2 * QLogic Fibre Channel HBA Driver
3 * Copyright (c) 2003-2011 QLogic Corporation
5 * See LICENSE.qla2xxx for copyright and licensing details.
9 #include <linux/moduleparam.h>
10 #include <linux/vmalloc.h>
11 #include <linux/delay.h>
12 #include <linux/kthread.h>
13 #include <linux/mutex.h>
14 #include <linux/kobject.h>
15 #include <linux/slab.h>
17 #include <scsi/scsi_tcq.h>
18 #include <scsi/scsicam.h>
19 #include <scsi/scsi_transport.h>
20 #include <scsi/scsi_transport_fc.h>
25 char qla2x00_version_str[40];
27 static int apidev_major;
30 * SRB allocation cache
32 static struct kmem_cache *srb_cachep;
35 * CT6 CTX allocation cache
37 static struct kmem_cache *ctx_cachep;
39 * error level for logging
41 int ql_errlev = ql_log_all;
43 int ql2xlogintimeout = 20;
44 module_param(ql2xlogintimeout, int, S_IRUGO);
45 MODULE_PARM_DESC(ql2xlogintimeout,
46 "Login timeout value in seconds.");
48 int qlport_down_retry;
49 module_param(qlport_down_retry, int, S_IRUGO);
50 MODULE_PARM_DESC(qlport_down_retry,
51 "Maximum number of command retries to a port that returns "
52 "a PORT-DOWN status.");
54 int ql2xplogiabsentdevice;
55 module_param(ql2xplogiabsentdevice, int, S_IRUGO|S_IWUSR);
56 MODULE_PARM_DESC(ql2xplogiabsentdevice,
57 "Option to enable PLOGI to devices that are not present after "
58 "a Fabric scan. This is needed for several broken switches. "
59 "Default is 0 - no PLOGI. 1 - perfom PLOGI.");
61 int ql2xloginretrycount = 0;
62 module_param(ql2xloginretrycount, int, S_IRUGO);
63 MODULE_PARM_DESC(ql2xloginretrycount,
64 "Specify an alternate value for the NVRAM login retry count.");
66 int ql2xallocfwdump = 1;
67 module_param(ql2xallocfwdump, int, S_IRUGO);
68 MODULE_PARM_DESC(ql2xallocfwdump,
69 "Option to enable allocation of memory for a firmware dump "
70 "during HBA initialization. Memory allocation requirements "
71 "vary by ISP type. Default is 1 - allocate memory.");
73 int ql2xextended_error_logging;
74 module_param(ql2xextended_error_logging, int, S_IRUGO|S_IWUSR);
75 MODULE_PARM_DESC(ql2xextended_error_logging,
76 "Option to enable extended error logging,\n"
77 "\t\tDefault is 0 - no logging. 0x40000000 - Module Init & Probe.\n"
78 "\t\t0x20000000 - Mailbox Cmnds. 0x10000000 - Device Discovery.\n"
79 "\t\t0x08000000 - IO tracing. 0x04000000 - DPC Thread.\n"
80 "\t\t0x02000000 - Async events. 0x01000000 - Timer routines.\n"
81 "\t\t0x00800000 - User space. 0x00400000 - Task Management.\n"
82 "\t\t0x00200000 - AER/EEH. 0x00100000 - Multi Q.\n"
83 "\t\t0x00080000 - P3P Specific. 0x00040000 - Virtual Port.\n"
84 "\t\t0x00020000 - Buffer Dump. 0x00010000 - Misc.\n"
85 "\t\t0x7fffffff - For enabling all logs, can be too many logs.\n"
86 "\t\t0x1e400000 - Preferred value for capturing essential "
87 "debug information (equivalent to old "
88 "ql2xextended_error_logging=1).\n"
89 "\t\tDo LOGICAL OR of the value to enable more than one level");
91 int ql2xshiftctondsd = 6;
92 module_param(ql2xshiftctondsd, int, S_IRUGO);
93 MODULE_PARM_DESC(ql2xshiftctondsd,
94 "Set to control shifting of command type processing "
95 "based on total number of SG elements.");
97 static void qla2x00_free_device(scsi_qla_host_t *);
100 module_param(ql2xfdmienable, int, S_IRUGO);
101 MODULE_PARM_DESC(ql2xfdmienable,
102 "Enables FDMI registrations. "
103 "0 - no FDMI. Default is 1 - perform FDMI.");
105 #define MAX_Q_DEPTH 32
106 static int ql2xmaxqdepth = MAX_Q_DEPTH;
107 module_param(ql2xmaxqdepth, int, S_IRUGO|S_IWUSR);
108 MODULE_PARM_DESC(ql2xmaxqdepth,
109 "Maximum queue depth to report for target devices.");
111 /* Do not change the value of this after module load */
112 int ql2xenabledif = 0;
113 module_param(ql2xenabledif, int, S_IRUGO|S_IWUSR);
114 MODULE_PARM_DESC(ql2xenabledif,
115 " Enable T10-CRC-DIF "
116 " Default is 0 - No DIF Support. 1 - Enable it"
117 ", 2 - Enable DIF for all types, except Type 0.");
119 int ql2xenablehba_err_chk = 2;
120 module_param(ql2xenablehba_err_chk, int, S_IRUGO|S_IWUSR);
121 MODULE_PARM_DESC(ql2xenablehba_err_chk,
122 " Enable T10-CRC-DIF Error isolation by HBA:\n"
124 " 0 -- Error isolation disabled\n"
125 " 1 -- Error isolation enabled only for DIX Type 0\n"
126 " 2 -- Error isolation enabled for all Types\n");
128 int ql2xiidmaenable=1;
129 module_param(ql2xiidmaenable, int, S_IRUGO);
130 MODULE_PARM_DESC(ql2xiidmaenable,
131 "Enables iIDMA settings "
132 "Default is 1 - perform iIDMA. 0 - no iIDMA.");
134 int ql2xmaxqueues = 1;
135 module_param(ql2xmaxqueues, int, S_IRUGO);
136 MODULE_PARM_DESC(ql2xmaxqueues,
137 "Enables MQ settings "
138 "Default is 1 for single queue. Set it to number "
139 "of queues in MQ mode.");
141 int ql2xmultique_tag;
142 module_param(ql2xmultique_tag, int, S_IRUGO);
143 MODULE_PARM_DESC(ql2xmultique_tag,
144 "Enables CPU affinity settings for the driver "
145 "Default is 0 for no affinity of request and response IO. "
146 "Set it to 1 to turn on the cpu affinity.");
149 module_param(ql2xfwloadbin, int, S_IRUGO|S_IWUSR);
150 MODULE_PARM_DESC(ql2xfwloadbin,
151 "Option to specify location from which to load ISP firmware:.\n"
152 " 2 -- load firmware via the request_firmware() (hotplug).\n"
154 " 1 -- load firmware from flash.\n"
155 " 0 -- use default semantics.\n");
158 module_param(ql2xetsenable, int, S_IRUGO);
159 MODULE_PARM_DESC(ql2xetsenable,
160 "Enables firmware ETS burst."
161 "Default is 0 - skip ETS enablement.");
164 module_param(ql2xdbwr, int, S_IRUGO|S_IWUSR);
165 MODULE_PARM_DESC(ql2xdbwr,
166 "Option to specify scheme for request queue posting.\n"
167 " 0 -- Regular doorbell.\n"
168 " 1 -- CAMRAM doorbell (faster).\n");
170 int ql2xtargetreset = 1;
171 module_param(ql2xtargetreset, int, S_IRUGO);
172 MODULE_PARM_DESC(ql2xtargetreset,
173 "Enable target reset."
174 "Default is 1 - use hw defaults.");
177 module_param(ql2xgffidenable, int, S_IRUGO);
178 MODULE_PARM_DESC(ql2xgffidenable,
179 "Enables GFF_ID checks of port type. "
180 "Default is 0 - Do not use GFF_ID information.");
182 int ql2xasynctmfenable;
183 module_param(ql2xasynctmfenable, int, S_IRUGO);
184 MODULE_PARM_DESC(ql2xasynctmfenable,
185 "Enables issue of TM IOCBs asynchronously via IOCB mechanism"
186 "Default is 0 - Issue TM IOCBs via mailbox mechanism.");
188 int ql2xdontresethba;
189 module_param(ql2xdontresethba, int, S_IRUGO|S_IWUSR);
190 MODULE_PARM_DESC(ql2xdontresethba,
191 "Option to specify reset behaviour.\n"
192 " 0 (Default) -- Reset on failure.\n"
193 " 1 -- Do not reset on failure.\n");
195 uint ql2xmaxlun = MAX_LUNS;
196 module_param(ql2xmaxlun, uint, S_IRUGO);
197 MODULE_PARM_DESC(ql2xmaxlun,
198 "Defines the maximum LU number to register with the SCSI "
199 "midlayer. Default is 65535.");
201 int ql2xmdcapmask = 0x1F;
202 module_param(ql2xmdcapmask, int, S_IRUGO);
203 MODULE_PARM_DESC(ql2xmdcapmask,
204 "Set the Minidump driver capture mask level. "
205 "Default is 0x1F - Can be set to 0x3, 0x7, 0xF, 0x1F, 0x7F.");
207 int ql2xmdenable = 1;
208 module_param(ql2xmdenable, int, S_IRUGO);
209 MODULE_PARM_DESC(ql2xmdenable,
210 "Enable/disable MiniDump. "
211 "0 - MiniDump disabled. "
212 "1 (Default) - MiniDump enabled.");
215 * SCSI host template entry points
217 static int qla2xxx_slave_configure(struct scsi_device * device);
218 static int qla2xxx_slave_alloc(struct scsi_device *);
219 static int qla2xxx_scan_finished(struct Scsi_Host *, unsigned long time);
220 static void qla2xxx_scan_start(struct Scsi_Host *);
221 static void qla2xxx_slave_destroy(struct scsi_device *);
222 static int qla2xxx_queuecommand(struct Scsi_Host *h, struct scsi_cmnd *cmd);
223 static int qla2xxx_eh_abort(struct scsi_cmnd *);
224 static int qla2xxx_eh_device_reset(struct scsi_cmnd *);
225 static int qla2xxx_eh_target_reset(struct scsi_cmnd *);
226 static int qla2xxx_eh_bus_reset(struct scsi_cmnd *);
227 static int qla2xxx_eh_host_reset(struct scsi_cmnd *);
229 static int qla2x00_change_queue_depth(struct scsi_device *, int, int);
230 static int qla2x00_change_queue_type(struct scsi_device *, int);
232 struct scsi_host_template qla2xxx_driver_template = {
233 .module = THIS_MODULE,
234 .name = QLA2XXX_DRIVER_NAME,
235 .queuecommand = qla2xxx_queuecommand,
237 .eh_abort_handler = qla2xxx_eh_abort,
238 .eh_device_reset_handler = qla2xxx_eh_device_reset,
239 .eh_target_reset_handler = qla2xxx_eh_target_reset,
240 .eh_bus_reset_handler = qla2xxx_eh_bus_reset,
241 .eh_host_reset_handler = qla2xxx_eh_host_reset,
243 .slave_configure = qla2xxx_slave_configure,
245 .slave_alloc = qla2xxx_slave_alloc,
246 .slave_destroy = qla2xxx_slave_destroy,
247 .scan_finished = qla2xxx_scan_finished,
248 .scan_start = qla2xxx_scan_start,
249 .change_queue_depth = qla2x00_change_queue_depth,
250 .change_queue_type = qla2x00_change_queue_type,
253 .use_clustering = ENABLE_CLUSTERING,
254 .sg_tablesize = SG_ALL,
256 .max_sectors = 0xFFFF,
257 .shost_attrs = qla2x00_host_attrs,
260 static struct scsi_transport_template *qla2xxx_transport_template = NULL;
261 struct scsi_transport_template *qla2xxx_transport_vport_template = NULL;
263 /* TODO Convert to inlines
269 qla2x00_start_timer(scsi_qla_host_t *vha, void *func, unsigned long interval)
271 init_timer(&vha->timer);
272 vha->timer.expires = jiffies + interval * HZ;
273 vha->timer.data = (unsigned long)vha;
274 vha->timer.function = (void (*)(unsigned long))func;
275 add_timer(&vha->timer);
276 vha->timer_active = 1;
280 qla2x00_restart_timer(scsi_qla_host_t *vha, unsigned long interval)
282 /* Currently used for 82XX only. */
283 if (vha->device_flags & DFLG_DEV_FAILED) {
284 ql_dbg(ql_dbg_timer, vha, 0x600d,
285 "Device in a failed state, returning.\n");
289 mod_timer(&vha->timer, jiffies + interval * HZ);
292 static __inline__ void
293 qla2x00_stop_timer(scsi_qla_host_t *vha)
295 del_timer_sync(&vha->timer);
296 vha->timer_active = 0;
299 static int qla2x00_do_dpc(void *data);
301 static void qla2x00_rst_aen(scsi_qla_host_t *);
303 static int qla2x00_mem_alloc(struct qla_hw_data *, uint16_t, uint16_t,
304 struct req_que **, struct rsp_que **);
305 static void qla2x00_free_fw_dump(struct qla_hw_data *);
306 static void qla2x00_mem_free(struct qla_hw_data *);
307 static void qla2x00_sp_free_dma(srb_t *);
309 /* -------------------------------------------------------------------------- */
310 static int qla2x00_alloc_queues(struct qla_hw_data *ha)
312 scsi_qla_host_t *vha = pci_get_drvdata(ha->pdev);
313 ha->req_q_map = kzalloc(sizeof(struct req_que *) * ha->max_req_queues,
315 if (!ha->req_q_map) {
316 ql_log(ql_log_fatal, vha, 0x003b,
317 "Unable to allocate memory for request queue ptrs.\n");
321 ha->rsp_q_map = kzalloc(sizeof(struct rsp_que *) * ha->max_rsp_queues,
323 if (!ha->rsp_q_map) {
324 ql_log(ql_log_fatal, vha, 0x003c,
325 "Unable to allocate memory for response queue ptrs.\n");
328 set_bit(0, ha->rsp_qid_map);
329 set_bit(0, ha->req_qid_map);
333 kfree(ha->req_q_map);
334 ha->req_q_map = NULL;
339 static void qla2x00_free_req_que(struct qla_hw_data *ha, struct req_que *req)
341 if (req && req->ring)
342 dma_free_coherent(&ha->pdev->dev,
343 (req->length + 1) * sizeof(request_t),
344 req->ring, req->dma);
350 static void qla2x00_free_rsp_que(struct qla_hw_data *ha, struct rsp_que *rsp)
352 if (rsp && rsp->ring)
353 dma_free_coherent(&ha->pdev->dev,
354 (rsp->length + 1) * sizeof(response_t),
355 rsp->ring, rsp->dma);
361 static void qla2x00_free_queues(struct qla_hw_data *ha)
367 for (cnt = 0; cnt < ha->max_req_queues; cnt++) {
368 req = ha->req_q_map[cnt];
369 qla2x00_free_req_que(ha, req);
371 kfree(ha->req_q_map);
372 ha->req_q_map = NULL;
374 for (cnt = 0; cnt < ha->max_rsp_queues; cnt++) {
375 rsp = ha->rsp_q_map[cnt];
376 qla2x00_free_rsp_que(ha, rsp);
378 kfree(ha->rsp_q_map);
379 ha->rsp_q_map = NULL;
382 static int qla25xx_setup_mode(struct scsi_qla_host *vha)
384 uint16_t options = 0;
386 struct qla_hw_data *ha = vha->hw;
388 if (!(ha->fw_attributes & BIT_6)) {
389 ql_log(ql_log_warn, vha, 0x00d8,
390 "Firmware is not multi-queue capable.\n");
393 if (ql2xmultique_tag) {
394 /* create a request queue for IO */
396 req = qla25xx_create_req_que(ha, options, 0, 0, -1,
397 QLA_DEFAULT_QUE_QOS);
399 ql_log(ql_log_warn, vha, 0x00e0,
400 "Failed to create request queue.\n");
403 ha->wq = alloc_workqueue("qla2xxx_wq", WQ_MEM_RECLAIM, 1);
404 vha->req = ha->req_q_map[req];
406 for (ques = 1; ques < ha->max_rsp_queues; ques++) {
407 ret = qla25xx_create_rsp_que(ha, options, 0, 0, req);
409 ql_log(ql_log_warn, vha, 0x00e8,
410 "Failed to create response queue.\n");
414 ha->flags.cpu_affinity_enabled = 1;
415 ql_dbg(ql_dbg_multiq, vha, 0xc007,
416 "CPU affinity mode enalbed, "
417 "no. of response queues:%d no. of request queues:%d.\n",
418 ha->max_rsp_queues, ha->max_req_queues);
419 ql_dbg(ql_dbg_init, vha, 0x00e9,
420 "CPU affinity mode enalbed, "
421 "no. of response queues:%d no. of request queues:%d.\n",
422 ha->max_rsp_queues, ha->max_req_queues);
426 qla25xx_delete_queues(vha);
427 destroy_workqueue(ha->wq);
429 vha->req = ha->req_q_map[0];
432 kfree(ha->req_q_map);
433 kfree(ha->rsp_q_map);
434 ha->max_req_queues = ha->max_rsp_queues = 1;
439 qla2x00_pci_info_str(struct scsi_qla_host *vha, char *str)
441 struct qla_hw_data *ha = vha->hw;
442 static char *pci_bus_modes[] = {
443 "33", "66", "100", "133",
448 pci_bus = (ha->pci_attr & (BIT_9 | BIT_10)) >> 9;
451 strcat(str, pci_bus_modes[pci_bus]);
453 pci_bus = (ha->pci_attr & BIT_8) >> 8;
455 strcat(str, pci_bus_modes[pci_bus]);
457 strcat(str, " MHz)");
463 qla24xx_pci_info_str(struct scsi_qla_host *vha, char *str)
465 static char *pci_bus_modes[] = { "33", "66", "100", "133", };
466 struct qla_hw_data *ha = vha->hw;
470 pcie_reg = pci_find_capability(ha->pdev, PCI_CAP_ID_EXP);
473 uint16_t pcie_lstat, lspeed, lwidth;
476 pci_read_config_word(ha->pdev, pcie_reg, &pcie_lstat);
477 lspeed = pcie_lstat & (BIT_0 | BIT_1 | BIT_2 | BIT_3);
478 lwidth = (pcie_lstat &
479 (BIT_4 | BIT_5 | BIT_6 | BIT_7 | BIT_8 | BIT_9)) >> 4;
481 strcpy(str, "PCIe (");
483 strcat(str, "2.5GT/s ");
484 else if (lspeed == 2)
485 strcat(str, "5.0GT/s ");
487 strcat(str, "<unknown> ");
488 snprintf(lwstr, sizeof(lwstr), "x%d)", lwidth);
495 pci_bus = (ha->pci_attr & CSRX_PCIX_BUS_MODE_MASK) >> 8;
496 if (pci_bus == 0 || pci_bus == 8) {
498 strcat(str, pci_bus_modes[pci_bus >> 3]);
502 strcat(str, "Mode 2");
504 strcat(str, "Mode 1");
506 strcat(str, pci_bus_modes[pci_bus & ~BIT_2]);
508 strcat(str, " MHz)");
514 qla2x00_fw_version_str(struct scsi_qla_host *vha, char *str)
517 struct qla_hw_data *ha = vha->hw;
519 sprintf(str, "%d.%02d.%02d ", ha->fw_major_version,
520 ha->fw_minor_version,
521 ha->fw_subminor_version);
523 if (ha->fw_attributes & BIT_9) {
528 switch (ha->fw_attributes & 0xFF) {
542 sprintf(un_str, "(%x)", ha->fw_attributes);
546 if (ha->fw_attributes & 0x100)
553 qla24xx_fw_version_str(struct scsi_qla_host *vha, char *str)
555 struct qla_hw_data *ha = vha->hw;
557 sprintf(str, "%d.%02d.%02d (%x)", ha->fw_major_version,
558 ha->fw_minor_version, ha->fw_subminor_version, ha->fw_attributes);
562 static inline srb_t *
563 qla2x00_get_new_sp(scsi_qla_host_t *vha, fc_port_t *fcport,
564 struct scsi_cmnd *cmd)
567 struct qla_hw_data *ha = vha->hw;
569 sp = mempool_alloc(ha->srb_mempool, GFP_ATOMIC);
571 ql_log(ql_log_warn, vha, 0x3006,
572 "Memory allocation failed for sp.\n");
576 atomic_set(&sp->ref_count, 1);
580 CMD_SP(cmd) = (void *)sp;
587 qla2xxx_queuecommand(struct Scsi_Host *host, struct scsi_cmnd *cmd)
589 scsi_qla_host_t *vha = shost_priv(host);
590 fc_port_t *fcport = (struct fc_port *) cmd->device->hostdata;
591 struct fc_rport *rport = starget_to_rport(scsi_target(cmd->device));
592 struct qla_hw_data *ha = vha->hw;
593 struct scsi_qla_host *base_vha = pci_get_drvdata(ha->pdev);
597 if (ha->flags.eeh_busy) {
598 if (ha->flags.pci_channel_io_perm_failure) {
599 ql_dbg(ql_dbg_io, vha, 0x3001,
600 "PCI Channel IO permanent failure, exiting "
602 cmd->result = DID_NO_CONNECT << 16;
604 ql_dbg(ql_dbg_io, vha, 0x3002,
605 "EEH_Busy, Requeuing the cmd=%p.\n", cmd);
606 cmd->result = DID_REQUEUE << 16;
608 goto qc24_fail_command;
611 rval = fc_remote_port_chkready(rport);
614 ql_dbg(ql_dbg_io, vha, 0x3003,
615 "fc_remote_port_chkready failed for cmd=%p, rval=0x%x.\n",
617 goto qc24_fail_command;
620 if (!vha->flags.difdix_supported &&
621 scsi_get_prot_op(cmd) != SCSI_PROT_NORMAL) {
622 ql_dbg(ql_dbg_io, vha, 0x3004,
623 "DIF Cap not reg, fail DIF capable cmd's:%p.\n",
625 cmd->result = DID_NO_CONNECT << 16;
626 goto qc24_fail_command;
628 if (atomic_read(&fcport->state) != FCS_ONLINE) {
629 if (atomic_read(&fcport->state) == FCS_DEVICE_DEAD ||
630 atomic_read(&base_vha->loop_state) == LOOP_DEAD) {
631 ql_dbg(ql_dbg_io, vha, 0x3005,
632 "Returning DNC, fcport_state=%d loop_state=%d.\n",
633 atomic_read(&fcport->state),
634 atomic_read(&base_vha->loop_state));
635 cmd->result = DID_NO_CONNECT << 16;
636 goto qc24_fail_command;
638 goto qc24_target_busy;
641 sp = qla2x00_get_new_sp(base_vha, fcport, cmd);
645 rval = ha->isp_ops->start_scsi(sp);
646 if (rval != QLA_SUCCESS) {
647 ql_dbg(ql_dbg_io, vha, 0x3013,
648 "Start scsi failed rval=%d for cmd=%p.\n", rval, cmd);
649 goto qc24_host_busy_free_sp;
654 qc24_host_busy_free_sp:
655 qla2x00_sp_free_dma(sp);
656 mempool_free(sp, ha->srb_mempool);
659 return SCSI_MLQUEUE_HOST_BUSY;
662 return SCSI_MLQUEUE_TARGET_BUSY;
671 * qla2x00_eh_wait_on_command
672 * Waits for the command to be returned by the Firmware for some
676 * cmd = Scsi Command to wait on.
683 qla2x00_eh_wait_on_command(struct scsi_cmnd *cmd)
685 #define ABORT_POLLING_PERIOD 1000
686 #define ABORT_WAIT_ITER ((10 * 1000) / (ABORT_POLLING_PERIOD))
687 unsigned long wait_iter = ABORT_WAIT_ITER;
688 scsi_qla_host_t *vha = shost_priv(cmd->device->host);
689 struct qla_hw_data *ha = vha->hw;
690 int ret = QLA_SUCCESS;
692 if (unlikely(pci_channel_offline(ha->pdev)) || ha->flags.eeh_busy) {
693 ql_dbg(ql_dbg_taskm, vha, 0x8005,
694 "Return:eh_wait.\n");
698 while (CMD_SP(cmd) && wait_iter--) {
699 msleep(ABORT_POLLING_PERIOD);
702 ret = QLA_FUNCTION_FAILED;
708 * qla2x00_wait_for_hba_online
709 * Wait till the HBA is online after going through
710 * <= MAX_RETRIES_OF_ISP_ABORT or
711 * finally HBA is disabled ie marked offline
714 * ha - pointer to host adapter structure
717 * Does context switching-Release SPIN_LOCK
718 * (if any) before calling this routine.
721 * Success (Adapter is online) : 0
722 * Failed (Adapter is offline/disabled) : 1
725 qla2x00_wait_for_hba_online(scsi_qla_host_t *vha)
728 unsigned long wait_online;
729 struct qla_hw_data *ha = vha->hw;
730 scsi_qla_host_t *base_vha = pci_get_drvdata(ha->pdev);
732 wait_online = jiffies + (MAX_LOOP_TIMEOUT * HZ);
733 while (((test_bit(ISP_ABORT_NEEDED, &base_vha->dpc_flags)) ||
734 test_bit(ABORT_ISP_ACTIVE, &base_vha->dpc_flags) ||
735 test_bit(ISP_ABORT_RETRY, &base_vha->dpc_flags) ||
736 ha->dpc_active) && time_before(jiffies, wait_online)) {
740 if (base_vha->flags.online)
741 return_status = QLA_SUCCESS;
743 return_status = QLA_FUNCTION_FAILED;
745 return (return_status);
749 * qla2x00_wait_for_reset_ready
750 * Wait till the HBA is online after going through
751 * <= MAX_RETRIES_OF_ISP_ABORT or
752 * finally HBA is disabled ie marked offline or flash
753 * operations are in progress.
756 * ha - pointer to host adapter structure
759 * Does context switching-Release SPIN_LOCK
760 * (if any) before calling this routine.
763 * Success (Adapter is online/no flash ops) : 0
764 * Failed (Adapter is offline/disabled/flash ops in progress) : 1
767 qla2x00_wait_for_reset_ready(scsi_qla_host_t *vha)
770 unsigned long wait_online;
771 struct qla_hw_data *ha = vha->hw;
772 scsi_qla_host_t *base_vha = pci_get_drvdata(ha->pdev);
774 wait_online = jiffies + (MAX_LOOP_TIMEOUT * HZ);
775 while (((test_bit(ISP_ABORT_NEEDED, &base_vha->dpc_flags)) ||
776 test_bit(ABORT_ISP_ACTIVE, &base_vha->dpc_flags) ||
777 test_bit(ISP_ABORT_RETRY, &base_vha->dpc_flags) ||
778 ha->optrom_state != QLA_SWAITING ||
779 ha->dpc_active) && time_before(jiffies, wait_online))
782 if (base_vha->flags.online && ha->optrom_state == QLA_SWAITING)
783 return_status = QLA_SUCCESS;
785 return_status = QLA_FUNCTION_FAILED;
787 ql_dbg(ql_dbg_taskm, vha, 0x8019,
788 "%s return status=%d.\n", __func__, return_status);
790 return return_status;
794 qla2x00_wait_for_chip_reset(scsi_qla_host_t *vha)
797 unsigned long wait_reset;
798 struct qla_hw_data *ha = vha->hw;
799 scsi_qla_host_t *base_vha = pci_get_drvdata(ha->pdev);
801 wait_reset = jiffies + (MAX_LOOP_TIMEOUT * HZ);
802 while (((test_bit(ISP_ABORT_NEEDED, &base_vha->dpc_flags)) ||
803 test_bit(ABORT_ISP_ACTIVE, &base_vha->dpc_flags) ||
804 test_bit(ISP_ABORT_RETRY, &base_vha->dpc_flags) ||
805 ha->dpc_active) && time_before(jiffies, wait_reset)) {
809 if (!test_bit(ISP_ABORT_NEEDED, &base_vha->dpc_flags) &&
810 ha->flags.chip_reset_done)
813 if (ha->flags.chip_reset_done)
814 return_status = QLA_SUCCESS;
816 return_status = QLA_FUNCTION_FAILED;
818 return return_status;
822 sp_get(struct srb *sp)
824 atomic_inc(&sp->ref_count);
827 /**************************************************************************
831 * The abort function will abort the specified command.
834 * cmd = Linux SCSI command packet to be aborted.
837 * Either SUCCESS or FAILED.
840 * Only return FAILED if command not returned by firmware.
841 **************************************************************************/
843 qla2xxx_eh_abort(struct scsi_cmnd *cmd)
845 scsi_qla_host_t *vha = shost_priv(cmd->device->host);
848 unsigned int id, lun;
851 struct qla_hw_data *ha = vha->hw;
856 ret = fc_block_scsi_eh(cmd);
861 id = cmd->device->id;
862 lun = cmd->device->lun;
864 spin_lock_irqsave(&ha->hardware_lock, flags);
865 sp = (srb_t *) CMD_SP(cmd);
867 spin_unlock_irqrestore(&ha->hardware_lock, flags);
871 ql_dbg(ql_dbg_taskm, vha, 0x8002,
872 "Aborting from RISC nexus=%ld:%d:%d sp=%p cmd=%p\n",
873 vha->host_no, id, lun, sp, cmd);
875 /* Get a reference to the sp and drop the lock.*/
878 spin_unlock_irqrestore(&ha->hardware_lock, flags);
879 if (ha->isp_ops->abort_command(sp)) {
881 ql_dbg(ql_dbg_taskm, vha, 0x8003,
882 "Abort command mbx failed cmd=%p.\n", cmd);
884 ql_dbg(ql_dbg_taskm, vha, 0x8004,
885 "Abort command mbx success cmd=%p.\n", cmd);
889 spin_lock_irqsave(&ha->hardware_lock, flags);
890 qla2x00_sp_compl(ha, sp);
891 spin_unlock_irqrestore(&ha->hardware_lock, flags);
893 /* Did the command return during mailbox execution? */
894 if (ret == FAILED && !CMD_SP(cmd))
897 /* Wait for the command to be returned. */
899 if (qla2x00_eh_wait_on_command(cmd) != QLA_SUCCESS) {
900 ql_log(ql_log_warn, vha, 0x8006,
901 "Abort handler timed out cmd=%p.\n", cmd);
906 ql_log(ql_log_info, vha, 0x801c,
907 "Abort command issued nexus=%ld:%d:%d -- %d %x.\n",
908 vha->host_no, id, lun, wait, ret);
914 qla2x00_eh_wait_for_pending_commands(scsi_qla_host_t *vha, unsigned int t,
915 unsigned int l, enum nexus_wait_type type)
917 int cnt, match, status;
919 struct qla_hw_data *ha = vha->hw;
923 status = QLA_SUCCESS;
925 spin_lock_irqsave(&ha->hardware_lock, flags);
927 for (cnt = 1; status == QLA_SUCCESS &&
928 cnt < MAX_OUTSTANDING_COMMANDS; cnt++) {
929 sp = req->outstanding_cmds[cnt];
932 if ((sp->ctx) && !IS_PROT_IO(sp))
934 if (vha->vp_idx != sp->fcport->vha->vp_idx)
942 match = sp->cmd->device->id == t;
945 match = (sp->cmd->device->id == t &&
946 sp->cmd->device->lun == l);
952 spin_unlock_irqrestore(&ha->hardware_lock, flags);
953 status = qla2x00_eh_wait_on_command(sp->cmd);
954 spin_lock_irqsave(&ha->hardware_lock, flags);
956 spin_unlock_irqrestore(&ha->hardware_lock, flags);
961 static char *reset_errors[] = {
964 "Task management failed",
965 "Waiting for command completions",
969 __qla2xxx_eh_generic_reset(char *name, enum nexus_wait_type type,
970 struct scsi_cmnd *cmd, int (*do_reset)(struct fc_port *, unsigned int, int))
972 scsi_qla_host_t *vha = shost_priv(cmd->device->host);
973 fc_port_t *fcport = (struct fc_port *) cmd->device->hostdata;
980 err = fc_block_scsi_eh(cmd);
984 ql_log(ql_log_info, vha, 0x8009,
985 "%s RESET ISSUED nexus=%ld:%d:%d cmd=%p.\n", name, vha->host_no,
986 cmd->device->id, cmd->device->lun, cmd);
989 if (qla2x00_wait_for_hba_online(vha) != QLA_SUCCESS) {
990 ql_log(ql_log_warn, vha, 0x800a,
991 "Wait for hba online failed for cmd=%p.\n", cmd);
992 goto eh_reset_failed;
995 if (do_reset(fcport, cmd->device->lun, cmd->request->cpu + 1)
997 ql_log(ql_log_warn, vha, 0x800c,
998 "do_reset failed for cmd=%p.\n", cmd);
999 goto eh_reset_failed;
1002 if (qla2x00_eh_wait_for_pending_commands(vha, cmd->device->id,
1003 cmd->device->lun, type) != QLA_SUCCESS) {
1004 ql_log(ql_log_warn, vha, 0x800d,
1005 "wait for peding cmds failed for cmd=%p.\n", cmd);
1006 goto eh_reset_failed;
1009 ql_log(ql_log_info, vha, 0x800e,
1010 "%s RESET SUCCEEDED nexus:%ld:%d:%d cmd=%p.\n", name,
1011 vha->host_no, cmd->device->id, cmd->device->lun, cmd);
1016 ql_log(ql_log_info, vha, 0x800f,
1017 "%s RESET FAILED: %s nexus=%ld:%d:%d cmd=%p.\n", name,
1018 reset_errors[err], vha->host_no, cmd->device->id, cmd->device->lun,
1024 qla2xxx_eh_device_reset(struct scsi_cmnd *cmd)
1026 scsi_qla_host_t *vha = shost_priv(cmd->device->host);
1027 struct qla_hw_data *ha = vha->hw;
1029 return __qla2xxx_eh_generic_reset("DEVICE", WAIT_LUN, cmd,
1030 ha->isp_ops->lun_reset);
1034 qla2xxx_eh_target_reset(struct scsi_cmnd *cmd)
1036 scsi_qla_host_t *vha = shost_priv(cmd->device->host);
1037 struct qla_hw_data *ha = vha->hw;
1039 return __qla2xxx_eh_generic_reset("TARGET", WAIT_TARGET, cmd,
1040 ha->isp_ops->target_reset);
1043 /**************************************************************************
1044 * qla2xxx_eh_bus_reset
1047 * The bus reset function will reset the bus and abort any executing
1051 * cmd = Linux SCSI command packet of the command that cause the
1055 * SUCCESS/FAILURE (defined as macro in scsi.h).
1057 **************************************************************************/
1059 qla2xxx_eh_bus_reset(struct scsi_cmnd *cmd)
1061 scsi_qla_host_t *vha = shost_priv(cmd->device->host);
1062 fc_port_t *fcport = (struct fc_port *) cmd->device->hostdata;
1064 unsigned int id, lun;
1066 id = cmd->device->id;
1067 lun = cmd->device->lun;
1073 ret = fc_block_scsi_eh(cmd);
1078 ql_log(ql_log_info, vha, 0x8012,
1079 "BUS RESET ISSUED nexus=%ld:%d%d.\n", vha->host_no, id, lun);
1081 if (qla2x00_wait_for_hba_online(vha) != QLA_SUCCESS) {
1082 ql_log(ql_log_fatal, vha, 0x8013,
1083 "Wait for hba online failed board disabled.\n");
1084 goto eh_bus_reset_done;
1087 if (qla2x00_loop_reset(vha) == QLA_SUCCESS)
1091 goto eh_bus_reset_done;
1093 /* Flush outstanding commands. */
1094 if (qla2x00_eh_wait_for_pending_commands(vha, 0, 0, WAIT_HOST) !=
1096 ql_log(ql_log_warn, vha, 0x8014,
1097 "Wait for pending commands failed.\n");
1102 ql_log(ql_log_warn, vha, 0x802b,
1103 "BUS RESET %s nexus=%ld:%d:%d.\n",
1104 (ret == FAILED) ? "FAILED" : "SUCCEDED", vha->host_no, id, lun);
1109 /**************************************************************************
1110 * qla2xxx_eh_host_reset
1113 * The reset function will reset the Adapter.
1116 * cmd = Linux SCSI command packet of the command that cause the
1120 * Either SUCCESS or FAILED.
1123 **************************************************************************/
1125 qla2xxx_eh_host_reset(struct scsi_cmnd *cmd)
1127 scsi_qla_host_t *vha = shost_priv(cmd->device->host);
1128 fc_port_t *fcport = (struct fc_port *) cmd->device->hostdata;
1129 struct qla_hw_data *ha = vha->hw;
1131 unsigned int id, lun;
1132 scsi_qla_host_t *base_vha = pci_get_drvdata(ha->pdev);
1134 id = cmd->device->id;
1135 lun = cmd->device->lun;
1141 ret = fc_block_scsi_eh(cmd);
1146 ql_log(ql_log_info, vha, 0x8018,
1147 "ADAPTER RESET ISSUED nexus=%ld:%d:%d.\n", vha->host_no, id, lun);
1149 if (qla2x00_wait_for_reset_ready(vha) != QLA_SUCCESS)
1150 goto eh_host_reset_lock;
1152 if (vha != base_vha) {
1153 if (qla2x00_vp_abort_isp(vha))
1154 goto eh_host_reset_lock;
1156 if (IS_QLA82XX(vha->hw)) {
1157 if (!qla82xx_fcoe_ctx_reset(vha)) {
1158 /* Ctx reset success */
1160 goto eh_host_reset_lock;
1162 /* fall thru if ctx reset failed */
1165 flush_workqueue(ha->wq);
1167 set_bit(ABORT_ISP_ACTIVE, &base_vha->dpc_flags);
1168 if (ha->isp_ops->abort_isp(base_vha)) {
1169 clear_bit(ABORT_ISP_ACTIVE, &base_vha->dpc_flags);
1170 /* failed. schedule dpc to try */
1171 set_bit(ISP_ABORT_NEEDED, &base_vha->dpc_flags);
1173 if (qla2x00_wait_for_hba_online(vha) != QLA_SUCCESS) {
1174 ql_log(ql_log_warn, vha, 0x802a,
1175 "wait for hba online failed.\n");
1176 goto eh_host_reset_lock;
1179 clear_bit(ABORT_ISP_ACTIVE, &base_vha->dpc_flags);
1182 /* Waiting for command to be returned to OS.*/
1183 if (qla2x00_eh_wait_for_pending_commands(vha, 0, 0, WAIT_HOST) ==
1188 ql_log(ql_log_info, vha, 0x8017,
1189 "ADAPTER RESET %s nexus=%ld:%d:%d.\n",
1190 (ret == FAILED) ? "FAILED" : "SUCCEEDED", vha->host_no, id, lun);
1196 * qla2x00_loop_reset
1200 * ha = adapter block pointer.
1206 qla2x00_loop_reset(scsi_qla_host_t *vha)
1209 struct fc_port *fcport;
1210 struct qla_hw_data *ha = vha->hw;
1212 if (ql2xtargetreset == 1 && ha->flags.enable_target_reset) {
1213 list_for_each_entry(fcport, &vha->vp_fcports, list) {
1214 if (fcport->port_type != FCT_TARGET)
1217 ret = ha->isp_ops->target_reset(fcport, 0, 0);
1218 if (ret != QLA_SUCCESS) {
1219 ql_dbg(ql_dbg_taskm, vha, 0x802c,
1220 "Bus Reset failed: Target Reset=%d "
1221 "d_id=%x.\n", ret, fcport->d_id.b24);
1226 if (ha->flags.enable_lip_full_login && !IS_QLA8XXX_TYPE(ha)) {
1227 ret = qla2x00_full_login_lip(vha);
1228 if (ret != QLA_SUCCESS) {
1229 ql_dbg(ql_dbg_taskm, vha, 0x802d,
1230 "full_login_lip=%d.\n", ret);
1232 atomic_set(&vha->loop_state, LOOP_DOWN);
1233 atomic_set(&vha->loop_down_timer, LOOP_DOWN_TIME);
1234 qla2x00_mark_all_devices_lost(vha, 0);
1237 if (ha->flags.enable_lip_reset) {
1238 ret = qla2x00_lip_reset(vha);
1239 if (ret != QLA_SUCCESS)
1240 ql_dbg(ql_dbg_taskm, vha, 0x802e,
1241 "lip_reset failed (%d).\n", ret);
1244 /* Issue marker command only when we are going to start the I/O */
1245 vha->marker_needed = 1;
1251 qla2x00_abort_all_cmds(scsi_qla_host_t *vha, int res)
1254 unsigned long flags;
1256 struct srb_ctx *ctx;
1257 struct qla_hw_data *ha = vha->hw;
1258 struct req_que *req;
1260 spin_lock_irqsave(&ha->hardware_lock, flags);
1261 for (que = 0; que < ha->max_req_queues; que++) {
1262 req = ha->req_q_map[que];
1265 for (cnt = 1; cnt < MAX_OUTSTANDING_COMMANDS; cnt++) {
1266 sp = req->outstanding_cmds[cnt];
1268 req->outstanding_cmds[cnt] = NULL;
1270 (sp->flags & SRB_FCP_CMND_DMA_VALID) ||
1272 sp->cmd->result = res;
1273 qla2x00_sp_compl(ha, sp);
1276 if (ctx->type == SRB_ELS_CMD_RPT ||
1277 ctx->type == SRB_ELS_CMD_HST ||
1278 ctx->type == SRB_CT_CMD) {
1279 struct fc_bsg_job *bsg_job =
1281 if (bsg_job->request->msgcode
1284 bsg_job->req->errors = 0;
1285 bsg_job->reply->result = res;
1286 bsg_job->job_done(bsg_job);
1291 ctx->u.iocb_cmd->free(sp);
1297 spin_unlock_irqrestore(&ha->hardware_lock, flags);
1301 qla2xxx_slave_alloc(struct scsi_device *sdev)
1303 struct fc_rport *rport = starget_to_rport(scsi_target(sdev));
1305 if (!rport || fc_remote_port_chkready(rport))
1308 sdev->hostdata = *(fc_port_t **)rport->dd_data;
1314 qla2xxx_slave_configure(struct scsi_device *sdev)
1316 scsi_qla_host_t *vha = shost_priv(sdev->host);
1317 struct req_que *req = vha->req;
1319 if (sdev->tagged_supported)
1320 scsi_activate_tcq(sdev, req->max_q_depth);
1322 scsi_deactivate_tcq(sdev, req->max_q_depth);
1327 qla2xxx_slave_destroy(struct scsi_device *sdev)
1329 sdev->hostdata = NULL;
1332 static void qla2x00_handle_queue_full(struct scsi_device *sdev, int qdepth)
1334 fc_port_t *fcport = (struct fc_port *) sdev->hostdata;
1336 if (!scsi_track_queue_full(sdev, qdepth))
1339 ql_dbg(ql_dbg_io, fcport->vha, 0x3029,
1340 "Queue depth adjusted-down to %d for nexus=%ld:%d:%d.\n",
1341 sdev->queue_depth, fcport->vha->host_no, sdev->id, sdev->lun);
1344 static void qla2x00_adjust_sdev_qdepth_up(struct scsi_device *sdev, int qdepth)
1346 fc_port_t *fcport = sdev->hostdata;
1347 struct scsi_qla_host *vha = fcport->vha;
1348 struct req_que *req = NULL;
1354 if (req->max_q_depth <= sdev->queue_depth || req->max_q_depth < qdepth)
1357 if (sdev->ordered_tags)
1358 scsi_adjust_queue_depth(sdev, MSG_ORDERED_TAG, qdepth);
1360 scsi_adjust_queue_depth(sdev, MSG_SIMPLE_TAG, qdepth);
1362 ql_dbg(ql_dbg_io, vha, 0x302a,
1363 "Queue depth adjusted-up to %d for nexus=%ld:%d:%d.\n",
1364 sdev->queue_depth, fcport->vha->host_no, sdev->id, sdev->lun);
1368 qla2x00_change_queue_depth(struct scsi_device *sdev, int qdepth, int reason)
1371 case SCSI_QDEPTH_DEFAULT:
1372 scsi_adjust_queue_depth(sdev, scsi_get_tag_type(sdev), qdepth);
1374 case SCSI_QDEPTH_QFULL:
1375 qla2x00_handle_queue_full(sdev, qdepth);
1377 case SCSI_QDEPTH_RAMP_UP:
1378 qla2x00_adjust_sdev_qdepth_up(sdev, qdepth);
1384 return sdev->queue_depth;
1388 qla2x00_change_queue_type(struct scsi_device *sdev, int tag_type)
1390 if (sdev->tagged_supported) {
1391 scsi_set_tag_type(sdev, tag_type);
1393 scsi_activate_tcq(sdev, sdev->queue_depth);
1395 scsi_deactivate_tcq(sdev, sdev->queue_depth);
1403 * qla2x00_config_dma_addressing() - Configure OS DMA addressing method.
1406 * At exit, the @ha's flags.enable_64bit_addressing set to indicated
1407 * supported addressing method.
1410 qla2x00_config_dma_addressing(struct qla_hw_data *ha)
1412 /* Assume a 32bit DMA mask. */
1413 ha->flags.enable_64bit_addressing = 0;
1415 if (!dma_set_mask(&ha->pdev->dev, DMA_BIT_MASK(64))) {
1416 /* Any upper-dword bits set? */
1417 if (MSD(dma_get_required_mask(&ha->pdev->dev)) &&
1418 !pci_set_consistent_dma_mask(ha->pdev, DMA_BIT_MASK(64))) {
1419 /* Ok, a 64bit DMA mask is applicable. */
1420 ha->flags.enable_64bit_addressing = 1;
1421 ha->isp_ops->calc_req_entries = qla2x00_calc_iocbs_64;
1422 ha->isp_ops->build_iocbs = qla2x00_build_scsi_iocbs_64;
1427 dma_set_mask(&ha->pdev->dev, DMA_BIT_MASK(32));
1428 pci_set_consistent_dma_mask(ha->pdev, DMA_BIT_MASK(32));
1432 qla2x00_enable_intrs(struct qla_hw_data *ha)
1434 unsigned long flags = 0;
1435 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
1437 spin_lock_irqsave(&ha->hardware_lock, flags);
1438 ha->interrupts_on = 1;
1439 /* enable risc and host interrupts */
1440 WRT_REG_WORD(®->ictrl, ICR_EN_INT | ICR_EN_RISC);
1441 RD_REG_WORD(®->ictrl);
1442 spin_unlock_irqrestore(&ha->hardware_lock, flags);
1447 qla2x00_disable_intrs(struct qla_hw_data *ha)
1449 unsigned long flags = 0;
1450 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
1452 spin_lock_irqsave(&ha->hardware_lock, flags);
1453 ha->interrupts_on = 0;
1454 /* disable risc and host interrupts */
1455 WRT_REG_WORD(®->ictrl, 0);
1456 RD_REG_WORD(®->ictrl);
1457 spin_unlock_irqrestore(&ha->hardware_lock, flags);
1461 qla24xx_enable_intrs(struct qla_hw_data *ha)
1463 unsigned long flags = 0;
1464 struct device_reg_24xx __iomem *reg = &ha->iobase->isp24;
1466 spin_lock_irqsave(&ha->hardware_lock, flags);
1467 ha->interrupts_on = 1;
1468 WRT_REG_DWORD(®->ictrl, ICRX_EN_RISC_INT);
1469 RD_REG_DWORD(®->ictrl);
1470 spin_unlock_irqrestore(&ha->hardware_lock, flags);
1474 qla24xx_disable_intrs(struct qla_hw_data *ha)
1476 unsigned long flags = 0;
1477 struct device_reg_24xx __iomem *reg = &ha->iobase->isp24;
1479 if (IS_NOPOLLING_TYPE(ha))
1481 spin_lock_irqsave(&ha->hardware_lock, flags);
1482 ha->interrupts_on = 0;
1483 WRT_REG_DWORD(®->ictrl, 0);
1484 RD_REG_DWORD(®->ictrl);
1485 spin_unlock_irqrestore(&ha->hardware_lock, flags);
1489 qla2x00_iospace_config(struct qla_hw_data *ha)
1491 resource_size_t pio;
1496 return qla82xx_iospace_config(ha);
1498 if (pci_request_selected_regions(ha->pdev, ha->bars,
1499 QLA2XXX_DRIVER_NAME)) {
1500 ql_log_pci(ql_log_fatal, ha->pdev, 0x0011,
1501 "Failed to reserve PIO/MMIO regions (%s), aborting.\n",
1502 pci_name(ha->pdev));
1503 goto iospace_error_exit;
1505 if (!(ha->bars & 1))
1508 /* We only need PIO for Flash operations on ISP2312 v2 chips. */
1509 pio = pci_resource_start(ha->pdev, 0);
1510 if (pci_resource_flags(ha->pdev, 0) & IORESOURCE_IO) {
1511 if (pci_resource_len(ha->pdev, 0) < MIN_IOBASE_LEN) {
1512 ql_log_pci(ql_log_warn, ha->pdev, 0x0012,
1513 "Invalid pci I/O region size (%s).\n",
1514 pci_name(ha->pdev));
1518 ql_log_pci(ql_log_warn, ha->pdev, 0x0013,
1519 "Region #0 no a PIO resource (%s).\n",
1520 pci_name(ha->pdev));
1523 ha->pio_address = pio;
1524 ql_dbg_pci(ql_dbg_init, ha->pdev, 0x0014,
1525 "PIO address=%llu.\n",
1526 (unsigned long long)ha->pio_address);
1529 /* Use MMIO operations for all accesses. */
1530 if (!(pci_resource_flags(ha->pdev, 1) & IORESOURCE_MEM)) {
1531 ql_log_pci(ql_log_fatal, ha->pdev, 0x0015,
1532 "Region #1 not an MMIO resource (%s), aborting.\n",
1533 pci_name(ha->pdev));
1534 goto iospace_error_exit;
1536 if (pci_resource_len(ha->pdev, 1) < MIN_IOBASE_LEN) {
1537 ql_log_pci(ql_log_fatal, ha->pdev, 0x0016,
1538 "Invalid PCI mem region size (%s), aborting.\n",
1539 pci_name(ha->pdev));
1540 goto iospace_error_exit;
1543 ha->iobase = ioremap(pci_resource_start(ha->pdev, 1), MIN_IOBASE_LEN);
1545 ql_log_pci(ql_log_fatal, ha->pdev, 0x0017,
1546 "Cannot remap MMIO (%s), aborting.\n",
1547 pci_name(ha->pdev));
1548 goto iospace_error_exit;
1551 /* Determine queue resources */
1552 ha->max_req_queues = ha->max_rsp_queues = 1;
1553 if ((ql2xmaxqueues <= 1 && !ql2xmultique_tag) ||
1554 (ql2xmaxqueues > 1 && ql2xmultique_tag) ||
1555 (!IS_QLA25XX(ha) && !IS_QLA81XX(ha)))
1558 ha->mqiobase = ioremap(pci_resource_start(ha->pdev, 3),
1559 pci_resource_len(ha->pdev, 3));
1561 ql_dbg_pci(ql_dbg_init, ha->pdev, 0x0018,
1562 "MQIO Base=%p.\n", ha->mqiobase);
1563 /* Read MSIX vector size of the board */
1564 pci_read_config_word(ha->pdev, QLA_PCI_MSIX_CONTROL, &msix);
1565 ha->msix_count = msix;
1566 /* Max queues are bounded by available msix vectors */
1567 /* queue 0 uses two msix vectors */
1568 if (ql2xmultique_tag) {
1569 cpus = num_online_cpus();
1570 ha->max_rsp_queues = (ha->msix_count - 1 > cpus) ?
1571 (cpus + 1) : (ha->msix_count - 1);
1572 ha->max_req_queues = 2;
1573 } else if (ql2xmaxqueues > 1) {
1574 ha->max_req_queues = ql2xmaxqueues > QLA_MQ_SIZE ?
1575 QLA_MQ_SIZE : ql2xmaxqueues;
1576 ql_dbg_pci(ql_dbg_multiq, ha->pdev, 0xc008,
1577 "QoS mode set, max no of request queues:%d.\n",
1578 ha->max_req_queues);
1579 ql_dbg_pci(ql_dbg_init, ha->pdev, 0x0019,
1580 "QoS mode set, max no of request queues:%d.\n",
1581 ha->max_req_queues);
1583 ql_log_pci(ql_log_info, ha->pdev, 0x001a,
1584 "MSI-X vector count: %d.\n", msix);
1586 ql_log_pci(ql_log_info, ha->pdev, 0x001b,
1587 "BAR 3 not enabled.\n");
1590 ha->msix_count = ha->max_rsp_queues + 1;
1591 ql_dbg_pci(ql_dbg_init, ha->pdev, 0x001c,
1592 "MSIX Count:%d.\n", ha->msix_count);
1600 static struct isp_operations qla2100_isp_ops = {
1601 .pci_config = qla2100_pci_config,
1602 .reset_chip = qla2x00_reset_chip,
1603 .chip_diag = qla2x00_chip_diag,
1604 .config_rings = qla2x00_config_rings,
1605 .reset_adapter = qla2x00_reset_adapter,
1606 .nvram_config = qla2x00_nvram_config,
1607 .update_fw_options = qla2x00_update_fw_options,
1608 .load_risc = qla2x00_load_risc,
1609 .pci_info_str = qla2x00_pci_info_str,
1610 .fw_version_str = qla2x00_fw_version_str,
1611 .intr_handler = qla2100_intr_handler,
1612 .enable_intrs = qla2x00_enable_intrs,
1613 .disable_intrs = qla2x00_disable_intrs,
1614 .abort_command = qla2x00_abort_command,
1615 .target_reset = qla2x00_abort_target,
1616 .lun_reset = qla2x00_lun_reset,
1617 .fabric_login = qla2x00_login_fabric,
1618 .fabric_logout = qla2x00_fabric_logout,
1619 .calc_req_entries = qla2x00_calc_iocbs_32,
1620 .build_iocbs = qla2x00_build_scsi_iocbs_32,
1621 .prep_ms_iocb = qla2x00_prep_ms_iocb,
1622 .prep_ms_fdmi_iocb = qla2x00_prep_ms_fdmi_iocb,
1623 .read_nvram = qla2x00_read_nvram_data,
1624 .write_nvram = qla2x00_write_nvram_data,
1625 .fw_dump = qla2100_fw_dump,
1628 .beacon_blink = NULL,
1629 .read_optrom = qla2x00_read_optrom_data,
1630 .write_optrom = qla2x00_write_optrom_data,
1631 .get_flash_version = qla2x00_get_flash_version,
1632 .start_scsi = qla2x00_start_scsi,
1633 .abort_isp = qla2x00_abort_isp,
1634 .iospace_config = qla2x00_iospace_config,
1637 static struct isp_operations qla2300_isp_ops = {
1638 .pci_config = qla2300_pci_config,
1639 .reset_chip = qla2x00_reset_chip,
1640 .chip_diag = qla2x00_chip_diag,
1641 .config_rings = qla2x00_config_rings,
1642 .reset_adapter = qla2x00_reset_adapter,
1643 .nvram_config = qla2x00_nvram_config,
1644 .update_fw_options = qla2x00_update_fw_options,
1645 .load_risc = qla2x00_load_risc,
1646 .pci_info_str = qla2x00_pci_info_str,
1647 .fw_version_str = qla2x00_fw_version_str,
1648 .intr_handler = qla2300_intr_handler,
1649 .enable_intrs = qla2x00_enable_intrs,
1650 .disable_intrs = qla2x00_disable_intrs,
1651 .abort_command = qla2x00_abort_command,
1652 .target_reset = qla2x00_abort_target,
1653 .lun_reset = qla2x00_lun_reset,
1654 .fabric_login = qla2x00_login_fabric,
1655 .fabric_logout = qla2x00_fabric_logout,
1656 .calc_req_entries = qla2x00_calc_iocbs_32,
1657 .build_iocbs = qla2x00_build_scsi_iocbs_32,
1658 .prep_ms_iocb = qla2x00_prep_ms_iocb,
1659 .prep_ms_fdmi_iocb = qla2x00_prep_ms_fdmi_iocb,
1660 .read_nvram = qla2x00_read_nvram_data,
1661 .write_nvram = qla2x00_write_nvram_data,
1662 .fw_dump = qla2300_fw_dump,
1663 .beacon_on = qla2x00_beacon_on,
1664 .beacon_off = qla2x00_beacon_off,
1665 .beacon_blink = qla2x00_beacon_blink,
1666 .read_optrom = qla2x00_read_optrom_data,
1667 .write_optrom = qla2x00_write_optrom_data,
1668 .get_flash_version = qla2x00_get_flash_version,
1669 .start_scsi = qla2x00_start_scsi,
1670 .abort_isp = qla2x00_abort_isp,
1671 .iospace_config = qla2x00_iospace_config,
1674 static struct isp_operations qla24xx_isp_ops = {
1675 .pci_config = qla24xx_pci_config,
1676 .reset_chip = qla24xx_reset_chip,
1677 .chip_diag = qla24xx_chip_diag,
1678 .config_rings = qla24xx_config_rings,
1679 .reset_adapter = qla24xx_reset_adapter,
1680 .nvram_config = qla24xx_nvram_config,
1681 .update_fw_options = qla24xx_update_fw_options,
1682 .load_risc = qla24xx_load_risc,
1683 .pci_info_str = qla24xx_pci_info_str,
1684 .fw_version_str = qla24xx_fw_version_str,
1685 .intr_handler = qla24xx_intr_handler,
1686 .enable_intrs = qla24xx_enable_intrs,
1687 .disable_intrs = qla24xx_disable_intrs,
1688 .abort_command = qla24xx_abort_command,
1689 .target_reset = qla24xx_abort_target,
1690 .lun_reset = qla24xx_lun_reset,
1691 .fabric_login = qla24xx_login_fabric,
1692 .fabric_logout = qla24xx_fabric_logout,
1693 .calc_req_entries = NULL,
1694 .build_iocbs = NULL,
1695 .prep_ms_iocb = qla24xx_prep_ms_iocb,
1696 .prep_ms_fdmi_iocb = qla24xx_prep_ms_fdmi_iocb,
1697 .read_nvram = qla24xx_read_nvram_data,
1698 .write_nvram = qla24xx_write_nvram_data,
1699 .fw_dump = qla24xx_fw_dump,
1700 .beacon_on = qla24xx_beacon_on,
1701 .beacon_off = qla24xx_beacon_off,
1702 .beacon_blink = qla24xx_beacon_blink,
1703 .read_optrom = qla24xx_read_optrom_data,
1704 .write_optrom = qla24xx_write_optrom_data,
1705 .get_flash_version = qla24xx_get_flash_version,
1706 .start_scsi = qla24xx_start_scsi,
1707 .abort_isp = qla2x00_abort_isp,
1708 .iospace_config = qla2x00_iospace_config,
1711 static struct isp_operations qla25xx_isp_ops = {
1712 .pci_config = qla25xx_pci_config,
1713 .reset_chip = qla24xx_reset_chip,
1714 .chip_diag = qla24xx_chip_diag,
1715 .config_rings = qla24xx_config_rings,
1716 .reset_adapter = qla24xx_reset_adapter,
1717 .nvram_config = qla24xx_nvram_config,
1718 .update_fw_options = qla24xx_update_fw_options,
1719 .load_risc = qla24xx_load_risc,
1720 .pci_info_str = qla24xx_pci_info_str,
1721 .fw_version_str = qla24xx_fw_version_str,
1722 .intr_handler = qla24xx_intr_handler,
1723 .enable_intrs = qla24xx_enable_intrs,
1724 .disable_intrs = qla24xx_disable_intrs,
1725 .abort_command = qla24xx_abort_command,
1726 .target_reset = qla24xx_abort_target,
1727 .lun_reset = qla24xx_lun_reset,
1728 .fabric_login = qla24xx_login_fabric,
1729 .fabric_logout = qla24xx_fabric_logout,
1730 .calc_req_entries = NULL,
1731 .build_iocbs = NULL,
1732 .prep_ms_iocb = qla24xx_prep_ms_iocb,
1733 .prep_ms_fdmi_iocb = qla24xx_prep_ms_fdmi_iocb,
1734 .read_nvram = qla25xx_read_nvram_data,
1735 .write_nvram = qla25xx_write_nvram_data,
1736 .fw_dump = qla25xx_fw_dump,
1737 .beacon_on = qla24xx_beacon_on,
1738 .beacon_off = qla24xx_beacon_off,
1739 .beacon_blink = qla24xx_beacon_blink,
1740 .read_optrom = qla25xx_read_optrom_data,
1741 .write_optrom = qla24xx_write_optrom_data,
1742 .get_flash_version = qla24xx_get_flash_version,
1743 .start_scsi = qla24xx_dif_start_scsi,
1744 .abort_isp = qla2x00_abort_isp,
1745 .iospace_config = qla2x00_iospace_config,
1748 static struct isp_operations qla81xx_isp_ops = {
1749 .pci_config = qla25xx_pci_config,
1750 .reset_chip = qla24xx_reset_chip,
1751 .chip_diag = qla24xx_chip_diag,
1752 .config_rings = qla24xx_config_rings,
1753 .reset_adapter = qla24xx_reset_adapter,
1754 .nvram_config = qla81xx_nvram_config,
1755 .update_fw_options = qla81xx_update_fw_options,
1756 .load_risc = qla81xx_load_risc,
1757 .pci_info_str = qla24xx_pci_info_str,
1758 .fw_version_str = qla24xx_fw_version_str,
1759 .intr_handler = qla24xx_intr_handler,
1760 .enable_intrs = qla24xx_enable_intrs,
1761 .disable_intrs = qla24xx_disable_intrs,
1762 .abort_command = qla24xx_abort_command,
1763 .target_reset = qla24xx_abort_target,
1764 .lun_reset = qla24xx_lun_reset,
1765 .fabric_login = qla24xx_login_fabric,
1766 .fabric_logout = qla24xx_fabric_logout,
1767 .calc_req_entries = NULL,
1768 .build_iocbs = NULL,
1769 .prep_ms_iocb = qla24xx_prep_ms_iocb,
1770 .prep_ms_fdmi_iocb = qla24xx_prep_ms_fdmi_iocb,
1772 .write_nvram = NULL,
1773 .fw_dump = qla81xx_fw_dump,
1774 .beacon_on = qla24xx_beacon_on,
1775 .beacon_off = qla24xx_beacon_off,
1776 .beacon_blink = qla24xx_beacon_blink,
1777 .read_optrom = qla25xx_read_optrom_data,
1778 .write_optrom = qla24xx_write_optrom_data,
1779 .get_flash_version = qla24xx_get_flash_version,
1780 .start_scsi = qla24xx_dif_start_scsi,
1781 .abort_isp = qla2x00_abort_isp,
1782 .iospace_config = qla2x00_iospace_config,
1785 static struct isp_operations qla82xx_isp_ops = {
1786 .pci_config = qla82xx_pci_config,
1787 .reset_chip = qla82xx_reset_chip,
1788 .chip_diag = qla24xx_chip_diag,
1789 .config_rings = qla82xx_config_rings,
1790 .reset_adapter = qla24xx_reset_adapter,
1791 .nvram_config = qla81xx_nvram_config,
1792 .update_fw_options = qla24xx_update_fw_options,
1793 .load_risc = qla82xx_load_risc,
1794 .pci_info_str = qla82xx_pci_info_str,
1795 .fw_version_str = qla24xx_fw_version_str,
1796 .intr_handler = qla82xx_intr_handler,
1797 .enable_intrs = qla82xx_enable_intrs,
1798 .disable_intrs = qla82xx_disable_intrs,
1799 .abort_command = qla24xx_abort_command,
1800 .target_reset = qla24xx_abort_target,
1801 .lun_reset = qla24xx_lun_reset,
1802 .fabric_login = qla24xx_login_fabric,
1803 .fabric_logout = qla24xx_fabric_logout,
1804 .calc_req_entries = NULL,
1805 .build_iocbs = NULL,
1806 .prep_ms_iocb = qla24xx_prep_ms_iocb,
1807 .prep_ms_fdmi_iocb = qla24xx_prep_ms_fdmi_iocb,
1808 .read_nvram = qla24xx_read_nvram_data,
1809 .write_nvram = qla24xx_write_nvram_data,
1810 .fw_dump = qla24xx_fw_dump,
1811 .beacon_on = qla82xx_beacon_on,
1812 .beacon_off = qla82xx_beacon_off,
1813 .beacon_blink = NULL,
1814 .read_optrom = qla82xx_read_optrom_data,
1815 .write_optrom = qla82xx_write_optrom_data,
1816 .get_flash_version = qla24xx_get_flash_version,
1817 .start_scsi = qla82xx_start_scsi,
1818 .abort_isp = qla82xx_abort_isp,
1819 .iospace_config = qla82xx_iospace_config,
1823 qla2x00_set_isp_flags(struct qla_hw_data *ha)
1825 ha->device_type = DT_EXTENDED_IDS;
1826 switch (ha->pdev->device) {
1827 case PCI_DEVICE_ID_QLOGIC_ISP2100:
1828 ha->device_type |= DT_ISP2100;
1829 ha->device_type &= ~DT_EXTENDED_IDS;
1830 ha->fw_srisc_address = RISC_START_ADDRESS_2100;
1832 case PCI_DEVICE_ID_QLOGIC_ISP2200:
1833 ha->device_type |= DT_ISP2200;
1834 ha->device_type &= ~DT_EXTENDED_IDS;
1835 ha->fw_srisc_address = RISC_START_ADDRESS_2100;
1837 case PCI_DEVICE_ID_QLOGIC_ISP2300:
1838 ha->device_type |= DT_ISP2300;
1839 ha->device_type |= DT_ZIO_SUPPORTED;
1840 ha->fw_srisc_address = RISC_START_ADDRESS_2300;
1842 case PCI_DEVICE_ID_QLOGIC_ISP2312:
1843 ha->device_type |= DT_ISP2312;
1844 ha->device_type |= DT_ZIO_SUPPORTED;
1845 ha->fw_srisc_address = RISC_START_ADDRESS_2300;
1847 case PCI_DEVICE_ID_QLOGIC_ISP2322:
1848 ha->device_type |= DT_ISP2322;
1849 ha->device_type |= DT_ZIO_SUPPORTED;
1850 if (ha->pdev->subsystem_vendor == 0x1028 &&
1851 ha->pdev->subsystem_device == 0x0170)
1852 ha->device_type |= DT_OEM_001;
1853 ha->fw_srisc_address = RISC_START_ADDRESS_2300;
1855 case PCI_DEVICE_ID_QLOGIC_ISP6312:
1856 ha->device_type |= DT_ISP6312;
1857 ha->fw_srisc_address = RISC_START_ADDRESS_2300;
1859 case PCI_DEVICE_ID_QLOGIC_ISP6322:
1860 ha->device_type |= DT_ISP6322;
1861 ha->fw_srisc_address = RISC_START_ADDRESS_2300;
1863 case PCI_DEVICE_ID_QLOGIC_ISP2422:
1864 ha->device_type |= DT_ISP2422;
1865 ha->device_type |= DT_ZIO_SUPPORTED;
1866 ha->device_type |= DT_FWI2;
1867 ha->device_type |= DT_IIDMA;
1868 ha->fw_srisc_address = RISC_START_ADDRESS_2400;
1870 case PCI_DEVICE_ID_QLOGIC_ISP2432:
1871 ha->device_type |= DT_ISP2432;
1872 ha->device_type |= DT_ZIO_SUPPORTED;
1873 ha->device_type |= DT_FWI2;
1874 ha->device_type |= DT_IIDMA;
1875 ha->fw_srisc_address = RISC_START_ADDRESS_2400;
1877 case PCI_DEVICE_ID_QLOGIC_ISP8432:
1878 ha->device_type |= DT_ISP8432;
1879 ha->device_type |= DT_ZIO_SUPPORTED;
1880 ha->device_type |= DT_FWI2;
1881 ha->device_type |= DT_IIDMA;
1882 ha->fw_srisc_address = RISC_START_ADDRESS_2400;
1884 case PCI_DEVICE_ID_QLOGIC_ISP5422:
1885 ha->device_type |= DT_ISP5422;
1886 ha->device_type |= DT_FWI2;
1887 ha->fw_srisc_address = RISC_START_ADDRESS_2400;
1889 case PCI_DEVICE_ID_QLOGIC_ISP5432:
1890 ha->device_type |= DT_ISP5432;
1891 ha->device_type |= DT_FWI2;
1892 ha->fw_srisc_address = RISC_START_ADDRESS_2400;
1894 case PCI_DEVICE_ID_QLOGIC_ISP2532:
1895 ha->device_type |= DT_ISP2532;
1896 ha->device_type |= DT_ZIO_SUPPORTED;
1897 ha->device_type |= DT_FWI2;
1898 ha->device_type |= DT_IIDMA;
1899 ha->fw_srisc_address = RISC_START_ADDRESS_2400;
1901 case PCI_DEVICE_ID_QLOGIC_ISP8001:
1902 ha->device_type |= DT_ISP8001;
1903 ha->device_type |= DT_ZIO_SUPPORTED;
1904 ha->device_type |= DT_FWI2;
1905 ha->device_type |= DT_IIDMA;
1906 ha->fw_srisc_address = RISC_START_ADDRESS_2400;
1908 case PCI_DEVICE_ID_QLOGIC_ISP8021:
1909 ha->device_type |= DT_ISP8021;
1910 ha->device_type |= DT_ZIO_SUPPORTED;
1911 ha->device_type |= DT_FWI2;
1912 ha->fw_srisc_address = RISC_START_ADDRESS_2400;
1913 /* Initialize 82XX ISP flags */
1914 qla82xx_init_flags(ha);
1919 ha->port_no = !(ha->portnum & 1);
1921 /* Get adapter physical port no from interrupt pin register. */
1922 pci_read_config_byte(ha->pdev, PCI_INTERRUPT_PIN, &ha->port_no);
1924 if (ha->port_no & 1)
1925 ha->flags.port0 = 1;
1927 ha->flags.port0 = 0;
1928 ql_dbg_pci(ql_dbg_init, ha->pdev, 0x000b,
1929 "device_type=0x%x port=%d fw_srisc_address=0x%x.\n",
1930 ha->device_type, ha->flags.port0, ha->fw_srisc_address);
1934 qla2xxx_scan_start(struct Scsi_Host *shost)
1936 scsi_qla_host_t *vha = shost_priv(shost);
1938 if (vha->hw->flags.running_gold_fw)
1941 set_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags);
1942 set_bit(LOCAL_LOOP_UPDATE, &vha->dpc_flags);
1943 set_bit(RSCN_UPDATE, &vha->dpc_flags);
1944 set_bit(NPIV_CONFIG_NEEDED, &vha->dpc_flags);
1948 qla2xxx_scan_finished(struct Scsi_Host *shost, unsigned long time)
1950 scsi_qla_host_t *vha = shost_priv(shost);
1954 if (time > vha->hw->loop_reset_delay * HZ)
1957 return atomic_read(&vha->loop_state) == LOOP_READY;
1961 * PCI driver interface
1963 static int __devinit
1964 qla2x00_probe_one(struct pci_dev *pdev, const struct pci_device_id *id)
1967 struct Scsi_Host *host;
1968 scsi_qla_host_t *base_vha = NULL;
1969 struct qla_hw_data *ha;
1972 struct scsi_host_template *sht;
1973 int bars, max_id, mem_only = 0;
1974 uint16_t req_length = 0, rsp_length = 0;
1975 struct req_que *req = NULL;
1976 struct rsp_que *rsp = NULL;
1978 bars = pci_select_bars(pdev, IORESOURCE_MEM | IORESOURCE_IO);
1979 sht = &qla2xxx_driver_template;
1980 if (pdev->device == PCI_DEVICE_ID_QLOGIC_ISP2422 ||
1981 pdev->device == PCI_DEVICE_ID_QLOGIC_ISP2432 ||
1982 pdev->device == PCI_DEVICE_ID_QLOGIC_ISP8432 ||
1983 pdev->device == PCI_DEVICE_ID_QLOGIC_ISP5422 ||
1984 pdev->device == PCI_DEVICE_ID_QLOGIC_ISP5432 ||
1985 pdev->device == PCI_DEVICE_ID_QLOGIC_ISP2532 ||
1986 pdev->device == PCI_DEVICE_ID_QLOGIC_ISP8001 ||
1987 pdev->device == PCI_DEVICE_ID_QLOGIC_ISP8021) {
1988 bars = pci_select_bars(pdev, IORESOURCE_MEM);
1990 ql_dbg_pci(ql_dbg_init, pdev, 0x0007,
1991 "Mem only adapter.\n");
1993 ql_dbg_pci(ql_dbg_init, pdev, 0x0008,
1994 "Bars=%d.\n", bars);
1997 if (pci_enable_device_mem(pdev))
2000 if (pci_enable_device(pdev))
2004 /* This may fail but that's ok */
2005 pci_enable_pcie_error_reporting(pdev);
2007 ha = kzalloc(sizeof(struct qla_hw_data), GFP_KERNEL);
2009 ql_log_pci(ql_log_fatal, pdev, 0x0009,
2010 "Unable to allocate memory for ha.\n");
2013 ql_dbg_pci(ql_dbg_init, pdev, 0x000a,
2014 "Memory allocated for ha=%p.\n", ha);
2017 /* Clear our data area */
2019 ha->mem_only = mem_only;
2020 spin_lock_init(&ha->hardware_lock);
2021 spin_lock_init(&ha->vport_slock);
2023 /* Set ISP-type information. */
2024 qla2x00_set_isp_flags(ha);
2026 /* Set EEH reset type to fundamental if required by hba */
2027 if ( IS_QLA24XX(ha) || IS_QLA25XX(ha) || IS_QLA81XX(ha)) {
2028 pdev->needs_freset = 1;
2031 ha->prev_topology = 0;
2032 ha->init_cb_size = sizeof(init_cb_t);
2033 ha->link_data_rate = PORT_SPEED_UNKNOWN;
2034 ha->optrom_size = OPTROM_SIZE_2300;
2036 /* Assign ISP specific operations. */
2037 max_id = MAX_TARGETS_2200;
2038 if (IS_QLA2100(ha)) {
2039 max_id = MAX_TARGETS_2100;
2040 ha->mbx_count = MAILBOX_REGISTER_COUNT_2100;
2041 req_length = REQUEST_ENTRY_CNT_2100;
2042 rsp_length = RESPONSE_ENTRY_CNT_2100;
2043 ha->max_loop_id = SNS_LAST_LOOP_ID_2100;
2044 ha->gid_list_info_size = 4;
2045 ha->flash_conf_off = ~0;
2046 ha->flash_data_off = ~0;
2047 ha->nvram_conf_off = ~0;
2048 ha->nvram_data_off = ~0;
2049 ha->isp_ops = &qla2100_isp_ops;
2050 } else if (IS_QLA2200(ha)) {
2051 ha->mbx_count = MAILBOX_REGISTER_COUNT;
2052 req_length = REQUEST_ENTRY_CNT_2200;
2053 rsp_length = RESPONSE_ENTRY_CNT_2100;
2054 ha->max_loop_id = SNS_LAST_LOOP_ID_2100;
2055 ha->gid_list_info_size = 4;
2056 ha->flash_conf_off = ~0;
2057 ha->flash_data_off = ~0;
2058 ha->nvram_conf_off = ~0;
2059 ha->nvram_data_off = ~0;
2060 ha->isp_ops = &qla2100_isp_ops;
2061 } else if (IS_QLA23XX(ha)) {
2062 ha->mbx_count = MAILBOX_REGISTER_COUNT;
2063 req_length = REQUEST_ENTRY_CNT_2200;
2064 rsp_length = RESPONSE_ENTRY_CNT_2300;
2065 ha->max_loop_id = SNS_LAST_LOOP_ID_2300;
2066 ha->gid_list_info_size = 6;
2067 if (IS_QLA2322(ha) || IS_QLA6322(ha))
2068 ha->optrom_size = OPTROM_SIZE_2322;
2069 ha->flash_conf_off = ~0;
2070 ha->flash_data_off = ~0;
2071 ha->nvram_conf_off = ~0;
2072 ha->nvram_data_off = ~0;
2073 ha->isp_ops = &qla2300_isp_ops;
2074 } else if (IS_QLA24XX_TYPE(ha)) {
2075 ha->mbx_count = MAILBOX_REGISTER_COUNT;
2076 req_length = REQUEST_ENTRY_CNT_24XX;
2077 rsp_length = RESPONSE_ENTRY_CNT_2300;
2078 ha->max_loop_id = SNS_LAST_LOOP_ID_2300;
2079 ha->init_cb_size = sizeof(struct mid_init_cb_24xx);
2080 ha->gid_list_info_size = 8;
2081 ha->optrom_size = OPTROM_SIZE_24XX;
2082 ha->nvram_npiv_size = QLA_MAX_VPORTS_QLA24XX;
2083 ha->isp_ops = &qla24xx_isp_ops;
2084 ha->flash_conf_off = FARX_ACCESS_FLASH_CONF;
2085 ha->flash_data_off = FARX_ACCESS_FLASH_DATA;
2086 ha->nvram_conf_off = FARX_ACCESS_NVRAM_CONF;
2087 ha->nvram_data_off = FARX_ACCESS_NVRAM_DATA;
2088 } else if (IS_QLA25XX(ha)) {
2089 ha->mbx_count = MAILBOX_REGISTER_COUNT;
2090 req_length = REQUEST_ENTRY_CNT_24XX;
2091 rsp_length = RESPONSE_ENTRY_CNT_2300;
2092 ha->max_loop_id = SNS_LAST_LOOP_ID_2300;
2093 ha->init_cb_size = sizeof(struct mid_init_cb_24xx);
2094 ha->gid_list_info_size = 8;
2095 ha->optrom_size = OPTROM_SIZE_25XX;
2096 ha->nvram_npiv_size = QLA_MAX_VPORTS_QLA25XX;
2097 ha->isp_ops = &qla25xx_isp_ops;
2098 ha->flash_conf_off = FARX_ACCESS_FLASH_CONF;
2099 ha->flash_data_off = FARX_ACCESS_FLASH_DATA;
2100 ha->nvram_conf_off = FARX_ACCESS_NVRAM_CONF;
2101 ha->nvram_data_off = FARX_ACCESS_NVRAM_DATA;
2102 } else if (IS_QLA81XX(ha)) {
2103 ha->mbx_count = MAILBOX_REGISTER_COUNT;
2104 req_length = REQUEST_ENTRY_CNT_24XX;
2105 rsp_length = RESPONSE_ENTRY_CNT_2300;
2106 ha->max_loop_id = SNS_LAST_LOOP_ID_2300;
2107 ha->init_cb_size = sizeof(struct mid_init_cb_81xx);
2108 ha->gid_list_info_size = 8;
2109 ha->optrom_size = OPTROM_SIZE_81XX;
2110 ha->nvram_npiv_size = QLA_MAX_VPORTS_QLA25XX;
2111 ha->isp_ops = &qla81xx_isp_ops;
2112 ha->flash_conf_off = FARX_ACCESS_FLASH_CONF_81XX;
2113 ha->flash_data_off = FARX_ACCESS_FLASH_DATA_81XX;
2114 ha->nvram_conf_off = ~0;
2115 ha->nvram_data_off = ~0;
2116 } else if (IS_QLA82XX(ha)) {
2117 ha->mbx_count = MAILBOX_REGISTER_COUNT;
2118 req_length = REQUEST_ENTRY_CNT_82XX;
2119 rsp_length = RESPONSE_ENTRY_CNT_82XX;
2120 ha->max_loop_id = SNS_LAST_LOOP_ID_2300;
2121 ha->init_cb_size = sizeof(struct mid_init_cb_81xx);
2122 ha->gid_list_info_size = 8;
2123 ha->optrom_size = OPTROM_SIZE_82XX;
2124 ha->nvram_npiv_size = QLA_MAX_VPORTS_QLA25XX;
2125 ha->isp_ops = &qla82xx_isp_ops;
2126 ha->flash_conf_off = FARX_ACCESS_FLASH_CONF;
2127 ha->flash_data_off = FARX_ACCESS_FLASH_DATA;
2128 ha->nvram_conf_off = FARX_ACCESS_NVRAM_CONF;
2129 ha->nvram_data_off = FARX_ACCESS_NVRAM_DATA;
2131 ql_dbg_pci(ql_dbg_init, pdev, 0x001e,
2132 "mbx_count=%d, req_length=%d, "
2133 "rsp_length=%d, max_loop_id=%d, init_cb_size=%d, "
2134 "gid_list_info_size=%d, optrom_size=%d, nvram_npiv_size=%d, .\n",
2135 ha->mbx_count, req_length, rsp_length, ha->max_loop_id,
2136 ha->init_cb_size, ha->gid_list_info_size, ha->optrom_size,
2137 ha->nvram_npiv_size);
2138 ql_dbg_pci(ql_dbg_init, pdev, 0x001f,
2139 "isp_ops=%p, flash_conf_off=%d, "
2140 "flash_data_off=%d, nvram_conf_off=%d, nvram_data_off=%d.\n",
2141 ha->isp_ops, ha->flash_conf_off, ha->flash_data_off,
2142 ha->nvram_conf_off, ha->nvram_data_off);
2144 /* Configure PCI I/O space */
2145 ret = ha->isp_ops->iospace_config(ha);
2147 goto probe_hw_failed;
2149 ql_log_pci(ql_log_info, pdev, 0x001d,
2150 "Found an ISP%04X irq %d iobase 0x%p.\n",
2151 pdev->device, pdev->irq, ha->iobase);
2152 mutex_init(&ha->vport_lock);
2153 init_completion(&ha->mbx_cmd_comp);
2154 complete(&ha->mbx_cmd_comp);
2155 init_completion(&ha->mbx_intr_comp);
2156 init_completion(&ha->dcbx_comp);
2158 set_bit(0, (unsigned long *) ha->vp_idx_map);
2160 qla2x00_config_dma_addressing(ha);
2161 ql_dbg_pci(ql_dbg_init, pdev, 0x0020,
2162 "64 Bit addressing is %s.\n",
2163 ha->flags.enable_64bit_addressing ? "enable" :
2165 ret = qla2x00_mem_alloc(ha, req_length, rsp_length, &req, &rsp);
2167 ql_log_pci(ql_log_fatal, pdev, 0x0031,
2168 "Failed to allocate memory for adapter, aborting.\n");
2170 goto probe_hw_failed;
2173 req->max_q_depth = MAX_Q_DEPTH;
2174 if (ql2xmaxqdepth != 0 && ql2xmaxqdepth <= 0xffffU)
2175 req->max_q_depth = ql2xmaxqdepth;
2178 base_vha = qla2x00_create_host(sht, ha);
2181 qla2x00_mem_free(ha);
2182 qla2x00_free_req_que(ha, req);
2183 qla2x00_free_rsp_que(ha, rsp);
2184 goto probe_hw_failed;
2187 pci_set_drvdata(pdev, base_vha);
2189 host = base_vha->host;
2190 base_vha->req = req;
2191 host->can_queue = req->length + 128;
2192 if (IS_QLA2XXX_MIDTYPE(ha))
2193 base_vha->mgmt_svr_loop_id = 10 + base_vha->vp_idx;
2195 base_vha->mgmt_svr_loop_id = MANAGEMENT_SERVER +
2198 /* Set the SG table size based on ISP type */
2199 if (!IS_FWI2_CAPABLE(ha)) {
2201 host->sg_tablesize = 32;
2203 if (!IS_QLA82XX(ha))
2204 host->sg_tablesize = QLA_SG_ALL;
2206 ql_dbg(ql_dbg_init, base_vha, 0x0032,
2207 "can_queue=%d, req=%p, "
2208 "mgmt_svr_loop_id=%d, sg_tablesize=%d.\n",
2209 host->can_queue, base_vha->req,
2210 base_vha->mgmt_svr_loop_id, host->sg_tablesize);
2211 host->max_id = max_id;
2212 host->this_id = 255;
2213 host->cmd_per_lun = 3;
2214 host->unique_id = host->host_no;
2215 if (IS_T10_PI_CAPABLE(ha) && ql2xenabledif)
2216 host->max_cmd_len = 32;
2218 host->max_cmd_len = MAX_CMDSZ;
2219 host->max_channel = MAX_BUSES - 1;
2220 host->max_lun = ql2xmaxlun;
2221 host->transportt = qla2xxx_transport_template;
2222 sht->vendor_id = (SCSI_NL_VID_TYPE_PCI | PCI_VENDOR_ID_QLOGIC);
2224 ql_dbg(ql_dbg_init, base_vha, 0x0033,
2225 "max_id=%d this_id=%d "
2226 "cmd_per_len=%d unique_id=%d max_cmd_len=%d max_channel=%d "
2227 "max_lun=%d transportt=%p, vendor_id=%llu.\n", host->max_id,
2228 host->this_id, host->cmd_per_lun, host->unique_id,
2229 host->max_cmd_len, host->max_channel, host->max_lun,
2230 host->transportt, sht->vendor_id);
2232 /* Set up the irqs */
2233 ret = qla2x00_request_irqs(ha, rsp);
2235 goto probe_init_failed;
2237 pci_save_state(pdev);
2239 /* Alloc arrays of request and response ring ptrs */
2241 if (!qla2x00_alloc_queues(ha)) {
2242 ql_log(ql_log_fatal, base_vha, 0x003d,
2243 "Failed to allocate memory for queue pointers.. aborting.\n");
2244 goto probe_init_failed;
2247 ha->rsp_q_map[0] = rsp;
2248 ha->req_q_map[0] = req;
2251 set_bit(0, ha->req_qid_map);
2252 set_bit(0, ha->rsp_qid_map);
2253 /* FWI2-capable only. */
2254 req->req_q_in = &ha->iobase->isp24.req_q_in;
2255 req->req_q_out = &ha->iobase->isp24.req_q_out;
2256 rsp->rsp_q_in = &ha->iobase->isp24.rsp_q_in;
2257 rsp->rsp_q_out = &ha->iobase->isp24.rsp_q_out;
2259 req->req_q_in = &ha->mqiobase->isp25mq.req_q_in;
2260 req->req_q_out = &ha->mqiobase->isp25mq.req_q_out;
2261 rsp->rsp_q_in = &ha->mqiobase->isp25mq.rsp_q_in;
2262 rsp->rsp_q_out = &ha->mqiobase->isp25mq.rsp_q_out;
2265 if (IS_QLA82XX(ha)) {
2266 req->req_q_out = &ha->iobase->isp82.req_q_out[0];
2267 rsp->rsp_q_in = &ha->iobase->isp82.rsp_q_in[0];
2268 rsp->rsp_q_out = &ha->iobase->isp82.rsp_q_out[0];
2271 ql_dbg(ql_dbg_multiq, base_vha, 0xc009,
2272 "rsp_q_map=%p req_q_map=%p rsp->req=%p req->rsp=%p.\n",
2273 ha->rsp_q_map, ha->req_q_map, rsp->req, req->rsp);
2274 ql_dbg(ql_dbg_multiq, base_vha, 0xc00a,
2275 "req->req_q_in=%p req->req_q_out=%p "
2276 "rsp->rsp_q_in=%p rsp->rsp_q_out=%p.\n",
2277 req->req_q_in, req->req_q_out,
2278 rsp->rsp_q_in, rsp->rsp_q_out);
2279 ql_dbg(ql_dbg_init, base_vha, 0x003e,
2280 "rsp_q_map=%p req_q_map=%p rsp->req=%p req->rsp=%p.\n",
2281 ha->rsp_q_map, ha->req_q_map, rsp->req, req->rsp);
2282 ql_dbg(ql_dbg_init, base_vha, 0x003f,
2283 "req->req_q_in=%p req->req_q_out=%p rsp->rsp_q_in=%p rsp->rsp_q_out=%p.\n",
2284 req->req_q_in, req->req_q_out, rsp->rsp_q_in, rsp->rsp_q_out);
2286 if (qla2x00_initialize_adapter(base_vha)) {
2287 ql_log(ql_log_fatal, base_vha, 0x00d6,
2288 "Failed to initialize adapter - Adapter flags %x.\n",
2289 base_vha->device_flags);
2291 if (IS_QLA82XX(ha)) {
2292 qla82xx_idc_lock(ha);
2293 qla82xx_wr_32(ha, QLA82XX_CRB_DEV_STATE,
2294 QLA82XX_DEV_FAILED);
2295 qla82xx_idc_unlock(ha);
2296 ql_log(ql_log_fatal, base_vha, 0x00d7,
2297 "HW State: FAILED.\n");
2305 if (qla25xx_setup_mode(base_vha)) {
2306 ql_log(ql_log_warn, base_vha, 0x00ec,
2307 "Failed to create queues, falling back to single queue mode.\n");
2312 if (ha->flags.running_gold_fw)
2316 * Startup the kernel thread for this host adapter
2318 ha->dpc_thread = kthread_create(qla2x00_do_dpc, ha,
2319 "%s_dpc", base_vha->host_str);
2320 if (IS_ERR(ha->dpc_thread)) {
2321 ql_log(ql_log_fatal, base_vha, 0x00ed,
2322 "Failed to start DPC thread.\n");
2323 ret = PTR_ERR(ha->dpc_thread);
2326 ql_dbg(ql_dbg_init, base_vha, 0x00ee,
2327 "DPC thread started successfully.\n");
2330 list_add_tail(&base_vha->list, &ha->vp_list);
2331 base_vha->host->irq = ha->pdev->irq;
2333 /* Initialized the timer */
2334 qla2x00_start_timer(base_vha, qla2x00_timer, WATCH_INTERVAL);
2335 ql_dbg(ql_dbg_init, base_vha, 0x00ef,
2336 "Started qla2x00_timer with "
2337 "interval=%d.\n", WATCH_INTERVAL);
2338 ql_dbg(ql_dbg_init, base_vha, 0x00f0,
2339 "Detected hba at address=%p.\n",
2342 if (IS_T10_PI_CAPABLE(ha) && ql2xenabledif) {
2343 if (ha->fw_attributes & BIT_4) {
2345 base_vha->flags.difdix_supported = 1;
2346 ql_dbg(ql_dbg_init, base_vha, 0x00f1,
2347 "Registering for DIF/DIX type 1 and 3 protection.\n");
2348 if (ql2xenabledif == 1)
2349 prot = SHOST_DIX_TYPE0_PROTECTION;
2350 scsi_host_set_prot(host,
2351 prot | SHOST_DIF_TYPE1_PROTECTION
2352 | SHOST_DIF_TYPE2_PROTECTION
2353 | SHOST_DIF_TYPE3_PROTECTION
2354 | SHOST_DIX_TYPE1_PROTECTION
2355 | SHOST_DIX_TYPE2_PROTECTION
2356 | SHOST_DIX_TYPE3_PROTECTION);
2357 scsi_host_set_guard(host, SHOST_DIX_GUARD_CRC);
2359 base_vha->flags.difdix_supported = 0;
2362 ha->isp_ops->enable_intrs(ha);
2364 ret = scsi_add_host(host, &pdev->dev);
2368 base_vha->flags.init_done = 1;
2369 base_vha->flags.online = 1;
2371 ql_dbg(ql_dbg_init, base_vha, 0x00f2,
2372 "Init done and hba is online.\n");
2374 scsi_scan_host(host);
2376 qla2x00_alloc_sysfs_attr(base_vha);
2378 qla2x00_init_host_attr(base_vha);
2380 qla2x00_dfs_setup(base_vha);
2382 ql_log(ql_log_info, base_vha, 0x00fb,
2383 "QLogic %s - %s.\n",
2384 ha->model_number, ha->model_desc ? ha->model_desc : "");
2385 ql_log(ql_log_info, base_vha, 0x00fc,
2386 "ISP%04X: %s @ %s hdma%c host#=%ld fw=%s.\n",
2387 pdev->device, ha->isp_ops->pci_info_str(base_vha, pci_info),
2388 pci_name(pdev), ha->flags.enable_64bit_addressing ? '+' : '-',
2390 ha->isp_ops->fw_version_str(base_vha, fw_str));
2395 qla2x00_free_req_que(ha, req);
2396 qla2x00_free_rsp_que(ha, rsp);
2397 ha->max_req_queues = ha->max_rsp_queues = 0;
2400 if (base_vha->timer_active)
2401 qla2x00_stop_timer(base_vha);
2402 base_vha->flags.online = 0;
2403 if (ha->dpc_thread) {
2404 struct task_struct *t = ha->dpc_thread;
2406 ha->dpc_thread = NULL;
2410 qla2x00_free_device(base_vha);
2412 scsi_host_put(base_vha->host);
2415 if (IS_QLA82XX(ha)) {
2416 qla82xx_idc_lock(ha);
2417 qla82xx_clear_drv_active(ha);
2418 qla82xx_idc_unlock(ha);
2419 iounmap((device_reg_t __iomem *)ha->nx_pcibase);
2421 iounmap((device_reg_t __iomem *)ha->nxdb_wr_ptr);
2424 iounmap(ha->iobase);
2426 pci_release_selected_regions(ha->pdev, ha->bars);
2431 pci_disable_device(pdev);
2436 qla2x00_shutdown(struct pci_dev *pdev)
2438 scsi_qla_host_t *vha;
2439 struct qla_hw_data *ha;
2441 vha = pci_get_drvdata(pdev);
2444 /* Turn-off FCE trace */
2445 if (ha->flags.fce_enabled) {
2446 qla2x00_disable_fce_trace(vha, NULL, NULL);
2447 ha->flags.fce_enabled = 0;
2450 /* Turn-off EFT trace */
2452 qla2x00_disable_eft_trace(vha);
2454 /* Stop currently executing firmware. */
2455 qla2x00_try_to_stop_firmware(vha);
2457 /* Turn adapter off line */
2458 vha->flags.online = 0;
2460 /* turn-off interrupts on the card */
2461 if (ha->interrupts_on) {
2462 vha->flags.init_done = 0;
2463 ha->isp_ops->disable_intrs(ha);
2466 qla2x00_free_irqs(vha);
2468 qla2x00_free_fw_dump(ha);
2472 qla2x00_remove_one(struct pci_dev *pdev)
2474 scsi_qla_host_t *base_vha, *vha;
2475 struct qla_hw_data *ha;
2476 unsigned long flags;
2478 base_vha = pci_get_drvdata(pdev);
2481 mutex_lock(&ha->vport_lock);
2482 while (ha->cur_vport_count) {
2483 struct Scsi_Host *scsi_host;
2485 spin_lock_irqsave(&ha->vport_slock, flags);
2487 BUG_ON(base_vha->list.next == &ha->vp_list);
2488 /* This assumes first entry in ha->vp_list is always base vha */
2489 vha = list_first_entry(&base_vha->list, scsi_qla_host_t, list);
2490 scsi_host = scsi_host_get(vha->host);
2492 spin_unlock_irqrestore(&ha->vport_slock, flags);
2493 mutex_unlock(&ha->vport_lock);
2495 fc_vport_terminate(vha->fc_vport);
2496 scsi_host_put(vha->host);
2498 mutex_lock(&ha->vport_lock);
2500 mutex_unlock(&ha->vport_lock);
2502 set_bit(UNLOADING, &base_vha->dpc_flags);
2504 qla2x00_abort_all_cmds(base_vha, DID_NO_CONNECT << 16);
2506 qla2x00_dfs_remove(base_vha);
2508 qla84xx_put_chip(base_vha);
2511 if (base_vha->timer_active)
2512 qla2x00_stop_timer(base_vha);
2514 base_vha->flags.online = 0;
2516 /* Flush the work queue and remove it */
2518 flush_workqueue(ha->wq);
2519 destroy_workqueue(ha->wq);
2523 /* Kill the kernel thread for this host */
2524 if (ha->dpc_thread) {
2525 struct task_struct *t = ha->dpc_thread;
2528 * qla2xxx_wake_dpc checks for ->dpc_thread
2529 * so we need to zero it out.
2531 ha->dpc_thread = NULL;
2535 qla2x00_free_sysfs_attr(base_vha);
2537 fc_remove_host(base_vha->host);
2539 scsi_remove_host(base_vha->host);
2541 qla2x00_free_device(base_vha);
2543 scsi_host_put(base_vha->host);
2545 if (IS_QLA82XX(ha)) {
2546 qla82xx_idc_lock(ha);
2547 qla82xx_clear_drv_active(ha);
2548 qla82xx_idc_unlock(ha);
2550 iounmap((device_reg_t __iomem *)ha->nx_pcibase);
2552 iounmap((device_reg_t __iomem *)ha->nxdb_wr_ptr);
2555 iounmap(ha->iobase);
2558 iounmap(ha->mqiobase);
2561 pci_release_selected_regions(ha->pdev, ha->bars);
2565 pci_disable_pcie_error_reporting(pdev);
2567 pci_disable_device(pdev);
2568 pci_set_drvdata(pdev, NULL);
2572 qla2x00_free_device(scsi_qla_host_t *vha)
2574 struct qla_hw_data *ha = vha->hw;
2576 qla2x00_abort_all_cmds(vha, DID_NO_CONNECT << 16);
2579 if (vha->timer_active)
2580 qla2x00_stop_timer(vha);
2582 /* Kill the kernel thread for this host */
2583 if (ha->dpc_thread) {
2584 struct task_struct *t = ha->dpc_thread;
2587 * qla2xxx_wake_dpc checks for ->dpc_thread
2588 * so we need to zero it out.
2590 ha->dpc_thread = NULL;
2594 qla25xx_delete_queues(vha);
2596 if (ha->flags.fce_enabled)
2597 qla2x00_disable_fce_trace(vha, NULL, NULL);
2600 qla2x00_disable_eft_trace(vha);
2602 /* Stop currently executing firmware. */
2603 qla2x00_try_to_stop_firmware(vha);
2605 vha->flags.online = 0;
2607 /* turn-off interrupts on the card */
2608 if (ha->interrupts_on) {
2609 vha->flags.init_done = 0;
2610 ha->isp_ops->disable_intrs(ha);
2613 qla2x00_free_irqs(vha);
2615 qla2x00_free_fcports(vha);
2617 qla2x00_mem_free(ha);
2619 qla82xx_md_free(vha);
2621 qla2x00_free_queues(ha);
2624 void qla2x00_free_fcports(struct scsi_qla_host *vha)
2626 fc_port_t *fcport, *tfcport;
2628 list_for_each_entry_safe(fcport, tfcport, &vha->vp_fcports, list) {
2629 list_del(&fcport->list);
2636 qla2x00_schedule_rport_del(struct scsi_qla_host *vha, fc_port_t *fcport,
2639 struct fc_rport *rport;
2640 scsi_qla_host_t *base_vha;
2641 unsigned long flags;
2646 rport = fcport->rport;
2648 base_vha = pci_get_drvdata(vha->hw->pdev);
2649 spin_lock_irqsave(vha->host->host_lock, flags);
2650 fcport->drport = rport;
2651 spin_unlock_irqrestore(vha->host->host_lock, flags);
2652 set_bit(FCPORT_UPDATE_NEEDED, &base_vha->dpc_flags);
2653 qla2xxx_wake_dpc(base_vha);
2655 fc_remote_port_delete(rport);
2659 * qla2x00_mark_device_lost Updates fcport state when device goes offline.
2661 * Input: ha = adapter block pointer. fcport = port structure pointer.
2667 void qla2x00_mark_device_lost(scsi_qla_host_t *vha, fc_port_t *fcport,
2668 int do_login, int defer)
2670 if (atomic_read(&fcport->state) == FCS_ONLINE &&
2671 vha->vp_idx == fcport->vp_idx) {
2672 qla2x00_set_fcport_state(fcport, FCS_DEVICE_LOST);
2673 qla2x00_schedule_rport_del(vha, fcport, defer);
2676 * We may need to retry the login, so don't change the state of the
2677 * port but do the retries.
2679 if (atomic_read(&fcport->state) != FCS_DEVICE_DEAD)
2680 qla2x00_set_fcport_state(fcport, FCS_DEVICE_LOST);
2685 if (fcport->login_retry == 0) {
2686 fcport->login_retry = vha->hw->login_retry_count;
2687 set_bit(RELOGIN_NEEDED, &vha->dpc_flags);
2689 ql_dbg(ql_dbg_disc, vha, 0x2067,
2691 "%02x%02x%02x%02x%02x%02x%02x%02x, "
2692 "id = 0x%04x retry cnt=%d.\n",
2693 fcport->port_name[0], fcport->port_name[1],
2694 fcport->port_name[2], fcport->port_name[3],
2695 fcport->port_name[4], fcport->port_name[5],
2696 fcport->port_name[6], fcport->port_name[7],
2697 fcport->loop_id, fcport->login_retry);
2702 * qla2x00_mark_all_devices_lost
2703 * Updates fcport state when device goes offline.
2706 * ha = adapter block pointer.
2707 * fcport = port structure pointer.
2715 qla2x00_mark_all_devices_lost(scsi_qla_host_t *vha, int defer)
2719 list_for_each_entry(fcport, &vha->vp_fcports, list) {
2720 if (vha->vp_idx != 0 && vha->vp_idx != fcport->vp_idx)
2724 * No point in marking the device as lost, if the device is
2727 if (atomic_read(&fcport->state) == FCS_DEVICE_DEAD)
2729 if (atomic_read(&fcport->state) == FCS_ONLINE) {
2730 qla2x00_set_fcport_state(fcport, FCS_DEVICE_LOST);
2732 qla2x00_schedule_rport_del(vha, fcport, defer);
2733 else if (vha->vp_idx == fcport->vp_idx)
2734 qla2x00_schedule_rport_del(vha, fcport, defer);
2741 * Allocates adapter memory.
2748 qla2x00_mem_alloc(struct qla_hw_data *ha, uint16_t req_len, uint16_t rsp_len,
2749 struct req_que **req, struct rsp_que **rsp)
2753 ha->init_cb = dma_alloc_coherent(&ha->pdev->dev, ha->init_cb_size,
2754 &ha->init_cb_dma, GFP_KERNEL);
2758 ha->gid_list = dma_alloc_coherent(&ha->pdev->dev, GID_LIST_SIZE,
2759 &ha->gid_list_dma, GFP_KERNEL);
2761 goto fail_free_init_cb;
2763 ha->srb_mempool = mempool_create_slab_pool(SRB_MIN_REQ, srb_cachep);
2764 if (!ha->srb_mempool)
2765 goto fail_free_gid_list;
2767 if (IS_QLA82XX(ha)) {
2768 /* Allocate cache for CT6 Ctx. */
2770 ctx_cachep = kmem_cache_create("qla2xxx_ctx",
2771 sizeof(struct ct6_dsd), 0,
2772 SLAB_HWCACHE_ALIGN, NULL);
2774 goto fail_free_gid_list;
2776 ha->ctx_mempool = mempool_create_slab_pool(SRB_MIN_REQ,
2778 if (!ha->ctx_mempool)
2779 goto fail_free_srb_mempool;
2780 ql_dbg_pci(ql_dbg_init, ha->pdev, 0x0021,
2781 "ctx_cachep=%p ctx_mempool=%p.\n",
2782 ctx_cachep, ha->ctx_mempool);
2785 /* Get memory for cached NVRAM */
2786 ha->nvram = kzalloc(MAX_NVRAM_SIZE, GFP_KERNEL);
2788 goto fail_free_ctx_mempool;
2790 snprintf(name, sizeof(name), "%s_%d", QLA2XXX_DRIVER_NAME,
2792 ha->s_dma_pool = dma_pool_create(name, &ha->pdev->dev,
2793 DMA_POOL_SIZE, 8, 0);
2794 if (!ha->s_dma_pool)
2795 goto fail_free_nvram;
2797 ql_dbg_pci(ql_dbg_init, ha->pdev, 0x0022,
2798 "init_cb=%p gid_list=%p, srb_mempool=%p s_dma_pool=%p.\n",
2799 ha->init_cb, ha->gid_list, ha->srb_mempool, ha->s_dma_pool);
2801 if (IS_QLA82XX(ha) || ql2xenabledif) {
2802 ha->dl_dma_pool = dma_pool_create(name, &ha->pdev->dev,
2803 DSD_LIST_DMA_POOL_SIZE, 8, 0);
2804 if (!ha->dl_dma_pool) {
2805 ql_log_pci(ql_log_fatal, ha->pdev, 0x0023,
2806 "Failed to allocate memory for dl_dma_pool.\n");
2807 goto fail_s_dma_pool;
2810 ha->fcp_cmnd_dma_pool = dma_pool_create(name, &ha->pdev->dev,
2811 FCP_CMND_DMA_POOL_SIZE, 8, 0);
2812 if (!ha->fcp_cmnd_dma_pool) {
2813 ql_log_pci(ql_log_fatal, ha->pdev, 0x0024,
2814 "Failed to allocate memory for fcp_cmnd_dma_pool.\n");
2815 goto fail_dl_dma_pool;
2817 ql_dbg_pci(ql_dbg_init, ha->pdev, 0x0025,
2818 "dl_dma_pool=%p fcp_cmnd_dma_pool=%p.\n",
2819 ha->dl_dma_pool, ha->fcp_cmnd_dma_pool);
2822 /* Allocate memory for SNS commands */
2823 if (IS_QLA2100(ha) || IS_QLA2200(ha)) {
2824 /* Get consistent memory allocated for SNS commands */
2825 ha->sns_cmd = dma_alloc_coherent(&ha->pdev->dev,
2826 sizeof(struct sns_cmd_pkt), &ha->sns_cmd_dma, GFP_KERNEL);
2829 ql_dbg_pci(ql_dbg_init, ha->pdev, 0x0026,
2830 "sns_cmd: %p.\n", ha->sns_cmd);
2832 /* Get consistent memory allocated for MS IOCB */
2833 ha->ms_iocb = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL,
2837 /* Get consistent memory allocated for CT SNS commands */
2838 ha->ct_sns = dma_alloc_coherent(&ha->pdev->dev,
2839 sizeof(struct ct_sns_pkt), &ha->ct_sns_dma, GFP_KERNEL);
2841 goto fail_free_ms_iocb;
2842 ql_dbg_pci(ql_dbg_init, ha->pdev, 0x0027,
2843 "ms_iocb=%p ct_sns=%p.\n",
2844 ha->ms_iocb, ha->ct_sns);
2847 /* Allocate memory for request ring */
2848 *req = kzalloc(sizeof(struct req_que), GFP_KERNEL);
2850 ql_log_pci(ql_log_fatal, ha->pdev, 0x0028,
2851 "Failed to allocate memory for req.\n");
2854 (*req)->length = req_len;
2855 (*req)->ring = dma_alloc_coherent(&ha->pdev->dev,
2856 ((*req)->length + 1) * sizeof(request_t),
2857 &(*req)->dma, GFP_KERNEL);
2858 if (!(*req)->ring) {
2859 ql_log_pci(ql_log_fatal, ha->pdev, 0x0029,
2860 "Failed to allocate memory for req_ring.\n");
2863 /* Allocate memory for response ring */
2864 *rsp = kzalloc(sizeof(struct rsp_que), GFP_KERNEL);
2866 ql_log_pci(ql_log_fatal, ha->pdev, 0x002a,
2867 "Failed to allocate memory for rsp.\n");
2871 (*rsp)->length = rsp_len;
2872 (*rsp)->ring = dma_alloc_coherent(&ha->pdev->dev,
2873 ((*rsp)->length + 1) * sizeof(response_t),
2874 &(*rsp)->dma, GFP_KERNEL);
2875 if (!(*rsp)->ring) {
2876 ql_log_pci(ql_log_fatal, ha->pdev, 0x002b,
2877 "Failed to allocate memory for rsp_ring.\n");
2882 ql_dbg_pci(ql_dbg_init, ha->pdev, 0x002c,
2883 "req=%p req->length=%d req->ring=%p rsp=%p "
2884 "rsp->length=%d rsp->ring=%p.\n",
2885 *req, (*req)->length, (*req)->ring, *rsp, (*rsp)->length,
2887 /* Allocate memory for NVRAM data for vports */
2888 if (ha->nvram_npiv_size) {
2889 ha->npiv_info = kzalloc(sizeof(struct qla_npiv_entry) *
2890 ha->nvram_npiv_size, GFP_KERNEL);
2891 if (!ha->npiv_info) {
2892 ql_log_pci(ql_log_fatal, ha->pdev, 0x002d,
2893 "Failed to allocate memory for npiv_info.\n");
2894 goto fail_npiv_info;
2897 ha->npiv_info = NULL;
2899 /* Get consistent memory allocated for EX-INIT-CB. */
2900 if (IS_QLA8XXX_TYPE(ha)) {
2901 ha->ex_init_cb = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL,
2902 &ha->ex_init_cb_dma);
2903 if (!ha->ex_init_cb)
2904 goto fail_ex_init_cb;
2905 ql_dbg_pci(ql_dbg_init, ha->pdev, 0x002e,
2906 "ex_init_cb=%p.\n", ha->ex_init_cb);
2909 INIT_LIST_HEAD(&ha->gbl_dsd_list);
2911 /* Get consistent memory allocated for Async Port-Database. */
2912 if (!IS_FWI2_CAPABLE(ha)) {
2913 ha->async_pd = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL,
2917 ql_dbg_pci(ql_dbg_init, ha->pdev, 0x002f,
2918 "async_pd=%p.\n", ha->async_pd);
2921 INIT_LIST_HEAD(&ha->vp_list);
2925 dma_pool_free(ha->s_dma_pool, ha->ex_init_cb, ha->ex_init_cb_dma);
2927 kfree(ha->npiv_info);
2929 dma_free_coherent(&ha->pdev->dev, ((*rsp)->length + 1) *
2930 sizeof(response_t), (*rsp)->ring, (*rsp)->dma);
2931 (*rsp)->ring = NULL;
2936 dma_free_coherent(&ha->pdev->dev, ((*req)->length + 1) *
2937 sizeof(request_t), (*req)->ring, (*req)->dma);
2938 (*req)->ring = NULL;
2943 dma_free_coherent(&ha->pdev->dev, sizeof(struct ct_sns_pkt),
2944 ha->ct_sns, ha->ct_sns_dma);
2948 dma_pool_free(ha->s_dma_pool, ha->ms_iocb, ha->ms_iocb_dma);
2950 ha->ms_iocb_dma = 0;
2952 if (IS_QLA82XX(ha) || ql2xenabledif) {
2953 dma_pool_destroy(ha->fcp_cmnd_dma_pool);
2954 ha->fcp_cmnd_dma_pool = NULL;
2957 if (IS_QLA82XX(ha) || ql2xenabledif) {
2958 dma_pool_destroy(ha->dl_dma_pool);
2959 ha->dl_dma_pool = NULL;
2962 dma_pool_destroy(ha->s_dma_pool);
2963 ha->s_dma_pool = NULL;
2967 fail_free_ctx_mempool:
2968 mempool_destroy(ha->ctx_mempool);
2969 ha->ctx_mempool = NULL;
2970 fail_free_srb_mempool:
2971 mempool_destroy(ha->srb_mempool);
2972 ha->srb_mempool = NULL;
2974 dma_free_coherent(&ha->pdev->dev, GID_LIST_SIZE, ha->gid_list,
2976 ha->gid_list = NULL;
2977 ha->gid_list_dma = 0;
2979 dma_free_coherent(&ha->pdev->dev, ha->init_cb_size, ha->init_cb,
2982 ha->init_cb_dma = 0;
2984 ql_log(ql_log_fatal, NULL, 0x0030,
2985 "Memory allocation failure.\n");
2990 * qla2x00_free_fw_dump
2991 * Frees fw dump stuff.
2994 * ha = adapter block pointer.
2997 qla2x00_free_fw_dump(struct qla_hw_data *ha)
3000 dma_free_coherent(&ha->pdev->dev, FCE_SIZE, ha->fce,
3005 dma_free_coherent(&ha->pdev->dev,
3006 ntohl(ha->fw_dump->eft_size), ha->eft, ha->eft_dma);
3015 ha->fw_dump_reading = 0;
3020 * Frees all adapter allocated memory.
3023 * ha = adapter block pointer.
3026 qla2x00_mem_free(struct qla_hw_data *ha)
3028 qla2x00_free_fw_dump(ha);
3030 if (ha->srb_mempool)
3031 mempool_destroy(ha->srb_mempool);
3034 dma_free_coherent(&ha->pdev->dev, DCBX_TLV_DATA_SIZE,
3035 ha->dcbx_tlv, ha->dcbx_tlv_dma);
3038 dma_free_coherent(&ha->pdev->dev, XGMAC_DATA_SIZE,
3039 ha->xgmac_data, ha->xgmac_data_dma);
3042 dma_free_coherent(&ha->pdev->dev, sizeof(struct sns_cmd_pkt),
3043 ha->sns_cmd, ha->sns_cmd_dma);
3046 dma_free_coherent(&ha->pdev->dev, sizeof(struct ct_sns_pkt),
3047 ha->ct_sns, ha->ct_sns_dma);
3050 dma_pool_free(ha->s_dma_pool, ha->sfp_data, ha->sfp_data_dma);
3053 dma_pool_free(ha->s_dma_pool, ha->edc_data, ha->edc_data_dma);
3056 dma_pool_free(ha->s_dma_pool, ha->ms_iocb, ha->ms_iocb_dma);
3059 dma_pool_free(ha->s_dma_pool,
3060 ha->ex_init_cb, ha->ex_init_cb_dma);
3063 dma_pool_free(ha->s_dma_pool, ha->async_pd, ha->async_pd_dma);
3066 dma_pool_destroy(ha->s_dma_pool);
3069 dma_free_coherent(&ha->pdev->dev, GID_LIST_SIZE, ha->gid_list,
3072 if (IS_QLA82XX(ha)) {
3073 if (!list_empty(&ha->gbl_dsd_list)) {
3074 struct dsd_dma *dsd_ptr, *tdsd_ptr;
3076 /* clean up allocated prev pool */
3077 list_for_each_entry_safe(dsd_ptr,
3078 tdsd_ptr, &ha->gbl_dsd_list, list) {
3079 dma_pool_free(ha->dl_dma_pool,
3080 dsd_ptr->dsd_addr, dsd_ptr->dsd_list_dma);
3081 list_del(&dsd_ptr->list);
3087 if (ha->dl_dma_pool)
3088 dma_pool_destroy(ha->dl_dma_pool);
3090 if (ha->fcp_cmnd_dma_pool)
3091 dma_pool_destroy(ha->fcp_cmnd_dma_pool);
3093 if (ha->ctx_mempool)
3094 mempool_destroy(ha->ctx_mempool);
3097 dma_free_coherent(&ha->pdev->dev, ha->init_cb_size,
3098 ha->init_cb, ha->init_cb_dma);
3099 vfree(ha->optrom_buffer);
3101 kfree(ha->npiv_info);
3103 ha->srb_mempool = NULL;
3104 ha->ctx_mempool = NULL;
3106 ha->sns_cmd_dma = 0;
3110 ha->ms_iocb_dma = 0;
3112 ha->init_cb_dma = 0;
3113 ha->ex_init_cb = NULL;
3114 ha->ex_init_cb_dma = 0;
3115 ha->async_pd = NULL;
3116 ha->async_pd_dma = 0;
3118 ha->s_dma_pool = NULL;
3119 ha->dl_dma_pool = NULL;
3120 ha->fcp_cmnd_dma_pool = NULL;
3122 ha->gid_list = NULL;
3123 ha->gid_list_dma = 0;
3126 struct scsi_qla_host *qla2x00_create_host(struct scsi_host_template *sht,
3127 struct qla_hw_data *ha)
3129 struct Scsi_Host *host;
3130 struct scsi_qla_host *vha = NULL;
3132 host = scsi_host_alloc(sht, sizeof(scsi_qla_host_t));
3134 ql_log_pci(ql_log_fatal, ha->pdev, 0x0107,
3135 "Failed to allocate host from the scsi layer, aborting.\n");
3139 /* Clear our data area */
3140 vha = shost_priv(host);
3141 memset(vha, 0, sizeof(scsi_qla_host_t));
3144 vha->host_no = host->host_no;
3147 INIT_LIST_HEAD(&vha->vp_fcports);
3148 INIT_LIST_HEAD(&vha->work_list);
3149 INIT_LIST_HEAD(&vha->list);
3151 spin_lock_init(&vha->work_lock);
3153 sprintf(vha->host_str, "%s_%ld", QLA2XXX_DRIVER_NAME, vha->host_no);
3154 ql_dbg(ql_dbg_init, vha, 0x0041,
3155 "Allocated the host=%p hw=%p vha=%p dev_name=%s",
3156 vha->host, vha->hw, vha,
3157 dev_name(&(ha->pdev->dev)));
3165 static struct qla_work_evt *
3166 qla2x00_alloc_work(struct scsi_qla_host *vha, enum qla_work_type type)
3168 struct qla_work_evt *e;
3171 QLA_VHA_MARK_BUSY(vha, bail);
3175 e = kzalloc(sizeof(struct qla_work_evt), GFP_ATOMIC);
3177 QLA_VHA_MARK_NOT_BUSY(vha);
3181 INIT_LIST_HEAD(&e->list);
3183 e->flags = QLA_EVT_FLAG_FREE;
3188 qla2x00_post_work(struct scsi_qla_host *vha, struct qla_work_evt *e)
3190 unsigned long flags;
3192 spin_lock_irqsave(&vha->work_lock, flags);
3193 list_add_tail(&e->list, &vha->work_list);
3194 spin_unlock_irqrestore(&vha->work_lock, flags);
3195 qla2xxx_wake_dpc(vha);
3201 qla2x00_post_aen_work(struct scsi_qla_host *vha, enum fc_host_event_code code,
3204 struct qla_work_evt *e;
3206 e = qla2x00_alloc_work(vha, QLA_EVT_AEN);
3208 return QLA_FUNCTION_FAILED;
3210 e->u.aen.code = code;
3211 e->u.aen.data = data;
3212 return qla2x00_post_work(vha, e);
3216 qla2x00_post_idc_ack_work(struct scsi_qla_host *vha, uint16_t *mb)
3218 struct qla_work_evt *e;
3220 e = qla2x00_alloc_work(vha, QLA_EVT_IDC_ACK);
3222 return QLA_FUNCTION_FAILED;
3224 memcpy(e->u.idc_ack.mb, mb, QLA_IDC_ACK_REGS * sizeof(uint16_t));
3225 return qla2x00_post_work(vha, e);
3228 #define qla2x00_post_async_work(name, type) \
3229 int qla2x00_post_async_##name##_work( \
3230 struct scsi_qla_host *vha, \
3231 fc_port_t *fcport, uint16_t *data) \
3233 struct qla_work_evt *e; \
3235 e = qla2x00_alloc_work(vha, type); \
3237 return QLA_FUNCTION_FAILED; \
3239 e->u.logio.fcport = fcport; \
3241 e->u.logio.data[0] = data[0]; \
3242 e->u.logio.data[1] = data[1]; \
3244 return qla2x00_post_work(vha, e); \
3247 qla2x00_post_async_work(login, QLA_EVT_ASYNC_LOGIN);
3248 qla2x00_post_async_work(login_done, QLA_EVT_ASYNC_LOGIN_DONE);
3249 qla2x00_post_async_work(logout, QLA_EVT_ASYNC_LOGOUT);
3250 qla2x00_post_async_work(logout_done, QLA_EVT_ASYNC_LOGOUT_DONE);
3251 qla2x00_post_async_work(adisc, QLA_EVT_ASYNC_ADISC);
3252 qla2x00_post_async_work(adisc_done, QLA_EVT_ASYNC_ADISC_DONE);
3255 qla2x00_post_uevent_work(struct scsi_qla_host *vha, u32 code)
3257 struct qla_work_evt *e;
3259 e = qla2x00_alloc_work(vha, QLA_EVT_UEVENT);
3261 return QLA_FUNCTION_FAILED;
3263 e->u.uevent.code = code;
3264 return qla2x00_post_work(vha, e);
3268 qla2x00_uevent_emit(struct scsi_qla_host *vha, u32 code)
3270 char event_string[40];
3271 char *envp[] = { event_string, NULL };
3274 case QLA_UEVENT_CODE_FW_DUMP:
3275 snprintf(event_string, sizeof(event_string), "FW_DUMP=%ld",
3282 kobject_uevent_env(&vha->hw->pdev->dev.kobj, KOBJ_CHANGE, envp);
3286 qla2x00_do_work(struct scsi_qla_host *vha)
3288 struct qla_work_evt *e, *tmp;
3289 unsigned long flags;
3292 spin_lock_irqsave(&vha->work_lock, flags);
3293 list_splice_init(&vha->work_list, &work);
3294 spin_unlock_irqrestore(&vha->work_lock, flags);
3296 list_for_each_entry_safe(e, tmp, &work, list) {
3297 list_del_init(&e->list);
3301 fc_host_post_event(vha->host, fc_get_event_number(),
3302 e->u.aen.code, e->u.aen.data);
3304 case QLA_EVT_IDC_ACK:
3305 qla81xx_idc_ack(vha, e->u.idc_ack.mb);
3307 case QLA_EVT_ASYNC_LOGIN:
3308 qla2x00_async_login(vha, e->u.logio.fcport,
3311 case QLA_EVT_ASYNC_LOGIN_DONE:
3312 qla2x00_async_login_done(vha, e->u.logio.fcport,
3315 case QLA_EVT_ASYNC_LOGOUT:
3316 qla2x00_async_logout(vha, e->u.logio.fcport);
3318 case QLA_EVT_ASYNC_LOGOUT_DONE:
3319 qla2x00_async_logout_done(vha, e->u.logio.fcport,
3322 case QLA_EVT_ASYNC_ADISC:
3323 qla2x00_async_adisc(vha, e->u.logio.fcport,
3326 case QLA_EVT_ASYNC_ADISC_DONE:
3327 qla2x00_async_adisc_done(vha, e->u.logio.fcport,
3330 case QLA_EVT_UEVENT:
3331 qla2x00_uevent_emit(vha, e->u.uevent.code);
3334 if (e->flags & QLA_EVT_FLAG_FREE)
3337 /* For each work completed decrement vha ref count */
3338 QLA_VHA_MARK_NOT_BUSY(vha);
3342 /* Relogins all the fcports of a vport
3343 * Context: dpc thread
3345 void qla2x00_relogin(struct scsi_qla_host *vha)
3349 uint16_t next_loopid = 0;
3350 struct qla_hw_data *ha = vha->hw;
3353 list_for_each_entry(fcport, &vha->vp_fcports, list) {
3355 * If the port is not ONLINE then try to login
3356 * to it if we haven't run out of retries.
3358 if (atomic_read(&fcport->state) != FCS_ONLINE &&
3359 fcport->login_retry && !(fcport->flags & FCF_ASYNC_SENT)) {
3360 fcport->login_retry--;
3361 if (fcport->flags & FCF_FABRIC_DEVICE) {
3362 if (fcport->flags & FCF_FCP2_DEVICE)
3363 ha->isp_ops->fabric_logout(vha,
3365 fcport->d_id.b.domain,
3366 fcport->d_id.b.area,
3367 fcport->d_id.b.al_pa);
3369 if (fcport->loop_id == FC_NO_LOOP_ID) {
3370 fcport->loop_id = next_loopid =
3371 ha->min_external_loopid;
3372 status = qla2x00_find_new_loop_id(
3374 if (status != QLA_SUCCESS) {
3375 /* Ran out of IDs to use */
3380 if (IS_ALOGIO_CAPABLE(ha)) {
3381 fcport->flags |= FCF_ASYNC_SENT;
3383 data[1] = QLA_LOGIO_LOGIN_RETRIED;
3384 status = qla2x00_post_async_login_work(
3386 if (status == QLA_SUCCESS)
3388 /* Attempt a retry. */
3391 status = qla2x00_fabric_login(vha,
3392 fcport, &next_loopid);
3394 status = qla2x00_local_device_login(vha,
3397 if (status == QLA_SUCCESS) {
3398 fcport->old_loop_id = fcport->loop_id;
3400 ql_dbg(ql_dbg_disc, vha, 0x2003,
3401 "Port login OK: logged in ID 0x%x.\n",
3404 qla2x00_update_fcport(vha, fcport);
3406 } else if (status == 1) {
3407 set_bit(RELOGIN_NEEDED, &vha->dpc_flags);
3408 /* retry the login again */
3409 ql_dbg(ql_dbg_disc, vha, 0x2007,
3410 "Retrying %d login again loop_id 0x%x.\n",
3411 fcport->login_retry, fcport->loop_id);
3413 fcport->login_retry = 0;
3416 if (fcport->login_retry == 0 && status != QLA_SUCCESS)
3417 fcport->loop_id = FC_NO_LOOP_ID;
3419 if (test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags))
3424 /**************************************************************************
3426 * This kernel thread is a task that is schedule by the interrupt handler
3427 * to perform the background processing for interrupts.
3430 * This task always run in the context of a kernel thread. It
3431 * is kick-off by the driver's detect code and starts up
3432 * up one per adapter. It immediately goes to sleep and waits for
3433 * some fibre event. When either the interrupt handler or
3434 * the timer routine detects a event it will one of the task
3435 * bits then wake us up.
3436 **************************************************************************/
3438 qla2x00_do_dpc(void *data)
3441 scsi_qla_host_t *base_vha;
3442 struct qla_hw_data *ha;
3444 ha = (struct qla_hw_data *)data;
3445 base_vha = pci_get_drvdata(ha->pdev);
3447 set_user_nice(current, -20);
3449 set_current_state(TASK_INTERRUPTIBLE);
3450 while (!kthread_should_stop()) {
3451 ql_dbg(ql_dbg_dpc, base_vha, 0x4000,
3452 "DPC handler sleeping.\n");
3455 __set_current_state(TASK_RUNNING);
3457 if (!base_vha->flags.init_done || ha->flags.mbox_busy)
3460 if (ha->flags.eeh_busy) {
3461 ql_dbg(ql_dbg_dpc, base_vha, 0x4003,
3462 "eeh_busy=%d.\n", ha->flags.eeh_busy);
3468 ql_dbg(ql_dbg_dpc, base_vha, 0x4001,
3469 "DPC handler waking up.\n");
3470 ql_dbg(ql_dbg_dpc, base_vha, 0x4002,
3471 "dpc_flags=0x%lx.\n", base_vha->dpc_flags);
3473 qla2x00_do_work(base_vha);
3475 if (IS_QLA82XX(ha)) {
3476 if (test_and_clear_bit(ISP_UNRECOVERABLE,
3477 &base_vha->dpc_flags)) {
3478 qla82xx_idc_lock(ha);
3479 qla82xx_wr_32(ha, QLA82XX_CRB_DEV_STATE,
3480 QLA82XX_DEV_FAILED);
3481 qla82xx_idc_unlock(ha);
3482 ql_log(ql_log_info, base_vha, 0x4004,
3483 "HW State: FAILED.\n");
3484 qla82xx_device_state_handler(base_vha);
3488 if (test_and_clear_bit(FCOE_CTX_RESET_NEEDED,
3489 &base_vha->dpc_flags)) {
3491 ql_dbg(ql_dbg_dpc, base_vha, 0x4005,
3492 "FCoE context reset scheduled.\n");
3493 if (!(test_and_set_bit(ABORT_ISP_ACTIVE,
3494 &base_vha->dpc_flags))) {
3495 if (qla82xx_fcoe_ctx_reset(base_vha)) {
3496 /* FCoE-ctx reset failed.
3497 * Escalate to chip-reset
3499 set_bit(ISP_ABORT_NEEDED,
3500 &base_vha->dpc_flags);
3502 clear_bit(ABORT_ISP_ACTIVE,
3503 &base_vha->dpc_flags);
3506 ql_dbg(ql_dbg_dpc, base_vha, 0x4006,
3507 "FCoE context reset end.\n");
3511 if (test_and_clear_bit(ISP_ABORT_NEEDED,
3512 &base_vha->dpc_flags)) {
3514 ql_dbg(ql_dbg_dpc, base_vha, 0x4007,
3515 "ISP abort scheduled.\n");
3516 if (!(test_and_set_bit(ABORT_ISP_ACTIVE,
3517 &base_vha->dpc_flags))) {
3519 if (ha->isp_ops->abort_isp(base_vha)) {
3520 /* failed. retry later */
3521 set_bit(ISP_ABORT_NEEDED,
3522 &base_vha->dpc_flags);
3524 clear_bit(ABORT_ISP_ACTIVE,
3525 &base_vha->dpc_flags);
3528 ql_dbg(ql_dbg_dpc, base_vha, 0x4008,
3529 "ISP abort end.\n");
3532 if (test_bit(FCPORT_UPDATE_NEEDED, &base_vha->dpc_flags)) {
3533 qla2x00_update_fcports(base_vha);
3534 clear_bit(FCPORT_UPDATE_NEEDED, &base_vha->dpc_flags);
3537 if (test_bit(ISP_QUIESCE_NEEDED, &base_vha->dpc_flags)) {
3538 ql_dbg(ql_dbg_dpc, base_vha, 0x4009,
3539 "Quiescence mode scheduled.\n");
3540 qla82xx_device_state_handler(base_vha);
3541 clear_bit(ISP_QUIESCE_NEEDED, &base_vha->dpc_flags);
3542 if (!ha->flags.quiesce_owner) {
3543 qla2x00_perform_loop_resync(base_vha);
3545 qla82xx_idc_lock(ha);
3546 qla82xx_clear_qsnt_ready(base_vha);
3547 qla82xx_idc_unlock(ha);
3549 ql_dbg(ql_dbg_dpc, base_vha, 0x400a,
3550 "Quiescence mode end.\n");
3553 if (test_and_clear_bit(RESET_MARKER_NEEDED,
3554 &base_vha->dpc_flags) &&
3555 (!(test_and_set_bit(RESET_ACTIVE, &base_vha->dpc_flags)))) {
3557 ql_dbg(ql_dbg_dpc, base_vha, 0x400b,
3558 "Reset marker scheduled.\n");
3559 qla2x00_rst_aen(base_vha);
3560 clear_bit(RESET_ACTIVE, &base_vha->dpc_flags);
3561 ql_dbg(ql_dbg_dpc, base_vha, 0x400c,
3562 "Reset marker end.\n");
3565 /* Retry each device up to login retry count */
3566 if ((test_and_clear_bit(RELOGIN_NEEDED,
3567 &base_vha->dpc_flags)) &&
3568 !test_bit(LOOP_RESYNC_NEEDED, &base_vha->dpc_flags) &&
3569 atomic_read(&base_vha->loop_state) != LOOP_DOWN) {
3571 ql_dbg(ql_dbg_dpc, base_vha, 0x400d,
3572 "Relogin scheduled.\n");
3573 qla2x00_relogin(base_vha);
3574 ql_dbg(ql_dbg_dpc, base_vha, 0x400e,
3578 if (test_and_clear_bit(LOOP_RESYNC_NEEDED,
3579 &base_vha->dpc_flags)) {
3581 ql_dbg(ql_dbg_dpc, base_vha, 0x400f,
3582 "Loop resync scheduled.\n");
3584 if (!(test_and_set_bit(LOOP_RESYNC_ACTIVE,
3585 &base_vha->dpc_flags))) {
3587 rval = qla2x00_loop_resync(base_vha);
3589 clear_bit(LOOP_RESYNC_ACTIVE,
3590 &base_vha->dpc_flags);
3593 ql_dbg(ql_dbg_dpc, base_vha, 0x4010,
3594 "Loop resync end.\n");
3597 if (test_bit(NPIV_CONFIG_NEEDED, &base_vha->dpc_flags) &&
3598 atomic_read(&base_vha->loop_state) == LOOP_READY) {
3599 clear_bit(NPIV_CONFIG_NEEDED, &base_vha->dpc_flags);
3600 qla2xxx_flash_npiv_conf(base_vha);
3603 if (!ha->interrupts_on)
3604 ha->isp_ops->enable_intrs(ha);
3606 if (test_and_clear_bit(BEACON_BLINK_NEEDED,
3607 &base_vha->dpc_flags))
3608 ha->isp_ops->beacon_blink(base_vha);
3610 qla2x00_do_dpc_all_vps(base_vha);
3614 set_current_state(TASK_INTERRUPTIBLE);
3615 } /* End of while(1) */
3616 __set_current_state(TASK_RUNNING);
3618 ql_dbg(ql_dbg_dpc, base_vha, 0x4011,
3619 "DPC handler exiting.\n");
3622 * Make sure that nobody tries to wake us up again.
3626 /* Cleanup any residual CTX SRBs. */
3627 qla2x00_abort_all_cmds(base_vha, DID_NO_CONNECT << 16);
3633 qla2xxx_wake_dpc(struct scsi_qla_host *vha)
3635 struct qla_hw_data *ha = vha->hw;
3636 struct task_struct *t = ha->dpc_thread;
3638 if (!test_bit(UNLOADING, &vha->dpc_flags) && t)
3644 * Processes asynchronous reset.
3647 * ha = adapter block pointer.
3650 qla2x00_rst_aen(scsi_qla_host_t *vha)
3652 if (vha->flags.online && !vha->flags.reset_active &&
3653 !atomic_read(&vha->loop_down_timer) &&
3654 !(test_bit(ABORT_ISP_ACTIVE, &vha->dpc_flags))) {
3656 clear_bit(RESET_MARKER_NEEDED, &vha->dpc_flags);
3659 * Issue marker command only when we are going to start
3662 vha->marker_needed = 1;
3663 } while (!atomic_read(&vha->loop_down_timer) &&
3664 (test_bit(RESET_MARKER_NEEDED, &vha->dpc_flags)));
3669 qla2x00_sp_free_dma(srb_t *sp)
3671 struct scsi_cmnd *cmd = sp->cmd;
3672 struct qla_hw_data *ha = sp->fcport->vha->hw;
3674 if (sp->flags & SRB_DMA_VALID) {
3675 scsi_dma_unmap(cmd);
3676 sp->flags &= ~SRB_DMA_VALID;
3679 if (sp->flags & SRB_CRC_PROT_DMA_VALID) {
3680 dma_unmap_sg(&ha->pdev->dev, scsi_prot_sglist(cmd),
3681 scsi_prot_sg_count(cmd), cmd->sc_data_direction);
3682 sp->flags &= ~SRB_CRC_PROT_DMA_VALID;
3685 if (sp->flags & SRB_CRC_CTX_DSD_VALID) {
3686 /* List assured to be having elements */
3687 qla2x00_clean_dsd_pool(ha, sp);
3688 sp->flags &= ~SRB_CRC_CTX_DSD_VALID;
3691 if (sp->flags & SRB_CRC_CTX_DMA_VALID) {
3692 dma_pool_free(ha->dl_dma_pool, sp->ctx,
3693 ((struct crc_context *)sp->ctx)->crc_ctx_dma);
3694 sp->flags &= ~SRB_CRC_CTX_DMA_VALID;
3697 if (sp->flags & SRB_FCP_CMND_DMA_VALID) {
3698 struct ct6_dsd *ctx = sp->ctx;
3699 dma_pool_free(ha->fcp_cmnd_dma_pool, ctx->fcp_cmnd,
3701 list_splice(&ctx->dsd_list, &ha->gbl_dsd_list);
3702 ha->gbl_dsd_inuse -= ctx->dsd_use_cnt;
3703 ha->gbl_dsd_avail += ctx->dsd_use_cnt;
3704 mempool_free(sp->ctx, ha->ctx_mempool);
3712 qla2x00_sp_final_compl(struct qla_hw_data *ha, srb_t *sp)
3714 struct scsi_cmnd *cmd = sp->cmd;
3716 qla2x00_sp_free_dma(sp);
3717 mempool_free(sp, ha->srb_mempool);
3718 cmd->scsi_done(cmd);
3722 qla2x00_sp_compl(struct qla_hw_data *ha, srb_t *sp)
3724 if (atomic_read(&sp->ref_count) == 0) {
3725 ql_dbg(ql_dbg_io, sp->fcport->vha, 0x3015,
3726 "SP reference-count to ZERO -- sp=%p cmd=%p.\n",
3728 if (ql2xextended_error_logging & ql_dbg_io)
3732 if (!atomic_dec_and_test(&sp->ref_count))
3734 qla2x00_sp_final_compl(ha, sp);
3737 /**************************************************************************
3743 * Context: Interrupt
3744 ***************************************************************************/
3746 qla2x00_timer(scsi_qla_host_t *vha)
3748 unsigned long cpu_flags = 0;
3753 struct qla_hw_data *ha = vha->hw;
3754 struct req_que *req;
3756 if (ha->flags.eeh_busy) {
3757 ql_dbg(ql_dbg_timer, vha, 0x6000,
3758 "EEH = %d, restarting timer.\n",
3759 ha->flags.eeh_busy);
3760 qla2x00_restart_timer(vha, WATCH_INTERVAL);
3764 /* Hardware read to raise pending EEH errors during mailbox waits. */
3765 if (!pci_channel_offline(ha->pdev))
3766 pci_read_config_word(ha->pdev, PCI_VENDOR_ID, &w);
3768 /* Make sure qla82xx_watchdog is run only for physical port */
3769 if (!vha->vp_idx && IS_QLA82XX(ha)) {
3770 if (test_bit(ISP_QUIESCE_NEEDED, &vha->dpc_flags))
3772 qla82xx_watchdog(vha);
3775 /* Loop down handler. */
3776 if (atomic_read(&vha->loop_down_timer) > 0 &&
3777 !(test_bit(ABORT_ISP_ACTIVE, &vha->dpc_flags)) &&
3778 !(test_bit(FCOE_CTX_RESET_NEEDED, &vha->dpc_flags))
3779 && vha->flags.online) {
3781 if (atomic_read(&vha->loop_down_timer) ==
3782 vha->loop_down_abort_time) {
3784 ql_log(ql_log_info, vha, 0x6008,
3785 "Loop down - aborting the queues before time expires.\n");
3787 if (!IS_QLA2100(ha) && vha->link_down_timeout)
3788 atomic_set(&vha->loop_state, LOOP_DEAD);
3791 * Schedule an ISP abort to return any FCP2-device
3794 /* NPIV - scan physical port only */
3796 spin_lock_irqsave(&ha->hardware_lock,
3798 req = ha->req_q_map[0];
3800 index < MAX_OUTSTANDING_COMMANDS;
3804 sp = req->outstanding_cmds[index];
3807 if (sp->ctx && !IS_PROT_IO(sp))
3810 if (!(sfcp->flags & FCF_FCP2_DEVICE))
3814 set_bit(FCOE_CTX_RESET_NEEDED,
3817 set_bit(ISP_ABORT_NEEDED,
3821 spin_unlock_irqrestore(&ha->hardware_lock,
3827 /* if the loop has been down for 4 minutes, reinit adapter */
3828 if (atomic_dec_and_test(&vha->loop_down_timer) != 0) {
3829 if (!(vha->device_flags & DFLG_NO_CABLE)) {
3830 ql_log(ql_log_warn, vha, 0x6009,
3831 "Loop down - aborting ISP.\n");
3834 set_bit(FCOE_CTX_RESET_NEEDED,
3837 set_bit(ISP_ABORT_NEEDED,
3841 ql_dbg(ql_dbg_timer, vha, 0x600a,
3842 "Loop down - seconds remaining %d.\n",
3843 atomic_read(&vha->loop_down_timer));
3846 /* Check if beacon LED needs to be blinked for physical host only */
3847 if (!vha->vp_idx && (ha->beacon_blink_led == 1)) {
3848 /* There is no beacon_blink function for ISP82xx */
3849 if (!IS_QLA82XX(ha)) {
3850 set_bit(BEACON_BLINK_NEEDED, &vha->dpc_flags);
3855 /* Process any deferred work. */
3856 if (!list_empty(&vha->work_list))
3859 /* Schedule the DPC routine if needed */
3860 if ((test_bit(ISP_ABORT_NEEDED, &vha->dpc_flags) ||
3861 test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags) ||
3862 test_bit(FCPORT_UPDATE_NEEDED, &vha->dpc_flags) ||
3864 test_bit(RESET_MARKER_NEEDED, &vha->dpc_flags) ||
3865 test_bit(BEACON_BLINK_NEEDED, &vha->dpc_flags) ||
3866 test_bit(ISP_UNRECOVERABLE, &vha->dpc_flags) ||
3867 test_bit(FCOE_CTX_RESET_NEEDED, &vha->dpc_flags) ||
3868 test_bit(VP_DPC_NEEDED, &vha->dpc_flags) ||
3869 test_bit(RELOGIN_NEEDED, &vha->dpc_flags))) {
3870 ql_dbg(ql_dbg_timer, vha, 0x600b,
3871 "isp_abort_needed=%d loop_resync_needed=%d "
3872 "fcport_update_needed=%d start_dpc=%d "
3873 "reset_marker_needed=%d",
3874 test_bit(ISP_ABORT_NEEDED, &vha->dpc_flags),
3875 test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags),
3876 test_bit(FCPORT_UPDATE_NEEDED, &vha->dpc_flags),
3878 test_bit(RESET_MARKER_NEEDED, &vha->dpc_flags));
3879 ql_dbg(ql_dbg_timer, vha, 0x600c,
3880 "beacon_blink_needed=%d isp_unrecoverable=%d "
3881 "fcoe_ctx_reset_needed=%d vp_dpc_needed=%d "
3882 "relogin_needed=%d.\n",
3883 test_bit(BEACON_BLINK_NEEDED, &vha->dpc_flags),
3884 test_bit(ISP_UNRECOVERABLE, &vha->dpc_flags),
3885 test_bit(FCOE_CTX_RESET_NEEDED, &vha->dpc_flags),
3886 test_bit(VP_DPC_NEEDED, &vha->dpc_flags),
3887 test_bit(RELOGIN_NEEDED, &vha->dpc_flags));
3888 qla2xxx_wake_dpc(vha);
3891 qla2x00_restart_timer(vha, WATCH_INTERVAL);
3894 /* Firmware interface routines. */
3897 #define FW_ISP21XX 0
3898 #define FW_ISP22XX 1
3899 #define FW_ISP2300 2
3900 #define FW_ISP2322 3
3901 #define FW_ISP24XX 4
3902 #define FW_ISP25XX 5
3903 #define FW_ISP81XX 6
3904 #define FW_ISP82XX 7
3906 #define FW_FILE_ISP21XX "ql2100_fw.bin"
3907 #define FW_FILE_ISP22XX "ql2200_fw.bin"
3908 #define FW_FILE_ISP2300 "ql2300_fw.bin"
3909 #define FW_FILE_ISP2322 "ql2322_fw.bin"
3910 #define FW_FILE_ISP24XX "ql2400_fw.bin"
3911 #define FW_FILE_ISP25XX "ql2500_fw.bin"
3912 #define FW_FILE_ISP81XX "ql8100_fw.bin"
3913 #define FW_FILE_ISP82XX "ql8200_fw.bin"
3915 static DEFINE_MUTEX(qla_fw_lock);
3917 static struct fw_blob qla_fw_blobs[FW_BLOBS] = {
3918 { .name = FW_FILE_ISP21XX, .segs = { 0x1000, 0 }, },
3919 { .name = FW_FILE_ISP22XX, .segs = { 0x1000, 0 }, },
3920 { .name = FW_FILE_ISP2300, .segs = { 0x800, 0 }, },
3921 { .name = FW_FILE_ISP2322, .segs = { 0x800, 0x1c000, 0x1e000, 0 }, },
3922 { .name = FW_FILE_ISP24XX, },
3923 { .name = FW_FILE_ISP25XX, },
3924 { .name = FW_FILE_ISP81XX, },
3925 { .name = FW_FILE_ISP82XX, },
3929 qla2x00_request_firmware(scsi_qla_host_t *vha)
3931 struct qla_hw_data *ha = vha->hw;
3932 struct fw_blob *blob;
3935 if (IS_QLA2100(ha)) {
3936 blob = &qla_fw_blobs[FW_ISP21XX];
3937 } else if (IS_QLA2200(ha)) {
3938 blob = &qla_fw_blobs[FW_ISP22XX];
3939 } else if (IS_QLA2300(ha) || IS_QLA2312(ha) || IS_QLA6312(ha)) {
3940 blob = &qla_fw_blobs[FW_ISP2300];
3941 } else if (IS_QLA2322(ha) || IS_QLA6322(ha)) {
3942 blob = &qla_fw_blobs[FW_ISP2322];
3943 } else if (IS_QLA24XX_TYPE(ha)) {
3944 blob = &qla_fw_blobs[FW_ISP24XX];
3945 } else if (IS_QLA25XX(ha)) {
3946 blob = &qla_fw_blobs[FW_ISP25XX];
3947 } else if (IS_QLA81XX(ha)) {
3948 blob = &qla_fw_blobs[FW_ISP81XX];
3949 } else if (IS_QLA82XX(ha)) {
3950 blob = &qla_fw_blobs[FW_ISP82XX];
3953 mutex_lock(&qla_fw_lock);
3957 if (request_firmware(&blob->fw, blob->name, &ha->pdev->dev)) {
3958 ql_log(ql_log_warn, vha, 0x0063,
3959 "Failed to load firmware image (%s).\n", blob->name);
3966 mutex_unlock(&qla_fw_lock);
3971 qla2x00_release_firmware(void)
3975 mutex_lock(&qla_fw_lock);
3976 for (idx = 0; idx < FW_BLOBS; idx++)
3977 if (qla_fw_blobs[idx].fw)
3978 release_firmware(qla_fw_blobs[idx].fw);
3979 mutex_unlock(&qla_fw_lock);
3982 static pci_ers_result_t
3983 qla2xxx_pci_error_detected(struct pci_dev *pdev, pci_channel_state_t state)
3985 scsi_qla_host_t *vha = pci_get_drvdata(pdev);
3986 struct qla_hw_data *ha = vha->hw;
3988 ql_dbg(ql_dbg_aer, vha, 0x9000,
3989 "PCI error detected, state %x.\n", state);
3992 case pci_channel_io_normal:
3993 ha->flags.eeh_busy = 0;
3994 return PCI_ERS_RESULT_CAN_RECOVER;
3995 case pci_channel_io_frozen:
3996 ha->flags.eeh_busy = 1;
3997 /* For ISP82XX complete any pending mailbox cmd */
3998 if (IS_QLA82XX(ha)) {
3999 ha->flags.isp82xx_fw_hung = 1;
4000 ql_dbg(ql_dbg_aer, vha, 0x9001, "Pci channel io frozen\n");
4001 qla82xx_clear_pending_mbx(vha);
4003 qla2x00_free_irqs(vha);
4004 pci_disable_device(pdev);
4005 /* Return back all IOs */
4006 qla2x00_abort_all_cmds(vha, DID_RESET << 16);
4007 return PCI_ERS_RESULT_NEED_RESET;
4008 case pci_channel_io_perm_failure:
4009 ha->flags.pci_channel_io_perm_failure = 1;
4010 qla2x00_abort_all_cmds(vha, DID_NO_CONNECT << 16);
4011 return PCI_ERS_RESULT_DISCONNECT;
4013 return PCI_ERS_RESULT_NEED_RESET;
4016 static pci_ers_result_t
4017 qla2xxx_pci_mmio_enabled(struct pci_dev *pdev)
4019 int risc_paused = 0;
4021 unsigned long flags;
4022 scsi_qla_host_t *base_vha = pci_get_drvdata(pdev);
4023 struct qla_hw_data *ha = base_vha->hw;
4024 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
4025 struct device_reg_24xx __iomem *reg24 = &ha->iobase->isp24;
4028 return PCI_ERS_RESULT_RECOVERED;
4030 spin_lock_irqsave(&ha->hardware_lock, flags);
4031 if (IS_QLA2100(ha) || IS_QLA2200(ha)){
4032 stat = RD_REG_DWORD(®->hccr);
4033 if (stat & HCCR_RISC_PAUSE)
4035 } else if (IS_QLA23XX(ha)) {
4036 stat = RD_REG_DWORD(®->u.isp2300.host_status);
4037 if (stat & HSR_RISC_PAUSED)
4039 } else if (IS_FWI2_CAPABLE(ha)) {
4040 stat = RD_REG_DWORD(®24->host_status);
4041 if (stat & HSRX_RISC_PAUSED)
4044 spin_unlock_irqrestore(&ha->hardware_lock, flags);
4047 ql_log(ql_log_info, base_vha, 0x9003,
4048 "RISC paused -- mmio_enabled, Dumping firmware.\n");
4049 ha->isp_ops->fw_dump(base_vha, 0);
4051 return PCI_ERS_RESULT_NEED_RESET;
4053 return PCI_ERS_RESULT_RECOVERED;
4056 uint32_t qla82xx_error_recovery(scsi_qla_host_t *base_vha)
4058 uint32_t rval = QLA_FUNCTION_FAILED;
4059 uint32_t drv_active = 0;
4060 struct qla_hw_data *ha = base_vha->hw;
4062 struct pci_dev *other_pdev = NULL;
4064 ql_dbg(ql_dbg_aer, base_vha, 0x9006,
4065 "Entered %s.\n", __func__);
4067 set_bit(ABORT_ISP_ACTIVE, &base_vha->dpc_flags);
4069 if (base_vha->flags.online) {
4070 /* Abort all outstanding commands,
4071 * so as to be requeued later */
4072 qla2x00_abort_isp_cleanup(base_vha);
4076 fn = PCI_FUNC(ha->pdev->devfn);
4079 ql_dbg(ql_dbg_aer, base_vha, 0x9007,
4080 "Finding pci device at function = 0x%x.\n", fn);
4082 pci_get_domain_bus_and_slot(pci_domain_nr(ha->pdev->bus),
4083 ha->pdev->bus->number, PCI_DEVFN(PCI_SLOT(ha->pdev->devfn),
4088 if (atomic_read(&other_pdev->enable_cnt)) {
4089 ql_dbg(ql_dbg_aer, base_vha, 0x9008,
4090 "Found PCI func available and enable at 0x%x.\n",
4092 pci_dev_put(other_pdev);
4095 pci_dev_put(other_pdev);
4100 ql_dbg(ql_dbg_aer, base_vha, 0x9009,
4101 "This devfn is reset owner = 0x%x.\n",
4103 qla82xx_idc_lock(ha);
4105 qla82xx_wr_32(ha, QLA82XX_CRB_DEV_STATE,
4106 QLA82XX_DEV_INITIALIZING);
4108 qla82xx_wr_32(ha, QLA82XX_CRB_DRV_IDC_VERSION,
4109 QLA82XX_IDC_VERSION);
4111 drv_active = qla82xx_rd_32(ha, QLA82XX_CRB_DRV_ACTIVE);
4112 ql_dbg(ql_dbg_aer, base_vha, 0x900a,
4113 "drv_active = 0x%x.\n", drv_active);
4115 qla82xx_idc_unlock(ha);
4116 /* Reset if device is not already reset
4117 * drv_active would be 0 if a reset has already been done
4120 rval = qla82xx_start_firmware(base_vha);
4123 qla82xx_idc_lock(ha);
4125 if (rval != QLA_SUCCESS) {
4126 ql_log(ql_log_info, base_vha, 0x900b,
4127 "HW State: FAILED.\n");
4128 qla82xx_clear_drv_active(ha);
4129 qla82xx_wr_32(ha, QLA82XX_CRB_DEV_STATE,
4130 QLA82XX_DEV_FAILED);
4132 ql_log(ql_log_info, base_vha, 0x900c,
4133 "HW State: READY.\n");
4134 qla82xx_wr_32(ha, QLA82XX_CRB_DEV_STATE,
4136 qla82xx_idc_unlock(ha);
4137 ha->flags.isp82xx_fw_hung = 0;
4138 rval = qla82xx_restart_isp(base_vha);
4139 qla82xx_idc_lock(ha);
4140 /* Clear driver state register */
4141 qla82xx_wr_32(ha, QLA82XX_CRB_DRV_STATE, 0);
4142 qla82xx_set_drv_active(base_vha);
4144 qla82xx_idc_unlock(ha);
4146 ql_dbg(ql_dbg_aer, base_vha, 0x900d,
4147 "This devfn is not reset owner = 0x%x.\n",
4149 if ((qla82xx_rd_32(ha, QLA82XX_CRB_DEV_STATE) ==
4150 QLA82XX_DEV_READY)) {
4151 ha->flags.isp82xx_fw_hung = 0;
4152 rval = qla82xx_restart_isp(base_vha);
4153 qla82xx_idc_lock(ha);
4154 qla82xx_set_drv_active(base_vha);
4155 qla82xx_idc_unlock(ha);
4158 clear_bit(ABORT_ISP_ACTIVE, &base_vha->dpc_flags);
4163 static pci_ers_result_t
4164 qla2xxx_pci_slot_reset(struct pci_dev *pdev)
4166 pci_ers_result_t ret = PCI_ERS_RESULT_DISCONNECT;
4167 scsi_qla_host_t *base_vha = pci_get_drvdata(pdev);
4168 struct qla_hw_data *ha = base_vha->hw;
4169 struct rsp_que *rsp;
4170 int rc, retries = 10;
4172 ql_dbg(ql_dbg_aer, base_vha, 0x9004,
4175 /* Workaround: qla2xxx driver which access hardware earlier
4176 * needs error state to be pci_channel_io_online.
4177 * Otherwise mailbox command timesout.
4179 pdev->error_state = pci_channel_io_normal;
4181 pci_restore_state(pdev);
4183 /* pci_restore_state() clears the saved_state flag of the device
4184 * save restored state which resets saved_state flag
4186 pci_save_state(pdev);
4189 rc = pci_enable_device_mem(pdev);
4191 rc = pci_enable_device(pdev);
4194 ql_log(ql_log_warn, base_vha, 0x9005,
4195 "Can't re-enable PCI device after reset.\n");
4196 goto exit_slot_reset;
4199 rsp = ha->rsp_q_map[0];
4200 if (qla2x00_request_irqs(ha, rsp))
4201 goto exit_slot_reset;
4203 if (ha->isp_ops->pci_config(base_vha))
4204 goto exit_slot_reset;
4206 if (IS_QLA82XX(ha)) {
4207 if (qla82xx_error_recovery(base_vha) == QLA_SUCCESS) {
4208 ret = PCI_ERS_RESULT_RECOVERED;
4209 goto exit_slot_reset;
4211 goto exit_slot_reset;
4214 while (ha->flags.mbox_busy && retries--)
4217 set_bit(ABORT_ISP_ACTIVE, &base_vha->dpc_flags);
4218 if (ha->isp_ops->abort_isp(base_vha) == QLA_SUCCESS)
4219 ret = PCI_ERS_RESULT_RECOVERED;
4220 clear_bit(ABORT_ISP_ACTIVE, &base_vha->dpc_flags);
4224 ql_dbg(ql_dbg_aer, base_vha, 0x900e,
4225 "slot_reset return %x.\n", ret);
4231 qla2xxx_pci_resume(struct pci_dev *pdev)
4233 scsi_qla_host_t *base_vha = pci_get_drvdata(pdev);
4234 struct qla_hw_data *ha = base_vha->hw;
4237 ql_dbg(ql_dbg_aer, base_vha, 0x900f,
4240 ret = qla2x00_wait_for_hba_online(base_vha);
4241 if (ret != QLA_SUCCESS) {
4242 ql_log(ql_log_fatal, base_vha, 0x9002,
4243 "The device failed to resume I/O from slot/link_reset.\n");
4246 pci_cleanup_aer_uncorrect_error_status(pdev);
4248 ha->flags.eeh_busy = 0;
4251 static struct pci_error_handlers qla2xxx_err_handler = {
4252 .error_detected = qla2xxx_pci_error_detected,
4253 .mmio_enabled = qla2xxx_pci_mmio_enabled,
4254 .slot_reset = qla2xxx_pci_slot_reset,
4255 .resume = qla2xxx_pci_resume,
4258 static struct pci_device_id qla2xxx_pci_tbl[] = {
4259 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP2100) },
4260 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP2200) },
4261 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP2300) },
4262 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP2312) },
4263 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP2322) },
4264 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP6312) },
4265 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP6322) },
4266 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP2422) },
4267 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP2432) },
4268 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP8432) },
4269 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP5422) },
4270 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP5432) },
4271 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP2532) },
4272 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP8001) },
4273 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP8021) },
4276 MODULE_DEVICE_TABLE(pci, qla2xxx_pci_tbl);
4278 static struct pci_driver qla2xxx_pci_driver = {
4279 .name = QLA2XXX_DRIVER_NAME,
4281 .owner = THIS_MODULE,
4283 .id_table = qla2xxx_pci_tbl,
4284 .probe = qla2x00_probe_one,
4285 .remove = qla2x00_remove_one,
4286 .shutdown = qla2x00_shutdown,
4287 .err_handler = &qla2xxx_err_handler,
4290 static struct file_operations apidev_fops = {
4291 .owner = THIS_MODULE,
4292 .llseek = noop_llseek,
4296 * qla2x00_module_init - Module initialization.
4299 qla2x00_module_init(void)
4303 /* Allocate cache for SRBs. */
4304 srb_cachep = kmem_cache_create("qla2xxx_srbs", sizeof(srb_t), 0,
4305 SLAB_HWCACHE_ALIGN, NULL);
4306 if (srb_cachep == NULL) {
4307 ql_log(ql_log_fatal, NULL, 0x0001,
4308 "Unable to allocate SRB cache...Failing load!.\n");
4312 /* Derive version string. */
4313 strcpy(qla2x00_version_str, QLA2XXX_VERSION);
4314 if (ql2xextended_error_logging)
4315 strcat(qla2x00_version_str, "-debug");
4317 qla2xxx_transport_template =
4318 fc_attach_transport(&qla2xxx_transport_functions);
4319 if (!qla2xxx_transport_template) {
4320 kmem_cache_destroy(srb_cachep);
4321 ql_log(ql_log_fatal, NULL, 0x0002,
4322 "fc_attach_transport failed...Failing load!.\n");
4326 apidev_major = register_chrdev(0, QLA2XXX_APIDEV, &apidev_fops);
4327 if (apidev_major < 0) {
4328 ql_log(ql_log_fatal, NULL, 0x0003,
4329 "Unable to register char device %s.\n", QLA2XXX_APIDEV);
4332 qla2xxx_transport_vport_template =
4333 fc_attach_transport(&qla2xxx_transport_vport_functions);
4334 if (!qla2xxx_transport_vport_template) {
4335 kmem_cache_destroy(srb_cachep);
4336 fc_release_transport(qla2xxx_transport_template);
4337 ql_log(ql_log_fatal, NULL, 0x0004,
4338 "fc_attach_transport vport failed...Failing load!.\n");
4341 ql_log(ql_log_info, NULL, 0x0005,
4342 "QLogic Fibre Channel HBA Driver: %s.\n",
4343 qla2x00_version_str);
4344 ret = pci_register_driver(&qla2xxx_pci_driver);
4346 kmem_cache_destroy(srb_cachep);
4347 fc_release_transport(qla2xxx_transport_template);
4348 fc_release_transport(qla2xxx_transport_vport_template);
4349 ql_log(ql_log_fatal, NULL, 0x0006,
4350 "pci_register_driver failed...ret=%d Failing load!.\n",
4357 * qla2x00_module_exit - Module cleanup.
4360 qla2x00_module_exit(void)
4362 unregister_chrdev(apidev_major, QLA2XXX_APIDEV);
4363 pci_unregister_driver(&qla2xxx_pci_driver);
4364 qla2x00_release_firmware();
4365 kmem_cache_destroy(srb_cachep);
4367 kmem_cache_destroy(ctx_cachep);
4368 fc_release_transport(qla2xxx_transport_template);
4369 fc_release_transport(qla2xxx_transport_vport_template);
4372 module_init(qla2x00_module_init);
4373 module_exit(qla2x00_module_exit);
4375 MODULE_AUTHOR("QLogic Corporation");
4376 MODULE_DESCRIPTION("QLogic Fibre Channel HBA Driver");
4377 MODULE_LICENSE("GPL");
4378 MODULE_VERSION(QLA2XXX_VERSION);
4379 MODULE_FIRMWARE(FW_FILE_ISP21XX);
4380 MODULE_FIRMWARE(FW_FILE_ISP22XX);
4381 MODULE_FIRMWARE(FW_FILE_ISP2300);
4382 MODULE_FIRMWARE(FW_FILE_ISP2322);
4383 MODULE_FIRMWARE(FW_FILE_ISP24XX);
4384 MODULE_FIRMWARE(FW_FILE_ISP25XX);