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>
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"
25 static char qla4xxx_version_str[40];
28 * SRB allocation cache
30 static struct kmem_cache *srb_cachep;
33 * Module parameter information and variables
35 static int ql4xdisablesysfsboot = 1;
36 module_param(ql4xdisablesysfsboot, int, S_IRUGO | S_IWUSR);
37 MODULE_PARM_DESC(ql4xdisablesysfsboot,
38 " Set to disable exporting boot targets to sysfs.\n"
39 "\t\t 0 - Export boot targets\n"
40 "\t\t 1 - Do not export boot targets (Default)");
43 module_param(ql4xdontresethba, int, S_IRUGO | S_IWUSR);
44 MODULE_PARM_DESC(ql4xdontresethba,
45 " Don't reset the HBA for driver recovery.\n"
46 "\t\t 0 - It will reset HBA (Default)\n"
47 "\t\t 1 - It will NOT reset HBA");
49 int ql4xextended_error_logging;
50 module_param(ql4xextended_error_logging, int, S_IRUGO | S_IWUSR);
51 MODULE_PARM_DESC(ql4xextended_error_logging,
52 " Option to enable extended error logging.\n"
53 "\t\t 0 - no logging (Default)\n"
54 "\t\t 2 - debug logging");
56 int ql4xenablemsix = 1;
57 module_param(ql4xenablemsix, int, S_IRUGO|S_IWUSR);
58 MODULE_PARM_DESC(ql4xenablemsix,
59 " Set to enable MSI or MSI-X interrupt mechanism.\n"
60 "\t\t 0 = enable INTx interrupt mechanism.\n"
61 "\t\t 1 = enable MSI-X interrupt mechanism (Default).\n"
62 "\t\t 2 = enable MSI interrupt mechanism.");
64 #define QL4_DEF_QDEPTH 32
65 static int ql4xmaxqdepth = QL4_DEF_QDEPTH;
66 module_param(ql4xmaxqdepth, int, S_IRUGO | S_IWUSR);
67 MODULE_PARM_DESC(ql4xmaxqdepth,
68 " Maximum queue depth to report for target devices.\n"
71 static int ql4xsess_recovery_tmo = QL4_SESS_RECOVERY_TMO;
72 module_param(ql4xsess_recovery_tmo, int, S_IRUGO);
73 MODULE_PARM_DESC(ql4xsess_recovery_tmo,
74 " Target Session Recovery Timeout.\n"
75 "\t\t Default: 120 sec.");
77 static int qla4xxx_wait_for_hba_online(struct scsi_qla_host *ha);
79 * SCSI host template entry points
81 static void qla4xxx_config_dma_addressing(struct scsi_qla_host *ha);
84 * iSCSI template entry points
86 static int qla4xxx_session_get_param(struct iscsi_cls_session *cls_sess,
87 enum iscsi_param param, char *buf);
88 static int qla4xxx_conn_get_param(struct iscsi_cls_conn *conn,
89 enum iscsi_param param, char *buf);
90 static int qla4xxx_host_get_param(struct Scsi_Host *shost,
91 enum iscsi_host_param param, char *buf);
92 static int qla4xxx_iface_set_param(struct Scsi_Host *shost, void *data,
94 static int qla4xxx_get_iface_param(struct iscsi_iface *iface,
95 enum iscsi_param_type param_type,
96 int param, char *buf);
97 static enum blk_eh_timer_return qla4xxx_eh_cmd_timed_out(struct scsi_cmnd *sc);
98 static struct iscsi_endpoint *qla4xxx_ep_connect(struct Scsi_Host *shost,
99 struct sockaddr *dst_addr,
101 static int qla4xxx_ep_poll(struct iscsi_endpoint *ep, int timeout_ms);
102 static void qla4xxx_ep_disconnect(struct iscsi_endpoint *ep);
103 static int qla4xxx_get_ep_param(struct iscsi_endpoint *ep,
104 enum iscsi_param param, char *buf);
105 static int qla4xxx_conn_start(struct iscsi_cls_conn *conn);
106 static struct iscsi_cls_conn *
107 qla4xxx_conn_create(struct iscsi_cls_session *cls_sess, uint32_t conn_idx);
108 static int qla4xxx_conn_bind(struct iscsi_cls_session *cls_session,
109 struct iscsi_cls_conn *cls_conn,
110 uint64_t transport_fd, int is_leading);
111 static void qla4xxx_conn_destroy(struct iscsi_cls_conn *conn);
112 static struct iscsi_cls_session *
113 qla4xxx_session_create(struct iscsi_endpoint *ep, uint16_t cmds_max,
114 uint16_t qdepth, uint32_t initial_cmdsn);
115 static void qla4xxx_session_destroy(struct iscsi_cls_session *sess);
116 static void qla4xxx_task_work(struct work_struct *wdata);
117 static int qla4xxx_alloc_pdu(struct iscsi_task *, uint8_t);
118 static int qla4xxx_task_xmit(struct iscsi_task *);
119 static void qla4xxx_task_cleanup(struct iscsi_task *);
120 static void qla4xxx_fail_session(struct iscsi_cls_session *cls_session);
121 static void qla4xxx_conn_get_stats(struct iscsi_cls_conn *cls_conn,
122 struct iscsi_stats *stats);
123 static int qla4xxx_send_ping(struct Scsi_Host *shost, uint32_t iface_num,
124 uint32_t iface_type, uint32_t payload_size,
125 uint32_t pid, struct sockaddr *dst_addr);
126 static int qla4xxx_get_chap_list(struct Scsi_Host *shost, uint16_t chap_tbl_idx,
127 uint32_t *num_entries, char *buf);
128 static int qla4xxx_delete_chap(struct Scsi_Host *shost, uint16_t chap_tbl_idx);
131 * SCSI host template entry points
133 static int qla4xxx_queuecommand(struct Scsi_Host *h, struct scsi_cmnd *cmd);
134 static int qla4xxx_eh_abort(struct scsi_cmnd *cmd);
135 static int qla4xxx_eh_device_reset(struct scsi_cmnd *cmd);
136 static int qla4xxx_eh_target_reset(struct scsi_cmnd *cmd);
137 static int qla4xxx_eh_host_reset(struct scsi_cmnd *cmd);
138 static int qla4xxx_slave_alloc(struct scsi_device *device);
139 static int qla4xxx_slave_configure(struct scsi_device *device);
140 static void qla4xxx_slave_destroy(struct scsi_device *sdev);
141 static umode_t ql4_attr_is_visible(int param_type, int param);
142 static int qla4xxx_host_reset(struct Scsi_Host *shost, int reset_type);
144 static struct qla4_8xxx_legacy_intr_set legacy_intr[] =
145 QLA82XX_LEGACY_INTR_CONFIG;
147 static struct scsi_host_template qla4xxx_driver_template = {
148 .module = THIS_MODULE,
150 .proc_name = DRIVER_NAME,
151 .queuecommand = qla4xxx_queuecommand,
153 .eh_abort_handler = qla4xxx_eh_abort,
154 .eh_device_reset_handler = qla4xxx_eh_device_reset,
155 .eh_target_reset_handler = qla4xxx_eh_target_reset,
156 .eh_host_reset_handler = qla4xxx_eh_host_reset,
157 .eh_timed_out = qla4xxx_eh_cmd_timed_out,
159 .slave_configure = qla4xxx_slave_configure,
160 .slave_alloc = qla4xxx_slave_alloc,
161 .slave_destroy = qla4xxx_slave_destroy,
165 .use_clustering = ENABLE_CLUSTERING,
166 .sg_tablesize = SG_ALL,
168 .max_sectors = 0xFFFF,
169 .shost_attrs = qla4xxx_host_attrs,
170 .host_reset = qla4xxx_host_reset,
171 .vendor_id = SCSI_NL_VID_TYPE_PCI | PCI_VENDOR_ID_QLOGIC,
174 static struct iscsi_transport qla4xxx_iscsi_transport = {
175 .owner = THIS_MODULE,
177 .caps = CAP_TEXT_NEGO |
178 CAP_DATA_PATH_OFFLOAD | CAP_HDRDGST |
179 CAP_DATADGST | CAP_LOGIN_OFFLOAD |
181 .attr_is_visible = ql4_attr_is_visible,
182 .create_session = qla4xxx_session_create,
183 .destroy_session = qla4xxx_session_destroy,
184 .start_conn = qla4xxx_conn_start,
185 .create_conn = qla4xxx_conn_create,
186 .bind_conn = qla4xxx_conn_bind,
187 .stop_conn = iscsi_conn_stop,
188 .destroy_conn = qla4xxx_conn_destroy,
189 .set_param = iscsi_set_param,
190 .get_conn_param = qla4xxx_conn_get_param,
191 .get_session_param = qla4xxx_session_get_param,
192 .get_ep_param = qla4xxx_get_ep_param,
193 .ep_connect = qla4xxx_ep_connect,
194 .ep_poll = qla4xxx_ep_poll,
195 .ep_disconnect = qla4xxx_ep_disconnect,
196 .get_stats = qla4xxx_conn_get_stats,
197 .send_pdu = iscsi_conn_send_pdu,
198 .xmit_task = qla4xxx_task_xmit,
199 .cleanup_task = qla4xxx_task_cleanup,
200 .alloc_pdu = qla4xxx_alloc_pdu,
202 .get_host_param = qla4xxx_host_get_param,
203 .set_iface_param = qla4xxx_iface_set_param,
204 .get_iface_param = qla4xxx_get_iface_param,
205 .bsg_request = qla4xxx_bsg_request,
206 .send_ping = qla4xxx_send_ping,
207 .get_chap = qla4xxx_get_chap_list,
208 .delete_chap = qla4xxx_delete_chap,
211 static struct scsi_transport_template *qla4xxx_scsi_transport;
213 static int qla4xxx_send_ping(struct Scsi_Host *shost, uint32_t iface_num,
214 uint32_t iface_type, uint32_t payload_size,
215 uint32_t pid, struct sockaddr *dst_addr)
217 struct scsi_qla_host *ha = to_qla_host(shost);
218 struct sockaddr_in *addr;
219 struct sockaddr_in6 *addr6;
220 uint32_t options = 0;
221 uint8_t ipaddr[IPv6_ADDR_LEN];
224 memset(ipaddr, 0, IPv6_ADDR_LEN);
226 if ((iface_type == ISCSI_IFACE_TYPE_IPV4) &&
227 (dst_addr->sa_family == AF_INET)) {
228 addr = (struct sockaddr_in *)dst_addr;
229 memcpy(ipaddr, &addr->sin_addr.s_addr, IP_ADDR_LEN);
230 DEBUG2(ql4_printk(KERN_INFO, ha, "%s: IPv4 Ping src: %pI4 "
231 "dest: %pI4\n", __func__,
232 &ha->ip_config.ip_address, ipaddr));
233 rval = qla4xxx_ping_iocb(ha, options, payload_size, pid,
237 } else if ((iface_type == ISCSI_IFACE_TYPE_IPV6) &&
238 (dst_addr->sa_family == AF_INET6)) {
240 addr6 = (struct sockaddr_in6 *)dst_addr;
241 memcpy(ipaddr, &addr6->sin6_addr.in6_u.u6_addr8, IPv6_ADDR_LEN);
243 options |= PING_IPV6_PROTOCOL_ENABLE;
245 /* Ping using LinkLocal address */
246 if ((iface_num == 0) || (iface_num == 1)) {
247 DEBUG2(ql4_printk(KERN_INFO, ha, "%s: LinkLocal Ping "
248 "src: %pI6 dest: %pI6\n", __func__,
249 &ha->ip_config.ipv6_link_local_addr,
251 options |= PING_IPV6_LINKLOCAL_ADDR;
252 rval = qla4xxx_ping_iocb(ha, options, payload_size,
255 ql4_printk(KERN_WARNING, ha, "%s: iface num = %d "
256 "not supported\n", __func__, iface_num);
262 * If ping using LinkLocal address fails, try ping using
265 if (rval != QLA_SUCCESS) {
266 options &= ~PING_IPV6_LINKLOCAL_ADDR;
267 if (iface_num == 0) {
268 options |= PING_IPV6_ADDR0;
269 DEBUG2(ql4_printk(KERN_INFO, ha, "%s: IPv6 "
271 "dest: %pI6\n", __func__,
272 &ha->ip_config.ipv6_addr0,
274 } else if (iface_num == 1) {
275 options |= PING_IPV6_ADDR1;
276 DEBUG2(ql4_printk(KERN_INFO, ha, "%s: IPv6 "
278 "dest: %pI6\n", __func__,
279 &ha->ip_config.ipv6_addr1,
282 rval = qla4xxx_ping_iocb(ha, options, payload_size,
293 static umode_t ql4_attr_is_visible(int param_type, int param)
295 switch (param_type) {
296 case ISCSI_HOST_PARAM:
298 case ISCSI_HOST_PARAM_HWADDRESS:
299 case ISCSI_HOST_PARAM_IPADDRESS:
300 case ISCSI_HOST_PARAM_INITIATOR_NAME:
301 case ISCSI_HOST_PARAM_PORT_STATE:
302 case ISCSI_HOST_PARAM_PORT_SPEED:
309 case ISCSI_PARAM_PERSISTENT_ADDRESS:
310 case ISCSI_PARAM_PERSISTENT_PORT:
311 case ISCSI_PARAM_CONN_ADDRESS:
312 case ISCSI_PARAM_CONN_PORT:
313 case ISCSI_PARAM_TARGET_NAME:
314 case ISCSI_PARAM_TPGT:
315 case ISCSI_PARAM_TARGET_ALIAS:
316 case ISCSI_PARAM_MAX_BURST:
317 case ISCSI_PARAM_MAX_R2T:
318 case ISCSI_PARAM_FIRST_BURST:
319 case ISCSI_PARAM_MAX_RECV_DLENGTH:
320 case ISCSI_PARAM_MAX_XMIT_DLENGTH:
321 case ISCSI_PARAM_IFACE_NAME:
322 case ISCSI_PARAM_CHAP_OUT_IDX:
323 case ISCSI_PARAM_CHAP_IN_IDX:
324 case ISCSI_PARAM_USERNAME:
325 case ISCSI_PARAM_PASSWORD:
326 case ISCSI_PARAM_USERNAME_IN:
327 case ISCSI_PARAM_PASSWORD_IN:
332 case ISCSI_NET_PARAM:
334 case ISCSI_NET_PARAM_IPV4_ADDR:
335 case ISCSI_NET_PARAM_IPV4_SUBNET:
336 case ISCSI_NET_PARAM_IPV4_GW:
337 case ISCSI_NET_PARAM_IPV4_BOOTPROTO:
338 case ISCSI_NET_PARAM_IFACE_ENABLE:
339 case ISCSI_NET_PARAM_IPV6_LINKLOCAL:
340 case ISCSI_NET_PARAM_IPV6_ADDR:
341 case ISCSI_NET_PARAM_IPV6_ROUTER:
342 case ISCSI_NET_PARAM_IPV6_ADDR_AUTOCFG:
343 case ISCSI_NET_PARAM_IPV6_LINKLOCAL_AUTOCFG:
344 case ISCSI_NET_PARAM_VLAN_ID:
345 case ISCSI_NET_PARAM_VLAN_PRIORITY:
346 case ISCSI_NET_PARAM_VLAN_ENABLED:
347 case ISCSI_NET_PARAM_MTU:
348 case ISCSI_NET_PARAM_PORT:
358 static int qla4xxx_get_chap_list(struct Scsi_Host *shost, uint16_t chap_tbl_idx,
359 uint32_t *num_entries, char *buf)
361 struct scsi_qla_host *ha = to_qla_host(shost);
362 struct ql4_chap_table *chap_table;
363 struct iscsi_chap_rec *chap_rec;
364 int max_chap_entries = 0;
365 int valid_chap_entries = 0;
369 max_chap_entries = (ha->hw.flt_chap_size / 2) /
370 sizeof(struct ql4_chap_table);
372 max_chap_entries = MAX_CHAP_ENTRIES_40XX;
374 ql4_printk(KERN_INFO, ha, "%s: num_entries = %d, CHAP idx = %d\n",
375 __func__, *num_entries, chap_tbl_idx);
379 goto exit_get_chap_list;
382 chap_rec = (struct iscsi_chap_rec *) buf;
383 mutex_lock(&ha->chap_sem);
384 for (i = chap_tbl_idx; i < max_chap_entries; i++) {
385 chap_table = (struct ql4_chap_table *)ha->chap_list + i;
386 if (chap_table->cookie !=
387 __constant_cpu_to_le16(CHAP_VALID_COOKIE))
390 chap_rec->chap_tbl_idx = i;
391 strncpy(chap_rec->username, chap_table->name,
392 ISCSI_CHAP_AUTH_NAME_MAX_LEN);
393 strncpy(chap_rec->password, chap_table->secret,
394 QL4_CHAP_MAX_SECRET_LEN);
395 chap_rec->password_length = chap_table->secret_len;
397 if (chap_table->flags & BIT_7) /* local */
398 chap_rec->chap_type = CHAP_TYPE_OUT;
400 if (chap_table->flags & BIT_6) /* peer */
401 chap_rec->chap_type = CHAP_TYPE_IN;
405 valid_chap_entries++;
406 if (valid_chap_entries == *num_entries)
411 mutex_unlock(&ha->chap_sem);
414 ql4_printk(KERN_INFO, ha, "%s: Valid CHAP Entries = %d\n",
415 __func__, valid_chap_entries);
416 *num_entries = valid_chap_entries;
420 static int __qla4xxx_is_chap_active(struct device *dev, void *data)
423 uint16_t *chap_tbl_idx = (uint16_t *) data;
424 struct iscsi_cls_session *cls_session;
425 struct iscsi_session *sess;
426 struct ddb_entry *ddb_entry;
428 if (!iscsi_is_session_dev(dev))
429 goto exit_is_chap_active;
431 cls_session = iscsi_dev_to_session(dev);
432 sess = cls_session->dd_data;
433 ddb_entry = sess->dd_data;
435 if (iscsi_session_chkready(cls_session))
436 goto exit_is_chap_active;
438 if (ddb_entry->chap_tbl_idx == *chap_tbl_idx)
445 static int qla4xxx_is_chap_active(struct Scsi_Host *shost,
446 uint16_t chap_tbl_idx)
450 ret = device_for_each_child(&shost->shost_gendev, &chap_tbl_idx,
451 __qla4xxx_is_chap_active);
456 static int qla4xxx_delete_chap(struct Scsi_Host *shost, uint16_t chap_tbl_idx)
458 struct scsi_qla_host *ha = to_qla_host(shost);
459 struct ql4_chap_table *chap_table;
461 int max_chap_entries = 0;
466 chap_table = dma_pool_alloc(ha->chap_dma_pool, GFP_KERNEL, &chap_dma);
467 if (chap_table == NULL)
470 memset(chap_table, 0, sizeof(struct ql4_chap_table));
473 max_chap_entries = (ha->hw.flt_chap_size / 2) /
474 sizeof(struct ql4_chap_table);
476 max_chap_entries = MAX_CHAP_ENTRIES_40XX;
478 if (chap_tbl_idx > max_chap_entries) {
480 goto exit_delete_chap;
483 /* Check if chap index is in use.
484 * If chap is in use don't delet chap entry */
485 ret = qla4xxx_is_chap_active(shost, chap_tbl_idx);
487 ql4_printk(KERN_INFO, ha, "CHAP entry %d is in use, cannot "
488 "delete from flash\n", chap_tbl_idx);
490 goto exit_delete_chap;
493 chap_size = sizeof(struct ql4_chap_table);
495 offset = FLASH_CHAP_OFFSET | (chap_tbl_idx * chap_size);
497 offset = FLASH_RAW_ACCESS_ADDR + (ha->hw.flt_region_chap << 2);
498 /* flt_chap_size is CHAP table size for both ports
499 * so divide it by 2 to calculate the offset for second port
501 if (ha->port_num == 1)
502 offset += (ha->hw.flt_chap_size / 2);
503 offset += (chap_tbl_idx * chap_size);
506 ret = qla4xxx_get_flash(ha, chap_dma, offset, chap_size);
507 if (ret != QLA_SUCCESS) {
509 goto exit_delete_chap;
512 DEBUG2(ql4_printk(KERN_INFO, ha, "Chap Cookie: x%x\n",
513 __le16_to_cpu(chap_table->cookie)));
515 if (__le16_to_cpu(chap_table->cookie) != CHAP_VALID_COOKIE) {
516 ql4_printk(KERN_ERR, ha, "No valid chap entry found\n");
517 goto exit_delete_chap;
520 chap_table->cookie = __constant_cpu_to_le16(0xFFFF);
522 offset = FLASH_CHAP_OFFSET |
523 (chap_tbl_idx * sizeof(struct ql4_chap_table));
524 ret = qla4xxx_set_flash(ha, chap_dma, offset, chap_size,
525 FLASH_OPT_RMW_COMMIT);
526 if (ret == QLA_SUCCESS && ha->chap_list) {
527 mutex_lock(&ha->chap_sem);
528 /* Update ha chap_list cache */
529 memcpy((struct ql4_chap_table *)ha->chap_list + chap_tbl_idx,
530 chap_table, sizeof(struct ql4_chap_table));
531 mutex_unlock(&ha->chap_sem);
533 if (ret != QLA_SUCCESS)
537 dma_pool_free(ha->chap_dma_pool, chap_table, chap_dma);
541 static int qla4xxx_get_iface_param(struct iscsi_iface *iface,
542 enum iscsi_param_type param_type,
543 int param, char *buf)
545 struct Scsi_Host *shost = iscsi_iface_to_shost(iface);
546 struct scsi_qla_host *ha = to_qla_host(shost);
549 if (param_type != ISCSI_NET_PARAM)
553 case ISCSI_NET_PARAM_IPV4_ADDR:
554 len = sprintf(buf, "%pI4\n", &ha->ip_config.ip_address);
556 case ISCSI_NET_PARAM_IPV4_SUBNET:
557 len = sprintf(buf, "%pI4\n", &ha->ip_config.subnet_mask);
559 case ISCSI_NET_PARAM_IPV4_GW:
560 len = sprintf(buf, "%pI4\n", &ha->ip_config.gateway);
562 case ISCSI_NET_PARAM_IFACE_ENABLE:
563 if (iface->iface_type == ISCSI_IFACE_TYPE_IPV4)
564 len = sprintf(buf, "%s\n",
565 (ha->ip_config.ipv4_options &
566 IPOPT_IPV4_PROTOCOL_ENABLE) ?
567 "enabled" : "disabled");
568 else if (iface->iface_type == ISCSI_IFACE_TYPE_IPV6)
569 len = sprintf(buf, "%s\n",
570 (ha->ip_config.ipv6_options &
571 IPV6_OPT_IPV6_PROTOCOL_ENABLE) ?
572 "enabled" : "disabled");
574 case ISCSI_NET_PARAM_IPV4_BOOTPROTO:
575 len = sprintf(buf, "%s\n",
576 (ha->ip_config.tcp_options & TCPOPT_DHCP_ENABLE) ?
579 case ISCSI_NET_PARAM_IPV6_ADDR:
580 if (iface->iface_num == 0)
581 len = sprintf(buf, "%pI6\n", &ha->ip_config.ipv6_addr0);
582 if (iface->iface_num == 1)
583 len = sprintf(buf, "%pI6\n", &ha->ip_config.ipv6_addr1);
585 case ISCSI_NET_PARAM_IPV6_LINKLOCAL:
586 len = sprintf(buf, "%pI6\n",
587 &ha->ip_config.ipv6_link_local_addr);
589 case ISCSI_NET_PARAM_IPV6_ROUTER:
590 len = sprintf(buf, "%pI6\n",
591 &ha->ip_config.ipv6_default_router_addr);
593 case ISCSI_NET_PARAM_IPV6_ADDR_AUTOCFG:
594 len = sprintf(buf, "%s\n",
595 (ha->ip_config.ipv6_addl_options &
596 IPV6_ADDOPT_NEIGHBOR_DISCOVERY_ADDR_ENABLE) ?
599 case ISCSI_NET_PARAM_IPV6_LINKLOCAL_AUTOCFG:
600 len = sprintf(buf, "%s\n",
601 (ha->ip_config.ipv6_addl_options &
602 IPV6_ADDOPT_AUTOCONFIG_LINK_LOCAL_ADDR) ?
605 case ISCSI_NET_PARAM_VLAN_ID:
606 if (iface->iface_type == ISCSI_IFACE_TYPE_IPV4)
607 len = sprintf(buf, "%d\n",
608 (ha->ip_config.ipv4_vlan_tag &
610 else if (iface->iface_type == ISCSI_IFACE_TYPE_IPV6)
611 len = sprintf(buf, "%d\n",
612 (ha->ip_config.ipv6_vlan_tag &
615 case ISCSI_NET_PARAM_VLAN_PRIORITY:
616 if (iface->iface_type == ISCSI_IFACE_TYPE_IPV4)
617 len = sprintf(buf, "%d\n",
618 ((ha->ip_config.ipv4_vlan_tag >> 13) &
619 ISCSI_MAX_VLAN_PRIORITY));
620 else if (iface->iface_type == ISCSI_IFACE_TYPE_IPV6)
621 len = sprintf(buf, "%d\n",
622 ((ha->ip_config.ipv6_vlan_tag >> 13) &
623 ISCSI_MAX_VLAN_PRIORITY));
625 case ISCSI_NET_PARAM_VLAN_ENABLED:
626 if (iface->iface_type == ISCSI_IFACE_TYPE_IPV4)
627 len = sprintf(buf, "%s\n",
628 (ha->ip_config.ipv4_options &
629 IPOPT_VLAN_TAGGING_ENABLE) ?
630 "enabled" : "disabled");
631 else if (iface->iface_type == ISCSI_IFACE_TYPE_IPV6)
632 len = sprintf(buf, "%s\n",
633 (ha->ip_config.ipv6_options &
634 IPV6_OPT_VLAN_TAGGING_ENABLE) ?
635 "enabled" : "disabled");
637 case ISCSI_NET_PARAM_MTU:
638 len = sprintf(buf, "%d\n", ha->ip_config.eth_mtu_size);
640 case ISCSI_NET_PARAM_PORT:
641 if (iface->iface_type == ISCSI_IFACE_TYPE_IPV4)
642 len = sprintf(buf, "%d\n", ha->ip_config.ipv4_port);
643 else if (iface->iface_type == ISCSI_IFACE_TYPE_IPV6)
644 len = sprintf(buf, "%d\n", ha->ip_config.ipv6_port);
653 static struct iscsi_endpoint *
654 qla4xxx_ep_connect(struct Scsi_Host *shost, struct sockaddr *dst_addr,
658 struct iscsi_endpoint *ep;
659 struct qla_endpoint *qla_ep;
660 struct scsi_qla_host *ha;
661 struct sockaddr_in *addr;
662 struct sockaddr_in6 *addr6;
664 DEBUG2(printk(KERN_INFO "Func: %s\n", __func__));
667 printk(KERN_ERR "%s: shost is NULL\n",
672 ha = iscsi_host_priv(shost);
674 ep = iscsi_create_endpoint(sizeof(struct qla_endpoint));
680 qla_ep = ep->dd_data;
681 memset(qla_ep, 0, sizeof(struct qla_endpoint));
682 if (dst_addr->sa_family == AF_INET) {
683 memcpy(&qla_ep->dst_addr, dst_addr, sizeof(struct sockaddr_in));
684 addr = (struct sockaddr_in *)&qla_ep->dst_addr;
685 DEBUG2(ql4_printk(KERN_INFO, ha, "%s: %pI4\n", __func__,
686 (char *)&addr->sin_addr));
687 } else if (dst_addr->sa_family == AF_INET6) {
688 memcpy(&qla_ep->dst_addr, dst_addr,
689 sizeof(struct sockaddr_in6));
690 addr6 = (struct sockaddr_in6 *)&qla_ep->dst_addr;
691 DEBUG2(ql4_printk(KERN_INFO, ha, "%s: %pI6\n", __func__,
692 (char *)&addr6->sin6_addr));
695 qla_ep->host = shost;
700 static int qla4xxx_ep_poll(struct iscsi_endpoint *ep, int timeout_ms)
702 struct qla_endpoint *qla_ep;
703 struct scsi_qla_host *ha;
706 DEBUG2(printk(KERN_INFO "Func: %s\n", __func__));
707 qla_ep = ep->dd_data;
708 ha = to_qla_host(qla_ep->host);
710 if (adapter_up(ha) && !test_bit(AF_BUILD_DDB_LIST, &ha->flags))
716 static void qla4xxx_ep_disconnect(struct iscsi_endpoint *ep)
718 DEBUG2(printk(KERN_INFO "Func: %s\n", __func__));
719 iscsi_destroy_endpoint(ep);
722 static int qla4xxx_get_ep_param(struct iscsi_endpoint *ep,
723 enum iscsi_param param,
726 struct qla_endpoint *qla_ep = ep->dd_data;
727 struct sockaddr *dst_addr;
729 DEBUG2(printk(KERN_INFO "Func: %s\n", __func__));
732 case ISCSI_PARAM_CONN_PORT:
733 case ISCSI_PARAM_CONN_ADDRESS:
737 dst_addr = (struct sockaddr *)&qla_ep->dst_addr;
741 return iscsi_conn_get_addr_param((struct sockaddr_storage *)
742 &qla_ep->dst_addr, param, buf);
748 static void qla4xxx_conn_get_stats(struct iscsi_cls_conn *cls_conn,
749 struct iscsi_stats *stats)
751 struct iscsi_session *sess;
752 struct iscsi_cls_session *cls_sess;
753 struct ddb_entry *ddb_entry;
754 struct scsi_qla_host *ha;
755 struct ql_iscsi_stats *ql_iscsi_stats;
758 dma_addr_t iscsi_stats_dma;
760 DEBUG2(printk(KERN_INFO "Func: %s\n", __func__));
762 cls_sess = iscsi_conn_to_session(cls_conn);
763 sess = cls_sess->dd_data;
764 ddb_entry = sess->dd_data;
767 stats_size = PAGE_ALIGN(sizeof(struct ql_iscsi_stats));
768 /* Allocate memory */
769 ql_iscsi_stats = dma_alloc_coherent(&ha->pdev->dev, stats_size,
770 &iscsi_stats_dma, GFP_KERNEL);
771 if (!ql_iscsi_stats) {
772 ql4_printk(KERN_ERR, ha,
773 "Unable to allocate memory for iscsi stats\n");
777 ret = qla4xxx_get_mgmt_data(ha, ddb_entry->fw_ddb_index, stats_size,
779 if (ret != QLA_SUCCESS) {
780 ql4_printk(KERN_ERR, ha,
781 "Unable to retreive iscsi stats\n");
786 stats->txdata_octets = le64_to_cpu(ql_iscsi_stats->tx_data_octets);
787 stats->rxdata_octets = le64_to_cpu(ql_iscsi_stats->rx_data_octets);
789 stats->noptx_pdus = le32_to_cpu(ql_iscsi_stats->tx_nopout_pdus);
790 stats->scsicmd_pdus = le32_to_cpu(ql_iscsi_stats->tx_scsi_cmd_pdus);
791 stats->tmfcmd_pdus = le32_to_cpu(ql_iscsi_stats->tx_tmf_cmd_pdus);
792 stats->login_pdus = le32_to_cpu(ql_iscsi_stats->tx_login_cmd_pdus);
793 stats->text_pdus = le32_to_cpu(ql_iscsi_stats->tx_text_cmd_pdus);
794 stats->dataout_pdus = le32_to_cpu(ql_iscsi_stats->tx_scsi_write_pdus);
795 stats->logout_pdus = le32_to_cpu(ql_iscsi_stats->tx_logout_cmd_pdus);
796 stats->snack_pdus = le32_to_cpu(ql_iscsi_stats->tx_snack_req_pdus);
798 stats->noprx_pdus = le32_to_cpu(ql_iscsi_stats->rx_nopin_pdus);
799 stats->scsirsp_pdus = le32_to_cpu(ql_iscsi_stats->rx_scsi_resp_pdus);
800 stats->tmfrsp_pdus = le32_to_cpu(ql_iscsi_stats->rx_tmf_resp_pdus);
801 stats->textrsp_pdus = le32_to_cpu(ql_iscsi_stats->rx_text_resp_pdus);
802 stats->datain_pdus = le32_to_cpu(ql_iscsi_stats->rx_scsi_read_pdus);
803 stats->logoutrsp_pdus =
804 le32_to_cpu(ql_iscsi_stats->rx_logout_resp_pdus);
805 stats->r2t_pdus = le32_to_cpu(ql_iscsi_stats->rx_r2t_pdus);
806 stats->async_pdus = le32_to_cpu(ql_iscsi_stats->rx_async_pdus);
807 stats->rjt_pdus = le32_to_cpu(ql_iscsi_stats->rx_reject_pdus);
810 dma_free_coherent(&ha->pdev->dev, stats_size, ql_iscsi_stats,
816 static enum blk_eh_timer_return qla4xxx_eh_cmd_timed_out(struct scsi_cmnd *sc)
818 struct iscsi_cls_session *session;
819 struct iscsi_session *sess;
821 enum blk_eh_timer_return ret = BLK_EH_NOT_HANDLED;
823 session = starget_to_session(scsi_target(sc->device));
824 sess = session->dd_data;
826 spin_lock_irqsave(&session->lock, flags);
827 if (session->state == ISCSI_SESSION_FAILED)
828 ret = BLK_EH_RESET_TIMER;
829 spin_unlock_irqrestore(&session->lock, flags);
834 static void qla4xxx_set_port_speed(struct Scsi_Host *shost)
836 struct scsi_qla_host *ha = to_qla_host(shost);
837 struct iscsi_cls_host *ihost = shost_priv(shost);
838 uint32_t speed = ISCSI_PORT_SPEED_UNKNOWN;
840 qla4xxx_get_firmware_state(ha);
842 switch (ha->addl_fw_state & 0x0F00) {
843 case FW_ADDSTATE_LINK_SPEED_10MBPS:
844 speed = ISCSI_PORT_SPEED_10MBPS;
846 case FW_ADDSTATE_LINK_SPEED_100MBPS:
847 speed = ISCSI_PORT_SPEED_100MBPS;
849 case FW_ADDSTATE_LINK_SPEED_1GBPS:
850 speed = ISCSI_PORT_SPEED_1GBPS;
852 case FW_ADDSTATE_LINK_SPEED_10GBPS:
853 speed = ISCSI_PORT_SPEED_10GBPS;
856 ihost->port_speed = speed;
859 static void qla4xxx_set_port_state(struct Scsi_Host *shost)
861 struct scsi_qla_host *ha = to_qla_host(shost);
862 struct iscsi_cls_host *ihost = shost_priv(shost);
863 uint32_t state = ISCSI_PORT_STATE_DOWN;
865 if (test_bit(AF_LINK_UP, &ha->flags))
866 state = ISCSI_PORT_STATE_UP;
868 ihost->port_state = state;
871 static int qla4xxx_host_get_param(struct Scsi_Host *shost,
872 enum iscsi_host_param param, char *buf)
874 struct scsi_qla_host *ha = to_qla_host(shost);
878 case ISCSI_HOST_PARAM_HWADDRESS:
879 len = sysfs_format_mac(buf, ha->my_mac, MAC_ADDR_LEN);
881 case ISCSI_HOST_PARAM_IPADDRESS:
882 len = sprintf(buf, "%pI4\n", &ha->ip_config.ip_address);
884 case ISCSI_HOST_PARAM_INITIATOR_NAME:
885 len = sprintf(buf, "%s\n", ha->name_string);
887 case ISCSI_HOST_PARAM_PORT_STATE:
888 qla4xxx_set_port_state(shost);
889 len = sprintf(buf, "%s\n", iscsi_get_port_state_name(shost));
891 case ISCSI_HOST_PARAM_PORT_SPEED:
892 qla4xxx_set_port_speed(shost);
893 len = sprintf(buf, "%s\n", iscsi_get_port_speed_name(shost));
902 static void qla4xxx_create_ipv4_iface(struct scsi_qla_host *ha)
908 ha->iface_ipv4 = iscsi_create_iface(ha->host,
909 &qla4xxx_iscsi_transport,
910 ISCSI_IFACE_TYPE_IPV4, 0, 0);
912 ql4_printk(KERN_ERR, ha, "Could not create IPv4 iSCSI "
916 static void qla4xxx_create_ipv6_iface(struct scsi_qla_host *ha)
918 if (!ha->iface_ipv6_0)
920 ha->iface_ipv6_0 = iscsi_create_iface(ha->host,
921 &qla4xxx_iscsi_transport,
922 ISCSI_IFACE_TYPE_IPV6, 0,
924 if (!ha->iface_ipv6_0)
925 ql4_printk(KERN_ERR, ha, "Could not create IPv6 iSCSI "
928 if (!ha->iface_ipv6_1)
930 ha->iface_ipv6_1 = iscsi_create_iface(ha->host,
931 &qla4xxx_iscsi_transport,
932 ISCSI_IFACE_TYPE_IPV6, 1,
934 if (!ha->iface_ipv6_1)
935 ql4_printk(KERN_ERR, ha, "Could not create IPv6 iSCSI "
939 static void qla4xxx_create_ifaces(struct scsi_qla_host *ha)
941 if (ha->ip_config.ipv4_options & IPOPT_IPV4_PROTOCOL_ENABLE)
942 qla4xxx_create_ipv4_iface(ha);
944 if (ha->ip_config.ipv6_options & IPV6_OPT_IPV6_PROTOCOL_ENABLE)
945 qla4xxx_create_ipv6_iface(ha);
948 static void qla4xxx_destroy_ipv4_iface(struct scsi_qla_host *ha)
950 if (ha->iface_ipv4) {
951 iscsi_destroy_iface(ha->iface_ipv4);
952 ha->iface_ipv4 = NULL;
956 static void qla4xxx_destroy_ipv6_iface(struct scsi_qla_host *ha)
958 if (ha->iface_ipv6_0) {
959 iscsi_destroy_iface(ha->iface_ipv6_0);
960 ha->iface_ipv6_0 = NULL;
962 if (ha->iface_ipv6_1) {
963 iscsi_destroy_iface(ha->iface_ipv6_1);
964 ha->iface_ipv6_1 = NULL;
968 static void qla4xxx_destroy_ifaces(struct scsi_qla_host *ha)
970 qla4xxx_destroy_ipv4_iface(ha);
971 qla4xxx_destroy_ipv6_iface(ha);
974 static void qla4xxx_set_ipv6(struct scsi_qla_host *ha,
975 struct iscsi_iface_param_info *iface_param,
976 struct addr_ctrl_blk *init_fw_cb)
979 * iface_num 0 is valid for IPv6 Addr, linklocal, router, autocfg.
980 * iface_num 1 is valid only for IPv6 Addr.
982 switch (iface_param->param) {
983 case ISCSI_NET_PARAM_IPV6_ADDR:
984 if (iface_param->iface_num & 0x1)
986 memcpy(init_fw_cb->ipv6_addr1, iface_param->value,
987 sizeof(init_fw_cb->ipv6_addr1));
990 memcpy(init_fw_cb->ipv6_addr0, iface_param->value,
991 sizeof(init_fw_cb->ipv6_addr0));
993 case ISCSI_NET_PARAM_IPV6_LINKLOCAL:
994 if (iface_param->iface_num & 0x1)
996 memcpy(init_fw_cb->ipv6_if_id, &iface_param->value[8],
997 sizeof(init_fw_cb->ipv6_if_id));
999 case ISCSI_NET_PARAM_IPV6_ROUTER:
1000 if (iface_param->iface_num & 0x1)
1002 memcpy(init_fw_cb->ipv6_dflt_rtr_addr, iface_param->value,
1003 sizeof(init_fw_cb->ipv6_dflt_rtr_addr));
1005 case ISCSI_NET_PARAM_IPV6_ADDR_AUTOCFG:
1006 /* Autocfg applies to even interface */
1007 if (iface_param->iface_num & 0x1)
1010 if (iface_param->value[0] == ISCSI_IPV6_AUTOCFG_DISABLE)
1011 init_fw_cb->ipv6_addtl_opts &=
1013 ~IPV6_ADDOPT_NEIGHBOR_DISCOVERY_ADDR_ENABLE);
1014 else if (iface_param->value[0] == ISCSI_IPV6_AUTOCFG_ND_ENABLE)
1015 init_fw_cb->ipv6_addtl_opts |=
1017 IPV6_ADDOPT_NEIGHBOR_DISCOVERY_ADDR_ENABLE);
1019 ql4_printk(KERN_ERR, ha, "Invalid autocfg setting for "
1022 case ISCSI_NET_PARAM_IPV6_LINKLOCAL_AUTOCFG:
1023 /* Autocfg applies to even interface */
1024 if (iface_param->iface_num & 0x1)
1027 if (iface_param->value[0] ==
1028 ISCSI_IPV6_LINKLOCAL_AUTOCFG_ENABLE)
1029 init_fw_cb->ipv6_addtl_opts |= cpu_to_le16(
1030 IPV6_ADDOPT_AUTOCONFIG_LINK_LOCAL_ADDR);
1031 else if (iface_param->value[0] ==
1032 ISCSI_IPV6_LINKLOCAL_AUTOCFG_DISABLE)
1033 init_fw_cb->ipv6_addtl_opts &= cpu_to_le16(
1034 ~IPV6_ADDOPT_AUTOCONFIG_LINK_LOCAL_ADDR);
1036 ql4_printk(KERN_ERR, ha, "Invalid autocfg setting for "
1037 "IPv6 linklocal addr\n");
1039 case ISCSI_NET_PARAM_IPV6_ROUTER_AUTOCFG:
1040 /* Autocfg applies to even interface */
1041 if (iface_param->iface_num & 0x1)
1044 if (iface_param->value[0] == ISCSI_IPV6_ROUTER_AUTOCFG_ENABLE)
1045 memset(init_fw_cb->ipv6_dflt_rtr_addr, 0,
1046 sizeof(init_fw_cb->ipv6_dflt_rtr_addr));
1048 case ISCSI_NET_PARAM_IFACE_ENABLE:
1049 if (iface_param->value[0] == ISCSI_IFACE_ENABLE) {
1050 init_fw_cb->ipv6_opts |=
1051 cpu_to_le16(IPV6_OPT_IPV6_PROTOCOL_ENABLE);
1052 qla4xxx_create_ipv6_iface(ha);
1054 init_fw_cb->ipv6_opts &=
1055 cpu_to_le16(~IPV6_OPT_IPV6_PROTOCOL_ENABLE &
1057 qla4xxx_destroy_ipv6_iface(ha);
1060 case ISCSI_NET_PARAM_VLAN_TAG:
1061 if (iface_param->len != sizeof(init_fw_cb->ipv6_vlan_tag))
1063 init_fw_cb->ipv6_vlan_tag =
1064 cpu_to_be16(*(uint16_t *)iface_param->value);
1066 case ISCSI_NET_PARAM_VLAN_ENABLED:
1067 if (iface_param->value[0] == ISCSI_VLAN_ENABLE)
1068 init_fw_cb->ipv6_opts |=
1069 cpu_to_le16(IPV6_OPT_VLAN_TAGGING_ENABLE);
1071 init_fw_cb->ipv6_opts &=
1072 cpu_to_le16(~IPV6_OPT_VLAN_TAGGING_ENABLE);
1074 case ISCSI_NET_PARAM_MTU:
1075 init_fw_cb->eth_mtu_size =
1076 cpu_to_le16(*(uint16_t *)iface_param->value);
1078 case ISCSI_NET_PARAM_PORT:
1079 /* Autocfg applies to even interface */
1080 if (iface_param->iface_num & 0x1)
1083 init_fw_cb->ipv6_port =
1084 cpu_to_le16(*(uint16_t *)iface_param->value);
1087 ql4_printk(KERN_ERR, ha, "Unknown IPv6 param = %d\n",
1088 iface_param->param);
1093 static void qla4xxx_set_ipv4(struct scsi_qla_host *ha,
1094 struct iscsi_iface_param_info *iface_param,
1095 struct addr_ctrl_blk *init_fw_cb)
1097 switch (iface_param->param) {
1098 case ISCSI_NET_PARAM_IPV4_ADDR:
1099 memcpy(init_fw_cb->ipv4_addr, iface_param->value,
1100 sizeof(init_fw_cb->ipv4_addr));
1102 case ISCSI_NET_PARAM_IPV4_SUBNET:
1103 memcpy(init_fw_cb->ipv4_subnet, iface_param->value,
1104 sizeof(init_fw_cb->ipv4_subnet));
1106 case ISCSI_NET_PARAM_IPV4_GW:
1107 memcpy(init_fw_cb->ipv4_gw_addr, iface_param->value,
1108 sizeof(init_fw_cb->ipv4_gw_addr));
1110 case ISCSI_NET_PARAM_IPV4_BOOTPROTO:
1111 if (iface_param->value[0] == ISCSI_BOOTPROTO_DHCP)
1112 init_fw_cb->ipv4_tcp_opts |=
1113 cpu_to_le16(TCPOPT_DHCP_ENABLE);
1114 else if (iface_param->value[0] == ISCSI_BOOTPROTO_STATIC)
1115 init_fw_cb->ipv4_tcp_opts &=
1116 cpu_to_le16(~TCPOPT_DHCP_ENABLE);
1118 ql4_printk(KERN_ERR, ha, "Invalid IPv4 bootproto\n");
1120 case ISCSI_NET_PARAM_IFACE_ENABLE:
1121 if (iface_param->value[0] == ISCSI_IFACE_ENABLE) {
1122 init_fw_cb->ipv4_ip_opts |=
1123 cpu_to_le16(IPOPT_IPV4_PROTOCOL_ENABLE);
1124 qla4xxx_create_ipv4_iface(ha);
1126 init_fw_cb->ipv4_ip_opts &=
1127 cpu_to_le16(~IPOPT_IPV4_PROTOCOL_ENABLE &
1129 qla4xxx_destroy_ipv4_iface(ha);
1132 case ISCSI_NET_PARAM_VLAN_TAG:
1133 if (iface_param->len != sizeof(init_fw_cb->ipv4_vlan_tag))
1135 init_fw_cb->ipv4_vlan_tag =
1136 cpu_to_be16(*(uint16_t *)iface_param->value);
1138 case ISCSI_NET_PARAM_VLAN_ENABLED:
1139 if (iface_param->value[0] == ISCSI_VLAN_ENABLE)
1140 init_fw_cb->ipv4_ip_opts |=
1141 cpu_to_le16(IPOPT_VLAN_TAGGING_ENABLE);
1143 init_fw_cb->ipv4_ip_opts &=
1144 cpu_to_le16(~IPOPT_VLAN_TAGGING_ENABLE);
1146 case ISCSI_NET_PARAM_MTU:
1147 init_fw_cb->eth_mtu_size =
1148 cpu_to_le16(*(uint16_t *)iface_param->value);
1150 case ISCSI_NET_PARAM_PORT:
1151 init_fw_cb->ipv4_port =
1152 cpu_to_le16(*(uint16_t *)iface_param->value);
1155 ql4_printk(KERN_ERR, ha, "Unknown IPv4 param = %d\n",
1156 iface_param->param);
1162 qla4xxx_initcb_to_acb(struct addr_ctrl_blk *init_fw_cb)
1164 struct addr_ctrl_blk_def *acb;
1165 acb = (struct addr_ctrl_blk_def *)init_fw_cb;
1166 memset(acb->reserved1, 0, sizeof(acb->reserved1));
1167 memset(acb->reserved2, 0, sizeof(acb->reserved2));
1168 memset(acb->reserved3, 0, sizeof(acb->reserved3));
1169 memset(acb->reserved4, 0, sizeof(acb->reserved4));
1170 memset(acb->reserved5, 0, sizeof(acb->reserved5));
1171 memset(acb->reserved6, 0, sizeof(acb->reserved6));
1172 memset(acb->reserved7, 0, sizeof(acb->reserved7));
1173 memset(acb->reserved8, 0, sizeof(acb->reserved8));
1174 memset(acb->reserved9, 0, sizeof(acb->reserved9));
1175 memset(acb->reserved10, 0, sizeof(acb->reserved10));
1176 memset(acb->reserved11, 0, sizeof(acb->reserved11));
1177 memset(acb->reserved12, 0, sizeof(acb->reserved12));
1178 memset(acb->reserved13, 0, sizeof(acb->reserved13));
1179 memset(acb->reserved14, 0, sizeof(acb->reserved14));
1180 memset(acb->reserved15, 0, sizeof(acb->reserved15));
1184 qla4xxx_iface_set_param(struct Scsi_Host *shost, void *data, uint32_t len)
1186 struct scsi_qla_host *ha = to_qla_host(shost);
1188 struct iscsi_iface_param_info *iface_param = NULL;
1189 struct addr_ctrl_blk *init_fw_cb = NULL;
1190 dma_addr_t init_fw_cb_dma;
1191 uint32_t mbox_cmd[MBOX_REG_COUNT];
1192 uint32_t mbox_sts[MBOX_REG_COUNT];
1194 struct nlattr *attr;
1196 init_fw_cb = dma_alloc_coherent(&ha->pdev->dev,
1197 sizeof(struct addr_ctrl_blk),
1198 &init_fw_cb_dma, GFP_KERNEL);
1200 ql4_printk(KERN_ERR, ha, "%s: Unable to alloc init_cb\n",
1205 memset(init_fw_cb, 0, sizeof(struct addr_ctrl_blk));
1206 memset(&mbox_cmd, 0, sizeof(mbox_cmd));
1207 memset(&mbox_sts, 0, sizeof(mbox_sts));
1209 if (qla4xxx_get_ifcb(ha, &mbox_cmd[0], &mbox_sts[0], init_fw_cb_dma)) {
1210 ql4_printk(KERN_ERR, ha, "%s: get ifcb failed\n", __func__);
1212 goto exit_init_fw_cb;
1215 nla_for_each_attr(attr, data, len, rem) {
1216 iface_param = nla_data(attr);
1218 if (iface_param->param_type != ISCSI_NET_PARAM)
1221 switch (iface_param->iface_type) {
1222 case ISCSI_IFACE_TYPE_IPV4:
1223 switch (iface_param->iface_num) {
1225 qla4xxx_set_ipv4(ha, iface_param, init_fw_cb);
1228 /* Cannot have more than one IPv4 interface */
1229 ql4_printk(KERN_ERR, ha, "Invalid IPv4 iface "
1231 iface_param->iface_num);
1235 case ISCSI_IFACE_TYPE_IPV6:
1236 switch (iface_param->iface_num) {
1239 qla4xxx_set_ipv6(ha, iface_param, init_fw_cb);
1242 /* Cannot have more than two IPv6 interface */
1243 ql4_printk(KERN_ERR, ha, "Invalid IPv6 iface "
1245 iface_param->iface_num);
1250 ql4_printk(KERN_ERR, ha, "Invalid iface type\n");
1255 init_fw_cb->cookie = cpu_to_le32(0x11BEAD5A);
1257 rval = qla4xxx_set_flash(ha, init_fw_cb_dma, FLASH_SEGMENT_IFCB,
1258 sizeof(struct addr_ctrl_blk),
1259 FLASH_OPT_RMW_COMMIT);
1260 if (rval != QLA_SUCCESS) {
1261 ql4_printk(KERN_ERR, ha, "%s: set flash mbx failed\n",
1264 goto exit_init_fw_cb;
1267 rval = qla4xxx_disable_acb(ha);
1268 if (rval != QLA_SUCCESS) {
1269 ql4_printk(KERN_ERR, ha, "%s: disable acb mbx failed\n",
1272 goto exit_init_fw_cb;
1275 wait_for_completion_timeout(&ha->disable_acb_comp,
1276 DISABLE_ACB_TOV * HZ);
1278 qla4xxx_initcb_to_acb(init_fw_cb);
1280 rval = qla4xxx_set_acb(ha, &mbox_cmd[0], &mbox_sts[0], init_fw_cb_dma);
1281 if (rval != QLA_SUCCESS) {
1282 ql4_printk(KERN_ERR, ha, "%s: set acb mbx failed\n",
1285 goto exit_init_fw_cb;
1288 memset(init_fw_cb, 0, sizeof(struct addr_ctrl_blk));
1289 qla4xxx_update_local_ifcb(ha, &mbox_cmd[0], &mbox_sts[0], init_fw_cb,
1293 dma_free_coherent(&ha->pdev->dev, sizeof(struct addr_ctrl_blk),
1294 init_fw_cb, init_fw_cb_dma);
1299 static int qla4xxx_session_get_param(struct iscsi_cls_session *cls_sess,
1300 enum iscsi_param param, char *buf)
1302 struct iscsi_session *sess = cls_sess->dd_data;
1303 struct ddb_entry *ddb_entry = sess->dd_data;
1304 struct scsi_qla_host *ha = ddb_entry->ha;
1309 case ISCSI_PARAM_CHAP_IN_IDX:
1310 rval = qla4xxx_get_chap_index(ha, sess->username_in,
1311 sess->password_in, BIDI_CHAP,
1316 len = sprintf(buf, "%hu\n", idx);
1318 case ISCSI_PARAM_CHAP_OUT_IDX:
1319 rval = qla4xxx_get_chap_index(ha, sess->username,
1320 sess->password, LOCAL_CHAP,
1325 len = sprintf(buf, "%hu\n", idx);
1328 return iscsi_session_get_param(cls_sess, param, buf);
1334 static int qla4xxx_conn_get_param(struct iscsi_cls_conn *cls_conn,
1335 enum iscsi_param param, char *buf)
1337 struct iscsi_conn *conn;
1338 struct qla_conn *qla_conn;
1339 struct sockaddr *dst_addr;
1342 conn = cls_conn->dd_data;
1343 qla_conn = conn->dd_data;
1344 dst_addr = &qla_conn->qla_ep->dst_addr;
1347 case ISCSI_PARAM_CONN_PORT:
1348 case ISCSI_PARAM_CONN_ADDRESS:
1349 return iscsi_conn_get_addr_param((struct sockaddr_storage *)
1350 dst_addr, param, buf);
1352 return iscsi_conn_get_param(cls_conn, param, buf);
1359 int qla4xxx_get_ddb_index(struct scsi_qla_host *ha, uint16_t *ddb_index)
1361 uint32_t mbx_sts = 0;
1362 uint16_t tmp_ddb_index;
1366 tmp_ddb_index = find_first_zero_bit(ha->ddb_idx_map, MAX_DDB_ENTRIES);
1368 if (tmp_ddb_index >= MAX_DDB_ENTRIES) {
1369 DEBUG2(ql4_printk(KERN_INFO, ha,
1370 "Free DDB index not available\n"));
1372 goto exit_get_ddb_index;
1375 if (test_and_set_bit(tmp_ddb_index, ha->ddb_idx_map))
1378 DEBUG2(ql4_printk(KERN_INFO, ha,
1379 "Found a free DDB index at %d\n", tmp_ddb_index));
1380 ret = qla4xxx_req_ddb_entry(ha, tmp_ddb_index, &mbx_sts);
1381 if (ret == QLA_ERROR) {
1382 if (mbx_sts == MBOX_STS_COMMAND_ERROR) {
1383 ql4_printk(KERN_INFO, ha,
1384 "DDB index = %d not available trying next\n",
1388 DEBUG2(ql4_printk(KERN_INFO, ha,
1389 "Free FW DDB not available\n"));
1392 *ddb_index = tmp_ddb_index;
1398 static int qla4xxx_match_ipaddress(struct scsi_qla_host *ha,
1399 struct ddb_entry *ddb_entry,
1400 char *existing_ipaddr,
1403 uint8_t dst_ipaddr[IPv6_ADDR_LEN];
1404 char formatted_ipaddr[DDB_IPADDR_LEN];
1405 int status = QLA_SUCCESS, ret = 0;
1407 if (ddb_entry->fw_ddb_entry.options & DDB_OPT_IPV6_DEVICE) {
1408 ret = in6_pton(user_ipaddr, strlen(user_ipaddr), dst_ipaddr,
1414 ret = sprintf(formatted_ipaddr, "%pI6", dst_ipaddr);
1416 ret = in4_pton(user_ipaddr, strlen(user_ipaddr), dst_ipaddr,
1422 ret = sprintf(formatted_ipaddr, "%pI4", dst_ipaddr);
1425 if (strcmp(existing_ipaddr, formatted_ipaddr))
1432 static int qla4xxx_match_fwdb_session(struct scsi_qla_host *ha,
1433 struct iscsi_cls_conn *cls_conn)
1435 int idx = 0, max_ddbs, rval;
1436 struct iscsi_cls_session *cls_sess = iscsi_conn_to_session(cls_conn);
1437 struct iscsi_session *sess, *existing_sess;
1438 struct iscsi_conn *conn, *existing_conn;
1439 struct ddb_entry *ddb_entry;
1441 sess = cls_sess->dd_data;
1442 conn = cls_conn->dd_data;
1444 if (sess->targetname == NULL ||
1445 conn->persistent_address == NULL ||
1446 conn->persistent_port == 0)
1449 max_ddbs = is_qla40XX(ha) ? MAX_DEV_DB_ENTRIES_40XX :
1452 for (idx = 0; idx < max_ddbs; idx++) {
1453 ddb_entry = qla4xxx_lookup_ddb_by_fw_index(ha, idx);
1454 if (ddb_entry == NULL)
1457 if (ddb_entry->ddb_type != FLASH_DDB)
1460 existing_sess = ddb_entry->sess->dd_data;
1461 existing_conn = ddb_entry->conn->dd_data;
1463 if (existing_sess->targetname == NULL ||
1464 existing_conn->persistent_address == NULL ||
1465 existing_conn->persistent_port == 0)
1468 DEBUG2(ql4_printk(KERN_INFO, ha,
1469 "IQN = %s User IQN = %s\n",
1470 existing_sess->targetname,
1473 DEBUG2(ql4_printk(KERN_INFO, ha,
1474 "IP = %s User IP = %s\n",
1475 existing_conn->persistent_address,
1476 conn->persistent_address));
1478 DEBUG2(ql4_printk(KERN_INFO, ha,
1479 "Port = %d User Port = %d\n",
1480 existing_conn->persistent_port,
1481 conn->persistent_port));
1483 if (strcmp(existing_sess->targetname, sess->targetname))
1485 rval = qla4xxx_match_ipaddress(ha, ddb_entry,
1486 existing_conn->persistent_address,
1487 conn->persistent_address);
1488 if (rval == QLA_ERROR)
1490 if (existing_conn->persistent_port != conn->persistent_port)
1495 if (idx == max_ddbs)
1498 DEBUG2(ql4_printk(KERN_INFO, ha,
1499 "Match found in fwdb sessions\n"));
1503 static struct iscsi_cls_session *
1504 qla4xxx_session_create(struct iscsi_endpoint *ep,
1505 uint16_t cmds_max, uint16_t qdepth,
1506 uint32_t initial_cmdsn)
1508 struct iscsi_cls_session *cls_sess;
1509 struct scsi_qla_host *ha;
1510 struct qla_endpoint *qla_ep;
1511 struct ddb_entry *ddb_entry;
1513 struct iscsi_session *sess;
1514 struct sockaddr *dst_addr;
1517 DEBUG2(printk(KERN_INFO "Func: %s\n", __func__));
1519 printk(KERN_ERR "qla4xxx: missing ep.\n");
1523 qla_ep = ep->dd_data;
1524 dst_addr = (struct sockaddr *)&qla_ep->dst_addr;
1525 ha = to_qla_host(qla_ep->host);
1527 ret = qla4xxx_get_ddb_index(ha, &ddb_index);
1528 if (ret == QLA_ERROR)
1531 cls_sess = iscsi_session_setup(&qla4xxx_iscsi_transport, qla_ep->host,
1532 cmds_max, sizeof(struct ddb_entry),
1533 sizeof(struct ql4_task_data),
1534 initial_cmdsn, ddb_index);
1538 sess = cls_sess->dd_data;
1539 ddb_entry = sess->dd_data;
1540 ddb_entry->fw_ddb_index = ddb_index;
1541 ddb_entry->fw_ddb_device_state = DDB_DS_NO_CONNECTION_ACTIVE;
1543 ddb_entry->sess = cls_sess;
1544 ddb_entry->unblock_sess = qla4xxx_unblock_ddb;
1545 ddb_entry->ddb_change = qla4xxx_ddb_change;
1546 cls_sess->recovery_tmo = ql4xsess_recovery_tmo;
1547 ha->fw_ddb_index_map[ddb_entry->fw_ddb_index] = ddb_entry;
1553 static void qla4xxx_session_destroy(struct iscsi_cls_session *cls_sess)
1555 struct iscsi_session *sess;
1556 struct ddb_entry *ddb_entry;
1557 struct scsi_qla_host *ha;
1558 unsigned long flags;
1560 DEBUG2(printk(KERN_INFO "Func: %s\n", __func__));
1561 sess = cls_sess->dd_data;
1562 ddb_entry = sess->dd_data;
1565 qla4xxx_clear_ddb_entry(ha, ddb_entry->fw_ddb_index);
1567 spin_lock_irqsave(&ha->hardware_lock, flags);
1568 qla4xxx_free_ddb(ha, ddb_entry);
1569 spin_unlock_irqrestore(&ha->hardware_lock, flags);
1570 iscsi_session_teardown(cls_sess);
1573 static struct iscsi_cls_conn *
1574 qla4xxx_conn_create(struct iscsi_cls_session *cls_sess, uint32_t conn_idx)
1576 struct iscsi_cls_conn *cls_conn;
1577 struct iscsi_session *sess;
1578 struct ddb_entry *ddb_entry;
1580 DEBUG2(printk(KERN_INFO "Func: %s\n", __func__));
1581 cls_conn = iscsi_conn_setup(cls_sess, sizeof(struct qla_conn),
1586 sess = cls_sess->dd_data;
1587 ddb_entry = sess->dd_data;
1588 ddb_entry->conn = cls_conn;
1593 static int qla4xxx_conn_bind(struct iscsi_cls_session *cls_session,
1594 struct iscsi_cls_conn *cls_conn,
1595 uint64_t transport_fd, int is_leading)
1597 struct iscsi_conn *conn;
1598 struct qla_conn *qla_conn;
1599 struct iscsi_endpoint *ep;
1601 DEBUG2(printk(KERN_INFO "Func: %s\n", __func__));
1603 if (iscsi_conn_bind(cls_session, cls_conn, is_leading))
1605 ep = iscsi_lookup_endpoint(transport_fd);
1606 conn = cls_conn->dd_data;
1607 qla_conn = conn->dd_data;
1608 qla_conn->qla_ep = ep->dd_data;
1612 static int qla4xxx_conn_start(struct iscsi_cls_conn *cls_conn)
1614 struct iscsi_cls_session *cls_sess = iscsi_conn_to_session(cls_conn);
1615 struct iscsi_session *sess;
1616 struct ddb_entry *ddb_entry;
1617 struct scsi_qla_host *ha;
1618 struct dev_db_entry *fw_ddb_entry = NULL;
1619 dma_addr_t fw_ddb_entry_dma;
1620 uint32_t mbx_sts = 0;
1622 int status = QLA_SUCCESS;
1624 DEBUG2(printk(KERN_INFO "Func: %s\n", __func__));
1625 sess = cls_sess->dd_data;
1626 ddb_entry = sess->dd_data;
1629 /* Check if we have matching FW DDB, if yes then do not
1630 * login to this target. This could cause target to logout previous
1633 ret = qla4xxx_match_fwdb_session(ha, cls_conn);
1634 if (ret == QLA_SUCCESS) {
1635 ql4_printk(KERN_INFO, ha,
1636 "Session already exist in FW.\n");
1638 goto exit_conn_start;
1641 fw_ddb_entry = dma_alloc_coherent(&ha->pdev->dev, sizeof(*fw_ddb_entry),
1642 &fw_ddb_entry_dma, GFP_KERNEL);
1643 if (!fw_ddb_entry) {
1644 ql4_printk(KERN_ERR, ha,
1645 "%s: Unable to allocate dma buffer\n", __func__);
1647 goto exit_conn_start;
1650 ret = qla4xxx_set_param_ddbentry(ha, ddb_entry, cls_conn, &mbx_sts);
1652 /* If iscsid is stopped and started then no need to do
1653 * set param again since ddb state will be already
1654 * active and FW does not allow set ddb to an
1658 if (ddb_entry->fw_ddb_device_state ==
1659 DDB_DS_SESSION_ACTIVE) {
1660 ddb_entry->unblock_sess(ddb_entry->sess);
1661 goto exit_set_param;
1664 ql4_printk(KERN_ERR, ha, "%s: Failed set param for index[%d]\n",
1665 __func__, ddb_entry->fw_ddb_index);
1666 goto exit_conn_start;
1669 status = qla4xxx_conn_open(ha, ddb_entry->fw_ddb_index);
1670 if (status == QLA_ERROR) {
1671 ql4_printk(KERN_ERR, ha, "%s: Login failed: %s\n", __func__,
1674 goto exit_conn_start;
1677 if (ddb_entry->fw_ddb_device_state == DDB_DS_NO_CONNECTION_ACTIVE)
1678 ddb_entry->fw_ddb_device_state = DDB_DS_LOGIN_IN_PROCESS;
1680 DEBUG2(printk(KERN_INFO "%s: DDB state [%d]\n", __func__,
1681 ddb_entry->fw_ddb_device_state));
1688 dma_free_coherent(&ha->pdev->dev, sizeof(*fw_ddb_entry),
1689 fw_ddb_entry, fw_ddb_entry_dma);
1693 static void qla4xxx_conn_destroy(struct iscsi_cls_conn *cls_conn)
1695 struct iscsi_cls_session *cls_sess = iscsi_conn_to_session(cls_conn);
1696 struct iscsi_session *sess;
1697 struct scsi_qla_host *ha;
1698 struct ddb_entry *ddb_entry;
1701 DEBUG2(printk(KERN_INFO "Func: %s\n", __func__));
1702 sess = cls_sess->dd_data;
1703 ddb_entry = sess->dd_data;
1706 options = LOGOUT_OPTION_CLOSE_SESSION;
1707 if (qla4xxx_session_logout_ddb(ha, ddb_entry, options) == QLA_ERROR)
1708 ql4_printk(KERN_ERR, ha, "%s: Logout failed\n", __func__);
1711 static void qla4xxx_task_work(struct work_struct *wdata)
1713 struct ql4_task_data *task_data;
1714 struct scsi_qla_host *ha;
1715 struct passthru_status *sts;
1716 struct iscsi_task *task;
1717 struct iscsi_hdr *hdr;
1720 struct iscsi_conn *conn;
1724 task_data = container_of(wdata, struct ql4_task_data, task_work);
1726 task = task_data->task;
1727 sts = &task_data->sts;
1728 hdr_len = sizeof(struct iscsi_hdr);
1730 DEBUG3(printk(KERN_INFO "Status returned\n"));
1731 DEBUG3(qla4xxx_dump_buffer(sts, 64));
1732 DEBUG3(printk(KERN_INFO "Response buffer"));
1733 DEBUG3(qla4xxx_dump_buffer(task_data->resp_buffer, 64));
1737 switch (sts->completionStatus) {
1738 case PASSTHRU_STATUS_COMPLETE:
1739 hdr = (struct iscsi_hdr *)task_data->resp_buffer;
1740 /* Assign back the itt in hdr, until we use the PREASSIGN_TAG */
1743 data = task_data->resp_buffer + hdr_len;
1744 data_len = task_data->resp_len - hdr_len;
1745 iscsi_complete_pdu(conn, hdr, data, data_len);
1748 ql4_printk(KERN_ERR, ha, "Passthru failed status = 0x%x\n",
1749 sts->completionStatus);
1755 static int qla4xxx_alloc_pdu(struct iscsi_task *task, uint8_t opcode)
1757 struct ql4_task_data *task_data;
1758 struct iscsi_session *sess;
1759 struct ddb_entry *ddb_entry;
1760 struct scsi_qla_host *ha;
1763 sess = task->conn->session;
1764 ddb_entry = sess->dd_data;
1766 task_data = task->dd_data;
1767 memset(task_data, 0, sizeof(struct ql4_task_data));
1770 ql4_printk(KERN_INFO, ha,
1771 "%s: SCSI Commands not implemented\n", __func__);
1775 hdr_len = sizeof(struct iscsi_hdr);
1777 task_data->task = task;
1779 if (task->data_count) {
1780 task_data->data_dma = dma_map_single(&ha->pdev->dev, task->data,
1785 DEBUG2(ql4_printk(KERN_INFO, ha, "%s: MaxRecvLen %u, iscsi hrd %d\n",
1786 __func__, task->conn->max_recv_dlength, hdr_len));
1788 task_data->resp_len = task->conn->max_recv_dlength + hdr_len;
1789 task_data->resp_buffer = dma_alloc_coherent(&ha->pdev->dev,
1790 task_data->resp_len,
1791 &task_data->resp_dma,
1793 if (!task_data->resp_buffer)
1794 goto exit_alloc_pdu;
1796 task_data->req_len = task->data_count + hdr_len;
1797 task_data->req_buffer = dma_alloc_coherent(&ha->pdev->dev,
1799 &task_data->req_dma,
1801 if (!task_data->req_buffer)
1802 goto exit_alloc_pdu;
1804 task->hdr = task_data->req_buffer;
1806 INIT_WORK(&task_data->task_work, qla4xxx_task_work);
1811 if (task_data->resp_buffer)
1812 dma_free_coherent(&ha->pdev->dev, task_data->resp_len,
1813 task_data->resp_buffer, task_data->resp_dma);
1815 if (task_data->req_buffer)
1816 dma_free_coherent(&ha->pdev->dev, task_data->req_len,
1817 task_data->req_buffer, task_data->req_dma);
1821 static void qla4xxx_task_cleanup(struct iscsi_task *task)
1823 struct ql4_task_data *task_data;
1824 struct iscsi_session *sess;
1825 struct ddb_entry *ddb_entry;
1826 struct scsi_qla_host *ha;
1829 hdr_len = sizeof(struct iscsi_hdr);
1830 sess = task->conn->session;
1831 ddb_entry = sess->dd_data;
1833 task_data = task->dd_data;
1835 if (task->data_count) {
1836 dma_unmap_single(&ha->pdev->dev, task_data->data_dma,
1837 task->data_count, PCI_DMA_TODEVICE);
1840 DEBUG2(ql4_printk(KERN_INFO, ha, "%s: MaxRecvLen %u, iscsi hrd %d\n",
1841 __func__, task->conn->max_recv_dlength, hdr_len));
1843 dma_free_coherent(&ha->pdev->dev, task_data->resp_len,
1844 task_data->resp_buffer, task_data->resp_dma);
1845 dma_free_coherent(&ha->pdev->dev, task_data->req_len,
1846 task_data->req_buffer, task_data->req_dma);
1850 static int qla4xxx_task_xmit(struct iscsi_task *task)
1852 struct scsi_cmnd *sc = task->sc;
1853 struct iscsi_session *sess = task->conn->session;
1854 struct ddb_entry *ddb_entry = sess->dd_data;
1855 struct scsi_qla_host *ha = ddb_entry->ha;
1858 return qla4xxx_send_passthru0(task);
1860 ql4_printk(KERN_INFO, ha, "%s: scsi cmd xmit not implemented\n",
1865 static void qla4xxx_copy_fwddb_param(struct scsi_qla_host *ha,
1866 struct dev_db_entry *fw_ddb_entry,
1867 struct iscsi_cls_session *cls_sess,
1868 struct iscsi_cls_conn *cls_conn)
1871 struct iscsi_session *sess;
1872 struct ddb_entry *ddb_entry;
1873 struct iscsi_conn *conn;
1874 char ip_addr[DDB_IPADDR_LEN];
1875 uint16_t options = 0;
1877 sess = cls_sess->dd_data;
1878 ddb_entry = sess->dd_data;
1879 conn = cls_conn->dd_data;
1881 ddb_entry->chap_tbl_idx = le16_to_cpu(fw_ddb_entry->chap_tbl_idx);
1883 conn->max_recv_dlength = BYTE_UNITS *
1884 le16_to_cpu(fw_ddb_entry->iscsi_max_rcv_data_seg_len);
1886 conn->max_xmit_dlength = BYTE_UNITS *
1887 le16_to_cpu(fw_ddb_entry->iscsi_max_snd_data_seg_len);
1889 sess->initial_r2t_en =
1890 (BIT_10 & le16_to_cpu(fw_ddb_entry->iscsi_options));
1892 sess->max_r2t = le16_to_cpu(fw_ddb_entry->iscsi_max_outsnd_r2t);
1894 sess->imm_data_en = (BIT_11 & le16_to_cpu(fw_ddb_entry->iscsi_options));
1896 sess->first_burst = BYTE_UNITS *
1897 le16_to_cpu(fw_ddb_entry->iscsi_first_burst_len);
1899 sess->max_burst = BYTE_UNITS *
1900 le16_to_cpu(fw_ddb_entry->iscsi_max_burst_len);
1902 sess->time2wait = le16_to_cpu(fw_ddb_entry->iscsi_def_time2wait);
1904 sess->time2retain = le16_to_cpu(fw_ddb_entry->iscsi_def_time2retain);
1906 conn->persistent_port = le16_to_cpu(fw_ddb_entry->port);
1908 sess->tpgt = le32_to_cpu(fw_ddb_entry->tgt_portal_grp);
1910 options = le16_to_cpu(fw_ddb_entry->options);
1911 if (options & DDB_OPT_IPV6_DEVICE)
1912 sprintf(ip_addr, "%pI6", fw_ddb_entry->ip_addr);
1914 sprintf(ip_addr, "%pI4", fw_ddb_entry->ip_addr);
1916 iscsi_set_param(cls_conn, ISCSI_PARAM_TARGET_NAME,
1917 (char *)fw_ddb_entry->iscsi_name, buflen);
1918 iscsi_set_param(cls_conn, ISCSI_PARAM_INITIATOR_NAME,
1919 (char *)ha->name_string, buflen);
1920 iscsi_set_param(cls_conn, ISCSI_PARAM_PERSISTENT_ADDRESS,
1921 (char *)ip_addr, buflen);
1922 iscsi_set_param(cls_conn, ISCSI_PARAM_TARGET_ALIAS,
1923 (char *)fw_ddb_entry->iscsi_alias, buflen);
1926 void qla4xxx_update_session_conn_fwddb_param(struct scsi_qla_host *ha,
1927 struct ddb_entry *ddb_entry)
1929 struct iscsi_cls_session *cls_sess;
1930 struct iscsi_cls_conn *cls_conn;
1932 dma_addr_t fw_ddb_entry_dma;
1933 struct dev_db_entry *fw_ddb_entry;
1935 fw_ddb_entry = dma_alloc_coherent(&ha->pdev->dev, sizeof(*fw_ddb_entry),
1936 &fw_ddb_entry_dma, GFP_KERNEL);
1937 if (!fw_ddb_entry) {
1938 ql4_printk(KERN_ERR, ha,
1939 "%s: Unable to allocate dma buffer\n", __func__);
1940 goto exit_session_conn_fwddb_param;
1943 if (qla4xxx_get_fwddb_entry(ha, ddb_entry->fw_ddb_index, fw_ddb_entry,
1944 fw_ddb_entry_dma, NULL, NULL, &ddb_state,
1945 NULL, NULL, NULL) == QLA_ERROR) {
1946 DEBUG2(ql4_printk(KERN_ERR, ha, "scsi%ld: %s: failed "
1947 "get_ddb_entry for fw_ddb_index %d\n",
1948 ha->host_no, __func__,
1949 ddb_entry->fw_ddb_index));
1950 goto exit_session_conn_fwddb_param;
1953 cls_sess = ddb_entry->sess;
1955 cls_conn = ddb_entry->conn;
1958 qla4xxx_copy_fwddb_param(ha, fw_ddb_entry, cls_sess, cls_conn);
1960 exit_session_conn_fwddb_param:
1962 dma_free_coherent(&ha->pdev->dev, sizeof(*fw_ddb_entry),
1963 fw_ddb_entry, fw_ddb_entry_dma);
1966 void qla4xxx_update_session_conn_param(struct scsi_qla_host *ha,
1967 struct ddb_entry *ddb_entry)
1969 struct iscsi_cls_session *cls_sess;
1970 struct iscsi_cls_conn *cls_conn;
1971 struct iscsi_session *sess;
1972 struct iscsi_conn *conn;
1974 dma_addr_t fw_ddb_entry_dma;
1975 struct dev_db_entry *fw_ddb_entry;
1977 fw_ddb_entry = dma_alloc_coherent(&ha->pdev->dev, sizeof(*fw_ddb_entry),
1978 &fw_ddb_entry_dma, GFP_KERNEL);
1979 if (!fw_ddb_entry) {
1980 ql4_printk(KERN_ERR, ha,
1981 "%s: Unable to allocate dma buffer\n", __func__);
1982 goto exit_session_conn_param;
1985 if (qla4xxx_get_fwddb_entry(ha, ddb_entry->fw_ddb_index, fw_ddb_entry,
1986 fw_ddb_entry_dma, NULL, NULL, &ddb_state,
1987 NULL, NULL, NULL) == QLA_ERROR) {
1988 DEBUG2(ql4_printk(KERN_ERR, ha, "scsi%ld: %s: failed "
1989 "get_ddb_entry for fw_ddb_index %d\n",
1990 ha->host_no, __func__,
1991 ddb_entry->fw_ddb_index));
1992 goto exit_session_conn_param;
1995 cls_sess = ddb_entry->sess;
1996 sess = cls_sess->dd_data;
1998 cls_conn = ddb_entry->conn;
1999 conn = cls_conn->dd_data;
2001 /* Update timers after login */
2002 ddb_entry->default_relogin_timeout =
2003 (le16_to_cpu(fw_ddb_entry->def_timeout) > LOGIN_TOV) &&
2004 (le16_to_cpu(fw_ddb_entry->def_timeout) < LOGIN_TOV * 10) ?
2005 le16_to_cpu(fw_ddb_entry->def_timeout) : LOGIN_TOV;
2006 ddb_entry->default_time2wait =
2007 le16_to_cpu(fw_ddb_entry->iscsi_def_time2wait);
2010 ddb_entry->chap_tbl_idx = le16_to_cpu(fw_ddb_entry->chap_tbl_idx);
2011 conn->max_recv_dlength = BYTE_UNITS *
2012 le16_to_cpu(fw_ddb_entry->iscsi_max_rcv_data_seg_len);
2014 conn->max_xmit_dlength = BYTE_UNITS *
2015 le16_to_cpu(fw_ddb_entry->iscsi_max_snd_data_seg_len);
2017 sess->initial_r2t_en =
2018 (BIT_10 & le16_to_cpu(fw_ddb_entry->iscsi_options));
2020 sess->max_r2t = le16_to_cpu(fw_ddb_entry->iscsi_max_outsnd_r2t);
2022 sess->imm_data_en = (BIT_11 & le16_to_cpu(fw_ddb_entry->iscsi_options));
2024 sess->first_burst = BYTE_UNITS *
2025 le16_to_cpu(fw_ddb_entry->iscsi_first_burst_len);
2027 sess->max_burst = BYTE_UNITS *
2028 le16_to_cpu(fw_ddb_entry->iscsi_max_burst_len);
2030 sess->time2wait = le16_to_cpu(fw_ddb_entry->iscsi_def_time2wait);
2032 sess->time2retain = le16_to_cpu(fw_ddb_entry->iscsi_def_time2retain);
2034 sess->tpgt = le32_to_cpu(fw_ddb_entry->tgt_portal_grp);
2036 memcpy(sess->initiatorname, ha->name_string,
2037 min(sizeof(ha->name_string), sizeof(sess->initiatorname)));
2039 iscsi_set_param(cls_conn, ISCSI_PARAM_TARGET_ALIAS,
2040 (char *)fw_ddb_entry->iscsi_alias, 0);
2042 exit_session_conn_param:
2044 dma_free_coherent(&ha->pdev->dev, sizeof(*fw_ddb_entry),
2045 fw_ddb_entry, fw_ddb_entry_dma);
2052 static void qla4xxx_start_timer(struct scsi_qla_host *ha, void *func,
2053 unsigned long interval)
2055 DEBUG(printk("scsi: %s: Starting timer thread for adapter %d\n",
2056 __func__, ha->host->host_no));
2057 init_timer(&ha->timer);
2058 ha->timer.expires = jiffies + interval * HZ;
2059 ha->timer.data = (unsigned long)ha;
2060 ha->timer.function = (void (*)(unsigned long))func;
2061 add_timer(&ha->timer);
2062 ha->timer_active = 1;
2065 static void qla4xxx_stop_timer(struct scsi_qla_host *ha)
2067 del_timer_sync(&ha->timer);
2068 ha->timer_active = 0;
2072 * qla4xxx_mark_device_missing - blocks the session
2073 * @cls_session: Pointer to the session to be blocked
2074 * @ddb_entry: Pointer to device database entry
2076 * This routine marks a device missing and close connection.
2078 void qla4xxx_mark_device_missing(struct iscsi_cls_session *cls_session)
2080 iscsi_block_session(cls_session);
2084 * qla4xxx_mark_all_devices_missing - mark all devices as missing.
2085 * @ha: Pointer to host adapter structure.
2087 * This routine marks a device missing and resets the relogin retry count.
2089 void qla4xxx_mark_all_devices_missing(struct scsi_qla_host *ha)
2091 iscsi_host_for_each_session(ha->host, qla4xxx_mark_device_missing);
2094 static struct srb* qla4xxx_get_new_srb(struct scsi_qla_host *ha,
2095 struct ddb_entry *ddb_entry,
2096 struct scsi_cmnd *cmd)
2100 srb = mempool_alloc(ha->srb_mempool, GFP_ATOMIC);
2104 kref_init(&srb->srb_ref);
2106 srb->ddb = ddb_entry;
2109 CMD_SP(cmd) = (void *)srb;
2114 static void qla4xxx_srb_free_dma(struct scsi_qla_host *ha, struct srb *srb)
2116 struct scsi_cmnd *cmd = srb->cmd;
2118 if (srb->flags & SRB_DMA_VALID) {
2119 scsi_dma_unmap(cmd);
2120 srb->flags &= ~SRB_DMA_VALID;
2125 void qla4xxx_srb_compl(struct kref *ref)
2127 struct srb *srb = container_of(ref, struct srb, srb_ref);
2128 struct scsi_cmnd *cmd = srb->cmd;
2129 struct scsi_qla_host *ha = srb->ha;
2131 qla4xxx_srb_free_dma(ha, srb);
2133 mempool_free(srb, ha->srb_mempool);
2135 cmd->scsi_done(cmd);
2139 * qla4xxx_queuecommand - scsi layer issues scsi command to driver.
2141 * @cmd: Pointer to Linux's SCSI command structure
2144 * This routine is invoked by Linux to send a SCSI command to the driver.
2145 * The mid-level driver tries to ensure that queuecommand never gets
2146 * invoked concurrently with itself or the interrupt handler (although
2147 * the interrupt handler may call this routine as part of request-
2148 * completion handling). Unfortunely, it sometimes calls the scheduler
2149 * in interrupt context which is a big NO! NO!.
2151 static int qla4xxx_queuecommand(struct Scsi_Host *host, struct scsi_cmnd *cmd)
2153 struct scsi_qla_host *ha = to_qla_host(host);
2154 struct ddb_entry *ddb_entry = cmd->device->hostdata;
2155 struct iscsi_cls_session *sess = ddb_entry->sess;
2159 if (test_bit(AF_EEH_BUSY, &ha->flags)) {
2160 if (test_bit(AF_PCI_CHANNEL_IO_PERM_FAILURE, &ha->flags))
2161 cmd->result = DID_NO_CONNECT << 16;
2163 cmd->result = DID_REQUEUE << 16;
2164 goto qc_fail_command;
2168 cmd->result = DID_IMM_RETRY << 16;
2169 goto qc_fail_command;
2172 rval = iscsi_session_chkready(sess);
2175 goto qc_fail_command;
2178 if (test_bit(DPC_RESET_HA_INTR, &ha->dpc_flags) ||
2179 test_bit(DPC_RESET_ACTIVE, &ha->dpc_flags) ||
2180 test_bit(DPC_RESET_HA, &ha->dpc_flags) ||
2181 test_bit(DPC_HA_UNRECOVERABLE, &ha->dpc_flags) ||
2182 test_bit(DPC_HA_NEED_QUIESCENT, &ha->dpc_flags) ||
2183 !test_bit(AF_ONLINE, &ha->flags) ||
2184 !test_bit(AF_LINK_UP, &ha->flags) ||
2185 test_bit(DPC_RESET_HA_FW_CONTEXT, &ha->dpc_flags))
2188 srb = qla4xxx_get_new_srb(ha, ddb_entry, cmd);
2192 rval = qla4xxx_send_command_to_isp(ha, srb);
2193 if (rval != QLA_SUCCESS)
2194 goto qc_host_busy_free_sp;
2198 qc_host_busy_free_sp:
2199 qla4xxx_srb_free_dma(ha, srb);
2200 mempool_free(srb, ha->srb_mempool);
2203 return SCSI_MLQUEUE_HOST_BUSY;
2206 cmd->scsi_done(cmd);
2212 * qla4xxx_mem_free - frees memory allocated to adapter
2213 * @ha: Pointer to host adapter structure.
2215 * Frees memory previously allocated by qla4xxx_mem_alloc
2217 static void qla4xxx_mem_free(struct scsi_qla_host *ha)
2220 dma_free_coherent(&ha->pdev->dev, ha->queues_len, ha->queues,
2226 ha->request_ring = NULL;
2227 ha->request_dma = 0;
2228 ha->response_ring = NULL;
2229 ha->response_dma = 0;
2230 ha->shadow_regs = NULL;
2231 ha->shadow_regs_dma = 0;
2233 /* Free srb pool. */
2234 if (ha->srb_mempool)
2235 mempool_destroy(ha->srb_mempool);
2237 ha->srb_mempool = NULL;
2239 if (ha->chap_dma_pool)
2240 dma_pool_destroy(ha->chap_dma_pool);
2243 vfree(ha->chap_list);
2244 ha->chap_list = NULL;
2246 if (ha->fw_ddb_dma_pool)
2247 dma_pool_destroy(ha->fw_ddb_dma_pool);
2249 /* release io space registers */
2250 if (is_qla8022(ha)) {
2253 (struct device_reg_82xx __iomem *)ha->nx_pcibase);
2256 pci_release_regions(ha->pdev);
2260 * qla4xxx_mem_alloc - allocates memory for use by adapter.
2261 * @ha: Pointer to host adapter structure
2263 * Allocates DMA memory for request and response queues. Also allocates memory
2266 static int qla4xxx_mem_alloc(struct scsi_qla_host *ha)
2268 unsigned long align;
2270 /* Allocate contiguous block of DMA memory for queues. */
2271 ha->queues_len = ((REQUEST_QUEUE_DEPTH * QUEUE_SIZE) +
2272 (RESPONSE_QUEUE_DEPTH * QUEUE_SIZE) +
2273 sizeof(struct shadow_regs) +
2275 (PAGE_SIZE - 1)) & ~(PAGE_SIZE - 1);
2276 ha->queues = dma_alloc_coherent(&ha->pdev->dev, ha->queues_len,
2277 &ha->queues_dma, GFP_KERNEL);
2278 if (ha->queues == NULL) {
2279 ql4_printk(KERN_WARNING, ha,
2280 "Memory Allocation failed - queues.\n");
2282 goto mem_alloc_error_exit;
2284 memset(ha->queues, 0, ha->queues_len);
2287 * As per RISC alignment requirements -- the bus-address must be a
2288 * multiple of the request-ring size (in bytes).
2291 if ((unsigned long)ha->queues_dma & (MEM_ALIGN_VALUE - 1))
2292 align = MEM_ALIGN_VALUE - ((unsigned long)ha->queues_dma &
2293 (MEM_ALIGN_VALUE - 1));
2295 /* Update request and response queue pointers. */
2296 ha->request_dma = ha->queues_dma + align;
2297 ha->request_ring = (struct queue_entry *) (ha->queues + align);
2298 ha->response_dma = ha->queues_dma + align +
2299 (REQUEST_QUEUE_DEPTH * QUEUE_SIZE);
2300 ha->response_ring = (struct queue_entry *) (ha->queues + align +
2301 (REQUEST_QUEUE_DEPTH *
2303 ha->shadow_regs_dma = ha->queues_dma + align +
2304 (REQUEST_QUEUE_DEPTH * QUEUE_SIZE) +
2305 (RESPONSE_QUEUE_DEPTH * QUEUE_SIZE);
2306 ha->shadow_regs = (struct shadow_regs *) (ha->queues + align +
2307 (REQUEST_QUEUE_DEPTH *
2309 (RESPONSE_QUEUE_DEPTH *
2312 /* Allocate memory for srb pool. */
2313 ha->srb_mempool = mempool_create(SRB_MIN_REQ, mempool_alloc_slab,
2314 mempool_free_slab, srb_cachep);
2315 if (ha->srb_mempool == NULL) {
2316 ql4_printk(KERN_WARNING, ha,
2317 "Memory Allocation failed - SRB Pool.\n");
2319 goto mem_alloc_error_exit;
2322 ha->chap_dma_pool = dma_pool_create("ql4_chap", &ha->pdev->dev,
2323 CHAP_DMA_BLOCK_SIZE, 8, 0);
2325 if (ha->chap_dma_pool == NULL) {
2326 ql4_printk(KERN_WARNING, ha,
2327 "%s: chap_dma_pool allocation failed..\n", __func__);
2328 goto mem_alloc_error_exit;
2331 ha->fw_ddb_dma_pool = dma_pool_create("ql4_fw_ddb", &ha->pdev->dev,
2332 DDB_DMA_BLOCK_SIZE, 8, 0);
2334 if (ha->fw_ddb_dma_pool == NULL) {
2335 ql4_printk(KERN_WARNING, ha,
2336 "%s: fw_ddb_dma_pool allocation failed..\n",
2338 goto mem_alloc_error_exit;
2343 mem_alloc_error_exit:
2344 qla4xxx_mem_free(ha);
2349 * qla4_8xxx_check_temp - Check the ISP82XX temperature.
2350 * @ha: adapter block pointer.
2352 * Note: The caller should not hold the idc lock.
2354 static int qla4_8xxx_check_temp(struct scsi_qla_host *ha)
2356 uint32_t temp, temp_state, temp_val;
2357 int status = QLA_SUCCESS;
2359 temp = qla4_8xxx_rd_32(ha, CRB_TEMP_STATE);
2361 temp_state = qla82xx_get_temp_state(temp);
2362 temp_val = qla82xx_get_temp_val(temp);
2364 if (temp_state == QLA82XX_TEMP_PANIC) {
2365 ql4_printk(KERN_WARNING, ha, "Device temperature %d degrees C"
2366 " exceeds maximum allowed. Hardware has been shut"
2367 " down.\n", temp_val);
2369 } else if (temp_state == QLA82XX_TEMP_WARN) {
2370 if (ha->temperature == QLA82XX_TEMP_NORMAL)
2371 ql4_printk(KERN_WARNING, ha, "Device temperature %d"
2372 " degrees C exceeds operating range."
2373 " Immediate action needed.\n", temp_val);
2375 if (ha->temperature == QLA82XX_TEMP_WARN)
2376 ql4_printk(KERN_INFO, ha, "Device temperature is"
2377 " now %d degrees C in normal range.\n",
2380 ha->temperature = temp_state;
2385 * qla4_8xxx_check_fw_alive - Check firmware health
2386 * @ha: Pointer to host adapter structure.
2388 * Context: Interrupt
2390 static int qla4_8xxx_check_fw_alive(struct scsi_qla_host *ha)
2392 uint32_t fw_heartbeat_counter;
2393 int status = QLA_SUCCESS;
2395 fw_heartbeat_counter = qla4_8xxx_rd_32(ha, QLA82XX_PEG_ALIVE_COUNTER);
2396 /* If PEG_ALIVE_COUNTER is 0xffffffff, AER/EEH is in progress, ignore */
2397 if (fw_heartbeat_counter == 0xffffffff) {
2398 DEBUG2(printk(KERN_WARNING "scsi%ld: %s: Device in frozen "
2399 "state, QLA82XX_PEG_ALIVE_COUNTER is 0xffffffff\n",
2400 ha->host_no, __func__));
2404 if (ha->fw_heartbeat_counter == fw_heartbeat_counter) {
2405 ha->seconds_since_last_heartbeat++;
2406 /* FW not alive after 2 seconds */
2407 if (ha->seconds_since_last_heartbeat == 2) {
2408 ha->seconds_since_last_heartbeat = 0;
2410 ql4_printk(KERN_INFO, ha,
2411 "scsi(%ld): %s, Dumping hw/fw registers:\n "
2412 " PEG_HALT_STATUS1: 0x%x, PEG_HALT_STATUS2:"
2413 " 0x%x,\n PEG_NET_0_PC: 0x%x, PEG_NET_1_PC:"
2414 " 0x%x,\n PEG_NET_2_PC: 0x%x, PEG_NET_3_PC:"
2415 " 0x%x,\n PEG_NET_4_PC: 0x%x\n",
2416 ha->host_no, __func__,
2418 QLA82XX_PEG_HALT_STATUS1),
2420 QLA82XX_PEG_HALT_STATUS2),
2421 qla4_8xxx_rd_32(ha, QLA82XX_CRB_PEG_NET_0 +
2423 qla4_8xxx_rd_32(ha, QLA82XX_CRB_PEG_NET_1 +
2425 qla4_8xxx_rd_32(ha, QLA82XX_CRB_PEG_NET_2 +
2427 qla4_8xxx_rd_32(ha, QLA82XX_CRB_PEG_NET_3 +
2429 qla4_8xxx_rd_32(ha, QLA82XX_CRB_PEG_NET_4 +
2434 ha->seconds_since_last_heartbeat = 0;
2436 ha->fw_heartbeat_counter = fw_heartbeat_counter;
2441 * qla4_8xxx_watchdog - Poll dev state
2442 * @ha: Pointer to host adapter structure.
2444 * Context: Interrupt
2446 void qla4_8xxx_watchdog(struct scsi_qla_host *ha)
2448 uint32_t dev_state, halt_status;
2450 /* don't poll if reset is going on */
2451 if (!(test_bit(DPC_RESET_ACTIVE, &ha->dpc_flags) ||
2452 test_bit(DPC_RESET_HA, &ha->dpc_flags) ||
2453 test_bit(DPC_RETRY_RESET_HA, &ha->dpc_flags))) {
2454 dev_state = qla4_8xxx_rd_32(ha, QLA82XX_CRB_DEV_STATE);
2456 if (qla4_8xxx_check_temp(ha)) {
2457 ql4_printk(KERN_INFO, ha, "disabling pause"
2458 " transmit on port 0 & 1.\n");
2459 qla4_8xxx_wr_32(ha, QLA82XX_CRB_NIU + 0x98,
2460 CRB_NIU_XG_PAUSE_CTL_P0 |
2461 CRB_NIU_XG_PAUSE_CTL_P1);
2462 set_bit(DPC_HA_UNRECOVERABLE, &ha->dpc_flags);
2463 qla4xxx_wake_dpc(ha);
2464 } else if (dev_state == QLA82XX_DEV_NEED_RESET &&
2465 !test_bit(DPC_RESET_HA, &ha->dpc_flags)) {
2466 if (!ql4xdontresethba) {
2467 ql4_printk(KERN_INFO, ha, "%s: HW State: "
2468 "NEED RESET!\n", __func__);
2469 set_bit(DPC_RESET_HA, &ha->dpc_flags);
2470 qla4xxx_wake_dpc(ha);
2472 } else if (dev_state == QLA82XX_DEV_NEED_QUIESCENT &&
2473 !test_bit(DPC_HA_NEED_QUIESCENT, &ha->dpc_flags)) {
2474 ql4_printk(KERN_INFO, ha, "%s: HW State: NEED QUIES!\n",
2476 set_bit(DPC_HA_NEED_QUIESCENT, &ha->dpc_flags);
2477 qla4xxx_wake_dpc(ha);
2479 /* Check firmware health */
2480 if (qla4_8xxx_check_fw_alive(ha)) {
2481 ql4_printk(KERN_INFO, ha, "disabling pause"
2482 " transmit on port 0 & 1.\n");
2483 qla4_8xxx_wr_32(ha, QLA82XX_CRB_NIU + 0x98,
2484 CRB_NIU_XG_PAUSE_CTL_P0 |
2485 CRB_NIU_XG_PAUSE_CTL_P1);
2486 halt_status = qla4_8xxx_rd_32(ha,
2487 QLA82XX_PEG_HALT_STATUS1);
2489 if (QLA82XX_FWERROR_CODE(halt_status) == 0x67)
2490 ql4_printk(KERN_ERR, ha, "%s:"
2491 " Firmware aborted with"
2492 " error code 0x00006700."
2493 " Device is being reset\n",
2496 /* Since we cannot change dev_state in interrupt
2497 * context, set appropriate DPC flag then wakeup
2499 if (halt_status & HALT_STATUS_UNRECOVERABLE)
2500 set_bit(DPC_HA_UNRECOVERABLE,
2503 ql4_printk(KERN_INFO, ha, "%s: detect "
2504 "abort needed!\n", __func__);
2505 set_bit(DPC_RESET_HA, &ha->dpc_flags);
2507 qla4xxx_mailbox_premature_completion(ha);
2508 qla4xxx_wake_dpc(ha);
2514 static void qla4xxx_check_relogin_flash_ddb(struct iscsi_cls_session *cls_sess)
2516 struct iscsi_session *sess;
2517 struct ddb_entry *ddb_entry;
2518 struct scsi_qla_host *ha;
2520 sess = cls_sess->dd_data;
2521 ddb_entry = sess->dd_data;
2524 if (!(ddb_entry->ddb_type == FLASH_DDB))
2527 if (adapter_up(ha) && !test_bit(DF_RELOGIN, &ddb_entry->flags) &&
2528 !iscsi_is_session_online(cls_sess)) {
2529 if (atomic_read(&ddb_entry->retry_relogin_timer) !=
2531 if (atomic_read(&ddb_entry->retry_relogin_timer) ==
2533 atomic_set(&ddb_entry->retry_relogin_timer,
2535 set_bit(DPC_RELOGIN_DEVICE, &ha->dpc_flags);
2536 set_bit(DF_RELOGIN, &ddb_entry->flags);
2537 DEBUG2(ql4_printk(KERN_INFO, ha,
2538 "%s: index [%d] login device\n",
2539 __func__, ddb_entry->fw_ddb_index));
2541 atomic_dec(&ddb_entry->retry_relogin_timer);
2545 /* Wait for relogin to timeout */
2546 if (atomic_read(&ddb_entry->relogin_timer) &&
2547 (atomic_dec_and_test(&ddb_entry->relogin_timer) != 0)) {
2549 * If the relogin times out and the device is
2550 * still NOT ONLINE then try and relogin again.
2552 if (!iscsi_is_session_online(cls_sess)) {
2553 /* Reset retry relogin timer */
2554 atomic_inc(&ddb_entry->relogin_retry_count);
2555 DEBUG2(ql4_printk(KERN_INFO, ha,
2556 "%s: index[%d] relogin timed out-retrying"
2557 " relogin (%d), retry (%d)\n", __func__,
2558 ddb_entry->fw_ddb_index,
2559 atomic_read(&ddb_entry->relogin_retry_count),
2560 ddb_entry->default_time2wait + 4));
2561 set_bit(DPC_RELOGIN_DEVICE, &ha->dpc_flags);
2562 atomic_set(&ddb_entry->retry_relogin_timer,
2563 ddb_entry->default_time2wait + 4);
2569 * qla4xxx_timer - checks every second for work to do.
2570 * @ha: Pointer to host adapter structure.
2572 static void qla4xxx_timer(struct scsi_qla_host *ha)
2577 iscsi_host_for_each_session(ha->host, qla4xxx_check_relogin_flash_ddb);
2579 /* If we are in the middle of AER/EEH processing
2580 * skip any processing and reschedule the timer
2582 if (test_bit(AF_EEH_BUSY, &ha->flags)) {
2583 mod_timer(&ha->timer, jiffies + HZ);
2587 /* Hardware read to trigger an EEH error during mailbox waits. */
2588 if (!pci_channel_offline(ha->pdev))
2589 pci_read_config_word(ha->pdev, PCI_VENDOR_ID, &w);
2591 if (is_qla8022(ha)) {
2592 qla4_8xxx_watchdog(ha);
2595 if (!is_qla8022(ha)) {
2596 /* Check for heartbeat interval. */
2597 if (ha->firmware_options & FWOPT_HEARTBEAT_ENABLE &&
2598 ha->heartbeat_interval != 0) {
2599 ha->seconds_since_last_heartbeat++;
2600 if (ha->seconds_since_last_heartbeat >
2601 ha->heartbeat_interval + 2)
2602 set_bit(DPC_RESET_HA, &ha->dpc_flags);
2606 /* Process any deferred work. */
2607 if (!list_empty(&ha->work_list))
2610 /* Wakeup the dpc routine for this adapter, if needed. */
2612 test_bit(DPC_RESET_HA, &ha->dpc_flags) ||
2613 test_bit(DPC_RETRY_RESET_HA, &ha->dpc_flags) ||
2614 test_bit(DPC_RELOGIN_DEVICE, &ha->dpc_flags) ||
2615 test_bit(DPC_RESET_HA_FW_CONTEXT, &ha->dpc_flags) ||
2616 test_bit(DPC_RESET_HA_INTR, &ha->dpc_flags) ||
2617 test_bit(DPC_GET_DHCP_IP_ADDR, &ha->dpc_flags) ||
2618 test_bit(DPC_LINK_CHANGED, &ha->dpc_flags) ||
2619 test_bit(DPC_HA_UNRECOVERABLE, &ha->dpc_flags) ||
2620 test_bit(DPC_HA_NEED_QUIESCENT, &ha->dpc_flags) ||
2621 test_bit(DPC_AEN, &ha->dpc_flags)) {
2622 DEBUG2(printk("scsi%ld: %s: scheduling dpc routine"
2623 " - dpc flags = 0x%lx\n",
2624 ha->host_no, __func__, ha->dpc_flags));
2625 qla4xxx_wake_dpc(ha);
2628 /* Reschedule timer thread to call us back in one second */
2629 mod_timer(&ha->timer, jiffies + HZ);
2631 DEBUG2(ha->seconds_since_last_intr++);
2635 * qla4xxx_cmd_wait - waits for all outstanding commands to complete
2636 * @ha: Pointer to host adapter structure.
2638 * This routine stalls the driver until all outstanding commands are returned.
2639 * Caller must release the Hardware Lock prior to calling this routine.
2641 static int qla4xxx_cmd_wait(struct scsi_qla_host *ha)
2644 unsigned long flags;
2645 struct scsi_cmnd *cmd;
2647 unsigned long wtime = jiffies + (WAIT_CMD_TOV * HZ);
2649 DEBUG2(ql4_printk(KERN_INFO, ha, "Wait up to %d seconds for cmds to "
2650 "complete\n", WAIT_CMD_TOV));
2652 while (!time_after_eq(jiffies, wtime)) {
2653 spin_lock_irqsave(&ha->hardware_lock, flags);
2654 /* Find a command that hasn't completed. */
2655 for (index = 0; index < ha->host->can_queue; index++) {
2656 cmd = scsi_host_find_tag(ha->host, index);
2658 * We cannot just check if the index is valid,
2659 * becase if we are run from the scsi eh, then
2660 * the scsi/block layer is going to prevent
2661 * the tag from being released.
2663 if (cmd != NULL && CMD_SP(cmd))
2666 spin_unlock_irqrestore(&ha->hardware_lock, flags);
2668 /* If No Commands are pending, wait is complete */
2669 if (index == ha->host->can_queue)
2674 /* If we timed out on waiting for commands to come back
2679 int qla4xxx_hw_reset(struct scsi_qla_host *ha)
2681 uint32_t ctrl_status;
2682 unsigned long flags = 0;
2684 DEBUG2(printk(KERN_ERR "scsi%ld: %s\n", ha->host_no, __func__));
2686 if (ql4xxx_lock_drvr_wait(ha) != QLA_SUCCESS)
2689 spin_lock_irqsave(&ha->hardware_lock, flags);
2692 * If the SCSI Reset Interrupt bit is set, clear it.
2693 * Otherwise, the Soft Reset won't work.
2695 ctrl_status = readw(&ha->reg->ctrl_status);
2696 if ((ctrl_status & CSR_SCSI_RESET_INTR) != 0)
2697 writel(set_rmask(CSR_SCSI_RESET_INTR), &ha->reg->ctrl_status);
2699 /* Issue Soft Reset */
2700 writel(set_rmask(CSR_SOFT_RESET), &ha->reg->ctrl_status);
2701 readl(&ha->reg->ctrl_status);
2703 spin_unlock_irqrestore(&ha->hardware_lock, flags);
2708 * qla4xxx_soft_reset - performs soft reset.
2709 * @ha: Pointer to host adapter structure.
2711 int qla4xxx_soft_reset(struct scsi_qla_host *ha)
2713 uint32_t max_wait_time;
2714 unsigned long flags = 0;
2716 uint32_t ctrl_status;
2718 status = qla4xxx_hw_reset(ha);
2719 if (status != QLA_SUCCESS)
2723 /* Wait until the Network Reset Intr bit is cleared */
2724 max_wait_time = RESET_INTR_TOV;
2726 spin_lock_irqsave(&ha->hardware_lock, flags);
2727 ctrl_status = readw(&ha->reg->ctrl_status);
2728 spin_unlock_irqrestore(&ha->hardware_lock, flags);
2730 if ((ctrl_status & CSR_NET_RESET_INTR) == 0)
2734 } while ((--max_wait_time));
2736 if ((ctrl_status & CSR_NET_RESET_INTR) != 0) {
2737 DEBUG2(printk(KERN_WARNING
2738 "scsi%ld: Network Reset Intr not cleared by "
2739 "Network function, clearing it now!\n",
2741 spin_lock_irqsave(&ha->hardware_lock, flags);
2742 writel(set_rmask(CSR_NET_RESET_INTR), &ha->reg->ctrl_status);
2743 readl(&ha->reg->ctrl_status);
2744 spin_unlock_irqrestore(&ha->hardware_lock, flags);
2747 /* Wait until the firmware tells us the Soft Reset is done */
2748 max_wait_time = SOFT_RESET_TOV;
2750 spin_lock_irqsave(&ha->hardware_lock, flags);
2751 ctrl_status = readw(&ha->reg->ctrl_status);
2752 spin_unlock_irqrestore(&ha->hardware_lock, flags);
2754 if ((ctrl_status & CSR_SOFT_RESET) == 0) {
2755 status = QLA_SUCCESS;
2760 } while ((--max_wait_time));
2763 * Also, make sure that the SCSI Reset Interrupt bit has been cleared
2764 * after the soft reset has taken place.
2766 spin_lock_irqsave(&ha->hardware_lock, flags);
2767 ctrl_status = readw(&ha->reg->ctrl_status);
2768 if ((ctrl_status & CSR_SCSI_RESET_INTR) != 0) {
2769 writel(set_rmask(CSR_SCSI_RESET_INTR), &ha->reg->ctrl_status);
2770 readl(&ha->reg->ctrl_status);
2772 spin_unlock_irqrestore(&ha->hardware_lock, flags);
2774 /* If soft reset fails then most probably the bios on other
2775 * function is also enabled.
2776 * Since the initialization is sequential the other fn
2777 * wont be able to acknowledge the soft reset.
2778 * Issue a force soft reset to workaround this scenario.
2780 if (max_wait_time == 0) {
2781 /* Issue Force Soft Reset */
2782 spin_lock_irqsave(&ha->hardware_lock, flags);
2783 writel(set_rmask(CSR_FORCE_SOFT_RESET), &ha->reg->ctrl_status);
2784 readl(&ha->reg->ctrl_status);
2785 spin_unlock_irqrestore(&ha->hardware_lock, flags);
2786 /* Wait until the firmware tells us the Soft Reset is done */
2787 max_wait_time = SOFT_RESET_TOV;
2789 spin_lock_irqsave(&ha->hardware_lock, flags);
2790 ctrl_status = readw(&ha->reg->ctrl_status);
2791 spin_unlock_irqrestore(&ha->hardware_lock, flags);
2793 if ((ctrl_status & CSR_FORCE_SOFT_RESET) == 0) {
2794 status = QLA_SUCCESS;
2799 } while ((--max_wait_time));
2806 * qla4xxx_abort_active_cmds - returns all outstanding i/o requests to O.S.
2807 * @ha: Pointer to host adapter structure.
2808 * @res: returned scsi status
2810 * This routine is called just prior to a HARD RESET to return all
2811 * outstanding commands back to the Operating System.
2812 * Caller should make sure that the following locks are released
2813 * before this calling routine: Hardware lock, and io_request_lock.
2815 static void qla4xxx_abort_active_cmds(struct scsi_qla_host *ha, int res)
2819 unsigned long flags;
2821 spin_lock_irqsave(&ha->hardware_lock, flags);
2822 for (i = 0; i < ha->host->can_queue; i++) {
2823 srb = qla4xxx_del_from_active_array(ha, i);
2825 srb->cmd->result = res;
2826 kref_put(&srb->srb_ref, qla4xxx_srb_compl);
2829 spin_unlock_irqrestore(&ha->hardware_lock, flags);
2832 void qla4xxx_dead_adapter_cleanup(struct scsi_qla_host *ha)
2834 clear_bit(AF_ONLINE, &ha->flags);
2836 /* Disable the board */
2837 ql4_printk(KERN_INFO, ha, "Disabling the board\n");
2839 qla4xxx_abort_active_cmds(ha, DID_NO_CONNECT << 16);
2840 qla4xxx_mark_all_devices_missing(ha);
2841 clear_bit(AF_INIT_DONE, &ha->flags);
2844 static void qla4xxx_fail_session(struct iscsi_cls_session *cls_session)
2846 struct iscsi_session *sess;
2847 struct ddb_entry *ddb_entry;
2849 sess = cls_session->dd_data;
2850 ddb_entry = sess->dd_data;
2851 ddb_entry->fw_ddb_device_state = DDB_DS_SESSION_FAILED;
2853 if (ddb_entry->ddb_type == FLASH_DDB)
2854 iscsi_block_session(ddb_entry->sess);
2856 iscsi_session_failure(cls_session->dd_data,
2857 ISCSI_ERR_CONN_FAILED);
2861 * qla4xxx_recover_adapter - recovers adapter after a fatal error
2862 * @ha: Pointer to host adapter structure.
2864 static int qla4xxx_recover_adapter(struct scsi_qla_host *ha)
2866 int status = QLA_ERROR;
2867 uint8_t reset_chip = 0;
2871 /* Stall incoming I/O until we are done */
2872 scsi_block_requests(ha->host);
2873 clear_bit(AF_ONLINE, &ha->flags);
2874 clear_bit(AF_LINK_UP, &ha->flags);
2876 DEBUG2(ql4_printk(KERN_INFO, ha, "%s: adapter OFFLINE\n", __func__));
2878 set_bit(DPC_RESET_ACTIVE, &ha->dpc_flags);
2880 iscsi_host_for_each_session(ha->host, qla4xxx_fail_session);
2882 if (test_bit(DPC_RESET_HA, &ha->dpc_flags))
2885 /* For the DPC_RESET_HA_INTR case (ISP-4xxx specific)
2886 * do not reset adapter, jump to initialize_adapter */
2887 if (test_bit(DPC_RESET_HA_INTR, &ha->dpc_flags)) {
2888 status = QLA_SUCCESS;
2889 goto recover_ha_init_adapter;
2892 /* For the ISP-82xx adapter, issue a stop_firmware if invoked
2893 * from eh_host_reset or ioctl module */
2894 if (is_qla8022(ha) && !reset_chip &&
2895 test_bit(DPC_RESET_HA_FW_CONTEXT, &ha->dpc_flags)) {
2897 DEBUG2(ql4_printk(KERN_INFO, ha,
2898 "scsi%ld: %s - Performing stop_firmware...\n",
2899 ha->host_no, __func__));
2900 status = ha->isp_ops->reset_firmware(ha);
2901 if (status == QLA_SUCCESS) {
2902 if (!test_bit(AF_FW_RECOVERY, &ha->flags))
2903 qla4xxx_cmd_wait(ha);
2904 ha->isp_ops->disable_intrs(ha);
2905 qla4xxx_process_aen(ha, FLUSH_DDB_CHANGED_AENS);
2906 qla4xxx_abort_active_cmds(ha, DID_RESET << 16);
2908 /* If the stop_firmware fails then
2909 * reset the entire chip */
2911 clear_bit(DPC_RESET_HA_FW_CONTEXT, &ha->dpc_flags);
2912 set_bit(DPC_RESET_HA, &ha->dpc_flags);
2916 /* Issue full chip reset if recovering from a catastrophic error,
2917 * or if stop_firmware fails for ISP-82xx.
2918 * This is the default case for ISP-4xxx */
2919 if (!is_qla8022(ha) || reset_chip) {
2920 if (!is_qla8022(ha))
2923 /* Check if 82XX firmware is alive or not
2924 * We may have arrived here from NEED_RESET
2926 if (test_bit(AF_FW_RECOVERY, &ha->flags))
2929 wait = jiffies + (FW_ALIVE_WAIT_TOV * HZ);
2930 while (time_before(jiffies, wait)) {
2931 if (qla4_8xxx_check_fw_alive(ha)) {
2932 qla4xxx_mailbox_premature_completion(ha);
2936 set_current_state(TASK_UNINTERRUPTIBLE);
2937 schedule_timeout(HZ);
2940 if (!test_bit(AF_FW_RECOVERY, &ha->flags))
2941 qla4xxx_cmd_wait(ha);
2943 qla4xxx_process_aen(ha, FLUSH_DDB_CHANGED_AENS);
2944 qla4xxx_abort_active_cmds(ha, DID_RESET << 16);
2945 DEBUG2(ql4_printk(KERN_INFO, ha,
2946 "scsi%ld: %s - Performing chip reset..\n",
2947 ha->host_no, __func__));
2948 status = ha->isp_ops->reset_chip(ha);
2951 /* Flush any pending ddb changed AENs */
2952 qla4xxx_process_aen(ha, FLUSH_DDB_CHANGED_AENS);
2954 recover_ha_init_adapter:
2955 /* Upon successful firmware/chip reset, re-initialize the adapter */
2956 if (status == QLA_SUCCESS) {
2957 /* For ISP-4xxx, force function 1 to always initialize
2958 * before function 3 to prevent both funcions from
2959 * stepping on top of the other */
2960 if (!is_qla8022(ha) && (ha->mac_index == 3))
2963 /* NOTE: AF_ONLINE flag set upon successful completion of
2964 * qla4xxx_initialize_adapter */
2965 status = qla4xxx_initialize_adapter(ha, RESET_ADAPTER);
2968 /* Retry failed adapter initialization, if necessary
2969 * Do not retry initialize_adapter for RESET_HA_INTR (ISP-4xxx specific)
2970 * case to prevent ping-pong resets between functions */
2971 if (!test_bit(AF_ONLINE, &ha->flags) &&
2972 !test_bit(DPC_RESET_HA_INTR, &ha->dpc_flags)) {
2973 /* Adapter initialization failed, see if we can retry
2975 * Since we don't want to block the DPC for too long
2976 * with multiple resets in the same thread,
2977 * utilize DPC to retry */
2978 if (is_qla8022(ha)) {
2979 qla4_8xxx_idc_lock(ha);
2980 dev_state = qla4_8xxx_rd_32(ha, QLA82XX_CRB_DEV_STATE);
2981 qla4_8xxx_idc_unlock(ha);
2982 if (dev_state == QLA82XX_DEV_FAILED) {
2983 ql4_printk(KERN_INFO, ha, "%s: don't retry "
2984 "recover adapter. H/W is in Failed "
2985 "state\n", __func__);
2986 qla4xxx_dead_adapter_cleanup(ha);
2987 clear_bit(DPC_RETRY_RESET_HA, &ha->dpc_flags);
2988 clear_bit(DPC_RESET_HA, &ha->dpc_flags);
2989 clear_bit(DPC_RESET_HA_FW_CONTEXT,
2997 if (!test_bit(DPC_RETRY_RESET_HA, &ha->dpc_flags)) {
2998 ha->retry_reset_ha_cnt = MAX_RESET_HA_RETRIES;
2999 DEBUG2(printk("scsi%ld: recover adapter - retrying "
3000 "(%d) more times\n", ha->host_no,
3001 ha->retry_reset_ha_cnt));
3002 set_bit(DPC_RETRY_RESET_HA, &ha->dpc_flags);
3005 if (ha->retry_reset_ha_cnt > 0) {
3006 /* Schedule another Reset HA--DPC will retry */
3007 ha->retry_reset_ha_cnt--;
3008 DEBUG2(printk("scsi%ld: recover adapter - "
3009 "retry remaining %d\n",
3011 ha->retry_reset_ha_cnt));
3015 if (ha->retry_reset_ha_cnt == 0) {
3016 /* Recover adapter retries have been exhausted.
3018 DEBUG2(printk("scsi%ld: recover adapter "
3019 "failed - board disabled\n",
3021 qla4xxx_dead_adapter_cleanup(ha);
3022 clear_bit(DPC_RETRY_RESET_HA, &ha->dpc_flags);
3023 clear_bit(DPC_RESET_HA, &ha->dpc_flags);
3024 clear_bit(DPC_RESET_HA_FW_CONTEXT,
3030 clear_bit(DPC_RESET_HA, &ha->dpc_flags);
3031 clear_bit(DPC_RESET_HA_FW_CONTEXT, &ha->dpc_flags);
3032 clear_bit(DPC_RETRY_RESET_HA, &ha->dpc_flags);
3036 ha->adapter_error_count++;
3038 if (test_bit(AF_ONLINE, &ha->flags))
3039 ha->isp_ops->enable_intrs(ha);
3041 scsi_unblock_requests(ha->host);
3043 clear_bit(DPC_RESET_ACTIVE, &ha->dpc_flags);
3044 DEBUG2(printk("scsi%ld: recover adapter: %s\n", ha->host_no,
3045 status == QLA_ERROR ? "FAILED" : "SUCCEEDED"));
3050 static void qla4xxx_relogin_devices(struct iscsi_cls_session *cls_session)
3052 struct iscsi_session *sess;
3053 struct ddb_entry *ddb_entry;
3054 struct scsi_qla_host *ha;
3056 sess = cls_session->dd_data;
3057 ddb_entry = sess->dd_data;
3059 if (!iscsi_is_session_online(cls_session)) {
3060 if (ddb_entry->fw_ddb_device_state == DDB_DS_SESSION_ACTIVE) {
3061 ql4_printk(KERN_INFO, ha, "scsi%ld: %s: ddb[%d]"
3062 " unblock session\n", ha->host_no, __func__,
3063 ddb_entry->fw_ddb_index);
3064 iscsi_unblock_session(ddb_entry->sess);
3066 /* Trigger relogin */
3067 if (ddb_entry->ddb_type == FLASH_DDB) {
3068 if (!test_bit(DF_RELOGIN, &ddb_entry->flags))
3069 qla4xxx_arm_relogin_timer(ddb_entry);
3071 iscsi_session_failure(cls_session->dd_data,
3072 ISCSI_ERR_CONN_FAILED);
3077 int qla4xxx_unblock_flash_ddb(struct iscsi_cls_session *cls_session)
3079 struct iscsi_session *sess;
3080 struct ddb_entry *ddb_entry;
3081 struct scsi_qla_host *ha;
3083 sess = cls_session->dd_data;
3084 ddb_entry = sess->dd_data;
3086 ql4_printk(KERN_INFO, ha, "scsi%ld: %s: ddb[%d]"
3087 " unblock session\n", ha->host_no, __func__,
3088 ddb_entry->fw_ddb_index);
3090 iscsi_unblock_session(ddb_entry->sess);
3092 /* Start scan target */
3093 if (test_bit(AF_ONLINE, &ha->flags)) {
3094 ql4_printk(KERN_INFO, ha, "scsi%ld: %s: ddb[%d]"
3095 " start scan\n", ha->host_no, __func__,
3096 ddb_entry->fw_ddb_index);
3097 scsi_queue_work(ha->host, &ddb_entry->sess->scan_work);
3102 int qla4xxx_unblock_ddb(struct iscsi_cls_session *cls_session)
3104 struct iscsi_session *sess;
3105 struct ddb_entry *ddb_entry;
3106 struct scsi_qla_host *ha;
3108 sess = cls_session->dd_data;
3109 ddb_entry = sess->dd_data;
3111 ql4_printk(KERN_INFO, ha, "scsi%ld: %s: ddb[%d]"
3112 " unblock user space session\n", ha->host_no, __func__,
3113 ddb_entry->fw_ddb_index);
3114 iscsi_conn_start(ddb_entry->conn);
3115 iscsi_conn_login_event(ddb_entry->conn,
3116 ISCSI_CONN_STATE_LOGGED_IN);
3121 static void qla4xxx_relogin_all_devices(struct scsi_qla_host *ha)
3123 iscsi_host_for_each_session(ha->host, qla4xxx_relogin_devices);
3126 static void qla4xxx_relogin_flash_ddb(struct iscsi_cls_session *cls_sess)
3128 uint16_t relogin_timer;
3129 struct iscsi_session *sess;
3130 struct ddb_entry *ddb_entry;
3131 struct scsi_qla_host *ha;
3133 sess = cls_sess->dd_data;
3134 ddb_entry = sess->dd_data;
3137 relogin_timer = max(ddb_entry->default_relogin_timeout,
3138 (uint16_t)RELOGIN_TOV);
3139 atomic_set(&ddb_entry->relogin_timer, relogin_timer);
3141 DEBUG2(ql4_printk(KERN_INFO, ha,
3142 "scsi%ld: Relogin index [%d]. TOV=%d\n", ha->host_no,
3143 ddb_entry->fw_ddb_index, relogin_timer));
3145 qla4xxx_login_flash_ddb(cls_sess);
3148 static void qla4xxx_dpc_relogin(struct iscsi_cls_session *cls_sess)
3150 struct iscsi_session *sess;
3151 struct ddb_entry *ddb_entry;
3152 struct scsi_qla_host *ha;
3154 sess = cls_sess->dd_data;
3155 ddb_entry = sess->dd_data;
3158 if (!(ddb_entry->ddb_type == FLASH_DDB))
3161 if (test_and_clear_bit(DF_RELOGIN, &ddb_entry->flags) &&
3162 !iscsi_is_session_online(cls_sess)) {
3163 DEBUG2(ql4_printk(KERN_INFO, ha,
3164 "relogin issued\n"));
3165 qla4xxx_relogin_flash_ddb(cls_sess);
3169 void qla4xxx_wake_dpc(struct scsi_qla_host *ha)
3172 queue_work(ha->dpc_thread, &ha->dpc_work);
3175 static struct qla4_work_evt *
3176 qla4xxx_alloc_work(struct scsi_qla_host *ha, uint32_t data_size,
3177 enum qla4_work_type type)
3179 struct qla4_work_evt *e;
3180 uint32_t size = sizeof(struct qla4_work_evt) + data_size;
3182 e = kzalloc(size, GFP_ATOMIC);
3186 INIT_LIST_HEAD(&e->list);
3191 static void qla4xxx_post_work(struct scsi_qla_host *ha,
3192 struct qla4_work_evt *e)
3194 unsigned long flags;
3196 spin_lock_irqsave(&ha->work_lock, flags);
3197 list_add_tail(&e->list, &ha->work_list);
3198 spin_unlock_irqrestore(&ha->work_lock, flags);
3199 qla4xxx_wake_dpc(ha);
3202 int qla4xxx_post_aen_work(struct scsi_qla_host *ha,
3203 enum iscsi_host_event_code aen_code,
3204 uint32_t data_size, uint8_t *data)
3206 struct qla4_work_evt *e;
3208 e = qla4xxx_alloc_work(ha, data_size, QLA4_EVENT_AEN);
3212 e->u.aen.code = aen_code;
3213 e->u.aen.data_size = data_size;
3214 memcpy(e->u.aen.data, data, data_size);
3216 qla4xxx_post_work(ha, e);
3221 int qla4xxx_post_ping_evt_work(struct scsi_qla_host *ha,
3222 uint32_t status, uint32_t pid,
3223 uint32_t data_size, uint8_t *data)
3225 struct qla4_work_evt *e;
3227 e = qla4xxx_alloc_work(ha, data_size, QLA4_EVENT_PING_STATUS);
3231 e->u.ping.status = status;
3232 e->u.ping.pid = pid;
3233 e->u.ping.data_size = data_size;
3234 memcpy(e->u.ping.data, data, data_size);
3236 qla4xxx_post_work(ha, e);
3241 static void qla4xxx_do_work(struct scsi_qla_host *ha)
3243 struct qla4_work_evt *e, *tmp;
3244 unsigned long flags;
3247 spin_lock_irqsave(&ha->work_lock, flags);
3248 list_splice_init(&ha->work_list, &work);
3249 spin_unlock_irqrestore(&ha->work_lock, flags);
3251 list_for_each_entry_safe(e, tmp, &work, list) {
3252 list_del_init(&e->list);
3255 case QLA4_EVENT_AEN:
3256 iscsi_post_host_event(ha->host_no,
3257 &qla4xxx_iscsi_transport,
3262 case QLA4_EVENT_PING_STATUS:
3263 iscsi_ping_comp_event(ha->host_no,
3264 &qla4xxx_iscsi_transport,
3267 e->u.ping.data_size,
3271 ql4_printk(KERN_WARNING, ha, "event type: 0x%x not "
3272 "supported", e->type);
3279 * qla4xxx_do_dpc - dpc routine
3280 * @data: in our case pointer to adapter structure
3282 * This routine is a task that is schedule by the interrupt handler
3283 * to perform the background processing for interrupts. We put it
3284 * on a task queue that is consumed whenever the scheduler runs; that's
3285 * so you can do anything (i.e. put the process to sleep etc). In fact,
3286 * the mid-level tries to sleep when it reaches the driver threshold
3287 * "host->can_queue". This can cause a panic if we were in our interrupt code.
3289 static void qla4xxx_do_dpc(struct work_struct *work)
3291 struct scsi_qla_host *ha =
3292 container_of(work, struct scsi_qla_host, dpc_work);
3293 int status = QLA_ERROR;
3295 DEBUG2(printk("scsi%ld: %s: DPC handler waking up."
3296 "flags = 0x%08lx, dpc_flags = 0x%08lx\n",
3297 ha->host_no, __func__, ha->flags, ha->dpc_flags))
3299 /* Initialization not yet finished. Don't do anything yet. */
3300 if (!test_bit(AF_INIT_DONE, &ha->flags))
3303 if (test_bit(AF_EEH_BUSY, &ha->flags)) {
3304 DEBUG2(printk(KERN_INFO "scsi%ld: %s: flags = %lx\n",
3305 ha->host_no, __func__, ha->flags));
3309 /* post events to application */
3310 qla4xxx_do_work(ha);
3312 if (is_qla8022(ha)) {
3313 if (test_bit(DPC_HA_UNRECOVERABLE, &ha->dpc_flags)) {
3314 qla4_8xxx_idc_lock(ha);
3315 qla4_8xxx_wr_32(ha, QLA82XX_CRB_DEV_STATE,
3316 QLA82XX_DEV_FAILED);
3317 qla4_8xxx_idc_unlock(ha);
3318 ql4_printk(KERN_INFO, ha, "HW State: FAILED\n");
3319 qla4_8xxx_device_state_handler(ha);
3321 if (test_and_clear_bit(DPC_HA_NEED_QUIESCENT, &ha->dpc_flags)) {
3322 qla4_8xxx_need_qsnt_handler(ha);
3326 if (!test_bit(DPC_RESET_ACTIVE, &ha->dpc_flags) &&
3327 (test_bit(DPC_RESET_HA, &ha->dpc_flags) ||
3328 test_bit(DPC_RESET_HA_INTR, &ha->dpc_flags) ||
3329 test_bit(DPC_RESET_HA_FW_CONTEXT, &ha->dpc_flags))) {
3330 if (ql4xdontresethba) {
3331 DEBUG2(printk("scsi%ld: %s: Don't Reset HBA\n",
3332 ha->host_no, __func__));
3333 clear_bit(DPC_RESET_HA, &ha->dpc_flags);
3334 clear_bit(DPC_RESET_HA_INTR, &ha->dpc_flags);
3335 clear_bit(DPC_RESET_HA_FW_CONTEXT, &ha->dpc_flags);
3336 goto dpc_post_reset_ha;
3338 if (test_bit(DPC_RESET_HA_FW_CONTEXT, &ha->dpc_flags) ||
3339 test_bit(DPC_RESET_HA, &ha->dpc_flags))
3340 qla4xxx_recover_adapter(ha);
3342 if (test_bit(DPC_RESET_HA_INTR, &ha->dpc_flags)) {
3343 uint8_t wait_time = RESET_INTR_TOV;
3345 while ((readw(&ha->reg->ctrl_status) &
3346 (CSR_SOFT_RESET | CSR_FORCE_SOFT_RESET)) != 0) {
3347 if (--wait_time == 0)
3352 DEBUG2(printk("scsi%ld: %s: SR|FSR "
3353 "bit not cleared-- resetting\n",
3354 ha->host_no, __func__));
3355 qla4xxx_abort_active_cmds(ha, DID_RESET << 16);
3356 if (ql4xxx_lock_drvr_wait(ha) == QLA_SUCCESS) {
3357 qla4xxx_process_aen(ha, FLUSH_DDB_CHANGED_AENS);
3358 status = qla4xxx_recover_adapter(ha);
3360 clear_bit(DPC_RESET_HA_INTR, &ha->dpc_flags);
3361 if (status == QLA_SUCCESS)
3362 ha->isp_ops->enable_intrs(ha);
3367 /* ---- process AEN? --- */
3368 if (test_and_clear_bit(DPC_AEN, &ha->dpc_flags))
3369 qla4xxx_process_aen(ha, PROCESS_ALL_AENS);
3371 /* ---- Get DHCP IP Address? --- */
3372 if (test_and_clear_bit(DPC_GET_DHCP_IP_ADDR, &ha->dpc_flags))
3373 qla4xxx_get_dhcp_ip_address(ha);
3375 /* ---- relogin device? --- */
3376 if (adapter_up(ha) &&
3377 test_and_clear_bit(DPC_RELOGIN_DEVICE, &ha->dpc_flags)) {
3378 iscsi_host_for_each_session(ha->host, qla4xxx_dpc_relogin);
3381 /* ---- link change? --- */
3382 if (test_and_clear_bit(DPC_LINK_CHANGED, &ha->dpc_flags)) {
3383 if (!test_bit(AF_LINK_UP, &ha->flags)) {
3384 /* ---- link down? --- */
3385 qla4xxx_mark_all_devices_missing(ha);
3387 /* ---- link up? --- *
3388 * F/W will auto login to all devices ONLY ONCE after
3389 * link up during driver initialization and runtime
3390 * fatal error recovery. Therefore, the driver must
3391 * manually relogin to devices when recovering from
3392 * connection failures, logouts, expired KATO, etc. */
3393 if (test_and_clear_bit(AF_BUILD_DDB_LIST, &ha->flags)) {
3394 qla4xxx_build_ddb_list(ha, ha->is_reset);
3395 iscsi_host_for_each_session(ha->host,
3396 qla4xxx_login_flash_ddb);
3398 qla4xxx_relogin_all_devices(ha);
3404 * qla4xxx_free_adapter - release the adapter
3405 * @ha: pointer to adapter structure
3407 static void qla4xxx_free_adapter(struct scsi_qla_host *ha)
3409 qla4xxx_abort_active_cmds(ha, DID_NO_CONNECT << 16);
3411 if (test_bit(AF_INTERRUPTS_ON, &ha->flags)) {
3412 /* Turn-off interrupts on the card. */
3413 ha->isp_ops->disable_intrs(ha);
3416 /* Remove timer thread, if present */
3417 if (ha->timer_active)
3418 qla4xxx_stop_timer(ha);
3420 /* Kill the kernel thread for this host */
3422 destroy_workqueue(ha->dpc_thread);
3424 /* Kill the kernel thread for this host */
3426 destroy_workqueue(ha->task_wq);
3428 /* Put firmware in known state */
3429 ha->isp_ops->reset_firmware(ha);
3431 if (is_qla8022(ha)) {
3432 qla4_8xxx_idc_lock(ha);
3433 qla4_8xxx_clear_drv_active(ha);
3434 qla4_8xxx_idc_unlock(ha);
3437 /* Detach interrupts */
3438 if (test_and_clear_bit(AF_IRQ_ATTACHED, &ha->flags))
3439 qla4xxx_free_irqs(ha);
3441 /* free extra memory */
3442 qla4xxx_mem_free(ha);
3445 int qla4_8xxx_iospace_config(struct scsi_qla_host *ha)
3448 uint8_t revision_id;
3449 unsigned long mem_base, mem_len, db_base, db_len;
3450 struct pci_dev *pdev = ha->pdev;
3452 status = pci_request_regions(pdev, DRIVER_NAME);
3455 "scsi(%ld) Failed to reserve PIO regions (%s) "
3456 "status=%d\n", ha->host_no, pci_name(pdev), status);
3457 goto iospace_error_exit;
3460 pci_read_config_byte(pdev, PCI_REVISION_ID, &revision_id);
3461 DEBUG2(printk(KERN_INFO "%s: revision-id=%d\n",
3462 __func__, revision_id));
3463 ha->revision_id = revision_id;
3465 /* remap phys address */
3466 mem_base = pci_resource_start(pdev, 0); /* 0 is for BAR 0 */
3467 mem_len = pci_resource_len(pdev, 0);
3468 DEBUG2(printk(KERN_INFO "%s: ioremap from %lx a size of %lx\n",
3469 __func__, mem_base, mem_len));
3471 /* mapping of pcibase pointer */
3472 ha->nx_pcibase = (unsigned long)ioremap(mem_base, mem_len);
3473 if (!ha->nx_pcibase) {
3475 "cannot remap MMIO (%s), aborting\n", pci_name(pdev));
3476 pci_release_regions(ha->pdev);
3477 goto iospace_error_exit;
3480 /* Mapping of IO base pointer, door bell read and write pointer */
3482 /* mapping of IO base pointer */
3484 (struct device_reg_82xx __iomem *)((uint8_t *)ha->nx_pcibase +
3485 0xbc000 + (ha->pdev->devfn << 11));
3487 db_base = pci_resource_start(pdev, 4); /* doorbell is on bar 4 */
3488 db_len = pci_resource_len(pdev, 4);
3490 ha->nx_db_wr_ptr = (ha->pdev->devfn == 4 ? QLA82XX_CAM_RAM_DB1 :
3491 QLA82XX_CAM_RAM_DB2);
3499 * qla4xxx_iospace_config - maps registers
3500 * @ha: pointer to adapter structure
3502 * This routines maps HBA's registers from the pci address space
3503 * into the kernel virtual address space for memory mapped i/o.
3505 int qla4xxx_iospace_config(struct scsi_qla_host *ha)
3507 unsigned long pio, pio_len, pio_flags;
3508 unsigned long mmio, mmio_len, mmio_flags;
3510 pio = pci_resource_start(ha->pdev, 0);
3511 pio_len = pci_resource_len(ha->pdev, 0);
3512 pio_flags = pci_resource_flags(ha->pdev, 0);
3513 if (pio_flags & IORESOURCE_IO) {
3514 if (pio_len < MIN_IOBASE_LEN) {
3515 ql4_printk(KERN_WARNING, ha,
3516 "Invalid PCI I/O region size\n");
3520 ql4_printk(KERN_WARNING, ha, "region #0 not a PIO resource\n");
3524 /* Use MMIO operations for all accesses. */
3525 mmio = pci_resource_start(ha->pdev, 1);
3526 mmio_len = pci_resource_len(ha->pdev, 1);
3527 mmio_flags = pci_resource_flags(ha->pdev, 1);
3529 if (!(mmio_flags & IORESOURCE_MEM)) {
3530 ql4_printk(KERN_ERR, ha,
3531 "region #0 not an MMIO resource, aborting\n");
3533 goto iospace_error_exit;
3536 if (mmio_len < MIN_IOBASE_LEN) {
3537 ql4_printk(KERN_ERR, ha,
3538 "Invalid PCI mem region size, aborting\n");
3539 goto iospace_error_exit;
3542 if (pci_request_regions(ha->pdev, DRIVER_NAME)) {
3543 ql4_printk(KERN_WARNING, ha,
3544 "Failed to reserve PIO/MMIO regions\n");
3546 goto iospace_error_exit;
3549 ha->pio_address = pio;
3550 ha->pio_length = pio_len;
3551 ha->reg = ioremap(mmio, MIN_IOBASE_LEN);
3553 ql4_printk(KERN_ERR, ha,
3554 "cannot remap MMIO, aborting\n");
3556 goto iospace_error_exit;
3565 static struct isp_operations qla4xxx_isp_ops = {
3566 .iospace_config = qla4xxx_iospace_config,
3567 .pci_config = qla4xxx_pci_config,
3568 .disable_intrs = qla4xxx_disable_intrs,
3569 .enable_intrs = qla4xxx_enable_intrs,
3570 .start_firmware = qla4xxx_start_firmware,
3571 .intr_handler = qla4xxx_intr_handler,
3572 .interrupt_service_routine = qla4xxx_interrupt_service_routine,
3573 .reset_chip = qla4xxx_soft_reset,
3574 .reset_firmware = qla4xxx_hw_reset,
3575 .queue_iocb = qla4xxx_queue_iocb,
3576 .complete_iocb = qla4xxx_complete_iocb,
3577 .rd_shdw_req_q_out = qla4xxx_rd_shdw_req_q_out,
3578 .rd_shdw_rsp_q_in = qla4xxx_rd_shdw_rsp_q_in,
3579 .get_sys_info = qla4xxx_get_sys_info,
3582 static struct isp_operations qla4_8xxx_isp_ops = {
3583 .iospace_config = qla4_8xxx_iospace_config,
3584 .pci_config = qla4_8xxx_pci_config,
3585 .disable_intrs = qla4_8xxx_disable_intrs,
3586 .enable_intrs = qla4_8xxx_enable_intrs,
3587 .start_firmware = qla4_8xxx_load_risc,
3588 .intr_handler = qla4_8xxx_intr_handler,
3589 .interrupt_service_routine = qla4_8xxx_interrupt_service_routine,
3590 .reset_chip = qla4_8xxx_isp_reset,
3591 .reset_firmware = qla4_8xxx_stop_firmware,
3592 .queue_iocb = qla4_8xxx_queue_iocb,
3593 .complete_iocb = qla4_8xxx_complete_iocb,
3594 .rd_shdw_req_q_out = qla4_8xxx_rd_shdw_req_q_out,
3595 .rd_shdw_rsp_q_in = qla4_8xxx_rd_shdw_rsp_q_in,
3596 .get_sys_info = qla4_8xxx_get_sys_info,
3599 uint16_t qla4xxx_rd_shdw_req_q_out(struct scsi_qla_host *ha)
3601 return (uint16_t)le32_to_cpu(ha->shadow_regs->req_q_out);
3604 uint16_t qla4_8xxx_rd_shdw_req_q_out(struct scsi_qla_host *ha)
3606 return (uint16_t)le32_to_cpu(readl(&ha->qla4_8xxx_reg->req_q_out));
3609 uint16_t qla4xxx_rd_shdw_rsp_q_in(struct scsi_qla_host *ha)
3611 return (uint16_t)le32_to_cpu(ha->shadow_regs->rsp_q_in);
3614 uint16_t qla4_8xxx_rd_shdw_rsp_q_in(struct scsi_qla_host *ha)
3616 return (uint16_t)le32_to_cpu(readl(&ha->qla4_8xxx_reg->rsp_q_in));
3619 static ssize_t qla4xxx_show_boot_eth_info(void *data, int type, char *buf)
3621 struct scsi_qla_host *ha = data;
3626 case ISCSI_BOOT_ETH_FLAGS:
3627 rc = sprintf(str, "%d\n", SYSFS_FLAG_FW_SEL_BOOT);
3629 case ISCSI_BOOT_ETH_INDEX:
3630 rc = sprintf(str, "0\n");
3632 case ISCSI_BOOT_ETH_MAC:
3633 rc = sysfs_format_mac(str, ha->my_mac,
3643 static umode_t qla4xxx_eth_get_attr_visibility(void *data, int type)
3648 case ISCSI_BOOT_ETH_FLAGS:
3649 case ISCSI_BOOT_ETH_MAC:
3650 case ISCSI_BOOT_ETH_INDEX:
3660 static ssize_t qla4xxx_show_boot_ini_info(void *data, int type, char *buf)
3662 struct scsi_qla_host *ha = data;
3667 case ISCSI_BOOT_INI_INITIATOR_NAME:
3668 rc = sprintf(str, "%s\n", ha->name_string);
3677 static umode_t qla4xxx_ini_get_attr_visibility(void *data, int type)
3682 case ISCSI_BOOT_INI_INITIATOR_NAME:
3693 qla4xxx_show_boot_tgt_info(struct ql4_boot_session_info *boot_sess, int type,
3696 struct ql4_conn_info *boot_conn = &boot_sess->conn_list[0];
3701 case ISCSI_BOOT_TGT_NAME:
3702 rc = sprintf(buf, "%s\n", (char *)&boot_sess->target_name);
3704 case ISCSI_BOOT_TGT_IP_ADDR:
3705 if (boot_sess->conn_list[0].dest_ipaddr.ip_type == 0x1)
3706 rc = sprintf(buf, "%pI4\n",
3707 &boot_conn->dest_ipaddr.ip_address);
3709 rc = sprintf(str, "%pI6\n",
3710 &boot_conn->dest_ipaddr.ip_address);
3712 case ISCSI_BOOT_TGT_PORT:
3713 rc = sprintf(str, "%d\n", boot_conn->dest_port);
3715 case ISCSI_BOOT_TGT_CHAP_NAME:
3716 rc = sprintf(str, "%.*s\n",
3717 boot_conn->chap.target_chap_name_length,
3718 (char *)&boot_conn->chap.target_chap_name);
3720 case ISCSI_BOOT_TGT_CHAP_SECRET:
3721 rc = sprintf(str, "%.*s\n",
3722 boot_conn->chap.target_secret_length,
3723 (char *)&boot_conn->chap.target_secret);
3725 case ISCSI_BOOT_TGT_REV_CHAP_NAME:
3726 rc = sprintf(str, "%.*s\n",
3727 boot_conn->chap.intr_chap_name_length,
3728 (char *)&boot_conn->chap.intr_chap_name);
3730 case ISCSI_BOOT_TGT_REV_CHAP_SECRET:
3731 rc = sprintf(str, "%.*s\n",
3732 boot_conn->chap.intr_secret_length,
3733 (char *)&boot_conn->chap.intr_secret);
3735 case ISCSI_BOOT_TGT_FLAGS:
3736 rc = sprintf(str, "%d\n", SYSFS_FLAG_FW_SEL_BOOT);
3738 case ISCSI_BOOT_TGT_NIC_ASSOC:
3739 rc = sprintf(str, "0\n");
3748 static ssize_t qla4xxx_show_boot_tgt_pri_info(void *data, int type, char *buf)
3750 struct scsi_qla_host *ha = data;
3751 struct ql4_boot_session_info *boot_sess = &(ha->boot_tgt.boot_pri_sess);
3753 return qla4xxx_show_boot_tgt_info(boot_sess, type, buf);
3756 static ssize_t qla4xxx_show_boot_tgt_sec_info(void *data, int type, char *buf)
3758 struct scsi_qla_host *ha = data;
3759 struct ql4_boot_session_info *boot_sess = &(ha->boot_tgt.boot_sec_sess);
3761 return qla4xxx_show_boot_tgt_info(boot_sess, type, buf);
3764 static umode_t qla4xxx_tgt_get_attr_visibility(void *data, int type)
3769 case ISCSI_BOOT_TGT_NAME:
3770 case ISCSI_BOOT_TGT_IP_ADDR:
3771 case ISCSI_BOOT_TGT_PORT:
3772 case ISCSI_BOOT_TGT_CHAP_NAME:
3773 case ISCSI_BOOT_TGT_CHAP_SECRET:
3774 case ISCSI_BOOT_TGT_REV_CHAP_NAME:
3775 case ISCSI_BOOT_TGT_REV_CHAP_SECRET:
3776 case ISCSI_BOOT_TGT_NIC_ASSOC:
3777 case ISCSI_BOOT_TGT_FLAGS:
3787 static void qla4xxx_boot_release(void *data)
3789 struct scsi_qla_host *ha = data;
3791 scsi_host_put(ha->host);
3794 static int get_fw_boot_info(struct scsi_qla_host *ha, uint16_t ddb_index[])
3797 uint32_t addr, pri_addr, sec_addr;
3801 uint8_t *buf = NULL;
3802 size_t size = 13 * sizeof(uint8_t);
3803 int ret = QLA_SUCCESS;
3805 func_num = PCI_FUNC(ha->pdev->devfn);
3807 ql4_printk(KERN_INFO, ha, "%s: Get FW boot info for 0x%x func %d\n",
3808 __func__, ha->pdev->device, func_num);
3810 if (is_qla40XX(ha)) {
3811 if (func_num == 1) {
3812 addr = NVRAM_PORT0_BOOT_MODE;
3813 pri_addr = NVRAM_PORT0_BOOT_PRI_TGT;
3814 sec_addr = NVRAM_PORT0_BOOT_SEC_TGT;
3815 } else if (func_num == 3) {
3816 addr = NVRAM_PORT1_BOOT_MODE;
3817 pri_addr = NVRAM_PORT1_BOOT_PRI_TGT;
3818 sec_addr = NVRAM_PORT1_BOOT_SEC_TGT;
3821 goto exit_boot_info;
3824 /* Check Boot Mode */
3825 val = rd_nvram_byte(ha, addr);
3826 if (!(val & 0x07)) {
3827 DEBUG2(ql4_printk(KERN_INFO, ha, "%s: Adapter boot "
3828 "options : 0x%x\n", __func__, val));
3830 goto exit_boot_info;
3833 /* get primary valid target index */
3834 val = rd_nvram_byte(ha, pri_addr);
3836 ddb_index[0] = (val & 0x7f);
3838 /* get secondary valid target index */
3839 val = rd_nvram_byte(ha, sec_addr);
3841 ddb_index[1] = (val & 0x7f);
3843 } else if (is_qla8022(ha)) {
3844 buf = dma_alloc_coherent(&ha->pdev->dev, size,
3845 &buf_dma, GFP_KERNEL);
3847 DEBUG2(ql4_printk(KERN_ERR, ha,
3848 "%s: Unable to allocate dma buffer\n",
3851 goto exit_boot_info;
3854 if (ha->port_num == 0)
3855 offset = BOOT_PARAM_OFFSET_PORT0;
3856 else if (ha->port_num == 1)
3857 offset = BOOT_PARAM_OFFSET_PORT1;
3860 goto exit_boot_info_free;
3862 addr = FLASH_RAW_ACCESS_ADDR + (ha->hw.flt_iscsi_param * 4) +
3864 if (qla4xxx_get_flash(ha, buf_dma, addr,
3865 13 * sizeof(uint8_t)) != QLA_SUCCESS) {
3866 DEBUG2(ql4_printk(KERN_ERR, ha, "scsi%ld: %s: Get Flash"
3867 " failed\n", ha->host_no, __func__));
3869 goto exit_boot_info_free;
3871 /* Check Boot Mode */
3872 if (!(buf[1] & 0x07)) {
3873 DEBUG2(ql4_printk(KERN_INFO, ha, "Firmware boot options"
3874 " : 0x%x\n", buf[1]));
3876 goto exit_boot_info_free;
3879 /* get primary valid target index */
3881 ddb_index[0] = buf[2] & 0x7f;
3883 /* get secondary valid target index */
3884 if (buf[11] & BIT_7)
3885 ddb_index[1] = buf[11] & 0x7f;
3888 goto exit_boot_info;
3891 DEBUG2(ql4_printk(KERN_INFO, ha, "%s: Primary target ID %d, Secondary"
3892 " target ID %d\n", __func__, ddb_index[0],
3895 exit_boot_info_free:
3896 dma_free_coherent(&ha->pdev->dev, size, buf, buf_dma);
3898 ha->pri_ddb_idx = ddb_index[0];
3899 ha->sec_ddb_idx = ddb_index[1];
3904 * qla4xxx_get_bidi_chap - Get a BIDI CHAP user and password
3905 * @ha: pointer to adapter structure
3906 * @username: CHAP username to be returned
3907 * @password: CHAP password to be returned
3909 * If a boot entry has BIDI CHAP enabled then we need to set the BIDI CHAP
3910 * user and password in the sysfs entry in /sys/firmware/iscsi_boot#/.
3911 * So from the CHAP cache find the first BIDI CHAP entry and set it
3912 * to the boot record in sysfs.
3914 static int qla4xxx_get_bidi_chap(struct scsi_qla_host *ha, char *username,
3917 int i, ret = -EINVAL;
3918 int max_chap_entries = 0;
3919 struct ql4_chap_table *chap_table;
3922 max_chap_entries = (ha->hw.flt_chap_size / 2) /
3923 sizeof(struct ql4_chap_table);
3925 max_chap_entries = MAX_CHAP_ENTRIES_40XX;
3927 if (!ha->chap_list) {
3928 ql4_printk(KERN_ERR, ha, "Do not have CHAP table cache\n");
3932 mutex_lock(&ha->chap_sem);
3933 for (i = 0; i < max_chap_entries; i++) {
3934 chap_table = (struct ql4_chap_table *)ha->chap_list + i;
3935 if (chap_table->cookie !=
3936 __constant_cpu_to_le16(CHAP_VALID_COOKIE)) {
3940 if (chap_table->flags & BIT_7) /* local */
3943 if (!(chap_table->flags & BIT_6)) /* Not BIDI */
3946 strncpy(password, chap_table->secret, QL4_CHAP_MAX_SECRET_LEN);
3947 strncpy(username, chap_table->name, QL4_CHAP_MAX_NAME_LEN);
3951 mutex_unlock(&ha->chap_sem);
3957 static int qla4xxx_get_boot_target(struct scsi_qla_host *ha,
3958 struct ql4_boot_session_info *boot_sess,
3961 struct ql4_conn_info *boot_conn = &boot_sess->conn_list[0];
3962 struct dev_db_entry *fw_ddb_entry;
3963 dma_addr_t fw_ddb_entry_dma;
3966 int ret = QLA_SUCCESS;
3968 fw_ddb_entry = dma_alloc_coherent(&ha->pdev->dev, sizeof(*fw_ddb_entry),
3969 &fw_ddb_entry_dma, GFP_KERNEL);
3970 if (!fw_ddb_entry) {
3971 DEBUG2(ql4_printk(KERN_ERR, ha,
3972 "%s: Unable to allocate dma buffer.\n",
3978 if (qla4xxx_bootdb_by_index(ha, fw_ddb_entry,
3979 fw_ddb_entry_dma, ddb_index)) {
3980 DEBUG2(ql4_printk(KERN_INFO, ha, "%s: No Flash DDB found at "
3981 "index [%d]\n", __func__, ddb_index));
3983 goto exit_boot_target;
3986 /* Update target name and IP from DDB */
3987 memcpy(boot_sess->target_name, fw_ddb_entry->iscsi_name,
3988 min(sizeof(boot_sess->target_name),
3989 sizeof(fw_ddb_entry->iscsi_name)));
3991 options = le16_to_cpu(fw_ddb_entry->options);
3992 if (options & DDB_OPT_IPV6_DEVICE) {
3993 memcpy(&boot_conn->dest_ipaddr.ip_address,
3994 &fw_ddb_entry->ip_addr[0], IPv6_ADDR_LEN);
3996 boot_conn->dest_ipaddr.ip_type = 0x1;
3997 memcpy(&boot_conn->dest_ipaddr.ip_address,
3998 &fw_ddb_entry->ip_addr[0], IP_ADDR_LEN);
4001 boot_conn->dest_port = le16_to_cpu(fw_ddb_entry->port);
4003 /* update chap information */
4004 idx = __le16_to_cpu(fw_ddb_entry->chap_tbl_idx);
4006 if (BIT_7 & le16_to_cpu(fw_ddb_entry->iscsi_options)) {
4008 DEBUG2(ql4_printk(KERN_INFO, ha, "Setting chap\n"));
4010 ret = qla4xxx_get_chap(ha, (char *)&boot_conn->chap.
4012 (char *)&boot_conn->chap.target_secret,
4015 ql4_printk(KERN_ERR, ha, "Failed to set chap\n");
4017 goto exit_boot_target;
4020 boot_conn->chap.target_chap_name_length = QL4_CHAP_MAX_NAME_LEN;
4021 boot_conn->chap.target_secret_length = QL4_CHAP_MAX_SECRET_LEN;
4024 if (BIT_4 & le16_to_cpu(fw_ddb_entry->iscsi_options)) {
4026 DEBUG2(ql4_printk(KERN_INFO, ha, "Setting BIDI chap\n"));
4028 ret = qla4xxx_get_bidi_chap(ha,
4029 (char *)&boot_conn->chap.intr_chap_name,
4030 (char *)&boot_conn->chap.intr_secret);
4033 ql4_printk(KERN_ERR, ha, "Failed to set BIDI chap\n");
4035 goto exit_boot_target;
4038 boot_conn->chap.intr_chap_name_length = QL4_CHAP_MAX_NAME_LEN;
4039 boot_conn->chap.intr_secret_length = QL4_CHAP_MAX_SECRET_LEN;
4043 dma_free_coherent(&ha->pdev->dev, sizeof(*fw_ddb_entry),
4044 fw_ddb_entry, fw_ddb_entry_dma);
4048 static int qla4xxx_get_boot_info(struct scsi_qla_host *ha)
4050 uint16_t ddb_index[2];
4051 int ret = QLA_ERROR;
4054 memset(ddb_index, 0, sizeof(ddb_index));
4055 ddb_index[0] = 0xffff;
4056 ddb_index[1] = 0xffff;
4057 ret = get_fw_boot_info(ha, ddb_index);
4058 if (ret != QLA_SUCCESS) {
4059 DEBUG2(ql4_printk(KERN_INFO, ha,
4060 "%s: No boot target configured.\n", __func__));
4064 if (ql4xdisablesysfsboot)
4067 if (ddb_index[0] == 0xffff)
4070 rval = qla4xxx_get_boot_target(ha, &(ha->boot_tgt.boot_pri_sess),
4072 if (rval != QLA_SUCCESS) {
4073 DEBUG2(ql4_printk(KERN_INFO, ha, "%s: Primary boot target not "
4074 "configured\n", __func__));
4079 if (ddb_index[1] == 0xffff)
4080 goto exit_get_boot_info;
4082 rval = qla4xxx_get_boot_target(ha, &(ha->boot_tgt.boot_sec_sess),
4084 if (rval != QLA_SUCCESS) {
4085 DEBUG2(ql4_printk(KERN_INFO, ha, "%s: Secondary boot target not"
4086 " configured\n", __func__));
4094 static int qla4xxx_setup_boot_info(struct scsi_qla_host *ha)
4096 struct iscsi_boot_kobj *boot_kobj;
4098 if (qla4xxx_get_boot_info(ha) != QLA_SUCCESS)
4101 if (ql4xdisablesysfsboot) {
4102 ql4_printk(KERN_INFO, ha,
4103 "%s: syfsboot disabled - driver will trigger login "
4104 "and publish session for discovery .\n", __func__);
4109 ha->boot_kset = iscsi_boot_create_host_kset(ha->host->host_no);
4113 if (!scsi_host_get(ha->host))
4115 boot_kobj = iscsi_boot_create_target(ha->boot_kset, 0, ha,
4116 qla4xxx_show_boot_tgt_pri_info,
4117 qla4xxx_tgt_get_attr_visibility,
4118 qla4xxx_boot_release);
4122 if (!scsi_host_get(ha->host))
4124 boot_kobj = iscsi_boot_create_target(ha->boot_kset, 1, ha,
4125 qla4xxx_show_boot_tgt_sec_info,
4126 qla4xxx_tgt_get_attr_visibility,
4127 qla4xxx_boot_release);
4131 if (!scsi_host_get(ha->host))
4133 boot_kobj = iscsi_boot_create_initiator(ha->boot_kset, 0, ha,
4134 qla4xxx_show_boot_ini_info,
4135 qla4xxx_ini_get_attr_visibility,
4136 qla4xxx_boot_release);
4140 if (!scsi_host_get(ha->host))
4142 boot_kobj = iscsi_boot_create_ethernet(ha->boot_kset, 0, ha,
4143 qla4xxx_show_boot_eth_info,
4144 qla4xxx_eth_get_attr_visibility,
4145 qla4xxx_boot_release);
4152 scsi_host_put(ha->host);
4154 iscsi_boot_destroy_kset(ha->boot_kset);
4160 * qla4xxx_create chap_list - Create CHAP list from FLASH
4161 * @ha: pointer to adapter structure
4163 * Read flash and make a list of CHAP entries, during login when a CHAP entry
4164 * is received, it will be checked in this list. If entry exist then the CHAP
4165 * entry index is set in the DDB. If CHAP entry does not exist in this list
4166 * then a new entry is added in FLASH in CHAP table and the index obtained is
4169 static void qla4xxx_create_chap_list(struct scsi_qla_host *ha)
4172 uint8_t *chap_flash_data = NULL;
4174 dma_addr_t chap_dma;
4175 uint32_t chap_size = 0;
4178 chap_size = MAX_CHAP_ENTRIES_40XX *
4179 sizeof(struct ql4_chap_table);
4180 else /* Single region contains CHAP info for both
4181 * ports which is divided into half for each port.
4183 chap_size = ha->hw.flt_chap_size / 2;
4185 chap_flash_data = dma_alloc_coherent(&ha->pdev->dev, chap_size,
4186 &chap_dma, GFP_KERNEL);
4187 if (!chap_flash_data) {
4188 ql4_printk(KERN_ERR, ha, "No memory for chap_flash_data\n");
4192 offset = FLASH_CHAP_OFFSET;
4194 offset = FLASH_RAW_ACCESS_ADDR + (ha->hw.flt_region_chap << 2);
4195 if (ha->port_num == 1)
4196 offset += chap_size;
4199 rval = qla4xxx_get_flash(ha, chap_dma, offset, chap_size);
4200 if (rval != QLA_SUCCESS)
4201 goto exit_chap_list;
4203 if (ha->chap_list == NULL)
4204 ha->chap_list = vmalloc(chap_size);
4205 if (ha->chap_list == NULL) {
4206 ql4_printk(KERN_ERR, ha, "No memory for ha->chap_list\n");
4207 goto exit_chap_list;
4210 memcpy(ha->chap_list, chap_flash_data, chap_size);
4213 dma_free_coherent(&ha->pdev->dev, chap_size,
4214 chap_flash_data, chap_dma);
4217 static void qla4xxx_get_param_ddb(struct ddb_entry *ddb_entry,
4218 struct ql4_tuple_ddb *tddb)
4220 struct scsi_qla_host *ha;
4221 struct iscsi_cls_session *cls_sess;
4222 struct iscsi_cls_conn *cls_conn;
4223 struct iscsi_session *sess;
4224 struct iscsi_conn *conn;
4226 DEBUG2(printk(KERN_INFO "Func: %s\n", __func__));
4228 cls_sess = ddb_entry->sess;
4229 sess = cls_sess->dd_data;
4230 cls_conn = ddb_entry->conn;
4231 conn = cls_conn->dd_data;
4233 tddb->tpgt = sess->tpgt;
4234 tddb->port = conn->persistent_port;
4235 strncpy(tddb->iscsi_name, sess->targetname, ISCSI_NAME_SIZE);
4236 strncpy(tddb->ip_addr, conn->persistent_address, DDB_IPADDR_LEN);
4239 static void qla4xxx_convert_param_ddb(struct dev_db_entry *fw_ddb_entry,
4240 struct ql4_tuple_ddb *tddb)
4242 uint16_t options = 0;
4244 tddb->tpgt = le32_to_cpu(fw_ddb_entry->tgt_portal_grp);
4245 memcpy(&tddb->iscsi_name[0], &fw_ddb_entry->iscsi_name[0],
4246 min(sizeof(tddb->iscsi_name), sizeof(fw_ddb_entry->iscsi_name)));
4248 options = le16_to_cpu(fw_ddb_entry->options);
4249 if (options & DDB_OPT_IPV6_DEVICE)
4250 sprintf(tddb->ip_addr, "%pI6", fw_ddb_entry->ip_addr);
4252 sprintf(tddb->ip_addr, "%pI4", fw_ddb_entry->ip_addr);
4254 tddb->port = le16_to_cpu(fw_ddb_entry->port);
4255 memcpy(&tddb->isid[0], &fw_ddb_entry->isid[0], sizeof(tddb->isid));
4258 static int qla4xxx_compare_tuple_ddb(struct scsi_qla_host *ha,
4259 struct ql4_tuple_ddb *old_tddb,
4260 struct ql4_tuple_ddb *new_tddb,
4261 uint8_t is_isid_compare)
4263 if (strcmp(old_tddb->iscsi_name, new_tddb->iscsi_name))
4266 if (strcmp(old_tddb->ip_addr, new_tddb->ip_addr))
4269 if (old_tddb->port != new_tddb->port)
4272 /* For multi sessions, driver generates the ISID, so do not compare
4273 * ISID in reset path since it would be a comparision between the
4274 * driver generated ISID and firmware generated ISID. This could
4275 * lead to adding duplicated DDBs in the list as driver generated
4276 * ISID would not match firmware generated ISID.
4278 if (is_isid_compare) {
4279 DEBUG2(ql4_printk(KERN_INFO, ha, "%s: old ISID [%02x%02x%02x"
4280 "%02x%02x%02x] New ISID [%02x%02x%02x%02x%02x%02x]\n",
4281 __func__, old_tddb->isid[5], old_tddb->isid[4],
4282 old_tddb->isid[3], old_tddb->isid[2], old_tddb->isid[1],
4283 old_tddb->isid[0], new_tddb->isid[5], new_tddb->isid[4],
4284 new_tddb->isid[3], new_tddb->isid[2], new_tddb->isid[1],
4285 new_tddb->isid[0]));
4287 if (memcmp(&old_tddb->isid[0], &new_tddb->isid[0],
4288 sizeof(old_tddb->isid)))
4292 DEBUG2(ql4_printk(KERN_INFO, ha,
4293 "Match Found, fw[%d,%d,%s,%s], [%d,%d,%s,%s]",
4294 old_tddb->port, old_tddb->tpgt, old_tddb->ip_addr,
4295 old_tddb->iscsi_name, new_tddb->port, new_tddb->tpgt,
4296 new_tddb->ip_addr, new_tddb->iscsi_name));
4301 static int qla4xxx_is_session_exists(struct scsi_qla_host *ha,
4302 struct dev_db_entry *fw_ddb_entry)
4304 struct ddb_entry *ddb_entry;
4305 struct ql4_tuple_ddb *fw_tddb = NULL;
4306 struct ql4_tuple_ddb *tmp_tddb = NULL;
4308 int ret = QLA_ERROR;
4310 fw_tddb = vzalloc(sizeof(*fw_tddb));
4312 DEBUG2(ql4_printk(KERN_WARNING, ha,
4313 "Memory Allocation failed.\n"));
4318 tmp_tddb = vzalloc(sizeof(*tmp_tddb));
4320 DEBUG2(ql4_printk(KERN_WARNING, ha,
4321 "Memory Allocation failed.\n"));
4326 qla4xxx_convert_param_ddb(fw_ddb_entry, fw_tddb);
4328 for (idx = 0; idx < MAX_DDB_ENTRIES; idx++) {
4329 ddb_entry = qla4xxx_lookup_ddb_by_fw_index(ha, idx);
4330 if (ddb_entry == NULL)
4333 qla4xxx_get_param_ddb(ddb_entry, tmp_tddb);
4334 if (!qla4xxx_compare_tuple_ddb(ha, fw_tddb, tmp_tddb, false)) {
4335 ret = QLA_SUCCESS; /* found */
4348 static int qla4xxx_is_flash_ddb_exists(struct scsi_qla_host *ha,
4349 struct list_head *list_nt,
4350 struct dev_db_entry *fw_ddb_entry)
4352 struct qla_ddb_index *nt_ddb_idx, *nt_ddb_idx_tmp;
4353 struct ql4_tuple_ddb *fw_tddb = NULL;
4354 struct ql4_tuple_ddb *tmp_tddb = NULL;
4355 int ret = QLA_ERROR;
4357 fw_tddb = vzalloc(sizeof(*fw_tddb));
4359 DEBUG2(ql4_printk(KERN_WARNING, ha,
4360 "Memory Allocation failed.\n"));
4365 tmp_tddb = vzalloc(sizeof(*tmp_tddb));
4367 DEBUG2(ql4_printk(KERN_WARNING, ha,
4368 "Memory Allocation failed.\n"));
4373 qla4xxx_convert_param_ddb(fw_ddb_entry, fw_tddb);
4375 list_for_each_entry_safe(nt_ddb_idx, nt_ddb_idx_tmp, list_nt, list) {
4376 qla4xxx_convert_param_ddb(&nt_ddb_idx->fw_ddb, tmp_tddb);
4377 if (!qla4xxx_compare_tuple_ddb(ha, fw_tddb, tmp_tddb, true)) {
4378 ret = QLA_SUCCESS; /* found */
4391 static void qla4xxx_free_ddb_list(struct list_head *list_ddb)
4393 struct qla_ddb_index *ddb_idx, *ddb_idx_tmp;
4395 list_for_each_entry_safe(ddb_idx, ddb_idx_tmp, list_ddb, list) {
4396 list_del_init(&ddb_idx->list);
4401 static struct iscsi_endpoint *qla4xxx_get_ep_fwdb(struct scsi_qla_host *ha,
4402 struct dev_db_entry *fw_ddb_entry)
4404 struct iscsi_endpoint *ep;
4405 struct sockaddr_in *addr;
4406 struct sockaddr_in6 *addr6;
4407 struct sockaddr *dst_addr;
4410 /* TODO: need to destroy on unload iscsi_endpoint*/
4411 dst_addr = vmalloc(sizeof(*dst_addr));
4415 if (fw_ddb_entry->options & DDB_OPT_IPV6_DEVICE) {
4416 dst_addr->sa_family = AF_INET6;
4417 addr6 = (struct sockaddr_in6 *)dst_addr;
4418 ip = (char *)&addr6->sin6_addr;
4419 memcpy(ip, fw_ddb_entry->ip_addr, IPv6_ADDR_LEN);
4420 addr6->sin6_port = htons(le16_to_cpu(fw_ddb_entry->port));
4423 dst_addr->sa_family = AF_INET;
4424 addr = (struct sockaddr_in *)dst_addr;
4425 ip = (char *)&addr->sin_addr;
4426 memcpy(ip, fw_ddb_entry->ip_addr, IP_ADDR_LEN);
4427 addr->sin_port = htons(le16_to_cpu(fw_ddb_entry->port));
4430 ep = qla4xxx_ep_connect(ha->host, dst_addr, 0);
4435 static int qla4xxx_verify_boot_idx(struct scsi_qla_host *ha, uint16_t idx)
4437 if (ql4xdisablesysfsboot)
4439 if (idx == ha->pri_ddb_idx || idx == ha->sec_ddb_idx)
4444 static void qla4xxx_setup_flash_ddb_entry(struct scsi_qla_host *ha,
4445 struct ddb_entry *ddb_entry)
4447 uint16_t def_timeout;
4449 ddb_entry->ddb_type = FLASH_DDB;
4450 ddb_entry->fw_ddb_index = INVALID_ENTRY;
4451 ddb_entry->fw_ddb_device_state = DDB_DS_NO_CONNECTION_ACTIVE;
4453 ddb_entry->unblock_sess = qla4xxx_unblock_flash_ddb;
4454 ddb_entry->ddb_change = qla4xxx_flash_ddb_change;
4456 atomic_set(&ddb_entry->retry_relogin_timer, INVALID_ENTRY);
4457 atomic_set(&ddb_entry->relogin_timer, 0);
4458 atomic_set(&ddb_entry->relogin_retry_count, 0);
4459 def_timeout = le16_to_cpu(ddb_entry->fw_ddb_entry.def_timeout);
4460 ddb_entry->default_relogin_timeout =
4461 (def_timeout > LOGIN_TOV) && (def_timeout < LOGIN_TOV * 10) ?
4462 def_timeout : LOGIN_TOV;
4463 ddb_entry->default_time2wait =
4464 le16_to_cpu(ddb_entry->fw_ddb_entry.iscsi_def_time2wait);
4467 static void qla4xxx_wait_for_ip_configuration(struct scsi_qla_host *ha)
4470 uint32_t ip_idx[IP_ADDR_COUNT] = {0, 1, 2, 3}; /* 4 IP interfaces */
4471 uint32_t sts[MBOX_REG_COUNT];
4473 unsigned long wtime;
4476 wtime = jiffies + (HZ * IP_CONFIG_TOV);
4478 for (idx = 0; idx < IP_ADDR_COUNT; idx++) {
4479 if (ip_idx[idx] == -1)
4482 ret = qla4xxx_get_ip_state(ha, 0, ip_idx[idx], sts);
4484 if (ret == QLA_ERROR) {
4489 ip_state = (sts[1] & IP_STATE_MASK) >> IP_STATE_SHIFT;
4491 DEBUG2(ql4_printk(KERN_INFO, ha,
4492 "Waiting for IP state for idx = %d, state = 0x%x\n",
4493 ip_idx[idx], ip_state));
4494 if (ip_state == IP_ADDRSTATE_UNCONFIGURED ||
4495 ip_state == IP_ADDRSTATE_INVALID ||
4496 ip_state == IP_ADDRSTATE_PREFERRED ||
4497 ip_state == IP_ADDRSTATE_DEPRICATED ||
4498 ip_state == IP_ADDRSTATE_DISABLING)
4502 /* Break if all IP states checked */
4503 if ((ip_idx[0] == -1) &&
4504 (ip_idx[1] == -1) &&
4505 (ip_idx[2] == -1) &&
4508 schedule_timeout_uninterruptible(HZ);
4509 } while (time_after(wtime, jiffies));
4512 static void qla4xxx_build_st_list(struct scsi_qla_host *ha,
4513 struct list_head *list_st)
4515 struct qla_ddb_index *st_ddb_idx;
4518 struct dev_db_entry *fw_ddb_entry;
4519 dma_addr_t fw_ddb_dma;
4521 uint32_t idx = 0, next_idx = 0;
4522 uint32_t state = 0, conn_err = 0;
4523 uint16_t conn_id = 0;
4525 fw_ddb_entry = dma_pool_alloc(ha->fw_ddb_dma_pool, GFP_KERNEL,
4527 if (fw_ddb_entry == NULL) {
4528 DEBUG2(ql4_printk(KERN_ERR, ha, "Out of memory\n"));
4532 max_ddbs = is_qla40XX(ha) ? MAX_DEV_DB_ENTRIES_40XX :
4534 fw_idx_size = sizeof(struct qla_ddb_index);
4536 for (idx = 0; idx < max_ddbs; idx = next_idx) {
4537 ret = qla4xxx_get_fwddb_entry(ha, idx, fw_ddb_entry, fw_ddb_dma,
4538 NULL, &next_idx, &state,
4539 &conn_err, NULL, &conn_id);
4540 if (ret == QLA_ERROR)
4543 /* Ignore DDB if invalid state (unassigned) */
4544 if (state == DDB_DS_UNASSIGNED)
4545 goto continue_next_st;
4547 /* Check if ST, add to the list_st */
4548 if (strlen((char *) fw_ddb_entry->iscsi_name) != 0)
4549 goto continue_next_st;
4551 st_ddb_idx = vzalloc(fw_idx_size);
4555 st_ddb_idx->fw_ddb_idx = idx;
4557 list_add_tail(&st_ddb_idx->list, list_st);
4565 dma_pool_free(ha->fw_ddb_dma_pool, fw_ddb_entry, fw_ddb_dma);
4569 * qla4xxx_remove_failed_ddb - Remove inactive or failed ddb from list
4570 * @ha: pointer to adapter structure
4571 * @list_ddb: List from which failed ddb to be removed
4573 * Iterate over the list of DDBs and find and remove DDBs that are either in
4574 * no connection active state or failed state
4576 static void qla4xxx_remove_failed_ddb(struct scsi_qla_host *ha,
4577 struct list_head *list_ddb)
4579 struct qla_ddb_index *ddb_idx, *ddb_idx_tmp;
4580 uint32_t next_idx = 0;
4581 uint32_t state = 0, conn_err = 0;
4584 list_for_each_entry_safe(ddb_idx, ddb_idx_tmp, list_ddb, list) {
4585 ret = qla4xxx_get_fwddb_entry(ha, ddb_idx->fw_ddb_idx,
4586 NULL, 0, NULL, &next_idx, &state,
4587 &conn_err, NULL, NULL);
4588 if (ret == QLA_ERROR)
4591 if (state == DDB_DS_NO_CONNECTION_ACTIVE ||
4592 state == DDB_DS_SESSION_FAILED) {
4593 list_del_init(&ddb_idx->list);
4599 static int qla4xxx_sess_conn_setup(struct scsi_qla_host *ha,
4600 struct dev_db_entry *fw_ddb_entry,
4603 struct iscsi_cls_session *cls_sess;
4604 struct iscsi_session *sess;
4605 struct iscsi_cls_conn *cls_conn;
4606 struct iscsi_endpoint *ep;
4607 uint16_t cmds_max = 32;
4608 uint16_t conn_id = 0;
4609 uint32_t initial_cmdsn = 0;
4610 int ret = QLA_SUCCESS;
4612 struct ddb_entry *ddb_entry = NULL;
4614 /* Create session object, with INVALID_ENTRY,
4615 * the targer_id would get set when we issue the login
4617 cls_sess = iscsi_session_setup(&qla4xxx_iscsi_transport, ha->host,
4618 cmds_max, sizeof(struct ddb_entry),
4619 sizeof(struct ql4_task_data),
4620 initial_cmdsn, INVALID_ENTRY);
4627 * so calling module_put function to decrement the
4630 module_put(qla4xxx_iscsi_transport.owner);
4631 sess = cls_sess->dd_data;
4632 ddb_entry = sess->dd_data;
4633 ddb_entry->sess = cls_sess;
4635 cls_sess->recovery_tmo = ql4xsess_recovery_tmo;
4636 memcpy(&ddb_entry->fw_ddb_entry, fw_ddb_entry,
4637 sizeof(struct dev_db_entry));
4639 qla4xxx_setup_flash_ddb_entry(ha, ddb_entry);
4641 cls_conn = iscsi_conn_setup(cls_sess, sizeof(struct qla_conn), conn_id);
4648 ddb_entry->conn = cls_conn;
4650 /* Setup ep, for displaying attributes in sysfs */
4651 ep = qla4xxx_get_ep_fwdb(ha, fw_ddb_entry);
4653 ep->conn = cls_conn;
4656 DEBUG2(ql4_printk(KERN_ERR, ha, "Unable to get ep\n"));
4661 /* Update sess/conn params */
4662 qla4xxx_copy_fwddb_param(ha, fw_ddb_entry, cls_sess, cls_conn);
4664 if (is_reset == RESET_ADAPTER) {
4665 iscsi_block_session(cls_sess);
4666 /* Use the relogin path to discover new devices
4667 * by short-circuting the logic of setting
4668 * timer to relogin - instead set the flags
4669 * to initiate login right away.
4671 set_bit(DPC_RELOGIN_DEVICE, &ha->dpc_flags);
4672 set_bit(DF_RELOGIN, &ddb_entry->flags);
4679 static void qla4xxx_build_nt_list(struct scsi_qla_host *ha,
4680 struct list_head *list_nt, int is_reset)
4682 struct dev_db_entry *fw_ddb_entry;
4683 dma_addr_t fw_ddb_dma;
4687 uint32_t idx = 0, next_idx = 0;
4688 uint32_t state = 0, conn_err = 0;
4689 uint16_t conn_id = 0;
4690 struct qla_ddb_index *nt_ddb_idx;
4692 fw_ddb_entry = dma_pool_alloc(ha->fw_ddb_dma_pool, GFP_KERNEL,
4694 if (fw_ddb_entry == NULL) {
4695 DEBUG2(ql4_printk(KERN_ERR, ha, "Out of memory\n"));
4698 max_ddbs = is_qla40XX(ha) ? MAX_DEV_DB_ENTRIES_40XX :
4700 fw_idx_size = sizeof(struct qla_ddb_index);
4702 for (idx = 0; idx < max_ddbs; idx = next_idx) {
4703 ret = qla4xxx_get_fwddb_entry(ha, idx, fw_ddb_entry, fw_ddb_dma,
4704 NULL, &next_idx, &state,
4705 &conn_err, NULL, &conn_id);
4706 if (ret == QLA_ERROR)
4709 if (qla4xxx_verify_boot_idx(ha, idx) != QLA_SUCCESS)
4710 goto continue_next_nt;
4712 /* Check if NT, then add to list it */
4713 if (strlen((char *) fw_ddb_entry->iscsi_name) == 0)
4714 goto continue_next_nt;
4716 if (!(state == DDB_DS_NO_CONNECTION_ACTIVE ||
4717 state == DDB_DS_SESSION_FAILED))
4718 goto continue_next_nt;
4720 DEBUG2(ql4_printk(KERN_INFO, ha,
4721 "Adding DDB to session = 0x%x\n", idx));
4722 if (is_reset == INIT_ADAPTER) {
4723 nt_ddb_idx = vmalloc(fw_idx_size);
4727 nt_ddb_idx->fw_ddb_idx = idx;
4729 memcpy(&nt_ddb_idx->fw_ddb, fw_ddb_entry,
4730 sizeof(struct dev_db_entry));
4732 if (qla4xxx_is_flash_ddb_exists(ha, list_nt,
4733 fw_ddb_entry) == QLA_SUCCESS) {
4735 goto continue_next_nt;
4737 list_add_tail(&nt_ddb_idx->list, list_nt);
4738 } else if (is_reset == RESET_ADAPTER) {
4739 if (qla4xxx_is_session_exists(ha, fw_ddb_entry) ==
4741 goto continue_next_nt;
4744 ret = qla4xxx_sess_conn_setup(ha, fw_ddb_entry, is_reset);
4745 if (ret == QLA_ERROR)
4755 dma_pool_free(ha->fw_ddb_dma_pool, fw_ddb_entry, fw_ddb_dma);
4759 * qla4xxx_build_ddb_list - Build ddb list and setup sessions
4760 * @ha: pointer to adapter structure
4761 * @is_reset: Is this init path or reset path
4763 * Create a list of sendtargets (st) from firmware DDBs, issue send targets
4764 * using connection open, then create the list of normal targets (nt)
4765 * from firmware DDBs. Based on the list of nt setup session and connection
4768 void qla4xxx_build_ddb_list(struct scsi_qla_host *ha, int is_reset)
4771 struct list_head list_st, list_nt;
4772 struct qla_ddb_index *st_ddb_idx, *st_ddb_idx_tmp;
4773 unsigned long wtime;
4775 if (!test_bit(AF_LINK_UP, &ha->flags)) {
4776 set_bit(AF_BUILD_DDB_LIST, &ha->flags);
4777 ha->is_reset = is_reset;
4781 INIT_LIST_HEAD(&list_st);
4782 INIT_LIST_HEAD(&list_nt);
4784 qla4xxx_build_st_list(ha, &list_st);
4786 /* Before issuing conn open mbox, ensure all IPs states are configured
4787 * Note, conn open fails if IPs are not configured
4789 qla4xxx_wait_for_ip_configuration(ha);
4791 /* Go thru the STs and fire the sendtargets by issuing conn open mbx */
4792 list_for_each_entry_safe(st_ddb_idx, st_ddb_idx_tmp, &list_st, list) {
4793 qla4xxx_conn_open(ha, st_ddb_idx->fw_ddb_idx);
4796 /* Wait to ensure all sendtargets are done for min 12 sec wait */
4797 tmo = ((ha->def_timeout > LOGIN_TOV) &&
4798 (ha->def_timeout < LOGIN_TOV * 10) ?
4799 ha->def_timeout : LOGIN_TOV);
4801 DEBUG2(ql4_printk(KERN_INFO, ha,
4802 "Default time to wait for build ddb %d\n", tmo));
4804 wtime = jiffies + (HZ * tmo);
4806 if (list_empty(&list_st))
4809 qla4xxx_remove_failed_ddb(ha, &list_st);
4810 schedule_timeout_uninterruptible(HZ / 10);
4811 } while (time_after(wtime, jiffies));
4813 /* Free up the sendtargets list */
4814 qla4xxx_free_ddb_list(&list_st);
4816 qla4xxx_build_nt_list(ha, &list_nt, is_reset);
4818 qla4xxx_free_ddb_list(&list_nt);
4820 qla4xxx_free_ddb_index(ha);
4824 * qla4xxx_probe_adapter - callback function to probe HBA
4825 * @pdev: pointer to pci_dev structure
4826 * @pci_device_id: pointer to pci_device entry
4828 * This routine will probe for Qlogic 4xxx iSCSI host adapters.
4829 * It returns zero if successful. It also initializes all data necessary for
4832 static int __devinit qla4xxx_probe_adapter(struct pci_dev *pdev,
4833 const struct pci_device_id *ent)
4835 int ret = -ENODEV, status;
4836 struct Scsi_Host *host;
4837 struct scsi_qla_host *ha;
4838 uint8_t init_retry_count = 0;
4840 struct qla4_8xxx_legacy_intr_set *nx_legacy_intr;
4843 if (pci_enable_device(pdev))
4846 host = iscsi_host_alloc(&qla4xxx_driver_template, sizeof(*ha), 0);
4849 "qla4xxx: Couldn't allocate host from scsi layer!\n");
4850 goto probe_disable_device;
4853 /* Clear our data area */
4854 ha = to_qla_host(host);
4855 memset(ha, 0, sizeof(*ha));
4857 /* Save the information from PCI BIOS. */
4860 ha->host_no = host->host_no;
4862 pci_enable_pcie_error_reporting(pdev);
4864 /* Setup Runtime configurable options */
4865 if (is_qla8022(ha)) {
4866 ha->isp_ops = &qla4_8xxx_isp_ops;
4867 rwlock_init(&ha->hw_lock);
4868 ha->qdr_sn_window = -1;
4869 ha->ddr_mn_window = -1;
4870 ha->curr_window = 255;
4871 ha->func_num = PCI_FUNC(ha->pdev->devfn);
4872 nx_legacy_intr = &legacy_intr[ha->func_num];
4873 ha->nx_legacy_intr.int_vec_bit = nx_legacy_intr->int_vec_bit;
4874 ha->nx_legacy_intr.tgt_status_reg =
4875 nx_legacy_intr->tgt_status_reg;
4876 ha->nx_legacy_intr.tgt_mask_reg = nx_legacy_intr->tgt_mask_reg;
4877 ha->nx_legacy_intr.pci_int_reg = nx_legacy_intr->pci_int_reg;
4879 ha->isp_ops = &qla4xxx_isp_ops;
4882 /* Set EEH reset type to fundamental if required by hba */
4884 pdev->needs_freset = 1;
4886 /* Configure PCI I/O space. */
4887 ret = ha->isp_ops->iospace_config(ha);
4889 goto probe_failed_ioconfig;
4891 ql4_printk(KERN_INFO, ha, "Found an ISP%04x, irq %d, iobase 0x%p\n",
4892 pdev->device, pdev->irq, ha->reg);
4894 qla4xxx_config_dma_addressing(ha);
4896 /* Initialize lists and spinlocks. */
4897 INIT_LIST_HEAD(&ha->free_srb_q);
4899 mutex_init(&ha->mbox_sem);
4900 mutex_init(&ha->chap_sem);
4901 init_completion(&ha->mbx_intr_comp);
4902 init_completion(&ha->disable_acb_comp);
4904 spin_lock_init(&ha->hardware_lock);
4906 /* Initialize work list */
4907 INIT_LIST_HEAD(&ha->work_list);
4909 /* Allocate dma buffers */
4910 if (qla4xxx_mem_alloc(ha)) {
4911 ql4_printk(KERN_WARNING, ha,
4912 "[ERROR] Failed to allocate memory for adapter\n");
4918 host->cmd_per_lun = 3;
4919 host->max_channel = 0;
4920 host->max_lun = MAX_LUNS - 1;
4921 host->max_id = MAX_TARGETS;
4922 host->max_cmd_len = IOCB_MAX_CDB_LEN;
4923 host->can_queue = MAX_SRBS ;
4924 host->transportt = qla4xxx_scsi_transport;
4926 ret = scsi_init_shared_tag_map(host, MAX_SRBS);
4928 ql4_printk(KERN_WARNING, ha,
4929 "%s: scsi_init_shared_tag_map failed\n", __func__);
4933 pci_set_drvdata(pdev, ha);
4935 ret = scsi_add_host(host, &pdev->dev);
4940 (void) qla4_8xxx_get_flash_info(ha);
4943 * Initialize the Host adapter request/response queues and
4945 * NOTE: interrupts enabled upon successful completion
4947 status = qla4xxx_initialize_adapter(ha, INIT_ADAPTER);
4948 while ((!test_bit(AF_ONLINE, &ha->flags)) &&
4949 init_retry_count++ < MAX_INIT_RETRIES) {
4951 if (is_qla8022(ha)) {
4952 qla4_8xxx_idc_lock(ha);
4953 dev_state = qla4_8xxx_rd_32(ha, QLA82XX_CRB_DEV_STATE);
4954 qla4_8xxx_idc_unlock(ha);
4955 if (dev_state == QLA82XX_DEV_FAILED) {
4956 ql4_printk(KERN_WARNING, ha, "%s: don't retry "
4957 "initialize adapter. H/W is in failed state\n",
4962 DEBUG2(printk("scsi: %s: retrying adapter initialization "
4963 "(%d)\n", __func__, init_retry_count));
4965 if (ha->isp_ops->reset_chip(ha) == QLA_ERROR)
4968 status = qla4xxx_initialize_adapter(ha, INIT_ADAPTER);
4971 if (!test_bit(AF_ONLINE, &ha->flags)) {
4972 ql4_printk(KERN_WARNING, ha, "Failed to initialize adapter\n");
4974 if (is_qla8022(ha) && ql4xdontresethba) {
4975 /* Put the device in failed state. */
4976 DEBUG2(printk(KERN_ERR "HW STATE: FAILED\n"));
4977 qla4_8xxx_idc_lock(ha);
4978 qla4_8xxx_wr_32(ha, QLA82XX_CRB_DEV_STATE,
4979 QLA82XX_DEV_FAILED);
4980 qla4_8xxx_idc_unlock(ha);
4986 /* Startup the kernel thread for this host adapter. */
4987 DEBUG2(printk("scsi: %s: Starting kernel thread for "
4988 "qla4xxx_dpc\n", __func__));
4989 sprintf(buf, "qla4xxx_%lu_dpc", ha->host_no);
4990 ha->dpc_thread = create_singlethread_workqueue(buf);
4991 if (!ha->dpc_thread) {
4992 ql4_printk(KERN_WARNING, ha, "Unable to start DPC thread!\n");
4996 INIT_WORK(&ha->dpc_work, qla4xxx_do_dpc);
4998 sprintf(buf, "qla4xxx_%lu_task", ha->host_no);
4999 ha->task_wq = alloc_workqueue(buf, WQ_MEM_RECLAIM, 1);
5001 ql4_printk(KERN_WARNING, ha, "Unable to start task thread!\n");
5006 /* For ISP-82XX, request_irqs is called in qla4_8xxx_load_risc
5007 * (which is called indirectly by qla4xxx_initialize_adapter),
5008 * so that irqs will be registered after crbinit but before
5011 if (!is_qla8022(ha)) {
5012 ret = qla4xxx_request_irqs(ha);
5014 ql4_printk(KERN_WARNING, ha, "Failed to reserve "
5015 "interrupt %d already in use.\n", pdev->irq);
5020 pci_save_state(ha->pdev);
5021 ha->isp_ops->enable_intrs(ha);
5023 /* Start timer thread. */
5024 qla4xxx_start_timer(ha, qla4xxx_timer, 1);
5026 set_bit(AF_INIT_DONE, &ha->flags);
5029 " QLogic iSCSI HBA Driver version: %s\n"
5030 " QLogic ISP%04x @ %s, host#=%ld, fw=%02d.%02d.%02d.%02d\n",
5031 qla4xxx_version_str, ha->pdev->device, pci_name(ha->pdev),
5032 ha->host_no, ha->firmware_version[0], ha->firmware_version[1],
5033 ha->patch_number, ha->build_number);
5035 if (qla4xxx_setup_boot_info(ha))
5036 ql4_printk(KERN_ERR, ha,
5037 "%s: No iSCSI boot target configured\n", __func__);
5039 /* Perform the build ddb list and login to each */
5040 qla4xxx_build_ddb_list(ha, INIT_ADAPTER);
5041 iscsi_host_for_each_session(ha->host, qla4xxx_login_flash_ddb);
5043 qla4xxx_create_chap_list(ha);
5045 qla4xxx_create_ifaces(ha);
5049 scsi_remove_host(ha->host);
5052 qla4xxx_free_adapter(ha);
5054 probe_failed_ioconfig:
5055 pci_disable_pcie_error_reporting(pdev);
5056 scsi_host_put(ha->host);
5058 probe_disable_device:
5059 pci_disable_device(pdev);
5065 * qla4xxx_prevent_other_port_reinit - prevent other port from re-initialize
5066 * @ha: pointer to adapter structure
5068 * Mark the other ISP-4xxx port to indicate that the driver is being removed,
5069 * so that the other port will not re-initialize while in the process of
5070 * removing the ha due to driver unload or hba hotplug.
5072 static void qla4xxx_prevent_other_port_reinit(struct scsi_qla_host *ha)
5074 struct scsi_qla_host *other_ha = NULL;
5075 struct pci_dev *other_pdev = NULL;
5076 int fn = ISP4XXX_PCI_FN_2;
5078 /*iscsi function numbers for ISP4xxx is 1 and 3*/
5079 if (PCI_FUNC(ha->pdev->devfn) & BIT_1)
5080 fn = ISP4XXX_PCI_FN_1;
5083 pci_get_domain_bus_and_slot(pci_domain_nr(ha->pdev->bus),
5084 ha->pdev->bus->number, PCI_DEVFN(PCI_SLOT(ha->pdev->devfn),
5087 /* Get other_ha if other_pdev is valid and state is enable*/
5089 if (atomic_read(&other_pdev->enable_cnt)) {
5090 other_ha = pci_get_drvdata(other_pdev);
5092 set_bit(AF_HA_REMOVAL, &other_ha->flags);
5093 DEBUG2(ql4_printk(KERN_INFO, ha, "%s: "
5094 "Prevent %s reinit\n", __func__,
5095 dev_name(&other_ha->pdev->dev)));
5098 pci_dev_put(other_pdev);
5102 static void qla4xxx_destroy_fw_ddb_session(struct scsi_qla_host *ha)
5104 struct ddb_entry *ddb_entry;
5108 for (idx = 0; idx < MAX_DDB_ENTRIES; idx++) {
5110 ddb_entry = qla4xxx_lookup_ddb_by_fw_index(ha, idx);
5111 if ((ddb_entry != NULL) &&
5112 (ddb_entry->ddb_type == FLASH_DDB)) {
5114 options = LOGOUT_OPTION_CLOSE_SESSION;
5115 if (qla4xxx_session_logout_ddb(ha, ddb_entry, options)
5117 ql4_printk(KERN_ERR, ha, "%s: Logout failed\n",
5120 qla4xxx_clear_ddb_entry(ha, ddb_entry->fw_ddb_index);
5122 * we have decremented the reference count of the driver
5123 * when we setup the session to have the driver unload
5124 * to be seamless without actually destroying the
5127 try_module_get(qla4xxx_iscsi_transport.owner);
5128 iscsi_destroy_endpoint(ddb_entry->conn->ep);
5129 qla4xxx_free_ddb(ha, ddb_entry);
5130 iscsi_session_teardown(ddb_entry->sess);
5135 * qla4xxx_remove_adapter - calback function to remove adapter.
5136 * @pci_dev: PCI device pointer
5138 static void __devexit qla4xxx_remove_adapter(struct pci_dev *pdev)
5140 struct scsi_qla_host *ha;
5142 ha = pci_get_drvdata(pdev);
5144 if (!is_qla8022(ha))
5145 qla4xxx_prevent_other_port_reinit(ha);
5147 /* destroy iface from sysfs */
5148 qla4xxx_destroy_ifaces(ha);
5150 if ((!ql4xdisablesysfsboot) && ha->boot_kset)
5151 iscsi_boot_destroy_kset(ha->boot_kset);
5153 qla4xxx_destroy_fw_ddb_session(ha);
5155 scsi_remove_host(ha->host);
5157 qla4xxx_free_adapter(ha);
5159 scsi_host_put(ha->host);
5161 pci_disable_pcie_error_reporting(pdev);
5162 pci_disable_device(pdev);
5163 pci_set_drvdata(pdev, NULL);
5167 * qla4xxx_config_dma_addressing() - Configure OS DMA addressing method.
5170 * At exit, the @ha's flags.enable_64bit_addressing set to indicated
5171 * supported addressing method.
5173 static void qla4xxx_config_dma_addressing(struct scsi_qla_host *ha)
5177 /* Update our PCI device dma_mask for full 64 bit mask */
5178 if (pci_set_dma_mask(ha->pdev, DMA_BIT_MASK(64)) == 0) {
5179 if (pci_set_consistent_dma_mask(ha->pdev, DMA_BIT_MASK(64))) {
5180 dev_dbg(&ha->pdev->dev,
5181 "Failed to set 64 bit PCI consistent mask; "
5183 retval = pci_set_consistent_dma_mask(ha->pdev,
5187 retval = pci_set_dma_mask(ha->pdev, DMA_BIT_MASK(32));
5190 static int qla4xxx_slave_alloc(struct scsi_device *sdev)
5192 struct iscsi_cls_session *cls_sess;
5193 struct iscsi_session *sess;
5194 struct ddb_entry *ddb;
5195 int queue_depth = QL4_DEF_QDEPTH;
5197 cls_sess = starget_to_session(sdev->sdev_target);
5198 sess = cls_sess->dd_data;
5199 ddb = sess->dd_data;
5201 sdev->hostdata = ddb;
5202 sdev->tagged_supported = 1;
5204 if (ql4xmaxqdepth != 0 && ql4xmaxqdepth <= 0xffffU)
5205 queue_depth = ql4xmaxqdepth;
5207 scsi_activate_tcq(sdev, queue_depth);
5211 static int qla4xxx_slave_configure(struct scsi_device *sdev)
5213 sdev->tagged_supported = 1;
5217 static void qla4xxx_slave_destroy(struct scsi_device *sdev)
5219 scsi_deactivate_tcq(sdev, 1);
5223 * qla4xxx_del_from_active_array - returns an active srb
5224 * @ha: Pointer to host adapter structure.
5225 * @index: index into the active_array
5227 * This routine removes and returns the srb at the specified index
5229 struct srb *qla4xxx_del_from_active_array(struct scsi_qla_host *ha,
5232 struct srb *srb = NULL;
5233 struct scsi_cmnd *cmd = NULL;
5235 cmd = scsi_host_find_tag(ha->host, index);
5239 srb = (struct srb *)CMD_SP(cmd);
5243 /* update counters */
5244 if (srb->flags & SRB_DMA_VALID) {
5245 ha->req_q_count += srb->iocb_cnt;
5246 ha->iocb_cnt -= srb->iocb_cnt;
5248 srb->cmd->host_scribble =
5249 (unsigned char *)(unsigned long) MAX_SRBS;
5255 * qla4xxx_eh_wait_on_command - waits for command to be returned by firmware
5256 * @ha: Pointer to host adapter structure.
5257 * @cmd: Scsi Command to wait on.
5259 * This routine waits for the command to be returned by the Firmware
5260 * for some max time.
5262 static int qla4xxx_eh_wait_on_command(struct scsi_qla_host *ha,
5263 struct scsi_cmnd *cmd)
5267 uint32_t max_wait_time = EH_WAIT_CMD_TOV;
5270 /* Dont wait on command if PCI error is being handled
5273 if (unlikely(pci_channel_offline(ha->pdev)) ||
5274 (test_bit(AF_EEH_BUSY, &ha->flags))) {
5275 ql4_printk(KERN_WARNING, ha, "scsi%ld: Return from %s\n",
5276 ha->host_no, __func__);
5281 /* Checking to see if its returned to OS */
5282 rp = (struct srb *) CMD_SP(cmd);
5289 } while (max_wait_time--);
5295 * qla4xxx_wait_for_hba_online - waits for HBA to come online
5296 * @ha: Pointer to host adapter structure
5298 static int qla4xxx_wait_for_hba_online(struct scsi_qla_host *ha)
5300 unsigned long wait_online;
5302 wait_online = jiffies + (HBA_ONLINE_TOV * HZ);
5303 while (time_before(jiffies, wait_online)) {
5315 * qla4xxx_eh_wait_for_commands - wait for active cmds to finish.
5316 * @ha: pointer to HBA
5320 * This function waits for all outstanding commands to a lun to complete. It
5321 * returns 0 if all pending commands are returned and 1 otherwise.
5323 static int qla4xxx_eh_wait_for_commands(struct scsi_qla_host *ha,
5324 struct scsi_target *stgt,
5325 struct scsi_device *sdev)
5329 struct scsi_cmnd *cmd;
5332 * Waiting for all commands for the designated target or dev
5333 * in the active array
5335 for (cnt = 0; cnt < ha->host->can_queue; cnt++) {
5336 cmd = scsi_host_find_tag(ha->host, cnt);
5337 if (cmd && stgt == scsi_target(cmd->device) &&
5338 (!sdev || sdev == cmd->device)) {
5339 if (!qla4xxx_eh_wait_on_command(ha, cmd)) {
5349 * qla4xxx_eh_abort - callback for abort task.
5350 * @cmd: Pointer to Linux's SCSI command structure
5352 * This routine is called by the Linux OS to abort the specified
5355 static int qla4xxx_eh_abort(struct scsi_cmnd *cmd)
5357 struct scsi_qla_host *ha = to_qla_host(cmd->device->host);
5358 unsigned int id = cmd->device->id;
5359 unsigned int lun = cmd->device->lun;
5360 unsigned long flags;
5361 struct srb *srb = NULL;
5365 ql4_printk(KERN_INFO, ha,
5366 "scsi%ld:%d:%d: Abort command issued cmd=%p\n",
5367 ha->host_no, id, lun, cmd);
5369 spin_lock_irqsave(&ha->hardware_lock, flags);
5370 srb = (struct srb *) CMD_SP(cmd);
5372 spin_unlock_irqrestore(&ha->hardware_lock, flags);
5375 kref_get(&srb->srb_ref);
5376 spin_unlock_irqrestore(&ha->hardware_lock, flags);
5378 if (qla4xxx_abort_task(ha, srb) != QLA_SUCCESS) {
5379 DEBUG3(printk("scsi%ld:%d:%d: Abort_task mbx failed.\n",
5380 ha->host_no, id, lun));
5383 DEBUG3(printk("scsi%ld:%d:%d: Abort_task mbx success.\n",
5384 ha->host_no, id, lun));
5388 kref_put(&srb->srb_ref, qla4xxx_srb_compl);
5390 /* Wait for command to complete */
5392 if (!qla4xxx_eh_wait_on_command(ha, cmd)) {
5393 DEBUG2(printk("scsi%ld:%d:%d: Abort handler timed out\n",
5394 ha->host_no, id, lun));
5399 ql4_printk(KERN_INFO, ha,
5400 "scsi%ld:%d:%d: Abort command - %s\n",
5401 ha->host_no, id, lun, (ret == SUCCESS) ? "succeeded" : "failed");
5407 * qla4xxx_eh_device_reset - callback for target reset.
5408 * @cmd: Pointer to Linux's SCSI command structure
5410 * This routine is called by the Linux OS to reset all luns on the
5413 static int qla4xxx_eh_device_reset(struct scsi_cmnd *cmd)
5415 struct scsi_qla_host *ha = to_qla_host(cmd->device->host);
5416 struct ddb_entry *ddb_entry = cmd->device->hostdata;
5417 int ret = FAILED, stat;
5422 ret = iscsi_block_scsi_eh(cmd);
5427 ql4_printk(KERN_INFO, ha,
5428 "scsi%ld:%d:%d:%d: DEVICE RESET ISSUED.\n", ha->host_no,
5429 cmd->device->channel, cmd->device->id, cmd->device->lun);
5431 DEBUG2(printk(KERN_INFO
5432 "scsi%ld: DEVICE_RESET cmd=%p jiffies = 0x%lx, to=%x,"
5433 "dpc_flags=%lx, status=%x allowed=%d\n", ha->host_no,
5434 cmd, jiffies, cmd->request->timeout / HZ,
5435 ha->dpc_flags, cmd->result, cmd->allowed));
5437 /* FIXME: wait for hba to go online */
5438 stat = qla4xxx_reset_lun(ha, ddb_entry, cmd->device->lun);
5439 if (stat != QLA_SUCCESS) {
5440 ql4_printk(KERN_INFO, ha, "DEVICE RESET FAILED. %d\n", stat);
5441 goto eh_dev_reset_done;
5444 if (qla4xxx_eh_wait_for_commands(ha, scsi_target(cmd->device),
5446 ql4_printk(KERN_INFO, ha,
5447 "DEVICE RESET FAILED - waiting for "
5449 goto eh_dev_reset_done;
5453 if (qla4xxx_send_marker_iocb(ha, ddb_entry, cmd->device->lun,
5454 MM_LUN_RESET) != QLA_SUCCESS)
5455 goto eh_dev_reset_done;
5457 ql4_printk(KERN_INFO, ha,
5458 "scsi(%ld:%d:%d:%d): DEVICE RESET SUCCEEDED.\n",
5459 ha->host_no, cmd->device->channel, cmd->device->id,
5470 * qla4xxx_eh_target_reset - callback for target reset.
5471 * @cmd: Pointer to Linux's SCSI command structure
5473 * This routine is called by the Linux OS to reset the target.
5475 static int qla4xxx_eh_target_reset(struct scsi_cmnd *cmd)
5477 struct scsi_qla_host *ha = to_qla_host(cmd->device->host);
5478 struct ddb_entry *ddb_entry = cmd->device->hostdata;
5484 ret = iscsi_block_scsi_eh(cmd);
5488 starget_printk(KERN_INFO, scsi_target(cmd->device),
5489 "WARM TARGET RESET ISSUED.\n");
5491 DEBUG2(printk(KERN_INFO
5492 "scsi%ld: TARGET_DEVICE_RESET cmd=%p jiffies = 0x%lx, "
5493 "to=%x,dpc_flags=%lx, status=%x allowed=%d\n",
5494 ha->host_no, cmd, jiffies, cmd->request->timeout / HZ,
5495 ha->dpc_flags, cmd->result, cmd->allowed));
5497 stat = qla4xxx_reset_target(ha, ddb_entry);
5498 if (stat != QLA_SUCCESS) {
5499 starget_printk(KERN_INFO, scsi_target(cmd->device),
5500 "WARM TARGET RESET FAILED.\n");
5504 if (qla4xxx_eh_wait_for_commands(ha, scsi_target(cmd->device),
5506 starget_printk(KERN_INFO, scsi_target(cmd->device),
5507 "WARM TARGET DEVICE RESET FAILED - "
5508 "waiting for commands.\n");
5513 if (qla4xxx_send_marker_iocb(ha, ddb_entry, cmd->device->lun,
5514 MM_TGT_WARM_RESET) != QLA_SUCCESS) {
5515 starget_printk(KERN_INFO, scsi_target(cmd->device),
5516 "WARM TARGET DEVICE RESET FAILED - "
5517 "marker iocb failed.\n");
5521 starget_printk(KERN_INFO, scsi_target(cmd->device),
5522 "WARM TARGET RESET SUCCEEDED.\n");
5527 * qla4xxx_is_eh_active - check if error handler is running
5528 * @shost: Pointer to SCSI Host struct
5530 * This routine finds that if reset host is called in EH
5531 * scenario or from some application like sg_reset
5533 static int qla4xxx_is_eh_active(struct Scsi_Host *shost)
5535 if (shost->shost_state == SHOST_RECOVERY)
5541 * qla4xxx_eh_host_reset - kernel callback
5542 * @cmd: Pointer to Linux's SCSI command structure
5544 * This routine is invoked by the Linux kernel to perform fatal error
5545 * recovery on the specified adapter.
5547 static int qla4xxx_eh_host_reset(struct scsi_cmnd *cmd)
5549 int return_status = FAILED;
5550 struct scsi_qla_host *ha;
5552 ha = to_qla_host(cmd->device->host);
5554 if (ql4xdontresethba) {
5555 DEBUG2(printk("scsi%ld: %s: Don't Reset HBA\n",
5556 ha->host_no, __func__));
5558 /* Clear outstanding srb in queues */
5559 if (qla4xxx_is_eh_active(cmd->device->host))
5560 qla4xxx_abort_active_cmds(ha, DID_ABORT << 16);
5565 ql4_printk(KERN_INFO, ha,
5566 "scsi(%ld:%d:%d:%d): HOST RESET ISSUED.\n", ha->host_no,
5567 cmd->device->channel, cmd->device->id, cmd->device->lun);
5569 if (qla4xxx_wait_for_hba_online(ha) != QLA_SUCCESS) {
5570 DEBUG2(printk("scsi%ld:%d: %s: Unable to reset host. Adapter "
5571 "DEAD.\n", ha->host_no, cmd->device->channel,
5577 if (!test_bit(DPC_RESET_HA, &ha->dpc_flags)) {
5579 set_bit(DPC_RESET_HA_FW_CONTEXT, &ha->dpc_flags);
5581 set_bit(DPC_RESET_HA, &ha->dpc_flags);
5584 if (qla4xxx_recover_adapter(ha) == QLA_SUCCESS)
5585 return_status = SUCCESS;
5587 ql4_printk(KERN_INFO, ha, "HOST RESET %s.\n",
5588 return_status == FAILED ? "FAILED" : "SUCCEEDED");
5590 return return_status;
5593 static int qla4xxx_context_reset(struct scsi_qla_host *ha)
5595 uint32_t mbox_cmd[MBOX_REG_COUNT];
5596 uint32_t mbox_sts[MBOX_REG_COUNT];
5597 struct addr_ctrl_blk_def *acb = NULL;
5598 uint32_t acb_len = sizeof(struct addr_ctrl_blk_def);
5599 int rval = QLA_SUCCESS;
5602 acb = dma_alloc_coherent(&ha->pdev->dev,
5603 sizeof(struct addr_ctrl_blk_def),
5604 &acb_dma, GFP_KERNEL);
5606 ql4_printk(KERN_ERR, ha, "%s: Unable to alloc acb\n",
5609 goto exit_port_reset;
5612 memset(acb, 0, acb_len);
5614 rval = qla4xxx_get_acb(ha, acb_dma, PRIMARI_ACB, acb_len);
5615 if (rval != QLA_SUCCESS) {
5620 rval = qla4xxx_disable_acb(ha);
5621 if (rval != QLA_SUCCESS) {
5626 wait_for_completion_timeout(&ha->disable_acb_comp,
5627 DISABLE_ACB_TOV * HZ);
5629 rval = qla4xxx_set_acb(ha, &mbox_cmd[0], &mbox_sts[0], acb_dma);
5630 if (rval != QLA_SUCCESS) {
5636 dma_free_coherent(&ha->pdev->dev, sizeof(struct addr_ctrl_blk_def),
5639 DEBUG2(ql4_printk(KERN_INFO, ha, "%s %s\n", __func__,
5640 rval == QLA_SUCCESS ? "SUCCEEDED" : "FAILED"));
5644 static int qla4xxx_host_reset(struct Scsi_Host *shost, int reset_type)
5646 struct scsi_qla_host *ha = to_qla_host(shost);
5647 int rval = QLA_SUCCESS;
5649 if (ql4xdontresethba) {
5650 DEBUG2(ql4_printk(KERN_INFO, ha, "%s: Don't Reset HBA\n",
5653 goto exit_host_reset;
5656 rval = qla4xxx_wait_for_hba_online(ha);
5657 if (rval != QLA_SUCCESS) {
5658 DEBUG2(ql4_printk(KERN_INFO, ha, "%s: Unable to reset host "
5659 "adapter\n", __func__));
5661 goto exit_host_reset;
5664 if (test_bit(DPC_RESET_HA, &ha->dpc_flags))
5665 goto recover_adapter;
5667 switch (reset_type) {
5668 case SCSI_ADAPTER_RESET:
5669 set_bit(DPC_RESET_HA, &ha->dpc_flags);
5671 case SCSI_FIRMWARE_RESET:
5672 if (!test_bit(DPC_RESET_HA, &ha->dpc_flags)) {
5674 /* set firmware context reset */
5675 set_bit(DPC_RESET_HA_FW_CONTEXT,
5678 rval = qla4xxx_context_reset(ha);
5679 goto exit_host_reset;
5686 rval = qla4xxx_recover_adapter(ha);
5687 if (rval != QLA_SUCCESS) {
5688 DEBUG2(ql4_printk(KERN_INFO, ha, "%s: recover adapter fail\n",
5697 /* PCI AER driver recovers from all correctable errors w/o
5698 * driver intervention. For uncorrectable errors PCI AER
5699 * driver calls the following device driver's callbacks
5701 * - Fatal Errors - link_reset
5702 * - Non-Fatal Errors - driver's pci_error_detected() which
5703 * returns CAN_RECOVER, NEED_RESET or DISCONNECT.
5705 * PCI AER driver calls
5706 * CAN_RECOVER - driver's pci_mmio_enabled(), mmio_enabled
5707 * returns RECOVERED or NEED_RESET if fw_hung
5708 * NEED_RESET - driver's slot_reset()
5709 * DISCONNECT - device is dead & cannot recover
5710 * RECOVERED - driver's pci_resume()
5712 static pci_ers_result_t
5713 qla4xxx_pci_error_detected(struct pci_dev *pdev, pci_channel_state_t state)
5715 struct scsi_qla_host *ha = pci_get_drvdata(pdev);
5717 ql4_printk(KERN_WARNING, ha, "scsi%ld: %s: error detected:state %x\n",
5718 ha->host_no, __func__, state);
5720 if (!is_aer_supported(ha))
5721 return PCI_ERS_RESULT_NONE;
5724 case pci_channel_io_normal:
5725 clear_bit(AF_EEH_BUSY, &ha->flags);
5726 return PCI_ERS_RESULT_CAN_RECOVER;
5727 case pci_channel_io_frozen:
5728 set_bit(AF_EEH_BUSY, &ha->flags);
5729 qla4xxx_mailbox_premature_completion(ha);
5730 qla4xxx_free_irqs(ha);
5731 pci_disable_device(pdev);
5732 /* Return back all IOs */
5733 qla4xxx_abort_active_cmds(ha, DID_RESET << 16);
5734 return PCI_ERS_RESULT_NEED_RESET;
5735 case pci_channel_io_perm_failure:
5736 set_bit(AF_EEH_BUSY, &ha->flags);
5737 set_bit(AF_PCI_CHANNEL_IO_PERM_FAILURE, &ha->flags);
5738 qla4xxx_abort_active_cmds(ha, DID_NO_CONNECT << 16);
5739 return PCI_ERS_RESULT_DISCONNECT;
5741 return PCI_ERS_RESULT_NEED_RESET;
5745 * qla4xxx_pci_mmio_enabled() gets called if
5746 * qla4xxx_pci_error_detected() returns PCI_ERS_RESULT_CAN_RECOVER
5747 * and read/write to the device still works.
5749 static pci_ers_result_t
5750 qla4xxx_pci_mmio_enabled(struct pci_dev *pdev)
5752 struct scsi_qla_host *ha = pci_get_drvdata(pdev);
5754 if (!is_aer_supported(ha))
5755 return PCI_ERS_RESULT_NONE;
5757 return PCI_ERS_RESULT_RECOVERED;
5760 static uint32_t qla4_8xxx_error_recovery(struct scsi_qla_host *ha)
5762 uint32_t rval = QLA_ERROR;
5765 struct pci_dev *other_pdev = NULL;
5767 ql4_printk(KERN_WARNING, ha, "scsi%ld: In %s\n", ha->host_no, __func__);
5769 set_bit(DPC_RESET_ACTIVE, &ha->dpc_flags);
5771 if (test_bit(AF_ONLINE, &ha->flags)) {
5772 clear_bit(AF_ONLINE, &ha->flags);
5773 clear_bit(AF_LINK_UP, &ha->flags);
5774 iscsi_host_for_each_session(ha->host, qla4xxx_fail_session);
5775 qla4xxx_process_aen(ha, FLUSH_DDB_CHANGED_AENS);
5778 fn = PCI_FUNC(ha->pdev->devfn);
5781 ql4_printk(KERN_INFO, ha, "scsi%ld: %s: Finding PCI device at "
5782 "func %x\n", ha->host_no, __func__, fn);
5783 /* Get the pci device given the domain, bus,
5784 * slot/function number */
5786 pci_get_domain_bus_and_slot(pci_domain_nr(ha->pdev->bus),
5787 ha->pdev->bus->number, PCI_DEVFN(PCI_SLOT(ha->pdev->devfn),
5793 if (atomic_read(&other_pdev->enable_cnt)) {
5794 ql4_printk(KERN_INFO, ha, "scsi%ld: %s: Found PCI "
5795 "func in enabled state%x\n", ha->host_no,
5797 pci_dev_put(other_pdev);
5800 pci_dev_put(other_pdev);
5803 /* The first function on the card, the reset owner will
5804 * start & initialize the firmware. The other functions
5805 * on the card will reset the firmware context
5808 ql4_printk(KERN_INFO, ha, "scsi%ld: %s: devfn being reset "
5809 "0x%x is the owner\n", ha->host_no, __func__,
5812 qla4_8xxx_idc_lock(ha);
5813 qla4_8xxx_wr_32(ha, QLA82XX_CRB_DEV_STATE,
5816 qla4_8xxx_wr_32(ha, QLA82XX_CRB_DRV_IDC_VERSION,
5817 QLA82XX_IDC_VERSION);
5819 qla4_8xxx_idc_unlock(ha);
5820 clear_bit(AF_FW_RECOVERY, &ha->flags);
5821 rval = qla4xxx_initialize_adapter(ha, RESET_ADAPTER);
5822 qla4_8xxx_idc_lock(ha);
5824 if (rval != QLA_SUCCESS) {
5825 ql4_printk(KERN_INFO, ha, "scsi%ld: %s: HW State: "
5826 "FAILED\n", ha->host_no, __func__);
5827 qla4_8xxx_clear_drv_active(ha);
5828 qla4_8xxx_wr_32(ha, QLA82XX_CRB_DEV_STATE,
5829 QLA82XX_DEV_FAILED);
5831 ql4_printk(KERN_INFO, ha, "scsi%ld: %s: HW State: "
5832 "READY\n", ha->host_no, __func__);
5833 qla4_8xxx_wr_32(ha, QLA82XX_CRB_DEV_STATE,
5835 /* Clear driver state register */
5836 qla4_8xxx_wr_32(ha, QLA82XX_CRB_DRV_STATE, 0);
5837 qla4_8xxx_set_drv_active(ha);
5838 ret = qla4xxx_request_irqs(ha);
5840 ql4_printk(KERN_WARNING, ha, "Failed to "
5841 "reserve interrupt %d already in use.\n",
5845 ha->isp_ops->enable_intrs(ha);
5849 qla4_8xxx_idc_unlock(ha);
5851 ql4_printk(KERN_INFO, ha, "scsi%ld: %s: devfn 0x%x is not "
5852 "the reset owner\n", ha->host_no, __func__,
5854 if ((qla4_8xxx_rd_32(ha, QLA82XX_CRB_DEV_STATE) ==
5855 QLA82XX_DEV_READY)) {
5856 clear_bit(AF_FW_RECOVERY, &ha->flags);
5857 rval = qla4xxx_initialize_adapter(ha, RESET_ADAPTER);
5858 if (rval == QLA_SUCCESS) {
5859 ret = qla4xxx_request_irqs(ha);
5861 ql4_printk(KERN_WARNING, ha, "Failed to"
5862 " reserve interrupt %d already in"
5863 " use.\n", ha->pdev->irq);
5866 ha->isp_ops->enable_intrs(ha);
5870 qla4_8xxx_idc_lock(ha);
5871 qla4_8xxx_set_drv_active(ha);
5872 qla4_8xxx_idc_unlock(ha);
5875 clear_bit(DPC_RESET_ACTIVE, &ha->dpc_flags);
5879 static pci_ers_result_t
5880 qla4xxx_pci_slot_reset(struct pci_dev *pdev)
5882 pci_ers_result_t ret = PCI_ERS_RESULT_DISCONNECT;
5883 struct scsi_qla_host *ha = pci_get_drvdata(pdev);
5886 ql4_printk(KERN_WARNING, ha, "scsi%ld: %s: slot_reset\n",
5887 ha->host_no, __func__);
5889 if (!is_aer_supported(ha))
5890 return PCI_ERS_RESULT_NONE;
5892 /* Restore the saved state of PCIe device -
5893 * BAR registers, PCI Config space, PCIX, MSI,
5896 pci_restore_state(pdev);
5898 /* pci_restore_state() clears the saved_state flag of the device
5899 * save restored state which resets saved_state flag
5901 pci_save_state(pdev);
5903 /* Initialize device or resume if in suspended state */
5904 rc = pci_enable_device(pdev);
5906 ql4_printk(KERN_WARNING, ha, "scsi%ld: %s: Can't re-enable "
5907 "device after reset\n", ha->host_no, __func__);
5908 goto exit_slot_reset;
5911 ha->isp_ops->disable_intrs(ha);
5913 if (is_qla8022(ha)) {
5914 if (qla4_8xxx_error_recovery(ha) == QLA_SUCCESS) {
5915 ret = PCI_ERS_RESULT_RECOVERED;
5916 goto exit_slot_reset;
5918 goto exit_slot_reset;
5922 ql4_printk(KERN_WARNING, ha, "scsi%ld: %s: Return=%x\n"
5923 "device after reset\n", ha->host_no, __func__, ret);
5928 qla4xxx_pci_resume(struct pci_dev *pdev)
5930 struct scsi_qla_host *ha = pci_get_drvdata(pdev);
5933 ql4_printk(KERN_WARNING, ha, "scsi%ld: %s: pci_resume\n",
5934 ha->host_no, __func__);
5936 ret = qla4xxx_wait_for_hba_online(ha);
5937 if (ret != QLA_SUCCESS) {
5938 ql4_printk(KERN_ERR, ha, "scsi%ld: %s: the device failed to "
5939 "resume I/O from slot/link_reset\n", ha->host_no,
5943 pci_cleanup_aer_uncorrect_error_status(pdev);
5944 clear_bit(AF_EEH_BUSY, &ha->flags);
5947 static struct pci_error_handlers qla4xxx_err_handler = {
5948 .error_detected = qla4xxx_pci_error_detected,
5949 .mmio_enabled = qla4xxx_pci_mmio_enabled,
5950 .slot_reset = qla4xxx_pci_slot_reset,
5951 .resume = qla4xxx_pci_resume,
5954 static struct pci_device_id qla4xxx_pci_tbl[] = {
5956 .vendor = PCI_VENDOR_ID_QLOGIC,
5957 .device = PCI_DEVICE_ID_QLOGIC_ISP4010,
5958 .subvendor = PCI_ANY_ID,
5959 .subdevice = PCI_ANY_ID,
5962 .vendor = PCI_VENDOR_ID_QLOGIC,
5963 .device = PCI_DEVICE_ID_QLOGIC_ISP4022,
5964 .subvendor = PCI_ANY_ID,
5965 .subdevice = PCI_ANY_ID,
5968 .vendor = PCI_VENDOR_ID_QLOGIC,
5969 .device = PCI_DEVICE_ID_QLOGIC_ISP4032,
5970 .subvendor = PCI_ANY_ID,
5971 .subdevice = PCI_ANY_ID,
5974 .vendor = PCI_VENDOR_ID_QLOGIC,
5975 .device = PCI_DEVICE_ID_QLOGIC_ISP8022,
5976 .subvendor = PCI_ANY_ID,
5977 .subdevice = PCI_ANY_ID,
5981 MODULE_DEVICE_TABLE(pci, qla4xxx_pci_tbl);
5983 static struct pci_driver qla4xxx_pci_driver = {
5984 .name = DRIVER_NAME,
5985 .id_table = qla4xxx_pci_tbl,
5986 .probe = qla4xxx_probe_adapter,
5987 .remove = qla4xxx_remove_adapter,
5988 .err_handler = &qla4xxx_err_handler,
5991 static int __init qla4xxx_module_init(void)
5995 /* Allocate cache for SRBs. */
5996 srb_cachep = kmem_cache_create("qla4xxx_srbs", sizeof(struct srb), 0,
5997 SLAB_HWCACHE_ALIGN, NULL);
5998 if (srb_cachep == NULL) {
6000 "%s: Unable to allocate SRB cache..."
6001 "Failing load!\n", DRIVER_NAME);
6006 /* Derive version string. */
6007 strcpy(qla4xxx_version_str, QLA4XXX_DRIVER_VERSION);
6008 if (ql4xextended_error_logging)
6009 strcat(qla4xxx_version_str, "-debug");
6011 qla4xxx_scsi_transport =
6012 iscsi_register_transport(&qla4xxx_iscsi_transport);
6013 if (!qla4xxx_scsi_transport){
6015 goto release_srb_cache;
6018 ret = pci_register_driver(&qla4xxx_pci_driver);
6020 goto unregister_transport;
6022 printk(KERN_INFO "QLogic iSCSI HBA Driver\n");
6025 unregister_transport:
6026 iscsi_unregister_transport(&qla4xxx_iscsi_transport);
6028 kmem_cache_destroy(srb_cachep);
6033 static void __exit qla4xxx_module_exit(void)
6035 pci_unregister_driver(&qla4xxx_pci_driver);
6036 iscsi_unregister_transport(&qla4xxx_iscsi_transport);
6037 kmem_cache_destroy(srb_cachep);
6040 module_init(qla4xxx_module_init);
6041 module_exit(qla4xxx_module_exit);
6043 MODULE_AUTHOR("QLogic Corporation");
6044 MODULE_DESCRIPTION("QLogic iSCSI HBA Driver");
6045 MODULE_LICENSE("GPL");
6046 MODULE_VERSION(QLA4XXX_DRIVER_VERSION);