2 * QLogic iSCSI HBA Driver
3 * Copyright (c) 2003-2013 QLogic Corporation
5 * See LICENSE.qla4xxx for copyright and licensing details.
7 #include <linux/moduleparam.h>
8 #include <linux/slab.h>
9 #include <linux/blkdev.h>
10 #include <linux/iscsi_boot_sysfs.h>
11 #include <linux/inet.h>
13 #include <scsi/scsi_tcq.h>
14 #include <scsi/scsicam.h>
17 #include "ql4_version.h"
20 #include "ql4_inline.h"
26 static char qla4xxx_version_str
[40];
29 * SRB allocation cache
31 static struct kmem_cache
*srb_cachep
;
34 * Module parameter information and variables
36 static int ql4xdisablesysfsboot
= 1;
37 module_param(ql4xdisablesysfsboot
, int, S_IRUGO
| S_IWUSR
);
38 MODULE_PARM_DESC(ql4xdisablesysfsboot
,
39 " Set to disable exporting boot targets to sysfs.\n"
40 "\t\t 0 - Export boot targets\n"
41 "\t\t 1 - Do not export boot targets (Default)");
44 module_param(ql4xdontresethba
, int, S_IRUGO
| S_IWUSR
);
45 MODULE_PARM_DESC(ql4xdontresethba
,
46 " Don't reset the HBA for driver recovery.\n"
47 "\t\t 0 - It will reset HBA (Default)\n"
48 "\t\t 1 - It will NOT reset HBA");
50 int ql4xextended_error_logging
;
51 module_param(ql4xextended_error_logging
, int, S_IRUGO
| S_IWUSR
);
52 MODULE_PARM_DESC(ql4xextended_error_logging
,
53 " Option to enable extended error logging.\n"
54 "\t\t 0 - no logging (Default)\n"
55 "\t\t 2 - debug logging");
57 int ql4xenablemsix
= 1;
58 module_param(ql4xenablemsix
, int, S_IRUGO
|S_IWUSR
);
59 MODULE_PARM_DESC(ql4xenablemsix
,
60 " Set to enable MSI or MSI-X interrupt mechanism.\n"
61 "\t\t 0 = enable INTx interrupt mechanism.\n"
62 "\t\t 1 = enable MSI-X interrupt mechanism (Default).\n"
63 "\t\t 2 = enable MSI interrupt mechanism.");
65 #define QL4_DEF_QDEPTH 32
66 static int ql4xmaxqdepth
= QL4_DEF_QDEPTH
;
67 module_param(ql4xmaxqdepth
, int, S_IRUGO
| S_IWUSR
);
68 MODULE_PARM_DESC(ql4xmaxqdepth
,
69 " Maximum queue depth to report for target devices.\n"
72 static int ql4xqfulltracking
= 1;
73 module_param(ql4xqfulltracking
, int, S_IRUGO
| S_IWUSR
);
74 MODULE_PARM_DESC(ql4xqfulltracking
,
75 " Enable or disable dynamic tracking and adjustment of\n"
76 "\t\t scsi device queue depth.\n"
78 "\t\t 1 - Enable. (Default)");
80 static int ql4xsess_recovery_tmo
= QL4_SESS_RECOVERY_TMO
;
81 module_param(ql4xsess_recovery_tmo
, int, S_IRUGO
);
82 MODULE_PARM_DESC(ql4xsess_recovery_tmo
,
83 " Target Session Recovery Timeout.\n"
84 "\t\t Default: 120 sec.");
86 int ql4xmdcapmask
= 0x1F;
87 module_param(ql4xmdcapmask
, int, S_IRUGO
);
88 MODULE_PARM_DESC(ql4xmdcapmask
,
89 " Set the Minidump driver capture mask level.\n"
90 "\t\t Default is 0x1F.\n"
91 "\t\t Can be set to 0x3, 0x7, 0xF, 0x1F, 0x3F, 0x7F");
94 module_param(ql4xenablemd
, int, S_IRUGO
| S_IWUSR
);
95 MODULE_PARM_DESC(ql4xenablemd
,
96 " Set to enable minidump.\n"
97 "\t\t 0 - disable minidump\n"
98 "\t\t 1 - enable minidump (Default)");
100 static int qla4xxx_wait_for_hba_online(struct scsi_qla_host
*ha
);
102 * SCSI host template entry points
104 static void qla4xxx_config_dma_addressing(struct scsi_qla_host
*ha
);
107 * iSCSI template entry points
109 static int qla4xxx_session_get_param(struct iscsi_cls_session
*cls_sess
,
110 enum iscsi_param param
, char *buf
);
111 static int qla4xxx_conn_get_param(struct iscsi_cls_conn
*conn
,
112 enum iscsi_param param
, char *buf
);
113 static int qla4xxx_host_get_param(struct Scsi_Host
*shost
,
114 enum iscsi_host_param param
, char *buf
);
115 static int qla4xxx_iface_set_param(struct Scsi_Host
*shost
, void *data
,
117 static int qla4xxx_get_iface_param(struct iscsi_iface
*iface
,
118 enum iscsi_param_type param_type
,
119 int param
, char *buf
);
120 static enum blk_eh_timer_return
qla4xxx_eh_cmd_timed_out(struct scsi_cmnd
*sc
);
121 static struct iscsi_endpoint
*qla4xxx_ep_connect(struct Scsi_Host
*shost
,
122 struct sockaddr
*dst_addr
,
124 static int qla4xxx_ep_poll(struct iscsi_endpoint
*ep
, int timeout_ms
);
125 static void qla4xxx_ep_disconnect(struct iscsi_endpoint
*ep
);
126 static int qla4xxx_get_ep_param(struct iscsi_endpoint
*ep
,
127 enum iscsi_param param
, char *buf
);
128 static int qla4xxx_conn_start(struct iscsi_cls_conn
*conn
);
129 static struct iscsi_cls_conn
*
130 qla4xxx_conn_create(struct iscsi_cls_session
*cls_sess
, uint32_t conn_idx
);
131 static int qla4xxx_conn_bind(struct iscsi_cls_session
*cls_session
,
132 struct iscsi_cls_conn
*cls_conn
,
133 uint64_t transport_fd
, int is_leading
);
134 static void qla4xxx_conn_destroy(struct iscsi_cls_conn
*conn
);
135 static struct iscsi_cls_session
*
136 qla4xxx_session_create(struct iscsi_endpoint
*ep
, uint16_t cmds_max
,
137 uint16_t qdepth
, uint32_t initial_cmdsn
);
138 static void qla4xxx_session_destroy(struct iscsi_cls_session
*sess
);
139 static void qla4xxx_task_work(struct work_struct
*wdata
);
140 static int qla4xxx_alloc_pdu(struct iscsi_task
*, uint8_t);
141 static int qla4xxx_task_xmit(struct iscsi_task
*);
142 static void qla4xxx_task_cleanup(struct iscsi_task
*);
143 static void qla4xxx_fail_session(struct iscsi_cls_session
*cls_session
);
144 static void qla4xxx_conn_get_stats(struct iscsi_cls_conn
*cls_conn
,
145 struct iscsi_stats
*stats
);
146 static int qla4xxx_send_ping(struct Scsi_Host
*shost
, uint32_t iface_num
,
147 uint32_t iface_type
, uint32_t payload_size
,
148 uint32_t pid
, struct sockaddr
*dst_addr
);
149 static int qla4xxx_get_chap_list(struct Scsi_Host
*shost
, uint16_t chap_tbl_idx
,
150 uint32_t *num_entries
, char *buf
);
151 static int qla4xxx_delete_chap(struct Scsi_Host
*shost
, uint16_t chap_tbl_idx
);
154 * SCSI host template entry points
156 static int qla4xxx_queuecommand(struct Scsi_Host
*h
, struct scsi_cmnd
*cmd
);
157 static int qla4xxx_eh_abort(struct scsi_cmnd
*cmd
);
158 static int qla4xxx_eh_device_reset(struct scsi_cmnd
*cmd
);
159 static int qla4xxx_eh_target_reset(struct scsi_cmnd
*cmd
);
160 static int qla4xxx_eh_host_reset(struct scsi_cmnd
*cmd
);
161 static int qla4xxx_slave_alloc(struct scsi_device
*device
);
162 static int qla4xxx_slave_configure(struct scsi_device
*device
);
163 static void qla4xxx_slave_destroy(struct scsi_device
*sdev
);
164 static umode_t
qla4_attr_is_visible(int param_type
, int param
);
165 static int qla4xxx_host_reset(struct Scsi_Host
*shost
, int reset_type
);
166 static int qla4xxx_change_queue_depth(struct scsi_device
*sdev
, int qdepth
,
170 * iSCSI Flash DDB sysfs entry points
173 qla4xxx_sysfs_ddb_set_param(struct iscsi_bus_flash_session
*fnode_sess
,
174 struct iscsi_bus_flash_conn
*fnode_conn
,
175 void *data
, int len
);
177 qla4xxx_sysfs_ddb_get_param(struct iscsi_bus_flash_session
*fnode_sess
,
178 int param
, char *buf
);
179 static int qla4xxx_sysfs_ddb_add(struct Scsi_Host
*shost
, const char *buf
,
182 qla4xxx_sysfs_ddb_delete(struct iscsi_bus_flash_session
*fnode_sess
);
183 static int qla4xxx_sysfs_ddb_login(struct iscsi_bus_flash_session
*fnode_sess
,
184 struct iscsi_bus_flash_conn
*fnode_conn
);
185 static int qla4xxx_sysfs_ddb_logout(struct iscsi_bus_flash_session
*fnode_sess
,
186 struct iscsi_bus_flash_conn
*fnode_conn
);
187 static int qla4xxx_sysfs_ddb_logout_sid(struct iscsi_cls_session
*cls_sess
);
189 static struct qla4_8xxx_legacy_intr_set legacy_intr
[] =
190 QLA82XX_LEGACY_INTR_CONFIG
;
192 static struct scsi_host_template qla4xxx_driver_template
= {
193 .module
= THIS_MODULE
,
195 .proc_name
= DRIVER_NAME
,
196 .queuecommand
= qla4xxx_queuecommand
,
198 .eh_abort_handler
= qla4xxx_eh_abort
,
199 .eh_device_reset_handler
= qla4xxx_eh_device_reset
,
200 .eh_target_reset_handler
= qla4xxx_eh_target_reset
,
201 .eh_host_reset_handler
= qla4xxx_eh_host_reset
,
202 .eh_timed_out
= qla4xxx_eh_cmd_timed_out
,
204 .slave_configure
= qla4xxx_slave_configure
,
205 .slave_alloc
= qla4xxx_slave_alloc
,
206 .slave_destroy
= qla4xxx_slave_destroy
,
207 .change_queue_depth
= qla4xxx_change_queue_depth
,
211 .use_clustering
= ENABLE_CLUSTERING
,
212 .sg_tablesize
= SG_ALL
,
214 .max_sectors
= 0xFFFF,
215 .shost_attrs
= qla4xxx_host_attrs
,
216 .host_reset
= qla4xxx_host_reset
,
217 .vendor_id
= SCSI_NL_VID_TYPE_PCI
| PCI_VENDOR_ID_QLOGIC
,
220 static struct iscsi_transport qla4xxx_iscsi_transport
= {
221 .owner
= THIS_MODULE
,
223 .caps
= CAP_TEXT_NEGO
|
224 CAP_DATA_PATH_OFFLOAD
| CAP_HDRDGST
|
225 CAP_DATADGST
| CAP_LOGIN_OFFLOAD
|
227 .attr_is_visible
= qla4_attr_is_visible
,
228 .create_session
= qla4xxx_session_create
,
229 .destroy_session
= qla4xxx_session_destroy
,
230 .start_conn
= qla4xxx_conn_start
,
231 .create_conn
= qla4xxx_conn_create
,
232 .bind_conn
= qla4xxx_conn_bind
,
233 .stop_conn
= iscsi_conn_stop
,
234 .destroy_conn
= qla4xxx_conn_destroy
,
235 .set_param
= iscsi_set_param
,
236 .get_conn_param
= qla4xxx_conn_get_param
,
237 .get_session_param
= qla4xxx_session_get_param
,
238 .get_ep_param
= qla4xxx_get_ep_param
,
239 .ep_connect
= qla4xxx_ep_connect
,
240 .ep_poll
= qla4xxx_ep_poll
,
241 .ep_disconnect
= qla4xxx_ep_disconnect
,
242 .get_stats
= qla4xxx_conn_get_stats
,
243 .send_pdu
= iscsi_conn_send_pdu
,
244 .xmit_task
= qla4xxx_task_xmit
,
245 .cleanup_task
= qla4xxx_task_cleanup
,
246 .alloc_pdu
= qla4xxx_alloc_pdu
,
248 .get_host_param
= qla4xxx_host_get_param
,
249 .set_iface_param
= qla4xxx_iface_set_param
,
250 .get_iface_param
= qla4xxx_get_iface_param
,
251 .bsg_request
= qla4xxx_bsg_request
,
252 .send_ping
= qla4xxx_send_ping
,
253 .get_chap
= qla4xxx_get_chap_list
,
254 .delete_chap
= qla4xxx_delete_chap
,
255 .get_flashnode_param
= qla4xxx_sysfs_ddb_get_param
,
256 .set_flashnode_param
= qla4xxx_sysfs_ddb_set_param
,
257 .new_flashnode
= qla4xxx_sysfs_ddb_add
,
258 .del_flashnode
= qla4xxx_sysfs_ddb_delete
,
259 .login_flashnode
= qla4xxx_sysfs_ddb_login
,
260 .logout_flashnode
= qla4xxx_sysfs_ddb_logout
,
261 .logout_flashnode_sid
= qla4xxx_sysfs_ddb_logout_sid
,
264 static struct scsi_transport_template
*qla4xxx_scsi_transport
;
266 static int qla4xxx_send_ping(struct Scsi_Host
*shost
, uint32_t iface_num
,
267 uint32_t iface_type
, uint32_t payload_size
,
268 uint32_t pid
, struct sockaddr
*dst_addr
)
270 struct scsi_qla_host
*ha
= to_qla_host(shost
);
271 struct sockaddr_in
*addr
;
272 struct sockaddr_in6
*addr6
;
273 uint32_t options
= 0;
274 uint8_t ipaddr
[IPv6_ADDR_LEN
];
277 memset(ipaddr
, 0, IPv6_ADDR_LEN
);
279 if ((iface_type
== ISCSI_IFACE_TYPE_IPV4
) &&
280 (dst_addr
->sa_family
== AF_INET
)) {
281 addr
= (struct sockaddr_in
*)dst_addr
;
282 memcpy(ipaddr
, &addr
->sin_addr
.s_addr
, IP_ADDR_LEN
);
283 DEBUG2(ql4_printk(KERN_INFO
, ha
, "%s: IPv4 Ping src: %pI4 "
284 "dest: %pI4\n", __func__
,
285 &ha
->ip_config
.ip_address
, ipaddr
));
286 rval
= qla4xxx_ping_iocb(ha
, options
, payload_size
, pid
,
290 } else if ((iface_type
== ISCSI_IFACE_TYPE_IPV6
) &&
291 (dst_addr
->sa_family
== AF_INET6
)) {
293 addr6
= (struct sockaddr_in6
*)dst_addr
;
294 memcpy(ipaddr
, &addr6
->sin6_addr
.in6_u
.u6_addr8
, IPv6_ADDR_LEN
);
296 options
|= PING_IPV6_PROTOCOL_ENABLE
;
298 /* Ping using LinkLocal address */
299 if ((iface_num
== 0) || (iface_num
== 1)) {
300 DEBUG2(ql4_printk(KERN_INFO
, ha
, "%s: LinkLocal Ping "
301 "src: %pI6 dest: %pI6\n", __func__
,
302 &ha
->ip_config
.ipv6_link_local_addr
,
304 options
|= PING_IPV6_LINKLOCAL_ADDR
;
305 rval
= qla4xxx_ping_iocb(ha
, options
, payload_size
,
308 ql4_printk(KERN_WARNING
, ha
, "%s: iface num = %d "
309 "not supported\n", __func__
, iface_num
);
315 * If ping using LinkLocal address fails, try ping using
318 if (rval
!= QLA_SUCCESS
) {
319 options
&= ~PING_IPV6_LINKLOCAL_ADDR
;
320 if (iface_num
== 0) {
321 options
|= PING_IPV6_ADDR0
;
322 DEBUG2(ql4_printk(KERN_INFO
, ha
, "%s: IPv6 "
324 "dest: %pI6\n", __func__
,
325 &ha
->ip_config
.ipv6_addr0
,
327 } else if (iface_num
== 1) {
328 options
|= PING_IPV6_ADDR1
;
329 DEBUG2(ql4_printk(KERN_INFO
, ha
, "%s: IPv6 "
331 "dest: %pI6\n", __func__
,
332 &ha
->ip_config
.ipv6_addr1
,
335 rval
= qla4xxx_ping_iocb(ha
, options
, payload_size
,
346 static umode_t
qla4_attr_is_visible(int param_type
, int param
)
348 switch (param_type
) {
349 case ISCSI_HOST_PARAM
:
351 case ISCSI_HOST_PARAM_HWADDRESS
:
352 case ISCSI_HOST_PARAM_IPADDRESS
:
353 case ISCSI_HOST_PARAM_INITIATOR_NAME
:
354 case ISCSI_HOST_PARAM_PORT_STATE
:
355 case ISCSI_HOST_PARAM_PORT_SPEED
:
362 case ISCSI_PARAM_PERSISTENT_ADDRESS
:
363 case ISCSI_PARAM_PERSISTENT_PORT
:
364 case ISCSI_PARAM_CONN_ADDRESS
:
365 case ISCSI_PARAM_CONN_PORT
:
366 case ISCSI_PARAM_TARGET_NAME
:
367 case ISCSI_PARAM_TPGT
:
368 case ISCSI_PARAM_TARGET_ALIAS
:
369 case ISCSI_PARAM_MAX_BURST
:
370 case ISCSI_PARAM_MAX_R2T
:
371 case ISCSI_PARAM_FIRST_BURST
:
372 case ISCSI_PARAM_MAX_RECV_DLENGTH
:
373 case ISCSI_PARAM_MAX_XMIT_DLENGTH
:
374 case ISCSI_PARAM_IFACE_NAME
:
375 case ISCSI_PARAM_CHAP_OUT_IDX
:
376 case ISCSI_PARAM_CHAP_IN_IDX
:
377 case ISCSI_PARAM_USERNAME
:
378 case ISCSI_PARAM_PASSWORD
:
379 case ISCSI_PARAM_USERNAME_IN
:
380 case ISCSI_PARAM_PASSWORD_IN
:
381 case ISCSI_PARAM_AUTO_SND_TGT_DISABLE
:
382 case ISCSI_PARAM_DISCOVERY_SESS
:
383 case ISCSI_PARAM_PORTAL_TYPE
:
384 case ISCSI_PARAM_CHAP_AUTH_EN
:
385 case ISCSI_PARAM_DISCOVERY_LOGOUT_EN
:
386 case ISCSI_PARAM_BIDI_CHAP_EN
:
387 case ISCSI_PARAM_DISCOVERY_AUTH_OPTIONAL
:
388 case ISCSI_PARAM_DEF_TIME2WAIT
:
389 case ISCSI_PARAM_DEF_TIME2RETAIN
:
390 case ISCSI_PARAM_HDRDGST_EN
:
391 case ISCSI_PARAM_DATADGST_EN
:
392 case ISCSI_PARAM_INITIAL_R2T_EN
:
393 case ISCSI_PARAM_IMM_DATA_EN
:
394 case ISCSI_PARAM_PDU_INORDER_EN
:
395 case ISCSI_PARAM_DATASEQ_INORDER_EN
:
396 case ISCSI_PARAM_MAX_SEGMENT_SIZE
:
397 case ISCSI_PARAM_TCP_TIMESTAMP_STAT
:
398 case ISCSI_PARAM_TCP_WSF_DISABLE
:
399 case ISCSI_PARAM_TCP_NAGLE_DISABLE
:
400 case ISCSI_PARAM_TCP_TIMER_SCALE
:
401 case ISCSI_PARAM_TCP_TIMESTAMP_EN
:
402 case ISCSI_PARAM_TCP_XMIT_WSF
:
403 case ISCSI_PARAM_TCP_RECV_WSF
:
404 case ISCSI_PARAM_IP_FRAGMENT_DISABLE
:
405 case ISCSI_PARAM_IPV4_TOS
:
406 case ISCSI_PARAM_IPV6_TC
:
407 case ISCSI_PARAM_IPV6_FLOW_LABEL
:
408 case ISCSI_PARAM_IS_FW_ASSIGNED_IPV6
:
409 case ISCSI_PARAM_KEEPALIVE_TMO
:
410 case ISCSI_PARAM_LOCAL_PORT
:
411 case ISCSI_PARAM_ISID
:
412 case ISCSI_PARAM_TSID
:
413 case ISCSI_PARAM_DEF_TASKMGMT_TMO
:
414 case ISCSI_PARAM_ERL
:
415 case ISCSI_PARAM_STATSN
:
416 case ISCSI_PARAM_EXP_STATSN
:
417 case ISCSI_PARAM_DISCOVERY_PARENT_IDX
:
418 case ISCSI_PARAM_DISCOVERY_PARENT_TYPE
:
423 case ISCSI_NET_PARAM
:
425 case ISCSI_NET_PARAM_IPV4_ADDR
:
426 case ISCSI_NET_PARAM_IPV4_SUBNET
:
427 case ISCSI_NET_PARAM_IPV4_GW
:
428 case ISCSI_NET_PARAM_IPV4_BOOTPROTO
:
429 case ISCSI_NET_PARAM_IFACE_ENABLE
:
430 case ISCSI_NET_PARAM_IPV6_LINKLOCAL
:
431 case ISCSI_NET_PARAM_IPV6_ADDR
:
432 case ISCSI_NET_PARAM_IPV6_ROUTER
:
433 case ISCSI_NET_PARAM_IPV6_ADDR_AUTOCFG
:
434 case ISCSI_NET_PARAM_IPV6_LINKLOCAL_AUTOCFG
:
435 case ISCSI_NET_PARAM_VLAN_ID
:
436 case ISCSI_NET_PARAM_VLAN_PRIORITY
:
437 case ISCSI_NET_PARAM_VLAN_ENABLED
:
438 case ISCSI_NET_PARAM_MTU
:
439 case ISCSI_NET_PARAM_PORT
:
444 case ISCSI_FLASHNODE_PARAM
:
446 case ISCSI_FLASHNODE_IS_FW_ASSIGNED_IPV6
:
447 case ISCSI_FLASHNODE_PORTAL_TYPE
:
448 case ISCSI_FLASHNODE_AUTO_SND_TGT_DISABLE
:
449 case ISCSI_FLASHNODE_DISCOVERY_SESS
:
450 case ISCSI_FLASHNODE_ENTRY_EN
:
451 case ISCSI_FLASHNODE_HDR_DGST_EN
:
452 case ISCSI_FLASHNODE_DATA_DGST_EN
:
453 case ISCSI_FLASHNODE_IMM_DATA_EN
:
454 case ISCSI_FLASHNODE_INITIAL_R2T_EN
:
455 case ISCSI_FLASHNODE_DATASEQ_INORDER
:
456 case ISCSI_FLASHNODE_PDU_INORDER
:
457 case ISCSI_FLASHNODE_CHAP_AUTH_EN
:
458 case ISCSI_FLASHNODE_SNACK_REQ_EN
:
459 case ISCSI_FLASHNODE_DISCOVERY_LOGOUT_EN
:
460 case ISCSI_FLASHNODE_BIDI_CHAP_EN
:
461 case ISCSI_FLASHNODE_DISCOVERY_AUTH_OPTIONAL
:
462 case ISCSI_FLASHNODE_ERL
:
463 case ISCSI_FLASHNODE_TCP_TIMESTAMP_STAT
:
464 case ISCSI_FLASHNODE_TCP_NAGLE_DISABLE
:
465 case ISCSI_FLASHNODE_TCP_WSF_DISABLE
:
466 case ISCSI_FLASHNODE_TCP_TIMER_SCALE
:
467 case ISCSI_FLASHNODE_TCP_TIMESTAMP_EN
:
468 case ISCSI_FLASHNODE_IP_FRAG_DISABLE
:
469 case ISCSI_FLASHNODE_MAX_RECV_DLENGTH
:
470 case ISCSI_FLASHNODE_MAX_XMIT_DLENGTH
:
471 case ISCSI_FLASHNODE_FIRST_BURST
:
472 case ISCSI_FLASHNODE_DEF_TIME2WAIT
:
473 case ISCSI_FLASHNODE_DEF_TIME2RETAIN
:
474 case ISCSI_FLASHNODE_MAX_R2T
:
475 case ISCSI_FLASHNODE_KEEPALIVE_TMO
:
476 case ISCSI_FLASHNODE_ISID
:
477 case ISCSI_FLASHNODE_TSID
:
478 case ISCSI_FLASHNODE_PORT
:
479 case ISCSI_FLASHNODE_MAX_BURST
:
480 case ISCSI_FLASHNODE_DEF_TASKMGMT_TMO
:
481 case ISCSI_FLASHNODE_IPADDR
:
482 case ISCSI_FLASHNODE_ALIAS
:
483 case ISCSI_FLASHNODE_REDIRECT_IPADDR
:
484 case ISCSI_FLASHNODE_MAX_SEGMENT_SIZE
:
485 case ISCSI_FLASHNODE_LOCAL_PORT
:
486 case ISCSI_FLASHNODE_IPV4_TOS
:
487 case ISCSI_FLASHNODE_IPV6_TC
:
488 case ISCSI_FLASHNODE_IPV6_FLOW_LABEL
:
489 case ISCSI_FLASHNODE_NAME
:
490 case ISCSI_FLASHNODE_TPGT
:
491 case ISCSI_FLASHNODE_LINK_LOCAL_IPV6
:
492 case ISCSI_FLASHNODE_DISCOVERY_PARENT_IDX
:
493 case ISCSI_FLASHNODE_DISCOVERY_PARENT_TYPE
:
494 case ISCSI_FLASHNODE_TCP_XMIT_WSF
:
495 case ISCSI_FLASHNODE_TCP_RECV_WSF
:
496 case ISCSI_FLASHNODE_CHAP_OUT_IDX
:
497 case ISCSI_FLASHNODE_USERNAME
:
498 case ISCSI_FLASHNODE_PASSWORD
:
499 case ISCSI_FLASHNODE_STATSN
:
500 case ISCSI_FLASHNODE_EXP_STATSN
:
501 case ISCSI_FLASHNODE_IS_BOOT_TGT
:
511 static int qla4xxx_get_chap_list(struct Scsi_Host
*shost
, uint16_t chap_tbl_idx
,
512 uint32_t *num_entries
, char *buf
)
514 struct scsi_qla_host
*ha
= to_qla_host(shost
);
515 struct ql4_chap_table
*chap_table
;
516 struct iscsi_chap_rec
*chap_rec
;
517 int max_chap_entries
= 0;
518 int valid_chap_entries
= 0;
522 max_chap_entries
= (ha
->hw
.flt_chap_size
/ 2) /
523 sizeof(struct ql4_chap_table
);
525 max_chap_entries
= MAX_CHAP_ENTRIES_40XX
;
527 ql4_printk(KERN_INFO
, ha
, "%s: num_entries = %d, CHAP idx = %d\n",
528 __func__
, *num_entries
, chap_tbl_idx
);
532 goto exit_get_chap_list
;
535 chap_rec
= (struct iscsi_chap_rec
*) buf
;
536 mutex_lock(&ha
->chap_sem
);
537 for (i
= chap_tbl_idx
; i
< max_chap_entries
; i
++) {
538 chap_table
= (struct ql4_chap_table
*)ha
->chap_list
+ i
;
539 if (chap_table
->cookie
!=
540 __constant_cpu_to_le16(CHAP_VALID_COOKIE
))
543 chap_rec
->chap_tbl_idx
= i
;
544 strncpy(chap_rec
->username
, chap_table
->name
,
545 ISCSI_CHAP_AUTH_NAME_MAX_LEN
);
546 strncpy(chap_rec
->password
, chap_table
->secret
,
547 QL4_CHAP_MAX_SECRET_LEN
);
548 chap_rec
->password_length
= chap_table
->secret_len
;
550 if (chap_table
->flags
& BIT_7
) /* local */
551 chap_rec
->chap_type
= CHAP_TYPE_OUT
;
553 if (chap_table
->flags
& BIT_6
) /* peer */
554 chap_rec
->chap_type
= CHAP_TYPE_IN
;
558 valid_chap_entries
++;
559 if (valid_chap_entries
== *num_entries
)
564 mutex_unlock(&ha
->chap_sem
);
567 ql4_printk(KERN_INFO
, ha
, "%s: Valid CHAP Entries = %d\n",
568 __func__
, valid_chap_entries
);
569 *num_entries
= valid_chap_entries
;
573 static int __qla4xxx_is_chap_active(struct device
*dev
, void *data
)
576 uint16_t *chap_tbl_idx
= (uint16_t *) data
;
577 struct iscsi_cls_session
*cls_session
;
578 struct iscsi_session
*sess
;
579 struct ddb_entry
*ddb_entry
;
581 if (!iscsi_is_session_dev(dev
))
582 goto exit_is_chap_active
;
584 cls_session
= iscsi_dev_to_session(dev
);
585 sess
= cls_session
->dd_data
;
586 ddb_entry
= sess
->dd_data
;
588 if (iscsi_session_chkready(cls_session
))
589 goto exit_is_chap_active
;
591 if (ddb_entry
->chap_tbl_idx
== *chap_tbl_idx
)
598 static int qla4xxx_is_chap_active(struct Scsi_Host
*shost
,
599 uint16_t chap_tbl_idx
)
603 ret
= device_for_each_child(&shost
->shost_gendev
, &chap_tbl_idx
,
604 __qla4xxx_is_chap_active
);
609 static int qla4xxx_delete_chap(struct Scsi_Host
*shost
, uint16_t chap_tbl_idx
)
611 struct scsi_qla_host
*ha
= to_qla_host(shost
);
612 struct ql4_chap_table
*chap_table
;
614 int max_chap_entries
= 0;
619 chap_table
= dma_pool_alloc(ha
->chap_dma_pool
, GFP_KERNEL
, &chap_dma
);
620 if (chap_table
== NULL
)
623 memset(chap_table
, 0, sizeof(struct ql4_chap_table
));
626 max_chap_entries
= (ha
->hw
.flt_chap_size
/ 2) /
627 sizeof(struct ql4_chap_table
);
629 max_chap_entries
= MAX_CHAP_ENTRIES_40XX
;
631 if (chap_tbl_idx
> max_chap_entries
) {
633 goto exit_delete_chap
;
636 /* Check if chap index is in use.
637 * If chap is in use don't delet chap entry */
638 ret
= qla4xxx_is_chap_active(shost
, chap_tbl_idx
);
640 ql4_printk(KERN_INFO
, ha
, "CHAP entry %d is in use, cannot "
641 "delete from flash\n", chap_tbl_idx
);
643 goto exit_delete_chap
;
646 chap_size
= sizeof(struct ql4_chap_table
);
648 offset
= FLASH_CHAP_OFFSET
| (chap_tbl_idx
* chap_size
);
650 offset
= FLASH_RAW_ACCESS_ADDR
+ (ha
->hw
.flt_region_chap
<< 2);
651 /* flt_chap_size is CHAP table size for both ports
652 * so divide it by 2 to calculate the offset for second port
654 if (ha
->port_num
== 1)
655 offset
+= (ha
->hw
.flt_chap_size
/ 2);
656 offset
+= (chap_tbl_idx
* chap_size
);
659 ret
= qla4xxx_get_flash(ha
, chap_dma
, offset
, chap_size
);
660 if (ret
!= QLA_SUCCESS
) {
662 goto exit_delete_chap
;
665 DEBUG2(ql4_printk(KERN_INFO
, ha
, "Chap Cookie: x%x\n",
666 __le16_to_cpu(chap_table
->cookie
)));
668 if (__le16_to_cpu(chap_table
->cookie
) != CHAP_VALID_COOKIE
) {
669 ql4_printk(KERN_ERR
, ha
, "No valid chap entry found\n");
670 goto exit_delete_chap
;
673 chap_table
->cookie
= __constant_cpu_to_le16(0xFFFF);
675 offset
= FLASH_CHAP_OFFSET
|
676 (chap_tbl_idx
* sizeof(struct ql4_chap_table
));
677 ret
= qla4xxx_set_flash(ha
, chap_dma
, offset
, chap_size
,
678 FLASH_OPT_RMW_COMMIT
);
679 if (ret
== QLA_SUCCESS
&& ha
->chap_list
) {
680 mutex_lock(&ha
->chap_sem
);
681 /* Update ha chap_list cache */
682 memcpy((struct ql4_chap_table
*)ha
->chap_list
+ chap_tbl_idx
,
683 chap_table
, sizeof(struct ql4_chap_table
));
684 mutex_unlock(&ha
->chap_sem
);
686 if (ret
!= QLA_SUCCESS
)
690 dma_pool_free(ha
->chap_dma_pool
, chap_table
, chap_dma
);
694 static int qla4xxx_get_iface_param(struct iscsi_iface
*iface
,
695 enum iscsi_param_type param_type
,
696 int param
, char *buf
)
698 struct Scsi_Host
*shost
= iscsi_iface_to_shost(iface
);
699 struct scsi_qla_host
*ha
= to_qla_host(shost
);
702 if (param_type
!= ISCSI_NET_PARAM
)
706 case ISCSI_NET_PARAM_IPV4_ADDR
:
707 len
= sprintf(buf
, "%pI4\n", &ha
->ip_config
.ip_address
);
709 case ISCSI_NET_PARAM_IPV4_SUBNET
:
710 len
= sprintf(buf
, "%pI4\n", &ha
->ip_config
.subnet_mask
);
712 case ISCSI_NET_PARAM_IPV4_GW
:
713 len
= sprintf(buf
, "%pI4\n", &ha
->ip_config
.gateway
);
715 case ISCSI_NET_PARAM_IFACE_ENABLE
:
716 if (iface
->iface_type
== ISCSI_IFACE_TYPE_IPV4
)
717 len
= sprintf(buf
, "%s\n",
718 (ha
->ip_config
.ipv4_options
&
719 IPOPT_IPV4_PROTOCOL_ENABLE
) ?
720 "enabled" : "disabled");
721 else if (iface
->iface_type
== ISCSI_IFACE_TYPE_IPV6
)
722 len
= sprintf(buf
, "%s\n",
723 (ha
->ip_config
.ipv6_options
&
724 IPV6_OPT_IPV6_PROTOCOL_ENABLE
) ?
725 "enabled" : "disabled");
727 case ISCSI_NET_PARAM_IPV4_BOOTPROTO
:
728 len
= sprintf(buf
, "%s\n",
729 (ha
->ip_config
.tcp_options
& TCPOPT_DHCP_ENABLE
) ?
732 case ISCSI_NET_PARAM_IPV6_ADDR
:
733 if (iface
->iface_num
== 0)
734 len
= sprintf(buf
, "%pI6\n", &ha
->ip_config
.ipv6_addr0
);
735 if (iface
->iface_num
== 1)
736 len
= sprintf(buf
, "%pI6\n", &ha
->ip_config
.ipv6_addr1
);
738 case ISCSI_NET_PARAM_IPV6_LINKLOCAL
:
739 len
= sprintf(buf
, "%pI6\n",
740 &ha
->ip_config
.ipv6_link_local_addr
);
742 case ISCSI_NET_PARAM_IPV6_ROUTER
:
743 len
= sprintf(buf
, "%pI6\n",
744 &ha
->ip_config
.ipv6_default_router_addr
);
746 case ISCSI_NET_PARAM_IPV6_ADDR_AUTOCFG
:
747 len
= sprintf(buf
, "%s\n",
748 (ha
->ip_config
.ipv6_addl_options
&
749 IPV6_ADDOPT_NEIGHBOR_DISCOVERY_ADDR_ENABLE
) ?
752 case ISCSI_NET_PARAM_IPV6_LINKLOCAL_AUTOCFG
:
753 len
= sprintf(buf
, "%s\n",
754 (ha
->ip_config
.ipv6_addl_options
&
755 IPV6_ADDOPT_AUTOCONFIG_LINK_LOCAL_ADDR
) ?
758 case ISCSI_NET_PARAM_VLAN_ID
:
759 if (iface
->iface_type
== ISCSI_IFACE_TYPE_IPV4
)
760 len
= sprintf(buf
, "%d\n",
761 (ha
->ip_config
.ipv4_vlan_tag
&
763 else if (iface
->iface_type
== ISCSI_IFACE_TYPE_IPV6
)
764 len
= sprintf(buf
, "%d\n",
765 (ha
->ip_config
.ipv6_vlan_tag
&
768 case ISCSI_NET_PARAM_VLAN_PRIORITY
:
769 if (iface
->iface_type
== ISCSI_IFACE_TYPE_IPV4
)
770 len
= sprintf(buf
, "%d\n",
771 ((ha
->ip_config
.ipv4_vlan_tag
>> 13) &
772 ISCSI_MAX_VLAN_PRIORITY
));
773 else if (iface
->iface_type
== ISCSI_IFACE_TYPE_IPV6
)
774 len
= sprintf(buf
, "%d\n",
775 ((ha
->ip_config
.ipv6_vlan_tag
>> 13) &
776 ISCSI_MAX_VLAN_PRIORITY
));
778 case ISCSI_NET_PARAM_VLAN_ENABLED
:
779 if (iface
->iface_type
== ISCSI_IFACE_TYPE_IPV4
)
780 len
= sprintf(buf
, "%s\n",
781 (ha
->ip_config
.ipv4_options
&
782 IPOPT_VLAN_TAGGING_ENABLE
) ?
783 "enabled" : "disabled");
784 else if (iface
->iface_type
== ISCSI_IFACE_TYPE_IPV6
)
785 len
= sprintf(buf
, "%s\n",
786 (ha
->ip_config
.ipv6_options
&
787 IPV6_OPT_VLAN_TAGGING_ENABLE
) ?
788 "enabled" : "disabled");
790 case ISCSI_NET_PARAM_MTU
:
791 len
= sprintf(buf
, "%d\n", ha
->ip_config
.eth_mtu_size
);
793 case ISCSI_NET_PARAM_PORT
:
794 if (iface
->iface_type
== ISCSI_IFACE_TYPE_IPV4
)
795 len
= sprintf(buf
, "%d\n", ha
->ip_config
.ipv4_port
);
796 else if (iface
->iface_type
== ISCSI_IFACE_TYPE_IPV6
)
797 len
= sprintf(buf
, "%d\n", ha
->ip_config
.ipv6_port
);
806 static struct iscsi_endpoint
*
807 qla4xxx_ep_connect(struct Scsi_Host
*shost
, struct sockaddr
*dst_addr
,
811 struct iscsi_endpoint
*ep
;
812 struct qla_endpoint
*qla_ep
;
813 struct scsi_qla_host
*ha
;
814 struct sockaddr_in
*addr
;
815 struct sockaddr_in6
*addr6
;
817 DEBUG2(printk(KERN_INFO
"Func: %s\n", __func__
));
820 printk(KERN_ERR
"%s: shost is NULL\n",
825 ha
= iscsi_host_priv(shost
);
827 ep
= iscsi_create_endpoint(sizeof(struct qla_endpoint
));
833 qla_ep
= ep
->dd_data
;
834 memset(qla_ep
, 0, sizeof(struct qla_endpoint
));
835 if (dst_addr
->sa_family
== AF_INET
) {
836 memcpy(&qla_ep
->dst_addr
, dst_addr
, sizeof(struct sockaddr_in
));
837 addr
= (struct sockaddr_in
*)&qla_ep
->dst_addr
;
838 DEBUG2(ql4_printk(KERN_INFO
, ha
, "%s: %pI4\n", __func__
,
839 (char *)&addr
->sin_addr
));
840 } else if (dst_addr
->sa_family
== AF_INET6
) {
841 memcpy(&qla_ep
->dst_addr
, dst_addr
,
842 sizeof(struct sockaddr_in6
));
843 addr6
= (struct sockaddr_in6
*)&qla_ep
->dst_addr
;
844 DEBUG2(ql4_printk(KERN_INFO
, ha
, "%s: %pI6\n", __func__
,
845 (char *)&addr6
->sin6_addr
));
848 qla_ep
->host
= shost
;
853 static int qla4xxx_ep_poll(struct iscsi_endpoint
*ep
, int timeout_ms
)
855 struct qla_endpoint
*qla_ep
;
856 struct scsi_qla_host
*ha
;
859 DEBUG2(printk(KERN_INFO
"Func: %s\n", __func__
));
860 qla_ep
= ep
->dd_data
;
861 ha
= to_qla_host(qla_ep
->host
);
863 if (adapter_up(ha
) && !test_bit(AF_BUILD_DDB_LIST
, &ha
->flags
))
869 static void qla4xxx_ep_disconnect(struct iscsi_endpoint
*ep
)
871 DEBUG2(printk(KERN_INFO
"Func: %s\n", __func__
));
872 iscsi_destroy_endpoint(ep
);
875 static int qla4xxx_get_ep_param(struct iscsi_endpoint
*ep
,
876 enum iscsi_param param
,
879 struct qla_endpoint
*qla_ep
= ep
->dd_data
;
880 struct sockaddr
*dst_addr
;
882 DEBUG2(printk(KERN_INFO
"Func: %s\n", __func__
));
885 case ISCSI_PARAM_CONN_PORT
:
886 case ISCSI_PARAM_CONN_ADDRESS
:
890 dst_addr
= (struct sockaddr
*)&qla_ep
->dst_addr
;
894 return iscsi_conn_get_addr_param((struct sockaddr_storage
*)
895 &qla_ep
->dst_addr
, param
, buf
);
901 static void qla4xxx_conn_get_stats(struct iscsi_cls_conn
*cls_conn
,
902 struct iscsi_stats
*stats
)
904 struct iscsi_session
*sess
;
905 struct iscsi_cls_session
*cls_sess
;
906 struct ddb_entry
*ddb_entry
;
907 struct scsi_qla_host
*ha
;
908 struct ql_iscsi_stats
*ql_iscsi_stats
;
911 dma_addr_t iscsi_stats_dma
;
913 DEBUG2(printk(KERN_INFO
"Func: %s\n", __func__
));
915 cls_sess
= iscsi_conn_to_session(cls_conn
);
916 sess
= cls_sess
->dd_data
;
917 ddb_entry
= sess
->dd_data
;
920 stats_size
= PAGE_ALIGN(sizeof(struct ql_iscsi_stats
));
921 /* Allocate memory */
922 ql_iscsi_stats
= dma_alloc_coherent(&ha
->pdev
->dev
, stats_size
,
923 &iscsi_stats_dma
, GFP_KERNEL
);
924 if (!ql_iscsi_stats
) {
925 ql4_printk(KERN_ERR
, ha
,
926 "Unable to allocate memory for iscsi stats\n");
930 ret
= qla4xxx_get_mgmt_data(ha
, ddb_entry
->fw_ddb_index
, stats_size
,
932 if (ret
!= QLA_SUCCESS
) {
933 ql4_printk(KERN_ERR
, ha
,
934 "Unable to retrieve iscsi stats\n");
939 stats
->txdata_octets
= le64_to_cpu(ql_iscsi_stats
->tx_data_octets
);
940 stats
->rxdata_octets
= le64_to_cpu(ql_iscsi_stats
->rx_data_octets
);
942 stats
->noptx_pdus
= le32_to_cpu(ql_iscsi_stats
->tx_nopout_pdus
);
943 stats
->scsicmd_pdus
= le32_to_cpu(ql_iscsi_stats
->tx_scsi_cmd_pdus
);
944 stats
->tmfcmd_pdus
= le32_to_cpu(ql_iscsi_stats
->tx_tmf_cmd_pdus
);
945 stats
->login_pdus
= le32_to_cpu(ql_iscsi_stats
->tx_login_cmd_pdus
);
946 stats
->text_pdus
= le32_to_cpu(ql_iscsi_stats
->tx_text_cmd_pdus
);
947 stats
->dataout_pdus
= le32_to_cpu(ql_iscsi_stats
->tx_scsi_write_pdus
);
948 stats
->logout_pdus
= le32_to_cpu(ql_iscsi_stats
->tx_logout_cmd_pdus
);
949 stats
->snack_pdus
= le32_to_cpu(ql_iscsi_stats
->tx_snack_req_pdus
);
951 stats
->noprx_pdus
= le32_to_cpu(ql_iscsi_stats
->rx_nopin_pdus
);
952 stats
->scsirsp_pdus
= le32_to_cpu(ql_iscsi_stats
->rx_scsi_resp_pdus
);
953 stats
->tmfrsp_pdus
= le32_to_cpu(ql_iscsi_stats
->rx_tmf_resp_pdus
);
954 stats
->textrsp_pdus
= le32_to_cpu(ql_iscsi_stats
->rx_text_resp_pdus
);
955 stats
->datain_pdus
= le32_to_cpu(ql_iscsi_stats
->rx_scsi_read_pdus
);
956 stats
->logoutrsp_pdus
=
957 le32_to_cpu(ql_iscsi_stats
->rx_logout_resp_pdus
);
958 stats
->r2t_pdus
= le32_to_cpu(ql_iscsi_stats
->rx_r2t_pdus
);
959 stats
->async_pdus
= le32_to_cpu(ql_iscsi_stats
->rx_async_pdus
);
960 stats
->rjt_pdus
= le32_to_cpu(ql_iscsi_stats
->rx_reject_pdus
);
963 dma_free_coherent(&ha
->pdev
->dev
, stats_size
, ql_iscsi_stats
,
969 static enum blk_eh_timer_return
qla4xxx_eh_cmd_timed_out(struct scsi_cmnd
*sc
)
971 struct iscsi_cls_session
*session
;
972 struct iscsi_session
*sess
;
974 enum blk_eh_timer_return ret
= BLK_EH_NOT_HANDLED
;
976 session
= starget_to_session(scsi_target(sc
->device
));
977 sess
= session
->dd_data
;
979 spin_lock_irqsave(&session
->lock
, flags
);
980 if (session
->state
== ISCSI_SESSION_FAILED
)
981 ret
= BLK_EH_RESET_TIMER
;
982 spin_unlock_irqrestore(&session
->lock
, flags
);
987 static void qla4xxx_set_port_speed(struct Scsi_Host
*shost
)
989 struct scsi_qla_host
*ha
= to_qla_host(shost
);
990 struct iscsi_cls_host
*ihost
= shost
->shost_data
;
991 uint32_t speed
= ISCSI_PORT_SPEED_UNKNOWN
;
993 qla4xxx_get_firmware_state(ha
);
995 switch (ha
->addl_fw_state
& 0x0F00) {
996 case FW_ADDSTATE_LINK_SPEED_10MBPS
:
997 speed
= ISCSI_PORT_SPEED_10MBPS
;
999 case FW_ADDSTATE_LINK_SPEED_100MBPS
:
1000 speed
= ISCSI_PORT_SPEED_100MBPS
;
1002 case FW_ADDSTATE_LINK_SPEED_1GBPS
:
1003 speed
= ISCSI_PORT_SPEED_1GBPS
;
1005 case FW_ADDSTATE_LINK_SPEED_10GBPS
:
1006 speed
= ISCSI_PORT_SPEED_10GBPS
;
1009 ihost
->port_speed
= speed
;
1012 static void qla4xxx_set_port_state(struct Scsi_Host
*shost
)
1014 struct scsi_qla_host
*ha
= to_qla_host(shost
);
1015 struct iscsi_cls_host
*ihost
= shost
->shost_data
;
1016 uint32_t state
= ISCSI_PORT_STATE_DOWN
;
1018 if (test_bit(AF_LINK_UP
, &ha
->flags
))
1019 state
= ISCSI_PORT_STATE_UP
;
1021 ihost
->port_state
= state
;
1024 static int qla4xxx_host_get_param(struct Scsi_Host
*shost
,
1025 enum iscsi_host_param param
, char *buf
)
1027 struct scsi_qla_host
*ha
= to_qla_host(shost
);
1031 case ISCSI_HOST_PARAM_HWADDRESS
:
1032 len
= sysfs_format_mac(buf
, ha
->my_mac
, MAC_ADDR_LEN
);
1034 case ISCSI_HOST_PARAM_IPADDRESS
:
1035 len
= sprintf(buf
, "%pI4\n", &ha
->ip_config
.ip_address
);
1037 case ISCSI_HOST_PARAM_INITIATOR_NAME
:
1038 len
= sprintf(buf
, "%s\n", ha
->name_string
);
1040 case ISCSI_HOST_PARAM_PORT_STATE
:
1041 qla4xxx_set_port_state(shost
);
1042 len
= sprintf(buf
, "%s\n", iscsi_get_port_state_name(shost
));
1044 case ISCSI_HOST_PARAM_PORT_SPEED
:
1045 qla4xxx_set_port_speed(shost
);
1046 len
= sprintf(buf
, "%s\n", iscsi_get_port_speed_name(shost
));
1055 static void qla4xxx_create_ipv4_iface(struct scsi_qla_host
*ha
)
1061 ha
->iface_ipv4
= iscsi_create_iface(ha
->host
,
1062 &qla4xxx_iscsi_transport
,
1063 ISCSI_IFACE_TYPE_IPV4
, 0, 0);
1064 if (!ha
->iface_ipv4
)
1065 ql4_printk(KERN_ERR
, ha
, "Could not create IPv4 iSCSI "
1069 static void qla4xxx_create_ipv6_iface(struct scsi_qla_host
*ha
)
1071 if (!ha
->iface_ipv6_0
)
1073 ha
->iface_ipv6_0
= iscsi_create_iface(ha
->host
,
1074 &qla4xxx_iscsi_transport
,
1075 ISCSI_IFACE_TYPE_IPV6
, 0,
1077 if (!ha
->iface_ipv6_0
)
1078 ql4_printk(KERN_ERR
, ha
, "Could not create IPv6 iSCSI "
1081 if (!ha
->iface_ipv6_1
)
1083 ha
->iface_ipv6_1
= iscsi_create_iface(ha
->host
,
1084 &qla4xxx_iscsi_transport
,
1085 ISCSI_IFACE_TYPE_IPV6
, 1,
1087 if (!ha
->iface_ipv6_1
)
1088 ql4_printk(KERN_ERR
, ha
, "Could not create IPv6 iSCSI "
1092 static void qla4xxx_create_ifaces(struct scsi_qla_host
*ha
)
1094 if (ha
->ip_config
.ipv4_options
& IPOPT_IPV4_PROTOCOL_ENABLE
)
1095 qla4xxx_create_ipv4_iface(ha
);
1097 if (ha
->ip_config
.ipv6_options
& IPV6_OPT_IPV6_PROTOCOL_ENABLE
)
1098 qla4xxx_create_ipv6_iface(ha
);
1101 static void qla4xxx_destroy_ipv4_iface(struct scsi_qla_host
*ha
)
1103 if (ha
->iface_ipv4
) {
1104 iscsi_destroy_iface(ha
->iface_ipv4
);
1105 ha
->iface_ipv4
= NULL
;
1109 static void qla4xxx_destroy_ipv6_iface(struct scsi_qla_host
*ha
)
1111 if (ha
->iface_ipv6_0
) {
1112 iscsi_destroy_iface(ha
->iface_ipv6_0
);
1113 ha
->iface_ipv6_0
= NULL
;
1115 if (ha
->iface_ipv6_1
) {
1116 iscsi_destroy_iface(ha
->iface_ipv6_1
);
1117 ha
->iface_ipv6_1
= NULL
;
1121 static void qla4xxx_destroy_ifaces(struct scsi_qla_host
*ha
)
1123 qla4xxx_destroy_ipv4_iface(ha
);
1124 qla4xxx_destroy_ipv6_iface(ha
);
1127 static void qla4xxx_set_ipv6(struct scsi_qla_host
*ha
,
1128 struct iscsi_iface_param_info
*iface_param
,
1129 struct addr_ctrl_blk
*init_fw_cb
)
1132 * iface_num 0 is valid for IPv6 Addr, linklocal, router, autocfg.
1133 * iface_num 1 is valid only for IPv6 Addr.
1135 switch (iface_param
->param
) {
1136 case ISCSI_NET_PARAM_IPV6_ADDR
:
1137 if (iface_param
->iface_num
& 0x1)
1139 memcpy(init_fw_cb
->ipv6_addr1
, iface_param
->value
,
1140 sizeof(init_fw_cb
->ipv6_addr1
));
1143 memcpy(init_fw_cb
->ipv6_addr0
, iface_param
->value
,
1144 sizeof(init_fw_cb
->ipv6_addr0
));
1146 case ISCSI_NET_PARAM_IPV6_LINKLOCAL
:
1147 if (iface_param
->iface_num
& 0x1)
1149 memcpy(init_fw_cb
->ipv6_if_id
, &iface_param
->value
[8],
1150 sizeof(init_fw_cb
->ipv6_if_id
));
1152 case ISCSI_NET_PARAM_IPV6_ROUTER
:
1153 if (iface_param
->iface_num
& 0x1)
1155 memcpy(init_fw_cb
->ipv6_dflt_rtr_addr
, iface_param
->value
,
1156 sizeof(init_fw_cb
->ipv6_dflt_rtr_addr
));
1158 case ISCSI_NET_PARAM_IPV6_ADDR_AUTOCFG
:
1159 /* Autocfg applies to even interface */
1160 if (iface_param
->iface_num
& 0x1)
1163 if (iface_param
->value
[0] == ISCSI_IPV6_AUTOCFG_DISABLE
)
1164 init_fw_cb
->ipv6_addtl_opts
&=
1166 ~IPV6_ADDOPT_NEIGHBOR_DISCOVERY_ADDR_ENABLE
);
1167 else if (iface_param
->value
[0] == ISCSI_IPV6_AUTOCFG_ND_ENABLE
)
1168 init_fw_cb
->ipv6_addtl_opts
|=
1170 IPV6_ADDOPT_NEIGHBOR_DISCOVERY_ADDR_ENABLE
);
1172 ql4_printk(KERN_ERR
, ha
, "Invalid autocfg setting for "
1175 case ISCSI_NET_PARAM_IPV6_LINKLOCAL_AUTOCFG
:
1176 /* Autocfg applies to even interface */
1177 if (iface_param
->iface_num
& 0x1)
1180 if (iface_param
->value
[0] ==
1181 ISCSI_IPV6_LINKLOCAL_AUTOCFG_ENABLE
)
1182 init_fw_cb
->ipv6_addtl_opts
|= cpu_to_le16(
1183 IPV6_ADDOPT_AUTOCONFIG_LINK_LOCAL_ADDR
);
1184 else if (iface_param
->value
[0] ==
1185 ISCSI_IPV6_LINKLOCAL_AUTOCFG_DISABLE
)
1186 init_fw_cb
->ipv6_addtl_opts
&= cpu_to_le16(
1187 ~IPV6_ADDOPT_AUTOCONFIG_LINK_LOCAL_ADDR
);
1189 ql4_printk(KERN_ERR
, ha
, "Invalid autocfg setting for "
1190 "IPv6 linklocal addr\n");
1192 case ISCSI_NET_PARAM_IPV6_ROUTER_AUTOCFG
:
1193 /* Autocfg applies to even interface */
1194 if (iface_param
->iface_num
& 0x1)
1197 if (iface_param
->value
[0] == ISCSI_IPV6_ROUTER_AUTOCFG_ENABLE
)
1198 memset(init_fw_cb
->ipv6_dflt_rtr_addr
, 0,
1199 sizeof(init_fw_cb
->ipv6_dflt_rtr_addr
));
1201 case ISCSI_NET_PARAM_IFACE_ENABLE
:
1202 if (iface_param
->value
[0] == ISCSI_IFACE_ENABLE
) {
1203 init_fw_cb
->ipv6_opts
|=
1204 cpu_to_le16(IPV6_OPT_IPV6_PROTOCOL_ENABLE
);
1205 qla4xxx_create_ipv6_iface(ha
);
1207 init_fw_cb
->ipv6_opts
&=
1208 cpu_to_le16(~IPV6_OPT_IPV6_PROTOCOL_ENABLE
&
1210 qla4xxx_destroy_ipv6_iface(ha
);
1213 case ISCSI_NET_PARAM_VLAN_TAG
:
1214 if (iface_param
->len
!= sizeof(init_fw_cb
->ipv6_vlan_tag
))
1216 init_fw_cb
->ipv6_vlan_tag
=
1217 cpu_to_be16(*(uint16_t *)iface_param
->value
);
1219 case ISCSI_NET_PARAM_VLAN_ENABLED
:
1220 if (iface_param
->value
[0] == ISCSI_VLAN_ENABLE
)
1221 init_fw_cb
->ipv6_opts
|=
1222 cpu_to_le16(IPV6_OPT_VLAN_TAGGING_ENABLE
);
1224 init_fw_cb
->ipv6_opts
&=
1225 cpu_to_le16(~IPV6_OPT_VLAN_TAGGING_ENABLE
);
1227 case ISCSI_NET_PARAM_MTU
:
1228 init_fw_cb
->eth_mtu_size
=
1229 cpu_to_le16(*(uint16_t *)iface_param
->value
);
1231 case ISCSI_NET_PARAM_PORT
:
1232 /* Autocfg applies to even interface */
1233 if (iface_param
->iface_num
& 0x1)
1236 init_fw_cb
->ipv6_port
=
1237 cpu_to_le16(*(uint16_t *)iface_param
->value
);
1240 ql4_printk(KERN_ERR
, ha
, "Unknown IPv6 param = %d\n",
1241 iface_param
->param
);
1246 static void qla4xxx_set_ipv4(struct scsi_qla_host
*ha
,
1247 struct iscsi_iface_param_info
*iface_param
,
1248 struct addr_ctrl_blk
*init_fw_cb
)
1250 switch (iface_param
->param
) {
1251 case ISCSI_NET_PARAM_IPV4_ADDR
:
1252 memcpy(init_fw_cb
->ipv4_addr
, iface_param
->value
,
1253 sizeof(init_fw_cb
->ipv4_addr
));
1255 case ISCSI_NET_PARAM_IPV4_SUBNET
:
1256 memcpy(init_fw_cb
->ipv4_subnet
, iface_param
->value
,
1257 sizeof(init_fw_cb
->ipv4_subnet
));
1259 case ISCSI_NET_PARAM_IPV4_GW
:
1260 memcpy(init_fw_cb
->ipv4_gw_addr
, iface_param
->value
,
1261 sizeof(init_fw_cb
->ipv4_gw_addr
));
1263 case ISCSI_NET_PARAM_IPV4_BOOTPROTO
:
1264 if (iface_param
->value
[0] == ISCSI_BOOTPROTO_DHCP
)
1265 init_fw_cb
->ipv4_tcp_opts
|=
1266 cpu_to_le16(TCPOPT_DHCP_ENABLE
);
1267 else if (iface_param
->value
[0] == ISCSI_BOOTPROTO_STATIC
)
1268 init_fw_cb
->ipv4_tcp_opts
&=
1269 cpu_to_le16(~TCPOPT_DHCP_ENABLE
);
1271 ql4_printk(KERN_ERR
, ha
, "Invalid IPv4 bootproto\n");
1273 case ISCSI_NET_PARAM_IFACE_ENABLE
:
1274 if (iface_param
->value
[0] == ISCSI_IFACE_ENABLE
) {
1275 init_fw_cb
->ipv4_ip_opts
|=
1276 cpu_to_le16(IPOPT_IPV4_PROTOCOL_ENABLE
);
1277 qla4xxx_create_ipv4_iface(ha
);
1279 init_fw_cb
->ipv4_ip_opts
&=
1280 cpu_to_le16(~IPOPT_IPV4_PROTOCOL_ENABLE
&
1282 qla4xxx_destroy_ipv4_iface(ha
);
1285 case ISCSI_NET_PARAM_VLAN_TAG
:
1286 if (iface_param
->len
!= sizeof(init_fw_cb
->ipv4_vlan_tag
))
1288 init_fw_cb
->ipv4_vlan_tag
=
1289 cpu_to_be16(*(uint16_t *)iface_param
->value
);
1291 case ISCSI_NET_PARAM_VLAN_ENABLED
:
1292 if (iface_param
->value
[0] == ISCSI_VLAN_ENABLE
)
1293 init_fw_cb
->ipv4_ip_opts
|=
1294 cpu_to_le16(IPOPT_VLAN_TAGGING_ENABLE
);
1296 init_fw_cb
->ipv4_ip_opts
&=
1297 cpu_to_le16(~IPOPT_VLAN_TAGGING_ENABLE
);
1299 case ISCSI_NET_PARAM_MTU
:
1300 init_fw_cb
->eth_mtu_size
=
1301 cpu_to_le16(*(uint16_t *)iface_param
->value
);
1303 case ISCSI_NET_PARAM_PORT
:
1304 init_fw_cb
->ipv4_port
=
1305 cpu_to_le16(*(uint16_t *)iface_param
->value
);
1308 ql4_printk(KERN_ERR
, ha
, "Unknown IPv4 param = %d\n",
1309 iface_param
->param
);
1315 qla4xxx_initcb_to_acb(struct addr_ctrl_blk
*init_fw_cb
)
1317 struct addr_ctrl_blk_def
*acb
;
1318 acb
= (struct addr_ctrl_blk_def
*)init_fw_cb
;
1319 memset(acb
->reserved1
, 0, sizeof(acb
->reserved1
));
1320 memset(acb
->reserved2
, 0, sizeof(acb
->reserved2
));
1321 memset(acb
->reserved3
, 0, sizeof(acb
->reserved3
));
1322 memset(acb
->reserved4
, 0, sizeof(acb
->reserved4
));
1323 memset(acb
->reserved5
, 0, sizeof(acb
->reserved5
));
1324 memset(acb
->reserved6
, 0, sizeof(acb
->reserved6
));
1325 memset(acb
->reserved7
, 0, sizeof(acb
->reserved7
));
1326 memset(acb
->reserved8
, 0, sizeof(acb
->reserved8
));
1327 memset(acb
->reserved9
, 0, sizeof(acb
->reserved9
));
1328 memset(acb
->reserved10
, 0, sizeof(acb
->reserved10
));
1329 memset(acb
->reserved11
, 0, sizeof(acb
->reserved11
));
1330 memset(acb
->reserved12
, 0, sizeof(acb
->reserved12
));
1331 memset(acb
->reserved13
, 0, sizeof(acb
->reserved13
));
1332 memset(acb
->reserved14
, 0, sizeof(acb
->reserved14
));
1333 memset(acb
->reserved15
, 0, sizeof(acb
->reserved15
));
1337 qla4xxx_iface_set_param(struct Scsi_Host
*shost
, void *data
, uint32_t len
)
1339 struct scsi_qla_host
*ha
= to_qla_host(shost
);
1341 struct iscsi_iface_param_info
*iface_param
= NULL
;
1342 struct addr_ctrl_blk
*init_fw_cb
= NULL
;
1343 dma_addr_t init_fw_cb_dma
;
1344 uint32_t mbox_cmd
[MBOX_REG_COUNT
];
1345 uint32_t mbox_sts
[MBOX_REG_COUNT
];
1347 struct nlattr
*attr
;
1349 init_fw_cb
= dma_alloc_coherent(&ha
->pdev
->dev
,
1350 sizeof(struct addr_ctrl_blk
),
1351 &init_fw_cb_dma
, GFP_KERNEL
);
1353 ql4_printk(KERN_ERR
, ha
, "%s: Unable to alloc init_cb\n",
1358 memset(init_fw_cb
, 0, sizeof(struct addr_ctrl_blk
));
1359 memset(&mbox_cmd
, 0, sizeof(mbox_cmd
));
1360 memset(&mbox_sts
, 0, sizeof(mbox_sts
));
1362 if (qla4xxx_get_ifcb(ha
, &mbox_cmd
[0], &mbox_sts
[0], init_fw_cb_dma
)) {
1363 ql4_printk(KERN_ERR
, ha
, "%s: get ifcb failed\n", __func__
);
1365 goto exit_init_fw_cb
;
1368 nla_for_each_attr(attr
, data
, len
, rem
) {
1369 iface_param
= nla_data(attr
);
1371 if (iface_param
->param_type
!= ISCSI_NET_PARAM
)
1374 switch (iface_param
->iface_type
) {
1375 case ISCSI_IFACE_TYPE_IPV4
:
1376 switch (iface_param
->iface_num
) {
1378 qla4xxx_set_ipv4(ha
, iface_param
, init_fw_cb
);
1381 /* Cannot have more than one IPv4 interface */
1382 ql4_printk(KERN_ERR
, ha
, "Invalid IPv4 iface "
1384 iface_param
->iface_num
);
1388 case ISCSI_IFACE_TYPE_IPV6
:
1389 switch (iface_param
->iface_num
) {
1392 qla4xxx_set_ipv6(ha
, iface_param
, init_fw_cb
);
1395 /* Cannot have more than two IPv6 interface */
1396 ql4_printk(KERN_ERR
, ha
, "Invalid IPv6 iface "
1398 iface_param
->iface_num
);
1403 ql4_printk(KERN_ERR
, ha
, "Invalid iface type\n");
1408 init_fw_cb
->cookie
= cpu_to_le32(0x11BEAD5A);
1410 rval
= qla4xxx_set_flash(ha
, init_fw_cb_dma
, FLASH_SEGMENT_IFCB
,
1411 sizeof(struct addr_ctrl_blk
),
1412 FLASH_OPT_RMW_COMMIT
);
1413 if (rval
!= QLA_SUCCESS
) {
1414 ql4_printk(KERN_ERR
, ha
, "%s: set flash mbx failed\n",
1417 goto exit_init_fw_cb
;
1420 rval
= qla4xxx_disable_acb(ha
);
1421 if (rval
!= QLA_SUCCESS
) {
1422 ql4_printk(KERN_ERR
, ha
, "%s: disable acb mbx failed\n",
1425 goto exit_init_fw_cb
;
1428 wait_for_completion_timeout(&ha
->disable_acb_comp
,
1429 DISABLE_ACB_TOV
* HZ
);
1431 qla4xxx_initcb_to_acb(init_fw_cb
);
1433 rval
= qla4xxx_set_acb(ha
, &mbox_cmd
[0], &mbox_sts
[0], init_fw_cb_dma
);
1434 if (rval
!= QLA_SUCCESS
) {
1435 ql4_printk(KERN_ERR
, ha
, "%s: set acb mbx failed\n",
1438 goto exit_init_fw_cb
;
1441 memset(init_fw_cb
, 0, sizeof(struct addr_ctrl_blk
));
1442 qla4xxx_update_local_ifcb(ha
, &mbox_cmd
[0], &mbox_sts
[0], init_fw_cb
,
1446 dma_free_coherent(&ha
->pdev
->dev
, sizeof(struct addr_ctrl_blk
),
1447 init_fw_cb
, init_fw_cb_dma
);
1452 static int qla4xxx_session_get_param(struct iscsi_cls_session
*cls_sess
,
1453 enum iscsi_param param
, char *buf
)
1455 struct iscsi_session
*sess
= cls_sess
->dd_data
;
1456 struct ddb_entry
*ddb_entry
= sess
->dd_data
;
1457 struct scsi_qla_host
*ha
= ddb_entry
->ha
;
1462 case ISCSI_PARAM_CHAP_IN_IDX
:
1463 rval
= qla4xxx_get_chap_index(ha
, sess
->username_in
,
1464 sess
->password_in
, BIDI_CHAP
,
1467 len
= sprintf(buf
, "\n");
1469 len
= sprintf(buf
, "%hu\n", idx
);
1471 case ISCSI_PARAM_CHAP_OUT_IDX
:
1472 rval
= qla4xxx_get_chap_index(ha
, sess
->username
,
1473 sess
->password
, LOCAL_CHAP
,
1476 len
= sprintf(buf
, "\n");
1478 len
= sprintf(buf
, "%hu\n", idx
);
1481 return iscsi_session_get_param(cls_sess
, param
, buf
);
1487 static int qla4xxx_conn_get_param(struct iscsi_cls_conn
*cls_conn
,
1488 enum iscsi_param param
, char *buf
)
1490 struct iscsi_conn
*conn
;
1491 struct qla_conn
*qla_conn
;
1492 struct sockaddr
*dst_addr
;
1495 conn
= cls_conn
->dd_data
;
1496 qla_conn
= conn
->dd_data
;
1497 dst_addr
= (struct sockaddr
*)&qla_conn
->qla_ep
->dst_addr
;
1500 case ISCSI_PARAM_CONN_PORT
:
1501 case ISCSI_PARAM_CONN_ADDRESS
:
1502 return iscsi_conn_get_addr_param((struct sockaddr_storage
*)
1503 dst_addr
, param
, buf
);
1505 return iscsi_conn_get_param(cls_conn
, param
, buf
);
1512 int qla4xxx_get_ddb_index(struct scsi_qla_host
*ha
, uint16_t *ddb_index
)
1514 uint32_t mbx_sts
= 0;
1515 uint16_t tmp_ddb_index
;
1519 tmp_ddb_index
= find_first_zero_bit(ha
->ddb_idx_map
, MAX_DDB_ENTRIES
);
1521 if (tmp_ddb_index
>= MAX_DDB_ENTRIES
) {
1522 DEBUG2(ql4_printk(KERN_INFO
, ha
,
1523 "Free DDB index not available\n"));
1525 goto exit_get_ddb_index
;
1528 if (test_and_set_bit(tmp_ddb_index
, ha
->ddb_idx_map
))
1531 DEBUG2(ql4_printk(KERN_INFO
, ha
,
1532 "Found a free DDB index at %d\n", tmp_ddb_index
));
1533 ret
= qla4xxx_req_ddb_entry(ha
, tmp_ddb_index
, &mbx_sts
);
1534 if (ret
== QLA_ERROR
) {
1535 if (mbx_sts
== MBOX_STS_COMMAND_ERROR
) {
1536 ql4_printk(KERN_INFO
, ha
,
1537 "DDB index = %d not available trying next\n",
1541 DEBUG2(ql4_printk(KERN_INFO
, ha
,
1542 "Free FW DDB not available\n"));
1545 *ddb_index
= tmp_ddb_index
;
1551 static int qla4xxx_match_ipaddress(struct scsi_qla_host
*ha
,
1552 struct ddb_entry
*ddb_entry
,
1553 char *existing_ipaddr
,
1556 uint8_t dst_ipaddr
[IPv6_ADDR_LEN
];
1557 char formatted_ipaddr
[DDB_IPADDR_LEN
];
1558 int status
= QLA_SUCCESS
, ret
= 0;
1560 if (ddb_entry
->fw_ddb_entry
.options
& DDB_OPT_IPV6_DEVICE
) {
1561 ret
= in6_pton(user_ipaddr
, strlen(user_ipaddr
), dst_ipaddr
,
1567 ret
= sprintf(formatted_ipaddr
, "%pI6", dst_ipaddr
);
1569 ret
= in4_pton(user_ipaddr
, strlen(user_ipaddr
), dst_ipaddr
,
1575 ret
= sprintf(formatted_ipaddr
, "%pI4", dst_ipaddr
);
1578 if (strcmp(existing_ipaddr
, formatted_ipaddr
))
1585 static int qla4xxx_match_fwdb_session(struct scsi_qla_host
*ha
,
1586 struct iscsi_cls_conn
*cls_conn
)
1588 int idx
= 0, max_ddbs
, rval
;
1589 struct iscsi_cls_session
*cls_sess
= iscsi_conn_to_session(cls_conn
);
1590 struct iscsi_session
*sess
, *existing_sess
;
1591 struct iscsi_conn
*conn
, *existing_conn
;
1592 struct ddb_entry
*ddb_entry
;
1594 sess
= cls_sess
->dd_data
;
1595 conn
= cls_conn
->dd_data
;
1597 if (sess
->targetname
== NULL
||
1598 conn
->persistent_address
== NULL
||
1599 conn
->persistent_port
== 0)
1602 max_ddbs
= is_qla40XX(ha
) ? MAX_DEV_DB_ENTRIES_40XX
:
1605 for (idx
= 0; idx
< max_ddbs
; idx
++) {
1606 ddb_entry
= qla4xxx_lookup_ddb_by_fw_index(ha
, idx
);
1607 if (ddb_entry
== NULL
)
1610 if (ddb_entry
->ddb_type
!= FLASH_DDB
)
1613 existing_sess
= ddb_entry
->sess
->dd_data
;
1614 existing_conn
= ddb_entry
->conn
->dd_data
;
1616 if (existing_sess
->targetname
== NULL
||
1617 existing_conn
->persistent_address
== NULL
||
1618 existing_conn
->persistent_port
== 0)
1621 DEBUG2(ql4_printk(KERN_INFO
, ha
,
1622 "IQN = %s User IQN = %s\n",
1623 existing_sess
->targetname
,
1626 DEBUG2(ql4_printk(KERN_INFO
, ha
,
1627 "IP = %s User IP = %s\n",
1628 existing_conn
->persistent_address
,
1629 conn
->persistent_address
));
1631 DEBUG2(ql4_printk(KERN_INFO
, ha
,
1632 "Port = %d User Port = %d\n",
1633 existing_conn
->persistent_port
,
1634 conn
->persistent_port
));
1636 if (strcmp(existing_sess
->targetname
, sess
->targetname
))
1638 rval
= qla4xxx_match_ipaddress(ha
, ddb_entry
,
1639 existing_conn
->persistent_address
,
1640 conn
->persistent_address
);
1641 if (rval
== QLA_ERROR
)
1643 if (existing_conn
->persistent_port
!= conn
->persistent_port
)
1648 if (idx
== max_ddbs
)
1651 DEBUG2(ql4_printk(KERN_INFO
, ha
,
1652 "Match found in fwdb sessions\n"));
1656 static struct iscsi_cls_session
*
1657 qla4xxx_session_create(struct iscsi_endpoint
*ep
,
1658 uint16_t cmds_max
, uint16_t qdepth
,
1659 uint32_t initial_cmdsn
)
1661 struct iscsi_cls_session
*cls_sess
;
1662 struct scsi_qla_host
*ha
;
1663 struct qla_endpoint
*qla_ep
;
1664 struct ddb_entry
*ddb_entry
;
1666 struct iscsi_session
*sess
;
1667 struct sockaddr
*dst_addr
;
1670 DEBUG2(printk(KERN_INFO
"Func: %s\n", __func__
));
1672 printk(KERN_ERR
"qla4xxx: missing ep.\n");
1676 qla_ep
= ep
->dd_data
;
1677 dst_addr
= (struct sockaddr
*)&qla_ep
->dst_addr
;
1678 ha
= to_qla_host(qla_ep
->host
);
1680 ret
= qla4xxx_get_ddb_index(ha
, &ddb_index
);
1681 if (ret
== QLA_ERROR
)
1684 cls_sess
= iscsi_session_setup(&qla4xxx_iscsi_transport
, qla_ep
->host
,
1685 cmds_max
, sizeof(struct ddb_entry
),
1686 sizeof(struct ql4_task_data
),
1687 initial_cmdsn
, ddb_index
);
1691 sess
= cls_sess
->dd_data
;
1692 ddb_entry
= sess
->dd_data
;
1693 ddb_entry
->fw_ddb_index
= ddb_index
;
1694 ddb_entry
->fw_ddb_device_state
= DDB_DS_NO_CONNECTION_ACTIVE
;
1696 ddb_entry
->sess
= cls_sess
;
1697 ddb_entry
->unblock_sess
= qla4xxx_unblock_ddb
;
1698 ddb_entry
->ddb_change
= qla4xxx_ddb_change
;
1699 cls_sess
->recovery_tmo
= ql4xsess_recovery_tmo
;
1700 ha
->fw_ddb_index_map
[ddb_entry
->fw_ddb_index
] = ddb_entry
;
1706 static void qla4xxx_session_destroy(struct iscsi_cls_session
*cls_sess
)
1708 struct iscsi_session
*sess
;
1709 struct ddb_entry
*ddb_entry
;
1710 struct scsi_qla_host
*ha
;
1711 unsigned long flags
, wtime
;
1712 struct dev_db_entry
*fw_ddb_entry
= NULL
;
1713 dma_addr_t fw_ddb_entry_dma
;
1717 DEBUG2(printk(KERN_INFO
"Func: %s\n", __func__
));
1718 sess
= cls_sess
->dd_data
;
1719 ddb_entry
= sess
->dd_data
;
1722 fw_ddb_entry
= dma_alloc_coherent(&ha
->pdev
->dev
, sizeof(*fw_ddb_entry
),
1723 &fw_ddb_entry_dma
, GFP_KERNEL
);
1724 if (!fw_ddb_entry
) {
1725 ql4_printk(KERN_ERR
, ha
,
1726 "%s: Unable to allocate dma buffer\n", __func__
);
1727 goto destroy_session
;
1730 wtime
= jiffies
+ (HZ
* LOGOUT_TOV
);
1732 ret
= qla4xxx_get_fwddb_entry(ha
, ddb_entry
->fw_ddb_index
,
1733 fw_ddb_entry
, fw_ddb_entry_dma
,
1734 NULL
, NULL
, &ddb_state
, NULL
,
1736 if (ret
== QLA_ERROR
)
1737 goto destroy_session
;
1739 if ((ddb_state
== DDB_DS_NO_CONNECTION_ACTIVE
) ||
1740 (ddb_state
== DDB_DS_SESSION_FAILED
))
1741 goto destroy_session
;
1743 schedule_timeout_uninterruptible(HZ
);
1744 } while ((time_after(wtime
, jiffies
)));
1747 qla4xxx_clear_ddb_entry(ha
, ddb_entry
->fw_ddb_index
);
1749 spin_lock_irqsave(&ha
->hardware_lock
, flags
);
1750 qla4xxx_free_ddb(ha
, ddb_entry
);
1751 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
1753 iscsi_session_teardown(cls_sess
);
1756 dma_free_coherent(&ha
->pdev
->dev
, sizeof(*fw_ddb_entry
),
1757 fw_ddb_entry
, fw_ddb_entry_dma
);
1760 static struct iscsi_cls_conn
*
1761 qla4xxx_conn_create(struct iscsi_cls_session
*cls_sess
, uint32_t conn_idx
)
1763 struct iscsi_cls_conn
*cls_conn
;
1764 struct iscsi_session
*sess
;
1765 struct ddb_entry
*ddb_entry
;
1767 DEBUG2(printk(KERN_INFO
"Func: %s\n", __func__
));
1768 cls_conn
= iscsi_conn_setup(cls_sess
, sizeof(struct qla_conn
),
1773 sess
= cls_sess
->dd_data
;
1774 ddb_entry
= sess
->dd_data
;
1775 ddb_entry
->conn
= cls_conn
;
1780 static int qla4xxx_conn_bind(struct iscsi_cls_session
*cls_session
,
1781 struct iscsi_cls_conn
*cls_conn
,
1782 uint64_t transport_fd
, int is_leading
)
1784 struct iscsi_conn
*conn
;
1785 struct qla_conn
*qla_conn
;
1786 struct iscsi_endpoint
*ep
;
1788 DEBUG2(printk(KERN_INFO
"Func: %s\n", __func__
));
1790 if (iscsi_conn_bind(cls_session
, cls_conn
, is_leading
))
1792 ep
= iscsi_lookup_endpoint(transport_fd
);
1793 conn
= cls_conn
->dd_data
;
1794 qla_conn
= conn
->dd_data
;
1795 qla_conn
->qla_ep
= ep
->dd_data
;
1799 static int qla4xxx_conn_start(struct iscsi_cls_conn
*cls_conn
)
1801 struct iscsi_cls_session
*cls_sess
= iscsi_conn_to_session(cls_conn
);
1802 struct iscsi_session
*sess
;
1803 struct ddb_entry
*ddb_entry
;
1804 struct scsi_qla_host
*ha
;
1805 struct dev_db_entry
*fw_ddb_entry
= NULL
;
1806 dma_addr_t fw_ddb_entry_dma
;
1807 uint32_t mbx_sts
= 0;
1809 int status
= QLA_SUCCESS
;
1811 DEBUG2(printk(KERN_INFO
"Func: %s\n", __func__
));
1812 sess
= cls_sess
->dd_data
;
1813 ddb_entry
= sess
->dd_data
;
1816 /* Check if we have matching FW DDB, if yes then do not
1817 * login to this target. This could cause target to logout previous
1820 ret
= qla4xxx_match_fwdb_session(ha
, cls_conn
);
1821 if (ret
== QLA_SUCCESS
) {
1822 ql4_printk(KERN_INFO
, ha
,
1823 "Session already exist in FW.\n");
1825 goto exit_conn_start
;
1828 fw_ddb_entry
= dma_alloc_coherent(&ha
->pdev
->dev
, sizeof(*fw_ddb_entry
),
1829 &fw_ddb_entry_dma
, GFP_KERNEL
);
1830 if (!fw_ddb_entry
) {
1831 ql4_printk(KERN_ERR
, ha
,
1832 "%s: Unable to allocate dma buffer\n", __func__
);
1834 goto exit_conn_start
;
1837 ret
= qla4xxx_set_param_ddbentry(ha
, ddb_entry
, cls_conn
, &mbx_sts
);
1839 /* If iscsid is stopped and started then no need to do
1840 * set param again since ddb state will be already
1841 * active and FW does not allow set ddb to an
1845 if (ddb_entry
->fw_ddb_device_state
==
1846 DDB_DS_SESSION_ACTIVE
) {
1847 ddb_entry
->unblock_sess(ddb_entry
->sess
);
1848 goto exit_set_param
;
1851 ql4_printk(KERN_ERR
, ha
, "%s: Failed set param for index[%d]\n",
1852 __func__
, ddb_entry
->fw_ddb_index
);
1853 goto exit_conn_start
;
1856 status
= qla4xxx_conn_open(ha
, ddb_entry
->fw_ddb_index
);
1857 if (status
== QLA_ERROR
) {
1858 ql4_printk(KERN_ERR
, ha
, "%s: Login failed: %s\n", __func__
,
1861 goto exit_conn_start
;
1864 if (ddb_entry
->fw_ddb_device_state
== DDB_DS_NO_CONNECTION_ACTIVE
)
1865 ddb_entry
->fw_ddb_device_state
= DDB_DS_LOGIN_IN_PROCESS
;
1867 DEBUG2(printk(KERN_INFO
"%s: DDB state [%d]\n", __func__
,
1868 ddb_entry
->fw_ddb_device_state
));
1875 dma_free_coherent(&ha
->pdev
->dev
, sizeof(*fw_ddb_entry
),
1876 fw_ddb_entry
, fw_ddb_entry_dma
);
1880 static void qla4xxx_conn_destroy(struct iscsi_cls_conn
*cls_conn
)
1882 struct iscsi_cls_session
*cls_sess
= iscsi_conn_to_session(cls_conn
);
1883 struct iscsi_session
*sess
;
1884 struct scsi_qla_host
*ha
;
1885 struct ddb_entry
*ddb_entry
;
1888 DEBUG2(printk(KERN_INFO
"Func: %s\n", __func__
));
1889 sess
= cls_sess
->dd_data
;
1890 ddb_entry
= sess
->dd_data
;
1893 options
= LOGOUT_OPTION_CLOSE_SESSION
;
1894 if (qla4xxx_session_logout_ddb(ha
, ddb_entry
, options
) == QLA_ERROR
)
1895 ql4_printk(KERN_ERR
, ha
, "%s: Logout failed\n", __func__
);
1898 static void qla4xxx_task_work(struct work_struct
*wdata
)
1900 struct ql4_task_data
*task_data
;
1901 struct scsi_qla_host
*ha
;
1902 struct passthru_status
*sts
;
1903 struct iscsi_task
*task
;
1904 struct iscsi_hdr
*hdr
;
1907 struct iscsi_conn
*conn
;
1911 task_data
= container_of(wdata
, struct ql4_task_data
, task_work
);
1913 task
= task_data
->task
;
1914 sts
= &task_data
->sts
;
1915 hdr_len
= sizeof(struct iscsi_hdr
);
1917 DEBUG3(printk(KERN_INFO
"Status returned\n"));
1918 DEBUG3(qla4xxx_dump_buffer(sts
, 64));
1919 DEBUG3(printk(KERN_INFO
"Response buffer"));
1920 DEBUG3(qla4xxx_dump_buffer(task_data
->resp_buffer
, 64));
1924 switch (sts
->completionStatus
) {
1925 case PASSTHRU_STATUS_COMPLETE
:
1926 hdr
= (struct iscsi_hdr
*)task_data
->resp_buffer
;
1927 /* Assign back the itt in hdr, until we use the PREASSIGN_TAG */
1930 data
= task_data
->resp_buffer
+ hdr_len
;
1931 data_len
= task_data
->resp_len
- hdr_len
;
1932 iscsi_complete_pdu(conn
, hdr
, data
, data_len
);
1935 ql4_printk(KERN_ERR
, ha
, "Passthru failed status = 0x%x\n",
1936 sts
->completionStatus
);
1942 static int qla4xxx_alloc_pdu(struct iscsi_task
*task
, uint8_t opcode
)
1944 struct ql4_task_data
*task_data
;
1945 struct iscsi_session
*sess
;
1946 struct ddb_entry
*ddb_entry
;
1947 struct scsi_qla_host
*ha
;
1950 sess
= task
->conn
->session
;
1951 ddb_entry
= sess
->dd_data
;
1953 task_data
= task
->dd_data
;
1954 memset(task_data
, 0, sizeof(struct ql4_task_data
));
1957 ql4_printk(KERN_INFO
, ha
,
1958 "%s: SCSI Commands not implemented\n", __func__
);
1962 hdr_len
= sizeof(struct iscsi_hdr
);
1964 task_data
->task
= task
;
1966 if (task
->data_count
) {
1967 task_data
->data_dma
= dma_map_single(&ha
->pdev
->dev
, task
->data
,
1972 DEBUG2(ql4_printk(KERN_INFO
, ha
, "%s: MaxRecvLen %u, iscsi hrd %d\n",
1973 __func__
, task
->conn
->max_recv_dlength
, hdr_len
));
1975 task_data
->resp_len
= task
->conn
->max_recv_dlength
+ hdr_len
;
1976 task_data
->resp_buffer
= dma_alloc_coherent(&ha
->pdev
->dev
,
1977 task_data
->resp_len
,
1978 &task_data
->resp_dma
,
1980 if (!task_data
->resp_buffer
)
1981 goto exit_alloc_pdu
;
1983 task_data
->req_len
= task
->data_count
+ hdr_len
;
1984 task_data
->req_buffer
= dma_alloc_coherent(&ha
->pdev
->dev
,
1986 &task_data
->req_dma
,
1988 if (!task_data
->req_buffer
)
1989 goto exit_alloc_pdu
;
1991 task
->hdr
= task_data
->req_buffer
;
1993 INIT_WORK(&task_data
->task_work
, qla4xxx_task_work
);
1998 if (task_data
->resp_buffer
)
1999 dma_free_coherent(&ha
->pdev
->dev
, task_data
->resp_len
,
2000 task_data
->resp_buffer
, task_data
->resp_dma
);
2002 if (task_data
->req_buffer
)
2003 dma_free_coherent(&ha
->pdev
->dev
, task_data
->req_len
,
2004 task_data
->req_buffer
, task_data
->req_dma
);
2008 static void qla4xxx_task_cleanup(struct iscsi_task
*task
)
2010 struct ql4_task_data
*task_data
;
2011 struct iscsi_session
*sess
;
2012 struct ddb_entry
*ddb_entry
;
2013 struct scsi_qla_host
*ha
;
2016 hdr_len
= sizeof(struct iscsi_hdr
);
2017 sess
= task
->conn
->session
;
2018 ddb_entry
= sess
->dd_data
;
2020 task_data
= task
->dd_data
;
2022 if (task
->data_count
) {
2023 dma_unmap_single(&ha
->pdev
->dev
, task_data
->data_dma
,
2024 task
->data_count
, PCI_DMA_TODEVICE
);
2027 DEBUG2(ql4_printk(KERN_INFO
, ha
, "%s: MaxRecvLen %u, iscsi hrd %d\n",
2028 __func__
, task
->conn
->max_recv_dlength
, hdr_len
));
2030 dma_free_coherent(&ha
->pdev
->dev
, task_data
->resp_len
,
2031 task_data
->resp_buffer
, task_data
->resp_dma
);
2032 dma_free_coherent(&ha
->pdev
->dev
, task_data
->req_len
,
2033 task_data
->req_buffer
, task_data
->req_dma
);
2037 static int qla4xxx_task_xmit(struct iscsi_task
*task
)
2039 struct scsi_cmnd
*sc
= task
->sc
;
2040 struct iscsi_session
*sess
= task
->conn
->session
;
2041 struct ddb_entry
*ddb_entry
= sess
->dd_data
;
2042 struct scsi_qla_host
*ha
= ddb_entry
->ha
;
2045 return qla4xxx_send_passthru0(task
);
2047 ql4_printk(KERN_INFO
, ha
, "%s: scsi cmd xmit not implemented\n",
2052 static int qla4xxx_copy_from_fwddb_param(struct iscsi_bus_flash_session
*sess
,
2053 struct iscsi_bus_flash_conn
*conn
,
2054 struct dev_db_entry
*fw_ddb_entry
)
2056 unsigned long options
= 0;
2059 options
= le16_to_cpu(fw_ddb_entry
->options
);
2060 conn
->is_fw_assigned_ipv6
= test_bit(OPT_IS_FW_ASSIGNED_IPV6
, &options
);
2061 if (test_bit(OPT_IPV6_DEVICE
, &options
)) {
2062 rc
= iscsi_switch_str_param(&sess
->portal_type
,
2067 rc
= iscsi_switch_str_param(&sess
->portal_type
,
2073 sess
->auto_snd_tgt_disable
= test_bit(OPT_AUTO_SENDTGTS_DISABLE
,
2075 sess
->discovery_sess
= test_bit(OPT_DISC_SESSION
, &options
);
2076 sess
->entry_state
= test_bit(OPT_ENTRY_STATE
, &options
);
2078 options
= le16_to_cpu(fw_ddb_entry
->iscsi_options
);
2079 conn
->hdrdgst_en
= test_bit(ISCSIOPT_HEADER_DIGEST_EN
, &options
);
2080 conn
->datadgst_en
= test_bit(ISCSIOPT_DATA_DIGEST_EN
, &options
);
2081 sess
->imm_data_en
= test_bit(ISCSIOPT_IMMEDIATE_DATA_EN
, &options
);
2082 sess
->initial_r2t_en
= test_bit(ISCSIOPT_INITIAL_R2T_EN
, &options
);
2083 sess
->dataseq_inorder_en
= test_bit(ISCSIOPT_DATA_SEQ_IN_ORDER
,
2085 sess
->pdu_inorder_en
= test_bit(ISCSIOPT_DATA_PDU_IN_ORDER
, &options
);
2086 sess
->chap_auth_en
= test_bit(ISCSIOPT_CHAP_AUTH_EN
, &options
);
2087 conn
->snack_req_en
= test_bit(ISCSIOPT_SNACK_REQ_EN
, &options
);
2088 sess
->discovery_logout_en
= test_bit(ISCSIOPT_DISCOVERY_LOGOUT_EN
,
2090 sess
->bidi_chap_en
= test_bit(ISCSIOPT_BIDI_CHAP_EN
, &options
);
2091 sess
->discovery_auth_optional
=
2092 test_bit(ISCSIOPT_DISCOVERY_AUTH_OPTIONAL
, &options
);
2093 if (test_bit(ISCSIOPT_ERL1
, &options
))
2095 if (test_bit(ISCSIOPT_ERL0
, &options
))
2098 options
= le16_to_cpu(fw_ddb_entry
->tcp_options
);
2099 conn
->tcp_timestamp_stat
= test_bit(TCPOPT_TIMESTAMP_STAT
, &options
);
2100 conn
->tcp_nagle_disable
= test_bit(TCPOPT_NAGLE_DISABLE
, &options
);
2101 conn
->tcp_wsf_disable
= test_bit(TCPOPT_WSF_DISABLE
, &options
);
2102 if (test_bit(TCPOPT_TIMER_SCALE3
, &options
))
2103 conn
->tcp_timer_scale
|= BIT_3
;
2104 if (test_bit(TCPOPT_TIMER_SCALE2
, &options
))
2105 conn
->tcp_timer_scale
|= BIT_2
;
2106 if (test_bit(TCPOPT_TIMER_SCALE1
, &options
))
2107 conn
->tcp_timer_scale
|= BIT_1
;
2109 conn
->tcp_timer_scale
>>= 1;
2110 conn
->tcp_timestamp_en
= test_bit(TCPOPT_TIMESTAMP_EN
, &options
);
2112 options
= le16_to_cpu(fw_ddb_entry
->ip_options
);
2113 conn
->fragment_disable
= test_bit(IPOPT_FRAGMENT_DISABLE
, &options
);
2115 conn
->max_recv_dlength
= BYTE_UNITS
*
2116 le16_to_cpu(fw_ddb_entry
->iscsi_max_rcv_data_seg_len
);
2117 conn
->max_xmit_dlength
= BYTE_UNITS
*
2118 le16_to_cpu(fw_ddb_entry
->iscsi_max_snd_data_seg_len
);
2119 sess
->first_burst
= BYTE_UNITS
*
2120 le16_to_cpu(fw_ddb_entry
->iscsi_first_burst_len
);
2121 sess
->max_burst
= BYTE_UNITS
*
2122 le16_to_cpu(fw_ddb_entry
->iscsi_max_burst_len
);
2123 sess
->max_r2t
= le16_to_cpu(fw_ddb_entry
->iscsi_max_outsnd_r2t
);
2124 sess
->time2wait
= le16_to_cpu(fw_ddb_entry
->iscsi_def_time2wait
);
2125 sess
->time2retain
= le16_to_cpu(fw_ddb_entry
->iscsi_def_time2retain
);
2126 sess
->tpgt
= le32_to_cpu(fw_ddb_entry
->tgt_portal_grp
);
2127 conn
->max_segment_size
= le16_to_cpu(fw_ddb_entry
->mss
);
2128 conn
->tcp_xmit_wsf
= fw_ddb_entry
->tcp_xmt_wsf
;
2129 conn
->tcp_recv_wsf
= fw_ddb_entry
->tcp_rcv_wsf
;
2130 conn
->ipv6_flow_label
= le16_to_cpu(fw_ddb_entry
->ipv6_flow_lbl
);
2131 conn
->keepalive_timeout
= le16_to_cpu(fw_ddb_entry
->ka_timeout
);
2132 conn
->local_port
= le16_to_cpu(fw_ddb_entry
->lcl_port
);
2133 conn
->statsn
= le32_to_cpu(fw_ddb_entry
->stat_sn
);
2134 conn
->exp_statsn
= le32_to_cpu(fw_ddb_entry
->exp_stat_sn
);
2135 sess
->discovery_parent_idx
= le16_to_cpu(fw_ddb_entry
->ddb_link
);
2136 sess
->discovery_parent_type
= le16_to_cpu(fw_ddb_entry
->ddb_link
);
2137 sess
->chap_out_idx
= le16_to_cpu(fw_ddb_entry
->chap_tbl_idx
);
2138 sess
->tsid
= le16_to_cpu(fw_ddb_entry
->tsid
);
2140 sess
->default_taskmgmt_timeout
=
2141 le16_to_cpu(fw_ddb_entry
->def_timeout
);
2142 conn
->port
= le16_to_cpu(fw_ddb_entry
->port
);
2144 options
= le16_to_cpu(fw_ddb_entry
->options
);
2145 conn
->ipaddress
= kzalloc(IPv6_ADDR_LEN
, GFP_KERNEL
);
2146 if (!conn
->ipaddress
) {
2151 conn
->redirect_ipaddr
= kzalloc(IPv6_ADDR_LEN
, GFP_KERNEL
);
2152 if (!conn
->redirect_ipaddr
) {
2157 memcpy(conn
->ipaddress
, fw_ddb_entry
->ip_addr
, IPv6_ADDR_LEN
);
2158 memcpy(conn
->redirect_ipaddr
, fw_ddb_entry
->tgt_addr
, IPv6_ADDR_LEN
);
2160 if (test_bit(OPT_IPV6_DEVICE
, &options
)) {
2161 conn
->ipv6_traffic_class
= fw_ddb_entry
->ipv4_tos
;
2163 conn
->link_local_ipv6_addr
= kzalloc(IPv6_ADDR_LEN
, GFP_KERNEL
);
2164 if (!conn
->link_local_ipv6_addr
) {
2169 memcpy(conn
->link_local_ipv6_addr
,
2170 fw_ddb_entry
->link_local_ipv6_addr
, IPv6_ADDR_LEN
);
2172 conn
->ipv4_tos
= fw_ddb_entry
->ipv4_tos
;
2175 if (fw_ddb_entry
->iscsi_name
[0]) {
2176 rc
= iscsi_switch_str_param(&sess
->targetname
,
2177 (char *)fw_ddb_entry
->iscsi_name
);
2182 if (fw_ddb_entry
->iscsi_alias
[0]) {
2183 rc
= iscsi_switch_str_param(&sess
->targetalias
,
2184 (char *)fw_ddb_entry
->iscsi_alias
);
2189 COPY_ISID(sess
->isid
, fw_ddb_entry
->isid
);
2195 static int qla4xxx_copy_to_fwddb_param(struct iscsi_bus_flash_session
*sess
,
2196 struct iscsi_bus_flash_conn
*conn
,
2197 struct dev_db_entry
*fw_ddb_entry
)
2202 options
= le16_to_cpu(fw_ddb_entry
->options
);
2203 SET_BITVAL(conn
->is_fw_assigned_ipv6
, options
, BIT_11
);
2204 if (!strncmp(sess
->portal_type
, PORTAL_TYPE_IPV6
, 4))
2209 SET_BITVAL(sess
->auto_snd_tgt_disable
, options
, BIT_6
);
2210 SET_BITVAL(sess
->discovery_sess
, options
, BIT_4
);
2211 SET_BITVAL(sess
->entry_state
, options
, BIT_3
);
2212 fw_ddb_entry
->options
= cpu_to_le16(options
);
2214 options
= le16_to_cpu(fw_ddb_entry
->iscsi_options
);
2215 SET_BITVAL(conn
->hdrdgst_en
, options
, BIT_13
);
2216 SET_BITVAL(conn
->datadgst_en
, options
, BIT_12
);
2217 SET_BITVAL(sess
->imm_data_en
, options
, BIT_11
);
2218 SET_BITVAL(sess
->initial_r2t_en
, options
, BIT_10
);
2219 SET_BITVAL(sess
->dataseq_inorder_en
, options
, BIT_9
);
2220 SET_BITVAL(sess
->pdu_inorder_en
, options
, BIT_8
);
2221 SET_BITVAL(sess
->chap_auth_en
, options
, BIT_7
);
2222 SET_BITVAL(conn
->snack_req_en
, options
, BIT_6
);
2223 SET_BITVAL(sess
->discovery_logout_en
, options
, BIT_5
);
2224 SET_BITVAL(sess
->bidi_chap_en
, options
, BIT_4
);
2225 SET_BITVAL(sess
->discovery_auth_optional
, options
, BIT_3
);
2226 SET_BITVAL(sess
->erl
& BIT_1
, options
, BIT_1
);
2227 SET_BITVAL(sess
->erl
& BIT_0
, options
, BIT_0
);
2228 fw_ddb_entry
->iscsi_options
= cpu_to_le16(options
);
2230 options
= le16_to_cpu(fw_ddb_entry
->tcp_options
);
2231 SET_BITVAL(conn
->tcp_timestamp_stat
, options
, BIT_6
);
2232 SET_BITVAL(conn
->tcp_nagle_disable
, options
, BIT_5
);
2233 SET_BITVAL(conn
->tcp_wsf_disable
, options
, BIT_4
);
2234 SET_BITVAL(conn
->tcp_timer_scale
& BIT_2
, options
, BIT_3
);
2235 SET_BITVAL(conn
->tcp_timer_scale
& BIT_1
, options
, BIT_2
);
2236 SET_BITVAL(conn
->tcp_timer_scale
& BIT_0
, options
, BIT_1
);
2237 SET_BITVAL(conn
->tcp_timestamp_en
, options
, BIT_0
);
2238 fw_ddb_entry
->tcp_options
= cpu_to_le16(options
);
2240 options
= le16_to_cpu(fw_ddb_entry
->ip_options
);
2241 SET_BITVAL(conn
->fragment_disable
, options
, BIT_4
);
2242 fw_ddb_entry
->ip_options
= cpu_to_le16(options
);
2244 fw_ddb_entry
->iscsi_max_outsnd_r2t
= cpu_to_le16(sess
->max_r2t
);
2245 fw_ddb_entry
->iscsi_max_rcv_data_seg_len
=
2246 cpu_to_le16(conn
->max_recv_dlength
/ BYTE_UNITS
);
2247 fw_ddb_entry
->iscsi_max_snd_data_seg_len
=
2248 cpu_to_le16(conn
->max_xmit_dlength
/ BYTE_UNITS
);
2249 fw_ddb_entry
->iscsi_first_burst_len
=
2250 cpu_to_le16(sess
->first_burst
/ BYTE_UNITS
);
2251 fw_ddb_entry
->iscsi_max_burst_len
= cpu_to_le16(sess
->max_burst
/
2253 fw_ddb_entry
->iscsi_def_time2wait
= cpu_to_le16(sess
->time2wait
);
2254 fw_ddb_entry
->iscsi_def_time2retain
= cpu_to_le16(sess
->time2retain
);
2255 fw_ddb_entry
->tgt_portal_grp
= cpu_to_le16(sess
->tpgt
);
2256 fw_ddb_entry
->mss
= cpu_to_le16(conn
->max_segment_size
);
2257 fw_ddb_entry
->tcp_xmt_wsf
= (uint8_t) cpu_to_le32(conn
->tcp_xmit_wsf
);
2258 fw_ddb_entry
->tcp_rcv_wsf
= (uint8_t) cpu_to_le32(conn
->tcp_recv_wsf
);
2259 fw_ddb_entry
->ipv6_flow_lbl
= cpu_to_le16(conn
->ipv6_flow_label
);
2260 fw_ddb_entry
->ka_timeout
= cpu_to_le16(conn
->keepalive_timeout
);
2261 fw_ddb_entry
->lcl_port
= cpu_to_le16(conn
->local_port
);
2262 fw_ddb_entry
->stat_sn
= cpu_to_le32(conn
->statsn
);
2263 fw_ddb_entry
->exp_stat_sn
= cpu_to_le32(conn
->exp_statsn
);
2264 fw_ddb_entry
->ddb_link
= cpu_to_le16(sess
->discovery_parent_idx
);
2265 fw_ddb_entry
->chap_tbl_idx
= cpu_to_le16(sess
->chap_out_idx
);
2266 fw_ddb_entry
->tsid
= cpu_to_le16(sess
->tsid
);
2267 fw_ddb_entry
->port
= cpu_to_le16(conn
->port
);
2268 fw_ddb_entry
->def_timeout
=
2269 cpu_to_le16(sess
->default_taskmgmt_timeout
);
2271 if (!strncmp(sess
->portal_type
, PORTAL_TYPE_IPV6
, 4))
2272 fw_ddb_entry
->ipv4_tos
= conn
->ipv6_traffic_class
;
2274 fw_ddb_entry
->ipv4_tos
= conn
->ipv4_tos
;
2276 if (conn
->ipaddress
)
2277 memcpy(fw_ddb_entry
->ip_addr
, conn
->ipaddress
,
2278 sizeof(fw_ddb_entry
->ip_addr
));
2280 if (conn
->redirect_ipaddr
)
2281 memcpy(fw_ddb_entry
->tgt_addr
, conn
->redirect_ipaddr
,
2282 sizeof(fw_ddb_entry
->tgt_addr
));
2284 if (conn
->link_local_ipv6_addr
)
2285 memcpy(fw_ddb_entry
->link_local_ipv6_addr
,
2286 conn
->link_local_ipv6_addr
,
2287 sizeof(fw_ddb_entry
->link_local_ipv6_addr
));
2289 if (sess
->targetname
)
2290 memcpy(fw_ddb_entry
->iscsi_name
, sess
->targetname
,
2291 sizeof(fw_ddb_entry
->iscsi_name
));
2293 if (sess
->targetalias
)
2294 memcpy(fw_ddb_entry
->iscsi_alias
, sess
->targetalias
,
2295 sizeof(fw_ddb_entry
->iscsi_alias
));
2297 COPY_ISID(fw_ddb_entry
->isid
, sess
->isid
);
2302 static void qla4xxx_copy_to_sess_conn_params(struct iscsi_conn
*conn
,
2303 struct iscsi_session
*sess
,
2304 struct dev_db_entry
*fw_ddb_entry
)
2306 unsigned long options
= 0;
2308 uint16_t disc_parent
;
2310 options
= le16_to_cpu(fw_ddb_entry
->options
);
2311 conn
->is_fw_assigned_ipv6
= test_bit(OPT_IS_FW_ASSIGNED_IPV6
, &options
);
2312 sess
->auto_snd_tgt_disable
= test_bit(OPT_AUTO_SENDTGTS_DISABLE
,
2314 sess
->discovery_sess
= test_bit(OPT_DISC_SESSION
, &options
);
2316 options
= le16_to_cpu(fw_ddb_entry
->iscsi_options
);
2317 conn
->hdrdgst_en
= test_bit(ISCSIOPT_HEADER_DIGEST_EN
, &options
);
2318 conn
->datadgst_en
= test_bit(ISCSIOPT_DATA_DIGEST_EN
, &options
);
2319 sess
->imm_data_en
= test_bit(ISCSIOPT_IMMEDIATE_DATA_EN
, &options
);
2320 sess
->initial_r2t_en
= test_bit(ISCSIOPT_INITIAL_R2T_EN
, &options
);
2321 sess
->dataseq_inorder_en
= test_bit(ISCSIOPT_DATA_SEQ_IN_ORDER
,
2323 sess
->pdu_inorder_en
= test_bit(ISCSIOPT_DATA_PDU_IN_ORDER
, &options
);
2324 sess
->chap_auth_en
= test_bit(ISCSIOPT_CHAP_AUTH_EN
, &options
);
2325 sess
->discovery_logout_en
= test_bit(ISCSIOPT_DISCOVERY_LOGOUT_EN
,
2327 sess
->bidi_chap_en
= test_bit(ISCSIOPT_BIDI_CHAP_EN
, &options
);
2328 sess
->discovery_auth_optional
=
2329 test_bit(ISCSIOPT_DISCOVERY_AUTH_OPTIONAL
, &options
);
2330 if (test_bit(ISCSIOPT_ERL1
, &options
))
2332 if (test_bit(ISCSIOPT_ERL0
, &options
))
2335 options
= le16_to_cpu(fw_ddb_entry
->tcp_options
);
2336 conn
->tcp_timestamp_stat
= test_bit(TCPOPT_TIMESTAMP_STAT
, &options
);
2337 conn
->tcp_nagle_disable
= test_bit(TCPOPT_NAGLE_DISABLE
, &options
);
2338 conn
->tcp_wsf_disable
= test_bit(TCPOPT_WSF_DISABLE
, &options
);
2339 if (test_bit(TCPOPT_TIMER_SCALE3
, &options
))
2340 conn
->tcp_timer_scale
|= BIT_3
;
2341 if (test_bit(TCPOPT_TIMER_SCALE2
, &options
))
2342 conn
->tcp_timer_scale
|= BIT_2
;
2343 if (test_bit(TCPOPT_TIMER_SCALE1
, &options
))
2344 conn
->tcp_timer_scale
|= BIT_1
;
2346 conn
->tcp_timer_scale
>>= 1;
2347 conn
->tcp_timestamp_en
= test_bit(TCPOPT_TIMESTAMP_EN
, &options
);
2349 options
= le16_to_cpu(fw_ddb_entry
->ip_options
);
2350 conn
->fragment_disable
= test_bit(IPOPT_FRAGMENT_DISABLE
, &options
);
2352 conn
->max_recv_dlength
= BYTE_UNITS
*
2353 le16_to_cpu(fw_ddb_entry
->iscsi_max_rcv_data_seg_len
);
2354 conn
->max_xmit_dlength
= BYTE_UNITS
*
2355 le16_to_cpu(fw_ddb_entry
->iscsi_max_snd_data_seg_len
);
2356 sess
->max_r2t
= le16_to_cpu(fw_ddb_entry
->iscsi_max_outsnd_r2t
);
2357 sess
->first_burst
= BYTE_UNITS
*
2358 le16_to_cpu(fw_ddb_entry
->iscsi_first_burst_len
);
2359 sess
->max_burst
= BYTE_UNITS
*
2360 le16_to_cpu(fw_ddb_entry
->iscsi_max_burst_len
);
2361 sess
->time2wait
= le16_to_cpu(fw_ddb_entry
->iscsi_def_time2wait
);
2362 sess
->time2retain
= le16_to_cpu(fw_ddb_entry
->iscsi_def_time2retain
);
2363 sess
->tpgt
= le32_to_cpu(fw_ddb_entry
->tgt_portal_grp
);
2364 conn
->max_segment_size
= le16_to_cpu(fw_ddb_entry
->mss
);
2365 conn
->tcp_xmit_wsf
= fw_ddb_entry
->tcp_xmt_wsf
;
2366 conn
->tcp_recv_wsf
= fw_ddb_entry
->tcp_rcv_wsf
;
2367 conn
->ipv4_tos
= fw_ddb_entry
->ipv4_tos
;
2368 conn
->keepalive_tmo
= le16_to_cpu(fw_ddb_entry
->ka_timeout
);
2369 conn
->local_port
= le16_to_cpu(fw_ddb_entry
->lcl_port
);
2370 conn
->statsn
= le32_to_cpu(fw_ddb_entry
->stat_sn
);
2371 conn
->exp_statsn
= le32_to_cpu(fw_ddb_entry
->exp_stat_sn
);
2372 sess
->tsid
= le16_to_cpu(fw_ddb_entry
->tsid
);
2373 COPY_ISID(sess
->isid
, fw_ddb_entry
->isid
);
2375 ddb_link
= le16_to_cpu(fw_ddb_entry
->ddb_link
);
2376 if (ddb_link
< MAX_DDB_ENTRIES
)
2377 sess
->discovery_parent_idx
= ddb_link
;
2379 sess
->discovery_parent_idx
= DDB_NO_LINK
;
2381 if (ddb_link
== DDB_ISNS
)
2382 disc_parent
= ISCSI_DISC_PARENT_ISNS
;
2383 else if (ddb_link
== DDB_NO_LINK
)
2384 disc_parent
= ISCSI_DISC_PARENT_UNKNOWN
;
2385 else if (ddb_link
< MAX_DDB_ENTRIES
)
2386 disc_parent
= ISCSI_DISC_PARENT_SENDTGT
;
2388 disc_parent
= ISCSI_DISC_PARENT_UNKNOWN
;
2390 iscsi_set_param(conn
->cls_conn
, ISCSI_PARAM_DISCOVERY_PARENT_TYPE
,
2391 iscsi_get_discovery_parent_name(disc_parent
), 0);
2393 iscsi_set_param(conn
->cls_conn
, ISCSI_PARAM_TARGET_ALIAS
,
2394 (char *)fw_ddb_entry
->iscsi_alias
, 0);
2397 static void qla4xxx_copy_fwddb_param(struct scsi_qla_host
*ha
,
2398 struct dev_db_entry
*fw_ddb_entry
,
2399 struct iscsi_cls_session
*cls_sess
,
2400 struct iscsi_cls_conn
*cls_conn
)
2403 struct iscsi_session
*sess
;
2404 struct ddb_entry
*ddb_entry
;
2405 struct iscsi_conn
*conn
;
2406 char ip_addr
[DDB_IPADDR_LEN
];
2407 uint16_t options
= 0;
2409 sess
= cls_sess
->dd_data
;
2410 ddb_entry
= sess
->dd_data
;
2411 conn
= cls_conn
->dd_data
;
2413 ddb_entry
->chap_tbl_idx
= le16_to_cpu(fw_ddb_entry
->chap_tbl_idx
);
2415 qla4xxx_copy_to_sess_conn_params(conn
, sess
, fw_ddb_entry
);
2417 sess
->def_taskmgmt_tmo
= le16_to_cpu(fw_ddb_entry
->def_timeout
);
2418 conn
->persistent_port
= le16_to_cpu(fw_ddb_entry
->port
);
2420 memset(ip_addr
, 0, sizeof(ip_addr
));
2421 options
= le16_to_cpu(fw_ddb_entry
->options
);
2422 if (options
& DDB_OPT_IPV6_DEVICE
) {
2423 iscsi_set_param(cls_conn
, ISCSI_PARAM_PORTAL_TYPE
, "ipv6", 4);
2425 memset(ip_addr
, 0, sizeof(ip_addr
));
2426 sprintf(ip_addr
, "%pI6", fw_ddb_entry
->ip_addr
);
2428 iscsi_set_param(cls_conn
, ISCSI_PARAM_PORTAL_TYPE
, "ipv4", 4);
2429 sprintf(ip_addr
, "%pI4", fw_ddb_entry
->ip_addr
);
2432 iscsi_set_param(cls_conn
, ISCSI_PARAM_PERSISTENT_ADDRESS
,
2433 (char *)ip_addr
, buflen
);
2434 iscsi_set_param(cls_conn
, ISCSI_PARAM_TARGET_NAME
,
2435 (char *)fw_ddb_entry
->iscsi_name
, buflen
);
2436 iscsi_set_param(cls_conn
, ISCSI_PARAM_INITIATOR_NAME
,
2437 (char *)ha
->name_string
, buflen
);
2440 void qla4xxx_update_session_conn_fwddb_param(struct scsi_qla_host
*ha
,
2441 struct ddb_entry
*ddb_entry
)
2443 struct iscsi_cls_session
*cls_sess
;
2444 struct iscsi_cls_conn
*cls_conn
;
2446 dma_addr_t fw_ddb_entry_dma
;
2447 struct dev_db_entry
*fw_ddb_entry
;
2449 fw_ddb_entry
= dma_alloc_coherent(&ha
->pdev
->dev
, sizeof(*fw_ddb_entry
),
2450 &fw_ddb_entry_dma
, GFP_KERNEL
);
2451 if (!fw_ddb_entry
) {
2452 ql4_printk(KERN_ERR
, ha
,
2453 "%s: Unable to allocate dma buffer\n", __func__
);
2454 goto exit_session_conn_fwddb_param
;
2457 if (qla4xxx_get_fwddb_entry(ha
, ddb_entry
->fw_ddb_index
, fw_ddb_entry
,
2458 fw_ddb_entry_dma
, NULL
, NULL
, &ddb_state
,
2459 NULL
, NULL
, NULL
) == QLA_ERROR
) {
2460 DEBUG2(ql4_printk(KERN_ERR
, ha
, "scsi%ld: %s: failed "
2461 "get_ddb_entry for fw_ddb_index %d\n",
2462 ha
->host_no
, __func__
,
2463 ddb_entry
->fw_ddb_index
));
2464 goto exit_session_conn_fwddb_param
;
2467 cls_sess
= ddb_entry
->sess
;
2469 cls_conn
= ddb_entry
->conn
;
2472 qla4xxx_copy_fwddb_param(ha
, fw_ddb_entry
, cls_sess
, cls_conn
);
2474 exit_session_conn_fwddb_param
:
2476 dma_free_coherent(&ha
->pdev
->dev
, sizeof(*fw_ddb_entry
),
2477 fw_ddb_entry
, fw_ddb_entry_dma
);
2480 void qla4xxx_update_session_conn_param(struct scsi_qla_host
*ha
,
2481 struct ddb_entry
*ddb_entry
)
2483 struct iscsi_cls_session
*cls_sess
;
2484 struct iscsi_cls_conn
*cls_conn
;
2485 struct iscsi_session
*sess
;
2486 struct iscsi_conn
*conn
;
2488 dma_addr_t fw_ddb_entry_dma
;
2489 struct dev_db_entry
*fw_ddb_entry
;
2491 fw_ddb_entry
= dma_alloc_coherent(&ha
->pdev
->dev
, sizeof(*fw_ddb_entry
),
2492 &fw_ddb_entry_dma
, GFP_KERNEL
);
2493 if (!fw_ddb_entry
) {
2494 ql4_printk(KERN_ERR
, ha
,
2495 "%s: Unable to allocate dma buffer\n", __func__
);
2496 goto exit_session_conn_param
;
2499 if (qla4xxx_get_fwddb_entry(ha
, ddb_entry
->fw_ddb_index
, fw_ddb_entry
,
2500 fw_ddb_entry_dma
, NULL
, NULL
, &ddb_state
,
2501 NULL
, NULL
, NULL
) == QLA_ERROR
) {
2502 DEBUG2(ql4_printk(KERN_ERR
, ha
, "scsi%ld: %s: failed "
2503 "get_ddb_entry for fw_ddb_index %d\n",
2504 ha
->host_no
, __func__
,
2505 ddb_entry
->fw_ddb_index
));
2506 goto exit_session_conn_param
;
2509 cls_sess
= ddb_entry
->sess
;
2510 sess
= cls_sess
->dd_data
;
2512 cls_conn
= ddb_entry
->conn
;
2513 conn
= cls_conn
->dd_data
;
2515 /* Update timers after login */
2516 ddb_entry
->default_relogin_timeout
=
2517 (le16_to_cpu(fw_ddb_entry
->def_timeout
) > LOGIN_TOV
) &&
2518 (le16_to_cpu(fw_ddb_entry
->def_timeout
) < LOGIN_TOV
* 10) ?
2519 le16_to_cpu(fw_ddb_entry
->def_timeout
) : LOGIN_TOV
;
2520 ddb_entry
->default_time2wait
=
2521 le16_to_cpu(fw_ddb_entry
->iscsi_def_time2wait
);
2524 ddb_entry
->chap_tbl_idx
= le16_to_cpu(fw_ddb_entry
->chap_tbl_idx
);
2525 qla4xxx_copy_to_sess_conn_params(conn
, sess
, fw_ddb_entry
);
2527 memcpy(sess
->initiatorname
, ha
->name_string
,
2528 min(sizeof(ha
->name_string
), sizeof(sess
->initiatorname
)));
2530 exit_session_conn_param
:
2532 dma_free_coherent(&ha
->pdev
->dev
, sizeof(*fw_ddb_entry
),
2533 fw_ddb_entry
, fw_ddb_entry_dma
);
2540 static void qla4xxx_start_timer(struct scsi_qla_host
*ha
, void *func
,
2541 unsigned long interval
)
2543 DEBUG(printk("scsi: %s: Starting timer thread for adapter %d\n",
2544 __func__
, ha
->host
->host_no
));
2545 init_timer(&ha
->timer
);
2546 ha
->timer
.expires
= jiffies
+ interval
* HZ
;
2547 ha
->timer
.data
= (unsigned long)ha
;
2548 ha
->timer
.function
= (void (*)(unsigned long))func
;
2549 add_timer(&ha
->timer
);
2550 ha
->timer_active
= 1;
2553 static void qla4xxx_stop_timer(struct scsi_qla_host
*ha
)
2555 del_timer_sync(&ha
->timer
);
2556 ha
->timer_active
= 0;
2560 * qla4xxx_mark_device_missing - blocks the session
2561 * @cls_session: Pointer to the session to be blocked
2562 * @ddb_entry: Pointer to device database entry
2564 * This routine marks a device missing and close connection.
2566 void qla4xxx_mark_device_missing(struct iscsi_cls_session
*cls_session
)
2568 iscsi_block_session(cls_session
);
2572 * qla4xxx_mark_all_devices_missing - mark all devices as missing.
2573 * @ha: Pointer to host adapter structure.
2575 * This routine marks a device missing and resets the relogin retry count.
2577 void qla4xxx_mark_all_devices_missing(struct scsi_qla_host
*ha
)
2579 iscsi_host_for_each_session(ha
->host
, qla4xxx_mark_device_missing
);
2582 static struct srb
* qla4xxx_get_new_srb(struct scsi_qla_host
*ha
,
2583 struct ddb_entry
*ddb_entry
,
2584 struct scsi_cmnd
*cmd
)
2588 srb
= mempool_alloc(ha
->srb_mempool
, GFP_ATOMIC
);
2592 kref_init(&srb
->srb_ref
);
2594 srb
->ddb
= ddb_entry
;
2597 CMD_SP(cmd
) = (void *)srb
;
2602 static void qla4xxx_srb_free_dma(struct scsi_qla_host
*ha
, struct srb
*srb
)
2604 struct scsi_cmnd
*cmd
= srb
->cmd
;
2606 if (srb
->flags
& SRB_DMA_VALID
) {
2607 scsi_dma_unmap(cmd
);
2608 srb
->flags
&= ~SRB_DMA_VALID
;
2613 void qla4xxx_srb_compl(struct kref
*ref
)
2615 struct srb
*srb
= container_of(ref
, struct srb
, srb_ref
);
2616 struct scsi_cmnd
*cmd
= srb
->cmd
;
2617 struct scsi_qla_host
*ha
= srb
->ha
;
2619 qla4xxx_srb_free_dma(ha
, srb
);
2621 mempool_free(srb
, ha
->srb_mempool
);
2623 cmd
->scsi_done(cmd
);
2627 * qla4xxx_queuecommand - scsi layer issues scsi command to driver.
2629 * @cmd: Pointer to Linux's SCSI command structure
2632 * This routine is invoked by Linux to send a SCSI command to the driver.
2633 * The mid-level driver tries to ensure that queuecommand never gets
2634 * invoked concurrently with itself or the interrupt handler (although
2635 * the interrupt handler may call this routine as part of request-
2636 * completion handling). Unfortunely, it sometimes calls the scheduler
2637 * in interrupt context which is a big NO! NO!.
2639 static int qla4xxx_queuecommand(struct Scsi_Host
*host
, struct scsi_cmnd
*cmd
)
2641 struct scsi_qla_host
*ha
= to_qla_host(host
);
2642 struct ddb_entry
*ddb_entry
= cmd
->device
->hostdata
;
2643 struct iscsi_cls_session
*sess
= ddb_entry
->sess
;
2647 if (test_bit(AF_EEH_BUSY
, &ha
->flags
)) {
2648 if (test_bit(AF_PCI_CHANNEL_IO_PERM_FAILURE
, &ha
->flags
))
2649 cmd
->result
= DID_NO_CONNECT
<< 16;
2651 cmd
->result
= DID_REQUEUE
<< 16;
2652 goto qc_fail_command
;
2656 cmd
->result
= DID_IMM_RETRY
<< 16;
2657 goto qc_fail_command
;
2660 rval
= iscsi_session_chkready(sess
);
2663 goto qc_fail_command
;
2666 if (test_bit(DPC_RESET_HA_INTR
, &ha
->dpc_flags
) ||
2667 test_bit(DPC_RESET_ACTIVE
, &ha
->dpc_flags
) ||
2668 test_bit(DPC_RESET_HA
, &ha
->dpc_flags
) ||
2669 test_bit(DPC_HA_UNRECOVERABLE
, &ha
->dpc_flags
) ||
2670 test_bit(DPC_HA_NEED_QUIESCENT
, &ha
->dpc_flags
) ||
2671 !test_bit(AF_ONLINE
, &ha
->flags
) ||
2672 !test_bit(AF_LINK_UP
, &ha
->flags
) ||
2673 test_bit(AF_LOOPBACK
, &ha
->flags
) ||
2674 test_bit(DPC_POST_IDC_ACK
, &ha
->dpc_flags
) ||
2675 test_bit(DPC_RESTORE_ACB
, &ha
->dpc_flags
) ||
2676 test_bit(DPC_RESET_HA_FW_CONTEXT
, &ha
->dpc_flags
))
2679 srb
= qla4xxx_get_new_srb(ha
, ddb_entry
, cmd
);
2683 rval
= qla4xxx_send_command_to_isp(ha
, srb
);
2684 if (rval
!= QLA_SUCCESS
)
2685 goto qc_host_busy_free_sp
;
2689 qc_host_busy_free_sp
:
2690 qla4xxx_srb_free_dma(ha
, srb
);
2691 mempool_free(srb
, ha
->srb_mempool
);
2694 return SCSI_MLQUEUE_HOST_BUSY
;
2697 cmd
->scsi_done(cmd
);
2703 * qla4xxx_mem_free - frees memory allocated to adapter
2704 * @ha: Pointer to host adapter structure.
2706 * Frees memory previously allocated by qla4xxx_mem_alloc
2708 static void qla4xxx_mem_free(struct scsi_qla_host
*ha
)
2711 dma_free_coherent(&ha
->pdev
->dev
, ha
->queues_len
, ha
->queues
,
2720 ha
->request_ring
= NULL
;
2721 ha
->request_dma
= 0;
2722 ha
->response_ring
= NULL
;
2723 ha
->response_dma
= 0;
2724 ha
->shadow_regs
= NULL
;
2725 ha
->shadow_regs_dma
= 0;
2727 ha
->fw_dump_size
= 0;
2729 /* Free srb pool. */
2730 if (ha
->srb_mempool
)
2731 mempool_destroy(ha
->srb_mempool
);
2733 ha
->srb_mempool
= NULL
;
2735 if (ha
->chap_dma_pool
)
2736 dma_pool_destroy(ha
->chap_dma_pool
);
2739 vfree(ha
->chap_list
);
2740 ha
->chap_list
= NULL
;
2742 if (ha
->fw_ddb_dma_pool
)
2743 dma_pool_destroy(ha
->fw_ddb_dma_pool
);
2745 /* release io space registers */
2746 if (is_qla8022(ha
)) {
2749 (struct device_reg_82xx __iomem
*)ha
->nx_pcibase
);
2750 } else if (is_qla8032(ha
) || is_qla8042(ha
)) {
2753 (struct device_reg_83xx __iomem
*)ha
->nx_pcibase
);
2754 } else if (ha
->reg
) {
2758 if (ha
->reset_tmplt
.buff
)
2759 vfree(ha
->reset_tmplt
.buff
);
2761 pci_release_regions(ha
->pdev
);
2765 * qla4xxx_mem_alloc - allocates memory for use by adapter.
2766 * @ha: Pointer to host adapter structure
2768 * Allocates DMA memory for request and response queues. Also allocates memory
2771 static int qla4xxx_mem_alloc(struct scsi_qla_host
*ha
)
2773 unsigned long align
;
2775 /* Allocate contiguous block of DMA memory for queues. */
2776 ha
->queues_len
= ((REQUEST_QUEUE_DEPTH
* QUEUE_SIZE
) +
2777 (RESPONSE_QUEUE_DEPTH
* QUEUE_SIZE
) +
2778 sizeof(struct shadow_regs
) +
2780 (PAGE_SIZE
- 1)) & ~(PAGE_SIZE
- 1);
2781 ha
->queues
= dma_alloc_coherent(&ha
->pdev
->dev
, ha
->queues_len
,
2782 &ha
->queues_dma
, GFP_KERNEL
);
2783 if (ha
->queues
== NULL
) {
2784 ql4_printk(KERN_WARNING
, ha
,
2785 "Memory Allocation failed - queues.\n");
2787 goto mem_alloc_error_exit
;
2789 memset(ha
->queues
, 0, ha
->queues_len
);
2792 * As per RISC alignment requirements -- the bus-address must be a
2793 * multiple of the request-ring size (in bytes).
2796 if ((unsigned long)ha
->queues_dma
& (MEM_ALIGN_VALUE
- 1))
2797 align
= MEM_ALIGN_VALUE
- ((unsigned long)ha
->queues_dma
&
2798 (MEM_ALIGN_VALUE
- 1));
2800 /* Update request and response queue pointers. */
2801 ha
->request_dma
= ha
->queues_dma
+ align
;
2802 ha
->request_ring
= (struct queue_entry
*) (ha
->queues
+ align
);
2803 ha
->response_dma
= ha
->queues_dma
+ align
+
2804 (REQUEST_QUEUE_DEPTH
* QUEUE_SIZE
);
2805 ha
->response_ring
= (struct queue_entry
*) (ha
->queues
+ align
+
2806 (REQUEST_QUEUE_DEPTH
*
2808 ha
->shadow_regs_dma
= ha
->queues_dma
+ align
+
2809 (REQUEST_QUEUE_DEPTH
* QUEUE_SIZE
) +
2810 (RESPONSE_QUEUE_DEPTH
* QUEUE_SIZE
);
2811 ha
->shadow_regs
= (struct shadow_regs
*) (ha
->queues
+ align
+
2812 (REQUEST_QUEUE_DEPTH
*
2814 (RESPONSE_QUEUE_DEPTH
*
2817 /* Allocate memory for srb pool. */
2818 ha
->srb_mempool
= mempool_create(SRB_MIN_REQ
, mempool_alloc_slab
,
2819 mempool_free_slab
, srb_cachep
);
2820 if (ha
->srb_mempool
== NULL
) {
2821 ql4_printk(KERN_WARNING
, ha
,
2822 "Memory Allocation failed - SRB Pool.\n");
2824 goto mem_alloc_error_exit
;
2827 ha
->chap_dma_pool
= dma_pool_create("ql4_chap", &ha
->pdev
->dev
,
2828 CHAP_DMA_BLOCK_SIZE
, 8, 0);
2830 if (ha
->chap_dma_pool
== NULL
) {
2831 ql4_printk(KERN_WARNING
, ha
,
2832 "%s: chap_dma_pool allocation failed..\n", __func__
);
2833 goto mem_alloc_error_exit
;
2836 ha
->fw_ddb_dma_pool
= dma_pool_create("ql4_fw_ddb", &ha
->pdev
->dev
,
2837 DDB_DMA_BLOCK_SIZE
, 8, 0);
2839 if (ha
->fw_ddb_dma_pool
== NULL
) {
2840 ql4_printk(KERN_WARNING
, ha
,
2841 "%s: fw_ddb_dma_pool allocation failed..\n",
2843 goto mem_alloc_error_exit
;
2848 mem_alloc_error_exit
:
2849 qla4xxx_mem_free(ha
);
2854 * qla4_8xxx_check_temp - Check the ISP82XX temperature.
2855 * @ha: adapter block pointer.
2857 * Note: The caller should not hold the idc lock.
2859 static int qla4_8xxx_check_temp(struct scsi_qla_host
*ha
)
2861 uint32_t temp
, temp_state
, temp_val
;
2862 int status
= QLA_SUCCESS
;
2864 temp
= qla4_8xxx_rd_direct(ha
, QLA8XXX_CRB_TEMP_STATE
);
2866 temp_state
= qla82xx_get_temp_state(temp
);
2867 temp_val
= qla82xx_get_temp_val(temp
);
2869 if (temp_state
== QLA82XX_TEMP_PANIC
) {
2870 ql4_printk(KERN_WARNING
, ha
, "Device temperature %d degrees C"
2871 " exceeds maximum allowed. Hardware has been shut"
2872 " down.\n", temp_val
);
2874 } else if (temp_state
== QLA82XX_TEMP_WARN
) {
2875 if (ha
->temperature
== QLA82XX_TEMP_NORMAL
)
2876 ql4_printk(KERN_WARNING
, ha
, "Device temperature %d"
2877 " degrees C exceeds operating range."
2878 " Immediate action needed.\n", temp_val
);
2880 if (ha
->temperature
== QLA82XX_TEMP_WARN
)
2881 ql4_printk(KERN_INFO
, ha
, "Device temperature is"
2882 " now %d degrees C in normal range.\n",
2885 ha
->temperature
= temp_state
;
2890 * qla4_8xxx_check_fw_alive - Check firmware health
2891 * @ha: Pointer to host adapter structure.
2893 * Context: Interrupt
2895 static int qla4_8xxx_check_fw_alive(struct scsi_qla_host
*ha
)
2897 uint32_t fw_heartbeat_counter
;
2898 int status
= QLA_SUCCESS
;
2900 fw_heartbeat_counter
= qla4_8xxx_rd_direct(ha
,
2901 QLA8XXX_PEG_ALIVE_COUNTER
);
2902 /* If PEG_ALIVE_COUNTER is 0xffffffff, AER/EEH is in progress, ignore */
2903 if (fw_heartbeat_counter
== 0xffffffff) {
2904 DEBUG2(printk(KERN_WARNING
"scsi%ld: %s: Device in frozen "
2905 "state, QLA82XX_PEG_ALIVE_COUNTER is 0xffffffff\n",
2906 ha
->host_no
, __func__
));
2910 if (ha
->fw_heartbeat_counter
== fw_heartbeat_counter
) {
2911 ha
->seconds_since_last_heartbeat
++;
2912 /* FW not alive after 2 seconds */
2913 if (ha
->seconds_since_last_heartbeat
== 2) {
2914 ha
->seconds_since_last_heartbeat
= 0;
2915 qla4_8xxx_dump_peg_reg(ha
);
2919 ha
->seconds_since_last_heartbeat
= 0;
2921 ha
->fw_heartbeat_counter
= fw_heartbeat_counter
;
2925 static void qla4_8xxx_process_fw_error(struct scsi_qla_host
*ha
)
2927 uint32_t halt_status
;
2928 int halt_status_unrecoverable
= 0;
2930 halt_status
= qla4_8xxx_rd_direct(ha
, QLA8XXX_PEG_HALT_STATUS1
);
2932 if (is_qla8022(ha
)) {
2933 ql4_printk(KERN_INFO
, ha
, "%s: disabling pause transmit on port 0 & 1.\n",
2935 qla4_82xx_wr_32(ha
, QLA82XX_CRB_NIU
+ 0x98,
2936 CRB_NIU_XG_PAUSE_CTL_P0
|
2937 CRB_NIU_XG_PAUSE_CTL_P1
);
2939 if (QLA82XX_FWERROR_CODE(halt_status
) == 0x67)
2940 ql4_printk(KERN_ERR
, ha
, "%s: Firmware aborted with error code 0x00006700. Device is being reset\n",
2942 if (halt_status
& HALT_STATUS_UNRECOVERABLE
)
2943 halt_status_unrecoverable
= 1;
2944 } else if (is_qla8032(ha
) || is_qla8042(ha
)) {
2945 if (halt_status
& QLA83XX_HALT_STATUS_FW_RESET
)
2946 ql4_printk(KERN_ERR
, ha
, "%s: Firmware error detected device is being reset\n",
2948 else if (halt_status
& QLA83XX_HALT_STATUS_UNRECOVERABLE
)
2949 halt_status_unrecoverable
= 1;
2953 * Since we cannot change dev_state in interrupt context,
2954 * set appropriate DPC flag then wakeup DPC
2956 if (halt_status_unrecoverable
) {
2957 set_bit(DPC_HA_UNRECOVERABLE
, &ha
->dpc_flags
);
2959 ql4_printk(KERN_INFO
, ha
, "%s: detect abort needed!\n",
2961 set_bit(DPC_RESET_HA
, &ha
->dpc_flags
);
2963 qla4xxx_mailbox_premature_completion(ha
);
2964 qla4xxx_wake_dpc(ha
);
2968 * qla4_8xxx_watchdog - Poll dev state
2969 * @ha: Pointer to host adapter structure.
2971 * Context: Interrupt
2973 void qla4_8xxx_watchdog(struct scsi_qla_host
*ha
)
2978 /* don't poll if reset is going on */
2979 if (!(test_bit(DPC_RESET_ACTIVE
, &ha
->dpc_flags
) ||
2980 test_bit(DPC_RESET_HA
, &ha
->dpc_flags
) ||
2981 test_bit(DPC_RETRY_RESET_HA
, &ha
->dpc_flags
))) {
2982 dev_state
= qla4_8xxx_rd_direct(ha
, QLA8XXX_CRB_DEV_STATE
);
2984 if (qla4_8xxx_check_temp(ha
)) {
2985 if (is_qla8022(ha
)) {
2986 ql4_printk(KERN_INFO
, ha
, "disabling pause transmit on port 0 & 1.\n");
2987 qla4_82xx_wr_32(ha
, QLA82XX_CRB_NIU
+ 0x98,
2988 CRB_NIU_XG_PAUSE_CTL_P0
|
2989 CRB_NIU_XG_PAUSE_CTL_P1
);
2991 set_bit(DPC_HA_UNRECOVERABLE
, &ha
->dpc_flags
);
2992 qla4xxx_wake_dpc(ha
);
2993 } else if (dev_state
== QLA8XXX_DEV_NEED_RESET
&&
2994 !test_bit(DPC_RESET_HA
, &ha
->dpc_flags
)) {
2996 ql4_printk(KERN_INFO
, ha
, "%s: HW State: NEED RESET!\n",
2999 if (is_qla8032(ha
) || is_qla8042(ha
)) {
3000 idc_ctrl
= qla4_83xx_rd_reg(ha
,
3001 QLA83XX_IDC_DRV_CTRL
);
3002 if (!(idc_ctrl
& GRACEFUL_RESET_BIT1
)) {
3003 ql4_printk(KERN_INFO
, ha
, "%s: Graceful reset bit is not set\n",
3005 qla4xxx_mailbox_premature_completion(
3010 if ((is_qla8032(ha
) || is_qla8042(ha
)) ||
3011 (is_qla8022(ha
) && !ql4xdontresethba
)) {
3012 set_bit(DPC_RESET_HA
, &ha
->dpc_flags
);
3013 qla4xxx_wake_dpc(ha
);
3015 } else if (dev_state
== QLA8XXX_DEV_NEED_QUIESCENT
&&
3016 !test_bit(DPC_HA_NEED_QUIESCENT
, &ha
->dpc_flags
)) {
3017 ql4_printk(KERN_INFO
, ha
, "%s: HW State: NEED QUIES!\n",
3019 set_bit(DPC_HA_NEED_QUIESCENT
, &ha
->dpc_flags
);
3020 qla4xxx_wake_dpc(ha
);
3022 /* Check firmware health */
3023 if (qla4_8xxx_check_fw_alive(ha
))
3024 qla4_8xxx_process_fw_error(ha
);
3029 static void qla4xxx_check_relogin_flash_ddb(struct iscsi_cls_session
*cls_sess
)
3031 struct iscsi_session
*sess
;
3032 struct ddb_entry
*ddb_entry
;
3033 struct scsi_qla_host
*ha
;
3035 sess
= cls_sess
->dd_data
;
3036 ddb_entry
= sess
->dd_data
;
3039 if (!(ddb_entry
->ddb_type
== FLASH_DDB
))
3042 if (adapter_up(ha
) && !test_bit(DF_RELOGIN
, &ddb_entry
->flags
) &&
3043 !iscsi_is_session_online(cls_sess
)) {
3044 if (atomic_read(&ddb_entry
->retry_relogin_timer
) !=
3046 if (atomic_read(&ddb_entry
->retry_relogin_timer
) ==
3048 atomic_set(&ddb_entry
->retry_relogin_timer
,
3050 set_bit(DPC_RELOGIN_DEVICE
, &ha
->dpc_flags
);
3051 set_bit(DF_RELOGIN
, &ddb_entry
->flags
);
3052 DEBUG2(ql4_printk(KERN_INFO
, ha
,
3053 "%s: index [%d] login device\n",
3054 __func__
, ddb_entry
->fw_ddb_index
));
3056 atomic_dec(&ddb_entry
->retry_relogin_timer
);
3060 /* Wait for relogin to timeout */
3061 if (atomic_read(&ddb_entry
->relogin_timer
) &&
3062 (atomic_dec_and_test(&ddb_entry
->relogin_timer
) != 0)) {
3064 * If the relogin times out and the device is
3065 * still NOT ONLINE then try and relogin again.
3067 if (!iscsi_is_session_online(cls_sess
)) {
3068 /* Reset retry relogin timer */
3069 atomic_inc(&ddb_entry
->relogin_retry_count
);
3070 DEBUG2(ql4_printk(KERN_INFO
, ha
,
3071 "%s: index[%d] relogin timed out-retrying"
3072 " relogin (%d), retry (%d)\n", __func__
,
3073 ddb_entry
->fw_ddb_index
,
3074 atomic_read(&ddb_entry
->relogin_retry_count
),
3075 ddb_entry
->default_time2wait
+ 4));
3076 set_bit(DPC_RELOGIN_DEVICE
, &ha
->dpc_flags
);
3077 atomic_set(&ddb_entry
->retry_relogin_timer
,
3078 ddb_entry
->default_time2wait
+ 4);
3084 * qla4xxx_timer - checks every second for work to do.
3085 * @ha: Pointer to host adapter structure.
3087 static void qla4xxx_timer(struct scsi_qla_host
*ha
)
3092 iscsi_host_for_each_session(ha
->host
, qla4xxx_check_relogin_flash_ddb
);
3094 /* If we are in the middle of AER/EEH processing
3095 * skip any processing and reschedule the timer
3097 if (test_bit(AF_EEH_BUSY
, &ha
->flags
)) {
3098 mod_timer(&ha
->timer
, jiffies
+ HZ
);
3102 /* Hardware read to trigger an EEH error during mailbox waits. */
3103 if (!pci_channel_offline(ha
->pdev
))
3104 pci_read_config_word(ha
->pdev
, PCI_VENDOR_ID
, &w
);
3107 qla4_8xxx_watchdog(ha
);
3109 if (is_qla40XX(ha
)) {
3110 /* Check for heartbeat interval. */
3111 if (ha
->firmware_options
& FWOPT_HEARTBEAT_ENABLE
&&
3112 ha
->heartbeat_interval
!= 0) {
3113 ha
->seconds_since_last_heartbeat
++;
3114 if (ha
->seconds_since_last_heartbeat
>
3115 ha
->heartbeat_interval
+ 2)
3116 set_bit(DPC_RESET_HA
, &ha
->dpc_flags
);
3120 /* Process any deferred work. */
3121 if (!list_empty(&ha
->work_list
))
3124 /* Wakeup the dpc routine for this adapter, if needed. */
3126 test_bit(DPC_RESET_HA
, &ha
->dpc_flags
) ||
3127 test_bit(DPC_RETRY_RESET_HA
, &ha
->dpc_flags
) ||
3128 test_bit(DPC_RELOGIN_DEVICE
, &ha
->dpc_flags
) ||
3129 test_bit(DPC_RESET_HA_FW_CONTEXT
, &ha
->dpc_flags
) ||
3130 test_bit(DPC_RESET_HA_INTR
, &ha
->dpc_flags
) ||
3131 test_bit(DPC_GET_DHCP_IP_ADDR
, &ha
->dpc_flags
) ||
3132 test_bit(DPC_LINK_CHANGED
, &ha
->dpc_flags
) ||
3133 test_bit(DPC_HA_UNRECOVERABLE
, &ha
->dpc_flags
) ||
3134 test_bit(DPC_HA_NEED_QUIESCENT
, &ha
->dpc_flags
) ||
3135 test_bit(DPC_AEN
, &ha
->dpc_flags
)) {
3136 DEBUG2(printk("scsi%ld: %s: scheduling dpc routine"
3137 " - dpc flags = 0x%lx\n",
3138 ha
->host_no
, __func__
, ha
->dpc_flags
));
3139 qla4xxx_wake_dpc(ha
);
3142 /* Reschedule timer thread to call us back in one second */
3143 mod_timer(&ha
->timer
, jiffies
+ HZ
);
3145 DEBUG2(ha
->seconds_since_last_intr
++);
3149 * qla4xxx_cmd_wait - waits for all outstanding commands to complete
3150 * @ha: Pointer to host adapter structure.
3152 * This routine stalls the driver until all outstanding commands are returned.
3153 * Caller must release the Hardware Lock prior to calling this routine.
3155 static int qla4xxx_cmd_wait(struct scsi_qla_host
*ha
)
3158 unsigned long flags
;
3159 struct scsi_cmnd
*cmd
;
3161 unsigned long wtime
= jiffies
+ (WAIT_CMD_TOV
* HZ
);
3163 DEBUG2(ql4_printk(KERN_INFO
, ha
, "Wait up to %d seconds for cmds to "
3164 "complete\n", WAIT_CMD_TOV
));
3166 while (!time_after_eq(jiffies
, wtime
)) {
3167 spin_lock_irqsave(&ha
->hardware_lock
, flags
);
3168 /* Find a command that hasn't completed. */
3169 for (index
= 0; index
< ha
->host
->can_queue
; index
++) {
3170 cmd
= scsi_host_find_tag(ha
->host
, index
);
3172 * We cannot just check if the index is valid,
3173 * becase if we are run from the scsi eh, then
3174 * the scsi/block layer is going to prevent
3175 * the tag from being released.
3177 if (cmd
!= NULL
&& CMD_SP(cmd
))
3180 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
3182 /* If No Commands are pending, wait is complete */
3183 if (index
== ha
->host
->can_queue
)
3188 /* If we timed out on waiting for commands to come back
3193 int qla4xxx_hw_reset(struct scsi_qla_host
*ha
)
3195 uint32_t ctrl_status
;
3196 unsigned long flags
= 0;
3198 DEBUG2(printk(KERN_ERR
"scsi%ld: %s\n", ha
->host_no
, __func__
));
3200 if (ql4xxx_lock_drvr_wait(ha
) != QLA_SUCCESS
)
3203 spin_lock_irqsave(&ha
->hardware_lock
, flags
);
3206 * If the SCSI Reset Interrupt bit is set, clear it.
3207 * Otherwise, the Soft Reset won't work.
3209 ctrl_status
= readw(&ha
->reg
->ctrl_status
);
3210 if ((ctrl_status
& CSR_SCSI_RESET_INTR
) != 0)
3211 writel(set_rmask(CSR_SCSI_RESET_INTR
), &ha
->reg
->ctrl_status
);
3213 /* Issue Soft Reset */
3214 writel(set_rmask(CSR_SOFT_RESET
), &ha
->reg
->ctrl_status
);
3215 readl(&ha
->reg
->ctrl_status
);
3217 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
3222 * qla4xxx_soft_reset - performs soft reset.
3223 * @ha: Pointer to host adapter structure.
3225 int qla4xxx_soft_reset(struct scsi_qla_host
*ha
)
3227 uint32_t max_wait_time
;
3228 unsigned long flags
= 0;
3230 uint32_t ctrl_status
;
3232 status
= qla4xxx_hw_reset(ha
);
3233 if (status
!= QLA_SUCCESS
)
3237 /* Wait until the Network Reset Intr bit is cleared */
3238 max_wait_time
= RESET_INTR_TOV
;
3240 spin_lock_irqsave(&ha
->hardware_lock
, flags
);
3241 ctrl_status
= readw(&ha
->reg
->ctrl_status
);
3242 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
3244 if ((ctrl_status
& CSR_NET_RESET_INTR
) == 0)
3248 } while ((--max_wait_time
));
3250 if ((ctrl_status
& CSR_NET_RESET_INTR
) != 0) {
3251 DEBUG2(printk(KERN_WARNING
3252 "scsi%ld: Network Reset Intr not cleared by "
3253 "Network function, clearing it now!\n",
3255 spin_lock_irqsave(&ha
->hardware_lock
, flags
);
3256 writel(set_rmask(CSR_NET_RESET_INTR
), &ha
->reg
->ctrl_status
);
3257 readl(&ha
->reg
->ctrl_status
);
3258 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
3261 /* Wait until the firmware tells us the Soft Reset is done */
3262 max_wait_time
= SOFT_RESET_TOV
;
3264 spin_lock_irqsave(&ha
->hardware_lock
, flags
);
3265 ctrl_status
= readw(&ha
->reg
->ctrl_status
);
3266 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
3268 if ((ctrl_status
& CSR_SOFT_RESET
) == 0) {
3269 status
= QLA_SUCCESS
;
3274 } while ((--max_wait_time
));
3277 * Also, make sure that the SCSI Reset Interrupt bit has been cleared
3278 * after the soft reset has taken place.
3280 spin_lock_irqsave(&ha
->hardware_lock
, flags
);
3281 ctrl_status
= readw(&ha
->reg
->ctrl_status
);
3282 if ((ctrl_status
& CSR_SCSI_RESET_INTR
) != 0) {
3283 writel(set_rmask(CSR_SCSI_RESET_INTR
), &ha
->reg
->ctrl_status
);
3284 readl(&ha
->reg
->ctrl_status
);
3286 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
3288 /* If soft reset fails then most probably the bios on other
3289 * function is also enabled.
3290 * Since the initialization is sequential the other fn
3291 * wont be able to acknowledge the soft reset.
3292 * Issue a force soft reset to workaround this scenario.
3294 if (max_wait_time
== 0) {
3295 /* Issue Force Soft Reset */
3296 spin_lock_irqsave(&ha
->hardware_lock
, flags
);
3297 writel(set_rmask(CSR_FORCE_SOFT_RESET
), &ha
->reg
->ctrl_status
);
3298 readl(&ha
->reg
->ctrl_status
);
3299 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
3300 /* Wait until the firmware tells us the Soft Reset is done */
3301 max_wait_time
= SOFT_RESET_TOV
;
3303 spin_lock_irqsave(&ha
->hardware_lock
, flags
);
3304 ctrl_status
= readw(&ha
->reg
->ctrl_status
);
3305 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
3307 if ((ctrl_status
& CSR_FORCE_SOFT_RESET
) == 0) {
3308 status
= QLA_SUCCESS
;
3313 } while ((--max_wait_time
));
3320 * qla4xxx_abort_active_cmds - returns all outstanding i/o requests to O.S.
3321 * @ha: Pointer to host adapter structure.
3322 * @res: returned scsi status
3324 * This routine is called just prior to a HARD RESET to return all
3325 * outstanding commands back to the Operating System.
3326 * Caller should make sure that the following locks are released
3327 * before this calling routine: Hardware lock, and io_request_lock.
3329 static void qla4xxx_abort_active_cmds(struct scsi_qla_host
*ha
, int res
)
3333 unsigned long flags
;
3335 spin_lock_irqsave(&ha
->hardware_lock
, flags
);
3336 for (i
= 0; i
< ha
->host
->can_queue
; i
++) {
3337 srb
= qla4xxx_del_from_active_array(ha
, i
);
3339 srb
->cmd
->result
= res
;
3340 kref_put(&srb
->srb_ref
, qla4xxx_srb_compl
);
3343 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
3346 void qla4xxx_dead_adapter_cleanup(struct scsi_qla_host
*ha
)
3348 clear_bit(AF_ONLINE
, &ha
->flags
);
3350 /* Disable the board */
3351 ql4_printk(KERN_INFO
, ha
, "Disabling the board\n");
3353 qla4xxx_abort_active_cmds(ha
, DID_NO_CONNECT
<< 16);
3354 qla4xxx_mark_all_devices_missing(ha
);
3355 clear_bit(AF_INIT_DONE
, &ha
->flags
);
3358 static void qla4xxx_fail_session(struct iscsi_cls_session
*cls_session
)
3360 struct iscsi_session
*sess
;
3361 struct ddb_entry
*ddb_entry
;
3363 sess
= cls_session
->dd_data
;
3364 ddb_entry
= sess
->dd_data
;
3365 ddb_entry
->fw_ddb_device_state
= DDB_DS_SESSION_FAILED
;
3367 if (ddb_entry
->ddb_type
== FLASH_DDB
)
3368 iscsi_block_session(ddb_entry
->sess
);
3370 iscsi_session_failure(cls_session
->dd_data
,
3371 ISCSI_ERR_CONN_FAILED
);
3375 * qla4xxx_recover_adapter - recovers adapter after a fatal error
3376 * @ha: Pointer to host adapter structure.
3378 static int qla4xxx_recover_adapter(struct scsi_qla_host
*ha
)
3380 int status
= QLA_ERROR
;
3381 uint8_t reset_chip
= 0;
3385 /* Stall incoming I/O until we are done */
3386 scsi_block_requests(ha
->host
);
3387 clear_bit(AF_ONLINE
, &ha
->flags
);
3388 clear_bit(AF_LINK_UP
, &ha
->flags
);
3390 DEBUG2(ql4_printk(KERN_INFO
, ha
, "%s: adapter OFFLINE\n", __func__
));
3392 set_bit(DPC_RESET_ACTIVE
, &ha
->dpc_flags
);
3394 if ((is_qla8032(ha
) || is_qla8042(ha
)) &&
3395 !test_bit(DPC_RESET_HA_FW_CONTEXT
, &ha
->dpc_flags
)) {
3396 ql4_printk(KERN_INFO
, ha
, "%s: disabling pause transmit on port 0 & 1.\n",
3398 /* disable pause frame for ISP83xx */
3399 qla4_83xx_disable_pause(ha
);
3402 iscsi_host_for_each_session(ha
->host
, qla4xxx_fail_session
);
3404 if (test_bit(DPC_RESET_HA
, &ha
->dpc_flags
))
3407 /* For the DPC_RESET_HA_INTR case (ISP-4xxx specific)
3408 * do not reset adapter, jump to initialize_adapter */
3409 if (test_bit(DPC_RESET_HA_INTR
, &ha
->dpc_flags
)) {
3410 status
= QLA_SUCCESS
;
3411 goto recover_ha_init_adapter
;
3414 /* For the ISP-8xxx adapter, issue a stop_firmware if invoked
3415 * from eh_host_reset or ioctl module */
3416 if (is_qla80XX(ha
) && !reset_chip
&&
3417 test_bit(DPC_RESET_HA_FW_CONTEXT
, &ha
->dpc_flags
)) {
3419 DEBUG2(ql4_printk(KERN_INFO
, ha
,
3420 "scsi%ld: %s - Performing stop_firmware...\n",
3421 ha
->host_no
, __func__
));
3422 status
= ha
->isp_ops
->reset_firmware(ha
);
3423 if (status
== QLA_SUCCESS
) {
3424 if (!test_bit(AF_FW_RECOVERY
, &ha
->flags
))
3425 qla4xxx_cmd_wait(ha
);
3427 ha
->isp_ops
->disable_intrs(ha
);
3428 qla4xxx_process_aen(ha
, FLUSH_DDB_CHANGED_AENS
);
3429 qla4xxx_abort_active_cmds(ha
, DID_RESET
<< 16);
3431 /* If the stop_firmware fails then
3432 * reset the entire chip */
3434 clear_bit(DPC_RESET_HA_FW_CONTEXT
, &ha
->dpc_flags
);
3435 set_bit(DPC_RESET_HA
, &ha
->dpc_flags
);
3439 /* Issue full chip reset if recovering from a catastrophic error,
3440 * or if stop_firmware fails for ISP-8xxx.
3441 * This is the default case for ISP-4xxx */
3442 if (is_qla40XX(ha
) || reset_chip
) {
3446 /* Check if 8XXX firmware is alive or not
3447 * We may have arrived here from NEED_RESET
3449 if (test_bit(AF_FW_RECOVERY
, &ha
->flags
))
3452 wait
= jiffies
+ (FW_ALIVE_WAIT_TOV
* HZ
);
3453 while (time_before(jiffies
, wait
)) {
3454 if (qla4_8xxx_check_fw_alive(ha
)) {
3455 qla4xxx_mailbox_premature_completion(ha
);
3459 set_current_state(TASK_UNINTERRUPTIBLE
);
3460 schedule_timeout(HZ
);
3463 if (!test_bit(AF_FW_RECOVERY
, &ha
->flags
))
3464 qla4xxx_cmd_wait(ha
);
3466 qla4xxx_process_aen(ha
, FLUSH_DDB_CHANGED_AENS
);
3467 qla4xxx_abort_active_cmds(ha
, DID_RESET
<< 16);
3468 DEBUG2(ql4_printk(KERN_INFO
, ha
,
3469 "scsi%ld: %s - Performing chip reset..\n",
3470 ha
->host_no
, __func__
));
3471 status
= ha
->isp_ops
->reset_chip(ha
);
3474 /* Flush any pending ddb changed AENs */
3475 qla4xxx_process_aen(ha
, FLUSH_DDB_CHANGED_AENS
);
3477 recover_ha_init_adapter
:
3478 /* Upon successful firmware/chip reset, re-initialize the adapter */
3479 if (status
== QLA_SUCCESS
) {
3480 /* For ISP-4xxx, force function 1 to always initialize
3481 * before function 3 to prevent both funcions from
3482 * stepping on top of the other */
3483 if (is_qla40XX(ha
) && (ha
->mac_index
== 3))
3486 /* NOTE: AF_ONLINE flag set upon successful completion of
3487 * qla4xxx_initialize_adapter */
3488 status
= qla4xxx_initialize_adapter(ha
, RESET_ADAPTER
);
3491 /* Retry failed adapter initialization, if necessary
3492 * Do not retry initialize_adapter for RESET_HA_INTR (ISP-4xxx specific)
3493 * case to prevent ping-pong resets between functions */
3494 if (!test_bit(AF_ONLINE
, &ha
->flags
) &&
3495 !test_bit(DPC_RESET_HA_INTR
, &ha
->dpc_flags
)) {
3496 /* Adapter initialization failed, see if we can retry
3498 * Since we don't want to block the DPC for too long
3499 * with multiple resets in the same thread,
3500 * utilize DPC to retry */
3501 if (is_qla80XX(ha
)) {
3502 ha
->isp_ops
->idc_lock(ha
);
3503 dev_state
= qla4_8xxx_rd_direct(ha
,
3504 QLA8XXX_CRB_DEV_STATE
);
3505 ha
->isp_ops
->idc_unlock(ha
);
3506 if (dev_state
== QLA8XXX_DEV_FAILED
) {
3507 ql4_printk(KERN_INFO
, ha
, "%s: don't retry "
3508 "recover adapter. H/W is in Failed "
3509 "state\n", __func__
);
3510 qla4xxx_dead_adapter_cleanup(ha
);
3511 clear_bit(DPC_RETRY_RESET_HA
, &ha
->dpc_flags
);
3512 clear_bit(DPC_RESET_HA
, &ha
->dpc_flags
);
3513 clear_bit(DPC_RESET_HA_FW_CONTEXT
,
3521 if (!test_bit(DPC_RETRY_RESET_HA
, &ha
->dpc_flags
)) {
3522 ha
->retry_reset_ha_cnt
= MAX_RESET_HA_RETRIES
;
3523 DEBUG2(printk("scsi%ld: recover adapter - retrying "
3524 "(%d) more times\n", ha
->host_no
,
3525 ha
->retry_reset_ha_cnt
));
3526 set_bit(DPC_RETRY_RESET_HA
, &ha
->dpc_flags
);
3529 if (ha
->retry_reset_ha_cnt
> 0) {
3530 /* Schedule another Reset HA--DPC will retry */
3531 ha
->retry_reset_ha_cnt
--;
3532 DEBUG2(printk("scsi%ld: recover adapter - "
3533 "retry remaining %d\n",
3535 ha
->retry_reset_ha_cnt
));
3539 if (ha
->retry_reset_ha_cnt
== 0) {
3540 /* Recover adapter retries have been exhausted.
3542 DEBUG2(printk("scsi%ld: recover adapter "
3543 "failed - board disabled\n",
3545 qla4xxx_dead_adapter_cleanup(ha
);
3546 clear_bit(DPC_RETRY_RESET_HA
, &ha
->dpc_flags
);
3547 clear_bit(DPC_RESET_HA
, &ha
->dpc_flags
);
3548 clear_bit(DPC_RESET_HA_FW_CONTEXT
,
3554 clear_bit(DPC_RESET_HA
, &ha
->dpc_flags
);
3555 clear_bit(DPC_RESET_HA_FW_CONTEXT
, &ha
->dpc_flags
);
3556 clear_bit(DPC_RETRY_RESET_HA
, &ha
->dpc_flags
);
3560 ha
->adapter_error_count
++;
3562 if (test_bit(AF_ONLINE
, &ha
->flags
))
3563 ha
->isp_ops
->enable_intrs(ha
);
3565 scsi_unblock_requests(ha
->host
);
3567 clear_bit(DPC_RESET_ACTIVE
, &ha
->dpc_flags
);
3568 DEBUG2(printk("scsi%ld: recover adapter: %s\n", ha
->host_no
,
3569 status
== QLA_ERROR
? "FAILED" : "SUCCEEDED"));
3574 static void qla4xxx_relogin_devices(struct iscsi_cls_session
*cls_session
)
3576 struct iscsi_session
*sess
;
3577 struct ddb_entry
*ddb_entry
;
3578 struct scsi_qla_host
*ha
;
3580 sess
= cls_session
->dd_data
;
3581 ddb_entry
= sess
->dd_data
;
3583 if (!iscsi_is_session_online(cls_session
)) {
3584 if (ddb_entry
->fw_ddb_device_state
== DDB_DS_SESSION_ACTIVE
) {
3585 ql4_printk(KERN_INFO
, ha
, "scsi%ld: %s: ddb[%d]"
3586 " unblock session\n", ha
->host_no
, __func__
,
3587 ddb_entry
->fw_ddb_index
);
3588 iscsi_unblock_session(ddb_entry
->sess
);
3590 /* Trigger relogin */
3591 if (ddb_entry
->ddb_type
== FLASH_DDB
) {
3592 if (!(test_bit(DF_RELOGIN
, &ddb_entry
->flags
) ||
3593 test_bit(DF_DISABLE_RELOGIN
,
3594 &ddb_entry
->flags
)))
3595 qla4xxx_arm_relogin_timer(ddb_entry
);
3597 iscsi_session_failure(cls_session
->dd_data
,
3598 ISCSI_ERR_CONN_FAILED
);
3603 int qla4xxx_unblock_flash_ddb(struct iscsi_cls_session
*cls_session
)
3605 struct iscsi_session
*sess
;
3606 struct ddb_entry
*ddb_entry
;
3607 struct scsi_qla_host
*ha
;
3609 sess
= cls_session
->dd_data
;
3610 ddb_entry
= sess
->dd_data
;
3612 ql4_printk(KERN_INFO
, ha
, "scsi%ld: %s: ddb[%d]"
3613 " unblock session\n", ha
->host_no
, __func__
,
3614 ddb_entry
->fw_ddb_index
);
3616 iscsi_unblock_session(ddb_entry
->sess
);
3618 /* Start scan target */
3619 if (test_bit(AF_ONLINE
, &ha
->flags
)) {
3620 ql4_printk(KERN_INFO
, ha
, "scsi%ld: %s: ddb[%d]"
3621 " start scan\n", ha
->host_no
, __func__
,
3622 ddb_entry
->fw_ddb_index
);
3623 scsi_queue_work(ha
->host
, &ddb_entry
->sess
->scan_work
);
3628 int qla4xxx_unblock_ddb(struct iscsi_cls_session
*cls_session
)
3630 struct iscsi_session
*sess
;
3631 struct ddb_entry
*ddb_entry
;
3632 struct scsi_qla_host
*ha
;
3633 int status
= QLA_SUCCESS
;
3635 sess
= cls_session
->dd_data
;
3636 ddb_entry
= sess
->dd_data
;
3638 ql4_printk(KERN_INFO
, ha
, "scsi%ld: %s: ddb[%d]"
3639 " unblock user space session\n", ha
->host_no
, __func__
,
3640 ddb_entry
->fw_ddb_index
);
3642 if (!iscsi_is_session_online(cls_session
)) {
3643 iscsi_conn_start(ddb_entry
->conn
);
3644 iscsi_conn_login_event(ddb_entry
->conn
,
3645 ISCSI_CONN_STATE_LOGGED_IN
);
3647 ql4_printk(KERN_INFO
, ha
,
3648 "scsi%ld: %s: ddb[%d] session [%d] already logged in\n",
3649 ha
->host_no
, __func__
, ddb_entry
->fw_ddb_index
,
3657 static void qla4xxx_relogin_all_devices(struct scsi_qla_host
*ha
)
3659 iscsi_host_for_each_session(ha
->host
, qla4xxx_relogin_devices
);
3662 static void qla4xxx_relogin_flash_ddb(struct iscsi_cls_session
*cls_sess
)
3664 uint16_t relogin_timer
;
3665 struct iscsi_session
*sess
;
3666 struct ddb_entry
*ddb_entry
;
3667 struct scsi_qla_host
*ha
;
3669 sess
= cls_sess
->dd_data
;
3670 ddb_entry
= sess
->dd_data
;
3673 relogin_timer
= max(ddb_entry
->default_relogin_timeout
,
3674 (uint16_t)RELOGIN_TOV
);
3675 atomic_set(&ddb_entry
->relogin_timer
, relogin_timer
);
3677 DEBUG2(ql4_printk(KERN_INFO
, ha
,
3678 "scsi%ld: Relogin index [%d]. TOV=%d\n", ha
->host_no
,
3679 ddb_entry
->fw_ddb_index
, relogin_timer
));
3681 qla4xxx_login_flash_ddb(cls_sess
);
3684 static void qla4xxx_dpc_relogin(struct iscsi_cls_session
*cls_sess
)
3686 struct iscsi_session
*sess
;
3687 struct ddb_entry
*ddb_entry
;
3688 struct scsi_qla_host
*ha
;
3690 sess
= cls_sess
->dd_data
;
3691 ddb_entry
= sess
->dd_data
;
3694 if (!(ddb_entry
->ddb_type
== FLASH_DDB
))
3697 if (test_bit(DF_DISABLE_RELOGIN
, &ddb_entry
->flags
))
3700 if (test_and_clear_bit(DF_RELOGIN
, &ddb_entry
->flags
) &&
3701 !iscsi_is_session_online(cls_sess
)) {
3702 DEBUG2(ql4_printk(KERN_INFO
, ha
,
3703 "relogin issued\n"));
3704 qla4xxx_relogin_flash_ddb(cls_sess
);
3708 void qla4xxx_wake_dpc(struct scsi_qla_host
*ha
)
3711 queue_work(ha
->dpc_thread
, &ha
->dpc_work
);
3714 static struct qla4_work_evt
*
3715 qla4xxx_alloc_work(struct scsi_qla_host
*ha
, uint32_t data_size
,
3716 enum qla4_work_type type
)
3718 struct qla4_work_evt
*e
;
3719 uint32_t size
= sizeof(struct qla4_work_evt
) + data_size
;
3721 e
= kzalloc(size
, GFP_ATOMIC
);
3725 INIT_LIST_HEAD(&e
->list
);
3730 static void qla4xxx_post_work(struct scsi_qla_host
*ha
,
3731 struct qla4_work_evt
*e
)
3733 unsigned long flags
;
3735 spin_lock_irqsave(&ha
->work_lock
, flags
);
3736 list_add_tail(&e
->list
, &ha
->work_list
);
3737 spin_unlock_irqrestore(&ha
->work_lock
, flags
);
3738 qla4xxx_wake_dpc(ha
);
3741 int qla4xxx_post_aen_work(struct scsi_qla_host
*ha
,
3742 enum iscsi_host_event_code aen_code
,
3743 uint32_t data_size
, uint8_t *data
)
3745 struct qla4_work_evt
*e
;
3747 e
= qla4xxx_alloc_work(ha
, data_size
, QLA4_EVENT_AEN
);
3751 e
->u
.aen
.code
= aen_code
;
3752 e
->u
.aen
.data_size
= data_size
;
3753 memcpy(e
->u
.aen
.data
, data
, data_size
);
3755 qla4xxx_post_work(ha
, e
);
3760 int qla4xxx_post_ping_evt_work(struct scsi_qla_host
*ha
,
3761 uint32_t status
, uint32_t pid
,
3762 uint32_t data_size
, uint8_t *data
)
3764 struct qla4_work_evt
*e
;
3766 e
= qla4xxx_alloc_work(ha
, data_size
, QLA4_EVENT_PING_STATUS
);
3770 e
->u
.ping
.status
= status
;
3771 e
->u
.ping
.pid
= pid
;
3772 e
->u
.ping
.data_size
= data_size
;
3773 memcpy(e
->u
.ping
.data
, data
, data_size
);
3775 qla4xxx_post_work(ha
, e
);
3780 static void qla4xxx_do_work(struct scsi_qla_host
*ha
)
3782 struct qla4_work_evt
*e
, *tmp
;
3783 unsigned long flags
;
3786 spin_lock_irqsave(&ha
->work_lock
, flags
);
3787 list_splice_init(&ha
->work_list
, &work
);
3788 spin_unlock_irqrestore(&ha
->work_lock
, flags
);
3790 list_for_each_entry_safe(e
, tmp
, &work
, list
) {
3791 list_del_init(&e
->list
);
3794 case QLA4_EVENT_AEN
:
3795 iscsi_post_host_event(ha
->host_no
,
3796 &qla4xxx_iscsi_transport
,
3801 case QLA4_EVENT_PING_STATUS
:
3802 iscsi_ping_comp_event(ha
->host_no
,
3803 &qla4xxx_iscsi_transport
,
3806 e
->u
.ping
.data_size
,
3810 ql4_printk(KERN_WARNING
, ha
, "event type: 0x%x not "
3811 "supported", e
->type
);
3818 * qla4xxx_do_dpc - dpc routine
3819 * @data: in our case pointer to adapter structure
3821 * This routine is a task that is schedule by the interrupt handler
3822 * to perform the background processing for interrupts. We put it
3823 * on a task queue that is consumed whenever the scheduler runs; that's
3824 * so you can do anything (i.e. put the process to sleep etc). In fact,
3825 * the mid-level tries to sleep when it reaches the driver threshold
3826 * "host->can_queue". This can cause a panic if we were in our interrupt code.
3828 static void qla4xxx_do_dpc(struct work_struct
*work
)
3830 struct scsi_qla_host
*ha
=
3831 container_of(work
, struct scsi_qla_host
, dpc_work
);
3832 int status
= QLA_ERROR
;
3834 DEBUG2(printk("scsi%ld: %s: DPC handler waking up."
3835 "flags = 0x%08lx, dpc_flags = 0x%08lx\n",
3836 ha
->host_no
, __func__
, ha
->flags
, ha
->dpc_flags
))
3838 /* Initialization not yet finished. Don't do anything yet. */
3839 if (!test_bit(AF_INIT_DONE
, &ha
->flags
))
3842 if (test_bit(AF_EEH_BUSY
, &ha
->flags
)) {
3843 DEBUG2(printk(KERN_INFO
"scsi%ld: %s: flags = %lx\n",
3844 ha
->host_no
, __func__
, ha
->flags
));
3848 /* post events to application */
3849 qla4xxx_do_work(ha
);
3851 if (is_qla80XX(ha
)) {
3852 if (test_bit(DPC_HA_UNRECOVERABLE
, &ha
->dpc_flags
)) {
3853 if (is_qla8032(ha
) || is_qla8042(ha
)) {
3854 ql4_printk(KERN_INFO
, ha
, "%s: disabling pause transmit on port 0 & 1.\n",
3856 /* disable pause frame for ISP83xx */
3857 qla4_83xx_disable_pause(ha
);
3860 ha
->isp_ops
->idc_lock(ha
);
3861 qla4_8xxx_wr_direct(ha
, QLA8XXX_CRB_DEV_STATE
,
3862 QLA8XXX_DEV_FAILED
);
3863 ha
->isp_ops
->idc_unlock(ha
);
3864 ql4_printk(KERN_INFO
, ha
, "HW State: FAILED\n");
3865 qla4_8xxx_device_state_handler(ha
);
3868 if (test_bit(DPC_POST_IDC_ACK
, &ha
->dpc_flags
)) {
3869 if (is_qla8042(ha
)) {
3870 if (ha
->idc_info
.info2
&
3871 ENABLE_INTERNAL_LOOPBACK
) {
3872 ql4_printk(KERN_INFO
, ha
, "%s: Disabling ACB\n",
3874 status
= qla4_84xx_config_acb(ha
,
3875 ACB_CONFIG_DISABLE
);
3876 if (status
!= QLA_SUCCESS
) {
3877 ql4_printk(KERN_INFO
, ha
, "%s: ACB config failed\n",
3882 qla4_83xx_post_idc_ack(ha
);
3883 clear_bit(DPC_POST_IDC_ACK
, &ha
->dpc_flags
);
3886 if (is_qla8042(ha
) &&
3887 test_bit(DPC_RESTORE_ACB
, &ha
->dpc_flags
)) {
3888 ql4_printk(KERN_INFO
, ha
, "%s: Restoring ACB\n",
3890 if (qla4_84xx_config_acb(ha
, ACB_CONFIG_SET
) !=
3892 ql4_printk(KERN_INFO
, ha
, "%s: ACB config failed ",
3895 clear_bit(DPC_RESTORE_ACB
, &ha
->dpc_flags
);
3898 if (test_and_clear_bit(DPC_HA_NEED_QUIESCENT
, &ha
->dpc_flags
)) {
3899 qla4_8xxx_need_qsnt_handler(ha
);
3903 if (!test_bit(DPC_RESET_ACTIVE
, &ha
->dpc_flags
) &&
3904 (test_bit(DPC_RESET_HA
, &ha
->dpc_flags
) ||
3905 test_bit(DPC_RESET_HA_INTR
, &ha
->dpc_flags
) ||
3906 test_bit(DPC_RESET_HA_FW_CONTEXT
, &ha
->dpc_flags
))) {
3907 if ((is_qla8022(ha
) && ql4xdontresethba
) ||
3908 ((is_qla8032(ha
) || is_qla8042(ha
)) &&
3909 qla4_83xx_idc_dontreset(ha
))) {
3910 DEBUG2(printk("scsi%ld: %s: Don't Reset HBA\n",
3911 ha
->host_no
, __func__
));
3912 clear_bit(DPC_RESET_HA
, &ha
->dpc_flags
);
3913 clear_bit(DPC_RESET_HA_INTR
, &ha
->dpc_flags
);
3914 clear_bit(DPC_RESET_HA_FW_CONTEXT
, &ha
->dpc_flags
);
3915 goto dpc_post_reset_ha
;
3917 if (test_bit(DPC_RESET_HA_FW_CONTEXT
, &ha
->dpc_flags
) ||
3918 test_bit(DPC_RESET_HA
, &ha
->dpc_flags
))
3919 qla4xxx_recover_adapter(ha
);
3921 if (test_bit(DPC_RESET_HA_INTR
, &ha
->dpc_flags
)) {
3922 uint8_t wait_time
= RESET_INTR_TOV
;
3924 while ((readw(&ha
->reg
->ctrl_status
) &
3925 (CSR_SOFT_RESET
| CSR_FORCE_SOFT_RESET
)) != 0) {
3926 if (--wait_time
== 0)
3931 DEBUG2(printk("scsi%ld: %s: SR|FSR "
3932 "bit not cleared-- resetting\n",
3933 ha
->host_no
, __func__
));
3934 qla4xxx_abort_active_cmds(ha
, DID_RESET
<< 16);
3935 if (ql4xxx_lock_drvr_wait(ha
) == QLA_SUCCESS
) {
3936 qla4xxx_process_aen(ha
, FLUSH_DDB_CHANGED_AENS
);
3937 status
= qla4xxx_recover_adapter(ha
);
3939 clear_bit(DPC_RESET_HA_INTR
, &ha
->dpc_flags
);
3940 if (status
== QLA_SUCCESS
)
3941 ha
->isp_ops
->enable_intrs(ha
);
3946 /* ---- process AEN? --- */
3947 if (test_and_clear_bit(DPC_AEN
, &ha
->dpc_flags
))
3948 qla4xxx_process_aen(ha
, PROCESS_ALL_AENS
);
3950 /* ---- Get DHCP IP Address? --- */
3951 if (test_and_clear_bit(DPC_GET_DHCP_IP_ADDR
, &ha
->dpc_flags
))
3952 qla4xxx_get_dhcp_ip_address(ha
);
3954 /* ---- relogin device? --- */
3955 if (adapter_up(ha
) &&
3956 test_and_clear_bit(DPC_RELOGIN_DEVICE
, &ha
->dpc_flags
)) {
3957 iscsi_host_for_each_session(ha
->host
, qla4xxx_dpc_relogin
);
3960 /* ---- link change? --- */
3961 if (!test_bit(AF_LOOPBACK
, &ha
->flags
) &&
3962 test_and_clear_bit(DPC_LINK_CHANGED
, &ha
->dpc_flags
)) {
3963 if (!test_bit(AF_LINK_UP
, &ha
->flags
)) {
3964 /* ---- link down? --- */
3965 qla4xxx_mark_all_devices_missing(ha
);
3967 /* ---- link up? --- *
3968 * F/W will auto login to all devices ONLY ONCE after
3969 * link up during driver initialization and runtime
3970 * fatal error recovery. Therefore, the driver must
3971 * manually relogin to devices when recovering from
3972 * connection failures, logouts, expired KATO, etc. */
3973 if (test_and_clear_bit(AF_BUILD_DDB_LIST
, &ha
->flags
)) {
3974 qla4xxx_build_ddb_list(ha
, ha
->is_reset
);
3975 iscsi_host_for_each_session(ha
->host
,
3976 qla4xxx_login_flash_ddb
);
3978 qla4xxx_relogin_all_devices(ha
);
3984 * qla4xxx_free_adapter - release the adapter
3985 * @ha: pointer to adapter structure
3987 static void qla4xxx_free_adapter(struct scsi_qla_host
*ha
)
3989 qla4xxx_abort_active_cmds(ha
, DID_NO_CONNECT
<< 16);
3991 /* Turn-off interrupts on the card. */
3992 ha
->isp_ops
->disable_intrs(ha
);
3994 if (is_qla40XX(ha
)) {
3995 writel(set_rmask(CSR_SCSI_PROCESSOR_INTR
),
3996 &ha
->reg
->ctrl_status
);
3997 readl(&ha
->reg
->ctrl_status
);
3998 } else if (is_qla8022(ha
)) {
3999 writel(0, &ha
->qla4_82xx_reg
->host_int
);
4000 readl(&ha
->qla4_82xx_reg
->host_int
);
4001 } else if (is_qla8032(ha
) || is_qla8042(ha
)) {
4002 writel(0, &ha
->qla4_83xx_reg
->risc_intr
);
4003 readl(&ha
->qla4_83xx_reg
->risc_intr
);
4006 /* Remove timer thread, if present */
4007 if (ha
->timer_active
)
4008 qla4xxx_stop_timer(ha
);
4010 /* Kill the kernel thread for this host */
4012 destroy_workqueue(ha
->dpc_thread
);
4014 /* Kill the kernel thread for this host */
4016 destroy_workqueue(ha
->task_wq
);
4018 /* Put firmware in known state */
4019 ha
->isp_ops
->reset_firmware(ha
);
4021 if (is_qla80XX(ha
)) {
4022 ha
->isp_ops
->idc_lock(ha
);
4023 qla4_8xxx_clear_drv_active(ha
);
4024 ha
->isp_ops
->idc_unlock(ha
);
4027 /* Detach interrupts */
4028 qla4xxx_free_irqs(ha
);
4030 /* free extra memory */
4031 qla4xxx_mem_free(ha
);
4034 int qla4_8xxx_iospace_config(struct scsi_qla_host
*ha
)
4037 unsigned long mem_base
, mem_len
, db_base
, db_len
;
4038 struct pci_dev
*pdev
= ha
->pdev
;
4040 status
= pci_request_regions(pdev
, DRIVER_NAME
);
4043 "scsi(%ld) Failed to reserve PIO regions (%s) "
4044 "status=%d\n", ha
->host_no
, pci_name(pdev
), status
);
4045 goto iospace_error_exit
;
4048 DEBUG2(printk(KERN_INFO
"%s: revision-id=%d\n",
4049 __func__
, pdev
->revision
));
4050 ha
->revision_id
= pdev
->revision
;
4052 /* remap phys address */
4053 mem_base
= pci_resource_start(pdev
, 0); /* 0 is for BAR 0 */
4054 mem_len
= pci_resource_len(pdev
, 0);
4055 DEBUG2(printk(KERN_INFO
"%s: ioremap from %lx a size of %lx\n",
4056 __func__
, mem_base
, mem_len
));
4058 /* mapping of pcibase pointer */
4059 ha
->nx_pcibase
= (unsigned long)ioremap(mem_base
, mem_len
);
4060 if (!ha
->nx_pcibase
) {
4062 "cannot remap MMIO (%s), aborting\n", pci_name(pdev
));
4063 pci_release_regions(ha
->pdev
);
4064 goto iospace_error_exit
;
4067 /* Mapping of IO base pointer, door bell read and write pointer */
4069 /* mapping of IO base pointer */
4070 if (is_qla8022(ha
)) {
4071 ha
->qla4_82xx_reg
= (struct device_reg_82xx __iomem
*)
4072 ((uint8_t *)ha
->nx_pcibase
+ 0xbc000 +
4073 (ha
->pdev
->devfn
<< 11));
4074 ha
->nx_db_wr_ptr
= (ha
->pdev
->devfn
== 4 ? QLA82XX_CAM_RAM_DB1
:
4075 QLA82XX_CAM_RAM_DB2
);
4076 } else if (is_qla8032(ha
) || is_qla8042(ha
)) {
4077 ha
->qla4_83xx_reg
= (struct device_reg_83xx __iomem
*)
4078 ((uint8_t *)ha
->nx_pcibase
);
4081 db_base
= pci_resource_start(pdev
, 4); /* doorbell is on bar 4 */
4082 db_len
= pci_resource_len(pdev
, 4);
4090 * qla4xxx_iospace_config - maps registers
4091 * @ha: pointer to adapter structure
4093 * This routines maps HBA's registers from the pci address space
4094 * into the kernel virtual address space for memory mapped i/o.
4096 int qla4xxx_iospace_config(struct scsi_qla_host
*ha
)
4098 unsigned long pio
, pio_len
, pio_flags
;
4099 unsigned long mmio
, mmio_len
, mmio_flags
;
4101 pio
= pci_resource_start(ha
->pdev
, 0);
4102 pio_len
= pci_resource_len(ha
->pdev
, 0);
4103 pio_flags
= pci_resource_flags(ha
->pdev
, 0);
4104 if (pio_flags
& IORESOURCE_IO
) {
4105 if (pio_len
< MIN_IOBASE_LEN
) {
4106 ql4_printk(KERN_WARNING
, ha
,
4107 "Invalid PCI I/O region size\n");
4111 ql4_printk(KERN_WARNING
, ha
, "region #0 not a PIO resource\n");
4115 /* Use MMIO operations for all accesses. */
4116 mmio
= pci_resource_start(ha
->pdev
, 1);
4117 mmio_len
= pci_resource_len(ha
->pdev
, 1);
4118 mmio_flags
= pci_resource_flags(ha
->pdev
, 1);
4120 if (!(mmio_flags
& IORESOURCE_MEM
)) {
4121 ql4_printk(KERN_ERR
, ha
,
4122 "region #0 not an MMIO resource, aborting\n");
4124 goto iospace_error_exit
;
4127 if (mmio_len
< MIN_IOBASE_LEN
) {
4128 ql4_printk(KERN_ERR
, ha
,
4129 "Invalid PCI mem region size, aborting\n");
4130 goto iospace_error_exit
;
4133 if (pci_request_regions(ha
->pdev
, DRIVER_NAME
)) {
4134 ql4_printk(KERN_WARNING
, ha
,
4135 "Failed to reserve PIO/MMIO regions\n");
4137 goto iospace_error_exit
;
4140 ha
->pio_address
= pio
;
4141 ha
->pio_length
= pio_len
;
4142 ha
->reg
= ioremap(mmio
, MIN_IOBASE_LEN
);
4144 ql4_printk(KERN_ERR
, ha
,
4145 "cannot remap MMIO, aborting\n");
4147 goto iospace_error_exit
;
4156 static struct isp_operations qla4xxx_isp_ops
= {
4157 .iospace_config
= qla4xxx_iospace_config
,
4158 .pci_config
= qla4xxx_pci_config
,
4159 .disable_intrs
= qla4xxx_disable_intrs
,
4160 .enable_intrs
= qla4xxx_enable_intrs
,
4161 .start_firmware
= qla4xxx_start_firmware
,
4162 .intr_handler
= qla4xxx_intr_handler
,
4163 .interrupt_service_routine
= qla4xxx_interrupt_service_routine
,
4164 .reset_chip
= qla4xxx_soft_reset
,
4165 .reset_firmware
= qla4xxx_hw_reset
,
4166 .queue_iocb
= qla4xxx_queue_iocb
,
4167 .complete_iocb
= qla4xxx_complete_iocb
,
4168 .rd_shdw_req_q_out
= qla4xxx_rd_shdw_req_q_out
,
4169 .rd_shdw_rsp_q_in
= qla4xxx_rd_shdw_rsp_q_in
,
4170 .get_sys_info
= qla4xxx_get_sys_info
,
4171 .queue_mailbox_command
= qla4xxx_queue_mbox_cmd
,
4172 .process_mailbox_interrupt
= qla4xxx_process_mbox_intr
,
4175 static struct isp_operations qla4_82xx_isp_ops
= {
4176 .iospace_config
= qla4_8xxx_iospace_config
,
4177 .pci_config
= qla4_8xxx_pci_config
,
4178 .disable_intrs
= qla4_82xx_disable_intrs
,
4179 .enable_intrs
= qla4_82xx_enable_intrs
,
4180 .start_firmware
= qla4_8xxx_load_risc
,
4181 .restart_firmware
= qla4_82xx_try_start_fw
,
4182 .intr_handler
= qla4_82xx_intr_handler
,
4183 .interrupt_service_routine
= qla4_82xx_interrupt_service_routine
,
4184 .need_reset
= qla4_8xxx_need_reset
,
4185 .reset_chip
= qla4_82xx_isp_reset
,
4186 .reset_firmware
= qla4_8xxx_stop_firmware
,
4187 .queue_iocb
= qla4_82xx_queue_iocb
,
4188 .complete_iocb
= qla4_82xx_complete_iocb
,
4189 .rd_shdw_req_q_out
= qla4_82xx_rd_shdw_req_q_out
,
4190 .rd_shdw_rsp_q_in
= qla4_82xx_rd_shdw_rsp_q_in
,
4191 .get_sys_info
= qla4_8xxx_get_sys_info
,
4192 .rd_reg_direct
= qla4_82xx_rd_32
,
4193 .wr_reg_direct
= qla4_82xx_wr_32
,
4194 .rd_reg_indirect
= qla4_82xx_md_rd_32
,
4195 .wr_reg_indirect
= qla4_82xx_md_wr_32
,
4196 .idc_lock
= qla4_82xx_idc_lock
,
4197 .idc_unlock
= qla4_82xx_idc_unlock
,
4198 .rom_lock_recovery
= qla4_82xx_rom_lock_recovery
,
4199 .queue_mailbox_command
= qla4_82xx_queue_mbox_cmd
,
4200 .process_mailbox_interrupt
= qla4_82xx_process_mbox_intr
,
4203 static struct isp_operations qla4_83xx_isp_ops
= {
4204 .iospace_config
= qla4_8xxx_iospace_config
,
4205 .pci_config
= qla4_8xxx_pci_config
,
4206 .disable_intrs
= qla4_83xx_disable_intrs
,
4207 .enable_intrs
= qla4_83xx_enable_intrs
,
4208 .start_firmware
= qla4_8xxx_load_risc
,
4209 .restart_firmware
= qla4_83xx_start_firmware
,
4210 .intr_handler
= qla4_83xx_intr_handler
,
4211 .interrupt_service_routine
= qla4_83xx_interrupt_service_routine
,
4212 .need_reset
= qla4_8xxx_need_reset
,
4213 .reset_chip
= qla4_83xx_isp_reset
,
4214 .reset_firmware
= qla4_8xxx_stop_firmware
,
4215 .queue_iocb
= qla4_83xx_queue_iocb
,
4216 .complete_iocb
= qla4_83xx_complete_iocb
,
4217 .rd_shdw_req_q_out
= qla4xxx_rd_shdw_req_q_out
,
4218 .rd_shdw_rsp_q_in
= qla4xxx_rd_shdw_rsp_q_in
,
4219 .get_sys_info
= qla4_8xxx_get_sys_info
,
4220 .rd_reg_direct
= qla4_83xx_rd_reg
,
4221 .wr_reg_direct
= qla4_83xx_wr_reg
,
4222 .rd_reg_indirect
= qla4_83xx_rd_reg_indirect
,
4223 .wr_reg_indirect
= qla4_83xx_wr_reg_indirect
,
4224 .idc_lock
= qla4_83xx_drv_lock
,
4225 .idc_unlock
= qla4_83xx_drv_unlock
,
4226 .rom_lock_recovery
= qla4_83xx_rom_lock_recovery
,
4227 .queue_mailbox_command
= qla4_83xx_queue_mbox_cmd
,
4228 .process_mailbox_interrupt
= qla4_83xx_process_mbox_intr
,
4231 uint16_t qla4xxx_rd_shdw_req_q_out(struct scsi_qla_host
*ha
)
4233 return (uint16_t)le32_to_cpu(ha
->shadow_regs
->req_q_out
);
4236 uint16_t qla4_82xx_rd_shdw_req_q_out(struct scsi_qla_host
*ha
)
4238 return (uint16_t)le32_to_cpu(readl(&ha
->qla4_82xx_reg
->req_q_out
));
4241 uint16_t qla4xxx_rd_shdw_rsp_q_in(struct scsi_qla_host
*ha
)
4243 return (uint16_t)le32_to_cpu(ha
->shadow_regs
->rsp_q_in
);
4246 uint16_t qla4_82xx_rd_shdw_rsp_q_in(struct scsi_qla_host
*ha
)
4248 return (uint16_t)le32_to_cpu(readl(&ha
->qla4_82xx_reg
->rsp_q_in
));
4251 static ssize_t
qla4xxx_show_boot_eth_info(void *data
, int type
, char *buf
)
4253 struct scsi_qla_host
*ha
= data
;
4258 case ISCSI_BOOT_ETH_FLAGS
:
4259 rc
= sprintf(str
, "%d\n", SYSFS_FLAG_FW_SEL_BOOT
);
4261 case ISCSI_BOOT_ETH_INDEX
:
4262 rc
= sprintf(str
, "0\n");
4264 case ISCSI_BOOT_ETH_MAC
:
4265 rc
= sysfs_format_mac(str
, ha
->my_mac
,
4275 static umode_t
qla4xxx_eth_get_attr_visibility(void *data
, int type
)
4280 case ISCSI_BOOT_ETH_FLAGS
:
4281 case ISCSI_BOOT_ETH_MAC
:
4282 case ISCSI_BOOT_ETH_INDEX
:
4292 static ssize_t
qla4xxx_show_boot_ini_info(void *data
, int type
, char *buf
)
4294 struct scsi_qla_host
*ha
= data
;
4299 case ISCSI_BOOT_INI_INITIATOR_NAME
:
4300 rc
= sprintf(str
, "%s\n", ha
->name_string
);
4309 static umode_t
qla4xxx_ini_get_attr_visibility(void *data
, int type
)
4314 case ISCSI_BOOT_INI_INITIATOR_NAME
:
4325 qla4xxx_show_boot_tgt_info(struct ql4_boot_session_info
*boot_sess
, int type
,
4328 struct ql4_conn_info
*boot_conn
= &boot_sess
->conn_list
[0];
4333 case ISCSI_BOOT_TGT_NAME
:
4334 rc
= sprintf(buf
, "%s\n", (char *)&boot_sess
->target_name
);
4336 case ISCSI_BOOT_TGT_IP_ADDR
:
4337 if (boot_sess
->conn_list
[0].dest_ipaddr
.ip_type
== 0x1)
4338 rc
= sprintf(buf
, "%pI4\n",
4339 &boot_conn
->dest_ipaddr
.ip_address
);
4341 rc
= sprintf(str
, "%pI6\n",
4342 &boot_conn
->dest_ipaddr
.ip_address
);
4344 case ISCSI_BOOT_TGT_PORT
:
4345 rc
= sprintf(str
, "%d\n", boot_conn
->dest_port
);
4347 case ISCSI_BOOT_TGT_CHAP_NAME
:
4348 rc
= sprintf(str
, "%.*s\n",
4349 boot_conn
->chap
.target_chap_name_length
,
4350 (char *)&boot_conn
->chap
.target_chap_name
);
4352 case ISCSI_BOOT_TGT_CHAP_SECRET
:
4353 rc
= sprintf(str
, "%.*s\n",
4354 boot_conn
->chap
.target_secret_length
,
4355 (char *)&boot_conn
->chap
.target_secret
);
4357 case ISCSI_BOOT_TGT_REV_CHAP_NAME
:
4358 rc
= sprintf(str
, "%.*s\n",
4359 boot_conn
->chap
.intr_chap_name_length
,
4360 (char *)&boot_conn
->chap
.intr_chap_name
);
4362 case ISCSI_BOOT_TGT_REV_CHAP_SECRET
:
4363 rc
= sprintf(str
, "%.*s\n",
4364 boot_conn
->chap
.intr_secret_length
,
4365 (char *)&boot_conn
->chap
.intr_secret
);
4367 case ISCSI_BOOT_TGT_FLAGS
:
4368 rc
= sprintf(str
, "%d\n", SYSFS_FLAG_FW_SEL_BOOT
);
4370 case ISCSI_BOOT_TGT_NIC_ASSOC
:
4371 rc
= sprintf(str
, "0\n");
4380 static ssize_t
qla4xxx_show_boot_tgt_pri_info(void *data
, int type
, char *buf
)
4382 struct scsi_qla_host
*ha
= data
;
4383 struct ql4_boot_session_info
*boot_sess
= &(ha
->boot_tgt
.boot_pri_sess
);
4385 return qla4xxx_show_boot_tgt_info(boot_sess
, type
, buf
);
4388 static ssize_t
qla4xxx_show_boot_tgt_sec_info(void *data
, int type
, char *buf
)
4390 struct scsi_qla_host
*ha
= data
;
4391 struct ql4_boot_session_info
*boot_sess
= &(ha
->boot_tgt
.boot_sec_sess
);
4393 return qla4xxx_show_boot_tgt_info(boot_sess
, type
, buf
);
4396 static umode_t
qla4xxx_tgt_get_attr_visibility(void *data
, int type
)
4401 case ISCSI_BOOT_TGT_NAME
:
4402 case ISCSI_BOOT_TGT_IP_ADDR
:
4403 case ISCSI_BOOT_TGT_PORT
:
4404 case ISCSI_BOOT_TGT_CHAP_NAME
:
4405 case ISCSI_BOOT_TGT_CHAP_SECRET
:
4406 case ISCSI_BOOT_TGT_REV_CHAP_NAME
:
4407 case ISCSI_BOOT_TGT_REV_CHAP_SECRET
:
4408 case ISCSI_BOOT_TGT_NIC_ASSOC
:
4409 case ISCSI_BOOT_TGT_FLAGS
:
4419 static void qla4xxx_boot_release(void *data
)
4421 struct scsi_qla_host
*ha
= data
;
4423 scsi_host_put(ha
->host
);
4426 static int get_fw_boot_info(struct scsi_qla_host
*ha
, uint16_t ddb_index
[])
4429 uint32_t addr
, pri_addr
, sec_addr
;
4433 uint8_t *buf
= NULL
;
4434 size_t size
= 13 * sizeof(uint8_t);
4435 int ret
= QLA_SUCCESS
;
4437 func_num
= PCI_FUNC(ha
->pdev
->devfn
);
4439 ql4_printk(KERN_INFO
, ha
, "%s: Get FW boot info for 0x%x func %d\n",
4440 __func__
, ha
->pdev
->device
, func_num
);
4442 if (is_qla40XX(ha
)) {
4443 if (func_num
== 1) {
4444 addr
= NVRAM_PORT0_BOOT_MODE
;
4445 pri_addr
= NVRAM_PORT0_BOOT_PRI_TGT
;
4446 sec_addr
= NVRAM_PORT0_BOOT_SEC_TGT
;
4447 } else if (func_num
== 3) {
4448 addr
= NVRAM_PORT1_BOOT_MODE
;
4449 pri_addr
= NVRAM_PORT1_BOOT_PRI_TGT
;
4450 sec_addr
= NVRAM_PORT1_BOOT_SEC_TGT
;
4453 goto exit_boot_info
;
4456 /* Check Boot Mode */
4457 val
= rd_nvram_byte(ha
, addr
);
4458 if (!(val
& 0x07)) {
4459 DEBUG2(ql4_printk(KERN_INFO
, ha
, "%s: Adapter boot "
4460 "options : 0x%x\n", __func__
, val
));
4462 goto exit_boot_info
;
4465 /* get primary valid target index */
4466 val
= rd_nvram_byte(ha
, pri_addr
);
4468 ddb_index
[0] = (val
& 0x7f);
4470 /* get secondary valid target index */
4471 val
= rd_nvram_byte(ha
, sec_addr
);
4473 ddb_index
[1] = (val
& 0x7f);
4475 } else if (is_qla80XX(ha
)) {
4476 buf
= dma_alloc_coherent(&ha
->pdev
->dev
, size
,
4477 &buf_dma
, GFP_KERNEL
);
4479 DEBUG2(ql4_printk(KERN_ERR
, ha
,
4480 "%s: Unable to allocate dma buffer\n",
4483 goto exit_boot_info
;
4486 if (ha
->port_num
== 0)
4487 offset
= BOOT_PARAM_OFFSET_PORT0
;
4488 else if (ha
->port_num
== 1)
4489 offset
= BOOT_PARAM_OFFSET_PORT1
;
4492 goto exit_boot_info_free
;
4494 addr
= FLASH_RAW_ACCESS_ADDR
+ (ha
->hw
.flt_iscsi_param
* 4) +
4496 if (qla4xxx_get_flash(ha
, buf_dma
, addr
,
4497 13 * sizeof(uint8_t)) != QLA_SUCCESS
) {
4498 DEBUG2(ql4_printk(KERN_ERR
, ha
, "scsi%ld: %s: Get Flash"
4499 " failed\n", ha
->host_no
, __func__
));
4501 goto exit_boot_info_free
;
4503 /* Check Boot Mode */
4504 if (!(buf
[1] & 0x07)) {
4505 DEBUG2(ql4_printk(KERN_INFO
, ha
, "Firmware boot options"
4506 " : 0x%x\n", buf
[1]));
4508 goto exit_boot_info_free
;
4511 /* get primary valid target index */
4513 ddb_index
[0] = buf
[2] & 0x7f;
4515 /* get secondary valid target index */
4516 if (buf
[11] & BIT_7
)
4517 ddb_index
[1] = buf
[11] & 0x7f;
4520 goto exit_boot_info
;
4523 DEBUG2(ql4_printk(KERN_INFO
, ha
, "%s: Primary target ID %d, Secondary"
4524 " target ID %d\n", __func__
, ddb_index
[0],
4527 exit_boot_info_free
:
4528 dma_free_coherent(&ha
->pdev
->dev
, size
, buf
, buf_dma
);
4530 ha
->pri_ddb_idx
= ddb_index
[0];
4531 ha
->sec_ddb_idx
= ddb_index
[1];
4536 * qla4xxx_get_bidi_chap - Get a BIDI CHAP user and password
4537 * @ha: pointer to adapter structure
4538 * @username: CHAP username to be returned
4539 * @password: CHAP password to be returned
4541 * If a boot entry has BIDI CHAP enabled then we need to set the BIDI CHAP
4542 * user and password in the sysfs entry in /sys/firmware/iscsi_boot#/.
4543 * So from the CHAP cache find the first BIDI CHAP entry and set it
4544 * to the boot record in sysfs.
4546 static int qla4xxx_get_bidi_chap(struct scsi_qla_host
*ha
, char *username
,
4549 int i
, ret
= -EINVAL
;
4550 int max_chap_entries
= 0;
4551 struct ql4_chap_table
*chap_table
;
4554 max_chap_entries
= (ha
->hw
.flt_chap_size
/ 2) /
4555 sizeof(struct ql4_chap_table
);
4557 max_chap_entries
= MAX_CHAP_ENTRIES_40XX
;
4559 if (!ha
->chap_list
) {
4560 ql4_printk(KERN_ERR
, ha
, "Do not have CHAP table cache\n");
4564 mutex_lock(&ha
->chap_sem
);
4565 for (i
= 0; i
< max_chap_entries
; i
++) {
4566 chap_table
= (struct ql4_chap_table
*)ha
->chap_list
+ i
;
4567 if (chap_table
->cookie
!=
4568 __constant_cpu_to_le16(CHAP_VALID_COOKIE
)) {
4572 if (chap_table
->flags
& BIT_7
) /* local */
4575 if (!(chap_table
->flags
& BIT_6
)) /* Not BIDI */
4578 strncpy(password
, chap_table
->secret
, QL4_CHAP_MAX_SECRET_LEN
);
4579 strncpy(username
, chap_table
->name
, QL4_CHAP_MAX_NAME_LEN
);
4583 mutex_unlock(&ha
->chap_sem
);
4589 static int qla4xxx_get_boot_target(struct scsi_qla_host
*ha
,
4590 struct ql4_boot_session_info
*boot_sess
,
4593 struct ql4_conn_info
*boot_conn
= &boot_sess
->conn_list
[0];
4594 struct dev_db_entry
*fw_ddb_entry
;
4595 dma_addr_t fw_ddb_entry_dma
;
4598 int ret
= QLA_SUCCESS
;
4600 fw_ddb_entry
= dma_alloc_coherent(&ha
->pdev
->dev
, sizeof(*fw_ddb_entry
),
4601 &fw_ddb_entry_dma
, GFP_KERNEL
);
4602 if (!fw_ddb_entry
) {
4603 DEBUG2(ql4_printk(KERN_ERR
, ha
,
4604 "%s: Unable to allocate dma buffer.\n",
4610 if (qla4xxx_bootdb_by_index(ha
, fw_ddb_entry
,
4611 fw_ddb_entry_dma
, ddb_index
)) {
4612 DEBUG2(ql4_printk(KERN_INFO
, ha
, "%s: No Flash DDB found at "
4613 "index [%d]\n", __func__
, ddb_index
));
4615 goto exit_boot_target
;
4618 /* Update target name and IP from DDB */
4619 memcpy(boot_sess
->target_name
, fw_ddb_entry
->iscsi_name
,
4620 min(sizeof(boot_sess
->target_name
),
4621 sizeof(fw_ddb_entry
->iscsi_name
)));
4623 options
= le16_to_cpu(fw_ddb_entry
->options
);
4624 if (options
& DDB_OPT_IPV6_DEVICE
) {
4625 memcpy(&boot_conn
->dest_ipaddr
.ip_address
,
4626 &fw_ddb_entry
->ip_addr
[0], IPv6_ADDR_LEN
);
4628 boot_conn
->dest_ipaddr
.ip_type
= 0x1;
4629 memcpy(&boot_conn
->dest_ipaddr
.ip_address
,
4630 &fw_ddb_entry
->ip_addr
[0], IP_ADDR_LEN
);
4633 boot_conn
->dest_port
= le16_to_cpu(fw_ddb_entry
->port
);
4635 /* update chap information */
4636 idx
= __le16_to_cpu(fw_ddb_entry
->chap_tbl_idx
);
4638 if (BIT_7
& le16_to_cpu(fw_ddb_entry
->iscsi_options
)) {
4640 DEBUG2(ql4_printk(KERN_INFO
, ha
, "Setting chap\n"));
4642 ret
= qla4xxx_get_chap(ha
, (char *)&boot_conn
->chap
.
4644 (char *)&boot_conn
->chap
.target_secret
,
4647 ql4_printk(KERN_ERR
, ha
, "Failed to set chap\n");
4649 goto exit_boot_target
;
4652 boot_conn
->chap
.target_chap_name_length
= QL4_CHAP_MAX_NAME_LEN
;
4653 boot_conn
->chap
.target_secret_length
= QL4_CHAP_MAX_SECRET_LEN
;
4656 if (BIT_4
& le16_to_cpu(fw_ddb_entry
->iscsi_options
)) {
4658 DEBUG2(ql4_printk(KERN_INFO
, ha
, "Setting BIDI chap\n"));
4660 ret
= qla4xxx_get_bidi_chap(ha
,
4661 (char *)&boot_conn
->chap
.intr_chap_name
,
4662 (char *)&boot_conn
->chap
.intr_secret
);
4665 ql4_printk(KERN_ERR
, ha
, "Failed to set BIDI chap\n");
4667 goto exit_boot_target
;
4670 boot_conn
->chap
.intr_chap_name_length
= QL4_CHAP_MAX_NAME_LEN
;
4671 boot_conn
->chap
.intr_secret_length
= QL4_CHAP_MAX_SECRET_LEN
;
4675 dma_free_coherent(&ha
->pdev
->dev
, sizeof(*fw_ddb_entry
),
4676 fw_ddb_entry
, fw_ddb_entry_dma
);
4680 static int qla4xxx_get_boot_info(struct scsi_qla_host
*ha
)
4682 uint16_t ddb_index
[2];
4683 int ret
= QLA_ERROR
;
4686 memset(ddb_index
, 0, sizeof(ddb_index
));
4687 ddb_index
[0] = 0xffff;
4688 ddb_index
[1] = 0xffff;
4689 ret
= get_fw_boot_info(ha
, ddb_index
);
4690 if (ret
!= QLA_SUCCESS
) {
4691 DEBUG2(ql4_printk(KERN_INFO
, ha
,
4692 "%s: No boot target configured.\n", __func__
));
4696 if (ql4xdisablesysfsboot
)
4699 if (ddb_index
[0] == 0xffff)
4702 rval
= qla4xxx_get_boot_target(ha
, &(ha
->boot_tgt
.boot_pri_sess
),
4704 if (rval
!= QLA_SUCCESS
) {
4705 DEBUG2(ql4_printk(KERN_INFO
, ha
, "%s: Primary boot target not "
4706 "configured\n", __func__
));
4711 if (ddb_index
[1] == 0xffff)
4712 goto exit_get_boot_info
;
4714 rval
= qla4xxx_get_boot_target(ha
, &(ha
->boot_tgt
.boot_sec_sess
),
4716 if (rval
!= QLA_SUCCESS
) {
4717 DEBUG2(ql4_printk(KERN_INFO
, ha
, "%s: Secondary boot target not"
4718 " configured\n", __func__
));
4726 static int qla4xxx_setup_boot_info(struct scsi_qla_host
*ha
)
4728 struct iscsi_boot_kobj
*boot_kobj
;
4730 if (qla4xxx_get_boot_info(ha
) != QLA_SUCCESS
)
4733 if (ql4xdisablesysfsboot
) {
4734 ql4_printk(KERN_INFO
, ha
,
4735 "%s: syfsboot disabled - driver will trigger login "
4736 "and publish session for discovery .\n", __func__
);
4741 ha
->boot_kset
= iscsi_boot_create_host_kset(ha
->host
->host_no
);
4745 if (!scsi_host_get(ha
->host
))
4747 boot_kobj
= iscsi_boot_create_target(ha
->boot_kset
, 0, ha
,
4748 qla4xxx_show_boot_tgt_pri_info
,
4749 qla4xxx_tgt_get_attr_visibility
,
4750 qla4xxx_boot_release
);
4754 if (!scsi_host_get(ha
->host
))
4756 boot_kobj
= iscsi_boot_create_target(ha
->boot_kset
, 1, ha
,
4757 qla4xxx_show_boot_tgt_sec_info
,
4758 qla4xxx_tgt_get_attr_visibility
,
4759 qla4xxx_boot_release
);
4763 if (!scsi_host_get(ha
->host
))
4765 boot_kobj
= iscsi_boot_create_initiator(ha
->boot_kset
, 0, ha
,
4766 qla4xxx_show_boot_ini_info
,
4767 qla4xxx_ini_get_attr_visibility
,
4768 qla4xxx_boot_release
);
4772 if (!scsi_host_get(ha
->host
))
4774 boot_kobj
= iscsi_boot_create_ethernet(ha
->boot_kset
, 0, ha
,
4775 qla4xxx_show_boot_eth_info
,
4776 qla4xxx_eth_get_attr_visibility
,
4777 qla4xxx_boot_release
);
4784 scsi_host_put(ha
->host
);
4786 iscsi_boot_destroy_kset(ha
->boot_kset
);
4792 * qla4xxx_create chap_list - Create CHAP list from FLASH
4793 * @ha: pointer to adapter structure
4795 * Read flash and make a list of CHAP entries, during login when a CHAP entry
4796 * is received, it will be checked in this list. If entry exist then the CHAP
4797 * entry index is set in the DDB. If CHAP entry does not exist in this list
4798 * then a new entry is added in FLASH in CHAP table and the index obtained is
4801 static void qla4xxx_create_chap_list(struct scsi_qla_host
*ha
)
4804 uint8_t *chap_flash_data
= NULL
;
4806 dma_addr_t chap_dma
;
4807 uint32_t chap_size
= 0;
4810 chap_size
= MAX_CHAP_ENTRIES_40XX
*
4811 sizeof(struct ql4_chap_table
);
4812 else /* Single region contains CHAP info for both
4813 * ports which is divided into half for each port.
4815 chap_size
= ha
->hw
.flt_chap_size
/ 2;
4817 chap_flash_data
= dma_alloc_coherent(&ha
->pdev
->dev
, chap_size
,
4818 &chap_dma
, GFP_KERNEL
);
4819 if (!chap_flash_data
) {
4820 ql4_printk(KERN_ERR
, ha
, "No memory for chap_flash_data\n");
4824 offset
= FLASH_CHAP_OFFSET
;
4826 offset
= FLASH_RAW_ACCESS_ADDR
+ (ha
->hw
.flt_region_chap
<< 2);
4827 if (ha
->port_num
== 1)
4828 offset
+= chap_size
;
4831 rval
= qla4xxx_get_flash(ha
, chap_dma
, offset
, chap_size
);
4832 if (rval
!= QLA_SUCCESS
)
4833 goto exit_chap_list
;
4835 if (ha
->chap_list
== NULL
)
4836 ha
->chap_list
= vmalloc(chap_size
);
4837 if (ha
->chap_list
== NULL
) {
4838 ql4_printk(KERN_ERR
, ha
, "No memory for ha->chap_list\n");
4839 goto exit_chap_list
;
4842 memcpy(ha
->chap_list
, chap_flash_data
, chap_size
);
4845 dma_free_coherent(&ha
->pdev
->dev
, chap_size
,
4846 chap_flash_data
, chap_dma
);
4849 static void qla4xxx_get_param_ddb(struct ddb_entry
*ddb_entry
,
4850 struct ql4_tuple_ddb
*tddb
)
4852 struct scsi_qla_host
*ha
;
4853 struct iscsi_cls_session
*cls_sess
;
4854 struct iscsi_cls_conn
*cls_conn
;
4855 struct iscsi_session
*sess
;
4856 struct iscsi_conn
*conn
;
4858 DEBUG2(printk(KERN_INFO
"Func: %s\n", __func__
));
4860 cls_sess
= ddb_entry
->sess
;
4861 sess
= cls_sess
->dd_data
;
4862 cls_conn
= ddb_entry
->conn
;
4863 conn
= cls_conn
->dd_data
;
4865 tddb
->tpgt
= sess
->tpgt
;
4866 tddb
->port
= conn
->persistent_port
;
4867 strncpy(tddb
->iscsi_name
, sess
->targetname
, ISCSI_NAME_SIZE
);
4868 strncpy(tddb
->ip_addr
, conn
->persistent_address
, DDB_IPADDR_LEN
);
4871 static void qla4xxx_convert_param_ddb(struct dev_db_entry
*fw_ddb_entry
,
4872 struct ql4_tuple_ddb
*tddb
,
4873 uint8_t *flash_isid
)
4875 uint16_t options
= 0;
4877 tddb
->tpgt
= le32_to_cpu(fw_ddb_entry
->tgt_portal_grp
);
4878 memcpy(&tddb
->iscsi_name
[0], &fw_ddb_entry
->iscsi_name
[0],
4879 min(sizeof(tddb
->iscsi_name
), sizeof(fw_ddb_entry
->iscsi_name
)));
4881 options
= le16_to_cpu(fw_ddb_entry
->options
);
4882 if (options
& DDB_OPT_IPV6_DEVICE
)
4883 sprintf(tddb
->ip_addr
, "%pI6", fw_ddb_entry
->ip_addr
);
4885 sprintf(tddb
->ip_addr
, "%pI4", fw_ddb_entry
->ip_addr
);
4887 tddb
->port
= le16_to_cpu(fw_ddb_entry
->port
);
4889 if (flash_isid
== NULL
)
4890 memcpy(&tddb
->isid
[0], &fw_ddb_entry
->isid
[0],
4891 sizeof(tddb
->isid
));
4893 memcpy(&tddb
->isid
[0], &flash_isid
[0], sizeof(tddb
->isid
));
4896 static int qla4xxx_compare_tuple_ddb(struct scsi_qla_host
*ha
,
4897 struct ql4_tuple_ddb
*old_tddb
,
4898 struct ql4_tuple_ddb
*new_tddb
,
4899 uint8_t is_isid_compare
)
4901 if (strcmp(old_tddb
->iscsi_name
, new_tddb
->iscsi_name
))
4904 if (strcmp(old_tddb
->ip_addr
, new_tddb
->ip_addr
))
4907 if (old_tddb
->port
!= new_tddb
->port
)
4910 /* For multi sessions, driver generates the ISID, so do not compare
4911 * ISID in reset path since it would be a comparison between the
4912 * driver generated ISID and firmware generated ISID. This could
4913 * lead to adding duplicated DDBs in the list as driver generated
4914 * ISID would not match firmware generated ISID.
4916 if (is_isid_compare
) {
4917 DEBUG2(ql4_printk(KERN_INFO
, ha
, "%s: old ISID [%02x%02x%02x"
4918 "%02x%02x%02x] New ISID [%02x%02x%02x%02x%02x%02x]\n",
4919 __func__
, old_tddb
->isid
[5], old_tddb
->isid
[4],
4920 old_tddb
->isid
[3], old_tddb
->isid
[2], old_tddb
->isid
[1],
4921 old_tddb
->isid
[0], new_tddb
->isid
[5], new_tddb
->isid
[4],
4922 new_tddb
->isid
[3], new_tddb
->isid
[2], new_tddb
->isid
[1],
4923 new_tddb
->isid
[0]));
4925 if (memcmp(&old_tddb
->isid
[0], &new_tddb
->isid
[0],
4926 sizeof(old_tddb
->isid
)))
4930 DEBUG2(ql4_printk(KERN_INFO
, ha
,
4931 "Match Found, fw[%d,%d,%s,%s], [%d,%d,%s,%s]",
4932 old_tddb
->port
, old_tddb
->tpgt
, old_tddb
->ip_addr
,
4933 old_tddb
->iscsi_name
, new_tddb
->port
, new_tddb
->tpgt
,
4934 new_tddb
->ip_addr
, new_tddb
->iscsi_name
));
4939 static int qla4xxx_is_session_exists(struct scsi_qla_host
*ha
,
4940 struct dev_db_entry
*fw_ddb_entry
)
4942 struct ddb_entry
*ddb_entry
;
4943 struct ql4_tuple_ddb
*fw_tddb
= NULL
;
4944 struct ql4_tuple_ddb
*tmp_tddb
= NULL
;
4946 int ret
= QLA_ERROR
;
4948 fw_tddb
= vzalloc(sizeof(*fw_tddb
));
4950 DEBUG2(ql4_printk(KERN_WARNING
, ha
,
4951 "Memory Allocation failed.\n"));
4956 tmp_tddb
= vzalloc(sizeof(*tmp_tddb
));
4958 DEBUG2(ql4_printk(KERN_WARNING
, ha
,
4959 "Memory Allocation failed.\n"));
4964 qla4xxx_convert_param_ddb(fw_ddb_entry
, fw_tddb
, NULL
);
4966 for (idx
= 0; idx
< MAX_DDB_ENTRIES
; idx
++) {
4967 ddb_entry
= qla4xxx_lookup_ddb_by_fw_index(ha
, idx
);
4968 if (ddb_entry
== NULL
)
4971 qla4xxx_get_param_ddb(ddb_entry
, tmp_tddb
);
4972 if (!qla4xxx_compare_tuple_ddb(ha
, fw_tddb
, tmp_tddb
, false)) {
4973 ret
= QLA_SUCCESS
; /* found */
4987 * qla4xxx_check_existing_isid - check if target with same isid exist
4989 * @list_nt: list of target
4990 * @isid: isid to check
4992 * This routine return QLA_SUCCESS if target with same isid exist
4994 static int qla4xxx_check_existing_isid(struct list_head
*list_nt
, uint8_t *isid
)
4996 struct qla_ddb_index
*nt_ddb_idx
, *nt_ddb_idx_tmp
;
4997 struct dev_db_entry
*fw_ddb_entry
;
4999 list_for_each_entry_safe(nt_ddb_idx
, nt_ddb_idx_tmp
, list_nt
, list
) {
5000 fw_ddb_entry
= &nt_ddb_idx
->fw_ddb
;
5002 if (memcmp(&fw_ddb_entry
->isid
[0], &isid
[0],
5003 sizeof(nt_ddb_idx
->fw_ddb
.isid
)) == 0) {
5011 * qla4xxx_update_isid - compare ddbs and updated isid
5012 * @ha: Pointer to host adapter structure.
5013 * @list_nt: list of nt target
5014 * @fw_ddb_entry: firmware ddb entry
5016 * This routine update isid if ddbs have same iqn, same isid and
5017 * different IP addr.
5018 * Return QLA_SUCCESS if isid is updated.
5020 static int qla4xxx_update_isid(struct scsi_qla_host
*ha
,
5021 struct list_head
*list_nt
,
5022 struct dev_db_entry
*fw_ddb_entry
)
5024 uint8_t base_value
, i
;
5026 base_value
= fw_ddb_entry
->isid
[1] & 0x1f;
5027 for (i
= 0; i
< 8; i
++) {
5028 fw_ddb_entry
->isid
[1] = (base_value
| (i
<< 5));
5029 if (qla4xxx_check_existing_isid(list_nt
, fw_ddb_entry
->isid
))
5033 if (!qla4xxx_check_existing_isid(list_nt
, fw_ddb_entry
->isid
))
5040 * qla4xxx_should_update_isid - check if isid need to update
5041 * @ha: Pointer to host adapter structure.
5042 * @old_tddb: ddb tuple
5043 * @new_tddb: ddb tuple
5045 * Return QLA_SUCCESS if different IP, different PORT, same iqn,
5048 static int qla4xxx_should_update_isid(struct scsi_qla_host
*ha
,
5049 struct ql4_tuple_ddb
*old_tddb
,
5050 struct ql4_tuple_ddb
*new_tddb
)
5052 if (strcmp(old_tddb
->ip_addr
, new_tddb
->ip_addr
) == 0) {
5054 if (old_tddb
->port
== new_tddb
->port
)
5058 if (strcmp(old_tddb
->iscsi_name
, new_tddb
->iscsi_name
))
5062 if (memcmp(&old_tddb
->isid
[0], &new_tddb
->isid
[0],
5063 sizeof(old_tddb
->isid
)))
5064 /* different isid */
5071 * qla4xxx_is_flash_ddb_exists - check if fw_ddb_entry already exists in list_nt
5072 * @ha: Pointer to host adapter structure.
5073 * @list_nt: list of nt target.
5074 * @fw_ddb_entry: firmware ddb entry.
5076 * This routine check if fw_ddb_entry already exists in list_nt to avoid
5077 * duplicate ddb in list_nt.
5078 * Return QLA_SUCCESS if duplicate ddb exit in list_nl.
5079 * Note: This function also update isid of DDB if required.
5082 static int qla4xxx_is_flash_ddb_exists(struct scsi_qla_host
*ha
,
5083 struct list_head
*list_nt
,
5084 struct dev_db_entry
*fw_ddb_entry
)
5086 struct qla_ddb_index
*nt_ddb_idx
, *nt_ddb_idx_tmp
;
5087 struct ql4_tuple_ddb
*fw_tddb
= NULL
;
5088 struct ql4_tuple_ddb
*tmp_tddb
= NULL
;
5089 int rval
, ret
= QLA_ERROR
;
5091 fw_tddb
= vzalloc(sizeof(*fw_tddb
));
5093 DEBUG2(ql4_printk(KERN_WARNING
, ha
,
5094 "Memory Allocation failed.\n"));
5099 tmp_tddb
= vzalloc(sizeof(*tmp_tddb
));
5101 DEBUG2(ql4_printk(KERN_WARNING
, ha
,
5102 "Memory Allocation failed.\n"));
5107 qla4xxx_convert_param_ddb(fw_ddb_entry
, fw_tddb
, NULL
);
5109 list_for_each_entry_safe(nt_ddb_idx
, nt_ddb_idx_tmp
, list_nt
, list
) {
5110 qla4xxx_convert_param_ddb(&nt_ddb_idx
->fw_ddb
, tmp_tddb
,
5111 nt_ddb_idx
->flash_isid
);
5112 ret
= qla4xxx_compare_tuple_ddb(ha
, fw_tddb
, tmp_tddb
, true);
5113 /* found duplicate ddb */
5114 if (ret
== QLA_SUCCESS
)
5118 list_for_each_entry_safe(nt_ddb_idx
, nt_ddb_idx_tmp
, list_nt
, list
) {
5119 qla4xxx_convert_param_ddb(&nt_ddb_idx
->fw_ddb
, tmp_tddb
, NULL
);
5121 ret
= qla4xxx_should_update_isid(ha
, tmp_tddb
, fw_tddb
);
5122 if (ret
== QLA_SUCCESS
) {
5123 rval
= qla4xxx_update_isid(ha
, list_nt
, fw_ddb_entry
);
5124 if (rval
== QLA_SUCCESS
)
5141 static void qla4xxx_free_ddb_list(struct list_head
*list_ddb
)
5143 struct qla_ddb_index
*ddb_idx
, *ddb_idx_tmp
;
5145 list_for_each_entry_safe(ddb_idx
, ddb_idx_tmp
, list_ddb
, list
) {
5146 list_del_init(&ddb_idx
->list
);
5151 static struct iscsi_endpoint
*qla4xxx_get_ep_fwdb(struct scsi_qla_host
*ha
,
5152 struct dev_db_entry
*fw_ddb_entry
)
5154 struct iscsi_endpoint
*ep
;
5155 struct sockaddr_in
*addr
;
5156 struct sockaddr_in6
*addr6
;
5157 struct sockaddr
*t_addr
;
5158 struct sockaddr_storage
*dst_addr
;
5161 /* TODO: need to destroy on unload iscsi_endpoint*/
5162 dst_addr
= vmalloc(sizeof(*dst_addr
));
5166 if (fw_ddb_entry
->options
& DDB_OPT_IPV6_DEVICE
) {
5167 t_addr
= (struct sockaddr
*)dst_addr
;
5168 t_addr
->sa_family
= AF_INET6
;
5169 addr6
= (struct sockaddr_in6
*)dst_addr
;
5170 ip
= (char *)&addr6
->sin6_addr
;
5171 memcpy(ip
, fw_ddb_entry
->ip_addr
, IPv6_ADDR_LEN
);
5172 addr6
->sin6_port
= htons(le16_to_cpu(fw_ddb_entry
->port
));
5175 t_addr
= (struct sockaddr
*)dst_addr
;
5176 t_addr
->sa_family
= AF_INET
;
5177 addr
= (struct sockaddr_in
*)dst_addr
;
5178 ip
= (char *)&addr
->sin_addr
;
5179 memcpy(ip
, fw_ddb_entry
->ip_addr
, IP_ADDR_LEN
);
5180 addr
->sin_port
= htons(le16_to_cpu(fw_ddb_entry
->port
));
5183 ep
= qla4xxx_ep_connect(ha
->host
, (struct sockaddr
*)dst_addr
, 0);
5188 static int qla4xxx_verify_boot_idx(struct scsi_qla_host
*ha
, uint16_t idx
)
5190 if (ql4xdisablesysfsboot
)
5192 if (idx
== ha
->pri_ddb_idx
|| idx
== ha
->sec_ddb_idx
)
5197 static void qla4xxx_setup_flash_ddb_entry(struct scsi_qla_host
*ha
,
5198 struct ddb_entry
*ddb_entry
,
5201 uint16_t def_timeout
;
5203 ddb_entry
->ddb_type
= FLASH_DDB
;
5204 ddb_entry
->fw_ddb_index
= INVALID_ENTRY
;
5205 ddb_entry
->fw_ddb_device_state
= DDB_DS_NO_CONNECTION_ACTIVE
;
5207 ddb_entry
->unblock_sess
= qla4xxx_unblock_flash_ddb
;
5208 ddb_entry
->ddb_change
= qla4xxx_flash_ddb_change
;
5210 atomic_set(&ddb_entry
->retry_relogin_timer
, INVALID_ENTRY
);
5211 atomic_set(&ddb_entry
->relogin_timer
, 0);
5212 atomic_set(&ddb_entry
->relogin_retry_count
, 0);
5213 def_timeout
= le16_to_cpu(ddb_entry
->fw_ddb_entry
.def_timeout
);
5214 ddb_entry
->default_relogin_timeout
=
5215 (def_timeout
> LOGIN_TOV
) && (def_timeout
< LOGIN_TOV
* 10) ?
5216 def_timeout
: LOGIN_TOV
;
5217 ddb_entry
->default_time2wait
=
5218 le16_to_cpu(ddb_entry
->fw_ddb_entry
.iscsi_def_time2wait
);
5220 if (ql4xdisablesysfsboot
&&
5221 (idx
== ha
->pri_ddb_idx
|| idx
== ha
->sec_ddb_idx
))
5222 set_bit(DF_BOOT_TGT
, &ddb_entry
->flags
);
5225 static void qla4xxx_wait_for_ip_configuration(struct scsi_qla_host
*ha
)
5228 uint32_t ip_idx
[IP_ADDR_COUNT
] = {0, 1, 2, 3}; /* 4 IP interfaces */
5229 uint32_t sts
[MBOX_REG_COUNT
];
5231 unsigned long wtime
;
5234 wtime
= jiffies
+ (HZ
* IP_CONFIG_TOV
);
5236 for (idx
= 0; idx
< IP_ADDR_COUNT
; idx
++) {
5237 if (ip_idx
[idx
] == -1)
5240 ret
= qla4xxx_get_ip_state(ha
, 0, ip_idx
[idx
], sts
);
5242 if (ret
== QLA_ERROR
) {
5247 ip_state
= (sts
[1] & IP_STATE_MASK
) >> IP_STATE_SHIFT
;
5249 DEBUG2(ql4_printk(KERN_INFO
, ha
,
5250 "Waiting for IP state for idx = %d, state = 0x%x\n",
5251 ip_idx
[idx
], ip_state
));
5252 if (ip_state
== IP_ADDRSTATE_UNCONFIGURED
||
5253 ip_state
== IP_ADDRSTATE_INVALID
||
5254 ip_state
== IP_ADDRSTATE_PREFERRED
||
5255 ip_state
== IP_ADDRSTATE_DEPRICATED
||
5256 ip_state
== IP_ADDRSTATE_DISABLING
)
5260 /* Break if all IP states checked */
5261 if ((ip_idx
[0] == -1) &&
5262 (ip_idx
[1] == -1) &&
5263 (ip_idx
[2] == -1) &&
5266 schedule_timeout_uninterruptible(HZ
);
5267 } while (time_after(wtime
, jiffies
));
5270 static void qla4xxx_build_st_list(struct scsi_qla_host
*ha
,
5271 struct list_head
*list_st
)
5273 struct qla_ddb_index
*st_ddb_idx
;
5276 struct dev_db_entry
*fw_ddb_entry
;
5277 dma_addr_t fw_ddb_dma
;
5279 uint32_t idx
= 0, next_idx
= 0;
5280 uint32_t state
= 0, conn_err
= 0;
5281 uint16_t conn_id
= 0;
5283 fw_ddb_entry
= dma_pool_alloc(ha
->fw_ddb_dma_pool
, GFP_KERNEL
,
5285 if (fw_ddb_entry
== NULL
) {
5286 DEBUG2(ql4_printk(KERN_ERR
, ha
, "Out of memory\n"));
5290 max_ddbs
= is_qla40XX(ha
) ? MAX_DEV_DB_ENTRIES_40XX
:
5292 fw_idx_size
= sizeof(struct qla_ddb_index
);
5294 for (idx
= 0; idx
< max_ddbs
; idx
= next_idx
) {
5295 ret
= qla4xxx_get_fwddb_entry(ha
, idx
, fw_ddb_entry
, fw_ddb_dma
,
5296 NULL
, &next_idx
, &state
,
5297 &conn_err
, NULL
, &conn_id
);
5298 if (ret
== QLA_ERROR
)
5301 /* Ignore DDB if invalid state (unassigned) */
5302 if (state
== DDB_DS_UNASSIGNED
)
5303 goto continue_next_st
;
5305 /* Check if ST, add to the list_st */
5306 if (strlen((char *) fw_ddb_entry
->iscsi_name
) != 0)
5307 goto continue_next_st
;
5309 st_ddb_idx
= vzalloc(fw_idx_size
);
5313 st_ddb_idx
->fw_ddb_idx
= idx
;
5315 list_add_tail(&st_ddb_idx
->list
, list_st
);
5323 dma_pool_free(ha
->fw_ddb_dma_pool
, fw_ddb_entry
, fw_ddb_dma
);
5327 * qla4xxx_remove_failed_ddb - Remove inactive or failed ddb from list
5328 * @ha: pointer to adapter structure
5329 * @list_ddb: List from which failed ddb to be removed
5331 * Iterate over the list of DDBs and find and remove DDBs that are either in
5332 * no connection active state or failed state
5334 static void qla4xxx_remove_failed_ddb(struct scsi_qla_host
*ha
,
5335 struct list_head
*list_ddb
)
5337 struct qla_ddb_index
*ddb_idx
, *ddb_idx_tmp
;
5338 uint32_t next_idx
= 0;
5339 uint32_t state
= 0, conn_err
= 0;
5342 list_for_each_entry_safe(ddb_idx
, ddb_idx_tmp
, list_ddb
, list
) {
5343 ret
= qla4xxx_get_fwddb_entry(ha
, ddb_idx
->fw_ddb_idx
,
5344 NULL
, 0, NULL
, &next_idx
, &state
,
5345 &conn_err
, NULL
, NULL
);
5346 if (ret
== QLA_ERROR
)
5349 if (state
== DDB_DS_NO_CONNECTION_ACTIVE
||
5350 state
== DDB_DS_SESSION_FAILED
) {
5351 list_del_init(&ddb_idx
->list
);
5357 static int qla4xxx_sess_conn_setup(struct scsi_qla_host
*ha
,
5358 struct dev_db_entry
*fw_ddb_entry
,
5359 int is_reset
, uint16_t idx
)
5361 struct iscsi_cls_session
*cls_sess
;
5362 struct iscsi_session
*sess
;
5363 struct iscsi_cls_conn
*cls_conn
;
5364 struct iscsi_endpoint
*ep
;
5365 uint16_t cmds_max
= 32;
5366 uint16_t conn_id
= 0;
5367 uint32_t initial_cmdsn
= 0;
5368 int ret
= QLA_SUCCESS
;
5370 struct ddb_entry
*ddb_entry
= NULL
;
5372 /* Create session object, with INVALID_ENTRY,
5373 * the targer_id would get set when we issue the login
5375 cls_sess
= iscsi_session_setup(&qla4xxx_iscsi_transport
, ha
->host
,
5376 cmds_max
, sizeof(struct ddb_entry
),
5377 sizeof(struct ql4_task_data
),
5378 initial_cmdsn
, INVALID_ENTRY
);
5385 * so calling module_put function to decrement the
5388 module_put(qla4xxx_iscsi_transport
.owner
);
5389 sess
= cls_sess
->dd_data
;
5390 ddb_entry
= sess
->dd_data
;
5391 ddb_entry
->sess
= cls_sess
;
5393 cls_sess
->recovery_tmo
= ql4xsess_recovery_tmo
;
5394 memcpy(&ddb_entry
->fw_ddb_entry
, fw_ddb_entry
,
5395 sizeof(struct dev_db_entry
));
5397 qla4xxx_setup_flash_ddb_entry(ha
, ddb_entry
, idx
);
5399 cls_conn
= iscsi_conn_setup(cls_sess
, sizeof(struct qla_conn
), conn_id
);
5406 ddb_entry
->conn
= cls_conn
;
5408 /* Setup ep, for displaying attributes in sysfs */
5409 ep
= qla4xxx_get_ep_fwdb(ha
, fw_ddb_entry
);
5411 ep
->conn
= cls_conn
;
5414 DEBUG2(ql4_printk(KERN_ERR
, ha
, "Unable to get ep\n"));
5419 /* Update sess/conn params */
5420 qla4xxx_copy_fwddb_param(ha
, fw_ddb_entry
, cls_sess
, cls_conn
);
5422 if (is_reset
== RESET_ADAPTER
) {
5423 iscsi_block_session(cls_sess
);
5424 /* Use the relogin path to discover new devices
5425 * by short-circuting the logic of setting
5426 * timer to relogin - instead set the flags
5427 * to initiate login right away.
5429 set_bit(DPC_RELOGIN_DEVICE
, &ha
->dpc_flags
);
5430 set_bit(DF_RELOGIN
, &ddb_entry
->flags
);
5437 static void qla4xxx_build_nt_list(struct scsi_qla_host
*ha
,
5438 struct list_head
*list_nt
, int is_reset
)
5440 struct dev_db_entry
*fw_ddb_entry
;
5441 dma_addr_t fw_ddb_dma
;
5445 uint32_t idx
= 0, next_idx
= 0;
5446 uint32_t state
= 0, conn_err
= 0;
5447 uint16_t conn_id
= 0;
5448 struct qla_ddb_index
*nt_ddb_idx
;
5450 fw_ddb_entry
= dma_pool_alloc(ha
->fw_ddb_dma_pool
, GFP_KERNEL
,
5452 if (fw_ddb_entry
== NULL
) {
5453 DEBUG2(ql4_printk(KERN_ERR
, ha
, "Out of memory\n"));
5456 max_ddbs
= is_qla40XX(ha
) ? MAX_DEV_DB_ENTRIES_40XX
:
5458 fw_idx_size
= sizeof(struct qla_ddb_index
);
5460 for (idx
= 0; idx
< max_ddbs
; idx
= next_idx
) {
5461 ret
= qla4xxx_get_fwddb_entry(ha
, idx
, fw_ddb_entry
, fw_ddb_dma
,
5462 NULL
, &next_idx
, &state
,
5463 &conn_err
, NULL
, &conn_id
);
5464 if (ret
== QLA_ERROR
)
5467 if (qla4xxx_verify_boot_idx(ha
, idx
) != QLA_SUCCESS
)
5468 goto continue_next_nt
;
5470 /* Check if NT, then add to list it */
5471 if (strlen((char *) fw_ddb_entry
->iscsi_name
) == 0)
5472 goto continue_next_nt
;
5474 if (!(state
== DDB_DS_NO_CONNECTION_ACTIVE
||
5475 state
== DDB_DS_SESSION_FAILED
))
5476 goto continue_next_nt
;
5478 DEBUG2(ql4_printk(KERN_INFO
, ha
,
5479 "Adding DDB to session = 0x%x\n", idx
));
5480 if (is_reset
== INIT_ADAPTER
) {
5481 nt_ddb_idx
= vmalloc(fw_idx_size
);
5485 nt_ddb_idx
->fw_ddb_idx
= idx
;
5487 /* Copy original isid as it may get updated in function
5488 * qla4xxx_update_isid(). We need original isid in
5489 * function qla4xxx_compare_tuple_ddb to find duplicate
5491 memcpy(&nt_ddb_idx
->flash_isid
[0],
5492 &fw_ddb_entry
->isid
[0],
5493 sizeof(nt_ddb_idx
->flash_isid
));
5495 ret
= qla4xxx_is_flash_ddb_exists(ha
, list_nt
,
5497 if (ret
== QLA_SUCCESS
) {
5498 /* free nt_ddb_idx and do not add to list_nt */
5500 goto continue_next_nt
;
5503 /* Copy updated isid */
5504 memcpy(&nt_ddb_idx
->fw_ddb
, fw_ddb_entry
,
5505 sizeof(struct dev_db_entry
));
5507 list_add_tail(&nt_ddb_idx
->list
, list_nt
);
5508 } else if (is_reset
== RESET_ADAPTER
) {
5509 if (qla4xxx_is_session_exists(ha
, fw_ddb_entry
) ==
5511 goto continue_next_nt
;
5514 ret
= qla4xxx_sess_conn_setup(ha
, fw_ddb_entry
, is_reset
, idx
);
5515 if (ret
== QLA_ERROR
)
5525 dma_pool_free(ha
->fw_ddb_dma_pool
, fw_ddb_entry
, fw_ddb_dma
);
5528 static void qla4xxx_build_new_nt_list(struct scsi_qla_host
*ha
,
5529 struct list_head
*list_nt
)
5531 struct dev_db_entry
*fw_ddb_entry
;
5532 dma_addr_t fw_ddb_dma
;
5536 uint32_t idx
= 0, next_idx
= 0;
5537 uint32_t state
= 0, conn_err
= 0;
5538 uint16_t conn_id
= 0;
5539 struct qla_ddb_index
*nt_ddb_idx
;
5541 fw_ddb_entry
= dma_pool_alloc(ha
->fw_ddb_dma_pool
, GFP_KERNEL
,
5543 if (fw_ddb_entry
== NULL
) {
5544 DEBUG2(ql4_printk(KERN_ERR
, ha
, "Out of memory\n"));
5545 goto exit_new_nt_list
;
5547 max_ddbs
= is_qla40XX(ha
) ? MAX_DEV_DB_ENTRIES_40XX
:
5549 fw_idx_size
= sizeof(struct qla_ddb_index
);
5551 for (idx
= 0; idx
< max_ddbs
; idx
= next_idx
) {
5552 ret
= qla4xxx_get_fwddb_entry(ha
, idx
, fw_ddb_entry
, fw_ddb_dma
,
5553 NULL
, &next_idx
, &state
,
5554 &conn_err
, NULL
, &conn_id
);
5555 if (ret
== QLA_ERROR
)
5558 /* Check if NT, then add it to list */
5559 if (strlen((char *)fw_ddb_entry
->iscsi_name
) == 0)
5560 goto continue_next_new_nt
;
5562 if (!(state
== DDB_DS_NO_CONNECTION_ACTIVE
))
5563 goto continue_next_new_nt
;
5565 DEBUG2(ql4_printk(KERN_INFO
, ha
,
5566 "Adding DDB to session = 0x%x\n", idx
));
5568 nt_ddb_idx
= vmalloc(fw_idx_size
);
5572 nt_ddb_idx
->fw_ddb_idx
= idx
;
5574 ret
= qla4xxx_is_session_exists(ha
, fw_ddb_entry
);
5575 if (ret
== QLA_SUCCESS
) {
5576 /* free nt_ddb_idx and do not add to list_nt */
5578 goto continue_next_new_nt
;
5581 list_add_tail(&nt_ddb_idx
->list
, list_nt
);
5583 ret
= qla4xxx_sess_conn_setup(ha
, fw_ddb_entry
, RESET_ADAPTER
,
5585 if (ret
== QLA_ERROR
)
5586 goto exit_new_nt_list
;
5588 continue_next_new_nt
:
5595 dma_pool_free(ha
->fw_ddb_dma_pool
, fw_ddb_entry
, fw_ddb_dma
);
5599 * qla4xxx_sysfs_ddb_is_non_persistent - check for non-persistence of ddb entry
5600 * @dev: dev associated with the sysfs entry
5601 * @data: pointer to flashnode session object
5604 * 1: if flashnode entry is non-persistent
5605 * 0: if flashnode entry is persistent
5607 static int qla4xxx_sysfs_ddb_is_non_persistent(struct device
*dev
, void *data
)
5609 struct iscsi_bus_flash_session
*fnode_sess
;
5611 if (!iscsi_flashnode_bus_match(dev
, NULL
))
5614 fnode_sess
= iscsi_dev_to_flash_session(dev
);
5616 return (fnode_sess
->flash_state
== DEV_DB_NON_PERSISTENT
);
5620 * qla4xxx_sysfs_ddb_tgt_create - Create sysfs entry for target
5621 * @ha: pointer to host
5622 * @fw_ddb_entry: flash ddb data
5623 * @idx: target index
5624 * @user: if set then this call is made from userland else from kernel
5627 * On sucess: QLA_SUCCESS
5628 * On failure: QLA_ERROR
5630 * This create separate sysfs entries for session and connection attributes of
5631 * the given fw ddb entry.
5632 * If this is invoked as a result of a userspace call then the entry is marked
5633 * as nonpersistent using flash_state field.
5635 static int qla4xxx_sysfs_ddb_tgt_create(struct scsi_qla_host
*ha
,
5636 struct dev_db_entry
*fw_ddb_entry
,
5637 uint16_t *idx
, int user
)
5639 struct iscsi_bus_flash_session
*fnode_sess
= NULL
;
5640 struct iscsi_bus_flash_conn
*fnode_conn
= NULL
;
5643 fnode_sess
= iscsi_create_flashnode_sess(ha
->host
, *idx
,
5644 &qla4xxx_iscsi_transport
, 0);
5646 ql4_printk(KERN_ERR
, ha
,
5647 "%s: Unable to create session sysfs entry for flashnode %d of host%lu\n",
5648 __func__
, *idx
, ha
->host_no
);
5649 goto exit_tgt_create
;
5652 fnode_conn
= iscsi_create_flashnode_conn(ha
->host
, fnode_sess
,
5653 &qla4xxx_iscsi_transport
, 0);
5655 ql4_printk(KERN_ERR
, ha
,
5656 "%s: Unable to create conn sysfs entry for flashnode %d of host%lu\n",
5657 __func__
, *idx
, ha
->host_no
);
5662 fnode_sess
->flash_state
= DEV_DB_NON_PERSISTENT
;
5664 fnode_sess
->flash_state
= DEV_DB_PERSISTENT
;
5666 if (*idx
== ha
->pri_ddb_idx
|| *idx
== ha
->sec_ddb_idx
)
5667 fnode_sess
->is_boot_target
= 1;
5669 fnode_sess
->is_boot_target
= 0;
5672 rc
= qla4xxx_copy_from_fwddb_param(fnode_sess
, fnode_conn
,
5675 ql4_printk(KERN_INFO
, ha
, "%s: sysfs entry %s created\n",
5676 __func__
, fnode_sess
->dev
.kobj
.name
);
5678 ql4_printk(KERN_INFO
, ha
, "%s: sysfs entry %s created\n",
5679 __func__
, fnode_conn
->dev
.kobj
.name
);
5684 iscsi_destroy_flashnode_sess(fnode_sess
);
5691 * qla4xxx_sysfs_ddb_add - Add new ddb entry in flash
5692 * @shost: pointer to host
5693 * @buf: type of ddb entry (ipv4/ipv6)
5694 * @len: length of buf
5696 * This creates new ddb entry in the flash by finding first free index and
5697 * storing default ddb there. And then create sysfs entry for the new ddb entry.
5699 static int qla4xxx_sysfs_ddb_add(struct Scsi_Host
*shost
, const char *buf
,
5702 struct scsi_qla_host
*ha
= to_qla_host(shost
);
5703 struct dev_db_entry
*fw_ddb_entry
= NULL
;
5704 dma_addr_t fw_ddb_entry_dma
;
5707 uint16_t max_ddbs
= 0;
5708 uint32_t options
= 0;
5709 uint32_t rval
= QLA_ERROR
;
5711 if (strncasecmp(PORTAL_TYPE_IPV4
, buf
, 4) &&
5712 strncasecmp(PORTAL_TYPE_IPV6
, buf
, 4)) {
5713 DEBUG2(ql4_printk(KERN_ERR
, ha
, "%s: Invalid portal type\n",
5718 max_ddbs
= is_qla40XX(ha
) ? MAX_PRST_DEV_DB_ENTRIES
:
5721 fw_ddb_entry
= dma_alloc_coherent(&ha
->pdev
->dev
, sizeof(*fw_ddb_entry
),
5722 &fw_ddb_entry_dma
, GFP_KERNEL
);
5723 if (!fw_ddb_entry
) {
5724 DEBUG2(ql4_printk(KERN_ERR
, ha
,
5725 "%s: Unable to allocate dma buffer\n",
5730 dev
= iscsi_find_flashnode_sess(ha
->host
, NULL
,
5731 qla4xxx_sysfs_ddb_is_non_persistent
);
5733 ql4_printk(KERN_ERR
, ha
,
5734 "%s: A non-persistent entry %s found\n",
5735 __func__
, dev
->kobj
.name
);
5740 /* Index 0 and 1 are reserved for boot target entries */
5741 for (idx
= 2; idx
< max_ddbs
; idx
++) {
5742 if (qla4xxx_flashdb_by_index(ha
, fw_ddb_entry
,
5743 fw_ddb_entry_dma
, idx
))
5747 if (idx
== max_ddbs
)
5750 if (!strncasecmp("ipv6", buf
, 4))
5751 options
|= IPV6_DEFAULT_DDB_ENTRY
;
5753 rval
= qla4xxx_get_default_ddb(ha
, options
, fw_ddb_entry_dma
);
5754 if (rval
== QLA_ERROR
)
5757 rval
= qla4xxx_sysfs_ddb_tgt_create(ha
, fw_ddb_entry
, &idx
, 1);
5761 dma_free_coherent(&ha
->pdev
->dev
, sizeof(*fw_ddb_entry
),
5762 fw_ddb_entry
, fw_ddb_entry_dma
);
5763 if (rval
== QLA_SUCCESS
)
5770 * qla4xxx_sysfs_ddb_apply - write the target ddb contents to Flash
5771 * @fnode_sess: pointer to session attrs of flash ddb entry
5772 * @fnode_conn: pointer to connection attrs of flash ddb entry
5774 * This writes the contents of target ddb buffer to Flash with a valid cookie
5775 * value in order to make the ddb entry persistent.
5777 static int qla4xxx_sysfs_ddb_apply(struct iscsi_bus_flash_session
*fnode_sess
,
5778 struct iscsi_bus_flash_conn
*fnode_conn
)
5780 struct Scsi_Host
*shost
= iscsi_flash_session_to_shost(fnode_sess
);
5781 struct scsi_qla_host
*ha
= to_qla_host(shost
);
5782 uint32_t dev_db_start_offset
= FLASH_OFFSET_DB_INFO
;
5783 struct dev_db_entry
*fw_ddb_entry
= NULL
;
5784 dma_addr_t fw_ddb_entry_dma
;
5785 uint32_t options
= 0;
5788 fw_ddb_entry
= dma_alloc_coherent(&ha
->pdev
->dev
, sizeof(*fw_ddb_entry
),
5789 &fw_ddb_entry_dma
, GFP_KERNEL
);
5790 if (!fw_ddb_entry
) {
5791 DEBUG2(ql4_printk(KERN_ERR
, ha
,
5792 "%s: Unable to allocate dma buffer\n",
5795 goto exit_ddb_apply
;
5798 if (!strncasecmp(fnode_sess
->portal_type
, PORTAL_TYPE_IPV6
, 4))
5799 options
|= IPV6_DEFAULT_DDB_ENTRY
;
5801 rval
= qla4xxx_get_default_ddb(ha
, options
, fw_ddb_entry_dma
);
5802 if (rval
== QLA_ERROR
)
5803 goto exit_ddb_apply
;
5805 dev_db_start_offset
+= (fnode_sess
->target_id
*
5806 sizeof(*fw_ddb_entry
));
5808 qla4xxx_copy_to_fwddb_param(fnode_sess
, fnode_conn
, fw_ddb_entry
);
5809 fw_ddb_entry
->cookie
= DDB_VALID_COOKIE
;
5811 rval
= qla4xxx_set_flash(ha
, fw_ddb_entry_dma
, dev_db_start_offset
,
5812 sizeof(*fw_ddb_entry
), FLASH_OPT_RMW_COMMIT
);
5814 if (rval
== QLA_SUCCESS
) {
5815 fnode_sess
->flash_state
= DEV_DB_PERSISTENT
;
5816 ql4_printk(KERN_INFO
, ha
,
5817 "%s: flash node %u of host %lu written to flash\n",
5818 __func__
, fnode_sess
->target_id
, ha
->host_no
);
5821 ql4_printk(KERN_ERR
, ha
,
5822 "%s: Error while writing flash node %u of host %lu to flash\n",
5823 __func__
, fnode_sess
->target_id
, ha
->host_no
);
5828 dma_free_coherent(&ha
->pdev
->dev
, sizeof(*fw_ddb_entry
),
5829 fw_ddb_entry
, fw_ddb_entry_dma
);
5833 static ssize_t
qla4xxx_sysfs_ddb_conn_open(struct scsi_qla_host
*ha
,
5834 struct dev_db_entry
*fw_ddb_entry
,
5837 struct dev_db_entry
*ddb_entry
= NULL
;
5838 dma_addr_t ddb_entry_dma
;
5839 unsigned long wtime
;
5840 uint32_t mbx_sts
= 0;
5841 uint32_t state
= 0, conn_err
= 0;
5845 ddb_entry
= dma_alloc_coherent(&ha
->pdev
->dev
, sizeof(*ddb_entry
),
5846 &ddb_entry_dma
, GFP_KERNEL
);
5848 DEBUG2(ql4_printk(KERN_ERR
, ha
,
5849 "%s: Unable to allocate dma buffer\n",
5854 memcpy(ddb_entry
, fw_ddb_entry
, sizeof(*ddb_entry
));
5856 ret
= qla4xxx_set_ddb_entry(ha
, idx
, ddb_entry_dma
, &mbx_sts
);
5857 if (ret
!= QLA_SUCCESS
) {
5858 DEBUG2(ql4_printk(KERN_ERR
, ha
,
5859 "%s: Unable to set ddb entry for index %d\n",
5861 goto exit_ddb_conn_open
;
5864 qla4xxx_conn_open(ha
, idx
);
5866 /* To ensure that sendtargets is done, wait for at least 12 secs */
5867 tmo
= ((ha
->def_timeout
> LOGIN_TOV
) &&
5868 (ha
->def_timeout
< LOGIN_TOV
* 10) ?
5869 ha
->def_timeout
: LOGIN_TOV
);
5871 DEBUG2(ql4_printk(KERN_INFO
, ha
,
5872 "Default time to wait for login to ddb %d\n", tmo
));
5874 wtime
= jiffies
+ (HZ
* tmo
);
5876 ret
= qla4xxx_get_fwddb_entry(ha
, idx
, NULL
, 0, NULL
,
5877 NULL
, &state
, &conn_err
, NULL
,
5879 if (ret
== QLA_ERROR
)
5882 if (state
== DDB_DS_NO_CONNECTION_ACTIVE
||
5883 state
== DDB_DS_SESSION_FAILED
)
5886 schedule_timeout_uninterruptible(HZ
/ 10);
5887 } while (time_after(wtime
, jiffies
));
5891 dma_free_coherent(&ha
->pdev
->dev
, sizeof(*ddb_entry
),
5892 ddb_entry
, ddb_entry_dma
);
5896 static int qla4xxx_ddb_login_st(struct scsi_qla_host
*ha
,
5897 struct dev_db_entry
*fw_ddb_entry
)
5899 struct qla_ddb_index
*ddb_idx
, *ddb_idx_tmp
;
5900 struct list_head list_nt
;
5904 if (test_bit(AF_ST_DISCOVERY_IN_PROGRESS
, &ha
->flags
)) {
5905 ql4_printk(KERN_WARNING
, ha
,
5906 "%s: A discovery already in progress!\n", __func__
);
5910 INIT_LIST_HEAD(&list_nt
);
5912 set_bit(AF_ST_DISCOVERY_IN_PROGRESS
, &ha
->flags
);
5914 ret
= qla4xxx_get_ddb_index(ha
, &ddb_index
);
5915 if (ret
== QLA_ERROR
)
5916 goto exit_login_st_clr_bit
;
5918 ret
= qla4xxx_sysfs_ddb_conn_open(ha
, fw_ddb_entry
, ddb_index
);
5919 if (ret
== QLA_ERROR
)
5922 qla4xxx_build_new_nt_list(ha
, &list_nt
);
5924 list_for_each_entry_safe(ddb_idx
, ddb_idx_tmp
, &list_nt
, list
) {
5925 list_del_init(&ddb_idx
->list
);
5926 qla4xxx_clear_ddb_entry(ha
, ddb_idx
->fw_ddb_idx
);
5931 if (qla4xxx_clear_ddb_entry(ha
, ddb_index
) == QLA_ERROR
) {
5932 ql4_printk(KERN_ERR
, ha
,
5933 "Unable to clear DDB index = 0x%x\n", ddb_index
);
5936 clear_bit(ddb_index
, ha
->ddb_idx_map
);
5938 exit_login_st_clr_bit
:
5939 clear_bit(AF_ST_DISCOVERY_IN_PROGRESS
, &ha
->flags
);
5943 static int qla4xxx_ddb_login_nt(struct scsi_qla_host
*ha
,
5944 struct dev_db_entry
*fw_ddb_entry
,
5947 int ret
= QLA_ERROR
;
5949 ret
= qla4xxx_is_session_exists(ha
, fw_ddb_entry
);
5950 if (ret
!= QLA_SUCCESS
)
5951 ret
= qla4xxx_sess_conn_setup(ha
, fw_ddb_entry
, RESET_ADAPTER
,
5960 * qla4xxx_sysfs_ddb_login - Login to the specified target
5961 * @fnode_sess: pointer to session attrs of flash ddb entry
5962 * @fnode_conn: pointer to connection attrs of flash ddb entry
5964 * This logs in to the specified target
5966 static int qla4xxx_sysfs_ddb_login(struct iscsi_bus_flash_session
*fnode_sess
,
5967 struct iscsi_bus_flash_conn
*fnode_conn
)
5969 struct Scsi_Host
*shost
= iscsi_flash_session_to_shost(fnode_sess
);
5970 struct scsi_qla_host
*ha
= to_qla_host(shost
);
5971 struct dev_db_entry
*fw_ddb_entry
= NULL
;
5972 dma_addr_t fw_ddb_entry_dma
;
5973 uint32_t options
= 0;
5976 if (fnode_sess
->flash_state
== DEV_DB_NON_PERSISTENT
) {
5977 ql4_printk(KERN_ERR
, ha
,
5978 "%s: Target info is not persistent\n", __func__
);
5980 goto exit_ddb_login
;
5983 fw_ddb_entry
= dma_alloc_coherent(&ha
->pdev
->dev
, sizeof(*fw_ddb_entry
),
5984 &fw_ddb_entry_dma
, GFP_KERNEL
);
5985 if (!fw_ddb_entry
) {
5986 DEBUG2(ql4_printk(KERN_ERR
, ha
,
5987 "%s: Unable to allocate dma buffer\n",
5990 goto exit_ddb_login
;
5993 if (!strncasecmp(fnode_sess
->portal_type
, PORTAL_TYPE_IPV6
, 4))
5994 options
|= IPV6_DEFAULT_DDB_ENTRY
;
5996 ret
= qla4xxx_get_default_ddb(ha
, options
, fw_ddb_entry_dma
);
5997 if (ret
== QLA_ERROR
)
5998 goto exit_ddb_login
;
6000 qla4xxx_copy_to_fwddb_param(fnode_sess
, fnode_conn
, fw_ddb_entry
);
6001 fw_ddb_entry
->cookie
= DDB_VALID_COOKIE
;
6003 if (strlen((char *)fw_ddb_entry
->iscsi_name
) == 0)
6004 ret
= qla4xxx_ddb_login_st(ha
, fw_ddb_entry
);
6006 ret
= qla4xxx_ddb_login_nt(ha
, fw_ddb_entry
,
6007 fnode_sess
->target_id
);
6014 dma_free_coherent(&ha
->pdev
->dev
, sizeof(*fw_ddb_entry
),
6015 fw_ddb_entry
, fw_ddb_entry_dma
);
6020 * qla4xxx_sysfs_ddb_logout_sid - Logout session for the specified target
6021 * @cls_sess: pointer to session to be logged out
6023 * This performs session log out from the specified target
6025 static int qla4xxx_sysfs_ddb_logout_sid(struct iscsi_cls_session
*cls_sess
)
6027 struct iscsi_session
*sess
;
6028 struct ddb_entry
*ddb_entry
= NULL
;
6029 struct scsi_qla_host
*ha
;
6030 struct dev_db_entry
*fw_ddb_entry
= NULL
;
6031 dma_addr_t fw_ddb_entry_dma
;
6032 unsigned long flags
;
6033 unsigned long wtime
;
6038 sess
= cls_sess
->dd_data
;
6039 ddb_entry
= sess
->dd_data
;
6042 if (ddb_entry
->ddb_type
!= FLASH_DDB
) {
6043 ql4_printk(KERN_ERR
, ha
, "%s: Not a flash node session\n",
6046 goto exit_ddb_logout
;
6049 if (test_bit(DF_BOOT_TGT
, &ddb_entry
->flags
)) {
6050 ql4_printk(KERN_ERR
, ha
,
6051 "%s: Logout from boot target entry is not permitted.\n",
6054 goto exit_ddb_logout
;
6057 fw_ddb_entry
= dma_alloc_coherent(&ha
->pdev
->dev
, sizeof(*fw_ddb_entry
),
6058 &fw_ddb_entry_dma
, GFP_KERNEL
);
6059 if (!fw_ddb_entry
) {
6060 ql4_printk(KERN_ERR
, ha
,
6061 "%s: Unable to allocate dma buffer\n", __func__
);
6063 goto exit_ddb_logout
;
6066 if (test_and_set_bit(DF_DISABLE_RELOGIN
, &ddb_entry
->flags
))
6067 goto ddb_logout_init
;
6069 ret
= qla4xxx_get_fwddb_entry(ha
, ddb_entry
->fw_ddb_index
,
6070 fw_ddb_entry
, fw_ddb_entry_dma
,
6071 NULL
, NULL
, &ddb_state
, NULL
,
6073 if (ret
== QLA_ERROR
)
6074 goto ddb_logout_init
;
6076 if (ddb_state
== DDB_DS_SESSION_ACTIVE
)
6077 goto ddb_logout_init
;
6079 /* wait until next relogin is triggered using DF_RELOGIN and
6080 * clear DF_RELOGIN to avoid invocation of further relogin
6082 wtime
= jiffies
+ (HZ
* RELOGIN_TOV
);
6084 if (test_and_clear_bit(DF_RELOGIN
, &ddb_entry
->flags
))
6085 goto ddb_logout_init
;
6087 schedule_timeout_uninterruptible(HZ
);
6088 } while ((time_after(wtime
, jiffies
)));
6091 atomic_set(&ddb_entry
->retry_relogin_timer
, INVALID_ENTRY
);
6092 atomic_set(&ddb_entry
->relogin_timer
, 0);
6094 options
= LOGOUT_OPTION_CLOSE_SESSION
;
6095 qla4xxx_session_logout_ddb(ha
, ddb_entry
, options
);
6097 memset(fw_ddb_entry
, 0, sizeof(*fw_ddb_entry
));
6098 wtime
= jiffies
+ (HZ
* LOGOUT_TOV
);
6100 ret
= qla4xxx_get_fwddb_entry(ha
, ddb_entry
->fw_ddb_index
,
6101 fw_ddb_entry
, fw_ddb_entry_dma
,
6102 NULL
, NULL
, &ddb_state
, NULL
,
6104 if (ret
== QLA_ERROR
)
6105 goto ddb_logout_clr_sess
;
6107 if ((ddb_state
== DDB_DS_NO_CONNECTION_ACTIVE
) ||
6108 (ddb_state
== DDB_DS_SESSION_FAILED
))
6109 goto ddb_logout_clr_sess
;
6111 schedule_timeout_uninterruptible(HZ
);
6112 } while ((time_after(wtime
, jiffies
)));
6114 ddb_logout_clr_sess
:
6115 qla4xxx_clear_ddb_entry(ha
, ddb_entry
->fw_ddb_index
);
6117 * we have decremented the reference count of the driver
6118 * when we setup the session to have the driver unload
6119 * to be seamless without actually destroying the
6122 try_module_get(qla4xxx_iscsi_transport
.owner
);
6123 iscsi_destroy_endpoint(ddb_entry
->conn
->ep
);
6125 spin_lock_irqsave(&ha
->hardware_lock
, flags
);
6126 qla4xxx_free_ddb(ha
, ddb_entry
);
6127 clear_bit(ddb_entry
->fw_ddb_index
, ha
->ddb_idx_map
);
6128 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
6130 iscsi_session_teardown(ddb_entry
->sess
);
6132 clear_bit(DF_DISABLE_RELOGIN
, &ddb_entry
->flags
);
6137 dma_free_coherent(&ha
->pdev
->dev
, sizeof(*fw_ddb_entry
),
6138 fw_ddb_entry
, fw_ddb_entry_dma
);
6143 * qla4xxx_sysfs_ddb_logout - Logout from the specified target
6144 * @fnode_sess: pointer to session attrs of flash ddb entry
6145 * @fnode_conn: pointer to connection attrs of flash ddb entry
6147 * This performs log out from the specified target
6149 static int qla4xxx_sysfs_ddb_logout(struct iscsi_bus_flash_session
*fnode_sess
,
6150 struct iscsi_bus_flash_conn
*fnode_conn
)
6152 struct Scsi_Host
*shost
= iscsi_flash_session_to_shost(fnode_sess
);
6153 struct scsi_qla_host
*ha
= to_qla_host(shost
);
6154 struct ql4_tuple_ddb
*flash_tddb
= NULL
;
6155 struct ql4_tuple_ddb
*tmp_tddb
= NULL
;
6156 struct dev_db_entry
*fw_ddb_entry
= NULL
;
6157 struct ddb_entry
*ddb_entry
= NULL
;
6158 dma_addr_t fw_ddb_dma
;
6159 uint32_t next_idx
= 0;
6160 uint32_t state
= 0, conn_err
= 0;
6161 uint16_t conn_id
= 0;
6163 int status
, ret
= 0;
6165 fw_ddb_entry
= dma_pool_alloc(ha
->fw_ddb_dma_pool
, GFP_KERNEL
,
6167 if (fw_ddb_entry
== NULL
) {
6168 ql4_printk(KERN_ERR
, ha
, "%s:Out of memory\n", __func__
);
6170 goto exit_ddb_logout
;
6173 flash_tddb
= vzalloc(sizeof(*flash_tddb
));
6175 ql4_printk(KERN_WARNING
, ha
,
6176 "%s:Memory Allocation failed.\n", __func__
);
6178 goto exit_ddb_logout
;
6181 tmp_tddb
= vzalloc(sizeof(*tmp_tddb
));
6183 ql4_printk(KERN_WARNING
, ha
,
6184 "%s:Memory Allocation failed.\n", __func__
);
6186 goto exit_ddb_logout
;
6189 if (!fnode_sess
->targetname
) {
6190 ql4_printk(KERN_ERR
, ha
,
6191 "%s:Cannot logout from SendTarget entry\n",
6194 goto exit_ddb_logout
;
6197 if (fnode_sess
->is_boot_target
) {
6198 ql4_printk(KERN_ERR
, ha
,
6199 "%s: Logout from boot target entry is not permitted.\n",
6202 goto exit_ddb_logout
;
6205 strncpy(flash_tddb
->iscsi_name
, fnode_sess
->targetname
,
6208 if (!strncmp(fnode_sess
->portal_type
, PORTAL_TYPE_IPV6
, 4))
6209 sprintf(flash_tddb
->ip_addr
, "%pI6", fnode_conn
->ipaddress
);
6211 sprintf(flash_tddb
->ip_addr
, "%pI4", fnode_conn
->ipaddress
);
6213 flash_tddb
->tpgt
= fnode_sess
->tpgt
;
6214 flash_tddb
->port
= fnode_conn
->port
;
6216 COPY_ISID(flash_tddb
->isid
, fnode_sess
->isid
);
6218 for (idx
= 0; idx
< MAX_DDB_ENTRIES
; idx
++) {
6219 ddb_entry
= qla4xxx_lookup_ddb_by_fw_index(ha
, idx
);
6220 if (ddb_entry
== NULL
)
6223 if (ddb_entry
->ddb_type
!= FLASH_DDB
)
6226 index
= ddb_entry
->sess
->target_id
;
6227 status
= qla4xxx_get_fwddb_entry(ha
, index
, fw_ddb_entry
,
6228 fw_ddb_dma
, NULL
, &next_idx
,
6229 &state
, &conn_err
, NULL
,
6231 if (status
== QLA_ERROR
) {
6236 qla4xxx_convert_param_ddb(fw_ddb_entry
, tmp_tddb
, NULL
);
6238 status
= qla4xxx_compare_tuple_ddb(ha
, flash_tddb
, tmp_tddb
,
6240 if (status
== QLA_SUCCESS
) {
6241 ret
= qla4xxx_sysfs_ddb_logout_sid(ddb_entry
->sess
);
6246 if (idx
== MAX_DDB_ENTRIES
)
6255 dma_pool_free(ha
->fw_ddb_dma_pool
, fw_ddb_entry
, fw_ddb_dma
);
6261 qla4xxx_sysfs_ddb_get_param(struct iscsi_bus_flash_session
*fnode_sess
,
6262 int param
, char *buf
)
6264 struct Scsi_Host
*shost
= iscsi_flash_session_to_shost(fnode_sess
);
6265 struct scsi_qla_host
*ha
= to_qla_host(shost
);
6266 struct iscsi_bus_flash_conn
*fnode_conn
;
6267 struct ql4_chap_table chap_tbl
;
6272 dev
= iscsi_find_flashnode_conn(fnode_sess
);
6276 fnode_conn
= iscsi_dev_to_flash_conn(dev
);
6279 case ISCSI_FLASHNODE_IS_FW_ASSIGNED_IPV6
:
6280 rc
= sprintf(buf
, "%u\n", fnode_conn
->is_fw_assigned_ipv6
);
6282 case ISCSI_FLASHNODE_PORTAL_TYPE
:
6283 rc
= sprintf(buf
, "%s\n", fnode_sess
->portal_type
);
6285 case ISCSI_FLASHNODE_AUTO_SND_TGT_DISABLE
:
6286 rc
= sprintf(buf
, "%u\n", fnode_sess
->auto_snd_tgt_disable
);
6288 case ISCSI_FLASHNODE_DISCOVERY_SESS
:
6289 rc
= sprintf(buf
, "%u\n", fnode_sess
->discovery_sess
);
6291 case ISCSI_FLASHNODE_ENTRY_EN
:
6292 rc
= sprintf(buf
, "%u\n", fnode_sess
->entry_state
);
6294 case ISCSI_FLASHNODE_HDR_DGST_EN
:
6295 rc
= sprintf(buf
, "%u\n", fnode_conn
->hdrdgst_en
);
6297 case ISCSI_FLASHNODE_DATA_DGST_EN
:
6298 rc
= sprintf(buf
, "%u\n", fnode_conn
->datadgst_en
);
6300 case ISCSI_FLASHNODE_IMM_DATA_EN
:
6301 rc
= sprintf(buf
, "%u\n", fnode_sess
->imm_data_en
);
6303 case ISCSI_FLASHNODE_INITIAL_R2T_EN
:
6304 rc
= sprintf(buf
, "%u\n", fnode_sess
->initial_r2t_en
);
6306 case ISCSI_FLASHNODE_DATASEQ_INORDER
:
6307 rc
= sprintf(buf
, "%u\n", fnode_sess
->dataseq_inorder_en
);
6309 case ISCSI_FLASHNODE_PDU_INORDER
:
6310 rc
= sprintf(buf
, "%u\n", fnode_sess
->pdu_inorder_en
);
6312 case ISCSI_FLASHNODE_CHAP_AUTH_EN
:
6313 rc
= sprintf(buf
, "%u\n", fnode_sess
->chap_auth_en
);
6315 case ISCSI_FLASHNODE_SNACK_REQ_EN
:
6316 rc
= sprintf(buf
, "%u\n", fnode_conn
->snack_req_en
);
6318 case ISCSI_FLASHNODE_DISCOVERY_LOGOUT_EN
:
6319 rc
= sprintf(buf
, "%u\n", fnode_sess
->discovery_logout_en
);
6321 case ISCSI_FLASHNODE_BIDI_CHAP_EN
:
6322 rc
= sprintf(buf
, "%u\n", fnode_sess
->bidi_chap_en
);
6324 case ISCSI_FLASHNODE_DISCOVERY_AUTH_OPTIONAL
:
6325 rc
= sprintf(buf
, "%u\n", fnode_sess
->discovery_auth_optional
);
6327 case ISCSI_FLASHNODE_ERL
:
6328 rc
= sprintf(buf
, "%u\n", fnode_sess
->erl
);
6330 case ISCSI_FLASHNODE_TCP_TIMESTAMP_STAT
:
6331 rc
= sprintf(buf
, "%u\n", fnode_conn
->tcp_timestamp_stat
);
6333 case ISCSI_FLASHNODE_TCP_NAGLE_DISABLE
:
6334 rc
= sprintf(buf
, "%u\n", fnode_conn
->tcp_nagle_disable
);
6336 case ISCSI_FLASHNODE_TCP_WSF_DISABLE
:
6337 rc
= sprintf(buf
, "%u\n", fnode_conn
->tcp_wsf_disable
);
6339 case ISCSI_FLASHNODE_TCP_TIMER_SCALE
:
6340 rc
= sprintf(buf
, "%u\n", fnode_conn
->tcp_timer_scale
);
6342 case ISCSI_FLASHNODE_TCP_TIMESTAMP_EN
:
6343 rc
= sprintf(buf
, "%u\n", fnode_conn
->tcp_timestamp_en
);
6345 case ISCSI_FLASHNODE_IP_FRAG_DISABLE
:
6346 rc
= sprintf(buf
, "%u\n", fnode_conn
->fragment_disable
);
6348 case ISCSI_FLASHNODE_MAX_RECV_DLENGTH
:
6349 rc
= sprintf(buf
, "%u\n", fnode_conn
->max_recv_dlength
);
6351 case ISCSI_FLASHNODE_MAX_XMIT_DLENGTH
:
6352 rc
= sprintf(buf
, "%u\n", fnode_conn
->max_xmit_dlength
);
6354 case ISCSI_FLASHNODE_FIRST_BURST
:
6355 rc
= sprintf(buf
, "%u\n", fnode_sess
->first_burst
);
6357 case ISCSI_FLASHNODE_DEF_TIME2WAIT
:
6358 rc
= sprintf(buf
, "%u\n", fnode_sess
->time2wait
);
6360 case ISCSI_FLASHNODE_DEF_TIME2RETAIN
:
6361 rc
= sprintf(buf
, "%u\n", fnode_sess
->time2retain
);
6363 case ISCSI_FLASHNODE_MAX_R2T
:
6364 rc
= sprintf(buf
, "%u\n", fnode_sess
->max_r2t
);
6366 case ISCSI_FLASHNODE_KEEPALIVE_TMO
:
6367 rc
= sprintf(buf
, "%u\n", fnode_conn
->keepalive_timeout
);
6369 case ISCSI_FLASHNODE_ISID
:
6370 rc
= sprintf(buf
, "%02x%02x%02x%02x%02x%02x\n",
6371 fnode_sess
->isid
[0], fnode_sess
->isid
[1],
6372 fnode_sess
->isid
[2], fnode_sess
->isid
[3],
6373 fnode_sess
->isid
[4], fnode_sess
->isid
[5]);
6375 case ISCSI_FLASHNODE_TSID
:
6376 rc
= sprintf(buf
, "%u\n", fnode_sess
->tsid
);
6378 case ISCSI_FLASHNODE_PORT
:
6379 rc
= sprintf(buf
, "%d\n", fnode_conn
->port
);
6381 case ISCSI_FLASHNODE_MAX_BURST
:
6382 rc
= sprintf(buf
, "%u\n", fnode_sess
->max_burst
);
6384 case ISCSI_FLASHNODE_DEF_TASKMGMT_TMO
:
6385 rc
= sprintf(buf
, "%u\n",
6386 fnode_sess
->default_taskmgmt_timeout
);
6388 case ISCSI_FLASHNODE_IPADDR
:
6389 if (!strncmp(fnode_sess
->portal_type
, PORTAL_TYPE_IPV6
, 4))
6390 rc
= sprintf(buf
, "%pI6\n", fnode_conn
->ipaddress
);
6392 rc
= sprintf(buf
, "%pI4\n", fnode_conn
->ipaddress
);
6394 case ISCSI_FLASHNODE_ALIAS
:
6395 if (fnode_sess
->targetalias
)
6396 rc
= sprintf(buf
, "%s\n", fnode_sess
->targetalias
);
6398 rc
= sprintf(buf
, "\n");
6400 case ISCSI_FLASHNODE_REDIRECT_IPADDR
:
6401 if (!strncmp(fnode_sess
->portal_type
, PORTAL_TYPE_IPV6
, 4))
6402 rc
= sprintf(buf
, "%pI6\n",
6403 fnode_conn
->redirect_ipaddr
);
6405 rc
= sprintf(buf
, "%pI4\n",
6406 fnode_conn
->redirect_ipaddr
);
6408 case ISCSI_FLASHNODE_MAX_SEGMENT_SIZE
:
6409 rc
= sprintf(buf
, "%u\n", fnode_conn
->max_segment_size
);
6411 case ISCSI_FLASHNODE_LOCAL_PORT
:
6412 rc
= sprintf(buf
, "%u\n", fnode_conn
->local_port
);
6414 case ISCSI_FLASHNODE_IPV4_TOS
:
6415 rc
= sprintf(buf
, "%u\n", fnode_conn
->ipv4_tos
);
6417 case ISCSI_FLASHNODE_IPV6_TC
:
6418 if (!strncmp(fnode_sess
->portal_type
, PORTAL_TYPE_IPV6
, 4))
6419 rc
= sprintf(buf
, "%u\n",
6420 fnode_conn
->ipv6_traffic_class
);
6422 rc
= sprintf(buf
, "\n");
6424 case ISCSI_FLASHNODE_IPV6_FLOW_LABEL
:
6425 rc
= sprintf(buf
, "%u\n", fnode_conn
->ipv6_flow_label
);
6427 case ISCSI_FLASHNODE_LINK_LOCAL_IPV6
:
6428 if (!strncmp(fnode_sess
->portal_type
, PORTAL_TYPE_IPV6
, 4))
6429 rc
= sprintf(buf
, "%pI6\n",
6430 fnode_conn
->link_local_ipv6_addr
);
6432 rc
= sprintf(buf
, "\n");
6434 case ISCSI_FLASHNODE_DISCOVERY_PARENT_IDX
:
6435 rc
= sprintf(buf
, "%u\n", fnode_sess
->discovery_parent_idx
);
6437 case ISCSI_FLASHNODE_DISCOVERY_PARENT_TYPE
:
6438 if (fnode_sess
->discovery_parent_type
== DDB_ISNS
)
6439 parent_type
= ISCSI_DISC_PARENT_ISNS
;
6440 else if (fnode_sess
->discovery_parent_type
== DDB_NO_LINK
)
6441 parent_type
= ISCSI_DISC_PARENT_UNKNOWN
;
6442 else if (fnode_sess
->discovery_parent_type
< MAX_DDB_ENTRIES
)
6443 parent_type
= ISCSI_DISC_PARENT_SENDTGT
;
6445 parent_type
= ISCSI_DISC_PARENT_UNKNOWN
;
6447 rc
= sprintf(buf
, "%s\n",
6448 iscsi_get_discovery_parent_name(parent_type
));
6450 case ISCSI_FLASHNODE_NAME
:
6451 if (fnode_sess
->targetname
)
6452 rc
= sprintf(buf
, "%s\n", fnode_sess
->targetname
);
6454 rc
= sprintf(buf
, "\n");
6456 case ISCSI_FLASHNODE_TPGT
:
6457 rc
= sprintf(buf
, "%u\n", fnode_sess
->tpgt
);
6459 case ISCSI_FLASHNODE_TCP_XMIT_WSF
:
6460 rc
= sprintf(buf
, "%u\n", fnode_conn
->tcp_xmit_wsf
);
6462 case ISCSI_FLASHNODE_TCP_RECV_WSF
:
6463 rc
= sprintf(buf
, "%u\n", fnode_conn
->tcp_recv_wsf
);
6465 case ISCSI_FLASHNODE_CHAP_OUT_IDX
:
6466 rc
= sprintf(buf
, "%u\n", fnode_sess
->chap_out_idx
);
6468 case ISCSI_FLASHNODE_USERNAME
:
6469 if (fnode_sess
->chap_auth_en
) {
6470 qla4xxx_get_uni_chap_at_index(ha
,
6473 fnode_sess
->chap_out_idx
);
6474 rc
= sprintf(buf
, "%s\n", chap_tbl
.name
);
6476 rc
= sprintf(buf
, "\n");
6479 case ISCSI_FLASHNODE_PASSWORD
:
6480 if (fnode_sess
->chap_auth_en
) {
6481 qla4xxx_get_uni_chap_at_index(ha
,
6484 fnode_sess
->chap_out_idx
);
6485 rc
= sprintf(buf
, "%s\n", chap_tbl
.secret
);
6487 rc
= sprintf(buf
, "\n");
6490 case ISCSI_FLASHNODE_STATSN
:
6491 rc
= sprintf(buf
, "%u\n", fnode_conn
->statsn
);
6493 case ISCSI_FLASHNODE_EXP_STATSN
:
6494 rc
= sprintf(buf
, "%u\n", fnode_conn
->exp_statsn
);
6496 case ISCSI_FLASHNODE_IS_BOOT_TGT
:
6497 rc
= sprintf(buf
, "%u\n", fnode_sess
->is_boot_target
);
6509 * qla4xxx_sysfs_ddb_set_param - Set parameter for firmware DDB entry
6510 * @fnode_sess: pointer to session attrs of flash ddb entry
6511 * @fnode_conn: pointer to connection attrs of flash ddb entry
6512 * @data: Parameters and their values to update
6515 * This sets the parameter of flash ddb entry and writes them to flash
6518 qla4xxx_sysfs_ddb_set_param(struct iscsi_bus_flash_session
*fnode_sess
,
6519 struct iscsi_bus_flash_conn
*fnode_conn
,
6520 void *data
, int len
)
6522 struct Scsi_Host
*shost
= iscsi_flash_session_to_shost(fnode_sess
);
6523 struct scsi_qla_host
*ha
= to_qla_host(shost
);
6524 struct iscsi_flashnode_param_info
*fnode_param
;
6525 struct nlattr
*attr
;
6529 nla_for_each_attr(attr
, data
, len
, rem
) {
6530 fnode_param
= nla_data(attr
);
6532 switch (fnode_param
->param
) {
6533 case ISCSI_FLASHNODE_IS_FW_ASSIGNED_IPV6
:
6534 fnode_conn
->is_fw_assigned_ipv6
= fnode_param
->value
[0];
6536 case ISCSI_FLASHNODE_PORTAL_TYPE
:
6537 memcpy(fnode_sess
->portal_type
, fnode_param
->value
,
6538 strlen(fnode_sess
->portal_type
));
6540 case ISCSI_FLASHNODE_AUTO_SND_TGT_DISABLE
:
6541 fnode_sess
->auto_snd_tgt_disable
=
6542 fnode_param
->value
[0];
6544 case ISCSI_FLASHNODE_DISCOVERY_SESS
:
6545 fnode_sess
->discovery_sess
= fnode_param
->value
[0];
6547 case ISCSI_FLASHNODE_ENTRY_EN
:
6548 fnode_sess
->entry_state
= fnode_param
->value
[0];
6550 case ISCSI_FLASHNODE_HDR_DGST_EN
:
6551 fnode_conn
->hdrdgst_en
= fnode_param
->value
[0];
6553 case ISCSI_FLASHNODE_DATA_DGST_EN
:
6554 fnode_conn
->datadgst_en
= fnode_param
->value
[0];
6556 case ISCSI_FLASHNODE_IMM_DATA_EN
:
6557 fnode_sess
->imm_data_en
= fnode_param
->value
[0];
6559 case ISCSI_FLASHNODE_INITIAL_R2T_EN
:
6560 fnode_sess
->initial_r2t_en
= fnode_param
->value
[0];
6562 case ISCSI_FLASHNODE_DATASEQ_INORDER
:
6563 fnode_sess
->dataseq_inorder_en
= fnode_param
->value
[0];
6565 case ISCSI_FLASHNODE_PDU_INORDER
:
6566 fnode_sess
->pdu_inorder_en
= fnode_param
->value
[0];
6568 case ISCSI_FLASHNODE_CHAP_AUTH_EN
:
6569 fnode_sess
->chap_auth_en
= fnode_param
->value
[0];
6571 case ISCSI_FLASHNODE_SNACK_REQ_EN
:
6572 fnode_conn
->snack_req_en
= fnode_param
->value
[0];
6574 case ISCSI_FLASHNODE_DISCOVERY_LOGOUT_EN
:
6575 fnode_sess
->discovery_logout_en
= fnode_param
->value
[0];
6577 case ISCSI_FLASHNODE_BIDI_CHAP_EN
:
6578 fnode_sess
->bidi_chap_en
= fnode_param
->value
[0];
6580 case ISCSI_FLASHNODE_DISCOVERY_AUTH_OPTIONAL
:
6581 fnode_sess
->discovery_auth_optional
=
6582 fnode_param
->value
[0];
6584 case ISCSI_FLASHNODE_ERL
:
6585 fnode_sess
->erl
= fnode_param
->value
[0];
6587 case ISCSI_FLASHNODE_TCP_TIMESTAMP_STAT
:
6588 fnode_conn
->tcp_timestamp_stat
= fnode_param
->value
[0];
6590 case ISCSI_FLASHNODE_TCP_NAGLE_DISABLE
:
6591 fnode_conn
->tcp_nagle_disable
= fnode_param
->value
[0];
6593 case ISCSI_FLASHNODE_TCP_WSF_DISABLE
:
6594 fnode_conn
->tcp_wsf_disable
= fnode_param
->value
[0];
6596 case ISCSI_FLASHNODE_TCP_TIMER_SCALE
:
6597 fnode_conn
->tcp_timer_scale
= fnode_param
->value
[0];
6599 case ISCSI_FLASHNODE_TCP_TIMESTAMP_EN
:
6600 fnode_conn
->tcp_timestamp_en
= fnode_param
->value
[0];
6602 case ISCSI_FLASHNODE_IP_FRAG_DISABLE
:
6603 fnode_conn
->fragment_disable
= fnode_param
->value
[0];
6605 case ISCSI_FLASHNODE_MAX_RECV_DLENGTH
:
6606 fnode_conn
->max_recv_dlength
=
6607 *(unsigned *)fnode_param
->value
;
6609 case ISCSI_FLASHNODE_MAX_XMIT_DLENGTH
:
6610 fnode_conn
->max_xmit_dlength
=
6611 *(unsigned *)fnode_param
->value
;
6613 case ISCSI_FLASHNODE_FIRST_BURST
:
6614 fnode_sess
->first_burst
=
6615 *(unsigned *)fnode_param
->value
;
6617 case ISCSI_FLASHNODE_DEF_TIME2WAIT
:
6618 fnode_sess
->time2wait
= *(uint16_t *)fnode_param
->value
;
6620 case ISCSI_FLASHNODE_DEF_TIME2RETAIN
:
6621 fnode_sess
->time2retain
=
6622 *(uint16_t *)fnode_param
->value
;
6624 case ISCSI_FLASHNODE_MAX_R2T
:
6625 fnode_sess
->max_r2t
=
6626 *(uint16_t *)fnode_param
->value
;
6628 case ISCSI_FLASHNODE_KEEPALIVE_TMO
:
6629 fnode_conn
->keepalive_timeout
=
6630 *(uint16_t *)fnode_param
->value
;
6632 case ISCSI_FLASHNODE_ISID
:
6633 memcpy(fnode_sess
->isid
, fnode_param
->value
,
6634 sizeof(fnode_sess
->isid
));
6636 case ISCSI_FLASHNODE_TSID
:
6637 fnode_sess
->tsid
= *(uint16_t *)fnode_param
->value
;
6639 case ISCSI_FLASHNODE_PORT
:
6640 fnode_conn
->port
= *(uint16_t *)fnode_param
->value
;
6642 case ISCSI_FLASHNODE_MAX_BURST
:
6643 fnode_sess
->max_burst
= *(unsigned *)fnode_param
->value
;
6645 case ISCSI_FLASHNODE_DEF_TASKMGMT_TMO
:
6646 fnode_sess
->default_taskmgmt_timeout
=
6647 *(uint16_t *)fnode_param
->value
;
6649 case ISCSI_FLASHNODE_IPADDR
:
6650 memcpy(fnode_conn
->ipaddress
, fnode_param
->value
,
6653 case ISCSI_FLASHNODE_ALIAS
:
6654 rc
= iscsi_switch_str_param(&fnode_sess
->targetalias
,
6655 (char *)fnode_param
->value
);
6657 case ISCSI_FLASHNODE_REDIRECT_IPADDR
:
6658 memcpy(fnode_conn
->redirect_ipaddr
, fnode_param
->value
,
6661 case ISCSI_FLASHNODE_MAX_SEGMENT_SIZE
:
6662 fnode_conn
->max_segment_size
=
6663 *(unsigned *)fnode_param
->value
;
6665 case ISCSI_FLASHNODE_LOCAL_PORT
:
6666 fnode_conn
->local_port
=
6667 *(uint16_t *)fnode_param
->value
;
6669 case ISCSI_FLASHNODE_IPV4_TOS
:
6670 fnode_conn
->ipv4_tos
= fnode_param
->value
[0];
6672 case ISCSI_FLASHNODE_IPV6_TC
:
6673 fnode_conn
->ipv6_traffic_class
= fnode_param
->value
[0];
6675 case ISCSI_FLASHNODE_IPV6_FLOW_LABEL
:
6676 fnode_conn
->ipv6_flow_label
= fnode_param
->value
[0];
6678 case ISCSI_FLASHNODE_NAME
:
6679 rc
= iscsi_switch_str_param(&fnode_sess
->targetname
,
6680 (char *)fnode_param
->value
);
6682 case ISCSI_FLASHNODE_TPGT
:
6683 fnode_sess
->tpgt
= *(uint16_t *)fnode_param
->value
;
6685 case ISCSI_FLASHNODE_LINK_LOCAL_IPV6
:
6686 memcpy(fnode_conn
->link_local_ipv6_addr
,
6687 fnode_param
->value
, IPv6_ADDR_LEN
);
6689 case ISCSI_FLASHNODE_DISCOVERY_PARENT_IDX
:
6690 fnode_sess
->discovery_parent_idx
=
6691 *(uint16_t *)fnode_param
->value
;
6693 case ISCSI_FLASHNODE_TCP_XMIT_WSF
:
6694 fnode_conn
->tcp_xmit_wsf
=
6695 *(uint8_t *)fnode_param
->value
;
6697 case ISCSI_FLASHNODE_TCP_RECV_WSF
:
6698 fnode_conn
->tcp_recv_wsf
=
6699 *(uint8_t *)fnode_param
->value
;
6701 case ISCSI_FLASHNODE_STATSN
:
6702 fnode_conn
->statsn
= *(uint32_t *)fnode_param
->value
;
6704 case ISCSI_FLASHNODE_EXP_STATSN
:
6705 fnode_conn
->exp_statsn
=
6706 *(uint32_t *)fnode_param
->value
;
6709 ql4_printk(KERN_ERR
, ha
,
6710 "%s: No such sysfs attribute\n", __func__
);
6712 goto exit_set_param
;
6716 rc
= qla4xxx_sysfs_ddb_apply(fnode_sess
, fnode_conn
);
6723 * qla4xxx_sysfs_ddb_delete - Delete firmware DDB entry
6724 * @fnode_sess: pointer to session attrs of flash ddb entry
6726 * This invalidates the flash ddb entry at the given index
6728 static int qla4xxx_sysfs_ddb_delete(struct iscsi_bus_flash_session
*fnode_sess
)
6730 struct Scsi_Host
*shost
= iscsi_flash_session_to_shost(fnode_sess
);
6731 struct scsi_qla_host
*ha
= to_qla_host(shost
);
6732 uint32_t dev_db_start_offset
;
6733 uint32_t dev_db_end_offset
;
6734 struct dev_db_entry
*fw_ddb_entry
= NULL
;
6735 dma_addr_t fw_ddb_entry_dma
;
6736 uint16_t *ddb_cookie
= NULL
;
6737 size_t ddb_size
= 0;
6742 if (fnode_sess
->is_boot_target
) {
6744 DEBUG2(ql4_printk(KERN_ERR
, ha
,
6745 "%s: Deletion of boot target entry is not permitted.\n",
6750 if (fnode_sess
->flash_state
== DEV_DB_NON_PERSISTENT
)
6753 if (is_qla40XX(ha
)) {
6754 dev_db_start_offset
= FLASH_OFFSET_DB_INFO
;
6755 dev_db_end_offset
= FLASH_OFFSET_DB_END
;
6756 dev_db_start_offset
+= (fnode_sess
->target_id
*
6757 sizeof(*fw_ddb_entry
));
6758 ddb_size
= sizeof(*fw_ddb_entry
);
6760 dev_db_start_offset
= FLASH_RAW_ACCESS_ADDR
+
6761 (ha
->hw
.flt_region_ddb
<< 2);
6762 /* flt_ddb_size is DDB table size for both ports
6763 * so divide it by 2 to calculate the offset for second port
6765 if (ha
->port_num
== 1)
6766 dev_db_start_offset
+= (ha
->hw
.flt_ddb_size
/ 2);
6768 dev_db_end_offset
= dev_db_start_offset
+
6769 (ha
->hw
.flt_ddb_size
/ 2);
6771 dev_db_start_offset
+= (fnode_sess
->target_id
*
6772 sizeof(*fw_ddb_entry
));
6773 dev_db_start_offset
+= offsetof(struct dev_db_entry
, cookie
);
6775 ddb_size
= sizeof(*ddb_cookie
);
6778 DEBUG2(ql4_printk(KERN_ERR
, ha
, "%s: start offset=%u, end offset=%u\n",
6779 __func__
, dev_db_start_offset
, dev_db_end_offset
));
6781 if (dev_db_start_offset
> dev_db_end_offset
) {
6783 DEBUG2(ql4_printk(KERN_ERR
, ha
, "%s:Invalid DDB index %u\n",
6784 __func__
, fnode_sess
->target_id
));
6788 pddb
= dma_alloc_coherent(&ha
->pdev
->dev
, ddb_size
,
6789 &fw_ddb_entry_dma
, GFP_KERNEL
);
6792 DEBUG2(ql4_printk(KERN_ERR
, ha
,
6793 "%s: Unable to allocate dma buffer\n",
6798 if (is_qla40XX(ha
)) {
6799 fw_ddb_entry
= pddb
;
6800 memset(fw_ddb_entry
, 0, ddb_size
);
6801 ddb_cookie
= &fw_ddb_entry
->cookie
;
6806 /* invalidate the cookie */
6807 *ddb_cookie
= 0xFFEE;
6808 qla4xxx_set_flash(ha
, fw_ddb_entry_dma
, dev_db_start_offset
,
6809 ddb_size
, FLASH_OPT_RMW_COMMIT
);
6812 target_id
= fnode_sess
->target_id
;
6813 iscsi_destroy_flashnode_sess(fnode_sess
);
6814 ql4_printk(KERN_INFO
, ha
,
6815 "%s: session and conn entries for flashnode %u of host %lu deleted\n",
6816 __func__
, target_id
, ha
->host_no
);
6819 dma_free_coherent(&ha
->pdev
->dev
, ddb_size
, pddb
,
6825 * qla4xxx_sysfs_ddb_export - Create sysfs entries for firmware DDBs
6826 * @ha: pointer to adapter structure
6828 * Export the firmware DDB for all send targets and normal targets to sysfs.
6830 static int qla4xxx_sysfs_ddb_export(struct scsi_qla_host
*ha
)
6832 struct dev_db_entry
*fw_ddb_entry
= NULL
;
6833 dma_addr_t fw_ddb_entry_dma
;
6836 int ret
= QLA_SUCCESS
;
6838 fw_ddb_entry
= dma_alloc_coherent(&ha
->pdev
->dev
,
6839 sizeof(*fw_ddb_entry
),
6840 &fw_ddb_entry_dma
, GFP_KERNEL
);
6841 if (!fw_ddb_entry
) {
6842 DEBUG2(ql4_printk(KERN_ERR
, ha
,
6843 "%s: Unable to allocate dma buffer\n",
6848 max_ddbs
= is_qla40XX(ha
) ? MAX_PRST_DEV_DB_ENTRIES
:
6851 for (idx
= 0; idx
< max_ddbs
; idx
++) {
6852 if (qla4xxx_flashdb_by_index(ha
, fw_ddb_entry
, fw_ddb_entry_dma
,
6856 ret
= qla4xxx_sysfs_ddb_tgt_create(ha
, fw_ddb_entry
, &idx
, 0);
6863 dma_free_coherent(&ha
->pdev
->dev
, sizeof(*fw_ddb_entry
), fw_ddb_entry
,
6869 static void qla4xxx_sysfs_ddb_remove(struct scsi_qla_host
*ha
)
6871 iscsi_destroy_all_flashnode(ha
->host
);
6875 * qla4xxx_build_ddb_list - Build ddb list and setup sessions
6876 * @ha: pointer to adapter structure
6877 * @is_reset: Is this init path or reset path
6879 * Create a list of sendtargets (st) from firmware DDBs, issue send targets
6880 * using connection open, then create the list of normal targets (nt)
6881 * from firmware DDBs. Based on the list of nt setup session and connection
6884 void qla4xxx_build_ddb_list(struct scsi_qla_host
*ha
, int is_reset
)
6887 struct list_head list_st
, list_nt
;
6888 struct qla_ddb_index
*st_ddb_idx
, *st_ddb_idx_tmp
;
6889 unsigned long wtime
;
6891 if (!test_bit(AF_LINK_UP
, &ha
->flags
)) {
6892 set_bit(AF_BUILD_DDB_LIST
, &ha
->flags
);
6893 ha
->is_reset
= is_reset
;
6897 INIT_LIST_HEAD(&list_st
);
6898 INIT_LIST_HEAD(&list_nt
);
6900 qla4xxx_build_st_list(ha
, &list_st
);
6902 /* Before issuing conn open mbox, ensure all IPs states are configured
6903 * Note, conn open fails if IPs are not configured
6905 qla4xxx_wait_for_ip_configuration(ha
);
6907 /* Go thru the STs and fire the sendtargets by issuing conn open mbx */
6908 list_for_each_entry_safe(st_ddb_idx
, st_ddb_idx_tmp
, &list_st
, list
) {
6909 qla4xxx_conn_open(ha
, st_ddb_idx
->fw_ddb_idx
);
6912 /* Wait to ensure all sendtargets are done for min 12 sec wait */
6913 tmo
= ((ha
->def_timeout
> LOGIN_TOV
) &&
6914 (ha
->def_timeout
< LOGIN_TOV
* 10) ?
6915 ha
->def_timeout
: LOGIN_TOV
);
6917 DEBUG2(ql4_printk(KERN_INFO
, ha
,
6918 "Default time to wait for build ddb %d\n", tmo
));
6920 wtime
= jiffies
+ (HZ
* tmo
);
6922 if (list_empty(&list_st
))
6925 qla4xxx_remove_failed_ddb(ha
, &list_st
);
6926 schedule_timeout_uninterruptible(HZ
/ 10);
6927 } while (time_after(wtime
, jiffies
));
6929 /* Free up the sendtargets list */
6930 qla4xxx_free_ddb_list(&list_st
);
6932 qla4xxx_build_nt_list(ha
, &list_nt
, is_reset
);
6934 qla4xxx_free_ddb_list(&list_nt
);
6936 qla4xxx_free_ddb_index(ha
);
6940 * qla4xxx_wait_login_resp_boot_tgt - Wait for iSCSI boot target login
6942 * @ha: pointer to adapter structure
6944 * When the boot entry is normal iSCSI target then DF_BOOT_TGT flag will be
6945 * set in DDB and we will wait for login response of boot targets during
6948 static void qla4xxx_wait_login_resp_boot_tgt(struct scsi_qla_host
*ha
)
6950 struct ddb_entry
*ddb_entry
;
6951 struct dev_db_entry
*fw_ddb_entry
= NULL
;
6952 dma_addr_t fw_ddb_entry_dma
;
6953 unsigned long wtime
;
6955 int max_ddbs
, idx
, ret
;
6957 max_ddbs
= is_qla40XX(ha
) ? MAX_DEV_DB_ENTRIES_40XX
:
6960 fw_ddb_entry
= dma_alloc_coherent(&ha
->pdev
->dev
, sizeof(*fw_ddb_entry
),
6961 &fw_ddb_entry_dma
, GFP_KERNEL
);
6962 if (!fw_ddb_entry
) {
6963 ql4_printk(KERN_ERR
, ha
,
6964 "%s: Unable to allocate dma buffer\n", __func__
);
6965 goto exit_login_resp
;
6968 wtime
= jiffies
+ (HZ
* BOOT_LOGIN_RESP_TOV
);
6970 for (idx
= 0; idx
< max_ddbs
; idx
++) {
6971 ddb_entry
= qla4xxx_lookup_ddb_by_fw_index(ha
, idx
);
6972 if (ddb_entry
== NULL
)
6975 if (test_bit(DF_BOOT_TGT
, &ddb_entry
->flags
)) {
6976 DEBUG2(ql4_printk(KERN_INFO
, ha
,
6977 "%s: DDB index [%d]\n", __func__
,
6978 ddb_entry
->fw_ddb_index
));
6980 ret
= qla4xxx_get_fwddb_entry(ha
,
6981 ddb_entry
->fw_ddb_index
,
6982 fw_ddb_entry
, fw_ddb_entry_dma
,
6983 NULL
, NULL
, &ddb_state
, NULL
,
6985 if (ret
== QLA_ERROR
)
6986 goto exit_login_resp
;
6988 if ((ddb_state
== DDB_DS_SESSION_ACTIVE
) ||
6989 (ddb_state
== DDB_DS_SESSION_FAILED
))
6992 schedule_timeout_uninterruptible(HZ
);
6994 } while ((time_after(wtime
, jiffies
)));
6996 if (!time_after(wtime
, jiffies
)) {
6997 DEBUG2(ql4_printk(KERN_INFO
, ha
,
6998 "%s: Login response wait timer expired\n",
7000 goto exit_login_resp
;
7007 dma_free_coherent(&ha
->pdev
->dev
, sizeof(*fw_ddb_entry
),
7008 fw_ddb_entry
, fw_ddb_entry_dma
);
7012 * qla4xxx_probe_adapter - callback function to probe HBA
7013 * @pdev: pointer to pci_dev structure
7014 * @pci_device_id: pointer to pci_device entry
7016 * This routine will probe for Qlogic 4xxx iSCSI host adapters.
7017 * It returns zero if successful. It also initializes all data necessary for
7020 static int qla4xxx_probe_adapter(struct pci_dev
*pdev
,
7021 const struct pci_device_id
*ent
)
7023 int ret
= -ENODEV
, status
;
7024 struct Scsi_Host
*host
;
7025 struct scsi_qla_host
*ha
;
7026 uint8_t init_retry_count
= 0;
7028 struct qla4_8xxx_legacy_intr_set
*nx_legacy_intr
;
7031 if (pci_enable_device(pdev
))
7034 host
= iscsi_host_alloc(&qla4xxx_driver_template
, sizeof(*ha
), 0);
7037 "qla4xxx: Couldn't allocate host from scsi layer!\n");
7038 goto probe_disable_device
;
7041 /* Clear our data area */
7042 ha
= to_qla_host(host
);
7043 memset(ha
, 0, sizeof(*ha
));
7045 /* Save the information from PCI BIOS. */
7048 ha
->host_no
= host
->host_no
;
7049 ha
->func_num
= PCI_FUNC(ha
->pdev
->devfn
);
7051 pci_enable_pcie_error_reporting(pdev
);
7053 /* Setup Runtime configurable options */
7054 if (is_qla8022(ha
)) {
7055 ha
->isp_ops
= &qla4_82xx_isp_ops
;
7056 ha
->reg_tbl
= (uint32_t *) qla4_82xx_reg_tbl
;
7057 ha
->qdr_sn_window
= -1;
7058 ha
->ddr_mn_window
= -1;
7059 ha
->curr_window
= 255;
7060 nx_legacy_intr
= &legacy_intr
[ha
->func_num
];
7061 ha
->nx_legacy_intr
.int_vec_bit
= nx_legacy_intr
->int_vec_bit
;
7062 ha
->nx_legacy_intr
.tgt_status_reg
=
7063 nx_legacy_intr
->tgt_status_reg
;
7064 ha
->nx_legacy_intr
.tgt_mask_reg
= nx_legacy_intr
->tgt_mask_reg
;
7065 ha
->nx_legacy_intr
.pci_int_reg
= nx_legacy_intr
->pci_int_reg
;
7066 } else if (is_qla8032(ha
) || is_qla8042(ha
)) {
7067 ha
->isp_ops
= &qla4_83xx_isp_ops
;
7068 ha
->reg_tbl
= (uint32_t *)qla4_83xx_reg_tbl
;
7070 ha
->isp_ops
= &qla4xxx_isp_ops
;
7073 if (is_qla80XX(ha
)) {
7074 rwlock_init(&ha
->hw_lock
);
7075 ha
->pf_bit
= ha
->func_num
<< 16;
7076 /* Set EEH reset type to fundamental if required by hba */
7077 pdev
->needs_freset
= 1;
7080 /* Configure PCI I/O space. */
7081 ret
= ha
->isp_ops
->iospace_config(ha
);
7083 goto probe_failed_ioconfig
;
7085 ql4_printk(KERN_INFO
, ha
, "Found an ISP%04x, irq %d, iobase 0x%p\n",
7086 pdev
->device
, pdev
->irq
, ha
->reg
);
7088 qla4xxx_config_dma_addressing(ha
);
7090 /* Initialize lists and spinlocks. */
7091 INIT_LIST_HEAD(&ha
->free_srb_q
);
7093 mutex_init(&ha
->mbox_sem
);
7094 mutex_init(&ha
->chap_sem
);
7095 init_completion(&ha
->mbx_intr_comp
);
7096 init_completion(&ha
->disable_acb_comp
);
7098 spin_lock_init(&ha
->hardware_lock
);
7099 spin_lock_init(&ha
->work_lock
);
7101 /* Initialize work list */
7102 INIT_LIST_HEAD(&ha
->work_list
);
7104 /* Allocate dma buffers */
7105 if (qla4xxx_mem_alloc(ha
)) {
7106 ql4_printk(KERN_WARNING
, ha
,
7107 "[ERROR] Failed to allocate memory for adapter\n");
7113 host
->cmd_per_lun
= 3;
7114 host
->max_channel
= 0;
7115 host
->max_lun
= MAX_LUNS
- 1;
7116 host
->max_id
= MAX_TARGETS
;
7117 host
->max_cmd_len
= IOCB_MAX_CDB_LEN
;
7118 host
->can_queue
= MAX_SRBS
;
7119 host
->transportt
= qla4xxx_scsi_transport
;
7121 ret
= scsi_init_shared_tag_map(host
, MAX_SRBS
);
7123 ql4_printk(KERN_WARNING
, ha
,
7124 "%s: scsi_init_shared_tag_map failed\n", __func__
);
7128 pci_set_drvdata(pdev
, ha
);
7130 ret
= scsi_add_host(host
, &pdev
->dev
);
7135 qla4_8xxx_get_flash_info(ha
);
7137 if (is_qla8032(ha
) || is_qla8042(ha
)) {
7138 qla4_83xx_read_reset_template(ha
);
7140 * NOTE: If ql4dontresethba==1, set IDC_CTRL DONTRESET_BIT0.
7141 * If DONRESET_BIT0 is set, drivers should not set dev_state
7142 * to NEED_RESET. But if NEED_RESET is set, drivers should
7143 * should honor the reset.
7145 if (ql4xdontresethba
== 1)
7146 qla4_83xx_set_idc_dontreset(ha
);
7150 * Initialize the Host adapter request/response queues and
7152 * NOTE: interrupts enabled upon successful completion
7154 status
= qla4xxx_initialize_adapter(ha
, INIT_ADAPTER
);
7156 /* Dont retry adapter initialization if IRQ allocation failed */
7157 if (is_qla80XX(ha
) && !test_bit(AF_IRQ_ATTACHED
, &ha
->flags
)) {
7158 ql4_printk(KERN_WARNING
, ha
, "%s: Skipping retry of adapter initialization\n",
7160 goto skip_retry_init
;
7163 while ((!test_bit(AF_ONLINE
, &ha
->flags
)) &&
7164 init_retry_count
++ < MAX_INIT_RETRIES
) {
7166 if (is_qla80XX(ha
)) {
7167 ha
->isp_ops
->idc_lock(ha
);
7168 dev_state
= qla4_8xxx_rd_direct(ha
,
7169 QLA8XXX_CRB_DEV_STATE
);
7170 ha
->isp_ops
->idc_unlock(ha
);
7171 if (dev_state
== QLA8XXX_DEV_FAILED
) {
7172 ql4_printk(KERN_WARNING
, ha
, "%s: don't retry "
7173 "initialize adapter. H/W is in failed state\n",
7178 DEBUG2(printk("scsi: %s: retrying adapter initialization "
7179 "(%d)\n", __func__
, init_retry_count
));
7181 if (ha
->isp_ops
->reset_chip(ha
) == QLA_ERROR
)
7184 status
= qla4xxx_initialize_adapter(ha
, INIT_ADAPTER
);
7188 if (!test_bit(AF_ONLINE
, &ha
->flags
)) {
7189 ql4_printk(KERN_WARNING
, ha
, "Failed to initialize adapter\n");
7191 if ((is_qla8022(ha
) && ql4xdontresethba
) ||
7192 ((is_qla8032(ha
) || is_qla8042(ha
)) &&
7193 qla4_83xx_idc_dontreset(ha
))) {
7194 /* Put the device in failed state. */
7195 DEBUG2(printk(KERN_ERR
"HW STATE: FAILED\n"));
7196 ha
->isp_ops
->idc_lock(ha
);
7197 qla4_8xxx_wr_direct(ha
, QLA8XXX_CRB_DEV_STATE
,
7198 QLA8XXX_DEV_FAILED
);
7199 ha
->isp_ops
->idc_unlock(ha
);
7205 /* Startup the kernel thread for this host adapter. */
7206 DEBUG2(printk("scsi: %s: Starting kernel thread for "
7207 "qla4xxx_dpc\n", __func__
));
7208 sprintf(buf
, "qla4xxx_%lu_dpc", ha
->host_no
);
7209 ha
->dpc_thread
= create_singlethread_workqueue(buf
);
7210 if (!ha
->dpc_thread
) {
7211 ql4_printk(KERN_WARNING
, ha
, "Unable to start DPC thread!\n");
7215 INIT_WORK(&ha
->dpc_work
, qla4xxx_do_dpc
);
7217 ha
->task_wq
= alloc_workqueue("qla4xxx_%lu_task", WQ_MEM_RECLAIM
, 1,
7220 ql4_printk(KERN_WARNING
, ha
, "Unable to start task thread!\n");
7226 * For ISP-8XXX, request_irqs is called in qla4_8xxx_load_risc
7227 * (which is called indirectly by qla4xxx_initialize_adapter),
7228 * so that irqs will be registered after crbinit but before
7231 if (is_qla40XX(ha
)) {
7232 ret
= qla4xxx_request_irqs(ha
);
7234 ql4_printk(KERN_WARNING
, ha
, "Failed to reserve "
7235 "interrupt %d already in use.\n", pdev
->irq
);
7240 pci_save_state(ha
->pdev
);
7241 ha
->isp_ops
->enable_intrs(ha
);
7243 /* Start timer thread. */
7244 qla4xxx_start_timer(ha
, qla4xxx_timer
, 1);
7246 set_bit(AF_INIT_DONE
, &ha
->flags
);
7248 qla4_8xxx_alloc_sysfs_attr(ha
);
7251 " QLogic iSCSI HBA Driver version: %s\n"
7252 " QLogic ISP%04x @ %s, host#=%ld, fw=%02d.%02d.%02d.%02d\n",
7253 qla4xxx_version_str
, ha
->pdev
->device
, pci_name(ha
->pdev
),
7254 ha
->host_no
, ha
->fw_info
.fw_major
, ha
->fw_info
.fw_minor
,
7255 ha
->fw_info
.fw_patch
, ha
->fw_info
.fw_build
);
7257 /* Set the driver version */
7259 qla4_8xxx_set_param(ha
, SET_DRVR_VERSION
);
7261 if (qla4xxx_setup_boot_info(ha
))
7262 ql4_printk(KERN_ERR
, ha
,
7263 "%s: No iSCSI boot target configured\n", __func__
);
7265 if (qla4xxx_sysfs_ddb_export(ha
))
7266 ql4_printk(KERN_ERR
, ha
,
7267 "%s: Error exporting ddb to sysfs\n", __func__
);
7269 /* Perform the build ddb list and login to each */
7270 qla4xxx_build_ddb_list(ha
, INIT_ADAPTER
);
7271 iscsi_host_for_each_session(ha
->host
, qla4xxx_login_flash_ddb
);
7272 qla4xxx_wait_login_resp_boot_tgt(ha
);
7274 qla4xxx_create_chap_list(ha
);
7276 qla4xxx_create_ifaces(ha
);
7280 scsi_remove_host(ha
->host
);
7283 qla4xxx_free_adapter(ha
);
7285 probe_failed_ioconfig
:
7286 pci_disable_pcie_error_reporting(pdev
);
7287 scsi_host_put(ha
->host
);
7289 probe_disable_device
:
7290 pci_disable_device(pdev
);
7296 * qla4xxx_prevent_other_port_reinit - prevent other port from re-initialize
7297 * @ha: pointer to adapter structure
7299 * Mark the other ISP-4xxx port to indicate that the driver is being removed,
7300 * so that the other port will not re-initialize while in the process of
7301 * removing the ha due to driver unload or hba hotplug.
7303 static void qla4xxx_prevent_other_port_reinit(struct scsi_qla_host
*ha
)
7305 struct scsi_qla_host
*other_ha
= NULL
;
7306 struct pci_dev
*other_pdev
= NULL
;
7307 int fn
= ISP4XXX_PCI_FN_2
;
7309 /*iscsi function numbers for ISP4xxx is 1 and 3*/
7310 if (PCI_FUNC(ha
->pdev
->devfn
) & BIT_1
)
7311 fn
= ISP4XXX_PCI_FN_1
;
7314 pci_get_domain_bus_and_slot(pci_domain_nr(ha
->pdev
->bus
),
7315 ha
->pdev
->bus
->number
, PCI_DEVFN(PCI_SLOT(ha
->pdev
->devfn
),
7318 /* Get other_ha if other_pdev is valid and state is enable*/
7320 if (atomic_read(&other_pdev
->enable_cnt
)) {
7321 other_ha
= pci_get_drvdata(other_pdev
);
7323 set_bit(AF_HA_REMOVAL
, &other_ha
->flags
);
7324 DEBUG2(ql4_printk(KERN_INFO
, ha
, "%s: "
7325 "Prevent %s reinit\n", __func__
,
7326 dev_name(&other_ha
->pdev
->dev
)));
7329 pci_dev_put(other_pdev
);
7333 static void qla4xxx_destroy_fw_ddb_session(struct scsi_qla_host
*ha
)
7335 struct ddb_entry
*ddb_entry
;
7339 for (idx
= 0; idx
< MAX_DDB_ENTRIES
; idx
++) {
7341 ddb_entry
= qla4xxx_lookup_ddb_by_fw_index(ha
, idx
);
7342 if ((ddb_entry
!= NULL
) &&
7343 (ddb_entry
->ddb_type
== FLASH_DDB
)) {
7345 options
= LOGOUT_OPTION_CLOSE_SESSION
;
7346 if (qla4xxx_session_logout_ddb(ha
, ddb_entry
, options
)
7348 ql4_printk(KERN_ERR
, ha
, "%s: Logout failed\n",
7351 qla4xxx_clear_ddb_entry(ha
, ddb_entry
->fw_ddb_index
);
7353 * we have decremented the reference count of the driver
7354 * when we setup the session to have the driver unload
7355 * to be seamless without actually destroying the
7358 try_module_get(qla4xxx_iscsi_transport
.owner
);
7359 iscsi_destroy_endpoint(ddb_entry
->conn
->ep
);
7360 qla4xxx_free_ddb(ha
, ddb_entry
);
7361 iscsi_session_teardown(ddb_entry
->sess
);
7366 * qla4xxx_remove_adapter - callback function to remove adapter.
7367 * @pci_dev: PCI device pointer
7369 static void qla4xxx_remove_adapter(struct pci_dev
*pdev
)
7371 struct scsi_qla_host
*ha
;
7374 * If the PCI device is disabled then it means probe_adapter had
7375 * failed and resources already cleaned up on probe_adapter exit.
7377 if (!pci_is_enabled(pdev
))
7380 ha
= pci_get_drvdata(pdev
);
7383 qla4xxx_prevent_other_port_reinit(ha
);
7385 /* destroy iface from sysfs */
7386 qla4xxx_destroy_ifaces(ha
);
7388 if ((!ql4xdisablesysfsboot
) && ha
->boot_kset
)
7389 iscsi_boot_destroy_kset(ha
->boot_kset
);
7391 qla4xxx_destroy_fw_ddb_session(ha
);
7392 qla4_8xxx_free_sysfs_attr(ha
);
7394 qla4xxx_sysfs_ddb_remove(ha
);
7395 scsi_remove_host(ha
->host
);
7397 qla4xxx_free_adapter(ha
);
7399 scsi_host_put(ha
->host
);
7401 pci_disable_pcie_error_reporting(pdev
);
7402 pci_disable_device(pdev
);
7406 * qla4xxx_config_dma_addressing() - Configure OS DMA addressing method.
7409 * At exit, the @ha's flags.enable_64bit_addressing set to indicated
7410 * supported addressing method.
7412 static void qla4xxx_config_dma_addressing(struct scsi_qla_host
*ha
)
7416 /* Update our PCI device dma_mask for full 64 bit mask */
7417 if (pci_set_dma_mask(ha
->pdev
, DMA_BIT_MASK(64)) == 0) {
7418 if (pci_set_consistent_dma_mask(ha
->pdev
, DMA_BIT_MASK(64))) {
7419 dev_dbg(&ha
->pdev
->dev
,
7420 "Failed to set 64 bit PCI consistent mask; "
7422 retval
= pci_set_consistent_dma_mask(ha
->pdev
,
7426 retval
= pci_set_dma_mask(ha
->pdev
, DMA_BIT_MASK(32));
7429 static int qla4xxx_slave_alloc(struct scsi_device
*sdev
)
7431 struct iscsi_cls_session
*cls_sess
;
7432 struct iscsi_session
*sess
;
7433 struct ddb_entry
*ddb
;
7434 int queue_depth
= QL4_DEF_QDEPTH
;
7436 cls_sess
= starget_to_session(sdev
->sdev_target
);
7437 sess
= cls_sess
->dd_data
;
7438 ddb
= sess
->dd_data
;
7440 sdev
->hostdata
= ddb
;
7441 sdev
->tagged_supported
= 1;
7443 if (ql4xmaxqdepth
!= 0 && ql4xmaxqdepth
<= 0xffffU
)
7444 queue_depth
= ql4xmaxqdepth
;
7446 scsi_activate_tcq(sdev
, queue_depth
);
7450 static int qla4xxx_slave_configure(struct scsi_device
*sdev
)
7452 sdev
->tagged_supported
= 1;
7456 static void qla4xxx_slave_destroy(struct scsi_device
*sdev
)
7458 scsi_deactivate_tcq(sdev
, 1);
7461 static int qla4xxx_change_queue_depth(struct scsi_device
*sdev
, int qdepth
,
7464 if (!ql4xqfulltracking
)
7467 return iscsi_change_queue_depth(sdev
, qdepth
, reason
);
7471 * qla4xxx_del_from_active_array - returns an active srb
7472 * @ha: Pointer to host adapter structure.
7473 * @index: index into the active_array
7475 * This routine removes and returns the srb at the specified index
7477 struct srb
*qla4xxx_del_from_active_array(struct scsi_qla_host
*ha
,
7480 struct srb
*srb
= NULL
;
7481 struct scsi_cmnd
*cmd
= NULL
;
7483 cmd
= scsi_host_find_tag(ha
->host
, index
);
7487 srb
= (struct srb
*)CMD_SP(cmd
);
7491 /* update counters */
7492 if (srb
->flags
& SRB_DMA_VALID
) {
7493 ha
->iocb_cnt
-= srb
->iocb_cnt
;
7495 srb
->cmd
->host_scribble
=
7496 (unsigned char *)(unsigned long) MAX_SRBS
;
7502 * qla4xxx_eh_wait_on_command - waits for command to be returned by firmware
7503 * @ha: Pointer to host adapter structure.
7504 * @cmd: Scsi Command to wait on.
7506 * This routine waits for the command to be returned by the Firmware
7507 * for some max time.
7509 static int qla4xxx_eh_wait_on_command(struct scsi_qla_host
*ha
,
7510 struct scsi_cmnd
*cmd
)
7514 uint32_t max_wait_time
= EH_WAIT_CMD_TOV
;
7517 /* Dont wait on command if PCI error is being handled
7520 if (unlikely(pci_channel_offline(ha
->pdev
)) ||
7521 (test_bit(AF_EEH_BUSY
, &ha
->flags
))) {
7522 ql4_printk(KERN_WARNING
, ha
, "scsi%ld: Return from %s\n",
7523 ha
->host_no
, __func__
);
7528 /* Checking to see if its returned to OS */
7529 rp
= (struct srb
*) CMD_SP(cmd
);
7536 } while (max_wait_time
--);
7542 * qla4xxx_wait_for_hba_online - waits for HBA to come online
7543 * @ha: Pointer to host adapter structure
7545 static int qla4xxx_wait_for_hba_online(struct scsi_qla_host
*ha
)
7547 unsigned long wait_online
;
7549 wait_online
= jiffies
+ (HBA_ONLINE_TOV
* HZ
);
7550 while (time_before(jiffies
, wait_online
)) {
7562 * qla4xxx_eh_wait_for_commands - wait for active cmds to finish.
7563 * @ha: pointer to HBA
7567 * This function waits for all outstanding commands to a lun to complete. It
7568 * returns 0 if all pending commands are returned and 1 otherwise.
7570 static int qla4xxx_eh_wait_for_commands(struct scsi_qla_host
*ha
,
7571 struct scsi_target
*stgt
,
7572 struct scsi_device
*sdev
)
7576 struct scsi_cmnd
*cmd
;
7579 * Waiting for all commands for the designated target or dev
7580 * in the active array
7582 for (cnt
= 0; cnt
< ha
->host
->can_queue
; cnt
++) {
7583 cmd
= scsi_host_find_tag(ha
->host
, cnt
);
7584 if (cmd
&& stgt
== scsi_target(cmd
->device
) &&
7585 (!sdev
|| sdev
== cmd
->device
)) {
7586 if (!qla4xxx_eh_wait_on_command(ha
, cmd
)) {
7596 * qla4xxx_eh_abort - callback for abort task.
7597 * @cmd: Pointer to Linux's SCSI command structure
7599 * This routine is called by the Linux OS to abort the specified
7602 static int qla4xxx_eh_abort(struct scsi_cmnd
*cmd
)
7604 struct scsi_qla_host
*ha
= to_qla_host(cmd
->device
->host
);
7605 unsigned int id
= cmd
->device
->id
;
7606 unsigned int lun
= cmd
->device
->lun
;
7607 unsigned long flags
;
7608 struct srb
*srb
= NULL
;
7612 ql4_printk(KERN_INFO
, ha
,
7613 "scsi%ld:%d:%d: Abort command issued cmd=%p\n",
7614 ha
->host_no
, id
, lun
, cmd
);
7616 spin_lock_irqsave(&ha
->hardware_lock
, flags
);
7617 srb
= (struct srb
*) CMD_SP(cmd
);
7619 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
7622 kref_get(&srb
->srb_ref
);
7623 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
7625 if (qla4xxx_abort_task(ha
, srb
) != QLA_SUCCESS
) {
7626 DEBUG3(printk("scsi%ld:%d:%d: Abort_task mbx failed.\n",
7627 ha
->host_no
, id
, lun
));
7630 DEBUG3(printk("scsi%ld:%d:%d: Abort_task mbx success.\n",
7631 ha
->host_no
, id
, lun
));
7635 kref_put(&srb
->srb_ref
, qla4xxx_srb_compl
);
7637 /* Wait for command to complete */
7639 if (!qla4xxx_eh_wait_on_command(ha
, cmd
)) {
7640 DEBUG2(printk("scsi%ld:%d:%d: Abort handler timed out\n",
7641 ha
->host_no
, id
, lun
));
7646 ql4_printk(KERN_INFO
, ha
,
7647 "scsi%ld:%d:%d: Abort command - %s\n",
7648 ha
->host_no
, id
, lun
, (ret
== SUCCESS
) ? "succeeded" : "failed");
7654 * qla4xxx_eh_device_reset - callback for target reset.
7655 * @cmd: Pointer to Linux's SCSI command structure
7657 * This routine is called by the Linux OS to reset all luns on the
7660 static int qla4xxx_eh_device_reset(struct scsi_cmnd
*cmd
)
7662 struct scsi_qla_host
*ha
= to_qla_host(cmd
->device
->host
);
7663 struct ddb_entry
*ddb_entry
= cmd
->device
->hostdata
;
7664 int ret
= FAILED
, stat
;
7669 ret
= iscsi_block_scsi_eh(cmd
);
7674 ql4_printk(KERN_INFO
, ha
,
7675 "scsi%ld:%d:%d:%d: DEVICE RESET ISSUED.\n", ha
->host_no
,
7676 cmd
->device
->channel
, cmd
->device
->id
, cmd
->device
->lun
);
7678 DEBUG2(printk(KERN_INFO
7679 "scsi%ld: DEVICE_RESET cmd=%p jiffies = 0x%lx, to=%x,"
7680 "dpc_flags=%lx, status=%x allowed=%d\n", ha
->host_no
,
7681 cmd
, jiffies
, cmd
->request
->timeout
/ HZ
,
7682 ha
->dpc_flags
, cmd
->result
, cmd
->allowed
));
7684 /* FIXME: wait for hba to go online */
7685 stat
= qla4xxx_reset_lun(ha
, ddb_entry
, cmd
->device
->lun
);
7686 if (stat
!= QLA_SUCCESS
) {
7687 ql4_printk(KERN_INFO
, ha
, "DEVICE RESET FAILED. %d\n", stat
);
7688 goto eh_dev_reset_done
;
7691 if (qla4xxx_eh_wait_for_commands(ha
, scsi_target(cmd
->device
),
7693 ql4_printk(KERN_INFO
, ha
,
7694 "DEVICE RESET FAILED - waiting for "
7696 goto eh_dev_reset_done
;
7700 if (qla4xxx_send_marker_iocb(ha
, ddb_entry
, cmd
->device
->lun
,
7701 MM_LUN_RESET
) != QLA_SUCCESS
)
7702 goto eh_dev_reset_done
;
7704 ql4_printk(KERN_INFO
, ha
,
7705 "scsi(%ld:%d:%d:%d): DEVICE RESET SUCCEEDED.\n",
7706 ha
->host_no
, cmd
->device
->channel
, cmd
->device
->id
,
7717 * qla4xxx_eh_target_reset - callback for target reset.
7718 * @cmd: Pointer to Linux's SCSI command structure
7720 * This routine is called by the Linux OS to reset the target.
7722 static int qla4xxx_eh_target_reset(struct scsi_cmnd
*cmd
)
7724 struct scsi_qla_host
*ha
= to_qla_host(cmd
->device
->host
);
7725 struct ddb_entry
*ddb_entry
= cmd
->device
->hostdata
;
7731 ret
= iscsi_block_scsi_eh(cmd
);
7735 starget_printk(KERN_INFO
, scsi_target(cmd
->device
),
7736 "WARM TARGET RESET ISSUED.\n");
7738 DEBUG2(printk(KERN_INFO
7739 "scsi%ld: TARGET_DEVICE_RESET cmd=%p jiffies = 0x%lx, "
7740 "to=%x,dpc_flags=%lx, status=%x allowed=%d\n",
7741 ha
->host_no
, cmd
, jiffies
, cmd
->request
->timeout
/ HZ
,
7742 ha
->dpc_flags
, cmd
->result
, cmd
->allowed
));
7744 stat
= qla4xxx_reset_target(ha
, ddb_entry
);
7745 if (stat
!= QLA_SUCCESS
) {
7746 starget_printk(KERN_INFO
, scsi_target(cmd
->device
),
7747 "WARM TARGET RESET FAILED.\n");
7751 if (qla4xxx_eh_wait_for_commands(ha
, scsi_target(cmd
->device
),
7753 starget_printk(KERN_INFO
, scsi_target(cmd
->device
),
7754 "WARM TARGET DEVICE RESET FAILED - "
7755 "waiting for commands.\n");
7760 if (qla4xxx_send_marker_iocb(ha
, ddb_entry
, cmd
->device
->lun
,
7761 MM_TGT_WARM_RESET
) != QLA_SUCCESS
) {
7762 starget_printk(KERN_INFO
, scsi_target(cmd
->device
),
7763 "WARM TARGET DEVICE RESET FAILED - "
7764 "marker iocb failed.\n");
7768 starget_printk(KERN_INFO
, scsi_target(cmd
->device
),
7769 "WARM TARGET RESET SUCCEEDED.\n");
7774 * qla4xxx_is_eh_active - check if error handler is running
7775 * @shost: Pointer to SCSI Host struct
7777 * This routine finds that if reset host is called in EH
7778 * scenario or from some application like sg_reset
7780 static int qla4xxx_is_eh_active(struct Scsi_Host
*shost
)
7782 if (shost
->shost_state
== SHOST_RECOVERY
)
7788 * qla4xxx_eh_host_reset - kernel callback
7789 * @cmd: Pointer to Linux's SCSI command structure
7791 * This routine is invoked by the Linux kernel to perform fatal error
7792 * recovery on the specified adapter.
7794 static int qla4xxx_eh_host_reset(struct scsi_cmnd
*cmd
)
7796 int return_status
= FAILED
;
7797 struct scsi_qla_host
*ha
;
7799 ha
= to_qla_host(cmd
->device
->host
);
7801 if ((is_qla8032(ha
) || is_qla8042(ha
)) && ql4xdontresethba
)
7802 qla4_83xx_set_idc_dontreset(ha
);
7805 * For ISP8324 and ISP8042, if IDC_CTRL DONTRESET_BIT0 is set by other
7806 * protocol drivers, we should not set device_state to NEED_RESET
7808 if (ql4xdontresethba
||
7809 ((is_qla8032(ha
) || is_qla8042(ha
)) &&
7810 qla4_83xx_idc_dontreset(ha
))) {
7811 DEBUG2(printk("scsi%ld: %s: Don't Reset HBA\n",
7812 ha
->host_no
, __func__
));
7814 /* Clear outstanding srb in queues */
7815 if (qla4xxx_is_eh_active(cmd
->device
->host
))
7816 qla4xxx_abort_active_cmds(ha
, DID_ABORT
<< 16);
7821 ql4_printk(KERN_INFO
, ha
,
7822 "scsi(%ld:%d:%d:%d): HOST RESET ISSUED.\n", ha
->host_no
,
7823 cmd
->device
->channel
, cmd
->device
->id
, cmd
->device
->lun
);
7825 if (qla4xxx_wait_for_hba_online(ha
) != QLA_SUCCESS
) {
7826 DEBUG2(printk("scsi%ld:%d: %s: Unable to reset host. Adapter "
7827 "DEAD.\n", ha
->host_no
, cmd
->device
->channel
,
7833 if (!test_bit(DPC_RESET_HA
, &ha
->dpc_flags
)) {
7835 set_bit(DPC_RESET_HA_FW_CONTEXT
, &ha
->dpc_flags
);
7837 set_bit(DPC_RESET_HA
, &ha
->dpc_flags
);
7840 if (qla4xxx_recover_adapter(ha
) == QLA_SUCCESS
)
7841 return_status
= SUCCESS
;
7843 ql4_printk(KERN_INFO
, ha
, "HOST RESET %s.\n",
7844 return_status
== FAILED
? "FAILED" : "SUCCEEDED");
7846 return return_status
;
7849 static int qla4xxx_context_reset(struct scsi_qla_host
*ha
)
7851 uint32_t mbox_cmd
[MBOX_REG_COUNT
];
7852 uint32_t mbox_sts
[MBOX_REG_COUNT
];
7853 struct addr_ctrl_blk_def
*acb
= NULL
;
7854 uint32_t acb_len
= sizeof(struct addr_ctrl_blk_def
);
7855 int rval
= QLA_SUCCESS
;
7858 acb
= dma_alloc_coherent(&ha
->pdev
->dev
,
7859 sizeof(struct addr_ctrl_blk_def
),
7860 &acb_dma
, GFP_KERNEL
);
7862 ql4_printk(KERN_ERR
, ha
, "%s: Unable to alloc acb\n",
7865 goto exit_port_reset
;
7868 memset(acb
, 0, acb_len
);
7870 rval
= qla4xxx_get_acb(ha
, acb_dma
, PRIMARI_ACB
, acb_len
);
7871 if (rval
!= QLA_SUCCESS
) {
7876 rval
= qla4xxx_disable_acb(ha
);
7877 if (rval
!= QLA_SUCCESS
) {
7882 wait_for_completion_timeout(&ha
->disable_acb_comp
,
7883 DISABLE_ACB_TOV
* HZ
);
7885 rval
= qla4xxx_set_acb(ha
, &mbox_cmd
[0], &mbox_sts
[0], acb_dma
);
7886 if (rval
!= QLA_SUCCESS
) {
7892 dma_free_coherent(&ha
->pdev
->dev
, sizeof(struct addr_ctrl_blk_def
),
7895 DEBUG2(ql4_printk(KERN_INFO
, ha
, "%s %s\n", __func__
,
7896 rval
== QLA_SUCCESS
? "SUCCEEDED" : "FAILED"));
7900 static int qla4xxx_host_reset(struct Scsi_Host
*shost
, int reset_type
)
7902 struct scsi_qla_host
*ha
= to_qla_host(shost
);
7903 int rval
= QLA_SUCCESS
;
7906 if (ql4xdontresethba
) {
7907 DEBUG2(ql4_printk(KERN_INFO
, ha
, "%s: Don't Reset HBA\n",
7910 goto exit_host_reset
;
7913 if (test_bit(DPC_RESET_HA
, &ha
->dpc_flags
))
7914 goto recover_adapter
;
7916 switch (reset_type
) {
7917 case SCSI_ADAPTER_RESET
:
7918 set_bit(DPC_RESET_HA
, &ha
->dpc_flags
);
7920 case SCSI_FIRMWARE_RESET
:
7921 if (!test_bit(DPC_RESET_HA
, &ha
->dpc_flags
)) {
7923 /* set firmware context reset */
7924 set_bit(DPC_RESET_HA_FW_CONTEXT
,
7927 rval
= qla4xxx_context_reset(ha
);
7928 goto exit_host_reset
;
7935 /* For ISP8324 and ISP8042 set graceful reset bit in IDC_DRV_CTRL if
7936 * reset is issued by application */
7937 if ((is_qla8032(ha
) || is_qla8042(ha
)) &&
7938 test_bit(DPC_RESET_HA
, &ha
->dpc_flags
)) {
7939 idc_ctrl
= qla4_83xx_rd_reg(ha
, QLA83XX_IDC_DRV_CTRL
);
7940 qla4_83xx_wr_reg(ha
, QLA83XX_IDC_DRV_CTRL
,
7941 (idc_ctrl
| GRACEFUL_RESET_BIT1
));
7944 rval
= qla4xxx_recover_adapter(ha
);
7945 if (rval
!= QLA_SUCCESS
) {
7946 DEBUG2(ql4_printk(KERN_INFO
, ha
, "%s: recover adapter fail\n",
7955 /* PCI AER driver recovers from all correctable errors w/o
7956 * driver intervention. For uncorrectable errors PCI AER
7957 * driver calls the following device driver's callbacks
7959 * - Fatal Errors - link_reset
7960 * - Non-Fatal Errors - driver's pci_error_detected() which
7961 * returns CAN_RECOVER, NEED_RESET or DISCONNECT.
7963 * PCI AER driver calls
7964 * CAN_RECOVER - driver's pci_mmio_enabled(), mmio_enabled
7965 * returns RECOVERED or NEED_RESET if fw_hung
7966 * NEED_RESET - driver's slot_reset()
7967 * DISCONNECT - device is dead & cannot recover
7968 * RECOVERED - driver's pci_resume()
7970 static pci_ers_result_t
7971 qla4xxx_pci_error_detected(struct pci_dev
*pdev
, pci_channel_state_t state
)
7973 struct scsi_qla_host
*ha
= pci_get_drvdata(pdev
);
7975 ql4_printk(KERN_WARNING
, ha
, "scsi%ld: %s: error detected:state %x\n",
7976 ha
->host_no
, __func__
, state
);
7978 if (!is_aer_supported(ha
))
7979 return PCI_ERS_RESULT_NONE
;
7982 case pci_channel_io_normal
:
7983 clear_bit(AF_EEH_BUSY
, &ha
->flags
);
7984 return PCI_ERS_RESULT_CAN_RECOVER
;
7985 case pci_channel_io_frozen
:
7986 set_bit(AF_EEH_BUSY
, &ha
->flags
);
7987 qla4xxx_mailbox_premature_completion(ha
);
7988 qla4xxx_free_irqs(ha
);
7989 pci_disable_device(pdev
);
7990 /* Return back all IOs */
7991 qla4xxx_abort_active_cmds(ha
, DID_RESET
<< 16);
7992 return PCI_ERS_RESULT_NEED_RESET
;
7993 case pci_channel_io_perm_failure
:
7994 set_bit(AF_EEH_BUSY
, &ha
->flags
);
7995 set_bit(AF_PCI_CHANNEL_IO_PERM_FAILURE
, &ha
->flags
);
7996 qla4xxx_abort_active_cmds(ha
, DID_NO_CONNECT
<< 16);
7997 return PCI_ERS_RESULT_DISCONNECT
;
7999 return PCI_ERS_RESULT_NEED_RESET
;
8003 * qla4xxx_pci_mmio_enabled() gets called if
8004 * qla4xxx_pci_error_detected() returns PCI_ERS_RESULT_CAN_RECOVER
8005 * and read/write to the device still works.
8007 static pci_ers_result_t
8008 qla4xxx_pci_mmio_enabled(struct pci_dev
*pdev
)
8010 struct scsi_qla_host
*ha
= pci_get_drvdata(pdev
);
8012 if (!is_aer_supported(ha
))
8013 return PCI_ERS_RESULT_NONE
;
8015 return PCI_ERS_RESULT_RECOVERED
;
8018 static uint32_t qla4_8xxx_error_recovery(struct scsi_qla_host
*ha
)
8020 uint32_t rval
= QLA_ERROR
;
8022 struct pci_dev
*other_pdev
= NULL
;
8024 ql4_printk(KERN_WARNING
, ha
, "scsi%ld: In %s\n", ha
->host_no
, __func__
);
8026 set_bit(DPC_RESET_ACTIVE
, &ha
->dpc_flags
);
8028 if (test_bit(AF_ONLINE
, &ha
->flags
)) {
8029 clear_bit(AF_ONLINE
, &ha
->flags
);
8030 clear_bit(AF_LINK_UP
, &ha
->flags
);
8031 iscsi_host_for_each_session(ha
->host
, qla4xxx_fail_session
);
8032 qla4xxx_process_aen(ha
, FLUSH_DDB_CHANGED_AENS
);
8035 fn
= PCI_FUNC(ha
->pdev
->devfn
);
8038 ql4_printk(KERN_INFO
, ha
, "scsi%ld: %s: Finding PCI device at "
8039 "func %x\n", ha
->host_no
, __func__
, fn
);
8040 /* Get the pci device given the domain, bus,
8041 * slot/function number */
8043 pci_get_domain_bus_and_slot(pci_domain_nr(ha
->pdev
->bus
),
8044 ha
->pdev
->bus
->number
, PCI_DEVFN(PCI_SLOT(ha
->pdev
->devfn
),
8050 if (atomic_read(&other_pdev
->enable_cnt
)) {
8051 ql4_printk(KERN_INFO
, ha
, "scsi%ld: %s: Found PCI "
8052 "func in enabled state%x\n", ha
->host_no
,
8054 pci_dev_put(other_pdev
);
8057 pci_dev_put(other_pdev
);
8060 /* The first function on the card, the reset owner will
8061 * start & initialize the firmware. The other functions
8062 * on the card will reset the firmware context
8065 ql4_printk(KERN_INFO
, ha
, "scsi%ld: %s: devfn being reset "
8066 "0x%x is the owner\n", ha
->host_no
, __func__
,
8069 ha
->isp_ops
->idc_lock(ha
);
8070 qla4_8xxx_wr_direct(ha
, QLA8XXX_CRB_DEV_STATE
,
8072 ha
->isp_ops
->idc_unlock(ha
);
8074 rval
= qla4_8xxx_update_idc_reg(ha
);
8075 if (rval
== QLA_ERROR
) {
8076 ql4_printk(KERN_INFO
, ha
, "scsi%ld: %s: HW State: FAILED\n",
8077 ha
->host_no
, __func__
);
8078 ha
->isp_ops
->idc_lock(ha
);
8079 qla4_8xxx_wr_direct(ha
, QLA8XXX_CRB_DEV_STATE
,
8080 QLA8XXX_DEV_FAILED
);
8081 ha
->isp_ops
->idc_unlock(ha
);
8082 goto exit_error_recovery
;
8085 clear_bit(AF_FW_RECOVERY
, &ha
->flags
);
8086 rval
= qla4xxx_initialize_adapter(ha
, RESET_ADAPTER
);
8088 if (rval
!= QLA_SUCCESS
) {
8089 ql4_printk(KERN_INFO
, ha
, "scsi%ld: %s: HW State: "
8090 "FAILED\n", ha
->host_no
, __func__
);
8091 ha
->isp_ops
->idc_lock(ha
);
8092 qla4_8xxx_clear_drv_active(ha
);
8093 qla4_8xxx_wr_direct(ha
, QLA8XXX_CRB_DEV_STATE
,
8094 QLA8XXX_DEV_FAILED
);
8095 ha
->isp_ops
->idc_unlock(ha
);
8097 ql4_printk(KERN_INFO
, ha
, "scsi%ld: %s: HW State: "
8098 "READY\n", ha
->host_no
, __func__
);
8099 ha
->isp_ops
->idc_lock(ha
);
8100 qla4_8xxx_wr_direct(ha
, QLA8XXX_CRB_DEV_STATE
,
8102 /* Clear driver state register */
8103 qla4_8xxx_wr_direct(ha
, QLA8XXX_CRB_DRV_STATE
, 0);
8104 qla4_8xxx_set_drv_active(ha
);
8105 ha
->isp_ops
->idc_unlock(ha
);
8106 ha
->isp_ops
->enable_intrs(ha
);
8109 ql4_printk(KERN_INFO
, ha
, "scsi%ld: %s: devfn 0x%x is not "
8110 "the reset owner\n", ha
->host_no
, __func__
,
8112 if ((qla4_8xxx_rd_direct(ha
, QLA8XXX_CRB_DEV_STATE
) ==
8113 QLA8XXX_DEV_READY
)) {
8114 clear_bit(AF_FW_RECOVERY
, &ha
->flags
);
8115 rval
= qla4xxx_initialize_adapter(ha
, RESET_ADAPTER
);
8116 if (rval
== QLA_SUCCESS
)
8117 ha
->isp_ops
->enable_intrs(ha
);
8119 ha
->isp_ops
->idc_lock(ha
);
8120 qla4_8xxx_set_drv_active(ha
);
8121 ha
->isp_ops
->idc_unlock(ha
);
8124 exit_error_recovery
:
8125 clear_bit(DPC_RESET_ACTIVE
, &ha
->dpc_flags
);
8129 static pci_ers_result_t
8130 qla4xxx_pci_slot_reset(struct pci_dev
*pdev
)
8132 pci_ers_result_t ret
= PCI_ERS_RESULT_DISCONNECT
;
8133 struct scsi_qla_host
*ha
= pci_get_drvdata(pdev
);
8136 ql4_printk(KERN_WARNING
, ha
, "scsi%ld: %s: slot_reset\n",
8137 ha
->host_no
, __func__
);
8139 if (!is_aer_supported(ha
))
8140 return PCI_ERS_RESULT_NONE
;
8142 /* Restore the saved state of PCIe device -
8143 * BAR registers, PCI Config space, PCIX, MSI,
8146 pci_restore_state(pdev
);
8148 /* pci_restore_state() clears the saved_state flag of the device
8149 * save restored state which resets saved_state flag
8151 pci_save_state(pdev
);
8153 /* Initialize device or resume if in suspended state */
8154 rc
= pci_enable_device(pdev
);
8156 ql4_printk(KERN_WARNING
, ha
, "scsi%ld: %s: Can't re-enable "
8157 "device after reset\n", ha
->host_no
, __func__
);
8158 goto exit_slot_reset
;
8161 ha
->isp_ops
->disable_intrs(ha
);
8163 if (is_qla80XX(ha
)) {
8164 if (qla4_8xxx_error_recovery(ha
) == QLA_SUCCESS
) {
8165 ret
= PCI_ERS_RESULT_RECOVERED
;
8166 goto exit_slot_reset
;
8168 goto exit_slot_reset
;
8172 ql4_printk(KERN_WARNING
, ha
, "scsi%ld: %s: Return=%x\n"
8173 "device after reset\n", ha
->host_no
, __func__
, ret
);
8178 qla4xxx_pci_resume(struct pci_dev
*pdev
)
8180 struct scsi_qla_host
*ha
= pci_get_drvdata(pdev
);
8183 ql4_printk(KERN_WARNING
, ha
, "scsi%ld: %s: pci_resume\n",
8184 ha
->host_no
, __func__
);
8186 ret
= qla4xxx_wait_for_hba_online(ha
);
8187 if (ret
!= QLA_SUCCESS
) {
8188 ql4_printk(KERN_ERR
, ha
, "scsi%ld: %s: the device failed to "
8189 "resume I/O from slot/link_reset\n", ha
->host_no
,
8193 pci_cleanup_aer_uncorrect_error_status(pdev
);
8194 clear_bit(AF_EEH_BUSY
, &ha
->flags
);
8197 static const struct pci_error_handlers qla4xxx_err_handler
= {
8198 .error_detected
= qla4xxx_pci_error_detected
,
8199 .mmio_enabled
= qla4xxx_pci_mmio_enabled
,
8200 .slot_reset
= qla4xxx_pci_slot_reset
,
8201 .resume
= qla4xxx_pci_resume
,
8204 static struct pci_device_id qla4xxx_pci_tbl
[] = {
8206 .vendor
= PCI_VENDOR_ID_QLOGIC
,
8207 .device
= PCI_DEVICE_ID_QLOGIC_ISP4010
,
8208 .subvendor
= PCI_ANY_ID
,
8209 .subdevice
= PCI_ANY_ID
,
8212 .vendor
= PCI_VENDOR_ID_QLOGIC
,
8213 .device
= PCI_DEVICE_ID_QLOGIC_ISP4022
,
8214 .subvendor
= PCI_ANY_ID
,
8215 .subdevice
= PCI_ANY_ID
,
8218 .vendor
= PCI_VENDOR_ID_QLOGIC
,
8219 .device
= PCI_DEVICE_ID_QLOGIC_ISP4032
,
8220 .subvendor
= PCI_ANY_ID
,
8221 .subdevice
= PCI_ANY_ID
,
8224 .vendor
= PCI_VENDOR_ID_QLOGIC
,
8225 .device
= PCI_DEVICE_ID_QLOGIC_ISP8022
,
8226 .subvendor
= PCI_ANY_ID
,
8227 .subdevice
= PCI_ANY_ID
,
8230 .vendor
= PCI_VENDOR_ID_QLOGIC
,
8231 .device
= PCI_DEVICE_ID_QLOGIC_ISP8324
,
8232 .subvendor
= PCI_ANY_ID
,
8233 .subdevice
= PCI_ANY_ID
,
8236 .vendor
= PCI_VENDOR_ID_QLOGIC
,
8237 .device
= PCI_DEVICE_ID_QLOGIC_ISP8042
,
8238 .subvendor
= PCI_ANY_ID
,
8239 .subdevice
= PCI_ANY_ID
,
8243 MODULE_DEVICE_TABLE(pci
, qla4xxx_pci_tbl
);
8245 static struct pci_driver qla4xxx_pci_driver
= {
8246 .name
= DRIVER_NAME
,
8247 .id_table
= qla4xxx_pci_tbl
,
8248 .probe
= qla4xxx_probe_adapter
,
8249 .remove
= qla4xxx_remove_adapter
,
8250 .err_handler
= &qla4xxx_err_handler
,
8253 static int __init
qla4xxx_module_init(void)
8257 /* Allocate cache for SRBs. */
8258 srb_cachep
= kmem_cache_create("qla4xxx_srbs", sizeof(struct srb
), 0,
8259 SLAB_HWCACHE_ALIGN
, NULL
);
8260 if (srb_cachep
== NULL
) {
8262 "%s: Unable to allocate SRB cache..."
8263 "Failing load!\n", DRIVER_NAME
);
8268 /* Derive version string. */
8269 strcpy(qla4xxx_version_str
, QLA4XXX_DRIVER_VERSION
);
8270 if (ql4xextended_error_logging
)
8271 strcat(qla4xxx_version_str
, "-debug");
8273 qla4xxx_scsi_transport
=
8274 iscsi_register_transport(&qla4xxx_iscsi_transport
);
8275 if (!qla4xxx_scsi_transport
){
8277 goto release_srb_cache
;
8280 ret
= pci_register_driver(&qla4xxx_pci_driver
);
8282 goto unregister_transport
;
8284 printk(KERN_INFO
"QLogic iSCSI HBA Driver\n");
8287 unregister_transport
:
8288 iscsi_unregister_transport(&qla4xxx_iscsi_transport
);
8290 kmem_cache_destroy(srb_cachep
);
8295 static void __exit
qla4xxx_module_exit(void)
8297 pci_unregister_driver(&qla4xxx_pci_driver
);
8298 iscsi_unregister_transport(&qla4xxx_iscsi_transport
);
8299 kmem_cache_destroy(srb_cachep
);
8302 module_init(qla4xxx_module_init
);
8303 module_exit(qla4xxx_module_exit
);
8305 MODULE_AUTHOR("QLogic Corporation");
8306 MODULE_DESCRIPTION("QLogic iSCSI HBA Driver");
8307 MODULE_LICENSE("GPL");
8308 MODULE_VERSION(QLA4XXX_DRIVER_VERSION
);