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 request_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");
205 int ql2xtargetreset = 1;
206 module_param(ql2xtargetreset, int, S_IRUGO);
207 MODULE_PARM_DESC(ql2xtargetreset,
208 "Enable target reset."
209 "Default is 1 - use hw defaults.");
212 module_param(ql2xgffidenable, int, S_IRUGO);
213 MODULE_PARM_DESC(ql2xgffidenable,
214 "Enables GFF_ID checks of port type. "
215 "Default is 0 - Do not use GFF_ID information.");
217 int ql2xasynctmfenable = 1;
218 module_param(ql2xasynctmfenable, int, S_IRUGO);
219 MODULE_PARM_DESC(ql2xasynctmfenable,
220 "Enables issue of TM IOCBs asynchronously via IOCB mechanism"
221 "Default is 1 - Issue TM IOCBs via mailbox mechanism.");
223 int ql2xdontresethba;
224 module_param(ql2xdontresethba, int, S_IRUGO|S_IWUSR);
225 MODULE_PARM_DESC(ql2xdontresethba,
226 "Option to specify reset behaviour.\n"
227 " 0 (Default) -- Reset on failure.\n"
228 " 1 -- Do not reset on failure.\n");
230 uint64_t ql2xmaxlun = MAX_LUNS;
231 module_param(ql2xmaxlun, ullong, S_IRUGO);
232 MODULE_PARM_DESC(ql2xmaxlun,
233 "Defines the maximum LU number to register with the SCSI "
234 "midlayer. Default is 65535.");
236 int ql2xmdcapmask = 0x1F;
237 module_param(ql2xmdcapmask, int, S_IRUGO);
238 MODULE_PARM_DESC(ql2xmdcapmask,
239 "Set the Minidump driver capture mask level. "
240 "Default is 0x1F - Can be set to 0x3, 0x7, 0xF, 0x1F, 0x7F.");
242 int ql2xmdenable = 1;
243 module_param(ql2xmdenable, int, S_IRUGO);
244 MODULE_PARM_DESC(ql2xmdenable,
245 "Enable/disable MiniDump. "
246 "0 - MiniDump disabled. "
247 "1 (Default) - MiniDump enabled.");
250 module_param(ql2xexlogins, uint, S_IRUGO|S_IWUSR);
251 MODULE_PARM_DESC(ql2xexlogins,
252 "Number of extended Logins. "
253 "0 (Default)- Disabled.");
255 int ql2xexchoffld = 1024;
256 module_param(ql2xexchoffld, uint, 0644);
257 MODULE_PARM_DESC(ql2xexchoffld,
258 "Number of target exchanges.");
260 int ql2xiniexchg = 1024;
261 module_param(ql2xiniexchg, uint, 0644);
262 MODULE_PARM_DESC(ql2xiniexchg,
263 "Number of initiator exchanges.");
266 module_param(ql2xfwholdabts, int, S_IRUGO);
267 MODULE_PARM_DESC(ql2xfwholdabts,
268 "Allow FW to hold status IOCB until ABTS rsp received. "
269 "0 (Default) Do not set fw option. "
270 "1 - Set fw option to hold ABTS.");
272 int ql2xmvasynctoatio = 1;
273 module_param(ql2xmvasynctoatio, int, S_IRUGO|S_IWUSR);
274 MODULE_PARM_DESC(ql2xmvasynctoatio,
275 "Move PUREX, ABTS RX and RIDA IOCBs to ATIOQ"
276 "0 (Default). Do not move IOCBs"
279 int ql2xautodetectsfp = 1;
280 module_param(ql2xautodetectsfp, int, 0444);
281 MODULE_PARM_DESC(ql2xautodetectsfp,
282 "Detect SFP range and set appropriate distance.\n"
283 "1 (Default): Enable\n");
285 int ql2xenablemsix = 1;
286 module_param(ql2xenablemsix, int, 0444);
287 MODULE_PARM_DESC(ql2xenablemsix,
288 "Set to enable MSI or MSI-X interrupt mechanism.\n"
289 " Default is 1, enable MSI-X interrupt mechanism.\n"
290 " 0 -- enable traditional pin-based mechanism.\n"
291 " 1 -- enable MSI-X interrupt mechanism.\n"
292 " 2 -- enable MSI interrupt mechanism.\n");
294 int qla2xuseresexchforels;
295 module_param(qla2xuseresexchforels, int, 0444);
296 MODULE_PARM_DESC(qla2xuseresexchforels,
297 "Reserve 1/2 of emergency exchanges for ELS.\n"
298 " 0 (default): disabled");
300 static int ql2xprotmask;
301 module_param(ql2xprotmask, int, 0644);
302 MODULE_PARM_DESC(ql2xprotmask,
303 "Override DIF/DIX protection capabilities mask\n"
304 "Default is 0 which sets protection mask based on "
305 "capabilities reported by HBA firmware.\n");
307 static int ql2xprotguard;
308 module_param(ql2xprotguard, int, 0644);
309 MODULE_PARM_DESC(ql2xprotguard, "Override choice of DIX checksum\n"
310 " 0 -- Let HBA firmware decide\n"
311 " 1 -- Force T10 CRC\n"
312 " 2 -- Force IP checksum\n");
314 int ql2xdifbundlinginternalbuffers;
315 module_param(ql2xdifbundlinginternalbuffers, int, 0644);
316 MODULE_PARM_DESC(ql2xdifbundlinginternalbuffers,
317 "Force using internal buffers for DIF information\n"
318 "0 (Default). Based on check.\n"
319 "1 Force using internal buffers\n");
322 module_param(ql2xsmartsan, int, 0444);
323 module_param_named(smartsan, ql2xsmartsan, int, 0444);
324 MODULE_PARM_DESC(ql2xsmartsan,
325 "Send SmartSAN Management Attributes for FDMI Registration."
326 " Default is 0 - No SmartSAN registration,"
327 " 1 - Register SmartSAN Management Attributes.");
330 module_param(ql2xrdpenable, int, 0444);
331 module_param_named(rdpenable, ql2xrdpenable, int, 0444);
332 MODULE_PARM_DESC(ql2xrdpenable,
333 "Enables RDP responses. "
334 "0 - no RDP responses (default). "
335 "1 - provide RDP responses.");
336 int ql2xabts_wait_nvme = 1;
337 module_param(ql2xabts_wait_nvme, int, 0444);
338 MODULE_PARM_DESC(ql2xabts_wait_nvme,
339 "To wait for ABTS response on I/O timeouts for NVMe. (default: 1)");
342 static void qla2x00_clear_drv_active(struct qla_hw_data *);
343 static void qla2x00_free_device(scsi_qla_host_t *);
344 static int qla2xxx_map_queues(struct Scsi_Host *shost);
345 static void qla2x00_destroy_deferred_work(struct qla_hw_data *);
348 static struct scsi_transport_template *qla2xxx_transport_template = NULL;
349 struct scsi_transport_template *qla2xxx_transport_vport_template = NULL;
351 /* TODO Convert to inlines
357 qla2x00_start_timer(scsi_qla_host_t *vha, unsigned long interval)
359 timer_setup(&vha->timer, qla2x00_timer, 0);
360 vha->timer.expires = jiffies + interval * HZ;
361 add_timer(&vha->timer);
362 vha->timer_active = 1;
366 qla2x00_restart_timer(scsi_qla_host_t *vha, unsigned long interval)
368 /* Currently used for 82XX only. */
369 if (vha->device_flags & DFLG_DEV_FAILED) {
370 ql_dbg(ql_dbg_timer, vha, 0x600d,
371 "Device in a failed state, returning.\n");
375 mod_timer(&vha->timer, jiffies + interval * HZ);
378 static __inline__ void
379 qla2x00_stop_timer(scsi_qla_host_t *vha)
381 del_timer_sync(&vha->timer);
382 vha->timer_active = 0;
385 static int qla2x00_do_dpc(void *data);
387 static void qla2x00_rst_aen(scsi_qla_host_t *);
389 static int qla2x00_mem_alloc(struct qla_hw_data *, uint16_t, uint16_t,
390 struct req_que **, struct rsp_que **);
391 static void qla2x00_free_fw_dump(struct qla_hw_data *);
392 static void qla2x00_mem_free(struct qla_hw_data *);
393 int qla2xxx_mqueuecommand(struct Scsi_Host *host, struct scsi_cmnd *cmd,
394 struct qla_qpair *qpair);
396 /* -------------------------------------------------------------------------- */
397 static void qla_init_base_qpair(struct scsi_qla_host *vha, struct req_que *req,
400 struct qla_hw_data *ha = vha->hw;
402 rsp->qpair = ha->base_qpair;
404 ha->base_qpair->hw = ha;
405 ha->base_qpair->req = req;
406 ha->base_qpair->rsp = rsp;
407 ha->base_qpair->vha = vha;
408 ha->base_qpair->qp_lock_ptr = &ha->hardware_lock;
409 ha->base_qpair->use_shadow_reg = IS_SHADOW_REG_CAPABLE(ha) ? 1 : 0;
410 ha->base_qpair->msix = &ha->msix_entries[QLA_MSIX_RSP_Q];
411 ha->base_qpair->srb_mempool = ha->srb_mempool;
412 INIT_LIST_HEAD(&ha->base_qpair->hints_list);
413 ha->base_qpair->enable_class_2 = ql2xenableclass2;
414 /* init qpair to this cpu. Will adjust at run time. */
415 qla_cpu_update(rsp->qpair, raw_smp_processor_id());
416 ha->base_qpair->pdev = ha->pdev;
418 if (IS_QLA27XX(ha) || IS_QLA83XX(ha) || IS_QLA28XX(ha))
419 ha->base_qpair->reqq_start_iocbs = qla_83xx_start_iocbs;
422 static int qla2x00_alloc_queues(struct qla_hw_data *ha, struct req_que *req,
425 scsi_qla_host_t *vha = pci_get_drvdata(ha->pdev);
427 ha->req_q_map = kcalloc(ha->max_req_queues, sizeof(struct req_que *),
429 if (!ha->req_q_map) {
430 ql_log(ql_log_fatal, vha, 0x003b,
431 "Unable to allocate memory for request queue ptrs.\n");
435 ha->rsp_q_map = kcalloc(ha->max_rsp_queues, sizeof(struct rsp_que *),
437 if (!ha->rsp_q_map) {
438 ql_log(ql_log_fatal, vha, 0x003c,
439 "Unable to allocate memory for response queue ptrs.\n");
443 ha->base_qpair = kzalloc(sizeof(struct qla_qpair), GFP_KERNEL);
444 if (ha->base_qpair == NULL) {
445 ql_log(ql_log_warn, vha, 0x00e0,
446 "Failed to allocate base queue pair memory.\n");
447 goto fail_base_qpair;
450 qla_init_base_qpair(vha, req, rsp);
452 if ((ql2xmqsupport || ql2xnvmeenable) && ha->max_qpairs) {
453 ha->queue_pair_map = kcalloc(ha->max_qpairs, sizeof(struct qla_qpair *),
455 if (!ha->queue_pair_map) {
456 ql_log(ql_log_fatal, vha, 0x0180,
457 "Unable to allocate memory for queue pair ptrs.\n");
463 * Make sure we record at least the request and response queue zero in
464 * case we need to free them if part of the probe fails.
466 ha->rsp_q_map[0] = rsp;
467 ha->req_q_map[0] = req;
468 set_bit(0, ha->rsp_qid_map);
469 set_bit(0, ha->req_qid_map);
473 kfree(ha->base_qpair);
474 ha->base_qpair = NULL;
476 kfree(ha->rsp_q_map);
477 ha->rsp_q_map = NULL;
479 kfree(ha->req_q_map);
480 ha->req_q_map = NULL;
485 static void qla2x00_free_req_que(struct qla_hw_data *ha, struct req_que *req)
487 if (IS_QLAFX00(ha)) {
488 if (req && req->ring_fx00)
489 dma_free_coherent(&ha->pdev->dev,
490 (req->length_fx00 + 1) * sizeof(request_t),
491 req->ring_fx00, req->dma_fx00);
492 } else if (req && req->ring)
493 dma_free_coherent(&ha->pdev->dev,
494 (req->length + 1) * sizeof(request_t),
495 req->ring, req->dma);
498 kfree(req->outstanding_cmds);
503 static void qla2x00_free_rsp_que(struct qla_hw_data *ha, struct rsp_que *rsp)
505 if (IS_QLAFX00(ha)) {
506 if (rsp && rsp->ring_fx00)
507 dma_free_coherent(&ha->pdev->dev,
508 (rsp->length_fx00 + 1) * sizeof(request_t),
509 rsp->ring_fx00, rsp->dma_fx00);
510 } else if (rsp && rsp->ring) {
511 dma_free_coherent(&ha->pdev->dev,
512 (rsp->length + 1) * sizeof(response_t),
513 rsp->ring, rsp->dma);
518 static void qla2x00_free_queues(struct qla_hw_data *ha)
525 if (ha->queue_pair_map) {
526 kfree(ha->queue_pair_map);
527 ha->queue_pair_map = NULL;
529 if (ha->base_qpair) {
530 kfree(ha->base_qpair);
531 ha->base_qpair = NULL;
534 spin_lock_irqsave(&ha->hardware_lock, flags);
535 for (cnt = 0; cnt < ha->max_req_queues; cnt++) {
536 if (!test_bit(cnt, ha->req_qid_map))
539 req = ha->req_q_map[cnt];
540 clear_bit(cnt, ha->req_qid_map);
541 ha->req_q_map[cnt] = NULL;
543 spin_unlock_irqrestore(&ha->hardware_lock, flags);
544 qla2x00_free_req_que(ha, req);
545 spin_lock_irqsave(&ha->hardware_lock, flags);
547 spin_unlock_irqrestore(&ha->hardware_lock, flags);
549 kfree(ha->req_q_map);
550 ha->req_q_map = NULL;
553 spin_lock_irqsave(&ha->hardware_lock, flags);
554 for (cnt = 0; cnt < ha->max_rsp_queues; cnt++) {
555 if (!test_bit(cnt, ha->rsp_qid_map))
558 rsp = ha->rsp_q_map[cnt];
559 clear_bit(cnt, ha->rsp_qid_map);
560 ha->rsp_q_map[cnt] = NULL;
561 spin_unlock_irqrestore(&ha->hardware_lock, flags);
562 qla2x00_free_rsp_que(ha, rsp);
563 spin_lock_irqsave(&ha->hardware_lock, flags);
565 spin_unlock_irqrestore(&ha->hardware_lock, flags);
567 kfree(ha->rsp_q_map);
568 ha->rsp_q_map = NULL;
572 qla2x00_pci_info_str(struct scsi_qla_host *vha, char *str, size_t str_len)
574 struct qla_hw_data *ha = vha->hw;
575 static const char *const pci_bus_modes[] = {
576 "33", "66", "100", "133",
580 pci_bus = (ha->pci_attr & (BIT_9 | BIT_10)) >> 9;
582 snprintf(str, str_len, "PCI-X (%s MHz)",
583 pci_bus_modes[pci_bus]);
585 pci_bus = (ha->pci_attr & BIT_8) >> 8;
586 snprintf(str, str_len, "PCI (%s MHz)", pci_bus_modes[pci_bus]);
593 qla24xx_pci_info_str(struct scsi_qla_host *vha, char *str, size_t str_len)
595 static const char *const pci_bus_modes[] = {
596 "33", "66", "100", "133",
598 struct qla_hw_data *ha = vha->hw;
601 if (pci_is_pcie(ha->pdev)) {
602 uint32_t lstat, lspeed, lwidth;
603 const char *speed_str;
605 pcie_capability_read_dword(ha->pdev, PCI_EXP_LNKCAP, &lstat);
606 lspeed = lstat & PCI_EXP_LNKCAP_SLS;
607 lwidth = (lstat & PCI_EXP_LNKCAP_MLW) >> 4;
611 speed_str = "2.5GT/s";
614 speed_str = "5.0GT/s";
617 speed_str = "8.0GT/s";
620 speed_str = "16.0GT/s";
623 speed_str = "<unknown>";
626 snprintf(str, str_len, "PCIe (%s x%d)", speed_str, lwidth);
631 pci_bus = (ha->pci_attr & CSRX_PCIX_BUS_MODE_MASK) >> 8;
632 if (pci_bus == 0 || pci_bus == 8)
633 snprintf(str, str_len, "PCI (%s MHz)",
634 pci_bus_modes[pci_bus >> 3]);
636 snprintf(str, str_len, "PCI-X Mode %d (%s MHz)",
638 pci_bus_modes[pci_bus & 3]);
644 qla2x00_fw_version_str(struct scsi_qla_host *vha, char *str, size_t size)
647 struct qla_hw_data *ha = vha->hw;
649 snprintf(str, size, "%d.%02d.%02d ", ha->fw_major_version,
650 ha->fw_minor_version, ha->fw_subminor_version);
652 if (ha->fw_attributes & BIT_9) {
657 switch (ha->fw_attributes & 0xFF) {
671 sprintf(un_str, "(%x)", ha->fw_attributes);
675 if (ha->fw_attributes & 0x100)
682 qla24xx_fw_version_str(struct scsi_qla_host *vha, char *str, size_t size)
684 struct qla_hw_data *ha = vha->hw;
686 snprintf(str, size, "%d.%02d.%02d (%x)", ha->fw_major_version,
687 ha->fw_minor_version, ha->fw_subminor_version, ha->fw_attributes);
691 void qla2x00_sp_free_dma(srb_t *sp)
693 struct qla_hw_data *ha = sp->vha->hw;
694 struct scsi_cmnd *cmd = GET_CMD_SP(sp);
696 if (sp->flags & SRB_DMA_VALID) {
698 sp->flags &= ~SRB_DMA_VALID;
701 if (sp->flags & SRB_CRC_PROT_DMA_VALID) {
702 dma_unmap_sg(&ha->pdev->dev, scsi_prot_sglist(cmd),
703 scsi_prot_sg_count(cmd), cmd->sc_data_direction);
704 sp->flags &= ~SRB_CRC_PROT_DMA_VALID;
707 if (sp->flags & SRB_CRC_CTX_DSD_VALID) {
708 /* List assured to be having elements */
709 qla2x00_clean_dsd_pool(ha, sp->u.scmd.crc_ctx);
710 sp->flags &= ~SRB_CRC_CTX_DSD_VALID;
713 if (sp->flags & SRB_CRC_CTX_DMA_VALID) {
714 struct crc_context *ctx0 = sp->u.scmd.crc_ctx;
716 dma_pool_free(ha->dl_dma_pool, ctx0, ctx0->crc_ctx_dma);
717 sp->flags &= ~SRB_CRC_CTX_DMA_VALID;
720 if (sp->flags & SRB_FCP_CMND_DMA_VALID) {
721 struct ct6_dsd *ctx1 = sp->u.scmd.ct6_ctx;
723 dma_pool_free(ha->fcp_cmnd_dma_pool, ctx1->fcp_cmnd,
725 list_splice(&ctx1->dsd_list, &ha->gbl_dsd_list);
726 ha->gbl_dsd_inuse -= ctx1->dsd_use_cnt;
727 ha->gbl_dsd_avail += ctx1->dsd_use_cnt;
728 mempool_free(ctx1, ha->ctx_mempool);
732 void qla2x00_sp_compl(srb_t *sp, int res)
734 struct scsi_cmnd *cmd = GET_CMD_SP(sp);
735 struct completion *comp = sp->comp;
745 void qla2xxx_qpair_sp_free_dma(srb_t *sp)
747 struct scsi_cmnd *cmd = GET_CMD_SP(sp);
748 struct qla_hw_data *ha = sp->fcport->vha->hw;
750 if (sp->flags & SRB_DMA_VALID) {
752 sp->flags &= ~SRB_DMA_VALID;
755 if (sp->flags & SRB_CRC_PROT_DMA_VALID) {
756 dma_unmap_sg(&ha->pdev->dev, scsi_prot_sglist(cmd),
757 scsi_prot_sg_count(cmd), cmd->sc_data_direction);
758 sp->flags &= ~SRB_CRC_PROT_DMA_VALID;
761 if (sp->flags & SRB_CRC_CTX_DSD_VALID) {
762 /* List assured to be having elements */
763 qla2x00_clean_dsd_pool(ha, sp->u.scmd.crc_ctx);
764 sp->flags &= ~SRB_CRC_CTX_DSD_VALID;
767 if (sp->flags & SRB_DIF_BUNDL_DMA_VALID) {
768 struct crc_context *difctx = sp->u.scmd.crc_ctx;
769 struct dsd_dma *dif_dsd, *nxt_dsd;
771 list_for_each_entry_safe(dif_dsd, nxt_dsd,
772 &difctx->ldif_dma_hndl_list, list) {
773 list_del(&dif_dsd->list);
774 dma_pool_free(ha->dif_bundl_pool, dif_dsd->dsd_addr,
775 dif_dsd->dsd_list_dma);
777 difctx->no_dif_bundl--;
780 list_for_each_entry_safe(dif_dsd, nxt_dsd,
781 &difctx->ldif_dsd_list, list) {
782 list_del(&dif_dsd->list);
783 dma_pool_free(ha->dl_dma_pool, dif_dsd->dsd_addr,
784 dif_dsd->dsd_list_dma);
786 difctx->no_ldif_dsd--;
789 if (difctx->no_ldif_dsd) {
790 ql_dbg(ql_dbg_tgt+ql_dbg_verbose, sp->vha, 0xe022,
791 "%s: difctx->no_ldif_dsd=%x\n",
792 __func__, difctx->no_ldif_dsd);
795 if (difctx->no_dif_bundl) {
796 ql_dbg(ql_dbg_tgt+ql_dbg_verbose, sp->vha, 0xe022,
797 "%s: difctx->no_dif_bundl=%x\n",
798 __func__, difctx->no_dif_bundl);
800 sp->flags &= ~SRB_DIF_BUNDL_DMA_VALID;
803 if (sp->flags & SRB_FCP_CMND_DMA_VALID) {
804 struct ct6_dsd *ctx1 = sp->u.scmd.ct6_ctx;
806 dma_pool_free(ha->fcp_cmnd_dma_pool, ctx1->fcp_cmnd,
808 list_splice(&ctx1->dsd_list, &ha->gbl_dsd_list);
809 ha->gbl_dsd_inuse -= ctx1->dsd_use_cnt;
810 ha->gbl_dsd_avail += ctx1->dsd_use_cnt;
811 mempool_free(ctx1, ha->ctx_mempool);
812 sp->flags &= ~SRB_FCP_CMND_DMA_VALID;
815 if (sp->flags & SRB_CRC_CTX_DMA_VALID) {
816 struct crc_context *ctx0 = sp->u.scmd.crc_ctx;
818 dma_pool_free(ha->dl_dma_pool, ctx0, ctx0->crc_ctx_dma);
819 sp->flags &= ~SRB_CRC_CTX_DMA_VALID;
823 void qla2xxx_qpair_sp_compl(srb_t *sp, int res)
825 struct scsi_cmnd *cmd = GET_CMD_SP(sp);
826 struct completion *comp = sp->comp;
837 qla2xxx_queuecommand(struct Scsi_Host *host, struct scsi_cmnd *cmd)
839 scsi_qla_host_t *vha = shost_priv(host);
840 fc_port_t *fcport = (struct fc_port *) cmd->device->hostdata;
841 struct fc_rport *rport = starget_to_rport(scsi_target(cmd->device));
842 struct qla_hw_data *ha = vha->hw;
843 struct scsi_qla_host *base_vha = pci_get_drvdata(ha->pdev);
847 if (unlikely(test_bit(UNLOADING, &base_vha->dpc_flags)) ||
848 WARN_ON_ONCE(!rport)) {
849 cmd->result = DID_NO_CONNECT << 16;
850 goto qc24_fail_command;
856 struct qla_qpair *qpair = NULL;
858 tag = blk_mq_unique_tag(scsi_cmd_to_rq(cmd));
859 hwq = blk_mq_unique_tag_to_hwq(tag);
860 qpair = ha->queue_pair_map[hwq];
863 return qla2xxx_mqueuecommand(host, cmd, qpair);
866 if (ha->flags.eeh_busy) {
867 if (ha->flags.pci_channel_io_perm_failure) {
868 ql_dbg(ql_dbg_aer, vha, 0x9010,
869 "PCI Channel IO permanent failure, exiting "
871 cmd->result = DID_NO_CONNECT << 16;
873 ql_dbg(ql_dbg_aer, vha, 0x9011,
874 "EEH_Busy, Requeuing the cmd=%p.\n", cmd);
875 cmd->result = DID_REQUEUE << 16;
877 goto qc24_fail_command;
880 rval = fc_remote_port_chkready(rport);
883 ql_dbg(ql_dbg_io + ql_dbg_verbose, vha, 0x3003,
884 "fc_remote_port_chkready failed for cmd=%p, rval=0x%x.\n",
886 goto qc24_fail_command;
889 if (!vha->flags.difdix_supported &&
890 scsi_get_prot_op(cmd) != SCSI_PROT_NORMAL) {
891 ql_dbg(ql_dbg_io, vha, 0x3004,
892 "DIF Cap not reg, fail DIF capable cmd's:%p.\n",
894 cmd->result = DID_NO_CONNECT << 16;
895 goto qc24_fail_command;
898 if (!fcport || fcport->deleted) {
899 cmd->result = DID_IMM_RETRY << 16;
900 goto qc24_fail_command;
903 if (atomic_read(&fcport->state) != FCS_ONLINE || fcport->deleted) {
904 if (atomic_read(&fcport->state) == FCS_DEVICE_DEAD ||
905 atomic_read(&base_vha->loop_state) == LOOP_DEAD) {
906 ql_dbg(ql_dbg_io, vha, 0x3005,
907 "Returning DNC, fcport_state=%d loop_state=%d.\n",
908 atomic_read(&fcport->state),
909 atomic_read(&base_vha->loop_state));
910 cmd->result = DID_NO_CONNECT << 16;
911 goto qc24_fail_command;
913 goto qc24_target_busy;
917 * Return target busy if we've received a non-zero retry_delay_timer
920 if (fcport->retry_delay_timestamp == 0) {
921 /* retry delay not set */
922 } else if (time_after(jiffies, fcport->retry_delay_timestamp))
923 fcport->retry_delay_timestamp = 0;
925 goto qc24_target_busy;
927 sp = scsi_cmd_priv(cmd);
928 qla2xxx_init_sp(sp, vha, vha->hw->base_qpair, fcport);
930 sp->u.scmd.cmd = cmd;
931 sp->type = SRB_SCSI_CMD;
933 CMD_SP(cmd) = (void *)sp;
934 sp->free = qla2x00_sp_free_dma;
935 sp->done = qla2x00_sp_compl;
937 rval = ha->isp_ops->start_scsi(sp);
938 if (rval != QLA_SUCCESS) {
939 ql_dbg(ql_dbg_io + ql_dbg_verbose, vha, 0x3013,
940 "Start scsi failed rval=%d for cmd=%p.\n", rval, cmd);
941 goto qc24_host_busy_free_sp;
946 qc24_host_busy_free_sp:
950 return SCSI_MLQUEUE_TARGET_BUSY;
958 /* For MQ supported I/O */
960 qla2xxx_mqueuecommand(struct Scsi_Host *host, struct scsi_cmnd *cmd,
961 struct qla_qpair *qpair)
963 scsi_qla_host_t *vha = shost_priv(host);
964 fc_port_t *fcport = (struct fc_port *) cmd->device->hostdata;
965 struct fc_rport *rport = starget_to_rport(scsi_target(cmd->device));
966 struct qla_hw_data *ha = vha->hw;
967 struct scsi_qla_host *base_vha = pci_get_drvdata(ha->pdev);
971 rval = rport ? fc_remote_port_chkready(rport) : (DID_NO_CONNECT << 16);
974 ql_dbg(ql_dbg_io + ql_dbg_verbose, vha, 0x3076,
975 "fc_remote_port_chkready failed for cmd=%p, rval=0x%x.\n",
977 goto qc24_fail_command;
980 if (!qpair->online) {
981 ql_dbg(ql_dbg_io, vha, 0x3077,
982 "qpair not online. eeh_busy=%d.\n", ha->flags.eeh_busy);
983 cmd->result = DID_NO_CONNECT << 16;
984 goto qc24_fail_command;
987 if (!fcport || fcport->deleted) {
988 cmd->result = DID_IMM_RETRY << 16;
989 goto qc24_fail_command;
992 if (atomic_read(&fcport->state) != FCS_ONLINE || fcport->deleted) {
993 if (atomic_read(&fcport->state) == FCS_DEVICE_DEAD ||
994 atomic_read(&base_vha->loop_state) == LOOP_DEAD) {
995 ql_dbg(ql_dbg_io, vha, 0x3077,
996 "Returning DNC, fcport_state=%d loop_state=%d.\n",
997 atomic_read(&fcport->state),
998 atomic_read(&base_vha->loop_state));
999 cmd->result = DID_NO_CONNECT << 16;
1000 goto qc24_fail_command;
1002 goto qc24_target_busy;
1006 * Return target busy if we've received a non-zero retry_delay_timer
1009 if (fcport->retry_delay_timestamp == 0) {
1010 /* retry delay not set */
1011 } else if (time_after(jiffies, fcport->retry_delay_timestamp))
1012 fcport->retry_delay_timestamp = 0;
1014 goto qc24_target_busy;
1016 sp = scsi_cmd_priv(cmd);
1017 qla2xxx_init_sp(sp, vha, qpair, fcport);
1019 sp->u.scmd.cmd = cmd;
1020 sp->type = SRB_SCSI_CMD;
1021 CMD_SP(cmd) = (void *)sp;
1022 sp->free = qla2xxx_qpair_sp_free_dma;
1023 sp->done = qla2xxx_qpair_sp_compl;
1025 rval = ha->isp_ops->start_scsi_mq(sp);
1026 if (rval != QLA_SUCCESS) {
1027 ql_dbg(ql_dbg_io + ql_dbg_verbose, vha, 0x3078,
1028 "Start scsi failed rval=%d for cmd=%p.\n", rval, cmd);
1029 goto qc24_host_busy_free_sp;
1034 qc24_host_busy_free_sp:
1038 return SCSI_MLQUEUE_TARGET_BUSY;
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 fc_port *fcport;
1699 struct qla_hw_data *ha = vha->hw;
1701 if (IS_QLAFX00(ha)) {
1702 return qlafx00_loop_reset(vha);
1705 if (ql2xtargetreset == 1 && ha->flags.enable_target_reset) {
1706 list_for_each_entry(fcport, &vha->vp_fcports, list) {
1707 if (fcport->port_type != FCT_TARGET)
1710 ret = ha->isp_ops->target_reset(fcport, 0, 0);
1711 if (ret != QLA_SUCCESS) {
1712 ql_dbg(ql_dbg_taskm, vha, 0x802c,
1713 "Bus Reset failed: Reset=%d "
1714 "d_id=%x.\n", ret, fcport->d_id.b24);
1720 if (ha->flags.enable_lip_full_login && !IS_CNA_CAPABLE(ha)) {
1721 atomic_set(&vha->loop_state, LOOP_DOWN);
1722 atomic_set(&vha->loop_down_timer, LOOP_DOWN_TIME);
1723 qla2x00_mark_all_devices_lost(vha);
1724 ret = qla2x00_full_login_lip(vha);
1725 if (ret != QLA_SUCCESS) {
1726 ql_dbg(ql_dbg_taskm, vha, 0x802d,
1727 "full_login_lip=%d.\n", ret);
1731 if (ha->flags.enable_lip_reset) {
1732 ret = qla2x00_lip_reset(vha);
1733 if (ret != QLA_SUCCESS)
1734 ql_dbg(ql_dbg_taskm, vha, 0x802e,
1735 "lip_reset failed (%d).\n", ret);
1738 /* Issue marker command only when we are going to start the I/O */
1739 vha->marker_needed = 1;
1745 * The caller must ensure that no completion interrupts will happen
1746 * while this function is in progress.
1748 static void qla2x00_abort_srb(struct qla_qpair *qp, srb_t *sp, const int res,
1749 unsigned long *flags)
1750 __releases(qp->qp_lock_ptr)
1751 __acquires(qp->qp_lock_ptr)
1753 DECLARE_COMPLETION_ONSTACK(comp);
1754 scsi_qla_host_t *vha = qp->vha;
1755 struct qla_hw_data *ha = vha->hw;
1756 struct scsi_cmnd *cmd = GET_CMD_SP(sp);
1761 lockdep_assert_held(qp->qp_lock_ptr);
1763 if (qla2x00_chip_is_down(vha)) {
1768 if (sp->type == SRB_NVME_CMD || sp->type == SRB_NVME_LS ||
1769 (sp->type == SRB_SCSI_CMD && !ha->flags.eeh_busy &&
1770 !test_bit(ABORT_ISP_ACTIVE, &vha->dpc_flags) &&
1771 !qla2x00_isp_reg_stat(ha))) {
1778 spin_unlock_irqrestore(qp->qp_lock_ptr, *flags);
1780 rval = ha->isp_ops->abort_command(sp);
1781 /* Wait for command completion. */
1783 ratov_j = ha->r_a_tov/10 * 4 * 1000;
1784 ratov_j = msecs_to_jiffies(ratov_j);
1787 if (wait_for_completion_timeout(&comp, ratov_j)) {
1788 ql_dbg(ql_dbg_taskm, vha, 0xffff,
1789 "%s: Abort wait timer (4 * R_A_TOV[%d]) expired\n",
1790 __func__, ha->r_a_tov/10);
1793 /* else FW return SP to driver */
1800 spin_lock_irqsave(qp->qp_lock_ptr, *flags);
1801 if (ret_cmd && blk_mq_request_started(scsi_cmd_to_rq(cmd)))
1809 * The caller must ensure that no completion interrupts will happen
1810 * while this function is in progress.
1813 __qla2x00_abort_all_cmds(struct qla_qpair *qp, int res)
1816 unsigned long flags;
1818 scsi_qla_host_t *vha = qp->vha;
1819 struct qla_hw_data *ha = vha->hw;
1820 struct req_que *req;
1821 struct qla_tgt *tgt = vha->vha_tgt.qla_tgt;
1822 struct qla_tgt_cmd *cmd;
1826 spin_lock_irqsave(qp->qp_lock_ptr, flags);
1828 for (cnt = 1; cnt < req->num_outstanding_cmds; cnt++) {
1829 sp = req->outstanding_cmds[cnt];
1831 switch (sp->cmd_type) {
1833 qla2x00_abort_srb(qp, sp, res, &flags);
1836 if (!vha->hw->tgt.tgt_ops || !tgt ||
1837 qla_ini_mode_enabled(vha)) {
1838 ql_dbg(ql_dbg_tgt_mgt, vha, 0xf003,
1839 "HOST-ABORT-HNDLR: dpc_flags=%lx. Target mode disabled\n",
1843 cmd = (struct qla_tgt_cmd *)sp;
1846 case TYPE_TGT_TMCMD:
1847 /* Skip task management functions. */
1852 req->outstanding_cmds[cnt] = NULL;
1855 spin_unlock_irqrestore(qp->qp_lock_ptr, flags);
1859 * The caller must ensure that no completion interrupts will happen
1860 * while this function is in progress.
1863 qla2x00_abort_all_cmds(scsi_qla_host_t *vha, int res)
1866 struct qla_hw_data *ha = vha->hw;
1868 /* Continue only if initialization complete. */
1869 if (!ha->base_qpair)
1871 __qla2x00_abort_all_cmds(ha->base_qpair, res);
1873 if (!ha->queue_pair_map)
1875 for (que = 0; que < ha->max_qpairs; que++) {
1876 if (!ha->queue_pair_map[que])
1879 __qla2x00_abort_all_cmds(ha->queue_pair_map[que], res);
1884 qla2xxx_slave_alloc(struct scsi_device *sdev)
1886 struct fc_rport *rport = starget_to_rport(scsi_target(sdev));
1888 if (!rport || fc_remote_port_chkready(rport))
1891 sdev->hostdata = *(fc_port_t **)rport->dd_data;
1897 qla2xxx_slave_configure(struct scsi_device *sdev)
1899 scsi_qla_host_t *vha = shost_priv(sdev->host);
1900 struct req_que *req = vha->req;
1902 if (IS_T10_PI_CAPABLE(vha->hw))
1903 blk_queue_update_dma_alignment(sdev->request_queue, 0x7);
1905 scsi_change_queue_depth(sdev, req->max_q_depth);
1910 qla2xxx_slave_destroy(struct scsi_device *sdev)
1912 sdev->hostdata = NULL;
1916 * qla2x00_config_dma_addressing() - Configure OS DMA addressing method.
1919 * At exit, the @ha's flags.enable_64bit_addressing set to indicated
1920 * supported addressing method.
1923 qla2x00_config_dma_addressing(struct qla_hw_data *ha)
1925 /* Assume a 32bit DMA mask. */
1926 ha->flags.enable_64bit_addressing = 0;
1928 if (!dma_set_mask(&ha->pdev->dev, DMA_BIT_MASK(64))) {
1929 /* Any upper-dword bits set? */
1930 if (MSD(dma_get_required_mask(&ha->pdev->dev)) &&
1931 !dma_set_coherent_mask(&ha->pdev->dev, DMA_BIT_MASK(64))) {
1932 /* Ok, a 64bit DMA mask is applicable. */
1933 ha->flags.enable_64bit_addressing = 1;
1934 ha->isp_ops->calc_req_entries = qla2x00_calc_iocbs_64;
1935 ha->isp_ops->build_iocbs = qla2x00_build_scsi_iocbs_64;
1940 dma_set_mask(&ha->pdev->dev, DMA_BIT_MASK(32));
1941 dma_set_coherent_mask(&ha->pdev->dev, DMA_BIT_MASK(32));
1945 qla2x00_enable_intrs(struct qla_hw_data *ha)
1947 unsigned long flags = 0;
1948 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
1950 spin_lock_irqsave(&ha->hardware_lock, flags);
1951 ha->interrupts_on = 1;
1952 /* enable risc and host interrupts */
1953 wrt_reg_word(®->ictrl, ICR_EN_INT | ICR_EN_RISC);
1954 rd_reg_word(®->ictrl);
1955 spin_unlock_irqrestore(&ha->hardware_lock, flags);
1960 qla2x00_disable_intrs(struct qla_hw_data *ha)
1962 unsigned long flags = 0;
1963 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
1965 spin_lock_irqsave(&ha->hardware_lock, flags);
1966 ha->interrupts_on = 0;
1967 /* disable risc and host interrupts */
1968 wrt_reg_word(®->ictrl, 0);
1969 rd_reg_word(®->ictrl);
1970 spin_unlock_irqrestore(&ha->hardware_lock, flags);
1974 qla24xx_enable_intrs(struct qla_hw_data *ha)
1976 unsigned long flags = 0;
1977 struct device_reg_24xx __iomem *reg = &ha->iobase->isp24;
1979 spin_lock_irqsave(&ha->hardware_lock, flags);
1980 ha->interrupts_on = 1;
1981 wrt_reg_dword(®->ictrl, ICRX_EN_RISC_INT);
1982 rd_reg_dword(®->ictrl);
1983 spin_unlock_irqrestore(&ha->hardware_lock, flags);
1987 qla24xx_disable_intrs(struct qla_hw_data *ha)
1989 unsigned long flags = 0;
1990 struct device_reg_24xx __iomem *reg = &ha->iobase->isp24;
1992 if (IS_NOPOLLING_TYPE(ha))
1994 spin_lock_irqsave(&ha->hardware_lock, flags);
1995 ha->interrupts_on = 0;
1996 wrt_reg_dword(®->ictrl, 0);
1997 rd_reg_dword(®->ictrl);
1998 spin_unlock_irqrestore(&ha->hardware_lock, flags);
2002 qla2x00_iospace_config(struct qla_hw_data *ha)
2004 resource_size_t pio;
2007 if (pci_request_selected_regions(ha->pdev, ha->bars,
2008 QLA2XXX_DRIVER_NAME)) {
2009 ql_log_pci(ql_log_fatal, ha->pdev, 0x0011,
2010 "Failed to reserve PIO/MMIO regions (%s), aborting.\n",
2011 pci_name(ha->pdev));
2012 goto iospace_error_exit;
2014 if (!(ha->bars & 1))
2017 /* We only need PIO for Flash operations on ISP2312 v2 chips. */
2018 pio = pci_resource_start(ha->pdev, 0);
2019 if (pci_resource_flags(ha->pdev, 0) & IORESOURCE_IO) {
2020 if (pci_resource_len(ha->pdev, 0) < MIN_IOBASE_LEN) {
2021 ql_log_pci(ql_log_warn, ha->pdev, 0x0012,
2022 "Invalid pci I/O region size (%s).\n",
2023 pci_name(ha->pdev));
2027 ql_log_pci(ql_log_warn, ha->pdev, 0x0013,
2028 "Region #0 no a PIO resource (%s).\n",
2029 pci_name(ha->pdev));
2032 ha->pio_address = pio;
2033 ql_dbg_pci(ql_dbg_init, ha->pdev, 0x0014,
2034 "PIO address=%llu.\n",
2035 (unsigned long long)ha->pio_address);
2038 /* Use MMIO operations for all accesses. */
2039 if (!(pci_resource_flags(ha->pdev, 1) & IORESOURCE_MEM)) {
2040 ql_log_pci(ql_log_fatal, ha->pdev, 0x0015,
2041 "Region #1 not an MMIO resource (%s), aborting.\n",
2042 pci_name(ha->pdev));
2043 goto iospace_error_exit;
2045 if (pci_resource_len(ha->pdev, 1) < MIN_IOBASE_LEN) {
2046 ql_log_pci(ql_log_fatal, ha->pdev, 0x0016,
2047 "Invalid PCI mem region size (%s), aborting.\n",
2048 pci_name(ha->pdev));
2049 goto iospace_error_exit;
2052 ha->iobase = ioremap(pci_resource_start(ha->pdev, 1), MIN_IOBASE_LEN);
2054 ql_log_pci(ql_log_fatal, ha->pdev, 0x0017,
2055 "Cannot remap MMIO (%s), aborting.\n",
2056 pci_name(ha->pdev));
2057 goto iospace_error_exit;
2060 /* Determine queue resources */
2061 ha->max_req_queues = ha->max_rsp_queues = 1;
2062 ha->msix_count = QLA_BASE_VECTORS;
2064 /* Check if FW supports MQ or not */
2065 if (!(ha->fw_attributes & BIT_6))
2068 if (!ql2xmqsupport || !ql2xnvmeenable ||
2069 (!IS_QLA25XX(ha) && !IS_QLA81XX(ha)))
2072 ha->mqiobase = ioremap(pci_resource_start(ha->pdev, 3),
2073 pci_resource_len(ha->pdev, 3));
2075 ql_dbg_pci(ql_dbg_init, ha->pdev, 0x0018,
2076 "MQIO Base=%p.\n", ha->mqiobase);
2077 /* Read MSIX vector size of the board */
2078 pci_read_config_word(ha->pdev, QLA_PCI_MSIX_CONTROL, &msix);
2079 ha->msix_count = msix + 1;
2080 /* Max queues are bounded by available msix vectors */
2081 /* MB interrupt uses 1 vector */
2082 ha->max_req_queues = ha->msix_count - 1;
2083 ha->max_rsp_queues = ha->max_req_queues;
2084 /* Queue pairs is the max value minus the base queue pair */
2085 ha->max_qpairs = ha->max_rsp_queues - 1;
2086 ql_dbg_pci(ql_dbg_init, ha->pdev, 0x0188,
2087 "Max no of queues pairs: %d.\n", ha->max_qpairs);
2089 ql_log_pci(ql_log_info, ha->pdev, 0x001a,
2090 "MSI-X vector count: %d.\n", ha->msix_count);
2092 ql_log_pci(ql_log_info, ha->pdev, 0x001b,
2093 "BAR 3 not enabled.\n");
2096 ql_dbg_pci(ql_dbg_init, ha->pdev, 0x001c,
2097 "MSIX Count: %d.\n", ha->msix_count);
2106 qla83xx_iospace_config(struct qla_hw_data *ha)
2110 if (pci_request_selected_regions(ha->pdev, ha->bars,
2111 QLA2XXX_DRIVER_NAME)) {
2112 ql_log_pci(ql_log_fatal, ha->pdev, 0x0117,
2113 "Failed to reserve PIO/MMIO regions (%s), aborting.\n",
2114 pci_name(ha->pdev));
2116 goto iospace_error_exit;
2119 /* Use MMIO operations for all accesses. */
2120 if (!(pci_resource_flags(ha->pdev, 0) & IORESOURCE_MEM)) {
2121 ql_log_pci(ql_log_warn, ha->pdev, 0x0118,
2122 "Invalid pci I/O region size (%s).\n",
2123 pci_name(ha->pdev));
2124 goto iospace_error_exit;
2126 if (pci_resource_len(ha->pdev, 0) < MIN_IOBASE_LEN) {
2127 ql_log_pci(ql_log_warn, ha->pdev, 0x0119,
2128 "Invalid PCI mem region size (%s), aborting\n",
2129 pci_name(ha->pdev));
2130 goto iospace_error_exit;
2133 ha->iobase = ioremap(pci_resource_start(ha->pdev, 0), MIN_IOBASE_LEN);
2135 ql_log_pci(ql_log_fatal, ha->pdev, 0x011a,
2136 "Cannot remap MMIO (%s), aborting.\n",
2137 pci_name(ha->pdev));
2138 goto iospace_error_exit;
2141 /* 64bit PCI BAR - BAR2 will correspoond to region 4 */
2142 /* 83XX 26XX always use MQ type access for queues
2143 * - mbar 2, a.k.a region 4 */
2144 ha->max_req_queues = ha->max_rsp_queues = 1;
2145 ha->msix_count = QLA_BASE_VECTORS;
2146 ha->mqiobase = ioremap(pci_resource_start(ha->pdev, 4),
2147 pci_resource_len(ha->pdev, 4));
2149 if (!ha->mqiobase) {
2150 ql_log_pci(ql_log_fatal, ha->pdev, 0x011d,
2151 "BAR2/region4 not enabled\n");
2155 ha->msixbase = ioremap(pci_resource_start(ha->pdev, 2),
2156 pci_resource_len(ha->pdev, 2));
2158 /* Read MSIX vector size of the board */
2159 pci_read_config_word(ha->pdev,
2160 QLA_83XX_PCI_MSIX_CONTROL, &msix);
2161 ha->msix_count = (msix & PCI_MSIX_FLAGS_QSIZE) + 1;
2163 * By default, driver uses at least two msix vectors
2166 if (ql2xmqsupport || ql2xnvmeenable) {
2167 /* MB interrupt uses 1 vector */
2168 ha->max_req_queues = ha->msix_count - 1;
2170 /* ATIOQ needs 1 vector. That's 1 less QPair */
2171 if (QLA_TGT_MODE_ENABLED())
2172 ha->max_req_queues--;
2174 ha->max_rsp_queues = ha->max_req_queues;
2176 /* Queue pairs is the max value minus
2177 * the base queue pair */
2178 ha->max_qpairs = ha->max_req_queues - 1;
2179 ql_dbg_pci(ql_dbg_init, ha->pdev, 0x00e3,
2180 "Max no of queues pairs: %d.\n", ha->max_qpairs);
2182 ql_log_pci(ql_log_info, ha->pdev, 0x011c,
2183 "MSI-X vector count: %d.\n", ha->msix_count);
2185 ql_log_pci(ql_log_info, ha->pdev, 0x011e,
2186 "BAR 1 not enabled.\n");
2189 ql_dbg_pci(ql_dbg_init, ha->pdev, 0x011f,
2190 "MSIX Count: %d.\n", ha->msix_count);
2197 static struct isp_operations qla2100_isp_ops = {
2198 .pci_config = qla2100_pci_config,
2199 .reset_chip = qla2x00_reset_chip,
2200 .chip_diag = qla2x00_chip_diag,
2201 .config_rings = qla2x00_config_rings,
2202 .reset_adapter = qla2x00_reset_adapter,
2203 .nvram_config = qla2x00_nvram_config,
2204 .update_fw_options = qla2x00_update_fw_options,
2205 .load_risc = qla2x00_load_risc,
2206 .pci_info_str = qla2x00_pci_info_str,
2207 .fw_version_str = qla2x00_fw_version_str,
2208 .intr_handler = qla2100_intr_handler,
2209 .enable_intrs = qla2x00_enable_intrs,
2210 .disable_intrs = qla2x00_disable_intrs,
2211 .abort_command = qla2x00_abort_command,
2212 .target_reset = qla2x00_abort_target,
2213 .lun_reset = qla2x00_lun_reset,
2214 .fabric_login = qla2x00_login_fabric,
2215 .fabric_logout = qla2x00_fabric_logout,
2216 .calc_req_entries = qla2x00_calc_iocbs_32,
2217 .build_iocbs = qla2x00_build_scsi_iocbs_32,
2218 .prep_ms_iocb = qla2x00_prep_ms_iocb,
2219 .prep_ms_fdmi_iocb = qla2x00_prep_ms_fdmi_iocb,
2220 .read_nvram = qla2x00_read_nvram_data,
2221 .write_nvram = qla2x00_write_nvram_data,
2222 .fw_dump = qla2100_fw_dump,
2225 .beacon_blink = NULL,
2226 .read_optrom = qla2x00_read_optrom_data,
2227 .write_optrom = qla2x00_write_optrom_data,
2228 .get_flash_version = qla2x00_get_flash_version,
2229 .start_scsi = qla2x00_start_scsi,
2230 .start_scsi_mq = NULL,
2231 .abort_isp = qla2x00_abort_isp,
2232 .iospace_config = qla2x00_iospace_config,
2233 .initialize_adapter = qla2x00_initialize_adapter,
2236 static struct isp_operations qla2300_isp_ops = {
2237 .pci_config = qla2300_pci_config,
2238 .reset_chip = qla2x00_reset_chip,
2239 .chip_diag = qla2x00_chip_diag,
2240 .config_rings = qla2x00_config_rings,
2241 .reset_adapter = qla2x00_reset_adapter,
2242 .nvram_config = qla2x00_nvram_config,
2243 .update_fw_options = qla2x00_update_fw_options,
2244 .load_risc = qla2x00_load_risc,
2245 .pci_info_str = qla2x00_pci_info_str,
2246 .fw_version_str = qla2x00_fw_version_str,
2247 .intr_handler = qla2300_intr_handler,
2248 .enable_intrs = qla2x00_enable_intrs,
2249 .disable_intrs = qla2x00_disable_intrs,
2250 .abort_command = qla2x00_abort_command,
2251 .target_reset = qla2x00_abort_target,
2252 .lun_reset = qla2x00_lun_reset,
2253 .fabric_login = qla2x00_login_fabric,
2254 .fabric_logout = qla2x00_fabric_logout,
2255 .calc_req_entries = qla2x00_calc_iocbs_32,
2256 .build_iocbs = qla2x00_build_scsi_iocbs_32,
2257 .prep_ms_iocb = qla2x00_prep_ms_iocb,
2258 .prep_ms_fdmi_iocb = qla2x00_prep_ms_fdmi_iocb,
2259 .read_nvram = qla2x00_read_nvram_data,
2260 .write_nvram = qla2x00_write_nvram_data,
2261 .fw_dump = qla2300_fw_dump,
2262 .beacon_on = qla2x00_beacon_on,
2263 .beacon_off = qla2x00_beacon_off,
2264 .beacon_blink = qla2x00_beacon_blink,
2265 .read_optrom = qla2x00_read_optrom_data,
2266 .write_optrom = qla2x00_write_optrom_data,
2267 .get_flash_version = qla2x00_get_flash_version,
2268 .start_scsi = qla2x00_start_scsi,
2269 .start_scsi_mq = NULL,
2270 .abort_isp = qla2x00_abort_isp,
2271 .iospace_config = qla2x00_iospace_config,
2272 .initialize_adapter = qla2x00_initialize_adapter,
2275 static struct isp_operations qla24xx_isp_ops = {
2276 .pci_config = qla24xx_pci_config,
2277 .reset_chip = qla24xx_reset_chip,
2278 .chip_diag = qla24xx_chip_diag,
2279 .config_rings = qla24xx_config_rings,
2280 .reset_adapter = qla24xx_reset_adapter,
2281 .nvram_config = qla24xx_nvram_config,
2282 .update_fw_options = qla24xx_update_fw_options,
2283 .load_risc = qla24xx_load_risc,
2284 .pci_info_str = qla24xx_pci_info_str,
2285 .fw_version_str = qla24xx_fw_version_str,
2286 .intr_handler = qla24xx_intr_handler,
2287 .enable_intrs = qla24xx_enable_intrs,
2288 .disable_intrs = qla24xx_disable_intrs,
2289 .abort_command = qla24xx_abort_command,
2290 .target_reset = qla24xx_abort_target,
2291 .lun_reset = qla24xx_lun_reset,
2292 .fabric_login = qla24xx_login_fabric,
2293 .fabric_logout = qla24xx_fabric_logout,
2294 .calc_req_entries = NULL,
2295 .build_iocbs = NULL,
2296 .prep_ms_iocb = qla24xx_prep_ms_iocb,
2297 .prep_ms_fdmi_iocb = qla24xx_prep_ms_fdmi_iocb,
2298 .read_nvram = qla24xx_read_nvram_data,
2299 .write_nvram = qla24xx_write_nvram_data,
2300 .fw_dump = qla24xx_fw_dump,
2301 .beacon_on = qla24xx_beacon_on,
2302 .beacon_off = qla24xx_beacon_off,
2303 .beacon_blink = qla24xx_beacon_blink,
2304 .read_optrom = qla24xx_read_optrom_data,
2305 .write_optrom = qla24xx_write_optrom_data,
2306 .get_flash_version = qla24xx_get_flash_version,
2307 .start_scsi = qla24xx_start_scsi,
2308 .start_scsi_mq = NULL,
2309 .abort_isp = qla2x00_abort_isp,
2310 .iospace_config = qla2x00_iospace_config,
2311 .initialize_adapter = qla2x00_initialize_adapter,
2314 static struct isp_operations qla25xx_isp_ops = {
2315 .pci_config = qla25xx_pci_config,
2316 .reset_chip = qla24xx_reset_chip,
2317 .chip_diag = qla24xx_chip_diag,
2318 .config_rings = qla24xx_config_rings,
2319 .reset_adapter = qla24xx_reset_adapter,
2320 .nvram_config = qla24xx_nvram_config,
2321 .update_fw_options = qla24xx_update_fw_options,
2322 .load_risc = qla24xx_load_risc,
2323 .pci_info_str = qla24xx_pci_info_str,
2324 .fw_version_str = qla24xx_fw_version_str,
2325 .intr_handler = qla24xx_intr_handler,
2326 .enable_intrs = qla24xx_enable_intrs,
2327 .disable_intrs = qla24xx_disable_intrs,
2328 .abort_command = qla24xx_abort_command,
2329 .target_reset = qla24xx_abort_target,
2330 .lun_reset = qla24xx_lun_reset,
2331 .fabric_login = qla24xx_login_fabric,
2332 .fabric_logout = qla24xx_fabric_logout,
2333 .calc_req_entries = NULL,
2334 .build_iocbs = NULL,
2335 .prep_ms_iocb = qla24xx_prep_ms_iocb,
2336 .prep_ms_fdmi_iocb = qla24xx_prep_ms_fdmi_iocb,
2337 .read_nvram = qla25xx_read_nvram_data,
2338 .write_nvram = qla25xx_write_nvram_data,
2339 .fw_dump = qla25xx_fw_dump,
2340 .beacon_on = qla24xx_beacon_on,
2341 .beacon_off = qla24xx_beacon_off,
2342 .beacon_blink = qla24xx_beacon_blink,
2343 .read_optrom = qla25xx_read_optrom_data,
2344 .write_optrom = qla24xx_write_optrom_data,
2345 .get_flash_version = qla24xx_get_flash_version,
2346 .start_scsi = qla24xx_dif_start_scsi,
2347 .start_scsi_mq = qla2xxx_dif_start_scsi_mq,
2348 .abort_isp = qla2x00_abort_isp,
2349 .iospace_config = qla2x00_iospace_config,
2350 .initialize_adapter = qla2x00_initialize_adapter,
2353 static struct isp_operations qla81xx_isp_ops = {
2354 .pci_config = qla25xx_pci_config,
2355 .reset_chip = qla24xx_reset_chip,
2356 .chip_diag = qla24xx_chip_diag,
2357 .config_rings = qla24xx_config_rings,
2358 .reset_adapter = qla24xx_reset_adapter,
2359 .nvram_config = qla81xx_nvram_config,
2360 .update_fw_options = qla24xx_update_fw_options,
2361 .load_risc = qla81xx_load_risc,
2362 .pci_info_str = qla24xx_pci_info_str,
2363 .fw_version_str = qla24xx_fw_version_str,
2364 .intr_handler = qla24xx_intr_handler,
2365 .enable_intrs = qla24xx_enable_intrs,
2366 .disable_intrs = qla24xx_disable_intrs,
2367 .abort_command = qla24xx_abort_command,
2368 .target_reset = qla24xx_abort_target,
2369 .lun_reset = qla24xx_lun_reset,
2370 .fabric_login = qla24xx_login_fabric,
2371 .fabric_logout = qla24xx_fabric_logout,
2372 .calc_req_entries = NULL,
2373 .build_iocbs = NULL,
2374 .prep_ms_iocb = qla24xx_prep_ms_iocb,
2375 .prep_ms_fdmi_iocb = qla24xx_prep_ms_fdmi_iocb,
2377 .write_nvram = NULL,
2378 .fw_dump = qla81xx_fw_dump,
2379 .beacon_on = qla24xx_beacon_on,
2380 .beacon_off = qla24xx_beacon_off,
2381 .beacon_blink = qla83xx_beacon_blink,
2382 .read_optrom = qla25xx_read_optrom_data,
2383 .write_optrom = qla24xx_write_optrom_data,
2384 .get_flash_version = qla24xx_get_flash_version,
2385 .start_scsi = qla24xx_dif_start_scsi,
2386 .start_scsi_mq = qla2xxx_dif_start_scsi_mq,
2387 .abort_isp = qla2x00_abort_isp,
2388 .iospace_config = qla2x00_iospace_config,
2389 .initialize_adapter = qla2x00_initialize_adapter,
2392 static struct isp_operations qla82xx_isp_ops = {
2393 .pci_config = qla82xx_pci_config,
2394 .reset_chip = qla82xx_reset_chip,
2395 .chip_diag = qla24xx_chip_diag,
2396 .config_rings = qla82xx_config_rings,
2397 .reset_adapter = qla24xx_reset_adapter,
2398 .nvram_config = qla81xx_nvram_config,
2399 .update_fw_options = qla24xx_update_fw_options,
2400 .load_risc = qla82xx_load_risc,
2401 .pci_info_str = qla24xx_pci_info_str,
2402 .fw_version_str = qla24xx_fw_version_str,
2403 .intr_handler = qla82xx_intr_handler,
2404 .enable_intrs = qla82xx_enable_intrs,
2405 .disable_intrs = qla82xx_disable_intrs,
2406 .abort_command = qla24xx_abort_command,
2407 .target_reset = qla24xx_abort_target,
2408 .lun_reset = qla24xx_lun_reset,
2409 .fabric_login = qla24xx_login_fabric,
2410 .fabric_logout = qla24xx_fabric_logout,
2411 .calc_req_entries = NULL,
2412 .build_iocbs = NULL,
2413 .prep_ms_iocb = qla24xx_prep_ms_iocb,
2414 .prep_ms_fdmi_iocb = qla24xx_prep_ms_fdmi_iocb,
2415 .read_nvram = qla24xx_read_nvram_data,
2416 .write_nvram = qla24xx_write_nvram_data,
2417 .fw_dump = qla82xx_fw_dump,
2418 .beacon_on = qla82xx_beacon_on,
2419 .beacon_off = qla82xx_beacon_off,
2420 .beacon_blink = NULL,
2421 .read_optrom = qla82xx_read_optrom_data,
2422 .write_optrom = qla82xx_write_optrom_data,
2423 .get_flash_version = qla82xx_get_flash_version,
2424 .start_scsi = qla82xx_start_scsi,
2425 .start_scsi_mq = NULL,
2426 .abort_isp = qla82xx_abort_isp,
2427 .iospace_config = qla82xx_iospace_config,
2428 .initialize_adapter = qla2x00_initialize_adapter,
2431 static struct isp_operations qla8044_isp_ops = {
2432 .pci_config = qla82xx_pci_config,
2433 .reset_chip = qla82xx_reset_chip,
2434 .chip_diag = qla24xx_chip_diag,
2435 .config_rings = qla82xx_config_rings,
2436 .reset_adapter = qla24xx_reset_adapter,
2437 .nvram_config = qla81xx_nvram_config,
2438 .update_fw_options = qla24xx_update_fw_options,
2439 .load_risc = qla82xx_load_risc,
2440 .pci_info_str = qla24xx_pci_info_str,
2441 .fw_version_str = qla24xx_fw_version_str,
2442 .intr_handler = qla8044_intr_handler,
2443 .enable_intrs = qla82xx_enable_intrs,
2444 .disable_intrs = qla82xx_disable_intrs,
2445 .abort_command = qla24xx_abort_command,
2446 .target_reset = qla24xx_abort_target,
2447 .lun_reset = qla24xx_lun_reset,
2448 .fabric_login = qla24xx_login_fabric,
2449 .fabric_logout = qla24xx_fabric_logout,
2450 .calc_req_entries = NULL,
2451 .build_iocbs = NULL,
2452 .prep_ms_iocb = qla24xx_prep_ms_iocb,
2453 .prep_ms_fdmi_iocb = qla24xx_prep_ms_fdmi_iocb,
2455 .write_nvram = NULL,
2456 .fw_dump = qla8044_fw_dump,
2457 .beacon_on = qla82xx_beacon_on,
2458 .beacon_off = qla82xx_beacon_off,
2459 .beacon_blink = NULL,
2460 .read_optrom = qla8044_read_optrom_data,
2461 .write_optrom = qla8044_write_optrom_data,
2462 .get_flash_version = qla82xx_get_flash_version,
2463 .start_scsi = qla82xx_start_scsi,
2464 .start_scsi_mq = NULL,
2465 .abort_isp = qla8044_abort_isp,
2466 .iospace_config = qla82xx_iospace_config,
2467 .initialize_adapter = qla2x00_initialize_adapter,
2470 static struct isp_operations qla83xx_isp_ops = {
2471 .pci_config = qla25xx_pci_config,
2472 .reset_chip = qla24xx_reset_chip,
2473 .chip_diag = qla24xx_chip_diag,
2474 .config_rings = qla24xx_config_rings,
2475 .reset_adapter = qla24xx_reset_adapter,
2476 .nvram_config = qla81xx_nvram_config,
2477 .update_fw_options = qla24xx_update_fw_options,
2478 .load_risc = qla81xx_load_risc,
2479 .pci_info_str = qla24xx_pci_info_str,
2480 .fw_version_str = qla24xx_fw_version_str,
2481 .intr_handler = qla24xx_intr_handler,
2482 .enable_intrs = qla24xx_enable_intrs,
2483 .disable_intrs = qla24xx_disable_intrs,
2484 .abort_command = qla24xx_abort_command,
2485 .target_reset = qla24xx_abort_target,
2486 .lun_reset = qla24xx_lun_reset,
2487 .fabric_login = qla24xx_login_fabric,
2488 .fabric_logout = qla24xx_fabric_logout,
2489 .calc_req_entries = NULL,
2490 .build_iocbs = NULL,
2491 .prep_ms_iocb = qla24xx_prep_ms_iocb,
2492 .prep_ms_fdmi_iocb = qla24xx_prep_ms_fdmi_iocb,
2494 .write_nvram = NULL,
2495 .fw_dump = qla83xx_fw_dump,
2496 .beacon_on = qla24xx_beacon_on,
2497 .beacon_off = qla24xx_beacon_off,
2498 .beacon_blink = qla83xx_beacon_blink,
2499 .read_optrom = qla25xx_read_optrom_data,
2500 .write_optrom = qla24xx_write_optrom_data,
2501 .get_flash_version = qla24xx_get_flash_version,
2502 .start_scsi = qla24xx_dif_start_scsi,
2503 .start_scsi_mq = qla2xxx_dif_start_scsi_mq,
2504 .abort_isp = qla2x00_abort_isp,
2505 .iospace_config = qla83xx_iospace_config,
2506 .initialize_adapter = qla2x00_initialize_adapter,
2509 static struct isp_operations qlafx00_isp_ops = {
2510 .pci_config = qlafx00_pci_config,
2511 .reset_chip = qlafx00_soft_reset,
2512 .chip_diag = qlafx00_chip_diag,
2513 .config_rings = qlafx00_config_rings,
2514 .reset_adapter = qlafx00_soft_reset,
2515 .nvram_config = NULL,
2516 .update_fw_options = NULL,
2518 .pci_info_str = qlafx00_pci_info_str,
2519 .fw_version_str = qlafx00_fw_version_str,
2520 .intr_handler = qlafx00_intr_handler,
2521 .enable_intrs = qlafx00_enable_intrs,
2522 .disable_intrs = qlafx00_disable_intrs,
2523 .abort_command = qla24xx_async_abort_command,
2524 .target_reset = qlafx00_abort_target,
2525 .lun_reset = qlafx00_lun_reset,
2526 .fabric_login = NULL,
2527 .fabric_logout = NULL,
2528 .calc_req_entries = NULL,
2529 .build_iocbs = NULL,
2530 .prep_ms_iocb = qla24xx_prep_ms_iocb,
2531 .prep_ms_fdmi_iocb = qla24xx_prep_ms_fdmi_iocb,
2532 .read_nvram = qla24xx_read_nvram_data,
2533 .write_nvram = qla24xx_write_nvram_data,
2535 .beacon_on = qla24xx_beacon_on,
2536 .beacon_off = qla24xx_beacon_off,
2537 .beacon_blink = NULL,
2538 .read_optrom = qla24xx_read_optrom_data,
2539 .write_optrom = qla24xx_write_optrom_data,
2540 .get_flash_version = qla24xx_get_flash_version,
2541 .start_scsi = qlafx00_start_scsi,
2542 .start_scsi_mq = NULL,
2543 .abort_isp = qlafx00_abort_isp,
2544 .iospace_config = qlafx00_iospace_config,
2545 .initialize_adapter = qlafx00_initialize_adapter,
2548 static struct isp_operations qla27xx_isp_ops = {
2549 .pci_config = qla25xx_pci_config,
2550 .reset_chip = qla24xx_reset_chip,
2551 .chip_diag = qla24xx_chip_diag,
2552 .config_rings = qla24xx_config_rings,
2553 .reset_adapter = qla24xx_reset_adapter,
2554 .nvram_config = qla81xx_nvram_config,
2555 .update_fw_options = qla24xx_update_fw_options,
2556 .load_risc = qla81xx_load_risc,
2557 .pci_info_str = qla24xx_pci_info_str,
2558 .fw_version_str = qla24xx_fw_version_str,
2559 .intr_handler = qla24xx_intr_handler,
2560 .enable_intrs = qla24xx_enable_intrs,
2561 .disable_intrs = qla24xx_disable_intrs,
2562 .abort_command = qla24xx_abort_command,
2563 .target_reset = qla24xx_abort_target,
2564 .lun_reset = qla24xx_lun_reset,
2565 .fabric_login = qla24xx_login_fabric,
2566 .fabric_logout = qla24xx_fabric_logout,
2567 .calc_req_entries = NULL,
2568 .build_iocbs = NULL,
2569 .prep_ms_iocb = qla24xx_prep_ms_iocb,
2570 .prep_ms_fdmi_iocb = qla24xx_prep_ms_fdmi_iocb,
2572 .write_nvram = NULL,
2573 .fw_dump = qla27xx_fwdump,
2574 .mpi_fw_dump = qla27xx_mpi_fwdump,
2575 .beacon_on = qla24xx_beacon_on,
2576 .beacon_off = qla24xx_beacon_off,
2577 .beacon_blink = qla83xx_beacon_blink,
2578 .read_optrom = qla25xx_read_optrom_data,
2579 .write_optrom = qla24xx_write_optrom_data,
2580 .get_flash_version = qla24xx_get_flash_version,
2581 .start_scsi = qla24xx_dif_start_scsi,
2582 .start_scsi_mq = qla2xxx_dif_start_scsi_mq,
2583 .abort_isp = qla2x00_abort_isp,
2584 .iospace_config = qla83xx_iospace_config,
2585 .initialize_adapter = qla2x00_initialize_adapter,
2589 qla2x00_set_isp_flags(struct qla_hw_data *ha)
2591 ha->device_type = DT_EXTENDED_IDS;
2592 switch (ha->pdev->device) {
2593 case PCI_DEVICE_ID_QLOGIC_ISP2100:
2594 ha->isp_type |= DT_ISP2100;
2595 ha->device_type &= ~DT_EXTENDED_IDS;
2596 ha->fw_srisc_address = RISC_START_ADDRESS_2100;
2598 case PCI_DEVICE_ID_QLOGIC_ISP2200:
2599 ha->isp_type |= DT_ISP2200;
2600 ha->device_type &= ~DT_EXTENDED_IDS;
2601 ha->fw_srisc_address = RISC_START_ADDRESS_2100;
2603 case PCI_DEVICE_ID_QLOGIC_ISP2300:
2604 ha->isp_type |= DT_ISP2300;
2605 ha->device_type |= DT_ZIO_SUPPORTED;
2606 ha->fw_srisc_address = RISC_START_ADDRESS_2300;
2608 case PCI_DEVICE_ID_QLOGIC_ISP2312:
2609 ha->isp_type |= DT_ISP2312;
2610 ha->device_type |= DT_ZIO_SUPPORTED;
2611 ha->fw_srisc_address = RISC_START_ADDRESS_2300;
2613 case PCI_DEVICE_ID_QLOGIC_ISP2322:
2614 ha->isp_type |= DT_ISP2322;
2615 ha->device_type |= DT_ZIO_SUPPORTED;
2616 if (ha->pdev->subsystem_vendor == 0x1028 &&
2617 ha->pdev->subsystem_device == 0x0170)
2618 ha->device_type |= DT_OEM_001;
2619 ha->fw_srisc_address = RISC_START_ADDRESS_2300;
2621 case PCI_DEVICE_ID_QLOGIC_ISP6312:
2622 ha->isp_type |= DT_ISP6312;
2623 ha->fw_srisc_address = RISC_START_ADDRESS_2300;
2625 case PCI_DEVICE_ID_QLOGIC_ISP6322:
2626 ha->isp_type |= DT_ISP6322;
2627 ha->fw_srisc_address = RISC_START_ADDRESS_2300;
2629 case PCI_DEVICE_ID_QLOGIC_ISP2422:
2630 ha->isp_type |= DT_ISP2422;
2631 ha->device_type |= DT_ZIO_SUPPORTED;
2632 ha->device_type |= DT_FWI2;
2633 ha->device_type |= DT_IIDMA;
2634 ha->fw_srisc_address = RISC_START_ADDRESS_2400;
2636 case PCI_DEVICE_ID_QLOGIC_ISP2432:
2637 ha->isp_type |= DT_ISP2432;
2638 ha->device_type |= DT_ZIO_SUPPORTED;
2639 ha->device_type |= DT_FWI2;
2640 ha->device_type |= DT_IIDMA;
2641 ha->fw_srisc_address = RISC_START_ADDRESS_2400;
2643 case PCI_DEVICE_ID_QLOGIC_ISP8432:
2644 ha->isp_type |= DT_ISP8432;
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_ISP5422:
2651 ha->isp_type |= DT_ISP5422;
2652 ha->device_type |= DT_FWI2;
2653 ha->fw_srisc_address = RISC_START_ADDRESS_2400;
2655 case PCI_DEVICE_ID_QLOGIC_ISP5432:
2656 ha->isp_type |= DT_ISP5432;
2657 ha->device_type |= DT_FWI2;
2658 ha->fw_srisc_address = RISC_START_ADDRESS_2400;
2660 case PCI_DEVICE_ID_QLOGIC_ISP2532:
2661 ha->isp_type |= DT_ISP2532;
2662 ha->device_type |= DT_ZIO_SUPPORTED;
2663 ha->device_type |= DT_FWI2;
2664 ha->device_type |= DT_IIDMA;
2665 ha->fw_srisc_address = RISC_START_ADDRESS_2400;
2667 case PCI_DEVICE_ID_QLOGIC_ISP8001:
2668 ha->isp_type |= DT_ISP8001;
2669 ha->device_type |= DT_ZIO_SUPPORTED;
2670 ha->device_type |= DT_FWI2;
2671 ha->device_type |= DT_IIDMA;
2672 ha->fw_srisc_address = RISC_START_ADDRESS_2400;
2674 case PCI_DEVICE_ID_QLOGIC_ISP8021:
2675 ha->isp_type |= DT_ISP8021;
2676 ha->device_type |= DT_ZIO_SUPPORTED;
2677 ha->device_type |= DT_FWI2;
2678 ha->fw_srisc_address = RISC_START_ADDRESS_2400;
2679 /* Initialize 82XX ISP flags */
2680 qla82xx_init_flags(ha);
2682 case PCI_DEVICE_ID_QLOGIC_ISP8044:
2683 ha->isp_type |= DT_ISP8044;
2684 ha->device_type |= DT_ZIO_SUPPORTED;
2685 ha->device_type |= DT_FWI2;
2686 ha->fw_srisc_address = RISC_START_ADDRESS_2400;
2687 /* Initialize 82XX ISP flags */
2688 qla82xx_init_flags(ha);
2690 case PCI_DEVICE_ID_QLOGIC_ISP2031:
2691 ha->isp_type |= DT_ISP2031;
2692 ha->device_type |= DT_ZIO_SUPPORTED;
2693 ha->device_type |= DT_FWI2;
2694 ha->device_type |= DT_IIDMA;
2695 ha->device_type |= DT_T10_PI;
2696 ha->fw_srisc_address = RISC_START_ADDRESS_2400;
2698 case PCI_DEVICE_ID_QLOGIC_ISP8031:
2699 ha->isp_type |= DT_ISP8031;
2700 ha->device_type |= DT_ZIO_SUPPORTED;
2701 ha->device_type |= DT_FWI2;
2702 ha->device_type |= DT_IIDMA;
2703 ha->device_type |= DT_T10_PI;
2704 ha->fw_srisc_address = RISC_START_ADDRESS_2400;
2706 case PCI_DEVICE_ID_QLOGIC_ISPF001:
2707 ha->isp_type |= DT_ISPFX00;
2709 case PCI_DEVICE_ID_QLOGIC_ISP2071:
2710 ha->isp_type |= DT_ISP2071;
2711 ha->device_type |= DT_ZIO_SUPPORTED;
2712 ha->device_type |= DT_FWI2;
2713 ha->device_type |= DT_IIDMA;
2714 ha->device_type |= DT_T10_PI;
2715 ha->fw_srisc_address = RISC_START_ADDRESS_2400;
2717 case PCI_DEVICE_ID_QLOGIC_ISP2271:
2718 ha->isp_type |= DT_ISP2271;
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_ISP2261:
2726 ha->isp_type |= DT_ISP2261;
2727 ha->device_type |= DT_ZIO_SUPPORTED;
2728 ha->device_type |= DT_FWI2;
2729 ha->device_type |= DT_IIDMA;
2730 ha->device_type |= DT_T10_PI;
2731 ha->fw_srisc_address = RISC_START_ADDRESS_2400;
2733 case PCI_DEVICE_ID_QLOGIC_ISP2081:
2734 case PCI_DEVICE_ID_QLOGIC_ISP2089:
2735 ha->isp_type |= DT_ISP2081;
2736 ha->device_type |= DT_ZIO_SUPPORTED;
2737 ha->device_type |= DT_FWI2;
2738 ha->device_type |= DT_IIDMA;
2739 ha->device_type |= DT_T10_PI;
2740 ha->fw_srisc_address = RISC_START_ADDRESS_2400;
2742 case PCI_DEVICE_ID_QLOGIC_ISP2281:
2743 case PCI_DEVICE_ID_QLOGIC_ISP2289:
2744 ha->isp_type |= DT_ISP2281;
2745 ha->device_type |= DT_ZIO_SUPPORTED;
2746 ha->device_type |= DT_FWI2;
2747 ha->device_type |= DT_IIDMA;
2748 ha->device_type |= DT_T10_PI;
2749 ha->fw_srisc_address = RISC_START_ADDRESS_2400;
2754 ha->port_no = ha->portnum & 1;
2756 /* Get adapter physical port no from interrupt pin register. */
2757 pci_read_config_byte(ha->pdev, PCI_INTERRUPT_PIN, &ha->port_no);
2758 if (IS_QLA25XX(ha) || IS_QLA2031(ha) ||
2759 IS_QLA27XX(ha) || IS_QLA28XX(ha))
2762 ha->port_no = !(ha->port_no & 1);
2765 ql_dbg_pci(ql_dbg_init, ha->pdev, 0x000b,
2766 "device_type=0x%x port=%d fw_srisc_address=0x%x.\n",
2767 ha->device_type, ha->port_no, ha->fw_srisc_address);
2771 qla2xxx_scan_start(struct Scsi_Host *shost)
2773 scsi_qla_host_t *vha = shost_priv(shost);
2775 if (vha->hw->flags.running_gold_fw)
2778 set_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags);
2779 set_bit(LOCAL_LOOP_UPDATE, &vha->dpc_flags);
2780 set_bit(RSCN_UPDATE, &vha->dpc_flags);
2781 set_bit(NPIV_CONFIG_NEEDED, &vha->dpc_flags);
2785 qla2xxx_scan_finished(struct Scsi_Host *shost, unsigned long time)
2787 scsi_qla_host_t *vha = shost_priv(shost);
2789 if (test_bit(UNLOADING, &vha->dpc_flags))
2793 if (time > vha->hw->loop_reset_delay * HZ)
2796 return atomic_read(&vha->loop_state) == LOOP_READY;
2799 static void qla_heartbeat_work_fn(struct work_struct *work)
2801 struct qla_hw_data *ha = container_of(work,
2802 struct qla_hw_data, heartbeat_work);
2803 struct scsi_qla_host *base_vha = pci_get_drvdata(ha->pdev);
2805 if (!ha->flags.mbox_busy && base_vha->flags.init_done)
2806 qla_no_op_mb(base_vha);
2809 static void qla2x00_iocb_work_fn(struct work_struct *work)
2811 struct scsi_qla_host *vha = container_of(work,
2812 struct scsi_qla_host, iocb_work);
2813 struct qla_hw_data *ha = vha->hw;
2814 struct scsi_qla_host *base_vha = pci_get_drvdata(ha->pdev);
2816 unsigned long flags;
2818 if (test_bit(UNLOADING, &base_vha->dpc_flags))
2821 while (!list_empty(&vha->work_list) && i > 0) {
2822 qla2x00_do_work(vha);
2826 spin_lock_irqsave(&vha->work_lock, flags);
2827 clear_bit(IOCB_WORK_ACTIVE, &vha->dpc_flags);
2828 spin_unlock_irqrestore(&vha->work_lock, flags);
2832 * PCI driver interface
2835 qla2x00_probe_one(struct pci_dev *pdev, const struct pci_device_id *id)
2838 struct Scsi_Host *host;
2839 scsi_qla_host_t *base_vha = NULL;
2840 struct qla_hw_data *ha;
2842 char fw_str[30], wq_name[30];
2843 struct scsi_host_template *sht;
2844 int bars, mem_only = 0;
2845 uint16_t req_length = 0, rsp_length = 0;
2846 struct req_que *req = NULL;
2847 struct rsp_que *rsp = NULL;
2850 bars = pci_select_bars(pdev, IORESOURCE_MEM | IORESOURCE_IO);
2851 sht = &qla2xxx_driver_template;
2852 if (pdev->device == PCI_DEVICE_ID_QLOGIC_ISP2422 ||
2853 pdev->device == PCI_DEVICE_ID_QLOGIC_ISP2432 ||
2854 pdev->device == PCI_DEVICE_ID_QLOGIC_ISP8432 ||
2855 pdev->device == PCI_DEVICE_ID_QLOGIC_ISP5422 ||
2856 pdev->device == PCI_DEVICE_ID_QLOGIC_ISP5432 ||
2857 pdev->device == PCI_DEVICE_ID_QLOGIC_ISP2532 ||
2858 pdev->device == PCI_DEVICE_ID_QLOGIC_ISP8001 ||
2859 pdev->device == PCI_DEVICE_ID_QLOGIC_ISP8021 ||
2860 pdev->device == PCI_DEVICE_ID_QLOGIC_ISP2031 ||
2861 pdev->device == PCI_DEVICE_ID_QLOGIC_ISP8031 ||
2862 pdev->device == PCI_DEVICE_ID_QLOGIC_ISPF001 ||
2863 pdev->device == PCI_DEVICE_ID_QLOGIC_ISP8044 ||
2864 pdev->device == PCI_DEVICE_ID_QLOGIC_ISP2071 ||
2865 pdev->device == PCI_DEVICE_ID_QLOGIC_ISP2271 ||
2866 pdev->device == PCI_DEVICE_ID_QLOGIC_ISP2261 ||
2867 pdev->device == PCI_DEVICE_ID_QLOGIC_ISP2081 ||
2868 pdev->device == PCI_DEVICE_ID_QLOGIC_ISP2281 ||
2869 pdev->device == PCI_DEVICE_ID_QLOGIC_ISP2089 ||
2870 pdev->device == PCI_DEVICE_ID_QLOGIC_ISP2289) {
2871 bars = pci_select_bars(pdev, IORESOURCE_MEM);
2873 ql_dbg_pci(ql_dbg_init, pdev, 0x0007,
2874 "Mem only adapter.\n");
2876 ql_dbg_pci(ql_dbg_init, pdev, 0x0008,
2877 "Bars=%d.\n", bars);
2880 if (pci_enable_device_mem(pdev))
2883 if (pci_enable_device(pdev))
2887 if (is_kdump_kernel()) {
2889 ql2xallocfwdump = 0;
2892 /* This may fail but that's ok */
2893 pci_enable_pcie_error_reporting(pdev);
2895 ha = kzalloc(sizeof(struct qla_hw_data), GFP_KERNEL);
2897 ql_log_pci(ql_log_fatal, pdev, 0x0009,
2898 "Unable to allocate memory for ha.\n");
2899 goto disable_device;
2901 ql_dbg_pci(ql_dbg_init, pdev, 0x000a,
2902 "Memory allocated for ha=%p.\n", ha);
2904 INIT_LIST_HEAD(&ha->tgt.q_full_list);
2905 spin_lock_init(&ha->tgt.q_full_lock);
2906 spin_lock_init(&ha->tgt.sess_lock);
2907 spin_lock_init(&ha->tgt.atio_lock);
2909 spin_lock_init(&ha->sadb_lock);
2910 INIT_LIST_HEAD(&ha->sadb_tx_index_list);
2911 INIT_LIST_HEAD(&ha->sadb_rx_index_list);
2913 spin_lock_init(&ha->sadb_fp_lock);
2915 if (qla_edif_sadb_build_free_pool(ha)) {
2917 goto disable_device;
2920 atomic_set(&ha->nvme_active_aen_cnt, 0);
2922 /* Clear our data area */
2924 ha->mem_only = mem_only;
2925 spin_lock_init(&ha->hardware_lock);
2926 spin_lock_init(&ha->vport_slock);
2927 mutex_init(&ha->selflogin_lock);
2928 mutex_init(&ha->optrom_mutex);
2930 /* Set ISP-type information. */
2931 qla2x00_set_isp_flags(ha);
2933 /* Set EEH reset type to fundamental if required by hba */
2934 if (IS_QLA24XX(ha) || IS_QLA25XX(ha) || IS_QLA81XX(ha) ||
2935 IS_QLA83XX(ha) || IS_QLA27XX(ha) || IS_QLA28XX(ha))
2936 pdev->needs_freset = 1;
2938 ha->prev_topology = 0;
2939 ha->init_cb_size = sizeof(init_cb_t);
2940 ha->link_data_rate = PORT_SPEED_UNKNOWN;
2941 ha->optrom_size = OPTROM_SIZE_2300;
2942 ha->max_exchg = FW_MAX_EXCHANGES_CNT;
2943 atomic_set(&ha->num_pend_mbx_stage1, 0);
2944 atomic_set(&ha->num_pend_mbx_stage2, 0);
2945 atomic_set(&ha->num_pend_mbx_stage3, 0);
2946 atomic_set(&ha->zio_threshold, DEFAULT_ZIO_THRESHOLD);
2947 ha->last_zio_threshold = DEFAULT_ZIO_THRESHOLD;
2949 /* Assign ISP specific operations. */
2950 if (IS_QLA2100(ha)) {
2951 ha->max_fibre_devices = MAX_FIBRE_DEVICES_2100;
2952 ha->mbx_count = MAILBOX_REGISTER_COUNT_2100;
2953 req_length = REQUEST_ENTRY_CNT_2100;
2954 rsp_length = RESPONSE_ENTRY_CNT_2100;
2955 ha->max_loop_id = SNS_LAST_LOOP_ID_2100;
2956 ha->gid_list_info_size = 4;
2957 ha->flash_conf_off = ~0;
2958 ha->flash_data_off = ~0;
2959 ha->nvram_conf_off = ~0;
2960 ha->nvram_data_off = ~0;
2961 ha->isp_ops = &qla2100_isp_ops;
2962 } else if (IS_QLA2200(ha)) {
2963 ha->max_fibre_devices = MAX_FIBRE_DEVICES_2100;
2964 ha->mbx_count = MAILBOX_REGISTER_COUNT_2200;
2965 req_length = REQUEST_ENTRY_CNT_2200;
2966 rsp_length = RESPONSE_ENTRY_CNT_2100;
2967 ha->max_loop_id = SNS_LAST_LOOP_ID_2100;
2968 ha->gid_list_info_size = 4;
2969 ha->flash_conf_off = ~0;
2970 ha->flash_data_off = ~0;
2971 ha->nvram_conf_off = ~0;
2972 ha->nvram_data_off = ~0;
2973 ha->isp_ops = &qla2100_isp_ops;
2974 } else if (IS_QLA23XX(ha)) {
2975 ha->max_fibre_devices = MAX_FIBRE_DEVICES_2100;
2976 ha->mbx_count = MAILBOX_REGISTER_COUNT;
2977 req_length = REQUEST_ENTRY_CNT_2200;
2978 rsp_length = RESPONSE_ENTRY_CNT_2300;
2979 ha->max_loop_id = SNS_LAST_LOOP_ID_2300;
2980 ha->gid_list_info_size = 6;
2981 if (IS_QLA2322(ha) || IS_QLA6322(ha))
2982 ha->optrom_size = OPTROM_SIZE_2322;
2983 ha->flash_conf_off = ~0;
2984 ha->flash_data_off = ~0;
2985 ha->nvram_conf_off = ~0;
2986 ha->nvram_data_off = ~0;
2987 ha->isp_ops = &qla2300_isp_ops;
2988 } else if (IS_QLA24XX_TYPE(ha)) {
2989 ha->max_fibre_devices = MAX_FIBRE_DEVICES_2400;
2990 ha->mbx_count = MAILBOX_REGISTER_COUNT;
2991 req_length = REQUEST_ENTRY_CNT_24XX;
2992 rsp_length = RESPONSE_ENTRY_CNT_2300;
2993 ha->tgt.atio_q_length = ATIO_ENTRY_CNT_24XX;
2994 ha->max_loop_id = SNS_LAST_LOOP_ID_2300;
2995 ha->init_cb_size = sizeof(struct mid_init_cb_24xx);
2996 ha->gid_list_info_size = 8;
2997 ha->optrom_size = OPTROM_SIZE_24XX;
2998 ha->nvram_npiv_size = QLA_MAX_VPORTS_QLA24XX;
2999 ha->isp_ops = &qla24xx_isp_ops;
3000 ha->flash_conf_off = FARX_ACCESS_FLASH_CONF;
3001 ha->flash_data_off = FARX_ACCESS_FLASH_DATA;
3002 ha->nvram_conf_off = FARX_ACCESS_NVRAM_CONF;
3003 ha->nvram_data_off = FARX_ACCESS_NVRAM_DATA;
3004 } else if (IS_QLA25XX(ha)) {
3005 ha->max_fibre_devices = MAX_FIBRE_DEVICES_2400;
3006 ha->mbx_count = MAILBOX_REGISTER_COUNT;
3007 req_length = REQUEST_ENTRY_CNT_24XX;
3008 rsp_length = RESPONSE_ENTRY_CNT_2300;
3009 ha->tgt.atio_q_length = ATIO_ENTRY_CNT_24XX;
3010 ha->max_loop_id = SNS_LAST_LOOP_ID_2300;
3011 ha->init_cb_size = sizeof(struct mid_init_cb_24xx);
3012 ha->gid_list_info_size = 8;
3013 ha->optrom_size = OPTROM_SIZE_25XX;
3014 ha->nvram_npiv_size = QLA_MAX_VPORTS_QLA25XX;
3015 ha->isp_ops = &qla25xx_isp_ops;
3016 ha->flash_conf_off = FARX_ACCESS_FLASH_CONF;
3017 ha->flash_data_off = FARX_ACCESS_FLASH_DATA;
3018 ha->nvram_conf_off = FARX_ACCESS_NVRAM_CONF;
3019 ha->nvram_data_off = FARX_ACCESS_NVRAM_DATA;
3020 } else if (IS_QLA81XX(ha)) {
3021 ha->max_fibre_devices = MAX_FIBRE_DEVICES_2400;
3022 ha->mbx_count = MAILBOX_REGISTER_COUNT;
3023 req_length = REQUEST_ENTRY_CNT_24XX;
3024 rsp_length = RESPONSE_ENTRY_CNT_2300;
3025 ha->tgt.atio_q_length = ATIO_ENTRY_CNT_24XX;
3026 ha->max_loop_id = SNS_LAST_LOOP_ID_2300;
3027 ha->init_cb_size = sizeof(struct mid_init_cb_81xx);
3028 ha->gid_list_info_size = 8;
3029 ha->optrom_size = OPTROM_SIZE_81XX;
3030 ha->nvram_npiv_size = QLA_MAX_VPORTS_QLA25XX;
3031 ha->isp_ops = &qla81xx_isp_ops;
3032 ha->flash_conf_off = FARX_ACCESS_FLASH_CONF_81XX;
3033 ha->flash_data_off = FARX_ACCESS_FLASH_DATA_81XX;
3034 ha->nvram_conf_off = ~0;
3035 ha->nvram_data_off = ~0;
3036 } else if (IS_QLA82XX(ha)) {
3037 ha->max_fibre_devices = MAX_FIBRE_DEVICES_2400;
3038 ha->mbx_count = MAILBOX_REGISTER_COUNT;
3039 req_length = REQUEST_ENTRY_CNT_82XX;
3040 rsp_length = RESPONSE_ENTRY_CNT_82XX;
3041 ha->max_loop_id = SNS_LAST_LOOP_ID_2300;
3042 ha->init_cb_size = sizeof(struct mid_init_cb_81xx);
3043 ha->gid_list_info_size = 8;
3044 ha->optrom_size = OPTROM_SIZE_82XX;
3045 ha->nvram_npiv_size = QLA_MAX_VPORTS_QLA25XX;
3046 ha->isp_ops = &qla82xx_isp_ops;
3047 ha->flash_conf_off = FARX_ACCESS_FLASH_CONF;
3048 ha->flash_data_off = FARX_ACCESS_FLASH_DATA;
3049 ha->nvram_conf_off = FARX_ACCESS_NVRAM_CONF;
3050 ha->nvram_data_off = FARX_ACCESS_NVRAM_DATA;
3051 } else if (IS_QLA8044(ha)) {
3052 ha->max_fibre_devices = MAX_FIBRE_DEVICES_2400;
3053 ha->mbx_count = MAILBOX_REGISTER_COUNT;
3054 req_length = REQUEST_ENTRY_CNT_82XX;
3055 rsp_length = RESPONSE_ENTRY_CNT_82XX;
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 = &qla8044_isp_ops;
3062 ha->flash_conf_off = FARX_ACCESS_FLASH_CONF;
3063 ha->flash_data_off = FARX_ACCESS_FLASH_DATA;
3064 ha->nvram_conf_off = FARX_ACCESS_NVRAM_CONF;
3065 ha->nvram_data_off = FARX_ACCESS_NVRAM_DATA;
3066 } else if (IS_QLA83XX(ha)) {
3067 ha->portnum = PCI_FUNC(ha->pdev->devfn);
3068 ha->max_fibre_devices = MAX_FIBRE_DEVICES_2400;
3069 ha->mbx_count = MAILBOX_REGISTER_COUNT;
3070 req_length = REQUEST_ENTRY_CNT_83XX;
3071 rsp_length = RESPONSE_ENTRY_CNT_83XX;
3072 ha->tgt.atio_q_length = ATIO_ENTRY_CNT_24XX;
3073 ha->max_loop_id = SNS_LAST_LOOP_ID_2300;
3074 ha->init_cb_size = sizeof(struct mid_init_cb_81xx);
3075 ha->gid_list_info_size = 8;
3076 ha->optrom_size = OPTROM_SIZE_83XX;
3077 ha->nvram_npiv_size = QLA_MAX_VPORTS_QLA25XX;
3078 ha->isp_ops = &qla83xx_isp_ops;
3079 ha->flash_conf_off = FARX_ACCESS_FLASH_CONF_81XX;
3080 ha->flash_data_off = FARX_ACCESS_FLASH_DATA_81XX;
3081 ha->nvram_conf_off = ~0;
3082 ha->nvram_data_off = ~0;
3083 } else if (IS_QLAFX00(ha)) {
3084 ha->max_fibre_devices = MAX_FIBRE_DEVICES_FX00;
3085 ha->mbx_count = MAILBOX_REGISTER_COUNT_FX00;
3086 ha->aen_mbx_count = AEN_MAILBOX_REGISTER_COUNT_FX00;
3087 req_length = REQUEST_ENTRY_CNT_FX00;
3088 rsp_length = RESPONSE_ENTRY_CNT_FX00;
3089 ha->isp_ops = &qlafx00_isp_ops;
3090 ha->port_down_retry_count = 30; /* default value */
3091 ha->mr.fw_hbt_cnt = QLAFX00_HEARTBEAT_INTERVAL;
3092 ha->mr.fw_reset_timer_tick = QLAFX00_RESET_INTERVAL;
3093 ha->mr.fw_critemp_timer_tick = QLAFX00_CRITEMP_INTERVAL;
3094 ha->mr.fw_hbt_en = 1;
3095 ha->mr.host_info_resend = false;
3096 ha->mr.hinfo_resend_timer_tick = QLAFX00_HINFO_RESEND_INTERVAL;
3097 } else if (IS_QLA27XX(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_83XX;
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_81XX;
3111 ha->flash_data_off = FARX_ACCESS_FLASH_DATA_81XX;
3112 ha->nvram_conf_off = ~0;
3113 ha->nvram_data_off = ~0;
3114 } else if (IS_QLA28XX(ha)) {
3115 ha->portnum = PCI_FUNC(ha->pdev->devfn);
3116 ha->max_fibre_devices = MAX_FIBRE_DEVICES_2400;
3117 ha->mbx_count = MAILBOX_REGISTER_COUNT;
3118 req_length = REQUEST_ENTRY_CNT_83XX;
3119 rsp_length = RESPONSE_ENTRY_CNT_83XX;
3120 ha->tgt.atio_q_length = ATIO_ENTRY_CNT_24XX;
3121 ha->max_loop_id = SNS_LAST_LOOP_ID_2300;
3122 ha->init_cb_size = sizeof(struct mid_init_cb_81xx);
3123 ha->gid_list_info_size = 8;
3124 ha->optrom_size = OPTROM_SIZE_28XX;
3125 ha->nvram_npiv_size = QLA_MAX_VPORTS_QLA25XX;
3126 ha->isp_ops = &qla27xx_isp_ops;
3127 ha->flash_conf_off = FARX_ACCESS_FLASH_CONF_28XX;
3128 ha->flash_data_off = FARX_ACCESS_FLASH_DATA_28XX;
3129 ha->nvram_conf_off = ~0;
3130 ha->nvram_data_off = ~0;
3133 ql_dbg_pci(ql_dbg_init, pdev, 0x001e,
3134 "mbx_count=%d, req_length=%d, "
3135 "rsp_length=%d, max_loop_id=%d, init_cb_size=%d, "
3136 "gid_list_info_size=%d, optrom_size=%d, nvram_npiv_size=%d, "
3137 "max_fibre_devices=%d.\n",
3138 ha->mbx_count, req_length, rsp_length, ha->max_loop_id,
3139 ha->init_cb_size, ha->gid_list_info_size, ha->optrom_size,
3140 ha->nvram_npiv_size, ha->max_fibre_devices);
3141 ql_dbg_pci(ql_dbg_init, pdev, 0x001f,
3142 "isp_ops=%p, flash_conf_off=%d, "
3143 "flash_data_off=%d, nvram_conf_off=%d, nvram_data_off=%d.\n",
3144 ha->isp_ops, ha->flash_conf_off, ha->flash_data_off,
3145 ha->nvram_conf_off, ha->nvram_data_off);
3147 /* Configure PCI I/O space */
3148 ret = ha->isp_ops->iospace_config(ha);
3150 goto iospace_config_failed;
3152 ql_log_pci(ql_log_info, pdev, 0x001d,
3153 "Found an ISP%04X irq %d iobase 0x%p.\n",
3154 pdev->device, pdev->irq, ha->iobase);
3155 mutex_init(&ha->vport_lock);
3156 mutex_init(&ha->mq_lock);
3157 init_completion(&ha->mbx_cmd_comp);
3158 complete(&ha->mbx_cmd_comp);
3159 init_completion(&ha->mbx_intr_comp);
3160 init_completion(&ha->dcbx_comp);
3161 init_completion(&ha->lb_portup_comp);
3163 set_bit(0, (unsigned long *) ha->vp_idx_map);
3165 qla2x00_config_dma_addressing(ha);
3166 ql_dbg_pci(ql_dbg_init, pdev, 0x0020,
3167 "64 Bit addressing is %s.\n",
3168 ha->flags.enable_64bit_addressing ? "enable" :
3170 ret = qla2x00_mem_alloc(ha, req_length, rsp_length, &req, &rsp);
3172 ql_log_pci(ql_log_fatal, pdev, 0x0031,
3173 "Failed to allocate memory for adapter, aborting.\n");
3175 goto probe_hw_failed;
3178 req->max_q_depth = MAX_Q_DEPTH;
3179 if (ql2xmaxqdepth != 0 && ql2xmaxqdepth <= 0xffffU)
3180 req->max_q_depth = ql2xmaxqdepth;
3183 base_vha = qla2x00_create_host(sht, ha);
3186 goto probe_hw_failed;
3189 pci_set_drvdata(pdev, base_vha);
3190 set_bit(PFLG_DRIVER_PROBING, &base_vha->pci_flags);
3192 host = base_vha->host;
3193 base_vha->req = req;
3194 if (IS_QLA2XXX_MIDTYPE(ha))
3195 base_vha->mgmt_svr_loop_id =
3196 qla2x00_reserve_mgmt_server_loop_id(base_vha);
3198 base_vha->mgmt_svr_loop_id = MANAGEMENT_SERVER +
3201 /* Setup fcport template structure. */
3202 ha->mr.fcport.vha = base_vha;
3203 ha->mr.fcport.port_type = FCT_UNKNOWN;
3204 ha->mr.fcport.loop_id = FC_NO_LOOP_ID;
3205 qla2x00_set_fcport_state(&ha->mr.fcport, FCS_UNCONFIGURED);
3206 ha->mr.fcport.supported_classes = FC_COS_UNSPECIFIED;
3207 ha->mr.fcport.scan_state = 1;
3209 qla2xxx_reset_stats(host, QLA2XX_HW_ERROR | QLA2XX_SHT_LNK_DWN |
3210 QLA2XX_INT_ERR | QLA2XX_CMD_TIMEOUT |
3211 QLA2XX_RESET_CMD_ERR | QLA2XX_TGT_SHT_LNK_DOWN);
3213 /* Set the SG table size based on ISP type */
3214 if (!IS_FWI2_CAPABLE(ha)) {
3216 host->sg_tablesize = 32;
3218 if (!IS_QLA82XX(ha))
3219 host->sg_tablesize = QLA_SG_ALL;
3221 host->max_id = ha->max_fibre_devices;
3222 host->cmd_per_lun = 3;
3223 host->unique_id = host->host_no;
3224 if (IS_T10_PI_CAPABLE(ha) && ql2xenabledif)
3225 host->max_cmd_len = 32;
3227 host->max_cmd_len = MAX_CMDSZ;
3228 host->max_channel = MAX_BUSES - 1;
3229 /* Older HBAs support only 16-bit LUNs */
3230 if (!IS_QLAFX00(ha) && !IS_FWI2_CAPABLE(ha) &&
3231 ql2xmaxlun > 0xffff)
3232 host->max_lun = 0xffff;
3234 host->max_lun = ql2xmaxlun;
3235 host->transportt = qla2xxx_transport_template;
3236 sht->vendor_id = (SCSI_NL_VID_TYPE_PCI | PCI_VENDOR_ID_QLOGIC);
3238 ql_dbg(ql_dbg_init, base_vha, 0x0033,
3239 "max_id=%d this_id=%d "
3240 "cmd_per_len=%d unique_id=%d max_cmd_len=%d max_channel=%d "
3241 "max_lun=%llu transportt=%p, vendor_id=%llu.\n", host->max_id,
3242 host->this_id, host->cmd_per_lun, host->unique_id,
3243 host->max_cmd_len, host->max_channel, host->max_lun,
3244 host->transportt, sht->vendor_id);
3246 INIT_WORK(&base_vha->iocb_work, qla2x00_iocb_work_fn);
3247 INIT_WORK(&ha->heartbeat_work, qla_heartbeat_work_fn);
3249 /* Set up the irqs */
3250 ret = qla2x00_request_irqs(ha, rsp);
3254 /* Alloc arrays of request and response ring ptrs */
3255 ret = qla2x00_alloc_queues(ha, req, rsp);
3257 ql_log(ql_log_fatal, base_vha, 0x003d,
3258 "Failed to allocate memory for queue pointers..."
3265 /* number of hardware queues supported by blk/scsi-mq*/
3266 host->nr_hw_queues = ha->max_qpairs;
3268 ql_dbg(ql_dbg_init, base_vha, 0x0192,
3269 "blk/scsi-mq enabled, HW queues = %d.\n", host->nr_hw_queues);
3271 if (ql2xnvmeenable) {
3272 host->nr_hw_queues = ha->max_qpairs;
3273 ql_dbg(ql_dbg_init, base_vha, 0x0194,
3274 "FC-NVMe support is enabled, HW queues=%d\n",
3275 host->nr_hw_queues);
3277 ql_dbg(ql_dbg_init, base_vha, 0x0193,
3278 "blk/scsi-mq disabled.\n");
3282 qlt_probe_one_stage1(base_vha, ha);
3284 pci_save_state(pdev);
3286 /* Assign back pointers */
3290 if (IS_QLAFX00(ha)) {
3291 ha->rsp_q_map[0] = rsp;
3292 ha->req_q_map[0] = req;
3293 set_bit(0, ha->req_qid_map);
3294 set_bit(0, ha->rsp_qid_map);
3297 /* FWI2-capable only. */
3298 req->req_q_in = &ha->iobase->isp24.req_q_in;
3299 req->req_q_out = &ha->iobase->isp24.req_q_out;
3300 rsp->rsp_q_in = &ha->iobase->isp24.rsp_q_in;
3301 rsp->rsp_q_out = &ha->iobase->isp24.rsp_q_out;
3302 if (ha->mqenable || IS_QLA83XX(ha) || IS_QLA27XX(ha) ||
3304 req->req_q_in = &ha->mqiobase->isp25mq.req_q_in;
3305 req->req_q_out = &ha->mqiobase->isp25mq.req_q_out;
3306 rsp->rsp_q_in = &ha->mqiobase->isp25mq.rsp_q_in;
3307 rsp->rsp_q_out = &ha->mqiobase->isp25mq.rsp_q_out;
3310 if (IS_QLAFX00(ha)) {
3311 req->req_q_in = &ha->iobase->ispfx00.req_q_in;
3312 req->req_q_out = &ha->iobase->ispfx00.req_q_out;
3313 rsp->rsp_q_in = &ha->iobase->ispfx00.rsp_q_in;
3314 rsp->rsp_q_out = &ha->iobase->ispfx00.rsp_q_out;
3317 if (IS_P3P_TYPE(ha)) {
3318 req->req_q_out = &ha->iobase->isp82.req_q_out[0];
3319 rsp->rsp_q_in = &ha->iobase->isp82.rsp_q_in[0];
3320 rsp->rsp_q_out = &ha->iobase->isp82.rsp_q_out[0];
3323 ql_dbg(ql_dbg_multiq, base_vha, 0xc009,
3324 "rsp_q_map=%p req_q_map=%p rsp->req=%p req->rsp=%p.\n",
3325 ha->rsp_q_map, ha->req_q_map, rsp->req, req->rsp);
3326 ql_dbg(ql_dbg_multiq, base_vha, 0xc00a,
3327 "req->req_q_in=%p req->req_q_out=%p "
3328 "rsp->rsp_q_in=%p rsp->rsp_q_out=%p.\n",
3329 req->req_q_in, req->req_q_out,
3330 rsp->rsp_q_in, rsp->rsp_q_out);
3331 ql_dbg(ql_dbg_init, base_vha, 0x003e,
3332 "rsp_q_map=%p req_q_map=%p rsp->req=%p req->rsp=%p.\n",
3333 ha->rsp_q_map, ha->req_q_map, rsp->req, req->rsp);
3334 ql_dbg(ql_dbg_init, base_vha, 0x003f,
3335 "req->req_q_in=%p req->req_q_out=%p rsp->rsp_q_in=%p rsp->rsp_q_out=%p.\n",
3336 req->req_q_in, req->req_q_out, rsp->rsp_q_in, rsp->rsp_q_out);
3338 ha->wq = alloc_workqueue("qla2xxx_wq", WQ_MEM_RECLAIM, 0);
3339 if (unlikely(!ha->wq)) {
3344 if (ha->isp_ops->initialize_adapter(base_vha)) {
3345 ql_log(ql_log_fatal, base_vha, 0x00d6,
3346 "Failed to initialize adapter - Adapter flags %x.\n",
3347 base_vha->device_flags);
3349 if (IS_QLA82XX(ha)) {
3350 qla82xx_idc_lock(ha);
3351 qla82xx_wr_32(ha, QLA82XX_CRB_DEV_STATE,
3352 QLA8XXX_DEV_FAILED);
3353 qla82xx_idc_unlock(ha);
3354 ql_log(ql_log_fatal, base_vha, 0x00d7,
3355 "HW State: FAILED.\n");
3356 } else if (IS_QLA8044(ha)) {
3357 qla8044_idc_lock(ha);
3358 qla8044_wr_direct(base_vha,
3359 QLA8044_CRB_DEV_STATE_INDEX,
3360 QLA8XXX_DEV_FAILED);
3361 qla8044_idc_unlock(ha);
3362 ql_log(ql_log_fatal, base_vha, 0x0150,
3363 "HW State: FAILED.\n");
3371 host->can_queue = QLAFX00_MAX_CANQUEUE;
3373 host->can_queue = req->num_outstanding_cmds - 10;
3375 ql_dbg(ql_dbg_init, base_vha, 0x0032,
3376 "can_queue=%d, req=%p, mgmt_svr_loop_id=%d, sg_tablesize=%d.\n",
3377 host->can_queue, base_vha->req,
3378 base_vha->mgmt_svr_loop_id, host->sg_tablesize);
3380 /* Check if FW supports MQ or not for ISP25xx */
3381 if (IS_QLA25XX(ha) && !(ha->fw_attributes & BIT_6))
3385 bool startit = false;
3387 if (QLA_TGT_MODE_ENABLED())
3390 if (ql2x_ini_mode == QLA2XXX_INI_MODE_ENABLED)
3393 /* Create start of day qpairs for Block MQ */
3394 for (i = 0; i < ha->max_qpairs; i++)
3395 qla2xxx_create_qpair(base_vha, 5, 0, startit);
3397 qla_init_iocb_limit(base_vha);
3399 if (ha->flags.running_gold_fw)
3403 * Startup the kernel thread for this host adapter
3405 ha->dpc_thread = kthread_create(qla2x00_do_dpc, ha,
3406 "%s_dpc", base_vha->host_str);
3407 if (IS_ERR(ha->dpc_thread)) {
3408 ql_log(ql_log_fatal, base_vha, 0x00ed,
3409 "Failed to start DPC thread.\n");
3410 ret = PTR_ERR(ha->dpc_thread);
3411 ha->dpc_thread = NULL;
3414 ql_dbg(ql_dbg_init, base_vha, 0x00ee,
3415 "DPC thread started successfully.\n");
3418 * If we're not coming up in initiator mode, we might sit for
3419 * a while without waking up the dpc thread, which leads to a
3420 * stuck process warning. So just kick the dpc once here and
3421 * let the kthread start (and go back to sleep in qla2x00_do_dpc).
3423 qla2xxx_wake_dpc(base_vha);
3425 INIT_WORK(&ha->board_disable, qla2x00_disable_board_on_pci_error);
3427 if (IS_QLA8031(ha) || IS_MCTP_CAPABLE(ha)) {
3428 sprintf(wq_name, "qla2xxx_%lu_dpc_lp_wq", base_vha->host_no);
3429 ha->dpc_lp_wq = create_singlethread_workqueue(wq_name);
3430 INIT_WORK(&ha->idc_aen, qla83xx_service_idc_aen);
3432 sprintf(wq_name, "qla2xxx_%lu_dpc_hp_wq", base_vha->host_no);
3433 ha->dpc_hp_wq = create_singlethread_workqueue(wq_name);
3434 INIT_WORK(&ha->nic_core_reset, qla83xx_nic_core_reset_work);
3435 INIT_WORK(&ha->idc_state_handler,
3436 qla83xx_idc_state_handler_work);
3437 INIT_WORK(&ha->nic_core_unrecoverable,
3438 qla83xx_nic_core_unrecoverable_work);
3442 list_add_tail(&base_vha->list, &ha->vp_list);
3443 base_vha->host->irq = ha->pdev->irq;
3445 /* Initialized the timer */
3446 qla2x00_start_timer(base_vha, WATCH_INTERVAL);
3447 ql_dbg(ql_dbg_init, base_vha, 0x00ef,
3448 "Started qla2x00_timer with "
3449 "interval=%d.\n", WATCH_INTERVAL);
3450 ql_dbg(ql_dbg_init, base_vha, 0x00f0,
3451 "Detected hba at address=%p.\n",
3454 if (IS_T10_PI_CAPABLE(ha) && ql2xenabledif) {
3455 if (ha->fw_attributes & BIT_4) {
3456 int prot = 0, guard;
3458 base_vha->flags.difdix_supported = 1;
3459 ql_dbg(ql_dbg_init, base_vha, 0x00f1,
3460 "Registering for DIF/DIX type 1 and 3 protection.\n");
3461 if (ql2xenabledif == 1)
3462 prot = SHOST_DIX_TYPE0_PROTECTION;
3464 scsi_host_set_prot(host, ql2xprotmask);
3466 scsi_host_set_prot(host,
3467 prot | SHOST_DIF_TYPE1_PROTECTION
3468 | SHOST_DIF_TYPE2_PROTECTION
3469 | SHOST_DIF_TYPE3_PROTECTION
3470 | SHOST_DIX_TYPE1_PROTECTION
3471 | SHOST_DIX_TYPE2_PROTECTION
3472 | SHOST_DIX_TYPE3_PROTECTION);
3474 guard = SHOST_DIX_GUARD_CRC;
3476 if (IS_PI_IPGUARD_CAPABLE(ha) &&
3477 (ql2xenabledif > 1 || IS_PI_DIFB_DIX0_CAPABLE(ha)))
3478 guard |= SHOST_DIX_GUARD_IP;
3481 scsi_host_set_guard(host, ql2xprotguard);
3483 scsi_host_set_guard(host, guard);
3485 base_vha->flags.difdix_supported = 0;
3488 ha->isp_ops->enable_intrs(ha);
3490 if (IS_QLAFX00(ha)) {
3491 ret = qlafx00_fx_disc(base_vha,
3492 &base_vha->hw->mr.fcport, FXDISC_GET_CONFIG_INFO);
3493 host->sg_tablesize = (ha->mr.extended_io_enabled) ?
3497 ret = scsi_add_host(host, &pdev->dev);
3501 base_vha->flags.init_done = 1;
3502 base_vha->flags.online = 1;
3503 ha->prev_minidump_failed = 0;
3505 ql_dbg(ql_dbg_init, base_vha, 0x00f2,
3506 "Init done and hba is online.\n");
3508 if (qla_ini_mode_enabled(base_vha) ||
3509 qla_dual_mode_enabled(base_vha))
3510 scsi_scan_host(host);
3512 ql_dbg(ql_dbg_init, base_vha, 0x0122,
3513 "skipping scsi_scan_host() for non-initiator port\n");
3515 qla2x00_alloc_sysfs_attr(base_vha);
3517 if (IS_QLAFX00(ha)) {
3518 ret = qlafx00_fx_disc(base_vha,
3519 &base_vha->hw->mr.fcport, FXDISC_GET_PORT_INFO);
3521 /* Register system information */
3522 ret = qlafx00_fx_disc(base_vha,
3523 &base_vha->hw->mr.fcport, FXDISC_REG_HOST_INFO);
3526 qla2x00_init_host_attr(base_vha);
3528 qla2x00_dfs_setup(base_vha);
3530 ql_log(ql_log_info, base_vha, 0x00fb,
3531 "QLogic %s - %s.\n", ha->model_number, ha->model_desc);
3532 ql_log(ql_log_info, base_vha, 0x00fc,
3533 "ISP%04X: %s @ %s hdma%c host#=%ld fw=%s.\n",
3534 pdev->device, ha->isp_ops->pci_info_str(base_vha, pci_info,
3536 pci_name(pdev), ha->flags.enable_64bit_addressing ? '+' : '-',
3538 ha->isp_ops->fw_version_str(base_vha, fw_str, sizeof(fw_str)));
3540 qlt_add_target(ha, base_vha);
3542 clear_bit(PFLG_DRIVER_PROBING, &base_vha->pci_flags);
3544 if (test_bit(UNLOADING, &base_vha->dpc_flags))
3550 qla_enode_stop(base_vha);
3551 qla_edb_stop(base_vha);
3552 if (base_vha->gnl.l) {
3553 dma_free_coherent(&ha->pdev->dev, base_vha->gnl.size,
3554 base_vha->gnl.l, base_vha->gnl.ldma);
3555 base_vha->gnl.l = NULL;
3558 if (base_vha->timer_active)
3559 qla2x00_stop_timer(base_vha);
3560 base_vha->flags.online = 0;
3561 if (ha->dpc_thread) {
3562 struct task_struct *t = ha->dpc_thread;
3564 ha->dpc_thread = NULL;
3568 qla2x00_free_device(base_vha);
3569 scsi_host_put(base_vha->host);
3571 * Need to NULL out local req/rsp after
3572 * qla2x00_free_device => qla2x00_free_queues frees
3573 * what these are pointing to. Or else we'll
3574 * fall over below in qla2x00_free_req/rsp_que.
3580 qla2x00_mem_free(ha);
3581 qla2x00_free_req_que(ha, req);
3582 qla2x00_free_rsp_que(ha, rsp);
3583 qla2x00_clear_drv_active(ha);
3585 iospace_config_failed:
3586 if (IS_P3P_TYPE(ha)) {
3587 if (!ha->nx_pcibase)
3588 iounmap((device_reg_t *)ha->nx_pcibase);
3590 iounmap((device_reg_t *)ha->nxdb_wr_ptr);
3593 iounmap(ha->iobase);
3595 iounmap(ha->cregbase);
3597 pci_release_selected_regions(ha->pdev, ha->bars);
3601 pci_disable_device(pdev);
3605 static void __qla_set_remove_flag(scsi_qla_host_t *base_vha)
3607 scsi_qla_host_t *vp;
3608 unsigned long flags;
3609 struct qla_hw_data *ha;
3616 spin_lock_irqsave(&ha->vport_slock, flags);
3617 list_for_each_entry(vp, &ha->vp_list, list)
3618 set_bit(PFLG_DRIVER_REMOVING, &vp->pci_flags);
3621 * Indicate device removal to prevent future board_disable
3622 * and wait until any pending board_disable has completed.
3624 set_bit(PFLG_DRIVER_REMOVING, &base_vha->pci_flags);
3625 spin_unlock_irqrestore(&ha->vport_slock, flags);
3629 qla2x00_shutdown(struct pci_dev *pdev)
3631 scsi_qla_host_t *vha;
3632 struct qla_hw_data *ha;
3634 vha = pci_get_drvdata(pdev);
3637 ql_log(ql_log_info, vha, 0xfffa,
3638 "Adapter shutdown\n");
3641 * Prevent future board_disable and wait
3642 * until any pending board_disable has completed.
3644 __qla_set_remove_flag(vha);
3645 cancel_work_sync(&ha->board_disable);
3647 if (!atomic_read(&pdev->enable_cnt))
3650 /* Notify ISPFX00 firmware */
3652 qlafx00_driver_shutdown(vha, 20);
3654 /* Turn-off FCE trace */
3655 if (ha->flags.fce_enabled) {
3656 qla2x00_disable_fce_trace(vha, NULL, NULL);
3657 ha->flags.fce_enabled = 0;
3660 /* Turn-off EFT trace */
3662 qla2x00_disable_eft_trace(vha);
3664 if (IS_QLA25XX(ha) || IS_QLA2031(ha) || IS_QLA27XX(ha) ||
3666 if (ha->flags.fw_started)
3667 qla2x00_abort_isp_cleanup(vha);
3669 /* Stop currently executing firmware. */
3670 qla2x00_try_to_stop_firmware(vha);
3674 if (vha->timer_active)
3675 qla2x00_stop_timer(vha);
3677 /* Turn adapter off line */
3678 vha->flags.online = 0;
3680 /* turn-off interrupts on the card */
3681 if (ha->interrupts_on) {
3682 vha->flags.init_done = 0;
3683 ha->isp_ops->disable_intrs(ha);
3686 qla2x00_free_irqs(vha);
3688 qla2x00_free_fw_dump(ha);
3690 pci_disable_device(pdev);
3691 ql_log(ql_log_info, vha, 0xfffe,
3692 "Adapter shutdown successfully.\n");
3695 /* Deletes all the virtual ports for a given ha */
3697 qla2x00_delete_all_vps(struct qla_hw_data *ha, scsi_qla_host_t *base_vha)
3699 scsi_qla_host_t *vha;
3700 unsigned long flags;
3702 mutex_lock(&ha->vport_lock);
3703 while (ha->cur_vport_count) {
3704 spin_lock_irqsave(&ha->vport_slock, flags);
3706 BUG_ON(base_vha->list.next == &ha->vp_list);
3707 /* This assumes first entry in ha->vp_list is always base vha */
3708 vha = list_first_entry(&base_vha->list, scsi_qla_host_t, list);
3709 scsi_host_get(vha->host);
3711 spin_unlock_irqrestore(&ha->vport_slock, flags);
3712 mutex_unlock(&ha->vport_lock);
3714 qla_nvme_delete(vha);
3716 fc_vport_terminate(vha->fc_vport);
3717 scsi_host_put(vha->host);
3719 mutex_lock(&ha->vport_lock);
3721 mutex_unlock(&ha->vport_lock);
3724 /* Stops all deferred work threads */
3726 qla2x00_destroy_deferred_work(struct qla_hw_data *ha)
3728 /* Cancel all work and destroy DPC workqueues */
3729 if (ha->dpc_lp_wq) {
3730 cancel_work_sync(&ha->idc_aen);
3731 destroy_workqueue(ha->dpc_lp_wq);
3732 ha->dpc_lp_wq = NULL;
3735 if (ha->dpc_hp_wq) {
3736 cancel_work_sync(&ha->nic_core_reset);
3737 cancel_work_sync(&ha->idc_state_handler);
3738 cancel_work_sync(&ha->nic_core_unrecoverable);
3739 destroy_workqueue(ha->dpc_hp_wq);
3740 ha->dpc_hp_wq = NULL;
3743 /* Kill the kernel thread for this host */
3744 if (ha->dpc_thread) {
3745 struct task_struct *t = ha->dpc_thread;
3748 * qla2xxx_wake_dpc checks for ->dpc_thread
3749 * so we need to zero it out.
3751 ha->dpc_thread = NULL;
3757 qla2x00_unmap_iobases(struct qla_hw_data *ha)
3759 if (IS_QLA82XX(ha)) {
3761 iounmap((device_reg_t *)ha->nx_pcibase);
3763 iounmap((device_reg_t *)ha->nxdb_wr_ptr);
3766 iounmap(ha->iobase);
3769 iounmap(ha->cregbase);
3772 iounmap(ha->mqiobase);
3774 if ((IS_QLA83XX(ha) || IS_QLA27XX(ha) || IS_QLA28XX(ha)) &&
3776 iounmap(ha->msixbase);
3781 qla2x00_clear_drv_active(struct qla_hw_data *ha)
3783 if (IS_QLA8044(ha)) {
3784 qla8044_idc_lock(ha);
3785 qla8044_clear_drv_active(ha);
3786 qla8044_idc_unlock(ha);
3787 } else if (IS_QLA82XX(ha)) {
3788 qla82xx_idc_lock(ha);
3789 qla82xx_clear_drv_active(ha);
3790 qla82xx_idc_unlock(ha);
3795 qla2x00_remove_one(struct pci_dev *pdev)
3797 scsi_qla_host_t *base_vha;
3798 struct qla_hw_data *ha;
3800 base_vha = pci_get_drvdata(pdev);
3802 ql_log(ql_log_info, base_vha, 0xb079,
3803 "Removing driver\n");
3804 __qla_set_remove_flag(base_vha);
3805 cancel_work_sync(&ha->board_disable);
3808 * If the PCI device is disabled then there was a PCI-disconnect and
3809 * qla2x00_disable_board_on_pci_error has taken care of most of the
3812 if (!atomic_read(&pdev->enable_cnt)) {
3813 dma_free_coherent(&ha->pdev->dev, base_vha->gnl.size,
3814 base_vha->gnl.l, base_vha->gnl.ldma);
3815 base_vha->gnl.l = NULL;
3816 scsi_host_put(base_vha->host);
3818 pci_set_drvdata(pdev, NULL);
3821 qla2x00_wait_for_hba_ready(base_vha);
3824 * if UNLOADING flag is already set, then continue unload,
3825 * where it was set first.
3827 if (test_and_set_bit(UNLOADING, &base_vha->dpc_flags))
3830 if (IS_QLA25XX(ha) || IS_QLA2031(ha) || IS_QLA27XX(ha) ||
3832 if (ha->flags.fw_started)
3833 qla2x00_abort_isp_cleanup(base_vha);
3834 } else if (!IS_QLAFX00(ha)) {
3835 if (IS_QLA8031(ha)) {
3836 ql_dbg(ql_dbg_p3p, base_vha, 0xb07e,
3837 "Clearing fcoe driver presence.\n");
3838 if (qla83xx_clear_drv_presence(base_vha) != QLA_SUCCESS)
3839 ql_dbg(ql_dbg_p3p, base_vha, 0xb079,
3840 "Error while clearing DRV-Presence.\n");
3843 qla2x00_try_to_stop_firmware(base_vha);
3846 qla2x00_wait_for_sess_deletion(base_vha);
3848 qla_nvme_delete(base_vha);
3850 dma_free_coherent(&ha->pdev->dev,
3851 base_vha->gnl.size, base_vha->gnl.l, base_vha->gnl.ldma);
3853 base_vha->gnl.l = NULL;
3854 qla_enode_stop(base_vha);
3855 qla_edb_stop(base_vha);
3857 vfree(base_vha->scan.l);
3860 qlafx00_driver_shutdown(base_vha, 20);
3862 qla2x00_delete_all_vps(ha, base_vha);
3864 qla2x00_dfs_remove(base_vha);
3866 qla84xx_put_chip(base_vha);
3869 if (base_vha->timer_active)
3870 qla2x00_stop_timer(base_vha);
3872 base_vha->flags.online = 0;
3874 /* free DMA memory */
3875 if (ha->exlogin_buf)
3876 qla2x00_free_exlogin_buffer(ha);
3878 /* free DMA memory */
3879 if (ha->exchoffld_buf)
3880 qla2x00_free_exchoffld_buffer(ha);
3882 qla2x00_destroy_deferred_work(ha);
3884 qlt_remove_target(ha, base_vha);
3886 qla2x00_free_sysfs_attr(base_vha, true);
3888 fc_remove_host(base_vha->host);
3890 scsi_remove_host(base_vha->host);
3892 qla2x00_free_device(base_vha);
3894 qla2x00_clear_drv_active(ha);
3896 scsi_host_put(base_vha->host);
3898 qla2x00_unmap_iobases(ha);
3900 pci_release_selected_regions(ha->pdev, ha->bars);
3903 pci_disable_pcie_error_reporting(pdev);
3905 pci_disable_device(pdev);
3909 qla24xx_free_purex_list(struct purex_list *list)
3911 struct list_head *item, *next;
3914 spin_lock_irqsave(&list->lock, flags);
3915 list_for_each_safe(item, next, &list->head) {
3917 kfree(list_entry(item, struct purex_item, list));
3919 spin_unlock_irqrestore(&list->lock, flags);
3923 qla2x00_free_device(scsi_qla_host_t *vha)
3925 struct qla_hw_data *ha = vha->hw;
3927 qla2x00_abort_all_cmds(vha, DID_NO_CONNECT << 16);
3930 if (vha->timer_active)
3931 qla2x00_stop_timer(vha);
3933 qla25xx_delete_queues(vha);
3934 vha->flags.online = 0;
3936 /* turn-off interrupts on the card */
3937 if (ha->interrupts_on) {
3938 vha->flags.init_done = 0;
3939 ha->isp_ops->disable_intrs(ha);
3942 qla2x00_free_fcports(vha);
3944 qla2x00_free_irqs(vha);
3946 /* Flush the work queue and remove it */
3948 flush_workqueue(ha->wq);
3949 destroy_workqueue(ha->wq);
3954 qla24xx_free_purex_list(&vha->purex_list);
3956 qla2x00_mem_free(ha);
3958 qla82xx_md_free(vha);
3960 qla_edif_sadb_release_free_pool(ha);
3961 qla_edif_sadb_release(ha);
3963 qla2x00_free_queues(ha);
3966 void qla2x00_free_fcports(struct scsi_qla_host *vha)
3968 fc_port_t *fcport, *tfcport;
3970 list_for_each_entry_safe(fcport, tfcport, &vha->vp_fcports, list)
3971 qla2x00_free_fcport(fcport);
3975 qla2x00_schedule_rport_del(struct scsi_qla_host *vha, fc_port_t *fcport)
3982 if (fcport->rport) {
3983 ql_dbg(ql_dbg_disc, fcport->vha, 0x2109,
3984 "%s %8phN. rport %p roles %x\n",
3985 __func__, fcport->port_name, fcport->rport,
3986 fcport->rport->roles);
3987 fc_remote_port_delete(fcport->rport);
3989 qlt_do_generation_tick(vha, &now);
3993 * qla2x00_mark_device_lost Updates fcport state when device goes offline.
3995 * Input: ha = adapter block pointer. fcport = port structure pointer.
4001 void qla2x00_mark_device_lost(scsi_qla_host_t *vha, fc_port_t *fcport,
4004 if (IS_QLAFX00(vha->hw)) {
4005 qla2x00_set_fcport_state(fcport, FCS_DEVICE_LOST);
4006 qla2x00_schedule_rport_del(vha, fcport);
4010 if (atomic_read(&fcport->state) == FCS_ONLINE &&
4011 vha->vp_idx == fcport->vha->vp_idx) {
4012 qla2x00_set_fcport_state(fcport, FCS_DEVICE_LOST);
4013 qla2x00_schedule_rport_del(vha, fcport);
4017 * We may need to retry the login, so don't change the state of the
4018 * port but do the retries.
4020 if (atomic_read(&fcport->state) != FCS_DEVICE_DEAD)
4021 qla2x00_set_fcport_state(fcport, FCS_DEVICE_LOST);
4026 set_bit(RELOGIN_NEEDED, &vha->dpc_flags);
4030 qla2x00_mark_all_devices_lost(scsi_qla_host_t *vha)
4034 ql_dbg(ql_dbg_disc, vha, 0x20f1,
4035 "Mark all dev lost\n");
4037 list_for_each_entry(fcport, &vha->vp_fcports, list) {
4038 if (fcport->loop_id != FC_NO_LOOP_ID &&
4039 (fcport->flags & FCF_FCP2_DEVICE) &&
4040 fcport->port_type == FCT_TARGET &&
4041 !qla2x00_reset_active(vha)) {
4042 ql_dbg(ql_dbg_disc, vha, 0x211a,
4043 "Delaying session delete for FCP2 flags 0x%x port_type = 0x%x port_id=%06x %phC",
4044 fcport->flags, fcport->port_type,
4045 fcport->d_id.b24, fcport->port_name);
4048 fcport->scan_state = 0;
4049 qlt_schedule_sess_for_deletion(fcport);
4053 static void qla2x00_set_reserved_loop_ids(struct qla_hw_data *ha)
4057 if (IS_FWI2_CAPABLE(ha))
4060 for (i = 0; i < SNS_FIRST_LOOP_ID; i++)
4061 set_bit(i, ha->loop_id_map);
4062 set_bit(MANAGEMENT_SERVER, ha->loop_id_map);
4063 set_bit(BROADCAST, ha->loop_id_map);
4068 * Allocates adapter memory.
4075 qla2x00_mem_alloc(struct qla_hw_data *ha, uint16_t req_len, uint16_t rsp_len,
4076 struct req_que **req, struct rsp_que **rsp)
4081 ha->init_cb = dma_alloc_coherent(&ha->pdev->dev, ha->init_cb_size,
4082 &ha->init_cb_dma, GFP_KERNEL);
4086 rc = btree_init32(&ha->host_map);
4088 goto fail_free_init_cb;
4090 if (qlt_mem_alloc(ha) < 0)
4091 goto fail_free_btree;
4093 ha->gid_list = dma_alloc_coherent(&ha->pdev->dev,
4094 qla2x00_gid_list_size(ha), &ha->gid_list_dma, GFP_KERNEL);
4096 goto fail_free_tgt_mem;
4098 ha->srb_mempool = mempool_create_slab_pool(SRB_MIN_REQ, srb_cachep);
4099 if (!ha->srb_mempool)
4100 goto fail_free_gid_list;
4102 if (IS_P3P_TYPE(ha) || IS_QLA27XX(ha) || (ql2xsecenable && IS_QLA28XX(ha))) {
4103 /* Allocate cache for CT6 Ctx. */
4105 ctx_cachep = kmem_cache_create("qla2xxx_ctx",
4106 sizeof(struct ct6_dsd), 0,
4107 SLAB_HWCACHE_ALIGN, NULL);
4109 goto fail_free_srb_mempool;
4111 ha->ctx_mempool = mempool_create_slab_pool(SRB_MIN_REQ,
4113 if (!ha->ctx_mempool)
4114 goto fail_free_srb_mempool;
4115 ql_dbg_pci(ql_dbg_init, ha->pdev, 0x0021,
4116 "ctx_cachep=%p ctx_mempool=%p.\n",
4117 ctx_cachep, ha->ctx_mempool);
4120 /* Get memory for cached NVRAM */
4121 ha->nvram = kzalloc(MAX_NVRAM_SIZE, GFP_KERNEL);
4123 goto fail_free_ctx_mempool;
4125 snprintf(name, sizeof(name), "%s_%d", QLA2XXX_DRIVER_NAME,
4127 ha->s_dma_pool = dma_pool_create(name, &ha->pdev->dev,
4128 DMA_POOL_SIZE, 8, 0);
4129 if (!ha->s_dma_pool)
4130 goto fail_free_nvram;
4132 ql_dbg_pci(ql_dbg_init, ha->pdev, 0x0022,
4133 "init_cb=%p gid_list=%p, srb_mempool=%p s_dma_pool=%p.\n",
4134 ha->init_cb, ha->gid_list, ha->srb_mempool, ha->s_dma_pool);
4136 if (IS_P3P_TYPE(ha) || ql2xenabledif || (IS_QLA28XX(ha) && ql2xsecenable)) {
4137 ha->dl_dma_pool = dma_pool_create(name, &ha->pdev->dev,
4138 DSD_LIST_DMA_POOL_SIZE, 8, 0);
4139 if (!ha->dl_dma_pool) {
4140 ql_log_pci(ql_log_fatal, ha->pdev, 0x0023,
4141 "Failed to allocate memory for dl_dma_pool.\n");
4142 goto fail_s_dma_pool;
4145 ha->fcp_cmnd_dma_pool = dma_pool_create(name, &ha->pdev->dev,
4146 FCP_CMND_DMA_POOL_SIZE, 8, 0);
4147 if (!ha->fcp_cmnd_dma_pool) {
4148 ql_log_pci(ql_log_fatal, ha->pdev, 0x0024,
4149 "Failed to allocate memory for fcp_cmnd_dma_pool.\n");
4150 goto fail_dl_dma_pool;
4153 if (ql2xenabledif) {
4154 u64 bufsize = DIF_BUNDLING_DMA_POOL_SIZE;
4155 struct dsd_dma *dsd, *nxt;
4157 /* Creata a DMA pool of buffers for DIF bundling */
4158 ha->dif_bundl_pool = dma_pool_create(name,
4159 &ha->pdev->dev, DIF_BUNDLING_DMA_POOL_SIZE, 8, 0);
4160 if (!ha->dif_bundl_pool) {
4161 ql_dbg_pci(ql_dbg_init, ha->pdev, 0x0024,
4162 "%s: failed create dif_bundl_pool\n",
4164 goto fail_dif_bundl_dma_pool;
4167 INIT_LIST_HEAD(&ha->pool.good.head);
4168 INIT_LIST_HEAD(&ha->pool.unusable.head);
4169 ha->pool.good.count = 0;
4170 ha->pool.unusable.count = 0;
4171 for (i = 0; i < 128; i++) {
4172 dsd = kzalloc(sizeof(*dsd), GFP_ATOMIC);
4174 ql_dbg_pci(ql_dbg_init, ha->pdev,
4175 0xe0ee, "%s: failed alloc dsd\n",
4179 ha->dif_bundle_kallocs++;
4181 dsd->dsd_addr = dma_pool_alloc(
4182 ha->dif_bundl_pool, GFP_ATOMIC,
4183 &dsd->dsd_list_dma);
4184 if (!dsd->dsd_addr) {
4185 ql_dbg_pci(ql_dbg_init, ha->pdev,
4187 "%s: failed alloc ->dsd_addr\n",
4190 ha->dif_bundle_kallocs--;
4193 ha->dif_bundle_dma_allocs++;
4196 * if DMA buffer crosses 4G boundary,
4197 * put it on bad list
4199 if (MSD(dsd->dsd_list_dma) ^
4200 MSD(dsd->dsd_list_dma + bufsize)) {
4201 list_add_tail(&dsd->list,
4202 &ha->pool.unusable.head);
4203 ha->pool.unusable.count++;
4205 list_add_tail(&dsd->list,
4206 &ha->pool.good.head);
4207 ha->pool.good.count++;
4211 /* return the good ones back to the pool */
4212 list_for_each_entry_safe(dsd, nxt,
4213 &ha->pool.good.head, list) {
4214 list_del(&dsd->list);
4215 dma_pool_free(ha->dif_bundl_pool,
4216 dsd->dsd_addr, dsd->dsd_list_dma);
4217 ha->dif_bundle_dma_allocs--;
4219 ha->dif_bundle_kallocs--;
4222 ql_dbg_pci(ql_dbg_init, ha->pdev, 0x0024,
4223 "%s: dif dma pool (good=%u unusable=%u)\n",
4224 __func__, ha->pool.good.count,
4225 ha->pool.unusable.count);
4228 ql_dbg_pci(ql_dbg_init, ha->pdev, 0x0025,
4229 "dl_dma_pool=%p fcp_cmnd_dma_pool=%p dif_bundl_pool=%p.\n",
4230 ha->dl_dma_pool, ha->fcp_cmnd_dma_pool,
4231 ha->dif_bundl_pool);
4234 /* Allocate memory for SNS commands */
4235 if (IS_QLA2100(ha) || IS_QLA2200(ha)) {
4236 /* Get consistent memory allocated for SNS commands */
4237 ha->sns_cmd = dma_alloc_coherent(&ha->pdev->dev,
4238 sizeof(struct sns_cmd_pkt), &ha->sns_cmd_dma, GFP_KERNEL);
4241 ql_dbg_pci(ql_dbg_init, ha->pdev, 0x0026,
4242 "sns_cmd: %p.\n", ha->sns_cmd);
4244 /* Get consistent memory allocated for MS IOCB */
4245 ha->ms_iocb = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL,
4249 /* Get consistent memory allocated for CT SNS commands */
4250 ha->ct_sns = dma_alloc_coherent(&ha->pdev->dev,
4251 sizeof(struct ct_sns_pkt), &ha->ct_sns_dma, GFP_KERNEL);
4253 goto fail_free_ms_iocb;
4254 ql_dbg_pci(ql_dbg_init, ha->pdev, 0x0027,
4255 "ms_iocb=%p ct_sns=%p.\n",
4256 ha->ms_iocb, ha->ct_sns);
4259 /* Allocate memory for request ring */
4260 *req = kzalloc(sizeof(struct req_que), GFP_KERNEL);
4262 ql_log_pci(ql_log_fatal, ha->pdev, 0x0028,
4263 "Failed to allocate memory for req.\n");
4266 (*req)->length = req_len;
4267 (*req)->ring = dma_alloc_coherent(&ha->pdev->dev,
4268 ((*req)->length + 1) * sizeof(request_t),
4269 &(*req)->dma, GFP_KERNEL);
4270 if (!(*req)->ring) {
4271 ql_log_pci(ql_log_fatal, ha->pdev, 0x0029,
4272 "Failed to allocate memory for req_ring.\n");
4275 /* Allocate memory for response ring */
4276 *rsp = kzalloc(sizeof(struct rsp_que), GFP_KERNEL);
4278 ql_log_pci(ql_log_fatal, ha->pdev, 0x002a,
4279 "Failed to allocate memory for rsp.\n");
4283 (*rsp)->length = rsp_len;
4284 (*rsp)->ring = dma_alloc_coherent(&ha->pdev->dev,
4285 ((*rsp)->length + 1) * sizeof(response_t),
4286 &(*rsp)->dma, GFP_KERNEL);
4287 if (!(*rsp)->ring) {
4288 ql_log_pci(ql_log_fatal, ha->pdev, 0x002b,
4289 "Failed to allocate memory for rsp_ring.\n");
4294 ql_dbg_pci(ql_dbg_init, ha->pdev, 0x002c,
4295 "req=%p req->length=%d req->ring=%p rsp=%p "
4296 "rsp->length=%d rsp->ring=%p.\n",
4297 *req, (*req)->length, (*req)->ring, *rsp, (*rsp)->length,
4299 /* Allocate memory for NVRAM data for vports */
4300 if (ha->nvram_npiv_size) {
4301 ha->npiv_info = kcalloc(ha->nvram_npiv_size,
4302 sizeof(struct qla_npiv_entry),
4304 if (!ha->npiv_info) {
4305 ql_log_pci(ql_log_fatal, ha->pdev, 0x002d,
4306 "Failed to allocate memory for npiv_info.\n");
4307 goto fail_npiv_info;
4310 ha->npiv_info = NULL;
4312 /* Get consistent memory allocated for EX-INIT-CB. */
4313 if (IS_CNA_CAPABLE(ha) || IS_QLA2031(ha) || IS_QLA27XX(ha) ||
4315 ha->ex_init_cb = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL,
4316 &ha->ex_init_cb_dma);
4317 if (!ha->ex_init_cb)
4318 goto fail_ex_init_cb;
4319 ql_dbg_pci(ql_dbg_init, ha->pdev, 0x002e,
4320 "ex_init_cb=%p.\n", ha->ex_init_cb);
4323 /* Get consistent memory allocated for Special Features-CB. */
4324 if (IS_QLA27XX(ha) || IS_QLA28XX(ha)) {
4325 ha->sf_init_cb = dma_pool_zalloc(ha->s_dma_pool, GFP_KERNEL,
4326 &ha->sf_init_cb_dma);
4327 if (!ha->sf_init_cb)
4328 goto fail_sf_init_cb;
4329 ql_dbg_pci(ql_dbg_init, ha->pdev, 0x0199,
4330 "sf_init_cb=%p.\n", ha->sf_init_cb);
4333 INIT_LIST_HEAD(&ha->gbl_dsd_list);
4335 /* Get consistent memory allocated for Async Port-Database. */
4336 if (!IS_FWI2_CAPABLE(ha)) {
4337 ha->async_pd = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL,
4341 ql_dbg_pci(ql_dbg_init, ha->pdev, 0x002f,
4342 "async_pd=%p.\n", ha->async_pd);
4345 INIT_LIST_HEAD(&ha->vp_list);
4347 /* Allocate memory for our loop_id bitmap */
4348 ha->loop_id_map = kcalloc(BITS_TO_LONGS(LOOPID_MAP_SIZE),
4351 if (!ha->loop_id_map)
4352 goto fail_loop_id_map;
4354 qla2x00_set_reserved_loop_ids(ha);
4355 ql_dbg_pci(ql_dbg_init, ha->pdev, 0x0123,
4356 "loop_id_map=%p.\n", ha->loop_id_map);
4359 ha->sfp_data = dma_alloc_coherent(&ha->pdev->dev,
4360 SFP_DEV_SIZE, &ha->sfp_data_dma, GFP_KERNEL);
4361 if (!ha->sfp_data) {
4362 ql_dbg_pci(ql_dbg_init, ha->pdev, 0x011b,
4363 "Unable to allocate memory for SFP read-data.\n");
4367 ha->flt = dma_alloc_coherent(&ha->pdev->dev,
4368 sizeof(struct qla_flt_header) + FLT_REGIONS_SIZE, &ha->flt_dma,
4371 ql_dbg_pci(ql_dbg_init, ha->pdev, 0x011b,
4372 "Unable to allocate memory for FLT.\n");
4373 goto fail_flt_buffer;
4376 /* allocate the purex dma pool */
4377 ha->purex_dma_pool = dma_pool_create(name, &ha->pdev->dev,
4380 if (!ha->purex_dma_pool) {
4381 ql_dbg_pci(ql_dbg_init, ha->pdev, 0x011b,
4382 "Unable to allocate purex_dma_pool.\n");
4386 ha->elsrej.size = sizeof(struct fc_els_ls_rjt) + 16;
4387 ha->elsrej.c = dma_alloc_coherent(&ha->pdev->dev,
4388 ha->elsrej.size, &ha->elsrej.cdma, GFP_KERNEL);
4390 if (!ha->elsrej.c) {
4391 ql_dbg_pci(ql_dbg_init, ha->pdev, 0xffff,
4392 "Alloc failed for els reject cmd.\n");
4395 ha->elsrej.c->er_cmd = ELS_LS_RJT;
4396 ha->elsrej.c->er_reason = ELS_RJT_LOGIC;
4397 ha->elsrej.c->er_explan = ELS_EXPL_UNAB_DATA;
4401 dma_pool_destroy(ha->purex_dma_pool);
4403 dma_free_coherent(&ha->pdev->dev, SFP_DEV_SIZE,
4404 ha->flt, ha->flt_dma);
4407 dma_free_coherent(&ha->pdev->dev, SFP_DEV_SIZE,
4408 ha->sfp_data, ha->sfp_data_dma);
4410 kfree(ha->loop_id_map);
4412 dma_pool_free(ha->s_dma_pool, ha->async_pd, ha->async_pd_dma);
4414 dma_pool_free(ha->s_dma_pool, ha->sf_init_cb, ha->sf_init_cb_dma);
4416 dma_pool_free(ha->s_dma_pool, ha->ex_init_cb, ha->ex_init_cb_dma);
4418 kfree(ha->npiv_info);
4420 dma_free_coherent(&ha->pdev->dev, ((*rsp)->length + 1) *
4421 sizeof(response_t), (*rsp)->ring, (*rsp)->dma);
4422 (*rsp)->ring = NULL;
4428 dma_free_coherent(&ha->pdev->dev, ((*req)->length + 1) *
4429 sizeof(request_t), (*req)->ring, (*req)->dma);
4430 (*req)->ring = NULL;
4436 dma_free_coherent(&ha->pdev->dev, sizeof(struct ct_sns_pkt),
4437 ha->ct_sns, ha->ct_sns_dma);
4441 dma_pool_free(ha->s_dma_pool, ha->ms_iocb, ha->ms_iocb_dma);
4443 ha->ms_iocb_dma = 0;
4446 dma_free_coherent(&ha->pdev->dev, sizeof(struct sns_cmd_pkt),
4447 ha->sns_cmd, ha->sns_cmd_dma);
4449 if (ql2xenabledif) {
4450 struct dsd_dma *dsd, *nxt;
4452 list_for_each_entry_safe(dsd, nxt, &ha->pool.unusable.head,
4454 list_del(&dsd->list);
4455 dma_pool_free(ha->dif_bundl_pool, dsd->dsd_addr,
4457 ha->dif_bundle_dma_allocs--;
4459 ha->dif_bundle_kallocs--;
4460 ha->pool.unusable.count--;
4462 dma_pool_destroy(ha->dif_bundl_pool);
4463 ha->dif_bundl_pool = NULL;
4466 fail_dif_bundl_dma_pool:
4467 if (IS_QLA82XX(ha) || ql2xenabledif) {
4468 dma_pool_destroy(ha->fcp_cmnd_dma_pool);
4469 ha->fcp_cmnd_dma_pool = NULL;
4472 if (IS_QLA82XX(ha) || ql2xenabledif) {
4473 dma_pool_destroy(ha->dl_dma_pool);
4474 ha->dl_dma_pool = NULL;
4477 dma_pool_destroy(ha->s_dma_pool);
4478 ha->s_dma_pool = NULL;
4482 fail_free_ctx_mempool:
4483 mempool_destroy(ha->ctx_mempool);
4484 ha->ctx_mempool = NULL;
4485 fail_free_srb_mempool:
4486 mempool_destroy(ha->srb_mempool);
4487 ha->srb_mempool = NULL;
4489 dma_free_coherent(&ha->pdev->dev, qla2x00_gid_list_size(ha),
4492 ha->gid_list = NULL;
4493 ha->gid_list_dma = 0;
4497 btree_destroy32(&ha->host_map);
4499 dma_free_coherent(&ha->pdev->dev, ha->init_cb_size, ha->init_cb,
4502 ha->init_cb_dma = 0;
4504 ql_log(ql_log_fatal, NULL, 0x0030,
4505 "Memory allocation failure.\n");
4510 qla2x00_set_exlogins_buffer(scsi_qla_host_t *vha)
4513 uint16_t size, max_cnt;
4515 struct qla_hw_data *ha = vha->hw;
4517 /* Return if we don't need to alloacate any extended logins */
4518 if (ql2xexlogins <= MAX_FIBRE_DEVICES_2400)
4521 if (!IS_EXLOGIN_OFFLD_CAPABLE(ha))
4524 ql_log(ql_log_info, vha, 0xd021, "EXLOGIN count: %d.\n", ql2xexlogins);
4526 rval = qla_get_exlogin_status(vha, &size, &max_cnt);
4527 if (rval != QLA_SUCCESS) {
4528 ql_log_pci(ql_log_fatal, ha->pdev, 0xd029,
4529 "Failed to get exlogin status.\n");
4533 temp = (ql2xexlogins > max_cnt) ? max_cnt : ql2xexlogins;
4536 if (temp != ha->exlogin_size) {
4537 qla2x00_free_exlogin_buffer(ha);
4538 ha->exlogin_size = temp;
4540 ql_log(ql_log_info, vha, 0xd024,
4541 "EXLOGIN: max_logins=%d, portdb=0x%x, total=%d.\n",
4542 max_cnt, size, temp);
4544 ql_log(ql_log_info, vha, 0xd025,
4545 "EXLOGIN: requested size=0x%x\n", ha->exlogin_size);
4547 /* Get consistent memory for extended logins */
4548 ha->exlogin_buf = dma_alloc_coherent(&ha->pdev->dev,
4549 ha->exlogin_size, &ha->exlogin_buf_dma, GFP_KERNEL);
4550 if (!ha->exlogin_buf) {
4551 ql_log_pci(ql_log_fatal, ha->pdev, 0xd02a,
4552 "Failed to allocate memory for exlogin_buf_dma.\n");
4557 /* Now configure the dma buffer */
4558 rval = qla_set_exlogin_mem_cfg(vha, ha->exlogin_buf_dma);
4560 ql_log(ql_log_fatal, vha, 0xd033,
4561 "Setup extended login buffer ****FAILED****.\n");
4562 qla2x00_free_exlogin_buffer(ha);
4569 * qla2x00_free_exlogin_buffer
4572 * ha = adapter block pointer
4575 qla2x00_free_exlogin_buffer(struct qla_hw_data *ha)
4577 if (ha->exlogin_buf) {
4578 dma_free_coherent(&ha->pdev->dev, ha->exlogin_size,
4579 ha->exlogin_buf, ha->exlogin_buf_dma);
4580 ha->exlogin_buf = NULL;
4581 ha->exlogin_size = 0;
4586 qla2x00_number_of_exch(scsi_qla_host_t *vha, u32 *ret_cnt, u16 max_cnt)
4589 struct init_cb_81xx *icb = (struct init_cb_81xx *)&vha->hw->init_cb;
4590 *ret_cnt = FW_DEF_EXCHANGES_CNT;
4592 if (max_cnt > vha->hw->max_exchg)
4593 max_cnt = vha->hw->max_exchg;
4595 if (qla_ini_mode_enabled(vha)) {
4596 if (vha->ql2xiniexchg > max_cnt)
4597 vha->ql2xiniexchg = max_cnt;
4599 if (vha->ql2xiniexchg > FW_DEF_EXCHANGES_CNT)
4600 *ret_cnt = vha->ql2xiniexchg;
4602 } else if (qla_tgt_mode_enabled(vha)) {
4603 if (vha->ql2xexchoffld > max_cnt) {
4604 vha->ql2xexchoffld = max_cnt;
4605 icb->exchange_count = cpu_to_le16(vha->ql2xexchoffld);
4608 if (vha->ql2xexchoffld > FW_DEF_EXCHANGES_CNT)
4609 *ret_cnt = vha->ql2xexchoffld;
4610 } else if (qla_dual_mode_enabled(vha)) {
4611 temp = vha->ql2xiniexchg + vha->ql2xexchoffld;
4612 if (temp > max_cnt) {
4613 vha->ql2xiniexchg -= (temp - max_cnt)/2;
4614 vha->ql2xexchoffld -= (((temp - max_cnt)/2) + 1);
4616 icb->exchange_count = cpu_to_le16(vha->ql2xexchoffld);
4619 if (temp > FW_DEF_EXCHANGES_CNT)
4625 qla2x00_set_exchoffld_buffer(scsi_qla_host_t *vha)
4629 u32 actual_cnt, totsz;
4630 struct qla_hw_data *ha = vha->hw;
4632 if (!ha->flags.exchoffld_enabled)
4635 if (!IS_EXCHG_OFFLD_CAPABLE(ha))
4639 rval = qla_get_exchoffld_status(vha, &size, &max_cnt);
4640 if (rval != QLA_SUCCESS) {
4641 ql_log_pci(ql_log_fatal, ha->pdev, 0xd012,
4642 "Failed to get exlogin status.\n");
4646 qla2x00_number_of_exch(vha, &actual_cnt, max_cnt);
4647 ql_log(ql_log_info, vha, 0xd014,
4648 "Actual exchange offload count: %d.\n", actual_cnt);
4650 totsz = actual_cnt * size;
4652 if (totsz != ha->exchoffld_size) {
4653 qla2x00_free_exchoffld_buffer(ha);
4654 if (actual_cnt <= FW_DEF_EXCHANGES_CNT) {
4655 ha->exchoffld_size = 0;
4656 ha->flags.exchoffld_enabled = 0;
4660 ha->exchoffld_size = totsz;
4662 ql_log(ql_log_info, vha, 0xd016,
4663 "Exchange offload: max_count=%d, actual count=%d entry sz=0x%x, total sz=0x%x\n",
4664 max_cnt, actual_cnt, size, totsz);
4666 ql_log(ql_log_info, vha, 0xd017,
4667 "Exchange Buffers requested size = 0x%x\n",
4668 ha->exchoffld_size);
4670 /* Get consistent memory for extended logins */
4671 ha->exchoffld_buf = dma_alloc_coherent(&ha->pdev->dev,
4672 ha->exchoffld_size, &ha->exchoffld_buf_dma, GFP_KERNEL);
4673 if (!ha->exchoffld_buf) {
4674 ql_log_pci(ql_log_fatal, ha->pdev, 0xd013,
4675 "Failed to allocate memory for Exchange Offload.\n");
4678 (FW_DEF_EXCHANGES_CNT + REDUCE_EXCHANGES_CNT)) {
4679 ha->max_exchg -= REDUCE_EXCHANGES_CNT;
4680 } else if (ha->max_exchg >
4681 (FW_DEF_EXCHANGES_CNT + 512)) {
4682 ha->max_exchg -= 512;
4684 ha->flags.exchoffld_enabled = 0;
4685 ql_log_pci(ql_log_fatal, ha->pdev, 0xd013,
4686 "Disabling Exchange offload due to lack of memory\n");
4688 ha->exchoffld_size = 0;
4692 } else if (!ha->exchoffld_buf || (actual_cnt <= FW_DEF_EXCHANGES_CNT)) {
4693 /* pathological case */
4694 qla2x00_free_exchoffld_buffer(ha);
4695 ha->exchoffld_size = 0;
4696 ha->flags.exchoffld_enabled = 0;
4697 ql_log(ql_log_info, vha, 0xd016,
4698 "Exchange offload not enable: offld size=%d, actual count=%d entry sz=0x%x, total sz=0x%x.\n",
4699 ha->exchoffld_size, actual_cnt, size, totsz);
4703 /* Now configure the dma buffer */
4704 rval = qla_set_exchoffld_mem_cfg(vha);
4706 ql_log(ql_log_fatal, vha, 0xd02e,
4707 "Setup exchange offload buffer ****FAILED****.\n");
4708 qla2x00_free_exchoffld_buffer(ha);
4710 /* re-adjust number of target exchange */
4711 struct init_cb_81xx *icb = (struct init_cb_81xx *)ha->init_cb;
4713 if (qla_ini_mode_enabled(vha))
4714 icb->exchange_count = 0;
4716 icb->exchange_count = cpu_to_le16(vha->ql2xexchoffld);
4723 * qla2x00_free_exchoffld_buffer
4726 * ha = adapter block pointer
4729 qla2x00_free_exchoffld_buffer(struct qla_hw_data *ha)
4731 if (ha->exchoffld_buf) {
4732 dma_free_coherent(&ha->pdev->dev, ha->exchoffld_size,
4733 ha->exchoffld_buf, ha->exchoffld_buf_dma);
4734 ha->exchoffld_buf = NULL;
4735 ha->exchoffld_size = 0;
4740 * qla2x00_free_fw_dump
4741 * Frees fw dump stuff.
4744 * ha = adapter block pointer
4747 qla2x00_free_fw_dump(struct qla_hw_data *ha)
4749 struct fwdt *fwdt = ha->fwdt;
4753 dma_free_coherent(&ha->pdev->dev,
4754 FCE_SIZE, ha->fce, ha->fce_dma);
4757 dma_free_coherent(&ha->pdev->dev,
4758 EFT_SIZE, ha->eft, ha->eft_dma);
4764 ha->flags.fce_enabled = 0;
4767 ha->fw_dumped = false;
4768 ha->fw_dump_cap_flags = 0;
4769 ha->fw_dump_reading = 0;
4771 ha->fw_dump_len = 0;
4773 for (j = 0; j < 2; j++, fwdt++) {
4774 vfree(fwdt->template);
4775 fwdt->template = NULL;
4782 * Frees all adapter allocated memory.
4785 * ha = adapter block pointer.
4788 qla2x00_mem_free(struct qla_hw_data *ha)
4790 qla2x00_free_fw_dump(ha);
4793 dma_free_coherent(&ha->pdev->dev, MCTP_DUMP_SIZE, ha->mctp_dump,
4795 ha->mctp_dump = NULL;
4797 mempool_destroy(ha->srb_mempool);
4798 ha->srb_mempool = NULL;
4801 dma_free_coherent(&ha->pdev->dev, DCBX_TLV_DATA_SIZE,
4802 ha->dcbx_tlv, ha->dcbx_tlv_dma);
4803 ha->dcbx_tlv = NULL;
4806 dma_free_coherent(&ha->pdev->dev, XGMAC_DATA_SIZE,
4807 ha->xgmac_data, ha->xgmac_data_dma);
4808 ha->xgmac_data = NULL;
4811 dma_free_coherent(&ha->pdev->dev, sizeof(struct sns_cmd_pkt),
4812 ha->sns_cmd, ha->sns_cmd_dma);
4814 ha->sns_cmd_dma = 0;
4817 dma_free_coherent(&ha->pdev->dev, sizeof(struct ct_sns_pkt),
4818 ha->ct_sns, ha->ct_sns_dma);
4823 dma_free_coherent(&ha->pdev->dev, SFP_DEV_SIZE, ha->sfp_data,
4825 ha->sfp_data = NULL;
4828 dma_free_coherent(&ha->pdev->dev,
4829 sizeof(struct qla_flt_header) + FLT_REGIONS_SIZE,
4830 ha->flt, ha->flt_dma);
4835 dma_pool_free(ha->s_dma_pool, ha->ms_iocb, ha->ms_iocb_dma);
4837 ha->ms_iocb_dma = 0;
4840 dma_pool_free(ha->s_dma_pool,
4841 ha->sf_init_cb, ha->sf_init_cb_dma);
4844 dma_pool_free(ha->s_dma_pool,
4845 ha->ex_init_cb, ha->ex_init_cb_dma);
4846 ha->ex_init_cb = NULL;
4847 ha->ex_init_cb_dma = 0;
4850 dma_pool_free(ha->s_dma_pool, ha->async_pd, ha->async_pd_dma);
4851 ha->async_pd = NULL;
4852 ha->async_pd_dma = 0;
4854 dma_pool_destroy(ha->s_dma_pool);
4855 ha->s_dma_pool = NULL;
4858 dma_free_coherent(&ha->pdev->dev, qla2x00_gid_list_size(ha),
4859 ha->gid_list, ha->gid_list_dma);
4860 ha->gid_list = NULL;
4861 ha->gid_list_dma = 0;
4863 if (IS_QLA82XX(ha)) {
4864 if (!list_empty(&ha->gbl_dsd_list)) {
4865 struct dsd_dma *dsd_ptr, *tdsd_ptr;
4867 /* clean up allocated prev pool */
4868 list_for_each_entry_safe(dsd_ptr,
4869 tdsd_ptr, &ha->gbl_dsd_list, list) {
4870 dma_pool_free(ha->dl_dma_pool,
4871 dsd_ptr->dsd_addr, dsd_ptr->dsd_list_dma);
4872 list_del(&dsd_ptr->list);
4878 dma_pool_destroy(ha->dl_dma_pool);
4879 ha->dl_dma_pool = NULL;
4881 dma_pool_destroy(ha->fcp_cmnd_dma_pool);
4882 ha->fcp_cmnd_dma_pool = NULL;
4884 mempool_destroy(ha->ctx_mempool);
4885 ha->ctx_mempool = NULL;
4887 if (ql2xenabledif && ha->dif_bundl_pool) {
4888 struct dsd_dma *dsd, *nxt;
4890 list_for_each_entry_safe(dsd, nxt, &ha->pool.unusable.head,
4892 list_del(&dsd->list);
4893 dma_pool_free(ha->dif_bundl_pool, dsd->dsd_addr,
4895 ha->dif_bundle_dma_allocs--;
4897 ha->dif_bundle_kallocs--;
4898 ha->pool.unusable.count--;
4900 list_for_each_entry_safe(dsd, nxt, &ha->pool.good.head, list) {
4901 list_del(&dsd->list);
4902 dma_pool_free(ha->dif_bundl_pool, dsd->dsd_addr,
4904 ha->dif_bundle_dma_allocs--;
4906 ha->dif_bundle_kallocs--;
4910 dma_pool_destroy(ha->dif_bundl_pool);
4911 ha->dif_bundl_pool = NULL;
4914 qla_remove_hostmap(ha);
4917 dma_free_coherent(&ha->pdev->dev, ha->init_cb_size,
4918 ha->init_cb, ha->init_cb_dma);
4920 dma_pool_destroy(ha->purex_dma_pool);
4921 ha->purex_dma_pool = NULL;
4924 dma_free_coherent(&ha->pdev->dev, ha->elsrej.size,
4925 ha->elsrej.c, ha->elsrej.cdma);
4926 ha->elsrej.c = NULL;
4930 ha->init_cb_dma = 0;
4932 vfree(ha->optrom_buffer);
4933 ha->optrom_buffer = NULL;
4936 kfree(ha->npiv_info);
4937 ha->npiv_info = NULL;
4940 kfree(ha->loop_id_map);
4941 ha->sf_init_cb = NULL;
4942 ha->sf_init_cb_dma = 0;
4943 ha->loop_id_map = NULL;
4946 struct scsi_qla_host *qla2x00_create_host(struct scsi_host_template *sht,
4947 struct qla_hw_data *ha)
4949 struct Scsi_Host *host;
4950 struct scsi_qla_host *vha = NULL;
4952 host = scsi_host_alloc(sht, sizeof(scsi_qla_host_t));
4954 ql_log_pci(ql_log_fatal, ha->pdev, 0x0107,
4955 "Failed to allocate host from the scsi layer, aborting.\n");
4959 /* Clear our data area */
4960 vha = shost_priv(host);
4961 memset(vha, 0, sizeof(scsi_qla_host_t));
4964 vha->host_no = host->host_no;
4967 vha->qlini_mode = ql2x_ini_mode;
4968 vha->ql2xexchoffld = ql2xexchoffld;
4969 vha->ql2xiniexchg = ql2xiniexchg;
4971 INIT_LIST_HEAD(&vha->vp_fcports);
4972 INIT_LIST_HEAD(&vha->work_list);
4973 INIT_LIST_HEAD(&vha->list);
4974 INIT_LIST_HEAD(&vha->qla_cmd_list);
4975 INIT_LIST_HEAD(&vha->qla_sess_op_cmd_list);
4976 INIT_LIST_HEAD(&vha->logo_list);
4977 INIT_LIST_HEAD(&vha->plogi_ack_list);
4978 INIT_LIST_HEAD(&vha->qp_list);
4979 INIT_LIST_HEAD(&vha->gnl.fcports);
4980 INIT_LIST_HEAD(&vha->gpnid_list);
4981 INIT_WORK(&vha->iocb_work, qla2x00_iocb_work_fn);
4983 INIT_LIST_HEAD(&vha->purex_list.head);
4984 spin_lock_init(&vha->purex_list.lock);
4986 spin_lock_init(&vha->work_lock);
4987 spin_lock_init(&vha->cmd_list_lock);
4988 init_waitqueue_head(&vha->fcport_waitQ);
4989 init_waitqueue_head(&vha->vref_waitq);
4990 qla_enode_init(vha);
4994 vha->gnl.size = sizeof(struct get_name_list_extended) *
4995 (ha->max_loop_id + 1);
4996 vha->gnl.l = dma_alloc_coherent(&ha->pdev->dev,
4997 vha->gnl.size, &vha->gnl.ldma, GFP_KERNEL);
4999 ql_log(ql_log_fatal, vha, 0xd04a,
5000 "Alloc failed for name list.\n");
5001 scsi_host_put(vha->host);
5005 /* todo: what about ext login? */
5006 vha->scan.size = ha->max_fibre_devices * sizeof(struct fab_scan_rp);
5007 vha->scan.l = vmalloc(vha->scan.size);
5009 ql_log(ql_log_fatal, vha, 0xd04a,
5010 "Alloc failed for scan database.\n");
5011 dma_free_coherent(&ha->pdev->dev, vha->gnl.size,
5012 vha->gnl.l, vha->gnl.ldma);
5014 scsi_host_put(vha->host);
5017 INIT_DELAYED_WORK(&vha->scan.scan_work, qla_scan_work_fn);
5019 sprintf(vha->host_str, "%s_%lu", QLA2XXX_DRIVER_NAME, vha->host_no);
5020 ql_dbg(ql_dbg_init, vha, 0x0041,
5021 "Allocated the host=%p hw=%p vha=%p dev_name=%s",
5022 vha->host, vha->hw, vha,
5023 dev_name(&(ha->pdev->dev)));
5028 struct qla_work_evt *
5029 qla2x00_alloc_work(struct scsi_qla_host *vha, enum qla_work_type type)
5031 struct qla_work_evt *e;
5034 if (test_bit(UNLOADING, &vha->dpc_flags))
5037 QLA_VHA_MARK_BUSY(vha, bail);
5041 e = kzalloc(sizeof(struct qla_work_evt), GFP_ATOMIC);
5043 QLA_VHA_MARK_NOT_BUSY(vha);
5047 INIT_LIST_HEAD(&e->list);
5049 e->flags = QLA_EVT_FLAG_FREE;
5054 qla2x00_post_work(struct scsi_qla_host *vha, struct qla_work_evt *e)
5056 unsigned long flags;
5059 spin_lock_irqsave(&vha->work_lock, flags);
5060 list_add_tail(&e->list, &vha->work_list);
5062 if (!test_and_set_bit(IOCB_WORK_ACTIVE, &vha->dpc_flags))
5065 spin_unlock_irqrestore(&vha->work_lock, flags);
5068 queue_work(vha->hw->wq, &vha->iocb_work);
5074 qla2x00_post_aen_work(struct scsi_qla_host *vha, enum fc_host_event_code code,
5077 struct qla_work_evt *e;
5079 e = qla2x00_alloc_work(vha, QLA_EVT_AEN);
5081 return QLA_FUNCTION_FAILED;
5083 e->u.aen.code = code;
5084 e->u.aen.data = data;
5085 return qla2x00_post_work(vha, e);
5089 qla2x00_post_idc_ack_work(struct scsi_qla_host *vha, uint16_t *mb)
5091 struct qla_work_evt *e;
5093 e = qla2x00_alloc_work(vha, QLA_EVT_IDC_ACK);
5095 return QLA_FUNCTION_FAILED;
5097 memcpy(e->u.idc_ack.mb, mb, QLA_IDC_ACK_REGS * sizeof(uint16_t));
5098 return qla2x00_post_work(vha, e);
5101 #define qla2x00_post_async_work(name, type) \
5102 int qla2x00_post_async_##name##_work( \
5103 struct scsi_qla_host *vha, \
5104 fc_port_t *fcport, uint16_t *data) \
5106 struct qla_work_evt *e; \
5108 e = qla2x00_alloc_work(vha, type); \
5110 return QLA_FUNCTION_FAILED; \
5112 e->u.logio.fcport = fcport; \
5114 e->u.logio.data[0] = data[0]; \
5115 e->u.logio.data[1] = data[1]; \
5117 fcport->flags |= FCF_ASYNC_ACTIVE; \
5118 return qla2x00_post_work(vha, e); \
5121 qla2x00_post_async_work(login, QLA_EVT_ASYNC_LOGIN);
5122 qla2x00_post_async_work(logout, QLA_EVT_ASYNC_LOGOUT);
5123 qla2x00_post_async_work(adisc, QLA_EVT_ASYNC_ADISC);
5124 qla2x00_post_async_work(prlo, QLA_EVT_ASYNC_PRLO);
5125 qla2x00_post_async_work(prlo_done, QLA_EVT_ASYNC_PRLO_DONE);
5128 qla2x00_post_uevent_work(struct scsi_qla_host *vha, u32 code)
5130 struct qla_work_evt *e;
5132 e = qla2x00_alloc_work(vha, QLA_EVT_UEVENT);
5134 return QLA_FUNCTION_FAILED;
5136 e->u.uevent.code = code;
5137 return qla2x00_post_work(vha, e);
5141 qla2x00_uevent_emit(struct scsi_qla_host *vha, u32 code)
5143 char event_string[40];
5144 char *envp[] = { event_string, NULL };
5147 case QLA_UEVENT_CODE_FW_DUMP:
5148 snprintf(event_string, sizeof(event_string), "FW_DUMP=%lu",
5155 kobject_uevent_env(&vha->hw->pdev->dev.kobj, KOBJ_CHANGE, envp);
5159 qlafx00_post_aenfx_work(struct scsi_qla_host *vha, uint32_t evtcode,
5160 uint32_t *data, int cnt)
5162 struct qla_work_evt *e;
5164 e = qla2x00_alloc_work(vha, QLA_EVT_AENFX);
5166 return QLA_FUNCTION_FAILED;
5168 e->u.aenfx.evtcode = evtcode;
5169 e->u.aenfx.count = cnt;
5170 memcpy(e->u.aenfx.mbx, data, sizeof(*data) * cnt);
5171 return qla2x00_post_work(vha, e);
5174 void qla24xx_sched_upd_fcport(fc_port_t *fcport)
5176 unsigned long flags;
5178 if (IS_SW_RESV_ADDR(fcport->d_id))
5181 spin_lock_irqsave(&fcport->vha->work_lock, flags);
5182 if (fcport->disc_state == DSC_UPD_FCPORT) {
5183 spin_unlock_irqrestore(&fcport->vha->work_lock, flags);
5186 fcport->jiffies_at_registration = jiffies;
5187 fcport->sec_since_registration = 0;
5188 fcport->next_disc_state = DSC_DELETED;
5189 qla2x00_set_fcport_disc_state(fcport, DSC_UPD_FCPORT);
5190 spin_unlock_irqrestore(&fcport->vha->work_lock, flags);
5192 queue_work(system_unbound_wq, &fcport->reg_work);
5196 void qla24xx_create_new_sess(struct scsi_qla_host *vha, struct qla_work_evt *e)
5198 unsigned long flags;
5199 fc_port_t *fcport = NULL, *tfcp;
5200 struct qlt_plogi_ack_t *pla =
5201 (struct qlt_plogi_ack_t *)e->u.new_sess.pla;
5202 uint8_t free_fcport = 0;
5204 ql_dbg(ql_dbg_disc, vha, 0xffff,
5205 "%s %d %8phC enter\n",
5206 __func__, __LINE__, e->u.new_sess.port_name);
5208 spin_lock_irqsave(&vha->hw->tgt.sess_lock, flags);
5209 fcport = qla2x00_find_fcport_by_wwpn(vha, e->u.new_sess.port_name, 1);
5211 fcport->d_id = e->u.new_sess.id;
5213 fcport->fw_login_state = DSC_LS_PLOGI_PEND;
5214 memcpy(fcport->node_name,
5215 pla->iocb.u.isp24.u.plogi.node_name,
5217 qlt_plogi_ack_link(vha, pla, fcport, QLT_PLOGI_LINK_SAME_WWN);
5218 /* we took an extra ref_count to prevent PLOGI ACK when
5219 * fcport/sess has not been created.
5224 spin_unlock_irqrestore(&vha->hw->tgt.sess_lock, flags);
5225 fcport = qla2x00_alloc_fcport(vha, GFP_KERNEL);
5227 fcport->d_id = e->u.new_sess.id;
5228 fcport->flags |= FCF_FABRIC_DEVICE;
5229 fcport->fw_login_state = DSC_LS_PLOGI_PEND;
5230 fcport->tgt_short_link_down_cnt = 0;
5232 memcpy(fcport->port_name, e->u.new_sess.port_name,
5235 fcport->fc4_type = e->u.new_sess.fc4_type;
5236 if (NVME_PRIORITY(vha->hw, fcport))
5237 fcport->do_prli_nvme = 1;
5239 fcport->do_prli_nvme = 0;
5241 if (e->u.new_sess.fc4_type & FS_FCP_IS_N2N) {
5242 fcport->dm_login_expire = jiffies +
5243 QLA_N2N_WAIT_TIME * HZ;
5244 fcport->fc4_type = FS_FC4TYPE_FCP;
5245 fcport->n2n_flag = 1;
5246 if (vha->flags.nvme_enabled)
5247 fcport->fc4_type |= FS_FC4TYPE_NVME;
5251 ql_dbg(ql_dbg_disc, vha, 0xffff,
5252 "%s %8phC mem alloc fail.\n",
5253 __func__, e->u.new_sess.port_name);
5256 list_del(&pla->list);
5257 kmem_cache_free(qla_tgt_plogi_cachep, pla);
5262 spin_lock_irqsave(&vha->hw->tgt.sess_lock, flags);
5263 /* search again to make sure no one else got ahead */
5264 tfcp = qla2x00_find_fcport_by_wwpn(vha,
5265 e->u.new_sess.port_name, 1);
5267 /* should rarily happen */
5268 ql_dbg(ql_dbg_disc, vha, 0xffff,
5269 "%s %8phC found existing fcport b4 add. DS %d LS %d\n",
5270 __func__, tfcp->port_name, tfcp->disc_state,
5271 tfcp->fw_login_state);
5275 list_add_tail(&fcport->list, &vha->vp_fcports);
5279 qlt_plogi_ack_link(vha, pla, fcport,
5280 QLT_PLOGI_LINK_SAME_WWN);
5284 spin_unlock_irqrestore(&vha->hw->tgt.sess_lock, flags);
5287 fcport->id_changed = 1;
5288 fcport->scan_state = QLA_FCPORT_FOUND;
5289 fcport->chip_reset = vha->hw->base_qpair->chip_reset;
5290 memcpy(fcport->node_name, e->u.new_sess.node_name, WWN_SIZE);
5293 if (pla->iocb.u.isp24.status_subcode == ELS_PRLI) {
5296 fcport->fw_login_state = DSC_LS_PRLI_PEND;
5300 pla->iocb.u.isp24.nport_handle);
5301 fcport->fw_login_state = DSC_LS_PRLI_PEND;
5304 pla->iocb.u.isp24.u.prli.wd3_lo);
5307 fcport->conf_compl_supported = 1;
5309 if ((wd3_lo & BIT_4) == 0)
5310 fcport->port_type = FCT_INITIATOR;
5312 fcport->port_type = FCT_TARGET;
5314 qlt_plogi_ack_unref(vha, pla);
5316 fc_port_t *dfcp = NULL;
5318 spin_lock_irqsave(&vha->hw->tgt.sess_lock, flags);
5319 tfcp = qla2x00_find_fcport_by_nportid(vha,
5320 &e->u.new_sess.id, 1);
5321 if (tfcp && (tfcp != fcport)) {
5323 * We have a conflict fcport with same NportID.
5325 ql_dbg(ql_dbg_disc, vha, 0xffff,
5326 "%s %8phC found conflict b4 add. DS %d LS %d\n",
5327 __func__, tfcp->port_name, tfcp->disc_state,
5328 tfcp->fw_login_state);
5330 switch (tfcp->disc_state) {
5333 case DSC_DELETE_PEND:
5334 fcport->login_pause = 1;
5335 tfcp->conflict = fcport;
5338 fcport->login_pause = 1;
5339 tfcp->conflict = fcport;
5344 spin_unlock_irqrestore(&vha->hw->tgt.sess_lock, flags);
5346 qlt_schedule_sess_for_deletion(tfcp);
5348 if (N2N_TOPO(vha->hw)) {
5349 fcport->flags &= ~FCF_FABRIC_DEVICE;
5350 fcport->keep_nport_handle = 1;
5351 if (vha->flags.nvme_enabled) {
5353 (FS_FC4TYPE_NVME | FS_FC4TYPE_FCP);
5354 fcport->n2n_flag = 1;
5356 fcport->fw_login_state = 0;
5358 schedule_delayed_work(&vha->scan.scan_work, 5);
5360 qla24xx_fcport_handle_login(vha, fcport);
5366 qla2x00_free_fcport(fcport);
5368 list_del(&pla->list);
5369 kmem_cache_free(qla_tgt_plogi_cachep, pla);
5374 static void qla_sp_retry(struct scsi_qla_host *vha, struct qla_work_evt *e)
5376 struct srb *sp = e->u.iosb.sp;
5379 rval = qla2x00_start_sp(sp);
5380 if (rval != QLA_SUCCESS) {
5381 ql_dbg(ql_dbg_disc, vha, 0x2043,
5382 "%s: %s: Re-issue IOCB failed (%d).\n",
5383 __func__, sp->name, rval);
5384 qla24xx_sp_unmap(vha, sp);
5389 qla2x00_do_work(struct scsi_qla_host *vha)
5391 struct qla_work_evt *e, *tmp;
5392 unsigned long flags;
5396 spin_lock_irqsave(&vha->work_lock, flags);
5397 list_splice_init(&vha->work_list, &work);
5398 spin_unlock_irqrestore(&vha->work_lock, flags);
5400 list_for_each_entry_safe(e, tmp, &work, list) {
5404 fc_host_post_event(vha->host, fc_get_event_number(),
5405 e->u.aen.code, e->u.aen.data);
5407 case QLA_EVT_IDC_ACK:
5408 qla81xx_idc_ack(vha, e->u.idc_ack.mb);
5410 case QLA_EVT_ASYNC_LOGIN:
5411 qla2x00_async_login(vha, e->u.logio.fcport,
5414 case QLA_EVT_ASYNC_LOGOUT:
5415 rc = qla2x00_async_logout(vha, e->u.logio.fcport);
5417 case QLA_EVT_ASYNC_ADISC:
5418 qla2x00_async_adisc(vha, e->u.logio.fcport,
5421 case QLA_EVT_UEVENT:
5422 qla2x00_uevent_emit(vha, e->u.uevent.code);
5425 qlafx00_process_aen(vha, e);
5428 qla24xx_async_gpnid(vha, &e->u.gpnid.id);
5431 qla24xx_sp_unmap(vha, e->u.iosb.sp);
5433 case QLA_EVT_RELOGIN:
5434 qla2x00_relogin(vha);
5436 case QLA_EVT_NEW_SESS:
5437 qla24xx_create_new_sess(vha, e);
5440 qla24xx_async_gpdb(vha, e->u.fcport.fcport,
5444 qla24xx_async_prli(vha, e->u.fcport.fcport);
5447 qla24xx_async_gpsc(vha, e->u.fcport.fcport);
5450 qla24xx_async_gnl(vha, e->u.fcport.fcport);
5453 qla24xx_do_nack_work(vha, e);
5455 case QLA_EVT_ASYNC_PRLO:
5456 rc = qla2x00_async_prlo(vha, e->u.logio.fcport);
5458 case QLA_EVT_ASYNC_PRLO_DONE:
5459 qla2x00_async_prlo_done(vha, e->u.logio.fcport,
5463 qla24xx_async_gpnft(vha, e->u.gpnft.fc4_type,
5466 case QLA_EVT_GPNFT_DONE:
5467 qla24xx_async_gpnft_done(vha, e->u.iosb.sp);
5469 case QLA_EVT_GNNFT_DONE:
5470 qla24xx_async_gnnft_done(vha, e->u.iosb.sp);
5473 qla24xx_async_gnnid(vha, e->u.fcport.fcport);
5475 case QLA_EVT_GFPNID:
5476 qla24xx_async_gfpnid(vha, e->u.fcport.fcport);
5478 case QLA_EVT_SP_RETRY:
5479 qla_sp_retry(vha, e);
5482 qla_do_iidma_work(vha, e->u.fcport.fcport);
5484 case QLA_EVT_ELS_PLOGI:
5485 qla24xx_els_dcmd2_iocb(vha, ELS_DCMD_PLOGI,
5486 e->u.fcport.fcport, false);
5488 case QLA_EVT_SA_REPLACE:
5489 qla24xx_issue_sa_replace_iocb(vha, e);
5494 /* put 'work' at head of 'vha->work_list' */
5495 spin_lock_irqsave(&vha->work_lock, flags);
5496 list_splice(&work, &vha->work_list);
5497 spin_unlock_irqrestore(&vha->work_lock, flags);
5500 list_del_init(&e->list);
5501 if (e->flags & QLA_EVT_FLAG_FREE)
5504 /* For each work completed decrement vha ref count */
5505 QLA_VHA_MARK_NOT_BUSY(vha);
5509 int qla24xx_post_relogin_work(struct scsi_qla_host *vha)
5511 struct qla_work_evt *e;
5513 e = qla2x00_alloc_work(vha, QLA_EVT_RELOGIN);
5516 set_bit(RELOGIN_NEEDED, &vha->dpc_flags);
5517 return QLA_FUNCTION_FAILED;
5520 return qla2x00_post_work(vha, e);
5523 /* Relogins all the fcports of a vport
5524 * Context: dpc thread
5526 void qla2x00_relogin(struct scsi_qla_host *vha)
5529 int status, relogin_needed = 0;
5530 struct event_arg ea;
5532 list_for_each_entry(fcport, &vha->vp_fcports, list) {
5534 * If the port is not ONLINE then try to login
5535 * to it if we haven't run out of retries.
5537 if (atomic_read(&fcport->state) != FCS_ONLINE &&
5538 fcport->login_retry) {
5539 if (fcport->scan_state != QLA_FCPORT_FOUND ||
5540 fcport->disc_state == DSC_LOGIN_AUTH_PEND ||
5541 fcport->disc_state == DSC_LOGIN_COMPLETE)
5544 if (fcport->flags & (FCF_ASYNC_SENT|FCF_ASYNC_ACTIVE) ||
5545 fcport->disc_state == DSC_DELETE_PEND) {
5548 if (vha->hw->current_topology != ISP_CFG_NL) {
5549 memset(&ea, 0, sizeof(ea));
5551 qla24xx_handle_relogin_event(vha, &ea);
5552 } else if (vha->hw->current_topology ==
5554 fcport->login_retry--;
5556 qla2x00_local_device_login(vha,
5558 if (status == QLA_SUCCESS) {
5559 fcport->old_loop_id =
5561 ql_dbg(ql_dbg_disc, vha, 0x2003,
5562 "Port login OK: logged in ID 0x%x.\n",
5564 qla2x00_update_fcport
5566 } else if (status == 1) {
5567 set_bit(RELOGIN_NEEDED,
5569 /* retry the login again */
5570 ql_dbg(ql_dbg_disc, vha, 0x2007,
5571 "Retrying %d login again loop_id 0x%x.\n",
5572 fcport->login_retry,
5575 fcport->login_retry = 0;
5578 if (fcport->login_retry == 0 &&
5579 status != QLA_SUCCESS)
5580 qla2x00_clear_loop_id(fcport);
5584 if (test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags))
5589 set_bit(RELOGIN_NEEDED, &vha->dpc_flags);
5591 ql_dbg(ql_dbg_disc, vha, 0x400e,
5595 /* Schedule work on any of the dpc-workqueues */
5597 qla83xx_schedule_work(scsi_qla_host_t *base_vha, int work_code)
5599 struct qla_hw_data *ha = base_vha->hw;
5601 switch (work_code) {
5602 case MBA_IDC_AEN: /* 0x8200 */
5604 queue_work(ha->dpc_lp_wq, &ha->idc_aen);
5607 case QLA83XX_NIC_CORE_RESET: /* 0x1 */
5608 if (!ha->flags.nic_core_reset_hdlr_active) {
5610 queue_work(ha->dpc_hp_wq, &ha->nic_core_reset);
5612 ql_dbg(ql_dbg_p3p, base_vha, 0xb05e,
5613 "NIC Core reset is already active. Skip "
5614 "scheduling it again.\n");
5616 case QLA83XX_IDC_STATE_HANDLER: /* 0x2 */
5618 queue_work(ha->dpc_hp_wq, &ha->idc_state_handler);
5620 case QLA83XX_NIC_CORE_UNRECOVERABLE: /* 0x3 */
5622 queue_work(ha->dpc_hp_wq, &ha->nic_core_unrecoverable);
5625 ql_log(ql_log_warn, base_vha, 0xb05f,
5626 "Unknown work-code=0x%x.\n", work_code);
5632 /* Work: Perform NIC Core Unrecoverable state handling */
5634 qla83xx_nic_core_unrecoverable_work(struct work_struct *work)
5636 struct qla_hw_data *ha =
5637 container_of(work, struct qla_hw_data, nic_core_unrecoverable);
5638 scsi_qla_host_t *base_vha = pci_get_drvdata(ha->pdev);
5639 uint32_t dev_state = 0;
5641 qla83xx_idc_lock(base_vha, 0);
5642 qla83xx_rd_reg(base_vha, QLA83XX_IDC_DEV_STATE, &dev_state);
5643 qla83xx_reset_ownership(base_vha);
5644 if (ha->flags.nic_core_reset_owner) {
5645 ha->flags.nic_core_reset_owner = 0;
5646 qla83xx_wr_reg(base_vha, QLA83XX_IDC_DEV_STATE,
5647 QLA8XXX_DEV_FAILED);
5648 ql_log(ql_log_info, base_vha, 0xb060, "HW State: FAILED.\n");
5649 qla83xx_schedule_work(base_vha, QLA83XX_IDC_STATE_HANDLER);
5651 qla83xx_idc_unlock(base_vha, 0);
5654 /* Work: Execute IDC state handler */
5656 qla83xx_idc_state_handler_work(struct work_struct *work)
5658 struct qla_hw_data *ha =
5659 container_of(work, struct qla_hw_data, idc_state_handler);
5660 scsi_qla_host_t *base_vha = pci_get_drvdata(ha->pdev);
5661 uint32_t dev_state = 0;
5663 qla83xx_idc_lock(base_vha, 0);
5664 qla83xx_rd_reg(base_vha, QLA83XX_IDC_DEV_STATE, &dev_state);
5665 if (dev_state == QLA8XXX_DEV_FAILED ||
5666 dev_state == QLA8XXX_DEV_NEED_QUIESCENT)
5667 qla83xx_idc_state_handler(base_vha);
5668 qla83xx_idc_unlock(base_vha, 0);
5672 qla83xx_check_nic_core_fw_alive(scsi_qla_host_t *base_vha)
5674 int rval = QLA_SUCCESS;
5675 unsigned long heart_beat_wait = jiffies + (1 * HZ);
5676 uint32_t heart_beat_counter1, heart_beat_counter2;
5679 if (time_after(jiffies, heart_beat_wait)) {
5680 ql_dbg(ql_dbg_p3p, base_vha, 0xb07c,
5681 "Nic Core f/w is not alive.\n");
5682 rval = QLA_FUNCTION_FAILED;
5686 qla83xx_idc_lock(base_vha, 0);
5687 qla83xx_rd_reg(base_vha, QLA83XX_FW_HEARTBEAT,
5688 &heart_beat_counter1);
5689 qla83xx_idc_unlock(base_vha, 0);
5691 qla83xx_idc_lock(base_vha, 0);
5692 qla83xx_rd_reg(base_vha, QLA83XX_FW_HEARTBEAT,
5693 &heart_beat_counter2);
5694 qla83xx_idc_unlock(base_vha, 0);
5695 } while (heart_beat_counter1 == heart_beat_counter2);
5700 /* Work: Perform NIC Core Reset handling */
5702 qla83xx_nic_core_reset_work(struct work_struct *work)
5704 struct qla_hw_data *ha =
5705 container_of(work, struct qla_hw_data, nic_core_reset);
5706 scsi_qla_host_t *base_vha = pci_get_drvdata(ha->pdev);
5707 uint32_t dev_state = 0;
5709 if (IS_QLA2031(ha)) {
5710 if (qla2xxx_mctp_dump(base_vha) != QLA_SUCCESS)
5711 ql_log(ql_log_warn, base_vha, 0xb081,
5712 "Failed to dump mctp\n");
5716 if (!ha->flags.nic_core_reset_hdlr_active) {
5717 if (qla83xx_check_nic_core_fw_alive(base_vha) == QLA_SUCCESS) {
5718 qla83xx_idc_lock(base_vha, 0);
5719 qla83xx_rd_reg(base_vha, QLA83XX_IDC_DEV_STATE,
5721 qla83xx_idc_unlock(base_vha, 0);
5722 if (dev_state != QLA8XXX_DEV_NEED_RESET) {
5723 ql_dbg(ql_dbg_p3p, base_vha, 0xb07a,
5724 "Nic Core f/w is alive.\n");
5729 ha->flags.nic_core_reset_hdlr_active = 1;
5730 if (qla83xx_nic_core_reset(base_vha)) {
5731 /* NIC Core reset failed. */
5732 ql_dbg(ql_dbg_p3p, base_vha, 0xb061,
5733 "NIC Core reset failed.\n");
5735 ha->flags.nic_core_reset_hdlr_active = 0;
5739 /* Work: Handle 8200 IDC aens */
5741 qla83xx_service_idc_aen(struct work_struct *work)
5743 struct qla_hw_data *ha =
5744 container_of(work, struct qla_hw_data, idc_aen);
5745 scsi_qla_host_t *base_vha = pci_get_drvdata(ha->pdev);
5746 uint32_t dev_state, idc_control;
5748 qla83xx_idc_lock(base_vha, 0);
5749 qla83xx_rd_reg(base_vha, QLA83XX_IDC_DEV_STATE, &dev_state);
5750 qla83xx_rd_reg(base_vha, QLA83XX_IDC_CONTROL, &idc_control);
5751 qla83xx_idc_unlock(base_vha, 0);
5752 if (dev_state == QLA8XXX_DEV_NEED_RESET) {
5753 if (idc_control & QLA83XX_IDC_GRACEFUL_RESET) {
5754 ql_dbg(ql_dbg_p3p, base_vha, 0xb062,
5755 "Application requested NIC Core Reset.\n");
5756 qla83xx_schedule_work(base_vha, QLA83XX_NIC_CORE_RESET);
5757 } else if (qla83xx_check_nic_core_fw_alive(base_vha) ==
5759 ql_dbg(ql_dbg_p3p, base_vha, 0xb07b,
5760 "Other protocol driver requested NIC Core Reset.\n");
5761 qla83xx_schedule_work(base_vha, QLA83XX_NIC_CORE_RESET);
5763 } else if (dev_state == QLA8XXX_DEV_FAILED ||
5764 dev_state == QLA8XXX_DEV_NEED_QUIESCENT) {
5765 qla83xx_schedule_work(base_vha, QLA83XX_IDC_STATE_HANDLER);
5770 * Control the frequency of IDC lock retries
5772 #define QLA83XX_WAIT_LOGIC_MS 100
5775 qla83xx_force_lock_recovery(scsi_qla_host_t *base_vha)
5779 uint32_t idc_lck_rcvry_stage_mask = 0x3;
5780 uint32_t idc_lck_rcvry_owner_mask = 0x3c;
5781 struct qla_hw_data *ha = base_vha->hw;
5783 ql_dbg(ql_dbg_p3p, base_vha, 0xb086,
5784 "Trying force recovery of the IDC lock.\n");
5786 rval = qla83xx_rd_reg(base_vha, QLA83XX_IDC_LOCK_RECOVERY, &data);
5790 if ((data & idc_lck_rcvry_stage_mask) > 0) {
5793 data = (IDC_LOCK_RECOVERY_STAGE1) | (ha->portnum << 2);
5794 rval = qla83xx_wr_reg(base_vha, QLA83XX_IDC_LOCK_RECOVERY,
5801 rval = qla83xx_rd_reg(base_vha, QLA83XX_IDC_LOCK_RECOVERY,
5806 if (((data & idc_lck_rcvry_owner_mask) >> 2) == ha->portnum) {
5807 data &= (IDC_LOCK_RECOVERY_STAGE2 |
5808 ~(idc_lck_rcvry_stage_mask));
5809 rval = qla83xx_wr_reg(base_vha,
5810 QLA83XX_IDC_LOCK_RECOVERY, data);
5814 /* Forcefully perform IDC UnLock */
5815 rval = qla83xx_rd_reg(base_vha, QLA83XX_DRIVER_UNLOCK,
5819 /* Clear lock-id by setting 0xff */
5820 rval = qla83xx_wr_reg(base_vha, QLA83XX_DRIVER_LOCKID,
5824 /* Clear lock-recovery by setting 0x0 */
5825 rval = qla83xx_wr_reg(base_vha,
5826 QLA83XX_IDC_LOCK_RECOVERY, 0x0);
5837 qla83xx_idc_lock_recovery(scsi_qla_host_t *base_vha)
5839 int rval = QLA_SUCCESS;
5840 uint32_t o_drv_lockid, n_drv_lockid;
5841 unsigned long lock_recovery_timeout;
5843 lock_recovery_timeout = jiffies + QLA83XX_MAX_LOCK_RECOVERY_WAIT;
5845 rval = qla83xx_rd_reg(base_vha, QLA83XX_DRIVER_LOCKID, &o_drv_lockid);
5849 /* MAX wait time before forcing IDC Lock recovery = 2 secs */
5850 if (time_after_eq(jiffies, lock_recovery_timeout)) {
5851 if (qla83xx_force_lock_recovery(base_vha) == QLA_SUCCESS)
5854 return QLA_FUNCTION_FAILED;
5857 rval = qla83xx_rd_reg(base_vha, QLA83XX_DRIVER_LOCKID, &n_drv_lockid);
5861 if (o_drv_lockid == n_drv_lockid) {
5862 msleep(QLA83XX_WAIT_LOGIC_MS);
5872 * Context: task, can sleep
5875 qla83xx_idc_lock(scsi_qla_host_t *base_vha, uint16_t requester_id)
5878 uint32_t lock_owner;
5879 struct qla_hw_data *ha = base_vha->hw;
5883 /* IDC-lock implementation using driver-lock/lock-id remote registers */
5885 if (qla83xx_rd_reg(base_vha, QLA83XX_DRIVER_LOCK, &data)
5888 /* Setting lock-id to our function-number */
5889 qla83xx_wr_reg(base_vha, QLA83XX_DRIVER_LOCKID,
5892 qla83xx_rd_reg(base_vha, QLA83XX_DRIVER_LOCKID,
5894 ql_dbg(ql_dbg_p3p, base_vha, 0xb063,
5895 "Failed to acquire IDC lock, acquired by %d, "
5896 "retrying...\n", lock_owner);
5898 /* Retry/Perform IDC-Lock recovery */
5899 if (qla83xx_idc_lock_recovery(base_vha)
5901 msleep(QLA83XX_WAIT_LOGIC_MS);
5904 ql_log(ql_log_warn, base_vha, 0xb075,
5905 "IDC Lock recovery FAILED.\n");
5914 qla25xx_rdp_rsp_reduce_size(struct scsi_qla_host *vha,
5915 struct purex_entry_24xx *purex)
5918 u32 sid = purex->s_id[2] << 16 | purex->s_id[1] << 8 | purex->s_id[0];
5919 struct port_database_24xx *pdb;
5921 /* Domain Controller is always logged-out. */
5922 /* if RDP request is not from Domain Controller: */
5923 if (sid != 0xfffc01)
5926 ql_dbg(ql_dbg_init, vha, 0x0181, "%s: s_id=%#x\n", __func__, sid);
5928 pdb = kzalloc(sizeof(*pdb), GFP_KERNEL);
5930 ql_dbg(ql_dbg_init, vha, 0x0181,
5931 "%s: Failed allocate pdb\n", __func__);
5932 } else if (qla24xx_get_port_database(vha,
5933 le16_to_cpu(purex->nport_handle), pdb)) {
5934 ql_dbg(ql_dbg_init, vha, 0x0181,
5935 "%s: Failed get pdb sid=%x\n", __func__, sid);
5936 } else if (pdb->current_login_state != PDS_PLOGI_COMPLETE &&
5937 pdb->current_login_state != PDS_PRLI_COMPLETE) {
5938 ql_dbg(ql_dbg_init, vha, 0x0181,
5939 "%s: Port not logged in sid=%#x\n", __func__, sid);
5941 /* RDP request is from logged in port */
5947 vha->hw->isp_ops->fw_version_str(vha, fwstr, sizeof(fwstr));
5948 fwstr[strcspn(fwstr, " ")] = 0;
5949 /* if FW version allows RDP response length upto 2048 bytes: */
5950 if (strcmp(fwstr, "8.09.00") > 0 || strcmp(fwstr, "8.05.65") == 0)
5953 ql_dbg(ql_dbg_init, vha, 0x0181, "%s: fw=%s\n", __func__, fwstr);
5955 /* RDP response length is to be reduced to maximum 256 bytes */
5960 * Function Name: qla24xx_process_purex_iocb
5963 * Prepare a RDP response and send to Fabric switch
5966 * vha: SCSI qla host
5967 * purex: RDP request received by HBA
5969 void qla24xx_process_purex_rdp(struct scsi_qla_host *vha,
5970 struct purex_item *item)
5972 struct qla_hw_data *ha = vha->hw;
5973 struct purex_entry_24xx *purex =
5974 (struct purex_entry_24xx *)&item->iocb;
5975 dma_addr_t rsp_els_dma;
5976 dma_addr_t rsp_payload_dma;
5977 dma_addr_t stat_dma;
5979 struct els_entry_24xx *rsp_els = NULL;
5980 struct rdp_rsp_payload *rsp_payload = NULL;
5981 struct link_statistics *stat = NULL;
5982 uint8_t *sfp = NULL;
5983 uint16_t sfp_flags = 0;
5984 uint rsp_payload_length = sizeof(*rsp_payload);
5987 ql_dbg(ql_dbg_init + ql_dbg_verbose, vha, 0x0180,
5988 "%s: Enter\n", __func__);
5990 ql_dbg(ql_dbg_init + ql_dbg_verbose, vha, 0x0181,
5991 "-------- ELS REQ -------\n");
5992 ql_dump_buffer(ql_dbg_init + ql_dbg_verbose, vha, 0x0182,
5993 purex, sizeof(*purex));
5995 if (qla25xx_rdp_rsp_reduce_size(vha, purex)) {
5996 rsp_payload_length =
5997 offsetof(typeof(*rsp_payload), optical_elmt_desc);
5998 ql_dbg(ql_dbg_init, vha, 0x0181,
5999 "Reducing RSP payload length to %u bytes...\n",
6000 rsp_payload_length);
6003 rsp_els = dma_alloc_coherent(&ha->pdev->dev, sizeof(*rsp_els),
6004 &rsp_els_dma, GFP_KERNEL);
6006 ql_log(ql_log_warn, vha, 0x0183,
6007 "Failed allocate dma buffer ELS RSP.\n");
6011 rsp_payload = dma_alloc_coherent(&ha->pdev->dev, sizeof(*rsp_payload),
6012 &rsp_payload_dma, GFP_KERNEL);
6014 ql_log(ql_log_warn, vha, 0x0184,
6015 "Failed allocate dma buffer ELS RSP payload.\n");
6019 sfp = dma_alloc_coherent(&ha->pdev->dev, SFP_RTDI_LEN,
6020 &sfp_dma, GFP_KERNEL);
6022 stat = dma_alloc_coherent(&ha->pdev->dev, sizeof(*stat),
6023 &stat_dma, GFP_KERNEL);
6025 /* Prepare Response IOCB */
6026 rsp_els->entry_type = ELS_IOCB_TYPE;
6027 rsp_els->entry_count = 1;
6028 rsp_els->sys_define = 0;
6029 rsp_els->entry_status = 0;
6030 rsp_els->handle = 0;
6031 rsp_els->nport_handle = purex->nport_handle;
6032 rsp_els->tx_dsd_count = cpu_to_le16(1);
6033 rsp_els->vp_index = purex->vp_idx;
6034 rsp_els->sof_type = EST_SOFI3;
6035 rsp_els->rx_xchg_address = purex->rx_xchg_addr;
6036 rsp_els->rx_dsd_count = 0;
6037 rsp_els->opcode = purex->els_frame_payload[0];
6039 rsp_els->d_id[0] = purex->s_id[0];
6040 rsp_els->d_id[1] = purex->s_id[1];
6041 rsp_els->d_id[2] = purex->s_id[2];
6043 rsp_els->control_flags = cpu_to_le16(EPD_ELS_ACC);
6044 rsp_els->rx_byte_count = 0;
6045 rsp_els->tx_byte_count = cpu_to_le32(rsp_payload_length);
6047 put_unaligned_le64(rsp_payload_dma, &rsp_els->tx_address);
6048 rsp_els->tx_len = rsp_els->tx_byte_count;
6050 rsp_els->rx_address = 0;
6051 rsp_els->rx_len = 0;
6053 /* Prepare Response Payload */
6054 rsp_payload->hdr.cmd = cpu_to_be32(0x2 << 24); /* LS_ACC */
6055 rsp_payload->hdr.len = cpu_to_be32(le32_to_cpu(rsp_els->tx_byte_count) -
6056 sizeof(rsp_payload->hdr));
6058 /* Link service Request Info Descriptor */
6059 rsp_payload->ls_req_info_desc.desc_tag = cpu_to_be32(0x1);
6060 rsp_payload->ls_req_info_desc.desc_len =
6061 cpu_to_be32(RDP_DESC_LEN(rsp_payload->ls_req_info_desc));
6062 rsp_payload->ls_req_info_desc.req_payload_word_0 =
6063 cpu_to_be32p((uint32_t *)purex->els_frame_payload);
6065 /* Link service Request Info Descriptor 2 */
6066 rsp_payload->ls_req_info_desc2.desc_tag = cpu_to_be32(0x1);
6067 rsp_payload->ls_req_info_desc2.desc_len =
6068 cpu_to_be32(RDP_DESC_LEN(rsp_payload->ls_req_info_desc2));
6069 rsp_payload->ls_req_info_desc2.req_payload_word_0 =
6070 cpu_to_be32p((uint32_t *)purex->els_frame_payload);
6073 rsp_payload->sfp_diag_desc.desc_tag = cpu_to_be32(0x10000);
6074 rsp_payload->sfp_diag_desc.desc_len =
6075 cpu_to_be32(RDP_DESC_LEN(rsp_payload->sfp_diag_desc));
6079 memset(sfp, 0, SFP_RTDI_LEN);
6080 rval = qla2x00_read_sfp(vha, sfp_dma, sfp, 0xa0, 0x7, 2, 0);
6082 /* SFP Flags bits 3-0: Port Tx Laser Type */
6083 if (sfp[0] & BIT_2 || sfp[1] & (BIT_6|BIT_5))
6084 sfp_flags |= BIT_0; /* short wave */
6085 else if (sfp[0] & BIT_1)
6086 sfp_flags |= BIT_1; /* long wave 1310nm */
6087 else if (sfp[1] & BIT_4)
6088 sfp_flags |= BIT_1|BIT_0; /* long wave 1550nm */
6092 memset(sfp, 0, SFP_RTDI_LEN);
6093 rval = qla2x00_read_sfp(vha, sfp_dma, sfp, 0xa0, 0x0, 1, 0);
6095 sfp_flags |= BIT_4; /* optical */
6097 sfp_flags |= BIT_6; /* sfp+ */
6100 rsp_payload->sfp_diag_desc.sfp_flags = cpu_to_be16(sfp_flags);
6102 /* SFP Diagnostics */
6103 memset(sfp, 0, SFP_RTDI_LEN);
6104 rval = qla2x00_read_sfp(vha, sfp_dma, sfp, 0xa2, 0x60, 10, 0);
6106 __be16 *trx = (__force __be16 *)sfp; /* already be16 */
6107 rsp_payload->sfp_diag_desc.temperature = trx[0];
6108 rsp_payload->sfp_diag_desc.vcc = trx[1];
6109 rsp_payload->sfp_diag_desc.tx_bias = trx[2];
6110 rsp_payload->sfp_diag_desc.tx_power = trx[3];
6111 rsp_payload->sfp_diag_desc.rx_power = trx[4];
6115 /* Port Speed Descriptor */
6116 rsp_payload->port_speed_desc.desc_tag = cpu_to_be32(0x10001);
6117 rsp_payload->port_speed_desc.desc_len =
6118 cpu_to_be32(RDP_DESC_LEN(rsp_payload->port_speed_desc));
6119 rsp_payload->port_speed_desc.speed_capab = cpu_to_be16(
6120 qla25xx_fdmi_port_speed_capability(ha));
6121 rsp_payload->port_speed_desc.operating_speed = cpu_to_be16(
6122 qla25xx_fdmi_port_speed_currently(ha));
6124 /* Link Error Status Descriptor */
6125 rsp_payload->ls_err_desc.desc_tag = cpu_to_be32(0x10002);
6126 rsp_payload->ls_err_desc.desc_len =
6127 cpu_to_be32(RDP_DESC_LEN(rsp_payload->ls_err_desc));
6130 rval = qla24xx_get_isp_stats(vha, stat, stat_dma, 0);
6132 rsp_payload->ls_err_desc.link_fail_cnt =
6133 cpu_to_be32(le32_to_cpu(stat->link_fail_cnt));
6134 rsp_payload->ls_err_desc.loss_sync_cnt =
6135 cpu_to_be32(le32_to_cpu(stat->loss_sync_cnt));
6136 rsp_payload->ls_err_desc.loss_sig_cnt =
6137 cpu_to_be32(le32_to_cpu(stat->loss_sig_cnt));
6138 rsp_payload->ls_err_desc.prim_seq_err_cnt =
6139 cpu_to_be32(le32_to_cpu(stat->prim_seq_err_cnt));
6140 rsp_payload->ls_err_desc.inval_xmit_word_cnt =
6141 cpu_to_be32(le32_to_cpu(stat->inval_xmit_word_cnt));
6142 rsp_payload->ls_err_desc.inval_crc_cnt =
6143 cpu_to_be32(le32_to_cpu(stat->inval_crc_cnt));
6144 rsp_payload->ls_err_desc.pn_port_phy_type |= BIT_6;
6148 /* Portname Descriptor */
6149 rsp_payload->port_name_diag_desc.desc_tag = cpu_to_be32(0x10003);
6150 rsp_payload->port_name_diag_desc.desc_len =
6151 cpu_to_be32(RDP_DESC_LEN(rsp_payload->port_name_diag_desc));
6152 memcpy(rsp_payload->port_name_diag_desc.WWNN,
6154 sizeof(rsp_payload->port_name_diag_desc.WWNN));
6155 memcpy(rsp_payload->port_name_diag_desc.WWPN,
6157 sizeof(rsp_payload->port_name_diag_desc.WWPN));
6159 /* F-Port Portname Descriptor */
6160 rsp_payload->port_name_direct_desc.desc_tag = cpu_to_be32(0x10003);
6161 rsp_payload->port_name_direct_desc.desc_len =
6162 cpu_to_be32(RDP_DESC_LEN(rsp_payload->port_name_direct_desc));
6163 memcpy(rsp_payload->port_name_direct_desc.WWNN,
6164 vha->fabric_node_name,
6165 sizeof(rsp_payload->port_name_direct_desc.WWNN));
6166 memcpy(rsp_payload->port_name_direct_desc.WWPN,
6167 vha->fabric_port_name,
6168 sizeof(rsp_payload->port_name_direct_desc.WWPN));
6170 /* Bufer Credit Descriptor */
6171 rsp_payload->buffer_credit_desc.desc_tag = cpu_to_be32(0x10006);
6172 rsp_payload->buffer_credit_desc.desc_len =
6173 cpu_to_be32(RDP_DESC_LEN(rsp_payload->buffer_credit_desc));
6174 rsp_payload->buffer_credit_desc.fcport_b2b = 0;
6175 rsp_payload->buffer_credit_desc.attached_fcport_b2b = cpu_to_be32(0);
6176 rsp_payload->buffer_credit_desc.fcport_rtt = cpu_to_be32(0);
6178 if (ha->flags.plogi_template_valid) {
6180 be16_to_cpu(ha->plogi_els_payld.fl_csp.sp_bb_cred);
6181 rsp_payload->buffer_credit_desc.fcport_b2b = cpu_to_be32(tmp);
6184 if (rsp_payload_length < sizeof(*rsp_payload))
6187 /* Optical Element Descriptor, Temperature */
6188 rsp_payload->optical_elmt_desc[0].desc_tag = cpu_to_be32(0x10007);
6189 rsp_payload->optical_elmt_desc[0].desc_len =
6190 cpu_to_be32(RDP_DESC_LEN(*rsp_payload->optical_elmt_desc));
6191 /* Optical Element Descriptor, Voltage */
6192 rsp_payload->optical_elmt_desc[1].desc_tag = cpu_to_be32(0x10007);
6193 rsp_payload->optical_elmt_desc[1].desc_len =
6194 cpu_to_be32(RDP_DESC_LEN(*rsp_payload->optical_elmt_desc));
6195 /* Optical Element Descriptor, Tx Bias Current */
6196 rsp_payload->optical_elmt_desc[2].desc_tag = cpu_to_be32(0x10007);
6197 rsp_payload->optical_elmt_desc[2].desc_len =
6198 cpu_to_be32(RDP_DESC_LEN(*rsp_payload->optical_elmt_desc));
6199 /* Optical Element Descriptor, Tx Power */
6200 rsp_payload->optical_elmt_desc[3].desc_tag = cpu_to_be32(0x10007);
6201 rsp_payload->optical_elmt_desc[3].desc_len =
6202 cpu_to_be32(RDP_DESC_LEN(*rsp_payload->optical_elmt_desc));
6203 /* Optical Element Descriptor, Rx Power */
6204 rsp_payload->optical_elmt_desc[4].desc_tag = cpu_to_be32(0x10007);
6205 rsp_payload->optical_elmt_desc[4].desc_len =
6206 cpu_to_be32(RDP_DESC_LEN(*rsp_payload->optical_elmt_desc));
6209 memset(sfp, 0, SFP_RTDI_LEN);
6210 rval = qla2x00_read_sfp(vha, sfp_dma, sfp, 0xa2, 0, 64, 0);
6212 __be16 *trx = (__force __be16 *)sfp; /* already be16 */
6214 /* Optical Element Descriptor, Temperature */
6215 rsp_payload->optical_elmt_desc[0].high_alarm = trx[0];
6216 rsp_payload->optical_elmt_desc[0].low_alarm = trx[1];
6217 rsp_payload->optical_elmt_desc[0].high_warn = trx[2];
6218 rsp_payload->optical_elmt_desc[0].low_warn = trx[3];
6219 rsp_payload->optical_elmt_desc[0].element_flags =
6220 cpu_to_be32(1 << 28);
6222 /* Optical Element Descriptor, Voltage */
6223 rsp_payload->optical_elmt_desc[1].high_alarm = trx[4];
6224 rsp_payload->optical_elmt_desc[1].low_alarm = trx[5];
6225 rsp_payload->optical_elmt_desc[1].high_warn = trx[6];
6226 rsp_payload->optical_elmt_desc[1].low_warn = trx[7];
6227 rsp_payload->optical_elmt_desc[1].element_flags =
6228 cpu_to_be32(2 << 28);
6230 /* Optical Element Descriptor, Tx Bias Current */
6231 rsp_payload->optical_elmt_desc[2].high_alarm = trx[8];
6232 rsp_payload->optical_elmt_desc[2].low_alarm = trx[9];
6233 rsp_payload->optical_elmt_desc[2].high_warn = trx[10];
6234 rsp_payload->optical_elmt_desc[2].low_warn = trx[11];
6235 rsp_payload->optical_elmt_desc[2].element_flags =
6236 cpu_to_be32(3 << 28);
6238 /* Optical Element Descriptor, Tx Power */
6239 rsp_payload->optical_elmt_desc[3].high_alarm = trx[12];
6240 rsp_payload->optical_elmt_desc[3].low_alarm = trx[13];
6241 rsp_payload->optical_elmt_desc[3].high_warn = trx[14];
6242 rsp_payload->optical_elmt_desc[3].low_warn = trx[15];
6243 rsp_payload->optical_elmt_desc[3].element_flags =
6244 cpu_to_be32(4 << 28);
6246 /* Optical Element Descriptor, Rx Power */
6247 rsp_payload->optical_elmt_desc[4].high_alarm = trx[16];
6248 rsp_payload->optical_elmt_desc[4].low_alarm = trx[17];
6249 rsp_payload->optical_elmt_desc[4].high_warn = trx[18];
6250 rsp_payload->optical_elmt_desc[4].low_warn = trx[19];
6251 rsp_payload->optical_elmt_desc[4].element_flags =
6252 cpu_to_be32(5 << 28);
6255 memset(sfp, 0, SFP_RTDI_LEN);
6256 rval = qla2x00_read_sfp(vha, sfp_dma, sfp, 0xa2, 112, 64, 0);
6258 /* Temperature high/low alarm/warning */
6259 rsp_payload->optical_elmt_desc[0].element_flags |=
6261 (sfp[0] >> 7 & 1) << 3 |
6262 (sfp[0] >> 6 & 1) << 2 |
6263 (sfp[4] >> 7 & 1) << 1 |
6264 (sfp[4] >> 6 & 1) << 0);
6266 /* Voltage high/low alarm/warning */
6267 rsp_payload->optical_elmt_desc[1].element_flags |=
6269 (sfp[0] >> 5 & 1) << 3 |
6270 (sfp[0] >> 4 & 1) << 2 |
6271 (sfp[4] >> 5 & 1) << 1 |
6272 (sfp[4] >> 4 & 1) << 0);
6274 /* Tx Bias Current high/low alarm/warning */
6275 rsp_payload->optical_elmt_desc[2].element_flags |=
6277 (sfp[0] >> 3 & 1) << 3 |
6278 (sfp[0] >> 2 & 1) << 2 |
6279 (sfp[4] >> 3 & 1) << 1 |
6280 (sfp[4] >> 2 & 1) << 0);
6282 /* Tx Power high/low alarm/warning */
6283 rsp_payload->optical_elmt_desc[3].element_flags |=
6285 (sfp[0] >> 1 & 1) << 3 |
6286 (sfp[0] >> 0 & 1) << 2 |
6287 (sfp[4] >> 1 & 1) << 1 |
6288 (sfp[4] >> 0 & 1) << 0);
6290 /* Rx Power high/low alarm/warning */
6291 rsp_payload->optical_elmt_desc[4].element_flags |=
6293 (sfp[1] >> 7 & 1) << 3 |
6294 (sfp[1] >> 6 & 1) << 2 |
6295 (sfp[5] >> 7 & 1) << 1 |
6296 (sfp[5] >> 6 & 1) << 0);
6300 /* Optical Product Data Descriptor */
6301 rsp_payload->optical_prod_desc.desc_tag = cpu_to_be32(0x10008);
6302 rsp_payload->optical_prod_desc.desc_len =
6303 cpu_to_be32(RDP_DESC_LEN(rsp_payload->optical_prod_desc));
6306 memset(sfp, 0, SFP_RTDI_LEN);
6307 rval = qla2x00_read_sfp(vha, sfp_dma, sfp, 0xa0, 20, 64, 0);
6309 memcpy(rsp_payload->optical_prod_desc.vendor_name,
6311 sizeof(rsp_payload->optical_prod_desc.vendor_name));
6312 memcpy(rsp_payload->optical_prod_desc.part_number,
6314 sizeof(rsp_payload->optical_prod_desc.part_number));
6315 memcpy(rsp_payload->optical_prod_desc.revision,
6317 sizeof(rsp_payload->optical_prod_desc.revision));
6318 memcpy(rsp_payload->optical_prod_desc.serial_number,
6320 sizeof(rsp_payload->optical_prod_desc.serial_number));
6323 memset(sfp, 0, SFP_RTDI_LEN);
6324 rval = qla2x00_read_sfp(vha, sfp_dma, sfp, 0xa0, 84, 8, 0);
6326 memcpy(rsp_payload->optical_prod_desc.date,
6328 sizeof(rsp_payload->optical_prod_desc.date));
6333 ql_dbg(ql_dbg_init, vha, 0x0183,
6334 "Sending ELS Response to RDP Request...\n");
6335 ql_dbg(ql_dbg_init + ql_dbg_verbose, vha, 0x0184,
6336 "-------- ELS RSP -------\n");
6337 ql_dump_buffer(ql_dbg_init + ql_dbg_verbose, vha, 0x0185,
6338 rsp_els, sizeof(*rsp_els));
6339 ql_dbg(ql_dbg_init + ql_dbg_verbose, vha, 0x0186,
6340 "-------- ELS RSP PAYLOAD -------\n");
6341 ql_dump_buffer(ql_dbg_init + ql_dbg_verbose, vha, 0x0187,
6342 rsp_payload, rsp_payload_length);
6344 rval = qla2x00_issue_iocb(vha, rsp_els, rsp_els_dma, 0);
6347 ql_log(ql_log_warn, vha, 0x0188,
6348 "%s: iocb failed to execute -> %x\n", __func__, rval);
6349 } else if (rsp_els->comp_status) {
6350 ql_log(ql_log_warn, vha, 0x0189,
6351 "%s: iocb failed to complete -> completion=%#x subcode=(%#x,%#x)\n",
6352 __func__, rsp_els->comp_status,
6353 rsp_els->error_subcode_1, rsp_els->error_subcode_2);
6355 ql_dbg(ql_dbg_init, vha, 0x018a, "%s: done.\n", __func__);
6360 dma_free_coherent(&ha->pdev->dev, sizeof(*stat),
6363 dma_free_coherent(&ha->pdev->dev, SFP_RTDI_LEN,
6366 dma_free_coherent(&ha->pdev->dev, sizeof(*rsp_payload),
6367 rsp_payload, rsp_payload_dma);
6369 dma_free_coherent(&ha->pdev->dev, sizeof(*rsp_els),
6370 rsp_els, rsp_els_dma);
6374 qla24xx_free_purex_item(struct purex_item *item)
6376 if (item == &item->vha->default_item)
6377 memset(&item->vha->default_item, 0, sizeof(struct purex_item));
6382 void qla24xx_process_purex_list(struct purex_list *list)
6384 struct list_head head = LIST_HEAD_INIT(head);
6385 struct purex_item *item, *next;
6388 spin_lock_irqsave(&list->lock, flags);
6389 list_splice_init(&list->head, &head);
6390 spin_unlock_irqrestore(&list->lock, flags);
6392 list_for_each_entry_safe(item, next, &head, list) {
6393 list_del(&item->list);
6394 item->process_item(item->vha, item);
6395 qla24xx_free_purex_item(item);
6400 * Context: task, can sleep
6403 qla83xx_idc_unlock(scsi_qla_host_t *base_vha, uint16_t requester_id)
6406 uint16_t options = (requester_id << 15) | BIT_7;
6410 struct qla_hw_data *ha = base_vha->hw;
6414 /* IDC-unlock implementation using driver-unlock/lock-id
6419 if (qla83xx_rd_reg(base_vha, QLA83XX_DRIVER_LOCKID, &data)
6421 if (data == ha->portnum) {
6422 qla83xx_rd_reg(base_vha, QLA83XX_DRIVER_UNLOCK, &data);
6423 /* Clearing lock-id by setting 0xff */
6424 qla83xx_wr_reg(base_vha, QLA83XX_DRIVER_LOCKID, 0xff);
6425 } else if (retry < 10) {
6426 /* SV: XXX: IDC unlock retrying needed here? */
6428 /* Retry for IDC-unlock */
6429 msleep(QLA83XX_WAIT_LOGIC_MS);
6431 ql_dbg(ql_dbg_p3p, base_vha, 0xb064,
6432 "Failed to release IDC lock, retrying=%d\n", retry);
6435 } else if (retry < 10) {
6436 /* Retry for IDC-unlock */
6437 msleep(QLA83XX_WAIT_LOGIC_MS);
6439 ql_dbg(ql_dbg_p3p, base_vha, 0xb065,
6440 "Failed to read drv-lockid, retrying=%d\n", retry);
6447 /* XXX: IDC-unlock implementation using access-control mbx */
6450 if (qla83xx_access_control(base_vha, options, 0, 0, NULL)) {
6452 /* Retry for IDC-unlock */
6453 msleep(QLA83XX_WAIT_LOGIC_MS);
6455 ql_dbg(ql_dbg_p3p, base_vha, 0xb066,
6456 "Failed to release IDC lock, retrying=%d\n", retry);
6466 __qla83xx_set_drv_presence(scsi_qla_host_t *vha)
6468 int rval = QLA_SUCCESS;
6469 struct qla_hw_data *ha = vha->hw;
6470 uint32_t drv_presence;
6472 rval = qla83xx_rd_reg(vha, QLA83XX_IDC_DRV_PRESENCE, &drv_presence);
6473 if (rval == QLA_SUCCESS) {
6474 drv_presence |= (1 << ha->portnum);
6475 rval = qla83xx_wr_reg(vha, QLA83XX_IDC_DRV_PRESENCE,
6483 qla83xx_set_drv_presence(scsi_qla_host_t *vha)
6485 int rval = QLA_SUCCESS;
6487 qla83xx_idc_lock(vha, 0);
6488 rval = __qla83xx_set_drv_presence(vha);
6489 qla83xx_idc_unlock(vha, 0);
6495 __qla83xx_clear_drv_presence(scsi_qla_host_t *vha)
6497 int rval = QLA_SUCCESS;
6498 struct qla_hw_data *ha = vha->hw;
6499 uint32_t drv_presence;
6501 rval = qla83xx_rd_reg(vha, QLA83XX_IDC_DRV_PRESENCE, &drv_presence);
6502 if (rval == QLA_SUCCESS) {
6503 drv_presence &= ~(1 << ha->portnum);
6504 rval = qla83xx_wr_reg(vha, QLA83XX_IDC_DRV_PRESENCE,
6512 qla83xx_clear_drv_presence(scsi_qla_host_t *vha)
6514 int rval = QLA_SUCCESS;
6516 qla83xx_idc_lock(vha, 0);
6517 rval = __qla83xx_clear_drv_presence(vha);
6518 qla83xx_idc_unlock(vha, 0);
6524 qla83xx_need_reset_handler(scsi_qla_host_t *vha)
6526 struct qla_hw_data *ha = vha->hw;
6527 uint32_t drv_ack, drv_presence;
6528 unsigned long ack_timeout;
6530 /* Wait for IDC ACK from all functions (DRV-ACK == DRV-PRESENCE) */
6531 ack_timeout = jiffies + (ha->fcoe_reset_timeout * HZ);
6533 qla83xx_rd_reg(vha, QLA83XX_IDC_DRIVER_ACK, &drv_ack);
6534 qla83xx_rd_reg(vha, QLA83XX_IDC_DRV_PRESENCE, &drv_presence);
6535 if ((drv_ack & drv_presence) == drv_presence)
6538 if (time_after_eq(jiffies, ack_timeout)) {
6539 ql_log(ql_log_warn, vha, 0xb067,
6540 "RESET ACK TIMEOUT! drv_presence=0x%x "
6541 "drv_ack=0x%x\n", drv_presence, drv_ack);
6543 * The function(s) which did not ack in time are forced
6544 * to withdraw any further participation in the IDC
6547 if (drv_ack != drv_presence)
6548 qla83xx_wr_reg(vha, QLA83XX_IDC_DRV_PRESENCE,
6553 qla83xx_idc_unlock(vha, 0);
6555 qla83xx_idc_lock(vha, 0);
6558 qla83xx_wr_reg(vha, QLA83XX_IDC_DEV_STATE, QLA8XXX_DEV_COLD);
6559 ql_log(ql_log_info, vha, 0xb068, "HW State: COLD/RE-INIT.\n");
6563 qla83xx_device_bootstrap(scsi_qla_host_t *vha)
6565 int rval = QLA_SUCCESS;
6566 uint32_t idc_control;
6568 qla83xx_wr_reg(vha, QLA83XX_IDC_DEV_STATE, QLA8XXX_DEV_INITIALIZING);
6569 ql_log(ql_log_info, vha, 0xb069, "HW State: INITIALIZING.\n");
6571 /* Clearing IDC-Control Graceful-Reset Bit before resetting f/w */
6572 __qla83xx_get_idc_control(vha, &idc_control);
6573 idc_control &= ~QLA83XX_IDC_GRACEFUL_RESET;
6574 __qla83xx_set_idc_control(vha, 0);
6576 qla83xx_idc_unlock(vha, 0);
6577 rval = qla83xx_restart_nic_firmware(vha);
6578 qla83xx_idc_lock(vha, 0);
6580 if (rval != QLA_SUCCESS) {
6581 ql_log(ql_log_fatal, vha, 0xb06a,
6582 "Failed to restart NIC f/w.\n");
6583 qla83xx_wr_reg(vha, QLA83XX_IDC_DEV_STATE, QLA8XXX_DEV_FAILED);
6584 ql_log(ql_log_info, vha, 0xb06b, "HW State: FAILED.\n");
6586 ql_dbg(ql_dbg_p3p, vha, 0xb06c,
6587 "Success in restarting nic f/w.\n");
6588 qla83xx_wr_reg(vha, QLA83XX_IDC_DEV_STATE, QLA8XXX_DEV_READY);
6589 ql_log(ql_log_info, vha, 0xb06d, "HW State: READY.\n");
6595 /* Assumes idc_lock always held on entry */
6597 qla83xx_idc_state_handler(scsi_qla_host_t *base_vha)
6599 struct qla_hw_data *ha = base_vha->hw;
6600 int rval = QLA_SUCCESS;
6601 unsigned long dev_init_timeout;
6604 /* Wait for MAX-INIT-TIMEOUT for the device to go ready */
6605 dev_init_timeout = jiffies + (ha->fcoe_dev_init_timeout * HZ);
6609 if (time_after_eq(jiffies, dev_init_timeout)) {
6610 ql_log(ql_log_warn, base_vha, 0xb06e,
6611 "Initialization TIMEOUT!\n");
6612 /* Init timeout. Disable further NIC Core
6615 qla83xx_wr_reg(base_vha, QLA83XX_IDC_DEV_STATE,
6616 QLA8XXX_DEV_FAILED);
6617 ql_log(ql_log_info, base_vha, 0xb06f,
6618 "HW State: FAILED.\n");
6621 qla83xx_rd_reg(base_vha, QLA83XX_IDC_DEV_STATE, &dev_state);
6622 switch (dev_state) {
6623 case QLA8XXX_DEV_READY:
6624 if (ha->flags.nic_core_reset_owner)
6625 qla83xx_idc_audit(base_vha,
6626 IDC_AUDIT_COMPLETION);
6627 ha->flags.nic_core_reset_owner = 0;
6628 ql_dbg(ql_dbg_p3p, base_vha, 0xb070,
6629 "Reset_owner reset by 0x%x.\n",
6632 case QLA8XXX_DEV_COLD:
6633 if (ha->flags.nic_core_reset_owner)
6634 rval = qla83xx_device_bootstrap(base_vha);
6636 /* Wait for AEN to change device-state */
6637 qla83xx_idc_unlock(base_vha, 0);
6639 qla83xx_idc_lock(base_vha, 0);
6642 case QLA8XXX_DEV_INITIALIZING:
6643 /* Wait for AEN to change device-state */
6644 qla83xx_idc_unlock(base_vha, 0);
6646 qla83xx_idc_lock(base_vha, 0);
6648 case QLA8XXX_DEV_NEED_RESET:
6649 if (!ql2xdontresethba && ha->flags.nic_core_reset_owner)
6650 qla83xx_need_reset_handler(base_vha);
6652 /* Wait for AEN to change device-state */
6653 qla83xx_idc_unlock(base_vha, 0);
6655 qla83xx_idc_lock(base_vha, 0);
6657 /* reset timeout value after need reset handler */
6658 dev_init_timeout = jiffies +
6659 (ha->fcoe_dev_init_timeout * HZ);
6661 case QLA8XXX_DEV_NEED_QUIESCENT:
6662 /* XXX: DEBUG for now */
6663 qla83xx_idc_unlock(base_vha, 0);
6665 qla83xx_idc_lock(base_vha, 0);
6667 case QLA8XXX_DEV_QUIESCENT:
6668 /* XXX: DEBUG for now */
6669 if (ha->flags.quiesce_owner)
6672 qla83xx_idc_unlock(base_vha, 0);
6674 qla83xx_idc_lock(base_vha, 0);
6675 dev_init_timeout = jiffies +
6676 (ha->fcoe_dev_init_timeout * HZ);
6678 case QLA8XXX_DEV_FAILED:
6679 if (ha->flags.nic_core_reset_owner)
6680 qla83xx_idc_audit(base_vha,
6681 IDC_AUDIT_COMPLETION);
6682 ha->flags.nic_core_reset_owner = 0;
6683 __qla83xx_clear_drv_presence(base_vha);
6684 qla83xx_idc_unlock(base_vha, 0);
6685 qla8xxx_dev_failed_handler(base_vha);
6686 rval = QLA_FUNCTION_FAILED;
6687 qla83xx_idc_lock(base_vha, 0);
6689 case QLA8XXX_BAD_VALUE:
6690 qla83xx_idc_unlock(base_vha, 0);
6692 qla83xx_idc_lock(base_vha, 0);
6695 ql_log(ql_log_warn, base_vha, 0xb071,
6696 "Unknown Device State: %x.\n", dev_state);
6697 qla83xx_idc_unlock(base_vha, 0);
6698 qla8xxx_dev_failed_handler(base_vha);
6699 rval = QLA_FUNCTION_FAILED;
6700 qla83xx_idc_lock(base_vha, 0);
6710 qla2x00_disable_board_on_pci_error(struct work_struct *work)
6712 struct qla_hw_data *ha = container_of(work, struct qla_hw_data,
6714 struct pci_dev *pdev = ha->pdev;
6715 scsi_qla_host_t *base_vha = pci_get_drvdata(ha->pdev);
6717 ql_log(ql_log_warn, base_vha, 0x015b,
6718 "Disabling adapter.\n");
6720 if (!atomic_read(&pdev->enable_cnt)) {
6721 ql_log(ql_log_info, base_vha, 0xfffc,
6722 "PCI device disabled, no action req for PCI error=%lx\n",
6723 base_vha->pci_flags);
6728 * if UNLOADING flag is already set, then continue unload,
6729 * where it was set first.
6731 if (test_and_set_bit(UNLOADING, &base_vha->dpc_flags))
6734 qla2x00_wait_for_sess_deletion(base_vha);
6736 qla2x00_delete_all_vps(ha, base_vha);
6738 qla2x00_abort_all_cmds(base_vha, DID_NO_CONNECT << 16);
6740 qla2x00_dfs_remove(base_vha);
6742 qla84xx_put_chip(base_vha);
6744 if (base_vha->timer_active)
6745 qla2x00_stop_timer(base_vha);
6747 base_vha->flags.online = 0;
6749 qla2x00_destroy_deferred_work(ha);
6752 * Do not try to stop beacon blink as it will issue a mailbox
6755 qla2x00_free_sysfs_attr(base_vha, false);
6757 fc_remove_host(base_vha->host);
6759 scsi_remove_host(base_vha->host);
6761 base_vha->flags.init_done = 0;
6762 qla25xx_delete_queues(base_vha);
6763 qla2x00_free_fcports(base_vha);
6764 qla2x00_free_irqs(base_vha);
6765 qla2x00_mem_free(ha);
6766 qla82xx_md_free(base_vha);
6767 qla2x00_free_queues(ha);
6769 qla2x00_unmap_iobases(ha);
6771 pci_release_selected_regions(ha->pdev, ha->bars);
6772 pci_disable_pcie_error_reporting(pdev);
6773 pci_disable_device(pdev);
6776 * Let qla2x00_remove_one cleanup qla_hw_data on device removal.
6780 /**************************************************************************
6782 * This kernel thread is a task that is schedule by the interrupt handler
6783 * to perform the background processing for interrupts.
6786 * This task always run in the context of a kernel thread. It
6787 * is kick-off by the driver's detect code and starts up
6788 * up one per adapter. It immediately goes to sleep and waits for
6789 * some fibre event. When either the interrupt handler or
6790 * the timer routine detects a event it will one of the task
6791 * bits then wake us up.
6792 **************************************************************************/
6794 qla2x00_do_dpc(void *data)
6796 scsi_qla_host_t *base_vha;
6797 struct qla_hw_data *ha;
6799 struct qla_qpair *qpair;
6801 ha = (struct qla_hw_data *)data;
6802 base_vha = pci_get_drvdata(ha->pdev);
6804 set_user_nice(current, MIN_NICE);
6806 set_current_state(TASK_INTERRUPTIBLE);
6807 while (!kthread_should_stop()) {
6808 ql_dbg(ql_dbg_dpc, base_vha, 0x4000,
6809 "DPC handler sleeping.\n");
6813 if (test_and_clear_bit(DO_EEH_RECOVERY, &base_vha->dpc_flags))
6814 qla_pci_set_eeh_busy(base_vha);
6816 if (!base_vha->flags.init_done || ha->flags.mbox_busy)
6819 if (ha->flags.eeh_busy) {
6820 ql_dbg(ql_dbg_dpc, base_vha, 0x4003,
6821 "eeh_busy=%d.\n", ha->flags.eeh_busy);
6827 ql_dbg(ql_dbg_dpc + ql_dbg_verbose, base_vha, 0x4001,
6828 "DPC handler waking up, dpc_flags=0x%lx.\n",
6829 base_vha->dpc_flags);
6831 if (test_bit(UNLOADING, &base_vha->dpc_flags))
6834 if (IS_P3P_TYPE(ha)) {
6835 if (IS_QLA8044(ha)) {
6836 if (test_and_clear_bit(ISP_UNRECOVERABLE,
6837 &base_vha->dpc_flags)) {
6838 qla8044_idc_lock(ha);
6839 qla8044_wr_direct(base_vha,
6840 QLA8044_CRB_DEV_STATE_INDEX,
6841 QLA8XXX_DEV_FAILED);
6842 qla8044_idc_unlock(ha);
6843 ql_log(ql_log_info, base_vha, 0x4004,
6844 "HW State: FAILED.\n");
6845 qla8044_device_state_handler(base_vha);
6850 if (test_and_clear_bit(ISP_UNRECOVERABLE,
6851 &base_vha->dpc_flags)) {
6852 qla82xx_idc_lock(ha);
6853 qla82xx_wr_32(ha, QLA82XX_CRB_DEV_STATE,
6854 QLA8XXX_DEV_FAILED);
6855 qla82xx_idc_unlock(ha);
6856 ql_log(ql_log_info, base_vha, 0x0151,
6857 "HW State: FAILED.\n");
6858 qla82xx_device_state_handler(base_vha);
6863 if (test_and_clear_bit(FCOE_CTX_RESET_NEEDED,
6864 &base_vha->dpc_flags)) {
6866 ql_dbg(ql_dbg_dpc, base_vha, 0x4005,
6867 "FCoE context reset scheduled.\n");
6868 if (!(test_and_set_bit(ABORT_ISP_ACTIVE,
6869 &base_vha->dpc_flags))) {
6870 if (qla82xx_fcoe_ctx_reset(base_vha)) {
6871 /* FCoE-ctx reset failed.
6872 * Escalate to chip-reset
6874 set_bit(ISP_ABORT_NEEDED,
6875 &base_vha->dpc_flags);
6877 clear_bit(ABORT_ISP_ACTIVE,
6878 &base_vha->dpc_flags);
6881 ql_dbg(ql_dbg_dpc, base_vha, 0x4006,
6882 "FCoE context reset end.\n");
6884 } else if (IS_QLAFX00(ha)) {
6885 if (test_and_clear_bit(ISP_UNRECOVERABLE,
6886 &base_vha->dpc_flags)) {
6887 ql_dbg(ql_dbg_dpc, base_vha, 0x4020,
6888 "Firmware Reset Recovery\n");
6889 if (qlafx00_reset_initialize(base_vha)) {
6890 /* Failed. Abort isp later. */
6891 if (!test_bit(UNLOADING,
6892 &base_vha->dpc_flags)) {
6893 set_bit(ISP_UNRECOVERABLE,
6894 &base_vha->dpc_flags);
6895 ql_dbg(ql_dbg_dpc, base_vha,
6897 "Reset Recovery Failed\n");
6902 if (test_and_clear_bit(FX00_TARGET_SCAN,
6903 &base_vha->dpc_flags)) {
6904 ql_dbg(ql_dbg_dpc, base_vha, 0x4022,
6905 "ISPFx00 Target Scan scheduled\n");
6906 if (qlafx00_rescan_isp(base_vha)) {
6907 if (!test_bit(UNLOADING,
6908 &base_vha->dpc_flags))
6909 set_bit(ISP_UNRECOVERABLE,
6910 &base_vha->dpc_flags);
6911 ql_dbg(ql_dbg_dpc, base_vha, 0x401e,
6912 "ISPFx00 Target Scan Failed\n");
6914 ql_dbg(ql_dbg_dpc, base_vha, 0x401f,
6915 "ISPFx00 Target Scan End\n");
6917 if (test_and_clear_bit(FX00_HOST_INFO_RESEND,
6918 &base_vha->dpc_flags)) {
6919 ql_dbg(ql_dbg_dpc, base_vha, 0x4023,
6920 "ISPFx00 Host Info resend scheduled\n");
6921 qlafx00_fx_disc(base_vha,
6922 &base_vha->hw->mr.fcport,
6923 FXDISC_REG_HOST_INFO);
6927 if (test_and_clear_bit(DETECT_SFP_CHANGE,
6928 &base_vha->dpc_flags)) {
6930 * - NO-OP -- await next ISP-ABORT. Preferred method
6931 * to minimize disruptions that will occur
6932 * when a forced chip-reset occurs.
6933 * - Force -- ISP-ABORT scheduled.
6935 /* set_bit(ISP_ABORT_NEEDED, &base_vha->dpc_flags); */
6938 if (test_and_clear_bit
6939 (ISP_ABORT_NEEDED, &base_vha->dpc_flags) &&
6940 !test_bit(UNLOADING, &base_vha->dpc_flags)) {
6941 bool do_reset = true;
6943 switch (base_vha->qlini_mode) {
6944 case QLA2XXX_INI_MODE_ENABLED:
6946 case QLA2XXX_INI_MODE_DISABLED:
6947 if (!qla_tgt_mode_enabled(base_vha) &&
6948 !ha->flags.fw_started)
6951 case QLA2XXX_INI_MODE_DUAL:
6952 if (!qla_dual_mode_enabled(base_vha) &&
6953 !ha->flags.fw_started)
6960 if (do_reset && !(test_and_set_bit(ABORT_ISP_ACTIVE,
6961 &base_vha->dpc_flags))) {
6962 base_vha->flags.online = 1;
6963 ql_dbg(ql_dbg_dpc, base_vha, 0x4007,
6964 "ISP abort scheduled.\n");
6965 if (ha->isp_ops->abort_isp(base_vha)) {
6966 /* failed. retry later */
6967 set_bit(ISP_ABORT_NEEDED,
6968 &base_vha->dpc_flags);
6970 clear_bit(ABORT_ISP_ACTIVE,
6971 &base_vha->dpc_flags);
6972 ql_dbg(ql_dbg_dpc, base_vha, 0x4008,
6973 "ISP abort end.\n");
6977 if (test_bit(PROCESS_PUREX_IOCB, &base_vha->dpc_flags)) {
6978 if (atomic_read(&base_vha->loop_state) == LOOP_READY) {
6979 qla24xx_process_purex_list
6980 (&base_vha->purex_list);
6981 clear_bit(PROCESS_PUREX_IOCB,
6982 &base_vha->dpc_flags);
6986 if (test_and_clear_bit(FCPORT_UPDATE_NEEDED,
6987 &base_vha->dpc_flags)) {
6988 qla2x00_update_fcports(base_vha);
6992 goto loop_resync_check;
6994 if (test_bit(ISP_QUIESCE_NEEDED, &base_vha->dpc_flags)) {
6995 ql_dbg(ql_dbg_dpc, base_vha, 0x4009,
6996 "Quiescence mode scheduled.\n");
6997 if (IS_P3P_TYPE(ha)) {
6999 qla82xx_device_state_handler(base_vha);
7001 qla8044_device_state_handler(base_vha);
7002 clear_bit(ISP_QUIESCE_NEEDED,
7003 &base_vha->dpc_flags);
7004 if (!ha->flags.quiesce_owner) {
7005 qla2x00_perform_loop_resync(base_vha);
7006 if (IS_QLA82XX(ha)) {
7007 qla82xx_idc_lock(ha);
7008 qla82xx_clear_qsnt_ready(
7010 qla82xx_idc_unlock(ha);
7011 } else if (IS_QLA8044(ha)) {
7012 qla8044_idc_lock(ha);
7013 qla8044_clear_qsnt_ready(
7015 qla8044_idc_unlock(ha);
7019 clear_bit(ISP_QUIESCE_NEEDED,
7020 &base_vha->dpc_flags);
7021 qla2x00_quiesce_io(base_vha);
7023 ql_dbg(ql_dbg_dpc, base_vha, 0x400a,
7024 "Quiescence mode end.\n");
7027 if (test_and_clear_bit(RESET_MARKER_NEEDED,
7028 &base_vha->dpc_flags) &&
7029 (!(test_and_set_bit(RESET_ACTIVE, &base_vha->dpc_flags)))) {
7031 ql_dbg(ql_dbg_dpc, base_vha, 0x400b,
7032 "Reset marker scheduled.\n");
7033 qla2x00_rst_aen(base_vha);
7034 clear_bit(RESET_ACTIVE, &base_vha->dpc_flags);
7035 ql_dbg(ql_dbg_dpc, base_vha, 0x400c,
7036 "Reset marker end.\n");
7039 /* Retry each device up to login retry count */
7040 if (test_bit(RELOGIN_NEEDED, &base_vha->dpc_flags) &&
7041 !test_bit(LOOP_RESYNC_NEEDED, &base_vha->dpc_flags) &&
7042 atomic_read(&base_vha->loop_state) != LOOP_DOWN) {
7044 if (!base_vha->relogin_jif ||
7045 time_after_eq(jiffies, base_vha->relogin_jif)) {
7046 base_vha->relogin_jif = jiffies + HZ;
7047 clear_bit(RELOGIN_NEEDED, &base_vha->dpc_flags);
7049 ql_dbg(ql_dbg_disc, base_vha, 0x400d,
7050 "Relogin scheduled.\n");
7051 qla24xx_post_relogin_work(base_vha);
7055 if (test_and_clear_bit(LOOP_RESYNC_NEEDED,
7056 &base_vha->dpc_flags)) {
7058 ql_dbg(ql_dbg_dpc, base_vha, 0x400f,
7059 "Loop resync scheduled.\n");
7061 if (!(test_and_set_bit(LOOP_RESYNC_ACTIVE,
7062 &base_vha->dpc_flags))) {
7064 qla2x00_loop_resync(base_vha);
7066 clear_bit(LOOP_RESYNC_ACTIVE,
7067 &base_vha->dpc_flags);
7070 ql_dbg(ql_dbg_dpc, base_vha, 0x4010,
7071 "Loop resync end.\n");
7077 if (test_bit(NPIV_CONFIG_NEEDED, &base_vha->dpc_flags) &&
7078 atomic_read(&base_vha->loop_state) == LOOP_READY) {
7079 clear_bit(NPIV_CONFIG_NEEDED, &base_vha->dpc_flags);
7080 qla2xxx_flash_npiv_conf(base_vha);
7084 if (!ha->interrupts_on)
7085 ha->isp_ops->enable_intrs(ha);
7087 if (test_and_clear_bit(BEACON_BLINK_NEEDED,
7088 &base_vha->dpc_flags)) {
7089 if (ha->beacon_blink_led == 1)
7090 ha->isp_ops->beacon_blink(base_vha);
7093 /* qpair online check */
7094 if (test_and_clear_bit(QPAIR_ONLINE_CHECK_NEEDED,
7095 &base_vha->dpc_flags)) {
7096 if (ha->flags.eeh_busy ||
7097 ha->flags.pci_channel_io_perm_failure)
7102 mutex_lock(&ha->mq_lock);
7103 list_for_each_entry(qpair, &base_vha->qp_list,
7105 qpair->online = online;
7106 mutex_unlock(&ha->mq_lock);
7109 if (test_and_clear_bit(SET_ZIO_THRESHOLD_NEEDED,
7110 &base_vha->dpc_flags)) {
7111 u16 threshold = ha->nvme_last_rptd_aen + ha->last_zio_threshold;
7113 if (threshold > ha->orig_fw_xcb_count)
7114 threshold = ha->orig_fw_xcb_count;
7116 ql_log(ql_log_info, base_vha, 0xffffff,
7117 "SET ZIO Activity exchange threshold to %d.\n",
7119 if (qla27xx_set_zio_threshold(base_vha, threshold)) {
7120 ql_log(ql_log_info, base_vha, 0xffffff,
7121 "Unable to SET ZIO Activity exchange threshold to %d.\n",
7126 if (!IS_QLAFX00(ha))
7127 qla2x00_do_dpc_all_vps(base_vha);
7129 if (test_and_clear_bit(N2N_LINK_RESET,
7130 &base_vha->dpc_flags)) {
7131 qla2x00_lip_reset(base_vha);
7136 set_current_state(TASK_INTERRUPTIBLE);
7137 } /* End of while(1) */
7138 __set_current_state(TASK_RUNNING);
7140 ql_dbg(ql_dbg_dpc, base_vha, 0x4011,
7141 "DPC handler exiting.\n");
7144 * Make sure that nobody tries to wake us up again.
7148 /* Cleanup any residual CTX SRBs. */
7149 qla2x00_abort_all_cmds(base_vha, DID_NO_CONNECT << 16);
7155 qla2xxx_wake_dpc(struct scsi_qla_host *vha)
7157 struct qla_hw_data *ha = vha->hw;
7158 struct task_struct *t = ha->dpc_thread;
7160 if (!test_bit(UNLOADING, &vha->dpc_flags) && t)
7166 * Processes asynchronous reset.
7169 * ha = adapter block pointer.
7172 qla2x00_rst_aen(scsi_qla_host_t *vha)
7174 if (vha->flags.online && !vha->flags.reset_active &&
7175 !atomic_read(&vha->loop_down_timer) &&
7176 !(test_bit(ABORT_ISP_ACTIVE, &vha->dpc_flags))) {
7178 clear_bit(RESET_MARKER_NEEDED, &vha->dpc_flags);
7181 * Issue marker command only when we are going to start
7184 vha->marker_needed = 1;
7185 } while (!atomic_read(&vha->loop_down_timer) &&
7186 (test_bit(RESET_MARKER_NEEDED, &vha->dpc_flags)));
7190 static bool qla_do_heartbeat(struct scsi_qla_host *vha)
7192 struct qla_hw_data *ha = vha->hw;
7195 bool do_heartbeat = false;
7198 * Allow do_heartbeat only if we don’t have any active interrupts,
7199 * but there are still IOs outstanding with firmware.
7201 cmpl_cnt = ha->base_qpair->cmd_completion_cnt;
7202 if (cmpl_cnt == ha->base_qpair->prev_completion_cnt &&
7203 cmpl_cnt != ha->base_qpair->cmd_cnt) {
7204 do_heartbeat = true;
7207 ha->base_qpair->prev_completion_cnt = cmpl_cnt;
7209 for (i = 0; i < ha->max_qpairs; i++) {
7210 if (ha->queue_pair_map[i]) {
7211 cmpl_cnt = ha->queue_pair_map[i]->cmd_completion_cnt;
7212 if (cmpl_cnt == ha->queue_pair_map[i]->prev_completion_cnt &&
7213 cmpl_cnt != ha->queue_pair_map[i]->cmd_cnt) {
7214 do_heartbeat = true;
7217 ha->queue_pair_map[i]->prev_completion_cnt = cmpl_cnt;
7222 return do_heartbeat;
7225 static void qla_heart_beat(struct scsi_qla_host *vha)
7227 struct qla_hw_data *ha = vha->hw;
7232 if (vha->hw->flags.eeh_busy || qla2x00_chip_is_down(vha))
7235 if (qla_do_heartbeat(vha))
7236 queue_work(ha->wq, &ha->heartbeat_work);
7239 /**************************************************************************
7245 * Context: Interrupt
7246 ***************************************************************************/
7248 qla2x00_timer(struct timer_list *t)
7250 scsi_qla_host_t *vha = from_timer(vha, t, timer);
7251 unsigned long cpu_flags = 0;
7256 struct qla_hw_data *ha = vha->hw;
7257 struct req_que *req;
7258 unsigned long flags;
7259 fc_port_t *fcport = NULL;
7261 if (ha->flags.eeh_busy) {
7262 ql_dbg(ql_dbg_timer, vha, 0x6000,
7263 "EEH = %d, restarting timer.\n",
7264 ha->flags.eeh_busy);
7265 qla2x00_restart_timer(vha, WATCH_INTERVAL);
7270 * Hardware read to raise pending EEH errors during mailbox waits. If
7271 * the read returns -1 then disable the board.
7273 if (!pci_channel_offline(ha->pdev)) {
7274 pci_read_config_word(ha->pdev, PCI_VENDOR_ID, &w);
7275 qla2x00_check_reg16_for_disconnect(vha, w);
7278 /* Make sure qla82xx_watchdog is run only for physical port */
7279 if (!vha->vp_idx && IS_P3P_TYPE(ha)) {
7280 if (test_bit(ISP_QUIESCE_NEEDED, &vha->dpc_flags))
7283 qla82xx_watchdog(vha);
7284 else if (IS_QLA8044(ha))
7285 qla8044_watchdog(vha);
7288 if (!vha->vp_idx && IS_QLAFX00(ha))
7289 qlafx00_timer_routine(vha);
7291 if (vha->link_down_time < QLA2XX_MAX_LINK_DOWN_TIME)
7292 vha->link_down_time++;
7294 spin_lock_irqsave(&vha->hw->tgt.sess_lock, flags);
7295 list_for_each_entry(fcport, &vha->vp_fcports, list) {
7296 if (fcport->tgt_link_down_time < QLA2XX_MAX_LINK_DOWN_TIME)
7297 fcport->tgt_link_down_time++;
7299 spin_unlock_irqrestore(&vha->hw->tgt.sess_lock, flags);
7301 /* Loop down handler. */
7302 if (atomic_read(&vha->loop_down_timer) > 0 &&
7303 !(test_bit(ABORT_ISP_ACTIVE, &vha->dpc_flags)) &&
7304 !(test_bit(FCOE_CTX_RESET_NEEDED, &vha->dpc_flags))
7305 && vha->flags.online) {
7307 if (atomic_read(&vha->loop_down_timer) ==
7308 vha->loop_down_abort_time) {
7310 ql_log(ql_log_info, vha, 0x6008,
7311 "Loop down - aborting the queues before time expires.\n");
7313 if (!IS_QLA2100(ha) && vha->link_down_timeout)
7314 atomic_set(&vha->loop_state, LOOP_DEAD);
7317 * Schedule an ISP abort to return any FCP2-device
7320 /* NPIV - scan physical port only */
7322 spin_lock_irqsave(&ha->hardware_lock,
7324 req = ha->req_q_map[0];
7326 index < req->num_outstanding_cmds;
7330 sp = req->outstanding_cmds[index];
7333 if (sp->cmd_type != TYPE_SRB)
7335 if (sp->type != SRB_SCSI_CMD)
7338 if (!(sfcp->flags & FCF_FCP2_DEVICE))
7342 set_bit(FCOE_CTX_RESET_NEEDED,
7345 set_bit(ISP_ABORT_NEEDED,
7349 spin_unlock_irqrestore(&ha->hardware_lock,
7355 /* if the loop has been down for 4 minutes, reinit adapter */
7356 if (atomic_dec_and_test(&vha->loop_down_timer) != 0) {
7357 if (!(vha->device_flags & DFLG_NO_CABLE)) {
7358 ql_log(ql_log_warn, vha, 0x6009,
7359 "Loop down - aborting ISP.\n");
7362 set_bit(FCOE_CTX_RESET_NEEDED,
7365 set_bit(ISP_ABORT_NEEDED,
7369 ql_dbg(ql_dbg_timer, vha, 0x600a,
7370 "Loop down - seconds remaining %d.\n",
7371 atomic_read(&vha->loop_down_timer));
7373 /* Check if beacon LED needs to be blinked for physical host only */
7374 if (!vha->vp_idx && (ha->beacon_blink_led == 1)) {
7375 /* There is no beacon_blink function for ISP82xx */
7376 if (!IS_P3P_TYPE(ha)) {
7377 set_bit(BEACON_BLINK_NEEDED, &vha->dpc_flags);
7382 /* check if edif running */
7383 if (vha->hw->flags.edif_enabled)
7384 qla_edif_timer(vha);
7386 /* Process any deferred work. */
7387 if (!list_empty(&vha->work_list)) {
7388 unsigned long flags;
7391 spin_lock_irqsave(&vha->work_lock, flags);
7392 if (!test_and_set_bit(IOCB_WORK_ACTIVE, &vha->dpc_flags))
7394 spin_unlock_irqrestore(&vha->work_lock, flags);
7396 queue_work(vha->hw->wq, &vha->iocb_work);
7401 * see if the active AEN count has changed from what was last reported.
7403 index = atomic_read(&ha->nvme_active_aen_cnt);
7405 (index != ha->nvme_last_rptd_aen) &&
7406 ha->zio_mode == QLA_ZIO_MODE_6 &&
7407 !ha->flags.host_shutting_down) {
7408 ha->nvme_last_rptd_aen = atomic_read(&ha->nvme_active_aen_cnt);
7409 ql_log(ql_log_info, vha, 0x3002,
7410 "nvme: Sched: Set ZIO exchange threshold to %d.\n",
7411 ha->nvme_last_rptd_aen);
7412 set_bit(SET_ZIO_THRESHOLD_NEEDED, &vha->dpc_flags);
7417 atomic_read(&ha->zio_threshold) != ha->last_zio_threshold &&
7418 IS_ZIO_THRESHOLD_CAPABLE(ha)) {
7419 ql_log(ql_log_info, vha, 0x3002,
7420 "Sched: Set ZIO exchange threshold to %d.\n",
7421 ha->last_zio_threshold);
7422 ha->last_zio_threshold = atomic_read(&ha->zio_threshold);
7423 set_bit(SET_ZIO_THRESHOLD_NEEDED, &vha->dpc_flags);
7427 /* Schedule the DPC routine if needed */
7428 if ((test_bit(ISP_ABORT_NEEDED, &vha->dpc_flags) ||
7429 test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags) ||
7430 test_bit(FCPORT_UPDATE_NEEDED, &vha->dpc_flags) ||
7432 test_bit(RESET_MARKER_NEEDED, &vha->dpc_flags) ||
7433 test_bit(BEACON_BLINK_NEEDED, &vha->dpc_flags) ||
7434 test_bit(ISP_UNRECOVERABLE, &vha->dpc_flags) ||
7435 test_bit(FCOE_CTX_RESET_NEEDED, &vha->dpc_flags) ||
7436 test_bit(VP_DPC_NEEDED, &vha->dpc_flags) ||
7437 test_bit(RELOGIN_NEEDED, &vha->dpc_flags) ||
7438 test_bit(PROCESS_PUREX_IOCB, &vha->dpc_flags))) {
7439 ql_dbg(ql_dbg_timer, vha, 0x600b,
7440 "isp_abort_needed=%d loop_resync_needed=%d "
7441 "fcport_update_needed=%d start_dpc=%d "
7442 "reset_marker_needed=%d",
7443 test_bit(ISP_ABORT_NEEDED, &vha->dpc_flags),
7444 test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags),
7445 test_bit(FCPORT_UPDATE_NEEDED, &vha->dpc_flags),
7447 test_bit(RESET_MARKER_NEEDED, &vha->dpc_flags));
7448 ql_dbg(ql_dbg_timer, vha, 0x600c,
7449 "beacon_blink_needed=%d isp_unrecoverable=%d "
7450 "fcoe_ctx_reset_needed=%d vp_dpc_needed=%d "
7451 "relogin_needed=%d, Process_purex_iocb=%d.\n",
7452 test_bit(BEACON_BLINK_NEEDED, &vha->dpc_flags),
7453 test_bit(ISP_UNRECOVERABLE, &vha->dpc_flags),
7454 test_bit(FCOE_CTX_RESET_NEEDED, &vha->dpc_flags),
7455 test_bit(VP_DPC_NEEDED, &vha->dpc_flags),
7456 test_bit(RELOGIN_NEEDED, &vha->dpc_flags),
7457 test_bit(PROCESS_PUREX_IOCB, &vha->dpc_flags));
7458 qla2xxx_wake_dpc(vha);
7461 qla_heart_beat(vha);
7463 qla2x00_restart_timer(vha, WATCH_INTERVAL);
7466 /* Firmware interface routines. */
7468 #define FW_ISP21XX 0
7469 #define FW_ISP22XX 1
7470 #define FW_ISP2300 2
7471 #define FW_ISP2322 3
7472 #define FW_ISP24XX 4
7473 #define FW_ISP25XX 5
7474 #define FW_ISP81XX 6
7475 #define FW_ISP82XX 7
7476 #define FW_ISP2031 8
7477 #define FW_ISP8031 9
7478 #define FW_ISP27XX 10
7479 #define FW_ISP28XX 11
7481 #define FW_FILE_ISP21XX "ql2100_fw.bin"
7482 #define FW_FILE_ISP22XX "ql2200_fw.bin"
7483 #define FW_FILE_ISP2300 "ql2300_fw.bin"
7484 #define FW_FILE_ISP2322 "ql2322_fw.bin"
7485 #define FW_FILE_ISP24XX "ql2400_fw.bin"
7486 #define FW_FILE_ISP25XX "ql2500_fw.bin"
7487 #define FW_FILE_ISP81XX "ql8100_fw.bin"
7488 #define FW_FILE_ISP82XX "ql8200_fw.bin"
7489 #define FW_FILE_ISP2031 "ql2600_fw.bin"
7490 #define FW_FILE_ISP8031 "ql8300_fw.bin"
7491 #define FW_FILE_ISP27XX "ql2700_fw.bin"
7492 #define FW_FILE_ISP28XX "ql2800_fw.bin"
7495 static DEFINE_MUTEX(qla_fw_lock);
7497 static struct fw_blob qla_fw_blobs[] = {
7498 { .name = FW_FILE_ISP21XX, .segs = { 0x1000, 0 }, },
7499 { .name = FW_FILE_ISP22XX, .segs = { 0x1000, 0 }, },
7500 { .name = FW_FILE_ISP2300, .segs = { 0x800, 0 }, },
7501 { .name = FW_FILE_ISP2322, .segs = { 0x800, 0x1c000, 0x1e000, 0 }, },
7502 { .name = FW_FILE_ISP24XX, },
7503 { .name = FW_FILE_ISP25XX, },
7504 { .name = FW_FILE_ISP81XX, },
7505 { .name = FW_FILE_ISP82XX, },
7506 { .name = FW_FILE_ISP2031, },
7507 { .name = FW_FILE_ISP8031, },
7508 { .name = FW_FILE_ISP27XX, },
7509 { .name = FW_FILE_ISP28XX, },
7514 qla2x00_request_firmware(scsi_qla_host_t *vha)
7516 struct qla_hw_data *ha = vha->hw;
7517 struct fw_blob *blob;
7519 if (IS_QLA2100(ha)) {
7520 blob = &qla_fw_blobs[FW_ISP21XX];
7521 } else if (IS_QLA2200(ha)) {
7522 blob = &qla_fw_blobs[FW_ISP22XX];
7523 } else if (IS_QLA2300(ha) || IS_QLA2312(ha) || IS_QLA6312(ha)) {
7524 blob = &qla_fw_blobs[FW_ISP2300];
7525 } else if (IS_QLA2322(ha) || IS_QLA6322(ha)) {
7526 blob = &qla_fw_blobs[FW_ISP2322];
7527 } else if (IS_QLA24XX_TYPE(ha)) {
7528 blob = &qla_fw_blobs[FW_ISP24XX];
7529 } else if (IS_QLA25XX(ha)) {
7530 blob = &qla_fw_blobs[FW_ISP25XX];
7531 } else if (IS_QLA81XX(ha)) {
7532 blob = &qla_fw_blobs[FW_ISP81XX];
7533 } else if (IS_QLA82XX(ha)) {
7534 blob = &qla_fw_blobs[FW_ISP82XX];
7535 } else if (IS_QLA2031(ha)) {
7536 blob = &qla_fw_blobs[FW_ISP2031];
7537 } else if (IS_QLA8031(ha)) {
7538 blob = &qla_fw_blobs[FW_ISP8031];
7539 } else if (IS_QLA27XX(ha)) {
7540 blob = &qla_fw_blobs[FW_ISP27XX];
7541 } else if (IS_QLA28XX(ha)) {
7542 blob = &qla_fw_blobs[FW_ISP28XX];
7550 mutex_lock(&qla_fw_lock);
7554 if (request_firmware(&blob->fw, blob->name, &ha->pdev->dev)) {
7555 ql_log(ql_log_warn, vha, 0x0063,
7556 "Failed to load firmware image (%s).\n", blob->name);
7562 mutex_unlock(&qla_fw_lock);
7567 qla2x00_release_firmware(void)
7569 struct fw_blob *blob;
7571 mutex_lock(&qla_fw_lock);
7572 for (blob = qla_fw_blobs; blob->name; blob++)
7573 release_firmware(blob->fw);
7574 mutex_unlock(&qla_fw_lock);
7577 static void qla_pci_error_cleanup(scsi_qla_host_t *vha)
7579 struct qla_hw_data *ha = vha->hw;
7580 scsi_qla_host_t *base_vha = pci_get_drvdata(ha->pdev);
7581 struct qla_qpair *qpair = NULL;
7582 struct scsi_qla_host *vp, *tvp;
7585 unsigned long flags;
7587 ql_dbg(ql_dbg_aer, vha, 0x9000,
7591 ha->base_qpair->chip_reset = ha->chip_reset;
7592 for (i = 0; i < ha->max_qpairs; i++) {
7593 if (ha->queue_pair_map[i])
7594 ha->queue_pair_map[i]->chip_reset =
7595 ha->base_qpair->chip_reset;
7599 * purge mailbox might take a while. Slot Reset/chip reset
7600 * will take care of the purge
7603 mutex_lock(&ha->mq_lock);
7604 ha->base_qpair->online = 0;
7605 list_for_each_entry(qpair, &base_vha->qp_list, qp_list_elem)
7608 mutex_unlock(&ha->mq_lock);
7610 qla2x00_mark_all_devices_lost(vha);
7612 spin_lock_irqsave(&ha->vport_slock, flags);
7613 list_for_each_entry_safe(vp, tvp, &ha->vp_list, list) {
7614 atomic_inc(&vp->vref_count);
7615 spin_unlock_irqrestore(&ha->vport_slock, flags);
7616 qla2x00_mark_all_devices_lost(vp);
7617 spin_lock_irqsave(&ha->vport_slock, flags);
7618 atomic_dec(&vp->vref_count);
7620 spin_unlock_irqrestore(&ha->vport_slock, flags);
7622 /* Clear all async request states across all VPs. */
7623 list_for_each_entry(fcport, &vha->vp_fcports, list)
7624 fcport->flags &= ~(FCF_LOGIN_NEEDED | FCF_ASYNC_SENT);
7626 spin_lock_irqsave(&ha->vport_slock, flags);
7627 list_for_each_entry_safe(vp, tvp, &ha->vp_list, list) {
7628 atomic_inc(&vp->vref_count);
7629 spin_unlock_irqrestore(&ha->vport_slock, flags);
7630 list_for_each_entry(fcport, &vp->vp_fcports, list)
7631 fcport->flags &= ~(FCF_LOGIN_NEEDED | FCF_ASYNC_SENT);
7632 spin_lock_irqsave(&ha->vport_slock, flags);
7633 atomic_dec(&vp->vref_count);
7635 spin_unlock_irqrestore(&ha->vport_slock, flags);
7639 static pci_ers_result_t
7640 qla2xxx_pci_error_detected(struct pci_dev *pdev, pci_channel_state_t state)
7642 scsi_qla_host_t *vha = pci_get_drvdata(pdev);
7643 struct qla_hw_data *ha = vha->hw;
7644 pci_ers_result_t ret = PCI_ERS_RESULT_NEED_RESET;
7646 ql_log(ql_log_warn, vha, 0x9000,
7647 "PCI error detected, state %x.\n", state);
7648 ha->pci_error_state = QLA_PCI_ERR_DETECTED;
7650 if (!atomic_read(&pdev->enable_cnt)) {
7651 ql_log(ql_log_info, vha, 0xffff,
7652 "PCI device is disabled,state %x\n", state);
7653 ret = PCI_ERS_RESULT_NEED_RESET;
7658 case pci_channel_io_normal:
7659 ha->flags.eeh_busy = 0;
7660 if (ql2xmqsupport || ql2xnvmeenable) {
7661 set_bit(QPAIR_ONLINE_CHECK_NEEDED, &vha->dpc_flags);
7662 qla2xxx_wake_dpc(vha);
7664 ret = PCI_ERS_RESULT_CAN_RECOVER;
7666 case pci_channel_io_frozen:
7667 qla_pci_set_eeh_busy(vha);
7668 ret = PCI_ERS_RESULT_NEED_RESET;
7670 case pci_channel_io_perm_failure:
7671 ha->flags.pci_channel_io_perm_failure = 1;
7672 qla2x00_abort_all_cmds(vha, DID_NO_CONNECT << 16);
7673 if (ql2xmqsupport || ql2xnvmeenable) {
7674 set_bit(QPAIR_ONLINE_CHECK_NEEDED, &vha->dpc_flags);
7675 qla2xxx_wake_dpc(vha);
7677 ret = PCI_ERS_RESULT_DISCONNECT;
7680 ql_dbg(ql_dbg_aer, vha, 0x600d,
7681 "PCI error detected returning [%x].\n", ret);
7685 static pci_ers_result_t
7686 qla2xxx_pci_mmio_enabled(struct pci_dev *pdev)
7688 int risc_paused = 0;
7690 unsigned long flags;
7691 scsi_qla_host_t *base_vha = pci_get_drvdata(pdev);
7692 struct qla_hw_data *ha = base_vha->hw;
7693 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
7694 struct device_reg_24xx __iomem *reg24 = &ha->iobase->isp24;
7696 ql_log(ql_log_warn, base_vha, 0x9000,
7699 ha->pci_error_state = QLA_PCI_MMIO_ENABLED;
7701 return PCI_ERS_RESULT_RECOVERED;
7703 spin_lock_irqsave(&ha->hardware_lock, flags);
7704 if (IS_QLA2100(ha) || IS_QLA2200(ha)){
7705 stat = rd_reg_word(®->hccr);
7706 if (stat & HCCR_RISC_PAUSE)
7708 } else if (IS_QLA23XX(ha)) {
7709 stat = rd_reg_dword(®->u.isp2300.host_status);
7710 if (stat & HSR_RISC_PAUSED)
7712 } else if (IS_FWI2_CAPABLE(ha)) {
7713 stat = rd_reg_dword(®24->host_status);
7714 if (stat & HSRX_RISC_PAUSED)
7717 spin_unlock_irqrestore(&ha->hardware_lock, flags);
7720 ql_log(ql_log_info, base_vha, 0x9003,
7721 "RISC paused -- mmio_enabled, Dumping firmware.\n");
7722 qla2xxx_dump_fw(base_vha);
7724 /* set PCI_ERS_RESULT_NEED_RESET to trigger call to qla2xxx_pci_slot_reset */
7725 ql_dbg(ql_dbg_aer, base_vha, 0x600d,
7726 "mmio enabled returning.\n");
7727 return PCI_ERS_RESULT_NEED_RESET;
7730 static pci_ers_result_t
7731 qla2xxx_pci_slot_reset(struct pci_dev *pdev)
7733 pci_ers_result_t ret = PCI_ERS_RESULT_DISCONNECT;
7734 scsi_qla_host_t *base_vha = pci_get_drvdata(pdev);
7735 struct qla_hw_data *ha = base_vha->hw;
7737 struct qla_qpair *qpair = NULL;
7739 ql_log(ql_log_warn, base_vha, 0x9004,
7742 ha->pci_error_state = QLA_PCI_SLOT_RESET;
7743 /* Workaround: qla2xxx driver which access hardware earlier
7744 * needs error state to be pci_channel_io_online.
7745 * Otherwise mailbox command timesout.
7747 pdev->error_state = pci_channel_io_normal;
7749 pci_restore_state(pdev);
7751 /* pci_restore_state() clears the saved_state flag of the device
7752 * save restored state which resets saved_state flag
7754 pci_save_state(pdev);
7757 rc = pci_enable_device_mem(pdev);
7759 rc = pci_enable_device(pdev);
7762 ql_log(ql_log_warn, base_vha, 0x9005,
7763 "Can't re-enable PCI device after reset.\n");
7764 goto exit_slot_reset;
7768 if (ha->isp_ops->pci_config(base_vha))
7769 goto exit_slot_reset;
7771 mutex_lock(&ha->mq_lock);
7772 list_for_each_entry(qpair, &base_vha->qp_list, qp_list_elem)
7774 mutex_unlock(&ha->mq_lock);
7776 ha->flags.eeh_busy = 0;
7777 base_vha->flags.online = 1;
7778 set_bit(ABORT_ISP_ACTIVE, &base_vha->dpc_flags);
7779 ha->isp_ops->abort_isp(base_vha);
7780 clear_bit(ABORT_ISP_ACTIVE, &base_vha->dpc_flags);
7782 if (qla2x00_isp_reg_stat(ha)) {
7783 ha->flags.eeh_busy = 1;
7784 qla_pci_error_cleanup(base_vha);
7785 ql_log(ql_log_warn, base_vha, 0x9005,
7786 "Device unable to recover from PCI error.\n");
7788 ret = PCI_ERS_RESULT_RECOVERED;
7792 ql_dbg(ql_dbg_aer, base_vha, 0x900e,
7793 "Slot Reset returning %x.\n", ret);
7799 qla2xxx_pci_resume(struct pci_dev *pdev)
7801 scsi_qla_host_t *base_vha = pci_get_drvdata(pdev);
7802 struct qla_hw_data *ha = base_vha->hw;
7805 ql_log(ql_log_warn, base_vha, 0x900f,
7809 ret = qla2x00_wait_for_hba_online(base_vha);
7810 if (ret != QLA_SUCCESS) {
7811 ql_log(ql_log_fatal, base_vha, 0x9002,
7812 "The device failed to resume I/O from slot/link_reset.\n");
7814 ha->pci_error_state = QLA_PCI_RESUME;
7815 ql_dbg(ql_dbg_aer, base_vha, 0x600d,
7816 "Pci Resume returning.\n");
7819 void qla_pci_set_eeh_busy(struct scsi_qla_host *vha)
7821 struct qla_hw_data *ha = vha->hw;
7822 struct scsi_qla_host *base_vha = pci_get_drvdata(ha->pdev);
7823 bool do_cleanup = false;
7824 unsigned long flags;
7826 if (ha->flags.eeh_busy)
7829 spin_lock_irqsave(&base_vha->work_lock, flags);
7830 if (!ha->flags.eeh_busy) {
7831 ha->flags.eeh_busy = 1;
7834 spin_unlock_irqrestore(&base_vha->work_lock, flags);
7837 qla_pci_error_cleanup(base_vha);
7841 * this routine will schedule a task to pause IO from interrupt context
7842 * if caller sees a PCIE error event (register read = 0xf's)
7844 void qla_schedule_eeh_work(struct scsi_qla_host *vha)
7846 struct qla_hw_data *ha = vha->hw;
7847 struct scsi_qla_host *base_vha = pci_get_drvdata(ha->pdev);
7849 if (ha->flags.eeh_busy)
7852 set_bit(DO_EEH_RECOVERY, &base_vha->dpc_flags);
7853 qla2xxx_wake_dpc(base_vha);
7857 qla_pci_reset_prepare(struct pci_dev *pdev)
7859 scsi_qla_host_t *base_vha = pci_get_drvdata(pdev);
7860 struct qla_hw_data *ha = base_vha->hw;
7861 struct qla_qpair *qpair;
7863 ql_log(ql_log_warn, base_vha, 0xffff,
7867 * PCI FLR/function reset is about to reset the
7868 * slot. Stop the chip to stop all DMA access.
7869 * It is assumed that pci_reset_done will be called
7870 * after FLR to resume Chip operation.
7872 ha->flags.eeh_busy = 1;
7873 mutex_lock(&ha->mq_lock);
7874 list_for_each_entry(qpair, &base_vha->qp_list, qp_list_elem)
7876 mutex_unlock(&ha->mq_lock);
7878 set_bit(ABORT_ISP_ACTIVE, &base_vha->dpc_flags);
7879 qla2x00_abort_isp_cleanup(base_vha);
7880 qla2x00_abort_all_cmds(base_vha, DID_RESET << 16);
7884 qla_pci_reset_done(struct pci_dev *pdev)
7886 scsi_qla_host_t *base_vha = pci_get_drvdata(pdev);
7887 struct qla_hw_data *ha = base_vha->hw;
7888 struct qla_qpair *qpair;
7890 ql_log(ql_log_warn, base_vha, 0xffff,
7894 * FLR just completed by PCI layer. Resume adapter
7896 ha->flags.eeh_busy = 0;
7897 mutex_lock(&ha->mq_lock);
7898 list_for_each_entry(qpair, &base_vha->qp_list, qp_list_elem)
7900 mutex_unlock(&ha->mq_lock);
7902 base_vha->flags.online = 1;
7903 ha->isp_ops->abort_isp(base_vha);
7904 clear_bit(ABORT_ISP_ACTIVE, &base_vha->dpc_flags);
7907 static int qla2xxx_map_queues(struct Scsi_Host *shost)
7910 scsi_qla_host_t *vha = (scsi_qla_host_t *)shost->hostdata;
7911 struct blk_mq_queue_map *qmap = &shost->tag_set.map[HCTX_TYPE_DEFAULT];
7913 if (USER_CTRL_IRQ(vha->hw) || !vha->hw->mqiobase)
7914 rc = blk_mq_map_queues(qmap);
7916 rc = blk_mq_pci_map_queues(qmap, vha->hw->pdev, vha->irq_offset);
7920 struct scsi_host_template qla2xxx_driver_template = {
7921 .module = THIS_MODULE,
7922 .name = QLA2XXX_DRIVER_NAME,
7923 .queuecommand = qla2xxx_queuecommand,
7925 .eh_timed_out = fc_eh_timed_out,
7926 .eh_abort_handler = qla2xxx_eh_abort,
7927 .eh_should_retry_cmd = fc_eh_should_retry_cmd,
7928 .eh_device_reset_handler = qla2xxx_eh_device_reset,
7929 .eh_target_reset_handler = qla2xxx_eh_target_reset,
7930 .eh_bus_reset_handler = qla2xxx_eh_bus_reset,
7931 .eh_host_reset_handler = qla2xxx_eh_host_reset,
7933 .slave_configure = qla2xxx_slave_configure,
7935 .slave_alloc = qla2xxx_slave_alloc,
7936 .slave_destroy = qla2xxx_slave_destroy,
7937 .scan_finished = qla2xxx_scan_finished,
7938 .scan_start = qla2xxx_scan_start,
7939 .change_queue_depth = scsi_change_queue_depth,
7940 .map_queues = qla2xxx_map_queues,
7943 .sg_tablesize = SG_ALL,
7945 .max_sectors = 0xFFFF,
7946 .shost_groups = qla2x00_host_groups,
7948 .supported_mode = MODE_INITIATOR,
7949 .track_queue_depth = 1,
7950 .cmd_size = sizeof(srb_t),
7953 static const struct pci_error_handlers qla2xxx_err_handler = {
7954 .error_detected = qla2xxx_pci_error_detected,
7955 .mmio_enabled = qla2xxx_pci_mmio_enabled,
7956 .slot_reset = qla2xxx_pci_slot_reset,
7957 .resume = qla2xxx_pci_resume,
7958 .reset_prepare = qla_pci_reset_prepare,
7959 .reset_done = qla_pci_reset_done,
7962 static struct pci_device_id qla2xxx_pci_tbl[] = {
7963 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP2100) },
7964 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP2200) },
7965 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP2300) },
7966 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP2312) },
7967 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP2322) },
7968 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP6312) },
7969 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP6322) },
7970 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP2422) },
7971 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP2432) },
7972 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP8432) },
7973 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP5422) },
7974 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP5432) },
7975 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP2532) },
7976 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP2031) },
7977 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP8001) },
7978 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP8021) },
7979 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP8031) },
7980 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISPF001) },
7981 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP8044) },
7982 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP2071) },
7983 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP2271) },
7984 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP2261) },
7985 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP2061) },
7986 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP2081) },
7987 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP2281) },
7988 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP2089) },
7989 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP2289) },
7992 MODULE_DEVICE_TABLE(pci, qla2xxx_pci_tbl);
7994 static struct pci_driver qla2xxx_pci_driver = {
7995 .name = QLA2XXX_DRIVER_NAME,
7997 .owner = THIS_MODULE,
7999 .id_table = qla2xxx_pci_tbl,
8000 .probe = qla2x00_probe_one,
8001 .remove = qla2x00_remove_one,
8002 .shutdown = qla2x00_shutdown,
8003 .err_handler = &qla2xxx_err_handler,
8006 static const struct file_operations apidev_fops = {
8007 .owner = THIS_MODULE,
8008 .llseek = noop_llseek,
8012 * qla2x00_module_init - Module initialization.
8015 qla2x00_module_init(void)
8019 BUILD_BUG_ON(sizeof(cmd_a64_entry_t) != 64);
8020 BUILD_BUG_ON(sizeof(cmd_entry_t) != 64);
8021 BUILD_BUG_ON(sizeof(cont_a64_entry_t) != 64);
8022 BUILD_BUG_ON(sizeof(cont_entry_t) != 64);
8023 BUILD_BUG_ON(sizeof(init_cb_t) != 96);
8024 BUILD_BUG_ON(sizeof(mrk_entry_t) != 64);
8025 BUILD_BUG_ON(sizeof(ms_iocb_entry_t) != 64);
8026 BUILD_BUG_ON(sizeof(request_t) != 64);
8027 BUILD_BUG_ON(sizeof(struct abort_entry_24xx) != 64);
8028 BUILD_BUG_ON(sizeof(struct abort_iocb_entry_fx00) != 64);
8029 BUILD_BUG_ON(sizeof(struct abts_entry_24xx) != 64);
8030 BUILD_BUG_ON(sizeof(struct access_chip_84xx) != 64);
8031 BUILD_BUG_ON(sizeof(struct access_chip_rsp_84xx) != 64);
8032 BUILD_BUG_ON(sizeof(struct cmd_bidir) != 64);
8033 BUILD_BUG_ON(sizeof(struct cmd_nvme) != 64);
8034 BUILD_BUG_ON(sizeof(struct cmd_type_6) != 64);
8035 BUILD_BUG_ON(sizeof(struct cmd_type_7) != 64);
8036 BUILD_BUG_ON(sizeof(struct cmd_type_7_fx00) != 64);
8037 BUILD_BUG_ON(sizeof(struct cmd_type_crc_2) != 64);
8038 BUILD_BUG_ON(sizeof(struct ct_entry_24xx) != 64);
8039 BUILD_BUG_ON(sizeof(struct ct_fdmi1_hba_attributes) != 2604);
8040 BUILD_BUG_ON(sizeof(struct ct_fdmi2_hba_attributes) != 4424);
8041 BUILD_BUG_ON(sizeof(struct ct_fdmi2_port_attributes) != 4164);
8042 BUILD_BUG_ON(sizeof(struct ct_fdmi_hba_attr) != 260);
8043 BUILD_BUG_ON(sizeof(struct ct_fdmi_port_attr) != 260);
8044 BUILD_BUG_ON(sizeof(struct ct_rsp_hdr) != 16);
8045 BUILD_BUG_ON(sizeof(struct ctio_crc2_to_fw) != 64);
8046 BUILD_BUG_ON(sizeof(struct device_reg_24xx) != 256);
8047 BUILD_BUG_ON(sizeof(struct device_reg_25xxmq) != 24);
8048 BUILD_BUG_ON(sizeof(struct device_reg_2xxx) != 256);
8049 BUILD_BUG_ON(sizeof(struct device_reg_82xx) != 1288);
8050 BUILD_BUG_ON(sizeof(struct device_reg_fx00) != 216);
8051 BUILD_BUG_ON(sizeof(struct els_entry_24xx) != 64);
8052 BUILD_BUG_ON(sizeof(struct els_sts_entry_24xx) != 64);
8053 BUILD_BUG_ON(sizeof(struct fxdisc_entry_fx00) != 64);
8054 BUILD_BUG_ON(sizeof(struct imm_ntfy_from_isp) != 64);
8055 BUILD_BUG_ON(sizeof(struct init_cb_24xx) != 128);
8056 BUILD_BUG_ON(sizeof(struct init_cb_81xx) != 128);
8057 BUILD_BUG_ON(sizeof(struct logio_entry_24xx) != 64);
8058 BUILD_BUG_ON(sizeof(struct mbx_entry) != 64);
8059 BUILD_BUG_ON(sizeof(struct mid_init_cb_24xx) != 5252);
8060 BUILD_BUG_ON(sizeof(struct mrk_entry_24xx) != 64);
8061 BUILD_BUG_ON(sizeof(struct nvram_24xx) != 512);
8062 BUILD_BUG_ON(sizeof(struct nvram_81xx) != 512);
8063 BUILD_BUG_ON(sizeof(struct pt_ls4_request) != 64);
8064 BUILD_BUG_ON(sizeof(struct pt_ls4_rx_unsol) != 64);
8065 BUILD_BUG_ON(sizeof(struct purex_entry_24xx) != 64);
8066 BUILD_BUG_ON(sizeof(struct qla2100_fw_dump) != 123634);
8067 BUILD_BUG_ON(sizeof(struct qla2300_fw_dump) != 136100);
8068 BUILD_BUG_ON(sizeof(struct qla24xx_fw_dump) != 37976);
8069 BUILD_BUG_ON(sizeof(struct qla25xx_fw_dump) != 39228);
8070 BUILD_BUG_ON(sizeof(struct qla2xxx_fce_chain) != 52);
8071 BUILD_BUG_ON(sizeof(struct qla2xxx_fw_dump) != 136172);
8072 BUILD_BUG_ON(sizeof(struct qla2xxx_mq_chain) != 524);
8073 BUILD_BUG_ON(sizeof(struct qla2xxx_mqueue_chain) != 8);
8074 BUILD_BUG_ON(sizeof(struct qla2xxx_mqueue_header) != 12);
8075 BUILD_BUG_ON(sizeof(struct qla2xxx_offld_chain) != 24);
8076 BUILD_BUG_ON(sizeof(struct qla81xx_fw_dump) != 39420);
8077 BUILD_BUG_ON(sizeof(struct qla82xx_uri_data_desc) != 28);
8078 BUILD_BUG_ON(sizeof(struct qla82xx_uri_table_desc) != 32);
8079 BUILD_BUG_ON(sizeof(struct qla83xx_fw_dump) != 51196);
8080 BUILD_BUG_ON(sizeof(struct qla_fcp_prio_cfg) != FCP_PRIO_CFG_SIZE);
8081 BUILD_BUG_ON(sizeof(struct qla_fdt_layout) != 128);
8082 BUILD_BUG_ON(sizeof(struct qla_flt_header) != 8);
8083 BUILD_BUG_ON(sizeof(struct qla_flt_region) != 16);
8084 BUILD_BUG_ON(sizeof(struct qla_npiv_entry) != 24);
8085 BUILD_BUG_ON(sizeof(struct qla_npiv_header) != 16);
8086 BUILD_BUG_ON(sizeof(struct rdp_rsp_payload) != 336);
8087 BUILD_BUG_ON(sizeof(struct sns_cmd_pkt) != 2064);
8088 BUILD_BUG_ON(sizeof(struct sts_entry_24xx) != 64);
8089 BUILD_BUG_ON(sizeof(struct tsk_mgmt_entry) != 64);
8090 BUILD_BUG_ON(sizeof(struct tsk_mgmt_entry_fx00) != 64);
8091 BUILD_BUG_ON(sizeof(struct verify_chip_entry_84xx) != 64);
8092 BUILD_BUG_ON(sizeof(struct verify_chip_rsp_84xx) != 52);
8093 BUILD_BUG_ON(sizeof(struct vf_evfp_entry_24xx) != 56);
8094 BUILD_BUG_ON(sizeof(struct vp_config_entry_24xx) != 64);
8095 BUILD_BUG_ON(sizeof(struct vp_ctrl_entry_24xx) != 64);
8096 BUILD_BUG_ON(sizeof(struct vp_rpt_id_entry_24xx) != 64);
8097 BUILD_BUG_ON(sizeof(sts21_entry_t) != 64);
8098 BUILD_BUG_ON(sizeof(sts22_entry_t) != 64);
8099 BUILD_BUG_ON(sizeof(sts_cont_entry_t) != 64);
8100 BUILD_BUG_ON(sizeof(sts_entry_t) != 64);
8101 BUILD_BUG_ON(sizeof(sw_info_t) != 32);
8102 BUILD_BUG_ON(sizeof(target_id_t) != 2);
8104 /* Allocate cache for SRBs. */
8105 srb_cachep = kmem_cache_create("qla2xxx_srbs", sizeof(srb_t), 0,
8106 SLAB_HWCACHE_ALIGN, NULL);
8107 if (srb_cachep == NULL) {
8108 ql_log(ql_log_fatal, NULL, 0x0001,
8109 "Unable to allocate SRB cache...Failing load!.\n");
8113 /* Initialize target kmem_cache and mem_pools */
8117 } else if (ret > 0) {
8119 * If initiator mode is explictly disabled by qlt_init(),
8120 * prevent scsi_transport_fc.c:fc_scsi_scan_rport() from
8121 * performing scsi_scan_target() during LOOP UP event.
8123 qla2xxx_transport_functions.disable_target_scan = 1;
8124 qla2xxx_transport_vport_functions.disable_target_scan = 1;
8127 /* Derive version string. */
8128 strcpy(qla2x00_version_str, QLA2XXX_VERSION);
8129 if (ql2xextended_error_logging)
8130 strcat(qla2x00_version_str, "-debug");
8131 if (ql2xextended_error_logging == 1)
8132 ql2xextended_error_logging = QL_DBG_DEFAULT1_MASK;
8134 qla2xxx_transport_template =
8135 fc_attach_transport(&qla2xxx_transport_functions);
8136 if (!qla2xxx_transport_template) {
8137 ql_log(ql_log_fatal, NULL, 0x0002,
8138 "fc_attach_transport failed...Failing load!.\n");
8143 apidev_major = register_chrdev(0, QLA2XXX_APIDEV, &apidev_fops);
8144 if (apidev_major < 0) {
8145 ql_log(ql_log_fatal, NULL, 0x0003,
8146 "Unable to register char device %s.\n", QLA2XXX_APIDEV);
8149 qla2xxx_transport_vport_template =
8150 fc_attach_transport(&qla2xxx_transport_vport_functions);
8151 if (!qla2xxx_transport_vport_template) {
8152 ql_log(ql_log_fatal, NULL, 0x0004,
8153 "fc_attach_transport vport failed...Failing load!.\n");
8157 ql_log(ql_log_info, NULL, 0x0005,
8158 "QLogic Fibre Channel HBA Driver: %s.\n",
8159 qla2x00_version_str);
8160 ret = pci_register_driver(&qla2xxx_pci_driver);
8162 ql_log(ql_log_fatal, NULL, 0x0006,
8163 "pci_register_driver failed...ret=%d Failing load!.\n",
8165 goto release_vport_transport;
8169 release_vport_transport:
8170 fc_release_transport(qla2xxx_transport_vport_template);
8173 if (apidev_major >= 0)
8174 unregister_chrdev(apidev_major, QLA2XXX_APIDEV);
8175 fc_release_transport(qla2xxx_transport_template);
8181 kmem_cache_destroy(srb_cachep);
8186 * qla2x00_module_exit - Module cleanup.
8189 qla2x00_module_exit(void)
8191 pci_unregister_driver(&qla2xxx_pci_driver);
8192 qla2x00_release_firmware();
8193 kmem_cache_destroy(ctx_cachep);
8194 fc_release_transport(qla2xxx_transport_vport_template);
8195 if (apidev_major >= 0)
8196 unregister_chrdev(apidev_major, QLA2XXX_APIDEV);
8197 fc_release_transport(qla2xxx_transport_template);
8199 kmem_cache_destroy(srb_cachep);
8202 module_init(qla2x00_module_init);
8203 module_exit(qla2x00_module_exit);
8205 MODULE_AUTHOR("QLogic Corporation");
8206 MODULE_DESCRIPTION("QLogic Fibre Channel HBA Driver");
8207 MODULE_LICENSE("GPL");
8208 MODULE_FIRMWARE(FW_FILE_ISP21XX);
8209 MODULE_FIRMWARE(FW_FILE_ISP22XX);
8210 MODULE_FIRMWARE(FW_FILE_ISP2300);
8211 MODULE_FIRMWARE(FW_FILE_ISP2322);
8212 MODULE_FIRMWARE(FW_FILE_ISP24XX);
8213 MODULE_FIRMWARE(FW_FILE_ISP25XX);