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 <scsi/scsi_tcq.h>
17 #include <scsi/scsicam.h>
18 #include <scsi/scsi_transport.h>
19 #include <scsi/scsi_transport_fc.h>
21 #include "qla_target.h"
26 char qla2x00_version_str[40];
28 static int apidev_major;
31 * SRB allocation cache
33 static struct kmem_cache *srb_cachep;
36 * CT6 CTX allocation cache
38 static struct kmem_cache *ctx_cachep;
40 * error level for logging
42 int ql_errlev = ql_log_all;
44 static int ql2xenableclass2;
45 module_param(ql2xenableclass2, int, S_IRUGO|S_IRUSR);
46 MODULE_PARM_DESC(ql2xenableclass2,
47 "Specify if Class 2 operations are supported from the very "
48 "beginning. Default is 0 - class 2 not supported.");
51 int ql2xlogintimeout = 20;
52 module_param(ql2xlogintimeout, int, S_IRUGO);
53 MODULE_PARM_DESC(ql2xlogintimeout,
54 "Login timeout value in seconds.");
56 int qlport_down_retry;
57 module_param(qlport_down_retry, int, S_IRUGO);
58 MODULE_PARM_DESC(qlport_down_retry,
59 "Maximum number of command retries to a port that returns "
60 "a PORT-DOWN status.");
62 int ql2xplogiabsentdevice;
63 module_param(ql2xplogiabsentdevice, int, S_IRUGO|S_IWUSR);
64 MODULE_PARM_DESC(ql2xplogiabsentdevice,
65 "Option to enable PLOGI to devices that are not present after "
66 "a Fabric scan. This is needed for several broken switches. "
67 "Default is 0 - no PLOGI. 1 - perfom PLOGI.");
69 int ql2xloginretrycount = 0;
70 module_param(ql2xloginretrycount, int, S_IRUGO);
71 MODULE_PARM_DESC(ql2xloginretrycount,
72 "Specify an alternate value for the NVRAM login retry count.");
74 int ql2xallocfwdump = 1;
75 module_param(ql2xallocfwdump, int, S_IRUGO);
76 MODULE_PARM_DESC(ql2xallocfwdump,
77 "Option to enable allocation of memory for a firmware dump "
78 "during HBA initialization. Memory allocation requirements "
79 "vary by ISP type. Default is 1 - allocate memory.");
81 int ql2xextended_error_logging;
82 module_param(ql2xextended_error_logging, int, S_IRUGO|S_IWUSR);
83 module_param_named(logging, ql2xextended_error_logging, int, S_IRUGO|S_IWUSR);
84 MODULE_PARM_DESC(ql2xextended_error_logging,
85 "Option to enable extended error logging,\n"
86 "\t\tDefault is 0 - no logging. 0x40000000 - Module Init & Probe.\n"
87 "\t\t0x20000000 - Mailbox Cmnds. 0x10000000 - Device Discovery.\n"
88 "\t\t0x08000000 - IO tracing. 0x04000000 - DPC Thread.\n"
89 "\t\t0x02000000 - Async events. 0x01000000 - Timer routines.\n"
90 "\t\t0x00800000 - User space. 0x00400000 - Task Management.\n"
91 "\t\t0x00200000 - AER/EEH. 0x00100000 - Multi Q.\n"
92 "\t\t0x00080000 - P3P Specific. 0x00040000 - Virtual Port.\n"
93 "\t\t0x00020000 - Buffer Dump. 0x00010000 - Misc.\n"
94 "\t\t0x00008000 - Verbose. 0x00004000 - Target.\n"
95 "\t\t0x00002000 - Target Mgmt. 0x00001000 - Target TMF.\n"
96 "\t\t0x7fffffff - For enabling all logs, can be too many logs.\n"
97 "\t\t0x1e400000 - Preferred value for capturing essential "
98 "debug information (equivalent to old "
99 "ql2xextended_error_logging=1).\n"
100 "\t\tDo LOGICAL OR of the value to enable more than one level");
102 int ql2xshiftctondsd = 6;
103 module_param(ql2xshiftctondsd, int, S_IRUGO);
104 MODULE_PARM_DESC(ql2xshiftctondsd,
105 "Set to control shifting of command type processing "
106 "based on total number of SG elements.");
108 int ql2xfdmienable=1;
109 module_param(ql2xfdmienable, int, S_IRUGO|S_IWUSR);
110 module_param_named(fdmi, ql2xfdmienable, int, S_IRUGO|S_IWUSR);
111 MODULE_PARM_DESC(ql2xfdmienable,
112 "Enables FDMI registrations. "
113 "0 - no FDMI. Default is 1 - perform FDMI.");
115 #define MAX_Q_DEPTH 32
116 static int ql2xmaxqdepth = MAX_Q_DEPTH;
117 module_param(ql2xmaxqdepth, int, S_IRUGO|S_IWUSR);
118 MODULE_PARM_DESC(ql2xmaxqdepth,
119 "Maximum queue depth to set for each LUN. "
122 int ql2xenabledif = 2;
123 module_param(ql2xenabledif, int, S_IRUGO);
124 MODULE_PARM_DESC(ql2xenabledif,
125 " Enable T10-CRC-DIF:\n"
127 " 0 -- No DIF Support\n"
128 " 1 -- Enable DIF for all types\n"
129 " 2 -- Enable DIF for all types, except Type 0.\n");
131 int ql2xenablehba_err_chk = 2;
132 module_param(ql2xenablehba_err_chk, int, S_IRUGO|S_IWUSR);
133 MODULE_PARM_DESC(ql2xenablehba_err_chk,
134 " Enable T10-CRC-DIF Error isolation by HBA:\n"
136 " 0 -- Error isolation disabled\n"
137 " 1 -- Error isolation enabled only for DIX Type 0\n"
138 " 2 -- Error isolation enabled for all Types\n");
140 int ql2xiidmaenable=1;
141 module_param(ql2xiidmaenable, int, S_IRUGO);
142 MODULE_PARM_DESC(ql2xiidmaenable,
143 "Enables iIDMA settings "
144 "Default is 1 - perform iIDMA. 0 - no iIDMA.");
146 int ql2xmaxqueues = 1;
147 module_param(ql2xmaxqueues, int, S_IRUGO);
148 MODULE_PARM_DESC(ql2xmaxqueues,
149 "Enables MQ settings "
150 "Default is 1 for single queue. Set it to number "
151 "of queues in MQ mode.");
153 int ql2xmultique_tag;
154 module_param(ql2xmultique_tag, int, S_IRUGO);
155 MODULE_PARM_DESC(ql2xmultique_tag,
156 "Enables CPU affinity settings for the driver "
157 "Default is 0 for no affinity of request and response IO. "
158 "Set it to 1 to turn on the cpu affinity.");
161 module_param(ql2xfwloadbin, int, S_IRUGO|S_IWUSR);
162 module_param_named(fwload, ql2xfwloadbin, int, S_IRUGO|S_IWUSR);
163 MODULE_PARM_DESC(ql2xfwloadbin,
164 "Option to specify location from which to load ISP firmware:.\n"
165 " 2 -- load firmware via the reject_firmware() (hotplug).\n"
167 " 1 -- load firmware from flash.\n"
168 " 0 -- use default semantics.\n");
171 module_param(ql2xetsenable, int, S_IRUGO);
172 MODULE_PARM_DESC(ql2xetsenable,
173 "Enables firmware ETS burst."
174 "Default is 0 - skip ETS enablement.");
177 module_param(ql2xdbwr, int, S_IRUGO|S_IWUSR);
178 MODULE_PARM_DESC(ql2xdbwr,
179 "Option to specify scheme for request queue posting.\n"
180 " 0 -- Regular doorbell.\n"
181 " 1 -- CAMRAM doorbell (faster).\n");
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 = 0;
228 module_param(ql2xexchoffld, uint, S_IRUGO|S_IWUSR);
229 MODULE_PARM_DESC(ql2xexchoffld,
230 "Number of exchanges to offload. "
231 "0 (Default)- Disabled.");
233 int ql2xfwholdabts = 0;
234 module_param(ql2xfwholdabts, int, S_IRUGO);
235 MODULE_PARM_DESC(ql2xfwholdabts,
236 "Allow FW to hold status IOCB until ABTS rsp received. "
237 "0 (Default) Do not set fw option. "
238 "1 - Set fw option to hold ABTS.");
241 * SCSI host template entry points
243 static int qla2xxx_slave_configure(struct scsi_device * device);
244 static int qla2xxx_slave_alloc(struct scsi_device *);
245 static int qla2xxx_scan_finished(struct Scsi_Host *, unsigned long time);
246 static void qla2xxx_scan_start(struct Scsi_Host *);
247 static void qla2xxx_slave_destroy(struct scsi_device *);
248 static int qla2xxx_queuecommand(struct Scsi_Host *h, struct scsi_cmnd *cmd);
249 static int qla2xxx_eh_abort(struct scsi_cmnd *);
250 static int qla2xxx_eh_device_reset(struct scsi_cmnd *);
251 static int qla2xxx_eh_target_reset(struct scsi_cmnd *);
252 static int qla2xxx_eh_bus_reset(struct scsi_cmnd *);
253 static int qla2xxx_eh_host_reset(struct scsi_cmnd *);
255 static void qla2x00_clear_drv_active(struct qla_hw_data *);
256 static void qla2x00_free_device(scsi_qla_host_t *);
257 static void qla83xx_disable_laser(scsi_qla_host_t *vha);
259 struct scsi_host_template qla2xxx_driver_template = {
260 .module = THIS_MODULE,
261 .name = QLA2XXX_DRIVER_NAME,
262 .queuecommand = qla2xxx_queuecommand,
264 .eh_abort_handler = qla2xxx_eh_abort,
265 .eh_device_reset_handler = qla2xxx_eh_device_reset,
266 .eh_target_reset_handler = qla2xxx_eh_target_reset,
267 .eh_bus_reset_handler = qla2xxx_eh_bus_reset,
268 .eh_host_reset_handler = qla2xxx_eh_host_reset,
270 .slave_configure = qla2xxx_slave_configure,
272 .slave_alloc = qla2xxx_slave_alloc,
273 .slave_destroy = qla2xxx_slave_destroy,
274 .scan_finished = qla2xxx_scan_finished,
275 .scan_start = qla2xxx_scan_start,
276 .change_queue_depth = scsi_change_queue_depth,
279 .use_clustering = ENABLE_CLUSTERING,
280 .sg_tablesize = SG_ALL,
282 .max_sectors = 0xFFFF,
283 .shost_attrs = qla2x00_host_attrs,
285 .supported_mode = MODE_INITIATOR,
286 .track_queue_depth = 1,
289 static struct scsi_transport_template *qla2xxx_transport_template = NULL;
290 struct scsi_transport_template *qla2xxx_transport_vport_template = NULL;
292 /* TODO Convert to inlines
298 qla2x00_start_timer(scsi_qla_host_t *vha, void *func, unsigned long interval)
300 init_timer(&vha->timer);
301 vha->timer.expires = jiffies + interval * HZ;
302 vha->timer.data = (unsigned long)vha;
303 vha->timer.function = (void (*)(unsigned long))func;
304 add_timer(&vha->timer);
305 vha->timer_active = 1;
309 qla2x00_restart_timer(scsi_qla_host_t *vha, unsigned long interval)
311 /* Currently used for 82XX only. */
312 if (vha->device_flags & DFLG_DEV_FAILED) {
313 ql_dbg(ql_dbg_timer, vha, 0x600d,
314 "Device in a failed state, returning.\n");
318 mod_timer(&vha->timer, jiffies + interval * HZ);
321 static __inline__ void
322 qla2x00_stop_timer(scsi_qla_host_t *vha)
324 del_timer_sync(&vha->timer);
325 vha->timer_active = 0;
328 static int qla2x00_do_dpc(void *data);
330 static void qla2x00_rst_aen(scsi_qla_host_t *);
332 static int qla2x00_mem_alloc(struct qla_hw_data *, uint16_t, uint16_t,
333 struct req_que **, struct rsp_que **);
334 static void qla2x00_free_fw_dump(struct qla_hw_data *);
335 static void qla2x00_mem_free(struct qla_hw_data *);
337 /* -------------------------------------------------------------------------- */
338 static int qla2x00_alloc_queues(struct qla_hw_data *ha, struct req_que *req,
341 scsi_qla_host_t *vha = pci_get_drvdata(ha->pdev);
342 ha->req_q_map = kzalloc(sizeof(struct req_que *) * ha->max_req_queues,
344 if (!ha->req_q_map) {
345 ql_log(ql_log_fatal, vha, 0x003b,
346 "Unable to allocate memory for request queue ptrs.\n");
350 ha->rsp_q_map = kzalloc(sizeof(struct rsp_que *) * ha->max_rsp_queues,
352 if (!ha->rsp_q_map) {
353 ql_log(ql_log_fatal, vha, 0x003c,
354 "Unable to allocate memory for response queue ptrs.\n");
358 * Make sure we record at least the request and response queue zero in
359 * case we need to free them if part of the probe fails.
361 ha->rsp_q_map[0] = rsp;
362 ha->req_q_map[0] = req;
363 set_bit(0, ha->rsp_qid_map);
364 set_bit(0, ha->req_qid_map);
368 kfree(ha->req_q_map);
369 ha->req_q_map = NULL;
374 static void qla2x00_free_req_que(struct qla_hw_data *ha, struct req_que *req)
376 if (IS_QLAFX00(ha)) {
377 if (req && req->ring_fx00)
378 dma_free_coherent(&ha->pdev->dev,
379 (req->length_fx00 + 1) * sizeof(request_t),
380 req->ring_fx00, req->dma_fx00);
381 } else if (req && req->ring)
382 dma_free_coherent(&ha->pdev->dev,
383 (req->length + 1) * sizeof(request_t),
384 req->ring, req->dma);
387 kfree(req->outstanding_cmds);
393 static void qla2x00_free_rsp_que(struct qla_hw_data *ha, struct rsp_que *rsp)
395 if (IS_QLAFX00(ha)) {
396 if (rsp && rsp->ring)
397 dma_free_coherent(&ha->pdev->dev,
398 (rsp->length_fx00 + 1) * sizeof(request_t),
399 rsp->ring_fx00, rsp->dma_fx00);
400 } else if (rsp && rsp->ring) {
401 dma_free_coherent(&ha->pdev->dev,
402 (rsp->length + 1) * sizeof(response_t),
403 rsp->ring, rsp->dma);
409 static void qla2x00_free_queues(struct qla_hw_data *ha)
415 for (cnt = 0; cnt < ha->max_req_queues; cnt++) {
416 if (!test_bit(cnt, ha->req_qid_map))
419 req = ha->req_q_map[cnt];
420 qla2x00_free_req_que(ha, req);
422 kfree(ha->req_q_map);
423 ha->req_q_map = NULL;
425 for (cnt = 0; cnt < ha->max_rsp_queues; cnt++) {
426 if (!test_bit(cnt, ha->rsp_qid_map))
429 rsp = ha->rsp_q_map[cnt];
430 qla2x00_free_rsp_que(ha, rsp);
432 kfree(ha->rsp_q_map);
433 ha->rsp_q_map = NULL;
436 static int qla25xx_setup_mode(struct scsi_qla_host *vha)
438 uint16_t options = 0;
440 struct qla_hw_data *ha = vha->hw;
442 if (!(ha->fw_attributes & BIT_6)) {
443 ql_log(ql_log_warn, vha, 0x00d8,
444 "Firmware is not multi-queue capable.\n");
447 if (ql2xmultique_tag) {
448 ha->wq = alloc_workqueue("qla2xxx_wq", WQ_MEM_RECLAIM, 1);
449 if (unlikely(!ha->wq)) {
450 ql_log(ql_log_warn, vha, 0x01e0,
451 "Failed to alloc workqueue.\n");
454 /* create a request queue for IO */
456 req = qla25xx_create_req_que(ha, options, 0, 0, -1,
457 QLA_DEFAULT_QUE_QOS);
459 ql_log(ql_log_warn, vha, 0x00e0,
460 "Failed to create request queue.\n");
463 vha->req = ha->req_q_map[req];
465 for (ques = 1; ques < ha->max_rsp_queues; ques++) {
466 ret = qla25xx_create_rsp_que(ha, options, 0, 0, req);
468 ql_log(ql_log_warn, vha, 0x00e8,
469 "Failed to create response queue.\n");
473 ha->flags.cpu_affinity_enabled = 1;
474 ql_dbg(ql_dbg_multiq, vha, 0xc007,
475 "CPU affinity mode enabled, "
476 "no. of response queues:%d no. of request queues:%d.\n",
477 ha->max_rsp_queues, ha->max_req_queues);
478 ql_dbg(ql_dbg_init, vha, 0x00e9,
479 "CPU affinity mode enabled, "
480 "no. of response queues:%d no. of request queues:%d.\n",
481 ha->max_rsp_queues, ha->max_req_queues);
486 qla25xx_delete_queues(vha);
487 vha->req = ha->req_q_map[0];
489 destroy_workqueue(ha->wq);
493 kfree(ha->req_q_map);
494 kfree(ha->rsp_q_map);
495 ha->max_req_queues = ha->max_rsp_queues = 1;
500 qla2x00_pci_info_str(struct scsi_qla_host *vha, char *str)
502 struct qla_hw_data *ha = vha->hw;
503 static char *pci_bus_modes[] = {
504 "33", "66", "100", "133",
509 pci_bus = (ha->pci_attr & (BIT_9 | BIT_10)) >> 9;
512 strcat(str, pci_bus_modes[pci_bus]);
514 pci_bus = (ha->pci_attr & BIT_8) >> 8;
516 strcat(str, pci_bus_modes[pci_bus]);
518 strcat(str, " MHz)");
524 qla24xx_pci_info_str(struct scsi_qla_host *vha, char *str)
526 static char *pci_bus_modes[] = { "33", "66", "100", "133", };
527 struct qla_hw_data *ha = vha->hw;
530 if (pci_is_pcie(ha->pdev)) {
532 uint32_t lstat, lspeed, lwidth;
534 pcie_capability_read_dword(ha->pdev, PCI_EXP_LNKCAP, &lstat);
535 lspeed = lstat & PCI_EXP_LNKCAP_SLS;
536 lwidth = (lstat & PCI_EXP_LNKCAP_MLW) >> 4;
538 strcpy(str, "PCIe (");
541 strcat(str, "2.5GT/s ");
544 strcat(str, "5.0GT/s ");
547 strcat(str, "8.0GT/s ");
550 strcat(str, "<unknown> ");
553 snprintf(lwstr, sizeof(lwstr), "x%d)", lwidth);
560 pci_bus = (ha->pci_attr & CSRX_PCIX_BUS_MODE_MASK) >> 8;
561 if (pci_bus == 0 || pci_bus == 8) {
563 strcat(str, pci_bus_modes[pci_bus >> 3]);
567 strcat(str, "Mode 2");
569 strcat(str, "Mode 1");
571 strcat(str, pci_bus_modes[pci_bus & ~BIT_2]);
573 strcat(str, " MHz)");
579 qla2x00_fw_version_str(struct scsi_qla_host *vha, char *str, size_t size)
582 struct qla_hw_data *ha = vha->hw;
584 snprintf(str, size, "%d.%02d.%02d ", ha->fw_major_version,
585 ha->fw_minor_version, ha->fw_subminor_version);
587 if (ha->fw_attributes & BIT_9) {
592 switch (ha->fw_attributes & 0xFF) {
606 sprintf(un_str, "(%x)", ha->fw_attributes);
610 if (ha->fw_attributes & 0x100)
617 qla24xx_fw_version_str(struct scsi_qla_host *vha, char *str, size_t size)
619 struct qla_hw_data *ha = vha->hw;
621 snprintf(str, size, "%d.%02d.%02d (%x)", ha->fw_major_version,
622 ha->fw_minor_version, ha->fw_subminor_version, ha->fw_attributes);
627 qla2x00_sp_free_dma(void *vha, void *ptr)
629 srb_t *sp = (srb_t *)ptr;
630 struct scsi_cmnd *cmd = GET_CMD_SP(sp);
631 struct qla_hw_data *ha = sp->fcport->vha->hw;
632 void *ctx = GET_CMD_CTX_SP(sp);
634 if (sp->flags & SRB_DMA_VALID) {
636 sp->flags &= ~SRB_DMA_VALID;
639 if (sp->flags & SRB_CRC_PROT_DMA_VALID) {
640 dma_unmap_sg(&ha->pdev->dev, scsi_prot_sglist(cmd),
641 scsi_prot_sg_count(cmd), cmd->sc_data_direction);
642 sp->flags &= ~SRB_CRC_PROT_DMA_VALID;
645 if (sp->flags & SRB_CRC_CTX_DSD_VALID) {
646 /* List assured to be having elements */
647 qla2x00_clean_dsd_pool(ha, sp, NULL);
648 sp->flags &= ~SRB_CRC_CTX_DSD_VALID;
651 if (sp->flags & SRB_CRC_CTX_DMA_VALID) {
652 dma_pool_free(ha->dl_dma_pool, ctx,
653 ((struct crc_context *)ctx)->crc_ctx_dma);
654 sp->flags &= ~SRB_CRC_CTX_DMA_VALID;
657 if (sp->flags & SRB_FCP_CMND_DMA_VALID) {
658 struct ct6_dsd *ctx1 = (struct ct6_dsd *)ctx;
660 dma_pool_free(ha->fcp_cmnd_dma_pool, ctx1->fcp_cmnd,
662 list_splice(&ctx1->dsd_list, &ha->gbl_dsd_list);
663 ha->gbl_dsd_inuse -= ctx1->dsd_use_cnt;
664 ha->gbl_dsd_avail += ctx1->dsd_use_cnt;
665 mempool_free(ctx1, ha->ctx_mempool);
670 qla2x00_rel_sp(sp->fcport->vha, sp);
674 qla2x00_sp_compl(void *data, void *ptr, int res)
676 struct qla_hw_data *ha = (struct qla_hw_data *)data;
677 srb_t *sp = (srb_t *)ptr;
678 struct scsi_cmnd *cmd = GET_CMD_SP(sp);
682 if (atomic_read(&sp->ref_count) == 0) {
683 ql_dbg(ql_dbg_io, sp->fcport->vha, 0x3015,
684 "SP reference-count to ZERO -- sp=%p cmd=%p.\n",
686 if (ql2xextended_error_logging & ql_dbg_io)
687 WARN_ON(atomic_read(&sp->ref_count) == 0);
690 if (!atomic_dec_and_test(&sp->ref_count))
693 qla2x00_sp_free_dma(ha, sp);
697 /* If we are SP1 here, we need to still take and release the host_lock as SP1
698 * does not have the changes necessary to avoid taking host->host_lock.
701 qla2xxx_queuecommand(struct Scsi_Host *host, struct scsi_cmnd *cmd)
703 scsi_qla_host_t *vha = shost_priv(host);
704 fc_port_t *fcport = (struct fc_port *) cmd->device->hostdata;
705 struct fc_rport *rport = starget_to_rport(scsi_target(cmd->device));
706 struct qla_hw_data *ha = vha->hw;
707 struct scsi_qla_host *base_vha = pci_get_drvdata(ha->pdev);
711 if (unlikely(test_bit(UNLOADING, &base_vha->dpc_flags))) {
712 cmd->result = DID_NO_CONNECT << 16;
713 goto qc24_fail_command;
716 if (ha->flags.eeh_busy) {
717 if (ha->flags.pci_channel_io_perm_failure) {
718 ql_dbg(ql_dbg_aer, vha, 0x9010,
719 "PCI Channel IO permanent failure, exiting "
721 cmd->result = DID_NO_CONNECT << 16;
723 ql_dbg(ql_dbg_aer, vha, 0x9011,
724 "EEH_Busy, Requeuing the cmd=%p.\n", cmd);
725 cmd->result = DID_REQUEUE << 16;
727 goto qc24_fail_command;
730 rval = fc_remote_port_chkready(rport);
733 ql_dbg(ql_dbg_io + ql_dbg_verbose, vha, 0x3003,
734 "fc_remote_port_chkready failed for cmd=%p, rval=0x%x.\n",
736 goto qc24_fail_command;
739 if (!vha->flags.difdix_supported &&
740 scsi_get_prot_op(cmd) != SCSI_PROT_NORMAL) {
741 ql_dbg(ql_dbg_io, vha, 0x3004,
742 "DIF Cap not reg, fail DIF capable cmd's:%p.\n",
744 cmd->result = DID_NO_CONNECT << 16;
745 goto qc24_fail_command;
749 cmd->result = DID_NO_CONNECT << 16;
750 goto qc24_fail_command;
753 if (atomic_read(&fcport->state) != FCS_ONLINE) {
754 if (atomic_read(&fcport->state) == FCS_DEVICE_DEAD ||
755 atomic_read(&base_vha->loop_state) == LOOP_DEAD) {
756 ql_dbg(ql_dbg_io, vha, 0x3005,
757 "Returning DNC, fcport_state=%d loop_state=%d.\n",
758 atomic_read(&fcport->state),
759 atomic_read(&base_vha->loop_state));
760 cmd->result = DID_NO_CONNECT << 16;
761 goto qc24_fail_command;
763 goto qc24_target_busy;
767 * Return target busy if we've received a non-zero retry_delay_timer
770 if (fcport->retry_delay_timestamp == 0) {
771 /* retry delay not set */
772 } else if (time_after(jiffies, fcport->retry_delay_timestamp))
773 fcport->retry_delay_timestamp = 0;
775 goto qc24_target_busy;
777 sp = qla2x00_get_sp(vha, fcport, GFP_ATOMIC);
781 sp->u.scmd.cmd = cmd;
782 sp->type = SRB_SCSI_CMD;
783 atomic_set(&sp->ref_count, 1);
784 CMD_SP(cmd) = (void *)sp;
785 sp->free = qla2x00_sp_free_dma;
786 sp->done = qla2x00_sp_compl;
788 rval = ha->isp_ops->start_scsi(sp);
789 if (rval != QLA_SUCCESS) {
790 ql_dbg(ql_dbg_io + ql_dbg_verbose, vha, 0x3013,
791 "Start scsi failed rval=%d for cmd=%p.\n", rval, cmd);
792 goto qc24_host_busy_free_sp;
797 qc24_host_busy_free_sp:
798 qla2x00_sp_free_dma(ha, sp);
801 return SCSI_MLQUEUE_HOST_BUSY;
804 return SCSI_MLQUEUE_TARGET_BUSY;
813 * qla2x00_eh_wait_on_command
814 * Waits for the command to be returned by the Firmware for some
818 * cmd = Scsi Command to wait on.
825 qla2x00_eh_wait_on_command(struct scsi_cmnd *cmd)
827 #define ABORT_POLLING_PERIOD 1000
828 #define ABORT_WAIT_ITER ((2 * 1000) / (ABORT_POLLING_PERIOD))
829 unsigned long wait_iter = ABORT_WAIT_ITER;
830 scsi_qla_host_t *vha = shost_priv(cmd->device->host);
831 struct qla_hw_data *ha = vha->hw;
832 int ret = QLA_SUCCESS;
834 if (unlikely(pci_channel_offline(ha->pdev)) || ha->flags.eeh_busy) {
835 ql_dbg(ql_dbg_taskm, vha, 0x8005,
836 "Return:eh_wait.\n");
840 while (CMD_SP(cmd) && wait_iter--) {
841 msleep(ABORT_POLLING_PERIOD);
844 ret = QLA_FUNCTION_FAILED;
850 * qla2x00_wait_for_hba_online
851 * Wait till the HBA is online after going through
852 * <= MAX_RETRIES_OF_ISP_ABORT or
853 * finally HBA is disabled ie marked offline
856 * ha - pointer to host adapter structure
859 * Does context switching-Release SPIN_LOCK
860 * (if any) before calling this routine.
863 * Success (Adapter is online) : 0
864 * Failed (Adapter is offline/disabled) : 1
867 qla2x00_wait_for_hba_online(scsi_qla_host_t *vha)
870 unsigned long wait_online;
871 struct qla_hw_data *ha = vha->hw;
872 scsi_qla_host_t *base_vha = pci_get_drvdata(ha->pdev);
874 wait_online = jiffies + (MAX_LOOP_TIMEOUT * HZ);
875 while (((test_bit(ISP_ABORT_NEEDED, &base_vha->dpc_flags)) ||
876 test_bit(ABORT_ISP_ACTIVE, &base_vha->dpc_flags) ||
877 test_bit(ISP_ABORT_RETRY, &base_vha->dpc_flags) ||
878 ha->dpc_active) && time_before(jiffies, wait_online)) {
882 if (base_vha->flags.online)
883 return_status = QLA_SUCCESS;
885 return_status = QLA_FUNCTION_FAILED;
887 return (return_status);
891 * qla2x00_wait_for_hba_ready
892 * Wait till the HBA is ready before doing driver unload
895 * ha - pointer to host adapter structure
898 * Does context switching-Release SPIN_LOCK
899 * (if any) before calling this routine.
903 qla2x00_wait_for_hba_ready(scsi_qla_host_t *vha)
905 struct qla_hw_data *ha = vha->hw;
906 scsi_qla_host_t *base_vha = pci_get_drvdata(ha->pdev);
908 while ((qla2x00_reset_active(vha) || ha->dpc_active ||
909 ha->flags.mbox_busy) ||
910 test_bit(FX00_RESET_RECOVERY, &vha->dpc_flags) ||
911 test_bit(FX00_TARGET_SCAN, &vha->dpc_flags)) {
912 if (test_bit(UNLOADING, &base_vha->dpc_flags))
919 qla2x00_wait_for_chip_reset(scsi_qla_host_t *vha)
922 unsigned long wait_reset;
923 struct qla_hw_data *ha = vha->hw;
924 scsi_qla_host_t *base_vha = pci_get_drvdata(ha->pdev);
926 wait_reset = jiffies + (MAX_LOOP_TIMEOUT * HZ);
927 while (((test_bit(ISP_ABORT_NEEDED, &base_vha->dpc_flags)) ||
928 test_bit(ABORT_ISP_ACTIVE, &base_vha->dpc_flags) ||
929 test_bit(ISP_ABORT_RETRY, &base_vha->dpc_flags) ||
930 ha->dpc_active) && time_before(jiffies, wait_reset)) {
934 if (!test_bit(ISP_ABORT_NEEDED, &base_vha->dpc_flags) &&
935 ha->flags.chip_reset_done)
938 if (ha->flags.chip_reset_done)
939 return_status = QLA_SUCCESS;
941 return_status = QLA_FUNCTION_FAILED;
943 return return_status;
947 sp_get(struct srb *sp)
949 atomic_inc(&sp->ref_count);
952 #define ISP_REG_DISCONNECT 0xffffffffU
953 /**************************************************************************
954 * qla2x00_isp_reg_stat
957 * Read the host status register of ISP before aborting the command.
960 * ha = pointer to host adapter structure.
964 * Either true or false.
966 * Note: Return true if there is register disconnect.
967 **************************************************************************/
969 uint32_t qla2x00_isp_reg_stat(struct qla_hw_data *ha)
971 struct device_reg_24xx __iomem *reg = &ha->iobase->isp24;
972 struct device_reg_82xx __iomem *reg82 = &ha->iobase->isp82;
975 return ((RD_REG_DWORD(®82->host_int)) == ISP_REG_DISCONNECT);
977 return ((RD_REG_DWORD(®->host_status)) ==
981 /**************************************************************************
985 * The abort function will abort the specified command.
988 * cmd = Linux SCSI command packet to be aborted.
991 * Either SUCCESS or FAILED.
994 * Only return FAILED if command not returned by firmware.
995 **************************************************************************/
997 qla2xxx_eh_abort(struct scsi_cmnd *cmd)
999 scsi_qla_host_t *vha = shost_priv(cmd->device->host);
1004 unsigned long flags;
1006 struct qla_hw_data *ha = vha->hw;
1008 if (qla2x00_isp_reg_stat(ha)) {
1009 ql_log(ql_log_info, vha, 0x8042,
1010 "PCI/Register disconnect, exiting.\n");
1016 ret = fc_block_scsi_eh(cmd);
1021 id = cmd->device->id;
1022 lun = cmd->device->lun;
1024 spin_lock_irqsave(&ha->hardware_lock, flags);
1025 sp = (srb_t *) CMD_SP(cmd);
1027 spin_unlock_irqrestore(&ha->hardware_lock, flags);
1031 ql_dbg(ql_dbg_taskm, vha, 0x8002,
1032 "Aborting from RISC nexus=%ld:%d:%llu sp=%p cmd=%p handle=%x\n",
1033 vha->host_no, id, lun, sp, cmd, sp->handle);
1035 /* Get a reference to the sp and drop the lock.*/
1038 spin_unlock_irqrestore(&ha->hardware_lock, flags);
1039 rval = ha->isp_ops->abort_command(sp);
1041 if (rval == QLA_FUNCTION_PARAMETER_ERROR)
1046 ql_dbg(ql_dbg_taskm, vha, 0x8003,
1047 "Abort command mbx failed cmd=%p, rval=%x.\n", cmd, rval);
1049 ql_dbg(ql_dbg_taskm, vha, 0x8004,
1050 "Abort command mbx success cmd=%p.\n", cmd);
1054 spin_lock_irqsave(&ha->hardware_lock, flags);
1055 sp->done(ha, sp, 0);
1056 spin_unlock_irqrestore(&ha->hardware_lock, flags);
1058 /* Did the command return during mailbox execution? */
1059 if (ret == FAILED && !CMD_SP(cmd))
1062 /* Wait for the command to be returned. */
1064 if (qla2x00_eh_wait_on_command(cmd) != QLA_SUCCESS) {
1065 ql_log(ql_log_warn, vha, 0x8006,
1066 "Abort handler timed out cmd=%p.\n", cmd);
1071 ql_log(ql_log_info, vha, 0x801c,
1072 "Abort command issued nexus=%ld:%d:%llu -- %d %x.\n",
1073 vha->host_no, id, lun, wait, ret);
1079 qla2x00_eh_wait_for_pending_commands(scsi_qla_host_t *vha, unsigned int t,
1080 uint64_t l, enum nexus_wait_type type)
1082 int cnt, match, status;
1083 unsigned long flags;
1084 struct qla_hw_data *ha = vha->hw;
1085 struct req_que *req;
1087 struct scsi_cmnd *cmd;
1089 status = QLA_SUCCESS;
1091 spin_lock_irqsave(&ha->hardware_lock, flags);
1093 for (cnt = 1; status == QLA_SUCCESS &&
1094 cnt < req->num_outstanding_cmds; cnt++) {
1095 sp = req->outstanding_cmds[cnt];
1098 if (sp->type != SRB_SCSI_CMD)
1100 if (vha->vp_idx != sp->fcport->vha->vp_idx)
1103 cmd = GET_CMD_SP(sp);
1109 match = cmd->device->id == t;
1112 match = (cmd->device->id == t &&
1113 cmd->device->lun == l);
1119 spin_unlock_irqrestore(&ha->hardware_lock, flags);
1120 status = qla2x00_eh_wait_on_command(cmd);
1121 spin_lock_irqsave(&ha->hardware_lock, flags);
1123 spin_unlock_irqrestore(&ha->hardware_lock, flags);
1128 static char *reset_errors[] = {
1131 "Task management failed",
1132 "Waiting for command completions",
1136 __qla2xxx_eh_generic_reset(char *name, enum nexus_wait_type type,
1137 struct scsi_cmnd *cmd, int (*do_reset)(struct fc_port *, uint64_t, int))
1139 scsi_qla_host_t *vha = shost_priv(cmd->device->host);
1140 fc_port_t *fcport = (struct fc_port *) cmd->device->hostdata;
1147 err = fc_block_scsi_eh(cmd);
1151 ql_log(ql_log_info, vha, 0x8009,
1152 "%s RESET ISSUED nexus=%ld:%d:%llu cmd=%p.\n", name, vha->host_no,
1153 cmd->device->id, cmd->device->lun, cmd);
1156 if (qla2x00_wait_for_hba_online(vha) != QLA_SUCCESS) {
1157 ql_log(ql_log_warn, vha, 0x800a,
1158 "Wait for hba online failed for cmd=%p.\n", cmd);
1159 goto eh_reset_failed;
1162 if (do_reset(fcport, cmd->device->lun, cmd->request->cpu + 1)
1164 ql_log(ql_log_warn, vha, 0x800c,
1165 "do_reset failed for cmd=%p.\n", cmd);
1166 goto eh_reset_failed;
1169 if (qla2x00_eh_wait_for_pending_commands(vha, cmd->device->id,
1170 cmd->device->lun, type) != QLA_SUCCESS) {
1171 ql_log(ql_log_warn, vha, 0x800d,
1172 "wait for pending cmds failed for cmd=%p.\n", cmd);
1173 goto eh_reset_failed;
1176 ql_log(ql_log_info, vha, 0x800e,
1177 "%s RESET SUCCEEDED nexus:%ld:%d:%llu cmd=%p.\n", name,
1178 vha->host_no, cmd->device->id, cmd->device->lun, cmd);
1183 ql_log(ql_log_info, vha, 0x800f,
1184 "%s RESET FAILED: %s nexus=%ld:%d:%llu cmd=%p.\n", name,
1185 reset_errors[err], vha->host_no, cmd->device->id, cmd->device->lun,
1191 qla2xxx_eh_device_reset(struct scsi_cmnd *cmd)
1193 scsi_qla_host_t *vha = shost_priv(cmd->device->host);
1194 struct qla_hw_data *ha = vha->hw;
1196 if (qla2x00_isp_reg_stat(ha)) {
1197 ql_log(ql_log_info, vha, 0x803e,
1198 "PCI/Register disconnect, exiting.\n");
1202 return __qla2xxx_eh_generic_reset("DEVICE", WAIT_LUN, cmd,
1203 ha->isp_ops->lun_reset);
1207 qla2xxx_eh_target_reset(struct scsi_cmnd *cmd)
1209 scsi_qla_host_t *vha = shost_priv(cmd->device->host);
1210 struct qla_hw_data *ha = vha->hw;
1212 if (qla2x00_isp_reg_stat(ha)) {
1213 ql_log(ql_log_info, vha, 0x803f,
1214 "PCI/Register disconnect, exiting.\n");
1218 return __qla2xxx_eh_generic_reset("TARGET", WAIT_TARGET, cmd,
1219 ha->isp_ops->target_reset);
1222 /**************************************************************************
1223 * qla2xxx_eh_bus_reset
1226 * The bus reset function will reset the bus and abort any executing
1230 * cmd = Linux SCSI command packet of the command that cause the
1234 * SUCCESS/FAILURE (defined as macro in scsi.h).
1236 **************************************************************************/
1238 qla2xxx_eh_bus_reset(struct scsi_cmnd *cmd)
1240 scsi_qla_host_t *vha = shost_priv(cmd->device->host);
1241 fc_port_t *fcport = (struct fc_port *) cmd->device->hostdata;
1245 struct qla_hw_data *ha = vha->hw;
1247 if (qla2x00_isp_reg_stat(ha)) {
1248 ql_log(ql_log_info, vha, 0x8040,
1249 "PCI/Register disconnect, exiting.\n");
1253 id = cmd->device->id;
1254 lun = cmd->device->lun;
1260 ret = fc_block_scsi_eh(cmd);
1265 ql_log(ql_log_info, vha, 0x8012,
1266 "BUS RESET ISSUED nexus=%ld:%d:%llu.\n", vha->host_no, id, lun);
1268 if (qla2x00_wait_for_hba_online(vha) != QLA_SUCCESS) {
1269 ql_log(ql_log_fatal, vha, 0x8013,
1270 "Wait for hba online failed board disabled.\n");
1271 goto eh_bus_reset_done;
1274 if (qla2x00_loop_reset(vha) == QLA_SUCCESS)
1278 goto eh_bus_reset_done;
1280 /* Flush outstanding commands. */
1281 if (qla2x00_eh_wait_for_pending_commands(vha, 0, 0, WAIT_HOST) !=
1283 ql_log(ql_log_warn, vha, 0x8014,
1284 "Wait for pending commands failed.\n");
1289 ql_log(ql_log_warn, vha, 0x802b,
1290 "BUS RESET %s nexus=%ld:%d:%llu.\n",
1291 (ret == FAILED) ? "FAILED" : "SUCCEEDED", vha->host_no, id, lun);
1296 /**************************************************************************
1297 * qla2xxx_eh_host_reset
1300 * The reset function will reset the Adapter.
1303 * cmd = Linux SCSI command packet of the command that cause the
1307 * Either SUCCESS or FAILED.
1310 **************************************************************************/
1312 qla2xxx_eh_host_reset(struct scsi_cmnd *cmd)
1314 scsi_qla_host_t *vha = shost_priv(cmd->device->host);
1315 struct qla_hw_data *ha = vha->hw;
1319 scsi_qla_host_t *base_vha = pci_get_drvdata(ha->pdev);
1321 if (qla2x00_isp_reg_stat(ha)) {
1322 ql_log(ql_log_info, vha, 0x8041,
1323 "PCI/Register disconnect, exiting.\n");
1324 schedule_work(&ha->board_disable);
1328 id = cmd->device->id;
1329 lun = cmd->device->lun;
1331 ql_log(ql_log_info, vha, 0x8018,
1332 "ADAPTER RESET ISSUED nexus=%ld:%d:%llu.\n", vha->host_no, id, lun);
1335 * No point in issuing another reset if one is active. Also do not
1336 * attempt a reset if we are updating flash.
1338 if (qla2x00_reset_active(vha) || ha->optrom_state != QLA_SWAITING)
1339 goto eh_host_reset_lock;
1341 if (vha != base_vha) {
1342 if (qla2x00_vp_abort_isp(vha))
1343 goto eh_host_reset_lock;
1345 if (IS_P3P_TYPE(vha->hw)) {
1346 if (!qla82xx_fcoe_ctx_reset(vha)) {
1347 /* Ctx reset success */
1349 goto eh_host_reset_lock;
1351 /* fall thru if ctx reset failed */
1354 flush_workqueue(ha->wq);
1356 set_bit(ABORT_ISP_ACTIVE, &base_vha->dpc_flags);
1357 if (ha->isp_ops->abort_isp(base_vha)) {
1358 clear_bit(ABORT_ISP_ACTIVE, &base_vha->dpc_flags);
1359 /* failed. schedule dpc to try */
1360 set_bit(ISP_ABORT_NEEDED, &base_vha->dpc_flags);
1362 if (qla2x00_wait_for_hba_online(vha) != QLA_SUCCESS) {
1363 ql_log(ql_log_warn, vha, 0x802a,
1364 "wait for hba online failed.\n");
1365 goto eh_host_reset_lock;
1368 clear_bit(ABORT_ISP_ACTIVE, &base_vha->dpc_flags);
1371 /* Waiting for command to be returned to OS.*/
1372 if (qla2x00_eh_wait_for_pending_commands(vha, 0, 0, WAIT_HOST) ==
1377 ql_log(ql_log_info, vha, 0x8017,
1378 "ADAPTER RESET %s nexus=%ld:%d:%llu.\n",
1379 (ret == FAILED) ? "FAILED" : "SUCCEEDED", vha->host_no, id, lun);
1385 * qla2x00_loop_reset
1389 * ha = adapter block pointer.
1395 qla2x00_loop_reset(scsi_qla_host_t *vha)
1398 struct qla_hw_data *ha = vha->hw;
1403 if (ha->flags.enable_lip_full_login && !IS_CNA_CAPABLE(ha)) {
1404 atomic_set(&vha->loop_state, LOOP_DOWN);
1405 atomic_set(&vha->loop_down_timer, LOOP_DOWN_TIME);
1406 qla2x00_mark_all_devices_lost(vha, 0);
1407 ret = qla2x00_full_login_lip(vha);
1408 if (ret != QLA_SUCCESS) {
1409 ql_dbg(ql_dbg_taskm, vha, 0x802d,
1410 "full_login_lip=%d.\n", ret);
1414 if (ha->flags.enable_lip_reset) {
1415 ret = qla2x00_lip_reset(vha);
1416 if (ret != QLA_SUCCESS)
1417 ql_dbg(ql_dbg_taskm, vha, 0x802e,
1418 "lip_reset failed (%d).\n", ret);
1421 /* Issue marker command only when we are going to start the I/O */
1422 vha->marker_needed = 1;
1428 qla2x00_abort_all_cmds(scsi_qla_host_t *vha, int res)
1430 int que, cnt, status;
1431 unsigned long flags;
1433 struct qla_hw_data *ha = vha->hw;
1434 struct req_que *req;
1436 qlt_host_reset_handler(ha);
1438 spin_lock_irqsave(&ha->hardware_lock, flags);
1439 for (que = 0; que < ha->max_req_queues; que++) {
1440 req = ha->req_q_map[que];
1443 if (!req->outstanding_cmds)
1445 for (cnt = 1; cnt < req->num_outstanding_cmds; cnt++) {
1446 sp = req->outstanding_cmds[cnt];
1448 /* Don't abort commands in adapter during EEH
1449 * recovery as it's not accessible/responding.
1451 if (GET_CMD_SP(sp) && !ha->flags.eeh_busy &&
1452 (sp->type == SRB_SCSI_CMD)) {
1453 /* Get a reference to the sp and drop the lock.
1454 * The reference ensures this sp->done() call
1455 * - and not the call in qla2xxx_eh_abort() -
1456 * ends the SCSI command (with result 'res').
1459 spin_unlock_irqrestore(&ha->hardware_lock, flags);
1460 status = qla2xxx_eh_abort(GET_CMD_SP(sp));
1461 spin_lock_irqsave(&ha->hardware_lock, flags);
1462 /* Get rid of extra reference if immediate exit
1463 * from ql2xxx_eh_abort */
1464 if (status == FAILED && (qla2x00_isp_reg_stat(ha)))
1465 atomic_dec(&sp->ref_count);
1467 req->outstanding_cmds[cnt] = NULL;
1468 sp->done(vha, sp, res);
1472 spin_unlock_irqrestore(&ha->hardware_lock, flags);
1476 qla2xxx_slave_alloc(struct scsi_device *sdev)
1478 struct fc_rport *rport = starget_to_rport(scsi_target(sdev));
1480 if (!rport || fc_remote_port_chkready(rport))
1483 sdev->hostdata = *(fc_port_t **)rport->dd_data;
1489 qla2xxx_slave_configure(struct scsi_device *sdev)
1491 scsi_qla_host_t *vha = shost_priv(sdev->host);
1492 struct req_que *req = vha->req;
1494 if (IS_T10_PI_CAPABLE(vha->hw))
1495 blk_queue_update_dma_alignment(sdev->request_queue, 0x7);
1497 scsi_change_queue_depth(sdev, req->max_q_depth);
1502 qla2xxx_slave_destroy(struct scsi_device *sdev)
1504 sdev->hostdata = NULL;
1508 * qla2x00_config_dma_addressing() - Configure OS DMA addressing method.
1511 * At exit, the @ha's flags.enable_64bit_addressing set to indicated
1512 * supported addressing method.
1515 qla2x00_config_dma_addressing(struct qla_hw_data *ha)
1517 /* Assume a 32bit DMA mask. */
1518 ha->flags.enable_64bit_addressing = 0;
1520 if (!dma_set_mask(&ha->pdev->dev, DMA_BIT_MASK(64))) {
1521 /* Any upper-dword bits set? */
1522 if (MSD(dma_get_required_mask(&ha->pdev->dev)) &&
1523 !pci_set_consistent_dma_mask(ha->pdev, DMA_BIT_MASK(64))) {
1524 /* Ok, a 64bit DMA mask is applicable. */
1525 ha->flags.enable_64bit_addressing = 1;
1526 ha->isp_ops->calc_req_entries = qla2x00_calc_iocbs_64;
1527 ha->isp_ops->build_iocbs = qla2x00_build_scsi_iocbs_64;
1532 dma_set_mask(&ha->pdev->dev, DMA_BIT_MASK(32));
1533 pci_set_consistent_dma_mask(ha->pdev, DMA_BIT_MASK(32));
1537 qla2x00_enable_intrs(struct qla_hw_data *ha)
1539 unsigned long flags = 0;
1540 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
1542 spin_lock_irqsave(&ha->hardware_lock, flags);
1543 ha->interrupts_on = 1;
1544 /* enable risc and host interrupts */
1545 WRT_REG_WORD(®->ictrl, ICR_EN_INT | ICR_EN_RISC);
1546 RD_REG_WORD(®->ictrl);
1547 spin_unlock_irqrestore(&ha->hardware_lock, flags);
1552 qla2x00_disable_intrs(struct qla_hw_data *ha)
1554 unsigned long flags = 0;
1555 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
1557 spin_lock_irqsave(&ha->hardware_lock, flags);
1558 ha->interrupts_on = 0;
1559 /* disable risc and host interrupts */
1560 WRT_REG_WORD(®->ictrl, 0);
1561 RD_REG_WORD(®->ictrl);
1562 spin_unlock_irqrestore(&ha->hardware_lock, flags);
1566 qla24xx_enable_intrs(struct qla_hw_data *ha)
1568 unsigned long flags = 0;
1569 struct device_reg_24xx __iomem *reg = &ha->iobase->isp24;
1571 spin_lock_irqsave(&ha->hardware_lock, flags);
1572 ha->interrupts_on = 1;
1573 WRT_REG_DWORD(®->ictrl, ICRX_EN_RISC_INT);
1574 RD_REG_DWORD(®->ictrl);
1575 spin_unlock_irqrestore(&ha->hardware_lock, flags);
1579 qla24xx_disable_intrs(struct qla_hw_data *ha)
1581 unsigned long flags = 0;
1582 struct device_reg_24xx __iomem *reg = &ha->iobase->isp24;
1584 if (IS_NOPOLLING_TYPE(ha))
1586 spin_lock_irqsave(&ha->hardware_lock, flags);
1587 ha->interrupts_on = 0;
1588 WRT_REG_DWORD(®->ictrl, 0);
1589 RD_REG_DWORD(®->ictrl);
1590 spin_unlock_irqrestore(&ha->hardware_lock, flags);
1594 qla2x00_iospace_config(struct qla_hw_data *ha)
1596 resource_size_t pio;
1600 if (pci_request_selected_regions(ha->pdev, ha->bars,
1601 QLA2XXX_DRIVER_NAME)) {
1602 ql_log_pci(ql_log_fatal, ha->pdev, 0x0011,
1603 "Failed to reserve PIO/MMIO regions (%s), aborting.\n",
1604 pci_name(ha->pdev));
1605 goto iospace_error_exit;
1607 if (!(ha->bars & 1))
1610 /* We only need PIO for Flash operations on ISP2312 v2 chips. */
1611 pio = pci_resource_start(ha->pdev, 0);
1612 if (pci_resource_flags(ha->pdev, 0) & IORESOURCE_IO) {
1613 if (pci_resource_len(ha->pdev, 0) < MIN_IOBASE_LEN) {
1614 ql_log_pci(ql_log_warn, ha->pdev, 0x0012,
1615 "Invalid pci I/O region size (%s).\n",
1616 pci_name(ha->pdev));
1620 ql_log_pci(ql_log_warn, ha->pdev, 0x0013,
1621 "Region #0 no a PIO resource (%s).\n",
1622 pci_name(ha->pdev));
1625 ha->pio_address = pio;
1626 ql_dbg_pci(ql_dbg_init, ha->pdev, 0x0014,
1627 "PIO address=%llu.\n",
1628 (unsigned long long)ha->pio_address);
1631 /* Use MMIO operations for all accesses. */
1632 if (!(pci_resource_flags(ha->pdev, 1) & IORESOURCE_MEM)) {
1633 ql_log_pci(ql_log_fatal, ha->pdev, 0x0015,
1634 "Region #1 not an MMIO resource (%s), aborting.\n",
1635 pci_name(ha->pdev));
1636 goto iospace_error_exit;
1638 if (pci_resource_len(ha->pdev, 1) < MIN_IOBASE_LEN) {
1639 ql_log_pci(ql_log_fatal, ha->pdev, 0x0016,
1640 "Invalid PCI mem region size (%s), aborting.\n",
1641 pci_name(ha->pdev));
1642 goto iospace_error_exit;
1645 ha->iobase = ioremap(pci_resource_start(ha->pdev, 1), MIN_IOBASE_LEN);
1647 ql_log_pci(ql_log_fatal, ha->pdev, 0x0017,
1648 "Cannot remap MMIO (%s), aborting.\n",
1649 pci_name(ha->pdev));
1650 goto iospace_error_exit;
1653 /* Determine queue resources */
1654 ha->max_req_queues = ha->max_rsp_queues = 1;
1655 if ((ql2xmaxqueues <= 1 && !ql2xmultique_tag) ||
1656 (ql2xmaxqueues > 1 && ql2xmultique_tag) ||
1657 (!IS_QLA25XX(ha) && !IS_QLA81XX(ha)))
1660 ha->mqiobase = ioremap(pci_resource_start(ha->pdev, 3),
1661 pci_resource_len(ha->pdev, 3));
1663 ql_dbg_pci(ql_dbg_init, ha->pdev, 0x0018,
1664 "MQIO Base=%p.\n", ha->mqiobase);
1665 /* Read MSIX vector size of the board */
1666 pci_read_config_word(ha->pdev, QLA_PCI_MSIX_CONTROL, &msix);
1667 ha->msix_count = msix;
1668 /* Max queues are bounded by available msix vectors */
1669 /* queue 0 uses two msix vectors */
1670 if (ql2xmultique_tag) {
1671 cpus = num_online_cpus();
1672 ha->max_rsp_queues = (ha->msix_count - 1 > cpus) ?
1673 (cpus + 1) : (ha->msix_count - 1);
1674 ha->max_req_queues = 2;
1675 } else if (ql2xmaxqueues > 1) {
1676 ha->max_req_queues = ql2xmaxqueues > QLA_MQ_SIZE ?
1677 QLA_MQ_SIZE : ql2xmaxqueues;
1678 ql_dbg_pci(ql_dbg_multiq, ha->pdev, 0xc008,
1679 "QoS mode set, max no of request queues:%d.\n",
1680 ha->max_req_queues);
1681 ql_dbg_pci(ql_dbg_init, ha->pdev, 0x0019,
1682 "QoS mode set, max no of request queues:%d.\n",
1683 ha->max_req_queues);
1685 ql_log_pci(ql_log_info, ha->pdev, 0x001a,
1686 "MSI-X vector count: %d.\n", msix);
1688 ql_log_pci(ql_log_info, ha->pdev, 0x001b,
1689 "BAR 3 not enabled.\n");
1692 ha->msix_count = ha->max_rsp_queues + 1;
1693 ql_dbg_pci(ql_dbg_init, ha->pdev, 0x001c,
1694 "MSIX Count:%d.\n", ha->msix_count);
1703 qla83xx_iospace_config(struct qla_hw_data *ha)
1708 if (pci_request_selected_regions(ha->pdev, ha->bars,
1709 QLA2XXX_DRIVER_NAME)) {
1710 ql_log_pci(ql_log_fatal, ha->pdev, 0x0117,
1711 "Failed to reserve PIO/MMIO regions (%s), aborting.\n",
1712 pci_name(ha->pdev));
1714 goto iospace_error_exit;
1717 /* Use MMIO operations for all accesses. */
1718 if (!(pci_resource_flags(ha->pdev, 0) & IORESOURCE_MEM)) {
1719 ql_log_pci(ql_log_warn, ha->pdev, 0x0118,
1720 "Invalid pci I/O region size (%s).\n",
1721 pci_name(ha->pdev));
1722 goto iospace_error_exit;
1724 if (pci_resource_len(ha->pdev, 0) < MIN_IOBASE_LEN) {
1725 ql_log_pci(ql_log_warn, ha->pdev, 0x0119,
1726 "Invalid PCI mem region size (%s), aborting\n",
1727 pci_name(ha->pdev));
1728 goto iospace_error_exit;
1731 ha->iobase = ioremap(pci_resource_start(ha->pdev, 0), MIN_IOBASE_LEN);
1733 ql_log_pci(ql_log_fatal, ha->pdev, 0x011a,
1734 "Cannot remap MMIO (%s), aborting.\n",
1735 pci_name(ha->pdev));
1736 goto iospace_error_exit;
1739 /* 64bit PCI BAR - BAR2 will correspoond to region 4 */
1740 /* 83XX 26XX always use MQ type access for queues
1741 * - mbar 2, a.k.a region 4 */
1742 ha->max_req_queues = ha->max_rsp_queues = 1;
1743 ha->mqiobase = ioremap(pci_resource_start(ha->pdev, 4),
1744 pci_resource_len(ha->pdev, 4));
1746 if (!ha->mqiobase) {
1747 ql_log_pci(ql_log_fatal, ha->pdev, 0x011d,
1748 "BAR2/region4 not enabled\n");
1752 ha->msixbase = ioremap(pci_resource_start(ha->pdev, 2),
1753 pci_resource_len(ha->pdev, 2));
1755 /* Read MSIX vector size of the board */
1756 pci_read_config_word(ha->pdev,
1757 QLA_83XX_PCI_MSIX_CONTROL, &msix);
1758 ha->msix_count = msix;
1759 /* Max queues are bounded by available msix vectors */
1760 /* queue 0 uses two msix vectors */
1761 if (ql2xmultique_tag) {
1762 cpus = num_online_cpus();
1763 ha->max_rsp_queues = (ha->msix_count - 1 > cpus) ?
1764 (cpus + 1) : (ha->msix_count - 1);
1765 ha->max_req_queues = 2;
1766 } else if (ql2xmaxqueues > 1) {
1767 ha->max_req_queues = ql2xmaxqueues > QLA_MQ_SIZE ?
1768 QLA_MQ_SIZE : ql2xmaxqueues;
1769 ql_dbg_pci(ql_dbg_multiq, ha->pdev, 0xc00c,
1770 "QoS mode set, max no of request queues:%d.\n",
1771 ha->max_req_queues);
1772 ql_dbg_pci(ql_dbg_init, ha->pdev, 0x011b,
1773 "QoS mode set, max no of request queues:%d.\n",
1774 ha->max_req_queues);
1776 ql_log_pci(ql_log_info, ha->pdev, 0x011c,
1777 "MSI-X vector count: %d.\n", msix);
1779 ql_log_pci(ql_log_info, ha->pdev, 0x011e,
1780 "BAR 1 not enabled.\n");
1783 ha->msix_count = ha->max_rsp_queues + 1;
1785 qlt_83xx_iospace_config(ha);
1787 ql_dbg_pci(ql_dbg_init, ha->pdev, 0x011f,
1788 "MSIX Count:%d.\n", ha->msix_count);
1795 static struct isp_operations qla2100_isp_ops = {
1796 .pci_config = qla2100_pci_config,
1797 .reset_chip = qla2x00_reset_chip,
1798 .chip_diag = qla2x00_chip_diag,
1799 .config_rings = qla2x00_config_rings,
1800 .reset_adapter = qla2x00_reset_adapter,
1801 .nvram_config = qla2x00_nvram_config,
1802 .update_fw_options = qla2x00_update_fw_options,
1803 .load_risc = qla2x00_load_risc,
1804 .pci_info_str = qla2x00_pci_info_str,
1805 .fw_version_str = qla2x00_fw_version_str,
1806 .intr_handler = qla2100_intr_handler,
1807 .enable_intrs = qla2x00_enable_intrs,
1808 .disable_intrs = qla2x00_disable_intrs,
1809 .abort_command = qla2x00_abort_command,
1810 .target_reset = qla2x00_abort_target,
1811 .lun_reset = qla2x00_lun_reset,
1812 .fabric_login = qla2x00_login_fabric,
1813 .fabric_logout = qla2x00_fabric_logout,
1814 .calc_req_entries = qla2x00_calc_iocbs_32,
1815 .build_iocbs = qla2x00_build_scsi_iocbs_32,
1816 .prep_ms_iocb = qla2x00_prep_ms_iocb,
1817 .prep_ms_fdmi_iocb = qla2x00_prep_ms_fdmi_iocb,
1818 .read_nvram = qla2x00_read_nvram_data,
1819 .write_nvram = qla2x00_write_nvram_data,
1820 .fw_dump = qla2100_fw_dump,
1823 .beacon_blink = NULL,
1824 .read_optrom = qla2x00_read_optrom_data,
1825 .write_optrom = qla2x00_write_optrom_data,
1826 .get_flash_version = qla2x00_get_flash_version,
1827 .start_scsi = qla2x00_start_scsi,
1828 .abort_isp = qla2x00_abort_isp,
1829 .iospace_config = qla2x00_iospace_config,
1830 .initialize_adapter = qla2x00_initialize_adapter,
1833 static struct isp_operations qla2300_isp_ops = {
1834 .pci_config = qla2300_pci_config,
1835 .reset_chip = qla2x00_reset_chip,
1836 .chip_diag = qla2x00_chip_diag,
1837 .config_rings = qla2x00_config_rings,
1838 .reset_adapter = qla2x00_reset_adapter,
1839 .nvram_config = qla2x00_nvram_config,
1840 .update_fw_options = qla2x00_update_fw_options,
1841 .load_risc = qla2x00_load_risc,
1842 .pci_info_str = qla2x00_pci_info_str,
1843 .fw_version_str = qla2x00_fw_version_str,
1844 .intr_handler = qla2300_intr_handler,
1845 .enable_intrs = qla2x00_enable_intrs,
1846 .disable_intrs = qla2x00_disable_intrs,
1847 .abort_command = qla2x00_abort_command,
1848 .target_reset = qla2x00_abort_target,
1849 .lun_reset = qla2x00_lun_reset,
1850 .fabric_login = qla2x00_login_fabric,
1851 .fabric_logout = qla2x00_fabric_logout,
1852 .calc_req_entries = qla2x00_calc_iocbs_32,
1853 .build_iocbs = qla2x00_build_scsi_iocbs_32,
1854 .prep_ms_iocb = qla2x00_prep_ms_iocb,
1855 .prep_ms_fdmi_iocb = qla2x00_prep_ms_fdmi_iocb,
1856 .read_nvram = qla2x00_read_nvram_data,
1857 .write_nvram = qla2x00_write_nvram_data,
1858 .fw_dump = qla2300_fw_dump,
1859 .beacon_on = qla2x00_beacon_on,
1860 .beacon_off = qla2x00_beacon_off,
1861 .beacon_blink = qla2x00_beacon_blink,
1862 .read_optrom = qla2x00_read_optrom_data,
1863 .write_optrom = qla2x00_write_optrom_data,
1864 .get_flash_version = qla2x00_get_flash_version,
1865 .start_scsi = qla2x00_start_scsi,
1866 .abort_isp = qla2x00_abort_isp,
1867 .iospace_config = qla2x00_iospace_config,
1868 .initialize_adapter = qla2x00_initialize_adapter,
1871 static struct isp_operations qla24xx_isp_ops = {
1872 .pci_config = qla24xx_pci_config,
1873 .reset_chip = qla24xx_reset_chip,
1874 .chip_diag = qla24xx_chip_diag,
1875 .config_rings = qla24xx_config_rings,
1876 .reset_adapter = qla24xx_reset_adapter,
1877 .nvram_config = qla24xx_nvram_config,
1878 .update_fw_options = qla24xx_update_fw_options,
1879 .load_risc = qla24xx_load_risc,
1880 .pci_info_str = qla24xx_pci_info_str,
1881 .fw_version_str = qla24xx_fw_version_str,
1882 .intr_handler = qla24xx_intr_handler,
1883 .enable_intrs = qla24xx_enable_intrs,
1884 .disable_intrs = qla24xx_disable_intrs,
1885 .abort_command = qla24xx_abort_command,
1886 .target_reset = qla24xx_abort_target,
1887 .lun_reset = qla24xx_lun_reset,
1888 .fabric_login = qla24xx_login_fabric,
1889 .fabric_logout = qla24xx_fabric_logout,
1890 .calc_req_entries = NULL,
1891 .build_iocbs = NULL,
1892 .prep_ms_iocb = qla24xx_prep_ms_iocb,
1893 .prep_ms_fdmi_iocb = qla24xx_prep_ms_fdmi_iocb,
1894 .read_nvram = qla24xx_read_nvram_data,
1895 .write_nvram = qla24xx_write_nvram_data,
1896 .fw_dump = qla24xx_fw_dump,
1897 .beacon_on = qla24xx_beacon_on,
1898 .beacon_off = qla24xx_beacon_off,
1899 .beacon_blink = qla24xx_beacon_blink,
1900 .read_optrom = qla24xx_read_optrom_data,
1901 .write_optrom = qla24xx_write_optrom_data,
1902 .get_flash_version = qla24xx_get_flash_version,
1903 .start_scsi = qla24xx_start_scsi,
1904 .abort_isp = qla2x00_abort_isp,
1905 .iospace_config = qla2x00_iospace_config,
1906 .initialize_adapter = qla2x00_initialize_adapter,
1909 static struct isp_operations qla25xx_isp_ops = {
1910 .pci_config = qla25xx_pci_config,
1911 .reset_chip = qla24xx_reset_chip,
1912 .chip_diag = qla24xx_chip_diag,
1913 .config_rings = qla24xx_config_rings,
1914 .reset_adapter = qla24xx_reset_adapter,
1915 .nvram_config = qla24xx_nvram_config,
1916 .update_fw_options = qla24xx_update_fw_options,
1917 .load_risc = qla24xx_load_risc,
1918 .pci_info_str = qla24xx_pci_info_str,
1919 .fw_version_str = qla24xx_fw_version_str,
1920 .intr_handler = qla24xx_intr_handler,
1921 .enable_intrs = qla24xx_enable_intrs,
1922 .disable_intrs = qla24xx_disable_intrs,
1923 .abort_command = qla24xx_abort_command,
1924 .target_reset = qla24xx_abort_target,
1925 .lun_reset = qla24xx_lun_reset,
1926 .fabric_login = qla24xx_login_fabric,
1927 .fabric_logout = qla24xx_fabric_logout,
1928 .calc_req_entries = NULL,
1929 .build_iocbs = NULL,
1930 .prep_ms_iocb = qla24xx_prep_ms_iocb,
1931 .prep_ms_fdmi_iocb = qla24xx_prep_ms_fdmi_iocb,
1932 .read_nvram = qla25xx_read_nvram_data,
1933 .write_nvram = qla25xx_write_nvram_data,
1934 .fw_dump = qla25xx_fw_dump,
1935 .beacon_on = qla24xx_beacon_on,
1936 .beacon_off = qla24xx_beacon_off,
1937 .beacon_blink = qla24xx_beacon_blink,
1938 .read_optrom = qla25xx_read_optrom_data,
1939 .write_optrom = qla24xx_write_optrom_data,
1940 .get_flash_version = qla24xx_get_flash_version,
1941 .start_scsi = qla24xx_dif_start_scsi,
1942 .abort_isp = qla2x00_abort_isp,
1943 .iospace_config = qla2x00_iospace_config,
1944 .initialize_adapter = qla2x00_initialize_adapter,
1947 static struct isp_operations qla81xx_isp_ops = {
1948 .pci_config = qla25xx_pci_config,
1949 .reset_chip = qla24xx_reset_chip,
1950 .chip_diag = qla24xx_chip_diag,
1951 .config_rings = qla24xx_config_rings,
1952 .reset_adapter = qla24xx_reset_adapter,
1953 .nvram_config = qla81xx_nvram_config,
1954 .update_fw_options = qla81xx_update_fw_options,
1955 .load_risc = qla81xx_load_risc,
1956 .pci_info_str = qla24xx_pci_info_str,
1957 .fw_version_str = qla24xx_fw_version_str,
1958 .intr_handler = qla24xx_intr_handler,
1959 .enable_intrs = qla24xx_enable_intrs,
1960 .disable_intrs = qla24xx_disable_intrs,
1961 .abort_command = qla24xx_abort_command,
1962 .target_reset = qla24xx_abort_target,
1963 .lun_reset = qla24xx_lun_reset,
1964 .fabric_login = qla24xx_login_fabric,
1965 .fabric_logout = qla24xx_fabric_logout,
1966 .calc_req_entries = NULL,
1967 .build_iocbs = NULL,
1968 .prep_ms_iocb = qla24xx_prep_ms_iocb,
1969 .prep_ms_fdmi_iocb = qla24xx_prep_ms_fdmi_iocb,
1971 .write_nvram = NULL,
1972 .fw_dump = qla81xx_fw_dump,
1973 .beacon_on = qla24xx_beacon_on,
1974 .beacon_off = qla24xx_beacon_off,
1975 .beacon_blink = qla83xx_beacon_blink,
1976 .read_optrom = qla25xx_read_optrom_data,
1977 .write_optrom = qla24xx_write_optrom_data,
1978 .get_flash_version = qla24xx_get_flash_version,
1979 .start_scsi = qla24xx_dif_start_scsi,
1980 .abort_isp = qla2x00_abort_isp,
1981 .iospace_config = qla2x00_iospace_config,
1982 .initialize_adapter = qla2x00_initialize_adapter,
1985 static struct isp_operations qla82xx_isp_ops = {
1986 .pci_config = qla82xx_pci_config,
1987 .reset_chip = qla82xx_reset_chip,
1988 .chip_diag = qla24xx_chip_diag,
1989 .config_rings = qla82xx_config_rings,
1990 .reset_adapter = qla24xx_reset_adapter,
1991 .nvram_config = qla81xx_nvram_config,
1992 .update_fw_options = qla24xx_update_fw_options,
1993 .load_risc = qla82xx_load_risc,
1994 .pci_info_str = qla24xx_pci_info_str,
1995 .fw_version_str = qla24xx_fw_version_str,
1996 .intr_handler = qla82xx_intr_handler,
1997 .enable_intrs = qla82xx_enable_intrs,
1998 .disable_intrs = qla82xx_disable_intrs,
1999 .abort_command = qla24xx_abort_command,
2000 .target_reset = qla24xx_abort_target,
2001 .lun_reset = qla24xx_lun_reset,
2002 .fabric_login = qla24xx_login_fabric,
2003 .fabric_logout = qla24xx_fabric_logout,
2004 .calc_req_entries = NULL,
2005 .build_iocbs = NULL,
2006 .prep_ms_iocb = qla24xx_prep_ms_iocb,
2007 .prep_ms_fdmi_iocb = qla24xx_prep_ms_fdmi_iocb,
2008 .read_nvram = qla24xx_read_nvram_data,
2009 .write_nvram = qla24xx_write_nvram_data,
2010 .fw_dump = qla82xx_fw_dump,
2011 .beacon_on = qla82xx_beacon_on,
2012 .beacon_off = qla82xx_beacon_off,
2013 .beacon_blink = NULL,
2014 .read_optrom = qla82xx_read_optrom_data,
2015 .write_optrom = qla82xx_write_optrom_data,
2016 .get_flash_version = qla82xx_get_flash_version,
2017 .start_scsi = qla82xx_start_scsi,
2018 .abort_isp = qla82xx_abort_isp,
2019 .iospace_config = qla82xx_iospace_config,
2020 .initialize_adapter = qla2x00_initialize_adapter,
2023 static struct isp_operations qla8044_isp_ops = {
2024 .pci_config = qla82xx_pci_config,
2025 .reset_chip = qla82xx_reset_chip,
2026 .chip_diag = qla24xx_chip_diag,
2027 .config_rings = qla82xx_config_rings,
2028 .reset_adapter = qla24xx_reset_adapter,
2029 .nvram_config = qla81xx_nvram_config,
2030 .update_fw_options = qla24xx_update_fw_options,
2031 .load_risc = qla82xx_load_risc,
2032 .pci_info_str = qla24xx_pci_info_str,
2033 .fw_version_str = qla24xx_fw_version_str,
2034 .intr_handler = qla8044_intr_handler,
2035 .enable_intrs = qla82xx_enable_intrs,
2036 .disable_intrs = qla82xx_disable_intrs,
2037 .abort_command = qla24xx_abort_command,
2038 .target_reset = qla24xx_abort_target,
2039 .lun_reset = qla24xx_lun_reset,
2040 .fabric_login = qla24xx_login_fabric,
2041 .fabric_logout = qla24xx_fabric_logout,
2042 .calc_req_entries = NULL,
2043 .build_iocbs = NULL,
2044 .prep_ms_iocb = qla24xx_prep_ms_iocb,
2045 .prep_ms_fdmi_iocb = qla24xx_prep_ms_fdmi_iocb,
2047 .write_nvram = NULL,
2048 .fw_dump = qla8044_fw_dump,
2049 .beacon_on = qla82xx_beacon_on,
2050 .beacon_off = qla82xx_beacon_off,
2051 .beacon_blink = NULL,
2052 .read_optrom = qla8044_read_optrom_data,
2053 .write_optrom = qla8044_write_optrom_data,
2054 .get_flash_version = qla82xx_get_flash_version,
2055 .start_scsi = qla82xx_start_scsi,
2056 .abort_isp = qla8044_abort_isp,
2057 .iospace_config = qla82xx_iospace_config,
2058 .initialize_adapter = qla2x00_initialize_adapter,
2061 static struct isp_operations qla83xx_isp_ops = {
2062 .pci_config = qla25xx_pci_config,
2063 .reset_chip = qla24xx_reset_chip,
2064 .chip_diag = qla24xx_chip_diag,
2065 .config_rings = qla24xx_config_rings,
2066 .reset_adapter = qla24xx_reset_adapter,
2067 .nvram_config = qla81xx_nvram_config,
2068 .update_fw_options = qla81xx_update_fw_options,
2069 .load_risc = qla81xx_load_risc,
2070 .pci_info_str = qla24xx_pci_info_str,
2071 .fw_version_str = qla24xx_fw_version_str,
2072 .intr_handler = qla24xx_intr_handler,
2073 .enable_intrs = qla24xx_enable_intrs,
2074 .disable_intrs = qla24xx_disable_intrs,
2075 .abort_command = qla24xx_abort_command,
2076 .target_reset = qla24xx_abort_target,
2077 .lun_reset = qla24xx_lun_reset,
2078 .fabric_login = qla24xx_login_fabric,
2079 .fabric_logout = qla24xx_fabric_logout,
2080 .calc_req_entries = NULL,
2081 .build_iocbs = NULL,
2082 .prep_ms_iocb = qla24xx_prep_ms_iocb,
2083 .prep_ms_fdmi_iocb = qla24xx_prep_ms_fdmi_iocb,
2085 .write_nvram = NULL,
2086 .fw_dump = qla83xx_fw_dump,
2087 .beacon_on = qla24xx_beacon_on,
2088 .beacon_off = qla24xx_beacon_off,
2089 .beacon_blink = qla83xx_beacon_blink,
2090 .read_optrom = qla25xx_read_optrom_data,
2091 .write_optrom = qla24xx_write_optrom_data,
2092 .get_flash_version = qla24xx_get_flash_version,
2093 .start_scsi = qla24xx_dif_start_scsi,
2094 .abort_isp = qla2x00_abort_isp,
2095 .iospace_config = qla83xx_iospace_config,
2096 .initialize_adapter = qla2x00_initialize_adapter,
2099 static struct isp_operations qlafx00_isp_ops = {
2100 .pci_config = qlafx00_pci_config,
2101 .reset_chip = qlafx00_soft_reset,
2102 .chip_diag = qlafx00_chip_diag,
2103 .config_rings = qlafx00_config_rings,
2104 .reset_adapter = qlafx00_soft_reset,
2105 .nvram_config = NULL,
2106 .update_fw_options = NULL,
2108 .pci_info_str = qlafx00_pci_info_str,
2109 .fw_version_str = qlafx00_fw_version_str,
2110 .intr_handler = qlafx00_intr_handler,
2111 .enable_intrs = qlafx00_enable_intrs,
2112 .disable_intrs = qlafx00_disable_intrs,
2113 .abort_command = qla24xx_async_abort_command,
2114 .target_reset = qlafx00_abort_target,
2115 .lun_reset = qlafx00_lun_reset,
2116 .fabric_login = NULL,
2117 .fabric_logout = NULL,
2118 .calc_req_entries = NULL,
2119 .build_iocbs = NULL,
2120 .prep_ms_iocb = qla24xx_prep_ms_iocb,
2121 .prep_ms_fdmi_iocb = qla24xx_prep_ms_fdmi_iocb,
2122 .read_nvram = qla24xx_read_nvram_data,
2123 .write_nvram = qla24xx_write_nvram_data,
2125 .beacon_on = qla24xx_beacon_on,
2126 .beacon_off = qla24xx_beacon_off,
2127 .beacon_blink = NULL,
2128 .read_optrom = qla24xx_read_optrom_data,
2129 .write_optrom = qla24xx_write_optrom_data,
2130 .get_flash_version = qla24xx_get_flash_version,
2131 .start_scsi = qlafx00_start_scsi,
2132 .abort_isp = qlafx00_abort_isp,
2133 .iospace_config = qlafx00_iospace_config,
2134 .initialize_adapter = qlafx00_initialize_adapter,
2137 static struct isp_operations qla27xx_isp_ops = {
2138 .pci_config = qla25xx_pci_config,
2139 .reset_chip = qla24xx_reset_chip,
2140 .chip_diag = qla24xx_chip_diag,
2141 .config_rings = qla24xx_config_rings,
2142 .reset_adapter = qla24xx_reset_adapter,
2143 .nvram_config = qla81xx_nvram_config,
2144 .update_fw_options = qla81xx_update_fw_options,
2145 .load_risc = qla81xx_load_risc,
2146 .pci_info_str = qla24xx_pci_info_str,
2147 .fw_version_str = qla24xx_fw_version_str,
2148 .intr_handler = qla24xx_intr_handler,
2149 .enable_intrs = qla24xx_enable_intrs,
2150 .disable_intrs = qla24xx_disable_intrs,
2151 .abort_command = qla24xx_abort_command,
2152 .target_reset = qla24xx_abort_target,
2153 .lun_reset = qla24xx_lun_reset,
2154 .fabric_login = qla24xx_login_fabric,
2155 .fabric_logout = qla24xx_fabric_logout,
2156 .calc_req_entries = NULL,
2157 .build_iocbs = NULL,
2158 .prep_ms_iocb = qla24xx_prep_ms_iocb,
2159 .prep_ms_fdmi_iocb = qla24xx_prep_ms_fdmi_iocb,
2161 .write_nvram = NULL,
2162 .fw_dump = qla27xx_fwdump,
2163 .beacon_on = qla24xx_beacon_on,
2164 .beacon_off = qla24xx_beacon_off,
2165 .beacon_blink = qla83xx_beacon_blink,
2166 .read_optrom = qla25xx_read_optrom_data,
2167 .write_optrom = qla24xx_write_optrom_data,
2168 .get_flash_version = qla24xx_get_flash_version,
2169 .start_scsi = qla24xx_dif_start_scsi,
2170 .abort_isp = qla2x00_abort_isp,
2171 .iospace_config = qla83xx_iospace_config,
2172 .initialize_adapter = qla2x00_initialize_adapter,
2176 qla2x00_set_isp_flags(struct qla_hw_data *ha)
2178 ha->device_type = DT_EXTENDED_IDS;
2179 switch (ha->pdev->device) {
2180 case PCI_DEVICE_ID_QLOGIC_ISP2100:
2181 ha->isp_type |= DT_ISP2100;
2182 ha->device_type &= ~DT_EXTENDED_IDS;
2183 ha->fw_srisc_address = RISC_START_ADDRESS_2100;
2185 case PCI_DEVICE_ID_QLOGIC_ISP2200:
2186 ha->isp_type |= DT_ISP2200;
2187 ha->device_type &= ~DT_EXTENDED_IDS;
2188 ha->fw_srisc_address = RISC_START_ADDRESS_2100;
2190 case PCI_DEVICE_ID_QLOGIC_ISP2300:
2191 ha->isp_type |= DT_ISP2300;
2192 ha->device_type |= DT_ZIO_SUPPORTED;
2193 ha->fw_srisc_address = RISC_START_ADDRESS_2300;
2195 case PCI_DEVICE_ID_QLOGIC_ISP2312:
2196 ha->isp_type |= DT_ISP2312;
2197 ha->device_type |= DT_ZIO_SUPPORTED;
2198 ha->fw_srisc_address = RISC_START_ADDRESS_2300;
2200 case PCI_DEVICE_ID_QLOGIC_ISP2322:
2201 ha->isp_type |= DT_ISP2322;
2202 ha->device_type |= DT_ZIO_SUPPORTED;
2203 if (ha->pdev->subsystem_vendor == 0x1028 &&
2204 ha->pdev->subsystem_device == 0x0170)
2205 ha->device_type |= DT_OEM_001;
2206 ha->fw_srisc_address = RISC_START_ADDRESS_2300;
2208 case PCI_DEVICE_ID_QLOGIC_ISP6312:
2209 ha->isp_type |= DT_ISP6312;
2210 ha->fw_srisc_address = RISC_START_ADDRESS_2300;
2212 case PCI_DEVICE_ID_QLOGIC_ISP6322:
2213 ha->isp_type |= DT_ISP6322;
2214 ha->fw_srisc_address = RISC_START_ADDRESS_2300;
2216 case PCI_DEVICE_ID_QLOGIC_ISP2422:
2217 ha->isp_type |= DT_ISP2422;
2218 ha->device_type |= DT_ZIO_SUPPORTED;
2219 ha->device_type |= DT_FWI2;
2220 ha->device_type |= DT_IIDMA;
2221 ha->fw_srisc_address = RISC_START_ADDRESS_2400;
2223 case PCI_DEVICE_ID_QLOGIC_ISP2432:
2224 ha->isp_type |= DT_ISP2432;
2225 ha->device_type |= DT_ZIO_SUPPORTED;
2226 ha->device_type |= DT_FWI2;
2227 ha->device_type |= DT_IIDMA;
2228 ha->fw_srisc_address = RISC_START_ADDRESS_2400;
2230 case PCI_DEVICE_ID_QLOGIC_ISP8432:
2231 ha->isp_type |= DT_ISP8432;
2232 ha->device_type |= DT_ZIO_SUPPORTED;
2233 ha->device_type |= DT_FWI2;
2234 ha->device_type |= DT_IIDMA;
2235 ha->fw_srisc_address = RISC_START_ADDRESS_2400;
2237 case PCI_DEVICE_ID_QLOGIC_ISP5422:
2238 ha->isp_type |= DT_ISP5422;
2239 ha->device_type |= DT_FWI2;
2240 ha->fw_srisc_address = RISC_START_ADDRESS_2400;
2242 case PCI_DEVICE_ID_QLOGIC_ISP5432:
2243 ha->isp_type |= DT_ISP5432;
2244 ha->device_type |= DT_FWI2;
2245 ha->fw_srisc_address = RISC_START_ADDRESS_2400;
2247 case PCI_DEVICE_ID_QLOGIC_ISP2532:
2248 ha->isp_type |= DT_ISP2532;
2249 ha->device_type |= DT_ZIO_SUPPORTED;
2250 ha->device_type |= DT_FWI2;
2251 ha->device_type |= DT_IIDMA;
2252 ha->fw_srisc_address = RISC_START_ADDRESS_2400;
2254 case PCI_DEVICE_ID_QLOGIC_ISP8001:
2255 ha->isp_type |= DT_ISP8001;
2256 ha->device_type |= DT_ZIO_SUPPORTED;
2257 ha->device_type |= DT_FWI2;
2258 ha->device_type |= DT_IIDMA;
2259 ha->fw_srisc_address = RISC_START_ADDRESS_2400;
2261 case PCI_DEVICE_ID_QLOGIC_ISP8021:
2262 ha->isp_type |= DT_ISP8021;
2263 ha->device_type |= DT_ZIO_SUPPORTED;
2264 ha->device_type |= DT_FWI2;
2265 ha->fw_srisc_address = RISC_START_ADDRESS_2400;
2266 /* Initialize 82XX ISP flags */
2267 qla82xx_init_flags(ha);
2269 case PCI_DEVICE_ID_QLOGIC_ISP8044:
2270 ha->isp_type |= DT_ISP8044;
2271 ha->device_type |= DT_ZIO_SUPPORTED;
2272 ha->device_type |= DT_FWI2;
2273 ha->fw_srisc_address = RISC_START_ADDRESS_2400;
2274 /* Initialize 82XX ISP flags */
2275 qla82xx_init_flags(ha);
2277 case PCI_DEVICE_ID_QLOGIC_ISP2031:
2278 ha->isp_type |= DT_ISP2031;
2279 ha->device_type |= DT_ZIO_SUPPORTED;
2280 ha->device_type |= DT_FWI2;
2281 ha->device_type |= DT_IIDMA;
2282 ha->device_type |= DT_T10_PI;
2283 ha->fw_srisc_address = RISC_START_ADDRESS_2400;
2285 case PCI_DEVICE_ID_QLOGIC_ISP8031:
2286 ha->isp_type |= DT_ISP8031;
2287 ha->device_type |= DT_ZIO_SUPPORTED;
2288 ha->device_type |= DT_FWI2;
2289 ha->device_type |= DT_IIDMA;
2290 ha->device_type |= DT_T10_PI;
2291 ha->fw_srisc_address = RISC_START_ADDRESS_2400;
2293 case PCI_DEVICE_ID_QLOGIC_ISPF001:
2294 ha->isp_type |= DT_ISPFX00;
2296 case PCI_DEVICE_ID_QLOGIC_ISP2071:
2297 ha->isp_type |= DT_ISP2071;
2298 ha->device_type |= DT_ZIO_SUPPORTED;
2299 ha->device_type |= DT_FWI2;
2300 ha->device_type |= DT_IIDMA;
2301 ha->device_type |= DT_T10_PI;
2302 ha->fw_srisc_address = RISC_START_ADDRESS_2400;
2304 case PCI_DEVICE_ID_QLOGIC_ISP2271:
2305 ha->isp_type |= DT_ISP2271;
2306 ha->device_type |= DT_ZIO_SUPPORTED;
2307 ha->device_type |= DT_FWI2;
2308 ha->device_type |= DT_IIDMA;
2309 ha->device_type |= DT_T10_PI;
2310 ha->fw_srisc_address = RISC_START_ADDRESS_2400;
2312 case PCI_DEVICE_ID_QLOGIC_ISP2261:
2313 ha->isp_type |= DT_ISP2261;
2314 ha->device_type |= DT_ZIO_SUPPORTED;
2315 ha->device_type |= DT_FWI2;
2316 ha->device_type |= DT_IIDMA;
2317 ha->device_type |= DT_T10_PI;
2318 ha->fw_srisc_address = RISC_START_ADDRESS_2400;
2323 ha->port_no = ha->portnum & 1;
2325 /* Get adapter physical port no from interrupt pin register. */
2326 pci_read_config_byte(ha->pdev, PCI_INTERRUPT_PIN, &ha->port_no);
2330 ha->port_no = !(ha->port_no & 1);
2333 ql_dbg_pci(ql_dbg_init, ha->pdev, 0x000b,
2334 "device_type=0x%x port=%d fw_srisc_address=0x%x.\n",
2335 ha->device_type, ha->port_no, ha->fw_srisc_address);
2339 qla2xxx_scan_start(struct Scsi_Host *shost)
2341 scsi_qla_host_t *vha = shost_priv(shost);
2343 if (vha->hw->flags.running_gold_fw)
2346 set_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags);
2347 set_bit(LOCAL_LOOP_UPDATE, &vha->dpc_flags);
2348 set_bit(RSCN_UPDATE, &vha->dpc_flags);
2349 set_bit(NPIV_CONFIG_NEEDED, &vha->dpc_flags);
2353 qla2xxx_scan_finished(struct Scsi_Host *shost, unsigned long time)
2355 scsi_qla_host_t *vha = shost_priv(shost);
2357 if (test_bit(UNLOADING, &vha->dpc_flags))
2361 if (time > vha->hw->loop_reset_delay * HZ)
2364 return atomic_read(&vha->loop_state) == LOOP_READY;
2368 * PCI driver interface
2371 qla2x00_probe_one(struct pci_dev *pdev, const struct pci_device_id *id)
2374 struct Scsi_Host *host;
2375 scsi_qla_host_t *base_vha = NULL;
2376 struct qla_hw_data *ha;
2378 char fw_str[30], wq_name[30];
2379 struct scsi_host_template *sht;
2380 int bars, mem_only = 0;
2381 uint16_t req_length = 0, rsp_length = 0;
2382 struct req_que *req = NULL;
2383 struct rsp_que *rsp = NULL;
2384 bars = pci_select_bars(pdev, IORESOURCE_MEM | IORESOURCE_IO);
2385 sht = &qla2xxx_driver_template;
2386 if (pdev->device == PCI_DEVICE_ID_QLOGIC_ISP2422 ||
2387 pdev->device == PCI_DEVICE_ID_QLOGIC_ISP2432 ||
2388 pdev->device == PCI_DEVICE_ID_QLOGIC_ISP8432 ||
2389 pdev->device == PCI_DEVICE_ID_QLOGIC_ISP5422 ||
2390 pdev->device == PCI_DEVICE_ID_QLOGIC_ISP5432 ||
2391 pdev->device == PCI_DEVICE_ID_QLOGIC_ISP2532 ||
2392 pdev->device == PCI_DEVICE_ID_QLOGIC_ISP8001 ||
2393 pdev->device == PCI_DEVICE_ID_QLOGIC_ISP8021 ||
2394 pdev->device == PCI_DEVICE_ID_QLOGIC_ISP2031 ||
2395 pdev->device == PCI_DEVICE_ID_QLOGIC_ISP8031 ||
2396 pdev->device == PCI_DEVICE_ID_QLOGIC_ISPF001 ||
2397 pdev->device == PCI_DEVICE_ID_QLOGIC_ISP8044 ||
2398 pdev->device == PCI_DEVICE_ID_QLOGIC_ISP2071 ||
2399 pdev->device == PCI_DEVICE_ID_QLOGIC_ISP2271 ||
2400 pdev->device == PCI_DEVICE_ID_QLOGIC_ISP2261) {
2401 bars = pci_select_bars(pdev, IORESOURCE_MEM);
2403 ql_dbg_pci(ql_dbg_init, pdev, 0x0007,
2404 "Mem only adapter.\n");
2406 ql_dbg_pci(ql_dbg_init, pdev, 0x0008,
2407 "Bars=%d.\n", bars);
2410 if (pci_enable_device_mem(pdev))
2413 if (pci_enable_device(pdev))
2417 /* This may fail but that's ok */
2418 pci_enable_pcie_error_reporting(pdev);
2420 ha = kzalloc(sizeof(struct qla_hw_data), GFP_KERNEL);
2422 ql_log_pci(ql_log_fatal, pdev, 0x0009,
2423 "Unable to allocate memory for ha.\n");
2424 goto disable_device;
2426 ql_dbg_pci(ql_dbg_init, pdev, 0x000a,
2427 "Memory allocated for ha=%p.\n", ha);
2429 ha->tgt.enable_class_2 = ql2xenableclass2;
2430 INIT_LIST_HEAD(&ha->tgt.q_full_list);
2431 spin_lock_init(&ha->tgt.q_full_lock);
2432 spin_lock_init(&ha->tgt.sess_lock);
2433 spin_lock_init(&ha->tgt.atio_lock);
2436 /* Clear our data area */
2438 ha->mem_only = mem_only;
2439 spin_lock_init(&ha->hardware_lock);
2440 spin_lock_init(&ha->vport_slock);
2441 mutex_init(&ha->selflogin_lock);
2442 mutex_init(&ha->optrom_mutex);
2444 /* Set ISP-type information. */
2445 qla2x00_set_isp_flags(ha);
2447 /* Set EEH reset type to fundamental if required by hba */
2448 if (IS_QLA24XX(ha) || IS_QLA25XX(ha) || IS_QLA81XX(ha) ||
2449 IS_QLA83XX(ha) || IS_QLA27XX(ha))
2450 pdev->needs_freset = 1;
2452 ha->prev_topology = 0;
2453 ha->init_cb_size = sizeof(init_cb_t);
2454 ha->link_data_rate = PORT_SPEED_UNKNOWN;
2455 ha->optrom_size = OPTROM_SIZE_2300;
2457 /* Assign ISP specific operations. */
2458 if (IS_QLA2100(ha)) {
2459 ha->max_fibre_devices = MAX_FIBRE_DEVICES_2100;
2460 ha->mbx_count = MAILBOX_REGISTER_COUNT_2100;
2461 req_length = REQUEST_ENTRY_CNT_2100;
2462 rsp_length = RESPONSE_ENTRY_CNT_2100;
2463 ha->max_loop_id = SNS_LAST_LOOP_ID_2100;
2464 ha->gid_list_info_size = 4;
2465 ha->flash_conf_off = ~0;
2466 ha->flash_data_off = ~0;
2467 ha->nvram_conf_off = ~0;
2468 ha->nvram_data_off = ~0;
2469 ha->isp_ops = &qla2100_isp_ops;
2470 } else if (IS_QLA2200(ha)) {
2471 ha->max_fibre_devices = MAX_FIBRE_DEVICES_2100;
2472 ha->mbx_count = MAILBOX_REGISTER_COUNT_2200;
2473 req_length = REQUEST_ENTRY_CNT_2200;
2474 rsp_length = RESPONSE_ENTRY_CNT_2100;
2475 ha->max_loop_id = SNS_LAST_LOOP_ID_2100;
2476 ha->gid_list_info_size = 4;
2477 ha->flash_conf_off = ~0;
2478 ha->flash_data_off = ~0;
2479 ha->nvram_conf_off = ~0;
2480 ha->nvram_data_off = ~0;
2481 ha->isp_ops = &qla2100_isp_ops;
2482 } else if (IS_QLA23XX(ha)) {
2483 ha->max_fibre_devices = MAX_FIBRE_DEVICES_2100;
2484 ha->mbx_count = MAILBOX_REGISTER_COUNT;
2485 req_length = REQUEST_ENTRY_CNT_2200;
2486 rsp_length = RESPONSE_ENTRY_CNT_2300;
2487 ha->max_loop_id = SNS_LAST_LOOP_ID_2300;
2488 ha->gid_list_info_size = 6;
2489 if (IS_QLA2322(ha) || IS_QLA6322(ha))
2490 ha->optrom_size = OPTROM_SIZE_2322;
2491 ha->flash_conf_off = ~0;
2492 ha->flash_data_off = ~0;
2493 ha->nvram_conf_off = ~0;
2494 ha->nvram_data_off = ~0;
2495 ha->isp_ops = &qla2300_isp_ops;
2496 } else if (IS_QLA24XX_TYPE(ha)) {
2497 ha->max_fibre_devices = MAX_FIBRE_DEVICES_2400;
2498 ha->mbx_count = MAILBOX_REGISTER_COUNT;
2499 req_length = REQUEST_ENTRY_CNT_24XX;
2500 rsp_length = RESPONSE_ENTRY_CNT_2300;
2501 ha->tgt.atio_q_length = ATIO_ENTRY_CNT_24XX;
2502 ha->max_loop_id = SNS_LAST_LOOP_ID_2300;
2503 ha->init_cb_size = sizeof(struct mid_init_cb_24xx);
2504 ha->gid_list_info_size = 8;
2505 ha->optrom_size = OPTROM_SIZE_24XX;
2506 ha->nvram_npiv_size = QLA_MAX_VPORTS_QLA24XX;
2507 ha->isp_ops = &qla24xx_isp_ops;
2508 ha->flash_conf_off = FARX_ACCESS_FLASH_CONF;
2509 ha->flash_data_off = FARX_ACCESS_FLASH_DATA;
2510 ha->nvram_conf_off = FARX_ACCESS_NVRAM_CONF;
2511 ha->nvram_data_off = FARX_ACCESS_NVRAM_DATA;
2512 } else if (IS_QLA25XX(ha)) {
2513 ha->max_fibre_devices = MAX_FIBRE_DEVICES_2400;
2514 ha->mbx_count = MAILBOX_REGISTER_COUNT;
2515 req_length = REQUEST_ENTRY_CNT_24XX;
2516 rsp_length = RESPONSE_ENTRY_CNT_2300;
2517 ha->tgt.atio_q_length = ATIO_ENTRY_CNT_24XX;
2518 ha->max_loop_id = SNS_LAST_LOOP_ID_2300;
2519 ha->init_cb_size = sizeof(struct mid_init_cb_24xx);
2520 ha->gid_list_info_size = 8;
2521 ha->optrom_size = OPTROM_SIZE_25XX;
2522 ha->nvram_npiv_size = QLA_MAX_VPORTS_QLA25XX;
2523 ha->isp_ops = &qla25xx_isp_ops;
2524 ha->flash_conf_off = FARX_ACCESS_FLASH_CONF;
2525 ha->flash_data_off = FARX_ACCESS_FLASH_DATA;
2526 ha->nvram_conf_off = FARX_ACCESS_NVRAM_CONF;
2527 ha->nvram_data_off = FARX_ACCESS_NVRAM_DATA;
2528 } else if (IS_QLA81XX(ha)) {
2529 ha->max_fibre_devices = MAX_FIBRE_DEVICES_2400;
2530 ha->mbx_count = MAILBOX_REGISTER_COUNT;
2531 req_length = REQUEST_ENTRY_CNT_24XX;
2532 rsp_length = RESPONSE_ENTRY_CNT_2300;
2533 ha->tgt.atio_q_length = ATIO_ENTRY_CNT_24XX;
2534 ha->max_loop_id = SNS_LAST_LOOP_ID_2300;
2535 ha->init_cb_size = sizeof(struct mid_init_cb_81xx);
2536 ha->gid_list_info_size = 8;
2537 ha->optrom_size = OPTROM_SIZE_81XX;
2538 ha->nvram_npiv_size = QLA_MAX_VPORTS_QLA25XX;
2539 ha->isp_ops = &qla81xx_isp_ops;
2540 ha->flash_conf_off = FARX_ACCESS_FLASH_CONF_81XX;
2541 ha->flash_data_off = FARX_ACCESS_FLASH_DATA_81XX;
2542 ha->nvram_conf_off = ~0;
2543 ha->nvram_data_off = ~0;
2544 } else if (IS_QLA82XX(ha)) {
2545 ha->max_fibre_devices = MAX_FIBRE_DEVICES_2400;
2546 ha->mbx_count = MAILBOX_REGISTER_COUNT;
2547 req_length = REQUEST_ENTRY_CNT_82XX;
2548 rsp_length = RESPONSE_ENTRY_CNT_82XX;
2549 ha->max_loop_id = SNS_LAST_LOOP_ID_2300;
2550 ha->init_cb_size = sizeof(struct mid_init_cb_81xx);
2551 ha->gid_list_info_size = 8;
2552 ha->optrom_size = OPTROM_SIZE_82XX;
2553 ha->nvram_npiv_size = QLA_MAX_VPORTS_QLA25XX;
2554 ha->isp_ops = &qla82xx_isp_ops;
2555 ha->flash_conf_off = FARX_ACCESS_FLASH_CONF;
2556 ha->flash_data_off = FARX_ACCESS_FLASH_DATA;
2557 ha->nvram_conf_off = FARX_ACCESS_NVRAM_CONF;
2558 ha->nvram_data_off = FARX_ACCESS_NVRAM_DATA;
2559 } else if (IS_QLA8044(ha)) {
2560 ha->max_fibre_devices = MAX_FIBRE_DEVICES_2400;
2561 ha->mbx_count = MAILBOX_REGISTER_COUNT;
2562 req_length = REQUEST_ENTRY_CNT_82XX;
2563 rsp_length = RESPONSE_ENTRY_CNT_82XX;
2564 ha->max_loop_id = SNS_LAST_LOOP_ID_2300;
2565 ha->init_cb_size = sizeof(struct mid_init_cb_81xx);
2566 ha->gid_list_info_size = 8;
2567 ha->optrom_size = OPTROM_SIZE_83XX;
2568 ha->nvram_npiv_size = QLA_MAX_VPORTS_QLA25XX;
2569 ha->isp_ops = &qla8044_isp_ops;
2570 ha->flash_conf_off = FARX_ACCESS_FLASH_CONF;
2571 ha->flash_data_off = FARX_ACCESS_FLASH_DATA;
2572 ha->nvram_conf_off = FARX_ACCESS_NVRAM_CONF;
2573 ha->nvram_data_off = FARX_ACCESS_NVRAM_DATA;
2574 } else if (IS_QLA83XX(ha)) {
2575 ha->portnum = PCI_FUNC(ha->pdev->devfn);
2576 ha->max_fibre_devices = MAX_FIBRE_DEVICES_2400;
2577 ha->mbx_count = MAILBOX_REGISTER_COUNT;
2578 req_length = REQUEST_ENTRY_CNT_83XX;
2579 rsp_length = RESPONSE_ENTRY_CNT_83XX;
2580 ha->tgt.atio_q_length = ATIO_ENTRY_CNT_24XX;
2581 ha->max_loop_id = SNS_LAST_LOOP_ID_2300;
2582 ha->init_cb_size = sizeof(struct mid_init_cb_81xx);
2583 ha->gid_list_info_size = 8;
2584 ha->optrom_size = OPTROM_SIZE_83XX;
2585 ha->nvram_npiv_size = QLA_MAX_VPORTS_QLA25XX;
2586 ha->isp_ops = &qla83xx_isp_ops;
2587 ha->flash_conf_off = FARX_ACCESS_FLASH_CONF_81XX;
2588 ha->flash_data_off = FARX_ACCESS_FLASH_DATA_81XX;
2589 ha->nvram_conf_off = ~0;
2590 ha->nvram_data_off = ~0;
2591 } else if (IS_QLAFX00(ha)) {
2592 ha->max_fibre_devices = MAX_FIBRE_DEVICES_FX00;
2593 ha->mbx_count = MAILBOX_REGISTER_COUNT_FX00;
2594 ha->aen_mbx_count = AEN_MAILBOX_REGISTER_COUNT_FX00;
2595 req_length = REQUEST_ENTRY_CNT_FX00;
2596 rsp_length = RESPONSE_ENTRY_CNT_FX00;
2597 ha->isp_ops = &qlafx00_isp_ops;
2598 ha->port_down_retry_count = 30; /* default value */
2599 ha->mr.fw_hbt_cnt = QLAFX00_HEARTBEAT_INTERVAL;
2600 ha->mr.fw_reset_timer_tick = QLAFX00_RESET_INTERVAL;
2601 ha->mr.fw_critemp_timer_tick = QLAFX00_CRITEMP_INTERVAL;
2602 ha->mr.fw_hbt_en = 1;
2603 ha->mr.host_info_resend = false;
2604 ha->mr.hinfo_resend_timer_tick = QLAFX00_HINFO_RESEND_INTERVAL;
2605 } else if (IS_QLA27XX(ha)) {
2606 ha->portnum = PCI_FUNC(ha->pdev->devfn);
2607 ha->max_fibre_devices = MAX_FIBRE_DEVICES_2400;
2608 ha->mbx_count = MAILBOX_REGISTER_COUNT;
2609 req_length = REQUEST_ENTRY_CNT_83XX;
2610 rsp_length = RESPONSE_ENTRY_CNT_83XX;
2611 ha->tgt.atio_q_length = ATIO_ENTRY_CNT_24XX;
2612 ha->max_loop_id = SNS_LAST_LOOP_ID_2300;
2613 ha->init_cb_size = sizeof(struct mid_init_cb_81xx);
2614 ha->gid_list_info_size = 8;
2615 ha->optrom_size = OPTROM_SIZE_83XX;
2616 ha->nvram_npiv_size = QLA_MAX_VPORTS_QLA25XX;
2617 ha->isp_ops = &qla27xx_isp_ops;
2618 ha->flash_conf_off = FARX_ACCESS_FLASH_CONF_81XX;
2619 ha->flash_data_off = FARX_ACCESS_FLASH_DATA_81XX;
2620 ha->nvram_conf_off = ~0;
2621 ha->nvram_data_off = ~0;
2624 ql_dbg_pci(ql_dbg_init, pdev, 0x001e,
2625 "mbx_count=%d, req_length=%d, "
2626 "rsp_length=%d, max_loop_id=%d, init_cb_size=%d, "
2627 "gid_list_info_size=%d, optrom_size=%d, nvram_npiv_size=%d, "
2628 "max_fibre_devices=%d.\n",
2629 ha->mbx_count, req_length, rsp_length, ha->max_loop_id,
2630 ha->init_cb_size, ha->gid_list_info_size, ha->optrom_size,
2631 ha->nvram_npiv_size, ha->max_fibre_devices);
2632 ql_dbg_pci(ql_dbg_init, pdev, 0x001f,
2633 "isp_ops=%p, flash_conf_off=%d, "
2634 "flash_data_off=%d, nvram_conf_off=%d, nvram_data_off=%d.\n",
2635 ha->isp_ops, ha->flash_conf_off, ha->flash_data_off,
2636 ha->nvram_conf_off, ha->nvram_data_off);
2638 /* Configure PCI I/O space */
2639 ret = ha->isp_ops->iospace_config(ha);
2641 goto iospace_config_failed;
2643 ql_log_pci(ql_log_info, pdev, 0x001d,
2644 "Found an ISP%04X irq %d iobase 0x%p.\n",
2645 pdev->device, pdev->irq, ha->iobase);
2646 mutex_init(&ha->vport_lock);
2647 init_completion(&ha->mbx_cmd_comp);
2648 complete(&ha->mbx_cmd_comp);
2649 init_completion(&ha->mbx_intr_comp);
2650 init_completion(&ha->dcbx_comp);
2651 init_completion(&ha->lb_portup_comp);
2653 set_bit(0, (unsigned long *) ha->vp_idx_map);
2655 qla2x00_config_dma_addressing(ha);
2656 ql_dbg_pci(ql_dbg_init, pdev, 0x0020,
2657 "64 Bit addressing is %s.\n",
2658 ha->flags.enable_64bit_addressing ? "enable" :
2660 ret = qla2x00_mem_alloc(ha, req_length, rsp_length, &req, &rsp);
2662 ql_log_pci(ql_log_fatal, pdev, 0x0031,
2663 "Failed to allocate memory for adapter, aborting.\n");
2665 goto probe_hw_failed;
2668 req->max_q_depth = MAX_Q_DEPTH;
2669 if (ql2xmaxqdepth != 0 && ql2xmaxqdepth <= 0xffffU)
2670 req->max_q_depth = ql2xmaxqdepth;
2673 base_vha = qla2x00_create_host(sht, ha);
2676 qla2x00_mem_free(ha);
2677 qla2x00_free_req_que(ha, req);
2678 qla2x00_free_rsp_que(ha, rsp);
2679 goto probe_hw_failed;
2682 pci_set_drvdata(pdev, base_vha);
2683 set_bit(PFLG_DRIVER_PROBING, &base_vha->pci_flags);
2685 host = base_vha->host;
2686 base_vha->req = req;
2687 if (IS_QLA2XXX_MIDTYPE(ha))
2688 base_vha->mgmt_svr_loop_id = 10 + base_vha->vp_idx;
2690 base_vha->mgmt_svr_loop_id = MANAGEMENT_SERVER +
2693 /* Setup fcport template structure. */
2694 ha->mr.fcport.vha = base_vha;
2695 ha->mr.fcport.port_type = FCT_UNKNOWN;
2696 ha->mr.fcport.loop_id = FC_NO_LOOP_ID;
2697 qla2x00_set_fcport_state(&ha->mr.fcport, FCS_UNCONFIGURED);
2698 ha->mr.fcport.supported_classes = FC_COS_UNSPECIFIED;
2699 ha->mr.fcport.scan_state = 1;
2701 /* Set the SG table size based on ISP type */
2702 if (!IS_FWI2_CAPABLE(ha)) {
2704 host->sg_tablesize = 32;
2706 if (!IS_QLA82XX(ha))
2707 host->sg_tablesize = QLA_SG_ALL;
2709 host->max_id = ha->max_fibre_devices;
2710 host->cmd_per_lun = 3;
2711 host->unique_id = host->host_no;
2712 if (IS_T10_PI_CAPABLE(ha) && ql2xenabledif)
2713 host->max_cmd_len = 32;
2715 host->max_cmd_len = MAX_CMDSZ;
2716 host->max_channel = MAX_BUSES - 1;
2717 /* Older HBAs support only 16-bit LUNs */
2718 if (!IS_QLAFX00(ha) && !IS_FWI2_CAPABLE(ha) &&
2719 ql2xmaxlun > 0xffff)
2720 host->max_lun = 0xffff;
2722 host->max_lun = ql2xmaxlun;
2723 host->transportt = qla2xxx_transport_template;
2724 sht->vendor_id = (SCSI_NL_VID_TYPE_PCI | PCI_VENDOR_ID_QLOGIC);
2726 ql_dbg(ql_dbg_init, base_vha, 0x0033,
2727 "max_id=%d this_id=%d "
2728 "cmd_per_len=%d unique_id=%d max_cmd_len=%d max_channel=%d "
2729 "max_lun=%llu transportt=%p, vendor_id=%llu.\n", host->max_id,
2730 host->this_id, host->cmd_per_lun, host->unique_id,
2731 host->max_cmd_len, host->max_channel, host->max_lun,
2732 host->transportt, sht->vendor_id);
2735 /* Alloc arrays of request and response ring ptrs */
2736 if (!qla2x00_alloc_queues(ha, req, rsp)) {
2737 ql_log(ql_log_fatal, base_vha, 0x003d,
2738 "Failed to allocate memory for queue pointers..."
2740 goto probe_init_failed;
2743 qlt_probe_one_stage1(base_vha, ha);
2745 /* Set up the irqs */
2746 ret = qla2x00_request_irqs(ha, rsp);
2748 goto probe_init_failed;
2750 pci_save_state(pdev);
2752 /* Assign back pointers */
2756 if (IS_QLAFX00(ha)) {
2757 ha->rsp_q_map[0] = rsp;
2758 ha->req_q_map[0] = req;
2759 set_bit(0, ha->req_qid_map);
2760 set_bit(0, ha->rsp_qid_map);
2763 /* FWI2-capable only. */
2764 req->req_q_in = &ha->iobase->isp24.req_q_in;
2765 req->req_q_out = &ha->iobase->isp24.req_q_out;
2766 rsp->rsp_q_in = &ha->iobase->isp24.rsp_q_in;
2767 rsp->rsp_q_out = &ha->iobase->isp24.rsp_q_out;
2768 if (ha->mqenable || IS_QLA83XX(ha) || IS_QLA27XX(ha)) {
2769 req->req_q_in = &ha->mqiobase->isp25mq.req_q_in;
2770 req->req_q_out = &ha->mqiobase->isp25mq.req_q_out;
2771 rsp->rsp_q_in = &ha->mqiobase->isp25mq.rsp_q_in;
2772 rsp->rsp_q_out = &ha->mqiobase->isp25mq.rsp_q_out;
2775 if (IS_QLAFX00(ha)) {
2776 req->req_q_in = &ha->iobase->ispfx00.req_q_in;
2777 req->req_q_out = &ha->iobase->ispfx00.req_q_out;
2778 rsp->rsp_q_in = &ha->iobase->ispfx00.rsp_q_in;
2779 rsp->rsp_q_out = &ha->iobase->ispfx00.rsp_q_out;
2782 if (IS_P3P_TYPE(ha)) {
2783 req->req_q_out = &ha->iobase->isp82.req_q_out[0];
2784 rsp->rsp_q_in = &ha->iobase->isp82.rsp_q_in[0];
2785 rsp->rsp_q_out = &ha->iobase->isp82.rsp_q_out[0];
2788 ql_dbg(ql_dbg_multiq, base_vha, 0xc009,
2789 "rsp_q_map=%p req_q_map=%p rsp->req=%p req->rsp=%p.\n",
2790 ha->rsp_q_map, ha->req_q_map, rsp->req, req->rsp);
2791 ql_dbg(ql_dbg_multiq, base_vha, 0xc00a,
2792 "req->req_q_in=%p req->req_q_out=%p "
2793 "rsp->rsp_q_in=%p rsp->rsp_q_out=%p.\n",
2794 req->req_q_in, req->req_q_out,
2795 rsp->rsp_q_in, rsp->rsp_q_out);
2796 ql_dbg(ql_dbg_init, base_vha, 0x003e,
2797 "rsp_q_map=%p req_q_map=%p rsp->req=%p req->rsp=%p.\n",
2798 ha->rsp_q_map, ha->req_q_map, rsp->req, req->rsp);
2799 ql_dbg(ql_dbg_init, base_vha, 0x003f,
2800 "req->req_q_in=%p req->req_q_out=%p rsp->rsp_q_in=%p rsp->rsp_q_out=%p.\n",
2801 req->req_q_in, req->req_q_out, rsp->rsp_q_in, rsp->rsp_q_out);
2803 if (ha->isp_ops->initialize_adapter(base_vha)) {
2804 ql_log(ql_log_fatal, base_vha, 0x00d6,
2805 "Failed to initialize adapter - Adapter flags %x.\n",
2806 base_vha->device_flags);
2808 if (IS_QLA82XX(ha)) {
2809 qla82xx_idc_lock(ha);
2810 qla82xx_wr_32(ha, QLA82XX_CRB_DEV_STATE,
2811 QLA8XXX_DEV_FAILED);
2812 qla82xx_idc_unlock(ha);
2813 ql_log(ql_log_fatal, base_vha, 0x00d7,
2814 "HW State: FAILED.\n");
2815 } else if (IS_QLA8044(ha)) {
2816 qla8044_idc_lock(ha);
2817 qla8044_wr_direct(base_vha,
2818 QLA8044_CRB_DEV_STATE_INDEX,
2819 QLA8XXX_DEV_FAILED);
2820 qla8044_idc_unlock(ha);
2821 ql_log(ql_log_fatal, base_vha, 0x0150,
2822 "HW State: FAILED.\n");
2830 host->can_queue = QLAFX00_MAX_CANQUEUE;
2832 host->can_queue = req->num_outstanding_cmds - 10;
2834 ql_dbg(ql_dbg_init, base_vha, 0x0032,
2835 "can_queue=%d, req=%p, mgmt_svr_loop_id=%d, sg_tablesize=%d.\n",
2836 host->can_queue, base_vha->req,
2837 base_vha->mgmt_svr_loop_id, host->sg_tablesize);
2840 if (qla25xx_setup_mode(base_vha)) {
2841 ql_log(ql_log_warn, base_vha, 0x00ec,
2842 "Failed to create queues, falling back to single queue mode.\n");
2847 if (ha->flags.running_gold_fw)
2851 * Startup the kernel thread for this host adapter
2853 ha->dpc_thread = kthread_create(qla2x00_do_dpc, ha,
2854 "%s_dpc", base_vha->host_str);
2855 if (IS_ERR(ha->dpc_thread)) {
2856 ql_log(ql_log_fatal, base_vha, 0x00ed,
2857 "Failed to start DPC thread.\n");
2858 ret = PTR_ERR(ha->dpc_thread);
2861 ql_dbg(ql_dbg_init, base_vha, 0x00ee,
2862 "DPC thread started successfully.\n");
2865 * If we're not coming up in initiator mode, we might sit for
2866 * a while without waking up the dpc thread, which leads to a
2867 * stuck process warning. So just kick the dpc once here and
2868 * let the kthread start (and go back to sleep in qla2x00_do_dpc).
2870 qla2xxx_wake_dpc(base_vha);
2872 INIT_WORK(&ha->board_disable, qla2x00_disable_board_on_pci_error);
2874 if (IS_QLA8031(ha) || IS_MCTP_CAPABLE(ha)) {
2875 sprintf(wq_name, "qla2xxx_%lu_dpc_lp_wq", base_vha->host_no);
2876 ha->dpc_lp_wq = create_singlethread_workqueue(wq_name);
2877 INIT_WORK(&ha->idc_aen, qla83xx_service_idc_aen);
2879 sprintf(wq_name, "qla2xxx_%lu_dpc_hp_wq", base_vha->host_no);
2880 ha->dpc_hp_wq = create_singlethread_workqueue(wq_name);
2881 INIT_WORK(&ha->nic_core_reset, qla83xx_nic_core_reset_work);
2882 INIT_WORK(&ha->idc_state_handler,
2883 qla83xx_idc_state_handler_work);
2884 INIT_WORK(&ha->nic_core_unrecoverable,
2885 qla83xx_nic_core_unrecoverable_work);
2889 list_add_tail(&base_vha->list, &ha->vp_list);
2890 base_vha->host->irq = ha->pdev->irq;
2892 /* Initialized the timer */
2893 qla2x00_start_timer(base_vha, qla2x00_timer, WATCH_INTERVAL);
2894 ql_dbg(ql_dbg_init, base_vha, 0x00ef,
2895 "Started qla2x00_timer with "
2896 "interval=%d.\n", WATCH_INTERVAL);
2897 ql_dbg(ql_dbg_init, base_vha, 0x00f0,
2898 "Detected hba at address=%p.\n",
2901 if (IS_T10_PI_CAPABLE(ha) && ql2xenabledif) {
2902 if (ha->fw_attributes & BIT_4) {
2903 int prot = 0, guard;
2904 base_vha->flags.difdix_supported = 1;
2905 ql_dbg(ql_dbg_init, base_vha, 0x00f1,
2906 "Registering for DIF/DIX type 1 and 3 protection.\n");
2907 if (ql2xenabledif == 1)
2908 prot = SHOST_DIX_TYPE0_PROTECTION;
2909 scsi_host_set_prot(host,
2910 prot | SHOST_DIF_TYPE1_PROTECTION
2911 | SHOST_DIF_TYPE2_PROTECTION
2912 | SHOST_DIF_TYPE3_PROTECTION
2913 | SHOST_DIX_TYPE1_PROTECTION
2914 | SHOST_DIX_TYPE2_PROTECTION
2915 | SHOST_DIX_TYPE3_PROTECTION);
2917 guard = SHOST_DIX_GUARD_CRC;
2919 if (IS_PI_IPGUARD_CAPABLE(ha) &&
2920 (ql2xenabledif > 1 || IS_PI_DIFB_DIX0_CAPABLE(ha)))
2921 guard |= SHOST_DIX_GUARD_IP;
2923 scsi_host_set_guard(host, guard);
2925 base_vha->flags.difdix_supported = 0;
2928 ha->isp_ops->enable_intrs(ha);
2930 if (IS_QLAFX00(ha)) {
2931 ret = qlafx00_fx_disc(base_vha,
2932 &base_vha->hw->mr.fcport, FXDISC_GET_CONFIG_INFO);
2933 host->sg_tablesize = (ha->mr.extended_io_enabled) ?
2937 ret = scsi_add_host(host, &pdev->dev);
2941 base_vha->flags.init_done = 1;
2942 base_vha->flags.online = 1;
2943 ha->prev_minidump_failed = 0;
2945 ql_dbg(ql_dbg_init, base_vha, 0x00f2,
2946 "Init done and hba is online.\n");
2948 if (qla_ini_mode_enabled(base_vha))
2949 scsi_scan_host(host);
2951 ql_dbg(ql_dbg_init, base_vha, 0x0122,
2952 "skipping scsi_scan_host() for non-initiator port\n");
2954 qla2x00_alloc_sysfs_attr(base_vha);
2956 if (IS_QLAFX00(ha)) {
2957 ret = qlafx00_fx_disc(base_vha,
2958 &base_vha->hw->mr.fcport, FXDISC_GET_PORT_INFO);
2960 /* Register system information */
2961 ret = qlafx00_fx_disc(base_vha,
2962 &base_vha->hw->mr.fcport, FXDISC_REG_HOST_INFO);
2965 qla2x00_init_host_attr(base_vha);
2967 qla2x00_dfs_setup(base_vha);
2969 ql_log(ql_log_info, base_vha, 0x00fb,
2970 "QLogic %s - %s.\n", ha->model_number, ha->model_desc);
2971 ql_log(ql_log_info, base_vha, 0x00fc,
2972 "ISP%04X: %s @ %s hdma%c host#=%ld fw=%s.\n",
2973 pdev->device, ha->isp_ops->pci_info_str(base_vha, pci_info),
2974 pci_name(pdev), ha->flags.enable_64bit_addressing ? '+' : '-',
2976 ha->isp_ops->fw_version_str(base_vha, fw_str, sizeof(fw_str)));
2978 qlt_add_target(ha, base_vha);
2980 clear_bit(PFLG_DRIVER_PROBING, &base_vha->pci_flags);
2982 if (test_bit(UNLOADING, &base_vha->dpc_flags))
2988 qla2x00_free_req_que(ha, req);
2989 ha->req_q_map[0] = NULL;
2990 clear_bit(0, ha->req_qid_map);
2991 qla2x00_free_rsp_que(ha, rsp);
2992 ha->rsp_q_map[0] = NULL;
2993 clear_bit(0, ha->rsp_qid_map);
2994 ha->max_req_queues = ha->max_rsp_queues = 0;
2997 if (base_vha->timer_active)
2998 qla2x00_stop_timer(base_vha);
2999 base_vha->flags.online = 0;
3000 if (ha->dpc_thread) {
3001 struct task_struct *t = ha->dpc_thread;
3003 ha->dpc_thread = NULL;
3007 qla2x00_free_device(base_vha);
3009 scsi_host_put(base_vha->host);
3012 qla2x00_clear_drv_active(ha);
3014 iospace_config_failed:
3015 if (IS_P3P_TYPE(ha)) {
3016 if (!ha->nx_pcibase)
3017 iounmap((device_reg_t *)ha->nx_pcibase);
3019 iounmap((device_reg_t *)ha->nxdb_wr_ptr);
3022 iounmap(ha->iobase);
3024 iounmap(ha->cregbase);
3026 pci_release_selected_regions(ha->pdev, ha->bars);
3031 pci_disable_device(pdev);
3036 qla2x00_shutdown(struct pci_dev *pdev)
3038 scsi_qla_host_t *vha;
3039 struct qla_hw_data *ha;
3041 if (!atomic_read(&pdev->enable_cnt))
3044 vha = pci_get_drvdata(pdev);
3047 /* Notify ISPFX00 firmware */
3049 qlafx00_driver_shutdown(vha, 20);
3051 /* Turn-off FCE trace */
3052 if (ha->flags.fce_enabled) {
3053 qla2x00_disable_fce_trace(vha, NULL, NULL);
3054 ha->flags.fce_enabled = 0;
3057 /* Turn-off EFT trace */
3059 qla2x00_disable_eft_trace(vha);
3061 /* Stop currently executing firmware. */
3062 qla2x00_try_to_stop_firmware(vha);
3065 if (vha->timer_active)
3066 qla2x00_stop_timer(vha);
3068 /* Turn adapter off line */
3069 vha->flags.online = 0;
3071 /* turn-off interrupts on the card */
3072 if (ha->interrupts_on) {
3073 vha->flags.init_done = 0;
3074 ha->isp_ops->disable_intrs(ha);
3077 qla2x00_free_irqs(vha);
3079 qla2x00_free_fw_dump(ha);
3081 pci_disable_pcie_error_reporting(pdev);
3082 pci_disable_device(pdev);
3085 /* Deletes all the virtual ports for a given ha */
3087 qla2x00_delete_all_vps(struct qla_hw_data *ha, scsi_qla_host_t *base_vha)
3089 scsi_qla_host_t *vha;
3090 unsigned long flags;
3092 mutex_lock(&ha->vport_lock);
3093 while (ha->cur_vport_count) {
3094 spin_lock_irqsave(&ha->vport_slock, flags);
3096 BUG_ON(base_vha->list.next == &ha->vp_list);
3097 /* This assumes first entry in ha->vp_list is always base vha */
3098 vha = list_first_entry(&base_vha->list, scsi_qla_host_t, list);
3099 scsi_host_get(vha->host);
3101 spin_unlock_irqrestore(&ha->vport_slock, flags);
3102 mutex_unlock(&ha->vport_lock);
3104 fc_vport_terminate(vha->fc_vport);
3105 scsi_host_put(vha->host);
3107 mutex_lock(&ha->vport_lock);
3109 mutex_unlock(&ha->vport_lock);
3112 /* Stops all deferred work threads */
3114 qla2x00_destroy_deferred_work(struct qla_hw_data *ha)
3116 /* Flush the work queue and remove it */
3118 flush_workqueue(ha->wq);
3119 destroy_workqueue(ha->wq);
3123 /* Cancel all work and destroy DPC workqueues */
3124 if (ha->dpc_lp_wq) {
3125 cancel_work_sync(&ha->idc_aen);
3126 destroy_workqueue(ha->dpc_lp_wq);
3127 ha->dpc_lp_wq = NULL;
3130 if (ha->dpc_hp_wq) {
3131 cancel_work_sync(&ha->nic_core_reset);
3132 cancel_work_sync(&ha->idc_state_handler);
3133 cancel_work_sync(&ha->nic_core_unrecoverable);
3134 destroy_workqueue(ha->dpc_hp_wq);
3135 ha->dpc_hp_wq = NULL;
3138 /* Kill the kernel thread for this host */
3139 if (ha->dpc_thread) {
3140 struct task_struct *t = ha->dpc_thread;
3143 * qla2xxx_wake_dpc checks for ->dpc_thread
3144 * so we need to zero it out.
3146 ha->dpc_thread = NULL;
3152 qla2x00_unmap_iobases(struct qla_hw_data *ha)
3154 if (IS_QLA82XX(ha)) {
3156 iounmap((device_reg_t *)ha->nx_pcibase);
3158 iounmap((device_reg_t *)ha->nxdb_wr_ptr);
3161 iounmap(ha->iobase);
3164 iounmap(ha->cregbase);
3167 iounmap(ha->mqiobase);
3169 if ((IS_QLA83XX(ha) || IS_QLA27XX(ha)) && ha->msixbase)
3170 iounmap(ha->msixbase);
3175 qla2x00_clear_drv_active(struct qla_hw_data *ha)
3177 if (IS_QLA8044(ha)) {
3178 qla8044_idc_lock(ha);
3179 qla8044_clear_drv_active(ha);
3180 qla8044_idc_unlock(ha);
3181 } else if (IS_QLA82XX(ha)) {
3182 qla82xx_idc_lock(ha);
3183 qla82xx_clear_drv_active(ha);
3184 qla82xx_idc_unlock(ha);
3189 qla2x00_remove_one(struct pci_dev *pdev)
3191 scsi_qla_host_t *base_vha;
3192 struct qla_hw_data *ha;
3194 base_vha = pci_get_drvdata(pdev);
3197 /* Indicate device removal to prevent future board_disable and wait
3198 * until any pending board_disable has completed. */
3199 set_bit(PFLG_DRIVER_REMOVING, &base_vha->pci_flags);
3200 cancel_work_sync(&ha->board_disable);
3203 * If the PCI device is disabled then there was a PCI-disconnect and
3204 * qla2x00_disable_board_on_pci_error has taken care of most of the
3207 if (!atomic_read(&pdev->enable_cnt)) {
3208 scsi_host_put(base_vha->host);
3210 pci_set_drvdata(pdev, NULL);
3214 qla2x00_wait_for_hba_ready(base_vha);
3216 /* if UNLOAD flag is already set, then continue unload,
3217 * where it was set first.
3219 if (test_bit(UNLOADING, &base_vha->dpc_flags))
3222 set_bit(UNLOADING, &base_vha->dpc_flags);
3225 qlafx00_driver_shutdown(base_vha, 20);
3227 qla2x00_delete_all_vps(ha, base_vha);
3229 if (IS_QLA8031(ha)) {
3230 ql_dbg(ql_dbg_p3p, base_vha, 0xb07e,
3231 "Clearing fcoe driver presence.\n");
3232 if (qla83xx_clear_drv_presence(base_vha) != QLA_SUCCESS)
3233 ql_dbg(ql_dbg_p3p, base_vha, 0xb079,
3234 "Error while clearing DRV-Presence.\n");
3237 qla2x00_abort_all_cmds(base_vha, DID_NO_CONNECT << 16);
3239 qla2x00_dfs_remove(base_vha);
3241 qla84xx_put_chip(base_vha);
3243 /* Laser should be disabled only for ISP2031 */
3245 qla83xx_disable_laser(base_vha);
3248 if (base_vha->timer_active)
3249 qla2x00_stop_timer(base_vha);
3251 base_vha->flags.online = 0;
3253 /* free DMA memory */
3254 if (ha->exlogin_buf)
3255 qla2x00_free_exlogin_buffer(ha);
3257 /* free DMA memory */
3258 if (ha->exchoffld_buf)
3259 qla2x00_free_exchoffld_buffer(ha);
3261 qla2x00_destroy_deferred_work(ha);
3263 qlt_remove_target(ha, base_vha);
3265 qla2x00_free_sysfs_attr(base_vha, true);
3267 fc_remove_host(base_vha->host);
3269 scsi_remove_host(base_vha->host);
3271 qla2x00_free_device(base_vha);
3273 qla2x00_clear_drv_active(ha);
3275 scsi_host_put(base_vha->host);
3277 qla2x00_unmap_iobases(ha);
3279 pci_release_selected_regions(ha->pdev, ha->bars);
3283 pci_disable_pcie_error_reporting(pdev);
3285 pci_disable_device(pdev);
3289 qla2x00_free_device(scsi_qla_host_t *vha)
3291 struct qla_hw_data *ha = vha->hw;
3293 qla2x00_abort_all_cmds(vha, DID_NO_CONNECT << 16);
3296 if (vha->timer_active)
3297 qla2x00_stop_timer(vha);
3299 qla25xx_delete_queues(vha);
3301 if (ha->flags.fce_enabled)
3302 qla2x00_disable_fce_trace(vha, NULL, NULL);
3305 qla2x00_disable_eft_trace(vha);
3307 /* Stop currently executing firmware. */
3308 qla2x00_try_to_stop_firmware(vha);
3310 vha->flags.online = 0;
3312 /* turn-off interrupts on the card */
3313 if (ha->interrupts_on) {
3314 vha->flags.init_done = 0;
3315 ha->isp_ops->disable_intrs(ha);
3318 qla2x00_free_irqs(vha);
3320 qla2x00_free_fcports(vha);
3322 qla2x00_mem_free(ha);
3324 qla82xx_md_free(vha);
3326 qla2x00_free_queues(ha);
3329 void qla2x00_free_fcports(struct scsi_qla_host *vha)
3331 fc_port_t *fcport, *tfcport;
3333 list_for_each_entry_safe(fcport, tfcport, &vha->vp_fcports, list) {
3334 list_del(&fcport->list);
3335 qla2x00_clear_loop_id(fcport);
3342 qla2x00_schedule_rport_del(struct scsi_qla_host *vha, fc_port_t *fcport,
3345 struct fc_rport *rport;
3346 scsi_qla_host_t *base_vha;
3347 unsigned long flags;
3352 rport = fcport->rport;
3354 base_vha = pci_get_drvdata(vha->hw->pdev);
3355 spin_lock_irqsave(vha->host->host_lock, flags);
3356 fcport->drport = rport;
3357 spin_unlock_irqrestore(vha->host->host_lock, flags);
3358 qlt_do_generation_tick(vha, &base_vha->total_fcport_update_gen);
3359 set_bit(FCPORT_UPDATE_NEEDED, &base_vha->dpc_flags);
3360 qla2xxx_wake_dpc(base_vha);
3364 fc_remote_port_delete(rport);
3365 qlt_do_generation_tick(vha, &now);
3366 qlt_fc_port_deleted(vha, fcport, now);
3371 * qla2x00_mark_device_lost Updates fcport state when device goes offline.
3373 * Input: ha = adapter block pointer. fcport = port structure pointer.
3379 void qla2x00_mark_device_lost(scsi_qla_host_t *vha, fc_port_t *fcport,
3380 int do_login, int defer)
3382 if (IS_QLAFX00(vha->hw)) {
3383 qla2x00_set_fcport_state(fcport, FCS_DEVICE_LOST);
3384 qla2x00_schedule_rport_del(vha, fcport, defer);
3388 if (atomic_read(&fcport->state) == FCS_ONLINE &&
3389 vha->vp_idx == fcport->vha->vp_idx) {
3390 qla2x00_set_fcport_state(fcport, FCS_DEVICE_LOST);
3391 qla2x00_schedule_rport_del(vha, fcport, defer);
3394 * We may need to retry the login, so don't change the state of the
3395 * port but do the retries.
3397 if (atomic_read(&fcport->state) != FCS_DEVICE_DEAD)
3398 qla2x00_set_fcport_state(fcport, FCS_DEVICE_LOST);
3403 set_bit(RELOGIN_NEEDED, &vha->dpc_flags);
3405 if (fcport->login_retry == 0) {
3406 fcport->login_retry = vha->hw->login_retry_count;
3408 ql_dbg(ql_dbg_disc, vha, 0x2067,
3409 "Port login retry %8phN, id = 0x%04x retry cnt=%d.\n",
3410 fcport->port_name, fcport->loop_id, fcport->login_retry);
3415 * qla2x00_mark_all_devices_lost
3416 * Updates fcport state when device goes offline.
3419 * ha = adapter block pointer.
3420 * fcport = port structure pointer.
3428 qla2x00_mark_all_devices_lost(scsi_qla_host_t *vha, int defer)
3432 list_for_each_entry(fcport, &vha->vp_fcports, list) {
3433 if (vha->vp_idx != 0 && vha->vp_idx != fcport->vha->vp_idx)
3437 * No point in marking the device as lost, if the device is
3440 if (atomic_read(&fcport->state) == FCS_DEVICE_DEAD)
3442 if (atomic_read(&fcport->state) == FCS_ONLINE) {
3443 qla2x00_set_fcport_state(fcport, FCS_DEVICE_LOST);
3445 qla2x00_schedule_rport_del(vha, fcport, defer);
3446 else if (vha->vp_idx == fcport->vha->vp_idx)
3447 qla2x00_schedule_rport_del(vha, fcport, defer);
3454 * Allocates adapter memory.
3461 qla2x00_mem_alloc(struct qla_hw_data *ha, uint16_t req_len, uint16_t rsp_len,
3462 struct req_que **req, struct rsp_que **rsp)
3466 ha->init_cb = dma_alloc_coherent(&ha->pdev->dev, ha->init_cb_size,
3467 &ha->init_cb_dma, GFP_KERNEL);
3471 if (qlt_mem_alloc(ha) < 0)
3472 goto fail_free_init_cb;
3474 ha->gid_list = dma_alloc_coherent(&ha->pdev->dev,
3475 qla2x00_gid_list_size(ha), &ha->gid_list_dma, GFP_KERNEL);
3477 goto fail_free_tgt_mem;
3479 ha->srb_mempool = mempool_create_slab_pool(SRB_MIN_REQ, srb_cachep);
3480 if (!ha->srb_mempool)
3481 goto fail_free_gid_list;
3483 if (IS_P3P_TYPE(ha)) {
3484 /* Allocate cache for CT6 Ctx. */
3486 ctx_cachep = kmem_cache_create("qla2xxx_ctx",
3487 sizeof(struct ct6_dsd), 0,
3488 SLAB_HWCACHE_ALIGN, NULL);
3490 goto fail_free_srb_mempool;
3492 ha->ctx_mempool = mempool_create_slab_pool(SRB_MIN_REQ,
3494 if (!ha->ctx_mempool)
3495 goto fail_free_srb_mempool;
3496 ql_dbg_pci(ql_dbg_init, ha->pdev, 0x0021,
3497 "ctx_cachep=%p ctx_mempool=%p.\n",
3498 ctx_cachep, ha->ctx_mempool);
3501 /* Get memory for cached NVRAM */
3502 ha->nvram = kzalloc(MAX_NVRAM_SIZE, GFP_KERNEL);
3504 goto fail_free_ctx_mempool;
3506 snprintf(name, sizeof(name), "%s_%d", QLA2XXX_DRIVER_NAME,
3508 ha->s_dma_pool = dma_pool_create(name, &ha->pdev->dev,
3509 DMA_POOL_SIZE, 8, 0);
3510 if (!ha->s_dma_pool)
3511 goto fail_free_nvram;
3513 ql_dbg_pci(ql_dbg_init, ha->pdev, 0x0022,
3514 "init_cb=%p gid_list=%p, srb_mempool=%p s_dma_pool=%p.\n",
3515 ha->init_cb, ha->gid_list, ha->srb_mempool, ha->s_dma_pool);
3517 if (IS_P3P_TYPE(ha) || ql2xenabledif) {
3518 ha->dl_dma_pool = dma_pool_create(name, &ha->pdev->dev,
3519 DSD_LIST_DMA_POOL_SIZE, 8, 0);
3520 if (!ha->dl_dma_pool) {
3521 ql_log_pci(ql_log_fatal, ha->pdev, 0x0023,
3522 "Failed to allocate memory for dl_dma_pool.\n");
3523 goto fail_s_dma_pool;
3526 ha->fcp_cmnd_dma_pool = dma_pool_create(name, &ha->pdev->dev,
3527 FCP_CMND_DMA_POOL_SIZE, 8, 0);
3528 if (!ha->fcp_cmnd_dma_pool) {
3529 ql_log_pci(ql_log_fatal, ha->pdev, 0x0024,
3530 "Failed to allocate memory for fcp_cmnd_dma_pool.\n");
3531 goto fail_dl_dma_pool;
3533 ql_dbg_pci(ql_dbg_init, ha->pdev, 0x0025,
3534 "dl_dma_pool=%p fcp_cmnd_dma_pool=%p.\n",
3535 ha->dl_dma_pool, ha->fcp_cmnd_dma_pool);
3538 /* Allocate memory for SNS commands */
3539 if (IS_QLA2100(ha) || IS_QLA2200(ha)) {
3540 /* Get consistent memory allocated for SNS commands */
3541 ha->sns_cmd = dma_alloc_coherent(&ha->pdev->dev,
3542 sizeof(struct sns_cmd_pkt), &ha->sns_cmd_dma, GFP_KERNEL);
3545 ql_dbg_pci(ql_dbg_init, ha->pdev, 0x0026,
3546 "sns_cmd: %p.\n", ha->sns_cmd);
3548 /* Get consistent memory allocated for MS IOCB */
3549 ha->ms_iocb = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL,
3553 /* Get consistent memory allocated for CT SNS commands */
3554 ha->ct_sns = dma_alloc_coherent(&ha->pdev->dev,
3555 sizeof(struct ct_sns_pkt), &ha->ct_sns_dma, GFP_KERNEL);
3557 goto fail_free_ms_iocb;
3558 ql_dbg_pci(ql_dbg_init, ha->pdev, 0x0027,
3559 "ms_iocb=%p ct_sns=%p.\n",
3560 ha->ms_iocb, ha->ct_sns);
3563 /* Allocate memory for request ring */
3564 *req = kzalloc(sizeof(struct req_que), GFP_KERNEL);
3566 ql_log_pci(ql_log_fatal, ha->pdev, 0x0028,
3567 "Failed to allocate memory for req.\n");
3570 (*req)->length = req_len;
3571 (*req)->ring = dma_alloc_coherent(&ha->pdev->dev,
3572 ((*req)->length + 1) * sizeof(request_t),
3573 &(*req)->dma, GFP_KERNEL);
3574 if (!(*req)->ring) {
3575 ql_log_pci(ql_log_fatal, ha->pdev, 0x0029,
3576 "Failed to allocate memory for req_ring.\n");
3579 /* Allocate memory for response ring */
3580 *rsp = kzalloc(sizeof(struct rsp_que), GFP_KERNEL);
3582 ql_log_pci(ql_log_fatal, ha->pdev, 0x002a,
3583 "Failed to allocate memory for rsp.\n");
3587 (*rsp)->length = rsp_len;
3588 (*rsp)->ring = dma_alloc_coherent(&ha->pdev->dev,
3589 ((*rsp)->length + 1) * sizeof(response_t),
3590 &(*rsp)->dma, GFP_KERNEL);
3591 if (!(*rsp)->ring) {
3592 ql_log_pci(ql_log_fatal, ha->pdev, 0x002b,
3593 "Failed to allocate memory for rsp_ring.\n");
3598 ql_dbg_pci(ql_dbg_init, ha->pdev, 0x002c,
3599 "req=%p req->length=%d req->ring=%p rsp=%p "
3600 "rsp->length=%d rsp->ring=%p.\n",
3601 *req, (*req)->length, (*req)->ring, *rsp, (*rsp)->length,
3603 /* Allocate memory for NVRAM data for vports */
3604 if (ha->nvram_npiv_size) {
3605 ha->npiv_info = kzalloc(sizeof(struct qla_npiv_entry) *
3606 ha->nvram_npiv_size, GFP_KERNEL);
3607 if (!ha->npiv_info) {
3608 ql_log_pci(ql_log_fatal, ha->pdev, 0x002d,
3609 "Failed to allocate memory for npiv_info.\n");
3610 goto fail_npiv_info;
3613 ha->npiv_info = NULL;
3615 /* Get consistent memory allocated for EX-INIT-CB. */
3616 if (IS_CNA_CAPABLE(ha) || IS_QLA2031(ha) || IS_QLA27XX(ha)) {
3617 ha->ex_init_cb = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL,
3618 &ha->ex_init_cb_dma);
3619 if (!ha->ex_init_cb)
3620 goto fail_ex_init_cb;
3621 ql_dbg_pci(ql_dbg_init, ha->pdev, 0x002e,
3622 "ex_init_cb=%p.\n", ha->ex_init_cb);
3625 INIT_LIST_HEAD(&ha->gbl_dsd_list);
3627 /* Get consistent memory allocated for Async Port-Database. */
3628 if (!IS_FWI2_CAPABLE(ha)) {
3629 ha->async_pd = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL,
3633 ql_dbg_pci(ql_dbg_init, ha->pdev, 0x002f,
3634 "async_pd=%p.\n", ha->async_pd);
3637 INIT_LIST_HEAD(&ha->vp_list);
3639 /* Allocate memory for our loop_id bitmap */
3640 ha->loop_id_map = kzalloc(BITS_TO_LONGS(LOOPID_MAP_SIZE) * sizeof(long),
3642 if (!ha->loop_id_map)
3643 goto fail_loop_id_map;
3645 qla2x00_set_reserved_loop_ids(ha);
3646 ql_dbg_pci(ql_dbg_init, ha->pdev, 0x0123,
3647 "loop_id_map=%p.\n", ha->loop_id_map);
3653 dma_pool_free(ha->s_dma_pool, ha->async_pd, ha->async_pd_dma);
3655 dma_pool_free(ha->s_dma_pool, ha->ex_init_cb, ha->ex_init_cb_dma);
3657 kfree(ha->npiv_info);
3659 dma_free_coherent(&ha->pdev->dev, ((*rsp)->length + 1) *
3660 sizeof(response_t), (*rsp)->ring, (*rsp)->dma);
3661 (*rsp)->ring = NULL;
3666 dma_free_coherent(&ha->pdev->dev, ((*req)->length + 1) *
3667 sizeof(request_t), (*req)->ring, (*req)->dma);
3668 (*req)->ring = NULL;
3673 dma_free_coherent(&ha->pdev->dev, sizeof(struct ct_sns_pkt),
3674 ha->ct_sns, ha->ct_sns_dma);
3678 dma_pool_free(ha->s_dma_pool, ha->ms_iocb, ha->ms_iocb_dma);
3680 ha->ms_iocb_dma = 0;
3683 dma_free_coherent(&ha->pdev->dev, sizeof(struct sns_cmd_pkt),
3684 ha->sns_cmd, ha->sns_cmd_dma);
3686 if (IS_QLA82XX(ha) || ql2xenabledif) {
3687 dma_pool_destroy(ha->fcp_cmnd_dma_pool);
3688 ha->fcp_cmnd_dma_pool = NULL;
3691 if (IS_QLA82XX(ha) || ql2xenabledif) {
3692 dma_pool_destroy(ha->dl_dma_pool);
3693 ha->dl_dma_pool = NULL;
3696 dma_pool_destroy(ha->s_dma_pool);
3697 ha->s_dma_pool = NULL;
3701 fail_free_ctx_mempool:
3702 if (ha->ctx_mempool)
3703 mempool_destroy(ha->ctx_mempool);
3704 ha->ctx_mempool = NULL;
3705 fail_free_srb_mempool:
3706 if (ha->srb_mempool)
3707 mempool_destroy(ha->srb_mempool);
3708 ha->srb_mempool = NULL;
3710 dma_free_coherent(&ha->pdev->dev, qla2x00_gid_list_size(ha),
3713 ha->gid_list = NULL;
3714 ha->gid_list_dma = 0;
3718 dma_free_coherent(&ha->pdev->dev, ha->init_cb_size, ha->init_cb,
3721 ha->init_cb_dma = 0;
3723 ql_log(ql_log_fatal, NULL, 0x0030,
3724 "Memory allocation failure.\n");
3729 qla2x00_set_exlogins_buffer(scsi_qla_host_t *vha)
3732 uint16_t size, max_cnt, temp;
3733 struct qla_hw_data *ha = vha->hw;
3735 /* Return if we don't need to alloacate any extended logins */
3739 ql_log(ql_log_info, vha, 0xd021, "EXLOGIN count: %d.\n", ql2xexlogins);
3741 rval = qla_get_exlogin_status(vha, &size, &max_cnt);
3742 if (rval != QLA_SUCCESS) {
3743 ql_log_pci(ql_log_fatal, ha->pdev, 0xd029,
3744 "Failed to get exlogin status.\n");
3748 temp = (ql2xexlogins > max_cnt) ? max_cnt : ql2xexlogins;
3749 ha->exlogin_size = (size * temp);
3750 ql_log(ql_log_info, vha, 0xd024,
3751 "EXLOGIN: max_logins=%d, portdb=0x%x, total=%d.\n",
3752 max_cnt, size, temp);
3754 ql_log(ql_log_info, vha, 0xd025, "EXLOGIN: requested size=0x%x\n",
3757 /* Get consistent memory for extended logins */
3758 ha->exlogin_buf = dma_alloc_coherent(&ha->pdev->dev,
3759 ha->exlogin_size, &ha->exlogin_buf_dma, GFP_KERNEL);
3760 if (!ha->exlogin_buf) {
3761 ql_log_pci(ql_log_fatal, ha->pdev, 0xd02a,
3762 "Failed to allocate memory for exlogin_buf_dma.\n");
3766 /* Now configure the dma buffer */
3767 rval = qla_set_exlogin_mem_cfg(vha, ha->exlogin_buf_dma);
3769 ql_log(ql_log_fatal, vha, 0x00cf,
3770 "Setup extended login buffer ****FAILED****.\n");
3771 qla2x00_free_exlogin_buffer(ha);
3778 * qla2x00_free_exlogin_buffer
3781 * ha = adapter block pointer
3784 qla2x00_free_exlogin_buffer(struct qla_hw_data *ha)
3786 if (ha->exlogin_buf) {
3787 dma_free_coherent(&ha->pdev->dev, ha->exlogin_size,
3788 ha->exlogin_buf, ha->exlogin_buf_dma);
3789 ha->exlogin_buf = NULL;
3790 ha->exlogin_size = 0;
3795 qla2x00_set_exchoffld_buffer(scsi_qla_host_t *vha)
3798 uint16_t size, max_cnt, temp;
3799 struct qla_hw_data *ha = vha->hw;
3801 /* Return if we don't need to alloacate any extended logins */
3805 ql_log(ql_log_info, vha, 0xd014,
3806 "Exchange offload count: %d.\n", ql2xexlogins);
3809 rval = qla_get_exchoffld_status(vha, &size, &max_cnt);
3810 if (rval != QLA_SUCCESS) {
3811 ql_log_pci(ql_log_fatal, ha->pdev, 0xd012,
3812 "Failed to get exlogin status.\n");
3816 temp = (ql2xexchoffld > max_cnt) ? max_cnt : ql2xexchoffld;
3817 ha->exchoffld_size = (size * temp);
3818 ql_log(ql_log_info, vha, 0xd016,
3819 "Exchange offload: max_count=%d, buffers=0x%x, total=%d.\n",
3820 max_cnt, size, temp);
3822 ql_log(ql_log_info, vha, 0xd017,
3823 "Exchange Buffers requested size = 0x%x\n", ha->exchoffld_size);
3825 /* Get consistent memory for extended logins */
3826 ha->exchoffld_buf = dma_alloc_coherent(&ha->pdev->dev,
3827 ha->exchoffld_size, &ha->exchoffld_buf_dma, GFP_KERNEL);
3828 if (!ha->exchoffld_buf) {
3829 ql_log_pci(ql_log_fatal, ha->pdev, 0xd013,
3830 "Failed to allocate memory for exchoffld_buf_dma.\n");
3834 /* Now configure the dma buffer */
3835 rval = qla_set_exchoffld_mem_cfg(vha, ha->exchoffld_buf_dma);
3837 ql_log(ql_log_fatal, vha, 0xd02e,
3838 "Setup exchange offload buffer ****FAILED****.\n");
3839 qla2x00_free_exchoffld_buffer(ha);
3846 * qla2x00_free_exchoffld_buffer
3849 * ha = adapter block pointer
3852 qla2x00_free_exchoffld_buffer(struct qla_hw_data *ha)
3854 if (ha->exchoffld_buf) {
3855 dma_free_coherent(&ha->pdev->dev, ha->exchoffld_size,
3856 ha->exchoffld_buf, ha->exchoffld_buf_dma);
3857 ha->exchoffld_buf = NULL;
3858 ha->exchoffld_size = 0;
3863 * qla2x00_free_fw_dump
3864 * Frees fw dump stuff.
3867 * ha = adapter block pointer
3870 qla2x00_free_fw_dump(struct qla_hw_data *ha)
3873 dma_free_coherent(&ha->pdev->dev,
3874 FCE_SIZE, ha->fce, ha->fce_dma);
3877 dma_free_coherent(&ha->pdev->dev,
3878 EFT_SIZE, ha->eft, ha->eft_dma);
3882 if (ha->fw_dump_template)
3883 vfree(ha->fw_dump_template);
3890 ha->fw_dump_cap_flags = 0;
3891 ha->fw_dump_reading = 0;
3893 ha->fw_dump_len = 0;
3894 ha->fw_dump_template = NULL;
3895 ha->fw_dump_template_len = 0;
3900 * Frees all adapter allocated memory.
3903 * ha = adapter block pointer.
3906 qla2x00_mem_free(struct qla_hw_data *ha)
3908 qla2x00_free_fw_dump(ha);
3911 dma_free_coherent(&ha->pdev->dev, MCTP_DUMP_SIZE, ha->mctp_dump,
3914 if (ha->srb_mempool)
3915 mempool_destroy(ha->srb_mempool);
3918 dma_free_coherent(&ha->pdev->dev, DCBX_TLV_DATA_SIZE,
3919 ha->dcbx_tlv, ha->dcbx_tlv_dma);
3922 dma_free_coherent(&ha->pdev->dev, XGMAC_DATA_SIZE,
3923 ha->xgmac_data, ha->xgmac_data_dma);
3926 dma_free_coherent(&ha->pdev->dev, sizeof(struct sns_cmd_pkt),
3927 ha->sns_cmd, ha->sns_cmd_dma);
3930 dma_free_coherent(&ha->pdev->dev, sizeof(struct ct_sns_pkt),
3931 ha->ct_sns, ha->ct_sns_dma);
3934 dma_pool_free(ha->s_dma_pool, ha->sfp_data, ha->sfp_data_dma);
3937 dma_pool_free(ha->s_dma_pool, ha->ms_iocb, ha->ms_iocb_dma);
3940 dma_pool_free(ha->s_dma_pool,
3941 ha->ex_init_cb, ha->ex_init_cb_dma);
3944 dma_pool_free(ha->s_dma_pool, ha->async_pd, ha->async_pd_dma);
3947 dma_pool_destroy(ha->s_dma_pool);
3950 dma_free_coherent(&ha->pdev->dev, qla2x00_gid_list_size(ha),
3951 ha->gid_list, ha->gid_list_dma);
3953 if (IS_QLA82XX(ha)) {
3954 if (!list_empty(&ha->gbl_dsd_list)) {
3955 struct dsd_dma *dsd_ptr, *tdsd_ptr;
3957 /* clean up allocated prev pool */
3958 list_for_each_entry_safe(dsd_ptr,
3959 tdsd_ptr, &ha->gbl_dsd_list, list) {
3960 dma_pool_free(ha->dl_dma_pool,
3961 dsd_ptr->dsd_addr, dsd_ptr->dsd_list_dma);
3962 list_del(&dsd_ptr->list);
3968 if (ha->dl_dma_pool)
3969 dma_pool_destroy(ha->dl_dma_pool);
3971 if (ha->fcp_cmnd_dma_pool)
3972 dma_pool_destroy(ha->fcp_cmnd_dma_pool);
3974 if (ha->ctx_mempool)
3975 mempool_destroy(ha->ctx_mempool);
3980 dma_free_coherent(&ha->pdev->dev, ha->init_cb_size,
3981 ha->init_cb, ha->init_cb_dma);
3982 vfree(ha->optrom_buffer);
3984 kfree(ha->npiv_info);
3986 kfree(ha->loop_id_map);
3988 ha->srb_mempool = NULL;
3989 ha->ctx_mempool = NULL;
3991 ha->sns_cmd_dma = 0;
3995 ha->ms_iocb_dma = 0;
3997 ha->init_cb_dma = 0;
3998 ha->ex_init_cb = NULL;
3999 ha->ex_init_cb_dma = 0;
4000 ha->async_pd = NULL;
4001 ha->async_pd_dma = 0;
4003 ha->s_dma_pool = NULL;
4004 ha->dl_dma_pool = NULL;
4005 ha->fcp_cmnd_dma_pool = NULL;
4007 ha->gid_list = NULL;
4008 ha->gid_list_dma = 0;
4010 ha->tgt.atio_ring = NULL;
4011 ha->tgt.atio_dma = 0;
4012 ha->tgt.tgt_vp_map = NULL;
4015 struct scsi_qla_host *qla2x00_create_host(struct scsi_host_template *sht,
4016 struct qla_hw_data *ha)
4018 struct Scsi_Host *host;
4019 struct scsi_qla_host *vha = NULL;
4021 host = scsi_host_alloc(sht, sizeof(scsi_qla_host_t));
4023 ql_log_pci(ql_log_fatal, ha->pdev, 0x0107,
4024 "Failed to allocate host from the scsi layer, aborting.\n");
4028 /* Clear our data area */
4029 vha = shost_priv(host);
4030 memset(vha, 0, sizeof(scsi_qla_host_t));
4033 vha->host_no = host->host_no;
4036 INIT_LIST_HEAD(&vha->vp_fcports);
4037 INIT_LIST_HEAD(&vha->work_list);
4038 INIT_LIST_HEAD(&vha->list);
4039 INIT_LIST_HEAD(&vha->qla_cmd_list);
4040 INIT_LIST_HEAD(&vha->qla_sess_op_cmd_list);
4041 INIT_LIST_HEAD(&vha->logo_list);
4042 INIT_LIST_HEAD(&vha->plogi_ack_list);
4044 spin_lock_init(&vha->work_lock);
4045 spin_lock_init(&vha->cmd_list_lock);
4046 init_waitqueue_head(&vha->vref_waitq);
4048 sprintf(vha->host_str, "%s_%ld", QLA2XXX_DRIVER_NAME, vha->host_no);
4049 ql_dbg(ql_dbg_init, vha, 0x0041,
4050 "Allocated the host=%p hw=%p vha=%p dev_name=%s",
4051 vha->host, vha->hw, vha,
4052 dev_name(&(ha->pdev->dev)));
4060 static struct qla_work_evt *
4061 qla2x00_alloc_work(struct scsi_qla_host *vha, enum qla_work_type type)
4063 struct qla_work_evt *e;
4066 QLA_VHA_MARK_BUSY(vha, bail);
4070 e = kzalloc(sizeof(struct qla_work_evt), GFP_ATOMIC);
4072 QLA_VHA_MARK_NOT_BUSY(vha);
4076 INIT_LIST_HEAD(&e->list);
4078 e->flags = QLA_EVT_FLAG_FREE;
4083 qla2x00_post_work(struct scsi_qla_host *vha, struct qla_work_evt *e)
4085 unsigned long flags;
4087 spin_lock_irqsave(&vha->work_lock, flags);
4088 list_add_tail(&e->list, &vha->work_list);
4089 spin_unlock_irqrestore(&vha->work_lock, flags);
4090 qla2xxx_wake_dpc(vha);
4096 qla2x00_post_aen_work(struct scsi_qla_host *vha, enum fc_host_event_code code,
4099 struct qla_work_evt *e;
4101 e = qla2x00_alloc_work(vha, QLA_EVT_AEN);
4103 return QLA_FUNCTION_FAILED;
4105 e->u.aen.code = code;
4106 e->u.aen.data = data;
4107 return qla2x00_post_work(vha, e);
4111 qla2x00_post_idc_ack_work(struct scsi_qla_host *vha, uint16_t *mb)
4113 struct qla_work_evt *e;
4115 e = qla2x00_alloc_work(vha, QLA_EVT_IDC_ACK);
4117 return QLA_FUNCTION_FAILED;
4119 memcpy(e->u.idc_ack.mb, mb, QLA_IDC_ACK_REGS * sizeof(uint16_t));
4120 return qla2x00_post_work(vha, e);
4123 #define qla2x00_post_async_work(name, type) \
4124 int qla2x00_post_async_##name##_work( \
4125 struct scsi_qla_host *vha, \
4126 fc_port_t *fcport, uint16_t *data) \
4128 struct qla_work_evt *e; \
4130 e = qla2x00_alloc_work(vha, type); \
4132 return QLA_FUNCTION_FAILED; \
4134 e->u.logio.fcport = fcport; \
4136 e->u.logio.data[0] = data[0]; \
4137 e->u.logio.data[1] = data[1]; \
4139 return qla2x00_post_work(vha, e); \
4142 qla2x00_post_async_work(login, QLA_EVT_ASYNC_LOGIN);
4143 qla2x00_post_async_work(login_done, QLA_EVT_ASYNC_LOGIN_DONE);
4144 qla2x00_post_async_work(logout, QLA_EVT_ASYNC_LOGOUT);
4145 qla2x00_post_async_work(logout_done, QLA_EVT_ASYNC_LOGOUT_DONE);
4146 qla2x00_post_async_work(adisc, QLA_EVT_ASYNC_ADISC);
4147 qla2x00_post_async_work(adisc_done, QLA_EVT_ASYNC_ADISC_DONE);
4150 qla2x00_post_uevent_work(struct scsi_qla_host *vha, u32 code)
4152 struct qla_work_evt *e;
4154 e = qla2x00_alloc_work(vha, QLA_EVT_UEVENT);
4156 return QLA_FUNCTION_FAILED;
4158 e->u.uevent.code = code;
4159 return qla2x00_post_work(vha, e);
4163 qla2x00_uevent_emit(struct scsi_qla_host *vha, u32 code)
4165 char event_string[40];
4166 char *envp[] = { event_string, NULL };
4169 case QLA_UEVENT_CODE_FW_DUMP:
4170 snprintf(event_string, sizeof(event_string), "FW_DUMP=%ld",
4177 kobject_uevent_env(&vha->hw->pdev->dev.kobj, KOBJ_CHANGE, envp);
4181 qlafx00_post_aenfx_work(struct scsi_qla_host *vha, uint32_t evtcode,
4182 uint32_t *data, int cnt)
4184 struct qla_work_evt *e;
4186 e = qla2x00_alloc_work(vha, QLA_EVT_AENFX);
4188 return QLA_FUNCTION_FAILED;
4190 e->u.aenfx.evtcode = evtcode;
4191 e->u.aenfx.count = cnt;
4192 memcpy(e->u.aenfx.mbx, data, sizeof(*data) * cnt);
4193 return qla2x00_post_work(vha, e);
4197 qla2x00_do_work(struct scsi_qla_host *vha)
4199 struct qla_work_evt *e, *tmp;
4200 unsigned long flags;
4203 spin_lock_irqsave(&vha->work_lock, flags);
4204 list_splice_init(&vha->work_list, &work);
4205 spin_unlock_irqrestore(&vha->work_lock, flags);
4207 list_for_each_entry_safe(e, tmp, &work, list) {
4208 list_del_init(&e->list);
4212 fc_host_post_event(vha->host, fc_get_event_number(),
4213 e->u.aen.code, e->u.aen.data);
4215 case QLA_EVT_IDC_ACK:
4216 qla81xx_idc_ack(vha, e->u.idc_ack.mb);
4218 case QLA_EVT_ASYNC_LOGIN:
4219 qla2x00_async_login(vha, e->u.logio.fcport,
4222 case QLA_EVT_ASYNC_LOGIN_DONE:
4223 qla2x00_async_login_done(vha, e->u.logio.fcport,
4226 case QLA_EVT_ASYNC_LOGOUT:
4227 qla2x00_async_logout(vha, e->u.logio.fcport);
4229 case QLA_EVT_ASYNC_LOGOUT_DONE:
4230 qla2x00_async_logout_done(vha, e->u.logio.fcport,
4233 case QLA_EVT_ASYNC_ADISC:
4234 qla2x00_async_adisc(vha, e->u.logio.fcport,
4237 case QLA_EVT_ASYNC_ADISC_DONE:
4238 qla2x00_async_adisc_done(vha, e->u.logio.fcport,
4241 case QLA_EVT_UEVENT:
4242 qla2x00_uevent_emit(vha, e->u.uevent.code);
4245 qlafx00_process_aen(vha, e);
4248 if (e->flags & QLA_EVT_FLAG_FREE)
4251 /* For each work completed decrement vha ref count */
4252 QLA_VHA_MARK_NOT_BUSY(vha);
4256 /* Relogins all the fcports of a vport
4257 * Context: dpc thread
4259 void qla2x00_relogin(struct scsi_qla_host *vha)
4263 uint16_t next_loopid = 0;
4264 struct qla_hw_data *ha = vha->hw;
4267 list_for_each_entry(fcport, &vha->vp_fcports, list) {
4269 * If the port is not ONLINE then try to login
4270 * to it if we haven't run out of retries.
4272 if (atomic_read(&fcport->state) != FCS_ONLINE &&
4273 fcport->login_retry && !(fcport->flags & FCF_ASYNC_SENT)) {
4274 fcport->login_retry--;
4275 if (fcport->flags & FCF_FABRIC_DEVICE) {
4276 if (fcport->flags & FCF_FCP2_DEVICE)
4277 ha->isp_ops->fabric_logout(vha,
4279 fcport->d_id.b.domain,
4280 fcport->d_id.b.area,
4281 fcport->d_id.b.al_pa);
4283 if (fcport->loop_id == FC_NO_LOOP_ID) {
4284 fcport->loop_id = next_loopid =
4285 ha->min_external_loopid;
4286 status = qla2x00_find_new_loop_id(
4288 if (status != QLA_SUCCESS) {
4289 /* Ran out of IDs to use */
4294 if (IS_ALOGIO_CAPABLE(ha)) {
4295 fcport->flags |= FCF_ASYNC_SENT;
4297 data[1] = QLA_LOGIO_LOGIN_RETRIED;
4298 status = qla2x00_post_async_login_work(
4300 if (status == QLA_SUCCESS)
4302 /* Attempt a retry. */
4305 status = qla2x00_fabric_login(vha,
4306 fcport, &next_loopid);
4307 if (status == QLA_SUCCESS) {
4316 qla2x00_get_port_database(
4318 if (status2 != QLA_SUCCESS)
4323 status = qla2x00_local_device_login(vha,
4326 if (status == QLA_SUCCESS) {
4327 fcport->old_loop_id = fcport->loop_id;
4329 ql_dbg(ql_dbg_disc, vha, 0x2003,
4330 "Port login OK: logged in ID 0x%x.\n",
4333 qla2x00_update_fcport(vha, fcport);
4335 } else if (status == 1) {
4336 set_bit(RELOGIN_NEEDED, &vha->dpc_flags);
4337 /* retry the login again */
4338 ql_dbg(ql_dbg_disc, vha, 0x2007,
4339 "Retrying %d login again loop_id 0x%x.\n",
4340 fcport->login_retry, fcport->loop_id);
4342 fcport->login_retry = 0;
4345 if (fcport->login_retry == 0 && status != QLA_SUCCESS)
4346 qla2x00_clear_loop_id(fcport);
4348 if (test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags))
4353 /* Schedule work on any of the dpc-workqueues */
4355 qla83xx_schedule_work(scsi_qla_host_t *base_vha, int work_code)
4357 struct qla_hw_data *ha = base_vha->hw;
4359 switch (work_code) {
4360 case MBA_IDC_AEN: /* 0x8200 */
4362 queue_work(ha->dpc_lp_wq, &ha->idc_aen);
4365 case QLA83XX_NIC_CORE_RESET: /* 0x1 */
4366 if (!ha->flags.nic_core_reset_hdlr_active) {
4368 queue_work(ha->dpc_hp_wq, &ha->nic_core_reset);
4370 ql_dbg(ql_dbg_p3p, base_vha, 0xb05e,
4371 "NIC Core reset is already active. Skip "
4372 "scheduling it again.\n");
4374 case QLA83XX_IDC_STATE_HANDLER: /* 0x2 */
4376 queue_work(ha->dpc_hp_wq, &ha->idc_state_handler);
4378 case QLA83XX_NIC_CORE_UNRECOVERABLE: /* 0x3 */
4380 queue_work(ha->dpc_hp_wq, &ha->nic_core_unrecoverable);
4383 ql_log(ql_log_warn, base_vha, 0xb05f,
4384 "Unknown work-code=0x%x.\n", work_code);
4390 /* Work: Perform NIC Core Unrecoverable state handling */
4392 qla83xx_nic_core_unrecoverable_work(struct work_struct *work)
4394 struct qla_hw_data *ha =
4395 container_of(work, struct qla_hw_data, nic_core_unrecoverable);
4396 scsi_qla_host_t *base_vha = pci_get_drvdata(ha->pdev);
4397 uint32_t dev_state = 0;
4399 qla83xx_idc_lock(base_vha, 0);
4400 qla83xx_rd_reg(base_vha, QLA83XX_IDC_DEV_STATE, &dev_state);
4401 qla83xx_reset_ownership(base_vha);
4402 if (ha->flags.nic_core_reset_owner) {
4403 ha->flags.nic_core_reset_owner = 0;
4404 qla83xx_wr_reg(base_vha, QLA83XX_IDC_DEV_STATE,
4405 QLA8XXX_DEV_FAILED);
4406 ql_log(ql_log_info, base_vha, 0xb060, "HW State: FAILED.\n");
4407 qla83xx_schedule_work(base_vha, QLA83XX_IDC_STATE_HANDLER);
4409 qla83xx_idc_unlock(base_vha, 0);
4412 /* Work: Execute IDC state handler */
4414 qla83xx_idc_state_handler_work(struct work_struct *work)
4416 struct qla_hw_data *ha =
4417 container_of(work, struct qla_hw_data, idc_state_handler);
4418 scsi_qla_host_t *base_vha = pci_get_drvdata(ha->pdev);
4419 uint32_t dev_state = 0;
4421 qla83xx_idc_lock(base_vha, 0);
4422 qla83xx_rd_reg(base_vha, QLA83XX_IDC_DEV_STATE, &dev_state);
4423 if (dev_state == QLA8XXX_DEV_FAILED ||
4424 dev_state == QLA8XXX_DEV_NEED_QUIESCENT)
4425 qla83xx_idc_state_handler(base_vha);
4426 qla83xx_idc_unlock(base_vha, 0);
4430 qla83xx_check_nic_core_fw_alive(scsi_qla_host_t *base_vha)
4432 int rval = QLA_SUCCESS;
4433 unsigned long heart_beat_wait = jiffies + (1 * HZ);
4434 uint32_t heart_beat_counter1, heart_beat_counter2;
4437 if (time_after(jiffies, heart_beat_wait)) {
4438 ql_dbg(ql_dbg_p3p, base_vha, 0xb07c,
4439 "Nic Core f/w is not alive.\n");
4440 rval = QLA_FUNCTION_FAILED;
4444 qla83xx_idc_lock(base_vha, 0);
4445 qla83xx_rd_reg(base_vha, QLA83XX_FW_HEARTBEAT,
4446 &heart_beat_counter1);
4447 qla83xx_idc_unlock(base_vha, 0);
4449 qla83xx_idc_lock(base_vha, 0);
4450 qla83xx_rd_reg(base_vha, QLA83XX_FW_HEARTBEAT,
4451 &heart_beat_counter2);
4452 qla83xx_idc_unlock(base_vha, 0);
4453 } while (heart_beat_counter1 == heart_beat_counter2);
4458 /* Work: Perform NIC Core Reset handling */
4460 qla83xx_nic_core_reset_work(struct work_struct *work)
4462 struct qla_hw_data *ha =
4463 container_of(work, struct qla_hw_data, nic_core_reset);
4464 scsi_qla_host_t *base_vha = pci_get_drvdata(ha->pdev);
4465 uint32_t dev_state = 0;
4467 if (IS_QLA2031(ha)) {
4468 if (qla2xxx_mctp_dump(base_vha) != QLA_SUCCESS)
4469 ql_log(ql_log_warn, base_vha, 0xb081,
4470 "Failed to dump mctp\n");
4474 if (!ha->flags.nic_core_reset_hdlr_active) {
4475 if (qla83xx_check_nic_core_fw_alive(base_vha) == QLA_SUCCESS) {
4476 qla83xx_idc_lock(base_vha, 0);
4477 qla83xx_rd_reg(base_vha, QLA83XX_IDC_DEV_STATE,
4479 qla83xx_idc_unlock(base_vha, 0);
4480 if (dev_state != QLA8XXX_DEV_NEED_RESET) {
4481 ql_dbg(ql_dbg_p3p, base_vha, 0xb07a,
4482 "Nic Core f/w is alive.\n");
4487 ha->flags.nic_core_reset_hdlr_active = 1;
4488 if (qla83xx_nic_core_reset(base_vha)) {
4489 /* NIC Core reset failed. */
4490 ql_dbg(ql_dbg_p3p, base_vha, 0xb061,
4491 "NIC Core reset failed.\n");
4493 ha->flags.nic_core_reset_hdlr_active = 0;
4497 /* Work: Handle 8200 IDC aens */
4499 qla83xx_service_idc_aen(struct work_struct *work)
4501 struct qla_hw_data *ha =
4502 container_of(work, struct qla_hw_data, idc_aen);
4503 scsi_qla_host_t *base_vha = pci_get_drvdata(ha->pdev);
4504 uint32_t dev_state, idc_control;
4506 qla83xx_idc_lock(base_vha, 0);
4507 qla83xx_rd_reg(base_vha, QLA83XX_IDC_DEV_STATE, &dev_state);
4508 qla83xx_rd_reg(base_vha, QLA83XX_IDC_CONTROL, &idc_control);
4509 qla83xx_idc_unlock(base_vha, 0);
4510 if (dev_state == QLA8XXX_DEV_NEED_RESET) {
4511 if (idc_control & QLA83XX_IDC_GRACEFUL_RESET) {
4512 ql_dbg(ql_dbg_p3p, base_vha, 0xb062,
4513 "Application requested NIC Core Reset.\n");
4514 qla83xx_schedule_work(base_vha, QLA83XX_NIC_CORE_RESET);
4515 } else if (qla83xx_check_nic_core_fw_alive(base_vha) ==
4517 ql_dbg(ql_dbg_p3p, base_vha, 0xb07b,
4518 "Other protocol driver requested NIC Core Reset.\n");
4519 qla83xx_schedule_work(base_vha, QLA83XX_NIC_CORE_RESET);
4521 } else if (dev_state == QLA8XXX_DEV_FAILED ||
4522 dev_state == QLA8XXX_DEV_NEED_QUIESCENT) {
4523 qla83xx_schedule_work(base_vha, QLA83XX_IDC_STATE_HANDLER);
4528 qla83xx_wait_logic(void)
4533 if (!in_interrupt()) {
4535 * Wait about 200ms before retrying again.
4536 * This controls the number of retries for single
4542 for (i = 0; i < 20; i++)
4543 cpu_relax(); /* This a nop instr on i386 */
4548 qla83xx_force_lock_recovery(scsi_qla_host_t *base_vha)
4552 uint32_t idc_lck_rcvry_stage_mask = 0x3;
4553 uint32_t idc_lck_rcvry_owner_mask = 0x3c;
4554 struct qla_hw_data *ha = base_vha->hw;
4555 ql_dbg(ql_dbg_p3p, base_vha, 0xb086,
4556 "Trying force recovery of the IDC lock.\n");
4558 rval = qla83xx_rd_reg(base_vha, QLA83XX_IDC_LOCK_RECOVERY, &data);
4562 if ((data & idc_lck_rcvry_stage_mask) > 0) {
4565 data = (IDC_LOCK_RECOVERY_STAGE1) | (ha->portnum << 2);
4566 rval = qla83xx_wr_reg(base_vha, QLA83XX_IDC_LOCK_RECOVERY,
4573 rval = qla83xx_rd_reg(base_vha, QLA83XX_IDC_LOCK_RECOVERY,
4578 if (((data & idc_lck_rcvry_owner_mask) >> 2) == ha->portnum) {
4579 data &= (IDC_LOCK_RECOVERY_STAGE2 |
4580 ~(idc_lck_rcvry_stage_mask));
4581 rval = qla83xx_wr_reg(base_vha,
4582 QLA83XX_IDC_LOCK_RECOVERY, data);
4586 /* Forcefully perform IDC UnLock */
4587 rval = qla83xx_rd_reg(base_vha, QLA83XX_DRIVER_UNLOCK,
4591 /* Clear lock-id by setting 0xff */
4592 rval = qla83xx_wr_reg(base_vha, QLA83XX_DRIVER_LOCKID,
4596 /* Clear lock-recovery by setting 0x0 */
4597 rval = qla83xx_wr_reg(base_vha,
4598 QLA83XX_IDC_LOCK_RECOVERY, 0x0);
4609 qla83xx_idc_lock_recovery(scsi_qla_host_t *base_vha)
4611 int rval = QLA_SUCCESS;
4612 uint32_t o_drv_lockid, n_drv_lockid;
4613 unsigned long lock_recovery_timeout;
4615 lock_recovery_timeout = jiffies + QLA83XX_MAX_LOCK_RECOVERY_WAIT;
4617 rval = qla83xx_rd_reg(base_vha, QLA83XX_DRIVER_LOCKID, &o_drv_lockid);
4621 /* MAX wait time before forcing IDC Lock recovery = 2 secs */
4622 if (time_after_eq(jiffies, lock_recovery_timeout)) {
4623 if (qla83xx_force_lock_recovery(base_vha) == QLA_SUCCESS)
4626 return QLA_FUNCTION_FAILED;
4629 rval = qla83xx_rd_reg(base_vha, QLA83XX_DRIVER_LOCKID, &n_drv_lockid);
4633 if (o_drv_lockid == n_drv_lockid) {
4634 qla83xx_wait_logic();
4644 qla83xx_idc_lock(scsi_qla_host_t *base_vha, uint16_t requester_id)
4646 uint16_t options = (requester_id << 15) | BIT_6;
4648 uint32_t lock_owner;
4649 struct qla_hw_data *ha = base_vha->hw;
4651 /* IDC-lock implementation using driver-lock/lock-id remote registers */
4653 if (qla83xx_rd_reg(base_vha, QLA83XX_DRIVER_LOCK, &data)
4656 /* Setting lock-id to our function-number */
4657 qla83xx_wr_reg(base_vha, QLA83XX_DRIVER_LOCKID,
4660 qla83xx_rd_reg(base_vha, QLA83XX_DRIVER_LOCKID,
4662 ql_dbg(ql_dbg_p3p, base_vha, 0xb063,
4663 "Failed to acquire IDC lock, acquired by %d, "
4664 "retrying...\n", lock_owner);
4666 /* Retry/Perform IDC-Lock recovery */
4667 if (qla83xx_idc_lock_recovery(base_vha)
4669 qla83xx_wait_logic();
4672 ql_log(ql_log_warn, base_vha, 0xb075,
4673 "IDC Lock recovery FAILED.\n");
4680 /* XXX: IDC-lock implementation using access-control mbx */
4682 if (qla83xx_access_control(base_vha, options, 0, 0, NULL)) {
4683 ql_dbg(ql_dbg_p3p, base_vha, 0xb072,
4684 "Failed to acquire IDC lock. retrying...\n");
4685 /* Retry/Perform IDC-Lock recovery */
4686 if (qla83xx_idc_lock_recovery(base_vha) == QLA_SUCCESS) {
4687 qla83xx_wait_logic();
4690 ql_log(ql_log_warn, base_vha, 0xb076,
4691 "IDC Lock recovery FAILED.\n");
4698 qla83xx_idc_unlock(scsi_qla_host_t *base_vha, uint16_t requester_id)
4701 uint16_t options = (requester_id << 15) | BIT_7;
4705 struct qla_hw_data *ha = base_vha->hw;
4707 /* IDC-unlock implementation using driver-unlock/lock-id
4712 if (qla83xx_rd_reg(base_vha, QLA83XX_DRIVER_LOCKID, &data)
4714 if (data == ha->portnum) {
4715 qla83xx_rd_reg(base_vha, QLA83XX_DRIVER_UNLOCK, &data);
4716 /* Clearing lock-id by setting 0xff */
4717 qla83xx_wr_reg(base_vha, QLA83XX_DRIVER_LOCKID, 0xff);
4718 } else if (retry < 10) {
4719 /* SV: XXX: IDC unlock retrying needed here? */
4721 /* Retry for IDC-unlock */
4722 qla83xx_wait_logic();
4724 ql_dbg(ql_dbg_p3p, base_vha, 0xb064,
4725 "Failed to release IDC lock, retrying=%d\n", retry);
4728 } else if (retry < 10) {
4729 /* Retry for IDC-unlock */
4730 qla83xx_wait_logic();
4732 ql_dbg(ql_dbg_p3p, base_vha, 0xb065,
4733 "Failed to read drv-lockid, retrying=%d\n", retry);
4740 /* XXX: IDC-unlock implementation using access-control mbx */
4743 if (qla83xx_access_control(base_vha, options, 0, 0, NULL)) {
4745 /* Retry for IDC-unlock */
4746 qla83xx_wait_logic();
4748 ql_dbg(ql_dbg_p3p, base_vha, 0xb066,
4749 "Failed to release IDC lock, retrying=%d\n", retry);
4759 __qla83xx_set_drv_presence(scsi_qla_host_t *vha)
4761 int rval = QLA_SUCCESS;
4762 struct qla_hw_data *ha = vha->hw;
4763 uint32_t drv_presence;
4765 rval = qla83xx_rd_reg(vha, QLA83XX_IDC_DRV_PRESENCE, &drv_presence);
4766 if (rval == QLA_SUCCESS) {
4767 drv_presence |= (1 << ha->portnum);
4768 rval = qla83xx_wr_reg(vha, QLA83XX_IDC_DRV_PRESENCE,
4776 qla83xx_set_drv_presence(scsi_qla_host_t *vha)
4778 int rval = QLA_SUCCESS;
4780 qla83xx_idc_lock(vha, 0);
4781 rval = __qla83xx_set_drv_presence(vha);
4782 qla83xx_idc_unlock(vha, 0);
4788 __qla83xx_clear_drv_presence(scsi_qla_host_t *vha)
4790 int rval = QLA_SUCCESS;
4791 struct qla_hw_data *ha = vha->hw;
4792 uint32_t drv_presence;
4794 rval = qla83xx_rd_reg(vha, QLA83XX_IDC_DRV_PRESENCE, &drv_presence);
4795 if (rval == QLA_SUCCESS) {
4796 drv_presence &= ~(1 << ha->portnum);
4797 rval = qla83xx_wr_reg(vha, QLA83XX_IDC_DRV_PRESENCE,
4805 qla83xx_clear_drv_presence(scsi_qla_host_t *vha)
4807 int rval = QLA_SUCCESS;
4809 qla83xx_idc_lock(vha, 0);
4810 rval = __qla83xx_clear_drv_presence(vha);
4811 qla83xx_idc_unlock(vha, 0);
4817 qla83xx_need_reset_handler(scsi_qla_host_t *vha)
4819 struct qla_hw_data *ha = vha->hw;
4820 uint32_t drv_ack, drv_presence;
4821 unsigned long ack_timeout;
4823 /* Wait for IDC ACK from all functions (DRV-ACK == DRV-PRESENCE) */
4824 ack_timeout = jiffies + (ha->fcoe_reset_timeout * HZ);
4826 qla83xx_rd_reg(vha, QLA83XX_IDC_DRIVER_ACK, &drv_ack);
4827 qla83xx_rd_reg(vha, QLA83XX_IDC_DRV_PRESENCE, &drv_presence);
4828 if ((drv_ack & drv_presence) == drv_presence)
4831 if (time_after_eq(jiffies, ack_timeout)) {
4832 ql_log(ql_log_warn, vha, 0xb067,
4833 "RESET ACK TIMEOUT! drv_presence=0x%x "
4834 "drv_ack=0x%x\n", drv_presence, drv_ack);
4836 * The function(s) which did not ack in time are forced
4837 * to withdraw any further participation in the IDC
4840 if (drv_ack != drv_presence)
4841 qla83xx_wr_reg(vha, QLA83XX_IDC_DRV_PRESENCE,
4846 qla83xx_idc_unlock(vha, 0);
4848 qla83xx_idc_lock(vha, 0);
4851 qla83xx_wr_reg(vha, QLA83XX_IDC_DEV_STATE, QLA8XXX_DEV_COLD);
4852 ql_log(ql_log_info, vha, 0xb068, "HW State: COLD/RE-INIT.\n");
4856 qla83xx_device_bootstrap(scsi_qla_host_t *vha)
4858 int rval = QLA_SUCCESS;
4859 uint32_t idc_control;
4861 qla83xx_wr_reg(vha, QLA83XX_IDC_DEV_STATE, QLA8XXX_DEV_INITIALIZING);
4862 ql_log(ql_log_info, vha, 0xb069, "HW State: INITIALIZING.\n");
4864 /* Clearing IDC-Control Graceful-Reset Bit before resetting f/w */
4865 __qla83xx_get_idc_control(vha, &idc_control);
4866 idc_control &= ~QLA83XX_IDC_GRACEFUL_RESET;
4867 __qla83xx_set_idc_control(vha, 0);
4869 qla83xx_idc_unlock(vha, 0);
4870 rval = qla83xx_restart_nic_firmware(vha);
4871 qla83xx_idc_lock(vha, 0);
4873 if (rval != QLA_SUCCESS) {
4874 ql_log(ql_log_fatal, vha, 0xb06a,
4875 "Failed to restart NIC f/w.\n");
4876 qla83xx_wr_reg(vha, QLA83XX_IDC_DEV_STATE, QLA8XXX_DEV_FAILED);
4877 ql_log(ql_log_info, vha, 0xb06b, "HW State: FAILED.\n");
4879 ql_dbg(ql_dbg_p3p, vha, 0xb06c,
4880 "Success in restarting nic f/w.\n");
4881 qla83xx_wr_reg(vha, QLA83XX_IDC_DEV_STATE, QLA8XXX_DEV_READY);
4882 ql_log(ql_log_info, vha, 0xb06d, "HW State: READY.\n");
4888 /* Assumes idc_lock always held on entry */
4890 qla83xx_idc_state_handler(scsi_qla_host_t *base_vha)
4892 struct qla_hw_data *ha = base_vha->hw;
4893 int rval = QLA_SUCCESS;
4894 unsigned long dev_init_timeout;
4897 /* Wait for MAX-INIT-TIMEOUT for the device to go ready */
4898 dev_init_timeout = jiffies + (ha->fcoe_dev_init_timeout * HZ);
4902 if (time_after_eq(jiffies, dev_init_timeout)) {
4903 ql_log(ql_log_warn, base_vha, 0xb06e,
4904 "Initialization TIMEOUT!\n");
4905 /* Init timeout. Disable further NIC Core
4908 qla83xx_wr_reg(base_vha, QLA83XX_IDC_DEV_STATE,
4909 QLA8XXX_DEV_FAILED);
4910 ql_log(ql_log_info, base_vha, 0xb06f,
4911 "HW State: FAILED.\n");
4914 qla83xx_rd_reg(base_vha, QLA83XX_IDC_DEV_STATE, &dev_state);
4915 switch (dev_state) {
4916 case QLA8XXX_DEV_READY:
4917 if (ha->flags.nic_core_reset_owner)
4918 qla83xx_idc_audit(base_vha,
4919 IDC_AUDIT_COMPLETION);
4920 ha->flags.nic_core_reset_owner = 0;
4921 ql_dbg(ql_dbg_p3p, base_vha, 0xb070,
4922 "Reset_owner reset by 0x%x.\n",
4925 case QLA8XXX_DEV_COLD:
4926 if (ha->flags.nic_core_reset_owner)
4927 rval = qla83xx_device_bootstrap(base_vha);
4929 /* Wait for AEN to change device-state */
4930 qla83xx_idc_unlock(base_vha, 0);
4932 qla83xx_idc_lock(base_vha, 0);
4935 case QLA8XXX_DEV_INITIALIZING:
4936 /* Wait for AEN to change device-state */
4937 qla83xx_idc_unlock(base_vha, 0);
4939 qla83xx_idc_lock(base_vha, 0);
4941 case QLA8XXX_DEV_NEED_RESET:
4942 if (!ql2xdontresethba && ha->flags.nic_core_reset_owner)
4943 qla83xx_need_reset_handler(base_vha);
4945 /* Wait for AEN to change device-state */
4946 qla83xx_idc_unlock(base_vha, 0);
4948 qla83xx_idc_lock(base_vha, 0);
4950 /* reset timeout value after need reset handler */
4951 dev_init_timeout = jiffies +
4952 (ha->fcoe_dev_init_timeout * HZ);
4954 case QLA8XXX_DEV_NEED_QUIESCENT:
4955 /* XXX: DEBUG for now */
4956 qla83xx_idc_unlock(base_vha, 0);
4958 qla83xx_idc_lock(base_vha, 0);
4960 case QLA8XXX_DEV_QUIESCENT:
4961 /* XXX: DEBUG for now */
4962 if (ha->flags.quiesce_owner)
4965 qla83xx_idc_unlock(base_vha, 0);
4967 qla83xx_idc_lock(base_vha, 0);
4968 dev_init_timeout = jiffies +
4969 (ha->fcoe_dev_init_timeout * HZ);
4971 case QLA8XXX_DEV_FAILED:
4972 if (ha->flags.nic_core_reset_owner)
4973 qla83xx_idc_audit(base_vha,
4974 IDC_AUDIT_COMPLETION);
4975 ha->flags.nic_core_reset_owner = 0;
4976 __qla83xx_clear_drv_presence(base_vha);
4977 qla83xx_idc_unlock(base_vha, 0);
4978 qla8xxx_dev_failed_handler(base_vha);
4979 rval = QLA_FUNCTION_FAILED;
4980 qla83xx_idc_lock(base_vha, 0);
4982 case QLA8XXX_BAD_VALUE:
4983 qla83xx_idc_unlock(base_vha, 0);
4985 qla83xx_idc_lock(base_vha, 0);
4988 ql_log(ql_log_warn, base_vha, 0xb071,
4989 "Unknown Device State: %x.\n", dev_state);
4990 qla83xx_idc_unlock(base_vha, 0);
4991 qla8xxx_dev_failed_handler(base_vha);
4992 rval = QLA_FUNCTION_FAILED;
4993 qla83xx_idc_lock(base_vha, 0);
5003 qla2x00_disable_board_on_pci_error(struct work_struct *work)
5005 struct qla_hw_data *ha = container_of(work, struct qla_hw_data,
5007 struct pci_dev *pdev = ha->pdev;
5008 scsi_qla_host_t *base_vha = pci_get_drvdata(ha->pdev);
5010 /* if UNLOAD flag is already set, then continue unload,
5011 * where it was set first.
5013 if (test_bit(UNLOADING, &base_vha->dpc_flags))
5016 ql_log(ql_log_warn, base_vha, 0x015b,
5017 "Disabling adapter.\n");
5019 set_bit(UNLOADING, &base_vha->dpc_flags);
5021 qla2x00_delete_all_vps(ha, base_vha);
5023 qla2x00_abort_all_cmds(base_vha, DID_NO_CONNECT << 16);
5025 qla2x00_dfs_remove(base_vha);
5027 qla84xx_put_chip(base_vha);
5029 if (base_vha->timer_active)
5030 qla2x00_stop_timer(base_vha);
5032 base_vha->flags.online = 0;
5034 qla2x00_destroy_deferred_work(ha);
5037 * Do not try to stop beacon blink as it will issue a mailbox
5040 qla2x00_free_sysfs_attr(base_vha, false);
5042 fc_remove_host(base_vha->host);
5044 scsi_remove_host(base_vha->host);
5046 base_vha->flags.init_done = 0;
5047 qla25xx_delete_queues(base_vha);
5048 qla2x00_free_irqs(base_vha);
5049 qla2x00_free_fcports(base_vha);
5050 qla2x00_mem_free(ha);
5051 qla82xx_md_free(base_vha);
5052 qla2x00_free_queues(ha);
5054 qla2x00_unmap_iobases(ha);
5056 pci_release_selected_regions(ha->pdev, ha->bars);
5057 pci_disable_pcie_error_reporting(pdev);
5058 pci_disable_device(pdev);
5061 * Let qla2x00_remove_one cleanup qla_hw_data on device removal.
5065 /**************************************************************************
5067 * This kernel thread is a task that is schedule by the interrupt handler
5068 * to perform the background processing for interrupts.
5071 * This task always run in the context of a kernel thread. It
5072 * is kick-off by the driver's detect code and starts up
5073 * up one per adapter. It immediately goes to sleep and waits for
5074 * some fibre event. When either the interrupt handler or
5075 * the timer routine detects a event it will one of the task
5076 * bits then wake us up.
5077 **************************************************************************/
5079 qla2x00_do_dpc(void *data)
5081 scsi_qla_host_t *base_vha;
5082 struct qla_hw_data *ha;
5084 ha = (struct qla_hw_data *)data;
5085 base_vha = pci_get_drvdata(ha->pdev);
5087 set_user_nice(current, MIN_NICE);
5089 set_current_state(TASK_INTERRUPTIBLE);
5090 while (!kthread_should_stop()) {
5091 ql_dbg(ql_dbg_dpc, base_vha, 0x4000,
5092 "DPC handler sleeping.\n");
5096 if (!base_vha->flags.init_done || ha->flags.mbox_busy)
5099 if (ha->flags.eeh_busy) {
5100 ql_dbg(ql_dbg_dpc, base_vha, 0x4003,
5101 "eeh_busy=%d.\n", ha->flags.eeh_busy);
5107 ql_dbg(ql_dbg_dpc + ql_dbg_verbose, base_vha, 0x4001,
5108 "DPC handler waking up, dpc_flags=0x%lx.\n",
5109 base_vha->dpc_flags);
5111 if (test_bit(UNLOADING, &base_vha->dpc_flags))
5114 qla2x00_do_work(base_vha);
5116 if (IS_P3P_TYPE(ha)) {
5117 if (IS_QLA8044(ha)) {
5118 if (test_and_clear_bit(ISP_UNRECOVERABLE,
5119 &base_vha->dpc_flags)) {
5120 qla8044_idc_lock(ha);
5121 qla8044_wr_direct(base_vha,
5122 QLA8044_CRB_DEV_STATE_INDEX,
5123 QLA8XXX_DEV_FAILED);
5124 qla8044_idc_unlock(ha);
5125 ql_log(ql_log_info, base_vha, 0x4004,
5126 "HW State: FAILED.\n");
5127 qla8044_device_state_handler(base_vha);
5132 if (test_and_clear_bit(ISP_UNRECOVERABLE,
5133 &base_vha->dpc_flags)) {
5134 qla82xx_idc_lock(ha);
5135 qla82xx_wr_32(ha, QLA82XX_CRB_DEV_STATE,
5136 QLA8XXX_DEV_FAILED);
5137 qla82xx_idc_unlock(ha);
5138 ql_log(ql_log_info, base_vha, 0x0151,
5139 "HW State: FAILED.\n");
5140 qla82xx_device_state_handler(base_vha);
5145 if (test_and_clear_bit(FCOE_CTX_RESET_NEEDED,
5146 &base_vha->dpc_flags)) {
5148 ql_dbg(ql_dbg_dpc, base_vha, 0x4005,
5149 "FCoE context reset scheduled.\n");
5150 if (!(test_and_set_bit(ABORT_ISP_ACTIVE,
5151 &base_vha->dpc_flags))) {
5152 if (qla82xx_fcoe_ctx_reset(base_vha)) {
5153 /* FCoE-ctx reset failed.
5154 * Escalate to chip-reset
5156 set_bit(ISP_ABORT_NEEDED,
5157 &base_vha->dpc_flags);
5159 clear_bit(ABORT_ISP_ACTIVE,
5160 &base_vha->dpc_flags);
5163 ql_dbg(ql_dbg_dpc, base_vha, 0x4006,
5164 "FCoE context reset end.\n");
5166 } else if (IS_QLAFX00(ha)) {
5167 if (test_and_clear_bit(ISP_UNRECOVERABLE,
5168 &base_vha->dpc_flags)) {
5169 ql_dbg(ql_dbg_dpc, base_vha, 0x4020,
5170 "Firmware Reset Recovery\n");
5171 if (qlafx00_reset_initialize(base_vha)) {
5172 /* Failed. Abort isp later. */
5173 if (!test_bit(UNLOADING,
5174 &base_vha->dpc_flags)) {
5175 set_bit(ISP_UNRECOVERABLE,
5176 &base_vha->dpc_flags);
5177 ql_dbg(ql_dbg_dpc, base_vha,
5179 "Reset Recovery Failed\n");
5184 if (test_and_clear_bit(FX00_TARGET_SCAN,
5185 &base_vha->dpc_flags)) {
5186 ql_dbg(ql_dbg_dpc, base_vha, 0x4022,
5187 "ISPFx00 Target Scan scheduled\n");
5188 if (qlafx00_rescan_isp(base_vha)) {
5189 if (!test_bit(UNLOADING,
5190 &base_vha->dpc_flags))
5191 set_bit(ISP_UNRECOVERABLE,
5192 &base_vha->dpc_flags);
5193 ql_dbg(ql_dbg_dpc, base_vha, 0x401e,
5194 "ISPFx00 Target Scan Failed\n");
5196 ql_dbg(ql_dbg_dpc, base_vha, 0x401f,
5197 "ISPFx00 Target Scan End\n");
5199 if (test_and_clear_bit(FX00_HOST_INFO_RESEND,
5200 &base_vha->dpc_flags)) {
5201 ql_dbg(ql_dbg_dpc, base_vha, 0x4023,
5202 "ISPFx00 Host Info resend scheduled\n");
5203 qlafx00_fx_disc(base_vha,
5204 &base_vha->hw->mr.fcport,
5205 FXDISC_REG_HOST_INFO);
5209 if (test_and_clear_bit
5210 (ISP_ABORT_NEEDED, &base_vha->dpc_flags) &&
5211 !test_bit(UNLOADING, &base_vha->dpc_flags)) {
5213 ql_dbg(ql_dbg_dpc, base_vha, 0x4007,
5214 "ISP abort scheduled.\n");
5215 if (!(test_and_set_bit(ABORT_ISP_ACTIVE,
5216 &base_vha->dpc_flags))) {
5218 if (ha->isp_ops->abort_isp(base_vha)) {
5219 /* failed. retry later */
5220 set_bit(ISP_ABORT_NEEDED,
5221 &base_vha->dpc_flags);
5223 clear_bit(ABORT_ISP_ACTIVE,
5224 &base_vha->dpc_flags);
5227 ql_dbg(ql_dbg_dpc, base_vha, 0x4008,
5228 "ISP abort end.\n");
5231 if (test_and_clear_bit(FCPORT_UPDATE_NEEDED,
5232 &base_vha->dpc_flags)) {
5233 qla2x00_update_fcports(base_vha);
5236 if (test_bit(SCR_PENDING, &base_vha->dpc_flags)) {
5238 ret = qla2x00_send_change_request(base_vha, 0x3, 0);
5239 if (ret != QLA_SUCCESS)
5240 ql_log(ql_log_warn, base_vha, 0x121,
5241 "Failed to enable receiving of RSCN "
5242 "requests: 0x%x.\n", ret);
5243 clear_bit(SCR_PENDING, &base_vha->dpc_flags);
5247 goto loop_resync_check;
5249 if (test_bit(ISP_QUIESCE_NEEDED, &base_vha->dpc_flags)) {
5250 ql_dbg(ql_dbg_dpc, base_vha, 0x4009,
5251 "Quiescence mode scheduled.\n");
5252 if (IS_P3P_TYPE(ha)) {
5254 qla82xx_device_state_handler(base_vha);
5256 qla8044_device_state_handler(base_vha);
5257 clear_bit(ISP_QUIESCE_NEEDED,
5258 &base_vha->dpc_flags);
5259 if (!ha->flags.quiesce_owner) {
5260 qla2x00_perform_loop_resync(base_vha);
5261 if (IS_QLA82XX(ha)) {
5262 qla82xx_idc_lock(ha);
5263 qla82xx_clear_qsnt_ready(
5265 qla82xx_idc_unlock(ha);
5266 } else if (IS_QLA8044(ha)) {
5267 qla8044_idc_lock(ha);
5268 qla8044_clear_qsnt_ready(
5270 qla8044_idc_unlock(ha);
5274 clear_bit(ISP_QUIESCE_NEEDED,
5275 &base_vha->dpc_flags);
5276 qla2x00_quiesce_io(base_vha);
5278 ql_dbg(ql_dbg_dpc, base_vha, 0x400a,
5279 "Quiescence mode end.\n");
5282 if (test_and_clear_bit(RESET_MARKER_NEEDED,
5283 &base_vha->dpc_flags) &&
5284 (!(test_and_set_bit(RESET_ACTIVE, &base_vha->dpc_flags)))) {
5286 ql_dbg(ql_dbg_dpc, base_vha, 0x400b,
5287 "Reset marker scheduled.\n");
5288 qla2x00_rst_aen(base_vha);
5289 clear_bit(RESET_ACTIVE, &base_vha->dpc_flags);
5290 ql_dbg(ql_dbg_dpc, base_vha, 0x400c,
5291 "Reset marker end.\n");
5294 /* Retry each device up to login retry count */
5295 if ((test_and_clear_bit(RELOGIN_NEEDED,
5296 &base_vha->dpc_flags)) &&
5297 !test_bit(LOOP_RESYNC_NEEDED, &base_vha->dpc_flags) &&
5298 atomic_read(&base_vha->loop_state) != LOOP_DOWN) {
5300 ql_dbg(ql_dbg_dpc, base_vha, 0x400d,
5301 "Relogin scheduled.\n");
5302 qla2x00_relogin(base_vha);
5303 ql_dbg(ql_dbg_dpc, base_vha, 0x400e,
5307 if (test_and_clear_bit(LOOP_RESYNC_NEEDED,
5308 &base_vha->dpc_flags)) {
5310 ql_dbg(ql_dbg_dpc, base_vha, 0x400f,
5311 "Loop resync scheduled.\n");
5313 if (!(test_and_set_bit(LOOP_RESYNC_ACTIVE,
5314 &base_vha->dpc_flags))) {
5316 qla2x00_loop_resync(base_vha);
5318 clear_bit(LOOP_RESYNC_ACTIVE,
5319 &base_vha->dpc_flags);
5322 ql_dbg(ql_dbg_dpc, base_vha, 0x4010,
5323 "Loop resync end.\n");
5329 if (test_bit(NPIV_CONFIG_NEEDED, &base_vha->dpc_flags) &&
5330 atomic_read(&base_vha->loop_state) == LOOP_READY) {
5331 clear_bit(NPIV_CONFIG_NEEDED, &base_vha->dpc_flags);
5332 qla2xxx_flash_npiv_conf(base_vha);
5336 if (!ha->interrupts_on)
5337 ha->isp_ops->enable_intrs(ha);
5339 if (test_and_clear_bit(BEACON_BLINK_NEEDED,
5340 &base_vha->dpc_flags)) {
5341 if (ha->beacon_blink_led == 1)
5342 ha->isp_ops->beacon_blink(base_vha);
5345 if (!IS_QLAFX00(ha))
5346 qla2x00_do_dpc_all_vps(base_vha);
5350 set_current_state(TASK_INTERRUPTIBLE);
5351 } /* End of while(1) */
5352 __set_current_state(TASK_RUNNING);
5354 ql_dbg(ql_dbg_dpc, base_vha, 0x4011,
5355 "DPC handler exiting.\n");
5358 * Make sure that nobody tries to wake us up again.
5362 /* Cleanup any residual CTX SRBs. */
5363 qla2x00_abort_all_cmds(base_vha, DID_NO_CONNECT << 16);
5369 qla2xxx_wake_dpc(struct scsi_qla_host *vha)
5371 struct qla_hw_data *ha = vha->hw;
5372 struct task_struct *t = ha->dpc_thread;
5374 if (!test_bit(UNLOADING, &vha->dpc_flags) && t)
5380 * Processes asynchronous reset.
5383 * ha = adapter block pointer.
5386 qla2x00_rst_aen(scsi_qla_host_t *vha)
5388 if (vha->flags.online && !vha->flags.reset_active &&
5389 !atomic_read(&vha->loop_down_timer) &&
5390 !(test_bit(ABORT_ISP_ACTIVE, &vha->dpc_flags))) {
5392 clear_bit(RESET_MARKER_NEEDED, &vha->dpc_flags);
5395 * Issue marker command only when we are going to start
5398 vha->marker_needed = 1;
5399 } while (!atomic_read(&vha->loop_down_timer) &&
5400 (test_bit(RESET_MARKER_NEEDED, &vha->dpc_flags)));
5404 /**************************************************************************
5410 * Context: Interrupt
5411 ***************************************************************************/
5413 qla2x00_timer(scsi_qla_host_t *vha)
5415 unsigned long cpu_flags = 0;
5420 struct qla_hw_data *ha = vha->hw;
5421 struct req_que *req;
5423 if (ha->flags.eeh_busy) {
5424 ql_dbg(ql_dbg_timer, vha, 0x6000,
5425 "EEH = %d, restarting timer.\n",
5426 ha->flags.eeh_busy);
5427 qla2x00_restart_timer(vha, WATCH_INTERVAL);
5432 * Hardware read to raise pending EEH errors during mailbox waits. If
5433 * the read returns -1 then disable the board.
5435 if (!pci_channel_offline(ha->pdev)) {
5436 pci_read_config_word(ha->pdev, PCI_VENDOR_ID, &w);
5437 qla2x00_check_reg16_for_disconnect(vha, w);
5440 /* Make sure qla82xx_watchdog is run only for physical port */
5441 if (!vha->vp_idx && IS_P3P_TYPE(ha)) {
5442 if (test_bit(ISP_QUIESCE_NEEDED, &vha->dpc_flags))
5445 qla82xx_watchdog(vha);
5446 else if (IS_QLA8044(ha))
5447 qla8044_watchdog(vha);
5450 if (!vha->vp_idx && IS_QLAFX00(ha))
5451 qlafx00_timer_routine(vha);
5453 /* Loop down handler. */
5454 if (atomic_read(&vha->loop_down_timer) > 0 &&
5455 !(test_bit(ABORT_ISP_ACTIVE, &vha->dpc_flags)) &&
5456 !(test_bit(FCOE_CTX_RESET_NEEDED, &vha->dpc_flags))
5457 && vha->flags.online) {
5459 if (atomic_read(&vha->loop_down_timer) ==
5460 vha->loop_down_abort_time) {
5462 ql_log(ql_log_info, vha, 0x6008,
5463 "Loop down - aborting the queues before time expires.\n");
5465 if (!IS_QLA2100(ha) && vha->link_down_timeout)
5466 atomic_set(&vha->loop_state, LOOP_DEAD);
5469 * Schedule an ISP abort to return any FCP2-device
5472 /* NPIV - scan physical port only */
5474 spin_lock_irqsave(&ha->hardware_lock,
5476 req = ha->req_q_map[0];
5478 index < req->num_outstanding_cmds;
5482 sp = req->outstanding_cmds[index];
5485 if (sp->type != SRB_SCSI_CMD)
5488 if (!(sfcp->flags & FCF_FCP2_DEVICE))
5492 set_bit(FCOE_CTX_RESET_NEEDED,
5495 set_bit(ISP_ABORT_NEEDED,
5499 spin_unlock_irqrestore(&ha->hardware_lock,
5505 /* if the loop has been down for 4 minutes, reinit adapter */
5506 if (atomic_dec_and_test(&vha->loop_down_timer) != 0) {
5507 if (!(vha->device_flags & DFLG_NO_CABLE)) {
5508 ql_log(ql_log_warn, vha, 0x6009,
5509 "Loop down - aborting ISP.\n");
5512 set_bit(FCOE_CTX_RESET_NEEDED,
5515 set_bit(ISP_ABORT_NEEDED,
5519 ql_dbg(ql_dbg_timer, vha, 0x600a,
5520 "Loop down - seconds remaining %d.\n",
5521 atomic_read(&vha->loop_down_timer));
5523 /* Check if beacon LED needs to be blinked for physical host only */
5524 if (!vha->vp_idx && (ha->beacon_blink_led == 1)) {
5525 /* There is no beacon_blink function for ISP82xx */
5526 if (!IS_P3P_TYPE(ha)) {
5527 set_bit(BEACON_BLINK_NEEDED, &vha->dpc_flags);
5532 /* Process any deferred work. */
5533 if (!list_empty(&vha->work_list))
5536 /* Schedule the DPC routine if needed */
5537 if ((test_bit(ISP_ABORT_NEEDED, &vha->dpc_flags) ||
5538 test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags) ||
5539 test_bit(FCPORT_UPDATE_NEEDED, &vha->dpc_flags) ||
5541 test_bit(RESET_MARKER_NEEDED, &vha->dpc_flags) ||
5542 test_bit(BEACON_BLINK_NEEDED, &vha->dpc_flags) ||
5543 test_bit(ISP_UNRECOVERABLE, &vha->dpc_flags) ||
5544 test_bit(FCOE_CTX_RESET_NEEDED, &vha->dpc_flags) ||
5545 test_bit(VP_DPC_NEEDED, &vha->dpc_flags) ||
5546 test_bit(RELOGIN_NEEDED, &vha->dpc_flags))) {
5547 ql_dbg(ql_dbg_timer, vha, 0x600b,
5548 "isp_abort_needed=%d loop_resync_needed=%d "
5549 "fcport_update_needed=%d start_dpc=%d "
5550 "reset_marker_needed=%d",
5551 test_bit(ISP_ABORT_NEEDED, &vha->dpc_flags),
5552 test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags),
5553 test_bit(FCPORT_UPDATE_NEEDED, &vha->dpc_flags),
5555 test_bit(RESET_MARKER_NEEDED, &vha->dpc_flags));
5556 ql_dbg(ql_dbg_timer, vha, 0x600c,
5557 "beacon_blink_needed=%d isp_unrecoverable=%d "
5558 "fcoe_ctx_reset_needed=%d vp_dpc_needed=%d "
5559 "relogin_needed=%d.\n",
5560 test_bit(BEACON_BLINK_NEEDED, &vha->dpc_flags),
5561 test_bit(ISP_UNRECOVERABLE, &vha->dpc_flags),
5562 test_bit(FCOE_CTX_RESET_NEEDED, &vha->dpc_flags),
5563 test_bit(VP_DPC_NEEDED, &vha->dpc_flags),
5564 test_bit(RELOGIN_NEEDED, &vha->dpc_flags));
5565 qla2xxx_wake_dpc(vha);
5568 qla2x00_restart_timer(vha, WATCH_INTERVAL);
5571 /* Firmware interface routines. */
5574 #define FW_ISP21XX 0
5575 #define FW_ISP22XX 1
5576 #define FW_ISP2300 2
5577 #define FW_ISP2322 3
5578 #define FW_ISP24XX 4
5579 #define FW_ISP25XX 5
5580 #define FW_ISP81XX 6
5581 #define FW_ISP82XX 7
5582 #define FW_ISP2031 8
5583 #define FW_ISP8031 9
5584 #define FW_ISP27XX 10
5586 #define FW_FILE_ISP21XX "/*(DEBLOBBED)*/"
5587 #define FW_FILE_ISP22XX "/*(DEBLOBBED)*/"
5588 #define FW_FILE_ISP2300 "/*(DEBLOBBED)*/"
5589 #define FW_FILE_ISP2322 "/*(DEBLOBBED)*/"
5590 #define FW_FILE_ISP24XX "/*(DEBLOBBED)*/"
5591 #define FW_FILE_ISP25XX "/*(DEBLOBBED)*/"
5592 #define FW_FILE_ISP81XX "/*(DEBLOBBED)*/"
5593 #define FW_FILE_ISP82XX "/*(DEBLOBBED)*/"
5594 #define FW_FILE_ISP2031 "/*(DEBLOBBED)*/"
5595 #define FW_FILE_ISP8031 "/*(DEBLOBBED)*/"
5596 #define FW_FILE_ISP27XX "/*(DEBLOBBED)*/"
5599 static DEFINE_MUTEX(qla_fw_lock);
5601 static struct fw_blob qla_fw_blobs[FW_BLOBS] = {
5602 { .name = FW_FILE_ISP21XX, .segs = { 0x1000, 0 }, },
5603 { .name = FW_FILE_ISP22XX, .segs = { 0x1000, 0 }, },
5604 { .name = FW_FILE_ISP2300, .segs = { 0x800, 0 }, },
5605 { .name = FW_FILE_ISP2322, .segs = { 0x800, 0x1c000, 0x1e000, 0 }, },
5606 { .name = FW_FILE_ISP24XX, },
5607 { .name = FW_FILE_ISP25XX, },
5608 { .name = FW_FILE_ISP81XX, },
5609 { .name = FW_FILE_ISP82XX, },
5610 { .name = FW_FILE_ISP2031, },
5611 { .name = FW_FILE_ISP8031, },
5612 { .name = FW_FILE_ISP27XX, },
5616 qla2x00_request_firmware(scsi_qla_host_t *vha)
5618 struct qla_hw_data *ha = vha->hw;
5619 struct fw_blob *blob;
5621 if (IS_QLA2100(ha)) {
5622 blob = &qla_fw_blobs[FW_ISP21XX];
5623 } else if (IS_QLA2200(ha)) {
5624 blob = &qla_fw_blobs[FW_ISP22XX];
5625 } else if (IS_QLA2300(ha) || IS_QLA2312(ha) || IS_QLA6312(ha)) {
5626 blob = &qla_fw_blobs[FW_ISP2300];
5627 } else if (IS_QLA2322(ha) || IS_QLA6322(ha)) {
5628 blob = &qla_fw_blobs[FW_ISP2322];
5629 } else if (IS_QLA24XX_TYPE(ha)) {
5630 blob = &qla_fw_blobs[FW_ISP24XX];
5631 } else if (IS_QLA25XX(ha)) {
5632 blob = &qla_fw_blobs[FW_ISP25XX];
5633 } else if (IS_QLA81XX(ha)) {
5634 blob = &qla_fw_blobs[FW_ISP81XX];
5635 } else if (IS_QLA82XX(ha)) {
5636 blob = &qla_fw_blobs[FW_ISP82XX];
5637 } else if (IS_QLA2031(ha)) {
5638 blob = &qla_fw_blobs[FW_ISP2031];
5639 } else if (IS_QLA8031(ha)) {
5640 blob = &qla_fw_blobs[FW_ISP8031];
5641 } else if (IS_QLA27XX(ha)) {
5642 blob = &qla_fw_blobs[FW_ISP27XX];
5647 mutex_lock(&qla_fw_lock);
5651 if (reject_firmware(&blob->fw, blob->name, &ha->pdev->dev)) {
5652 ql_log(ql_log_warn, vha, 0x0063,
5653 "Failed to load firmware image (%s).\n", blob->name);
5660 mutex_unlock(&qla_fw_lock);
5665 qla2x00_release_firmware(void)
5669 mutex_lock(&qla_fw_lock);
5670 for (idx = 0; idx < FW_BLOBS; idx++)
5671 release_firmware(qla_fw_blobs[idx].fw);
5672 mutex_unlock(&qla_fw_lock);
5675 static pci_ers_result_t
5676 qla2xxx_pci_error_detected(struct pci_dev *pdev, pci_channel_state_t state)
5678 scsi_qla_host_t *vha = pci_get_drvdata(pdev);
5679 struct qla_hw_data *ha = vha->hw;
5681 ql_dbg(ql_dbg_aer, vha, 0x9000,
5682 "PCI error detected, state %x.\n", state);
5685 case pci_channel_io_normal:
5686 ha->flags.eeh_busy = 0;
5687 return PCI_ERS_RESULT_CAN_RECOVER;
5688 case pci_channel_io_frozen:
5689 ha->flags.eeh_busy = 1;
5690 /* For ISP82XX complete any pending mailbox cmd */
5691 if (IS_QLA82XX(ha)) {
5692 ha->flags.isp82xx_fw_hung = 1;
5693 ql_dbg(ql_dbg_aer, vha, 0x9001, "Pci channel io frozen\n");
5694 qla82xx_clear_pending_mbx(vha);
5696 qla2x00_free_irqs(vha);
5697 pci_disable_device(pdev);
5698 /* Return back all IOs */
5699 qla2x00_abort_all_cmds(vha, DID_RESET << 16);
5700 return PCI_ERS_RESULT_NEED_RESET;
5701 case pci_channel_io_perm_failure:
5702 ha->flags.pci_channel_io_perm_failure = 1;
5703 qla2x00_abort_all_cmds(vha, DID_NO_CONNECT << 16);
5704 return PCI_ERS_RESULT_DISCONNECT;
5706 return PCI_ERS_RESULT_NEED_RESET;
5709 static pci_ers_result_t
5710 qla2xxx_pci_mmio_enabled(struct pci_dev *pdev)
5712 int risc_paused = 0;
5714 unsigned long flags;
5715 scsi_qla_host_t *base_vha = pci_get_drvdata(pdev);
5716 struct qla_hw_data *ha = base_vha->hw;
5717 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
5718 struct device_reg_24xx __iomem *reg24 = &ha->iobase->isp24;
5721 return PCI_ERS_RESULT_RECOVERED;
5723 spin_lock_irqsave(&ha->hardware_lock, flags);
5724 if (IS_QLA2100(ha) || IS_QLA2200(ha)){
5725 stat = RD_REG_DWORD(®->hccr);
5726 if (stat & HCCR_RISC_PAUSE)
5728 } else if (IS_QLA23XX(ha)) {
5729 stat = RD_REG_DWORD(®->u.isp2300.host_status);
5730 if (stat & HSR_RISC_PAUSED)
5732 } else if (IS_FWI2_CAPABLE(ha)) {
5733 stat = RD_REG_DWORD(®24->host_status);
5734 if (stat & HSRX_RISC_PAUSED)
5737 spin_unlock_irqrestore(&ha->hardware_lock, flags);
5740 ql_log(ql_log_info, base_vha, 0x9003,
5741 "RISC paused -- mmio_enabled, Dumping firmware.\n");
5742 ha->isp_ops->fw_dump(base_vha, 0);
5744 return PCI_ERS_RESULT_NEED_RESET;
5746 return PCI_ERS_RESULT_RECOVERED;
5750 qla82xx_error_recovery(scsi_qla_host_t *base_vha)
5752 uint32_t rval = QLA_FUNCTION_FAILED;
5753 uint32_t drv_active = 0;
5754 struct qla_hw_data *ha = base_vha->hw;
5756 struct pci_dev *other_pdev = NULL;
5758 ql_dbg(ql_dbg_aer, base_vha, 0x9006,
5759 "Entered %s.\n", __func__);
5761 set_bit(ABORT_ISP_ACTIVE, &base_vha->dpc_flags);
5763 if (base_vha->flags.online) {
5764 /* Abort all outstanding commands,
5765 * so as to be requeued later */
5766 qla2x00_abort_isp_cleanup(base_vha);
5770 fn = PCI_FUNC(ha->pdev->devfn);
5773 ql_dbg(ql_dbg_aer, base_vha, 0x9007,
5774 "Finding pci device at function = 0x%x.\n", fn);
5776 pci_get_domain_bus_and_slot(pci_domain_nr(ha->pdev->bus),
5777 ha->pdev->bus->number, PCI_DEVFN(PCI_SLOT(ha->pdev->devfn),
5782 if (atomic_read(&other_pdev->enable_cnt)) {
5783 ql_dbg(ql_dbg_aer, base_vha, 0x9008,
5784 "Found PCI func available and enable at 0x%x.\n",
5786 pci_dev_put(other_pdev);
5789 pci_dev_put(other_pdev);
5794 ql_dbg(ql_dbg_aer, base_vha, 0x9009,
5795 "This devfn is reset owner = 0x%x.\n",
5797 qla82xx_idc_lock(ha);
5799 qla82xx_wr_32(ha, QLA82XX_CRB_DEV_STATE,
5800 QLA8XXX_DEV_INITIALIZING);
5802 qla82xx_wr_32(ha, QLA82XX_CRB_DRV_IDC_VERSION,
5803 QLA82XX_IDC_VERSION);
5805 drv_active = qla82xx_rd_32(ha, QLA82XX_CRB_DRV_ACTIVE);
5806 ql_dbg(ql_dbg_aer, base_vha, 0x900a,
5807 "drv_active = 0x%x.\n", drv_active);
5809 qla82xx_idc_unlock(ha);
5810 /* Reset if device is not already reset
5811 * drv_active would be 0 if a reset has already been done
5814 rval = qla82xx_start_firmware(base_vha);
5817 qla82xx_idc_lock(ha);
5819 if (rval != QLA_SUCCESS) {
5820 ql_log(ql_log_info, base_vha, 0x900b,
5821 "HW State: FAILED.\n");
5822 qla82xx_clear_drv_active(ha);
5823 qla82xx_wr_32(ha, QLA82XX_CRB_DEV_STATE,
5824 QLA8XXX_DEV_FAILED);
5826 ql_log(ql_log_info, base_vha, 0x900c,
5827 "HW State: READY.\n");
5828 qla82xx_wr_32(ha, QLA82XX_CRB_DEV_STATE,
5830 qla82xx_idc_unlock(ha);
5831 ha->flags.isp82xx_fw_hung = 0;
5832 rval = qla82xx_restart_isp(base_vha);
5833 qla82xx_idc_lock(ha);
5834 /* Clear driver state register */
5835 qla82xx_wr_32(ha, QLA82XX_CRB_DRV_STATE, 0);
5836 qla82xx_set_drv_active(base_vha);
5838 qla82xx_idc_unlock(ha);
5840 ql_dbg(ql_dbg_aer, base_vha, 0x900d,
5841 "This devfn is not reset owner = 0x%x.\n",
5843 if ((qla82xx_rd_32(ha, QLA82XX_CRB_DEV_STATE) ==
5844 QLA8XXX_DEV_READY)) {
5845 ha->flags.isp82xx_fw_hung = 0;
5846 rval = qla82xx_restart_isp(base_vha);
5847 qla82xx_idc_lock(ha);
5848 qla82xx_set_drv_active(base_vha);
5849 qla82xx_idc_unlock(ha);
5852 clear_bit(ABORT_ISP_ACTIVE, &base_vha->dpc_flags);
5857 static pci_ers_result_t
5858 qla2xxx_pci_slot_reset(struct pci_dev *pdev)
5860 pci_ers_result_t ret = PCI_ERS_RESULT_DISCONNECT;
5861 scsi_qla_host_t *base_vha = pci_get_drvdata(pdev);
5862 struct qla_hw_data *ha = base_vha->hw;
5863 struct rsp_que *rsp;
5864 int rc, retries = 10;
5866 ql_dbg(ql_dbg_aer, base_vha, 0x9004,
5869 /* Workaround: qla2xxx driver which access hardware earlier
5870 * needs error state to be pci_channel_io_online.
5871 * Otherwise mailbox command timesout.
5873 pdev->error_state = pci_channel_io_normal;
5875 pci_restore_state(pdev);
5877 /* pci_restore_state() clears the saved_state flag of the device
5878 * save restored state which resets saved_state flag
5880 pci_save_state(pdev);
5883 rc = pci_enable_device_mem(pdev);
5885 rc = pci_enable_device(pdev);
5888 ql_log(ql_log_warn, base_vha, 0x9005,
5889 "Can't re-enable PCI device after reset.\n");
5890 goto exit_slot_reset;
5893 rsp = ha->rsp_q_map[0];
5894 if (qla2x00_request_irqs(ha, rsp))
5895 goto exit_slot_reset;
5897 if (ha->isp_ops->pci_config(base_vha))
5898 goto exit_slot_reset;
5900 if (IS_QLA82XX(ha)) {
5901 if (qla82xx_error_recovery(base_vha) == QLA_SUCCESS) {
5902 ret = PCI_ERS_RESULT_RECOVERED;
5903 goto exit_slot_reset;
5905 goto exit_slot_reset;
5908 while (ha->flags.mbox_busy && retries--)
5911 set_bit(ABORT_ISP_ACTIVE, &base_vha->dpc_flags);
5912 if (ha->isp_ops->abort_isp(base_vha) == QLA_SUCCESS)
5913 ret = PCI_ERS_RESULT_RECOVERED;
5914 clear_bit(ABORT_ISP_ACTIVE, &base_vha->dpc_flags);
5918 ql_dbg(ql_dbg_aer, base_vha, 0x900e,
5919 "slot_reset return %x.\n", ret);
5925 qla2xxx_pci_resume(struct pci_dev *pdev)
5927 scsi_qla_host_t *base_vha = pci_get_drvdata(pdev);
5928 struct qla_hw_data *ha = base_vha->hw;
5931 ql_dbg(ql_dbg_aer, base_vha, 0x900f,
5934 ret = qla2x00_wait_for_hba_online(base_vha);
5935 if (ret != QLA_SUCCESS) {
5936 ql_log(ql_log_fatal, base_vha, 0x9002,
5937 "The device failed to resume I/O from slot/link_reset.\n");
5940 pci_cleanup_aer_uncorrect_error_status(pdev);
5942 ha->flags.eeh_busy = 0;
5946 qla83xx_disable_laser(scsi_qla_host_t *vha)
5948 uint32_t reg, data, fn;
5949 struct qla_hw_data *ha = vha->hw;
5950 struct device_reg_24xx __iomem *isp_reg = &ha->iobase->isp24;
5952 /* pci func #/port # */
5953 ql_dbg(ql_dbg_init, vha, 0x004b,
5954 "Disabling Laser for hba: %p\n", vha);
5956 fn = (RD_REG_DWORD(&isp_reg->ctrl_status) &
5957 (BIT_15|BIT_14|BIT_13|BIT_12));
5966 data = LASER_OFF_2031;
5968 qla83xx_wr_reg(vha, reg, data);
5971 static const struct pci_error_handlers qla2xxx_err_handler = {
5972 .error_detected = qla2xxx_pci_error_detected,
5973 .mmio_enabled = qla2xxx_pci_mmio_enabled,
5974 .slot_reset = qla2xxx_pci_slot_reset,
5975 .resume = qla2xxx_pci_resume,
5978 static struct pci_device_id qla2xxx_pci_tbl[] = {
5979 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP2100) },
5980 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP2200) },
5981 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP2300) },
5982 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP2312) },
5983 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP2322) },
5984 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP6312) },
5985 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP6322) },
5986 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP2422) },
5987 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP2432) },
5988 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP8432) },
5989 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP5422) },
5990 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP5432) },
5991 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP2532) },
5992 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP2031) },
5993 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP8001) },
5994 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP8021) },
5995 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP8031) },
5996 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISPF001) },
5997 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP8044) },
5998 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP2071) },
5999 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP2271) },
6000 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP2261) },
6003 MODULE_DEVICE_TABLE(pci, qla2xxx_pci_tbl);
6005 static struct pci_driver qla2xxx_pci_driver = {
6006 .name = QLA2XXX_DRIVER_NAME,
6008 .owner = THIS_MODULE,
6010 .id_table = qla2xxx_pci_tbl,
6011 .probe = qla2x00_probe_one,
6012 .remove = qla2x00_remove_one,
6013 .shutdown = qla2x00_shutdown,
6014 .err_handler = &qla2xxx_err_handler,
6017 static const struct file_operations apidev_fops = {
6018 .owner = THIS_MODULE,
6019 .llseek = noop_llseek,
6023 * qla2x00_module_init - Module initialization.
6026 qla2x00_module_init(void)
6030 /* Allocate cache for SRBs. */
6031 srb_cachep = kmem_cache_create("qla2xxx_srbs", sizeof(srb_t), 0,
6032 SLAB_HWCACHE_ALIGN, NULL);
6033 if (srb_cachep == NULL) {
6034 ql_log(ql_log_fatal, NULL, 0x0001,
6035 "Unable to allocate SRB cache...Failing load!.\n");
6039 /* Initialize target kmem_cache and mem_pools */
6043 } else if (ret > 0) {
6045 * If initiator mode is explictly disabled by qlt_init(),
6046 * prevent scsi_transport_fc.c:fc_scsi_scan_rport() from
6047 * performing scsi_scan_target() during LOOP UP event.
6049 qla2xxx_transport_functions.disable_target_scan = 1;
6050 qla2xxx_transport_vport_functions.disable_target_scan = 1;
6053 /* Derive version string. */
6054 strcpy(qla2x00_version_str, QLA2XXX_VERSION);
6055 if (ql2xextended_error_logging)
6056 strcat(qla2x00_version_str, "-debug");
6058 qla2xxx_transport_template =
6059 fc_attach_transport(&qla2xxx_transport_functions);
6060 if (!qla2xxx_transport_template) {
6061 ql_log(ql_log_fatal, NULL, 0x0002,
6062 "fc_attach_transport failed...Failing load!.\n");
6067 apidev_major = register_chrdev(0, QLA2XXX_APIDEV, &apidev_fops);
6068 if (apidev_major < 0) {
6069 ql_log(ql_log_fatal, NULL, 0x0003,
6070 "Unable to register char device %s.\n", QLA2XXX_APIDEV);
6073 qla2xxx_transport_vport_template =
6074 fc_attach_transport(&qla2xxx_transport_vport_functions);
6075 if (!qla2xxx_transport_vport_template) {
6076 ql_log(ql_log_fatal, NULL, 0x0004,
6077 "fc_attach_transport vport failed...Failing load!.\n");
6081 ql_log(ql_log_info, NULL, 0x0005,
6082 "QLogic Fibre Channel HBA Driver: %s.\n",
6083 qla2x00_version_str);
6084 ret = pci_register_driver(&qla2xxx_pci_driver);
6086 ql_log(ql_log_fatal, NULL, 0x0006,
6087 "pci_register_driver failed...ret=%d Failing load!.\n",
6089 goto release_vport_transport;
6093 release_vport_transport:
6094 fc_release_transport(qla2xxx_transport_vport_template);
6097 if (apidev_major >= 0)
6098 unregister_chrdev(apidev_major, QLA2XXX_APIDEV);
6099 fc_release_transport(qla2xxx_transport_template);
6105 kmem_cache_destroy(srb_cachep);
6110 * qla2x00_module_exit - Module cleanup.
6113 qla2x00_module_exit(void)
6115 unregister_chrdev(apidev_major, QLA2XXX_APIDEV);
6116 pci_unregister_driver(&qla2xxx_pci_driver);
6117 qla2x00_release_firmware();
6118 kmem_cache_destroy(srb_cachep);
6121 kmem_cache_destroy(ctx_cachep);
6122 fc_release_transport(qla2xxx_transport_template);
6123 fc_release_transport(qla2xxx_transport_vport_template);
6126 module_init(qla2x00_module_init);
6127 module_exit(qla2x00_module_exit);
6129 MODULE_AUTHOR("QLogic Corporation");
6130 MODULE_DESCRIPTION("QLogic Fibre Channel HBA Driver");
6131 MODULE_LICENSE("GPL");
6132 MODULE_VERSION(QLA2XXX_VERSION);