[SCSI] be2iscsi: Invalidate WRB in Abort/Reset Path
[linux-2.6-block.git] / drivers / scsi / be2iscsi / be_iscsi.c
CommitLineData
6733b39a 1/**
533c165f 2 * Copyright (C) 2005 - 2013 Emulex
6733b39a
JK
3 * All rights reserved.
4 *
5 * This program is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU General Public License version 2
7 * as published by the Free Software Foundation. The full GNU General
8 * Public License is included in this distribution in the file called COPYING.
9 *
255fa9a3 10 * Written by: Jayamohan Kallickal (jayamohan.kallickal@emulex.com)
6733b39a
JK
11 *
12 * Contact Information:
255fa9a3 13 * linux-drivers@emulex.com
6733b39a 14 *
255fa9a3
JK
15 * Emulex
16 * 3333 Susan Street
17 * Costa Mesa, CA 92626
6733b39a
JK
18 */
19
20#include <scsi/libiscsi.h>
21#include <scsi/scsi_transport_iscsi.h>
22#include <scsi/scsi_transport.h>
23#include <scsi/scsi_cmnd.h>
24#include <scsi/scsi_device.h>
25#include <scsi/scsi_host.h>
0e43895e
MC
26#include <scsi/scsi_netlink.h>
27#include <net/netlink.h>
6733b39a
JK
28#include <scsi/scsi.h>
29
30#include "be_iscsi.h"
31
32extern struct iscsi_transport beiscsi_iscsi_transport;
33
34/**
35 * beiscsi_session_create - creates a new iscsi session
36 * @cmds_max: max commands supported
37 * @qdepth: max queue depth supported
38 * @initial_cmdsn: initial iscsi CMDSN
39 */
40struct iscsi_cls_session *beiscsi_session_create(struct iscsi_endpoint *ep,
41 u16 cmds_max,
42 u16 qdepth,
43 u32 initial_cmdsn)
44{
45 struct Scsi_Host *shost;
46 struct beiscsi_endpoint *beiscsi_ep;
47 struct iscsi_cls_session *cls_session;
6733b39a 48 struct beiscsi_hba *phba;
b8b9e1b8
JK
49 struct iscsi_session *sess;
50 struct beiscsi_session *beiscsi_sess;
6733b39a 51 struct beiscsi_io_task *io_task;
6733b39a 52
6733b39a
JK
53
54 if (!ep) {
99bc5d55
JSJ
55 printk(KERN_ERR
56 "beiscsi_session_create: invalid ep\n");
6733b39a
JK
57 return NULL;
58 }
59 beiscsi_ep = ep->dd_data;
60 phba = beiscsi_ep->phba;
61 shost = phba->shost;
99bc5d55
JSJ
62
63 beiscsi_log(phba, KERN_INFO, BEISCSI_LOG_CONFIG,
64 "BS_%d : In beiscsi_session_create\n");
65
6733b39a 66 if (cmds_max > beiscsi_ep->phba->params.wrbs_per_cxn) {
99bc5d55
JSJ
67 beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_CONFIG,
68 "BS_%d : Cannot handle %d cmds."
69 "Max cmds per session supported is %d. Using %d."
70 "\n", cmds_max,
71 beiscsi_ep->phba->params.wrbs_per_cxn,
72 beiscsi_ep->phba->params.wrbs_per_cxn);
73
6733b39a
JK
74 cmds_max = beiscsi_ep->phba->params.wrbs_per_cxn;
75 }
76
bfead3b2
JK
77 cls_session = iscsi_session_setup(&beiscsi_iscsi_transport,
78 shost, cmds_max,
79 sizeof(*beiscsi_sess),
80 sizeof(*io_task),
81 initial_cmdsn, ISCSI_MAX_TARGET);
6733b39a
JK
82 if (!cls_session)
83 return NULL;
84 sess = cls_session->dd_data;
2afc95bf
JK
85 beiscsi_sess = sess->dd_data;
86 beiscsi_sess->bhs_pool = pci_pool_create("beiscsi_bhs_pool",
87 phba->pcidev,
88 sizeof(struct be_cmd_bhs),
89 64, 0);
90 if (!beiscsi_sess->bhs_pool)
91 goto destroy_sess;
6733b39a 92
6733b39a 93 return cls_session;
2afc95bf
JK
94destroy_sess:
95 iscsi_session_teardown(cls_session);
96 return NULL;
6733b39a
JK
97}
98
99/**
100 * beiscsi_session_destroy - destroys iscsi session
101 * @cls_session: pointer to iscsi cls session
102 *
103 * Destroys iSCSI session instance and releases
104 * resources allocated for it.
105 */
106void beiscsi_session_destroy(struct iscsi_cls_session *cls_session)
107{
6733b39a 108 struct iscsi_session *sess = cls_session->dd_data;
2afc95bf 109 struct beiscsi_session *beiscsi_sess = sess->dd_data;
6733b39a 110
99bc5d55 111 printk(KERN_INFO "In beiscsi_session_destroy\n");
2afc95bf 112 pci_pool_destroy(beiscsi_sess->bhs_pool);
6733b39a
JK
113 iscsi_session_teardown(cls_session);
114}
115
116/**
117 * beiscsi_conn_create - create an instance of iscsi connection
118 * @cls_session: ptr to iscsi_cls_session
119 * @cid: iscsi cid
120 */
121struct iscsi_cls_conn *
122beiscsi_conn_create(struct iscsi_cls_session *cls_session, u32 cid)
123{
124 struct beiscsi_hba *phba;
125 struct Scsi_Host *shost;
126 struct iscsi_cls_conn *cls_conn;
127 struct beiscsi_conn *beiscsi_conn;
128 struct iscsi_conn *conn;
2afc95bf
JK
129 struct iscsi_session *sess;
130 struct beiscsi_session *beiscsi_sess;
6733b39a 131
6733b39a
JK
132 shost = iscsi_session_to_shost(cls_session);
133 phba = iscsi_host_priv(shost);
134
99bc5d55
JSJ
135 beiscsi_log(phba, KERN_INFO, BEISCSI_LOG_CONFIG,
136 "BS_%d : In beiscsi_conn_create ,cid"
137 "from iscsi layer=%d\n", cid);
138
6733b39a
JK
139 cls_conn = iscsi_conn_setup(cls_session, sizeof(*beiscsi_conn), cid);
140 if (!cls_conn)
141 return NULL;
142
143 conn = cls_conn->dd_data;
144 beiscsi_conn = conn->dd_data;
145 beiscsi_conn->ep = NULL;
146 beiscsi_conn->phba = phba;
147 beiscsi_conn->conn = conn;
2afc95bf
JK
148 sess = cls_session->dd_data;
149 beiscsi_sess = sess->dd_data;
150 beiscsi_conn->beiscsi_sess = beiscsi_sess;
6733b39a
JK
151 return cls_conn;
152}
153
154/**
155 * beiscsi_bindconn_cid - Bind the beiscsi_conn with phba connection table
156 * @beiscsi_conn: The pointer to beiscsi_conn structure
157 * @phba: The phba instance
158 * @cid: The cid to free
159 */
160static int beiscsi_bindconn_cid(struct beiscsi_hba *phba,
161 struct beiscsi_conn *beiscsi_conn,
162 unsigned int cid)
163{
a7909b39
JK
164 uint16_t cri_index = BE_GET_CRI_FROM_CID(cid);
165
166 if (phba->conn_table[cri_index]) {
99bc5d55
JSJ
167 beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_CONFIG,
168 "BS_%d : Connection table already occupied. Detected clash\n");
169
6733b39a
JK
170 return -EINVAL;
171 } else {
99bc5d55
JSJ
172 beiscsi_log(phba, KERN_INFO, BEISCSI_LOG_CONFIG,
173 "BS_%d : phba->conn_table[%d]=%p(beiscsi_conn)\n",
a7909b39 174 cri_index, beiscsi_conn);
99bc5d55 175
a7909b39 176 phba->conn_table[cri_index] = beiscsi_conn;
6733b39a
JK
177 }
178 return 0;
179}
180
181/**
182 * beiscsi_conn_bind - Binds iscsi session/connection with TCP connection
183 * @cls_session: pointer to iscsi cls session
184 * @cls_conn: pointer to iscsi cls conn
185 * @transport_fd: EP handle(64 bit)
186 *
187 * This function binds the TCP Conn with iSCSI Connection and Session.
188 */
189int beiscsi_conn_bind(struct iscsi_cls_session *cls_session,
190 struct iscsi_cls_conn *cls_conn,
191 u64 transport_fd, int is_leading)
192{
193 struct iscsi_conn *conn = cls_conn->dd_data;
194 struct beiscsi_conn *beiscsi_conn = conn->dd_data;
3093b048
MC
195 struct Scsi_Host *shost = iscsi_session_to_shost(cls_session);
196 struct beiscsi_hba *phba = iscsi_host_priv(shost);
1e4be6ff
JK
197 struct hwi_controller *phwi_ctrlr = phba->phwi_ctrlr;
198 struct hwi_wrb_context *pwrb_context;
6733b39a
JK
199 struct beiscsi_endpoint *beiscsi_ep;
200 struct iscsi_endpoint *ep;
201
6733b39a
JK
202 ep = iscsi_lookup_endpoint(transport_fd);
203 if (!ep)
204 return -EINVAL;
205
206 beiscsi_ep = ep->dd_data;
207
208 if (iscsi_conn_bind(cls_session, cls_conn, is_leading))
209 return -EINVAL;
210
211 if (beiscsi_ep->phba != phba) {
99bc5d55
JSJ
212 beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_CONFIG,
213 "BS_%d : beiscsi_ep->hba=%p not equal to phba=%p\n",
214 beiscsi_ep->phba, phba);
215
6733b39a
JK
216 return -EEXIST;
217 }
218
1e4be6ff
JK
219 pwrb_context = &phwi_ctrlr->wrb_context[BE_GET_CRI_FROM_CID(
220 beiscsi_ep->ep_cid)];
221
6733b39a
JK
222 beiscsi_conn->beiscsi_conn_cid = beiscsi_ep->ep_cid;
223 beiscsi_conn->ep = beiscsi_ep;
224 beiscsi_ep->conn = beiscsi_conn;
1e4be6ff 225 beiscsi_conn->doorbell_offset = pwrb_context->doorbell_offset;
99bc5d55
JSJ
226
227 beiscsi_log(phba, KERN_INFO, BEISCSI_LOG_CONFIG,
228 "BS_%d : beiscsi_conn=%p conn=%p ep_cid=%d\n",
229 beiscsi_conn, conn, beiscsi_ep->ep_cid);
230
6733b39a
JK
231 return beiscsi_bindconn_cid(phba, beiscsi_conn, beiscsi_ep->ep_cid);
232}
233
0e43895e
MC
234static int beiscsi_create_ipv4_iface(struct beiscsi_hba *phba)
235{
236 if (phba->ipv4_iface)
237 return 0;
238
239 phba->ipv4_iface = iscsi_create_iface(phba->shost,
240 &beiscsi_iscsi_transport,
241 ISCSI_IFACE_TYPE_IPV4,
242 0, 0);
243 if (!phba->ipv4_iface) {
99bc5d55
JSJ
244 beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_CONFIG,
245 "BS_%d : Could not "
246 "create default IPv4 address.\n");
0e43895e
MC
247 return -ENODEV;
248 }
249
250 return 0;
251}
252
253static int beiscsi_create_ipv6_iface(struct beiscsi_hba *phba)
254{
255 if (phba->ipv6_iface)
256 return 0;
257
258 phba->ipv6_iface = iscsi_create_iface(phba->shost,
259 &beiscsi_iscsi_transport,
260 ISCSI_IFACE_TYPE_IPV6,
261 0, 0);
262 if (!phba->ipv6_iface) {
99bc5d55
JSJ
263 beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_CONFIG,
264 "BS_%d : Could not "
265 "create default IPv6 address.\n");
0e43895e
MC
266 return -ENODEV;
267 }
268
269 return 0;
270}
271
272void beiscsi_create_def_ifaces(struct beiscsi_hba *phba)
273{
1f536d49 274 struct be_cmd_get_if_info_resp *if_info;
0e43895e 275
1f536d49 276 if (!mgmt_get_if_info(phba, BE2_IPV4, &if_info)) {
0e43895e 277 beiscsi_create_ipv4_iface(phba);
1f536d49
JK
278 kfree(if_info);
279 }
0e43895e 280
1f536d49 281 if (!mgmt_get_if_info(phba, BE2_IPV6, &if_info)) {
0e43895e 282 beiscsi_create_ipv6_iface(phba);
1f536d49
JK
283 kfree(if_info);
284 }
0e43895e
MC
285}
286
287void beiscsi_destroy_def_ifaces(struct beiscsi_hba *phba)
288{
289 if (phba->ipv6_iface)
290 iscsi_destroy_iface(phba->ipv6_iface);
291 if (phba->ipv4_iface)
292 iscsi_destroy_iface(phba->ipv4_iface);
293}
294
295static int
296beiscsi_set_static_ip(struct Scsi_Host *shost,
297 struct iscsi_iface_param_info *iface_param,
298 void *data, uint32_t dt_len)
299{
300 struct beiscsi_hba *phba = iscsi_host_priv(shost);
301 struct iscsi_iface_param_info *iface_ip = NULL;
302 struct iscsi_iface_param_info *iface_subnet = NULL;
303 struct nlattr *nla;
304 int ret;
305
306
307 switch (iface_param->param) {
308 case ISCSI_NET_PARAM_IPV4_BOOTPROTO:
309 nla = nla_find(data, dt_len, ISCSI_NET_PARAM_IPV4_ADDR);
310 if (nla)
311 iface_ip = nla_data(nla);
312
313 nla = nla_find(data, dt_len, ISCSI_NET_PARAM_IPV4_SUBNET);
314 if (nla)
315 iface_subnet = nla_data(nla);
316 break;
317 case ISCSI_NET_PARAM_IPV4_ADDR:
318 iface_ip = iface_param;
319 nla = nla_find(data, dt_len, ISCSI_NET_PARAM_IPV4_SUBNET);
320 if (nla)
321 iface_subnet = nla_data(nla);
322 break;
323 case ISCSI_NET_PARAM_IPV4_SUBNET:
324 iface_subnet = iface_param;
325 nla = nla_find(data, dt_len, ISCSI_NET_PARAM_IPV4_ADDR);
326 if (nla)
327 iface_ip = nla_data(nla);
328 break;
329 default:
99bc5d55
JSJ
330 beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_CONFIG,
331 "BS_%d : Unsupported param %d\n",
332 iface_param->param);
0e43895e
MC
333 }
334
335 if (!iface_ip || !iface_subnet) {
99bc5d55
JSJ
336 beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_CONFIG,
337 "BS_%d : IP and Subnet Mask required\n");
0e43895e
MC
338 return -EINVAL;
339 }
340
341 ret = mgmt_set_ip(phba, iface_ip, iface_subnet,
342 ISCSI_BOOTPROTO_STATIC);
343
344 return ret;
345}
346
6f72238e
JSJ
347/**
348 * beiscsi_set_vlan_tag()- Set the VLAN TAG
349 * @shost: Scsi Host for the driver instance
350 * @iface_param: Interface paramters
351 *
352 * Set the VLAN TAG for the adapter or disable
353 * the VLAN config
354 *
355 * returns
356 * Success: 0
357 * Failure: Non-Zero Value
358 **/
359static int
360beiscsi_set_vlan_tag(struct Scsi_Host *shost,
361 struct iscsi_iface_param_info *iface_param)
362{
363 struct beiscsi_hba *phba = iscsi_host_priv(shost);
364 int ret = 0;
365
366 /* Get the Interface Handle */
367 if (mgmt_get_all_if_id(phba)) {
368 beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_CONFIG,
369 "BS_%d : Getting Interface Handle Failed\n");
370 return -EIO;
371 }
372
373 switch (iface_param->param) {
374 case ISCSI_NET_PARAM_VLAN_ENABLED:
375 if (iface_param->value[0] != ISCSI_VLAN_ENABLE)
376 ret = mgmt_set_vlan(phba, BEISCSI_VLAN_DISABLE);
377 break;
378 case ISCSI_NET_PARAM_VLAN_TAG:
379 ret = mgmt_set_vlan(phba,
380 *((uint16_t *)iface_param->value));
381 break;
382 default:
383 beiscsi_log(phba, KERN_WARNING, BEISCSI_LOG_CONFIG,
b23f7a09 384 "BS_%d : Unknown Param Type : %d\n",
6f72238e
JSJ
385 iface_param->param);
386 return -ENOSYS;
387 }
388 return ret;
389}
390
391
0e43895e
MC
392static int
393beiscsi_set_ipv4(struct Scsi_Host *shost,
394 struct iscsi_iface_param_info *iface_param,
395 void *data, uint32_t dt_len)
396{
397 struct beiscsi_hba *phba = iscsi_host_priv(shost);
398 int ret = 0;
399
400 /* Check the param */
401 switch (iface_param->param) {
402 case ISCSI_NET_PARAM_IPV4_GW:
403 ret = mgmt_set_gateway(phba, iface_param);
404 break;
405 case ISCSI_NET_PARAM_IPV4_BOOTPROTO:
406 if (iface_param->value[0] == ISCSI_BOOTPROTO_DHCP)
407 ret = mgmt_set_ip(phba, iface_param,
408 NULL, ISCSI_BOOTPROTO_DHCP);
409 else if (iface_param->value[0] == ISCSI_BOOTPROTO_STATIC)
410 ret = beiscsi_set_static_ip(shost, iface_param,
411 data, dt_len);
412 else
99bc5d55
JSJ
413 beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_CONFIG,
414 "BS_%d : Invalid BOOTPROTO: %d\n",
415 iface_param->value[0]);
0e43895e
MC
416 break;
417 case ISCSI_NET_PARAM_IFACE_ENABLE:
418 if (iface_param->value[0] == ISCSI_IFACE_ENABLE)
419 ret = beiscsi_create_ipv4_iface(phba);
420 else
421 iscsi_destroy_iface(phba->ipv4_iface);
422 break;
423 case ISCSI_NET_PARAM_IPV4_SUBNET:
424 case ISCSI_NET_PARAM_IPV4_ADDR:
425 ret = beiscsi_set_static_ip(shost, iface_param,
426 data, dt_len);
427 break;
6f72238e
JSJ
428 case ISCSI_NET_PARAM_VLAN_ENABLED:
429 case ISCSI_NET_PARAM_VLAN_TAG:
430 ret = beiscsi_set_vlan_tag(shost, iface_param);
431 break;
0e43895e 432 default:
99bc5d55
JSJ
433 beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_CONFIG,
434 "BS_%d : Param %d not supported\n",
435 iface_param->param);
0e43895e
MC
436 }
437
438 return ret;
439}
440
441static int
442beiscsi_set_ipv6(struct Scsi_Host *shost,
443 struct iscsi_iface_param_info *iface_param,
444 void *data, uint32_t dt_len)
445{
446 struct beiscsi_hba *phba = iscsi_host_priv(shost);
447 int ret = 0;
448
449 switch (iface_param->param) {
450 case ISCSI_NET_PARAM_IFACE_ENABLE:
451 if (iface_param->value[0] == ISCSI_IFACE_ENABLE)
452 ret = beiscsi_create_ipv6_iface(phba);
453 else {
454 iscsi_destroy_iface(phba->ipv6_iface);
455 ret = 0;
456 }
457 break;
458 case ISCSI_NET_PARAM_IPV6_ADDR:
459 ret = mgmt_set_ip(phba, iface_param, NULL,
460 ISCSI_BOOTPROTO_STATIC);
461 break;
462 default:
99bc5d55
JSJ
463 beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_CONFIG,
464 "BS_%d : Param %d not supported\n",
465 iface_param->param);
0e43895e
MC
466 }
467
468 return ret;
469}
470
471int be2iscsi_iface_set_param(struct Scsi_Host *shost,
472 void *data, uint32_t dt_len)
473{
474 struct iscsi_iface_param_info *iface_param = NULL;
99bc5d55 475 struct beiscsi_hba *phba = iscsi_host_priv(shost);
0e43895e
MC
476 struct nlattr *attrib;
477 uint32_t rm_len = dt_len;
478 int ret = 0 ;
479
480 nla_for_each_attr(attrib, data, dt_len, rm_len) {
481 iface_param = nla_data(attrib);
482
483 if (iface_param->param_type != ISCSI_NET_PARAM)
484 continue;
485
486 /*
487 * BE2ISCSI only supports 1 interface
488 */
489 if (iface_param->iface_num) {
99bc5d55
JSJ
490 beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_CONFIG,
491 "BS_%d : Invalid iface_num %d."
492 "Only iface_num 0 is supported.\n",
493 iface_param->iface_num);
494
0e43895e
MC
495 return -EINVAL;
496 }
497
498 switch (iface_param->iface_type) {
499 case ISCSI_IFACE_TYPE_IPV4:
500 ret = beiscsi_set_ipv4(shost, iface_param,
501 data, dt_len);
502 break;
503 case ISCSI_IFACE_TYPE_IPV6:
504 ret = beiscsi_set_ipv6(shost, iface_param,
505 data, dt_len);
506 break;
507 default:
99bc5d55
JSJ
508 beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_CONFIG,
509 "BS_%d : Invalid iface type :%d passed\n",
510 iface_param->iface_type);
0e43895e
MC
511 break;
512 }
513
514 if (ret)
515 return ret;
516 }
517
518 return ret;
519}
520
521static int be2iscsi_get_if_param(struct beiscsi_hba *phba,
522 struct iscsi_iface *iface, int param,
523 char *buf)
524{
1f536d49 525 struct be_cmd_get_if_info_resp *if_info;
0e43895e
MC
526 int len, ip_type = BE2_IPV4;
527
0e43895e
MC
528 if (iface->iface_type == ISCSI_IFACE_TYPE_IPV6)
529 ip_type = BE2_IPV6;
530
531 len = mgmt_get_if_info(phba, ip_type, &if_info);
1f536d49
JK
532 if (len) {
533 kfree(if_info);
0e43895e 534 return len;
1f536d49 535 }
0e43895e
MC
536
537 switch (param) {
538 case ISCSI_NET_PARAM_IPV4_ADDR:
1f536d49 539 len = sprintf(buf, "%pI4\n", if_info->ip_addr.addr);
0e43895e
MC
540 break;
541 case ISCSI_NET_PARAM_IPV6_ADDR:
1f536d49 542 len = sprintf(buf, "%pI6\n", if_info->ip_addr.addr);
0e43895e
MC
543 break;
544 case ISCSI_NET_PARAM_IPV4_BOOTPROTO:
1f536d49 545 if (!if_info->dhcp_state)
8359c79b 546 len = sprintf(buf, "static\n");
0e43895e 547 else
8359c79b 548 len = sprintf(buf, "dhcp\n");
0e43895e
MC
549 break;
550 case ISCSI_NET_PARAM_IPV4_SUBNET:
1f536d49 551 len = sprintf(buf, "%pI4\n", if_info->ip_addr.subnet_mask);
0e43895e 552 break;
6f72238e
JSJ
553 case ISCSI_NET_PARAM_VLAN_ENABLED:
554 len = sprintf(buf, "%s\n",
1f536d49 555 (if_info->vlan_priority == BEISCSI_VLAN_DISABLE)
8359c79b 556 ? "Disabled\n" : "Enabled\n");
6f72238e
JSJ
557 break;
558 case ISCSI_NET_PARAM_VLAN_ID:
1f536d49 559 if (if_info->vlan_priority == BEISCSI_VLAN_DISABLE)
6f72238e
JSJ
560 return -EINVAL;
561 else
562 len = sprintf(buf, "%d\n",
1f536d49 563 (if_info->vlan_priority &
6f72238e
JSJ
564 ISCSI_MAX_VLAN_ID));
565 break;
566 case ISCSI_NET_PARAM_VLAN_PRIORITY:
1f536d49 567 if (if_info->vlan_priority == BEISCSI_VLAN_DISABLE)
6f72238e
JSJ
568 return -EINVAL;
569 else
570 len = sprintf(buf, "%d\n",
1f536d49 571 ((if_info->vlan_priority >> 13) &
6f72238e
JSJ
572 ISCSI_MAX_VLAN_PRIORITY));
573 break;
0e43895e
MC
574 default:
575 WARN_ON(1);
576 }
577
1f536d49 578 kfree(if_info);
0e43895e
MC
579 return len;
580}
581
582int be2iscsi_iface_get_param(struct iscsi_iface *iface,
583 enum iscsi_param_type param_type,
584 int param, char *buf)
585{
586 struct Scsi_Host *shost = iscsi_iface_to_shost(iface);
587 struct beiscsi_hba *phba = iscsi_host_priv(shost);
588 struct be_cmd_get_def_gateway_resp gateway;
589 int len = -ENOSYS;
590
591 switch (param) {
592 case ISCSI_NET_PARAM_IPV4_ADDR:
593 case ISCSI_NET_PARAM_IPV4_SUBNET:
594 case ISCSI_NET_PARAM_IPV4_BOOTPROTO:
595 case ISCSI_NET_PARAM_IPV6_ADDR:
6f72238e
JSJ
596 case ISCSI_NET_PARAM_VLAN_ENABLED:
597 case ISCSI_NET_PARAM_VLAN_ID:
598 case ISCSI_NET_PARAM_VLAN_PRIORITY:
0e43895e
MC
599 len = be2iscsi_get_if_param(phba, iface, param, buf);
600 break;
601 case ISCSI_NET_PARAM_IFACE_ENABLE:
8359c79b 602 len = sprintf(buf, "enabled\n");
0e43895e
MC
603 break;
604 case ISCSI_NET_PARAM_IPV4_GW:
605 memset(&gateway, 0, sizeof(gateway));
606 len = mgmt_get_gateway(phba, BE2_IPV4, &gateway);
607 if (!len)
608 len = sprintf(buf, "%pI4\n", &gateway.ip_addr.addr);
609 break;
610 default:
611 len = -ENOSYS;
612 }
613
614 return len;
615}
616
6733b39a 617/**
c7f7fd5b
MC
618 * beiscsi_ep_get_param - get the iscsi parameter
619 * @ep: pointer to iscsi ep
6733b39a
JK
620 * @param: parameter type identifier
621 * @buf: buffer pointer
622 *
623 * returns iscsi parameter
624 */
c7f7fd5b 625int beiscsi_ep_get_param(struct iscsi_endpoint *ep,
6733b39a
JK
626 enum iscsi_param param, char *buf)
627{
c7f7fd5b 628 struct beiscsi_endpoint *beiscsi_ep = ep->dd_data;
6733b39a
JK
629 int len = 0;
630
99bc5d55
JSJ
631 beiscsi_log(beiscsi_ep->phba, KERN_INFO,
632 BEISCSI_LOG_CONFIG,
633 "BS_%d : In beiscsi_ep_get_param,"
634 " param= %d\n", param);
6733b39a
JK
635
636 switch (param) {
637 case ISCSI_PARAM_CONN_PORT:
638 len = sprintf(buf, "%hu\n", beiscsi_ep->dst_tcpport);
639 break;
640 case ISCSI_PARAM_CONN_ADDRESS:
641 if (beiscsi_ep->ip_type == BE2_IPV4)
642 len = sprintf(buf, "%pI4\n", &beiscsi_ep->dst_addr);
643 else
644 len = sprintf(buf, "%pI6\n", &beiscsi_ep->dst6_addr);
645 break;
646 default:
c7f7fd5b 647 return -ENOSYS;
6733b39a
JK
648 }
649 return len;
650}
651
652int beiscsi_set_param(struct iscsi_cls_conn *cls_conn,
653 enum iscsi_param param, char *buf, int buflen)
654{
655 struct iscsi_conn *conn = cls_conn->dd_data;
656 struct iscsi_session *session = conn->session;
99bc5d55 657 struct beiscsi_hba *phba = NULL;
6733b39a
JK
658 int ret;
659
99bc5d55
JSJ
660 phba = ((struct beiscsi_conn *)conn->dd_data)->phba;
661 beiscsi_log(phba, KERN_INFO, BEISCSI_LOG_CONFIG,
662 "BS_%d : In beiscsi_conn_set_param,"
663 " param= %d\n", param);
664
6733b39a
JK
665 ret = iscsi_set_param(cls_conn, param, buf, buflen);
666 if (ret)
667 return ret;
668 /*
669 * If userspace tried to set the value to higher than we can
670 * support override here.
671 */
672 switch (param) {
673 case ISCSI_PARAM_FIRST_BURST:
674 if (session->first_burst > 8192)
675 session->first_burst = 8192;
676 break;
677 case ISCSI_PARAM_MAX_RECV_DLENGTH:
678 if (conn->max_recv_dlength > 65536)
679 conn->max_recv_dlength = 65536;
680 break;
681 case ISCSI_PARAM_MAX_BURST:
230dceb4
JK
682 if (session->max_burst > 262144)
683 session->max_burst = 262144;
6733b39a 684 break;
42f43c41 685 case ISCSI_PARAM_MAX_XMIT_DLENGTH:
7331613e 686 if (conn->max_xmit_dlength > 65536)
42f43c41 687 conn->max_xmit_dlength = 65536;
6733b39a
JK
688 default:
689 return 0;
690 }
691
692 return 0;
693}
694
2177199d
JSJ
695/**
696 * beiscsi_get_initname - Read Initiator Name from flash
697 * @buf: buffer bointer
698 * @phba: The device priv structure instance
699 *
700 * returns number of bytes
701 */
702static int beiscsi_get_initname(char *buf, struct beiscsi_hba *phba)
703{
704 int rc;
e175defe 705 unsigned int tag;
2177199d
JSJ
706 struct be_mcc_wrb *wrb;
707 struct be_cmd_hba_name *resp;
2177199d
JSJ
708
709 tag = be_cmd_get_initname(phba);
710 if (!tag) {
99bc5d55
JSJ
711 beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_CONFIG,
712 "BS_%d : Getting Initiator Name Failed\n");
713
2177199d 714 return -EBUSY;
e175defe 715 }
2177199d 716
e175defe
JSJ
717 rc = beiscsi_mccq_compl(phba, tag, &wrb, NULL);
718 if (rc) {
99bc5d55
JSJ
719 beiscsi_log(phba, KERN_ERR,
720 BEISCSI_LOG_CONFIG | BEISCSI_LOG_MBOX,
e175defe
JSJ
721 "BS_%d : Initiator Name MBX Failed\n");
722 return rc;
2177199d 723 }
e175defe 724
2177199d
JSJ
725 resp = embedded_payload(wrb);
726 rc = sprintf(buf, "%s\n", resp->initiator_name);
727 return rc;
728}
729
c62eef0d
JSJ
730/**
731 * beiscsi_get_port_state - Get the Port State
732 * @shost : pointer to scsi_host structure
733 *
c62eef0d
JSJ
734 */
735static void beiscsi_get_port_state(struct Scsi_Host *shost)
736{
737 struct beiscsi_hba *phba = iscsi_host_priv(shost);
738 struct iscsi_cls_host *ihost = shost->shost_data;
739
740 ihost->port_state = (phba->state == BE_ADAPTER_UP) ?
741 ISCSI_PORT_STATE_UP : ISCSI_PORT_STATE_DOWN;
742}
743
744/**
745 * beiscsi_get_port_speed - Get the Port Speed from Adapter
746 * @shost : pointer to scsi_host structure
747 *
748 * returns Success/Failure
749 */
750static int beiscsi_get_port_speed(struct Scsi_Host *shost)
751{
e175defe
JSJ
752 int rc;
753 unsigned int tag;
c62eef0d
JSJ
754 struct be_mcc_wrb *wrb;
755 struct be_cmd_ntwk_link_status_resp *resp;
756 struct beiscsi_hba *phba = iscsi_host_priv(shost);
757 struct iscsi_cls_host *ihost = shost->shost_data;
c62eef0d
JSJ
758
759 tag = be_cmd_get_port_speed(phba);
760 if (!tag) {
99bc5d55
JSJ
761 beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_CONFIG,
762 "BS_%d : Getting Port Speed Failed\n");
763
c62eef0d 764 return -EBUSY;
e175defe
JSJ
765 }
766 rc = beiscsi_mccq_compl(phba, tag, &wrb, NULL);
767 if (rc) {
99bc5d55
JSJ
768 beiscsi_log(phba, KERN_ERR,
769 BEISCSI_LOG_CONFIG | BEISCSI_LOG_MBOX,
e175defe
JSJ
770 "BS_%d : Port Speed MBX Failed\n");
771 return rc;
c62eef0d 772 }
c62eef0d
JSJ
773 resp = embedded_payload(wrb);
774
775 switch (resp->mac_speed) {
776 case BE2ISCSI_LINK_SPEED_10MBPS:
777 ihost->port_speed = ISCSI_PORT_SPEED_10MBPS;
778 break;
779 case BE2ISCSI_LINK_SPEED_100MBPS:
780 ihost->port_speed = BE2ISCSI_LINK_SPEED_100MBPS;
781 break;
782 case BE2ISCSI_LINK_SPEED_1GBPS:
783 ihost->port_speed = ISCSI_PORT_SPEED_1GBPS;
784 break;
785 case BE2ISCSI_LINK_SPEED_10GBPS:
786 ihost->port_speed = ISCSI_PORT_SPEED_10GBPS;
787 break;
788 default:
789 ihost->port_speed = ISCSI_PORT_SPEED_UNKNOWN;
790 }
791 return 0;
792}
793
6733b39a
JK
794/**
795 * beiscsi_get_host_param - get the iscsi parameter
796 * @shost: pointer to scsi_host structure
797 * @param: parameter type identifier
798 * @buf: buffer pointer
799 *
800 * returns host parameter
801 */
802int beiscsi_get_host_param(struct Scsi_Host *shost,
803 enum iscsi_host_param param, char *buf)
804{
3093b048 805 struct beiscsi_hba *phba = iscsi_host_priv(shost);
b15d05b0 806 int status = 0;
6733b39a 807
99bc5d55
JSJ
808 beiscsi_log(phba, KERN_INFO, BEISCSI_LOG_CONFIG,
809 "BS_%d : In beiscsi_get_host_param,"
810 " param= %d\n", param);
811
6733b39a
JK
812 switch (param) {
813 case ISCSI_HOST_PARAM_HWADDRESS:
c7acc5b8
JK
814 status = beiscsi_get_macaddr(buf, phba);
815 if (status < 0) {
99bc5d55
JSJ
816 beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_CONFIG,
817 "BS_%d : beiscsi_get_macaddr Failed\n");
c7acc5b8 818 return status;
756d29c8 819 }
6733b39a 820 break;
2177199d
JSJ
821 case ISCSI_HOST_PARAM_INITIATOR_NAME:
822 status = beiscsi_get_initname(buf, phba);
823 if (status < 0) {
99bc5d55
JSJ
824 beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_CONFIG,
825 "BS_%d : Retreiving Initiator Name Failed\n");
2177199d
JSJ
826 return status;
827 }
828 break;
c62eef0d
JSJ
829 case ISCSI_HOST_PARAM_PORT_STATE:
830 beiscsi_get_port_state(shost);
831 status = sprintf(buf, "%s\n", iscsi_get_port_state_name(shost));
832 break;
833 case ISCSI_HOST_PARAM_PORT_SPEED:
834 status = beiscsi_get_port_speed(shost);
835 if (status) {
99bc5d55
JSJ
836 beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_CONFIG,
837 "BS_%d : Retreiving Port Speed Failed\n");
c62eef0d
JSJ
838 return status;
839 }
840 status = sprintf(buf, "%s\n", iscsi_get_port_speed_name(shost));
841 break;
6733b39a
JK
842 default:
843 return iscsi_host_get_param(shost, param, buf);
844 }
b15d05b0 845 return status;
6733b39a
JK
846}
847
c7acc5b8
JK
848int beiscsi_get_macaddr(char *buf, struct beiscsi_hba *phba)
849{
0e43895e 850 struct be_cmd_get_nic_conf_resp resp;
c7acc5b8
JK
851 int rc;
852
6c83185a 853 if (phba->mac_addr_set)
df5d0e6e 854 return sysfs_format_mac(buf, phba->mac_address, ETH_ALEN);
c7acc5b8 855
0e43895e
MC
856 memset(&resp, 0, sizeof(resp));
857 rc = mgmt_get_nic_conf(phba, &resp);
858 if (rc)
859 return rc;
c7acc5b8 860
6c83185a 861 phba->mac_addr_set = true;
0e43895e
MC
862 memcpy(phba->mac_address, resp.mac_address, ETH_ALEN);
863 return sysfs_format_mac(buf, phba->mac_address, ETH_ALEN);
c7acc5b8
JK
864}
865
6733b39a
JK
866/**
867 * beiscsi_conn_get_stats - get the iscsi stats
868 * @cls_conn: pointer to iscsi cls conn
869 * @stats: pointer to iscsi_stats structure
870 *
871 * returns iscsi stats
872 */
873void beiscsi_conn_get_stats(struct iscsi_cls_conn *cls_conn,
874 struct iscsi_stats *stats)
875{
876 struct iscsi_conn *conn = cls_conn->dd_data;
99bc5d55
JSJ
877 struct beiscsi_hba *phba = NULL;
878
879 phba = ((struct beiscsi_conn *)conn->dd_data)->phba;
880 beiscsi_log(phba, KERN_INFO, BEISCSI_LOG_CONFIG,
881 "BS_%d : In beiscsi_conn_get_stats\n");
6733b39a 882
6733b39a
JK
883 stats->txdata_octets = conn->txdata_octets;
884 stats->rxdata_octets = conn->rxdata_octets;
885 stats->dataout_pdus = conn->dataout_pdus_cnt;
886 stats->scsirsp_pdus = conn->scsirsp_pdus_cnt;
887 stats->scsicmd_pdus = conn->scsicmd_pdus_cnt;
888 stats->datain_pdus = conn->datain_pdus_cnt;
889 stats->tmfrsp_pdus = conn->tmfrsp_pdus_cnt;
890 stats->tmfcmd_pdus = conn->tmfcmd_pdus_cnt;
891 stats->r2t_pdus = conn->r2t_pdus_cnt;
892 stats->digest_err = 0;
893 stats->timeout_err = 0;
894 stats->custom_length = 0;
895 strcpy(stats->custom[0].desc, "eh_abort_cnt");
896 stats->custom[0].value = conn->eh_abort_cnt;
897}
898
899/**
900 * beiscsi_set_params_for_offld - get the parameters for offload
901 * @beiscsi_conn: pointer to beiscsi_conn
902 * @params: pointer to offload_params structure
903 */
904static void beiscsi_set_params_for_offld(struct beiscsi_conn *beiscsi_conn,
905 struct beiscsi_offload_params *params)
906{
907 struct iscsi_conn *conn = beiscsi_conn->conn;
908 struct iscsi_session *session = conn->session;
909
910 AMAP_SET_BITS(struct amap_beiscsi_offload_params, max_burst_length,
911 params, session->max_burst);
912 AMAP_SET_BITS(struct amap_beiscsi_offload_params,
913 max_send_data_segment_length, params,
914 conn->max_xmit_dlength);
915 AMAP_SET_BITS(struct amap_beiscsi_offload_params, first_burst_length,
916 params, session->first_burst);
917 AMAP_SET_BITS(struct amap_beiscsi_offload_params, erl, params,
918 session->erl);
919 AMAP_SET_BITS(struct amap_beiscsi_offload_params, dde, params,
920 conn->datadgst_en);
921 AMAP_SET_BITS(struct amap_beiscsi_offload_params, hde, params,
922 conn->hdrdgst_en);
923 AMAP_SET_BITS(struct amap_beiscsi_offload_params, ir2t, params,
924 session->initial_r2t_en);
925 AMAP_SET_BITS(struct amap_beiscsi_offload_params, imd, params,
926 session->imm_data_en);
acb9693c
JSJ
927 AMAP_SET_BITS(struct amap_beiscsi_offload_params,
928 data_seq_inorder, params,
929 session->dataseq_inorder_en);
930 AMAP_SET_BITS(struct amap_beiscsi_offload_params,
931 pdu_seq_inorder, params,
932 session->pdu_inorder_en);
933 AMAP_SET_BITS(struct amap_beiscsi_offload_params, max_r2t, params,
934 session->max_r2t);
6733b39a
JK
935 AMAP_SET_BITS(struct amap_beiscsi_offload_params, exp_statsn, params,
936 (conn->exp_statsn - 1));
7331613e
JK
937 AMAP_SET_BITS(struct amap_beiscsi_offload_params,
938 max_recv_data_segment_length, params,
939 conn->max_recv_dlength);
940
6733b39a
JK
941}
942
943/**
944 * beiscsi_conn_start - offload of session to chip
945 * @cls_conn: pointer to beiscsi_conn
946 */
947int beiscsi_conn_start(struct iscsi_cls_conn *cls_conn)
948{
949 struct iscsi_conn *conn = cls_conn->dd_data;
950 struct beiscsi_conn *beiscsi_conn = conn->dd_data;
951 struct beiscsi_endpoint *beiscsi_ep;
952 struct beiscsi_offload_params params;
6733b39a 953
99bc5d55
JSJ
954 beiscsi_log(beiscsi_conn->phba, KERN_INFO,
955 BEISCSI_LOG_CONFIG,
956 "BS_%d : In beiscsi_conn_start\n");
957
6733b39a
JK
958 memset(&params, 0, sizeof(struct beiscsi_offload_params));
959 beiscsi_ep = beiscsi_conn->ep;
960 if (!beiscsi_ep)
99bc5d55
JSJ
961 beiscsi_log(beiscsi_conn->phba, KERN_ERR,
962 BEISCSI_LOG_CONFIG,
963 "BS_%d : In beiscsi_conn_start , no beiscsi_ep\n");
6733b39a 964
6733b39a
JK
965 beiscsi_conn->login_in_progress = 0;
966 beiscsi_set_params_for_offld(beiscsi_conn, &params);
967 beiscsi_offload_connection(beiscsi_conn, &params);
968 iscsi_conn_start(cls_conn);
969 return 0;
970}
971
972/**
973 * beiscsi_get_cid - Allocate a cid
974 * @phba: The phba instance
975 */
976static int beiscsi_get_cid(struct beiscsi_hba *phba)
977{
0a3db7c0
JK
978 unsigned short cid = 0xFFFF, cid_from_ulp;
979 struct ulp_cid_info *cid_info = NULL;
980 uint16_t cid_avlbl_ulp0, cid_avlbl_ulp1;
981
982 /* Find the ULP which has more CID available */
983 cid_avlbl_ulp0 = (phba->cid_array_info[BEISCSI_ULP0]) ?
984 BEISCSI_ULP0_AVLBL_CID(phba) : 0;
985 cid_avlbl_ulp1 = (phba->cid_array_info[BEISCSI_ULP1]) ?
986 BEISCSI_ULP1_AVLBL_CID(phba) : 0;
987 cid_from_ulp = (cid_avlbl_ulp0 > cid_avlbl_ulp1) ?
988 BEISCSI_ULP0 : BEISCSI_ULP1;
989
990 if (test_bit(cid_from_ulp, (void *)&phba->fw_config.ulp_supported)) {
991 cid_info = phba->cid_array_info[cid_from_ulp];
992 if (!cid_info->avlbl_cids)
993 return cid;
994
995 cid = cid_info->cid_array[cid_info->cid_alloc++];
996
997 if (cid_info->cid_alloc == BEISCSI_GET_CID_COUNT(
998 phba, cid_from_ulp))
999 cid_info->cid_alloc = 0;
1000
1001 cid_info->avlbl_cids--;
1002 }
6733b39a
JK
1003 return cid;
1004}
1005
fa95d206
MC
1006/**
1007 * beiscsi_put_cid - Free the cid
1008 * @phba: The phba for which the cid is being freed
1009 * @cid: The cid to free
1010 */
1011static void beiscsi_put_cid(struct beiscsi_hba *phba, unsigned short cid)
1012{
0a3db7c0
JK
1013 uint16_t cid_post_ulp;
1014 struct hwi_controller *phwi_ctrlr;
1015 struct hwi_wrb_context *pwrb_context;
1016 struct ulp_cid_info *cid_info = NULL;
1017 uint16_t cri_index = BE_GET_CRI_FROM_CID(cid);
1018
1019 phwi_ctrlr = phba->phwi_ctrlr;
1020 pwrb_context = &phwi_ctrlr->wrb_context[cri_index];
1021 cid_post_ulp = pwrb_context->ulp_num;
1022
1023 cid_info = phba->cid_array_info[cid_post_ulp];
1024 cid_info->avlbl_cids++;
1025
1026 cid_info->cid_array[cid_info->cid_free++] = cid;
1027 if (cid_info->cid_free == BEISCSI_GET_CID_COUNT(phba, cid_post_ulp))
1028 cid_info->cid_free = 0;
fa95d206
MC
1029}
1030
1031/**
1032 * beiscsi_free_ep - free endpoint
1033 * @ep: pointer to iscsi endpoint structure
1034 */
1035static void beiscsi_free_ep(struct beiscsi_endpoint *beiscsi_ep)
1036{
1037 struct beiscsi_hba *phba = beiscsi_ep->phba;
43f388b0 1038 struct beiscsi_conn *beiscsi_conn;
fa95d206
MC
1039
1040 beiscsi_put_cid(phba, beiscsi_ep->ep_cid);
1041 beiscsi_ep->phba = NULL;
a7909b39
JK
1042 phba->ep_array[BE_GET_CRI_FROM_CID
1043 (beiscsi_ep->ep_cid)] = NULL;
43f388b0
JK
1044
1045 /**
1046 * Check if any connection resource allocated by driver
1047 * is to be freed.This case occurs when target redirection
1048 * or connection retry is done.
1049 **/
1050 if (!beiscsi_ep->conn)
1051 return;
1052
1053 beiscsi_conn = beiscsi_ep->conn;
1054 if (beiscsi_conn->login_in_progress) {
4a4a11b9
JK
1055 beiscsi_free_mgmt_task_handles(beiscsi_conn,
1056 beiscsi_conn->task);
43f388b0
JK
1057 beiscsi_conn->login_in_progress = 0;
1058 }
fa95d206
MC
1059}
1060
6733b39a
JK
1061/**
1062 * beiscsi_open_conn - Ask FW to open a TCP connection
1063 * @ep: endpoint to be used
1064 * @src_addr: The source IP address
1065 * @dst_addr: The Destination IP address
1066 *
1067 * Asks the FW to open a TCP connection
1068 */
1069static int beiscsi_open_conn(struct iscsi_endpoint *ep,
1070 struct sockaddr *src_addr,
1071 struct sockaddr *dst_addr, int non_blocking)
1072{
1073 struct beiscsi_endpoint *beiscsi_ep = ep->dd_data;
1074 struct beiscsi_hba *phba = beiscsi_ep->phba;
756d29c8 1075 struct tcp_connect_and_offload_out *ptcpcnct_out;
3cbb7a74 1076 struct be_dma_mem nonemb_cmd;
e175defe 1077 unsigned int tag;
d3ad2bb3 1078 int ret = -ENOMEM;
6733b39a 1079
99bc5d55
JSJ
1080 beiscsi_log(phba, KERN_INFO, BEISCSI_LOG_CONFIG,
1081 "BS_%d : In beiscsi_open_conn\n");
1082
6733b39a
JK
1083 beiscsi_ep->ep_cid = beiscsi_get_cid(phba);
1084 if (beiscsi_ep->ep_cid == 0xFFFF) {
99bc5d55
JSJ
1085 beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_CONFIG,
1086 "BS_%d : No free cid available\n");
6733b39a
JK
1087 return ret;
1088 }
99bc5d55
JSJ
1089
1090 beiscsi_log(phba, KERN_INFO, BEISCSI_LOG_CONFIG,
1091 "BS_%d : In beiscsi_open_conn, ep_cid=%d\n",
1092 beiscsi_ep->ep_cid);
1093
a7909b39
JK
1094 phba->ep_array[BE_GET_CRI_FROM_CID
1095 (beiscsi_ep->ep_cid)] = ep;
6733b39a
JK
1096
1097 beiscsi_ep->cid_vld = 0;
3cbb7a74
JK
1098 nonemb_cmd.va = pci_alloc_consistent(phba->ctrl.pdev,
1099 sizeof(struct tcp_connect_and_offload_in),
1100 &nonemb_cmd.dma);
1101 if (nonemb_cmd.va == NULL) {
99bc5d55
JSJ
1102
1103 beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_CONFIG,
1104 "BS_%d : Failed to allocate memory for"
1105 " mgmt_open_connection\n");
1106
a7909b39 1107 beiscsi_free_ep(beiscsi_ep);
3cbb7a74
JK
1108 return -ENOMEM;
1109 }
1110 nonemb_cmd.size = sizeof(struct tcp_connect_and_offload_in);
1111 memset(nonemb_cmd.va, 0, nonemb_cmd.size);
1112 tag = mgmt_open_connection(phba, dst_addr, beiscsi_ep, &nonemb_cmd);
1e234bbb 1113 if (tag <= 0) {
99bc5d55
JSJ
1114 beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_CONFIG,
1115 "BS_%d : mgmt_open_connection Failed for cid=%d\n",
1116 beiscsi_ep->ep_cid);
1117
3cbb7a74
JK
1118 pci_free_consistent(phba->ctrl.pdev, nonemb_cmd.size,
1119 nonemb_cmd.va, nonemb_cmd.dma);
a7909b39 1120 beiscsi_free_ep(beiscsi_ep);
1f92638f 1121 return -EAGAIN;
756d29c8 1122 }
e175defe 1123
1e234bbb 1124 ret = beiscsi_mccq_compl(phba, tag, NULL, nonemb_cmd.va);
e175defe 1125 if (ret) {
99bc5d55
JSJ
1126 beiscsi_log(phba, KERN_ERR,
1127 BEISCSI_LOG_CONFIG | BEISCSI_LOG_MBOX,
e175defe 1128 "BS_%d : mgmt_open_connection Failed");
99bc5d55 1129
3cbb7a74
JK
1130 pci_free_consistent(phba->ctrl.pdev, nonemb_cmd.size,
1131 nonemb_cmd.va, nonemb_cmd.dma);
a7909b39
JK
1132 beiscsi_free_ep(beiscsi_ep);
1133 return -EBUSY;
756d29c8 1134 }
e175defe 1135
1e234bbb 1136 ptcpcnct_out = (struct tcp_connect_and_offload_out *)nonemb_cmd.va;
e175defe
JSJ
1137 beiscsi_ep = ep->dd_data;
1138 beiscsi_ep->fw_handle = ptcpcnct_out->connection_handle;
1139 beiscsi_ep->cid_vld = 1;
1140 beiscsi_log(phba, KERN_INFO, BEISCSI_LOG_CONFIG,
1141 "BS_%d : mgmt_open_connection Success\n");
1142
3cbb7a74
JK
1143 pci_free_consistent(phba->ctrl.pdev, nonemb_cmd.size,
1144 nonemb_cmd.va, nonemb_cmd.dma);
756d29c8 1145 return 0;
6733b39a
JK
1146}
1147
1148/**
1149 * beiscsi_ep_connect - Ask chip to create TCP Conn
1150 * @scsi_host: Pointer to scsi_host structure
1151 * @dst_addr: The IP address of Target
1152 * @non_blocking: blocking or non-blocking call
1153 *
1154 * This routines first asks chip to create a connection and then allocates an EP
1155 */
1156struct iscsi_endpoint *
1157beiscsi_ep_connect(struct Scsi_Host *shost, struct sockaddr *dst_addr,
1158 int non_blocking)
1159{
1160 struct beiscsi_hba *phba;
1161 struct beiscsi_endpoint *beiscsi_ep;
1162 struct iscsi_endpoint *ep;
1163 int ret;
1164
6733b39a
JK
1165 if (shost)
1166 phba = iscsi_host_priv(shost);
1167 else {
1168 ret = -ENXIO;
99bc5d55
JSJ
1169 printk(KERN_ERR
1170 "beiscsi_ep_connect shost is NULL\n");
6733b39a
JK
1171 return ERR_PTR(ret);
1172 }
bfead3b2 1173
cf6e3c64
JK
1174 if (beiscsi_error(phba)) {
1175 ret = -EIO;
1176 beiscsi_log(phba, KERN_WARNING, BEISCSI_LOG_CONFIG,
1177 "BS_%d : The FW state Not Stable!!!\n");
1178 return ERR_PTR(ret);
1179 }
1180
5dc1c416 1181 if (phba->state != BE_ADAPTER_UP) {
bfead3b2 1182 ret = -EBUSY;
8359c79b
JSJ
1183 beiscsi_log(phba, KERN_WARNING, BEISCSI_LOG_CONFIG,
1184 "BS_%d : The Adapter Port state is Down!!!\n");
bfead3b2
JK
1185 return ERR_PTR(ret);
1186 }
1187
6733b39a
JK
1188 ep = iscsi_create_endpoint(sizeof(struct beiscsi_endpoint));
1189 if (!ep) {
1190 ret = -ENOMEM;
1191 return ERR_PTR(ret);
1192 }
1193
1194 beiscsi_ep = ep->dd_data;
1195 beiscsi_ep->phba = phba;
c2462288 1196 beiscsi_ep->openiscsi_ep = ep;
f5ed7bd4
JK
1197 ret = beiscsi_open_conn(ep, NULL, dst_addr, non_blocking);
1198 if (ret) {
99bc5d55
JSJ
1199 beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_CONFIG,
1200 "BS_%d : Failed in beiscsi_open_conn\n");
6733b39a
JK
1201 goto free_ep;
1202 }
1203
1204 return ep;
1205
1206free_ep:
fa95d206 1207 iscsi_destroy_endpoint(ep);
6733b39a
JK
1208 return ERR_PTR(ret);
1209}
1210
1211/**
1212 * beiscsi_ep_poll - Poll to see if connection is established
1213 * @ep: endpoint to be used
1214 * @timeout_ms: timeout specified in millisecs
1215 *
1216 * Poll to see if TCP connection established
1217 */
1218int beiscsi_ep_poll(struct iscsi_endpoint *ep, int timeout_ms)
1219{
1220 struct beiscsi_endpoint *beiscsi_ep = ep->dd_data;
1221
99bc5d55
JSJ
1222 beiscsi_log(beiscsi_ep->phba, KERN_INFO, BEISCSI_LOG_CONFIG,
1223 "BS_%d : In beiscsi_ep_poll\n");
1224
6733b39a
JK
1225 if (beiscsi_ep->cid_vld == 1)
1226 return 1;
1227 else
1228 return 0;
1229}
1230
1231/**
1232 * beiscsi_close_conn - Upload the connection
1233 * @ep: The iscsi endpoint
1234 * @flag: The type of connection closure
1235 */
c2462288 1236static int beiscsi_close_conn(struct beiscsi_endpoint *beiscsi_ep, int flag)
6733b39a
JK
1237{
1238 int ret = 0;
756d29c8 1239 unsigned int tag;
6733b39a
JK
1240 struct beiscsi_hba *phba = beiscsi_ep->phba;
1241
756d29c8
JK
1242 tag = mgmt_upload_connection(phba, beiscsi_ep->ep_cid, flag);
1243 if (!tag) {
99bc5d55
JSJ
1244 beiscsi_log(phba, KERN_INFO, BEISCSI_LOG_CONFIG,
1245 "BS_%d : upload failed for cid 0x%x\n",
1246 beiscsi_ep->ep_cid);
1247
d3ad2bb3 1248 ret = -EAGAIN;
6733b39a 1249 }
e175defe
JSJ
1250
1251 ret = beiscsi_mccq_compl(phba, tag, NULL, NULL);
6733b39a
JK
1252 return ret;
1253}
1254
6733b39a
JK
1255/**
1256 * beiscsi_unbind_conn_to_cid - Unbind the beiscsi_conn from phba conn table
1257 * @phba: The phba instance
1258 * @cid: The cid to free
1259 */
1260static int beiscsi_unbind_conn_to_cid(struct beiscsi_hba *phba,
1261 unsigned int cid)
1262{
a7909b39
JK
1263 uint16_t cri_index = BE_GET_CRI_FROM_CID(cid);
1264
1265 if (phba->conn_table[cri_index])
1266 phba->conn_table[cri_index] = NULL;
6733b39a 1267 else {
99bc5d55
JSJ
1268 beiscsi_log(phba, KERN_INFO, BEISCSI_LOG_CONFIG,
1269 "BS_%d : Connection table Not occupied.\n");
6733b39a
JK
1270 return -EINVAL;
1271 }
1272 return 0;
1273}
1274
1275/**
fa95d206
MC
1276 * beiscsi_ep_disconnect - Tears down the TCP connection
1277 * @ep: endpoint to be used
1278 *
1279 * Tears down the TCP connection
6733b39a 1280 */
fa95d206 1281void beiscsi_ep_disconnect(struct iscsi_endpoint *ep)
6733b39a 1282{
fa95d206 1283 struct beiscsi_conn *beiscsi_conn;
6733b39a 1284 struct beiscsi_endpoint *beiscsi_ep;
fa95d206 1285 struct beiscsi_hba *phba;
756d29c8 1286 unsigned int tag;
0a513dd8 1287 uint8_t mgmt_invalidate_flag, tcp_upload_flag;
6733b39a
JK
1288 unsigned short savecfg_flag = CMD_ISCSI_SESSION_SAVE_CFG_ON_FLASH;
1289
fa95d206
MC
1290 beiscsi_ep = ep->dd_data;
1291 phba = beiscsi_ep->phba;
99bc5d55
JSJ
1292 beiscsi_log(phba, KERN_INFO, BEISCSI_LOG_CONFIG,
1293 "BS_%d : In beiscsi_ep_disconnect for ep_cid = %d\n",
1294 beiscsi_ep->ep_cid);
fa95d206 1295
0a513dd8
JSJ
1296 if (beiscsi_ep->conn) {
1297 beiscsi_conn = beiscsi_ep->conn;
1298 iscsi_suspend_queue(beiscsi_conn->conn);
1299 mgmt_invalidate_flag = ~BEISCSI_NO_RST_ISSUE;
1300 tcp_upload_flag = CONNECTION_UPLOAD_GRACEFUL;
1301 } else {
1302 mgmt_invalidate_flag = BEISCSI_NO_RST_ISSUE;
1303 tcp_upload_flag = CONNECTION_UPLOAD_ABORT;
6733b39a 1304 }
fa95d206 1305
756d29c8 1306 tag = mgmt_invalidate_connection(phba, beiscsi_ep,
0a513dd8
JSJ
1307 beiscsi_ep->ep_cid,
1308 mgmt_invalidate_flag,
1309 savecfg_flag);
756d29c8 1310 if (!tag) {
99bc5d55 1311 beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_CONFIG,
0a513dd8 1312 "BS_%d : mgmt_invalidate_connection Failed for cid=%d\n",
99bc5d55 1313 beiscsi_ep->ep_cid);
6733b39a 1314 }
fa95d206 1315
e175defe 1316 beiscsi_mccq_compl(phba, tag, NULL, NULL);
0a513dd8 1317 beiscsi_close_conn(beiscsi_ep, tcp_upload_flag);
c2462288 1318 beiscsi_free_ep(beiscsi_ep);
6733b39a 1319 beiscsi_unbind_conn_to_cid(phba, beiscsi_ep->ep_cid);
fa95d206 1320 iscsi_destroy_endpoint(beiscsi_ep->openiscsi_ep);
6733b39a 1321}
3128c6c7 1322
587a1f16 1323umode_t be2iscsi_attr_is_visible(int param_type, int param)
3128c6c7
MC
1324{
1325 switch (param_type) {
0e43895e
MC
1326 case ISCSI_NET_PARAM:
1327 switch (param) {
1328 case ISCSI_NET_PARAM_IFACE_ENABLE:
1329 case ISCSI_NET_PARAM_IPV4_ADDR:
1330 case ISCSI_NET_PARAM_IPV4_SUBNET:
1331 case ISCSI_NET_PARAM_IPV4_BOOTPROTO:
1332 case ISCSI_NET_PARAM_IPV4_GW:
1333 case ISCSI_NET_PARAM_IPV6_ADDR:
6f72238e
JSJ
1334 case ISCSI_NET_PARAM_VLAN_ID:
1335 case ISCSI_NET_PARAM_VLAN_PRIORITY:
1336 case ISCSI_NET_PARAM_VLAN_ENABLED:
0e43895e
MC
1337 return S_IRUGO;
1338 default:
1339 return 0;
1340 }
f27fb2ef
MC
1341 case ISCSI_HOST_PARAM:
1342 switch (param) {
1343 case ISCSI_HOST_PARAM_HWADDRESS:
c62eef0d
JSJ
1344 case ISCSI_HOST_PARAM_INITIATOR_NAME:
1345 case ISCSI_HOST_PARAM_PORT_STATE:
1346 case ISCSI_HOST_PARAM_PORT_SPEED:
f27fb2ef
MC
1347 return S_IRUGO;
1348 default:
1349 return 0;
1350 }
3128c6c7
MC
1351 case ISCSI_PARAM:
1352 switch (param) {
1353 case ISCSI_PARAM_MAX_RECV_DLENGTH:
1354 case ISCSI_PARAM_MAX_XMIT_DLENGTH:
1355 case ISCSI_PARAM_HDRDGST_EN:
1356 case ISCSI_PARAM_DATADGST_EN:
1357 case ISCSI_PARAM_CONN_ADDRESS:
1358 case ISCSI_PARAM_CONN_PORT:
1359 case ISCSI_PARAM_EXP_STATSN:
1360 case ISCSI_PARAM_PERSISTENT_ADDRESS:
1361 case ISCSI_PARAM_PERSISTENT_PORT:
1362 case ISCSI_PARAM_PING_TMO:
1363 case ISCSI_PARAM_RECV_TMO:
1d063c17
MC
1364 case ISCSI_PARAM_INITIAL_R2T_EN:
1365 case ISCSI_PARAM_MAX_R2T:
1366 case ISCSI_PARAM_IMM_DATA_EN:
1367 case ISCSI_PARAM_FIRST_BURST:
1368 case ISCSI_PARAM_MAX_BURST:
1369 case ISCSI_PARAM_PDU_INORDER_EN:
1370 case ISCSI_PARAM_DATASEQ_INORDER_EN:
1371 case ISCSI_PARAM_ERL:
1372 case ISCSI_PARAM_TARGET_NAME:
1373 case ISCSI_PARAM_TPGT:
1374 case ISCSI_PARAM_USERNAME:
1375 case ISCSI_PARAM_PASSWORD:
1376 case ISCSI_PARAM_USERNAME_IN:
1377 case ISCSI_PARAM_PASSWORD_IN:
1378 case ISCSI_PARAM_FAST_ABORT:
1379 case ISCSI_PARAM_ABORT_TMO:
1380 case ISCSI_PARAM_LU_RESET_TMO:
1381 case ISCSI_PARAM_IFACE_NAME:
1382 case ISCSI_PARAM_INITIATOR_NAME:
3128c6c7
MC
1383 return S_IRUGO;
1384 default:
1385 return 0;
1386 }
1387 }
1388
1389 return 0;
1390}