1 // SPDX-License-Identifier: GPL-2.0-only
3 * QLogic Fibre Channel HBA Driver
4 * Copyright (c) 2003-2014 QLogic Corporation
8 #include <linux/moduleparam.h>
9 #include <linux/vmalloc.h>
10 #include <linux/delay.h>
11 #include <linux/kthread.h>
12 #include <linux/mutex.h>
13 #include <linux/kobject.h>
14 #include <linux/slab.h>
15 #include <linux/blk-mq-pci.h>
16 #include <linux/refcount.h>
17 #include <linux/crash_dump.h>
19 #include <scsi/scsi_tcq.h>
20 #include <scsi/scsicam.h>
21 #include <scsi/scsi_transport.h>
22 #include <scsi/scsi_transport_fc.h>
24 #include "qla_target.h"
29 char qla2x00_version_str[40];
31 static int apidev_major;
34 * SRB allocation cache
36 struct kmem_cache *srb_cachep;
38 int ql2xfulldump_on_mpifail;
39 module_param(ql2xfulldump_on_mpifail, int, S_IRUGO | S_IWUSR);
40 MODULE_PARM_DESC(ql2xfulldump_on_mpifail,
41 "Set this to take full dump on MPI hang.");
43 int ql2xenforce_iocb_limit = 1;
44 module_param(ql2xenforce_iocb_limit, int, S_IRUGO | S_IWUSR);
45 MODULE_PARM_DESC(ql2xenforce_iocb_limit,
46 "Enforce IOCB throttling, to avoid FW congestion. (default: 1)");
49 * CT6 CTX allocation cache
51 static struct kmem_cache *ctx_cachep;
53 * error level for logging
55 uint ql_errlev = 0x8001;
58 module_param(ql2xsecenable, int, S_IRUGO);
59 MODULE_PARM_DESC(ql2xsecenable,
60 "Enable/disable security. 0(Default) - Security disabled. 1 - Security enabled.");
62 static int ql2xenableclass2;
63 module_param(ql2xenableclass2, int, S_IRUGO|S_IRUSR);
64 MODULE_PARM_DESC(ql2xenableclass2,
65 "Specify if Class 2 operations are supported from the very "
66 "beginning. Default is 0 - class 2 not supported.");
69 int ql2xlogintimeout = 20;
70 module_param(ql2xlogintimeout, int, S_IRUGO);
71 MODULE_PARM_DESC(ql2xlogintimeout,
72 "Login timeout value in seconds.");
74 int qlport_down_retry;
75 module_param(qlport_down_retry, int, S_IRUGO);
76 MODULE_PARM_DESC(qlport_down_retry,
77 "Maximum number of command retries to a port that returns "
78 "a PORT-DOWN status.");
80 int ql2xplogiabsentdevice;
81 module_param(ql2xplogiabsentdevice, int, S_IRUGO|S_IWUSR);
82 MODULE_PARM_DESC(ql2xplogiabsentdevice,
83 "Option to enable PLOGI to devices that are not present after "
84 "a Fabric scan. This is needed for several broken switches. "
85 "Default is 0 - no PLOGI. 1 - perform PLOGI.");
87 int ql2xloginretrycount;
88 module_param(ql2xloginretrycount, int, S_IRUGO);
89 MODULE_PARM_DESC(ql2xloginretrycount,
90 "Specify an alternate value for the NVRAM login retry count.");
92 int ql2xallocfwdump = 1;
93 module_param(ql2xallocfwdump, int, S_IRUGO);
94 MODULE_PARM_DESC(ql2xallocfwdump,
95 "Option to enable allocation of memory for a firmware dump "
96 "during HBA initialization. Memory allocation requirements "
97 "vary by ISP type. Default is 1 - allocate memory.");
99 int ql2xextended_error_logging;
100 module_param(ql2xextended_error_logging, int, S_IRUGO|S_IWUSR);
101 module_param_named(logging, ql2xextended_error_logging, int, S_IRUGO|S_IWUSR);
102 MODULE_PARM_DESC(ql2xextended_error_logging,
103 "Option to enable extended error logging,\n"
104 "\t\tDefault is 0 - no logging. 0x40000000 - Module Init & Probe.\n"
105 "\t\t0x20000000 - Mailbox Cmnds. 0x10000000 - Device Discovery.\n"
106 "\t\t0x08000000 - IO tracing. 0x04000000 - DPC Thread.\n"
107 "\t\t0x02000000 - Async events. 0x01000000 - Timer routines.\n"
108 "\t\t0x00800000 - User space. 0x00400000 - Task Management.\n"
109 "\t\t0x00200000 - AER/EEH. 0x00100000 - Multi Q.\n"
110 "\t\t0x00080000 - P3P Specific. 0x00040000 - Virtual Port.\n"
111 "\t\t0x00020000 - Buffer Dump. 0x00010000 - Misc.\n"
112 "\t\t0x00008000 - Verbose. 0x00004000 - Target.\n"
113 "\t\t0x00002000 - Target Mgmt. 0x00001000 - Target TMF.\n"
114 "\t\t0x7fffffff - For enabling all logs, can be too many logs.\n"
115 "\t\t0x1e400000 - Preferred value for capturing essential "
116 "debug information (equivalent to old "
117 "ql2xextended_error_logging=1).\n"
118 "\t\tDo LOGICAL OR of the value to enable more than one level");
120 int ql2xshiftctondsd = 6;
121 module_param(ql2xshiftctondsd, int, S_IRUGO);
122 MODULE_PARM_DESC(ql2xshiftctondsd,
123 "Set to control shifting of command type processing "
124 "based on total number of SG elements.");
126 int ql2xfdmienable = 1;
127 module_param(ql2xfdmienable, int, S_IRUGO|S_IWUSR);
128 module_param_named(fdmi, ql2xfdmienable, int, S_IRUGO|S_IWUSR);
129 MODULE_PARM_DESC(ql2xfdmienable,
130 "Enables FDMI registrations. "
131 "0 - no FDMI registrations. "
132 "1 - provide FDMI registrations (default).");
134 #define MAX_Q_DEPTH 64
135 static int ql2xmaxqdepth = MAX_Q_DEPTH;
136 module_param(ql2xmaxqdepth, int, S_IRUGO|S_IWUSR);
137 MODULE_PARM_DESC(ql2xmaxqdepth,
138 "Maximum queue depth to set for each LUN. "
141 int ql2xenabledif = 2;
142 module_param(ql2xenabledif, int, S_IRUGO);
143 MODULE_PARM_DESC(ql2xenabledif,
144 " Enable T10-CRC-DIF:\n"
146 " 0 -- No DIF Support\n"
147 " 1 -- Enable DIF for all types\n"
148 " 2 -- Enable DIF for all types, except Type 0.\n");
150 #if (IS_ENABLED(CONFIG_NVME_FC))
151 int ql2xnvmeenable = 1;
155 module_param(ql2xnvmeenable, int, 0644);
156 MODULE_PARM_DESC(ql2xnvmeenable,
157 "Enables NVME support. "
158 "0 - no NVMe. Default is Y");
160 int ql2xenablehba_err_chk = 2;
161 module_param(ql2xenablehba_err_chk, int, S_IRUGO|S_IWUSR);
162 MODULE_PARM_DESC(ql2xenablehba_err_chk,
163 " Enable T10-CRC-DIF Error isolation by HBA:\n"
165 " 0 -- Error isolation disabled\n"
166 " 1 -- Error isolation enabled only for DIX Type 0\n"
167 " 2 -- Error isolation enabled for all Types\n");
169 int ql2xiidmaenable = 1;
170 module_param(ql2xiidmaenable, int, S_IRUGO);
171 MODULE_PARM_DESC(ql2xiidmaenable,
172 "Enables iIDMA settings "
173 "Default is 1 - perform iIDMA. 0 - no iIDMA.");
175 int ql2xmqsupport = 1;
176 module_param(ql2xmqsupport, int, S_IRUGO);
177 MODULE_PARM_DESC(ql2xmqsupport,
178 "Enable on demand multiple queue pairs support "
179 "Default is 1 for supported. "
180 "Set it to 0 to turn off mq qpair support.");
183 module_param(ql2xfwloadbin, int, S_IRUGO|S_IWUSR);
184 module_param_named(fwload, ql2xfwloadbin, int, S_IRUGO|S_IWUSR);
185 MODULE_PARM_DESC(ql2xfwloadbin,
186 "Option to specify location from which to load ISP firmware:.\n"
187 " 2 -- load firmware via the reject_firmware() (hotplug).\n"
189 " 1 -- load firmware from flash.\n"
190 " 0 -- use default semantics.\n");
193 module_param(ql2xetsenable, int, S_IRUGO);
194 MODULE_PARM_DESC(ql2xetsenable,
195 "Enables firmware ETS burst."
196 "Default is 0 - skip ETS enablement.");
199 module_param(ql2xdbwr, int, S_IRUGO|S_IWUSR);
200 MODULE_PARM_DESC(ql2xdbwr,
201 "Option to specify scheme for request queue posting.\n"
202 " 0 -- Regular doorbell.\n"
203 " 1 -- CAMRAM doorbell (faster).\n");
206 module_param(ql2xgffidenable, int, S_IRUGO);
207 MODULE_PARM_DESC(ql2xgffidenable,
208 "Enables GFF_ID checks of port type. "
209 "Default is 0 - Do not use GFF_ID information.");
211 int ql2xasynctmfenable = 1;
212 module_param(ql2xasynctmfenable, int, S_IRUGO);
213 MODULE_PARM_DESC(ql2xasynctmfenable,
214 "Enables issue of TM IOCBs asynchronously via IOCB mechanism"
215 "Default is 1 - Issue TM IOCBs via mailbox mechanism.");
217 int ql2xdontresethba;
218 module_param(ql2xdontresethba, int, S_IRUGO|S_IWUSR);
219 MODULE_PARM_DESC(ql2xdontresethba,
220 "Option to specify reset behaviour.\n"
221 " 0 (Default) -- Reset on failure.\n"
222 " 1 -- Do not reset on failure.\n");
224 uint64_t ql2xmaxlun = MAX_LUNS;
225 module_param(ql2xmaxlun, ullong, S_IRUGO);
226 MODULE_PARM_DESC(ql2xmaxlun,
227 "Defines the maximum LU number to register with the SCSI "
228 "midlayer. Default is 65535.");
230 int ql2xmdcapmask = 0x1F;
231 module_param(ql2xmdcapmask, int, S_IRUGO);
232 MODULE_PARM_DESC(ql2xmdcapmask,
233 "Set the Minidump driver capture mask level. "
234 "Default is 0x1F - Can be set to 0x3, 0x7, 0xF, 0x1F, 0x7F.");
236 int ql2xmdenable = 1;
237 module_param(ql2xmdenable, int, S_IRUGO);
238 MODULE_PARM_DESC(ql2xmdenable,
239 "Enable/disable MiniDump. "
240 "0 - MiniDump disabled. "
241 "1 (Default) - MiniDump enabled.");
244 module_param(ql2xexlogins, uint, S_IRUGO|S_IWUSR);
245 MODULE_PARM_DESC(ql2xexlogins,
246 "Number of extended Logins. "
247 "0 (Default)- Disabled.");
249 int ql2xexchoffld = 1024;
250 module_param(ql2xexchoffld, uint, 0644);
251 MODULE_PARM_DESC(ql2xexchoffld,
252 "Number of target exchanges.");
254 int ql2xiniexchg = 1024;
255 module_param(ql2xiniexchg, uint, 0644);
256 MODULE_PARM_DESC(ql2xiniexchg,
257 "Number of initiator exchanges.");
260 module_param(ql2xfwholdabts, int, S_IRUGO);
261 MODULE_PARM_DESC(ql2xfwholdabts,
262 "Allow FW to hold status IOCB until ABTS rsp received. "
263 "0 (Default) Do not set fw option. "
264 "1 - Set fw option to hold ABTS.");
266 int ql2xmvasynctoatio = 1;
267 module_param(ql2xmvasynctoatio, int, S_IRUGO|S_IWUSR);
268 MODULE_PARM_DESC(ql2xmvasynctoatio,
269 "Move PUREX, ABTS RX and RIDA IOCBs to ATIOQ"
270 "0 (Default). Do not move IOCBs"
273 int ql2xautodetectsfp = 1;
274 module_param(ql2xautodetectsfp, int, 0444);
275 MODULE_PARM_DESC(ql2xautodetectsfp,
276 "Detect SFP range and set appropriate distance.\n"
277 "1 (Default): Enable\n");
279 int ql2xenablemsix = 1;
280 module_param(ql2xenablemsix, int, 0444);
281 MODULE_PARM_DESC(ql2xenablemsix,
282 "Set to enable MSI or MSI-X interrupt mechanism.\n"
283 " Default is 1, enable MSI-X interrupt mechanism.\n"
284 " 0 -- enable traditional pin-based mechanism.\n"
285 " 1 -- enable MSI-X interrupt mechanism.\n"
286 " 2 -- enable MSI interrupt mechanism.\n");
288 int qla2xuseresexchforels;
289 module_param(qla2xuseresexchforels, int, 0444);
290 MODULE_PARM_DESC(qla2xuseresexchforels,
291 "Reserve 1/2 of emergency exchanges for ELS.\n"
292 " 0 (default): disabled");
294 static int ql2xprotmask;
295 module_param(ql2xprotmask, int, 0644);
296 MODULE_PARM_DESC(ql2xprotmask,
297 "Override DIF/DIX protection capabilities mask\n"
298 "Default is 0 which sets protection mask based on "
299 "capabilities reported by HBA firmware.\n");
301 static int ql2xprotguard;
302 module_param(ql2xprotguard, int, 0644);
303 MODULE_PARM_DESC(ql2xprotguard, "Override choice of DIX checksum\n"
304 " 0 -- Let HBA firmware decide\n"
305 " 1 -- Force T10 CRC\n"
306 " 2 -- Force IP checksum\n");
308 int ql2xdifbundlinginternalbuffers;
309 module_param(ql2xdifbundlinginternalbuffers, int, 0644);
310 MODULE_PARM_DESC(ql2xdifbundlinginternalbuffers,
311 "Force using internal buffers for DIF information\n"
312 "0 (Default). Based on check.\n"
313 "1 Force using internal buffers\n");
316 module_param(ql2xsmartsan, int, 0444);
317 module_param_named(smartsan, ql2xsmartsan, int, 0444);
318 MODULE_PARM_DESC(ql2xsmartsan,
319 "Send SmartSAN Management Attributes for FDMI Registration."
320 " Default is 0 - No SmartSAN registration,"
321 " 1 - Register SmartSAN Management Attributes.");
324 module_param(ql2xrdpenable, int, 0444);
325 module_param_named(rdpenable, ql2xrdpenable, int, 0444);
326 MODULE_PARM_DESC(ql2xrdpenable,
327 "Enables RDP responses. "
328 "0 - no RDP responses (default). "
329 "1 - provide RDP responses.");
330 int ql2xabts_wait_nvme = 1;
331 module_param(ql2xabts_wait_nvme, int, 0444);
332 MODULE_PARM_DESC(ql2xabts_wait_nvme,
333 "To wait for ABTS response on I/O timeouts for NVMe. (default: 1)");
336 static void qla2x00_clear_drv_active(struct qla_hw_data *);
337 static void qla2x00_free_device(scsi_qla_host_t *);
338 static int qla2xxx_map_queues(struct Scsi_Host *shost);
339 static void qla2x00_destroy_deferred_work(struct qla_hw_data *);
342 static struct scsi_transport_template *qla2xxx_transport_template = NULL;
343 struct scsi_transport_template *qla2xxx_transport_vport_template = NULL;
345 /* TODO Convert to inlines
351 qla2x00_start_timer(scsi_qla_host_t *vha, unsigned long interval)
353 timer_setup(&vha->timer, qla2x00_timer, 0);
354 vha->timer.expires = jiffies + interval * HZ;
355 add_timer(&vha->timer);
356 vha->timer_active = 1;
360 qla2x00_restart_timer(scsi_qla_host_t *vha, unsigned long interval)
362 /* Currently used for 82XX only. */
363 if (vha->device_flags & DFLG_DEV_FAILED) {
364 ql_dbg(ql_dbg_timer, vha, 0x600d,
365 "Device in a failed state, returning.\n");
369 mod_timer(&vha->timer, jiffies + interval * HZ);
372 static __inline__ void
373 qla2x00_stop_timer(scsi_qla_host_t *vha)
375 del_timer_sync(&vha->timer);
376 vha->timer_active = 0;
379 static int qla2x00_do_dpc(void *data);
381 static void qla2x00_rst_aen(scsi_qla_host_t *);
383 static int qla2x00_mem_alloc(struct qla_hw_data *, uint16_t, uint16_t,
384 struct req_que **, struct rsp_que **);
385 static void qla2x00_free_fw_dump(struct qla_hw_data *);
386 static void qla2x00_mem_free(struct qla_hw_data *);
387 int qla2xxx_mqueuecommand(struct Scsi_Host *host, struct scsi_cmnd *cmd,
388 struct qla_qpair *qpair);
390 /* -------------------------------------------------------------------------- */
391 static void qla_init_base_qpair(struct scsi_qla_host *vha, struct req_que *req,
394 struct qla_hw_data *ha = vha->hw;
396 rsp->qpair = ha->base_qpair;
398 ha->base_qpair->hw = ha;
399 ha->base_qpair->req = req;
400 ha->base_qpair->rsp = rsp;
401 ha->base_qpair->vha = vha;
402 ha->base_qpair->qp_lock_ptr = &ha->hardware_lock;
403 ha->base_qpair->use_shadow_reg = IS_SHADOW_REG_CAPABLE(ha) ? 1 : 0;
404 ha->base_qpair->msix = &ha->msix_entries[QLA_MSIX_RSP_Q];
405 ha->base_qpair->srb_mempool = ha->srb_mempool;
406 INIT_LIST_HEAD(&ha->base_qpair->hints_list);
407 ha->base_qpair->enable_class_2 = ql2xenableclass2;
408 /* init qpair to this cpu. Will adjust at run time. */
409 qla_cpu_update(rsp->qpair, raw_smp_processor_id());
410 ha->base_qpair->pdev = ha->pdev;
412 if (IS_QLA27XX(ha) || IS_QLA83XX(ha) || IS_QLA28XX(ha))
413 ha->base_qpair->reqq_start_iocbs = qla_83xx_start_iocbs;
416 static int qla2x00_alloc_queues(struct qla_hw_data *ha, struct req_que *req,
419 scsi_qla_host_t *vha = pci_get_drvdata(ha->pdev);
421 ha->req_q_map = kcalloc(ha->max_req_queues, sizeof(struct req_que *),
423 if (!ha->req_q_map) {
424 ql_log(ql_log_fatal, vha, 0x003b,
425 "Unable to allocate memory for request queue ptrs.\n");
429 ha->rsp_q_map = kcalloc(ha->max_rsp_queues, sizeof(struct rsp_que *),
431 if (!ha->rsp_q_map) {
432 ql_log(ql_log_fatal, vha, 0x003c,
433 "Unable to allocate memory for response queue ptrs.\n");
437 ha->base_qpair = kzalloc(sizeof(struct qla_qpair), GFP_KERNEL);
438 if (ha->base_qpair == NULL) {
439 ql_log(ql_log_warn, vha, 0x00e0,
440 "Failed to allocate base queue pair memory.\n");
441 goto fail_base_qpair;
444 qla_init_base_qpair(vha, req, rsp);
446 if ((ql2xmqsupport || ql2xnvmeenable) && ha->max_qpairs) {
447 ha->queue_pair_map = kcalloc(ha->max_qpairs, sizeof(struct qla_qpair *),
449 if (!ha->queue_pair_map) {
450 ql_log(ql_log_fatal, vha, 0x0180,
451 "Unable to allocate memory for queue pair ptrs.\n");
457 * Make sure we record at least the request and response queue zero in
458 * case we need to free them if part of the probe fails.
460 ha->rsp_q_map[0] = rsp;
461 ha->req_q_map[0] = req;
462 set_bit(0, ha->rsp_qid_map);
463 set_bit(0, ha->req_qid_map);
467 kfree(ha->base_qpair);
468 ha->base_qpair = NULL;
470 kfree(ha->rsp_q_map);
471 ha->rsp_q_map = NULL;
473 kfree(ha->req_q_map);
474 ha->req_q_map = NULL;
479 static void qla2x00_free_req_que(struct qla_hw_data *ha, struct req_que *req)
481 if (IS_QLAFX00(ha)) {
482 if (req && req->ring_fx00)
483 dma_free_coherent(&ha->pdev->dev,
484 (req->length_fx00 + 1) * sizeof(request_t),
485 req->ring_fx00, req->dma_fx00);
486 } else if (req && req->ring)
487 dma_free_coherent(&ha->pdev->dev,
488 (req->length + 1) * sizeof(request_t),
489 req->ring, req->dma);
492 kfree(req->outstanding_cmds);
497 static void qla2x00_free_rsp_que(struct qla_hw_data *ha, struct rsp_que *rsp)
499 if (IS_QLAFX00(ha)) {
500 if (rsp && rsp->ring_fx00)
501 dma_free_coherent(&ha->pdev->dev,
502 (rsp->length_fx00 + 1) * sizeof(request_t),
503 rsp->ring_fx00, rsp->dma_fx00);
504 } else if (rsp && rsp->ring) {
505 dma_free_coherent(&ha->pdev->dev,
506 (rsp->length + 1) * sizeof(response_t),
507 rsp->ring, rsp->dma);
512 static void qla2x00_free_queues(struct qla_hw_data *ha)
519 if (ha->queue_pair_map) {
520 kfree(ha->queue_pair_map);
521 ha->queue_pair_map = NULL;
523 if (ha->base_qpair) {
524 kfree(ha->base_qpair);
525 ha->base_qpair = NULL;
528 spin_lock_irqsave(&ha->hardware_lock, flags);
529 for (cnt = 0; cnt < ha->max_req_queues; cnt++) {
530 if (!test_bit(cnt, ha->req_qid_map))
533 req = ha->req_q_map[cnt];
534 clear_bit(cnt, ha->req_qid_map);
535 ha->req_q_map[cnt] = NULL;
537 spin_unlock_irqrestore(&ha->hardware_lock, flags);
538 qla2x00_free_req_que(ha, req);
539 spin_lock_irqsave(&ha->hardware_lock, flags);
541 spin_unlock_irqrestore(&ha->hardware_lock, flags);
543 kfree(ha->req_q_map);
544 ha->req_q_map = NULL;
547 spin_lock_irqsave(&ha->hardware_lock, flags);
548 for (cnt = 0; cnt < ha->max_rsp_queues; cnt++) {
549 if (!test_bit(cnt, ha->rsp_qid_map))
552 rsp = ha->rsp_q_map[cnt];
553 clear_bit(cnt, ha->rsp_qid_map);
554 ha->rsp_q_map[cnt] = NULL;
555 spin_unlock_irqrestore(&ha->hardware_lock, flags);
556 qla2x00_free_rsp_que(ha, rsp);
557 spin_lock_irqsave(&ha->hardware_lock, flags);
559 spin_unlock_irqrestore(&ha->hardware_lock, flags);
561 kfree(ha->rsp_q_map);
562 ha->rsp_q_map = NULL;
566 qla2x00_pci_info_str(struct scsi_qla_host *vha, char *str, size_t str_len)
568 struct qla_hw_data *ha = vha->hw;
569 static const char *const pci_bus_modes[] = {
570 "33", "66", "100", "133",
574 pci_bus = (ha->pci_attr & (BIT_9 | BIT_10)) >> 9;
576 snprintf(str, str_len, "PCI-X (%s MHz)",
577 pci_bus_modes[pci_bus]);
579 pci_bus = (ha->pci_attr & BIT_8) >> 8;
580 snprintf(str, str_len, "PCI (%s MHz)", pci_bus_modes[pci_bus]);
587 qla24xx_pci_info_str(struct scsi_qla_host *vha, char *str, size_t str_len)
589 static const char *const pci_bus_modes[] = {
590 "33", "66", "100", "133",
592 struct qla_hw_data *ha = vha->hw;
595 if (pci_is_pcie(ha->pdev)) {
596 uint32_t lstat, lspeed, lwidth;
597 const char *speed_str;
599 pcie_capability_read_dword(ha->pdev, PCI_EXP_LNKCAP, &lstat);
600 lspeed = lstat & PCI_EXP_LNKCAP_SLS;
601 lwidth = (lstat & PCI_EXP_LNKCAP_MLW) >> 4;
605 speed_str = "2.5GT/s";
608 speed_str = "5.0GT/s";
611 speed_str = "8.0GT/s";
614 speed_str = "16.0GT/s";
617 speed_str = "<unknown>";
620 snprintf(str, str_len, "PCIe (%s x%d)", speed_str, lwidth);
625 pci_bus = (ha->pci_attr & CSRX_PCIX_BUS_MODE_MASK) >> 8;
626 if (pci_bus == 0 || pci_bus == 8)
627 snprintf(str, str_len, "PCI (%s MHz)",
628 pci_bus_modes[pci_bus >> 3]);
630 snprintf(str, str_len, "PCI-X Mode %d (%s MHz)",
632 pci_bus_modes[pci_bus & 3]);
638 qla2x00_fw_version_str(struct scsi_qla_host *vha, char *str, size_t size)
641 struct qla_hw_data *ha = vha->hw;
643 snprintf(str, size, "%d.%02d.%02d ", ha->fw_major_version,
644 ha->fw_minor_version, ha->fw_subminor_version);
646 if (ha->fw_attributes & BIT_9) {
651 switch (ha->fw_attributes & 0xFF) {
665 sprintf(un_str, "(%x)", ha->fw_attributes);
669 if (ha->fw_attributes & 0x100)
676 qla24xx_fw_version_str(struct scsi_qla_host *vha, char *str, size_t size)
678 struct qla_hw_data *ha = vha->hw;
680 snprintf(str, size, "%d.%02d.%02d (%x)", ha->fw_major_version,
681 ha->fw_minor_version, ha->fw_subminor_version, ha->fw_attributes);
685 void qla2x00_sp_free_dma(srb_t *sp)
687 struct qla_hw_data *ha = sp->vha->hw;
688 struct scsi_cmnd *cmd = GET_CMD_SP(sp);
690 if (sp->flags & SRB_DMA_VALID) {
692 sp->flags &= ~SRB_DMA_VALID;
695 if (sp->flags & SRB_CRC_PROT_DMA_VALID) {
696 dma_unmap_sg(&ha->pdev->dev, scsi_prot_sglist(cmd),
697 scsi_prot_sg_count(cmd), cmd->sc_data_direction);
698 sp->flags &= ~SRB_CRC_PROT_DMA_VALID;
701 if (sp->flags & SRB_CRC_CTX_DSD_VALID) {
702 /* List assured to be having elements */
703 qla2x00_clean_dsd_pool(ha, sp->u.scmd.crc_ctx);
704 sp->flags &= ~SRB_CRC_CTX_DSD_VALID;
707 if (sp->flags & SRB_CRC_CTX_DMA_VALID) {
708 struct crc_context *ctx0 = sp->u.scmd.crc_ctx;
710 dma_pool_free(ha->dl_dma_pool, ctx0, ctx0->crc_ctx_dma);
711 sp->flags &= ~SRB_CRC_CTX_DMA_VALID;
714 if (sp->flags & SRB_FCP_CMND_DMA_VALID) {
715 struct ct6_dsd *ctx1 = sp->u.scmd.ct6_ctx;
717 dma_pool_free(ha->fcp_cmnd_dma_pool, ctx1->fcp_cmnd,
719 list_splice(&ctx1->dsd_list, &ha->gbl_dsd_list);
720 ha->gbl_dsd_inuse -= ctx1->dsd_use_cnt;
721 ha->gbl_dsd_avail += ctx1->dsd_use_cnt;
722 mempool_free(ctx1, ha->ctx_mempool);
726 void qla2x00_sp_compl(srb_t *sp, int res)
728 struct scsi_cmnd *cmd = GET_CMD_SP(sp);
729 struct completion *comp = sp->comp;
732 kref_put(&sp->cmd_kref, qla2x00_sp_release);
740 void qla2xxx_qpair_sp_free_dma(srb_t *sp)
742 struct scsi_cmnd *cmd = GET_CMD_SP(sp);
743 struct qla_hw_data *ha = sp->fcport->vha->hw;
745 if (sp->flags & SRB_DMA_VALID) {
747 sp->flags &= ~SRB_DMA_VALID;
750 if (sp->flags & SRB_CRC_PROT_DMA_VALID) {
751 dma_unmap_sg(&ha->pdev->dev, scsi_prot_sglist(cmd),
752 scsi_prot_sg_count(cmd), cmd->sc_data_direction);
753 sp->flags &= ~SRB_CRC_PROT_DMA_VALID;
756 if (sp->flags & SRB_CRC_CTX_DSD_VALID) {
757 /* List assured to be having elements */
758 qla2x00_clean_dsd_pool(ha, sp->u.scmd.crc_ctx);
759 sp->flags &= ~SRB_CRC_CTX_DSD_VALID;
762 if (sp->flags & SRB_DIF_BUNDL_DMA_VALID) {
763 struct crc_context *difctx = sp->u.scmd.crc_ctx;
764 struct dsd_dma *dif_dsd, *nxt_dsd;
766 list_for_each_entry_safe(dif_dsd, nxt_dsd,
767 &difctx->ldif_dma_hndl_list, list) {
768 list_del(&dif_dsd->list);
769 dma_pool_free(ha->dif_bundl_pool, dif_dsd->dsd_addr,
770 dif_dsd->dsd_list_dma);
772 difctx->no_dif_bundl--;
775 list_for_each_entry_safe(dif_dsd, nxt_dsd,
776 &difctx->ldif_dsd_list, list) {
777 list_del(&dif_dsd->list);
778 dma_pool_free(ha->dl_dma_pool, dif_dsd->dsd_addr,
779 dif_dsd->dsd_list_dma);
781 difctx->no_ldif_dsd--;
784 if (difctx->no_ldif_dsd) {
785 ql_dbg(ql_dbg_tgt+ql_dbg_verbose, sp->vha, 0xe022,
786 "%s: difctx->no_ldif_dsd=%x\n",
787 __func__, difctx->no_ldif_dsd);
790 if (difctx->no_dif_bundl) {
791 ql_dbg(ql_dbg_tgt+ql_dbg_verbose, sp->vha, 0xe022,
792 "%s: difctx->no_dif_bundl=%x\n",
793 __func__, difctx->no_dif_bundl);
795 sp->flags &= ~SRB_DIF_BUNDL_DMA_VALID;
798 if (sp->flags & SRB_FCP_CMND_DMA_VALID) {
799 struct ct6_dsd *ctx1 = sp->u.scmd.ct6_ctx;
801 dma_pool_free(ha->fcp_cmnd_dma_pool, ctx1->fcp_cmnd,
803 list_splice(&ctx1->dsd_list, &ha->gbl_dsd_list);
804 ha->gbl_dsd_inuse -= ctx1->dsd_use_cnt;
805 ha->gbl_dsd_avail += ctx1->dsd_use_cnt;
806 mempool_free(ctx1, ha->ctx_mempool);
807 sp->flags &= ~SRB_FCP_CMND_DMA_VALID;
810 if (sp->flags & SRB_CRC_CTX_DMA_VALID) {
811 struct crc_context *ctx0 = sp->u.scmd.crc_ctx;
813 dma_pool_free(ha->dl_dma_pool, ctx0, ctx0->crc_ctx_dma);
814 sp->flags &= ~SRB_CRC_CTX_DMA_VALID;
818 void qla2xxx_qpair_sp_compl(srb_t *sp, int res)
820 struct scsi_cmnd *cmd = GET_CMD_SP(sp);
821 struct completion *comp = sp->comp;
824 kref_put(&sp->cmd_kref, qla2x00_sp_release);
833 qla2xxx_queuecommand(struct Scsi_Host *host, struct scsi_cmnd *cmd)
835 scsi_qla_host_t *vha = shost_priv(host);
836 fc_port_t *fcport = (struct fc_port *) cmd->device->hostdata;
837 struct fc_rport *rport = starget_to_rport(scsi_target(cmd->device));
838 struct qla_hw_data *ha = vha->hw;
839 struct scsi_qla_host *base_vha = pci_get_drvdata(ha->pdev);
843 if (unlikely(test_bit(UNLOADING, &base_vha->dpc_flags)) ||
844 WARN_ON_ONCE(!rport)) {
845 cmd->result = DID_NO_CONNECT << 16;
846 goto qc24_fail_command;
852 struct qla_qpair *qpair = NULL;
854 tag = blk_mq_unique_tag(scsi_cmd_to_rq(cmd));
855 hwq = blk_mq_unique_tag_to_hwq(tag);
856 qpair = ha->queue_pair_map[hwq];
859 return qla2xxx_mqueuecommand(host, cmd, qpair);
862 if (ha->flags.eeh_busy) {
863 if (ha->flags.pci_channel_io_perm_failure) {
864 ql_dbg(ql_dbg_aer, vha, 0x9010,
865 "PCI Channel IO permanent failure, exiting "
867 cmd->result = DID_NO_CONNECT << 16;
869 ql_dbg(ql_dbg_aer, vha, 0x9011,
870 "EEH_Busy, Requeuing the cmd=%p.\n", cmd);
871 cmd->result = DID_REQUEUE << 16;
873 goto qc24_fail_command;
876 rval = fc_remote_port_chkready(rport);
879 ql_dbg(ql_dbg_io + ql_dbg_verbose, vha, 0x3003,
880 "fc_remote_port_chkready failed for cmd=%p, rval=0x%x.\n",
882 goto qc24_fail_command;
885 if (!vha->flags.difdix_supported &&
886 scsi_get_prot_op(cmd) != SCSI_PROT_NORMAL) {
887 ql_dbg(ql_dbg_io, vha, 0x3004,
888 "DIF Cap not reg, fail DIF capable cmd's:%p.\n",
890 cmd->result = DID_NO_CONNECT << 16;
891 goto qc24_fail_command;
894 if (!fcport || fcport->deleted) {
895 cmd->result = DID_IMM_RETRY << 16;
896 goto qc24_fail_command;
899 if (atomic_read(&fcport->state) != FCS_ONLINE || fcport->deleted) {
900 if (atomic_read(&fcport->state) == FCS_DEVICE_DEAD ||
901 atomic_read(&base_vha->loop_state) == LOOP_DEAD) {
902 ql_dbg(ql_dbg_io, vha, 0x3005,
903 "Returning DNC, fcport_state=%d loop_state=%d.\n",
904 atomic_read(&fcport->state),
905 atomic_read(&base_vha->loop_state));
906 cmd->result = DID_NO_CONNECT << 16;
907 goto qc24_fail_command;
909 goto qc24_target_busy;
913 * Return target busy if we've received a non-zero retry_delay_timer
916 if (fcport->retry_delay_timestamp == 0) {
917 /* retry delay not set */
918 } else if (time_after(jiffies, fcport->retry_delay_timestamp))
919 fcport->retry_delay_timestamp = 0;
921 goto qc24_target_busy;
923 sp = scsi_cmd_priv(cmd);
925 qla2xxx_init_sp(sp, vha, vha->hw->base_qpair, fcport);
927 sp->u.scmd.cmd = cmd;
928 sp->type = SRB_SCSI_CMD;
930 CMD_SP(cmd) = (void *)sp;
931 sp->free = qla2x00_sp_free_dma;
932 sp->done = qla2x00_sp_compl;
934 rval = ha->isp_ops->start_scsi(sp);
935 if (rval != QLA_SUCCESS) {
936 ql_dbg(ql_dbg_io + ql_dbg_verbose, vha, 0x3013,
937 "Start scsi failed rval=%d for cmd=%p.\n", rval, cmd);
938 goto qc24_host_busy_free_sp;
943 qc24_host_busy_free_sp:
945 kref_put(&sp->cmd_kref, qla2x00_sp_release);
948 return SCSI_MLQUEUE_TARGET_BUSY;
956 /* For MQ supported I/O */
958 qla2xxx_mqueuecommand(struct Scsi_Host *host, struct scsi_cmnd *cmd,
959 struct qla_qpair *qpair)
961 scsi_qla_host_t *vha = shost_priv(host);
962 fc_port_t *fcport = (struct fc_port *) cmd->device->hostdata;
963 struct fc_rport *rport = starget_to_rport(scsi_target(cmd->device));
964 struct qla_hw_data *ha = vha->hw;
965 struct scsi_qla_host *base_vha = pci_get_drvdata(ha->pdev);
969 rval = rport ? fc_remote_port_chkready(rport) : (DID_NO_CONNECT << 16);
972 ql_dbg(ql_dbg_io + ql_dbg_verbose, vha, 0x3076,
973 "fc_remote_port_chkready failed for cmd=%p, rval=0x%x.\n",
975 goto qc24_fail_command;
978 if (!qpair->online) {
979 ql_dbg(ql_dbg_io, vha, 0x3077,
980 "qpair not online. eeh_busy=%d.\n", ha->flags.eeh_busy);
981 cmd->result = DID_NO_CONNECT << 16;
982 goto qc24_fail_command;
985 if (!fcport || fcport->deleted) {
986 cmd->result = DID_IMM_RETRY << 16;
987 goto qc24_fail_command;
990 if (atomic_read(&fcport->state) != FCS_ONLINE || fcport->deleted) {
991 if (atomic_read(&fcport->state) == FCS_DEVICE_DEAD ||
992 atomic_read(&base_vha->loop_state) == LOOP_DEAD) {
993 ql_dbg(ql_dbg_io, vha, 0x3077,
994 "Returning DNC, fcport_state=%d loop_state=%d.\n",
995 atomic_read(&fcport->state),
996 atomic_read(&base_vha->loop_state));
997 cmd->result = DID_NO_CONNECT << 16;
998 goto qc24_fail_command;
1000 goto qc24_target_busy;
1004 * Return target busy if we've received a non-zero retry_delay_timer
1007 if (fcport->retry_delay_timestamp == 0) {
1008 /* retry delay not set */
1009 } else if (time_after(jiffies, fcport->retry_delay_timestamp))
1010 fcport->retry_delay_timestamp = 0;
1012 goto qc24_target_busy;
1014 sp = scsi_cmd_priv(cmd);
1016 qla2xxx_init_sp(sp, vha, qpair, fcport);
1018 sp->u.scmd.cmd = cmd;
1019 sp->type = SRB_SCSI_CMD;
1020 CMD_SP(cmd) = (void *)sp;
1021 sp->free = qla2xxx_qpair_sp_free_dma;
1022 sp->done = qla2xxx_qpair_sp_compl;
1024 rval = ha->isp_ops->start_scsi_mq(sp);
1025 if (rval != QLA_SUCCESS) {
1026 ql_dbg(ql_dbg_io + ql_dbg_verbose, vha, 0x3078,
1027 "Start scsi failed rval=%d for cmd=%p.\n", rval, cmd);
1028 goto qc24_host_busy_free_sp;
1033 qc24_host_busy_free_sp:
1035 kref_put(&sp->cmd_kref, qla2x00_sp_release);
1038 return SCSI_MLQUEUE_TARGET_BUSY;
1041 cmd->scsi_done(cmd);
1047 * qla2x00_eh_wait_on_command
1048 * Waits for the command to be returned by the Firmware for some
1052 * cmd = Scsi Command to wait on.
1055 * Completed in time : QLA_SUCCESS
1056 * Did not complete in time : QLA_FUNCTION_FAILED
1059 qla2x00_eh_wait_on_command(struct scsi_cmnd *cmd)
1061 #define ABORT_POLLING_PERIOD 1000
1062 #define ABORT_WAIT_ITER ((2 * 1000) / (ABORT_POLLING_PERIOD))
1063 unsigned long wait_iter = ABORT_WAIT_ITER;
1064 scsi_qla_host_t *vha = shost_priv(cmd->device->host);
1065 struct qla_hw_data *ha = vha->hw;
1066 int ret = QLA_SUCCESS;
1068 if (unlikely(pci_channel_offline(ha->pdev)) || ha->flags.eeh_busy) {
1069 ql_dbg(ql_dbg_taskm, vha, 0x8005,
1070 "Return:eh_wait.\n");
1074 while (CMD_SP(cmd) && wait_iter--) {
1075 msleep(ABORT_POLLING_PERIOD);
1078 ret = QLA_FUNCTION_FAILED;
1084 * qla2x00_wait_for_hba_online
1085 * Wait till the HBA is online after going through
1086 * <= MAX_RETRIES_OF_ISP_ABORT or
1087 * finally HBA is disabled ie marked offline
1090 * ha - pointer to host adapter structure
1093 * Does context switching-Release SPIN_LOCK
1094 * (if any) before calling this routine.
1097 * Success (Adapter is online) : 0
1098 * Failed (Adapter is offline/disabled) : 1
1101 qla2x00_wait_for_hba_online(scsi_qla_host_t *vha)
1104 unsigned long wait_online;
1105 struct qla_hw_data *ha = vha->hw;
1106 scsi_qla_host_t *base_vha = pci_get_drvdata(ha->pdev);
1108 wait_online = jiffies + (MAX_LOOP_TIMEOUT * HZ);
1109 while (((test_bit(ISP_ABORT_NEEDED, &base_vha->dpc_flags)) ||
1110 test_bit(ABORT_ISP_ACTIVE, &base_vha->dpc_flags) ||
1111 test_bit(ISP_ABORT_RETRY, &base_vha->dpc_flags) ||
1112 ha->dpc_active) && time_before(jiffies, wait_online)) {
1116 if (base_vha->flags.online)
1117 return_status = QLA_SUCCESS;
1119 return_status = QLA_FUNCTION_FAILED;
1121 return (return_status);
1124 static inline int test_fcport_count(scsi_qla_host_t *vha)
1126 struct qla_hw_data *ha = vha->hw;
1127 unsigned long flags;
1129 /* Return 0 = sleep, x=wake */
1131 spin_lock_irqsave(&ha->tgt.sess_lock, flags);
1132 ql_dbg(ql_dbg_init, vha, 0x00ec,
1133 "tgt %p, fcport_count=%d\n",
1134 vha, vha->fcport_count);
1135 res = (vha->fcport_count == 0);
1137 struct fc_port *fcport;
1139 list_for_each_entry(fcport, &vha->vp_fcports, list) {
1140 if (fcport->deleted != QLA_SESS_DELETED) {
1141 /* session(s) may not be fully logged in
1142 * (ie fcport_count=0), but session
1143 * deletion thread(s) may be inflight.
1151 spin_unlock_irqrestore(&ha->tgt.sess_lock, flags);
1157 * qla2x00_wait_for_sess_deletion can only be called from remove_one.
1158 * it has dependency on UNLOADING flag to stop device discovery
1161 qla2x00_wait_for_sess_deletion(scsi_qla_host_t *vha)
1165 qla2x00_mark_all_devices_lost(vha);
1167 for (i = 0; i < 10; i++) {
1168 if (wait_event_timeout(vha->fcport_waitQ,
1169 test_fcport_count(vha), HZ) > 0)
1173 flush_workqueue(vha->hw->wq);
1177 * qla2x00_wait_for_hba_ready
1178 * Wait till the HBA is ready before doing driver unload
1181 * ha - pointer to host adapter structure
1184 * Does context switching-Release SPIN_LOCK
1185 * (if any) before calling this routine.
1189 qla2x00_wait_for_hba_ready(scsi_qla_host_t *vha)
1191 struct qla_hw_data *ha = vha->hw;
1192 scsi_qla_host_t *base_vha = pci_get_drvdata(ha->pdev);
1194 while ((qla2x00_reset_active(vha) || ha->dpc_active ||
1195 ha->flags.mbox_busy) ||
1196 test_bit(FX00_RESET_RECOVERY, &vha->dpc_flags) ||
1197 test_bit(FX00_TARGET_SCAN, &vha->dpc_flags)) {
1198 if (test_bit(UNLOADING, &base_vha->dpc_flags))
1205 qla2x00_wait_for_chip_reset(scsi_qla_host_t *vha)
1208 unsigned long wait_reset;
1209 struct qla_hw_data *ha = vha->hw;
1210 scsi_qla_host_t *base_vha = pci_get_drvdata(ha->pdev);
1212 wait_reset = jiffies + (MAX_LOOP_TIMEOUT * HZ);
1213 while (((test_bit(ISP_ABORT_NEEDED, &base_vha->dpc_flags)) ||
1214 test_bit(ABORT_ISP_ACTIVE, &base_vha->dpc_flags) ||
1215 test_bit(ISP_ABORT_RETRY, &base_vha->dpc_flags) ||
1216 ha->dpc_active) && time_before(jiffies, wait_reset)) {
1220 if (!test_bit(ISP_ABORT_NEEDED, &base_vha->dpc_flags) &&
1221 ha->flags.chip_reset_done)
1224 if (ha->flags.chip_reset_done)
1225 return_status = QLA_SUCCESS;
1227 return_status = QLA_FUNCTION_FAILED;
1229 return return_status;
1232 /**************************************************************************
1236 * The abort function will abort the specified command.
1239 * cmd = Linux SCSI command packet to be aborted.
1242 * Either SUCCESS or FAILED.
1245 * Only return FAILED if command not returned by firmware.
1246 **************************************************************************/
1248 qla2xxx_eh_abort(struct scsi_cmnd *cmd)
1250 scsi_qla_host_t *vha = shost_priv(cmd->device->host);
1251 DECLARE_COMPLETION_ONSTACK(comp);
1257 struct qla_hw_data *ha = vha->hw;
1259 struct qla_qpair *qpair;
1260 unsigned long flags;
1261 int fast_fail_status = SUCCESS;
1263 if (qla2x00_isp_reg_stat(ha)) {
1264 ql_log(ql_log_info, vha, 0x8042,
1265 "PCI/Register disconnect, exiting.\n");
1266 qla_pci_set_eeh_busy(vha);
1270 /* Save any FAST_IO_FAIL value to return later if abort succeeds */
1271 ret = fc_block_scsi_eh(cmd);
1273 fast_fail_status = ret;
1275 sp = scsi_cmd_priv(cmd);
1278 vha->cmd_timeout_cnt++;
1280 if ((sp->fcport && sp->fcport->deleted) || !qpair)
1281 return fast_fail_status != SUCCESS ? fast_fail_status : FAILED;
1283 spin_lock_irqsave(qpair->qp_lock_ptr, flags);
1285 spin_unlock_irqrestore(qpair->qp_lock_ptr, flags);
1288 id = cmd->device->id;
1289 lun = cmd->device->lun;
1291 ql_dbg(ql_dbg_taskm, vha, 0x8002,
1292 "Aborting from RISC nexus=%ld:%d:%llu sp=%p cmd=%p handle=%x\n",
1293 vha->host_no, id, lun, sp, cmd, sp->handle);
1296 * Abort will release the original Command/sp from FW. Let the
1297 * original command call scsi_done. In return, he will wakeup
1298 * this sleeping thread.
1300 rval = ha->isp_ops->abort_command(sp);
1302 ql_dbg(ql_dbg_taskm, vha, 0x8003,
1303 "Abort command mbx cmd=%p, rval=%x.\n", cmd, rval);
1305 /* Wait for the command completion. */
1306 ratov_j = ha->r_a_tov/10 * 4 * 1000;
1307 ratov_j = msecs_to_jiffies(ratov_j);
1310 if (!wait_for_completion_timeout(&comp, ratov_j)) {
1311 ql_dbg(ql_dbg_taskm, vha, 0xffff,
1312 "%s: Abort wait timer (4 * R_A_TOV[%d]) expired\n",
1313 __func__, ha->r_a_tov/10);
1316 ret = fast_fail_status;
1326 ql_log(ql_log_info, vha, 0x801c,
1327 "Abort command issued nexus=%ld:%d:%llu -- %x.\n",
1328 vha->host_no, id, lun, ret);
1334 * Returns: QLA_SUCCESS or QLA_FUNCTION_FAILED.
1337 qla2x00_eh_wait_for_pending_commands(scsi_qla_host_t *vha, unsigned int t,
1338 uint64_t l, enum nexus_wait_type type)
1340 int cnt, match, status;
1341 unsigned long flags;
1342 struct qla_hw_data *ha = vha->hw;
1343 struct req_que *req;
1345 struct scsi_cmnd *cmd;
1347 status = QLA_SUCCESS;
1349 spin_lock_irqsave(&ha->hardware_lock, flags);
1351 for (cnt = 1; status == QLA_SUCCESS &&
1352 cnt < req->num_outstanding_cmds; cnt++) {
1353 sp = req->outstanding_cmds[cnt];
1356 if (sp->type != SRB_SCSI_CMD)
1358 if (vha->vp_idx != sp->vha->vp_idx)
1361 cmd = GET_CMD_SP(sp);
1367 match = cmd->device->id == t;
1370 match = (cmd->device->id == t &&
1371 cmd->device->lun == l);
1377 spin_unlock_irqrestore(&ha->hardware_lock, flags);
1378 status = qla2x00_eh_wait_on_command(cmd);
1379 spin_lock_irqsave(&ha->hardware_lock, flags);
1381 spin_unlock_irqrestore(&ha->hardware_lock, flags);
1386 static char *reset_errors[] = {
1389 "Task management failed",
1390 "Waiting for command completions",
1394 qla2xxx_eh_device_reset(struct scsi_cmnd *cmd)
1396 struct scsi_device *sdev = cmd->device;
1397 scsi_qla_host_t *vha = shost_priv(sdev->host);
1398 struct fc_rport *rport = starget_to_rport(scsi_target(sdev));
1399 fc_port_t *fcport = (struct fc_port *) sdev->hostdata;
1400 struct qla_hw_data *ha = vha->hw;
1403 if (qla2x00_isp_reg_stat(ha)) {
1404 ql_log(ql_log_info, vha, 0x803e,
1405 "PCI/Register disconnect, exiting.\n");
1406 qla_pci_set_eeh_busy(vha);
1414 err = fc_block_rport(rport);
1418 if (fcport->deleted)
1421 ql_log(ql_log_info, vha, 0x8009,
1422 "DEVICE RESET ISSUED nexus=%ld:%d:%llu cmd=%p.\n", vha->host_no,
1423 sdev->id, sdev->lun, cmd);
1426 if (qla2x00_wait_for_hba_online(vha) != QLA_SUCCESS) {
1427 ql_log(ql_log_warn, vha, 0x800a,
1428 "Wait for hba online failed for cmd=%p.\n", cmd);
1429 goto eh_reset_failed;
1432 if (ha->isp_ops->lun_reset(fcport, sdev->lun, 1)
1434 ql_log(ql_log_warn, vha, 0x800c,
1435 "do_reset failed for cmd=%p.\n", cmd);
1436 goto eh_reset_failed;
1439 if (qla2x00_eh_wait_for_pending_commands(vha, sdev->id,
1440 sdev->lun, WAIT_LUN) != QLA_SUCCESS) {
1441 ql_log(ql_log_warn, vha, 0x800d,
1442 "wait for pending cmds failed for cmd=%p.\n", cmd);
1443 goto eh_reset_failed;
1446 ql_log(ql_log_info, vha, 0x800e,
1447 "DEVICE RESET SUCCEEDED nexus:%ld:%d:%llu cmd=%p.\n",
1448 vha->host_no, sdev->id, sdev->lun, cmd);
1453 ql_log(ql_log_info, vha, 0x800f,
1454 "DEVICE RESET FAILED: %s nexus=%ld:%d:%llu cmd=%p.\n",
1455 reset_errors[err], vha->host_no, sdev->id, sdev->lun,
1457 vha->reset_cmd_err_cnt++;
1462 qla2xxx_eh_target_reset(struct scsi_cmnd *cmd)
1464 struct scsi_device *sdev = cmd->device;
1465 struct fc_rport *rport = starget_to_rport(scsi_target(sdev));
1466 scsi_qla_host_t *vha = shost_priv(rport_to_shost(rport));
1467 struct qla_hw_data *ha = vha->hw;
1468 fc_port_t *fcport = *(fc_port_t **)rport->dd_data;
1471 if (qla2x00_isp_reg_stat(ha)) {
1472 ql_log(ql_log_info, vha, 0x803f,
1473 "PCI/Register disconnect, exiting.\n");
1474 qla_pci_set_eeh_busy(vha);
1482 err = fc_block_rport(rport);
1486 if (fcport->deleted)
1489 ql_log(ql_log_info, vha, 0x8009,
1490 "TARGET RESET ISSUED nexus=%ld:%d cmd=%p.\n", vha->host_no,
1494 if (qla2x00_wait_for_hba_online(vha) != QLA_SUCCESS) {
1495 ql_log(ql_log_warn, vha, 0x800a,
1496 "Wait for hba online failed for cmd=%p.\n", cmd);
1497 goto eh_reset_failed;
1500 if (ha->isp_ops->target_reset(fcport, 0, 0) != QLA_SUCCESS) {
1501 ql_log(ql_log_warn, vha, 0x800c,
1502 "target_reset failed for cmd=%p.\n", cmd);
1503 goto eh_reset_failed;
1506 if (qla2x00_eh_wait_for_pending_commands(vha, sdev->id,
1507 0, WAIT_TARGET) != QLA_SUCCESS) {
1508 ql_log(ql_log_warn, vha, 0x800d,
1509 "wait for pending cmds failed for cmd=%p.\n", cmd);
1510 goto eh_reset_failed;
1513 ql_log(ql_log_info, vha, 0x800e,
1514 "TARGET RESET SUCCEEDED nexus:%ld:%d cmd=%p.\n",
1515 vha->host_no, sdev->id, cmd);
1520 ql_log(ql_log_info, vha, 0x800f,
1521 "TARGET RESET FAILED: %s nexus=%ld:%d:%llu cmd=%p.\n",
1522 reset_errors[err], vha->host_no, cmd->device->id, cmd->device->lun,
1524 vha->reset_cmd_err_cnt++;
1528 /**************************************************************************
1529 * qla2xxx_eh_bus_reset
1532 * The bus reset function will reset the bus and abort any executing
1536 * cmd = Linux SCSI command packet of the command that cause the
1540 * SUCCESS/FAILURE (defined as macro in scsi.h).
1542 **************************************************************************/
1544 qla2xxx_eh_bus_reset(struct scsi_cmnd *cmd)
1546 scsi_qla_host_t *vha = shost_priv(cmd->device->host);
1550 struct qla_hw_data *ha = vha->hw;
1552 if (qla2x00_isp_reg_stat(ha)) {
1553 ql_log(ql_log_info, vha, 0x8040,
1554 "PCI/Register disconnect, exiting.\n");
1555 qla_pci_set_eeh_busy(vha);
1559 id = cmd->device->id;
1560 lun = cmd->device->lun;
1562 if (qla2x00_chip_is_down(vha))
1565 ql_log(ql_log_info, vha, 0x8012,
1566 "BUS RESET ISSUED nexus=%ld:%d:%llu.\n", vha->host_no, id, lun);
1568 if (qla2x00_wait_for_hba_online(vha) != QLA_SUCCESS) {
1569 ql_log(ql_log_fatal, vha, 0x8013,
1570 "Wait for hba online failed board disabled.\n");
1571 goto eh_bus_reset_done;
1574 if (qla2x00_loop_reset(vha) == QLA_SUCCESS)
1578 goto eh_bus_reset_done;
1580 /* Flush outstanding commands. */
1581 if (qla2x00_eh_wait_for_pending_commands(vha, 0, 0, WAIT_HOST) !=
1583 ql_log(ql_log_warn, vha, 0x8014,
1584 "Wait for pending commands failed.\n");
1589 ql_log(ql_log_warn, vha, 0x802b,
1590 "BUS RESET %s nexus=%ld:%d:%llu.\n",
1591 (ret == FAILED) ? "FAILED" : "SUCCEEDED", vha->host_no, id, lun);
1596 /**************************************************************************
1597 * qla2xxx_eh_host_reset
1600 * The reset function will reset the Adapter.
1603 * cmd = Linux SCSI command packet of the command that cause the
1607 * Either SUCCESS or FAILED.
1610 **************************************************************************/
1612 qla2xxx_eh_host_reset(struct scsi_cmnd *cmd)
1614 scsi_qla_host_t *vha = shost_priv(cmd->device->host);
1615 struct qla_hw_data *ha = vha->hw;
1619 scsi_qla_host_t *base_vha = pci_get_drvdata(ha->pdev);
1621 if (qla2x00_isp_reg_stat(ha)) {
1622 ql_log(ql_log_info, vha, 0x8041,
1623 "PCI/Register disconnect, exiting.\n");
1624 qla_pci_set_eeh_busy(vha);
1628 id = cmd->device->id;
1629 lun = cmd->device->lun;
1631 ql_log(ql_log_info, vha, 0x8018,
1632 "ADAPTER RESET ISSUED nexus=%ld:%d:%llu.\n", vha->host_no, id, lun);
1635 * No point in issuing another reset if one is active. Also do not
1636 * attempt a reset if we are updating flash.
1638 if (qla2x00_reset_active(vha) || ha->optrom_state != QLA_SWAITING)
1639 goto eh_host_reset_lock;
1641 if (vha != base_vha) {
1642 if (qla2x00_vp_abort_isp(vha))
1643 goto eh_host_reset_lock;
1645 if (IS_P3P_TYPE(vha->hw)) {
1646 if (!qla82xx_fcoe_ctx_reset(vha)) {
1647 /* Ctx reset success */
1649 goto eh_host_reset_lock;
1651 /* fall thru if ctx reset failed */
1654 flush_workqueue(ha->wq);
1656 set_bit(ABORT_ISP_ACTIVE, &base_vha->dpc_flags);
1657 if (ha->isp_ops->abort_isp(base_vha)) {
1658 clear_bit(ABORT_ISP_ACTIVE, &base_vha->dpc_flags);
1659 /* failed. schedule dpc to try */
1660 set_bit(ISP_ABORT_NEEDED, &base_vha->dpc_flags);
1662 if (qla2x00_wait_for_hba_online(vha) != QLA_SUCCESS) {
1663 ql_log(ql_log_warn, vha, 0x802a,
1664 "wait for hba online failed.\n");
1665 goto eh_host_reset_lock;
1668 clear_bit(ABORT_ISP_ACTIVE, &base_vha->dpc_flags);
1671 /* Waiting for command to be returned to OS.*/
1672 if (qla2x00_eh_wait_for_pending_commands(vha, 0, 0, WAIT_HOST) ==
1677 ql_log(ql_log_info, vha, 0x8017,
1678 "ADAPTER RESET %s nexus=%ld:%d:%llu.\n",
1679 (ret == FAILED) ? "FAILED" : "SUCCEEDED", vha->host_no, id, lun);
1685 * qla2x00_loop_reset
1689 * ha = adapter block pointer.
1695 qla2x00_loop_reset(scsi_qla_host_t *vha)
1698 struct qla_hw_data *ha = vha->hw;
1703 if (ha->flags.enable_lip_full_login && !IS_CNA_CAPABLE(ha)) {
1704 atomic_set(&vha->loop_state, LOOP_DOWN);
1705 atomic_set(&vha->loop_down_timer, LOOP_DOWN_TIME);
1706 qla2x00_mark_all_devices_lost(vha);
1707 ret = qla2x00_full_login_lip(vha);
1708 if (ret != QLA_SUCCESS) {
1709 ql_dbg(ql_dbg_taskm, vha, 0x802d,
1710 "full_login_lip=%d.\n", ret);
1714 if (ha->flags.enable_lip_reset) {
1715 ret = qla2x00_lip_reset(vha);
1716 if (ret != QLA_SUCCESS)
1717 ql_dbg(ql_dbg_taskm, vha, 0x802e,
1718 "lip_reset failed (%d).\n", ret);
1721 /* Issue marker command only when we are going to start the I/O */
1722 vha->marker_needed = 1;
1728 * The caller must ensure that no completion interrupts will happen
1729 * while this function is in progress.
1731 static void qla2x00_abort_srb(struct qla_qpair *qp, srb_t *sp, const int res,
1732 unsigned long *flags)
1733 __releases(qp->qp_lock_ptr)
1734 __acquires(qp->qp_lock_ptr)
1736 DECLARE_COMPLETION_ONSTACK(comp);
1737 scsi_qla_host_t *vha = qp->vha;
1738 struct qla_hw_data *ha = vha->hw;
1739 struct scsi_cmnd *cmd = GET_CMD_SP(sp);
1744 lockdep_assert_held(qp->qp_lock_ptr);
1746 if (qla2x00_chip_is_down(vha)) {
1751 if (sp->type == SRB_NVME_CMD || sp->type == SRB_NVME_LS ||
1752 (sp->type == SRB_SCSI_CMD && !ha->flags.eeh_busy &&
1753 !test_bit(ABORT_ISP_ACTIVE, &vha->dpc_flags) &&
1754 !qla2x00_isp_reg_stat(ha))) {
1761 spin_unlock_irqrestore(qp->qp_lock_ptr, *flags);
1763 rval = ha->isp_ops->abort_command(sp);
1764 /* Wait for command completion. */
1766 ratov_j = ha->r_a_tov/10 * 4 * 1000;
1767 ratov_j = msecs_to_jiffies(ratov_j);
1770 if (wait_for_completion_timeout(&comp, ratov_j)) {
1771 ql_dbg(ql_dbg_taskm, vha, 0xffff,
1772 "%s: Abort wait timer (4 * R_A_TOV[%d]) expired\n",
1773 __func__, ha->r_a_tov/10);
1776 /* else FW return SP to driver */
1783 spin_lock_irqsave(qp->qp_lock_ptr, *flags);
1784 if (ret_cmd && blk_mq_request_started(scsi_cmd_to_rq(cmd)))
1792 * The caller must ensure that no completion interrupts will happen
1793 * while this function is in progress.
1796 __qla2x00_abort_all_cmds(struct qla_qpair *qp, int res)
1799 unsigned long flags;
1801 scsi_qla_host_t *vha = qp->vha;
1802 struct qla_hw_data *ha = vha->hw;
1803 struct req_que *req;
1804 struct qla_tgt *tgt = vha->vha_tgt.qla_tgt;
1805 struct qla_tgt_cmd *cmd;
1809 spin_lock_irqsave(qp->qp_lock_ptr, flags);
1811 for (cnt = 1; cnt < req->num_outstanding_cmds; cnt++) {
1812 sp = req->outstanding_cmds[cnt];
1814 switch (sp->cmd_type) {
1816 qla2x00_abort_srb(qp, sp, res, &flags);
1819 if (!vha->hw->tgt.tgt_ops || !tgt ||
1820 qla_ini_mode_enabled(vha)) {
1821 ql_dbg(ql_dbg_tgt_mgt, vha, 0xf003,
1822 "HOST-ABORT-HNDLR: dpc_flags=%lx. Target mode disabled\n",
1826 cmd = (struct qla_tgt_cmd *)sp;
1829 case TYPE_TGT_TMCMD:
1830 /* Skip task management functions. */
1835 req->outstanding_cmds[cnt] = NULL;
1838 spin_unlock_irqrestore(qp->qp_lock_ptr, flags);
1842 * The caller must ensure that no completion interrupts will happen
1843 * while this function is in progress.
1846 qla2x00_abort_all_cmds(scsi_qla_host_t *vha, int res)
1849 struct qla_hw_data *ha = vha->hw;
1851 /* Continue only if initialization complete. */
1852 if (!ha->base_qpair)
1854 __qla2x00_abort_all_cmds(ha->base_qpair, res);
1856 if (!ha->queue_pair_map)
1858 for (que = 0; que < ha->max_qpairs; que++) {
1859 if (!ha->queue_pair_map[que])
1862 __qla2x00_abort_all_cmds(ha->queue_pair_map[que], res);
1867 qla2xxx_slave_alloc(struct scsi_device *sdev)
1869 struct fc_rport *rport = starget_to_rport(scsi_target(sdev));
1871 if (!rport || fc_remote_port_chkready(rport))
1874 sdev->hostdata = *(fc_port_t **)rport->dd_data;
1880 qla2xxx_slave_configure(struct scsi_device *sdev)
1882 scsi_qla_host_t *vha = shost_priv(sdev->host);
1883 struct req_que *req = vha->req;
1885 if (IS_T10_PI_CAPABLE(vha->hw))
1886 blk_queue_update_dma_alignment(sdev->request_queue, 0x7);
1888 scsi_change_queue_depth(sdev, req->max_q_depth);
1893 qla2xxx_slave_destroy(struct scsi_device *sdev)
1895 sdev->hostdata = NULL;
1899 * qla2x00_config_dma_addressing() - Configure OS DMA addressing method.
1902 * At exit, the @ha's flags.enable_64bit_addressing set to indicated
1903 * supported addressing method.
1906 qla2x00_config_dma_addressing(struct qla_hw_data *ha)
1908 /* Assume a 32bit DMA mask. */
1909 ha->flags.enable_64bit_addressing = 0;
1911 if (!dma_set_mask(&ha->pdev->dev, DMA_BIT_MASK(64))) {
1912 /* Any upper-dword bits set? */
1913 if (MSD(dma_get_required_mask(&ha->pdev->dev)) &&
1914 !dma_set_coherent_mask(&ha->pdev->dev, DMA_BIT_MASK(64))) {
1915 /* Ok, a 64bit DMA mask is applicable. */
1916 ha->flags.enable_64bit_addressing = 1;
1917 ha->isp_ops->calc_req_entries = qla2x00_calc_iocbs_64;
1918 ha->isp_ops->build_iocbs = qla2x00_build_scsi_iocbs_64;
1923 dma_set_mask(&ha->pdev->dev, DMA_BIT_MASK(32));
1924 dma_set_coherent_mask(&ha->pdev->dev, DMA_BIT_MASK(32));
1928 qla2x00_enable_intrs(struct qla_hw_data *ha)
1930 unsigned long flags = 0;
1931 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
1933 spin_lock_irqsave(&ha->hardware_lock, flags);
1934 ha->interrupts_on = 1;
1935 /* enable risc and host interrupts */
1936 wrt_reg_word(®->ictrl, ICR_EN_INT | ICR_EN_RISC);
1937 rd_reg_word(®->ictrl);
1938 spin_unlock_irqrestore(&ha->hardware_lock, flags);
1943 qla2x00_disable_intrs(struct qla_hw_data *ha)
1945 unsigned long flags = 0;
1946 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
1948 spin_lock_irqsave(&ha->hardware_lock, flags);
1949 ha->interrupts_on = 0;
1950 /* disable risc and host interrupts */
1951 wrt_reg_word(®->ictrl, 0);
1952 rd_reg_word(®->ictrl);
1953 spin_unlock_irqrestore(&ha->hardware_lock, flags);
1957 qla24xx_enable_intrs(struct qla_hw_data *ha)
1959 unsigned long flags = 0;
1960 struct device_reg_24xx __iomem *reg = &ha->iobase->isp24;
1962 spin_lock_irqsave(&ha->hardware_lock, flags);
1963 ha->interrupts_on = 1;
1964 wrt_reg_dword(®->ictrl, ICRX_EN_RISC_INT);
1965 rd_reg_dword(®->ictrl);
1966 spin_unlock_irqrestore(&ha->hardware_lock, flags);
1970 qla24xx_disable_intrs(struct qla_hw_data *ha)
1972 unsigned long flags = 0;
1973 struct device_reg_24xx __iomem *reg = &ha->iobase->isp24;
1975 if (IS_NOPOLLING_TYPE(ha))
1977 spin_lock_irqsave(&ha->hardware_lock, flags);
1978 ha->interrupts_on = 0;
1979 wrt_reg_dword(®->ictrl, 0);
1980 rd_reg_dword(®->ictrl);
1981 spin_unlock_irqrestore(&ha->hardware_lock, flags);
1985 qla2x00_iospace_config(struct qla_hw_data *ha)
1987 resource_size_t pio;
1990 if (pci_request_selected_regions(ha->pdev, ha->bars,
1991 QLA2XXX_DRIVER_NAME)) {
1992 ql_log_pci(ql_log_fatal, ha->pdev, 0x0011,
1993 "Failed to reserve PIO/MMIO regions (%s), aborting.\n",
1994 pci_name(ha->pdev));
1995 goto iospace_error_exit;
1997 if (!(ha->bars & 1))
2000 /* We only need PIO for Flash operations on ISP2312 v2 chips. */
2001 pio = pci_resource_start(ha->pdev, 0);
2002 if (pci_resource_flags(ha->pdev, 0) & IORESOURCE_IO) {
2003 if (pci_resource_len(ha->pdev, 0) < MIN_IOBASE_LEN) {
2004 ql_log_pci(ql_log_warn, ha->pdev, 0x0012,
2005 "Invalid pci I/O region size (%s).\n",
2006 pci_name(ha->pdev));
2010 ql_log_pci(ql_log_warn, ha->pdev, 0x0013,
2011 "Region #0 no a PIO resource (%s).\n",
2012 pci_name(ha->pdev));
2015 ha->pio_address = pio;
2016 ql_dbg_pci(ql_dbg_init, ha->pdev, 0x0014,
2017 "PIO address=%llu.\n",
2018 (unsigned long long)ha->pio_address);
2021 /* Use MMIO operations for all accesses. */
2022 if (!(pci_resource_flags(ha->pdev, 1) & IORESOURCE_MEM)) {
2023 ql_log_pci(ql_log_fatal, ha->pdev, 0x0015,
2024 "Region #1 not an MMIO resource (%s), aborting.\n",
2025 pci_name(ha->pdev));
2026 goto iospace_error_exit;
2028 if (pci_resource_len(ha->pdev, 1) < MIN_IOBASE_LEN) {
2029 ql_log_pci(ql_log_fatal, ha->pdev, 0x0016,
2030 "Invalid PCI mem region size (%s), aborting.\n",
2031 pci_name(ha->pdev));
2032 goto iospace_error_exit;
2035 ha->iobase = ioremap(pci_resource_start(ha->pdev, 1), MIN_IOBASE_LEN);
2037 ql_log_pci(ql_log_fatal, ha->pdev, 0x0017,
2038 "Cannot remap MMIO (%s), aborting.\n",
2039 pci_name(ha->pdev));
2040 goto iospace_error_exit;
2043 /* Determine queue resources */
2044 ha->max_req_queues = ha->max_rsp_queues = 1;
2045 ha->msix_count = QLA_BASE_VECTORS;
2047 /* Check if FW supports MQ or not */
2048 if (!(ha->fw_attributes & BIT_6))
2051 if (!ql2xmqsupport || !ql2xnvmeenable ||
2052 (!IS_QLA25XX(ha) && !IS_QLA81XX(ha)))
2055 ha->mqiobase = ioremap(pci_resource_start(ha->pdev, 3),
2056 pci_resource_len(ha->pdev, 3));
2058 ql_dbg_pci(ql_dbg_init, ha->pdev, 0x0018,
2059 "MQIO Base=%p.\n", ha->mqiobase);
2060 /* Read MSIX vector size of the board */
2061 pci_read_config_word(ha->pdev, QLA_PCI_MSIX_CONTROL, &msix);
2062 ha->msix_count = msix + 1;
2063 /* Max queues are bounded by available msix vectors */
2064 /* MB interrupt uses 1 vector */
2065 ha->max_req_queues = ha->msix_count - 1;
2066 ha->max_rsp_queues = ha->max_req_queues;
2067 /* Queue pairs is the max value minus the base queue pair */
2068 ha->max_qpairs = ha->max_rsp_queues - 1;
2069 ql_dbg_pci(ql_dbg_init, ha->pdev, 0x0188,
2070 "Max no of queues pairs: %d.\n", ha->max_qpairs);
2072 ql_log_pci(ql_log_info, ha->pdev, 0x001a,
2073 "MSI-X vector count: %d.\n", ha->msix_count);
2075 ql_log_pci(ql_log_info, ha->pdev, 0x001b,
2076 "BAR 3 not enabled.\n");
2079 ql_dbg_pci(ql_dbg_init, ha->pdev, 0x001c,
2080 "MSIX Count: %d.\n", ha->msix_count);
2089 qla83xx_iospace_config(struct qla_hw_data *ha)
2093 if (pci_request_selected_regions(ha->pdev, ha->bars,
2094 QLA2XXX_DRIVER_NAME)) {
2095 ql_log_pci(ql_log_fatal, ha->pdev, 0x0117,
2096 "Failed to reserve PIO/MMIO regions (%s), aborting.\n",
2097 pci_name(ha->pdev));
2099 goto iospace_error_exit;
2102 /* Use MMIO operations for all accesses. */
2103 if (!(pci_resource_flags(ha->pdev, 0) & IORESOURCE_MEM)) {
2104 ql_log_pci(ql_log_warn, ha->pdev, 0x0118,
2105 "Invalid pci I/O region size (%s).\n",
2106 pci_name(ha->pdev));
2107 goto iospace_error_exit;
2109 if (pci_resource_len(ha->pdev, 0) < MIN_IOBASE_LEN) {
2110 ql_log_pci(ql_log_warn, ha->pdev, 0x0119,
2111 "Invalid PCI mem region size (%s), aborting\n",
2112 pci_name(ha->pdev));
2113 goto iospace_error_exit;
2116 ha->iobase = ioremap(pci_resource_start(ha->pdev, 0), MIN_IOBASE_LEN);
2118 ql_log_pci(ql_log_fatal, ha->pdev, 0x011a,
2119 "Cannot remap MMIO (%s), aborting.\n",
2120 pci_name(ha->pdev));
2121 goto iospace_error_exit;
2124 /* 64bit PCI BAR - BAR2 will correspoond to region 4 */
2125 /* 83XX 26XX always use MQ type access for queues
2126 * - mbar 2, a.k.a region 4 */
2127 ha->max_req_queues = ha->max_rsp_queues = 1;
2128 ha->msix_count = QLA_BASE_VECTORS;
2129 ha->mqiobase = ioremap(pci_resource_start(ha->pdev, 4),
2130 pci_resource_len(ha->pdev, 4));
2132 if (!ha->mqiobase) {
2133 ql_log_pci(ql_log_fatal, ha->pdev, 0x011d,
2134 "BAR2/region4 not enabled\n");
2138 ha->msixbase = ioremap(pci_resource_start(ha->pdev, 2),
2139 pci_resource_len(ha->pdev, 2));
2141 /* Read MSIX vector size of the board */
2142 pci_read_config_word(ha->pdev,
2143 QLA_83XX_PCI_MSIX_CONTROL, &msix);
2144 ha->msix_count = (msix & PCI_MSIX_FLAGS_QSIZE) + 1;
2146 * By default, driver uses at least two msix vectors
2149 if (ql2xmqsupport || ql2xnvmeenable) {
2150 /* MB interrupt uses 1 vector */
2151 ha->max_req_queues = ha->msix_count - 1;
2153 /* ATIOQ needs 1 vector. That's 1 less QPair */
2154 if (QLA_TGT_MODE_ENABLED())
2155 ha->max_req_queues--;
2157 ha->max_rsp_queues = ha->max_req_queues;
2159 /* Queue pairs is the max value minus
2160 * the base queue pair */
2161 ha->max_qpairs = ha->max_req_queues - 1;
2162 ql_dbg_pci(ql_dbg_init, ha->pdev, 0x00e3,
2163 "Max no of queues pairs: %d.\n", ha->max_qpairs);
2165 ql_log_pci(ql_log_info, ha->pdev, 0x011c,
2166 "MSI-X vector count: %d.\n", ha->msix_count);
2168 ql_log_pci(ql_log_info, ha->pdev, 0x011e,
2169 "BAR 1 not enabled.\n");
2172 ql_dbg_pci(ql_dbg_init, ha->pdev, 0x011f,
2173 "MSIX Count: %d.\n", ha->msix_count);
2180 static struct isp_operations qla2100_isp_ops = {
2181 .pci_config = qla2100_pci_config,
2182 .reset_chip = qla2x00_reset_chip,
2183 .chip_diag = qla2x00_chip_diag,
2184 .config_rings = qla2x00_config_rings,
2185 .reset_adapter = qla2x00_reset_adapter,
2186 .nvram_config = qla2x00_nvram_config,
2187 .update_fw_options = qla2x00_update_fw_options,
2188 .load_risc = qla2x00_load_risc,
2189 .pci_info_str = qla2x00_pci_info_str,
2190 .fw_version_str = qla2x00_fw_version_str,
2191 .intr_handler = qla2100_intr_handler,
2192 .enable_intrs = qla2x00_enable_intrs,
2193 .disable_intrs = qla2x00_disable_intrs,
2194 .abort_command = qla2x00_abort_command,
2195 .target_reset = qla2x00_abort_target,
2196 .lun_reset = qla2x00_lun_reset,
2197 .fabric_login = qla2x00_login_fabric,
2198 .fabric_logout = qla2x00_fabric_logout,
2199 .calc_req_entries = qla2x00_calc_iocbs_32,
2200 .build_iocbs = qla2x00_build_scsi_iocbs_32,
2201 .prep_ms_iocb = qla2x00_prep_ms_iocb,
2202 .prep_ms_fdmi_iocb = qla2x00_prep_ms_fdmi_iocb,
2203 .read_nvram = qla2x00_read_nvram_data,
2204 .write_nvram = qla2x00_write_nvram_data,
2205 .fw_dump = qla2100_fw_dump,
2208 .beacon_blink = NULL,
2209 .read_optrom = qla2x00_read_optrom_data,
2210 .write_optrom = qla2x00_write_optrom_data,
2211 .get_flash_version = qla2x00_get_flash_version,
2212 .start_scsi = qla2x00_start_scsi,
2213 .start_scsi_mq = NULL,
2214 .abort_isp = qla2x00_abort_isp,
2215 .iospace_config = qla2x00_iospace_config,
2216 .initialize_adapter = qla2x00_initialize_adapter,
2219 static struct isp_operations qla2300_isp_ops = {
2220 .pci_config = qla2300_pci_config,
2221 .reset_chip = qla2x00_reset_chip,
2222 .chip_diag = qla2x00_chip_diag,
2223 .config_rings = qla2x00_config_rings,
2224 .reset_adapter = qla2x00_reset_adapter,
2225 .nvram_config = qla2x00_nvram_config,
2226 .update_fw_options = qla2x00_update_fw_options,
2227 .load_risc = qla2x00_load_risc,
2228 .pci_info_str = qla2x00_pci_info_str,
2229 .fw_version_str = qla2x00_fw_version_str,
2230 .intr_handler = qla2300_intr_handler,
2231 .enable_intrs = qla2x00_enable_intrs,
2232 .disable_intrs = qla2x00_disable_intrs,
2233 .abort_command = qla2x00_abort_command,
2234 .target_reset = qla2x00_abort_target,
2235 .lun_reset = qla2x00_lun_reset,
2236 .fabric_login = qla2x00_login_fabric,
2237 .fabric_logout = qla2x00_fabric_logout,
2238 .calc_req_entries = qla2x00_calc_iocbs_32,
2239 .build_iocbs = qla2x00_build_scsi_iocbs_32,
2240 .prep_ms_iocb = qla2x00_prep_ms_iocb,
2241 .prep_ms_fdmi_iocb = qla2x00_prep_ms_fdmi_iocb,
2242 .read_nvram = qla2x00_read_nvram_data,
2243 .write_nvram = qla2x00_write_nvram_data,
2244 .fw_dump = qla2300_fw_dump,
2245 .beacon_on = qla2x00_beacon_on,
2246 .beacon_off = qla2x00_beacon_off,
2247 .beacon_blink = qla2x00_beacon_blink,
2248 .read_optrom = qla2x00_read_optrom_data,
2249 .write_optrom = qla2x00_write_optrom_data,
2250 .get_flash_version = qla2x00_get_flash_version,
2251 .start_scsi = qla2x00_start_scsi,
2252 .start_scsi_mq = NULL,
2253 .abort_isp = qla2x00_abort_isp,
2254 .iospace_config = qla2x00_iospace_config,
2255 .initialize_adapter = qla2x00_initialize_adapter,
2258 static struct isp_operations qla24xx_isp_ops = {
2259 .pci_config = qla24xx_pci_config,
2260 .reset_chip = qla24xx_reset_chip,
2261 .chip_diag = qla24xx_chip_diag,
2262 .config_rings = qla24xx_config_rings,
2263 .reset_adapter = qla24xx_reset_adapter,
2264 .nvram_config = qla24xx_nvram_config,
2265 .update_fw_options = qla24xx_update_fw_options,
2266 .load_risc = qla24xx_load_risc,
2267 .pci_info_str = qla24xx_pci_info_str,
2268 .fw_version_str = qla24xx_fw_version_str,
2269 .intr_handler = qla24xx_intr_handler,
2270 .enable_intrs = qla24xx_enable_intrs,
2271 .disable_intrs = qla24xx_disable_intrs,
2272 .abort_command = qla24xx_abort_command,
2273 .target_reset = qla24xx_abort_target,
2274 .lun_reset = qla24xx_lun_reset,
2275 .fabric_login = qla24xx_login_fabric,
2276 .fabric_logout = qla24xx_fabric_logout,
2277 .calc_req_entries = NULL,
2278 .build_iocbs = NULL,
2279 .prep_ms_iocb = qla24xx_prep_ms_iocb,
2280 .prep_ms_fdmi_iocb = qla24xx_prep_ms_fdmi_iocb,
2281 .read_nvram = qla24xx_read_nvram_data,
2282 .write_nvram = qla24xx_write_nvram_data,
2283 .fw_dump = qla24xx_fw_dump,
2284 .beacon_on = qla24xx_beacon_on,
2285 .beacon_off = qla24xx_beacon_off,
2286 .beacon_blink = qla24xx_beacon_blink,
2287 .read_optrom = qla24xx_read_optrom_data,
2288 .write_optrom = qla24xx_write_optrom_data,
2289 .get_flash_version = qla24xx_get_flash_version,
2290 .start_scsi = qla24xx_start_scsi,
2291 .start_scsi_mq = NULL,
2292 .abort_isp = qla2x00_abort_isp,
2293 .iospace_config = qla2x00_iospace_config,
2294 .initialize_adapter = qla2x00_initialize_adapter,
2297 static struct isp_operations qla25xx_isp_ops = {
2298 .pci_config = qla25xx_pci_config,
2299 .reset_chip = qla24xx_reset_chip,
2300 .chip_diag = qla24xx_chip_diag,
2301 .config_rings = qla24xx_config_rings,
2302 .reset_adapter = qla24xx_reset_adapter,
2303 .nvram_config = qla24xx_nvram_config,
2304 .update_fw_options = qla24xx_update_fw_options,
2305 .load_risc = qla24xx_load_risc,
2306 .pci_info_str = qla24xx_pci_info_str,
2307 .fw_version_str = qla24xx_fw_version_str,
2308 .intr_handler = qla24xx_intr_handler,
2309 .enable_intrs = qla24xx_enable_intrs,
2310 .disable_intrs = qla24xx_disable_intrs,
2311 .abort_command = qla24xx_abort_command,
2312 .target_reset = qla24xx_abort_target,
2313 .lun_reset = qla24xx_lun_reset,
2314 .fabric_login = qla24xx_login_fabric,
2315 .fabric_logout = qla24xx_fabric_logout,
2316 .calc_req_entries = NULL,
2317 .build_iocbs = NULL,
2318 .prep_ms_iocb = qla24xx_prep_ms_iocb,
2319 .prep_ms_fdmi_iocb = qla24xx_prep_ms_fdmi_iocb,
2320 .read_nvram = qla25xx_read_nvram_data,
2321 .write_nvram = qla25xx_write_nvram_data,
2322 .fw_dump = qla25xx_fw_dump,
2323 .beacon_on = qla24xx_beacon_on,
2324 .beacon_off = qla24xx_beacon_off,
2325 .beacon_blink = qla24xx_beacon_blink,
2326 .read_optrom = qla25xx_read_optrom_data,
2327 .write_optrom = qla24xx_write_optrom_data,
2328 .get_flash_version = qla24xx_get_flash_version,
2329 .start_scsi = qla24xx_dif_start_scsi,
2330 .start_scsi_mq = qla2xxx_dif_start_scsi_mq,
2331 .abort_isp = qla2x00_abort_isp,
2332 .iospace_config = qla2x00_iospace_config,
2333 .initialize_adapter = qla2x00_initialize_adapter,
2336 static struct isp_operations qla81xx_isp_ops = {
2337 .pci_config = qla25xx_pci_config,
2338 .reset_chip = qla24xx_reset_chip,
2339 .chip_diag = qla24xx_chip_diag,
2340 .config_rings = qla24xx_config_rings,
2341 .reset_adapter = qla24xx_reset_adapter,
2342 .nvram_config = qla81xx_nvram_config,
2343 .update_fw_options = qla24xx_update_fw_options,
2344 .load_risc = qla81xx_load_risc,
2345 .pci_info_str = qla24xx_pci_info_str,
2346 .fw_version_str = qla24xx_fw_version_str,
2347 .intr_handler = qla24xx_intr_handler,
2348 .enable_intrs = qla24xx_enable_intrs,
2349 .disable_intrs = qla24xx_disable_intrs,
2350 .abort_command = qla24xx_abort_command,
2351 .target_reset = qla24xx_abort_target,
2352 .lun_reset = qla24xx_lun_reset,
2353 .fabric_login = qla24xx_login_fabric,
2354 .fabric_logout = qla24xx_fabric_logout,
2355 .calc_req_entries = NULL,
2356 .build_iocbs = NULL,
2357 .prep_ms_iocb = qla24xx_prep_ms_iocb,
2358 .prep_ms_fdmi_iocb = qla24xx_prep_ms_fdmi_iocb,
2360 .write_nvram = NULL,
2361 .fw_dump = qla81xx_fw_dump,
2362 .beacon_on = qla24xx_beacon_on,
2363 .beacon_off = qla24xx_beacon_off,
2364 .beacon_blink = qla83xx_beacon_blink,
2365 .read_optrom = qla25xx_read_optrom_data,
2366 .write_optrom = qla24xx_write_optrom_data,
2367 .get_flash_version = qla24xx_get_flash_version,
2368 .start_scsi = qla24xx_dif_start_scsi,
2369 .start_scsi_mq = qla2xxx_dif_start_scsi_mq,
2370 .abort_isp = qla2x00_abort_isp,
2371 .iospace_config = qla2x00_iospace_config,
2372 .initialize_adapter = qla2x00_initialize_adapter,
2375 static struct isp_operations qla82xx_isp_ops = {
2376 .pci_config = qla82xx_pci_config,
2377 .reset_chip = qla82xx_reset_chip,
2378 .chip_diag = qla24xx_chip_diag,
2379 .config_rings = qla82xx_config_rings,
2380 .reset_adapter = qla24xx_reset_adapter,
2381 .nvram_config = qla81xx_nvram_config,
2382 .update_fw_options = qla24xx_update_fw_options,
2383 .load_risc = qla82xx_load_risc,
2384 .pci_info_str = qla24xx_pci_info_str,
2385 .fw_version_str = qla24xx_fw_version_str,
2386 .intr_handler = qla82xx_intr_handler,
2387 .enable_intrs = qla82xx_enable_intrs,
2388 .disable_intrs = qla82xx_disable_intrs,
2389 .abort_command = qla24xx_abort_command,
2390 .target_reset = qla24xx_abort_target,
2391 .lun_reset = qla24xx_lun_reset,
2392 .fabric_login = qla24xx_login_fabric,
2393 .fabric_logout = qla24xx_fabric_logout,
2394 .calc_req_entries = NULL,
2395 .build_iocbs = NULL,
2396 .prep_ms_iocb = qla24xx_prep_ms_iocb,
2397 .prep_ms_fdmi_iocb = qla24xx_prep_ms_fdmi_iocb,
2398 .read_nvram = qla24xx_read_nvram_data,
2399 .write_nvram = qla24xx_write_nvram_data,
2400 .fw_dump = qla82xx_fw_dump,
2401 .beacon_on = qla82xx_beacon_on,
2402 .beacon_off = qla82xx_beacon_off,
2403 .beacon_blink = NULL,
2404 .read_optrom = qla82xx_read_optrom_data,
2405 .write_optrom = qla82xx_write_optrom_data,
2406 .get_flash_version = qla82xx_get_flash_version,
2407 .start_scsi = qla82xx_start_scsi,
2408 .start_scsi_mq = NULL,
2409 .abort_isp = qla82xx_abort_isp,
2410 .iospace_config = qla82xx_iospace_config,
2411 .initialize_adapter = qla2x00_initialize_adapter,
2414 static struct isp_operations qla8044_isp_ops = {
2415 .pci_config = qla82xx_pci_config,
2416 .reset_chip = qla82xx_reset_chip,
2417 .chip_diag = qla24xx_chip_diag,
2418 .config_rings = qla82xx_config_rings,
2419 .reset_adapter = qla24xx_reset_adapter,
2420 .nvram_config = qla81xx_nvram_config,
2421 .update_fw_options = qla24xx_update_fw_options,
2422 .load_risc = qla82xx_load_risc,
2423 .pci_info_str = qla24xx_pci_info_str,
2424 .fw_version_str = qla24xx_fw_version_str,
2425 .intr_handler = qla8044_intr_handler,
2426 .enable_intrs = qla82xx_enable_intrs,
2427 .disable_intrs = qla82xx_disable_intrs,
2428 .abort_command = qla24xx_abort_command,
2429 .target_reset = qla24xx_abort_target,
2430 .lun_reset = qla24xx_lun_reset,
2431 .fabric_login = qla24xx_login_fabric,
2432 .fabric_logout = qla24xx_fabric_logout,
2433 .calc_req_entries = NULL,
2434 .build_iocbs = NULL,
2435 .prep_ms_iocb = qla24xx_prep_ms_iocb,
2436 .prep_ms_fdmi_iocb = qla24xx_prep_ms_fdmi_iocb,
2438 .write_nvram = NULL,
2439 .fw_dump = qla8044_fw_dump,
2440 .beacon_on = qla82xx_beacon_on,
2441 .beacon_off = qla82xx_beacon_off,
2442 .beacon_blink = NULL,
2443 .read_optrom = qla8044_read_optrom_data,
2444 .write_optrom = qla8044_write_optrom_data,
2445 .get_flash_version = qla82xx_get_flash_version,
2446 .start_scsi = qla82xx_start_scsi,
2447 .start_scsi_mq = NULL,
2448 .abort_isp = qla8044_abort_isp,
2449 .iospace_config = qla82xx_iospace_config,
2450 .initialize_adapter = qla2x00_initialize_adapter,
2453 static struct isp_operations qla83xx_isp_ops = {
2454 .pci_config = qla25xx_pci_config,
2455 .reset_chip = qla24xx_reset_chip,
2456 .chip_diag = qla24xx_chip_diag,
2457 .config_rings = qla24xx_config_rings,
2458 .reset_adapter = qla24xx_reset_adapter,
2459 .nvram_config = qla81xx_nvram_config,
2460 .update_fw_options = qla24xx_update_fw_options,
2461 .load_risc = qla81xx_load_risc,
2462 .pci_info_str = qla24xx_pci_info_str,
2463 .fw_version_str = qla24xx_fw_version_str,
2464 .intr_handler = qla24xx_intr_handler,
2465 .enable_intrs = qla24xx_enable_intrs,
2466 .disable_intrs = qla24xx_disable_intrs,
2467 .abort_command = qla24xx_abort_command,
2468 .target_reset = qla24xx_abort_target,
2469 .lun_reset = qla24xx_lun_reset,
2470 .fabric_login = qla24xx_login_fabric,
2471 .fabric_logout = qla24xx_fabric_logout,
2472 .calc_req_entries = NULL,
2473 .build_iocbs = NULL,
2474 .prep_ms_iocb = qla24xx_prep_ms_iocb,
2475 .prep_ms_fdmi_iocb = qla24xx_prep_ms_fdmi_iocb,
2477 .write_nvram = NULL,
2478 .fw_dump = qla83xx_fw_dump,
2479 .beacon_on = qla24xx_beacon_on,
2480 .beacon_off = qla24xx_beacon_off,
2481 .beacon_blink = qla83xx_beacon_blink,
2482 .read_optrom = qla25xx_read_optrom_data,
2483 .write_optrom = qla24xx_write_optrom_data,
2484 .get_flash_version = qla24xx_get_flash_version,
2485 .start_scsi = qla24xx_dif_start_scsi,
2486 .start_scsi_mq = qla2xxx_dif_start_scsi_mq,
2487 .abort_isp = qla2x00_abort_isp,
2488 .iospace_config = qla83xx_iospace_config,
2489 .initialize_adapter = qla2x00_initialize_adapter,
2492 static struct isp_operations qlafx00_isp_ops = {
2493 .pci_config = qlafx00_pci_config,
2494 .reset_chip = qlafx00_soft_reset,
2495 .chip_diag = qlafx00_chip_diag,
2496 .config_rings = qlafx00_config_rings,
2497 .reset_adapter = qlafx00_soft_reset,
2498 .nvram_config = NULL,
2499 .update_fw_options = NULL,
2501 .pci_info_str = qlafx00_pci_info_str,
2502 .fw_version_str = qlafx00_fw_version_str,
2503 .intr_handler = qlafx00_intr_handler,
2504 .enable_intrs = qlafx00_enable_intrs,
2505 .disable_intrs = qlafx00_disable_intrs,
2506 .abort_command = qla24xx_async_abort_command,
2507 .target_reset = qlafx00_abort_target,
2508 .lun_reset = qlafx00_lun_reset,
2509 .fabric_login = NULL,
2510 .fabric_logout = NULL,
2511 .calc_req_entries = NULL,
2512 .build_iocbs = NULL,
2513 .prep_ms_iocb = qla24xx_prep_ms_iocb,
2514 .prep_ms_fdmi_iocb = qla24xx_prep_ms_fdmi_iocb,
2515 .read_nvram = qla24xx_read_nvram_data,
2516 .write_nvram = qla24xx_write_nvram_data,
2518 .beacon_on = qla24xx_beacon_on,
2519 .beacon_off = qla24xx_beacon_off,
2520 .beacon_blink = NULL,
2521 .read_optrom = qla24xx_read_optrom_data,
2522 .write_optrom = qla24xx_write_optrom_data,
2523 .get_flash_version = qla24xx_get_flash_version,
2524 .start_scsi = qlafx00_start_scsi,
2525 .start_scsi_mq = NULL,
2526 .abort_isp = qlafx00_abort_isp,
2527 .iospace_config = qlafx00_iospace_config,
2528 .initialize_adapter = qlafx00_initialize_adapter,
2531 static struct isp_operations qla27xx_isp_ops = {
2532 .pci_config = qla25xx_pci_config,
2533 .reset_chip = qla24xx_reset_chip,
2534 .chip_diag = qla24xx_chip_diag,
2535 .config_rings = qla24xx_config_rings,
2536 .reset_adapter = qla24xx_reset_adapter,
2537 .nvram_config = qla81xx_nvram_config,
2538 .update_fw_options = qla24xx_update_fw_options,
2539 .load_risc = qla81xx_load_risc,
2540 .pci_info_str = qla24xx_pci_info_str,
2541 .fw_version_str = qla24xx_fw_version_str,
2542 .intr_handler = qla24xx_intr_handler,
2543 .enable_intrs = qla24xx_enable_intrs,
2544 .disable_intrs = qla24xx_disable_intrs,
2545 .abort_command = qla24xx_abort_command,
2546 .target_reset = qla24xx_abort_target,
2547 .lun_reset = qla24xx_lun_reset,
2548 .fabric_login = qla24xx_login_fabric,
2549 .fabric_logout = qla24xx_fabric_logout,
2550 .calc_req_entries = NULL,
2551 .build_iocbs = NULL,
2552 .prep_ms_iocb = qla24xx_prep_ms_iocb,
2553 .prep_ms_fdmi_iocb = qla24xx_prep_ms_fdmi_iocb,
2555 .write_nvram = NULL,
2556 .fw_dump = qla27xx_fwdump,
2557 .mpi_fw_dump = qla27xx_mpi_fwdump,
2558 .beacon_on = qla24xx_beacon_on,
2559 .beacon_off = qla24xx_beacon_off,
2560 .beacon_blink = qla83xx_beacon_blink,
2561 .read_optrom = qla25xx_read_optrom_data,
2562 .write_optrom = qla24xx_write_optrom_data,
2563 .get_flash_version = qla24xx_get_flash_version,
2564 .start_scsi = qla24xx_dif_start_scsi,
2565 .start_scsi_mq = qla2xxx_dif_start_scsi_mq,
2566 .abort_isp = qla2x00_abort_isp,
2567 .iospace_config = qla83xx_iospace_config,
2568 .initialize_adapter = qla2x00_initialize_adapter,
2572 qla2x00_set_isp_flags(struct qla_hw_data *ha)
2574 ha->device_type = DT_EXTENDED_IDS;
2575 switch (ha->pdev->device) {
2576 case PCI_DEVICE_ID_QLOGIC_ISP2100:
2577 ha->isp_type |= DT_ISP2100;
2578 ha->device_type &= ~DT_EXTENDED_IDS;
2579 ha->fw_srisc_address = RISC_START_ADDRESS_2100;
2581 case PCI_DEVICE_ID_QLOGIC_ISP2200:
2582 ha->isp_type |= DT_ISP2200;
2583 ha->device_type &= ~DT_EXTENDED_IDS;
2584 ha->fw_srisc_address = RISC_START_ADDRESS_2100;
2586 case PCI_DEVICE_ID_QLOGIC_ISP2300:
2587 ha->isp_type |= DT_ISP2300;
2588 ha->device_type |= DT_ZIO_SUPPORTED;
2589 ha->fw_srisc_address = RISC_START_ADDRESS_2300;
2591 case PCI_DEVICE_ID_QLOGIC_ISP2312:
2592 ha->isp_type |= DT_ISP2312;
2593 ha->device_type |= DT_ZIO_SUPPORTED;
2594 ha->fw_srisc_address = RISC_START_ADDRESS_2300;
2596 case PCI_DEVICE_ID_QLOGIC_ISP2322:
2597 ha->isp_type |= DT_ISP2322;
2598 ha->device_type |= DT_ZIO_SUPPORTED;
2599 if (ha->pdev->subsystem_vendor == 0x1028 &&
2600 ha->pdev->subsystem_device == 0x0170)
2601 ha->device_type |= DT_OEM_001;
2602 ha->fw_srisc_address = RISC_START_ADDRESS_2300;
2604 case PCI_DEVICE_ID_QLOGIC_ISP6312:
2605 ha->isp_type |= DT_ISP6312;
2606 ha->fw_srisc_address = RISC_START_ADDRESS_2300;
2608 case PCI_DEVICE_ID_QLOGIC_ISP6322:
2609 ha->isp_type |= DT_ISP6322;
2610 ha->fw_srisc_address = RISC_START_ADDRESS_2300;
2612 case PCI_DEVICE_ID_QLOGIC_ISP2422:
2613 ha->isp_type |= DT_ISP2422;
2614 ha->device_type |= DT_ZIO_SUPPORTED;
2615 ha->device_type |= DT_FWI2;
2616 ha->device_type |= DT_IIDMA;
2617 ha->fw_srisc_address = RISC_START_ADDRESS_2400;
2619 case PCI_DEVICE_ID_QLOGIC_ISP2432:
2620 ha->isp_type |= DT_ISP2432;
2621 ha->device_type |= DT_ZIO_SUPPORTED;
2622 ha->device_type |= DT_FWI2;
2623 ha->device_type |= DT_IIDMA;
2624 ha->fw_srisc_address = RISC_START_ADDRESS_2400;
2626 case PCI_DEVICE_ID_QLOGIC_ISP8432:
2627 ha->isp_type |= DT_ISP8432;
2628 ha->device_type |= DT_ZIO_SUPPORTED;
2629 ha->device_type |= DT_FWI2;
2630 ha->device_type |= DT_IIDMA;
2631 ha->fw_srisc_address = RISC_START_ADDRESS_2400;
2633 case PCI_DEVICE_ID_QLOGIC_ISP5422:
2634 ha->isp_type |= DT_ISP5422;
2635 ha->device_type |= DT_FWI2;
2636 ha->fw_srisc_address = RISC_START_ADDRESS_2400;
2638 case PCI_DEVICE_ID_QLOGIC_ISP5432:
2639 ha->isp_type |= DT_ISP5432;
2640 ha->device_type |= DT_FWI2;
2641 ha->fw_srisc_address = RISC_START_ADDRESS_2400;
2643 case PCI_DEVICE_ID_QLOGIC_ISP2532:
2644 ha->isp_type |= DT_ISP2532;
2645 ha->device_type |= DT_ZIO_SUPPORTED;
2646 ha->device_type |= DT_FWI2;
2647 ha->device_type |= DT_IIDMA;
2648 ha->fw_srisc_address = RISC_START_ADDRESS_2400;
2650 case PCI_DEVICE_ID_QLOGIC_ISP8001:
2651 ha->isp_type |= DT_ISP8001;
2652 ha->device_type |= DT_ZIO_SUPPORTED;
2653 ha->device_type |= DT_FWI2;
2654 ha->device_type |= DT_IIDMA;
2655 ha->fw_srisc_address = RISC_START_ADDRESS_2400;
2657 case PCI_DEVICE_ID_QLOGIC_ISP8021:
2658 ha->isp_type |= DT_ISP8021;
2659 ha->device_type |= DT_ZIO_SUPPORTED;
2660 ha->device_type |= DT_FWI2;
2661 ha->fw_srisc_address = RISC_START_ADDRESS_2400;
2662 /* Initialize 82XX ISP flags */
2663 qla82xx_init_flags(ha);
2665 case PCI_DEVICE_ID_QLOGIC_ISP8044:
2666 ha->isp_type |= DT_ISP8044;
2667 ha->device_type |= DT_ZIO_SUPPORTED;
2668 ha->device_type |= DT_FWI2;
2669 ha->fw_srisc_address = RISC_START_ADDRESS_2400;
2670 /* Initialize 82XX ISP flags */
2671 qla82xx_init_flags(ha);
2673 case PCI_DEVICE_ID_QLOGIC_ISP2031:
2674 ha->isp_type |= DT_ISP2031;
2675 ha->device_type |= DT_ZIO_SUPPORTED;
2676 ha->device_type |= DT_FWI2;
2677 ha->device_type |= DT_IIDMA;
2678 ha->device_type |= DT_T10_PI;
2679 ha->fw_srisc_address = RISC_START_ADDRESS_2400;
2681 case PCI_DEVICE_ID_QLOGIC_ISP8031:
2682 ha->isp_type |= DT_ISP8031;
2683 ha->device_type |= DT_ZIO_SUPPORTED;
2684 ha->device_type |= DT_FWI2;
2685 ha->device_type |= DT_IIDMA;
2686 ha->device_type |= DT_T10_PI;
2687 ha->fw_srisc_address = RISC_START_ADDRESS_2400;
2689 case PCI_DEVICE_ID_QLOGIC_ISPF001:
2690 ha->isp_type |= DT_ISPFX00;
2692 case PCI_DEVICE_ID_QLOGIC_ISP2071:
2693 ha->isp_type |= DT_ISP2071;
2694 ha->device_type |= DT_ZIO_SUPPORTED;
2695 ha->device_type |= DT_FWI2;
2696 ha->device_type |= DT_IIDMA;
2697 ha->device_type |= DT_T10_PI;
2698 ha->fw_srisc_address = RISC_START_ADDRESS_2400;
2700 case PCI_DEVICE_ID_QLOGIC_ISP2271:
2701 ha->isp_type |= DT_ISP2271;
2702 ha->device_type |= DT_ZIO_SUPPORTED;
2703 ha->device_type |= DT_FWI2;
2704 ha->device_type |= DT_IIDMA;
2705 ha->device_type |= DT_T10_PI;
2706 ha->fw_srisc_address = RISC_START_ADDRESS_2400;
2708 case PCI_DEVICE_ID_QLOGIC_ISP2261:
2709 ha->isp_type |= DT_ISP2261;
2710 ha->device_type |= DT_ZIO_SUPPORTED;
2711 ha->device_type |= DT_FWI2;
2712 ha->device_type |= DT_IIDMA;
2713 ha->device_type |= DT_T10_PI;
2714 ha->fw_srisc_address = RISC_START_ADDRESS_2400;
2716 case PCI_DEVICE_ID_QLOGIC_ISP2081:
2717 case PCI_DEVICE_ID_QLOGIC_ISP2089:
2718 ha->isp_type |= DT_ISP2081;
2719 ha->device_type |= DT_ZIO_SUPPORTED;
2720 ha->device_type |= DT_FWI2;
2721 ha->device_type |= DT_IIDMA;
2722 ha->device_type |= DT_T10_PI;
2723 ha->fw_srisc_address = RISC_START_ADDRESS_2400;
2725 case PCI_DEVICE_ID_QLOGIC_ISP2281:
2726 case PCI_DEVICE_ID_QLOGIC_ISP2289:
2727 ha->isp_type |= DT_ISP2281;
2728 ha->device_type |= DT_ZIO_SUPPORTED;
2729 ha->device_type |= DT_FWI2;
2730 ha->device_type |= DT_IIDMA;
2731 ha->device_type |= DT_T10_PI;
2732 ha->fw_srisc_address = RISC_START_ADDRESS_2400;
2737 ha->port_no = ha->portnum & 1;
2739 /* Get adapter physical port no from interrupt pin register. */
2740 pci_read_config_byte(ha->pdev, PCI_INTERRUPT_PIN, &ha->port_no);
2741 if (IS_QLA25XX(ha) || IS_QLA2031(ha) ||
2742 IS_QLA27XX(ha) || IS_QLA28XX(ha))
2745 ha->port_no = !(ha->port_no & 1);
2748 ql_dbg_pci(ql_dbg_init, ha->pdev, 0x000b,
2749 "device_type=0x%x port=%d fw_srisc_address=0x%x.\n",
2750 ha->device_type, ha->port_no, ha->fw_srisc_address);
2754 qla2xxx_scan_start(struct Scsi_Host *shost)
2756 scsi_qla_host_t *vha = shost_priv(shost);
2758 if (vha->hw->flags.running_gold_fw)
2761 set_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags);
2762 set_bit(LOCAL_LOOP_UPDATE, &vha->dpc_flags);
2763 set_bit(RSCN_UPDATE, &vha->dpc_flags);
2764 set_bit(NPIV_CONFIG_NEEDED, &vha->dpc_flags);
2768 qla2xxx_scan_finished(struct Scsi_Host *shost, unsigned long time)
2770 scsi_qla_host_t *vha = shost_priv(shost);
2772 if (test_bit(UNLOADING, &vha->dpc_flags))
2776 if (time > vha->hw->loop_reset_delay * HZ)
2779 return atomic_read(&vha->loop_state) == LOOP_READY;
2782 static void qla_heartbeat_work_fn(struct work_struct *work)
2784 struct qla_hw_data *ha = container_of(work,
2785 struct qla_hw_data, heartbeat_work);
2786 struct scsi_qla_host *base_vha = pci_get_drvdata(ha->pdev);
2788 if (!ha->flags.mbox_busy && base_vha->flags.init_done)
2789 qla_no_op_mb(base_vha);
2792 static void qla2x00_iocb_work_fn(struct work_struct *work)
2794 struct scsi_qla_host *vha = container_of(work,
2795 struct scsi_qla_host, iocb_work);
2796 struct qla_hw_data *ha = vha->hw;
2797 struct scsi_qla_host *base_vha = pci_get_drvdata(ha->pdev);
2799 unsigned long flags;
2801 if (test_bit(UNLOADING, &base_vha->dpc_flags))
2804 while (!list_empty(&vha->work_list) && i > 0) {
2805 qla2x00_do_work(vha);
2809 spin_lock_irqsave(&vha->work_lock, flags);
2810 clear_bit(IOCB_WORK_ACTIVE, &vha->dpc_flags);
2811 spin_unlock_irqrestore(&vha->work_lock, flags);
2815 * PCI driver interface
2818 qla2x00_probe_one(struct pci_dev *pdev, const struct pci_device_id *id)
2821 struct Scsi_Host *host;
2822 scsi_qla_host_t *base_vha = NULL;
2823 struct qla_hw_data *ha;
2825 char fw_str[30], wq_name[30];
2826 struct scsi_host_template *sht;
2827 int bars, mem_only = 0;
2828 uint16_t req_length = 0, rsp_length = 0;
2829 struct req_que *req = NULL;
2830 struct rsp_que *rsp = NULL;
2833 bars = pci_select_bars(pdev, IORESOURCE_MEM | IORESOURCE_IO);
2834 sht = &qla2xxx_driver_template;
2835 if (pdev->device == PCI_DEVICE_ID_QLOGIC_ISP2422 ||
2836 pdev->device == PCI_DEVICE_ID_QLOGIC_ISP2432 ||
2837 pdev->device == PCI_DEVICE_ID_QLOGIC_ISP8432 ||
2838 pdev->device == PCI_DEVICE_ID_QLOGIC_ISP5422 ||
2839 pdev->device == PCI_DEVICE_ID_QLOGIC_ISP5432 ||
2840 pdev->device == PCI_DEVICE_ID_QLOGIC_ISP2532 ||
2841 pdev->device == PCI_DEVICE_ID_QLOGIC_ISP8001 ||
2842 pdev->device == PCI_DEVICE_ID_QLOGIC_ISP8021 ||
2843 pdev->device == PCI_DEVICE_ID_QLOGIC_ISP2031 ||
2844 pdev->device == PCI_DEVICE_ID_QLOGIC_ISP8031 ||
2845 pdev->device == PCI_DEVICE_ID_QLOGIC_ISPF001 ||
2846 pdev->device == PCI_DEVICE_ID_QLOGIC_ISP8044 ||
2847 pdev->device == PCI_DEVICE_ID_QLOGIC_ISP2071 ||
2848 pdev->device == PCI_DEVICE_ID_QLOGIC_ISP2271 ||
2849 pdev->device == PCI_DEVICE_ID_QLOGIC_ISP2261 ||
2850 pdev->device == PCI_DEVICE_ID_QLOGIC_ISP2081 ||
2851 pdev->device == PCI_DEVICE_ID_QLOGIC_ISP2281 ||
2852 pdev->device == PCI_DEVICE_ID_QLOGIC_ISP2089 ||
2853 pdev->device == PCI_DEVICE_ID_QLOGIC_ISP2289) {
2854 bars = pci_select_bars(pdev, IORESOURCE_MEM);
2856 ql_dbg_pci(ql_dbg_init, pdev, 0x0007,
2857 "Mem only adapter.\n");
2859 ql_dbg_pci(ql_dbg_init, pdev, 0x0008,
2860 "Bars=%d.\n", bars);
2863 if (pci_enable_device_mem(pdev))
2866 if (pci_enable_device(pdev))
2870 if (is_kdump_kernel()) {
2872 ql2xallocfwdump = 0;
2875 /* This may fail but that's ok */
2876 pci_enable_pcie_error_reporting(pdev);
2878 ha = kzalloc(sizeof(struct qla_hw_data), GFP_KERNEL);
2880 ql_log_pci(ql_log_fatal, pdev, 0x0009,
2881 "Unable to allocate memory for ha.\n");
2882 goto disable_device;
2884 ql_dbg_pci(ql_dbg_init, pdev, 0x000a,
2885 "Memory allocated for ha=%p.\n", ha);
2887 INIT_LIST_HEAD(&ha->tgt.q_full_list);
2888 spin_lock_init(&ha->tgt.q_full_lock);
2889 spin_lock_init(&ha->tgt.sess_lock);
2890 spin_lock_init(&ha->tgt.atio_lock);
2892 spin_lock_init(&ha->sadb_lock);
2893 INIT_LIST_HEAD(&ha->sadb_tx_index_list);
2894 INIT_LIST_HEAD(&ha->sadb_rx_index_list);
2896 spin_lock_init(&ha->sadb_fp_lock);
2898 if (qla_edif_sadb_build_free_pool(ha)) {
2900 goto disable_device;
2903 atomic_set(&ha->nvme_active_aen_cnt, 0);
2905 /* Clear our data area */
2907 ha->mem_only = mem_only;
2908 spin_lock_init(&ha->hardware_lock);
2909 spin_lock_init(&ha->vport_slock);
2910 mutex_init(&ha->selflogin_lock);
2911 mutex_init(&ha->optrom_mutex);
2913 /* Set ISP-type information. */
2914 qla2x00_set_isp_flags(ha);
2916 /* Set EEH reset type to fundamental if required by hba */
2917 if (IS_QLA24XX(ha) || IS_QLA25XX(ha) || IS_QLA81XX(ha) ||
2918 IS_QLA83XX(ha) || IS_QLA27XX(ha) || IS_QLA28XX(ha))
2919 pdev->needs_freset = 1;
2921 ha->prev_topology = 0;
2922 ha->init_cb_size = sizeof(init_cb_t);
2923 ha->link_data_rate = PORT_SPEED_UNKNOWN;
2924 ha->optrom_size = OPTROM_SIZE_2300;
2925 ha->max_exchg = FW_MAX_EXCHANGES_CNT;
2926 atomic_set(&ha->num_pend_mbx_stage1, 0);
2927 atomic_set(&ha->num_pend_mbx_stage2, 0);
2928 atomic_set(&ha->num_pend_mbx_stage3, 0);
2929 atomic_set(&ha->zio_threshold, DEFAULT_ZIO_THRESHOLD);
2930 ha->last_zio_threshold = DEFAULT_ZIO_THRESHOLD;
2932 /* Assign ISP specific operations. */
2933 if (IS_QLA2100(ha)) {
2934 ha->max_fibre_devices = MAX_FIBRE_DEVICES_2100;
2935 ha->mbx_count = MAILBOX_REGISTER_COUNT_2100;
2936 req_length = REQUEST_ENTRY_CNT_2100;
2937 rsp_length = RESPONSE_ENTRY_CNT_2100;
2938 ha->max_loop_id = SNS_LAST_LOOP_ID_2100;
2939 ha->gid_list_info_size = 4;
2940 ha->flash_conf_off = ~0;
2941 ha->flash_data_off = ~0;
2942 ha->nvram_conf_off = ~0;
2943 ha->nvram_data_off = ~0;
2944 ha->isp_ops = &qla2100_isp_ops;
2945 } else if (IS_QLA2200(ha)) {
2946 ha->max_fibre_devices = MAX_FIBRE_DEVICES_2100;
2947 ha->mbx_count = MAILBOX_REGISTER_COUNT_2200;
2948 req_length = REQUEST_ENTRY_CNT_2200;
2949 rsp_length = RESPONSE_ENTRY_CNT_2100;
2950 ha->max_loop_id = SNS_LAST_LOOP_ID_2100;
2951 ha->gid_list_info_size = 4;
2952 ha->flash_conf_off = ~0;
2953 ha->flash_data_off = ~0;
2954 ha->nvram_conf_off = ~0;
2955 ha->nvram_data_off = ~0;
2956 ha->isp_ops = &qla2100_isp_ops;
2957 } else if (IS_QLA23XX(ha)) {
2958 ha->max_fibre_devices = MAX_FIBRE_DEVICES_2100;
2959 ha->mbx_count = MAILBOX_REGISTER_COUNT;
2960 req_length = REQUEST_ENTRY_CNT_2200;
2961 rsp_length = RESPONSE_ENTRY_CNT_2300;
2962 ha->max_loop_id = SNS_LAST_LOOP_ID_2300;
2963 ha->gid_list_info_size = 6;
2964 if (IS_QLA2322(ha) || IS_QLA6322(ha))
2965 ha->optrom_size = OPTROM_SIZE_2322;
2966 ha->flash_conf_off = ~0;
2967 ha->flash_data_off = ~0;
2968 ha->nvram_conf_off = ~0;
2969 ha->nvram_data_off = ~0;
2970 ha->isp_ops = &qla2300_isp_ops;
2971 } else if (IS_QLA24XX_TYPE(ha)) {
2972 ha->max_fibre_devices = MAX_FIBRE_DEVICES_2400;
2973 ha->mbx_count = MAILBOX_REGISTER_COUNT;
2974 req_length = REQUEST_ENTRY_CNT_24XX;
2975 rsp_length = RESPONSE_ENTRY_CNT_2300;
2976 ha->tgt.atio_q_length = ATIO_ENTRY_CNT_24XX;
2977 ha->max_loop_id = SNS_LAST_LOOP_ID_2300;
2978 ha->init_cb_size = sizeof(struct mid_init_cb_24xx);
2979 ha->gid_list_info_size = 8;
2980 ha->optrom_size = OPTROM_SIZE_24XX;
2981 ha->nvram_npiv_size = QLA_MAX_VPORTS_QLA24XX;
2982 ha->isp_ops = &qla24xx_isp_ops;
2983 ha->flash_conf_off = FARX_ACCESS_FLASH_CONF;
2984 ha->flash_data_off = FARX_ACCESS_FLASH_DATA;
2985 ha->nvram_conf_off = FARX_ACCESS_NVRAM_CONF;
2986 ha->nvram_data_off = FARX_ACCESS_NVRAM_DATA;
2987 } else if (IS_QLA25XX(ha)) {
2988 ha->max_fibre_devices = MAX_FIBRE_DEVICES_2400;
2989 ha->mbx_count = MAILBOX_REGISTER_COUNT;
2990 req_length = REQUEST_ENTRY_CNT_24XX;
2991 rsp_length = RESPONSE_ENTRY_CNT_2300;
2992 ha->tgt.atio_q_length = ATIO_ENTRY_CNT_24XX;
2993 ha->max_loop_id = SNS_LAST_LOOP_ID_2300;
2994 ha->init_cb_size = sizeof(struct mid_init_cb_24xx);
2995 ha->gid_list_info_size = 8;
2996 ha->optrom_size = OPTROM_SIZE_25XX;
2997 ha->nvram_npiv_size = QLA_MAX_VPORTS_QLA25XX;
2998 ha->isp_ops = &qla25xx_isp_ops;
2999 ha->flash_conf_off = FARX_ACCESS_FLASH_CONF;
3000 ha->flash_data_off = FARX_ACCESS_FLASH_DATA;
3001 ha->nvram_conf_off = FARX_ACCESS_NVRAM_CONF;
3002 ha->nvram_data_off = FARX_ACCESS_NVRAM_DATA;
3003 } else if (IS_QLA81XX(ha)) {
3004 ha->max_fibre_devices = MAX_FIBRE_DEVICES_2400;
3005 ha->mbx_count = MAILBOX_REGISTER_COUNT;
3006 req_length = REQUEST_ENTRY_CNT_24XX;
3007 rsp_length = RESPONSE_ENTRY_CNT_2300;
3008 ha->tgt.atio_q_length = ATIO_ENTRY_CNT_24XX;
3009 ha->max_loop_id = SNS_LAST_LOOP_ID_2300;
3010 ha->init_cb_size = sizeof(struct mid_init_cb_81xx);
3011 ha->gid_list_info_size = 8;
3012 ha->optrom_size = OPTROM_SIZE_81XX;
3013 ha->nvram_npiv_size = QLA_MAX_VPORTS_QLA25XX;
3014 ha->isp_ops = &qla81xx_isp_ops;
3015 ha->flash_conf_off = FARX_ACCESS_FLASH_CONF_81XX;
3016 ha->flash_data_off = FARX_ACCESS_FLASH_DATA_81XX;
3017 ha->nvram_conf_off = ~0;
3018 ha->nvram_data_off = ~0;
3019 } else if (IS_QLA82XX(ha)) {
3020 ha->max_fibre_devices = MAX_FIBRE_DEVICES_2400;
3021 ha->mbx_count = MAILBOX_REGISTER_COUNT;
3022 req_length = REQUEST_ENTRY_CNT_82XX;
3023 rsp_length = RESPONSE_ENTRY_CNT_82XX;
3024 ha->max_loop_id = SNS_LAST_LOOP_ID_2300;
3025 ha->init_cb_size = sizeof(struct mid_init_cb_81xx);
3026 ha->gid_list_info_size = 8;
3027 ha->optrom_size = OPTROM_SIZE_82XX;
3028 ha->nvram_npiv_size = QLA_MAX_VPORTS_QLA25XX;
3029 ha->isp_ops = &qla82xx_isp_ops;
3030 ha->flash_conf_off = FARX_ACCESS_FLASH_CONF;
3031 ha->flash_data_off = FARX_ACCESS_FLASH_DATA;
3032 ha->nvram_conf_off = FARX_ACCESS_NVRAM_CONF;
3033 ha->nvram_data_off = FARX_ACCESS_NVRAM_DATA;
3034 } else if (IS_QLA8044(ha)) {
3035 ha->max_fibre_devices = MAX_FIBRE_DEVICES_2400;
3036 ha->mbx_count = MAILBOX_REGISTER_COUNT;
3037 req_length = REQUEST_ENTRY_CNT_82XX;
3038 rsp_length = RESPONSE_ENTRY_CNT_82XX;
3039 ha->max_loop_id = SNS_LAST_LOOP_ID_2300;
3040 ha->init_cb_size = sizeof(struct mid_init_cb_81xx);
3041 ha->gid_list_info_size = 8;
3042 ha->optrom_size = OPTROM_SIZE_83XX;
3043 ha->nvram_npiv_size = QLA_MAX_VPORTS_QLA25XX;
3044 ha->isp_ops = &qla8044_isp_ops;
3045 ha->flash_conf_off = FARX_ACCESS_FLASH_CONF;
3046 ha->flash_data_off = FARX_ACCESS_FLASH_DATA;
3047 ha->nvram_conf_off = FARX_ACCESS_NVRAM_CONF;
3048 ha->nvram_data_off = FARX_ACCESS_NVRAM_DATA;
3049 } else if (IS_QLA83XX(ha)) {
3050 ha->portnum = PCI_FUNC(ha->pdev->devfn);
3051 ha->max_fibre_devices = MAX_FIBRE_DEVICES_2400;
3052 ha->mbx_count = MAILBOX_REGISTER_COUNT;
3053 req_length = REQUEST_ENTRY_CNT_83XX;
3054 rsp_length = RESPONSE_ENTRY_CNT_83XX;
3055 ha->tgt.atio_q_length = ATIO_ENTRY_CNT_24XX;
3056 ha->max_loop_id = SNS_LAST_LOOP_ID_2300;
3057 ha->init_cb_size = sizeof(struct mid_init_cb_81xx);
3058 ha->gid_list_info_size = 8;
3059 ha->optrom_size = OPTROM_SIZE_83XX;
3060 ha->nvram_npiv_size = QLA_MAX_VPORTS_QLA25XX;
3061 ha->isp_ops = &qla83xx_isp_ops;
3062 ha->flash_conf_off = FARX_ACCESS_FLASH_CONF_81XX;
3063 ha->flash_data_off = FARX_ACCESS_FLASH_DATA_81XX;
3064 ha->nvram_conf_off = ~0;
3065 ha->nvram_data_off = ~0;
3066 } else if (IS_QLAFX00(ha)) {
3067 ha->max_fibre_devices = MAX_FIBRE_DEVICES_FX00;
3068 ha->mbx_count = MAILBOX_REGISTER_COUNT_FX00;
3069 ha->aen_mbx_count = AEN_MAILBOX_REGISTER_COUNT_FX00;
3070 req_length = REQUEST_ENTRY_CNT_FX00;
3071 rsp_length = RESPONSE_ENTRY_CNT_FX00;
3072 ha->isp_ops = &qlafx00_isp_ops;
3073 ha->port_down_retry_count = 30; /* default value */
3074 ha->mr.fw_hbt_cnt = QLAFX00_HEARTBEAT_INTERVAL;
3075 ha->mr.fw_reset_timer_tick = QLAFX00_RESET_INTERVAL;
3076 ha->mr.fw_critemp_timer_tick = QLAFX00_CRITEMP_INTERVAL;
3077 ha->mr.fw_hbt_en = 1;
3078 ha->mr.host_info_resend = false;
3079 ha->mr.hinfo_resend_timer_tick = QLAFX00_HINFO_RESEND_INTERVAL;
3080 } else if (IS_QLA27XX(ha)) {
3081 ha->portnum = PCI_FUNC(ha->pdev->devfn);
3082 ha->max_fibre_devices = MAX_FIBRE_DEVICES_2400;
3083 ha->mbx_count = MAILBOX_REGISTER_COUNT;
3084 req_length = REQUEST_ENTRY_CNT_83XX;
3085 rsp_length = RESPONSE_ENTRY_CNT_83XX;
3086 ha->tgt.atio_q_length = ATIO_ENTRY_CNT_24XX;
3087 ha->max_loop_id = SNS_LAST_LOOP_ID_2300;
3088 ha->init_cb_size = sizeof(struct mid_init_cb_81xx);
3089 ha->gid_list_info_size = 8;
3090 ha->optrom_size = OPTROM_SIZE_83XX;
3091 ha->nvram_npiv_size = QLA_MAX_VPORTS_QLA25XX;
3092 ha->isp_ops = &qla27xx_isp_ops;
3093 ha->flash_conf_off = FARX_ACCESS_FLASH_CONF_81XX;
3094 ha->flash_data_off = FARX_ACCESS_FLASH_DATA_81XX;
3095 ha->nvram_conf_off = ~0;
3096 ha->nvram_data_off = ~0;
3097 } else if (IS_QLA28XX(ha)) {
3098 ha->portnum = PCI_FUNC(ha->pdev->devfn);
3099 ha->max_fibre_devices = MAX_FIBRE_DEVICES_2400;
3100 ha->mbx_count = MAILBOX_REGISTER_COUNT;
3101 req_length = REQUEST_ENTRY_CNT_83XX;
3102 rsp_length = RESPONSE_ENTRY_CNT_83XX;
3103 ha->tgt.atio_q_length = ATIO_ENTRY_CNT_24XX;
3104 ha->max_loop_id = SNS_LAST_LOOP_ID_2300;
3105 ha->init_cb_size = sizeof(struct mid_init_cb_81xx);
3106 ha->gid_list_info_size = 8;
3107 ha->optrom_size = OPTROM_SIZE_28XX;
3108 ha->nvram_npiv_size = QLA_MAX_VPORTS_QLA25XX;
3109 ha->isp_ops = &qla27xx_isp_ops;
3110 ha->flash_conf_off = FARX_ACCESS_FLASH_CONF_28XX;
3111 ha->flash_data_off = FARX_ACCESS_FLASH_DATA_28XX;
3112 ha->nvram_conf_off = ~0;
3113 ha->nvram_data_off = ~0;
3116 ql_dbg_pci(ql_dbg_init, pdev, 0x001e,
3117 "mbx_count=%d, req_length=%d, "
3118 "rsp_length=%d, max_loop_id=%d, init_cb_size=%d, "
3119 "gid_list_info_size=%d, optrom_size=%d, nvram_npiv_size=%d, "
3120 "max_fibre_devices=%d.\n",
3121 ha->mbx_count, req_length, rsp_length, ha->max_loop_id,
3122 ha->init_cb_size, ha->gid_list_info_size, ha->optrom_size,
3123 ha->nvram_npiv_size, ha->max_fibre_devices);
3124 ql_dbg_pci(ql_dbg_init, pdev, 0x001f,
3125 "isp_ops=%p, flash_conf_off=%d, "
3126 "flash_data_off=%d, nvram_conf_off=%d, nvram_data_off=%d.\n",
3127 ha->isp_ops, ha->flash_conf_off, ha->flash_data_off,
3128 ha->nvram_conf_off, ha->nvram_data_off);
3130 /* Configure PCI I/O space */
3131 ret = ha->isp_ops->iospace_config(ha);
3133 goto iospace_config_failed;
3135 ql_log_pci(ql_log_info, pdev, 0x001d,
3136 "Found an ISP%04X irq %d iobase 0x%p.\n",
3137 pdev->device, pdev->irq, ha->iobase);
3138 mutex_init(&ha->vport_lock);
3139 mutex_init(&ha->mq_lock);
3140 init_completion(&ha->mbx_cmd_comp);
3141 complete(&ha->mbx_cmd_comp);
3142 init_completion(&ha->mbx_intr_comp);
3143 init_completion(&ha->dcbx_comp);
3144 init_completion(&ha->lb_portup_comp);
3146 set_bit(0, (unsigned long *) ha->vp_idx_map);
3148 qla2x00_config_dma_addressing(ha);
3149 ql_dbg_pci(ql_dbg_init, pdev, 0x0020,
3150 "64 Bit addressing is %s.\n",
3151 ha->flags.enable_64bit_addressing ? "enable" :
3153 ret = qla2x00_mem_alloc(ha, req_length, rsp_length, &req, &rsp);
3155 ql_log_pci(ql_log_fatal, pdev, 0x0031,
3156 "Failed to allocate memory for adapter, aborting.\n");
3158 goto probe_hw_failed;
3161 req->max_q_depth = MAX_Q_DEPTH;
3162 if (ql2xmaxqdepth != 0 && ql2xmaxqdepth <= 0xffffU)
3163 req->max_q_depth = ql2xmaxqdepth;
3166 base_vha = qla2x00_create_host(sht, ha);
3169 goto probe_hw_failed;
3172 pci_set_drvdata(pdev, base_vha);
3173 set_bit(PFLG_DRIVER_PROBING, &base_vha->pci_flags);
3175 host = base_vha->host;
3176 base_vha->req = req;
3177 if (IS_QLA2XXX_MIDTYPE(ha))
3178 base_vha->mgmt_svr_loop_id =
3179 qla2x00_reserve_mgmt_server_loop_id(base_vha);
3181 base_vha->mgmt_svr_loop_id = MANAGEMENT_SERVER +
3184 /* Setup fcport template structure. */
3185 ha->mr.fcport.vha = base_vha;
3186 ha->mr.fcport.port_type = FCT_UNKNOWN;
3187 ha->mr.fcport.loop_id = FC_NO_LOOP_ID;
3188 qla2x00_set_fcport_state(&ha->mr.fcport, FCS_UNCONFIGURED);
3189 ha->mr.fcport.supported_classes = FC_COS_UNSPECIFIED;
3190 ha->mr.fcport.scan_state = 1;
3192 qla2xxx_reset_stats(host, QLA2XX_HW_ERROR | QLA2XX_SHT_LNK_DWN |
3193 QLA2XX_INT_ERR | QLA2XX_CMD_TIMEOUT |
3194 QLA2XX_RESET_CMD_ERR | QLA2XX_TGT_SHT_LNK_DOWN);
3196 /* Set the SG table size based on ISP type */
3197 if (!IS_FWI2_CAPABLE(ha)) {
3199 host->sg_tablesize = 32;
3201 if (!IS_QLA82XX(ha))
3202 host->sg_tablesize = QLA_SG_ALL;
3204 host->max_id = ha->max_fibre_devices;
3205 host->cmd_per_lun = 3;
3206 host->unique_id = host->host_no;
3207 if (IS_T10_PI_CAPABLE(ha) && ql2xenabledif)
3208 host->max_cmd_len = 32;
3210 host->max_cmd_len = MAX_CMDSZ;
3211 host->max_channel = MAX_BUSES - 1;
3212 /* Older HBAs support only 16-bit LUNs */
3213 if (!IS_QLAFX00(ha) && !IS_FWI2_CAPABLE(ha) &&
3214 ql2xmaxlun > 0xffff)
3215 host->max_lun = 0xffff;
3217 host->max_lun = ql2xmaxlun;
3218 host->transportt = qla2xxx_transport_template;
3219 sht->vendor_id = (SCSI_NL_VID_TYPE_PCI | PCI_VENDOR_ID_QLOGIC);
3221 ql_dbg(ql_dbg_init, base_vha, 0x0033,
3222 "max_id=%d this_id=%d "
3223 "cmd_per_len=%d unique_id=%d max_cmd_len=%d max_channel=%d "
3224 "max_lun=%llu transportt=%p, vendor_id=%llu.\n", host->max_id,
3225 host->this_id, host->cmd_per_lun, host->unique_id,
3226 host->max_cmd_len, host->max_channel, host->max_lun,
3227 host->transportt, sht->vendor_id);
3229 INIT_WORK(&base_vha->iocb_work, qla2x00_iocb_work_fn);
3230 INIT_WORK(&ha->heartbeat_work, qla_heartbeat_work_fn);
3232 /* Set up the irqs */
3233 ret = qla2x00_request_irqs(ha, rsp);
3237 /* Alloc arrays of request and response ring ptrs */
3238 ret = qla2x00_alloc_queues(ha, req, rsp);
3240 ql_log(ql_log_fatal, base_vha, 0x003d,
3241 "Failed to allocate memory for queue pointers..."
3248 /* number of hardware queues supported by blk/scsi-mq*/
3249 host->nr_hw_queues = ha->max_qpairs;
3251 ql_dbg(ql_dbg_init, base_vha, 0x0192,
3252 "blk/scsi-mq enabled, HW queues = %d.\n", host->nr_hw_queues);
3254 if (ql2xnvmeenable) {
3255 host->nr_hw_queues = ha->max_qpairs;
3256 ql_dbg(ql_dbg_init, base_vha, 0x0194,
3257 "FC-NVMe support is enabled, HW queues=%d\n",
3258 host->nr_hw_queues);
3260 ql_dbg(ql_dbg_init, base_vha, 0x0193,
3261 "blk/scsi-mq disabled.\n");
3265 qlt_probe_one_stage1(base_vha, ha);
3267 pci_save_state(pdev);
3269 /* Assign back pointers */
3273 if (IS_QLAFX00(ha)) {
3274 ha->rsp_q_map[0] = rsp;
3275 ha->req_q_map[0] = req;
3276 set_bit(0, ha->req_qid_map);
3277 set_bit(0, ha->rsp_qid_map);
3280 /* FWI2-capable only. */
3281 req->req_q_in = &ha->iobase->isp24.req_q_in;
3282 req->req_q_out = &ha->iobase->isp24.req_q_out;
3283 rsp->rsp_q_in = &ha->iobase->isp24.rsp_q_in;
3284 rsp->rsp_q_out = &ha->iobase->isp24.rsp_q_out;
3285 if (ha->mqenable || IS_QLA83XX(ha) || IS_QLA27XX(ha) ||
3287 req->req_q_in = &ha->mqiobase->isp25mq.req_q_in;
3288 req->req_q_out = &ha->mqiobase->isp25mq.req_q_out;
3289 rsp->rsp_q_in = &ha->mqiobase->isp25mq.rsp_q_in;
3290 rsp->rsp_q_out = &ha->mqiobase->isp25mq.rsp_q_out;
3293 if (IS_QLAFX00(ha)) {
3294 req->req_q_in = &ha->iobase->ispfx00.req_q_in;
3295 req->req_q_out = &ha->iobase->ispfx00.req_q_out;
3296 rsp->rsp_q_in = &ha->iobase->ispfx00.rsp_q_in;
3297 rsp->rsp_q_out = &ha->iobase->ispfx00.rsp_q_out;
3300 if (IS_P3P_TYPE(ha)) {
3301 req->req_q_out = &ha->iobase->isp82.req_q_out[0];
3302 rsp->rsp_q_in = &ha->iobase->isp82.rsp_q_in[0];
3303 rsp->rsp_q_out = &ha->iobase->isp82.rsp_q_out[0];
3306 ql_dbg(ql_dbg_multiq, base_vha, 0xc009,
3307 "rsp_q_map=%p req_q_map=%p rsp->req=%p req->rsp=%p.\n",
3308 ha->rsp_q_map, ha->req_q_map, rsp->req, req->rsp);
3309 ql_dbg(ql_dbg_multiq, base_vha, 0xc00a,
3310 "req->req_q_in=%p req->req_q_out=%p "
3311 "rsp->rsp_q_in=%p rsp->rsp_q_out=%p.\n",
3312 req->req_q_in, req->req_q_out,
3313 rsp->rsp_q_in, rsp->rsp_q_out);
3314 ql_dbg(ql_dbg_init, base_vha, 0x003e,
3315 "rsp_q_map=%p req_q_map=%p rsp->req=%p req->rsp=%p.\n",
3316 ha->rsp_q_map, ha->req_q_map, rsp->req, req->rsp);
3317 ql_dbg(ql_dbg_init, base_vha, 0x003f,
3318 "req->req_q_in=%p req->req_q_out=%p rsp->rsp_q_in=%p rsp->rsp_q_out=%p.\n",
3319 req->req_q_in, req->req_q_out, rsp->rsp_q_in, rsp->rsp_q_out);
3321 ha->wq = alloc_workqueue("qla2xxx_wq", WQ_MEM_RECLAIM, 0);
3322 if (unlikely(!ha->wq)) {
3327 if (ha->isp_ops->initialize_adapter(base_vha)) {
3328 ql_log(ql_log_fatal, base_vha, 0x00d6,
3329 "Failed to initialize adapter - Adapter flags %x.\n",
3330 base_vha->device_flags);
3332 if (IS_QLA82XX(ha)) {
3333 qla82xx_idc_lock(ha);
3334 qla82xx_wr_32(ha, QLA82XX_CRB_DEV_STATE,
3335 QLA8XXX_DEV_FAILED);
3336 qla82xx_idc_unlock(ha);
3337 ql_log(ql_log_fatal, base_vha, 0x00d7,
3338 "HW State: FAILED.\n");
3339 } else if (IS_QLA8044(ha)) {
3340 qla8044_idc_lock(ha);
3341 qla8044_wr_direct(base_vha,
3342 QLA8044_CRB_DEV_STATE_INDEX,
3343 QLA8XXX_DEV_FAILED);
3344 qla8044_idc_unlock(ha);
3345 ql_log(ql_log_fatal, base_vha, 0x0150,
3346 "HW State: FAILED.\n");
3354 host->can_queue = QLAFX00_MAX_CANQUEUE;
3356 host->can_queue = req->num_outstanding_cmds - 10;
3358 ql_dbg(ql_dbg_init, base_vha, 0x0032,
3359 "can_queue=%d, req=%p, mgmt_svr_loop_id=%d, sg_tablesize=%d.\n",
3360 host->can_queue, base_vha->req,
3361 base_vha->mgmt_svr_loop_id, host->sg_tablesize);
3364 bool startit = false;
3366 if (QLA_TGT_MODE_ENABLED())
3369 if (ql2x_ini_mode == QLA2XXX_INI_MODE_ENABLED)
3372 /* Create start of day qpairs for Block MQ */
3373 for (i = 0; i < ha->max_qpairs; i++)
3374 qla2xxx_create_qpair(base_vha, 5, 0, startit);
3376 qla_init_iocb_limit(base_vha);
3378 if (ha->flags.running_gold_fw)
3382 * Startup the kernel thread for this host adapter
3384 ha->dpc_thread = kthread_create(qla2x00_do_dpc, ha,
3385 "%s_dpc", base_vha->host_str);
3386 if (IS_ERR(ha->dpc_thread)) {
3387 ql_log(ql_log_fatal, base_vha, 0x00ed,
3388 "Failed to start DPC thread.\n");
3389 ret = PTR_ERR(ha->dpc_thread);
3390 ha->dpc_thread = NULL;
3393 ql_dbg(ql_dbg_init, base_vha, 0x00ee,
3394 "DPC thread started successfully.\n");
3397 * If we're not coming up in initiator mode, we might sit for
3398 * a while without waking up the dpc thread, which leads to a
3399 * stuck process warning. So just kick the dpc once here and
3400 * let the kthread start (and go back to sleep in qla2x00_do_dpc).
3402 qla2xxx_wake_dpc(base_vha);
3404 INIT_WORK(&ha->board_disable, qla2x00_disable_board_on_pci_error);
3406 if (IS_QLA8031(ha) || IS_MCTP_CAPABLE(ha)) {
3407 sprintf(wq_name, "qla2xxx_%lu_dpc_lp_wq", base_vha->host_no);
3408 ha->dpc_lp_wq = create_singlethread_workqueue(wq_name);
3409 INIT_WORK(&ha->idc_aen, qla83xx_service_idc_aen);
3411 sprintf(wq_name, "qla2xxx_%lu_dpc_hp_wq", base_vha->host_no);
3412 ha->dpc_hp_wq = create_singlethread_workqueue(wq_name);
3413 INIT_WORK(&ha->nic_core_reset, qla83xx_nic_core_reset_work);
3414 INIT_WORK(&ha->idc_state_handler,
3415 qla83xx_idc_state_handler_work);
3416 INIT_WORK(&ha->nic_core_unrecoverable,
3417 qla83xx_nic_core_unrecoverable_work);
3421 list_add_tail(&base_vha->list, &ha->vp_list);
3422 base_vha->host->irq = ha->pdev->irq;
3424 /* Initialized the timer */
3425 qla2x00_start_timer(base_vha, WATCH_INTERVAL);
3426 ql_dbg(ql_dbg_init, base_vha, 0x00ef,
3427 "Started qla2x00_timer with "
3428 "interval=%d.\n", WATCH_INTERVAL);
3429 ql_dbg(ql_dbg_init, base_vha, 0x00f0,
3430 "Detected hba at address=%p.\n",
3433 if (IS_T10_PI_CAPABLE(ha) && ql2xenabledif) {
3434 if (ha->fw_attributes & BIT_4) {
3435 int prot = 0, guard;
3437 base_vha->flags.difdix_supported = 1;
3438 ql_dbg(ql_dbg_init, base_vha, 0x00f1,
3439 "Registering for DIF/DIX type 1 and 3 protection.\n");
3440 if (ql2xenabledif == 1)
3441 prot = SHOST_DIX_TYPE0_PROTECTION;
3443 scsi_host_set_prot(host, ql2xprotmask);
3445 scsi_host_set_prot(host,
3446 prot | SHOST_DIF_TYPE1_PROTECTION
3447 | SHOST_DIF_TYPE2_PROTECTION
3448 | SHOST_DIF_TYPE3_PROTECTION
3449 | SHOST_DIX_TYPE1_PROTECTION
3450 | SHOST_DIX_TYPE2_PROTECTION
3451 | SHOST_DIX_TYPE3_PROTECTION);
3453 guard = SHOST_DIX_GUARD_CRC;
3455 if (IS_PI_IPGUARD_CAPABLE(ha) &&
3456 (ql2xenabledif > 1 || IS_PI_DIFB_DIX0_CAPABLE(ha)))
3457 guard |= SHOST_DIX_GUARD_IP;
3460 scsi_host_set_guard(host, ql2xprotguard);
3462 scsi_host_set_guard(host, guard);
3464 base_vha->flags.difdix_supported = 0;
3467 ha->isp_ops->enable_intrs(ha);
3469 if (IS_QLAFX00(ha)) {
3470 ret = qlafx00_fx_disc(base_vha,
3471 &base_vha->hw->mr.fcport, FXDISC_GET_CONFIG_INFO);
3472 host->sg_tablesize = (ha->mr.extended_io_enabled) ?
3476 ret = scsi_add_host(host, &pdev->dev);
3480 base_vha->flags.init_done = 1;
3481 base_vha->flags.online = 1;
3482 ha->prev_minidump_failed = 0;
3484 ql_dbg(ql_dbg_init, base_vha, 0x00f2,
3485 "Init done and hba is online.\n");
3487 if (qla_ini_mode_enabled(base_vha) ||
3488 qla_dual_mode_enabled(base_vha))
3489 scsi_scan_host(host);
3491 ql_dbg(ql_dbg_init, base_vha, 0x0122,
3492 "skipping scsi_scan_host() for non-initiator port\n");
3494 qla2x00_alloc_sysfs_attr(base_vha);
3496 if (IS_QLAFX00(ha)) {
3497 ret = qlafx00_fx_disc(base_vha,
3498 &base_vha->hw->mr.fcport, FXDISC_GET_PORT_INFO);
3500 /* Register system information */
3501 ret = qlafx00_fx_disc(base_vha,
3502 &base_vha->hw->mr.fcport, FXDISC_REG_HOST_INFO);
3505 qla2x00_init_host_attr(base_vha);
3507 qla2x00_dfs_setup(base_vha);
3509 ql_log(ql_log_info, base_vha, 0x00fb,
3510 "QLogic %s - %s.\n", ha->model_number, ha->model_desc);
3511 ql_log(ql_log_info, base_vha, 0x00fc,
3512 "ISP%04X: %s @ %s hdma%c host#=%ld fw=%s.\n",
3513 pdev->device, ha->isp_ops->pci_info_str(base_vha, pci_info,
3515 pci_name(pdev), ha->flags.enable_64bit_addressing ? '+' : '-',
3517 ha->isp_ops->fw_version_str(base_vha, fw_str, sizeof(fw_str)));
3519 qlt_add_target(ha, base_vha);
3521 clear_bit(PFLG_DRIVER_PROBING, &base_vha->pci_flags);
3523 if (test_bit(UNLOADING, &base_vha->dpc_flags))
3529 qla_enode_stop(base_vha);
3530 qla_edb_stop(base_vha);
3531 if (base_vha->gnl.l) {
3532 dma_free_coherent(&ha->pdev->dev, base_vha->gnl.size,
3533 base_vha->gnl.l, base_vha->gnl.ldma);
3534 base_vha->gnl.l = NULL;
3537 if (base_vha->timer_active)
3538 qla2x00_stop_timer(base_vha);
3539 base_vha->flags.online = 0;
3540 if (ha->dpc_thread) {
3541 struct task_struct *t = ha->dpc_thread;
3543 ha->dpc_thread = NULL;
3547 qla2x00_free_device(base_vha);
3548 scsi_host_put(base_vha->host);
3550 * Need to NULL out local req/rsp after
3551 * qla2x00_free_device => qla2x00_free_queues frees
3552 * what these are pointing to. Or else we'll
3553 * fall over below in qla2x00_free_req/rsp_que.
3559 qla2x00_mem_free(ha);
3560 qla2x00_free_req_que(ha, req);
3561 qla2x00_free_rsp_que(ha, rsp);
3562 qla2x00_clear_drv_active(ha);
3564 iospace_config_failed:
3565 if (IS_P3P_TYPE(ha)) {
3566 if (!ha->nx_pcibase)
3567 iounmap((device_reg_t *)ha->nx_pcibase);
3569 iounmap((device_reg_t *)ha->nxdb_wr_ptr);
3572 iounmap(ha->iobase);
3574 iounmap(ha->cregbase);
3576 pci_release_selected_regions(ha->pdev, ha->bars);
3580 pci_disable_device(pdev);
3584 static void __qla_set_remove_flag(scsi_qla_host_t *base_vha)
3586 scsi_qla_host_t *vp;
3587 unsigned long flags;
3588 struct qla_hw_data *ha;
3595 spin_lock_irqsave(&ha->vport_slock, flags);
3596 list_for_each_entry(vp, &ha->vp_list, list)
3597 set_bit(PFLG_DRIVER_REMOVING, &vp->pci_flags);
3600 * Indicate device removal to prevent future board_disable
3601 * and wait until any pending board_disable has completed.
3603 set_bit(PFLG_DRIVER_REMOVING, &base_vha->pci_flags);
3604 spin_unlock_irqrestore(&ha->vport_slock, flags);
3608 qla2x00_shutdown(struct pci_dev *pdev)
3610 scsi_qla_host_t *vha;
3611 struct qla_hw_data *ha;
3613 vha = pci_get_drvdata(pdev);
3616 ql_log(ql_log_info, vha, 0xfffa,
3617 "Adapter shutdown\n");
3620 * Prevent future board_disable and wait
3621 * until any pending board_disable has completed.
3623 __qla_set_remove_flag(vha);
3624 cancel_work_sync(&ha->board_disable);
3626 if (!atomic_read(&pdev->enable_cnt))
3629 /* Notify ISPFX00 firmware */
3631 qlafx00_driver_shutdown(vha, 20);
3633 /* Turn-off FCE trace */
3634 if (ha->flags.fce_enabled) {
3635 qla2x00_disable_fce_trace(vha, NULL, NULL);
3636 ha->flags.fce_enabled = 0;
3639 /* Turn-off EFT trace */
3641 qla2x00_disable_eft_trace(vha);
3643 if (IS_QLA25XX(ha) || IS_QLA2031(ha) || IS_QLA27XX(ha) ||
3645 if (ha->flags.fw_started)
3646 qla2x00_abort_isp_cleanup(vha);
3648 /* Stop currently executing firmware. */
3649 qla2x00_try_to_stop_firmware(vha);
3653 if (vha->timer_active)
3654 qla2x00_stop_timer(vha);
3656 /* Turn adapter off line */
3657 vha->flags.online = 0;
3659 /* turn-off interrupts on the card */
3660 if (ha->interrupts_on) {
3661 vha->flags.init_done = 0;
3662 ha->isp_ops->disable_intrs(ha);
3665 qla2x00_free_irqs(vha);
3667 qla2x00_free_fw_dump(ha);
3669 pci_disable_device(pdev);
3670 ql_log(ql_log_info, vha, 0xfffe,
3671 "Adapter shutdown successfully.\n");
3674 /* Deletes all the virtual ports for a given ha */
3676 qla2x00_delete_all_vps(struct qla_hw_data *ha, scsi_qla_host_t *base_vha)
3678 scsi_qla_host_t *vha;
3679 unsigned long flags;
3681 mutex_lock(&ha->vport_lock);
3682 while (ha->cur_vport_count) {
3683 spin_lock_irqsave(&ha->vport_slock, flags);
3685 BUG_ON(base_vha->list.next == &ha->vp_list);
3686 /* This assumes first entry in ha->vp_list is always base vha */
3687 vha = list_first_entry(&base_vha->list, scsi_qla_host_t, list);
3688 scsi_host_get(vha->host);
3690 spin_unlock_irqrestore(&ha->vport_slock, flags);
3691 mutex_unlock(&ha->vport_lock);
3693 qla_nvme_delete(vha);
3695 fc_vport_terminate(vha->fc_vport);
3696 scsi_host_put(vha->host);
3698 mutex_lock(&ha->vport_lock);
3700 mutex_unlock(&ha->vport_lock);
3703 /* Stops all deferred work threads */
3705 qla2x00_destroy_deferred_work(struct qla_hw_data *ha)
3707 /* Cancel all work and destroy DPC workqueues */
3708 if (ha->dpc_lp_wq) {
3709 cancel_work_sync(&ha->idc_aen);
3710 destroy_workqueue(ha->dpc_lp_wq);
3711 ha->dpc_lp_wq = NULL;
3714 if (ha->dpc_hp_wq) {
3715 cancel_work_sync(&ha->nic_core_reset);
3716 cancel_work_sync(&ha->idc_state_handler);
3717 cancel_work_sync(&ha->nic_core_unrecoverable);
3718 destroy_workqueue(ha->dpc_hp_wq);
3719 ha->dpc_hp_wq = NULL;
3722 /* Kill the kernel thread for this host */
3723 if (ha->dpc_thread) {
3724 struct task_struct *t = ha->dpc_thread;
3727 * qla2xxx_wake_dpc checks for ->dpc_thread
3728 * so we need to zero it out.
3730 ha->dpc_thread = NULL;
3736 qla2x00_unmap_iobases(struct qla_hw_data *ha)
3738 if (IS_QLA82XX(ha)) {
3740 iounmap((device_reg_t *)ha->nx_pcibase);
3742 iounmap((device_reg_t *)ha->nxdb_wr_ptr);
3745 iounmap(ha->iobase);
3748 iounmap(ha->cregbase);
3751 iounmap(ha->mqiobase);
3754 iounmap(ha->msixbase);
3759 qla2x00_clear_drv_active(struct qla_hw_data *ha)
3761 if (IS_QLA8044(ha)) {
3762 qla8044_idc_lock(ha);
3763 qla8044_clear_drv_active(ha);
3764 qla8044_idc_unlock(ha);
3765 } else if (IS_QLA82XX(ha)) {
3766 qla82xx_idc_lock(ha);
3767 qla82xx_clear_drv_active(ha);
3768 qla82xx_idc_unlock(ha);
3773 qla2x00_remove_one(struct pci_dev *pdev)
3775 scsi_qla_host_t *base_vha;
3776 struct qla_hw_data *ha;
3778 base_vha = pci_get_drvdata(pdev);
3780 ql_log(ql_log_info, base_vha, 0xb079,
3781 "Removing driver\n");
3782 __qla_set_remove_flag(base_vha);
3783 cancel_work_sync(&ha->board_disable);
3786 * If the PCI device is disabled then there was a PCI-disconnect and
3787 * qla2x00_disable_board_on_pci_error has taken care of most of the
3790 if (!atomic_read(&pdev->enable_cnt)) {
3791 dma_free_coherent(&ha->pdev->dev, base_vha->gnl.size,
3792 base_vha->gnl.l, base_vha->gnl.ldma);
3793 base_vha->gnl.l = NULL;
3794 scsi_host_put(base_vha->host);
3796 pci_set_drvdata(pdev, NULL);
3799 qla2x00_wait_for_hba_ready(base_vha);
3802 * if UNLOADING flag is already set, then continue unload,
3803 * where it was set first.
3805 if (test_and_set_bit(UNLOADING, &base_vha->dpc_flags))
3808 if (IS_QLA25XX(ha) || IS_QLA2031(ha) || IS_QLA27XX(ha) ||
3810 if (ha->flags.fw_started)
3811 qla2x00_abort_isp_cleanup(base_vha);
3812 } else if (!IS_QLAFX00(ha)) {
3813 if (IS_QLA8031(ha)) {
3814 ql_dbg(ql_dbg_p3p, base_vha, 0xb07e,
3815 "Clearing fcoe driver presence.\n");
3816 if (qla83xx_clear_drv_presence(base_vha) != QLA_SUCCESS)
3817 ql_dbg(ql_dbg_p3p, base_vha, 0xb079,
3818 "Error while clearing DRV-Presence.\n");
3821 qla2x00_try_to_stop_firmware(base_vha);
3824 qla2x00_wait_for_sess_deletion(base_vha);
3826 qla_nvme_delete(base_vha);
3828 dma_free_coherent(&ha->pdev->dev,
3829 base_vha->gnl.size, base_vha->gnl.l, base_vha->gnl.ldma);
3831 base_vha->gnl.l = NULL;
3832 qla_enode_stop(base_vha);
3833 qla_edb_stop(base_vha);
3835 vfree(base_vha->scan.l);
3838 qlafx00_driver_shutdown(base_vha, 20);
3840 qla2x00_delete_all_vps(ha, base_vha);
3842 qla2x00_dfs_remove(base_vha);
3844 qla84xx_put_chip(base_vha);
3847 if (base_vha->timer_active)
3848 qla2x00_stop_timer(base_vha);
3850 base_vha->flags.online = 0;
3852 /* free DMA memory */
3853 if (ha->exlogin_buf)
3854 qla2x00_free_exlogin_buffer(ha);
3856 /* free DMA memory */
3857 if (ha->exchoffld_buf)
3858 qla2x00_free_exchoffld_buffer(ha);
3860 qla2x00_destroy_deferred_work(ha);
3862 qlt_remove_target(ha, base_vha);
3864 qla2x00_free_sysfs_attr(base_vha, true);
3866 fc_remove_host(base_vha->host);
3868 scsi_remove_host(base_vha->host);
3870 qla2x00_free_device(base_vha);
3872 qla2x00_clear_drv_active(ha);
3874 scsi_host_put(base_vha->host);
3876 qla2x00_unmap_iobases(ha);
3878 pci_release_selected_regions(ha->pdev, ha->bars);
3881 pci_disable_pcie_error_reporting(pdev);
3883 pci_disable_device(pdev);
3887 qla24xx_free_purex_list(struct purex_list *list)
3889 struct purex_item *item, *next;
3892 spin_lock_irqsave(&list->lock, flags);
3893 list_for_each_entry_safe(item, next, &list->head, list) {
3894 list_del(&item->list);
3895 if (item == &item->vha->default_item)
3899 spin_unlock_irqrestore(&list->lock, flags);
3903 qla2x00_free_device(scsi_qla_host_t *vha)
3905 struct qla_hw_data *ha = vha->hw;
3907 qla2x00_abort_all_cmds(vha, DID_NO_CONNECT << 16);
3910 if (vha->timer_active)
3911 qla2x00_stop_timer(vha);
3913 qla25xx_delete_queues(vha);
3914 vha->flags.online = 0;
3916 /* turn-off interrupts on the card */
3917 if (ha->interrupts_on) {
3918 vha->flags.init_done = 0;
3919 ha->isp_ops->disable_intrs(ha);
3922 qla2x00_free_fcports(vha);
3924 qla2x00_free_irqs(vha);
3926 /* Flush the work queue and remove it */
3928 flush_workqueue(ha->wq);
3929 destroy_workqueue(ha->wq);
3934 qla24xx_free_purex_list(&vha->purex_list);
3936 qla2x00_mem_free(ha);
3938 qla82xx_md_free(vha);
3940 qla_edif_sadb_release_free_pool(ha);
3941 qla_edif_sadb_release(ha);
3943 qla2x00_free_queues(ha);
3946 void qla2x00_free_fcports(struct scsi_qla_host *vha)
3948 fc_port_t *fcport, *tfcport;
3950 list_for_each_entry_safe(fcport, tfcport, &vha->vp_fcports, list)
3951 qla2x00_free_fcport(fcport);
3955 qla2x00_schedule_rport_del(struct scsi_qla_host *vha, fc_port_t *fcport)
3962 if (fcport->rport) {
3963 ql_dbg(ql_dbg_disc, fcport->vha, 0x2109,
3964 "%s %8phN. rport %p roles %x\n",
3965 __func__, fcport->port_name, fcport->rport,
3966 fcport->rport->roles);
3967 fc_remote_port_delete(fcport->rport);
3969 qlt_do_generation_tick(vha, &now);
3973 * qla2x00_mark_device_lost Updates fcport state when device goes offline.
3975 * Input: ha = adapter block pointer. fcport = port structure pointer.
3981 void qla2x00_mark_device_lost(scsi_qla_host_t *vha, fc_port_t *fcport,
3984 if (IS_QLAFX00(vha->hw)) {
3985 qla2x00_set_fcport_state(fcport, FCS_DEVICE_LOST);
3986 qla2x00_schedule_rport_del(vha, fcport);
3990 if (atomic_read(&fcport->state) == FCS_ONLINE &&
3991 vha->vp_idx == fcport->vha->vp_idx) {
3992 qla2x00_set_fcport_state(fcport, FCS_DEVICE_LOST);
3993 qla2x00_schedule_rport_del(vha, fcport);
3997 * We may need to retry the login, so don't change the state of the
3998 * port but do the retries.
4000 if (atomic_read(&fcport->state) != FCS_DEVICE_DEAD)
4001 qla2x00_set_fcport_state(fcport, FCS_DEVICE_LOST);
4006 set_bit(RELOGIN_NEEDED, &vha->dpc_flags);
4010 qla2x00_mark_all_devices_lost(scsi_qla_host_t *vha)
4014 ql_dbg(ql_dbg_disc, vha, 0x20f1,
4015 "Mark all dev lost\n");
4017 list_for_each_entry(fcport, &vha->vp_fcports, list) {
4018 if (fcport->loop_id != FC_NO_LOOP_ID &&
4019 (fcport->flags & FCF_FCP2_DEVICE) &&
4020 fcport->port_type == FCT_TARGET &&
4021 !qla2x00_reset_active(vha)) {
4022 ql_dbg(ql_dbg_disc, vha, 0x211a,
4023 "Delaying session delete for FCP2 flags 0x%x port_type = 0x%x port_id=%06x %phC",
4024 fcport->flags, fcport->port_type,
4025 fcport->d_id.b24, fcport->port_name);
4028 fcport->scan_state = 0;
4029 qlt_schedule_sess_for_deletion(fcport);
4033 static void qla2x00_set_reserved_loop_ids(struct qla_hw_data *ha)
4037 if (IS_FWI2_CAPABLE(ha))
4040 for (i = 0; i < SNS_FIRST_LOOP_ID; i++)
4041 set_bit(i, ha->loop_id_map);
4042 set_bit(MANAGEMENT_SERVER, ha->loop_id_map);
4043 set_bit(BROADCAST, ha->loop_id_map);
4048 * Allocates adapter memory.
4055 qla2x00_mem_alloc(struct qla_hw_data *ha, uint16_t req_len, uint16_t rsp_len,
4056 struct req_que **req, struct rsp_que **rsp)
4061 ha->init_cb = dma_alloc_coherent(&ha->pdev->dev, ha->init_cb_size,
4062 &ha->init_cb_dma, GFP_KERNEL);
4066 rc = btree_init32(&ha->host_map);
4068 goto fail_free_init_cb;
4070 if (qlt_mem_alloc(ha) < 0)
4071 goto fail_free_btree;
4073 ha->gid_list = dma_alloc_coherent(&ha->pdev->dev,
4074 qla2x00_gid_list_size(ha), &ha->gid_list_dma, GFP_KERNEL);
4076 goto fail_free_tgt_mem;
4078 ha->srb_mempool = mempool_create_slab_pool(SRB_MIN_REQ, srb_cachep);
4079 if (!ha->srb_mempool)
4080 goto fail_free_gid_list;
4082 if (IS_P3P_TYPE(ha) || IS_QLA27XX(ha) || (ql2xsecenable && IS_QLA28XX(ha))) {
4083 /* Allocate cache for CT6 Ctx. */
4085 ctx_cachep = kmem_cache_create("qla2xxx_ctx",
4086 sizeof(struct ct6_dsd), 0,
4087 SLAB_HWCACHE_ALIGN, NULL);
4089 goto fail_free_srb_mempool;
4091 ha->ctx_mempool = mempool_create_slab_pool(SRB_MIN_REQ,
4093 if (!ha->ctx_mempool)
4094 goto fail_free_srb_mempool;
4095 ql_dbg_pci(ql_dbg_init, ha->pdev, 0x0021,
4096 "ctx_cachep=%p ctx_mempool=%p.\n",
4097 ctx_cachep, ha->ctx_mempool);
4100 /* Get memory for cached NVRAM */
4101 ha->nvram = kzalloc(MAX_NVRAM_SIZE, GFP_KERNEL);
4103 goto fail_free_ctx_mempool;
4105 snprintf(name, sizeof(name), "%s_%d", QLA2XXX_DRIVER_NAME,
4107 ha->s_dma_pool = dma_pool_create(name, &ha->pdev->dev,
4108 DMA_POOL_SIZE, 8, 0);
4109 if (!ha->s_dma_pool)
4110 goto fail_free_nvram;
4112 ql_dbg_pci(ql_dbg_init, ha->pdev, 0x0022,
4113 "init_cb=%p gid_list=%p, srb_mempool=%p s_dma_pool=%p.\n",
4114 ha->init_cb, ha->gid_list, ha->srb_mempool, ha->s_dma_pool);
4116 if (IS_P3P_TYPE(ha) || ql2xenabledif || (IS_QLA28XX(ha) && ql2xsecenable)) {
4117 ha->dl_dma_pool = dma_pool_create(name, &ha->pdev->dev,
4118 DSD_LIST_DMA_POOL_SIZE, 8, 0);
4119 if (!ha->dl_dma_pool) {
4120 ql_log_pci(ql_log_fatal, ha->pdev, 0x0023,
4121 "Failed to allocate memory for dl_dma_pool.\n");
4122 goto fail_s_dma_pool;
4125 ha->fcp_cmnd_dma_pool = dma_pool_create(name, &ha->pdev->dev,
4126 FCP_CMND_DMA_POOL_SIZE, 8, 0);
4127 if (!ha->fcp_cmnd_dma_pool) {
4128 ql_log_pci(ql_log_fatal, ha->pdev, 0x0024,
4129 "Failed to allocate memory for fcp_cmnd_dma_pool.\n");
4130 goto fail_dl_dma_pool;
4133 if (ql2xenabledif) {
4134 u64 bufsize = DIF_BUNDLING_DMA_POOL_SIZE;
4135 struct dsd_dma *dsd, *nxt;
4137 /* Creata a DMA pool of buffers for DIF bundling */
4138 ha->dif_bundl_pool = dma_pool_create(name,
4139 &ha->pdev->dev, DIF_BUNDLING_DMA_POOL_SIZE, 8, 0);
4140 if (!ha->dif_bundl_pool) {
4141 ql_dbg_pci(ql_dbg_init, ha->pdev, 0x0024,
4142 "%s: failed create dif_bundl_pool\n",
4144 goto fail_dif_bundl_dma_pool;
4147 INIT_LIST_HEAD(&ha->pool.good.head);
4148 INIT_LIST_HEAD(&ha->pool.unusable.head);
4149 ha->pool.good.count = 0;
4150 ha->pool.unusable.count = 0;
4151 for (i = 0; i < 128; i++) {
4152 dsd = kzalloc(sizeof(*dsd), GFP_ATOMIC);
4154 ql_dbg_pci(ql_dbg_init, ha->pdev,
4155 0xe0ee, "%s: failed alloc dsd\n",
4159 ha->dif_bundle_kallocs++;
4161 dsd->dsd_addr = dma_pool_alloc(
4162 ha->dif_bundl_pool, GFP_ATOMIC,
4163 &dsd->dsd_list_dma);
4164 if (!dsd->dsd_addr) {
4165 ql_dbg_pci(ql_dbg_init, ha->pdev,
4167 "%s: failed alloc ->dsd_addr\n",
4170 ha->dif_bundle_kallocs--;
4173 ha->dif_bundle_dma_allocs++;
4176 * if DMA buffer crosses 4G boundary,
4177 * put it on bad list
4179 if (MSD(dsd->dsd_list_dma) ^
4180 MSD(dsd->dsd_list_dma + bufsize)) {
4181 list_add_tail(&dsd->list,
4182 &ha->pool.unusable.head);
4183 ha->pool.unusable.count++;
4185 list_add_tail(&dsd->list,
4186 &ha->pool.good.head);
4187 ha->pool.good.count++;
4191 /* return the good ones back to the pool */
4192 list_for_each_entry_safe(dsd, nxt,
4193 &ha->pool.good.head, list) {
4194 list_del(&dsd->list);
4195 dma_pool_free(ha->dif_bundl_pool,
4196 dsd->dsd_addr, dsd->dsd_list_dma);
4197 ha->dif_bundle_dma_allocs--;
4199 ha->dif_bundle_kallocs--;
4202 ql_dbg_pci(ql_dbg_init, ha->pdev, 0x0024,
4203 "%s: dif dma pool (good=%u unusable=%u)\n",
4204 __func__, ha->pool.good.count,
4205 ha->pool.unusable.count);
4208 ql_dbg_pci(ql_dbg_init, ha->pdev, 0x0025,
4209 "dl_dma_pool=%p fcp_cmnd_dma_pool=%p dif_bundl_pool=%p.\n",
4210 ha->dl_dma_pool, ha->fcp_cmnd_dma_pool,
4211 ha->dif_bundl_pool);
4214 /* Allocate memory for SNS commands */
4215 if (IS_QLA2100(ha) || IS_QLA2200(ha)) {
4216 /* Get consistent memory allocated for SNS commands */
4217 ha->sns_cmd = dma_alloc_coherent(&ha->pdev->dev,
4218 sizeof(struct sns_cmd_pkt), &ha->sns_cmd_dma, GFP_KERNEL);
4221 ql_dbg_pci(ql_dbg_init, ha->pdev, 0x0026,
4222 "sns_cmd: %p.\n", ha->sns_cmd);
4224 /* Get consistent memory allocated for MS IOCB */
4225 ha->ms_iocb = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL,
4229 /* Get consistent memory allocated for CT SNS commands */
4230 ha->ct_sns = dma_alloc_coherent(&ha->pdev->dev,
4231 sizeof(struct ct_sns_pkt), &ha->ct_sns_dma, GFP_KERNEL);
4233 goto fail_free_ms_iocb;
4234 ql_dbg_pci(ql_dbg_init, ha->pdev, 0x0027,
4235 "ms_iocb=%p ct_sns=%p.\n",
4236 ha->ms_iocb, ha->ct_sns);
4239 /* Allocate memory for request ring */
4240 *req = kzalloc(sizeof(struct req_que), GFP_KERNEL);
4242 ql_log_pci(ql_log_fatal, ha->pdev, 0x0028,
4243 "Failed to allocate memory for req.\n");
4246 (*req)->length = req_len;
4247 (*req)->ring = dma_alloc_coherent(&ha->pdev->dev,
4248 ((*req)->length + 1) * sizeof(request_t),
4249 &(*req)->dma, GFP_KERNEL);
4250 if (!(*req)->ring) {
4251 ql_log_pci(ql_log_fatal, ha->pdev, 0x0029,
4252 "Failed to allocate memory for req_ring.\n");
4255 /* Allocate memory for response ring */
4256 *rsp = kzalloc(sizeof(struct rsp_que), GFP_KERNEL);
4258 ql_log_pci(ql_log_fatal, ha->pdev, 0x002a,
4259 "Failed to allocate memory for rsp.\n");
4263 (*rsp)->length = rsp_len;
4264 (*rsp)->ring = dma_alloc_coherent(&ha->pdev->dev,
4265 ((*rsp)->length + 1) * sizeof(response_t),
4266 &(*rsp)->dma, GFP_KERNEL);
4267 if (!(*rsp)->ring) {
4268 ql_log_pci(ql_log_fatal, ha->pdev, 0x002b,
4269 "Failed to allocate memory for rsp_ring.\n");
4274 ql_dbg_pci(ql_dbg_init, ha->pdev, 0x002c,
4275 "req=%p req->length=%d req->ring=%p rsp=%p "
4276 "rsp->length=%d rsp->ring=%p.\n",
4277 *req, (*req)->length, (*req)->ring, *rsp, (*rsp)->length,
4279 /* Allocate memory for NVRAM data for vports */
4280 if (ha->nvram_npiv_size) {
4281 ha->npiv_info = kcalloc(ha->nvram_npiv_size,
4282 sizeof(struct qla_npiv_entry),
4284 if (!ha->npiv_info) {
4285 ql_log_pci(ql_log_fatal, ha->pdev, 0x002d,
4286 "Failed to allocate memory for npiv_info.\n");
4287 goto fail_npiv_info;
4290 ha->npiv_info = NULL;
4292 /* Get consistent memory allocated for EX-INIT-CB. */
4293 if (IS_CNA_CAPABLE(ha) || IS_QLA2031(ha) || IS_QLA27XX(ha) ||
4295 ha->ex_init_cb = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL,
4296 &ha->ex_init_cb_dma);
4297 if (!ha->ex_init_cb)
4298 goto fail_ex_init_cb;
4299 ql_dbg_pci(ql_dbg_init, ha->pdev, 0x002e,
4300 "ex_init_cb=%p.\n", ha->ex_init_cb);
4303 /* Get consistent memory allocated for Special Features-CB. */
4304 if (IS_QLA27XX(ha) || IS_QLA28XX(ha)) {
4305 ha->sf_init_cb = dma_pool_zalloc(ha->s_dma_pool, GFP_KERNEL,
4306 &ha->sf_init_cb_dma);
4307 if (!ha->sf_init_cb)
4308 goto fail_sf_init_cb;
4309 ql_dbg_pci(ql_dbg_init, ha->pdev, 0x0199,
4310 "sf_init_cb=%p.\n", ha->sf_init_cb);
4313 INIT_LIST_HEAD(&ha->gbl_dsd_list);
4315 /* Get consistent memory allocated for Async Port-Database. */
4316 if (!IS_FWI2_CAPABLE(ha)) {
4317 ha->async_pd = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL,
4321 ql_dbg_pci(ql_dbg_init, ha->pdev, 0x002f,
4322 "async_pd=%p.\n", ha->async_pd);
4325 INIT_LIST_HEAD(&ha->vp_list);
4327 /* Allocate memory for our loop_id bitmap */
4328 ha->loop_id_map = kcalloc(BITS_TO_LONGS(LOOPID_MAP_SIZE),
4331 if (!ha->loop_id_map)
4332 goto fail_loop_id_map;
4334 qla2x00_set_reserved_loop_ids(ha);
4335 ql_dbg_pci(ql_dbg_init, ha->pdev, 0x0123,
4336 "loop_id_map=%p.\n", ha->loop_id_map);
4339 ha->sfp_data = dma_alloc_coherent(&ha->pdev->dev,
4340 SFP_DEV_SIZE, &ha->sfp_data_dma, GFP_KERNEL);
4341 if (!ha->sfp_data) {
4342 ql_dbg_pci(ql_dbg_init, ha->pdev, 0x011b,
4343 "Unable to allocate memory for SFP read-data.\n");
4347 ha->flt = dma_alloc_coherent(&ha->pdev->dev,
4348 sizeof(struct qla_flt_header) + FLT_REGIONS_SIZE, &ha->flt_dma,
4351 ql_dbg_pci(ql_dbg_init, ha->pdev, 0x011b,
4352 "Unable to allocate memory for FLT.\n");
4353 goto fail_flt_buffer;
4356 /* allocate the purex dma pool */
4357 ha->purex_dma_pool = dma_pool_create(name, &ha->pdev->dev,
4358 ELS_MAX_PAYLOAD, 8, 0);
4360 if (!ha->purex_dma_pool) {
4361 ql_dbg_pci(ql_dbg_init, ha->pdev, 0x011b,
4362 "Unable to allocate purex_dma_pool.\n");
4366 ha->elsrej.size = sizeof(struct fc_els_ls_rjt) + 16;
4367 ha->elsrej.c = dma_alloc_coherent(&ha->pdev->dev,
4368 ha->elsrej.size, &ha->elsrej.cdma, GFP_KERNEL);
4370 if (!ha->elsrej.c) {
4371 ql_dbg_pci(ql_dbg_init, ha->pdev, 0xffff,
4372 "Alloc failed for els reject cmd.\n");
4375 ha->elsrej.c->er_cmd = ELS_LS_RJT;
4376 ha->elsrej.c->er_reason = ELS_RJT_LOGIC;
4377 ha->elsrej.c->er_explan = ELS_EXPL_UNAB_DATA;
4381 dma_pool_destroy(ha->purex_dma_pool);
4383 dma_free_coherent(&ha->pdev->dev, SFP_DEV_SIZE,
4384 ha->flt, ha->flt_dma);
4387 dma_free_coherent(&ha->pdev->dev, SFP_DEV_SIZE,
4388 ha->sfp_data, ha->sfp_data_dma);
4390 kfree(ha->loop_id_map);
4392 dma_pool_free(ha->s_dma_pool, ha->async_pd, ha->async_pd_dma);
4394 dma_pool_free(ha->s_dma_pool, ha->sf_init_cb, ha->sf_init_cb_dma);
4396 dma_pool_free(ha->s_dma_pool, ha->ex_init_cb, ha->ex_init_cb_dma);
4398 kfree(ha->npiv_info);
4400 dma_free_coherent(&ha->pdev->dev, ((*rsp)->length + 1) *
4401 sizeof(response_t), (*rsp)->ring, (*rsp)->dma);
4402 (*rsp)->ring = NULL;
4408 dma_free_coherent(&ha->pdev->dev, ((*req)->length + 1) *
4409 sizeof(request_t), (*req)->ring, (*req)->dma);
4410 (*req)->ring = NULL;
4416 dma_free_coherent(&ha->pdev->dev, sizeof(struct ct_sns_pkt),
4417 ha->ct_sns, ha->ct_sns_dma);
4421 dma_pool_free(ha->s_dma_pool, ha->ms_iocb, ha->ms_iocb_dma);
4423 ha->ms_iocb_dma = 0;
4426 dma_free_coherent(&ha->pdev->dev, sizeof(struct sns_cmd_pkt),
4427 ha->sns_cmd, ha->sns_cmd_dma);
4429 if (ql2xenabledif) {
4430 struct dsd_dma *dsd, *nxt;
4432 list_for_each_entry_safe(dsd, nxt, &ha->pool.unusable.head,
4434 list_del(&dsd->list);
4435 dma_pool_free(ha->dif_bundl_pool, dsd->dsd_addr,
4437 ha->dif_bundle_dma_allocs--;
4439 ha->dif_bundle_kallocs--;
4440 ha->pool.unusable.count--;
4442 dma_pool_destroy(ha->dif_bundl_pool);
4443 ha->dif_bundl_pool = NULL;
4446 fail_dif_bundl_dma_pool:
4447 if (IS_QLA82XX(ha) || ql2xenabledif) {
4448 dma_pool_destroy(ha->fcp_cmnd_dma_pool);
4449 ha->fcp_cmnd_dma_pool = NULL;
4452 if (IS_QLA82XX(ha) || ql2xenabledif) {
4453 dma_pool_destroy(ha->dl_dma_pool);
4454 ha->dl_dma_pool = NULL;
4457 dma_pool_destroy(ha->s_dma_pool);
4458 ha->s_dma_pool = NULL;
4462 fail_free_ctx_mempool:
4463 mempool_destroy(ha->ctx_mempool);
4464 ha->ctx_mempool = NULL;
4465 fail_free_srb_mempool:
4466 mempool_destroy(ha->srb_mempool);
4467 ha->srb_mempool = NULL;
4469 dma_free_coherent(&ha->pdev->dev, qla2x00_gid_list_size(ha),
4472 ha->gid_list = NULL;
4473 ha->gid_list_dma = 0;
4477 btree_destroy32(&ha->host_map);
4479 dma_free_coherent(&ha->pdev->dev, ha->init_cb_size, ha->init_cb,
4482 ha->init_cb_dma = 0;
4484 ql_log(ql_log_fatal, NULL, 0x0030,
4485 "Memory allocation failure.\n");
4490 qla2x00_set_exlogins_buffer(scsi_qla_host_t *vha)
4493 uint16_t size, max_cnt;
4495 struct qla_hw_data *ha = vha->hw;
4497 /* Return if we don't need to alloacate any extended logins */
4498 if (ql2xexlogins <= MAX_FIBRE_DEVICES_2400)
4501 if (!IS_EXLOGIN_OFFLD_CAPABLE(ha))
4504 ql_log(ql_log_info, vha, 0xd021, "EXLOGIN count: %d.\n", ql2xexlogins);
4506 rval = qla_get_exlogin_status(vha, &size, &max_cnt);
4507 if (rval != QLA_SUCCESS) {
4508 ql_log_pci(ql_log_fatal, ha->pdev, 0xd029,
4509 "Failed to get exlogin status.\n");
4513 temp = (ql2xexlogins > max_cnt) ? max_cnt : ql2xexlogins;
4516 if (temp != ha->exlogin_size) {
4517 qla2x00_free_exlogin_buffer(ha);
4518 ha->exlogin_size = temp;
4520 ql_log(ql_log_info, vha, 0xd024,
4521 "EXLOGIN: max_logins=%d, portdb=0x%x, total=%d.\n",
4522 max_cnt, size, temp);
4524 ql_log(ql_log_info, vha, 0xd025,
4525 "EXLOGIN: requested size=0x%x\n", ha->exlogin_size);
4527 /* Get consistent memory for extended logins */
4528 ha->exlogin_buf = dma_alloc_coherent(&ha->pdev->dev,
4529 ha->exlogin_size, &ha->exlogin_buf_dma, GFP_KERNEL);
4530 if (!ha->exlogin_buf) {
4531 ql_log_pci(ql_log_fatal, ha->pdev, 0xd02a,
4532 "Failed to allocate memory for exlogin_buf_dma.\n");
4537 /* Now configure the dma buffer */
4538 rval = qla_set_exlogin_mem_cfg(vha, ha->exlogin_buf_dma);
4540 ql_log(ql_log_fatal, vha, 0xd033,
4541 "Setup extended login buffer ****FAILED****.\n");
4542 qla2x00_free_exlogin_buffer(ha);
4549 * qla2x00_free_exlogin_buffer
4552 * ha = adapter block pointer
4555 qla2x00_free_exlogin_buffer(struct qla_hw_data *ha)
4557 if (ha->exlogin_buf) {
4558 dma_free_coherent(&ha->pdev->dev, ha->exlogin_size,
4559 ha->exlogin_buf, ha->exlogin_buf_dma);
4560 ha->exlogin_buf = NULL;
4561 ha->exlogin_size = 0;
4566 qla2x00_number_of_exch(scsi_qla_host_t *vha, u32 *ret_cnt, u16 max_cnt)
4569 struct init_cb_81xx *icb = (struct init_cb_81xx *)&vha->hw->init_cb;
4570 *ret_cnt = FW_DEF_EXCHANGES_CNT;
4572 if (max_cnt > vha->hw->max_exchg)
4573 max_cnt = vha->hw->max_exchg;
4575 if (qla_ini_mode_enabled(vha)) {
4576 if (vha->ql2xiniexchg > max_cnt)
4577 vha->ql2xiniexchg = max_cnt;
4579 if (vha->ql2xiniexchg > FW_DEF_EXCHANGES_CNT)
4580 *ret_cnt = vha->ql2xiniexchg;
4582 } else if (qla_tgt_mode_enabled(vha)) {
4583 if (vha->ql2xexchoffld > max_cnt) {
4584 vha->ql2xexchoffld = max_cnt;
4585 icb->exchange_count = cpu_to_le16(vha->ql2xexchoffld);
4588 if (vha->ql2xexchoffld > FW_DEF_EXCHANGES_CNT)
4589 *ret_cnt = vha->ql2xexchoffld;
4590 } else if (qla_dual_mode_enabled(vha)) {
4591 temp = vha->ql2xiniexchg + vha->ql2xexchoffld;
4592 if (temp > max_cnt) {
4593 vha->ql2xiniexchg -= (temp - max_cnt)/2;
4594 vha->ql2xexchoffld -= (((temp - max_cnt)/2) + 1);
4596 icb->exchange_count = cpu_to_le16(vha->ql2xexchoffld);
4599 if (temp > FW_DEF_EXCHANGES_CNT)
4605 qla2x00_set_exchoffld_buffer(scsi_qla_host_t *vha)
4609 u32 actual_cnt, totsz;
4610 struct qla_hw_data *ha = vha->hw;
4612 if (!ha->flags.exchoffld_enabled)
4615 if (!IS_EXCHG_OFFLD_CAPABLE(ha))
4619 rval = qla_get_exchoffld_status(vha, &size, &max_cnt);
4620 if (rval != QLA_SUCCESS) {
4621 ql_log_pci(ql_log_fatal, ha->pdev, 0xd012,
4622 "Failed to get exlogin status.\n");
4626 qla2x00_number_of_exch(vha, &actual_cnt, max_cnt);
4627 ql_log(ql_log_info, vha, 0xd014,
4628 "Actual exchange offload count: %d.\n", actual_cnt);
4630 totsz = actual_cnt * size;
4632 if (totsz != ha->exchoffld_size) {
4633 qla2x00_free_exchoffld_buffer(ha);
4634 if (actual_cnt <= FW_DEF_EXCHANGES_CNT) {
4635 ha->exchoffld_size = 0;
4636 ha->flags.exchoffld_enabled = 0;
4640 ha->exchoffld_size = totsz;
4642 ql_log(ql_log_info, vha, 0xd016,
4643 "Exchange offload: max_count=%d, actual count=%d entry sz=0x%x, total sz=0x%x\n",
4644 max_cnt, actual_cnt, size, totsz);
4646 ql_log(ql_log_info, vha, 0xd017,
4647 "Exchange Buffers requested size = 0x%x\n",
4648 ha->exchoffld_size);
4650 /* Get consistent memory for extended logins */
4651 ha->exchoffld_buf = dma_alloc_coherent(&ha->pdev->dev,
4652 ha->exchoffld_size, &ha->exchoffld_buf_dma, GFP_KERNEL);
4653 if (!ha->exchoffld_buf) {
4654 ql_log_pci(ql_log_fatal, ha->pdev, 0xd013,
4655 "Failed to allocate memory for Exchange Offload.\n");
4658 (FW_DEF_EXCHANGES_CNT + REDUCE_EXCHANGES_CNT)) {
4659 ha->max_exchg -= REDUCE_EXCHANGES_CNT;
4660 } else if (ha->max_exchg >
4661 (FW_DEF_EXCHANGES_CNT + 512)) {
4662 ha->max_exchg -= 512;
4664 ha->flags.exchoffld_enabled = 0;
4665 ql_log_pci(ql_log_fatal, ha->pdev, 0xd013,
4666 "Disabling Exchange offload due to lack of memory\n");
4668 ha->exchoffld_size = 0;
4672 } else if (!ha->exchoffld_buf || (actual_cnt <= FW_DEF_EXCHANGES_CNT)) {
4673 /* pathological case */
4674 qla2x00_free_exchoffld_buffer(ha);
4675 ha->exchoffld_size = 0;
4676 ha->flags.exchoffld_enabled = 0;
4677 ql_log(ql_log_info, vha, 0xd016,
4678 "Exchange offload not enable: offld size=%d, actual count=%d entry sz=0x%x, total sz=0x%x.\n",
4679 ha->exchoffld_size, actual_cnt, size, totsz);
4683 /* Now configure the dma buffer */
4684 rval = qla_set_exchoffld_mem_cfg(vha);
4686 ql_log(ql_log_fatal, vha, 0xd02e,
4687 "Setup exchange offload buffer ****FAILED****.\n");
4688 qla2x00_free_exchoffld_buffer(ha);
4690 /* re-adjust number of target exchange */
4691 struct init_cb_81xx *icb = (struct init_cb_81xx *)ha->init_cb;
4693 if (qla_ini_mode_enabled(vha))
4694 icb->exchange_count = 0;
4696 icb->exchange_count = cpu_to_le16(vha->ql2xexchoffld);
4703 * qla2x00_free_exchoffld_buffer
4706 * ha = adapter block pointer
4709 qla2x00_free_exchoffld_buffer(struct qla_hw_data *ha)
4711 if (ha->exchoffld_buf) {
4712 dma_free_coherent(&ha->pdev->dev, ha->exchoffld_size,
4713 ha->exchoffld_buf, ha->exchoffld_buf_dma);
4714 ha->exchoffld_buf = NULL;
4715 ha->exchoffld_size = 0;
4720 * qla2x00_free_fw_dump
4721 * Frees fw dump stuff.
4724 * ha = adapter block pointer
4727 qla2x00_free_fw_dump(struct qla_hw_data *ha)
4729 struct fwdt *fwdt = ha->fwdt;
4733 dma_free_coherent(&ha->pdev->dev,
4734 FCE_SIZE, ha->fce, ha->fce_dma);
4737 dma_free_coherent(&ha->pdev->dev,
4738 EFT_SIZE, ha->eft, ha->eft_dma);
4744 ha->flags.fce_enabled = 0;
4747 ha->fw_dumped = false;
4748 ha->fw_dump_cap_flags = 0;
4749 ha->fw_dump_reading = 0;
4751 ha->fw_dump_len = 0;
4753 for (j = 0; j < 2; j++, fwdt++) {
4754 vfree(fwdt->template);
4755 fwdt->template = NULL;
4762 * Frees all adapter allocated memory.
4765 * ha = adapter block pointer.
4768 qla2x00_mem_free(struct qla_hw_data *ha)
4770 qla2x00_free_fw_dump(ha);
4773 dma_free_coherent(&ha->pdev->dev, MCTP_DUMP_SIZE, ha->mctp_dump,
4775 ha->mctp_dump = NULL;
4777 mempool_destroy(ha->srb_mempool);
4778 ha->srb_mempool = NULL;
4781 dma_free_coherent(&ha->pdev->dev, DCBX_TLV_DATA_SIZE,
4782 ha->dcbx_tlv, ha->dcbx_tlv_dma);
4783 ha->dcbx_tlv = NULL;
4786 dma_free_coherent(&ha->pdev->dev, XGMAC_DATA_SIZE,
4787 ha->xgmac_data, ha->xgmac_data_dma);
4788 ha->xgmac_data = NULL;
4791 dma_free_coherent(&ha->pdev->dev, sizeof(struct sns_cmd_pkt),
4792 ha->sns_cmd, ha->sns_cmd_dma);
4794 ha->sns_cmd_dma = 0;
4797 dma_free_coherent(&ha->pdev->dev, sizeof(struct ct_sns_pkt),
4798 ha->ct_sns, ha->ct_sns_dma);
4803 dma_free_coherent(&ha->pdev->dev, SFP_DEV_SIZE, ha->sfp_data,
4805 ha->sfp_data = NULL;
4808 dma_free_coherent(&ha->pdev->dev,
4809 sizeof(struct qla_flt_header) + FLT_REGIONS_SIZE,
4810 ha->flt, ha->flt_dma);
4815 dma_pool_free(ha->s_dma_pool, ha->ms_iocb, ha->ms_iocb_dma);
4817 ha->ms_iocb_dma = 0;
4820 dma_pool_free(ha->s_dma_pool,
4821 ha->sf_init_cb, ha->sf_init_cb_dma);
4824 dma_pool_free(ha->s_dma_pool,
4825 ha->ex_init_cb, ha->ex_init_cb_dma);
4826 ha->ex_init_cb = NULL;
4827 ha->ex_init_cb_dma = 0;
4830 dma_pool_free(ha->s_dma_pool, ha->async_pd, ha->async_pd_dma);
4831 ha->async_pd = NULL;
4832 ha->async_pd_dma = 0;
4834 dma_pool_destroy(ha->s_dma_pool);
4835 ha->s_dma_pool = NULL;
4838 dma_free_coherent(&ha->pdev->dev, qla2x00_gid_list_size(ha),
4839 ha->gid_list, ha->gid_list_dma);
4840 ha->gid_list = NULL;
4841 ha->gid_list_dma = 0;
4843 if (IS_QLA82XX(ha)) {
4844 if (!list_empty(&ha->gbl_dsd_list)) {
4845 struct dsd_dma *dsd_ptr, *tdsd_ptr;
4847 /* clean up allocated prev pool */
4848 list_for_each_entry_safe(dsd_ptr,
4849 tdsd_ptr, &ha->gbl_dsd_list, list) {
4850 dma_pool_free(ha->dl_dma_pool,
4851 dsd_ptr->dsd_addr, dsd_ptr->dsd_list_dma);
4852 list_del(&dsd_ptr->list);
4858 dma_pool_destroy(ha->dl_dma_pool);
4859 ha->dl_dma_pool = NULL;
4861 dma_pool_destroy(ha->fcp_cmnd_dma_pool);
4862 ha->fcp_cmnd_dma_pool = NULL;
4864 mempool_destroy(ha->ctx_mempool);
4865 ha->ctx_mempool = NULL;
4867 if (ql2xenabledif && ha->dif_bundl_pool) {
4868 struct dsd_dma *dsd, *nxt;
4870 list_for_each_entry_safe(dsd, nxt, &ha->pool.unusable.head,
4872 list_del(&dsd->list);
4873 dma_pool_free(ha->dif_bundl_pool, dsd->dsd_addr,
4875 ha->dif_bundle_dma_allocs--;
4877 ha->dif_bundle_kallocs--;
4878 ha->pool.unusable.count--;
4880 list_for_each_entry_safe(dsd, nxt, &ha->pool.good.head, list) {
4881 list_del(&dsd->list);
4882 dma_pool_free(ha->dif_bundl_pool, dsd->dsd_addr,
4884 ha->dif_bundle_dma_allocs--;
4886 ha->dif_bundle_kallocs--;
4890 dma_pool_destroy(ha->dif_bundl_pool);
4891 ha->dif_bundl_pool = NULL;
4894 qla_remove_hostmap(ha);
4897 dma_free_coherent(&ha->pdev->dev, ha->init_cb_size,
4898 ha->init_cb, ha->init_cb_dma);
4900 dma_pool_destroy(ha->purex_dma_pool);
4901 ha->purex_dma_pool = NULL;
4904 dma_free_coherent(&ha->pdev->dev, ha->elsrej.size,
4905 ha->elsrej.c, ha->elsrej.cdma);
4906 ha->elsrej.c = NULL;
4910 ha->init_cb_dma = 0;
4912 vfree(ha->optrom_buffer);
4913 ha->optrom_buffer = NULL;
4916 kfree(ha->npiv_info);
4917 ha->npiv_info = NULL;
4920 kfree(ha->loop_id_map);
4921 ha->sf_init_cb = NULL;
4922 ha->sf_init_cb_dma = 0;
4923 ha->loop_id_map = NULL;
4926 struct scsi_qla_host *qla2x00_create_host(struct scsi_host_template *sht,
4927 struct qla_hw_data *ha)
4929 struct Scsi_Host *host;
4930 struct scsi_qla_host *vha = NULL;
4932 host = scsi_host_alloc(sht, sizeof(scsi_qla_host_t));
4934 ql_log_pci(ql_log_fatal, ha->pdev, 0x0107,
4935 "Failed to allocate host from the scsi layer, aborting.\n");
4939 /* Clear our data area */
4940 vha = shost_priv(host);
4941 memset(vha, 0, sizeof(scsi_qla_host_t));
4944 vha->host_no = host->host_no;
4947 vha->qlini_mode = ql2x_ini_mode;
4948 vha->ql2xexchoffld = ql2xexchoffld;
4949 vha->ql2xiniexchg = ql2xiniexchg;
4951 INIT_LIST_HEAD(&vha->vp_fcports);
4952 INIT_LIST_HEAD(&vha->work_list);
4953 INIT_LIST_HEAD(&vha->list);
4954 INIT_LIST_HEAD(&vha->qla_cmd_list);
4955 INIT_LIST_HEAD(&vha->qla_sess_op_cmd_list);
4956 INIT_LIST_HEAD(&vha->logo_list);
4957 INIT_LIST_HEAD(&vha->plogi_ack_list);
4958 INIT_LIST_HEAD(&vha->qp_list);
4959 INIT_LIST_HEAD(&vha->gnl.fcports);
4960 INIT_LIST_HEAD(&vha->gpnid_list);
4961 INIT_WORK(&vha->iocb_work, qla2x00_iocb_work_fn);
4963 INIT_LIST_HEAD(&vha->purex_list.head);
4964 spin_lock_init(&vha->purex_list.lock);
4966 spin_lock_init(&vha->work_lock);
4967 spin_lock_init(&vha->cmd_list_lock);
4968 init_waitqueue_head(&vha->fcport_waitQ);
4969 init_waitqueue_head(&vha->vref_waitq);
4970 qla_enode_init(vha);
4974 vha->gnl.size = sizeof(struct get_name_list_extended) *
4975 (ha->max_loop_id + 1);
4976 vha->gnl.l = dma_alloc_coherent(&ha->pdev->dev,
4977 vha->gnl.size, &vha->gnl.ldma, GFP_KERNEL);
4979 ql_log(ql_log_fatal, vha, 0xd04a,
4980 "Alloc failed for name list.\n");
4981 scsi_host_put(vha->host);
4985 /* todo: what about ext login? */
4986 vha->scan.size = ha->max_fibre_devices * sizeof(struct fab_scan_rp);
4987 vha->scan.l = vmalloc(vha->scan.size);
4989 ql_log(ql_log_fatal, vha, 0xd04a,
4990 "Alloc failed for scan database.\n");
4991 dma_free_coherent(&ha->pdev->dev, vha->gnl.size,
4992 vha->gnl.l, vha->gnl.ldma);
4994 scsi_host_put(vha->host);
4997 INIT_DELAYED_WORK(&vha->scan.scan_work, qla_scan_work_fn);
4999 sprintf(vha->host_str, "%s_%lu", QLA2XXX_DRIVER_NAME, vha->host_no);
5000 ql_dbg(ql_dbg_init, vha, 0x0041,
5001 "Allocated the host=%p hw=%p vha=%p dev_name=%s",
5002 vha->host, vha->hw, vha,
5003 dev_name(&(ha->pdev->dev)));
5008 struct qla_work_evt *
5009 qla2x00_alloc_work(struct scsi_qla_host *vha, enum qla_work_type type)
5011 struct qla_work_evt *e;
5014 if (test_bit(UNLOADING, &vha->dpc_flags))
5017 QLA_VHA_MARK_BUSY(vha, bail);
5021 e = kzalloc(sizeof(struct qla_work_evt), GFP_ATOMIC);
5023 QLA_VHA_MARK_NOT_BUSY(vha);
5027 INIT_LIST_HEAD(&e->list);
5029 e->flags = QLA_EVT_FLAG_FREE;
5034 qla2x00_post_work(struct scsi_qla_host *vha, struct qla_work_evt *e)
5036 unsigned long flags;
5039 spin_lock_irqsave(&vha->work_lock, flags);
5040 list_add_tail(&e->list, &vha->work_list);
5042 if (!test_and_set_bit(IOCB_WORK_ACTIVE, &vha->dpc_flags))
5045 spin_unlock_irqrestore(&vha->work_lock, flags);
5048 queue_work(vha->hw->wq, &vha->iocb_work);
5054 qla2x00_post_aen_work(struct scsi_qla_host *vha, enum fc_host_event_code code,
5057 struct qla_work_evt *e;
5059 e = qla2x00_alloc_work(vha, QLA_EVT_AEN);
5061 return QLA_FUNCTION_FAILED;
5063 e->u.aen.code = code;
5064 e->u.aen.data = data;
5065 return qla2x00_post_work(vha, e);
5069 qla2x00_post_idc_ack_work(struct scsi_qla_host *vha, uint16_t *mb)
5071 struct qla_work_evt *e;
5073 e = qla2x00_alloc_work(vha, QLA_EVT_IDC_ACK);
5075 return QLA_FUNCTION_FAILED;
5077 memcpy(e->u.idc_ack.mb, mb, QLA_IDC_ACK_REGS * sizeof(uint16_t));
5078 return qla2x00_post_work(vha, e);
5081 #define qla2x00_post_async_work(name, type) \
5082 int qla2x00_post_async_##name##_work( \
5083 struct scsi_qla_host *vha, \
5084 fc_port_t *fcport, uint16_t *data) \
5086 struct qla_work_evt *e; \
5088 e = qla2x00_alloc_work(vha, type); \
5090 return QLA_FUNCTION_FAILED; \
5092 e->u.logio.fcport = fcport; \
5094 e->u.logio.data[0] = data[0]; \
5095 e->u.logio.data[1] = data[1]; \
5097 fcport->flags |= FCF_ASYNC_ACTIVE; \
5098 return qla2x00_post_work(vha, e); \
5101 qla2x00_post_async_work(login, QLA_EVT_ASYNC_LOGIN);
5102 qla2x00_post_async_work(logout, QLA_EVT_ASYNC_LOGOUT);
5103 qla2x00_post_async_work(adisc, QLA_EVT_ASYNC_ADISC);
5104 qla2x00_post_async_work(prlo, QLA_EVT_ASYNC_PRLO);
5105 qla2x00_post_async_work(prlo_done, QLA_EVT_ASYNC_PRLO_DONE);
5108 qla2x00_post_uevent_work(struct scsi_qla_host *vha, u32 code)
5110 struct qla_work_evt *e;
5112 e = qla2x00_alloc_work(vha, QLA_EVT_UEVENT);
5114 return QLA_FUNCTION_FAILED;
5116 e->u.uevent.code = code;
5117 return qla2x00_post_work(vha, e);
5121 qla2x00_uevent_emit(struct scsi_qla_host *vha, u32 code)
5123 char event_string[40];
5124 char *envp[] = { event_string, NULL };
5127 case QLA_UEVENT_CODE_FW_DUMP:
5128 snprintf(event_string, sizeof(event_string), "FW_DUMP=%lu",
5135 kobject_uevent_env(&vha->hw->pdev->dev.kobj, KOBJ_CHANGE, envp);
5139 qlafx00_post_aenfx_work(struct scsi_qla_host *vha, uint32_t evtcode,
5140 uint32_t *data, int cnt)
5142 struct qla_work_evt *e;
5144 e = qla2x00_alloc_work(vha, QLA_EVT_AENFX);
5146 return QLA_FUNCTION_FAILED;
5148 e->u.aenfx.evtcode = evtcode;
5149 e->u.aenfx.count = cnt;
5150 memcpy(e->u.aenfx.mbx, data, sizeof(*data) * cnt);
5151 return qla2x00_post_work(vha, e);
5154 void qla24xx_sched_upd_fcport(fc_port_t *fcport)
5156 unsigned long flags;
5158 if (IS_SW_RESV_ADDR(fcport->d_id))
5161 spin_lock_irqsave(&fcport->vha->work_lock, flags);
5162 if (fcport->disc_state == DSC_UPD_FCPORT) {
5163 spin_unlock_irqrestore(&fcport->vha->work_lock, flags);
5166 fcport->jiffies_at_registration = jiffies;
5167 fcport->sec_since_registration = 0;
5168 fcport->next_disc_state = DSC_DELETED;
5169 qla2x00_set_fcport_disc_state(fcport, DSC_UPD_FCPORT);
5170 spin_unlock_irqrestore(&fcport->vha->work_lock, flags);
5172 queue_work(system_unbound_wq, &fcport->reg_work);
5176 void qla24xx_create_new_sess(struct scsi_qla_host *vha, struct qla_work_evt *e)
5178 unsigned long flags;
5179 fc_port_t *fcport = NULL, *tfcp;
5180 struct qlt_plogi_ack_t *pla =
5181 (struct qlt_plogi_ack_t *)e->u.new_sess.pla;
5182 uint8_t free_fcport = 0;
5184 ql_dbg(ql_dbg_disc, vha, 0xffff,
5185 "%s %d %8phC enter\n",
5186 __func__, __LINE__, e->u.new_sess.port_name);
5188 spin_lock_irqsave(&vha->hw->tgt.sess_lock, flags);
5189 fcport = qla2x00_find_fcport_by_wwpn(vha, e->u.new_sess.port_name, 1);
5191 fcport->d_id = e->u.new_sess.id;
5193 fcport->fw_login_state = DSC_LS_PLOGI_PEND;
5194 memcpy(fcport->node_name,
5195 pla->iocb.u.isp24.u.plogi.node_name,
5197 qlt_plogi_ack_link(vha, pla, fcport, QLT_PLOGI_LINK_SAME_WWN);
5198 /* we took an extra ref_count to prevent PLOGI ACK when
5199 * fcport/sess has not been created.
5204 spin_unlock_irqrestore(&vha->hw->tgt.sess_lock, flags);
5205 fcport = qla2x00_alloc_fcport(vha, GFP_KERNEL);
5207 fcport->d_id = e->u.new_sess.id;
5208 fcport->flags |= FCF_FABRIC_DEVICE;
5209 fcport->fw_login_state = DSC_LS_PLOGI_PEND;
5210 fcport->tgt_short_link_down_cnt = 0;
5212 memcpy(fcport->port_name, e->u.new_sess.port_name,
5215 fcport->fc4_type = e->u.new_sess.fc4_type;
5216 if (NVME_PRIORITY(vha->hw, fcport))
5217 fcport->do_prli_nvme = 1;
5219 fcport->do_prli_nvme = 0;
5221 if (e->u.new_sess.fc4_type & FS_FCP_IS_N2N) {
5222 fcport->dm_login_expire = jiffies +
5223 QLA_N2N_WAIT_TIME * HZ;
5224 fcport->fc4_type = FS_FC4TYPE_FCP;
5225 fcport->n2n_flag = 1;
5226 if (vha->flags.nvme_enabled)
5227 fcport->fc4_type |= FS_FC4TYPE_NVME;
5231 ql_dbg(ql_dbg_disc, vha, 0xffff,
5232 "%s %8phC mem alloc fail.\n",
5233 __func__, e->u.new_sess.port_name);
5236 list_del(&pla->list);
5237 kmem_cache_free(qla_tgt_plogi_cachep, pla);
5242 spin_lock_irqsave(&vha->hw->tgt.sess_lock, flags);
5243 /* search again to make sure no one else got ahead */
5244 tfcp = qla2x00_find_fcport_by_wwpn(vha,
5245 e->u.new_sess.port_name, 1);
5247 /* should rarily happen */
5248 ql_dbg(ql_dbg_disc, vha, 0xffff,
5249 "%s %8phC found existing fcport b4 add. DS %d LS %d\n",
5250 __func__, tfcp->port_name, tfcp->disc_state,
5251 tfcp->fw_login_state);
5255 list_add_tail(&fcport->list, &vha->vp_fcports);
5259 qlt_plogi_ack_link(vha, pla, fcport,
5260 QLT_PLOGI_LINK_SAME_WWN);
5264 spin_unlock_irqrestore(&vha->hw->tgt.sess_lock, flags);
5267 fcport->id_changed = 1;
5268 fcport->scan_state = QLA_FCPORT_FOUND;
5269 fcport->chip_reset = vha->hw->base_qpair->chip_reset;
5270 memcpy(fcport->node_name, e->u.new_sess.node_name, WWN_SIZE);
5273 if (pla->iocb.u.isp24.status_subcode == ELS_PRLI) {
5276 fcport->fw_login_state = DSC_LS_PRLI_PEND;
5280 pla->iocb.u.isp24.nport_handle);
5281 fcport->fw_login_state = DSC_LS_PRLI_PEND;
5284 pla->iocb.u.isp24.u.prli.wd3_lo);
5287 fcport->conf_compl_supported = 1;
5289 if ((wd3_lo & BIT_4) == 0)
5290 fcport->port_type = FCT_INITIATOR;
5292 fcport->port_type = FCT_TARGET;
5294 qlt_plogi_ack_unref(vha, pla);
5296 fc_port_t *dfcp = NULL;
5298 spin_lock_irqsave(&vha->hw->tgt.sess_lock, flags);
5299 tfcp = qla2x00_find_fcport_by_nportid(vha,
5300 &e->u.new_sess.id, 1);
5301 if (tfcp && (tfcp != fcport)) {
5303 * We have a conflict fcport with same NportID.
5305 ql_dbg(ql_dbg_disc, vha, 0xffff,
5306 "%s %8phC found conflict b4 add. DS %d LS %d\n",
5307 __func__, tfcp->port_name, tfcp->disc_state,
5308 tfcp->fw_login_state);
5310 switch (tfcp->disc_state) {
5313 case DSC_DELETE_PEND:
5314 fcport->login_pause = 1;
5315 tfcp->conflict = fcport;
5318 fcport->login_pause = 1;
5319 tfcp->conflict = fcport;
5324 spin_unlock_irqrestore(&vha->hw->tgt.sess_lock, flags);
5326 qlt_schedule_sess_for_deletion(tfcp);
5328 if (N2N_TOPO(vha->hw)) {
5329 fcport->flags &= ~FCF_FABRIC_DEVICE;
5330 fcport->keep_nport_handle = 1;
5331 if (vha->flags.nvme_enabled) {
5333 (FS_FC4TYPE_NVME | FS_FC4TYPE_FCP);
5334 fcport->n2n_flag = 1;
5336 fcport->fw_login_state = 0;
5338 schedule_delayed_work(&vha->scan.scan_work, 5);
5340 qla24xx_fcport_handle_login(vha, fcport);
5346 qla2x00_free_fcport(fcport);
5348 list_del(&pla->list);
5349 kmem_cache_free(qla_tgt_plogi_cachep, pla);
5354 static void qla_sp_retry(struct scsi_qla_host *vha, struct qla_work_evt *e)
5356 struct srb *sp = e->u.iosb.sp;
5359 rval = qla2x00_start_sp(sp);
5360 if (rval != QLA_SUCCESS) {
5361 ql_dbg(ql_dbg_disc, vha, 0x2043,
5362 "%s: %s: Re-issue IOCB failed (%d).\n",
5363 __func__, sp->name, rval);
5364 qla24xx_sp_unmap(vha, sp);
5369 qla2x00_do_work(struct scsi_qla_host *vha)
5371 struct qla_work_evt *e, *tmp;
5372 unsigned long flags;
5376 spin_lock_irqsave(&vha->work_lock, flags);
5377 list_splice_init(&vha->work_list, &work);
5378 spin_unlock_irqrestore(&vha->work_lock, flags);
5380 list_for_each_entry_safe(e, tmp, &work, list) {
5384 fc_host_post_event(vha->host, fc_get_event_number(),
5385 e->u.aen.code, e->u.aen.data);
5387 case QLA_EVT_IDC_ACK:
5388 qla81xx_idc_ack(vha, e->u.idc_ack.mb);
5390 case QLA_EVT_ASYNC_LOGIN:
5391 qla2x00_async_login(vha, e->u.logio.fcport,
5394 case QLA_EVT_ASYNC_LOGOUT:
5395 rc = qla2x00_async_logout(vha, e->u.logio.fcport);
5397 case QLA_EVT_ASYNC_ADISC:
5398 qla2x00_async_adisc(vha, e->u.logio.fcport,
5401 case QLA_EVT_UEVENT:
5402 qla2x00_uevent_emit(vha, e->u.uevent.code);
5405 qlafx00_process_aen(vha, e);
5408 qla24xx_async_gpnid(vha, &e->u.gpnid.id);
5411 qla24xx_sp_unmap(vha, e->u.iosb.sp);
5413 case QLA_EVT_RELOGIN:
5414 qla2x00_relogin(vha);
5416 case QLA_EVT_NEW_SESS:
5417 qla24xx_create_new_sess(vha, e);
5420 qla24xx_async_gpdb(vha, e->u.fcport.fcport,
5424 qla24xx_async_prli(vha, e->u.fcport.fcport);
5427 qla24xx_async_gpsc(vha, e->u.fcport.fcport);
5430 qla24xx_async_gnl(vha, e->u.fcport.fcport);
5433 qla24xx_do_nack_work(vha, e);
5435 case QLA_EVT_ASYNC_PRLO:
5436 rc = qla2x00_async_prlo(vha, e->u.logio.fcport);
5438 case QLA_EVT_ASYNC_PRLO_DONE:
5439 qla2x00_async_prlo_done(vha, e->u.logio.fcport,
5443 qla24xx_async_gpnft(vha, e->u.gpnft.fc4_type,
5446 case QLA_EVT_GPNFT_DONE:
5447 qla24xx_async_gpnft_done(vha, e->u.iosb.sp);
5449 case QLA_EVT_GNNFT_DONE:
5450 qla24xx_async_gnnft_done(vha, e->u.iosb.sp);
5453 qla24xx_async_gnnid(vha, e->u.fcport.fcport);
5455 case QLA_EVT_GFPNID:
5456 qla24xx_async_gfpnid(vha, e->u.fcport.fcport);
5458 case QLA_EVT_SP_RETRY:
5459 qla_sp_retry(vha, e);
5462 qla_do_iidma_work(vha, e->u.fcport.fcport);
5464 case QLA_EVT_ELS_PLOGI:
5465 qla24xx_els_dcmd2_iocb(vha, ELS_DCMD_PLOGI,
5466 e->u.fcport.fcport, false);
5468 case QLA_EVT_SA_REPLACE:
5469 qla24xx_issue_sa_replace_iocb(vha, e);
5474 /* put 'work' at head of 'vha->work_list' */
5475 spin_lock_irqsave(&vha->work_lock, flags);
5476 list_splice(&work, &vha->work_list);
5477 spin_unlock_irqrestore(&vha->work_lock, flags);
5480 list_del_init(&e->list);
5481 if (e->flags & QLA_EVT_FLAG_FREE)
5484 /* For each work completed decrement vha ref count */
5485 QLA_VHA_MARK_NOT_BUSY(vha);
5489 int qla24xx_post_relogin_work(struct scsi_qla_host *vha)
5491 struct qla_work_evt *e;
5493 e = qla2x00_alloc_work(vha, QLA_EVT_RELOGIN);
5496 set_bit(RELOGIN_NEEDED, &vha->dpc_flags);
5497 return QLA_FUNCTION_FAILED;
5500 return qla2x00_post_work(vha, e);
5503 /* Relogins all the fcports of a vport
5504 * Context: dpc thread
5506 void qla2x00_relogin(struct scsi_qla_host *vha)
5509 int status, relogin_needed = 0;
5510 struct event_arg ea;
5512 list_for_each_entry(fcport, &vha->vp_fcports, list) {
5514 * If the port is not ONLINE then try to login
5515 * to it if we haven't run out of retries.
5517 if (atomic_read(&fcport->state) != FCS_ONLINE &&
5518 fcport->login_retry) {
5519 if (fcport->scan_state != QLA_FCPORT_FOUND ||
5520 fcport->disc_state == DSC_LOGIN_AUTH_PEND ||
5521 fcport->disc_state == DSC_LOGIN_COMPLETE)
5524 if (fcport->flags & (FCF_ASYNC_SENT|FCF_ASYNC_ACTIVE) ||
5525 fcport->disc_state == DSC_DELETE_PEND) {
5528 if (vha->hw->current_topology != ISP_CFG_NL) {
5529 memset(&ea, 0, sizeof(ea));
5531 qla24xx_handle_relogin_event(vha, &ea);
5532 } else if (vha->hw->current_topology ==
5534 IS_QLA2XXX_MIDTYPE(vha->hw)) {
5535 (void)qla24xx_fcport_handle_login(vha,
5537 } else if (vha->hw->current_topology ==
5539 fcport->login_retry--;
5541 qla2x00_local_device_login(vha,
5543 if (status == QLA_SUCCESS) {
5544 fcport->old_loop_id =
5546 ql_dbg(ql_dbg_disc, vha, 0x2003,
5547 "Port login OK: logged in ID 0x%x.\n",
5549 qla2x00_update_fcport
5551 } else if (status == 1) {
5552 set_bit(RELOGIN_NEEDED,
5554 /* retry the login again */
5555 ql_dbg(ql_dbg_disc, vha, 0x2007,
5556 "Retrying %d login again loop_id 0x%x.\n",
5557 fcport->login_retry,
5560 fcport->login_retry = 0;
5563 if (fcport->login_retry == 0 &&
5564 status != QLA_SUCCESS)
5565 qla2x00_clear_loop_id(fcport);
5569 if (test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags))
5574 set_bit(RELOGIN_NEEDED, &vha->dpc_flags);
5576 ql_dbg(ql_dbg_disc, vha, 0x400e,
5580 /* Schedule work on any of the dpc-workqueues */
5582 qla83xx_schedule_work(scsi_qla_host_t *base_vha, int work_code)
5584 struct qla_hw_data *ha = base_vha->hw;
5586 switch (work_code) {
5587 case MBA_IDC_AEN: /* 0x8200 */
5589 queue_work(ha->dpc_lp_wq, &ha->idc_aen);
5592 case QLA83XX_NIC_CORE_RESET: /* 0x1 */
5593 if (!ha->flags.nic_core_reset_hdlr_active) {
5595 queue_work(ha->dpc_hp_wq, &ha->nic_core_reset);
5597 ql_dbg(ql_dbg_p3p, base_vha, 0xb05e,
5598 "NIC Core reset is already active. Skip "
5599 "scheduling it again.\n");
5601 case QLA83XX_IDC_STATE_HANDLER: /* 0x2 */
5603 queue_work(ha->dpc_hp_wq, &ha->idc_state_handler);
5605 case QLA83XX_NIC_CORE_UNRECOVERABLE: /* 0x3 */
5607 queue_work(ha->dpc_hp_wq, &ha->nic_core_unrecoverable);
5610 ql_log(ql_log_warn, base_vha, 0xb05f,
5611 "Unknown work-code=0x%x.\n", work_code);
5617 /* Work: Perform NIC Core Unrecoverable state handling */
5619 qla83xx_nic_core_unrecoverable_work(struct work_struct *work)
5621 struct qla_hw_data *ha =
5622 container_of(work, struct qla_hw_data, nic_core_unrecoverable);
5623 scsi_qla_host_t *base_vha = pci_get_drvdata(ha->pdev);
5624 uint32_t dev_state = 0;
5626 qla83xx_idc_lock(base_vha, 0);
5627 qla83xx_rd_reg(base_vha, QLA83XX_IDC_DEV_STATE, &dev_state);
5628 qla83xx_reset_ownership(base_vha);
5629 if (ha->flags.nic_core_reset_owner) {
5630 ha->flags.nic_core_reset_owner = 0;
5631 qla83xx_wr_reg(base_vha, QLA83XX_IDC_DEV_STATE,
5632 QLA8XXX_DEV_FAILED);
5633 ql_log(ql_log_info, base_vha, 0xb060, "HW State: FAILED.\n");
5634 qla83xx_schedule_work(base_vha, QLA83XX_IDC_STATE_HANDLER);
5636 qla83xx_idc_unlock(base_vha, 0);
5639 /* Work: Execute IDC state handler */
5641 qla83xx_idc_state_handler_work(struct work_struct *work)
5643 struct qla_hw_data *ha =
5644 container_of(work, struct qla_hw_data, idc_state_handler);
5645 scsi_qla_host_t *base_vha = pci_get_drvdata(ha->pdev);
5646 uint32_t dev_state = 0;
5648 qla83xx_idc_lock(base_vha, 0);
5649 qla83xx_rd_reg(base_vha, QLA83XX_IDC_DEV_STATE, &dev_state);
5650 if (dev_state == QLA8XXX_DEV_FAILED ||
5651 dev_state == QLA8XXX_DEV_NEED_QUIESCENT)
5652 qla83xx_idc_state_handler(base_vha);
5653 qla83xx_idc_unlock(base_vha, 0);
5657 qla83xx_check_nic_core_fw_alive(scsi_qla_host_t *base_vha)
5659 int rval = QLA_SUCCESS;
5660 unsigned long heart_beat_wait = jiffies + (1 * HZ);
5661 uint32_t heart_beat_counter1, heart_beat_counter2;
5664 if (time_after(jiffies, heart_beat_wait)) {
5665 ql_dbg(ql_dbg_p3p, base_vha, 0xb07c,
5666 "Nic Core f/w is not alive.\n");
5667 rval = QLA_FUNCTION_FAILED;
5671 qla83xx_idc_lock(base_vha, 0);
5672 qla83xx_rd_reg(base_vha, QLA83XX_FW_HEARTBEAT,
5673 &heart_beat_counter1);
5674 qla83xx_idc_unlock(base_vha, 0);
5676 qla83xx_idc_lock(base_vha, 0);
5677 qla83xx_rd_reg(base_vha, QLA83XX_FW_HEARTBEAT,
5678 &heart_beat_counter2);
5679 qla83xx_idc_unlock(base_vha, 0);
5680 } while (heart_beat_counter1 == heart_beat_counter2);
5685 /* Work: Perform NIC Core Reset handling */
5687 qla83xx_nic_core_reset_work(struct work_struct *work)
5689 struct qla_hw_data *ha =
5690 container_of(work, struct qla_hw_data, nic_core_reset);
5691 scsi_qla_host_t *base_vha = pci_get_drvdata(ha->pdev);
5692 uint32_t dev_state = 0;
5694 if (IS_QLA2031(ha)) {
5695 if (qla2xxx_mctp_dump(base_vha) != QLA_SUCCESS)
5696 ql_log(ql_log_warn, base_vha, 0xb081,
5697 "Failed to dump mctp\n");
5701 if (!ha->flags.nic_core_reset_hdlr_active) {
5702 if (qla83xx_check_nic_core_fw_alive(base_vha) == QLA_SUCCESS) {
5703 qla83xx_idc_lock(base_vha, 0);
5704 qla83xx_rd_reg(base_vha, QLA83XX_IDC_DEV_STATE,
5706 qla83xx_idc_unlock(base_vha, 0);
5707 if (dev_state != QLA8XXX_DEV_NEED_RESET) {
5708 ql_dbg(ql_dbg_p3p, base_vha, 0xb07a,
5709 "Nic Core f/w is alive.\n");
5714 ha->flags.nic_core_reset_hdlr_active = 1;
5715 if (qla83xx_nic_core_reset(base_vha)) {
5716 /* NIC Core reset failed. */
5717 ql_dbg(ql_dbg_p3p, base_vha, 0xb061,
5718 "NIC Core reset failed.\n");
5720 ha->flags.nic_core_reset_hdlr_active = 0;
5724 /* Work: Handle 8200 IDC aens */
5726 qla83xx_service_idc_aen(struct work_struct *work)
5728 struct qla_hw_data *ha =
5729 container_of(work, struct qla_hw_data, idc_aen);
5730 scsi_qla_host_t *base_vha = pci_get_drvdata(ha->pdev);
5731 uint32_t dev_state, idc_control;
5733 qla83xx_idc_lock(base_vha, 0);
5734 qla83xx_rd_reg(base_vha, QLA83XX_IDC_DEV_STATE, &dev_state);
5735 qla83xx_rd_reg(base_vha, QLA83XX_IDC_CONTROL, &idc_control);
5736 qla83xx_idc_unlock(base_vha, 0);
5737 if (dev_state == QLA8XXX_DEV_NEED_RESET) {
5738 if (idc_control & QLA83XX_IDC_GRACEFUL_RESET) {
5739 ql_dbg(ql_dbg_p3p, base_vha, 0xb062,
5740 "Application requested NIC Core Reset.\n");
5741 qla83xx_schedule_work(base_vha, QLA83XX_NIC_CORE_RESET);
5742 } else if (qla83xx_check_nic_core_fw_alive(base_vha) ==
5744 ql_dbg(ql_dbg_p3p, base_vha, 0xb07b,
5745 "Other protocol driver requested NIC Core Reset.\n");
5746 qla83xx_schedule_work(base_vha, QLA83XX_NIC_CORE_RESET);
5748 } else if (dev_state == QLA8XXX_DEV_FAILED ||
5749 dev_state == QLA8XXX_DEV_NEED_QUIESCENT) {
5750 qla83xx_schedule_work(base_vha, QLA83XX_IDC_STATE_HANDLER);
5755 * Control the frequency of IDC lock retries
5757 #define QLA83XX_WAIT_LOGIC_MS 100
5760 qla83xx_force_lock_recovery(scsi_qla_host_t *base_vha)
5764 uint32_t idc_lck_rcvry_stage_mask = 0x3;
5765 uint32_t idc_lck_rcvry_owner_mask = 0x3c;
5766 struct qla_hw_data *ha = base_vha->hw;
5768 ql_dbg(ql_dbg_p3p, base_vha, 0xb086,
5769 "Trying force recovery of the IDC lock.\n");
5771 rval = qla83xx_rd_reg(base_vha, QLA83XX_IDC_LOCK_RECOVERY, &data);
5775 if ((data & idc_lck_rcvry_stage_mask) > 0) {
5778 data = (IDC_LOCK_RECOVERY_STAGE1) | (ha->portnum << 2);
5779 rval = qla83xx_wr_reg(base_vha, QLA83XX_IDC_LOCK_RECOVERY,
5786 rval = qla83xx_rd_reg(base_vha, QLA83XX_IDC_LOCK_RECOVERY,
5791 if (((data & idc_lck_rcvry_owner_mask) >> 2) == ha->portnum) {
5792 data &= (IDC_LOCK_RECOVERY_STAGE2 |
5793 ~(idc_lck_rcvry_stage_mask));
5794 rval = qla83xx_wr_reg(base_vha,
5795 QLA83XX_IDC_LOCK_RECOVERY, data);
5799 /* Forcefully perform IDC UnLock */
5800 rval = qla83xx_rd_reg(base_vha, QLA83XX_DRIVER_UNLOCK,
5804 /* Clear lock-id by setting 0xff */
5805 rval = qla83xx_wr_reg(base_vha, QLA83XX_DRIVER_LOCKID,
5809 /* Clear lock-recovery by setting 0x0 */
5810 rval = qla83xx_wr_reg(base_vha,
5811 QLA83XX_IDC_LOCK_RECOVERY, 0x0);
5822 qla83xx_idc_lock_recovery(scsi_qla_host_t *base_vha)
5824 int rval = QLA_SUCCESS;
5825 uint32_t o_drv_lockid, n_drv_lockid;
5826 unsigned long lock_recovery_timeout;
5828 lock_recovery_timeout = jiffies + QLA83XX_MAX_LOCK_RECOVERY_WAIT;
5830 rval = qla83xx_rd_reg(base_vha, QLA83XX_DRIVER_LOCKID, &o_drv_lockid);
5834 /* MAX wait time before forcing IDC Lock recovery = 2 secs */
5835 if (time_after_eq(jiffies, lock_recovery_timeout)) {
5836 if (qla83xx_force_lock_recovery(base_vha) == QLA_SUCCESS)
5839 return QLA_FUNCTION_FAILED;
5842 rval = qla83xx_rd_reg(base_vha, QLA83XX_DRIVER_LOCKID, &n_drv_lockid);
5846 if (o_drv_lockid == n_drv_lockid) {
5847 msleep(QLA83XX_WAIT_LOGIC_MS);
5857 * Context: task, can sleep
5860 qla83xx_idc_lock(scsi_qla_host_t *base_vha, uint16_t requester_id)
5863 uint32_t lock_owner;
5864 struct qla_hw_data *ha = base_vha->hw;
5868 /* IDC-lock implementation using driver-lock/lock-id remote registers */
5870 if (qla83xx_rd_reg(base_vha, QLA83XX_DRIVER_LOCK, &data)
5873 /* Setting lock-id to our function-number */
5874 qla83xx_wr_reg(base_vha, QLA83XX_DRIVER_LOCKID,
5877 qla83xx_rd_reg(base_vha, QLA83XX_DRIVER_LOCKID,
5879 ql_dbg(ql_dbg_p3p, base_vha, 0xb063,
5880 "Failed to acquire IDC lock, acquired by %d, "
5881 "retrying...\n", lock_owner);
5883 /* Retry/Perform IDC-Lock recovery */
5884 if (qla83xx_idc_lock_recovery(base_vha)
5886 msleep(QLA83XX_WAIT_LOGIC_MS);
5889 ql_log(ql_log_warn, base_vha, 0xb075,
5890 "IDC Lock recovery FAILED.\n");
5899 qla25xx_rdp_rsp_reduce_size(struct scsi_qla_host *vha,
5900 struct purex_entry_24xx *purex)
5903 u32 sid = purex->s_id[2] << 16 | purex->s_id[1] << 8 | purex->s_id[0];
5904 struct port_database_24xx *pdb;
5906 /* Domain Controller is always logged-out. */
5907 /* if RDP request is not from Domain Controller: */
5908 if (sid != 0xfffc01)
5911 ql_dbg(ql_dbg_init, vha, 0x0181, "%s: s_id=%#x\n", __func__, sid);
5913 pdb = kzalloc(sizeof(*pdb), GFP_KERNEL);
5915 ql_dbg(ql_dbg_init, vha, 0x0181,
5916 "%s: Failed allocate pdb\n", __func__);
5917 } else if (qla24xx_get_port_database(vha,
5918 le16_to_cpu(purex->nport_handle), pdb)) {
5919 ql_dbg(ql_dbg_init, vha, 0x0181,
5920 "%s: Failed get pdb sid=%x\n", __func__, sid);
5921 } else if (pdb->current_login_state != PDS_PLOGI_COMPLETE &&
5922 pdb->current_login_state != PDS_PRLI_COMPLETE) {
5923 ql_dbg(ql_dbg_init, vha, 0x0181,
5924 "%s: Port not logged in sid=%#x\n", __func__, sid);
5926 /* RDP request is from logged in port */
5932 vha->hw->isp_ops->fw_version_str(vha, fwstr, sizeof(fwstr));
5933 fwstr[strcspn(fwstr, " ")] = 0;
5934 /* if FW version allows RDP response length upto 2048 bytes: */
5935 if (strcmp(fwstr, "8.09.00") > 0 || strcmp(fwstr, "8.05.65") == 0)
5938 ql_dbg(ql_dbg_init, vha, 0x0181, "%s: fw=%s\n", __func__, fwstr);
5940 /* RDP response length is to be reduced to maximum 256 bytes */
5945 * Function Name: qla24xx_process_purex_iocb
5948 * Prepare a RDP response and send to Fabric switch
5951 * vha: SCSI qla host
5952 * purex: RDP request received by HBA
5954 void qla24xx_process_purex_rdp(struct scsi_qla_host *vha,
5955 struct purex_item *item)
5957 struct qla_hw_data *ha = vha->hw;
5958 struct purex_entry_24xx *purex =
5959 (struct purex_entry_24xx *)&item->iocb;
5960 dma_addr_t rsp_els_dma;
5961 dma_addr_t rsp_payload_dma;
5962 dma_addr_t stat_dma;
5964 struct els_entry_24xx *rsp_els = NULL;
5965 struct rdp_rsp_payload *rsp_payload = NULL;
5966 struct link_statistics *stat = NULL;
5967 uint8_t *sfp = NULL;
5968 uint16_t sfp_flags = 0;
5969 uint rsp_payload_length = sizeof(*rsp_payload);
5972 ql_dbg(ql_dbg_init + ql_dbg_verbose, vha, 0x0180,
5973 "%s: Enter\n", __func__);
5975 ql_dbg(ql_dbg_init + ql_dbg_verbose, vha, 0x0181,
5976 "-------- ELS REQ -------\n");
5977 ql_dump_buffer(ql_dbg_init + ql_dbg_verbose, vha, 0x0182,
5978 purex, sizeof(*purex));
5980 if (qla25xx_rdp_rsp_reduce_size(vha, purex)) {
5981 rsp_payload_length =
5982 offsetof(typeof(*rsp_payload), optical_elmt_desc);
5983 ql_dbg(ql_dbg_init, vha, 0x0181,
5984 "Reducing RSP payload length to %u bytes...\n",
5985 rsp_payload_length);
5988 rsp_els = dma_alloc_coherent(&ha->pdev->dev, sizeof(*rsp_els),
5989 &rsp_els_dma, GFP_KERNEL);
5991 ql_log(ql_log_warn, vha, 0x0183,
5992 "Failed allocate dma buffer ELS RSP.\n");
5996 rsp_payload = dma_alloc_coherent(&ha->pdev->dev, sizeof(*rsp_payload),
5997 &rsp_payload_dma, GFP_KERNEL);
5999 ql_log(ql_log_warn, vha, 0x0184,
6000 "Failed allocate dma buffer ELS RSP payload.\n");
6004 sfp = dma_alloc_coherent(&ha->pdev->dev, SFP_RTDI_LEN,
6005 &sfp_dma, GFP_KERNEL);
6007 stat = dma_alloc_coherent(&ha->pdev->dev, sizeof(*stat),
6008 &stat_dma, GFP_KERNEL);
6010 /* Prepare Response IOCB */
6011 rsp_els->entry_type = ELS_IOCB_TYPE;
6012 rsp_els->entry_count = 1;
6013 rsp_els->sys_define = 0;
6014 rsp_els->entry_status = 0;
6015 rsp_els->handle = 0;
6016 rsp_els->nport_handle = purex->nport_handle;
6017 rsp_els->tx_dsd_count = cpu_to_le16(1);
6018 rsp_els->vp_index = purex->vp_idx;
6019 rsp_els->sof_type = EST_SOFI3;
6020 rsp_els->rx_xchg_address = purex->rx_xchg_addr;
6021 rsp_els->rx_dsd_count = 0;
6022 rsp_els->opcode = purex->els_frame_payload[0];
6024 rsp_els->d_id[0] = purex->s_id[0];
6025 rsp_els->d_id[1] = purex->s_id[1];
6026 rsp_els->d_id[2] = purex->s_id[2];
6028 rsp_els->control_flags = cpu_to_le16(EPD_ELS_ACC);
6029 rsp_els->rx_byte_count = 0;
6030 rsp_els->tx_byte_count = cpu_to_le32(rsp_payload_length);
6032 put_unaligned_le64(rsp_payload_dma, &rsp_els->tx_address);
6033 rsp_els->tx_len = rsp_els->tx_byte_count;
6035 rsp_els->rx_address = 0;
6036 rsp_els->rx_len = 0;
6038 /* Prepare Response Payload */
6039 rsp_payload->hdr.cmd = cpu_to_be32(0x2 << 24); /* LS_ACC */
6040 rsp_payload->hdr.len = cpu_to_be32(le32_to_cpu(rsp_els->tx_byte_count) -
6041 sizeof(rsp_payload->hdr));
6043 /* Link service Request Info Descriptor */
6044 rsp_payload->ls_req_info_desc.desc_tag = cpu_to_be32(0x1);
6045 rsp_payload->ls_req_info_desc.desc_len =
6046 cpu_to_be32(RDP_DESC_LEN(rsp_payload->ls_req_info_desc));
6047 rsp_payload->ls_req_info_desc.req_payload_word_0 =
6048 cpu_to_be32p((uint32_t *)purex->els_frame_payload);
6050 /* Link service Request Info Descriptor 2 */
6051 rsp_payload->ls_req_info_desc2.desc_tag = cpu_to_be32(0x1);
6052 rsp_payload->ls_req_info_desc2.desc_len =
6053 cpu_to_be32(RDP_DESC_LEN(rsp_payload->ls_req_info_desc2));
6054 rsp_payload->ls_req_info_desc2.req_payload_word_0 =
6055 cpu_to_be32p((uint32_t *)purex->els_frame_payload);
6058 rsp_payload->sfp_diag_desc.desc_tag = cpu_to_be32(0x10000);
6059 rsp_payload->sfp_diag_desc.desc_len =
6060 cpu_to_be32(RDP_DESC_LEN(rsp_payload->sfp_diag_desc));
6064 memset(sfp, 0, SFP_RTDI_LEN);
6065 rval = qla2x00_read_sfp(vha, sfp_dma, sfp, 0xa0, 0x7, 2, 0);
6067 /* SFP Flags bits 3-0: Port Tx Laser Type */
6068 if (sfp[0] & BIT_2 || sfp[1] & (BIT_6|BIT_5))
6069 sfp_flags |= BIT_0; /* short wave */
6070 else if (sfp[0] & BIT_1)
6071 sfp_flags |= BIT_1; /* long wave 1310nm */
6072 else if (sfp[1] & BIT_4)
6073 sfp_flags |= BIT_1|BIT_0; /* long wave 1550nm */
6077 memset(sfp, 0, SFP_RTDI_LEN);
6078 rval = qla2x00_read_sfp(vha, sfp_dma, sfp, 0xa0, 0x0, 1, 0);
6080 sfp_flags |= BIT_4; /* optical */
6082 sfp_flags |= BIT_6; /* sfp+ */
6085 rsp_payload->sfp_diag_desc.sfp_flags = cpu_to_be16(sfp_flags);
6087 /* SFP Diagnostics */
6088 memset(sfp, 0, SFP_RTDI_LEN);
6089 rval = qla2x00_read_sfp(vha, sfp_dma, sfp, 0xa2, 0x60, 10, 0);
6091 __be16 *trx = (__force __be16 *)sfp; /* already be16 */
6092 rsp_payload->sfp_diag_desc.temperature = trx[0];
6093 rsp_payload->sfp_diag_desc.vcc = trx[1];
6094 rsp_payload->sfp_diag_desc.tx_bias = trx[2];
6095 rsp_payload->sfp_diag_desc.tx_power = trx[3];
6096 rsp_payload->sfp_diag_desc.rx_power = trx[4];
6100 /* Port Speed Descriptor */
6101 rsp_payload->port_speed_desc.desc_tag = cpu_to_be32(0x10001);
6102 rsp_payload->port_speed_desc.desc_len =
6103 cpu_to_be32(RDP_DESC_LEN(rsp_payload->port_speed_desc));
6104 rsp_payload->port_speed_desc.speed_capab = cpu_to_be16(
6105 qla25xx_fdmi_port_speed_capability(ha));
6106 rsp_payload->port_speed_desc.operating_speed = cpu_to_be16(
6107 qla25xx_fdmi_port_speed_currently(ha));
6109 /* Link Error Status Descriptor */
6110 rsp_payload->ls_err_desc.desc_tag = cpu_to_be32(0x10002);
6111 rsp_payload->ls_err_desc.desc_len =
6112 cpu_to_be32(RDP_DESC_LEN(rsp_payload->ls_err_desc));
6115 rval = qla24xx_get_isp_stats(vha, stat, stat_dma, 0);
6117 rsp_payload->ls_err_desc.link_fail_cnt =
6118 cpu_to_be32(le32_to_cpu(stat->link_fail_cnt));
6119 rsp_payload->ls_err_desc.loss_sync_cnt =
6120 cpu_to_be32(le32_to_cpu(stat->loss_sync_cnt));
6121 rsp_payload->ls_err_desc.loss_sig_cnt =
6122 cpu_to_be32(le32_to_cpu(stat->loss_sig_cnt));
6123 rsp_payload->ls_err_desc.prim_seq_err_cnt =
6124 cpu_to_be32(le32_to_cpu(stat->prim_seq_err_cnt));
6125 rsp_payload->ls_err_desc.inval_xmit_word_cnt =
6126 cpu_to_be32(le32_to_cpu(stat->inval_xmit_word_cnt));
6127 rsp_payload->ls_err_desc.inval_crc_cnt =
6128 cpu_to_be32(le32_to_cpu(stat->inval_crc_cnt));
6129 rsp_payload->ls_err_desc.pn_port_phy_type |= BIT_6;
6133 /* Portname Descriptor */
6134 rsp_payload->port_name_diag_desc.desc_tag = cpu_to_be32(0x10003);
6135 rsp_payload->port_name_diag_desc.desc_len =
6136 cpu_to_be32(RDP_DESC_LEN(rsp_payload->port_name_diag_desc));
6137 memcpy(rsp_payload->port_name_diag_desc.WWNN,
6139 sizeof(rsp_payload->port_name_diag_desc.WWNN));
6140 memcpy(rsp_payload->port_name_diag_desc.WWPN,
6142 sizeof(rsp_payload->port_name_diag_desc.WWPN));
6144 /* F-Port Portname Descriptor */
6145 rsp_payload->port_name_direct_desc.desc_tag = cpu_to_be32(0x10003);
6146 rsp_payload->port_name_direct_desc.desc_len =
6147 cpu_to_be32(RDP_DESC_LEN(rsp_payload->port_name_direct_desc));
6148 memcpy(rsp_payload->port_name_direct_desc.WWNN,
6149 vha->fabric_node_name,
6150 sizeof(rsp_payload->port_name_direct_desc.WWNN));
6151 memcpy(rsp_payload->port_name_direct_desc.WWPN,
6152 vha->fabric_port_name,
6153 sizeof(rsp_payload->port_name_direct_desc.WWPN));
6155 /* Bufer Credit Descriptor */
6156 rsp_payload->buffer_credit_desc.desc_tag = cpu_to_be32(0x10006);
6157 rsp_payload->buffer_credit_desc.desc_len =
6158 cpu_to_be32(RDP_DESC_LEN(rsp_payload->buffer_credit_desc));
6159 rsp_payload->buffer_credit_desc.fcport_b2b = 0;
6160 rsp_payload->buffer_credit_desc.attached_fcport_b2b = cpu_to_be32(0);
6161 rsp_payload->buffer_credit_desc.fcport_rtt = cpu_to_be32(0);
6163 if (ha->flags.plogi_template_valid) {
6165 be16_to_cpu(ha->plogi_els_payld.fl_csp.sp_bb_cred);
6166 rsp_payload->buffer_credit_desc.fcport_b2b = cpu_to_be32(tmp);
6169 if (rsp_payload_length < sizeof(*rsp_payload))
6172 /* Optical Element Descriptor, Temperature */
6173 rsp_payload->optical_elmt_desc[0].desc_tag = cpu_to_be32(0x10007);
6174 rsp_payload->optical_elmt_desc[0].desc_len =
6175 cpu_to_be32(RDP_DESC_LEN(*rsp_payload->optical_elmt_desc));
6176 /* Optical Element Descriptor, Voltage */
6177 rsp_payload->optical_elmt_desc[1].desc_tag = cpu_to_be32(0x10007);
6178 rsp_payload->optical_elmt_desc[1].desc_len =
6179 cpu_to_be32(RDP_DESC_LEN(*rsp_payload->optical_elmt_desc));
6180 /* Optical Element Descriptor, Tx Bias Current */
6181 rsp_payload->optical_elmt_desc[2].desc_tag = cpu_to_be32(0x10007);
6182 rsp_payload->optical_elmt_desc[2].desc_len =
6183 cpu_to_be32(RDP_DESC_LEN(*rsp_payload->optical_elmt_desc));
6184 /* Optical Element Descriptor, Tx Power */
6185 rsp_payload->optical_elmt_desc[3].desc_tag = cpu_to_be32(0x10007);
6186 rsp_payload->optical_elmt_desc[3].desc_len =
6187 cpu_to_be32(RDP_DESC_LEN(*rsp_payload->optical_elmt_desc));
6188 /* Optical Element Descriptor, Rx Power */
6189 rsp_payload->optical_elmt_desc[4].desc_tag = cpu_to_be32(0x10007);
6190 rsp_payload->optical_elmt_desc[4].desc_len =
6191 cpu_to_be32(RDP_DESC_LEN(*rsp_payload->optical_elmt_desc));
6194 memset(sfp, 0, SFP_RTDI_LEN);
6195 rval = qla2x00_read_sfp(vha, sfp_dma, sfp, 0xa2, 0, 64, 0);
6197 __be16 *trx = (__force __be16 *)sfp; /* already be16 */
6199 /* Optical Element Descriptor, Temperature */
6200 rsp_payload->optical_elmt_desc[0].high_alarm = trx[0];
6201 rsp_payload->optical_elmt_desc[0].low_alarm = trx[1];
6202 rsp_payload->optical_elmt_desc[0].high_warn = trx[2];
6203 rsp_payload->optical_elmt_desc[0].low_warn = trx[3];
6204 rsp_payload->optical_elmt_desc[0].element_flags =
6205 cpu_to_be32(1 << 28);
6207 /* Optical Element Descriptor, Voltage */
6208 rsp_payload->optical_elmt_desc[1].high_alarm = trx[4];
6209 rsp_payload->optical_elmt_desc[1].low_alarm = trx[5];
6210 rsp_payload->optical_elmt_desc[1].high_warn = trx[6];
6211 rsp_payload->optical_elmt_desc[1].low_warn = trx[7];
6212 rsp_payload->optical_elmt_desc[1].element_flags =
6213 cpu_to_be32(2 << 28);
6215 /* Optical Element Descriptor, Tx Bias Current */
6216 rsp_payload->optical_elmt_desc[2].high_alarm = trx[8];
6217 rsp_payload->optical_elmt_desc[2].low_alarm = trx[9];
6218 rsp_payload->optical_elmt_desc[2].high_warn = trx[10];
6219 rsp_payload->optical_elmt_desc[2].low_warn = trx[11];
6220 rsp_payload->optical_elmt_desc[2].element_flags =
6221 cpu_to_be32(3 << 28);
6223 /* Optical Element Descriptor, Tx Power */
6224 rsp_payload->optical_elmt_desc[3].high_alarm = trx[12];
6225 rsp_payload->optical_elmt_desc[3].low_alarm = trx[13];
6226 rsp_payload->optical_elmt_desc[3].high_warn = trx[14];
6227 rsp_payload->optical_elmt_desc[3].low_warn = trx[15];
6228 rsp_payload->optical_elmt_desc[3].element_flags =
6229 cpu_to_be32(4 << 28);
6231 /* Optical Element Descriptor, Rx Power */
6232 rsp_payload->optical_elmt_desc[4].high_alarm = trx[16];
6233 rsp_payload->optical_elmt_desc[4].low_alarm = trx[17];
6234 rsp_payload->optical_elmt_desc[4].high_warn = trx[18];
6235 rsp_payload->optical_elmt_desc[4].low_warn = trx[19];
6236 rsp_payload->optical_elmt_desc[4].element_flags =
6237 cpu_to_be32(5 << 28);
6240 memset(sfp, 0, SFP_RTDI_LEN);
6241 rval = qla2x00_read_sfp(vha, sfp_dma, sfp, 0xa2, 112, 64, 0);
6243 /* Temperature high/low alarm/warning */
6244 rsp_payload->optical_elmt_desc[0].element_flags |=
6246 (sfp[0] >> 7 & 1) << 3 |
6247 (sfp[0] >> 6 & 1) << 2 |
6248 (sfp[4] >> 7 & 1) << 1 |
6249 (sfp[4] >> 6 & 1) << 0);
6251 /* Voltage high/low alarm/warning */
6252 rsp_payload->optical_elmt_desc[1].element_flags |=
6254 (sfp[0] >> 5 & 1) << 3 |
6255 (sfp[0] >> 4 & 1) << 2 |
6256 (sfp[4] >> 5 & 1) << 1 |
6257 (sfp[4] >> 4 & 1) << 0);
6259 /* Tx Bias Current high/low alarm/warning */
6260 rsp_payload->optical_elmt_desc[2].element_flags |=
6262 (sfp[0] >> 3 & 1) << 3 |
6263 (sfp[0] >> 2 & 1) << 2 |
6264 (sfp[4] >> 3 & 1) << 1 |
6265 (sfp[4] >> 2 & 1) << 0);
6267 /* Tx Power high/low alarm/warning */
6268 rsp_payload->optical_elmt_desc[3].element_flags |=
6270 (sfp[0] >> 1 & 1) << 3 |
6271 (sfp[0] >> 0 & 1) << 2 |
6272 (sfp[4] >> 1 & 1) << 1 |
6273 (sfp[4] >> 0 & 1) << 0);
6275 /* Rx Power high/low alarm/warning */
6276 rsp_payload->optical_elmt_desc[4].element_flags |=
6278 (sfp[1] >> 7 & 1) << 3 |
6279 (sfp[1] >> 6 & 1) << 2 |
6280 (sfp[5] >> 7 & 1) << 1 |
6281 (sfp[5] >> 6 & 1) << 0);
6285 /* Optical Product Data Descriptor */
6286 rsp_payload->optical_prod_desc.desc_tag = cpu_to_be32(0x10008);
6287 rsp_payload->optical_prod_desc.desc_len =
6288 cpu_to_be32(RDP_DESC_LEN(rsp_payload->optical_prod_desc));
6291 memset(sfp, 0, SFP_RTDI_LEN);
6292 rval = qla2x00_read_sfp(vha, sfp_dma, sfp, 0xa0, 20, 64, 0);
6294 memcpy(rsp_payload->optical_prod_desc.vendor_name,
6296 sizeof(rsp_payload->optical_prod_desc.vendor_name));
6297 memcpy(rsp_payload->optical_prod_desc.part_number,
6299 sizeof(rsp_payload->optical_prod_desc.part_number));
6300 memcpy(rsp_payload->optical_prod_desc.revision,
6302 sizeof(rsp_payload->optical_prod_desc.revision));
6303 memcpy(rsp_payload->optical_prod_desc.serial_number,
6305 sizeof(rsp_payload->optical_prod_desc.serial_number));
6308 memset(sfp, 0, SFP_RTDI_LEN);
6309 rval = qla2x00_read_sfp(vha, sfp_dma, sfp, 0xa0, 84, 8, 0);
6311 memcpy(rsp_payload->optical_prod_desc.date,
6313 sizeof(rsp_payload->optical_prod_desc.date));
6318 ql_dbg(ql_dbg_init, vha, 0x0183,
6319 "Sending ELS Response to RDP Request...\n");
6320 ql_dbg(ql_dbg_init + ql_dbg_verbose, vha, 0x0184,
6321 "-------- ELS RSP -------\n");
6322 ql_dump_buffer(ql_dbg_init + ql_dbg_verbose, vha, 0x0185,
6323 rsp_els, sizeof(*rsp_els));
6324 ql_dbg(ql_dbg_init + ql_dbg_verbose, vha, 0x0186,
6325 "-------- ELS RSP PAYLOAD -------\n");
6326 ql_dump_buffer(ql_dbg_init + ql_dbg_verbose, vha, 0x0187,
6327 rsp_payload, rsp_payload_length);
6329 rval = qla2x00_issue_iocb(vha, rsp_els, rsp_els_dma, 0);
6332 ql_log(ql_log_warn, vha, 0x0188,
6333 "%s: iocb failed to execute -> %x\n", __func__, rval);
6334 } else if (rsp_els->comp_status) {
6335 ql_log(ql_log_warn, vha, 0x0189,
6336 "%s: iocb failed to complete -> completion=%#x subcode=(%#x,%#x)\n",
6337 __func__, rsp_els->comp_status,
6338 rsp_els->error_subcode_1, rsp_els->error_subcode_2);
6340 ql_dbg(ql_dbg_init, vha, 0x018a, "%s: done.\n", __func__);
6345 dma_free_coherent(&ha->pdev->dev, sizeof(*stat),
6348 dma_free_coherent(&ha->pdev->dev, SFP_RTDI_LEN,
6351 dma_free_coherent(&ha->pdev->dev, sizeof(*rsp_payload),
6352 rsp_payload, rsp_payload_dma);
6354 dma_free_coherent(&ha->pdev->dev, sizeof(*rsp_els),
6355 rsp_els, rsp_els_dma);
6359 qla24xx_free_purex_item(struct purex_item *item)
6361 if (item == &item->vha->default_item)
6362 memset(&item->vha->default_item, 0, sizeof(struct purex_item));
6367 void qla24xx_process_purex_list(struct purex_list *list)
6369 struct list_head head = LIST_HEAD_INIT(head);
6370 struct purex_item *item, *next;
6373 spin_lock_irqsave(&list->lock, flags);
6374 list_splice_init(&list->head, &head);
6375 spin_unlock_irqrestore(&list->lock, flags);
6377 list_for_each_entry_safe(item, next, &head, list) {
6378 list_del(&item->list);
6379 item->process_item(item->vha, item);
6380 qla24xx_free_purex_item(item);
6385 * Context: task, can sleep
6388 qla83xx_idc_unlock(scsi_qla_host_t *base_vha, uint16_t requester_id)
6391 uint16_t options = (requester_id << 15) | BIT_7;
6395 struct qla_hw_data *ha = base_vha->hw;
6399 /* IDC-unlock implementation using driver-unlock/lock-id
6404 if (qla83xx_rd_reg(base_vha, QLA83XX_DRIVER_LOCKID, &data)
6406 if (data == ha->portnum) {
6407 qla83xx_rd_reg(base_vha, QLA83XX_DRIVER_UNLOCK, &data);
6408 /* Clearing lock-id by setting 0xff */
6409 qla83xx_wr_reg(base_vha, QLA83XX_DRIVER_LOCKID, 0xff);
6410 } else if (retry < 10) {
6411 /* SV: XXX: IDC unlock retrying needed here? */
6413 /* Retry for IDC-unlock */
6414 msleep(QLA83XX_WAIT_LOGIC_MS);
6416 ql_dbg(ql_dbg_p3p, base_vha, 0xb064,
6417 "Failed to release IDC lock, retrying=%d\n", retry);
6420 } else if (retry < 10) {
6421 /* Retry for IDC-unlock */
6422 msleep(QLA83XX_WAIT_LOGIC_MS);
6424 ql_dbg(ql_dbg_p3p, base_vha, 0xb065,
6425 "Failed to read drv-lockid, retrying=%d\n", retry);
6432 /* XXX: IDC-unlock implementation using access-control mbx */
6435 if (qla83xx_access_control(base_vha, options, 0, 0, NULL)) {
6437 /* Retry for IDC-unlock */
6438 msleep(QLA83XX_WAIT_LOGIC_MS);
6440 ql_dbg(ql_dbg_p3p, base_vha, 0xb066,
6441 "Failed to release IDC lock, retrying=%d\n", retry);
6451 __qla83xx_set_drv_presence(scsi_qla_host_t *vha)
6453 int rval = QLA_SUCCESS;
6454 struct qla_hw_data *ha = vha->hw;
6455 uint32_t drv_presence;
6457 rval = qla83xx_rd_reg(vha, QLA83XX_IDC_DRV_PRESENCE, &drv_presence);
6458 if (rval == QLA_SUCCESS) {
6459 drv_presence |= (1 << ha->portnum);
6460 rval = qla83xx_wr_reg(vha, QLA83XX_IDC_DRV_PRESENCE,
6468 qla83xx_set_drv_presence(scsi_qla_host_t *vha)
6470 int rval = QLA_SUCCESS;
6472 qla83xx_idc_lock(vha, 0);
6473 rval = __qla83xx_set_drv_presence(vha);
6474 qla83xx_idc_unlock(vha, 0);
6480 __qla83xx_clear_drv_presence(scsi_qla_host_t *vha)
6482 int rval = QLA_SUCCESS;
6483 struct qla_hw_data *ha = vha->hw;
6484 uint32_t drv_presence;
6486 rval = qla83xx_rd_reg(vha, QLA83XX_IDC_DRV_PRESENCE, &drv_presence);
6487 if (rval == QLA_SUCCESS) {
6488 drv_presence &= ~(1 << ha->portnum);
6489 rval = qla83xx_wr_reg(vha, QLA83XX_IDC_DRV_PRESENCE,
6497 qla83xx_clear_drv_presence(scsi_qla_host_t *vha)
6499 int rval = QLA_SUCCESS;
6501 qla83xx_idc_lock(vha, 0);
6502 rval = __qla83xx_clear_drv_presence(vha);
6503 qla83xx_idc_unlock(vha, 0);
6509 qla83xx_need_reset_handler(scsi_qla_host_t *vha)
6511 struct qla_hw_data *ha = vha->hw;
6512 uint32_t drv_ack, drv_presence;
6513 unsigned long ack_timeout;
6515 /* Wait for IDC ACK from all functions (DRV-ACK == DRV-PRESENCE) */
6516 ack_timeout = jiffies + (ha->fcoe_reset_timeout * HZ);
6518 qla83xx_rd_reg(vha, QLA83XX_IDC_DRIVER_ACK, &drv_ack);
6519 qla83xx_rd_reg(vha, QLA83XX_IDC_DRV_PRESENCE, &drv_presence);
6520 if ((drv_ack & drv_presence) == drv_presence)
6523 if (time_after_eq(jiffies, ack_timeout)) {
6524 ql_log(ql_log_warn, vha, 0xb067,
6525 "RESET ACK TIMEOUT! drv_presence=0x%x "
6526 "drv_ack=0x%x\n", drv_presence, drv_ack);
6528 * The function(s) which did not ack in time are forced
6529 * to withdraw any further participation in the IDC
6532 if (drv_ack != drv_presence)
6533 qla83xx_wr_reg(vha, QLA83XX_IDC_DRV_PRESENCE,
6538 qla83xx_idc_unlock(vha, 0);
6540 qla83xx_idc_lock(vha, 0);
6543 qla83xx_wr_reg(vha, QLA83XX_IDC_DEV_STATE, QLA8XXX_DEV_COLD);
6544 ql_log(ql_log_info, vha, 0xb068, "HW State: COLD/RE-INIT.\n");
6548 qla83xx_device_bootstrap(scsi_qla_host_t *vha)
6550 int rval = QLA_SUCCESS;
6551 uint32_t idc_control;
6553 qla83xx_wr_reg(vha, QLA83XX_IDC_DEV_STATE, QLA8XXX_DEV_INITIALIZING);
6554 ql_log(ql_log_info, vha, 0xb069, "HW State: INITIALIZING.\n");
6556 /* Clearing IDC-Control Graceful-Reset Bit before resetting f/w */
6557 __qla83xx_get_idc_control(vha, &idc_control);
6558 idc_control &= ~QLA83XX_IDC_GRACEFUL_RESET;
6559 __qla83xx_set_idc_control(vha, 0);
6561 qla83xx_idc_unlock(vha, 0);
6562 rval = qla83xx_restart_nic_firmware(vha);
6563 qla83xx_idc_lock(vha, 0);
6565 if (rval != QLA_SUCCESS) {
6566 ql_log(ql_log_fatal, vha, 0xb06a,
6567 "Failed to restart NIC f/w.\n");
6568 qla83xx_wr_reg(vha, QLA83XX_IDC_DEV_STATE, QLA8XXX_DEV_FAILED);
6569 ql_log(ql_log_info, vha, 0xb06b, "HW State: FAILED.\n");
6571 ql_dbg(ql_dbg_p3p, vha, 0xb06c,
6572 "Success in restarting nic f/w.\n");
6573 qla83xx_wr_reg(vha, QLA83XX_IDC_DEV_STATE, QLA8XXX_DEV_READY);
6574 ql_log(ql_log_info, vha, 0xb06d, "HW State: READY.\n");
6580 /* Assumes idc_lock always held on entry */
6582 qla83xx_idc_state_handler(scsi_qla_host_t *base_vha)
6584 struct qla_hw_data *ha = base_vha->hw;
6585 int rval = QLA_SUCCESS;
6586 unsigned long dev_init_timeout;
6589 /* Wait for MAX-INIT-TIMEOUT for the device to go ready */
6590 dev_init_timeout = jiffies + (ha->fcoe_dev_init_timeout * HZ);
6594 if (time_after_eq(jiffies, dev_init_timeout)) {
6595 ql_log(ql_log_warn, base_vha, 0xb06e,
6596 "Initialization TIMEOUT!\n");
6597 /* Init timeout. Disable further NIC Core
6600 qla83xx_wr_reg(base_vha, QLA83XX_IDC_DEV_STATE,
6601 QLA8XXX_DEV_FAILED);
6602 ql_log(ql_log_info, base_vha, 0xb06f,
6603 "HW State: FAILED.\n");
6606 qla83xx_rd_reg(base_vha, QLA83XX_IDC_DEV_STATE, &dev_state);
6607 switch (dev_state) {
6608 case QLA8XXX_DEV_READY:
6609 if (ha->flags.nic_core_reset_owner)
6610 qla83xx_idc_audit(base_vha,
6611 IDC_AUDIT_COMPLETION);
6612 ha->flags.nic_core_reset_owner = 0;
6613 ql_dbg(ql_dbg_p3p, base_vha, 0xb070,
6614 "Reset_owner reset by 0x%x.\n",
6617 case QLA8XXX_DEV_COLD:
6618 if (ha->flags.nic_core_reset_owner)
6619 rval = qla83xx_device_bootstrap(base_vha);
6621 /* Wait for AEN to change device-state */
6622 qla83xx_idc_unlock(base_vha, 0);
6624 qla83xx_idc_lock(base_vha, 0);
6627 case QLA8XXX_DEV_INITIALIZING:
6628 /* Wait for AEN to change device-state */
6629 qla83xx_idc_unlock(base_vha, 0);
6631 qla83xx_idc_lock(base_vha, 0);
6633 case QLA8XXX_DEV_NEED_RESET:
6634 if (!ql2xdontresethba && ha->flags.nic_core_reset_owner)
6635 qla83xx_need_reset_handler(base_vha);
6637 /* Wait for AEN to change device-state */
6638 qla83xx_idc_unlock(base_vha, 0);
6640 qla83xx_idc_lock(base_vha, 0);
6642 /* reset timeout value after need reset handler */
6643 dev_init_timeout = jiffies +
6644 (ha->fcoe_dev_init_timeout * HZ);
6646 case QLA8XXX_DEV_NEED_QUIESCENT:
6647 /* XXX: DEBUG for now */
6648 qla83xx_idc_unlock(base_vha, 0);
6650 qla83xx_idc_lock(base_vha, 0);
6652 case QLA8XXX_DEV_QUIESCENT:
6653 /* XXX: DEBUG for now */
6654 if (ha->flags.quiesce_owner)
6657 qla83xx_idc_unlock(base_vha, 0);
6659 qla83xx_idc_lock(base_vha, 0);
6660 dev_init_timeout = jiffies +
6661 (ha->fcoe_dev_init_timeout * HZ);
6663 case QLA8XXX_DEV_FAILED:
6664 if (ha->flags.nic_core_reset_owner)
6665 qla83xx_idc_audit(base_vha,
6666 IDC_AUDIT_COMPLETION);
6667 ha->flags.nic_core_reset_owner = 0;
6668 __qla83xx_clear_drv_presence(base_vha);
6669 qla83xx_idc_unlock(base_vha, 0);
6670 qla8xxx_dev_failed_handler(base_vha);
6671 rval = QLA_FUNCTION_FAILED;
6672 qla83xx_idc_lock(base_vha, 0);
6674 case QLA8XXX_BAD_VALUE:
6675 qla83xx_idc_unlock(base_vha, 0);
6677 qla83xx_idc_lock(base_vha, 0);
6680 ql_log(ql_log_warn, base_vha, 0xb071,
6681 "Unknown Device State: %x.\n", dev_state);
6682 qla83xx_idc_unlock(base_vha, 0);
6683 qla8xxx_dev_failed_handler(base_vha);
6684 rval = QLA_FUNCTION_FAILED;
6685 qla83xx_idc_lock(base_vha, 0);
6695 qla2x00_disable_board_on_pci_error(struct work_struct *work)
6697 struct qla_hw_data *ha = container_of(work, struct qla_hw_data,
6699 struct pci_dev *pdev = ha->pdev;
6700 scsi_qla_host_t *base_vha = pci_get_drvdata(ha->pdev);
6702 ql_log(ql_log_warn, base_vha, 0x015b,
6703 "Disabling adapter.\n");
6705 if (!atomic_read(&pdev->enable_cnt)) {
6706 ql_log(ql_log_info, base_vha, 0xfffc,
6707 "PCI device disabled, no action req for PCI error=%lx\n",
6708 base_vha->pci_flags);
6713 * if UNLOADING flag is already set, then continue unload,
6714 * where it was set first.
6716 if (test_and_set_bit(UNLOADING, &base_vha->dpc_flags))
6719 qla2x00_wait_for_sess_deletion(base_vha);
6721 qla2x00_delete_all_vps(ha, base_vha);
6723 qla2x00_abort_all_cmds(base_vha, DID_NO_CONNECT << 16);
6725 qla2x00_dfs_remove(base_vha);
6727 qla84xx_put_chip(base_vha);
6729 if (base_vha->timer_active)
6730 qla2x00_stop_timer(base_vha);
6732 base_vha->flags.online = 0;
6734 qla2x00_destroy_deferred_work(ha);
6737 * Do not try to stop beacon blink as it will issue a mailbox
6740 qla2x00_free_sysfs_attr(base_vha, false);
6742 fc_remove_host(base_vha->host);
6744 scsi_remove_host(base_vha->host);
6746 base_vha->flags.init_done = 0;
6747 qla25xx_delete_queues(base_vha);
6748 qla2x00_free_fcports(base_vha);
6749 qla2x00_free_irqs(base_vha);
6750 qla2x00_mem_free(ha);
6751 qla82xx_md_free(base_vha);
6752 qla2x00_free_queues(ha);
6754 qla2x00_unmap_iobases(ha);
6756 pci_release_selected_regions(ha->pdev, ha->bars);
6757 pci_disable_pcie_error_reporting(pdev);
6758 pci_disable_device(pdev);
6761 * Let qla2x00_remove_one cleanup qla_hw_data on device removal.
6765 /**************************************************************************
6767 * This kernel thread is a task that is schedule by the interrupt handler
6768 * to perform the background processing for interrupts.
6771 * This task always run in the context of a kernel thread. It
6772 * is kick-off by the driver's detect code and starts up
6773 * up one per adapter. It immediately goes to sleep and waits for
6774 * some fibre event. When either the interrupt handler or
6775 * the timer routine detects a event it will one of the task
6776 * bits then wake us up.
6777 **************************************************************************/
6779 qla2x00_do_dpc(void *data)
6781 scsi_qla_host_t *base_vha;
6782 struct qla_hw_data *ha;
6784 struct qla_qpair *qpair;
6786 ha = (struct qla_hw_data *)data;
6787 base_vha = pci_get_drvdata(ha->pdev);
6789 set_user_nice(current, MIN_NICE);
6791 set_current_state(TASK_INTERRUPTIBLE);
6792 while (!kthread_should_stop()) {
6793 ql_dbg(ql_dbg_dpc, base_vha, 0x4000,
6794 "DPC handler sleeping.\n");
6798 if (test_and_clear_bit(DO_EEH_RECOVERY, &base_vha->dpc_flags))
6799 qla_pci_set_eeh_busy(base_vha);
6801 if (!base_vha->flags.init_done || ha->flags.mbox_busy)
6804 if (ha->flags.eeh_busy) {
6805 ql_dbg(ql_dbg_dpc, base_vha, 0x4003,
6806 "eeh_busy=%d.\n", ha->flags.eeh_busy);
6812 ql_dbg(ql_dbg_dpc + ql_dbg_verbose, base_vha, 0x4001,
6813 "DPC handler waking up, dpc_flags=0x%lx.\n",
6814 base_vha->dpc_flags);
6816 if (test_bit(UNLOADING, &base_vha->dpc_flags))
6819 if (IS_P3P_TYPE(ha)) {
6820 if (IS_QLA8044(ha)) {
6821 if (test_and_clear_bit(ISP_UNRECOVERABLE,
6822 &base_vha->dpc_flags)) {
6823 qla8044_idc_lock(ha);
6824 qla8044_wr_direct(base_vha,
6825 QLA8044_CRB_DEV_STATE_INDEX,
6826 QLA8XXX_DEV_FAILED);
6827 qla8044_idc_unlock(ha);
6828 ql_log(ql_log_info, base_vha, 0x4004,
6829 "HW State: FAILED.\n");
6830 qla8044_device_state_handler(base_vha);
6835 if (test_and_clear_bit(ISP_UNRECOVERABLE,
6836 &base_vha->dpc_flags)) {
6837 qla82xx_idc_lock(ha);
6838 qla82xx_wr_32(ha, QLA82XX_CRB_DEV_STATE,
6839 QLA8XXX_DEV_FAILED);
6840 qla82xx_idc_unlock(ha);
6841 ql_log(ql_log_info, base_vha, 0x0151,
6842 "HW State: FAILED.\n");
6843 qla82xx_device_state_handler(base_vha);
6848 if (test_and_clear_bit(FCOE_CTX_RESET_NEEDED,
6849 &base_vha->dpc_flags)) {
6851 ql_dbg(ql_dbg_dpc, base_vha, 0x4005,
6852 "FCoE context reset scheduled.\n");
6853 if (!(test_and_set_bit(ABORT_ISP_ACTIVE,
6854 &base_vha->dpc_flags))) {
6855 if (qla82xx_fcoe_ctx_reset(base_vha)) {
6856 /* FCoE-ctx reset failed.
6857 * Escalate to chip-reset
6859 set_bit(ISP_ABORT_NEEDED,
6860 &base_vha->dpc_flags);
6862 clear_bit(ABORT_ISP_ACTIVE,
6863 &base_vha->dpc_flags);
6866 ql_dbg(ql_dbg_dpc, base_vha, 0x4006,
6867 "FCoE context reset end.\n");
6869 } else if (IS_QLAFX00(ha)) {
6870 if (test_and_clear_bit(ISP_UNRECOVERABLE,
6871 &base_vha->dpc_flags)) {
6872 ql_dbg(ql_dbg_dpc, base_vha, 0x4020,
6873 "Firmware Reset Recovery\n");
6874 if (qlafx00_reset_initialize(base_vha)) {
6875 /* Failed. Abort isp later. */
6876 if (!test_bit(UNLOADING,
6877 &base_vha->dpc_flags)) {
6878 set_bit(ISP_UNRECOVERABLE,
6879 &base_vha->dpc_flags);
6880 ql_dbg(ql_dbg_dpc, base_vha,
6882 "Reset Recovery Failed\n");
6887 if (test_and_clear_bit(FX00_TARGET_SCAN,
6888 &base_vha->dpc_flags)) {
6889 ql_dbg(ql_dbg_dpc, base_vha, 0x4022,
6890 "ISPFx00 Target Scan scheduled\n");
6891 if (qlafx00_rescan_isp(base_vha)) {
6892 if (!test_bit(UNLOADING,
6893 &base_vha->dpc_flags))
6894 set_bit(ISP_UNRECOVERABLE,
6895 &base_vha->dpc_flags);
6896 ql_dbg(ql_dbg_dpc, base_vha, 0x401e,
6897 "ISPFx00 Target Scan Failed\n");
6899 ql_dbg(ql_dbg_dpc, base_vha, 0x401f,
6900 "ISPFx00 Target Scan End\n");
6902 if (test_and_clear_bit(FX00_HOST_INFO_RESEND,
6903 &base_vha->dpc_flags)) {
6904 ql_dbg(ql_dbg_dpc, base_vha, 0x4023,
6905 "ISPFx00 Host Info resend scheduled\n");
6906 qlafx00_fx_disc(base_vha,
6907 &base_vha->hw->mr.fcport,
6908 FXDISC_REG_HOST_INFO);
6912 if (test_and_clear_bit(DETECT_SFP_CHANGE,
6913 &base_vha->dpc_flags)) {
6915 * - NO-OP -- await next ISP-ABORT. Preferred method
6916 * to minimize disruptions that will occur
6917 * when a forced chip-reset occurs.
6918 * - Force -- ISP-ABORT scheduled.
6920 /* set_bit(ISP_ABORT_NEEDED, &base_vha->dpc_flags); */
6923 if (test_and_clear_bit
6924 (ISP_ABORT_NEEDED, &base_vha->dpc_flags) &&
6925 !test_bit(UNLOADING, &base_vha->dpc_flags)) {
6926 bool do_reset = true;
6928 switch (base_vha->qlini_mode) {
6929 case QLA2XXX_INI_MODE_ENABLED:
6931 case QLA2XXX_INI_MODE_DISABLED:
6932 if (!qla_tgt_mode_enabled(base_vha) &&
6933 !ha->flags.fw_started)
6936 case QLA2XXX_INI_MODE_DUAL:
6937 if (!qla_dual_mode_enabled(base_vha) &&
6938 !ha->flags.fw_started)
6945 if (do_reset && !(test_and_set_bit(ABORT_ISP_ACTIVE,
6946 &base_vha->dpc_flags))) {
6947 base_vha->flags.online = 1;
6948 ql_dbg(ql_dbg_dpc, base_vha, 0x4007,
6949 "ISP abort scheduled.\n");
6950 if (ha->isp_ops->abort_isp(base_vha)) {
6951 /* failed. retry later */
6952 set_bit(ISP_ABORT_NEEDED,
6953 &base_vha->dpc_flags);
6955 clear_bit(ABORT_ISP_ACTIVE,
6956 &base_vha->dpc_flags);
6957 ql_dbg(ql_dbg_dpc, base_vha, 0x4008,
6958 "ISP abort end.\n");
6962 if (test_bit(PROCESS_PUREX_IOCB, &base_vha->dpc_flags)) {
6963 if (atomic_read(&base_vha->loop_state) == LOOP_READY) {
6964 qla24xx_process_purex_list
6965 (&base_vha->purex_list);
6966 clear_bit(PROCESS_PUREX_IOCB,
6967 &base_vha->dpc_flags);
6971 if (test_and_clear_bit(FCPORT_UPDATE_NEEDED,
6972 &base_vha->dpc_flags)) {
6973 qla2x00_update_fcports(base_vha);
6977 goto loop_resync_check;
6979 if (test_bit(ISP_QUIESCE_NEEDED, &base_vha->dpc_flags)) {
6980 ql_dbg(ql_dbg_dpc, base_vha, 0x4009,
6981 "Quiescence mode scheduled.\n");
6982 if (IS_P3P_TYPE(ha)) {
6984 qla82xx_device_state_handler(base_vha);
6986 qla8044_device_state_handler(base_vha);
6987 clear_bit(ISP_QUIESCE_NEEDED,
6988 &base_vha->dpc_flags);
6989 if (!ha->flags.quiesce_owner) {
6990 qla2x00_perform_loop_resync(base_vha);
6991 if (IS_QLA82XX(ha)) {
6992 qla82xx_idc_lock(ha);
6993 qla82xx_clear_qsnt_ready(
6995 qla82xx_idc_unlock(ha);
6996 } else if (IS_QLA8044(ha)) {
6997 qla8044_idc_lock(ha);
6998 qla8044_clear_qsnt_ready(
7000 qla8044_idc_unlock(ha);
7004 clear_bit(ISP_QUIESCE_NEEDED,
7005 &base_vha->dpc_flags);
7006 qla2x00_quiesce_io(base_vha);
7008 ql_dbg(ql_dbg_dpc, base_vha, 0x400a,
7009 "Quiescence mode end.\n");
7012 if (test_and_clear_bit(RESET_MARKER_NEEDED,
7013 &base_vha->dpc_flags) &&
7014 (!(test_and_set_bit(RESET_ACTIVE, &base_vha->dpc_flags)))) {
7016 ql_dbg(ql_dbg_dpc, base_vha, 0x400b,
7017 "Reset marker scheduled.\n");
7018 qla2x00_rst_aen(base_vha);
7019 clear_bit(RESET_ACTIVE, &base_vha->dpc_flags);
7020 ql_dbg(ql_dbg_dpc, base_vha, 0x400c,
7021 "Reset marker end.\n");
7024 /* Retry each device up to login retry count */
7025 if (test_bit(RELOGIN_NEEDED, &base_vha->dpc_flags) &&
7026 !test_bit(LOOP_RESYNC_NEEDED, &base_vha->dpc_flags) &&
7027 atomic_read(&base_vha->loop_state) != LOOP_DOWN) {
7029 if (!base_vha->relogin_jif ||
7030 time_after_eq(jiffies, base_vha->relogin_jif)) {
7031 base_vha->relogin_jif = jiffies + HZ;
7032 clear_bit(RELOGIN_NEEDED, &base_vha->dpc_flags);
7034 ql_dbg(ql_dbg_disc, base_vha, 0x400d,
7035 "Relogin scheduled.\n");
7036 qla24xx_post_relogin_work(base_vha);
7040 if (test_and_clear_bit(LOOP_RESYNC_NEEDED,
7041 &base_vha->dpc_flags)) {
7043 ql_dbg(ql_dbg_dpc, base_vha, 0x400f,
7044 "Loop resync scheduled.\n");
7046 if (!(test_and_set_bit(LOOP_RESYNC_ACTIVE,
7047 &base_vha->dpc_flags))) {
7049 qla2x00_loop_resync(base_vha);
7051 clear_bit(LOOP_RESYNC_ACTIVE,
7052 &base_vha->dpc_flags);
7055 ql_dbg(ql_dbg_dpc, base_vha, 0x4010,
7056 "Loop resync end.\n");
7062 if (test_bit(NPIV_CONFIG_NEEDED, &base_vha->dpc_flags) &&
7063 atomic_read(&base_vha->loop_state) == LOOP_READY) {
7064 clear_bit(NPIV_CONFIG_NEEDED, &base_vha->dpc_flags);
7065 qla2xxx_flash_npiv_conf(base_vha);
7069 if (!ha->interrupts_on)
7070 ha->isp_ops->enable_intrs(ha);
7072 if (test_and_clear_bit(BEACON_BLINK_NEEDED,
7073 &base_vha->dpc_flags)) {
7074 if (ha->beacon_blink_led == 1)
7075 ha->isp_ops->beacon_blink(base_vha);
7078 /* qpair online check */
7079 if (test_and_clear_bit(QPAIR_ONLINE_CHECK_NEEDED,
7080 &base_vha->dpc_flags)) {
7081 if (ha->flags.eeh_busy ||
7082 ha->flags.pci_channel_io_perm_failure)
7087 mutex_lock(&ha->mq_lock);
7088 list_for_each_entry(qpair, &base_vha->qp_list,
7090 qpair->online = online;
7091 mutex_unlock(&ha->mq_lock);
7094 if (test_and_clear_bit(SET_ZIO_THRESHOLD_NEEDED,
7095 &base_vha->dpc_flags)) {
7096 u16 threshold = ha->nvme_last_rptd_aen + ha->last_zio_threshold;
7098 if (threshold > ha->orig_fw_xcb_count)
7099 threshold = ha->orig_fw_xcb_count;
7101 ql_log(ql_log_info, base_vha, 0xffffff,
7102 "SET ZIO Activity exchange threshold to %d.\n",
7104 if (qla27xx_set_zio_threshold(base_vha, threshold)) {
7105 ql_log(ql_log_info, base_vha, 0xffffff,
7106 "Unable to SET ZIO Activity exchange threshold to %d.\n",
7111 if (!IS_QLAFX00(ha))
7112 qla2x00_do_dpc_all_vps(base_vha);
7114 if (test_and_clear_bit(N2N_LINK_RESET,
7115 &base_vha->dpc_flags)) {
7116 qla2x00_lip_reset(base_vha);
7121 set_current_state(TASK_INTERRUPTIBLE);
7122 } /* End of while(1) */
7123 __set_current_state(TASK_RUNNING);
7125 ql_dbg(ql_dbg_dpc, base_vha, 0x4011,
7126 "DPC handler exiting.\n");
7129 * Make sure that nobody tries to wake us up again.
7133 /* Cleanup any residual CTX SRBs. */
7134 qla2x00_abort_all_cmds(base_vha, DID_NO_CONNECT << 16);
7140 qla2xxx_wake_dpc(struct scsi_qla_host *vha)
7142 struct qla_hw_data *ha = vha->hw;
7143 struct task_struct *t = ha->dpc_thread;
7145 if (!test_bit(UNLOADING, &vha->dpc_flags) && t)
7151 * Processes asynchronous reset.
7154 * ha = adapter block pointer.
7157 qla2x00_rst_aen(scsi_qla_host_t *vha)
7159 if (vha->flags.online && !vha->flags.reset_active &&
7160 !atomic_read(&vha->loop_down_timer) &&
7161 !(test_bit(ABORT_ISP_ACTIVE, &vha->dpc_flags))) {
7163 clear_bit(RESET_MARKER_NEEDED, &vha->dpc_flags);
7166 * Issue marker command only when we are going to start
7169 vha->marker_needed = 1;
7170 } while (!atomic_read(&vha->loop_down_timer) &&
7171 (test_bit(RESET_MARKER_NEEDED, &vha->dpc_flags)));
7175 static bool qla_do_heartbeat(struct scsi_qla_host *vha)
7177 struct qla_hw_data *ha = vha->hw;
7180 bool do_heartbeat = false;
7183 * Allow do_heartbeat only if we don’t have any active interrupts,
7184 * but there are still IOs outstanding with firmware.
7186 cmpl_cnt = ha->base_qpair->cmd_completion_cnt;
7187 if (cmpl_cnt == ha->base_qpair->prev_completion_cnt &&
7188 cmpl_cnt != ha->base_qpair->cmd_cnt) {
7189 do_heartbeat = true;
7192 ha->base_qpair->prev_completion_cnt = cmpl_cnt;
7194 for (i = 0; i < ha->max_qpairs; i++) {
7195 if (ha->queue_pair_map[i]) {
7196 cmpl_cnt = ha->queue_pair_map[i]->cmd_completion_cnt;
7197 if (cmpl_cnt == ha->queue_pair_map[i]->prev_completion_cnt &&
7198 cmpl_cnt != ha->queue_pair_map[i]->cmd_cnt) {
7199 do_heartbeat = true;
7202 ha->queue_pair_map[i]->prev_completion_cnt = cmpl_cnt;
7207 return do_heartbeat;
7210 static void qla_heart_beat(struct scsi_qla_host *vha, u16 dpc_started)
7212 struct qla_hw_data *ha = vha->hw;
7217 if (vha->hw->flags.eeh_busy || qla2x00_chip_is_down(vha))
7221 * dpc thread cannot run if heartbeat is running at the same time.
7222 * We also do not want to starve heartbeat task. Therefore, do
7223 * heartbeat task at least once every 5 seconds.
7226 time_before(jiffies, ha->last_heartbeat_run_jiffies + 5 * HZ))
7229 if (qla_do_heartbeat(vha)) {
7230 ha->last_heartbeat_run_jiffies = jiffies;
7231 queue_work(ha->wq, &ha->heartbeat_work);
7235 /**************************************************************************
7241 * Context: Interrupt
7242 ***************************************************************************/
7244 qla2x00_timer(struct timer_list *t)
7246 scsi_qla_host_t *vha = from_timer(vha, t, timer);
7247 unsigned long cpu_flags = 0;
7252 struct qla_hw_data *ha = vha->hw;
7253 struct req_que *req;
7254 unsigned long flags;
7255 fc_port_t *fcport = NULL;
7257 if (ha->flags.eeh_busy) {
7258 ql_dbg(ql_dbg_timer, vha, 0x6000,
7259 "EEH = %d, restarting timer.\n",
7260 ha->flags.eeh_busy);
7261 qla2x00_restart_timer(vha, WATCH_INTERVAL);
7266 * Hardware read to raise pending EEH errors during mailbox waits. If
7267 * the read returns -1 then disable the board.
7269 if (!pci_channel_offline(ha->pdev)) {
7270 pci_read_config_word(ha->pdev, PCI_VENDOR_ID, &w);
7271 qla2x00_check_reg16_for_disconnect(vha, w);
7274 /* Make sure qla82xx_watchdog is run only for physical port */
7275 if (!vha->vp_idx && IS_P3P_TYPE(ha)) {
7276 if (test_bit(ISP_QUIESCE_NEEDED, &vha->dpc_flags))
7279 qla82xx_watchdog(vha);
7280 else if (IS_QLA8044(ha))
7281 qla8044_watchdog(vha);
7284 if (!vha->vp_idx && IS_QLAFX00(ha))
7285 qlafx00_timer_routine(vha);
7287 if (vha->link_down_time < QLA2XX_MAX_LINK_DOWN_TIME)
7288 vha->link_down_time++;
7290 spin_lock_irqsave(&vha->hw->tgt.sess_lock, flags);
7291 list_for_each_entry(fcport, &vha->vp_fcports, list) {
7292 if (fcport->tgt_link_down_time < QLA2XX_MAX_LINK_DOWN_TIME)
7293 fcport->tgt_link_down_time++;
7295 spin_unlock_irqrestore(&vha->hw->tgt.sess_lock, flags);
7297 /* Loop down handler. */
7298 if (atomic_read(&vha->loop_down_timer) > 0 &&
7299 !(test_bit(ABORT_ISP_ACTIVE, &vha->dpc_flags)) &&
7300 !(test_bit(FCOE_CTX_RESET_NEEDED, &vha->dpc_flags))
7301 && vha->flags.online) {
7303 if (atomic_read(&vha->loop_down_timer) ==
7304 vha->loop_down_abort_time) {
7306 ql_log(ql_log_info, vha, 0x6008,
7307 "Loop down - aborting the queues before time expires.\n");
7309 if (!IS_QLA2100(ha) && vha->link_down_timeout)
7310 atomic_set(&vha->loop_state, LOOP_DEAD);
7313 * Schedule an ISP abort to return any FCP2-device
7316 /* NPIV - scan physical port only */
7318 spin_lock_irqsave(&ha->hardware_lock,
7320 req = ha->req_q_map[0];
7322 index < req->num_outstanding_cmds;
7326 sp = req->outstanding_cmds[index];
7329 if (sp->cmd_type != TYPE_SRB)
7331 if (sp->type != SRB_SCSI_CMD)
7334 if (!(sfcp->flags & FCF_FCP2_DEVICE))
7338 set_bit(FCOE_CTX_RESET_NEEDED,
7341 set_bit(ISP_ABORT_NEEDED,
7345 spin_unlock_irqrestore(&ha->hardware_lock,
7351 /* if the loop has been down for 4 minutes, reinit adapter */
7352 if (atomic_dec_and_test(&vha->loop_down_timer) != 0) {
7353 if (!(vha->device_flags & DFLG_NO_CABLE)) {
7354 ql_log(ql_log_warn, vha, 0x6009,
7355 "Loop down - aborting ISP.\n");
7358 set_bit(FCOE_CTX_RESET_NEEDED,
7361 set_bit(ISP_ABORT_NEEDED,
7365 ql_dbg(ql_dbg_timer, vha, 0x600a,
7366 "Loop down - seconds remaining %d.\n",
7367 atomic_read(&vha->loop_down_timer));
7369 /* Check if beacon LED needs to be blinked for physical host only */
7370 if (!vha->vp_idx && (ha->beacon_blink_led == 1)) {
7371 /* There is no beacon_blink function for ISP82xx */
7372 if (!IS_P3P_TYPE(ha)) {
7373 set_bit(BEACON_BLINK_NEEDED, &vha->dpc_flags);
7378 /* check if edif running */
7379 if (vha->hw->flags.edif_enabled)
7380 qla_edif_timer(vha);
7382 /* Process any deferred work. */
7383 if (!list_empty(&vha->work_list)) {
7384 unsigned long flags;
7387 spin_lock_irqsave(&vha->work_lock, flags);
7388 if (!test_and_set_bit(IOCB_WORK_ACTIVE, &vha->dpc_flags))
7390 spin_unlock_irqrestore(&vha->work_lock, flags);
7392 queue_work(vha->hw->wq, &vha->iocb_work);
7397 * see if the active AEN count has changed from what was last reported.
7399 index = atomic_read(&ha->nvme_active_aen_cnt);
7401 (index != ha->nvme_last_rptd_aen) &&
7402 ha->zio_mode == QLA_ZIO_MODE_6 &&
7403 !ha->flags.host_shutting_down) {
7404 ha->nvme_last_rptd_aen = atomic_read(&ha->nvme_active_aen_cnt);
7405 ql_log(ql_log_info, vha, 0x3002,
7406 "nvme: Sched: Set ZIO exchange threshold to %d.\n",
7407 ha->nvme_last_rptd_aen);
7408 set_bit(SET_ZIO_THRESHOLD_NEEDED, &vha->dpc_flags);
7413 atomic_read(&ha->zio_threshold) != ha->last_zio_threshold &&
7414 IS_ZIO_THRESHOLD_CAPABLE(ha)) {
7415 ql_log(ql_log_info, vha, 0x3002,
7416 "Sched: Set ZIO exchange threshold to %d.\n",
7417 ha->last_zio_threshold);
7418 ha->last_zio_threshold = atomic_read(&ha->zio_threshold);
7419 set_bit(SET_ZIO_THRESHOLD_NEEDED, &vha->dpc_flags);
7423 /* borrowing w to signify dpc will run */
7425 /* Schedule the DPC routine if needed */
7426 if ((test_bit(ISP_ABORT_NEEDED, &vha->dpc_flags) ||
7427 test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags) ||
7428 test_bit(FCPORT_UPDATE_NEEDED, &vha->dpc_flags) ||
7430 test_bit(RESET_MARKER_NEEDED, &vha->dpc_flags) ||
7431 test_bit(BEACON_BLINK_NEEDED, &vha->dpc_flags) ||
7432 test_bit(ISP_UNRECOVERABLE, &vha->dpc_flags) ||
7433 test_bit(FCOE_CTX_RESET_NEEDED, &vha->dpc_flags) ||
7434 test_bit(VP_DPC_NEEDED, &vha->dpc_flags) ||
7435 test_bit(RELOGIN_NEEDED, &vha->dpc_flags) ||
7436 test_bit(PROCESS_PUREX_IOCB, &vha->dpc_flags))) {
7437 ql_dbg(ql_dbg_timer, vha, 0x600b,
7438 "isp_abort_needed=%d loop_resync_needed=%d "
7439 "fcport_update_needed=%d start_dpc=%d "
7440 "reset_marker_needed=%d",
7441 test_bit(ISP_ABORT_NEEDED, &vha->dpc_flags),
7442 test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags),
7443 test_bit(FCPORT_UPDATE_NEEDED, &vha->dpc_flags),
7445 test_bit(RESET_MARKER_NEEDED, &vha->dpc_flags));
7446 ql_dbg(ql_dbg_timer, vha, 0x600c,
7447 "beacon_blink_needed=%d isp_unrecoverable=%d "
7448 "fcoe_ctx_reset_needed=%d vp_dpc_needed=%d "
7449 "relogin_needed=%d, Process_purex_iocb=%d.\n",
7450 test_bit(BEACON_BLINK_NEEDED, &vha->dpc_flags),
7451 test_bit(ISP_UNRECOVERABLE, &vha->dpc_flags),
7452 test_bit(FCOE_CTX_RESET_NEEDED, &vha->dpc_flags),
7453 test_bit(VP_DPC_NEEDED, &vha->dpc_flags),
7454 test_bit(RELOGIN_NEEDED, &vha->dpc_flags),
7455 test_bit(PROCESS_PUREX_IOCB, &vha->dpc_flags));
7456 qla2xxx_wake_dpc(vha);
7460 qla_heart_beat(vha, w);
7462 qla2x00_restart_timer(vha, WATCH_INTERVAL);
7465 /* Firmware interface routines. */
7467 #define FW_ISP21XX 0
7468 #define FW_ISP22XX 1
7469 #define FW_ISP2300 2
7470 #define FW_ISP2322 3
7471 #define FW_ISP24XX 4
7472 #define FW_ISP25XX 5
7473 #define FW_ISP81XX 6
7474 #define FW_ISP82XX 7
7475 #define FW_ISP2031 8
7476 #define FW_ISP8031 9
7477 #define FW_ISP27XX 10
7478 #define FW_ISP28XX 11
7480 #define FW_FILE_ISP21XX "/*(DEBLOBBED)*/"
7481 #define FW_FILE_ISP22XX "/*(DEBLOBBED)*/"
7482 #define FW_FILE_ISP2300 "/*(DEBLOBBED)*/"
7483 #define FW_FILE_ISP2322 "/*(DEBLOBBED)*/"
7484 #define FW_FILE_ISP24XX "/*(DEBLOBBED)*/"
7485 #define FW_FILE_ISP25XX "/*(DEBLOBBED)*/"
7486 #define FW_FILE_ISP81XX "/*(DEBLOBBED)*/"
7487 #define FW_FILE_ISP82XX "/*(DEBLOBBED)*/"
7488 #define FW_FILE_ISP2031 "/*(DEBLOBBED)*/"
7489 #define FW_FILE_ISP8031 "/*(DEBLOBBED)*/"
7490 #define FW_FILE_ISP27XX "/*(DEBLOBBED)*/"
7491 #define FW_FILE_ISP28XX "/*(DEBLOBBED)*/"
7494 static DEFINE_MUTEX(qla_fw_lock);
7496 static struct fw_blob qla_fw_blobs[] = {
7497 { .name = FW_FILE_ISP21XX, .segs = { 0x1000, 0 }, },
7498 { .name = FW_FILE_ISP22XX, .segs = { 0x1000, 0 }, },
7499 { .name = FW_FILE_ISP2300, .segs = { 0x800, 0 }, },
7500 { .name = FW_FILE_ISP2322, .segs = { 0x800, 0x1c000, 0x1e000, 0 }, },
7501 { .name = FW_FILE_ISP24XX, },
7502 { .name = FW_FILE_ISP25XX, },
7503 { .name = FW_FILE_ISP81XX, },
7504 { .name = FW_FILE_ISP82XX, },
7505 { .name = FW_FILE_ISP2031, },
7506 { .name = FW_FILE_ISP8031, },
7507 { .name = FW_FILE_ISP27XX, },
7508 { .name = FW_FILE_ISP28XX, },
7513 qla2x00_request_firmware(scsi_qla_host_t *vha)
7515 struct qla_hw_data *ha = vha->hw;
7516 struct fw_blob *blob;
7518 if (IS_QLA2100(ha)) {
7519 blob = &qla_fw_blobs[FW_ISP21XX];
7520 } else if (IS_QLA2200(ha)) {
7521 blob = &qla_fw_blobs[FW_ISP22XX];
7522 } else if (IS_QLA2300(ha) || IS_QLA2312(ha) || IS_QLA6312(ha)) {
7523 blob = &qla_fw_blobs[FW_ISP2300];
7524 } else if (IS_QLA2322(ha) || IS_QLA6322(ha)) {
7525 blob = &qla_fw_blobs[FW_ISP2322];
7526 } else if (IS_QLA24XX_TYPE(ha)) {
7527 blob = &qla_fw_blobs[FW_ISP24XX];
7528 } else if (IS_QLA25XX(ha)) {
7529 blob = &qla_fw_blobs[FW_ISP25XX];
7530 } else if (IS_QLA81XX(ha)) {
7531 blob = &qla_fw_blobs[FW_ISP81XX];
7532 } else if (IS_QLA82XX(ha)) {
7533 blob = &qla_fw_blobs[FW_ISP82XX];
7534 } else if (IS_QLA2031(ha)) {
7535 blob = &qla_fw_blobs[FW_ISP2031];
7536 } else if (IS_QLA8031(ha)) {
7537 blob = &qla_fw_blobs[FW_ISP8031];
7538 } else if (IS_QLA27XX(ha)) {
7539 blob = &qla_fw_blobs[FW_ISP27XX];
7540 } else if (IS_QLA28XX(ha)) {
7541 blob = &qla_fw_blobs[FW_ISP28XX];
7549 mutex_lock(&qla_fw_lock);
7553 if (reject_firmware(&blob->fw, blob->name, &ha->pdev->dev)) {
7554 ql_log(ql_log_warn, vha, 0x0063,
7555 "Failed to load firmware image (%s).\n", blob->name);
7561 mutex_unlock(&qla_fw_lock);
7566 qla2x00_release_firmware(void)
7568 struct fw_blob *blob;
7570 mutex_lock(&qla_fw_lock);
7571 for (blob = qla_fw_blobs; blob->name; blob++)
7572 release_firmware(blob->fw);
7573 mutex_unlock(&qla_fw_lock);
7576 static void qla_pci_error_cleanup(scsi_qla_host_t *vha)
7578 struct qla_hw_data *ha = vha->hw;
7579 scsi_qla_host_t *base_vha = pci_get_drvdata(ha->pdev);
7580 struct qla_qpair *qpair = NULL;
7581 struct scsi_qla_host *vp, *tvp;
7584 unsigned long flags;
7586 ql_dbg(ql_dbg_aer, vha, 0x9000,
7590 ha->base_qpair->chip_reset = ha->chip_reset;
7591 for (i = 0; i < ha->max_qpairs; i++) {
7592 if (ha->queue_pair_map[i])
7593 ha->queue_pair_map[i]->chip_reset =
7594 ha->base_qpair->chip_reset;
7598 * purge mailbox might take a while. Slot Reset/chip reset
7599 * will take care of the purge
7602 mutex_lock(&ha->mq_lock);
7603 ha->base_qpair->online = 0;
7604 list_for_each_entry(qpair, &base_vha->qp_list, qp_list_elem)
7607 mutex_unlock(&ha->mq_lock);
7609 qla2x00_mark_all_devices_lost(vha);
7611 spin_lock_irqsave(&ha->vport_slock, flags);
7612 list_for_each_entry_safe(vp, tvp, &ha->vp_list, list) {
7613 atomic_inc(&vp->vref_count);
7614 spin_unlock_irqrestore(&ha->vport_slock, flags);
7615 qla2x00_mark_all_devices_lost(vp);
7616 spin_lock_irqsave(&ha->vport_slock, flags);
7617 atomic_dec(&vp->vref_count);
7619 spin_unlock_irqrestore(&ha->vport_slock, flags);
7621 /* Clear all async request states across all VPs. */
7622 list_for_each_entry(fcport, &vha->vp_fcports, list)
7623 fcport->flags &= ~(FCF_LOGIN_NEEDED | FCF_ASYNC_SENT);
7625 spin_lock_irqsave(&ha->vport_slock, flags);
7626 list_for_each_entry_safe(vp, tvp, &ha->vp_list, list) {
7627 atomic_inc(&vp->vref_count);
7628 spin_unlock_irqrestore(&ha->vport_slock, flags);
7629 list_for_each_entry(fcport, &vp->vp_fcports, list)
7630 fcport->flags &= ~(FCF_LOGIN_NEEDED | FCF_ASYNC_SENT);
7631 spin_lock_irqsave(&ha->vport_slock, flags);
7632 atomic_dec(&vp->vref_count);
7634 spin_unlock_irqrestore(&ha->vport_slock, flags);
7638 static pci_ers_result_t
7639 qla2xxx_pci_error_detected(struct pci_dev *pdev, pci_channel_state_t state)
7641 scsi_qla_host_t *vha = pci_get_drvdata(pdev);
7642 struct qla_hw_data *ha = vha->hw;
7643 pci_ers_result_t ret = PCI_ERS_RESULT_NEED_RESET;
7645 ql_log(ql_log_warn, vha, 0x9000,
7646 "PCI error detected, state %x.\n", state);
7647 ha->pci_error_state = QLA_PCI_ERR_DETECTED;
7649 if (!atomic_read(&pdev->enable_cnt)) {
7650 ql_log(ql_log_info, vha, 0xffff,
7651 "PCI device is disabled,state %x\n", state);
7652 ret = PCI_ERS_RESULT_NEED_RESET;
7657 case pci_channel_io_normal:
7658 qla_pci_set_eeh_busy(vha);
7659 if (ql2xmqsupport || ql2xnvmeenable) {
7660 set_bit(QPAIR_ONLINE_CHECK_NEEDED, &vha->dpc_flags);
7661 qla2xxx_wake_dpc(vha);
7663 ret = PCI_ERS_RESULT_CAN_RECOVER;
7665 case pci_channel_io_frozen:
7666 qla_pci_set_eeh_busy(vha);
7667 ret = PCI_ERS_RESULT_NEED_RESET;
7669 case pci_channel_io_perm_failure:
7670 ha->flags.pci_channel_io_perm_failure = 1;
7671 qla2x00_abort_all_cmds(vha, DID_NO_CONNECT << 16);
7672 if (ql2xmqsupport || ql2xnvmeenable) {
7673 set_bit(QPAIR_ONLINE_CHECK_NEEDED, &vha->dpc_flags);
7674 qla2xxx_wake_dpc(vha);
7676 ret = PCI_ERS_RESULT_DISCONNECT;
7679 ql_dbg(ql_dbg_aer, vha, 0x600d,
7680 "PCI error detected returning [%x].\n", ret);
7684 static pci_ers_result_t
7685 qla2xxx_pci_mmio_enabled(struct pci_dev *pdev)
7687 int risc_paused = 0;
7689 unsigned long flags;
7690 scsi_qla_host_t *base_vha = pci_get_drvdata(pdev);
7691 struct qla_hw_data *ha = base_vha->hw;
7692 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
7693 struct device_reg_24xx __iomem *reg24 = &ha->iobase->isp24;
7695 ql_log(ql_log_warn, base_vha, 0x9000,
7698 ha->pci_error_state = QLA_PCI_MMIO_ENABLED;
7701 return PCI_ERS_RESULT_RECOVERED;
7703 if (qla2x00_isp_reg_stat(ha)) {
7704 ql_log(ql_log_info, base_vha, 0x803f,
7705 "During mmio enabled, PCI/Register disconnect still detected.\n");
7709 spin_lock_irqsave(&ha->hardware_lock, flags);
7710 if (IS_QLA2100(ha) || IS_QLA2200(ha)){
7711 stat = rd_reg_word(®->hccr);
7712 if (stat & HCCR_RISC_PAUSE)
7714 } else if (IS_QLA23XX(ha)) {
7715 stat = rd_reg_dword(®->u.isp2300.host_status);
7716 if (stat & HSR_RISC_PAUSED)
7718 } else if (IS_FWI2_CAPABLE(ha)) {
7719 stat = rd_reg_dword(®24->host_status);
7720 if (stat & HSRX_RISC_PAUSED)
7723 spin_unlock_irqrestore(&ha->hardware_lock, flags);
7726 ql_log(ql_log_info, base_vha, 0x9003,
7727 "RISC paused -- mmio_enabled, Dumping firmware.\n");
7728 qla2xxx_dump_fw(base_vha);
7731 /* set PCI_ERS_RESULT_NEED_RESET to trigger call to qla2xxx_pci_slot_reset */
7732 ql_dbg(ql_dbg_aer, base_vha, 0x600d,
7733 "mmio enabled returning.\n");
7734 return PCI_ERS_RESULT_NEED_RESET;
7737 static pci_ers_result_t
7738 qla2xxx_pci_slot_reset(struct pci_dev *pdev)
7740 pci_ers_result_t ret = PCI_ERS_RESULT_DISCONNECT;
7741 scsi_qla_host_t *base_vha = pci_get_drvdata(pdev);
7742 struct qla_hw_data *ha = base_vha->hw;
7744 struct qla_qpair *qpair = NULL;
7746 ql_log(ql_log_warn, base_vha, 0x9004,
7749 ha->pci_error_state = QLA_PCI_SLOT_RESET;
7750 /* Workaround: qla2xxx driver which access hardware earlier
7751 * needs error state to be pci_channel_io_online.
7752 * Otherwise mailbox command timesout.
7754 pdev->error_state = pci_channel_io_normal;
7756 pci_restore_state(pdev);
7758 /* pci_restore_state() clears the saved_state flag of the device
7759 * save restored state which resets saved_state flag
7761 pci_save_state(pdev);
7764 rc = pci_enable_device_mem(pdev);
7766 rc = pci_enable_device(pdev);
7769 ql_log(ql_log_warn, base_vha, 0x9005,
7770 "Can't re-enable PCI device after reset.\n");
7771 goto exit_slot_reset;
7775 if (ha->isp_ops->pci_config(base_vha))
7776 goto exit_slot_reset;
7778 mutex_lock(&ha->mq_lock);
7779 list_for_each_entry(qpair, &base_vha->qp_list, qp_list_elem)
7781 mutex_unlock(&ha->mq_lock);
7783 ha->flags.eeh_busy = 0;
7784 base_vha->flags.online = 1;
7785 set_bit(ABORT_ISP_ACTIVE, &base_vha->dpc_flags);
7786 ha->isp_ops->abort_isp(base_vha);
7787 clear_bit(ABORT_ISP_ACTIVE, &base_vha->dpc_flags);
7789 if (qla2x00_isp_reg_stat(ha)) {
7790 ha->flags.eeh_busy = 1;
7791 qla_pci_error_cleanup(base_vha);
7792 ql_log(ql_log_warn, base_vha, 0x9005,
7793 "Device unable to recover from PCI error.\n");
7795 ret = PCI_ERS_RESULT_RECOVERED;
7799 ql_dbg(ql_dbg_aer, base_vha, 0x900e,
7800 "Slot Reset returning %x.\n", ret);
7806 qla2xxx_pci_resume(struct pci_dev *pdev)
7808 scsi_qla_host_t *base_vha = pci_get_drvdata(pdev);
7809 struct qla_hw_data *ha = base_vha->hw;
7812 ql_log(ql_log_warn, base_vha, 0x900f,
7816 ret = qla2x00_wait_for_hba_online(base_vha);
7817 if (ret != QLA_SUCCESS) {
7818 ql_log(ql_log_fatal, base_vha, 0x9002,
7819 "The device failed to resume I/O from slot/link_reset.\n");
7821 ha->pci_error_state = QLA_PCI_RESUME;
7822 ql_dbg(ql_dbg_aer, base_vha, 0x600d,
7823 "Pci Resume returning.\n");
7826 void qla_pci_set_eeh_busy(struct scsi_qla_host *vha)
7828 struct qla_hw_data *ha = vha->hw;
7829 struct scsi_qla_host *base_vha = pci_get_drvdata(ha->pdev);
7830 bool do_cleanup = false;
7831 unsigned long flags;
7833 if (ha->flags.eeh_busy)
7836 spin_lock_irqsave(&base_vha->work_lock, flags);
7837 if (!ha->flags.eeh_busy) {
7838 ha->flags.eeh_busy = 1;
7841 spin_unlock_irqrestore(&base_vha->work_lock, flags);
7844 qla_pci_error_cleanup(base_vha);
7848 * this routine will schedule a task to pause IO from interrupt context
7849 * if caller sees a PCIE error event (register read = 0xf's)
7851 void qla_schedule_eeh_work(struct scsi_qla_host *vha)
7853 struct qla_hw_data *ha = vha->hw;
7854 struct scsi_qla_host *base_vha = pci_get_drvdata(ha->pdev);
7856 if (ha->flags.eeh_busy)
7859 set_bit(DO_EEH_RECOVERY, &base_vha->dpc_flags);
7860 qla2xxx_wake_dpc(base_vha);
7864 qla_pci_reset_prepare(struct pci_dev *pdev)
7866 scsi_qla_host_t *base_vha = pci_get_drvdata(pdev);
7867 struct qla_hw_data *ha = base_vha->hw;
7868 struct qla_qpair *qpair;
7870 ql_log(ql_log_warn, base_vha, 0xffff,
7874 * PCI FLR/function reset is about to reset the
7875 * slot. Stop the chip to stop all DMA access.
7876 * It is assumed that pci_reset_done will be called
7877 * after FLR to resume Chip operation.
7879 ha->flags.eeh_busy = 1;
7880 mutex_lock(&ha->mq_lock);
7881 list_for_each_entry(qpair, &base_vha->qp_list, qp_list_elem)
7883 mutex_unlock(&ha->mq_lock);
7885 set_bit(ABORT_ISP_ACTIVE, &base_vha->dpc_flags);
7886 qla2x00_abort_isp_cleanup(base_vha);
7887 qla2x00_abort_all_cmds(base_vha, DID_RESET << 16);
7891 qla_pci_reset_done(struct pci_dev *pdev)
7893 scsi_qla_host_t *base_vha = pci_get_drvdata(pdev);
7894 struct qla_hw_data *ha = base_vha->hw;
7895 struct qla_qpair *qpair;
7897 ql_log(ql_log_warn, base_vha, 0xffff,
7901 * FLR just completed by PCI layer. Resume adapter
7903 ha->flags.eeh_busy = 0;
7904 mutex_lock(&ha->mq_lock);
7905 list_for_each_entry(qpair, &base_vha->qp_list, qp_list_elem)
7907 mutex_unlock(&ha->mq_lock);
7909 base_vha->flags.online = 1;
7910 ha->isp_ops->abort_isp(base_vha);
7911 clear_bit(ABORT_ISP_ACTIVE, &base_vha->dpc_flags);
7914 static int qla2xxx_map_queues(struct Scsi_Host *shost)
7917 scsi_qla_host_t *vha = (scsi_qla_host_t *)shost->hostdata;
7918 struct blk_mq_queue_map *qmap = &shost->tag_set.map[HCTX_TYPE_DEFAULT];
7920 if (USER_CTRL_IRQ(vha->hw) || !vha->hw->mqiobase)
7921 rc = blk_mq_map_queues(qmap);
7923 rc = blk_mq_pci_map_queues(qmap, vha->hw->pdev, vha->irq_offset);
7927 struct scsi_host_template qla2xxx_driver_template = {
7928 .module = THIS_MODULE,
7929 .name = QLA2XXX_DRIVER_NAME,
7930 .queuecommand = qla2xxx_queuecommand,
7932 .eh_timed_out = fc_eh_timed_out,
7933 .eh_abort_handler = qla2xxx_eh_abort,
7934 .eh_should_retry_cmd = fc_eh_should_retry_cmd,
7935 .eh_device_reset_handler = qla2xxx_eh_device_reset,
7936 .eh_target_reset_handler = qla2xxx_eh_target_reset,
7937 .eh_bus_reset_handler = qla2xxx_eh_bus_reset,
7938 .eh_host_reset_handler = qla2xxx_eh_host_reset,
7940 .slave_configure = qla2xxx_slave_configure,
7942 .slave_alloc = qla2xxx_slave_alloc,
7943 .slave_destroy = qla2xxx_slave_destroy,
7944 .scan_finished = qla2xxx_scan_finished,
7945 .scan_start = qla2xxx_scan_start,
7946 .change_queue_depth = scsi_change_queue_depth,
7947 .map_queues = qla2xxx_map_queues,
7950 .sg_tablesize = SG_ALL,
7952 .max_sectors = 0xFFFF,
7953 .shost_attrs = qla2x00_host_attrs,
7955 .supported_mode = MODE_INITIATOR,
7956 .track_queue_depth = 1,
7957 .cmd_size = sizeof(srb_t),
7960 static const struct pci_error_handlers qla2xxx_err_handler = {
7961 .error_detected = qla2xxx_pci_error_detected,
7962 .mmio_enabled = qla2xxx_pci_mmio_enabled,
7963 .slot_reset = qla2xxx_pci_slot_reset,
7964 .resume = qla2xxx_pci_resume,
7965 .reset_prepare = qla_pci_reset_prepare,
7966 .reset_done = qla_pci_reset_done,
7969 static struct pci_device_id qla2xxx_pci_tbl[] = {
7970 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP2100) },
7971 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP2200) },
7972 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP2300) },
7973 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP2312) },
7974 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP2322) },
7975 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP6312) },
7976 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP6322) },
7977 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP2422) },
7978 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP2432) },
7979 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP8432) },
7980 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP5422) },
7981 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP5432) },
7982 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP2532) },
7983 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP2031) },
7984 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP8001) },
7985 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP8021) },
7986 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP8031) },
7987 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISPF001) },
7988 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP8044) },
7989 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP2071) },
7990 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP2271) },
7991 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP2261) },
7992 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP2061) },
7993 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP2081) },
7994 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP2281) },
7995 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP2089) },
7996 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP2289) },
7999 MODULE_DEVICE_TABLE(pci, qla2xxx_pci_tbl);
8001 static struct pci_driver qla2xxx_pci_driver = {
8002 .name = QLA2XXX_DRIVER_NAME,
8004 .owner = THIS_MODULE,
8006 .id_table = qla2xxx_pci_tbl,
8007 .probe = qla2x00_probe_one,
8008 .remove = qla2x00_remove_one,
8009 .shutdown = qla2x00_shutdown,
8010 .err_handler = &qla2xxx_err_handler,
8013 static const struct file_operations apidev_fops = {
8014 .owner = THIS_MODULE,
8015 .llseek = noop_llseek,
8019 * qla2x00_module_init - Module initialization.
8022 qla2x00_module_init(void)
8026 BUILD_BUG_ON(sizeof(cmd_a64_entry_t) != 64);
8027 BUILD_BUG_ON(sizeof(cmd_entry_t) != 64);
8028 BUILD_BUG_ON(sizeof(cont_a64_entry_t) != 64);
8029 BUILD_BUG_ON(sizeof(cont_entry_t) != 64);
8030 BUILD_BUG_ON(sizeof(init_cb_t) != 96);
8031 BUILD_BUG_ON(sizeof(mrk_entry_t) != 64);
8032 BUILD_BUG_ON(sizeof(ms_iocb_entry_t) != 64);
8033 BUILD_BUG_ON(sizeof(request_t) != 64);
8034 BUILD_BUG_ON(sizeof(struct abort_entry_24xx) != 64);
8035 BUILD_BUG_ON(sizeof(struct abort_iocb_entry_fx00) != 64);
8036 BUILD_BUG_ON(sizeof(struct abts_entry_24xx) != 64);
8037 BUILD_BUG_ON(sizeof(struct access_chip_84xx) != 64);
8038 BUILD_BUG_ON(sizeof(struct access_chip_rsp_84xx) != 64);
8039 BUILD_BUG_ON(sizeof(struct cmd_bidir) != 64);
8040 BUILD_BUG_ON(sizeof(struct cmd_nvme) != 64);
8041 BUILD_BUG_ON(sizeof(struct cmd_type_6) != 64);
8042 BUILD_BUG_ON(sizeof(struct cmd_type_7) != 64);
8043 BUILD_BUG_ON(sizeof(struct cmd_type_7_fx00) != 64);
8044 BUILD_BUG_ON(sizeof(struct cmd_type_crc_2) != 64);
8045 BUILD_BUG_ON(sizeof(struct ct_entry_24xx) != 64);
8046 BUILD_BUG_ON(sizeof(struct ct_fdmi1_hba_attributes) != 2604);
8047 BUILD_BUG_ON(sizeof(struct ct_fdmi2_hba_attributes) != 4424);
8048 BUILD_BUG_ON(sizeof(struct ct_fdmi2_port_attributes) != 4164);
8049 BUILD_BUG_ON(sizeof(struct ct_fdmi_hba_attr) != 260);
8050 BUILD_BUG_ON(sizeof(struct ct_fdmi_port_attr) != 260);
8051 BUILD_BUG_ON(sizeof(struct ct_rsp_hdr) != 16);
8052 BUILD_BUG_ON(sizeof(struct ctio_crc2_to_fw) != 64);
8053 BUILD_BUG_ON(sizeof(struct device_reg_24xx) != 256);
8054 BUILD_BUG_ON(sizeof(struct device_reg_25xxmq) != 24);
8055 BUILD_BUG_ON(sizeof(struct device_reg_2xxx) != 256);
8056 BUILD_BUG_ON(sizeof(struct device_reg_82xx) != 1288);
8057 BUILD_BUG_ON(sizeof(struct device_reg_fx00) != 216);
8058 BUILD_BUG_ON(sizeof(struct els_entry_24xx) != 64);
8059 BUILD_BUG_ON(sizeof(struct els_sts_entry_24xx) != 64);
8060 BUILD_BUG_ON(sizeof(struct fxdisc_entry_fx00) != 64);
8061 BUILD_BUG_ON(sizeof(struct imm_ntfy_from_isp) != 64);
8062 BUILD_BUG_ON(sizeof(struct init_cb_24xx) != 128);
8063 BUILD_BUG_ON(sizeof(struct init_cb_81xx) != 128);
8064 BUILD_BUG_ON(sizeof(struct logio_entry_24xx) != 64);
8065 BUILD_BUG_ON(sizeof(struct mbx_entry) != 64);
8066 BUILD_BUG_ON(sizeof(struct mid_init_cb_24xx) != 5252);
8067 BUILD_BUG_ON(sizeof(struct mrk_entry_24xx) != 64);
8068 BUILD_BUG_ON(sizeof(struct nvram_24xx) != 512);
8069 BUILD_BUG_ON(sizeof(struct nvram_81xx) != 512);
8070 BUILD_BUG_ON(sizeof(struct pt_ls4_request) != 64);
8071 BUILD_BUG_ON(sizeof(struct pt_ls4_rx_unsol) != 64);
8072 BUILD_BUG_ON(sizeof(struct purex_entry_24xx) != 64);
8073 BUILD_BUG_ON(sizeof(struct qla2100_fw_dump) != 123634);
8074 BUILD_BUG_ON(sizeof(struct qla2300_fw_dump) != 136100);
8075 BUILD_BUG_ON(sizeof(struct qla24xx_fw_dump) != 37976);
8076 BUILD_BUG_ON(sizeof(struct qla25xx_fw_dump) != 39228);
8077 BUILD_BUG_ON(sizeof(struct qla2xxx_fce_chain) != 52);
8078 BUILD_BUG_ON(sizeof(struct qla2xxx_fw_dump) != 136172);
8079 BUILD_BUG_ON(sizeof(struct qla2xxx_mq_chain) != 524);
8080 BUILD_BUG_ON(sizeof(struct qla2xxx_mqueue_chain) != 8);
8081 BUILD_BUG_ON(sizeof(struct qla2xxx_mqueue_header) != 12);
8082 BUILD_BUG_ON(sizeof(struct qla2xxx_offld_chain) != 24);
8083 BUILD_BUG_ON(sizeof(struct qla81xx_fw_dump) != 39420);
8084 BUILD_BUG_ON(sizeof(struct qla82xx_uri_data_desc) != 28);
8085 BUILD_BUG_ON(sizeof(struct qla82xx_uri_table_desc) != 32);
8086 BUILD_BUG_ON(sizeof(struct qla83xx_fw_dump) != 51196);
8087 BUILD_BUG_ON(sizeof(struct qla_fcp_prio_cfg) != FCP_PRIO_CFG_SIZE);
8088 BUILD_BUG_ON(sizeof(struct qla_fdt_layout) != 128);
8089 BUILD_BUG_ON(sizeof(struct qla_flt_header) != 8);
8090 BUILD_BUG_ON(sizeof(struct qla_flt_region) != 16);
8091 BUILD_BUG_ON(sizeof(struct qla_npiv_entry) != 24);
8092 BUILD_BUG_ON(sizeof(struct qla_npiv_header) != 16);
8093 BUILD_BUG_ON(sizeof(struct rdp_rsp_payload) != 336);
8094 BUILD_BUG_ON(sizeof(struct sns_cmd_pkt) != 2064);
8095 BUILD_BUG_ON(sizeof(struct sts_entry_24xx) != 64);
8096 BUILD_BUG_ON(sizeof(struct tsk_mgmt_entry) != 64);
8097 BUILD_BUG_ON(sizeof(struct tsk_mgmt_entry_fx00) != 64);
8098 BUILD_BUG_ON(sizeof(struct verify_chip_entry_84xx) != 64);
8099 BUILD_BUG_ON(sizeof(struct verify_chip_rsp_84xx) != 52);
8100 BUILD_BUG_ON(sizeof(struct vf_evfp_entry_24xx) != 56);
8101 BUILD_BUG_ON(sizeof(struct vp_config_entry_24xx) != 64);
8102 BUILD_BUG_ON(sizeof(struct vp_ctrl_entry_24xx) != 64);
8103 BUILD_BUG_ON(sizeof(struct vp_rpt_id_entry_24xx) != 64);
8104 BUILD_BUG_ON(sizeof(sts21_entry_t) != 64);
8105 BUILD_BUG_ON(sizeof(sts22_entry_t) != 64);
8106 BUILD_BUG_ON(sizeof(sts_cont_entry_t) != 64);
8107 BUILD_BUG_ON(sizeof(sts_entry_t) != 64);
8108 BUILD_BUG_ON(sizeof(sw_info_t) != 32);
8109 BUILD_BUG_ON(sizeof(target_id_t) != 2);
8111 /* Allocate cache for SRBs. */
8112 srb_cachep = kmem_cache_create("qla2xxx_srbs", sizeof(srb_t), 0,
8113 SLAB_HWCACHE_ALIGN, NULL);
8114 if (srb_cachep == NULL) {
8115 ql_log(ql_log_fatal, NULL, 0x0001,
8116 "Unable to allocate SRB cache...Failing load!.\n");
8120 /* Initialize target kmem_cache and mem_pools */
8124 } else if (ret > 0) {
8126 * If initiator mode is explictly disabled by qlt_init(),
8127 * prevent scsi_transport_fc.c:fc_scsi_scan_rport() from
8128 * performing scsi_scan_target() during LOOP UP event.
8130 qla2xxx_transport_functions.disable_target_scan = 1;
8131 qla2xxx_transport_vport_functions.disable_target_scan = 1;
8134 /* Derive version string. */
8135 strcpy(qla2x00_version_str, QLA2XXX_VERSION);
8136 if (ql2xextended_error_logging)
8137 strcat(qla2x00_version_str, "-debug");
8138 if (ql2xextended_error_logging == 1)
8139 ql2xextended_error_logging = QL_DBG_DEFAULT1_MASK;
8141 if (ql2x_ini_mode == QLA2XXX_INI_MODE_DUAL)
8142 qla_insert_tgt_attrs();
8144 qla2xxx_transport_template =
8145 fc_attach_transport(&qla2xxx_transport_functions);
8146 if (!qla2xxx_transport_template) {
8147 ql_log(ql_log_fatal, NULL, 0x0002,
8148 "fc_attach_transport failed...Failing load!.\n");
8153 apidev_major = register_chrdev(0, QLA2XXX_APIDEV, &apidev_fops);
8154 if (apidev_major < 0) {
8155 ql_log(ql_log_fatal, NULL, 0x0003,
8156 "Unable to register char device %s.\n", QLA2XXX_APIDEV);
8159 qla2xxx_transport_vport_template =
8160 fc_attach_transport(&qla2xxx_transport_vport_functions);
8161 if (!qla2xxx_transport_vport_template) {
8162 ql_log(ql_log_fatal, NULL, 0x0004,
8163 "fc_attach_transport vport failed...Failing load!.\n");
8167 ql_log(ql_log_info, NULL, 0x0005,
8168 "QLogic Fibre Channel HBA Driver: %s.\n",
8169 qla2x00_version_str);
8170 ret = pci_register_driver(&qla2xxx_pci_driver);
8172 ql_log(ql_log_fatal, NULL, 0x0006,
8173 "pci_register_driver failed...ret=%d Failing load!.\n",
8175 goto release_vport_transport;
8179 release_vport_transport:
8180 fc_release_transport(qla2xxx_transport_vport_template);
8183 if (apidev_major >= 0)
8184 unregister_chrdev(apidev_major, QLA2XXX_APIDEV);
8185 fc_release_transport(qla2xxx_transport_template);
8191 kmem_cache_destroy(srb_cachep);
8196 * qla2x00_module_exit - Module cleanup.
8199 qla2x00_module_exit(void)
8201 pci_unregister_driver(&qla2xxx_pci_driver);
8202 qla2x00_release_firmware();
8203 kmem_cache_destroy(ctx_cachep);
8204 fc_release_transport(qla2xxx_transport_vport_template);
8205 if (apidev_major >= 0)
8206 unregister_chrdev(apidev_major, QLA2XXX_APIDEV);
8207 fc_release_transport(qla2xxx_transport_template);
8209 kmem_cache_destroy(srb_cachep);
8212 module_init(qla2x00_module_init);
8213 module_exit(qla2x00_module_exit);
8215 MODULE_AUTHOR("QLogic Corporation");
8216 MODULE_DESCRIPTION("QLogic Fibre Channel HBA Driver");
8217 MODULE_LICENSE("GPL");