2 * QLogic Fibre Channel HBA Driver
3 * Copyright (c) 2003-2014 QLogic Corporation
5 * See LICENSE.qla2xxx for copyright and licensing details.
9 #include <linux/moduleparam.h>
10 #include <linux/vmalloc.h>
11 #include <linux/delay.h>
12 #include <linux/kthread.h>
13 #include <linux/mutex.h>
14 #include <linux/kobject.h>
15 #include <linux/slab.h>
16 #include <linux/blk-mq-pci.h>
17 #include <linux/refcount.h>
18 #include <linux/crash_dump.h>
20 #include <scsi/scsi_tcq.h>
21 #include <scsi/scsicam.h>
22 #include <scsi/scsi_transport.h>
23 #include <scsi/scsi_transport_fc.h>
25 #include "qla_target.h"
30 char qla2x00_version_str[40];
32 static int apidev_major;
35 * SRB allocation cache
37 struct kmem_cache *srb_cachep;
40 * CT6 CTX allocation cache
42 static struct kmem_cache *ctx_cachep;
44 * error level for logging
46 uint ql_errlev = 0x8001;
48 static int ql2xenableclass2;
49 module_param(ql2xenableclass2, int, S_IRUGO|S_IRUSR);
50 MODULE_PARM_DESC(ql2xenableclass2,
51 "Specify if Class 2 operations are supported from the very "
52 "beginning. Default is 0 - class 2 not supported.");
55 int ql2xlogintimeout = 20;
56 module_param(ql2xlogintimeout, int, S_IRUGO);
57 MODULE_PARM_DESC(ql2xlogintimeout,
58 "Login timeout value in seconds.");
60 int qlport_down_retry;
61 module_param(qlport_down_retry, int, S_IRUGO);
62 MODULE_PARM_DESC(qlport_down_retry,
63 "Maximum number of command retries to a port that returns "
64 "a PORT-DOWN status.");
66 int ql2xplogiabsentdevice;
67 module_param(ql2xplogiabsentdevice, int, S_IRUGO|S_IWUSR);
68 MODULE_PARM_DESC(ql2xplogiabsentdevice,
69 "Option to enable PLOGI to devices that are not present after "
70 "a Fabric scan. This is needed for several broken switches. "
71 "Default is 0 - no PLOGI. 1 - perform PLOGI.");
73 int ql2xloginretrycount;
74 module_param(ql2xloginretrycount, int, S_IRUGO);
75 MODULE_PARM_DESC(ql2xloginretrycount,
76 "Specify an alternate value for the NVRAM login retry count.");
78 int ql2xallocfwdump = 1;
79 module_param(ql2xallocfwdump, int, S_IRUGO);
80 MODULE_PARM_DESC(ql2xallocfwdump,
81 "Option to enable allocation of memory for a firmware dump "
82 "during HBA initialization. Memory allocation requirements "
83 "vary by ISP type. Default is 1 - allocate memory.");
85 int ql2xextended_error_logging;
86 module_param(ql2xextended_error_logging, int, S_IRUGO|S_IWUSR);
87 module_param_named(logging, ql2xextended_error_logging, int, S_IRUGO|S_IWUSR);
88 MODULE_PARM_DESC(ql2xextended_error_logging,
89 "Option to enable extended error logging,\n"
90 "\t\tDefault is 0 - no logging. 0x40000000 - Module Init & Probe.\n"
91 "\t\t0x20000000 - Mailbox Cmnds. 0x10000000 - Device Discovery.\n"
92 "\t\t0x08000000 - IO tracing. 0x04000000 - DPC Thread.\n"
93 "\t\t0x02000000 - Async events. 0x01000000 - Timer routines.\n"
94 "\t\t0x00800000 - User space. 0x00400000 - Task Management.\n"
95 "\t\t0x00200000 - AER/EEH. 0x00100000 - Multi Q.\n"
96 "\t\t0x00080000 - P3P Specific. 0x00040000 - Virtual Port.\n"
97 "\t\t0x00020000 - Buffer Dump. 0x00010000 - Misc.\n"
98 "\t\t0x00008000 - Verbose. 0x00004000 - Target.\n"
99 "\t\t0x00002000 - Target Mgmt. 0x00001000 - Target TMF.\n"
100 "\t\t0x7fffffff - For enabling all logs, can be too many logs.\n"
101 "\t\t0x1e400000 - Preferred value for capturing essential "
102 "debug information (equivalent to old "
103 "ql2xextended_error_logging=1).\n"
104 "\t\tDo LOGICAL OR of the value to enable more than one level");
106 int ql2xshiftctondsd = 6;
107 module_param(ql2xshiftctondsd, int, S_IRUGO);
108 MODULE_PARM_DESC(ql2xshiftctondsd,
109 "Set to control shifting of command type processing "
110 "based on total number of SG elements.");
112 int ql2xfdmienable = 1;
113 module_param(ql2xfdmienable, int, S_IRUGO|S_IWUSR);
114 module_param_named(fdmi, ql2xfdmienable, int, S_IRUGO|S_IWUSR);
115 MODULE_PARM_DESC(ql2xfdmienable,
116 "Enables FDMI registrations. "
117 "0 - no FDMI. Default is 1 - perform FDMI.");
119 #define MAX_Q_DEPTH 64
120 static int ql2xmaxqdepth = MAX_Q_DEPTH;
121 module_param(ql2xmaxqdepth, int, S_IRUGO|S_IWUSR);
122 MODULE_PARM_DESC(ql2xmaxqdepth,
123 "Maximum queue depth to set for each LUN. "
126 #if (IS_ENABLED(CONFIG_NVME_FC))
129 int ql2xenabledif = 2;
131 module_param(ql2xenabledif, int, S_IRUGO);
132 MODULE_PARM_DESC(ql2xenabledif,
133 " Enable T10-CRC-DIF:\n"
135 " 0 -- No DIF Support\n"
136 " 1 -- Enable DIF for all types\n"
137 " 2 -- Enable DIF for all types, except Type 0.\n");
139 #if (IS_ENABLED(CONFIG_NVME_FC))
140 int ql2xnvmeenable = 1;
144 module_param(ql2xnvmeenable, int, 0644);
145 MODULE_PARM_DESC(ql2xnvmeenable,
146 "Enables NVME support. "
147 "0 - no NVMe. Default is Y");
149 int ql2xenablehba_err_chk = 2;
150 module_param(ql2xenablehba_err_chk, int, S_IRUGO|S_IWUSR);
151 MODULE_PARM_DESC(ql2xenablehba_err_chk,
152 " Enable T10-CRC-DIF Error isolation by HBA:\n"
154 " 0 -- Error isolation disabled\n"
155 " 1 -- Error isolation enabled only for DIX Type 0\n"
156 " 2 -- Error isolation enabled for all Types\n");
158 int ql2xiidmaenable = 1;
159 module_param(ql2xiidmaenable, int, S_IRUGO);
160 MODULE_PARM_DESC(ql2xiidmaenable,
161 "Enables iIDMA settings "
162 "Default is 1 - perform iIDMA. 0 - no iIDMA.");
164 int ql2xmqsupport = 1;
165 module_param(ql2xmqsupport, int, S_IRUGO);
166 MODULE_PARM_DESC(ql2xmqsupport,
167 "Enable on demand multiple queue pairs support "
168 "Default is 1 for supported. "
169 "Set it to 0 to turn off mq qpair support.");
172 module_param(ql2xfwloadbin, int, S_IRUGO|S_IWUSR);
173 module_param_named(fwload, ql2xfwloadbin, int, S_IRUGO|S_IWUSR);
174 MODULE_PARM_DESC(ql2xfwloadbin,
175 "Option to specify location from which to load ISP firmware:.\n"
176 " 2 -- load firmware via the reject_firmware() (hotplug).\n"
178 " 1 -- load firmware from flash.\n"
179 " 0 -- use default semantics.\n");
182 module_param(ql2xetsenable, int, S_IRUGO);
183 MODULE_PARM_DESC(ql2xetsenable,
184 "Enables firmware ETS burst."
185 "Default is 0 - skip ETS enablement.");
188 module_param(ql2xdbwr, int, S_IRUGO|S_IWUSR);
189 MODULE_PARM_DESC(ql2xdbwr,
190 "Option to specify scheme for request queue posting.\n"
191 " 0 -- Regular doorbell.\n"
192 " 1 -- CAMRAM doorbell (faster).\n");
195 module_param(ql2xgffidenable, int, S_IRUGO);
196 MODULE_PARM_DESC(ql2xgffidenable,
197 "Enables GFF_ID checks of port type. "
198 "Default is 0 - Do not use GFF_ID information.");
200 int ql2xasynctmfenable = 1;
201 module_param(ql2xasynctmfenable, int, S_IRUGO);
202 MODULE_PARM_DESC(ql2xasynctmfenable,
203 "Enables issue of TM IOCBs asynchronously via IOCB mechanism"
204 "Default is 1 - Issue TM IOCBs via mailbox mechanism.");
206 int ql2xdontresethba;
207 module_param(ql2xdontresethba, int, S_IRUGO|S_IWUSR);
208 MODULE_PARM_DESC(ql2xdontresethba,
209 "Option to specify reset behaviour.\n"
210 " 0 (Default) -- Reset on failure.\n"
211 " 1 -- Do not reset on failure.\n");
213 uint64_t ql2xmaxlun = MAX_LUNS;
214 module_param(ql2xmaxlun, ullong, S_IRUGO);
215 MODULE_PARM_DESC(ql2xmaxlun,
216 "Defines the maximum LU number to register with the SCSI "
217 "midlayer. Default is 65535.");
219 int ql2xmdcapmask = 0x1F;
220 module_param(ql2xmdcapmask, int, S_IRUGO);
221 MODULE_PARM_DESC(ql2xmdcapmask,
222 "Set the Minidump driver capture mask level. "
223 "Default is 0x1F - Can be set to 0x3, 0x7, 0xF, 0x1F, 0x7F.");
225 int ql2xmdenable = 1;
226 module_param(ql2xmdenable, int, S_IRUGO);
227 MODULE_PARM_DESC(ql2xmdenable,
228 "Enable/disable MiniDump. "
229 "0 - MiniDump disabled. "
230 "1 (Default) - MiniDump enabled.");
233 module_param(ql2xexlogins, uint, S_IRUGO|S_IWUSR);
234 MODULE_PARM_DESC(ql2xexlogins,
235 "Number of extended Logins. "
236 "0 (Default)- Disabled.");
238 int ql2xexchoffld = 1024;
239 module_param(ql2xexchoffld, uint, 0644);
240 MODULE_PARM_DESC(ql2xexchoffld,
241 "Number of target exchanges.");
243 int ql2xiniexchg = 1024;
244 module_param(ql2xiniexchg, uint, 0644);
245 MODULE_PARM_DESC(ql2xiniexchg,
246 "Number of initiator exchanges.");
249 module_param(ql2xfwholdabts, int, S_IRUGO);
250 MODULE_PARM_DESC(ql2xfwholdabts,
251 "Allow FW to hold status IOCB until ABTS rsp received. "
252 "0 (Default) Do not set fw option. "
253 "1 - Set fw option to hold ABTS.");
255 int ql2xmvasynctoatio = 1;
256 module_param(ql2xmvasynctoatio, int, S_IRUGO|S_IWUSR);
257 MODULE_PARM_DESC(ql2xmvasynctoatio,
258 "Move PUREX, ABTS RX and RIDA IOCBs to ATIOQ"
259 "0 (Default). Do not move IOCBs"
262 int ql2xautodetectsfp = 1;
263 module_param(ql2xautodetectsfp, int, 0444);
264 MODULE_PARM_DESC(ql2xautodetectsfp,
265 "Detect SFP range and set appropriate distance.\n"
266 "1 (Default): Enable\n");
268 int ql2xenablemsix = 1;
269 module_param(ql2xenablemsix, int, 0444);
270 MODULE_PARM_DESC(ql2xenablemsix,
271 "Set to enable MSI or MSI-X interrupt mechanism.\n"
272 " Default is 1, enable MSI-X interrupt mechanism.\n"
273 " 0 -- enable traditional pin-based mechanism.\n"
274 " 1 -- enable MSI-X interrupt mechanism.\n"
275 " 2 -- enable MSI interrupt mechanism.\n");
277 int qla2xuseresexchforels;
278 module_param(qla2xuseresexchforels, int, 0444);
279 MODULE_PARM_DESC(qla2xuseresexchforels,
280 "Reserve 1/2 of emergency exchanges for ELS.\n"
281 " 0 (default): disabled");
283 static int ql2xprotmask;
284 module_param(ql2xprotmask, int, 0644);
285 MODULE_PARM_DESC(ql2xprotmask,
286 "Override DIF/DIX protection capabilities mask\n"
287 "Default is 0 which sets protection mask based on "
288 "capabilities reported by HBA firmware.\n");
290 static int ql2xprotguard;
291 module_param(ql2xprotguard, int, 0644);
292 MODULE_PARM_DESC(ql2xprotguard, "Override choice of DIX checksum\n"
293 " 0 -- Let HBA firmware decide\n"
294 " 1 -- Force T10 CRC\n"
295 " 2 -- Force IP checksum\n");
297 int ql2xdifbundlinginternalbuffers;
298 module_param(ql2xdifbundlinginternalbuffers, int, 0644);
299 MODULE_PARM_DESC(ql2xdifbundlinginternalbuffers,
300 "Force using internal buffers for DIF information\n"
301 "0 (Default). Based on check.\n"
302 "1 Force using internal buffers\n");
304 static void qla2x00_clear_drv_active(struct qla_hw_data *);
305 static void qla2x00_free_device(scsi_qla_host_t *);
306 static int qla2xxx_map_queues(struct Scsi_Host *shost);
307 static void qla2x00_destroy_deferred_work(struct qla_hw_data *);
310 static struct scsi_transport_template *qla2xxx_transport_template = NULL;
311 struct scsi_transport_template *qla2xxx_transport_vport_template = NULL;
313 /* TODO Convert to inlines
319 qla2x00_start_timer(scsi_qla_host_t *vha, unsigned long interval)
321 timer_setup(&vha->timer, qla2x00_timer, 0);
322 vha->timer.expires = jiffies + interval * HZ;
323 add_timer(&vha->timer);
324 vha->timer_active = 1;
328 qla2x00_restart_timer(scsi_qla_host_t *vha, unsigned long interval)
330 /* Currently used for 82XX only. */
331 if (vha->device_flags & DFLG_DEV_FAILED) {
332 ql_dbg(ql_dbg_timer, vha, 0x600d,
333 "Device in a failed state, returning.\n");
337 mod_timer(&vha->timer, jiffies + interval * HZ);
340 static __inline__ void
341 qla2x00_stop_timer(scsi_qla_host_t *vha)
343 del_timer_sync(&vha->timer);
344 vha->timer_active = 0;
347 static int qla2x00_do_dpc(void *data);
349 static void qla2x00_rst_aen(scsi_qla_host_t *);
351 static int qla2x00_mem_alloc(struct qla_hw_data *, uint16_t, uint16_t,
352 struct req_que **, struct rsp_que **);
353 static void qla2x00_free_fw_dump(struct qla_hw_data *);
354 static void qla2x00_mem_free(struct qla_hw_data *);
355 int qla2xxx_mqueuecommand(struct Scsi_Host *host, struct scsi_cmnd *cmd,
356 struct qla_qpair *qpair);
358 /* -------------------------------------------------------------------------- */
359 static void qla_init_base_qpair(struct scsi_qla_host *vha, struct req_que *req,
362 struct qla_hw_data *ha = vha->hw;
364 rsp->qpair = ha->base_qpair;
366 ha->base_qpair->hw = ha;
367 ha->base_qpair->req = req;
368 ha->base_qpair->rsp = rsp;
369 ha->base_qpair->vha = vha;
370 ha->base_qpair->qp_lock_ptr = &ha->hardware_lock;
371 ha->base_qpair->use_shadow_reg = IS_SHADOW_REG_CAPABLE(ha) ? 1 : 0;
372 ha->base_qpair->msix = &ha->msix_entries[QLA_MSIX_RSP_Q];
373 ha->base_qpair->srb_mempool = ha->srb_mempool;
374 INIT_LIST_HEAD(&ha->base_qpair->hints_list);
375 ha->base_qpair->enable_class_2 = ql2xenableclass2;
376 /* init qpair to this cpu. Will adjust at run time. */
377 qla_cpu_update(rsp->qpair, raw_smp_processor_id());
378 ha->base_qpair->pdev = ha->pdev;
380 if (IS_QLA27XX(ha) || IS_QLA83XX(ha) || IS_QLA28XX(ha))
381 ha->base_qpair->reqq_start_iocbs = qla_83xx_start_iocbs;
384 static int qla2x00_alloc_queues(struct qla_hw_data *ha, struct req_que *req,
387 scsi_qla_host_t *vha = pci_get_drvdata(ha->pdev);
389 ha->req_q_map = kcalloc(ha->max_req_queues, sizeof(struct req_que *),
391 if (!ha->req_q_map) {
392 ql_log(ql_log_fatal, vha, 0x003b,
393 "Unable to allocate memory for request queue ptrs.\n");
397 ha->rsp_q_map = kcalloc(ha->max_rsp_queues, sizeof(struct rsp_que *),
399 if (!ha->rsp_q_map) {
400 ql_log(ql_log_fatal, vha, 0x003c,
401 "Unable to allocate memory for response queue ptrs.\n");
405 ha->base_qpair = kzalloc(sizeof(struct qla_qpair), GFP_KERNEL);
406 if (ha->base_qpair == NULL) {
407 ql_log(ql_log_warn, vha, 0x00e0,
408 "Failed to allocate base queue pair memory.\n");
409 goto fail_base_qpair;
412 qla_init_base_qpair(vha, req, rsp);
414 if ((ql2xmqsupport || ql2xnvmeenable) && ha->max_qpairs) {
415 ha->queue_pair_map = kcalloc(ha->max_qpairs, sizeof(struct qla_qpair *),
417 if (!ha->queue_pair_map) {
418 ql_log(ql_log_fatal, vha, 0x0180,
419 "Unable to allocate memory for queue pair ptrs.\n");
425 * Make sure we record at least the request and response queue zero in
426 * case we need to free them if part of the probe fails.
428 ha->rsp_q_map[0] = rsp;
429 ha->req_q_map[0] = req;
430 set_bit(0, ha->rsp_qid_map);
431 set_bit(0, ha->req_qid_map);
435 kfree(ha->base_qpair);
436 ha->base_qpair = NULL;
438 kfree(ha->rsp_q_map);
439 ha->rsp_q_map = NULL;
441 kfree(ha->req_q_map);
442 ha->req_q_map = NULL;
447 static void qla2x00_free_req_que(struct qla_hw_data *ha, struct req_que *req)
449 if (IS_QLAFX00(ha)) {
450 if (req && req->ring_fx00)
451 dma_free_coherent(&ha->pdev->dev,
452 (req->length_fx00 + 1) * sizeof(request_t),
453 req->ring_fx00, req->dma_fx00);
454 } else if (req && req->ring)
455 dma_free_coherent(&ha->pdev->dev,
456 (req->length + 1) * sizeof(request_t),
457 req->ring, req->dma);
460 kfree(req->outstanding_cmds);
465 static void qla2x00_free_rsp_que(struct qla_hw_data *ha, struct rsp_que *rsp)
467 if (IS_QLAFX00(ha)) {
468 if (rsp && rsp->ring_fx00)
469 dma_free_coherent(&ha->pdev->dev,
470 (rsp->length_fx00 + 1) * sizeof(request_t),
471 rsp->ring_fx00, rsp->dma_fx00);
472 } else if (rsp && rsp->ring) {
473 dma_free_coherent(&ha->pdev->dev,
474 (rsp->length + 1) * sizeof(response_t),
475 rsp->ring, rsp->dma);
480 static void qla2x00_free_queues(struct qla_hw_data *ha)
487 if (ha->queue_pair_map) {
488 kfree(ha->queue_pair_map);
489 ha->queue_pair_map = NULL;
491 if (ha->base_qpair) {
492 kfree(ha->base_qpair);
493 ha->base_qpair = NULL;
496 spin_lock_irqsave(&ha->hardware_lock, flags);
497 for (cnt = 0; cnt < ha->max_req_queues; cnt++) {
498 if (!test_bit(cnt, ha->req_qid_map))
501 req = ha->req_q_map[cnt];
502 clear_bit(cnt, ha->req_qid_map);
503 ha->req_q_map[cnt] = NULL;
505 spin_unlock_irqrestore(&ha->hardware_lock, flags);
506 qla2x00_free_req_que(ha, req);
507 spin_lock_irqsave(&ha->hardware_lock, flags);
509 spin_unlock_irqrestore(&ha->hardware_lock, flags);
511 kfree(ha->req_q_map);
512 ha->req_q_map = NULL;
515 spin_lock_irqsave(&ha->hardware_lock, flags);
516 for (cnt = 0; cnt < ha->max_rsp_queues; cnt++) {
517 if (!test_bit(cnt, ha->rsp_qid_map))
520 rsp = ha->rsp_q_map[cnt];
521 clear_bit(cnt, ha->rsp_qid_map);
522 ha->rsp_q_map[cnt] = NULL;
523 spin_unlock_irqrestore(&ha->hardware_lock, flags);
524 qla2x00_free_rsp_que(ha, rsp);
525 spin_lock_irqsave(&ha->hardware_lock, flags);
527 spin_unlock_irqrestore(&ha->hardware_lock, flags);
529 kfree(ha->rsp_q_map);
530 ha->rsp_q_map = NULL;
534 qla2x00_pci_info_str(struct scsi_qla_host *vha, char *str, size_t str_len)
536 struct qla_hw_data *ha = vha->hw;
537 static const char *const pci_bus_modes[] = {
538 "33", "66", "100", "133",
542 pci_bus = (ha->pci_attr & (BIT_9 | BIT_10)) >> 9;
544 snprintf(str, str_len, "PCI-X (%s MHz)",
545 pci_bus_modes[pci_bus]);
547 pci_bus = (ha->pci_attr & BIT_8) >> 8;
548 snprintf(str, str_len, "PCI (%s MHz)", pci_bus_modes[pci_bus]);
555 qla24xx_pci_info_str(struct scsi_qla_host *vha, char *str, size_t str_len)
557 static const char *const pci_bus_modes[] = {
558 "33", "66", "100", "133",
560 struct qla_hw_data *ha = vha->hw;
563 if (pci_is_pcie(ha->pdev)) {
564 uint32_t lstat, lspeed, lwidth;
565 const char *speed_str;
567 pcie_capability_read_dword(ha->pdev, PCI_EXP_LNKCAP, &lstat);
568 lspeed = lstat & PCI_EXP_LNKCAP_SLS;
569 lwidth = (lstat & PCI_EXP_LNKCAP_MLW) >> 4;
573 speed_str = "2.5GT/s";
576 speed_str = "5.0GT/s";
579 speed_str = "8.0GT/s";
582 speed_str = "<unknown>";
585 snprintf(str, str_len, "PCIe (%s x%d)", speed_str, lwidth);
590 pci_bus = (ha->pci_attr & CSRX_PCIX_BUS_MODE_MASK) >> 8;
591 if (pci_bus == 0 || pci_bus == 8)
592 snprintf(str, str_len, "PCI (%s MHz)",
593 pci_bus_modes[pci_bus >> 3]);
595 snprintf(str, str_len, "PCI-X Mode %d (%s MHz)",
597 pci_bus_modes[pci_bus & 3]);
603 qla2x00_fw_version_str(struct scsi_qla_host *vha, char *str, size_t size)
606 struct qla_hw_data *ha = vha->hw;
608 snprintf(str, size, "%d.%02d.%02d ", ha->fw_major_version,
609 ha->fw_minor_version, ha->fw_subminor_version);
611 if (ha->fw_attributes & BIT_9) {
616 switch (ha->fw_attributes & 0xFF) {
630 sprintf(un_str, "(%x)", ha->fw_attributes);
634 if (ha->fw_attributes & 0x100)
641 qla24xx_fw_version_str(struct scsi_qla_host *vha, char *str, size_t size)
643 struct qla_hw_data *ha = vha->hw;
645 snprintf(str, size, "%d.%02d.%02d (%x)", ha->fw_major_version,
646 ha->fw_minor_version, ha->fw_subminor_version, ha->fw_attributes);
650 void qla2x00_sp_free_dma(srb_t *sp)
652 struct qla_hw_data *ha = sp->vha->hw;
653 struct scsi_cmnd *cmd = GET_CMD_SP(sp);
655 if (sp->flags & SRB_DMA_VALID) {
657 sp->flags &= ~SRB_DMA_VALID;
660 if (sp->flags & SRB_CRC_PROT_DMA_VALID) {
661 dma_unmap_sg(&ha->pdev->dev, scsi_prot_sglist(cmd),
662 scsi_prot_sg_count(cmd), cmd->sc_data_direction);
663 sp->flags &= ~SRB_CRC_PROT_DMA_VALID;
666 if (sp->flags & SRB_CRC_CTX_DSD_VALID) {
667 /* List assured to be having elements */
668 qla2x00_clean_dsd_pool(ha, sp->u.scmd.crc_ctx);
669 sp->flags &= ~SRB_CRC_CTX_DSD_VALID;
672 if (sp->flags & SRB_CRC_CTX_DMA_VALID) {
673 struct crc_context *ctx0 = sp->u.scmd.crc_ctx;
675 dma_pool_free(ha->dl_dma_pool, ctx0, ctx0->crc_ctx_dma);
676 sp->flags &= ~SRB_CRC_CTX_DMA_VALID;
679 if (sp->flags & SRB_FCP_CMND_DMA_VALID) {
680 struct ct6_dsd *ctx1 = sp->u.scmd.ct6_ctx;
682 dma_pool_free(ha->fcp_cmnd_dma_pool, ctx1->fcp_cmnd,
684 list_splice(&ctx1->dsd_list, &ha->gbl_dsd_list);
685 ha->gbl_dsd_inuse -= ctx1->dsd_use_cnt;
686 ha->gbl_dsd_avail += ctx1->dsd_use_cnt;
687 mempool_free(ctx1, ha->ctx_mempool);
691 void qla2x00_sp_compl(srb_t *sp, int res)
693 struct scsi_cmnd *cmd = GET_CMD_SP(sp);
694 struct completion *comp = sp->comp;
704 void qla2xxx_qpair_sp_free_dma(srb_t *sp)
706 struct scsi_cmnd *cmd = GET_CMD_SP(sp);
707 struct qla_hw_data *ha = sp->fcport->vha->hw;
709 if (sp->flags & SRB_DMA_VALID) {
711 sp->flags &= ~SRB_DMA_VALID;
714 if (sp->flags & SRB_CRC_PROT_DMA_VALID) {
715 dma_unmap_sg(&ha->pdev->dev, scsi_prot_sglist(cmd),
716 scsi_prot_sg_count(cmd), cmd->sc_data_direction);
717 sp->flags &= ~SRB_CRC_PROT_DMA_VALID;
720 if (sp->flags & SRB_CRC_CTX_DSD_VALID) {
721 /* List assured to be having elements */
722 qla2x00_clean_dsd_pool(ha, sp->u.scmd.crc_ctx);
723 sp->flags &= ~SRB_CRC_CTX_DSD_VALID;
726 if (sp->flags & SRB_DIF_BUNDL_DMA_VALID) {
727 struct crc_context *difctx = sp->u.scmd.crc_ctx;
728 struct dsd_dma *dif_dsd, *nxt_dsd;
730 list_for_each_entry_safe(dif_dsd, nxt_dsd,
731 &difctx->ldif_dma_hndl_list, list) {
732 list_del(&dif_dsd->list);
733 dma_pool_free(ha->dif_bundl_pool, dif_dsd->dsd_addr,
734 dif_dsd->dsd_list_dma);
736 difctx->no_dif_bundl--;
739 list_for_each_entry_safe(dif_dsd, nxt_dsd,
740 &difctx->ldif_dsd_list, list) {
741 list_del(&dif_dsd->list);
742 dma_pool_free(ha->dl_dma_pool, dif_dsd->dsd_addr,
743 dif_dsd->dsd_list_dma);
745 difctx->no_ldif_dsd--;
748 if (difctx->no_ldif_dsd) {
749 ql_dbg(ql_dbg_tgt+ql_dbg_verbose, sp->vha, 0xe022,
750 "%s: difctx->no_ldif_dsd=%x\n",
751 __func__, difctx->no_ldif_dsd);
754 if (difctx->no_dif_bundl) {
755 ql_dbg(ql_dbg_tgt+ql_dbg_verbose, sp->vha, 0xe022,
756 "%s: difctx->no_dif_bundl=%x\n",
757 __func__, difctx->no_dif_bundl);
759 sp->flags &= ~SRB_DIF_BUNDL_DMA_VALID;
762 if (sp->flags & SRB_FCP_CMND_DMA_VALID) {
763 struct ct6_dsd *ctx1 = sp->u.scmd.ct6_ctx;
765 dma_pool_free(ha->fcp_cmnd_dma_pool, ctx1->fcp_cmnd,
767 list_splice(&ctx1->dsd_list, &ha->gbl_dsd_list);
768 ha->gbl_dsd_inuse -= ctx1->dsd_use_cnt;
769 ha->gbl_dsd_avail += ctx1->dsd_use_cnt;
770 mempool_free(ctx1, ha->ctx_mempool);
771 sp->flags &= ~SRB_FCP_CMND_DMA_VALID;
774 if (sp->flags & SRB_CRC_CTX_DMA_VALID) {
775 struct crc_context *ctx0 = sp->u.scmd.crc_ctx;
777 dma_pool_free(ha->dl_dma_pool, ctx0, ctx0->crc_ctx_dma);
778 sp->flags &= ~SRB_CRC_CTX_DMA_VALID;
782 void qla2xxx_qpair_sp_compl(srb_t *sp, int res)
784 struct scsi_cmnd *cmd = GET_CMD_SP(sp);
785 struct completion *comp = sp->comp;
796 qla2xxx_queuecommand(struct Scsi_Host *host, struct scsi_cmnd *cmd)
798 scsi_qla_host_t *vha = shost_priv(host);
799 fc_port_t *fcport = (struct fc_port *) cmd->device->hostdata;
800 struct fc_rport *rport = starget_to_rport(scsi_target(cmd->device));
801 struct qla_hw_data *ha = vha->hw;
802 struct scsi_qla_host *base_vha = pci_get_drvdata(ha->pdev);
806 if (unlikely(test_bit(UNLOADING, &base_vha->dpc_flags)) ||
807 WARN_ON_ONCE(!rport)) {
808 cmd->result = DID_NO_CONNECT << 16;
809 goto qc24_fail_command;
815 struct qla_qpair *qpair = NULL;
817 tag = blk_mq_unique_tag(cmd->request);
818 hwq = blk_mq_unique_tag_to_hwq(tag);
819 qpair = ha->queue_pair_map[hwq];
822 return qla2xxx_mqueuecommand(host, cmd, qpair);
825 if (ha->flags.eeh_busy) {
826 if (ha->flags.pci_channel_io_perm_failure) {
827 ql_dbg(ql_dbg_aer, vha, 0x9010,
828 "PCI Channel IO permanent failure, exiting "
830 cmd->result = DID_NO_CONNECT << 16;
832 ql_dbg(ql_dbg_aer, vha, 0x9011,
833 "EEH_Busy, Requeuing the cmd=%p.\n", cmd);
834 cmd->result = DID_REQUEUE << 16;
836 goto qc24_fail_command;
839 rval = fc_remote_port_chkready(rport);
842 ql_dbg(ql_dbg_io + ql_dbg_verbose, vha, 0x3003,
843 "fc_remote_port_chkready failed for cmd=%p, rval=0x%x.\n",
845 goto qc24_fail_command;
848 if (!vha->flags.difdix_supported &&
849 scsi_get_prot_op(cmd) != SCSI_PROT_NORMAL) {
850 ql_dbg(ql_dbg_io, vha, 0x3004,
851 "DIF Cap not reg, fail DIF capable cmd's:%p.\n",
853 cmd->result = DID_NO_CONNECT << 16;
854 goto qc24_fail_command;
858 cmd->result = DID_NO_CONNECT << 16;
859 goto qc24_fail_command;
862 if (atomic_read(&fcport->state) != FCS_ONLINE) {
863 if (atomic_read(&fcport->state) == FCS_DEVICE_DEAD ||
864 atomic_read(&base_vha->loop_state) == LOOP_DEAD) {
865 ql_dbg(ql_dbg_io, vha, 0x3005,
866 "Returning DNC, fcport_state=%d loop_state=%d.\n",
867 atomic_read(&fcport->state),
868 atomic_read(&base_vha->loop_state));
869 cmd->result = DID_NO_CONNECT << 16;
870 goto qc24_fail_command;
872 goto qc24_target_busy;
876 * Return target busy if we've received a non-zero retry_delay_timer
879 if (fcport->retry_delay_timestamp == 0) {
880 /* retry delay not set */
881 } else if (time_after(jiffies, fcport->retry_delay_timestamp))
882 fcport->retry_delay_timestamp = 0;
884 goto qc24_target_busy;
886 sp = scsi_cmd_priv(cmd);
887 qla2xxx_init_sp(sp, vha, vha->hw->base_qpair, fcport);
889 sp->u.scmd.cmd = cmd;
890 sp->type = SRB_SCSI_CMD;
892 CMD_SP(cmd) = (void *)sp;
893 sp->free = qla2x00_sp_free_dma;
894 sp->done = qla2x00_sp_compl;
896 rval = ha->isp_ops->start_scsi(sp);
897 if (rval != QLA_SUCCESS) {
898 ql_dbg(ql_dbg_io + ql_dbg_verbose, vha, 0x3013,
899 "Start scsi failed rval=%d for cmd=%p.\n", rval, cmd);
900 goto qc24_host_busy_free_sp;
905 qc24_host_busy_free_sp:
909 return SCSI_MLQUEUE_TARGET_BUSY;
917 /* For MQ supported I/O */
919 qla2xxx_mqueuecommand(struct Scsi_Host *host, struct scsi_cmnd *cmd,
920 struct qla_qpair *qpair)
922 scsi_qla_host_t *vha = shost_priv(host);
923 fc_port_t *fcport = (struct fc_port *) cmd->device->hostdata;
924 struct fc_rport *rport = starget_to_rport(scsi_target(cmd->device));
925 struct qla_hw_data *ha = vha->hw;
926 struct scsi_qla_host *base_vha = pci_get_drvdata(ha->pdev);
930 rval = rport ? fc_remote_port_chkready(rport) : FC_PORTSTATE_OFFLINE;
933 ql_dbg(ql_dbg_io + ql_dbg_verbose, vha, 0x3076,
934 "fc_remote_port_chkready failed for cmd=%p, rval=0x%x.\n",
936 goto qc24_fail_command;
940 cmd->result = DID_NO_CONNECT << 16;
941 goto qc24_fail_command;
944 if (atomic_read(&fcport->state) != FCS_ONLINE) {
945 if (atomic_read(&fcport->state) == FCS_DEVICE_DEAD ||
946 atomic_read(&base_vha->loop_state) == LOOP_DEAD) {
947 ql_dbg(ql_dbg_io, vha, 0x3077,
948 "Returning DNC, fcport_state=%d loop_state=%d.\n",
949 atomic_read(&fcport->state),
950 atomic_read(&base_vha->loop_state));
951 cmd->result = DID_NO_CONNECT << 16;
952 goto qc24_fail_command;
954 goto qc24_target_busy;
958 * Return target busy if we've received a non-zero retry_delay_timer
961 if (fcport->retry_delay_timestamp == 0) {
962 /* retry delay not set */
963 } else if (time_after(jiffies, fcport->retry_delay_timestamp))
964 fcport->retry_delay_timestamp = 0;
966 goto qc24_target_busy;
968 sp = scsi_cmd_priv(cmd);
969 qla2xxx_init_sp(sp, vha, qpair, fcport);
971 sp->u.scmd.cmd = cmd;
972 sp->type = SRB_SCSI_CMD;
973 CMD_SP(cmd) = (void *)sp;
974 sp->free = qla2xxx_qpair_sp_free_dma;
975 sp->done = qla2xxx_qpair_sp_compl;
977 rval = ha->isp_ops->start_scsi_mq(sp);
978 if (rval != QLA_SUCCESS) {
979 ql_dbg(ql_dbg_io + ql_dbg_verbose, vha, 0x3078,
980 "Start scsi failed rval=%d for cmd=%p.\n", rval, cmd);
981 goto qc24_host_busy_free_sp;
986 qc24_host_busy_free_sp:
990 return SCSI_MLQUEUE_TARGET_BUSY;
999 * qla2x00_eh_wait_on_command
1000 * Waits for the command to be returned by the Firmware for some
1004 * cmd = Scsi Command to wait on.
1007 * Completed in time : QLA_SUCCESS
1008 * Did not complete in time : QLA_FUNCTION_FAILED
1011 qla2x00_eh_wait_on_command(struct scsi_cmnd *cmd)
1013 #define ABORT_POLLING_PERIOD 1000
1014 #define ABORT_WAIT_ITER ((2 * 1000) / (ABORT_POLLING_PERIOD))
1015 unsigned long wait_iter = ABORT_WAIT_ITER;
1016 scsi_qla_host_t *vha = shost_priv(cmd->device->host);
1017 struct qla_hw_data *ha = vha->hw;
1018 int ret = QLA_SUCCESS;
1020 if (unlikely(pci_channel_offline(ha->pdev)) || ha->flags.eeh_busy) {
1021 ql_dbg(ql_dbg_taskm, vha, 0x8005,
1022 "Return:eh_wait.\n");
1026 while (CMD_SP(cmd) && wait_iter--) {
1027 msleep(ABORT_POLLING_PERIOD);
1030 ret = QLA_FUNCTION_FAILED;
1036 * qla2x00_wait_for_hba_online
1037 * Wait till the HBA is online after going through
1038 * <= MAX_RETRIES_OF_ISP_ABORT or
1039 * finally HBA is disabled ie marked offline
1042 * ha - pointer to host adapter structure
1045 * Does context switching-Release SPIN_LOCK
1046 * (if any) before calling this routine.
1049 * Success (Adapter is online) : 0
1050 * Failed (Adapter is offline/disabled) : 1
1053 qla2x00_wait_for_hba_online(scsi_qla_host_t *vha)
1056 unsigned long wait_online;
1057 struct qla_hw_data *ha = vha->hw;
1058 scsi_qla_host_t *base_vha = pci_get_drvdata(ha->pdev);
1060 wait_online = jiffies + (MAX_LOOP_TIMEOUT * HZ);
1061 while (((test_bit(ISP_ABORT_NEEDED, &base_vha->dpc_flags)) ||
1062 test_bit(ABORT_ISP_ACTIVE, &base_vha->dpc_flags) ||
1063 test_bit(ISP_ABORT_RETRY, &base_vha->dpc_flags) ||
1064 ha->dpc_active) && time_before(jiffies, wait_online)) {
1068 if (base_vha->flags.online)
1069 return_status = QLA_SUCCESS;
1071 return_status = QLA_FUNCTION_FAILED;
1073 return (return_status);
1076 static inline int test_fcport_count(scsi_qla_host_t *vha)
1078 struct qla_hw_data *ha = vha->hw;
1079 unsigned long flags;
1082 spin_lock_irqsave(&ha->tgt.sess_lock, flags);
1083 ql_dbg(ql_dbg_init, vha, 0x00ec,
1084 "tgt %p, fcport_count=%d\n",
1085 vha, vha->fcport_count);
1086 res = (vha->fcport_count == 0);
1087 spin_unlock_irqrestore(&ha->tgt.sess_lock, flags);
1093 * qla2x00_wait_for_sess_deletion can only be called from remove_one.
1094 * it has dependency on UNLOADING flag to stop device discovery
1097 qla2x00_wait_for_sess_deletion(scsi_qla_host_t *vha)
1101 qla2x00_mark_all_devices_lost(vha, 0);
1103 for (i = 0; i < 10; i++) {
1104 if (wait_event_timeout(vha->fcport_waitQ,
1105 test_fcport_count(vha), HZ) > 0)
1109 flush_workqueue(vha->hw->wq);
1113 * qla2x00_wait_for_hba_ready
1114 * Wait till the HBA is ready before doing driver unload
1117 * ha - pointer to host adapter structure
1120 * Does context switching-Release SPIN_LOCK
1121 * (if any) before calling this routine.
1125 qla2x00_wait_for_hba_ready(scsi_qla_host_t *vha)
1127 struct qla_hw_data *ha = vha->hw;
1128 scsi_qla_host_t *base_vha = pci_get_drvdata(ha->pdev);
1130 while ((qla2x00_reset_active(vha) || ha->dpc_active ||
1131 ha->flags.mbox_busy) ||
1132 test_bit(FX00_RESET_RECOVERY, &vha->dpc_flags) ||
1133 test_bit(FX00_TARGET_SCAN, &vha->dpc_flags)) {
1134 if (test_bit(UNLOADING, &base_vha->dpc_flags))
1141 qla2x00_wait_for_chip_reset(scsi_qla_host_t *vha)
1144 unsigned long wait_reset;
1145 struct qla_hw_data *ha = vha->hw;
1146 scsi_qla_host_t *base_vha = pci_get_drvdata(ha->pdev);
1148 wait_reset = jiffies + (MAX_LOOP_TIMEOUT * HZ);
1149 while (((test_bit(ISP_ABORT_NEEDED, &base_vha->dpc_flags)) ||
1150 test_bit(ABORT_ISP_ACTIVE, &base_vha->dpc_flags) ||
1151 test_bit(ISP_ABORT_RETRY, &base_vha->dpc_flags) ||
1152 ha->dpc_active) && time_before(jiffies, wait_reset)) {
1156 if (!test_bit(ISP_ABORT_NEEDED, &base_vha->dpc_flags) &&
1157 ha->flags.chip_reset_done)
1160 if (ha->flags.chip_reset_done)
1161 return_status = QLA_SUCCESS;
1163 return_status = QLA_FUNCTION_FAILED;
1165 return return_status;
1168 #define ISP_REG_DISCONNECT 0xffffffffU
1169 /**************************************************************************
1170 * qla2x00_isp_reg_stat
1173 * Read the host status register of ISP before aborting the command.
1176 * ha = pointer to host adapter structure.
1180 * Either true or false.
1182 * Note: Return true if there is register disconnect.
1183 **************************************************************************/
1185 uint32_t qla2x00_isp_reg_stat(struct qla_hw_data *ha)
1187 struct device_reg_24xx __iomem *reg = &ha->iobase->isp24;
1188 struct device_reg_82xx __iomem *reg82 = &ha->iobase->isp82;
1190 if (IS_P3P_TYPE(ha))
1191 return ((RD_REG_DWORD(®82->host_int)) == ISP_REG_DISCONNECT);
1193 return ((RD_REG_DWORD(®->host_status)) ==
1194 ISP_REG_DISCONNECT);
1197 /**************************************************************************
1201 * The abort function will abort the specified command.
1204 * cmd = Linux SCSI command packet to be aborted.
1207 * Either SUCCESS or FAILED.
1210 * Only return FAILED if command not returned by firmware.
1211 **************************************************************************/
1213 qla2xxx_eh_abort(struct scsi_cmnd *cmd)
1215 scsi_qla_host_t *vha = shost_priv(cmd->device->host);
1216 DECLARE_COMPLETION_ONSTACK(comp);
1222 struct qla_hw_data *ha = vha->hw;
1224 struct qla_qpair *qpair;
1225 unsigned long flags;
1226 int fast_fail_status = SUCCESS;
1228 if (qla2x00_isp_reg_stat(ha)) {
1229 ql_log(ql_log_info, vha, 0x8042,
1230 "PCI/Register disconnect, exiting.\n");
1234 /* Save any FAST_IO_FAIL value to return later if abort succeeds */
1235 ret = fc_block_scsi_eh(cmd);
1237 fast_fail_status = ret;
1239 sp = scsi_cmd_priv(cmd);
1242 if ((sp->fcport && sp->fcport->deleted) || !qpair)
1243 return fast_fail_status != SUCCESS ? fast_fail_status : FAILED;
1245 spin_lock_irqsave(qpair->qp_lock_ptr, flags);
1246 if (sp->completed) {
1247 spin_unlock_irqrestore(qpair->qp_lock_ptr, flags);
1251 if (sp->abort || sp->aborted) {
1252 spin_unlock_irqrestore(qpair->qp_lock_ptr, flags);
1258 spin_unlock_irqrestore(qpair->qp_lock_ptr, flags);
1261 id = cmd->device->id;
1262 lun = cmd->device->lun;
1264 ql_dbg(ql_dbg_taskm, vha, 0x8002,
1265 "Aborting from RISC nexus=%ld:%d:%llu sp=%p cmd=%p handle=%x\n",
1266 vha->host_no, id, lun, sp, cmd, sp->handle);
1269 * Abort will release the original Command/sp from FW. Let the
1270 * original command call scsi_done. In return, he will wakeup
1271 * this sleeping thread.
1273 rval = ha->isp_ops->abort_command(sp);
1275 ql_dbg(ql_dbg_taskm, vha, 0x8003,
1276 "Abort command mbx cmd=%p, rval=%x.\n", cmd, rval);
1278 /* Wait for the command completion. */
1279 ratov_j = ha->r_a_tov/10 * 4 * 1000;
1280 ratov_j = msecs_to_jiffies(ratov_j);
1283 if (!wait_for_completion_timeout(&comp, ratov_j)) {
1284 ql_dbg(ql_dbg_taskm, vha, 0xffff,
1285 "%s: Abort wait timer (4 * R_A_TOV[%d]) expired\n",
1286 __func__, ha->r_a_tov/10);
1289 ret = fast_fail_status;
1299 ql_log(ql_log_info, vha, 0x801c,
1300 "Abort command issued nexus=%ld:%d:%llu -- %x.\n",
1301 vha->host_no, id, lun, ret);
1307 * Returns: QLA_SUCCESS or QLA_FUNCTION_FAILED.
1310 qla2x00_eh_wait_for_pending_commands(scsi_qla_host_t *vha, unsigned int t,
1311 uint64_t l, enum nexus_wait_type type)
1313 int cnt, match, status;
1314 unsigned long flags;
1315 struct qla_hw_data *ha = vha->hw;
1316 struct req_que *req;
1318 struct scsi_cmnd *cmd;
1320 status = QLA_SUCCESS;
1322 spin_lock_irqsave(&ha->hardware_lock, flags);
1324 for (cnt = 1; status == QLA_SUCCESS &&
1325 cnt < req->num_outstanding_cmds; cnt++) {
1326 sp = req->outstanding_cmds[cnt];
1329 if (sp->type != SRB_SCSI_CMD)
1331 if (vha->vp_idx != sp->vha->vp_idx)
1334 cmd = GET_CMD_SP(sp);
1340 match = cmd->device->id == t;
1343 match = (cmd->device->id == t &&
1344 cmd->device->lun == l);
1350 spin_unlock_irqrestore(&ha->hardware_lock, flags);
1351 status = qla2x00_eh_wait_on_command(cmd);
1352 spin_lock_irqsave(&ha->hardware_lock, flags);
1354 spin_unlock_irqrestore(&ha->hardware_lock, flags);
1359 static char *reset_errors[] = {
1362 "Task management failed",
1363 "Waiting for command completions",
1367 __qla2xxx_eh_generic_reset(char *name, enum nexus_wait_type type,
1368 struct scsi_cmnd *cmd, int (*do_reset)(struct fc_port *, uint64_t, int))
1370 scsi_qla_host_t *vha = shost_priv(cmd->device->host);
1371 fc_port_t *fcport = (struct fc_port *) cmd->device->hostdata;
1378 err = fc_block_scsi_eh(cmd);
1382 if (fcport->deleted)
1385 ql_log(ql_log_info, vha, 0x8009,
1386 "%s RESET ISSUED nexus=%ld:%d:%llu cmd=%p.\n", name, vha->host_no,
1387 cmd->device->id, cmd->device->lun, cmd);
1390 if (qla2x00_wait_for_hba_online(vha) != QLA_SUCCESS) {
1391 ql_log(ql_log_warn, vha, 0x800a,
1392 "Wait for hba online failed for cmd=%p.\n", cmd);
1393 goto eh_reset_failed;
1396 if (do_reset(fcport, cmd->device->lun, 1)
1398 ql_log(ql_log_warn, vha, 0x800c,
1399 "do_reset failed for cmd=%p.\n", cmd);
1400 goto eh_reset_failed;
1403 if (qla2x00_eh_wait_for_pending_commands(vha, cmd->device->id,
1404 cmd->device->lun, type) != QLA_SUCCESS) {
1405 ql_log(ql_log_warn, vha, 0x800d,
1406 "wait for pending cmds failed for cmd=%p.\n", cmd);
1407 goto eh_reset_failed;
1410 ql_log(ql_log_info, vha, 0x800e,
1411 "%s RESET SUCCEEDED nexus:%ld:%d:%llu cmd=%p.\n", name,
1412 vha->host_no, cmd->device->id, cmd->device->lun, cmd);
1417 ql_log(ql_log_info, vha, 0x800f,
1418 "%s RESET FAILED: %s nexus=%ld:%d:%llu cmd=%p.\n", name,
1419 reset_errors[err], vha->host_no, cmd->device->id, cmd->device->lun,
1425 qla2xxx_eh_device_reset(struct scsi_cmnd *cmd)
1427 scsi_qla_host_t *vha = shost_priv(cmd->device->host);
1428 struct qla_hw_data *ha = vha->hw;
1430 if (qla2x00_isp_reg_stat(ha)) {
1431 ql_log(ql_log_info, vha, 0x803e,
1432 "PCI/Register disconnect, exiting.\n");
1436 return __qla2xxx_eh_generic_reset("DEVICE", WAIT_LUN, cmd,
1437 ha->isp_ops->lun_reset);
1441 qla2xxx_eh_target_reset(struct scsi_cmnd *cmd)
1443 scsi_qla_host_t *vha = shost_priv(cmd->device->host);
1444 struct qla_hw_data *ha = vha->hw;
1446 if (qla2x00_isp_reg_stat(ha)) {
1447 ql_log(ql_log_info, vha, 0x803f,
1448 "PCI/Register disconnect, exiting.\n");
1452 return __qla2xxx_eh_generic_reset("TARGET", WAIT_TARGET, cmd,
1453 ha->isp_ops->target_reset);
1456 /**************************************************************************
1457 * qla2xxx_eh_bus_reset
1460 * The bus reset function will reset the bus and abort any executing
1464 * cmd = Linux SCSI command packet of the command that cause the
1468 * SUCCESS/FAILURE (defined as macro in scsi.h).
1470 **************************************************************************/
1472 qla2xxx_eh_bus_reset(struct scsi_cmnd *cmd)
1474 scsi_qla_host_t *vha = shost_priv(cmd->device->host);
1475 fc_port_t *fcport = (struct fc_port *) cmd->device->hostdata;
1479 struct qla_hw_data *ha = vha->hw;
1481 if (qla2x00_isp_reg_stat(ha)) {
1482 ql_log(ql_log_info, vha, 0x8040,
1483 "PCI/Register disconnect, exiting.\n");
1487 id = cmd->device->id;
1488 lun = cmd->device->lun;
1494 ret = fc_block_scsi_eh(cmd);
1499 if (qla2x00_chip_is_down(vha))
1502 ql_log(ql_log_info, vha, 0x8012,
1503 "BUS RESET ISSUED nexus=%ld:%d:%llu.\n", vha->host_no, id, lun);
1505 if (qla2x00_wait_for_hba_online(vha) != QLA_SUCCESS) {
1506 ql_log(ql_log_fatal, vha, 0x8013,
1507 "Wait for hba online failed board disabled.\n");
1508 goto eh_bus_reset_done;
1511 if (qla2x00_loop_reset(vha) == QLA_SUCCESS)
1515 goto eh_bus_reset_done;
1517 /* Flush outstanding commands. */
1518 if (qla2x00_eh_wait_for_pending_commands(vha, 0, 0, WAIT_HOST) !=
1520 ql_log(ql_log_warn, vha, 0x8014,
1521 "Wait for pending commands failed.\n");
1526 ql_log(ql_log_warn, vha, 0x802b,
1527 "BUS RESET %s nexus=%ld:%d:%llu.\n",
1528 (ret == FAILED) ? "FAILED" : "SUCCEEDED", vha->host_no, id, lun);
1533 /**************************************************************************
1534 * qla2xxx_eh_host_reset
1537 * The reset function will reset the Adapter.
1540 * cmd = Linux SCSI command packet of the command that cause the
1544 * Either SUCCESS or FAILED.
1547 **************************************************************************/
1549 qla2xxx_eh_host_reset(struct scsi_cmnd *cmd)
1551 scsi_qla_host_t *vha = shost_priv(cmd->device->host);
1552 struct qla_hw_data *ha = vha->hw;
1556 scsi_qla_host_t *base_vha = pci_get_drvdata(ha->pdev);
1558 if (qla2x00_isp_reg_stat(ha)) {
1559 ql_log(ql_log_info, vha, 0x8041,
1560 "PCI/Register disconnect, exiting.\n");
1561 schedule_work(&ha->board_disable);
1565 id = cmd->device->id;
1566 lun = cmd->device->lun;
1568 ql_log(ql_log_info, vha, 0x8018,
1569 "ADAPTER RESET ISSUED nexus=%ld:%d:%llu.\n", vha->host_no, id, lun);
1572 * No point in issuing another reset if one is active. Also do not
1573 * attempt a reset if we are updating flash.
1575 if (qla2x00_reset_active(vha) || ha->optrom_state != QLA_SWAITING)
1576 goto eh_host_reset_lock;
1578 if (vha != base_vha) {
1579 if (qla2x00_vp_abort_isp(vha))
1580 goto eh_host_reset_lock;
1582 if (IS_P3P_TYPE(vha->hw)) {
1583 if (!qla82xx_fcoe_ctx_reset(vha)) {
1584 /* Ctx reset success */
1586 goto eh_host_reset_lock;
1588 /* fall thru if ctx reset failed */
1591 flush_workqueue(ha->wq);
1593 set_bit(ABORT_ISP_ACTIVE, &base_vha->dpc_flags);
1594 if (ha->isp_ops->abort_isp(base_vha)) {
1595 clear_bit(ABORT_ISP_ACTIVE, &base_vha->dpc_flags);
1596 /* failed. schedule dpc to try */
1597 set_bit(ISP_ABORT_NEEDED, &base_vha->dpc_flags);
1599 if (qla2x00_wait_for_hba_online(vha) != QLA_SUCCESS) {
1600 ql_log(ql_log_warn, vha, 0x802a,
1601 "wait for hba online failed.\n");
1602 goto eh_host_reset_lock;
1605 clear_bit(ABORT_ISP_ACTIVE, &base_vha->dpc_flags);
1608 /* Waiting for command to be returned to OS.*/
1609 if (qla2x00_eh_wait_for_pending_commands(vha, 0, 0, WAIT_HOST) ==
1614 ql_log(ql_log_info, vha, 0x8017,
1615 "ADAPTER RESET %s nexus=%ld:%d:%llu.\n",
1616 (ret == FAILED) ? "FAILED" : "SUCCEEDED", vha->host_no, id, lun);
1622 * qla2x00_loop_reset
1626 * ha = adapter block pointer.
1632 qla2x00_loop_reset(scsi_qla_host_t *vha)
1635 struct qla_hw_data *ha = vha->hw;
1640 if (ha->flags.enable_lip_full_login && !IS_CNA_CAPABLE(ha)) {
1641 atomic_set(&vha->loop_state, LOOP_DOWN);
1642 atomic_set(&vha->loop_down_timer, LOOP_DOWN_TIME);
1643 qla2x00_mark_all_devices_lost(vha, 0);
1644 ret = qla2x00_full_login_lip(vha);
1645 if (ret != QLA_SUCCESS) {
1646 ql_dbg(ql_dbg_taskm, vha, 0x802d,
1647 "full_login_lip=%d.\n", ret);
1651 if (ha->flags.enable_lip_reset) {
1652 ret = qla2x00_lip_reset(vha);
1653 if (ret != QLA_SUCCESS)
1654 ql_dbg(ql_dbg_taskm, vha, 0x802e,
1655 "lip_reset failed (%d).\n", ret);
1658 /* Issue marker command only when we are going to start the I/O */
1659 vha->marker_needed = 1;
1664 static void qla2x00_abort_srb(struct qla_qpair *qp, srb_t *sp, const int res,
1665 unsigned long *flags)
1666 __releases(qp->qp_lock_ptr)
1667 __acquires(qp->qp_lock_ptr)
1669 DECLARE_COMPLETION_ONSTACK(comp);
1670 scsi_qla_host_t *vha = qp->vha;
1671 struct qla_hw_data *ha = vha->hw;
1676 if (qla2x00_chip_is_down(vha)) {
1681 if (sp->type == SRB_NVME_CMD || sp->type == SRB_NVME_LS ||
1682 (sp->type == SRB_SCSI_CMD && !ha->flags.eeh_busy &&
1683 !test_bit(ABORT_ISP_ACTIVE, &vha->dpc_flags) &&
1684 !qla2x00_isp_reg_stat(ha))) {
1692 spin_unlock_irqrestore(qp->qp_lock_ptr, *flags);
1694 rval = ha->isp_ops->abort_command(sp);
1695 /* Wait for command completion. */
1697 ratov_j = ha->r_a_tov/10 * 4 * 1000;
1698 ratov_j = msecs_to_jiffies(ratov_j);
1701 if (wait_for_completion_timeout(&comp, ratov_j)) {
1702 ql_dbg(ql_dbg_taskm, vha, 0xffff,
1703 "%s: Abort wait timer (4 * R_A_TOV[%d]) expired\n",
1704 __func__, ha->r_a_tov/10);
1707 /* else FW return SP to driver */
1714 spin_lock_irqsave(qp->qp_lock_ptr, *flags);
1715 if (ret_cmd && (!sp->completed || !sp->aborted))
1723 __qla2x00_abort_all_cmds(struct qla_qpair *qp, int res)
1726 unsigned long flags;
1728 scsi_qla_host_t *vha = qp->vha;
1729 struct qla_hw_data *ha = vha->hw;
1730 struct req_que *req;
1731 struct qla_tgt *tgt = vha->vha_tgt.qla_tgt;
1732 struct qla_tgt_cmd *cmd;
1736 spin_lock_irqsave(qp->qp_lock_ptr, flags);
1738 for (cnt = 1; cnt < req->num_outstanding_cmds; cnt++) {
1739 sp = req->outstanding_cmds[cnt];
1741 switch (sp->cmd_type) {
1743 qla2x00_abort_srb(qp, sp, res, &flags);
1746 if (!vha->hw->tgt.tgt_ops || !tgt ||
1747 qla_ini_mode_enabled(vha)) {
1748 ql_dbg(ql_dbg_tgt_mgt, vha, 0xf003,
1749 "HOST-ABORT-HNDLR: dpc_flags=%lx. Target mode disabled\n",
1753 cmd = (struct qla_tgt_cmd *)sp;
1756 case TYPE_TGT_TMCMD:
1757 /* Skip task management functions. */
1762 req->outstanding_cmds[cnt] = NULL;
1765 spin_unlock_irqrestore(qp->qp_lock_ptr, flags);
1769 qla2x00_abort_all_cmds(scsi_qla_host_t *vha, int res)
1772 struct qla_hw_data *ha = vha->hw;
1774 /* Continue only if initialization complete. */
1775 if (!ha->base_qpair)
1777 __qla2x00_abort_all_cmds(ha->base_qpair, res);
1779 if (!ha->queue_pair_map)
1781 for (que = 0; que < ha->max_qpairs; que++) {
1782 if (!ha->queue_pair_map[que])
1785 __qla2x00_abort_all_cmds(ha->queue_pair_map[que], res);
1790 qla2xxx_slave_alloc(struct scsi_device *sdev)
1792 struct fc_rport *rport = starget_to_rport(scsi_target(sdev));
1794 if (!rport || fc_remote_port_chkready(rport))
1797 sdev->hostdata = *(fc_port_t **)rport->dd_data;
1803 qla2xxx_slave_configure(struct scsi_device *sdev)
1805 scsi_qla_host_t *vha = shost_priv(sdev->host);
1806 struct req_que *req = vha->req;
1808 if (IS_T10_PI_CAPABLE(vha->hw))
1809 blk_queue_update_dma_alignment(sdev->request_queue, 0x7);
1811 scsi_change_queue_depth(sdev, req->max_q_depth);
1816 qla2xxx_slave_destroy(struct scsi_device *sdev)
1818 sdev->hostdata = NULL;
1822 * qla2x00_config_dma_addressing() - Configure OS DMA addressing method.
1825 * At exit, the @ha's flags.enable_64bit_addressing set to indicated
1826 * supported addressing method.
1829 qla2x00_config_dma_addressing(struct qla_hw_data *ha)
1831 /* Assume a 32bit DMA mask. */
1832 ha->flags.enable_64bit_addressing = 0;
1834 if (!dma_set_mask(&ha->pdev->dev, DMA_BIT_MASK(64))) {
1835 /* Any upper-dword bits set? */
1836 if (MSD(dma_get_required_mask(&ha->pdev->dev)) &&
1837 !pci_set_consistent_dma_mask(ha->pdev, DMA_BIT_MASK(64))) {
1838 /* Ok, a 64bit DMA mask is applicable. */
1839 ha->flags.enable_64bit_addressing = 1;
1840 ha->isp_ops->calc_req_entries = qla2x00_calc_iocbs_64;
1841 ha->isp_ops->build_iocbs = qla2x00_build_scsi_iocbs_64;
1846 dma_set_mask(&ha->pdev->dev, DMA_BIT_MASK(32));
1847 pci_set_consistent_dma_mask(ha->pdev, DMA_BIT_MASK(32));
1851 qla2x00_enable_intrs(struct qla_hw_data *ha)
1853 unsigned long flags = 0;
1854 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
1856 spin_lock_irqsave(&ha->hardware_lock, flags);
1857 ha->interrupts_on = 1;
1858 /* enable risc and host interrupts */
1859 WRT_REG_WORD(®->ictrl, ICR_EN_INT | ICR_EN_RISC);
1860 RD_REG_WORD(®->ictrl);
1861 spin_unlock_irqrestore(&ha->hardware_lock, flags);
1866 qla2x00_disable_intrs(struct qla_hw_data *ha)
1868 unsigned long flags = 0;
1869 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
1871 spin_lock_irqsave(&ha->hardware_lock, flags);
1872 ha->interrupts_on = 0;
1873 /* disable risc and host interrupts */
1874 WRT_REG_WORD(®->ictrl, 0);
1875 RD_REG_WORD(®->ictrl);
1876 spin_unlock_irqrestore(&ha->hardware_lock, flags);
1880 qla24xx_enable_intrs(struct qla_hw_data *ha)
1882 unsigned long flags = 0;
1883 struct device_reg_24xx __iomem *reg = &ha->iobase->isp24;
1885 spin_lock_irqsave(&ha->hardware_lock, flags);
1886 ha->interrupts_on = 1;
1887 WRT_REG_DWORD(®->ictrl, ICRX_EN_RISC_INT);
1888 RD_REG_DWORD(®->ictrl);
1889 spin_unlock_irqrestore(&ha->hardware_lock, flags);
1893 qla24xx_disable_intrs(struct qla_hw_data *ha)
1895 unsigned long flags = 0;
1896 struct device_reg_24xx __iomem *reg = &ha->iobase->isp24;
1898 if (IS_NOPOLLING_TYPE(ha))
1900 spin_lock_irqsave(&ha->hardware_lock, flags);
1901 ha->interrupts_on = 0;
1902 WRT_REG_DWORD(®->ictrl, 0);
1903 RD_REG_DWORD(®->ictrl);
1904 spin_unlock_irqrestore(&ha->hardware_lock, flags);
1908 qla2x00_iospace_config(struct qla_hw_data *ha)
1910 resource_size_t pio;
1913 if (pci_request_selected_regions(ha->pdev, ha->bars,
1914 QLA2XXX_DRIVER_NAME)) {
1915 ql_log_pci(ql_log_fatal, ha->pdev, 0x0011,
1916 "Failed to reserve PIO/MMIO regions (%s), aborting.\n",
1917 pci_name(ha->pdev));
1918 goto iospace_error_exit;
1920 if (!(ha->bars & 1))
1923 /* We only need PIO for Flash operations on ISP2312 v2 chips. */
1924 pio = pci_resource_start(ha->pdev, 0);
1925 if (pci_resource_flags(ha->pdev, 0) & IORESOURCE_IO) {
1926 if (pci_resource_len(ha->pdev, 0) < MIN_IOBASE_LEN) {
1927 ql_log_pci(ql_log_warn, ha->pdev, 0x0012,
1928 "Invalid pci I/O region size (%s).\n",
1929 pci_name(ha->pdev));
1933 ql_log_pci(ql_log_warn, ha->pdev, 0x0013,
1934 "Region #0 no a PIO resource (%s).\n",
1935 pci_name(ha->pdev));
1938 ha->pio_address = pio;
1939 ql_dbg_pci(ql_dbg_init, ha->pdev, 0x0014,
1940 "PIO address=%llu.\n",
1941 (unsigned long long)ha->pio_address);
1944 /* Use MMIO operations for all accesses. */
1945 if (!(pci_resource_flags(ha->pdev, 1) & IORESOURCE_MEM)) {
1946 ql_log_pci(ql_log_fatal, ha->pdev, 0x0015,
1947 "Region #1 not an MMIO resource (%s), aborting.\n",
1948 pci_name(ha->pdev));
1949 goto iospace_error_exit;
1951 if (pci_resource_len(ha->pdev, 1) < MIN_IOBASE_LEN) {
1952 ql_log_pci(ql_log_fatal, ha->pdev, 0x0016,
1953 "Invalid PCI mem region size (%s), aborting.\n",
1954 pci_name(ha->pdev));
1955 goto iospace_error_exit;
1958 ha->iobase = ioremap(pci_resource_start(ha->pdev, 1), MIN_IOBASE_LEN);
1960 ql_log_pci(ql_log_fatal, ha->pdev, 0x0017,
1961 "Cannot remap MMIO (%s), aborting.\n",
1962 pci_name(ha->pdev));
1963 goto iospace_error_exit;
1966 /* Determine queue resources */
1967 ha->max_req_queues = ha->max_rsp_queues = 1;
1968 ha->msix_count = QLA_BASE_VECTORS;
1970 /* Check if FW supports MQ or not */
1971 if (!(ha->fw_attributes & BIT_6))
1974 if (!ql2xmqsupport || !ql2xnvmeenable ||
1975 (!IS_QLA25XX(ha) && !IS_QLA81XX(ha)))
1978 ha->mqiobase = ioremap(pci_resource_start(ha->pdev, 3),
1979 pci_resource_len(ha->pdev, 3));
1981 ql_dbg_pci(ql_dbg_init, ha->pdev, 0x0018,
1982 "MQIO Base=%p.\n", ha->mqiobase);
1983 /* Read MSIX vector size of the board */
1984 pci_read_config_word(ha->pdev, QLA_PCI_MSIX_CONTROL, &msix);
1985 ha->msix_count = msix + 1;
1986 /* Max queues are bounded by available msix vectors */
1987 /* MB interrupt uses 1 vector */
1988 ha->max_req_queues = ha->msix_count - 1;
1989 ha->max_rsp_queues = ha->max_req_queues;
1990 /* Queue pairs is the max value minus the base queue pair */
1991 ha->max_qpairs = ha->max_rsp_queues - 1;
1992 ql_dbg_pci(ql_dbg_init, ha->pdev, 0x0188,
1993 "Max no of queues pairs: %d.\n", ha->max_qpairs);
1995 ql_log_pci(ql_log_info, ha->pdev, 0x001a,
1996 "MSI-X vector count: %d.\n", ha->msix_count);
1998 ql_log_pci(ql_log_info, ha->pdev, 0x001b,
1999 "BAR 3 not enabled.\n");
2002 ql_dbg_pci(ql_dbg_init, ha->pdev, 0x001c,
2003 "MSIX Count: %d.\n", ha->msix_count);
2012 qla83xx_iospace_config(struct qla_hw_data *ha)
2016 if (pci_request_selected_regions(ha->pdev, ha->bars,
2017 QLA2XXX_DRIVER_NAME)) {
2018 ql_log_pci(ql_log_fatal, ha->pdev, 0x0117,
2019 "Failed to reserve PIO/MMIO regions (%s), aborting.\n",
2020 pci_name(ha->pdev));
2022 goto iospace_error_exit;
2025 /* Use MMIO operations for all accesses. */
2026 if (!(pci_resource_flags(ha->pdev, 0) & IORESOURCE_MEM)) {
2027 ql_log_pci(ql_log_warn, ha->pdev, 0x0118,
2028 "Invalid pci I/O region size (%s).\n",
2029 pci_name(ha->pdev));
2030 goto iospace_error_exit;
2032 if (pci_resource_len(ha->pdev, 0) < MIN_IOBASE_LEN) {
2033 ql_log_pci(ql_log_warn, ha->pdev, 0x0119,
2034 "Invalid PCI mem region size (%s), aborting\n",
2035 pci_name(ha->pdev));
2036 goto iospace_error_exit;
2039 ha->iobase = ioremap(pci_resource_start(ha->pdev, 0), MIN_IOBASE_LEN);
2041 ql_log_pci(ql_log_fatal, ha->pdev, 0x011a,
2042 "Cannot remap MMIO (%s), aborting.\n",
2043 pci_name(ha->pdev));
2044 goto iospace_error_exit;
2047 /* 64bit PCI BAR - BAR2 will correspoond to region 4 */
2048 /* 83XX 26XX always use MQ type access for queues
2049 * - mbar 2, a.k.a region 4 */
2050 ha->max_req_queues = ha->max_rsp_queues = 1;
2051 ha->msix_count = QLA_BASE_VECTORS;
2052 ha->mqiobase = ioremap(pci_resource_start(ha->pdev, 4),
2053 pci_resource_len(ha->pdev, 4));
2055 if (!ha->mqiobase) {
2056 ql_log_pci(ql_log_fatal, ha->pdev, 0x011d,
2057 "BAR2/region4 not enabled\n");
2061 ha->msixbase = ioremap(pci_resource_start(ha->pdev, 2),
2062 pci_resource_len(ha->pdev, 2));
2064 /* Read MSIX vector size of the board */
2065 pci_read_config_word(ha->pdev,
2066 QLA_83XX_PCI_MSIX_CONTROL, &msix);
2067 ha->msix_count = (msix & PCI_MSIX_FLAGS_QSIZE) + 1;
2069 * By default, driver uses at least two msix vectors
2072 if (ql2xmqsupport || ql2xnvmeenable) {
2073 /* MB interrupt uses 1 vector */
2074 ha->max_req_queues = ha->msix_count - 1;
2076 /* ATIOQ needs 1 vector. That's 1 less QPair */
2077 if (QLA_TGT_MODE_ENABLED())
2078 ha->max_req_queues--;
2080 ha->max_rsp_queues = ha->max_req_queues;
2082 /* Queue pairs is the max value minus
2083 * the base queue pair */
2084 ha->max_qpairs = ha->max_req_queues - 1;
2085 ql_dbg_pci(ql_dbg_init, ha->pdev, 0x00e3,
2086 "Max no of queues pairs: %d.\n", ha->max_qpairs);
2088 ql_log_pci(ql_log_info, ha->pdev, 0x011c,
2089 "MSI-X vector count: %d.\n", ha->msix_count);
2091 ql_log_pci(ql_log_info, ha->pdev, 0x011e,
2092 "BAR 1 not enabled.\n");
2095 ql_dbg_pci(ql_dbg_init, ha->pdev, 0x011f,
2096 "MSIX Count: %d.\n", ha->msix_count);
2103 static struct isp_operations qla2100_isp_ops = {
2104 .pci_config = qla2100_pci_config,
2105 .reset_chip = qla2x00_reset_chip,
2106 .chip_diag = qla2x00_chip_diag,
2107 .config_rings = qla2x00_config_rings,
2108 .reset_adapter = qla2x00_reset_adapter,
2109 .nvram_config = qla2x00_nvram_config,
2110 .update_fw_options = qla2x00_update_fw_options,
2111 .load_risc = qla2x00_load_risc,
2112 .pci_info_str = qla2x00_pci_info_str,
2113 .fw_version_str = qla2x00_fw_version_str,
2114 .intr_handler = qla2100_intr_handler,
2115 .enable_intrs = qla2x00_enable_intrs,
2116 .disable_intrs = qla2x00_disable_intrs,
2117 .abort_command = qla2x00_abort_command,
2118 .target_reset = qla2x00_abort_target,
2119 .lun_reset = qla2x00_lun_reset,
2120 .fabric_login = qla2x00_login_fabric,
2121 .fabric_logout = qla2x00_fabric_logout,
2122 .calc_req_entries = qla2x00_calc_iocbs_32,
2123 .build_iocbs = qla2x00_build_scsi_iocbs_32,
2124 .prep_ms_iocb = qla2x00_prep_ms_iocb,
2125 .prep_ms_fdmi_iocb = qla2x00_prep_ms_fdmi_iocb,
2126 .read_nvram = qla2x00_read_nvram_data,
2127 .write_nvram = qla2x00_write_nvram_data,
2128 .fw_dump = qla2100_fw_dump,
2131 .beacon_blink = NULL,
2132 .read_optrom = qla2x00_read_optrom_data,
2133 .write_optrom = qla2x00_write_optrom_data,
2134 .get_flash_version = qla2x00_get_flash_version,
2135 .start_scsi = qla2x00_start_scsi,
2136 .start_scsi_mq = NULL,
2137 .abort_isp = qla2x00_abort_isp,
2138 .iospace_config = qla2x00_iospace_config,
2139 .initialize_adapter = qla2x00_initialize_adapter,
2142 static struct isp_operations qla2300_isp_ops = {
2143 .pci_config = qla2300_pci_config,
2144 .reset_chip = qla2x00_reset_chip,
2145 .chip_diag = qla2x00_chip_diag,
2146 .config_rings = qla2x00_config_rings,
2147 .reset_adapter = qla2x00_reset_adapter,
2148 .nvram_config = qla2x00_nvram_config,
2149 .update_fw_options = qla2x00_update_fw_options,
2150 .load_risc = qla2x00_load_risc,
2151 .pci_info_str = qla2x00_pci_info_str,
2152 .fw_version_str = qla2x00_fw_version_str,
2153 .intr_handler = qla2300_intr_handler,
2154 .enable_intrs = qla2x00_enable_intrs,
2155 .disable_intrs = qla2x00_disable_intrs,
2156 .abort_command = qla2x00_abort_command,
2157 .target_reset = qla2x00_abort_target,
2158 .lun_reset = qla2x00_lun_reset,
2159 .fabric_login = qla2x00_login_fabric,
2160 .fabric_logout = qla2x00_fabric_logout,
2161 .calc_req_entries = qla2x00_calc_iocbs_32,
2162 .build_iocbs = qla2x00_build_scsi_iocbs_32,
2163 .prep_ms_iocb = qla2x00_prep_ms_iocb,
2164 .prep_ms_fdmi_iocb = qla2x00_prep_ms_fdmi_iocb,
2165 .read_nvram = qla2x00_read_nvram_data,
2166 .write_nvram = qla2x00_write_nvram_data,
2167 .fw_dump = qla2300_fw_dump,
2168 .beacon_on = qla2x00_beacon_on,
2169 .beacon_off = qla2x00_beacon_off,
2170 .beacon_blink = qla2x00_beacon_blink,
2171 .read_optrom = qla2x00_read_optrom_data,
2172 .write_optrom = qla2x00_write_optrom_data,
2173 .get_flash_version = qla2x00_get_flash_version,
2174 .start_scsi = qla2x00_start_scsi,
2175 .start_scsi_mq = NULL,
2176 .abort_isp = qla2x00_abort_isp,
2177 .iospace_config = qla2x00_iospace_config,
2178 .initialize_adapter = qla2x00_initialize_adapter,
2181 static struct isp_operations qla24xx_isp_ops = {
2182 .pci_config = qla24xx_pci_config,
2183 .reset_chip = qla24xx_reset_chip,
2184 .chip_diag = qla24xx_chip_diag,
2185 .config_rings = qla24xx_config_rings,
2186 .reset_adapter = qla24xx_reset_adapter,
2187 .nvram_config = qla24xx_nvram_config,
2188 .update_fw_options = qla24xx_update_fw_options,
2189 .load_risc = qla24xx_load_risc,
2190 .pci_info_str = qla24xx_pci_info_str,
2191 .fw_version_str = qla24xx_fw_version_str,
2192 .intr_handler = qla24xx_intr_handler,
2193 .enable_intrs = qla24xx_enable_intrs,
2194 .disable_intrs = qla24xx_disable_intrs,
2195 .abort_command = qla24xx_abort_command,
2196 .target_reset = qla24xx_abort_target,
2197 .lun_reset = qla24xx_lun_reset,
2198 .fabric_login = qla24xx_login_fabric,
2199 .fabric_logout = qla24xx_fabric_logout,
2200 .calc_req_entries = NULL,
2201 .build_iocbs = NULL,
2202 .prep_ms_iocb = qla24xx_prep_ms_iocb,
2203 .prep_ms_fdmi_iocb = qla24xx_prep_ms_fdmi_iocb,
2204 .read_nvram = qla24xx_read_nvram_data,
2205 .write_nvram = qla24xx_write_nvram_data,
2206 .fw_dump = qla24xx_fw_dump,
2207 .beacon_on = qla24xx_beacon_on,
2208 .beacon_off = qla24xx_beacon_off,
2209 .beacon_blink = qla24xx_beacon_blink,
2210 .read_optrom = qla24xx_read_optrom_data,
2211 .write_optrom = qla24xx_write_optrom_data,
2212 .get_flash_version = qla24xx_get_flash_version,
2213 .start_scsi = qla24xx_start_scsi,
2214 .start_scsi_mq = NULL,
2215 .abort_isp = qla2x00_abort_isp,
2216 .iospace_config = qla2x00_iospace_config,
2217 .initialize_adapter = qla2x00_initialize_adapter,
2220 static struct isp_operations qla25xx_isp_ops = {
2221 .pci_config = qla25xx_pci_config,
2222 .reset_chip = qla24xx_reset_chip,
2223 .chip_diag = qla24xx_chip_diag,
2224 .config_rings = qla24xx_config_rings,
2225 .reset_adapter = qla24xx_reset_adapter,
2226 .nvram_config = qla24xx_nvram_config,
2227 .update_fw_options = qla24xx_update_fw_options,
2228 .load_risc = qla24xx_load_risc,
2229 .pci_info_str = qla24xx_pci_info_str,
2230 .fw_version_str = qla24xx_fw_version_str,
2231 .intr_handler = qla24xx_intr_handler,
2232 .enable_intrs = qla24xx_enable_intrs,
2233 .disable_intrs = qla24xx_disable_intrs,
2234 .abort_command = qla24xx_abort_command,
2235 .target_reset = qla24xx_abort_target,
2236 .lun_reset = qla24xx_lun_reset,
2237 .fabric_login = qla24xx_login_fabric,
2238 .fabric_logout = qla24xx_fabric_logout,
2239 .calc_req_entries = NULL,
2240 .build_iocbs = NULL,
2241 .prep_ms_iocb = qla24xx_prep_ms_iocb,
2242 .prep_ms_fdmi_iocb = qla24xx_prep_ms_fdmi_iocb,
2243 .read_nvram = qla25xx_read_nvram_data,
2244 .write_nvram = qla25xx_write_nvram_data,
2245 .fw_dump = qla25xx_fw_dump,
2246 .beacon_on = qla24xx_beacon_on,
2247 .beacon_off = qla24xx_beacon_off,
2248 .beacon_blink = qla24xx_beacon_blink,
2249 .read_optrom = qla25xx_read_optrom_data,
2250 .write_optrom = qla24xx_write_optrom_data,
2251 .get_flash_version = qla24xx_get_flash_version,
2252 .start_scsi = qla24xx_dif_start_scsi,
2253 .start_scsi_mq = qla2xxx_dif_start_scsi_mq,
2254 .abort_isp = qla2x00_abort_isp,
2255 .iospace_config = qla2x00_iospace_config,
2256 .initialize_adapter = qla2x00_initialize_adapter,
2259 static struct isp_operations qla81xx_isp_ops = {
2260 .pci_config = qla25xx_pci_config,
2261 .reset_chip = qla24xx_reset_chip,
2262 .chip_diag = qla24xx_chip_diag,
2263 .config_rings = qla24xx_config_rings,
2264 .reset_adapter = qla24xx_reset_adapter,
2265 .nvram_config = qla81xx_nvram_config,
2266 .update_fw_options = qla81xx_update_fw_options,
2267 .load_risc = qla81xx_load_risc,
2268 .pci_info_str = qla24xx_pci_info_str,
2269 .fw_version_str = qla24xx_fw_version_str,
2270 .intr_handler = qla24xx_intr_handler,
2271 .enable_intrs = qla24xx_enable_intrs,
2272 .disable_intrs = qla24xx_disable_intrs,
2273 .abort_command = qla24xx_abort_command,
2274 .target_reset = qla24xx_abort_target,
2275 .lun_reset = qla24xx_lun_reset,
2276 .fabric_login = qla24xx_login_fabric,
2277 .fabric_logout = qla24xx_fabric_logout,
2278 .calc_req_entries = NULL,
2279 .build_iocbs = NULL,
2280 .prep_ms_iocb = qla24xx_prep_ms_iocb,
2281 .prep_ms_fdmi_iocb = qla24xx_prep_ms_fdmi_iocb,
2283 .write_nvram = NULL,
2284 .fw_dump = qla81xx_fw_dump,
2285 .beacon_on = qla24xx_beacon_on,
2286 .beacon_off = qla24xx_beacon_off,
2287 .beacon_blink = qla83xx_beacon_blink,
2288 .read_optrom = qla25xx_read_optrom_data,
2289 .write_optrom = qla24xx_write_optrom_data,
2290 .get_flash_version = qla24xx_get_flash_version,
2291 .start_scsi = qla24xx_dif_start_scsi,
2292 .start_scsi_mq = qla2xxx_dif_start_scsi_mq,
2293 .abort_isp = qla2x00_abort_isp,
2294 .iospace_config = qla2x00_iospace_config,
2295 .initialize_adapter = qla2x00_initialize_adapter,
2298 static struct isp_operations qla82xx_isp_ops = {
2299 .pci_config = qla82xx_pci_config,
2300 .reset_chip = qla82xx_reset_chip,
2301 .chip_diag = qla24xx_chip_diag,
2302 .config_rings = qla82xx_config_rings,
2303 .reset_adapter = qla24xx_reset_adapter,
2304 .nvram_config = qla81xx_nvram_config,
2305 .update_fw_options = qla24xx_update_fw_options,
2306 .load_risc = qla82xx_load_risc,
2307 .pci_info_str = qla24xx_pci_info_str,
2308 .fw_version_str = qla24xx_fw_version_str,
2309 .intr_handler = qla82xx_intr_handler,
2310 .enable_intrs = qla82xx_enable_intrs,
2311 .disable_intrs = qla82xx_disable_intrs,
2312 .abort_command = qla24xx_abort_command,
2313 .target_reset = qla24xx_abort_target,
2314 .lun_reset = qla24xx_lun_reset,
2315 .fabric_login = qla24xx_login_fabric,
2316 .fabric_logout = qla24xx_fabric_logout,
2317 .calc_req_entries = NULL,
2318 .build_iocbs = NULL,
2319 .prep_ms_iocb = qla24xx_prep_ms_iocb,
2320 .prep_ms_fdmi_iocb = qla24xx_prep_ms_fdmi_iocb,
2321 .read_nvram = qla24xx_read_nvram_data,
2322 .write_nvram = qla24xx_write_nvram_data,
2323 .fw_dump = qla82xx_fw_dump,
2324 .beacon_on = qla82xx_beacon_on,
2325 .beacon_off = qla82xx_beacon_off,
2326 .beacon_blink = NULL,
2327 .read_optrom = qla82xx_read_optrom_data,
2328 .write_optrom = qla82xx_write_optrom_data,
2329 .get_flash_version = qla82xx_get_flash_version,
2330 .start_scsi = qla82xx_start_scsi,
2331 .start_scsi_mq = NULL,
2332 .abort_isp = qla82xx_abort_isp,
2333 .iospace_config = qla82xx_iospace_config,
2334 .initialize_adapter = qla2x00_initialize_adapter,
2337 static struct isp_operations qla8044_isp_ops = {
2338 .pci_config = qla82xx_pci_config,
2339 .reset_chip = qla82xx_reset_chip,
2340 .chip_diag = qla24xx_chip_diag,
2341 .config_rings = qla82xx_config_rings,
2342 .reset_adapter = qla24xx_reset_adapter,
2343 .nvram_config = qla81xx_nvram_config,
2344 .update_fw_options = qla24xx_update_fw_options,
2345 .load_risc = qla82xx_load_risc,
2346 .pci_info_str = qla24xx_pci_info_str,
2347 .fw_version_str = qla24xx_fw_version_str,
2348 .intr_handler = qla8044_intr_handler,
2349 .enable_intrs = qla82xx_enable_intrs,
2350 .disable_intrs = qla82xx_disable_intrs,
2351 .abort_command = qla24xx_abort_command,
2352 .target_reset = qla24xx_abort_target,
2353 .lun_reset = qla24xx_lun_reset,
2354 .fabric_login = qla24xx_login_fabric,
2355 .fabric_logout = qla24xx_fabric_logout,
2356 .calc_req_entries = NULL,
2357 .build_iocbs = NULL,
2358 .prep_ms_iocb = qla24xx_prep_ms_iocb,
2359 .prep_ms_fdmi_iocb = qla24xx_prep_ms_fdmi_iocb,
2361 .write_nvram = NULL,
2362 .fw_dump = qla8044_fw_dump,
2363 .beacon_on = qla82xx_beacon_on,
2364 .beacon_off = qla82xx_beacon_off,
2365 .beacon_blink = NULL,
2366 .read_optrom = qla8044_read_optrom_data,
2367 .write_optrom = qla8044_write_optrom_data,
2368 .get_flash_version = qla82xx_get_flash_version,
2369 .start_scsi = qla82xx_start_scsi,
2370 .start_scsi_mq = NULL,
2371 .abort_isp = qla8044_abort_isp,
2372 .iospace_config = qla82xx_iospace_config,
2373 .initialize_adapter = qla2x00_initialize_adapter,
2376 static struct isp_operations qla83xx_isp_ops = {
2377 .pci_config = qla25xx_pci_config,
2378 .reset_chip = qla24xx_reset_chip,
2379 .chip_diag = qla24xx_chip_diag,
2380 .config_rings = qla24xx_config_rings,
2381 .reset_adapter = qla24xx_reset_adapter,
2382 .nvram_config = qla81xx_nvram_config,
2383 .update_fw_options = qla81xx_update_fw_options,
2384 .load_risc = qla81xx_load_risc,
2385 .pci_info_str = qla24xx_pci_info_str,
2386 .fw_version_str = qla24xx_fw_version_str,
2387 .intr_handler = qla24xx_intr_handler,
2388 .enable_intrs = qla24xx_enable_intrs,
2389 .disable_intrs = qla24xx_disable_intrs,
2390 .abort_command = qla24xx_abort_command,
2391 .target_reset = qla24xx_abort_target,
2392 .lun_reset = qla24xx_lun_reset,
2393 .fabric_login = qla24xx_login_fabric,
2394 .fabric_logout = qla24xx_fabric_logout,
2395 .calc_req_entries = NULL,
2396 .build_iocbs = NULL,
2397 .prep_ms_iocb = qla24xx_prep_ms_iocb,
2398 .prep_ms_fdmi_iocb = qla24xx_prep_ms_fdmi_iocb,
2400 .write_nvram = NULL,
2401 .fw_dump = qla83xx_fw_dump,
2402 .beacon_on = qla24xx_beacon_on,
2403 .beacon_off = qla24xx_beacon_off,
2404 .beacon_blink = qla83xx_beacon_blink,
2405 .read_optrom = qla25xx_read_optrom_data,
2406 .write_optrom = qla24xx_write_optrom_data,
2407 .get_flash_version = qla24xx_get_flash_version,
2408 .start_scsi = qla24xx_dif_start_scsi,
2409 .start_scsi_mq = qla2xxx_dif_start_scsi_mq,
2410 .abort_isp = qla2x00_abort_isp,
2411 .iospace_config = qla83xx_iospace_config,
2412 .initialize_adapter = qla2x00_initialize_adapter,
2415 static struct isp_operations qlafx00_isp_ops = {
2416 .pci_config = qlafx00_pci_config,
2417 .reset_chip = qlafx00_soft_reset,
2418 .chip_diag = qlafx00_chip_diag,
2419 .config_rings = qlafx00_config_rings,
2420 .reset_adapter = qlafx00_soft_reset,
2421 .nvram_config = NULL,
2422 .update_fw_options = NULL,
2424 .pci_info_str = qlafx00_pci_info_str,
2425 .fw_version_str = qlafx00_fw_version_str,
2426 .intr_handler = qlafx00_intr_handler,
2427 .enable_intrs = qlafx00_enable_intrs,
2428 .disable_intrs = qlafx00_disable_intrs,
2429 .abort_command = qla24xx_async_abort_command,
2430 .target_reset = qlafx00_abort_target,
2431 .lun_reset = qlafx00_lun_reset,
2432 .fabric_login = NULL,
2433 .fabric_logout = NULL,
2434 .calc_req_entries = NULL,
2435 .build_iocbs = NULL,
2436 .prep_ms_iocb = qla24xx_prep_ms_iocb,
2437 .prep_ms_fdmi_iocb = qla24xx_prep_ms_fdmi_iocb,
2438 .read_nvram = qla24xx_read_nvram_data,
2439 .write_nvram = qla24xx_write_nvram_data,
2441 .beacon_on = qla24xx_beacon_on,
2442 .beacon_off = qla24xx_beacon_off,
2443 .beacon_blink = NULL,
2444 .read_optrom = qla24xx_read_optrom_data,
2445 .write_optrom = qla24xx_write_optrom_data,
2446 .get_flash_version = qla24xx_get_flash_version,
2447 .start_scsi = qlafx00_start_scsi,
2448 .start_scsi_mq = NULL,
2449 .abort_isp = qlafx00_abort_isp,
2450 .iospace_config = qlafx00_iospace_config,
2451 .initialize_adapter = qlafx00_initialize_adapter,
2454 static struct isp_operations qla27xx_isp_ops = {
2455 .pci_config = qla25xx_pci_config,
2456 .reset_chip = qla24xx_reset_chip,
2457 .chip_diag = qla24xx_chip_diag,
2458 .config_rings = qla24xx_config_rings,
2459 .reset_adapter = qla24xx_reset_adapter,
2460 .nvram_config = qla81xx_nvram_config,
2461 .update_fw_options = qla24xx_update_fw_options,
2462 .load_risc = qla81xx_load_risc,
2463 .pci_info_str = qla24xx_pci_info_str,
2464 .fw_version_str = qla24xx_fw_version_str,
2465 .intr_handler = qla24xx_intr_handler,
2466 .enable_intrs = qla24xx_enable_intrs,
2467 .disable_intrs = qla24xx_disable_intrs,
2468 .abort_command = qla24xx_abort_command,
2469 .target_reset = qla24xx_abort_target,
2470 .lun_reset = qla24xx_lun_reset,
2471 .fabric_login = qla24xx_login_fabric,
2472 .fabric_logout = qla24xx_fabric_logout,
2473 .calc_req_entries = NULL,
2474 .build_iocbs = NULL,
2475 .prep_ms_iocb = qla24xx_prep_ms_iocb,
2476 .prep_ms_fdmi_iocb = qla24xx_prep_ms_fdmi_iocb,
2478 .write_nvram = NULL,
2479 .fw_dump = qla27xx_fwdump,
2480 .beacon_on = qla24xx_beacon_on,
2481 .beacon_off = qla24xx_beacon_off,
2482 .beacon_blink = qla83xx_beacon_blink,
2483 .read_optrom = qla25xx_read_optrom_data,
2484 .write_optrom = qla24xx_write_optrom_data,
2485 .get_flash_version = qla24xx_get_flash_version,
2486 .start_scsi = qla24xx_dif_start_scsi,
2487 .start_scsi_mq = qla2xxx_dif_start_scsi_mq,
2488 .abort_isp = qla2x00_abort_isp,
2489 .iospace_config = qla83xx_iospace_config,
2490 .initialize_adapter = qla2x00_initialize_adapter,
2494 qla2x00_set_isp_flags(struct qla_hw_data *ha)
2496 ha->device_type = DT_EXTENDED_IDS;
2497 switch (ha->pdev->device) {
2498 case PCI_DEVICE_ID_QLOGIC_ISP2100:
2499 ha->isp_type |= DT_ISP2100;
2500 ha->device_type &= ~DT_EXTENDED_IDS;
2501 ha->fw_srisc_address = RISC_START_ADDRESS_2100;
2503 case PCI_DEVICE_ID_QLOGIC_ISP2200:
2504 ha->isp_type |= DT_ISP2200;
2505 ha->device_type &= ~DT_EXTENDED_IDS;
2506 ha->fw_srisc_address = RISC_START_ADDRESS_2100;
2508 case PCI_DEVICE_ID_QLOGIC_ISP2300:
2509 ha->isp_type |= DT_ISP2300;
2510 ha->device_type |= DT_ZIO_SUPPORTED;
2511 ha->fw_srisc_address = RISC_START_ADDRESS_2300;
2513 case PCI_DEVICE_ID_QLOGIC_ISP2312:
2514 ha->isp_type |= DT_ISP2312;
2515 ha->device_type |= DT_ZIO_SUPPORTED;
2516 ha->fw_srisc_address = RISC_START_ADDRESS_2300;
2518 case PCI_DEVICE_ID_QLOGIC_ISP2322:
2519 ha->isp_type |= DT_ISP2322;
2520 ha->device_type |= DT_ZIO_SUPPORTED;
2521 if (ha->pdev->subsystem_vendor == 0x1028 &&
2522 ha->pdev->subsystem_device == 0x0170)
2523 ha->device_type |= DT_OEM_001;
2524 ha->fw_srisc_address = RISC_START_ADDRESS_2300;
2526 case PCI_DEVICE_ID_QLOGIC_ISP6312:
2527 ha->isp_type |= DT_ISP6312;
2528 ha->fw_srisc_address = RISC_START_ADDRESS_2300;
2530 case PCI_DEVICE_ID_QLOGIC_ISP6322:
2531 ha->isp_type |= DT_ISP6322;
2532 ha->fw_srisc_address = RISC_START_ADDRESS_2300;
2534 case PCI_DEVICE_ID_QLOGIC_ISP2422:
2535 ha->isp_type |= DT_ISP2422;
2536 ha->device_type |= DT_ZIO_SUPPORTED;
2537 ha->device_type |= DT_FWI2;
2538 ha->device_type |= DT_IIDMA;
2539 ha->fw_srisc_address = RISC_START_ADDRESS_2400;
2541 case PCI_DEVICE_ID_QLOGIC_ISP2432:
2542 ha->isp_type |= DT_ISP2432;
2543 ha->device_type |= DT_ZIO_SUPPORTED;
2544 ha->device_type |= DT_FWI2;
2545 ha->device_type |= DT_IIDMA;
2546 ha->fw_srisc_address = RISC_START_ADDRESS_2400;
2548 case PCI_DEVICE_ID_QLOGIC_ISP8432:
2549 ha->isp_type |= DT_ISP8432;
2550 ha->device_type |= DT_ZIO_SUPPORTED;
2551 ha->device_type |= DT_FWI2;
2552 ha->device_type |= DT_IIDMA;
2553 ha->fw_srisc_address = RISC_START_ADDRESS_2400;
2555 case PCI_DEVICE_ID_QLOGIC_ISP5422:
2556 ha->isp_type |= DT_ISP5422;
2557 ha->device_type |= DT_FWI2;
2558 ha->fw_srisc_address = RISC_START_ADDRESS_2400;
2560 case PCI_DEVICE_ID_QLOGIC_ISP5432:
2561 ha->isp_type |= DT_ISP5432;
2562 ha->device_type |= DT_FWI2;
2563 ha->fw_srisc_address = RISC_START_ADDRESS_2400;
2565 case PCI_DEVICE_ID_QLOGIC_ISP2532:
2566 ha->isp_type |= DT_ISP2532;
2567 ha->device_type |= DT_ZIO_SUPPORTED;
2568 ha->device_type |= DT_FWI2;
2569 ha->device_type |= DT_IIDMA;
2570 ha->fw_srisc_address = RISC_START_ADDRESS_2400;
2572 case PCI_DEVICE_ID_QLOGIC_ISP8001:
2573 ha->isp_type |= DT_ISP8001;
2574 ha->device_type |= DT_ZIO_SUPPORTED;
2575 ha->device_type |= DT_FWI2;
2576 ha->device_type |= DT_IIDMA;
2577 ha->fw_srisc_address = RISC_START_ADDRESS_2400;
2579 case PCI_DEVICE_ID_QLOGIC_ISP8021:
2580 ha->isp_type |= DT_ISP8021;
2581 ha->device_type |= DT_ZIO_SUPPORTED;
2582 ha->device_type |= DT_FWI2;
2583 ha->fw_srisc_address = RISC_START_ADDRESS_2400;
2584 /* Initialize 82XX ISP flags */
2585 qla82xx_init_flags(ha);
2587 case PCI_DEVICE_ID_QLOGIC_ISP8044:
2588 ha->isp_type |= DT_ISP8044;
2589 ha->device_type |= DT_ZIO_SUPPORTED;
2590 ha->device_type |= DT_FWI2;
2591 ha->fw_srisc_address = RISC_START_ADDRESS_2400;
2592 /* Initialize 82XX ISP flags */
2593 qla82xx_init_flags(ha);
2595 case PCI_DEVICE_ID_QLOGIC_ISP2031:
2596 ha->isp_type |= DT_ISP2031;
2597 ha->device_type |= DT_ZIO_SUPPORTED;
2598 ha->device_type |= DT_FWI2;
2599 ha->device_type |= DT_IIDMA;
2600 ha->device_type |= DT_T10_PI;
2601 ha->fw_srisc_address = RISC_START_ADDRESS_2400;
2603 case PCI_DEVICE_ID_QLOGIC_ISP8031:
2604 ha->isp_type |= DT_ISP8031;
2605 ha->device_type |= DT_ZIO_SUPPORTED;
2606 ha->device_type |= DT_FWI2;
2607 ha->device_type |= DT_IIDMA;
2608 ha->device_type |= DT_T10_PI;
2609 ha->fw_srisc_address = RISC_START_ADDRESS_2400;
2611 case PCI_DEVICE_ID_QLOGIC_ISPF001:
2612 ha->isp_type |= DT_ISPFX00;
2614 case PCI_DEVICE_ID_QLOGIC_ISP2071:
2615 ha->isp_type |= DT_ISP2071;
2616 ha->device_type |= DT_ZIO_SUPPORTED;
2617 ha->device_type |= DT_FWI2;
2618 ha->device_type |= DT_IIDMA;
2619 ha->device_type |= DT_T10_PI;
2620 ha->fw_srisc_address = RISC_START_ADDRESS_2400;
2622 case PCI_DEVICE_ID_QLOGIC_ISP2271:
2623 ha->isp_type |= DT_ISP2271;
2624 ha->device_type |= DT_ZIO_SUPPORTED;
2625 ha->device_type |= DT_FWI2;
2626 ha->device_type |= DT_IIDMA;
2627 ha->device_type |= DT_T10_PI;
2628 ha->fw_srisc_address = RISC_START_ADDRESS_2400;
2630 case PCI_DEVICE_ID_QLOGIC_ISP2261:
2631 ha->isp_type |= DT_ISP2261;
2632 ha->device_type |= DT_ZIO_SUPPORTED;
2633 ha->device_type |= DT_FWI2;
2634 ha->device_type |= DT_IIDMA;
2635 ha->device_type |= DT_T10_PI;
2636 ha->fw_srisc_address = RISC_START_ADDRESS_2400;
2638 case PCI_DEVICE_ID_QLOGIC_ISP2081:
2639 case PCI_DEVICE_ID_QLOGIC_ISP2089:
2640 ha->isp_type |= DT_ISP2081;
2641 ha->device_type |= DT_ZIO_SUPPORTED;
2642 ha->device_type |= DT_FWI2;
2643 ha->device_type |= DT_IIDMA;
2644 ha->device_type |= DT_T10_PI;
2645 ha->fw_srisc_address = RISC_START_ADDRESS_2400;
2647 case PCI_DEVICE_ID_QLOGIC_ISP2281:
2648 case PCI_DEVICE_ID_QLOGIC_ISP2289:
2649 ha->isp_type |= DT_ISP2281;
2650 ha->device_type |= DT_ZIO_SUPPORTED;
2651 ha->device_type |= DT_FWI2;
2652 ha->device_type |= DT_IIDMA;
2653 ha->device_type |= DT_T10_PI;
2654 ha->fw_srisc_address = RISC_START_ADDRESS_2400;
2659 ha->port_no = ha->portnum & 1;
2661 /* Get adapter physical port no from interrupt pin register. */
2662 pci_read_config_byte(ha->pdev, PCI_INTERRUPT_PIN, &ha->port_no);
2663 if (IS_QLA25XX(ha) || IS_QLA2031(ha) ||
2664 IS_QLA27XX(ha) || IS_QLA28XX(ha))
2667 ha->port_no = !(ha->port_no & 1);
2670 ql_dbg_pci(ql_dbg_init, ha->pdev, 0x000b,
2671 "device_type=0x%x port=%d fw_srisc_address=0x%x.\n",
2672 ha->device_type, ha->port_no, ha->fw_srisc_address);
2676 qla2xxx_scan_start(struct Scsi_Host *shost)
2678 scsi_qla_host_t *vha = shost_priv(shost);
2680 if (vha->hw->flags.running_gold_fw)
2683 set_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags);
2684 set_bit(LOCAL_LOOP_UPDATE, &vha->dpc_flags);
2685 set_bit(RSCN_UPDATE, &vha->dpc_flags);
2686 set_bit(NPIV_CONFIG_NEEDED, &vha->dpc_flags);
2690 qla2xxx_scan_finished(struct Scsi_Host *shost, unsigned long time)
2692 scsi_qla_host_t *vha = shost_priv(shost);
2694 if (test_bit(UNLOADING, &vha->dpc_flags))
2698 if (time > vha->hw->loop_reset_delay * HZ)
2701 return atomic_read(&vha->loop_state) == LOOP_READY;
2704 static void qla2x00_iocb_work_fn(struct work_struct *work)
2706 struct scsi_qla_host *vha = container_of(work,
2707 struct scsi_qla_host, iocb_work);
2708 struct qla_hw_data *ha = vha->hw;
2709 struct scsi_qla_host *base_vha = pci_get_drvdata(ha->pdev);
2711 unsigned long flags;
2713 if (test_bit(UNLOADING, &base_vha->dpc_flags))
2716 while (!list_empty(&vha->work_list) && i > 0) {
2717 qla2x00_do_work(vha);
2721 spin_lock_irqsave(&vha->work_lock, flags);
2722 clear_bit(IOCB_WORK_ACTIVE, &vha->dpc_flags);
2723 spin_unlock_irqrestore(&vha->work_lock, flags);
2727 * PCI driver interface
2730 qla2x00_probe_one(struct pci_dev *pdev, const struct pci_device_id *id)
2733 struct Scsi_Host *host;
2734 scsi_qla_host_t *base_vha = NULL;
2735 struct qla_hw_data *ha;
2737 char fw_str[30], wq_name[30];
2738 struct scsi_host_template *sht;
2739 int bars, mem_only = 0;
2740 uint16_t req_length = 0, rsp_length = 0;
2741 struct req_que *req = NULL;
2742 struct rsp_que *rsp = NULL;
2745 bars = pci_select_bars(pdev, IORESOURCE_MEM | IORESOURCE_IO);
2746 sht = &qla2xxx_driver_template;
2747 if (pdev->device == PCI_DEVICE_ID_QLOGIC_ISP2422 ||
2748 pdev->device == PCI_DEVICE_ID_QLOGIC_ISP2432 ||
2749 pdev->device == PCI_DEVICE_ID_QLOGIC_ISP8432 ||
2750 pdev->device == PCI_DEVICE_ID_QLOGIC_ISP5422 ||
2751 pdev->device == PCI_DEVICE_ID_QLOGIC_ISP5432 ||
2752 pdev->device == PCI_DEVICE_ID_QLOGIC_ISP2532 ||
2753 pdev->device == PCI_DEVICE_ID_QLOGIC_ISP8001 ||
2754 pdev->device == PCI_DEVICE_ID_QLOGIC_ISP8021 ||
2755 pdev->device == PCI_DEVICE_ID_QLOGIC_ISP2031 ||
2756 pdev->device == PCI_DEVICE_ID_QLOGIC_ISP8031 ||
2757 pdev->device == PCI_DEVICE_ID_QLOGIC_ISPF001 ||
2758 pdev->device == PCI_DEVICE_ID_QLOGIC_ISP8044 ||
2759 pdev->device == PCI_DEVICE_ID_QLOGIC_ISP2071 ||
2760 pdev->device == PCI_DEVICE_ID_QLOGIC_ISP2271 ||
2761 pdev->device == PCI_DEVICE_ID_QLOGIC_ISP2261 ||
2762 pdev->device == PCI_DEVICE_ID_QLOGIC_ISP2081 ||
2763 pdev->device == PCI_DEVICE_ID_QLOGIC_ISP2281 ||
2764 pdev->device == PCI_DEVICE_ID_QLOGIC_ISP2089 ||
2765 pdev->device == PCI_DEVICE_ID_QLOGIC_ISP2289) {
2766 bars = pci_select_bars(pdev, IORESOURCE_MEM);
2768 ql_dbg_pci(ql_dbg_init, pdev, 0x0007,
2769 "Mem only adapter.\n");
2771 ql_dbg_pci(ql_dbg_init, pdev, 0x0008,
2772 "Bars=%d.\n", bars);
2775 if (pci_enable_device_mem(pdev))
2778 if (pci_enable_device(pdev))
2782 if (is_kdump_kernel()) {
2784 ql2xallocfwdump = 0;
2787 /* This may fail but that's ok */
2788 pci_enable_pcie_error_reporting(pdev);
2790 ha = kzalloc(sizeof(struct qla_hw_data), GFP_KERNEL);
2792 ql_log_pci(ql_log_fatal, pdev, 0x0009,
2793 "Unable to allocate memory for ha.\n");
2794 goto disable_device;
2796 ql_dbg_pci(ql_dbg_init, pdev, 0x000a,
2797 "Memory allocated for ha=%p.\n", ha);
2799 INIT_LIST_HEAD(&ha->tgt.q_full_list);
2800 spin_lock_init(&ha->tgt.q_full_lock);
2801 spin_lock_init(&ha->tgt.sess_lock);
2802 spin_lock_init(&ha->tgt.atio_lock);
2804 atomic_set(&ha->nvme_active_aen_cnt, 0);
2806 /* Clear our data area */
2808 ha->mem_only = mem_only;
2809 spin_lock_init(&ha->hardware_lock);
2810 spin_lock_init(&ha->vport_slock);
2811 mutex_init(&ha->selflogin_lock);
2812 mutex_init(&ha->optrom_mutex);
2814 /* Set ISP-type information. */
2815 qla2x00_set_isp_flags(ha);
2817 /* Set EEH reset type to fundamental if required by hba */
2818 if (IS_QLA24XX(ha) || IS_QLA25XX(ha) || IS_QLA81XX(ha) ||
2819 IS_QLA83XX(ha) || IS_QLA27XX(ha) || IS_QLA28XX(ha))
2820 pdev->needs_freset = 1;
2822 ha->prev_topology = 0;
2823 ha->init_cb_size = sizeof(init_cb_t);
2824 ha->link_data_rate = PORT_SPEED_UNKNOWN;
2825 ha->optrom_size = OPTROM_SIZE_2300;
2826 ha->max_exchg = FW_MAX_EXCHANGES_CNT;
2827 atomic_set(&ha->num_pend_mbx_stage1, 0);
2828 atomic_set(&ha->num_pend_mbx_stage2, 0);
2829 atomic_set(&ha->num_pend_mbx_stage3, 0);
2830 atomic_set(&ha->zio_threshold, DEFAULT_ZIO_THRESHOLD);
2831 ha->last_zio_threshold = DEFAULT_ZIO_THRESHOLD;
2833 /* Assign ISP specific operations. */
2834 if (IS_QLA2100(ha)) {
2835 ha->max_fibre_devices = MAX_FIBRE_DEVICES_2100;
2836 ha->mbx_count = MAILBOX_REGISTER_COUNT_2100;
2837 req_length = REQUEST_ENTRY_CNT_2100;
2838 rsp_length = RESPONSE_ENTRY_CNT_2100;
2839 ha->max_loop_id = SNS_LAST_LOOP_ID_2100;
2840 ha->gid_list_info_size = 4;
2841 ha->flash_conf_off = ~0;
2842 ha->flash_data_off = ~0;
2843 ha->nvram_conf_off = ~0;
2844 ha->nvram_data_off = ~0;
2845 ha->isp_ops = &qla2100_isp_ops;
2846 } else if (IS_QLA2200(ha)) {
2847 ha->max_fibre_devices = MAX_FIBRE_DEVICES_2100;
2848 ha->mbx_count = MAILBOX_REGISTER_COUNT_2200;
2849 req_length = REQUEST_ENTRY_CNT_2200;
2850 rsp_length = RESPONSE_ENTRY_CNT_2100;
2851 ha->max_loop_id = SNS_LAST_LOOP_ID_2100;
2852 ha->gid_list_info_size = 4;
2853 ha->flash_conf_off = ~0;
2854 ha->flash_data_off = ~0;
2855 ha->nvram_conf_off = ~0;
2856 ha->nvram_data_off = ~0;
2857 ha->isp_ops = &qla2100_isp_ops;
2858 } else if (IS_QLA23XX(ha)) {
2859 ha->max_fibre_devices = MAX_FIBRE_DEVICES_2100;
2860 ha->mbx_count = MAILBOX_REGISTER_COUNT;
2861 req_length = REQUEST_ENTRY_CNT_2200;
2862 rsp_length = RESPONSE_ENTRY_CNT_2300;
2863 ha->max_loop_id = SNS_LAST_LOOP_ID_2300;
2864 ha->gid_list_info_size = 6;
2865 if (IS_QLA2322(ha) || IS_QLA6322(ha))
2866 ha->optrom_size = OPTROM_SIZE_2322;
2867 ha->flash_conf_off = ~0;
2868 ha->flash_data_off = ~0;
2869 ha->nvram_conf_off = ~0;
2870 ha->nvram_data_off = ~0;
2871 ha->isp_ops = &qla2300_isp_ops;
2872 } else if (IS_QLA24XX_TYPE(ha)) {
2873 ha->max_fibre_devices = MAX_FIBRE_DEVICES_2400;
2874 ha->mbx_count = MAILBOX_REGISTER_COUNT;
2875 req_length = REQUEST_ENTRY_CNT_24XX;
2876 rsp_length = RESPONSE_ENTRY_CNT_2300;
2877 ha->tgt.atio_q_length = ATIO_ENTRY_CNT_24XX;
2878 ha->max_loop_id = SNS_LAST_LOOP_ID_2300;
2879 ha->init_cb_size = sizeof(struct mid_init_cb_24xx);
2880 ha->gid_list_info_size = 8;
2881 ha->optrom_size = OPTROM_SIZE_24XX;
2882 ha->nvram_npiv_size = QLA_MAX_VPORTS_QLA24XX;
2883 ha->isp_ops = &qla24xx_isp_ops;
2884 ha->flash_conf_off = FARX_ACCESS_FLASH_CONF;
2885 ha->flash_data_off = FARX_ACCESS_FLASH_DATA;
2886 ha->nvram_conf_off = FARX_ACCESS_NVRAM_CONF;
2887 ha->nvram_data_off = FARX_ACCESS_NVRAM_DATA;
2888 } else if (IS_QLA25XX(ha)) {
2889 ha->max_fibre_devices = MAX_FIBRE_DEVICES_2400;
2890 ha->mbx_count = MAILBOX_REGISTER_COUNT;
2891 req_length = REQUEST_ENTRY_CNT_24XX;
2892 rsp_length = RESPONSE_ENTRY_CNT_2300;
2893 ha->tgt.atio_q_length = ATIO_ENTRY_CNT_24XX;
2894 ha->max_loop_id = SNS_LAST_LOOP_ID_2300;
2895 ha->init_cb_size = sizeof(struct mid_init_cb_24xx);
2896 ha->gid_list_info_size = 8;
2897 ha->optrom_size = OPTROM_SIZE_25XX;
2898 ha->nvram_npiv_size = QLA_MAX_VPORTS_QLA25XX;
2899 ha->isp_ops = &qla25xx_isp_ops;
2900 ha->flash_conf_off = FARX_ACCESS_FLASH_CONF;
2901 ha->flash_data_off = FARX_ACCESS_FLASH_DATA;
2902 ha->nvram_conf_off = FARX_ACCESS_NVRAM_CONF;
2903 ha->nvram_data_off = FARX_ACCESS_NVRAM_DATA;
2904 } else if (IS_QLA81XX(ha)) {
2905 ha->max_fibre_devices = MAX_FIBRE_DEVICES_2400;
2906 ha->mbx_count = MAILBOX_REGISTER_COUNT;
2907 req_length = REQUEST_ENTRY_CNT_24XX;
2908 rsp_length = RESPONSE_ENTRY_CNT_2300;
2909 ha->tgt.atio_q_length = ATIO_ENTRY_CNT_24XX;
2910 ha->max_loop_id = SNS_LAST_LOOP_ID_2300;
2911 ha->init_cb_size = sizeof(struct mid_init_cb_81xx);
2912 ha->gid_list_info_size = 8;
2913 ha->optrom_size = OPTROM_SIZE_81XX;
2914 ha->nvram_npiv_size = QLA_MAX_VPORTS_QLA25XX;
2915 ha->isp_ops = &qla81xx_isp_ops;
2916 ha->flash_conf_off = FARX_ACCESS_FLASH_CONF_81XX;
2917 ha->flash_data_off = FARX_ACCESS_FLASH_DATA_81XX;
2918 ha->nvram_conf_off = ~0;
2919 ha->nvram_data_off = ~0;
2920 } else if (IS_QLA82XX(ha)) {
2921 ha->max_fibre_devices = MAX_FIBRE_DEVICES_2400;
2922 ha->mbx_count = MAILBOX_REGISTER_COUNT;
2923 req_length = REQUEST_ENTRY_CNT_82XX;
2924 rsp_length = RESPONSE_ENTRY_CNT_82XX;
2925 ha->max_loop_id = SNS_LAST_LOOP_ID_2300;
2926 ha->init_cb_size = sizeof(struct mid_init_cb_81xx);
2927 ha->gid_list_info_size = 8;
2928 ha->optrom_size = OPTROM_SIZE_82XX;
2929 ha->nvram_npiv_size = QLA_MAX_VPORTS_QLA25XX;
2930 ha->isp_ops = &qla82xx_isp_ops;
2931 ha->flash_conf_off = FARX_ACCESS_FLASH_CONF;
2932 ha->flash_data_off = FARX_ACCESS_FLASH_DATA;
2933 ha->nvram_conf_off = FARX_ACCESS_NVRAM_CONF;
2934 ha->nvram_data_off = FARX_ACCESS_NVRAM_DATA;
2935 } else if (IS_QLA8044(ha)) {
2936 ha->max_fibre_devices = MAX_FIBRE_DEVICES_2400;
2937 ha->mbx_count = MAILBOX_REGISTER_COUNT;
2938 req_length = REQUEST_ENTRY_CNT_82XX;
2939 rsp_length = RESPONSE_ENTRY_CNT_82XX;
2940 ha->max_loop_id = SNS_LAST_LOOP_ID_2300;
2941 ha->init_cb_size = sizeof(struct mid_init_cb_81xx);
2942 ha->gid_list_info_size = 8;
2943 ha->optrom_size = OPTROM_SIZE_83XX;
2944 ha->nvram_npiv_size = QLA_MAX_VPORTS_QLA25XX;
2945 ha->isp_ops = &qla8044_isp_ops;
2946 ha->flash_conf_off = FARX_ACCESS_FLASH_CONF;
2947 ha->flash_data_off = FARX_ACCESS_FLASH_DATA;
2948 ha->nvram_conf_off = FARX_ACCESS_NVRAM_CONF;
2949 ha->nvram_data_off = FARX_ACCESS_NVRAM_DATA;
2950 } else if (IS_QLA83XX(ha)) {
2951 ha->portnum = PCI_FUNC(ha->pdev->devfn);
2952 ha->max_fibre_devices = MAX_FIBRE_DEVICES_2400;
2953 ha->mbx_count = MAILBOX_REGISTER_COUNT;
2954 req_length = REQUEST_ENTRY_CNT_83XX;
2955 rsp_length = RESPONSE_ENTRY_CNT_83XX;
2956 ha->tgt.atio_q_length = ATIO_ENTRY_CNT_24XX;
2957 ha->max_loop_id = SNS_LAST_LOOP_ID_2300;
2958 ha->init_cb_size = sizeof(struct mid_init_cb_81xx);
2959 ha->gid_list_info_size = 8;
2960 ha->optrom_size = OPTROM_SIZE_83XX;
2961 ha->nvram_npiv_size = QLA_MAX_VPORTS_QLA25XX;
2962 ha->isp_ops = &qla83xx_isp_ops;
2963 ha->flash_conf_off = FARX_ACCESS_FLASH_CONF_81XX;
2964 ha->flash_data_off = FARX_ACCESS_FLASH_DATA_81XX;
2965 ha->nvram_conf_off = ~0;
2966 ha->nvram_data_off = ~0;
2967 } else if (IS_QLAFX00(ha)) {
2968 ha->max_fibre_devices = MAX_FIBRE_DEVICES_FX00;
2969 ha->mbx_count = MAILBOX_REGISTER_COUNT_FX00;
2970 ha->aen_mbx_count = AEN_MAILBOX_REGISTER_COUNT_FX00;
2971 req_length = REQUEST_ENTRY_CNT_FX00;
2972 rsp_length = RESPONSE_ENTRY_CNT_FX00;
2973 ha->isp_ops = &qlafx00_isp_ops;
2974 ha->port_down_retry_count = 30; /* default value */
2975 ha->mr.fw_hbt_cnt = QLAFX00_HEARTBEAT_INTERVAL;
2976 ha->mr.fw_reset_timer_tick = QLAFX00_RESET_INTERVAL;
2977 ha->mr.fw_critemp_timer_tick = QLAFX00_CRITEMP_INTERVAL;
2978 ha->mr.fw_hbt_en = 1;
2979 ha->mr.host_info_resend = false;
2980 ha->mr.hinfo_resend_timer_tick = QLAFX00_HINFO_RESEND_INTERVAL;
2981 } else if (IS_QLA27XX(ha)) {
2982 ha->portnum = PCI_FUNC(ha->pdev->devfn);
2983 ha->max_fibre_devices = MAX_FIBRE_DEVICES_2400;
2984 ha->mbx_count = MAILBOX_REGISTER_COUNT;
2985 req_length = REQUEST_ENTRY_CNT_83XX;
2986 rsp_length = RESPONSE_ENTRY_CNT_83XX;
2987 ha->tgt.atio_q_length = ATIO_ENTRY_CNT_24XX;
2988 ha->max_loop_id = SNS_LAST_LOOP_ID_2300;
2989 ha->init_cb_size = sizeof(struct mid_init_cb_81xx);
2990 ha->gid_list_info_size = 8;
2991 ha->optrom_size = OPTROM_SIZE_83XX;
2992 ha->nvram_npiv_size = QLA_MAX_VPORTS_QLA25XX;
2993 ha->isp_ops = &qla27xx_isp_ops;
2994 ha->flash_conf_off = FARX_ACCESS_FLASH_CONF_81XX;
2995 ha->flash_data_off = FARX_ACCESS_FLASH_DATA_81XX;
2996 ha->nvram_conf_off = ~0;
2997 ha->nvram_data_off = ~0;
2998 } else if (IS_QLA28XX(ha)) {
2999 ha->portnum = PCI_FUNC(ha->pdev->devfn);
3000 ha->max_fibre_devices = MAX_FIBRE_DEVICES_2400;
3001 ha->mbx_count = MAILBOX_REGISTER_COUNT;
3002 req_length = REQUEST_ENTRY_CNT_24XX;
3003 rsp_length = RESPONSE_ENTRY_CNT_2300;
3004 ha->tgt.atio_q_length = ATIO_ENTRY_CNT_24XX;
3005 ha->max_loop_id = SNS_LAST_LOOP_ID_2300;
3006 ha->init_cb_size = sizeof(struct mid_init_cb_81xx);
3007 ha->gid_list_info_size = 8;
3008 ha->optrom_size = OPTROM_SIZE_28XX;
3009 ha->nvram_npiv_size = QLA_MAX_VPORTS_QLA25XX;
3010 ha->isp_ops = &qla27xx_isp_ops;
3011 ha->flash_conf_off = FARX_ACCESS_FLASH_CONF_28XX;
3012 ha->flash_data_off = FARX_ACCESS_FLASH_DATA_28XX;
3013 ha->nvram_conf_off = ~0;
3014 ha->nvram_data_off = ~0;
3017 ql_dbg_pci(ql_dbg_init, pdev, 0x001e,
3018 "mbx_count=%d, req_length=%d, "
3019 "rsp_length=%d, max_loop_id=%d, init_cb_size=%d, "
3020 "gid_list_info_size=%d, optrom_size=%d, nvram_npiv_size=%d, "
3021 "max_fibre_devices=%d.\n",
3022 ha->mbx_count, req_length, rsp_length, ha->max_loop_id,
3023 ha->init_cb_size, ha->gid_list_info_size, ha->optrom_size,
3024 ha->nvram_npiv_size, ha->max_fibre_devices);
3025 ql_dbg_pci(ql_dbg_init, pdev, 0x001f,
3026 "isp_ops=%p, flash_conf_off=%d, "
3027 "flash_data_off=%d, nvram_conf_off=%d, nvram_data_off=%d.\n",
3028 ha->isp_ops, ha->flash_conf_off, ha->flash_data_off,
3029 ha->nvram_conf_off, ha->nvram_data_off);
3031 /* Configure PCI I/O space */
3032 ret = ha->isp_ops->iospace_config(ha);
3034 goto iospace_config_failed;
3036 ql_log_pci(ql_log_info, pdev, 0x001d,
3037 "Found an ISP%04X irq %d iobase 0x%p.\n",
3038 pdev->device, pdev->irq, ha->iobase);
3039 mutex_init(&ha->vport_lock);
3040 mutex_init(&ha->mq_lock);
3041 init_completion(&ha->mbx_cmd_comp);
3042 complete(&ha->mbx_cmd_comp);
3043 init_completion(&ha->mbx_intr_comp);
3044 init_completion(&ha->dcbx_comp);
3045 init_completion(&ha->lb_portup_comp);
3047 set_bit(0, (unsigned long *) ha->vp_idx_map);
3049 qla2x00_config_dma_addressing(ha);
3050 ql_dbg_pci(ql_dbg_init, pdev, 0x0020,
3051 "64 Bit addressing is %s.\n",
3052 ha->flags.enable_64bit_addressing ? "enable" :
3054 ret = qla2x00_mem_alloc(ha, req_length, rsp_length, &req, &rsp);
3056 ql_log_pci(ql_log_fatal, pdev, 0x0031,
3057 "Failed to allocate memory for adapter, aborting.\n");
3059 goto probe_hw_failed;
3062 req->max_q_depth = MAX_Q_DEPTH;
3063 if (ql2xmaxqdepth != 0 && ql2xmaxqdepth <= 0xffffU)
3064 req->max_q_depth = ql2xmaxqdepth;
3067 base_vha = qla2x00_create_host(sht, ha);
3070 goto probe_hw_failed;
3073 pci_set_drvdata(pdev, base_vha);
3074 set_bit(PFLG_DRIVER_PROBING, &base_vha->pci_flags);
3076 host = base_vha->host;
3077 base_vha->req = req;
3078 if (IS_QLA2XXX_MIDTYPE(ha))
3079 base_vha->mgmt_svr_loop_id =
3080 qla2x00_reserve_mgmt_server_loop_id(base_vha);
3082 base_vha->mgmt_svr_loop_id = MANAGEMENT_SERVER +
3085 /* Setup fcport template structure. */
3086 ha->mr.fcport.vha = base_vha;
3087 ha->mr.fcport.port_type = FCT_UNKNOWN;
3088 ha->mr.fcport.loop_id = FC_NO_LOOP_ID;
3089 qla2x00_set_fcport_state(&ha->mr.fcport, FCS_UNCONFIGURED);
3090 ha->mr.fcport.supported_classes = FC_COS_UNSPECIFIED;
3091 ha->mr.fcport.scan_state = 1;
3093 /* Set the SG table size based on ISP type */
3094 if (!IS_FWI2_CAPABLE(ha)) {
3096 host->sg_tablesize = 32;
3098 if (!IS_QLA82XX(ha))
3099 host->sg_tablesize = QLA_SG_ALL;
3101 host->max_id = ha->max_fibre_devices;
3102 host->cmd_per_lun = 3;
3103 host->unique_id = host->host_no;
3104 if (IS_T10_PI_CAPABLE(ha) && ql2xenabledif)
3105 host->max_cmd_len = 32;
3107 host->max_cmd_len = MAX_CMDSZ;
3108 host->max_channel = MAX_BUSES - 1;
3109 /* Older HBAs support only 16-bit LUNs */
3110 if (!IS_QLAFX00(ha) && !IS_FWI2_CAPABLE(ha) &&
3111 ql2xmaxlun > 0xffff)
3112 host->max_lun = 0xffff;
3114 host->max_lun = ql2xmaxlun;
3115 host->transportt = qla2xxx_transport_template;
3116 sht->vendor_id = (SCSI_NL_VID_TYPE_PCI | PCI_VENDOR_ID_QLOGIC);
3118 ql_dbg(ql_dbg_init, base_vha, 0x0033,
3119 "max_id=%d this_id=%d "
3120 "cmd_per_len=%d unique_id=%d max_cmd_len=%d max_channel=%d "
3121 "max_lun=%llu transportt=%p, vendor_id=%llu.\n", host->max_id,
3122 host->this_id, host->cmd_per_lun, host->unique_id,
3123 host->max_cmd_len, host->max_channel, host->max_lun,
3124 host->transportt, sht->vendor_id);
3126 INIT_WORK(&base_vha->iocb_work, qla2x00_iocb_work_fn);
3128 /* Set up the irqs */
3129 ret = qla2x00_request_irqs(ha, rsp);
3133 /* Alloc arrays of request and response ring ptrs */
3134 ret = qla2x00_alloc_queues(ha, req, rsp);
3136 ql_log(ql_log_fatal, base_vha, 0x003d,
3137 "Failed to allocate memory for queue pointers..."
3144 /* number of hardware queues supported by blk/scsi-mq*/
3145 host->nr_hw_queues = ha->max_qpairs;
3147 ql_dbg(ql_dbg_init, base_vha, 0x0192,
3148 "blk/scsi-mq enabled, HW queues = %d.\n", host->nr_hw_queues);
3150 if (ql2xnvmeenable) {
3151 host->nr_hw_queues = ha->max_qpairs;
3152 ql_dbg(ql_dbg_init, base_vha, 0x0194,
3153 "FC-NVMe support is enabled, HW queues=%d\n",
3154 host->nr_hw_queues);
3156 ql_dbg(ql_dbg_init, base_vha, 0x0193,
3157 "blk/scsi-mq disabled.\n");
3161 qlt_probe_one_stage1(base_vha, ha);
3163 pci_save_state(pdev);
3165 /* Assign back pointers */
3169 if (IS_QLAFX00(ha)) {
3170 ha->rsp_q_map[0] = rsp;
3171 ha->req_q_map[0] = req;
3172 set_bit(0, ha->req_qid_map);
3173 set_bit(0, ha->rsp_qid_map);
3176 /* FWI2-capable only. */
3177 req->req_q_in = &ha->iobase->isp24.req_q_in;
3178 req->req_q_out = &ha->iobase->isp24.req_q_out;
3179 rsp->rsp_q_in = &ha->iobase->isp24.rsp_q_in;
3180 rsp->rsp_q_out = &ha->iobase->isp24.rsp_q_out;
3181 if (ha->mqenable || IS_QLA83XX(ha) || IS_QLA27XX(ha) ||
3183 req->req_q_in = &ha->mqiobase->isp25mq.req_q_in;
3184 req->req_q_out = &ha->mqiobase->isp25mq.req_q_out;
3185 rsp->rsp_q_in = &ha->mqiobase->isp25mq.rsp_q_in;
3186 rsp->rsp_q_out = &ha->mqiobase->isp25mq.rsp_q_out;
3189 if (IS_QLAFX00(ha)) {
3190 req->req_q_in = &ha->iobase->ispfx00.req_q_in;
3191 req->req_q_out = &ha->iobase->ispfx00.req_q_out;
3192 rsp->rsp_q_in = &ha->iobase->ispfx00.rsp_q_in;
3193 rsp->rsp_q_out = &ha->iobase->ispfx00.rsp_q_out;
3196 if (IS_P3P_TYPE(ha)) {
3197 req->req_q_out = &ha->iobase->isp82.req_q_out[0];
3198 rsp->rsp_q_in = &ha->iobase->isp82.rsp_q_in[0];
3199 rsp->rsp_q_out = &ha->iobase->isp82.rsp_q_out[0];
3202 ql_dbg(ql_dbg_multiq, base_vha, 0xc009,
3203 "rsp_q_map=%p req_q_map=%p rsp->req=%p req->rsp=%p.\n",
3204 ha->rsp_q_map, ha->req_q_map, rsp->req, req->rsp);
3205 ql_dbg(ql_dbg_multiq, base_vha, 0xc00a,
3206 "req->req_q_in=%p req->req_q_out=%p "
3207 "rsp->rsp_q_in=%p rsp->rsp_q_out=%p.\n",
3208 req->req_q_in, req->req_q_out,
3209 rsp->rsp_q_in, rsp->rsp_q_out);
3210 ql_dbg(ql_dbg_init, base_vha, 0x003e,
3211 "rsp_q_map=%p req_q_map=%p rsp->req=%p req->rsp=%p.\n",
3212 ha->rsp_q_map, ha->req_q_map, rsp->req, req->rsp);
3213 ql_dbg(ql_dbg_init, base_vha, 0x003f,
3214 "req->req_q_in=%p req->req_q_out=%p rsp->rsp_q_in=%p rsp->rsp_q_out=%p.\n",
3215 req->req_q_in, req->req_q_out, rsp->rsp_q_in, rsp->rsp_q_out);
3217 ha->wq = alloc_workqueue("qla2xxx_wq", 0, 0);
3218 if (unlikely(!ha->wq)) {
3223 if (ha->isp_ops->initialize_adapter(base_vha)) {
3224 ql_log(ql_log_fatal, base_vha, 0x00d6,
3225 "Failed to initialize adapter - Adapter flags %x.\n",
3226 base_vha->device_flags);
3228 if (IS_QLA82XX(ha)) {
3229 qla82xx_idc_lock(ha);
3230 qla82xx_wr_32(ha, QLA82XX_CRB_DEV_STATE,
3231 QLA8XXX_DEV_FAILED);
3232 qla82xx_idc_unlock(ha);
3233 ql_log(ql_log_fatal, base_vha, 0x00d7,
3234 "HW State: FAILED.\n");
3235 } else if (IS_QLA8044(ha)) {
3236 qla8044_idc_lock(ha);
3237 qla8044_wr_direct(base_vha,
3238 QLA8044_CRB_DEV_STATE_INDEX,
3239 QLA8XXX_DEV_FAILED);
3240 qla8044_idc_unlock(ha);
3241 ql_log(ql_log_fatal, base_vha, 0x0150,
3242 "HW State: FAILED.\n");
3250 host->can_queue = QLAFX00_MAX_CANQUEUE;
3252 host->can_queue = req->num_outstanding_cmds - 10;
3254 ql_dbg(ql_dbg_init, base_vha, 0x0032,
3255 "can_queue=%d, req=%p, mgmt_svr_loop_id=%d, sg_tablesize=%d.\n",
3256 host->can_queue, base_vha->req,
3257 base_vha->mgmt_svr_loop_id, host->sg_tablesize);
3260 bool startit = false;
3262 if (QLA_TGT_MODE_ENABLED())
3265 if (ql2x_ini_mode == QLA2XXX_INI_MODE_ENABLED)
3268 /* Create start of day qpairs for Block MQ */
3269 for (i = 0; i < ha->max_qpairs; i++)
3270 qla2xxx_create_qpair(base_vha, 5, 0, startit);
3273 if (ha->flags.running_gold_fw)
3277 * Startup the kernel thread for this host adapter
3279 ha->dpc_thread = kthread_create(qla2x00_do_dpc, ha,
3280 "%s_dpc", base_vha->host_str);
3281 if (IS_ERR(ha->dpc_thread)) {
3282 ql_log(ql_log_fatal, base_vha, 0x00ed,
3283 "Failed to start DPC thread.\n");
3284 ret = PTR_ERR(ha->dpc_thread);
3285 ha->dpc_thread = NULL;
3288 ql_dbg(ql_dbg_init, base_vha, 0x00ee,
3289 "DPC thread started successfully.\n");
3292 * If we're not coming up in initiator mode, we might sit for
3293 * a while without waking up the dpc thread, which leads to a
3294 * stuck process warning. So just kick the dpc once here and
3295 * let the kthread start (and go back to sleep in qla2x00_do_dpc).
3297 qla2xxx_wake_dpc(base_vha);
3299 INIT_WORK(&ha->board_disable, qla2x00_disable_board_on_pci_error);
3301 if (IS_QLA8031(ha) || IS_MCTP_CAPABLE(ha)) {
3302 sprintf(wq_name, "qla2xxx_%lu_dpc_lp_wq", base_vha->host_no);
3303 ha->dpc_lp_wq = create_singlethread_workqueue(wq_name);
3304 INIT_WORK(&ha->idc_aen, qla83xx_service_idc_aen);
3306 sprintf(wq_name, "qla2xxx_%lu_dpc_hp_wq", base_vha->host_no);
3307 ha->dpc_hp_wq = create_singlethread_workqueue(wq_name);
3308 INIT_WORK(&ha->nic_core_reset, qla83xx_nic_core_reset_work);
3309 INIT_WORK(&ha->idc_state_handler,
3310 qla83xx_idc_state_handler_work);
3311 INIT_WORK(&ha->nic_core_unrecoverable,
3312 qla83xx_nic_core_unrecoverable_work);
3316 list_add_tail(&base_vha->list, &ha->vp_list);
3317 base_vha->host->irq = ha->pdev->irq;
3319 /* Initialized the timer */
3320 qla2x00_start_timer(base_vha, WATCH_INTERVAL);
3321 ql_dbg(ql_dbg_init, base_vha, 0x00ef,
3322 "Started qla2x00_timer with "
3323 "interval=%d.\n", WATCH_INTERVAL);
3324 ql_dbg(ql_dbg_init, base_vha, 0x00f0,
3325 "Detected hba at address=%p.\n",
3328 if (IS_T10_PI_CAPABLE(ha) && ql2xenabledif) {
3329 if (ha->fw_attributes & BIT_4) {
3330 int prot = 0, guard;
3332 base_vha->flags.difdix_supported = 1;
3333 ql_dbg(ql_dbg_init, base_vha, 0x00f1,
3334 "Registering for DIF/DIX type 1 and 3 protection.\n");
3335 if (ql2xenabledif == 1)
3336 prot = SHOST_DIX_TYPE0_PROTECTION;
3338 scsi_host_set_prot(host, ql2xprotmask);
3340 scsi_host_set_prot(host,
3341 prot | SHOST_DIF_TYPE1_PROTECTION
3342 | SHOST_DIF_TYPE2_PROTECTION
3343 | SHOST_DIF_TYPE3_PROTECTION
3344 | SHOST_DIX_TYPE1_PROTECTION
3345 | SHOST_DIX_TYPE2_PROTECTION
3346 | SHOST_DIX_TYPE3_PROTECTION);
3348 guard = SHOST_DIX_GUARD_CRC;
3350 if (IS_PI_IPGUARD_CAPABLE(ha) &&
3351 (ql2xenabledif > 1 || IS_PI_DIFB_DIX0_CAPABLE(ha)))
3352 guard |= SHOST_DIX_GUARD_IP;
3355 scsi_host_set_guard(host, ql2xprotguard);
3357 scsi_host_set_guard(host, guard);
3359 base_vha->flags.difdix_supported = 0;
3362 ha->isp_ops->enable_intrs(ha);
3364 if (IS_QLAFX00(ha)) {
3365 ret = qlafx00_fx_disc(base_vha,
3366 &base_vha->hw->mr.fcport, FXDISC_GET_CONFIG_INFO);
3367 host->sg_tablesize = (ha->mr.extended_io_enabled) ?
3371 ret = scsi_add_host(host, &pdev->dev);
3375 base_vha->flags.init_done = 1;
3376 base_vha->flags.online = 1;
3377 ha->prev_minidump_failed = 0;
3379 ql_dbg(ql_dbg_init, base_vha, 0x00f2,
3380 "Init done and hba is online.\n");
3382 if (qla_ini_mode_enabled(base_vha) ||
3383 qla_dual_mode_enabled(base_vha))
3384 scsi_scan_host(host);
3386 ql_dbg(ql_dbg_init, base_vha, 0x0122,
3387 "skipping scsi_scan_host() for non-initiator port\n");
3389 qla2x00_alloc_sysfs_attr(base_vha);
3391 if (IS_QLAFX00(ha)) {
3392 ret = qlafx00_fx_disc(base_vha,
3393 &base_vha->hw->mr.fcport, FXDISC_GET_PORT_INFO);
3395 /* Register system information */
3396 ret = qlafx00_fx_disc(base_vha,
3397 &base_vha->hw->mr.fcport, FXDISC_REG_HOST_INFO);
3400 qla2x00_init_host_attr(base_vha);
3402 qla2x00_dfs_setup(base_vha);
3404 ql_log(ql_log_info, base_vha, 0x00fb,
3405 "QLogic %s - %s.\n", ha->model_number, ha->model_desc);
3406 ql_log(ql_log_info, base_vha, 0x00fc,
3407 "ISP%04X: %s @ %s hdma%c host#=%ld fw=%s.\n",
3408 pdev->device, ha->isp_ops->pci_info_str(base_vha, pci_info,
3410 pci_name(pdev), ha->flags.enable_64bit_addressing ? '+' : '-',
3412 ha->isp_ops->fw_version_str(base_vha, fw_str, sizeof(fw_str)));
3414 qlt_add_target(ha, base_vha);
3416 clear_bit(PFLG_DRIVER_PROBING, &base_vha->pci_flags);
3418 if (test_bit(UNLOADING, &base_vha->dpc_flags))
3421 if (ha->flags.detected_lr_sfp) {
3422 ql_log(ql_log_info, base_vha, 0xffff,
3423 "Reset chip to pick up LR SFP setting\n");
3424 set_bit(ISP_ABORT_NEEDED, &base_vha->dpc_flags);
3425 qla2xxx_wake_dpc(base_vha);
3431 if (base_vha->gnl.l) {
3432 dma_free_coherent(&ha->pdev->dev, base_vha->gnl.size,
3433 base_vha->gnl.l, base_vha->gnl.ldma);
3434 base_vha->gnl.l = NULL;
3437 if (base_vha->timer_active)
3438 qla2x00_stop_timer(base_vha);
3439 base_vha->flags.online = 0;
3440 if (ha->dpc_thread) {
3441 struct task_struct *t = ha->dpc_thread;
3443 ha->dpc_thread = NULL;
3447 qla2x00_free_device(base_vha);
3448 scsi_host_put(base_vha->host);
3450 * Need to NULL out local req/rsp after
3451 * qla2x00_free_device => qla2x00_free_queues frees
3452 * what these are pointing to. Or else we'll
3453 * fall over below in qla2x00_free_req/rsp_que.
3459 qla2x00_mem_free(ha);
3460 qla2x00_free_req_que(ha, req);
3461 qla2x00_free_rsp_que(ha, rsp);
3462 qla2x00_clear_drv_active(ha);
3464 iospace_config_failed:
3465 if (IS_P3P_TYPE(ha)) {
3466 if (!ha->nx_pcibase)
3467 iounmap((device_reg_t *)ha->nx_pcibase);
3469 iounmap((device_reg_t *)ha->nxdb_wr_ptr);
3472 iounmap(ha->iobase);
3474 iounmap(ha->cregbase);
3476 pci_release_selected_regions(ha->pdev, ha->bars);
3480 pci_disable_device(pdev);
3485 qla2x00_shutdown(struct pci_dev *pdev)
3487 scsi_qla_host_t *vha;
3488 struct qla_hw_data *ha;
3490 vha = pci_get_drvdata(pdev);
3493 ql_log(ql_log_info, vha, 0xfffa,
3494 "Adapter shutdown\n");
3497 * Prevent future board_disable and wait
3498 * until any pending board_disable has completed.
3500 set_bit(PFLG_DRIVER_REMOVING, &vha->pci_flags);
3501 cancel_work_sync(&ha->board_disable);
3503 if (!atomic_read(&pdev->enable_cnt))
3506 /* Notify ISPFX00 firmware */
3508 qlafx00_driver_shutdown(vha, 20);
3510 /* Turn-off FCE trace */
3511 if (ha->flags.fce_enabled) {
3512 qla2x00_disable_fce_trace(vha, NULL, NULL);
3513 ha->flags.fce_enabled = 0;
3516 /* Turn-off EFT trace */
3518 qla2x00_disable_eft_trace(vha);
3520 if (IS_QLA25XX(ha) || IS_QLA2031(ha) || IS_QLA27XX(ha) ||
3522 if (ha->flags.fw_started)
3523 qla2x00_abort_isp_cleanup(vha);
3525 /* Stop currently executing firmware. */
3526 qla2x00_try_to_stop_firmware(vha);
3530 if (vha->timer_active)
3531 qla2x00_stop_timer(vha);
3533 /* Turn adapter off line */
3534 vha->flags.online = 0;
3536 /* turn-off interrupts on the card */
3537 if (ha->interrupts_on) {
3538 vha->flags.init_done = 0;
3539 ha->isp_ops->disable_intrs(ha);
3542 qla2x00_free_irqs(vha);
3544 qla2x00_free_fw_dump(ha);
3546 pci_disable_device(pdev);
3547 ql_log(ql_log_info, vha, 0xfffe,
3548 "Adapter shutdown successfully.\n");
3551 /* Deletes all the virtual ports for a given ha */
3553 qla2x00_delete_all_vps(struct qla_hw_data *ha, scsi_qla_host_t *base_vha)
3555 scsi_qla_host_t *vha;
3556 unsigned long flags;
3558 mutex_lock(&ha->vport_lock);
3559 while (ha->cur_vport_count) {
3560 spin_lock_irqsave(&ha->vport_slock, flags);
3562 BUG_ON(base_vha->list.next == &ha->vp_list);
3563 /* This assumes first entry in ha->vp_list is always base vha */
3564 vha = list_first_entry(&base_vha->list, scsi_qla_host_t, list);
3565 scsi_host_get(vha->host);
3567 spin_unlock_irqrestore(&ha->vport_slock, flags);
3568 mutex_unlock(&ha->vport_lock);
3570 qla_nvme_delete(vha);
3572 fc_vport_terminate(vha->fc_vport);
3573 scsi_host_put(vha->host);
3575 mutex_lock(&ha->vport_lock);
3577 mutex_unlock(&ha->vport_lock);
3580 /* Stops all deferred work threads */
3582 qla2x00_destroy_deferred_work(struct qla_hw_data *ha)
3584 /* Cancel all work and destroy DPC workqueues */
3585 if (ha->dpc_lp_wq) {
3586 cancel_work_sync(&ha->idc_aen);
3587 destroy_workqueue(ha->dpc_lp_wq);
3588 ha->dpc_lp_wq = NULL;
3591 if (ha->dpc_hp_wq) {
3592 cancel_work_sync(&ha->nic_core_reset);
3593 cancel_work_sync(&ha->idc_state_handler);
3594 cancel_work_sync(&ha->nic_core_unrecoverable);
3595 destroy_workqueue(ha->dpc_hp_wq);
3596 ha->dpc_hp_wq = NULL;
3599 /* Kill the kernel thread for this host */
3600 if (ha->dpc_thread) {
3601 struct task_struct *t = ha->dpc_thread;
3604 * qla2xxx_wake_dpc checks for ->dpc_thread
3605 * so we need to zero it out.
3607 ha->dpc_thread = NULL;
3613 qla2x00_unmap_iobases(struct qla_hw_data *ha)
3615 if (IS_QLA82XX(ha)) {
3617 iounmap((device_reg_t *)ha->nx_pcibase);
3619 iounmap((device_reg_t *)ha->nxdb_wr_ptr);
3622 iounmap(ha->iobase);
3625 iounmap(ha->cregbase);
3628 iounmap(ha->mqiobase);
3631 iounmap(ha->msixbase);
3636 qla2x00_clear_drv_active(struct qla_hw_data *ha)
3638 if (IS_QLA8044(ha)) {
3639 qla8044_idc_lock(ha);
3640 qla8044_clear_drv_active(ha);
3641 qla8044_idc_unlock(ha);
3642 } else if (IS_QLA82XX(ha)) {
3643 qla82xx_idc_lock(ha);
3644 qla82xx_clear_drv_active(ha);
3645 qla82xx_idc_unlock(ha);
3650 qla2x00_remove_one(struct pci_dev *pdev)
3652 scsi_qla_host_t *base_vha;
3653 struct qla_hw_data *ha;
3655 base_vha = pci_get_drvdata(pdev);
3657 ql_log(ql_log_info, base_vha, 0xb079,
3658 "Removing driver\n");
3660 /* Indicate device removal to prevent future board_disable and wait
3661 * until any pending board_disable has completed. */
3662 set_bit(PFLG_DRIVER_REMOVING, &base_vha->pci_flags);
3663 cancel_work_sync(&ha->board_disable);
3666 * If the PCI device is disabled then there was a PCI-disconnect and
3667 * qla2x00_disable_board_on_pci_error has taken care of most of the
3670 if (!atomic_read(&pdev->enable_cnt)) {
3671 dma_free_coherent(&ha->pdev->dev, base_vha->gnl.size,
3672 base_vha->gnl.l, base_vha->gnl.ldma);
3673 base_vha->gnl.l = NULL;
3674 scsi_host_put(base_vha->host);
3676 pci_set_drvdata(pdev, NULL);
3679 qla2x00_wait_for_hba_ready(base_vha);
3682 * if UNLOADING flag is already set, then continue unload,
3683 * where it was set first.
3685 if (test_and_set_bit(UNLOADING, &base_vha->dpc_flags))
3688 if (IS_QLA25XX(ha) || IS_QLA2031(ha) || IS_QLA27XX(ha) ||
3690 if (ha->flags.fw_started)
3691 qla2x00_abort_isp_cleanup(base_vha);
3692 } else if (!IS_QLAFX00(ha)) {
3693 if (IS_QLA8031(ha)) {
3694 ql_dbg(ql_dbg_p3p, base_vha, 0xb07e,
3695 "Clearing fcoe driver presence.\n");
3696 if (qla83xx_clear_drv_presence(base_vha) != QLA_SUCCESS)
3697 ql_dbg(ql_dbg_p3p, base_vha, 0xb079,
3698 "Error while clearing DRV-Presence.\n");
3701 qla2x00_try_to_stop_firmware(base_vha);
3704 qla2x00_wait_for_sess_deletion(base_vha);
3706 qla_nvme_delete(base_vha);
3708 dma_free_coherent(&ha->pdev->dev,
3709 base_vha->gnl.size, base_vha->gnl.l, base_vha->gnl.ldma);
3711 base_vha->gnl.l = NULL;
3713 vfree(base_vha->scan.l);
3716 qlafx00_driver_shutdown(base_vha, 20);
3718 qla2x00_delete_all_vps(ha, base_vha);
3720 qla2x00_dfs_remove(base_vha);
3722 qla84xx_put_chip(base_vha);
3725 if (base_vha->timer_active)
3726 qla2x00_stop_timer(base_vha);
3728 base_vha->flags.online = 0;
3730 /* free DMA memory */
3731 if (ha->exlogin_buf)
3732 qla2x00_free_exlogin_buffer(ha);
3734 /* free DMA memory */
3735 if (ha->exchoffld_buf)
3736 qla2x00_free_exchoffld_buffer(ha);
3738 qla2x00_destroy_deferred_work(ha);
3740 qlt_remove_target(ha, base_vha);
3742 qla2x00_free_sysfs_attr(base_vha, true);
3744 fc_remove_host(base_vha->host);
3745 qlt_remove_target_resources(ha);
3747 scsi_remove_host(base_vha->host);
3749 qla2x00_free_device(base_vha);
3751 qla2x00_clear_drv_active(ha);
3753 scsi_host_put(base_vha->host);
3755 qla2x00_unmap_iobases(ha);
3757 pci_release_selected_regions(ha->pdev, ha->bars);
3760 pci_disable_pcie_error_reporting(pdev);
3762 pci_disable_device(pdev);
3766 qla2x00_free_device(scsi_qla_host_t *vha)
3768 struct qla_hw_data *ha = vha->hw;
3770 qla2x00_abort_all_cmds(vha, DID_NO_CONNECT << 16);
3773 if (vha->timer_active)
3774 qla2x00_stop_timer(vha);
3776 qla25xx_delete_queues(vha);
3777 vha->flags.online = 0;
3779 /* turn-off interrupts on the card */
3780 if (ha->interrupts_on) {
3781 vha->flags.init_done = 0;
3782 ha->isp_ops->disable_intrs(ha);
3785 qla2x00_free_fcports(vha);
3787 qla2x00_free_irqs(vha);
3789 /* Flush the work queue and remove it */
3791 flush_workqueue(ha->wq);
3792 destroy_workqueue(ha->wq);
3797 qla2x00_mem_free(ha);
3799 qla82xx_md_free(vha);
3801 qla2x00_free_queues(ha);
3804 void qla2x00_free_fcports(struct scsi_qla_host *vha)
3806 fc_port_t *fcport, *tfcport;
3808 list_for_each_entry_safe(fcport, tfcport, &vha->vp_fcports, list)
3809 qla2x00_free_fcport(fcport);
3813 qla2x00_schedule_rport_del(struct scsi_qla_host *vha, fc_port_t *fcport,
3816 struct fc_rport *rport;
3817 scsi_qla_host_t *base_vha;
3818 unsigned long flags;
3823 rport = fcport->rport;
3825 base_vha = pci_get_drvdata(vha->hw->pdev);
3826 spin_lock_irqsave(vha->host->host_lock, flags);
3827 fcport->drport = rport;
3828 spin_unlock_irqrestore(vha->host->host_lock, flags);
3829 qlt_do_generation_tick(vha, &base_vha->total_fcport_update_gen);
3830 set_bit(FCPORT_UPDATE_NEEDED, &base_vha->dpc_flags);
3831 qla2xxx_wake_dpc(base_vha);
3836 ql_dbg(ql_dbg_disc, fcport->vha, 0x2109,
3837 "%s %8phN. rport %p roles %x\n",
3838 __func__, fcport->port_name, rport,
3840 fc_remote_port_delete(rport);
3842 qlt_do_generation_tick(vha, &now);
3847 * qla2x00_mark_device_lost Updates fcport state when device goes offline.
3849 * Input: ha = adapter block pointer. fcport = port structure pointer.
3855 void qla2x00_mark_device_lost(scsi_qla_host_t *vha, fc_port_t *fcport,
3856 int do_login, int defer)
3858 if (IS_QLAFX00(vha->hw)) {
3859 qla2x00_set_fcport_state(fcport, FCS_DEVICE_LOST);
3860 qla2x00_schedule_rport_del(vha, fcport, defer);
3864 if (atomic_read(&fcport->state) == FCS_ONLINE &&
3865 vha->vp_idx == fcport->vha->vp_idx) {
3866 qla2x00_set_fcport_state(fcport, FCS_DEVICE_LOST);
3867 qla2x00_schedule_rport_del(vha, fcport, defer);
3870 * We may need to retry the login, so don't change the state of the
3871 * port but do the retries.
3873 if (atomic_read(&fcport->state) != FCS_DEVICE_DEAD)
3874 qla2x00_set_fcport_state(fcport, FCS_DEVICE_LOST);
3879 set_bit(RELOGIN_NEEDED, &vha->dpc_flags);
3883 * qla2x00_mark_all_devices_lost
3884 * Updates fcport state when device goes offline.
3887 * ha = adapter block pointer.
3888 * fcport = port structure pointer.
3896 qla2x00_mark_all_devices_lost(scsi_qla_host_t *vha, int defer)
3900 ql_dbg(ql_dbg_disc, vha, 0x20f1,
3901 "Mark all dev lost\n");
3903 list_for_each_entry(fcport, &vha->vp_fcports, list) {
3904 fcport->scan_state = 0;
3905 qlt_schedule_sess_for_deletion(fcport);
3907 if (vha->vp_idx != 0 && vha->vp_idx != fcport->vha->vp_idx)
3911 * No point in marking the device as lost, if the device is
3914 if (atomic_read(&fcport->state) == FCS_DEVICE_DEAD)
3916 if (atomic_read(&fcport->state) == FCS_ONLINE) {
3917 qla2x00_set_fcport_state(fcport, FCS_DEVICE_LOST);
3919 qla2x00_schedule_rport_del(vha, fcport, defer);
3920 else if (vha->vp_idx == fcport->vha->vp_idx)
3921 qla2x00_schedule_rport_del(vha, fcport, defer);
3926 static void qla2x00_set_reserved_loop_ids(struct qla_hw_data *ha)
3930 if (IS_FWI2_CAPABLE(ha))
3933 for (i = 0; i < SNS_FIRST_LOOP_ID; i++)
3934 set_bit(i, ha->loop_id_map);
3935 set_bit(MANAGEMENT_SERVER, ha->loop_id_map);
3936 set_bit(BROADCAST, ha->loop_id_map);
3941 * Allocates adapter memory.
3948 qla2x00_mem_alloc(struct qla_hw_data *ha, uint16_t req_len, uint16_t rsp_len,
3949 struct req_que **req, struct rsp_que **rsp)
3953 ha->init_cb = dma_alloc_coherent(&ha->pdev->dev, ha->init_cb_size,
3954 &ha->init_cb_dma, GFP_KERNEL);
3958 if (qlt_mem_alloc(ha) < 0)
3959 goto fail_free_init_cb;
3961 ha->gid_list = dma_alloc_coherent(&ha->pdev->dev,
3962 qla2x00_gid_list_size(ha), &ha->gid_list_dma, GFP_KERNEL);
3964 goto fail_free_tgt_mem;
3966 ha->srb_mempool = mempool_create_slab_pool(SRB_MIN_REQ, srb_cachep);
3967 if (!ha->srb_mempool)
3968 goto fail_free_gid_list;
3970 if (IS_P3P_TYPE(ha)) {
3971 /* Allocate cache for CT6 Ctx. */
3973 ctx_cachep = kmem_cache_create("qla2xxx_ctx",
3974 sizeof(struct ct6_dsd), 0,
3975 SLAB_HWCACHE_ALIGN, NULL);
3977 goto fail_free_srb_mempool;
3979 ha->ctx_mempool = mempool_create_slab_pool(SRB_MIN_REQ,
3981 if (!ha->ctx_mempool)
3982 goto fail_free_srb_mempool;
3983 ql_dbg_pci(ql_dbg_init, ha->pdev, 0x0021,
3984 "ctx_cachep=%p ctx_mempool=%p.\n",
3985 ctx_cachep, ha->ctx_mempool);
3988 /* Get memory for cached NVRAM */
3989 ha->nvram = kzalloc(MAX_NVRAM_SIZE, GFP_KERNEL);
3991 goto fail_free_ctx_mempool;
3993 snprintf(name, sizeof(name), "%s_%d", QLA2XXX_DRIVER_NAME,
3995 ha->s_dma_pool = dma_pool_create(name, &ha->pdev->dev,
3996 DMA_POOL_SIZE, 8, 0);
3997 if (!ha->s_dma_pool)
3998 goto fail_free_nvram;
4000 ql_dbg_pci(ql_dbg_init, ha->pdev, 0x0022,
4001 "init_cb=%p gid_list=%p, srb_mempool=%p s_dma_pool=%p.\n",
4002 ha->init_cb, ha->gid_list, ha->srb_mempool, ha->s_dma_pool);
4004 if (IS_P3P_TYPE(ha) || ql2xenabledif) {
4005 ha->dl_dma_pool = dma_pool_create(name, &ha->pdev->dev,
4006 DSD_LIST_DMA_POOL_SIZE, 8, 0);
4007 if (!ha->dl_dma_pool) {
4008 ql_log_pci(ql_log_fatal, ha->pdev, 0x0023,
4009 "Failed to allocate memory for dl_dma_pool.\n");
4010 goto fail_s_dma_pool;
4013 ha->fcp_cmnd_dma_pool = dma_pool_create(name, &ha->pdev->dev,
4014 FCP_CMND_DMA_POOL_SIZE, 8, 0);
4015 if (!ha->fcp_cmnd_dma_pool) {
4016 ql_log_pci(ql_log_fatal, ha->pdev, 0x0024,
4017 "Failed to allocate memory for fcp_cmnd_dma_pool.\n");
4018 goto fail_dl_dma_pool;
4021 if (ql2xenabledif) {
4022 u64 bufsize = DIF_BUNDLING_DMA_POOL_SIZE;
4023 struct dsd_dma *dsd, *nxt;
4025 /* Creata a DMA pool of buffers for DIF bundling */
4026 ha->dif_bundl_pool = dma_pool_create(name,
4027 &ha->pdev->dev, DIF_BUNDLING_DMA_POOL_SIZE, 8, 0);
4028 if (!ha->dif_bundl_pool) {
4029 ql_dbg_pci(ql_dbg_init, ha->pdev, 0x0024,
4030 "%s: failed create dif_bundl_pool\n",
4032 goto fail_dif_bundl_dma_pool;
4035 INIT_LIST_HEAD(&ha->pool.good.head);
4036 INIT_LIST_HEAD(&ha->pool.unusable.head);
4037 ha->pool.good.count = 0;
4038 ha->pool.unusable.count = 0;
4039 for (i = 0; i < 128; i++) {
4040 dsd = kzalloc(sizeof(*dsd), GFP_ATOMIC);
4042 ql_dbg_pci(ql_dbg_init, ha->pdev,
4043 0xe0ee, "%s: failed alloc dsd\n",
4047 ha->dif_bundle_kallocs++;
4049 dsd->dsd_addr = dma_pool_alloc(
4050 ha->dif_bundl_pool, GFP_ATOMIC,
4051 &dsd->dsd_list_dma);
4052 if (!dsd->dsd_addr) {
4053 ql_dbg_pci(ql_dbg_init, ha->pdev,
4055 "%s: failed alloc ->dsd_addr\n",
4058 ha->dif_bundle_kallocs--;
4061 ha->dif_bundle_dma_allocs++;
4064 * if DMA buffer crosses 4G boundary,
4065 * put it on bad list
4067 if (MSD(dsd->dsd_list_dma) ^
4068 MSD(dsd->dsd_list_dma + bufsize)) {
4069 list_add_tail(&dsd->list,
4070 &ha->pool.unusable.head);
4071 ha->pool.unusable.count++;
4073 list_add_tail(&dsd->list,
4074 &ha->pool.good.head);
4075 ha->pool.good.count++;
4079 /* return the good ones back to the pool */
4080 list_for_each_entry_safe(dsd, nxt,
4081 &ha->pool.good.head, list) {
4082 list_del(&dsd->list);
4083 dma_pool_free(ha->dif_bundl_pool,
4084 dsd->dsd_addr, dsd->dsd_list_dma);
4085 ha->dif_bundle_dma_allocs--;
4087 ha->dif_bundle_kallocs--;
4090 ql_dbg_pci(ql_dbg_init, ha->pdev, 0x0024,
4091 "%s: dif dma pool (good=%u unusable=%u)\n",
4092 __func__, ha->pool.good.count,
4093 ha->pool.unusable.count);
4096 ql_dbg_pci(ql_dbg_init, ha->pdev, 0x0025,
4097 "dl_dma_pool=%p fcp_cmnd_dma_pool=%p dif_bundl_pool=%p.\n",
4098 ha->dl_dma_pool, ha->fcp_cmnd_dma_pool,
4099 ha->dif_bundl_pool);
4102 /* Allocate memory for SNS commands */
4103 if (IS_QLA2100(ha) || IS_QLA2200(ha)) {
4104 /* Get consistent memory allocated for SNS commands */
4105 ha->sns_cmd = dma_alloc_coherent(&ha->pdev->dev,
4106 sizeof(struct sns_cmd_pkt), &ha->sns_cmd_dma, GFP_KERNEL);
4109 ql_dbg_pci(ql_dbg_init, ha->pdev, 0x0026,
4110 "sns_cmd: %p.\n", ha->sns_cmd);
4112 /* Get consistent memory allocated for MS IOCB */
4113 ha->ms_iocb = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL,
4117 /* Get consistent memory allocated for CT SNS commands */
4118 ha->ct_sns = dma_alloc_coherent(&ha->pdev->dev,
4119 sizeof(struct ct_sns_pkt), &ha->ct_sns_dma, GFP_KERNEL);
4121 goto fail_free_ms_iocb;
4122 ql_dbg_pci(ql_dbg_init, ha->pdev, 0x0027,
4123 "ms_iocb=%p ct_sns=%p.\n",
4124 ha->ms_iocb, ha->ct_sns);
4127 /* Allocate memory for request ring */
4128 *req = kzalloc(sizeof(struct req_que), GFP_KERNEL);
4130 ql_log_pci(ql_log_fatal, ha->pdev, 0x0028,
4131 "Failed to allocate memory for req.\n");
4134 (*req)->length = req_len;
4135 (*req)->ring = dma_alloc_coherent(&ha->pdev->dev,
4136 ((*req)->length + 1) * sizeof(request_t),
4137 &(*req)->dma, GFP_KERNEL);
4138 if (!(*req)->ring) {
4139 ql_log_pci(ql_log_fatal, ha->pdev, 0x0029,
4140 "Failed to allocate memory for req_ring.\n");
4143 /* Allocate memory for response ring */
4144 *rsp = kzalloc(sizeof(struct rsp_que), GFP_KERNEL);
4146 ql_log_pci(ql_log_fatal, ha->pdev, 0x002a,
4147 "Failed to allocate memory for rsp.\n");
4151 (*rsp)->length = rsp_len;
4152 (*rsp)->ring = dma_alloc_coherent(&ha->pdev->dev,
4153 ((*rsp)->length + 1) * sizeof(response_t),
4154 &(*rsp)->dma, GFP_KERNEL);
4155 if (!(*rsp)->ring) {
4156 ql_log_pci(ql_log_fatal, ha->pdev, 0x002b,
4157 "Failed to allocate memory for rsp_ring.\n");
4162 ql_dbg_pci(ql_dbg_init, ha->pdev, 0x002c,
4163 "req=%p req->length=%d req->ring=%p rsp=%p "
4164 "rsp->length=%d rsp->ring=%p.\n",
4165 *req, (*req)->length, (*req)->ring, *rsp, (*rsp)->length,
4167 /* Allocate memory for NVRAM data for vports */
4168 if (ha->nvram_npiv_size) {
4169 ha->npiv_info = kcalloc(ha->nvram_npiv_size,
4170 sizeof(struct qla_npiv_entry),
4172 if (!ha->npiv_info) {
4173 ql_log_pci(ql_log_fatal, ha->pdev, 0x002d,
4174 "Failed to allocate memory for npiv_info.\n");
4175 goto fail_npiv_info;
4178 ha->npiv_info = NULL;
4180 /* Get consistent memory allocated for EX-INIT-CB. */
4181 if (IS_CNA_CAPABLE(ha) || IS_QLA2031(ha) || IS_QLA27XX(ha) ||
4183 ha->ex_init_cb = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL,
4184 &ha->ex_init_cb_dma);
4185 if (!ha->ex_init_cb)
4186 goto fail_ex_init_cb;
4187 ql_dbg_pci(ql_dbg_init, ha->pdev, 0x002e,
4188 "ex_init_cb=%p.\n", ha->ex_init_cb);
4191 INIT_LIST_HEAD(&ha->gbl_dsd_list);
4193 /* Get consistent memory allocated for Async Port-Database. */
4194 if (!IS_FWI2_CAPABLE(ha)) {
4195 ha->async_pd = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL,
4199 ql_dbg_pci(ql_dbg_init, ha->pdev, 0x002f,
4200 "async_pd=%p.\n", ha->async_pd);
4203 INIT_LIST_HEAD(&ha->vp_list);
4205 /* Allocate memory for our loop_id bitmap */
4206 ha->loop_id_map = kcalloc(BITS_TO_LONGS(LOOPID_MAP_SIZE),
4209 if (!ha->loop_id_map)
4210 goto fail_loop_id_map;
4212 qla2x00_set_reserved_loop_ids(ha);
4213 ql_dbg_pci(ql_dbg_init, ha->pdev, 0x0123,
4214 "loop_id_map=%p.\n", ha->loop_id_map);
4217 ha->sfp_data = dma_alloc_coherent(&ha->pdev->dev,
4218 SFP_DEV_SIZE, &ha->sfp_data_dma, GFP_KERNEL);
4219 if (!ha->sfp_data) {
4220 ql_dbg_pci(ql_dbg_init, ha->pdev, 0x011b,
4221 "Unable to allocate memory for SFP read-data.\n");
4225 ha->flt = dma_alloc_coherent(&ha->pdev->dev,
4226 sizeof(struct qla_flt_header) + FLT_REGIONS_SIZE, &ha->flt_dma,
4229 ql_dbg_pci(ql_dbg_init, ha->pdev, 0x011b,
4230 "Unable to allocate memory for FLT.\n");
4231 goto fail_flt_buffer;
4237 dma_free_coherent(&ha->pdev->dev, SFP_DEV_SIZE,
4238 ha->sfp_data, ha->sfp_data_dma);
4240 kfree(ha->loop_id_map);
4242 dma_pool_free(ha->s_dma_pool, ha->async_pd, ha->async_pd_dma);
4244 dma_pool_free(ha->s_dma_pool, ha->ex_init_cb, ha->ex_init_cb_dma);
4246 kfree(ha->npiv_info);
4248 dma_free_coherent(&ha->pdev->dev, ((*rsp)->length + 1) *
4249 sizeof(response_t), (*rsp)->ring, (*rsp)->dma);
4250 (*rsp)->ring = NULL;
4256 dma_free_coherent(&ha->pdev->dev, ((*req)->length + 1) *
4257 sizeof(request_t), (*req)->ring, (*req)->dma);
4258 (*req)->ring = NULL;
4264 dma_free_coherent(&ha->pdev->dev, sizeof(struct ct_sns_pkt),
4265 ha->ct_sns, ha->ct_sns_dma);
4269 dma_pool_free(ha->s_dma_pool, ha->ms_iocb, ha->ms_iocb_dma);
4271 ha->ms_iocb_dma = 0;
4274 dma_free_coherent(&ha->pdev->dev, sizeof(struct sns_cmd_pkt),
4275 ha->sns_cmd, ha->sns_cmd_dma);
4277 if (ql2xenabledif) {
4278 struct dsd_dma *dsd, *nxt;
4280 list_for_each_entry_safe(dsd, nxt, &ha->pool.unusable.head,
4282 list_del(&dsd->list);
4283 dma_pool_free(ha->dif_bundl_pool, dsd->dsd_addr,
4285 ha->dif_bundle_dma_allocs--;
4287 ha->dif_bundle_kallocs--;
4288 ha->pool.unusable.count--;
4290 dma_pool_destroy(ha->dif_bundl_pool);
4291 ha->dif_bundl_pool = NULL;
4294 fail_dif_bundl_dma_pool:
4295 if (IS_QLA82XX(ha) || ql2xenabledif) {
4296 dma_pool_destroy(ha->fcp_cmnd_dma_pool);
4297 ha->fcp_cmnd_dma_pool = NULL;
4300 if (IS_QLA82XX(ha) || ql2xenabledif) {
4301 dma_pool_destroy(ha->dl_dma_pool);
4302 ha->dl_dma_pool = NULL;
4305 dma_pool_destroy(ha->s_dma_pool);
4306 ha->s_dma_pool = NULL;
4310 fail_free_ctx_mempool:
4311 mempool_destroy(ha->ctx_mempool);
4312 ha->ctx_mempool = NULL;
4313 fail_free_srb_mempool:
4314 mempool_destroy(ha->srb_mempool);
4315 ha->srb_mempool = NULL;
4317 dma_free_coherent(&ha->pdev->dev, qla2x00_gid_list_size(ha),
4320 ha->gid_list = NULL;
4321 ha->gid_list_dma = 0;
4325 dma_free_coherent(&ha->pdev->dev, ha->init_cb_size, ha->init_cb,
4328 ha->init_cb_dma = 0;
4330 ql_log(ql_log_fatal, NULL, 0x0030,
4331 "Memory allocation failure.\n");
4336 qla2x00_set_exlogins_buffer(scsi_qla_host_t *vha)
4339 uint16_t size, max_cnt, temp;
4340 struct qla_hw_data *ha = vha->hw;
4342 /* Return if we don't need to alloacate any extended logins */
4346 if (!IS_EXLOGIN_OFFLD_CAPABLE(ha))
4349 ql_log(ql_log_info, vha, 0xd021, "EXLOGIN count: %d.\n", ql2xexlogins);
4351 rval = qla_get_exlogin_status(vha, &size, &max_cnt);
4352 if (rval != QLA_SUCCESS) {
4353 ql_log_pci(ql_log_fatal, ha->pdev, 0xd029,
4354 "Failed to get exlogin status.\n");
4358 temp = (ql2xexlogins > max_cnt) ? max_cnt : ql2xexlogins;
4361 if (temp != ha->exlogin_size) {
4362 qla2x00_free_exlogin_buffer(ha);
4363 ha->exlogin_size = temp;
4365 ql_log(ql_log_info, vha, 0xd024,
4366 "EXLOGIN: max_logins=%d, portdb=0x%x, total=%d.\n",
4367 max_cnt, size, temp);
4369 ql_log(ql_log_info, vha, 0xd025,
4370 "EXLOGIN: requested size=0x%x\n", ha->exlogin_size);
4372 /* Get consistent memory for extended logins */
4373 ha->exlogin_buf = dma_alloc_coherent(&ha->pdev->dev,
4374 ha->exlogin_size, &ha->exlogin_buf_dma, GFP_KERNEL);
4375 if (!ha->exlogin_buf) {
4376 ql_log_pci(ql_log_fatal, ha->pdev, 0xd02a,
4377 "Failed to allocate memory for exlogin_buf_dma.\n");
4382 /* Now configure the dma buffer */
4383 rval = qla_set_exlogin_mem_cfg(vha, ha->exlogin_buf_dma);
4385 ql_log(ql_log_fatal, vha, 0xd033,
4386 "Setup extended login buffer ****FAILED****.\n");
4387 qla2x00_free_exlogin_buffer(ha);
4394 * qla2x00_free_exlogin_buffer
4397 * ha = adapter block pointer
4400 qla2x00_free_exlogin_buffer(struct qla_hw_data *ha)
4402 if (ha->exlogin_buf) {
4403 dma_free_coherent(&ha->pdev->dev, ha->exlogin_size,
4404 ha->exlogin_buf, ha->exlogin_buf_dma);
4405 ha->exlogin_buf = NULL;
4406 ha->exlogin_size = 0;
4411 qla2x00_number_of_exch(scsi_qla_host_t *vha, u32 *ret_cnt, u16 max_cnt)
4414 struct init_cb_81xx *icb = (struct init_cb_81xx *)&vha->hw->init_cb;
4415 *ret_cnt = FW_DEF_EXCHANGES_CNT;
4417 if (max_cnt > vha->hw->max_exchg)
4418 max_cnt = vha->hw->max_exchg;
4420 if (qla_ini_mode_enabled(vha)) {
4421 if (vha->ql2xiniexchg > max_cnt)
4422 vha->ql2xiniexchg = max_cnt;
4424 if (vha->ql2xiniexchg > FW_DEF_EXCHANGES_CNT)
4425 *ret_cnt = vha->ql2xiniexchg;
4427 } else if (qla_tgt_mode_enabled(vha)) {
4428 if (vha->ql2xexchoffld > max_cnt) {
4429 vha->ql2xexchoffld = max_cnt;
4430 icb->exchange_count = cpu_to_le16(vha->ql2xexchoffld);
4433 if (vha->ql2xexchoffld > FW_DEF_EXCHANGES_CNT)
4434 *ret_cnt = vha->ql2xexchoffld;
4435 } else if (qla_dual_mode_enabled(vha)) {
4436 temp = vha->ql2xiniexchg + vha->ql2xexchoffld;
4437 if (temp > max_cnt) {
4438 vha->ql2xiniexchg -= (temp - max_cnt)/2;
4439 vha->ql2xexchoffld -= (((temp - max_cnt)/2) + 1);
4441 icb->exchange_count = cpu_to_le16(vha->ql2xexchoffld);
4444 if (temp > FW_DEF_EXCHANGES_CNT)
4450 qla2x00_set_exchoffld_buffer(scsi_qla_host_t *vha)
4454 u32 actual_cnt, totsz;
4455 struct qla_hw_data *ha = vha->hw;
4457 if (!ha->flags.exchoffld_enabled)
4460 if (!IS_EXCHG_OFFLD_CAPABLE(ha))
4464 rval = qla_get_exchoffld_status(vha, &size, &max_cnt);
4465 if (rval != QLA_SUCCESS) {
4466 ql_log_pci(ql_log_fatal, ha->pdev, 0xd012,
4467 "Failed to get exlogin status.\n");
4471 qla2x00_number_of_exch(vha, &actual_cnt, max_cnt);
4472 ql_log(ql_log_info, vha, 0xd014,
4473 "Actual exchange offload count: %d.\n", actual_cnt);
4475 totsz = actual_cnt * size;
4477 if (totsz != ha->exchoffld_size) {
4478 qla2x00_free_exchoffld_buffer(ha);
4479 if (actual_cnt <= FW_DEF_EXCHANGES_CNT) {
4480 ha->exchoffld_size = 0;
4481 ha->flags.exchoffld_enabled = 0;
4485 ha->exchoffld_size = totsz;
4487 ql_log(ql_log_info, vha, 0xd016,
4488 "Exchange offload: max_count=%d, actual count=%d entry sz=0x%x, total sz=0x%x\n",
4489 max_cnt, actual_cnt, size, totsz);
4491 ql_log(ql_log_info, vha, 0xd017,
4492 "Exchange Buffers requested size = 0x%x\n",
4493 ha->exchoffld_size);
4495 /* Get consistent memory for extended logins */
4496 ha->exchoffld_buf = dma_alloc_coherent(&ha->pdev->dev,
4497 ha->exchoffld_size, &ha->exchoffld_buf_dma, GFP_KERNEL);
4498 if (!ha->exchoffld_buf) {
4499 ql_log_pci(ql_log_fatal, ha->pdev, 0xd013,
4500 "Failed to allocate memory for Exchange Offload.\n");
4503 (FW_DEF_EXCHANGES_CNT + REDUCE_EXCHANGES_CNT)) {
4504 ha->max_exchg -= REDUCE_EXCHANGES_CNT;
4505 } else if (ha->max_exchg >
4506 (FW_DEF_EXCHANGES_CNT + 512)) {
4507 ha->max_exchg -= 512;
4509 ha->flags.exchoffld_enabled = 0;
4510 ql_log_pci(ql_log_fatal, ha->pdev, 0xd013,
4511 "Disabling Exchange offload due to lack of memory\n");
4513 ha->exchoffld_size = 0;
4517 } else if (!ha->exchoffld_buf || (actual_cnt <= FW_DEF_EXCHANGES_CNT)) {
4518 /* pathological case */
4519 qla2x00_free_exchoffld_buffer(ha);
4520 ha->exchoffld_size = 0;
4521 ha->flags.exchoffld_enabled = 0;
4522 ql_log(ql_log_info, vha, 0xd016,
4523 "Exchange offload not enable: offld size=%d, actual count=%d entry sz=0x%x, total sz=0x%x.\n",
4524 ha->exchoffld_size, actual_cnt, size, totsz);
4528 /* Now configure the dma buffer */
4529 rval = qla_set_exchoffld_mem_cfg(vha);
4531 ql_log(ql_log_fatal, vha, 0xd02e,
4532 "Setup exchange offload buffer ****FAILED****.\n");
4533 qla2x00_free_exchoffld_buffer(ha);
4535 /* re-adjust number of target exchange */
4536 struct init_cb_81xx *icb = (struct init_cb_81xx *)ha->init_cb;
4538 if (qla_ini_mode_enabled(vha))
4539 icb->exchange_count = 0;
4541 icb->exchange_count = cpu_to_le16(vha->ql2xexchoffld);
4548 * qla2x00_free_exchoffld_buffer
4551 * ha = adapter block pointer
4554 qla2x00_free_exchoffld_buffer(struct qla_hw_data *ha)
4556 if (ha->exchoffld_buf) {
4557 dma_free_coherent(&ha->pdev->dev, ha->exchoffld_size,
4558 ha->exchoffld_buf, ha->exchoffld_buf_dma);
4559 ha->exchoffld_buf = NULL;
4560 ha->exchoffld_size = 0;
4565 * qla2x00_free_fw_dump
4566 * Frees fw dump stuff.
4569 * ha = adapter block pointer
4572 qla2x00_free_fw_dump(struct qla_hw_data *ha)
4574 struct fwdt *fwdt = ha->fwdt;
4578 dma_free_coherent(&ha->pdev->dev,
4579 FCE_SIZE, ha->fce, ha->fce_dma);
4582 dma_free_coherent(&ha->pdev->dev,
4583 EFT_SIZE, ha->eft, ha->eft_dma);
4590 ha->flags.fce_enabled = 0;
4594 ha->fw_dump_cap_flags = 0;
4595 ha->fw_dump_reading = 0;
4597 ha->fw_dump_len = 0;
4599 for (j = 0; j < 2; j++, fwdt++) {
4601 vfree(fwdt->template);
4602 fwdt->template = NULL;
4609 * Frees all adapter allocated memory.
4612 * ha = adapter block pointer.
4615 qla2x00_mem_free(struct qla_hw_data *ha)
4617 qla2x00_free_fw_dump(ha);
4620 dma_free_coherent(&ha->pdev->dev, MCTP_DUMP_SIZE, ha->mctp_dump,
4622 ha->mctp_dump = NULL;
4624 mempool_destroy(ha->srb_mempool);
4625 ha->srb_mempool = NULL;
4628 dma_free_coherent(&ha->pdev->dev, DCBX_TLV_DATA_SIZE,
4629 ha->dcbx_tlv, ha->dcbx_tlv_dma);
4630 ha->dcbx_tlv = NULL;
4633 dma_free_coherent(&ha->pdev->dev, XGMAC_DATA_SIZE,
4634 ha->xgmac_data, ha->xgmac_data_dma);
4635 ha->xgmac_data = NULL;
4638 dma_free_coherent(&ha->pdev->dev, sizeof(struct sns_cmd_pkt),
4639 ha->sns_cmd, ha->sns_cmd_dma);
4641 ha->sns_cmd_dma = 0;
4644 dma_free_coherent(&ha->pdev->dev, sizeof(struct ct_sns_pkt),
4645 ha->ct_sns, ha->ct_sns_dma);
4650 dma_free_coherent(&ha->pdev->dev, SFP_DEV_SIZE, ha->sfp_data,
4652 ha->sfp_data = NULL;
4655 dma_free_coherent(&ha->pdev->dev,
4656 sizeof(struct qla_flt_header) + FLT_REGIONS_SIZE,
4657 ha->flt, ha->flt_dma);
4662 dma_pool_free(ha->s_dma_pool, ha->ms_iocb, ha->ms_iocb_dma);
4664 ha->ms_iocb_dma = 0;
4667 dma_pool_free(ha->s_dma_pool,
4668 ha->ex_init_cb, ha->ex_init_cb_dma);
4669 ha->ex_init_cb = NULL;
4670 ha->ex_init_cb_dma = 0;
4673 dma_pool_free(ha->s_dma_pool, ha->async_pd, ha->async_pd_dma);
4674 ha->async_pd = NULL;
4675 ha->async_pd_dma = 0;
4677 dma_pool_destroy(ha->s_dma_pool);
4678 ha->s_dma_pool = NULL;
4681 dma_free_coherent(&ha->pdev->dev, qla2x00_gid_list_size(ha),
4682 ha->gid_list, ha->gid_list_dma);
4683 ha->gid_list = NULL;
4684 ha->gid_list_dma = 0;
4686 if (IS_QLA82XX(ha)) {
4687 if (!list_empty(&ha->gbl_dsd_list)) {
4688 struct dsd_dma *dsd_ptr, *tdsd_ptr;
4690 /* clean up allocated prev pool */
4691 list_for_each_entry_safe(dsd_ptr,
4692 tdsd_ptr, &ha->gbl_dsd_list, list) {
4693 dma_pool_free(ha->dl_dma_pool,
4694 dsd_ptr->dsd_addr, dsd_ptr->dsd_list_dma);
4695 list_del(&dsd_ptr->list);
4701 dma_pool_destroy(ha->dl_dma_pool);
4702 ha->dl_dma_pool = NULL;
4704 dma_pool_destroy(ha->fcp_cmnd_dma_pool);
4705 ha->fcp_cmnd_dma_pool = NULL;
4707 mempool_destroy(ha->ctx_mempool);
4708 ha->ctx_mempool = NULL;
4710 if (ql2xenabledif && ha->dif_bundl_pool) {
4711 struct dsd_dma *dsd, *nxt;
4713 list_for_each_entry_safe(dsd, nxt, &ha->pool.unusable.head,
4715 list_del(&dsd->list);
4716 dma_pool_free(ha->dif_bundl_pool, dsd->dsd_addr,
4718 ha->dif_bundle_dma_allocs--;
4720 ha->dif_bundle_kallocs--;
4721 ha->pool.unusable.count--;
4723 list_for_each_entry_safe(dsd, nxt, &ha->pool.good.head, list) {
4724 list_del(&dsd->list);
4725 dma_pool_free(ha->dif_bundl_pool, dsd->dsd_addr,
4727 ha->dif_bundle_dma_allocs--;
4729 ha->dif_bundle_kallocs--;
4733 dma_pool_destroy(ha->dif_bundl_pool);
4734 ha->dif_bundl_pool = NULL;
4739 dma_free_coherent(&ha->pdev->dev, ha->init_cb_size,
4740 ha->init_cb, ha->init_cb_dma);
4742 ha->init_cb_dma = 0;
4744 vfree(ha->optrom_buffer);
4745 ha->optrom_buffer = NULL;
4748 kfree(ha->npiv_info);
4749 ha->npiv_info = NULL;
4752 kfree(ha->loop_id_map);
4753 ha->loop_id_map = NULL;
4756 struct scsi_qla_host *qla2x00_create_host(struct scsi_host_template *sht,
4757 struct qla_hw_data *ha)
4759 struct Scsi_Host *host;
4760 struct scsi_qla_host *vha = NULL;
4762 host = scsi_host_alloc(sht, sizeof(scsi_qla_host_t));
4764 ql_log_pci(ql_log_fatal, ha->pdev, 0x0107,
4765 "Failed to allocate host from the scsi layer, aborting.\n");
4769 /* Clear our data area */
4770 vha = shost_priv(host);
4771 memset(vha, 0, sizeof(scsi_qla_host_t));
4774 vha->host_no = host->host_no;
4777 vha->qlini_mode = ql2x_ini_mode;
4778 vha->ql2xexchoffld = ql2xexchoffld;
4779 vha->ql2xiniexchg = ql2xiniexchg;
4781 INIT_LIST_HEAD(&vha->vp_fcports);
4782 INIT_LIST_HEAD(&vha->work_list);
4783 INIT_LIST_HEAD(&vha->list);
4784 INIT_LIST_HEAD(&vha->qla_cmd_list);
4785 INIT_LIST_HEAD(&vha->qla_sess_op_cmd_list);
4786 INIT_LIST_HEAD(&vha->logo_list);
4787 INIT_LIST_HEAD(&vha->plogi_ack_list);
4788 INIT_LIST_HEAD(&vha->qp_list);
4789 INIT_LIST_HEAD(&vha->gnl.fcports);
4790 INIT_LIST_HEAD(&vha->gpnid_list);
4791 INIT_WORK(&vha->iocb_work, qla2x00_iocb_work_fn);
4793 spin_lock_init(&vha->work_lock);
4794 spin_lock_init(&vha->cmd_list_lock);
4795 init_waitqueue_head(&vha->fcport_waitQ);
4796 init_waitqueue_head(&vha->vref_waitq);
4798 vha->gnl.size = sizeof(struct get_name_list_extended) *
4799 (ha->max_loop_id + 1);
4800 vha->gnl.l = dma_alloc_coherent(&ha->pdev->dev,
4801 vha->gnl.size, &vha->gnl.ldma, GFP_KERNEL);
4803 ql_log(ql_log_fatal, vha, 0xd04a,
4804 "Alloc failed for name list.\n");
4805 scsi_host_put(vha->host);
4809 /* todo: what about ext login? */
4810 vha->scan.size = ha->max_fibre_devices * sizeof(struct fab_scan_rp);
4811 vha->scan.l = vmalloc(vha->scan.size);
4813 ql_log(ql_log_fatal, vha, 0xd04a,
4814 "Alloc failed for scan database.\n");
4815 dma_free_coherent(&ha->pdev->dev, vha->gnl.size,
4816 vha->gnl.l, vha->gnl.ldma);
4818 scsi_host_put(vha->host);
4821 INIT_DELAYED_WORK(&vha->scan.scan_work, qla_scan_work_fn);
4823 sprintf(vha->host_str, "%s_%ld", QLA2XXX_DRIVER_NAME, vha->host_no);
4824 ql_dbg(ql_dbg_init, vha, 0x0041,
4825 "Allocated the host=%p hw=%p vha=%p dev_name=%s",
4826 vha->host, vha->hw, vha,
4827 dev_name(&(ha->pdev->dev)));
4832 struct qla_work_evt *
4833 qla2x00_alloc_work(struct scsi_qla_host *vha, enum qla_work_type type)
4835 struct qla_work_evt *e;
4838 if (test_bit(UNLOADING, &vha->dpc_flags))
4841 QLA_VHA_MARK_BUSY(vha, bail);
4845 e = kzalloc(sizeof(struct qla_work_evt), GFP_ATOMIC);
4847 QLA_VHA_MARK_NOT_BUSY(vha);
4851 INIT_LIST_HEAD(&e->list);
4853 e->flags = QLA_EVT_FLAG_FREE;
4858 qla2x00_post_work(struct scsi_qla_host *vha, struct qla_work_evt *e)
4860 unsigned long flags;
4863 spin_lock_irqsave(&vha->work_lock, flags);
4864 list_add_tail(&e->list, &vha->work_list);
4866 if (!test_and_set_bit(IOCB_WORK_ACTIVE, &vha->dpc_flags))
4869 spin_unlock_irqrestore(&vha->work_lock, flags);
4872 queue_work(vha->hw->wq, &vha->iocb_work);
4878 qla2x00_post_aen_work(struct scsi_qla_host *vha, enum fc_host_event_code code,
4881 struct qla_work_evt *e;
4883 e = qla2x00_alloc_work(vha, QLA_EVT_AEN);
4885 return QLA_FUNCTION_FAILED;
4887 e->u.aen.code = code;
4888 e->u.aen.data = data;
4889 return qla2x00_post_work(vha, e);
4893 qla2x00_post_idc_ack_work(struct scsi_qla_host *vha, uint16_t *mb)
4895 struct qla_work_evt *e;
4897 e = qla2x00_alloc_work(vha, QLA_EVT_IDC_ACK);
4899 return QLA_FUNCTION_FAILED;
4901 memcpy(e->u.idc_ack.mb, mb, QLA_IDC_ACK_REGS * sizeof(uint16_t));
4902 return qla2x00_post_work(vha, e);
4905 #define qla2x00_post_async_work(name, type) \
4906 int qla2x00_post_async_##name##_work( \
4907 struct scsi_qla_host *vha, \
4908 fc_port_t *fcport, uint16_t *data) \
4910 struct qla_work_evt *e; \
4912 e = qla2x00_alloc_work(vha, type); \
4914 return QLA_FUNCTION_FAILED; \
4916 e->u.logio.fcport = fcport; \
4918 e->u.logio.data[0] = data[0]; \
4919 e->u.logio.data[1] = data[1]; \
4921 fcport->flags |= FCF_ASYNC_ACTIVE; \
4922 return qla2x00_post_work(vha, e); \
4925 qla2x00_post_async_work(login, QLA_EVT_ASYNC_LOGIN);
4926 qla2x00_post_async_work(logout, QLA_EVT_ASYNC_LOGOUT);
4927 qla2x00_post_async_work(logout_done, QLA_EVT_ASYNC_LOGOUT_DONE);
4928 qla2x00_post_async_work(adisc, QLA_EVT_ASYNC_ADISC);
4929 qla2x00_post_async_work(prlo, QLA_EVT_ASYNC_PRLO);
4930 qla2x00_post_async_work(prlo_done, QLA_EVT_ASYNC_PRLO_DONE);
4933 qla2x00_post_uevent_work(struct scsi_qla_host *vha, u32 code)
4935 struct qla_work_evt *e;
4937 e = qla2x00_alloc_work(vha, QLA_EVT_UEVENT);
4939 return QLA_FUNCTION_FAILED;
4941 e->u.uevent.code = code;
4942 return qla2x00_post_work(vha, e);
4946 qla2x00_uevent_emit(struct scsi_qla_host *vha, u32 code)
4948 char event_string[40];
4949 char *envp[] = { event_string, NULL };
4952 case QLA_UEVENT_CODE_FW_DUMP:
4953 snprintf(event_string, sizeof(event_string), "FW_DUMP=%ld",
4960 kobject_uevent_env(&vha->hw->pdev->dev.kobj, KOBJ_CHANGE, envp);
4964 qlafx00_post_aenfx_work(struct scsi_qla_host *vha, uint32_t evtcode,
4965 uint32_t *data, int cnt)
4967 struct qla_work_evt *e;
4969 e = qla2x00_alloc_work(vha, QLA_EVT_AENFX);
4971 return QLA_FUNCTION_FAILED;
4973 e->u.aenfx.evtcode = evtcode;
4974 e->u.aenfx.count = cnt;
4975 memcpy(e->u.aenfx.mbx, data, sizeof(*data) * cnt);
4976 return qla2x00_post_work(vha, e);
4979 void qla24xx_sched_upd_fcport(fc_port_t *fcport)
4981 unsigned long flags;
4983 if (IS_SW_RESV_ADDR(fcport->d_id))
4986 spin_lock_irqsave(&fcport->vha->work_lock, flags);
4987 if (fcport->disc_state == DSC_UPD_FCPORT) {
4988 spin_unlock_irqrestore(&fcport->vha->work_lock, flags);
4991 fcport->jiffies_at_registration = jiffies;
4992 fcport->sec_since_registration = 0;
4993 fcport->next_disc_state = DSC_DELETED;
4994 qla2x00_set_fcport_disc_state(fcport, DSC_UPD_FCPORT);
4995 spin_unlock_irqrestore(&fcport->vha->work_lock, flags);
4997 queue_work(system_unbound_wq, &fcport->reg_work);
5001 void qla24xx_create_new_sess(struct scsi_qla_host *vha, struct qla_work_evt *e)
5003 unsigned long flags;
5004 fc_port_t *fcport = NULL, *tfcp;
5005 struct qlt_plogi_ack_t *pla =
5006 (struct qlt_plogi_ack_t *)e->u.new_sess.pla;
5007 uint8_t free_fcport = 0;
5009 ql_dbg(ql_dbg_disc, vha, 0xffff,
5010 "%s %d %8phC enter\n",
5011 __func__, __LINE__, e->u.new_sess.port_name);
5013 spin_lock_irqsave(&vha->hw->tgt.sess_lock, flags);
5014 fcport = qla2x00_find_fcport_by_wwpn(vha, e->u.new_sess.port_name, 1);
5016 fcport->d_id = e->u.new_sess.id;
5018 fcport->fw_login_state = DSC_LS_PLOGI_PEND;
5019 memcpy(fcport->node_name,
5020 pla->iocb.u.isp24.u.plogi.node_name,
5022 qlt_plogi_ack_link(vha, pla, fcport, QLT_PLOGI_LINK_SAME_WWN);
5023 /* we took an extra ref_count to prevent PLOGI ACK when
5024 * fcport/sess has not been created.
5029 spin_unlock_irqrestore(&vha->hw->tgt.sess_lock, flags);
5030 fcport = qla2x00_alloc_fcport(vha, GFP_KERNEL);
5032 fcport->d_id = e->u.new_sess.id;
5033 fcport->flags |= FCF_FABRIC_DEVICE;
5034 fcport->fw_login_state = DSC_LS_PLOGI_PEND;
5036 memcpy(fcport->port_name, e->u.new_sess.port_name,
5039 fcport->fc4_type = e->u.new_sess.fc4_type;
5040 if (e->u.new_sess.fc4_type & FS_FCP_IS_N2N) {
5041 fcport->fc4_type = FS_FC4TYPE_FCP;
5042 fcport->n2n_flag = 1;
5043 if (vha->flags.nvme_enabled)
5044 fcport->fc4_type |= FS_FC4TYPE_NVME;
5048 ql_dbg(ql_dbg_disc, vha, 0xffff,
5049 "%s %8phC mem alloc fail.\n",
5050 __func__, e->u.new_sess.port_name);
5053 list_del(&pla->list);
5054 kmem_cache_free(qla_tgt_plogi_cachep, pla);
5059 spin_lock_irqsave(&vha->hw->tgt.sess_lock, flags);
5060 /* search again to make sure no one else got ahead */
5061 tfcp = qla2x00_find_fcport_by_wwpn(vha,
5062 e->u.new_sess.port_name, 1);
5064 /* should rarily happen */
5065 ql_dbg(ql_dbg_disc, vha, 0xffff,
5066 "%s %8phC found existing fcport b4 add. DS %d LS %d\n",
5067 __func__, tfcp->port_name, tfcp->disc_state,
5068 tfcp->fw_login_state);
5072 list_add_tail(&fcport->list, &vha->vp_fcports);
5076 qlt_plogi_ack_link(vha, pla, fcport,
5077 QLT_PLOGI_LINK_SAME_WWN);
5081 spin_unlock_irqrestore(&vha->hw->tgt.sess_lock, flags);
5084 fcport->id_changed = 1;
5085 fcport->scan_state = QLA_FCPORT_FOUND;
5086 fcport->chip_reset = vha->hw->base_qpair->chip_reset;
5087 memcpy(fcport->node_name, e->u.new_sess.node_name, WWN_SIZE);
5090 if (pla->iocb.u.isp24.status_subcode == ELS_PRLI) {
5093 fcport->fw_login_state = DSC_LS_PRLI_PEND;
5097 pla->iocb.u.isp24.nport_handle);
5098 fcport->fw_login_state = DSC_LS_PRLI_PEND;
5101 pla->iocb.u.isp24.u.prli.wd3_lo);
5104 fcport->conf_compl_supported = 1;
5106 if ((wd3_lo & BIT_4) == 0)
5107 fcport->port_type = FCT_INITIATOR;
5109 fcport->port_type = FCT_TARGET;
5111 qlt_plogi_ack_unref(vha, pla);
5113 fc_port_t *dfcp = NULL;
5115 spin_lock_irqsave(&vha->hw->tgt.sess_lock, flags);
5116 tfcp = qla2x00_find_fcport_by_nportid(vha,
5117 &e->u.new_sess.id, 1);
5118 if (tfcp && (tfcp != fcport)) {
5120 * We have a conflict fcport with same NportID.
5122 ql_dbg(ql_dbg_disc, vha, 0xffff,
5123 "%s %8phC found conflict b4 add. DS %d LS %d\n",
5124 __func__, tfcp->port_name, tfcp->disc_state,
5125 tfcp->fw_login_state);
5127 switch (tfcp->disc_state) {
5130 case DSC_DELETE_PEND:
5131 fcport->login_pause = 1;
5132 tfcp->conflict = fcport;
5135 fcport->login_pause = 1;
5136 tfcp->conflict = fcport;
5141 spin_unlock_irqrestore(&vha->hw->tgt.sess_lock, flags);
5143 qlt_schedule_sess_for_deletion(tfcp);
5145 if (N2N_TOPO(vha->hw)) {
5146 fcport->flags &= ~FCF_FABRIC_DEVICE;
5147 fcport->keep_nport_handle = 1;
5148 if (vha->flags.nvme_enabled) {
5150 (FS_FC4TYPE_NVME | FS_FC4TYPE_FCP);
5151 fcport->n2n_flag = 1;
5153 fcport->fw_login_state = 0;
5155 * wait link init done before sending login
5158 qla24xx_fcport_handle_login(vha, fcport);
5164 qla2x00_free_fcport(fcport);
5166 list_del(&pla->list);
5167 kmem_cache_free(qla_tgt_plogi_cachep, pla);
5172 static void qla_sp_retry(struct scsi_qla_host *vha, struct qla_work_evt *e)
5174 struct srb *sp = e->u.iosb.sp;
5177 rval = qla2x00_start_sp(sp);
5178 if (rval != QLA_SUCCESS) {
5179 ql_dbg(ql_dbg_disc, vha, 0x2043,
5180 "%s: %s: Re-issue IOCB failed (%d).\n",
5181 __func__, sp->name, rval);
5182 qla24xx_sp_unmap(vha, sp);
5187 qla2x00_do_work(struct scsi_qla_host *vha)
5189 struct qla_work_evt *e, *tmp;
5190 unsigned long flags;
5194 spin_lock_irqsave(&vha->work_lock, flags);
5195 list_splice_init(&vha->work_list, &work);
5196 spin_unlock_irqrestore(&vha->work_lock, flags);
5198 list_for_each_entry_safe(e, tmp, &work, list) {
5202 fc_host_post_event(vha->host, fc_get_event_number(),
5203 e->u.aen.code, e->u.aen.data);
5205 case QLA_EVT_IDC_ACK:
5206 qla81xx_idc_ack(vha, e->u.idc_ack.mb);
5208 case QLA_EVT_ASYNC_LOGIN:
5209 qla2x00_async_login(vha, e->u.logio.fcport,
5212 case QLA_EVT_ASYNC_LOGOUT:
5213 rc = qla2x00_async_logout(vha, e->u.logio.fcport);
5215 case QLA_EVT_ASYNC_LOGOUT_DONE:
5216 qla2x00_async_logout_done(vha, e->u.logio.fcport,
5219 case QLA_EVT_ASYNC_ADISC:
5220 qla2x00_async_adisc(vha, e->u.logio.fcport,
5223 case QLA_EVT_UEVENT:
5224 qla2x00_uevent_emit(vha, e->u.uevent.code);
5227 qlafx00_process_aen(vha, e);
5230 qla24xx_async_gpnid(vha, &e->u.gpnid.id);
5233 qla24xx_sp_unmap(vha, e->u.iosb.sp);
5235 case QLA_EVT_RELOGIN:
5236 qla2x00_relogin(vha);
5238 case QLA_EVT_NEW_SESS:
5239 qla24xx_create_new_sess(vha, e);
5242 qla24xx_async_gpdb(vha, e->u.fcport.fcport,
5246 qla24xx_async_prli(vha, e->u.fcport.fcport);
5249 qla24xx_async_gpsc(vha, e->u.fcport.fcport);
5252 qla24xx_async_gnl(vha, e->u.fcport.fcport);
5255 qla24xx_do_nack_work(vha, e);
5257 case QLA_EVT_ASYNC_PRLO:
5258 rc = qla2x00_async_prlo(vha, e->u.logio.fcport);
5260 case QLA_EVT_ASYNC_PRLO_DONE:
5261 qla2x00_async_prlo_done(vha, e->u.logio.fcport,
5265 qla24xx_async_gpnft(vha, e->u.gpnft.fc4_type,
5268 case QLA_EVT_GPNFT_DONE:
5269 qla24xx_async_gpnft_done(vha, e->u.iosb.sp);
5271 case QLA_EVT_GNNFT_DONE:
5272 qla24xx_async_gnnft_done(vha, e->u.iosb.sp);
5275 qla24xx_async_gnnid(vha, e->u.fcport.fcport);
5277 case QLA_EVT_GFPNID:
5278 qla24xx_async_gfpnid(vha, e->u.fcport.fcport);
5280 case QLA_EVT_SP_RETRY:
5281 qla_sp_retry(vha, e);
5284 qla_do_iidma_work(vha, e->u.fcport.fcport);
5286 case QLA_EVT_ELS_PLOGI:
5287 qla24xx_els_dcmd2_iocb(vha, ELS_DCMD_PLOGI,
5288 e->u.fcport.fcport, false);
5293 /* put 'work' at head of 'vha->work_list' */
5294 spin_lock_irqsave(&vha->work_lock, flags);
5295 list_splice(&work, &vha->work_list);
5296 spin_unlock_irqrestore(&vha->work_lock, flags);
5299 list_del_init(&e->list);
5300 if (e->flags & QLA_EVT_FLAG_FREE)
5303 /* For each work completed decrement vha ref count */
5304 QLA_VHA_MARK_NOT_BUSY(vha);
5308 int qla24xx_post_relogin_work(struct scsi_qla_host *vha)
5310 struct qla_work_evt *e;
5312 e = qla2x00_alloc_work(vha, QLA_EVT_RELOGIN);
5315 set_bit(RELOGIN_NEEDED, &vha->dpc_flags);
5316 return QLA_FUNCTION_FAILED;
5319 return qla2x00_post_work(vha, e);
5322 /* Relogins all the fcports of a vport
5323 * Context: dpc thread
5325 void qla2x00_relogin(struct scsi_qla_host *vha)
5328 int status, relogin_needed = 0;
5329 struct event_arg ea;
5331 list_for_each_entry(fcport, &vha->vp_fcports, list) {
5333 * If the port is not ONLINE then try to login
5334 * to it if we haven't run out of retries.
5336 if (atomic_read(&fcport->state) != FCS_ONLINE &&
5337 fcport->login_retry) {
5338 if (fcport->scan_state != QLA_FCPORT_FOUND ||
5339 fcport->disc_state == DSC_LOGIN_COMPLETE)
5342 if (fcport->flags & (FCF_ASYNC_SENT|FCF_ASYNC_ACTIVE) ||
5343 fcport->disc_state == DSC_DELETE_PEND) {
5346 if (vha->hw->current_topology != ISP_CFG_NL) {
5347 memset(&ea, 0, sizeof(ea));
5349 qla24xx_handle_relogin_event(vha, &ea);
5350 } else if (vha->hw->current_topology ==
5352 IS_QLA2XXX_MIDTYPE(vha->hw)) {
5353 (void)qla24xx_fcport_handle_login(vha,
5355 } else if (vha->hw->current_topology ==
5357 fcport->login_retry--;
5359 qla2x00_local_device_login(vha,
5361 if (status == QLA_SUCCESS) {
5362 fcport->old_loop_id =
5364 ql_dbg(ql_dbg_disc, vha, 0x2003,
5365 "Port login OK: logged in ID 0x%x.\n",
5367 qla2x00_update_fcport
5369 } else if (status == 1) {
5370 set_bit(RELOGIN_NEEDED,
5372 /* retry the login again */
5373 ql_dbg(ql_dbg_disc, vha, 0x2007,
5374 "Retrying %d login again loop_id 0x%x.\n",
5375 fcport->login_retry,
5378 fcport->login_retry = 0;
5381 if (fcport->login_retry == 0 &&
5382 status != QLA_SUCCESS)
5383 qla2x00_clear_loop_id(fcport);
5387 if (test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags))
5392 set_bit(RELOGIN_NEEDED, &vha->dpc_flags);
5394 ql_dbg(ql_dbg_disc, vha, 0x400e,
5398 /* Schedule work on any of the dpc-workqueues */
5400 qla83xx_schedule_work(scsi_qla_host_t *base_vha, int work_code)
5402 struct qla_hw_data *ha = base_vha->hw;
5404 switch (work_code) {
5405 case MBA_IDC_AEN: /* 0x8200 */
5407 queue_work(ha->dpc_lp_wq, &ha->idc_aen);
5410 case QLA83XX_NIC_CORE_RESET: /* 0x1 */
5411 if (!ha->flags.nic_core_reset_hdlr_active) {
5413 queue_work(ha->dpc_hp_wq, &ha->nic_core_reset);
5415 ql_dbg(ql_dbg_p3p, base_vha, 0xb05e,
5416 "NIC Core reset is already active. Skip "
5417 "scheduling it again.\n");
5419 case QLA83XX_IDC_STATE_HANDLER: /* 0x2 */
5421 queue_work(ha->dpc_hp_wq, &ha->idc_state_handler);
5423 case QLA83XX_NIC_CORE_UNRECOVERABLE: /* 0x3 */
5425 queue_work(ha->dpc_hp_wq, &ha->nic_core_unrecoverable);
5428 ql_log(ql_log_warn, base_vha, 0xb05f,
5429 "Unknown work-code=0x%x.\n", work_code);
5435 /* Work: Perform NIC Core Unrecoverable state handling */
5437 qla83xx_nic_core_unrecoverable_work(struct work_struct *work)
5439 struct qla_hw_data *ha =
5440 container_of(work, struct qla_hw_data, nic_core_unrecoverable);
5441 scsi_qla_host_t *base_vha = pci_get_drvdata(ha->pdev);
5442 uint32_t dev_state = 0;
5444 qla83xx_idc_lock(base_vha, 0);
5445 qla83xx_rd_reg(base_vha, QLA83XX_IDC_DEV_STATE, &dev_state);
5446 qla83xx_reset_ownership(base_vha);
5447 if (ha->flags.nic_core_reset_owner) {
5448 ha->flags.nic_core_reset_owner = 0;
5449 qla83xx_wr_reg(base_vha, QLA83XX_IDC_DEV_STATE,
5450 QLA8XXX_DEV_FAILED);
5451 ql_log(ql_log_info, base_vha, 0xb060, "HW State: FAILED.\n");
5452 qla83xx_schedule_work(base_vha, QLA83XX_IDC_STATE_HANDLER);
5454 qla83xx_idc_unlock(base_vha, 0);
5457 /* Work: Execute IDC state handler */
5459 qla83xx_idc_state_handler_work(struct work_struct *work)
5461 struct qla_hw_data *ha =
5462 container_of(work, struct qla_hw_data, idc_state_handler);
5463 scsi_qla_host_t *base_vha = pci_get_drvdata(ha->pdev);
5464 uint32_t dev_state = 0;
5466 qla83xx_idc_lock(base_vha, 0);
5467 qla83xx_rd_reg(base_vha, QLA83XX_IDC_DEV_STATE, &dev_state);
5468 if (dev_state == QLA8XXX_DEV_FAILED ||
5469 dev_state == QLA8XXX_DEV_NEED_QUIESCENT)
5470 qla83xx_idc_state_handler(base_vha);
5471 qla83xx_idc_unlock(base_vha, 0);
5475 qla83xx_check_nic_core_fw_alive(scsi_qla_host_t *base_vha)
5477 int rval = QLA_SUCCESS;
5478 unsigned long heart_beat_wait = jiffies + (1 * HZ);
5479 uint32_t heart_beat_counter1, heart_beat_counter2;
5482 if (time_after(jiffies, heart_beat_wait)) {
5483 ql_dbg(ql_dbg_p3p, base_vha, 0xb07c,
5484 "Nic Core f/w is not alive.\n");
5485 rval = QLA_FUNCTION_FAILED;
5489 qla83xx_idc_lock(base_vha, 0);
5490 qla83xx_rd_reg(base_vha, QLA83XX_FW_HEARTBEAT,
5491 &heart_beat_counter1);
5492 qla83xx_idc_unlock(base_vha, 0);
5494 qla83xx_idc_lock(base_vha, 0);
5495 qla83xx_rd_reg(base_vha, QLA83XX_FW_HEARTBEAT,
5496 &heart_beat_counter2);
5497 qla83xx_idc_unlock(base_vha, 0);
5498 } while (heart_beat_counter1 == heart_beat_counter2);
5503 /* Work: Perform NIC Core Reset handling */
5505 qla83xx_nic_core_reset_work(struct work_struct *work)
5507 struct qla_hw_data *ha =
5508 container_of(work, struct qla_hw_data, nic_core_reset);
5509 scsi_qla_host_t *base_vha = pci_get_drvdata(ha->pdev);
5510 uint32_t dev_state = 0;
5512 if (IS_QLA2031(ha)) {
5513 if (qla2xxx_mctp_dump(base_vha) != QLA_SUCCESS)
5514 ql_log(ql_log_warn, base_vha, 0xb081,
5515 "Failed to dump mctp\n");
5519 if (!ha->flags.nic_core_reset_hdlr_active) {
5520 if (qla83xx_check_nic_core_fw_alive(base_vha) == QLA_SUCCESS) {
5521 qla83xx_idc_lock(base_vha, 0);
5522 qla83xx_rd_reg(base_vha, QLA83XX_IDC_DEV_STATE,
5524 qla83xx_idc_unlock(base_vha, 0);
5525 if (dev_state != QLA8XXX_DEV_NEED_RESET) {
5526 ql_dbg(ql_dbg_p3p, base_vha, 0xb07a,
5527 "Nic Core f/w is alive.\n");
5532 ha->flags.nic_core_reset_hdlr_active = 1;
5533 if (qla83xx_nic_core_reset(base_vha)) {
5534 /* NIC Core reset failed. */
5535 ql_dbg(ql_dbg_p3p, base_vha, 0xb061,
5536 "NIC Core reset failed.\n");
5538 ha->flags.nic_core_reset_hdlr_active = 0;
5542 /* Work: Handle 8200 IDC aens */
5544 qla83xx_service_idc_aen(struct work_struct *work)
5546 struct qla_hw_data *ha =
5547 container_of(work, struct qla_hw_data, idc_aen);
5548 scsi_qla_host_t *base_vha = pci_get_drvdata(ha->pdev);
5549 uint32_t dev_state, idc_control;
5551 qla83xx_idc_lock(base_vha, 0);
5552 qla83xx_rd_reg(base_vha, QLA83XX_IDC_DEV_STATE, &dev_state);
5553 qla83xx_rd_reg(base_vha, QLA83XX_IDC_CONTROL, &idc_control);
5554 qla83xx_idc_unlock(base_vha, 0);
5555 if (dev_state == QLA8XXX_DEV_NEED_RESET) {
5556 if (idc_control & QLA83XX_IDC_GRACEFUL_RESET) {
5557 ql_dbg(ql_dbg_p3p, base_vha, 0xb062,
5558 "Application requested NIC Core Reset.\n");
5559 qla83xx_schedule_work(base_vha, QLA83XX_NIC_CORE_RESET);
5560 } else if (qla83xx_check_nic_core_fw_alive(base_vha) ==
5562 ql_dbg(ql_dbg_p3p, base_vha, 0xb07b,
5563 "Other protocol driver requested NIC Core Reset.\n");
5564 qla83xx_schedule_work(base_vha, QLA83XX_NIC_CORE_RESET);
5566 } else if (dev_state == QLA8XXX_DEV_FAILED ||
5567 dev_state == QLA8XXX_DEV_NEED_QUIESCENT) {
5568 qla83xx_schedule_work(base_vha, QLA83XX_IDC_STATE_HANDLER);
5573 qla83xx_wait_logic(void)
5578 if (!in_interrupt()) {
5580 * Wait about 200ms before retrying again.
5581 * This controls the number of retries for single
5587 for (i = 0; i < 20; i++)
5588 cpu_relax(); /* This a nop instr on i386 */
5593 qla83xx_force_lock_recovery(scsi_qla_host_t *base_vha)
5597 uint32_t idc_lck_rcvry_stage_mask = 0x3;
5598 uint32_t idc_lck_rcvry_owner_mask = 0x3c;
5599 struct qla_hw_data *ha = base_vha->hw;
5601 ql_dbg(ql_dbg_p3p, base_vha, 0xb086,
5602 "Trying force recovery of the IDC lock.\n");
5604 rval = qla83xx_rd_reg(base_vha, QLA83XX_IDC_LOCK_RECOVERY, &data);
5608 if ((data & idc_lck_rcvry_stage_mask) > 0) {
5611 data = (IDC_LOCK_RECOVERY_STAGE1) | (ha->portnum << 2);
5612 rval = qla83xx_wr_reg(base_vha, QLA83XX_IDC_LOCK_RECOVERY,
5619 rval = qla83xx_rd_reg(base_vha, QLA83XX_IDC_LOCK_RECOVERY,
5624 if (((data & idc_lck_rcvry_owner_mask) >> 2) == ha->portnum) {
5625 data &= (IDC_LOCK_RECOVERY_STAGE2 |
5626 ~(idc_lck_rcvry_stage_mask));
5627 rval = qla83xx_wr_reg(base_vha,
5628 QLA83XX_IDC_LOCK_RECOVERY, data);
5632 /* Forcefully perform IDC UnLock */
5633 rval = qla83xx_rd_reg(base_vha, QLA83XX_DRIVER_UNLOCK,
5637 /* Clear lock-id by setting 0xff */
5638 rval = qla83xx_wr_reg(base_vha, QLA83XX_DRIVER_LOCKID,
5642 /* Clear lock-recovery by setting 0x0 */
5643 rval = qla83xx_wr_reg(base_vha,
5644 QLA83XX_IDC_LOCK_RECOVERY, 0x0);
5655 qla83xx_idc_lock_recovery(scsi_qla_host_t *base_vha)
5657 int rval = QLA_SUCCESS;
5658 uint32_t o_drv_lockid, n_drv_lockid;
5659 unsigned long lock_recovery_timeout;
5661 lock_recovery_timeout = jiffies + QLA83XX_MAX_LOCK_RECOVERY_WAIT;
5663 rval = qla83xx_rd_reg(base_vha, QLA83XX_DRIVER_LOCKID, &o_drv_lockid);
5667 /* MAX wait time before forcing IDC Lock recovery = 2 secs */
5668 if (time_after_eq(jiffies, lock_recovery_timeout)) {
5669 if (qla83xx_force_lock_recovery(base_vha) == QLA_SUCCESS)
5672 return QLA_FUNCTION_FAILED;
5675 rval = qla83xx_rd_reg(base_vha, QLA83XX_DRIVER_LOCKID, &n_drv_lockid);
5679 if (o_drv_lockid == n_drv_lockid) {
5680 qla83xx_wait_logic();
5690 qla83xx_idc_lock(scsi_qla_host_t *base_vha, uint16_t requester_id)
5693 uint32_t lock_owner;
5694 struct qla_hw_data *ha = base_vha->hw;
5696 /* IDC-lock implementation using driver-lock/lock-id remote registers */
5698 if (qla83xx_rd_reg(base_vha, QLA83XX_DRIVER_LOCK, &data)
5701 /* Setting lock-id to our function-number */
5702 qla83xx_wr_reg(base_vha, QLA83XX_DRIVER_LOCKID,
5705 qla83xx_rd_reg(base_vha, QLA83XX_DRIVER_LOCKID,
5707 ql_dbg(ql_dbg_p3p, base_vha, 0xb063,
5708 "Failed to acquire IDC lock, acquired by %d, "
5709 "retrying...\n", lock_owner);
5711 /* Retry/Perform IDC-Lock recovery */
5712 if (qla83xx_idc_lock_recovery(base_vha)
5714 qla83xx_wait_logic();
5717 ql_log(ql_log_warn, base_vha, 0xb075,
5718 "IDC Lock recovery FAILED.\n");
5727 qla83xx_idc_unlock(scsi_qla_host_t *base_vha, uint16_t requester_id)
5730 uint16_t options = (requester_id << 15) | BIT_7;
5734 struct qla_hw_data *ha = base_vha->hw;
5736 /* IDC-unlock implementation using driver-unlock/lock-id
5741 if (qla83xx_rd_reg(base_vha, QLA83XX_DRIVER_LOCKID, &data)
5743 if (data == ha->portnum) {
5744 qla83xx_rd_reg(base_vha, QLA83XX_DRIVER_UNLOCK, &data);
5745 /* Clearing lock-id by setting 0xff */
5746 qla83xx_wr_reg(base_vha, QLA83XX_DRIVER_LOCKID, 0xff);
5747 } else if (retry < 10) {
5748 /* SV: XXX: IDC unlock retrying needed here? */
5750 /* Retry for IDC-unlock */
5751 qla83xx_wait_logic();
5753 ql_dbg(ql_dbg_p3p, base_vha, 0xb064,
5754 "Failed to release IDC lock, retrying=%d\n", retry);
5757 } else if (retry < 10) {
5758 /* Retry for IDC-unlock */
5759 qla83xx_wait_logic();
5761 ql_dbg(ql_dbg_p3p, base_vha, 0xb065,
5762 "Failed to read drv-lockid, retrying=%d\n", retry);
5769 /* XXX: IDC-unlock implementation using access-control mbx */
5772 if (qla83xx_access_control(base_vha, options, 0, 0, NULL)) {
5774 /* Retry for IDC-unlock */
5775 qla83xx_wait_logic();
5777 ql_dbg(ql_dbg_p3p, base_vha, 0xb066,
5778 "Failed to release IDC lock, retrying=%d\n", retry);
5788 __qla83xx_set_drv_presence(scsi_qla_host_t *vha)
5790 int rval = QLA_SUCCESS;
5791 struct qla_hw_data *ha = vha->hw;
5792 uint32_t drv_presence;
5794 rval = qla83xx_rd_reg(vha, QLA83XX_IDC_DRV_PRESENCE, &drv_presence);
5795 if (rval == QLA_SUCCESS) {
5796 drv_presence |= (1 << ha->portnum);
5797 rval = qla83xx_wr_reg(vha, QLA83XX_IDC_DRV_PRESENCE,
5805 qla83xx_set_drv_presence(scsi_qla_host_t *vha)
5807 int rval = QLA_SUCCESS;
5809 qla83xx_idc_lock(vha, 0);
5810 rval = __qla83xx_set_drv_presence(vha);
5811 qla83xx_idc_unlock(vha, 0);
5817 __qla83xx_clear_drv_presence(scsi_qla_host_t *vha)
5819 int rval = QLA_SUCCESS;
5820 struct qla_hw_data *ha = vha->hw;
5821 uint32_t drv_presence;
5823 rval = qla83xx_rd_reg(vha, QLA83XX_IDC_DRV_PRESENCE, &drv_presence);
5824 if (rval == QLA_SUCCESS) {
5825 drv_presence &= ~(1 << ha->portnum);
5826 rval = qla83xx_wr_reg(vha, QLA83XX_IDC_DRV_PRESENCE,
5834 qla83xx_clear_drv_presence(scsi_qla_host_t *vha)
5836 int rval = QLA_SUCCESS;
5838 qla83xx_idc_lock(vha, 0);
5839 rval = __qla83xx_clear_drv_presence(vha);
5840 qla83xx_idc_unlock(vha, 0);
5846 qla83xx_need_reset_handler(scsi_qla_host_t *vha)
5848 struct qla_hw_data *ha = vha->hw;
5849 uint32_t drv_ack, drv_presence;
5850 unsigned long ack_timeout;
5852 /* Wait for IDC ACK from all functions (DRV-ACK == DRV-PRESENCE) */
5853 ack_timeout = jiffies + (ha->fcoe_reset_timeout * HZ);
5855 qla83xx_rd_reg(vha, QLA83XX_IDC_DRIVER_ACK, &drv_ack);
5856 qla83xx_rd_reg(vha, QLA83XX_IDC_DRV_PRESENCE, &drv_presence);
5857 if ((drv_ack & drv_presence) == drv_presence)
5860 if (time_after_eq(jiffies, ack_timeout)) {
5861 ql_log(ql_log_warn, vha, 0xb067,
5862 "RESET ACK TIMEOUT! drv_presence=0x%x "
5863 "drv_ack=0x%x\n", drv_presence, drv_ack);
5865 * The function(s) which did not ack in time are forced
5866 * to withdraw any further participation in the IDC
5869 if (drv_ack != drv_presence)
5870 qla83xx_wr_reg(vha, QLA83XX_IDC_DRV_PRESENCE,
5875 qla83xx_idc_unlock(vha, 0);
5877 qla83xx_idc_lock(vha, 0);
5880 qla83xx_wr_reg(vha, QLA83XX_IDC_DEV_STATE, QLA8XXX_DEV_COLD);
5881 ql_log(ql_log_info, vha, 0xb068, "HW State: COLD/RE-INIT.\n");
5885 qla83xx_device_bootstrap(scsi_qla_host_t *vha)
5887 int rval = QLA_SUCCESS;
5888 uint32_t idc_control;
5890 qla83xx_wr_reg(vha, QLA83XX_IDC_DEV_STATE, QLA8XXX_DEV_INITIALIZING);
5891 ql_log(ql_log_info, vha, 0xb069, "HW State: INITIALIZING.\n");
5893 /* Clearing IDC-Control Graceful-Reset Bit before resetting f/w */
5894 __qla83xx_get_idc_control(vha, &idc_control);
5895 idc_control &= ~QLA83XX_IDC_GRACEFUL_RESET;
5896 __qla83xx_set_idc_control(vha, 0);
5898 qla83xx_idc_unlock(vha, 0);
5899 rval = qla83xx_restart_nic_firmware(vha);
5900 qla83xx_idc_lock(vha, 0);
5902 if (rval != QLA_SUCCESS) {
5903 ql_log(ql_log_fatal, vha, 0xb06a,
5904 "Failed to restart NIC f/w.\n");
5905 qla83xx_wr_reg(vha, QLA83XX_IDC_DEV_STATE, QLA8XXX_DEV_FAILED);
5906 ql_log(ql_log_info, vha, 0xb06b, "HW State: FAILED.\n");
5908 ql_dbg(ql_dbg_p3p, vha, 0xb06c,
5909 "Success in restarting nic f/w.\n");
5910 qla83xx_wr_reg(vha, QLA83XX_IDC_DEV_STATE, QLA8XXX_DEV_READY);
5911 ql_log(ql_log_info, vha, 0xb06d, "HW State: READY.\n");
5917 /* Assumes idc_lock always held on entry */
5919 qla83xx_idc_state_handler(scsi_qla_host_t *base_vha)
5921 struct qla_hw_data *ha = base_vha->hw;
5922 int rval = QLA_SUCCESS;
5923 unsigned long dev_init_timeout;
5926 /* Wait for MAX-INIT-TIMEOUT for the device to go ready */
5927 dev_init_timeout = jiffies + (ha->fcoe_dev_init_timeout * HZ);
5931 if (time_after_eq(jiffies, dev_init_timeout)) {
5932 ql_log(ql_log_warn, base_vha, 0xb06e,
5933 "Initialization TIMEOUT!\n");
5934 /* Init timeout. Disable further NIC Core
5937 qla83xx_wr_reg(base_vha, QLA83XX_IDC_DEV_STATE,
5938 QLA8XXX_DEV_FAILED);
5939 ql_log(ql_log_info, base_vha, 0xb06f,
5940 "HW State: FAILED.\n");
5943 qla83xx_rd_reg(base_vha, QLA83XX_IDC_DEV_STATE, &dev_state);
5944 switch (dev_state) {
5945 case QLA8XXX_DEV_READY:
5946 if (ha->flags.nic_core_reset_owner)
5947 qla83xx_idc_audit(base_vha,
5948 IDC_AUDIT_COMPLETION);
5949 ha->flags.nic_core_reset_owner = 0;
5950 ql_dbg(ql_dbg_p3p, base_vha, 0xb070,
5951 "Reset_owner reset by 0x%x.\n",
5954 case QLA8XXX_DEV_COLD:
5955 if (ha->flags.nic_core_reset_owner)
5956 rval = qla83xx_device_bootstrap(base_vha);
5958 /* Wait for AEN to change device-state */
5959 qla83xx_idc_unlock(base_vha, 0);
5961 qla83xx_idc_lock(base_vha, 0);
5964 case QLA8XXX_DEV_INITIALIZING:
5965 /* Wait for AEN to change device-state */
5966 qla83xx_idc_unlock(base_vha, 0);
5968 qla83xx_idc_lock(base_vha, 0);
5970 case QLA8XXX_DEV_NEED_RESET:
5971 if (!ql2xdontresethba && ha->flags.nic_core_reset_owner)
5972 qla83xx_need_reset_handler(base_vha);
5974 /* Wait for AEN to change device-state */
5975 qla83xx_idc_unlock(base_vha, 0);
5977 qla83xx_idc_lock(base_vha, 0);
5979 /* reset timeout value after need reset handler */
5980 dev_init_timeout = jiffies +
5981 (ha->fcoe_dev_init_timeout * HZ);
5983 case QLA8XXX_DEV_NEED_QUIESCENT:
5984 /* XXX: DEBUG for now */
5985 qla83xx_idc_unlock(base_vha, 0);
5987 qla83xx_idc_lock(base_vha, 0);
5989 case QLA8XXX_DEV_QUIESCENT:
5990 /* XXX: DEBUG for now */
5991 if (ha->flags.quiesce_owner)
5994 qla83xx_idc_unlock(base_vha, 0);
5996 qla83xx_idc_lock(base_vha, 0);
5997 dev_init_timeout = jiffies +
5998 (ha->fcoe_dev_init_timeout * HZ);
6000 case QLA8XXX_DEV_FAILED:
6001 if (ha->flags.nic_core_reset_owner)
6002 qla83xx_idc_audit(base_vha,
6003 IDC_AUDIT_COMPLETION);
6004 ha->flags.nic_core_reset_owner = 0;
6005 __qla83xx_clear_drv_presence(base_vha);
6006 qla83xx_idc_unlock(base_vha, 0);
6007 qla8xxx_dev_failed_handler(base_vha);
6008 rval = QLA_FUNCTION_FAILED;
6009 qla83xx_idc_lock(base_vha, 0);
6011 case QLA8XXX_BAD_VALUE:
6012 qla83xx_idc_unlock(base_vha, 0);
6014 qla83xx_idc_lock(base_vha, 0);
6017 ql_log(ql_log_warn, base_vha, 0xb071,
6018 "Unknown Device State: %x.\n", dev_state);
6019 qla83xx_idc_unlock(base_vha, 0);
6020 qla8xxx_dev_failed_handler(base_vha);
6021 rval = QLA_FUNCTION_FAILED;
6022 qla83xx_idc_lock(base_vha, 0);
6032 qla2x00_disable_board_on_pci_error(struct work_struct *work)
6034 struct qla_hw_data *ha = container_of(work, struct qla_hw_data,
6036 struct pci_dev *pdev = ha->pdev;
6037 scsi_qla_host_t *base_vha = pci_get_drvdata(ha->pdev);
6039 ql_log(ql_log_warn, base_vha, 0x015b,
6040 "Disabling adapter.\n");
6042 if (!atomic_read(&pdev->enable_cnt)) {
6043 ql_log(ql_log_info, base_vha, 0xfffc,
6044 "PCI device disabled, no action req for PCI error=%lx\n",
6045 base_vha->pci_flags);
6050 * if UNLOADING flag is already set, then continue unload,
6051 * where it was set first.
6053 if (test_and_set_bit(UNLOADING, &base_vha->dpc_flags))
6056 qla2x00_wait_for_sess_deletion(base_vha);
6058 qla2x00_delete_all_vps(ha, base_vha);
6060 qla2x00_abort_all_cmds(base_vha, DID_NO_CONNECT << 16);
6062 qla2x00_dfs_remove(base_vha);
6064 qla84xx_put_chip(base_vha);
6066 if (base_vha->timer_active)
6067 qla2x00_stop_timer(base_vha);
6069 base_vha->flags.online = 0;
6071 qla2x00_destroy_deferred_work(ha);
6074 * Do not try to stop beacon blink as it will issue a mailbox
6077 qla2x00_free_sysfs_attr(base_vha, false);
6079 fc_remove_host(base_vha->host);
6081 scsi_remove_host(base_vha->host);
6083 base_vha->flags.init_done = 0;
6084 qla25xx_delete_queues(base_vha);
6085 qla2x00_free_fcports(base_vha);
6086 qla2x00_free_irqs(base_vha);
6087 qla2x00_mem_free(ha);
6088 qla82xx_md_free(base_vha);
6089 qla2x00_free_queues(ha);
6091 qla2x00_unmap_iobases(ha);
6093 pci_release_selected_regions(ha->pdev, ha->bars);
6094 pci_disable_pcie_error_reporting(pdev);
6095 pci_disable_device(pdev);
6098 * Let qla2x00_remove_one cleanup qla_hw_data on device removal.
6102 /**************************************************************************
6104 * This kernel thread is a task that is schedule by the interrupt handler
6105 * to perform the background processing for interrupts.
6108 * This task always run in the context of a kernel thread. It
6109 * is kick-off by the driver's detect code and starts up
6110 * up one per adapter. It immediately goes to sleep and waits for
6111 * some fibre event. When either the interrupt handler or
6112 * the timer routine detects a event it will one of the task
6113 * bits then wake us up.
6114 **************************************************************************/
6116 qla2x00_do_dpc(void *data)
6118 scsi_qla_host_t *base_vha;
6119 struct qla_hw_data *ha;
6121 struct qla_qpair *qpair;
6123 ha = (struct qla_hw_data *)data;
6124 base_vha = pci_get_drvdata(ha->pdev);
6126 set_user_nice(current, MIN_NICE);
6128 set_current_state(TASK_INTERRUPTIBLE);
6129 while (!kthread_should_stop()) {
6130 ql_dbg(ql_dbg_dpc, base_vha, 0x4000,
6131 "DPC handler sleeping.\n");
6135 if (!base_vha->flags.init_done || ha->flags.mbox_busy)
6138 if (ha->flags.eeh_busy) {
6139 ql_dbg(ql_dbg_dpc, base_vha, 0x4003,
6140 "eeh_busy=%d.\n", ha->flags.eeh_busy);
6146 ql_dbg(ql_dbg_dpc + ql_dbg_verbose, base_vha, 0x4001,
6147 "DPC handler waking up, dpc_flags=0x%lx.\n",
6148 base_vha->dpc_flags);
6150 if (test_bit(UNLOADING, &base_vha->dpc_flags))
6153 if (IS_P3P_TYPE(ha)) {
6154 if (IS_QLA8044(ha)) {
6155 if (test_and_clear_bit(ISP_UNRECOVERABLE,
6156 &base_vha->dpc_flags)) {
6157 qla8044_idc_lock(ha);
6158 qla8044_wr_direct(base_vha,
6159 QLA8044_CRB_DEV_STATE_INDEX,
6160 QLA8XXX_DEV_FAILED);
6161 qla8044_idc_unlock(ha);
6162 ql_log(ql_log_info, base_vha, 0x4004,
6163 "HW State: FAILED.\n");
6164 qla8044_device_state_handler(base_vha);
6169 if (test_and_clear_bit(ISP_UNRECOVERABLE,
6170 &base_vha->dpc_flags)) {
6171 qla82xx_idc_lock(ha);
6172 qla82xx_wr_32(ha, QLA82XX_CRB_DEV_STATE,
6173 QLA8XXX_DEV_FAILED);
6174 qla82xx_idc_unlock(ha);
6175 ql_log(ql_log_info, base_vha, 0x0151,
6176 "HW State: FAILED.\n");
6177 qla82xx_device_state_handler(base_vha);
6182 if (test_and_clear_bit(FCOE_CTX_RESET_NEEDED,
6183 &base_vha->dpc_flags)) {
6185 ql_dbg(ql_dbg_dpc, base_vha, 0x4005,
6186 "FCoE context reset scheduled.\n");
6187 if (!(test_and_set_bit(ABORT_ISP_ACTIVE,
6188 &base_vha->dpc_flags))) {
6189 if (qla82xx_fcoe_ctx_reset(base_vha)) {
6190 /* FCoE-ctx reset failed.
6191 * Escalate to chip-reset
6193 set_bit(ISP_ABORT_NEEDED,
6194 &base_vha->dpc_flags);
6196 clear_bit(ABORT_ISP_ACTIVE,
6197 &base_vha->dpc_flags);
6200 ql_dbg(ql_dbg_dpc, base_vha, 0x4006,
6201 "FCoE context reset end.\n");
6203 } else if (IS_QLAFX00(ha)) {
6204 if (test_and_clear_bit(ISP_UNRECOVERABLE,
6205 &base_vha->dpc_flags)) {
6206 ql_dbg(ql_dbg_dpc, base_vha, 0x4020,
6207 "Firmware Reset Recovery\n");
6208 if (qlafx00_reset_initialize(base_vha)) {
6209 /* Failed. Abort isp later. */
6210 if (!test_bit(UNLOADING,
6211 &base_vha->dpc_flags)) {
6212 set_bit(ISP_UNRECOVERABLE,
6213 &base_vha->dpc_flags);
6214 ql_dbg(ql_dbg_dpc, base_vha,
6216 "Reset Recovery Failed\n");
6221 if (test_and_clear_bit(FX00_TARGET_SCAN,
6222 &base_vha->dpc_flags)) {
6223 ql_dbg(ql_dbg_dpc, base_vha, 0x4022,
6224 "ISPFx00 Target Scan scheduled\n");
6225 if (qlafx00_rescan_isp(base_vha)) {
6226 if (!test_bit(UNLOADING,
6227 &base_vha->dpc_flags))
6228 set_bit(ISP_UNRECOVERABLE,
6229 &base_vha->dpc_flags);
6230 ql_dbg(ql_dbg_dpc, base_vha, 0x401e,
6231 "ISPFx00 Target Scan Failed\n");
6233 ql_dbg(ql_dbg_dpc, base_vha, 0x401f,
6234 "ISPFx00 Target Scan End\n");
6236 if (test_and_clear_bit(FX00_HOST_INFO_RESEND,
6237 &base_vha->dpc_flags)) {
6238 ql_dbg(ql_dbg_dpc, base_vha, 0x4023,
6239 "ISPFx00 Host Info resend scheduled\n");
6240 qlafx00_fx_disc(base_vha,
6241 &base_vha->hw->mr.fcport,
6242 FXDISC_REG_HOST_INFO);
6246 if (test_and_clear_bit(DETECT_SFP_CHANGE,
6247 &base_vha->dpc_flags) &&
6248 !test_bit(ISP_ABORT_NEEDED, &base_vha->dpc_flags)) {
6249 qla24xx_detect_sfp(base_vha);
6251 if (ha->flags.detected_lr_sfp !=
6252 ha->flags.using_lr_setting)
6253 set_bit(ISP_ABORT_NEEDED, &base_vha->dpc_flags);
6256 if (test_and_clear_bit
6257 (ISP_ABORT_NEEDED, &base_vha->dpc_flags) &&
6258 !test_bit(UNLOADING, &base_vha->dpc_flags)) {
6259 bool do_reset = true;
6261 switch (base_vha->qlini_mode) {
6262 case QLA2XXX_INI_MODE_ENABLED:
6264 case QLA2XXX_INI_MODE_DISABLED:
6265 if (!qla_tgt_mode_enabled(base_vha) &&
6266 !ha->flags.fw_started)
6269 case QLA2XXX_INI_MODE_DUAL:
6270 if (!qla_dual_mode_enabled(base_vha) &&
6271 !ha->flags.fw_started)
6278 if (do_reset && !(test_and_set_bit(ABORT_ISP_ACTIVE,
6279 &base_vha->dpc_flags))) {
6280 base_vha->flags.online = 1;
6281 ql_dbg(ql_dbg_dpc, base_vha, 0x4007,
6282 "ISP abort scheduled.\n");
6283 if (ha->isp_ops->abort_isp(base_vha)) {
6284 /* failed. retry later */
6285 set_bit(ISP_ABORT_NEEDED,
6286 &base_vha->dpc_flags);
6288 clear_bit(ABORT_ISP_ACTIVE,
6289 &base_vha->dpc_flags);
6290 ql_dbg(ql_dbg_dpc, base_vha, 0x4008,
6291 "ISP abort end.\n");
6295 if (test_and_clear_bit(FCPORT_UPDATE_NEEDED,
6296 &base_vha->dpc_flags)) {
6297 qla2x00_update_fcports(base_vha);
6301 goto loop_resync_check;
6303 if (test_bit(ISP_QUIESCE_NEEDED, &base_vha->dpc_flags)) {
6304 ql_dbg(ql_dbg_dpc, base_vha, 0x4009,
6305 "Quiescence mode scheduled.\n");
6306 if (IS_P3P_TYPE(ha)) {
6308 qla82xx_device_state_handler(base_vha);
6310 qla8044_device_state_handler(base_vha);
6311 clear_bit(ISP_QUIESCE_NEEDED,
6312 &base_vha->dpc_flags);
6313 if (!ha->flags.quiesce_owner) {
6314 qla2x00_perform_loop_resync(base_vha);
6315 if (IS_QLA82XX(ha)) {
6316 qla82xx_idc_lock(ha);
6317 qla82xx_clear_qsnt_ready(
6319 qla82xx_idc_unlock(ha);
6320 } else if (IS_QLA8044(ha)) {
6321 qla8044_idc_lock(ha);
6322 qla8044_clear_qsnt_ready(
6324 qla8044_idc_unlock(ha);
6328 clear_bit(ISP_QUIESCE_NEEDED,
6329 &base_vha->dpc_flags);
6330 qla2x00_quiesce_io(base_vha);
6332 ql_dbg(ql_dbg_dpc, base_vha, 0x400a,
6333 "Quiescence mode end.\n");
6336 if (test_and_clear_bit(RESET_MARKER_NEEDED,
6337 &base_vha->dpc_flags) &&
6338 (!(test_and_set_bit(RESET_ACTIVE, &base_vha->dpc_flags)))) {
6340 ql_dbg(ql_dbg_dpc, base_vha, 0x400b,
6341 "Reset marker scheduled.\n");
6342 qla2x00_rst_aen(base_vha);
6343 clear_bit(RESET_ACTIVE, &base_vha->dpc_flags);
6344 ql_dbg(ql_dbg_dpc, base_vha, 0x400c,
6345 "Reset marker end.\n");
6348 /* Retry each device up to login retry count */
6349 if (test_bit(RELOGIN_NEEDED, &base_vha->dpc_flags) &&
6350 !test_bit(LOOP_RESYNC_NEEDED, &base_vha->dpc_flags) &&
6351 atomic_read(&base_vha->loop_state) != LOOP_DOWN) {
6353 if (!base_vha->relogin_jif ||
6354 time_after_eq(jiffies, base_vha->relogin_jif)) {
6355 base_vha->relogin_jif = jiffies + HZ;
6356 clear_bit(RELOGIN_NEEDED, &base_vha->dpc_flags);
6358 ql_dbg(ql_dbg_disc, base_vha, 0x400d,
6359 "Relogin scheduled.\n");
6360 qla24xx_post_relogin_work(base_vha);
6364 if (test_and_clear_bit(LOOP_RESYNC_NEEDED,
6365 &base_vha->dpc_flags)) {
6367 ql_dbg(ql_dbg_dpc, base_vha, 0x400f,
6368 "Loop resync scheduled.\n");
6370 if (!(test_and_set_bit(LOOP_RESYNC_ACTIVE,
6371 &base_vha->dpc_flags))) {
6373 qla2x00_loop_resync(base_vha);
6375 clear_bit(LOOP_RESYNC_ACTIVE,
6376 &base_vha->dpc_flags);
6379 ql_dbg(ql_dbg_dpc, base_vha, 0x4010,
6380 "Loop resync end.\n");
6386 if (test_bit(NPIV_CONFIG_NEEDED, &base_vha->dpc_flags) &&
6387 atomic_read(&base_vha->loop_state) == LOOP_READY) {
6388 clear_bit(NPIV_CONFIG_NEEDED, &base_vha->dpc_flags);
6389 qla2xxx_flash_npiv_conf(base_vha);
6393 if (!ha->interrupts_on)
6394 ha->isp_ops->enable_intrs(ha);
6396 if (test_and_clear_bit(BEACON_BLINK_NEEDED,
6397 &base_vha->dpc_flags)) {
6398 if (ha->beacon_blink_led == 1)
6399 ha->isp_ops->beacon_blink(base_vha);
6402 /* qpair online check */
6403 if (test_and_clear_bit(QPAIR_ONLINE_CHECK_NEEDED,
6404 &base_vha->dpc_flags)) {
6405 if (ha->flags.eeh_busy ||
6406 ha->flags.pci_channel_io_perm_failure)
6411 mutex_lock(&ha->mq_lock);
6412 list_for_each_entry(qpair, &base_vha->qp_list,
6414 qpair->online = online;
6415 mutex_unlock(&ha->mq_lock);
6418 if (test_and_clear_bit(SET_NVME_ZIO_THRESHOLD_NEEDED,
6419 &base_vha->dpc_flags)) {
6420 ql_log(ql_log_info, base_vha, 0xffffff,
6421 "nvme: SET ZIO Activity exchange threshold to %d.\n",
6422 ha->nvme_last_rptd_aen);
6423 if (qla27xx_set_zio_threshold(base_vha,
6424 ha->nvme_last_rptd_aen)) {
6425 ql_log(ql_log_info, base_vha, 0xffffff,
6426 "nvme: Unable to SET ZIO Activity exchange threshold to %d.\n",
6427 ha->nvme_last_rptd_aen);
6431 if (test_and_clear_bit(SET_ZIO_THRESHOLD_NEEDED,
6432 &base_vha->dpc_flags)) {
6433 ql_log(ql_log_info, base_vha, 0xffffff,
6434 "SET ZIO Activity exchange threshold to %d.\n",
6435 ha->last_zio_threshold);
6436 qla27xx_set_zio_threshold(base_vha,
6437 ha->last_zio_threshold);
6440 if (!IS_QLAFX00(ha))
6441 qla2x00_do_dpc_all_vps(base_vha);
6443 if (test_and_clear_bit(N2N_LINK_RESET,
6444 &base_vha->dpc_flags)) {
6445 qla2x00_lip_reset(base_vha);
6450 set_current_state(TASK_INTERRUPTIBLE);
6451 } /* End of while(1) */
6452 __set_current_state(TASK_RUNNING);
6454 ql_dbg(ql_dbg_dpc, base_vha, 0x4011,
6455 "DPC handler exiting.\n");
6458 * Make sure that nobody tries to wake us up again.
6462 /* Cleanup any residual CTX SRBs. */
6463 qla2x00_abort_all_cmds(base_vha, DID_NO_CONNECT << 16);
6469 qla2xxx_wake_dpc(struct scsi_qla_host *vha)
6471 struct qla_hw_data *ha = vha->hw;
6472 struct task_struct *t = ha->dpc_thread;
6474 if (!test_bit(UNLOADING, &vha->dpc_flags) && t)
6480 * Processes asynchronous reset.
6483 * ha = adapter block pointer.
6486 qla2x00_rst_aen(scsi_qla_host_t *vha)
6488 if (vha->flags.online && !vha->flags.reset_active &&
6489 !atomic_read(&vha->loop_down_timer) &&
6490 !(test_bit(ABORT_ISP_ACTIVE, &vha->dpc_flags))) {
6492 clear_bit(RESET_MARKER_NEEDED, &vha->dpc_flags);
6495 * Issue marker command only when we are going to start
6498 vha->marker_needed = 1;
6499 } while (!atomic_read(&vha->loop_down_timer) &&
6500 (test_bit(RESET_MARKER_NEEDED, &vha->dpc_flags)));
6504 /**************************************************************************
6510 * Context: Interrupt
6511 ***************************************************************************/
6513 qla2x00_timer(struct timer_list *t)
6515 scsi_qla_host_t *vha = from_timer(vha, t, timer);
6516 unsigned long cpu_flags = 0;
6521 struct qla_hw_data *ha = vha->hw;
6522 struct req_que *req;
6524 if (ha->flags.eeh_busy) {
6525 ql_dbg(ql_dbg_timer, vha, 0x6000,
6526 "EEH = %d, restarting timer.\n",
6527 ha->flags.eeh_busy);
6528 qla2x00_restart_timer(vha, WATCH_INTERVAL);
6533 * Hardware read to raise pending EEH errors during mailbox waits. If
6534 * the read returns -1 then disable the board.
6536 if (!pci_channel_offline(ha->pdev)) {
6537 pci_read_config_word(ha->pdev, PCI_VENDOR_ID, &w);
6538 qla2x00_check_reg16_for_disconnect(vha, w);
6541 /* Make sure qla82xx_watchdog is run only for physical port */
6542 if (!vha->vp_idx && IS_P3P_TYPE(ha)) {
6543 if (test_bit(ISP_QUIESCE_NEEDED, &vha->dpc_flags))
6546 qla82xx_watchdog(vha);
6547 else if (IS_QLA8044(ha))
6548 qla8044_watchdog(vha);
6551 if (!vha->vp_idx && IS_QLAFX00(ha))
6552 qlafx00_timer_routine(vha);
6554 /* Loop down handler. */
6555 if (atomic_read(&vha->loop_down_timer) > 0 &&
6556 !(test_bit(ABORT_ISP_ACTIVE, &vha->dpc_flags)) &&
6557 !(test_bit(FCOE_CTX_RESET_NEEDED, &vha->dpc_flags))
6558 && vha->flags.online) {
6560 if (atomic_read(&vha->loop_down_timer) ==
6561 vha->loop_down_abort_time) {
6563 ql_log(ql_log_info, vha, 0x6008,
6564 "Loop down - aborting the queues before time expires.\n");
6566 if (!IS_QLA2100(ha) && vha->link_down_timeout)
6567 atomic_set(&vha->loop_state, LOOP_DEAD);
6570 * Schedule an ISP abort to return any FCP2-device
6573 /* NPIV - scan physical port only */
6575 spin_lock_irqsave(&ha->hardware_lock,
6577 req = ha->req_q_map[0];
6579 index < req->num_outstanding_cmds;
6583 sp = req->outstanding_cmds[index];
6586 if (sp->cmd_type != TYPE_SRB)
6588 if (sp->type != SRB_SCSI_CMD)
6591 if (!(sfcp->flags & FCF_FCP2_DEVICE))
6595 set_bit(FCOE_CTX_RESET_NEEDED,
6598 set_bit(ISP_ABORT_NEEDED,
6602 spin_unlock_irqrestore(&ha->hardware_lock,
6608 /* if the loop has been down for 4 minutes, reinit adapter */
6609 if (atomic_dec_and_test(&vha->loop_down_timer) != 0) {
6610 if (!(vha->device_flags & DFLG_NO_CABLE)) {
6611 ql_log(ql_log_warn, vha, 0x6009,
6612 "Loop down - aborting ISP.\n");
6615 set_bit(FCOE_CTX_RESET_NEEDED,
6618 set_bit(ISP_ABORT_NEEDED,
6622 ql_dbg(ql_dbg_timer, vha, 0x600a,
6623 "Loop down - seconds remaining %d.\n",
6624 atomic_read(&vha->loop_down_timer));
6626 /* Check if beacon LED needs to be blinked for physical host only */
6627 if (!vha->vp_idx && (ha->beacon_blink_led == 1)) {
6628 /* There is no beacon_blink function for ISP82xx */
6629 if (!IS_P3P_TYPE(ha)) {
6630 set_bit(BEACON_BLINK_NEEDED, &vha->dpc_flags);
6635 /* Process any deferred work. */
6636 if (!list_empty(&vha->work_list)) {
6637 unsigned long flags;
6640 spin_lock_irqsave(&vha->work_lock, flags);
6641 if (!test_and_set_bit(IOCB_WORK_ACTIVE, &vha->dpc_flags))
6643 spin_unlock_irqrestore(&vha->work_lock, flags);
6645 queue_work(vha->hw->wq, &vha->iocb_work);
6650 * see if the active AEN count has changed from what was last reported.
6653 (atomic_read(&ha->nvme_active_aen_cnt) != ha->nvme_last_rptd_aen) &&
6654 ha->zio_mode == QLA_ZIO_MODE_6 &&
6655 !ha->flags.host_shutting_down) {
6656 ql_log(ql_log_info, vha, 0x3002,
6657 "nvme: Sched: Set ZIO exchange threshold to %d.\n",
6658 ha->nvme_last_rptd_aen);
6659 ha->nvme_last_rptd_aen = atomic_read(&ha->nvme_active_aen_cnt);
6660 set_bit(SET_NVME_ZIO_THRESHOLD_NEEDED, &vha->dpc_flags);
6665 (atomic_read(&ha->zio_threshold) != ha->last_zio_threshold) &&
6666 (ha->zio_mode == QLA_ZIO_MODE_6) &&
6667 (IS_QLA83XX(ha) || IS_QLA27XX(ha) || IS_QLA28XX(ha))) {
6668 ql_log(ql_log_info, vha, 0x3002,
6669 "Sched: Set ZIO exchange threshold to %d.\n",
6670 ha->last_zio_threshold);
6671 ha->last_zio_threshold = atomic_read(&ha->zio_threshold);
6672 set_bit(SET_ZIO_THRESHOLD_NEEDED, &vha->dpc_flags);
6676 /* Schedule the DPC routine if needed */
6677 if ((test_bit(ISP_ABORT_NEEDED, &vha->dpc_flags) ||
6678 test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags) ||
6679 test_bit(FCPORT_UPDATE_NEEDED, &vha->dpc_flags) ||
6681 test_bit(RESET_MARKER_NEEDED, &vha->dpc_flags) ||
6682 test_bit(BEACON_BLINK_NEEDED, &vha->dpc_flags) ||
6683 test_bit(ISP_UNRECOVERABLE, &vha->dpc_flags) ||
6684 test_bit(FCOE_CTX_RESET_NEEDED, &vha->dpc_flags) ||
6685 test_bit(VP_DPC_NEEDED, &vha->dpc_flags) ||
6686 test_bit(RELOGIN_NEEDED, &vha->dpc_flags))) {
6687 ql_dbg(ql_dbg_timer, vha, 0x600b,
6688 "isp_abort_needed=%d loop_resync_needed=%d "
6689 "fcport_update_needed=%d start_dpc=%d "
6690 "reset_marker_needed=%d",
6691 test_bit(ISP_ABORT_NEEDED, &vha->dpc_flags),
6692 test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags),
6693 test_bit(FCPORT_UPDATE_NEEDED, &vha->dpc_flags),
6695 test_bit(RESET_MARKER_NEEDED, &vha->dpc_flags));
6696 ql_dbg(ql_dbg_timer, vha, 0x600c,
6697 "beacon_blink_needed=%d isp_unrecoverable=%d "
6698 "fcoe_ctx_reset_needed=%d vp_dpc_needed=%d "
6699 "relogin_needed=%d.\n",
6700 test_bit(BEACON_BLINK_NEEDED, &vha->dpc_flags),
6701 test_bit(ISP_UNRECOVERABLE, &vha->dpc_flags),
6702 test_bit(FCOE_CTX_RESET_NEEDED, &vha->dpc_flags),
6703 test_bit(VP_DPC_NEEDED, &vha->dpc_flags),
6704 test_bit(RELOGIN_NEEDED, &vha->dpc_flags));
6705 qla2xxx_wake_dpc(vha);
6708 qla2x00_restart_timer(vha, WATCH_INTERVAL);
6711 /* Firmware interface routines. */
6713 #define FW_ISP21XX 0
6714 #define FW_ISP22XX 1
6715 #define FW_ISP2300 2
6716 #define FW_ISP2322 3
6717 #define FW_ISP24XX 4
6718 #define FW_ISP25XX 5
6719 #define FW_ISP81XX 6
6720 #define FW_ISP82XX 7
6721 #define FW_ISP2031 8
6722 #define FW_ISP8031 9
6723 #define FW_ISP27XX 10
6724 #define FW_ISP28XX 11
6726 #define FW_FILE_ISP21XX "/*(DEBLOBBED)*/"
6727 #define FW_FILE_ISP22XX "/*(DEBLOBBED)*/"
6728 #define FW_FILE_ISP2300 "/*(DEBLOBBED)*/"
6729 #define FW_FILE_ISP2322 "/*(DEBLOBBED)*/"
6730 #define FW_FILE_ISP24XX "/*(DEBLOBBED)*/"
6731 #define FW_FILE_ISP25XX "/*(DEBLOBBED)*/"
6732 #define FW_FILE_ISP81XX "/*(DEBLOBBED)*/"
6733 #define FW_FILE_ISP82XX "/*(DEBLOBBED)*/"
6734 #define FW_FILE_ISP2031 "/*(DEBLOBBED)*/"
6735 #define FW_FILE_ISP8031 "/*(DEBLOBBED)*/"
6736 #define FW_FILE_ISP27XX "/*(DEBLOBBED)*/"
6737 #define FW_FILE_ISP28XX "/*(DEBLOBBED)*/"
6740 static DEFINE_MUTEX(qla_fw_lock);
6742 static struct fw_blob qla_fw_blobs[] = {
6743 { .name = FW_FILE_ISP21XX, .segs = { 0x1000, 0 }, },
6744 { .name = FW_FILE_ISP22XX, .segs = { 0x1000, 0 }, },
6745 { .name = FW_FILE_ISP2300, .segs = { 0x800, 0 }, },
6746 { .name = FW_FILE_ISP2322, .segs = { 0x800, 0x1c000, 0x1e000, 0 }, },
6747 { .name = FW_FILE_ISP24XX, },
6748 { .name = FW_FILE_ISP25XX, },
6749 { .name = FW_FILE_ISP81XX, },
6750 { .name = FW_FILE_ISP82XX, },
6751 { .name = FW_FILE_ISP2031, },
6752 { .name = FW_FILE_ISP8031, },
6753 { .name = FW_FILE_ISP27XX, },
6754 { .name = FW_FILE_ISP28XX, },
6759 qla2x00_request_firmware(scsi_qla_host_t *vha)
6761 struct qla_hw_data *ha = vha->hw;
6762 struct fw_blob *blob;
6764 if (IS_QLA2100(ha)) {
6765 blob = &qla_fw_blobs[FW_ISP21XX];
6766 } else if (IS_QLA2200(ha)) {
6767 blob = &qla_fw_blobs[FW_ISP22XX];
6768 } else if (IS_QLA2300(ha) || IS_QLA2312(ha) || IS_QLA6312(ha)) {
6769 blob = &qla_fw_blobs[FW_ISP2300];
6770 } else if (IS_QLA2322(ha) || IS_QLA6322(ha)) {
6771 blob = &qla_fw_blobs[FW_ISP2322];
6772 } else if (IS_QLA24XX_TYPE(ha)) {
6773 blob = &qla_fw_blobs[FW_ISP24XX];
6774 } else if (IS_QLA25XX(ha)) {
6775 blob = &qla_fw_blobs[FW_ISP25XX];
6776 } else if (IS_QLA81XX(ha)) {
6777 blob = &qla_fw_blobs[FW_ISP81XX];
6778 } else if (IS_QLA82XX(ha)) {
6779 blob = &qla_fw_blobs[FW_ISP82XX];
6780 } else if (IS_QLA2031(ha)) {
6781 blob = &qla_fw_blobs[FW_ISP2031];
6782 } else if (IS_QLA8031(ha)) {
6783 blob = &qla_fw_blobs[FW_ISP8031];
6784 } else if (IS_QLA27XX(ha)) {
6785 blob = &qla_fw_blobs[FW_ISP27XX];
6786 } else if (IS_QLA28XX(ha)) {
6787 blob = &qla_fw_blobs[FW_ISP28XX];
6795 mutex_lock(&qla_fw_lock);
6799 if (reject_firmware(&blob->fw, blob->name, &ha->pdev->dev)) {
6800 ql_log(ql_log_warn, vha, 0x0063,
6801 "Failed to load firmware image (%s).\n", blob->name);
6807 mutex_unlock(&qla_fw_lock);
6812 qla2x00_release_firmware(void)
6814 struct fw_blob *blob;
6816 mutex_lock(&qla_fw_lock);
6817 for (blob = qla_fw_blobs; blob->name; blob++)
6818 release_firmware(blob->fw);
6819 mutex_unlock(&qla_fw_lock);
6822 static void qla_pci_error_cleanup(scsi_qla_host_t *vha)
6824 struct qla_hw_data *ha = vha->hw;
6825 scsi_qla_host_t *base_vha = pci_get_drvdata(ha->pdev);
6826 struct qla_qpair *qpair = NULL;
6827 struct scsi_qla_host *vp;
6830 unsigned long flags;
6834 ha->base_qpair->chip_reset = ha->chip_reset;
6835 for (i = 0; i < ha->max_qpairs; i++) {
6836 if (ha->queue_pair_map[i])
6837 ha->queue_pair_map[i]->chip_reset =
6838 ha->base_qpair->chip_reset;
6841 /* purge MBox commands */
6842 if (atomic_read(&ha->num_pend_mbx_stage3)) {
6843 clear_bit(MBX_INTR_WAIT, &ha->mbx_cmd_flags);
6844 complete(&ha->mbx_intr_comp);
6849 while (atomic_read(&ha->num_pend_mbx_stage3) ||
6850 atomic_read(&ha->num_pend_mbx_stage2) ||
6851 atomic_read(&ha->num_pend_mbx_stage1)) {
6858 ha->flags.purge_mbox = 0;
6860 mutex_lock(&ha->mq_lock);
6861 list_for_each_entry(qpair, &base_vha->qp_list, qp_list_elem)
6863 mutex_unlock(&ha->mq_lock);
6865 qla2x00_mark_all_devices_lost(vha, 0);
6867 spin_lock_irqsave(&ha->vport_slock, flags);
6868 list_for_each_entry(vp, &ha->vp_list, list) {
6869 atomic_inc(&vp->vref_count);
6870 spin_unlock_irqrestore(&ha->vport_slock, flags);
6871 qla2x00_mark_all_devices_lost(vp, 0);
6872 spin_lock_irqsave(&ha->vport_slock, flags);
6873 atomic_dec(&vp->vref_count);
6875 spin_unlock_irqrestore(&ha->vport_slock, flags);
6877 /* Clear all async request states across all VPs. */
6878 list_for_each_entry(fcport, &vha->vp_fcports, list)
6879 fcport->flags &= ~(FCF_LOGIN_NEEDED | FCF_ASYNC_SENT);
6881 spin_lock_irqsave(&ha->vport_slock, flags);
6882 list_for_each_entry(vp, &ha->vp_list, list) {
6883 atomic_inc(&vp->vref_count);
6884 spin_unlock_irqrestore(&ha->vport_slock, flags);
6885 list_for_each_entry(fcport, &vp->vp_fcports, list)
6886 fcport->flags &= ~(FCF_LOGIN_NEEDED | FCF_ASYNC_SENT);
6887 spin_lock_irqsave(&ha->vport_slock, flags);
6888 atomic_dec(&vp->vref_count);
6890 spin_unlock_irqrestore(&ha->vport_slock, flags);
6894 static pci_ers_result_t
6895 qla2xxx_pci_error_detected(struct pci_dev *pdev, pci_channel_state_t state)
6897 scsi_qla_host_t *vha = pci_get_drvdata(pdev);
6898 struct qla_hw_data *ha = vha->hw;
6900 ql_dbg(ql_dbg_aer, vha, 0x9000,
6901 "PCI error detected, state %x.\n", state);
6903 if (!atomic_read(&pdev->enable_cnt)) {
6904 ql_log(ql_log_info, vha, 0xffff,
6905 "PCI device is disabled,state %x\n", state);
6906 return PCI_ERS_RESULT_NEED_RESET;
6910 case pci_channel_io_normal:
6911 ha->flags.eeh_busy = 0;
6912 if (ql2xmqsupport || ql2xnvmeenable) {
6913 set_bit(QPAIR_ONLINE_CHECK_NEEDED, &vha->dpc_flags);
6914 qla2xxx_wake_dpc(vha);
6916 return PCI_ERS_RESULT_CAN_RECOVER;
6917 case pci_channel_io_frozen:
6918 ha->flags.eeh_busy = 1;
6919 qla_pci_error_cleanup(vha);
6920 return PCI_ERS_RESULT_NEED_RESET;
6921 case pci_channel_io_perm_failure:
6922 ha->flags.pci_channel_io_perm_failure = 1;
6923 qla2x00_abort_all_cmds(vha, DID_NO_CONNECT << 16);
6924 if (ql2xmqsupport || ql2xnvmeenable) {
6925 set_bit(QPAIR_ONLINE_CHECK_NEEDED, &vha->dpc_flags);
6926 qla2xxx_wake_dpc(vha);
6928 return PCI_ERS_RESULT_DISCONNECT;
6930 return PCI_ERS_RESULT_NEED_RESET;
6933 static pci_ers_result_t
6934 qla2xxx_pci_mmio_enabled(struct pci_dev *pdev)
6936 int risc_paused = 0;
6938 unsigned long flags;
6939 scsi_qla_host_t *base_vha = pci_get_drvdata(pdev);
6940 struct qla_hw_data *ha = base_vha->hw;
6941 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
6942 struct device_reg_24xx __iomem *reg24 = &ha->iobase->isp24;
6945 return PCI_ERS_RESULT_RECOVERED;
6947 spin_lock_irqsave(&ha->hardware_lock, flags);
6948 if (IS_QLA2100(ha) || IS_QLA2200(ha)){
6949 stat = RD_REG_DWORD(®->hccr);
6950 if (stat & HCCR_RISC_PAUSE)
6952 } else if (IS_QLA23XX(ha)) {
6953 stat = RD_REG_DWORD(®->u.isp2300.host_status);
6954 if (stat & HSR_RISC_PAUSED)
6956 } else if (IS_FWI2_CAPABLE(ha)) {
6957 stat = RD_REG_DWORD(®24->host_status);
6958 if (stat & HSRX_RISC_PAUSED)
6961 spin_unlock_irqrestore(&ha->hardware_lock, flags);
6964 ql_log(ql_log_info, base_vha, 0x9003,
6965 "RISC paused -- mmio_enabled, Dumping firmware.\n");
6966 ha->isp_ops->fw_dump(base_vha, 0);
6968 return PCI_ERS_RESULT_NEED_RESET;
6970 return PCI_ERS_RESULT_RECOVERED;
6973 static pci_ers_result_t
6974 qla2xxx_pci_slot_reset(struct pci_dev *pdev)
6976 pci_ers_result_t ret = PCI_ERS_RESULT_DISCONNECT;
6977 scsi_qla_host_t *base_vha = pci_get_drvdata(pdev);
6978 struct qla_hw_data *ha = base_vha->hw;
6980 struct qla_qpair *qpair = NULL;
6982 ql_dbg(ql_dbg_aer, base_vha, 0x9004,
6985 /* Workaround: qla2xxx driver which access hardware earlier
6986 * needs error state to be pci_channel_io_online.
6987 * Otherwise mailbox command timesout.
6989 pdev->error_state = pci_channel_io_normal;
6991 pci_restore_state(pdev);
6993 /* pci_restore_state() clears the saved_state flag of the device
6994 * save restored state which resets saved_state flag
6996 pci_save_state(pdev);
6999 rc = pci_enable_device_mem(pdev);
7001 rc = pci_enable_device(pdev);
7004 ql_log(ql_log_warn, base_vha, 0x9005,
7005 "Can't re-enable PCI device after reset.\n");
7006 goto exit_slot_reset;
7010 if (ha->isp_ops->pci_config(base_vha))
7011 goto exit_slot_reset;
7013 mutex_lock(&ha->mq_lock);
7014 list_for_each_entry(qpair, &base_vha->qp_list, qp_list_elem)
7016 mutex_unlock(&ha->mq_lock);
7018 base_vha->flags.online = 1;
7019 set_bit(ABORT_ISP_ACTIVE, &base_vha->dpc_flags);
7020 if (ha->isp_ops->abort_isp(base_vha) == QLA_SUCCESS)
7021 ret = PCI_ERS_RESULT_RECOVERED;
7022 clear_bit(ABORT_ISP_ACTIVE, &base_vha->dpc_flags);
7026 ql_dbg(ql_dbg_aer, base_vha, 0x900e,
7027 "slot_reset return %x.\n", ret);
7033 qla2xxx_pci_resume(struct pci_dev *pdev)
7035 scsi_qla_host_t *base_vha = pci_get_drvdata(pdev);
7036 struct qla_hw_data *ha = base_vha->hw;
7039 ql_dbg(ql_dbg_aer, base_vha, 0x900f,
7042 ha->flags.eeh_busy = 0;
7044 ret = qla2x00_wait_for_hba_online(base_vha);
7045 if (ret != QLA_SUCCESS) {
7046 ql_log(ql_log_fatal, base_vha, 0x9002,
7047 "The device failed to resume I/O from slot/link_reset.\n");
7052 qla_pci_reset_prepare(struct pci_dev *pdev)
7054 scsi_qla_host_t *base_vha = pci_get_drvdata(pdev);
7055 struct qla_hw_data *ha = base_vha->hw;
7056 struct qla_qpair *qpair;
7058 ql_log(ql_log_warn, base_vha, 0xffff,
7062 * PCI FLR/function reset is about to reset the
7063 * slot. Stop the chip to stop all DMA access.
7064 * It is assumed that pci_reset_done will be called
7065 * after FLR to resume Chip operation.
7067 ha->flags.eeh_busy = 1;
7068 mutex_lock(&ha->mq_lock);
7069 list_for_each_entry(qpair, &base_vha->qp_list, qp_list_elem)
7071 mutex_unlock(&ha->mq_lock);
7073 set_bit(ABORT_ISP_ACTIVE, &base_vha->dpc_flags);
7074 qla2x00_abort_isp_cleanup(base_vha);
7075 qla2x00_abort_all_cmds(base_vha, DID_RESET << 16);
7079 qla_pci_reset_done(struct pci_dev *pdev)
7081 scsi_qla_host_t *base_vha = pci_get_drvdata(pdev);
7082 struct qla_hw_data *ha = base_vha->hw;
7083 struct qla_qpair *qpair;
7085 ql_log(ql_log_warn, base_vha, 0xffff,
7089 * FLR just completed by PCI layer. Resume adapter
7091 ha->flags.eeh_busy = 0;
7092 mutex_lock(&ha->mq_lock);
7093 list_for_each_entry(qpair, &base_vha->qp_list, qp_list_elem)
7095 mutex_unlock(&ha->mq_lock);
7097 base_vha->flags.online = 1;
7098 ha->isp_ops->abort_isp(base_vha);
7099 clear_bit(ABORT_ISP_ACTIVE, &base_vha->dpc_flags);
7102 static int qla2xxx_map_queues(struct Scsi_Host *shost)
7105 scsi_qla_host_t *vha = (scsi_qla_host_t *)shost->hostdata;
7106 struct blk_mq_queue_map *qmap = &shost->tag_set.map[HCTX_TYPE_DEFAULT];
7108 if (USER_CTRL_IRQ(vha->hw) || !vha->hw->mqiobase)
7109 rc = blk_mq_map_queues(qmap);
7111 rc = blk_mq_pci_map_queues(qmap, vha->hw->pdev, vha->irq_offset);
7115 struct scsi_host_template qla2xxx_driver_template = {
7116 .module = THIS_MODULE,
7117 .name = QLA2XXX_DRIVER_NAME,
7118 .queuecommand = qla2xxx_queuecommand,
7120 .eh_timed_out = fc_eh_timed_out,
7121 .eh_abort_handler = qla2xxx_eh_abort,
7122 .eh_device_reset_handler = qla2xxx_eh_device_reset,
7123 .eh_target_reset_handler = qla2xxx_eh_target_reset,
7124 .eh_bus_reset_handler = qla2xxx_eh_bus_reset,
7125 .eh_host_reset_handler = qla2xxx_eh_host_reset,
7127 .slave_configure = qla2xxx_slave_configure,
7129 .slave_alloc = qla2xxx_slave_alloc,
7130 .slave_destroy = qla2xxx_slave_destroy,
7131 .scan_finished = qla2xxx_scan_finished,
7132 .scan_start = qla2xxx_scan_start,
7133 .change_queue_depth = scsi_change_queue_depth,
7134 .map_queues = qla2xxx_map_queues,
7137 .sg_tablesize = SG_ALL,
7139 .max_sectors = 0xFFFF,
7140 .shost_attrs = qla2x00_host_attrs,
7142 .supported_mode = MODE_INITIATOR,
7143 .track_queue_depth = 1,
7144 .cmd_size = sizeof(srb_t),
7147 static const struct pci_error_handlers qla2xxx_err_handler = {
7148 .error_detected = qla2xxx_pci_error_detected,
7149 .mmio_enabled = qla2xxx_pci_mmio_enabled,
7150 .slot_reset = qla2xxx_pci_slot_reset,
7151 .resume = qla2xxx_pci_resume,
7152 .reset_prepare = qla_pci_reset_prepare,
7153 .reset_done = qla_pci_reset_done,
7156 static struct pci_device_id qla2xxx_pci_tbl[] = {
7157 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP2100) },
7158 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP2200) },
7159 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP2300) },
7160 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP2312) },
7161 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP2322) },
7162 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP6312) },
7163 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP6322) },
7164 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP2422) },
7165 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP2432) },
7166 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP8432) },
7167 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP5422) },
7168 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP5432) },
7169 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP2532) },
7170 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP2031) },
7171 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP8001) },
7172 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP8021) },
7173 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP8031) },
7174 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISPF001) },
7175 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP8044) },
7176 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP2071) },
7177 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP2271) },
7178 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP2261) },
7179 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP2061) },
7180 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP2081) },
7181 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP2281) },
7182 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP2089) },
7183 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP2289) },
7186 MODULE_DEVICE_TABLE(pci, qla2xxx_pci_tbl);
7188 static struct pci_driver qla2xxx_pci_driver = {
7189 .name = QLA2XXX_DRIVER_NAME,
7191 .owner = THIS_MODULE,
7193 .id_table = qla2xxx_pci_tbl,
7194 .probe = qla2x00_probe_one,
7195 .remove = qla2x00_remove_one,
7196 .shutdown = qla2x00_shutdown,
7197 .err_handler = &qla2xxx_err_handler,
7200 static const struct file_operations apidev_fops = {
7201 .owner = THIS_MODULE,
7202 .llseek = noop_llseek,
7206 * qla2x00_module_init - Module initialization.
7209 qla2x00_module_init(void)
7213 BUILD_BUG_ON(sizeof(cmd_entry_t) != 64);
7214 BUILD_BUG_ON(sizeof(cont_a64_entry_t) != 64);
7215 BUILD_BUG_ON(sizeof(cont_entry_t) != 64);
7216 BUILD_BUG_ON(sizeof(init_cb_t) != 96);
7217 BUILD_BUG_ON(sizeof(ms_iocb_entry_t) != 64);
7218 BUILD_BUG_ON(sizeof(request_t) != 64);
7219 BUILD_BUG_ON(sizeof(struct access_chip_84xx) != 64);
7220 BUILD_BUG_ON(sizeof(struct cmd_bidir) != 64);
7221 BUILD_BUG_ON(sizeof(struct cmd_nvme) != 64);
7222 BUILD_BUG_ON(sizeof(struct cmd_type_6) != 64);
7223 BUILD_BUG_ON(sizeof(struct cmd_type_7) != 64);
7224 BUILD_BUG_ON(sizeof(struct cmd_type_7_fx00) != 64);
7225 BUILD_BUG_ON(sizeof(struct cmd_type_crc_2) != 64);
7226 BUILD_BUG_ON(sizeof(struct ct_entry_24xx) != 64);
7227 BUILD_BUG_ON(sizeof(struct ctio_crc2_to_fw) != 64);
7228 BUILD_BUG_ON(sizeof(struct els_entry_24xx) != 64);
7229 BUILD_BUG_ON(sizeof(struct fxdisc_entry_fx00) != 64);
7230 BUILD_BUG_ON(sizeof(struct init_cb_24xx) != 128);
7231 BUILD_BUG_ON(sizeof(struct init_cb_81xx) != 128);
7232 BUILD_BUG_ON(sizeof(struct pt_ls4_request) != 64);
7233 BUILD_BUG_ON(sizeof(struct sns_cmd_pkt) != 2064);
7234 BUILD_BUG_ON(sizeof(struct verify_chip_entry_84xx) != 64);
7235 BUILD_BUG_ON(sizeof(struct vf_evfp_entry_24xx) != 56);
7237 /* Allocate cache for SRBs. */
7238 srb_cachep = kmem_cache_create("qla2xxx_srbs", sizeof(srb_t), 0,
7239 SLAB_HWCACHE_ALIGN, NULL);
7240 if (srb_cachep == NULL) {
7241 ql_log(ql_log_fatal, NULL, 0x0001,
7242 "Unable to allocate SRB cache...Failing load!.\n");
7246 /* Initialize target kmem_cache and mem_pools */
7250 } else if (ret > 0) {
7252 * If initiator mode is explictly disabled by qlt_init(),
7253 * prevent scsi_transport_fc.c:fc_scsi_scan_rport() from
7254 * performing scsi_scan_target() during LOOP UP event.
7256 qla2xxx_transport_functions.disable_target_scan = 1;
7257 qla2xxx_transport_vport_functions.disable_target_scan = 1;
7260 /* Derive version string. */
7261 strcpy(qla2x00_version_str, QLA2XXX_VERSION);
7262 if (ql2xextended_error_logging)
7263 strcat(qla2x00_version_str, "-debug");
7264 if (ql2xextended_error_logging == 1)
7265 ql2xextended_error_logging = QL_DBG_DEFAULT1_MASK;
7267 if (ql2x_ini_mode == QLA2XXX_INI_MODE_DUAL)
7268 qla_insert_tgt_attrs();
7270 qla2xxx_transport_template =
7271 fc_attach_transport(&qla2xxx_transport_functions);
7272 if (!qla2xxx_transport_template) {
7273 ql_log(ql_log_fatal, NULL, 0x0002,
7274 "fc_attach_transport failed...Failing load!.\n");
7279 apidev_major = register_chrdev(0, QLA2XXX_APIDEV, &apidev_fops);
7280 if (apidev_major < 0) {
7281 ql_log(ql_log_fatal, NULL, 0x0003,
7282 "Unable to register char device %s.\n", QLA2XXX_APIDEV);
7285 qla2xxx_transport_vport_template =
7286 fc_attach_transport(&qla2xxx_transport_vport_functions);
7287 if (!qla2xxx_transport_vport_template) {
7288 ql_log(ql_log_fatal, NULL, 0x0004,
7289 "fc_attach_transport vport failed...Failing load!.\n");
7293 ql_log(ql_log_info, NULL, 0x0005,
7294 "QLogic Fibre Channel HBA Driver: %s.\n",
7295 qla2x00_version_str);
7296 ret = pci_register_driver(&qla2xxx_pci_driver);
7298 ql_log(ql_log_fatal, NULL, 0x0006,
7299 "pci_register_driver failed...ret=%d Failing load!.\n",
7301 goto release_vport_transport;
7305 release_vport_transport:
7306 fc_release_transport(qla2xxx_transport_vport_template);
7309 if (apidev_major >= 0)
7310 unregister_chrdev(apidev_major, QLA2XXX_APIDEV);
7311 fc_release_transport(qla2xxx_transport_template);
7317 kmem_cache_destroy(srb_cachep);
7322 * qla2x00_module_exit - Module cleanup.
7325 qla2x00_module_exit(void)
7327 pci_unregister_driver(&qla2xxx_pci_driver);
7328 qla2x00_release_firmware();
7329 kmem_cache_destroy(ctx_cachep);
7330 fc_release_transport(qla2xxx_transport_vport_template);
7331 if (apidev_major >= 0)
7332 unregister_chrdev(apidev_major, QLA2XXX_APIDEV);
7333 fc_release_transport(qla2xxx_transport_template);
7335 kmem_cache_destroy(srb_cachep);
7338 module_init(qla2x00_module_init);
7339 module_exit(qla2x00_module_exit);
7341 MODULE_AUTHOR("QLogic Corporation");
7342 MODULE_DESCRIPTION("QLogic Fibre Channel HBA Driver");
7343 MODULE_LICENSE("GPL");
7344 MODULE_VERSION(QLA2XXX_VERSION);