2 * QLogic iSCSI HBA Driver
3 * Copyright (c) 2003-2010 QLogic Corporation
5 * See LICENSE.qla4xxx for copyright and licensing details.
7 #include <linux/moduleparam.h>
8 #include <linux/slab.h>
10 #include <scsi/scsi_tcq.h>
11 #include <scsi/scsicam.h>
14 #include "ql4_version.h"
17 #include "ql4_inline.h"
22 static char qla4xxx_version_str
[40];
25 * SRB allocation cache
27 static struct kmem_cache
*srb_cachep
;
30 * Module parameter information and variables
32 int ql4xdontresethba
= 0;
33 module_param(ql4xdontresethba
, int, S_IRUGO
| S_IWUSR
);
34 MODULE_PARM_DESC(ql4xdontresethba
,
35 "Don't reset the HBA for driver recovery \n"
36 " 0 - It will reset HBA (Default)\n"
37 " 1 - It will NOT reset HBA");
39 int ql4xextended_error_logging
= 0; /* 0 = off, 1 = log errors */
40 module_param(ql4xextended_error_logging
, int, S_IRUGO
| S_IWUSR
);
41 MODULE_PARM_DESC(ql4xextended_error_logging
,
42 "Option to enable extended error logging, "
43 "Default is 0 - no logging, 1 - debug logging");
45 int ql4xenablemsix
= 1;
46 module_param(ql4xenablemsix
, int, S_IRUGO
|S_IWUSR
);
47 MODULE_PARM_DESC(ql4xenablemsix
,
48 "Set to enable MSI or MSI-X interrupt mechanism.\n"
49 " 0 = enable INTx interrupt mechanism.\n"
50 " 1 = enable MSI-X interrupt mechanism (Default).\n"
51 " 2 = enable MSI interrupt mechanism.");
53 #define QL4_DEF_QDEPTH 32
54 static int ql4xmaxqdepth
= QL4_DEF_QDEPTH
;
55 module_param(ql4xmaxqdepth
, int, S_IRUGO
| S_IWUSR
);
56 MODULE_PARM_DESC(ql4xmaxqdepth
,
57 "Maximum queue depth to report for target devices.\n"
60 static int ql4xsess_recovery_tmo
= QL4_SESS_RECOVERY_TMO
;
61 module_param(ql4xsess_recovery_tmo
, int, S_IRUGO
);
62 MODULE_PARM_DESC(ql4xsess_recovery_tmo
,
63 "Target Session Recovery Timeout.\n"
67 * SCSI host template entry points
69 static void qla4xxx_config_dma_addressing(struct scsi_qla_host
*ha
);
72 * iSCSI template entry points
74 static int qla4xxx_tgt_dscvr(struct Scsi_Host
*shost
,
75 enum iscsi_tgt_dscvr type
, uint32_t enable
,
76 struct sockaddr
*dst_addr
);
77 static int qla4xxx_conn_get_param(struct iscsi_cls_conn
*conn
,
78 enum iscsi_param param
, char *buf
);
79 static int qla4xxx_sess_get_param(struct iscsi_cls_session
*sess
,
80 enum iscsi_param param
, char *buf
);
81 static int qla4xxx_host_get_param(struct Scsi_Host
*shost
,
82 enum iscsi_host_param param
, char *buf
);
83 static int qla4xxx_iface_set_param(struct Scsi_Host
*shost
, char *data
,
85 static int qla4xxx_get_iface_param(struct iscsi_iface
*iface
,
86 enum iscsi_param_type param_type
,
87 int param
, char *buf
);
88 static void qla4xxx_recovery_timedout(struct iscsi_cls_session
*session
);
89 static enum blk_eh_timer_return
qla4xxx_eh_cmd_timed_out(struct scsi_cmnd
*sc
);
92 * SCSI host template entry points
94 static int qla4xxx_queuecommand(struct Scsi_Host
*h
, struct scsi_cmnd
*cmd
);
95 static int qla4xxx_eh_abort(struct scsi_cmnd
*cmd
);
96 static int qla4xxx_eh_device_reset(struct scsi_cmnd
*cmd
);
97 static int qla4xxx_eh_target_reset(struct scsi_cmnd
*cmd
);
98 static int qla4xxx_eh_host_reset(struct scsi_cmnd
*cmd
);
99 static int qla4xxx_slave_alloc(struct scsi_device
*device
);
100 static int qla4xxx_slave_configure(struct scsi_device
*device
);
101 static void qla4xxx_slave_destroy(struct scsi_device
*sdev
);
102 static void qla4xxx_scan_start(struct Scsi_Host
*shost
);
103 static mode_t
ql4_attr_is_visible(int param_type
, int param
);
105 static struct qla4_8xxx_legacy_intr_set legacy_intr
[] =
106 QLA82XX_LEGACY_INTR_CONFIG
;
108 static struct scsi_host_template qla4xxx_driver_template
= {
109 .module
= THIS_MODULE
,
111 .proc_name
= DRIVER_NAME
,
112 .queuecommand
= qla4xxx_queuecommand
,
114 .eh_abort_handler
= qla4xxx_eh_abort
,
115 .eh_device_reset_handler
= qla4xxx_eh_device_reset
,
116 .eh_target_reset_handler
= qla4xxx_eh_target_reset
,
117 .eh_host_reset_handler
= qla4xxx_eh_host_reset
,
118 .eh_timed_out
= qla4xxx_eh_cmd_timed_out
,
120 .slave_configure
= qla4xxx_slave_configure
,
121 .slave_alloc
= qla4xxx_slave_alloc
,
122 .slave_destroy
= qla4xxx_slave_destroy
,
124 .scan_finished
= iscsi_scan_finished
,
125 .scan_start
= qla4xxx_scan_start
,
129 .use_clustering
= ENABLE_CLUSTERING
,
130 .sg_tablesize
= SG_ALL
,
132 .max_sectors
= 0xFFFF,
133 .shost_attrs
= qla4xxx_host_attrs
,
136 static struct iscsi_transport qla4xxx_iscsi_transport
= {
137 .owner
= THIS_MODULE
,
139 .caps
= CAP_FW_DB
| CAP_SENDTARGETS_OFFLOAD
|
140 CAP_DATA_PATH_OFFLOAD
,
141 .host_param_mask
= ISCSI_HOST_HWADDRESS
|
142 ISCSI_HOST_IPADDRESS
|
143 ISCSI_HOST_INITIATOR_NAME
,
144 .iface_param_mask
= ISCSI_NET_IPV4_ADDR
|
145 ISCSI_NET_IPV4_SUBNET
|
147 ISCSI_NET_IPV4_BOOTPROTO
|
148 ISCSI_NET_IFACE_ENABLE
|
149 ISCSI_NET_IPV6_LINKLOCAL
|
150 ISCSI_NET_IPV6_ADDR
|
151 ISCSI_NET_IPV6_ROUTER
|
152 ISCSI_NET_IPV6_ADDR_AUTOCFG
|
153 ISCSI_NET_IPV6_LINKLOCAL_AUTOCFG
|
154 ISCSI_NET_IFACE_ENABLE
,
155 .tgt_dscvr
= qla4xxx_tgt_dscvr
,
156 .attr_is_visible
= ql4_attr_is_visible
,
157 .get_conn_param
= qla4xxx_conn_get_param
,
158 .get_session_param
= qla4xxx_sess_get_param
,
159 .get_host_param
= qla4xxx_host_get_param
,
160 .set_iface_param
= qla4xxx_iface_set_param
,
161 .session_recovery_timedout
= qla4xxx_recovery_timedout
,
162 .get_iface_param
= qla4xxx_get_iface_param
,
165 static struct scsi_transport_template
*qla4xxx_scsi_transport
;
167 static mode_t
ql4_attr_is_visible(int param_type
, int param
)
169 switch (param_type
) {
172 case ISCSI_PARAM_CONN_ADDRESS
:
173 case ISCSI_PARAM_CONN_PORT
:
174 case ISCSI_PARAM_TARGET_NAME
:
175 case ISCSI_PARAM_TPGT
:
176 case ISCSI_PARAM_TARGET_ALIAS
:
186 static int qla4xxx_get_iface_param(struct iscsi_iface
*iface
,
187 enum iscsi_param_type param_type
,
188 int param
, char *buf
)
190 struct Scsi_Host
*shost
= iscsi_iface_to_shost(iface
);
191 struct scsi_qla_host
*ha
= to_qla_host(shost
);
194 if (param_type
!= ISCSI_NET_PARAM
)
198 case ISCSI_NET_PARAM_IPV4_ADDR
:
199 len
= sprintf(buf
, "%pI4\n", &ha
->ip_config
.ip_address
);
201 case ISCSI_NET_PARAM_IPV4_SUBNET
:
202 len
= sprintf(buf
, "%pI4\n", &ha
->ip_config
.subnet_mask
);
204 case ISCSI_NET_PARAM_IPV4_GW
:
205 len
= sprintf(buf
, "%pI4\n", &ha
->ip_config
.gateway
);
207 case ISCSI_NET_PARAM_IFACE_ENABLE
:
208 if (iface
->iface_type
== ISCSI_IFACE_TYPE_IPV4
)
209 len
= sprintf(buf
, "%s\n",
210 (ha
->ip_config
.ipv4_options
&
211 IPOPT_IPV4_PROTOCOL_ENABLE
) ?
212 "enabled" : "disabled");
213 else if (iface
->iface_type
== ISCSI_IFACE_TYPE_IPV6
)
214 len
= sprintf(buf
, "%s\n",
215 (ha
->ip_config
.ipv6_options
&
216 IPV6_OPT_IPV6_PROTOCOL_ENABLE
) ?
217 "enabled" : "disabled");
219 case ISCSI_NET_PARAM_IPV4_BOOTPROTO
:
220 len
= sprintf(buf
, "%s\n",
221 (ha
->ip_config
.tcp_options
& TCPOPT_DHCP_ENABLE
) ?
224 case ISCSI_NET_PARAM_IPV6_ADDR
:
225 if (iface
->iface_num
== 0)
226 len
= sprintf(buf
, "%pI6\n", &ha
->ip_config
.ipv6_addr0
);
227 if (iface
->iface_num
== 1)
228 len
= sprintf(buf
, "%pI6\n", &ha
->ip_config
.ipv6_addr1
);
230 case ISCSI_NET_PARAM_IPV6_LINKLOCAL
:
231 len
= sprintf(buf
, "%pI6\n",
232 &ha
->ip_config
.ipv6_link_local_addr
);
234 case ISCSI_NET_PARAM_IPV6_ROUTER
:
235 len
= sprintf(buf
, "%pI6\n",
236 &ha
->ip_config
.ipv6_default_router_addr
);
238 case ISCSI_NET_PARAM_IPV6_ADDR_AUTOCFG
:
239 len
= sprintf(buf
, "%s\n",
240 (ha
->ip_config
.ipv6_addl_options
&
241 IPV6_ADDOPT_NEIGHBOR_DISCOVERY_ADDR_ENABLE
) ?
244 case ISCSI_NET_PARAM_IPV6_LINKLOCAL_AUTOCFG
:
245 len
= sprintf(buf
, "%s\n",
246 (ha
->ip_config
.ipv6_addl_options
&
247 IPV6_ADDOPT_AUTOCONFIG_LINK_LOCAL_ADDR
) ?
257 static enum blk_eh_timer_return
qla4xxx_eh_cmd_timed_out(struct scsi_cmnd
*sc
)
259 struct iscsi_cls_session
*session
;
260 struct ddb_entry
*ddb_entry
;
262 session
= starget_to_session(scsi_target(sc
->device
));
263 ddb_entry
= session
->dd_data
;
265 /* if we are not logged in then the LLD is going to clean up the cmd */
266 if (atomic_read(&ddb_entry
->state
) != DDB_STATE_ONLINE
)
267 return BLK_EH_RESET_TIMER
;
269 return BLK_EH_NOT_HANDLED
;
272 static void qla4xxx_recovery_timedout(struct iscsi_cls_session
*session
)
274 struct ddb_entry
*ddb_entry
= session
->dd_data
;
275 struct scsi_qla_host
*ha
= ddb_entry
->ha
;
277 if (atomic_read(&ddb_entry
->state
) != DDB_STATE_ONLINE
) {
278 atomic_set(&ddb_entry
->state
, DDB_STATE_DEAD
);
280 DEBUG2(printk("scsi%ld: %s: ddb [%d] session recovery timeout "
281 "of (%d) secs exhausted, marking device DEAD.\n",
282 ha
->host_no
, __func__
, ddb_entry
->fw_ddb_index
,
283 ddb_entry
->sess
->recovery_tmo
));
287 static int qla4xxx_host_get_param(struct Scsi_Host
*shost
,
288 enum iscsi_host_param param
, char *buf
)
290 struct scsi_qla_host
*ha
= to_qla_host(shost
);
294 case ISCSI_HOST_PARAM_HWADDRESS
:
295 len
= sysfs_format_mac(buf
, ha
->my_mac
, MAC_ADDR_LEN
);
297 case ISCSI_HOST_PARAM_IPADDRESS
:
298 len
= sprintf(buf
, "%pI4\n", &ha
->ip_config
.ip_address
);
300 case ISCSI_HOST_PARAM_INITIATOR_NAME
:
301 len
= sprintf(buf
, "%s\n", ha
->name_string
);
310 static void qla4xxx_create_ipv4_iface(struct scsi_qla_host
*ha
)
316 ha
->iface_ipv4
= iscsi_create_iface(ha
->host
,
317 &qla4xxx_iscsi_transport
,
318 ISCSI_IFACE_TYPE_IPV4
, 0, 0);
320 ql4_printk(KERN_ERR
, ha
, "Could not create IPv4 iSCSI "
324 static void qla4xxx_create_ipv6_iface(struct scsi_qla_host
*ha
)
326 if (!ha
->iface_ipv6_0
)
328 ha
->iface_ipv6_0
= iscsi_create_iface(ha
->host
,
329 &qla4xxx_iscsi_transport
,
330 ISCSI_IFACE_TYPE_IPV6
, 0,
332 if (!ha
->iface_ipv6_0
)
333 ql4_printk(KERN_ERR
, ha
, "Could not create IPv6 iSCSI "
336 if (!ha
->iface_ipv6_1
)
338 ha
->iface_ipv6_1
= iscsi_create_iface(ha
->host
,
339 &qla4xxx_iscsi_transport
,
340 ISCSI_IFACE_TYPE_IPV6
, 1,
342 if (!ha
->iface_ipv6_1
)
343 ql4_printk(KERN_ERR
, ha
, "Could not create IPv6 iSCSI "
347 static void qla4xxx_create_ifaces(struct scsi_qla_host
*ha
)
349 if (ha
->ip_config
.ipv4_options
& IPOPT_IPV4_PROTOCOL_ENABLE
)
350 qla4xxx_create_ipv4_iface(ha
);
352 if (ha
->ip_config
.ipv6_options
& IPV6_OPT_IPV6_PROTOCOL_ENABLE
)
353 qla4xxx_create_ipv6_iface(ha
);
356 static void qla4xxx_destroy_ipv4_iface(struct scsi_qla_host
*ha
)
358 if (ha
->iface_ipv4
) {
359 iscsi_destroy_iface(ha
->iface_ipv4
);
360 ha
->iface_ipv4
= NULL
;
364 static void qla4xxx_destroy_ipv6_iface(struct scsi_qla_host
*ha
)
366 if (ha
->iface_ipv6_0
) {
367 iscsi_destroy_iface(ha
->iface_ipv6_0
);
368 ha
->iface_ipv6_0
= NULL
;
370 if (ha
->iface_ipv6_1
) {
371 iscsi_destroy_iface(ha
->iface_ipv6_1
);
372 ha
->iface_ipv6_1
= NULL
;
376 static void qla4xxx_destroy_ifaces(struct scsi_qla_host
*ha
)
378 qla4xxx_destroy_ipv4_iface(ha
);
379 qla4xxx_destroy_ipv6_iface(ha
);
382 static void qla4xxx_set_ipv6(struct scsi_qla_host
*ha
,
383 struct iscsi_iface_param_info
*iface_param
,
384 struct addr_ctrl_blk
*init_fw_cb
)
387 * iface_num 0 is valid for IPv6 Addr, linklocal, router, autocfg.
388 * iface_num 1 is valid only for IPv6 Addr.
390 switch (iface_param
->param
) {
391 case ISCSI_NET_PARAM_IPV6_ADDR
:
392 if (iface_param
->iface_num
& 0x1)
394 memcpy(init_fw_cb
->ipv6_addr1
, iface_param
->value
,
395 sizeof(init_fw_cb
->ipv6_addr1
));
398 memcpy(init_fw_cb
->ipv6_addr0
, iface_param
->value
,
399 sizeof(init_fw_cb
->ipv6_addr0
));
401 case ISCSI_NET_PARAM_IPV6_LINKLOCAL
:
402 if (iface_param
->iface_num
& 0x1)
404 memcpy(init_fw_cb
->ipv6_if_id
, &iface_param
->value
[8],
405 sizeof(init_fw_cb
->ipv6_if_id
));
407 case ISCSI_NET_PARAM_IPV6_ROUTER
:
408 if (iface_param
->iface_num
& 0x1)
410 memcpy(init_fw_cb
->ipv6_dflt_rtr_addr
, iface_param
->value
,
411 sizeof(init_fw_cb
->ipv6_dflt_rtr_addr
));
413 case ISCSI_NET_PARAM_IPV6_ADDR_AUTOCFG
:
414 /* Autocfg applies to even interface */
415 if (iface_param
->iface_num
& 0x1)
418 if (iface_param
->value
[0] == ISCSI_IPV6_AUTOCFG_DISABLE
)
419 init_fw_cb
->ipv6_addtl_opts
&=
421 ~IPV6_ADDOPT_NEIGHBOR_DISCOVERY_ADDR_ENABLE
);
422 else if (iface_param
->value
[0] == ISCSI_IPV6_AUTOCFG_ND_ENABLE
)
423 init_fw_cb
->ipv6_addtl_opts
|=
425 IPV6_ADDOPT_NEIGHBOR_DISCOVERY_ADDR_ENABLE
);
427 ql4_printk(KERN_ERR
, ha
, "Invalid autocfg setting for "
430 case ISCSI_NET_PARAM_IPV6_LINKLOCAL_AUTOCFG
:
431 /* Autocfg applies to even interface */
432 if (iface_param
->iface_num
& 0x1)
435 if (iface_param
->value
[0] ==
436 ISCSI_IPV6_LINKLOCAL_AUTOCFG_ENABLE
)
437 init_fw_cb
->ipv6_addtl_opts
|= cpu_to_le16(
438 IPV6_ADDOPT_AUTOCONFIG_LINK_LOCAL_ADDR
);
439 else if (iface_param
->value
[0] ==
440 ISCSI_IPV6_LINKLOCAL_AUTOCFG_DISABLE
)
441 init_fw_cb
->ipv6_addtl_opts
&= cpu_to_le16(
442 ~IPV6_ADDOPT_AUTOCONFIG_LINK_LOCAL_ADDR
);
444 ql4_printk(KERN_ERR
, ha
, "Invalid autocfg setting for "
445 "IPv6 linklocal addr\n");
447 case ISCSI_NET_PARAM_IPV6_ROUTER_AUTOCFG
:
448 /* Autocfg applies to even interface */
449 if (iface_param
->iface_num
& 0x1)
452 if (iface_param
->value
[0] == ISCSI_IPV6_ROUTER_AUTOCFG_ENABLE
)
453 memset(init_fw_cb
->ipv6_dflt_rtr_addr
, 0,
454 sizeof(init_fw_cb
->ipv6_dflt_rtr_addr
));
456 case ISCSI_NET_PARAM_IFACE_ENABLE
:
457 if (iface_param
->value
[0] == ISCSI_IFACE_ENABLE
) {
458 init_fw_cb
->ipv6_opts
|=
459 cpu_to_le16(IPV6_OPT_IPV6_PROTOCOL_ENABLE
);
460 qla4xxx_create_ipv6_iface(ha
);
462 init_fw_cb
->ipv6_opts
&=
463 cpu_to_le16(~IPV6_OPT_IPV6_PROTOCOL_ENABLE
&
465 qla4xxx_destroy_ipv6_iface(ha
);
468 case ISCSI_NET_PARAM_VLAN_ID
:
469 if (iface_param
->len
!= sizeof(init_fw_cb
->ipv6_vlan_tag
))
471 init_fw_cb
->ipv6_vlan_tag
= *(uint16_t *)iface_param
->value
;
474 ql4_printk(KERN_ERR
, ha
, "Unknown IPv6 param = %d\n",
480 static void qla4xxx_set_ipv4(struct scsi_qla_host
*ha
,
481 struct iscsi_iface_param_info
*iface_param
,
482 struct addr_ctrl_blk
*init_fw_cb
)
484 switch (iface_param
->param
) {
485 case ISCSI_NET_PARAM_IPV4_ADDR
:
486 memcpy(init_fw_cb
->ipv4_addr
, iface_param
->value
,
487 sizeof(init_fw_cb
->ipv4_addr
));
489 case ISCSI_NET_PARAM_IPV4_SUBNET
:
490 memcpy(init_fw_cb
->ipv4_subnet
, iface_param
->value
,
491 sizeof(init_fw_cb
->ipv4_subnet
));
493 case ISCSI_NET_PARAM_IPV4_GW
:
494 memcpy(init_fw_cb
->ipv4_gw_addr
, iface_param
->value
,
495 sizeof(init_fw_cb
->ipv4_gw_addr
));
497 case ISCSI_NET_PARAM_IPV4_BOOTPROTO
:
498 if (iface_param
->value
[0] == ISCSI_BOOTPROTO_DHCP
)
499 init_fw_cb
->ipv4_tcp_opts
|=
500 cpu_to_le16(TCPOPT_DHCP_ENABLE
);
501 else if (iface_param
->value
[0] == ISCSI_BOOTPROTO_STATIC
)
502 init_fw_cb
->ipv4_tcp_opts
&=
503 cpu_to_le16(~TCPOPT_DHCP_ENABLE
);
505 ql4_printk(KERN_ERR
, ha
, "Invalid IPv4 bootproto\n");
507 case ISCSI_NET_PARAM_IFACE_ENABLE
:
508 if (iface_param
->value
[0] == ISCSI_IFACE_ENABLE
) {
509 init_fw_cb
->ipv4_ip_opts
|=
510 cpu_to_le16(IPOPT_IPV4_PROTOCOL_ENABLE
);
511 qla4xxx_create_ipv4_iface(ha
);
513 init_fw_cb
->ipv4_ip_opts
&=
514 cpu_to_le16(~IPOPT_IPV4_PROTOCOL_ENABLE
&
516 qla4xxx_destroy_ipv4_iface(ha
);
519 case ISCSI_NET_PARAM_VLAN_ID
:
520 if (iface_param
->len
!= sizeof(init_fw_cb
->ipv4_vlan_tag
))
522 init_fw_cb
->ipv4_vlan_tag
= *(uint16_t *)iface_param
->value
;
525 ql4_printk(KERN_ERR
, ha
, "Unknown IPv4 param = %d\n",
532 qla4xxx_initcb_to_acb(struct addr_ctrl_blk
*init_fw_cb
)
534 struct addr_ctrl_blk_def
*acb
;
535 acb
= (struct addr_ctrl_blk_def
*)init_fw_cb
;
536 memset(acb
->reserved1
, 0, sizeof(acb
->reserved1
));
537 memset(acb
->reserved2
, 0, sizeof(acb
->reserved2
));
538 memset(acb
->reserved3
, 0, sizeof(acb
->reserved3
));
539 memset(acb
->reserved4
, 0, sizeof(acb
->reserved4
));
540 memset(acb
->reserved5
, 0, sizeof(acb
->reserved5
));
541 memset(acb
->reserved6
, 0, sizeof(acb
->reserved6
));
542 memset(acb
->reserved7
, 0, sizeof(acb
->reserved7
));
543 memset(acb
->reserved8
, 0, sizeof(acb
->reserved8
));
544 memset(acb
->reserved9
, 0, sizeof(acb
->reserved9
));
545 memset(acb
->reserved10
, 0, sizeof(acb
->reserved10
));
546 memset(acb
->reserved11
, 0, sizeof(acb
->reserved11
));
547 memset(acb
->reserved12
, 0, sizeof(acb
->reserved12
));
548 memset(acb
->reserved13
, 0, sizeof(acb
->reserved13
));
549 memset(acb
->reserved14
, 0, sizeof(acb
->reserved14
));
550 memset(acb
->reserved15
, 0, sizeof(acb
->reserved15
));
554 qla4xxx_iface_set_param(struct Scsi_Host
*shost
, char *data
, int count
)
556 struct scsi_qla_host
*ha
= to_qla_host(shost
);
558 struct iscsi_iface_param_info
*iface_param
= NULL
;
559 struct addr_ctrl_blk
*init_fw_cb
= NULL
;
560 dma_addr_t init_fw_cb_dma
;
561 uint32_t mbox_cmd
[MBOX_REG_COUNT
];
562 uint32_t mbox_sts
[MBOX_REG_COUNT
];
563 uint32_t total_param_count
;
566 init_fw_cb
= dma_alloc_coherent(&ha
->pdev
->dev
,
567 sizeof(struct addr_ctrl_blk
),
568 &init_fw_cb_dma
, GFP_KERNEL
);
570 ql4_printk(KERN_ERR
, ha
, "%s: Unable to alloc init_cb\n",
575 memset(init_fw_cb
, 0, sizeof(struct addr_ctrl_blk
));
576 memset(&mbox_cmd
, 0, sizeof(mbox_cmd
));
577 memset(&mbox_sts
, 0, sizeof(mbox_sts
));
579 if (qla4xxx_get_ifcb(ha
, &mbox_cmd
[0], &mbox_sts
[0], init_fw_cb_dma
)) {
580 ql4_printk(KERN_ERR
, ha
, "%s: get ifcb failed\n", __func__
);
582 goto exit_init_fw_cb
;
585 total_param_count
= count
;
586 iface_param
= (struct iscsi_iface_param_info
*)data
;
588 for ( ; total_param_count
!= 0; total_param_count
--) {
589 length
= iface_param
->len
;
591 if (iface_param
->param_type
!= ISCSI_NET_PARAM
)
594 switch (iface_param
->iface_type
) {
595 case ISCSI_IFACE_TYPE_IPV4
:
596 switch (iface_param
->iface_num
) {
598 qla4xxx_set_ipv4(ha
, iface_param
, init_fw_cb
);
601 /* Cannot have more than one IPv4 interface */
602 ql4_printk(KERN_ERR
, ha
, "Invalid IPv4 iface "
604 iface_param
->iface_num
);
608 case ISCSI_IFACE_TYPE_IPV6
:
609 switch (iface_param
->iface_num
) {
612 qla4xxx_set_ipv6(ha
, iface_param
, init_fw_cb
);
615 /* Cannot have more than two IPv6 interface */
616 ql4_printk(KERN_ERR
, ha
, "Invalid IPv6 iface "
618 iface_param
->iface_num
);
623 ql4_printk(KERN_ERR
, ha
, "Invalid iface type\n");
627 iface_param
= (struct iscsi_iface_param_info
*)
628 ((uint8_t *)iface_param
+
629 sizeof(struct iscsi_iface_param_info
) + length
);
632 init_fw_cb
->cookie
= cpu_to_le32(0x11BEAD5A);
634 rval
= qla4xxx_set_flash(ha
, init_fw_cb_dma
, FLASH_SEGMENT_IFCB
,
635 sizeof(struct addr_ctrl_blk
),
636 FLASH_OPT_RMW_COMMIT
);
637 if (rval
!= QLA_SUCCESS
) {
638 ql4_printk(KERN_ERR
, ha
, "%s: set flash mbx failed\n",
641 goto exit_init_fw_cb
;
644 qla4xxx_disable_acb(ha
);
646 qla4xxx_initcb_to_acb(init_fw_cb
);
648 rval
= qla4xxx_set_acb(ha
, &mbox_cmd
[0], &mbox_sts
[0], init_fw_cb_dma
);
649 if (rval
!= QLA_SUCCESS
) {
650 ql4_printk(KERN_ERR
, ha
, "%s: set acb mbx failed\n",
653 goto exit_init_fw_cb
;
656 memset(init_fw_cb
, 0, sizeof(struct addr_ctrl_blk
));
657 qla4xxx_update_local_ifcb(ha
, &mbox_cmd
[0], &mbox_sts
[0], init_fw_cb
,
661 dma_free_coherent(&ha
->pdev
->dev
, sizeof(struct addr_ctrl_blk
),
662 init_fw_cb
, init_fw_cb_dma
);
667 static int qla4xxx_sess_get_param(struct iscsi_cls_session
*sess
,
668 enum iscsi_param param
, char *buf
)
670 struct ddb_entry
*ddb_entry
= sess
->dd_data
;
674 case ISCSI_PARAM_TARGET_NAME
:
675 len
= snprintf(buf
, PAGE_SIZE
- 1, "%s\n",
676 ddb_entry
->iscsi_name
);
678 case ISCSI_PARAM_TPGT
:
679 len
= sprintf(buf
, "%u\n", ddb_entry
->tpgt
);
681 case ISCSI_PARAM_TARGET_ALIAS
:
682 len
= snprintf(buf
, PAGE_SIZE
- 1, "%s\n",
683 ddb_entry
->iscsi_alias
);
692 static int qla4xxx_conn_get_param(struct iscsi_cls_conn
*conn
,
693 enum iscsi_param param
, char *buf
)
695 struct iscsi_cls_session
*session
;
696 struct ddb_entry
*ddb_entry
;
699 session
= iscsi_dev_to_session(conn
->dev
.parent
);
700 ddb_entry
= session
->dd_data
;
703 case ISCSI_PARAM_CONN_PORT
:
704 len
= sprintf(buf
, "%hu\n", ddb_entry
->port
);
706 case ISCSI_PARAM_CONN_ADDRESS
:
707 /* TODO: what are the ipv6 bits */
708 len
= sprintf(buf
, "%pI4\n", &ddb_entry
->ip_addr
);
717 static int qla4xxx_tgt_dscvr(struct Scsi_Host
*shost
,
718 enum iscsi_tgt_dscvr type
, uint32_t enable
,
719 struct sockaddr
*dst_addr
)
721 struct scsi_qla_host
*ha
;
722 struct sockaddr_in
*addr
;
723 struct sockaddr_in6
*addr6
;
726 ha
= (struct scsi_qla_host
*) shost
->hostdata
;
729 case ISCSI_TGT_DSCVR_SEND_TARGETS
:
730 if (dst_addr
->sa_family
== AF_INET
) {
731 addr
= (struct sockaddr_in
*)dst_addr
;
732 if (qla4xxx_send_tgts(ha
, (char *)&addr
->sin_addr
,
733 addr
->sin_port
) != QLA_SUCCESS
)
735 } else if (dst_addr
->sa_family
== AF_INET6
) {
737 * TODO: fix qla4xxx_send_tgts
739 addr6
= (struct sockaddr_in6
*)dst_addr
;
740 if (qla4xxx_send_tgts(ha
, (char *)&addr6
->sin6_addr
,
741 addr6
->sin6_port
) != QLA_SUCCESS
)
752 void qla4xxx_destroy_sess(struct ddb_entry
*ddb_entry
)
754 if (!ddb_entry
->sess
)
757 if (ddb_entry
->conn
) {
758 atomic_set(&ddb_entry
->state
, DDB_STATE_DEAD
);
759 iscsi_remove_session(ddb_entry
->sess
);
761 iscsi_free_session(ddb_entry
->sess
);
764 int qla4xxx_add_sess(struct ddb_entry
*ddb_entry
)
768 ddb_entry
->sess
->recovery_tmo
= ql4xsess_recovery_tmo
;
770 err
= iscsi_add_session(ddb_entry
->sess
, ddb_entry
->fw_ddb_index
);
772 DEBUG2(printk(KERN_ERR
"Could not add session.\n"));
776 ddb_entry
->conn
= iscsi_create_conn(ddb_entry
->sess
, 0, 0);
777 if (!ddb_entry
->conn
) {
778 iscsi_remove_session(ddb_entry
->sess
);
779 DEBUG2(printk(KERN_ERR
"Could not add connection.\n"));
783 /* finally ready to go */
784 iscsi_unblock_session(ddb_entry
->sess
);
788 struct ddb_entry
*qla4xxx_alloc_sess(struct scsi_qla_host
*ha
)
790 struct ddb_entry
*ddb_entry
;
791 struct iscsi_cls_session
*sess
;
793 sess
= iscsi_alloc_session(ha
->host
, &qla4xxx_iscsi_transport
,
794 sizeof(struct ddb_entry
));
798 ddb_entry
= sess
->dd_data
;
799 memset(ddb_entry
, 0, sizeof(*ddb_entry
));
801 ddb_entry
->sess
= sess
;
805 static void qla4xxx_scan_start(struct Scsi_Host
*shost
)
807 struct scsi_qla_host
*ha
= shost_priv(shost
);
808 struct ddb_entry
*ddb_entry
, *ddbtemp
;
810 /* finish setup of sessions that were already setup in firmware */
811 list_for_each_entry_safe(ddb_entry
, ddbtemp
, &ha
->ddb_list
, list
) {
812 if (ddb_entry
->fw_ddb_device_state
== DDB_DS_SESSION_ACTIVE
)
813 qla4xxx_add_sess(ddb_entry
);
821 static void qla4xxx_start_timer(struct scsi_qla_host
*ha
, void *func
,
822 unsigned long interval
)
824 DEBUG(printk("scsi: %s: Starting timer thread for adapter %d\n",
825 __func__
, ha
->host
->host_no
));
826 init_timer(&ha
->timer
);
827 ha
->timer
.expires
= jiffies
+ interval
* HZ
;
828 ha
->timer
.data
= (unsigned long)ha
;
829 ha
->timer
.function
= (void (*)(unsigned long))func
;
830 add_timer(&ha
->timer
);
831 ha
->timer_active
= 1;
834 static void qla4xxx_stop_timer(struct scsi_qla_host
*ha
)
836 del_timer_sync(&ha
->timer
);
837 ha
->timer_active
= 0;
841 * qla4xxx_mark_device_missing - mark a device as missing.
842 * @ha: Pointer to host adapter structure.
843 * @ddb_entry: Pointer to device database entry
845 * This routine marks a device missing and close connection.
847 void qla4xxx_mark_device_missing(struct scsi_qla_host
*ha
,
848 struct ddb_entry
*ddb_entry
)
850 if ((atomic_read(&ddb_entry
->state
) != DDB_STATE_DEAD
)) {
851 atomic_set(&ddb_entry
->state
, DDB_STATE_MISSING
);
852 DEBUG2(printk("scsi%ld: ddb [%d] marked MISSING\n",
853 ha
->host_no
, ddb_entry
->fw_ddb_index
));
855 DEBUG2(printk("scsi%ld: ddb [%d] DEAD\n", ha
->host_no
,
856 ddb_entry
->fw_ddb_index
))
858 iscsi_block_session(ddb_entry
->sess
);
859 iscsi_conn_error_event(ddb_entry
->conn
, ISCSI_ERR_CONN_FAILED
);
863 * qla4xxx_mark_all_devices_missing - mark all devices as missing.
864 * @ha: Pointer to host adapter structure.
866 * This routine marks a device missing and resets the relogin retry count.
868 void qla4xxx_mark_all_devices_missing(struct scsi_qla_host
*ha
)
870 struct ddb_entry
*ddb_entry
, *ddbtemp
;
871 list_for_each_entry_safe(ddb_entry
, ddbtemp
, &ha
->ddb_list
, list
) {
872 qla4xxx_mark_device_missing(ha
, ddb_entry
);
876 static struct srb
* qla4xxx_get_new_srb(struct scsi_qla_host
*ha
,
877 struct ddb_entry
*ddb_entry
,
878 struct scsi_cmnd
*cmd
)
882 srb
= mempool_alloc(ha
->srb_mempool
, GFP_ATOMIC
);
886 kref_init(&srb
->srb_ref
);
888 srb
->ddb
= ddb_entry
;
891 CMD_SP(cmd
) = (void *)srb
;
896 static void qla4xxx_srb_free_dma(struct scsi_qla_host
*ha
, struct srb
*srb
)
898 struct scsi_cmnd
*cmd
= srb
->cmd
;
900 if (srb
->flags
& SRB_DMA_VALID
) {
902 srb
->flags
&= ~SRB_DMA_VALID
;
907 void qla4xxx_srb_compl(struct kref
*ref
)
909 struct srb
*srb
= container_of(ref
, struct srb
, srb_ref
);
910 struct scsi_cmnd
*cmd
= srb
->cmd
;
911 struct scsi_qla_host
*ha
= srb
->ha
;
913 qla4xxx_srb_free_dma(ha
, srb
);
915 mempool_free(srb
, ha
->srb_mempool
);
921 * qla4xxx_queuecommand - scsi layer issues scsi command to driver.
923 * @cmd: Pointer to Linux's SCSI command structure
926 * This routine is invoked by Linux to send a SCSI command to the driver.
927 * The mid-level driver tries to ensure that queuecommand never gets
928 * invoked concurrently with itself or the interrupt handler (although
929 * the interrupt handler may call this routine as part of request-
930 * completion handling). Unfortunely, it sometimes calls the scheduler
931 * in interrupt context which is a big NO! NO!.
933 static int qla4xxx_queuecommand(struct Scsi_Host
*host
, struct scsi_cmnd
*cmd
)
935 struct scsi_qla_host
*ha
= to_qla_host(host
);
936 struct ddb_entry
*ddb_entry
= cmd
->device
->hostdata
;
937 struct iscsi_cls_session
*sess
= ddb_entry
->sess
;
941 if (test_bit(AF_EEH_BUSY
, &ha
->flags
)) {
942 if (test_bit(AF_PCI_CHANNEL_IO_PERM_FAILURE
, &ha
->flags
))
943 cmd
->result
= DID_NO_CONNECT
<< 16;
945 cmd
->result
= DID_REQUEUE
<< 16;
946 goto qc_fail_command
;
950 cmd
->result
= DID_IMM_RETRY
<< 16;
951 goto qc_fail_command
;
954 rval
= iscsi_session_chkready(sess
);
957 goto qc_fail_command
;
960 if (atomic_read(&ddb_entry
->state
) != DDB_STATE_ONLINE
) {
961 if (atomic_read(&ddb_entry
->state
) == DDB_STATE_DEAD
) {
962 cmd
->result
= DID_NO_CONNECT
<< 16;
963 goto qc_fail_command
;
965 return SCSI_MLQUEUE_TARGET_BUSY
;
968 if (test_bit(DPC_RESET_HA_INTR
, &ha
->dpc_flags
) ||
969 test_bit(DPC_RESET_ACTIVE
, &ha
->dpc_flags
) ||
970 test_bit(DPC_RESET_HA
, &ha
->dpc_flags
) ||
971 test_bit(DPC_HA_UNRECOVERABLE
, &ha
->dpc_flags
) ||
972 test_bit(DPC_HA_NEED_QUIESCENT
, &ha
->dpc_flags
) ||
973 !test_bit(AF_ONLINE
, &ha
->flags
) ||
974 test_bit(DPC_RESET_HA_FW_CONTEXT
, &ha
->dpc_flags
))
977 srb
= qla4xxx_get_new_srb(ha
, ddb_entry
, cmd
);
981 rval
= qla4xxx_send_command_to_isp(ha
, srb
);
982 if (rval
!= QLA_SUCCESS
)
983 goto qc_host_busy_free_sp
;
987 qc_host_busy_free_sp
:
988 qla4xxx_srb_free_dma(ha
, srb
);
989 mempool_free(srb
, ha
->srb_mempool
);
992 return SCSI_MLQUEUE_HOST_BUSY
;
1001 * qla4xxx_mem_free - frees memory allocated to adapter
1002 * @ha: Pointer to host adapter structure.
1004 * Frees memory previously allocated by qla4xxx_mem_alloc
1006 static void qla4xxx_mem_free(struct scsi_qla_host
*ha
)
1009 dma_free_coherent(&ha
->pdev
->dev
, ha
->queues_len
, ha
->queues
,
1015 ha
->request_ring
= NULL
;
1016 ha
->request_dma
= 0;
1017 ha
->response_ring
= NULL
;
1018 ha
->response_dma
= 0;
1019 ha
->shadow_regs
= NULL
;
1020 ha
->shadow_regs_dma
= 0;
1022 /* Free srb pool. */
1023 if (ha
->srb_mempool
)
1024 mempool_destroy(ha
->srb_mempool
);
1026 ha
->srb_mempool
= NULL
;
1028 /* release io space registers */
1029 if (is_qla8022(ha
)) {
1032 (struct device_reg_82xx __iomem
*)ha
->nx_pcibase
);
1035 pci_release_regions(ha
->pdev
);
1039 * qla4xxx_mem_alloc - allocates memory for use by adapter.
1040 * @ha: Pointer to host adapter structure
1042 * Allocates DMA memory for request and response queues. Also allocates memory
1045 static int qla4xxx_mem_alloc(struct scsi_qla_host
*ha
)
1047 unsigned long align
;
1049 /* Allocate contiguous block of DMA memory for queues. */
1050 ha
->queues_len
= ((REQUEST_QUEUE_DEPTH
* QUEUE_SIZE
) +
1051 (RESPONSE_QUEUE_DEPTH
* QUEUE_SIZE
) +
1052 sizeof(struct shadow_regs
) +
1054 (PAGE_SIZE
- 1)) & ~(PAGE_SIZE
- 1);
1055 ha
->queues
= dma_alloc_coherent(&ha
->pdev
->dev
, ha
->queues_len
,
1056 &ha
->queues_dma
, GFP_KERNEL
);
1057 if (ha
->queues
== NULL
) {
1058 ql4_printk(KERN_WARNING
, ha
,
1059 "Memory Allocation failed - queues.\n");
1061 goto mem_alloc_error_exit
;
1063 memset(ha
->queues
, 0, ha
->queues_len
);
1066 * As per RISC alignment requirements -- the bus-address must be a
1067 * multiple of the request-ring size (in bytes).
1070 if ((unsigned long)ha
->queues_dma
& (MEM_ALIGN_VALUE
- 1))
1071 align
= MEM_ALIGN_VALUE
- ((unsigned long)ha
->queues_dma
&
1072 (MEM_ALIGN_VALUE
- 1));
1074 /* Update request and response queue pointers. */
1075 ha
->request_dma
= ha
->queues_dma
+ align
;
1076 ha
->request_ring
= (struct queue_entry
*) (ha
->queues
+ align
);
1077 ha
->response_dma
= ha
->queues_dma
+ align
+
1078 (REQUEST_QUEUE_DEPTH
* QUEUE_SIZE
);
1079 ha
->response_ring
= (struct queue_entry
*) (ha
->queues
+ align
+
1080 (REQUEST_QUEUE_DEPTH
*
1082 ha
->shadow_regs_dma
= ha
->queues_dma
+ align
+
1083 (REQUEST_QUEUE_DEPTH
* QUEUE_SIZE
) +
1084 (RESPONSE_QUEUE_DEPTH
* QUEUE_SIZE
);
1085 ha
->shadow_regs
= (struct shadow_regs
*) (ha
->queues
+ align
+
1086 (REQUEST_QUEUE_DEPTH
*
1088 (RESPONSE_QUEUE_DEPTH
*
1091 /* Allocate memory for srb pool. */
1092 ha
->srb_mempool
= mempool_create(SRB_MIN_REQ
, mempool_alloc_slab
,
1093 mempool_free_slab
, srb_cachep
);
1094 if (ha
->srb_mempool
== NULL
) {
1095 ql4_printk(KERN_WARNING
, ha
,
1096 "Memory Allocation failed - SRB Pool.\n");
1098 goto mem_alloc_error_exit
;
1103 mem_alloc_error_exit
:
1104 qla4xxx_mem_free(ha
);
1109 * qla4_8xxx_check_fw_alive - Check firmware health
1110 * @ha: Pointer to host adapter structure.
1112 * Context: Interrupt
1114 static void qla4_8xxx_check_fw_alive(struct scsi_qla_host
*ha
)
1116 uint32_t fw_heartbeat_counter
, halt_status
;
1118 fw_heartbeat_counter
= qla4_8xxx_rd_32(ha
, QLA82XX_PEG_ALIVE_COUNTER
);
1119 /* If PEG_ALIVE_COUNTER is 0xffffffff, AER/EEH is in progress, ignore */
1120 if (fw_heartbeat_counter
== 0xffffffff) {
1121 DEBUG2(printk(KERN_WARNING
"scsi%ld: %s: Device in frozen "
1122 "state, QLA82XX_PEG_ALIVE_COUNTER is 0xffffffff\n",
1123 ha
->host_no
, __func__
));
1127 if (ha
->fw_heartbeat_counter
== fw_heartbeat_counter
) {
1128 ha
->seconds_since_last_heartbeat
++;
1129 /* FW not alive after 2 seconds */
1130 if (ha
->seconds_since_last_heartbeat
== 2) {
1131 ha
->seconds_since_last_heartbeat
= 0;
1132 halt_status
= qla4_8xxx_rd_32(ha
,
1133 QLA82XX_PEG_HALT_STATUS1
);
1135 ql4_printk(KERN_INFO
, ha
,
1136 "scsi(%ld): %s, Dumping hw/fw registers:\n "
1137 " PEG_HALT_STATUS1: 0x%x, PEG_HALT_STATUS2:"
1138 " 0x%x,\n PEG_NET_0_PC: 0x%x, PEG_NET_1_PC:"
1139 " 0x%x,\n PEG_NET_2_PC: 0x%x, PEG_NET_3_PC:"
1140 " 0x%x,\n PEG_NET_4_PC: 0x%x\n",
1141 ha
->host_no
, __func__
, halt_status
,
1143 QLA82XX_PEG_HALT_STATUS2
),
1144 qla4_8xxx_rd_32(ha
, QLA82XX_CRB_PEG_NET_0
+
1146 qla4_8xxx_rd_32(ha
, QLA82XX_CRB_PEG_NET_1
+
1148 qla4_8xxx_rd_32(ha
, QLA82XX_CRB_PEG_NET_2
+
1150 qla4_8xxx_rd_32(ha
, QLA82XX_CRB_PEG_NET_3
+
1152 qla4_8xxx_rd_32(ha
, QLA82XX_CRB_PEG_NET_4
+
1155 /* Since we cannot change dev_state in interrupt
1156 * context, set appropriate DPC flag then wakeup
1158 if (halt_status
& HALT_STATUS_UNRECOVERABLE
)
1159 set_bit(DPC_HA_UNRECOVERABLE
, &ha
->dpc_flags
);
1161 printk("scsi%ld: %s: detect abort needed!\n",
1162 ha
->host_no
, __func__
);
1163 set_bit(DPC_RESET_HA
, &ha
->dpc_flags
);
1165 qla4xxx_wake_dpc(ha
);
1166 qla4xxx_mailbox_premature_completion(ha
);
1169 ha
->seconds_since_last_heartbeat
= 0;
1171 ha
->fw_heartbeat_counter
= fw_heartbeat_counter
;
1175 * qla4_8xxx_watchdog - Poll dev state
1176 * @ha: Pointer to host adapter structure.
1178 * Context: Interrupt
1180 void qla4_8xxx_watchdog(struct scsi_qla_host
*ha
)
1184 dev_state
= qla4_8xxx_rd_32(ha
, QLA82XX_CRB_DEV_STATE
);
1186 /* don't poll if reset is going on */
1187 if (!(test_bit(DPC_RESET_ACTIVE
, &ha
->dpc_flags
) ||
1188 test_bit(DPC_RESET_HA
, &ha
->dpc_flags
) ||
1189 test_bit(DPC_RETRY_RESET_HA
, &ha
->dpc_flags
))) {
1190 if (dev_state
== QLA82XX_DEV_NEED_RESET
&&
1191 !test_bit(DPC_RESET_HA
, &ha
->dpc_flags
)) {
1192 if (!ql4xdontresethba
) {
1193 ql4_printk(KERN_INFO
, ha
, "%s: HW State: "
1194 "NEED RESET!\n", __func__
);
1195 set_bit(DPC_RESET_HA
, &ha
->dpc_flags
);
1196 qla4xxx_wake_dpc(ha
);
1197 qla4xxx_mailbox_premature_completion(ha
);
1199 } else if (dev_state
== QLA82XX_DEV_NEED_QUIESCENT
&&
1200 !test_bit(DPC_HA_NEED_QUIESCENT
, &ha
->dpc_flags
)) {
1201 ql4_printk(KERN_INFO
, ha
, "%s: HW State: NEED QUIES!\n",
1203 set_bit(DPC_HA_NEED_QUIESCENT
, &ha
->dpc_flags
);
1204 qla4xxx_wake_dpc(ha
);
1206 /* Check firmware health */
1207 qla4_8xxx_check_fw_alive(ha
);
1213 * qla4xxx_timer - checks every second for work to do.
1214 * @ha: Pointer to host adapter structure.
1216 static void qla4xxx_timer(struct scsi_qla_host
*ha
)
1218 struct ddb_entry
*ddb_entry
, *dtemp
;
1222 /* If we are in the middle of AER/EEH processing
1223 * skip any processing and reschedule the timer
1225 if (test_bit(AF_EEH_BUSY
, &ha
->flags
)) {
1226 mod_timer(&ha
->timer
, jiffies
+ HZ
);
1230 /* Hardware read to trigger an EEH error during mailbox waits. */
1231 if (!pci_channel_offline(ha
->pdev
))
1232 pci_read_config_word(ha
->pdev
, PCI_VENDOR_ID
, &w
);
1234 if (is_qla8022(ha
)) {
1235 qla4_8xxx_watchdog(ha
);
1238 /* Search for relogin's to time-out and port down retry. */
1239 list_for_each_entry_safe(ddb_entry
, dtemp
, &ha
->ddb_list
, list
) {
1240 /* Count down time between sending relogins */
1241 if (adapter_up(ha
) &&
1242 !test_bit(DF_RELOGIN
, &ddb_entry
->flags
) &&
1243 atomic_read(&ddb_entry
->state
) != DDB_STATE_ONLINE
) {
1244 if (atomic_read(&ddb_entry
->retry_relogin_timer
) !=
1246 if (atomic_read(&ddb_entry
->retry_relogin_timer
)
1248 atomic_set(&ddb_entry
->
1249 retry_relogin_timer
,
1251 set_bit(DPC_RELOGIN_DEVICE
,
1253 set_bit(DF_RELOGIN
, &ddb_entry
->flags
);
1254 DEBUG2(printk("scsi%ld: %s: ddb [%d]"
1256 ha
->host_no
, __func__
,
1257 ddb_entry
->fw_ddb_index
));
1259 atomic_dec(&ddb_entry
->
1260 retry_relogin_timer
);
1264 /* Wait for relogin to timeout */
1265 if (atomic_read(&ddb_entry
->relogin_timer
) &&
1266 (atomic_dec_and_test(&ddb_entry
->relogin_timer
) != 0)) {
1268 * If the relogin times out and the device is
1269 * still NOT ONLINE then try and relogin again.
1271 if (atomic_read(&ddb_entry
->state
) !=
1273 ddb_entry
->fw_ddb_device_state
==
1274 DDB_DS_SESSION_FAILED
) {
1275 /* Reset retry relogin timer */
1276 atomic_inc(&ddb_entry
->relogin_retry_count
);
1277 DEBUG2(printk("scsi%ld: ddb [%d] relogin"
1278 " timed out-retrying"
1281 ddb_entry
->fw_ddb_index
,
1282 atomic_read(&ddb_entry
->
1283 relogin_retry_count
))
1286 DEBUG(printk("scsi%ld:%d:%d: ddb [%d] "
1287 "initiate relogin after"
1289 ha
->host_no
, ddb_entry
->bus
,
1291 ddb_entry
->fw_ddb_index
,
1292 ddb_entry
->default_time2wait
+ 4)
1295 atomic_set(&ddb_entry
->retry_relogin_timer
,
1296 ddb_entry
->default_time2wait
+ 4);
1301 if (!is_qla8022(ha
)) {
1302 /* Check for heartbeat interval. */
1303 if (ha
->firmware_options
& FWOPT_HEARTBEAT_ENABLE
&&
1304 ha
->heartbeat_interval
!= 0) {
1305 ha
->seconds_since_last_heartbeat
++;
1306 if (ha
->seconds_since_last_heartbeat
>
1307 ha
->heartbeat_interval
+ 2)
1308 set_bit(DPC_RESET_HA
, &ha
->dpc_flags
);
1312 /* Wakeup the dpc routine for this adapter, if needed. */
1314 test_bit(DPC_RESET_HA
, &ha
->dpc_flags
) ||
1315 test_bit(DPC_RETRY_RESET_HA
, &ha
->dpc_flags
) ||
1316 test_bit(DPC_RELOGIN_DEVICE
, &ha
->dpc_flags
) ||
1317 test_bit(DPC_RESET_HA_FW_CONTEXT
, &ha
->dpc_flags
) ||
1318 test_bit(DPC_RESET_HA_INTR
, &ha
->dpc_flags
) ||
1319 test_bit(DPC_GET_DHCP_IP_ADDR
, &ha
->dpc_flags
) ||
1320 test_bit(DPC_LINK_CHANGED
, &ha
->dpc_flags
) ||
1321 test_bit(DPC_HA_UNRECOVERABLE
, &ha
->dpc_flags
) ||
1322 test_bit(DPC_HA_NEED_QUIESCENT
, &ha
->dpc_flags
) ||
1323 test_bit(DPC_AEN
, &ha
->dpc_flags
)) {
1324 DEBUG2(printk("scsi%ld: %s: scheduling dpc routine"
1325 " - dpc flags = 0x%lx\n",
1326 ha
->host_no
, __func__
, ha
->dpc_flags
));
1327 qla4xxx_wake_dpc(ha
);
1330 /* Reschedule timer thread to call us back in one second */
1331 mod_timer(&ha
->timer
, jiffies
+ HZ
);
1333 DEBUG2(ha
->seconds_since_last_intr
++);
1337 * qla4xxx_cmd_wait - waits for all outstanding commands to complete
1338 * @ha: Pointer to host adapter structure.
1340 * This routine stalls the driver until all outstanding commands are returned.
1341 * Caller must release the Hardware Lock prior to calling this routine.
1343 static int qla4xxx_cmd_wait(struct scsi_qla_host
*ha
)
1346 unsigned long flags
;
1347 struct scsi_cmnd
*cmd
;
1349 unsigned long wtime
= jiffies
+ (WAIT_CMD_TOV
* HZ
);
1351 DEBUG2(ql4_printk(KERN_INFO
, ha
, "Wait up to %d seconds for cmds to "
1352 "complete\n", WAIT_CMD_TOV
));
1354 while (!time_after_eq(jiffies
, wtime
)) {
1355 spin_lock_irqsave(&ha
->hardware_lock
, flags
);
1356 /* Find a command that hasn't completed. */
1357 for (index
= 0; index
< ha
->host
->can_queue
; index
++) {
1358 cmd
= scsi_host_find_tag(ha
->host
, index
);
1360 * We cannot just check if the index is valid,
1361 * becase if we are run from the scsi eh, then
1362 * the scsi/block layer is going to prevent
1363 * the tag from being released.
1365 if (cmd
!= NULL
&& CMD_SP(cmd
))
1368 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
1370 /* If No Commands are pending, wait is complete */
1371 if (index
== ha
->host
->can_queue
)
1376 /* If we timed out on waiting for commands to come back
1381 int qla4xxx_hw_reset(struct scsi_qla_host
*ha
)
1383 uint32_t ctrl_status
;
1384 unsigned long flags
= 0;
1386 DEBUG2(printk(KERN_ERR
"scsi%ld: %s\n", ha
->host_no
, __func__
));
1388 if (ql4xxx_lock_drvr_wait(ha
) != QLA_SUCCESS
)
1391 spin_lock_irqsave(&ha
->hardware_lock
, flags
);
1394 * If the SCSI Reset Interrupt bit is set, clear it.
1395 * Otherwise, the Soft Reset won't work.
1397 ctrl_status
= readw(&ha
->reg
->ctrl_status
);
1398 if ((ctrl_status
& CSR_SCSI_RESET_INTR
) != 0)
1399 writel(set_rmask(CSR_SCSI_RESET_INTR
), &ha
->reg
->ctrl_status
);
1401 /* Issue Soft Reset */
1402 writel(set_rmask(CSR_SOFT_RESET
), &ha
->reg
->ctrl_status
);
1403 readl(&ha
->reg
->ctrl_status
);
1405 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
1410 * qla4xxx_soft_reset - performs soft reset.
1411 * @ha: Pointer to host adapter structure.
1413 int qla4xxx_soft_reset(struct scsi_qla_host
*ha
)
1415 uint32_t max_wait_time
;
1416 unsigned long flags
= 0;
1418 uint32_t ctrl_status
;
1420 status
= qla4xxx_hw_reset(ha
);
1421 if (status
!= QLA_SUCCESS
)
1425 /* Wait until the Network Reset Intr bit is cleared */
1426 max_wait_time
= RESET_INTR_TOV
;
1428 spin_lock_irqsave(&ha
->hardware_lock
, flags
);
1429 ctrl_status
= readw(&ha
->reg
->ctrl_status
);
1430 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
1432 if ((ctrl_status
& CSR_NET_RESET_INTR
) == 0)
1436 } while ((--max_wait_time
));
1438 if ((ctrl_status
& CSR_NET_RESET_INTR
) != 0) {
1439 DEBUG2(printk(KERN_WARNING
1440 "scsi%ld: Network Reset Intr not cleared by "
1441 "Network function, clearing it now!\n",
1443 spin_lock_irqsave(&ha
->hardware_lock
, flags
);
1444 writel(set_rmask(CSR_NET_RESET_INTR
), &ha
->reg
->ctrl_status
);
1445 readl(&ha
->reg
->ctrl_status
);
1446 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
1449 /* Wait until the firmware tells us the Soft Reset is done */
1450 max_wait_time
= SOFT_RESET_TOV
;
1452 spin_lock_irqsave(&ha
->hardware_lock
, flags
);
1453 ctrl_status
= readw(&ha
->reg
->ctrl_status
);
1454 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
1456 if ((ctrl_status
& CSR_SOFT_RESET
) == 0) {
1457 status
= QLA_SUCCESS
;
1462 } while ((--max_wait_time
));
1465 * Also, make sure that the SCSI Reset Interrupt bit has been cleared
1466 * after the soft reset has taken place.
1468 spin_lock_irqsave(&ha
->hardware_lock
, flags
);
1469 ctrl_status
= readw(&ha
->reg
->ctrl_status
);
1470 if ((ctrl_status
& CSR_SCSI_RESET_INTR
) != 0) {
1471 writel(set_rmask(CSR_SCSI_RESET_INTR
), &ha
->reg
->ctrl_status
);
1472 readl(&ha
->reg
->ctrl_status
);
1474 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
1476 /* If soft reset fails then most probably the bios on other
1477 * function is also enabled.
1478 * Since the initialization is sequential the other fn
1479 * wont be able to acknowledge the soft reset.
1480 * Issue a force soft reset to workaround this scenario.
1482 if (max_wait_time
== 0) {
1483 /* Issue Force Soft Reset */
1484 spin_lock_irqsave(&ha
->hardware_lock
, flags
);
1485 writel(set_rmask(CSR_FORCE_SOFT_RESET
), &ha
->reg
->ctrl_status
);
1486 readl(&ha
->reg
->ctrl_status
);
1487 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
1488 /* Wait until the firmware tells us the Soft Reset is done */
1489 max_wait_time
= SOFT_RESET_TOV
;
1491 spin_lock_irqsave(&ha
->hardware_lock
, flags
);
1492 ctrl_status
= readw(&ha
->reg
->ctrl_status
);
1493 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
1495 if ((ctrl_status
& CSR_FORCE_SOFT_RESET
) == 0) {
1496 status
= QLA_SUCCESS
;
1501 } while ((--max_wait_time
));
1508 * qla4xxx_abort_active_cmds - returns all outstanding i/o requests to O.S.
1509 * @ha: Pointer to host adapter structure.
1510 * @res: returned scsi status
1512 * This routine is called just prior to a HARD RESET to return all
1513 * outstanding commands back to the Operating System.
1514 * Caller should make sure that the following locks are released
1515 * before this calling routine: Hardware lock, and io_request_lock.
1517 static void qla4xxx_abort_active_cmds(struct scsi_qla_host
*ha
, int res
)
1521 unsigned long flags
;
1523 spin_lock_irqsave(&ha
->hardware_lock
, flags
);
1524 for (i
= 0; i
< ha
->host
->can_queue
; i
++) {
1525 srb
= qla4xxx_del_from_active_array(ha
, i
);
1527 srb
->cmd
->result
= res
;
1528 kref_put(&srb
->srb_ref
, qla4xxx_srb_compl
);
1531 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
1534 void qla4xxx_dead_adapter_cleanup(struct scsi_qla_host
*ha
)
1536 clear_bit(AF_ONLINE
, &ha
->flags
);
1538 /* Disable the board */
1539 ql4_printk(KERN_INFO
, ha
, "Disabling the board\n");
1541 qla4xxx_abort_active_cmds(ha
, DID_NO_CONNECT
<< 16);
1542 qla4xxx_mark_all_devices_missing(ha
);
1543 clear_bit(AF_INIT_DONE
, &ha
->flags
);
1547 * qla4xxx_recover_adapter - recovers adapter after a fatal error
1548 * @ha: Pointer to host adapter structure.
1550 static int qla4xxx_recover_adapter(struct scsi_qla_host
*ha
)
1552 int status
= QLA_ERROR
;
1553 uint8_t reset_chip
= 0;
1555 /* Stall incoming I/O until we are done */
1556 scsi_block_requests(ha
->host
);
1557 clear_bit(AF_ONLINE
, &ha
->flags
);
1559 DEBUG2(ql4_printk(KERN_INFO
, ha
, "%s: adapter OFFLINE\n", __func__
));
1561 set_bit(DPC_RESET_ACTIVE
, &ha
->dpc_flags
);
1563 if (test_bit(DPC_RESET_HA
, &ha
->dpc_flags
))
1566 /* For the DPC_RESET_HA_INTR case (ISP-4xxx specific)
1567 * do not reset adapter, jump to initialize_adapter */
1568 if (test_bit(DPC_RESET_HA_INTR
, &ha
->dpc_flags
)) {
1569 status
= QLA_SUCCESS
;
1570 goto recover_ha_init_adapter
;
1573 /* For the ISP-82xx adapter, issue a stop_firmware if invoked
1574 * from eh_host_reset or ioctl module */
1575 if (is_qla8022(ha
) && !reset_chip
&&
1576 test_bit(DPC_RESET_HA_FW_CONTEXT
, &ha
->dpc_flags
)) {
1578 DEBUG2(ql4_printk(KERN_INFO
, ha
,
1579 "scsi%ld: %s - Performing stop_firmware...\n",
1580 ha
->host_no
, __func__
));
1581 status
= ha
->isp_ops
->reset_firmware(ha
);
1582 if (status
== QLA_SUCCESS
) {
1583 if (!test_bit(AF_FW_RECOVERY
, &ha
->flags
))
1584 qla4xxx_cmd_wait(ha
);
1585 ha
->isp_ops
->disable_intrs(ha
);
1586 qla4xxx_process_aen(ha
, FLUSH_DDB_CHANGED_AENS
);
1587 qla4xxx_abort_active_cmds(ha
, DID_RESET
<< 16);
1589 /* If the stop_firmware fails then
1590 * reset the entire chip */
1592 clear_bit(DPC_RESET_HA_FW_CONTEXT
, &ha
->dpc_flags
);
1593 set_bit(DPC_RESET_HA
, &ha
->dpc_flags
);
1597 /* Issue full chip reset if recovering from a catastrophic error,
1598 * or if stop_firmware fails for ISP-82xx.
1599 * This is the default case for ISP-4xxx */
1600 if (!is_qla8022(ha
) || reset_chip
) {
1601 if (!test_bit(AF_FW_RECOVERY
, &ha
->flags
))
1602 qla4xxx_cmd_wait(ha
);
1603 qla4xxx_process_aen(ha
, FLUSH_DDB_CHANGED_AENS
);
1604 qla4xxx_abort_active_cmds(ha
, DID_RESET
<< 16);
1605 DEBUG2(ql4_printk(KERN_INFO
, ha
,
1606 "scsi%ld: %s - Performing chip reset..\n",
1607 ha
->host_no
, __func__
));
1608 status
= ha
->isp_ops
->reset_chip(ha
);
1611 /* Flush any pending ddb changed AENs */
1612 qla4xxx_process_aen(ha
, FLUSH_DDB_CHANGED_AENS
);
1614 recover_ha_init_adapter
:
1615 /* Upon successful firmware/chip reset, re-initialize the adapter */
1616 if (status
== QLA_SUCCESS
) {
1617 /* For ISP-4xxx, force function 1 to always initialize
1618 * before function 3 to prevent both funcions from
1619 * stepping on top of the other */
1620 if (!is_qla8022(ha
) && (ha
->mac_index
== 3))
1623 /* NOTE: AF_ONLINE flag set upon successful completion of
1624 * qla4xxx_initialize_adapter */
1625 status
= qla4xxx_initialize_adapter(ha
, PRESERVE_DDB_LIST
);
1628 /* Retry failed adapter initialization, if necessary
1629 * Do not retry initialize_adapter for RESET_HA_INTR (ISP-4xxx specific)
1630 * case to prevent ping-pong resets between functions */
1631 if (!test_bit(AF_ONLINE
, &ha
->flags
) &&
1632 !test_bit(DPC_RESET_HA_INTR
, &ha
->dpc_flags
)) {
1633 /* Adapter initialization failed, see if we can retry
1635 * Since we don't want to block the DPC for too long
1636 * with multiple resets in the same thread,
1637 * utilize DPC to retry */
1638 if (!test_bit(DPC_RETRY_RESET_HA
, &ha
->dpc_flags
)) {
1639 ha
->retry_reset_ha_cnt
= MAX_RESET_HA_RETRIES
;
1640 DEBUG2(printk("scsi%ld: recover adapter - retrying "
1641 "(%d) more times\n", ha
->host_no
,
1642 ha
->retry_reset_ha_cnt
));
1643 set_bit(DPC_RETRY_RESET_HA
, &ha
->dpc_flags
);
1646 if (ha
->retry_reset_ha_cnt
> 0) {
1647 /* Schedule another Reset HA--DPC will retry */
1648 ha
->retry_reset_ha_cnt
--;
1649 DEBUG2(printk("scsi%ld: recover adapter - "
1650 "retry remaining %d\n",
1652 ha
->retry_reset_ha_cnt
));
1656 if (ha
->retry_reset_ha_cnt
== 0) {
1657 /* Recover adapter retries have been exhausted.
1659 DEBUG2(printk("scsi%ld: recover adapter "
1660 "failed - board disabled\n",
1662 qla4xxx_dead_adapter_cleanup(ha
);
1663 clear_bit(DPC_RETRY_RESET_HA
, &ha
->dpc_flags
);
1664 clear_bit(DPC_RESET_HA
, &ha
->dpc_flags
);
1665 clear_bit(DPC_RESET_HA_FW_CONTEXT
,
1671 clear_bit(DPC_RESET_HA
, &ha
->dpc_flags
);
1672 clear_bit(DPC_RESET_HA_FW_CONTEXT
, &ha
->dpc_flags
);
1673 clear_bit(DPC_RETRY_RESET_HA
, &ha
->dpc_flags
);
1676 ha
->adapter_error_count
++;
1678 if (test_bit(AF_ONLINE
, &ha
->flags
))
1679 ha
->isp_ops
->enable_intrs(ha
);
1681 scsi_unblock_requests(ha
->host
);
1683 clear_bit(DPC_RESET_ACTIVE
, &ha
->dpc_flags
);
1684 DEBUG2(printk("scsi%ld: recover adapter: %s\n", ha
->host_no
,
1685 status
== QLA_ERROR
? "FAILED" : "SUCCEEDED"));
1690 static void qla4xxx_relogin_all_devices(struct scsi_qla_host
*ha
)
1692 struct ddb_entry
*ddb_entry
, *dtemp
;
1694 list_for_each_entry_safe(ddb_entry
, dtemp
, &ha
->ddb_list
, list
) {
1695 if ((atomic_read(&ddb_entry
->state
) == DDB_STATE_MISSING
) ||
1696 (atomic_read(&ddb_entry
->state
) == DDB_STATE_DEAD
)) {
1697 if (ddb_entry
->fw_ddb_device_state
==
1698 DDB_DS_SESSION_ACTIVE
) {
1699 atomic_set(&ddb_entry
->state
, DDB_STATE_ONLINE
);
1700 ql4_printk(KERN_INFO
, ha
, "scsi%ld: %s: ddb[%d]"
1701 " marked ONLINE\n", ha
->host_no
, __func__
,
1702 ddb_entry
->fw_ddb_index
);
1704 iscsi_unblock_session(ddb_entry
->sess
);
1706 qla4xxx_relogin_device(ha
, ddb_entry
);
1711 void qla4xxx_wake_dpc(struct scsi_qla_host
*ha
)
1714 queue_work(ha
->dpc_thread
, &ha
->dpc_work
);
1718 * qla4xxx_do_dpc - dpc routine
1719 * @data: in our case pointer to adapter structure
1721 * This routine is a task that is schedule by the interrupt handler
1722 * to perform the background processing for interrupts. We put it
1723 * on a task queue that is consumed whenever the scheduler runs; that's
1724 * so you can do anything (i.e. put the process to sleep etc). In fact,
1725 * the mid-level tries to sleep when it reaches the driver threshold
1726 * "host->can_queue". This can cause a panic if we were in our interrupt code.
1728 static void qla4xxx_do_dpc(struct work_struct
*work
)
1730 struct scsi_qla_host
*ha
=
1731 container_of(work
, struct scsi_qla_host
, dpc_work
);
1732 struct ddb_entry
*ddb_entry
, *dtemp
;
1733 int status
= QLA_ERROR
;
1735 DEBUG2(printk("scsi%ld: %s: DPC handler waking up."
1736 "flags = 0x%08lx, dpc_flags = 0x%08lx\n",
1737 ha
->host_no
, __func__
, ha
->flags
, ha
->dpc_flags
))
1739 /* Initialization not yet finished. Don't do anything yet. */
1740 if (!test_bit(AF_INIT_DONE
, &ha
->flags
))
1743 if (test_bit(AF_EEH_BUSY
, &ha
->flags
)) {
1744 DEBUG2(printk(KERN_INFO
"scsi%ld: %s: flags = %lx\n",
1745 ha
->host_no
, __func__
, ha
->flags
));
1749 if (is_qla8022(ha
)) {
1750 if (test_bit(DPC_HA_UNRECOVERABLE
, &ha
->dpc_flags
)) {
1751 qla4_8xxx_idc_lock(ha
);
1752 qla4_8xxx_wr_32(ha
, QLA82XX_CRB_DEV_STATE
,
1753 QLA82XX_DEV_FAILED
);
1754 qla4_8xxx_idc_unlock(ha
);
1755 ql4_printk(KERN_INFO
, ha
, "HW State: FAILED\n");
1756 qla4_8xxx_device_state_handler(ha
);
1758 if (test_and_clear_bit(DPC_HA_NEED_QUIESCENT
, &ha
->dpc_flags
)) {
1759 qla4_8xxx_need_qsnt_handler(ha
);
1763 if (!test_bit(DPC_RESET_ACTIVE
, &ha
->dpc_flags
) &&
1764 (test_bit(DPC_RESET_HA
, &ha
->dpc_flags
) ||
1765 test_bit(DPC_RESET_HA_INTR
, &ha
->dpc_flags
) ||
1766 test_bit(DPC_RESET_HA_FW_CONTEXT
, &ha
->dpc_flags
))) {
1767 if (ql4xdontresethba
) {
1768 DEBUG2(printk("scsi%ld: %s: Don't Reset HBA\n",
1769 ha
->host_no
, __func__
));
1770 clear_bit(DPC_RESET_HA
, &ha
->dpc_flags
);
1771 clear_bit(DPC_RESET_HA_INTR
, &ha
->dpc_flags
);
1772 clear_bit(DPC_RESET_HA_FW_CONTEXT
, &ha
->dpc_flags
);
1773 goto dpc_post_reset_ha
;
1775 if (test_bit(DPC_RESET_HA_FW_CONTEXT
, &ha
->dpc_flags
) ||
1776 test_bit(DPC_RESET_HA
, &ha
->dpc_flags
))
1777 qla4xxx_recover_adapter(ha
);
1779 if (test_bit(DPC_RESET_HA_INTR
, &ha
->dpc_flags
)) {
1780 uint8_t wait_time
= RESET_INTR_TOV
;
1782 while ((readw(&ha
->reg
->ctrl_status
) &
1783 (CSR_SOFT_RESET
| CSR_FORCE_SOFT_RESET
)) != 0) {
1784 if (--wait_time
== 0)
1789 DEBUG2(printk("scsi%ld: %s: SR|FSR "
1790 "bit not cleared-- resetting\n",
1791 ha
->host_no
, __func__
));
1792 qla4xxx_abort_active_cmds(ha
, DID_RESET
<< 16);
1793 if (ql4xxx_lock_drvr_wait(ha
) == QLA_SUCCESS
) {
1794 qla4xxx_process_aen(ha
, FLUSH_DDB_CHANGED_AENS
);
1795 status
= qla4xxx_recover_adapter(ha
);
1797 clear_bit(DPC_RESET_HA_INTR
, &ha
->dpc_flags
);
1798 if (status
== QLA_SUCCESS
)
1799 ha
->isp_ops
->enable_intrs(ha
);
1804 /* ---- process AEN? --- */
1805 if (test_and_clear_bit(DPC_AEN
, &ha
->dpc_flags
))
1806 qla4xxx_process_aen(ha
, PROCESS_ALL_AENS
);
1808 /* ---- Get DHCP IP Address? --- */
1809 if (test_and_clear_bit(DPC_GET_DHCP_IP_ADDR
, &ha
->dpc_flags
))
1810 qla4xxx_get_dhcp_ip_address(ha
);
1812 /* ---- link change? --- */
1813 if (test_and_clear_bit(DPC_LINK_CHANGED
, &ha
->dpc_flags
)) {
1814 if (!test_bit(AF_LINK_UP
, &ha
->flags
)) {
1815 /* ---- link down? --- */
1816 qla4xxx_mark_all_devices_missing(ha
);
1818 /* ---- link up? --- *
1819 * F/W will auto login to all devices ONLY ONCE after
1820 * link up during driver initialization and runtime
1821 * fatal error recovery. Therefore, the driver must
1822 * manually relogin to devices when recovering from
1823 * connection failures, logouts, expired KATO, etc. */
1825 qla4xxx_relogin_all_devices(ha
);
1829 /* ---- relogin device? --- */
1830 if (adapter_up(ha
) &&
1831 test_and_clear_bit(DPC_RELOGIN_DEVICE
, &ha
->dpc_flags
)) {
1832 list_for_each_entry_safe(ddb_entry
, dtemp
,
1833 &ha
->ddb_list
, list
) {
1834 if (test_and_clear_bit(DF_RELOGIN
, &ddb_entry
->flags
) &&
1835 atomic_read(&ddb_entry
->state
) != DDB_STATE_ONLINE
)
1836 qla4xxx_relogin_device(ha
, ddb_entry
);
1839 * If mbx cmd times out there is no point
1840 * in continuing further.
1841 * With large no of targets this can hang
1844 if (test_bit(DPC_RESET_HA
, &ha
->dpc_flags
)) {
1845 printk(KERN_WARNING
"scsi%ld: %s: "
1846 "need to reset hba\n",
1847 ha
->host_no
, __func__
);
1856 * qla4xxx_free_adapter - release the adapter
1857 * @ha: pointer to adapter structure
1859 static void qla4xxx_free_adapter(struct scsi_qla_host
*ha
)
1862 if (test_bit(AF_INTERRUPTS_ON
, &ha
->flags
)) {
1863 /* Turn-off interrupts on the card. */
1864 ha
->isp_ops
->disable_intrs(ha
);
1867 /* Remove timer thread, if present */
1868 if (ha
->timer_active
)
1869 qla4xxx_stop_timer(ha
);
1871 /* Kill the kernel thread for this host */
1873 destroy_workqueue(ha
->dpc_thread
);
1875 /* Put firmware in known state */
1876 ha
->isp_ops
->reset_firmware(ha
);
1878 if (is_qla8022(ha
)) {
1879 qla4_8xxx_idc_lock(ha
);
1880 qla4_8xxx_clear_drv_active(ha
);
1881 qla4_8xxx_idc_unlock(ha
);
1884 /* Detach interrupts */
1885 if (test_and_clear_bit(AF_IRQ_ATTACHED
, &ha
->flags
))
1886 qla4xxx_free_irqs(ha
);
1888 /* free extra memory */
1889 qla4xxx_mem_free(ha
);
1892 int qla4_8xxx_iospace_config(struct scsi_qla_host
*ha
)
1895 uint8_t revision_id
;
1896 unsigned long mem_base
, mem_len
, db_base
, db_len
;
1897 struct pci_dev
*pdev
= ha
->pdev
;
1899 status
= pci_request_regions(pdev
, DRIVER_NAME
);
1902 "scsi(%ld) Failed to reserve PIO regions (%s) "
1903 "status=%d\n", ha
->host_no
, pci_name(pdev
), status
);
1904 goto iospace_error_exit
;
1907 pci_read_config_byte(pdev
, PCI_REVISION_ID
, &revision_id
);
1908 DEBUG2(printk(KERN_INFO
"%s: revision-id=%d\n",
1909 __func__
, revision_id
));
1910 ha
->revision_id
= revision_id
;
1912 /* remap phys address */
1913 mem_base
= pci_resource_start(pdev
, 0); /* 0 is for BAR 0 */
1914 mem_len
= pci_resource_len(pdev
, 0);
1915 DEBUG2(printk(KERN_INFO
"%s: ioremap from %lx a size of %lx\n",
1916 __func__
, mem_base
, mem_len
));
1918 /* mapping of pcibase pointer */
1919 ha
->nx_pcibase
= (unsigned long)ioremap(mem_base
, mem_len
);
1920 if (!ha
->nx_pcibase
) {
1922 "cannot remap MMIO (%s), aborting\n", pci_name(pdev
));
1923 pci_release_regions(ha
->pdev
);
1924 goto iospace_error_exit
;
1927 /* Mapping of IO base pointer, door bell read and write pointer */
1929 /* mapping of IO base pointer */
1931 (struct device_reg_82xx __iomem
*)((uint8_t *)ha
->nx_pcibase
+
1932 0xbc000 + (ha
->pdev
->devfn
<< 11));
1934 db_base
= pci_resource_start(pdev
, 4); /* doorbell is on bar 4 */
1935 db_len
= pci_resource_len(pdev
, 4);
1937 ha
->nx_db_wr_ptr
= (ha
->pdev
->devfn
== 4 ? QLA82XX_CAM_RAM_DB1
:
1938 QLA82XX_CAM_RAM_DB2
);
1946 * qla4xxx_iospace_config - maps registers
1947 * @ha: pointer to adapter structure
1949 * This routines maps HBA's registers from the pci address space
1950 * into the kernel virtual address space for memory mapped i/o.
1952 int qla4xxx_iospace_config(struct scsi_qla_host
*ha
)
1954 unsigned long pio
, pio_len
, pio_flags
;
1955 unsigned long mmio
, mmio_len
, mmio_flags
;
1957 pio
= pci_resource_start(ha
->pdev
, 0);
1958 pio_len
= pci_resource_len(ha
->pdev
, 0);
1959 pio_flags
= pci_resource_flags(ha
->pdev
, 0);
1960 if (pio_flags
& IORESOURCE_IO
) {
1961 if (pio_len
< MIN_IOBASE_LEN
) {
1962 ql4_printk(KERN_WARNING
, ha
,
1963 "Invalid PCI I/O region size\n");
1967 ql4_printk(KERN_WARNING
, ha
, "region #0 not a PIO resource\n");
1971 /* Use MMIO operations for all accesses. */
1972 mmio
= pci_resource_start(ha
->pdev
, 1);
1973 mmio_len
= pci_resource_len(ha
->pdev
, 1);
1974 mmio_flags
= pci_resource_flags(ha
->pdev
, 1);
1976 if (!(mmio_flags
& IORESOURCE_MEM
)) {
1977 ql4_printk(KERN_ERR
, ha
,
1978 "region #0 not an MMIO resource, aborting\n");
1980 goto iospace_error_exit
;
1983 if (mmio_len
< MIN_IOBASE_LEN
) {
1984 ql4_printk(KERN_ERR
, ha
,
1985 "Invalid PCI mem region size, aborting\n");
1986 goto iospace_error_exit
;
1989 if (pci_request_regions(ha
->pdev
, DRIVER_NAME
)) {
1990 ql4_printk(KERN_WARNING
, ha
,
1991 "Failed to reserve PIO/MMIO regions\n");
1993 goto iospace_error_exit
;
1996 ha
->pio_address
= pio
;
1997 ha
->pio_length
= pio_len
;
1998 ha
->reg
= ioremap(mmio
, MIN_IOBASE_LEN
);
2000 ql4_printk(KERN_ERR
, ha
,
2001 "cannot remap MMIO, aborting\n");
2003 goto iospace_error_exit
;
2012 static struct isp_operations qla4xxx_isp_ops
= {
2013 .iospace_config
= qla4xxx_iospace_config
,
2014 .pci_config
= qla4xxx_pci_config
,
2015 .disable_intrs
= qla4xxx_disable_intrs
,
2016 .enable_intrs
= qla4xxx_enable_intrs
,
2017 .start_firmware
= qla4xxx_start_firmware
,
2018 .intr_handler
= qla4xxx_intr_handler
,
2019 .interrupt_service_routine
= qla4xxx_interrupt_service_routine
,
2020 .reset_chip
= qla4xxx_soft_reset
,
2021 .reset_firmware
= qla4xxx_hw_reset
,
2022 .queue_iocb
= qla4xxx_queue_iocb
,
2023 .complete_iocb
= qla4xxx_complete_iocb
,
2024 .rd_shdw_req_q_out
= qla4xxx_rd_shdw_req_q_out
,
2025 .rd_shdw_rsp_q_in
= qla4xxx_rd_shdw_rsp_q_in
,
2026 .get_sys_info
= qla4xxx_get_sys_info
,
2029 static struct isp_operations qla4_8xxx_isp_ops
= {
2030 .iospace_config
= qla4_8xxx_iospace_config
,
2031 .pci_config
= qla4_8xxx_pci_config
,
2032 .disable_intrs
= qla4_8xxx_disable_intrs
,
2033 .enable_intrs
= qla4_8xxx_enable_intrs
,
2034 .start_firmware
= qla4_8xxx_load_risc
,
2035 .intr_handler
= qla4_8xxx_intr_handler
,
2036 .interrupt_service_routine
= qla4_8xxx_interrupt_service_routine
,
2037 .reset_chip
= qla4_8xxx_isp_reset
,
2038 .reset_firmware
= qla4_8xxx_stop_firmware
,
2039 .queue_iocb
= qla4_8xxx_queue_iocb
,
2040 .complete_iocb
= qla4_8xxx_complete_iocb
,
2041 .rd_shdw_req_q_out
= qla4_8xxx_rd_shdw_req_q_out
,
2042 .rd_shdw_rsp_q_in
= qla4_8xxx_rd_shdw_rsp_q_in
,
2043 .get_sys_info
= qla4_8xxx_get_sys_info
,
2046 uint16_t qla4xxx_rd_shdw_req_q_out(struct scsi_qla_host
*ha
)
2048 return (uint16_t)le32_to_cpu(ha
->shadow_regs
->req_q_out
);
2051 uint16_t qla4_8xxx_rd_shdw_req_q_out(struct scsi_qla_host
*ha
)
2053 return (uint16_t)le32_to_cpu(readl(&ha
->qla4_8xxx_reg
->req_q_out
));
2056 uint16_t qla4xxx_rd_shdw_rsp_q_in(struct scsi_qla_host
*ha
)
2058 return (uint16_t)le32_to_cpu(ha
->shadow_regs
->rsp_q_in
);
2061 uint16_t qla4_8xxx_rd_shdw_rsp_q_in(struct scsi_qla_host
*ha
)
2063 return (uint16_t)le32_to_cpu(readl(&ha
->qla4_8xxx_reg
->rsp_q_in
));
2067 * qla4xxx_probe_adapter - callback function to probe HBA
2068 * @pdev: pointer to pci_dev structure
2069 * @pci_device_id: pointer to pci_device entry
2071 * This routine will probe for Qlogic 4xxx iSCSI host adapters.
2072 * It returns zero if successful. It also initializes all data necessary for
2075 static int __devinit
qla4xxx_probe_adapter(struct pci_dev
*pdev
,
2076 const struct pci_device_id
*ent
)
2078 int ret
= -ENODEV
, status
;
2079 struct Scsi_Host
*host
;
2080 struct scsi_qla_host
*ha
;
2081 uint8_t init_retry_count
= 0;
2083 struct qla4_8xxx_legacy_intr_set
*nx_legacy_intr
;
2086 if (pci_enable_device(pdev
))
2089 host
= scsi_host_alloc(&qla4xxx_driver_template
, sizeof(*ha
));
2092 "qla4xxx: Couldn't allocate host from scsi layer!\n");
2093 goto probe_disable_device
;
2096 /* Clear our data area */
2097 ha
= (struct scsi_qla_host
*) host
->hostdata
;
2098 memset(ha
, 0, sizeof(*ha
));
2100 /* Save the information from PCI BIOS. */
2103 ha
->host_no
= host
->host_no
;
2105 pci_enable_pcie_error_reporting(pdev
);
2107 /* Setup Runtime configurable options */
2108 if (is_qla8022(ha
)) {
2109 ha
->isp_ops
= &qla4_8xxx_isp_ops
;
2110 rwlock_init(&ha
->hw_lock
);
2111 ha
->qdr_sn_window
= -1;
2112 ha
->ddr_mn_window
= -1;
2113 ha
->curr_window
= 255;
2114 ha
->func_num
= PCI_FUNC(ha
->pdev
->devfn
);
2115 nx_legacy_intr
= &legacy_intr
[ha
->func_num
];
2116 ha
->nx_legacy_intr
.int_vec_bit
= nx_legacy_intr
->int_vec_bit
;
2117 ha
->nx_legacy_intr
.tgt_status_reg
=
2118 nx_legacy_intr
->tgt_status_reg
;
2119 ha
->nx_legacy_intr
.tgt_mask_reg
= nx_legacy_intr
->tgt_mask_reg
;
2120 ha
->nx_legacy_intr
.pci_int_reg
= nx_legacy_intr
->pci_int_reg
;
2122 ha
->isp_ops
= &qla4xxx_isp_ops
;
2125 /* Set EEH reset type to fundamental if required by hba */
2127 pdev
->needs_freset
= 1;
2129 /* Configure PCI I/O space. */
2130 ret
= ha
->isp_ops
->iospace_config(ha
);
2132 goto probe_failed_ioconfig
;
2134 ql4_printk(KERN_INFO
, ha
, "Found an ISP%04x, irq %d, iobase 0x%p\n",
2135 pdev
->device
, pdev
->irq
, ha
->reg
);
2137 qla4xxx_config_dma_addressing(ha
);
2139 /* Initialize lists and spinlocks. */
2140 INIT_LIST_HEAD(&ha
->ddb_list
);
2141 INIT_LIST_HEAD(&ha
->free_srb_q
);
2143 mutex_init(&ha
->mbox_sem
);
2144 init_completion(&ha
->mbx_intr_comp
);
2146 spin_lock_init(&ha
->hardware_lock
);
2148 /* Allocate dma buffers */
2149 if (qla4xxx_mem_alloc(ha
)) {
2150 ql4_printk(KERN_WARNING
, ha
,
2151 "[ERROR] Failed to allocate memory for adapter\n");
2158 (void) qla4_8xxx_get_flash_info(ha
);
2161 * Initialize the Host adapter request/response queues and
2163 * NOTE: interrupts enabled upon successful completion
2165 status
= qla4xxx_initialize_adapter(ha
, REBUILD_DDB_LIST
);
2166 while ((!test_bit(AF_ONLINE
, &ha
->flags
)) &&
2167 init_retry_count
++ < MAX_INIT_RETRIES
) {
2169 if (is_qla8022(ha
)) {
2170 qla4_8xxx_idc_lock(ha
);
2171 dev_state
= qla4_8xxx_rd_32(ha
, QLA82XX_CRB_DEV_STATE
);
2172 qla4_8xxx_idc_unlock(ha
);
2173 if (dev_state
== QLA82XX_DEV_FAILED
) {
2174 ql4_printk(KERN_WARNING
, ha
, "%s: don't retry "
2175 "initialize adapter. H/W is in failed state\n",
2180 DEBUG2(printk("scsi: %s: retrying adapter initialization "
2181 "(%d)\n", __func__
, init_retry_count
));
2183 if (ha
->isp_ops
->reset_chip(ha
) == QLA_ERROR
)
2186 status
= qla4xxx_initialize_adapter(ha
, REBUILD_DDB_LIST
);
2189 if (!test_bit(AF_ONLINE
, &ha
->flags
)) {
2190 ql4_printk(KERN_WARNING
, ha
, "Failed to initialize adapter\n");
2192 if (is_qla8022(ha
) && ql4xdontresethba
) {
2193 /* Put the device in failed state. */
2194 DEBUG2(printk(KERN_ERR
"HW STATE: FAILED\n"));
2195 qla4_8xxx_idc_lock(ha
);
2196 qla4_8xxx_wr_32(ha
, QLA82XX_CRB_DEV_STATE
,
2197 QLA82XX_DEV_FAILED
);
2198 qla4_8xxx_idc_unlock(ha
);
2204 host
->cmd_per_lun
= 3;
2205 host
->max_channel
= 0;
2206 host
->max_lun
= MAX_LUNS
- 1;
2207 host
->max_id
= MAX_TARGETS
;
2208 host
->max_cmd_len
= IOCB_MAX_CDB_LEN
;
2209 host
->can_queue
= MAX_SRBS
;
2210 host
->transportt
= qla4xxx_scsi_transport
;
2212 ret
= scsi_init_shared_tag_map(host
, MAX_SRBS
);
2214 ql4_printk(KERN_WARNING
, ha
,
2215 "scsi_init_shared_tag_map failed\n");
2219 /* Startup the kernel thread for this host adapter. */
2220 DEBUG2(printk("scsi: %s: Starting kernel thread for "
2221 "qla4xxx_dpc\n", __func__
));
2222 sprintf(buf
, "qla4xxx_%lu_dpc", ha
->host_no
);
2223 ha
->dpc_thread
= create_singlethread_workqueue(buf
);
2224 if (!ha
->dpc_thread
) {
2225 ql4_printk(KERN_WARNING
, ha
, "Unable to start DPC thread!\n");
2229 INIT_WORK(&ha
->dpc_work
, qla4xxx_do_dpc
);
2231 /* For ISP-82XX, request_irqs is called in qla4_8xxx_load_risc
2232 * (which is called indirectly by qla4xxx_initialize_adapter),
2233 * so that irqs will be registered after crbinit but before
2236 if (!is_qla8022(ha
)) {
2237 ret
= qla4xxx_request_irqs(ha
);
2239 ql4_printk(KERN_WARNING
, ha
, "Failed to reserve "
2240 "interrupt %d already in use.\n", pdev
->irq
);
2245 pci_save_state(ha
->pdev
);
2246 ha
->isp_ops
->enable_intrs(ha
);
2248 /* Start timer thread. */
2249 qla4xxx_start_timer(ha
, qla4xxx_timer
, 1);
2251 set_bit(AF_INIT_DONE
, &ha
->flags
);
2253 pci_set_drvdata(pdev
, ha
);
2255 ret
= scsi_add_host(host
, &pdev
->dev
);
2260 " QLogic iSCSI HBA Driver version: %s\n"
2261 " QLogic ISP%04x @ %s, host#=%ld, fw=%02d.%02d.%02d.%02d\n",
2262 qla4xxx_version_str
, ha
->pdev
->device
, pci_name(ha
->pdev
),
2263 ha
->host_no
, ha
->firmware_version
[0], ha
->firmware_version
[1],
2264 ha
->patch_number
, ha
->build_number
);
2265 scsi_scan_host(host
);
2267 qla4xxx_create_ifaces(ha
);
2271 qla4xxx_free_adapter(ha
);
2273 probe_failed_ioconfig
:
2274 pci_disable_pcie_error_reporting(pdev
);
2275 scsi_host_put(ha
->host
);
2277 probe_disable_device
:
2278 pci_disable_device(pdev
);
2284 * qla4xxx_prevent_other_port_reinit - prevent other port from re-initialize
2285 * @ha: pointer to adapter structure
2287 * Mark the other ISP-4xxx port to indicate that the driver is being removed,
2288 * so that the other port will not re-initialize while in the process of
2289 * removing the ha due to driver unload or hba hotplug.
2291 static void qla4xxx_prevent_other_port_reinit(struct scsi_qla_host
*ha
)
2293 struct scsi_qla_host
*other_ha
= NULL
;
2294 struct pci_dev
*other_pdev
= NULL
;
2295 int fn
= ISP4XXX_PCI_FN_2
;
2297 /*iscsi function numbers for ISP4xxx is 1 and 3*/
2298 if (PCI_FUNC(ha
->pdev
->devfn
) & BIT_1
)
2299 fn
= ISP4XXX_PCI_FN_1
;
2302 pci_get_domain_bus_and_slot(pci_domain_nr(ha
->pdev
->bus
),
2303 ha
->pdev
->bus
->number
, PCI_DEVFN(PCI_SLOT(ha
->pdev
->devfn
),
2306 /* Get other_ha if other_pdev is valid and state is enable*/
2308 if (atomic_read(&other_pdev
->enable_cnt
)) {
2309 other_ha
= pci_get_drvdata(other_pdev
);
2311 set_bit(AF_HA_REMOVAL
, &other_ha
->flags
);
2312 DEBUG2(ql4_printk(KERN_INFO
, ha
, "%s: "
2313 "Prevent %s reinit\n", __func__
,
2314 dev_name(&other_ha
->pdev
->dev
)));
2317 pci_dev_put(other_pdev
);
2322 * qla4xxx_remove_adapter - calback function to remove adapter.
2323 * @pci_dev: PCI device pointer
2325 static void __devexit
qla4xxx_remove_adapter(struct pci_dev
*pdev
)
2327 struct scsi_qla_host
*ha
;
2329 ha
= pci_get_drvdata(pdev
);
2331 if (!is_qla8022(ha
))
2332 qla4xxx_prevent_other_port_reinit(ha
);
2334 /* remove devs from iscsi_sessions to scsi_devices */
2335 qla4xxx_free_ddb_list(ha
);
2337 /* destroy iface from sysfs */
2338 qla4xxx_destroy_ifaces(ha
);
2340 scsi_remove_host(ha
->host
);
2342 qla4xxx_free_adapter(ha
);
2344 scsi_host_put(ha
->host
);
2346 pci_disable_pcie_error_reporting(pdev
);
2347 pci_disable_device(pdev
);
2348 pci_set_drvdata(pdev
, NULL
);
2352 * qla4xxx_config_dma_addressing() - Configure OS DMA addressing method.
2355 * At exit, the @ha's flags.enable_64bit_addressing set to indicated
2356 * supported addressing method.
2358 static void qla4xxx_config_dma_addressing(struct scsi_qla_host
*ha
)
2362 /* Update our PCI device dma_mask for full 64 bit mask */
2363 if (pci_set_dma_mask(ha
->pdev
, DMA_BIT_MASK(64)) == 0) {
2364 if (pci_set_consistent_dma_mask(ha
->pdev
, DMA_BIT_MASK(64))) {
2365 dev_dbg(&ha
->pdev
->dev
,
2366 "Failed to set 64 bit PCI consistent mask; "
2368 retval
= pci_set_consistent_dma_mask(ha
->pdev
,
2372 retval
= pci_set_dma_mask(ha
->pdev
, DMA_BIT_MASK(32));
2375 static int qla4xxx_slave_alloc(struct scsi_device
*sdev
)
2377 struct iscsi_cls_session
*sess
= starget_to_session(sdev
->sdev_target
);
2378 struct ddb_entry
*ddb
= sess
->dd_data
;
2379 int queue_depth
= QL4_DEF_QDEPTH
;
2381 sdev
->hostdata
= ddb
;
2382 sdev
->tagged_supported
= 1;
2384 if (ql4xmaxqdepth
!= 0 && ql4xmaxqdepth
<= 0xffffU
)
2385 queue_depth
= ql4xmaxqdepth
;
2387 scsi_activate_tcq(sdev
, queue_depth
);
2391 static int qla4xxx_slave_configure(struct scsi_device
*sdev
)
2393 sdev
->tagged_supported
= 1;
2397 static void qla4xxx_slave_destroy(struct scsi_device
*sdev
)
2399 scsi_deactivate_tcq(sdev
, 1);
2403 * qla4xxx_del_from_active_array - returns an active srb
2404 * @ha: Pointer to host adapter structure.
2405 * @index: index into the active_array
2407 * This routine removes and returns the srb at the specified index
2409 struct srb
*qla4xxx_del_from_active_array(struct scsi_qla_host
*ha
,
2412 struct srb
*srb
= NULL
;
2413 struct scsi_cmnd
*cmd
= NULL
;
2415 cmd
= scsi_host_find_tag(ha
->host
, index
);
2419 srb
= (struct srb
*)CMD_SP(cmd
);
2423 /* update counters */
2424 if (srb
->flags
& SRB_DMA_VALID
) {
2425 ha
->req_q_count
+= srb
->iocb_cnt
;
2426 ha
->iocb_cnt
-= srb
->iocb_cnt
;
2428 srb
->cmd
->host_scribble
=
2429 (unsigned char *)(unsigned long) MAX_SRBS
;
2435 * qla4xxx_eh_wait_on_command - waits for command to be returned by firmware
2436 * @ha: Pointer to host adapter structure.
2437 * @cmd: Scsi Command to wait on.
2439 * This routine waits for the command to be returned by the Firmware
2440 * for some max time.
2442 static int qla4xxx_eh_wait_on_command(struct scsi_qla_host
*ha
,
2443 struct scsi_cmnd
*cmd
)
2447 uint32_t max_wait_time
= EH_WAIT_CMD_TOV
;
2450 /* Dont wait on command if PCI error is being handled
2453 if (unlikely(pci_channel_offline(ha
->pdev
)) ||
2454 (test_bit(AF_EEH_BUSY
, &ha
->flags
))) {
2455 ql4_printk(KERN_WARNING
, ha
, "scsi%ld: Return from %s\n",
2456 ha
->host_no
, __func__
);
2461 /* Checking to see if its returned to OS */
2462 rp
= (struct srb
*) CMD_SP(cmd
);
2469 } while (max_wait_time
--);
2475 * qla4xxx_wait_for_hba_online - waits for HBA to come online
2476 * @ha: Pointer to host adapter structure
2478 static int qla4xxx_wait_for_hba_online(struct scsi_qla_host
*ha
)
2480 unsigned long wait_online
;
2482 wait_online
= jiffies
+ (HBA_ONLINE_TOV
* HZ
);
2483 while (time_before(jiffies
, wait_online
)) {
2495 * qla4xxx_eh_wait_for_commands - wait for active cmds to finish.
2496 * @ha: pointer to HBA
2500 * This function waits for all outstanding commands to a lun to complete. It
2501 * returns 0 if all pending commands are returned and 1 otherwise.
2503 static int qla4xxx_eh_wait_for_commands(struct scsi_qla_host
*ha
,
2504 struct scsi_target
*stgt
,
2505 struct scsi_device
*sdev
)
2509 struct scsi_cmnd
*cmd
;
2512 * Waiting for all commands for the designated target or dev
2513 * in the active array
2515 for (cnt
= 0; cnt
< ha
->host
->can_queue
; cnt
++) {
2516 cmd
= scsi_host_find_tag(ha
->host
, cnt
);
2517 if (cmd
&& stgt
== scsi_target(cmd
->device
) &&
2518 (!sdev
|| sdev
== cmd
->device
)) {
2519 if (!qla4xxx_eh_wait_on_command(ha
, cmd
)) {
2529 * qla4xxx_eh_abort - callback for abort task.
2530 * @cmd: Pointer to Linux's SCSI command structure
2532 * This routine is called by the Linux OS to abort the specified
2535 static int qla4xxx_eh_abort(struct scsi_cmnd
*cmd
)
2537 struct scsi_qla_host
*ha
= to_qla_host(cmd
->device
->host
);
2538 unsigned int id
= cmd
->device
->id
;
2539 unsigned int lun
= cmd
->device
->lun
;
2540 unsigned long flags
;
2541 struct srb
*srb
= NULL
;
2545 ql4_printk(KERN_INFO
, ha
,
2546 "scsi%ld:%d:%d: Abort command issued cmd=%p\n",
2547 ha
->host_no
, id
, lun
, cmd
);
2549 spin_lock_irqsave(&ha
->hardware_lock
, flags
);
2550 srb
= (struct srb
*) CMD_SP(cmd
);
2552 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
2555 kref_get(&srb
->srb_ref
);
2556 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
2558 if (qla4xxx_abort_task(ha
, srb
) != QLA_SUCCESS
) {
2559 DEBUG3(printk("scsi%ld:%d:%d: Abort_task mbx failed.\n",
2560 ha
->host_no
, id
, lun
));
2563 DEBUG3(printk("scsi%ld:%d:%d: Abort_task mbx success.\n",
2564 ha
->host_no
, id
, lun
));
2568 kref_put(&srb
->srb_ref
, qla4xxx_srb_compl
);
2570 /* Wait for command to complete */
2572 if (!qla4xxx_eh_wait_on_command(ha
, cmd
)) {
2573 DEBUG2(printk("scsi%ld:%d:%d: Abort handler timed out\n",
2574 ha
->host_no
, id
, lun
));
2579 ql4_printk(KERN_INFO
, ha
,
2580 "scsi%ld:%d:%d: Abort command - %s\n",
2581 ha
->host_no
, id
, lun
, (ret
== SUCCESS
) ? "succeeded" : "failed");
2587 * qla4xxx_eh_device_reset - callback for target reset.
2588 * @cmd: Pointer to Linux's SCSI command structure
2590 * This routine is called by the Linux OS to reset all luns on the
2593 static int qla4xxx_eh_device_reset(struct scsi_cmnd
*cmd
)
2595 struct scsi_qla_host
*ha
= to_qla_host(cmd
->device
->host
);
2596 struct ddb_entry
*ddb_entry
= cmd
->device
->hostdata
;
2597 int ret
= FAILED
, stat
;
2602 ret
= iscsi_block_scsi_eh(cmd
);
2607 ql4_printk(KERN_INFO
, ha
,
2608 "scsi%ld:%d:%d:%d: DEVICE RESET ISSUED.\n", ha
->host_no
,
2609 cmd
->device
->channel
, cmd
->device
->id
, cmd
->device
->lun
);
2611 DEBUG2(printk(KERN_INFO
2612 "scsi%ld: DEVICE_RESET cmd=%p jiffies = 0x%lx, to=%x,"
2613 "dpc_flags=%lx, status=%x allowed=%d\n", ha
->host_no
,
2614 cmd
, jiffies
, cmd
->request
->timeout
/ HZ
,
2615 ha
->dpc_flags
, cmd
->result
, cmd
->allowed
));
2617 /* FIXME: wait for hba to go online */
2618 stat
= qla4xxx_reset_lun(ha
, ddb_entry
, cmd
->device
->lun
);
2619 if (stat
!= QLA_SUCCESS
) {
2620 ql4_printk(KERN_INFO
, ha
, "DEVICE RESET FAILED. %d\n", stat
);
2621 goto eh_dev_reset_done
;
2624 if (qla4xxx_eh_wait_for_commands(ha
, scsi_target(cmd
->device
),
2626 ql4_printk(KERN_INFO
, ha
,
2627 "DEVICE RESET FAILED - waiting for "
2629 goto eh_dev_reset_done
;
2633 if (qla4xxx_send_marker_iocb(ha
, ddb_entry
, cmd
->device
->lun
,
2634 MM_LUN_RESET
) != QLA_SUCCESS
)
2635 goto eh_dev_reset_done
;
2637 ql4_printk(KERN_INFO
, ha
,
2638 "scsi(%ld:%d:%d:%d): DEVICE RESET SUCCEEDED.\n",
2639 ha
->host_no
, cmd
->device
->channel
, cmd
->device
->id
,
2650 * qla4xxx_eh_target_reset - callback for target reset.
2651 * @cmd: Pointer to Linux's SCSI command structure
2653 * This routine is called by the Linux OS to reset the target.
2655 static int qla4xxx_eh_target_reset(struct scsi_cmnd
*cmd
)
2657 struct scsi_qla_host
*ha
= to_qla_host(cmd
->device
->host
);
2658 struct ddb_entry
*ddb_entry
= cmd
->device
->hostdata
;
2664 ret
= iscsi_block_scsi_eh(cmd
);
2668 starget_printk(KERN_INFO
, scsi_target(cmd
->device
),
2669 "WARM TARGET RESET ISSUED.\n");
2671 DEBUG2(printk(KERN_INFO
2672 "scsi%ld: TARGET_DEVICE_RESET cmd=%p jiffies = 0x%lx, "
2673 "to=%x,dpc_flags=%lx, status=%x allowed=%d\n",
2674 ha
->host_no
, cmd
, jiffies
, cmd
->request
->timeout
/ HZ
,
2675 ha
->dpc_flags
, cmd
->result
, cmd
->allowed
));
2677 stat
= qla4xxx_reset_target(ha
, ddb_entry
);
2678 if (stat
!= QLA_SUCCESS
) {
2679 starget_printk(KERN_INFO
, scsi_target(cmd
->device
),
2680 "WARM TARGET RESET FAILED.\n");
2684 if (qla4xxx_eh_wait_for_commands(ha
, scsi_target(cmd
->device
),
2686 starget_printk(KERN_INFO
, scsi_target(cmd
->device
),
2687 "WARM TARGET DEVICE RESET FAILED - "
2688 "waiting for commands.\n");
2693 if (qla4xxx_send_marker_iocb(ha
, ddb_entry
, cmd
->device
->lun
,
2694 MM_TGT_WARM_RESET
) != QLA_SUCCESS
) {
2695 starget_printk(KERN_INFO
, scsi_target(cmd
->device
),
2696 "WARM TARGET DEVICE RESET FAILED - "
2697 "marker iocb failed.\n");
2701 starget_printk(KERN_INFO
, scsi_target(cmd
->device
),
2702 "WARM TARGET RESET SUCCEEDED.\n");
2707 * qla4xxx_eh_host_reset - kernel callback
2708 * @cmd: Pointer to Linux's SCSI command structure
2710 * This routine is invoked by the Linux kernel to perform fatal error
2711 * recovery on the specified adapter.
2713 static int qla4xxx_eh_host_reset(struct scsi_cmnd
*cmd
)
2715 int return_status
= FAILED
;
2716 struct scsi_qla_host
*ha
;
2718 ha
= (struct scsi_qla_host
*) cmd
->device
->host
->hostdata
;
2720 if (ql4xdontresethba
) {
2721 DEBUG2(printk("scsi%ld: %s: Don't Reset HBA\n",
2722 ha
->host_no
, __func__
));
2726 ql4_printk(KERN_INFO
, ha
,
2727 "scsi(%ld:%d:%d:%d): HOST RESET ISSUED.\n", ha
->host_no
,
2728 cmd
->device
->channel
, cmd
->device
->id
, cmd
->device
->lun
);
2730 if (qla4xxx_wait_for_hba_online(ha
) != QLA_SUCCESS
) {
2731 DEBUG2(printk("scsi%ld:%d: %s: Unable to reset host. Adapter "
2732 "DEAD.\n", ha
->host_no
, cmd
->device
->channel
,
2738 if (!test_bit(DPC_RESET_HA
, &ha
->dpc_flags
)) {
2740 set_bit(DPC_RESET_HA_FW_CONTEXT
, &ha
->dpc_flags
);
2742 set_bit(DPC_RESET_HA
, &ha
->dpc_flags
);
2745 if (qla4xxx_recover_adapter(ha
) == QLA_SUCCESS
)
2746 return_status
= SUCCESS
;
2748 ql4_printk(KERN_INFO
, ha
, "HOST RESET %s.\n",
2749 return_status
== FAILED
? "FAILED" : "SUCCEEDED");
2751 return return_status
;
2754 /* PCI AER driver recovers from all correctable errors w/o
2755 * driver intervention. For uncorrectable errors PCI AER
2756 * driver calls the following device driver's callbacks
2758 * - Fatal Errors - link_reset
2759 * - Non-Fatal Errors - driver's pci_error_detected() which
2760 * returns CAN_RECOVER, NEED_RESET or DISCONNECT.
2762 * PCI AER driver calls
2763 * CAN_RECOVER - driver's pci_mmio_enabled(), mmio_enabled
2764 * returns RECOVERED or NEED_RESET if fw_hung
2765 * NEED_RESET - driver's slot_reset()
2766 * DISCONNECT - device is dead & cannot recover
2767 * RECOVERED - driver's pci_resume()
2769 static pci_ers_result_t
2770 qla4xxx_pci_error_detected(struct pci_dev
*pdev
, pci_channel_state_t state
)
2772 struct scsi_qla_host
*ha
= pci_get_drvdata(pdev
);
2774 ql4_printk(KERN_WARNING
, ha
, "scsi%ld: %s: error detected:state %x\n",
2775 ha
->host_no
, __func__
, state
);
2777 if (!is_aer_supported(ha
))
2778 return PCI_ERS_RESULT_NONE
;
2781 case pci_channel_io_normal
:
2782 clear_bit(AF_EEH_BUSY
, &ha
->flags
);
2783 return PCI_ERS_RESULT_CAN_RECOVER
;
2784 case pci_channel_io_frozen
:
2785 set_bit(AF_EEH_BUSY
, &ha
->flags
);
2786 qla4xxx_mailbox_premature_completion(ha
);
2787 qla4xxx_free_irqs(ha
);
2788 pci_disable_device(pdev
);
2789 /* Return back all IOs */
2790 qla4xxx_abort_active_cmds(ha
, DID_RESET
<< 16);
2791 return PCI_ERS_RESULT_NEED_RESET
;
2792 case pci_channel_io_perm_failure
:
2793 set_bit(AF_EEH_BUSY
, &ha
->flags
);
2794 set_bit(AF_PCI_CHANNEL_IO_PERM_FAILURE
, &ha
->flags
);
2795 qla4xxx_abort_active_cmds(ha
, DID_NO_CONNECT
<< 16);
2796 return PCI_ERS_RESULT_DISCONNECT
;
2798 return PCI_ERS_RESULT_NEED_RESET
;
2802 * qla4xxx_pci_mmio_enabled() gets called if
2803 * qla4xxx_pci_error_detected() returns PCI_ERS_RESULT_CAN_RECOVER
2804 * and read/write to the device still works.
2806 static pci_ers_result_t
2807 qla4xxx_pci_mmio_enabled(struct pci_dev
*pdev
)
2809 struct scsi_qla_host
*ha
= pci_get_drvdata(pdev
);
2811 if (!is_aer_supported(ha
))
2812 return PCI_ERS_RESULT_NONE
;
2814 return PCI_ERS_RESULT_RECOVERED
;
2817 static uint32_t qla4_8xxx_error_recovery(struct scsi_qla_host
*ha
)
2819 uint32_t rval
= QLA_ERROR
;
2822 struct pci_dev
*other_pdev
= NULL
;
2824 ql4_printk(KERN_WARNING
, ha
, "scsi%ld: In %s\n", ha
->host_no
, __func__
);
2826 set_bit(DPC_RESET_ACTIVE
, &ha
->dpc_flags
);
2828 if (test_bit(AF_ONLINE
, &ha
->flags
)) {
2829 clear_bit(AF_ONLINE
, &ha
->flags
);
2830 qla4xxx_mark_all_devices_missing(ha
);
2831 qla4xxx_process_aen(ha
, FLUSH_DDB_CHANGED_AENS
);
2834 fn
= PCI_FUNC(ha
->pdev
->devfn
);
2837 ql4_printk(KERN_INFO
, ha
, "scsi%ld: %s: Finding PCI device at "
2838 "func %x\n", ha
->host_no
, __func__
, fn
);
2839 /* Get the pci device given the domain, bus,
2840 * slot/function number */
2842 pci_get_domain_bus_and_slot(pci_domain_nr(ha
->pdev
->bus
),
2843 ha
->pdev
->bus
->number
, PCI_DEVFN(PCI_SLOT(ha
->pdev
->devfn
),
2849 if (atomic_read(&other_pdev
->enable_cnt
)) {
2850 ql4_printk(KERN_INFO
, ha
, "scsi%ld: %s: Found PCI "
2851 "func in enabled state%x\n", ha
->host_no
,
2853 pci_dev_put(other_pdev
);
2856 pci_dev_put(other_pdev
);
2859 /* The first function on the card, the reset owner will
2860 * start & initialize the firmware. The other functions
2861 * on the card will reset the firmware context
2864 ql4_printk(KERN_INFO
, ha
, "scsi%ld: %s: devfn being reset "
2865 "0x%x is the owner\n", ha
->host_no
, __func__
,
2868 qla4_8xxx_idc_lock(ha
);
2869 qla4_8xxx_wr_32(ha
, QLA82XX_CRB_DEV_STATE
,
2872 qla4_8xxx_wr_32(ha
, QLA82XX_CRB_DRV_IDC_VERSION
,
2873 QLA82XX_IDC_VERSION
);
2875 qla4_8xxx_idc_unlock(ha
);
2876 clear_bit(AF_FW_RECOVERY
, &ha
->flags
);
2877 rval
= qla4xxx_initialize_adapter(ha
, PRESERVE_DDB_LIST
);
2878 qla4_8xxx_idc_lock(ha
);
2880 if (rval
!= QLA_SUCCESS
) {
2881 ql4_printk(KERN_INFO
, ha
, "scsi%ld: %s: HW State: "
2882 "FAILED\n", ha
->host_no
, __func__
);
2883 qla4_8xxx_clear_drv_active(ha
);
2884 qla4_8xxx_wr_32(ha
, QLA82XX_CRB_DEV_STATE
,
2885 QLA82XX_DEV_FAILED
);
2887 ql4_printk(KERN_INFO
, ha
, "scsi%ld: %s: HW State: "
2888 "READY\n", ha
->host_no
, __func__
);
2889 qla4_8xxx_wr_32(ha
, QLA82XX_CRB_DEV_STATE
,
2891 /* Clear driver state register */
2892 qla4_8xxx_wr_32(ha
, QLA82XX_CRB_DRV_STATE
, 0);
2893 qla4_8xxx_set_drv_active(ha
);
2894 ret
= qla4xxx_request_irqs(ha
);
2896 ql4_printk(KERN_WARNING
, ha
, "Failed to "
2897 "reserve interrupt %d already in use.\n",
2901 ha
->isp_ops
->enable_intrs(ha
);
2905 qla4_8xxx_idc_unlock(ha
);
2907 ql4_printk(KERN_INFO
, ha
, "scsi%ld: %s: devfn 0x%x is not "
2908 "the reset owner\n", ha
->host_no
, __func__
,
2910 if ((qla4_8xxx_rd_32(ha
, QLA82XX_CRB_DEV_STATE
) ==
2911 QLA82XX_DEV_READY
)) {
2912 clear_bit(AF_FW_RECOVERY
, &ha
->flags
);
2913 rval
= qla4xxx_initialize_adapter(ha
,
2915 if (rval
== QLA_SUCCESS
) {
2916 ret
= qla4xxx_request_irqs(ha
);
2918 ql4_printk(KERN_WARNING
, ha
, "Failed to"
2919 " reserve interrupt %d already in"
2920 " use.\n", ha
->pdev
->irq
);
2923 ha
->isp_ops
->enable_intrs(ha
);
2927 qla4_8xxx_idc_lock(ha
);
2928 qla4_8xxx_set_drv_active(ha
);
2929 qla4_8xxx_idc_unlock(ha
);
2932 clear_bit(DPC_RESET_ACTIVE
, &ha
->dpc_flags
);
2936 static pci_ers_result_t
2937 qla4xxx_pci_slot_reset(struct pci_dev
*pdev
)
2939 pci_ers_result_t ret
= PCI_ERS_RESULT_DISCONNECT
;
2940 struct scsi_qla_host
*ha
= pci_get_drvdata(pdev
);
2943 ql4_printk(KERN_WARNING
, ha
, "scsi%ld: %s: slot_reset\n",
2944 ha
->host_no
, __func__
);
2946 if (!is_aer_supported(ha
))
2947 return PCI_ERS_RESULT_NONE
;
2949 /* Restore the saved state of PCIe device -
2950 * BAR registers, PCI Config space, PCIX, MSI,
2953 pci_restore_state(pdev
);
2955 /* pci_restore_state() clears the saved_state flag of the device
2956 * save restored state which resets saved_state flag
2958 pci_save_state(pdev
);
2960 /* Initialize device or resume if in suspended state */
2961 rc
= pci_enable_device(pdev
);
2963 ql4_printk(KERN_WARNING
, ha
, "scsi%ld: %s: Can't re-enable "
2964 "device after reset\n", ha
->host_no
, __func__
);
2965 goto exit_slot_reset
;
2968 ha
->isp_ops
->disable_intrs(ha
);
2970 if (is_qla8022(ha
)) {
2971 if (qla4_8xxx_error_recovery(ha
) == QLA_SUCCESS
) {
2972 ret
= PCI_ERS_RESULT_RECOVERED
;
2973 goto exit_slot_reset
;
2975 goto exit_slot_reset
;
2979 ql4_printk(KERN_WARNING
, ha
, "scsi%ld: %s: Return=%x\n"
2980 "device after reset\n", ha
->host_no
, __func__
, ret
);
2985 qla4xxx_pci_resume(struct pci_dev
*pdev
)
2987 struct scsi_qla_host
*ha
= pci_get_drvdata(pdev
);
2990 ql4_printk(KERN_WARNING
, ha
, "scsi%ld: %s: pci_resume\n",
2991 ha
->host_no
, __func__
);
2993 ret
= qla4xxx_wait_for_hba_online(ha
);
2994 if (ret
!= QLA_SUCCESS
) {
2995 ql4_printk(KERN_ERR
, ha
, "scsi%ld: %s: the device failed to "
2996 "resume I/O from slot/link_reset\n", ha
->host_no
,
3000 pci_cleanup_aer_uncorrect_error_status(pdev
);
3001 clear_bit(AF_EEH_BUSY
, &ha
->flags
);
3004 static struct pci_error_handlers qla4xxx_err_handler
= {
3005 .error_detected
= qla4xxx_pci_error_detected
,
3006 .mmio_enabled
= qla4xxx_pci_mmio_enabled
,
3007 .slot_reset
= qla4xxx_pci_slot_reset
,
3008 .resume
= qla4xxx_pci_resume
,
3011 static struct pci_device_id qla4xxx_pci_tbl
[] = {
3013 .vendor
= PCI_VENDOR_ID_QLOGIC
,
3014 .device
= PCI_DEVICE_ID_QLOGIC_ISP4010
,
3015 .subvendor
= PCI_ANY_ID
,
3016 .subdevice
= PCI_ANY_ID
,
3019 .vendor
= PCI_VENDOR_ID_QLOGIC
,
3020 .device
= PCI_DEVICE_ID_QLOGIC_ISP4022
,
3021 .subvendor
= PCI_ANY_ID
,
3022 .subdevice
= PCI_ANY_ID
,
3025 .vendor
= PCI_VENDOR_ID_QLOGIC
,
3026 .device
= PCI_DEVICE_ID_QLOGIC_ISP4032
,
3027 .subvendor
= PCI_ANY_ID
,
3028 .subdevice
= PCI_ANY_ID
,
3031 .vendor
= PCI_VENDOR_ID_QLOGIC
,
3032 .device
= PCI_DEVICE_ID_QLOGIC_ISP8022
,
3033 .subvendor
= PCI_ANY_ID
,
3034 .subdevice
= PCI_ANY_ID
,
3038 MODULE_DEVICE_TABLE(pci
, qla4xxx_pci_tbl
);
3040 static struct pci_driver qla4xxx_pci_driver
= {
3041 .name
= DRIVER_NAME
,
3042 .id_table
= qla4xxx_pci_tbl
,
3043 .probe
= qla4xxx_probe_adapter
,
3044 .remove
= qla4xxx_remove_adapter
,
3045 .err_handler
= &qla4xxx_err_handler
,
3048 static int __init
qla4xxx_module_init(void)
3052 /* Allocate cache for SRBs. */
3053 srb_cachep
= kmem_cache_create("qla4xxx_srbs", sizeof(struct srb
), 0,
3054 SLAB_HWCACHE_ALIGN
, NULL
);
3055 if (srb_cachep
== NULL
) {
3057 "%s: Unable to allocate SRB cache..."
3058 "Failing load!\n", DRIVER_NAME
);
3063 /* Derive version string. */
3064 strcpy(qla4xxx_version_str
, QLA4XXX_DRIVER_VERSION
);
3065 if (ql4xextended_error_logging
)
3066 strcat(qla4xxx_version_str
, "-debug");
3068 qla4xxx_scsi_transport
=
3069 iscsi_register_transport(&qla4xxx_iscsi_transport
);
3070 if (!qla4xxx_scsi_transport
){
3072 goto release_srb_cache
;
3075 ret
= pci_register_driver(&qla4xxx_pci_driver
);
3077 goto unregister_transport
;
3079 printk(KERN_INFO
"QLogic iSCSI HBA Driver\n");
3082 unregister_transport
:
3083 iscsi_unregister_transport(&qla4xxx_iscsi_transport
);
3085 kmem_cache_destroy(srb_cachep
);
3090 static void __exit
qla4xxx_module_exit(void)
3092 pci_unregister_driver(&qla4xxx_pci_driver
);
3093 iscsi_unregister_transport(&qla4xxx_iscsi_transport
);
3094 kmem_cache_destroy(srb_cachep
);
3097 module_init(qla4xxx_module_init
);
3098 module_exit(qla4xxx_module_exit
);
3100 MODULE_AUTHOR("QLogic Corporation");
3101 MODULE_DESCRIPTION("QLogic iSCSI HBA Driver");
3102 MODULE_LICENSE("GPL");
3103 MODULE_VERSION(QLA4XXX_DRIVER_VERSION
);