blob: 46cc40e83b3676a2366942f0ed6074b98351a269 [file] [log] [blame]
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05301/**
Jayamohan Kallickal255fa9a2011-03-25 14:23:57 -07002 * Copyright (C) 2005 - 2011 Emulex
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05303 * 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 *
Jayamohan Kallickal255fa9a2011-03-25 14:23:57 -070010 * Written by: Jayamohan Kallickal (jayamohan.kallickal@emulex.com)
Jayamohan Kallickal6733b392009-09-05 07:36:35 +053011 *
12 * Contact Information:
Jayamohan Kallickal255fa9a2011-03-25 14:23:57 -070013 * linux-drivers@emulex.com
Jayamohan Kallickal6733b392009-09-05 07:36:35 +053014 *
Jayamohan Kallickal255fa9a2011-03-25 14:23:57 -070015 * Emulex
16 * 3333 Susan Street
17 * Costa Mesa, CA 92626
Jayamohan Kallickal6733b392009-09-05 07:36:35 +053018 */
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>
Mike Christie0e438952012-04-03 23:41:51 -050026#include <scsi/scsi_netlink.h>
27#include <net/netlink.h>
Jayamohan Kallickal6733b392009-09-05 07:36:35 +053028#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;
Jayamohan Kallickal6733b392009-09-05 07:36:35 +053048 struct beiscsi_hba *phba;
Jayamohan Kallickalb8b9e1b82009-09-22 08:21:22 +053049 struct iscsi_session *sess;
50 struct beiscsi_session *beiscsi_sess;
Jayamohan Kallickal6733b392009-09-05 07:36:35 +053051 struct beiscsi_io_task *io_task;
Jayamohan Kallickal6733b392009-09-05 07:36:35 +053052
53 SE_DEBUG(DBG_LVL_8, "In beiscsi_session_create\n");
54
55 if (!ep) {
Jayamohan Kallickal457ff3b2010-07-22 04:16:00 +053056 SE_DEBUG(DBG_LVL_1, "beiscsi_session_create: invalid ep\n");
Jayamohan Kallickal6733b392009-09-05 07:36:35 +053057 return NULL;
58 }
59 beiscsi_ep = ep->dd_data;
60 phba = beiscsi_ep->phba;
61 shost = phba->shost;
62 if (cmds_max > beiscsi_ep->phba->params.wrbs_per_cxn) {
63 shost_printk(KERN_ERR, shost, "Cannot handle %d cmds."
64 "Max cmds per session supported is %d. Using %d. "
65 "\n", cmds_max,
66 beiscsi_ep->phba->params.wrbs_per_cxn,
67 beiscsi_ep->phba->params.wrbs_per_cxn);
68 cmds_max = beiscsi_ep->phba->params.wrbs_per_cxn;
69 }
70
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +053071 cls_session = iscsi_session_setup(&beiscsi_iscsi_transport,
72 shost, cmds_max,
73 sizeof(*beiscsi_sess),
74 sizeof(*io_task),
75 initial_cmdsn, ISCSI_MAX_TARGET);
Jayamohan Kallickal6733b392009-09-05 07:36:35 +053076 if (!cls_session)
77 return NULL;
78 sess = cls_session->dd_data;
Jayamohan Kallickal2afc95b2009-09-22 08:22:26 +053079 beiscsi_sess = sess->dd_data;
80 beiscsi_sess->bhs_pool = pci_pool_create("beiscsi_bhs_pool",
81 phba->pcidev,
82 sizeof(struct be_cmd_bhs),
83 64, 0);
84 if (!beiscsi_sess->bhs_pool)
85 goto destroy_sess;
Jayamohan Kallickal6733b392009-09-05 07:36:35 +053086
Jayamohan Kallickal6733b392009-09-05 07:36:35 +053087 return cls_session;
Jayamohan Kallickal2afc95b2009-09-22 08:22:26 +053088destroy_sess:
89 iscsi_session_teardown(cls_session);
90 return NULL;
Jayamohan Kallickal6733b392009-09-05 07:36:35 +053091}
92
93/**
94 * beiscsi_session_destroy - destroys iscsi session
95 * @cls_session: pointer to iscsi cls session
96 *
97 * Destroys iSCSI session instance and releases
98 * resources allocated for it.
99 */
100void beiscsi_session_destroy(struct iscsi_cls_session *cls_session)
101{
Jayamohan Kallickal6733b392009-09-05 07:36:35 +0530102 struct iscsi_session *sess = cls_session->dd_data;
Jayamohan Kallickal2afc95b2009-09-22 08:22:26 +0530103 struct beiscsi_session *beiscsi_sess = sess->dd_data;
Jayamohan Kallickal6733b392009-09-05 07:36:35 +0530104
Jayamohan Kallickal756d29c2010-01-05 05:10:46 +0530105 SE_DEBUG(DBG_LVL_8, "In beiscsi_session_destroy\n");
Jayamohan Kallickal2afc95b2009-09-22 08:22:26 +0530106 pci_pool_destroy(beiscsi_sess->bhs_pool);
Jayamohan Kallickal6733b392009-09-05 07:36:35 +0530107 iscsi_session_teardown(cls_session);
108}
109
110/**
111 * beiscsi_conn_create - create an instance of iscsi connection
112 * @cls_session: ptr to iscsi_cls_session
113 * @cid: iscsi cid
114 */
115struct iscsi_cls_conn *
116beiscsi_conn_create(struct iscsi_cls_session *cls_session, u32 cid)
117{
118 struct beiscsi_hba *phba;
119 struct Scsi_Host *shost;
120 struct iscsi_cls_conn *cls_conn;
121 struct beiscsi_conn *beiscsi_conn;
122 struct iscsi_conn *conn;
Jayamohan Kallickal2afc95b2009-09-22 08:22:26 +0530123 struct iscsi_session *sess;
124 struct beiscsi_session *beiscsi_sess;
Jayamohan Kallickal6733b392009-09-05 07:36:35 +0530125
126 SE_DEBUG(DBG_LVL_8, "In beiscsi_conn_create ,cid"
127 "from iscsi layer=%d\n", cid);
128 shost = iscsi_session_to_shost(cls_session);
129 phba = iscsi_host_priv(shost);
130
131 cls_conn = iscsi_conn_setup(cls_session, sizeof(*beiscsi_conn), cid);
132 if (!cls_conn)
133 return NULL;
134
135 conn = cls_conn->dd_data;
136 beiscsi_conn = conn->dd_data;
137 beiscsi_conn->ep = NULL;
138 beiscsi_conn->phba = phba;
139 beiscsi_conn->conn = conn;
Jayamohan Kallickal2afc95b2009-09-22 08:22:26 +0530140 sess = cls_session->dd_data;
141 beiscsi_sess = sess->dd_data;
142 beiscsi_conn->beiscsi_sess = beiscsi_sess;
Jayamohan Kallickal6733b392009-09-05 07:36:35 +0530143 return cls_conn;
144}
145
146/**
147 * beiscsi_bindconn_cid - Bind the beiscsi_conn with phba connection table
148 * @beiscsi_conn: The pointer to beiscsi_conn structure
149 * @phba: The phba instance
150 * @cid: The cid to free
151 */
152static int beiscsi_bindconn_cid(struct beiscsi_hba *phba,
153 struct beiscsi_conn *beiscsi_conn,
154 unsigned int cid)
155{
156 if (phba->conn_table[cid]) {
157 SE_DEBUG(DBG_LVL_1,
158 "Connection table already occupied. Detected clash\n");
159 return -EINVAL;
160 } else {
Jayamohan Kallickal457ff3b2010-07-22 04:16:00 +0530161 SE_DEBUG(DBG_LVL_8, "phba->conn_table[%d]=%p(beiscsi_conn)\n",
Jayamohan Kallickal6733b392009-09-05 07:36:35 +0530162 cid, beiscsi_conn);
163 phba->conn_table[cid] = beiscsi_conn;
164 }
165 return 0;
166}
167
168/**
169 * beiscsi_conn_bind - Binds iscsi session/connection with TCP connection
170 * @cls_session: pointer to iscsi cls session
171 * @cls_conn: pointer to iscsi cls conn
172 * @transport_fd: EP handle(64 bit)
173 *
174 * This function binds the TCP Conn with iSCSI Connection and Session.
175 */
176int beiscsi_conn_bind(struct iscsi_cls_session *cls_session,
177 struct iscsi_cls_conn *cls_conn,
178 u64 transport_fd, int is_leading)
179{
180 struct iscsi_conn *conn = cls_conn->dd_data;
181 struct beiscsi_conn *beiscsi_conn = conn->dd_data;
Mike Christie3093b042011-07-25 13:48:46 -0500182 struct Scsi_Host *shost = iscsi_session_to_shost(cls_session);
183 struct beiscsi_hba *phba = iscsi_host_priv(shost);
Jayamohan Kallickal6733b392009-09-05 07:36:35 +0530184 struct beiscsi_endpoint *beiscsi_ep;
185 struct iscsi_endpoint *ep;
186
187 SE_DEBUG(DBG_LVL_8, "In beiscsi_conn_bind\n");
188 ep = iscsi_lookup_endpoint(transport_fd);
189 if (!ep)
190 return -EINVAL;
191
192 beiscsi_ep = ep->dd_data;
193
194 if (iscsi_conn_bind(cls_session, cls_conn, is_leading))
195 return -EINVAL;
196
197 if (beiscsi_ep->phba != phba) {
198 SE_DEBUG(DBG_LVL_8,
Jayamohan Kallickal457ff3b2010-07-22 04:16:00 +0530199 "beiscsi_ep->hba=%p not equal to phba=%p\n",
Jayamohan Kallickal6733b392009-09-05 07:36:35 +0530200 beiscsi_ep->phba, phba);
201 return -EEXIST;
202 }
203
204 beiscsi_conn->beiscsi_conn_cid = beiscsi_ep->ep_cid;
205 beiscsi_conn->ep = beiscsi_ep;
206 beiscsi_ep->conn = beiscsi_conn;
Jayamohan Kallickal457ff3b2010-07-22 04:16:00 +0530207 SE_DEBUG(DBG_LVL_8, "beiscsi_conn=%p conn=%p ep_cid=%d\n",
Jayamohan Kallickal6733b392009-09-05 07:36:35 +0530208 beiscsi_conn, conn, beiscsi_ep->ep_cid);
209 return beiscsi_bindconn_cid(phba, beiscsi_conn, beiscsi_ep->ep_cid);
210}
211
Mike Christie0e438952012-04-03 23:41:51 -0500212static int beiscsi_create_ipv4_iface(struct beiscsi_hba *phba)
213{
214 if (phba->ipv4_iface)
215 return 0;
216
217 phba->ipv4_iface = iscsi_create_iface(phba->shost,
218 &beiscsi_iscsi_transport,
219 ISCSI_IFACE_TYPE_IPV4,
220 0, 0);
221 if (!phba->ipv4_iface) {
222 shost_printk(KERN_ERR, phba->shost, "Could not "
223 "create default IPv4 address.\n");
224 return -ENODEV;
225 }
226
227 return 0;
228}
229
230static int beiscsi_create_ipv6_iface(struct beiscsi_hba *phba)
231{
232 if (phba->ipv6_iface)
233 return 0;
234
235 phba->ipv6_iface = iscsi_create_iface(phba->shost,
236 &beiscsi_iscsi_transport,
237 ISCSI_IFACE_TYPE_IPV6,
238 0, 0);
239 if (!phba->ipv6_iface) {
240 shost_printk(KERN_ERR, phba->shost, "Could not "
241 "create default IPv6 address.\n");
242 return -ENODEV;
243 }
244
245 return 0;
246}
247
248void beiscsi_create_def_ifaces(struct beiscsi_hba *phba)
249{
250 struct be_cmd_get_if_info_resp if_info;
251
252 if (!mgmt_get_if_info(phba, BE2_IPV4, &if_info))
253 beiscsi_create_ipv4_iface(phba);
254
255 if (!mgmt_get_if_info(phba, BE2_IPV6, &if_info))
256 beiscsi_create_ipv6_iface(phba);
257}
258
259void beiscsi_destroy_def_ifaces(struct beiscsi_hba *phba)
260{
261 if (phba->ipv6_iface)
262 iscsi_destroy_iface(phba->ipv6_iface);
263 if (phba->ipv4_iface)
264 iscsi_destroy_iface(phba->ipv4_iface);
265}
266
267static int
268beiscsi_set_static_ip(struct Scsi_Host *shost,
269 struct iscsi_iface_param_info *iface_param,
270 void *data, uint32_t dt_len)
271{
272 struct beiscsi_hba *phba = iscsi_host_priv(shost);
273 struct iscsi_iface_param_info *iface_ip = NULL;
274 struct iscsi_iface_param_info *iface_subnet = NULL;
275 struct nlattr *nla;
276 int ret;
277
278
279 switch (iface_param->param) {
280 case ISCSI_NET_PARAM_IPV4_BOOTPROTO:
281 nla = nla_find(data, dt_len, ISCSI_NET_PARAM_IPV4_ADDR);
282 if (nla)
283 iface_ip = nla_data(nla);
284
285 nla = nla_find(data, dt_len, ISCSI_NET_PARAM_IPV4_SUBNET);
286 if (nla)
287 iface_subnet = nla_data(nla);
288 break;
289 case ISCSI_NET_PARAM_IPV4_ADDR:
290 iface_ip = iface_param;
291 nla = nla_find(data, dt_len, ISCSI_NET_PARAM_IPV4_SUBNET);
292 if (nla)
293 iface_subnet = nla_data(nla);
294 break;
295 case ISCSI_NET_PARAM_IPV4_SUBNET:
296 iface_subnet = iface_param;
297 nla = nla_find(data, dt_len, ISCSI_NET_PARAM_IPV4_ADDR);
298 if (nla)
299 iface_ip = nla_data(nla);
300 break;
301 default:
302 shost_printk(KERN_ERR, shost, "Unsupported param %d\n",
303 iface_param->param);
304 }
305
306 if (!iface_ip || !iface_subnet) {
307 shost_printk(KERN_ERR, shost, "IP and Subnet Mask required\n");
308 return -EINVAL;
309 }
310
311 ret = mgmt_set_ip(phba, iface_ip, iface_subnet,
312 ISCSI_BOOTPROTO_STATIC);
313
314 return ret;
315}
316
317static int
318beiscsi_set_ipv4(struct Scsi_Host *shost,
319 struct iscsi_iface_param_info *iface_param,
320 void *data, uint32_t dt_len)
321{
322 struct beiscsi_hba *phba = iscsi_host_priv(shost);
323 int ret = 0;
324
325 /* Check the param */
326 switch (iface_param->param) {
327 case ISCSI_NET_PARAM_IPV4_GW:
328 ret = mgmt_set_gateway(phba, iface_param);
329 break;
330 case ISCSI_NET_PARAM_IPV4_BOOTPROTO:
331 if (iface_param->value[0] == ISCSI_BOOTPROTO_DHCP)
332 ret = mgmt_set_ip(phba, iface_param,
333 NULL, ISCSI_BOOTPROTO_DHCP);
334 else if (iface_param->value[0] == ISCSI_BOOTPROTO_STATIC)
335 ret = beiscsi_set_static_ip(shost, iface_param,
336 data, dt_len);
337 else
338 shost_printk(KERN_ERR, shost, "Invalid BOOTPROTO: %d\n",
339 iface_param->value[0]);
340 break;
341 case ISCSI_NET_PARAM_IFACE_ENABLE:
342 if (iface_param->value[0] == ISCSI_IFACE_ENABLE)
343 ret = beiscsi_create_ipv4_iface(phba);
344 else
345 iscsi_destroy_iface(phba->ipv4_iface);
346 break;
347 case ISCSI_NET_PARAM_IPV4_SUBNET:
348 case ISCSI_NET_PARAM_IPV4_ADDR:
349 ret = beiscsi_set_static_ip(shost, iface_param,
350 data, dt_len);
351 break;
352 default:
353 shost_printk(KERN_ERR, shost, "Param %d not supported\n",
354 iface_param->param);
355 }
356
357 return ret;
358}
359
360static int
361beiscsi_set_ipv6(struct Scsi_Host *shost,
362 struct iscsi_iface_param_info *iface_param,
363 void *data, uint32_t dt_len)
364{
365 struct beiscsi_hba *phba = iscsi_host_priv(shost);
366 int ret = 0;
367
368 switch (iface_param->param) {
369 case ISCSI_NET_PARAM_IFACE_ENABLE:
370 if (iface_param->value[0] == ISCSI_IFACE_ENABLE)
371 ret = beiscsi_create_ipv6_iface(phba);
372 else {
373 iscsi_destroy_iface(phba->ipv6_iface);
374 ret = 0;
375 }
376 break;
377 case ISCSI_NET_PARAM_IPV6_ADDR:
378 ret = mgmt_set_ip(phba, iface_param, NULL,
379 ISCSI_BOOTPROTO_STATIC);
380 break;
381 default:
382 shost_printk(KERN_ERR, shost, "Param %d not supported\n",
383 iface_param->param);
384 }
385
386 return ret;
387}
388
389int be2iscsi_iface_set_param(struct Scsi_Host *shost,
390 void *data, uint32_t dt_len)
391{
392 struct iscsi_iface_param_info *iface_param = NULL;
393 struct nlattr *attrib;
394 uint32_t rm_len = dt_len;
395 int ret = 0 ;
396
397 nla_for_each_attr(attrib, data, dt_len, rm_len) {
398 iface_param = nla_data(attrib);
399
400 if (iface_param->param_type != ISCSI_NET_PARAM)
401 continue;
402
403 /*
404 * BE2ISCSI only supports 1 interface
405 */
406 if (iface_param->iface_num) {
407 shost_printk(KERN_ERR, shost, "Invalid iface_num %d."
408 "Only iface_num 0 is supported.\n",
409 iface_param->iface_num);
410 return -EINVAL;
411 }
412
413 switch (iface_param->iface_type) {
414 case ISCSI_IFACE_TYPE_IPV4:
415 ret = beiscsi_set_ipv4(shost, iface_param,
416 data, dt_len);
417 break;
418 case ISCSI_IFACE_TYPE_IPV6:
419 ret = beiscsi_set_ipv6(shost, iface_param,
420 data, dt_len);
421 break;
422 default:
423 shost_printk(KERN_ERR, shost,
424 "Invalid iface type :%d passed\n",
425 iface_param->iface_type);
426 break;
427 }
428
429 if (ret)
430 return ret;
431 }
432
433 return ret;
434}
435
436static int be2iscsi_get_if_param(struct beiscsi_hba *phba,
437 struct iscsi_iface *iface, int param,
438 char *buf)
439{
440 struct be_cmd_get_if_info_resp if_info;
441 int len, ip_type = BE2_IPV4;
442
443 memset(&if_info, 0, sizeof(if_info));
444
445 if (iface->iface_type == ISCSI_IFACE_TYPE_IPV6)
446 ip_type = BE2_IPV6;
447
448 len = mgmt_get_if_info(phba, ip_type, &if_info);
449 if (len)
450 return len;
451
452 switch (param) {
453 case ISCSI_NET_PARAM_IPV4_ADDR:
454 len = sprintf(buf, "%pI4\n", &if_info.ip_addr.addr);
455 break;
456 case ISCSI_NET_PARAM_IPV6_ADDR:
457 len = sprintf(buf, "%pI6\n", &if_info.ip_addr.addr);
458 break;
459 case ISCSI_NET_PARAM_IPV4_BOOTPROTO:
460 if (!if_info.dhcp_state)
461 len = sprintf(buf, "static");
462 else
463 len = sprintf(buf, "dhcp");
464 break;
465 case ISCSI_NET_PARAM_IPV4_SUBNET:
466 len = sprintf(buf, "%pI4\n", &if_info.ip_addr.subnet_mask);
467 break;
468 default:
469 WARN_ON(1);
470 }
471
472 return len;
473}
474
475int be2iscsi_iface_get_param(struct iscsi_iface *iface,
476 enum iscsi_param_type param_type,
477 int param, char *buf)
478{
479 struct Scsi_Host *shost = iscsi_iface_to_shost(iface);
480 struct beiscsi_hba *phba = iscsi_host_priv(shost);
481 struct be_cmd_get_def_gateway_resp gateway;
482 int len = -ENOSYS;
483
484 switch (param) {
485 case ISCSI_NET_PARAM_IPV4_ADDR:
486 case ISCSI_NET_PARAM_IPV4_SUBNET:
487 case ISCSI_NET_PARAM_IPV4_BOOTPROTO:
488 case ISCSI_NET_PARAM_IPV6_ADDR:
489 len = be2iscsi_get_if_param(phba, iface, param, buf);
490 break;
491 case ISCSI_NET_PARAM_IFACE_ENABLE:
492 len = sprintf(buf, "enabled");
493 break;
494 case ISCSI_NET_PARAM_IPV4_GW:
495 memset(&gateway, 0, sizeof(gateway));
496 len = mgmt_get_gateway(phba, BE2_IPV4, &gateway);
497 if (!len)
498 len = sprintf(buf, "%pI4\n", &gateway.ip_addr.addr);
499 break;
500 default:
501 len = -ENOSYS;
502 }
503
504 return len;
505}
506
Jayamohan Kallickal6733b392009-09-05 07:36:35 +0530507/**
Mike Christiec7f7fd52011-02-16 15:04:41 -0600508 * beiscsi_ep_get_param - get the iscsi parameter
509 * @ep: pointer to iscsi ep
Jayamohan Kallickal6733b392009-09-05 07:36:35 +0530510 * @param: parameter type identifier
511 * @buf: buffer pointer
512 *
513 * returns iscsi parameter
514 */
Mike Christiec7f7fd52011-02-16 15:04:41 -0600515int beiscsi_ep_get_param(struct iscsi_endpoint *ep,
Jayamohan Kallickal6733b392009-09-05 07:36:35 +0530516 enum iscsi_param param, char *buf)
517{
Mike Christiec7f7fd52011-02-16 15:04:41 -0600518 struct beiscsi_endpoint *beiscsi_ep = ep->dd_data;
Jayamohan Kallickal6733b392009-09-05 07:36:35 +0530519 int len = 0;
520
Jayamohan Kallickalb5b93232012-04-03 23:41:40 -0500521 SE_DEBUG(DBG_LVL_8, "In beiscsi_ep_get_param, param= %d\n", param);
Jayamohan Kallickal6733b392009-09-05 07:36:35 +0530522
523 switch (param) {
524 case ISCSI_PARAM_CONN_PORT:
525 len = sprintf(buf, "%hu\n", beiscsi_ep->dst_tcpport);
526 break;
527 case ISCSI_PARAM_CONN_ADDRESS:
528 if (beiscsi_ep->ip_type == BE2_IPV4)
529 len = sprintf(buf, "%pI4\n", &beiscsi_ep->dst_addr);
530 else
531 len = sprintf(buf, "%pI6\n", &beiscsi_ep->dst6_addr);
532 break;
533 default:
Mike Christiec7f7fd52011-02-16 15:04:41 -0600534 return -ENOSYS;
Jayamohan Kallickal6733b392009-09-05 07:36:35 +0530535 }
536 return len;
537}
538
539int beiscsi_set_param(struct iscsi_cls_conn *cls_conn,
540 enum iscsi_param param, char *buf, int buflen)
541{
542 struct iscsi_conn *conn = cls_conn->dd_data;
543 struct iscsi_session *session = conn->session;
544 int ret;
545
Jayamohan Kallickal756d29c2010-01-05 05:10:46 +0530546 SE_DEBUG(DBG_LVL_8, "In beiscsi_conn_set_param, param= %d\n", param);
Jayamohan Kallickal6733b392009-09-05 07:36:35 +0530547 ret = iscsi_set_param(cls_conn, param, buf, buflen);
548 if (ret)
549 return ret;
550 /*
551 * If userspace tried to set the value to higher than we can
552 * support override here.
553 */
554 switch (param) {
555 case ISCSI_PARAM_FIRST_BURST:
556 if (session->first_burst > 8192)
557 session->first_burst = 8192;
558 break;
559 case ISCSI_PARAM_MAX_RECV_DLENGTH:
560 if (conn->max_recv_dlength > 65536)
561 conn->max_recv_dlength = 65536;
562 break;
563 case ISCSI_PARAM_MAX_BURST:
Jayamohan Kallickal230dceb2010-01-23 05:36:10 +0530564 if (session->max_burst > 262144)
565 session->max_burst = 262144;
Jayamohan Kallickal6733b392009-09-05 07:36:35 +0530566 break;
Jayamohan Kallickal42f43c42010-07-22 04:26:45 +0530567 case ISCSI_PARAM_MAX_XMIT_DLENGTH:
568 if ((conn->max_xmit_dlength > 65536) ||
569 (conn->max_xmit_dlength == 0))
570 conn->max_xmit_dlength = 65536;
Jayamohan Kallickal6733b392009-09-05 07:36:35 +0530571 default:
572 return 0;
573 }
574
575 return 0;
576}
577
578/**
John Soni Jose21771992012-04-03 23:41:49 -0500579 * beiscsi_get_initname - Read Initiator Name from flash
580 * @buf: buffer bointer
581 * @phba: The device priv structure instance
582 *
583 * returns number of bytes
584 */
585static int beiscsi_get_initname(char *buf, struct beiscsi_hba *phba)
586{
587 int rc;
588 unsigned int tag, wrb_num;
589 unsigned short status, extd_status;
590 struct be_mcc_wrb *wrb;
591 struct be_cmd_hba_name *resp;
592 struct be_queue_info *mccq = &phba->ctrl.mcc_obj.q;
593
594 tag = be_cmd_get_initname(phba);
595 if (!tag) {
596 SE_DEBUG(DBG_LVL_1, "Getting Initiator Name Failed\n");
597 return -EBUSY;
598 } else
599 wait_event_interruptible(phba->ctrl.mcc_wait[tag],
600 phba->ctrl.mcc_numtag[tag]);
601
602 wrb_num = (phba->ctrl.mcc_numtag[tag] & 0x00FF0000) >> 16;
603 extd_status = (phba->ctrl.mcc_numtag[tag] & 0x0000FF00) >> 8;
604 status = phba->ctrl.mcc_numtag[tag] & 0x000000FF;
605
606 if (status || extd_status) {
607 SE_DEBUG(DBG_LVL_1, "MailBox Command Failed with "
608 "status = %d extd_status = %d\n",
609 status, extd_status);
610 free_mcc_tag(&phba->ctrl, tag);
611 return -EAGAIN;
612 }
613 wrb = queue_get_wrb(mccq, wrb_num);
614 free_mcc_tag(&phba->ctrl, tag);
615 resp = embedded_payload(wrb);
616 rc = sprintf(buf, "%s\n", resp->initiator_name);
617 return rc;
618}
619
620/**
Jayamohan Kallickal6733b392009-09-05 07:36:35 +0530621 * beiscsi_get_host_param - get the iscsi parameter
622 * @shost: pointer to scsi_host structure
623 * @param: parameter type identifier
624 * @buf: buffer pointer
625 *
626 * returns host parameter
627 */
628int beiscsi_get_host_param(struct Scsi_Host *shost,
629 enum iscsi_host_param param, char *buf)
630{
Mike Christie3093b042011-07-25 13:48:46 -0500631 struct beiscsi_hba *phba = iscsi_host_priv(shost);
Jayamohan Kallickalb15d05b2010-08-12 23:36:06 +0530632 int status = 0;
Jayamohan Kallickal6733b392009-09-05 07:36:35 +0530633
Jayamohan Kallickal756d29c2010-01-05 05:10:46 +0530634 SE_DEBUG(DBG_LVL_8, "In beiscsi_get_host_param, param= %d\n", param);
Jayamohan Kallickal6733b392009-09-05 07:36:35 +0530635 switch (param) {
636 case ISCSI_HOST_PARAM_HWADDRESS:
Jayamohan Kallickalc7acc5b2010-07-22 04:29:18 +0530637 status = beiscsi_get_macaddr(buf, phba);
638 if (status < 0) {
639 SE_DEBUG(DBG_LVL_1, "beiscsi_get_macaddr Failed\n");
640 return status;
Jayamohan Kallickal756d29c2010-01-05 05:10:46 +0530641 }
Jayamohan Kallickal6733b392009-09-05 07:36:35 +0530642 break;
John Soni Jose21771992012-04-03 23:41:49 -0500643 case ISCSI_HOST_PARAM_INITIATOR_NAME:
644 status = beiscsi_get_initname(buf, phba);
645 if (status < 0) {
646 SE_DEBUG(DBG_LVL_1,
647 "Retreiving Initiator Name Failed\n");
648 return status;
649 }
650 break;
Jayamohan Kallickal6733b392009-09-05 07:36:35 +0530651 default:
652 return iscsi_host_get_param(shost, param, buf);
653 }
Jayamohan Kallickalb15d05b2010-08-12 23:36:06 +0530654 return status;
Jayamohan Kallickal6733b392009-09-05 07:36:35 +0530655}
656
Jayamohan Kallickalc7acc5b2010-07-22 04:29:18 +0530657int beiscsi_get_macaddr(char *buf, struct beiscsi_hba *phba)
658{
Mike Christie0e438952012-04-03 23:41:51 -0500659 struct be_cmd_get_nic_conf_resp resp;
Jayamohan Kallickalc7acc5b2010-07-22 04:29:18 +0530660 int rc;
661
Mike Christie0e438952012-04-03 23:41:51 -0500662 if (strlen(phba->mac_address))
663 return strlcpy(buf, phba->mac_address, PAGE_SIZE);
Jayamohan Kallickalc7acc5b2010-07-22 04:29:18 +0530664
Mike Christie0e438952012-04-03 23:41:51 -0500665 memset(&resp, 0, sizeof(resp));
666 rc = mgmt_get_nic_conf(phba, &resp);
667 if (rc)
668 return rc;
Jayamohan Kallickalc7acc5b2010-07-22 04:29:18 +0530669
Mike Christie0e438952012-04-03 23:41:51 -0500670 memcpy(phba->mac_address, resp.mac_address, ETH_ALEN);
671 return sysfs_format_mac(buf, phba->mac_address, ETH_ALEN);
Jayamohan Kallickalc7acc5b2010-07-22 04:29:18 +0530672}
673
Jayamohan Kallickal6733b392009-09-05 07:36:35 +0530674/**
675 * beiscsi_conn_get_stats - get the iscsi stats
676 * @cls_conn: pointer to iscsi cls conn
677 * @stats: pointer to iscsi_stats structure
678 *
679 * returns iscsi stats
680 */
681void beiscsi_conn_get_stats(struct iscsi_cls_conn *cls_conn,
682 struct iscsi_stats *stats)
683{
684 struct iscsi_conn *conn = cls_conn->dd_data;
685
686 SE_DEBUG(DBG_LVL_8, "In beiscsi_conn_get_stats\n");
687 stats->txdata_octets = conn->txdata_octets;
688 stats->rxdata_octets = conn->rxdata_octets;
689 stats->dataout_pdus = conn->dataout_pdus_cnt;
690 stats->scsirsp_pdus = conn->scsirsp_pdus_cnt;
691 stats->scsicmd_pdus = conn->scsicmd_pdus_cnt;
692 stats->datain_pdus = conn->datain_pdus_cnt;
693 stats->tmfrsp_pdus = conn->tmfrsp_pdus_cnt;
694 stats->tmfcmd_pdus = conn->tmfcmd_pdus_cnt;
695 stats->r2t_pdus = conn->r2t_pdus_cnt;
696 stats->digest_err = 0;
697 stats->timeout_err = 0;
698 stats->custom_length = 0;
699 strcpy(stats->custom[0].desc, "eh_abort_cnt");
700 stats->custom[0].value = conn->eh_abort_cnt;
701}
702
703/**
704 * beiscsi_set_params_for_offld - get the parameters for offload
705 * @beiscsi_conn: pointer to beiscsi_conn
706 * @params: pointer to offload_params structure
707 */
708static void beiscsi_set_params_for_offld(struct beiscsi_conn *beiscsi_conn,
709 struct beiscsi_offload_params *params)
710{
711 struct iscsi_conn *conn = beiscsi_conn->conn;
712 struct iscsi_session *session = conn->session;
713
714 AMAP_SET_BITS(struct amap_beiscsi_offload_params, max_burst_length,
715 params, session->max_burst);
716 AMAP_SET_BITS(struct amap_beiscsi_offload_params,
717 max_send_data_segment_length, params,
718 conn->max_xmit_dlength);
719 AMAP_SET_BITS(struct amap_beiscsi_offload_params, first_burst_length,
720 params, session->first_burst);
721 AMAP_SET_BITS(struct amap_beiscsi_offload_params, erl, params,
722 session->erl);
723 AMAP_SET_BITS(struct amap_beiscsi_offload_params, dde, params,
724 conn->datadgst_en);
725 AMAP_SET_BITS(struct amap_beiscsi_offload_params, hde, params,
726 conn->hdrdgst_en);
727 AMAP_SET_BITS(struct amap_beiscsi_offload_params, ir2t, params,
728 session->initial_r2t_en);
729 AMAP_SET_BITS(struct amap_beiscsi_offload_params, imd, params,
730 session->imm_data_en);
731 AMAP_SET_BITS(struct amap_beiscsi_offload_params, exp_statsn, params,
732 (conn->exp_statsn - 1));
733}
734
735/**
736 * beiscsi_conn_start - offload of session to chip
737 * @cls_conn: pointer to beiscsi_conn
738 */
739int beiscsi_conn_start(struct iscsi_cls_conn *cls_conn)
740{
741 struct iscsi_conn *conn = cls_conn->dd_data;
742 struct beiscsi_conn *beiscsi_conn = conn->dd_data;
743 struct beiscsi_endpoint *beiscsi_ep;
744 struct beiscsi_offload_params params;
Jayamohan Kallickal6733b392009-09-05 07:36:35 +0530745
Jayamohan Kallickal756d29c2010-01-05 05:10:46 +0530746 SE_DEBUG(DBG_LVL_8, "In beiscsi_conn_start\n");
Jayamohan Kallickal6733b392009-09-05 07:36:35 +0530747 memset(&params, 0, sizeof(struct beiscsi_offload_params));
748 beiscsi_ep = beiscsi_conn->ep;
749 if (!beiscsi_ep)
750 SE_DEBUG(DBG_LVL_1, "In beiscsi_conn_start , no beiscsi_ep\n");
751
Jayamohan Kallickal6733b392009-09-05 07:36:35 +0530752 beiscsi_conn->login_in_progress = 0;
753 beiscsi_set_params_for_offld(beiscsi_conn, &params);
754 beiscsi_offload_connection(beiscsi_conn, &params);
755 iscsi_conn_start(cls_conn);
756 return 0;
757}
758
759/**
760 * beiscsi_get_cid - Allocate a cid
761 * @phba: The phba instance
762 */
763static int beiscsi_get_cid(struct beiscsi_hba *phba)
764{
765 unsigned short cid = 0xFFFF;
766
767 if (!phba->avlbl_cids)
768 return cid;
769
770 cid = phba->cid_array[phba->cid_alloc++];
771 if (phba->cid_alloc == phba->params.cxns_per_ctrl)
772 phba->cid_alloc = 0;
773 phba->avlbl_cids--;
774 return cid;
775}
776
777/**
Mike Christiefa95d202010-06-09 03:30:08 -0500778 * beiscsi_put_cid - Free the cid
779 * @phba: The phba for which the cid is being freed
780 * @cid: The cid to free
781 */
782static void beiscsi_put_cid(struct beiscsi_hba *phba, unsigned short cid)
783{
784 phba->avlbl_cids++;
785 phba->cid_array[phba->cid_free++] = cid;
786 if (phba->cid_free == phba->params.cxns_per_ctrl)
787 phba->cid_free = 0;
788}
789
790/**
791 * beiscsi_free_ep - free endpoint
792 * @ep: pointer to iscsi endpoint structure
793 */
794static void beiscsi_free_ep(struct beiscsi_endpoint *beiscsi_ep)
795{
796 struct beiscsi_hba *phba = beiscsi_ep->phba;
797
798 beiscsi_put_cid(phba, beiscsi_ep->ep_cid);
799 beiscsi_ep->phba = NULL;
800}
801
802/**
Jayamohan Kallickal6733b392009-09-05 07:36:35 +0530803 * beiscsi_open_conn - Ask FW to open a TCP connection
804 * @ep: endpoint to be used
805 * @src_addr: The source IP address
806 * @dst_addr: The Destination IP address
807 *
808 * Asks the FW to open a TCP connection
809 */
810static int beiscsi_open_conn(struct iscsi_endpoint *ep,
811 struct sockaddr *src_addr,
812 struct sockaddr *dst_addr, int non_blocking)
813{
814 struct beiscsi_endpoint *beiscsi_ep = ep->dd_data;
815 struct beiscsi_hba *phba = beiscsi_ep->phba;
Jayamohan Kallickal756d29c2010-01-05 05:10:46 +0530816 struct be_queue_info *mccq = &phba->ctrl.mcc_obj.q;
817 struct be_mcc_wrb *wrb;
818 struct tcp_connect_and_offload_out *ptcpcnct_out;
819 unsigned short status, extd_status;
Jayamohan Kallickal3cbb7a72010-07-22 04:27:47 +0530820 struct be_dma_mem nonemb_cmd;
Jayamohan Kallickal756d29c2010-01-05 05:10:46 +0530821 unsigned int tag, wrb_num;
Jayamohan Kallickald3ad2bb2010-07-22 04:16:38 +0530822 int ret = -ENOMEM;
Jayamohan Kallickal6733b392009-09-05 07:36:35 +0530823
Jayamohan Kallickal756d29c2010-01-05 05:10:46 +0530824 SE_DEBUG(DBG_LVL_8, "In beiscsi_open_conn\n");
Jayamohan Kallickal6733b392009-09-05 07:36:35 +0530825 beiscsi_ep->ep_cid = beiscsi_get_cid(phba);
826 if (beiscsi_ep->ep_cid == 0xFFFF) {
827 SE_DEBUG(DBG_LVL_1, "No free cid available\n");
828 return ret;
829 }
Jayamohan Kallickal457ff3b2010-07-22 04:16:00 +0530830 SE_DEBUG(DBG_LVL_8, "In beiscsi_open_conn, ep_cid=%d\n",
Jayamohan Kallickal6733b392009-09-05 07:36:35 +0530831 beiscsi_ep->ep_cid);
Jayamohan Kallickal7da50872010-01-05 05:04:12 +0530832 phba->ep_array[beiscsi_ep->ep_cid -
833 phba->fw_config.iscsi_cid_start] = ep;
834 if (beiscsi_ep->ep_cid > (phba->fw_config.iscsi_cid_start +
835 phba->params.cxns_per_ctrl * 2)) {
Jayamohan Kallickal6733b392009-09-05 07:36:35 +0530836 SE_DEBUG(DBG_LVL_1, "Failed in allocate iscsi cid\n");
Mike Christiefa95d202010-06-09 03:30:08 -0500837 goto free_ep;
Jayamohan Kallickal6733b392009-09-05 07:36:35 +0530838 }
839
840 beiscsi_ep->cid_vld = 0;
Jayamohan Kallickal3cbb7a72010-07-22 04:27:47 +0530841 nonemb_cmd.va = pci_alloc_consistent(phba->ctrl.pdev,
842 sizeof(struct tcp_connect_and_offload_in),
843 &nonemb_cmd.dma);
844 if (nonemb_cmd.va == NULL) {
845 SE_DEBUG(DBG_LVL_1,
846 "Failed to allocate memory for mgmt_open_connection"
847 "\n");
848 beiscsi_put_cid(phba, beiscsi_ep->ep_cid);
849 return -ENOMEM;
850 }
851 nonemb_cmd.size = sizeof(struct tcp_connect_and_offload_in);
852 memset(nonemb_cmd.va, 0, nonemb_cmd.size);
853 tag = mgmt_open_connection(phba, dst_addr, beiscsi_ep, &nonemb_cmd);
Jayamohan Kallickal756d29c2010-01-05 05:10:46 +0530854 if (!tag) {
855 SE_DEBUG(DBG_LVL_1,
Jayamohan Kallickal457ff3b2010-07-22 04:16:00 +0530856 "mgmt_open_connection Failed for cid=%d\n",
Jayamohan Kallickal756d29c2010-01-05 05:10:46 +0530857 beiscsi_ep->ep_cid);
Jayamohan Kallickal1f926382010-07-22 04:22:27 +0530858 beiscsi_put_cid(phba, beiscsi_ep->ep_cid);
Jayamohan Kallickal3cbb7a72010-07-22 04:27:47 +0530859 pci_free_consistent(phba->ctrl.pdev, nonemb_cmd.size,
860 nonemb_cmd.va, nonemb_cmd.dma);
Jayamohan Kallickal1f926382010-07-22 04:22:27 +0530861 return -EAGAIN;
Jayamohan Kallickal756d29c2010-01-05 05:10:46 +0530862 } else {
863 wait_event_interruptible(phba->ctrl.mcc_wait[tag],
864 phba->ctrl.mcc_numtag[tag]);
865 }
866 wrb_num = (phba->ctrl.mcc_numtag[tag] & 0x00FF0000) >> 16;
867 extd_status = (phba->ctrl.mcc_numtag[tag] & 0x0000FF00) >> 8;
868 status = phba->ctrl.mcc_numtag[tag] & 0x000000FF;
869 if (status || extd_status) {
870 SE_DEBUG(DBG_LVL_1, "mgmt_open_connection Failed"
Mike Christiefa95d202010-06-09 03:30:08 -0500871 " status = %d extd_status = %d\n",
Jayamohan Kallickal756d29c2010-01-05 05:10:46 +0530872 status, extd_status);
873 free_mcc_tag(&phba->ctrl, tag);
Jayamohan Kallickal3cbb7a72010-07-22 04:27:47 +0530874 pci_free_consistent(phba->ctrl.pdev, nonemb_cmd.size,
875 nonemb_cmd.va, nonemb_cmd.dma);
Mike Christiefa95d202010-06-09 03:30:08 -0500876 goto free_ep;
Jayamohan Kallickal756d29c2010-01-05 05:10:46 +0530877 } else {
878 wrb = queue_get_wrb(mccq, wrb_num);
879 free_mcc_tag(&phba->ctrl, tag);
880
Jayamohan Kallickal457ff3b2010-07-22 04:16:00 +0530881 ptcpcnct_out = embedded_payload(wrb);
Jayamohan Kallickal756d29c2010-01-05 05:10:46 +0530882 beiscsi_ep = ep->dd_data;
883 beiscsi_ep->fw_handle = ptcpcnct_out->connection_handle;
884 beiscsi_ep->cid_vld = 1;
885 SE_DEBUG(DBG_LVL_8, "mgmt_open_connection Success\n");
886 }
Jayamohan Kallickal3cbb7a72010-07-22 04:27:47 +0530887 pci_free_consistent(phba->ctrl.pdev, nonemb_cmd.size,
888 nonemb_cmd.va, nonemb_cmd.dma);
Jayamohan Kallickal756d29c2010-01-05 05:10:46 +0530889 return 0;
Jayamohan Kallickal6733b392009-09-05 07:36:35 +0530890
Mike Christiefa95d202010-06-09 03:30:08 -0500891free_ep:
892 beiscsi_free_ep(beiscsi_ep);
Jayamohan Kallickald3ad2bb2010-07-22 04:16:38 +0530893 return -EBUSY;
Jayamohan Kallickal6733b392009-09-05 07:36:35 +0530894}
895
896/**
897 * beiscsi_ep_connect - Ask chip to create TCP Conn
898 * @scsi_host: Pointer to scsi_host structure
899 * @dst_addr: The IP address of Target
900 * @non_blocking: blocking or non-blocking call
901 *
902 * This routines first asks chip to create a connection and then allocates an EP
903 */
904struct iscsi_endpoint *
905beiscsi_ep_connect(struct Scsi_Host *shost, struct sockaddr *dst_addr,
906 int non_blocking)
907{
908 struct beiscsi_hba *phba;
909 struct beiscsi_endpoint *beiscsi_ep;
910 struct iscsi_endpoint *ep;
911 int ret;
912
Jayamohan Kallickal457ff3b2010-07-22 04:16:00 +0530913 SE_DEBUG(DBG_LVL_8, "In beiscsi_ep_connect\n");
Jayamohan Kallickal6733b392009-09-05 07:36:35 +0530914 if (shost)
915 phba = iscsi_host_priv(shost);
916 else {
917 ret = -ENXIO;
Jayamohan Kallickal457ff3b2010-07-22 04:16:00 +0530918 SE_DEBUG(DBG_LVL_1, "shost is NULL\n");
Jayamohan Kallickal6733b392009-09-05 07:36:35 +0530919 return ERR_PTR(ret);
920 }
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +0530921
Jayamohan Kallickal5dc1c412010-01-23 05:36:52 +0530922 if (phba->state != BE_ADAPTER_UP) {
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +0530923 ret = -EBUSY;
Jayamohan Kallickal457ff3b2010-07-22 04:16:00 +0530924 SE_DEBUG(DBG_LVL_1, "The Adapter state is Not UP\n");
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +0530925 return ERR_PTR(ret);
926 }
927
Jayamohan Kallickal6733b392009-09-05 07:36:35 +0530928 ep = iscsi_create_endpoint(sizeof(struct beiscsi_endpoint));
929 if (!ep) {
930 ret = -ENOMEM;
931 return ERR_PTR(ret);
932 }
933
934 beiscsi_ep = ep->dd_data;
935 beiscsi_ep->phba = phba;
Jayamohan Kallickalc2462282010-01-05 05:05:34 +0530936 beiscsi_ep->openiscsi_ep = ep;
Jayamohan Kallickalf5ed7bd2010-07-22 04:18:01 +0530937 ret = beiscsi_open_conn(ep, NULL, dst_addr, non_blocking);
938 if (ret) {
Jayamohan Kallickal457ff3b2010-07-22 04:16:00 +0530939 SE_DEBUG(DBG_LVL_1, "Failed in beiscsi_open_conn\n");
Jayamohan Kallickal6733b392009-09-05 07:36:35 +0530940 goto free_ep;
941 }
942
943 return ep;
944
945free_ep:
Mike Christiefa95d202010-06-09 03:30:08 -0500946 iscsi_destroy_endpoint(ep);
Jayamohan Kallickal6733b392009-09-05 07:36:35 +0530947 return ERR_PTR(ret);
948}
949
950/**
951 * beiscsi_ep_poll - Poll to see if connection is established
952 * @ep: endpoint to be used
953 * @timeout_ms: timeout specified in millisecs
954 *
955 * Poll to see if TCP connection established
956 */
957int beiscsi_ep_poll(struct iscsi_endpoint *ep, int timeout_ms)
958{
959 struct beiscsi_endpoint *beiscsi_ep = ep->dd_data;
960
961 SE_DEBUG(DBG_LVL_8, "In beiscsi_ep_poll\n");
962 if (beiscsi_ep->cid_vld == 1)
963 return 1;
964 else
965 return 0;
966}
967
968/**
969 * beiscsi_close_conn - Upload the connection
970 * @ep: The iscsi endpoint
971 * @flag: The type of connection closure
972 */
Jayamohan Kallickalc2462282010-01-05 05:05:34 +0530973static int beiscsi_close_conn(struct beiscsi_endpoint *beiscsi_ep, int flag)
Jayamohan Kallickal6733b392009-09-05 07:36:35 +0530974{
975 int ret = 0;
Jayamohan Kallickal756d29c2010-01-05 05:10:46 +0530976 unsigned int tag;
Jayamohan Kallickal6733b392009-09-05 07:36:35 +0530977 struct beiscsi_hba *phba = beiscsi_ep->phba;
978
Jayamohan Kallickal756d29c2010-01-05 05:10:46 +0530979 tag = mgmt_upload_connection(phba, beiscsi_ep->ep_cid, flag);
980 if (!tag) {
Jayamohan Kallickal457ff3b2010-07-22 04:16:00 +0530981 SE_DEBUG(DBG_LVL_8, "upload failed for cid 0x%x\n",
Jayamohan Kallickal6733b392009-09-05 07:36:35 +0530982 beiscsi_ep->ep_cid);
Jayamohan Kallickald3ad2bb2010-07-22 04:16:38 +0530983 ret = -EAGAIN;
Jayamohan Kallickal756d29c2010-01-05 05:10:46 +0530984 } else {
985 wait_event_interruptible(phba->ctrl.mcc_wait[tag],
986 phba->ctrl.mcc_numtag[tag]);
987 free_mcc_tag(&phba->ctrl, tag);
Jayamohan Kallickal6733b392009-09-05 07:36:35 +0530988 }
Jayamohan Kallickal6733b392009-09-05 07:36:35 +0530989 return ret;
990}
991
992/**
Jayamohan Kallickal6733b392009-09-05 07:36:35 +0530993 * beiscsi_unbind_conn_to_cid - Unbind the beiscsi_conn from phba conn table
994 * @phba: The phba instance
995 * @cid: The cid to free
996 */
997static int beiscsi_unbind_conn_to_cid(struct beiscsi_hba *phba,
998 unsigned int cid)
999{
1000 if (phba->conn_table[cid])
1001 phba->conn_table[cid] = NULL;
1002 else {
Jayamohan Kallickal457ff3b2010-07-22 04:16:00 +05301003 SE_DEBUG(DBG_LVL_8, "Connection table Not occupied.\n");
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05301004 return -EINVAL;
1005 }
1006 return 0;
1007}
1008
1009/**
Mike Christiefa95d202010-06-09 03:30:08 -05001010 * beiscsi_ep_disconnect - Tears down the TCP connection
1011 * @ep: endpoint to be used
1012 *
1013 * Tears down the TCP connection
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05301014 */
Mike Christiefa95d202010-06-09 03:30:08 -05001015void beiscsi_ep_disconnect(struct iscsi_endpoint *ep)
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05301016{
Mike Christiefa95d202010-06-09 03:30:08 -05001017 struct beiscsi_conn *beiscsi_conn;
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05301018 struct beiscsi_endpoint *beiscsi_ep;
Mike Christiefa95d202010-06-09 03:30:08 -05001019 struct beiscsi_hba *phba;
Jayamohan Kallickal756d29c2010-01-05 05:10:46 +05301020 unsigned int tag;
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05301021 unsigned short savecfg_flag = CMD_ISCSI_SESSION_SAVE_CFG_ON_FLASH;
1022
Mike Christiefa95d202010-06-09 03:30:08 -05001023 beiscsi_ep = ep->dd_data;
1024 phba = beiscsi_ep->phba;
1025 SE_DEBUG(DBG_LVL_8, "In beiscsi_ep_disconnect for ep_cid = %d\n",
1026 beiscsi_ep->ep_cid);
1027
1028 if (!beiscsi_ep->conn) {
1029 SE_DEBUG(DBG_LVL_8, "In beiscsi_ep_disconnect, no "
1030 "beiscsi_ep\n");
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05301031 return;
1032 }
Mike Christiefa95d202010-06-09 03:30:08 -05001033 beiscsi_conn = beiscsi_ep->conn;
1034 iscsi_suspend_queue(beiscsi_conn->conn);
1035
1036 SE_DEBUG(DBG_LVL_8, "In beiscsi_ep_disconnect ep_cid = %d\n",
1037 beiscsi_ep->ep_cid);
1038
Jayamohan Kallickal756d29c2010-01-05 05:10:46 +05301039 tag = mgmt_invalidate_connection(phba, beiscsi_ep,
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05301040 beiscsi_ep->ep_cid, 1,
1041 savecfg_flag);
Jayamohan Kallickal756d29c2010-01-05 05:10:46 +05301042 if (!tag) {
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05301043 SE_DEBUG(DBG_LVL_1,
Jayamohan Kallickal457ff3b2010-07-22 04:16:00 +05301044 "mgmt_invalidate_connection Failed for cid=%d\n",
Jayamohan Kallickal90a289e2010-02-20 08:04:28 +05301045 beiscsi_ep->ep_cid);
Jayamohan Kallickal756d29c2010-01-05 05:10:46 +05301046 } else {
1047 wait_event_interruptible(phba->ctrl.mcc_wait[tag],
1048 phba->ctrl.mcc_numtag[tag]);
1049 free_mcc_tag(&phba->ctrl, tag);
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05301050 }
Mike Christiefa95d202010-06-09 03:30:08 -05001051
Jayamohan Kallickalc2462282010-01-05 05:05:34 +05301052 beiscsi_close_conn(beiscsi_ep, CONNECTION_UPLOAD_GRACEFUL);
1053 beiscsi_free_ep(beiscsi_ep);
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05301054 beiscsi_unbind_conn_to_cid(phba, beiscsi_ep->ep_cid);
Mike Christiefa95d202010-06-09 03:30:08 -05001055 iscsi_destroy_endpoint(beiscsi_ep->openiscsi_ep);
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05301056}
Mike Christie3128c6c2011-07-25 13:48:42 -05001057
Al Viro587a1f12011-07-23 23:11:19 -04001058umode_t be2iscsi_attr_is_visible(int param_type, int param)
Mike Christie3128c6c2011-07-25 13:48:42 -05001059{
1060 switch (param_type) {
Mike Christie0e438952012-04-03 23:41:51 -05001061 case ISCSI_NET_PARAM:
1062 switch (param) {
1063 case ISCSI_NET_PARAM_IFACE_ENABLE:
1064 case ISCSI_NET_PARAM_IPV4_ADDR:
1065 case ISCSI_NET_PARAM_IPV4_SUBNET:
1066 case ISCSI_NET_PARAM_IPV4_BOOTPROTO:
1067 case ISCSI_NET_PARAM_IPV4_GW:
1068 case ISCSI_NET_PARAM_IPV6_ADDR:
1069 return S_IRUGO;
1070 default:
1071 return 0;
1072 }
Mike Christief27fb2e2011-07-25 13:48:45 -05001073 case ISCSI_HOST_PARAM:
1074 switch (param) {
1075 case ISCSI_HOST_PARAM_HWADDRESS:
Mike Christief27fb2e2011-07-25 13:48:45 -05001076 return S_IRUGO;
1077 default:
1078 return 0;
1079 }
Mike Christie3128c6c2011-07-25 13:48:42 -05001080 case ISCSI_PARAM:
1081 switch (param) {
1082 case ISCSI_PARAM_MAX_RECV_DLENGTH:
1083 case ISCSI_PARAM_MAX_XMIT_DLENGTH:
1084 case ISCSI_PARAM_HDRDGST_EN:
1085 case ISCSI_PARAM_DATADGST_EN:
1086 case ISCSI_PARAM_CONN_ADDRESS:
1087 case ISCSI_PARAM_CONN_PORT:
1088 case ISCSI_PARAM_EXP_STATSN:
1089 case ISCSI_PARAM_PERSISTENT_ADDRESS:
1090 case ISCSI_PARAM_PERSISTENT_PORT:
1091 case ISCSI_PARAM_PING_TMO:
1092 case ISCSI_PARAM_RECV_TMO:
Mike Christie1d063c12011-07-25 13:48:43 -05001093 case ISCSI_PARAM_INITIAL_R2T_EN:
1094 case ISCSI_PARAM_MAX_R2T:
1095 case ISCSI_PARAM_IMM_DATA_EN:
1096 case ISCSI_PARAM_FIRST_BURST:
1097 case ISCSI_PARAM_MAX_BURST:
1098 case ISCSI_PARAM_PDU_INORDER_EN:
1099 case ISCSI_PARAM_DATASEQ_INORDER_EN:
1100 case ISCSI_PARAM_ERL:
1101 case ISCSI_PARAM_TARGET_NAME:
1102 case ISCSI_PARAM_TPGT:
1103 case ISCSI_PARAM_USERNAME:
1104 case ISCSI_PARAM_PASSWORD:
1105 case ISCSI_PARAM_USERNAME_IN:
1106 case ISCSI_PARAM_PASSWORD_IN:
1107 case ISCSI_PARAM_FAST_ABORT:
1108 case ISCSI_PARAM_ABORT_TMO:
1109 case ISCSI_PARAM_LU_RESET_TMO:
1110 case ISCSI_PARAM_IFACE_NAME:
1111 case ISCSI_PARAM_INITIATOR_NAME:
Mike Christie3128c6c2011-07-25 13:48:42 -05001112 return S_IRUGO;
1113 default:
1114 return 0;
1115 }
1116 }
1117
1118 return 0;
1119}