2 * Copyright (C) 2005 - 2011 Emulex
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.
10 * Written by: Jayamohan Kallickal (jayamohan.kallickal@emulex.com)
12 * Contact Information:
13 * linux-drivers@emulex.com
17 * Costa Mesa, CA 92626
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>
26 #include <scsi/scsi_netlink.h>
27 #include <net/netlink.h>
28 #include <scsi/scsi.h>
32 extern struct iscsi_transport beiscsi_iscsi_transport
;
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
40 struct iscsi_cls_session
*beiscsi_session_create(struct iscsi_endpoint
*ep
,
45 struct Scsi_Host
*shost
;
46 struct beiscsi_endpoint
*beiscsi_ep
;
47 struct iscsi_cls_session
*cls_session
;
48 struct beiscsi_hba
*phba
;
49 struct iscsi_session
*sess
;
50 struct beiscsi_session
*beiscsi_sess
;
51 struct beiscsi_io_task
*io_task
;
53 SE_DEBUG(DBG_LVL_8
, "In beiscsi_session_create\n");
56 SE_DEBUG(DBG_LVL_1
, "beiscsi_session_create: invalid ep\n");
59 beiscsi_ep
= ep
->dd_data
;
60 phba
= beiscsi_ep
->phba
;
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. "
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
;
71 cls_session
= iscsi_session_setup(&beiscsi_iscsi_transport
,
73 sizeof(*beiscsi_sess
),
75 initial_cmdsn
, ISCSI_MAX_TARGET
);
78 sess
= cls_session
->dd_data
;
79 beiscsi_sess
= sess
->dd_data
;
80 beiscsi_sess
->bhs_pool
= pci_pool_create("beiscsi_bhs_pool",
82 sizeof(struct be_cmd_bhs
),
84 if (!beiscsi_sess
->bhs_pool
)
89 iscsi_session_teardown(cls_session
);
94 * beiscsi_session_destroy - destroys iscsi session
95 * @cls_session: pointer to iscsi cls session
97 * Destroys iSCSI session instance and releases
98 * resources allocated for it.
100 void beiscsi_session_destroy(struct iscsi_cls_session
*cls_session
)
102 struct iscsi_session
*sess
= cls_session
->dd_data
;
103 struct beiscsi_session
*beiscsi_sess
= sess
->dd_data
;
105 SE_DEBUG(DBG_LVL_8
, "In beiscsi_session_destroy\n");
106 pci_pool_destroy(beiscsi_sess
->bhs_pool
);
107 iscsi_session_teardown(cls_session
);
111 * beiscsi_conn_create - create an instance of iscsi connection
112 * @cls_session: ptr to iscsi_cls_session
115 struct iscsi_cls_conn
*
116 beiscsi_conn_create(struct iscsi_cls_session
*cls_session
, u32 cid
)
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
;
123 struct iscsi_session
*sess
;
124 struct beiscsi_session
*beiscsi_sess
;
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
);
131 cls_conn
= iscsi_conn_setup(cls_session
, sizeof(*beiscsi_conn
), cid
);
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
;
140 sess
= cls_session
->dd_data
;
141 beiscsi_sess
= sess
->dd_data
;
142 beiscsi_conn
->beiscsi_sess
= beiscsi_sess
;
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
152 static int beiscsi_bindconn_cid(struct beiscsi_hba
*phba
,
153 struct beiscsi_conn
*beiscsi_conn
,
156 if (phba
->conn_table
[cid
]) {
158 "Connection table already occupied. Detected clash\n");
161 SE_DEBUG(DBG_LVL_8
, "phba->conn_table[%d]=%p(beiscsi_conn)\n",
163 phba
->conn_table
[cid
] = beiscsi_conn
;
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)
174 * This function binds the TCP Conn with iSCSI Connection and Session.
176 int beiscsi_conn_bind(struct iscsi_cls_session
*cls_session
,
177 struct iscsi_cls_conn
*cls_conn
,
178 u64 transport_fd
, int is_leading
)
180 struct iscsi_conn
*conn
= cls_conn
->dd_data
;
181 struct beiscsi_conn
*beiscsi_conn
= conn
->dd_data
;
182 struct Scsi_Host
*shost
= iscsi_session_to_shost(cls_session
);
183 struct beiscsi_hba
*phba
= iscsi_host_priv(shost
);
184 struct beiscsi_endpoint
*beiscsi_ep
;
185 struct iscsi_endpoint
*ep
;
187 SE_DEBUG(DBG_LVL_8
, "In beiscsi_conn_bind\n");
188 ep
= iscsi_lookup_endpoint(transport_fd
);
192 beiscsi_ep
= ep
->dd_data
;
194 if (iscsi_conn_bind(cls_session
, cls_conn
, is_leading
))
197 if (beiscsi_ep
->phba
!= phba
) {
199 "beiscsi_ep->hba=%p not equal to phba=%p\n",
200 beiscsi_ep
->phba
, phba
);
204 beiscsi_conn
->beiscsi_conn_cid
= beiscsi_ep
->ep_cid
;
205 beiscsi_conn
->ep
= beiscsi_ep
;
206 beiscsi_ep
->conn
= beiscsi_conn
;
207 SE_DEBUG(DBG_LVL_8
, "beiscsi_conn=%p conn=%p ep_cid=%d\n",
208 beiscsi_conn
, conn
, beiscsi_ep
->ep_cid
);
209 return beiscsi_bindconn_cid(phba
, beiscsi_conn
, beiscsi_ep
->ep_cid
);
212 static int beiscsi_create_ipv4_iface(struct beiscsi_hba
*phba
)
214 if (phba
->ipv4_iface
)
217 phba
->ipv4_iface
= iscsi_create_iface(phba
->shost
,
218 &beiscsi_iscsi_transport
,
219 ISCSI_IFACE_TYPE_IPV4
,
221 if (!phba
->ipv4_iface
) {
222 shost_printk(KERN_ERR
, phba
->shost
, "Could not "
223 "create default IPv4 address.\n");
230 static int beiscsi_create_ipv6_iface(struct beiscsi_hba
*phba
)
232 if (phba
->ipv6_iface
)
235 phba
->ipv6_iface
= iscsi_create_iface(phba
->shost
,
236 &beiscsi_iscsi_transport
,
237 ISCSI_IFACE_TYPE_IPV6
,
239 if (!phba
->ipv6_iface
) {
240 shost_printk(KERN_ERR
, phba
->shost
, "Could not "
241 "create default IPv6 address.\n");
248 void beiscsi_create_def_ifaces(struct beiscsi_hba
*phba
)
250 struct be_cmd_get_if_info_resp if_info
;
252 if (!mgmt_get_if_info(phba
, BE2_IPV4
, &if_info
))
253 beiscsi_create_ipv4_iface(phba
);
255 if (!mgmt_get_if_info(phba
, BE2_IPV6
, &if_info
))
256 beiscsi_create_ipv6_iface(phba
);
259 void beiscsi_destroy_def_ifaces(struct beiscsi_hba
*phba
)
261 if (phba
->ipv6_iface
)
262 iscsi_destroy_iface(phba
->ipv6_iface
);
263 if (phba
->ipv4_iface
)
264 iscsi_destroy_iface(phba
->ipv4_iface
);
268 beiscsi_set_static_ip(struct Scsi_Host
*shost
,
269 struct iscsi_iface_param_info
*iface_param
,
270 void *data
, uint32_t dt_len
)
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
;
279 switch (iface_param
->param
) {
280 case ISCSI_NET_PARAM_IPV4_BOOTPROTO
:
281 nla
= nla_find(data
, dt_len
, ISCSI_NET_PARAM_IPV4_ADDR
);
283 iface_ip
= nla_data(nla
);
285 nla
= nla_find(data
, dt_len
, ISCSI_NET_PARAM_IPV4_SUBNET
);
287 iface_subnet
= nla_data(nla
);
289 case ISCSI_NET_PARAM_IPV4_ADDR
:
290 iface_ip
= iface_param
;
291 nla
= nla_find(data
, dt_len
, ISCSI_NET_PARAM_IPV4_SUBNET
);
293 iface_subnet
= nla_data(nla
);
295 case ISCSI_NET_PARAM_IPV4_SUBNET
:
296 iface_subnet
= iface_param
;
297 nla
= nla_find(data
, dt_len
, ISCSI_NET_PARAM_IPV4_ADDR
);
299 iface_ip
= nla_data(nla
);
302 shost_printk(KERN_ERR
, shost
, "Unsupported param %d\n",
306 if (!iface_ip
|| !iface_subnet
) {
307 shost_printk(KERN_ERR
, shost
, "IP and Subnet Mask required\n");
311 ret
= mgmt_set_ip(phba
, iface_ip
, iface_subnet
,
312 ISCSI_BOOTPROTO_STATIC
);
318 beiscsi_set_ipv4(struct Scsi_Host
*shost
,
319 struct iscsi_iface_param_info
*iface_param
,
320 void *data
, uint32_t dt_len
)
322 struct beiscsi_hba
*phba
= iscsi_host_priv(shost
);
325 /* Check the param */
326 switch (iface_param
->param
) {
327 case ISCSI_NET_PARAM_IPV4_GW
:
328 ret
= mgmt_set_gateway(phba
, iface_param
);
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
,
338 shost_printk(KERN_ERR
, shost
, "Invalid BOOTPROTO: %d\n",
339 iface_param
->value
[0]);
341 case ISCSI_NET_PARAM_IFACE_ENABLE
:
342 if (iface_param
->value
[0] == ISCSI_IFACE_ENABLE
)
343 ret
= beiscsi_create_ipv4_iface(phba
);
345 iscsi_destroy_iface(phba
->ipv4_iface
);
347 case ISCSI_NET_PARAM_IPV4_SUBNET
:
348 case ISCSI_NET_PARAM_IPV4_ADDR
:
349 ret
= beiscsi_set_static_ip(shost
, iface_param
,
353 shost_printk(KERN_ERR
, shost
, "Param %d not supported\n",
361 beiscsi_set_ipv6(struct Scsi_Host
*shost
,
362 struct iscsi_iface_param_info
*iface_param
,
363 void *data
, uint32_t dt_len
)
365 struct beiscsi_hba
*phba
= iscsi_host_priv(shost
);
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
);
373 iscsi_destroy_iface(phba
->ipv6_iface
);
377 case ISCSI_NET_PARAM_IPV6_ADDR
:
378 ret
= mgmt_set_ip(phba
, iface_param
, NULL
,
379 ISCSI_BOOTPROTO_STATIC
);
382 shost_printk(KERN_ERR
, shost
, "Param %d not supported\n",
389 int be2iscsi_iface_set_param(struct Scsi_Host
*shost
,
390 void *data
, uint32_t dt_len
)
392 struct iscsi_iface_param_info
*iface_param
= NULL
;
393 struct nlattr
*attrib
;
394 uint32_t rm_len
= dt_len
;
397 nla_for_each_attr(attrib
, data
, dt_len
, rm_len
) {
398 iface_param
= nla_data(attrib
);
400 if (iface_param
->param_type
!= ISCSI_NET_PARAM
)
404 * BE2ISCSI only supports 1 interface
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
);
413 switch (iface_param
->iface_type
) {
414 case ISCSI_IFACE_TYPE_IPV4
:
415 ret
= beiscsi_set_ipv4(shost
, iface_param
,
418 case ISCSI_IFACE_TYPE_IPV6
:
419 ret
= beiscsi_set_ipv6(shost
, iface_param
,
423 shost_printk(KERN_ERR
, shost
,
424 "Invalid iface type :%d passed\n",
425 iface_param
->iface_type
);
436 static int be2iscsi_get_if_param(struct beiscsi_hba
*phba
,
437 struct iscsi_iface
*iface
, int param
,
440 struct be_cmd_get_if_info_resp if_info
;
441 int len
, ip_type
= BE2_IPV4
;
443 memset(&if_info
, 0, sizeof(if_info
));
445 if (iface
->iface_type
== ISCSI_IFACE_TYPE_IPV6
)
448 len
= mgmt_get_if_info(phba
, ip_type
, &if_info
);
453 case ISCSI_NET_PARAM_IPV4_ADDR
:
454 len
= sprintf(buf
, "%pI4\n", &if_info
.ip_addr
.addr
);
456 case ISCSI_NET_PARAM_IPV6_ADDR
:
457 len
= sprintf(buf
, "%pI6\n", &if_info
.ip_addr
.addr
);
459 case ISCSI_NET_PARAM_IPV4_BOOTPROTO
:
460 if (!if_info
.dhcp_state
)
461 len
= sprintf(buf
, "static");
463 len
= sprintf(buf
, "dhcp");
465 case ISCSI_NET_PARAM_IPV4_SUBNET
:
466 len
= sprintf(buf
, "%pI4\n", &if_info
.ip_addr
.subnet_mask
);
475 int be2iscsi_iface_get_param(struct iscsi_iface
*iface
,
476 enum iscsi_param_type param_type
,
477 int param
, char *buf
)
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
;
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
);
491 case ISCSI_NET_PARAM_IFACE_ENABLE
:
492 len
= sprintf(buf
, "enabled");
494 case ISCSI_NET_PARAM_IPV4_GW
:
495 memset(&gateway
, 0, sizeof(gateway
));
496 len
= mgmt_get_gateway(phba
, BE2_IPV4
, &gateway
);
498 len
= sprintf(buf
, "%pI4\n", &gateway
.ip_addr
.addr
);
508 * beiscsi_ep_get_param - get the iscsi parameter
509 * @ep: pointer to iscsi ep
510 * @param: parameter type identifier
511 * @buf: buffer pointer
513 * returns iscsi parameter
515 int beiscsi_ep_get_param(struct iscsi_endpoint
*ep
,
516 enum iscsi_param param
, char *buf
)
518 struct beiscsi_endpoint
*beiscsi_ep
= ep
->dd_data
;
521 SE_DEBUG(DBG_LVL_8
, "In beiscsi_ep_get_param, param= %d\n", param
);
524 case ISCSI_PARAM_CONN_PORT
:
525 len
= sprintf(buf
, "%hu\n", beiscsi_ep
->dst_tcpport
);
527 case ISCSI_PARAM_CONN_ADDRESS
:
528 if (beiscsi_ep
->ip_type
== BE2_IPV4
)
529 len
= sprintf(buf
, "%pI4\n", &beiscsi_ep
->dst_addr
);
531 len
= sprintf(buf
, "%pI6\n", &beiscsi_ep
->dst6_addr
);
539 int beiscsi_set_param(struct iscsi_cls_conn
*cls_conn
,
540 enum iscsi_param param
, char *buf
, int buflen
)
542 struct iscsi_conn
*conn
= cls_conn
->dd_data
;
543 struct iscsi_session
*session
= conn
->session
;
546 SE_DEBUG(DBG_LVL_8
, "In beiscsi_conn_set_param, param= %d\n", param
);
547 ret
= iscsi_set_param(cls_conn
, param
, buf
, buflen
);
551 * If userspace tried to set the value to higher than we can
552 * support override here.
555 case ISCSI_PARAM_FIRST_BURST
:
556 if (session
->first_burst
> 8192)
557 session
->first_burst
= 8192;
559 case ISCSI_PARAM_MAX_RECV_DLENGTH
:
560 if (conn
->max_recv_dlength
> 65536)
561 conn
->max_recv_dlength
= 65536;
563 case ISCSI_PARAM_MAX_BURST
:
564 if (session
->max_burst
> 262144)
565 session
->max_burst
= 262144;
567 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;
579 * beiscsi_get_initname - Read Initiator Name from flash
580 * @buf: buffer bointer
581 * @phba: The device priv structure instance
583 * returns number of bytes
585 static int beiscsi_get_initname(char *buf
, struct beiscsi_hba
*phba
)
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
;
594 tag
= be_cmd_get_initname(phba
);
596 SE_DEBUG(DBG_LVL_1
, "Getting Initiator Name Failed\n");
599 wait_event_interruptible(phba
->ctrl
.mcc_wait
[tag
],
600 phba
->ctrl
.mcc_numtag
[tag
]);
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;
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
);
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
);
621 * beiscsi_get_port_state - Get the Port State
622 * @shost : pointer to scsi_host structure
624 * returns number of bytes
626 static void beiscsi_get_port_state(struct Scsi_Host
*shost
)
628 struct beiscsi_hba
*phba
= iscsi_host_priv(shost
);
629 struct iscsi_cls_host
*ihost
= shost
->shost_data
;
631 ihost
->port_state
= (phba
->state
== BE_ADAPTER_UP
) ?
632 ISCSI_PORT_STATE_UP
: ISCSI_PORT_STATE_DOWN
;
636 * beiscsi_get_port_speed - Get the Port Speed from Adapter
637 * @shost : pointer to scsi_host structure
639 * returns Success/Failure
641 static int beiscsi_get_port_speed(struct Scsi_Host
*shost
)
643 unsigned int tag
, wrb_num
;
644 unsigned short status
, extd_status
;
645 struct be_mcc_wrb
*wrb
;
646 struct be_cmd_ntwk_link_status_resp
*resp
;
647 struct beiscsi_hba
*phba
= iscsi_host_priv(shost
);
648 struct iscsi_cls_host
*ihost
= shost
->shost_data
;
649 struct be_queue_info
*mccq
= &phba
->ctrl
.mcc_obj
.q
;
651 tag
= be_cmd_get_port_speed(phba
);
653 SE_DEBUG(DBG_LVL_1
, "Getting Port Speed Failed\n");
656 wait_event_interruptible(phba
->ctrl
.mcc_wait
[tag
],
657 phba
->ctrl
.mcc_numtag
[tag
]);
659 wrb_num
= (phba
->ctrl
.mcc_numtag
[tag
] & 0x00FF0000) >> 16;
660 extd_status
= (phba
->ctrl
.mcc_numtag
[tag
] & 0x0000FF00) >> 8;
661 status
= phba
->ctrl
.mcc_numtag
[tag
] & 0x000000FF;
663 if (status
|| extd_status
) {
664 SE_DEBUG(DBG_LVL_1
, "MailBox Command Failed with "
665 "status = %d extd_status = %d\n",
666 status
, extd_status
);
667 free_mcc_tag(&phba
->ctrl
, tag
);
670 wrb
= queue_get_wrb(mccq
, wrb_num
);
671 free_mcc_tag(&phba
->ctrl
, tag
);
672 resp
= embedded_payload(wrb
);
674 switch (resp
->mac_speed
) {
675 case BE2ISCSI_LINK_SPEED_10MBPS
:
676 ihost
->port_speed
= ISCSI_PORT_SPEED_10MBPS
;
678 case BE2ISCSI_LINK_SPEED_100MBPS
:
679 ihost
->port_speed
= BE2ISCSI_LINK_SPEED_100MBPS
;
681 case BE2ISCSI_LINK_SPEED_1GBPS
:
682 ihost
->port_speed
= ISCSI_PORT_SPEED_1GBPS
;
684 case BE2ISCSI_LINK_SPEED_10GBPS
:
685 ihost
->port_speed
= ISCSI_PORT_SPEED_10GBPS
;
688 ihost
->port_speed
= ISCSI_PORT_SPEED_UNKNOWN
;
694 * beiscsi_get_host_param - get the iscsi parameter
695 * @shost: pointer to scsi_host structure
696 * @param: parameter type identifier
697 * @buf: buffer pointer
699 * returns host parameter
701 int beiscsi_get_host_param(struct Scsi_Host
*shost
,
702 enum iscsi_host_param param
, char *buf
)
704 struct beiscsi_hba
*phba
= iscsi_host_priv(shost
);
707 SE_DEBUG(DBG_LVL_8
, "In beiscsi_get_host_param, param= %d\n", param
);
709 case ISCSI_HOST_PARAM_HWADDRESS
:
710 status
= beiscsi_get_macaddr(buf
, phba
);
712 SE_DEBUG(DBG_LVL_1
, "beiscsi_get_macaddr Failed\n");
716 case ISCSI_HOST_PARAM_INITIATOR_NAME
:
717 status
= beiscsi_get_initname(buf
, phba
);
720 "Retreiving Initiator Name Failed\n");
724 case ISCSI_HOST_PARAM_PORT_STATE
:
725 beiscsi_get_port_state(shost
);
726 status
= sprintf(buf
, "%s\n", iscsi_get_port_state_name(shost
));
728 case ISCSI_HOST_PARAM_PORT_SPEED
:
729 status
= beiscsi_get_port_speed(shost
);
732 "Retreiving Port Speed Failed\n");
735 status
= sprintf(buf
, "%s\n", iscsi_get_port_speed_name(shost
));
738 return iscsi_host_get_param(shost
, param
, buf
);
743 int beiscsi_get_macaddr(char *buf
, struct beiscsi_hba
*phba
)
745 struct be_cmd_get_nic_conf_resp resp
;
748 if (strlen(phba
->mac_address
))
749 return strlcpy(buf
, phba
->mac_address
, PAGE_SIZE
);
751 memset(&resp
, 0, sizeof(resp
));
752 rc
= mgmt_get_nic_conf(phba
, &resp
);
756 memcpy(phba
->mac_address
, resp
.mac_address
, ETH_ALEN
);
757 return sysfs_format_mac(buf
, phba
->mac_address
, ETH_ALEN
);
761 * beiscsi_conn_get_stats - get the iscsi stats
762 * @cls_conn: pointer to iscsi cls conn
763 * @stats: pointer to iscsi_stats structure
765 * returns iscsi stats
767 void beiscsi_conn_get_stats(struct iscsi_cls_conn
*cls_conn
,
768 struct iscsi_stats
*stats
)
770 struct iscsi_conn
*conn
= cls_conn
->dd_data
;
772 SE_DEBUG(DBG_LVL_8
, "In beiscsi_conn_get_stats\n");
773 stats
->txdata_octets
= conn
->txdata_octets
;
774 stats
->rxdata_octets
= conn
->rxdata_octets
;
775 stats
->dataout_pdus
= conn
->dataout_pdus_cnt
;
776 stats
->scsirsp_pdus
= conn
->scsirsp_pdus_cnt
;
777 stats
->scsicmd_pdus
= conn
->scsicmd_pdus_cnt
;
778 stats
->datain_pdus
= conn
->datain_pdus_cnt
;
779 stats
->tmfrsp_pdus
= conn
->tmfrsp_pdus_cnt
;
780 stats
->tmfcmd_pdus
= conn
->tmfcmd_pdus_cnt
;
781 stats
->r2t_pdus
= conn
->r2t_pdus_cnt
;
782 stats
->digest_err
= 0;
783 stats
->timeout_err
= 0;
784 stats
->custom_length
= 0;
785 strcpy(stats
->custom
[0].desc
, "eh_abort_cnt");
786 stats
->custom
[0].value
= conn
->eh_abort_cnt
;
790 * beiscsi_set_params_for_offld - get the parameters for offload
791 * @beiscsi_conn: pointer to beiscsi_conn
792 * @params: pointer to offload_params structure
794 static void beiscsi_set_params_for_offld(struct beiscsi_conn
*beiscsi_conn
,
795 struct beiscsi_offload_params
*params
)
797 struct iscsi_conn
*conn
= beiscsi_conn
->conn
;
798 struct iscsi_session
*session
= conn
->session
;
800 AMAP_SET_BITS(struct amap_beiscsi_offload_params
, max_burst_length
,
801 params
, session
->max_burst
);
802 AMAP_SET_BITS(struct amap_beiscsi_offload_params
,
803 max_send_data_segment_length
, params
,
804 conn
->max_xmit_dlength
);
805 AMAP_SET_BITS(struct amap_beiscsi_offload_params
, first_burst_length
,
806 params
, session
->first_burst
);
807 AMAP_SET_BITS(struct amap_beiscsi_offload_params
, erl
, params
,
809 AMAP_SET_BITS(struct amap_beiscsi_offload_params
, dde
, params
,
811 AMAP_SET_BITS(struct amap_beiscsi_offload_params
, hde
, params
,
813 AMAP_SET_BITS(struct amap_beiscsi_offload_params
, ir2t
, params
,
814 session
->initial_r2t_en
);
815 AMAP_SET_BITS(struct amap_beiscsi_offload_params
, imd
, params
,
816 session
->imm_data_en
);
817 AMAP_SET_BITS(struct amap_beiscsi_offload_params
, exp_statsn
, params
,
818 (conn
->exp_statsn
- 1));
822 * beiscsi_conn_start - offload of session to chip
823 * @cls_conn: pointer to beiscsi_conn
825 int beiscsi_conn_start(struct iscsi_cls_conn
*cls_conn
)
827 struct iscsi_conn
*conn
= cls_conn
->dd_data
;
828 struct beiscsi_conn
*beiscsi_conn
= conn
->dd_data
;
829 struct beiscsi_endpoint
*beiscsi_ep
;
830 struct beiscsi_offload_params params
;
832 SE_DEBUG(DBG_LVL_8
, "In beiscsi_conn_start\n");
833 memset(¶ms
, 0, sizeof(struct beiscsi_offload_params
));
834 beiscsi_ep
= beiscsi_conn
->ep
;
836 SE_DEBUG(DBG_LVL_1
, "In beiscsi_conn_start , no beiscsi_ep\n");
838 beiscsi_conn
->login_in_progress
= 0;
839 beiscsi_set_params_for_offld(beiscsi_conn
, ¶ms
);
840 beiscsi_offload_connection(beiscsi_conn
, ¶ms
);
841 iscsi_conn_start(cls_conn
);
846 * beiscsi_get_cid - Allocate a cid
847 * @phba: The phba instance
849 static int beiscsi_get_cid(struct beiscsi_hba
*phba
)
851 unsigned short cid
= 0xFFFF;
853 if (!phba
->avlbl_cids
)
856 cid
= phba
->cid_array
[phba
->cid_alloc
++];
857 if (phba
->cid_alloc
== phba
->params
.cxns_per_ctrl
)
864 * beiscsi_put_cid - Free the cid
865 * @phba: The phba for which the cid is being freed
866 * @cid: The cid to free
868 static void beiscsi_put_cid(struct beiscsi_hba
*phba
, unsigned short cid
)
871 phba
->cid_array
[phba
->cid_free
++] = cid
;
872 if (phba
->cid_free
== phba
->params
.cxns_per_ctrl
)
877 * beiscsi_free_ep - free endpoint
878 * @ep: pointer to iscsi endpoint structure
880 static void beiscsi_free_ep(struct beiscsi_endpoint
*beiscsi_ep
)
882 struct beiscsi_hba
*phba
= beiscsi_ep
->phba
;
884 beiscsi_put_cid(phba
, beiscsi_ep
->ep_cid
);
885 beiscsi_ep
->phba
= NULL
;
889 * beiscsi_open_conn - Ask FW to open a TCP connection
890 * @ep: endpoint to be used
891 * @src_addr: The source IP address
892 * @dst_addr: The Destination IP address
894 * Asks the FW to open a TCP connection
896 static int beiscsi_open_conn(struct iscsi_endpoint
*ep
,
897 struct sockaddr
*src_addr
,
898 struct sockaddr
*dst_addr
, int non_blocking
)
900 struct beiscsi_endpoint
*beiscsi_ep
= ep
->dd_data
;
901 struct beiscsi_hba
*phba
= beiscsi_ep
->phba
;
902 struct be_queue_info
*mccq
= &phba
->ctrl
.mcc_obj
.q
;
903 struct be_mcc_wrb
*wrb
;
904 struct tcp_connect_and_offload_out
*ptcpcnct_out
;
905 unsigned short status
, extd_status
;
906 struct be_dma_mem nonemb_cmd
;
907 unsigned int tag
, wrb_num
;
910 SE_DEBUG(DBG_LVL_8
, "In beiscsi_open_conn\n");
911 beiscsi_ep
->ep_cid
= beiscsi_get_cid(phba
);
912 if (beiscsi_ep
->ep_cid
== 0xFFFF) {
913 SE_DEBUG(DBG_LVL_1
, "No free cid available\n");
916 SE_DEBUG(DBG_LVL_8
, "In beiscsi_open_conn, ep_cid=%d\n",
918 phba
->ep_array
[beiscsi_ep
->ep_cid
-
919 phba
->fw_config
.iscsi_cid_start
] = ep
;
920 if (beiscsi_ep
->ep_cid
> (phba
->fw_config
.iscsi_cid_start
+
921 phba
->params
.cxns_per_ctrl
* 2)) {
922 SE_DEBUG(DBG_LVL_1
, "Failed in allocate iscsi cid\n");
926 beiscsi_ep
->cid_vld
= 0;
927 nonemb_cmd
.va
= pci_alloc_consistent(phba
->ctrl
.pdev
,
928 sizeof(struct tcp_connect_and_offload_in
),
930 if (nonemb_cmd
.va
== NULL
) {
932 "Failed to allocate memory for mgmt_open_connection"
934 beiscsi_put_cid(phba
, beiscsi_ep
->ep_cid
);
937 nonemb_cmd
.size
= sizeof(struct tcp_connect_and_offload_in
);
938 memset(nonemb_cmd
.va
, 0, nonemb_cmd
.size
);
939 tag
= mgmt_open_connection(phba
, dst_addr
, beiscsi_ep
, &nonemb_cmd
);
942 "mgmt_open_connection Failed for cid=%d\n",
944 beiscsi_put_cid(phba
, beiscsi_ep
->ep_cid
);
945 pci_free_consistent(phba
->ctrl
.pdev
, nonemb_cmd
.size
,
946 nonemb_cmd
.va
, nonemb_cmd
.dma
);
949 wait_event_interruptible(phba
->ctrl
.mcc_wait
[tag
],
950 phba
->ctrl
.mcc_numtag
[tag
]);
952 wrb_num
= (phba
->ctrl
.mcc_numtag
[tag
] & 0x00FF0000) >> 16;
953 extd_status
= (phba
->ctrl
.mcc_numtag
[tag
] & 0x0000FF00) >> 8;
954 status
= phba
->ctrl
.mcc_numtag
[tag
] & 0x000000FF;
955 if (status
|| extd_status
) {
956 SE_DEBUG(DBG_LVL_1
, "mgmt_open_connection Failed"
957 " status = %d extd_status = %d\n",
958 status
, extd_status
);
959 free_mcc_tag(&phba
->ctrl
, tag
);
960 pci_free_consistent(phba
->ctrl
.pdev
, nonemb_cmd
.size
,
961 nonemb_cmd
.va
, nonemb_cmd
.dma
);
964 wrb
= queue_get_wrb(mccq
, wrb_num
);
965 free_mcc_tag(&phba
->ctrl
, tag
);
967 ptcpcnct_out
= embedded_payload(wrb
);
968 beiscsi_ep
= ep
->dd_data
;
969 beiscsi_ep
->fw_handle
= ptcpcnct_out
->connection_handle
;
970 beiscsi_ep
->cid_vld
= 1;
971 SE_DEBUG(DBG_LVL_8
, "mgmt_open_connection Success\n");
973 pci_free_consistent(phba
->ctrl
.pdev
, nonemb_cmd
.size
,
974 nonemb_cmd
.va
, nonemb_cmd
.dma
);
978 beiscsi_free_ep(beiscsi_ep
);
983 * beiscsi_ep_connect - Ask chip to create TCP Conn
984 * @scsi_host: Pointer to scsi_host structure
985 * @dst_addr: The IP address of Target
986 * @non_blocking: blocking or non-blocking call
988 * This routines first asks chip to create a connection and then allocates an EP
990 struct iscsi_endpoint
*
991 beiscsi_ep_connect(struct Scsi_Host
*shost
, struct sockaddr
*dst_addr
,
994 struct beiscsi_hba
*phba
;
995 struct beiscsi_endpoint
*beiscsi_ep
;
996 struct iscsi_endpoint
*ep
;
999 SE_DEBUG(DBG_LVL_8
, "In beiscsi_ep_connect\n");
1001 phba
= iscsi_host_priv(shost
);
1004 SE_DEBUG(DBG_LVL_1
, "shost is NULL\n");
1005 return ERR_PTR(ret
);
1008 if (phba
->state
!= BE_ADAPTER_UP
) {
1010 SE_DEBUG(DBG_LVL_1
, "The Adapter state is Not UP\n");
1011 return ERR_PTR(ret
);
1014 ep
= iscsi_create_endpoint(sizeof(struct beiscsi_endpoint
));
1017 return ERR_PTR(ret
);
1020 beiscsi_ep
= ep
->dd_data
;
1021 beiscsi_ep
->phba
= phba
;
1022 beiscsi_ep
->openiscsi_ep
= ep
;
1023 ret
= beiscsi_open_conn(ep
, NULL
, dst_addr
, non_blocking
);
1025 SE_DEBUG(DBG_LVL_1
, "Failed in beiscsi_open_conn\n");
1032 iscsi_destroy_endpoint(ep
);
1033 return ERR_PTR(ret
);
1037 * beiscsi_ep_poll - Poll to see if connection is established
1038 * @ep: endpoint to be used
1039 * @timeout_ms: timeout specified in millisecs
1041 * Poll to see if TCP connection established
1043 int beiscsi_ep_poll(struct iscsi_endpoint
*ep
, int timeout_ms
)
1045 struct beiscsi_endpoint
*beiscsi_ep
= ep
->dd_data
;
1047 SE_DEBUG(DBG_LVL_8
, "In beiscsi_ep_poll\n");
1048 if (beiscsi_ep
->cid_vld
== 1)
1055 * beiscsi_close_conn - Upload the connection
1056 * @ep: The iscsi endpoint
1057 * @flag: The type of connection closure
1059 static int beiscsi_close_conn(struct beiscsi_endpoint
*beiscsi_ep
, int flag
)
1063 struct beiscsi_hba
*phba
= beiscsi_ep
->phba
;
1065 tag
= mgmt_upload_connection(phba
, beiscsi_ep
->ep_cid
, flag
);
1067 SE_DEBUG(DBG_LVL_8
, "upload failed for cid 0x%x\n",
1068 beiscsi_ep
->ep_cid
);
1071 wait_event_interruptible(phba
->ctrl
.mcc_wait
[tag
],
1072 phba
->ctrl
.mcc_numtag
[tag
]);
1073 free_mcc_tag(&phba
->ctrl
, tag
);
1079 * beiscsi_unbind_conn_to_cid - Unbind the beiscsi_conn from phba conn table
1080 * @phba: The phba instance
1081 * @cid: The cid to free
1083 static int beiscsi_unbind_conn_to_cid(struct beiscsi_hba
*phba
,
1086 if (phba
->conn_table
[cid
])
1087 phba
->conn_table
[cid
] = NULL
;
1089 SE_DEBUG(DBG_LVL_8
, "Connection table Not occupied.\n");
1096 * beiscsi_ep_disconnect - Tears down the TCP connection
1097 * @ep: endpoint to be used
1099 * Tears down the TCP connection
1101 void beiscsi_ep_disconnect(struct iscsi_endpoint
*ep
)
1103 struct beiscsi_conn
*beiscsi_conn
;
1104 struct beiscsi_endpoint
*beiscsi_ep
;
1105 struct beiscsi_hba
*phba
;
1107 unsigned short savecfg_flag
= CMD_ISCSI_SESSION_SAVE_CFG_ON_FLASH
;
1109 beiscsi_ep
= ep
->dd_data
;
1110 phba
= beiscsi_ep
->phba
;
1111 SE_DEBUG(DBG_LVL_8
, "In beiscsi_ep_disconnect for ep_cid = %d\n",
1112 beiscsi_ep
->ep_cid
);
1114 if (!beiscsi_ep
->conn
) {
1115 SE_DEBUG(DBG_LVL_8
, "In beiscsi_ep_disconnect, no "
1119 beiscsi_conn
= beiscsi_ep
->conn
;
1120 iscsi_suspend_queue(beiscsi_conn
->conn
);
1122 SE_DEBUG(DBG_LVL_8
, "In beiscsi_ep_disconnect ep_cid = %d\n",
1123 beiscsi_ep
->ep_cid
);
1125 tag
= mgmt_invalidate_connection(phba
, beiscsi_ep
,
1126 beiscsi_ep
->ep_cid
, 1,
1130 "mgmt_invalidate_connection Failed for cid=%d\n",
1131 beiscsi_ep
->ep_cid
);
1133 wait_event_interruptible(phba
->ctrl
.mcc_wait
[tag
],
1134 phba
->ctrl
.mcc_numtag
[tag
]);
1135 free_mcc_tag(&phba
->ctrl
, tag
);
1138 beiscsi_close_conn(beiscsi_ep
, CONNECTION_UPLOAD_GRACEFUL
);
1139 beiscsi_free_ep(beiscsi_ep
);
1140 beiscsi_unbind_conn_to_cid(phba
, beiscsi_ep
->ep_cid
);
1141 iscsi_destroy_endpoint(beiscsi_ep
->openiscsi_ep
);
1144 umode_t
be2iscsi_attr_is_visible(int param_type
, int param
)
1146 switch (param_type
) {
1147 case ISCSI_NET_PARAM
:
1149 case ISCSI_NET_PARAM_IFACE_ENABLE
:
1150 case ISCSI_NET_PARAM_IPV4_ADDR
:
1151 case ISCSI_NET_PARAM_IPV4_SUBNET
:
1152 case ISCSI_NET_PARAM_IPV4_BOOTPROTO
:
1153 case ISCSI_NET_PARAM_IPV4_GW
:
1154 case ISCSI_NET_PARAM_IPV6_ADDR
:
1159 case ISCSI_HOST_PARAM
:
1161 case ISCSI_HOST_PARAM_HWADDRESS
:
1162 case ISCSI_HOST_PARAM_INITIATOR_NAME
:
1163 case ISCSI_HOST_PARAM_PORT_STATE
:
1164 case ISCSI_HOST_PARAM_PORT_SPEED
:
1171 case ISCSI_PARAM_MAX_RECV_DLENGTH
:
1172 case ISCSI_PARAM_MAX_XMIT_DLENGTH
:
1173 case ISCSI_PARAM_HDRDGST_EN
:
1174 case ISCSI_PARAM_DATADGST_EN
:
1175 case ISCSI_PARAM_CONN_ADDRESS
:
1176 case ISCSI_PARAM_CONN_PORT
:
1177 case ISCSI_PARAM_EXP_STATSN
:
1178 case ISCSI_PARAM_PERSISTENT_ADDRESS
:
1179 case ISCSI_PARAM_PERSISTENT_PORT
:
1180 case ISCSI_PARAM_PING_TMO
:
1181 case ISCSI_PARAM_RECV_TMO
:
1182 case ISCSI_PARAM_INITIAL_R2T_EN
:
1183 case ISCSI_PARAM_MAX_R2T
:
1184 case ISCSI_PARAM_IMM_DATA_EN
:
1185 case ISCSI_PARAM_FIRST_BURST
:
1186 case ISCSI_PARAM_MAX_BURST
:
1187 case ISCSI_PARAM_PDU_INORDER_EN
:
1188 case ISCSI_PARAM_DATASEQ_INORDER_EN
:
1189 case ISCSI_PARAM_ERL
:
1190 case ISCSI_PARAM_TARGET_NAME
:
1191 case ISCSI_PARAM_TPGT
:
1192 case ISCSI_PARAM_USERNAME
:
1193 case ISCSI_PARAM_PASSWORD
:
1194 case ISCSI_PARAM_USERNAME_IN
:
1195 case ISCSI_PARAM_PASSWORD_IN
:
1196 case ISCSI_PARAM_FAST_ABORT
:
1197 case ISCSI_PARAM_ABORT_TMO
:
1198 case ISCSI_PARAM_LU_RESET_TMO
:
1199 case ISCSI_PARAM_IFACE_NAME
:
1200 case ISCSI_PARAM_INITIATOR_NAME
: