2 * QLogic iSCSI HBA Driver
3 * Copyright (c) 2003-2010 QLogic Corporation
5 * See LICENSE.qla4xxx for copyright and licensing details.
7 #include <linux/moduleparam.h>
8 #include <linux/slab.h>
9 #include <linux/blkdev.h>
10 #include <linux/iscsi_boot_sysfs.h>
11 #include <linux/inet.h>
13 #include <scsi/scsi_tcq.h>
14 #include <scsi/scsicam.h>
17 #include "ql4_version.h"
20 #include "ql4_inline.h"
25 static char qla4xxx_version_str[40];
28 * SRB allocation cache
30 static struct kmem_cache *srb_cachep;
33 * Module parameter information and variables
35 int ql4xdisablesysfsboot = 1;
36 module_param(ql4xdisablesysfsboot, int, S_IRUGO | S_IWUSR);
37 MODULE_PARM_DESC(ql4xdisablesysfsboot,
38 " Set to disable exporting boot targets to sysfs.\n"
39 "\t\t 0 - Export boot targets\n"
40 "\t\t 1 - Do not export boot targets (Default)");
42 int ql4xdontresethba = 0;
43 module_param(ql4xdontresethba, int, S_IRUGO | S_IWUSR);
44 MODULE_PARM_DESC(ql4xdontresethba,
45 " Don't reset the HBA for driver recovery.\n"
46 "\t\t 0 - It will reset HBA (Default)\n"
47 "\t\t 1 - It will NOT reset HBA");
49 int ql4xextended_error_logging;
50 module_param(ql4xextended_error_logging, int, S_IRUGO | S_IWUSR);
51 MODULE_PARM_DESC(ql4xextended_error_logging,
52 " Option to enable extended error logging.\n"
53 "\t\t 0 - no logging (Default)\n"
54 "\t\t 2 - debug logging");
56 int ql4xenablemsix = 1;
57 module_param(ql4xenablemsix, int, S_IRUGO|S_IWUSR);
58 MODULE_PARM_DESC(ql4xenablemsix,
59 " Set to enable MSI or MSI-X interrupt mechanism.\n"
60 "\t\t 0 = enable INTx interrupt mechanism.\n"
61 "\t\t 1 = enable MSI-X interrupt mechanism (Default).\n"
62 "\t\t 2 = enable MSI interrupt mechanism.");
64 #define QL4_DEF_QDEPTH 32
65 static int ql4xmaxqdepth = QL4_DEF_QDEPTH;
66 module_param(ql4xmaxqdepth, int, S_IRUGO | S_IWUSR);
67 MODULE_PARM_DESC(ql4xmaxqdepth,
68 " Maximum queue depth to report for target devices.\n"
71 static int ql4xsess_recovery_tmo = QL4_SESS_RECOVERY_TMO;
72 module_param(ql4xsess_recovery_tmo, int, S_IRUGO);
73 MODULE_PARM_DESC(ql4xsess_recovery_tmo,
74 "Target Session Recovery Timeout.\n"
75 "\t\t Default: 120 sec.");
77 static int qla4xxx_wait_for_hba_online(struct scsi_qla_host *ha);
79 * SCSI host template entry points
81 static void qla4xxx_config_dma_addressing(struct scsi_qla_host *ha);
84 * iSCSI template entry points
86 static int qla4xxx_conn_get_param(struct iscsi_cls_conn *conn,
87 enum iscsi_param param, char *buf);
88 static int qla4xxx_host_get_param(struct Scsi_Host *shost,
89 enum iscsi_host_param param, char *buf);
90 static int qla4xxx_iface_set_param(struct Scsi_Host *shost, void *data,
92 static int qla4xxx_get_iface_param(struct iscsi_iface *iface,
93 enum iscsi_param_type param_type,
94 int param, char *buf);
95 static enum blk_eh_timer_return qla4xxx_eh_cmd_timed_out(struct scsi_cmnd *sc);
96 static struct iscsi_endpoint *qla4xxx_ep_connect(struct Scsi_Host *shost,
97 struct sockaddr *dst_addr,
99 static int qla4xxx_ep_poll(struct iscsi_endpoint *ep, int timeout_ms);
100 static void qla4xxx_ep_disconnect(struct iscsi_endpoint *ep);
101 static int qla4xxx_get_ep_param(struct iscsi_endpoint *ep,
102 enum iscsi_param param, char *buf);
103 static int qla4xxx_conn_start(struct iscsi_cls_conn *conn);
104 static struct iscsi_cls_conn *
105 qla4xxx_conn_create(struct iscsi_cls_session *cls_sess, uint32_t conn_idx);
106 static int qla4xxx_conn_bind(struct iscsi_cls_session *cls_session,
107 struct iscsi_cls_conn *cls_conn,
108 uint64_t transport_fd, int is_leading);
109 static void qla4xxx_conn_destroy(struct iscsi_cls_conn *conn);
110 static struct iscsi_cls_session *
111 qla4xxx_session_create(struct iscsi_endpoint *ep, uint16_t cmds_max,
112 uint16_t qdepth, uint32_t initial_cmdsn);
113 static void qla4xxx_session_destroy(struct iscsi_cls_session *sess);
114 static void qla4xxx_task_work(struct work_struct *wdata);
115 static int qla4xxx_alloc_pdu(struct iscsi_task *, uint8_t);
116 static int qla4xxx_task_xmit(struct iscsi_task *);
117 static void qla4xxx_task_cleanup(struct iscsi_task *);
118 static void qla4xxx_fail_session(struct iscsi_cls_session *cls_session);
119 static void qla4xxx_conn_get_stats(struct iscsi_cls_conn *cls_conn,
120 struct iscsi_stats *stats);
122 * SCSI host template entry points
124 static int qla4xxx_queuecommand(struct Scsi_Host *h, struct scsi_cmnd *cmd);
125 static int qla4xxx_eh_abort(struct scsi_cmnd *cmd);
126 static int qla4xxx_eh_device_reset(struct scsi_cmnd *cmd);
127 static int qla4xxx_eh_target_reset(struct scsi_cmnd *cmd);
128 static int qla4xxx_eh_host_reset(struct scsi_cmnd *cmd);
129 static int qla4xxx_slave_alloc(struct scsi_device *device);
130 static int qla4xxx_slave_configure(struct scsi_device *device);
131 static void qla4xxx_slave_destroy(struct scsi_device *sdev);
132 static umode_t ql4_attr_is_visible(int param_type, int param);
133 static int qla4xxx_host_reset(struct Scsi_Host *shost, int reset_type);
135 static struct qla4_8xxx_legacy_intr_set legacy_intr[] =
136 QLA82XX_LEGACY_INTR_CONFIG;
138 static struct scsi_host_template qla4xxx_driver_template = {
139 .module = THIS_MODULE,
141 .proc_name = DRIVER_NAME,
142 .queuecommand = qla4xxx_queuecommand,
144 .eh_abort_handler = qla4xxx_eh_abort,
145 .eh_device_reset_handler = qla4xxx_eh_device_reset,
146 .eh_target_reset_handler = qla4xxx_eh_target_reset,
147 .eh_host_reset_handler = qla4xxx_eh_host_reset,
148 .eh_timed_out = qla4xxx_eh_cmd_timed_out,
150 .slave_configure = qla4xxx_slave_configure,
151 .slave_alloc = qla4xxx_slave_alloc,
152 .slave_destroy = qla4xxx_slave_destroy,
156 .use_clustering = ENABLE_CLUSTERING,
157 .sg_tablesize = SG_ALL,
159 .max_sectors = 0xFFFF,
160 .shost_attrs = qla4xxx_host_attrs,
161 .host_reset = qla4xxx_host_reset,
162 .vendor_id = SCSI_NL_VID_TYPE_PCI | PCI_VENDOR_ID_QLOGIC,
165 static struct iscsi_transport qla4xxx_iscsi_transport = {
166 .owner = THIS_MODULE,
168 .caps = CAP_TEXT_NEGO |
169 CAP_DATA_PATH_OFFLOAD | CAP_HDRDGST |
170 CAP_DATADGST | CAP_LOGIN_OFFLOAD |
172 .attr_is_visible = ql4_attr_is_visible,
173 .create_session = qla4xxx_session_create,
174 .destroy_session = qla4xxx_session_destroy,
175 .start_conn = qla4xxx_conn_start,
176 .create_conn = qla4xxx_conn_create,
177 .bind_conn = qla4xxx_conn_bind,
178 .stop_conn = iscsi_conn_stop,
179 .destroy_conn = qla4xxx_conn_destroy,
180 .set_param = iscsi_set_param,
181 .get_conn_param = qla4xxx_conn_get_param,
182 .get_session_param = iscsi_session_get_param,
183 .get_ep_param = qla4xxx_get_ep_param,
184 .ep_connect = qla4xxx_ep_connect,
185 .ep_poll = qla4xxx_ep_poll,
186 .ep_disconnect = qla4xxx_ep_disconnect,
187 .get_stats = qla4xxx_conn_get_stats,
188 .send_pdu = iscsi_conn_send_pdu,
189 .xmit_task = qla4xxx_task_xmit,
190 .cleanup_task = qla4xxx_task_cleanup,
191 .alloc_pdu = qla4xxx_alloc_pdu,
193 .get_host_param = qla4xxx_host_get_param,
194 .set_iface_param = qla4xxx_iface_set_param,
195 .get_iface_param = qla4xxx_get_iface_param,
196 .bsg_request = qla4xxx_bsg_request,
199 static struct scsi_transport_template *qla4xxx_scsi_transport;
201 static umode_t ql4_attr_is_visible(int param_type, int param)
203 switch (param_type) {
204 case ISCSI_HOST_PARAM:
206 case ISCSI_HOST_PARAM_HWADDRESS:
207 case ISCSI_HOST_PARAM_IPADDRESS:
208 case ISCSI_HOST_PARAM_INITIATOR_NAME:
215 case ISCSI_PARAM_PERSISTENT_ADDRESS:
216 case ISCSI_PARAM_PERSISTENT_PORT:
217 case ISCSI_PARAM_CONN_ADDRESS:
218 case ISCSI_PARAM_CONN_PORT:
219 case ISCSI_PARAM_TARGET_NAME:
220 case ISCSI_PARAM_TPGT:
221 case ISCSI_PARAM_TARGET_ALIAS:
222 case ISCSI_PARAM_MAX_BURST:
223 case ISCSI_PARAM_MAX_R2T:
224 case ISCSI_PARAM_FIRST_BURST:
225 case ISCSI_PARAM_MAX_RECV_DLENGTH:
226 case ISCSI_PARAM_MAX_XMIT_DLENGTH:
227 case ISCSI_PARAM_IFACE_NAME:
232 case ISCSI_NET_PARAM:
234 case ISCSI_NET_PARAM_IPV4_ADDR:
235 case ISCSI_NET_PARAM_IPV4_SUBNET:
236 case ISCSI_NET_PARAM_IPV4_GW:
237 case ISCSI_NET_PARAM_IPV4_BOOTPROTO:
238 case ISCSI_NET_PARAM_IFACE_ENABLE:
239 case ISCSI_NET_PARAM_IPV6_LINKLOCAL:
240 case ISCSI_NET_PARAM_IPV6_ADDR:
241 case ISCSI_NET_PARAM_IPV6_ROUTER:
242 case ISCSI_NET_PARAM_IPV6_ADDR_AUTOCFG:
243 case ISCSI_NET_PARAM_IPV6_LINKLOCAL_AUTOCFG:
244 case ISCSI_NET_PARAM_VLAN_ID:
245 case ISCSI_NET_PARAM_VLAN_PRIORITY:
246 case ISCSI_NET_PARAM_VLAN_ENABLED:
247 case ISCSI_NET_PARAM_MTU:
248 case ISCSI_NET_PARAM_PORT:
258 static int qla4xxx_get_iface_param(struct iscsi_iface *iface,
259 enum iscsi_param_type param_type,
260 int param, char *buf)
262 struct Scsi_Host *shost = iscsi_iface_to_shost(iface);
263 struct scsi_qla_host *ha = to_qla_host(shost);
266 if (param_type != ISCSI_NET_PARAM)
270 case ISCSI_NET_PARAM_IPV4_ADDR:
271 len = sprintf(buf, "%pI4\n", &ha->ip_config.ip_address);
273 case ISCSI_NET_PARAM_IPV4_SUBNET:
274 len = sprintf(buf, "%pI4\n", &ha->ip_config.subnet_mask);
276 case ISCSI_NET_PARAM_IPV4_GW:
277 len = sprintf(buf, "%pI4\n", &ha->ip_config.gateway);
279 case ISCSI_NET_PARAM_IFACE_ENABLE:
280 if (iface->iface_type == ISCSI_IFACE_TYPE_IPV4)
281 len = sprintf(buf, "%s\n",
282 (ha->ip_config.ipv4_options &
283 IPOPT_IPV4_PROTOCOL_ENABLE) ?
284 "enabled" : "disabled");
285 else if (iface->iface_type == ISCSI_IFACE_TYPE_IPV6)
286 len = sprintf(buf, "%s\n",
287 (ha->ip_config.ipv6_options &
288 IPV6_OPT_IPV6_PROTOCOL_ENABLE) ?
289 "enabled" : "disabled");
291 case ISCSI_NET_PARAM_IPV4_BOOTPROTO:
292 len = sprintf(buf, "%s\n",
293 (ha->ip_config.tcp_options & TCPOPT_DHCP_ENABLE) ?
296 case ISCSI_NET_PARAM_IPV6_ADDR:
297 if (iface->iface_num == 0)
298 len = sprintf(buf, "%pI6\n", &ha->ip_config.ipv6_addr0);
299 if (iface->iface_num == 1)
300 len = sprintf(buf, "%pI6\n", &ha->ip_config.ipv6_addr1);
302 case ISCSI_NET_PARAM_IPV6_LINKLOCAL:
303 len = sprintf(buf, "%pI6\n",
304 &ha->ip_config.ipv6_link_local_addr);
306 case ISCSI_NET_PARAM_IPV6_ROUTER:
307 len = sprintf(buf, "%pI6\n",
308 &ha->ip_config.ipv6_default_router_addr);
310 case ISCSI_NET_PARAM_IPV6_ADDR_AUTOCFG:
311 len = sprintf(buf, "%s\n",
312 (ha->ip_config.ipv6_addl_options &
313 IPV6_ADDOPT_NEIGHBOR_DISCOVERY_ADDR_ENABLE) ?
316 case ISCSI_NET_PARAM_IPV6_LINKLOCAL_AUTOCFG:
317 len = sprintf(buf, "%s\n",
318 (ha->ip_config.ipv6_addl_options &
319 IPV6_ADDOPT_AUTOCONFIG_LINK_LOCAL_ADDR) ?
322 case ISCSI_NET_PARAM_VLAN_ID:
323 if (iface->iface_type == ISCSI_IFACE_TYPE_IPV4)
324 len = sprintf(buf, "%d\n",
325 (ha->ip_config.ipv4_vlan_tag &
327 else if (iface->iface_type == ISCSI_IFACE_TYPE_IPV6)
328 len = sprintf(buf, "%d\n",
329 (ha->ip_config.ipv6_vlan_tag &
332 case ISCSI_NET_PARAM_VLAN_PRIORITY:
333 if (iface->iface_type == ISCSI_IFACE_TYPE_IPV4)
334 len = sprintf(buf, "%d\n",
335 ((ha->ip_config.ipv4_vlan_tag >> 13) &
336 ISCSI_MAX_VLAN_PRIORITY));
337 else if (iface->iface_type == ISCSI_IFACE_TYPE_IPV6)
338 len = sprintf(buf, "%d\n",
339 ((ha->ip_config.ipv6_vlan_tag >> 13) &
340 ISCSI_MAX_VLAN_PRIORITY));
342 case ISCSI_NET_PARAM_VLAN_ENABLED:
343 if (iface->iface_type == ISCSI_IFACE_TYPE_IPV4)
344 len = sprintf(buf, "%s\n",
345 (ha->ip_config.ipv4_options &
346 IPOPT_VLAN_TAGGING_ENABLE) ?
347 "enabled" : "disabled");
348 else if (iface->iface_type == ISCSI_IFACE_TYPE_IPV6)
349 len = sprintf(buf, "%s\n",
350 (ha->ip_config.ipv6_options &
351 IPV6_OPT_VLAN_TAGGING_ENABLE) ?
352 "enabled" : "disabled");
354 case ISCSI_NET_PARAM_MTU:
355 len = sprintf(buf, "%d\n", ha->ip_config.eth_mtu_size);
357 case ISCSI_NET_PARAM_PORT:
358 if (iface->iface_type == ISCSI_IFACE_TYPE_IPV4)
359 len = sprintf(buf, "%d\n", ha->ip_config.ipv4_port);
360 else if (iface->iface_type == ISCSI_IFACE_TYPE_IPV6)
361 len = sprintf(buf, "%d\n", ha->ip_config.ipv6_port);
370 static struct iscsi_endpoint *
371 qla4xxx_ep_connect(struct Scsi_Host *shost, struct sockaddr *dst_addr,
375 struct iscsi_endpoint *ep;
376 struct qla_endpoint *qla_ep;
377 struct scsi_qla_host *ha;
378 struct sockaddr_in *addr;
379 struct sockaddr_in6 *addr6;
381 DEBUG2(printk(KERN_INFO "Func: %s\n", __func__));
384 printk(KERN_ERR "%s: shost is NULL\n",
389 ha = iscsi_host_priv(shost);
391 ep = iscsi_create_endpoint(sizeof(struct qla_endpoint));
397 qla_ep = ep->dd_data;
398 memset(qla_ep, 0, sizeof(struct qla_endpoint));
399 if (dst_addr->sa_family == AF_INET) {
400 memcpy(&qla_ep->dst_addr, dst_addr, sizeof(struct sockaddr_in));
401 addr = (struct sockaddr_in *)&qla_ep->dst_addr;
402 DEBUG2(ql4_printk(KERN_INFO, ha, "%s: %pI4\n", __func__,
403 (char *)&addr->sin_addr));
404 } else if (dst_addr->sa_family == AF_INET6) {
405 memcpy(&qla_ep->dst_addr, dst_addr,
406 sizeof(struct sockaddr_in6));
407 addr6 = (struct sockaddr_in6 *)&qla_ep->dst_addr;
408 DEBUG2(ql4_printk(KERN_INFO, ha, "%s: %pI6\n", __func__,
409 (char *)&addr6->sin6_addr));
412 qla_ep->host = shost;
417 static int qla4xxx_ep_poll(struct iscsi_endpoint *ep, int timeout_ms)
419 struct qla_endpoint *qla_ep;
420 struct scsi_qla_host *ha;
423 DEBUG2(printk(KERN_INFO "Func: %s\n", __func__));
424 qla_ep = ep->dd_data;
425 ha = to_qla_host(qla_ep->host);
427 if (adapter_up(ha) && !test_bit(AF_BUILD_DDB_LIST, &ha->flags))
433 static void qla4xxx_ep_disconnect(struct iscsi_endpoint *ep)
435 DEBUG2(printk(KERN_INFO "Func: %s\n", __func__));
436 iscsi_destroy_endpoint(ep);
439 static int qla4xxx_get_ep_param(struct iscsi_endpoint *ep,
440 enum iscsi_param param,
443 struct qla_endpoint *qla_ep = ep->dd_data;
444 struct sockaddr *dst_addr;
446 DEBUG2(printk(KERN_INFO "Func: %s\n", __func__));
449 case ISCSI_PARAM_CONN_PORT:
450 case ISCSI_PARAM_CONN_ADDRESS:
454 dst_addr = (struct sockaddr *)&qla_ep->dst_addr;
458 return iscsi_conn_get_addr_param((struct sockaddr_storage *)
459 &qla_ep->dst_addr, param, buf);
465 static void qla4xxx_conn_get_stats(struct iscsi_cls_conn *cls_conn,
466 struct iscsi_stats *stats)
468 struct iscsi_session *sess;
469 struct iscsi_cls_session *cls_sess;
470 struct ddb_entry *ddb_entry;
471 struct scsi_qla_host *ha;
472 struct ql_iscsi_stats *ql_iscsi_stats;
475 dma_addr_t iscsi_stats_dma;
477 DEBUG2(printk(KERN_INFO "Func: %s\n", __func__));
479 cls_sess = iscsi_conn_to_session(cls_conn);
480 sess = cls_sess->dd_data;
481 ddb_entry = sess->dd_data;
484 stats_size = PAGE_ALIGN(sizeof(struct ql_iscsi_stats));
485 /* Allocate memory */
486 ql_iscsi_stats = dma_alloc_coherent(&ha->pdev->dev, stats_size,
487 &iscsi_stats_dma, GFP_KERNEL);
488 if (!ql_iscsi_stats) {
489 ql4_printk(KERN_ERR, ha,
490 "Unable to allocate memory for iscsi stats\n");
494 ret = qla4xxx_get_mgmt_data(ha, ddb_entry->fw_ddb_index, stats_size,
496 if (ret != QLA_SUCCESS) {
497 ql4_printk(KERN_ERR, ha,
498 "Unable to retreive iscsi stats\n");
503 stats->txdata_octets = le64_to_cpu(ql_iscsi_stats->tx_data_octets);
504 stats->rxdata_octets = le64_to_cpu(ql_iscsi_stats->rx_data_octets);
506 stats->noptx_pdus = le32_to_cpu(ql_iscsi_stats->tx_nopout_pdus);
507 stats->scsicmd_pdus = le32_to_cpu(ql_iscsi_stats->tx_scsi_cmd_pdus);
508 stats->tmfcmd_pdus = le32_to_cpu(ql_iscsi_stats->tx_tmf_cmd_pdus);
509 stats->login_pdus = le32_to_cpu(ql_iscsi_stats->tx_login_cmd_pdus);
510 stats->text_pdus = le32_to_cpu(ql_iscsi_stats->tx_text_cmd_pdus);
511 stats->dataout_pdus = le32_to_cpu(ql_iscsi_stats->tx_scsi_write_pdus);
512 stats->logout_pdus = le32_to_cpu(ql_iscsi_stats->tx_logout_cmd_pdus);
513 stats->snack_pdus = le32_to_cpu(ql_iscsi_stats->tx_snack_req_pdus);
515 stats->noprx_pdus = le32_to_cpu(ql_iscsi_stats->rx_nopin_pdus);
516 stats->scsirsp_pdus = le32_to_cpu(ql_iscsi_stats->rx_scsi_resp_pdus);
517 stats->tmfrsp_pdus = le32_to_cpu(ql_iscsi_stats->rx_tmf_resp_pdus);
518 stats->textrsp_pdus = le32_to_cpu(ql_iscsi_stats->rx_text_resp_pdus);
519 stats->datain_pdus = le32_to_cpu(ql_iscsi_stats->rx_scsi_read_pdus);
520 stats->logoutrsp_pdus =
521 le32_to_cpu(ql_iscsi_stats->rx_logout_resp_pdus);
522 stats->r2t_pdus = le32_to_cpu(ql_iscsi_stats->rx_r2t_pdus);
523 stats->async_pdus = le32_to_cpu(ql_iscsi_stats->rx_async_pdus);
524 stats->rjt_pdus = le32_to_cpu(ql_iscsi_stats->rx_reject_pdus);
527 dma_free_coherent(&ha->pdev->dev, stats_size, ql_iscsi_stats,
533 static enum blk_eh_timer_return qla4xxx_eh_cmd_timed_out(struct scsi_cmnd *sc)
535 struct iscsi_cls_session *session;
536 struct iscsi_session *sess;
538 enum blk_eh_timer_return ret = BLK_EH_NOT_HANDLED;
540 session = starget_to_session(scsi_target(sc->device));
541 sess = session->dd_data;
543 spin_lock_irqsave(&session->lock, flags);
544 if (session->state == ISCSI_SESSION_FAILED)
545 ret = BLK_EH_RESET_TIMER;
546 spin_unlock_irqrestore(&session->lock, flags);
551 static int qla4xxx_host_get_param(struct Scsi_Host *shost,
552 enum iscsi_host_param param, char *buf)
554 struct scsi_qla_host *ha = to_qla_host(shost);
558 case ISCSI_HOST_PARAM_HWADDRESS:
559 len = sysfs_format_mac(buf, ha->my_mac, MAC_ADDR_LEN);
561 case ISCSI_HOST_PARAM_IPADDRESS:
562 len = sprintf(buf, "%pI4\n", &ha->ip_config.ip_address);
564 case ISCSI_HOST_PARAM_INITIATOR_NAME:
565 len = sprintf(buf, "%s\n", ha->name_string);
574 static void qla4xxx_create_ipv4_iface(struct scsi_qla_host *ha)
580 ha->iface_ipv4 = iscsi_create_iface(ha->host,
581 &qla4xxx_iscsi_transport,
582 ISCSI_IFACE_TYPE_IPV4, 0, 0);
584 ql4_printk(KERN_ERR, ha, "Could not create IPv4 iSCSI "
588 static void qla4xxx_create_ipv6_iface(struct scsi_qla_host *ha)
590 if (!ha->iface_ipv6_0)
592 ha->iface_ipv6_0 = iscsi_create_iface(ha->host,
593 &qla4xxx_iscsi_transport,
594 ISCSI_IFACE_TYPE_IPV6, 0,
596 if (!ha->iface_ipv6_0)
597 ql4_printk(KERN_ERR, ha, "Could not create IPv6 iSCSI "
600 if (!ha->iface_ipv6_1)
602 ha->iface_ipv6_1 = iscsi_create_iface(ha->host,
603 &qla4xxx_iscsi_transport,
604 ISCSI_IFACE_TYPE_IPV6, 1,
606 if (!ha->iface_ipv6_1)
607 ql4_printk(KERN_ERR, ha, "Could not create IPv6 iSCSI "
611 static void qla4xxx_create_ifaces(struct scsi_qla_host *ha)
613 if (ha->ip_config.ipv4_options & IPOPT_IPV4_PROTOCOL_ENABLE)
614 qla4xxx_create_ipv4_iface(ha);
616 if (ha->ip_config.ipv6_options & IPV6_OPT_IPV6_PROTOCOL_ENABLE)
617 qla4xxx_create_ipv6_iface(ha);
620 static void qla4xxx_destroy_ipv4_iface(struct scsi_qla_host *ha)
622 if (ha->iface_ipv4) {
623 iscsi_destroy_iface(ha->iface_ipv4);
624 ha->iface_ipv4 = NULL;
628 static void qla4xxx_destroy_ipv6_iface(struct scsi_qla_host *ha)
630 if (ha->iface_ipv6_0) {
631 iscsi_destroy_iface(ha->iface_ipv6_0);
632 ha->iface_ipv6_0 = NULL;
634 if (ha->iface_ipv6_1) {
635 iscsi_destroy_iface(ha->iface_ipv6_1);
636 ha->iface_ipv6_1 = NULL;
640 static void qla4xxx_destroy_ifaces(struct scsi_qla_host *ha)
642 qla4xxx_destroy_ipv4_iface(ha);
643 qla4xxx_destroy_ipv6_iface(ha);
646 static void qla4xxx_set_ipv6(struct scsi_qla_host *ha,
647 struct iscsi_iface_param_info *iface_param,
648 struct addr_ctrl_blk *init_fw_cb)
651 * iface_num 0 is valid for IPv6 Addr, linklocal, router, autocfg.
652 * iface_num 1 is valid only for IPv6 Addr.
654 switch (iface_param->param) {
655 case ISCSI_NET_PARAM_IPV6_ADDR:
656 if (iface_param->iface_num & 0x1)
658 memcpy(init_fw_cb->ipv6_addr1, iface_param->value,
659 sizeof(init_fw_cb->ipv6_addr1));
662 memcpy(init_fw_cb->ipv6_addr0, iface_param->value,
663 sizeof(init_fw_cb->ipv6_addr0));
665 case ISCSI_NET_PARAM_IPV6_LINKLOCAL:
666 if (iface_param->iface_num & 0x1)
668 memcpy(init_fw_cb->ipv6_if_id, &iface_param->value[8],
669 sizeof(init_fw_cb->ipv6_if_id));
671 case ISCSI_NET_PARAM_IPV6_ROUTER:
672 if (iface_param->iface_num & 0x1)
674 memcpy(init_fw_cb->ipv6_dflt_rtr_addr, iface_param->value,
675 sizeof(init_fw_cb->ipv6_dflt_rtr_addr));
677 case ISCSI_NET_PARAM_IPV6_ADDR_AUTOCFG:
678 /* Autocfg applies to even interface */
679 if (iface_param->iface_num & 0x1)
682 if (iface_param->value[0] == ISCSI_IPV6_AUTOCFG_DISABLE)
683 init_fw_cb->ipv6_addtl_opts &=
685 ~IPV6_ADDOPT_NEIGHBOR_DISCOVERY_ADDR_ENABLE);
686 else if (iface_param->value[0] == ISCSI_IPV6_AUTOCFG_ND_ENABLE)
687 init_fw_cb->ipv6_addtl_opts |=
689 IPV6_ADDOPT_NEIGHBOR_DISCOVERY_ADDR_ENABLE);
691 ql4_printk(KERN_ERR, ha, "Invalid autocfg setting for "
694 case ISCSI_NET_PARAM_IPV6_LINKLOCAL_AUTOCFG:
695 /* Autocfg applies to even interface */
696 if (iface_param->iface_num & 0x1)
699 if (iface_param->value[0] ==
700 ISCSI_IPV6_LINKLOCAL_AUTOCFG_ENABLE)
701 init_fw_cb->ipv6_addtl_opts |= cpu_to_le16(
702 IPV6_ADDOPT_AUTOCONFIG_LINK_LOCAL_ADDR);
703 else if (iface_param->value[0] ==
704 ISCSI_IPV6_LINKLOCAL_AUTOCFG_DISABLE)
705 init_fw_cb->ipv6_addtl_opts &= cpu_to_le16(
706 ~IPV6_ADDOPT_AUTOCONFIG_LINK_LOCAL_ADDR);
708 ql4_printk(KERN_ERR, ha, "Invalid autocfg setting for "
709 "IPv6 linklocal addr\n");
711 case ISCSI_NET_PARAM_IPV6_ROUTER_AUTOCFG:
712 /* Autocfg applies to even interface */
713 if (iface_param->iface_num & 0x1)
716 if (iface_param->value[0] == ISCSI_IPV6_ROUTER_AUTOCFG_ENABLE)
717 memset(init_fw_cb->ipv6_dflt_rtr_addr, 0,
718 sizeof(init_fw_cb->ipv6_dflt_rtr_addr));
720 case ISCSI_NET_PARAM_IFACE_ENABLE:
721 if (iface_param->value[0] == ISCSI_IFACE_ENABLE) {
722 init_fw_cb->ipv6_opts |=
723 cpu_to_le16(IPV6_OPT_IPV6_PROTOCOL_ENABLE);
724 qla4xxx_create_ipv6_iface(ha);
726 init_fw_cb->ipv6_opts &=
727 cpu_to_le16(~IPV6_OPT_IPV6_PROTOCOL_ENABLE &
729 qla4xxx_destroy_ipv6_iface(ha);
732 case ISCSI_NET_PARAM_VLAN_TAG:
733 if (iface_param->len != sizeof(init_fw_cb->ipv6_vlan_tag))
735 init_fw_cb->ipv6_vlan_tag =
736 cpu_to_be16(*(uint16_t *)iface_param->value);
738 case ISCSI_NET_PARAM_VLAN_ENABLED:
739 if (iface_param->value[0] == ISCSI_VLAN_ENABLE)
740 init_fw_cb->ipv6_opts |=
741 cpu_to_le16(IPV6_OPT_VLAN_TAGGING_ENABLE);
743 init_fw_cb->ipv6_opts &=
744 cpu_to_le16(~IPV6_OPT_VLAN_TAGGING_ENABLE);
746 case ISCSI_NET_PARAM_MTU:
747 init_fw_cb->eth_mtu_size =
748 cpu_to_le16(*(uint16_t *)iface_param->value);
750 case ISCSI_NET_PARAM_PORT:
751 /* Autocfg applies to even interface */
752 if (iface_param->iface_num & 0x1)
755 init_fw_cb->ipv6_port =
756 cpu_to_le16(*(uint16_t *)iface_param->value);
759 ql4_printk(KERN_ERR, ha, "Unknown IPv6 param = %d\n",
765 static void qla4xxx_set_ipv4(struct scsi_qla_host *ha,
766 struct iscsi_iface_param_info *iface_param,
767 struct addr_ctrl_blk *init_fw_cb)
769 switch (iface_param->param) {
770 case ISCSI_NET_PARAM_IPV4_ADDR:
771 memcpy(init_fw_cb->ipv4_addr, iface_param->value,
772 sizeof(init_fw_cb->ipv4_addr));
774 case ISCSI_NET_PARAM_IPV4_SUBNET:
775 memcpy(init_fw_cb->ipv4_subnet, iface_param->value,
776 sizeof(init_fw_cb->ipv4_subnet));
778 case ISCSI_NET_PARAM_IPV4_GW:
779 memcpy(init_fw_cb->ipv4_gw_addr, iface_param->value,
780 sizeof(init_fw_cb->ipv4_gw_addr));
782 case ISCSI_NET_PARAM_IPV4_BOOTPROTO:
783 if (iface_param->value[0] == ISCSI_BOOTPROTO_DHCP)
784 init_fw_cb->ipv4_tcp_opts |=
785 cpu_to_le16(TCPOPT_DHCP_ENABLE);
786 else if (iface_param->value[0] == ISCSI_BOOTPROTO_STATIC)
787 init_fw_cb->ipv4_tcp_opts &=
788 cpu_to_le16(~TCPOPT_DHCP_ENABLE);
790 ql4_printk(KERN_ERR, ha, "Invalid IPv4 bootproto\n");
792 case ISCSI_NET_PARAM_IFACE_ENABLE:
793 if (iface_param->value[0] == ISCSI_IFACE_ENABLE) {
794 init_fw_cb->ipv4_ip_opts |=
795 cpu_to_le16(IPOPT_IPV4_PROTOCOL_ENABLE);
796 qla4xxx_create_ipv4_iface(ha);
798 init_fw_cb->ipv4_ip_opts &=
799 cpu_to_le16(~IPOPT_IPV4_PROTOCOL_ENABLE &
801 qla4xxx_destroy_ipv4_iface(ha);
804 case ISCSI_NET_PARAM_VLAN_TAG:
805 if (iface_param->len != sizeof(init_fw_cb->ipv4_vlan_tag))
807 init_fw_cb->ipv4_vlan_tag =
808 cpu_to_be16(*(uint16_t *)iface_param->value);
810 case ISCSI_NET_PARAM_VLAN_ENABLED:
811 if (iface_param->value[0] == ISCSI_VLAN_ENABLE)
812 init_fw_cb->ipv4_ip_opts |=
813 cpu_to_le16(IPOPT_VLAN_TAGGING_ENABLE);
815 init_fw_cb->ipv4_ip_opts &=
816 cpu_to_le16(~IPOPT_VLAN_TAGGING_ENABLE);
818 case ISCSI_NET_PARAM_MTU:
819 init_fw_cb->eth_mtu_size =
820 cpu_to_le16(*(uint16_t *)iface_param->value);
822 case ISCSI_NET_PARAM_PORT:
823 init_fw_cb->ipv4_port =
824 cpu_to_le16(*(uint16_t *)iface_param->value);
827 ql4_printk(KERN_ERR, ha, "Unknown IPv4 param = %d\n",
834 qla4xxx_initcb_to_acb(struct addr_ctrl_blk *init_fw_cb)
836 struct addr_ctrl_blk_def *acb;
837 acb = (struct addr_ctrl_blk_def *)init_fw_cb;
838 memset(acb->reserved1, 0, sizeof(acb->reserved1));
839 memset(acb->reserved2, 0, sizeof(acb->reserved2));
840 memset(acb->reserved3, 0, sizeof(acb->reserved3));
841 memset(acb->reserved4, 0, sizeof(acb->reserved4));
842 memset(acb->reserved5, 0, sizeof(acb->reserved5));
843 memset(acb->reserved6, 0, sizeof(acb->reserved6));
844 memset(acb->reserved7, 0, sizeof(acb->reserved7));
845 memset(acb->reserved8, 0, sizeof(acb->reserved8));
846 memset(acb->reserved9, 0, sizeof(acb->reserved9));
847 memset(acb->reserved10, 0, sizeof(acb->reserved10));
848 memset(acb->reserved11, 0, sizeof(acb->reserved11));
849 memset(acb->reserved12, 0, sizeof(acb->reserved12));
850 memset(acb->reserved13, 0, sizeof(acb->reserved13));
851 memset(acb->reserved14, 0, sizeof(acb->reserved14));
852 memset(acb->reserved15, 0, sizeof(acb->reserved15));
856 qla4xxx_iface_set_param(struct Scsi_Host *shost, void *data, uint32_t len)
858 struct scsi_qla_host *ha = to_qla_host(shost);
860 struct iscsi_iface_param_info *iface_param = NULL;
861 struct addr_ctrl_blk *init_fw_cb = NULL;
862 dma_addr_t init_fw_cb_dma;
863 uint32_t mbox_cmd[MBOX_REG_COUNT];
864 uint32_t mbox_sts[MBOX_REG_COUNT];
868 init_fw_cb = dma_alloc_coherent(&ha->pdev->dev,
869 sizeof(struct addr_ctrl_blk),
870 &init_fw_cb_dma, GFP_KERNEL);
872 ql4_printk(KERN_ERR, ha, "%s: Unable to alloc init_cb\n",
877 memset(init_fw_cb, 0, sizeof(struct addr_ctrl_blk));
878 memset(&mbox_cmd, 0, sizeof(mbox_cmd));
879 memset(&mbox_sts, 0, sizeof(mbox_sts));
881 if (qla4xxx_get_ifcb(ha, &mbox_cmd[0], &mbox_sts[0], init_fw_cb_dma)) {
882 ql4_printk(KERN_ERR, ha, "%s: get ifcb failed\n", __func__);
884 goto exit_init_fw_cb;
887 nla_for_each_attr(attr, data, len, rem) {
888 iface_param = nla_data(attr);
890 if (iface_param->param_type != ISCSI_NET_PARAM)
893 switch (iface_param->iface_type) {
894 case ISCSI_IFACE_TYPE_IPV4:
895 switch (iface_param->iface_num) {
897 qla4xxx_set_ipv4(ha, iface_param, init_fw_cb);
900 /* Cannot have more than one IPv4 interface */
901 ql4_printk(KERN_ERR, ha, "Invalid IPv4 iface "
903 iface_param->iface_num);
907 case ISCSI_IFACE_TYPE_IPV6:
908 switch (iface_param->iface_num) {
911 qla4xxx_set_ipv6(ha, iface_param, init_fw_cb);
914 /* Cannot have more than two IPv6 interface */
915 ql4_printk(KERN_ERR, ha, "Invalid IPv6 iface "
917 iface_param->iface_num);
922 ql4_printk(KERN_ERR, ha, "Invalid iface type\n");
927 init_fw_cb->cookie = cpu_to_le32(0x11BEAD5A);
929 rval = qla4xxx_set_flash(ha, init_fw_cb_dma, FLASH_SEGMENT_IFCB,
930 sizeof(struct addr_ctrl_blk),
931 FLASH_OPT_RMW_COMMIT);
932 if (rval != QLA_SUCCESS) {
933 ql4_printk(KERN_ERR, ha, "%s: set flash mbx failed\n",
936 goto exit_init_fw_cb;
939 rval = qla4xxx_disable_acb(ha);
940 if (rval != QLA_SUCCESS) {
941 ql4_printk(KERN_ERR, ha, "%s: disable acb mbx failed\n",
944 goto exit_init_fw_cb;
947 wait_for_completion_timeout(&ha->disable_acb_comp,
948 DISABLE_ACB_TOV * HZ);
950 qla4xxx_initcb_to_acb(init_fw_cb);
952 rval = qla4xxx_set_acb(ha, &mbox_cmd[0], &mbox_sts[0], init_fw_cb_dma);
953 if (rval != QLA_SUCCESS) {
954 ql4_printk(KERN_ERR, ha, "%s: set acb mbx failed\n",
957 goto exit_init_fw_cb;
960 memset(init_fw_cb, 0, sizeof(struct addr_ctrl_blk));
961 qla4xxx_update_local_ifcb(ha, &mbox_cmd[0], &mbox_sts[0], init_fw_cb,
965 dma_free_coherent(&ha->pdev->dev, sizeof(struct addr_ctrl_blk),
966 init_fw_cb, init_fw_cb_dma);
971 static int qla4xxx_conn_get_param(struct iscsi_cls_conn *cls_conn,
972 enum iscsi_param param, char *buf)
974 struct iscsi_conn *conn;
975 struct qla_conn *qla_conn;
976 struct sockaddr *dst_addr;
979 conn = cls_conn->dd_data;
980 qla_conn = conn->dd_data;
981 dst_addr = &qla_conn->qla_ep->dst_addr;
984 case ISCSI_PARAM_CONN_PORT:
985 case ISCSI_PARAM_CONN_ADDRESS:
986 return iscsi_conn_get_addr_param((struct sockaddr_storage *)
987 dst_addr, param, buf);
989 return iscsi_conn_get_param(cls_conn, param, buf);
996 int qla4xxx_get_ddb_index(struct scsi_qla_host *ha, uint16_t *ddb_index)
998 uint32_t mbx_sts = 0;
999 uint16_t tmp_ddb_index;
1003 tmp_ddb_index = find_first_zero_bit(ha->ddb_idx_map, MAX_DDB_ENTRIES);
1005 if (tmp_ddb_index >= MAX_DDB_ENTRIES) {
1006 DEBUG2(ql4_printk(KERN_INFO, ha,
1007 "Free DDB index not available\n"));
1009 goto exit_get_ddb_index;
1012 if (test_and_set_bit(tmp_ddb_index, ha->ddb_idx_map))
1015 DEBUG2(ql4_printk(KERN_INFO, ha,
1016 "Found a free DDB index at %d\n", tmp_ddb_index));
1017 ret = qla4xxx_req_ddb_entry(ha, tmp_ddb_index, &mbx_sts);
1018 if (ret == QLA_ERROR) {
1019 if (mbx_sts == MBOX_STS_COMMAND_ERROR) {
1020 ql4_printk(KERN_INFO, ha,
1021 "DDB index = %d not available trying next\n",
1025 DEBUG2(ql4_printk(KERN_INFO, ha,
1026 "Free FW DDB not available\n"));
1029 *ddb_index = tmp_ddb_index;
1035 static int qla4xxx_match_ipaddress(struct scsi_qla_host *ha,
1036 struct ddb_entry *ddb_entry,
1037 char *existing_ipaddr,
1040 uint8_t dst_ipaddr[IPv6_ADDR_LEN];
1041 char formatted_ipaddr[DDB_IPADDR_LEN];
1042 int status = QLA_SUCCESS, ret = 0;
1044 if (ddb_entry->fw_ddb_entry.options & DDB_OPT_IPV6_DEVICE) {
1045 ret = in6_pton(user_ipaddr, strlen(user_ipaddr), dst_ipaddr,
1051 ret = sprintf(formatted_ipaddr, "%pI6", dst_ipaddr);
1053 ret = in4_pton(user_ipaddr, strlen(user_ipaddr), dst_ipaddr,
1059 ret = sprintf(formatted_ipaddr, "%pI4", dst_ipaddr);
1062 if (strcmp(existing_ipaddr, formatted_ipaddr))
1069 static int qla4xxx_match_fwdb_session(struct scsi_qla_host *ha,
1070 struct iscsi_cls_conn *cls_conn)
1072 int idx = 0, max_ddbs, rval;
1073 struct iscsi_cls_session *cls_sess = iscsi_conn_to_session(cls_conn);
1074 struct iscsi_session *sess, *existing_sess;
1075 struct iscsi_conn *conn, *existing_conn;
1076 struct ddb_entry *ddb_entry;
1078 sess = cls_sess->dd_data;
1079 conn = cls_conn->dd_data;
1081 if (sess->targetname == NULL ||
1082 conn->persistent_address == NULL ||
1083 conn->persistent_port == 0)
1086 max_ddbs = is_qla40XX(ha) ? MAX_DEV_DB_ENTRIES_40XX :
1089 for (idx = 0; idx < max_ddbs; idx++) {
1090 ddb_entry = qla4xxx_lookup_ddb_by_fw_index(ha, idx);
1091 if (ddb_entry == NULL)
1094 if (ddb_entry->ddb_type != FLASH_DDB)
1097 existing_sess = ddb_entry->sess->dd_data;
1098 existing_conn = ddb_entry->conn->dd_data;
1100 if (existing_sess->targetname == NULL ||
1101 existing_conn->persistent_address == NULL ||
1102 existing_conn->persistent_port == 0)
1105 DEBUG2(ql4_printk(KERN_INFO, ha,
1106 "IQN = %s User IQN = %s\n",
1107 existing_sess->targetname,
1110 DEBUG2(ql4_printk(KERN_INFO, ha,
1111 "IP = %s User IP = %s\n",
1112 existing_conn->persistent_address,
1113 conn->persistent_address));
1115 DEBUG2(ql4_printk(KERN_INFO, ha,
1116 "Port = %d User Port = %d\n",
1117 existing_conn->persistent_port,
1118 conn->persistent_port));
1120 if (strcmp(existing_sess->targetname, sess->targetname))
1122 rval = qla4xxx_match_ipaddress(ha, ddb_entry,
1123 existing_conn->persistent_address,
1124 conn->persistent_address);
1125 if (rval == QLA_ERROR)
1127 if (existing_conn->persistent_port != conn->persistent_port)
1132 if (idx == max_ddbs)
1135 DEBUG2(ql4_printk(KERN_INFO, ha,
1136 "Match found in fwdb sessions\n"));
1140 static struct iscsi_cls_session *
1141 qla4xxx_session_create(struct iscsi_endpoint *ep,
1142 uint16_t cmds_max, uint16_t qdepth,
1143 uint32_t initial_cmdsn)
1145 struct iscsi_cls_session *cls_sess;
1146 struct scsi_qla_host *ha;
1147 struct qla_endpoint *qla_ep;
1148 struct ddb_entry *ddb_entry;
1150 struct iscsi_session *sess;
1151 struct sockaddr *dst_addr;
1154 DEBUG2(printk(KERN_INFO "Func: %s\n", __func__));
1156 printk(KERN_ERR "qla4xxx: missing ep.\n");
1160 qla_ep = ep->dd_data;
1161 dst_addr = (struct sockaddr *)&qla_ep->dst_addr;
1162 ha = to_qla_host(qla_ep->host);
1164 ret = qla4xxx_get_ddb_index(ha, &ddb_index);
1165 if (ret == QLA_ERROR)
1168 cls_sess = iscsi_session_setup(&qla4xxx_iscsi_transport, qla_ep->host,
1169 cmds_max, sizeof(struct ddb_entry),
1170 sizeof(struct ql4_task_data),
1171 initial_cmdsn, ddb_index);
1175 sess = cls_sess->dd_data;
1176 ddb_entry = sess->dd_data;
1177 ddb_entry->fw_ddb_index = ddb_index;
1178 ddb_entry->fw_ddb_device_state = DDB_DS_NO_CONNECTION_ACTIVE;
1180 ddb_entry->sess = cls_sess;
1181 ddb_entry->unblock_sess = qla4xxx_unblock_ddb;
1182 ddb_entry->ddb_change = qla4xxx_ddb_change;
1183 cls_sess->recovery_tmo = ql4xsess_recovery_tmo;
1184 ha->fw_ddb_index_map[ddb_entry->fw_ddb_index] = ddb_entry;
1190 static void qla4xxx_session_destroy(struct iscsi_cls_session *cls_sess)
1192 struct iscsi_session *sess;
1193 struct ddb_entry *ddb_entry;
1194 struct scsi_qla_host *ha;
1195 unsigned long flags;
1197 DEBUG2(printk(KERN_INFO "Func: %s\n", __func__));
1198 sess = cls_sess->dd_data;
1199 ddb_entry = sess->dd_data;
1202 qla4xxx_clear_ddb_entry(ha, ddb_entry->fw_ddb_index);
1204 spin_lock_irqsave(&ha->hardware_lock, flags);
1205 qla4xxx_free_ddb(ha, ddb_entry);
1206 spin_unlock_irqrestore(&ha->hardware_lock, flags);
1207 iscsi_session_teardown(cls_sess);
1210 static struct iscsi_cls_conn *
1211 qla4xxx_conn_create(struct iscsi_cls_session *cls_sess, uint32_t conn_idx)
1213 struct iscsi_cls_conn *cls_conn;
1214 struct iscsi_session *sess;
1215 struct ddb_entry *ddb_entry;
1217 DEBUG2(printk(KERN_INFO "Func: %s\n", __func__));
1218 cls_conn = iscsi_conn_setup(cls_sess, sizeof(struct qla_conn),
1223 sess = cls_sess->dd_data;
1224 ddb_entry = sess->dd_data;
1225 ddb_entry->conn = cls_conn;
1230 static int qla4xxx_conn_bind(struct iscsi_cls_session *cls_session,
1231 struct iscsi_cls_conn *cls_conn,
1232 uint64_t transport_fd, int is_leading)
1234 struct iscsi_conn *conn;
1235 struct qla_conn *qla_conn;
1236 struct iscsi_endpoint *ep;
1238 DEBUG2(printk(KERN_INFO "Func: %s\n", __func__));
1240 if (iscsi_conn_bind(cls_session, cls_conn, is_leading))
1242 ep = iscsi_lookup_endpoint(transport_fd);
1243 conn = cls_conn->dd_data;
1244 qla_conn = conn->dd_data;
1245 qla_conn->qla_ep = ep->dd_data;
1249 static int qla4xxx_conn_start(struct iscsi_cls_conn *cls_conn)
1251 struct iscsi_cls_session *cls_sess = iscsi_conn_to_session(cls_conn);
1252 struct iscsi_session *sess;
1253 struct ddb_entry *ddb_entry;
1254 struct scsi_qla_host *ha;
1255 struct dev_db_entry *fw_ddb_entry = NULL;
1256 dma_addr_t fw_ddb_entry_dma;
1257 uint32_t mbx_sts = 0;
1259 int status = QLA_SUCCESS;
1261 DEBUG2(printk(KERN_INFO "Func: %s\n", __func__));
1262 sess = cls_sess->dd_data;
1263 ddb_entry = sess->dd_data;
1266 /* Check if we have matching FW DDB, if yes then do not
1267 * login to this target. This could cause target to logout previous
1270 ret = qla4xxx_match_fwdb_session(ha, cls_conn);
1271 if (ret == QLA_SUCCESS) {
1272 ql4_printk(KERN_INFO, ha,
1273 "Session already exist in FW.\n");
1275 goto exit_conn_start;
1278 fw_ddb_entry = dma_alloc_coherent(&ha->pdev->dev, sizeof(*fw_ddb_entry),
1279 &fw_ddb_entry_dma, GFP_KERNEL);
1280 if (!fw_ddb_entry) {
1281 ql4_printk(KERN_ERR, ha,
1282 "%s: Unable to allocate dma buffer\n", __func__);
1284 goto exit_conn_start;
1287 ret = qla4xxx_set_param_ddbentry(ha, ddb_entry, cls_conn, &mbx_sts);
1289 /* If iscsid is stopped and started then no need to do
1290 * set param again since ddb state will be already
1291 * active and FW does not allow set ddb to an
1295 if (ddb_entry->fw_ddb_device_state ==
1296 DDB_DS_SESSION_ACTIVE) {
1297 ddb_entry->unblock_sess(ddb_entry->sess);
1298 goto exit_set_param;
1301 ql4_printk(KERN_ERR, ha, "%s: Failed set param for index[%d]\n",
1302 __func__, ddb_entry->fw_ddb_index);
1303 goto exit_conn_start;
1306 status = qla4xxx_conn_open(ha, ddb_entry->fw_ddb_index);
1307 if (status == QLA_ERROR) {
1308 ql4_printk(KERN_ERR, ha, "%s: Login failed: %s\n", __func__,
1311 goto exit_conn_start;
1314 if (ddb_entry->fw_ddb_device_state == DDB_DS_NO_CONNECTION_ACTIVE)
1315 ddb_entry->fw_ddb_device_state = DDB_DS_LOGIN_IN_PROCESS;
1317 DEBUG2(printk(KERN_INFO "%s: DDB state [%d]\n", __func__,
1318 ddb_entry->fw_ddb_device_state));
1325 dma_free_coherent(&ha->pdev->dev, sizeof(*fw_ddb_entry),
1326 fw_ddb_entry, fw_ddb_entry_dma);
1330 static void qla4xxx_conn_destroy(struct iscsi_cls_conn *cls_conn)
1332 struct iscsi_cls_session *cls_sess = iscsi_conn_to_session(cls_conn);
1333 struct iscsi_session *sess;
1334 struct scsi_qla_host *ha;
1335 struct ddb_entry *ddb_entry;
1338 DEBUG2(printk(KERN_INFO "Func: %s\n", __func__));
1339 sess = cls_sess->dd_data;
1340 ddb_entry = sess->dd_data;
1343 options = LOGOUT_OPTION_CLOSE_SESSION;
1344 if (qla4xxx_session_logout_ddb(ha, ddb_entry, options) == QLA_ERROR)
1345 ql4_printk(KERN_ERR, ha, "%s: Logout failed\n", __func__);
1348 static void qla4xxx_task_work(struct work_struct *wdata)
1350 struct ql4_task_data *task_data;
1351 struct scsi_qla_host *ha;
1352 struct passthru_status *sts;
1353 struct iscsi_task *task;
1354 struct iscsi_hdr *hdr;
1357 struct iscsi_conn *conn;
1361 task_data = container_of(wdata, struct ql4_task_data, task_work);
1363 task = task_data->task;
1364 sts = &task_data->sts;
1365 hdr_len = sizeof(struct iscsi_hdr);
1367 DEBUG3(printk(KERN_INFO "Status returned\n"));
1368 DEBUG3(qla4xxx_dump_buffer(sts, 64));
1369 DEBUG3(printk(KERN_INFO "Response buffer"));
1370 DEBUG3(qla4xxx_dump_buffer(task_data->resp_buffer, 64));
1374 switch (sts->completionStatus) {
1375 case PASSTHRU_STATUS_COMPLETE:
1376 hdr = (struct iscsi_hdr *)task_data->resp_buffer;
1377 /* Assign back the itt in hdr, until we use the PREASSIGN_TAG */
1380 data = task_data->resp_buffer + hdr_len;
1381 data_len = task_data->resp_len - hdr_len;
1382 iscsi_complete_pdu(conn, hdr, data, data_len);
1385 ql4_printk(KERN_ERR, ha, "Passthru failed status = 0x%x\n",
1386 sts->completionStatus);
1392 static int qla4xxx_alloc_pdu(struct iscsi_task *task, uint8_t opcode)
1394 struct ql4_task_data *task_data;
1395 struct iscsi_session *sess;
1396 struct ddb_entry *ddb_entry;
1397 struct scsi_qla_host *ha;
1400 sess = task->conn->session;
1401 ddb_entry = sess->dd_data;
1403 task_data = task->dd_data;
1404 memset(task_data, 0, sizeof(struct ql4_task_data));
1407 ql4_printk(KERN_INFO, ha,
1408 "%s: SCSI Commands not implemented\n", __func__);
1412 hdr_len = sizeof(struct iscsi_hdr);
1414 task_data->task = task;
1416 if (task->data_count) {
1417 task_data->data_dma = dma_map_single(&ha->pdev->dev, task->data,
1422 DEBUG2(ql4_printk(KERN_INFO, ha, "%s: MaxRecvLen %u, iscsi hrd %d\n",
1423 __func__, task->conn->max_recv_dlength, hdr_len));
1425 task_data->resp_len = task->conn->max_recv_dlength + hdr_len;
1426 task_data->resp_buffer = dma_alloc_coherent(&ha->pdev->dev,
1427 task_data->resp_len,
1428 &task_data->resp_dma,
1430 if (!task_data->resp_buffer)
1431 goto exit_alloc_pdu;
1433 task_data->req_len = task->data_count + hdr_len;
1434 task_data->req_buffer = dma_alloc_coherent(&ha->pdev->dev,
1436 &task_data->req_dma,
1438 if (!task_data->req_buffer)
1439 goto exit_alloc_pdu;
1441 task->hdr = task_data->req_buffer;
1443 INIT_WORK(&task_data->task_work, qla4xxx_task_work);
1448 if (task_data->resp_buffer)
1449 dma_free_coherent(&ha->pdev->dev, task_data->resp_len,
1450 task_data->resp_buffer, task_data->resp_dma);
1452 if (task_data->req_buffer)
1453 dma_free_coherent(&ha->pdev->dev, task_data->req_len,
1454 task_data->req_buffer, task_data->req_dma);
1458 static void qla4xxx_task_cleanup(struct iscsi_task *task)
1460 struct ql4_task_data *task_data;
1461 struct iscsi_session *sess;
1462 struct ddb_entry *ddb_entry;
1463 struct scsi_qla_host *ha;
1466 hdr_len = sizeof(struct iscsi_hdr);
1467 sess = task->conn->session;
1468 ddb_entry = sess->dd_data;
1470 task_data = task->dd_data;
1472 if (task->data_count) {
1473 dma_unmap_single(&ha->pdev->dev, task_data->data_dma,
1474 task->data_count, PCI_DMA_TODEVICE);
1477 DEBUG2(ql4_printk(KERN_INFO, ha, "%s: MaxRecvLen %u, iscsi hrd %d\n",
1478 __func__, task->conn->max_recv_dlength, hdr_len));
1480 dma_free_coherent(&ha->pdev->dev, task_data->resp_len,
1481 task_data->resp_buffer, task_data->resp_dma);
1482 dma_free_coherent(&ha->pdev->dev, task_data->req_len,
1483 task_data->req_buffer, task_data->req_dma);
1487 static int qla4xxx_task_xmit(struct iscsi_task *task)
1489 struct scsi_cmnd *sc = task->sc;
1490 struct iscsi_session *sess = task->conn->session;
1491 struct ddb_entry *ddb_entry = sess->dd_data;
1492 struct scsi_qla_host *ha = ddb_entry->ha;
1495 return qla4xxx_send_passthru0(task);
1497 ql4_printk(KERN_INFO, ha, "%s: scsi cmd xmit not implemented\n",
1502 static void qla4xxx_copy_fwddb_param(struct scsi_qla_host *ha,
1503 struct dev_db_entry *fw_ddb_entry,
1504 struct iscsi_cls_session *cls_sess,
1505 struct iscsi_cls_conn *cls_conn)
1508 struct iscsi_session *sess;
1509 struct iscsi_conn *conn;
1510 char ip_addr[DDB_IPADDR_LEN];
1511 uint16_t options = 0;
1513 sess = cls_sess->dd_data;
1514 conn = cls_conn->dd_data;
1516 conn->max_recv_dlength = BYTE_UNITS *
1517 le16_to_cpu(fw_ddb_entry->iscsi_max_rcv_data_seg_len);
1519 conn->max_xmit_dlength = BYTE_UNITS *
1520 le16_to_cpu(fw_ddb_entry->iscsi_max_snd_data_seg_len);
1522 sess->initial_r2t_en =
1523 (BIT_10 & le16_to_cpu(fw_ddb_entry->iscsi_options));
1525 sess->max_r2t = le16_to_cpu(fw_ddb_entry->iscsi_max_outsnd_r2t);
1527 sess->imm_data_en = (BIT_11 & le16_to_cpu(fw_ddb_entry->iscsi_options));
1529 sess->first_burst = BYTE_UNITS *
1530 le16_to_cpu(fw_ddb_entry->iscsi_first_burst_len);
1532 sess->max_burst = BYTE_UNITS *
1533 le16_to_cpu(fw_ddb_entry->iscsi_max_burst_len);
1535 sess->time2wait = le16_to_cpu(fw_ddb_entry->iscsi_def_time2wait);
1537 sess->time2retain = le16_to_cpu(fw_ddb_entry->iscsi_def_time2retain);
1539 conn->persistent_port = le16_to_cpu(fw_ddb_entry->port);
1541 sess->tpgt = le32_to_cpu(fw_ddb_entry->tgt_portal_grp);
1543 options = le16_to_cpu(fw_ddb_entry->options);
1544 if (options & DDB_OPT_IPV6_DEVICE)
1545 sprintf(ip_addr, "%pI6", fw_ddb_entry->ip_addr);
1547 sprintf(ip_addr, "%pI4", fw_ddb_entry->ip_addr);
1549 iscsi_set_param(cls_conn, ISCSI_PARAM_TARGET_NAME,
1550 (char *)fw_ddb_entry->iscsi_name, buflen);
1551 iscsi_set_param(cls_conn, ISCSI_PARAM_INITIATOR_NAME,
1552 (char *)ha->name_string, buflen);
1553 iscsi_set_param(cls_conn, ISCSI_PARAM_PERSISTENT_ADDRESS,
1554 (char *)ip_addr, buflen);
1555 iscsi_set_param(cls_conn, ISCSI_PARAM_TARGET_ALIAS,
1556 (char *)fw_ddb_entry->iscsi_alias, buflen);
1559 void qla4xxx_update_session_conn_fwddb_param(struct scsi_qla_host *ha,
1560 struct ddb_entry *ddb_entry)
1562 struct iscsi_cls_session *cls_sess;
1563 struct iscsi_cls_conn *cls_conn;
1565 dma_addr_t fw_ddb_entry_dma;
1566 struct dev_db_entry *fw_ddb_entry;
1568 fw_ddb_entry = dma_alloc_coherent(&ha->pdev->dev, sizeof(*fw_ddb_entry),
1569 &fw_ddb_entry_dma, GFP_KERNEL);
1570 if (!fw_ddb_entry) {
1571 ql4_printk(KERN_ERR, ha,
1572 "%s: Unable to allocate dma buffer\n", __func__);
1573 goto exit_session_conn_fwddb_param;
1576 if (qla4xxx_get_fwddb_entry(ha, ddb_entry->fw_ddb_index, fw_ddb_entry,
1577 fw_ddb_entry_dma, NULL, NULL, &ddb_state,
1578 NULL, NULL, NULL) == QLA_ERROR) {
1579 DEBUG2(ql4_printk(KERN_ERR, ha, "scsi%ld: %s: failed "
1580 "get_ddb_entry for fw_ddb_index %d\n",
1581 ha->host_no, __func__,
1582 ddb_entry->fw_ddb_index));
1583 goto exit_session_conn_fwddb_param;
1586 cls_sess = ddb_entry->sess;
1588 cls_conn = ddb_entry->conn;
1591 qla4xxx_copy_fwddb_param(ha, fw_ddb_entry, cls_sess, cls_conn);
1593 exit_session_conn_fwddb_param:
1595 dma_free_coherent(&ha->pdev->dev, sizeof(*fw_ddb_entry),
1596 fw_ddb_entry, fw_ddb_entry_dma);
1599 void qla4xxx_update_session_conn_param(struct scsi_qla_host *ha,
1600 struct ddb_entry *ddb_entry)
1602 struct iscsi_cls_session *cls_sess;
1603 struct iscsi_cls_conn *cls_conn;
1604 struct iscsi_session *sess;
1605 struct iscsi_conn *conn;
1607 dma_addr_t fw_ddb_entry_dma;
1608 struct dev_db_entry *fw_ddb_entry;
1610 fw_ddb_entry = dma_alloc_coherent(&ha->pdev->dev, sizeof(*fw_ddb_entry),
1611 &fw_ddb_entry_dma, GFP_KERNEL);
1612 if (!fw_ddb_entry) {
1613 ql4_printk(KERN_ERR, ha,
1614 "%s: Unable to allocate dma buffer\n", __func__);
1615 goto exit_session_conn_param;
1618 if (qla4xxx_get_fwddb_entry(ha, ddb_entry->fw_ddb_index, fw_ddb_entry,
1619 fw_ddb_entry_dma, NULL, NULL, &ddb_state,
1620 NULL, NULL, NULL) == QLA_ERROR) {
1621 DEBUG2(ql4_printk(KERN_ERR, ha, "scsi%ld: %s: failed "
1622 "get_ddb_entry for fw_ddb_index %d\n",
1623 ha->host_no, __func__,
1624 ddb_entry->fw_ddb_index));
1625 goto exit_session_conn_param;
1628 cls_sess = ddb_entry->sess;
1629 sess = cls_sess->dd_data;
1631 cls_conn = ddb_entry->conn;
1632 conn = cls_conn->dd_data;
1634 /* Update timers after login */
1635 ddb_entry->default_relogin_timeout =
1636 (le16_to_cpu(fw_ddb_entry->def_timeout) > LOGIN_TOV) &&
1637 (le16_to_cpu(fw_ddb_entry->def_timeout) < LOGIN_TOV * 10) ?
1638 le16_to_cpu(fw_ddb_entry->def_timeout) : LOGIN_TOV;
1639 ddb_entry->default_time2wait =
1640 le16_to_cpu(fw_ddb_entry->iscsi_def_time2wait);
1643 conn->max_recv_dlength = BYTE_UNITS *
1644 le16_to_cpu(fw_ddb_entry->iscsi_max_rcv_data_seg_len);
1646 conn->max_xmit_dlength = BYTE_UNITS *
1647 le16_to_cpu(fw_ddb_entry->iscsi_max_snd_data_seg_len);
1649 sess->initial_r2t_en =
1650 (BIT_10 & le16_to_cpu(fw_ddb_entry->iscsi_options));
1652 sess->max_r2t = le16_to_cpu(fw_ddb_entry->iscsi_max_outsnd_r2t);
1654 sess->imm_data_en = (BIT_11 & le16_to_cpu(fw_ddb_entry->iscsi_options));
1656 sess->first_burst = BYTE_UNITS *
1657 le16_to_cpu(fw_ddb_entry->iscsi_first_burst_len);
1659 sess->max_burst = BYTE_UNITS *
1660 le16_to_cpu(fw_ddb_entry->iscsi_max_burst_len);
1662 sess->time2wait = le16_to_cpu(fw_ddb_entry->iscsi_def_time2wait);
1664 sess->time2retain = le16_to_cpu(fw_ddb_entry->iscsi_def_time2retain);
1666 sess->tpgt = le32_to_cpu(fw_ddb_entry->tgt_portal_grp);
1668 memcpy(sess->initiatorname, ha->name_string,
1669 min(sizeof(ha->name_string), sizeof(sess->initiatorname)));
1671 iscsi_set_param(cls_conn, ISCSI_PARAM_TARGET_ALIAS,
1672 (char *)fw_ddb_entry->iscsi_alias, 0);
1674 exit_session_conn_param:
1676 dma_free_coherent(&ha->pdev->dev, sizeof(*fw_ddb_entry),
1677 fw_ddb_entry, fw_ddb_entry_dma);
1684 static void qla4xxx_start_timer(struct scsi_qla_host *ha, void *func,
1685 unsigned long interval)
1687 DEBUG(printk("scsi: %s: Starting timer thread for adapter %d\n",
1688 __func__, ha->host->host_no));
1689 init_timer(&ha->timer);
1690 ha->timer.expires = jiffies + interval * HZ;
1691 ha->timer.data = (unsigned long)ha;
1692 ha->timer.function = (void (*)(unsigned long))func;
1693 add_timer(&ha->timer);
1694 ha->timer_active = 1;
1697 static void qla4xxx_stop_timer(struct scsi_qla_host *ha)
1699 del_timer_sync(&ha->timer);
1700 ha->timer_active = 0;
1704 * qla4xxx_mark_device_missing - blocks the session
1705 * @cls_session: Pointer to the session to be blocked
1706 * @ddb_entry: Pointer to device database entry
1708 * This routine marks a device missing and close connection.
1710 void qla4xxx_mark_device_missing(struct iscsi_cls_session *cls_session)
1712 iscsi_block_session(cls_session);
1716 * qla4xxx_mark_all_devices_missing - mark all devices as missing.
1717 * @ha: Pointer to host adapter structure.
1719 * This routine marks a device missing and resets the relogin retry count.
1721 void qla4xxx_mark_all_devices_missing(struct scsi_qla_host *ha)
1723 iscsi_host_for_each_session(ha->host, qla4xxx_mark_device_missing);
1726 static struct srb* qla4xxx_get_new_srb(struct scsi_qla_host *ha,
1727 struct ddb_entry *ddb_entry,
1728 struct scsi_cmnd *cmd)
1732 srb = mempool_alloc(ha->srb_mempool, GFP_ATOMIC);
1736 kref_init(&srb->srb_ref);
1738 srb->ddb = ddb_entry;
1741 CMD_SP(cmd) = (void *)srb;
1746 static void qla4xxx_srb_free_dma(struct scsi_qla_host *ha, struct srb *srb)
1748 struct scsi_cmnd *cmd = srb->cmd;
1750 if (srb->flags & SRB_DMA_VALID) {
1751 scsi_dma_unmap(cmd);
1752 srb->flags &= ~SRB_DMA_VALID;
1757 void qla4xxx_srb_compl(struct kref *ref)
1759 struct srb *srb = container_of(ref, struct srb, srb_ref);
1760 struct scsi_cmnd *cmd = srb->cmd;
1761 struct scsi_qla_host *ha = srb->ha;
1763 qla4xxx_srb_free_dma(ha, srb);
1765 mempool_free(srb, ha->srb_mempool);
1767 cmd->scsi_done(cmd);
1771 * qla4xxx_queuecommand - scsi layer issues scsi command to driver.
1773 * @cmd: Pointer to Linux's SCSI command structure
1776 * This routine is invoked by Linux to send a SCSI command to the driver.
1777 * The mid-level driver tries to ensure that queuecommand never gets
1778 * invoked concurrently with itself or the interrupt handler (although
1779 * the interrupt handler may call this routine as part of request-
1780 * completion handling). Unfortunely, it sometimes calls the scheduler
1781 * in interrupt context which is a big NO! NO!.
1783 static int qla4xxx_queuecommand(struct Scsi_Host *host, struct scsi_cmnd *cmd)
1785 struct scsi_qla_host *ha = to_qla_host(host);
1786 struct ddb_entry *ddb_entry = cmd->device->hostdata;
1787 struct iscsi_cls_session *sess = ddb_entry->sess;
1791 if (test_bit(AF_EEH_BUSY, &ha->flags)) {
1792 if (test_bit(AF_PCI_CHANNEL_IO_PERM_FAILURE, &ha->flags))
1793 cmd->result = DID_NO_CONNECT << 16;
1795 cmd->result = DID_REQUEUE << 16;
1796 goto qc_fail_command;
1800 cmd->result = DID_IMM_RETRY << 16;
1801 goto qc_fail_command;
1804 rval = iscsi_session_chkready(sess);
1807 goto qc_fail_command;
1810 if (test_bit(DPC_RESET_HA_INTR, &ha->dpc_flags) ||
1811 test_bit(DPC_RESET_ACTIVE, &ha->dpc_flags) ||
1812 test_bit(DPC_RESET_HA, &ha->dpc_flags) ||
1813 test_bit(DPC_HA_UNRECOVERABLE, &ha->dpc_flags) ||
1814 test_bit(DPC_HA_NEED_QUIESCENT, &ha->dpc_flags) ||
1815 !test_bit(AF_ONLINE, &ha->flags) ||
1816 !test_bit(AF_LINK_UP, &ha->flags) ||
1817 test_bit(DPC_RESET_HA_FW_CONTEXT, &ha->dpc_flags))
1820 srb = qla4xxx_get_new_srb(ha, ddb_entry, cmd);
1824 rval = qla4xxx_send_command_to_isp(ha, srb);
1825 if (rval != QLA_SUCCESS)
1826 goto qc_host_busy_free_sp;
1830 qc_host_busy_free_sp:
1831 qla4xxx_srb_free_dma(ha, srb);
1832 mempool_free(srb, ha->srb_mempool);
1835 return SCSI_MLQUEUE_HOST_BUSY;
1838 cmd->scsi_done(cmd);
1844 * qla4xxx_mem_free - frees memory allocated to adapter
1845 * @ha: Pointer to host adapter structure.
1847 * Frees memory previously allocated by qla4xxx_mem_alloc
1849 static void qla4xxx_mem_free(struct scsi_qla_host *ha)
1852 dma_free_coherent(&ha->pdev->dev, ha->queues_len, ha->queues,
1858 ha->request_ring = NULL;
1859 ha->request_dma = 0;
1860 ha->response_ring = NULL;
1861 ha->response_dma = 0;
1862 ha->shadow_regs = NULL;
1863 ha->shadow_regs_dma = 0;
1865 /* Free srb pool. */
1866 if (ha->srb_mempool)
1867 mempool_destroy(ha->srb_mempool);
1869 ha->srb_mempool = NULL;
1871 if (ha->chap_dma_pool)
1872 dma_pool_destroy(ha->chap_dma_pool);
1875 vfree(ha->chap_list);
1876 ha->chap_list = NULL;
1878 if (ha->fw_ddb_dma_pool)
1879 dma_pool_destroy(ha->fw_ddb_dma_pool);
1881 /* release io space registers */
1882 if (is_qla8022(ha)) {
1885 (struct device_reg_82xx __iomem *)ha->nx_pcibase);
1888 pci_release_regions(ha->pdev);
1892 * qla4xxx_mem_alloc - allocates memory for use by adapter.
1893 * @ha: Pointer to host adapter structure
1895 * Allocates DMA memory for request and response queues. Also allocates memory
1898 static int qla4xxx_mem_alloc(struct scsi_qla_host *ha)
1900 unsigned long align;
1902 /* Allocate contiguous block of DMA memory for queues. */
1903 ha->queues_len = ((REQUEST_QUEUE_DEPTH * QUEUE_SIZE) +
1904 (RESPONSE_QUEUE_DEPTH * QUEUE_SIZE) +
1905 sizeof(struct shadow_regs) +
1907 (PAGE_SIZE - 1)) & ~(PAGE_SIZE - 1);
1908 ha->queues = dma_alloc_coherent(&ha->pdev->dev, ha->queues_len,
1909 &ha->queues_dma, GFP_KERNEL);
1910 if (ha->queues == NULL) {
1911 ql4_printk(KERN_WARNING, ha,
1912 "Memory Allocation failed - queues.\n");
1914 goto mem_alloc_error_exit;
1916 memset(ha->queues, 0, ha->queues_len);
1919 * As per RISC alignment requirements -- the bus-address must be a
1920 * multiple of the request-ring size (in bytes).
1923 if ((unsigned long)ha->queues_dma & (MEM_ALIGN_VALUE - 1))
1924 align = MEM_ALIGN_VALUE - ((unsigned long)ha->queues_dma &
1925 (MEM_ALIGN_VALUE - 1));
1927 /* Update request and response queue pointers. */
1928 ha->request_dma = ha->queues_dma + align;
1929 ha->request_ring = (struct queue_entry *) (ha->queues + align);
1930 ha->response_dma = ha->queues_dma + align +
1931 (REQUEST_QUEUE_DEPTH * QUEUE_SIZE);
1932 ha->response_ring = (struct queue_entry *) (ha->queues + align +
1933 (REQUEST_QUEUE_DEPTH *
1935 ha->shadow_regs_dma = ha->queues_dma + align +
1936 (REQUEST_QUEUE_DEPTH * QUEUE_SIZE) +
1937 (RESPONSE_QUEUE_DEPTH * QUEUE_SIZE);
1938 ha->shadow_regs = (struct shadow_regs *) (ha->queues + align +
1939 (REQUEST_QUEUE_DEPTH *
1941 (RESPONSE_QUEUE_DEPTH *
1944 /* Allocate memory for srb pool. */
1945 ha->srb_mempool = mempool_create(SRB_MIN_REQ, mempool_alloc_slab,
1946 mempool_free_slab, srb_cachep);
1947 if (ha->srb_mempool == NULL) {
1948 ql4_printk(KERN_WARNING, ha,
1949 "Memory Allocation failed - SRB Pool.\n");
1951 goto mem_alloc_error_exit;
1954 ha->chap_dma_pool = dma_pool_create("ql4_chap", &ha->pdev->dev,
1955 CHAP_DMA_BLOCK_SIZE, 8, 0);
1957 if (ha->chap_dma_pool == NULL) {
1958 ql4_printk(KERN_WARNING, ha,
1959 "%s: chap_dma_pool allocation failed..\n", __func__);
1960 goto mem_alloc_error_exit;
1963 ha->fw_ddb_dma_pool = dma_pool_create("ql4_fw_ddb", &ha->pdev->dev,
1964 DDB_DMA_BLOCK_SIZE, 8, 0);
1966 if (ha->fw_ddb_dma_pool == NULL) {
1967 ql4_printk(KERN_WARNING, ha,
1968 "%s: fw_ddb_dma_pool allocation failed..\n",
1970 goto mem_alloc_error_exit;
1975 mem_alloc_error_exit:
1976 qla4xxx_mem_free(ha);
1981 * qla4_8xxx_check_temp - Check the ISP82XX temperature.
1982 * @ha: adapter block pointer.
1984 * Note: The caller should not hold the idc lock.
1986 static int qla4_8xxx_check_temp(struct scsi_qla_host *ha)
1988 uint32_t temp, temp_state, temp_val;
1989 int status = QLA_SUCCESS;
1991 temp = qla4_8xxx_rd_32(ha, CRB_TEMP_STATE);
1993 temp_state = qla82xx_get_temp_state(temp);
1994 temp_val = qla82xx_get_temp_val(temp);
1996 if (temp_state == QLA82XX_TEMP_PANIC) {
1997 ql4_printk(KERN_WARNING, ha, "Device temperature %d degrees C"
1998 " exceeds maximum allowed. Hardware has been shut"
1999 " down.\n", temp_val);
2001 } else if (temp_state == QLA82XX_TEMP_WARN) {
2002 if (ha->temperature == QLA82XX_TEMP_NORMAL)
2003 ql4_printk(KERN_WARNING, ha, "Device temperature %d"
2004 " degrees C exceeds operating range."
2005 " Immediate action needed.\n", temp_val);
2007 if (ha->temperature == QLA82XX_TEMP_WARN)
2008 ql4_printk(KERN_INFO, ha, "Device temperature is"
2009 " now %d degrees C in normal range.\n",
2012 ha->temperature = temp_state;
2017 * qla4_8xxx_check_fw_alive - Check firmware health
2018 * @ha: Pointer to host adapter structure.
2020 * Context: Interrupt
2022 static int qla4_8xxx_check_fw_alive(struct scsi_qla_host *ha)
2024 uint32_t fw_heartbeat_counter;
2025 int status = QLA_SUCCESS;
2027 fw_heartbeat_counter = qla4_8xxx_rd_32(ha, QLA82XX_PEG_ALIVE_COUNTER);
2028 /* If PEG_ALIVE_COUNTER is 0xffffffff, AER/EEH is in progress, ignore */
2029 if (fw_heartbeat_counter == 0xffffffff) {
2030 DEBUG2(printk(KERN_WARNING "scsi%ld: %s: Device in frozen "
2031 "state, QLA82XX_PEG_ALIVE_COUNTER is 0xffffffff\n",
2032 ha->host_no, __func__));
2036 if (ha->fw_heartbeat_counter == fw_heartbeat_counter) {
2037 ha->seconds_since_last_heartbeat++;
2038 /* FW not alive after 2 seconds */
2039 if (ha->seconds_since_last_heartbeat == 2) {
2040 ha->seconds_since_last_heartbeat = 0;
2042 ql4_printk(KERN_INFO, ha,
2043 "scsi(%ld): %s, Dumping hw/fw registers:\n "
2044 " PEG_HALT_STATUS1: 0x%x, PEG_HALT_STATUS2:"
2045 " 0x%x,\n PEG_NET_0_PC: 0x%x, PEG_NET_1_PC:"
2046 " 0x%x,\n PEG_NET_2_PC: 0x%x, PEG_NET_3_PC:"
2047 " 0x%x,\n PEG_NET_4_PC: 0x%x\n",
2048 ha->host_no, __func__,
2050 QLA82XX_PEG_HALT_STATUS1),
2052 QLA82XX_PEG_HALT_STATUS2),
2053 qla4_8xxx_rd_32(ha, QLA82XX_CRB_PEG_NET_0 +
2055 qla4_8xxx_rd_32(ha, QLA82XX_CRB_PEG_NET_1 +
2057 qla4_8xxx_rd_32(ha, QLA82XX_CRB_PEG_NET_2 +
2059 qla4_8xxx_rd_32(ha, QLA82XX_CRB_PEG_NET_3 +
2061 qla4_8xxx_rd_32(ha, QLA82XX_CRB_PEG_NET_4 +
2066 ha->seconds_since_last_heartbeat = 0;
2068 ha->fw_heartbeat_counter = fw_heartbeat_counter;
2073 * qla4_8xxx_watchdog - Poll dev state
2074 * @ha: Pointer to host adapter structure.
2076 * Context: Interrupt
2078 void qla4_8xxx_watchdog(struct scsi_qla_host *ha)
2080 uint32_t dev_state, halt_status;
2082 /* don't poll if reset is going on */
2083 if (!(test_bit(DPC_RESET_ACTIVE, &ha->dpc_flags) ||
2084 test_bit(DPC_RESET_HA, &ha->dpc_flags) ||
2085 test_bit(DPC_RETRY_RESET_HA, &ha->dpc_flags))) {
2086 dev_state = qla4_8xxx_rd_32(ha, QLA82XX_CRB_DEV_STATE);
2088 if (qla4_8xxx_check_temp(ha)) {
2089 ql4_printk(KERN_INFO, ha, "disabling pause"
2090 " transmit on port 0 & 1.\n");
2091 qla4_8xxx_wr_32(ha, QLA82XX_CRB_NIU + 0x98,
2092 CRB_NIU_XG_PAUSE_CTL_P0 |
2093 CRB_NIU_XG_PAUSE_CTL_P1);
2094 set_bit(DPC_HA_UNRECOVERABLE, &ha->dpc_flags);
2095 qla4xxx_wake_dpc(ha);
2096 } else if (dev_state == QLA82XX_DEV_NEED_RESET &&
2097 !test_bit(DPC_RESET_HA, &ha->dpc_flags)) {
2098 if (!ql4xdontresethba) {
2099 ql4_printk(KERN_INFO, ha, "%s: HW State: "
2100 "NEED RESET!\n", __func__);
2101 set_bit(DPC_RESET_HA, &ha->dpc_flags);
2102 qla4xxx_wake_dpc(ha);
2104 } else if (dev_state == QLA82XX_DEV_NEED_QUIESCENT &&
2105 !test_bit(DPC_HA_NEED_QUIESCENT, &ha->dpc_flags)) {
2106 ql4_printk(KERN_INFO, ha, "%s: HW State: NEED QUIES!\n",
2108 set_bit(DPC_HA_NEED_QUIESCENT, &ha->dpc_flags);
2109 qla4xxx_wake_dpc(ha);
2111 /* Check firmware health */
2112 if (qla4_8xxx_check_fw_alive(ha)) {
2113 ql4_printk(KERN_INFO, ha, "disabling pause"
2114 " transmit on port 0 & 1.\n");
2115 qla4_8xxx_wr_32(ha, QLA82XX_CRB_NIU + 0x98,
2116 CRB_NIU_XG_PAUSE_CTL_P0 |
2117 CRB_NIU_XG_PAUSE_CTL_P1);
2118 halt_status = qla4_8xxx_rd_32(ha,
2119 QLA82XX_PEG_HALT_STATUS1);
2121 if (LSW(MSB(halt_status)) == 0x67)
2122 ql4_printk(KERN_ERR, ha, "%s:"
2123 " Firmware aborted with"
2124 " error code 0x00006700."
2125 " Device is being reset\n",
2128 /* Since we cannot change dev_state in interrupt
2129 * context, set appropriate DPC flag then wakeup
2131 if (halt_status & HALT_STATUS_UNRECOVERABLE)
2132 set_bit(DPC_HA_UNRECOVERABLE,
2135 ql4_printk(KERN_INFO, ha, "%s: detect "
2136 "abort needed!\n", __func__);
2137 set_bit(DPC_RESET_HA, &ha->dpc_flags);
2139 qla4xxx_mailbox_premature_completion(ha);
2140 qla4xxx_wake_dpc(ha);
2146 static void qla4xxx_check_relogin_flash_ddb(struct iscsi_cls_session *cls_sess)
2148 struct iscsi_session *sess;
2149 struct ddb_entry *ddb_entry;
2150 struct scsi_qla_host *ha;
2152 sess = cls_sess->dd_data;
2153 ddb_entry = sess->dd_data;
2156 if (!(ddb_entry->ddb_type == FLASH_DDB))
2159 if (adapter_up(ha) && !test_bit(DF_RELOGIN, &ddb_entry->flags) &&
2160 !iscsi_is_session_online(cls_sess)) {
2161 if (atomic_read(&ddb_entry->retry_relogin_timer) !=
2163 if (atomic_read(&ddb_entry->retry_relogin_timer) ==
2165 atomic_set(&ddb_entry->retry_relogin_timer,
2167 set_bit(DPC_RELOGIN_DEVICE, &ha->dpc_flags);
2168 set_bit(DF_RELOGIN, &ddb_entry->flags);
2169 DEBUG2(ql4_printk(KERN_INFO, ha,
2170 "%s: index [%d] login device\n",
2171 __func__, ddb_entry->fw_ddb_index));
2173 atomic_dec(&ddb_entry->retry_relogin_timer);
2177 /* Wait for relogin to timeout */
2178 if (atomic_read(&ddb_entry->relogin_timer) &&
2179 (atomic_dec_and_test(&ddb_entry->relogin_timer) != 0)) {
2181 * If the relogin times out and the device is
2182 * still NOT ONLINE then try and relogin again.
2184 if (!iscsi_is_session_online(cls_sess)) {
2185 /* Reset retry relogin timer */
2186 atomic_inc(&ddb_entry->relogin_retry_count);
2187 DEBUG2(ql4_printk(KERN_INFO, ha,
2188 "%s: index[%d] relogin timed out-retrying"
2189 " relogin (%d), retry (%d)\n", __func__,
2190 ddb_entry->fw_ddb_index,
2191 atomic_read(&ddb_entry->relogin_retry_count),
2192 ddb_entry->default_time2wait + 4));
2193 set_bit(DPC_RELOGIN_DEVICE, &ha->dpc_flags);
2194 atomic_set(&ddb_entry->retry_relogin_timer,
2195 ddb_entry->default_time2wait + 4);
2201 * qla4xxx_timer - checks every second for work to do.
2202 * @ha: Pointer to host adapter structure.
2204 static void qla4xxx_timer(struct scsi_qla_host *ha)
2209 iscsi_host_for_each_session(ha->host, qla4xxx_check_relogin_flash_ddb);
2211 /* If we are in the middle of AER/EEH processing
2212 * skip any processing and reschedule the timer
2214 if (test_bit(AF_EEH_BUSY, &ha->flags)) {
2215 mod_timer(&ha->timer, jiffies + HZ);
2219 /* Hardware read to trigger an EEH error during mailbox waits. */
2220 if (!pci_channel_offline(ha->pdev))
2221 pci_read_config_word(ha->pdev, PCI_VENDOR_ID, &w);
2223 if (is_qla8022(ha)) {
2224 qla4_8xxx_watchdog(ha);
2227 if (!is_qla8022(ha)) {
2228 /* Check for heartbeat interval. */
2229 if (ha->firmware_options & FWOPT_HEARTBEAT_ENABLE &&
2230 ha->heartbeat_interval != 0) {
2231 ha->seconds_since_last_heartbeat++;
2232 if (ha->seconds_since_last_heartbeat >
2233 ha->heartbeat_interval + 2)
2234 set_bit(DPC_RESET_HA, &ha->dpc_flags);
2238 /* Wakeup the dpc routine for this adapter, if needed. */
2240 test_bit(DPC_RESET_HA, &ha->dpc_flags) ||
2241 test_bit(DPC_RETRY_RESET_HA, &ha->dpc_flags) ||
2242 test_bit(DPC_RELOGIN_DEVICE, &ha->dpc_flags) ||
2243 test_bit(DPC_RESET_HA_FW_CONTEXT, &ha->dpc_flags) ||
2244 test_bit(DPC_RESET_HA_INTR, &ha->dpc_flags) ||
2245 test_bit(DPC_GET_DHCP_IP_ADDR, &ha->dpc_flags) ||
2246 test_bit(DPC_LINK_CHANGED, &ha->dpc_flags) ||
2247 test_bit(DPC_HA_UNRECOVERABLE, &ha->dpc_flags) ||
2248 test_bit(DPC_HA_NEED_QUIESCENT, &ha->dpc_flags) ||
2249 test_bit(DPC_AEN, &ha->dpc_flags)) {
2250 DEBUG2(printk("scsi%ld: %s: scheduling dpc routine"
2251 " - dpc flags = 0x%lx\n",
2252 ha->host_no, __func__, ha->dpc_flags));
2253 qla4xxx_wake_dpc(ha);
2256 /* Reschedule timer thread to call us back in one second */
2257 mod_timer(&ha->timer, jiffies + HZ);
2259 DEBUG2(ha->seconds_since_last_intr++);
2263 * qla4xxx_cmd_wait - waits for all outstanding commands to complete
2264 * @ha: Pointer to host adapter structure.
2266 * This routine stalls the driver until all outstanding commands are returned.
2267 * Caller must release the Hardware Lock prior to calling this routine.
2269 static int qla4xxx_cmd_wait(struct scsi_qla_host *ha)
2272 unsigned long flags;
2273 struct scsi_cmnd *cmd;
2275 unsigned long wtime = jiffies + (WAIT_CMD_TOV * HZ);
2277 DEBUG2(ql4_printk(KERN_INFO, ha, "Wait up to %d seconds for cmds to "
2278 "complete\n", WAIT_CMD_TOV));
2280 while (!time_after_eq(jiffies, wtime)) {
2281 spin_lock_irqsave(&ha->hardware_lock, flags);
2282 /* Find a command that hasn't completed. */
2283 for (index = 0; index < ha->host->can_queue; index++) {
2284 cmd = scsi_host_find_tag(ha->host, index);
2286 * We cannot just check if the index is valid,
2287 * becase if we are run from the scsi eh, then
2288 * the scsi/block layer is going to prevent
2289 * the tag from being released.
2291 if (cmd != NULL && CMD_SP(cmd))
2294 spin_unlock_irqrestore(&ha->hardware_lock, flags);
2296 /* If No Commands are pending, wait is complete */
2297 if (index == ha->host->can_queue)
2302 /* If we timed out on waiting for commands to come back
2307 int qla4xxx_hw_reset(struct scsi_qla_host *ha)
2309 uint32_t ctrl_status;
2310 unsigned long flags = 0;
2312 DEBUG2(printk(KERN_ERR "scsi%ld: %s\n", ha->host_no, __func__));
2314 if (ql4xxx_lock_drvr_wait(ha) != QLA_SUCCESS)
2317 spin_lock_irqsave(&ha->hardware_lock, flags);
2320 * If the SCSI Reset Interrupt bit is set, clear it.
2321 * Otherwise, the Soft Reset won't work.
2323 ctrl_status = readw(&ha->reg->ctrl_status);
2324 if ((ctrl_status & CSR_SCSI_RESET_INTR) != 0)
2325 writel(set_rmask(CSR_SCSI_RESET_INTR), &ha->reg->ctrl_status);
2327 /* Issue Soft Reset */
2328 writel(set_rmask(CSR_SOFT_RESET), &ha->reg->ctrl_status);
2329 readl(&ha->reg->ctrl_status);
2331 spin_unlock_irqrestore(&ha->hardware_lock, flags);
2336 * qla4xxx_soft_reset - performs soft reset.
2337 * @ha: Pointer to host adapter structure.
2339 int qla4xxx_soft_reset(struct scsi_qla_host *ha)
2341 uint32_t max_wait_time;
2342 unsigned long flags = 0;
2344 uint32_t ctrl_status;
2346 status = qla4xxx_hw_reset(ha);
2347 if (status != QLA_SUCCESS)
2351 /* Wait until the Network Reset Intr bit is cleared */
2352 max_wait_time = RESET_INTR_TOV;
2354 spin_lock_irqsave(&ha->hardware_lock, flags);
2355 ctrl_status = readw(&ha->reg->ctrl_status);
2356 spin_unlock_irqrestore(&ha->hardware_lock, flags);
2358 if ((ctrl_status & CSR_NET_RESET_INTR) == 0)
2362 } while ((--max_wait_time));
2364 if ((ctrl_status & CSR_NET_RESET_INTR) != 0) {
2365 DEBUG2(printk(KERN_WARNING
2366 "scsi%ld: Network Reset Intr not cleared by "
2367 "Network function, clearing it now!\n",
2369 spin_lock_irqsave(&ha->hardware_lock, flags);
2370 writel(set_rmask(CSR_NET_RESET_INTR), &ha->reg->ctrl_status);
2371 readl(&ha->reg->ctrl_status);
2372 spin_unlock_irqrestore(&ha->hardware_lock, flags);
2375 /* Wait until the firmware tells us the Soft Reset is done */
2376 max_wait_time = SOFT_RESET_TOV;
2378 spin_lock_irqsave(&ha->hardware_lock, flags);
2379 ctrl_status = readw(&ha->reg->ctrl_status);
2380 spin_unlock_irqrestore(&ha->hardware_lock, flags);
2382 if ((ctrl_status & CSR_SOFT_RESET) == 0) {
2383 status = QLA_SUCCESS;
2388 } while ((--max_wait_time));
2391 * Also, make sure that the SCSI Reset Interrupt bit has been cleared
2392 * after the soft reset has taken place.
2394 spin_lock_irqsave(&ha->hardware_lock, flags);
2395 ctrl_status = readw(&ha->reg->ctrl_status);
2396 if ((ctrl_status & CSR_SCSI_RESET_INTR) != 0) {
2397 writel(set_rmask(CSR_SCSI_RESET_INTR), &ha->reg->ctrl_status);
2398 readl(&ha->reg->ctrl_status);
2400 spin_unlock_irqrestore(&ha->hardware_lock, flags);
2402 /* If soft reset fails then most probably the bios on other
2403 * function is also enabled.
2404 * Since the initialization is sequential the other fn
2405 * wont be able to acknowledge the soft reset.
2406 * Issue a force soft reset to workaround this scenario.
2408 if (max_wait_time == 0) {
2409 /* Issue Force Soft Reset */
2410 spin_lock_irqsave(&ha->hardware_lock, flags);
2411 writel(set_rmask(CSR_FORCE_SOFT_RESET), &ha->reg->ctrl_status);
2412 readl(&ha->reg->ctrl_status);
2413 spin_unlock_irqrestore(&ha->hardware_lock, flags);
2414 /* Wait until the firmware tells us the Soft Reset is done */
2415 max_wait_time = SOFT_RESET_TOV;
2417 spin_lock_irqsave(&ha->hardware_lock, flags);
2418 ctrl_status = readw(&ha->reg->ctrl_status);
2419 spin_unlock_irqrestore(&ha->hardware_lock, flags);
2421 if ((ctrl_status & CSR_FORCE_SOFT_RESET) == 0) {
2422 status = QLA_SUCCESS;
2427 } while ((--max_wait_time));
2434 * qla4xxx_abort_active_cmds - returns all outstanding i/o requests to O.S.
2435 * @ha: Pointer to host adapter structure.
2436 * @res: returned scsi status
2438 * This routine is called just prior to a HARD RESET to return all
2439 * outstanding commands back to the Operating System.
2440 * Caller should make sure that the following locks are released
2441 * before this calling routine: Hardware lock, and io_request_lock.
2443 static void qla4xxx_abort_active_cmds(struct scsi_qla_host *ha, int res)
2447 unsigned long flags;
2449 spin_lock_irqsave(&ha->hardware_lock, flags);
2450 for (i = 0; i < ha->host->can_queue; i++) {
2451 srb = qla4xxx_del_from_active_array(ha, i);
2453 srb->cmd->result = res;
2454 kref_put(&srb->srb_ref, qla4xxx_srb_compl);
2457 spin_unlock_irqrestore(&ha->hardware_lock, flags);
2460 void qla4xxx_dead_adapter_cleanup(struct scsi_qla_host *ha)
2462 clear_bit(AF_ONLINE, &ha->flags);
2464 /* Disable the board */
2465 ql4_printk(KERN_INFO, ha, "Disabling the board\n");
2467 qla4xxx_abort_active_cmds(ha, DID_NO_CONNECT << 16);
2468 qla4xxx_mark_all_devices_missing(ha);
2469 clear_bit(AF_INIT_DONE, &ha->flags);
2472 static void qla4xxx_fail_session(struct iscsi_cls_session *cls_session)
2474 struct iscsi_session *sess;
2475 struct ddb_entry *ddb_entry;
2477 sess = cls_session->dd_data;
2478 ddb_entry = sess->dd_data;
2479 ddb_entry->fw_ddb_device_state = DDB_DS_SESSION_FAILED;
2481 if (ddb_entry->ddb_type == FLASH_DDB)
2482 iscsi_block_session(ddb_entry->sess);
2484 iscsi_session_failure(cls_session->dd_data,
2485 ISCSI_ERR_CONN_FAILED);
2489 * qla4xxx_recover_adapter - recovers adapter after a fatal error
2490 * @ha: Pointer to host adapter structure.
2492 static int qla4xxx_recover_adapter(struct scsi_qla_host *ha)
2494 int status = QLA_ERROR;
2495 uint8_t reset_chip = 0;
2499 /* Stall incoming I/O until we are done */
2500 scsi_block_requests(ha->host);
2501 clear_bit(AF_ONLINE, &ha->flags);
2502 clear_bit(AF_LINK_UP, &ha->flags);
2504 DEBUG2(ql4_printk(KERN_INFO, ha, "%s: adapter OFFLINE\n", __func__));
2506 set_bit(DPC_RESET_ACTIVE, &ha->dpc_flags);
2508 iscsi_host_for_each_session(ha->host, qla4xxx_fail_session);
2510 if (test_bit(DPC_RESET_HA, &ha->dpc_flags))
2513 /* For the DPC_RESET_HA_INTR case (ISP-4xxx specific)
2514 * do not reset adapter, jump to initialize_adapter */
2515 if (test_bit(DPC_RESET_HA_INTR, &ha->dpc_flags)) {
2516 status = QLA_SUCCESS;
2517 goto recover_ha_init_adapter;
2520 /* For the ISP-82xx adapter, issue a stop_firmware if invoked
2521 * from eh_host_reset or ioctl module */
2522 if (is_qla8022(ha) && !reset_chip &&
2523 test_bit(DPC_RESET_HA_FW_CONTEXT, &ha->dpc_flags)) {
2525 DEBUG2(ql4_printk(KERN_INFO, ha,
2526 "scsi%ld: %s - Performing stop_firmware...\n",
2527 ha->host_no, __func__));
2528 status = ha->isp_ops->reset_firmware(ha);
2529 if (status == QLA_SUCCESS) {
2530 if (!test_bit(AF_FW_RECOVERY, &ha->flags))
2531 qla4xxx_cmd_wait(ha);
2532 ha->isp_ops->disable_intrs(ha);
2533 qla4xxx_process_aen(ha, FLUSH_DDB_CHANGED_AENS);
2534 qla4xxx_abort_active_cmds(ha, DID_RESET << 16);
2536 /* If the stop_firmware fails then
2537 * reset the entire chip */
2539 clear_bit(DPC_RESET_HA_FW_CONTEXT, &ha->dpc_flags);
2540 set_bit(DPC_RESET_HA, &ha->dpc_flags);
2544 /* Issue full chip reset if recovering from a catastrophic error,
2545 * or if stop_firmware fails for ISP-82xx.
2546 * This is the default case for ISP-4xxx */
2547 if (!is_qla8022(ha) || reset_chip) {
2548 if (!is_qla8022(ha))
2551 /* Check if 82XX firmware is alive or not
2552 * We may have arrived here from NEED_RESET
2554 if (test_bit(AF_FW_RECOVERY, &ha->flags))
2557 wait = jiffies + (FW_ALIVE_WAIT_TOV * HZ);
2558 while (time_before(jiffies, wait)) {
2559 if (qla4_8xxx_check_fw_alive(ha)) {
2560 qla4xxx_mailbox_premature_completion(ha);
2564 set_current_state(TASK_UNINTERRUPTIBLE);
2565 schedule_timeout(HZ);
2568 if (!test_bit(AF_FW_RECOVERY, &ha->flags))
2569 qla4xxx_cmd_wait(ha);
2571 qla4xxx_process_aen(ha, FLUSH_DDB_CHANGED_AENS);
2572 qla4xxx_abort_active_cmds(ha, DID_RESET << 16);
2573 DEBUG2(ql4_printk(KERN_INFO, ha,
2574 "scsi%ld: %s - Performing chip reset..\n",
2575 ha->host_no, __func__));
2576 status = ha->isp_ops->reset_chip(ha);
2579 /* Flush any pending ddb changed AENs */
2580 qla4xxx_process_aen(ha, FLUSH_DDB_CHANGED_AENS);
2582 recover_ha_init_adapter:
2583 /* Upon successful firmware/chip reset, re-initialize the adapter */
2584 if (status == QLA_SUCCESS) {
2585 /* For ISP-4xxx, force function 1 to always initialize
2586 * before function 3 to prevent both funcions from
2587 * stepping on top of the other */
2588 if (!is_qla8022(ha) && (ha->mac_index == 3))
2591 /* NOTE: AF_ONLINE flag set upon successful completion of
2592 * qla4xxx_initialize_adapter */
2593 status = qla4xxx_initialize_adapter(ha, RESET_ADAPTER);
2596 /* Retry failed adapter initialization, if necessary
2597 * Do not retry initialize_adapter for RESET_HA_INTR (ISP-4xxx specific)
2598 * case to prevent ping-pong resets between functions */
2599 if (!test_bit(AF_ONLINE, &ha->flags) &&
2600 !test_bit(DPC_RESET_HA_INTR, &ha->dpc_flags)) {
2601 /* Adapter initialization failed, see if we can retry
2603 * Since we don't want to block the DPC for too long
2604 * with multiple resets in the same thread,
2605 * utilize DPC to retry */
2606 if (is_qla8022(ha)) {
2607 qla4_8xxx_idc_lock(ha);
2608 dev_state = qla4_8xxx_rd_32(ha, QLA82XX_CRB_DEV_STATE);
2609 qla4_8xxx_idc_unlock(ha);
2610 if (dev_state == QLA82XX_DEV_FAILED) {
2611 ql4_printk(KERN_INFO, ha, "%s: don't retry "
2612 "recover adapter. H/W is in Failed "
2613 "state\n", __func__);
2614 qla4xxx_dead_adapter_cleanup(ha);
2615 clear_bit(DPC_RETRY_RESET_HA, &ha->dpc_flags);
2616 clear_bit(DPC_RESET_HA, &ha->dpc_flags);
2617 clear_bit(DPC_RESET_HA_FW_CONTEXT,
2625 if (!test_bit(DPC_RETRY_RESET_HA, &ha->dpc_flags)) {
2626 ha->retry_reset_ha_cnt = MAX_RESET_HA_RETRIES;
2627 DEBUG2(printk("scsi%ld: recover adapter - retrying "
2628 "(%d) more times\n", ha->host_no,
2629 ha->retry_reset_ha_cnt));
2630 set_bit(DPC_RETRY_RESET_HA, &ha->dpc_flags);
2633 if (ha->retry_reset_ha_cnt > 0) {
2634 /* Schedule another Reset HA--DPC will retry */
2635 ha->retry_reset_ha_cnt--;
2636 DEBUG2(printk("scsi%ld: recover adapter - "
2637 "retry remaining %d\n",
2639 ha->retry_reset_ha_cnt));
2643 if (ha->retry_reset_ha_cnt == 0) {
2644 /* Recover adapter retries have been exhausted.
2646 DEBUG2(printk("scsi%ld: recover adapter "
2647 "failed - board disabled\n",
2649 qla4xxx_dead_adapter_cleanup(ha);
2650 clear_bit(DPC_RETRY_RESET_HA, &ha->dpc_flags);
2651 clear_bit(DPC_RESET_HA, &ha->dpc_flags);
2652 clear_bit(DPC_RESET_HA_FW_CONTEXT,
2658 clear_bit(DPC_RESET_HA, &ha->dpc_flags);
2659 clear_bit(DPC_RESET_HA_FW_CONTEXT, &ha->dpc_flags);
2660 clear_bit(DPC_RETRY_RESET_HA, &ha->dpc_flags);
2664 ha->adapter_error_count++;
2666 if (test_bit(AF_ONLINE, &ha->flags))
2667 ha->isp_ops->enable_intrs(ha);
2669 scsi_unblock_requests(ha->host);
2671 clear_bit(DPC_RESET_ACTIVE, &ha->dpc_flags);
2672 DEBUG2(printk("scsi%ld: recover adapter: %s\n", ha->host_no,
2673 status == QLA_ERROR ? "FAILED" : "SUCCEEDED"));
2678 static void qla4xxx_relogin_devices(struct iscsi_cls_session *cls_session)
2680 struct iscsi_session *sess;
2681 struct ddb_entry *ddb_entry;
2682 struct scsi_qla_host *ha;
2684 sess = cls_session->dd_data;
2685 ddb_entry = sess->dd_data;
2687 if (!iscsi_is_session_online(cls_session)) {
2688 if (ddb_entry->fw_ddb_device_state == DDB_DS_SESSION_ACTIVE) {
2689 ql4_printk(KERN_INFO, ha, "scsi%ld: %s: ddb[%d]"
2690 " unblock session\n", ha->host_no, __func__,
2691 ddb_entry->fw_ddb_index);
2692 iscsi_unblock_session(ddb_entry->sess);
2694 /* Trigger relogin */
2695 if (ddb_entry->ddb_type == FLASH_DDB) {
2696 if (!test_bit(DF_RELOGIN, &ddb_entry->flags))
2697 qla4xxx_arm_relogin_timer(ddb_entry);
2699 iscsi_session_failure(cls_session->dd_data,
2700 ISCSI_ERR_CONN_FAILED);
2705 int qla4xxx_unblock_flash_ddb(struct iscsi_cls_session *cls_session)
2707 struct iscsi_session *sess;
2708 struct ddb_entry *ddb_entry;
2709 struct scsi_qla_host *ha;
2711 sess = cls_session->dd_data;
2712 ddb_entry = sess->dd_data;
2714 ql4_printk(KERN_INFO, ha, "scsi%ld: %s: ddb[%d]"
2715 " unblock session\n", ha->host_no, __func__,
2716 ddb_entry->fw_ddb_index);
2718 iscsi_unblock_session(ddb_entry->sess);
2720 /* Start scan target */
2721 if (test_bit(AF_ONLINE, &ha->flags)) {
2722 ql4_printk(KERN_INFO, ha, "scsi%ld: %s: ddb[%d]"
2723 " start scan\n", ha->host_no, __func__,
2724 ddb_entry->fw_ddb_index);
2725 scsi_queue_work(ha->host, &ddb_entry->sess->scan_work);
2730 int qla4xxx_unblock_ddb(struct iscsi_cls_session *cls_session)
2732 struct iscsi_session *sess;
2733 struct ddb_entry *ddb_entry;
2734 struct scsi_qla_host *ha;
2736 sess = cls_session->dd_data;
2737 ddb_entry = sess->dd_data;
2739 ql4_printk(KERN_INFO, ha, "scsi%ld: %s: ddb[%d]"
2740 " unblock user space session\n", ha->host_no, __func__,
2741 ddb_entry->fw_ddb_index);
2742 iscsi_conn_start(ddb_entry->conn);
2743 iscsi_conn_login_event(ddb_entry->conn,
2744 ISCSI_CONN_STATE_LOGGED_IN);
2749 static void qla4xxx_relogin_all_devices(struct scsi_qla_host *ha)
2751 iscsi_host_for_each_session(ha->host, qla4xxx_relogin_devices);
2754 static void qla4xxx_relogin_flash_ddb(struct iscsi_cls_session *cls_sess)
2756 uint16_t relogin_timer;
2757 struct iscsi_session *sess;
2758 struct ddb_entry *ddb_entry;
2759 struct scsi_qla_host *ha;
2761 sess = cls_sess->dd_data;
2762 ddb_entry = sess->dd_data;
2765 relogin_timer = max(ddb_entry->default_relogin_timeout,
2766 (uint16_t)RELOGIN_TOV);
2767 atomic_set(&ddb_entry->relogin_timer, relogin_timer);
2769 DEBUG2(ql4_printk(KERN_INFO, ha,
2770 "scsi%ld: Relogin index [%d]. TOV=%d\n", ha->host_no,
2771 ddb_entry->fw_ddb_index, relogin_timer));
2773 qla4xxx_login_flash_ddb(cls_sess);
2776 static void qla4xxx_dpc_relogin(struct iscsi_cls_session *cls_sess)
2778 struct iscsi_session *sess;
2779 struct ddb_entry *ddb_entry;
2780 struct scsi_qla_host *ha;
2782 sess = cls_sess->dd_data;
2783 ddb_entry = sess->dd_data;
2786 if (!(ddb_entry->ddb_type == FLASH_DDB))
2789 if (test_and_clear_bit(DF_RELOGIN, &ddb_entry->flags) &&
2790 !iscsi_is_session_online(cls_sess)) {
2791 DEBUG2(ql4_printk(KERN_INFO, ha,
2792 "relogin issued\n"));
2793 qla4xxx_relogin_flash_ddb(cls_sess);
2797 void qla4xxx_wake_dpc(struct scsi_qla_host *ha)
2800 queue_work(ha->dpc_thread, &ha->dpc_work);
2804 * qla4xxx_do_dpc - dpc routine
2805 * @data: in our case pointer to adapter structure
2807 * This routine is a task that is schedule by the interrupt handler
2808 * to perform the background processing for interrupts. We put it
2809 * on a task queue that is consumed whenever the scheduler runs; that's
2810 * so you can do anything (i.e. put the process to sleep etc). In fact,
2811 * the mid-level tries to sleep when it reaches the driver threshold
2812 * "host->can_queue". This can cause a panic if we were in our interrupt code.
2814 static void qla4xxx_do_dpc(struct work_struct *work)
2816 struct scsi_qla_host *ha =
2817 container_of(work, struct scsi_qla_host, dpc_work);
2818 int status = QLA_ERROR;
2820 DEBUG2(printk("scsi%ld: %s: DPC handler waking up."
2821 "flags = 0x%08lx, dpc_flags = 0x%08lx\n",
2822 ha->host_no, __func__, ha->flags, ha->dpc_flags))
2824 /* Initialization not yet finished. Don't do anything yet. */
2825 if (!test_bit(AF_INIT_DONE, &ha->flags))
2828 if (test_bit(AF_EEH_BUSY, &ha->flags)) {
2829 DEBUG2(printk(KERN_INFO "scsi%ld: %s: flags = %lx\n",
2830 ha->host_no, __func__, ha->flags));
2834 if (is_qla8022(ha)) {
2835 if (test_bit(DPC_HA_UNRECOVERABLE, &ha->dpc_flags)) {
2836 qla4_8xxx_idc_lock(ha);
2837 qla4_8xxx_wr_32(ha, QLA82XX_CRB_DEV_STATE,
2838 QLA82XX_DEV_FAILED);
2839 qla4_8xxx_idc_unlock(ha);
2840 ql4_printk(KERN_INFO, ha, "HW State: FAILED\n");
2841 qla4_8xxx_device_state_handler(ha);
2843 if (test_and_clear_bit(DPC_HA_NEED_QUIESCENT, &ha->dpc_flags)) {
2844 qla4_8xxx_need_qsnt_handler(ha);
2848 if (!test_bit(DPC_RESET_ACTIVE, &ha->dpc_flags) &&
2849 (test_bit(DPC_RESET_HA, &ha->dpc_flags) ||
2850 test_bit(DPC_RESET_HA_INTR, &ha->dpc_flags) ||
2851 test_bit(DPC_RESET_HA_FW_CONTEXT, &ha->dpc_flags))) {
2852 if (ql4xdontresethba) {
2853 DEBUG2(printk("scsi%ld: %s: Don't Reset HBA\n",
2854 ha->host_no, __func__));
2855 clear_bit(DPC_RESET_HA, &ha->dpc_flags);
2856 clear_bit(DPC_RESET_HA_INTR, &ha->dpc_flags);
2857 clear_bit(DPC_RESET_HA_FW_CONTEXT, &ha->dpc_flags);
2858 goto dpc_post_reset_ha;
2860 if (test_bit(DPC_RESET_HA_FW_CONTEXT, &ha->dpc_flags) ||
2861 test_bit(DPC_RESET_HA, &ha->dpc_flags))
2862 qla4xxx_recover_adapter(ha);
2864 if (test_bit(DPC_RESET_HA_INTR, &ha->dpc_flags)) {
2865 uint8_t wait_time = RESET_INTR_TOV;
2867 while ((readw(&ha->reg->ctrl_status) &
2868 (CSR_SOFT_RESET | CSR_FORCE_SOFT_RESET)) != 0) {
2869 if (--wait_time == 0)
2874 DEBUG2(printk("scsi%ld: %s: SR|FSR "
2875 "bit not cleared-- resetting\n",
2876 ha->host_no, __func__));
2877 qla4xxx_abort_active_cmds(ha, DID_RESET << 16);
2878 if (ql4xxx_lock_drvr_wait(ha) == QLA_SUCCESS) {
2879 qla4xxx_process_aen(ha, FLUSH_DDB_CHANGED_AENS);
2880 status = qla4xxx_recover_adapter(ha);
2882 clear_bit(DPC_RESET_HA_INTR, &ha->dpc_flags);
2883 if (status == QLA_SUCCESS)
2884 ha->isp_ops->enable_intrs(ha);
2889 /* ---- process AEN? --- */
2890 if (test_and_clear_bit(DPC_AEN, &ha->dpc_flags))
2891 qla4xxx_process_aen(ha, PROCESS_ALL_AENS);
2893 /* ---- Get DHCP IP Address? --- */
2894 if (test_and_clear_bit(DPC_GET_DHCP_IP_ADDR, &ha->dpc_flags))
2895 qla4xxx_get_dhcp_ip_address(ha);
2897 /* ---- relogin device? --- */
2898 if (adapter_up(ha) &&
2899 test_and_clear_bit(DPC_RELOGIN_DEVICE, &ha->dpc_flags)) {
2900 iscsi_host_for_each_session(ha->host, qla4xxx_dpc_relogin);
2903 /* ---- link change? --- */
2904 if (test_and_clear_bit(DPC_LINK_CHANGED, &ha->dpc_flags)) {
2905 if (!test_bit(AF_LINK_UP, &ha->flags)) {
2906 /* ---- link down? --- */
2907 qla4xxx_mark_all_devices_missing(ha);
2909 /* ---- link up? --- *
2910 * F/W will auto login to all devices ONLY ONCE after
2911 * link up during driver initialization and runtime
2912 * fatal error recovery. Therefore, the driver must
2913 * manually relogin to devices when recovering from
2914 * connection failures, logouts, expired KATO, etc. */
2915 if (test_and_clear_bit(AF_BUILD_DDB_LIST, &ha->flags)) {
2916 qla4xxx_build_ddb_list(ha, ha->is_reset);
2917 iscsi_host_for_each_session(ha->host,
2918 qla4xxx_login_flash_ddb);
2920 qla4xxx_relogin_all_devices(ha);
2926 * qla4xxx_free_adapter - release the adapter
2927 * @ha: pointer to adapter structure
2929 static void qla4xxx_free_adapter(struct scsi_qla_host *ha)
2931 qla4xxx_abort_active_cmds(ha, DID_NO_CONNECT << 16);
2933 if (test_bit(AF_INTERRUPTS_ON, &ha->flags)) {
2934 /* Turn-off interrupts on the card. */
2935 ha->isp_ops->disable_intrs(ha);
2938 /* Remove timer thread, if present */
2939 if (ha->timer_active)
2940 qla4xxx_stop_timer(ha);
2942 /* Kill the kernel thread for this host */
2944 destroy_workqueue(ha->dpc_thread);
2946 /* Kill the kernel thread for this host */
2948 destroy_workqueue(ha->task_wq);
2950 /* Put firmware in known state */
2951 ha->isp_ops->reset_firmware(ha);
2953 if (is_qla8022(ha)) {
2954 qla4_8xxx_idc_lock(ha);
2955 qla4_8xxx_clear_drv_active(ha);
2956 qla4_8xxx_idc_unlock(ha);
2959 /* Detach interrupts */
2960 if (test_and_clear_bit(AF_IRQ_ATTACHED, &ha->flags))
2961 qla4xxx_free_irqs(ha);
2963 /* free extra memory */
2964 qla4xxx_mem_free(ha);
2967 int qla4_8xxx_iospace_config(struct scsi_qla_host *ha)
2970 uint8_t revision_id;
2971 unsigned long mem_base, mem_len, db_base, db_len;
2972 struct pci_dev *pdev = ha->pdev;
2974 status = pci_request_regions(pdev, DRIVER_NAME);
2977 "scsi(%ld) Failed to reserve PIO regions (%s) "
2978 "status=%d\n", ha->host_no, pci_name(pdev), status);
2979 goto iospace_error_exit;
2982 pci_read_config_byte(pdev, PCI_REVISION_ID, &revision_id);
2983 DEBUG2(printk(KERN_INFO "%s: revision-id=%d\n",
2984 __func__, revision_id));
2985 ha->revision_id = revision_id;
2987 /* remap phys address */
2988 mem_base = pci_resource_start(pdev, 0); /* 0 is for BAR 0 */
2989 mem_len = pci_resource_len(pdev, 0);
2990 DEBUG2(printk(KERN_INFO "%s: ioremap from %lx a size of %lx\n",
2991 __func__, mem_base, mem_len));
2993 /* mapping of pcibase pointer */
2994 ha->nx_pcibase = (unsigned long)ioremap(mem_base, mem_len);
2995 if (!ha->nx_pcibase) {
2997 "cannot remap MMIO (%s), aborting\n", pci_name(pdev));
2998 pci_release_regions(ha->pdev);
2999 goto iospace_error_exit;
3002 /* Mapping of IO base pointer, door bell read and write pointer */
3004 /* mapping of IO base pointer */
3006 (struct device_reg_82xx __iomem *)((uint8_t *)ha->nx_pcibase +
3007 0xbc000 + (ha->pdev->devfn << 11));
3009 db_base = pci_resource_start(pdev, 4); /* doorbell is on bar 4 */
3010 db_len = pci_resource_len(pdev, 4);
3012 ha->nx_db_wr_ptr = (ha->pdev->devfn == 4 ? QLA82XX_CAM_RAM_DB1 :
3013 QLA82XX_CAM_RAM_DB2);
3021 * qla4xxx_iospace_config - maps registers
3022 * @ha: pointer to adapter structure
3024 * This routines maps HBA's registers from the pci address space
3025 * into the kernel virtual address space for memory mapped i/o.
3027 int qla4xxx_iospace_config(struct scsi_qla_host *ha)
3029 unsigned long pio, pio_len, pio_flags;
3030 unsigned long mmio, mmio_len, mmio_flags;
3032 pio = pci_resource_start(ha->pdev, 0);
3033 pio_len = pci_resource_len(ha->pdev, 0);
3034 pio_flags = pci_resource_flags(ha->pdev, 0);
3035 if (pio_flags & IORESOURCE_IO) {
3036 if (pio_len < MIN_IOBASE_LEN) {
3037 ql4_printk(KERN_WARNING, ha,
3038 "Invalid PCI I/O region size\n");
3042 ql4_printk(KERN_WARNING, ha, "region #0 not a PIO resource\n");
3046 /* Use MMIO operations for all accesses. */
3047 mmio = pci_resource_start(ha->pdev, 1);
3048 mmio_len = pci_resource_len(ha->pdev, 1);
3049 mmio_flags = pci_resource_flags(ha->pdev, 1);
3051 if (!(mmio_flags & IORESOURCE_MEM)) {
3052 ql4_printk(KERN_ERR, ha,
3053 "region #0 not an MMIO resource, aborting\n");
3055 goto iospace_error_exit;
3058 if (mmio_len < MIN_IOBASE_LEN) {
3059 ql4_printk(KERN_ERR, ha,
3060 "Invalid PCI mem region size, aborting\n");
3061 goto iospace_error_exit;
3064 if (pci_request_regions(ha->pdev, DRIVER_NAME)) {
3065 ql4_printk(KERN_WARNING, ha,
3066 "Failed to reserve PIO/MMIO regions\n");
3068 goto iospace_error_exit;
3071 ha->pio_address = pio;
3072 ha->pio_length = pio_len;
3073 ha->reg = ioremap(mmio, MIN_IOBASE_LEN);
3075 ql4_printk(KERN_ERR, ha,
3076 "cannot remap MMIO, aborting\n");
3078 goto iospace_error_exit;
3087 static struct isp_operations qla4xxx_isp_ops = {
3088 .iospace_config = qla4xxx_iospace_config,
3089 .pci_config = qla4xxx_pci_config,
3090 .disable_intrs = qla4xxx_disable_intrs,
3091 .enable_intrs = qla4xxx_enable_intrs,
3092 .start_firmware = qla4xxx_start_firmware,
3093 .intr_handler = qla4xxx_intr_handler,
3094 .interrupt_service_routine = qla4xxx_interrupt_service_routine,
3095 .reset_chip = qla4xxx_soft_reset,
3096 .reset_firmware = qla4xxx_hw_reset,
3097 .queue_iocb = qla4xxx_queue_iocb,
3098 .complete_iocb = qla4xxx_complete_iocb,
3099 .rd_shdw_req_q_out = qla4xxx_rd_shdw_req_q_out,
3100 .rd_shdw_rsp_q_in = qla4xxx_rd_shdw_rsp_q_in,
3101 .get_sys_info = qla4xxx_get_sys_info,
3104 static struct isp_operations qla4_8xxx_isp_ops = {
3105 .iospace_config = qla4_8xxx_iospace_config,
3106 .pci_config = qla4_8xxx_pci_config,
3107 .disable_intrs = qla4_8xxx_disable_intrs,
3108 .enable_intrs = qla4_8xxx_enable_intrs,
3109 .start_firmware = qla4_8xxx_load_risc,
3110 .intr_handler = qla4_8xxx_intr_handler,
3111 .interrupt_service_routine = qla4_8xxx_interrupt_service_routine,
3112 .reset_chip = qla4_8xxx_isp_reset,
3113 .reset_firmware = qla4_8xxx_stop_firmware,
3114 .queue_iocb = qla4_8xxx_queue_iocb,
3115 .complete_iocb = qla4_8xxx_complete_iocb,
3116 .rd_shdw_req_q_out = qla4_8xxx_rd_shdw_req_q_out,
3117 .rd_shdw_rsp_q_in = qla4_8xxx_rd_shdw_rsp_q_in,
3118 .get_sys_info = qla4_8xxx_get_sys_info,
3121 uint16_t qla4xxx_rd_shdw_req_q_out(struct scsi_qla_host *ha)
3123 return (uint16_t)le32_to_cpu(ha->shadow_regs->req_q_out);
3126 uint16_t qla4_8xxx_rd_shdw_req_q_out(struct scsi_qla_host *ha)
3128 return (uint16_t)le32_to_cpu(readl(&ha->qla4_8xxx_reg->req_q_out));
3131 uint16_t qla4xxx_rd_shdw_rsp_q_in(struct scsi_qla_host *ha)
3133 return (uint16_t)le32_to_cpu(ha->shadow_regs->rsp_q_in);
3136 uint16_t qla4_8xxx_rd_shdw_rsp_q_in(struct scsi_qla_host *ha)
3138 return (uint16_t)le32_to_cpu(readl(&ha->qla4_8xxx_reg->rsp_q_in));
3141 static ssize_t qla4xxx_show_boot_eth_info(void *data, int type, char *buf)
3143 struct scsi_qla_host *ha = data;
3148 case ISCSI_BOOT_ETH_FLAGS:
3149 rc = sprintf(str, "%d\n", SYSFS_FLAG_FW_SEL_BOOT);
3151 case ISCSI_BOOT_ETH_INDEX:
3152 rc = sprintf(str, "0\n");
3154 case ISCSI_BOOT_ETH_MAC:
3155 rc = sysfs_format_mac(str, ha->my_mac,
3165 static umode_t qla4xxx_eth_get_attr_visibility(void *data, int type)
3170 case ISCSI_BOOT_ETH_FLAGS:
3171 case ISCSI_BOOT_ETH_MAC:
3172 case ISCSI_BOOT_ETH_INDEX:
3182 static ssize_t qla4xxx_show_boot_ini_info(void *data, int type, char *buf)
3184 struct scsi_qla_host *ha = data;
3189 case ISCSI_BOOT_INI_INITIATOR_NAME:
3190 rc = sprintf(str, "%s\n", ha->name_string);
3199 static umode_t qla4xxx_ini_get_attr_visibility(void *data, int type)
3204 case ISCSI_BOOT_INI_INITIATOR_NAME:
3215 qla4xxx_show_boot_tgt_info(struct ql4_boot_session_info *boot_sess, int type,
3218 struct ql4_conn_info *boot_conn = &boot_sess->conn_list[0];
3223 case ISCSI_BOOT_TGT_NAME:
3224 rc = sprintf(buf, "%s\n", (char *)&boot_sess->target_name);
3226 case ISCSI_BOOT_TGT_IP_ADDR:
3227 if (boot_sess->conn_list[0].dest_ipaddr.ip_type == 0x1)
3228 rc = sprintf(buf, "%pI4\n",
3229 &boot_conn->dest_ipaddr.ip_address);
3231 rc = sprintf(str, "%pI6\n",
3232 &boot_conn->dest_ipaddr.ip_address);
3234 case ISCSI_BOOT_TGT_PORT:
3235 rc = sprintf(str, "%d\n", boot_conn->dest_port);
3237 case ISCSI_BOOT_TGT_CHAP_NAME:
3238 rc = sprintf(str, "%.*s\n",
3239 boot_conn->chap.target_chap_name_length,
3240 (char *)&boot_conn->chap.target_chap_name);
3242 case ISCSI_BOOT_TGT_CHAP_SECRET:
3243 rc = sprintf(str, "%.*s\n",
3244 boot_conn->chap.target_secret_length,
3245 (char *)&boot_conn->chap.target_secret);
3247 case ISCSI_BOOT_TGT_REV_CHAP_NAME:
3248 rc = sprintf(str, "%.*s\n",
3249 boot_conn->chap.intr_chap_name_length,
3250 (char *)&boot_conn->chap.intr_chap_name);
3252 case ISCSI_BOOT_TGT_REV_CHAP_SECRET:
3253 rc = sprintf(str, "%.*s\n",
3254 boot_conn->chap.intr_secret_length,
3255 (char *)&boot_conn->chap.intr_secret);
3257 case ISCSI_BOOT_TGT_FLAGS:
3258 rc = sprintf(str, "%d\n", SYSFS_FLAG_FW_SEL_BOOT);
3260 case ISCSI_BOOT_TGT_NIC_ASSOC:
3261 rc = sprintf(str, "0\n");
3270 static ssize_t qla4xxx_show_boot_tgt_pri_info(void *data, int type, char *buf)
3272 struct scsi_qla_host *ha = data;
3273 struct ql4_boot_session_info *boot_sess = &(ha->boot_tgt.boot_pri_sess);
3275 return qla4xxx_show_boot_tgt_info(boot_sess, type, buf);
3278 static ssize_t qla4xxx_show_boot_tgt_sec_info(void *data, int type, char *buf)
3280 struct scsi_qla_host *ha = data;
3281 struct ql4_boot_session_info *boot_sess = &(ha->boot_tgt.boot_sec_sess);
3283 return qla4xxx_show_boot_tgt_info(boot_sess, type, buf);
3286 static umode_t qla4xxx_tgt_get_attr_visibility(void *data, int type)
3291 case ISCSI_BOOT_TGT_NAME:
3292 case ISCSI_BOOT_TGT_IP_ADDR:
3293 case ISCSI_BOOT_TGT_PORT:
3294 case ISCSI_BOOT_TGT_CHAP_NAME:
3295 case ISCSI_BOOT_TGT_CHAP_SECRET:
3296 case ISCSI_BOOT_TGT_REV_CHAP_NAME:
3297 case ISCSI_BOOT_TGT_REV_CHAP_SECRET:
3298 case ISCSI_BOOT_TGT_NIC_ASSOC:
3299 case ISCSI_BOOT_TGT_FLAGS:
3309 static void qla4xxx_boot_release(void *data)
3311 struct scsi_qla_host *ha = data;
3313 scsi_host_put(ha->host);
3316 static int get_fw_boot_info(struct scsi_qla_host *ha, uint16_t ddb_index[])
3319 uint32_t addr, pri_addr, sec_addr;
3323 uint8_t *buf = NULL;
3324 size_t size = 13 * sizeof(uint8_t);
3325 int ret = QLA_SUCCESS;
3327 func_num = PCI_FUNC(ha->pdev->devfn);
3329 ql4_printk(KERN_INFO, ha, "%s: Get FW boot info for 0x%x func %d\n",
3330 __func__, ha->pdev->device, func_num);
3332 if (is_qla40XX(ha)) {
3333 if (func_num == 1) {
3334 addr = NVRAM_PORT0_BOOT_MODE;
3335 pri_addr = NVRAM_PORT0_BOOT_PRI_TGT;
3336 sec_addr = NVRAM_PORT0_BOOT_SEC_TGT;
3337 } else if (func_num == 3) {
3338 addr = NVRAM_PORT1_BOOT_MODE;
3339 pri_addr = NVRAM_PORT1_BOOT_PRI_TGT;
3340 sec_addr = NVRAM_PORT1_BOOT_SEC_TGT;
3343 goto exit_boot_info;
3346 /* Check Boot Mode */
3347 val = rd_nvram_byte(ha, addr);
3348 if (!(val & 0x07)) {
3349 DEBUG2(ql4_printk(KERN_ERR, ha,
3350 "%s: Failed Boot options : 0x%x\n",
3353 goto exit_boot_info;
3356 /* get primary valid target index */
3357 val = rd_nvram_byte(ha, pri_addr);
3359 ddb_index[0] = (val & 0x7f);
3361 /* get secondary valid target index */
3362 val = rd_nvram_byte(ha, sec_addr);
3364 ddb_index[1] = (val & 0x7f);
3366 } else if (is_qla8022(ha)) {
3367 buf = dma_alloc_coherent(&ha->pdev->dev, size,
3368 &buf_dma, GFP_KERNEL);
3370 DEBUG2(ql4_printk(KERN_ERR, ha,
3371 "%s: Unable to allocate dma buffer\n",
3374 goto exit_boot_info;
3377 if (ha->port_num == 0)
3378 offset = BOOT_PARAM_OFFSET_PORT0;
3379 else if (ha->port_num == 1)
3380 offset = BOOT_PARAM_OFFSET_PORT1;
3383 goto exit_boot_info_free;
3385 addr = FLASH_RAW_ACCESS_ADDR + (ha->hw.flt_iscsi_param * 4) +
3387 if (qla4xxx_get_flash(ha, buf_dma, addr,
3388 13 * sizeof(uint8_t)) != QLA_SUCCESS) {
3389 DEBUG2(ql4_printk(KERN_ERR, ha, "scsi%ld: %s: Get Flash"
3390 "failed\n", ha->host_no, __func__));
3392 goto exit_boot_info_free;
3394 /* Check Boot Mode */
3395 if (!(buf[1] & 0x07)) {
3396 DEBUG2(ql4_printk(KERN_INFO, ha,
3397 "Failed: Boot options : 0x%x\n",
3400 goto exit_boot_info_free;
3403 /* get primary valid target index */
3405 ddb_index[0] = buf[2] & 0x7f;
3407 /* get secondary valid target index */
3408 if (buf[11] & BIT_7)
3409 ddb_index[1] = buf[11] & 0x7f;
3412 goto exit_boot_info;
3415 DEBUG2(ql4_printk(KERN_INFO, ha, "%s: Primary target ID %d, Secondary"
3416 " target ID %d\n", __func__, ddb_index[0],
3419 ha->pri_ddb_idx = ddb_index[0];
3420 ha->sec_ddb_idx = ddb_index[1];
3422 exit_boot_info_free:
3423 dma_free_coherent(&ha->pdev->dev, size, buf, buf_dma);
3429 * qla4xxx_get_bidi_chap - Get a BIDI CHAP user and password
3430 * @ha: pointer to adapter structure
3431 * @username: CHAP username to be returned
3432 * @password: CHAP password to be returned
3434 * If a boot entry has BIDI CHAP enabled then we need to set the BIDI CHAP
3435 * user and password in the sysfs entry in /sys/firmware/iscsi_boot#/.
3436 * So from the CHAP cache find the first BIDI CHAP entry and set it
3437 * to the boot record in sysfs.
3439 static int qla4xxx_get_bidi_chap(struct scsi_qla_host *ha, char *username,
3442 int i, ret = -EINVAL;
3443 int max_chap_entries = 0;
3444 struct ql4_chap_table *chap_table;
3447 max_chap_entries = (ha->hw.flt_chap_size / 2) /
3448 sizeof(struct ql4_chap_table);
3450 max_chap_entries = MAX_CHAP_ENTRIES_40XX;
3452 if (!ha->chap_list) {
3453 ql4_printk(KERN_ERR, ha, "Do not have CHAP table cache\n");
3457 mutex_lock(&ha->chap_sem);
3458 for (i = 0; i < max_chap_entries; i++) {
3459 chap_table = (struct ql4_chap_table *)ha->chap_list + i;
3460 if (chap_table->cookie !=
3461 __constant_cpu_to_le16(CHAP_VALID_COOKIE)) {
3465 if (chap_table->flags & BIT_7) /* local */
3468 if (!(chap_table->flags & BIT_6)) /* Not BIDI */
3471 strncpy(password, chap_table->secret, QL4_CHAP_MAX_SECRET_LEN);
3472 strncpy(username, chap_table->name, QL4_CHAP_MAX_NAME_LEN);
3476 mutex_unlock(&ha->chap_sem);
3482 static int qla4xxx_get_boot_target(struct scsi_qla_host *ha,
3483 struct ql4_boot_session_info *boot_sess,
3486 struct ql4_conn_info *boot_conn = &boot_sess->conn_list[0];
3487 struct dev_db_entry *fw_ddb_entry;
3488 dma_addr_t fw_ddb_entry_dma;
3491 int ret = QLA_SUCCESS;
3493 fw_ddb_entry = dma_alloc_coherent(&ha->pdev->dev, sizeof(*fw_ddb_entry),
3494 &fw_ddb_entry_dma, GFP_KERNEL);
3495 if (!fw_ddb_entry) {
3496 DEBUG2(ql4_printk(KERN_ERR, ha,
3497 "%s: Unable to allocate dma buffer.\n",
3503 if (qla4xxx_bootdb_by_index(ha, fw_ddb_entry,
3504 fw_ddb_entry_dma, ddb_index)) {
3505 DEBUG2(ql4_printk(KERN_ERR, ha,
3506 "%s: Flash DDB read Failed\n", __func__));
3508 goto exit_boot_target;
3511 /* Update target name and IP from DDB */
3512 memcpy(boot_sess->target_name, fw_ddb_entry->iscsi_name,
3513 min(sizeof(boot_sess->target_name),
3514 sizeof(fw_ddb_entry->iscsi_name)));
3516 options = le16_to_cpu(fw_ddb_entry->options);
3517 if (options & DDB_OPT_IPV6_DEVICE) {
3518 memcpy(&boot_conn->dest_ipaddr.ip_address,
3519 &fw_ddb_entry->ip_addr[0], IPv6_ADDR_LEN);
3521 boot_conn->dest_ipaddr.ip_type = 0x1;
3522 memcpy(&boot_conn->dest_ipaddr.ip_address,
3523 &fw_ddb_entry->ip_addr[0], IP_ADDR_LEN);
3526 boot_conn->dest_port = le16_to_cpu(fw_ddb_entry->port);
3528 /* update chap information */
3529 idx = __le16_to_cpu(fw_ddb_entry->chap_tbl_idx);
3531 if (BIT_7 & le16_to_cpu(fw_ddb_entry->iscsi_options)) {
3533 DEBUG2(ql4_printk(KERN_INFO, ha, "Setting chap\n"));
3535 ret = qla4xxx_get_chap(ha, (char *)&boot_conn->chap.
3537 (char *)&boot_conn->chap.target_secret,
3540 ql4_printk(KERN_ERR, ha, "Failed to set chap\n");
3542 goto exit_boot_target;
3545 boot_conn->chap.target_chap_name_length = QL4_CHAP_MAX_NAME_LEN;
3546 boot_conn->chap.target_secret_length = QL4_CHAP_MAX_SECRET_LEN;
3549 if (BIT_4 & le16_to_cpu(fw_ddb_entry->iscsi_options)) {
3551 DEBUG2(ql4_printk(KERN_INFO, ha, "Setting BIDI chap\n"));
3553 ret = qla4xxx_get_bidi_chap(ha,
3554 (char *)&boot_conn->chap.intr_chap_name,
3555 (char *)&boot_conn->chap.intr_secret);
3558 ql4_printk(KERN_ERR, ha, "Failed to set BIDI chap\n");
3560 goto exit_boot_target;
3563 boot_conn->chap.intr_chap_name_length = QL4_CHAP_MAX_NAME_LEN;
3564 boot_conn->chap.intr_secret_length = QL4_CHAP_MAX_SECRET_LEN;
3568 dma_free_coherent(&ha->pdev->dev, sizeof(*fw_ddb_entry),
3569 fw_ddb_entry, fw_ddb_entry_dma);
3573 static int qla4xxx_get_boot_info(struct scsi_qla_host *ha)
3575 uint16_t ddb_index[2];
3576 int ret = QLA_ERROR;
3579 memset(ddb_index, 0, sizeof(ddb_index));
3580 ddb_index[0] = 0xffff;
3581 ddb_index[1] = 0xffff;
3582 ret = get_fw_boot_info(ha, ddb_index);
3583 if (ret != QLA_SUCCESS) {
3584 DEBUG2(ql4_printk(KERN_ERR, ha,
3585 "%s: Failed to set boot info.\n", __func__));
3589 if (ql4xdisablesysfsboot)
3592 if (ddb_index[0] == 0xffff)
3595 rval = qla4xxx_get_boot_target(ha, &(ha->boot_tgt.boot_pri_sess),
3597 if (rval != QLA_SUCCESS) {
3598 DEBUG2(ql4_printk(KERN_ERR, ha, "%s: Failed to get "
3599 "primary target\n", __func__));
3604 if (ddb_index[1] == 0xffff)
3605 goto exit_get_boot_info;
3607 rval = qla4xxx_get_boot_target(ha, &(ha->boot_tgt.boot_sec_sess),
3609 if (rval != QLA_SUCCESS) {
3610 DEBUG2(ql4_printk(KERN_ERR, ha, "%s: Failed to get "
3611 "secondary target\n", __func__));
3619 static int qla4xxx_setup_boot_info(struct scsi_qla_host *ha)
3621 struct iscsi_boot_kobj *boot_kobj;
3623 if (qla4xxx_get_boot_info(ha) != QLA_SUCCESS)
3626 if (ql4xdisablesysfsboot) {
3627 ql4_printk(KERN_INFO, ha,
3628 "%s: syfsboot disabled - driver will trigger login"
3629 "and publish session for discovery .\n", __func__);
3634 ha->boot_kset = iscsi_boot_create_host_kset(ha->host->host_no);
3638 if (!scsi_host_get(ha->host))
3640 boot_kobj = iscsi_boot_create_target(ha->boot_kset, 0, ha,
3641 qla4xxx_show_boot_tgt_pri_info,
3642 qla4xxx_tgt_get_attr_visibility,
3643 qla4xxx_boot_release);
3647 if (!scsi_host_get(ha->host))
3649 boot_kobj = iscsi_boot_create_target(ha->boot_kset, 1, ha,
3650 qla4xxx_show_boot_tgt_sec_info,
3651 qla4xxx_tgt_get_attr_visibility,
3652 qla4xxx_boot_release);
3656 if (!scsi_host_get(ha->host))
3658 boot_kobj = iscsi_boot_create_initiator(ha->boot_kset, 0, ha,
3659 qla4xxx_show_boot_ini_info,
3660 qla4xxx_ini_get_attr_visibility,
3661 qla4xxx_boot_release);
3665 if (!scsi_host_get(ha->host))
3667 boot_kobj = iscsi_boot_create_ethernet(ha->boot_kset, 0, ha,
3668 qla4xxx_show_boot_eth_info,
3669 qla4xxx_eth_get_attr_visibility,
3670 qla4xxx_boot_release);
3677 scsi_host_put(ha->host);
3679 iscsi_boot_destroy_kset(ha->boot_kset);
3685 * qla4xxx_create chap_list - Create CHAP list from FLASH
3686 * @ha: pointer to adapter structure
3688 * Read flash and make a list of CHAP entries, during login when a CHAP entry
3689 * is received, it will be checked in this list. If entry exist then the CHAP
3690 * entry index is set in the DDB. If CHAP entry does not exist in this list
3691 * then a new entry is added in FLASH in CHAP table and the index obtained is
3694 static void qla4xxx_create_chap_list(struct scsi_qla_host *ha)
3697 uint8_t *chap_flash_data = NULL;
3699 dma_addr_t chap_dma;
3700 uint32_t chap_size = 0;
3703 chap_size = MAX_CHAP_ENTRIES_40XX *
3704 sizeof(struct ql4_chap_table);
3705 else /* Single region contains CHAP info for both
3706 * ports which is divided into half for each port.
3708 chap_size = ha->hw.flt_chap_size / 2;
3710 chap_flash_data = dma_alloc_coherent(&ha->pdev->dev, chap_size,
3711 &chap_dma, GFP_KERNEL);
3712 if (!chap_flash_data) {
3713 ql4_printk(KERN_ERR, ha, "No memory for chap_flash_data\n");
3717 offset = FLASH_CHAP_OFFSET;
3719 offset = FLASH_RAW_ACCESS_ADDR + (ha->hw.flt_region_chap << 2);
3720 if (ha->port_num == 1)
3721 offset += chap_size;
3724 rval = qla4xxx_get_flash(ha, chap_dma, offset, chap_size);
3725 if (rval != QLA_SUCCESS)
3726 goto exit_chap_list;
3728 if (ha->chap_list == NULL)
3729 ha->chap_list = vmalloc(chap_size);
3730 if (ha->chap_list == NULL) {
3731 ql4_printk(KERN_ERR, ha, "No memory for ha->chap_list\n");
3732 goto exit_chap_list;
3735 memcpy(ha->chap_list, chap_flash_data, chap_size);
3738 dma_free_coherent(&ha->pdev->dev, chap_size,
3739 chap_flash_data, chap_dma);
3742 static void qla4xxx_get_param_ddb(struct ddb_entry *ddb_entry,
3743 struct ql4_tuple_ddb *tddb)
3745 struct scsi_qla_host *ha;
3746 struct iscsi_cls_session *cls_sess;
3747 struct iscsi_cls_conn *cls_conn;
3748 struct iscsi_session *sess;
3749 struct iscsi_conn *conn;
3751 DEBUG2(printk(KERN_INFO "Func: %s\n", __func__));
3753 cls_sess = ddb_entry->sess;
3754 sess = cls_sess->dd_data;
3755 cls_conn = ddb_entry->conn;
3756 conn = cls_conn->dd_data;
3758 tddb->tpgt = sess->tpgt;
3759 tddb->port = conn->persistent_port;
3760 strncpy(tddb->iscsi_name, sess->targetname, ISCSI_NAME_SIZE);
3761 strncpy(tddb->ip_addr, conn->persistent_address, DDB_IPADDR_LEN);
3764 static void qla4xxx_convert_param_ddb(struct dev_db_entry *fw_ddb_entry,
3765 struct ql4_tuple_ddb *tddb)
3767 uint16_t options = 0;
3769 tddb->tpgt = le32_to_cpu(fw_ddb_entry->tgt_portal_grp);
3770 memcpy(&tddb->iscsi_name[0], &fw_ddb_entry->iscsi_name[0],
3771 min(sizeof(tddb->iscsi_name), sizeof(fw_ddb_entry->iscsi_name)));
3773 options = le16_to_cpu(fw_ddb_entry->options);
3774 if (options & DDB_OPT_IPV6_DEVICE)
3775 sprintf(tddb->ip_addr, "%pI6", fw_ddb_entry->ip_addr);
3777 sprintf(tddb->ip_addr, "%pI4", fw_ddb_entry->ip_addr);
3779 tddb->port = le16_to_cpu(fw_ddb_entry->port);
3782 static int qla4xxx_compare_tuple_ddb(struct scsi_qla_host *ha,
3783 struct ql4_tuple_ddb *old_tddb,
3784 struct ql4_tuple_ddb *new_tddb)
3786 if (strcmp(old_tddb->iscsi_name, new_tddb->iscsi_name))
3789 if (strcmp(old_tddb->ip_addr, new_tddb->ip_addr))
3792 if (old_tddb->port != new_tddb->port)
3795 DEBUG2(ql4_printk(KERN_INFO, ha,
3796 "Match Found, fw[%d,%d,%s,%s], [%d,%d,%s,%s]",
3797 old_tddb->port, old_tddb->tpgt, old_tddb->ip_addr,
3798 old_tddb->iscsi_name, new_tddb->port, new_tddb->tpgt,
3799 new_tddb->ip_addr, new_tddb->iscsi_name));
3804 static int qla4xxx_is_session_exists(struct scsi_qla_host *ha,
3805 struct dev_db_entry *fw_ddb_entry)
3807 struct ddb_entry *ddb_entry;
3808 struct ql4_tuple_ddb *fw_tddb = NULL;
3809 struct ql4_tuple_ddb *tmp_tddb = NULL;
3811 int ret = QLA_ERROR;
3813 fw_tddb = vzalloc(sizeof(*fw_tddb));
3815 DEBUG2(ql4_printk(KERN_WARNING, ha,
3816 "Memory Allocation failed.\n"));
3821 tmp_tddb = vzalloc(sizeof(*tmp_tddb));
3823 DEBUG2(ql4_printk(KERN_WARNING, ha,
3824 "Memory Allocation failed.\n"));
3829 qla4xxx_convert_param_ddb(fw_ddb_entry, fw_tddb);
3831 for (idx = 0; idx < MAX_DDB_ENTRIES; idx++) {
3832 ddb_entry = qla4xxx_lookup_ddb_by_fw_index(ha, idx);
3833 if (ddb_entry == NULL)
3836 qla4xxx_get_param_ddb(ddb_entry, tmp_tddb);
3837 if (!qla4xxx_compare_tuple_ddb(ha, fw_tddb, tmp_tddb)) {
3838 ret = QLA_SUCCESS; /* found */
3851 static int qla4xxx_is_flash_ddb_exists(struct scsi_qla_host *ha,
3852 struct list_head *list_nt,
3853 struct dev_db_entry *fw_ddb_entry)
3855 struct qla_ddb_index *nt_ddb_idx, *nt_ddb_idx_tmp;
3856 struct ql4_tuple_ddb *fw_tddb = NULL;
3857 struct ql4_tuple_ddb *tmp_tddb = NULL;
3858 int ret = QLA_ERROR;
3860 fw_tddb = vzalloc(sizeof(*fw_tddb));
3862 DEBUG2(ql4_printk(KERN_WARNING, ha,
3863 "Memory Allocation failed.\n"));
3868 tmp_tddb = vzalloc(sizeof(*tmp_tddb));
3870 DEBUG2(ql4_printk(KERN_WARNING, ha,
3871 "Memory Allocation failed.\n"));
3876 qla4xxx_convert_param_ddb(fw_ddb_entry, fw_tddb);
3878 list_for_each_entry_safe(nt_ddb_idx, nt_ddb_idx_tmp, list_nt, list) {
3879 qla4xxx_convert_param_ddb(&nt_ddb_idx->fw_ddb, tmp_tddb);
3880 if (!qla4xxx_compare_tuple_ddb(ha, fw_tddb, tmp_tddb)) {
3881 ret = QLA_SUCCESS; /* found */
3894 static void qla4xxx_free_ddb_list(struct list_head *list_ddb)
3896 struct qla_ddb_index *ddb_idx, *ddb_idx_tmp;
3898 list_for_each_entry_safe(ddb_idx, ddb_idx_tmp, list_ddb, list) {
3899 list_del_init(&ddb_idx->list);
3904 static struct iscsi_endpoint *qla4xxx_get_ep_fwdb(struct scsi_qla_host *ha,
3905 struct dev_db_entry *fw_ddb_entry)
3907 struct iscsi_endpoint *ep;
3908 struct sockaddr_in *addr;
3909 struct sockaddr_in6 *addr6;
3910 struct sockaddr *dst_addr;
3913 /* TODO: need to destroy on unload iscsi_endpoint*/
3914 dst_addr = vmalloc(sizeof(*dst_addr));
3918 if (fw_ddb_entry->options & DDB_OPT_IPV6_DEVICE) {
3919 dst_addr->sa_family = AF_INET6;
3920 addr6 = (struct sockaddr_in6 *)dst_addr;
3921 ip = (char *)&addr6->sin6_addr;
3922 memcpy(ip, fw_ddb_entry->ip_addr, IPv6_ADDR_LEN);
3923 addr6->sin6_port = htons(le16_to_cpu(fw_ddb_entry->port));
3926 dst_addr->sa_family = AF_INET;
3927 addr = (struct sockaddr_in *)dst_addr;
3928 ip = (char *)&addr->sin_addr;
3929 memcpy(ip, fw_ddb_entry->ip_addr, IP_ADDR_LEN);
3930 addr->sin_port = htons(le16_to_cpu(fw_ddb_entry->port));
3933 ep = qla4xxx_ep_connect(ha->host, dst_addr, 0);
3938 static int qla4xxx_verify_boot_idx(struct scsi_qla_host *ha, uint16_t idx)
3940 if (ql4xdisablesysfsboot)
3942 if (idx == ha->pri_ddb_idx || idx == ha->sec_ddb_idx)
3947 static void qla4xxx_setup_flash_ddb_entry(struct scsi_qla_host *ha,
3948 struct ddb_entry *ddb_entry)
3950 uint16_t def_timeout;
3952 ddb_entry->ddb_type = FLASH_DDB;
3953 ddb_entry->fw_ddb_index = INVALID_ENTRY;
3954 ddb_entry->fw_ddb_device_state = DDB_DS_NO_CONNECTION_ACTIVE;
3956 ddb_entry->unblock_sess = qla4xxx_unblock_flash_ddb;
3957 ddb_entry->ddb_change = qla4xxx_flash_ddb_change;
3959 atomic_set(&ddb_entry->retry_relogin_timer, INVALID_ENTRY);
3960 atomic_set(&ddb_entry->relogin_timer, 0);
3961 atomic_set(&ddb_entry->relogin_retry_count, 0);
3962 def_timeout = le16_to_cpu(ddb_entry->fw_ddb_entry.def_timeout);
3963 ddb_entry->default_relogin_timeout =
3964 (def_timeout > LOGIN_TOV) && (def_timeout < LOGIN_TOV * 10) ?
3965 def_timeout : LOGIN_TOV;
3966 ddb_entry->default_time2wait =
3967 le16_to_cpu(ddb_entry->fw_ddb_entry.iscsi_def_time2wait);
3970 static void qla4xxx_wait_for_ip_configuration(struct scsi_qla_host *ha)
3973 uint32_t ip_idx[IP_ADDR_COUNT] = {0, 1, 2, 3}; /* 4 IP interfaces */
3974 uint32_t sts[MBOX_REG_COUNT];
3976 unsigned long wtime;
3979 wtime = jiffies + (HZ * IP_CONFIG_TOV);
3981 for (idx = 0; idx < IP_ADDR_COUNT; idx++) {
3982 if (ip_idx[idx] == -1)
3985 ret = qla4xxx_get_ip_state(ha, 0, ip_idx[idx], sts);
3987 if (ret == QLA_ERROR) {
3992 ip_state = (sts[1] & IP_STATE_MASK) >> IP_STATE_SHIFT;
3994 DEBUG2(ql4_printk(KERN_INFO, ha,
3995 "Waiting for IP state for idx = %d, state = 0x%x\n",
3996 ip_idx[idx], ip_state));
3997 if (ip_state == IP_ADDRSTATE_UNCONFIGURED ||
3998 ip_state == IP_ADDRSTATE_INVALID ||
3999 ip_state == IP_ADDRSTATE_PREFERRED ||
4000 ip_state == IP_ADDRSTATE_DEPRICATED ||
4001 ip_state == IP_ADDRSTATE_DISABLING)
4005 /* Break if all IP states checked */
4006 if ((ip_idx[0] == -1) &&
4007 (ip_idx[1] == -1) &&
4008 (ip_idx[2] == -1) &&
4011 schedule_timeout_uninterruptible(HZ);
4012 } while (time_after(wtime, jiffies));
4015 static void qla4xxx_build_st_list(struct scsi_qla_host *ha,
4016 struct list_head *list_st)
4018 struct qla_ddb_index *st_ddb_idx;
4021 struct dev_db_entry *fw_ddb_entry;
4022 dma_addr_t fw_ddb_dma;
4024 uint32_t idx = 0, next_idx = 0;
4025 uint32_t state = 0, conn_err = 0;
4026 uint16_t conn_id = 0;
4028 fw_ddb_entry = dma_pool_alloc(ha->fw_ddb_dma_pool, GFP_KERNEL,
4030 if (fw_ddb_entry == NULL) {
4031 DEBUG2(ql4_printk(KERN_ERR, ha, "Out of memory\n"));
4035 max_ddbs = is_qla40XX(ha) ? MAX_DEV_DB_ENTRIES_40XX :
4037 fw_idx_size = sizeof(struct qla_ddb_index);
4039 for (idx = 0; idx < max_ddbs; idx = next_idx) {
4040 ret = qla4xxx_get_fwddb_entry(ha, idx, fw_ddb_entry, fw_ddb_dma,
4041 NULL, &next_idx, &state,
4042 &conn_err, NULL, &conn_id);
4043 if (ret == QLA_ERROR)
4046 /* Check if ST, add to the list_st */
4047 if (strlen((char *) fw_ddb_entry->iscsi_name) != 0)
4048 goto continue_next_st;
4050 st_ddb_idx = vzalloc(fw_idx_size);
4054 st_ddb_idx->fw_ddb_idx = idx;
4056 list_add_tail(&st_ddb_idx->list, list_st);
4064 dma_pool_free(ha->fw_ddb_dma_pool, fw_ddb_entry, fw_ddb_dma);
4068 * qla4xxx_remove_failed_ddb - Remove inactive or failed ddb from list
4069 * @ha: pointer to adapter structure
4070 * @list_ddb: List from which failed ddb to be removed
4072 * Iterate over the list of DDBs and find and remove DDBs that are either in
4073 * no connection active state or failed state
4075 static void qla4xxx_remove_failed_ddb(struct scsi_qla_host *ha,
4076 struct list_head *list_ddb)
4078 struct qla_ddb_index *ddb_idx, *ddb_idx_tmp;
4079 uint32_t next_idx = 0;
4080 uint32_t state = 0, conn_err = 0;
4083 list_for_each_entry_safe(ddb_idx, ddb_idx_tmp, list_ddb, list) {
4084 ret = qla4xxx_get_fwddb_entry(ha, ddb_idx->fw_ddb_idx,
4085 NULL, 0, NULL, &next_idx, &state,
4086 &conn_err, NULL, NULL);
4087 if (ret == QLA_ERROR)
4090 if (state == DDB_DS_NO_CONNECTION_ACTIVE ||
4091 state == DDB_DS_SESSION_FAILED) {
4092 list_del_init(&ddb_idx->list);
4098 static int qla4xxx_sess_conn_setup(struct scsi_qla_host *ha,
4099 struct dev_db_entry *fw_ddb_entry,
4102 struct iscsi_cls_session *cls_sess;
4103 struct iscsi_session *sess;
4104 struct iscsi_cls_conn *cls_conn;
4105 struct iscsi_endpoint *ep;
4106 uint16_t cmds_max = 32;
4107 uint16_t conn_id = 0;
4108 uint32_t initial_cmdsn = 0;
4109 int ret = QLA_SUCCESS;
4111 struct ddb_entry *ddb_entry = NULL;
4113 /* Create session object, with INVALID_ENTRY,
4114 * the targer_id would get set when we issue the login
4116 cls_sess = iscsi_session_setup(&qla4xxx_iscsi_transport, ha->host,
4117 cmds_max, sizeof(struct ddb_entry),
4118 sizeof(struct ql4_task_data),
4119 initial_cmdsn, INVALID_ENTRY);
4126 * so calling module_put function to decrement the
4129 module_put(qla4xxx_iscsi_transport.owner);
4130 sess = cls_sess->dd_data;
4131 ddb_entry = sess->dd_data;
4132 ddb_entry->sess = cls_sess;
4134 cls_sess->recovery_tmo = ql4xsess_recovery_tmo;
4135 memcpy(&ddb_entry->fw_ddb_entry, fw_ddb_entry,
4136 sizeof(struct dev_db_entry));
4138 qla4xxx_setup_flash_ddb_entry(ha, ddb_entry);
4140 cls_conn = iscsi_conn_setup(cls_sess, sizeof(struct qla_conn), conn_id);
4147 ddb_entry->conn = cls_conn;
4149 /* Setup ep, for displaying attributes in sysfs */
4150 ep = qla4xxx_get_ep_fwdb(ha, fw_ddb_entry);
4152 ep->conn = cls_conn;
4155 DEBUG2(ql4_printk(KERN_ERR, ha, "Unable to get ep\n"));
4160 /* Update sess/conn params */
4161 qla4xxx_copy_fwddb_param(ha, fw_ddb_entry, cls_sess, cls_conn);
4163 if (is_reset == RESET_ADAPTER) {
4164 iscsi_block_session(cls_sess);
4165 /* Use the relogin path to discover new devices
4166 * by short-circuting the logic of setting
4167 * timer to relogin - instead set the flags
4168 * to initiate login right away.
4170 set_bit(DPC_RELOGIN_DEVICE, &ha->dpc_flags);
4171 set_bit(DF_RELOGIN, &ddb_entry->flags);
4178 static void qla4xxx_build_nt_list(struct scsi_qla_host *ha,
4179 struct list_head *list_nt, int is_reset)
4181 struct dev_db_entry *fw_ddb_entry;
4182 dma_addr_t fw_ddb_dma;
4186 uint32_t idx = 0, next_idx = 0;
4187 uint32_t state = 0, conn_err = 0;
4188 uint16_t conn_id = 0;
4189 struct qla_ddb_index *nt_ddb_idx;
4191 fw_ddb_entry = dma_pool_alloc(ha->fw_ddb_dma_pool, GFP_KERNEL,
4193 if (fw_ddb_entry == NULL) {
4194 DEBUG2(ql4_printk(KERN_ERR, ha, "Out of memory\n"));
4197 max_ddbs = is_qla40XX(ha) ? MAX_DEV_DB_ENTRIES_40XX :
4199 fw_idx_size = sizeof(struct qla_ddb_index);
4201 for (idx = 0; idx < max_ddbs; idx = next_idx) {
4202 ret = qla4xxx_get_fwddb_entry(ha, idx, fw_ddb_entry, fw_ddb_dma,
4203 NULL, &next_idx, &state,
4204 &conn_err, NULL, &conn_id);
4205 if (ret == QLA_ERROR)
4208 if (qla4xxx_verify_boot_idx(ha, idx) != QLA_SUCCESS)
4209 goto continue_next_nt;
4211 /* Check if NT, then add to list it */
4212 if (strlen((char *) fw_ddb_entry->iscsi_name) == 0)
4213 goto continue_next_nt;
4215 if (!(state == DDB_DS_NO_CONNECTION_ACTIVE ||
4216 state == DDB_DS_SESSION_FAILED))
4217 goto continue_next_nt;
4219 DEBUG2(ql4_printk(KERN_INFO, ha,
4220 "Adding DDB to session = 0x%x\n", idx));
4221 if (is_reset == INIT_ADAPTER) {
4222 nt_ddb_idx = vmalloc(fw_idx_size);
4226 nt_ddb_idx->fw_ddb_idx = idx;
4228 memcpy(&nt_ddb_idx->fw_ddb, fw_ddb_entry,
4229 sizeof(struct dev_db_entry));
4231 if (qla4xxx_is_flash_ddb_exists(ha, list_nt,
4232 fw_ddb_entry) == QLA_SUCCESS) {
4234 goto continue_next_nt;
4236 list_add_tail(&nt_ddb_idx->list, list_nt);
4237 } else if (is_reset == RESET_ADAPTER) {
4238 if (qla4xxx_is_session_exists(ha, fw_ddb_entry) ==
4240 goto continue_next_nt;
4243 ret = qla4xxx_sess_conn_setup(ha, fw_ddb_entry, is_reset);
4244 if (ret == QLA_ERROR)
4254 dma_pool_free(ha->fw_ddb_dma_pool, fw_ddb_entry, fw_ddb_dma);
4258 * qla4xxx_build_ddb_list - Build ddb list and setup sessions
4259 * @ha: pointer to adapter structure
4260 * @is_reset: Is this init path or reset path
4262 * Create a list of sendtargets (st) from firmware DDBs, issue send targets
4263 * using connection open, then create the list of normal targets (nt)
4264 * from firmware DDBs. Based on the list of nt setup session and connection
4267 void qla4xxx_build_ddb_list(struct scsi_qla_host *ha, int is_reset)
4270 struct list_head list_st, list_nt;
4271 struct qla_ddb_index *st_ddb_idx, *st_ddb_idx_tmp;
4272 unsigned long wtime;
4274 if (!test_bit(AF_LINK_UP, &ha->flags)) {
4275 set_bit(AF_BUILD_DDB_LIST, &ha->flags);
4276 ha->is_reset = is_reset;
4280 INIT_LIST_HEAD(&list_st);
4281 INIT_LIST_HEAD(&list_nt);
4283 qla4xxx_build_st_list(ha, &list_st);
4285 /* Before issuing conn open mbox, ensure all IPs states are configured
4286 * Note, conn open fails if IPs are not configured
4288 qla4xxx_wait_for_ip_configuration(ha);
4290 /* Go thru the STs and fire the sendtargets by issuing conn open mbx */
4291 list_for_each_entry_safe(st_ddb_idx, st_ddb_idx_tmp, &list_st, list) {
4292 qla4xxx_conn_open(ha, st_ddb_idx->fw_ddb_idx);
4295 /* Wait to ensure all sendtargets are done for min 12 sec wait */
4296 tmo = ((ha->def_timeout > LOGIN_TOV) &&
4297 (ha->def_timeout < LOGIN_TOV * 10) ?
4298 ha->def_timeout : LOGIN_TOV);
4300 DEBUG2(ql4_printk(KERN_INFO, ha,
4301 "Default time to wait for build ddb %d\n", tmo));
4303 wtime = jiffies + (HZ * tmo);
4305 if (list_empty(&list_st))
4308 qla4xxx_remove_failed_ddb(ha, &list_st);
4309 schedule_timeout_uninterruptible(HZ / 10);
4310 } while (time_after(wtime, jiffies));
4312 /* Free up the sendtargets list */
4313 qla4xxx_free_ddb_list(&list_st);
4315 qla4xxx_build_nt_list(ha, &list_nt, is_reset);
4317 qla4xxx_free_ddb_list(&list_nt);
4319 qla4xxx_free_ddb_index(ha);
4323 * qla4xxx_probe_adapter - callback function to probe HBA
4324 * @pdev: pointer to pci_dev structure
4325 * @pci_device_id: pointer to pci_device entry
4327 * This routine will probe for Qlogic 4xxx iSCSI host adapters.
4328 * It returns zero if successful. It also initializes all data necessary for
4331 static int __devinit qla4xxx_probe_adapter(struct pci_dev *pdev,
4332 const struct pci_device_id *ent)
4334 int ret = -ENODEV, status;
4335 struct Scsi_Host *host;
4336 struct scsi_qla_host *ha;
4337 uint8_t init_retry_count = 0;
4339 struct qla4_8xxx_legacy_intr_set *nx_legacy_intr;
4342 if (pci_enable_device(pdev))
4345 host = iscsi_host_alloc(&qla4xxx_driver_template, sizeof(*ha), 0);
4348 "qla4xxx: Couldn't allocate host from scsi layer!\n");
4349 goto probe_disable_device;
4352 /* Clear our data area */
4353 ha = to_qla_host(host);
4354 memset(ha, 0, sizeof(*ha));
4356 /* Save the information from PCI BIOS. */
4359 ha->host_no = host->host_no;
4361 pci_enable_pcie_error_reporting(pdev);
4363 /* Setup Runtime configurable options */
4364 if (is_qla8022(ha)) {
4365 ha->isp_ops = &qla4_8xxx_isp_ops;
4366 rwlock_init(&ha->hw_lock);
4367 ha->qdr_sn_window = -1;
4368 ha->ddr_mn_window = -1;
4369 ha->curr_window = 255;
4370 ha->func_num = PCI_FUNC(ha->pdev->devfn);
4371 nx_legacy_intr = &legacy_intr[ha->func_num];
4372 ha->nx_legacy_intr.int_vec_bit = nx_legacy_intr->int_vec_bit;
4373 ha->nx_legacy_intr.tgt_status_reg =
4374 nx_legacy_intr->tgt_status_reg;
4375 ha->nx_legacy_intr.tgt_mask_reg = nx_legacy_intr->tgt_mask_reg;
4376 ha->nx_legacy_intr.pci_int_reg = nx_legacy_intr->pci_int_reg;
4378 ha->isp_ops = &qla4xxx_isp_ops;
4381 /* Set EEH reset type to fundamental if required by hba */
4383 pdev->needs_freset = 1;
4385 /* Configure PCI I/O space. */
4386 ret = ha->isp_ops->iospace_config(ha);
4388 goto probe_failed_ioconfig;
4390 ql4_printk(KERN_INFO, ha, "Found an ISP%04x, irq %d, iobase 0x%p\n",
4391 pdev->device, pdev->irq, ha->reg);
4393 qla4xxx_config_dma_addressing(ha);
4395 /* Initialize lists and spinlocks. */
4396 INIT_LIST_HEAD(&ha->free_srb_q);
4398 mutex_init(&ha->mbox_sem);
4399 mutex_init(&ha->chap_sem);
4400 init_completion(&ha->mbx_intr_comp);
4401 init_completion(&ha->disable_acb_comp);
4403 spin_lock_init(&ha->hardware_lock);
4405 /* Allocate dma buffers */
4406 if (qla4xxx_mem_alloc(ha)) {
4407 ql4_printk(KERN_WARNING, ha,
4408 "[ERROR] Failed to allocate memory for adapter\n");
4414 host->cmd_per_lun = 3;
4415 host->max_channel = 0;
4416 host->max_lun = MAX_LUNS - 1;
4417 host->max_id = MAX_TARGETS;
4418 host->max_cmd_len = IOCB_MAX_CDB_LEN;
4419 host->can_queue = MAX_SRBS ;
4420 host->transportt = qla4xxx_scsi_transport;
4422 ret = scsi_init_shared_tag_map(host, MAX_SRBS);
4424 ql4_printk(KERN_WARNING, ha,
4425 "%s: scsi_init_shared_tag_map failed\n", __func__);
4429 pci_set_drvdata(pdev, ha);
4431 ret = scsi_add_host(host, &pdev->dev);
4436 (void) qla4_8xxx_get_flash_info(ha);
4439 * Initialize the Host adapter request/response queues and
4441 * NOTE: interrupts enabled upon successful completion
4443 status = qla4xxx_initialize_adapter(ha, INIT_ADAPTER);
4444 while ((!test_bit(AF_ONLINE, &ha->flags)) &&
4445 init_retry_count++ < MAX_INIT_RETRIES) {
4447 if (is_qla8022(ha)) {
4448 qla4_8xxx_idc_lock(ha);
4449 dev_state = qla4_8xxx_rd_32(ha, QLA82XX_CRB_DEV_STATE);
4450 qla4_8xxx_idc_unlock(ha);
4451 if (dev_state == QLA82XX_DEV_FAILED) {
4452 ql4_printk(KERN_WARNING, ha, "%s: don't retry "
4453 "initialize adapter. H/W is in failed state\n",
4458 DEBUG2(printk("scsi: %s: retrying adapter initialization "
4459 "(%d)\n", __func__, init_retry_count));
4461 if (ha->isp_ops->reset_chip(ha) == QLA_ERROR)
4464 status = qla4xxx_initialize_adapter(ha, INIT_ADAPTER);
4467 if (!test_bit(AF_ONLINE, &ha->flags)) {
4468 ql4_printk(KERN_WARNING, ha, "Failed to initialize adapter\n");
4470 if (is_qla8022(ha) && ql4xdontresethba) {
4471 /* Put the device in failed state. */
4472 DEBUG2(printk(KERN_ERR "HW STATE: FAILED\n"));
4473 qla4_8xxx_idc_lock(ha);
4474 qla4_8xxx_wr_32(ha, QLA82XX_CRB_DEV_STATE,
4475 QLA82XX_DEV_FAILED);
4476 qla4_8xxx_idc_unlock(ha);
4482 /* Startup the kernel thread for this host adapter. */
4483 DEBUG2(printk("scsi: %s: Starting kernel thread for "
4484 "qla4xxx_dpc\n", __func__));
4485 sprintf(buf, "qla4xxx_%lu_dpc", ha->host_no);
4486 ha->dpc_thread = create_singlethread_workqueue(buf);
4487 if (!ha->dpc_thread) {
4488 ql4_printk(KERN_WARNING, ha, "Unable to start DPC thread!\n");
4492 INIT_WORK(&ha->dpc_work, qla4xxx_do_dpc);
4494 sprintf(buf, "qla4xxx_%lu_task", ha->host_no);
4495 ha->task_wq = alloc_workqueue(buf, WQ_MEM_RECLAIM, 1);
4497 ql4_printk(KERN_WARNING, ha, "Unable to start task thread!\n");
4502 /* For ISP-82XX, request_irqs is called in qla4_8xxx_load_risc
4503 * (which is called indirectly by qla4xxx_initialize_adapter),
4504 * so that irqs will be registered after crbinit but before
4507 if (!is_qla8022(ha)) {
4508 ret = qla4xxx_request_irqs(ha);
4510 ql4_printk(KERN_WARNING, ha, "Failed to reserve "
4511 "interrupt %d already in use.\n", pdev->irq);
4516 pci_save_state(ha->pdev);
4517 ha->isp_ops->enable_intrs(ha);
4519 /* Start timer thread. */
4520 qla4xxx_start_timer(ha, qla4xxx_timer, 1);
4522 set_bit(AF_INIT_DONE, &ha->flags);
4525 " QLogic iSCSI HBA Driver version: %s\n"
4526 " QLogic ISP%04x @ %s, host#=%ld, fw=%02d.%02d.%02d.%02d\n",
4527 qla4xxx_version_str, ha->pdev->device, pci_name(ha->pdev),
4528 ha->host_no, ha->firmware_version[0], ha->firmware_version[1],
4529 ha->patch_number, ha->build_number);
4531 if (qla4xxx_setup_boot_info(ha))
4532 ql4_printk(KERN_ERR, ha, "%s:ISCSI boot info setup failed\n",
4535 /* Perform the build ddb list and login to each */
4536 qla4xxx_build_ddb_list(ha, INIT_ADAPTER);
4537 iscsi_host_for_each_session(ha->host, qla4xxx_login_flash_ddb);
4539 qla4xxx_create_chap_list(ha);
4541 qla4xxx_create_ifaces(ha);
4545 scsi_remove_host(ha->host);
4548 qla4xxx_free_adapter(ha);
4550 probe_failed_ioconfig:
4551 pci_disable_pcie_error_reporting(pdev);
4552 scsi_host_put(ha->host);
4554 probe_disable_device:
4555 pci_disable_device(pdev);
4561 * qla4xxx_prevent_other_port_reinit - prevent other port from re-initialize
4562 * @ha: pointer to adapter structure
4564 * Mark the other ISP-4xxx port to indicate that the driver is being removed,
4565 * so that the other port will not re-initialize while in the process of
4566 * removing the ha due to driver unload or hba hotplug.
4568 static void qla4xxx_prevent_other_port_reinit(struct scsi_qla_host *ha)
4570 struct scsi_qla_host *other_ha = NULL;
4571 struct pci_dev *other_pdev = NULL;
4572 int fn = ISP4XXX_PCI_FN_2;
4574 /*iscsi function numbers for ISP4xxx is 1 and 3*/
4575 if (PCI_FUNC(ha->pdev->devfn) & BIT_1)
4576 fn = ISP4XXX_PCI_FN_1;
4579 pci_get_domain_bus_and_slot(pci_domain_nr(ha->pdev->bus),
4580 ha->pdev->bus->number, PCI_DEVFN(PCI_SLOT(ha->pdev->devfn),
4583 /* Get other_ha if other_pdev is valid and state is enable*/
4585 if (atomic_read(&other_pdev->enable_cnt)) {
4586 other_ha = pci_get_drvdata(other_pdev);
4588 set_bit(AF_HA_REMOVAL, &other_ha->flags);
4589 DEBUG2(ql4_printk(KERN_INFO, ha, "%s: "
4590 "Prevent %s reinit\n", __func__,
4591 dev_name(&other_ha->pdev->dev)));
4594 pci_dev_put(other_pdev);
4598 static void qla4xxx_destroy_fw_ddb_session(struct scsi_qla_host *ha)
4600 struct ddb_entry *ddb_entry;
4604 for (idx = 0; idx < MAX_DDB_ENTRIES; idx++) {
4606 ddb_entry = qla4xxx_lookup_ddb_by_fw_index(ha, idx);
4607 if ((ddb_entry != NULL) &&
4608 (ddb_entry->ddb_type == FLASH_DDB)) {
4610 options = LOGOUT_OPTION_CLOSE_SESSION;
4611 if (qla4xxx_session_logout_ddb(ha, ddb_entry, options)
4613 ql4_printk(KERN_ERR, ha, "%s: Logout failed\n",
4616 qla4xxx_clear_ddb_entry(ha, ddb_entry->fw_ddb_index);
4618 * we have decremented the reference count of the driver
4619 * when we setup the session to have the driver unload
4620 * to be seamless without actually destroying the
4623 try_module_get(qla4xxx_iscsi_transport.owner);
4624 iscsi_destroy_endpoint(ddb_entry->conn->ep);
4625 qla4xxx_free_ddb(ha, ddb_entry);
4626 iscsi_session_teardown(ddb_entry->sess);
4631 * qla4xxx_remove_adapter - calback function to remove adapter.
4632 * @pci_dev: PCI device pointer
4634 static void __devexit qla4xxx_remove_adapter(struct pci_dev *pdev)
4636 struct scsi_qla_host *ha;
4638 ha = pci_get_drvdata(pdev);
4640 if (!is_qla8022(ha))
4641 qla4xxx_prevent_other_port_reinit(ha);
4643 /* destroy iface from sysfs */
4644 qla4xxx_destroy_ifaces(ha);
4646 if ((!ql4xdisablesysfsboot) && ha->boot_kset)
4647 iscsi_boot_destroy_kset(ha->boot_kset);
4649 qla4xxx_destroy_fw_ddb_session(ha);
4651 scsi_remove_host(ha->host);
4653 qla4xxx_free_adapter(ha);
4655 scsi_host_put(ha->host);
4657 pci_disable_pcie_error_reporting(pdev);
4658 pci_disable_device(pdev);
4659 pci_set_drvdata(pdev, NULL);
4663 * qla4xxx_config_dma_addressing() - Configure OS DMA addressing method.
4666 * At exit, the @ha's flags.enable_64bit_addressing set to indicated
4667 * supported addressing method.
4669 static void qla4xxx_config_dma_addressing(struct scsi_qla_host *ha)
4673 /* Update our PCI device dma_mask for full 64 bit mask */
4674 if (pci_set_dma_mask(ha->pdev, DMA_BIT_MASK(64)) == 0) {
4675 if (pci_set_consistent_dma_mask(ha->pdev, DMA_BIT_MASK(64))) {
4676 dev_dbg(&ha->pdev->dev,
4677 "Failed to set 64 bit PCI consistent mask; "
4679 retval = pci_set_consistent_dma_mask(ha->pdev,
4683 retval = pci_set_dma_mask(ha->pdev, DMA_BIT_MASK(32));
4686 static int qla4xxx_slave_alloc(struct scsi_device *sdev)
4688 struct iscsi_cls_session *cls_sess;
4689 struct iscsi_session *sess;
4690 struct ddb_entry *ddb;
4691 int queue_depth = QL4_DEF_QDEPTH;
4693 cls_sess = starget_to_session(sdev->sdev_target);
4694 sess = cls_sess->dd_data;
4695 ddb = sess->dd_data;
4697 sdev->hostdata = ddb;
4698 sdev->tagged_supported = 1;
4700 if (ql4xmaxqdepth != 0 && ql4xmaxqdepth <= 0xffffU)
4701 queue_depth = ql4xmaxqdepth;
4703 scsi_activate_tcq(sdev, queue_depth);
4707 static int qla4xxx_slave_configure(struct scsi_device *sdev)
4709 sdev->tagged_supported = 1;
4713 static void qla4xxx_slave_destroy(struct scsi_device *sdev)
4715 scsi_deactivate_tcq(sdev, 1);
4719 * qla4xxx_del_from_active_array - returns an active srb
4720 * @ha: Pointer to host adapter structure.
4721 * @index: index into the active_array
4723 * This routine removes and returns the srb at the specified index
4725 struct srb *qla4xxx_del_from_active_array(struct scsi_qla_host *ha,
4728 struct srb *srb = NULL;
4729 struct scsi_cmnd *cmd = NULL;
4731 cmd = scsi_host_find_tag(ha->host, index);
4735 srb = (struct srb *)CMD_SP(cmd);
4739 /* update counters */
4740 if (srb->flags & SRB_DMA_VALID) {
4741 ha->req_q_count += srb->iocb_cnt;
4742 ha->iocb_cnt -= srb->iocb_cnt;
4744 srb->cmd->host_scribble =
4745 (unsigned char *)(unsigned long) MAX_SRBS;
4751 * qla4xxx_eh_wait_on_command - waits for command to be returned by firmware
4752 * @ha: Pointer to host adapter structure.
4753 * @cmd: Scsi Command to wait on.
4755 * This routine waits for the command to be returned by the Firmware
4756 * for some max time.
4758 static int qla4xxx_eh_wait_on_command(struct scsi_qla_host *ha,
4759 struct scsi_cmnd *cmd)
4763 uint32_t max_wait_time = EH_WAIT_CMD_TOV;
4766 /* Dont wait on command if PCI error is being handled
4769 if (unlikely(pci_channel_offline(ha->pdev)) ||
4770 (test_bit(AF_EEH_BUSY, &ha->flags))) {
4771 ql4_printk(KERN_WARNING, ha, "scsi%ld: Return from %s\n",
4772 ha->host_no, __func__);
4777 /* Checking to see if its returned to OS */
4778 rp = (struct srb *) CMD_SP(cmd);
4785 } while (max_wait_time--);
4791 * qla4xxx_wait_for_hba_online - waits for HBA to come online
4792 * @ha: Pointer to host adapter structure
4794 static int qla4xxx_wait_for_hba_online(struct scsi_qla_host *ha)
4796 unsigned long wait_online;
4798 wait_online = jiffies + (HBA_ONLINE_TOV * HZ);
4799 while (time_before(jiffies, wait_online)) {
4811 * qla4xxx_eh_wait_for_commands - wait for active cmds to finish.
4812 * @ha: pointer to HBA
4816 * This function waits for all outstanding commands to a lun to complete. It
4817 * returns 0 if all pending commands are returned and 1 otherwise.
4819 static int qla4xxx_eh_wait_for_commands(struct scsi_qla_host *ha,
4820 struct scsi_target *stgt,
4821 struct scsi_device *sdev)
4825 struct scsi_cmnd *cmd;
4828 * Waiting for all commands for the designated target or dev
4829 * in the active array
4831 for (cnt = 0; cnt < ha->host->can_queue; cnt++) {
4832 cmd = scsi_host_find_tag(ha->host, cnt);
4833 if (cmd && stgt == scsi_target(cmd->device) &&
4834 (!sdev || sdev == cmd->device)) {
4835 if (!qla4xxx_eh_wait_on_command(ha, cmd)) {
4845 * qla4xxx_eh_abort - callback for abort task.
4846 * @cmd: Pointer to Linux's SCSI command structure
4848 * This routine is called by the Linux OS to abort the specified
4851 static int qla4xxx_eh_abort(struct scsi_cmnd *cmd)
4853 struct scsi_qla_host *ha = to_qla_host(cmd->device->host);
4854 unsigned int id = cmd->device->id;
4855 unsigned int lun = cmd->device->lun;
4856 unsigned long flags;
4857 struct srb *srb = NULL;
4861 ql4_printk(KERN_INFO, ha,
4862 "scsi%ld:%d:%d: Abort command issued cmd=%p\n",
4863 ha->host_no, id, lun, cmd);
4865 spin_lock_irqsave(&ha->hardware_lock, flags);
4866 srb = (struct srb *) CMD_SP(cmd);
4868 spin_unlock_irqrestore(&ha->hardware_lock, flags);
4871 kref_get(&srb->srb_ref);
4872 spin_unlock_irqrestore(&ha->hardware_lock, flags);
4874 if (qla4xxx_abort_task(ha, srb) != QLA_SUCCESS) {
4875 DEBUG3(printk("scsi%ld:%d:%d: Abort_task mbx failed.\n",
4876 ha->host_no, id, lun));
4879 DEBUG3(printk("scsi%ld:%d:%d: Abort_task mbx success.\n",
4880 ha->host_no, id, lun));
4884 kref_put(&srb->srb_ref, qla4xxx_srb_compl);
4886 /* Wait for command to complete */
4888 if (!qla4xxx_eh_wait_on_command(ha, cmd)) {
4889 DEBUG2(printk("scsi%ld:%d:%d: Abort handler timed out\n",
4890 ha->host_no, id, lun));
4895 ql4_printk(KERN_INFO, ha,
4896 "scsi%ld:%d:%d: Abort command - %s\n",
4897 ha->host_no, id, lun, (ret == SUCCESS) ? "succeeded" : "failed");
4903 * qla4xxx_eh_device_reset - callback for target reset.
4904 * @cmd: Pointer to Linux's SCSI command structure
4906 * This routine is called by the Linux OS to reset all luns on the
4909 static int qla4xxx_eh_device_reset(struct scsi_cmnd *cmd)
4911 struct scsi_qla_host *ha = to_qla_host(cmd->device->host);
4912 struct ddb_entry *ddb_entry = cmd->device->hostdata;
4913 int ret = FAILED, stat;
4918 ret = iscsi_block_scsi_eh(cmd);
4923 ql4_printk(KERN_INFO, ha,
4924 "scsi%ld:%d:%d:%d: DEVICE RESET ISSUED.\n", ha->host_no,
4925 cmd->device->channel, cmd->device->id, cmd->device->lun);
4927 DEBUG2(printk(KERN_INFO
4928 "scsi%ld: DEVICE_RESET cmd=%p jiffies = 0x%lx, to=%x,"
4929 "dpc_flags=%lx, status=%x allowed=%d\n", ha->host_no,
4930 cmd, jiffies, cmd->request->timeout / HZ,
4931 ha->dpc_flags, cmd->result, cmd->allowed));
4933 /* FIXME: wait for hba to go online */
4934 stat = qla4xxx_reset_lun(ha, ddb_entry, cmd->device->lun);
4935 if (stat != QLA_SUCCESS) {
4936 ql4_printk(KERN_INFO, ha, "DEVICE RESET FAILED. %d\n", stat);
4937 goto eh_dev_reset_done;
4940 if (qla4xxx_eh_wait_for_commands(ha, scsi_target(cmd->device),
4942 ql4_printk(KERN_INFO, ha,
4943 "DEVICE RESET FAILED - waiting for "
4945 goto eh_dev_reset_done;
4949 if (qla4xxx_send_marker_iocb(ha, ddb_entry, cmd->device->lun,
4950 MM_LUN_RESET) != QLA_SUCCESS)
4951 goto eh_dev_reset_done;
4953 ql4_printk(KERN_INFO, ha,
4954 "scsi(%ld:%d:%d:%d): DEVICE RESET SUCCEEDED.\n",
4955 ha->host_no, cmd->device->channel, cmd->device->id,
4966 * qla4xxx_eh_target_reset - callback for target reset.
4967 * @cmd: Pointer to Linux's SCSI command structure
4969 * This routine is called by the Linux OS to reset the target.
4971 static int qla4xxx_eh_target_reset(struct scsi_cmnd *cmd)
4973 struct scsi_qla_host *ha = to_qla_host(cmd->device->host);
4974 struct ddb_entry *ddb_entry = cmd->device->hostdata;
4980 ret = iscsi_block_scsi_eh(cmd);
4984 starget_printk(KERN_INFO, scsi_target(cmd->device),
4985 "WARM TARGET RESET ISSUED.\n");
4987 DEBUG2(printk(KERN_INFO
4988 "scsi%ld: TARGET_DEVICE_RESET cmd=%p jiffies = 0x%lx, "
4989 "to=%x,dpc_flags=%lx, status=%x allowed=%d\n",
4990 ha->host_no, cmd, jiffies, cmd->request->timeout / HZ,
4991 ha->dpc_flags, cmd->result, cmd->allowed));
4993 stat = qla4xxx_reset_target(ha, ddb_entry);
4994 if (stat != QLA_SUCCESS) {
4995 starget_printk(KERN_INFO, scsi_target(cmd->device),
4996 "WARM TARGET RESET FAILED.\n");
5000 if (qla4xxx_eh_wait_for_commands(ha, scsi_target(cmd->device),
5002 starget_printk(KERN_INFO, scsi_target(cmd->device),
5003 "WARM TARGET DEVICE RESET FAILED - "
5004 "waiting for commands.\n");
5009 if (qla4xxx_send_marker_iocb(ha, ddb_entry, cmd->device->lun,
5010 MM_TGT_WARM_RESET) != QLA_SUCCESS) {
5011 starget_printk(KERN_INFO, scsi_target(cmd->device),
5012 "WARM TARGET DEVICE RESET FAILED - "
5013 "marker iocb failed.\n");
5017 starget_printk(KERN_INFO, scsi_target(cmd->device),
5018 "WARM TARGET RESET SUCCEEDED.\n");
5023 * qla4xxx_is_eh_active - check if error handler is running
5024 * @shost: Pointer to SCSI Host struct
5026 * This routine finds that if reset host is called in EH
5027 * scenario or from some application like sg_reset
5029 static int qla4xxx_is_eh_active(struct Scsi_Host *shost)
5031 if (shost->shost_state == SHOST_RECOVERY)
5037 * qla4xxx_eh_host_reset - kernel callback
5038 * @cmd: Pointer to Linux's SCSI command structure
5040 * This routine is invoked by the Linux kernel to perform fatal error
5041 * recovery on the specified adapter.
5043 static int qla4xxx_eh_host_reset(struct scsi_cmnd *cmd)
5045 int return_status = FAILED;
5046 struct scsi_qla_host *ha;
5048 ha = to_qla_host(cmd->device->host);
5050 if (ql4xdontresethba) {
5051 DEBUG2(printk("scsi%ld: %s: Don't Reset HBA\n",
5052 ha->host_no, __func__));
5054 /* Clear outstanding srb in queues */
5055 if (qla4xxx_is_eh_active(cmd->device->host))
5056 qla4xxx_abort_active_cmds(ha, DID_ABORT << 16);
5061 ql4_printk(KERN_INFO, ha,
5062 "scsi(%ld:%d:%d:%d): HOST RESET ISSUED.\n", ha->host_no,
5063 cmd->device->channel, cmd->device->id, cmd->device->lun);
5065 if (qla4xxx_wait_for_hba_online(ha) != QLA_SUCCESS) {
5066 DEBUG2(printk("scsi%ld:%d: %s: Unable to reset host. Adapter "
5067 "DEAD.\n", ha->host_no, cmd->device->channel,
5073 if (!test_bit(DPC_RESET_HA, &ha->dpc_flags)) {
5075 set_bit(DPC_RESET_HA_FW_CONTEXT, &ha->dpc_flags);
5077 set_bit(DPC_RESET_HA, &ha->dpc_flags);
5080 if (qla4xxx_recover_adapter(ha) == QLA_SUCCESS)
5081 return_status = SUCCESS;
5083 ql4_printk(KERN_INFO, ha, "HOST RESET %s.\n",
5084 return_status == FAILED ? "FAILED" : "SUCCEEDED");
5086 return return_status;
5089 static int qla4xxx_context_reset(struct scsi_qla_host *ha)
5091 uint32_t mbox_cmd[MBOX_REG_COUNT];
5092 uint32_t mbox_sts[MBOX_REG_COUNT];
5093 struct addr_ctrl_blk_def *acb = NULL;
5094 uint32_t acb_len = sizeof(struct addr_ctrl_blk_def);
5095 int rval = QLA_SUCCESS;
5098 acb = dma_alloc_coherent(&ha->pdev->dev,
5099 sizeof(struct addr_ctrl_blk_def),
5100 &acb_dma, GFP_KERNEL);
5102 ql4_printk(KERN_ERR, ha, "%s: Unable to alloc acb\n",
5105 goto exit_port_reset;
5108 memset(acb, 0, acb_len);
5110 rval = qla4xxx_get_acb(ha, acb_dma, PRIMARI_ACB, acb_len);
5111 if (rval != QLA_SUCCESS) {
5116 rval = qla4xxx_disable_acb(ha);
5117 if (rval != QLA_SUCCESS) {
5122 wait_for_completion_timeout(&ha->disable_acb_comp,
5123 DISABLE_ACB_TOV * HZ);
5125 rval = qla4xxx_set_acb(ha, &mbox_cmd[0], &mbox_sts[0], acb_dma);
5126 if (rval != QLA_SUCCESS) {
5132 dma_free_coherent(&ha->pdev->dev, sizeof(struct addr_ctrl_blk_def),
5135 DEBUG2(ql4_printk(KERN_INFO, ha, "%s %s\n", __func__,
5136 rval == QLA_SUCCESS ? "SUCCEEDED" : "FAILED"));
5140 static int qla4xxx_host_reset(struct Scsi_Host *shost, int reset_type)
5142 struct scsi_qla_host *ha = to_qla_host(shost);
5143 int rval = QLA_SUCCESS;
5145 if (ql4xdontresethba) {
5146 DEBUG2(ql4_printk(KERN_INFO, ha, "%s: Don't Reset HBA\n",
5149 goto exit_host_reset;
5152 rval = qla4xxx_wait_for_hba_online(ha);
5153 if (rval != QLA_SUCCESS) {
5154 DEBUG2(ql4_printk(KERN_INFO, ha, "%s: Unable to reset host "
5155 "adapter\n", __func__));
5157 goto exit_host_reset;
5160 if (test_bit(DPC_RESET_HA, &ha->dpc_flags))
5161 goto recover_adapter;
5163 switch (reset_type) {
5164 case SCSI_ADAPTER_RESET:
5165 set_bit(DPC_RESET_HA, &ha->dpc_flags);
5167 case SCSI_FIRMWARE_RESET:
5168 if (!test_bit(DPC_RESET_HA, &ha->dpc_flags)) {
5170 /* set firmware context reset */
5171 set_bit(DPC_RESET_HA_FW_CONTEXT,
5174 rval = qla4xxx_context_reset(ha);
5175 goto exit_host_reset;
5182 rval = qla4xxx_recover_adapter(ha);
5183 if (rval != QLA_SUCCESS) {
5184 DEBUG2(ql4_printk(KERN_INFO, ha, "%s: recover adapter fail\n",
5193 /* PCI AER driver recovers from all correctable errors w/o
5194 * driver intervention. For uncorrectable errors PCI AER
5195 * driver calls the following device driver's callbacks
5197 * - Fatal Errors - link_reset
5198 * - Non-Fatal Errors - driver's pci_error_detected() which
5199 * returns CAN_RECOVER, NEED_RESET or DISCONNECT.
5201 * PCI AER driver calls
5202 * CAN_RECOVER - driver's pci_mmio_enabled(), mmio_enabled
5203 * returns RECOVERED or NEED_RESET if fw_hung
5204 * NEED_RESET - driver's slot_reset()
5205 * DISCONNECT - device is dead & cannot recover
5206 * RECOVERED - driver's pci_resume()
5208 static pci_ers_result_t
5209 qla4xxx_pci_error_detected(struct pci_dev *pdev, pci_channel_state_t state)
5211 struct scsi_qla_host *ha = pci_get_drvdata(pdev);
5213 ql4_printk(KERN_WARNING, ha, "scsi%ld: %s: error detected:state %x\n",
5214 ha->host_no, __func__, state);
5216 if (!is_aer_supported(ha))
5217 return PCI_ERS_RESULT_NONE;
5220 case pci_channel_io_normal:
5221 clear_bit(AF_EEH_BUSY, &ha->flags);
5222 return PCI_ERS_RESULT_CAN_RECOVER;
5223 case pci_channel_io_frozen:
5224 set_bit(AF_EEH_BUSY, &ha->flags);
5225 qla4xxx_mailbox_premature_completion(ha);
5226 qla4xxx_free_irqs(ha);
5227 pci_disable_device(pdev);
5228 /* Return back all IOs */
5229 qla4xxx_abort_active_cmds(ha, DID_RESET << 16);
5230 return PCI_ERS_RESULT_NEED_RESET;
5231 case pci_channel_io_perm_failure:
5232 set_bit(AF_EEH_BUSY, &ha->flags);
5233 set_bit(AF_PCI_CHANNEL_IO_PERM_FAILURE, &ha->flags);
5234 qla4xxx_abort_active_cmds(ha, DID_NO_CONNECT << 16);
5235 return PCI_ERS_RESULT_DISCONNECT;
5237 return PCI_ERS_RESULT_NEED_RESET;
5241 * qla4xxx_pci_mmio_enabled() gets called if
5242 * qla4xxx_pci_error_detected() returns PCI_ERS_RESULT_CAN_RECOVER
5243 * and read/write to the device still works.
5245 static pci_ers_result_t
5246 qla4xxx_pci_mmio_enabled(struct pci_dev *pdev)
5248 struct scsi_qla_host *ha = pci_get_drvdata(pdev);
5250 if (!is_aer_supported(ha))
5251 return PCI_ERS_RESULT_NONE;
5253 return PCI_ERS_RESULT_RECOVERED;
5256 static uint32_t qla4_8xxx_error_recovery(struct scsi_qla_host *ha)
5258 uint32_t rval = QLA_ERROR;
5261 struct pci_dev *other_pdev = NULL;
5263 ql4_printk(KERN_WARNING, ha, "scsi%ld: In %s\n", ha->host_no, __func__);
5265 set_bit(DPC_RESET_ACTIVE, &ha->dpc_flags);
5267 if (test_bit(AF_ONLINE, &ha->flags)) {
5268 clear_bit(AF_ONLINE, &ha->flags);
5269 clear_bit(AF_LINK_UP, &ha->flags);
5270 iscsi_host_for_each_session(ha->host, qla4xxx_fail_session);
5271 qla4xxx_process_aen(ha, FLUSH_DDB_CHANGED_AENS);
5274 fn = PCI_FUNC(ha->pdev->devfn);
5277 ql4_printk(KERN_INFO, ha, "scsi%ld: %s: Finding PCI device at "
5278 "func %x\n", ha->host_no, __func__, fn);
5279 /* Get the pci device given the domain, bus,
5280 * slot/function number */
5282 pci_get_domain_bus_and_slot(pci_domain_nr(ha->pdev->bus),
5283 ha->pdev->bus->number, PCI_DEVFN(PCI_SLOT(ha->pdev->devfn),
5289 if (atomic_read(&other_pdev->enable_cnt)) {
5290 ql4_printk(KERN_INFO, ha, "scsi%ld: %s: Found PCI "
5291 "func in enabled state%x\n", ha->host_no,
5293 pci_dev_put(other_pdev);
5296 pci_dev_put(other_pdev);
5299 /* The first function on the card, the reset owner will
5300 * start & initialize the firmware. The other functions
5301 * on the card will reset the firmware context
5304 ql4_printk(KERN_INFO, ha, "scsi%ld: %s: devfn being reset "
5305 "0x%x is the owner\n", ha->host_no, __func__,
5308 qla4_8xxx_idc_lock(ha);
5309 qla4_8xxx_wr_32(ha, QLA82XX_CRB_DEV_STATE,
5312 qla4_8xxx_wr_32(ha, QLA82XX_CRB_DRV_IDC_VERSION,
5313 QLA82XX_IDC_VERSION);
5315 qla4_8xxx_idc_unlock(ha);
5316 clear_bit(AF_FW_RECOVERY, &ha->flags);
5317 rval = qla4xxx_initialize_adapter(ha, RESET_ADAPTER);
5318 qla4_8xxx_idc_lock(ha);
5320 if (rval != QLA_SUCCESS) {
5321 ql4_printk(KERN_INFO, ha, "scsi%ld: %s: HW State: "
5322 "FAILED\n", ha->host_no, __func__);
5323 qla4_8xxx_clear_drv_active(ha);
5324 qla4_8xxx_wr_32(ha, QLA82XX_CRB_DEV_STATE,
5325 QLA82XX_DEV_FAILED);
5327 ql4_printk(KERN_INFO, ha, "scsi%ld: %s: HW State: "
5328 "READY\n", ha->host_no, __func__);
5329 qla4_8xxx_wr_32(ha, QLA82XX_CRB_DEV_STATE,
5331 /* Clear driver state register */
5332 qla4_8xxx_wr_32(ha, QLA82XX_CRB_DRV_STATE, 0);
5333 qla4_8xxx_set_drv_active(ha);
5334 ret = qla4xxx_request_irqs(ha);
5336 ql4_printk(KERN_WARNING, ha, "Failed to "
5337 "reserve interrupt %d already in use.\n",
5341 ha->isp_ops->enable_intrs(ha);
5345 qla4_8xxx_idc_unlock(ha);
5347 ql4_printk(KERN_INFO, ha, "scsi%ld: %s: devfn 0x%x is not "
5348 "the reset owner\n", ha->host_no, __func__,
5350 if ((qla4_8xxx_rd_32(ha, QLA82XX_CRB_DEV_STATE) ==
5351 QLA82XX_DEV_READY)) {
5352 clear_bit(AF_FW_RECOVERY, &ha->flags);
5353 rval = qla4xxx_initialize_adapter(ha, RESET_ADAPTER);
5354 if (rval == QLA_SUCCESS) {
5355 ret = qla4xxx_request_irqs(ha);
5357 ql4_printk(KERN_WARNING, ha, "Failed to"
5358 " reserve interrupt %d already in"
5359 " use.\n", ha->pdev->irq);
5362 ha->isp_ops->enable_intrs(ha);
5366 qla4_8xxx_idc_lock(ha);
5367 qla4_8xxx_set_drv_active(ha);
5368 qla4_8xxx_idc_unlock(ha);
5371 clear_bit(DPC_RESET_ACTIVE, &ha->dpc_flags);
5375 static pci_ers_result_t
5376 qla4xxx_pci_slot_reset(struct pci_dev *pdev)
5378 pci_ers_result_t ret = PCI_ERS_RESULT_DISCONNECT;
5379 struct scsi_qla_host *ha = pci_get_drvdata(pdev);
5382 ql4_printk(KERN_WARNING, ha, "scsi%ld: %s: slot_reset\n",
5383 ha->host_no, __func__);
5385 if (!is_aer_supported(ha))
5386 return PCI_ERS_RESULT_NONE;
5388 /* Restore the saved state of PCIe device -
5389 * BAR registers, PCI Config space, PCIX, MSI,
5392 pci_restore_state(pdev);
5394 /* pci_restore_state() clears the saved_state flag of the device
5395 * save restored state which resets saved_state flag
5397 pci_save_state(pdev);
5399 /* Initialize device or resume if in suspended state */
5400 rc = pci_enable_device(pdev);
5402 ql4_printk(KERN_WARNING, ha, "scsi%ld: %s: Can't re-enable "
5403 "device after reset\n", ha->host_no, __func__);
5404 goto exit_slot_reset;
5407 ha->isp_ops->disable_intrs(ha);
5409 if (is_qla8022(ha)) {
5410 if (qla4_8xxx_error_recovery(ha) == QLA_SUCCESS) {
5411 ret = PCI_ERS_RESULT_RECOVERED;
5412 goto exit_slot_reset;
5414 goto exit_slot_reset;
5418 ql4_printk(KERN_WARNING, ha, "scsi%ld: %s: Return=%x\n"
5419 "device after reset\n", ha->host_no, __func__, ret);
5424 qla4xxx_pci_resume(struct pci_dev *pdev)
5426 struct scsi_qla_host *ha = pci_get_drvdata(pdev);
5429 ql4_printk(KERN_WARNING, ha, "scsi%ld: %s: pci_resume\n",
5430 ha->host_no, __func__);
5432 ret = qla4xxx_wait_for_hba_online(ha);
5433 if (ret != QLA_SUCCESS) {
5434 ql4_printk(KERN_ERR, ha, "scsi%ld: %s: the device failed to "
5435 "resume I/O from slot/link_reset\n", ha->host_no,
5439 pci_cleanup_aer_uncorrect_error_status(pdev);
5440 clear_bit(AF_EEH_BUSY, &ha->flags);
5443 static struct pci_error_handlers qla4xxx_err_handler = {
5444 .error_detected = qla4xxx_pci_error_detected,
5445 .mmio_enabled = qla4xxx_pci_mmio_enabled,
5446 .slot_reset = qla4xxx_pci_slot_reset,
5447 .resume = qla4xxx_pci_resume,
5450 static struct pci_device_id qla4xxx_pci_tbl[] = {
5452 .vendor = PCI_VENDOR_ID_QLOGIC,
5453 .device = PCI_DEVICE_ID_QLOGIC_ISP4010,
5454 .subvendor = PCI_ANY_ID,
5455 .subdevice = PCI_ANY_ID,
5458 .vendor = PCI_VENDOR_ID_QLOGIC,
5459 .device = PCI_DEVICE_ID_QLOGIC_ISP4022,
5460 .subvendor = PCI_ANY_ID,
5461 .subdevice = PCI_ANY_ID,
5464 .vendor = PCI_VENDOR_ID_QLOGIC,
5465 .device = PCI_DEVICE_ID_QLOGIC_ISP4032,
5466 .subvendor = PCI_ANY_ID,
5467 .subdevice = PCI_ANY_ID,
5470 .vendor = PCI_VENDOR_ID_QLOGIC,
5471 .device = PCI_DEVICE_ID_QLOGIC_ISP8022,
5472 .subvendor = PCI_ANY_ID,
5473 .subdevice = PCI_ANY_ID,
5477 MODULE_DEVICE_TABLE(pci, qla4xxx_pci_tbl);
5479 static struct pci_driver qla4xxx_pci_driver = {
5480 .name = DRIVER_NAME,
5481 .id_table = qla4xxx_pci_tbl,
5482 .probe = qla4xxx_probe_adapter,
5483 .remove = qla4xxx_remove_adapter,
5484 .err_handler = &qla4xxx_err_handler,
5487 static int __init qla4xxx_module_init(void)
5491 /* Allocate cache for SRBs. */
5492 srb_cachep = kmem_cache_create("qla4xxx_srbs", sizeof(struct srb), 0,
5493 SLAB_HWCACHE_ALIGN, NULL);
5494 if (srb_cachep == NULL) {
5496 "%s: Unable to allocate SRB cache..."
5497 "Failing load!\n", DRIVER_NAME);
5502 /* Derive version string. */
5503 strcpy(qla4xxx_version_str, QLA4XXX_DRIVER_VERSION);
5504 if (ql4xextended_error_logging)
5505 strcat(qla4xxx_version_str, "-debug");
5507 qla4xxx_scsi_transport =
5508 iscsi_register_transport(&qla4xxx_iscsi_transport);
5509 if (!qla4xxx_scsi_transport){
5511 goto release_srb_cache;
5514 ret = pci_register_driver(&qla4xxx_pci_driver);
5516 goto unregister_transport;
5518 printk(KERN_INFO "QLogic iSCSI HBA Driver\n");
5521 unregister_transport:
5522 iscsi_unregister_transport(&qla4xxx_iscsi_transport);
5524 kmem_cache_destroy(srb_cachep);
5529 static void __exit qla4xxx_module_exit(void)
5531 pci_unregister_driver(&qla4xxx_pci_driver);
5532 iscsi_unregister_transport(&qla4xxx_iscsi_transport);
5533 kmem_cache_destroy(srb_cachep);
5536 module_init(qla4xxx_module_init);
5537 module_exit(qla4xxx_module_exit);
5539 MODULE_AUTHOR("QLogic Corporation");
5540 MODULE_DESCRIPTION("QLogic iSCSI HBA Driver");
5541 MODULE_LICENSE("GPL");
5542 MODULE_VERSION(QLA4XXX_DRIVER_VERSION);