[SCSI] be2iscsi: Format the MAC_ADDR with sysfs_format_mac.
[linux-2.6-block.git] / drivers / scsi / be2iscsi / be_iscsi.c
CommitLineData
6733b39a 1/**
255fa9a3 2 * Copyright (C) 2005 - 2011 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{
164 if (phba->conn_table[cid]) {
99bc5d55
JSJ
165 beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_CONFIG,
166 "BS_%d : Connection table already occupied. Detected clash\n");
167
6733b39a
JK
168 return -EINVAL;
169 } else {
99bc5d55
JSJ
170 beiscsi_log(phba, KERN_INFO, BEISCSI_LOG_CONFIG,
171 "BS_%d : phba->conn_table[%d]=%p(beiscsi_conn)\n",
172 cid, beiscsi_conn);
173
6733b39a
JK
174 phba->conn_table[cid] = beiscsi_conn;
175 }
176 return 0;
177}
178
179/**
180 * beiscsi_conn_bind - Binds iscsi session/connection with TCP connection
181 * @cls_session: pointer to iscsi cls session
182 * @cls_conn: pointer to iscsi cls conn
183 * @transport_fd: EP handle(64 bit)
184 *
185 * This function binds the TCP Conn with iSCSI Connection and Session.
186 */
187int beiscsi_conn_bind(struct iscsi_cls_session *cls_session,
188 struct iscsi_cls_conn *cls_conn,
189 u64 transport_fd, int is_leading)
190{
191 struct iscsi_conn *conn = cls_conn->dd_data;
192 struct beiscsi_conn *beiscsi_conn = conn->dd_data;
3093b048
MC
193 struct Scsi_Host *shost = iscsi_session_to_shost(cls_session);
194 struct beiscsi_hba *phba = iscsi_host_priv(shost);
6733b39a
JK
195 struct beiscsi_endpoint *beiscsi_ep;
196 struct iscsi_endpoint *ep;
197
6733b39a
JK
198 ep = iscsi_lookup_endpoint(transport_fd);
199 if (!ep)
200 return -EINVAL;
201
202 beiscsi_ep = ep->dd_data;
203
204 if (iscsi_conn_bind(cls_session, cls_conn, is_leading))
205 return -EINVAL;
206
207 if (beiscsi_ep->phba != phba) {
99bc5d55
JSJ
208 beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_CONFIG,
209 "BS_%d : beiscsi_ep->hba=%p not equal to phba=%p\n",
210 beiscsi_ep->phba, phba);
211
6733b39a
JK
212 return -EEXIST;
213 }
214
215 beiscsi_conn->beiscsi_conn_cid = beiscsi_ep->ep_cid;
216 beiscsi_conn->ep = beiscsi_ep;
217 beiscsi_ep->conn = beiscsi_conn;
99bc5d55
JSJ
218
219 beiscsi_log(phba, KERN_INFO, BEISCSI_LOG_CONFIG,
220 "BS_%d : beiscsi_conn=%p conn=%p ep_cid=%d\n",
221 beiscsi_conn, conn, beiscsi_ep->ep_cid);
222
6733b39a
JK
223 return beiscsi_bindconn_cid(phba, beiscsi_conn, beiscsi_ep->ep_cid);
224}
225
0e43895e
MC
226static int beiscsi_create_ipv4_iface(struct beiscsi_hba *phba)
227{
228 if (phba->ipv4_iface)
229 return 0;
230
231 phba->ipv4_iface = iscsi_create_iface(phba->shost,
232 &beiscsi_iscsi_transport,
233 ISCSI_IFACE_TYPE_IPV4,
234 0, 0);
235 if (!phba->ipv4_iface) {
99bc5d55
JSJ
236 beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_CONFIG,
237 "BS_%d : Could not "
238 "create default IPv4 address.\n");
0e43895e
MC
239 return -ENODEV;
240 }
241
242 return 0;
243}
244
245static int beiscsi_create_ipv6_iface(struct beiscsi_hba *phba)
246{
247 if (phba->ipv6_iface)
248 return 0;
249
250 phba->ipv6_iface = iscsi_create_iface(phba->shost,
251 &beiscsi_iscsi_transport,
252 ISCSI_IFACE_TYPE_IPV6,
253 0, 0);
254 if (!phba->ipv6_iface) {
99bc5d55
JSJ
255 beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_CONFIG,
256 "BS_%d : Could not "
257 "create default IPv6 address.\n");
0e43895e
MC
258 return -ENODEV;
259 }
260
261 return 0;
262}
263
264void beiscsi_create_def_ifaces(struct beiscsi_hba *phba)
265{
266 struct be_cmd_get_if_info_resp if_info;
267
268 if (!mgmt_get_if_info(phba, BE2_IPV4, &if_info))
269 beiscsi_create_ipv4_iface(phba);
270
271 if (!mgmt_get_if_info(phba, BE2_IPV6, &if_info))
272 beiscsi_create_ipv6_iface(phba);
273}
274
275void beiscsi_destroy_def_ifaces(struct beiscsi_hba *phba)
276{
277 if (phba->ipv6_iface)
278 iscsi_destroy_iface(phba->ipv6_iface);
279 if (phba->ipv4_iface)
280 iscsi_destroy_iface(phba->ipv4_iface);
281}
282
283static int
284beiscsi_set_static_ip(struct Scsi_Host *shost,
285 struct iscsi_iface_param_info *iface_param,
286 void *data, uint32_t dt_len)
287{
288 struct beiscsi_hba *phba = iscsi_host_priv(shost);
289 struct iscsi_iface_param_info *iface_ip = NULL;
290 struct iscsi_iface_param_info *iface_subnet = NULL;
291 struct nlattr *nla;
292 int ret;
293
294
295 switch (iface_param->param) {
296 case ISCSI_NET_PARAM_IPV4_BOOTPROTO:
297 nla = nla_find(data, dt_len, ISCSI_NET_PARAM_IPV4_ADDR);
298 if (nla)
299 iface_ip = nla_data(nla);
300
301 nla = nla_find(data, dt_len, ISCSI_NET_PARAM_IPV4_SUBNET);
302 if (nla)
303 iface_subnet = nla_data(nla);
304 break;
305 case ISCSI_NET_PARAM_IPV4_ADDR:
306 iface_ip = iface_param;
307 nla = nla_find(data, dt_len, ISCSI_NET_PARAM_IPV4_SUBNET);
308 if (nla)
309 iface_subnet = nla_data(nla);
310 break;
311 case ISCSI_NET_PARAM_IPV4_SUBNET:
312 iface_subnet = iface_param;
313 nla = nla_find(data, dt_len, ISCSI_NET_PARAM_IPV4_ADDR);
314 if (nla)
315 iface_ip = nla_data(nla);
316 break;
317 default:
99bc5d55
JSJ
318 beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_CONFIG,
319 "BS_%d : Unsupported param %d\n",
320 iface_param->param);
0e43895e
MC
321 }
322
323 if (!iface_ip || !iface_subnet) {
99bc5d55
JSJ
324 beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_CONFIG,
325 "BS_%d : IP and Subnet Mask required\n");
0e43895e
MC
326 return -EINVAL;
327 }
328
329 ret = mgmt_set_ip(phba, iface_ip, iface_subnet,
330 ISCSI_BOOTPROTO_STATIC);
331
332 return ret;
333}
334
335static int
336beiscsi_set_ipv4(struct Scsi_Host *shost,
337 struct iscsi_iface_param_info *iface_param,
338 void *data, uint32_t dt_len)
339{
340 struct beiscsi_hba *phba = iscsi_host_priv(shost);
341 int ret = 0;
342
343 /* Check the param */
344 switch (iface_param->param) {
345 case ISCSI_NET_PARAM_IPV4_GW:
346 ret = mgmt_set_gateway(phba, iface_param);
347 break;
348 case ISCSI_NET_PARAM_IPV4_BOOTPROTO:
349 if (iface_param->value[0] == ISCSI_BOOTPROTO_DHCP)
350 ret = mgmt_set_ip(phba, iface_param,
351 NULL, ISCSI_BOOTPROTO_DHCP);
352 else if (iface_param->value[0] == ISCSI_BOOTPROTO_STATIC)
353 ret = beiscsi_set_static_ip(shost, iface_param,
354 data, dt_len);
355 else
99bc5d55
JSJ
356 beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_CONFIG,
357 "BS_%d : Invalid BOOTPROTO: %d\n",
358 iface_param->value[0]);
0e43895e
MC
359 break;
360 case ISCSI_NET_PARAM_IFACE_ENABLE:
361 if (iface_param->value[0] == ISCSI_IFACE_ENABLE)
362 ret = beiscsi_create_ipv4_iface(phba);
363 else
364 iscsi_destroy_iface(phba->ipv4_iface);
365 break;
366 case ISCSI_NET_PARAM_IPV4_SUBNET:
367 case ISCSI_NET_PARAM_IPV4_ADDR:
368 ret = beiscsi_set_static_ip(shost, iface_param,
369 data, dt_len);
370 break;
371 default:
99bc5d55
JSJ
372 beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_CONFIG,
373 "BS_%d : Param %d not supported\n",
374 iface_param->param);
0e43895e
MC
375 }
376
377 return ret;
378}
379
380static int
381beiscsi_set_ipv6(struct Scsi_Host *shost,
382 struct iscsi_iface_param_info *iface_param,
383 void *data, uint32_t dt_len)
384{
385 struct beiscsi_hba *phba = iscsi_host_priv(shost);
386 int ret = 0;
387
388 switch (iface_param->param) {
389 case ISCSI_NET_PARAM_IFACE_ENABLE:
390 if (iface_param->value[0] == ISCSI_IFACE_ENABLE)
391 ret = beiscsi_create_ipv6_iface(phba);
392 else {
393 iscsi_destroy_iface(phba->ipv6_iface);
394 ret = 0;
395 }
396 break;
397 case ISCSI_NET_PARAM_IPV6_ADDR:
398 ret = mgmt_set_ip(phba, iface_param, NULL,
399 ISCSI_BOOTPROTO_STATIC);
400 break;
401 default:
99bc5d55
JSJ
402 beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_CONFIG,
403 "BS_%d : Param %d not supported\n",
404 iface_param->param);
0e43895e
MC
405 }
406
407 return ret;
408}
409
410int be2iscsi_iface_set_param(struct Scsi_Host *shost,
411 void *data, uint32_t dt_len)
412{
413 struct iscsi_iface_param_info *iface_param = NULL;
99bc5d55 414 struct beiscsi_hba *phba = iscsi_host_priv(shost);
0e43895e
MC
415 struct nlattr *attrib;
416 uint32_t rm_len = dt_len;
417 int ret = 0 ;
418
419 nla_for_each_attr(attrib, data, dt_len, rm_len) {
420 iface_param = nla_data(attrib);
421
422 if (iface_param->param_type != ISCSI_NET_PARAM)
423 continue;
424
425 /*
426 * BE2ISCSI only supports 1 interface
427 */
428 if (iface_param->iface_num) {
99bc5d55
JSJ
429 beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_CONFIG,
430 "BS_%d : Invalid iface_num %d."
431 "Only iface_num 0 is supported.\n",
432 iface_param->iface_num);
433
0e43895e
MC
434 return -EINVAL;
435 }
436
437 switch (iface_param->iface_type) {
438 case ISCSI_IFACE_TYPE_IPV4:
439 ret = beiscsi_set_ipv4(shost, iface_param,
440 data, dt_len);
441 break;
442 case ISCSI_IFACE_TYPE_IPV6:
443 ret = beiscsi_set_ipv6(shost, iface_param,
444 data, dt_len);
445 break;
446 default:
99bc5d55
JSJ
447 beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_CONFIG,
448 "BS_%d : Invalid iface type :%d passed\n",
449 iface_param->iface_type);
0e43895e
MC
450 break;
451 }
452
453 if (ret)
454 return ret;
455 }
456
457 return ret;
458}
459
460static int be2iscsi_get_if_param(struct beiscsi_hba *phba,
461 struct iscsi_iface *iface, int param,
462 char *buf)
463{
464 struct be_cmd_get_if_info_resp if_info;
465 int len, ip_type = BE2_IPV4;
466
467 memset(&if_info, 0, sizeof(if_info));
468
469 if (iface->iface_type == ISCSI_IFACE_TYPE_IPV6)
470 ip_type = BE2_IPV6;
471
472 len = mgmt_get_if_info(phba, ip_type, &if_info);
473 if (len)
474 return len;
475
476 switch (param) {
477 case ISCSI_NET_PARAM_IPV4_ADDR:
478 len = sprintf(buf, "%pI4\n", &if_info.ip_addr.addr);
479 break;
480 case ISCSI_NET_PARAM_IPV6_ADDR:
481 len = sprintf(buf, "%pI6\n", &if_info.ip_addr.addr);
482 break;
483 case ISCSI_NET_PARAM_IPV4_BOOTPROTO:
484 if (!if_info.dhcp_state)
485 len = sprintf(buf, "static");
486 else
487 len = sprintf(buf, "dhcp");
488 break;
489 case ISCSI_NET_PARAM_IPV4_SUBNET:
490 len = sprintf(buf, "%pI4\n", &if_info.ip_addr.subnet_mask);
491 break;
492 default:
493 WARN_ON(1);
494 }
495
496 return len;
497}
498
499int be2iscsi_iface_get_param(struct iscsi_iface *iface,
500 enum iscsi_param_type param_type,
501 int param, char *buf)
502{
503 struct Scsi_Host *shost = iscsi_iface_to_shost(iface);
504 struct beiscsi_hba *phba = iscsi_host_priv(shost);
505 struct be_cmd_get_def_gateway_resp gateway;
506 int len = -ENOSYS;
507
508 switch (param) {
509 case ISCSI_NET_PARAM_IPV4_ADDR:
510 case ISCSI_NET_PARAM_IPV4_SUBNET:
511 case ISCSI_NET_PARAM_IPV4_BOOTPROTO:
512 case ISCSI_NET_PARAM_IPV6_ADDR:
513 len = be2iscsi_get_if_param(phba, iface, param, buf);
514 break;
515 case ISCSI_NET_PARAM_IFACE_ENABLE:
516 len = sprintf(buf, "enabled");
517 break;
518 case ISCSI_NET_PARAM_IPV4_GW:
519 memset(&gateway, 0, sizeof(gateway));
520 len = mgmt_get_gateway(phba, BE2_IPV4, &gateway);
521 if (!len)
522 len = sprintf(buf, "%pI4\n", &gateway.ip_addr.addr);
523 break;
524 default:
525 len = -ENOSYS;
526 }
527
528 return len;
529}
530
6733b39a 531/**
c7f7fd5b
MC
532 * beiscsi_ep_get_param - get the iscsi parameter
533 * @ep: pointer to iscsi ep
6733b39a
JK
534 * @param: parameter type identifier
535 * @buf: buffer pointer
536 *
537 * returns iscsi parameter
538 */
c7f7fd5b 539int beiscsi_ep_get_param(struct iscsi_endpoint *ep,
6733b39a
JK
540 enum iscsi_param param, char *buf)
541{
c7f7fd5b 542 struct beiscsi_endpoint *beiscsi_ep = ep->dd_data;
6733b39a
JK
543 int len = 0;
544
99bc5d55
JSJ
545 beiscsi_log(beiscsi_ep->phba, KERN_INFO,
546 BEISCSI_LOG_CONFIG,
547 "BS_%d : In beiscsi_ep_get_param,"
548 " param= %d\n", param);
6733b39a
JK
549
550 switch (param) {
551 case ISCSI_PARAM_CONN_PORT:
552 len = sprintf(buf, "%hu\n", beiscsi_ep->dst_tcpport);
553 break;
554 case ISCSI_PARAM_CONN_ADDRESS:
555 if (beiscsi_ep->ip_type == BE2_IPV4)
556 len = sprintf(buf, "%pI4\n", &beiscsi_ep->dst_addr);
557 else
558 len = sprintf(buf, "%pI6\n", &beiscsi_ep->dst6_addr);
559 break;
560 default:
c7f7fd5b 561 return -ENOSYS;
6733b39a
JK
562 }
563 return len;
564}
565
566int beiscsi_set_param(struct iscsi_cls_conn *cls_conn,
567 enum iscsi_param param, char *buf, int buflen)
568{
569 struct iscsi_conn *conn = cls_conn->dd_data;
570 struct iscsi_session *session = conn->session;
99bc5d55 571 struct beiscsi_hba *phba = NULL;
6733b39a
JK
572 int ret;
573
99bc5d55
JSJ
574 phba = ((struct beiscsi_conn *)conn->dd_data)->phba;
575 beiscsi_log(phba, KERN_INFO, BEISCSI_LOG_CONFIG,
576 "BS_%d : In beiscsi_conn_set_param,"
577 " param= %d\n", param);
578
6733b39a
JK
579 ret = iscsi_set_param(cls_conn, param, buf, buflen);
580 if (ret)
581 return ret;
582 /*
583 * If userspace tried to set the value to higher than we can
584 * support override here.
585 */
586 switch (param) {
587 case ISCSI_PARAM_FIRST_BURST:
588 if (session->first_burst > 8192)
589 session->first_burst = 8192;
590 break;
591 case ISCSI_PARAM_MAX_RECV_DLENGTH:
592 if (conn->max_recv_dlength > 65536)
593 conn->max_recv_dlength = 65536;
594 break;
595 case ISCSI_PARAM_MAX_BURST:
230dceb4
JK
596 if (session->max_burst > 262144)
597 session->max_burst = 262144;
6733b39a 598 break;
42f43c41
JK
599 case ISCSI_PARAM_MAX_XMIT_DLENGTH:
600 if ((conn->max_xmit_dlength > 65536) ||
601 (conn->max_xmit_dlength == 0))
602 conn->max_xmit_dlength = 65536;
6733b39a
JK
603 default:
604 return 0;
605 }
606
607 return 0;
608}
609
2177199d
JSJ
610/**
611 * beiscsi_get_initname - Read Initiator Name from flash
612 * @buf: buffer bointer
613 * @phba: The device priv structure instance
614 *
615 * returns number of bytes
616 */
617static int beiscsi_get_initname(char *buf, struct beiscsi_hba *phba)
618{
619 int rc;
620 unsigned int tag, wrb_num;
621 unsigned short status, extd_status;
622 struct be_mcc_wrb *wrb;
623 struct be_cmd_hba_name *resp;
624 struct be_queue_info *mccq = &phba->ctrl.mcc_obj.q;
625
626 tag = be_cmd_get_initname(phba);
627 if (!tag) {
99bc5d55
JSJ
628 beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_CONFIG,
629 "BS_%d : Getting Initiator Name Failed\n");
630
2177199d
JSJ
631 return -EBUSY;
632 } else
633 wait_event_interruptible(phba->ctrl.mcc_wait[tag],
634 phba->ctrl.mcc_numtag[tag]);
635
636 wrb_num = (phba->ctrl.mcc_numtag[tag] & 0x00FF0000) >> 16;
637 extd_status = (phba->ctrl.mcc_numtag[tag] & 0x0000FF00) >> 8;
638 status = phba->ctrl.mcc_numtag[tag] & 0x000000FF;
639
640 if (status || extd_status) {
99bc5d55
JSJ
641 beiscsi_log(phba, KERN_ERR,
642 BEISCSI_LOG_CONFIG | BEISCSI_LOG_MBOX,
643 "BS_%d : MailBox Command Failed with "
644 "status = %d extd_status = %d\n",
645 status, extd_status);
646
2177199d
JSJ
647 free_mcc_tag(&phba->ctrl, tag);
648 return -EAGAIN;
649 }
650 wrb = queue_get_wrb(mccq, wrb_num);
651 free_mcc_tag(&phba->ctrl, tag);
652 resp = embedded_payload(wrb);
653 rc = sprintf(buf, "%s\n", resp->initiator_name);
654 return rc;
655}
656
c62eef0d
JSJ
657/**
658 * beiscsi_get_port_state - Get the Port State
659 * @shost : pointer to scsi_host structure
660 *
661 * returns number of bytes
662 */
663static void beiscsi_get_port_state(struct Scsi_Host *shost)
664{
665 struct beiscsi_hba *phba = iscsi_host_priv(shost);
666 struct iscsi_cls_host *ihost = shost->shost_data;
667
668 ihost->port_state = (phba->state == BE_ADAPTER_UP) ?
669 ISCSI_PORT_STATE_UP : ISCSI_PORT_STATE_DOWN;
670}
671
672/**
673 * beiscsi_get_port_speed - Get the Port Speed from Adapter
674 * @shost : pointer to scsi_host structure
675 *
676 * returns Success/Failure
677 */
678static int beiscsi_get_port_speed(struct Scsi_Host *shost)
679{
680 unsigned int tag, wrb_num;
681 unsigned short status, extd_status;
682 struct be_mcc_wrb *wrb;
683 struct be_cmd_ntwk_link_status_resp *resp;
684 struct beiscsi_hba *phba = iscsi_host_priv(shost);
685 struct iscsi_cls_host *ihost = shost->shost_data;
686 struct be_queue_info *mccq = &phba->ctrl.mcc_obj.q;
687
688 tag = be_cmd_get_port_speed(phba);
689 if (!tag) {
99bc5d55
JSJ
690 beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_CONFIG,
691 "BS_%d : Getting Port Speed Failed\n");
692
c62eef0d
JSJ
693 return -EBUSY;
694 } else
695 wait_event_interruptible(phba->ctrl.mcc_wait[tag],
696 phba->ctrl.mcc_numtag[tag]);
697
698 wrb_num = (phba->ctrl.mcc_numtag[tag] & 0x00FF0000) >> 16;
699 extd_status = (phba->ctrl.mcc_numtag[tag] & 0x0000FF00) >> 8;
700 status = phba->ctrl.mcc_numtag[tag] & 0x000000FF;
701
702 if (status || extd_status) {
99bc5d55
JSJ
703 beiscsi_log(phba, KERN_ERR,
704 BEISCSI_LOG_CONFIG | BEISCSI_LOG_MBOX,
705 "BS_%d : MailBox Command Failed with "
706 "status = %d extd_status = %d\n",
707 status, extd_status);
708
c62eef0d
JSJ
709 free_mcc_tag(&phba->ctrl, tag);
710 return -EAGAIN;
711 }
712 wrb = queue_get_wrb(mccq, wrb_num);
713 free_mcc_tag(&phba->ctrl, tag);
714 resp = embedded_payload(wrb);
715
716 switch (resp->mac_speed) {
717 case BE2ISCSI_LINK_SPEED_10MBPS:
718 ihost->port_speed = ISCSI_PORT_SPEED_10MBPS;
719 break;
720 case BE2ISCSI_LINK_SPEED_100MBPS:
721 ihost->port_speed = BE2ISCSI_LINK_SPEED_100MBPS;
722 break;
723 case BE2ISCSI_LINK_SPEED_1GBPS:
724 ihost->port_speed = ISCSI_PORT_SPEED_1GBPS;
725 break;
726 case BE2ISCSI_LINK_SPEED_10GBPS:
727 ihost->port_speed = ISCSI_PORT_SPEED_10GBPS;
728 break;
729 default:
730 ihost->port_speed = ISCSI_PORT_SPEED_UNKNOWN;
731 }
732 return 0;
733}
734
6733b39a
JK
735/**
736 * beiscsi_get_host_param - get the iscsi parameter
737 * @shost: pointer to scsi_host structure
738 * @param: parameter type identifier
739 * @buf: buffer pointer
740 *
741 * returns host parameter
742 */
743int beiscsi_get_host_param(struct Scsi_Host *shost,
744 enum iscsi_host_param param, char *buf)
745{
3093b048 746 struct beiscsi_hba *phba = iscsi_host_priv(shost);
b15d05b0 747 int status = 0;
6733b39a 748
99bc5d55
JSJ
749 beiscsi_log(phba, KERN_INFO, BEISCSI_LOG_CONFIG,
750 "BS_%d : In beiscsi_get_host_param,"
751 " param= %d\n", param);
752
6733b39a
JK
753 switch (param) {
754 case ISCSI_HOST_PARAM_HWADDRESS:
c7acc5b8
JK
755 status = beiscsi_get_macaddr(buf, phba);
756 if (status < 0) {
99bc5d55
JSJ
757 beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_CONFIG,
758 "BS_%d : beiscsi_get_macaddr Failed\n");
c7acc5b8 759 return status;
756d29c8 760 }
6733b39a 761 break;
2177199d
JSJ
762 case ISCSI_HOST_PARAM_INITIATOR_NAME:
763 status = beiscsi_get_initname(buf, phba);
764 if (status < 0) {
99bc5d55
JSJ
765 beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_CONFIG,
766 "BS_%d : Retreiving Initiator Name Failed\n");
2177199d
JSJ
767 return status;
768 }
769 break;
c62eef0d
JSJ
770 case ISCSI_HOST_PARAM_PORT_STATE:
771 beiscsi_get_port_state(shost);
772 status = sprintf(buf, "%s\n", iscsi_get_port_state_name(shost));
773 break;
774 case ISCSI_HOST_PARAM_PORT_SPEED:
775 status = beiscsi_get_port_speed(shost);
776 if (status) {
99bc5d55
JSJ
777 beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_CONFIG,
778 "BS_%d : Retreiving Port Speed Failed\n");
c62eef0d
JSJ
779 return status;
780 }
781 status = sprintf(buf, "%s\n", iscsi_get_port_speed_name(shost));
782 break;
6733b39a
JK
783 default:
784 return iscsi_host_get_param(shost, param, buf);
785 }
b15d05b0 786 return status;
6733b39a
JK
787}
788
c7acc5b8
JK
789int beiscsi_get_macaddr(char *buf, struct beiscsi_hba *phba)
790{
0e43895e 791 struct be_cmd_get_nic_conf_resp resp;
c7acc5b8
JK
792 int rc;
793
0e43895e 794 if (strlen(phba->mac_address))
df5d0e6e 795 return sysfs_format_mac(buf, phba->mac_address, ETH_ALEN);
c7acc5b8 796
0e43895e
MC
797 memset(&resp, 0, sizeof(resp));
798 rc = mgmt_get_nic_conf(phba, &resp);
799 if (rc)
800 return rc;
c7acc5b8 801
0e43895e
MC
802 memcpy(phba->mac_address, resp.mac_address, ETH_ALEN);
803 return sysfs_format_mac(buf, phba->mac_address, ETH_ALEN);
c7acc5b8
JK
804}
805
6733b39a
JK
806/**
807 * beiscsi_conn_get_stats - get the iscsi stats
808 * @cls_conn: pointer to iscsi cls conn
809 * @stats: pointer to iscsi_stats structure
810 *
811 * returns iscsi stats
812 */
813void beiscsi_conn_get_stats(struct iscsi_cls_conn *cls_conn,
814 struct iscsi_stats *stats)
815{
816 struct iscsi_conn *conn = cls_conn->dd_data;
99bc5d55
JSJ
817 struct beiscsi_hba *phba = NULL;
818
819 phba = ((struct beiscsi_conn *)conn->dd_data)->phba;
820 beiscsi_log(phba, KERN_INFO, BEISCSI_LOG_CONFIG,
821 "BS_%d : In beiscsi_conn_get_stats\n");
6733b39a 822
6733b39a
JK
823 stats->txdata_octets = conn->txdata_octets;
824 stats->rxdata_octets = conn->rxdata_octets;
825 stats->dataout_pdus = conn->dataout_pdus_cnt;
826 stats->scsirsp_pdus = conn->scsirsp_pdus_cnt;
827 stats->scsicmd_pdus = conn->scsicmd_pdus_cnt;
828 stats->datain_pdus = conn->datain_pdus_cnt;
829 stats->tmfrsp_pdus = conn->tmfrsp_pdus_cnt;
830 stats->tmfcmd_pdus = conn->tmfcmd_pdus_cnt;
831 stats->r2t_pdus = conn->r2t_pdus_cnt;
832 stats->digest_err = 0;
833 stats->timeout_err = 0;
834 stats->custom_length = 0;
835 strcpy(stats->custom[0].desc, "eh_abort_cnt");
836 stats->custom[0].value = conn->eh_abort_cnt;
837}
838
839/**
840 * beiscsi_set_params_for_offld - get the parameters for offload
841 * @beiscsi_conn: pointer to beiscsi_conn
842 * @params: pointer to offload_params structure
843 */
844static void beiscsi_set_params_for_offld(struct beiscsi_conn *beiscsi_conn,
845 struct beiscsi_offload_params *params)
846{
847 struct iscsi_conn *conn = beiscsi_conn->conn;
848 struct iscsi_session *session = conn->session;
849
850 AMAP_SET_BITS(struct amap_beiscsi_offload_params, max_burst_length,
851 params, session->max_burst);
852 AMAP_SET_BITS(struct amap_beiscsi_offload_params,
853 max_send_data_segment_length, params,
854 conn->max_xmit_dlength);
855 AMAP_SET_BITS(struct amap_beiscsi_offload_params, first_burst_length,
856 params, session->first_burst);
857 AMAP_SET_BITS(struct amap_beiscsi_offload_params, erl, params,
858 session->erl);
859 AMAP_SET_BITS(struct amap_beiscsi_offload_params, dde, params,
860 conn->datadgst_en);
861 AMAP_SET_BITS(struct amap_beiscsi_offload_params, hde, params,
862 conn->hdrdgst_en);
863 AMAP_SET_BITS(struct amap_beiscsi_offload_params, ir2t, params,
864 session->initial_r2t_en);
865 AMAP_SET_BITS(struct amap_beiscsi_offload_params, imd, params,
866 session->imm_data_en);
867 AMAP_SET_BITS(struct amap_beiscsi_offload_params, exp_statsn, params,
868 (conn->exp_statsn - 1));
869}
870
871/**
872 * beiscsi_conn_start - offload of session to chip
873 * @cls_conn: pointer to beiscsi_conn
874 */
875int beiscsi_conn_start(struct iscsi_cls_conn *cls_conn)
876{
877 struct iscsi_conn *conn = cls_conn->dd_data;
878 struct beiscsi_conn *beiscsi_conn = conn->dd_data;
879 struct beiscsi_endpoint *beiscsi_ep;
880 struct beiscsi_offload_params params;
6733b39a 881
99bc5d55
JSJ
882 beiscsi_log(beiscsi_conn->phba, KERN_INFO,
883 BEISCSI_LOG_CONFIG,
884 "BS_%d : In beiscsi_conn_start\n");
885
6733b39a
JK
886 memset(&params, 0, sizeof(struct beiscsi_offload_params));
887 beiscsi_ep = beiscsi_conn->ep;
888 if (!beiscsi_ep)
99bc5d55
JSJ
889 beiscsi_log(beiscsi_conn->phba, KERN_ERR,
890 BEISCSI_LOG_CONFIG,
891 "BS_%d : In beiscsi_conn_start , no beiscsi_ep\n");
6733b39a 892
6733b39a
JK
893 beiscsi_conn->login_in_progress = 0;
894 beiscsi_set_params_for_offld(beiscsi_conn, &params);
895 beiscsi_offload_connection(beiscsi_conn, &params);
896 iscsi_conn_start(cls_conn);
897 return 0;
898}
899
900/**
901 * beiscsi_get_cid - Allocate a cid
902 * @phba: The phba instance
903 */
904static int beiscsi_get_cid(struct beiscsi_hba *phba)
905{
906 unsigned short cid = 0xFFFF;
907
908 if (!phba->avlbl_cids)
909 return cid;
910
911 cid = phba->cid_array[phba->cid_alloc++];
912 if (phba->cid_alloc == phba->params.cxns_per_ctrl)
913 phba->cid_alloc = 0;
914 phba->avlbl_cids--;
915 return cid;
916}
917
fa95d206
MC
918/**
919 * beiscsi_put_cid - Free the cid
920 * @phba: The phba for which the cid is being freed
921 * @cid: The cid to free
922 */
923static void beiscsi_put_cid(struct beiscsi_hba *phba, unsigned short cid)
924{
925 phba->avlbl_cids++;
926 phba->cid_array[phba->cid_free++] = cid;
927 if (phba->cid_free == phba->params.cxns_per_ctrl)
928 phba->cid_free = 0;
929}
930
931/**
932 * beiscsi_free_ep - free endpoint
933 * @ep: pointer to iscsi endpoint structure
934 */
935static void beiscsi_free_ep(struct beiscsi_endpoint *beiscsi_ep)
936{
937 struct beiscsi_hba *phba = beiscsi_ep->phba;
938
939 beiscsi_put_cid(phba, beiscsi_ep->ep_cid);
940 beiscsi_ep->phba = NULL;
941}
942
6733b39a
JK
943/**
944 * beiscsi_open_conn - Ask FW to open a TCP connection
945 * @ep: endpoint to be used
946 * @src_addr: The source IP address
947 * @dst_addr: The Destination IP address
948 *
949 * Asks the FW to open a TCP connection
950 */
951static int beiscsi_open_conn(struct iscsi_endpoint *ep,
952 struct sockaddr *src_addr,
953 struct sockaddr *dst_addr, int non_blocking)
954{
955 struct beiscsi_endpoint *beiscsi_ep = ep->dd_data;
956 struct beiscsi_hba *phba = beiscsi_ep->phba;
756d29c8
JK
957 struct be_queue_info *mccq = &phba->ctrl.mcc_obj.q;
958 struct be_mcc_wrb *wrb;
959 struct tcp_connect_and_offload_out *ptcpcnct_out;
960 unsigned short status, extd_status;
3cbb7a74 961 struct be_dma_mem nonemb_cmd;
756d29c8 962 unsigned int tag, wrb_num;
d3ad2bb3 963 int ret = -ENOMEM;
6733b39a 964
99bc5d55
JSJ
965 beiscsi_log(phba, KERN_INFO, BEISCSI_LOG_CONFIG,
966 "BS_%d : In beiscsi_open_conn\n");
967
6733b39a
JK
968 beiscsi_ep->ep_cid = beiscsi_get_cid(phba);
969 if (beiscsi_ep->ep_cid == 0xFFFF) {
99bc5d55
JSJ
970 beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_CONFIG,
971 "BS_%d : No free cid available\n");
6733b39a
JK
972 return ret;
973 }
99bc5d55
JSJ
974
975 beiscsi_log(phba, KERN_INFO, BEISCSI_LOG_CONFIG,
976 "BS_%d : In beiscsi_open_conn, ep_cid=%d\n",
977 beiscsi_ep->ep_cid);
978
7da50879
JK
979 phba->ep_array[beiscsi_ep->ep_cid -
980 phba->fw_config.iscsi_cid_start] = ep;
981 if (beiscsi_ep->ep_cid > (phba->fw_config.iscsi_cid_start +
982 phba->params.cxns_per_ctrl * 2)) {
99bc5d55
JSJ
983
984 beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_CONFIG,
985 "BS_%d : Failed in allocate iscsi cid\n");
fa95d206 986 goto free_ep;
6733b39a
JK
987 }
988
989 beiscsi_ep->cid_vld = 0;
3cbb7a74
JK
990 nonemb_cmd.va = pci_alloc_consistent(phba->ctrl.pdev,
991 sizeof(struct tcp_connect_and_offload_in),
992 &nonemb_cmd.dma);
993 if (nonemb_cmd.va == NULL) {
99bc5d55
JSJ
994
995 beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_CONFIG,
996 "BS_%d : Failed to allocate memory for"
997 " mgmt_open_connection\n");
998
3cbb7a74
JK
999 beiscsi_put_cid(phba, beiscsi_ep->ep_cid);
1000 return -ENOMEM;
1001 }
1002 nonemb_cmd.size = sizeof(struct tcp_connect_and_offload_in);
1003 memset(nonemb_cmd.va, 0, nonemb_cmd.size);
1004 tag = mgmt_open_connection(phba, dst_addr, beiscsi_ep, &nonemb_cmd);
756d29c8 1005 if (!tag) {
99bc5d55
JSJ
1006 beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_CONFIG,
1007 "BS_%d : mgmt_open_connection Failed for cid=%d\n",
1008 beiscsi_ep->ep_cid);
1009
1f92638f 1010 beiscsi_put_cid(phba, beiscsi_ep->ep_cid);
3cbb7a74
JK
1011 pci_free_consistent(phba->ctrl.pdev, nonemb_cmd.size,
1012 nonemb_cmd.va, nonemb_cmd.dma);
1f92638f 1013 return -EAGAIN;
756d29c8
JK
1014 } else {
1015 wait_event_interruptible(phba->ctrl.mcc_wait[tag],
1016 phba->ctrl.mcc_numtag[tag]);
1017 }
1018 wrb_num = (phba->ctrl.mcc_numtag[tag] & 0x00FF0000) >> 16;
1019 extd_status = (phba->ctrl.mcc_numtag[tag] & 0x0000FF00) >> 8;
1020 status = phba->ctrl.mcc_numtag[tag] & 0x000000FF;
1021 if (status || extd_status) {
99bc5d55
JSJ
1022 beiscsi_log(phba, KERN_ERR,
1023 BEISCSI_LOG_CONFIG | BEISCSI_LOG_MBOX,
1024 "BS_%d : mgmt_open_connection Failed"
1025 " status = %d extd_status = %d\n",
1026 status, extd_status);
1027
756d29c8 1028 free_mcc_tag(&phba->ctrl, tag);
3cbb7a74
JK
1029 pci_free_consistent(phba->ctrl.pdev, nonemb_cmd.size,
1030 nonemb_cmd.va, nonemb_cmd.dma);
fa95d206 1031 goto free_ep;
756d29c8
JK
1032 } else {
1033 wrb = queue_get_wrb(mccq, wrb_num);
1034 free_mcc_tag(&phba->ctrl, tag);
1035
457ff3b7 1036 ptcpcnct_out = embedded_payload(wrb);
756d29c8
JK
1037 beiscsi_ep = ep->dd_data;
1038 beiscsi_ep->fw_handle = ptcpcnct_out->connection_handle;
1039 beiscsi_ep->cid_vld = 1;
99bc5d55
JSJ
1040 beiscsi_log(phba, KERN_INFO, BEISCSI_LOG_CONFIG,
1041 "BS_%d : mgmt_open_connection Success\n");
756d29c8 1042 }
3cbb7a74
JK
1043 pci_free_consistent(phba->ctrl.pdev, nonemb_cmd.size,
1044 nonemb_cmd.va, nonemb_cmd.dma);
756d29c8 1045 return 0;
6733b39a 1046
fa95d206
MC
1047free_ep:
1048 beiscsi_free_ep(beiscsi_ep);
d3ad2bb3 1049 return -EBUSY;
6733b39a
JK
1050}
1051
1052/**
1053 * beiscsi_ep_connect - Ask chip to create TCP Conn
1054 * @scsi_host: Pointer to scsi_host structure
1055 * @dst_addr: The IP address of Target
1056 * @non_blocking: blocking or non-blocking call
1057 *
1058 * This routines first asks chip to create a connection and then allocates an EP
1059 */
1060struct iscsi_endpoint *
1061beiscsi_ep_connect(struct Scsi_Host *shost, struct sockaddr *dst_addr,
1062 int non_blocking)
1063{
1064 struct beiscsi_hba *phba;
1065 struct beiscsi_endpoint *beiscsi_ep;
1066 struct iscsi_endpoint *ep;
1067 int ret;
1068
6733b39a
JK
1069 if (shost)
1070 phba = iscsi_host_priv(shost);
1071 else {
1072 ret = -ENXIO;
99bc5d55
JSJ
1073 printk(KERN_ERR
1074 "beiscsi_ep_connect shost is NULL\n");
6733b39a
JK
1075 return ERR_PTR(ret);
1076 }
bfead3b2 1077
5dc1c416 1078 if (phba->state != BE_ADAPTER_UP) {
bfead3b2 1079 ret = -EBUSY;
99bc5d55
JSJ
1080 beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_CONFIG,
1081 "BS_%d : The Adapter state is Not UP\n");
bfead3b2
JK
1082 return ERR_PTR(ret);
1083 }
1084
6733b39a
JK
1085 ep = iscsi_create_endpoint(sizeof(struct beiscsi_endpoint));
1086 if (!ep) {
1087 ret = -ENOMEM;
1088 return ERR_PTR(ret);
1089 }
1090
1091 beiscsi_ep = ep->dd_data;
1092 beiscsi_ep->phba = phba;
c2462288 1093 beiscsi_ep->openiscsi_ep = ep;
f5ed7bd4
JK
1094 ret = beiscsi_open_conn(ep, NULL, dst_addr, non_blocking);
1095 if (ret) {
99bc5d55
JSJ
1096 beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_CONFIG,
1097 "BS_%d : Failed in beiscsi_open_conn\n");
6733b39a
JK
1098 goto free_ep;
1099 }
1100
1101 return ep;
1102
1103free_ep:
fa95d206 1104 iscsi_destroy_endpoint(ep);
6733b39a
JK
1105 return ERR_PTR(ret);
1106}
1107
1108/**
1109 * beiscsi_ep_poll - Poll to see if connection is established
1110 * @ep: endpoint to be used
1111 * @timeout_ms: timeout specified in millisecs
1112 *
1113 * Poll to see if TCP connection established
1114 */
1115int beiscsi_ep_poll(struct iscsi_endpoint *ep, int timeout_ms)
1116{
1117 struct beiscsi_endpoint *beiscsi_ep = ep->dd_data;
1118
99bc5d55
JSJ
1119 beiscsi_log(beiscsi_ep->phba, KERN_INFO, BEISCSI_LOG_CONFIG,
1120 "BS_%d : In beiscsi_ep_poll\n");
1121
6733b39a
JK
1122 if (beiscsi_ep->cid_vld == 1)
1123 return 1;
1124 else
1125 return 0;
1126}
1127
1128/**
1129 * beiscsi_close_conn - Upload the connection
1130 * @ep: The iscsi endpoint
1131 * @flag: The type of connection closure
1132 */
c2462288 1133static int beiscsi_close_conn(struct beiscsi_endpoint *beiscsi_ep, int flag)
6733b39a
JK
1134{
1135 int ret = 0;
756d29c8 1136 unsigned int tag;
6733b39a
JK
1137 struct beiscsi_hba *phba = beiscsi_ep->phba;
1138
756d29c8
JK
1139 tag = mgmt_upload_connection(phba, beiscsi_ep->ep_cid, flag);
1140 if (!tag) {
99bc5d55
JSJ
1141 beiscsi_log(phba, KERN_INFO, BEISCSI_LOG_CONFIG,
1142 "BS_%d : upload failed for cid 0x%x\n",
1143 beiscsi_ep->ep_cid);
1144
d3ad2bb3 1145 ret = -EAGAIN;
756d29c8
JK
1146 } else {
1147 wait_event_interruptible(phba->ctrl.mcc_wait[tag],
1148 phba->ctrl.mcc_numtag[tag]);
1149 free_mcc_tag(&phba->ctrl, tag);
6733b39a 1150 }
6733b39a
JK
1151 return ret;
1152}
1153
6733b39a
JK
1154/**
1155 * beiscsi_unbind_conn_to_cid - Unbind the beiscsi_conn from phba conn table
1156 * @phba: The phba instance
1157 * @cid: The cid to free
1158 */
1159static int beiscsi_unbind_conn_to_cid(struct beiscsi_hba *phba,
1160 unsigned int cid)
1161{
1162 if (phba->conn_table[cid])
1163 phba->conn_table[cid] = NULL;
1164 else {
99bc5d55
JSJ
1165 beiscsi_log(phba, KERN_INFO, BEISCSI_LOG_CONFIG,
1166 "BS_%d : Connection table Not occupied.\n");
6733b39a
JK
1167 return -EINVAL;
1168 }
1169 return 0;
1170}
1171
1172/**
fa95d206
MC
1173 * beiscsi_ep_disconnect - Tears down the TCP connection
1174 * @ep: endpoint to be used
1175 *
1176 * Tears down the TCP connection
6733b39a 1177 */
fa95d206 1178void beiscsi_ep_disconnect(struct iscsi_endpoint *ep)
6733b39a 1179{
fa95d206 1180 struct beiscsi_conn *beiscsi_conn;
6733b39a 1181 struct beiscsi_endpoint *beiscsi_ep;
fa95d206 1182 struct beiscsi_hba *phba;
756d29c8 1183 unsigned int tag;
6733b39a
JK
1184 unsigned short savecfg_flag = CMD_ISCSI_SESSION_SAVE_CFG_ON_FLASH;
1185
fa95d206
MC
1186 beiscsi_ep = ep->dd_data;
1187 phba = beiscsi_ep->phba;
99bc5d55
JSJ
1188 beiscsi_log(phba, KERN_INFO, BEISCSI_LOG_CONFIG,
1189 "BS_%d : In beiscsi_ep_disconnect for ep_cid = %d\n",
1190 beiscsi_ep->ep_cid);
fa95d206
MC
1191
1192 if (!beiscsi_ep->conn) {
99bc5d55
JSJ
1193 beiscsi_log(phba, KERN_INFO, BEISCSI_LOG_CONFIG,
1194 "BS_%d : In beiscsi_ep_disconnect, no "
1195 "beiscsi_ep\n");
6733b39a
JK
1196 return;
1197 }
fa95d206
MC
1198 beiscsi_conn = beiscsi_ep->conn;
1199 iscsi_suspend_queue(beiscsi_conn->conn);
1200
99bc5d55
JSJ
1201 beiscsi_log(phba, KERN_INFO, BEISCSI_LOG_CONFIG,
1202 "BS_%d : In beiscsi_ep_disconnect ep_cid = %d\n",
1203 beiscsi_ep->ep_cid);
fa95d206 1204
756d29c8 1205 tag = mgmt_invalidate_connection(phba, beiscsi_ep,
6733b39a
JK
1206 beiscsi_ep->ep_cid, 1,
1207 savecfg_flag);
756d29c8 1208 if (!tag) {
99bc5d55
JSJ
1209 beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_CONFIG,
1210 "BS_%d : mgmt_invalidate_connection"
1211 " Failed for cid=%d\n",
1212 beiscsi_ep->ep_cid);
756d29c8
JK
1213 } else {
1214 wait_event_interruptible(phba->ctrl.mcc_wait[tag],
1215 phba->ctrl.mcc_numtag[tag]);
1216 free_mcc_tag(&phba->ctrl, tag);
6733b39a 1217 }
fa95d206 1218
c2462288
JK
1219 beiscsi_close_conn(beiscsi_ep, CONNECTION_UPLOAD_GRACEFUL);
1220 beiscsi_free_ep(beiscsi_ep);
6733b39a 1221 beiscsi_unbind_conn_to_cid(phba, beiscsi_ep->ep_cid);
fa95d206 1222 iscsi_destroy_endpoint(beiscsi_ep->openiscsi_ep);
6733b39a 1223}
3128c6c7 1224
587a1f16 1225umode_t be2iscsi_attr_is_visible(int param_type, int param)
3128c6c7
MC
1226{
1227 switch (param_type) {
0e43895e
MC
1228 case ISCSI_NET_PARAM:
1229 switch (param) {
1230 case ISCSI_NET_PARAM_IFACE_ENABLE:
1231 case ISCSI_NET_PARAM_IPV4_ADDR:
1232 case ISCSI_NET_PARAM_IPV4_SUBNET:
1233 case ISCSI_NET_PARAM_IPV4_BOOTPROTO:
1234 case ISCSI_NET_PARAM_IPV4_GW:
1235 case ISCSI_NET_PARAM_IPV6_ADDR:
1236 return S_IRUGO;
1237 default:
1238 return 0;
1239 }
f27fb2ef
MC
1240 case ISCSI_HOST_PARAM:
1241 switch (param) {
1242 case ISCSI_HOST_PARAM_HWADDRESS:
c62eef0d
JSJ
1243 case ISCSI_HOST_PARAM_INITIATOR_NAME:
1244 case ISCSI_HOST_PARAM_PORT_STATE:
1245 case ISCSI_HOST_PARAM_PORT_SPEED:
f27fb2ef
MC
1246 return S_IRUGO;
1247 default:
1248 return 0;
1249 }
3128c6c7
MC
1250 case ISCSI_PARAM:
1251 switch (param) {
1252 case ISCSI_PARAM_MAX_RECV_DLENGTH:
1253 case ISCSI_PARAM_MAX_XMIT_DLENGTH:
1254 case ISCSI_PARAM_HDRDGST_EN:
1255 case ISCSI_PARAM_DATADGST_EN:
1256 case ISCSI_PARAM_CONN_ADDRESS:
1257 case ISCSI_PARAM_CONN_PORT:
1258 case ISCSI_PARAM_EXP_STATSN:
1259 case ISCSI_PARAM_PERSISTENT_ADDRESS:
1260 case ISCSI_PARAM_PERSISTENT_PORT:
1261 case ISCSI_PARAM_PING_TMO:
1262 case ISCSI_PARAM_RECV_TMO:
1d063c17
MC
1263 case ISCSI_PARAM_INITIAL_R2T_EN:
1264 case ISCSI_PARAM_MAX_R2T:
1265 case ISCSI_PARAM_IMM_DATA_EN:
1266 case ISCSI_PARAM_FIRST_BURST:
1267 case ISCSI_PARAM_MAX_BURST:
1268 case ISCSI_PARAM_PDU_INORDER_EN:
1269 case ISCSI_PARAM_DATASEQ_INORDER_EN:
1270 case ISCSI_PARAM_ERL:
1271 case ISCSI_PARAM_TARGET_NAME:
1272 case ISCSI_PARAM_TPGT:
1273 case ISCSI_PARAM_USERNAME:
1274 case ISCSI_PARAM_PASSWORD:
1275 case ISCSI_PARAM_USERNAME_IN:
1276 case ISCSI_PARAM_PASSWORD_IN:
1277 case ISCSI_PARAM_FAST_ABORT:
1278 case ISCSI_PARAM_ABORT_TMO:
1279 case ISCSI_PARAM_LU_RESET_TMO:
1280 case ISCSI_PARAM_IFACE_NAME:
1281 case ISCSI_PARAM_INITIATOR_NAME:
3128c6c7
MC
1282 return S_IRUGO;
1283 default:
1284 return 0;
1285 }
1286 }
1287
1288 return 0;
1289}