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>
12 #include <scsi/scsi_tcq.h>
13 #include <scsi/scsicam.h>
16 #include "ql4_version.h"
19 #include "ql4_inline.h"
24 static char qla4xxx_version_str[40];
27 * SRB allocation cache
29 static struct kmem_cache *srb_cachep;
32 * Module parameter information and variables
34 int ql4xdontresethba = 0;
35 module_param(ql4xdontresethba, int, S_IRUGO | S_IWUSR);
36 MODULE_PARM_DESC(ql4xdontresethba,
37 "Don't reset the HBA for driver recovery \n"
38 " 0 - It will reset HBA (Default)\n"
39 " 1 - It will NOT reset HBA");
41 int ql4xextended_error_logging = 0; /* 0 = off, 1 = log errors */
42 module_param(ql4xextended_error_logging, int, S_IRUGO | S_IWUSR);
43 MODULE_PARM_DESC(ql4xextended_error_logging,
44 "Option to enable extended error logging, "
45 "Default is 0 - no logging, 1 - debug logging");
47 int ql4xenablemsix = 1;
48 module_param(ql4xenablemsix, int, S_IRUGO|S_IWUSR);
49 MODULE_PARM_DESC(ql4xenablemsix,
50 "Set to enable MSI or MSI-X interrupt mechanism.\n"
51 " 0 = enable INTx interrupt mechanism.\n"
52 " 1 = enable MSI-X interrupt mechanism (Default).\n"
53 " 2 = enable MSI interrupt mechanism.");
55 #define QL4_DEF_QDEPTH 32
56 static int ql4xmaxqdepth = QL4_DEF_QDEPTH;
57 module_param(ql4xmaxqdepth, int, S_IRUGO | S_IWUSR);
58 MODULE_PARM_DESC(ql4xmaxqdepth,
59 "Maximum queue depth to report for target devices.\n"
62 static int ql4xsess_recovery_tmo = QL4_SESS_RECOVERY_TMO;
63 module_param(ql4xsess_recovery_tmo, int, S_IRUGO);
64 MODULE_PARM_DESC(ql4xsess_recovery_tmo,
65 "Target Session Recovery Timeout.\n"
68 static int qla4xxx_wait_for_hba_online(struct scsi_qla_host *ha);
70 * SCSI host template entry points
72 static void qla4xxx_config_dma_addressing(struct scsi_qla_host *ha);
75 * iSCSI template entry points
77 static int qla4xxx_conn_get_param(struct iscsi_cls_conn *conn,
78 enum iscsi_param param, char *buf);
79 static int qla4xxx_host_get_param(struct Scsi_Host *shost,
80 enum iscsi_host_param param, char *buf);
81 static int qla4xxx_iface_set_param(struct Scsi_Host *shost, char *data,
83 static int qla4xxx_get_iface_param(struct iscsi_iface *iface,
84 enum iscsi_param_type param_type,
85 int param, char *buf);
86 static enum blk_eh_timer_return qla4xxx_eh_cmd_timed_out(struct scsi_cmnd *sc);
87 static struct iscsi_endpoint *qla4xxx_ep_connect(struct Scsi_Host *shost,
88 struct sockaddr *dst_addr,
90 static int qla4xxx_ep_poll(struct iscsi_endpoint *ep, int timeout_ms);
91 static void qla4xxx_ep_disconnect(struct iscsi_endpoint *ep);
92 static int qla4xxx_get_ep_param(struct iscsi_endpoint *ep,
93 enum iscsi_param param, char *buf);
94 static int qla4xxx_conn_start(struct iscsi_cls_conn *conn);
95 static struct iscsi_cls_conn *
96 qla4xxx_conn_create(struct iscsi_cls_session *cls_sess, uint32_t conn_idx);
97 static int qla4xxx_conn_bind(struct iscsi_cls_session *cls_session,
98 struct iscsi_cls_conn *cls_conn,
99 uint64_t transport_fd, int is_leading);
100 static void qla4xxx_conn_destroy(struct iscsi_cls_conn *conn);
101 static struct iscsi_cls_session *
102 qla4xxx_session_create(struct iscsi_endpoint *ep, uint16_t cmds_max,
103 uint16_t qdepth, uint32_t initial_cmdsn);
104 static void qla4xxx_session_destroy(struct iscsi_cls_session *sess);
105 static void qla4xxx_task_work(struct work_struct *wdata);
106 static int qla4xxx_alloc_pdu(struct iscsi_task *, uint8_t);
107 static int qla4xxx_task_xmit(struct iscsi_task *);
108 static void qla4xxx_task_cleanup(struct iscsi_task *);
109 static void qla4xxx_fail_session(struct iscsi_cls_session *cls_session);
110 static void qla4xxx_conn_get_stats(struct iscsi_cls_conn *cls_conn,
111 struct iscsi_stats *stats);
113 * SCSI host template entry points
115 static int qla4xxx_queuecommand(struct Scsi_Host *h, struct scsi_cmnd *cmd);
116 static int qla4xxx_eh_abort(struct scsi_cmnd *cmd);
117 static int qla4xxx_eh_device_reset(struct scsi_cmnd *cmd);
118 static int qla4xxx_eh_target_reset(struct scsi_cmnd *cmd);
119 static int qla4xxx_eh_host_reset(struct scsi_cmnd *cmd);
120 static int qla4xxx_slave_alloc(struct scsi_device *device);
121 static int qla4xxx_slave_configure(struct scsi_device *device);
122 static void qla4xxx_slave_destroy(struct scsi_device *sdev);
123 static mode_t ql4_attr_is_visible(int param_type, int param);
125 static struct qla4_8xxx_legacy_intr_set legacy_intr[] =
126 QLA82XX_LEGACY_INTR_CONFIG;
128 static struct scsi_host_template qla4xxx_driver_template = {
129 .module = THIS_MODULE,
131 .proc_name = DRIVER_NAME,
132 .queuecommand = qla4xxx_queuecommand,
134 .eh_abort_handler = qla4xxx_eh_abort,
135 .eh_device_reset_handler = qla4xxx_eh_device_reset,
136 .eh_target_reset_handler = qla4xxx_eh_target_reset,
137 .eh_host_reset_handler = qla4xxx_eh_host_reset,
138 .eh_timed_out = qla4xxx_eh_cmd_timed_out,
140 .slave_configure = qla4xxx_slave_configure,
141 .slave_alloc = qla4xxx_slave_alloc,
142 .slave_destroy = qla4xxx_slave_destroy,
146 .use_clustering = ENABLE_CLUSTERING,
147 .sg_tablesize = SG_ALL,
149 .max_sectors = 0xFFFF,
150 .shost_attrs = qla4xxx_host_attrs,
151 .vendor_id = SCSI_NL_VID_TYPE_PCI | PCI_VENDOR_ID_QLOGIC,
154 static struct iscsi_transport qla4xxx_iscsi_transport = {
155 .owner = THIS_MODULE,
157 .caps = CAP_TEXT_NEGO |
158 CAP_DATA_PATH_OFFLOAD | CAP_HDRDGST |
159 CAP_DATADGST | CAP_LOGIN_OFFLOAD |
161 .attr_is_visible = ql4_attr_is_visible,
162 .create_session = qla4xxx_session_create,
163 .destroy_session = qla4xxx_session_destroy,
164 .start_conn = qla4xxx_conn_start,
165 .create_conn = qla4xxx_conn_create,
166 .bind_conn = qla4xxx_conn_bind,
167 .stop_conn = iscsi_conn_stop,
168 .destroy_conn = qla4xxx_conn_destroy,
169 .set_param = iscsi_set_param,
170 .get_conn_param = qla4xxx_conn_get_param,
171 .get_session_param = iscsi_session_get_param,
172 .get_ep_param = qla4xxx_get_ep_param,
173 .ep_connect = qla4xxx_ep_connect,
174 .ep_poll = qla4xxx_ep_poll,
175 .ep_disconnect = qla4xxx_ep_disconnect,
176 .get_stats = qla4xxx_conn_get_stats,
177 .send_pdu = iscsi_conn_send_pdu,
178 .xmit_task = qla4xxx_task_xmit,
179 .cleanup_task = qla4xxx_task_cleanup,
180 .alloc_pdu = qla4xxx_alloc_pdu,
182 .get_host_param = qla4xxx_host_get_param,
183 .set_iface_param = qla4xxx_iface_set_param,
184 .get_iface_param = qla4xxx_get_iface_param,
185 .bsg_request = qla4xxx_bsg_request,
188 static struct scsi_transport_template *qla4xxx_scsi_transport;
190 static mode_t ql4_attr_is_visible(int param_type, int param)
192 switch (param_type) {
193 case ISCSI_HOST_PARAM:
195 case ISCSI_HOST_PARAM_HWADDRESS:
196 case ISCSI_HOST_PARAM_IPADDRESS:
197 case ISCSI_HOST_PARAM_INITIATOR_NAME:
204 case ISCSI_PARAM_CONN_ADDRESS:
205 case ISCSI_PARAM_CONN_PORT:
206 case ISCSI_PARAM_TARGET_NAME:
207 case ISCSI_PARAM_TPGT:
208 case ISCSI_PARAM_TARGET_ALIAS:
209 case ISCSI_PARAM_MAX_BURST:
210 case ISCSI_PARAM_MAX_R2T:
211 case ISCSI_PARAM_FIRST_BURST:
212 case ISCSI_PARAM_MAX_RECV_DLENGTH:
213 case ISCSI_PARAM_MAX_XMIT_DLENGTH:
218 case ISCSI_NET_PARAM:
220 case ISCSI_NET_PARAM_IPV4_ADDR:
221 case ISCSI_NET_PARAM_IPV4_SUBNET:
222 case ISCSI_NET_PARAM_IPV4_GW:
223 case ISCSI_NET_PARAM_IPV4_BOOTPROTO:
224 case ISCSI_NET_PARAM_IFACE_ENABLE:
225 case ISCSI_NET_PARAM_IPV6_LINKLOCAL:
226 case ISCSI_NET_PARAM_IPV6_ADDR:
227 case ISCSI_NET_PARAM_IPV6_ROUTER:
228 case ISCSI_NET_PARAM_IPV6_ADDR_AUTOCFG:
229 case ISCSI_NET_PARAM_IPV6_LINKLOCAL_AUTOCFG:
230 case ISCSI_NET_PARAM_VLAN_ID:
231 case ISCSI_NET_PARAM_VLAN_PRIORITY:
232 case ISCSI_NET_PARAM_VLAN_ENABLED:
233 case ISCSI_NET_PARAM_MTU:
243 static int qla4xxx_get_iface_param(struct iscsi_iface *iface,
244 enum iscsi_param_type param_type,
245 int param, char *buf)
247 struct Scsi_Host *shost = iscsi_iface_to_shost(iface);
248 struct scsi_qla_host *ha = to_qla_host(shost);
251 if (param_type != ISCSI_NET_PARAM)
255 case ISCSI_NET_PARAM_IPV4_ADDR:
256 len = sprintf(buf, "%pI4\n", &ha->ip_config.ip_address);
258 case ISCSI_NET_PARAM_IPV4_SUBNET:
259 len = sprintf(buf, "%pI4\n", &ha->ip_config.subnet_mask);
261 case ISCSI_NET_PARAM_IPV4_GW:
262 len = sprintf(buf, "%pI4\n", &ha->ip_config.gateway);
264 case ISCSI_NET_PARAM_IFACE_ENABLE:
265 if (iface->iface_type == ISCSI_IFACE_TYPE_IPV4)
266 len = sprintf(buf, "%s\n",
267 (ha->ip_config.ipv4_options &
268 IPOPT_IPV4_PROTOCOL_ENABLE) ?
269 "enabled" : "disabled");
270 else if (iface->iface_type == ISCSI_IFACE_TYPE_IPV6)
271 len = sprintf(buf, "%s\n",
272 (ha->ip_config.ipv6_options &
273 IPV6_OPT_IPV6_PROTOCOL_ENABLE) ?
274 "enabled" : "disabled");
276 case ISCSI_NET_PARAM_IPV4_BOOTPROTO:
277 len = sprintf(buf, "%s\n",
278 (ha->ip_config.tcp_options & TCPOPT_DHCP_ENABLE) ?
281 case ISCSI_NET_PARAM_IPV6_ADDR:
282 if (iface->iface_num == 0)
283 len = sprintf(buf, "%pI6\n", &ha->ip_config.ipv6_addr0);
284 if (iface->iface_num == 1)
285 len = sprintf(buf, "%pI6\n", &ha->ip_config.ipv6_addr1);
287 case ISCSI_NET_PARAM_IPV6_LINKLOCAL:
288 len = sprintf(buf, "%pI6\n",
289 &ha->ip_config.ipv6_link_local_addr);
291 case ISCSI_NET_PARAM_IPV6_ROUTER:
292 len = sprintf(buf, "%pI6\n",
293 &ha->ip_config.ipv6_default_router_addr);
295 case ISCSI_NET_PARAM_IPV6_ADDR_AUTOCFG:
296 len = sprintf(buf, "%s\n",
297 (ha->ip_config.ipv6_addl_options &
298 IPV6_ADDOPT_NEIGHBOR_DISCOVERY_ADDR_ENABLE) ?
301 case ISCSI_NET_PARAM_IPV6_LINKLOCAL_AUTOCFG:
302 len = sprintf(buf, "%s\n",
303 (ha->ip_config.ipv6_addl_options &
304 IPV6_ADDOPT_AUTOCONFIG_LINK_LOCAL_ADDR) ?
307 case ISCSI_NET_PARAM_VLAN_ID:
308 if (iface->iface_type == ISCSI_IFACE_TYPE_IPV4)
309 len = sprintf(buf, "%d\n",
310 (ha->ip_config.ipv4_vlan_tag &
312 else if (iface->iface_type == ISCSI_IFACE_TYPE_IPV6)
313 len = sprintf(buf, "%d\n",
314 (ha->ip_config.ipv6_vlan_tag &
317 case ISCSI_NET_PARAM_VLAN_PRIORITY:
318 if (iface->iface_type == ISCSI_IFACE_TYPE_IPV4)
319 len = sprintf(buf, "%d\n",
320 ((ha->ip_config.ipv4_vlan_tag >> 13) &
321 ISCSI_MAX_VLAN_PRIORITY));
322 else if (iface->iface_type == ISCSI_IFACE_TYPE_IPV6)
323 len = sprintf(buf, "%d\n",
324 ((ha->ip_config.ipv6_vlan_tag >> 13) &
325 ISCSI_MAX_VLAN_PRIORITY));
327 case ISCSI_NET_PARAM_VLAN_ENABLED:
328 if (iface->iface_type == ISCSI_IFACE_TYPE_IPV4)
329 len = sprintf(buf, "%s\n",
330 (ha->ip_config.ipv4_options &
331 IPOPT_VLAN_TAGGING_ENABLE) ?
332 "enabled" : "disabled");
333 else if (iface->iface_type == ISCSI_IFACE_TYPE_IPV6)
334 len = sprintf(buf, "%s\n",
335 (ha->ip_config.ipv6_options &
336 IPV6_OPT_VLAN_TAGGING_ENABLE) ?
337 "enabled" : "disabled");
339 case ISCSI_NET_PARAM_MTU:
340 len = sprintf(buf, "%d\n", ha->ip_config.eth_mtu_size);
349 static struct iscsi_endpoint *
350 qla4xxx_ep_connect(struct Scsi_Host *shost, struct sockaddr *dst_addr,
354 struct iscsi_endpoint *ep;
355 struct qla_endpoint *qla_ep;
356 struct scsi_qla_host *ha;
357 struct sockaddr_in *addr;
358 struct sockaddr_in6 *addr6;
360 DEBUG2(printk(KERN_INFO "Func: %s\n", __func__));
363 printk(KERN_ERR "%s: shost is NULL\n",
368 ha = iscsi_host_priv(shost);
370 ep = iscsi_create_endpoint(sizeof(struct qla_endpoint));
376 qla_ep = ep->dd_data;
377 memset(qla_ep, 0, sizeof(struct qla_endpoint));
378 if (dst_addr->sa_family == AF_INET) {
379 memcpy(&qla_ep->dst_addr, dst_addr, sizeof(struct sockaddr_in));
380 addr = (struct sockaddr_in *)&qla_ep->dst_addr;
381 DEBUG2(ql4_printk(KERN_INFO, ha, "%s: %pI4\n", __func__,
382 (char *)&addr->sin_addr));
383 } else if (dst_addr->sa_family == AF_INET6) {
384 memcpy(&qla_ep->dst_addr, dst_addr,
385 sizeof(struct sockaddr_in6));
386 addr6 = (struct sockaddr_in6 *)&qla_ep->dst_addr;
387 DEBUG2(ql4_printk(KERN_INFO, ha, "%s: %pI6\n", __func__,
388 (char *)&addr6->sin6_addr));
391 qla_ep->host = shost;
396 static int qla4xxx_ep_poll(struct iscsi_endpoint *ep, int timeout_ms)
398 struct qla_endpoint *qla_ep;
399 struct scsi_qla_host *ha;
402 DEBUG2(printk(KERN_INFO "Func: %s\n", __func__));
403 qla_ep = ep->dd_data;
404 ha = to_qla_host(qla_ep->host);
412 static void qla4xxx_ep_disconnect(struct iscsi_endpoint *ep)
414 DEBUG2(printk(KERN_INFO "Func: %s\n", __func__));
415 iscsi_destroy_endpoint(ep);
418 static int qla4xxx_get_ep_param(struct iscsi_endpoint *ep,
419 enum iscsi_param param,
422 struct qla_endpoint *qla_ep = ep->dd_data;
423 struct sockaddr *dst_addr;
425 DEBUG2(printk(KERN_INFO "Func: %s\n", __func__));
428 case ISCSI_PARAM_CONN_PORT:
429 case ISCSI_PARAM_CONN_ADDRESS:
433 dst_addr = (struct sockaddr *)&qla_ep->dst_addr;
437 return iscsi_conn_get_addr_param((struct sockaddr_storage *)
438 &qla_ep->dst_addr, param, buf);
444 static void qla4xxx_conn_get_stats(struct iscsi_cls_conn *cls_conn,
445 struct iscsi_stats *stats)
447 struct iscsi_session *sess;
448 struct iscsi_cls_session *cls_sess;
449 struct ddb_entry *ddb_entry;
450 struct scsi_qla_host *ha;
451 struct ql_iscsi_stats *ql_iscsi_stats;
454 dma_addr_t iscsi_stats_dma;
456 DEBUG2(printk(KERN_INFO "Func: %s\n", __func__));
458 cls_sess = iscsi_conn_to_session(cls_conn);
459 sess = cls_sess->dd_data;
460 ddb_entry = sess->dd_data;
463 stats_size = PAGE_ALIGN(sizeof(struct ql_iscsi_stats));
464 /* Allocate memory */
465 ql_iscsi_stats = dma_alloc_coherent(&ha->pdev->dev, stats_size,
466 &iscsi_stats_dma, GFP_KERNEL);
467 if (!ql_iscsi_stats) {
468 ql4_printk(KERN_ERR, ha,
469 "Unable to allocate memory for iscsi stats\n");
473 ret = qla4xxx_get_mgmt_data(ha, ddb_entry->fw_ddb_index, stats_size,
475 if (ret != QLA_SUCCESS) {
476 ql4_printk(KERN_ERR, ha,
477 "Unable to retreive iscsi stats\n");
482 stats->txdata_octets = le64_to_cpu(ql_iscsi_stats->tx_data_octets);
483 stats->rxdata_octets = le64_to_cpu(ql_iscsi_stats->rx_data_octets);
485 stats->noptx_pdus = le32_to_cpu(ql_iscsi_stats->tx_nopout_pdus);
486 stats->scsicmd_pdus = le32_to_cpu(ql_iscsi_stats->tx_scsi_cmd_pdus);
487 stats->tmfcmd_pdus = le32_to_cpu(ql_iscsi_stats->tx_tmf_cmd_pdus);
488 stats->login_pdus = le32_to_cpu(ql_iscsi_stats->tx_login_cmd_pdus);
489 stats->text_pdus = le32_to_cpu(ql_iscsi_stats->tx_text_cmd_pdus);
490 stats->dataout_pdus = le32_to_cpu(ql_iscsi_stats->tx_scsi_write_pdus);
491 stats->logout_pdus = le32_to_cpu(ql_iscsi_stats->tx_logout_cmd_pdus);
492 stats->snack_pdus = le32_to_cpu(ql_iscsi_stats->tx_snack_req_pdus);
494 stats->noprx_pdus = le32_to_cpu(ql_iscsi_stats->rx_nopin_pdus);
495 stats->scsirsp_pdus = le32_to_cpu(ql_iscsi_stats->rx_scsi_resp_pdus);
496 stats->tmfrsp_pdus = le32_to_cpu(ql_iscsi_stats->rx_tmf_resp_pdus);
497 stats->textrsp_pdus = le32_to_cpu(ql_iscsi_stats->rx_text_resp_pdus);
498 stats->datain_pdus = le32_to_cpu(ql_iscsi_stats->rx_scsi_read_pdus);
499 stats->logoutrsp_pdus =
500 le32_to_cpu(ql_iscsi_stats->rx_logout_resp_pdus);
501 stats->r2t_pdus = le32_to_cpu(ql_iscsi_stats->rx_r2t_pdus);
502 stats->async_pdus = le32_to_cpu(ql_iscsi_stats->rx_async_pdus);
503 stats->rjt_pdus = le32_to_cpu(ql_iscsi_stats->rx_reject_pdus);
506 dma_free_coherent(&ha->pdev->dev, stats_size, ql_iscsi_stats,
512 static enum blk_eh_timer_return qla4xxx_eh_cmd_timed_out(struct scsi_cmnd *sc)
514 struct iscsi_cls_session *session;
515 struct iscsi_session *sess;
517 enum blk_eh_timer_return ret = BLK_EH_NOT_HANDLED;
519 session = starget_to_session(scsi_target(sc->device));
520 sess = session->dd_data;
522 spin_lock_irqsave(&session->lock, flags);
523 if (session->state == ISCSI_SESSION_FAILED)
524 ret = BLK_EH_RESET_TIMER;
525 spin_unlock_irqrestore(&session->lock, flags);
530 static int qla4xxx_host_get_param(struct Scsi_Host *shost,
531 enum iscsi_host_param param, char *buf)
533 struct scsi_qla_host *ha = to_qla_host(shost);
537 case ISCSI_HOST_PARAM_HWADDRESS:
538 len = sysfs_format_mac(buf, ha->my_mac, MAC_ADDR_LEN);
540 case ISCSI_HOST_PARAM_IPADDRESS:
541 len = sprintf(buf, "%pI4\n", &ha->ip_config.ip_address);
543 case ISCSI_HOST_PARAM_INITIATOR_NAME:
544 len = sprintf(buf, "%s\n", ha->name_string);
553 static void qla4xxx_create_ipv4_iface(struct scsi_qla_host *ha)
559 ha->iface_ipv4 = iscsi_create_iface(ha->host,
560 &qla4xxx_iscsi_transport,
561 ISCSI_IFACE_TYPE_IPV4, 0, 0);
563 ql4_printk(KERN_ERR, ha, "Could not create IPv4 iSCSI "
567 static void qla4xxx_create_ipv6_iface(struct scsi_qla_host *ha)
569 if (!ha->iface_ipv6_0)
571 ha->iface_ipv6_0 = iscsi_create_iface(ha->host,
572 &qla4xxx_iscsi_transport,
573 ISCSI_IFACE_TYPE_IPV6, 0,
575 if (!ha->iface_ipv6_0)
576 ql4_printk(KERN_ERR, ha, "Could not create IPv6 iSCSI "
579 if (!ha->iface_ipv6_1)
581 ha->iface_ipv6_1 = iscsi_create_iface(ha->host,
582 &qla4xxx_iscsi_transport,
583 ISCSI_IFACE_TYPE_IPV6, 1,
585 if (!ha->iface_ipv6_1)
586 ql4_printk(KERN_ERR, ha, "Could not create IPv6 iSCSI "
590 static void qla4xxx_create_ifaces(struct scsi_qla_host *ha)
592 if (ha->ip_config.ipv4_options & IPOPT_IPV4_PROTOCOL_ENABLE)
593 qla4xxx_create_ipv4_iface(ha);
595 if (ha->ip_config.ipv6_options & IPV6_OPT_IPV6_PROTOCOL_ENABLE)
596 qla4xxx_create_ipv6_iface(ha);
599 static void qla4xxx_destroy_ipv4_iface(struct scsi_qla_host *ha)
601 if (ha->iface_ipv4) {
602 iscsi_destroy_iface(ha->iface_ipv4);
603 ha->iface_ipv4 = NULL;
607 static void qla4xxx_destroy_ipv6_iface(struct scsi_qla_host *ha)
609 if (ha->iface_ipv6_0) {
610 iscsi_destroy_iface(ha->iface_ipv6_0);
611 ha->iface_ipv6_0 = NULL;
613 if (ha->iface_ipv6_1) {
614 iscsi_destroy_iface(ha->iface_ipv6_1);
615 ha->iface_ipv6_1 = NULL;
619 static void qla4xxx_destroy_ifaces(struct scsi_qla_host *ha)
621 qla4xxx_destroy_ipv4_iface(ha);
622 qla4xxx_destroy_ipv6_iface(ha);
625 static void qla4xxx_set_ipv6(struct scsi_qla_host *ha,
626 struct iscsi_iface_param_info *iface_param,
627 struct addr_ctrl_blk *init_fw_cb)
630 * iface_num 0 is valid for IPv6 Addr, linklocal, router, autocfg.
631 * iface_num 1 is valid only for IPv6 Addr.
633 switch (iface_param->param) {
634 case ISCSI_NET_PARAM_IPV6_ADDR:
635 if (iface_param->iface_num & 0x1)
637 memcpy(init_fw_cb->ipv6_addr1, iface_param->value,
638 sizeof(init_fw_cb->ipv6_addr1));
641 memcpy(init_fw_cb->ipv6_addr0, iface_param->value,
642 sizeof(init_fw_cb->ipv6_addr0));
644 case ISCSI_NET_PARAM_IPV6_LINKLOCAL:
645 if (iface_param->iface_num & 0x1)
647 memcpy(init_fw_cb->ipv6_if_id, &iface_param->value[8],
648 sizeof(init_fw_cb->ipv6_if_id));
650 case ISCSI_NET_PARAM_IPV6_ROUTER:
651 if (iface_param->iface_num & 0x1)
653 memcpy(init_fw_cb->ipv6_dflt_rtr_addr, iface_param->value,
654 sizeof(init_fw_cb->ipv6_dflt_rtr_addr));
656 case ISCSI_NET_PARAM_IPV6_ADDR_AUTOCFG:
657 /* Autocfg applies to even interface */
658 if (iface_param->iface_num & 0x1)
661 if (iface_param->value[0] == ISCSI_IPV6_AUTOCFG_DISABLE)
662 init_fw_cb->ipv6_addtl_opts &=
664 ~IPV6_ADDOPT_NEIGHBOR_DISCOVERY_ADDR_ENABLE);
665 else if (iface_param->value[0] == ISCSI_IPV6_AUTOCFG_ND_ENABLE)
666 init_fw_cb->ipv6_addtl_opts |=
668 IPV6_ADDOPT_NEIGHBOR_DISCOVERY_ADDR_ENABLE);
670 ql4_printk(KERN_ERR, ha, "Invalid autocfg setting for "
673 case ISCSI_NET_PARAM_IPV6_LINKLOCAL_AUTOCFG:
674 /* Autocfg applies to even interface */
675 if (iface_param->iface_num & 0x1)
678 if (iface_param->value[0] ==
679 ISCSI_IPV6_LINKLOCAL_AUTOCFG_ENABLE)
680 init_fw_cb->ipv6_addtl_opts |= cpu_to_le16(
681 IPV6_ADDOPT_AUTOCONFIG_LINK_LOCAL_ADDR);
682 else if (iface_param->value[0] ==
683 ISCSI_IPV6_LINKLOCAL_AUTOCFG_DISABLE)
684 init_fw_cb->ipv6_addtl_opts &= cpu_to_le16(
685 ~IPV6_ADDOPT_AUTOCONFIG_LINK_LOCAL_ADDR);
687 ql4_printk(KERN_ERR, ha, "Invalid autocfg setting for "
688 "IPv6 linklocal addr\n");
690 case ISCSI_NET_PARAM_IPV6_ROUTER_AUTOCFG:
691 /* Autocfg applies to even interface */
692 if (iface_param->iface_num & 0x1)
695 if (iface_param->value[0] == ISCSI_IPV6_ROUTER_AUTOCFG_ENABLE)
696 memset(init_fw_cb->ipv6_dflt_rtr_addr, 0,
697 sizeof(init_fw_cb->ipv6_dflt_rtr_addr));
699 case ISCSI_NET_PARAM_IFACE_ENABLE:
700 if (iface_param->value[0] == ISCSI_IFACE_ENABLE) {
701 init_fw_cb->ipv6_opts |=
702 cpu_to_le16(IPV6_OPT_IPV6_PROTOCOL_ENABLE);
703 qla4xxx_create_ipv6_iface(ha);
705 init_fw_cb->ipv6_opts &=
706 cpu_to_le16(~IPV6_OPT_IPV6_PROTOCOL_ENABLE &
708 qla4xxx_destroy_ipv6_iface(ha);
711 case ISCSI_NET_PARAM_VLAN_ID:
712 if (iface_param->len != sizeof(init_fw_cb->ipv6_vlan_tag))
714 init_fw_cb->ipv6_vlan_tag =
715 cpu_to_be16(*(uint16_t *)iface_param->value);
717 case ISCSI_NET_PARAM_VLAN_ENABLED:
718 if (iface_param->value[0] == ISCSI_VLAN_ENABLE)
719 init_fw_cb->ipv6_opts |=
720 cpu_to_le16(IPV6_OPT_VLAN_TAGGING_ENABLE);
722 init_fw_cb->ipv6_opts &=
723 cpu_to_le16(~IPV6_OPT_VLAN_TAGGING_ENABLE);
725 case ISCSI_NET_PARAM_MTU:
726 init_fw_cb->eth_mtu_size =
727 cpu_to_le16(*(uint16_t *)iface_param->value);
730 ql4_printk(KERN_ERR, ha, "Unknown IPv6 param = %d\n",
736 static void qla4xxx_set_ipv4(struct scsi_qla_host *ha,
737 struct iscsi_iface_param_info *iface_param,
738 struct addr_ctrl_blk *init_fw_cb)
740 switch (iface_param->param) {
741 case ISCSI_NET_PARAM_IPV4_ADDR:
742 memcpy(init_fw_cb->ipv4_addr, iface_param->value,
743 sizeof(init_fw_cb->ipv4_addr));
745 case ISCSI_NET_PARAM_IPV4_SUBNET:
746 memcpy(init_fw_cb->ipv4_subnet, iface_param->value,
747 sizeof(init_fw_cb->ipv4_subnet));
749 case ISCSI_NET_PARAM_IPV4_GW:
750 memcpy(init_fw_cb->ipv4_gw_addr, iface_param->value,
751 sizeof(init_fw_cb->ipv4_gw_addr));
753 case ISCSI_NET_PARAM_IPV4_BOOTPROTO:
754 if (iface_param->value[0] == ISCSI_BOOTPROTO_DHCP)
755 init_fw_cb->ipv4_tcp_opts |=
756 cpu_to_le16(TCPOPT_DHCP_ENABLE);
757 else if (iface_param->value[0] == ISCSI_BOOTPROTO_STATIC)
758 init_fw_cb->ipv4_tcp_opts &=
759 cpu_to_le16(~TCPOPT_DHCP_ENABLE);
761 ql4_printk(KERN_ERR, ha, "Invalid IPv4 bootproto\n");
763 case ISCSI_NET_PARAM_IFACE_ENABLE:
764 if (iface_param->value[0] == ISCSI_IFACE_ENABLE) {
765 init_fw_cb->ipv4_ip_opts |=
766 cpu_to_le16(IPOPT_IPV4_PROTOCOL_ENABLE);
767 qla4xxx_create_ipv4_iface(ha);
769 init_fw_cb->ipv4_ip_opts &=
770 cpu_to_le16(~IPOPT_IPV4_PROTOCOL_ENABLE &
772 qla4xxx_destroy_ipv4_iface(ha);
775 case ISCSI_NET_PARAM_VLAN_ID:
776 if (iface_param->len != sizeof(init_fw_cb->ipv4_vlan_tag))
778 init_fw_cb->ipv4_vlan_tag =
779 cpu_to_be16(*(uint16_t *)iface_param->value);
781 case ISCSI_NET_PARAM_VLAN_ENABLED:
782 if (iface_param->value[0] == ISCSI_VLAN_ENABLE)
783 init_fw_cb->ipv4_ip_opts |=
784 cpu_to_le16(IPOPT_VLAN_TAGGING_ENABLE);
786 init_fw_cb->ipv4_ip_opts &=
787 cpu_to_le16(~IPOPT_VLAN_TAGGING_ENABLE);
789 case ISCSI_NET_PARAM_MTU:
790 init_fw_cb->eth_mtu_size =
791 cpu_to_le16(*(uint16_t *)iface_param->value);
794 ql4_printk(KERN_ERR, ha, "Unknown IPv4 param = %d\n",
801 qla4xxx_initcb_to_acb(struct addr_ctrl_blk *init_fw_cb)
803 struct addr_ctrl_blk_def *acb;
804 acb = (struct addr_ctrl_blk_def *)init_fw_cb;
805 memset(acb->reserved1, 0, sizeof(acb->reserved1));
806 memset(acb->reserved2, 0, sizeof(acb->reserved2));
807 memset(acb->reserved3, 0, sizeof(acb->reserved3));
808 memset(acb->reserved4, 0, sizeof(acb->reserved4));
809 memset(acb->reserved5, 0, sizeof(acb->reserved5));
810 memset(acb->reserved6, 0, sizeof(acb->reserved6));
811 memset(acb->reserved7, 0, sizeof(acb->reserved7));
812 memset(acb->reserved8, 0, sizeof(acb->reserved8));
813 memset(acb->reserved9, 0, sizeof(acb->reserved9));
814 memset(acb->reserved10, 0, sizeof(acb->reserved10));
815 memset(acb->reserved11, 0, sizeof(acb->reserved11));
816 memset(acb->reserved12, 0, sizeof(acb->reserved12));
817 memset(acb->reserved13, 0, sizeof(acb->reserved13));
818 memset(acb->reserved14, 0, sizeof(acb->reserved14));
819 memset(acb->reserved15, 0, sizeof(acb->reserved15));
823 qla4xxx_iface_set_param(struct Scsi_Host *shost, char *data, int count)
825 struct scsi_qla_host *ha = to_qla_host(shost);
827 struct iscsi_iface_param_info *iface_param = NULL;
828 struct addr_ctrl_blk *init_fw_cb = NULL;
829 dma_addr_t init_fw_cb_dma;
830 uint32_t mbox_cmd[MBOX_REG_COUNT];
831 uint32_t mbox_sts[MBOX_REG_COUNT];
832 uint32_t total_param_count;
835 init_fw_cb = dma_alloc_coherent(&ha->pdev->dev,
836 sizeof(struct addr_ctrl_blk),
837 &init_fw_cb_dma, GFP_KERNEL);
839 ql4_printk(KERN_ERR, ha, "%s: Unable to alloc init_cb\n",
844 memset(init_fw_cb, 0, sizeof(struct addr_ctrl_blk));
845 memset(&mbox_cmd, 0, sizeof(mbox_cmd));
846 memset(&mbox_sts, 0, sizeof(mbox_sts));
848 if (qla4xxx_get_ifcb(ha, &mbox_cmd[0], &mbox_sts[0], init_fw_cb_dma)) {
849 ql4_printk(KERN_ERR, ha, "%s: get ifcb failed\n", __func__);
851 goto exit_init_fw_cb;
854 total_param_count = count;
855 iface_param = (struct iscsi_iface_param_info *)data;
857 for ( ; total_param_count != 0; total_param_count--) {
858 length = iface_param->len;
860 if (iface_param->param_type != ISCSI_NET_PARAM)
863 switch (iface_param->iface_type) {
864 case ISCSI_IFACE_TYPE_IPV4:
865 switch (iface_param->iface_num) {
867 qla4xxx_set_ipv4(ha, iface_param, init_fw_cb);
870 /* Cannot have more than one IPv4 interface */
871 ql4_printk(KERN_ERR, ha, "Invalid IPv4 iface "
873 iface_param->iface_num);
877 case ISCSI_IFACE_TYPE_IPV6:
878 switch (iface_param->iface_num) {
881 qla4xxx_set_ipv6(ha, iface_param, init_fw_cb);
884 /* Cannot have more than two IPv6 interface */
885 ql4_printk(KERN_ERR, ha, "Invalid IPv6 iface "
887 iface_param->iface_num);
892 ql4_printk(KERN_ERR, ha, "Invalid iface type\n");
896 iface_param = (struct iscsi_iface_param_info *)
897 ((uint8_t *)iface_param +
898 sizeof(struct iscsi_iface_param_info) + length);
901 init_fw_cb->cookie = cpu_to_le32(0x11BEAD5A);
903 rval = qla4xxx_set_flash(ha, init_fw_cb_dma, FLASH_SEGMENT_IFCB,
904 sizeof(struct addr_ctrl_blk),
905 FLASH_OPT_RMW_COMMIT);
906 if (rval != QLA_SUCCESS) {
907 ql4_printk(KERN_ERR, ha, "%s: set flash mbx failed\n",
910 goto exit_init_fw_cb;
913 qla4xxx_disable_acb(ha);
915 qla4xxx_initcb_to_acb(init_fw_cb);
917 rval = qla4xxx_set_acb(ha, &mbox_cmd[0], &mbox_sts[0], init_fw_cb_dma);
918 if (rval != QLA_SUCCESS) {
919 ql4_printk(KERN_ERR, ha, "%s: set acb mbx failed\n",
922 goto exit_init_fw_cb;
925 memset(init_fw_cb, 0, sizeof(struct addr_ctrl_blk));
926 qla4xxx_update_local_ifcb(ha, &mbox_cmd[0], &mbox_sts[0], init_fw_cb,
930 dma_free_coherent(&ha->pdev->dev, sizeof(struct addr_ctrl_blk),
931 init_fw_cb, init_fw_cb_dma);
936 static int qla4xxx_conn_get_param(struct iscsi_cls_conn *cls_conn,
937 enum iscsi_param param, char *buf)
939 struct iscsi_conn *conn;
940 struct qla_conn *qla_conn;
941 struct sockaddr *dst_addr;
944 conn = cls_conn->dd_data;
945 qla_conn = conn->dd_data;
946 dst_addr = &qla_conn->qla_ep->dst_addr;
949 case ISCSI_PARAM_CONN_PORT:
950 case ISCSI_PARAM_CONN_ADDRESS:
951 return iscsi_conn_get_addr_param((struct sockaddr_storage *)
952 dst_addr, param, buf);
954 return iscsi_conn_get_param(cls_conn, param, buf);
961 static struct iscsi_cls_session *
962 qla4xxx_session_create(struct iscsi_endpoint *ep,
963 uint16_t cmds_max, uint16_t qdepth,
964 uint32_t initial_cmdsn)
966 struct iscsi_cls_session *cls_sess;
967 struct scsi_qla_host *ha;
968 struct qla_endpoint *qla_ep;
969 struct ddb_entry *ddb_entry;
971 uint32_t mbx_sts = 0;
972 struct iscsi_session *sess;
973 struct sockaddr *dst_addr;
976 DEBUG2(printk(KERN_INFO "Func: %s\n", __func__));
978 printk(KERN_ERR "qla4xxx: missing ep.\n");
982 qla_ep = ep->dd_data;
983 dst_addr = (struct sockaddr *)&qla_ep->dst_addr;
984 ha = to_qla_host(qla_ep->host);
986 ddb_index = find_first_zero_bit(ha->ddb_idx_map, MAX_DDB_ENTRIES);
988 if (ddb_index >= MAX_DDB_ENTRIES) {
989 DEBUG2(ql4_printk(KERN_INFO, ha,
990 "Free DDB index not available\n"));
994 if (test_and_set_bit(ddb_index, ha->ddb_idx_map))
997 DEBUG2(ql4_printk(KERN_INFO, ha,
998 "Found a free DDB index at %d\n", ddb_index));
999 ret = qla4xxx_req_ddb_entry(ha, ddb_index, &mbx_sts);
1000 if (ret == QLA_ERROR) {
1001 if (mbx_sts == MBOX_STS_COMMAND_ERROR) {
1002 ql4_printk(KERN_INFO, ha,
1003 "DDB index = %d not available trying next\n",
1007 DEBUG2(ql4_printk(KERN_INFO, ha,
1008 "Free FW DDB not available\n"));
1012 cls_sess = iscsi_session_setup(&qla4xxx_iscsi_transport, qla_ep->host,
1013 cmds_max, sizeof(struct ddb_entry),
1014 sizeof(struct ql4_task_data),
1015 initial_cmdsn, ddb_index);
1019 sess = cls_sess->dd_data;
1020 ddb_entry = sess->dd_data;
1021 ddb_entry->fw_ddb_index = ddb_index;
1022 ddb_entry->fw_ddb_device_state = DDB_DS_NO_CONNECTION_ACTIVE;
1024 ddb_entry->sess = cls_sess;
1025 cls_sess->recovery_tmo = ql4xsess_recovery_tmo;
1026 ha->fw_ddb_index_map[ddb_entry->fw_ddb_index] = ddb_entry;
1032 static void qla4xxx_session_destroy(struct iscsi_cls_session *cls_sess)
1034 struct iscsi_session *sess;
1035 struct ddb_entry *ddb_entry;
1036 struct scsi_qla_host *ha;
1037 unsigned long flags;
1039 DEBUG2(printk(KERN_INFO "Func: %s\n", __func__));
1040 sess = cls_sess->dd_data;
1041 ddb_entry = sess->dd_data;
1044 spin_lock_irqsave(&ha->hardware_lock, flags);
1045 qla4xxx_free_ddb(ha, ddb_entry);
1046 spin_unlock_irqrestore(&ha->hardware_lock, flags);
1047 iscsi_session_teardown(cls_sess);
1050 static struct iscsi_cls_conn *
1051 qla4xxx_conn_create(struct iscsi_cls_session *cls_sess, uint32_t conn_idx)
1053 struct iscsi_cls_conn *cls_conn;
1054 struct iscsi_session *sess;
1055 struct ddb_entry *ddb_entry;
1057 DEBUG2(printk(KERN_INFO "Func: %s\n", __func__));
1058 cls_conn = iscsi_conn_setup(cls_sess, sizeof(struct qla_conn),
1060 sess = cls_sess->dd_data;
1061 ddb_entry = sess->dd_data;
1062 ddb_entry->conn = cls_conn;
1067 static int qla4xxx_conn_bind(struct iscsi_cls_session *cls_session,
1068 struct iscsi_cls_conn *cls_conn,
1069 uint64_t transport_fd, int is_leading)
1071 struct iscsi_conn *conn;
1072 struct qla_conn *qla_conn;
1073 struct iscsi_endpoint *ep;
1075 DEBUG2(printk(KERN_INFO "Func: %s\n", __func__));
1077 if (iscsi_conn_bind(cls_session, cls_conn, is_leading))
1079 ep = iscsi_lookup_endpoint(transport_fd);
1080 conn = cls_conn->dd_data;
1081 qla_conn = conn->dd_data;
1082 qla_conn->qla_ep = ep->dd_data;
1086 static int qla4xxx_conn_start(struct iscsi_cls_conn *cls_conn)
1088 struct iscsi_cls_session *cls_sess = iscsi_conn_to_session(cls_conn);
1089 struct iscsi_session *sess;
1090 struct ddb_entry *ddb_entry;
1091 struct scsi_qla_host *ha;
1092 struct dev_db_entry *fw_ddb_entry;
1093 dma_addr_t fw_ddb_entry_dma;
1094 uint32_t mbx_sts = 0;
1096 int status = QLA_SUCCESS;
1098 DEBUG2(printk(KERN_INFO "Func: %s\n", __func__));
1099 sess = cls_sess->dd_data;
1100 ddb_entry = sess->dd_data;
1103 fw_ddb_entry = dma_alloc_coherent(&ha->pdev->dev, sizeof(*fw_ddb_entry),
1104 &fw_ddb_entry_dma, GFP_KERNEL);
1105 if (!fw_ddb_entry) {
1106 ql4_printk(KERN_ERR, ha,
1107 "%s: Unable to allocate dma buffer\n", __func__);
1111 ret = qla4xxx_set_param_ddbentry(ha, ddb_entry, cls_conn, &mbx_sts);
1113 /* If iscsid is stopped and started then no need to do
1114 * set param again since ddb state will be already
1115 * active and FW does not allow set ddb to an
1119 if (ddb_entry->fw_ddb_device_state ==
1120 DDB_DS_SESSION_ACTIVE)
1121 goto exit_set_param;
1123 ql4_printk(KERN_ERR, ha, "%s: Failed set param for index[%d]\n",
1124 __func__, ddb_entry->fw_ddb_index);
1125 goto exit_conn_start;
1128 status = qla4xxx_conn_open(ha, ddb_entry->fw_ddb_index);
1129 if (status == QLA_ERROR) {
1130 ql4_printk(KERN_ERR, ha, "%s: Login failed: %s\n", __func__,
1133 goto exit_conn_start;
1136 ddb_entry->fw_ddb_device_state = DDB_DS_LOGIN_IN_PROCESS;
1139 iscsi_conn_start(cls_conn);
1143 dma_free_coherent(&ha->pdev->dev, sizeof(*fw_ddb_entry),
1144 fw_ddb_entry, fw_ddb_entry_dma);
1148 static void qla4xxx_conn_destroy(struct iscsi_cls_conn *cls_conn)
1150 struct iscsi_cls_session *cls_sess = iscsi_conn_to_session(cls_conn);
1151 struct iscsi_session *sess;
1152 struct scsi_qla_host *ha;
1153 struct ddb_entry *ddb_entry;
1156 DEBUG2(printk(KERN_INFO "Func: %s\n", __func__));
1157 sess = cls_sess->dd_data;
1158 ddb_entry = sess->dd_data;
1161 options = LOGOUT_OPTION_CLOSE_SESSION;
1162 if (qla4xxx_session_logout_ddb(ha, ddb_entry, options) == QLA_ERROR)
1163 ql4_printk(KERN_ERR, ha, "%s: Logout failed\n", __func__);
1165 qla4xxx_clear_ddb_entry(ha, ddb_entry->fw_ddb_index);
1168 * Clear the DDB bit so that next login can use the bit
1169 * if FW is not clearing the DDB entry then set DDB will fail anyways
1171 clear_bit(ddb_entry->fw_ddb_index, ha->ddb_idx_map);
1174 static void qla4xxx_task_work(struct work_struct *wdata)
1176 struct ql4_task_data *task_data;
1177 struct scsi_qla_host *ha;
1178 struct passthru_status *sts;
1179 struct iscsi_task *task;
1180 struct iscsi_hdr *hdr;
1183 struct iscsi_conn *conn;
1187 task_data = container_of(wdata, struct ql4_task_data, task_work);
1189 task = task_data->task;
1190 sts = &task_data->sts;
1191 hdr_len = sizeof(struct iscsi_hdr);
1193 DEBUG3(printk(KERN_INFO "Status returned\n"));
1194 DEBUG3(qla4xxx_dump_buffer(sts, 64));
1195 DEBUG3(printk(KERN_INFO "Response buffer"));
1196 DEBUG3(qla4xxx_dump_buffer(task_data->resp_buffer, 64));
1200 switch (sts->completionStatus) {
1201 case PASSTHRU_STATUS_COMPLETE:
1202 hdr = (struct iscsi_hdr *)task_data->resp_buffer;
1203 /* Assign back the itt in hdr, until we use the PREASSIGN_TAG */
1206 data = task_data->resp_buffer + hdr_len;
1207 data_len = task_data->resp_len - hdr_len;
1208 iscsi_complete_pdu(conn, hdr, data, data_len);
1211 ql4_printk(KERN_ERR, ha, "Passthru failed status = 0x%x\n",
1212 sts->completionStatus);
1218 static int qla4xxx_alloc_pdu(struct iscsi_task *task, uint8_t opcode)
1220 struct ql4_task_data *task_data;
1221 struct iscsi_session *sess;
1222 struct ddb_entry *ddb_entry;
1223 struct scsi_qla_host *ha;
1226 sess = task->conn->session;
1227 ddb_entry = sess->dd_data;
1229 task_data = task->dd_data;
1230 memset(task_data, 0, sizeof(struct ql4_task_data));
1233 ql4_printk(KERN_INFO, ha,
1234 "%s: SCSI Commands not implemented\n", __func__);
1238 hdr_len = sizeof(struct iscsi_hdr);
1240 task_data->task = task;
1242 if (task->data_count) {
1243 task_data->data_dma = dma_map_single(&ha->pdev->dev, task->data,
1248 DEBUG2(ql4_printk(KERN_INFO, ha, "%s: MaxRecvLen %u, iscsi hrd %d\n",
1249 __func__, task->conn->max_recv_dlength, hdr_len));
1251 task_data->resp_len = task->conn->max_recv_dlength;
1252 task_data->resp_buffer = dma_alloc_coherent(&ha->pdev->dev,
1253 task_data->resp_len,
1254 &task_data->resp_dma,
1256 if (!task_data->resp_buffer)
1257 goto exit_alloc_pdu;
1259 task_data->req_buffer = dma_alloc_coherent(&ha->pdev->dev,
1260 task->data_count + hdr_len,
1261 &task_data->req_dma,
1263 if (!task_data->req_buffer)
1264 goto exit_alloc_pdu;
1266 task->hdr = task_data->req_buffer;
1268 INIT_WORK(&task_data->task_work, qla4xxx_task_work);
1273 if (task_data->resp_buffer)
1274 dma_free_coherent(&ha->pdev->dev, task_data->resp_len,
1275 task_data->resp_buffer, task_data->resp_dma);
1277 if (task_data->req_buffer)
1278 dma_free_coherent(&ha->pdev->dev, task->data_count + hdr_len,
1279 task_data->req_buffer, task_data->req_dma);
1283 static void qla4xxx_task_cleanup(struct iscsi_task *task)
1285 struct ql4_task_data *task_data;
1286 struct iscsi_session *sess;
1287 struct ddb_entry *ddb_entry;
1288 struct scsi_qla_host *ha;
1291 hdr_len = sizeof(struct iscsi_hdr);
1292 sess = task->conn->session;
1293 ddb_entry = sess->dd_data;
1295 task_data = task->dd_data;
1297 if (task->data_count) {
1298 dma_unmap_single(&ha->pdev->dev, task_data->data_dma,
1299 task->data_count, PCI_DMA_TODEVICE);
1302 DEBUG2(ql4_printk(KERN_INFO, ha, "%s: MaxRecvLen %u, iscsi hrd %d\n",
1303 __func__, task->conn->max_recv_dlength, hdr_len));
1305 dma_free_coherent(&ha->pdev->dev, task_data->resp_len,
1306 task_data->resp_buffer, task_data->resp_dma);
1307 dma_free_coherent(&ha->pdev->dev, task->data_count + hdr_len,
1308 task_data->req_buffer, task_data->req_dma);
1312 static int qla4xxx_task_xmit(struct iscsi_task *task)
1314 struct scsi_cmnd *sc = task->sc;
1315 struct iscsi_session *sess = task->conn->session;
1316 struct ddb_entry *ddb_entry = sess->dd_data;
1317 struct scsi_qla_host *ha = ddb_entry->ha;
1320 return qla4xxx_send_passthru0(task);
1322 ql4_printk(KERN_INFO, ha, "%s: scsi cmd xmit not implemented\n",
1327 void qla4xxx_update_session_conn_param(struct scsi_qla_host *ha,
1328 struct ddb_entry *ddb_entry)
1330 struct iscsi_cls_session *cls_sess;
1331 struct iscsi_cls_conn *cls_conn;
1332 struct iscsi_session *sess;
1333 struct iscsi_conn *conn;
1335 dma_addr_t fw_ddb_entry_dma;
1336 struct dev_db_entry *fw_ddb_entry;
1338 fw_ddb_entry = dma_alloc_coherent(&ha->pdev->dev, sizeof(*fw_ddb_entry),
1339 &fw_ddb_entry_dma, GFP_KERNEL);
1340 if (!fw_ddb_entry) {
1341 ql4_printk(KERN_ERR, ha,
1342 "%s: Unable to allocate dma buffer\n", __func__);
1346 if (qla4xxx_get_fwddb_entry(ha, ddb_entry->fw_ddb_index, fw_ddb_entry,
1347 fw_ddb_entry_dma, NULL, NULL, &ddb_state,
1348 NULL, NULL, NULL) == QLA_ERROR) {
1349 DEBUG2(ql4_printk(KERN_ERR, ha, "scsi%ld: %s: failed "
1350 "get_ddb_entry for fw_ddb_index %d\n",
1351 ha->host_no, __func__,
1352 ddb_entry->fw_ddb_index));
1356 cls_sess = ddb_entry->sess;
1357 sess = cls_sess->dd_data;
1359 cls_conn = ddb_entry->conn;
1360 conn = cls_conn->dd_data;
1363 conn->max_recv_dlength = BYTE_UNITS *
1364 le16_to_cpu(fw_ddb_entry->iscsi_max_rcv_data_seg_len);
1366 conn->max_xmit_dlength = BYTE_UNITS *
1367 le16_to_cpu(fw_ddb_entry->iscsi_max_snd_data_seg_len);
1369 sess->initial_r2t_en =
1370 (BIT_10 & le16_to_cpu(fw_ddb_entry->iscsi_options));
1372 sess->max_r2t = le16_to_cpu(fw_ddb_entry->iscsi_max_outsnd_r2t);
1374 sess->imm_data_en = (BIT_11 & le16_to_cpu(fw_ddb_entry->iscsi_options));
1376 sess->first_burst = BYTE_UNITS *
1377 le16_to_cpu(fw_ddb_entry->iscsi_first_burst_len);
1379 sess->max_burst = BYTE_UNITS *
1380 le16_to_cpu(fw_ddb_entry->iscsi_max_burst_len);
1382 sess->time2wait = le16_to_cpu(fw_ddb_entry->iscsi_def_time2wait);
1384 sess->time2retain = le16_to_cpu(fw_ddb_entry->iscsi_def_time2retain);
1386 sess->tpgt = le32_to_cpu(fw_ddb_entry->tgt_portal_grp);
1388 memcpy(sess->initiatorname, ha->name_string,
1389 min(sizeof(ha->name_string), sizeof(sess->initiatorname)));
1396 static void qla4xxx_start_timer(struct scsi_qla_host *ha, void *func,
1397 unsigned long interval)
1399 DEBUG(printk("scsi: %s: Starting timer thread for adapter %d\n",
1400 __func__, ha->host->host_no));
1401 init_timer(&ha->timer);
1402 ha->timer.expires = jiffies + interval * HZ;
1403 ha->timer.data = (unsigned long)ha;
1404 ha->timer.function = (void (*)(unsigned long))func;
1405 add_timer(&ha->timer);
1406 ha->timer_active = 1;
1409 static void qla4xxx_stop_timer(struct scsi_qla_host *ha)
1411 del_timer_sync(&ha->timer);
1412 ha->timer_active = 0;
1416 * qla4xxx_mark_device_missing - blocks the session
1417 * @cls_session: Pointer to the session to be blocked
1418 * @ddb_entry: Pointer to device database entry
1420 * This routine marks a device missing and close connection.
1422 void qla4xxx_mark_device_missing(struct iscsi_cls_session *cls_session)
1424 iscsi_block_session(cls_session);
1428 * qla4xxx_mark_all_devices_missing - mark all devices as missing.
1429 * @ha: Pointer to host adapter structure.
1431 * This routine marks a device missing and resets the relogin retry count.
1433 void qla4xxx_mark_all_devices_missing(struct scsi_qla_host *ha)
1435 iscsi_host_for_each_session(ha->host, qla4xxx_mark_device_missing);
1438 static struct srb* qla4xxx_get_new_srb(struct scsi_qla_host *ha,
1439 struct ddb_entry *ddb_entry,
1440 struct scsi_cmnd *cmd)
1444 srb = mempool_alloc(ha->srb_mempool, GFP_ATOMIC);
1448 kref_init(&srb->srb_ref);
1450 srb->ddb = ddb_entry;
1453 CMD_SP(cmd) = (void *)srb;
1458 static void qla4xxx_srb_free_dma(struct scsi_qla_host *ha, struct srb *srb)
1460 struct scsi_cmnd *cmd = srb->cmd;
1462 if (srb->flags & SRB_DMA_VALID) {
1463 scsi_dma_unmap(cmd);
1464 srb->flags &= ~SRB_DMA_VALID;
1469 void qla4xxx_srb_compl(struct kref *ref)
1471 struct srb *srb = container_of(ref, struct srb, srb_ref);
1472 struct scsi_cmnd *cmd = srb->cmd;
1473 struct scsi_qla_host *ha = srb->ha;
1475 qla4xxx_srb_free_dma(ha, srb);
1477 mempool_free(srb, ha->srb_mempool);
1479 cmd->scsi_done(cmd);
1483 * qla4xxx_queuecommand - scsi layer issues scsi command to driver.
1485 * @cmd: Pointer to Linux's SCSI command structure
1488 * This routine is invoked by Linux to send a SCSI command to the driver.
1489 * The mid-level driver tries to ensure that queuecommand never gets
1490 * invoked concurrently with itself or the interrupt handler (although
1491 * the interrupt handler may call this routine as part of request-
1492 * completion handling). Unfortunely, it sometimes calls the scheduler
1493 * in interrupt context which is a big NO! NO!.
1495 static int qla4xxx_queuecommand(struct Scsi_Host *host, struct scsi_cmnd *cmd)
1497 struct scsi_qla_host *ha = to_qla_host(host);
1498 struct ddb_entry *ddb_entry = cmd->device->hostdata;
1499 struct iscsi_cls_session *sess = ddb_entry->sess;
1503 if (test_bit(AF_EEH_BUSY, &ha->flags)) {
1504 if (test_bit(AF_PCI_CHANNEL_IO_PERM_FAILURE, &ha->flags))
1505 cmd->result = DID_NO_CONNECT << 16;
1507 cmd->result = DID_REQUEUE << 16;
1508 goto qc_fail_command;
1512 cmd->result = DID_IMM_RETRY << 16;
1513 goto qc_fail_command;
1516 rval = iscsi_session_chkready(sess);
1519 goto qc_fail_command;
1522 if (test_bit(DPC_RESET_HA_INTR, &ha->dpc_flags) ||
1523 test_bit(DPC_RESET_ACTIVE, &ha->dpc_flags) ||
1524 test_bit(DPC_RESET_HA, &ha->dpc_flags) ||
1525 test_bit(DPC_HA_UNRECOVERABLE, &ha->dpc_flags) ||
1526 test_bit(DPC_HA_NEED_QUIESCENT, &ha->dpc_flags) ||
1527 !test_bit(AF_ONLINE, &ha->flags) ||
1528 !test_bit(AF_LINK_UP, &ha->flags) ||
1529 test_bit(DPC_RESET_HA_FW_CONTEXT, &ha->dpc_flags))
1532 srb = qla4xxx_get_new_srb(ha, ddb_entry, cmd);
1536 rval = qla4xxx_send_command_to_isp(ha, srb);
1537 if (rval != QLA_SUCCESS)
1538 goto qc_host_busy_free_sp;
1542 qc_host_busy_free_sp:
1543 qla4xxx_srb_free_dma(ha, srb);
1544 mempool_free(srb, ha->srb_mempool);
1547 return SCSI_MLQUEUE_HOST_BUSY;
1550 cmd->scsi_done(cmd);
1556 * qla4xxx_mem_free - frees memory allocated to adapter
1557 * @ha: Pointer to host adapter structure.
1559 * Frees memory previously allocated by qla4xxx_mem_alloc
1561 static void qla4xxx_mem_free(struct scsi_qla_host *ha)
1564 dma_free_coherent(&ha->pdev->dev, ha->queues_len, ha->queues,
1570 ha->request_ring = NULL;
1571 ha->request_dma = 0;
1572 ha->response_ring = NULL;
1573 ha->response_dma = 0;
1574 ha->shadow_regs = NULL;
1575 ha->shadow_regs_dma = 0;
1577 /* Free srb pool. */
1578 if (ha->srb_mempool)
1579 mempool_destroy(ha->srb_mempool);
1581 ha->srb_mempool = NULL;
1583 if (ha->chap_dma_pool)
1584 dma_pool_destroy(ha->chap_dma_pool);
1586 /* release io space registers */
1587 if (is_qla8022(ha)) {
1590 (struct device_reg_82xx __iomem *)ha->nx_pcibase);
1593 pci_release_regions(ha->pdev);
1597 * qla4xxx_mem_alloc - allocates memory for use by adapter.
1598 * @ha: Pointer to host adapter structure
1600 * Allocates DMA memory for request and response queues. Also allocates memory
1603 static int qla4xxx_mem_alloc(struct scsi_qla_host *ha)
1605 unsigned long align;
1607 /* Allocate contiguous block of DMA memory for queues. */
1608 ha->queues_len = ((REQUEST_QUEUE_DEPTH * QUEUE_SIZE) +
1609 (RESPONSE_QUEUE_DEPTH * QUEUE_SIZE) +
1610 sizeof(struct shadow_regs) +
1612 (PAGE_SIZE - 1)) & ~(PAGE_SIZE - 1);
1613 ha->queues = dma_alloc_coherent(&ha->pdev->dev, ha->queues_len,
1614 &ha->queues_dma, GFP_KERNEL);
1615 if (ha->queues == NULL) {
1616 ql4_printk(KERN_WARNING, ha,
1617 "Memory Allocation failed - queues.\n");
1619 goto mem_alloc_error_exit;
1621 memset(ha->queues, 0, ha->queues_len);
1624 * As per RISC alignment requirements -- the bus-address must be a
1625 * multiple of the request-ring size (in bytes).
1628 if ((unsigned long)ha->queues_dma & (MEM_ALIGN_VALUE - 1))
1629 align = MEM_ALIGN_VALUE - ((unsigned long)ha->queues_dma &
1630 (MEM_ALIGN_VALUE - 1));
1632 /* Update request and response queue pointers. */
1633 ha->request_dma = ha->queues_dma + align;
1634 ha->request_ring = (struct queue_entry *) (ha->queues + align);
1635 ha->response_dma = ha->queues_dma + align +
1636 (REQUEST_QUEUE_DEPTH * QUEUE_SIZE);
1637 ha->response_ring = (struct queue_entry *) (ha->queues + align +
1638 (REQUEST_QUEUE_DEPTH *
1640 ha->shadow_regs_dma = ha->queues_dma + align +
1641 (REQUEST_QUEUE_DEPTH * QUEUE_SIZE) +
1642 (RESPONSE_QUEUE_DEPTH * QUEUE_SIZE);
1643 ha->shadow_regs = (struct shadow_regs *) (ha->queues + align +
1644 (REQUEST_QUEUE_DEPTH *
1646 (RESPONSE_QUEUE_DEPTH *
1649 /* Allocate memory for srb pool. */
1650 ha->srb_mempool = mempool_create(SRB_MIN_REQ, mempool_alloc_slab,
1651 mempool_free_slab, srb_cachep);
1652 if (ha->srb_mempool == NULL) {
1653 ql4_printk(KERN_WARNING, ha,
1654 "Memory Allocation failed - SRB Pool.\n");
1656 goto mem_alloc_error_exit;
1659 ha->chap_dma_pool = dma_pool_create("ql4_chap", &ha->pdev->dev,
1660 CHAP_DMA_BLOCK_SIZE, 8, 0);
1662 if (ha->chap_dma_pool == NULL) {
1663 ql4_printk(KERN_WARNING, ha,
1664 "%s: chap_dma_pool allocation failed..\n", __func__);
1665 goto mem_alloc_error_exit;
1670 mem_alloc_error_exit:
1671 qla4xxx_mem_free(ha);
1676 * qla4_8xxx_check_fw_alive - Check firmware health
1677 * @ha: Pointer to host adapter structure.
1679 * Context: Interrupt
1681 static void qla4_8xxx_check_fw_alive(struct scsi_qla_host *ha)
1683 uint32_t fw_heartbeat_counter, halt_status;
1685 fw_heartbeat_counter = qla4_8xxx_rd_32(ha, QLA82XX_PEG_ALIVE_COUNTER);
1686 /* If PEG_ALIVE_COUNTER is 0xffffffff, AER/EEH is in progress, ignore */
1687 if (fw_heartbeat_counter == 0xffffffff) {
1688 DEBUG2(printk(KERN_WARNING "scsi%ld: %s: Device in frozen "
1689 "state, QLA82XX_PEG_ALIVE_COUNTER is 0xffffffff\n",
1690 ha->host_no, __func__));
1694 if (ha->fw_heartbeat_counter == fw_heartbeat_counter) {
1695 ha->seconds_since_last_heartbeat++;
1696 /* FW not alive after 2 seconds */
1697 if (ha->seconds_since_last_heartbeat == 2) {
1698 ha->seconds_since_last_heartbeat = 0;
1699 halt_status = qla4_8xxx_rd_32(ha,
1700 QLA82XX_PEG_HALT_STATUS1);
1702 ql4_printk(KERN_INFO, ha,
1703 "scsi(%ld): %s, Dumping hw/fw registers:\n "
1704 " PEG_HALT_STATUS1: 0x%x, PEG_HALT_STATUS2:"
1705 " 0x%x,\n PEG_NET_0_PC: 0x%x, PEG_NET_1_PC:"
1706 " 0x%x,\n PEG_NET_2_PC: 0x%x, PEG_NET_3_PC:"
1707 " 0x%x,\n PEG_NET_4_PC: 0x%x\n",
1708 ha->host_no, __func__, halt_status,
1710 QLA82XX_PEG_HALT_STATUS2),
1711 qla4_8xxx_rd_32(ha, QLA82XX_CRB_PEG_NET_0 +
1713 qla4_8xxx_rd_32(ha, QLA82XX_CRB_PEG_NET_1 +
1715 qla4_8xxx_rd_32(ha, QLA82XX_CRB_PEG_NET_2 +
1717 qla4_8xxx_rd_32(ha, QLA82XX_CRB_PEG_NET_3 +
1719 qla4_8xxx_rd_32(ha, QLA82XX_CRB_PEG_NET_4 +
1722 /* Since we cannot change dev_state in interrupt
1723 * context, set appropriate DPC flag then wakeup
1725 if (halt_status & HALT_STATUS_UNRECOVERABLE)
1726 set_bit(DPC_HA_UNRECOVERABLE, &ha->dpc_flags);
1728 printk("scsi%ld: %s: detect abort needed!\n",
1729 ha->host_no, __func__);
1730 set_bit(DPC_RESET_HA, &ha->dpc_flags);
1732 qla4xxx_wake_dpc(ha);
1733 qla4xxx_mailbox_premature_completion(ha);
1736 ha->seconds_since_last_heartbeat = 0;
1738 ha->fw_heartbeat_counter = fw_heartbeat_counter;
1742 * qla4_8xxx_watchdog - Poll dev state
1743 * @ha: Pointer to host adapter structure.
1745 * Context: Interrupt
1747 void qla4_8xxx_watchdog(struct scsi_qla_host *ha)
1751 dev_state = qla4_8xxx_rd_32(ha, QLA82XX_CRB_DEV_STATE);
1753 /* don't poll if reset is going on */
1754 if (!(test_bit(DPC_RESET_ACTIVE, &ha->dpc_flags) ||
1755 test_bit(DPC_RESET_HA, &ha->dpc_flags) ||
1756 test_bit(DPC_RETRY_RESET_HA, &ha->dpc_flags))) {
1757 if (dev_state == QLA82XX_DEV_NEED_RESET &&
1758 !test_bit(DPC_RESET_HA, &ha->dpc_flags)) {
1759 if (!ql4xdontresethba) {
1760 ql4_printk(KERN_INFO, ha, "%s: HW State: "
1761 "NEED RESET!\n", __func__);
1762 set_bit(DPC_RESET_HA, &ha->dpc_flags);
1763 qla4xxx_wake_dpc(ha);
1764 qla4xxx_mailbox_premature_completion(ha);
1766 } else if (dev_state == QLA82XX_DEV_NEED_QUIESCENT &&
1767 !test_bit(DPC_HA_NEED_QUIESCENT, &ha->dpc_flags)) {
1768 ql4_printk(KERN_INFO, ha, "%s: HW State: NEED QUIES!\n",
1770 set_bit(DPC_HA_NEED_QUIESCENT, &ha->dpc_flags);
1771 qla4xxx_wake_dpc(ha);
1773 /* Check firmware health */
1774 qla4_8xxx_check_fw_alive(ha);
1780 * qla4xxx_timer - checks every second for work to do.
1781 * @ha: Pointer to host adapter structure.
1783 static void qla4xxx_timer(struct scsi_qla_host *ha)
1788 /* If we are in the middle of AER/EEH processing
1789 * skip any processing and reschedule the timer
1791 if (test_bit(AF_EEH_BUSY, &ha->flags)) {
1792 mod_timer(&ha->timer, jiffies + HZ);
1796 /* Hardware read to trigger an EEH error during mailbox waits. */
1797 if (!pci_channel_offline(ha->pdev))
1798 pci_read_config_word(ha->pdev, PCI_VENDOR_ID, &w);
1800 if (is_qla8022(ha)) {
1801 qla4_8xxx_watchdog(ha);
1804 if (!is_qla8022(ha)) {
1805 /* Check for heartbeat interval. */
1806 if (ha->firmware_options & FWOPT_HEARTBEAT_ENABLE &&
1807 ha->heartbeat_interval != 0) {
1808 ha->seconds_since_last_heartbeat++;
1809 if (ha->seconds_since_last_heartbeat >
1810 ha->heartbeat_interval + 2)
1811 set_bit(DPC_RESET_HA, &ha->dpc_flags);
1815 /* Wakeup the dpc routine for this adapter, if needed. */
1817 test_bit(DPC_RESET_HA, &ha->dpc_flags) ||
1818 test_bit(DPC_RETRY_RESET_HA, &ha->dpc_flags) ||
1819 test_bit(DPC_RELOGIN_DEVICE, &ha->dpc_flags) ||
1820 test_bit(DPC_RESET_HA_FW_CONTEXT, &ha->dpc_flags) ||
1821 test_bit(DPC_RESET_HA_INTR, &ha->dpc_flags) ||
1822 test_bit(DPC_GET_DHCP_IP_ADDR, &ha->dpc_flags) ||
1823 test_bit(DPC_LINK_CHANGED, &ha->dpc_flags) ||
1824 test_bit(DPC_HA_UNRECOVERABLE, &ha->dpc_flags) ||
1825 test_bit(DPC_HA_NEED_QUIESCENT, &ha->dpc_flags) ||
1826 test_bit(DPC_AEN, &ha->dpc_flags)) {
1827 DEBUG2(printk("scsi%ld: %s: scheduling dpc routine"
1828 " - dpc flags = 0x%lx\n",
1829 ha->host_no, __func__, ha->dpc_flags));
1830 qla4xxx_wake_dpc(ha);
1833 /* Reschedule timer thread to call us back in one second */
1834 mod_timer(&ha->timer, jiffies + HZ);
1836 DEBUG2(ha->seconds_since_last_intr++);
1840 * qla4xxx_cmd_wait - waits for all outstanding commands to complete
1841 * @ha: Pointer to host adapter structure.
1843 * This routine stalls the driver until all outstanding commands are returned.
1844 * Caller must release the Hardware Lock prior to calling this routine.
1846 static int qla4xxx_cmd_wait(struct scsi_qla_host *ha)
1849 unsigned long flags;
1850 struct scsi_cmnd *cmd;
1852 unsigned long wtime = jiffies + (WAIT_CMD_TOV * HZ);
1854 DEBUG2(ql4_printk(KERN_INFO, ha, "Wait up to %d seconds for cmds to "
1855 "complete\n", WAIT_CMD_TOV));
1857 while (!time_after_eq(jiffies, wtime)) {
1858 spin_lock_irqsave(&ha->hardware_lock, flags);
1859 /* Find a command that hasn't completed. */
1860 for (index = 0; index < ha->host->can_queue; index++) {
1861 cmd = scsi_host_find_tag(ha->host, index);
1863 * We cannot just check if the index is valid,
1864 * becase if we are run from the scsi eh, then
1865 * the scsi/block layer is going to prevent
1866 * the tag from being released.
1868 if (cmd != NULL && CMD_SP(cmd))
1871 spin_unlock_irqrestore(&ha->hardware_lock, flags);
1873 /* If No Commands are pending, wait is complete */
1874 if (index == ha->host->can_queue)
1879 /* If we timed out on waiting for commands to come back
1884 int qla4xxx_hw_reset(struct scsi_qla_host *ha)
1886 uint32_t ctrl_status;
1887 unsigned long flags = 0;
1889 DEBUG2(printk(KERN_ERR "scsi%ld: %s\n", ha->host_no, __func__));
1891 if (ql4xxx_lock_drvr_wait(ha) != QLA_SUCCESS)
1894 spin_lock_irqsave(&ha->hardware_lock, flags);
1897 * If the SCSI Reset Interrupt bit is set, clear it.
1898 * Otherwise, the Soft Reset won't work.
1900 ctrl_status = readw(&ha->reg->ctrl_status);
1901 if ((ctrl_status & CSR_SCSI_RESET_INTR) != 0)
1902 writel(set_rmask(CSR_SCSI_RESET_INTR), &ha->reg->ctrl_status);
1904 /* Issue Soft Reset */
1905 writel(set_rmask(CSR_SOFT_RESET), &ha->reg->ctrl_status);
1906 readl(&ha->reg->ctrl_status);
1908 spin_unlock_irqrestore(&ha->hardware_lock, flags);
1913 * qla4xxx_soft_reset - performs soft reset.
1914 * @ha: Pointer to host adapter structure.
1916 int qla4xxx_soft_reset(struct scsi_qla_host *ha)
1918 uint32_t max_wait_time;
1919 unsigned long flags = 0;
1921 uint32_t ctrl_status;
1923 status = qla4xxx_hw_reset(ha);
1924 if (status != QLA_SUCCESS)
1928 /* Wait until the Network Reset Intr bit is cleared */
1929 max_wait_time = RESET_INTR_TOV;
1931 spin_lock_irqsave(&ha->hardware_lock, flags);
1932 ctrl_status = readw(&ha->reg->ctrl_status);
1933 spin_unlock_irqrestore(&ha->hardware_lock, flags);
1935 if ((ctrl_status & CSR_NET_RESET_INTR) == 0)
1939 } while ((--max_wait_time));
1941 if ((ctrl_status & CSR_NET_RESET_INTR) != 0) {
1942 DEBUG2(printk(KERN_WARNING
1943 "scsi%ld: Network Reset Intr not cleared by "
1944 "Network function, clearing it now!\n",
1946 spin_lock_irqsave(&ha->hardware_lock, flags);
1947 writel(set_rmask(CSR_NET_RESET_INTR), &ha->reg->ctrl_status);
1948 readl(&ha->reg->ctrl_status);
1949 spin_unlock_irqrestore(&ha->hardware_lock, flags);
1952 /* Wait until the firmware tells us the Soft Reset is done */
1953 max_wait_time = SOFT_RESET_TOV;
1955 spin_lock_irqsave(&ha->hardware_lock, flags);
1956 ctrl_status = readw(&ha->reg->ctrl_status);
1957 spin_unlock_irqrestore(&ha->hardware_lock, flags);
1959 if ((ctrl_status & CSR_SOFT_RESET) == 0) {
1960 status = QLA_SUCCESS;
1965 } while ((--max_wait_time));
1968 * Also, make sure that the SCSI Reset Interrupt bit has been cleared
1969 * after the soft reset has taken place.
1971 spin_lock_irqsave(&ha->hardware_lock, flags);
1972 ctrl_status = readw(&ha->reg->ctrl_status);
1973 if ((ctrl_status & CSR_SCSI_RESET_INTR) != 0) {
1974 writel(set_rmask(CSR_SCSI_RESET_INTR), &ha->reg->ctrl_status);
1975 readl(&ha->reg->ctrl_status);
1977 spin_unlock_irqrestore(&ha->hardware_lock, flags);
1979 /* If soft reset fails then most probably the bios on other
1980 * function is also enabled.
1981 * Since the initialization is sequential the other fn
1982 * wont be able to acknowledge the soft reset.
1983 * Issue a force soft reset to workaround this scenario.
1985 if (max_wait_time == 0) {
1986 /* Issue Force Soft Reset */
1987 spin_lock_irqsave(&ha->hardware_lock, flags);
1988 writel(set_rmask(CSR_FORCE_SOFT_RESET), &ha->reg->ctrl_status);
1989 readl(&ha->reg->ctrl_status);
1990 spin_unlock_irqrestore(&ha->hardware_lock, flags);
1991 /* Wait until the firmware tells us the Soft Reset is done */
1992 max_wait_time = SOFT_RESET_TOV;
1994 spin_lock_irqsave(&ha->hardware_lock, flags);
1995 ctrl_status = readw(&ha->reg->ctrl_status);
1996 spin_unlock_irqrestore(&ha->hardware_lock, flags);
1998 if ((ctrl_status & CSR_FORCE_SOFT_RESET) == 0) {
1999 status = QLA_SUCCESS;
2004 } while ((--max_wait_time));
2011 * qla4xxx_abort_active_cmds - returns all outstanding i/o requests to O.S.
2012 * @ha: Pointer to host adapter structure.
2013 * @res: returned scsi status
2015 * This routine is called just prior to a HARD RESET to return all
2016 * outstanding commands back to the Operating System.
2017 * Caller should make sure that the following locks are released
2018 * before this calling routine: Hardware lock, and io_request_lock.
2020 static void qla4xxx_abort_active_cmds(struct scsi_qla_host *ha, int res)
2024 unsigned long flags;
2026 spin_lock_irqsave(&ha->hardware_lock, flags);
2027 for (i = 0; i < ha->host->can_queue; i++) {
2028 srb = qla4xxx_del_from_active_array(ha, i);
2030 srb->cmd->result = res;
2031 kref_put(&srb->srb_ref, qla4xxx_srb_compl);
2034 spin_unlock_irqrestore(&ha->hardware_lock, flags);
2037 void qla4xxx_dead_adapter_cleanup(struct scsi_qla_host *ha)
2039 clear_bit(AF_ONLINE, &ha->flags);
2041 /* Disable the board */
2042 ql4_printk(KERN_INFO, ha, "Disabling the board\n");
2044 qla4xxx_abort_active_cmds(ha, DID_NO_CONNECT << 16);
2045 qla4xxx_mark_all_devices_missing(ha);
2046 clear_bit(AF_INIT_DONE, &ha->flags);
2049 static void qla4xxx_fail_session(struct iscsi_cls_session *cls_session)
2051 struct iscsi_session *sess;
2052 struct ddb_entry *ddb_entry;
2054 sess = cls_session->dd_data;
2055 ddb_entry = sess->dd_data;
2056 ddb_entry->fw_ddb_device_state = DDB_DS_SESSION_FAILED;
2057 iscsi_session_failure(cls_session->dd_data, ISCSI_ERR_CONN_FAILED);
2061 * qla4xxx_recover_adapter - recovers adapter after a fatal error
2062 * @ha: Pointer to host adapter structure.
2064 static int qla4xxx_recover_adapter(struct scsi_qla_host *ha)
2066 int status = QLA_ERROR;
2067 uint8_t reset_chip = 0;
2069 /* Stall incoming I/O until we are done */
2070 scsi_block_requests(ha->host);
2071 clear_bit(AF_ONLINE, &ha->flags);
2072 clear_bit(AF_LINK_UP, &ha->flags);
2074 DEBUG2(ql4_printk(KERN_INFO, ha, "%s: adapter OFFLINE\n", __func__));
2076 set_bit(DPC_RESET_ACTIVE, &ha->dpc_flags);
2078 iscsi_host_for_each_session(ha->host, qla4xxx_fail_session);
2080 if (test_bit(DPC_RESET_HA, &ha->dpc_flags))
2083 /* For the DPC_RESET_HA_INTR case (ISP-4xxx specific)
2084 * do not reset adapter, jump to initialize_adapter */
2085 if (test_bit(DPC_RESET_HA_INTR, &ha->dpc_flags)) {
2086 status = QLA_SUCCESS;
2087 goto recover_ha_init_adapter;
2090 /* For the ISP-82xx adapter, issue a stop_firmware if invoked
2091 * from eh_host_reset or ioctl module */
2092 if (is_qla8022(ha) && !reset_chip &&
2093 test_bit(DPC_RESET_HA_FW_CONTEXT, &ha->dpc_flags)) {
2095 DEBUG2(ql4_printk(KERN_INFO, ha,
2096 "scsi%ld: %s - Performing stop_firmware...\n",
2097 ha->host_no, __func__));
2098 status = ha->isp_ops->reset_firmware(ha);
2099 if (status == QLA_SUCCESS) {
2100 if (!test_bit(AF_FW_RECOVERY, &ha->flags))
2101 qla4xxx_cmd_wait(ha);
2102 ha->isp_ops->disable_intrs(ha);
2103 qla4xxx_process_aen(ha, FLUSH_DDB_CHANGED_AENS);
2104 qla4xxx_abort_active_cmds(ha, DID_RESET << 16);
2106 /* If the stop_firmware fails then
2107 * reset the entire chip */
2109 clear_bit(DPC_RESET_HA_FW_CONTEXT, &ha->dpc_flags);
2110 set_bit(DPC_RESET_HA, &ha->dpc_flags);
2114 /* Issue full chip reset if recovering from a catastrophic error,
2115 * or if stop_firmware fails for ISP-82xx.
2116 * This is the default case for ISP-4xxx */
2117 if (!is_qla8022(ha) || reset_chip) {
2118 if (!test_bit(AF_FW_RECOVERY, &ha->flags))
2119 qla4xxx_cmd_wait(ha);
2120 qla4xxx_process_aen(ha, FLUSH_DDB_CHANGED_AENS);
2121 qla4xxx_abort_active_cmds(ha, DID_RESET << 16);
2122 DEBUG2(ql4_printk(KERN_INFO, ha,
2123 "scsi%ld: %s - Performing chip reset..\n",
2124 ha->host_no, __func__));
2125 status = ha->isp_ops->reset_chip(ha);
2128 /* Flush any pending ddb changed AENs */
2129 qla4xxx_process_aen(ha, FLUSH_DDB_CHANGED_AENS);
2131 recover_ha_init_adapter:
2132 /* Upon successful firmware/chip reset, re-initialize the adapter */
2133 if (status == QLA_SUCCESS) {
2134 /* For ISP-4xxx, force function 1 to always initialize
2135 * before function 3 to prevent both funcions from
2136 * stepping on top of the other */
2137 if (!is_qla8022(ha) && (ha->mac_index == 3))
2140 /* NOTE: AF_ONLINE flag set upon successful completion of
2141 * qla4xxx_initialize_adapter */
2142 status = qla4xxx_initialize_adapter(ha);
2145 /* Retry failed adapter initialization, if necessary
2146 * Do not retry initialize_adapter for RESET_HA_INTR (ISP-4xxx specific)
2147 * case to prevent ping-pong resets between functions */
2148 if (!test_bit(AF_ONLINE, &ha->flags) &&
2149 !test_bit(DPC_RESET_HA_INTR, &ha->dpc_flags)) {
2150 /* Adapter initialization failed, see if we can retry
2152 * Since we don't want to block the DPC for too long
2153 * with multiple resets in the same thread,
2154 * utilize DPC to retry */
2155 if (!test_bit(DPC_RETRY_RESET_HA, &ha->dpc_flags)) {
2156 ha->retry_reset_ha_cnt = MAX_RESET_HA_RETRIES;
2157 DEBUG2(printk("scsi%ld: recover adapter - retrying "
2158 "(%d) more times\n", ha->host_no,
2159 ha->retry_reset_ha_cnt));
2160 set_bit(DPC_RETRY_RESET_HA, &ha->dpc_flags);
2163 if (ha->retry_reset_ha_cnt > 0) {
2164 /* Schedule another Reset HA--DPC will retry */
2165 ha->retry_reset_ha_cnt--;
2166 DEBUG2(printk("scsi%ld: recover adapter - "
2167 "retry remaining %d\n",
2169 ha->retry_reset_ha_cnt));
2173 if (ha->retry_reset_ha_cnt == 0) {
2174 /* Recover adapter retries have been exhausted.
2176 DEBUG2(printk("scsi%ld: recover adapter "
2177 "failed - board disabled\n",
2179 qla4xxx_dead_adapter_cleanup(ha);
2180 clear_bit(DPC_RETRY_RESET_HA, &ha->dpc_flags);
2181 clear_bit(DPC_RESET_HA, &ha->dpc_flags);
2182 clear_bit(DPC_RESET_HA_FW_CONTEXT,
2188 clear_bit(DPC_RESET_HA, &ha->dpc_flags);
2189 clear_bit(DPC_RESET_HA_FW_CONTEXT, &ha->dpc_flags);
2190 clear_bit(DPC_RETRY_RESET_HA, &ha->dpc_flags);
2193 ha->adapter_error_count++;
2195 if (test_bit(AF_ONLINE, &ha->flags))
2196 ha->isp_ops->enable_intrs(ha);
2198 scsi_unblock_requests(ha->host);
2200 clear_bit(DPC_RESET_ACTIVE, &ha->dpc_flags);
2201 DEBUG2(printk("scsi%ld: recover adapter: %s\n", ha->host_no,
2202 status == QLA_ERROR ? "FAILED" : "SUCCEEDED"));
2207 static void qla4xxx_relogin_devices(struct iscsi_cls_session *cls_session)
2209 struct iscsi_session *sess;
2210 struct ddb_entry *ddb_entry;
2211 struct scsi_qla_host *ha;
2213 sess = cls_session->dd_data;
2214 ddb_entry = sess->dd_data;
2216 if (!iscsi_is_session_online(cls_session)) {
2217 if (ddb_entry->fw_ddb_device_state == DDB_DS_SESSION_ACTIVE) {
2218 ql4_printk(KERN_INFO, ha, "scsi%ld: %s: ddb[%d]"
2219 " unblock session\n", ha->host_no, __func__,
2220 ddb_entry->fw_ddb_index);
2221 iscsi_unblock_session(ddb_entry->sess);
2223 /* Trigger relogin */
2224 iscsi_session_failure(cls_session->dd_data,
2225 ISCSI_ERR_CONN_FAILED);
2230 static void qla4xxx_relogin_all_devices(struct scsi_qla_host *ha)
2232 iscsi_host_for_each_session(ha->host, qla4xxx_relogin_devices);
2235 void qla4xxx_wake_dpc(struct scsi_qla_host *ha)
2238 queue_work(ha->dpc_thread, &ha->dpc_work);
2242 * qla4xxx_do_dpc - dpc routine
2243 * @data: in our case pointer to adapter structure
2245 * This routine is a task that is schedule by the interrupt handler
2246 * to perform the background processing for interrupts. We put it
2247 * on a task queue that is consumed whenever the scheduler runs; that's
2248 * so you can do anything (i.e. put the process to sleep etc). In fact,
2249 * the mid-level tries to sleep when it reaches the driver threshold
2250 * "host->can_queue". This can cause a panic if we were in our interrupt code.
2252 static void qla4xxx_do_dpc(struct work_struct *work)
2254 struct scsi_qla_host *ha =
2255 container_of(work, struct scsi_qla_host, dpc_work);
2256 int status = QLA_ERROR;
2258 DEBUG2(printk("scsi%ld: %s: DPC handler waking up."
2259 "flags = 0x%08lx, dpc_flags = 0x%08lx\n",
2260 ha->host_no, __func__, ha->flags, ha->dpc_flags))
2262 /* Initialization not yet finished. Don't do anything yet. */
2263 if (!test_bit(AF_INIT_DONE, &ha->flags))
2266 if (test_bit(AF_EEH_BUSY, &ha->flags)) {
2267 DEBUG2(printk(KERN_INFO "scsi%ld: %s: flags = %lx\n",
2268 ha->host_no, __func__, ha->flags));
2272 if (is_qla8022(ha)) {
2273 if (test_bit(DPC_HA_UNRECOVERABLE, &ha->dpc_flags)) {
2274 qla4_8xxx_idc_lock(ha);
2275 qla4_8xxx_wr_32(ha, QLA82XX_CRB_DEV_STATE,
2276 QLA82XX_DEV_FAILED);
2277 qla4_8xxx_idc_unlock(ha);
2278 ql4_printk(KERN_INFO, ha, "HW State: FAILED\n");
2279 qla4_8xxx_device_state_handler(ha);
2281 if (test_and_clear_bit(DPC_HA_NEED_QUIESCENT, &ha->dpc_flags)) {
2282 qla4_8xxx_need_qsnt_handler(ha);
2286 if (!test_bit(DPC_RESET_ACTIVE, &ha->dpc_flags) &&
2287 (test_bit(DPC_RESET_HA, &ha->dpc_flags) ||
2288 test_bit(DPC_RESET_HA_INTR, &ha->dpc_flags) ||
2289 test_bit(DPC_RESET_HA_FW_CONTEXT, &ha->dpc_flags))) {
2290 if (ql4xdontresethba) {
2291 DEBUG2(printk("scsi%ld: %s: Don't Reset HBA\n",
2292 ha->host_no, __func__));
2293 clear_bit(DPC_RESET_HA, &ha->dpc_flags);
2294 clear_bit(DPC_RESET_HA_INTR, &ha->dpc_flags);
2295 clear_bit(DPC_RESET_HA_FW_CONTEXT, &ha->dpc_flags);
2296 goto dpc_post_reset_ha;
2298 if (test_bit(DPC_RESET_HA_FW_CONTEXT, &ha->dpc_flags) ||
2299 test_bit(DPC_RESET_HA, &ha->dpc_flags))
2300 qla4xxx_recover_adapter(ha);
2302 if (test_bit(DPC_RESET_HA_INTR, &ha->dpc_flags)) {
2303 uint8_t wait_time = RESET_INTR_TOV;
2305 while ((readw(&ha->reg->ctrl_status) &
2306 (CSR_SOFT_RESET | CSR_FORCE_SOFT_RESET)) != 0) {
2307 if (--wait_time == 0)
2312 DEBUG2(printk("scsi%ld: %s: SR|FSR "
2313 "bit not cleared-- resetting\n",
2314 ha->host_no, __func__));
2315 qla4xxx_abort_active_cmds(ha, DID_RESET << 16);
2316 if (ql4xxx_lock_drvr_wait(ha) == QLA_SUCCESS) {
2317 qla4xxx_process_aen(ha, FLUSH_DDB_CHANGED_AENS);
2318 status = qla4xxx_recover_adapter(ha);
2320 clear_bit(DPC_RESET_HA_INTR, &ha->dpc_flags);
2321 if (status == QLA_SUCCESS)
2322 ha->isp_ops->enable_intrs(ha);
2327 /* ---- process AEN? --- */
2328 if (test_and_clear_bit(DPC_AEN, &ha->dpc_flags))
2329 qla4xxx_process_aen(ha, PROCESS_ALL_AENS);
2331 /* ---- Get DHCP IP Address? --- */
2332 if (test_and_clear_bit(DPC_GET_DHCP_IP_ADDR, &ha->dpc_flags))
2333 qla4xxx_get_dhcp_ip_address(ha);
2335 /* ---- link change? --- */
2336 if (test_and_clear_bit(DPC_LINK_CHANGED, &ha->dpc_flags)) {
2337 if (!test_bit(AF_LINK_UP, &ha->flags)) {
2338 /* ---- link down? --- */
2339 qla4xxx_mark_all_devices_missing(ha);
2341 /* ---- link up? --- *
2342 * F/W will auto login to all devices ONLY ONCE after
2343 * link up during driver initialization and runtime
2344 * fatal error recovery. Therefore, the driver must
2345 * manually relogin to devices when recovering from
2346 * connection failures, logouts, expired KATO, etc. */
2348 qla4xxx_relogin_all_devices(ha);
2354 * qla4xxx_free_adapter - release the adapter
2355 * @ha: pointer to adapter structure
2357 static void qla4xxx_free_adapter(struct scsi_qla_host *ha)
2360 if (test_bit(AF_INTERRUPTS_ON, &ha->flags)) {
2361 /* Turn-off interrupts on the card. */
2362 ha->isp_ops->disable_intrs(ha);
2365 /* Remove timer thread, if present */
2366 if (ha->timer_active)
2367 qla4xxx_stop_timer(ha);
2369 /* Kill the kernel thread for this host */
2371 destroy_workqueue(ha->dpc_thread);
2373 /* Kill the kernel thread for this host */
2375 destroy_workqueue(ha->task_wq);
2377 /* Put firmware in known state */
2378 ha->isp_ops->reset_firmware(ha);
2380 if (is_qla8022(ha)) {
2381 qla4_8xxx_idc_lock(ha);
2382 qla4_8xxx_clear_drv_active(ha);
2383 qla4_8xxx_idc_unlock(ha);
2386 /* Detach interrupts */
2387 if (test_and_clear_bit(AF_IRQ_ATTACHED, &ha->flags))
2388 qla4xxx_free_irqs(ha);
2390 /* free extra memory */
2391 qla4xxx_mem_free(ha);
2394 int qla4_8xxx_iospace_config(struct scsi_qla_host *ha)
2397 uint8_t revision_id;
2398 unsigned long mem_base, mem_len, db_base, db_len;
2399 struct pci_dev *pdev = ha->pdev;
2401 status = pci_request_regions(pdev, DRIVER_NAME);
2404 "scsi(%ld) Failed to reserve PIO regions (%s) "
2405 "status=%d\n", ha->host_no, pci_name(pdev), status);
2406 goto iospace_error_exit;
2409 pci_read_config_byte(pdev, PCI_REVISION_ID, &revision_id);
2410 DEBUG2(printk(KERN_INFO "%s: revision-id=%d\n",
2411 __func__, revision_id));
2412 ha->revision_id = revision_id;
2414 /* remap phys address */
2415 mem_base = pci_resource_start(pdev, 0); /* 0 is for BAR 0 */
2416 mem_len = pci_resource_len(pdev, 0);
2417 DEBUG2(printk(KERN_INFO "%s: ioremap from %lx a size of %lx\n",
2418 __func__, mem_base, mem_len));
2420 /* mapping of pcibase pointer */
2421 ha->nx_pcibase = (unsigned long)ioremap(mem_base, mem_len);
2422 if (!ha->nx_pcibase) {
2424 "cannot remap MMIO (%s), aborting\n", pci_name(pdev));
2425 pci_release_regions(ha->pdev);
2426 goto iospace_error_exit;
2429 /* Mapping of IO base pointer, door bell read and write pointer */
2431 /* mapping of IO base pointer */
2433 (struct device_reg_82xx __iomem *)((uint8_t *)ha->nx_pcibase +
2434 0xbc000 + (ha->pdev->devfn << 11));
2436 db_base = pci_resource_start(pdev, 4); /* doorbell is on bar 4 */
2437 db_len = pci_resource_len(pdev, 4);
2439 ha->nx_db_wr_ptr = (ha->pdev->devfn == 4 ? QLA82XX_CAM_RAM_DB1 :
2440 QLA82XX_CAM_RAM_DB2);
2448 * qla4xxx_iospace_config - maps registers
2449 * @ha: pointer to adapter structure
2451 * This routines maps HBA's registers from the pci address space
2452 * into the kernel virtual address space for memory mapped i/o.
2454 int qla4xxx_iospace_config(struct scsi_qla_host *ha)
2456 unsigned long pio, pio_len, pio_flags;
2457 unsigned long mmio, mmio_len, mmio_flags;
2459 pio = pci_resource_start(ha->pdev, 0);
2460 pio_len = pci_resource_len(ha->pdev, 0);
2461 pio_flags = pci_resource_flags(ha->pdev, 0);
2462 if (pio_flags & IORESOURCE_IO) {
2463 if (pio_len < MIN_IOBASE_LEN) {
2464 ql4_printk(KERN_WARNING, ha,
2465 "Invalid PCI I/O region size\n");
2469 ql4_printk(KERN_WARNING, ha, "region #0 not a PIO resource\n");
2473 /* Use MMIO operations for all accesses. */
2474 mmio = pci_resource_start(ha->pdev, 1);
2475 mmio_len = pci_resource_len(ha->pdev, 1);
2476 mmio_flags = pci_resource_flags(ha->pdev, 1);
2478 if (!(mmio_flags & IORESOURCE_MEM)) {
2479 ql4_printk(KERN_ERR, ha,
2480 "region #0 not an MMIO resource, aborting\n");
2482 goto iospace_error_exit;
2485 if (mmio_len < MIN_IOBASE_LEN) {
2486 ql4_printk(KERN_ERR, ha,
2487 "Invalid PCI mem region size, aborting\n");
2488 goto iospace_error_exit;
2491 if (pci_request_regions(ha->pdev, DRIVER_NAME)) {
2492 ql4_printk(KERN_WARNING, ha,
2493 "Failed to reserve PIO/MMIO regions\n");
2495 goto iospace_error_exit;
2498 ha->pio_address = pio;
2499 ha->pio_length = pio_len;
2500 ha->reg = ioremap(mmio, MIN_IOBASE_LEN);
2502 ql4_printk(KERN_ERR, ha,
2503 "cannot remap MMIO, aborting\n");
2505 goto iospace_error_exit;
2514 static struct isp_operations qla4xxx_isp_ops = {
2515 .iospace_config = qla4xxx_iospace_config,
2516 .pci_config = qla4xxx_pci_config,
2517 .disable_intrs = qla4xxx_disable_intrs,
2518 .enable_intrs = qla4xxx_enable_intrs,
2519 .start_firmware = qla4xxx_start_firmware,
2520 .intr_handler = qla4xxx_intr_handler,
2521 .interrupt_service_routine = qla4xxx_interrupt_service_routine,
2522 .reset_chip = qla4xxx_soft_reset,
2523 .reset_firmware = qla4xxx_hw_reset,
2524 .queue_iocb = qla4xxx_queue_iocb,
2525 .complete_iocb = qla4xxx_complete_iocb,
2526 .rd_shdw_req_q_out = qla4xxx_rd_shdw_req_q_out,
2527 .rd_shdw_rsp_q_in = qla4xxx_rd_shdw_rsp_q_in,
2528 .get_sys_info = qla4xxx_get_sys_info,
2531 static struct isp_operations qla4_8xxx_isp_ops = {
2532 .iospace_config = qla4_8xxx_iospace_config,
2533 .pci_config = qla4_8xxx_pci_config,
2534 .disable_intrs = qla4_8xxx_disable_intrs,
2535 .enable_intrs = qla4_8xxx_enable_intrs,
2536 .start_firmware = qla4_8xxx_load_risc,
2537 .intr_handler = qla4_8xxx_intr_handler,
2538 .interrupt_service_routine = qla4_8xxx_interrupt_service_routine,
2539 .reset_chip = qla4_8xxx_isp_reset,
2540 .reset_firmware = qla4_8xxx_stop_firmware,
2541 .queue_iocb = qla4_8xxx_queue_iocb,
2542 .complete_iocb = qla4_8xxx_complete_iocb,
2543 .rd_shdw_req_q_out = qla4_8xxx_rd_shdw_req_q_out,
2544 .rd_shdw_rsp_q_in = qla4_8xxx_rd_shdw_rsp_q_in,
2545 .get_sys_info = qla4_8xxx_get_sys_info,
2548 uint16_t qla4xxx_rd_shdw_req_q_out(struct scsi_qla_host *ha)
2550 return (uint16_t)le32_to_cpu(ha->shadow_regs->req_q_out);
2553 uint16_t qla4_8xxx_rd_shdw_req_q_out(struct scsi_qla_host *ha)
2555 return (uint16_t)le32_to_cpu(readl(&ha->qla4_8xxx_reg->req_q_out));
2558 uint16_t qla4xxx_rd_shdw_rsp_q_in(struct scsi_qla_host *ha)
2560 return (uint16_t)le32_to_cpu(ha->shadow_regs->rsp_q_in);
2563 uint16_t qla4_8xxx_rd_shdw_rsp_q_in(struct scsi_qla_host *ha)
2565 return (uint16_t)le32_to_cpu(readl(&ha->qla4_8xxx_reg->rsp_q_in));
2568 static ssize_t qla4xxx_show_boot_eth_info(void *data, int type, char *buf)
2570 struct scsi_qla_host *ha = data;
2575 case ISCSI_BOOT_ETH_FLAGS:
2576 rc = sprintf(str, "%d\n", SYSFS_FLAG_FW_SEL_BOOT);
2578 case ISCSI_BOOT_ETH_INDEX:
2579 rc = sprintf(str, "0\n");
2581 case ISCSI_BOOT_ETH_MAC:
2582 rc = sysfs_format_mac(str, ha->my_mac,
2592 static mode_t qla4xxx_eth_get_attr_visibility(void *data, int type)
2597 case ISCSI_BOOT_ETH_FLAGS:
2598 case ISCSI_BOOT_ETH_MAC:
2599 case ISCSI_BOOT_ETH_INDEX:
2609 static ssize_t qla4xxx_show_boot_ini_info(void *data, int type, char *buf)
2611 struct scsi_qla_host *ha = data;
2616 case ISCSI_BOOT_INI_INITIATOR_NAME:
2617 rc = sprintf(str, "%s\n", ha->name_string);
2626 static mode_t qla4xxx_ini_get_attr_visibility(void *data, int type)
2631 case ISCSI_BOOT_INI_INITIATOR_NAME:
2642 qla4xxx_show_boot_tgt_info(struct ql4_boot_session_info *boot_sess, int type,
2645 struct ql4_conn_info *boot_conn = &boot_sess->conn_list[0];
2650 case ISCSI_BOOT_TGT_NAME:
2651 rc = sprintf(buf, "%s\n", (char *)&boot_sess->target_name);
2653 case ISCSI_BOOT_TGT_IP_ADDR:
2654 if (boot_sess->conn_list[0].dest_ipaddr.ip_type == 0x1)
2655 rc = sprintf(buf, "%pI4\n",
2656 &boot_conn->dest_ipaddr.ip_address);
2658 rc = sprintf(str, "%pI6\n",
2659 &boot_conn->dest_ipaddr.ip_address);
2661 case ISCSI_BOOT_TGT_PORT:
2662 rc = sprintf(str, "%d\n", boot_conn->dest_port);
2664 case ISCSI_BOOT_TGT_CHAP_NAME:
2665 rc = sprintf(str, "%.*s\n",
2666 boot_conn->chap.target_chap_name_length,
2667 (char *)&boot_conn->chap.target_chap_name);
2669 case ISCSI_BOOT_TGT_CHAP_SECRET:
2670 rc = sprintf(str, "%.*s\n",
2671 boot_conn->chap.target_secret_length,
2672 (char *)&boot_conn->chap.target_secret);
2674 case ISCSI_BOOT_TGT_REV_CHAP_NAME:
2675 rc = sprintf(str, "%.*s\n",
2676 boot_conn->chap.intr_chap_name_length,
2677 (char *)&boot_conn->chap.intr_chap_name);
2679 case ISCSI_BOOT_TGT_REV_CHAP_SECRET:
2680 rc = sprintf(str, "%.*s\n",
2681 boot_conn->chap.intr_secret_length,
2682 (char *)&boot_conn->chap.intr_secret);
2684 case ISCSI_BOOT_TGT_FLAGS:
2685 rc = sprintf(str, "%d\n", SYSFS_FLAG_FW_SEL_BOOT);
2687 case ISCSI_BOOT_TGT_NIC_ASSOC:
2688 rc = sprintf(str, "0\n");
2697 static ssize_t qla4xxx_show_boot_tgt_pri_info(void *data, int type, char *buf)
2699 struct scsi_qla_host *ha = data;
2700 struct ql4_boot_session_info *boot_sess = &(ha->boot_tgt.boot_pri_sess);
2702 return qla4xxx_show_boot_tgt_info(boot_sess, type, buf);
2705 static ssize_t qla4xxx_show_boot_tgt_sec_info(void *data, int type, char *buf)
2707 struct scsi_qla_host *ha = data;
2708 struct ql4_boot_session_info *boot_sess = &(ha->boot_tgt.boot_sec_sess);
2710 return qla4xxx_show_boot_tgt_info(boot_sess, type, buf);
2713 static mode_t qla4xxx_tgt_get_attr_visibility(void *data, int type)
2718 case ISCSI_BOOT_TGT_NAME:
2719 case ISCSI_BOOT_TGT_IP_ADDR:
2720 case ISCSI_BOOT_TGT_PORT:
2721 case ISCSI_BOOT_TGT_CHAP_NAME:
2722 case ISCSI_BOOT_TGT_CHAP_SECRET:
2723 case ISCSI_BOOT_TGT_REV_CHAP_NAME:
2724 case ISCSI_BOOT_TGT_REV_CHAP_SECRET:
2725 case ISCSI_BOOT_TGT_NIC_ASSOC:
2726 case ISCSI_BOOT_TGT_FLAGS:
2736 static void qla4xxx_boot_release(void *data)
2738 struct scsi_qla_host *ha = data;
2740 scsi_host_put(ha->host);
2743 static int get_fw_boot_info(struct scsi_qla_host *ha, uint16_t ddb_index[])
2746 uint32_t addr, pri_addr, sec_addr;
2750 uint8_t *buf = NULL;
2751 size_t size = 13 * sizeof(uint8_t);
2752 int ret = QLA_SUCCESS;
2754 func_num = PCI_FUNC(ha->pdev->devfn);
2756 DEBUG2(ql4_printk(KERN_INFO, ha,
2757 "%s: Get FW boot info for 0x%x func %d\n", __func__,
2758 (is_qla4032(ha) ? PCI_DEVICE_ID_QLOGIC_ISP4032 :
2759 PCI_DEVICE_ID_QLOGIC_ISP8022), func_num));
2761 if (is_qla4032(ha)) {
2762 if (func_num == 1) {
2763 addr = NVRAM_PORT0_BOOT_MODE;
2764 pri_addr = NVRAM_PORT0_BOOT_PRI_TGT;
2765 sec_addr = NVRAM_PORT0_BOOT_SEC_TGT;
2766 } else if (func_num == 3) {
2767 addr = NVRAM_PORT1_BOOT_MODE;
2768 pri_addr = NVRAM_PORT1_BOOT_PRI_TGT;
2769 sec_addr = NVRAM_PORT1_BOOT_SEC_TGT;
2772 goto exit_boot_info;
2775 /* Check Boot Mode */
2776 val = rd_nvram_byte(ha, addr);
2777 if (!(val & 0x07)) {
2778 DEBUG2(ql4_printk(KERN_ERR, ha,
2779 "%s: Failed Boot options : 0x%x\n",
2782 goto exit_boot_info;
2785 /* get primary valid target index */
2786 val = rd_nvram_byte(ha, pri_addr);
2788 ddb_index[0] = (val & 0x7f);
2792 /* get secondary valid target index */
2793 val = rd_nvram_byte(ha, sec_addr);
2795 ddb_index[1] = (val & 0x7f);
2799 } else if (is_qla8022(ha)) {
2800 buf = dma_alloc_coherent(&ha->pdev->dev, size,
2801 &buf_dma, GFP_KERNEL);
2803 DEBUG2(ql4_printk(KERN_ERR, ha,
2804 "%s: Unable to allocate dma buffer\n",
2807 goto exit_boot_info;
2810 if (ha->port_num == 0)
2811 offset = BOOT_PARAM_OFFSET_PORT0;
2812 else if (ha->port_num == 1)
2813 offset = BOOT_PARAM_OFFSET_PORT1;
2816 goto exit_boot_info_free;
2818 addr = FLASH_RAW_ACCESS_ADDR + (ha->hw.flt_iscsi_param * 4) +
2820 if (qla4xxx_get_flash(ha, buf_dma, addr,
2821 13 * sizeof(uint8_t)) != QLA_SUCCESS) {
2822 DEBUG2(ql4_printk(KERN_ERR, ha, "scsi%ld: %s: Get Flash"
2823 "failed\n", ha->host_no, __func__));
2825 goto exit_boot_info_free;
2827 /* Check Boot Mode */
2828 if (!(buf[1] & 0x07)) {
2829 DEBUG2(ql4_printk(KERN_INFO, ha,
2830 "Failed: Boot options : 0x%x\n",
2833 goto exit_boot_info_free;
2836 /* get primary valid target index */
2838 ddb_index[0] = buf[2] & 0x7f;
2842 /* get secondary valid target index */
2843 if (buf[11] & BIT_7)
2844 ddb_index[1] = buf[11] & 0x7f;
2850 goto exit_boot_info;
2853 DEBUG2(ql4_printk(KERN_INFO, ha, "%s: Primary target ID %d, Secondary"
2854 " target ID %d\n", __func__, ddb_index[0],
2857 exit_boot_info_free:
2858 dma_free_coherent(&ha->pdev->dev, size, buf, buf_dma);
2863 static int qla4xxx_get_boot_target(struct scsi_qla_host *ha,
2864 struct ql4_boot_session_info *boot_sess,
2867 struct ql4_conn_info *boot_conn = &boot_sess->conn_list[0];
2868 struct dev_db_entry *fw_ddb_entry;
2869 dma_addr_t fw_ddb_entry_dma;
2872 int ret = QLA_SUCCESS;
2874 fw_ddb_entry = dma_alloc_coherent(&ha->pdev->dev, sizeof(*fw_ddb_entry),
2875 &fw_ddb_entry_dma, GFP_KERNEL);
2876 if (!fw_ddb_entry) {
2877 DEBUG2(ql4_printk(KERN_ERR, ha,
2878 "%s: Unable to allocate dma buffer.\n",
2884 if (qla4xxx_bootdb_by_index(ha, fw_ddb_entry,
2885 fw_ddb_entry_dma, ddb_index)) {
2886 DEBUG2(ql4_printk(KERN_ERR, ha,
2887 "%s: Flash DDB read Failed\n", __func__));
2889 goto exit_boot_target;
2892 /* Update target name and IP from DDB */
2893 memcpy(boot_sess->target_name, fw_ddb_entry->iscsi_name,
2894 min(sizeof(boot_sess->target_name),
2895 sizeof(fw_ddb_entry->iscsi_name)));
2897 options = le16_to_cpu(fw_ddb_entry->options);
2898 if (options & DDB_OPT_IPV6_DEVICE) {
2899 memcpy(&boot_conn->dest_ipaddr.ip_address,
2900 &fw_ddb_entry->ip_addr[0], IPv6_ADDR_LEN);
2902 boot_conn->dest_ipaddr.ip_type = 0x1;
2903 memcpy(&boot_conn->dest_ipaddr.ip_address,
2904 &fw_ddb_entry->ip_addr[0], IP_ADDR_LEN);
2907 boot_conn->dest_port = le16_to_cpu(fw_ddb_entry->port);
2909 /* update chap information */
2910 idx = __le16_to_cpu(fw_ddb_entry->chap_tbl_idx);
2912 if (BIT_7 & le16_to_cpu(fw_ddb_entry->iscsi_options)) {
2914 DEBUG2(ql4_printk(KERN_INFO, ha, "Setting chap\n"));
2916 ret = qla4xxx_get_chap(ha, (char *)&boot_conn->chap.
2918 (char *)&boot_conn->chap.target_secret,
2921 ql4_printk(KERN_ERR, ha, "Failed to set chap\n");
2923 goto exit_boot_target;
2926 boot_conn->chap.target_chap_name_length = QL4_CHAP_MAX_NAME_LEN;
2927 boot_conn->chap.target_secret_length = QL4_CHAP_MAX_SECRET_LEN;
2930 if (BIT_4 & le16_to_cpu(fw_ddb_entry->iscsi_options)) {
2932 DEBUG2(ql4_printk(KERN_INFO, ha, "Setting BIDI chap\n"));
2934 ret = qla4xxx_get_chap(ha, (char *)&boot_conn->chap.
2936 (char *)&boot_conn->chap.intr_secret,
2939 ql4_printk(KERN_ERR, ha, "Failed to set BIDI chap\n");
2941 goto exit_boot_target;
2944 boot_conn->chap.intr_chap_name_length = QL4_CHAP_MAX_NAME_LEN;
2945 boot_conn->chap.intr_secret_length = QL4_CHAP_MAX_SECRET_LEN;
2949 dma_free_coherent(&ha->pdev->dev, sizeof(*fw_ddb_entry),
2950 fw_ddb_entry, fw_ddb_entry_dma);
2954 static int qla4xxx_get_boot_info(struct scsi_qla_host *ha)
2956 uint16_t ddb_index[2];
2957 int ret = QLA_SUCCESS;
2959 memset(ddb_index, 0, sizeof(ddb_index));
2960 ret = get_fw_boot_info(ha, ddb_index);
2961 if (ret != QLA_SUCCESS) {
2962 DEBUG2(ql4_printk(KERN_ERR, ha,
2963 "%s: Failed to set boot info.\n", __func__));
2967 ret = qla4xxx_get_boot_target(ha, &(ha->boot_tgt.boot_pri_sess),
2969 if (ret != QLA_SUCCESS) {
2970 DEBUG2(ql4_printk(KERN_ERR, ha, "%s: Failed to get "
2971 "primary target\n", __func__));
2974 ret = qla4xxx_get_boot_target(ha, &(ha->boot_tgt.boot_sec_sess),
2976 if (ret != QLA_SUCCESS) {
2977 DEBUG2(ql4_printk(KERN_ERR, ha, "%s: Failed to get "
2978 "secondary target\n", __func__));
2983 static int qla4xxx_setup_boot_info(struct scsi_qla_host *ha)
2985 struct iscsi_boot_kobj *boot_kobj;
2987 if (qla4xxx_get_boot_info(ha) != QLA_SUCCESS)
2990 ha->boot_kset = iscsi_boot_create_host_kset(ha->host->host_no);
2994 if (!scsi_host_get(ha->host))
2996 boot_kobj = iscsi_boot_create_target(ha->boot_kset, 0, ha,
2997 qla4xxx_show_boot_tgt_pri_info,
2998 qla4xxx_tgt_get_attr_visibility,
2999 qla4xxx_boot_release);
3003 if (!scsi_host_get(ha->host))
3005 boot_kobj = iscsi_boot_create_target(ha->boot_kset, 1, ha,
3006 qla4xxx_show_boot_tgt_sec_info,
3007 qla4xxx_tgt_get_attr_visibility,
3008 qla4xxx_boot_release);
3012 if (!scsi_host_get(ha->host))
3014 boot_kobj = iscsi_boot_create_initiator(ha->boot_kset, 0, ha,
3015 qla4xxx_show_boot_ini_info,
3016 qla4xxx_ini_get_attr_visibility,
3017 qla4xxx_boot_release);
3021 if (!scsi_host_get(ha->host))
3023 boot_kobj = iscsi_boot_create_ethernet(ha->boot_kset, 0, ha,
3024 qla4xxx_show_boot_eth_info,
3025 qla4xxx_eth_get_attr_visibility,
3026 qla4xxx_boot_release);
3033 scsi_host_put(ha->host);
3035 iscsi_boot_destroy_kset(ha->boot_kset);
3040 * qla4xxx_probe_adapter - callback function to probe HBA
3041 * @pdev: pointer to pci_dev structure
3042 * @pci_device_id: pointer to pci_device entry
3044 * This routine will probe for Qlogic 4xxx iSCSI host adapters.
3045 * It returns zero if successful. It also initializes all data necessary for
3048 static int __devinit qla4xxx_probe_adapter(struct pci_dev *pdev,
3049 const struct pci_device_id *ent)
3051 int ret = -ENODEV, status;
3052 struct Scsi_Host *host;
3053 struct scsi_qla_host *ha;
3054 uint8_t init_retry_count = 0;
3056 struct qla4_8xxx_legacy_intr_set *nx_legacy_intr;
3059 if (pci_enable_device(pdev))
3062 host = iscsi_host_alloc(&qla4xxx_driver_template, sizeof(*ha), 0);
3065 "qla4xxx: Couldn't allocate host from scsi layer!\n");
3066 goto probe_disable_device;
3069 /* Clear our data area */
3070 ha = to_qla_host(host);
3071 memset(ha, 0, sizeof(*ha));
3073 /* Save the information from PCI BIOS. */
3076 ha->host_no = host->host_no;
3078 pci_enable_pcie_error_reporting(pdev);
3080 /* Setup Runtime configurable options */
3081 if (is_qla8022(ha)) {
3082 ha->isp_ops = &qla4_8xxx_isp_ops;
3083 rwlock_init(&ha->hw_lock);
3084 ha->qdr_sn_window = -1;
3085 ha->ddr_mn_window = -1;
3086 ha->curr_window = 255;
3087 ha->func_num = PCI_FUNC(ha->pdev->devfn);
3088 nx_legacy_intr = &legacy_intr[ha->func_num];
3089 ha->nx_legacy_intr.int_vec_bit = nx_legacy_intr->int_vec_bit;
3090 ha->nx_legacy_intr.tgt_status_reg =
3091 nx_legacy_intr->tgt_status_reg;
3092 ha->nx_legacy_intr.tgt_mask_reg = nx_legacy_intr->tgt_mask_reg;
3093 ha->nx_legacy_intr.pci_int_reg = nx_legacy_intr->pci_int_reg;
3095 ha->isp_ops = &qla4xxx_isp_ops;
3098 /* Set EEH reset type to fundamental if required by hba */
3100 pdev->needs_freset = 1;
3102 /* Configure PCI I/O space. */
3103 ret = ha->isp_ops->iospace_config(ha);
3105 goto probe_failed_ioconfig;
3107 ql4_printk(KERN_INFO, ha, "Found an ISP%04x, irq %d, iobase 0x%p\n",
3108 pdev->device, pdev->irq, ha->reg);
3110 qla4xxx_config_dma_addressing(ha);
3112 /* Initialize lists and spinlocks. */
3113 INIT_LIST_HEAD(&ha->free_srb_q);
3115 mutex_init(&ha->mbox_sem);
3116 init_completion(&ha->mbx_intr_comp);
3118 spin_lock_init(&ha->hardware_lock);
3120 /* Allocate dma buffers */
3121 if (qla4xxx_mem_alloc(ha)) {
3122 ql4_printk(KERN_WARNING, ha,
3123 "[ERROR] Failed to allocate memory for adapter\n");
3129 host->cmd_per_lun = 3;
3130 host->max_channel = 0;
3131 host->max_lun = MAX_LUNS - 1;
3132 host->max_id = MAX_TARGETS;
3133 host->max_cmd_len = IOCB_MAX_CDB_LEN;
3134 host->can_queue = MAX_SRBS ;
3135 host->transportt = qla4xxx_scsi_transport;
3137 ret = scsi_init_shared_tag_map(host, MAX_SRBS);
3139 ql4_printk(KERN_WARNING, ha,
3140 "%s: scsi_init_shared_tag_map failed\n", __func__);
3144 pci_set_drvdata(pdev, ha);
3146 ret = scsi_add_host(host, &pdev->dev);
3151 (void) qla4_8xxx_get_flash_info(ha);
3154 * Initialize the Host adapter request/response queues and
3156 * NOTE: interrupts enabled upon successful completion
3158 status = qla4xxx_initialize_adapter(ha);
3159 while ((!test_bit(AF_ONLINE, &ha->flags)) &&
3160 init_retry_count++ < MAX_INIT_RETRIES) {
3162 if (is_qla8022(ha)) {
3163 qla4_8xxx_idc_lock(ha);
3164 dev_state = qla4_8xxx_rd_32(ha, QLA82XX_CRB_DEV_STATE);
3165 qla4_8xxx_idc_unlock(ha);
3166 if (dev_state == QLA82XX_DEV_FAILED) {
3167 ql4_printk(KERN_WARNING, ha, "%s: don't retry "
3168 "initialize adapter. H/W is in failed state\n",
3173 DEBUG2(printk("scsi: %s: retrying adapter initialization "
3174 "(%d)\n", __func__, init_retry_count));
3176 if (ha->isp_ops->reset_chip(ha) == QLA_ERROR)
3179 status = qla4xxx_initialize_adapter(ha);
3182 if (!test_bit(AF_ONLINE, &ha->flags)) {
3183 ql4_printk(KERN_WARNING, ha, "Failed to initialize adapter\n");
3185 if (is_qla8022(ha) && ql4xdontresethba) {
3186 /* Put the device in failed state. */
3187 DEBUG2(printk(KERN_ERR "HW STATE: FAILED\n"));
3188 qla4_8xxx_idc_lock(ha);
3189 qla4_8xxx_wr_32(ha, QLA82XX_CRB_DEV_STATE,
3190 QLA82XX_DEV_FAILED);
3191 qla4_8xxx_idc_unlock(ha);
3197 /* Startup the kernel thread for this host adapter. */
3198 DEBUG2(printk("scsi: %s: Starting kernel thread for "
3199 "qla4xxx_dpc\n", __func__));
3200 sprintf(buf, "qla4xxx_%lu_dpc", ha->host_no);
3201 ha->dpc_thread = create_singlethread_workqueue(buf);
3202 if (!ha->dpc_thread) {
3203 ql4_printk(KERN_WARNING, ha, "Unable to start DPC thread!\n");
3207 INIT_WORK(&ha->dpc_work, qla4xxx_do_dpc);
3209 sprintf(buf, "qla4xxx_%lu_task", ha->host_no);
3210 ha->task_wq = alloc_workqueue(buf, WQ_MEM_RECLAIM, 1);
3212 ql4_printk(KERN_WARNING, ha, "Unable to start task thread!\n");
3217 /* For ISP-82XX, request_irqs is called in qla4_8xxx_load_risc
3218 * (which is called indirectly by qla4xxx_initialize_adapter),
3219 * so that irqs will be registered after crbinit but before
3222 if (!is_qla8022(ha)) {
3223 ret = qla4xxx_request_irqs(ha);
3225 ql4_printk(KERN_WARNING, ha, "Failed to reserve "
3226 "interrupt %d already in use.\n", pdev->irq);
3231 pci_save_state(ha->pdev);
3232 ha->isp_ops->enable_intrs(ha);
3234 /* Start timer thread. */
3235 qla4xxx_start_timer(ha, qla4xxx_timer, 1);
3237 set_bit(AF_INIT_DONE, &ha->flags);
3240 " QLogic iSCSI HBA Driver version: %s\n"
3241 " QLogic ISP%04x @ %s, host#=%ld, fw=%02d.%02d.%02d.%02d\n",
3242 qla4xxx_version_str, ha->pdev->device, pci_name(ha->pdev),
3243 ha->host_no, ha->firmware_version[0], ha->firmware_version[1],
3244 ha->patch_number, ha->build_number);
3246 if (qla4xxx_setup_boot_info(ha))
3247 ql4_printk(KERN_ERR, ha, "%s:ISCSI boot info setup failed\n",
3250 qla4xxx_create_ifaces(ha);
3254 scsi_remove_host(ha->host);
3257 qla4xxx_free_adapter(ha);
3259 probe_failed_ioconfig:
3260 pci_disable_pcie_error_reporting(pdev);
3261 scsi_host_put(ha->host);
3263 probe_disable_device:
3264 pci_disable_device(pdev);
3270 * qla4xxx_prevent_other_port_reinit - prevent other port from re-initialize
3271 * @ha: pointer to adapter structure
3273 * Mark the other ISP-4xxx port to indicate that the driver is being removed,
3274 * so that the other port will not re-initialize while in the process of
3275 * removing the ha due to driver unload or hba hotplug.
3277 static void qla4xxx_prevent_other_port_reinit(struct scsi_qla_host *ha)
3279 struct scsi_qla_host *other_ha = NULL;
3280 struct pci_dev *other_pdev = NULL;
3281 int fn = ISP4XXX_PCI_FN_2;
3283 /*iscsi function numbers for ISP4xxx is 1 and 3*/
3284 if (PCI_FUNC(ha->pdev->devfn) & BIT_1)
3285 fn = ISP4XXX_PCI_FN_1;
3288 pci_get_domain_bus_and_slot(pci_domain_nr(ha->pdev->bus),
3289 ha->pdev->bus->number, PCI_DEVFN(PCI_SLOT(ha->pdev->devfn),
3292 /* Get other_ha if other_pdev is valid and state is enable*/
3294 if (atomic_read(&other_pdev->enable_cnt)) {
3295 other_ha = pci_get_drvdata(other_pdev);
3297 set_bit(AF_HA_REMOVAL, &other_ha->flags);
3298 DEBUG2(ql4_printk(KERN_INFO, ha, "%s: "
3299 "Prevent %s reinit\n", __func__,
3300 dev_name(&other_ha->pdev->dev)));
3303 pci_dev_put(other_pdev);
3308 * qla4xxx_remove_adapter - calback function to remove adapter.
3309 * @pci_dev: PCI device pointer
3311 static void __devexit qla4xxx_remove_adapter(struct pci_dev *pdev)
3313 struct scsi_qla_host *ha;
3315 ha = pci_get_drvdata(pdev);
3317 if (!is_qla8022(ha))
3318 qla4xxx_prevent_other_port_reinit(ha);
3320 /* destroy iface from sysfs */
3321 qla4xxx_destroy_ifaces(ha);
3324 iscsi_boot_destroy_kset(ha->boot_kset);
3326 scsi_remove_host(ha->host);
3328 qla4xxx_free_adapter(ha);
3330 scsi_host_put(ha->host);
3332 pci_disable_pcie_error_reporting(pdev);
3333 pci_disable_device(pdev);
3334 pci_set_drvdata(pdev, NULL);
3338 * qla4xxx_config_dma_addressing() - Configure OS DMA addressing method.
3341 * At exit, the @ha's flags.enable_64bit_addressing set to indicated
3342 * supported addressing method.
3344 static void qla4xxx_config_dma_addressing(struct scsi_qla_host *ha)
3348 /* Update our PCI device dma_mask for full 64 bit mask */
3349 if (pci_set_dma_mask(ha->pdev, DMA_BIT_MASK(64)) == 0) {
3350 if (pci_set_consistent_dma_mask(ha->pdev, DMA_BIT_MASK(64))) {
3351 dev_dbg(&ha->pdev->dev,
3352 "Failed to set 64 bit PCI consistent mask; "
3354 retval = pci_set_consistent_dma_mask(ha->pdev,
3358 retval = pci_set_dma_mask(ha->pdev, DMA_BIT_MASK(32));
3361 static int qla4xxx_slave_alloc(struct scsi_device *sdev)
3363 struct iscsi_cls_session *cls_sess;
3364 struct iscsi_session *sess;
3365 struct ddb_entry *ddb;
3366 int queue_depth = QL4_DEF_QDEPTH;
3368 cls_sess = starget_to_session(sdev->sdev_target);
3369 sess = cls_sess->dd_data;
3370 ddb = sess->dd_data;
3372 sdev->hostdata = ddb;
3373 sdev->tagged_supported = 1;
3375 if (ql4xmaxqdepth != 0 && ql4xmaxqdepth <= 0xffffU)
3376 queue_depth = ql4xmaxqdepth;
3378 scsi_activate_tcq(sdev, queue_depth);
3382 static int qla4xxx_slave_configure(struct scsi_device *sdev)
3384 sdev->tagged_supported = 1;
3388 static void qla4xxx_slave_destroy(struct scsi_device *sdev)
3390 scsi_deactivate_tcq(sdev, 1);
3394 * qla4xxx_del_from_active_array - returns an active srb
3395 * @ha: Pointer to host adapter structure.
3396 * @index: index into the active_array
3398 * This routine removes and returns the srb at the specified index
3400 struct srb *qla4xxx_del_from_active_array(struct scsi_qla_host *ha,
3403 struct srb *srb = NULL;
3404 struct scsi_cmnd *cmd = NULL;
3406 cmd = scsi_host_find_tag(ha->host, index);
3410 srb = (struct srb *)CMD_SP(cmd);
3414 /* update counters */
3415 if (srb->flags & SRB_DMA_VALID) {
3416 ha->req_q_count += srb->iocb_cnt;
3417 ha->iocb_cnt -= srb->iocb_cnt;
3419 srb->cmd->host_scribble =
3420 (unsigned char *)(unsigned long) MAX_SRBS;
3426 * qla4xxx_eh_wait_on_command - waits for command to be returned by firmware
3427 * @ha: Pointer to host adapter structure.
3428 * @cmd: Scsi Command to wait on.
3430 * This routine waits for the command to be returned by the Firmware
3431 * for some max time.
3433 static int qla4xxx_eh_wait_on_command(struct scsi_qla_host *ha,
3434 struct scsi_cmnd *cmd)
3438 uint32_t max_wait_time = EH_WAIT_CMD_TOV;
3441 /* Dont wait on command if PCI error is being handled
3444 if (unlikely(pci_channel_offline(ha->pdev)) ||
3445 (test_bit(AF_EEH_BUSY, &ha->flags))) {
3446 ql4_printk(KERN_WARNING, ha, "scsi%ld: Return from %s\n",
3447 ha->host_no, __func__);
3452 /* Checking to see if its returned to OS */
3453 rp = (struct srb *) CMD_SP(cmd);
3460 } while (max_wait_time--);
3466 * qla4xxx_wait_for_hba_online - waits for HBA to come online
3467 * @ha: Pointer to host adapter structure
3469 static int qla4xxx_wait_for_hba_online(struct scsi_qla_host *ha)
3471 unsigned long wait_online;
3473 wait_online = jiffies + (HBA_ONLINE_TOV * HZ);
3474 while (time_before(jiffies, wait_online)) {
3486 * qla4xxx_eh_wait_for_commands - wait for active cmds to finish.
3487 * @ha: pointer to HBA
3491 * This function waits for all outstanding commands to a lun to complete. It
3492 * returns 0 if all pending commands are returned and 1 otherwise.
3494 static int qla4xxx_eh_wait_for_commands(struct scsi_qla_host *ha,
3495 struct scsi_target *stgt,
3496 struct scsi_device *sdev)
3500 struct scsi_cmnd *cmd;
3503 * Waiting for all commands for the designated target or dev
3504 * in the active array
3506 for (cnt = 0; cnt < ha->host->can_queue; cnt++) {
3507 cmd = scsi_host_find_tag(ha->host, cnt);
3508 if (cmd && stgt == scsi_target(cmd->device) &&
3509 (!sdev || sdev == cmd->device)) {
3510 if (!qla4xxx_eh_wait_on_command(ha, cmd)) {
3520 * qla4xxx_eh_abort - callback for abort task.
3521 * @cmd: Pointer to Linux's SCSI command structure
3523 * This routine is called by the Linux OS to abort the specified
3526 static int qla4xxx_eh_abort(struct scsi_cmnd *cmd)
3528 struct scsi_qla_host *ha = to_qla_host(cmd->device->host);
3529 unsigned int id = cmd->device->id;
3530 unsigned int lun = cmd->device->lun;
3531 unsigned long flags;
3532 struct srb *srb = NULL;
3536 ql4_printk(KERN_INFO, ha,
3537 "scsi%ld:%d:%d: Abort command issued cmd=%p\n",
3538 ha->host_no, id, lun, cmd);
3540 spin_lock_irqsave(&ha->hardware_lock, flags);
3541 srb = (struct srb *) CMD_SP(cmd);
3543 spin_unlock_irqrestore(&ha->hardware_lock, flags);
3546 kref_get(&srb->srb_ref);
3547 spin_unlock_irqrestore(&ha->hardware_lock, flags);
3549 if (qla4xxx_abort_task(ha, srb) != QLA_SUCCESS) {
3550 DEBUG3(printk("scsi%ld:%d:%d: Abort_task mbx failed.\n",
3551 ha->host_no, id, lun));
3554 DEBUG3(printk("scsi%ld:%d:%d: Abort_task mbx success.\n",
3555 ha->host_no, id, lun));
3559 kref_put(&srb->srb_ref, qla4xxx_srb_compl);
3561 /* Wait for command to complete */
3563 if (!qla4xxx_eh_wait_on_command(ha, cmd)) {
3564 DEBUG2(printk("scsi%ld:%d:%d: Abort handler timed out\n",
3565 ha->host_no, id, lun));
3570 ql4_printk(KERN_INFO, ha,
3571 "scsi%ld:%d:%d: Abort command - %s\n",
3572 ha->host_no, id, lun, (ret == SUCCESS) ? "succeeded" : "failed");
3578 * qla4xxx_eh_device_reset - callback for target reset.
3579 * @cmd: Pointer to Linux's SCSI command structure
3581 * This routine is called by the Linux OS to reset all luns on the
3584 static int qla4xxx_eh_device_reset(struct scsi_cmnd *cmd)
3586 struct scsi_qla_host *ha = to_qla_host(cmd->device->host);
3587 struct ddb_entry *ddb_entry = cmd->device->hostdata;
3588 int ret = FAILED, stat;
3593 ret = iscsi_block_scsi_eh(cmd);
3598 ql4_printk(KERN_INFO, ha,
3599 "scsi%ld:%d:%d:%d: DEVICE RESET ISSUED.\n", ha->host_no,
3600 cmd->device->channel, cmd->device->id, cmd->device->lun);
3602 DEBUG2(printk(KERN_INFO
3603 "scsi%ld: DEVICE_RESET cmd=%p jiffies = 0x%lx, to=%x,"
3604 "dpc_flags=%lx, status=%x allowed=%d\n", ha->host_no,
3605 cmd, jiffies, cmd->request->timeout / HZ,
3606 ha->dpc_flags, cmd->result, cmd->allowed));
3608 /* FIXME: wait for hba to go online */
3609 stat = qla4xxx_reset_lun(ha, ddb_entry, cmd->device->lun);
3610 if (stat != QLA_SUCCESS) {
3611 ql4_printk(KERN_INFO, ha, "DEVICE RESET FAILED. %d\n", stat);
3612 goto eh_dev_reset_done;
3615 if (qla4xxx_eh_wait_for_commands(ha, scsi_target(cmd->device),
3617 ql4_printk(KERN_INFO, ha,
3618 "DEVICE RESET FAILED - waiting for "
3620 goto eh_dev_reset_done;
3624 if (qla4xxx_send_marker_iocb(ha, ddb_entry, cmd->device->lun,
3625 MM_LUN_RESET) != QLA_SUCCESS)
3626 goto eh_dev_reset_done;
3628 ql4_printk(KERN_INFO, ha,
3629 "scsi(%ld:%d:%d:%d): DEVICE RESET SUCCEEDED.\n",
3630 ha->host_no, cmd->device->channel, cmd->device->id,
3641 * qla4xxx_eh_target_reset - callback for target reset.
3642 * @cmd: Pointer to Linux's SCSI command structure
3644 * This routine is called by the Linux OS to reset the target.
3646 static int qla4xxx_eh_target_reset(struct scsi_cmnd *cmd)
3648 struct scsi_qla_host *ha = to_qla_host(cmd->device->host);
3649 struct ddb_entry *ddb_entry = cmd->device->hostdata;
3655 ret = iscsi_block_scsi_eh(cmd);
3659 starget_printk(KERN_INFO, scsi_target(cmd->device),
3660 "WARM TARGET RESET ISSUED.\n");
3662 DEBUG2(printk(KERN_INFO
3663 "scsi%ld: TARGET_DEVICE_RESET cmd=%p jiffies = 0x%lx, "
3664 "to=%x,dpc_flags=%lx, status=%x allowed=%d\n",
3665 ha->host_no, cmd, jiffies, cmd->request->timeout / HZ,
3666 ha->dpc_flags, cmd->result, cmd->allowed));
3668 stat = qla4xxx_reset_target(ha, ddb_entry);
3669 if (stat != QLA_SUCCESS) {
3670 starget_printk(KERN_INFO, scsi_target(cmd->device),
3671 "WARM TARGET RESET FAILED.\n");
3675 if (qla4xxx_eh_wait_for_commands(ha, scsi_target(cmd->device),
3677 starget_printk(KERN_INFO, scsi_target(cmd->device),
3678 "WARM TARGET DEVICE RESET FAILED - "
3679 "waiting for commands.\n");
3684 if (qla4xxx_send_marker_iocb(ha, ddb_entry, cmd->device->lun,
3685 MM_TGT_WARM_RESET) != QLA_SUCCESS) {
3686 starget_printk(KERN_INFO, scsi_target(cmd->device),
3687 "WARM TARGET DEVICE RESET FAILED - "
3688 "marker iocb failed.\n");
3692 starget_printk(KERN_INFO, scsi_target(cmd->device),
3693 "WARM TARGET RESET SUCCEEDED.\n");
3698 * qla4xxx_eh_host_reset - kernel callback
3699 * @cmd: Pointer to Linux's SCSI command structure
3701 * This routine is invoked by the Linux kernel to perform fatal error
3702 * recovery on the specified adapter.
3704 static int qla4xxx_eh_host_reset(struct scsi_cmnd *cmd)
3706 int return_status = FAILED;
3707 struct scsi_qla_host *ha;
3709 ha = to_qla_host(cmd->device->host);
3711 if (ql4xdontresethba) {
3712 DEBUG2(printk("scsi%ld: %s: Don't Reset HBA\n",
3713 ha->host_no, __func__));
3717 ql4_printk(KERN_INFO, ha,
3718 "scsi(%ld:%d:%d:%d): HOST RESET ISSUED.\n", ha->host_no,
3719 cmd->device->channel, cmd->device->id, cmd->device->lun);
3721 if (qla4xxx_wait_for_hba_online(ha) != QLA_SUCCESS) {
3722 DEBUG2(printk("scsi%ld:%d: %s: Unable to reset host. Adapter "
3723 "DEAD.\n", ha->host_no, cmd->device->channel,
3729 if (!test_bit(DPC_RESET_HA, &ha->dpc_flags)) {
3731 set_bit(DPC_RESET_HA_FW_CONTEXT, &ha->dpc_flags);
3733 set_bit(DPC_RESET_HA, &ha->dpc_flags);
3736 if (qla4xxx_recover_adapter(ha) == QLA_SUCCESS)
3737 return_status = SUCCESS;
3739 ql4_printk(KERN_INFO, ha, "HOST RESET %s.\n",
3740 return_status == FAILED ? "FAILED" : "SUCCEEDED");
3742 return return_status;
3745 /* PCI AER driver recovers from all correctable errors w/o
3746 * driver intervention. For uncorrectable errors PCI AER
3747 * driver calls the following device driver's callbacks
3749 * - Fatal Errors - link_reset
3750 * - Non-Fatal Errors - driver's pci_error_detected() which
3751 * returns CAN_RECOVER, NEED_RESET or DISCONNECT.
3753 * PCI AER driver calls
3754 * CAN_RECOVER - driver's pci_mmio_enabled(), mmio_enabled
3755 * returns RECOVERED or NEED_RESET if fw_hung
3756 * NEED_RESET - driver's slot_reset()
3757 * DISCONNECT - device is dead & cannot recover
3758 * RECOVERED - driver's pci_resume()
3760 static pci_ers_result_t
3761 qla4xxx_pci_error_detected(struct pci_dev *pdev, pci_channel_state_t state)
3763 struct scsi_qla_host *ha = pci_get_drvdata(pdev);
3765 ql4_printk(KERN_WARNING, ha, "scsi%ld: %s: error detected:state %x\n",
3766 ha->host_no, __func__, state);
3768 if (!is_aer_supported(ha))
3769 return PCI_ERS_RESULT_NONE;
3772 case pci_channel_io_normal:
3773 clear_bit(AF_EEH_BUSY, &ha->flags);
3774 return PCI_ERS_RESULT_CAN_RECOVER;
3775 case pci_channel_io_frozen:
3776 set_bit(AF_EEH_BUSY, &ha->flags);
3777 qla4xxx_mailbox_premature_completion(ha);
3778 qla4xxx_free_irqs(ha);
3779 pci_disable_device(pdev);
3780 /* Return back all IOs */
3781 qla4xxx_abort_active_cmds(ha, DID_RESET << 16);
3782 return PCI_ERS_RESULT_NEED_RESET;
3783 case pci_channel_io_perm_failure:
3784 set_bit(AF_EEH_BUSY, &ha->flags);
3785 set_bit(AF_PCI_CHANNEL_IO_PERM_FAILURE, &ha->flags);
3786 qla4xxx_abort_active_cmds(ha, DID_NO_CONNECT << 16);
3787 return PCI_ERS_RESULT_DISCONNECT;
3789 return PCI_ERS_RESULT_NEED_RESET;
3793 * qla4xxx_pci_mmio_enabled() gets called if
3794 * qla4xxx_pci_error_detected() returns PCI_ERS_RESULT_CAN_RECOVER
3795 * and read/write to the device still works.
3797 static pci_ers_result_t
3798 qla4xxx_pci_mmio_enabled(struct pci_dev *pdev)
3800 struct scsi_qla_host *ha = pci_get_drvdata(pdev);
3802 if (!is_aer_supported(ha))
3803 return PCI_ERS_RESULT_NONE;
3805 return PCI_ERS_RESULT_RECOVERED;
3808 static uint32_t qla4_8xxx_error_recovery(struct scsi_qla_host *ha)
3810 uint32_t rval = QLA_ERROR;
3813 struct pci_dev *other_pdev = NULL;
3815 ql4_printk(KERN_WARNING, ha, "scsi%ld: In %s\n", ha->host_no, __func__);
3817 set_bit(DPC_RESET_ACTIVE, &ha->dpc_flags);
3819 if (test_bit(AF_ONLINE, &ha->flags)) {
3820 clear_bit(AF_ONLINE, &ha->flags);
3821 clear_bit(AF_LINK_UP, &ha->flags);
3822 iscsi_host_for_each_session(ha->host, qla4xxx_fail_session);
3823 qla4xxx_process_aen(ha, FLUSH_DDB_CHANGED_AENS);
3826 fn = PCI_FUNC(ha->pdev->devfn);
3829 ql4_printk(KERN_INFO, ha, "scsi%ld: %s: Finding PCI device at "
3830 "func %x\n", ha->host_no, __func__, fn);
3831 /* Get the pci device given the domain, bus,
3832 * slot/function number */
3834 pci_get_domain_bus_and_slot(pci_domain_nr(ha->pdev->bus),
3835 ha->pdev->bus->number, PCI_DEVFN(PCI_SLOT(ha->pdev->devfn),
3841 if (atomic_read(&other_pdev->enable_cnt)) {
3842 ql4_printk(KERN_INFO, ha, "scsi%ld: %s: Found PCI "
3843 "func in enabled state%x\n", ha->host_no,
3845 pci_dev_put(other_pdev);
3848 pci_dev_put(other_pdev);
3851 /* The first function on the card, the reset owner will
3852 * start & initialize the firmware. The other functions
3853 * on the card will reset the firmware context
3856 ql4_printk(KERN_INFO, ha, "scsi%ld: %s: devfn being reset "
3857 "0x%x is the owner\n", ha->host_no, __func__,
3860 qla4_8xxx_idc_lock(ha);
3861 qla4_8xxx_wr_32(ha, QLA82XX_CRB_DEV_STATE,
3864 qla4_8xxx_wr_32(ha, QLA82XX_CRB_DRV_IDC_VERSION,
3865 QLA82XX_IDC_VERSION);
3867 qla4_8xxx_idc_unlock(ha);
3868 clear_bit(AF_FW_RECOVERY, &ha->flags);
3869 rval = qla4xxx_initialize_adapter(ha);
3870 qla4_8xxx_idc_lock(ha);
3872 if (rval != QLA_SUCCESS) {
3873 ql4_printk(KERN_INFO, ha, "scsi%ld: %s: HW State: "
3874 "FAILED\n", ha->host_no, __func__);
3875 qla4_8xxx_clear_drv_active(ha);
3876 qla4_8xxx_wr_32(ha, QLA82XX_CRB_DEV_STATE,
3877 QLA82XX_DEV_FAILED);
3879 ql4_printk(KERN_INFO, ha, "scsi%ld: %s: HW State: "
3880 "READY\n", ha->host_no, __func__);
3881 qla4_8xxx_wr_32(ha, QLA82XX_CRB_DEV_STATE,
3883 /* Clear driver state register */
3884 qla4_8xxx_wr_32(ha, QLA82XX_CRB_DRV_STATE, 0);
3885 qla4_8xxx_set_drv_active(ha);
3886 ret = qla4xxx_request_irqs(ha);
3888 ql4_printk(KERN_WARNING, ha, "Failed to "
3889 "reserve interrupt %d already in use.\n",
3893 ha->isp_ops->enable_intrs(ha);
3897 qla4_8xxx_idc_unlock(ha);
3899 ql4_printk(KERN_INFO, ha, "scsi%ld: %s: devfn 0x%x is not "
3900 "the reset owner\n", ha->host_no, __func__,
3902 if ((qla4_8xxx_rd_32(ha, QLA82XX_CRB_DEV_STATE) ==
3903 QLA82XX_DEV_READY)) {
3904 clear_bit(AF_FW_RECOVERY, &ha->flags);
3905 rval = qla4xxx_initialize_adapter(ha);
3906 if (rval == QLA_SUCCESS) {
3907 ret = qla4xxx_request_irqs(ha);
3909 ql4_printk(KERN_WARNING, ha, "Failed to"
3910 " reserve interrupt %d already in"
3911 " use.\n", ha->pdev->irq);
3914 ha->isp_ops->enable_intrs(ha);
3918 qla4_8xxx_idc_lock(ha);
3919 qla4_8xxx_set_drv_active(ha);
3920 qla4_8xxx_idc_unlock(ha);
3923 clear_bit(DPC_RESET_ACTIVE, &ha->dpc_flags);
3927 static pci_ers_result_t
3928 qla4xxx_pci_slot_reset(struct pci_dev *pdev)
3930 pci_ers_result_t ret = PCI_ERS_RESULT_DISCONNECT;
3931 struct scsi_qla_host *ha = pci_get_drvdata(pdev);
3934 ql4_printk(KERN_WARNING, ha, "scsi%ld: %s: slot_reset\n",
3935 ha->host_no, __func__);
3937 if (!is_aer_supported(ha))
3938 return PCI_ERS_RESULT_NONE;
3940 /* Restore the saved state of PCIe device -
3941 * BAR registers, PCI Config space, PCIX, MSI,
3944 pci_restore_state(pdev);
3946 /* pci_restore_state() clears the saved_state flag of the device
3947 * save restored state which resets saved_state flag
3949 pci_save_state(pdev);
3951 /* Initialize device or resume if in suspended state */
3952 rc = pci_enable_device(pdev);
3954 ql4_printk(KERN_WARNING, ha, "scsi%ld: %s: Can't re-enable "
3955 "device after reset\n", ha->host_no, __func__);
3956 goto exit_slot_reset;
3959 ha->isp_ops->disable_intrs(ha);
3961 if (is_qla8022(ha)) {
3962 if (qla4_8xxx_error_recovery(ha) == QLA_SUCCESS) {
3963 ret = PCI_ERS_RESULT_RECOVERED;
3964 goto exit_slot_reset;
3966 goto exit_slot_reset;
3970 ql4_printk(KERN_WARNING, ha, "scsi%ld: %s: Return=%x\n"
3971 "device after reset\n", ha->host_no, __func__, ret);
3976 qla4xxx_pci_resume(struct pci_dev *pdev)
3978 struct scsi_qla_host *ha = pci_get_drvdata(pdev);
3981 ql4_printk(KERN_WARNING, ha, "scsi%ld: %s: pci_resume\n",
3982 ha->host_no, __func__);
3984 ret = qla4xxx_wait_for_hba_online(ha);
3985 if (ret != QLA_SUCCESS) {
3986 ql4_printk(KERN_ERR, ha, "scsi%ld: %s: the device failed to "
3987 "resume I/O from slot/link_reset\n", ha->host_no,
3991 pci_cleanup_aer_uncorrect_error_status(pdev);
3992 clear_bit(AF_EEH_BUSY, &ha->flags);
3995 static struct pci_error_handlers qla4xxx_err_handler = {
3996 .error_detected = qla4xxx_pci_error_detected,
3997 .mmio_enabled = qla4xxx_pci_mmio_enabled,
3998 .slot_reset = qla4xxx_pci_slot_reset,
3999 .resume = qla4xxx_pci_resume,
4002 static struct pci_device_id qla4xxx_pci_tbl[] = {
4004 .vendor = PCI_VENDOR_ID_QLOGIC,
4005 .device = PCI_DEVICE_ID_QLOGIC_ISP4010,
4006 .subvendor = PCI_ANY_ID,
4007 .subdevice = PCI_ANY_ID,
4010 .vendor = PCI_VENDOR_ID_QLOGIC,
4011 .device = PCI_DEVICE_ID_QLOGIC_ISP4022,
4012 .subvendor = PCI_ANY_ID,
4013 .subdevice = PCI_ANY_ID,
4016 .vendor = PCI_VENDOR_ID_QLOGIC,
4017 .device = PCI_DEVICE_ID_QLOGIC_ISP4032,
4018 .subvendor = PCI_ANY_ID,
4019 .subdevice = PCI_ANY_ID,
4022 .vendor = PCI_VENDOR_ID_QLOGIC,
4023 .device = PCI_DEVICE_ID_QLOGIC_ISP8022,
4024 .subvendor = PCI_ANY_ID,
4025 .subdevice = PCI_ANY_ID,
4029 MODULE_DEVICE_TABLE(pci, qla4xxx_pci_tbl);
4031 static struct pci_driver qla4xxx_pci_driver = {
4032 .name = DRIVER_NAME,
4033 .id_table = qla4xxx_pci_tbl,
4034 .probe = qla4xxx_probe_adapter,
4035 .remove = qla4xxx_remove_adapter,
4036 .err_handler = &qla4xxx_err_handler,
4039 static int __init qla4xxx_module_init(void)
4043 /* Allocate cache for SRBs. */
4044 srb_cachep = kmem_cache_create("qla4xxx_srbs", sizeof(struct srb), 0,
4045 SLAB_HWCACHE_ALIGN, NULL);
4046 if (srb_cachep == NULL) {
4048 "%s: Unable to allocate SRB cache..."
4049 "Failing load!\n", DRIVER_NAME);
4054 /* Derive version string. */
4055 strcpy(qla4xxx_version_str, QLA4XXX_DRIVER_VERSION);
4056 if (ql4xextended_error_logging)
4057 strcat(qla4xxx_version_str, "-debug");
4059 qla4xxx_scsi_transport =
4060 iscsi_register_transport(&qla4xxx_iscsi_transport);
4061 if (!qla4xxx_scsi_transport){
4063 goto release_srb_cache;
4066 ret = pci_register_driver(&qla4xxx_pci_driver);
4068 goto unregister_transport;
4070 printk(KERN_INFO "QLogic iSCSI HBA Driver\n");
4073 unregister_transport:
4074 iscsi_unregister_transport(&qla4xxx_iscsi_transport);
4076 kmem_cache_destroy(srb_cachep);
4081 static void __exit qla4xxx_module_exit(void)
4083 pci_unregister_driver(&qla4xxx_pci_driver);
4084 iscsi_unregister_transport(&qla4xxx_iscsi_transport);
4085 kmem_cache_destroy(srb_cachep);
4088 module_init(qla4xxx_module_init);
4089 module_exit(qla4xxx_module_exit);
4091 MODULE_AUTHOR("QLogic Corporation");
4092 MODULE_DESCRIPTION("QLogic iSCSI HBA Driver");
4093 MODULE_LICENSE("GPL");
4094 MODULE_VERSION(QLA4XXX_DRIVER_VERSION);