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