2 * QLogic iSCSI HBA Driver
3 * Copyright (c) 2003-2012 QLogic Corporation
5 * See LICENSE.qla4xxx for copyright and licensing details.
7 #include <linux/moduleparam.h>
8 #include <linux/slab.h>
9 #include <linux/blkdev.h>
10 #include <linux/iscsi_boot_sysfs.h>
11 #include <linux/inet.h>
13 #include <scsi/scsi_tcq.h>
14 #include <scsi/scsicam.h>
17 #include "ql4_version.h"
20 #include "ql4_inline.h"
26 static char qla4xxx_version_str[40];
29 * SRB allocation cache
31 static struct kmem_cache *srb_cachep;
34 * Module parameter information and variables
36 static int ql4xdisablesysfsboot = 1;
37 module_param(ql4xdisablesysfsboot, int, S_IRUGO | S_IWUSR);
38 MODULE_PARM_DESC(ql4xdisablesysfsboot,
39 " Set to disable exporting boot targets to sysfs.\n"
40 "\t\t 0 - Export boot targets\n"
41 "\t\t 1 - Do not export boot targets (Default)");
44 module_param(ql4xdontresethba, int, S_IRUGO | S_IWUSR);
45 MODULE_PARM_DESC(ql4xdontresethba,
46 " Don't reset the HBA for driver recovery.\n"
47 "\t\t 0 - It will reset HBA (Default)\n"
48 "\t\t 1 - It will NOT reset HBA");
50 int ql4xextended_error_logging;
51 module_param(ql4xextended_error_logging, int, S_IRUGO | S_IWUSR);
52 MODULE_PARM_DESC(ql4xextended_error_logging,
53 " Option to enable extended error logging.\n"
54 "\t\t 0 - no logging (Default)\n"
55 "\t\t 2 - debug logging");
57 int ql4xenablemsix = 1;
58 module_param(ql4xenablemsix, int, S_IRUGO|S_IWUSR);
59 MODULE_PARM_DESC(ql4xenablemsix,
60 " Set to enable MSI or MSI-X interrupt mechanism.\n"
61 "\t\t 0 = enable INTx interrupt mechanism.\n"
62 "\t\t 1 = enable MSI-X interrupt mechanism (Default).\n"
63 "\t\t 2 = enable MSI interrupt mechanism.");
65 #define QL4_DEF_QDEPTH 32
66 static int ql4xmaxqdepth = QL4_DEF_QDEPTH;
67 module_param(ql4xmaxqdepth, int, S_IRUGO | S_IWUSR);
68 MODULE_PARM_DESC(ql4xmaxqdepth,
69 " Maximum queue depth to report for target devices.\n"
72 static int ql4xqfulltracking = 1;
73 module_param(ql4xqfulltracking, int, S_IRUGO | S_IWUSR);
74 MODULE_PARM_DESC(ql4xqfulltracking,
75 " Enable or disable dynamic tracking and adjustment of\n"
76 "\t\t scsi device queue depth.\n"
78 "\t\t 1 - Enable. (Default)");
80 static int ql4xsess_recovery_tmo = QL4_SESS_RECOVERY_TMO;
81 module_param(ql4xsess_recovery_tmo, int, S_IRUGO);
82 MODULE_PARM_DESC(ql4xsess_recovery_tmo,
83 " Target Session Recovery Timeout.\n"
84 "\t\t Default: 120 sec.");
86 int ql4xmdcapmask = 0x1F;
87 module_param(ql4xmdcapmask, int, S_IRUGO);
88 MODULE_PARM_DESC(ql4xmdcapmask,
89 " Set the Minidump driver capture mask level.\n"
90 "\t\t Default is 0x1F.\n"
91 "\t\t Can be set to 0x3, 0x7, 0xF, 0x1F, 0x3F, 0x7F");
94 module_param(ql4xenablemd, int, S_IRUGO | S_IWUSR);
95 MODULE_PARM_DESC(ql4xenablemd,
96 " Set to enable minidump.\n"
97 "\t\t 0 - disable minidump\n"
98 "\t\t 1 - enable minidump (Default)");
100 static int qla4xxx_wait_for_hba_online(struct scsi_qla_host *ha);
102 * SCSI host template entry points
104 static void qla4xxx_config_dma_addressing(struct scsi_qla_host *ha);
107 * iSCSI template entry points
109 static int qla4xxx_session_get_param(struct iscsi_cls_session *cls_sess,
110 enum iscsi_param param, char *buf);
111 static int qla4xxx_conn_get_param(struct iscsi_cls_conn *conn,
112 enum iscsi_param param, char *buf);
113 static int qla4xxx_host_get_param(struct Scsi_Host *shost,
114 enum iscsi_host_param param, char *buf);
115 static int qla4xxx_iface_set_param(struct Scsi_Host *shost, void *data,
117 static int qla4xxx_get_iface_param(struct iscsi_iface *iface,
118 enum iscsi_param_type param_type,
119 int param, char *buf);
120 static enum blk_eh_timer_return qla4xxx_eh_cmd_timed_out(struct scsi_cmnd *sc);
121 static struct iscsi_endpoint *qla4xxx_ep_connect(struct Scsi_Host *shost,
122 struct sockaddr *dst_addr,
124 static int qla4xxx_ep_poll(struct iscsi_endpoint *ep, int timeout_ms);
125 static void qla4xxx_ep_disconnect(struct iscsi_endpoint *ep);
126 static int qla4xxx_get_ep_param(struct iscsi_endpoint *ep,
127 enum iscsi_param param, char *buf);
128 static int qla4xxx_conn_start(struct iscsi_cls_conn *conn);
129 static struct iscsi_cls_conn *
130 qla4xxx_conn_create(struct iscsi_cls_session *cls_sess, uint32_t conn_idx);
131 static int qla4xxx_conn_bind(struct iscsi_cls_session *cls_session,
132 struct iscsi_cls_conn *cls_conn,
133 uint64_t transport_fd, int is_leading);
134 static void qla4xxx_conn_destroy(struct iscsi_cls_conn *conn);
135 static struct iscsi_cls_session *
136 qla4xxx_session_create(struct iscsi_endpoint *ep, uint16_t cmds_max,
137 uint16_t qdepth, uint32_t initial_cmdsn);
138 static void qla4xxx_session_destroy(struct iscsi_cls_session *sess);
139 static void qla4xxx_task_work(struct work_struct *wdata);
140 static int qla4xxx_alloc_pdu(struct iscsi_task *, uint8_t);
141 static int qla4xxx_task_xmit(struct iscsi_task *);
142 static void qla4xxx_task_cleanup(struct iscsi_task *);
143 static void qla4xxx_fail_session(struct iscsi_cls_session *cls_session);
144 static void qla4xxx_conn_get_stats(struct iscsi_cls_conn *cls_conn,
145 struct iscsi_stats *stats);
146 static int qla4xxx_send_ping(struct Scsi_Host *shost, uint32_t iface_num,
147 uint32_t iface_type, uint32_t payload_size,
148 uint32_t pid, struct sockaddr *dst_addr);
149 static int qla4xxx_get_chap_list(struct Scsi_Host *shost, uint16_t chap_tbl_idx,
150 uint32_t *num_entries, char *buf);
151 static int qla4xxx_delete_chap(struct Scsi_Host *shost, uint16_t chap_tbl_idx);
154 * SCSI host template entry points
156 static int qla4xxx_queuecommand(struct Scsi_Host *h, struct scsi_cmnd *cmd);
157 static int qla4xxx_eh_abort(struct scsi_cmnd *cmd);
158 static int qla4xxx_eh_device_reset(struct scsi_cmnd *cmd);
159 static int qla4xxx_eh_target_reset(struct scsi_cmnd *cmd);
160 static int qla4xxx_eh_host_reset(struct scsi_cmnd *cmd);
161 static int qla4xxx_slave_alloc(struct scsi_device *device);
162 static int qla4xxx_slave_configure(struct scsi_device *device);
163 static void qla4xxx_slave_destroy(struct scsi_device *sdev);
164 static umode_t qla4_attr_is_visible(int param_type, int param);
165 static int qla4xxx_host_reset(struct Scsi_Host *shost, int reset_type);
166 static int qla4xxx_change_queue_depth(struct scsi_device *sdev, int qdepth,
169 static struct qla4_8xxx_legacy_intr_set legacy_intr[] =
170 QLA82XX_LEGACY_INTR_CONFIG;
172 static struct scsi_host_template qla4xxx_driver_template = {
173 .module = THIS_MODULE,
175 .proc_name = DRIVER_NAME,
176 .queuecommand = qla4xxx_queuecommand,
178 .eh_abort_handler = qla4xxx_eh_abort,
179 .eh_device_reset_handler = qla4xxx_eh_device_reset,
180 .eh_target_reset_handler = qla4xxx_eh_target_reset,
181 .eh_host_reset_handler = qla4xxx_eh_host_reset,
182 .eh_timed_out = qla4xxx_eh_cmd_timed_out,
184 .slave_configure = qla4xxx_slave_configure,
185 .slave_alloc = qla4xxx_slave_alloc,
186 .slave_destroy = qla4xxx_slave_destroy,
187 .change_queue_depth = qla4xxx_change_queue_depth,
191 .use_clustering = ENABLE_CLUSTERING,
192 .sg_tablesize = SG_ALL,
194 .max_sectors = 0xFFFF,
195 .shost_attrs = qla4xxx_host_attrs,
196 .host_reset = qla4xxx_host_reset,
197 .vendor_id = SCSI_NL_VID_TYPE_PCI | PCI_VENDOR_ID_QLOGIC,
200 static struct iscsi_transport qla4xxx_iscsi_transport = {
201 .owner = THIS_MODULE,
203 .caps = CAP_TEXT_NEGO |
204 CAP_DATA_PATH_OFFLOAD | CAP_HDRDGST |
205 CAP_DATADGST | CAP_LOGIN_OFFLOAD |
207 .attr_is_visible = qla4_attr_is_visible,
208 .create_session = qla4xxx_session_create,
209 .destroy_session = qla4xxx_session_destroy,
210 .start_conn = qla4xxx_conn_start,
211 .create_conn = qla4xxx_conn_create,
212 .bind_conn = qla4xxx_conn_bind,
213 .stop_conn = iscsi_conn_stop,
214 .destroy_conn = qla4xxx_conn_destroy,
215 .set_param = iscsi_set_param,
216 .get_conn_param = qla4xxx_conn_get_param,
217 .get_session_param = qla4xxx_session_get_param,
218 .get_ep_param = qla4xxx_get_ep_param,
219 .ep_connect = qla4xxx_ep_connect,
220 .ep_poll = qla4xxx_ep_poll,
221 .ep_disconnect = qla4xxx_ep_disconnect,
222 .get_stats = qla4xxx_conn_get_stats,
223 .send_pdu = iscsi_conn_send_pdu,
224 .xmit_task = qla4xxx_task_xmit,
225 .cleanup_task = qla4xxx_task_cleanup,
226 .alloc_pdu = qla4xxx_alloc_pdu,
228 .get_host_param = qla4xxx_host_get_param,
229 .set_iface_param = qla4xxx_iface_set_param,
230 .get_iface_param = qla4xxx_get_iface_param,
231 .bsg_request = qla4xxx_bsg_request,
232 .send_ping = qla4xxx_send_ping,
233 .get_chap = qla4xxx_get_chap_list,
234 .delete_chap = qla4xxx_delete_chap,
237 static struct scsi_transport_template *qla4xxx_scsi_transport;
239 static int qla4xxx_send_ping(struct Scsi_Host *shost, uint32_t iface_num,
240 uint32_t iface_type, uint32_t payload_size,
241 uint32_t pid, struct sockaddr *dst_addr)
243 struct scsi_qla_host *ha = to_qla_host(shost);
244 struct sockaddr_in *addr;
245 struct sockaddr_in6 *addr6;
246 uint32_t options = 0;
247 uint8_t ipaddr[IPv6_ADDR_LEN];
250 memset(ipaddr, 0, IPv6_ADDR_LEN);
252 if ((iface_type == ISCSI_IFACE_TYPE_IPV4) &&
253 (dst_addr->sa_family == AF_INET)) {
254 addr = (struct sockaddr_in *)dst_addr;
255 memcpy(ipaddr, &addr->sin_addr.s_addr, IP_ADDR_LEN);
256 DEBUG2(ql4_printk(KERN_INFO, ha, "%s: IPv4 Ping src: %pI4 "
257 "dest: %pI4\n", __func__,
258 &ha->ip_config.ip_address, ipaddr));
259 rval = qla4xxx_ping_iocb(ha, options, payload_size, pid,
263 } else if ((iface_type == ISCSI_IFACE_TYPE_IPV6) &&
264 (dst_addr->sa_family == AF_INET6)) {
266 addr6 = (struct sockaddr_in6 *)dst_addr;
267 memcpy(ipaddr, &addr6->sin6_addr.in6_u.u6_addr8, IPv6_ADDR_LEN);
269 options |= PING_IPV6_PROTOCOL_ENABLE;
271 /* Ping using LinkLocal address */
272 if ((iface_num == 0) || (iface_num == 1)) {
273 DEBUG2(ql4_printk(KERN_INFO, ha, "%s: LinkLocal Ping "
274 "src: %pI6 dest: %pI6\n", __func__,
275 &ha->ip_config.ipv6_link_local_addr,
277 options |= PING_IPV6_LINKLOCAL_ADDR;
278 rval = qla4xxx_ping_iocb(ha, options, payload_size,
281 ql4_printk(KERN_WARNING, ha, "%s: iface num = %d "
282 "not supported\n", __func__, iface_num);
288 * If ping using LinkLocal address fails, try ping using
291 if (rval != QLA_SUCCESS) {
292 options &= ~PING_IPV6_LINKLOCAL_ADDR;
293 if (iface_num == 0) {
294 options |= PING_IPV6_ADDR0;
295 DEBUG2(ql4_printk(KERN_INFO, ha, "%s: IPv6 "
297 "dest: %pI6\n", __func__,
298 &ha->ip_config.ipv6_addr0,
300 } else if (iface_num == 1) {
301 options |= PING_IPV6_ADDR1;
302 DEBUG2(ql4_printk(KERN_INFO, ha, "%s: IPv6 "
304 "dest: %pI6\n", __func__,
305 &ha->ip_config.ipv6_addr1,
308 rval = qla4xxx_ping_iocb(ha, options, payload_size,
319 static umode_t qla4_attr_is_visible(int param_type, int param)
321 switch (param_type) {
322 case ISCSI_HOST_PARAM:
324 case ISCSI_HOST_PARAM_HWADDRESS:
325 case ISCSI_HOST_PARAM_IPADDRESS:
326 case ISCSI_HOST_PARAM_INITIATOR_NAME:
327 case ISCSI_HOST_PARAM_PORT_STATE:
328 case ISCSI_HOST_PARAM_PORT_SPEED:
335 case ISCSI_PARAM_PERSISTENT_ADDRESS:
336 case ISCSI_PARAM_PERSISTENT_PORT:
337 case ISCSI_PARAM_CONN_ADDRESS:
338 case ISCSI_PARAM_CONN_PORT:
339 case ISCSI_PARAM_TARGET_NAME:
340 case ISCSI_PARAM_TPGT:
341 case ISCSI_PARAM_TARGET_ALIAS:
342 case ISCSI_PARAM_MAX_BURST:
343 case ISCSI_PARAM_MAX_R2T:
344 case ISCSI_PARAM_FIRST_BURST:
345 case ISCSI_PARAM_MAX_RECV_DLENGTH:
346 case ISCSI_PARAM_MAX_XMIT_DLENGTH:
347 case ISCSI_PARAM_IFACE_NAME:
348 case ISCSI_PARAM_CHAP_OUT_IDX:
349 case ISCSI_PARAM_CHAP_IN_IDX:
350 case ISCSI_PARAM_USERNAME:
351 case ISCSI_PARAM_PASSWORD:
352 case ISCSI_PARAM_USERNAME_IN:
353 case ISCSI_PARAM_PASSWORD_IN:
358 case ISCSI_NET_PARAM:
360 case ISCSI_NET_PARAM_IPV4_ADDR:
361 case ISCSI_NET_PARAM_IPV4_SUBNET:
362 case ISCSI_NET_PARAM_IPV4_GW:
363 case ISCSI_NET_PARAM_IPV4_BOOTPROTO:
364 case ISCSI_NET_PARAM_IFACE_ENABLE:
365 case ISCSI_NET_PARAM_IPV6_LINKLOCAL:
366 case ISCSI_NET_PARAM_IPV6_ADDR:
367 case ISCSI_NET_PARAM_IPV6_ROUTER:
368 case ISCSI_NET_PARAM_IPV6_ADDR_AUTOCFG:
369 case ISCSI_NET_PARAM_IPV6_LINKLOCAL_AUTOCFG:
370 case ISCSI_NET_PARAM_VLAN_ID:
371 case ISCSI_NET_PARAM_VLAN_PRIORITY:
372 case ISCSI_NET_PARAM_VLAN_ENABLED:
373 case ISCSI_NET_PARAM_MTU:
374 case ISCSI_NET_PARAM_PORT:
384 static int qla4xxx_get_chap_list(struct Scsi_Host *shost, uint16_t chap_tbl_idx,
385 uint32_t *num_entries, char *buf)
387 struct scsi_qla_host *ha = to_qla_host(shost);
388 struct ql4_chap_table *chap_table;
389 struct iscsi_chap_rec *chap_rec;
390 int max_chap_entries = 0;
391 int valid_chap_entries = 0;
395 max_chap_entries = (ha->hw.flt_chap_size / 2) /
396 sizeof(struct ql4_chap_table);
398 max_chap_entries = MAX_CHAP_ENTRIES_40XX;
400 ql4_printk(KERN_INFO, ha, "%s: num_entries = %d, CHAP idx = %d\n",
401 __func__, *num_entries, chap_tbl_idx);
405 goto exit_get_chap_list;
408 chap_rec = (struct iscsi_chap_rec *) buf;
409 mutex_lock(&ha->chap_sem);
410 for (i = chap_tbl_idx; i < max_chap_entries; i++) {
411 chap_table = (struct ql4_chap_table *)ha->chap_list + i;
412 if (chap_table->cookie !=
413 __constant_cpu_to_le16(CHAP_VALID_COOKIE))
416 chap_rec->chap_tbl_idx = i;
417 strncpy(chap_rec->username, chap_table->name,
418 ISCSI_CHAP_AUTH_NAME_MAX_LEN);
419 strncpy(chap_rec->password, chap_table->secret,
420 QL4_CHAP_MAX_SECRET_LEN);
421 chap_rec->password_length = chap_table->secret_len;
423 if (chap_table->flags & BIT_7) /* local */
424 chap_rec->chap_type = CHAP_TYPE_OUT;
426 if (chap_table->flags & BIT_6) /* peer */
427 chap_rec->chap_type = CHAP_TYPE_IN;
431 valid_chap_entries++;
432 if (valid_chap_entries == *num_entries)
437 mutex_unlock(&ha->chap_sem);
440 ql4_printk(KERN_INFO, ha, "%s: Valid CHAP Entries = %d\n",
441 __func__, valid_chap_entries);
442 *num_entries = valid_chap_entries;
446 static int __qla4xxx_is_chap_active(struct device *dev, void *data)
449 uint16_t *chap_tbl_idx = (uint16_t *) data;
450 struct iscsi_cls_session *cls_session;
451 struct iscsi_session *sess;
452 struct ddb_entry *ddb_entry;
454 if (!iscsi_is_session_dev(dev))
455 goto exit_is_chap_active;
457 cls_session = iscsi_dev_to_session(dev);
458 sess = cls_session->dd_data;
459 ddb_entry = sess->dd_data;
461 if (iscsi_session_chkready(cls_session))
462 goto exit_is_chap_active;
464 if (ddb_entry->chap_tbl_idx == *chap_tbl_idx)
471 static int qla4xxx_is_chap_active(struct Scsi_Host *shost,
472 uint16_t chap_tbl_idx)
476 ret = device_for_each_child(&shost->shost_gendev, &chap_tbl_idx,
477 __qla4xxx_is_chap_active);
482 static int qla4xxx_delete_chap(struct Scsi_Host *shost, uint16_t chap_tbl_idx)
484 struct scsi_qla_host *ha = to_qla_host(shost);
485 struct ql4_chap_table *chap_table;
487 int max_chap_entries = 0;
492 chap_table = dma_pool_alloc(ha->chap_dma_pool, GFP_KERNEL, &chap_dma);
493 if (chap_table == NULL)
496 memset(chap_table, 0, sizeof(struct ql4_chap_table));
499 max_chap_entries = (ha->hw.flt_chap_size / 2) /
500 sizeof(struct ql4_chap_table);
502 max_chap_entries = MAX_CHAP_ENTRIES_40XX;
504 if (chap_tbl_idx > max_chap_entries) {
506 goto exit_delete_chap;
509 /* Check if chap index is in use.
510 * If chap is in use don't delet chap entry */
511 ret = qla4xxx_is_chap_active(shost, chap_tbl_idx);
513 ql4_printk(KERN_INFO, ha, "CHAP entry %d is in use, cannot "
514 "delete from flash\n", chap_tbl_idx);
516 goto exit_delete_chap;
519 chap_size = sizeof(struct ql4_chap_table);
521 offset = FLASH_CHAP_OFFSET | (chap_tbl_idx * chap_size);
523 offset = FLASH_RAW_ACCESS_ADDR + (ha->hw.flt_region_chap << 2);
524 /* flt_chap_size is CHAP table size for both ports
525 * so divide it by 2 to calculate the offset for second port
527 if (ha->port_num == 1)
528 offset += (ha->hw.flt_chap_size / 2);
529 offset += (chap_tbl_idx * chap_size);
532 ret = qla4xxx_get_flash(ha, chap_dma, offset, chap_size);
533 if (ret != QLA_SUCCESS) {
535 goto exit_delete_chap;
538 DEBUG2(ql4_printk(KERN_INFO, ha, "Chap Cookie: x%x\n",
539 __le16_to_cpu(chap_table->cookie)));
541 if (__le16_to_cpu(chap_table->cookie) != CHAP_VALID_COOKIE) {
542 ql4_printk(KERN_ERR, ha, "No valid chap entry found\n");
543 goto exit_delete_chap;
546 chap_table->cookie = __constant_cpu_to_le16(0xFFFF);
548 offset = FLASH_CHAP_OFFSET |
549 (chap_tbl_idx * sizeof(struct ql4_chap_table));
550 ret = qla4xxx_set_flash(ha, chap_dma, offset, chap_size,
551 FLASH_OPT_RMW_COMMIT);
552 if (ret == QLA_SUCCESS && ha->chap_list) {
553 mutex_lock(&ha->chap_sem);
554 /* Update ha chap_list cache */
555 memcpy((struct ql4_chap_table *)ha->chap_list + chap_tbl_idx,
556 chap_table, sizeof(struct ql4_chap_table));
557 mutex_unlock(&ha->chap_sem);
559 if (ret != QLA_SUCCESS)
563 dma_pool_free(ha->chap_dma_pool, chap_table, chap_dma);
567 static int qla4xxx_get_iface_param(struct iscsi_iface *iface,
568 enum iscsi_param_type param_type,
569 int param, char *buf)
571 struct Scsi_Host *shost = iscsi_iface_to_shost(iface);
572 struct scsi_qla_host *ha = to_qla_host(shost);
575 if (param_type != ISCSI_NET_PARAM)
579 case ISCSI_NET_PARAM_IPV4_ADDR:
580 len = sprintf(buf, "%pI4\n", &ha->ip_config.ip_address);
582 case ISCSI_NET_PARAM_IPV4_SUBNET:
583 len = sprintf(buf, "%pI4\n", &ha->ip_config.subnet_mask);
585 case ISCSI_NET_PARAM_IPV4_GW:
586 len = sprintf(buf, "%pI4\n", &ha->ip_config.gateway);
588 case ISCSI_NET_PARAM_IFACE_ENABLE:
589 if (iface->iface_type == ISCSI_IFACE_TYPE_IPV4)
590 len = sprintf(buf, "%s\n",
591 (ha->ip_config.ipv4_options &
592 IPOPT_IPV4_PROTOCOL_ENABLE) ?
593 "enabled" : "disabled");
594 else if (iface->iface_type == ISCSI_IFACE_TYPE_IPV6)
595 len = sprintf(buf, "%s\n",
596 (ha->ip_config.ipv6_options &
597 IPV6_OPT_IPV6_PROTOCOL_ENABLE) ?
598 "enabled" : "disabled");
600 case ISCSI_NET_PARAM_IPV4_BOOTPROTO:
601 len = sprintf(buf, "%s\n",
602 (ha->ip_config.tcp_options & TCPOPT_DHCP_ENABLE) ?
605 case ISCSI_NET_PARAM_IPV6_ADDR:
606 if (iface->iface_num == 0)
607 len = sprintf(buf, "%pI6\n", &ha->ip_config.ipv6_addr0);
608 if (iface->iface_num == 1)
609 len = sprintf(buf, "%pI6\n", &ha->ip_config.ipv6_addr1);
611 case ISCSI_NET_PARAM_IPV6_LINKLOCAL:
612 len = sprintf(buf, "%pI6\n",
613 &ha->ip_config.ipv6_link_local_addr);
615 case ISCSI_NET_PARAM_IPV6_ROUTER:
616 len = sprintf(buf, "%pI6\n",
617 &ha->ip_config.ipv6_default_router_addr);
619 case ISCSI_NET_PARAM_IPV6_ADDR_AUTOCFG:
620 len = sprintf(buf, "%s\n",
621 (ha->ip_config.ipv6_addl_options &
622 IPV6_ADDOPT_NEIGHBOR_DISCOVERY_ADDR_ENABLE) ?
625 case ISCSI_NET_PARAM_IPV6_LINKLOCAL_AUTOCFG:
626 len = sprintf(buf, "%s\n",
627 (ha->ip_config.ipv6_addl_options &
628 IPV6_ADDOPT_AUTOCONFIG_LINK_LOCAL_ADDR) ?
631 case ISCSI_NET_PARAM_VLAN_ID:
632 if (iface->iface_type == ISCSI_IFACE_TYPE_IPV4)
633 len = sprintf(buf, "%d\n",
634 (ha->ip_config.ipv4_vlan_tag &
636 else if (iface->iface_type == ISCSI_IFACE_TYPE_IPV6)
637 len = sprintf(buf, "%d\n",
638 (ha->ip_config.ipv6_vlan_tag &
641 case ISCSI_NET_PARAM_VLAN_PRIORITY:
642 if (iface->iface_type == ISCSI_IFACE_TYPE_IPV4)
643 len = sprintf(buf, "%d\n",
644 ((ha->ip_config.ipv4_vlan_tag >> 13) &
645 ISCSI_MAX_VLAN_PRIORITY));
646 else if (iface->iface_type == ISCSI_IFACE_TYPE_IPV6)
647 len = sprintf(buf, "%d\n",
648 ((ha->ip_config.ipv6_vlan_tag >> 13) &
649 ISCSI_MAX_VLAN_PRIORITY));
651 case ISCSI_NET_PARAM_VLAN_ENABLED:
652 if (iface->iface_type == ISCSI_IFACE_TYPE_IPV4)
653 len = sprintf(buf, "%s\n",
654 (ha->ip_config.ipv4_options &
655 IPOPT_VLAN_TAGGING_ENABLE) ?
656 "enabled" : "disabled");
657 else if (iface->iface_type == ISCSI_IFACE_TYPE_IPV6)
658 len = sprintf(buf, "%s\n",
659 (ha->ip_config.ipv6_options &
660 IPV6_OPT_VLAN_TAGGING_ENABLE) ?
661 "enabled" : "disabled");
663 case ISCSI_NET_PARAM_MTU:
664 len = sprintf(buf, "%d\n", ha->ip_config.eth_mtu_size);
666 case ISCSI_NET_PARAM_PORT:
667 if (iface->iface_type == ISCSI_IFACE_TYPE_IPV4)
668 len = sprintf(buf, "%d\n", ha->ip_config.ipv4_port);
669 else if (iface->iface_type == ISCSI_IFACE_TYPE_IPV6)
670 len = sprintf(buf, "%d\n", ha->ip_config.ipv6_port);
679 static struct iscsi_endpoint *
680 qla4xxx_ep_connect(struct Scsi_Host *shost, struct sockaddr *dst_addr,
684 struct iscsi_endpoint *ep;
685 struct qla_endpoint *qla_ep;
686 struct scsi_qla_host *ha;
687 struct sockaddr_in *addr;
688 struct sockaddr_in6 *addr6;
690 DEBUG2(printk(KERN_INFO "Func: %s\n", __func__));
693 printk(KERN_ERR "%s: shost is NULL\n",
698 ha = iscsi_host_priv(shost);
700 ep = iscsi_create_endpoint(sizeof(struct qla_endpoint));
706 qla_ep = ep->dd_data;
707 memset(qla_ep, 0, sizeof(struct qla_endpoint));
708 if (dst_addr->sa_family == AF_INET) {
709 memcpy(&qla_ep->dst_addr, dst_addr, sizeof(struct sockaddr_in));
710 addr = (struct sockaddr_in *)&qla_ep->dst_addr;
711 DEBUG2(ql4_printk(KERN_INFO, ha, "%s: %pI4\n", __func__,
712 (char *)&addr->sin_addr));
713 } else if (dst_addr->sa_family == AF_INET6) {
714 memcpy(&qla_ep->dst_addr, dst_addr,
715 sizeof(struct sockaddr_in6));
716 addr6 = (struct sockaddr_in6 *)&qla_ep->dst_addr;
717 DEBUG2(ql4_printk(KERN_INFO, ha, "%s: %pI6\n", __func__,
718 (char *)&addr6->sin6_addr));
721 qla_ep->host = shost;
726 static int qla4xxx_ep_poll(struct iscsi_endpoint *ep, int timeout_ms)
728 struct qla_endpoint *qla_ep;
729 struct scsi_qla_host *ha;
732 DEBUG2(printk(KERN_INFO "Func: %s\n", __func__));
733 qla_ep = ep->dd_data;
734 ha = to_qla_host(qla_ep->host);
736 if (adapter_up(ha) && !test_bit(AF_BUILD_DDB_LIST, &ha->flags))
742 static void qla4xxx_ep_disconnect(struct iscsi_endpoint *ep)
744 DEBUG2(printk(KERN_INFO "Func: %s\n", __func__));
745 iscsi_destroy_endpoint(ep);
748 static int qla4xxx_get_ep_param(struct iscsi_endpoint *ep,
749 enum iscsi_param param,
752 struct qla_endpoint *qla_ep = ep->dd_data;
753 struct sockaddr *dst_addr;
755 DEBUG2(printk(KERN_INFO "Func: %s\n", __func__));
758 case ISCSI_PARAM_CONN_PORT:
759 case ISCSI_PARAM_CONN_ADDRESS:
763 dst_addr = (struct sockaddr *)&qla_ep->dst_addr;
767 return iscsi_conn_get_addr_param((struct sockaddr_storage *)
768 &qla_ep->dst_addr, param, buf);
774 static void qla4xxx_conn_get_stats(struct iscsi_cls_conn *cls_conn,
775 struct iscsi_stats *stats)
777 struct iscsi_session *sess;
778 struct iscsi_cls_session *cls_sess;
779 struct ddb_entry *ddb_entry;
780 struct scsi_qla_host *ha;
781 struct ql_iscsi_stats *ql_iscsi_stats;
784 dma_addr_t iscsi_stats_dma;
786 DEBUG2(printk(KERN_INFO "Func: %s\n", __func__));
788 cls_sess = iscsi_conn_to_session(cls_conn);
789 sess = cls_sess->dd_data;
790 ddb_entry = sess->dd_data;
793 stats_size = PAGE_ALIGN(sizeof(struct ql_iscsi_stats));
794 /* Allocate memory */
795 ql_iscsi_stats = dma_alloc_coherent(&ha->pdev->dev, stats_size,
796 &iscsi_stats_dma, GFP_KERNEL);
797 if (!ql_iscsi_stats) {
798 ql4_printk(KERN_ERR, ha,
799 "Unable to allocate memory for iscsi stats\n");
803 ret = qla4xxx_get_mgmt_data(ha, ddb_entry->fw_ddb_index, stats_size,
805 if (ret != QLA_SUCCESS) {
806 ql4_printk(KERN_ERR, ha,
807 "Unable to retreive iscsi stats\n");
812 stats->txdata_octets = le64_to_cpu(ql_iscsi_stats->tx_data_octets);
813 stats->rxdata_octets = le64_to_cpu(ql_iscsi_stats->rx_data_octets);
815 stats->noptx_pdus = le32_to_cpu(ql_iscsi_stats->tx_nopout_pdus);
816 stats->scsicmd_pdus = le32_to_cpu(ql_iscsi_stats->tx_scsi_cmd_pdus);
817 stats->tmfcmd_pdus = le32_to_cpu(ql_iscsi_stats->tx_tmf_cmd_pdus);
818 stats->login_pdus = le32_to_cpu(ql_iscsi_stats->tx_login_cmd_pdus);
819 stats->text_pdus = le32_to_cpu(ql_iscsi_stats->tx_text_cmd_pdus);
820 stats->dataout_pdus = le32_to_cpu(ql_iscsi_stats->tx_scsi_write_pdus);
821 stats->logout_pdus = le32_to_cpu(ql_iscsi_stats->tx_logout_cmd_pdus);
822 stats->snack_pdus = le32_to_cpu(ql_iscsi_stats->tx_snack_req_pdus);
824 stats->noprx_pdus = le32_to_cpu(ql_iscsi_stats->rx_nopin_pdus);
825 stats->scsirsp_pdus = le32_to_cpu(ql_iscsi_stats->rx_scsi_resp_pdus);
826 stats->tmfrsp_pdus = le32_to_cpu(ql_iscsi_stats->rx_tmf_resp_pdus);
827 stats->textrsp_pdus = le32_to_cpu(ql_iscsi_stats->rx_text_resp_pdus);
828 stats->datain_pdus = le32_to_cpu(ql_iscsi_stats->rx_scsi_read_pdus);
829 stats->logoutrsp_pdus =
830 le32_to_cpu(ql_iscsi_stats->rx_logout_resp_pdus);
831 stats->r2t_pdus = le32_to_cpu(ql_iscsi_stats->rx_r2t_pdus);
832 stats->async_pdus = le32_to_cpu(ql_iscsi_stats->rx_async_pdus);
833 stats->rjt_pdus = le32_to_cpu(ql_iscsi_stats->rx_reject_pdus);
836 dma_free_coherent(&ha->pdev->dev, stats_size, ql_iscsi_stats,
842 static enum blk_eh_timer_return qla4xxx_eh_cmd_timed_out(struct scsi_cmnd *sc)
844 struct iscsi_cls_session *session;
845 struct iscsi_session *sess;
847 enum blk_eh_timer_return ret = BLK_EH_NOT_HANDLED;
849 session = starget_to_session(scsi_target(sc->device));
850 sess = session->dd_data;
852 spin_lock_irqsave(&session->lock, flags);
853 if (session->state == ISCSI_SESSION_FAILED)
854 ret = BLK_EH_RESET_TIMER;
855 spin_unlock_irqrestore(&session->lock, flags);
860 static void qla4xxx_set_port_speed(struct Scsi_Host *shost)
862 struct scsi_qla_host *ha = to_qla_host(shost);
863 struct iscsi_cls_host *ihost = shost->shost_data;
864 uint32_t speed = ISCSI_PORT_SPEED_UNKNOWN;
866 qla4xxx_get_firmware_state(ha);
868 switch (ha->addl_fw_state & 0x0F00) {
869 case FW_ADDSTATE_LINK_SPEED_10MBPS:
870 speed = ISCSI_PORT_SPEED_10MBPS;
872 case FW_ADDSTATE_LINK_SPEED_100MBPS:
873 speed = ISCSI_PORT_SPEED_100MBPS;
875 case FW_ADDSTATE_LINK_SPEED_1GBPS:
876 speed = ISCSI_PORT_SPEED_1GBPS;
878 case FW_ADDSTATE_LINK_SPEED_10GBPS:
879 speed = ISCSI_PORT_SPEED_10GBPS;
882 ihost->port_speed = speed;
885 static void qla4xxx_set_port_state(struct Scsi_Host *shost)
887 struct scsi_qla_host *ha = to_qla_host(shost);
888 struct iscsi_cls_host *ihost = shost->shost_data;
889 uint32_t state = ISCSI_PORT_STATE_DOWN;
891 if (test_bit(AF_LINK_UP, &ha->flags))
892 state = ISCSI_PORT_STATE_UP;
894 ihost->port_state = state;
897 static int qla4xxx_host_get_param(struct Scsi_Host *shost,
898 enum iscsi_host_param param, char *buf)
900 struct scsi_qla_host *ha = to_qla_host(shost);
904 case ISCSI_HOST_PARAM_HWADDRESS:
905 len = sysfs_format_mac(buf, ha->my_mac, MAC_ADDR_LEN);
907 case ISCSI_HOST_PARAM_IPADDRESS:
908 len = sprintf(buf, "%pI4\n", &ha->ip_config.ip_address);
910 case ISCSI_HOST_PARAM_INITIATOR_NAME:
911 len = sprintf(buf, "%s\n", ha->name_string);
913 case ISCSI_HOST_PARAM_PORT_STATE:
914 qla4xxx_set_port_state(shost);
915 len = sprintf(buf, "%s\n", iscsi_get_port_state_name(shost));
917 case ISCSI_HOST_PARAM_PORT_SPEED:
918 qla4xxx_set_port_speed(shost);
919 len = sprintf(buf, "%s\n", iscsi_get_port_speed_name(shost));
928 static void qla4xxx_create_ipv4_iface(struct scsi_qla_host *ha)
934 ha->iface_ipv4 = iscsi_create_iface(ha->host,
935 &qla4xxx_iscsi_transport,
936 ISCSI_IFACE_TYPE_IPV4, 0, 0);
938 ql4_printk(KERN_ERR, ha, "Could not create IPv4 iSCSI "
942 static void qla4xxx_create_ipv6_iface(struct scsi_qla_host *ha)
944 if (!ha->iface_ipv6_0)
946 ha->iface_ipv6_0 = iscsi_create_iface(ha->host,
947 &qla4xxx_iscsi_transport,
948 ISCSI_IFACE_TYPE_IPV6, 0,
950 if (!ha->iface_ipv6_0)
951 ql4_printk(KERN_ERR, ha, "Could not create IPv6 iSCSI "
954 if (!ha->iface_ipv6_1)
956 ha->iface_ipv6_1 = iscsi_create_iface(ha->host,
957 &qla4xxx_iscsi_transport,
958 ISCSI_IFACE_TYPE_IPV6, 1,
960 if (!ha->iface_ipv6_1)
961 ql4_printk(KERN_ERR, ha, "Could not create IPv6 iSCSI "
965 static void qla4xxx_create_ifaces(struct scsi_qla_host *ha)
967 if (ha->ip_config.ipv4_options & IPOPT_IPV4_PROTOCOL_ENABLE)
968 qla4xxx_create_ipv4_iface(ha);
970 if (ha->ip_config.ipv6_options & IPV6_OPT_IPV6_PROTOCOL_ENABLE)
971 qla4xxx_create_ipv6_iface(ha);
974 static void qla4xxx_destroy_ipv4_iface(struct scsi_qla_host *ha)
976 if (ha->iface_ipv4) {
977 iscsi_destroy_iface(ha->iface_ipv4);
978 ha->iface_ipv4 = NULL;
982 static void qla4xxx_destroy_ipv6_iface(struct scsi_qla_host *ha)
984 if (ha->iface_ipv6_0) {
985 iscsi_destroy_iface(ha->iface_ipv6_0);
986 ha->iface_ipv6_0 = NULL;
988 if (ha->iface_ipv6_1) {
989 iscsi_destroy_iface(ha->iface_ipv6_1);
990 ha->iface_ipv6_1 = NULL;
994 static void qla4xxx_destroy_ifaces(struct scsi_qla_host *ha)
996 qla4xxx_destroy_ipv4_iface(ha);
997 qla4xxx_destroy_ipv6_iface(ha);
1000 static void qla4xxx_set_ipv6(struct scsi_qla_host *ha,
1001 struct iscsi_iface_param_info *iface_param,
1002 struct addr_ctrl_blk *init_fw_cb)
1005 * iface_num 0 is valid for IPv6 Addr, linklocal, router, autocfg.
1006 * iface_num 1 is valid only for IPv6 Addr.
1008 switch (iface_param->param) {
1009 case ISCSI_NET_PARAM_IPV6_ADDR:
1010 if (iface_param->iface_num & 0x1)
1012 memcpy(init_fw_cb->ipv6_addr1, iface_param->value,
1013 sizeof(init_fw_cb->ipv6_addr1));
1016 memcpy(init_fw_cb->ipv6_addr0, iface_param->value,
1017 sizeof(init_fw_cb->ipv6_addr0));
1019 case ISCSI_NET_PARAM_IPV6_LINKLOCAL:
1020 if (iface_param->iface_num & 0x1)
1022 memcpy(init_fw_cb->ipv6_if_id, &iface_param->value[8],
1023 sizeof(init_fw_cb->ipv6_if_id));
1025 case ISCSI_NET_PARAM_IPV6_ROUTER:
1026 if (iface_param->iface_num & 0x1)
1028 memcpy(init_fw_cb->ipv6_dflt_rtr_addr, iface_param->value,
1029 sizeof(init_fw_cb->ipv6_dflt_rtr_addr));
1031 case ISCSI_NET_PARAM_IPV6_ADDR_AUTOCFG:
1032 /* Autocfg applies to even interface */
1033 if (iface_param->iface_num & 0x1)
1036 if (iface_param->value[0] == ISCSI_IPV6_AUTOCFG_DISABLE)
1037 init_fw_cb->ipv6_addtl_opts &=
1039 ~IPV6_ADDOPT_NEIGHBOR_DISCOVERY_ADDR_ENABLE);
1040 else if (iface_param->value[0] == ISCSI_IPV6_AUTOCFG_ND_ENABLE)
1041 init_fw_cb->ipv6_addtl_opts |=
1043 IPV6_ADDOPT_NEIGHBOR_DISCOVERY_ADDR_ENABLE);
1045 ql4_printk(KERN_ERR, ha, "Invalid autocfg setting for "
1048 case ISCSI_NET_PARAM_IPV6_LINKLOCAL_AUTOCFG:
1049 /* Autocfg applies to even interface */
1050 if (iface_param->iface_num & 0x1)
1053 if (iface_param->value[0] ==
1054 ISCSI_IPV6_LINKLOCAL_AUTOCFG_ENABLE)
1055 init_fw_cb->ipv6_addtl_opts |= cpu_to_le16(
1056 IPV6_ADDOPT_AUTOCONFIG_LINK_LOCAL_ADDR);
1057 else if (iface_param->value[0] ==
1058 ISCSI_IPV6_LINKLOCAL_AUTOCFG_DISABLE)
1059 init_fw_cb->ipv6_addtl_opts &= cpu_to_le16(
1060 ~IPV6_ADDOPT_AUTOCONFIG_LINK_LOCAL_ADDR);
1062 ql4_printk(KERN_ERR, ha, "Invalid autocfg setting for "
1063 "IPv6 linklocal addr\n");
1065 case ISCSI_NET_PARAM_IPV6_ROUTER_AUTOCFG:
1066 /* Autocfg applies to even interface */
1067 if (iface_param->iface_num & 0x1)
1070 if (iface_param->value[0] == ISCSI_IPV6_ROUTER_AUTOCFG_ENABLE)
1071 memset(init_fw_cb->ipv6_dflt_rtr_addr, 0,
1072 sizeof(init_fw_cb->ipv6_dflt_rtr_addr));
1074 case ISCSI_NET_PARAM_IFACE_ENABLE:
1075 if (iface_param->value[0] == ISCSI_IFACE_ENABLE) {
1076 init_fw_cb->ipv6_opts |=
1077 cpu_to_le16(IPV6_OPT_IPV6_PROTOCOL_ENABLE);
1078 qla4xxx_create_ipv6_iface(ha);
1080 init_fw_cb->ipv6_opts &=
1081 cpu_to_le16(~IPV6_OPT_IPV6_PROTOCOL_ENABLE &
1083 qla4xxx_destroy_ipv6_iface(ha);
1086 case ISCSI_NET_PARAM_VLAN_TAG:
1087 if (iface_param->len != sizeof(init_fw_cb->ipv6_vlan_tag))
1089 init_fw_cb->ipv6_vlan_tag =
1090 cpu_to_be16(*(uint16_t *)iface_param->value);
1092 case ISCSI_NET_PARAM_VLAN_ENABLED:
1093 if (iface_param->value[0] == ISCSI_VLAN_ENABLE)
1094 init_fw_cb->ipv6_opts |=
1095 cpu_to_le16(IPV6_OPT_VLAN_TAGGING_ENABLE);
1097 init_fw_cb->ipv6_opts &=
1098 cpu_to_le16(~IPV6_OPT_VLAN_TAGGING_ENABLE);
1100 case ISCSI_NET_PARAM_MTU:
1101 init_fw_cb->eth_mtu_size =
1102 cpu_to_le16(*(uint16_t *)iface_param->value);
1104 case ISCSI_NET_PARAM_PORT:
1105 /* Autocfg applies to even interface */
1106 if (iface_param->iface_num & 0x1)
1109 init_fw_cb->ipv6_port =
1110 cpu_to_le16(*(uint16_t *)iface_param->value);
1113 ql4_printk(KERN_ERR, ha, "Unknown IPv6 param = %d\n",
1114 iface_param->param);
1119 static void qla4xxx_set_ipv4(struct scsi_qla_host *ha,
1120 struct iscsi_iface_param_info *iface_param,
1121 struct addr_ctrl_blk *init_fw_cb)
1123 switch (iface_param->param) {
1124 case ISCSI_NET_PARAM_IPV4_ADDR:
1125 memcpy(init_fw_cb->ipv4_addr, iface_param->value,
1126 sizeof(init_fw_cb->ipv4_addr));
1128 case ISCSI_NET_PARAM_IPV4_SUBNET:
1129 memcpy(init_fw_cb->ipv4_subnet, iface_param->value,
1130 sizeof(init_fw_cb->ipv4_subnet));
1132 case ISCSI_NET_PARAM_IPV4_GW:
1133 memcpy(init_fw_cb->ipv4_gw_addr, iface_param->value,
1134 sizeof(init_fw_cb->ipv4_gw_addr));
1136 case ISCSI_NET_PARAM_IPV4_BOOTPROTO:
1137 if (iface_param->value[0] == ISCSI_BOOTPROTO_DHCP)
1138 init_fw_cb->ipv4_tcp_opts |=
1139 cpu_to_le16(TCPOPT_DHCP_ENABLE);
1140 else if (iface_param->value[0] == ISCSI_BOOTPROTO_STATIC)
1141 init_fw_cb->ipv4_tcp_opts &=
1142 cpu_to_le16(~TCPOPT_DHCP_ENABLE);
1144 ql4_printk(KERN_ERR, ha, "Invalid IPv4 bootproto\n");
1146 case ISCSI_NET_PARAM_IFACE_ENABLE:
1147 if (iface_param->value[0] == ISCSI_IFACE_ENABLE) {
1148 init_fw_cb->ipv4_ip_opts |=
1149 cpu_to_le16(IPOPT_IPV4_PROTOCOL_ENABLE);
1150 qla4xxx_create_ipv4_iface(ha);
1152 init_fw_cb->ipv4_ip_opts &=
1153 cpu_to_le16(~IPOPT_IPV4_PROTOCOL_ENABLE &
1155 qla4xxx_destroy_ipv4_iface(ha);
1158 case ISCSI_NET_PARAM_VLAN_TAG:
1159 if (iface_param->len != sizeof(init_fw_cb->ipv4_vlan_tag))
1161 init_fw_cb->ipv4_vlan_tag =
1162 cpu_to_be16(*(uint16_t *)iface_param->value);
1164 case ISCSI_NET_PARAM_VLAN_ENABLED:
1165 if (iface_param->value[0] == ISCSI_VLAN_ENABLE)
1166 init_fw_cb->ipv4_ip_opts |=
1167 cpu_to_le16(IPOPT_VLAN_TAGGING_ENABLE);
1169 init_fw_cb->ipv4_ip_opts &=
1170 cpu_to_le16(~IPOPT_VLAN_TAGGING_ENABLE);
1172 case ISCSI_NET_PARAM_MTU:
1173 init_fw_cb->eth_mtu_size =
1174 cpu_to_le16(*(uint16_t *)iface_param->value);
1176 case ISCSI_NET_PARAM_PORT:
1177 init_fw_cb->ipv4_port =
1178 cpu_to_le16(*(uint16_t *)iface_param->value);
1181 ql4_printk(KERN_ERR, ha, "Unknown IPv4 param = %d\n",
1182 iface_param->param);
1188 qla4xxx_initcb_to_acb(struct addr_ctrl_blk *init_fw_cb)
1190 struct addr_ctrl_blk_def *acb;
1191 acb = (struct addr_ctrl_blk_def *)init_fw_cb;
1192 memset(acb->reserved1, 0, sizeof(acb->reserved1));
1193 memset(acb->reserved2, 0, sizeof(acb->reserved2));
1194 memset(acb->reserved3, 0, sizeof(acb->reserved3));
1195 memset(acb->reserved4, 0, sizeof(acb->reserved4));
1196 memset(acb->reserved5, 0, sizeof(acb->reserved5));
1197 memset(acb->reserved6, 0, sizeof(acb->reserved6));
1198 memset(acb->reserved7, 0, sizeof(acb->reserved7));
1199 memset(acb->reserved8, 0, sizeof(acb->reserved8));
1200 memset(acb->reserved9, 0, sizeof(acb->reserved9));
1201 memset(acb->reserved10, 0, sizeof(acb->reserved10));
1202 memset(acb->reserved11, 0, sizeof(acb->reserved11));
1203 memset(acb->reserved12, 0, sizeof(acb->reserved12));
1204 memset(acb->reserved13, 0, sizeof(acb->reserved13));
1205 memset(acb->reserved14, 0, sizeof(acb->reserved14));
1206 memset(acb->reserved15, 0, sizeof(acb->reserved15));
1210 qla4xxx_iface_set_param(struct Scsi_Host *shost, void *data, uint32_t len)
1212 struct scsi_qla_host *ha = to_qla_host(shost);
1214 struct iscsi_iface_param_info *iface_param = NULL;
1215 struct addr_ctrl_blk *init_fw_cb = NULL;
1216 dma_addr_t init_fw_cb_dma;
1217 uint32_t mbox_cmd[MBOX_REG_COUNT];
1218 uint32_t mbox_sts[MBOX_REG_COUNT];
1220 struct nlattr *attr;
1222 init_fw_cb = dma_alloc_coherent(&ha->pdev->dev,
1223 sizeof(struct addr_ctrl_blk),
1224 &init_fw_cb_dma, GFP_KERNEL);
1226 ql4_printk(KERN_ERR, ha, "%s: Unable to alloc init_cb\n",
1231 memset(init_fw_cb, 0, sizeof(struct addr_ctrl_blk));
1232 memset(&mbox_cmd, 0, sizeof(mbox_cmd));
1233 memset(&mbox_sts, 0, sizeof(mbox_sts));
1235 if (qla4xxx_get_ifcb(ha, &mbox_cmd[0], &mbox_sts[0], init_fw_cb_dma)) {
1236 ql4_printk(KERN_ERR, ha, "%s: get ifcb failed\n", __func__);
1238 goto exit_init_fw_cb;
1241 nla_for_each_attr(attr, data, len, rem) {
1242 iface_param = nla_data(attr);
1244 if (iface_param->param_type != ISCSI_NET_PARAM)
1247 switch (iface_param->iface_type) {
1248 case ISCSI_IFACE_TYPE_IPV4:
1249 switch (iface_param->iface_num) {
1251 qla4xxx_set_ipv4(ha, iface_param, init_fw_cb);
1254 /* Cannot have more than one IPv4 interface */
1255 ql4_printk(KERN_ERR, ha, "Invalid IPv4 iface "
1257 iface_param->iface_num);
1261 case ISCSI_IFACE_TYPE_IPV6:
1262 switch (iface_param->iface_num) {
1265 qla4xxx_set_ipv6(ha, iface_param, init_fw_cb);
1268 /* Cannot have more than two IPv6 interface */
1269 ql4_printk(KERN_ERR, ha, "Invalid IPv6 iface "
1271 iface_param->iface_num);
1276 ql4_printk(KERN_ERR, ha, "Invalid iface type\n");
1281 init_fw_cb->cookie = cpu_to_le32(0x11BEAD5A);
1283 rval = qla4xxx_set_flash(ha, init_fw_cb_dma, FLASH_SEGMENT_IFCB,
1284 sizeof(struct addr_ctrl_blk),
1285 FLASH_OPT_RMW_COMMIT);
1286 if (rval != QLA_SUCCESS) {
1287 ql4_printk(KERN_ERR, ha, "%s: set flash mbx failed\n",
1290 goto exit_init_fw_cb;
1293 rval = qla4xxx_disable_acb(ha);
1294 if (rval != QLA_SUCCESS) {
1295 ql4_printk(KERN_ERR, ha, "%s: disable acb mbx failed\n",
1298 goto exit_init_fw_cb;
1301 wait_for_completion_timeout(&ha->disable_acb_comp,
1302 DISABLE_ACB_TOV * HZ);
1304 qla4xxx_initcb_to_acb(init_fw_cb);
1306 rval = qla4xxx_set_acb(ha, &mbox_cmd[0], &mbox_sts[0], init_fw_cb_dma);
1307 if (rval != QLA_SUCCESS) {
1308 ql4_printk(KERN_ERR, ha, "%s: set acb mbx failed\n",
1311 goto exit_init_fw_cb;
1314 memset(init_fw_cb, 0, sizeof(struct addr_ctrl_blk));
1315 qla4xxx_update_local_ifcb(ha, &mbox_cmd[0], &mbox_sts[0], init_fw_cb,
1319 dma_free_coherent(&ha->pdev->dev, sizeof(struct addr_ctrl_blk),
1320 init_fw_cb, init_fw_cb_dma);
1325 static int qla4xxx_session_get_param(struct iscsi_cls_session *cls_sess,
1326 enum iscsi_param param, char *buf)
1328 struct iscsi_session *sess = cls_sess->dd_data;
1329 struct ddb_entry *ddb_entry = sess->dd_data;
1330 struct scsi_qla_host *ha = ddb_entry->ha;
1335 case ISCSI_PARAM_CHAP_IN_IDX:
1336 rval = qla4xxx_get_chap_index(ha, sess->username_in,
1337 sess->password_in, BIDI_CHAP,
1342 len = sprintf(buf, "%hu\n", idx);
1344 case ISCSI_PARAM_CHAP_OUT_IDX:
1345 rval = qla4xxx_get_chap_index(ha, sess->username,
1346 sess->password, LOCAL_CHAP,
1351 len = sprintf(buf, "%hu\n", idx);
1354 return iscsi_session_get_param(cls_sess, param, buf);
1360 static int qla4xxx_conn_get_param(struct iscsi_cls_conn *cls_conn,
1361 enum iscsi_param param, char *buf)
1363 struct iscsi_conn *conn;
1364 struct qla_conn *qla_conn;
1365 struct sockaddr *dst_addr;
1368 conn = cls_conn->dd_data;
1369 qla_conn = conn->dd_data;
1370 dst_addr = (struct sockaddr *)&qla_conn->qla_ep->dst_addr;
1373 case ISCSI_PARAM_CONN_PORT:
1374 case ISCSI_PARAM_CONN_ADDRESS:
1375 return iscsi_conn_get_addr_param((struct sockaddr_storage *)
1376 dst_addr, param, buf);
1378 return iscsi_conn_get_param(cls_conn, param, buf);
1385 int qla4xxx_get_ddb_index(struct scsi_qla_host *ha, uint16_t *ddb_index)
1387 uint32_t mbx_sts = 0;
1388 uint16_t tmp_ddb_index;
1392 tmp_ddb_index = find_first_zero_bit(ha->ddb_idx_map, MAX_DDB_ENTRIES);
1394 if (tmp_ddb_index >= MAX_DDB_ENTRIES) {
1395 DEBUG2(ql4_printk(KERN_INFO, ha,
1396 "Free DDB index not available\n"));
1398 goto exit_get_ddb_index;
1401 if (test_and_set_bit(tmp_ddb_index, ha->ddb_idx_map))
1404 DEBUG2(ql4_printk(KERN_INFO, ha,
1405 "Found a free DDB index at %d\n", tmp_ddb_index));
1406 ret = qla4xxx_req_ddb_entry(ha, tmp_ddb_index, &mbx_sts);
1407 if (ret == QLA_ERROR) {
1408 if (mbx_sts == MBOX_STS_COMMAND_ERROR) {
1409 ql4_printk(KERN_INFO, ha,
1410 "DDB index = %d not available trying next\n",
1414 DEBUG2(ql4_printk(KERN_INFO, ha,
1415 "Free FW DDB not available\n"));
1418 *ddb_index = tmp_ddb_index;
1424 static int qla4xxx_match_ipaddress(struct scsi_qla_host *ha,
1425 struct ddb_entry *ddb_entry,
1426 char *existing_ipaddr,
1429 uint8_t dst_ipaddr[IPv6_ADDR_LEN];
1430 char formatted_ipaddr[DDB_IPADDR_LEN];
1431 int status = QLA_SUCCESS, ret = 0;
1433 if (ddb_entry->fw_ddb_entry.options & DDB_OPT_IPV6_DEVICE) {
1434 ret = in6_pton(user_ipaddr, strlen(user_ipaddr), dst_ipaddr,
1440 ret = sprintf(formatted_ipaddr, "%pI6", dst_ipaddr);
1442 ret = in4_pton(user_ipaddr, strlen(user_ipaddr), dst_ipaddr,
1448 ret = sprintf(formatted_ipaddr, "%pI4", dst_ipaddr);
1451 if (strcmp(existing_ipaddr, formatted_ipaddr))
1458 static int qla4xxx_match_fwdb_session(struct scsi_qla_host *ha,
1459 struct iscsi_cls_conn *cls_conn)
1461 int idx = 0, max_ddbs, rval;
1462 struct iscsi_cls_session *cls_sess = iscsi_conn_to_session(cls_conn);
1463 struct iscsi_session *sess, *existing_sess;
1464 struct iscsi_conn *conn, *existing_conn;
1465 struct ddb_entry *ddb_entry;
1467 sess = cls_sess->dd_data;
1468 conn = cls_conn->dd_data;
1470 if (sess->targetname == NULL ||
1471 conn->persistent_address == NULL ||
1472 conn->persistent_port == 0)
1475 max_ddbs = is_qla40XX(ha) ? MAX_DEV_DB_ENTRIES_40XX :
1478 for (idx = 0; idx < max_ddbs; idx++) {
1479 ddb_entry = qla4xxx_lookup_ddb_by_fw_index(ha, idx);
1480 if (ddb_entry == NULL)
1483 if (ddb_entry->ddb_type != FLASH_DDB)
1486 existing_sess = ddb_entry->sess->dd_data;
1487 existing_conn = ddb_entry->conn->dd_data;
1489 if (existing_sess->targetname == NULL ||
1490 existing_conn->persistent_address == NULL ||
1491 existing_conn->persistent_port == 0)
1494 DEBUG2(ql4_printk(KERN_INFO, ha,
1495 "IQN = %s User IQN = %s\n",
1496 existing_sess->targetname,
1499 DEBUG2(ql4_printk(KERN_INFO, ha,
1500 "IP = %s User IP = %s\n",
1501 existing_conn->persistent_address,
1502 conn->persistent_address));
1504 DEBUG2(ql4_printk(KERN_INFO, ha,
1505 "Port = %d User Port = %d\n",
1506 existing_conn->persistent_port,
1507 conn->persistent_port));
1509 if (strcmp(existing_sess->targetname, sess->targetname))
1511 rval = qla4xxx_match_ipaddress(ha, ddb_entry,
1512 existing_conn->persistent_address,
1513 conn->persistent_address);
1514 if (rval == QLA_ERROR)
1516 if (existing_conn->persistent_port != conn->persistent_port)
1521 if (idx == max_ddbs)
1524 DEBUG2(ql4_printk(KERN_INFO, ha,
1525 "Match found in fwdb sessions\n"));
1529 static struct iscsi_cls_session *
1530 qla4xxx_session_create(struct iscsi_endpoint *ep,
1531 uint16_t cmds_max, uint16_t qdepth,
1532 uint32_t initial_cmdsn)
1534 struct iscsi_cls_session *cls_sess;
1535 struct scsi_qla_host *ha;
1536 struct qla_endpoint *qla_ep;
1537 struct ddb_entry *ddb_entry;
1539 struct iscsi_session *sess;
1540 struct sockaddr *dst_addr;
1543 DEBUG2(printk(KERN_INFO "Func: %s\n", __func__));
1545 printk(KERN_ERR "qla4xxx: missing ep.\n");
1549 qla_ep = ep->dd_data;
1550 dst_addr = (struct sockaddr *)&qla_ep->dst_addr;
1551 ha = to_qla_host(qla_ep->host);
1553 ret = qla4xxx_get_ddb_index(ha, &ddb_index);
1554 if (ret == QLA_ERROR)
1557 cls_sess = iscsi_session_setup(&qla4xxx_iscsi_transport, qla_ep->host,
1558 cmds_max, sizeof(struct ddb_entry),
1559 sizeof(struct ql4_task_data),
1560 initial_cmdsn, ddb_index);
1564 sess = cls_sess->dd_data;
1565 ddb_entry = sess->dd_data;
1566 ddb_entry->fw_ddb_index = ddb_index;
1567 ddb_entry->fw_ddb_device_state = DDB_DS_NO_CONNECTION_ACTIVE;
1569 ddb_entry->sess = cls_sess;
1570 ddb_entry->unblock_sess = qla4xxx_unblock_ddb;
1571 ddb_entry->ddb_change = qla4xxx_ddb_change;
1572 cls_sess->recovery_tmo = ql4xsess_recovery_tmo;
1573 ha->fw_ddb_index_map[ddb_entry->fw_ddb_index] = ddb_entry;
1579 static void qla4xxx_session_destroy(struct iscsi_cls_session *cls_sess)
1581 struct iscsi_session *sess;
1582 struct ddb_entry *ddb_entry;
1583 struct scsi_qla_host *ha;
1584 unsigned long flags, wtime;
1585 struct dev_db_entry *fw_ddb_entry = NULL;
1586 dma_addr_t fw_ddb_entry_dma;
1590 DEBUG2(printk(KERN_INFO "Func: %s\n", __func__));
1591 sess = cls_sess->dd_data;
1592 ddb_entry = sess->dd_data;
1595 fw_ddb_entry = dma_alloc_coherent(&ha->pdev->dev, sizeof(*fw_ddb_entry),
1596 &fw_ddb_entry_dma, GFP_KERNEL);
1597 if (!fw_ddb_entry) {
1598 ql4_printk(KERN_ERR, ha,
1599 "%s: Unable to allocate dma buffer\n", __func__);
1600 goto destroy_session;
1603 wtime = jiffies + (HZ * LOGOUT_TOV);
1605 ret = qla4xxx_get_fwddb_entry(ha, ddb_entry->fw_ddb_index,
1606 fw_ddb_entry, fw_ddb_entry_dma,
1607 NULL, NULL, &ddb_state, NULL,
1609 if (ret == QLA_ERROR)
1610 goto destroy_session;
1612 if ((ddb_state == DDB_DS_NO_CONNECTION_ACTIVE) ||
1613 (ddb_state == DDB_DS_SESSION_FAILED))
1614 goto destroy_session;
1616 schedule_timeout_uninterruptible(HZ);
1617 } while ((time_after(wtime, jiffies)));
1620 qla4xxx_clear_ddb_entry(ha, ddb_entry->fw_ddb_index);
1622 spin_lock_irqsave(&ha->hardware_lock, flags);
1623 qla4xxx_free_ddb(ha, ddb_entry);
1624 spin_unlock_irqrestore(&ha->hardware_lock, flags);
1626 iscsi_session_teardown(cls_sess);
1629 dma_free_coherent(&ha->pdev->dev, sizeof(*fw_ddb_entry),
1630 fw_ddb_entry, fw_ddb_entry_dma);
1633 static struct iscsi_cls_conn *
1634 qla4xxx_conn_create(struct iscsi_cls_session *cls_sess, uint32_t conn_idx)
1636 struct iscsi_cls_conn *cls_conn;
1637 struct iscsi_session *sess;
1638 struct ddb_entry *ddb_entry;
1640 DEBUG2(printk(KERN_INFO "Func: %s\n", __func__));
1641 cls_conn = iscsi_conn_setup(cls_sess, sizeof(struct qla_conn),
1646 sess = cls_sess->dd_data;
1647 ddb_entry = sess->dd_data;
1648 ddb_entry->conn = cls_conn;
1653 static int qla4xxx_conn_bind(struct iscsi_cls_session *cls_session,
1654 struct iscsi_cls_conn *cls_conn,
1655 uint64_t transport_fd, int is_leading)
1657 struct iscsi_conn *conn;
1658 struct qla_conn *qla_conn;
1659 struct iscsi_endpoint *ep;
1661 DEBUG2(printk(KERN_INFO "Func: %s\n", __func__));
1663 if (iscsi_conn_bind(cls_session, cls_conn, is_leading))
1665 ep = iscsi_lookup_endpoint(transport_fd);
1666 conn = cls_conn->dd_data;
1667 qla_conn = conn->dd_data;
1668 qla_conn->qla_ep = ep->dd_data;
1672 static int qla4xxx_conn_start(struct iscsi_cls_conn *cls_conn)
1674 struct iscsi_cls_session *cls_sess = iscsi_conn_to_session(cls_conn);
1675 struct iscsi_session *sess;
1676 struct ddb_entry *ddb_entry;
1677 struct scsi_qla_host *ha;
1678 struct dev_db_entry *fw_ddb_entry = NULL;
1679 dma_addr_t fw_ddb_entry_dma;
1680 uint32_t mbx_sts = 0;
1682 int status = QLA_SUCCESS;
1684 DEBUG2(printk(KERN_INFO "Func: %s\n", __func__));
1685 sess = cls_sess->dd_data;
1686 ddb_entry = sess->dd_data;
1689 /* Check if we have matching FW DDB, if yes then do not
1690 * login to this target. This could cause target to logout previous
1693 ret = qla4xxx_match_fwdb_session(ha, cls_conn);
1694 if (ret == QLA_SUCCESS) {
1695 ql4_printk(KERN_INFO, ha,
1696 "Session already exist in FW.\n");
1698 goto exit_conn_start;
1701 fw_ddb_entry = dma_alloc_coherent(&ha->pdev->dev, sizeof(*fw_ddb_entry),
1702 &fw_ddb_entry_dma, GFP_KERNEL);
1703 if (!fw_ddb_entry) {
1704 ql4_printk(KERN_ERR, ha,
1705 "%s: Unable to allocate dma buffer\n", __func__);
1707 goto exit_conn_start;
1710 ret = qla4xxx_set_param_ddbentry(ha, ddb_entry, cls_conn, &mbx_sts);
1712 /* If iscsid is stopped and started then no need to do
1713 * set param again since ddb state will be already
1714 * active and FW does not allow set ddb to an
1718 if (ddb_entry->fw_ddb_device_state ==
1719 DDB_DS_SESSION_ACTIVE) {
1720 ddb_entry->unblock_sess(ddb_entry->sess);
1721 goto exit_set_param;
1724 ql4_printk(KERN_ERR, ha, "%s: Failed set param for index[%d]\n",
1725 __func__, ddb_entry->fw_ddb_index);
1726 goto exit_conn_start;
1729 status = qla4xxx_conn_open(ha, ddb_entry->fw_ddb_index);
1730 if (status == QLA_ERROR) {
1731 ql4_printk(KERN_ERR, ha, "%s: Login failed: %s\n", __func__,
1734 goto exit_conn_start;
1737 if (ddb_entry->fw_ddb_device_state == DDB_DS_NO_CONNECTION_ACTIVE)
1738 ddb_entry->fw_ddb_device_state = DDB_DS_LOGIN_IN_PROCESS;
1740 DEBUG2(printk(KERN_INFO "%s: DDB state [%d]\n", __func__,
1741 ddb_entry->fw_ddb_device_state));
1748 dma_free_coherent(&ha->pdev->dev, sizeof(*fw_ddb_entry),
1749 fw_ddb_entry, fw_ddb_entry_dma);
1753 static void qla4xxx_conn_destroy(struct iscsi_cls_conn *cls_conn)
1755 struct iscsi_cls_session *cls_sess = iscsi_conn_to_session(cls_conn);
1756 struct iscsi_session *sess;
1757 struct scsi_qla_host *ha;
1758 struct ddb_entry *ddb_entry;
1761 DEBUG2(printk(KERN_INFO "Func: %s\n", __func__));
1762 sess = cls_sess->dd_data;
1763 ddb_entry = sess->dd_data;
1766 options = LOGOUT_OPTION_CLOSE_SESSION;
1767 if (qla4xxx_session_logout_ddb(ha, ddb_entry, options) == QLA_ERROR)
1768 ql4_printk(KERN_ERR, ha, "%s: Logout failed\n", __func__);
1771 static void qla4xxx_task_work(struct work_struct *wdata)
1773 struct ql4_task_data *task_data;
1774 struct scsi_qla_host *ha;
1775 struct passthru_status *sts;
1776 struct iscsi_task *task;
1777 struct iscsi_hdr *hdr;
1780 struct iscsi_conn *conn;
1784 task_data = container_of(wdata, struct ql4_task_data, task_work);
1786 task = task_data->task;
1787 sts = &task_data->sts;
1788 hdr_len = sizeof(struct iscsi_hdr);
1790 DEBUG3(printk(KERN_INFO "Status returned\n"));
1791 DEBUG3(qla4xxx_dump_buffer(sts, 64));
1792 DEBUG3(printk(KERN_INFO "Response buffer"));
1793 DEBUG3(qla4xxx_dump_buffer(task_data->resp_buffer, 64));
1797 switch (sts->completionStatus) {
1798 case PASSTHRU_STATUS_COMPLETE:
1799 hdr = (struct iscsi_hdr *)task_data->resp_buffer;
1800 /* Assign back the itt in hdr, until we use the PREASSIGN_TAG */
1803 data = task_data->resp_buffer + hdr_len;
1804 data_len = task_data->resp_len - hdr_len;
1805 iscsi_complete_pdu(conn, hdr, data, data_len);
1808 ql4_printk(KERN_ERR, ha, "Passthru failed status = 0x%x\n",
1809 sts->completionStatus);
1815 static int qla4xxx_alloc_pdu(struct iscsi_task *task, uint8_t opcode)
1817 struct ql4_task_data *task_data;
1818 struct iscsi_session *sess;
1819 struct ddb_entry *ddb_entry;
1820 struct scsi_qla_host *ha;
1823 sess = task->conn->session;
1824 ddb_entry = sess->dd_data;
1826 task_data = task->dd_data;
1827 memset(task_data, 0, sizeof(struct ql4_task_data));
1830 ql4_printk(KERN_INFO, ha,
1831 "%s: SCSI Commands not implemented\n", __func__);
1835 hdr_len = sizeof(struct iscsi_hdr);
1837 task_data->task = task;
1839 if (task->data_count) {
1840 task_data->data_dma = dma_map_single(&ha->pdev->dev, task->data,
1845 DEBUG2(ql4_printk(KERN_INFO, ha, "%s: MaxRecvLen %u, iscsi hrd %d\n",
1846 __func__, task->conn->max_recv_dlength, hdr_len));
1848 task_data->resp_len = task->conn->max_recv_dlength + hdr_len;
1849 task_data->resp_buffer = dma_alloc_coherent(&ha->pdev->dev,
1850 task_data->resp_len,
1851 &task_data->resp_dma,
1853 if (!task_data->resp_buffer)
1854 goto exit_alloc_pdu;
1856 task_data->req_len = task->data_count + hdr_len;
1857 task_data->req_buffer = dma_alloc_coherent(&ha->pdev->dev,
1859 &task_data->req_dma,
1861 if (!task_data->req_buffer)
1862 goto exit_alloc_pdu;
1864 task->hdr = task_data->req_buffer;
1866 INIT_WORK(&task_data->task_work, qla4xxx_task_work);
1871 if (task_data->resp_buffer)
1872 dma_free_coherent(&ha->pdev->dev, task_data->resp_len,
1873 task_data->resp_buffer, task_data->resp_dma);
1875 if (task_data->req_buffer)
1876 dma_free_coherent(&ha->pdev->dev, task_data->req_len,
1877 task_data->req_buffer, task_data->req_dma);
1881 static void qla4xxx_task_cleanup(struct iscsi_task *task)
1883 struct ql4_task_data *task_data;
1884 struct iscsi_session *sess;
1885 struct ddb_entry *ddb_entry;
1886 struct scsi_qla_host *ha;
1889 hdr_len = sizeof(struct iscsi_hdr);
1890 sess = task->conn->session;
1891 ddb_entry = sess->dd_data;
1893 task_data = task->dd_data;
1895 if (task->data_count) {
1896 dma_unmap_single(&ha->pdev->dev, task_data->data_dma,
1897 task->data_count, PCI_DMA_TODEVICE);
1900 DEBUG2(ql4_printk(KERN_INFO, ha, "%s: MaxRecvLen %u, iscsi hrd %d\n",
1901 __func__, task->conn->max_recv_dlength, hdr_len));
1903 dma_free_coherent(&ha->pdev->dev, task_data->resp_len,
1904 task_data->resp_buffer, task_data->resp_dma);
1905 dma_free_coherent(&ha->pdev->dev, task_data->req_len,
1906 task_data->req_buffer, task_data->req_dma);
1910 static int qla4xxx_task_xmit(struct iscsi_task *task)
1912 struct scsi_cmnd *sc = task->sc;
1913 struct iscsi_session *sess = task->conn->session;
1914 struct ddb_entry *ddb_entry = sess->dd_data;
1915 struct scsi_qla_host *ha = ddb_entry->ha;
1918 return qla4xxx_send_passthru0(task);
1920 ql4_printk(KERN_INFO, ha, "%s: scsi cmd xmit not implemented\n",
1925 static void qla4xxx_copy_fwddb_param(struct scsi_qla_host *ha,
1926 struct dev_db_entry *fw_ddb_entry,
1927 struct iscsi_cls_session *cls_sess,
1928 struct iscsi_cls_conn *cls_conn)
1931 struct iscsi_session *sess;
1932 struct ddb_entry *ddb_entry;
1933 struct iscsi_conn *conn;
1934 char ip_addr[DDB_IPADDR_LEN];
1935 uint16_t options = 0;
1937 sess = cls_sess->dd_data;
1938 ddb_entry = sess->dd_data;
1939 conn = cls_conn->dd_data;
1941 ddb_entry->chap_tbl_idx = le16_to_cpu(fw_ddb_entry->chap_tbl_idx);
1943 conn->max_recv_dlength = BYTE_UNITS *
1944 le16_to_cpu(fw_ddb_entry->iscsi_max_rcv_data_seg_len);
1946 conn->max_xmit_dlength = BYTE_UNITS *
1947 le16_to_cpu(fw_ddb_entry->iscsi_max_snd_data_seg_len);
1949 sess->initial_r2t_en =
1950 (BIT_10 & le16_to_cpu(fw_ddb_entry->iscsi_options));
1952 sess->max_r2t = le16_to_cpu(fw_ddb_entry->iscsi_max_outsnd_r2t);
1954 sess->imm_data_en = (BIT_11 & le16_to_cpu(fw_ddb_entry->iscsi_options));
1956 sess->first_burst = BYTE_UNITS *
1957 le16_to_cpu(fw_ddb_entry->iscsi_first_burst_len);
1959 sess->max_burst = BYTE_UNITS *
1960 le16_to_cpu(fw_ddb_entry->iscsi_max_burst_len);
1962 sess->time2wait = le16_to_cpu(fw_ddb_entry->iscsi_def_time2wait);
1964 sess->time2retain = le16_to_cpu(fw_ddb_entry->iscsi_def_time2retain);
1966 conn->persistent_port = le16_to_cpu(fw_ddb_entry->port);
1968 sess->tpgt = le32_to_cpu(fw_ddb_entry->tgt_portal_grp);
1970 options = le16_to_cpu(fw_ddb_entry->options);
1971 if (options & DDB_OPT_IPV6_DEVICE)
1972 sprintf(ip_addr, "%pI6", fw_ddb_entry->ip_addr);
1974 sprintf(ip_addr, "%pI4", fw_ddb_entry->ip_addr);
1976 iscsi_set_param(cls_conn, ISCSI_PARAM_TARGET_NAME,
1977 (char *)fw_ddb_entry->iscsi_name, buflen);
1978 iscsi_set_param(cls_conn, ISCSI_PARAM_INITIATOR_NAME,
1979 (char *)ha->name_string, buflen);
1980 iscsi_set_param(cls_conn, ISCSI_PARAM_PERSISTENT_ADDRESS,
1981 (char *)ip_addr, buflen);
1982 iscsi_set_param(cls_conn, ISCSI_PARAM_TARGET_ALIAS,
1983 (char *)fw_ddb_entry->iscsi_alias, buflen);
1986 void qla4xxx_update_session_conn_fwddb_param(struct scsi_qla_host *ha,
1987 struct ddb_entry *ddb_entry)
1989 struct iscsi_cls_session *cls_sess;
1990 struct iscsi_cls_conn *cls_conn;
1992 dma_addr_t fw_ddb_entry_dma;
1993 struct dev_db_entry *fw_ddb_entry;
1995 fw_ddb_entry = dma_alloc_coherent(&ha->pdev->dev, sizeof(*fw_ddb_entry),
1996 &fw_ddb_entry_dma, GFP_KERNEL);
1997 if (!fw_ddb_entry) {
1998 ql4_printk(KERN_ERR, ha,
1999 "%s: Unable to allocate dma buffer\n", __func__);
2000 goto exit_session_conn_fwddb_param;
2003 if (qla4xxx_get_fwddb_entry(ha, ddb_entry->fw_ddb_index, fw_ddb_entry,
2004 fw_ddb_entry_dma, NULL, NULL, &ddb_state,
2005 NULL, NULL, NULL) == QLA_ERROR) {
2006 DEBUG2(ql4_printk(KERN_ERR, ha, "scsi%ld: %s: failed "
2007 "get_ddb_entry for fw_ddb_index %d\n",
2008 ha->host_no, __func__,
2009 ddb_entry->fw_ddb_index));
2010 goto exit_session_conn_fwddb_param;
2013 cls_sess = ddb_entry->sess;
2015 cls_conn = ddb_entry->conn;
2018 qla4xxx_copy_fwddb_param(ha, fw_ddb_entry, cls_sess, cls_conn);
2020 exit_session_conn_fwddb_param:
2022 dma_free_coherent(&ha->pdev->dev, sizeof(*fw_ddb_entry),
2023 fw_ddb_entry, fw_ddb_entry_dma);
2026 void qla4xxx_update_session_conn_param(struct scsi_qla_host *ha,
2027 struct ddb_entry *ddb_entry)
2029 struct iscsi_cls_session *cls_sess;
2030 struct iscsi_cls_conn *cls_conn;
2031 struct iscsi_session *sess;
2032 struct iscsi_conn *conn;
2034 dma_addr_t fw_ddb_entry_dma;
2035 struct dev_db_entry *fw_ddb_entry;
2037 fw_ddb_entry = dma_alloc_coherent(&ha->pdev->dev, sizeof(*fw_ddb_entry),
2038 &fw_ddb_entry_dma, GFP_KERNEL);
2039 if (!fw_ddb_entry) {
2040 ql4_printk(KERN_ERR, ha,
2041 "%s: Unable to allocate dma buffer\n", __func__);
2042 goto exit_session_conn_param;
2045 if (qla4xxx_get_fwddb_entry(ha, ddb_entry->fw_ddb_index, fw_ddb_entry,
2046 fw_ddb_entry_dma, NULL, NULL, &ddb_state,
2047 NULL, NULL, NULL) == QLA_ERROR) {
2048 DEBUG2(ql4_printk(KERN_ERR, ha, "scsi%ld: %s: failed "
2049 "get_ddb_entry for fw_ddb_index %d\n",
2050 ha->host_no, __func__,
2051 ddb_entry->fw_ddb_index));
2052 goto exit_session_conn_param;
2055 cls_sess = ddb_entry->sess;
2056 sess = cls_sess->dd_data;
2058 cls_conn = ddb_entry->conn;
2059 conn = cls_conn->dd_data;
2061 /* Update timers after login */
2062 ddb_entry->default_relogin_timeout =
2063 (le16_to_cpu(fw_ddb_entry->def_timeout) > LOGIN_TOV) &&
2064 (le16_to_cpu(fw_ddb_entry->def_timeout) < LOGIN_TOV * 10) ?
2065 le16_to_cpu(fw_ddb_entry->def_timeout) : LOGIN_TOV;
2066 ddb_entry->default_time2wait =
2067 le16_to_cpu(fw_ddb_entry->iscsi_def_time2wait);
2070 ddb_entry->chap_tbl_idx = le16_to_cpu(fw_ddb_entry->chap_tbl_idx);
2071 conn->max_recv_dlength = BYTE_UNITS *
2072 le16_to_cpu(fw_ddb_entry->iscsi_max_rcv_data_seg_len);
2074 conn->max_xmit_dlength = BYTE_UNITS *
2075 le16_to_cpu(fw_ddb_entry->iscsi_max_snd_data_seg_len);
2077 sess->initial_r2t_en =
2078 (BIT_10 & le16_to_cpu(fw_ddb_entry->iscsi_options));
2080 sess->max_r2t = le16_to_cpu(fw_ddb_entry->iscsi_max_outsnd_r2t);
2082 sess->imm_data_en = (BIT_11 & le16_to_cpu(fw_ddb_entry->iscsi_options));
2084 sess->first_burst = BYTE_UNITS *
2085 le16_to_cpu(fw_ddb_entry->iscsi_first_burst_len);
2087 sess->max_burst = BYTE_UNITS *
2088 le16_to_cpu(fw_ddb_entry->iscsi_max_burst_len);
2090 sess->time2wait = le16_to_cpu(fw_ddb_entry->iscsi_def_time2wait);
2092 sess->time2retain = le16_to_cpu(fw_ddb_entry->iscsi_def_time2retain);
2094 sess->tpgt = le32_to_cpu(fw_ddb_entry->tgt_portal_grp);
2096 memcpy(sess->initiatorname, ha->name_string,
2097 min(sizeof(ha->name_string), sizeof(sess->initiatorname)));
2099 iscsi_set_param(cls_conn, ISCSI_PARAM_TARGET_ALIAS,
2100 (char *)fw_ddb_entry->iscsi_alias, 0);
2102 exit_session_conn_param:
2104 dma_free_coherent(&ha->pdev->dev, sizeof(*fw_ddb_entry),
2105 fw_ddb_entry, fw_ddb_entry_dma);
2112 static void qla4xxx_start_timer(struct scsi_qla_host *ha, void *func,
2113 unsigned long interval)
2115 DEBUG(printk("scsi: %s: Starting timer thread for adapter %d\n",
2116 __func__, ha->host->host_no));
2117 init_timer(&ha->timer);
2118 ha->timer.expires = jiffies + interval * HZ;
2119 ha->timer.data = (unsigned long)ha;
2120 ha->timer.function = (void (*)(unsigned long))func;
2121 add_timer(&ha->timer);
2122 ha->timer_active = 1;
2125 static void qla4xxx_stop_timer(struct scsi_qla_host *ha)
2127 del_timer_sync(&ha->timer);
2128 ha->timer_active = 0;
2132 * qla4xxx_mark_device_missing - blocks the session
2133 * @cls_session: Pointer to the session to be blocked
2134 * @ddb_entry: Pointer to device database entry
2136 * This routine marks a device missing and close connection.
2138 void qla4xxx_mark_device_missing(struct iscsi_cls_session *cls_session)
2140 iscsi_block_session(cls_session);
2144 * qla4xxx_mark_all_devices_missing - mark all devices as missing.
2145 * @ha: Pointer to host adapter structure.
2147 * This routine marks a device missing and resets the relogin retry count.
2149 void qla4xxx_mark_all_devices_missing(struct scsi_qla_host *ha)
2151 iscsi_host_for_each_session(ha->host, qla4xxx_mark_device_missing);
2154 static struct srb* qla4xxx_get_new_srb(struct scsi_qla_host *ha,
2155 struct ddb_entry *ddb_entry,
2156 struct scsi_cmnd *cmd)
2160 srb = mempool_alloc(ha->srb_mempool, GFP_ATOMIC);
2164 kref_init(&srb->srb_ref);
2166 srb->ddb = ddb_entry;
2169 CMD_SP(cmd) = (void *)srb;
2174 static void qla4xxx_srb_free_dma(struct scsi_qla_host *ha, struct srb *srb)
2176 struct scsi_cmnd *cmd = srb->cmd;
2178 if (srb->flags & SRB_DMA_VALID) {
2179 scsi_dma_unmap(cmd);
2180 srb->flags &= ~SRB_DMA_VALID;
2185 void qla4xxx_srb_compl(struct kref *ref)
2187 struct srb *srb = container_of(ref, struct srb, srb_ref);
2188 struct scsi_cmnd *cmd = srb->cmd;
2189 struct scsi_qla_host *ha = srb->ha;
2191 qla4xxx_srb_free_dma(ha, srb);
2193 mempool_free(srb, ha->srb_mempool);
2195 cmd->scsi_done(cmd);
2199 * qla4xxx_queuecommand - scsi layer issues scsi command to driver.
2201 * @cmd: Pointer to Linux's SCSI command structure
2204 * This routine is invoked by Linux to send a SCSI command to the driver.
2205 * The mid-level driver tries to ensure that queuecommand never gets
2206 * invoked concurrently with itself or the interrupt handler (although
2207 * the interrupt handler may call this routine as part of request-
2208 * completion handling). Unfortunely, it sometimes calls the scheduler
2209 * in interrupt context which is a big NO! NO!.
2211 static int qla4xxx_queuecommand(struct Scsi_Host *host, struct scsi_cmnd *cmd)
2213 struct scsi_qla_host *ha = to_qla_host(host);
2214 struct ddb_entry *ddb_entry = cmd->device->hostdata;
2215 struct iscsi_cls_session *sess = ddb_entry->sess;
2219 if (test_bit(AF_EEH_BUSY, &ha->flags)) {
2220 if (test_bit(AF_PCI_CHANNEL_IO_PERM_FAILURE, &ha->flags))
2221 cmd->result = DID_NO_CONNECT << 16;
2223 cmd->result = DID_REQUEUE << 16;
2224 goto qc_fail_command;
2228 cmd->result = DID_IMM_RETRY << 16;
2229 goto qc_fail_command;
2232 rval = iscsi_session_chkready(sess);
2235 goto qc_fail_command;
2238 if (test_bit(DPC_RESET_HA_INTR, &ha->dpc_flags) ||
2239 test_bit(DPC_RESET_ACTIVE, &ha->dpc_flags) ||
2240 test_bit(DPC_RESET_HA, &ha->dpc_flags) ||
2241 test_bit(DPC_HA_UNRECOVERABLE, &ha->dpc_flags) ||
2242 test_bit(DPC_HA_NEED_QUIESCENT, &ha->dpc_flags) ||
2243 !test_bit(AF_ONLINE, &ha->flags) ||
2244 !test_bit(AF_LINK_UP, &ha->flags) ||
2245 test_bit(DPC_RESET_HA_FW_CONTEXT, &ha->dpc_flags))
2248 srb = qla4xxx_get_new_srb(ha, ddb_entry, cmd);
2252 rval = qla4xxx_send_command_to_isp(ha, srb);
2253 if (rval != QLA_SUCCESS)
2254 goto qc_host_busy_free_sp;
2258 qc_host_busy_free_sp:
2259 qla4xxx_srb_free_dma(ha, srb);
2260 mempool_free(srb, ha->srb_mempool);
2263 return SCSI_MLQUEUE_HOST_BUSY;
2266 cmd->scsi_done(cmd);
2272 * qla4xxx_mem_free - frees memory allocated to adapter
2273 * @ha: Pointer to host adapter structure.
2275 * Frees memory previously allocated by qla4xxx_mem_alloc
2277 static void qla4xxx_mem_free(struct scsi_qla_host *ha)
2280 dma_free_coherent(&ha->pdev->dev, ha->queues_len, ha->queues,
2289 ha->request_ring = NULL;
2290 ha->request_dma = 0;
2291 ha->response_ring = NULL;
2292 ha->response_dma = 0;
2293 ha->shadow_regs = NULL;
2294 ha->shadow_regs_dma = 0;
2296 ha->fw_dump_size = 0;
2298 /* Free srb pool. */
2299 if (ha->srb_mempool)
2300 mempool_destroy(ha->srb_mempool);
2302 ha->srb_mempool = NULL;
2304 if (ha->chap_dma_pool)
2305 dma_pool_destroy(ha->chap_dma_pool);
2308 vfree(ha->chap_list);
2309 ha->chap_list = NULL;
2311 if (ha->fw_ddb_dma_pool)
2312 dma_pool_destroy(ha->fw_ddb_dma_pool);
2314 /* release io space registers */
2315 if (is_qla8022(ha)) {
2318 (struct device_reg_82xx __iomem *)ha->nx_pcibase);
2319 } else if (is_qla8032(ha)) {
2322 (struct device_reg_83xx __iomem *)ha->nx_pcibase);
2323 } else if (ha->reg) {
2327 if (ha->reset_tmplt.buff)
2328 vfree(ha->reset_tmplt.buff);
2330 pci_release_regions(ha->pdev);
2334 * qla4xxx_mem_alloc - allocates memory for use by adapter.
2335 * @ha: Pointer to host adapter structure
2337 * Allocates DMA memory for request and response queues. Also allocates memory
2340 static int qla4xxx_mem_alloc(struct scsi_qla_host *ha)
2342 unsigned long align;
2344 /* Allocate contiguous block of DMA memory for queues. */
2345 ha->queues_len = ((REQUEST_QUEUE_DEPTH * QUEUE_SIZE) +
2346 (RESPONSE_QUEUE_DEPTH * QUEUE_SIZE) +
2347 sizeof(struct shadow_regs) +
2349 (PAGE_SIZE - 1)) & ~(PAGE_SIZE - 1);
2350 ha->queues = dma_alloc_coherent(&ha->pdev->dev, ha->queues_len,
2351 &ha->queues_dma, GFP_KERNEL);
2352 if (ha->queues == NULL) {
2353 ql4_printk(KERN_WARNING, ha,
2354 "Memory Allocation failed - queues.\n");
2356 goto mem_alloc_error_exit;
2358 memset(ha->queues, 0, ha->queues_len);
2361 * As per RISC alignment requirements -- the bus-address must be a
2362 * multiple of the request-ring size (in bytes).
2365 if ((unsigned long)ha->queues_dma & (MEM_ALIGN_VALUE - 1))
2366 align = MEM_ALIGN_VALUE - ((unsigned long)ha->queues_dma &
2367 (MEM_ALIGN_VALUE - 1));
2369 /* Update request and response queue pointers. */
2370 ha->request_dma = ha->queues_dma + align;
2371 ha->request_ring = (struct queue_entry *) (ha->queues + align);
2372 ha->response_dma = ha->queues_dma + align +
2373 (REQUEST_QUEUE_DEPTH * QUEUE_SIZE);
2374 ha->response_ring = (struct queue_entry *) (ha->queues + align +
2375 (REQUEST_QUEUE_DEPTH *
2377 ha->shadow_regs_dma = ha->queues_dma + align +
2378 (REQUEST_QUEUE_DEPTH * QUEUE_SIZE) +
2379 (RESPONSE_QUEUE_DEPTH * QUEUE_SIZE);
2380 ha->shadow_regs = (struct shadow_regs *) (ha->queues + align +
2381 (REQUEST_QUEUE_DEPTH *
2383 (RESPONSE_QUEUE_DEPTH *
2386 /* Allocate memory for srb pool. */
2387 ha->srb_mempool = mempool_create(SRB_MIN_REQ, mempool_alloc_slab,
2388 mempool_free_slab, srb_cachep);
2389 if (ha->srb_mempool == NULL) {
2390 ql4_printk(KERN_WARNING, ha,
2391 "Memory Allocation failed - SRB Pool.\n");
2393 goto mem_alloc_error_exit;
2396 ha->chap_dma_pool = dma_pool_create("ql4_chap", &ha->pdev->dev,
2397 CHAP_DMA_BLOCK_SIZE, 8, 0);
2399 if (ha->chap_dma_pool == NULL) {
2400 ql4_printk(KERN_WARNING, ha,
2401 "%s: chap_dma_pool allocation failed..\n", __func__);
2402 goto mem_alloc_error_exit;
2405 ha->fw_ddb_dma_pool = dma_pool_create("ql4_fw_ddb", &ha->pdev->dev,
2406 DDB_DMA_BLOCK_SIZE, 8, 0);
2408 if (ha->fw_ddb_dma_pool == NULL) {
2409 ql4_printk(KERN_WARNING, ha,
2410 "%s: fw_ddb_dma_pool allocation failed..\n",
2412 goto mem_alloc_error_exit;
2417 mem_alloc_error_exit:
2418 qla4xxx_mem_free(ha);
2423 * qla4_8xxx_check_temp - Check the ISP82XX temperature.
2424 * @ha: adapter block pointer.
2426 * Note: The caller should not hold the idc lock.
2428 static int qla4_8xxx_check_temp(struct scsi_qla_host *ha)
2430 uint32_t temp, temp_state, temp_val;
2431 int status = QLA_SUCCESS;
2433 temp = qla4_8xxx_rd_direct(ha, QLA8XXX_CRB_TEMP_STATE);
2435 temp_state = qla82xx_get_temp_state(temp);
2436 temp_val = qla82xx_get_temp_val(temp);
2438 if (temp_state == QLA82XX_TEMP_PANIC) {
2439 ql4_printk(KERN_WARNING, ha, "Device temperature %d degrees C"
2440 " exceeds maximum allowed. Hardware has been shut"
2441 " down.\n", temp_val);
2443 } else if (temp_state == QLA82XX_TEMP_WARN) {
2444 if (ha->temperature == QLA82XX_TEMP_NORMAL)
2445 ql4_printk(KERN_WARNING, ha, "Device temperature %d"
2446 " degrees C exceeds operating range."
2447 " Immediate action needed.\n", temp_val);
2449 if (ha->temperature == QLA82XX_TEMP_WARN)
2450 ql4_printk(KERN_INFO, ha, "Device temperature is"
2451 " now %d degrees C in normal range.\n",
2454 ha->temperature = temp_state;
2459 * qla4_8xxx_check_fw_alive - Check firmware health
2460 * @ha: Pointer to host adapter structure.
2462 * Context: Interrupt
2464 static int qla4_8xxx_check_fw_alive(struct scsi_qla_host *ha)
2466 uint32_t fw_heartbeat_counter;
2467 int status = QLA_SUCCESS;
2469 fw_heartbeat_counter = qla4_8xxx_rd_direct(ha,
2470 QLA8XXX_PEG_ALIVE_COUNTER);
2471 /* If PEG_ALIVE_COUNTER is 0xffffffff, AER/EEH is in progress, ignore */
2472 if (fw_heartbeat_counter == 0xffffffff) {
2473 DEBUG2(printk(KERN_WARNING "scsi%ld: %s: Device in frozen "
2474 "state, QLA82XX_PEG_ALIVE_COUNTER is 0xffffffff\n",
2475 ha->host_no, __func__));
2479 if (ha->fw_heartbeat_counter == fw_heartbeat_counter) {
2480 ha->seconds_since_last_heartbeat++;
2481 /* FW not alive after 2 seconds */
2482 if (ha->seconds_since_last_heartbeat == 2) {
2483 ha->seconds_since_last_heartbeat = 0;
2484 qla4_8xxx_dump_peg_reg(ha);
2488 ha->seconds_since_last_heartbeat = 0;
2490 ha->fw_heartbeat_counter = fw_heartbeat_counter;
2494 static void qla4_8xxx_process_fw_error(struct scsi_qla_host *ha)
2496 uint32_t halt_status;
2497 int halt_status_unrecoverable = 0;
2499 halt_status = qla4_8xxx_rd_direct(ha, QLA8XXX_PEG_HALT_STATUS1);
2501 if (is_qla8022(ha)) {
2502 ql4_printk(KERN_INFO, ha, "%s: disabling pause transmit on port 0 & 1.\n",
2504 qla4_82xx_wr_32(ha, QLA82XX_CRB_NIU + 0x98,
2505 CRB_NIU_XG_PAUSE_CTL_P0 |
2506 CRB_NIU_XG_PAUSE_CTL_P1);
2508 if (QLA82XX_FWERROR_CODE(halt_status) == 0x67)
2509 ql4_printk(KERN_ERR, ha, "%s: Firmware aborted with error code 0x00006700. Device is being reset\n",
2511 if (halt_status & HALT_STATUS_UNRECOVERABLE)
2512 halt_status_unrecoverable = 1;
2513 } else if (is_qla8032(ha)) {
2514 if (halt_status & QLA83XX_HALT_STATUS_FW_RESET)
2515 ql4_printk(KERN_ERR, ha, "%s: Firmware error detected device is being reset\n",
2517 else if (halt_status & QLA83XX_HALT_STATUS_UNRECOVERABLE)
2518 halt_status_unrecoverable = 1;
2522 * Since we cannot change dev_state in interrupt context,
2523 * set appropriate DPC flag then wakeup DPC
2525 if (halt_status_unrecoverable) {
2526 set_bit(DPC_HA_UNRECOVERABLE, &ha->dpc_flags);
2528 ql4_printk(KERN_INFO, ha, "%s: detect abort needed!\n",
2530 set_bit(DPC_RESET_HA, &ha->dpc_flags);
2532 qla4xxx_mailbox_premature_completion(ha);
2533 qla4xxx_wake_dpc(ha);
2537 * qla4_8xxx_watchdog - Poll dev state
2538 * @ha: Pointer to host adapter structure.
2540 * Context: Interrupt
2542 void qla4_8xxx_watchdog(struct scsi_qla_host *ha)
2546 /* don't poll if reset is going on */
2547 if (!(test_bit(DPC_RESET_ACTIVE, &ha->dpc_flags) ||
2548 test_bit(DPC_RESET_HA, &ha->dpc_flags) ||
2549 test_bit(DPC_RETRY_RESET_HA, &ha->dpc_flags))) {
2550 dev_state = qla4_8xxx_rd_direct(ha, QLA8XXX_CRB_DEV_STATE);
2552 if (qla4_8xxx_check_temp(ha)) {
2553 if (is_qla8022(ha)) {
2554 ql4_printk(KERN_INFO, ha, "disabling pause transmit on port 0 & 1.\n");
2555 qla4_82xx_wr_32(ha, QLA82XX_CRB_NIU + 0x98,
2556 CRB_NIU_XG_PAUSE_CTL_P0 |
2557 CRB_NIU_XG_PAUSE_CTL_P1);
2559 set_bit(DPC_HA_UNRECOVERABLE, &ha->dpc_flags);
2560 qla4xxx_wake_dpc(ha);
2561 } else if (dev_state == QLA8XXX_DEV_NEED_RESET &&
2562 !test_bit(DPC_RESET_HA, &ha->dpc_flags)) {
2563 if (is_qla8032(ha) ||
2564 (is_qla8022(ha) && !ql4xdontresethba)) {
2565 ql4_printk(KERN_INFO, ha, "%s: HW State: "
2566 "NEED RESET!\n", __func__);
2567 set_bit(DPC_RESET_HA, &ha->dpc_flags);
2568 qla4xxx_wake_dpc(ha);
2570 } else if (dev_state == QLA8XXX_DEV_NEED_QUIESCENT &&
2571 !test_bit(DPC_HA_NEED_QUIESCENT, &ha->dpc_flags)) {
2572 ql4_printk(KERN_INFO, ha, "%s: HW State: NEED QUIES!\n",
2574 set_bit(DPC_HA_NEED_QUIESCENT, &ha->dpc_flags);
2575 qla4xxx_wake_dpc(ha);
2577 /* Check firmware health */
2578 if (qla4_8xxx_check_fw_alive(ha))
2579 qla4_8xxx_process_fw_error(ha);
2584 static void qla4xxx_check_relogin_flash_ddb(struct iscsi_cls_session *cls_sess)
2586 struct iscsi_session *sess;
2587 struct ddb_entry *ddb_entry;
2588 struct scsi_qla_host *ha;
2590 sess = cls_sess->dd_data;
2591 ddb_entry = sess->dd_data;
2594 if (!(ddb_entry->ddb_type == FLASH_DDB))
2597 if (adapter_up(ha) && !test_bit(DF_RELOGIN, &ddb_entry->flags) &&
2598 !iscsi_is_session_online(cls_sess)) {
2599 if (atomic_read(&ddb_entry->retry_relogin_timer) !=
2601 if (atomic_read(&ddb_entry->retry_relogin_timer) ==
2603 atomic_set(&ddb_entry->retry_relogin_timer,
2605 set_bit(DPC_RELOGIN_DEVICE, &ha->dpc_flags);
2606 set_bit(DF_RELOGIN, &ddb_entry->flags);
2607 DEBUG2(ql4_printk(KERN_INFO, ha,
2608 "%s: index [%d] login device\n",
2609 __func__, ddb_entry->fw_ddb_index));
2611 atomic_dec(&ddb_entry->retry_relogin_timer);
2615 /* Wait for relogin to timeout */
2616 if (atomic_read(&ddb_entry->relogin_timer) &&
2617 (atomic_dec_and_test(&ddb_entry->relogin_timer) != 0)) {
2619 * If the relogin times out and the device is
2620 * still NOT ONLINE then try and relogin again.
2622 if (!iscsi_is_session_online(cls_sess)) {
2623 /* Reset retry relogin timer */
2624 atomic_inc(&ddb_entry->relogin_retry_count);
2625 DEBUG2(ql4_printk(KERN_INFO, ha,
2626 "%s: index[%d] relogin timed out-retrying"
2627 " relogin (%d), retry (%d)\n", __func__,
2628 ddb_entry->fw_ddb_index,
2629 atomic_read(&ddb_entry->relogin_retry_count),
2630 ddb_entry->default_time2wait + 4));
2631 set_bit(DPC_RELOGIN_DEVICE, &ha->dpc_flags);
2632 atomic_set(&ddb_entry->retry_relogin_timer,
2633 ddb_entry->default_time2wait + 4);
2639 * qla4xxx_timer - checks every second for work to do.
2640 * @ha: Pointer to host adapter structure.
2642 static void qla4xxx_timer(struct scsi_qla_host *ha)
2647 iscsi_host_for_each_session(ha->host, qla4xxx_check_relogin_flash_ddb);
2649 /* If we are in the middle of AER/EEH processing
2650 * skip any processing and reschedule the timer
2652 if (test_bit(AF_EEH_BUSY, &ha->flags)) {
2653 mod_timer(&ha->timer, jiffies + HZ);
2657 /* Hardware read to trigger an EEH error during mailbox waits. */
2658 if (!pci_channel_offline(ha->pdev))
2659 pci_read_config_word(ha->pdev, PCI_VENDOR_ID, &w);
2662 qla4_8xxx_watchdog(ha);
2664 if (is_qla40XX(ha)) {
2665 /* Check for heartbeat interval. */
2666 if (ha->firmware_options & FWOPT_HEARTBEAT_ENABLE &&
2667 ha->heartbeat_interval != 0) {
2668 ha->seconds_since_last_heartbeat++;
2669 if (ha->seconds_since_last_heartbeat >
2670 ha->heartbeat_interval + 2)
2671 set_bit(DPC_RESET_HA, &ha->dpc_flags);
2675 /* Process any deferred work. */
2676 if (!list_empty(&ha->work_list))
2679 /* Wakeup the dpc routine for this adapter, if needed. */
2681 test_bit(DPC_RESET_HA, &ha->dpc_flags) ||
2682 test_bit(DPC_RETRY_RESET_HA, &ha->dpc_flags) ||
2683 test_bit(DPC_RELOGIN_DEVICE, &ha->dpc_flags) ||
2684 test_bit(DPC_RESET_HA_FW_CONTEXT, &ha->dpc_flags) ||
2685 test_bit(DPC_RESET_HA_INTR, &ha->dpc_flags) ||
2686 test_bit(DPC_GET_DHCP_IP_ADDR, &ha->dpc_flags) ||
2687 test_bit(DPC_LINK_CHANGED, &ha->dpc_flags) ||
2688 test_bit(DPC_HA_UNRECOVERABLE, &ha->dpc_flags) ||
2689 test_bit(DPC_HA_NEED_QUIESCENT, &ha->dpc_flags) ||
2690 test_bit(DPC_AEN, &ha->dpc_flags)) {
2691 DEBUG2(printk("scsi%ld: %s: scheduling dpc routine"
2692 " - dpc flags = 0x%lx\n",
2693 ha->host_no, __func__, ha->dpc_flags));
2694 qla4xxx_wake_dpc(ha);
2697 /* Reschedule timer thread to call us back in one second */
2698 mod_timer(&ha->timer, jiffies + HZ);
2700 DEBUG2(ha->seconds_since_last_intr++);
2704 * qla4xxx_cmd_wait - waits for all outstanding commands to complete
2705 * @ha: Pointer to host adapter structure.
2707 * This routine stalls the driver until all outstanding commands are returned.
2708 * Caller must release the Hardware Lock prior to calling this routine.
2710 static int qla4xxx_cmd_wait(struct scsi_qla_host *ha)
2713 unsigned long flags;
2714 struct scsi_cmnd *cmd;
2716 unsigned long wtime = jiffies + (WAIT_CMD_TOV * HZ);
2718 DEBUG2(ql4_printk(KERN_INFO, ha, "Wait up to %d seconds for cmds to "
2719 "complete\n", WAIT_CMD_TOV));
2721 while (!time_after_eq(jiffies, wtime)) {
2722 spin_lock_irqsave(&ha->hardware_lock, flags);
2723 /* Find a command that hasn't completed. */
2724 for (index = 0; index < ha->host->can_queue; index++) {
2725 cmd = scsi_host_find_tag(ha->host, index);
2727 * We cannot just check if the index is valid,
2728 * becase if we are run from the scsi eh, then
2729 * the scsi/block layer is going to prevent
2730 * the tag from being released.
2732 if (cmd != NULL && CMD_SP(cmd))
2735 spin_unlock_irqrestore(&ha->hardware_lock, flags);
2737 /* If No Commands are pending, wait is complete */
2738 if (index == ha->host->can_queue)
2743 /* If we timed out on waiting for commands to come back
2748 int qla4xxx_hw_reset(struct scsi_qla_host *ha)
2750 uint32_t ctrl_status;
2751 unsigned long flags = 0;
2753 DEBUG2(printk(KERN_ERR "scsi%ld: %s\n", ha->host_no, __func__));
2755 if (ql4xxx_lock_drvr_wait(ha) != QLA_SUCCESS)
2758 spin_lock_irqsave(&ha->hardware_lock, flags);
2761 * If the SCSI Reset Interrupt bit is set, clear it.
2762 * Otherwise, the Soft Reset won't work.
2764 ctrl_status = readw(&ha->reg->ctrl_status);
2765 if ((ctrl_status & CSR_SCSI_RESET_INTR) != 0)
2766 writel(set_rmask(CSR_SCSI_RESET_INTR), &ha->reg->ctrl_status);
2768 /* Issue Soft Reset */
2769 writel(set_rmask(CSR_SOFT_RESET), &ha->reg->ctrl_status);
2770 readl(&ha->reg->ctrl_status);
2772 spin_unlock_irqrestore(&ha->hardware_lock, flags);
2777 * qla4xxx_soft_reset - performs soft reset.
2778 * @ha: Pointer to host adapter structure.
2780 int qla4xxx_soft_reset(struct scsi_qla_host *ha)
2782 uint32_t max_wait_time;
2783 unsigned long flags = 0;
2785 uint32_t ctrl_status;
2787 status = qla4xxx_hw_reset(ha);
2788 if (status != QLA_SUCCESS)
2792 /* Wait until the Network Reset Intr bit is cleared */
2793 max_wait_time = RESET_INTR_TOV;
2795 spin_lock_irqsave(&ha->hardware_lock, flags);
2796 ctrl_status = readw(&ha->reg->ctrl_status);
2797 spin_unlock_irqrestore(&ha->hardware_lock, flags);
2799 if ((ctrl_status & CSR_NET_RESET_INTR) == 0)
2803 } while ((--max_wait_time));
2805 if ((ctrl_status & CSR_NET_RESET_INTR) != 0) {
2806 DEBUG2(printk(KERN_WARNING
2807 "scsi%ld: Network Reset Intr not cleared by "
2808 "Network function, clearing it now!\n",
2810 spin_lock_irqsave(&ha->hardware_lock, flags);
2811 writel(set_rmask(CSR_NET_RESET_INTR), &ha->reg->ctrl_status);
2812 readl(&ha->reg->ctrl_status);
2813 spin_unlock_irqrestore(&ha->hardware_lock, flags);
2816 /* Wait until the firmware tells us the Soft Reset is done */
2817 max_wait_time = SOFT_RESET_TOV;
2819 spin_lock_irqsave(&ha->hardware_lock, flags);
2820 ctrl_status = readw(&ha->reg->ctrl_status);
2821 spin_unlock_irqrestore(&ha->hardware_lock, flags);
2823 if ((ctrl_status & CSR_SOFT_RESET) == 0) {
2824 status = QLA_SUCCESS;
2829 } while ((--max_wait_time));
2832 * Also, make sure that the SCSI Reset Interrupt bit has been cleared
2833 * after the soft reset has taken place.
2835 spin_lock_irqsave(&ha->hardware_lock, flags);
2836 ctrl_status = readw(&ha->reg->ctrl_status);
2837 if ((ctrl_status & CSR_SCSI_RESET_INTR) != 0) {
2838 writel(set_rmask(CSR_SCSI_RESET_INTR), &ha->reg->ctrl_status);
2839 readl(&ha->reg->ctrl_status);
2841 spin_unlock_irqrestore(&ha->hardware_lock, flags);
2843 /* If soft reset fails then most probably the bios on other
2844 * function is also enabled.
2845 * Since the initialization is sequential the other fn
2846 * wont be able to acknowledge the soft reset.
2847 * Issue a force soft reset to workaround this scenario.
2849 if (max_wait_time == 0) {
2850 /* Issue Force Soft Reset */
2851 spin_lock_irqsave(&ha->hardware_lock, flags);
2852 writel(set_rmask(CSR_FORCE_SOFT_RESET), &ha->reg->ctrl_status);
2853 readl(&ha->reg->ctrl_status);
2854 spin_unlock_irqrestore(&ha->hardware_lock, flags);
2855 /* Wait until the firmware tells us the Soft Reset is done */
2856 max_wait_time = SOFT_RESET_TOV;
2858 spin_lock_irqsave(&ha->hardware_lock, flags);
2859 ctrl_status = readw(&ha->reg->ctrl_status);
2860 spin_unlock_irqrestore(&ha->hardware_lock, flags);
2862 if ((ctrl_status & CSR_FORCE_SOFT_RESET) == 0) {
2863 status = QLA_SUCCESS;
2868 } while ((--max_wait_time));
2875 * qla4xxx_abort_active_cmds - returns all outstanding i/o requests to O.S.
2876 * @ha: Pointer to host adapter structure.
2877 * @res: returned scsi status
2879 * This routine is called just prior to a HARD RESET to return all
2880 * outstanding commands back to the Operating System.
2881 * Caller should make sure that the following locks are released
2882 * before this calling routine: Hardware lock, and io_request_lock.
2884 static void qla4xxx_abort_active_cmds(struct scsi_qla_host *ha, int res)
2888 unsigned long flags;
2890 spin_lock_irqsave(&ha->hardware_lock, flags);
2891 for (i = 0; i < ha->host->can_queue; i++) {
2892 srb = qla4xxx_del_from_active_array(ha, i);
2894 srb->cmd->result = res;
2895 kref_put(&srb->srb_ref, qla4xxx_srb_compl);
2898 spin_unlock_irqrestore(&ha->hardware_lock, flags);
2901 void qla4xxx_dead_adapter_cleanup(struct scsi_qla_host *ha)
2903 clear_bit(AF_ONLINE, &ha->flags);
2905 /* Disable the board */
2906 ql4_printk(KERN_INFO, ha, "Disabling the board\n");
2908 qla4xxx_abort_active_cmds(ha, DID_NO_CONNECT << 16);
2909 qla4xxx_mark_all_devices_missing(ha);
2910 clear_bit(AF_INIT_DONE, &ha->flags);
2913 static void qla4xxx_fail_session(struct iscsi_cls_session *cls_session)
2915 struct iscsi_session *sess;
2916 struct ddb_entry *ddb_entry;
2918 sess = cls_session->dd_data;
2919 ddb_entry = sess->dd_data;
2920 ddb_entry->fw_ddb_device_state = DDB_DS_SESSION_FAILED;
2922 if (ddb_entry->ddb_type == FLASH_DDB)
2923 iscsi_block_session(ddb_entry->sess);
2925 iscsi_session_failure(cls_session->dd_data,
2926 ISCSI_ERR_CONN_FAILED);
2930 * qla4xxx_recover_adapter - recovers adapter after a fatal error
2931 * @ha: Pointer to host adapter structure.
2933 static int qla4xxx_recover_adapter(struct scsi_qla_host *ha)
2935 int status = QLA_ERROR;
2936 uint8_t reset_chip = 0;
2940 /* Stall incoming I/O until we are done */
2941 scsi_block_requests(ha->host);
2942 clear_bit(AF_ONLINE, &ha->flags);
2943 clear_bit(AF_LINK_UP, &ha->flags);
2945 DEBUG2(ql4_printk(KERN_INFO, ha, "%s: adapter OFFLINE\n", __func__));
2947 set_bit(DPC_RESET_ACTIVE, &ha->dpc_flags);
2949 iscsi_host_for_each_session(ha->host, qla4xxx_fail_session);
2951 if (test_bit(DPC_RESET_HA, &ha->dpc_flags))
2954 /* For the DPC_RESET_HA_INTR case (ISP-4xxx specific)
2955 * do not reset adapter, jump to initialize_adapter */
2956 if (test_bit(DPC_RESET_HA_INTR, &ha->dpc_flags)) {
2957 status = QLA_SUCCESS;
2958 goto recover_ha_init_adapter;
2961 /* For the ISP-8xxx adapter, issue a stop_firmware if invoked
2962 * from eh_host_reset or ioctl module */
2963 if (is_qla80XX(ha) && !reset_chip &&
2964 test_bit(DPC_RESET_HA_FW_CONTEXT, &ha->dpc_flags)) {
2966 DEBUG2(ql4_printk(KERN_INFO, ha,
2967 "scsi%ld: %s - Performing stop_firmware...\n",
2968 ha->host_no, __func__));
2969 status = ha->isp_ops->reset_firmware(ha);
2970 if (status == QLA_SUCCESS) {
2971 if (!test_bit(AF_FW_RECOVERY, &ha->flags))
2972 qla4xxx_cmd_wait(ha);
2973 ha->isp_ops->disable_intrs(ha);
2974 qla4xxx_process_aen(ha, FLUSH_DDB_CHANGED_AENS);
2975 qla4xxx_abort_active_cmds(ha, DID_RESET << 16);
2977 /* If the stop_firmware fails then
2978 * reset the entire chip */
2980 clear_bit(DPC_RESET_HA_FW_CONTEXT, &ha->dpc_flags);
2981 set_bit(DPC_RESET_HA, &ha->dpc_flags);
2985 /* Issue full chip reset if recovering from a catastrophic error,
2986 * or if stop_firmware fails for ISP-8xxx.
2987 * This is the default case for ISP-4xxx */
2988 if (is_qla40XX(ha) || reset_chip) {
2992 /* Check if 8XXX firmware is alive or not
2993 * We may have arrived here from NEED_RESET
2995 if (test_bit(AF_FW_RECOVERY, &ha->flags))
2998 wait = jiffies + (FW_ALIVE_WAIT_TOV * HZ);
2999 while (time_before(jiffies, wait)) {
3000 if (qla4_8xxx_check_fw_alive(ha)) {
3001 qla4xxx_mailbox_premature_completion(ha);
3005 set_current_state(TASK_UNINTERRUPTIBLE);
3006 schedule_timeout(HZ);
3009 if (!test_bit(AF_FW_RECOVERY, &ha->flags))
3010 qla4xxx_cmd_wait(ha);
3012 qla4xxx_process_aen(ha, FLUSH_DDB_CHANGED_AENS);
3013 qla4xxx_abort_active_cmds(ha, DID_RESET << 16);
3014 DEBUG2(ql4_printk(KERN_INFO, ha,
3015 "scsi%ld: %s - Performing chip reset..\n",
3016 ha->host_no, __func__));
3017 status = ha->isp_ops->reset_chip(ha);
3020 /* Flush any pending ddb changed AENs */
3021 qla4xxx_process_aen(ha, FLUSH_DDB_CHANGED_AENS);
3023 recover_ha_init_adapter:
3024 /* Upon successful firmware/chip reset, re-initialize the adapter */
3025 if (status == QLA_SUCCESS) {
3026 /* For ISP-4xxx, force function 1 to always initialize
3027 * before function 3 to prevent both funcions from
3028 * stepping on top of the other */
3029 if (is_qla40XX(ha) && (ha->mac_index == 3))
3032 /* NOTE: AF_ONLINE flag set upon successful completion of
3033 * qla4xxx_initialize_adapter */
3034 status = qla4xxx_initialize_adapter(ha, RESET_ADAPTER);
3037 /* Retry failed adapter initialization, if necessary
3038 * Do not retry initialize_adapter for RESET_HA_INTR (ISP-4xxx specific)
3039 * case to prevent ping-pong resets between functions */
3040 if (!test_bit(AF_ONLINE, &ha->flags) &&
3041 !test_bit(DPC_RESET_HA_INTR, &ha->dpc_flags)) {
3042 /* Adapter initialization failed, see if we can retry
3044 * Since we don't want to block the DPC for too long
3045 * with multiple resets in the same thread,
3046 * utilize DPC to retry */
3047 if (is_qla80XX(ha)) {
3048 ha->isp_ops->idc_lock(ha);
3049 dev_state = qla4_8xxx_rd_direct(ha,
3050 QLA8XXX_CRB_DEV_STATE);
3051 ha->isp_ops->idc_unlock(ha);
3052 if (dev_state == QLA8XXX_DEV_FAILED) {
3053 ql4_printk(KERN_INFO, ha, "%s: don't retry "
3054 "recover adapter. H/W is in Failed "
3055 "state\n", __func__);
3056 qla4xxx_dead_adapter_cleanup(ha);
3057 clear_bit(DPC_RETRY_RESET_HA, &ha->dpc_flags);
3058 clear_bit(DPC_RESET_HA, &ha->dpc_flags);
3059 clear_bit(DPC_RESET_HA_FW_CONTEXT,
3067 if (!test_bit(DPC_RETRY_RESET_HA, &ha->dpc_flags)) {
3068 ha->retry_reset_ha_cnt = MAX_RESET_HA_RETRIES;
3069 DEBUG2(printk("scsi%ld: recover adapter - retrying "
3070 "(%d) more times\n", ha->host_no,
3071 ha->retry_reset_ha_cnt));
3072 set_bit(DPC_RETRY_RESET_HA, &ha->dpc_flags);
3075 if (ha->retry_reset_ha_cnt > 0) {
3076 /* Schedule another Reset HA--DPC will retry */
3077 ha->retry_reset_ha_cnt--;
3078 DEBUG2(printk("scsi%ld: recover adapter - "
3079 "retry remaining %d\n",
3081 ha->retry_reset_ha_cnt));
3085 if (ha->retry_reset_ha_cnt == 0) {
3086 /* Recover adapter retries have been exhausted.
3088 DEBUG2(printk("scsi%ld: recover adapter "
3089 "failed - board disabled\n",
3091 qla4xxx_dead_adapter_cleanup(ha);
3092 clear_bit(DPC_RETRY_RESET_HA, &ha->dpc_flags);
3093 clear_bit(DPC_RESET_HA, &ha->dpc_flags);
3094 clear_bit(DPC_RESET_HA_FW_CONTEXT,
3100 clear_bit(DPC_RESET_HA, &ha->dpc_flags);
3101 clear_bit(DPC_RESET_HA_FW_CONTEXT, &ha->dpc_flags);
3102 clear_bit(DPC_RETRY_RESET_HA, &ha->dpc_flags);
3106 ha->adapter_error_count++;
3108 if (test_bit(AF_ONLINE, &ha->flags))
3109 ha->isp_ops->enable_intrs(ha);
3111 scsi_unblock_requests(ha->host);
3113 clear_bit(DPC_RESET_ACTIVE, &ha->dpc_flags);
3114 DEBUG2(printk("scsi%ld: recover adapter: %s\n", ha->host_no,
3115 status == QLA_ERROR ? "FAILED" : "SUCCEEDED"));
3120 static void qla4xxx_relogin_devices(struct iscsi_cls_session *cls_session)
3122 struct iscsi_session *sess;
3123 struct ddb_entry *ddb_entry;
3124 struct scsi_qla_host *ha;
3126 sess = cls_session->dd_data;
3127 ddb_entry = sess->dd_data;
3129 if (!iscsi_is_session_online(cls_session)) {
3130 if (ddb_entry->fw_ddb_device_state == DDB_DS_SESSION_ACTIVE) {
3131 ql4_printk(KERN_INFO, ha, "scsi%ld: %s: ddb[%d]"
3132 " unblock session\n", ha->host_no, __func__,
3133 ddb_entry->fw_ddb_index);
3134 iscsi_unblock_session(ddb_entry->sess);
3136 /* Trigger relogin */
3137 if (ddb_entry->ddb_type == FLASH_DDB) {
3138 if (!test_bit(DF_RELOGIN, &ddb_entry->flags))
3139 qla4xxx_arm_relogin_timer(ddb_entry);
3141 iscsi_session_failure(cls_session->dd_data,
3142 ISCSI_ERR_CONN_FAILED);
3147 int qla4xxx_unblock_flash_ddb(struct iscsi_cls_session *cls_session)
3149 struct iscsi_session *sess;
3150 struct ddb_entry *ddb_entry;
3151 struct scsi_qla_host *ha;
3153 sess = cls_session->dd_data;
3154 ddb_entry = sess->dd_data;
3156 ql4_printk(KERN_INFO, ha, "scsi%ld: %s: ddb[%d]"
3157 " unblock session\n", ha->host_no, __func__,
3158 ddb_entry->fw_ddb_index);
3160 iscsi_unblock_session(ddb_entry->sess);
3162 /* Start scan target */
3163 if (test_bit(AF_ONLINE, &ha->flags)) {
3164 ql4_printk(KERN_INFO, ha, "scsi%ld: %s: ddb[%d]"
3165 " start scan\n", ha->host_no, __func__,
3166 ddb_entry->fw_ddb_index);
3167 scsi_queue_work(ha->host, &ddb_entry->sess->scan_work);
3172 int qla4xxx_unblock_ddb(struct iscsi_cls_session *cls_session)
3174 struct iscsi_session *sess;
3175 struct ddb_entry *ddb_entry;
3176 struct scsi_qla_host *ha;
3177 int status = QLA_SUCCESS;
3179 sess = cls_session->dd_data;
3180 ddb_entry = sess->dd_data;
3182 ql4_printk(KERN_INFO, ha, "scsi%ld: %s: ddb[%d]"
3183 " unblock user space session\n", ha->host_no, __func__,
3184 ddb_entry->fw_ddb_index);
3186 if (!iscsi_is_session_online(cls_session)) {
3187 iscsi_conn_start(ddb_entry->conn);
3188 iscsi_conn_login_event(ddb_entry->conn,
3189 ISCSI_CONN_STATE_LOGGED_IN);
3191 ql4_printk(KERN_INFO, ha,
3192 "scsi%ld: %s: ddb[%d] session [%d] already logged in\n",
3193 ha->host_no, __func__, ddb_entry->fw_ddb_index,
3201 static void qla4xxx_relogin_all_devices(struct scsi_qla_host *ha)
3203 iscsi_host_for_each_session(ha->host, qla4xxx_relogin_devices);
3206 static void qla4xxx_relogin_flash_ddb(struct iscsi_cls_session *cls_sess)
3208 uint16_t relogin_timer;
3209 struct iscsi_session *sess;
3210 struct ddb_entry *ddb_entry;
3211 struct scsi_qla_host *ha;
3213 sess = cls_sess->dd_data;
3214 ddb_entry = sess->dd_data;
3217 relogin_timer = max(ddb_entry->default_relogin_timeout,
3218 (uint16_t)RELOGIN_TOV);
3219 atomic_set(&ddb_entry->relogin_timer, relogin_timer);
3221 DEBUG2(ql4_printk(KERN_INFO, ha,
3222 "scsi%ld: Relogin index [%d]. TOV=%d\n", ha->host_no,
3223 ddb_entry->fw_ddb_index, relogin_timer));
3225 qla4xxx_login_flash_ddb(cls_sess);
3228 static void qla4xxx_dpc_relogin(struct iscsi_cls_session *cls_sess)
3230 struct iscsi_session *sess;
3231 struct ddb_entry *ddb_entry;
3232 struct scsi_qla_host *ha;
3234 sess = cls_sess->dd_data;
3235 ddb_entry = sess->dd_data;
3238 if (!(ddb_entry->ddb_type == FLASH_DDB))
3241 if (test_and_clear_bit(DF_RELOGIN, &ddb_entry->flags) &&
3242 !iscsi_is_session_online(cls_sess)) {
3243 DEBUG2(ql4_printk(KERN_INFO, ha,
3244 "relogin issued\n"));
3245 qla4xxx_relogin_flash_ddb(cls_sess);
3249 void qla4xxx_wake_dpc(struct scsi_qla_host *ha)
3252 queue_work(ha->dpc_thread, &ha->dpc_work);
3255 static struct qla4_work_evt *
3256 qla4xxx_alloc_work(struct scsi_qla_host *ha, uint32_t data_size,
3257 enum qla4_work_type type)
3259 struct qla4_work_evt *e;
3260 uint32_t size = sizeof(struct qla4_work_evt) + data_size;
3262 e = kzalloc(size, GFP_ATOMIC);
3266 INIT_LIST_HEAD(&e->list);
3271 static void qla4xxx_post_work(struct scsi_qla_host *ha,
3272 struct qla4_work_evt *e)
3274 unsigned long flags;
3276 spin_lock_irqsave(&ha->work_lock, flags);
3277 list_add_tail(&e->list, &ha->work_list);
3278 spin_unlock_irqrestore(&ha->work_lock, flags);
3279 qla4xxx_wake_dpc(ha);
3282 int qla4xxx_post_aen_work(struct scsi_qla_host *ha,
3283 enum iscsi_host_event_code aen_code,
3284 uint32_t data_size, uint8_t *data)
3286 struct qla4_work_evt *e;
3288 e = qla4xxx_alloc_work(ha, data_size, QLA4_EVENT_AEN);
3292 e->u.aen.code = aen_code;
3293 e->u.aen.data_size = data_size;
3294 memcpy(e->u.aen.data, data, data_size);
3296 qla4xxx_post_work(ha, e);
3301 int qla4xxx_post_ping_evt_work(struct scsi_qla_host *ha,
3302 uint32_t status, uint32_t pid,
3303 uint32_t data_size, uint8_t *data)
3305 struct qla4_work_evt *e;
3307 e = qla4xxx_alloc_work(ha, data_size, QLA4_EVENT_PING_STATUS);
3311 e->u.ping.status = status;
3312 e->u.ping.pid = pid;
3313 e->u.ping.data_size = data_size;
3314 memcpy(e->u.ping.data, data, data_size);
3316 qla4xxx_post_work(ha, e);
3321 static void qla4xxx_do_work(struct scsi_qla_host *ha)
3323 struct qla4_work_evt *e, *tmp;
3324 unsigned long flags;
3327 spin_lock_irqsave(&ha->work_lock, flags);
3328 list_splice_init(&ha->work_list, &work);
3329 spin_unlock_irqrestore(&ha->work_lock, flags);
3331 list_for_each_entry_safe(e, tmp, &work, list) {
3332 list_del_init(&e->list);
3335 case QLA4_EVENT_AEN:
3336 iscsi_post_host_event(ha->host_no,
3337 &qla4xxx_iscsi_transport,
3342 case QLA4_EVENT_PING_STATUS:
3343 iscsi_ping_comp_event(ha->host_no,
3344 &qla4xxx_iscsi_transport,
3347 e->u.ping.data_size,
3351 ql4_printk(KERN_WARNING, ha, "event type: 0x%x not "
3352 "supported", e->type);
3359 * qla4xxx_do_dpc - dpc routine
3360 * @data: in our case pointer to adapter structure
3362 * This routine is a task that is schedule by the interrupt handler
3363 * to perform the background processing for interrupts. We put it
3364 * on a task queue that is consumed whenever the scheduler runs; that's
3365 * so you can do anything (i.e. put the process to sleep etc). In fact,
3366 * the mid-level tries to sleep when it reaches the driver threshold
3367 * "host->can_queue". This can cause a panic if we were in our interrupt code.
3369 static void qla4xxx_do_dpc(struct work_struct *work)
3371 struct scsi_qla_host *ha =
3372 container_of(work, struct scsi_qla_host, dpc_work);
3373 int status = QLA_ERROR;
3375 DEBUG2(printk("scsi%ld: %s: DPC handler waking up."
3376 "flags = 0x%08lx, dpc_flags = 0x%08lx\n",
3377 ha->host_no, __func__, ha->flags, ha->dpc_flags))
3379 /* Initialization not yet finished. Don't do anything yet. */
3380 if (!test_bit(AF_INIT_DONE, &ha->flags))
3383 if (test_bit(AF_EEH_BUSY, &ha->flags)) {
3384 DEBUG2(printk(KERN_INFO "scsi%ld: %s: flags = %lx\n",
3385 ha->host_no, __func__, ha->flags));
3389 /* post events to application */
3390 qla4xxx_do_work(ha);
3392 if (is_qla80XX(ha)) {
3393 if (test_bit(DPC_HA_UNRECOVERABLE, &ha->dpc_flags)) {
3394 ha->isp_ops->idc_lock(ha);
3395 qla4_8xxx_wr_direct(ha, QLA8XXX_CRB_DEV_STATE,
3396 QLA8XXX_DEV_FAILED);
3397 ha->isp_ops->idc_unlock(ha);
3398 ql4_printk(KERN_INFO, ha, "HW State: FAILED\n");
3399 qla4_8xxx_device_state_handler(ha);
3401 if (test_and_clear_bit(DPC_HA_NEED_QUIESCENT, &ha->dpc_flags)) {
3402 qla4_8xxx_need_qsnt_handler(ha);
3406 if (!test_bit(DPC_RESET_ACTIVE, &ha->dpc_flags) &&
3407 (test_bit(DPC_RESET_HA, &ha->dpc_flags) ||
3408 test_bit(DPC_RESET_HA_INTR, &ha->dpc_flags) ||
3409 test_bit(DPC_RESET_HA_FW_CONTEXT, &ha->dpc_flags))) {
3410 if ((is_qla8022(ha) && ql4xdontresethba) ||
3411 (is_qla8032(ha) && qla4_83xx_idc_dontreset(ha))) {
3412 DEBUG2(printk("scsi%ld: %s: Don't Reset HBA\n",
3413 ha->host_no, __func__));
3414 clear_bit(DPC_RESET_HA, &ha->dpc_flags);
3415 clear_bit(DPC_RESET_HA_INTR, &ha->dpc_flags);
3416 clear_bit(DPC_RESET_HA_FW_CONTEXT, &ha->dpc_flags);
3417 goto dpc_post_reset_ha;
3419 if (test_bit(DPC_RESET_HA_FW_CONTEXT, &ha->dpc_flags) ||
3420 test_bit(DPC_RESET_HA, &ha->dpc_flags))
3421 qla4xxx_recover_adapter(ha);
3423 if (test_bit(DPC_RESET_HA_INTR, &ha->dpc_flags)) {
3424 uint8_t wait_time = RESET_INTR_TOV;
3426 while ((readw(&ha->reg->ctrl_status) &
3427 (CSR_SOFT_RESET | CSR_FORCE_SOFT_RESET)) != 0) {
3428 if (--wait_time == 0)
3433 DEBUG2(printk("scsi%ld: %s: SR|FSR "
3434 "bit not cleared-- resetting\n",
3435 ha->host_no, __func__));
3436 qla4xxx_abort_active_cmds(ha, DID_RESET << 16);
3437 if (ql4xxx_lock_drvr_wait(ha) == QLA_SUCCESS) {
3438 qla4xxx_process_aen(ha, FLUSH_DDB_CHANGED_AENS);
3439 status = qla4xxx_recover_adapter(ha);
3441 clear_bit(DPC_RESET_HA_INTR, &ha->dpc_flags);
3442 if (status == QLA_SUCCESS)
3443 ha->isp_ops->enable_intrs(ha);
3448 /* ---- process AEN? --- */
3449 if (test_and_clear_bit(DPC_AEN, &ha->dpc_flags))
3450 qla4xxx_process_aen(ha, PROCESS_ALL_AENS);
3452 /* ---- Get DHCP IP Address? --- */
3453 if (test_and_clear_bit(DPC_GET_DHCP_IP_ADDR, &ha->dpc_flags))
3454 qla4xxx_get_dhcp_ip_address(ha);
3456 /* ---- relogin device? --- */
3457 if (adapter_up(ha) &&
3458 test_and_clear_bit(DPC_RELOGIN_DEVICE, &ha->dpc_flags)) {
3459 iscsi_host_for_each_session(ha->host, qla4xxx_dpc_relogin);
3462 /* ---- link change? --- */
3463 if (test_and_clear_bit(DPC_LINK_CHANGED, &ha->dpc_flags)) {
3464 if (!test_bit(AF_LINK_UP, &ha->flags)) {
3465 /* ---- link down? --- */
3466 qla4xxx_mark_all_devices_missing(ha);
3468 /* ---- link up? --- *
3469 * F/W will auto login to all devices ONLY ONCE after
3470 * link up during driver initialization and runtime
3471 * fatal error recovery. Therefore, the driver must
3472 * manually relogin to devices when recovering from
3473 * connection failures, logouts, expired KATO, etc. */
3474 if (test_and_clear_bit(AF_BUILD_DDB_LIST, &ha->flags)) {
3475 qla4xxx_build_ddb_list(ha, ha->is_reset);
3476 iscsi_host_for_each_session(ha->host,
3477 qla4xxx_login_flash_ddb);
3479 qla4xxx_relogin_all_devices(ha);
3485 * qla4xxx_free_adapter - release the adapter
3486 * @ha: pointer to adapter structure
3488 static void qla4xxx_free_adapter(struct scsi_qla_host *ha)
3490 qla4xxx_abort_active_cmds(ha, DID_NO_CONNECT << 16);
3492 if (test_bit(AF_INTERRUPTS_ON, &ha->flags)) {
3493 /* Turn-off interrupts on the card. */
3494 ha->isp_ops->disable_intrs(ha);
3497 if (is_qla40XX(ha)) {
3498 writel(set_rmask(CSR_SCSI_PROCESSOR_INTR),
3499 &ha->reg->ctrl_status);
3500 readl(&ha->reg->ctrl_status);
3501 } else if (is_qla8022(ha)) {
3502 writel(0, &ha->qla4_82xx_reg->host_int);
3503 readl(&ha->qla4_82xx_reg->host_int);
3504 } else if (is_qla8032(ha)) {
3505 writel(0, &ha->qla4_83xx_reg->risc_intr);
3506 readl(&ha->qla4_83xx_reg->risc_intr);
3509 /* Remove timer thread, if present */
3510 if (ha->timer_active)
3511 qla4xxx_stop_timer(ha);
3513 /* Kill the kernel thread for this host */
3515 destroy_workqueue(ha->dpc_thread);
3517 /* Kill the kernel thread for this host */
3519 destroy_workqueue(ha->task_wq);
3521 /* Put firmware in known state */
3522 ha->isp_ops->reset_firmware(ha);
3524 if (is_qla80XX(ha)) {
3525 ha->isp_ops->idc_lock(ha);
3526 qla4_8xxx_clear_drv_active(ha);
3527 ha->isp_ops->idc_unlock(ha);
3530 /* Detach interrupts */
3531 if (test_and_clear_bit(AF_IRQ_ATTACHED, &ha->flags))
3532 qla4xxx_free_irqs(ha);
3534 /* free extra memory */
3535 qla4xxx_mem_free(ha);
3538 int qla4_8xxx_iospace_config(struct scsi_qla_host *ha)
3541 unsigned long mem_base, mem_len, db_base, db_len;
3542 struct pci_dev *pdev = ha->pdev;
3544 status = pci_request_regions(pdev, DRIVER_NAME);
3547 "scsi(%ld) Failed to reserve PIO regions (%s) "
3548 "status=%d\n", ha->host_no, pci_name(pdev), status);
3549 goto iospace_error_exit;
3552 DEBUG2(printk(KERN_INFO "%s: revision-id=%d\n",
3553 __func__, pdev->revision));
3554 ha->revision_id = pdev->revision;
3556 /* remap phys address */
3557 mem_base = pci_resource_start(pdev, 0); /* 0 is for BAR 0 */
3558 mem_len = pci_resource_len(pdev, 0);
3559 DEBUG2(printk(KERN_INFO "%s: ioremap from %lx a size of %lx\n",
3560 __func__, mem_base, mem_len));
3562 /* mapping of pcibase pointer */
3563 ha->nx_pcibase = (unsigned long)ioremap(mem_base, mem_len);
3564 if (!ha->nx_pcibase) {
3566 "cannot remap MMIO (%s), aborting\n", pci_name(pdev));
3567 pci_release_regions(ha->pdev);
3568 goto iospace_error_exit;
3571 /* Mapping of IO base pointer, door bell read and write pointer */
3573 /* mapping of IO base pointer */
3574 if (is_qla8022(ha)) {
3575 ha->qla4_82xx_reg = (struct device_reg_82xx __iomem *)
3576 ((uint8_t *)ha->nx_pcibase + 0xbc000 +
3577 (ha->pdev->devfn << 11));
3578 ha->nx_db_wr_ptr = (ha->pdev->devfn == 4 ? QLA82XX_CAM_RAM_DB1 :
3579 QLA82XX_CAM_RAM_DB2);
3580 } else if (is_qla8032(ha)) {
3581 ha->qla4_83xx_reg = (struct device_reg_83xx __iomem *)
3582 ((uint8_t *)ha->nx_pcibase);
3585 db_base = pci_resource_start(pdev, 4); /* doorbell is on bar 4 */
3586 db_len = pci_resource_len(pdev, 4);
3594 * qla4xxx_iospace_config - maps registers
3595 * @ha: pointer to adapter structure
3597 * This routines maps HBA's registers from the pci address space
3598 * into the kernel virtual address space for memory mapped i/o.
3600 int qla4xxx_iospace_config(struct scsi_qla_host *ha)
3602 unsigned long pio, pio_len, pio_flags;
3603 unsigned long mmio, mmio_len, mmio_flags;
3605 pio = pci_resource_start(ha->pdev, 0);
3606 pio_len = pci_resource_len(ha->pdev, 0);
3607 pio_flags = pci_resource_flags(ha->pdev, 0);
3608 if (pio_flags & IORESOURCE_IO) {
3609 if (pio_len < MIN_IOBASE_LEN) {
3610 ql4_printk(KERN_WARNING, ha,
3611 "Invalid PCI I/O region size\n");
3615 ql4_printk(KERN_WARNING, ha, "region #0 not a PIO resource\n");
3619 /* Use MMIO operations for all accesses. */
3620 mmio = pci_resource_start(ha->pdev, 1);
3621 mmio_len = pci_resource_len(ha->pdev, 1);
3622 mmio_flags = pci_resource_flags(ha->pdev, 1);
3624 if (!(mmio_flags & IORESOURCE_MEM)) {
3625 ql4_printk(KERN_ERR, ha,
3626 "region #0 not an MMIO resource, aborting\n");
3628 goto iospace_error_exit;
3631 if (mmio_len < MIN_IOBASE_LEN) {
3632 ql4_printk(KERN_ERR, ha,
3633 "Invalid PCI mem region size, aborting\n");
3634 goto iospace_error_exit;
3637 if (pci_request_regions(ha->pdev, DRIVER_NAME)) {
3638 ql4_printk(KERN_WARNING, ha,
3639 "Failed to reserve PIO/MMIO regions\n");
3641 goto iospace_error_exit;
3644 ha->pio_address = pio;
3645 ha->pio_length = pio_len;
3646 ha->reg = ioremap(mmio, MIN_IOBASE_LEN);
3648 ql4_printk(KERN_ERR, ha,
3649 "cannot remap MMIO, aborting\n");
3651 goto iospace_error_exit;
3660 static struct isp_operations qla4xxx_isp_ops = {
3661 .iospace_config = qla4xxx_iospace_config,
3662 .pci_config = qla4xxx_pci_config,
3663 .disable_intrs = qla4xxx_disable_intrs,
3664 .enable_intrs = qla4xxx_enable_intrs,
3665 .start_firmware = qla4xxx_start_firmware,
3666 .intr_handler = qla4xxx_intr_handler,
3667 .interrupt_service_routine = qla4xxx_interrupt_service_routine,
3668 .reset_chip = qla4xxx_soft_reset,
3669 .reset_firmware = qla4xxx_hw_reset,
3670 .queue_iocb = qla4xxx_queue_iocb,
3671 .complete_iocb = qla4xxx_complete_iocb,
3672 .rd_shdw_req_q_out = qla4xxx_rd_shdw_req_q_out,
3673 .rd_shdw_rsp_q_in = qla4xxx_rd_shdw_rsp_q_in,
3674 .get_sys_info = qla4xxx_get_sys_info,
3675 .queue_mailbox_command = qla4xxx_queue_mbox_cmd,
3676 .process_mailbox_interrupt = qla4xxx_process_mbox_intr,
3679 static struct isp_operations qla4_82xx_isp_ops = {
3680 .iospace_config = qla4_8xxx_iospace_config,
3681 .pci_config = qla4_8xxx_pci_config,
3682 .disable_intrs = qla4_82xx_disable_intrs,
3683 .enable_intrs = qla4_82xx_enable_intrs,
3684 .start_firmware = qla4_8xxx_load_risc,
3685 .restart_firmware = qla4_82xx_try_start_fw,
3686 .intr_handler = qla4_82xx_intr_handler,
3687 .interrupt_service_routine = qla4_82xx_interrupt_service_routine,
3688 .need_reset = qla4_8xxx_need_reset,
3689 .reset_chip = qla4_82xx_isp_reset,
3690 .reset_firmware = qla4_8xxx_stop_firmware,
3691 .queue_iocb = qla4_82xx_queue_iocb,
3692 .complete_iocb = qla4_82xx_complete_iocb,
3693 .rd_shdw_req_q_out = qla4_82xx_rd_shdw_req_q_out,
3694 .rd_shdw_rsp_q_in = qla4_82xx_rd_shdw_rsp_q_in,
3695 .get_sys_info = qla4_8xxx_get_sys_info,
3696 .rd_reg_direct = qla4_82xx_rd_32,
3697 .wr_reg_direct = qla4_82xx_wr_32,
3698 .rd_reg_indirect = qla4_82xx_md_rd_32,
3699 .wr_reg_indirect = qla4_82xx_md_wr_32,
3700 .idc_lock = qla4_82xx_idc_lock,
3701 .idc_unlock = qla4_82xx_idc_unlock,
3702 .rom_lock_recovery = qla4_82xx_rom_lock_recovery,
3703 .queue_mailbox_command = qla4_82xx_queue_mbox_cmd,
3704 .process_mailbox_interrupt = qla4_82xx_process_mbox_intr,
3707 static struct isp_operations qla4_83xx_isp_ops = {
3708 .iospace_config = qla4_8xxx_iospace_config,
3709 .pci_config = qla4_8xxx_pci_config,
3710 .disable_intrs = qla4_83xx_disable_intrs,
3711 .enable_intrs = qla4_83xx_enable_intrs,
3712 .start_firmware = qla4_8xxx_load_risc,
3713 .restart_firmware = qla4_83xx_start_firmware,
3714 .intr_handler = qla4_83xx_intr_handler,
3715 .interrupt_service_routine = qla4_83xx_interrupt_service_routine,
3716 .need_reset = qla4_8xxx_need_reset,
3717 .reset_chip = qla4_83xx_isp_reset,
3718 .reset_firmware = qla4_8xxx_stop_firmware,
3719 .queue_iocb = qla4_83xx_queue_iocb,
3720 .complete_iocb = qla4_83xx_complete_iocb,
3721 .rd_shdw_req_q_out = qla4_83xx_rd_shdw_req_q_out,
3722 .rd_shdw_rsp_q_in = qla4_83xx_rd_shdw_rsp_q_in,
3723 .get_sys_info = qla4_8xxx_get_sys_info,
3724 .rd_reg_direct = qla4_83xx_rd_reg,
3725 .wr_reg_direct = qla4_83xx_wr_reg,
3726 .rd_reg_indirect = qla4_83xx_rd_reg_indirect,
3727 .wr_reg_indirect = qla4_83xx_wr_reg_indirect,
3728 .idc_lock = qla4_83xx_drv_lock,
3729 .idc_unlock = qla4_83xx_drv_unlock,
3730 .rom_lock_recovery = qla4_83xx_rom_lock_recovery,
3731 .queue_mailbox_command = qla4_83xx_queue_mbox_cmd,
3732 .process_mailbox_interrupt = qla4_83xx_process_mbox_intr,
3735 uint16_t qla4xxx_rd_shdw_req_q_out(struct scsi_qla_host *ha)
3737 return (uint16_t)le32_to_cpu(ha->shadow_regs->req_q_out);
3740 uint16_t qla4_82xx_rd_shdw_req_q_out(struct scsi_qla_host *ha)
3742 return (uint16_t)le32_to_cpu(readl(&ha->qla4_82xx_reg->req_q_out));
3745 uint16_t qla4_83xx_rd_shdw_req_q_out(struct scsi_qla_host *ha)
3747 return (uint16_t)le32_to_cpu(readl(&ha->qla4_83xx_reg->req_q_out));
3750 uint16_t qla4xxx_rd_shdw_rsp_q_in(struct scsi_qla_host *ha)
3752 return (uint16_t)le32_to_cpu(ha->shadow_regs->rsp_q_in);
3755 uint16_t qla4_82xx_rd_shdw_rsp_q_in(struct scsi_qla_host *ha)
3757 return (uint16_t)le32_to_cpu(readl(&ha->qla4_82xx_reg->rsp_q_in));
3760 uint16_t qla4_83xx_rd_shdw_rsp_q_in(struct scsi_qla_host *ha)
3762 return (uint16_t)le32_to_cpu(readl(&ha->qla4_83xx_reg->rsp_q_in));
3765 static ssize_t qla4xxx_show_boot_eth_info(void *data, int type, char *buf)
3767 struct scsi_qla_host *ha = data;
3772 case ISCSI_BOOT_ETH_FLAGS:
3773 rc = sprintf(str, "%d\n", SYSFS_FLAG_FW_SEL_BOOT);
3775 case ISCSI_BOOT_ETH_INDEX:
3776 rc = sprintf(str, "0\n");
3778 case ISCSI_BOOT_ETH_MAC:
3779 rc = sysfs_format_mac(str, ha->my_mac,
3789 static umode_t qla4xxx_eth_get_attr_visibility(void *data, int type)
3794 case ISCSI_BOOT_ETH_FLAGS:
3795 case ISCSI_BOOT_ETH_MAC:
3796 case ISCSI_BOOT_ETH_INDEX:
3806 static ssize_t qla4xxx_show_boot_ini_info(void *data, int type, char *buf)
3808 struct scsi_qla_host *ha = data;
3813 case ISCSI_BOOT_INI_INITIATOR_NAME:
3814 rc = sprintf(str, "%s\n", ha->name_string);
3823 static umode_t qla4xxx_ini_get_attr_visibility(void *data, int type)
3828 case ISCSI_BOOT_INI_INITIATOR_NAME:
3839 qla4xxx_show_boot_tgt_info(struct ql4_boot_session_info *boot_sess, int type,
3842 struct ql4_conn_info *boot_conn = &boot_sess->conn_list[0];
3847 case ISCSI_BOOT_TGT_NAME:
3848 rc = sprintf(buf, "%s\n", (char *)&boot_sess->target_name);
3850 case ISCSI_BOOT_TGT_IP_ADDR:
3851 if (boot_sess->conn_list[0].dest_ipaddr.ip_type == 0x1)
3852 rc = sprintf(buf, "%pI4\n",
3853 &boot_conn->dest_ipaddr.ip_address);
3855 rc = sprintf(str, "%pI6\n",
3856 &boot_conn->dest_ipaddr.ip_address);
3858 case ISCSI_BOOT_TGT_PORT:
3859 rc = sprintf(str, "%d\n", boot_conn->dest_port);
3861 case ISCSI_BOOT_TGT_CHAP_NAME:
3862 rc = sprintf(str, "%.*s\n",
3863 boot_conn->chap.target_chap_name_length,
3864 (char *)&boot_conn->chap.target_chap_name);
3866 case ISCSI_BOOT_TGT_CHAP_SECRET:
3867 rc = sprintf(str, "%.*s\n",
3868 boot_conn->chap.target_secret_length,
3869 (char *)&boot_conn->chap.target_secret);
3871 case ISCSI_BOOT_TGT_REV_CHAP_NAME:
3872 rc = sprintf(str, "%.*s\n",
3873 boot_conn->chap.intr_chap_name_length,
3874 (char *)&boot_conn->chap.intr_chap_name);
3876 case ISCSI_BOOT_TGT_REV_CHAP_SECRET:
3877 rc = sprintf(str, "%.*s\n",
3878 boot_conn->chap.intr_secret_length,
3879 (char *)&boot_conn->chap.intr_secret);
3881 case ISCSI_BOOT_TGT_FLAGS:
3882 rc = sprintf(str, "%d\n", SYSFS_FLAG_FW_SEL_BOOT);
3884 case ISCSI_BOOT_TGT_NIC_ASSOC:
3885 rc = sprintf(str, "0\n");
3894 static ssize_t qla4xxx_show_boot_tgt_pri_info(void *data, int type, char *buf)
3896 struct scsi_qla_host *ha = data;
3897 struct ql4_boot_session_info *boot_sess = &(ha->boot_tgt.boot_pri_sess);
3899 return qla4xxx_show_boot_tgt_info(boot_sess, type, buf);
3902 static ssize_t qla4xxx_show_boot_tgt_sec_info(void *data, int type, char *buf)
3904 struct scsi_qla_host *ha = data;
3905 struct ql4_boot_session_info *boot_sess = &(ha->boot_tgt.boot_sec_sess);
3907 return qla4xxx_show_boot_tgt_info(boot_sess, type, buf);
3910 static umode_t qla4xxx_tgt_get_attr_visibility(void *data, int type)
3915 case ISCSI_BOOT_TGT_NAME:
3916 case ISCSI_BOOT_TGT_IP_ADDR:
3917 case ISCSI_BOOT_TGT_PORT:
3918 case ISCSI_BOOT_TGT_CHAP_NAME:
3919 case ISCSI_BOOT_TGT_CHAP_SECRET:
3920 case ISCSI_BOOT_TGT_REV_CHAP_NAME:
3921 case ISCSI_BOOT_TGT_REV_CHAP_SECRET:
3922 case ISCSI_BOOT_TGT_NIC_ASSOC:
3923 case ISCSI_BOOT_TGT_FLAGS:
3933 static void qla4xxx_boot_release(void *data)
3935 struct scsi_qla_host *ha = data;
3937 scsi_host_put(ha->host);
3940 static int get_fw_boot_info(struct scsi_qla_host *ha, uint16_t ddb_index[])
3943 uint32_t addr, pri_addr, sec_addr;
3947 uint8_t *buf = NULL;
3948 size_t size = 13 * sizeof(uint8_t);
3949 int ret = QLA_SUCCESS;
3951 func_num = PCI_FUNC(ha->pdev->devfn);
3953 ql4_printk(KERN_INFO, ha, "%s: Get FW boot info for 0x%x func %d\n",
3954 __func__, ha->pdev->device, func_num);
3956 if (is_qla40XX(ha)) {
3957 if (func_num == 1) {
3958 addr = NVRAM_PORT0_BOOT_MODE;
3959 pri_addr = NVRAM_PORT0_BOOT_PRI_TGT;
3960 sec_addr = NVRAM_PORT0_BOOT_SEC_TGT;
3961 } else if (func_num == 3) {
3962 addr = NVRAM_PORT1_BOOT_MODE;
3963 pri_addr = NVRAM_PORT1_BOOT_PRI_TGT;
3964 sec_addr = NVRAM_PORT1_BOOT_SEC_TGT;
3967 goto exit_boot_info;
3970 /* Check Boot Mode */
3971 val = rd_nvram_byte(ha, addr);
3972 if (!(val & 0x07)) {
3973 DEBUG2(ql4_printk(KERN_INFO, ha, "%s: Adapter boot "
3974 "options : 0x%x\n", __func__, val));
3976 goto exit_boot_info;
3979 /* get primary valid target index */
3980 val = rd_nvram_byte(ha, pri_addr);
3982 ddb_index[0] = (val & 0x7f);
3984 /* get secondary valid target index */
3985 val = rd_nvram_byte(ha, sec_addr);
3987 ddb_index[1] = (val & 0x7f);
3989 } else if (is_qla8022(ha)) {
3990 buf = dma_alloc_coherent(&ha->pdev->dev, size,
3991 &buf_dma, GFP_KERNEL);
3993 DEBUG2(ql4_printk(KERN_ERR, ha,
3994 "%s: Unable to allocate dma buffer\n",
3997 goto exit_boot_info;
4000 if (ha->port_num == 0)
4001 offset = BOOT_PARAM_OFFSET_PORT0;
4002 else if (ha->port_num == 1)
4003 offset = BOOT_PARAM_OFFSET_PORT1;
4006 goto exit_boot_info_free;
4008 addr = FLASH_RAW_ACCESS_ADDR + (ha->hw.flt_iscsi_param * 4) +
4010 if (qla4xxx_get_flash(ha, buf_dma, addr,
4011 13 * sizeof(uint8_t)) != QLA_SUCCESS) {
4012 DEBUG2(ql4_printk(KERN_ERR, ha, "scsi%ld: %s: Get Flash"
4013 " failed\n", ha->host_no, __func__));
4015 goto exit_boot_info_free;
4017 /* Check Boot Mode */
4018 if (!(buf[1] & 0x07)) {
4019 DEBUG2(ql4_printk(KERN_INFO, ha, "Firmware boot options"
4020 " : 0x%x\n", buf[1]));
4022 goto exit_boot_info_free;
4025 /* get primary valid target index */
4027 ddb_index[0] = buf[2] & 0x7f;
4029 /* get secondary valid target index */
4030 if (buf[11] & BIT_7)
4031 ddb_index[1] = buf[11] & 0x7f;
4034 goto exit_boot_info;
4037 DEBUG2(ql4_printk(KERN_INFO, ha, "%s: Primary target ID %d, Secondary"
4038 " target ID %d\n", __func__, ddb_index[0],
4041 exit_boot_info_free:
4042 dma_free_coherent(&ha->pdev->dev, size, buf, buf_dma);
4044 ha->pri_ddb_idx = ddb_index[0];
4045 ha->sec_ddb_idx = ddb_index[1];
4050 * qla4xxx_get_bidi_chap - Get a BIDI CHAP user and password
4051 * @ha: pointer to adapter structure
4052 * @username: CHAP username to be returned
4053 * @password: CHAP password to be returned
4055 * If a boot entry has BIDI CHAP enabled then we need to set the BIDI CHAP
4056 * user and password in the sysfs entry in /sys/firmware/iscsi_boot#/.
4057 * So from the CHAP cache find the first BIDI CHAP entry and set it
4058 * to the boot record in sysfs.
4060 static int qla4xxx_get_bidi_chap(struct scsi_qla_host *ha, char *username,
4063 int i, ret = -EINVAL;
4064 int max_chap_entries = 0;
4065 struct ql4_chap_table *chap_table;
4068 max_chap_entries = (ha->hw.flt_chap_size / 2) /
4069 sizeof(struct ql4_chap_table);
4071 max_chap_entries = MAX_CHAP_ENTRIES_40XX;
4073 if (!ha->chap_list) {
4074 ql4_printk(KERN_ERR, ha, "Do not have CHAP table cache\n");
4078 mutex_lock(&ha->chap_sem);
4079 for (i = 0; i < max_chap_entries; i++) {
4080 chap_table = (struct ql4_chap_table *)ha->chap_list + i;
4081 if (chap_table->cookie !=
4082 __constant_cpu_to_le16(CHAP_VALID_COOKIE)) {
4086 if (chap_table->flags & BIT_7) /* local */
4089 if (!(chap_table->flags & BIT_6)) /* Not BIDI */
4092 strncpy(password, chap_table->secret, QL4_CHAP_MAX_SECRET_LEN);
4093 strncpy(username, chap_table->name, QL4_CHAP_MAX_NAME_LEN);
4097 mutex_unlock(&ha->chap_sem);
4103 static int qla4xxx_get_boot_target(struct scsi_qla_host *ha,
4104 struct ql4_boot_session_info *boot_sess,
4107 struct ql4_conn_info *boot_conn = &boot_sess->conn_list[0];
4108 struct dev_db_entry *fw_ddb_entry;
4109 dma_addr_t fw_ddb_entry_dma;
4112 int ret = QLA_SUCCESS;
4114 fw_ddb_entry = dma_alloc_coherent(&ha->pdev->dev, sizeof(*fw_ddb_entry),
4115 &fw_ddb_entry_dma, GFP_KERNEL);
4116 if (!fw_ddb_entry) {
4117 DEBUG2(ql4_printk(KERN_ERR, ha,
4118 "%s: Unable to allocate dma buffer.\n",
4124 if (qla4xxx_bootdb_by_index(ha, fw_ddb_entry,
4125 fw_ddb_entry_dma, ddb_index)) {
4126 DEBUG2(ql4_printk(KERN_INFO, ha, "%s: No Flash DDB found at "
4127 "index [%d]\n", __func__, ddb_index));
4129 goto exit_boot_target;
4132 /* Update target name and IP from DDB */
4133 memcpy(boot_sess->target_name, fw_ddb_entry->iscsi_name,
4134 min(sizeof(boot_sess->target_name),
4135 sizeof(fw_ddb_entry->iscsi_name)));
4137 options = le16_to_cpu(fw_ddb_entry->options);
4138 if (options & DDB_OPT_IPV6_DEVICE) {
4139 memcpy(&boot_conn->dest_ipaddr.ip_address,
4140 &fw_ddb_entry->ip_addr[0], IPv6_ADDR_LEN);
4142 boot_conn->dest_ipaddr.ip_type = 0x1;
4143 memcpy(&boot_conn->dest_ipaddr.ip_address,
4144 &fw_ddb_entry->ip_addr[0], IP_ADDR_LEN);
4147 boot_conn->dest_port = le16_to_cpu(fw_ddb_entry->port);
4149 /* update chap information */
4150 idx = __le16_to_cpu(fw_ddb_entry->chap_tbl_idx);
4152 if (BIT_7 & le16_to_cpu(fw_ddb_entry->iscsi_options)) {
4154 DEBUG2(ql4_printk(KERN_INFO, ha, "Setting chap\n"));
4156 ret = qla4xxx_get_chap(ha, (char *)&boot_conn->chap.
4158 (char *)&boot_conn->chap.target_secret,
4161 ql4_printk(KERN_ERR, ha, "Failed to set chap\n");
4163 goto exit_boot_target;
4166 boot_conn->chap.target_chap_name_length = QL4_CHAP_MAX_NAME_LEN;
4167 boot_conn->chap.target_secret_length = QL4_CHAP_MAX_SECRET_LEN;
4170 if (BIT_4 & le16_to_cpu(fw_ddb_entry->iscsi_options)) {
4172 DEBUG2(ql4_printk(KERN_INFO, ha, "Setting BIDI chap\n"));
4174 ret = qla4xxx_get_bidi_chap(ha,
4175 (char *)&boot_conn->chap.intr_chap_name,
4176 (char *)&boot_conn->chap.intr_secret);
4179 ql4_printk(KERN_ERR, ha, "Failed to set BIDI chap\n");
4181 goto exit_boot_target;
4184 boot_conn->chap.intr_chap_name_length = QL4_CHAP_MAX_NAME_LEN;
4185 boot_conn->chap.intr_secret_length = QL4_CHAP_MAX_SECRET_LEN;
4189 dma_free_coherent(&ha->pdev->dev, sizeof(*fw_ddb_entry),
4190 fw_ddb_entry, fw_ddb_entry_dma);
4194 static int qla4xxx_get_boot_info(struct scsi_qla_host *ha)
4196 uint16_t ddb_index[2];
4197 int ret = QLA_ERROR;
4200 memset(ddb_index, 0, sizeof(ddb_index));
4201 ddb_index[0] = 0xffff;
4202 ddb_index[1] = 0xffff;
4203 ret = get_fw_boot_info(ha, ddb_index);
4204 if (ret != QLA_SUCCESS) {
4205 DEBUG2(ql4_printk(KERN_INFO, ha,
4206 "%s: No boot target configured.\n", __func__));
4210 if (ql4xdisablesysfsboot)
4213 if (ddb_index[0] == 0xffff)
4216 rval = qla4xxx_get_boot_target(ha, &(ha->boot_tgt.boot_pri_sess),
4218 if (rval != QLA_SUCCESS) {
4219 DEBUG2(ql4_printk(KERN_INFO, ha, "%s: Primary boot target not "
4220 "configured\n", __func__));
4225 if (ddb_index[1] == 0xffff)
4226 goto exit_get_boot_info;
4228 rval = qla4xxx_get_boot_target(ha, &(ha->boot_tgt.boot_sec_sess),
4230 if (rval != QLA_SUCCESS) {
4231 DEBUG2(ql4_printk(KERN_INFO, ha, "%s: Secondary boot target not"
4232 " configured\n", __func__));
4240 static int qla4xxx_setup_boot_info(struct scsi_qla_host *ha)
4242 struct iscsi_boot_kobj *boot_kobj;
4244 if (qla4xxx_get_boot_info(ha) != QLA_SUCCESS)
4247 if (ql4xdisablesysfsboot) {
4248 ql4_printk(KERN_INFO, ha,
4249 "%s: syfsboot disabled - driver will trigger login "
4250 "and publish session for discovery .\n", __func__);
4255 ha->boot_kset = iscsi_boot_create_host_kset(ha->host->host_no);
4259 if (!scsi_host_get(ha->host))
4261 boot_kobj = iscsi_boot_create_target(ha->boot_kset, 0, ha,
4262 qla4xxx_show_boot_tgt_pri_info,
4263 qla4xxx_tgt_get_attr_visibility,
4264 qla4xxx_boot_release);
4268 if (!scsi_host_get(ha->host))
4270 boot_kobj = iscsi_boot_create_target(ha->boot_kset, 1, ha,
4271 qla4xxx_show_boot_tgt_sec_info,
4272 qla4xxx_tgt_get_attr_visibility,
4273 qla4xxx_boot_release);
4277 if (!scsi_host_get(ha->host))
4279 boot_kobj = iscsi_boot_create_initiator(ha->boot_kset, 0, ha,
4280 qla4xxx_show_boot_ini_info,
4281 qla4xxx_ini_get_attr_visibility,
4282 qla4xxx_boot_release);
4286 if (!scsi_host_get(ha->host))
4288 boot_kobj = iscsi_boot_create_ethernet(ha->boot_kset, 0, ha,
4289 qla4xxx_show_boot_eth_info,
4290 qla4xxx_eth_get_attr_visibility,
4291 qla4xxx_boot_release);
4298 scsi_host_put(ha->host);
4300 iscsi_boot_destroy_kset(ha->boot_kset);
4306 * qla4xxx_create chap_list - Create CHAP list from FLASH
4307 * @ha: pointer to adapter structure
4309 * Read flash and make a list of CHAP entries, during login when a CHAP entry
4310 * is received, it will be checked in this list. If entry exist then the CHAP
4311 * entry index is set in the DDB. If CHAP entry does not exist in this list
4312 * then a new entry is added in FLASH in CHAP table and the index obtained is
4315 static void qla4xxx_create_chap_list(struct scsi_qla_host *ha)
4318 uint8_t *chap_flash_data = NULL;
4320 dma_addr_t chap_dma;
4321 uint32_t chap_size = 0;
4324 chap_size = MAX_CHAP_ENTRIES_40XX *
4325 sizeof(struct ql4_chap_table);
4326 else /* Single region contains CHAP info for both
4327 * ports which is divided into half for each port.
4329 chap_size = ha->hw.flt_chap_size / 2;
4331 chap_flash_data = dma_alloc_coherent(&ha->pdev->dev, chap_size,
4332 &chap_dma, GFP_KERNEL);
4333 if (!chap_flash_data) {
4334 ql4_printk(KERN_ERR, ha, "No memory for chap_flash_data\n");
4338 offset = FLASH_CHAP_OFFSET;
4340 offset = FLASH_RAW_ACCESS_ADDR + (ha->hw.flt_region_chap << 2);
4341 if (ha->port_num == 1)
4342 offset += chap_size;
4345 rval = qla4xxx_get_flash(ha, chap_dma, offset, chap_size);
4346 if (rval != QLA_SUCCESS)
4347 goto exit_chap_list;
4349 if (ha->chap_list == NULL)
4350 ha->chap_list = vmalloc(chap_size);
4351 if (ha->chap_list == NULL) {
4352 ql4_printk(KERN_ERR, ha, "No memory for ha->chap_list\n");
4353 goto exit_chap_list;
4356 memcpy(ha->chap_list, chap_flash_data, chap_size);
4359 dma_free_coherent(&ha->pdev->dev, chap_size,
4360 chap_flash_data, chap_dma);
4363 static void qla4xxx_get_param_ddb(struct ddb_entry *ddb_entry,
4364 struct ql4_tuple_ddb *tddb)
4366 struct scsi_qla_host *ha;
4367 struct iscsi_cls_session *cls_sess;
4368 struct iscsi_cls_conn *cls_conn;
4369 struct iscsi_session *sess;
4370 struct iscsi_conn *conn;
4372 DEBUG2(printk(KERN_INFO "Func: %s\n", __func__));
4374 cls_sess = ddb_entry->sess;
4375 sess = cls_sess->dd_data;
4376 cls_conn = ddb_entry->conn;
4377 conn = cls_conn->dd_data;
4379 tddb->tpgt = sess->tpgt;
4380 tddb->port = conn->persistent_port;
4381 strncpy(tddb->iscsi_name, sess->targetname, ISCSI_NAME_SIZE);
4382 strncpy(tddb->ip_addr, conn->persistent_address, DDB_IPADDR_LEN);
4385 static void qla4xxx_convert_param_ddb(struct dev_db_entry *fw_ddb_entry,
4386 struct ql4_tuple_ddb *tddb,
4387 uint8_t *flash_isid)
4389 uint16_t options = 0;
4391 tddb->tpgt = le32_to_cpu(fw_ddb_entry->tgt_portal_grp);
4392 memcpy(&tddb->iscsi_name[0], &fw_ddb_entry->iscsi_name[0],
4393 min(sizeof(tddb->iscsi_name), sizeof(fw_ddb_entry->iscsi_name)));
4395 options = le16_to_cpu(fw_ddb_entry->options);
4396 if (options & DDB_OPT_IPV6_DEVICE)
4397 sprintf(tddb->ip_addr, "%pI6", fw_ddb_entry->ip_addr);
4399 sprintf(tddb->ip_addr, "%pI4", fw_ddb_entry->ip_addr);
4401 tddb->port = le16_to_cpu(fw_ddb_entry->port);
4403 if (flash_isid == NULL)
4404 memcpy(&tddb->isid[0], &fw_ddb_entry->isid[0],
4405 sizeof(tddb->isid));
4407 memcpy(&tddb->isid[0], &flash_isid[0], sizeof(tddb->isid));
4410 static int qla4xxx_compare_tuple_ddb(struct scsi_qla_host *ha,
4411 struct ql4_tuple_ddb *old_tddb,
4412 struct ql4_tuple_ddb *new_tddb,
4413 uint8_t is_isid_compare)
4415 if (strcmp(old_tddb->iscsi_name, new_tddb->iscsi_name))
4418 if (strcmp(old_tddb->ip_addr, new_tddb->ip_addr))
4421 if (old_tddb->port != new_tddb->port)
4424 /* For multi sessions, driver generates the ISID, so do not compare
4425 * ISID in reset path since it would be a comparision between the
4426 * driver generated ISID and firmware generated ISID. This could
4427 * lead to adding duplicated DDBs in the list as driver generated
4428 * ISID would not match firmware generated ISID.
4430 if (is_isid_compare) {
4431 DEBUG2(ql4_printk(KERN_INFO, ha, "%s: old ISID [%02x%02x%02x"
4432 "%02x%02x%02x] New ISID [%02x%02x%02x%02x%02x%02x]\n",
4433 __func__, old_tddb->isid[5], old_tddb->isid[4],
4434 old_tddb->isid[3], old_tddb->isid[2], old_tddb->isid[1],
4435 old_tddb->isid[0], new_tddb->isid[5], new_tddb->isid[4],
4436 new_tddb->isid[3], new_tddb->isid[2], new_tddb->isid[1],
4437 new_tddb->isid[0]));
4439 if (memcmp(&old_tddb->isid[0], &new_tddb->isid[0],
4440 sizeof(old_tddb->isid)))
4444 DEBUG2(ql4_printk(KERN_INFO, ha,
4445 "Match Found, fw[%d,%d,%s,%s], [%d,%d,%s,%s]",
4446 old_tddb->port, old_tddb->tpgt, old_tddb->ip_addr,
4447 old_tddb->iscsi_name, new_tddb->port, new_tddb->tpgt,
4448 new_tddb->ip_addr, new_tddb->iscsi_name));
4453 static int qla4xxx_is_session_exists(struct scsi_qla_host *ha,
4454 struct dev_db_entry *fw_ddb_entry)
4456 struct ddb_entry *ddb_entry;
4457 struct ql4_tuple_ddb *fw_tddb = NULL;
4458 struct ql4_tuple_ddb *tmp_tddb = NULL;
4460 int ret = QLA_ERROR;
4462 fw_tddb = vzalloc(sizeof(*fw_tddb));
4464 DEBUG2(ql4_printk(KERN_WARNING, ha,
4465 "Memory Allocation failed.\n"));
4470 tmp_tddb = vzalloc(sizeof(*tmp_tddb));
4472 DEBUG2(ql4_printk(KERN_WARNING, ha,
4473 "Memory Allocation failed.\n"));
4478 qla4xxx_convert_param_ddb(fw_ddb_entry, fw_tddb, NULL);
4480 for (idx = 0; idx < MAX_DDB_ENTRIES; idx++) {
4481 ddb_entry = qla4xxx_lookup_ddb_by_fw_index(ha, idx);
4482 if (ddb_entry == NULL)
4485 qla4xxx_get_param_ddb(ddb_entry, tmp_tddb);
4486 if (!qla4xxx_compare_tuple_ddb(ha, fw_tddb, tmp_tddb, false)) {
4487 ret = QLA_SUCCESS; /* found */
4501 * qla4xxx_check_existing_isid - check if target with same isid exist
4503 * @list_nt: list of target
4504 * @isid: isid to check
4506 * This routine return QLA_SUCCESS if target with same isid exist
4508 static int qla4xxx_check_existing_isid(struct list_head *list_nt, uint8_t *isid)
4510 struct qla_ddb_index *nt_ddb_idx, *nt_ddb_idx_tmp;
4511 struct dev_db_entry *fw_ddb_entry;
4513 list_for_each_entry_safe(nt_ddb_idx, nt_ddb_idx_tmp, list_nt, list) {
4514 fw_ddb_entry = &nt_ddb_idx->fw_ddb;
4516 if (memcmp(&fw_ddb_entry->isid[0], &isid[0],
4517 sizeof(nt_ddb_idx->fw_ddb.isid)) == 0) {
4525 * qla4xxx_update_isid - compare ddbs and updated isid
4526 * @ha: Pointer to host adapter structure.
4527 * @list_nt: list of nt target
4528 * @fw_ddb_entry: firmware ddb entry
4530 * This routine update isid if ddbs have same iqn, same isid and
4531 * different IP addr.
4532 * Return QLA_SUCCESS if isid is updated.
4534 static int qla4xxx_update_isid(struct scsi_qla_host *ha,
4535 struct list_head *list_nt,
4536 struct dev_db_entry *fw_ddb_entry)
4538 uint8_t base_value, i;
4540 base_value = fw_ddb_entry->isid[1] & 0x1f;
4541 for (i = 0; i < 8; i++) {
4542 fw_ddb_entry->isid[1] = (base_value | (i << 5));
4543 if (qla4xxx_check_existing_isid(list_nt, fw_ddb_entry->isid))
4547 if (!qla4xxx_check_existing_isid(list_nt, fw_ddb_entry->isid))
4554 * qla4xxx_should_update_isid - check if isid need to update
4555 * @ha: Pointer to host adapter structure.
4556 * @old_tddb: ddb tuple
4557 * @new_tddb: ddb tuple
4559 * Return QLA_SUCCESS if different IP, different PORT, same iqn,
4562 static int qla4xxx_should_update_isid(struct scsi_qla_host *ha,
4563 struct ql4_tuple_ddb *old_tddb,
4564 struct ql4_tuple_ddb *new_tddb)
4566 if (strcmp(old_tddb->ip_addr, new_tddb->ip_addr) == 0) {
4568 if (old_tddb->port == new_tddb->port)
4572 if (strcmp(old_tddb->iscsi_name, new_tddb->iscsi_name))
4576 if (memcmp(&old_tddb->isid[0], &new_tddb->isid[0],
4577 sizeof(old_tddb->isid)))
4578 /* different isid */
4585 * qla4xxx_is_flash_ddb_exists - check if fw_ddb_entry already exists in list_nt
4586 * @ha: Pointer to host adapter structure.
4587 * @list_nt: list of nt target.
4588 * @fw_ddb_entry: firmware ddb entry.
4590 * This routine check if fw_ddb_entry already exists in list_nt to avoid
4591 * duplicate ddb in list_nt.
4592 * Return QLA_SUCCESS if duplicate ddb exit in list_nl.
4593 * Note: This function also update isid of DDB if required.
4596 static int qla4xxx_is_flash_ddb_exists(struct scsi_qla_host *ha,
4597 struct list_head *list_nt,
4598 struct dev_db_entry *fw_ddb_entry)
4600 struct qla_ddb_index *nt_ddb_idx, *nt_ddb_idx_tmp;
4601 struct ql4_tuple_ddb *fw_tddb = NULL;
4602 struct ql4_tuple_ddb *tmp_tddb = NULL;
4603 int rval, ret = QLA_ERROR;
4605 fw_tddb = vzalloc(sizeof(*fw_tddb));
4607 DEBUG2(ql4_printk(KERN_WARNING, ha,
4608 "Memory Allocation failed.\n"));
4613 tmp_tddb = vzalloc(sizeof(*tmp_tddb));
4615 DEBUG2(ql4_printk(KERN_WARNING, ha,
4616 "Memory Allocation failed.\n"));
4621 qla4xxx_convert_param_ddb(fw_ddb_entry, fw_tddb, NULL);
4623 list_for_each_entry_safe(nt_ddb_idx, nt_ddb_idx_tmp, list_nt, list) {
4624 qla4xxx_convert_param_ddb(&nt_ddb_idx->fw_ddb, tmp_tddb,
4625 nt_ddb_idx->flash_isid);
4626 ret = qla4xxx_compare_tuple_ddb(ha, fw_tddb, tmp_tddb, true);
4627 /* found duplicate ddb */
4628 if (ret == QLA_SUCCESS)
4632 list_for_each_entry_safe(nt_ddb_idx, nt_ddb_idx_tmp, list_nt, list) {
4633 qla4xxx_convert_param_ddb(&nt_ddb_idx->fw_ddb, tmp_tddb, NULL);
4635 ret = qla4xxx_should_update_isid(ha, tmp_tddb, fw_tddb);
4636 if (ret == QLA_SUCCESS) {
4637 rval = qla4xxx_update_isid(ha, list_nt, fw_ddb_entry);
4638 if (rval == QLA_SUCCESS)
4655 static void qla4xxx_free_ddb_list(struct list_head *list_ddb)
4657 struct qla_ddb_index *ddb_idx, *ddb_idx_tmp;
4659 list_for_each_entry_safe(ddb_idx, ddb_idx_tmp, list_ddb, list) {
4660 list_del_init(&ddb_idx->list);
4665 static struct iscsi_endpoint *qla4xxx_get_ep_fwdb(struct scsi_qla_host *ha,
4666 struct dev_db_entry *fw_ddb_entry)
4668 struct iscsi_endpoint *ep;
4669 struct sockaddr_in *addr;
4670 struct sockaddr_in6 *addr6;
4671 struct sockaddr *dst_addr;
4674 /* TODO: need to destroy on unload iscsi_endpoint*/
4675 dst_addr = vmalloc(sizeof(*dst_addr));
4679 if (fw_ddb_entry->options & DDB_OPT_IPV6_DEVICE) {
4680 dst_addr->sa_family = AF_INET6;
4681 addr6 = (struct sockaddr_in6 *)dst_addr;
4682 ip = (char *)&addr6->sin6_addr;
4683 memcpy(ip, fw_ddb_entry->ip_addr, IPv6_ADDR_LEN);
4684 addr6->sin6_port = htons(le16_to_cpu(fw_ddb_entry->port));
4687 dst_addr->sa_family = AF_INET;
4688 addr = (struct sockaddr_in *)dst_addr;
4689 ip = (char *)&addr->sin_addr;
4690 memcpy(ip, fw_ddb_entry->ip_addr, IP_ADDR_LEN);
4691 addr->sin_port = htons(le16_to_cpu(fw_ddb_entry->port));
4694 ep = qla4xxx_ep_connect(ha->host, dst_addr, 0);
4699 static int qla4xxx_verify_boot_idx(struct scsi_qla_host *ha, uint16_t idx)
4701 if (ql4xdisablesysfsboot)
4703 if (idx == ha->pri_ddb_idx || idx == ha->sec_ddb_idx)
4708 static void qla4xxx_setup_flash_ddb_entry(struct scsi_qla_host *ha,
4709 struct ddb_entry *ddb_entry)
4711 uint16_t def_timeout;
4713 ddb_entry->ddb_type = FLASH_DDB;
4714 ddb_entry->fw_ddb_index = INVALID_ENTRY;
4715 ddb_entry->fw_ddb_device_state = DDB_DS_NO_CONNECTION_ACTIVE;
4717 ddb_entry->unblock_sess = qla4xxx_unblock_flash_ddb;
4718 ddb_entry->ddb_change = qla4xxx_flash_ddb_change;
4720 atomic_set(&ddb_entry->retry_relogin_timer, INVALID_ENTRY);
4721 atomic_set(&ddb_entry->relogin_timer, 0);
4722 atomic_set(&ddb_entry->relogin_retry_count, 0);
4723 def_timeout = le16_to_cpu(ddb_entry->fw_ddb_entry.def_timeout);
4724 ddb_entry->default_relogin_timeout =
4725 (def_timeout > LOGIN_TOV) && (def_timeout < LOGIN_TOV * 10) ?
4726 def_timeout : LOGIN_TOV;
4727 ddb_entry->default_time2wait =
4728 le16_to_cpu(ddb_entry->fw_ddb_entry.iscsi_def_time2wait);
4731 static void qla4xxx_wait_for_ip_configuration(struct scsi_qla_host *ha)
4734 uint32_t ip_idx[IP_ADDR_COUNT] = {0, 1, 2, 3}; /* 4 IP interfaces */
4735 uint32_t sts[MBOX_REG_COUNT];
4737 unsigned long wtime;
4740 wtime = jiffies + (HZ * IP_CONFIG_TOV);
4742 for (idx = 0; idx < IP_ADDR_COUNT; idx++) {
4743 if (ip_idx[idx] == -1)
4746 ret = qla4xxx_get_ip_state(ha, 0, ip_idx[idx], sts);
4748 if (ret == QLA_ERROR) {
4753 ip_state = (sts[1] & IP_STATE_MASK) >> IP_STATE_SHIFT;
4755 DEBUG2(ql4_printk(KERN_INFO, ha,
4756 "Waiting for IP state for idx = %d, state = 0x%x\n",
4757 ip_idx[idx], ip_state));
4758 if (ip_state == IP_ADDRSTATE_UNCONFIGURED ||
4759 ip_state == IP_ADDRSTATE_INVALID ||
4760 ip_state == IP_ADDRSTATE_PREFERRED ||
4761 ip_state == IP_ADDRSTATE_DEPRICATED ||
4762 ip_state == IP_ADDRSTATE_DISABLING)
4766 /* Break if all IP states checked */
4767 if ((ip_idx[0] == -1) &&
4768 (ip_idx[1] == -1) &&
4769 (ip_idx[2] == -1) &&
4772 schedule_timeout_uninterruptible(HZ);
4773 } while (time_after(wtime, jiffies));
4776 static void qla4xxx_build_st_list(struct scsi_qla_host *ha,
4777 struct list_head *list_st)
4779 struct qla_ddb_index *st_ddb_idx;
4782 struct dev_db_entry *fw_ddb_entry;
4783 dma_addr_t fw_ddb_dma;
4785 uint32_t idx = 0, next_idx = 0;
4786 uint32_t state = 0, conn_err = 0;
4787 uint16_t conn_id = 0;
4789 fw_ddb_entry = dma_pool_alloc(ha->fw_ddb_dma_pool, GFP_KERNEL,
4791 if (fw_ddb_entry == NULL) {
4792 DEBUG2(ql4_printk(KERN_ERR, ha, "Out of memory\n"));
4796 max_ddbs = is_qla40XX(ha) ? MAX_DEV_DB_ENTRIES_40XX :
4798 fw_idx_size = sizeof(struct qla_ddb_index);
4800 for (idx = 0; idx < max_ddbs; idx = next_idx) {
4801 ret = qla4xxx_get_fwddb_entry(ha, idx, fw_ddb_entry, fw_ddb_dma,
4802 NULL, &next_idx, &state,
4803 &conn_err, NULL, &conn_id);
4804 if (ret == QLA_ERROR)
4807 /* Ignore DDB if invalid state (unassigned) */
4808 if (state == DDB_DS_UNASSIGNED)
4809 goto continue_next_st;
4811 /* Check if ST, add to the list_st */
4812 if (strlen((char *) fw_ddb_entry->iscsi_name) != 0)
4813 goto continue_next_st;
4815 st_ddb_idx = vzalloc(fw_idx_size);
4819 st_ddb_idx->fw_ddb_idx = idx;
4821 list_add_tail(&st_ddb_idx->list, list_st);
4829 dma_pool_free(ha->fw_ddb_dma_pool, fw_ddb_entry, fw_ddb_dma);
4833 * qla4xxx_remove_failed_ddb - Remove inactive or failed ddb from list
4834 * @ha: pointer to adapter structure
4835 * @list_ddb: List from which failed ddb to be removed
4837 * Iterate over the list of DDBs and find and remove DDBs that are either in
4838 * no connection active state or failed state
4840 static void qla4xxx_remove_failed_ddb(struct scsi_qla_host *ha,
4841 struct list_head *list_ddb)
4843 struct qla_ddb_index *ddb_idx, *ddb_idx_tmp;
4844 uint32_t next_idx = 0;
4845 uint32_t state = 0, conn_err = 0;
4848 list_for_each_entry_safe(ddb_idx, ddb_idx_tmp, list_ddb, list) {
4849 ret = qla4xxx_get_fwddb_entry(ha, ddb_idx->fw_ddb_idx,
4850 NULL, 0, NULL, &next_idx, &state,
4851 &conn_err, NULL, NULL);
4852 if (ret == QLA_ERROR)
4855 if (state == DDB_DS_NO_CONNECTION_ACTIVE ||
4856 state == DDB_DS_SESSION_FAILED) {
4857 list_del_init(&ddb_idx->list);
4863 static int qla4xxx_sess_conn_setup(struct scsi_qla_host *ha,
4864 struct dev_db_entry *fw_ddb_entry,
4867 struct iscsi_cls_session *cls_sess;
4868 struct iscsi_session *sess;
4869 struct iscsi_cls_conn *cls_conn;
4870 struct iscsi_endpoint *ep;
4871 uint16_t cmds_max = 32;
4872 uint16_t conn_id = 0;
4873 uint32_t initial_cmdsn = 0;
4874 int ret = QLA_SUCCESS;
4876 struct ddb_entry *ddb_entry = NULL;
4878 /* Create session object, with INVALID_ENTRY,
4879 * the targer_id would get set when we issue the login
4881 cls_sess = iscsi_session_setup(&qla4xxx_iscsi_transport, ha->host,
4882 cmds_max, sizeof(struct ddb_entry),
4883 sizeof(struct ql4_task_data),
4884 initial_cmdsn, INVALID_ENTRY);
4891 * so calling module_put function to decrement the
4894 module_put(qla4xxx_iscsi_transport.owner);
4895 sess = cls_sess->dd_data;
4896 ddb_entry = sess->dd_data;
4897 ddb_entry->sess = cls_sess;
4899 cls_sess->recovery_tmo = ql4xsess_recovery_tmo;
4900 memcpy(&ddb_entry->fw_ddb_entry, fw_ddb_entry,
4901 sizeof(struct dev_db_entry));
4903 qla4xxx_setup_flash_ddb_entry(ha, ddb_entry);
4905 cls_conn = iscsi_conn_setup(cls_sess, sizeof(struct qla_conn), conn_id);
4912 ddb_entry->conn = cls_conn;
4914 /* Setup ep, for displaying attributes in sysfs */
4915 ep = qla4xxx_get_ep_fwdb(ha, fw_ddb_entry);
4917 ep->conn = cls_conn;
4920 DEBUG2(ql4_printk(KERN_ERR, ha, "Unable to get ep\n"));
4925 /* Update sess/conn params */
4926 qla4xxx_copy_fwddb_param(ha, fw_ddb_entry, cls_sess, cls_conn);
4928 if (is_reset == RESET_ADAPTER) {
4929 iscsi_block_session(cls_sess);
4930 /* Use the relogin path to discover new devices
4931 * by short-circuting the logic of setting
4932 * timer to relogin - instead set the flags
4933 * to initiate login right away.
4935 set_bit(DPC_RELOGIN_DEVICE, &ha->dpc_flags);
4936 set_bit(DF_RELOGIN, &ddb_entry->flags);
4943 static void qla4xxx_build_nt_list(struct scsi_qla_host *ha,
4944 struct list_head *list_nt, int is_reset)
4946 struct dev_db_entry *fw_ddb_entry;
4947 dma_addr_t fw_ddb_dma;
4951 uint32_t idx = 0, next_idx = 0;
4952 uint32_t state = 0, conn_err = 0;
4953 uint16_t conn_id = 0;
4954 struct qla_ddb_index *nt_ddb_idx;
4956 fw_ddb_entry = dma_pool_alloc(ha->fw_ddb_dma_pool, GFP_KERNEL,
4958 if (fw_ddb_entry == NULL) {
4959 DEBUG2(ql4_printk(KERN_ERR, ha, "Out of memory\n"));
4962 max_ddbs = is_qla40XX(ha) ? MAX_DEV_DB_ENTRIES_40XX :
4964 fw_idx_size = sizeof(struct qla_ddb_index);
4966 for (idx = 0; idx < max_ddbs; idx = next_idx) {
4967 ret = qla4xxx_get_fwddb_entry(ha, idx, fw_ddb_entry, fw_ddb_dma,
4968 NULL, &next_idx, &state,
4969 &conn_err, NULL, &conn_id);
4970 if (ret == QLA_ERROR)
4973 if (qla4xxx_verify_boot_idx(ha, idx) != QLA_SUCCESS)
4974 goto continue_next_nt;
4976 /* Check if NT, then add to list it */
4977 if (strlen((char *) fw_ddb_entry->iscsi_name) == 0)
4978 goto continue_next_nt;
4980 if (!(state == DDB_DS_NO_CONNECTION_ACTIVE ||
4981 state == DDB_DS_SESSION_FAILED))
4982 goto continue_next_nt;
4984 DEBUG2(ql4_printk(KERN_INFO, ha,
4985 "Adding DDB to session = 0x%x\n", idx));
4986 if (is_reset == INIT_ADAPTER) {
4987 nt_ddb_idx = vmalloc(fw_idx_size);
4991 nt_ddb_idx->fw_ddb_idx = idx;
4993 /* Copy original isid as it may get updated in function
4994 * qla4xxx_update_isid(). We need original isid in
4995 * function qla4xxx_compare_tuple_ddb to find duplicate
4997 memcpy(&nt_ddb_idx->flash_isid[0],
4998 &fw_ddb_entry->isid[0],
4999 sizeof(nt_ddb_idx->flash_isid));
5001 ret = qla4xxx_is_flash_ddb_exists(ha, list_nt,
5003 if (ret == QLA_SUCCESS) {
5004 /* free nt_ddb_idx and do not add to list_nt */
5006 goto continue_next_nt;
5009 /* Copy updated isid */
5010 memcpy(&nt_ddb_idx->fw_ddb, fw_ddb_entry,
5011 sizeof(struct dev_db_entry));
5013 list_add_tail(&nt_ddb_idx->list, list_nt);
5014 } else if (is_reset == RESET_ADAPTER) {
5015 if (qla4xxx_is_session_exists(ha, fw_ddb_entry) ==
5017 goto continue_next_nt;
5020 ret = qla4xxx_sess_conn_setup(ha, fw_ddb_entry, is_reset);
5021 if (ret == QLA_ERROR)
5031 dma_pool_free(ha->fw_ddb_dma_pool, fw_ddb_entry, fw_ddb_dma);
5035 * qla4xxx_build_ddb_list - Build ddb list and setup sessions
5036 * @ha: pointer to adapter structure
5037 * @is_reset: Is this init path or reset path
5039 * Create a list of sendtargets (st) from firmware DDBs, issue send targets
5040 * using connection open, then create the list of normal targets (nt)
5041 * from firmware DDBs. Based on the list of nt setup session and connection
5044 void qla4xxx_build_ddb_list(struct scsi_qla_host *ha, int is_reset)
5047 struct list_head list_st, list_nt;
5048 struct qla_ddb_index *st_ddb_idx, *st_ddb_idx_tmp;
5049 unsigned long wtime;
5051 if (!test_bit(AF_LINK_UP, &ha->flags)) {
5052 set_bit(AF_BUILD_DDB_LIST, &ha->flags);
5053 ha->is_reset = is_reset;
5057 INIT_LIST_HEAD(&list_st);
5058 INIT_LIST_HEAD(&list_nt);
5060 qla4xxx_build_st_list(ha, &list_st);
5062 /* Before issuing conn open mbox, ensure all IPs states are configured
5063 * Note, conn open fails if IPs are not configured
5065 qla4xxx_wait_for_ip_configuration(ha);
5067 /* Go thru the STs and fire the sendtargets by issuing conn open mbx */
5068 list_for_each_entry_safe(st_ddb_idx, st_ddb_idx_tmp, &list_st, list) {
5069 qla4xxx_conn_open(ha, st_ddb_idx->fw_ddb_idx);
5072 /* Wait to ensure all sendtargets are done for min 12 sec wait */
5073 tmo = ((ha->def_timeout > LOGIN_TOV) &&
5074 (ha->def_timeout < LOGIN_TOV * 10) ?
5075 ha->def_timeout : LOGIN_TOV);
5077 DEBUG2(ql4_printk(KERN_INFO, ha,
5078 "Default time to wait for build ddb %d\n", tmo));
5080 wtime = jiffies + (HZ * tmo);
5082 if (list_empty(&list_st))
5085 qla4xxx_remove_failed_ddb(ha, &list_st);
5086 schedule_timeout_uninterruptible(HZ / 10);
5087 } while (time_after(wtime, jiffies));
5089 /* Free up the sendtargets list */
5090 qla4xxx_free_ddb_list(&list_st);
5092 qla4xxx_build_nt_list(ha, &list_nt, is_reset);
5094 qla4xxx_free_ddb_list(&list_nt);
5096 qla4xxx_free_ddb_index(ha);
5100 * qla4xxx_probe_adapter - callback function to probe HBA
5101 * @pdev: pointer to pci_dev structure
5102 * @pci_device_id: pointer to pci_device entry
5104 * This routine will probe for Qlogic 4xxx iSCSI host adapters.
5105 * It returns zero if successful. It also initializes all data necessary for
5108 static int __devinit qla4xxx_probe_adapter(struct pci_dev *pdev,
5109 const struct pci_device_id *ent)
5111 int ret = -ENODEV, status;
5112 struct Scsi_Host *host;
5113 struct scsi_qla_host *ha;
5114 uint8_t init_retry_count = 0;
5116 struct qla4_8xxx_legacy_intr_set *nx_legacy_intr;
5119 if (pci_enable_device(pdev))
5122 host = iscsi_host_alloc(&qla4xxx_driver_template, sizeof(*ha), 0);
5125 "qla4xxx: Couldn't allocate host from scsi layer!\n");
5126 goto probe_disable_device;
5129 /* Clear our data area */
5130 ha = to_qla_host(host);
5131 memset(ha, 0, sizeof(*ha));
5133 /* Save the information from PCI BIOS. */
5136 ha->host_no = host->host_no;
5137 ha->func_num = PCI_FUNC(ha->pdev->devfn);
5139 pci_enable_pcie_error_reporting(pdev);
5141 /* Setup Runtime configurable options */
5142 if (is_qla8022(ha)) {
5143 ha->isp_ops = &qla4_82xx_isp_ops;
5144 ha->reg_tbl = (uint32_t *) qla4_82xx_reg_tbl;
5145 ha->qdr_sn_window = -1;
5146 ha->ddr_mn_window = -1;
5147 ha->curr_window = 255;
5148 nx_legacy_intr = &legacy_intr[ha->func_num];
5149 ha->nx_legacy_intr.int_vec_bit = nx_legacy_intr->int_vec_bit;
5150 ha->nx_legacy_intr.tgt_status_reg =
5151 nx_legacy_intr->tgt_status_reg;
5152 ha->nx_legacy_intr.tgt_mask_reg = nx_legacy_intr->tgt_mask_reg;
5153 ha->nx_legacy_intr.pci_int_reg = nx_legacy_intr->pci_int_reg;
5154 } else if (is_qla8032(ha)) {
5155 ha->isp_ops = &qla4_83xx_isp_ops;
5156 ha->reg_tbl = (uint32_t *)qla4_83xx_reg_tbl;
5158 ha->isp_ops = &qla4xxx_isp_ops;
5161 if (is_qla80XX(ha)) {
5162 rwlock_init(&ha->hw_lock);
5163 ha->pf_bit = ha->func_num << 16;
5164 /* Set EEH reset type to fundamental if required by hba */
5165 pdev->needs_freset = 1;
5168 /* Configure PCI I/O space. */
5169 ret = ha->isp_ops->iospace_config(ha);
5171 goto probe_failed_ioconfig;
5173 ql4_printk(KERN_INFO, ha, "Found an ISP%04x, irq %d, iobase 0x%p\n",
5174 pdev->device, pdev->irq, ha->reg);
5176 qla4xxx_config_dma_addressing(ha);
5178 /* Initialize lists and spinlocks. */
5179 INIT_LIST_HEAD(&ha->free_srb_q);
5181 mutex_init(&ha->mbox_sem);
5182 mutex_init(&ha->chap_sem);
5183 init_completion(&ha->mbx_intr_comp);
5184 init_completion(&ha->disable_acb_comp);
5186 spin_lock_init(&ha->hardware_lock);
5187 spin_lock_init(&ha->work_lock);
5189 /* Initialize work list */
5190 INIT_LIST_HEAD(&ha->work_list);
5192 /* Allocate dma buffers */
5193 if (qla4xxx_mem_alloc(ha)) {
5194 ql4_printk(KERN_WARNING, ha,
5195 "[ERROR] Failed to allocate memory for adapter\n");
5201 host->cmd_per_lun = 3;
5202 host->max_channel = 0;
5203 host->max_lun = MAX_LUNS - 1;
5204 host->max_id = MAX_TARGETS;
5205 host->max_cmd_len = IOCB_MAX_CDB_LEN;
5206 host->can_queue = MAX_SRBS ;
5207 host->transportt = qla4xxx_scsi_transport;
5209 ret = scsi_init_shared_tag_map(host, MAX_SRBS);
5211 ql4_printk(KERN_WARNING, ha,
5212 "%s: scsi_init_shared_tag_map failed\n", __func__);
5216 pci_set_drvdata(pdev, ha);
5218 ret = scsi_add_host(host, &pdev->dev);
5223 qla4_8xxx_get_flash_info(ha);
5225 if (is_qla8032(ha)) {
5226 qla4_83xx_read_reset_template(ha);
5228 * NOTE: If ql4dontresethba==1, set IDC_CTRL DONTRESET_BIT0.
5229 * If DONRESET_BIT0 is set, drivers should not set dev_state
5230 * to NEED_RESET. But if NEED_RESET is set, drivers should
5231 * should honor the reset.
5233 if (ql4xdontresethba == 1)
5234 qla4_83xx_set_idc_dontreset(ha);
5238 * Initialize the Host adapter request/response queues and
5240 * NOTE: interrupts enabled upon successful completion
5242 status = qla4xxx_initialize_adapter(ha, INIT_ADAPTER);
5244 /* Dont retry adapter initialization if IRQ allocation failed */
5245 if (!test_bit(AF_IRQ_ATTACHED, &ha->flags))
5246 goto skip_retry_init;
5248 while ((!test_bit(AF_ONLINE, &ha->flags)) &&
5249 init_retry_count++ < MAX_INIT_RETRIES) {
5251 if (is_qla80XX(ha)) {
5252 ha->isp_ops->idc_lock(ha);
5253 dev_state = qla4_8xxx_rd_direct(ha,
5254 QLA82XX_CRB_DEV_STATE);
5255 ha->isp_ops->idc_unlock(ha);
5256 if (dev_state == QLA8XXX_DEV_FAILED) {
5257 ql4_printk(KERN_WARNING, ha, "%s: don't retry "
5258 "initialize adapter. H/W is in failed state\n",
5263 DEBUG2(printk("scsi: %s: retrying adapter initialization "
5264 "(%d)\n", __func__, init_retry_count));
5266 if (ha->isp_ops->reset_chip(ha) == QLA_ERROR)
5269 status = qla4xxx_initialize_adapter(ha, INIT_ADAPTER);
5273 if (!test_bit(AF_ONLINE, &ha->flags)) {
5274 ql4_printk(KERN_WARNING, ha, "Failed to initialize adapter\n");
5276 if ((is_qla8022(ha) && ql4xdontresethba) ||
5277 (is_qla8032(ha) && qla4_83xx_idc_dontreset(ha))) {
5278 /* Put the device in failed state. */
5279 DEBUG2(printk(KERN_ERR "HW STATE: FAILED\n"));
5280 ha->isp_ops->idc_lock(ha);
5281 qla4_8xxx_wr_direct(ha, QLA8XXX_CRB_DEV_STATE,
5282 QLA8XXX_DEV_FAILED);
5283 ha->isp_ops->idc_unlock(ha);
5289 /* Startup the kernel thread for this host adapter. */
5290 DEBUG2(printk("scsi: %s: Starting kernel thread for "
5291 "qla4xxx_dpc\n", __func__));
5292 sprintf(buf, "qla4xxx_%lu_dpc", ha->host_no);
5293 ha->dpc_thread = create_singlethread_workqueue(buf);
5294 if (!ha->dpc_thread) {
5295 ql4_printk(KERN_WARNING, ha, "Unable to start DPC thread!\n");
5299 INIT_WORK(&ha->dpc_work, qla4xxx_do_dpc);
5301 sprintf(buf, "qla4xxx_%lu_task", ha->host_no);
5302 ha->task_wq = alloc_workqueue(buf, WQ_MEM_RECLAIM, 1);
5304 ql4_printk(KERN_WARNING, ha, "Unable to start task thread!\n");
5310 * For ISP-8XXX, request_irqs is called in qla4_8xxx_load_risc
5311 * (which is called indirectly by qla4xxx_initialize_adapter),
5312 * so that irqs will be registered after crbinit but before
5315 if (is_qla40XX(ha)) {
5316 ret = qla4xxx_request_irqs(ha);
5318 ql4_printk(KERN_WARNING, ha, "Failed to reserve "
5319 "interrupt %d already in use.\n", pdev->irq);
5324 pci_save_state(ha->pdev);
5325 ha->isp_ops->enable_intrs(ha);
5327 /* Start timer thread. */
5328 qla4xxx_start_timer(ha, qla4xxx_timer, 1);
5330 set_bit(AF_INIT_DONE, &ha->flags);
5332 qla4_8xxx_alloc_sysfs_attr(ha);
5335 " QLogic iSCSI HBA Driver version: %s\n"
5336 " QLogic ISP%04x @ %s, host#=%ld, fw=%02d.%02d.%02d.%02d\n",
5337 qla4xxx_version_str, ha->pdev->device, pci_name(ha->pdev),
5338 ha->host_no, ha->firmware_version[0], ha->firmware_version[1],
5339 ha->patch_number, ha->build_number);
5341 /* Set the driver version */
5343 qla4_8xxx_set_param(ha, SET_DRVR_VERSION);
5345 if (qla4xxx_setup_boot_info(ha))
5346 ql4_printk(KERN_ERR, ha,
5347 "%s: No iSCSI boot target configured\n", __func__);
5349 /* Perform the build ddb list and login to each */
5350 qla4xxx_build_ddb_list(ha, INIT_ADAPTER);
5351 iscsi_host_for_each_session(ha->host, qla4xxx_login_flash_ddb);
5353 qla4xxx_create_chap_list(ha);
5355 qla4xxx_create_ifaces(ha);
5359 scsi_remove_host(ha->host);
5362 qla4xxx_free_adapter(ha);
5364 probe_failed_ioconfig:
5365 pci_disable_pcie_error_reporting(pdev);
5366 scsi_host_put(ha->host);
5368 probe_disable_device:
5369 pci_disable_device(pdev);
5375 * qla4xxx_prevent_other_port_reinit - prevent other port from re-initialize
5376 * @ha: pointer to adapter structure
5378 * Mark the other ISP-4xxx port to indicate that the driver is being removed,
5379 * so that the other port will not re-initialize while in the process of
5380 * removing the ha due to driver unload or hba hotplug.
5382 static void qla4xxx_prevent_other_port_reinit(struct scsi_qla_host *ha)
5384 struct scsi_qla_host *other_ha = NULL;
5385 struct pci_dev *other_pdev = NULL;
5386 int fn = ISP4XXX_PCI_FN_2;
5388 /*iscsi function numbers for ISP4xxx is 1 and 3*/
5389 if (PCI_FUNC(ha->pdev->devfn) & BIT_1)
5390 fn = ISP4XXX_PCI_FN_1;
5393 pci_get_domain_bus_and_slot(pci_domain_nr(ha->pdev->bus),
5394 ha->pdev->bus->number, PCI_DEVFN(PCI_SLOT(ha->pdev->devfn),
5397 /* Get other_ha if other_pdev is valid and state is enable*/
5399 if (atomic_read(&other_pdev->enable_cnt)) {
5400 other_ha = pci_get_drvdata(other_pdev);
5402 set_bit(AF_HA_REMOVAL, &other_ha->flags);
5403 DEBUG2(ql4_printk(KERN_INFO, ha, "%s: "
5404 "Prevent %s reinit\n", __func__,
5405 dev_name(&other_ha->pdev->dev)));
5408 pci_dev_put(other_pdev);
5412 static void qla4xxx_destroy_fw_ddb_session(struct scsi_qla_host *ha)
5414 struct ddb_entry *ddb_entry;
5418 for (idx = 0; idx < MAX_DDB_ENTRIES; idx++) {
5420 ddb_entry = qla4xxx_lookup_ddb_by_fw_index(ha, idx);
5421 if ((ddb_entry != NULL) &&
5422 (ddb_entry->ddb_type == FLASH_DDB)) {
5424 options = LOGOUT_OPTION_CLOSE_SESSION;
5425 if (qla4xxx_session_logout_ddb(ha, ddb_entry, options)
5427 ql4_printk(KERN_ERR, ha, "%s: Logout failed\n",
5430 qla4xxx_clear_ddb_entry(ha, ddb_entry->fw_ddb_index);
5432 * we have decremented the reference count of the driver
5433 * when we setup the session to have the driver unload
5434 * to be seamless without actually destroying the
5437 try_module_get(qla4xxx_iscsi_transport.owner);
5438 iscsi_destroy_endpoint(ddb_entry->conn->ep);
5439 qla4xxx_free_ddb(ha, ddb_entry);
5440 iscsi_session_teardown(ddb_entry->sess);
5445 * qla4xxx_remove_adapter - calback function to remove adapter.
5446 * @pci_dev: PCI device pointer
5448 static void __devexit qla4xxx_remove_adapter(struct pci_dev *pdev)
5450 struct scsi_qla_host *ha;
5452 ha = pci_get_drvdata(pdev);
5455 qla4xxx_prevent_other_port_reinit(ha);
5457 /* destroy iface from sysfs */
5458 qla4xxx_destroy_ifaces(ha);
5460 if ((!ql4xdisablesysfsboot) && ha->boot_kset)
5461 iscsi_boot_destroy_kset(ha->boot_kset);
5463 qla4xxx_destroy_fw_ddb_session(ha);
5464 qla4_8xxx_free_sysfs_attr(ha);
5466 scsi_remove_host(ha->host);
5468 qla4xxx_free_adapter(ha);
5470 scsi_host_put(ha->host);
5472 pci_disable_pcie_error_reporting(pdev);
5473 pci_disable_device(pdev);
5474 pci_set_drvdata(pdev, NULL);
5478 * qla4xxx_config_dma_addressing() - Configure OS DMA addressing method.
5481 * At exit, the @ha's flags.enable_64bit_addressing set to indicated
5482 * supported addressing method.
5484 static void qla4xxx_config_dma_addressing(struct scsi_qla_host *ha)
5488 /* Update our PCI device dma_mask for full 64 bit mask */
5489 if (pci_set_dma_mask(ha->pdev, DMA_BIT_MASK(64)) == 0) {
5490 if (pci_set_consistent_dma_mask(ha->pdev, DMA_BIT_MASK(64))) {
5491 dev_dbg(&ha->pdev->dev,
5492 "Failed to set 64 bit PCI consistent mask; "
5494 retval = pci_set_consistent_dma_mask(ha->pdev,
5498 retval = pci_set_dma_mask(ha->pdev, DMA_BIT_MASK(32));
5501 static int qla4xxx_slave_alloc(struct scsi_device *sdev)
5503 struct iscsi_cls_session *cls_sess;
5504 struct iscsi_session *sess;
5505 struct ddb_entry *ddb;
5506 int queue_depth = QL4_DEF_QDEPTH;
5508 cls_sess = starget_to_session(sdev->sdev_target);
5509 sess = cls_sess->dd_data;
5510 ddb = sess->dd_data;
5512 sdev->hostdata = ddb;
5513 sdev->tagged_supported = 1;
5515 if (ql4xmaxqdepth != 0 && ql4xmaxqdepth <= 0xffffU)
5516 queue_depth = ql4xmaxqdepth;
5518 scsi_activate_tcq(sdev, queue_depth);
5522 static int qla4xxx_slave_configure(struct scsi_device *sdev)
5524 sdev->tagged_supported = 1;
5528 static void qla4xxx_slave_destroy(struct scsi_device *sdev)
5530 scsi_deactivate_tcq(sdev, 1);
5533 static int qla4xxx_change_queue_depth(struct scsi_device *sdev, int qdepth,
5536 if (!ql4xqfulltracking)
5539 return iscsi_change_queue_depth(sdev, qdepth, reason);
5543 * qla4xxx_del_from_active_array - returns an active srb
5544 * @ha: Pointer to host adapter structure.
5545 * @index: index into the active_array
5547 * This routine removes and returns the srb at the specified index
5549 struct srb *qla4xxx_del_from_active_array(struct scsi_qla_host *ha,
5552 struct srb *srb = NULL;
5553 struct scsi_cmnd *cmd = NULL;
5555 cmd = scsi_host_find_tag(ha->host, index);
5559 srb = (struct srb *)CMD_SP(cmd);
5563 /* update counters */
5564 if (srb->flags & SRB_DMA_VALID) {
5565 ha->req_q_count += srb->iocb_cnt;
5566 ha->iocb_cnt -= srb->iocb_cnt;
5568 srb->cmd->host_scribble =
5569 (unsigned char *)(unsigned long) MAX_SRBS;
5575 * qla4xxx_eh_wait_on_command - waits for command to be returned by firmware
5576 * @ha: Pointer to host adapter structure.
5577 * @cmd: Scsi Command to wait on.
5579 * This routine waits for the command to be returned by the Firmware
5580 * for some max time.
5582 static int qla4xxx_eh_wait_on_command(struct scsi_qla_host *ha,
5583 struct scsi_cmnd *cmd)
5587 uint32_t max_wait_time = EH_WAIT_CMD_TOV;
5590 /* Dont wait on command if PCI error is being handled
5593 if (unlikely(pci_channel_offline(ha->pdev)) ||
5594 (test_bit(AF_EEH_BUSY, &ha->flags))) {
5595 ql4_printk(KERN_WARNING, ha, "scsi%ld: Return from %s\n",
5596 ha->host_no, __func__);
5601 /* Checking to see if its returned to OS */
5602 rp = (struct srb *) CMD_SP(cmd);
5609 } while (max_wait_time--);
5615 * qla4xxx_wait_for_hba_online - waits for HBA to come online
5616 * @ha: Pointer to host adapter structure
5618 static int qla4xxx_wait_for_hba_online(struct scsi_qla_host *ha)
5620 unsigned long wait_online;
5622 wait_online = jiffies + (HBA_ONLINE_TOV * HZ);
5623 while (time_before(jiffies, wait_online)) {
5635 * qla4xxx_eh_wait_for_commands - wait for active cmds to finish.
5636 * @ha: pointer to HBA
5640 * This function waits for all outstanding commands to a lun to complete. It
5641 * returns 0 if all pending commands are returned and 1 otherwise.
5643 static int qla4xxx_eh_wait_for_commands(struct scsi_qla_host *ha,
5644 struct scsi_target *stgt,
5645 struct scsi_device *sdev)
5649 struct scsi_cmnd *cmd;
5652 * Waiting for all commands for the designated target or dev
5653 * in the active array
5655 for (cnt = 0; cnt < ha->host->can_queue; cnt++) {
5656 cmd = scsi_host_find_tag(ha->host, cnt);
5657 if (cmd && stgt == scsi_target(cmd->device) &&
5658 (!sdev || sdev == cmd->device)) {
5659 if (!qla4xxx_eh_wait_on_command(ha, cmd)) {
5669 * qla4xxx_eh_abort - callback for abort task.
5670 * @cmd: Pointer to Linux's SCSI command structure
5672 * This routine is called by the Linux OS to abort the specified
5675 static int qla4xxx_eh_abort(struct scsi_cmnd *cmd)
5677 struct scsi_qla_host *ha = to_qla_host(cmd->device->host);
5678 unsigned int id = cmd->device->id;
5679 unsigned int lun = cmd->device->lun;
5680 unsigned long flags;
5681 struct srb *srb = NULL;
5685 ql4_printk(KERN_INFO, ha,
5686 "scsi%ld:%d:%d: Abort command issued cmd=%p\n",
5687 ha->host_no, id, lun, cmd);
5689 spin_lock_irqsave(&ha->hardware_lock, flags);
5690 srb = (struct srb *) CMD_SP(cmd);
5692 spin_unlock_irqrestore(&ha->hardware_lock, flags);
5695 kref_get(&srb->srb_ref);
5696 spin_unlock_irqrestore(&ha->hardware_lock, flags);
5698 if (qla4xxx_abort_task(ha, srb) != QLA_SUCCESS) {
5699 DEBUG3(printk("scsi%ld:%d:%d: Abort_task mbx failed.\n",
5700 ha->host_no, id, lun));
5703 DEBUG3(printk("scsi%ld:%d:%d: Abort_task mbx success.\n",
5704 ha->host_no, id, lun));
5708 kref_put(&srb->srb_ref, qla4xxx_srb_compl);
5710 /* Wait for command to complete */
5712 if (!qla4xxx_eh_wait_on_command(ha, cmd)) {
5713 DEBUG2(printk("scsi%ld:%d:%d: Abort handler timed out\n",
5714 ha->host_no, id, lun));
5719 ql4_printk(KERN_INFO, ha,
5720 "scsi%ld:%d:%d: Abort command - %s\n",
5721 ha->host_no, id, lun, (ret == SUCCESS) ? "succeeded" : "failed");
5727 * qla4xxx_eh_device_reset - callback for target reset.
5728 * @cmd: Pointer to Linux's SCSI command structure
5730 * This routine is called by the Linux OS to reset all luns on the
5733 static int qla4xxx_eh_device_reset(struct scsi_cmnd *cmd)
5735 struct scsi_qla_host *ha = to_qla_host(cmd->device->host);
5736 struct ddb_entry *ddb_entry = cmd->device->hostdata;
5737 int ret = FAILED, stat;
5742 ret = iscsi_block_scsi_eh(cmd);
5747 ql4_printk(KERN_INFO, ha,
5748 "scsi%ld:%d:%d:%d: DEVICE RESET ISSUED.\n", ha->host_no,
5749 cmd->device->channel, cmd->device->id, cmd->device->lun);
5751 DEBUG2(printk(KERN_INFO
5752 "scsi%ld: DEVICE_RESET cmd=%p jiffies = 0x%lx, to=%x,"
5753 "dpc_flags=%lx, status=%x allowed=%d\n", ha->host_no,
5754 cmd, jiffies, cmd->request->timeout / HZ,
5755 ha->dpc_flags, cmd->result, cmd->allowed));
5757 /* FIXME: wait for hba to go online */
5758 stat = qla4xxx_reset_lun(ha, ddb_entry, cmd->device->lun);
5759 if (stat != QLA_SUCCESS) {
5760 ql4_printk(KERN_INFO, ha, "DEVICE RESET FAILED. %d\n", stat);
5761 goto eh_dev_reset_done;
5764 if (qla4xxx_eh_wait_for_commands(ha, scsi_target(cmd->device),
5766 ql4_printk(KERN_INFO, ha,
5767 "DEVICE RESET FAILED - waiting for "
5769 goto eh_dev_reset_done;
5773 if (qla4xxx_send_marker_iocb(ha, ddb_entry, cmd->device->lun,
5774 MM_LUN_RESET) != QLA_SUCCESS)
5775 goto eh_dev_reset_done;
5777 ql4_printk(KERN_INFO, ha,
5778 "scsi(%ld:%d:%d:%d): DEVICE RESET SUCCEEDED.\n",
5779 ha->host_no, cmd->device->channel, cmd->device->id,
5790 * qla4xxx_eh_target_reset - callback for target reset.
5791 * @cmd: Pointer to Linux's SCSI command structure
5793 * This routine is called by the Linux OS to reset the target.
5795 static int qla4xxx_eh_target_reset(struct scsi_cmnd *cmd)
5797 struct scsi_qla_host *ha = to_qla_host(cmd->device->host);
5798 struct ddb_entry *ddb_entry = cmd->device->hostdata;
5804 ret = iscsi_block_scsi_eh(cmd);
5808 starget_printk(KERN_INFO, scsi_target(cmd->device),
5809 "WARM TARGET RESET ISSUED.\n");
5811 DEBUG2(printk(KERN_INFO
5812 "scsi%ld: TARGET_DEVICE_RESET cmd=%p jiffies = 0x%lx, "
5813 "to=%x,dpc_flags=%lx, status=%x allowed=%d\n",
5814 ha->host_no, cmd, jiffies, cmd->request->timeout / HZ,
5815 ha->dpc_flags, cmd->result, cmd->allowed));
5817 stat = qla4xxx_reset_target(ha, ddb_entry);
5818 if (stat != QLA_SUCCESS) {
5819 starget_printk(KERN_INFO, scsi_target(cmd->device),
5820 "WARM TARGET RESET FAILED.\n");
5824 if (qla4xxx_eh_wait_for_commands(ha, scsi_target(cmd->device),
5826 starget_printk(KERN_INFO, scsi_target(cmd->device),
5827 "WARM TARGET DEVICE RESET FAILED - "
5828 "waiting for commands.\n");
5833 if (qla4xxx_send_marker_iocb(ha, ddb_entry, cmd->device->lun,
5834 MM_TGT_WARM_RESET) != QLA_SUCCESS) {
5835 starget_printk(KERN_INFO, scsi_target(cmd->device),
5836 "WARM TARGET DEVICE RESET FAILED - "
5837 "marker iocb failed.\n");
5841 starget_printk(KERN_INFO, scsi_target(cmd->device),
5842 "WARM TARGET RESET SUCCEEDED.\n");
5847 * qla4xxx_is_eh_active - check if error handler is running
5848 * @shost: Pointer to SCSI Host struct
5850 * This routine finds that if reset host is called in EH
5851 * scenario or from some application like sg_reset
5853 static int qla4xxx_is_eh_active(struct Scsi_Host *shost)
5855 if (shost->shost_state == SHOST_RECOVERY)
5861 * qla4xxx_eh_host_reset - kernel callback
5862 * @cmd: Pointer to Linux's SCSI command structure
5864 * This routine is invoked by the Linux kernel to perform fatal error
5865 * recovery on the specified adapter.
5867 static int qla4xxx_eh_host_reset(struct scsi_cmnd *cmd)
5869 int return_status = FAILED;
5870 struct scsi_qla_host *ha;
5872 ha = to_qla_host(cmd->device->host);
5874 if (is_qla8032(ha) && ql4xdontresethba)
5875 qla4_83xx_set_idc_dontreset(ha);
5878 * For ISP8324, if IDC_CTRL DONTRESET_BIT0 is set by other
5879 * protocol drivers, we should not set device_state to
5882 if (ql4xdontresethba ||
5883 (is_qla8032(ha) && qla4_83xx_idc_dontreset(ha))) {
5884 DEBUG2(printk("scsi%ld: %s: Don't Reset HBA\n",
5885 ha->host_no, __func__));
5887 /* Clear outstanding srb in queues */
5888 if (qla4xxx_is_eh_active(cmd->device->host))
5889 qla4xxx_abort_active_cmds(ha, DID_ABORT << 16);
5894 ql4_printk(KERN_INFO, ha,
5895 "scsi(%ld:%d:%d:%d): HOST RESET ISSUED.\n", ha->host_no,
5896 cmd->device->channel, cmd->device->id, cmd->device->lun);
5898 if (qla4xxx_wait_for_hba_online(ha) != QLA_SUCCESS) {
5899 DEBUG2(printk("scsi%ld:%d: %s: Unable to reset host. Adapter "
5900 "DEAD.\n", ha->host_no, cmd->device->channel,
5906 if (!test_bit(DPC_RESET_HA, &ha->dpc_flags)) {
5908 set_bit(DPC_RESET_HA_FW_CONTEXT, &ha->dpc_flags);
5910 set_bit(DPC_RESET_HA, &ha->dpc_flags);
5913 if (qla4xxx_recover_adapter(ha) == QLA_SUCCESS)
5914 return_status = SUCCESS;
5916 ql4_printk(KERN_INFO, ha, "HOST RESET %s.\n",
5917 return_status == FAILED ? "FAILED" : "SUCCEEDED");
5919 return return_status;
5922 static int qla4xxx_context_reset(struct scsi_qla_host *ha)
5924 uint32_t mbox_cmd[MBOX_REG_COUNT];
5925 uint32_t mbox_sts[MBOX_REG_COUNT];
5926 struct addr_ctrl_blk_def *acb = NULL;
5927 uint32_t acb_len = sizeof(struct addr_ctrl_blk_def);
5928 int rval = QLA_SUCCESS;
5931 acb = dma_alloc_coherent(&ha->pdev->dev,
5932 sizeof(struct addr_ctrl_blk_def),
5933 &acb_dma, GFP_KERNEL);
5935 ql4_printk(KERN_ERR, ha, "%s: Unable to alloc acb\n",
5938 goto exit_port_reset;
5941 memset(acb, 0, acb_len);
5943 rval = qla4xxx_get_acb(ha, acb_dma, PRIMARI_ACB, acb_len);
5944 if (rval != QLA_SUCCESS) {
5949 rval = qla4xxx_disable_acb(ha);
5950 if (rval != QLA_SUCCESS) {
5955 wait_for_completion_timeout(&ha->disable_acb_comp,
5956 DISABLE_ACB_TOV * HZ);
5958 rval = qla4xxx_set_acb(ha, &mbox_cmd[0], &mbox_sts[0], acb_dma);
5959 if (rval != QLA_SUCCESS) {
5965 dma_free_coherent(&ha->pdev->dev, sizeof(struct addr_ctrl_blk_def),
5968 DEBUG2(ql4_printk(KERN_INFO, ha, "%s %s\n", __func__,
5969 rval == QLA_SUCCESS ? "SUCCEEDED" : "FAILED"));
5973 static int qla4xxx_host_reset(struct Scsi_Host *shost, int reset_type)
5975 struct scsi_qla_host *ha = to_qla_host(shost);
5976 int rval = QLA_SUCCESS;
5978 if (ql4xdontresethba) {
5979 DEBUG2(ql4_printk(KERN_INFO, ha, "%s: Don't Reset HBA\n",
5982 goto exit_host_reset;
5985 rval = qla4xxx_wait_for_hba_online(ha);
5986 if (rval != QLA_SUCCESS) {
5987 DEBUG2(ql4_printk(KERN_INFO, ha, "%s: Unable to reset host "
5988 "adapter\n", __func__));
5990 goto exit_host_reset;
5993 if (test_bit(DPC_RESET_HA, &ha->dpc_flags))
5994 goto recover_adapter;
5996 switch (reset_type) {
5997 case SCSI_ADAPTER_RESET:
5998 set_bit(DPC_RESET_HA, &ha->dpc_flags);
6000 case SCSI_FIRMWARE_RESET:
6001 if (!test_bit(DPC_RESET_HA, &ha->dpc_flags)) {
6003 /* set firmware context reset */
6004 set_bit(DPC_RESET_HA_FW_CONTEXT,
6007 rval = qla4xxx_context_reset(ha);
6008 goto exit_host_reset;
6015 rval = qla4xxx_recover_adapter(ha);
6016 if (rval != QLA_SUCCESS) {
6017 DEBUG2(ql4_printk(KERN_INFO, ha, "%s: recover adapter fail\n",
6026 /* PCI AER driver recovers from all correctable errors w/o
6027 * driver intervention. For uncorrectable errors PCI AER
6028 * driver calls the following device driver's callbacks
6030 * - Fatal Errors - link_reset
6031 * - Non-Fatal Errors - driver's pci_error_detected() which
6032 * returns CAN_RECOVER, NEED_RESET or DISCONNECT.
6034 * PCI AER driver calls
6035 * CAN_RECOVER - driver's pci_mmio_enabled(), mmio_enabled
6036 * returns RECOVERED or NEED_RESET if fw_hung
6037 * NEED_RESET - driver's slot_reset()
6038 * DISCONNECT - device is dead & cannot recover
6039 * RECOVERED - driver's pci_resume()
6041 static pci_ers_result_t
6042 qla4xxx_pci_error_detected(struct pci_dev *pdev, pci_channel_state_t state)
6044 struct scsi_qla_host *ha = pci_get_drvdata(pdev);
6046 ql4_printk(KERN_WARNING, ha, "scsi%ld: %s: error detected:state %x\n",
6047 ha->host_no, __func__, state);
6049 if (!is_aer_supported(ha))
6050 return PCI_ERS_RESULT_NONE;
6053 case pci_channel_io_normal:
6054 clear_bit(AF_EEH_BUSY, &ha->flags);
6055 return PCI_ERS_RESULT_CAN_RECOVER;
6056 case pci_channel_io_frozen:
6057 set_bit(AF_EEH_BUSY, &ha->flags);
6058 qla4xxx_mailbox_premature_completion(ha);
6059 qla4xxx_free_irqs(ha);
6060 pci_disable_device(pdev);
6061 /* Return back all IOs */
6062 qla4xxx_abort_active_cmds(ha, DID_RESET << 16);
6063 return PCI_ERS_RESULT_NEED_RESET;
6064 case pci_channel_io_perm_failure:
6065 set_bit(AF_EEH_BUSY, &ha->flags);
6066 set_bit(AF_PCI_CHANNEL_IO_PERM_FAILURE, &ha->flags);
6067 qla4xxx_abort_active_cmds(ha, DID_NO_CONNECT << 16);
6068 return PCI_ERS_RESULT_DISCONNECT;
6070 return PCI_ERS_RESULT_NEED_RESET;
6074 * qla4xxx_pci_mmio_enabled() gets called if
6075 * qla4xxx_pci_error_detected() returns PCI_ERS_RESULT_CAN_RECOVER
6076 * and read/write to the device still works.
6078 static pci_ers_result_t
6079 qla4xxx_pci_mmio_enabled(struct pci_dev *pdev)
6081 struct scsi_qla_host *ha = pci_get_drvdata(pdev);
6083 if (!is_aer_supported(ha))
6084 return PCI_ERS_RESULT_NONE;
6086 return PCI_ERS_RESULT_RECOVERED;
6089 static uint32_t qla4_8xxx_error_recovery(struct scsi_qla_host *ha)
6091 uint32_t rval = QLA_ERROR;
6094 struct pci_dev *other_pdev = NULL;
6096 ql4_printk(KERN_WARNING, ha, "scsi%ld: In %s\n", ha->host_no, __func__);
6098 set_bit(DPC_RESET_ACTIVE, &ha->dpc_flags);
6100 if (test_bit(AF_ONLINE, &ha->flags)) {
6101 clear_bit(AF_ONLINE, &ha->flags);
6102 clear_bit(AF_LINK_UP, &ha->flags);
6103 iscsi_host_for_each_session(ha->host, qla4xxx_fail_session);
6104 qla4xxx_process_aen(ha, FLUSH_DDB_CHANGED_AENS);
6107 fn = PCI_FUNC(ha->pdev->devfn);
6110 ql4_printk(KERN_INFO, ha, "scsi%ld: %s: Finding PCI device at "
6111 "func %x\n", ha->host_no, __func__, fn);
6112 /* Get the pci device given the domain, bus,
6113 * slot/function number */
6115 pci_get_domain_bus_and_slot(pci_domain_nr(ha->pdev->bus),
6116 ha->pdev->bus->number, PCI_DEVFN(PCI_SLOT(ha->pdev->devfn),
6122 if (atomic_read(&other_pdev->enable_cnt)) {
6123 ql4_printk(KERN_INFO, ha, "scsi%ld: %s: Found PCI "
6124 "func in enabled state%x\n", ha->host_no,
6126 pci_dev_put(other_pdev);
6129 pci_dev_put(other_pdev);
6132 /* The first function on the card, the reset owner will
6133 * start & initialize the firmware. The other functions
6134 * on the card will reset the firmware context
6137 ql4_printk(KERN_INFO, ha, "scsi%ld: %s: devfn being reset "
6138 "0x%x is the owner\n", ha->host_no, __func__,
6141 ha->isp_ops->idc_lock(ha);
6142 qla4_8xxx_wr_direct(ha, QLA8XXX_CRB_DEV_STATE,
6144 ha->isp_ops->idc_unlock(ha);
6146 rval = qla4_8xxx_update_idc_reg(ha);
6147 if (rval == QLA_ERROR) {
6148 ql4_printk(KERN_INFO, ha, "scsi%ld: %s: HW State: FAILED\n",
6149 ha->host_no, __func__);
6150 ha->isp_ops->idc_lock(ha);
6151 qla4_8xxx_wr_direct(ha, QLA8XXX_CRB_DEV_STATE,
6152 QLA8XXX_DEV_FAILED);
6153 ha->isp_ops->idc_unlock(ha);
6154 goto exit_error_recovery;
6157 clear_bit(AF_FW_RECOVERY, &ha->flags);
6158 rval = qla4xxx_initialize_adapter(ha, RESET_ADAPTER);
6160 if (rval != QLA_SUCCESS) {
6161 ql4_printk(KERN_INFO, ha, "scsi%ld: %s: HW State: "
6162 "FAILED\n", ha->host_no, __func__);
6163 ha->isp_ops->idc_lock(ha);
6164 qla4_8xxx_clear_drv_active(ha);
6165 qla4_8xxx_wr_direct(ha, QLA8XXX_CRB_DEV_STATE,
6166 QLA8XXX_DEV_FAILED);
6167 ha->isp_ops->idc_unlock(ha);
6169 ql4_printk(KERN_INFO, ha, "scsi%ld: %s: HW State: "
6170 "READY\n", ha->host_no, __func__);
6171 ha->isp_ops->idc_lock(ha);
6172 qla4_8xxx_wr_direct(ha, QLA8XXX_CRB_DEV_STATE,
6174 /* Clear driver state register */
6175 qla4_8xxx_wr_direct(ha, QLA8XXX_CRB_DRV_STATE, 0);
6176 qla4_8xxx_set_drv_active(ha);
6177 ha->isp_ops->idc_unlock(ha);
6178 ret = qla4xxx_request_irqs(ha);
6180 ql4_printk(KERN_WARNING, ha, "Failed to "
6181 "reserve interrupt %d already in use.\n",
6185 ha->isp_ops->enable_intrs(ha);
6190 ql4_printk(KERN_INFO, ha, "scsi%ld: %s: devfn 0x%x is not "
6191 "the reset owner\n", ha->host_no, __func__,
6193 if ((qla4_8xxx_rd_direct(ha, QLA8XXX_CRB_DEV_STATE) ==
6194 QLA8XXX_DEV_READY)) {
6195 clear_bit(AF_FW_RECOVERY, &ha->flags);
6196 rval = qla4xxx_initialize_adapter(ha, RESET_ADAPTER);
6197 if (rval == QLA_SUCCESS) {
6198 ret = qla4xxx_request_irqs(ha);
6200 ql4_printk(KERN_WARNING, ha, "Failed to"
6201 " reserve interrupt %d already in"
6202 " use.\n", ha->pdev->irq);
6205 ha->isp_ops->enable_intrs(ha);
6209 ha->isp_ops->idc_lock(ha);
6210 qla4_8xxx_set_drv_active(ha);
6211 ha->isp_ops->idc_unlock(ha);
6214 exit_error_recovery:
6215 clear_bit(DPC_RESET_ACTIVE, &ha->dpc_flags);
6219 static pci_ers_result_t
6220 qla4xxx_pci_slot_reset(struct pci_dev *pdev)
6222 pci_ers_result_t ret = PCI_ERS_RESULT_DISCONNECT;
6223 struct scsi_qla_host *ha = pci_get_drvdata(pdev);
6226 ql4_printk(KERN_WARNING, ha, "scsi%ld: %s: slot_reset\n",
6227 ha->host_no, __func__);
6229 if (!is_aer_supported(ha))
6230 return PCI_ERS_RESULT_NONE;
6232 /* Restore the saved state of PCIe device -
6233 * BAR registers, PCI Config space, PCIX, MSI,
6236 pci_restore_state(pdev);
6238 /* pci_restore_state() clears the saved_state flag of the device
6239 * save restored state which resets saved_state flag
6241 pci_save_state(pdev);
6243 /* Initialize device or resume if in suspended state */
6244 rc = pci_enable_device(pdev);
6246 ql4_printk(KERN_WARNING, ha, "scsi%ld: %s: Can't re-enable "
6247 "device after reset\n", ha->host_no, __func__);
6248 goto exit_slot_reset;
6251 ha->isp_ops->disable_intrs(ha);
6253 if (is_qla80XX(ha)) {
6254 if (qla4_8xxx_error_recovery(ha) == QLA_SUCCESS) {
6255 ret = PCI_ERS_RESULT_RECOVERED;
6256 goto exit_slot_reset;
6258 goto exit_slot_reset;
6262 ql4_printk(KERN_WARNING, ha, "scsi%ld: %s: Return=%x\n"
6263 "device after reset\n", ha->host_no, __func__, ret);
6268 qla4xxx_pci_resume(struct pci_dev *pdev)
6270 struct scsi_qla_host *ha = pci_get_drvdata(pdev);
6273 ql4_printk(KERN_WARNING, ha, "scsi%ld: %s: pci_resume\n",
6274 ha->host_no, __func__);
6276 ret = qla4xxx_wait_for_hba_online(ha);
6277 if (ret != QLA_SUCCESS) {
6278 ql4_printk(KERN_ERR, ha, "scsi%ld: %s: the device failed to "
6279 "resume I/O from slot/link_reset\n", ha->host_no,
6283 pci_cleanup_aer_uncorrect_error_status(pdev);
6284 clear_bit(AF_EEH_BUSY, &ha->flags);
6287 static struct pci_error_handlers qla4xxx_err_handler = {
6288 .error_detected = qla4xxx_pci_error_detected,
6289 .mmio_enabled = qla4xxx_pci_mmio_enabled,
6290 .slot_reset = qla4xxx_pci_slot_reset,
6291 .resume = qla4xxx_pci_resume,
6294 static struct pci_device_id qla4xxx_pci_tbl[] = {
6296 .vendor = PCI_VENDOR_ID_QLOGIC,
6297 .device = PCI_DEVICE_ID_QLOGIC_ISP4010,
6298 .subvendor = PCI_ANY_ID,
6299 .subdevice = PCI_ANY_ID,
6302 .vendor = PCI_VENDOR_ID_QLOGIC,
6303 .device = PCI_DEVICE_ID_QLOGIC_ISP4022,
6304 .subvendor = PCI_ANY_ID,
6305 .subdevice = PCI_ANY_ID,
6308 .vendor = PCI_VENDOR_ID_QLOGIC,
6309 .device = PCI_DEVICE_ID_QLOGIC_ISP4032,
6310 .subvendor = PCI_ANY_ID,
6311 .subdevice = PCI_ANY_ID,
6314 .vendor = PCI_VENDOR_ID_QLOGIC,
6315 .device = PCI_DEVICE_ID_QLOGIC_ISP8022,
6316 .subvendor = PCI_ANY_ID,
6317 .subdevice = PCI_ANY_ID,
6320 .vendor = PCI_VENDOR_ID_QLOGIC,
6321 .device = PCI_DEVICE_ID_QLOGIC_ISP8324,
6322 .subvendor = PCI_ANY_ID,
6323 .subdevice = PCI_ANY_ID,
6327 MODULE_DEVICE_TABLE(pci, qla4xxx_pci_tbl);
6329 static struct pci_driver qla4xxx_pci_driver = {
6330 .name = DRIVER_NAME,
6331 .id_table = qla4xxx_pci_tbl,
6332 .probe = qla4xxx_probe_adapter,
6333 .remove = qla4xxx_remove_adapter,
6334 .err_handler = &qla4xxx_err_handler,
6337 static int __init qla4xxx_module_init(void)
6341 /* Allocate cache for SRBs. */
6342 srb_cachep = kmem_cache_create("qla4xxx_srbs", sizeof(struct srb), 0,
6343 SLAB_HWCACHE_ALIGN, NULL);
6344 if (srb_cachep == NULL) {
6346 "%s: Unable to allocate SRB cache..."
6347 "Failing load!\n", DRIVER_NAME);
6352 /* Derive version string. */
6353 strcpy(qla4xxx_version_str, QLA4XXX_DRIVER_VERSION);
6354 if (ql4xextended_error_logging)
6355 strcat(qla4xxx_version_str, "-debug");
6357 qla4xxx_scsi_transport =
6358 iscsi_register_transport(&qla4xxx_iscsi_transport);
6359 if (!qla4xxx_scsi_transport){
6361 goto release_srb_cache;
6364 ret = pci_register_driver(&qla4xxx_pci_driver);
6366 goto unregister_transport;
6368 printk(KERN_INFO "QLogic iSCSI HBA Driver\n");
6371 unregister_transport:
6372 iscsi_unregister_transport(&qla4xxx_iscsi_transport);
6374 kmem_cache_destroy(srb_cachep);
6379 static void __exit qla4xxx_module_exit(void)
6381 pci_unregister_driver(&qla4xxx_pci_driver);
6382 iscsi_unregister_transport(&qla4xxx_iscsi_transport);
6383 kmem_cache_destroy(srb_cachep);
6386 module_init(qla4xxx_module_init);
6387 module_exit(qla4xxx_module_exit);
6389 MODULE_AUTHOR("QLogic Corporation");
6390 MODULE_DESCRIPTION("QLogic iSCSI HBA Driver");
6391 MODULE_LICENSE("GPL");
6392 MODULE_VERSION(QLA4XXX_DRIVER_VERSION);