2 * QLogic Fibre Channel HBA Driver
3 * Copyright (c) 2003-2014 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>
16 #include <linux/blk-mq-pci.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>
22 #include "qla_target.h"
27 char qla2x00_version_str[40];
29 static int apidev_major;
32 * SRB allocation cache
34 struct kmem_cache *srb_cachep;
37 * CT6 CTX allocation cache
39 static struct kmem_cache *ctx_cachep;
41 * error level for logging
43 int ql_errlev = ql_log_all;
45 static int ql2xenableclass2;
46 module_param(ql2xenableclass2, int, S_IRUGO|S_IRUSR);
47 MODULE_PARM_DESC(ql2xenableclass2,
48 "Specify if Class 2 operations are supported from the very "
49 "beginning. Default is 0 - class 2 not supported.");
52 int ql2xlogintimeout = 20;
53 module_param(ql2xlogintimeout, int, S_IRUGO);
54 MODULE_PARM_DESC(ql2xlogintimeout,
55 "Login timeout value in seconds.");
57 int qlport_down_retry;
58 module_param(qlport_down_retry, int, S_IRUGO);
59 MODULE_PARM_DESC(qlport_down_retry,
60 "Maximum number of command retries to a port that returns "
61 "a PORT-DOWN status.");
63 int ql2xplogiabsentdevice;
64 module_param(ql2xplogiabsentdevice, int, S_IRUGO|S_IWUSR);
65 MODULE_PARM_DESC(ql2xplogiabsentdevice,
66 "Option to enable PLOGI to devices that are not present after "
67 "a Fabric scan. This is needed for several broken switches. "
68 "Default is 0 - no PLOGI. 1 - perfom PLOGI.");
70 int ql2xloginretrycount = 0;
71 module_param(ql2xloginretrycount, int, S_IRUGO);
72 MODULE_PARM_DESC(ql2xloginretrycount,
73 "Specify an alternate value for the NVRAM login retry count.");
75 int ql2xallocfwdump = 1;
76 module_param(ql2xallocfwdump, int, S_IRUGO);
77 MODULE_PARM_DESC(ql2xallocfwdump,
78 "Option to enable allocation of memory for a firmware dump "
79 "during HBA initialization. Memory allocation requirements "
80 "vary by ISP type. Default is 1 - allocate memory.");
82 int ql2xextended_error_logging;
83 module_param(ql2xextended_error_logging, int, S_IRUGO|S_IWUSR);
84 module_param_named(logging, ql2xextended_error_logging, int, S_IRUGO|S_IWUSR);
85 MODULE_PARM_DESC(ql2xextended_error_logging,
86 "Option to enable extended error logging,\n"
87 "\t\tDefault is 0 - no logging. 0x40000000 - Module Init & Probe.\n"
88 "\t\t0x20000000 - Mailbox Cmnds. 0x10000000 - Device Discovery.\n"
89 "\t\t0x08000000 - IO tracing. 0x04000000 - DPC Thread.\n"
90 "\t\t0x02000000 - Async events. 0x01000000 - Timer routines.\n"
91 "\t\t0x00800000 - User space. 0x00400000 - Task Management.\n"
92 "\t\t0x00200000 - AER/EEH. 0x00100000 - Multi Q.\n"
93 "\t\t0x00080000 - P3P Specific. 0x00040000 - Virtual Port.\n"
94 "\t\t0x00020000 - Buffer Dump. 0x00010000 - Misc.\n"
95 "\t\t0x00008000 - Verbose. 0x00004000 - Target.\n"
96 "\t\t0x00002000 - Target Mgmt. 0x00001000 - Target TMF.\n"
97 "\t\t0x7fffffff - For enabling all logs, can be too many logs.\n"
98 "\t\t0x1e400000 - Preferred value for capturing essential "
99 "debug information (equivalent to old "
100 "ql2xextended_error_logging=1).\n"
101 "\t\tDo LOGICAL OR of the value to enable more than one level");
103 int ql2xshiftctondsd = 6;
104 module_param(ql2xshiftctondsd, int, S_IRUGO);
105 MODULE_PARM_DESC(ql2xshiftctondsd,
106 "Set to control shifting of command type processing "
107 "based on total number of SG elements.");
109 int ql2xfdmienable=1;
110 module_param(ql2xfdmienable, int, S_IRUGO|S_IWUSR);
111 module_param_named(fdmi, ql2xfdmienable, int, S_IRUGO|S_IWUSR);
112 MODULE_PARM_DESC(ql2xfdmienable,
113 "Enables FDMI registrations. "
114 "0 - no FDMI. Default is 1 - perform FDMI.");
116 #define MAX_Q_DEPTH 32
117 static int ql2xmaxqdepth = MAX_Q_DEPTH;
118 module_param(ql2xmaxqdepth, int, S_IRUGO|S_IWUSR);
119 MODULE_PARM_DESC(ql2xmaxqdepth,
120 "Maximum queue depth to set for each LUN. "
123 int ql2xenabledif = 2;
124 module_param(ql2xenabledif, int, S_IRUGO);
125 MODULE_PARM_DESC(ql2xenabledif,
126 " Enable T10-CRC-DIF:\n"
128 " 0 -- No DIF Support\n"
129 " 1 -- Enable DIF for all types\n"
130 " 2 -- Enable DIF for all types, except Type 0.\n");
132 int ql2xenablehba_err_chk = 2;
133 module_param(ql2xenablehba_err_chk, int, S_IRUGO|S_IWUSR);
134 MODULE_PARM_DESC(ql2xenablehba_err_chk,
135 " Enable T10-CRC-DIF Error isolation by HBA:\n"
137 " 0 -- Error isolation disabled\n"
138 " 1 -- Error isolation enabled only for DIX Type 0\n"
139 " 2 -- Error isolation enabled for all Types\n");
141 int ql2xiidmaenable=1;
142 module_param(ql2xiidmaenable, int, S_IRUGO);
143 MODULE_PARM_DESC(ql2xiidmaenable,
144 "Enables iIDMA settings "
145 "Default is 1 - perform iIDMA. 0 - no iIDMA.");
147 int ql2xmqsupport = 1;
148 module_param(ql2xmqsupport, int, S_IRUGO);
149 MODULE_PARM_DESC(ql2xmqsupport,
150 "Enable on demand multiple queue pairs support "
151 "Default is 1 for supported. "
152 "Set it to 0 to turn off mq qpair support.");
155 module_param(ql2xfwloadbin, int, S_IRUGO|S_IWUSR);
156 module_param_named(fwload, ql2xfwloadbin, int, S_IRUGO|S_IWUSR);
157 MODULE_PARM_DESC(ql2xfwloadbin,
158 "Option to specify location from which to load ISP firmware:.\n"
159 " 2 -- load firmware via the request_firmware() (hotplug).\n"
161 " 1 -- load firmware from flash.\n"
162 " 0 -- use default semantics.\n");
165 module_param(ql2xetsenable, int, S_IRUGO);
166 MODULE_PARM_DESC(ql2xetsenable,
167 "Enables firmware ETS burst."
168 "Default is 0 - skip ETS enablement.");
171 module_param(ql2xdbwr, int, S_IRUGO|S_IWUSR);
172 MODULE_PARM_DESC(ql2xdbwr,
173 "Option to specify scheme for request queue posting.\n"
174 " 0 -- Regular doorbell.\n"
175 " 1 -- CAMRAM doorbell (faster).\n");
177 int ql2xtargetreset = 1;
178 module_param(ql2xtargetreset, int, S_IRUGO);
179 MODULE_PARM_DESC(ql2xtargetreset,
180 "Enable target reset."
181 "Default is 1 - use hw defaults.");
184 module_param(ql2xgffidenable, int, S_IRUGO);
185 MODULE_PARM_DESC(ql2xgffidenable,
186 "Enables GFF_ID checks of port type. "
187 "Default is 0 - Do not use GFF_ID information.");
189 int ql2xasynctmfenable;
190 module_param(ql2xasynctmfenable, int, S_IRUGO);
191 MODULE_PARM_DESC(ql2xasynctmfenable,
192 "Enables issue of TM IOCBs asynchronously via IOCB mechanism"
193 "Default is 0 - Issue TM IOCBs via mailbox mechanism.");
195 int ql2xdontresethba;
196 module_param(ql2xdontresethba, int, S_IRUGO|S_IWUSR);
197 MODULE_PARM_DESC(ql2xdontresethba,
198 "Option to specify reset behaviour.\n"
199 " 0 (Default) -- Reset on failure.\n"
200 " 1 -- Do not reset on failure.\n");
202 uint64_t ql2xmaxlun = MAX_LUNS;
203 module_param(ql2xmaxlun, ullong, S_IRUGO);
204 MODULE_PARM_DESC(ql2xmaxlun,
205 "Defines the maximum LU number to register with the SCSI "
206 "midlayer. Default is 65535.");
208 int ql2xmdcapmask = 0x1F;
209 module_param(ql2xmdcapmask, int, S_IRUGO);
210 MODULE_PARM_DESC(ql2xmdcapmask,
211 "Set the Minidump driver capture mask level. "
212 "Default is 0x1F - Can be set to 0x3, 0x7, 0xF, 0x1F, 0x7F.");
214 int ql2xmdenable = 1;
215 module_param(ql2xmdenable, int, S_IRUGO);
216 MODULE_PARM_DESC(ql2xmdenable,
217 "Enable/disable MiniDump. "
218 "0 - MiniDump disabled. "
219 "1 (Default) - MiniDump enabled.");
221 int ql2xexlogins = 0;
222 module_param(ql2xexlogins, uint, S_IRUGO|S_IWUSR);
223 MODULE_PARM_DESC(ql2xexlogins,
224 "Number of extended Logins. "
225 "0 (Default)- Disabled.");
227 int ql2xexchoffld = 1024;
228 module_param(ql2xexchoffld, uint, 0644);
229 MODULE_PARM_DESC(ql2xexchoffld,
230 "Number of target exchanges.");
232 int ql2xiniexchg = 1024;
233 module_param(ql2xiniexchg, uint, 0644);
234 MODULE_PARM_DESC(ql2xiniexchg,
235 "Number of initiator exchanges.");
237 int ql2xfwholdabts = 0;
238 module_param(ql2xfwholdabts, int, S_IRUGO);
239 MODULE_PARM_DESC(ql2xfwholdabts,
240 "Allow FW to hold status IOCB until ABTS rsp received. "
241 "0 (Default) Do not set fw option. "
242 "1 - Set fw option to hold ABTS.");
244 int ql2xmvasynctoatio = 1;
245 module_param(ql2xmvasynctoatio, int, S_IRUGO|S_IWUSR);
246 MODULE_PARM_DESC(ql2xmvasynctoatio,
247 "Move PUREX, ABTS RX and RIDA IOCBs to ATIOQ"
248 "0 (Default). Do not move IOCBs"
252 * SCSI host template entry points
254 static int qla2xxx_slave_configure(struct scsi_device * device);
255 static int qla2xxx_slave_alloc(struct scsi_device *);
256 static int qla2xxx_scan_finished(struct Scsi_Host *, unsigned long time);
257 static void qla2xxx_scan_start(struct Scsi_Host *);
258 static void qla2xxx_slave_destroy(struct scsi_device *);
259 static int qla2xxx_queuecommand(struct Scsi_Host *h, struct scsi_cmnd *cmd);
260 static int qla2xxx_eh_abort(struct scsi_cmnd *);
261 static int qla2xxx_eh_device_reset(struct scsi_cmnd *);
262 static int qla2xxx_eh_target_reset(struct scsi_cmnd *);
263 static int qla2xxx_eh_bus_reset(struct scsi_cmnd *);
264 static int qla2xxx_eh_host_reset(struct scsi_cmnd *);
266 static void qla2x00_clear_drv_active(struct qla_hw_data *);
267 static void qla2x00_free_device(scsi_qla_host_t *);
268 static void qla83xx_disable_laser(scsi_qla_host_t *vha);
269 static int qla2xxx_map_queues(struct Scsi_Host *shost);
271 struct scsi_host_template qla2xxx_driver_template = {
272 .module = THIS_MODULE,
273 .name = QLA2XXX_DRIVER_NAME,
274 .queuecommand = qla2xxx_queuecommand,
276 .eh_timed_out = fc_eh_timed_out,
277 .eh_abort_handler = qla2xxx_eh_abort,
278 .eh_device_reset_handler = qla2xxx_eh_device_reset,
279 .eh_target_reset_handler = qla2xxx_eh_target_reset,
280 .eh_bus_reset_handler = qla2xxx_eh_bus_reset,
281 .eh_host_reset_handler = qla2xxx_eh_host_reset,
283 .slave_configure = qla2xxx_slave_configure,
285 .slave_alloc = qla2xxx_slave_alloc,
286 .slave_destroy = qla2xxx_slave_destroy,
287 .scan_finished = qla2xxx_scan_finished,
288 .scan_start = qla2xxx_scan_start,
289 .change_queue_depth = scsi_change_queue_depth,
290 .map_queues = qla2xxx_map_queues,
293 .use_clustering = ENABLE_CLUSTERING,
294 .sg_tablesize = SG_ALL,
296 .max_sectors = 0xFFFF,
297 .shost_attrs = qla2x00_host_attrs,
299 .supported_mode = MODE_INITIATOR,
300 .track_queue_depth = 1,
303 static struct scsi_transport_template *qla2xxx_transport_template = NULL;
304 struct scsi_transport_template *qla2xxx_transport_vport_template = NULL;
306 /* TODO Convert to inlines
312 qla2x00_start_timer(scsi_qla_host_t *vha, void *func, unsigned long interval)
314 init_timer(&vha->timer);
315 vha->timer.expires = jiffies + interval * HZ;
316 vha->timer.data = (unsigned long)vha;
317 vha->timer.function = (void (*)(unsigned long))func;
318 add_timer(&vha->timer);
319 vha->timer_active = 1;
323 qla2x00_restart_timer(scsi_qla_host_t *vha, unsigned long interval)
325 /* Currently used for 82XX only. */
326 if (vha->device_flags & DFLG_DEV_FAILED) {
327 ql_dbg(ql_dbg_timer, vha, 0x600d,
328 "Device in a failed state, returning.\n");
332 mod_timer(&vha->timer, jiffies + interval * HZ);
335 static __inline__ void
336 qla2x00_stop_timer(scsi_qla_host_t *vha)
338 del_timer_sync(&vha->timer);
339 vha->timer_active = 0;
342 static int qla2x00_do_dpc(void *data);
344 static void qla2x00_rst_aen(scsi_qla_host_t *);
346 static int qla2x00_mem_alloc(struct qla_hw_data *, uint16_t, uint16_t,
347 struct req_que **, struct rsp_que **);
348 static void qla2x00_free_fw_dump(struct qla_hw_data *);
349 static void qla2x00_mem_free(struct qla_hw_data *);
350 int qla2xxx_mqueuecommand(struct Scsi_Host *host, struct scsi_cmnd *cmd,
351 struct qla_qpair *qpair);
353 /* -------------------------------------------------------------------------- */
354 static int qla2x00_alloc_queues(struct qla_hw_data *ha, struct req_que *req,
357 scsi_qla_host_t *vha = pci_get_drvdata(ha->pdev);
358 ha->req_q_map = kzalloc(sizeof(struct req_que *) * ha->max_req_queues,
360 if (!ha->req_q_map) {
361 ql_log(ql_log_fatal, vha, 0x003b,
362 "Unable to allocate memory for request queue ptrs.\n");
366 ha->rsp_q_map = kzalloc(sizeof(struct rsp_que *) * ha->max_rsp_queues,
368 if (!ha->rsp_q_map) {
369 ql_log(ql_log_fatal, vha, 0x003c,
370 "Unable to allocate memory for response queue ptrs.\n");
374 ha->base_qpair = kzalloc(sizeof(struct qla_qpair), GFP_KERNEL);
375 if (ha->base_qpair == NULL) {
376 ql_log(ql_log_warn, vha, 0x00e0,
377 "Failed to allocate base queue pair memory.\n");
378 goto fail_base_qpair;
381 rsp->qpair = ha->base_qpair;
383 ha->base_qpair->req = req;
384 ha->base_qpair->rsp = rsp;
385 ha->base_qpair->vha = vha;
386 ha->base_qpair->qp_lock_ptr = &ha->hardware_lock;
387 ha->base_qpair->msix = &ha->msix_entries[QLA_MSIX_RSP_Q];
388 INIT_LIST_HEAD(&ha->base_qpair->hints_list);
389 qla_cpu_update(rsp->qpair, smp_processor_id());
391 if (ql2xmqsupport && ha->max_qpairs) {
392 ha->queue_pair_map = kcalloc(ha->max_qpairs, sizeof(struct qla_qpair *),
394 if (!ha->queue_pair_map) {
395 ql_log(ql_log_fatal, vha, 0x0180,
396 "Unable to allocate memory for queue pair ptrs.\n");
402 * Make sure we record at least the request and response queue zero in
403 * case we need to free them if part of the probe fails.
405 ha->rsp_q_map[0] = rsp;
406 ha->req_q_map[0] = req;
407 set_bit(0, ha->rsp_qid_map);
408 set_bit(0, ha->req_qid_map);
412 kfree(ha->base_qpair);
413 ha->base_qpair = NULL;
415 kfree(ha->rsp_q_map);
416 ha->rsp_q_map = NULL;
418 kfree(ha->req_q_map);
419 ha->req_q_map = NULL;
424 static void qla2x00_free_req_que(struct qla_hw_data *ha, struct req_que *req)
426 if (IS_QLAFX00(ha)) {
427 if (req && req->ring_fx00)
428 dma_free_coherent(&ha->pdev->dev,
429 (req->length_fx00 + 1) * sizeof(request_t),
430 req->ring_fx00, req->dma_fx00);
431 } else if (req && req->ring)
432 dma_free_coherent(&ha->pdev->dev,
433 (req->length + 1) * sizeof(request_t),
434 req->ring, req->dma);
437 kfree(req->outstanding_cmds);
442 static void qla2x00_free_rsp_que(struct qla_hw_data *ha, struct rsp_que *rsp)
444 if (IS_QLAFX00(ha)) {
445 if (rsp && rsp->ring)
446 dma_free_coherent(&ha->pdev->dev,
447 (rsp->length_fx00 + 1) * sizeof(request_t),
448 rsp->ring_fx00, rsp->dma_fx00);
449 } else if (rsp && rsp->ring) {
450 dma_free_coherent(&ha->pdev->dev,
451 (rsp->length + 1) * sizeof(response_t),
452 rsp->ring, rsp->dma);
457 static void qla2x00_free_queues(struct qla_hw_data *ha)
464 if (ha->queue_pair_map) {
465 kfree(ha->queue_pair_map);
466 ha->queue_pair_map = NULL;
468 if (ha->base_qpair) {
469 kfree(ha->base_qpair);
470 ha->base_qpair = NULL;
473 spin_lock_irqsave(&ha->hardware_lock, flags);
474 for (cnt = 0; cnt < ha->max_req_queues; cnt++) {
475 if (!test_bit(cnt, ha->req_qid_map))
478 req = ha->req_q_map[cnt];
479 clear_bit(cnt, ha->req_qid_map);
480 ha->req_q_map[cnt] = NULL;
482 spin_unlock_irqrestore(&ha->hardware_lock, flags);
483 qla2x00_free_req_que(ha, req);
484 spin_lock_irqsave(&ha->hardware_lock, flags);
486 spin_unlock_irqrestore(&ha->hardware_lock, flags);
488 kfree(ha->req_q_map);
489 ha->req_q_map = NULL;
492 spin_lock_irqsave(&ha->hardware_lock, flags);
493 for (cnt = 0; cnt < ha->max_rsp_queues; cnt++) {
494 if (!test_bit(cnt, ha->rsp_qid_map))
497 rsp = ha->rsp_q_map[cnt];
498 clear_bit(cnt, ha->rsp_qid_map);
499 ha->rsp_q_map[cnt] = NULL;
500 spin_unlock_irqrestore(&ha->hardware_lock, flags);
501 qla2x00_free_rsp_que(ha, rsp);
502 spin_lock_irqsave(&ha->hardware_lock, flags);
504 spin_unlock_irqrestore(&ha->hardware_lock, flags);
506 kfree(ha->rsp_q_map);
507 ha->rsp_q_map = NULL;
511 qla2x00_pci_info_str(struct scsi_qla_host *vha, char *str)
513 struct qla_hw_data *ha = vha->hw;
514 static char *pci_bus_modes[] = {
515 "33", "66", "100", "133",
520 pci_bus = (ha->pci_attr & (BIT_9 | BIT_10)) >> 9;
523 strcat(str, pci_bus_modes[pci_bus]);
525 pci_bus = (ha->pci_attr & BIT_8) >> 8;
527 strcat(str, pci_bus_modes[pci_bus]);
529 strcat(str, " MHz)");
535 qla24xx_pci_info_str(struct scsi_qla_host *vha, char *str)
537 static char *pci_bus_modes[] = { "33", "66", "100", "133", };
538 struct qla_hw_data *ha = vha->hw;
541 if (pci_is_pcie(ha->pdev)) {
543 uint32_t lstat, lspeed, lwidth;
545 pcie_capability_read_dword(ha->pdev, PCI_EXP_LNKCAP, &lstat);
546 lspeed = lstat & PCI_EXP_LNKCAP_SLS;
547 lwidth = (lstat & PCI_EXP_LNKCAP_MLW) >> 4;
549 strcpy(str, "PCIe (");
552 strcat(str, "2.5GT/s ");
555 strcat(str, "5.0GT/s ");
558 strcat(str, "8.0GT/s ");
561 strcat(str, "<unknown> ");
564 snprintf(lwstr, sizeof(lwstr), "x%d)", lwidth);
571 pci_bus = (ha->pci_attr & CSRX_PCIX_BUS_MODE_MASK) >> 8;
572 if (pci_bus == 0 || pci_bus == 8) {
574 strcat(str, pci_bus_modes[pci_bus >> 3]);
578 strcat(str, "Mode 2");
580 strcat(str, "Mode 1");
582 strcat(str, pci_bus_modes[pci_bus & ~BIT_2]);
584 strcat(str, " MHz)");
590 qla2x00_fw_version_str(struct scsi_qla_host *vha, char *str, size_t size)
593 struct qla_hw_data *ha = vha->hw;
595 snprintf(str, size, "%d.%02d.%02d ", ha->fw_major_version,
596 ha->fw_minor_version, ha->fw_subminor_version);
598 if (ha->fw_attributes & BIT_9) {
603 switch (ha->fw_attributes & 0xFF) {
617 sprintf(un_str, "(%x)", ha->fw_attributes);
621 if (ha->fw_attributes & 0x100)
628 qla24xx_fw_version_str(struct scsi_qla_host *vha, char *str, size_t size)
630 struct qla_hw_data *ha = vha->hw;
632 snprintf(str, size, "%d.%02d.%02d (%x)", ha->fw_major_version,
633 ha->fw_minor_version, ha->fw_subminor_version, ha->fw_attributes);
638 qla2x00_sp_free_dma(void *ptr)
641 struct qla_hw_data *ha = sp->vha->hw;
642 struct scsi_cmnd *cmd = GET_CMD_SP(sp);
643 void *ctx = GET_CMD_CTX_SP(sp);
645 if (sp->flags & SRB_DMA_VALID) {
647 sp->flags &= ~SRB_DMA_VALID;
650 if (sp->flags & SRB_CRC_PROT_DMA_VALID) {
651 dma_unmap_sg(&ha->pdev->dev, scsi_prot_sglist(cmd),
652 scsi_prot_sg_count(cmd), cmd->sc_data_direction);
653 sp->flags &= ~SRB_CRC_PROT_DMA_VALID;
659 if (sp->flags & SRB_CRC_CTX_DSD_VALID) {
660 /* List assured to be having elements */
661 qla2x00_clean_dsd_pool(ha, ctx);
662 sp->flags &= ~SRB_CRC_CTX_DSD_VALID;
665 if (sp->flags & SRB_CRC_CTX_DMA_VALID) {
666 struct crc_context *ctx0 = ctx;
668 dma_pool_free(ha->dl_dma_pool, ctx0, ctx0->crc_ctx_dma);
669 sp->flags &= ~SRB_CRC_CTX_DMA_VALID;
672 if (sp->flags & SRB_FCP_CMND_DMA_VALID) {
673 struct ct6_dsd *ctx1 = ctx;
675 dma_pool_free(ha->fcp_cmnd_dma_pool, ctx1->fcp_cmnd,
677 list_splice(&ctx1->dsd_list, &ha->gbl_dsd_list);
678 ha->gbl_dsd_inuse -= ctx1->dsd_use_cnt;
679 ha->gbl_dsd_avail += ctx1->dsd_use_cnt;
680 mempool_free(ctx1, ha->ctx_mempool);
689 qla2x00_sp_compl(void *ptr, int res)
692 struct scsi_cmnd *cmd = GET_CMD_SP(sp);
696 if (atomic_read(&sp->ref_count) == 0) {
697 ql_dbg(ql_dbg_io, sp->vha, 0x3015,
698 "SP reference-count to ZERO -- sp=%p cmd=%p.\n",
700 if (ql2xextended_error_logging & ql_dbg_io)
701 WARN_ON(atomic_read(&sp->ref_count) == 0);
704 if (!atomic_dec_and_test(&sp->ref_count))
707 qla2x00_sp_free_dma(sp);
712 qla2xxx_qpair_sp_free_dma(void *ptr)
714 srb_t *sp = (srb_t *)ptr;
715 struct scsi_cmnd *cmd = GET_CMD_SP(sp);
716 struct qla_hw_data *ha = sp->fcport->vha->hw;
717 void *ctx = GET_CMD_CTX_SP(sp);
719 if (sp->flags & SRB_DMA_VALID) {
721 sp->flags &= ~SRB_DMA_VALID;
724 if (sp->flags & SRB_CRC_PROT_DMA_VALID) {
725 dma_unmap_sg(&ha->pdev->dev, scsi_prot_sglist(cmd),
726 scsi_prot_sg_count(cmd), cmd->sc_data_direction);
727 sp->flags &= ~SRB_CRC_PROT_DMA_VALID;
733 if (sp->flags & SRB_CRC_CTX_DSD_VALID) {
734 /* List assured to be having elements */
735 qla2x00_clean_dsd_pool(ha, ctx);
736 sp->flags &= ~SRB_CRC_CTX_DSD_VALID;
739 if (sp->flags & SRB_CRC_CTX_DMA_VALID) {
740 struct crc_context *ctx0 = ctx;
742 dma_pool_free(ha->dl_dma_pool, ctx, ctx0->crc_ctx_dma);
743 sp->flags &= ~SRB_CRC_CTX_DMA_VALID;
746 if (sp->flags & SRB_FCP_CMND_DMA_VALID) {
747 struct ct6_dsd *ctx1 = ctx;
748 dma_pool_free(ha->fcp_cmnd_dma_pool, ctx1->fcp_cmnd,
750 list_splice(&ctx1->dsd_list, &ha->gbl_dsd_list);
751 ha->gbl_dsd_inuse -= ctx1->dsd_use_cnt;
752 ha->gbl_dsd_avail += ctx1->dsd_use_cnt;
753 mempool_free(ctx1, ha->ctx_mempool);
757 qla2xxx_rel_qpair_sp(sp->qpair, sp);
761 qla2xxx_qpair_sp_compl(void *ptr, int res)
764 struct scsi_cmnd *cmd = GET_CMD_SP(sp);
768 if (atomic_read(&sp->ref_count) == 0) {
769 ql_dbg(ql_dbg_io, sp->fcport->vha, 0x3079,
770 "SP reference-count to ZERO -- sp=%p cmd=%p.\n",
772 if (ql2xextended_error_logging & ql_dbg_io)
773 WARN_ON(atomic_read(&sp->ref_count) == 0);
776 if (!atomic_dec_and_test(&sp->ref_count))
779 qla2xxx_qpair_sp_free_dma(sp);
783 /* If we are SP1 here, we need to still take and release the host_lock as SP1
784 * does not have the changes necessary to avoid taking host->host_lock.
787 qla2xxx_queuecommand(struct Scsi_Host *host, struct scsi_cmnd *cmd)
789 scsi_qla_host_t *vha = shost_priv(host);
790 fc_port_t *fcport = (struct fc_port *) cmd->device->hostdata;
791 struct fc_rport *rport = starget_to_rport(scsi_target(cmd->device));
792 struct qla_hw_data *ha = vha->hw;
793 struct scsi_qla_host *base_vha = pci_get_drvdata(ha->pdev);
796 struct qla_qpair *qpair = NULL;
800 if (unlikely(test_bit(UNLOADING, &base_vha->dpc_flags))) {
801 cmd->result = DID_NO_CONNECT << 16;
802 goto qc24_fail_command;
806 if (shost_use_blk_mq(vha->host)) {
807 tag = blk_mq_unique_tag(cmd->request);
808 hwq = blk_mq_unique_tag_to_hwq(tag);
809 qpair = ha->queue_pair_map[hwq];
810 } else if (vha->vp_idx && vha->qpair) {
815 return qla2xxx_mqueuecommand(host, cmd, qpair);
818 if (ha->flags.eeh_busy) {
819 if (ha->flags.pci_channel_io_perm_failure) {
820 ql_dbg(ql_dbg_aer, vha, 0x9010,
821 "PCI Channel IO permanent failure, exiting "
823 cmd->result = DID_NO_CONNECT << 16;
825 ql_dbg(ql_dbg_aer, vha, 0x9011,
826 "EEH_Busy, Requeuing the cmd=%p.\n", cmd);
827 cmd->result = DID_REQUEUE << 16;
829 goto qc24_fail_command;
832 rval = fc_remote_port_chkready(rport);
835 ql_dbg(ql_dbg_io + ql_dbg_verbose, vha, 0x3003,
836 "fc_remote_port_chkready failed for cmd=%p, rval=0x%x.\n",
838 goto qc24_fail_command;
841 if (!vha->flags.difdix_supported &&
842 scsi_get_prot_op(cmd) != SCSI_PROT_NORMAL) {
843 ql_dbg(ql_dbg_io, vha, 0x3004,
844 "DIF Cap not reg, fail DIF capable cmd's:%p.\n",
846 cmd->result = DID_NO_CONNECT << 16;
847 goto qc24_fail_command;
851 cmd->result = DID_NO_CONNECT << 16;
852 goto qc24_fail_command;
855 if (atomic_read(&fcport->state) != FCS_ONLINE) {
856 if (atomic_read(&fcport->state) == FCS_DEVICE_DEAD ||
857 atomic_read(&base_vha->loop_state) == LOOP_DEAD) {
858 ql_dbg(ql_dbg_io, vha, 0x3005,
859 "Returning DNC, fcport_state=%d loop_state=%d.\n",
860 atomic_read(&fcport->state),
861 atomic_read(&base_vha->loop_state));
862 cmd->result = DID_NO_CONNECT << 16;
863 goto qc24_fail_command;
865 goto qc24_target_busy;
869 * Return target busy if we've received a non-zero retry_delay_timer
872 if (fcport->retry_delay_timestamp == 0) {
873 /* retry delay not set */
874 } else if (time_after(jiffies, fcport->retry_delay_timestamp))
875 fcport->retry_delay_timestamp = 0;
877 goto qc24_target_busy;
879 sp = qla2x00_get_sp(vha, fcport, GFP_ATOMIC);
883 sp->u.scmd.cmd = cmd;
884 sp->type = SRB_SCSI_CMD;
885 atomic_set(&sp->ref_count, 1);
886 CMD_SP(cmd) = (void *)sp;
887 sp->free = qla2x00_sp_free_dma;
888 sp->done = qla2x00_sp_compl;
890 rval = ha->isp_ops->start_scsi(sp);
891 if (rval != QLA_SUCCESS) {
892 ql_dbg(ql_dbg_io + ql_dbg_verbose, vha, 0x3013,
893 "Start scsi failed rval=%d for cmd=%p.\n", rval, cmd);
894 goto qc24_host_busy_free_sp;
899 qc24_host_busy_free_sp:
900 qla2x00_sp_free_dma(sp);
903 return SCSI_MLQUEUE_HOST_BUSY;
906 return SCSI_MLQUEUE_TARGET_BUSY;
914 /* For MQ supported I/O */
916 qla2xxx_mqueuecommand(struct Scsi_Host *host, struct scsi_cmnd *cmd,
917 struct qla_qpair *qpair)
919 scsi_qla_host_t *vha = shost_priv(host);
920 fc_port_t *fcport = (struct fc_port *) cmd->device->hostdata;
921 struct fc_rport *rport = starget_to_rport(scsi_target(cmd->device));
922 struct qla_hw_data *ha = vha->hw;
923 struct scsi_qla_host *base_vha = pci_get_drvdata(ha->pdev);
927 rval = fc_remote_port_chkready(rport);
930 ql_dbg(ql_dbg_io + ql_dbg_verbose, vha, 0x3076,
931 "fc_remote_port_chkready failed for cmd=%p, rval=0x%x.\n",
933 goto qc24_fail_command;
937 cmd->result = DID_NO_CONNECT << 16;
938 goto qc24_fail_command;
941 if (atomic_read(&fcport->state) != FCS_ONLINE) {
942 if (atomic_read(&fcport->state) == FCS_DEVICE_DEAD ||
943 atomic_read(&base_vha->loop_state) == LOOP_DEAD) {
944 ql_dbg(ql_dbg_io, vha, 0x3077,
945 "Returning DNC, fcport_state=%d loop_state=%d.\n",
946 atomic_read(&fcport->state),
947 atomic_read(&base_vha->loop_state));
948 cmd->result = DID_NO_CONNECT << 16;
949 goto qc24_fail_command;
951 goto qc24_target_busy;
955 * Return target busy if we've received a non-zero retry_delay_timer
958 if (fcport->retry_delay_timestamp == 0) {
959 /* retry delay not set */
960 } else if (time_after(jiffies, fcport->retry_delay_timestamp))
961 fcport->retry_delay_timestamp = 0;
963 goto qc24_target_busy;
965 sp = qla2xxx_get_qpair_sp(qpair, fcport, GFP_ATOMIC);
969 sp->u.scmd.cmd = cmd;
970 sp->type = SRB_SCSI_CMD;
971 atomic_set(&sp->ref_count, 1);
972 CMD_SP(cmd) = (void *)sp;
973 sp->free = qla2xxx_qpair_sp_free_dma;
974 sp->done = qla2xxx_qpair_sp_compl;
977 rval = ha->isp_ops->start_scsi_mq(sp);
978 if (rval != QLA_SUCCESS) {
979 ql_dbg(ql_dbg_io + ql_dbg_verbose, vha, 0x3078,
980 "Start scsi failed rval=%d for cmd=%p.\n", rval, cmd);
981 if (rval == QLA_INTERFACE_ERROR)
982 goto qc24_fail_command;
983 goto qc24_host_busy_free_sp;
988 qc24_host_busy_free_sp:
989 qla2xxx_qpair_sp_free_dma(sp);
992 return SCSI_MLQUEUE_HOST_BUSY;
995 return SCSI_MLQUEUE_TARGET_BUSY;
1004 * qla2x00_eh_wait_on_command
1005 * Waits for the command to be returned by the Firmware for some
1009 * cmd = Scsi Command to wait on.
1016 qla2x00_eh_wait_on_command(struct scsi_cmnd *cmd)
1018 #define ABORT_POLLING_PERIOD 1000
1019 #define ABORT_WAIT_ITER ((2 * 1000) / (ABORT_POLLING_PERIOD))
1020 unsigned long wait_iter = ABORT_WAIT_ITER;
1021 scsi_qla_host_t *vha = shost_priv(cmd->device->host);
1022 struct qla_hw_data *ha = vha->hw;
1023 int ret = QLA_SUCCESS;
1025 if (unlikely(pci_channel_offline(ha->pdev)) || ha->flags.eeh_busy) {
1026 ql_dbg(ql_dbg_taskm, vha, 0x8005,
1027 "Return:eh_wait.\n");
1031 while (CMD_SP(cmd) && wait_iter--) {
1032 msleep(ABORT_POLLING_PERIOD);
1035 ret = QLA_FUNCTION_FAILED;
1041 * qla2x00_wait_for_hba_online
1042 * Wait till the HBA is online after going through
1043 * <= MAX_RETRIES_OF_ISP_ABORT or
1044 * finally HBA is disabled ie marked offline
1047 * ha - pointer to host adapter structure
1050 * Does context switching-Release SPIN_LOCK
1051 * (if any) before calling this routine.
1054 * Success (Adapter is online) : 0
1055 * Failed (Adapter is offline/disabled) : 1
1058 qla2x00_wait_for_hba_online(scsi_qla_host_t *vha)
1061 unsigned long wait_online;
1062 struct qla_hw_data *ha = vha->hw;
1063 scsi_qla_host_t *base_vha = pci_get_drvdata(ha->pdev);
1065 wait_online = jiffies + (MAX_LOOP_TIMEOUT * HZ);
1066 while (((test_bit(ISP_ABORT_NEEDED, &base_vha->dpc_flags)) ||
1067 test_bit(ABORT_ISP_ACTIVE, &base_vha->dpc_flags) ||
1068 test_bit(ISP_ABORT_RETRY, &base_vha->dpc_flags) ||
1069 ha->dpc_active) && time_before(jiffies, wait_online)) {
1073 if (base_vha->flags.online)
1074 return_status = QLA_SUCCESS;
1076 return_status = QLA_FUNCTION_FAILED;
1078 return (return_status);
1081 static inline int test_fcport_count(scsi_qla_host_t *vha)
1083 struct qla_hw_data *ha = vha->hw;
1084 unsigned long flags;
1087 spin_lock_irqsave(&ha->tgt.sess_lock, flags);
1088 ql_dbg(ql_dbg_init, vha, 0x00ec,
1089 "tgt %p, fcport_count=%d\n",
1090 vha, vha->fcport_count);
1091 res = (vha->fcport_count == 0);
1092 spin_unlock_irqrestore(&ha->tgt.sess_lock, flags);
1098 * qla2x00_wait_for_sess_deletion can only be called from remove_one.
1099 * it has dependency on UNLOADING flag to stop device discovery
1102 qla2x00_wait_for_sess_deletion(scsi_qla_host_t *vha)
1104 qla2x00_mark_all_devices_lost(vha, 0);
1106 wait_event(vha->fcport_waitQ, test_fcport_count(vha));
1110 * qla2x00_wait_for_hba_ready
1111 * Wait till the HBA is ready before doing driver unload
1114 * ha - pointer to host adapter structure
1117 * Does context switching-Release SPIN_LOCK
1118 * (if any) before calling this routine.
1122 qla2x00_wait_for_hba_ready(scsi_qla_host_t *vha)
1124 struct qla_hw_data *ha = vha->hw;
1125 scsi_qla_host_t *base_vha = pci_get_drvdata(ha->pdev);
1127 while ((qla2x00_reset_active(vha) || ha->dpc_active ||
1128 ha->flags.mbox_busy) ||
1129 test_bit(FX00_RESET_RECOVERY, &vha->dpc_flags) ||
1130 test_bit(FX00_TARGET_SCAN, &vha->dpc_flags)) {
1131 if (test_bit(UNLOADING, &base_vha->dpc_flags))
1138 qla2x00_wait_for_chip_reset(scsi_qla_host_t *vha)
1141 unsigned long wait_reset;
1142 struct qla_hw_data *ha = vha->hw;
1143 scsi_qla_host_t *base_vha = pci_get_drvdata(ha->pdev);
1145 wait_reset = jiffies + (MAX_LOOP_TIMEOUT * HZ);
1146 while (((test_bit(ISP_ABORT_NEEDED, &base_vha->dpc_flags)) ||
1147 test_bit(ABORT_ISP_ACTIVE, &base_vha->dpc_flags) ||
1148 test_bit(ISP_ABORT_RETRY, &base_vha->dpc_flags) ||
1149 ha->dpc_active) && time_before(jiffies, wait_reset)) {
1153 if (!test_bit(ISP_ABORT_NEEDED, &base_vha->dpc_flags) &&
1154 ha->flags.chip_reset_done)
1157 if (ha->flags.chip_reset_done)
1158 return_status = QLA_SUCCESS;
1160 return_status = QLA_FUNCTION_FAILED;
1162 return return_status;
1166 sp_get(struct srb *sp)
1168 atomic_inc(&sp->ref_count);
1171 #define ISP_REG_DISCONNECT 0xffffffffU
1172 /**************************************************************************
1173 * qla2x00_isp_reg_stat
1176 * Read the host status register of ISP before aborting the command.
1179 * ha = pointer to host adapter structure.
1183 * Either true or false.
1185 * Note: Return true if there is register disconnect.
1186 **************************************************************************/
1188 uint32_t qla2x00_isp_reg_stat(struct qla_hw_data *ha)
1190 struct device_reg_24xx __iomem *reg = &ha->iobase->isp24;
1191 struct device_reg_82xx __iomem *reg82 = &ha->iobase->isp82;
1193 if (IS_P3P_TYPE(ha))
1194 return ((RD_REG_DWORD(®82->host_int)) == ISP_REG_DISCONNECT);
1196 return ((RD_REG_DWORD(®->host_status)) ==
1197 ISP_REG_DISCONNECT);
1200 /**************************************************************************
1204 * The abort function will abort the specified command.
1207 * cmd = Linux SCSI command packet to be aborted.
1210 * Either SUCCESS or FAILED.
1213 * Only return FAILED if command not returned by firmware.
1214 **************************************************************************/
1216 qla2xxx_eh_abort(struct scsi_cmnd *cmd)
1218 scsi_qla_host_t *vha = shost_priv(cmd->device->host);
1223 unsigned long flags;
1225 struct qla_hw_data *ha = vha->hw;
1227 if (qla2x00_isp_reg_stat(ha)) {
1228 ql_log(ql_log_info, vha, 0x8042,
1229 "PCI/Register disconnect, exiting.\n");
1235 ret = fc_block_scsi_eh(cmd);
1240 id = cmd->device->id;
1241 lun = cmd->device->lun;
1243 spin_lock_irqsave(&ha->hardware_lock, flags);
1244 sp = (srb_t *) CMD_SP(cmd);
1246 spin_unlock_irqrestore(&ha->hardware_lock, flags);
1250 ql_dbg(ql_dbg_taskm, vha, 0x8002,
1251 "Aborting from RISC nexus=%ld:%d:%llu sp=%p cmd=%p handle=%x\n",
1252 vha->host_no, id, lun, sp, cmd, sp->handle);
1254 /* Get a reference to the sp and drop the lock.*/
1257 spin_unlock_irqrestore(&ha->hardware_lock, flags);
1258 rval = ha->isp_ops->abort_command(sp);
1260 if (rval == QLA_FUNCTION_PARAMETER_ERROR)
1265 ql_dbg(ql_dbg_taskm, vha, 0x8003,
1266 "Abort command mbx failed cmd=%p, rval=%x.\n", cmd, rval);
1268 ql_dbg(ql_dbg_taskm, vha, 0x8004,
1269 "Abort command mbx success cmd=%p.\n", cmd);
1273 spin_lock_irqsave(&ha->hardware_lock, flags);
1275 spin_unlock_irqrestore(&ha->hardware_lock, flags);
1277 /* Did the command return during mailbox execution? */
1278 if (ret == FAILED && !CMD_SP(cmd))
1281 /* Wait for the command to be returned. */
1283 if (qla2x00_eh_wait_on_command(cmd) != QLA_SUCCESS) {
1284 ql_log(ql_log_warn, vha, 0x8006,
1285 "Abort handler timed out cmd=%p.\n", cmd);
1290 ql_log(ql_log_info, vha, 0x801c,
1291 "Abort command issued nexus=%ld:%d:%llu -- %d %x.\n",
1292 vha->host_no, id, lun, wait, ret);
1298 qla2x00_eh_wait_for_pending_commands(scsi_qla_host_t *vha, unsigned int t,
1299 uint64_t l, enum nexus_wait_type type)
1301 int cnt, match, status;
1302 unsigned long flags;
1303 struct qla_hw_data *ha = vha->hw;
1304 struct req_que *req;
1306 struct scsi_cmnd *cmd;
1308 status = QLA_SUCCESS;
1310 spin_lock_irqsave(&ha->hardware_lock, flags);
1312 for (cnt = 1; status == QLA_SUCCESS &&
1313 cnt < req->num_outstanding_cmds; cnt++) {
1314 sp = req->outstanding_cmds[cnt];
1317 if (sp->type != SRB_SCSI_CMD)
1319 if (vha->vp_idx != sp->vha->vp_idx)
1322 cmd = GET_CMD_SP(sp);
1328 match = cmd->device->id == t;
1331 match = (cmd->device->id == t &&
1332 cmd->device->lun == l);
1338 spin_unlock_irqrestore(&ha->hardware_lock, flags);
1339 status = qla2x00_eh_wait_on_command(cmd);
1340 spin_lock_irqsave(&ha->hardware_lock, flags);
1342 spin_unlock_irqrestore(&ha->hardware_lock, flags);
1347 static char *reset_errors[] = {
1350 "Task management failed",
1351 "Waiting for command completions",
1355 __qla2xxx_eh_generic_reset(char *name, enum nexus_wait_type type,
1356 struct scsi_cmnd *cmd, int (*do_reset)(struct fc_port *, uint64_t, int))
1358 scsi_qla_host_t *vha = shost_priv(cmd->device->host);
1359 fc_port_t *fcport = (struct fc_port *) cmd->device->hostdata;
1366 err = fc_block_scsi_eh(cmd);
1370 ql_log(ql_log_info, vha, 0x8009,
1371 "%s RESET ISSUED nexus=%ld:%d:%llu cmd=%p.\n", name, vha->host_no,
1372 cmd->device->id, cmd->device->lun, cmd);
1375 if (qla2x00_wait_for_hba_online(vha) != QLA_SUCCESS) {
1376 ql_log(ql_log_warn, vha, 0x800a,
1377 "Wait for hba online failed for cmd=%p.\n", cmd);
1378 goto eh_reset_failed;
1381 if (do_reset(fcport, cmd->device->lun, cmd->request->cpu + 1)
1383 ql_log(ql_log_warn, vha, 0x800c,
1384 "do_reset failed for cmd=%p.\n", cmd);
1385 goto eh_reset_failed;
1388 if (qla2x00_eh_wait_for_pending_commands(vha, cmd->device->id,
1389 cmd->device->lun, type) != QLA_SUCCESS) {
1390 ql_log(ql_log_warn, vha, 0x800d,
1391 "wait for pending cmds failed for cmd=%p.\n", cmd);
1392 goto eh_reset_failed;
1395 ql_log(ql_log_info, vha, 0x800e,
1396 "%s RESET SUCCEEDED nexus:%ld:%d:%llu cmd=%p.\n", name,
1397 vha->host_no, cmd->device->id, cmd->device->lun, cmd);
1402 ql_log(ql_log_info, vha, 0x800f,
1403 "%s RESET FAILED: %s nexus=%ld:%d:%llu cmd=%p.\n", name,
1404 reset_errors[err], vha->host_no, cmd->device->id, cmd->device->lun,
1410 qla2xxx_eh_device_reset(struct scsi_cmnd *cmd)
1412 scsi_qla_host_t *vha = shost_priv(cmd->device->host);
1413 struct qla_hw_data *ha = vha->hw;
1415 if (qla2x00_isp_reg_stat(ha)) {
1416 ql_log(ql_log_info, vha, 0x803e,
1417 "PCI/Register disconnect, exiting.\n");
1421 return __qla2xxx_eh_generic_reset("DEVICE", WAIT_LUN, cmd,
1422 ha->isp_ops->lun_reset);
1426 qla2xxx_eh_target_reset(struct scsi_cmnd *cmd)
1428 scsi_qla_host_t *vha = shost_priv(cmd->device->host);
1429 struct qla_hw_data *ha = vha->hw;
1431 if (qla2x00_isp_reg_stat(ha)) {
1432 ql_log(ql_log_info, vha, 0x803f,
1433 "PCI/Register disconnect, exiting.\n");
1437 return __qla2xxx_eh_generic_reset("TARGET", WAIT_TARGET, cmd,
1438 ha->isp_ops->target_reset);
1441 /**************************************************************************
1442 * qla2xxx_eh_bus_reset
1445 * The bus reset function will reset the bus and abort any executing
1449 * cmd = Linux SCSI command packet of the command that cause the
1453 * SUCCESS/FAILURE (defined as macro in scsi.h).
1455 **************************************************************************/
1457 qla2xxx_eh_bus_reset(struct scsi_cmnd *cmd)
1459 scsi_qla_host_t *vha = shost_priv(cmd->device->host);
1460 fc_port_t *fcport = (struct fc_port *) cmd->device->hostdata;
1464 struct qla_hw_data *ha = vha->hw;
1466 if (qla2x00_isp_reg_stat(ha)) {
1467 ql_log(ql_log_info, vha, 0x8040,
1468 "PCI/Register disconnect, exiting.\n");
1472 id = cmd->device->id;
1473 lun = cmd->device->lun;
1479 ret = fc_block_scsi_eh(cmd);
1484 ql_log(ql_log_info, vha, 0x8012,
1485 "BUS RESET ISSUED nexus=%ld:%d:%llu.\n", vha->host_no, id, lun);
1487 if (qla2x00_wait_for_hba_online(vha) != QLA_SUCCESS) {
1488 ql_log(ql_log_fatal, vha, 0x8013,
1489 "Wait for hba online failed board disabled.\n");
1490 goto eh_bus_reset_done;
1493 if (qla2x00_loop_reset(vha) == QLA_SUCCESS)
1497 goto eh_bus_reset_done;
1499 /* Flush outstanding commands. */
1500 if (qla2x00_eh_wait_for_pending_commands(vha, 0, 0, WAIT_HOST) !=
1502 ql_log(ql_log_warn, vha, 0x8014,
1503 "Wait for pending commands failed.\n");
1508 ql_log(ql_log_warn, vha, 0x802b,
1509 "BUS RESET %s nexus=%ld:%d:%llu.\n",
1510 (ret == FAILED) ? "FAILED" : "SUCCEEDED", vha->host_no, id, lun);
1515 /**************************************************************************
1516 * qla2xxx_eh_host_reset
1519 * The reset function will reset the Adapter.
1522 * cmd = Linux SCSI command packet of the command that cause the
1526 * Either SUCCESS or FAILED.
1529 **************************************************************************/
1531 qla2xxx_eh_host_reset(struct scsi_cmnd *cmd)
1533 scsi_qla_host_t *vha = shost_priv(cmd->device->host);
1534 struct qla_hw_data *ha = vha->hw;
1538 scsi_qla_host_t *base_vha = pci_get_drvdata(ha->pdev);
1540 if (qla2x00_isp_reg_stat(ha)) {
1541 ql_log(ql_log_info, vha, 0x8041,
1542 "PCI/Register disconnect, exiting.\n");
1543 schedule_work(&ha->board_disable);
1547 id = cmd->device->id;
1548 lun = cmd->device->lun;
1550 ql_log(ql_log_info, vha, 0x8018,
1551 "ADAPTER RESET ISSUED nexus=%ld:%d:%llu.\n", vha->host_no, id, lun);
1554 * No point in issuing another reset if one is active. Also do not
1555 * attempt a reset if we are updating flash.
1557 if (qla2x00_reset_active(vha) || ha->optrom_state != QLA_SWAITING)
1558 goto eh_host_reset_lock;
1560 if (vha != base_vha) {
1561 if (qla2x00_vp_abort_isp(vha))
1562 goto eh_host_reset_lock;
1564 if (IS_P3P_TYPE(vha->hw)) {
1565 if (!qla82xx_fcoe_ctx_reset(vha)) {
1566 /* Ctx reset success */
1568 goto eh_host_reset_lock;
1570 /* fall thru if ctx reset failed */
1573 flush_workqueue(ha->wq);
1575 set_bit(ABORT_ISP_ACTIVE, &base_vha->dpc_flags);
1576 if (ha->isp_ops->abort_isp(base_vha)) {
1577 clear_bit(ABORT_ISP_ACTIVE, &base_vha->dpc_flags);
1578 /* failed. schedule dpc to try */
1579 set_bit(ISP_ABORT_NEEDED, &base_vha->dpc_flags);
1581 if (qla2x00_wait_for_hba_online(vha) != QLA_SUCCESS) {
1582 ql_log(ql_log_warn, vha, 0x802a,
1583 "wait for hba online failed.\n");
1584 goto eh_host_reset_lock;
1587 clear_bit(ABORT_ISP_ACTIVE, &base_vha->dpc_flags);
1590 /* Waiting for command to be returned to OS.*/
1591 if (qla2x00_eh_wait_for_pending_commands(vha, 0, 0, WAIT_HOST) ==
1596 ql_log(ql_log_info, vha, 0x8017,
1597 "ADAPTER RESET %s nexus=%ld:%d:%llu.\n",
1598 (ret == FAILED) ? "FAILED" : "SUCCEEDED", vha->host_no, id, lun);
1604 * qla2x00_loop_reset
1608 * ha = adapter block pointer.
1614 qla2x00_loop_reset(scsi_qla_host_t *vha)
1617 struct fc_port *fcport;
1618 struct qla_hw_data *ha = vha->hw;
1620 if (IS_QLAFX00(ha)) {
1621 return qlafx00_loop_reset(vha);
1624 if (ql2xtargetreset == 1 && ha->flags.enable_target_reset) {
1625 list_for_each_entry(fcport, &vha->vp_fcports, list) {
1626 if (fcport->port_type != FCT_TARGET)
1629 ret = ha->isp_ops->target_reset(fcport, 0, 0);
1630 if (ret != QLA_SUCCESS) {
1631 ql_dbg(ql_dbg_taskm, vha, 0x802c,
1632 "Bus Reset failed: Reset=%d "
1633 "d_id=%x.\n", ret, fcport->d_id.b24);
1639 if (ha->flags.enable_lip_full_login && !IS_CNA_CAPABLE(ha)) {
1640 atomic_set(&vha->loop_state, LOOP_DOWN);
1641 atomic_set(&vha->loop_down_timer, LOOP_DOWN_TIME);
1642 qla2x00_mark_all_devices_lost(vha, 0);
1643 ret = qla2x00_full_login_lip(vha);
1644 if (ret != QLA_SUCCESS) {
1645 ql_dbg(ql_dbg_taskm, vha, 0x802d,
1646 "full_login_lip=%d.\n", ret);
1650 if (ha->flags.enable_lip_reset) {
1651 ret = qla2x00_lip_reset(vha);
1652 if (ret != QLA_SUCCESS)
1653 ql_dbg(ql_dbg_taskm, vha, 0x802e,
1654 "lip_reset failed (%d).\n", ret);
1657 /* Issue marker command only when we are going to start the I/O */
1658 vha->marker_needed = 1;
1664 qla2x00_abort_all_cmds(scsi_qla_host_t *vha, int res)
1666 int que, cnt, status;
1667 unsigned long flags;
1669 struct qla_hw_data *ha = vha->hw;
1670 struct req_que *req;
1671 struct qla_tgt *tgt = vha->vha_tgt.qla_tgt;
1672 struct qla_tgt_cmd *cmd;
1675 spin_lock_irqsave(&ha->hardware_lock, flags);
1676 for (que = 0; que < ha->max_req_queues; que++) {
1677 req = ha->req_q_map[que];
1680 if (!req->outstanding_cmds)
1682 for (cnt = 1; cnt < req->num_outstanding_cmds; cnt++) {
1683 sp = req->outstanding_cmds[cnt];
1685 req->outstanding_cmds[cnt] = NULL;
1686 if (sp->cmd_type == TYPE_SRB) {
1688 * Don't abort commands in adapter
1689 * during EEH recovery as it's not
1690 * accessible/responding.
1692 if (GET_CMD_SP(sp) &&
1693 !ha->flags.eeh_busy &&
1694 (sp->type == SRB_SCSI_CMD)) {
1696 * Get a reference to the sp
1697 * and drop the lock. The
1698 * reference ensures this
1699 * sp->done() call and not the
1700 * call in qla2xxx_eh_abort()
1701 * ends the SCSI command (with
1705 spin_unlock_irqrestore(
1706 &ha->hardware_lock, flags);
1707 status = qla2xxx_eh_abort(
1710 &ha->hardware_lock, flags);
1712 * Get rid of extra reference
1713 * if immediate exit from
1716 if (status == FAILED &&
1717 (qla2x00_isp_reg_stat(ha)))
1723 if (!vha->hw->tgt.tgt_ops || !tgt ||
1724 qla_ini_mode_enabled(vha)) {
1726 ql_dbg(ql_dbg_tgt_mgt,
1728 "HOST-ABORT-HNDLR: dpc_flags=%lx. Target mode disabled\n",
1732 cmd = (struct qla_tgt_cmd *)sp;
1733 qlt_abort_cmd_on_host_reset(cmd->vha,
1739 spin_unlock_irqrestore(&ha->hardware_lock, flags);
1743 qla2xxx_slave_alloc(struct scsi_device *sdev)
1745 struct fc_rport *rport = starget_to_rport(scsi_target(sdev));
1747 if (!rport || fc_remote_port_chkready(rport))
1750 sdev->hostdata = *(fc_port_t **)rport->dd_data;
1756 qla2xxx_slave_configure(struct scsi_device *sdev)
1758 scsi_qla_host_t *vha = shost_priv(sdev->host);
1759 struct req_que *req = vha->req;
1761 if (IS_T10_PI_CAPABLE(vha->hw))
1762 blk_queue_update_dma_alignment(sdev->request_queue, 0x7);
1764 scsi_change_queue_depth(sdev, req->max_q_depth);
1769 qla2xxx_slave_destroy(struct scsi_device *sdev)
1771 sdev->hostdata = NULL;
1775 * qla2x00_config_dma_addressing() - Configure OS DMA addressing method.
1778 * At exit, the @ha's flags.enable_64bit_addressing set to indicated
1779 * supported addressing method.
1782 qla2x00_config_dma_addressing(struct qla_hw_data *ha)
1784 /* Assume a 32bit DMA mask. */
1785 ha->flags.enable_64bit_addressing = 0;
1787 if (!dma_set_mask(&ha->pdev->dev, DMA_BIT_MASK(64))) {
1788 /* Any upper-dword bits set? */
1789 if (MSD(dma_get_required_mask(&ha->pdev->dev)) &&
1790 !pci_set_consistent_dma_mask(ha->pdev, DMA_BIT_MASK(64))) {
1791 /* Ok, a 64bit DMA mask is applicable. */
1792 ha->flags.enable_64bit_addressing = 1;
1793 ha->isp_ops->calc_req_entries = qla2x00_calc_iocbs_64;
1794 ha->isp_ops->build_iocbs = qla2x00_build_scsi_iocbs_64;
1799 dma_set_mask(&ha->pdev->dev, DMA_BIT_MASK(32));
1800 pci_set_consistent_dma_mask(ha->pdev, DMA_BIT_MASK(32));
1804 qla2x00_enable_intrs(struct qla_hw_data *ha)
1806 unsigned long flags = 0;
1807 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
1809 spin_lock_irqsave(&ha->hardware_lock, flags);
1810 ha->interrupts_on = 1;
1811 /* enable risc and host interrupts */
1812 WRT_REG_WORD(®->ictrl, ICR_EN_INT | ICR_EN_RISC);
1813 RD_REG_WORD(®->ictrl);
1814 spin_unlock_irqrestore(&ha->hardware_lock, flags);
1819 qla2x00_disable_intrs(struct qla_hw_data *ha)
1821 unsigned long flags = 0;
1822 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
1824 spin_lock_irqsave(&ha->hardware_lock, flags);
1825 ha->interrupts_on = 0;
1826 /* disable risc and host interrupts */
1827 WRT_REG_WORD(®->ictrl, 0);
1828 RD_REG_WORD(®->ictrl);
1829 spin_unlock_irqrestore(&ha->hardware_lock, flags);
1833 qla24xx_enable_intrs(struct qla_hw_data *ha)
1835 unsigned long flags = 0;
1836 struct device_reg_24xx __iomem *reg = &ha->iobase->isp24;
1838 spin_lock_irqsave(&ha->hardware_lock, flags);
1839 ha->interrupts_on = 1;
1840 WRT_REG_DWORD(®->ictrl, ICRX_EN_RISC_INT);
1841 RD_REG_DWORD(®->ictrl);
1842 spin_unlock_irqrestore(&ha->hardware_lock, flags);
1846 qla24xx_disable_intrs(struct qla_hw_data *ha)
1848 unsigned long flags = 0;
1849 struct device_reg_24xx __iomem *reg = &ha->iobase->isp24;
1851 if (IS_NOPOLLING_TYPE(ha))
1853 spin_lock_irqsave(&ha->hardware_lock, flags);
1854 ha->interrupts_on = 0;
1855 WRT_REG_DWORD(®->ictrl, 0);
1856 RD_REG_DWORD(®->ictrl);
1857 spin_unlock_irqrestore(&ha->hardware_lock, flags);
1861 qla2x00_iospace_config(struct qla_hw_data *ha)
1863 resource_size_t pio;
1866 if (pci_request_selected_regions(ha->pdev, ha->bars,
1867 QLA2XXX_DRIVER_NAME)) {
1868 ql_log_pci(ql_log_fatal, ha->pdev, 0x0011,
1869 "Failed to reserve PIO/MMIO regions (%s), aborting.\n",
1870 pci_name(ha->pdev));
1871 goto iospace_error_exit;
1873 if (!(ha->bars & 1))
1876 /* We only need PIO for Flash operations on ISP2312 v2 chips. */
1877 pio = pci_resource_start(ha->pdev, 0);
1878 if (pci_resource_flags(ha->pdev, 0) & IORESOURCE_IO) {
1879 if (pci_resource_len(ha->pdev, 0) < MIN_IOBASE_LEN) {
1880 ql_log_pci(ql_log_warn, ha->pdev, 0x0012,
1881 "Invalid pci I/O region size (%s).\n",
1882 pci_name(ha->pdev));
1886 ql_log_pci(ql_log_warn, ha->pdev, 0x0013,
1887 "Region #0 no a PIO resource (%s).\n",
1888 pci_name(ha->pdev));
1891 ha->pio_address = pio;
1892 ql_dbg_pci(ql_dbg_init, ha->pdev, 0x0014,
1893 "PIO address=%llu.\n",
1894 (unsigned long long)ha->pio_address);
1897 /* Use MMIO operations for all accesses. */
1898 if (!(pci_resource_flags(ha->pdev, 1) & IORESOURCE_MEM)) {
1899 ql_log_pci(ql_log_fatal, ha->pdev, 0x0015,
1900 "Region #1 not an MMIO resource (%s), aborting.\n",
1901 pci_name(ha->pdev));
1902 goto iospace_error_exit;
1904 if (pci_resource_len(ha->pdev, 1) < MIN_IOBASE_LEN) {
1905 ql_log_pci(ql_log_fatal, ha->pdev, 0x0016,
1906 "Invalid PCI mem region size (%s), aborting.\n",
1907 pci_name(ha->pdev));
1908 goto iospace_error_exit;
1911 ha->iobase = ioremap(pci_resource_start(ha->pdev, 1), MIN_IOBASE_LEN);
1913 ql_log_pci(ql_log_fatal, ha->pdev, 0x0017,
1914 "Cannot remap MMIO (%s), aborting.\n",
1915 pci_name(ha->pdev));
1916 goto iospace_error_exit;
1919 /* Determine queue resources */
1920 ha->max_req_queues = ha->max_rsp_queues = 1;
1921 ha->msix_count = QLA_BASE_VECTORS;
1922 if (!ql2xmqsupport || (!IS_QLA25XX(ha) && !IS_QLA81XX(ha)))
1925 ha->mqiobase = ioremap(pci_resource_start(ha->pdev, 3),
1926 pci_resource_len(ha->pdev, 3));
1928 ql_dbg_pci(ql_dbg_init, ha->pdev, 0x0018,
1929 "MQIO Base=%p.\n", ha->mqiobase);
1930 /* Read MSIX vector size of the board */
1931 pci_read_config_word(ha->pdev, QLA_PCI_MSIX_CONTROL, &msix);
1932 ha->msix_count = msix + 1;
1933 /* Max queues are bounded by available msix vectors */
1934 /* MB interrupt uses 1 vector */
1935 ha->max_req_queues = ha->msix_count - 1;
1936 ha->max_rsp_queues = ha->max_req_queues;
1937 /* Queue pairs is the max value minus the base queue pair */
1938 ha->max_qpairs = ha->max_rsp_queues - 1;
1939 ql_dbg_pci(ql_dbg_init, ha->pdev, 0x0188,
1940 "Max no of queues pairs: %d.\n", ha->max_qpairs);
1942 ql_log_pci(ql_log_info, ha->pdev, 0x001a,
1943 "MSI-X vector count: %d.\n", ha->msix_count);
1945 ql_log_pci(ql_log_info, ha->pdev, 0x001b,
1946 "BAR 3 not enabled.\n");
1949 ql_dbg_pci(ql_dbg_init, ha->pdev, 0x001c,
1950 "MSIX Count: %d.\n", ha->msix_count);
1959 qla83xx_iospace_config(struct qla_hw_data *ha)
1963 if (pci_request_selected_regions(ha->pdev, ha->bars,
1964 QLA2XXX_DRIVER_NAME)) {
1965 ql_log_pci(ql_log_fatal, ha->pdev, 0x0117,
1966 "Failed to reserve PIO/MMIO regions (%s), aborting.\n",
1967 pci_name(ha->pdev));
1969 goto iospace_error_exit;
1972 /* Use MMIO operations for all accesses. */
1973 if (!(pci_resource_flags(ha->pdev, 0) & IORESOURCE_MEM)) {
1974 ql_log_pci(ql_log_warn, ha->pdev, 0x0118,
1975 "Invalid pci I/O region size (%s).\n",
1976 pci_name(ha->pdev));
1977 goto iospace_error_exit;
1979 if (pci_resource_len(ha->pdev, 0) < MIN_IOBASE_LEN) {
1980 ql_log_pci(ql_log_warn, ha->pdev, 0x0119,
1981 "Invalid PCI mem region size (%s), aborting\n",
1982 pci_name(ha->pdev));
1983 goto iospace_error_exit;
1986 ha->iobase = ioremap(pci_resource_start(ha->pdev, 0), MIN_IOBASE_LEN);
1988 ql_log_pci(ql_log_fatal, ha->pdev, 0x011a,
1989 "Cannot remap MMIO (%s), aborting.\n",
1990 pci_name(ha->pdev));
1991 goto iospace_error_exit;
1994 /* 64bit PCI BAR - BAR2 will correspoond to region 4 */
1995 /* 83XX 26XX always use MQ type access for queues
1996 * - mbar 2, a.k.a region 4 */
1997 ha->max_req_queues = ha->max_rsp_queues = 1;
1998 ha->msix_count = QLA_BASE_VECTORS;
1999 ha->mqiobase = ioremap(pci_resource_start(ha->pdev, 4),
2000 pci_resource_len(ha->pdev, 4));
2002 if (!ha->mqiobase) {
2003 ql_log_pci(ql_log_fatal, ha->pdev, 0x011d,
2004 "BAR2/region4 not enabled\n");
2008 ha->msixbase = ioremap(pci_resource_start(ha->pdev, 2),
2009 pci_resource_len(ha->pdev, 2));
2011 /* Read MSIX vector size of the board */
2012 pci_read_config_word(ha->pdev,
2013 QLA_83XX_PCI_MSIX_CONTROL, &msix);
2014 ha->msix_count = (msix & PCI_MSIX_FLAGS_QSIZE) + 1;
2016 * By default, driver uses at least two msix vectors
2019 if (ql2xmqsupport) {
2020 /* MB interrupt uses 1 vector */
2021 ha->max_req_queues = ha->msix_count - 1;
2023 /* ATIOQ needs 1 vector. That's 1 less QPair */
2024 if (QLA_TGT_MODE_ENABLED())
2025 ha->max_req_queues--;
2027 ha->max_rsp_queues = ha->max_req_queues;
2029 /* Queue pairs is the max value minus
2030 * the base queue pair */
2031 ha->max_qpairs = ha->max_req_queues - 1;
2032 ql_dbg_pci(ql_dbg_init, ha->pdev, 0x00e3,
2033 "Max no of queues pairs: %d.\n", ha->max_qpairs);
2035 ql_log_pci(ql_log_info, ha->pdev, 0x011c,
2036 "MSI-X vector count: %d.\n", ha->msix_count);
2038 ql_log_pci(ql_log_info, ha->pdev, 0x011e,
2039 "BAR 1 not enabled.\n");
2042 ql_dbg_pci(ql_dbg_init, ha->pdev, 0x011f,
2043 "MSIX Count: %d.\n", ha->msix_count);
2050 static struct isp_operations qla2100_isp_ops = {
2051 .pci_config = qla2100_pci_config,
2052 .reset_chip = qla2x00_reset_chip,
2053 .chip_diag = qla2x00_chip_diag,
2054 .config_rings = qla2x00_config_rings,
2055 .reset_adapter = qla2x00_reset_adapter,
2056 .nvram_config = qla2x00_nvram_config,
2057 .update_fw_options = qla2x00_update_fw_options,
2058 .load_risc = qla2x00_load_risc,
2059 .pci_info_str = qla2x00_pci_info_str,
2060 .fw_version_str = qla2x00_fw_version_str,
2061 .intr_handler = qla2100_intr_handler,
2062 .enable_intrs = qla2x00_enable_intrs,
2063 .disable_intrs = qla2x00_disable_intrs,
2064 .abort_command = qla2x00_abort_command,
2065 .target_reset = qla2x00_abort_target,
2066 .lun_reset = qla2x00_lun_reset,
2067 .fabric_login = qla2x00_login_fabric,
2068 .fabric_logout = qla2x00_fabric_logout,
2069 .calc_req_entries = qla2x00_calc_iocbs_32,
2070 .build_iocbs = qla2x00_build_scsi_iocbs_32,
2071 .prep_ms_iocb = qla2x00_prep_ms_iocb,
2072 .prep_ms_fdmi_iocb = qla2x00_prep_ms_fdmi_iocb,
2073 .read_nvram = qla2x00_read_nvram_data,
2074 .write_nvram = qla2x00_write_nvram_data,
2075 .fw_dump = qla2100_fw_dump,
2078 .beacon_blink = NULL,
2079 .read_optrom = qla2x00_read_optrom_data,
2080 .write_optrom = qla2x00_write_optrom_data,
2081 .get_flash_version = qla2x00_get_flash_version,
2082 .start_scsi = qla2x00_start_scsi,
2083 .start_scsi_mq = NULL,
2084 .abort_isp = qla2x00_abort_isp,
2085 .iospace_config = qla2x00_iospace_config,
2086 .initialize_adapter = qla2x00_initialize_adapter,
2089 static struct isp_operations qla2300_isp_ops = {
2090 .pci_config = qla2300_pci_config,
2091 .reset_chip = qla2x00_reset_chip,
2092 .chip_diag = qla2x00_chip_diag,
2093 .config_rings = qla2x00_config_rings,
2094 .reset_adapter = qla2x00_reset_adapter,
2095 .nvram_config = qla2x00_nvram_config,
2096 .update_fw_options = qla2x00_update_fw_options,
2097 .load_risc = qla2x00_load_risc,
2098 .pci_info_str = qla2x00_pci_info_str,
2099 .fw_version_str = qla2x00_fw_version_str,
2100 .intr_handler = qla2300_intr_handler,
2101 .enable_intrs = qla2x00_enable_intrs,
2102 .disable_intrs = qla2x00_disable_intrs,
2103 .abort_command = qla2x00_abort_command,
2104 .target_reset = qla2x00_abort_target,
2105 .lun_reset = qla2x00_lun_reset,
2106 .fabric_login = qla2x00_login_fabric,
2107 .fabric_logout = qla2x00_fabric_logout,
2108 .calc_req_entries = qla2x00_calc_iocbs_32,
2109 .build_iocbs = qla2x00_build_scsi_iocbs_32,
2110 .prep_ms_iocb = qla2x00_prep_ms_iocb,
2111 .prep_ms_fdmi_iocb = qla2x00_prep_ms_fdmi_iocb,
2112 .read_nvram = qla2x00_read_nvram_data,
2113 .write_nvram = qla2x00_write_nvram_data,
2114 .fw_dump = qla2300_fw_dump,
2115 .beacon_on = qla2x00_beacon_on,
2116 .beacon_off = qla2x00_beacon_off,
2117 .beacon_blink = qla2x00_beacon_blink,
2118 .read_optrom = qla2x00_read_optrom_data,
2119 .write_optrom = qla2x00_write_optrom_data,
2120 .get_flash_version = qla2x00_get_flash_version,
2121 .start_scsi = qla2x00_start_scsi,
2122 .start_scsi_mq = NULL,
2123 .abort_isp = qla2x00_abort_isp,
2124 .iospace_config = qla2x00_iospace_config,
2125 .initialize_adapter = qla2x00_initialize_adapter,
2128 static struct isp_operations qla24xx_isp_ops = {
2129 .pci_config = qla24xx_pci_config,
2130 .reset_chip = qla24xx_reset_chip,
2131 .chip_diag = qla24xx_chip_diag,
2132 .config_rings = qla24xx_config_rings,
2133 .reset_adapter = qla24xx_reset_adapter,
2134 .nvram_config = qla24xx_nvram_config,
2135 .update_fw_options = qla24xx_update_fw_options,
2136 .load_risc = qla24xx_load_risc,
2137 .pci_info_str = qla24xx_pci_info_str,
2138 .fw_version_str = qla24xx_fw_version_str,
2139 .intr_handler = qla24xx_intr_handler,
2140 .enable_intrs = qla24xx_enable_intrs,
2141 .disable_intrs = qla24xx_disable_intrs,
2142 .abort_command = qla24xx_abort_command,
2143 .target_reset = qla24xx_abort_target,
2144 .lun_reset = qla24xx_lun_reset,
2145 .fabric_login = qla24xx_login_fabric,
2146 .fabric_logout = qla24xx_fabric_logout,
2147 .calc_req_entries = NULL,
2148 .build_iocbs = NULL,
2149 .prep_ms_iocb = qla24xx_prep_ms_iocb,
2150 .prep_ms_fdmi_iocb = qla24xx_prep_ms_fdmi_iocb,
2151 .read_nvram = qla24xx_read_nvram_data,
2152 .write_nvram = qla24xx_write_nvram_data,
2153 .fw_dump = qla24xx_fw_dump,
2154 .beacon_on = qla24xx_beacon_on,
2155 .beacon_off = qla24xx_beacon_off,
2156 .beacon_blink = qla24xx_beacon_blink,
2157 .read_optrom = qla24xx_read_optrom_data,
2158 .write_optrom = qla24xx_write_optrom_data,
2159 .get_flash_version = qla24xx_get_flash_version,
2160 .start_scsi = qla24xx_start_scsi,
2161 .start_scsi_mq = NULL,
2162 .abort_isp = qla2x00_abort_isp,
2163 .iospace_config = qla2x00_iospace_config,
2164 .initialize_adapter = qla2x00_initialize_adapter,
2167 static struct isp_operations qla25xx_isp_ops = {
2168 .pci_config = qla25xx_pci_config,
2169 .reset_chip = qla24xx_reset_chip,
2170 .chip_diag = qla24xx_chip_diag,
2171 .config_rings = qla24xx_config_rings,
2172 .reset_adapter = qla24xx_reset_adapter,
2173 .nvram_config = qla24xx_nvram_config,
2174 .update_fw_options = qla24xx_update_fw_options,
2175 .load_risc = qla24xx_load_risc,
2176 .pci_info_str = qla24xx_pci_info_str,
2177 .fw_version_str = qla24xx_fw_version_str,
2178 .intr_handler = qla24xx_intr_handler,
2179 .enable_intrs = qla24xx_enable_intrs,
2180 .disable_intrs = qla24xx_disable_intrs,
2181 .abort_command = qla24xx_abort_command,
2182 .target_reset = qla24xx_abort_target,
2183 .lun_reset = qla24xx_lun_reset,
2184 .fabric_login = qla24xx_login_fabric,
2185 .fabric_logout = qla24xx_fabric_logout,
2186 .calc_req_entries = NULL,
2187 .build_iocbs = NULL,
2188 .prep_ms_iocb = qla24xx_prep_ms_iocb,
2189 .prep_ms_fdmi_iocb = qla24xx_prep_ms_fdmi_iocb,
2190 .read_nvram = qla25xx_read_nvram_data,
2191 .write_nvram = qla25xx_write_nvram_data,
2192 .fw_dump = qla25xx_fw_dump,
2193 .beacon_on = qla24xx_beacon_on,
2194 .beacon_off = qla24xx_beacon_off,
2195 .beacon_blink = qla24xx_beacon_blink,
2196 .read_optrom = qla25xx_read_optrom_data,
2197 .write_optrom = qla24xx_write_optrom_data,
2198 .get_flash_version = qla24xx_get_flash_version,
2199 .start_scsi = qla24xx_dif_start_scsi,
2200 .start_scsi_mq = qla2xxx_dif_start_scsi_mq,
2201 .abort_isp = qla2x00_abort_isp,
2202 .iospace_config = qla2x00_iospace_config,
2203 .initialize_adapter = qla2x00_initialize_adapter,
2206 static struct isp_operations qla81xx_isp_ops = {
2207 .pci_config = qla25xx_pci_config,
2208 .reset_chip = qla24xx_reset_chip,
2209 .chip_diag = qla24xx_chip_diag,
2210 .config_rings = qla24xx_config_rings,
2211 .reset_adapter = qla24xx_reset_adapter,
2212 .nvram_config = qla81xx_nvram_config,
2213 .update_fw_options = qla81xx_update_fw_options,
2214 .load_risc = qla81xx_load_risc,
2215 .pci_info_str = qla24xx_pci_info_str,
2216 .fw_version_str = qla24xx_fw_version_str,
2217 .intr_handler = qla24xx_intr_handler,
2218 .enable_intrs = qla24xx_enable_intrs,
2219 .disable_intrs = qla24xx_disable_intrs,
2220 .abort_command = qla24xx_abort_command,
2221 .target_reset = qla24xx_abort_target,
2222 .lun_reset = qla24xx_lun_reset,
2223 .fabric_login = qla24xx_login_fabric,
2224 .fabric_logout = qla24xx_fabric_logout,
2225 .calc_req_entries = NULL,
2226 .build_iocbs = NULL,
2227 .prep_ms_iocb = qla24xx_prep_ms_iocb,
2228 .prep_ms_fdmi_iocb = qla24xx_prep_ms_fdmi_iocb,
2230 .write_nvram = NULL,
2231 .fw_dump = qla81xx_fw_dump,
2232 .beacon_on = qla24xx_beacon_on,
2233 .beacon_off = qla24xx_beacon_off,
2234 .beacon_blink = qla83xx_beacon_blink,
2235 .read_optrom = qla25xx_read_optrom_data,
2236 .write_optrom = qla24xx_write_optrom_data,
2237 .get_flash_version = qla24xx_get_flash_version,
2238 .start_scsi = qla24xx_dif_start_scsi,
2239 .start_scsi_mq = qla2xxx_dif_start_scsi_mq,
2240 .abort_isp = qla2x00_abort_isp,
2241 .iospace_config = qla2x00_iospace_config,
2242 .initialize_adapter = qla2x00_initialize_adapter,
2245 static struct isp_operations qla82xx_isp_ops = {
2246 .pci_config = qla82xx_pci_config,
2247 .reset_chip = qla82xx_reset_chip,
2248 .chip_diag = qla24xx_chip_diag,
2249 .config_rings = qla82xx_config_rings,
2250 .reset_adapter = qla24xx_reset_adapter,
2251 .nvram_config = qla81xx_nvram_config,
2252 .update_fw_options = qla24xx_update_fw_options,
2253 .load_risc = qla82xx_load_risc,
2254 .pci_info_str = qla24xx_pci_info_str,
2255 .fw_version_str = qla24xx_fw_version_str,
2256 .intr_handler = qla82xx_intr_handler,
2257 .enable_intrs = qla82xx_enable_intrs,
2258 .disable_intrs = qla82xx_disable_intrs,
2259 .abort_command = qla24xx_abort_command,
2260 .target_reset = qla24xx_abort_target,
2261 .lun_reset = qla24xx_lun_reset,
2262 .fabric_login = qla24xx_login_fabric,
2263 .fabric_logout = qla24xx_fabric_logout,
2264 .calc_req_entries = NULL,
2265 .build_iocbs = NULL,
2266 .prep_ms_iocb = qla24xx_prep_ms_iocb,
2267 .prep_ms_fdmi_iocb = qla24xx_prep_ms_fdmi_iocb,
2268 .read_nvram = qla24xx_read_nvram_data,
2269 .write_nvram = qla24xx_write_nvram_data,
2270 .fw_dump = qla82xx_fw_dump,
2271 .beacon_on = qla82xx_beacon_on,
2272 .beacon_off = qla82xx_beacon_off,
2273 .beacon_blink = NULL,
2274 .read_optrom = qla82xx_read_optrom_data,
2275 .write_optrom = qla82xx_write_optrom_data,
2276 .get_flash_version = qla82xx_get_flash_version,
2277 .start_scsi = qla82xx_start_scsi,
2278 .start_scsi_mq = NULL,
2279 .abort_isp = qla82xx_abort_isp,
2280 .iospace_config = qla82xx_iospace_config,
2281 .initialize_adapter = qla2x00_initialize_adapter,
2284 static struct isp_operations qla8044_isp_ops = {
2285 .pci_config = qla82xx_pci_config,
2286 .reset_chip = qla82xx_reset_chip,
2287 .chip_diag = qla24xx_chip_diag,
2288 .config_rings = qla82xx_config_rings,
2289 .reset_adapter = qla24xx_reset_adapter,
2290 .nvram_config = qla81xx_nvram_config,
2291 .update_fw_options = qla24xx_update_fw_options,
2292 .load_risc = qla82xx_load_risc,
2293 .pci_info_str = qla24xx_pci_info_str,
2294 .fw_version_str = qla24xx_fw_version_str,
2295 .intr_handler = qla8044_intr_handler,
2296 .enable_intrs = qla82xx_enable_intrs,
2297 .disable_intrs = qla82xx_disable_intrs,
2298 .abort_command = qla24xx_abort_command,
2299 .target_reset = qla24xx_abort_target,
2300 .lun_reset = qla24xx_lun_reset,
2301 .fabric_login = qla24xx_login_fabric,
2302 .fabric_logout = qla24xx_fabric_logout,
2303 .calc_req_entries = NULL,
2304 .build_iocbs = NULL,
2305 .prep_ms_iocb = qla24xx_prep_ms_iocb,
2306 .prep_ms_fdmi_iocb = qla24xx_prep_ms_fdmi_iocb,
2308 .write_nvram = NULL,
2309 .fw_dump = qla8044_fw_dump,
2310 .beacon_on = qla82xx_beacon_on,
2311 .beacon_off = qla82xx_beacon_off,
2312 .beacon_blink = NULL,
2313 .read_optrom = qla8044_read_optrom_data,
2314 .write_optrom = qla8044_write_optrom_data,
2315 .get_flash_version = qla82xx_get_flash_version,
2316 .start_scsi = qla82xx_start_scsi,
2317 .start_scsi_mq = NULL,
2318 .abort_isp = qla8044_abort_isp,
2319 .iospace_config = qla82xx_iospace_config,
2320 .initialize_adapter = qla2x00_initialize_adapter,
2323 static struct isp_operations qla83xx_isp_ops = {
2324 .pci_config = qla25xx_pci_config,
2325 .reset_chip = qla24xx_reset_chip,
2326 .chip_diag = qla24xx_chip_diag,
2327 .config_rings = qla24xx_config_rings,
2328 .reset_adapter = qla24xx_reset_adapter,
2329 .nvram_config = qla81xx_nvram_config,
2330 .update_fw_options = qla81xx_update_fw_options,
2331 .load_risc = qla81xx_load_risc,
2332 .pci_info_str = qla24xx_pci_info_str,
2333 .fw_version_str = qla24xx_fw_version_str,
2334 .intr_handler = qla24xx_intr_handler,
2335 .enable_intrs = qla24xx_enable_intrs,
2336 .disable_intrs = qla24xx_disable_intrs,
2337 .abort_command = qla24xx_abort_command,
2338 .target_reset = qla24xx_abort_target,
2339 .lun_reset = qla24xx_lun_reset,
2340 .fabric_login = qla24xx_login_fabric,
2341 .fabric_logout = qla24xx_fabric_logout,
2342 .calc_req_entries = NULL,
2343 .build_iocbs = NULL,
2344 .prep_ms_iocb = qla24xx_prep_ms_iocb,
2345 .prep_ms_fdmi_iocb = qla24xx_prep_ms_fdmi_iocb,
2347 .write_nvram = NULL,
2348 .fw_dump = qla83xx_fw_dump,
2349 .beacon_on = qla24xx_beacon_on,
2350 .beacon_off = qla24xx_beacon_off,
2351 .beacon_blink = qla83xx_beacon_blink,
2352 .read_optrom = qla25xx_read_optrom_data,
2353 .write_optrom = qla24xx_write_optrom_data,
2354 .get_flash_version = qla24xx_get_flash_version,
2355 .start_scsi = qla24xx_dif_start_scsi,
2356 .start_scsi_mq = qla2xxx_dif_start_scsi_mq,
2357 .abort_isp = qla2x00_abort_isp,
2358 .iospace_config = qla83xx_iospace_config,
2359 .initialize_adapter = qla2x00_initialize_adapter,
2362 static struct isp_operations qlafx00_isp_ops = {
2363 .pci_config = qlafx00_pci_config,
2364 .reset_chip = qlafx00_soft_reset,
2365 .chip_diag = qlafx00_chip_diag,
2366 .config_rings = qlafx00_config_rings,
2367 .reset_adapter = qlafx00_soft_reset,
2368 .nvram_config = NULL,
2369 .update_fw_options = NULL,
2371 .pci_info_str = qlafx00_pci_info_str,
2372 .fw_version_str = qlafx00_fw_version_str,
2373 .intr_handler = qlafx00_intr_handler,
2374 .enable_intrs = qlafx00_enable_intrs,
2375 .disable_intrs = qlafx00_disable_intrs,
2376 .abort_command = qla24xx_async_abort_command,
2377 .target_reset = qlafx00_abort_target,
2378 .lun_reset = qlafx00_lun_reset,
2379 .fabric_login = NULL,
2380 .fabric_logout = NULL,
2381 .calc_req_entries = NULL,
2382 .build_iocbs = NULL,
2383 .prep_ms_iocb = qla24xx_prep_ms_iocb,
2384 .prep_ms_fdmi_iocb = qla24xx_prep_ms_fdmi_iocb,
2385 .read_nvram = qla24xx_read_nvram_data,
2386 .write_nvram = qla24xx_write_nvram_data,
2388 .beacon_on = qla24xx_beacon_on,
2389 .beacon_off = qla24xx_beacon_off,
2390 .beacon_blink = NULL,
2391 .read_optrom = qla24xx_read_optrom_data,
2392 .write_optrom = qla24xx_write_optrom_data,
2393 .get_flash_version = qla24xx_get_flash_version,
2394 .start_scsi = qlafx00_start_scsi,
2395 .start_scsi_mq = NULL,
2396 .abort_isp = qlafx00_abort_isp,
2397 .iospace_config = qlafx00_iospace_config,
2398 .initialize_adapter = qlafx00_initialize_adapter,
2401 static struct isp_operations qla27xx_isp_ops = {
2402 .pci_config = qla25xx_pci_config,
2403 .reset_chip = qla24xx_reset_chip,
2404 .chip_diag = qla24xx_chip_diag,
2405 .config_rings = qla24xx_config_rings,
2406 .reset_adapter = qla24xx_reset_adapter,
2407 .nvram_config = qla81xx_nvram_config,
2408 .update_fw_options = qla81xx_update_fw_options,
2409 .load_risc = qla81xx_load_risc,
2410 .pci_info_str = qla24xx_pci_info_str,
2411 .fw_version_str = qla24xx_fw_version_str,
2412 .intr_handler = qla24xx_intr_handler,
2413 .enable_intrs = qla24xx_enable_intrs,
2414 .disable_intrs = qla24xx_disable_intrs,
2415 .abort_command = qla24xx_abort_command,
2416 .target_reset = qla24xx_abort_target,
2417 .lun_reset = qla24xx_lun_reset,
2418 .fabric_login = qla24xx_login_fabric,
2419 .fabric_logout = qla24xx_fabric_logout,
2420 .calc_req_entries = NULL,
2421 .build_iocbs = NULL,
2422 .prep_ms_iocb = qla24xx_prep_ms_iocb,
2423 .prep_ms_fdmi_iocb = qla24xx_prep_ms_fdmi_iocb,
2425 .write_nvram = NULL,
2426 .fw_dump = qla27xx_fwdump,
2427 .beacon_on = qla24xx_beacon_on,
2428 .beacon_off = qla24xx_beacon_off,
2429 .beacon_blink = qla83xx_beacon_blink,
2430 .read_optrom = qla25xx_read_optrom_data,
2431 .write_optrom = qla24xx_write_optrom_data,
2432 .get_flash_version = qla24xx_get_flash_version,
2433 .start_scsi = qla24xx_dif_start_scsi,
2434 .start_scsi_mq = qla2xxx_dif_start_scsi_mq,
2435 .abort_isp = qla2x00_abort_isp,
2436 .iospace_config = qla83xx_iospace_config,
2437 .initialize_adapter = qla2x00_initialize_adapter,
2441 qla2x00_set_isp_flags(struct qla_hw_data *ha)
2443 ha->device_type = DT_EXTENDED_IDS;
2444 switch (ha->pdev->device) {
2445 case PCI_DEVICE_ID_QLOGIC_ISP2100:
2446 ha->isp_type |= DT_ISP2100;
2447 ha->device_type &= ~DT_EXTENDED_IDS;
2448 ha->fw_srisc_address = RISC_START_ADDRESS_2100;
2450 case PCI_DEVICE_ID_QLOGIC_ISP2200:
2451 ha->isp_type |= DT_ISP2200;
2452 ha->device_type &= ~DT_EXTENDED_IDS;
2453 ha->fw_srisc_address = RISC_START_ADDRESS_2100;
2455 case PCI_DEVICE_ID_QLOGIC_ISP2300:
2456 ha->isp_type |= DT_ISP2300;
2457 ha->device_type |= DT_ZIO_SUPPORTED;
2458 ha->fw_srisc_address = RISC_START_ADDRESS_2300;
2460 case PCI_DEVICE_ID_QLOGIC_ISP2312:
2461 ha->isp_type |= DT_ISP2312;
2462 ha->device_type |= DT_ZIO_SUPPORTED;
2463 ha->fw_srisc_address = RISC_START_ADDRESS_2300;
2465 case PCI_DEVICE_ID_QLOGIC_ISP2322:
2466 ha->isp_type |= DT_ISP2322;
2467 ha->device_type |= DT_ZIO_SUPPORTED;
2468 if (ha->pdev->subsystem_vendor == 0x1028 &&
2469 ha->pdev->subsystem_device == 0x0170)
2470 ha->device_type |= DT_OEM_001;
2471 ha->fw_srisc_address = RISC_START_ADDRESS_2300;
2473 case PCI_DEVICE_ID_QLOGIC_ISP6312:
2474 ha->isp_type |= DT_ISP6312;
2475 ha->fw_srisc_address = RISC_START_ADDRESS_2300;
2477 case PCI_DEVICE_ID_QLOGIC_ISP6322:
2478 ha->isp_type |= DT_ISP6322;
2479 ha->fw_srisc_address = RISC_START_ADDRESS_2300;
2481 case PCI_DEVICE_ID_QLOGIC_ISP2422:
2482 ha->isp_type |= DT_ISP2422;
2483 ha->device_type |= DT_ZIO_SUPPORTED;
2484 ha->device_type |= DT_FWI2;
2485 ha->device_type |= DT_IIDMA;
2486 ha->fw_srisc_address = RISC_START_ADDRESS_2400;
2488 case PCI_DEVICE_ID_QLOGIC_ISP2432:
2489 ha->isp_type |= DT_ISP2432;
2490 ha->device_type |= DT_ZIO_SUPPORTED;
2491 ha->device_type |= DT_FWI2;
2492 ha->device_type |= DT_IIDMA;
2493 ha->fw_srisc_address = RISC_START_ADDRESS_2400;
2495 case PCI_DEVICE_ID_QLOGIC_ISP8432:
2496 ha->isp_type |= DT_ISP8432;
2497 ha->device_type |= DT_ZIO_SUPPORTED;
2498 ha->device_type |= DT_FWI2;
2499 ha->device_type |= DT_IIDMA;
2500 ha->fw_srisc_address = RISC_START_ADDRESS_2400;
2502 case PCI_DEVICE_ID_QLOGIC_ISP5422:
2503 ha->isp_type |= DT_ISP5422;
2504 ha->device_type |= DT_FWI2;
2505 ha->fw_srisc_address = RISC_START_ADDRESS_2400;
2507 case PCI_DEVICE_ID_QLOGIC_ISP5432:
2508 ha->isp_type |= DT_ISP5432;
2509 ha->device_type |= DT_FWI2;
2510 ha->fw_srisc_address = RISC_START_ADDRESS_2400;
2512 case PCI_DEVICE_ID_QLOGIC_ISP2532:
2513 ha->isp_type |= DT_ISP2532;
2514 ha->device_type |= DT_ZIO_SUPPORTED;
2515 ha->device_type |= DT_FWI2;
2516 ha->device_type |= DT_IIDMA;
2517 ha->fw_srisc_address = RISC_START_ADDRESS_2400;
2519 case PCI_DEVICE_ID_QLOGIC_ISP8001:
2520 ha->isp_type |= DT_ISP8001;
2521 ha->device_type |= DT_ZIO_SUPPORTED;
2522 ha->device_type |= DT_FWI2;
2523 ha->device_type |= DT_IIDMA;
2524 ha->fw_srisc_address = RISC_START_ADDRESS_2400;
2526 case PCI_DEVICE_ID_QLOGIC_ISP8021:
2527 ha->isp_type |= DT_ISP8021;
2528 ha->device_type |= DT_ZIO_SUPPORTED;
2529 ha->device_type |= DT_FWI2;
2530 ha->fw_srisc_address = RISC_START_ADDRESS_2400;
2531 /* Initialize 82XX ISP flags */
2532 qla82xx_init_flags(ha);
2534 case PCI_DEVICE_ID_QLOGIC_ISP8044:
2535 ha->isp_type |= DT_ISP8044;
2536 ha->device_type |= DT_ZIO_SUPPORTED;
2537 ha->device_type |= DT_FWI2;
2538 ha->fw_srisc_address = RISC_START_ADDRESS_2400;
2539 /* Initialize 82XX ISP flags */
2540 qla82xx_init_flags(ha);
2542 case PCI_DEVICE_ID_QLOGIC_ISP2031:
2543 ha->isp_type |= DT_ISP2031;
2544 ha->device_type |= DT_ZIO_SUPPORTED;
2545 ha->device_type |= DT_FWI2;
2546 ha->device_type |= DT_IIDMA;
2547 ha->device_type |= DT_T10_PI;
2548 ha->fw_srisc_address = RISC_START_ADDRESS_2400;
2550 case PCI_DEVICE_ID_QLOGIC_ISP8031:
2551 ha->isp_type |= DT_ISP8031;
2552 ha->device_type |= DT_ZIO_SUPPORTED;
2553 ha->device_type |= DT_FWI2;
2554 ha->device_type |= DT_IIDMA;
2555 ha->device_type |= DT_T10_PI;
2556 ha->fw_srisc_address = RISC_START_ADDRESS_2400;
2558 case PCI_DEVICE_ID_QLOGIC_ISPF001:
2559 ha->isp_type |= DT_ISPFX00;
2561 case PCI_DEVICE_ID_QLOGIC_ISP2071:
2562 ha->isp_type |= DT_ISP2071;
2563 ha->device_type |= DT_ZIO_SUPPORTED;
2564 ha->device_type |= DT_FWI2;
2565 ha->device_type |= DT_IIDMA;
2566 ha->device_type |= DT_T10_PI;
2567 ha->fw_srisc_address = RISC_START_ADDRESS_2400;
2569 case PCI_DEVICE_ID_QLOGIC_ISP2271:
2570 ha->isp_type |= DT_ISP2271;
2571 ha->device_type |= DT_ZIO_SUPPORTED;
2572 ha->device_type |= DT_FWI2;
2573 ha->device_type |= DT_IIDMA;
2574 ha->device_type |= DT_T10_PI;
2575 ha->fw_srisc_address = RISC_START_ADDRESS_2400;
2577 case PCI_DEVICE_ID_QLOGIC_ISP2261:
2578 ha->isp_type |= DT_ISP2261;
2579 ha->device_type |= DT_ZIO_SUPPORTED;
2580 ha->device_type |= DT_FWI2;
2581 ha->device_type |= DT_IIDMA;
2582 ha->device_type |= DT_T10_PI;
2583 ha->fw_srisc_address = RISC_START_ADDRESS_2400;
2588 ha->port_no = ha->portnum & 1;
2590 /* Get adapter physical port no from interrupt pin register. */
2591 pci_read_config_byte(ha->pdev, PCI_INTERRUPT_PIN, &ha->port_no);
2595 ha->port_no = !(ha->port_no & 1);
2598 ql_dbg_pci(ql_dbg_init, ha->pdev, 0x000b,
2599 "device_type=0x%x port=%d fw_srisc_address=0x%x.\n",
2600 ha->device_type, ha->port_no, ha->fw_srisc_address);
2604 qla2xxx_scan_start(struct Scsi_Host *shost)
2606 scsi_qla_host_t *vha = shost_priv(shost);
2608 if (vha->hw->flags.running_gold_fw)
2611 set_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags);
2612 set_bit(LOCAL_LOOP_UPDATE, &vha->dpc_flags);
2613 set_bit(RSCN_UPDATE, &vha->dpc_flags);
2614 set_bit(NPIV_CONFIG_NEEDED, &vha->dpc_flags);
2618 qla2xxx_scan_finished(struct Scsi_Host *shost, unsigned long time)
2620 scsi_qla_host_t *vha = shost_priv(shost);
2622 if (test_bit(UNLOADING, &vha->dpc_flags))
2626 if (time > vha->hw->loop_reset_delay * HZ)
2629 return atomic_read(&vha->loop_state) == LOOP_READY;
2632 static void qla2x00_iocb_work_fn(struct work_struct *work)
2634 struct scsi_qla_host *vha = container_of(work,
2635 struct scsi_qla_host, iocb_work);
2638 while (!list_empty(&vha->work_list)) {
2639 qla2x00_do_work(vha);
2647 * PCI driver interface
2650 qla2x00_probe_one(struct pci_dev *pdev, const struct pci_device_id *id)
2653 struct Scsi_Host *host;
2654 scsi_qla_host_t *base_vha = NULL;
2655 struct qla_hw_data *ha;
2657 char fw_str[30], wq_name[30];
2658 struct scsi_host_template *sht;
2659 int bars, mem_only = 0;
2660 uint16_t req_length = 0, rsp_length = 0;
2661 struct req_que *req = NULL;
2662 struct rsp_que *rsp = NULL;
2665 bars = pci_select_bars(pdev, IORESOURCE_MEM | IORESOURCE_IO);
2666 sht = &qla2xxx_driver_template;
2667 if (pdev->device == PCI_DEVICE_ID_QLOGIC_ISP2422 ||
2668 pdev->device == PCI_DEVICE_ID_QLOGIC_ISP2432 ||
2669 pdev->device == PCI_DEVICE_ID_QLOGIC_ISP8432 ||
2670 pdev->device == PCI_DEVICE_ID_QLOGIC_ISP5422 ||
2671 pdev->device == PCI_DEVICE_ID_QLOGIC_ISP5432 ||
2672 pdev->device == PCI_DEVICE_ID_QLOGIC_ISP2532 ||
2673 pdev->device == PCI_DEVICE_ID_QLOGIC_ISP8001 ||
2674 pdev->device == PCI_DEVICE_ID_QLOGIC_ISP8021 ||
2675 pdev->device == PCI_DEVICE_ID_QLOGIC_ISP2031 ||
2676 pdev->device == PCI_DEVICE_ID_QLOGIC_ISP8031 ||
2677 pdev->device == PCI_DEVICE_ID_QLOGIC_ISPF001 ||
2678 pdev->device == PCI_DEVICE_ID_QLOGIC_ISP8044 ||
2679 pdev->device == PCI_DEVICE_ID_QLOGIC_ISP2071 ||
2680 pdev->device == PCI_DEVICE_ID_QLOGIC_ISP2271 ||
2681 pdev->device == PCI_DEVICE_ID_QLOGIC_ISP2261) {
2682 bars = pci_select_bars(pdev, IORESOURCE_MEM);
2684 ql_dbg_pci(ql_dbg_init, pdev, 0x0007,
2685 "Mem only adapter.\n");
2687 ql_dbg_pci(ql_dbg_init, pdev, 0x0008,
2688 "Bars=%d.\n", bars);
2691 if (pci_enable_device_mem(pdev))
2694 if (pci_enable_device(pdev))
2698 /* This may fail but that's ok */
2699 pci_enable_pcie_error_reporting(pdev);
2701 ha = kzalloc(sizeof(struct qla_hw_data), GFP_KERNEL);
2703 ql_log_pci(ql_log_fatal, pdev, 0x0009,
2704 "Unable to allocate memory for ha.\n");
2705 goto disable_device;
2707 ql_dbg_pci(ql_dbg_init, pdev, 0x000a,
2708 "Memory allocated for ha=%p.\n", ha);
2710 ha->tgt.enable_class_2 = ql2xenableclass2;
2711 INIT_LIST_HEAD(&ha->tgt.q_full_list);
2712 spin_lock_init(&ha->tgt.q_full_lock);
2713 spin_lock_init(&ha->tgt.sess_lock);
2714 spin_lock_init(&ha->tgt.atio_lock);
2717 /* Clear our data area */
2719 ha->mem_only = mem_only;
2720 spin_lock_init(&ha->hardware_lock);
2721 spin_lock_init(&ha->vport_slock);
2722 mutex_init(&ha->selflogin_lock);
2723 mutex_init(&ha->optrom_mutex);
2725 /* Set ISP-type information. */
2726 qla2x00_set_isp_flags(ha);
2728 /* Set EEH reset type to fundamental if required by hba */
2729 if (IS_QLA24XX(ha) || IS_QLA25XX(ha) || IS_QLA81XX(ha) ||
2730 IS_QLA83XX(ha) || IS_QLA27XX(ha))
2731 pdev->needs_freset = 1;
2733 ha->prev_topology = 0;
2734 ha->init_cb_size = sizeof(init_cb_t);
2735 ha->link_data_rate = PORT_SPEED_UNKNOWN;
2736 ha->optrom_size = OPTROM_SIZE_2300;
2738 /* Assign ISP specific operations. */
2739 if (IS_QLA2100(ha)) {
2740 ha->max_fibre_devices = MAX_FIBRE_DEVICES_2100;
2741 ha->mbx_count = MAILBOX_REGISTER_COUNT_2100;
2742 req_length = REQUEST_ENTRY_CNT_2100;
2743 rsp_length = RESPONSE_ENTRY_CNT_2100;
2744 ha->max_loop_id = SNS_LAST_LOOP_ID_2100;
2745 ha->gid_list_info_size = 4;
2746 ha->flash_conf_off = ~0;
2747 ha->flash_data_off = ~0;
2748 ha->nvram_conf_off = ~0;
2749 ha->nvram_data_off = ~0;
2750 ha->isp_ops = &qla2100_isp_ops;
2751 } else if (IS_QLA2200(ha)) {
2752 ha->max_fibre_devices = MAX_FIBRE_DEVICES_2100;
2753 ha->mbx_count = MAILBOX_REGISTER_COUNT_2200;
2754 req_length = REQUEST_ENTRY_CNT_2200;
2755 rsp_length = RESPONSE_ENTRY_CNT_2100;
2756 ha->max_loop_id = SNS_LAST_LOOP_ID_2100;
2757 ha->gid_list_info_size = 4;
2758 ha->flash_conf_off = ~0;
2759 ha->flash_data_off = ~0;
2760 ha->nvram_conf_off = ~0;
2761 ha->nvram_data_off = ~0;
2762 ha->isp_ops = &qla2100_isp_ops;
2763 } else if (IS_QLA23XX(ha)) {
2764 ha->max_fibre_devices = MAX_FIBRE_DEVICES_2100;
2765 ha->mbx_count = MAILBOX_REGISTER_COUNT;
2766 req_length = REQUEST_ENTRY_CNT_2200;
2767 rsp_length = RESPONSE_ENTRY_CNT_2300;
2768 ha->max_loop_id = SNS_LAST_LOOP_ID_2300;
2769 ha->gid_list_info_size = 6;
2770 if (IS_QLA2322(ha) || IS_QLA6322(ha))
2771 ha->optrom_size = OPTROM_SIZE_2322;
2772 ha->flash_conf_off = ~0;
2773 ha->flash_data_off = ~0;
2774 ha->nvram_conf_off = ~0;
2775 ha->nvram_data_off = ~0;
2776 ha->isp_ops = &qla2300_isp_ops;
2777 } else if (IS_QLA24XX_TYPE(ha)) {
2778 ha->max_fibre_devices = MAX_FIBRE_DEVICES_2400;
2779 ha->mbx_count = MAILBOX_REGISTER_COUNT;
2780 req_length = REQUEST_ENTRY_CNT_24XX;
2781 rsp_length = RESPONSE_ENTRY_CNT_2300;
2782 ha->tgt.atio_q_length = ATIO_ENTRY_CNT_24XX;
2783 ha->max_loop_id = SNS_LAST_LOOP_ID_2300;
2784 ha->init_cb_size = sizeof(struct mid_init_cb_24xx);
2785 ha->gid_list_info_size = 8;
2786 ha->optrom_size = OPTROM_SIZE_24XX;
2787 ha->nvram_npiv_size = QLA_MAX_VPORTS_QLA24XX;
2788 ha->isp_ops = &qla24xx_isp_ops;
2789 ha->flash_conf_off = FARX_ACCESS_FLASH_CONF;
2790 ha->flash_data_off = FARX_ACCESS_FLASH_DATA;
2791 ha->nvram_conf_off = FARX_ACCESS_NVRAM_CONF;
2792 ha->nvram_data_off = FARX_ACCESS_NVRAM_DATA;
2793 } else if (IS_QLA25XX(ha)) {
2794 ha->max_fibre_devices = MAX_FIBRE_DEVICES_2400;
2795 ha->mbx_count = MAILBOX_REGISTER_COUNT;
2796 req_length = REQUEST_ENTRY_CNT_24XX;
2797 rsp_length = RESPONSE_ENTRY_CNT_2300;
2798 ha->tgt.atio_q_length = ATIO_ENTRY_CNT_24XX;
2799 ha->max_loop_id = SNS_LAST_LOOP_ID_2300;
2800 ha->init_cb_size = sizeof(struct mid_init_cb_24xx);
2801 ha->gid_list_info_size = 8;
2802 ha->optrom_size = OPTROM_SIZE_25XX;
2803 ha->nvram_npiv_size = QLA_MAX_VPORTS_QLA25XX;
2804 ha->isp_ops = &qla25xx_isp_ops;
2805 ha->flash_conf_off = FARX_ACCESS_FLASH_CONF;
2806 ha->flash_data_off = FARX_ACCESS_FLASH_DATA;
2807 ha->nvram_conf_off = FARX_ACCESS_NVRAM_CONF;
2808 ha->nvram_data_off = FARX_ACCESS_NVRAM_DATA;
2809 } else if (IS_QLA81XX(ha)) {
2810 ha->max_fibre_devices = MAX_FIBRE_DEVICES_2400;
2811 ha->mbx_count = MAILBOX_REGISTER_COUNT;
2812 req_length = REQUEST_ENTRY_CNT_24XX;
2813 rsp_length = RESPONSE_ENTRY_CNT_2300;
2814 ha->tgt.atio_q_length = ATIO_ENTRY_CNT_24XX;
2815 ha->max_loop_id = SNS_LAST_LOOP_ID_2300;
2816 ha->init_cb_size = sizeof(struct mid_init_cb_81xx);
2817 ha->gid_list_info_size = 8;
2818 ha->optrom_size = OPTROM_SIZE_81XX;
2819 ha->nvram_npiv_size = QLA_MAX_VPORTS_QLA25XX;
2820 ha->isp_ops = &qla81xx_isp_ops;
2821 ha->flash_conf_off = FARX_ACCESS_FLASH_CONF_81XX;
2822 ha->flash_data_off = FARX_ACCESS_FLASH_DATA_81XX;
2823 ha->nvram_conf_off = ~0;
2824 ha->nvram_data_off = ~0;
2825 } else if (IS_QLA82XX(ha)) {
2826 ha->max_fibre_devices = MAX_FIBRE_DEVICES_2400;
2827 ha->mbx_count = MAILBOX_REGISTER_COUNT;
2828 req_length = REQUEST_ENTRY_CNT_82XX;
2829 rsp_length = RESPONSE_ENTRY_CNT_82XX;
2830 ha->max_loop_id = SNS_LAST_LOOP_ID_2300;
2831 ha->init_cb_size = sizeof(struct mid_init_cb_81xx);
2832 ha->gid_list_info_size = 8;
2833 ha->optrom_size = OPTROM_SIZE_82XX;
2834 ha->nvram_npiv_size = QLA_MAX_VPORTS_QLA25XX;
2835 ha->isp_ops = &qla82xx_isp_ops;
2836 ha->flash_conf_off = FARX_ACCESS_FLASH_CONF;
2837 ha->flash_data_off = FARX_ACCESS_FLASH_DATA;
2838 ha->nvram_conf_off = FARX_ACCESS_NVRAM_CONF;
2839 ha->nvram_data_off = FARX_ACCESS_NVRAM_DATA;
2840 } else if (IS_QLA8044(ha)) {
2841 ha->max_fibre_devices = MAX_FIBRE_DEVICES_2400;
2842 ha->mbx_count = MAILBOX_REGISTER_COUNT;
2843 req_length = REQUEST_ENTRY_CNT_82XX;
2844 rsp_length = RESPONSE_ENTRY_CNT_82XX;
2845 ha->max_loop_id = SNS_LAST_LOOP_ID_2300;
2846 ha->init_cb_size = sizeof(struct mid_init_cb_81xx);
2847 ha->gid_list_info_size = 8;
2848 ha->optrom_size = OPTROM_SIZE_83XX;
2849 ha->nvram_npiv_size = QLA_MAX_VPORTS_QLA25XX;
2850 ha->isp_ops = &qla8044_isp_ops;
2851 ha->flash_conf_off = FARX_ACCESS_FLASH_CONF;
2852 ha->flash_data_off = FARX_ACCESS_FLASH_DATA;
2853 ha->nvram_conf_off = FARX_ACCESS_NVRAM_CONF;
2854 ha->nvram_data_off = FARX_ACCESS_NVRAM_DATA;
2855 } else if (IS_QLA83XX(ha)) {
2856 ha->portnum = PCI_FUNC(ha->pdev->devfn);
2857 ha->max_fibre_devices = MAX_FIBRE_DEVICES_2400;
2858 ha->mbx_count = MAILBOX_REGISTER_COUNT;
2859 req_length = REQUEST_ENTRY_CNT_83XX;
2860 rsp_length = RESPONSE_ENTRY_CNT_83XX;
2861 ha->tgt.atio_q_length = ATIO_ENTRY_CNT_24XX;
2862 ha->max_loop_id = SNS_LAST_LOOP_ID_2300;
2863 ha->init_cb_size = sizeof(struct mid_init_cb_81xx);
2864 ha->gid_list_info_size = 8;
2865 ha->optrom_size = OPTROM_SIZE_83XX;
2866 ha->nvram_npiv_size = QLA_MAX_VPORTS_QLA25XX;
2867 ha->isp_ops = &qla83xx_isp_ops;
2868 ha->flash_conf_off = FARX_ACCESS_FLASH_CONF_81XX;
2869 ha->flash_data_off = FARX_ACCESS_FLASH_DATA_81XX;
2870 ha->nvram_conf_off = ~0;
2871 ha->nvram_data_off = ~0;
2872 } else if (IS_QLAFX00(ha)) {
2873 ha->max_fibre_devices = MAX_FIBRE_DEVICES_FX00;
2874 ha->mbx_count = MAILBOX_REGISTER_COUNT_FX00;
2875 ha->aen_mbx_count = AEN_MAILBOX_REGISTER_COUNT_FX00;
2876 req_length = REQUEST_ENTRY_CNT_FX00;
2877 rsp_length = RESPONSE_ENTRY_CNT_FX00;
2878 ha->isp_ops = &qlafx00_isp_ops;
2879 ha->port_down_retry_count = 30; /* default value */
2880 ha->mr.fw_hbt_cnt = QLAFX00_HEARTBEAT_INTERVAL;
2881 ha->mr.fw_reset_timer_tick = QLAFX00_RESET_INTERVAL;
2882 ha->mr.fw_critemp_timer_tick = QLAFX00_CRITEMP_INTERVAL;
2883 ha->mr.fw_hbt_en = 1;
2884 ha->mr.host_info_resend = false;
2885 ha->mr.hinfo_resend_timer_tick = QLAFX00_HINFO_RESEND_INTERVAL;
2886 } else if (IS_QLA27XX(ha)) {
2887 ha->portnum = PCI_FUNC(ha->pdev->devfn);
2888 ha->max_fibre_devices = MAX_FIBRE_DEVICES_2400;
2889 ha->mbx_count = MAILBOX_REGISTER_COUNT;
2890 req_length = REQUEST_ENTRY_CNT_83XX;
2891 rsp_length = RESPONSE_ENTRY_CNT_83XX;
2892 ha->tgt.atio_q_length = ATIO_ENTRY_CNT_24XX;
2893 ha->max_loop_id = SNS_LAST_LOOP_ID_2300;
2894 ha->init_cb_size = sizeof(struct mid_init_cb_81xx);
2895 ha->gid_list_info_size = 8;
2896 ha->optrom_size = OPTROM_SIZE_83XX;
2897 ha->nvram_npiv_size = QLA_MAX_VPORTS_QLA25XX;
2898 ha->isp_ops = &qla27xx_isp_ops;
2899 ha->flash_conf_off = FARX_ACCESS_FLASH_CONF_81XX;
2900 ha->flash_data_off = FARX_ACCESS_FLASH_DATA_81XX;
2901 ha->nvram_conf_off = ~0;
2902 ha->nvram_data_off = ~0;
2905 ql_dbg_pci(ql_dbg_init, pdev, 0x001e,
2906 "mbx_count=%d, req_length=%d, "
2907 "rsp_length=%d, max_loop_id=%d, init_cb_size=%d, "
2908 "gid_list_info_size=%d, optrom_size=%d, nvram_npiv_size=%d, "
2909 "max_fibre_devices=%d.\n",
2910 ha->mbx_count, req_length, rsp_length, ha->max_loop_id,
2911 ha->init_cb_size, ha->gid_list_info_size, ha->optrom_size,
2912 ha->nvram_npiv_size, ha->max_fibre_devices);
2913 ql_dbg_pci(ql_dbg_init, pdev, 0x001f,
2914 "isp_ops=%p, flash_conf_off=%d, "
2915 "flash_data_off=%d, nvram_conf_off=%d, nvram_data_off=%d.\n",
2916 ha->isp_ops, ha->flash_conf_off, ha->flash_data_off,
2917 ha->nvram_conf_off, ha->nvram_data_off);
2919 /* Configure PCI I/O space */
2920 ret = ha->isp_ops->iospace_config(ha);
2922 goto iospace_config_failed;
2924 ql_log_pci(ql_log_info, pdev, 0x001d,
2925 "Found an ISP%04X irq %d iobase 0x%p.\n",
2926 pdev->device, pdev->irq, ha->iobase);
2927 mutex_init(&ha->vport_lock);
2928 mutex_init(&ha->mq_lock);
2929 init_completion(&ha->mbx_cmd_comp);
2930 complete(&ha->mbx_cmd_comp);
2931 init_completion(&ha->mbx_intr_comp);
2932 init_completion(&ha->dcbx_comp);
2933 init_completion(&ha->lb_portup_comp);
2935 set_bit(0, (unsigned long *) ha->vp_idx_map);
2937 qla2x00_config_dma_addressing(ha);
2938 ql_dbg_pci(ql_dbg_init, pdev, 0x0020,
2939 "64 Bit addressing is %s.\n",
2940 ha->flags.enable_64bit_addressing ? "enable" :
2942 ret = qla2x00_mem_alloc(ha, req_length, rsp_length, &req, &rsp);
2944 ql_log_pci(ql_log_fatal, pdev, 0x0031,
2945 "Failed to allocate memory for adapter, aborting.\n");
2947 goto probe_hw_failed;
2950 req->max_q_depth = MAX_Q_DEPTH;
2951 if (ql2xmaxqdepth != 0 && ql2xmaxqdepth <= 0xffffU)
2952 req->max_q_depth = ql2xmaxqdepth;
2955 base_vha = qla2x00_create_host(sht, ha);
2958 qla2x00_mem_free(ha);
2959 qla2x00_free_req_que(ha, req);
2960 qla2x00_free_rsp_que(ha, rsp);
2961 goto probe_hw_failed;
2964 pci_set_drvdata(pdev, base_vha);
2965 set_bit(PFLG_DRIVER_PROBING, &base_vha->pci_flags);
2967 host = base_vha->host;
2968 base_vha->req = req;
2969 if (IS_QLA2XXX_MIDTYPE(ha))
2970 base_vha->mgmt_svr_loop_id = 10 + base_vha->vp_idx;
2972 base_vha->mgmt_svr_loop_id = MANAGEMENT_SERVER +
2975 /* Setup fcport template structure. */
2976 ha->mr.fcport.vha = base_vha;
2977 ha->mr.fcport.port_type = FCT_UNKNOWN;
2978 ha->mr.fcport.loop_id = FC_NO_LOOP_ID;
2979 qla2x00_set_fcport_state(&ha->mr.fcport, FCS_UNCONFIGURED);
2980 ha->mr.fcport.supported_classes = FC_COS_UNSPECIFIED;
2981 ha->mr.fcport.scan_state = 1;
2983 /* Set the SG table size based on ISP type */
2984 if (!IS_FWI2_CAPABLE(ha)) {
2986 host->sg_tablesize = 32;
2988 if (!IS_QLA82XX(ha))
2989 host->sg_tablesize = QLA_SG_ALL;
2991 host->max_id = ha->max_fibre_devices;
2992 host->cmd_per_lun = 3;
2993 host->unique_id = host->host_no;
2994 if (IS_T10_PI_CAPABLE(ha) && ql2xenabledif)
2995 host->max_cmd_len = 32;
2997 host->max_cmd_len = MAX_CMDSZ;
2998 host->max_channel = MAX_BUSES - 1;
2999 /* Older HBAs support only 16-bit LUNs */
3000 if (!IS_QLAFX00(ha) && !IS_FWI2_CAPABLE(ha) &&
3001 ql2xmaxlun > 0xffff)
3002 host->max_lun = 0xffff;
3004 host->max_lun = ql2xmaxlun;
3005 host->transportt = qla2xxx_transport_template;
3006 sht->vendor_id = (SCSI_NL_VID_TYPE_PCI | PCI_VENDOR_ID_QLOGIC);
3008 ql_dbg(ql_dbg_init, base_vha, 0x0033,
3009 "max_id=%d this_id=%d "
3010 "cmd_per_len=%d unique_id=%d max_cmd_len=%d max_channel=%d "
3011 "max_lun=%llu transportt=%p, vendor_id=%llu.\n", host->max_id,
3012 host->this_id, host->cmd_per_lun, host->unique_id,
3013 host->max_cmd_len, host->max_channel, host->max_lun,
3014 host->transportt, sht->vendor_id);
3016 /* Set up the irqs */
3017 ret = qla2x00_request_irqs(ha, rsp);
3019 goto probe_init_failed;
3021 /* Alloc arrays of request and response ring ptrs */
3022 if (!qla2x00_alloc_queues(ha, req, rsp)) {
3023 ql_log(ql_log_fatal, base_vha, 0x003d,
3024 "Failed to allocate memory for queue pointers..."
3026 goto probe_init_failed;
3029 if (ha->mqenable && shost_use_blk_mq(host)) {
3030 /* number of hardware queues supported by blk/scsi-mq*/
3031 host->nr_hw_queues = ha->max_qpairs;
3033 ql_dbg(ql_dbg_init, base_vha, 0x0192,
3034 "blk/scsi-mq enabled, HW queues = %d.\n", host->nr_hw_queues);
3036 ql_dbg(ql_dbg_init, base_vha, 0x0193,
3037 "blk/scsi-mq disabled.\n");
3039 qlt_probe_one_stage1(base_vha, ha);
3041 pci_save_state(pdev);
3043 /* Assign back pointers */
3047 if (IS_QLAFX00(ha)) {
3048 ha->rsp_q_map[0] = rsp;
3049 ha->req_q_map[0] = req;
3050 set_bit(0, ha->req_qid_map);
3051 set_bit(0, ha->rsp_qid_map);
3054 /* FWI2-capable only. */
3055 req->req_q_in = &ha->iobase->isp24.req_q_in;
3056 req->req_q_out = &ha->iobase->isp24.req_q_out;
3057 rsp->rsp_q_in = &ha->iobase->isp24.rsp_q_in;
3058 rsp->rsp_q_out = &ha->iobase->isp24.rsp_q_out;
3059 if (ha->mqenable || IS_QLA83XX(ha) || IS_QLA27XX(ha)) {
3060 req->req_q_in = &ha->mqiobase->isp25mq.req_q_in;
3061 req->req_q_out = &ha->mqiobase->isp25mq.req_q_out;
3062 rsp->rsp_q_in = &ha->mqiobase->isp25mq.rsp_q_in;
3063 rsp->rsp_q_out = &ha->mqiobase->isp25mq.rsp_q_out;
3066 if (IS_QLAFX00(ha)) {
3067 req->req_q_in = &ha->iobase->ispfx00.req_q_in;
3068 req->req_q_out = &ha->iobase->ispfx00.req_q_out;
3069 rsp->rsp_q_in = &ha->iobase->ispfx00.rsp_q_in;
3070 rsp->rsp_q_out = &ha->iobase->ispfx00.rsp_q_out;
3073 if (IS_P3P_TYPE(ha)) {
3074 req->req_q_out = &ha->iobase->isp82.req_q_out[0];
3075 rsp->rsp_q_in = &ha->iobase->isp82.rsp_q_in[0];
3076 rsp->rsp_q_out = &ha->iobase->isp82.rsp_q_out[0];
3079 ql_dbg(ql_dbg_multiq, base_vha, 0xc009,
3080 "rsp_q_map=%p req_q_map=%p rsp->req=%p req->rsp=%p.\n",
3081 ha->rsp_q_map, ha->req_q_map, rsp->req, req->rsp);
3082 ql_dbg(ql_dbg_multiq, base_vha, 0xc00a,
3083 "req->req_q_in=%p req->req_q_out=%p "
3084 "rsp->rsp_q_in=%p rsp->rsp_q_out=%p.\n",
3085 req->req_q_in, req->req_q_out,
3086 rsp->rsp_q_in, rsp->rsp_q_out);
3087 ql_dbg(ql_dbg_init, base_vha, 0x003e,
3088 "rsp_q_map=%p req_q_map=%p rsp->req=%p req->rsp=%p.\n",
3089 ha->rsp_q_map, ha->req_q_map, rsp->req, req->rsp);
3090 ql_dbg(ql_dbg_init, base_vha, 0x003f,
3091 "req->req_q_in=%p req->req_q_out=%p rsp->rsp_q_in=%p rsp->rsp_q_out=%p.\n",
3092 req->req_q_in, req->req_q_out, rsp->rsp_q_in, rsp->rsp_q_out);
3094 if (ha->isp_ops->initialize_adapter(base_vha)) {
3095 ql_log(ql_log_fatal, base_vha, 0x00d6,
3096 "Failed to initialize adapter - Adapter flags %x.\n",
3097 base_vha->device_flags);
3099 if (IS_QLA82XX(ha)) {
3100 qla82xx_idc_lock(ha);
3101 qla82xx_wr_32(ha, QLA82XX_CRB_DEV_STATE,
3102 QLA8XXX_DEV_FAILED);
3103 qla82xx_idc_unlock(ha);
3104 ql_log(ql_log_fatal, base_vha, 0x00d7,
3105 "HW State: FAILED.\n");
3106 } else if (IS_QLA8044(ha)) {
3107 qla8044_idc_lock(ha);
3108 qla8044_wr_direct(base_vha,
3109 QLA8044_CRB_DEV_STATE_INDEX,
3110 QLA8XXX_DEV_FAILED);
3111 qla8044_idc_unlock(ha);
3112 ql_log(ql_log_fatal, base_vha, 0x0150,
3113 "HW State: FAILED.\n");
3121 host->can_queue = QLAFX00_MAX_CANQUEUE;
3123 host->can_queue = req->num_outstanding_cmds - 10;
3125 ql_dbg(ql_dbg_init, base_vha, 0x0032,
3126 "can_queue=%d, req=%p, mgmt_svr_loop_id=%d, sg_tablesize=%d.\n",
3127 host->can_queue, base_vha->req,
3128 base_vha->mgmt_svr_loop_id, host->sg_tablesize);
3132 bool startit = false;
3133 ha->wq = alloc_workqueue("qla2xxx_wq", WQ_MEM_RECLAIM, 1);
3135 if (QLA_TGT_MODE_ENABLED()) {
3140 if ((ql2x_ini_mode == QLA2XXX_INI_MODE_ENABLED) &&
3141 shost_use_blk_mq(host)) {
3147 /* Create start of day qpairs for Block MQ */
3148 for (i = 0; i < ha->max_qpairs; i++)
3149 qla2xxx_create_qpair(base_vha, 5, 0, startit);
3153 if (ha->flags.running_gold_fw)
3157 * Startup the kernel thread for this host adapter
3159 ha->dpc_thread = kthread_create(qla2x00_do_dpc, ha,
3160 "%s_dpc", base_vha->host_str);
3161 if (IS_ERR(ha->dpc_thread)) {
3162 ql_log(ql_log_fatal, base_vha, 0x00ed,
3163 "Failed to start DPC thread.\n");
3164 ret = PTR_ERR(ha->dpc_thread);
3167 ql_dbg(ql_dbg_init, base_vha, 0x00ee,
3168 "DPC thread started successfully.\n");
3171 * If we're not coming up in initiator mode, we might sit for
3172 * a while without waking up the dpc thread, which leads to a
3173 * stuck process warning. So just kick the dpc once here and
3174 * let the kthread start (and go back to sleep in qla2x00_do_dpc).
3176 qla2xxx_wake_dpc(base_vha);
3178 INIT_WORK(&base_vha->iocb_work, qla2x00_iocb_work_fn);
3179 INIT_WORK(&ha->board_disable, qla2x00_disable_board_on_pci_error);
3181 if (IS_QLA8031(ha) || IS_MCTP_CAPABLE(ha)) {
3182 sprintf(wq_name, "qla2xxx_%lu_dpc_lp_wq", base_vha->host_no);
3183 ha->dpc_lp_wq = create_singlethread_workqueue(wq_name);
3184 INIT_WORK(&ha->idc_aen, qla83xx_service_idc_aen);
3186 sprintf(wq_name, "qla2xxx_%lu_dpc_hp_wq", base_vha->host_no);
3187 ha->dpc_hp_wq = create_singlethread_workqueue(wq_name);
3188 INIT_WORK(&ha->nic_core_reset, qla83xx_nic_core_reset_work);
3189 INIT_WORK(&ha->idc_state_handler,
3190 qla83xx_idc_state_handler_work);
3191 INIT_WORK(&ha->nic_core_unrecoverable,
3192 qla83xx_nic_core_unrecoverable_work);
3196 list_add_tail(&base_vha->list, &ha->vp_list);
3197 base_vha->host->irq = ha->pdev->irq;
3199 /* Initialized the timer */
3200 qla2x00_start_timer(base_vha, qla2x00_timer, WATCH_INTERVAL);
3201 ql_dbg(ql_dbg_init, base_vha, 0x00ef,
3202 "Started qla2x00_timer with "
3203 "interval=%d.\n", WATCH_INTERVAL);
3204 ql_dbg(ql_dbg_init, base_vha, 0x00f0,
3205 "Detected hba at address=%p.\n",
3208 if (IS_T10_PI_CAPABLE(ha) && ql2xenabledif) {
3209 if (ha->fw_attributes & BIT_4) {
3210 int prot = 0, guard;
3211 base_vha->flags.difdix_supported = 1;
3212 ql_dbg(ql_dbg_init, base_vha, 0x00f1,
3213 "Registering for DIF/DIX type 1 and 3 protection.\n");
3214 if (ql2xenabledif == 1)
3215 prot = SHOST_DIX_TYPE0_PROTECTION;
3216 scsi_host_set_prot(host,
3217 prot | SHOST_DIF_TYPE1_PROTECTION
3218 | SHOST_DIF_TYPE2_PROTECTION
3219 | SHOST_DIF_TYPE3_PROTECTION
3220 | SHOST_DIX_TYPE1_PROTECTION
3221 | SHOST_DIX_TYPE2_PROTECTION
3222 | SHOST_DIX_TYPE3_PROTECTION);
3224 guard = SHOST_DIX_GUARD_CRC;
3226 if (IS_PI_IPGUARD_CAPABLE(ha) &&
3227 (ql2xenabledif > 1 || IS_PI_DIFB_DIX0_CAPABLE(ha)))
3228 guard |= SHOST_DIX_GUARD_IP;
3230 scsi_host_set_guard(host, guard);
3232 base_vha->flags.difdix_supported = 0;
3235 ha->isp_ops->enable_intrs(ha);
3237 if (IS_QLAFX00(ha)) {
3238 ret = qlafx00_fx_disc(base_vha,
3239 &base_vha->hw->mr.fcport, FXDISC_GET_CONFIG_INFO);
3240 host->sg_tablesize = (ha->mr.extended_io_enabled) ?
3244 ret = scsi_add_host(host, &pdev->dev);
3248 base_vha->flags.init_done = 1;
3249 base_vha->flags.online = 1;
3250 ha->prev_minidump_failed = 0;
3252 ql_dbg(ql_dbg_init, base_vha, 0x00f2,
3253 "Init done and hba is online.\n");
3255 if (qla_ini_mode_enabled(base_vha) ||
3256 qla_dual_mode_enabled(base_vha))
3257 scsi_scan_host(host);
3259 ql_dbg(ql_dbg_init, base_vha, 0x0122,
3260 "skipping scsi_scan_host() for non-initiator port\n");
3262 qla2x00_alloc_sysfs_attr(base_vha);
3264 if (IS_QLAFX00(ha)) {
3265 ret = qlafx00_fx_disc(base_vha,
3266 &base_vha->hw->mr.fcport, FXDISC_GET_PORT_INFO);
3268 /* Register system information */
3269 ret = qlafx00_fx_disc(base_vha,
3270 &base_vha->hw->mr.fcport, FXDISC_REG_HOST_INFO);
3273 qla2x00_init_host_attr(base_vha);
3275 qla2x00_dfs_setup(base_vha);
3277 ql_log(ql_log_info, base_vha, 0x00fb,
3278 "QLogic %s - %s.\n", ha->model_number, ha->model_desc);
3279 ql_log(ql_log_info, base_vha, 0x00fc,
3280 "ISP%04X: %s @ %s hdma%c host#=%ld fw=%s.\n",
3281 pdev->device, ha->isp_ops->pci_info_str(base_vha, pci_info),
3282 pci_name(pdev), ha->flags.enable_64bit_addressing ? '+' : '-',
3284 ha->isp_ops->fw_version_str(base_vha, fw_str, sizeof(fw_str)));
3286 qlt_add_target(ha, base_vha);
3288 clear_bit(PFLG_DRIVER_PROBING, &base_vha->pci_flags);
3290 if (test_bit(UNLOADING, &base_vha->dpc_flags))
3296 qla2x00_free_req_que(ha, req);
3297 ha->req_q_map[0] = NULL;
3298 clear_bit(0, ha->req_qid_map);
3299 qla2x00_free_rsp_que(ha, rsp);
3300 ha->rsp_q_map[0] = NULL;
3301 clear_bit(0, ha->rsp_qid_map);
3302 ha->max_req_queues = ha->max_rsp_queues = 0;
3305 if (base_vha->timer_active)
3306 qla2x00_stop_timer(base_vha);
3307 base_vha->flags.online = 0;
3308 if (ha->dpc_thread) {
3309 struct task_struct *t = ha->dpc_thread;
3311 ha->dpc_thread = NULL;
3315 qla2x00_free_device(base_vha);
3317 scsi_host_put(base_vha->host);
3320 qla2x00_clear_drv_active(ha);
3322 iospace_config_failed:
3323 if (IS_P3P_TYPE(ha)) {
3324 if (!ha->nx_pcibase)
3325 iounmap((device_reg_t *)ha->nx_pcibase);
3327 iounmap((device_reg_t *)ha->nxdb_wr_ptr);
3330 iounmap(ha->iobase);
3332 iounmap(ha->cregbase);
3334 pci_release_selected_regions(ha->pdev, ha->bars);
3338 pci_disable_device(pdev);
3343 qla2x00_shutdown(struct pci_dev *pdev)
3345 scsi_qla_host_t *vha;
3346 struct qla_hw_data *ha;
3348 if (!atomic_read(&pdev->enable_cnt))
3351 vha = pci_get_drvdata(pdev);
3354 /* Notify ISPFX00 firmware */
3356 qlafx00_driver_shutdown(vha, 20);
3358 /* Turn-off FCE trace */
3359 if (ha->flags.fce_enabled) {
3360 qla2x00_disable_fce_trace(vha, NULL, NULL);
3361 ha->flags.fce_enabled = 0;
3364 /* Turn-off EFT trace */
3366 qla2x00_disable_eft_trace(vha);
3368 /* Stop currently executing firmware. */
3369 qla2x00_try_to_stop_firmware(vha);
3371 /* Turn adapter off line */
3372 vha->flags.online = 0;
3374 /* turn-off interrupts on the card */
3375 if (ha->interrupts_on) {
3376 vha->flags.init_done = 0;
3377 ha->isp_ops->disable_intrs(ha);
3380 qla2x00_free_irqs(vha);
3382 qla2x00_free_fw_dump(ha);
3384 pci_disable_pcie_error_reporting(pdev);
3385 pci_disable_device(pdev);
3388 /* Deletes all the virtual ports for a given ha */
3390 qla2x00_delete_all_vps(struct qla_hw_data *ha, scsi_qla_host_t *base_vha)
3392 scsi_qla_host_t *vha;
3393 unsigned long flags;
3395 mutex_lock(&ha->vport_lock);
3396 while (ha->cur_vport_count) {
3397 spin_lock_irqsave(&ha->vport_slock, flags);
3399 BUG_ON(base_vha->list.next == &ha->vp_list);
3400 /* This assumes first entry in ha->vp_list is always base vha */
3401 vha = list_first_entry(&base_vha->list, scsi_qla_host_t, list);
3402 scsi_host_get(vha->host);
3404 spin_unlock_irqrestore(&ha->vport_slock, flags);
3405 mutex_unlock(&ha->vport_lock);
3407 fc_vport_terminate(vha->fc_vport);
3408 scsi_host_put(vha->host);
3410 mutex_lock(&ha->vport_lock);
3412 mutex_unlock(&ha->vport_lock);
3415 /* Stops all deferred work threads */
3417 qla2x00_destroy_deferred_work(struct qla_hw_data *ha)
3419 /* Cancel all work and destroy DPC workqueues */
3420 if (ha->dpc_lp_wq) {
3421 cancel_work_sync(&ha->idc_aen);
3422 destroy_workqueue(ha->dpc_lp_wq);
3423 ha->dpc_lp_wq = NULL;
3426 if (ha->dpc_hp_wq) {
3427 cancel_work_sync(&ha->nic_core_reset);
3428 cancel_work_sync(&ha->idc_state_handler);
3429 cancel_work_sync(&ha->nic_core_unrecoverable);
3430 destroy_workqueue(ha->dpc_hp_wq);
3431 ha->dpc_hp_wq = NULL;
3434 /* Kill the kernel thread for this host */
3435 if (ha->dpc_thread) {
3436 struct task_struct *t = ha->dpc_thread;
3439 * qla2xxx_wake_dpc checks for ->dpc_thread
3440 * so we need to zero it out.
3442 ha->dpc_thread = NULL;
3448 qla2x00_unmap_iobases(struct qla_hw_data *ha)
3450 if (IS_QLA82XX(ha)) {
3452 iounmap((device_reg_t *)ha->nx_pcibase);
3454 iounmap((device_reg_t *)ha->nxdb_wr_ptr);
3457 iounmap(ha->iobase);
3460 iounmap(ha->cregbase);
3463 iounmap(ha->mqiobase);
3465 if ((IS_QLA83XX(ha) || IS_QLA27XX(ha)) && ha->msixbase)
3466 iounmap(ha->msixbase);
3471 qla2x00_clear_drv_active(struct qla_hw_data *ha)
3473 if (IS_QLA8044(ha)) {
3474 qla8044_idc_lock(ha);
3475 qla8044_clear_drv_active(ha);
3476 qla8044_idc_unlock(ha);
3477 } else if (IS_QLA82XX(ha)) {
3478 qla82xx_idc_lock(ha);
3479 qla82xx_clear_drv_active(ha);
3480 qla82xx_idc_unlock(ha);
3485 qla2x00_remove_one(struct pci_dev *pdev)
3487 scsi_qla_host_t *base_vha;
3488 struct qla_hw_data *ha;
3490 base_vha = pci_get_drvdata(pdev);
3493 /* Indicate device removal to prevent future board_disable and wait
3494 * until any pending board_disable has completed. */
3495 set_bit(PFLG_DRIVER_REMOVING, &base_vha->pci_flags);
3496 cancel_work_sync(&ha->board_disable);
3499 * If the PCI device is disabled then there was a PCI-disconnect and
3500 * qla2x00_disable_board_on_pci_error has taken care of most of the
3503 if (!atomic_read(&pdev->enable_cnt)) {
3504 dma_free_coherent(&ha->pdev->dev, base_vha->gnl.size,
3505 base_vha->gnl.l, base_vha->gnl.ldma);
3507 scsi_host_put(base_vha->host);
3509 pci_set_drvdata(pdev, NULL);
3512 qla2x00_wait_for_hba_ready(base_vha);
3515 * if UNLOAD flag is already set, then continue unload,
3516 * where it was set first.
3518 if (test_bit(UNLOADING, &base_vha->dpc_flags))
3521 set_bit(UNLOADING, &base_vha->dpc_flags);
3522 dma_free_coherent(&ha->pdev->dev,
3523 base_vha->gnl.size, base_vha->gnl.l, base_vha->gnl.ldma);
3526 qlafx00_driver_shutdown(base_vha, 20);
3528 qla2x00_delete_all_vps(ha, base_vha);
3530 if (IS_QLA8031(ha)) {
3531 ql_dbg(ql_dbg_p3p, base_vha, 0xb07e,
3532 "Clearing fcoe driver presence.\n");
3533 if (qla83xx_clear_drv_presence(base_vha) != QLA_SUCCESS)
3534 ql_dbg(ql_dbg_p3p, base_vha, 0xb079,
3535 "Error while clearing DRV-Presence.\n");
3538 qla2x00_abort_all_cmds(base_vha, DID_NO_CONNECT << 16);
3540 qla2x00_dfs_remove(base_vha);
3542 qla84xx_put_chip(base_vha);
3544 /* Laser should be disabled only for ISP2031 */
3546 qla83xx_disable_laser(base_vha);
3549 if (base_vha->timer_active)
3550 qla2x00_stop_timer(base_vha);
3552 base_vha->flags.online = 0;
3554 /* free DMA memory */
3555 if (ha->exlogin_buf)
3556 qla2x00_free_exlogin_buffer(ha);
3558 /* free DMA memory */
3559 if (ha->exchoffld_buf)
3560 qla2x00_free_exchoffld_buffer(ha);
3562 qla2x00_destroy_deferred_work(ha);
3564 qlt_remove_target(ha, base_vha);
3566 qla2x00_free_sysfs_attr(base_vha, true);
3568 fc_remove_host(base_vha->host);
3569 qlt_remove_target_resources(ha);
3571 scsi_remove_host(base_vha->host);
3573 qla2x00_free_device(base_vha);
3575 qla2x00_clear_drv_active(ha);
3577 scsi_host_put(base_vha->host);
3579 qla2x00_unmap_iobases(ha);
3581 pci_release_selected_regions(ha->pdev, ha->bars);
3584 pci_disable_pcie_error_reporting(pdev);
3586 pci_disable_device(pdev);
3590 qla2x00_free_device(scsi_qla_host_t *vha)
3592 struct qla_hw_data *ha = vha->hw;
3594 qla2x00_abort_all_cmds(vha, DID_NO_CONNECT << 16);
3597 if (vha->timer_active)
3598 qla2x00_stop_timer(vha);
3600 qla25xx_delete_queues(vha);
3602 if (ha->flags.fce_enabled)
3603 qla2x00_disable_fce_trace(vha, NULL, NULL);
3606 qla2x00_disable_eft_trace(vha);
3608 /* Stop currently executing firmware. */
3609 qla2x00_try_to_stop_firmware(vha);
3611 vha->flags.online = 0;
3613 /* turn-off interrupts on the card */
3614 if (ha->interrupts_on) {
3615 vha->flags.init_done = 0;
3616 ha->isp_ops->disable_intrs(ha);
3619 qla2x00_free_fcports(vha);
3621 qla2x00_free_irqs(vha);
3623 /* Flush the work queue and remove it */
3625 flush_workqueue(ha->wq);
3626 destroy_workqueue(ha->wq);
3631 qla2x00_mem_free(ha);
3633 qla82xx_md_free(vha);
3635 qla2x00_free_queues(ha);
3638 void qla2x00_free_fcports(struct scsi_qla_host *vha)
3640 fc_port_t *fcport, *tfcport;
3642 list_for_each_entry_safe(fcport, tfcport, &vha->vp_fcports, list) {
3643 list_del(&fcport->list);
3644 qla2x00_clear_loop_id(fcport);
3650 qla2x00_schedule_rport_del(struct scsi_qla_host *vha, fc_port_t *fcport,
3653 struct fc_rport *rport;
3654 scsi_qla_host_t *base_vha;
3655 unsigned long flags;
3660 rport = fcport->rport;
3662 base_vha = pci_get_drvdata(vha->hw->pdev);
3663 spin_lock_irqsave(vha->host->host_lock, flags);
3664 fcport->drport = rport;
3665 spin_unlock_irqrestore(vha->host->host_lock, flags);
3666 qlt_do_generation_tick(vha, &base_vha->total_fcport_update_gen);
3667 set_bit(FCPORT_UPDATE_NEEDED, &base_vha->dpc_flags);
3668 qla2xxx_wake_dpc(base_vha);
3672 ql_dbg(ql_dbg_disc, fcport->vha, 0x2109,
3673 "%s %8phN. rport %p roles %x\n",
3674 __func__, fcport->port_name, rport,
3676 fc_remote_port_delete(rport);
3678 qlt_do_generation_tick(vha, &now);
3683 * qla2x00_mark_device_lost Updates fcport state when device goes offline.
3685 * Input: ha = adapter block pointer. fcport = port structure pointer.
3691 void qla2x00_mark_device_lost(scsi_qla_host_t *vha, fc_port_t *fcport,
3692 int do_login, int defer)
3694 if (IS_QLAFX00(vha->hw)) {
3695 qla2x00_set_fcport_state(fcport, FCS_DEVICE_LOST);
3696 qla2x00_schedule_rport_del(vha, fcport, defer);
3700 if (atomic_read(&fcport->state) == FCS_ONLINE &&
3701 vha->vp_idx == fcport->vha->vp_idx) {
3702 qla2x00_set_fcport_state(fcport, FCS_DEVICE_LOST);
3703 qla2x00_schedule_rport_del(vha, fcport, defer);
3706 * We may need to retry the login, so don't change the state of the
3707 * port but do the retries.
3709 if (atomic_read(&fcport->state) != FCS_DEVICE_DEAD)
3710 qla2x00_set_fcport_state(fcport, FCS_DEVICE_LOST);
3715 set_bit(RELOGIN_NEEDED, &vha->dpc_flags);
3717 if (fcport->login_retry == 0) {
3718 fcport->login_retry = vha->hw->login_retry_count;
3720 ql_dbg(ql_dbg_disc, vha, 0x20a3,
3721 "Port login retry %8phN, lid 0x%04x retry cnt=%d.\n",
3722 fcport->port_name, fcport->loop_id, fcport->login_retry);
3727 * qla2x00_mark_all_devices_lost
3728 * Updates fcport state when device goes offline.
3731 * ha = adapter block pointer.
3732 * fcport = port structure pointer.
3740 qla2x00_mark_all_devices_lost(scsi_qla_host_t *vha, int defer)
3744 ql_dbg(ql_dbg_disc, vha, 0x20f1,
3745 "Mark all dev lost\n");
3747 list_for_each_entry(fcport, &vha->vp_fcports, list) {
3748 fcport->scan_state = 0;
3749 qlt_schedule_sess_for_deletion_lock(fcport);
3751 if (vha->vp_idx != 0 && vha->vp_idx != fcport->vha->vp_idx)
3755 * No point in marking the device as lost, if the device is
3758 if (atomic_read(&fcport->state) == FCS_DEVICE_DEAD)
3760 if (atomic_read(&fcport->state) == FCS_ONLINE) {
3761 qla2x00_set_fcport_state(fcport, FCS_DEVICE_LOST);
3763 qla2x00_schedule_rport_del(vha, fcport, defer);
3764 else if (vha->vp_idx == fcport->vha->vp_idx)
3765 qla2x00_schedule_rport_del(vha, fcport, defer);
3772 * Allocates adapter memory.
3779 qla2x00_mem_alloc(struct qla_hw_data *ha, uint16_t req_len, uint16_t rsp_len,
3780 struct req_que **req, struct rsp_que **rsp)
3784 ha->init_cb = dma_alloc_coherent(&ha->pdev->dev, ha->init_cb_size,
3785 &ha->init_cb_dma, GFP_KERNEL);
3789 if (qlt_mem_alloc(ha) < 0)
3790 goto fail_free_init_cb;
3792 ha->gid_list = dma_alloc_coherent(&ha->pdev->dev,
3793 qla2x00_gid_list_size(ha), &ha->gid_list_dma, GFP_KERNEL);
3795 goto fail_free_tgt_mem;
3797 ha->srb_mempool = mempool_create_slab_pool(SRB_MIN_REQ, srb_cachep);
3798 if (!ha->srb_mempool)
3799 goto fail_free_gid_list;
3801 if (IS_P3P_TYPE(ha)) {
3802 /* Allocate cache for CT6 Ctx. */
3804 ctx_cachep = kmem_cache_create("qla2xxx_ctx",
3805 sizeof(struct ct6_dsd), 0,
3806 SLAB_HWCACHE_ALIGN, NULL);
3808 goto fail_free_srb_mempool;
3810 ha->ctx_mempool = mempool_create_slab_pool(SRB_MIN_REQ,
3812 if (!ha->ctx_mempool)
3813 goto fail_free_srb_mempool;
3814 ql_dbg_pci(ql_dbg_init, ha->pdev, 0x0021,
3815 "ctx_cachep=%p ctx_mempool=%p.\n",
3816 ctx_cachep, ha->ctx_mempool);
3819 /* Get memory for cached NVRAM */
3820 ha->nvram = kzalloc(MAX_NVRAM_SIZE, GFP_KERNEL);
3822 goto fail_free_ctx_mempool;
3824 snprintf(name, sizeof(name), "%s_%d", QLA2XXX_DRIVER_NAME,
3826 ha->s_dma_pool = dma_pool_create(name, &ha->pdev->dev,
3827 DMA_POOL_SIZE, 8, 0);
3828 if (!ha->s_dma_pool)
3829 goto fail_free_nvram;
3831 ql_dbg_pci(ql_dbg_init, ha->pdev, 0x0022,
3832 "init_cb=%p gid_list=%p, srb_mempool=%p s_dma_pool=%p.\n",
3833 ha->init_cb, ha->gid_list, ha->srb_mempool, ha->s_dma_pool);
3835 if (IS_P3P_TYPE(ha) || ql2xenabledif) {
3836 ha->dl_dma_pool = dma_pool_create(name, &ha->pdev->dev,
3837 DSD_LIST_DMA_POOL_SIZE, 8, 0);
3838 if (!ha->dl_dma_pool) {
3839 ql_log_pci(ql_log_fatal, ha->pdev, 0x0023,
3840 "Failed to allocate memory for dl_dma_pool.\n");
3841 goto fail_s_dma_pool;
3844 ha->fcp_cmnd_dma_pool = dma_pool_create(name, &ha->pdev->dev,
3845 FCP_CMND_DMA_POOL_SIZE, 8, 0);
3846 if (!ha->fcp_cmnd_dma_pool) {
3847 ql_log_pci(ql_log_fatal, ha->pdev, 0x0024,
3848 "Failed to allocate memory for fcp_cmnd_dma_pool.\n");
3849 goto fail_dl_dma_pool;
3851 ql_dbg_pci(ql_dbg_init, ha->pdev, 0x0025,
3852 "dl_dma_pool=%p fcp_cmnd_dma_pool=%p.\n",
3853 ha->dl_dma_pool, ha->fcp_cmnd_dma_pool);
3856 /* Allocate memory for SNS commands */
3857 if (IS_QLA2100(ha) || IS_QLA2200(ha)) {
3858 /* Get consistent memory allocated for SNS commands */
3859 ha->sns_cmd = dma_alloc_coherent(&ha->pdev->dev,
3860 sizeof(struct sns_cmd_pkt), &ha->sns_cmd_dma, GFP_KERNEL);
3863 ql_dbg_pci(ql_dbg_init, ha->pdev, 0x0026,
3864 "sns_cmd: %p.\n", ha->sns_cmd);
3866 /* Get consistent memory allocated for MS IOCB */
3867 ha->ms_iocb = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL,
3871 /* Get consistent memory allocated for CT SNS commands */
3872 ha->ct_sns = dma_alloc_coherent(&ha->pdev->dev,
3873 sizeof(struct ct_sns_pkt), &ha->ct_sns_dma, GFP_KERNEL);
3875 goto fail_free_ms_iocb;
3876 ql_dbg_pci(ql_dbg_init, ha->pdev, 0x0027,
3877 "ms_iocb=%p ct_sns=%p.\n",
3878 ha->ms_iocb, ha->ct_sns);
3881 /* Allocate memory for request ring */
3882 *req = kzalloc(sizeof(struct req_que), GFP_KERNEL);
3884 ql_log_pci(ql_log_fatal, ha->pdev, 0x0028,
3885 "Failed to allocate memory for req.\n");
3888 (*req)->length = req_len;
3889 (*req)->ring = dma_alloc_coherent(&ha->pdev->dev,
3890 ((*req)->length + 1) * sizeof(request_t),
3891 &(*req)->dma, GFP_KERNEL);
3892 if (!(*req)->ring) {
3893 ql_log_pci(ql_log_fatal, ha->pdev, 0x0029,
3894 "Failed to allocate memory for req_ring.\n");
3897 /* Allocate memory for response ring */
3898 *rsp = kzalloc(sizeof(struct rsp_que), GFP_KERNEL);
3900 ql_log_pci(ql_log_fatal, ha->pdev, 0x002a,
3901 "Failed to allocate memory for rsp.\n");
3905 (*rsp)->length = rsp_len;
3906 (*rsp)->ring = dma_alloc_coherent(&ha->pdev->dev,
3907 ((*rsp)->length + 1) * sizeof(response_t),
3908 &(*rsp)->dma, GFP_KERNEL);
3909 if (!(*rsp)->ring) {
3910 ql_log_pci(ql_log_fatal, ha->pdev, 0x002b,
3911 "Failed to allocate memory for rsp_ring.\n");
3916 ql_dbg_pci(ql_dbg_init, ha->pdev, 0x002c,
3917 "req=%p req->length=%d req->ring=%p rsp=%p "
3918 "rsp->length=%d rsp->ring=%p.\n",
3919 *req, (*req)->length, (*req)->ring, *rsp, (*rsp)->length,
3921 /* Allocate memory for NVRAM data for vports */
3922 if (ha->nvram_npiv_size) {
3923 ha->npiv_info = kzalloc(sizeof(struct qla_npiv_entry) *
3924 ha->nvram_npiv_size, GFP_KERNEL);
3925 if (!ha->npiv_info) {
3926 ql_log_pci(ql_log_fatal, ha->pdev, 0x002d,
3927 "Failed to allocate memory for npiv_info.\n");
3928 goto fail_npiv_info;
3931 ha->npiv_info = NULL;
3933 /* Get consistent memory allocated for EX-INIT-CB. */
3934 if (IS_CNA_CAPABLE(ha) || IS_QLA2031(ha) || IS_QLA27XX(ha)) {
3935 ha->ex_init_cb = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL,
3936 &ha->ex_init_cb_dma);
3937 if (!ha->ex_init_cb)
3938 goto fail_ex_init_cb;
3939 ql_dbg_pci(ql_dbg_init, ha->pdev, 0x002e,
3940 "ex_init_cb=%p.\n", ha->ex_init_cb);
3943 INIT_LIST_HEAD(&ha->gbl_dsd_list);
3945 /* Get consistent memory allocated for Async Port-Database. */
3946 if (!IS_FWI2_CAPABLE(ha)) {
3947 ha->async_pd = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL,
3951 ql_dbg_pci(ql_dbg_init, ha->pdev, 0x002f,
3952 "async_pd=%p.\n", ha->async_pd);
3955 INIT_LIST_HEAD(&ha->vp_list);
3957 /* Allocate memory for our loop_id bitmap */
3958 ha->loop_id_map = kzalloc(BITS_TO_LONGS(LOOPID_MAP_SIZE) * sizeof(long),
3960 if (!ha->loop_id_map)
3961 goto fail_loop_id_map;
3963 qla2x00_set_reserved_loop_ids(ha);
3964 ql_dbg_pci(ql_dbg_init, ha->pdev, 0x0123,
3965 "loop_id_map=%p.\n", ha->loop_id_map);
3971 dma_pool_free(ha->s_dma_pool, ha->async_pd, ha->async_pd_dma);
3973 dma_pool_free(ha->s_dma_pool, ha->ex_init_cb, ha->ex_init_cb_dma);
3975 kfree(ha->npiv_info);
3977 dma_free_coherent(&ha->pdev->dev, ((*rsp)->length + 1) *
3978 sizeof(response_t), (*rsp)->ring, (*rsp)->dma);
3979 (*rsp)->ring = NULL;
3984 dma_free_coherent(&ha->pdev->dev, ((*req)->length + 1) *
3985 sizeof(request_t), (*req)->ring, (*req)->dma);
3986 (*req)->ring = NULL;
3991 dma_free_coherent(&ha->pdev->dev, sizeof(struct ct_sns_pkt),
3992 ha->ct_sns, ha->ct_sns_dma);
3996 dma_pool_free(ha->s_dma_pool, ha->ms_iocb, ha->ms_iocb_dma);
3998 ha->ms_iocb_dma = 0;
4001 dma_free_coherent(&ha->pdev->dev, sizeof(struct sns_cmd_pkt),
4002 ha->sns_cmd, ha->sns_cmd_dma);
4004 if (IS_QLA82XX(ha) || ql2xenabledif) {
4005 dma_pool_destroy(ha->fcp_cmnd_dma_pool);
4006 ha->fcp_cmnd_dma_pool = NULL;
4009 if (IS_QLA82XX(ha) || ql2xenabledif) {
4010 dma_pool_destroy(ha->dl_dma_pool);
4011 ha->dl_dma_pool = NULL;
4014 dma_pool_destroy(ha->s_dma_pool);
4015 ha->s_dma_pool = NULL;
4019 fail_free_ctx_mempool:
4020 if (ha->ctx_mempool)
4021 mempool_destroy(ha->ctx_mempool);
4022 ha->ctx_mempool = NULL;
4023 fail_free_srb_mempool:
4024 if (ha->srb_mempool)
4025 mempool_destroy(ha->srb_mempool);
4026 ha->srb_mempool = NULL;
4028 dma_free_coherent(&ha->pdev->dev, qla2x00_gid_list_size(ha),
4031 ha->gid_list = NULL;
4032 ha->gid_list_dma = 0;
4036 dma_free_coherent(&ha->pdev->dev, ha->init_cb_size, ha->init_cb,
4039 ha->init_cb_dma = 0;
4041 ql_log(ql_log_fatal, NULL, 0x0030,
4042 "Memory allocation failure.\n");
4047 qla2x00_set_exlogins_buffer(scsi_qla_host_t *vha)
4050 uint16_t size, max_cnt, temp;
4051 struct qla_hw_data *ha = vha->hw;
4053 /* Return if we don't need to alloacate any extended logins */
4057 if (!IS_EXLOGIN_OFFLD_CAPABLE(ha))
4060 ql_log(ql_log_info, vha, 0xd021, "EXLOGIN count: %d.\n", ql2xexlogins);
4062 rval = qla_get_exlogin_status(vha, &size, &max_cnt);
4063 if (rval != QLA_SUCCESS) {
4064 ql_log_pci(ql_log_fatal, ha->pdev, 0xd029,
4065 "Failed to get exlogin status.\n");
4069 temp = (ql2xexlogins > max_cnt) ? max_cnt : ql2xexlogins;
4072 if (temp != ha->exlogin_size) {
4073 qla2x00_free_exlogin_buffer(ha);
4074 ha->exlogin_size = temp;
4076 ql_log(ql_log_info, vha, 0xd024,
4077 "EXLOGIN: max_logins=%d, portdb=0x%x, total=%d.\n",
4078 max_cnt, size, temp);
4080 ql_log(ql_log_info, vha, 0xd025,
4081 "EXLOGIN: requested size=0x%x\n", ha->exlogin_size);
4083 /* Get consistent memory for extended logins */
4084 ha->exlogin_buf = dma_alloc_coherent(&ha->pdev->dev,
4085 ha->exlogin_size, &ha->exlogin_buf_dma, GFP_KERNEL);
4086 if (!ha->exlogin_buf) {
4087 ql_log_pci(ql_log_fatal, ha->pdev, 0xd02a,
4088 "Failed to allocate memory for exlogin_buf_dma.\n");
4093 /* Now configure the dma buffer */
4094 rval = qla_set_exlogin_mem_cfg(vha, ha->exlogin_buf_dma);
4096 ql_log(ql_log_fatal, vha, 0xd033,
4097 "Setup extended login buffer ****FAILED****.\n");
4098 qla2x00_free_exlogin_buffer(ha);
4105 * qla2x00_free_exlogin_buffer
4108 * ha = adapter block pointer
4111 qla2x00_free_exlogin_buffer(struct qla_hw_data *ha)
4113 if (ha->exlogin_buf) {
4114 dma_free_coherent(&ha->pdev->dev, ha->exlogin_size,
4115 ha->exlogin_buf, ha->exlogin_buf_dma);
4116 ha->exlogin_buf = NULL;
4117 ha->exlogin_size = 0;
4122 qla2x00_number_of_exch(scsi_qla_host_t *vha, u32 *ret_cnt, u16 max_cnt)
4125 *ret_cnt = FW_DEF_EXCHANGES_CNT;
4127 if (qla_ini_mode_enabled(vha)) {
4128 if (ql2xiniexchg > max_cnt)
4129 ql2xiniexchg = max_cnt;
4131 if (ql2xiniexchg > FW_DEF_EXCHANGES_CNT)
4132 *ret_cnt = ql2xiniexchg;
4133 } else if (qla_tgt_mode_enabled(vha)) {
4134 if (ql2xexchoffld > max_cnt)
4135 ql2xexchoffld = max_cnt;
4137 if (ql2xexchoffld > FW_DEF_EXCHANGES_CNT)
4138 *ret_cnt = ql2xexchoffld;
4139 } else if (qla_dual_mode_enabled(vha)) {
4140 temp = ql2xiniexchg + ql2xexchoffld;
4141 if (temp > max_cnt) {
4142 ql2xiniexchg -= (temp - max_cnt)/2;
4143 ql2xexchoffld -= (((temp - max_cnt)/2) + 1);
4147 if (temp > FW_DEF_EXCHANGES_CNT)
4153 qla2x00_set_exchoffld_buffer(scsi_qla_host_t *vha)
4158 struct qla_hw_data *ha = vha->hw;
4160 if (!ha->flags.exchoffld_enabled)
4163 if (!IS_EXCHG_OFFLD_CAPABLE(ha))
4166 ql_log(ql_log_info, vha, 0xd014,
4167 "Exchange offload count: %d.\n", ql2xexlogins);
4170 rval = qla_get_exchoffld_status(vha, &size, &max_cnt);
4171 if (rval != QLA_SUCCESS) {
4172 ql_log_pci(ql_log_fatal, ha->pdev, 0xd012,
4173 "Failed to get exlogin status.\n");
4177 qla2x00_number_of_exch(vha, &temp, max_cnt);
4180 if (temp != ha->exchoffld_size) {
4181 qla2x00_free_exchoffld_buffer(ha);
4182 ha->exchoffld_size = temp;
4184 ql_log(ql_log_info, vha, 0xd016,
4185 "Exchange offload: max_count=%d, buffers=0x%x, total=%d.\n",
4186 max_cnt, size, temp);
4188 ql_log(ql_log_info, vha, 0xd017,
4189 "Exchange Buffers requested size = 0x%x\n",
4190 ha->exchoffld_size);
4192 /* Get consistent memory for extended logins */
4193 ha->exchoffld_buf = dma_alloc_coherent(&ha->pdev->dev,
4194 ha->exchoffld_size, &ha->exchoffld_buf_dma, GFP_KERNEL);
4195 if (!ha->exchoffld_buf) {
4196 ql_log_pci(ql_log_fatal, ha->pdev, 0xd013,
4197 "Failed to allocate memory for exchoffld_buf_dma.\n");
4202 /* Now configure the dma buffer */
4203 rval = qla_set_exchoffld_mem_cfg(vha);
4205 ql_log(ql_log_fatal, vha, 0xd02e,
4206 "Setup exchange offload buffer ****FAILED****.\n");
4207 qla2x00_free_exchoffld_buffer(ha);
4209 /* re-adjust number of target exchange */
4210 struct init_cb_81xx *icb = (struct init_cb_81xx *)ha->init_cb;
4212 if (qla_ini_mode_enabled(vha))
4213 icb->exchange_count = 0;
4215 icb->exchange_count = cpu_to_le16(ql2xexchoffld);
4222 * qla2x00_free_exchoffld_buffer
4225 * ha = adapter block pointer
4228 qla2x00_free_exchoffld_buffer(struct qla_hw_data *ha)
4230 if (ha->exchoffld_buf) {
4231 dma_free_coherent(&ha->pdev->dev, ha->exchoffld_size,
4232 ha->exchoffld_buf, ha->exchoffld_buf_dma);
4233 ha->exchoffld_buf = NULL;
4234 ha->exchoffld_size = 0;
4239 * qla2x00_free_fw_dump
4240 * Frees fw dump stuff.
4243 * ha = adapter block pointer
4246 qla2x00_free_fw_dump(struct qla_hw_data *ha)
4249 dma_free_coherent(&ha->pdev->dev,
4250 FCE_SIZE, ha->fce, ha->fce_dma);
4253 dma_free_coherent(&ha->pdev->dev,
4254 EFT_SIZE, ha->eft, ha->eft_dma);
4258 if (ha->fw_dump_template)
4259 vfree(ha->fw_dump_template);
4266 ha->fw_dump_cap_flags = 0;
4267 ha->fw_dump_reading = 0;
4269 ha->fw_dump_len = 0;
4270 ha->fw_dump_template = NULL;
4271 ha->fw_dump_template_len = 0;
4276 * Frees all adapter allocated memory.
4279 * ha = adapter block pointer.
4282 qla2x00_mem_free(struct qla_hw_data *ha)
4284 qla2x00_free_fw_dump(ha);
4287 dma_free_coherent(&ha->pdev->dev, MCTP_DUMP_SIZE, ha->mctp_dump,
4290 if (ha->srb_mempool)
4291 mempool_destroy(ha->srb_mempool);
4294 dma_free_coherent(&ha->pdev->dev, DCBX_TLV_DATA_SIZE,
4295 ha->dcbx_tlv, ha->dcbx_tlv_dma);
4298 dma_free_coherent(&ha->pdev->dev, XGMAC_DATA_SIZE,
4299 ha->xgmac_data, ha->xgmac_data_dma);
4302 dma_free_coherent(&ha->pdev->dev, sizeof(struct sns_cmd_pkt),
4303 ha->sns_cmd, ha->sns_cmd_dma);
4306 dma_free_coherent(&ha->pdev->dev, sizeof(struct ct_sns_pkt),
4307 ha->ct_sns, ha->ct_sns_dma);
4310 dma_pool_free(ha->s_dma_pool, ha->sfp_data, ha->sfp_data_dma);
4313 dma_pool_free(ha->s_dma_pool, ha->ms_iocb, ha->ms_iocb_dma);
4316 dma_pool_free(ha->s_dma_pool,
4317 ha->ex_init_cb, ha->ex_init_cb_dma);
4320 dma_pool_free(ha->s_dma_pool, ha->async_pd, ha->async_pd_dma);
4323 dma_pool_destroy(ha->s_dma_pool);
4326 dma_free_coherent(&ha->pdev->dev, qla2x00_gid_list_size(ha),
4327 ha->gid_list, ha->gid_list_dma);
4329 if (IS_QLA82XX(ha)) {
4330 if (!list_empty(&ha->gbl_dsd_list)) {
4331 struct dsd_dma *dsd_ptr, *tdsd_ptr;
4333 /* clean up allocated prev pool */
4334 list_for_each_entry_safe(dsd_ptr,
4335 tdsd_ptr, &ha->gbl_dsd_list, list) {
4336 dma_pool_free(ha->dl_dma_pool,
4337 dsd_ptr->dsd_addr, dsd_ptr->dsd_list_dma);
4338 list_del(&dsd_ptr->list);
4344 if (ha->dl_dma_pool)
4345 dma_pool_destroy(ha->dl_dma_pool);
4347 if (ha->fcp_cmnd_dma_pool)
4348 dma_pool_destroy(ha->fcp_cmnd_dma_pool);
4350 if (ha->ctx_mempool)
4351 mempool_destroy(ha->ctx_mempool);
4356 dma_free_coherent(&ha->pdev->dev, ha->init_cb_size,
4357 ha->init_cb, ha->init_cb_dma);
4358 vfree(ha->optrom_buffer);
4360 kfree(ha->npiv_info);
4362 kfree(ha->loop_id_map);
4364 ha->srb_mempool = NULL;
4365 ha->ctx_mempool = NULL;
4367 ha->sns_cmd_dma = 0;
4371 ha->ms_iocb_dma = 0;
4373 ha->init_cb_dma = 0;
4374 ha->ex_init_cb = NULL;
4375 ha->ex_init_cb_dma = 0;
4376 ha->async_pd = NULL;
4377 ha->async_pd_dma = 0;
4379 ha->s_dma_pool = NULL;
4380 ha->dl_dma_pool = NULL;
4381 ha->fcp_cmnd_dma_pool = NULL;
4383 ha->gid_list = NULL;
4384 ha->gid_list_dma = 0;
4386 ha->tgt.atio_ring = NULL;
4387 ha->tgt.atio_dma = 0;
4388 ha->tgt.tgt_vp_map = NULL;
4391 struct scsi_qla_host *qla2x00_create_host(struct scsi_host_template *sht,
4392 struct qla_hw_data *ha)
4394 struct Scsi_Host *host;
4395 struct scsi_qla_host *vha = NULL;
4397 host = scsi_host_alloc(sht, sizeof(scsi_qla_host_t));
4399 ql_log_pci(ql_log_fatal, ha->pdev, 0x0107,
4400 "Failed to allocate host from the scsi layer, aborting.\n");
4404 /* Clear our data area */
4405 vha = shost_priv(host);
4406 memset(vha, 0, sizeof(scsi_qla_host_t));
4409 vha->host_no = host->host_no;
4412 INIT_LIST_HEAD(&vha->vp_fcports);
4413 INIT_LIST_HEAD(&vha->work_list);
4414 INIT_LIST_HEAD(&vha->list);
4415 INIT_LIST_HEAD(&vha->qla_cmd_list);
4416 INIT_LIST_HEAD(&vha->qla_sess_op_cmd_list);
4417 INIT_LIST_HEAD(&vha->logo_list);
4418 INIT_LIST_HEAD(&vha->plogi_ack_list);
4419 INIT_LIST_HEAD(&vha->qp_list);
4420 INIT_LIST_HEAD(&vha->gnl.fcports);
4422 spin_lock_init(&vha->work_lock);
4423 spin_lock_init(&vha->cmd_list_lock);
4424 init_waitqueue_head(&vha->fcport_waitQ);
4425 init_waitqueue_head(&vha->vref_waitq);
4427 vha->gnl.size = sizeof(struct get_name_list_extended) *
4428 (ha->max_loop_id + 1);
4429 vha->gnl.l = dma_alloc_coherent(&ha->pdev->dev,
4430 vha->gnl.size, &vha->gnl.ldma, GFP_KERNEL);
4432 ql_log(ql_log_fatal, vha, 0xd04a,
4433 "Alloc failed for name list.\n");
4434 scsi_remove_host(vha->host);
4438 sprintf(vha->host_str, "%s_%ld", QLA2XXX_DRIVER_NAME, vha->host_no);
4439 ql_dbg(ql_dbg_init, vha, 0x0041,
4440 "Allocated the host=%p hw=%p vha=%p dev_name=%s",
4441 vha->host, vha->hw, vha,
4442 dev_name(&(ha->pdev->dev)));
4447 struct qla_work_evt *
4448 qla2x00_alloc_work(struct scsi_qla_host *vha, enum qla_work_type type)
4450 struct qla_work_evt *e;
4453 QLA_VHA_MARK_BUSY(vha, bail);
4457 e = kzalloc(sizeof(struct qla_work_evt), GFP_ATOMIC);
4459 QLA_VHA_MARK_NOT_BUSY(vha);
4463 INIT_LIST_HEAD(&e->list);
4465 e->flags = QLA_EVT_FLAG_FREE;
4470 qla2x00_post_work(struct scsi_qla_host *vha, struct qla_work_evt *e)
4472 unsigned long flags;
4474 spin_lock_irqsave(&vha->work_lock, flags);
4475 list_add_tail(&e->list, &vha->work_list);
4476 spin_unlock_irqrestore(&vha->work_lock, flags);
4478 if (QLA_EARLY_LINKUP(vha->hw))
4479 schedule_work(&vha->iocb_work);
4481 qla2xxx_wake_dpc(vha);
4487 qla2x00_post_aen_work(struct scsi_qla_host *vha, enum fc_host_event_code code,
4490 struct qla_work_evt *e;
4492 e = qla2x00_alloc_work(vha, QLA_EVT_AEN);
4494 return QLA_FUNCTION_FAILED;
4496 e->u.aen.code = code;
4497 e->u.aen.data = data;
4498 return qla2x00_post_work(vha, e);
4502 qla2x00_post_idc_ack_work(struct scsi_qla_host *vha, uint16_t *mb)
4504 struct qla_work_evt *e;
4506 e = qla2x00_alloc_work(vha, QLA_EVT_IDC_ACK);
4508 return QLA_FUNCTION_FAILED;
4510 memcpy(e->u.idc_ack.mb, mb, QLA_IDC_ACK_REGS * sizeof(uint16_t));
4511 return qla2x00_post_work(vha, e);
4514 #define qla2x00_post_async_work(name, type) \
4515 int qla2x00_post_async_##name##_work( \
4516 struct scsi_qla_host *vha, \
4517 fc_port_t *fcport, uint16_t *data) \
4519 struct qla_work_evt *e; \
4521 e = qla2x00_alloc_work(vha, type); \
4523 return QLA_FUNCTION_FAILED; \
4525 e->u.logio.fcport = fcport; \
4527 e->u.logio.data[0] = data[0]; \
4528 e->u.logio.data[1] = data[1]; \
4530 return qla2x00_post_work(vha, e); \
4533 qla2x00_post_async_work(login, QLA_EVT_ASYNC_LOGIN);
4534 qla2x00_post_async_work(logout, QLA_EVT_ASYNC_LOGOUT);
4535 qla2x00_post_async_work(logout_done, QLA_EVT_ASYNC_LOGOUT_DONE);
4536 qla2x00_post_async_work(adisc, QLA_EVT_ASYNC_ADISC);
4537 qla2x00_post_async_work(adisc_done, QLA_EVT_ASYNC_ADISC_DONE);
4540 qla2x00_post_uevent_work(struct scsi_qla_host *vha, u32 code)
4542 struct qla_work_evt *e;
4544 e = qla2x00_alloc_work(vha, QLA_EVT_UEVENT);
4546 return QLA_FUNCTION_FAILED;
4548 e->u.uevent.code = code;
4549 return qla2x00_post_work(vha, e);
4553 qla2x00_uevent_emit(struct scsi_qla_host *vha, u32 code)
4555 char event_string[40];
4556 char *envp[] = { event_string, NULL };
4559 case QLA_UEVENT_CODE_FW_DUMP:
4560 snprintf(event_string, sizeof(event_string), "FW_DUMP=%ld",
4567 kobject_uevent_env(&vha->hw->pdev->dev.kobj, KOBJ_CHANGE, envp);
4571 qlafx00_post_aenfx_work(struct scsi_qla_host *vha, uint32_t evtcode,
4572 uint32_t *data, int cnt)
4574 struct qla_work_evt *e;
4576 e = qla2x00_alloc_work(vha, QLA_EVT_AENFX);
4578 return QLA_FUNCTION_FAILED;
4580 e->u.aenfx.evtcode = evtcode;
4581 e->u.aenfx.count = cnt;
4582 memcpy(e->u.aenfx.mbx, data, sizeof(*data) * cnt);
4583 return qla2x00_post_work(vha, e);
4586 int qla24xx_post_upd_fcport_work(struct scsi_qla_host *vha, fc_port_t *fcport)
4588 struct qla_work_evt *e;
4590 e = qla2x00_alloc_work(vha, QLA_EVT_UPD_FCPORT);
4592 return QLA_FUNCTION_FAILED;
4594 e->u.fcport.fcport = fcport;
4595 return qla2x00_post_work(vha, e);
4599 void qla24xx_create_new_sess(struct scsi_qla_host *vha, struct qla_work_evt *e)
4601 unsigned long flags;
4602 fc_port_t *fcport = NULL;
4603 struct qlt_plogi_ack_t *pla =
4604 (struct qlt_plogi_ack_t *)e->u.new_sess.pla;
4606 spin_lock_irqsave(&vha->hw->tgt.sess_lock, flags);
4607 fcport = qla2x00_find_fcport_by_wwpn(vha, e->u.new_sess.port_name, 1);
4609 fcport->d_id = e->u.new_sess.id;
4611 fcport->fw_login_state = DSC_LS_PLOGI_PEND;
4612 qlt_plogi_ack_link(vha, pla, fcport, QLT_PLOGI_LINK_SAME_WWN);
4613 /* we took an extra ref_count to prevent PLOGI ACK when
4614 * fcport/sess has not been created.
4619 fcport = qla2x00_alloc_fcport(vha, GFP_KERNEL);
4621 fcport->d_id = e->u.new_sess.id;
4622 fcport->scan_state = QLA_FCPORT_FOUND;
4623 fcport->flags |= FCF_FABRIC_DEVICE;
4624 fcport->fw_login_state = DSC_LS_PLOGI_PEND;
4626 memcpy(fcport->port_name, e->u.new_sess.port_name,
4628 list_add_tail(&fcport->list, &vha->vp_fcports);
4631 qlt_plogi_ack_link(vha, pla, fcport,
4632 QLT_PLOGI_LINK_SAME_WWN);
4637 spin_unlock_irqrestore(&vha->hw->tgt.sess_lock, flags);
4641 qlt_plogi_ack_unref(vha, pla);
4643 qla24xx_async_gnl(vha, fcport);
4648 qla2x00_do_work(struct scsi_qla_host *vha)
4650 struct qla_work_evt *e, *tmp;
4651 unsigned long flags;
4654 spin_lock_irqsave(&vha->work_lock, flags);
4655 list_splice_init(&vha->work_list, &work);
4656 spin_unlock_irqrestore(&vha->work_lock, flags);
4658 list_for_each_entry_safe(e, tmp, &work, list) {
4659 list_del_init(&e->list);
4663 fc_host_post_event(vha->host, fc_get_event_number(),
4664 e->u.aen.code, e->u.aen.data);
4666 case QLA_EVT_IDC_ACK:
4667 qla81xx_idc_ack(vha, e->u.idc_ack.mb);
4669 case QLA_EVT_ASYNC_LOGIN:
4670 qla2x00_async_login(vha, e->u.logio.fcport,
4673 case QLA_EVT_ASYNC_LOGOUT:
4674 qla2x00_async_logout(vha, e->u.logio.fcport);
4676 case QLA_EVT_ASYNC_LOGOUT_DONE:
4677 qla2x00_async_logout_done(vha, e->u.logio.fcport,
4680 case QLA_EVT_ASYNC_ADISC:
4681 qla2x00_async_adisc(vha, e->u.logio.fcport,
4684 case QLA_EVT_ASYNC_ADISC_DONE:
4685 qla2x00_async_adisc_done(vha, e->u.logio.fcport,
4688 case QLA_EVT_UEVENT:
4689 qla2x00_uevent_emit(vha, e->u.uevent.code);
4692 qlafx00_process_aen(vha, e);
4695 qla24xx_async_gidpn(vha, e->u.fcport.fcport);
4698 qla24xx_async_gpnid(vha, &e->u.gpnid.id);
4700 case QLA_EVT_GPNID_DONE:
4701 qla24xx_async_gpnid_done(vha, e->u.iosb.sp);
4703 case QLA_EVT_NEW_SESS:
4704 qla24xx_create_new_sess(vha, e);
4707 qla24xx_async_gpdb(vha, e->u.fcport.fcport,
4711 qla24xx_async_gpsc(vha, e->u.fcport.fcport);
4713 case QLA_EVT_UPD_FCPORT:
4714 qla2x00_update_fcport(vha, e->u.fcport.fcport);
4717 qla24xx_async_gnl(vha, e->u.fcport.fcport);
4720 qla24xx_do_nack_work(vha, e);
4723 if (e->flags & QLA_EVT_FLAG_FREE)
4726 /* For each work completed decrement vha ref count */
4727 QLA_VHA_MARK_NOT_BUSY(vha);
4731 /* Relogins all the fcports of a vport
4732 * Context: dpc thread
4734 void qla2x00_relogin(struct scsi_qla_host *vha)
4738 struct event_arg ea;
4740 list_for_each_entry(fcport, &vha->vp_fcports, list) {
4742 * If the port is not ONLINE then try to login
4743 * to it if we haven't run out of retries.
4745 if (atomic_read(&fcport->state) != FCS_ONLINE &&
4746 fcport->login_retry && !(fcport->flags & FCF_ASYNC_SENT)) {
4747 fcport->login_retry--;
4748 if (fcport->flags & FCF_FABRIC_DEVICE) {
4749 ql_dbg(ql_dbg_disc, fcport->vha, 0x2108,
4750 "%s %8phC DS %d LS %d\n", __func__,
4751 fcport->port_name, fcport->disc_state,
4752 fcport->fw_login_state);
4753 memset(&ea, 0, sizeof(ea));
4754 ea.event = FCME_RELOGIN;
4756 qla2x00_fcport_event_handler(vha, &ea);
4758 status = qla2x00_local_device_login(vha,
4760 if (status == QLA_SUCCESS) {
4761 fcport->old_loop_id = fcport->loop_id;
4762 ql_dbg(ql_dbg_disc, vha, 0x2003,
4763 "Port login OK: logged in ID 0x%x.\n",
4765 qla2x00_update_fcport(vha, fcport);
4766 } else if (status == 1) {
4767 set_bit(RELOGIN_NEEDED, &vha->dpc_flags);
4768 /* retry the login again */
4769 ql_dbg(ql_dbg_disc, vha, 0x2007,
4770 "Retrying %d login again loop_id 0x%x.\n",
4771 fcport->login_retry,
4774 fcport->login_retry = 0;
4777 if (fcport->login_retry == 0 &&
4778 status != QLA_SUCCESS)
4779 qla2x00_clear_loop_id(fcport);
4782 if (test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags))
4787 /* Schedule work on any of the dpc-workqueues */
4789 qla83xx_schedule_work(scsi_qla_host_t *base_vha, int work_code)
4791 struct qla_hw_data *ha = base_vha->hw;
4793 switch (work_code) {
4794 case MBA_IDC_AEN: /* 0x8200 */
4796 queue_work(ha->dpc_lp_wq, &ha->idc_aen);
4799 case QLA83XX_NIC_CORE_RESET: /* 0x1 */
4800 if (!ha->flags.nic_core_reset_hdlr_active) {
4802 queue_work(ha->dpc_hp_wq, &ha->nic_core_reset);
4804 ql_dbg(ql_dbg_p3p, base_vha, 0xb05e,
4805 "NIC Core reset is already active. Skip "
4806 "scheduling it again.\n");
4808 case QLA83XX_IDC_STATE_HANDLER: /* 0x2 */
4810 queue_work(ha->dpc_hp_wq, &ha->idc_state_handler);
4812 case QLA83XX_NIC_CORE_UNRECOVERABLE: /* 0x3 */
4814 queue_work(ha->dpc_hp_wq, &ha->nic_core_unrecoverable);
4817 ql_log(ql_log_warn, base_vha, 0xb05f,
4818 "Unknown work-code=0x%x.\n", work_code);
4824 /* Work: Perform NIC Core Unrecoverable state handling */
4826 qla83xx_nic_core_unrecoverable_work(struct work_struct *work)
4828 struct qla_hw_data *ha =
4829 container_of(work, struct qla_hw_data, nic_core_unrecoverable);
4830 scsi_qla_host_t *base_vha = pci_get_drvdata(ha->pdev);
4831 uint32_t dev_state = 0;
4833 qla83xx_idc_lock(base_vha, 0);
4834 qla83xx_rd_reg(base_vha, QLA83XX_IDC_DEV_STATE, &dev_state);
4835 qla83xx_reset_ownership(base_vha);
4836 if (ha->flags.nic_core_reset_owner) {
4837 ha->flags.nic_core_reset_owner = 0;
4838 qla83xx_wr_reg(base_vha, QLA83XX_IDC_DEV_STATE,
4839 QLA8XXX_DEV_FAILED);
4840 ql_log(ql_log_info, base_vha, 0xb060, "HW State: FAILED.\n");
4841 qla83xx_schedule_work(base_vha, QLA83XX_IDC_STATE_HANDLER);
4843 qla83xx_idc_unlock(base_vha, 0);
4846 /* Work: Execute IDC state handler */
4848 qla83xx_idc_state_handler_work(struct work_struct *work)
4850 struct qla_hw_data *ha =
4851 container_of(work, struct qla_hw_data, idc_state_handler);
4852 scsi_qla_host_t *base_vha = pci_get_drvdata(ha->pdev);
4853 uint32_t dev_state = 0;
4855 qla83xx_idc_lock(base_vha, 0);
4856 qla83xx_rd_reg(base_vha, QLA83XX_IDC_DEV_STATE, &dev_state);
4857 if (dev_state == QLA8XXX_DEV_FAILED ||
4858 dev_state == QLA8XXX_DEV_NEED_QUIESCENT)
4859 qla83xx_idc_state_handler(base_vha);
4860 qla83xx_idc_unlock(base_vha, 0);
4864 qla83xx_check_nic_core_fw_alive(scsi_qla_host_t *base_vha)
4866 int rval = QLA_SUCCESS;
4867 unsigned long heart_beat_wait = jiffies + (1 * HZ);
4868 uint32_t heart_beat_counter1, heart_beat_counter2;
4871 if (time_after(jiffies, heart_beat_wait)) {
4872 ql_dbg(ql_dbg_p3p, base_vha, 0xb07c,
4873 "Nic Core f/w is not alive.\n");
4874 rval = QLA_FUNCTION_FAILED;
4878 qla83xx_idc_lock(base_vha, 0);
4879 qla83xx_rd_reg(base_vha, QLA83XX_FW_HEARTBEAT,
4880 &heart_beat_counter1);
4881 qla83xx_idc_unlock(base_vha, 0);
4883 qla83xx_idc_lock(base_vha, 0);
4884 qla83xx_rd_reg(base_vha, QLA83XX_FW_HEARTBEAT,
4885 &heart_beat_counter2);
4886 qla83xx_idc_unlock(base_vha, 0);
4887 } while (heart_beat_counter1 == heart_beat_counter2);
4892 /* Work: Perform NIC Core Reset handling */
4894 qla83xx_nic_core_reset_work(struct work_struct *work)
4896 struct qla_hw_data *ha =
4897 container_of(work, struct qla_hw_data, nic_core_reset);
4898 scsi_qla_host_t *base_vha = pci_get_drvdata(ha->pdev);
4899 uint32_t dev_state = 0;
4901 if (IS_QLA2031(ha)) {
4902 if (qla2xxx_mctp_dump(base_vha) != QLA_SUCCESS)
4903 ql_log(ql_log_warn, base_vha, 0xb081,
4904 "Failed to dump mctp\n");
4908 if (!ha->flags.nic_core_reset_hdlr_active) {
4909 if (qla83xx_check_nic_core_fw_alive(base_vha) == QLA_SUCCESS) {
4910 qla83xx_idc_lock(base_vha, 0);
4911 qla83xx_rd_reg(base_vha, QLA83XX_IDC_DEV_STATE,
4913 qla83xx_idc_unlock(base_vha, 0);
4914 if (dev_state != QLA8XXX_DEV_NEED_RESET) {
4915 ql_dbg(ql_dbg_p3p, base_vha, 0xb07a,
4916 "Nic Core f/w is alive.\n");
4921 ha->flags.nic_core_reset_hdlr_active = 1;
4922 if (qla83xx_nic_core_reset(base_vha)) {
4923 /* NIC Core reset failed. */
4924 ql_dbg(ql_dbg_p3p, base_vha, 0xb061,
4925 "NIC Core reset failed.\n");
4927 ha->flags.nic_core_reset_hdlr_active = 0;
4931 /* Work: Handle 8200 IDC aens */
4933 qla83xx_service_idc_aen(struct work_struct *work)
4935 struct qla_hw_data *ha =
4936 container_of(work, struct qla_hw_data, idc_aen);
4937 scsi_qla_host_t *base_vha = pci_get_drvdata(ha->pdev);
4938 uint32_t dev_state, idc_control;
4940 qla83xx_idc_lock(base_vha, 0);
4941 qla83xx_rd_reg(base_vha, QLA83XX_IDC_DEV_STATE, &dev_state);
4942 qla83xx_rd_reg(base_vha, QLA83XX_IDC_CONTROL, &idc_control);
4943 qla83xx_idc_unlock(base_vha, 0);
4944 if (dev_state == QLA8XXX_DEV_NEED_RESET) {
4945 if (idc_control & QLA83XX_IDC_GRACEFUL_RESET) {
4946 ql_dbg(ql_dbg_p3p, base_vha, 0xb062,
4947 "Application requested NIC Core Reset.\n");
4948 qla83xx_schedule_work(base_vha, QLA83XX_NIC_CORE_RESET);
4949 } else if (qla83xx_check_nic_core_fw_alive(base_vha) ==
4951 ql_dbg(ql_dbg_p3p, base_vha, 0xb07b,
4952 "Other protocol driver requested NIC Core Reset.\n");
4953 qla83xx_schedule_work(base_vha, QLA83XX_NIC_CORE_RESET);
4955 } else if (dev_state == QLA8XXX_DEV_FAILED ||
4956 dev_state == QLA8XXX_DEV_NEED_QUIESCENT) {
4957 qla83xx_schedule_work(base_vha, QLA83XX_IDC_STATE_HANDLER);
4962 qla83xx_wait_logic(void)
4967 if (!in_interrupt()) {
4969 * Wait about 200ms before retrying again.
4970 * This controls the number of retries for single
4976 for (i = 0; i < 20; i++)
4977 cpu_relax(); /* This a nop instr on i386 */
4982 qla83xx_force_lock_recovery(scsi_qla_host_t *base_vha)
4986 uint32_t idc_lck_rcvry_stage_mask = 0x3;
4987 uint32_t idc_lck_rcvry_owner_mask = 0x3c;
4988 struct qla_hw_data *ha = base_vha->hw;
4989 ql_dbg(ql_dbg_p3p, base_vha, 0xb086,
4990 "Trying force recovery of the IDC lock.\n");
4992 rval = qla83xx_rd_reg(base_vha, QLA83XX_IDC_LOCK_RECOVERY, &data);
4996 if ((data & idc_lck_rcvry_stage_mask) > 0) {
4999 data = (IDC_LOCK_RECOVERY_STAGE1) | (ha->portnum << 2);
5000 rval = qla83xx_wr_reg(base_vha, QLA83XX_IDC_LOCK_RECOVERY,
5007 rval = qla83xx_rd_reg(base_vha, QLA83XX_IDC_LOCK_RECOVERY,
5012 if (((data & idc_lck_rcvry_owner_mask) >> 2) == ha->portnum) {
5013 data &= (IDC_LOCK_RECOVERY_STAGE2 |
5014 ~(idc_lck_rcvry_stage_mask));
5015 rval = qla83xx_wr_reg(base_vha,
5016 QLA83XX_IDC_LOCK_RECOVERY, data);
5020 /* Forcefully perform IDC UnLock */
5021 rval = qla83xx_rd_reg(base_vha, QLA83XX_DRIVER_UNLOCK,
5025 /* Clear lock-id by setting 0xff */
5026 rval = qla83xx_wr_reg(base_vha, QLA83XX_DRIVER_LOCKID,
5030 /* Clear lock-recovery by setting 0x0 */
5031 rval = qla83xx_wr_reg(base_vha,
5032 QLA83XX_IDC_LOCK_RECOVERY, 0x0);
5043 qla83xx_idc_lock_recovery(scsi_qla_host_t *base_vha)
5045 int rval = QLA_SUCCESS;
5046 uint32_t o_drv_lockid, n_drv_lockid;
5047 unsigned long lock_recovery_timeout;
5049 lock_recovery_timeout = jiffies + QLA83XX_MAX_LOCK_RECOVERY_WAIT;
5051 rval = qla83xx_rd_reg(base_vha, QLA83XX_DRIVER_LOCKID, &o_drv_lockid);
5055 /* MAX wait time before forcing IDC Lock recovery = 2 secs */
5056 if (time_after_eq(jiffies, lock_recovery_timeout)) {
5057 if (qla83xx_force_lock_recovery(base_vha) == QLA_SUCCESS)
5060 return QLA_FUNCTION_FAILED;
5063 rval = qla83xx_rd_reg(base_vha, QLA83XX_DRIVER_LOCKID, &n_drv_lockid);
5067 if (o_drv_lockid == n_drv_lockid) {
5068 qla83xx_wait_logic();
5078 qla83xx_idc_lock(scsi_qla_host_t *base_vha, uint16_t requester_id)
5080 uint16_t options = (requester_id << 15) | BIT_6;
5082 uint32_t lock_owner;
5083 struct qla_hw_data *ha = base_vha->hw;
5085 /* IDC-lock implementation using driver-lock/lock-id remote registers */
5087 if (qla83xx_rd_reg(base_vha, QLA83XX_DRIVER_LOCK, &data)
5090 /* Setting lock-id to our function-number */
5091 qla83xx_wr_reg(base_vha, QLA83XX_DRIVER_LOCKID,
5094 qla83xx_rd_reg(base_vha, QLA83XX_DRIVER_LOCKID,
5096 ql_dbg(ql_dbg_p3p, base_vha, 0xb063,
5097 "Failed to acquire IDC lock, acquired by %d, "
5098 "retrying...\n", lock_owner);
5100 /* Retry/Perform IDC-Lock recovery */
5101 if (qla83xx_idc_lock_recovery(base_vha)
5103 qla83xx_wait_logic();
5106 ql_log(ql_log_warn, base_vha, 0xb075,
5107 "IDC Lock recovery FAILED.\n");
5114 /* XXX: IDC-lock implementation using access-control mbx */
5116 if (qla83xx_access_control(base_vha, options, 0, 0, NULL)) {
5117 ql_dbg(ql_dbg_p3p, base_vha, 0xb072,
5118 "Failed to acquire IDC lock. retrying...\n");
5119 /* Retry/Perform IDC-Lock recovery */
5120 if (qla83xx_idc_lock_recovery(base_vha) == QLA_SUCCESS) {
5121 qla83xx_wait_logic();
5124 ql_log(ql_log_warn, base_vha, 0xb076,
5125 "IDC Lock recovery FAILED.\n");
5132 qla83xx_idc_unlock(scsi_qla_host_t *base_vha, uint16_t requester_id)
5135 uint16_t options = (requester_id << 15) | BIT_7;
5139 struct qla_hw_data *ha = base_vha->hw;
5141 /* IDC-unlock implementation using driver-unlock/lock-id
5146 if (qla83xx_rd_reg(base_vha, QLA83XX_DRIVER_LOCKID, &data)
5148 if (data == ha->portnum) {
5149 qla83xx_rd_reg(base_vha, QLA83XX_DRIVER_UNLOCK, &data);
5150 /* Clearing lock-id by setting 0xff */
5151 qla83xx_wr_reg(base_vha, QLA83XX_DRIVER_LOCKID, 0xff);
5152 } else if (retry < 10) {
5153 /* SV: XXX: IDC unlock retrying needed here? */
5155 /* Retry for IDC-unlock */
5156 qla83xx_wait_logic();
5158 ql_dbg(ql_dbg_p3p, base_vha, 0xb064,
5159 "Failed to release IDC lock, retrying=%d\n", retry);
5162 } else if (retry < 10) {
5163 /* Retry for IDC-unlock */
5164 qla83xx_wait_logic();
5166 ql_dbg(ql_dbg_p3p, base_vha, 0xb065,
5167 "Failed to read drv-lockid, retrying=%d\n", retry);
5174 /* XXX: IDC-unlock implementation using access-control mbx */
5177 if (qla83xx_access_control(base_vha, options, 0, 0, NULL)) {
5179 /* Retry for IDC-unlock */
5180 qla83xx_wait_logic();
5182 ql_dbg(ql_dbg_p3p, base_vha, 0xb066,
5183 "Failed to release IDC lock, retrying=%d\n", retry);
5193 __qla83xx_set_drv_presence(scsi_qla_host_t *vha)
5195 int rval = QLA_SUCCESS;
5196 struct qla_hw_data *ha = vha->hw;
5197 uint32_t drv_presence;
5199 rval = qla83xx_rd_reg(vha, QLA83XX_IDC_DRV_PRESENCE, &drv_presence);
5200 if (rval == QLA_SUCCESS) {
5201 drv_presence |= (1 << ha->portnum);
5202 rval = qla83xx_wr_reg(vha, QLA83XX_IDC_DRV_PRESENCE,
5210 qla83xx_set_drv_presence(scsi_qla_host_t *vha)
5212 int rval = QLA_SUCCESS;
5214 qla83xx_idc_lock(vha, 0);
5215 rval = __qla83xx_set_drv_presence(vha);
5216 qla83xx_idc_unlock(vha, 0);
5222 __qla83xx_clear_drv_presence(scsi_qla_host_t *vha)
5224 int rval = QLA_SUCCESS;
5225 struct qla_hw_data *ha = vha->hw;
5226 uint32_t drv_presence;
5228 rval = qla83xx_rd_reg(vha, QLA83XX_IDC_DRV_PRESENCE, &drv_presence);
5229 if (rval == QLA_SUCCESS) {
5230 drv_presence &= ~(1 << ha->portnum);
5231 rval = qla83xx_wr_reg(vha, QLA83XX_IDC_DRV_PRESENCE,
5239 qla83xx_clear_drv_presence(scsi_qla_host_t *vha)
5241 int rval = QLA_SUCCESS;
5243 qla83xx_idc_lock(vha, 0);
5244 rval = __qla83xx_clear_drv_presence(vha);
5245 qla83xx_idc_unlock(vha, 0);
5251 qla83xx_need_reset_handler(scsi_qla_host_t *vha)
5253 struct qla_hw_data *ha = vha->hw;
5254 uint32_t drv_ack, drv_presence;
5255 unsigned long ack_timeout;
5257 /* Wait for IDC ACK from all functions (DRV-ACK == DRV-PRESENCE) */
5258 ack_timeout = jiffies + (ha->fcoe_reset_timeout * HZ);
5260 qla83xx_rd_reg(vha, QLA83XX_IDC_DRIVER_ACK, &drv_ack);
5261 qla83xx_rd_reg(vha, QLA83XX_IDC_DRV_PRESENCE, &drv_presence);
5262 if ((drv_ack & drv_presence) == drv_presence)
5265 if (time_after_eq(jiffies, ack_timeout)) {
5266 ql_log(ql_log_warn, vha, 0xb067,
5267 "RESET ACK TIMEOUT! drv_presence=0x%x "
5268 "drv_ack=0x%x\n", drv_presence, drv_ack);
5270 * The function(s) which did not ack in time are forced
5271 * to withdraw any further participation in the IDC
5274 if (drv_ack != drv_presence)
5275 qla83xx_wr_reg(vha, QLA83XX_IDC_DRV_PRESENCE,
5280 qla83xx_idc_unlock(vha, 0);
5282 qla83xx_idc_lock(vha, 0);
5285 qla83xx_wr_reg(vha, QLA83XX_IDC_DEV_STATE, QLA8XXX_DEV_COLD);
5286 ql_log(ql_log_info, vha, 0xb068, "HW State: COLD/RE-INIT.\n");
5290 qla83xx_device_bootstrap(scsi_qla_host_t *vha)
5292 int rval = QLA_SUCCESS;
5293 uint32_t idc_control;
5295 qla83xx_wr_reg(vha, QLA83XX_IDC_DEV_STATE, QLA8XXX_DEV_INITIALIZING);
5296 ql_log(ql_log_info, vha, 0xb069, "HW State: INITIALIZING.\n");
5298 /* Clearing IDC-Control Graceful-Reset Bit before resetting f/w */
5299 __qla83xx_get_idc_control(vha, &idc_control);
5300 idc_control &= ~QLA83XX_IDC_GRACEFUL_RESET;
5301 __qla83xx_set_idc_control(vha, 0);
5303 qla83xx_idc_unlock(vha, 0);
5304 rval = qla83xx_restart_nic_firmware(vha);
5305 qla83xx_idc_lock(vha, 0);
5307 if (rval != QLA_SUCCESS) {
5308 ql_log(ql_log_fatal, vha, 0xb06a,
5309 "Failed to restart NIC f/w.\n");
5310 qla83xx_wr_reg(vha, QLA83XX_IDC_DEV_STATE, QLA8XXX_DEV_FAILED);
5311 ql_log(ql_log_info, vha, 0xb06b, "HW State: FAILED.\n");
5313 ql_dbg(ql_dbg_p3p, vha, 0xb06c,
5314 "Success in restarting nic f/w.\n");
5315 qla83xx_wr_reg(vha, QLA83XX_IDC_DEV_STATE, QLA8XXX_DEV_READY);
5316 ql_log(ql_log_info, vha, 0xb06d, "HW State: READY.\n");
5322 /* Assumes idc_lock always held on entry */
5324 qla83xx_idc_state_handler(scsi_qla_host_t *base_vha)
5326 struct qla_hw_data *ha = base_vha->hw;
5327 int rval = QLA_SUCCESS;
5328 unsigned long dev_init_timeout;
5331 /* Wait for MAX-INIT-TIMEOUT for the device to go ready */
5332 dev_init_timeout = jiffies + (ha->fcoe_dev_init_timeout * HZ);
5336 if (time_after_eq(jiffies, dev_init_timeout)) {
5337 ql_log(ql_log_warn, base_vha, 0xb06e,
5338 "Initialization TIMEOUT!\n");
5339 /* Init timeout. Disable further NIC Core
5342 qla83xx_wr_reg(base_vha, QLA83XX_IDC_DEV_STATE,
5343 QLA8XXX_DEV_FAILED);
5344 ql_log(ql_log_info, base_vha, 0xb06f,
5345 "HW State: FAILED.\n");
5348 qla83xx_rd_reg(base_vha, QLA83XX_IDC_DEV_STATE, &dev_state);
5349 switch (dev_state) {
5350 case QLA8XXX_DEV_READY:
5351 if (ha->flags.nic_core_reset_owner)
5352 qla83xx_idc_audit(base_vha,
5353 IDC_AUDIT_COMPLETION);
5354 ha->flags.nic_core_reset_owner = 0;
5355 ql_dbg(ql_dbg_p3p, base_vha, 0xb070,
5356 "Reset_owner reset by 0x%x.\n",
5359 case QLA8XXX_DEV_COLD:
5360 if (ha->flags.nic_core_reset_owner)
5361 rval = qla83xx_device_bootstrap(base_vha);
5363 /* Wait for AEN to change device-state */
5364 qla83xx_idc_unlock(base_vha, 0);
5366 qla83xx_idc_lock(base_vha, 0);
5369 case QLA8XXX_DEV_INITIALIZING:
5370 /* Wait for AEN to change device-state */
5371 qla83xx_idc_unlock(base_vha, 0);
5373 qla83xx_idc_lock(base_vha, 0);
5375 case QLA8XXX_DEV_NEED_RESET:
5376 if (!ql2xdontresethba && ha->flags.nic_core_reset_owner)
5377 qla83xx_need_reset_handler(base_vha);
5379 /* Wait for AEN to change device-state */
5380 qla83xx_idc_unlock(base_vha, 0);
5382 qla83xx_idc_lock(base_vha, 0);
5384 /* reset timeout value after need reset handler */
5385 dev_init_timeout = jiffies +
5386 (ha->fcoe_dev_init_timeout * HZ);
5388 case QLA8XXX_DEV_NEED_QUIESCENT:
5389 /* XXX: DEBUG for now */
5390 qla83xx_idc_unlock(base_vha, 0);
5392 qla83xx_idc_lock(base_vha, 0);
5394 case QLA8XXX_DEV_QUIESCENT:
5395 /* XXX: DEBUG for now */
5396 if (ha->flags.quiesce_owner)
5399 qla83xx_idc_unlock(base_vha, 0);
5401 qla83xx_idc_lock(base_vha, 0);
5402 dev_init_timeout = jiffies +
5403 (ha->fcoe_dev_init_timeout * HZ);
5405 case QLA8XXX_DEV_FAILED:
5406 if (ha->flags.nic_core_reset_owner)
5407 qla83xx_idc_audit(base_vha,
5408 IDC_AUDIT_COMPLETION);
5409 ha->flags.nic_core_reset_owner = 0;
5410 __qla83xx_clear_drv_presence(base_vha);
5411 qla83xx_idc_unlock(base_vha, 0);
5412 qla8xxx_dev_failed_handler(base_vha);
5413 rval = QLA_FUNCTION_FAILED;
5414 qla83xx_idc_lock(base_vha, 0);
5416 case QLA8XXX_BAD_VALUE:
5417 qla83xx_idc_unlock(base_vha, 0);
5419 qla83xx_idc_lock(base_vha, 0);
5422 ql_log(ql_log_warn, base_vha, 0xb071,
5423 "Unknown Device State: %x.\n", dev_state);
5424 qla83xx_idc_unlock(base_vha, 0);
5425 qla8xxx_dev_failed_handler(base_vha);
5426 rval = QLA_FUNCTION_FAILED;
5427 qla83xx_idc_lock(base_vha, 0);
5437 qla2x00_disable_board_on_pci_error(struct work_struct *work)
5439 struct qla_hw_data *ha = container_of(work, struct qla_hw_data,
5441 struct pci_dev *pdev = ha->pdev;
5442 scsi_qla_host_t *base_vha = pci_get_drvdata(ha->pdev);
5445 * if UNLOAD flag is already set, then continue unload,
5446 * where it was set first.
5448 if (test_bit(UNLOADING, &base_vha->dpc_flags))
5451 ql_log(ql_log_warn, base_vha, 0x015b,
5452 "Disabling adapter.\n");
5454 qla2x00_wait_for_sess_deletion(base_vha);
5456 set_bit(UNLOADING, &base_vha->dpc_flags);
5458 qla2x00_delete_all_vps(ha, base_vha);
5460 qla2x00_abort_all_cmds(base_vha, DID_NO_CONNECT << 16);
5462 qla2x00_dfs_remove(base_vha);
5464 qla84xx_put_chip(base_vha);
5466 if (base_vha->timer_active)
5467 qla2x00_stop_timer(base_vha);
5469 base_vha->flags.online = 0;
5471 qla2x00_destroy_deferred_work(ha);
5474 * Do not try to stop beacon blink as it will issue a mailbox
5477 qla2x00_free_sysfs_attr(base_vha, false);
5479 fc_remove_host(base_vha->host);
5481 scsi_remove_host(base_vha->host);
5483 base_vha->flags.init_done = 0;
5484 qla25xx_delete_queues(base_vha);
5485 qla2x00_free_fcports(base_vha);
5486 qla2x00_free_irqs(base_vha);
5487 qla2x00_mem_free(ha);
5488 qla82xx_md_free(base_vha);
5489 qla2x00_free_queues(ha);
5491 qla2x00_unmap_iobases(ha);
5493 pci_release_selected_regions(ha->pdev, ha->bars);
5494 pci_disable_pcie_error_reporting(pdev);
5495 pci_disable_device(pdev);
5498 * Let qla2x00_remove_one cleanup qla_hw_data on device removal.
5502 /**************************************************************************
5504 * This kernel thread is a task that is schedule by the interrupt handler
5505 * to perform the background processing for interrupts.
5508 * This task always run in the context of a kernel thread. It
5509 * is kick-off by the driver's detect code and starts up
5510 * up one per adapter. It immediately goes to sleep and waits for
5511 * some fibre event. When either the interrupt handler or
5512 * the timer routine detects a event it will one of the task
5513 * bits then wake us up.
5514 **************************************************************************/
5516 qla2x00_do_dpc(void *data)
5518 scsi_qla_host_t *base_vha;
5519 struct qla_hw_data *ha;
5521 struct qla_qpair *qpair;
5523 ha = (struct qla_hw_data *)data;
5524 base_vha = pci_get_drvdata(ha->pdev);
5526 set_user_nice(current, MIN_NICE);
5528 set_current_state(TASK_INTERRUPTIBLE);
5529 while (!kthread_should_stop()) {
5530 ql_dbg(ql_dbg_dpc, base_vha, 0x4000,
5531 "DPC handler sleeping.\n");
5535 if (!base_vha->flags.init_done || ha->flags.mbox_busy)
5538 if (ha->flags.eeh_busy) {
5539 ql_dbg(ql_dbg_dpc, base_vha, 0x4003,
5540 "eeh_busy=%d.\n", ha->flags.eeh_busy);
5546 ql_dbg(ql_dbg_dpc + ql_dbg_verbose, base_vha, 0x4001,
5547 "DPC handler waking up, dpc_flags=0x%lx.\n",
5548 base_vha->dpc_flags);
5550 if (test_bit(UNLOADING, &base_vha->dpc_flags))
5553 qla2x00_do_work(base_vha);
5555 if (IS_P3P_TYPE(ha)) {
5556 if (IS_QLA8044(ha)) {
5557 if (test_and_clear_bit(ISP_UNRECOVERABLE,
5558 &base_vha->dpc_flags)) {
5559 qla8044_idc_lock(ha);
5560 qla8044_wr_direct(base_vha,
5561 QLA8044_CRB_DEV_STATE_INDEX,
5562 QLA8XXX_DEV_FAILED);
5563 qla8044_idc_unlock(ha);
5564 ql_log(ql_log_info, base_vha, 0x4004,
5565 "HW State: FAILED.\n");
5566 qla8044_device_state_handler(base_vha);
5571 if (test_and_clear_bit(ISP_UNRECOVERABLE,
5572 &base_vha->dpc_flags)) {
5573 qla82xx_idc_lock(ha);
5574 qla82xx_wr_32(ha, QLA82XX_CRB_DEV_STATE,
5575 QLA8XXX_DEV_FAILED);
5576 qla82xx_idc_unlock(ha);
5577 ql_log(ql_log_info, base_vha, 0x0151,
5578 "HW State: FAILED.\n");
5579 qla82xx_device_state_handler(base_vha);
5584 if (test_and_clear_bit(FCOE_CTX_RESET_NEEDED,
5585 &base_vha->dpc_flags)) {
5587 ql_dbg(ql_dbg_dpc, base_vha, 0x4005,
5588 "FCoE context reset scheduled.\n");
5589 if (!(test_and_set_bit(ABORT_ISP_ACTIVE,
5590 &base_vha->dpc_flags))) {
5591 if (qla82xx_fcoe_ctx_reset(base_vha)) {
5592 /* FCoE-ctx reset failed.
5593 * Escalate to chip-reset
5595 set_bit(ISP_ABORT_NEEDED,
5596 &base_vha->dpc_flags);
5598 clear_bit(ABORT_ISP_ACTIVE,
5599 &base_vha->dpc_flags);
5602 ql_dbg(ql_dbg_dpc, base_vha, 0x4006,
5603 "FCoE context reset end.\n");
5605 } else if (IS_QLAFX00(ha)) {
5606 if (test_and_clear_bit(ISP_UNRECOVERABLE,
5607 &base_vha->dpc_flags)) {
5608 ql_dbg(ql_dbg_dpc, base_vha, 0x4020,
5609 "Firmware Reset Recovery\n");
5610 if (qlafx00_reset_initialize(base_vha)) {
5611 /* Failed. Abort isp later. */
5612 if (!test_bit(UNLOADING,
5613 &base_vha->dpc_flags)) {
5614 set_bit(ISP_UNRECOVERABLE,
5615 &base_vha->dpc_flags);
5616 ql_dbg(ql_dbg_dpc, base_vha,
5618 "Reset Recovery Failed\n");
5623 if (test_and_clear_bit(FX00_TARGET_SCAN,
5624 &base_vha->dpc_flags)) {
5625 ql_dbg(ql_dbg_dpc, base_vha, 0x4022,
5626 "ISPFx00 Target Scan scheduled\n");
5627 if (qlafx00_rescan_isp(base_vha)) {
5628 if (!test_bit(UNLOADING,
5629 &base_vha->dpc_flags))
5630 set_bit(ISP_UNRECOVERABLE,
5631 &base_vha->dpc_flags);
5632 ql_dbg(ql_dbg_dpc, base_vha, 0x401e,
5633 "ISPFx00 Target Scan Failed\n");
5635 ql_dbg(ql_dbg_dpc, base_vha, 0x401f,
5636 "ISPFx00 Target Scan End\n");
5638 if (test_and_clear_bit(FX00_HOST_INFO_RESEND,
5639 &base_vha->dpc_flags)) {
5640 ql_dbg(ql_dbg_dpc, base_vha, 0x4023,
5641 "ISPFx00 Host Info resend scheduled\n");
5642 qlafx00_fx_disc(base_vha,
5643 &base_vha->hw->mr.fcport,
5644 FXDISC_REG_HOST_INFO);
5648 if (test_and_clear_bit(ISP_ABORT_NEEDED,
5649 &base_vha->dpc_flags)) {
5651 ql_dbg(ql_dbg_dpc, base_vha, 0x4007,
5652 "ISP abort scheduled.\n");
5653 if (!(test_and_set_bit(ABORT_ISP_ACTIVE,
5654 &base_vha->dpc_flags))) {
5656 if (ha->isp_ops->abort_isp(base_vha)) {
5657 /* failed. retry later */
5658 set_bit(ISP_ABORT_NEEDED,
5659 &base_vha->dpc_flags);
5661 clear_bit(ABORT_ISP_ACTIVE,
5662 &base_vha->dpc_flags);
5665 ql_dbg(ql_dbg_dpc, base_vha, 0x4008,
5666 "ISP abort end.\n");
5669 if (test_and_clear_bit(FCPORT_UPDATE_NEEDED,
5670 &base_vha->dpc_flags)) {
5671 qla2x00_update_fcports(base_vha);
5675 goto loop_resync_check;
5677 if (test_bit(ISP_QUIESCE_NEEDED, &base_vha->dpc_flags)) {
5678 ql_dbg(ql_dbg_dpc, base_vha, 0x4009,
5679 "Quiescence mode scheduled.\n");
5680 if (IS_P3P_TYPE(ha)) {
5682 qla82xx_device_state_handler(base_vha);
5684 qla8044_device_state_handler(base_vha);
5685 clear_bit(ISP_QUIESCE_NEEDED,
5686 &base_vha->dpc_flags);
5687 if (!ha->flags.quiesce_owner) {
5688 qla2x00_perform_loop_resync(base_vha);
5689 if (IS_QLA82XX(ha)) {
5690 qla82xx_idc_lock(ha);
5691 qla82xx_clear_qsnt_ready(
5693 qla82xx_idc_unlock(ha);
5694 } else if (IS_QLA8044(ha)) {
5695 qla8044_idc_lock(ha);
5696 qla8044_clear_qsnt_ready(
5698 qla8044_idc_unlock(ha);
5702 clear_bit(ISP_QUIESCE_NEEDED,
5703 &base_vha->dpc_flags);
5704 qla2x00_quiesce_io(base_vha);
5706 ql_dbg(ql_dbg_dpc, base_vha, 0x400a,
5707 "Quiescence mode end.\n");
5710 if (test_and_clear_bit(RESET_MARKER_NEEDED,
5711 &base_vha->dpc_flags) &&
5712 (!(test_and_set_bit(RESET_ACTIVE, &base_vha->dpc_flags)))) {
5714 ql_dbg(ql_dbg_dpc, base_vha, 0x400b,
5715 "Reset marker scheduled.\n");
5716 qla2x00_rst_aen(base_vha);
5717 clear_bit(RESET_ACTIVE, &base_vha->dpc_flags);
5718 ql_dbg(ql_dbg_dpc, base_vha, 0x400c,
5719 "Reset marker end.\n");
5722 /* Retry each device up to login retry count */
5723 if ((test_and_clear_bit(RELOGIN_NEEDED,
5724 &base_vha->dpc_flags)) &&
5725 !test_bit(LOOP_RESYNC_NEEDED, &base_vha->dpc_flags) &&
5726 atomic_read(&base_vha->loop_state) != LOOP_DOWN) {
5728 ql_dbg(ql_dbg_dpc, base_vha, 0x400d,
5729 "Relogin scheduled.\n");
5730 qla2x00_relogin(base_vha);
5731 ql_dbg(ql_dbg_dpc, base_vha, 0x400e,
5735 if (test_and_clear_bit(LOOP_RESYNC_NEEDED,
5736 &base_vha->dpc_flags)) {
5738 ql_dbg(ql_dbg_dpc, base_vha, 0x400f,
5739 "Loop resync scheduled.\n");
5741 if (!(test_and_set_bit(LOOP_RESYNC_ACTIVE,
5742 &base_vha->dpc_flags))) {
5744 qla2x00_loop_resync(base_vha);
5746 clear_bit(LOOP_RESYNC_ACTIVE,
5747 &base_vha->dpc_flags);
5750 ql_dbg(ql_dbg_dpc, base_vha, 0x4010,
5751 "Loop resync end.\n");
5757 if (test_bit(NPIV_CONFIG_NEEDED, &base_vha->dpc_flags) &&
5758 atomic_read(&base_vha->loop_state) == LOOP_READY) {
5759 clear_bit(NPIV_CONFIG_NEEDED, &base_vha->dpc_flags);
5760 qla2xxx_flash_npiv_conf(base_vha);
5764 if (!ha->interrupts_on)
5765 ha->isp_ops->enable_intrs(ha);
5767 if (test_and_clear_bit(BEACON_BLINK_NEEDED,
5768 &base_vha->dpc_flags)) {
5769 if (ha->beacon_blink_led == 1)
5770 ha->isp_ops->beacon_blink(base_vha);
5773 /* qpair online check */
5774 if (test_and_clear_bit(QPAIR_ONLINE_CHECK_NEEDED,
5775 &base_vha->dpc_flags)) {
5776 if (ha->flags.eeh_busy ||
5777 ha->flags.pci_channel_io_perm_failure)
5782 mutex_lock(&ha->mq_lock);
5783 list_for_each_entry(qpair, &base_vha->qp_list,
5785 qpair->online = online;
5786 mutex_unlock(&ha->mq_lock);
5789 if (!IS_QLAFX00(ha))
5790 qla2x00_do_dpc_all_vps(base_vha);
5794 set_current_state(TASK_INTERRUPTIBLE);
5795 } /* End of while(1) */
5796 __set_current_state(TASK_RUNNING);
5798 ql_dbg(ql_dbg_dpc, base_vha, 0x4011,
5799 "DPC handler exiting.\n");
5802 * Make sure that nobody tries to wake us up again.
5806 /* Cleanup any residual CTX SRBs. */
5807 qla2x00_abort_all_cmds(base_vha, DID_NO_CONNECT << 16);
5813 qla2xxx_wake_dpc(struct scsi_qla_host *vha)
5815 struct qla_hw_data *ha = vha->hw;
5816 struct task_struct *t = ha->dpc_thread;
5818 if (!test_bit(UNLOADING, &vha->dpc_flags) && t)
5824 * Processes asynchronous reset.
5827 * ha = adapter block pointer.
5830 qla2x00_rst_aen(scsi_qla_host_t *vha)
5832 if (vha->flags.online && !vha->flags.reset_active &&
5833 !atomic_read(&vha->loop_down_timer) &&
5834 !(test_bit(ABORT_ISP_ACTIVE, &vha->dpc_flags))) {
5836 clear_bit(RESET_MARKER_NEEDED, &vha->dpc_flags);
5839 * Issue marker command only when we are going to start
5842 vha->marker_needed = 1;
5843 } while (!atomic_read(&vha->loop_down_timer) &&
5844 (test_bit(RESET_MARKER_NEEDED, &vha->dpc_flags)));
5848 /**************************************************************************
5854 * Context: Interrupt
5855 ***************************************************************************/
5857 qla2x00_timer(scsi_qla_host_t *vha)
5859 unsigned long cpu_flags = 0;
5864 struct qla_hw_data *ha = vha->hw;
5865 struct req_que *req;
5867 if (ha->flags.eeh_busy) {
5868 ql_dbg(ql_dbg_timer, vha, 0x6000,
5869 "EEH = %d, restarting timer.\n",
5870 ha->flags.eeh_busy);
5871 qla2x00_restart_timer(vha, WATCH_INTERVAL);
5876 * Hardware read to raise pending EEH errors during mailbox waits. If
5877 * the read returns -1 then disable the board.
5879 if (!pci_channel_offline(ha->pdev)) {
5880 pci_read_config_word(ha->pdev, PCI_VENDOR_ID, &w);
5881 qla2x00_check_reg16_for_disconnect(vha, w);
5884 /* Make sure qla82xx_watchdog is run only for physical port */
5885 if (!vha->vp_idx && IS_P3P_TYPE(ha)) {
5886 if (test_bit(ISP_QUIESCE_NEEDED, &vha->dpc_flags))
5889 qla82xx_watchdog(vha);
5890 else if (IS_QLA8044(ha))
5891 qla8044_watchdog(vha);
5894 if (!vha->vp_idx && IS_QLAFX00(ha))
5895 qlafx00_timer_routine(vha);
5897 /* Loop down handler. */
5898 if (atomic_read(&vha->loop_down_timer) > 0 &&
5899 !(test_bit(ABORT_ISP_ACTIVE, &vha->dpc_flags)) &&
5900 !(test_bit(FCOE_CTX_RESET_NEEDED, &vha->dpc_flags))
5901 && vha->flags.online) {
5903 if (atomic_read(&vha->loop_down_timer) ==
5904 vha->loop_down_abort_time) {
5906 ql_log(ql_log_info, vha, 0x6008,
5907 "Loop down - aborting the queues before time expires.\n");
5909 if (!IS_QLA2100(ha) && vha->link_down_timeout)
5910 atomic_set(&vha->loop_state, LOOP_DEAD);
5913 * Schedule an ISP abort to return any FCP2-device
5916 /* NPIV - scan physical port only */
5918 spin_lock_irqsave(&ha->hardware_lock,
5920 req = ha->req_q_map[0];
5922 index < req->num_outstanding_cmds;
5926 sp = req->outstanding_cmds[index];
5929 if (sp->cmd_type != TYPE_SRB)
5931 if (sp->type != SRB_SCSI_CMD)
5934 if (!(sfcp->flags & FCF_FCP2_DEVICE))
5938 set_bit(FCOE_CTX_RESET_NEEDED,
5941 set_bit(ISP_ABORT_NEEDED,
5945 spin_unlock_irqrestore(&ha->hardware_lock,
5951 /* if the loop has been down for 4 minutes, reinit adapter */
5952 if (atomic_dec_and_test(&vha->loop_down_timer) != 0) {
5953 if (!(vha->device_flags & DFLG_NO_CABLE)) {
5954 ql_log(ql_log_warn, vha, 0x6009,
5955 "Loop down - aborting ISP.\n");
5958 set_bit(FCOE_CTX_RESET_NEEDED,
5961 set_bit(ISP_ABORT_NEEDED,
5965 ql_dbg(ql_dbg_timer, vha, 0x600a,
5966 "Loop down - seconds remaining %d.\n",
5967 atomic_read(&vha->loop_down_timer));
5969 /* Check if beacon LED needs to be blinked for physical host only */
5970 if (!vha->vp_idx && (ha->beacon_blink_led == 1)) {
5971 /* There is no beacon_blink function for ISP82xx */
5972 if (!IS_P3P_TYPE(ha)) {
5973 set_bit(BEACON_BLINK_NEEDED, &vha->dpc_flags);
5978 /* Process any deferred work. */
5979 if (!list_empty(&vha->work_list))
5982 /* Schedule the DPC routine if needed */
5983 if ((test_bit(ISP_ABORT_NEEDED, &vha->dpc_flags) ||
5984 test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags) ||
5985 test_bit(FCPORT_UPDATE_NEEDED, &vha->dpc_flags) ||
5987 test_bit(RESET_MARKER_NEEDED, &vha->dpc_flags) ||
5988 test_bit(BEACON_BLINK_NEEDED, &vha->dpc_flags) ||
5989 test_bit(ISP_UNRECOVERABLE, &vha->dpc_flags) ||
5990 test_bit(FCOE_CTX_RESET_NEEDED, &vha->dpc_flags) ||
5991 test_bit(VP_DPC_NEEDED, &vha->dpc_flags) ||
5992 test_bit(RELOGIN_NEEDED, &vha->dpc_flags))) {
5993 ql_dbg(ql_dbg_timer, vha, 0x600b,
5994 "isp_abort_needed=%d loop_resync_needed=%d "
5995 "fcport_update_needed=%d start_dpc=%d "
5996 "reset_marker_needed=%d",
5997 test_bit(ISP_ABORT_NEEDED, &vha->dpc_flags),
5998 test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags),
5999 test_bit(FCPORT_UPDATE_NEEDED, &vha->dpc_flags),
6001 test_bit(RESET_MARKER_NEEDED, &vha->dpc_flags));
6002 ql_dbg(ql_dbg_timer, vha, 0x600c,
6003 "beacon_blink_needed=%d isp_unrecoverable=%d "
6004 "fcoe_ctx_reset_needed=%d vp_dpc_needed=%d "
6005 "relogin_needed=%d.\n",
6006 test_bit(BEACON_BLINK_NEEDED, &vha->dpc_flags),
6007 test_bit(ISP_UNRECOVERABLE, &vha->dpc_flags),
6008 test_bit(FCOE_CTX_RESET_NEEDED, &vha->dpc_flags),
6009 test_bit(VP_DPC_NEEDED, &vha->dpc_flags),
6010 test_bit(RELOGIN_NEEDED, &vha->dpc_flags));
6011 qla2xxx_wake_dpc(vha);
6014 qla2x00_restart_timer(vha, WATCH_INTERVAL);
6017 /* Firmware interface routines. */
6020 #define FW_ISP21XX 0
6021 #define FW_ISP22XX 1
6022 #define FW_ISP2300 2
6023 #define FW_ISP2322 3
6024 #define FW_ISP24XX 4
6025 #define FW_ISP25XX 5
6026 #define FW_ISP81XX 6
6027 #define FW_ISP82XX 7
6028 #define FW_ISP2031 8
6029 #define FW_ISP8031 9
6030 #define FW_ISP27XX 10
6032 #define FW_FILE_ISP21XX "ql2100_fw.bin"
6033 #define FW_FILE_ISP22XX "ql2200_fw.bin"
6034 #define FW_FILE_ISP2300 "ql2300_fw.bin"
6035 #define FW_FILE_ISP2322 "ql2322_fw.bin"
6036 #define FW_FILE_ISP24XX "ql2400_fw.bin"
6037 #define FW_FILE_ISP25XX "ql2500_fw.bin"
6038 #define FW_FILE_ISP81XX "ql8100_fw.bin"
6039 #define FW_FILE_ISP82XX "ql8200_fw.bin"
6040 #define FW_FILE_ISP2031 "ql2600_fw.bin"
6041 #define FW_FILE_ISP8031 "ql8300_fw.bin"
6042 #define FW_FILE_ISP27XX "ql2700_fw.bin"
6045 static DEFINE_MUTEX(qla_fw_lock);
6047 static struct fw_blob qla_fw_blobs[FW_BLOBS] = {
6048 { .name = FW_FILE_ISP21XX, .segs = { 0x1000, 0 }, },
6049 { .name = FW_FILE_ISP22XX, .segs = { 0x1000, 0 }, },
6050 { .name = FW_FILE_ISP2300, .segs = { 0x800, 0 }, },
6051 { .name = FW_FILE_ISP2322, .segs = { 0x800, 0x1c000, 0x1e000, 0 }, },
6052 { .name = FW_FILE_ISP24XX, },
6053 { .name = FW_FILE_ISP25XX, },
6054 { .name = FW_FILE_ISP81XX, },
6055 { .name = FW_FILE_ISP82XX, },
6056 { .name = FW_FILE_ISP2031, },
6057 { .name = FW_FILE_ISP8031, },
6058 { .name = FW_FILE_ISP27XX, },
6062 qla2x00_request_firmware(scsi_qla_host_t *vha)
6064 struct qla_hw_data *ha = vha->hw;
6065 struct fw_blob *blob;
6067 if (IS_QLA2100(ha)) {
6068 blob = &qla_fw_blobs[FW_ISP21XX];
6069 } else if (IS_QLA2200(ha)) {
6070 blob = &qla_fw_blobs[FW_ISP22XX];
6071 } else if (IS_QLA2300(ha) || IS_QLA2312(ha) || IS_QLA6312(ha)) {
6072 blob = &qla_fw_blobs[FW_ISP2300];
6073 } else if (IS_QLA2322(ha) || IS_QLA6322(ha)) {
6074 blob = &qla_fw_blobs[FW_ISP2322];
6075 } else if (IS_QLA24XX_TYPE(ha)) {
6076 blob = &qla_fw_blobs[FW_ISP24XX];
6077 } else if (IS_QLA25XX(ha)) {
6078 blob = &qla_fw_blobs[FW_ISP25XX];
6079 } else if (IS_QLA81XX(ha)) {
6080 blob = &qla_fw_blobs[FW_ISP81XX];
6081 } else if (IS_QLA82XX(ha)) {
6082 blob = &qla_fw_blobs[FW_ISP82XX];
6083 } else if (IS_QLA2031(ha)) {
6084 blob = &qla_fw_blobs[FW_ISP2031];
6085 } else if (IS_QLA8031(ha)) {
6086 blob = &qla_fw_blobs[FW_ISP8031];
6087 } else if (IS_QLA27XX(ha)) {
6088 blob = &qla_fw_blobs[FW_ISP27XX];
6093 mutex_lock(&qla_fw_lock);
6097 if (request_firmware(&blob->fw, blob->name, &ha->pdev->dev)) {
6098 ql_log(ql_log_warn, vha, 0x0063,
6099 "Failed to load firmware image (%s).\n", blob->name);
6106 mutex_unlock(&qla_fw_lock);
6111 qla2x00_release_firmware(void)
6115 mutex_lock(&qla_fw_lock);
6116 for (idx = 0; idx < FW_BLOBS; idx++)
6117 release_firmware(qla_fw_blobs[idx].fw);
6118 mutex_unlock(&qla_fw_lock);
6121 static pci_ers_result_t
6122 qla2xxx_pci_error_detected(struct pci_dev *pdev, pci_channel_state_t state)
6124 scsi_qla_host_t *vha = pci_get_drvdata(pdev);
6125 struct qla_hw_data *ha = vha->hw;
6127 ql_dbg(ql_dbg_aer, vha, 0x9000,
6128 "PCI error detected, state %x.\n", state);
6131 case pci_channel_io_normal:
6132 ha->flags.eeh_busy = 0;
6133 if (ql2xmqsupport) {
6134 set_bit(QPAIR_ONLINE_CHECK_NEEDED, &vha->dpc_flags);
6135 qla2xxx_wake_dpc(vha);
6137 return PCI_ERS_RESULT_CAN_RECOVER;
6138 case pci_channel_io_frozen:
6139 ha->flags.eeh_busy = 1;
6140 /* For ISP82XX complete any pending mailbox cmd */
6141 if (IS_QLA82XX(ha)) {
6142 ha->flags.isp82xx_fw_hung = 1;
6143 ql_dbg(ql_dbg_aer, vha, 0x9001, "Pci channel io frozen\n");
6144 qla82xx_clear_pending_mbx(vha);
6146 qla2x00_free_irqs(vha);
6147 pci_disable_device(pdev);
6148 /* Return back all IOs */
6149 qla2x00_abort_all_cmds(vha, DID_RESET << 16);
6150 if (ql2xmqsupport) {
6151 set_bit(QPAIR_ONLINE_CHECK_NEEDED, &vha->dpc_flags);
6152 qla2xxx_wake_dpc(vha);
6154 return PCI_ERS_RESULT_NEED_RESET;
6155 case pci_channel_io_perm_failure:
6156 ha->flags.pci_channel_io_perm_failure = 1;
6157 qla2x00_abort_all_cmds(vha, DID_NO_CONNECT << 16);
6158 if (ql2xmqsupport) {
6159 set_bit(QPAIR_ONLINE_CHECK_NEEDED, &vha->dpc_flags);
6160 qla2xxx_wake_dpc(vha);
6162 return PCI_ERS_RESULT_DISCONNECT;
6164 return PCI_ERS_RESULT_NEED_RESET;
6167 static pci_ers_result_t
6168 qla2xxx_pci_mmio_enabled(struct pci_dev *pdev)
6170 int risc_paused = 0;
6172 unsigned long flags;
6173 scsi_qla_host_t *base_vha = pci_get_drvdata(pdev);
6174 struct qla_hw_data *ha = base_vha->hw;
6175 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
6176 struct device_reg_24xx __iomem *reg24 = &ha->iobase->isp24;
6179 return PCI_ERS_RESULT_RECOVERED;
6181 spin_lock_irqsave(&ha->hardware_lock, flags);
6182 if (IS_QLA2100(ha) || IS_QLA2200(ha)){
6183 stat = RD_REG_DWORD(®->hccr);
6184 if (stat & HCCR_RISC_PAUSE)
6186 } else if (IS_QLA23XX(ha)) {
6187 stat = RD_REG_DWORD(®->u.isp2300.host_status);
6188 if (stat & HSR_RISC_PAUSED)
6190 } else if (IS_FWI2_CAPABLE(ha)) {
6191 stat = RD_REG_DWORD(®24->host_status);
6192 if (stat & HSRX_RISC_PAUSED)
6195 spin_unlock_irqrestore(&ha->hardware_lock, flags);
6198 ql_log(ql_log_info, base_vha, 0x9003,
6199 "RISC paused -- mmio_enabled, Dumping firmware.\n");
6200 ha->isp_ops->fw_dump(base_vha, 0);
6202 return PCI_ERS_RESULT_NEED_RESET;
6204 return PCI_ERS_RESULT_RECOVERED;
6208 qla82xx_error_recovery(scsi_qla_host_t *base_vha)
6210 uint32_t rval = QLA_FUNCTION_FAILED;
6211 uint32_t drv_active = 0;
6212 struct qla_hw_data *ha = base_vha->hw;
6214 struct pci_dev *other_pdev = NULL;
6216 ql_dbg(ql_dbg_aer, base_vha, 0x9006,
6217 "Entered %s.\n", __func__);
6219 set_bit(ABORT_ISP_ACTIVE, &base_vha->dpc_flags);
6221 if (base_vha->flags.online) {
6222 /* Abort all outstanding commands,
6223 * so as to be requeued later */
6224 qla2x00_abort_isp_cleanup(base_vha);
6228 fn = PCI_FUNC(ha->pdev->devfn);
6231 ql_dbg(ql_dbg_aer, base_vha, 0x9007,
6232 "Finding pci device at function = 0x%x.\n", fn);
6234 pci_get_domain_bus_and_slot(pci_domain_nr(ha->pdev->bus),
6235 ha->pdev->bus->number, PCI_DEVFN(PCI_SLOT(ha->pdev->devfn),
6240 if (atomic_read(&other_pdev->enable_cnt)) {
6241 ql_dbg(ql_dbg_aer, base_vha, 0x9008,
6242 "Found PCI func available and enable at 0x%x.\n",
6244 pci_dev_put(other_pdev);
6247 pci_dev_put(other_pdev);
6252 ql_dbg(ql_dbg_aer, base_vha, 0x9009,
6253 "This devfn is reset owner = 0x%x.\n",
6255 qla82xx_idc_lock(ha);
6257 qla82xx_wr_32(ha, QLA82XX_CRB_DEV_STATE,
6258 QLA8XXX_DEV_INITIALIZING);
6260 qla82xx_wr_32(ha, QLA82XX_CRB_DRV_IDC_VERSION,
6261 QLA82XX_IDC_VERSION);
6263 drv_active = qla82xx_rd_32(ha, QLA82XX_CRB_DRV_ACTIVE);
6264 ql_dbg(ql_dbg_aer, base_vha, 0x900a,
6265 "drv_active = 0x%x.\n", drv_active);
6267 qla82xx_idc_unlock(ha);
6268 /* Reset if device is not already reset
6269 * drv_active would be 0 if a reset has already been done
6272 rval = qla82xx_start_firmware(base_vha);
6275 qla82xx_idc_lock(ha);
6277 if (rval != QLA_SUCCESS) {
6278 ql_log(ql_log_info, base_vha, 0x900b,
6279 "HW State: FAILED.\n");
6280 qla82xx_clear_drv_active(ha);
6281 qla82xx_wr_32(ha, QLA82XX_CRB_DEV_STATE,
6282 QLA8XXX_DEV_FAILED);
6284 ql_log(ql_log_info, base_vha, 0x900c,
6285 "HW State: READY.\n");
6286 qla82xx_wr_32(ha, QLA82XX_CRB_DEV_STATE,
6288 qla82xx_idc_unlock(ha);
6289 ha->flags.isp82xx_fw_hung = 0;
6290 rval = qla82xx_restart_isp(base_vha);
6291 qla82xx_idc_lock(ha);
6292 /* Clear driver state register */
6293 qla82xx_wr_32(ha, QLA82XX_CRB_DRV_STATE, 0);
6294 qla82xx_set_drv_active(base_vha);
6296 qla82xx_idc_unlock(ha);
6298 ql_dbg(ql_dbg_aer, base_vha, 0x900d,
6299 "This devfn is not reset owner = 0x%x.\n",
6301 if ((qla82xx_rd_32(ha, QLA82XX_CRB_DEV_STATE) ==
6302 QLA8XXX_DEV_READY)) {
6303 ha->flags.isp82xx_fw_hung = 0;
6304 rval = qla82xx_restart_isp(base_vha);
6305 qla82xx_idc_lock(ha);
6306 qla82xx_set_drv_active(base_vha);
6307 qla82xx_idc_unlock(ha);
6310 clear_bit(ABORT_ISP_ACTIVE, &base_vha->dpc_flags);
6315 static pci_ers_result_t
6316 qla2xxx_pci_slot_reset(struct pci_dev *pdev)
6318 pci_ers_result_t ret = PCI_ERS_RESULT_DISCONNECT;
6319 scsi_qla_host_t *base_vha = pci_get_drvdata(pdev);
6320 struct qla_hw_data *ha = base_vha->hw;
6321 struct rsp_que *rsp;
6322 int rc, retries = 10;
6324 ql_dbg(ql_dbg_aer, base_vha, 0x9004,
6327 /* Workaround: qla2xxx driver which access hardware earlier
6328 * needs error state to be pci_channel_io_online.
6329 * Otherwise mailbox command timesout.
6331 pdev->error_state = pci_channel_io_normal;
6333 pci_restore_state(pdev);
6335 /* pci_restore_state() clears the saved_state flag of the device
6336 * save restored state which resets saved_state flag
6338 pci_save_state(pdev);
6341 rc = pci_enable_device_mem(pdev);
6343 rc = pci_enable_device(pdev);
6346 ql_log(ql_log_warn, base_vha, 0x9005,
6347 "Can't re-enable PCI device after reset.\n");
6348 goto exit_slot_reset;
6351 rsp = ha->rsp_q_map[0];
6352 if (qla2x00_request_irqs(ha, rsp))
6353 goto exit_slot_reset;
6355 if (ha->isp_ops->pci_config(base_vha))
6356 goto exit_slot_reset;
6358 if (IS_QLA82XX(ha)) {
6359 if (qla82xx_error_recovery(base_vha) == QLA_SUCCESS) {
6360 ret = PCI_ERS_RESULT_RECOVERED;
6361 goto exit_slot_reset;
6363 goto exit_slot_reset;
6366 while (ha->flags.mbox_busy && retries--)
6369 set_bit(ABORT_ISP_ACTIVE, &base_vha->dpc_flags);
6370 if (ha->isp_ops->abort_isp(base_vha) == QLA_SUCCESS)
6371 ret = PCI_ERS_RESULT_RECOVERED;
6372 clear_bit(ABORT_ISP_ACTIVE, &base_vha->dpc_flags);
6376 ql_dbg(ql_dbg_aer, base_vha, 0x900e,
6377 "slot_reset return %x.\n", ret);
6383 qla2xxx_pci_resume(struct pci_dev *pdev)
6385 scsi_qla_host_t *base_vha = pci_get_drvdata(pdev);
6386 struct qla_hw_data *ha = base_vha->hw;
6389 ql_dbg(ql_dbg_aer, base_vha, 0x900f,
6392 ret = qla2x00_wait_for_hba_online(base_vha);
6393 if (ret != QLA_SUCCESS) {
6394 ql_log(ql_log_fatal, base_vha, 0x9002,
6395 "The device failed to resume I/O from slot/link_reset.\n");
6398 pci_cleanup_aer_uncorrect_error_status(pdev);
6400 ha->flags.eeh_busy = 0;
6404 qla83xx_disable_laser(scsi_qla_host_t *vha)
6406 uint32_t reg, data, fn;
6407 struct qla_hw_data *ha = vha->hw;
6408 struct device_reg_24xx __iomem *isp_reg = &ha->iobase->isp24;
6410 /* pci func #/port # */
6411 ql_dbg(ql_dbg_init, vha, 0x004b,
6412 "Disabling Laser for hba: %p\n", vha);
6414 fn = (RD_REG_DWORD(&isp_reg->ctrl_status) &
6415 (BIT_15|BIT_14|BIT_13|BIT_12));
6424 data = LASER_OFF_2031;
6426 qla83xx_wr_reg(vha, reg, data);
6429 static int qla2xxx_map_queues(struct Scsi_Host *shost)
6431 scsi_qla_host_t *vha = (scsi_qla_host_t *)shost->hostdata;
6433 return blk_mq_pci_map_queues(&shost->tag_set, vha->hw->pdev);
6436 static const struct pci_error_handlers qla2xxx_err_handler = {
6437 .error_detected = qla2xxx_pci_error_detected,
6438 .mmio_enabled = qla2xxx_pci_mmio_enabled,
6439 .slot_reset = qla2xxx_pci_slot_reset,
6440 .resume = qla2xxx_pci_resume,
6443 static struct pci_device_id qla2xxx_pci_tbl[] = {
6444 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP2100) },
6445 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP2200) },
6446 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP2300) },
6447 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP2312) },
6448 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP2322) },
6449 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP6312) },
6450 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP6322) },
6451 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP2422) },
6452 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP2432) },
6453 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP8432) },
6454 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP5422) },
6455 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP5432) },
6456 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP2532) },
6457 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP2031) },
6458 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP8001) },
6459 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP8021) },
6460 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP8031) },
6461 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISPF001) },
6462 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP8044) },
6463 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP2071) },
6464 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP2271) },
6465 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP2261) },
6468 MODULE_DEVICE_TABLE(pci, qla2xxx_pci_tbl);
6470 static struct pci_driver qla2xxx_pci_driver = {
6471 .name = QLA2XXX_DRIVER_NAME,
6473 .owner = THIS_MODULE,
6475 .id_table = qla2xxx_pci_tbl,
6476 .probe = qla2x00_probe_one,
6477 .remove = qla2x00_remove_one,
6478 .shutdown = qla2x00_shutdown,
6479 .err_handler = &qla2xxx_err_handler,
6482 static const struct file_operations apidev_fops = {
6483 .owner = THIS_MODULE,
6484 .llseek = noop_llseek,
6488 * qla2x00_module_init - Module initialization.
6491 qla2x00_module_init(void)
6495 /* Allocate cache for SRBs. */
6496 srb_cachep = kmem_cache_create("qla2xxx_srbs", sizeof(srb_t), 0,
6497 SLAB_HWCACHE_ALIGN, NULL);
6498 if (srb_cachep == NULL) {
6499 ql_log(ql_log_fatal, NULL, 0x0001,
6500 "Unable to allocate SRB cache...Failing load!.\n");
6504 /* Initialize target kmem_cache and mem_pools */
6507 kmem_cache_destroy(srb_cachep);
6509 } else if (ret > 0) {
6511 * If initiator mode is explictly disabled by qlt_init(),
6512 * prevent scsi_transport_fc.c:fc_scsi_scan_rport() from
6513 * performing scsi_scan_target() during LOOP UP event.
6515 qla2xxx_transport_functions.disable_target_scan = 1;
6516 qla2xxx_transport_vport_functions.disable_target_scan = 1;
6519 /* Derive version string. */
6520 strcpy(qla2x00_version_str, QLA2XXX_VERSION);
6521 if (ql2xextended_error_logging)
6522 strcat(qla2x00_version_str, "-debug");
6524 qla2xxx_transport_template =
6525 fc_attach_transport(&qla2xxx_transport_functions);
6526 if (!qla2xxx_transport_template) {
6527 kmem_cache_destroy(srb_cachep);
6528 ql_log(ql_log_fatal, NULL, 0x0002,
6529 "fc_attach_transport failed...Failing load!.\n");
6534 apidev_major = register_chrdev(0, QLA2XXX_APIDEV, &apidev_fops);
6535 if (apidev_major < 0) {
6536 ql_log(ql_log_fatal, NULL, 0x0003,
6537 "Unable to register char device %s.\n", QLA2XXX_APIDEV);
6540 qla2xxx_transport_vport_template =
6541 fc_attach_transport(&qla2xxx_transport_vport_functions);
6542 if (!qla2xxx_transport_vport_template) {
6543 kmem_cache_destroy(srb_cachep);
6545 fc_release_transport(qla2xxx_transport_template);
6546 ql_log(ql_log_fatal, NULL, 0x0004,
6547 "fc_attach_transport vport failed...Failing load!.\n");
6550 ql_log(ql_log_info, NULL, 0x0005,
6551 "QLogic Fibre Channel HBA Driver: %s.\n",
6552 qla2x00_version_str);
6553 ret = pci_register_driver(&qla2xxx_pci_driver);
6555 kmem_cache_destroy(srb_cachep);
6557 fc_release_transport(qla2xxx_transport_template);
6558 fc_release_transport(qla2xxx_transport_vport_template);
6559 ql_log(ql_log_fatal, NULL, 0x0006,
6560 "pci_register_driver failed...ret=%d Failing load!.\n",
6567 * qla2x00_module_exit - Module cleanup.
6570 qla2x00_module_exit(void)
6572 unregister_chrdev(apidev_major, QLA2XXX_APIDEV);
6573 pci_unregister_driver(&qla2xxx_pci_driver);
6574 qla2x00_release_firmware();
6575 kmem_cache_destroy(srb_cachep);
6578 kmem_cache_destroy(ctx_cachep);
6579 fc_release_transport(qla2xxx_transport_template);
6580 fc_release_transport(qla2xxx_transport_vport_template);
6583 module_init(qla2x00_module_init);
6584 module_exit(qla2x00_module_exit);
6586 MODULE_AUTHOR("QLogic Corporation");
6587 MODULE_DESCRIPTION("QLogic Fibre Channel HBA Driver");
6588 MODULE_LICENSE("GPL");
6589 MODULE_VERSION(QLA2XXX_VERSION);
6590 MODULE_FIRMWARE(FW_FILE_ISP21XX);
6591 MODULE_FIRMWARE(FW_FILE_ISP22XX);
6592 MODULE_FIRMWARE(FW_FILE_ISP2300);
6593 MODULE_FIRMWARE(FW_FILE_ISP2322);
6594 MODULE_FIRMWARE(FW_FILE_ISP24XX);
6595 MODULE_FIRMWARE(FW_FILE_ISP25XX);