1 // SPDX-License-Identifier: GPL-2.0-only
3 * QLogic Fibre Channel HBA Driver
4 * Copyright (c) 2003-2014 QLogic Corporation
8 #include <linux/bitfield.h>
9 #include <linux/moduleparam.h>
10 #include <linux/vmalloc.h>
11 #include <linux/delay.h>
12 #include <linux/kthread.h>
13 #include <linux/mutex.h>
14 #include <linux/kobject.h>
15 #include <linux/slab.h>
16 #include <linux/refcount.h>
17 #include <linux/crash_dump.h>
18 #include <linux/trace_events.h>
19 #include <linux/trace.h>
21 #include <scsi/scsi_tcq.h>
22 #include <scsi/scsicam.h>
23 #include <scsi/scsi_transport.h>
24 #include <scsi/scsi_transport_fc.h>
26 #include "qla_target.h"
31 char qla2x00_version_str[40];
33 static int apidev_major;
36 * SRB allocation cache
38 struct kmem_cache *srb_cachep;
40 static struct trace_array *qla_trc_array;
42 int ql2xfulldump_on_mpifail;
43 module_param(ql2xfulldump_on_mpifail, int, S_IRUGO | S_IWUSR);
44 MODULE_PARM_DESC(ql2xfulldump_on_mpifail,
45 "Set this to take full dump on MPI hang.");
47 int ql2xenforce_iocb_limit = 2;
48 module_param(ql2xenforce_iocb_limit, int, S_IRUGO | S_IWUSR);
49 MODULE_PARM_DESC(ql2xenforce_iocb_limit,
50 "Enforce IOCB throttling, to avoid FW congestion. (default: 2) "
51 "1: track usage per queue, 2: track usage per adapter");
54 * CT6 CTX allocation cache
56 static struct kmem_cache *ctx_cachep;
58 * error level for logging
60 uint ql_errlev = 0x8001;
63 module_param(ql2xsecenable, int, S_IRUGO);
64 MODULE_PARM_DESC(ql2xsecenable,
65 "Enable/disable security. 0(Default) - Security disabled. 1 - Security enabled.");
67 static int ql2xenableclass2;
68 module_param(ql2xenableclass2, int, S_IRUGO|S_IRUSR);
69 MODULE_PARM_DESC(ql2xenableclass2,
70 "Specify if Class 2 operations are supported from the very "
71 "beginning. Default is 0 - class 2 not supported.");
74 int ql2xlogintimeout = 20;
75 module_param(ql2xlogintimeout, int, S_IRUGO);
76 MODULE_PARM_DESC(ql2xlogintimeout,
77 "Login timeout value in seconds.");
79 int qlport_down_retry;
80 module_param(qlport_down_retry, int, S_IRUGO);
81 MODULE_PARM_DESC(qlport_down_retry,
82 "Maximum number of command retries to a port that returns "
83 "a PORT-DOWN status.");
85 int ql2xplogiabsentdevice;
86 module_param(ql2xplogiabsentdevice, int, S_IRUGO|S_IWUSR);
87 MODULE_PARM_DESC(ql2xplogiabsentdevice,
88 "Option to enable PLOGI to devices that are not present after "
89 "a Fabric scan. This is needed for several broken switches. "
90 "Default is 0 - no PLOGI. 1 - perform PLOGI.");
92 int ql2xloginretrycount;
93 module_param(ql2xloginretrycount, int, S_IRUGO);
94 MODULE_PARM_DESC(ql2xloginretrycount,
95 "Specify an alternate value for the NVRAM login retry count.");
97 int ql2xallocfwdump = 1;
98 module_param(ql2xallocfwdump, int, S_IRUGO);
99 MODULE_PARM_DESC(ql2xallocfwdump,
100 "Option to enable allocation of memory for a firmware dump "
101 "during HBA initialization. Memory allocation requirements "
102 "vary by ISP type. Default is 1 - allocate memory.");
104 int ql2xextended_error_logging;
105 module_param(ql2xextended_error_logging, int, S_IRUGO|S_IWUSR);
106 module_param_named(logging, ql2xextended_error_logging, int, S_IRUGO|S_IWUSR);
107 MODULE_PARM_DESC(ql2xextended_error_logging,
108 "Option to enable extended error logging,\n"
109 "\t\tDefault is 0 - no logging. 0x40000000 - Module Init & Probe.\n"
110 "\t\t0x20000000 - Mailbox Cmnds. 0x10000000 - Device Discovery.\n"
111 "\t\t0x08000000 - IO tracing. 0x04000000 - DPC Thread.\n"
112 "\t\t0x02000000 - Async events. 0x01000000 - Timer routines.\n"
113 "\t\t0x00800000 - User space. 0x00400000 - Task Management.\n"
114 "\t\t0x00200000 - AER/EEH. 0x00100000 - Multi Q.\n"
115 "\t\t0x00080000 - P3P Specific. 0x00040000 - Virtual Port.\n"
116 "\t\t0x00020000 - Buffer Dump. 0x00010000 - Misc.\n"
117 "\t\t0x00008000 - Verbose. 0x00004000 - Target.\n"
118 "\t\t0x00002000 - Target Mgmt. 0x00001000 - Target TMF.\n"
119 "\t\t0x7fffffff - For enabling all logs, can be too many logs.\n"
120 "\t\t0x1e400000 - Preferred value for capturing essential "
121 "debug information (equivalent to old "
122 "ql2xextended_error_logging=1).\n"
123 "\t\tDo LOGICAL OR of the value to enable more than one level");
125 int ql2xextended_error_logging_ktrace = 1;
126 module_param(ql2xextended_error_logging_ktrace, int, S_IRUGO|S_IWUSR);
127 MODULE_PARM_DESC(ql2xextended_error_logging_ktrace,
128 "Same BIT definition as ql2xextended_error_logging, but used to control logging to kernel trace buffer (default=1).\n");
130 int ql2xshiftctondsd = 6;
131 module_param(ql2xshiftctondsd, int, S_IRUGO);
132 MODULE_PARM_DESC(ql2xshiftctondsd,
133 "Set to control shifting of command type processing "
134 "based on total number of SG elements.");
136 int ql2xfdmienable = 1;
137 module_param(ql2xfdmienable, int, S_IRUGO|S_IWUSR);
138 module_param_named(fdmi, ql2xfdmienable, int, S_IRUGO|S_IWUSR);
139 MODULE_PARM_DESC(ql2xfdmienable,
140 "Enables FDMI registrations. "
141 "0 - no FDMI registrations. "
142 "1 - provide FDMI registrations (default).");
144 #define MAX_Q_DEPTH 64
145 static int ql2xmaxqdepth = MAX_Q_DEPTH;
146 module_param(ql2xmaxqdepth, int, S_IRUGO|S_IWUSR);
147 MODULE_PARM_DESC(ql2xmaxqdepth,
148 "Maximum queue depth to set for each LUN. "
151 int ql2xenabledif = 2;
152 module_param(ql2xenabledif, int, S_IRUGO);
153 MODULE_PARM_DESC(ql2xenabledif,
154 " Enable T10-CRC-DIF:\n"
156 " 0 -- No DIF Support\n"
157 " 1 -- Enable DIF for all types\n"
158 " 2 -- Enable DIF for all types, except Type 0.\n");
160 #if (IS_ENABLED(CONFIG_NVME_FC))
161 int ql2xnvmeenable = 1;
165 module_param(ql2xnvmeenable, int, 0644);
166 MODULE_PARM_DESC(ql2xnvmeenable,
167 "Enables NVME support. "
168 "0 - no NVMe. Default is Y");
170 int ql2xenablehba_err_chk = 2;
171 module_param(ql2xenablehba_err_chk, int, S_IRUGO|S_IWUSR);
172 MODULE_PARM_DESC(ql2xenablehba_err_chk,
173 " Enable T10-CRC-DIF Error isolation by HBA:\n"
175 " 0 -- Error isolation disabled\n"
176 " 1 -- Error isolation enabled only for DIX Type 0\n"
177 " 2 -- Error isolation enabled for all Types\n");
179 int ql2xmqsupport = 1;
180 module_param(ql2xmqsupport, int, S_IRUGO);
181 MODULE_PARM_DESC(ql2xmqsupport,
182 "Enable on demand multiple queue pairs support "
183 "Default is 1 for supported. "
184 "Set it to 0 to turn off mq qpair support.");
187 module_param(ql2xfwloadbin, int, S_IRUGO|S_IWUSR);
188 module_param_named(fwload, ql2xfwloadbin, int, S_IRUGO|S_IWUSR);
189 MODULE_PARM_DESC(ql2xfwloadbin,
190 "Option to specify location from which to load ISP firmware:.\n"
191 " 2 -- load firmware via the request_firmware() (hotplug).\n"
193 " 1 -- load firmware from flash.\n"
194 " 0 -- use default semantics.\n");
197 module_param(ql2xdbwr, int, S_IRUGO|S_IWUSR);
198 MODULE_PARM_DESC(ql2xdbwr,
199 "Option to specify scheme for request queue posting.\n"
200 " 0 -- Regular doorbell.\n"
201 " 1 -- CAMRAM doorbell (faster).\n");
204 module_param(ql2xgffidenable, int, S_IRUGO);
205 MODULE_PARM_DESC(ql2xgffidenable,
206 "Enables GFF_ID checks of port type. "
207 "Default is 0 - Do not use GFF_ID information.");
209 int ql2xasynctmfenable = 1;
210 module_param(ql2xasynctmfenable, int, S_IRUGO);
211 MODULE_PARM_DESC(ql2xasynctmfenable,
212 "Enables issue of TM IOCBs asynchronously via IOCB mechanism"
213 "Default is 1 - Issue TM IOCBs via mailbox mechanism.");
215 int ql2xdontresethba;
216 module_param(ql2xdontresethba, int, S_IRUGO|S_IWUSR);
217 MODULE_PARM_DESC(ql2xdontresethba,
218 "Option to specify reset behaviour.\n"
219 " 0 (Default) -- Reset on failure.\n"
220 " 1 -- Do not reset on failure.\n");
222 uint64_t ql2xmaxlun = MAX_LUNS;
223 module_param(ql2xmaxlun, ullong, S_IRUGO);
224 MODULE_PARM_DESC(ql2xmaxlun,
225 "Defines the maximum LU number to register with the SCSI "
226 "midlayer. Default is 65535.");
228 int ql2xmdcapmask = 0x1F;
229 module_param(ql2xmdcapmask, int, S_IRUGO);
230 MODULE_PARM_DESC(ql2xmdcapmask,
231 "Set the Minidump driver capture mask level. "
232 "Default is 0x1F - Can be set to 0x3, 0x7, 0xF, 0x1F, 0x7F.");
234 int ql2xmdenable = 1;
235 module_param(ql2xmdenable, int, S_IRUGO);
236 MODULE_PARM_DESC(ql2xmdenable,
237 "Enable/disable MiniDump. "
238 "0 - MiniDump disabled. "
239 "1 (Default) - MiniDump enabled.");
242 module_param(ql2xexlogins, uint, S_IRUGO|S_IWUSR);
243 MODULE_PARM_DESC(ql2xexlogins,
244 "Number of extended Logins. "
245 "0 (Default)- Disabled.");
247 int ql2xexchoffld = 1024;
248 module_param(ql2xexchoffld, uint, 0644);
249 MODULE_PARM_DESC(ql2xexchoffld,
250 "Number of target exchanges.");
252 int ql2xiniexchg = 1024;
253 module_param(ql2xiniexchg, uint, 0644);
254 MODULE_PARM_DESC(ql2xiniexchg,
255 "Number of initiator exchanges.");
258 module_param(ql2xfwholdabts, int, S_IRUGO);
259 MODULE_PARM_DESC(ql2xfwholdabts,
260 "Allow FW to hold status IOCB until ABTS rsp received. "
261 "0 (Default) Do not set fw option. "
262 "1 - Set fw option to hold ABTS.");
264 int ql2xmvasynctoatio = 1;
265 module_param(ql2xmvasynctoatio, int, S_IRUGO|S_IWUSR);
266 MODULE_PARM_DESC(ql2xmvasynctoatio,
267 "Move PUREX, ABTS RX and RIDA IOCBs to ATIOQ"
268 "0 (Default). Do not move IOCBs"
271 int ql2xautodetectsfp = 1;
272 module_param(ql2xautodetectsfp, int, 0444);
273 MODULE_PARM_DESC(ql2xautodetectsfp,
274 "Detect SFP range and set appropriate distance.\n"
275 "1 (Default): Enable\n");
277 int ql2xenablemsix = 1;
278 module_param(ql2xenablemsix, int, 0444);
279 MODULE_PARM_DESC(ql2xenablemsix,
280 "Set to enable MSI or MSI-X interrupt mechanism.\n"
281 " Default is 1, enable MSI-X interrupt mechanism.\n"
282 " 0 -- enable traditional pin-based mechanism.\n"
283 " 1 -- enable MSI-X interrupt mechanism.\n"
284 " 2 -- enable MSI interrupt mechanism.\n");
286 int qla2xuseresexchforels;
287 module_param(qla2xuseresexchforels, int, 0444);
288 MODULE_PARM_DESC(qla2xuseresexchforels,
289 "Reserve 1/2 of emergency exchanges for ELS.\n"
290 " 0 (default): disabled");
292 static int ql2xprotmask;
293 module_param(ql2xprotmask, int, 0644);
294 MODULE_PARM_DESC(ql2xprotmask,
295 "Override DIF/DIX protection capabilities mask\n"
296 "Default is 0 which sets protection mask based on "
297 "capabilities reported by HBA firmware.\n");
299 static int ql2xprotguard;
300 module_param(ql2xprotguard, int, 0644);
301 MODULE_PARM_DESC(ql2xprotguard, "Override choice of DIX checksum\n"
302 " 0 -- Let HBA firmware decide\n"
303 " 1 -- Force T10 CRC\n"
304 " 2 -- Force IP checksum\n");
306 int ql2xdifbundlinginternalbuffers;
307 module_param(ql2xdifbundlinginternalbuffers, int, 0644);
308 MODULE_PARM_DESC(ql2xdifbundlinginternalbuffers,
309 "Force using internal buffers for DIF information\n"
310 "0 (Default). Based on check.\n"
311 "1 Force using internal buffers\n");
314 module_param(ql2xsmartsan, int, 0444);
315 module_param_named(smartsan, ql2xsmartsan, int, 0444);
316 MODULE_PARM_DESC(ql2xsmartsan,
317 "Send SmartSAN Management Attributes for FDMI Registration."
318 " Default is 0 - No SmartSAN registration,"
319 " 1 - Register SmartSAN Management Attributes.");
322 module_param(ql2xrdpenable, int, 0444);
323 module_param_named(rdpenable, ql2xrdpenable, int, 0444);
324 MODULE_PARM_DESC(ql2xrdpenable,
325 "Enables RDP responses. "
326 "0 - no RDP responses (default). "
327 "1 - provide RDP responses.");
328 int ql2xabts_wait_nvme = 1;
329 module_param(ql2xabts_wait_nvme, int, 0444);
330 MODULE_PARM_DESC(ql2xabts_wait_nvme,
331 "To wait for ABTS response on I/O timeouts for NVMe. (default: 1)");
334 static u32 ql2xdelay_before_pci_error_handling = 5;
335 module_param(ql2xdelay_before_pci_error_handling, uint, 0644);
336 MODULE_PARM_DESC(ql2xdelay_before_pci_error_handling,
337 "Number of seconds delayed before qla begin PCI error self-handling (default: 5).\n");
339 static void qla2x00_clear_drv_active(struct qla_hw_data *);
340 static void qla2x00_free_device(scsi_qla_host_t *);
341 static void qla2xxx_map_queues(struct Scsi_Host *shost);
342 static void qla2x00_destroy_deferred_work(struct qla_hw_data *);
344 u32 ql2xnvme_queues = DEF_NVME_HW_QUEUES;
345 module_param(ql2xnvme_queues, uint, S_IRUGO);
346 MODULE_PARM_DESC(ql2xnvme_queues,
347 "Number of NVMe Queues that can be configured.\n"
348 "Final value will be min(ql2xnvme_queues, num_cpus,num_chip_queues)\n"
349 "1 - Minimum number of queues supported\n"
350 "8 - Default value");
352 int ql2xfc2target = 1;
353 module_param(ql2xfc2target, int, 0444);
354 MODULE_PARM_DESC(qla2xfc2target,
355 "Enables FC2 Target support. "
356 "0 - FC2 Target support is disabled. "
357 "1 - FC2 Target support is enabled (default).");
359 static struct scsi_transport_template *qla2xxx_transport_template = NULL;
360 struct scsi_transport_template *qla2xxx_transport_vport_template = NULL;
362 /* TODO Convert to inlines
368 qla2x00_start_timer(scsi_qla_host_t *vha, unsigned long interval)
370 timer_setup(&vha->timer, qla2x00_timer, 0);
371 vha->timer.expires = jiffies + interval * HZ;
372 add_timer(&vha->timer);
373 vha->timer_active = 1;
377 qla2x00_restart_timer(scsi_qla_host_t *vha, unsigned long interval)
379 /* Currently used for 82XX only. */
380 if (vha->device_flags & DFLG_DEV_FAILED) {
381 ql_dbg(ql_dbg_timer, vha, 0x600d,
382 "Device in a failed state, returning.\n");
386 mod_timer(&vha->timer, jiffies + interval * HZ);
389 static __inline__ void
390 qla2x00_stop_timer(scsi_qla_host_t *vha)
392 timer_delete_sync(&vha->timer);
393 vha->timer_active = 0;
396 static int qla2x00_do_dpc(void *data);
398 static void qla2x00_rst_aen(scsi_qla_host_t *);
400 static int qla2x00_mem_alloc(struct qla_hw_data *, uint16_t, uint16_t,
401 struct req_que **, struct rsp_que **);
402 static void qla2x00_free_fw_dump(struct qla_hw_data *);
403 static void qla2x00_mem_free(struct qla_hw_data *);
404 int qla2xxx_mqueuecommand(struct Scsi_Host *host, struct scsi_cmnd *cmd,
405 struct qla_qpair *qpair);
407 /* -------------------------------------------------------------------------- */
408 static void qla_init_base_qpair(struct scsi_qla_host *vha, struct req_que *req,
411 struct qla_hw_data *ha = vha->hw;
413 rsp->qpair = ha->base_qpair;
415 ha->base_qpair->hw = ha;
416 ha->base_qpair->req = req;
417 ha->base_qpair->rsp = rsp;
418 ha->base_qpair->vha = vha;
419 ha->base_qpair->qp_lock_ptr = &ha->hardware_lock;
420 ha->base_qpair->use_shadow_reg = IS_SHADOW_REG_CAPABLE(ha) ? 1 : 0;
421 ha->base_qpair->msix = &ha->msix_entries[QLA_MSIX_RSP_Q];
422 ha->base_qpair->srb_mempool = ha->srb_mempool;
423 INIT_LIST_HEAD(&ha->base_qpair->hints_list);
424 INIT_LIST_HEAD(&ha->base_qpair->dsd_list);
425 ha->base_qpair->enable_class_2 = ql2xenableclass2;
426 /* init qpair to this cpu. Will adjust at run time. */
427 qla_cpu_update(rsp->qpair, raw_smp_processor_id());
428 ha->base_qpair->pdev = ha->pdev;
430 if (IS_QLA27XX(ha) || IS_QLA83XX(ha) || IS_QLA28XX(ha))
431 ha->base_qpair->reqq_start_iocbs = qla_83xx_start_iocbs;
434 static int qla2x00_alloc_queues(struct qla_hw_data *ha, struct req_que *req,
437 scsi_qla_host_t *vha = pci_get_drvdata(ha->pdev);
439 ha->req_q_map = kcalloc(ha->max_req_queues, sizeof(struct req_que *),
441 if (!ha->req_q_map) {
442 ql_log(ql_log_fatal, vha, 0x003b,
443 "Unable to allocate memory for request queue ptrs.\n");
447 ha->rsp_q_map = kcalloc(ha->max_rsp_queues, sizeof(struct rsp_que *),
449 if (!ha->rsp_q_map) {
450 ql_log(ql_log_fatal, vha, 0x003c,
451 "Unable to allocate memory for response queue ptrs.\n");
455 ha->base_qpair = kzalloc(sizeof(struct qla_qpair), GFP_KERNEL);
456 if (ha->base_qpair == NULL) {
457 ql_log(ql_log_warn, vha, 0x00e0,
458 "Failed to allocate base queue pair memory.\n");
459 goto fail_base_qpair;
462 qla_init_base_qpair(vha, req, rsp);
464 if ((ql2xmqsupport || ql2xnvmeenable) && ha->max_qpairs) {
465 ha->queue_pair_map = kcalloc(ha->max_qpairs, sizeof(struct qla_qpair *),
467 if (!ha->queue_pair_map) {
468 ql_log(ql_log_fatal, vha, 0x0180,
469 "Unable to allocate memory for queue pair ptrs.\n");
472 if (qla_mapq_alloc_qp_cpu_map(ha) != 0) {
473 kfree(ha->queue_pair_map);
474 ha->queue_pair_map = NULL;
480 * Make sure we record at least the request and response queue zero in
481 * case we need to free them if part of the probe fails.
483 ha->rsp_q_map[0] = rsp;
484 ha->req_q_map[0] = req;
485 set_bit(0, ha->rsp_qid_map);
486 set_bit(0, ha->req_qid_map);
490 kfree(ha->base_qpair);
491 ha->base_qpair = NULL;
493 kfree(ha->rsp_q_map);
494 ha->rsp_q_map = NULL;
496 kfree(ha->req_q_map);
497 ha->req_q_map = NULL;
502 static void qla2x00_free_req_que(struct qla_hw_data *ha, struct req_que *req)
504 if (IS_QLAFX00(ha)) {
505 if (req && req->ring_fx00)
506 dma_free_coherent(&ha->pdev->dev,
507 (req->length_fx00 + 1) * sizeof(request_t),
508 req->ring_fx00, req->dma_fx00);
509 } else if (req && req->ring)
510 dma_free_coherent(&ha->pdev->dev,
511 (req->length + 1) * sizeof(request_t),
512 req->ring, req->dma);
515 kfree(req->outstanding_cmds);
520 static void qla2x00_free_rsp_que(struct qla_hw_data *ha, struct rsp_que *rsp)
522 if (IS_QLAFX00(ha)) {
523 if (rsp && rsp->ring_fx00)
524 dma_free_coherent(&ha->pdev->dev,
525 (rsp->length_fx00 + 1) * sizeof(request_t),
526 rsp->ring_fx00, rsp->dma_fx00);
527 } else if (rsp && rsp->ring) {
528 dma_free_coherent(&ha->pdev->dev,
529 (rsp->length + 1) * sizeof(response_t),
530 rsp->ring, rsp->dma);
535 static void qla2x00_free_queues(struct qla_hw_data *ha)
542 if (ha->queue_pair_map) {
543 kfree(ha->queue_pair_map);
544 ha->queue_pair_map = NULL;
546 if (ha->base_qpair) {
547 kfree(ha->base_qpair);
548 ha->base_qpair = NULL;
551 qla_mapq_free_qp_cpu_map(ha);
552 spin_lock_irqsave(&ha->hardware_lock, flags);
553 for (cnt = 0; cnt < ha->max_req_queues; cnt++) {
554 if (!test_bit(cnt, ha->req_qid_map))
557 req = ha->req_q_map[cnt];
558 clear_bit(cnt, ha->req_qid_map);
559 ha->req_q_map[cnt] = NULL;
561 spin_unlock_irqrestore(&ha->hardware_lock, flags);
562 qla2x00_free_req_que(ha, req);
563 spin_lock_irqsave(&ha->hardware_lock, flags);
565 spin_unlock_irqrestore(&ha->hardware_lock, flags);
567 kfree(ha->req_q_map);
568 ha->req_q_map = NULL;
571 spin_lock_irqsave(&ha->hardware_lock, flags);
572 for (cnt = 0; cnt < ha->max_rsp_queues; cnt++) {
573 if (!test_bit(cnt, ha->rsp_qid_map))
576 rsp = ha->rsp_q_map[cnt];
577 clear_bit(cnt, ha->rsp_qid_map);
578 ha->rsp_q_map[cnt] = NULL;
579 spin_unlock_irqrestore(&ha->hardware_lock, flags);
580 qla2x00_free_rsp_que(ha, rsp);
581 spin_lock_irqsave(&ha->hardware_lock, flags);
583 spin_unlock_irqrestore(&ha->hardware_lock, flags);
585 kfree(ha->rsp_q_map);
586 ha->rsp_q_map = NULL;
590 qla2x00_pci_info_str(struct scsi_qla_host *vha, char *str, size_t str_len)
592 struct qla_hw_data *ha = vha->hw;
593 static const char *const pci_bus_modes[] = {
594 "33", "66", "100", "133",
598 pci_bus = (ha->pci_attr & (BIT_9 | BIT_10)) >> 9;
600 snprintf(str, str_len, "PCI-X (%s MHz)",
601 pci_bus_modes[pci_bus]);
603 pci_bus = (ha->pci_attr & BIT_8) >> 8;
604 snprintf(str, str_len, "PCI (%s MHz)", pci_bus_modes[pci_bus]);
611 qla24xx_pci_info_str(struct scsi_qla_host *vha, char *str, size_t str_len)
613 static const char *const pci_bus_modes[] = {
614 "33", "66", "100", "133",
616 struct qla_hw_data *ha = vha->hw;
619 if (pci_is_pcie(ha->pdev)) {
620 uint32_t lstat, lspeed, lwidth;
621 const char *speed_str;
623 pcie_capability_read_dword(ha->pdev, PCI_EXP_LNKCAP, &lstat);
624 lspeed = FIELD_GET(PCI_EXP_LNKCAP_SLS, lstat);
625 lwidth = FIELD_GET(PCI_EXP_LNKCAP_MLW, lstat);
629 speed_str = "2.5GT/s";
632 speed_str = "5.0GT/s";
635 speed_str = "8.0GT/s";
638 speed_str = "16.0GT/s";
641 speed_str = "<unknown>";
644 snprintf(str, str_len, "PCIe (%s x%d)", speed_str, lwidth);
649 pci_bus = (ha->pci_attr & CSRX_PCIX_BUS_MODE_MASK) >> 8;
650 if (pci_bus == 0 || pci_bus == 8)
651 snprintf(str, str_len, "PCI (%s MHz)",
652 pci_bus_modes[pci_bus >> 3]);
654 snprintf(str, str_len, "PCI-X Mode %d (%s MHz)",
656 pci_bus_modes[pci_bus & 3]);
662 qla2x00_fw_version_str(struct scsi_qla_host *vha, char *str, size_t size)
665 struct qla_hw_data *ha = vha->hw;
667 snprintf(str, size, "%d.%02d.%02d ", ha->fw_major_version,
668 ha->fw_minor_version, ha->fw_subminor_version);
670 if (ha->fw_attributes & BIT_9) {
675 switch (ha->fw_attributes & 0xFF) {
689 sprintf(un_str, "(%x)", ha->fw_attributes);
693 if (ha->fw_attributes & 0x100)
700 qla24xx_fw_version_str(struct scsi_qla_host *vha, char *str, size_t size)
702 struct qla_hw_data *ha = vha->hw;
704 snprintf(str, size, "%d.%02d.%02d (%x)", ha->fw_major_version,
705 ha->fw_minor_version, ha->fw_subminor_version, ha->fw_attributes);
709 void qla2x00_sp_free_dma(srb_t *sp)
711 struct qla_hw_data *ha = sp->vha->hw;
712 struct scsi_cmnd *cmd = GET_CMD_SP(sp);
714 if (sp->flags & SRB_DMA_VALID) {
716 sp->flags &= ~SRB_DMA_VALID;
719 if (sp->flags & SRB_CRC_PROT_DMA_VALID) {
720 dma_unmap_sg(&ha->pdev->dev, scsi_prot_sglist(cmd),
721 scsi_prot_sg_count(cmd), cmd->sc_data_direction);
722 sp->flags &= ~SRB_CRC_PROT_DMA_VALID;
725 if (sp->flags & SRB_CRC_CTX_DSD_VALID) {
726 /* List assured to be having elements */
727 qla2x00_clean_dsd_pool(ha, sp->u.scmd.crc_ctx);
728 sp->flags &= ~SRB_CRC_CTX_DSD_VALID;
731 if (sp->flags & SRB_CRC_CTX_DMA_VALID) {
732 struct crc_context *ctx0 = sp->u.scmd.crc_ctx;
734 dma_pool_free(ha->dl_dma_pool, ctx0, ctx0->crc_ctx_dma);
735 sp->flags &= ~SRB_CRC_CTX_DMA_VALID;
738 if (sp->flags & SRB_FCP_CMND_DMA_VALID) {
739 struct ct6_dsd *ctx1 = &sp->u.scmd.ct6_ctx;
741 dma_pool_free(ha->fcp_cmnd_dma_pool, ctx1->fcp_cmnd,
743 list_splice(&ctx1->dsd_list, &sp->qpair->dsd_list);
744 sp->qpair->dsd_inuse -= ctx1->dsd_use_cnt;
745 sp->qpair->dsd_avail += ctx1->dsd_use_cnt;
748 if (sp->flags & SRB_GOT_BUF)
749 qla_put_buf(sp->qpair, &sp->u.scmd.buf_dsc);
752 void qla2x00_sp_compl(srb_t *sp, int res)
754 struct scsi_cmnd *cmd = GET_CMD_SP(sp);
755 struct completion *comp = sp->comp;
758 kref_put(&sp->cmd_kref, qla2x00_sp_release);
766 void qla2xxx_qpair_sp_free_dma(srb_t *sp)
768 struct scsi_cmnd *cmd = GET_CMD_SP(sp);
769 struct qla_hw_data *ha = sp->fcport->vha->hw;
771 if (sp->flags & SRB_DMA_VALID) {
773 sp->flags &= ~SRB_DMA_VALID;
776 if (sp->flags & SRB_CRC_PROT_DMA_VALID) {
777 dma_unmap_sg(&ha->pdev->dev, scsi_prot_sglist(cmd),
778 scsi_prot_sg_count(cmd), cmd->sc_data_direction);
779 sp->flags &= ~SRB_CRC_PROT_DMA_VALID;
782 if (sp->flags & SRB_CRC_CTX_DSD_VALID) {
783 /* List assured to be having elements */
784 qla2x00_clean_dsd_pool(ha, sp->u.scmd.crc_ctx);
785 sp->flags &= ~SRB_CRC_CTX_DSD_VALID;
788 if (sp->flags & SRB_DIF_BUNDL_DMA_VALID) {
789 struct crc_context *difctx = sp->u.scmd.crc_ctx;
790 struct dsd_dma *dif_dsd, *nxt_dsd;
792 list_for_each_entry_safe(dif_dsd, nxt_dsd,
793 &difctx->ldif_dma_hndl_list, list) {
794 list_del(&dif_dsd->list);
795 dma_pool_free(ha->dif_bundl_pool, dif_dsd->dsd_addr,
796 dif_dsd->dsd_list_dma);
798 difctx->no_dif_bundl--;
801 list_for_each_entry_safe(dif_dsd, nxt_dsd,
802 &difctx->ldif_dsd_list, list) {
803 list_del(&dif_dsd->list);
804 dma_pool_free(ha->dl_dma_pool, dif_dsd->dsd_addr,
805 dif_dsd->dsd_list_dma);
807 difctx->no_ldif_dsd--;
810 if (difctx->no_ldif_dsd) {
811 ql_dbg(ql_dbg_tgt+ql_dbg_verbose, sp->vha, 0xe022,
812 "%s: difctx->no_ldif_dsd=%x\n",
813 __func__, difctx->no_ldif_dsd);
816 if (difctx->no_dif_bundl) {
817 ql_dbg(ql_dbg_tgt+ql_dbg_verbose, sp->vha, 0xe022,
818 "%s: difctx->no_dif_bundl=%x\n",
819 __func__, difctx->no_dif_bundl);
821 sp->flags &= ~SRB_DIF_BUNDL_DMA_VALID;
824 if (sp->flags & SRB_FCP_CMND_DMA_VALID) {
825 struct ct6_dsd *ctx1 = &sp->u.scmd.ct6_ctx;
827 dma_pool_free(ha->fcp_cmnd_dma_pool, ctx1->fcp_cmnd,
829 list_splice(&ctx1->dsd_list, &sp->qpair->dsd_list);
830 sp->qpair->dsd_inuse -= ctx1->dsd_use_cnt;
831 sp->qpair->dsd_avail += ctx1->dsd_use_cnt;
832 sp->flags &= ~SRB_FCP_CMND_DMA_VALID;
835 if (sp->flags & SRB_CRC_CTX_DMA_VALID) {
836 struct crc_context *ctx0 = sp->u.scmd.crc_ctx;
838 dma_pool_free(ha->dl_dma_pool, ctx0, ctx0->crc_ctx_dma);
839 sp->flags &= ~SRB_CRC_CTX_DMA_VALID;
842 if (sp->flags & SRB_GOT_BUF)
843 qla_put_buf(sp->qpair, &sp->u.scmd.buf_dsc);
846 void qla2xxx_qpair_sp_compl(srb_t *sp, int res)
848 struct scsi_cmnd *cmd = GET_CMD_SP(sp);
849 struct completion *comp = sp->comp;
852 kref_put(&sp->cmd_kref, qla2x00_sp_release);
861 qla2xxx_queuecommand(struct Scsi_Host *host, struct scsi_cmnd *cmd)
863 scsi_qla_host_t *vha = shost_priv(host);
864 fc_port_t *fcport = (struct fc_port *) cmd->device->hostdata;
865 struct fc_rport *rport = starget_to_rport(scsi_target(cmd->device));
866 struct qla_hw_data *ha = vha->hw;
867 struct scsi_qla_host *base_vha = pci_get_drvdata(ha->pdev);
871 if (unlikely(test_bit(UNLOADING, &base_vha->dpc_flags)) ||
872 WARN_ON_ONCE(!rport)) {
873 cmd->result = DID_NO_CONNECT << 16;
874 goto qc24_fail_command;
880 struct qla_qpair *qpair = NULL;
882 tag = blk_mq_unique_tag(scsi_cmd_to_rq(cmd));
883 hwq = blk_mq_unique_tag_to_hwq(tag);
884 qpair = ha->queue_pair_map[hwq];
887 return qla2xxx_mqueuecommand(host, cmd, qpair);
890 if (ha->flags.eeh_busy) {
891 if (ha->flags.pci_channel_io_perm_failure) {
892 ql_dbg(ql_dbg_aer, vha, 0x9010,
893 "PCI Channel IO permanent failure, exiting "
895 cmd->result = DID_NO_CONNECT << 16;
897 ql_dbg(ql_dbg_aer, vha, 0x9011,
898 "EEH_Busy, Requeuing the cmd=%p.\n", cmd);
899 cmd->result = DID_REQUEUE << 16;
901 goto qc24_fail_command;
904 rval = fc_remote_port_chkready(rport);
907 ql_dbg(ql_dbg_io + ql_dbg_verbose, vha, 0x3003,
908 "fc_remote_port_chkready failed for cmd=%p, rval=0x%x.\n",
910 goto qc24_fail_command;
913 if (!vha->flags.difdix_supported &&
914 scsi_get_prot_op(cmd) != SCSI_PROT_NORMAL) {
915 ql_dbg(ql_dbg_io, vha, 0x3004,
916 "DIF Cap not reg, fail DIF capable cmd's:%p.\n",
918 cmd->result = DID_NO_CONNECT << 16;
919 goto qc24_fail_command;
922 if (!fcport || fcport->deleted) {
923 cmd->result = DID_IMM_RETRY << 16;
924 goto qc24_fail_command;
927 if (atomic_read(&fcport->state) != FCS_ONLINE || fcport->deleted) {
928 if (atomic_read(&fcport->state) == FCS_DEVICE_DEAD ||
929 atomic_read(&base_vha->loop_state) == LOOP_DEAD) {
930 ql_dbg(ql_dbg_io, vha, 0x3005,
931 "Returning DNC, fcport_state=%d loop_state=%d.\n",
932 atomic_read(&fcport->state),
933 atomic_read(&base_vha->loop_state));
934 cmd->result = DID_NO_CONNECT << 16;
935 goto qc24_fail_command;
937 goto qc24_target_busy;
941 * Return target busy if we've received a non-zero retry_delay_timer
944 if (fcport->retry_delay_timestamp == 0) {
945 /* retry delay not set */
946 } else if (time_after(jiffies, fcport->retry_delay_timestamp))
947 fcport->retry_delay_timestamp = 0;
949 goto qc24_target_busy;
951 sp = scsi_cmd_priv(cmd);
953 qla2xxx_init_sp(sp, vha, vha->hw->base_qpair, fcport);
955 sp->u.scmd.cmd = cmd;
956 sp->type = SRB_SCSI_CMD;
957 sp->free = qla2x00_sp_free_dma;
958 sp->done = qla2x00_sp_compl;
960 rval = ha->isp_ops->start_scsi(sp);
961 if (rval != QLA_SUCCESS) {
962 ql_dbg(ql_dbg_io + ql_dbg_verbose, vha, 0x3013,
963 "Start scsi failed rval=%d for cmd=%p.\n", rval, cmd);
964 goto qc24_host_busy_free_sp;
969 qc24_host_busy_free_sp:
971 kref_put(&sp->cmd_kref, qla2x00_sp_release);
974 return SCSI_MLQUEUE_TARGET_BUSY;
982 /* For MQ supported I/O */
984 qla2xxx_mqueuecommand(struct Scsi_Host *host, struct scsi_cmnd *cmd,
985 struct qla_qpair *qpair)
987 scsi_qla_host_t *vha = shost_priv(host);
988 fc_port_t *fcport = (struct fc_port *) cmd->device->hostdata;
989 struct fc_rport *rport = starget_to_rport(scsi_target(cmd->device));
990 struct qla_hw_data *ha = vha->hw;
991 struct scsi_qla_host *base_vha = pci_get_drvdata(ha->pdev);
995 rval = rport ? fc_remote_port_chkready(rport) : (DID_NO_CONNECT << 16);
998 ql_dbg(ql_dbg_io + ql_dbg_verbose, vha, 0x3076,
999 "fc_remote_port_chkready failed for cmd=%p, rval=0x%x.\n",
1001 goto qc24_fail_command;
1004 if (!qpair->online) {
1005 ql_dbg(ql_dbg_io, vha, 0x3077,
1006 "qpair not online. eeh_busy=%d.\n", ha->flags.eeh_busy);
1007 cmd->result = DID_NO_CONNECT << 16;
1008 goto qc24_fail_command;
1011 if (!fcport || fcport->deleted) {
1012 cmd->result = DID_IMM_RETRY << 16;
1013 goto qc24_fail_command;
1016 if (atomic_read(&fcport->state) != FCS_ONLINE || fcport->deleted) {
1017 if (atomic_read(&fcport->state) == FCS_DEVICE_DEAD ||
1018 atomic_read(&base_vha->loop_state) == LOOP_DEAD) {
1019 ql_dbg(ql_dbg_io, vha, 0x3077,
1020 "Returning DNC, fcport_state=%d loop_state=%d.\n",
1021 atomic_read(&fcport->state),
1022 atomic_read(&base_vha->loop_state));
1023 cmd->result = DID_NO_CONNECT << 16;
1024 goto qc24_fail_command;
1026 goto qc24_target_busy;
1030 * Return target busy if we've received a non-zero retry_delay_timer
1033 if (fcport->retry_delay_timestamp == 0) {
1034 /* retry delay not set */
1035 } else if (time_after(jiffies, fcport->retry_delay_timestamp))
1036 fcport->retry_delay_timestamp = 0;
1038 goto qc24_target_busy;
1040 sp = scsi_cmd_priv(cmd);
1042 qla2xxx_init_sp(sp, vha, qpair, fcport);
1044 sp->u.scmd.cmd = cmd;
1045 sp->type = SRB_SCSI_CMD;
1046 sp->free = qla2xxx_qpair_sp_free_dma;
1047 sp->done = qla2xxx_qpair_sp_compl;
1049 rval = ha->isp_ops->start_scsi_mq(sp);
1050 if (rval != QLA_SUCCESS) {
1051 ql_dbg(ql_dbg_io + ql_dbg_verbose, vha, 0x3078,
1052 "Start scsi failed rval=%d for cmd=%p.\n", rval, cmd);
1053 goto qc24_host_busy_free_sp;
1058 qc24_host_busy_free_sp:
1060 kref_put(&sp->cmd_kref, qla2x00_sp_release);
1063 return SCSI_MLQUEUE_TARGET_BUSY;
1072 * qla2x00_wait_for_hba_online
1073 * Wait till the HBA is online after going through
1074 * <= MAX_RETRIES_OF_ISP_ABORT or
1075 * finally HBA is disabled ie marked offline
1078 * ha - pointer to host adapter structure
1081 * Does context switching-Release SPIN_LOCK
1082 * (if any) before calling this routine.
1085 * Success (Adapter is online) : 0
1086 * Failed (Adapter is offline/disabled) : 1
1089 qla2x00_wait_for_hba_online(scsi_qla_host_t *vha)
1092 unsigned long wait_online;
1093 struct qla_hw_data *ha = vha->hw;
1094 scsi_qla_host_t *base_vha = pci_get_drvdata(ha->pdev);
1096 wait_online = jiffies + (MAX_LOOP_TIMEOUT * HZ);
1097 while (((test_bit(ISP_ABORT_NEEDED, &base_vha->dpc_flags)) ||
1098 test_bit(ABORT_ISP_ACTIVE, &base_vha->dpc_flags) ||
1099 test_bit(ISP_ABORT_RETRY, &base_vha->dpc_flags) ||
1100 ha->dpc_active) && time_before(jiffies, wait_online)) {
1104 if (base_vha->flags.online)
1105 return_status = QLA_SUCCESS;
1107 return_status = QLA_FUNCTION_FAILED;
1109 return (return_status);
1112 static inline int test_fcport_count(scsi_qla_host_t *vha)
1114 struct qla_hw_data *ha = vha->hw;
1115 unsigned long flags;
1117 /* Return 0 = sleep, x=wake */
1119 spin_lock_irqsave(&ha->tgt.sess_lock, flags);
1120 ql_dbg(ql_dbg_init, vha, 0x00ec,
1121 "tgt %p, fcport_count=%d\n",
1122 vha, vha->fcport_count);
1123 res = (vha->fcport_count == 0);
1125 struct fc_port *fcport;
1127 list_for_each_entry(fcport, &vha->vp_fcports, list) {
1128 if (fcport->deleted != QLA_SESS_DELETED) {
1129 /* session(s) may not be fully logged in
1130 * (ie fcport_count=0), but session
1131 * deletion thread(s) may be inflight.
1139 spin_unlock_irqrestore(&ha->tgt.sess_lock, flags);
1145 * qla2x00_wait_for_sess_deletion can only be called from remove_one.
1146 * it has dependency on UNLOADING flag to stop device discovery
1149 qla2x00_wait_for_sess_deletion(scsi_qla_host_t *vha)
1153 qla2x00_mark_all_devices_lost(vha);
1155 for (i = 0; i < 10; i++) {
1156 if (wait_event_timeout(vha->fcport_waitQ,
1157 test_fcport_count(vha), HZ) > 0)
1161 flush_workqueue(vha->hw->wq);
1165 * qla2x00_wait_for_hba_ready
1166 * Wait till the HBA is ready before doing driver unload
1169 * ha - pointer to host adapter structure
1172 * Does context switching-Release SPIN_LOCK
1173 * (if any) before calling this routine.
1177 qla2x00_wait_for_hba_ready(scsi_qla_host_t *vha)
1179 struct qla_hw_data *ha = vha->hw;
1180 scsi_qla_host_t *base_vha = pci_get_drvdata(ha->pdev);
1182 while ((qla2x00_reset_active(vha) || ha->dpc_active ||
1183 ha->flags.mbox_busy) ||
1184 test_bit(FX00_RESET_RECOVERY, &vha->dpc_flags) ||
1185 test_bit(FX00_TARGET_SCAN, &vha->dpc_flags)) {
1186 if (test_bit(UNLOADING, &base_vha->dpc_flags))
1193 qla2x00_wait_for_chip_reset(scsi_qla_host_t *vha)
1196 unsigned long wait_reset;
1197 struct qla_hw_data *ha = vha->hw;
1198 scsi_qla_host_t *base_vha = pci_get_drvdata(ha->pdev);
1200 wait_reset = jiffies + (MAX_LOOP_TIMEOUT * HZ);
1201 while (((test_bit(ISP_ABORT_NEEDED, &base_vha->dpc_flags)) ||
1202 test_bit(ABORT_ISP_ACTIVE, &base_vha->dpc_flags) ||
1203 test_bit(ISP_ABORT_RETRY, &base_vha->dpc_flags) ||
1204 ha->dpc_active) && time_before(jiffies, wait_reset)) {
1208 if (!test_bit(ISP_ABORT_NEEDED, &base_vha->dpc_flags) &&
1209 ha->flags.chip_reset_done)
1212 if (ha->flags.chip_reset_done)
1213 return_status = QLA_SUCCESS;
1215 return_status = QLA_FUNCTION_FAILED;
1217 return return_status;
1220 /**************************************************************************
1224 * The abort function will abort the specified command.
1227 * cmd = Linux SCSI command packet to be aborted.
1230 * Either SUCCESS or FAILED.
1233 * Only return FAILED if command not returned by firmware.
1234 **************************************************************************/
1236 qla2xxx_eh_abort(struct scsi_cmnd *cmd)
1238 scsi_qla_host_t *vha = shost_priv(cmd->device->host);
1239 DECLARE_COMPLETION_ONSTACK(comp);
1245 struct qla_hw_data *ha = vha->hw;
1247 struct qla_qpair *qpair;
1248 unsigned long flags;
1249 int fast_fail_status = SUCCESS;
1251 if (qla2x00_isp_reg_stat(ha)) {
1252 ql_log(ql_log_info, vha, 0x8042,
1253 "PCI/Register disconnect, exiting.\n");
1254 qla_pci_set_eeh_busy(vha);
1258 /* Save any FAST_IO_FAIL value to return later if abort succeeds */
1259 ret = fc_block_scsi_eh(cmd);
1261 fast_fail_status = ret;
1263 sp = scsi_cmd_priv(cmd);
1266 vha->cmd_timeout_cnt++;
1268 if ((sp->fcport && sp->fcport->deleted) || !qpair)
1269 return fast_fail_status != SUCCESS ? fast_fail_status : FAILED;
1271 spin_lock_irqsave(qpair->qp_lock_ptr, flags);
1273 spin_unlock_irqrestore(qpair->qp_lock_ptr, flags);
1276 id = cmd->device->id;
1277 lun = cmd->device->lun;
1279 ql_dbg(ql_dbg_taskm, vha, 0x8002,
1280 "Aborting from RISC nexus=%ld:%d:%llu sp=%p cmd=%p handle=%x\n",
1281 vha->host_no, id, lun, sp, cmd, sp->handle);
1284 * Abort will release the original Command/sp from FW. Let the
1285 * original command call scsi_done. In return, he will wakeup
1286 * this sleeping thread.
1288 rval = ha->isp_ops->abort_command(sp);
1290 ql_dbg(ql_dbg_taskm, vha, 0x8003,
1291 "Abort command mbx cmd=%p, rval=%x.\n", cmd, rval);
1293 /* Wait for the command completion. */
1294 ratov_j = ha->r_a_tov/10 * 4 * 1000;
1295 ratov_j = msecs_to_jiffies(ratov_j);
1298 if (!wait_for_completion_timeout(&comp, ratov_j)) {
1299 ql_dbg(ql_dbg_taskm, vha, 0xffff,
1300 "%s: Abort wait timer (4 * R_A_TOV[%d]) expired\n",
1301 __func__, ha->r_a_tov/10);
1304 ret = fast_fail_status;
1314 ql_log(ql_log_info, vha, 0x801c,
1315 "Abort command issued nexus=%ld:%d:%llu -- %x.\n",
1316 vha->host_no, id, lun, ret);
1321 #define ABORT_POLLING_PERIOD 1000
1322 #define ABORT_WAIT_ITER ((2 * 1000) / (ABORT_POLLING_PERIOD))
1325 * Returns: QLA_SUCCESS or QLA_FUNCTION_FAILED.
1328 __qla2x00_eh_wait_for_pending_commands(struct qla_qpair *qpair, unsigned int t,
1329 uint64_t l, enum nexus_wait_type type)
1331 int cnt, match, status;
1332 unsigned long flags;
1333 scsi_qla_host_t *vha = qpair->vha;
1334 struct req_que *req = qpair->req;
1336 struct scsi_cmnd *cmd;
1337 unsigned long wait_iter = ABORT_WAIT_ITER;
1339 struct qla_hw_data *ha = vha->hw;
1341 status = QLA_SUCCESS;
1343 while (wait_iter--) {
1346 spin_lock_irqsave(qpair->qp_lock_ptr, flags);
1347 for (cnt = 1; cnt < req->num_outstanding_cmds; cnt++) {
1348 sp = req->outstanding_cmds[cnt];
1351 if (sp->type != SRB_SCSI_CMD)
1353 if (vha->vp_idx != sp->vha->vp_idx)
1356 cmd = GET_CMD_SP(sp);
1363 match = sp->fcport->d_id.b24 == t;
1369 match = (sp->fcport->d_id.b24 == t &&
1370 cmd->device->lun == l);
1378 spin_unlock_irqrestore(qpair->qp_lock_ptr, flags);
1380 if (unlikely(pci_channel_offline(ha->pdev)) ||
1381 ha->flags.eeh_busy) {
1382 ql_dbg(ql_dbg_taskm, vha, 0x8005,
1383 "Return:eh_wait.\n");
1388 * SRB_SCSI_CMD is still in the outstanding_cmds array.
1389 * it means scsi_done has not called. Wait for it to
1390 * clear from outstanding_cmds.
1392 msleep(ABORT_POLLING_PERIOD);
1393 spin_lock_irqsave(qpair->qp_lock_ptr, flags);
1396 spin_unlock_irqrestore(qpair->qp_lock_ptr, flags);
1402 if (wait_iter == -1)
1403 status = QLA_FUNCTION_FAILED;
1409 qla2x00_eh_wait_for_pending_commands(scsi_qla_host_t *vha, unsigned int t,
1410 uint64_t l, enum nexus_wait_type type)
1412 struct qla_qpair *qpair;
1413 struct qla_hw_data *ha = vha->hw;
1414 int i, status = QLA_SUCCESS;
1416 status = __qla2x00_eh_wait_for_pending_commands(ha->base_qpair, t, l,
1418 for (i = 0; status == QLA_SUCCESS && i < ha->max_qpairs; i++) {
1419 qpair = ha->queue_pair_map[i];
1422 status = __qla2x00_eh_wait_for_pending_commands(qpair, t, l,
1428 static char *reset_errors[] = {
1431 "Task management failed",
1432 "Waiting for command completions",
1436 qla2xxx_eh_device_reset(struct scsi_cmnd *cmd)
1438 struct scsi_device *sdev = cmd->device;
1439 scsi_qla_host_t *vha = shost_priv(sdev->host);
1440 struct fc_rport *rport = starget_to_rport(scsi_target(sdev));
1441 fc_port_t *fcport = (struct fc_port *) sdev->hostdata;
1442 struct qla_hw_data *ha = vha->hw;
1445 if (qla2x00_isp_reg_stat(ha)) {
1446 ql_log(ql_log_info, vha, 0x803e,
1447 "PCI/Register disconnect, exiting.\n");
1448 qla_pci_set_eeh_busy(vha);
1456 err = fc_block_rport(rport);
1460 if (fcport->deleted)
1463 ql_log(ql_log_info, vha, 0x8009,
1464 "DEVICE RESET ISSUED nexus=%ld:%d:%llu cmd=%p.\n", vha->host_no,
1465 sdev->id, sdev->lun, cmd);
1468 if (qla2x00_wait_for_hba_online(vha) != QLA_SUCCESS) {
1469 ql_log(ql_log_warn, vha, 0x800a,
1470 "Wait for hba online failed for cmd=%p.\n", cmd);
1471 goto eh_reset_failed;
1474 if (ha->isp_ops->lun_reset(fcport, sdev->lun, 1)
1476 ql_log(ql_log_warn, vha, 0x800c,
1477 "do_reset failed for cmd=%p.\n", cmd);
1478 goto eh_reset_failed;
1481 if (qla2x00_eh_wait_for_pending_commands(vha, fcport->d_id.b24,
1483 WAIT_LUN) != QLA_SUCCESS) {
1484 ql_log(ql_log_warn, vha, 0x800d,
1485 "wait for pending cmds failed for cmd=%p.\n", cmd);
1486 goto eh_reset_failed;
1489 ql_log(ql_log_info, vha, 0x800e,
1490 "DEVICE RESET SUCCEEDED nexus:%ld:%d:%llu cmd=%p.\n",
1491 vha->host_no, sdev->id, sdev->lun, cmd);
1496 ql_log(ql_log_info, vha, 0x800f,
1497 "DEVICE RESET FAILED: %s nexus=%ld:%d:%llu cmd=%p.\n",
1498 reset_errors[err], vha->host_no, sdev->id, sdev->lun,
1500 vha->reset_cmd_err_cnt++;
1505 qla2xxx_eh_target_reset(struct scsi_cmnd *cmd)
1507 struct scsi_device *sdev = cmd->device;
1508 struct fc_rport *rport = starget_to_rport(scsi_target(sdev));
1509 scsi_qla_host_t *vha = shost_priv(rport_to_shost(rport));
1510 struct qla_hw_data *ha = vha->hw;
1511 fc_port_t *fcport = *(fc_port_t **)rport->dd_data;
1514 if (qla2x00_isp_reg_stat(ha)) {
1515 ql_log(ql_log_info, vha, 0x803f,
1516 "PCI/Register disconnect, exiting.\n");
1517 qla_pci_set_eeh_busy(vha);
1525 err = fc_block_rport(rport);
1529 if (fcport->deleted)
1532 ql_log(ql_log_info, vha, 0x8009,
1533 "TARGET RESET ISSUED nexus=%ld:%d cmd=%p.\n", vha->host_no,
1537 if (qla2x00_wait_for_hba_online(vha) != QLA_SUCCESS) {
1538 ql_log(ql_log_warn, vha, 0x800a,
1539 "Wait for hba online failed for cmd=%p.\n", cmd);
1540 goto eh_reset_failed;
1543 if (ha->isp_ops->target_reset(fcport, 0, 0) != QLA_SUCCESS) {
1544 ql_log(ql_log_warn, vha, 0x800c,
1545 "target_reset failed for cmd=%p.\n", cmd);
1546 goto eh_reset_failed;
1549 if (qla2x00_eh_wait_for_pending_commands(vha, fcport->d_id.b24, 0,
1550 WAIT_TARGET) != QLA_SUCCESS) {
1551 ql_log(ql_log_warn, vha, 0x800d,
1552 "wait for pending cmds failed for cmd=%p.\n", cmd);
1553 goto eh_reset_failed;
1556 ql_log(ql_log_info, vha, 0x800e,
1557 "TARGET RESET SUCCEEDED nexus:%ld:%d cmd=%p.\n",
1558 vha->host_no, sdev->id, cmd);
1563 ql_log(ql_log_info, vha, 0x800f,
1564 "TARGET RESET FAILED: %s nexus=%ld:%d:%llu cmd=%p.\n",
1565 reset_errors[err], vha->host_no, cmd->device->id, cmd->device->lun,
1567 vha->reset_cmd_err_cnt++;
1571 /**************************************************************************
1572 * qla2xxx_eh_bus_reset
1575 * The bus reset function will reset the bus and abort any executing
1579 * cmd = Linux SCSI command packet of the command that cause the
1583 * SUCCESS/FAILURE (defined as macro in scsi.h).
1585 **************************************************************************/
1587 qla2xxx_eh_bus_reset(struct scsi_cmnd *cmd)
1589 scsi_qla_host_t *vha = shost_priv(cmd->device->host);
1593 struct qla_hw_data *ha = vha->hw;
1595 if (qla2x00_isp_reg_stat(ha)) {
1596 ql_log(ql_log_info, vha, 0x8040,
1597 "PCI/Register disconnect, exiting.\n");
1598 qla_pci_set_eeh_busy(vha);
1602 id = cmd->device->id;
1603 lun = cmd->device->lun;
1605 if (qla2x00_chip_is_down(vha))
1608 ql_log(ql_log_info, vha, 0x8012,
1609 "BUS RESET ISSUED nexus=%ld:%d:%llu.\n", vha->host_no, id, lun);
1611 if (qla2x00_wait_for_hba_online(vha) != QLA_SUCCESS) {
1612 ql_log(ql_log_fatal, vha, 0x8013,
1613 "Wait for hba online failed board disabled.\n");
1614 goto eh_bus_reset_done;
1617 if (qla2x00_loop_reset(vha) == QLA_SUCCESS)
1621 goto eh_bus_reset_done;
1623 /* Flush outstanding commands. */
1624 if (qla2x00_eh_wait_for_pending_commands(vha, 0, 0, WAIT_HOST) !=
1626 ql_log(ql_log_warn, vha, 0x8014,
1627 "Wait for pending commands failed.\n");
1632 ql_log(ql_log_warn, vha, 0x802b,
1633 "BUS RESET %s nexus=%ld:%d:%llu.\n",
1634 (ret == FAILED) ? "FAILED" : "SUCCEEDED", vha->host_no, id, lun);
1639 /**************************************************************************
1640 * qla2xxx_eh_host_reset
1643 * The reset function will reset the Adapter.
1646 * cmd = Linux SCSI command packet of the command that cause the
1650 * Either SUCCESS or FAILED.
1653 **************************************************************************/
1655 qla2xxx_eh_host_reset(struct scsi_cmnd *cmd)
1657 scsi_qla_host_t *vha = shost_priv(cmd->device->host);
1658 struct qla_hw_data *ha = vha->hw;
1662 scsi_qla_host_t *base_vha = pci_get_drvdata(ha->pdev);
1664 if (qla2x00_isp_reg_stat(ha)) {
1665 ql_log(ql_log_info, vha, 0x8041,
1666 "PCI/Register disconnect, exiting.\n");
1667 qla_pci_set_eeh_busy(vha);
1671 id = cmd->device->id;
1672 lun = cmd->device->lun;
1674 ql_log(ql_log_info, vha, 0x8018,
1675 "ADAPTER RESET ISSUED nexus=%ld:%d:%llu.\n", vha->host_no, id, lun);
1678 * No point in issuing another reset if one is active. Also do not
1679 * attempt a reset if we are updating flash.
1681 if (qla2x00_reset_active(vha) || ha->optrom_state != QLA_SWAITING)
1682 goto eh_host_reset_lock;
1684 if (vha != base_vha) {
1685 if (qla2x00_vp_abort_isp(vha))
1686 goto eh_host_reset_lock;
1688 if (IS_P3P_TYPE(vha->hw)) {
1689 if (!qla82xx_fcoe_ctx_reset(vha)) {
1690 /* Ctx reset success */
1692 goto eh_host_reset_lock;
1694 /* fall thru if ctx reset failed */
1697 flush_workqueue(ha->wq);
1699 set_bit(ABORT_ISP_ACTIVE, &base_vha->dpc_flags);
1700 if (ha->isp_ops->abort_isp(base_vha)) {
1701 clear_bit(ABORT_ISP_ACTIVE, &base_vha->dpc_flags);
1702 /* failed. schedule dpc to try */
1703 set_bit(ISP_ABORT_NEEDED, &base_vha->dpc_flags);
1705 if (qla2x00_wait_for_hba_online(vha) != QLA_SUCCESS) {
1706 ql_log(ql_log_warn, vha, 0x802a,
1707 "wait for hba online failed.\n");
1708 goto eh_host_reset_lock;
1711 clear_bit(ABORT_ISP_ACTIVE, &base_vha->dpc_flags);
1714 /* Waiting for command to be returned to OS.*/
1715 if (qla2x00_eh_wait_for_pending_commands(vha, 0, 0, WAIT_HOST) ==
1720 ql_log(ql_log_info, vha, 0x8017,
1721 "ADAPTER RESET %s nexus=%ld:%d:%llu.\n",
1722 (ret == FAILED) ? "FAILED" : "SUCCEEDED", vha->host_no, id, lun);
1728 * qla2x00_loop_reset
1732 * ha = adapter block pointer.
1738 qla2x00_loop_reset(scsi_qla_host_t *vha)
1741 struct qla_hw_data *ha = vha->hw;
1746 if (ha->flags.enable_lip_full_login && !IS_CNA_CAPABLE(ha)) {
1747 atomic_set(&vha->loop_state, LOOP_DOWN);
1748 atomic_set(&vha->loop_down_timer, LOOP_DOWN_TIME);
1749 qla2x00_mark_all_devices_lost(vha);
1750 ret = qla2x00_full_login_lip(vha);
1751 if (ret != QLA_SUCCESS) {
1752 ql_dbg(ql_dbg_taskm, vha, 0x802d,
1753 "full_login_lip=%d.\n", ret);
1757 if (ha->flags.enable_lip_reset) {
1758 ret = qla2x00_lip_reset(vha);
1759 if (ret != QLA_SUCCESS)
1760 ql_dbg(ql_dbg_taskm, vha, 0x802e,
1761 "lip_reset failed (%d).\n", ret);
1764 /* Issue marker command only when we are going to start the I/O */
1765 vha->marker_needed = 1;
1771 * The caller must ensure that no completion interrupts will happen
1772 * while this function is in progress.
1774 static void qla2x00_abort_srb(struct qla_qpair *qp, srb_t *sp, const int res,
1775 unsigned long *flags)
1776 __releases(qp->qp_lock_ptr)
1777 __acquires(qp->qp_lock_ptr)
1779 DECLARE_COMPLETION_ONSTACK(comp);
1780 scsi_qla_host_t *vha = qp->vha;
1781 struct qla_hw_data *ha = vha->hw;
1782 struct scsi_cmnd *cmd = GET_CMD_SP(sp);
1787 lockdep_assert_held(qp->qp_lock_ptr);
1789 if (qla2x00_chip_is_down(vha)) {
1794 if (sp->type == SRB_NVME_CMD || sp->type == SRB_NVME_LS ||
1795 (sp->type == SRB_SCSI_CMD && !ha->flags.eeh_busy &&
1796 !test_bit(ABORT_ISP_ACTIVE, &vha->dpc_flags) &&
1797 !qla2x00_isp_reg_stat(ha))) {
1804 spin_unlock_irqrestore(qp->qp_lock_ptr, *flags);
1806 rval = ha->isp_ops->abort_command(sp);
1807 /* Wait for command completion. */
1809 ratov_j = ha->r_a_tov/10 * 4 * 1000;
1810 ratov_j = msecs_to_jiffies(ratov_j);
1813 if (wait_for_completion_timeout(&comp, ratov_j)) {
1814 ql_dbg(ql_dbg_taskm, vha, 0xffff,
1815 "%s: Abort wait timer (4 * R_A_TOV[%d]) expired\n",
1816 __func__, ha->r_a_tov/10);
1819 /* else FW return SP to driver */
1826 spin_lock_irqsave(qp->qp_lock_ptr, *flags);
1829 if (ret_cmd && blk_mq_request_started(scsi_cmd_to_rq(cmd)))
1843 * The caller must ensure that no completion interrupts will happen
1844 * while this function is in progress.
1847 __qla2x00_abort_all_cmds(struct qla_qpair *qp, int res)
1850 unsigned long flags;
1852 scsi_qla_host_t *vha = qp->vha;
1853 struct qla_hw_data *ha = vha->hw;
1854 struct req_que *req;
1855 struct qla_tgt *tgt = vha->vha_tgt.qla_tgt;
1856 struct qla_tgt_cmd *cmd;
1860 spin_lock_irqsave(qp->qp_lock_ptr, flags);
1862 for (cnt = 1; cnt < req->num_outstanding_cmds; cnt++) {
1863 sp = req->outstanding_cmds[cnt];
1865 if (qla2x00_chip_is_down(vha)) {
1866 req->outstanding_cmds[cnt] = NULL;
1871 switch (sp->cmd_type) {
1873 qla2x00_abort_srb(qp, sp, res, &flags);
1876 if (!vha->hw->tgt.tgt_ops || !tgt ||
1877 qla_ini_mode_enabled(vha)) {
1878 ql_dbg(ql_dbg_tgt_mgt, vha, 0xf003,
1879 "HOST-ABORT-HNDLR: dpc_flags=%lx. Target mode disabled\n",
1883 cmd = (struct qla_tgt_cmd *)sp;
1886 case TYPE_TGT_TMCMD:
1887 /* Skip task management functions. */
1892 req->outstanding_cmds[cnt] = NULL;
1895 spin_unlock_irqrestore(qp->qp_lock_ptr, flags);
1899 * The caller must ensure that no completion interrupts will happen
1900 * while this function is in progress.
1903 qla2x00_abort_all_cmds(scsi_qla_host_t *vha, int res)
1906 struct qla_hw_data *ha = vha->hw;
1908 /* Continue only if initialization complete. */
1909 if (!ha->base_qpair)
1911 __qla2x00_abort_all_cmds(ha->base_qpair, res);
1913 if (!ha->queue_pair_map)
1915 for (que = 0; que < ha->max_qpairs; que++) {
1916 if (!ha->queue_pair_map[que])
1919 __qla2x00_abort_all_cmds(ha->queue_pair_map[que], res);
1924 qla2xxx_sdev_init(struct scsi_device *sdev)
1926 struct fc_rport *rport = starget_to_rport(scsi_target(sdev));
1928 if (!rport || fc_remote_port_chkready(rport))
1931 sdev->hostdata = *(fc_port_t **)rport->dd_data;
1937 qla2xxx_sdev_configure(struct scsi_device *sdev, struct queue_limits *lim)
1939 scsi_qla_host_t *vha = shost_priv(sdev->host);
1940 struct req_que *req = vha->req;
1942 scsi_change_queue_depth(sdev, req->max_q_depth);
1947 qla2xxx_sdev_destroy(struct scsi_device *sdev)
1949 sdev->hostdata = NULL;
1953 * qla2x00_config_dma_addressing() - Configure OS DMA addressing method.
1956 * At exit, the @ha's flags.enable_64bit_addressing set to indicated
1957 * supported addressing method.
1960 qla2x00_config_dma_addressing(struct qla_hw_data *ha)
1962 /* Assume a 32bit DMA mask. */
1963 ha->flags.enable_64bit_addressing = 0;
1965 if (!dma_set_mask(&ha->pdev->dev, DMA_BIT_MASK(64))) {
1966 /* Any upper-dword bits set? */
1967 if (MSD(dma_get_required_mask(&ha->pdev->dev)) &&
1968 !dma_set_coherent_mask(&ha->pdev->dev, DMA_BIT_MASK(64))) {
1969 /* Ok, a 64bit DMA mask is applicable. */
1970 ha->flags.enable_64bit_addressing = 1;
1971 ha->isp_ops->calc_req_entries = qla2x00_calc_iocbs_64;
1972 ha->isp_ops->build_iocbs = qla2x00_build_scsi_iocbs_64;
1977 dma_set_mask(&ha->pdev->dev, DMA_BIT_MASK(32));
1978 dma_set_coherent_mask(&ha->pdev->dev, DMA_BIT_MASK(32));
1982 qla2x00_enable_intrs(struct qla_hw_data *ha)
1984 unsigned long flags = 0;
1985 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
1987 spin_lock_irqsave(&ha->hardware_lock, flags);
1988 ha->interrupts_on = 1;
1989 /* enable risc and host interrupts */
1990 wrt_reg_word(®->ictrl, ICR_EN_INT | ICR_EN_RISC);
1991 rd_reg_word(®->ictrl);
1992 spin_unlock_irqrestore(&ha->hardware_lock, flags);
1997 qla2x00_disable_intrs(struct qla_hw_data *ha)
1999 unsigned long flags = 0;
2000 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
2002 spin_lock_irqsave(&ha->hardware_lock, flags);
2003 ha->interrupts_on = 0;
2004 /* disable risc and host interrupts */
2005 wrt_reg_word(®->ictrl, 0);
2006 rd_reg_word(®->ictrl);
2007 spin_unlock_irqrestore(&ha->hardware_lock, flags);
2011 qla24xx_enable_intrs(struct qla_hw_data *ha)
2013 unsigned long flags = 0;
2014 struct device_reg_24xx __iomem *reg = &ha->iobase->isp24;
2016 spin_lock_irqsave(&ha->hardware_lock, flags);
2017 ha->interrupts_on = 1;
2018 wrt_reg_dword(®->ictrl, ICRX_EN_RISC_INT);
2019 rd_reg_dword(®->ictrl);
2020 spin_unlock_irqrestore(&ha->hardware_lock, flags);
2024 qla24xx_disable_intrs(struct qla_hw_data *ha)
2026 unsigned long flags = 0;
2027 struct device_reg_24xx __iomem *reg = &ha->iobase->isp24;
2029 if (IS_NOPOLLING_TYPE(ha))
2031 spin_lock_irqsave(&ha->hardware_lock, flags);
2032 ha->interrupts_on = 0;
2033 wrt_reg_dword(®->ictrl, 0);
2034 rd_reg_dword(®->ictrl);
2035 spin_unlock_irqrestore(&ha->hardware_lock, flags);
2039 qla2x00_iospace_config(struct qla_hw_data *ha)
2041 resource_size_t pio;
2044 if (pci_request_selected_regions(ha->pdev, ha->bars,
2045 QLA2XXX_DRIVER_NAME)) {
2046 ql_log_pci(ql_log_fatal, ha->pdev, 0x0011,
2047 "Failed to reserve PIO/MMIO regions (%s), aborting.\n",
2048 pci_name(ha->pdev));
2049 goto iospace_error_exit;
2051 if (!(ha->bars & 1))
2054 /* We only need PIO for Flash operations on ISP2312 v2 chips. */
2055 pio = pci_resource_start(ha->pdev, 0);
2056 if (pci_resource_flags(ha->pdev, 0) & IORESOURCE_IO) {
2057 if (pci_resource_len(ha->pdev, 0) < MIN_IOBASE_LEN) {
2058 ql_log_pci(ql_log_warn, ha->pdev, 0x0012,
2059 "Invalid pci I/O region size (%s).\n",
2060 pci_name(ha->pdev));
2064 ql_log_pci(ql_log_warn, ha->pdev, 0x0013,
2065 "Region #0 no a PIO resource (%s).\n",
2066 pci_name(ha->pdev));
2069 ha->pio_address = pio;
2070 ql_dbg_pci(ql_dbg_init, ha->pdev, 0x0014,
2071 "PIO address=%llu.\n",
2072 (unsigned long long)ha->pio_address);
2075 /* Use MMIO operations for all accesses. */
2076 if (!(pci_resource_flags(ha->pdev, 1) & IORESOURCE_MEM)) {
2077 ql_log_pci(ql_log_fatal, ha->pdev, 0x0015,
2078 "Region #1 not an MMIO resource (%s), aborting.\n",
2079 pci_name(ha->pdev));
2080 goto iospace_error_exit;
2082 if (pci_resource_len(ha->pdev, 1) < MIN_IOBASE_LEN) {
2083 ql_log_pci(ql_log_fatal, ha->pdev, 0x0016,
2084 "Invalid PCI mem region size (%s), aborting.\n",
2085 pci_name(ha->pdev));
2086 goto iospace_error_exit;
2089 ha->iobase = ioremap(pci_resource_start(ha->pdev, 1), MIN_IOBASE_LEN);
2091 ql_log_pci(ql_log_fatal, ha->pdev, 0x0017,
2092 "Cannot remap MMIO (%s), aborting.\n",
2093 pci_name(ha->pdev));
2094 goto iospace_error_exit;
2097 /* Determine queue resources */
2098 ha->max_req_queues = ha->max_rsp_queues = 1;
2099 ha->msix_count = QLA_BASE_VECTORS;
2101 /* Check if FW supports MQ or not */
2102 if (!(ha->fw_attributes & BIT_6))
2105 if (!ql2xmqsupport || !ql2xnvmeenable ||
2106 (!IS_QLA25XX(ha) && !IS_QLA81XX(ha)))
2109 ha->mqiobase = ioremap(pci_resource_start(ha->pdev, 3),
2110 pci_resource_len(ha->pdev, 3));
2112 ql_dbg_pci(ql_dbg_init, ha->pdev, 0x0018,
2113 "MQIO Base=%p.\n", ha->mqiobase);
2114 /* Read MSIX vector size of the board */
2115 pci_read_config_word(ha->pdev, QLA_PCI_MSIX_CONTROL, &msix);
2116 ha->msix_count = msix + 1;
2117 /* Max queues are bounded by available msix vectors */
2118 /* MB interrupt uses 1 vector */
2119 ha->max_req_queues = ha->msix_count - 1;
2120 ha->max_rsp_queues = ha->max_req_queues;
2121 /* Queue pairs is the max value minus the base queue pair */
2122 ha->max_qpairs = ha->max_rsp_queues - 1;
2123 ql_dbg_pci(ql_dbg_init, ha->pdev, 0x0188,
2124 "Max no of queues pairs: %d.\n", ha->max_qpairs);
2126 ql_log_pci(ql_log_info, ha->pdev, 0x001a,
2127 "MSI-X vector count: %d.\n", ha->msix_count);
2129 ql_log_pci(ql_log_info, ha->pdev, 0x001b,
2130 "BAR 3 not enabled.\n");
2133 ql_dbg_pci(ql_dbg_init, ha->pdev, 0x001c,
2134 "MSIX Count: %d.\n", ha->msix_count);
2143 qla83xx_iospace_config(struct qla_hw_data *ha)
2147 if (pci_request_selected_regions(ha->pdev, ha->bars,
2148 QLA2XXX_DRIVER_NAME)) {
2149 ql_log_pci(ql_log_fatal, ha->pdev, 0x0117,
2150 "Failed to reserve PIO/MMIO regions (%s), aborting.\n",
2151 pci_name(ha->pdev));
2153 goto iospace_error_exit;
2156 /* Use MMIO operations for all accesses. */
2157 if (!(pci_resource_flags(ha->pdev, 0) & IORESOURCE_MEM)) {
2158 ql_log_pci(ql_log_warn, ha->pdev, 0x0118,
2159 "Invalid pci I/O region size (%s).\n",
2160 pci_name(ha->pdev));
2161 goto iospace_error_exit;
2163 if (pci_resource_len(ha->pdev, 0) < MIN_IOBASE_LEN) {
2164 ql_log_pci(ql_log_warn, ha->pdev, 0x0119,
2165 "Invalid PCI mem region size (%s), aborting\n",
2166 pci_name(ha->pdev));
2167 goto iospace_error_exit;
2170 ha->iobase = ioremap(pci_resource_start(ha->pdev, 0), MIN_IOBASE_LEN);
2172 ql_log_pci(ql_log_fatal, ha->pdev, 0x011a,
2173 "Cannot remap MMIO (%s), aborting.\n",
2174 pci_name(ha->pdev));
2175 goto iospace_error_exit;
2178 /* 64bit PCI BAR - BAR2 will correspoond to region 4 */
2179 /* 83XX 26XX always use MQ type access for queues
2180 * - mbar 2, a.k.a region 4 */
2181 ha->max_req_queues = ha->max_rsp_queues = 1;
2182 ha->msix_count = QLA_BASE_VECTORS;
2183 ha->mqiobase = ioremap(pci_resource_start(ha->pdev, 4),
2184 pci_resource_len(ha->pdev, 4));
2186 if (!ha->mqiobase) {
2187 ql_log_pci(ql_log_fatal, ha->pdev, 0x011d,
2188 "BAR2/region4 not enabled\n");
2192 ha->msixbase = ioremap(pci_resource_start(ha->pdev, 2),
2193 pci_resource_len(ha->pdev, 2));
2195 /* Read MSIX vector size of the board */
2196 pci_read_config_word(ha->pdev,
2197 QLA_83XX_PCI_MSIX_CONTROL, &msix);
2198 ha->msix_count = (msix & PCI_MSIX_FLAGS_QSIZE) + 1;
2200 * By default, driver uses at least two msix vectors
2203 if (ql2xmqsupport || ql2xnvmeenable) {
2204 /* MB interrupt uses 1 vector */
2205 ha->max_req_queues = ha->msix_count - 1;
2207 /* ATIOQ needs 1 vector. That's 1 less QPair */
2208 if (QLA_TGT_MODE_ENABLED())
2209 ha->max_req_queues--;
2211 ha->max_rsp_queues = ha->max_req_queues;
2213 /* Queue pairs is the max value minus
2214 * the base queue pair */
2215 ha->max_qpairs = ha->max_req_queues - 1;
2216 ql_dbg_pci(ql_dbg_init, ha->pdev, 0x00e3,
2217 "Max no of queues pairs: %d.\n", ha->max_qpairs);
2219 ql_log_pci(ql_log_info, ha->pdev, 0x011c,
2220 "MSI-X vector count: %d.\n", ha->msix_count);
2222 ql_log_pci(ql_log_info, ha->pdev, 0x011e,
2223 "BAR 1 not enabled.\n");
2226 ql_dbg_pci(ql_dbg_init, ha->pdev, 0x011f,
2227 "MSIX Count: %d.\n", ha->msix_count);
2234 static struct isp_operations qla2100_isp_ops = {
2235 .pci_config = qla2100_pci_config,
2236 .reset_chip = qla2x00_reset_chip,
2237 .chip_diag = qla2x00_chip_diag,
2238 .config_rings = qla2x00_config_rings,
2239 .reset_adapter = qla2x00_reset_adapter,
2240 .nvram_config = qla2x00_nvram_config,
2241 .update_fw_options = qla2x00_update_fw_options,
2242 .load_risc = qla2x00_load_risc,
2243 .pci_info_str = qla2x00_pci_info_str,
2244 .fw_version_str = qla2x00_fw_version_str,
2245 .intr_handler = qla2100_intr_handler,
2246 .enable_intrs = qla2x00_enable_intrs,
2247 .disable_intrs = qla2x00_disable_intrs,
2248 .abort_command = qla2x00_abort_command,
2249 .target_reset = qla2x00_abort_target,
2250 .lun_reset = qla2x00_lun_reset,
2251 .fabric_login = qla2x00_login_fabric,
2252 .fabric_logout = qla2x00_fabric_logout,
2253 .calc_req_entries = qla2x00_calc_iocbs_32,
2254 .build_iocbs = qla2x00_build_scsi_iocbs_32,
2255 .prep_ms_iocb = qla2x00_prep_ms_iocb,
2256 .prep_ms_fdmi_iocb = qla2x00_prep_ms_fdmi_iocb,
2257 .read_nvram = qla2x00_read_nvram_data,
2258 .write_nvram = qla2x00_write_nvram_data,
2259 .fw_dump = qla2100_fw_dump,
2262 .beacon_blink = NULL,
2263 .read_optrom = qla2x00_read_optrom_data,
2264 .write_optrom = qla2x00_write_optrom_data,
2265 .get_flash_version = qla2x00_get_flash_version,
2266 .start_scsi = qla2x00_start_scsi,
2267 .start_scsi_mq = NULL,
2268 .abort_isp = qla2x00_abort_isp,
2269 .iospace_config = qla2x00_iospace_config,
2270 .initialize_adapter = qla2x00_initialize_adapter,
2273 static struct isp_operations qla2300_isp_ops = {
2274 .pci_config = qla2300_pci_config,
2275 .reset_chip = qla2x00_reset_chip,
2276 .chip_diag = qla2x00_chip_diag,
2277 .config_rings = qla2x00_config_rings,
2278 .reset_adapter = qla2x00_reset_adapter,
2279 .nvram_config = qla2x00_nvram_config,
2280 .update_fw_options = qla2x00_update_fw_options,
2281 .load_risc = qla2x00_load_risc,
2282 .pci_info_str = qla2x00_pci_info_str,
2283 .fw_version_str = qla2x00_fw_version_str,
2284 .intr_handler = qla2300_intr_handler,
2285 .enable_intrs = qla2x00_enable_intrs,
2286 .disable_intrs = qla2x00_disable_intrs,
2287 .abort_command = qla2x00_abort_command,
2288 .target_reset = qla2x00_abort_target,
2289 .lun_reset = qla2x00_lun_reset,
2290 .fabric_login = qla2x00_login_fabric,
2291 .fabric_logout = qla2x00_fabric_logout,
2292 .calc_req_entries = qla2x00_calc_iocbs_32,
2293 .build_iocbs = qla2x00_build_scsi_iocbs_32,
2294 .prep_ms_iocb = qla2x00_prep_ms_iocb,
2295 .prep_ms_fdmi_iocb = qla2x00_prep_ms_fdmi_iocb,
2296 .read_nvram = qla2x00_read_nvram_data,
2297 .write_nvram = qla2x00_write_nvram_data,
2298 .fw_dump = qla2300_fw_dump,
2299 .beacon_on = qla2x00_beacon_on,
2300 .beacon_off = qla2x00_beacon_off,
2301 .beacon_blink = qla2x00_beacon_blink,
2302 .read_optrom = qla2x00_read_optrom_data,
2303 .write_optrom = qla2x00_write_optrom_data,
2304 .get_flash_version = qla2x00_get_flash_version,
2305 .start_scsi = qla2x00_start_scsi,
2306 .start_scsi_mq = NULL,
2307 .abort_isp = qla2x00_abort_isp,
2308 .iospace_config = qla2x00_iospace_config,
2309 .initialize_adapter = qla2x00_initialize_adapter,
2312 static struct isp_operations qla24xx_isp_ops = {
2313 .pci_config = qla24xx_pci_config,
2314 .reset_chip = qla24xx_reset_chip,
2315 .chip_diag = qla24xx_chip_diag,
2316 .config_rings = qla24xx_config_rings,
2317 .reset_adapter = qla24xx_reset_adapter,
2318 .nvram_config = qla24xx_nvram_config,
2319 .update_fw_options = qla24xx_update_fw_options,
2320 .load_risc = qla24xx_load_risc,
2321 .pci_info_str = qla24xx_pci_info_str,
2322 .fw_version_str = qla24xx_fw_version_str,
2323 .intr_handler = qla24xx_intr_handler,
2324 .enable_intrs = qla24xx_enable_intrs,
2325 .disable_intrs = qla24xx_disable_intrs,
2326 .abort_command = qla24xx_abort_command,
2327 .target_reset = qla24xx_abort_target,
2328 .lun_reset = qla24xx_lun_reset,
2329 .fabric_login = qla24xx_login_fabric,
2330 .fabric_logout = qla24xx_fabric_logout,
2331 .calc_req_entries = NULL,
2332 .build_iocbs = NULL,
2333 .prep_ms_iocb = qla24xx_prep_ms_iocb,
2334 .prep_ms_fdmi_iocb = qla24xx_prep_ms_fdmi_iocb,
2335 .read_nvram = qla24xx_read_nvram_data,
2336 .write_nvram = qla24xx_write_nvram_data,
2337 .fw_dump = qla24xx_fw_dump,
2338 .beacon_on = qla24xx_beacon_on,
2339 .beacon_off = qla24xx_beacon_off,
2340 .beacon_blink = qla24xx_beacon_blink,
2341 .read_optrom = qla24xx_read_optrom_data,
2342 .write_optrom = qla24xx_write_optrom_data,
2343 .get_flash_version = qla24xx_get_flash_version,
2344 .start_scsi = qla24xx_start_scsi,
2345 .start_scsi_mq = NULL,
2346 .abort_isp = qla2x00_abort_isp,
2347 .iospace_config = qla2x00_iospace_config,
2348 .initialize_adapter = qla2x00_initialize_adapter,
2351 static struct isp_operations qla25xx_isp_ops = {
2352 .pci_config = qla25xx_pci_config,
2353 .reset_chip = qla24xx_reset_chip,
2354 .chip_diag = qla24xx_chip_diag,
2355 .config_rings = qla24xx_config_rings,
2356 .reset_adapter = qla24xx_reset_adapter,
2357 .nvram_config = qla24xx_nvram_config,
2358 .update_fw_options = qla24xx_update_fw_options,
2359 .load_risc = qla24xx_load_risc,
2360 .pci_info_str = qla24xx_pci_info_str,
2361 .fw_version_str = qla24xx_fw_version_str,
2362 .intr_handler = qla24xx_intr_handler,
2363 .enable_intrs = qla24xx_enable_intrs,
2364 .disable_intrs = qla24xx_disable_intrs,
2365 .abort_command = qla24xx_abort_command,
2366 .target_reset = qla24xx_abort_target,
2367 .lun_reset = qla24xx_lun_reset,
2368 .fabric_login = qla24xx_login_fabric,
2369 .fabric_logout = qla24xx_fabric_logout,
2370 .calc_req_entries = NULL,
2371 .build_iocbs = NULL,
2372 .prep_ms_iocb = qla24xx_prep_ms_iocb,
2373 .prep_ms_fdmi_iocb = qla24xx_prep_ms_fdmi_iocb,
2374 .read_nvram = qla25xx_read_nvram_data,
2375 .write_nvram = qla25xx_write_nvram_data,
2376 .fw_dump = qla25xx_fw_dump,
2377 .beacon_on = qla24xx_beacon_on,
2378 .beacon_off = qla24xx_beacon_off,
2379 .beacon_blink = qla24xx_beacon_blink,
2380 .read_optrom = qla25xx_read_optrom_data,
2381 .write_optrom = qla24xx_write_optrom_data,
2382 .get_flash_version = qla24xx_get_flash_version,
2383 .start_scsi = qla24xx_dif_start_scsi,
2384 .start_scsi_mq = qla2xxx_dif_start_scsi_mq,
2385 .abort_isp = qla2x00_abort_isp,
2386 .iospace_config = qla2x00_iospace_config,
2387 .initialize_adapter = qla2x00_initialize_adapter,
2390 static struct isp_operations qla81xx_isp_ops = {
2391 .pci_config = qla25xx_pci_config,
2392 .reset_chip = qla24xx_reset_chip,
2393 .chip_diag = qla24xx_chip_diag,
2394 .config_rings = qla24xx_config_rings,
2395 .reset_adapter = qla24xx_reset_adapter,
2396 .nvram_config = qla81xx_nvram_config,
2397 .update_fw_options = qla24xx_update_fw_options,
2398 .load_risc = qla81xx_load_risc,
2399 .pci_info_str = qla24xx_pci_info_str,
2400 .fw_version_str = qla24xx_fw_version_str,
2401 .intr_handler = qla24xx_intr_handler,
2402 .enable_intrs = qla24xx_enable_intrs,
2403 .disable_intrs = qla24xx_disable_intrs,
2404 .abort_command = qla24xx_abort_command,
2405 .target_reset = qla24xx_abort_target,
2406 .lun_reset = qla24xx_lun_reset,
2407 .fabric_login = qla24xx_login_fabric,
2408 .fabric_logout = qla24xx_fabric_logout,
2409 .calc_req_entries = NULL,
2410 .build_iocbs = NULL,
2411 .prep_ms_iocb = qla24xx_prep_ms_iocb,
2412 .prep_ms_fdmi_iocb = qla24xx_prep_ms_fdmi_iocb,
2414 .write_nvram = NULL,
2415 .fw_dump = qla81xx_fw_dump,
2416 .beacon_on = qla24xx_beacon_on,
2417 .beacon_off = qla24xx_beacon_off,
2418 .beacon_blink = qla83xx_beacon_blink,
2419 .read_optrom = qla25xx_read_optrom_data,
2420 .write_optrom = qla24xx_write_optrom_data,
2421 .get_flash_version = qla24xx_get_flash_version,
2422 .start_scsi = qla24xx_dif_start_scsi,
2423 .start_scsi_mq = qla2xxx_dif_start_scsi_mq,
2424 .abort_isp = qla2x00_abort_isp,
2425 .iospace_config = qla2x00_iospace_config,
2426 .initialize_adapter = qla2x00_initialize_adapter,
2429 static struct isp_operations qla82xx_isp_ops = {
2430 .pci_config = qla82xx_pci_config,
2431 .reset_chip = qla82xx_reset_chip,
2432 .chip_diag = qla24xx_chip_diag,
2433 .config_rings = qla82xx_config_rings,
2434 .reset_adapter = qla24xx_reset_adapter,
2435 .nvram_config = qla81xx_nvram_config,
2436 .update_fw_options = qla24xx_update_fw_options,
2437 .load_risc = qla82xx_load_risc,
2438 .pci_info_str = qla24xx_pci_info_str,
2439 .fw_version_str = qla24xx_fw_version_str,
2440 .intr_handler = qla82xx_intr_handler,
2441 .enable_intrs = qla82xx_enable_intrs,
2442 .disable_intrs = qla82xx_disable_intrs,
2443 .abort_command = qla24xx_abort_command,
2444 .target_reset = qla24xx_abort_target,
2445 .lun_reset = qla24xx_lun_reset,
2446 .fabric_login = qla24xx_login_fabric,
2447 .fabric_logout = qla24xx_fabric_logout,
2448 .calc_req_entries = NULL,
2449 .build_iocbs = NULL,
2450 .prep_ms_iocb = qla24xx_prep_ms_iocb,
2451 .prep_ms_fdmi_iocb = qla24xx_prep_ms_fdmi_iocb,
2452 .read_nvram = qla24xx_read_nvram_data,
2453 .write_nvram = qla24xx_write_nvram_data,
2454 .fw_dump = qla82xx_fw_dump,
2455 .beacon_on = qla82xx_beacon_on,
2456 .beacon_off = qla82xx_beacon_off,
2457 .beacon_blink = NULL,
2458 .read_optrom = qla82xx_read_optrom_data,
2459 .write_optrom = qla82xx_write_optrom_data,
2460 .get_flash_version = qla82xx_get_flash_version,
2461 .start_scsi = qla82xx_start_scsi,
2462 .start_scsi_mq = NULL,
2463 .abort_isp = qla82xx_abort_isp,
2464 .iospace_config = qla82xx_iospace_config,
2465 .initialize_adapter = qla2x00_initialize_adapter,
2468 static struct isp_operations qla8044_isp_ops = {
2469 .pci_config = qla82xx_pci_config,
2470 .reset_chip = qla82xx_reset_chip,
2471 .chip_diag = qla24xx_chip_diag,
2472 .config_rings = qla82xx_config_rings,
2473 .reset_adapter = qla24xx_reset_adapter,
2474 .nvram_config = qla81xx_nvram_config,
2475 .update_fw_options = qla24xx_update_fw_options,
2476 .load_risc = qla82xx_load_risc,
2477 .pci_info_str = qla24xx_pci_info_str,
2478 .fw_version_str = qla24xx_fw_version_str,
2479 .intr_handler = qla8044_intr_handler,
2480 .enable_intrs = qla82xx_enable_intrs,
2481 .disable_intrs = qla82xx_disable_intrs,
2482 .abort_command = qla24xx_abort_command,
2483 .target_reset = qla24xx_abort_target,
2484 .lun_reset = qla24xx_lun_reset,
2485 .fabric_login = qla24xx_login_fabric,
2486 .fabric_logout = qla24xx_fabric_logout,
2487 .calc_req_entries = NULL,
2488 .build_iocbs = NULL,
2489 .prep_ms_iocb = qla24xx_prep_ms_iocb,
2490 .prep_ms_fdmi_iocb = qla24xx_prep_ms_fdmi_iocb,
2492 .write_nvram = NULL,
2493 .fw_dump = qla8044_fw_dump,
2494 .beacon_on = qla82xx_beacon_on,
2495 .beacon_off = qla82xx_beacon_off,
2496 .beacon_blink = NULL,
2497 .read_optrom = qla8044_read_optrom_data,
2498 .write_optrom = qla8044_write_optrom_data,
2499 .get_flash_version = qla82xx_get_flash_version,
2500 .start_scsi = qla82xx_start_scsi,
2501 .start_scsi_mq = NULL,
2502 .abort_isp = qla8044_abort_isp,
2503 .iospace_config = qla82xx_iospace_config,
2504 .initialize_adapter = qla2x00_initialize_adapter,
2507 static struct isp_operations qla83xx_isp_ops = {
2508 .pci_config = qla25xx_pci_config,
2509 .reset_chip = qla24xx_reset_chip,
2510 .chip_diag = qla24xx_chip_diag,
2511 .config_rings = qla24xx_config_rings,
2512 .reset_adapter = qla24xx_reset_adapter,
2513 .nvram_config = qla81xx_nvram_config,
2514 .update_fw_options = qla24xx_update_fw_options,
2515 .load_risc = qla81xx_load_risc,
2516 .pci_info_str = qla24xx_pci_info_str,
2517 .fw_version_str = qla24xx_fw_version_str,
2518 .intr_handler = qla24xx_intr_handler,
2519 .enable_intrs = qla24xx_enable_intrs,
2520 .disable_intrs = qla24xx_disable_intrs,
2521 .abort_command = qla24xx_abort_command,
2522 .target_reset = qla24xx_abort_target,
2523 .lun_reset = qla24xx_lun_reset,
2524 .fabric_login = qla24xx_login_fabric,
2525 .fabric_logout = qla24xx_fabric_logout,
2526 .calc_req_entries = NULL,
2527 .build_iocbs = NULL,
2528 .prep_ms_iocb = qla24xx_prep_ms_iocb,
2529 .prep_ms_fdmi_iocb = qla24xx_prep_ms_fdmi_iocb,
2531 .write_nvram = NULL,
2532 .fw_dump = qla83xx_fw_dump,
2533 .beacon_on = qla24xx_beacon_on,
2534 .beacon_off = qla24xx_beacon_off,
2535 .beacon_blink = qla83xx_beacon_blink,
2536 .read_optrom = qla25xx_read_optrom_data,
2537 .write_optrom = qla24xx_write_optrom_data,
2538 .get_flash_version = qla24xx_get_flash_version,
2539 .start_scsi = qla24xx_dif_start_scsi,
2540 .start_scsi_mq = qla2xxx_dif_start_scsi_mq,
2541 .abort_isp = qla2x00_abort_isp,
2542 .iospace_config = qla83xx_iospace_config,
2543 .initialize_adapter = qla2x00_initialize_adapter,
2546 static struct isp_operations qlafx00_isp_ops = {
2547 .pci_config = qlafx00_pci_config,
2548 .reset_chip = qlafx00_soft_reset,
2549 .chip_diag = qlafx00_chip_diag,
2550 .config_rings = qlafx00_config_rings,
2551 .reset_adapter = qlafx00_soft_reset,
2552 .nvram_config = NULL,
2553 .update_fw_options = NULL,
2555 .pci_info_str = qlafx00_pci_info_str,
2556 .fw_version_str = qlafx00_fw_version_str,
2557 .intr_handler = qlafx00_intr_handler,
2558 .enable_intrs = qlafx00_enable_intrs,
2559 .disable_intrs = qlafx00_disable_intrs,
2560 .abort_command = qla24xx_async_abort_command,
2561 .target_reset = qlafx00_abort_target,
2562 .lun_reset = qlafx00_lun_reset,
2563 .fabric_login = NULL,
2564 .fabric_logout = NULL,
2565 .calc_req_entries = NULL,
2566 .build_iocbs = NULL,
2567 .prep_ms_iocb = qla24xx_prep_ms_iocb,
2568 .prep_ms_fdmi_iocb = qla24xx_prep_ms_fdmi_iocb,
2569 .read_nvram = qla24xx_read_nvram_data,
2570 .write_nvram = qla24xx_write_nvram_data,
2572 .beacon_on = qla24xx_beacon_on,
2573 .beacon_off = qla24xx_beacon_off,
2574 .beacon_blink = NULL,
2575 .read_optrom = qla24xx_read_optrom_data,
2576 .write_optrom = qla24xx_write_optrom_data,
2577 .get_flash_version = qla24xx_get_flash_version,
2578 .start_scsi = qlafx00_start_scsi,
2579 .start_scsi_mq = NULL,
2580 .abort_isp = qlafx00_abort_isp,
2581 .iospace_config = qlafx00_iospace_config,
2582 .initialize_adapter = qlafx00_initialize_adapter,
2585 static struct isp_operations qla27xx_isp_ops = {
2586 .pci_config = qla25xx_pci_config,
2587 .reset_chip = qla24xx_reset_chip,
2588 .chip_diag = qla24xx_chip_diag,
2589 .config_rings = qla24xx_config_rings,
2590 .reset_adapter = qla24xx_reset_adapter,
2591 .nvram_config = qla81xx_nvram_config,
2592 .update_fw_options = qla24xx_update_fw_options,
2593 .load_risc = qla81xx_load_risc,
2594 .pci_info_str = qla24xx_pci_info_str,
2595 .fw_version_str = qla24xx_fw_version_str,
2596 .intr_handler = qla24xx_intr_handler,
2597 .enable_intrs = qla24xx_enable_intrs,
2598 .disable_intrs = qla24xx_disable_intrs,
2599 .abort_command = qla24xx_abort_command,
2600 .target_reset = qla24xx_abort_target,
2601 .lun_reset = qla24xx_lun_reset,
2602 .fabric_login = qla24xx_login_fabric,
2603 .fabric_logout = qla24xx_fabric_logout,
2604 .calc_req_entries = NULL,
2605 .build_iocbs = NULL,
2606 .prep_ms_iocb = qla24xx_prep_ms_iocb,
2607 .prep_ms_fdmi_iocb = qla24xx_prep_ms_fdmi_iocb,
2609 .write_nvram = NULL,
2610 .fw_dump = qla27xx_fwdump,
2611 .mpi_fw_dump = qla27xx_mpi_fwdump,
2612 .beacon_on = qla24xx_beacon_on,
2613 .beacon_off = qla24xx_beacon_off,
2614 .beacon_blink = qla83xx_beacon_blink,
2615 .read_optrom = qla25xx_read_optrom_data,
2616 .write_optrom = qla24xx_write_optrom_data,
2617 .get_flash_version = qla24xx_get_flash_version,
2618 .start_scsi = qla24xx_dif_start_scsi,
2619 .start_scsi_mq = qla2xxx_dif_start_scsi_mq,
2620 .abort_isp = qla2x00_abort_isp,
2621 .iospace_config = qla83xx_iospace_config,
2622 .initialize_adapter = qla2x00_initialize_adapter,
2626 qla2x00_set_isp_flags(struct qla_hw_data *ha)
2628 ha->device_type = DT_EXTENDED_IDS;
2629 switch (ha->pdev->device) {
2630 case PCI_DEVICE_ID_QLOGIC_ISP2100:
2631 ha->isp_type |= DT_ISP2100;
2632 ha->device_type &= ~DT_EXTENDED_IDS;
2633 ha->fw_srisc_address = RISC_START_ADDRESS_2100;
2635 case PCI_DEVICE_ID_QLOGIC_ISP2200:
2636 ha->isp_type |= DT_ISP2200;
2637 ha->device_type &= ~DT_EXTENDED_IDS;
2638 ha->fw_srisc_address = RISC_START_ADDRESS_2100;
2640 case PCI_DEVICE_ID_QLOGIC_ISP2300:
2641 ha->isp_type |= DT_ISP2300;
2642 ha->device_type |= DT_ZIO_SUPPORTED;
2643 ha->fw_srisc_address = RISC_START_ADDRESS_2300;
2645 case PCI_DEVICE_ID_QLOGIC_ISP2312:
2646 ha->isp_type |= DT_ISP2312;
2647 ha->device_type |= DT_ZIO_SUPPORTED;
2648 ha->fw_srisc_address = RISC_START_ADDRESS_2300;
2650 case PCI_DEVICE_ID_QLOGIC_ISP2322:
2651 ha->isp_type |= DT_ISP2322;
2652 ha->device_type |= DT_ZIO_SUPPORTED;
2653 if (ha->pdev->subsystem_vendor == 0x1028 &&
2654 ha->pdev->subsystem_device == 0x0170)
2655 ha->device_type |= DT_OEM_001;
2656 ha->fw_srisc_address = RISC_START_ADDRESS_2300;
2658 case PCI_DEVICE_ID_QLOGIC_ISP6312:
2659 ha->isp_type |= DT_ISP6312;
2660 ha->fw_srisc_address = RISC_START_ADDRESS_2300;
2662 case PCI_DEVICE_ID_QLOGIC_ISP6322:
2663 ha->isp_type |= DT_ISP6322;
2664 ha->fw_srisc_address = RISC_START_ADDRESS_2300;
2666 case PCI_DEVICE_ID_QLOGIC_ISP2422:
2667 ha->isp_type |= DT_ISP2422;
2668 ha->device_type |= DT_ZIO_SUPPORTED;
2669 ha->device_type |= DT_FWI2;
2670 ha->device_type |= DT_IIDMA;
2671 ha->fw_srisc_address = RISC_START_ADDRESS_2400;
2673 case PCI_DEVICE_ID_QLOGIC_ISP2432:
2674 ha->isp_type |= DT_ISP2432;
2675 ha->device_type |= DT_ZIO_SUPPORTED;
2676 ha->device_type |= DT_FWI2;
2677 ha->device_type |= DT_IIDMA;
2678 ha->fw_srisc_address = RISC_START_ADDRESS_2400;
2680 case PCI_DEVICE_ID_QLOGIC_ISP8432:
2681 ha->isp_type |= DT_ISP8432;
2682 ha->device_type |= DT_ZIO_SUPPORTED;
2683 ha->device_type |= DT_FWI2;
2684 ha->device_type |= DT_IIDMA;
2685 ha->fw_srisc_address = RISC_START_ADDRESS_2400;
2687 case PCI_DEVICE_ID_QLOGIC_ISP5422:
2688 ha->isp_type |= DT_ISP5422;
2689 ha->device_type |= DT_FWI2;
2690 ha->fw_srisc_address = RISC_START_ADDRESS_2400;
2692 case PCI_DEVICE_ID_QLOGIC_ISP5432:
2693 ha->isp_type |= DT_ISP5432;
2694 ha->device_type |= DT_FWI2;
2695 ha->fw_srisc_address = RISC_START_ADDRESS_2400;
2697 case PCI_DEVICE_ID_QLOGIC_ISP2532:
2698 ha->isp_type |= DT_ISP2532;
2699 ha->device_type |= DT_ZIO_SUPPORTED;
2700 ha->device_type |= DT_FWI2;
2701 ha->device_type |= DT_IIDMA;
2702 ha->fw_srisc_address = RISC_START_ADDRESS_2400;
2704 case PCI_DEVICE_ID_QLOGIC_ISP8001:
2705 ha->isp_type |= DT_ISP8001;
2706 ha->device_type |= DT_ZIO_SUPPORTED;
2707 ha->device_type |= DT_FWI2;
2708 ha->device_type |= DT_IIDMA;
2709 ha->fw_srisc_address = RISC_START_ADDRESS_2400;
2711 case PCI_DEVICE_ID_QLOGIC_ISP8021:
2712 ha->isp_type |= DT_ISP8021;
2713 ha->device_type |= DT_ZIO_SUPPORTED;
2714 ha->device_type |= DT_FWI2;
2715 ha->fw_srisc_address = RISC_START_ADDRESS_2400;
2716 /* Initialize 82XX ISP flags */
2717 qla82xx_init_flags(ha);
2719 case PCI_DEVICE_ID_QLOGIC_ISP8044:
2720 ha->isp_type |= DT_ISP8044;
2721 ha->device_type |= DT_ZIO_SUPPORTED;
2722 ha->device_type |= DT_FWI2;
2723 ha->fw_srisc_address = RISC_START_ADDRESS_2400;
2724 /* Initialize 82XX ISP flags */
2725 qla82xx_init_flags(ha);
2727 case PCI_DEVICE_ID_QLOGIC_ISP2031:
2728 ha->isp_type |= DT_ISP2031;
2729 ha->device_type |= DT_ZIO_SUPPORTED;
2730 ha->device_type |= DT_FWI2;
2731 ha->device_type |= DT_IIDMA;
2732 ha->device_type |= DT_T10_PI;
2733 ha->fw_srisc_address = RISC_START_ADDRESS_2400;
2735 case PCI_DEVICE_ID_QLOGIC_ISP8031:
2736 ha->isp_type |= DT_ISP8031;
2737 ha->device_type |= DT_ZIO_SUPPORTED;
2738 ha->device_type |= DT_FWI2;
2739 ha->device_type |= DT_IIDMA;
2740 ha->device_type |= DT_T10_PI;
2741 ha->fw_srisc_address = RISC_START_ADDRESS_2400;
2743 case PCI_DEVICE_ID_QLOGIC_ISPF001:
2744 ha->isp_type |= DT_ISPFX00;
2746 case PCI_DEVICE_ID_QLOGIC_ISP2071:
2747 ha->isp_type |= DT_ISP2071;
2748 ha->device_type |= DT_ZIO_SUPPORTED;
2749 ha->device_type |= DT_FWI2;
2750 ha->device_type |= DT_IIDMA;
2751 ha->device_type |= DT_T10_PI;
2752 ha->fw_srisc_address = RISC_START_ADDRESS_2400;
2754 case PCI_DEVICE_ID_QLOGIC_ISP2271:
2755 ha->isp_type |= DT_ISP2271;
2756 ha->device_type |= DT_ZIO_SUPPORTED;
2757 ha->device_type |= DT_FWI2;
2758 ha->device_type |= DT_IIDMA;
2759 ha->device_type |= DT_T10_PI;
2760 ha->fw_srisc_address = RISC_START_ADDRESS_2400;
2762 case PCI_DEVICE_ID_QLOGIC_ISP2261:
2763 ha->isp_type |= DT_ISP2261;
2764 ha->device_type |= DT_ZIO_SUPPORTED;
2765 ha->device_type |= DT_FWI2;
2766 ha->device_type |= DT_IIDMA;
2767 ha->device_type |= DT_T10_PI;
2768 ha->fw_srisc_address = RISC_START_ADDRESS_2400;
2770 case PCI_DEVICE_ID_QLOGIC_ISP2081:
2771 case PCI_DEVICE_ID_QLOGIC_ISP2089:
2772 ha->isp_type |= DT_ISP2081;
2773 ha->device_type |= DT_ZIO_SUPPORTED;
2774 ha->device_type |= DT_FWI2;
2775 ha->device_type |= DT_IIDMA;
2776 ha->device_type |= DT_T10_PI;
2777 ha->fw_srisc_address = RISC_START_ADDRESS_2400;
2779 case PCI_DEVICE_ID_QLOGIC_ISP2281:
2780 case PCI_DEVICE_ID_QLOGIC_ISP2289:
2781 ha->isp_type |= DT_ISP2281;
2782 ha->device_type |= DT_ZIO_SUPPORTED;
2783 ha->device_type |= DT_FWI2;
2784 ha->device_type |= DT_IIDMA;
2785 ha->device_type |= DT_T10_PI;
2786 ha->fw_srisc_address = RISC_START_ADDRESS_2400;
2791 ha->port_no = ha->portnum & 1;
2793 /* Get adapter physical port no from interrupt pin register. */
2794 pci_read_config_byte(ha->pdev, PCI_INTERRUPT_PIN, &ha->port_no);
2795 if (IS_QLA25XX(ha) || IS_QLA2031(ha) ||
2796 IS_QLA27XX(ha) || IS_QLA28XX(ha))
2799 ha->port_no = !(ha->port_no & 1);
2802 ql_dbg_pci(ql_dbg_init, ha->pdev, 0x000b,
2803 "device_type=0x%x port=%d fw_srisc_address=0x%x.\n",
2804 ha->device_type, ha->port_no, ha->fw_srisc_address);
2808 qla2xxx_scan_start(struct Scsi_Host *shost)
2810 scsi_qla_host_t *vha = shost_priv(shost);
2812 if (vha->hw->flags.running_gold_fw)
2815 set_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags);
2816 set_bit(LOCAL_LOOP_UPDATE, &vha->dpc_flags);
2817 set_bit(RSCN_UPDATE, &vha->dpc_flags);
2818 set_bit(NPIV_CONFIG_NEEDED, &vha->dpc_flags);
2822 qla2xxx_scan_finished(struct Scsi_Host *shost, unsigned long time)
2824 scsi_qla_host_t *vha = shost_priv(shost);
2826 if (test_bit(UNLOADING, &vha->dpc_flags))
2830 if (time > vha->hw->loop_reset_delay * HZ)
2833 return atomic_read(&vha->loop_state) == LOOP_READY;
2836 static void qla_heartbeat_work_fn(struct work_struct *work)
2838 struct qla_hw_data *ha = container_of(work,
2839 struct qla_hw_data, heartbeat_work);
2840 struct scsi_qla_host *base_vha = pci_get_drvdata(ha->pdev);
2842 if (!ha->flags.mbox_busy && base_vha->flags.init_done)
2843 qla_no_op_mb(base_vha);
2846 static void qla2x00_iocb_work_fn(struct work_struct *work)
2848 struct scsi_qla_host *vha = container_of(work,
2849 struct scsi_qla_host, iocb_work);
2850 struct qla_hw_data *ha = vha->hw;
2851 struct scsi_qla_host *base_vha = pci_get_drvdata(ha->pdev);
2853 unsigned long flags;
2855 if (test_bit(UNLOADING, &base_vha->dpc_flags))
2858 while (!list_empty(&vha->work_list) && i > 0) {
2859 qla2x00_do_work(vha);
2863 spin_lock_irqsave(&vha->work_lock, flags);
2864 clear_bit(IOCB_WORK_ACTIVE, &vha->dpc_flags);
2865 spin_unlock_irqrestore(&vha->work_lock, flags);
2869 qla_trace_init(void)
2871 qla_trc_array = trace_array_get_by_name("qla2xxx", NULL);
2872 if (!qla_trc_array) {
2873 ql_log(ql_log_fatal, NULL, 0x0001,
2874 "Unable to create qla2xxx trace instance, instance logging will be disabled.\n");
2878 QLA_TRACE_ENABLE(qla_trc_array);
2882 qla_trace_uninit(void)
2886 trace_array_put(qla_trc_array);
2890 * PCI driver interface
2893 qla2x00_probe_one(struct pci_dev *pdev, const struct pci_device_id *id)
2896 struct Scsi_Host *host;
2897 scsi_qla_host_t *base_vha = NULL;
2898 struct qla_hw_data *ha;
2900 char fw_str[30], wq_name[30];
2901 struct scsi_host_template *sht;
2902 int bars, mem_only = 0;
2903 uint16_t req_length = 0, rsp_length = 0;
2904 struct req_que *req = NULL;
2905 struct rsp_que *rsp = NULL;
2908 bars = pci_select_bars(pdev, IORESOURCE_MEM | IORESOURCE_IO);
2909 sht = &qla2xxx_driver_template;
2910 if (pdev->device == PCI_DEVICE_ID_QLOGIC_ISP2422 ||
2911 pdev->device == PCI_DEVICE_ID_QLOGIC_ISP2432 ||
2912 pdev->device == PCI_DEVICE_ID_QLOGIC_ISP8432 ||
2913 pdev->device == PCI_DEVICE_ID_QLOGIC_ISP5422 ||
2914 pdev->device == PCI_DEVICE_ID_QLOGIC_ISP5432 ||
2915 pdev->device == PCI_DEVICE_ID_QLOGIC_ISP2532 ||
2916 pdev->device == PCI_DEVICE_ID_QLOGIC_ISP8001 ||
2917 pdev->device == PCI_DEVICE_ID_QLOGIC_ISP8021 ||
2918 pdev->device == PCI_DEVICE_ID_QLOGIC_ISP2031 ||
2919 pdev->device == PCI_DEVICE_ID_QLOGIC_ISP8031 ||
2920 pdev->device == PCI_DEVICE_ID_QLOGIC_ISPF001 ||
2921 pdev->device == PCI_DEVICE_ID_QLOGIC_ISP8044 ||
2922 pdev->device == PCI_DEVICE_ID_QLOGIC_ISP2071 ||
2923 pdev->device == PCI_DEVICE_ID_QLOGIC_ISP2271 ||
2924 pdev->device == PCI_DEVICE_ID_QLOGIC_ISP2261 ||
2925 pdev->device == PCI_DEVICE_ID_QLOGIC_ISP2081 ||
2926 pdev->device == PCI_DEVICE_ID_QLOGIC_ISP2281 ||
2927 pdev->device == PCI_DEVICE_ID_QLOGIC_ISP2089 ||
2928 pdev->device == PCI_DEVICE_ID_QLOGIC_ISP2289) {
2929 bars = pci_select_bars(pdev, IORESOURCE_MEM);
2931 ql_dbg_pci(ql_dbg_init, pdev, 0x0007,
2932 "Mem only adapter.\n");
2934 ql_dbg_pci(ql_dbg_init, pdev, 0x0008,
2935 "Bars=%d.\n", bars);
2938 if (pci_enable_device_mem(pdev))
2941 if (pci_enable_device(pdev))
2945 if (is_kdump_kernel()) {
2947 ql2xallocfwdump = 0;
2950 ha = kzalloc(sizeof(struct qla_hw_data), GFP_KERNEL);
2952 ql_log_pci(ql_log_fatal, pdev, 0x0009,
2953 "Unable to allocate memory for ha.\n");
2954 goto disable_device;
2956 ql_dbg_pci(ql_dbg_init, pdev, 0x000a,
2957 "Memory allocated for ha=%p.\n", ha);
2959 INIT_LIST_HEAD(&ha->tgt.q_full_list);
2960 spin_lock_init(&ha->tgt.q_full_lock);
2961 spin_lock_init(&ha->tgt.sess_lock);
2962 spin_lock_init(&ha->tgt.atio_lock);
2964 spin_lock_init(&ha->sadb_lock);
2965 INIT_LIST_HEAD(&ha->sadb_tx_index_list);
2966 INIT_LIST_HEAD(&ha->sadb_rx_index_list);
2968 spin_lock_init(&ha->sadb_fp_lock);
2970 if (qla_edif_sadb_build_free_pool(ha)) {
2972 goto disable_device;
2975 atomic_set(&ha->nvme_active_aen_cnt, 0);
2977 /* Clear our data area */
2979 ha->mem_only = mem_only;
2980 spin_lock_init(&ha->hardware_lock);
2981 spin_lock_init(&ha->vport_slock);
2982 mutex_init(&ha->selflogin_lock);
2983 mutex_init(&ha->optrom_mutex);
2985 /* Set ISP-type information. */
2986 qla2x00_set_isp_flags(ha);
2988 /* Set EEH reset type to fundamental if required by hba */
2989 if (IS_QLA24XX(ha) || IS_QLA25XX(ha) || IS_QLA81XX(ha) ||
2990 IS_QLA83XX(ha) || IS_QLA27XX(ha) || IS_QLA28XX(ha))
2991 pdev->needs_freset = 1;
2993 ha->prev_topology = 0;
2994 ha->init_cb_size = sizeof(init_cb_t);
2995 ha->link_data_rate = PORT_SPEED_UNKNOWN;
2996 ha->optrom_size = OPTROM_SIZE_2300;
2997 ha->max_exchg = FW_MAX_EXCHANGES_CNT;
2998 atomic_set(&ha->num_pend_mbx_stage1, 0);
2999 atomic_set(&ha->num_pend_mbx_stage2, 0);
3000 atomic_set(&ha->zio_threshold, DEFAULT_ZIO_THRESHOLD);
3001 ha->last_zio_threshold = DEFAULT_ZIO_THRESHOLD;
3002 INIT_LIST_HEAD(&ha->tmf_pending);
3003 INIT_LIST_HEAD(&ha->tmf_active);
3005 /* Assign ISP specific operations. */
3006 if (IS_QLA2100(ha)) {
3007 ha->max_fibre_devices = MAX_FIBRE_DEVICES_2100;
3008 ha->mbx_count = MAILBOX_REGISTER_COUNT_2100;
3009 req_length = REQUEST_ENTRY_CNT_2100;
3010 rsp_length = RESPONSE_ENTRY_CNT_2100;
3011 ha->max_loop_id = SNS_LAST_LOOP_ID_2100;
3012 ha->gid_list_info_size = 4;
3013 ha->flash_conf_off = ~0;
3014 ha->flash_data_off = ~0;
3015 ha->nvram_conf_off = ~0;
3016 ha->nvram_data_off = ~0;
3017 ha->isp_ops = &qla2100_isp_ops;
3018 } else if (IS_QLA2200(ha)) {
3019 ha->max_fibre_devices = MAX_FIBRE_DEVICES_2100;
3020 ha->mbx_count = MAILBOX_REGISTER_COUNT_2200;
3021 req_length = REQUEST_ENTRY_CNT_2200;
3022 rsp_length = RESPONSE_ENTRY_CNT_2100;
3023 ha->max_loop_id = SNS_LAST_LOOP_ID_2100;
3024 ha->gid_list_info_size = 4;
3025 ha->flash_conf_off = ~0;
3026 ha->flash_data_off = ~0;
3027 ha->nvram_conf_off = ~0;
3028 ha->nvram_data_off = ~0;
3029 ha->isp_ops = &qla2100_isp_ops;
3030 } else if (IS_QLA23XX(ha)) {
3031 ha->max_fibre_devices = MAX_FIBRE_DEVICES_2100;
3032 ha->mbx_count = MAILBOX_REGISTER_COUNT;
3033 req_length = REQUEST_ENTRY_CNT_2200;
3034 rsp_length = RESPONSE_ENTRY_CNT_2300;
3035 ha->max_loop_id = SNS_LAST_LOOP_ID_2300;
3036 ha->gid_list_info_size = 6;
3037 if (IS_QLA2322(ha) || IS_QLA6322(ha))
3038 ha->optrom_size = OPTROM_SIZE_2322;
3039 ha->flash_conf_off = ~0;
3040 ha->flash_data_off = ~0;
3041 ha->nvram_conf_off = ~0;
3042 ha->nvram_data_off = ~0;
3043 ha->isp_ops = &qla2300_isp_ops;
3044 } else if (IS_QLA24XX_TYPE(ha)) {
3045 ha->max_fibre_devices = MAX_FIBRE_DEVICES_2400;
3046 ha->mbx_count = MAILBOX_REGISTER_COUNT;
3047 req_length = REQUEST_ENTRY_CNT_24XX;
3048 rsp_length = RESPONSE_ENTRY_CNT_2300;
3049 ha->tgt.atio_q_length = ATIO_ENTRY_CNT_24XX;
3050 ha->max_loop_id = SNS_LAST_LOOP_ID_2300;
3051 ha->init_cb_size = sizeof(struct mid_init_cb_24xx);
3052 ha->gid_list_info_size = 8;
3053 ha->optrom_size = OPTROM_SIZE_24XX;
3054 ha->nvram_npiv_size = QLA_MAX_VPORTS_QLA24XX;
3055 ha->isp_ops = &qla24xx_isp_ops;
3056 ha->flash_conf_off = FARX_ACCESS_FLASH_CONF;
3057 ha->flash_data_off = FARX_ACCESS_FLASH_DATA;
3058 ha->nvram_conf_off = FARX_ACCESS_NVRAM_CONF;
3059 ha->nvram_data_off = FARX_ACCESS_NVRAM_DATA;
3060 } else if (IS_QLA25XX(ha)) {
3061 ha->max_fibre_devices = MAX_FIBRE_DEVICES_2400;
3062 ha->mbx_count = MAILBOX_REGISTER_COUNT;
3063 req_length = REQUEST_ENTRY_CNT_24XX;
3064 rsp_length = RESPONSE_ENTRY_CNT_2300;
3065 ha->tgt.atio_q_length = ATIO_ENTRY_CNT_24XX;
3066 ha->max_loop_id = SNS_LAST_LOOP_ID_2300;
3067 ha->init_cb_size = sizeof(struct mid_init_cb_24xx);
3068 ha->gid_list_info_size = 8;
3069 ha->optrom_size = OPTROM_SIZE_25XX;
3070 ha->nvram_npiv_size = QLA_MAX_VPORTS_QLA25XX;
3071 ha->isp_ops = &qla25xx_isp_ops;
3072 ha->flash_conf_off = FARX_ACCESS_FLASH_CONF;
3073 ha->flash_data_off = FARX_ACCESS_FLASH_DATA;
3074 ha->nvram_conf_off = FARX_ACCESS_NVRAM_CONF;
3075 ha->nvram_data_off = FARX_ACCESS_NVRAM_DATA;
3076 } else if (IS_QLA81XX(ha)) {
3077 ha->max_fibre_devices = MAX_FIBRE_DEVICES_2400;
3078 ha->mbx_count = MAILBOX_REGISTER_COUNT;
3079 req_length = REQUEST_ENTRY_CNT_24XX;
3080 rsp_length = RESPONSE_ENTRY_CNT_2300;
3081 ha->tgt.atio_q_length = ATIO_ENTRY_CNT_24XX;
3082 ha->max_loop_id = SNS_LAST_LOOP_ID_2300;
3083 ha->init_cb_size = sizeof(struct mid_init_cb_81xx);
3084 ha->gid_list_info_size = 8;
3085 ha->optrom_size = OPTROM_SIZE_81XX;
3086 ha->nvram_npiv_size = QLA_MAX_VPORTS_QLA25XX;
3087 ha->isp_ops = &qla81xx_isp_ops;
3088 ha->flash_conf_off = FARX_ACCESS_FLASH_CONF_81XX;
3089 ha->flash_data_off = FARX_ACCESS_FLASH_DATA_81XX;
3090 ha->nvram_conf_off = ~0;
3091 ha->nvram_data_off = ~0;
3092 } else if (IS_QLA82XX(ha)) {
3093 ha->max_fibre_devices = MAX_FIBRE_DEVICES_2400;
3094 ha->mbx_count = MAILBOX_REGISTER_COUNT;
3095 req_length = REQUEST_ENTRY_CNT_82XX;
3096 rsp_length = RESPONSE_ENTRY_CNT_82XX;
3097 ha->max_loop_id = SNS_LAST_LOOP_ID_2300;
3098 ha->init_cb_size = sizeof(struct mid_init_cb_81xx);
3099 ha->gid_list_info_size = 8;
3100 ha->optrom_size = OPTROM_SIZE_82XX;
3101 ha->nvram_npiv_size = QLA_MAX_VPORTS_QLA25XX;
3102 ha->isp_ops = &qla82xx_isp_ops;
3103 ha->flash_conf_off = FARX_ACCESS_FLASH_CONF;
3104 ha->flash_data_off = FARX_ACCESS_FLASH_DATA;
3105 ha->nvram_conf_off = FARX_ACCESS_NVRAM_CONF;
3106 ha->nvram_data_off = FARX_ACCESS_NVRAM_DATA;
3107 } else if (IS_QLA8044(ha)) {
3108 ha->max_fibre_devices = MAX_FIBRE_DEVICES_2400;
3109 ha->mbx_count = MAILBOX_REGISTER_COUNT;
3110 req_length = REQUEST_ENTRY_CNT_82XX;
3111 rsp_length = RESPONSE_ENTRY_CNT_82XX;
3112 ha->max_loop_id = SNS_LAST_LOOP_ID_2300;
3113 ha->init_cb_size = sizeof(struct mid_init_cb_81xx);
3114 ha->gid_list_info_size = 8;
3115 ha->optrom_size = OPTROM_SIZE_83XX;
3116 ha->nvram_npiv_size = QLA_MAX_VPORTS_QLA25XX;
3117 ha->isp_ops = &qla8044_isp_ops;
3118 ha->flash_conf_off = FARX_ACCESS_FLASH_CONF;
3119 ha->flash_data_off = FARX_ACCESS_FLASH_DATA;
3120 ha->nvram_conf_off = FARX_ACCESS_NVRAM_CONF;
3121 ha->nvram_data_off = FARX_ACCESS_NVRAM_DATA;
3122 } else if (IS_QLA83XX(ha)) {
3123 ha->portnum = PCI_FUNC(ha->pdev->devfn);
3124 ha->max_fibre_devices = MAX_FIBRE_DEVICES_2400;
3125 ha->mbx_count = MAILBOX_REGISTER_COUNT;
3126 req_length = REQUEST_ENTRY_CNT_83XX;
3127 rsp_length = RESPONSE_ENTRY_CNT_83XX;
3128 ha->tgt.atio_q_length = ATIO_ENTRY_CNT_24XX;
3129 ha->max_loop_id = SNS_LAST_LOOP_ID_2300;
3130 ha->init_cb_size = sizeof(struct mid_init_cb_81xx);
3131 ha->gid_list_info_size = 8;
3132 ha->optrom_size = OPTROM_SIZE_83XX;
3133 ha->nvram_npiv_size = QLA_MAX_VPORTS_QLA25XX;
3134 ha->isp_ops = &qla83xx_isp_ops;
3135 ha->flash_conf_off = FARX_ACCESS_FLASH_CONF_81XX;
3136 ha->flash_data_off = FARX_ACCESS_FLASH_DATA_81XX;
3137 ha->nvram_conf_off = ~0;
3138 ha->nvram_data_off = ~0;
3139 } else if (IS_QLAFX00(ha)) {
3140 ha->max_fibre_devices = MAX_FIBRE_DEVICES_FX00;
3141 ha->mbx_count = MAILBOX_REGISTER_COUNT_FX00;
3142 ha->aen_mbx_count = AEN_MAILBOX_REGISTER_COUNT_FX00;
3143 req_length = REQUEST_ENTRY_CNT_FX00;
3144 rsp_length = RESPONSE_ENTRY_CNT_FX00;
3145 ha->isp_ops = &qlafx00_isp_ops;
3146 ha->port_down_retry_count = 30; /* default value */
3147 ha->mr.fw_hbt_cnt = QLAFX00_HEARTBEAT_INTERVAL;
3148 ha->mr.fw_reset_timer_tick = QLAFX00_RESET_INTERVAL;
3149 ha->mr.fw_critemp_timer_tick = QLAFX00_CRITEMP_INTERVAL;
3150 ha->mr.fw_hbt_en = 1;
3151 ha->mr.host_info_resend = false;
3152 ha->mr.hinfo_resend_timer_tick = QLAFX00_HINFO_RESEND_INTERVAL;
3153 } else if (IS_QLA27XX(ha)) {
3154 ha->portnum = PCI_FUNC(ha->pdev->devfn);
3155 ha->max_fibre_devices = MAX_FIBRE_DEVICES_2400;
3156 ha->mbx_count = MAILBOX_REGISTER_COUNT;
3157 req_length = REQUEST_ENTRY_CNT_83XX;
3158 rsp_length = RESPONSE_ENTRY_CNT_83XX;
3159 ha->tgt.atio_q_length = ATIO_ENTRY_CNT_24XX;
3160 ha->max_loop_id = SNS_LAST_LOOP_ID_2300;
3161 ha->init_cb_size = sizeof(struct mid_init_cb_81xx);
3162 ha->gid_list_info_size = 8;
3163 ha->optrom_size = OPTROM_SIZE_83XX;
3164 ha->nvram_npiv_size = QLA_MAX_VPORTS_QLA25XX;
3165 ha->isp_ops = &qla27xx_isp_ops;
3166 ha->flash_conf_off = FARX_ACCESS_FLASH_CONF_81XX;
3167 ha->flash_data_off = FARX_ACCESS_FLASH_DATA_81XX;
3168 ha->nvram_conf_off = ~0;
3169 ha->nvram_data_off = ~0;
3170 } else if (IS_QLA28XX(ha)) {
3171 ha->portnum = PCI_FUNC(ha->pdev->devfn);
3172 ha->max_fibre_devices = MAX_FIBRE_DEVICES_2400;
3173 ha->mbx_count = MAILBOX_REGISTER_COUNT;
3174 req_length = REQUEST_ENTRY_CNT_83XX;
3175 rsp_length = RESPONSE_ENTRY_CNT_83XX;
3176 ha->tgt.atio_q_length = ATIO_ENTRY_CNT_24XX;
3177 ha->max_loop_id = SNS_LAST_LOOP_ID_2300;
3178 ha->init_cb_size = sizeof(struct mid_init_cb_81xx);
3179 ha->gid_list_info_size = 8;
3180 ha->optrom_size = OPTROM_SIZE_28XX;
3181 ha->nvram_npiv_size = QLA_MAX_VPORTS_QLA25XX;
3182 ha->isp_ops = &qla27xx_isp_ops;
3183 ha->flash_conf_off = FARX_ACCESS_FLASH_CONF_28XX;
3184 ha->flash_data_off = FARX_ACCESS_FLASH_DATA_28XX;
3185 ha->nvram_conf_off = ~0;
3186 ha->nvram_data_off = ~0;
3189 ql_dbg_pci(ql_dbg_init, pdev, 0x001e,
3190 "mbx_count=%d, req_length=%d, "
3191 "rsp_length=%d, max_loop_id=%d, init_cb_size=%d, "
3192 "gid_list_info_size=%d, optrom_size=%d, nvram_npiv_size=%d, "
3193 "max_fibre_devices=%d.\n",
3194 ha->mbx_count, req_length, rsp_length, ha->max_loop_id,
3195 ha->init_cb_size, ha->gid_list_info_size, ha->optrom_size,
3196 ha->nvram_npiv_size, ha->max_fibre_devices);
3197 ql_dbg_pci(ql_dbg_init, pdev, 0x001f,
3198 "isp_ops=%p, flash_conf_off=%d, "
3199 "flash_data_off=%d, nvram_conf_off=%d, nvram_data_off=%d.\n",
3200 ha->isp_ops, ha->flash_conf_off, ha->flash_data_off,
3201 ha->nvram_conf_off, ha->nvram_data_off);
3203 /* Configure PCI I/O space */
3204 ret = ha->isp_ops->iospace_config(ha);
3206 goto iospace_config_failed;
3208 ql_log_pci(ql_log_info, pdev, 0x001d,
3209 "Found an ISP%04X irq %d iobase 0x%p.\n",
3210 pdev->device, pdev->irq, ha->iobase);
3211 mutex_init(&ha->vport_lock);
3212 mutex_init(&ha->mq_lock);
3213 init_completion(&ha->mbx_cmd_comp);
3214 complete(&ha->mbx_cmd_comp);
3215 init_completion(&ha->mbx_intr_comp);
3216 init_completion(&ha->dcbx_comp);
3217 init_completion(&ha->lb_portup_comp);
3219 set_bit(0, (unsigned long *) ha->vp_idx_map);
3221 qla2x00_config_dma_addressing(ha);
3222 ql_dbg_pci(ql_dbg_init, pdev, 0x0020,
3223 "64 Bit addressing is %s.\n",
3224 ha->flags.enable_64bit_addressing ? "enable" :
3226 ret = qla2x00_mem_alloc(ha, req_length, rsp_length, &req, &rsp);
3228 ql_log_pci(ql_log_fatal, pdev, 0x0031,
3229 "Failed to allocate memory for adapter, aborting.\n");
3231 goto probe_hw_failed;
3234 req->max_q_depth = MAX_Q_DEPTH;
3235 if (ql2xmaxqdepth != 0 && ql2xmaxqdepth <= 0xffffU)
3236 req->max_q_depth = ql2xmaxqdepth;
3239 base_vha = qla2x00_create_host(sht, ha);
3242 goto probe_hw_failed;
3245 pci_set_drvdata(pdev, base_vha);
3246 set_bit(PFLG_DRIVER_PROBING, &base_vha->pci_flags);
3248 host = base_vha->host;
3249 base_vha->req = req;
3250 if (IS_QLA2XXX_MIDTYPE(ha))
3251 base_vha->mgmt_svr_loop_id =
3252 qla2x00_reserve_mgmt_server_loop_id(base_vha);
3254 base_vha->mgmt_svr_loop_id = MANAGEMENT_SERVER +
3257 /* Setup fcport template structure. */
3258 ha->mr.fcport.vha = base_vha;
3259 ha->mr.fcport.port_type = FCT_UNKNOWN;
3260 ha->mr.fcport.loop_id = FC_NO_LOOP_ID;
3261 qla2x00_set_fcport_state(&ha->mr.fcport, FCS_UNCONFIGURED);
3262 ha->mr.fcport.supported_classes = FC_COS_UNSPECIFIED;
3263 ha->mr.fcport.scan_state = 1;
3265 qla2xxx_reset_stats(host, QLA2XX_HW_ERROR | QLA2XX_SHT_LNK_DWN |
3266 QLA2XX_INT_ERR | QLA2XX_CMD_TIMEOUT |
3267 QLA2XX_RESET_CMD_ERR | QLA2XX_TGT_SHT_LNK_DOWN);
3269 /* Set the SG table size based on ISP type */
3270 if (!IS_FWI2_CAPABLE(ha)) {
3272 host->sg_tablesize = 32;
3274 if (!IS_QLA82XX(ha))
3275 host->sg_tablesize = QLA_SG_ALL;
3277 host->max_id = ha->max_fibre_devices;
3278 host->cmd_per_lun = 3;
3279 host->unique_id = host->host_no;
3281 if (ql2xenabledif && ql2xenabledif != 2) {
3282 ql_log(ql_log_warn, base_vha, 0x302d,
3283 "Invalid value for ql2xenabledif, resetting it to default (2)\n");
3287 if (IS_T10_PI_CAPABLE(ha) && ql2xenabledif)
3288 host->max_cmd_len = 32;
3290 host->max_cmd_len = MAX_CMDSZ;
3291 host->max_channel = MAX_BUSES - 1;
3292 /* Older HBAs support only 16-bit LUNs */
3293 if (!IS_QLAFX00(ha) && !IS_FWI2_CAPABLE(ha) &&
3294 ql2xmaxlun > 0xffff)
3295 host->max_lun = 0xffff;
3297 host->max_lun = ql2xmaxlun;
3298 host->transportt = qla2xxx_transport_template;
3299 sht->vendor_id = (SCSI_NL_VID_TYPE_PCI | PCI_VENDOR_ID_QLOGIC);
3301 ql_dbg(ql_dbg_init, base_vha, 0x0033,
3302 "max_id=%d this_id=%d "
3303 "cmd_per_len=%d unique_id=%d max_cmd_len=%d max_channel=%d "
3304 "max_lun=%llu transportt=%p, vendor_id=%llu.\n", host->max_id,
3305 host->this_id, host->cmd_per_lun, host->unique_id,
3306 host->max_cmd_len, host->max_channel, host->max_lun,
3307 host->transportt, sht->vendor_id);
3309 INIT_WORK(&ha->heartbeat_work, qla_heartbeat_work_fn);
3311 /* Set up the irqs */
3312 ret = qla2x00_request_irqs(ha, rsp);
3316 /* Alloc arrays of request and response ring ptrs */
3317 ret = qla2x00_alloc_queues(ha, req, rsp);
3319 ql_log(ql_log_fatal, base_vha, 0x003d,
3320 "Failed to allocate memory for queue pointers..."
3327 /* number of hardware queues supported by blk/scsi-mq*/
3328 host->nr_hw_queues = ha->max_qpairs;
3330 ql_dbg(ql_dbg_init, base_vha, 0x0192,
3331 "blk/scsi-mq enabled, HW queues = %d.\n", host->nr_hw_queues);
3333 if (ql2xnvmeenable) {
3334 host->nr_hw_queues = ha->max_qpairs;
3335 ql_dbg(ql_dbg_init, base_vha, 0x0194,
3336 "FC-NVMe support is enabled, HW queues=%d\n",
3337 host->nr_hw_queues);
3339 ql_dbg(ql_dbg_init, base_vha, 0x0193,
3340 "blk/scsi-mq disabled.\n");
3344 qlt_probe_one_stage1(base_vha, ha);
3346 pci_save_state(pdev);
3348 /* Assign back pointers */
3352 if (IS_QLAFX00(ha)) {
3353 ha->rsp_q_map[0] = rsp;
3354 ha->req_q_map[0] = req;
3355 set_bit(0, ha->req_qid_map);
3356 set_bit(0, ha->rsp_qid_map);
3359 /* FWI2-capable only. */
3360 req->req_q_in = &ha->iobase->isp24.req_q_in;
3361 req->req_q_out = &ha->iobase->isp24.req_q_out;
3362 rsp->rsp_q_in = &ha->iobase->isp24.rsp_q_in;
3363 rsp->rsp_q_out = &ha->iobase->isp24.rsp_q_out;
3364 if (ha->mqenable || IS_QLA83XX(ha) || IS_QLA27XX(ha) ||
3366 req->req_q_in = &ha->mqiobase->isp25mq.req_q_in;
3367 req->req_q_out = &ha->mqiobase->isp25mq.req_q_out;
3368 rsp->rsp_q_in = &ha->mqiobase->isp25mq.rsp_q_in;
3369 rsp->rsp_q_out = &ha->mqiobase->isp25mq.rsp_q_out;
3372 if (IS_QLAFX00(ha)) {
3373 req->req_q_in = &ha->iobase->ispfx00.req_q_in;
3374 req->req_q_out = &ha->iobase->ispfx00.req_q_out;
3375 rsp->rsp_q_in = &ha->iobase->ispfx00.rsp_q_in;
3376 rsp->rsp_q_out = &ha->iobase->ispfx00.rsp_q_out;
3379 if (IS_P3P_TYPE(ha)) {
3380 req->req_q_out = &ha->iobase->isp82.req_q_out[0];
3381 rsp->rsp_q_in = &ha->iobase->isp82.rsp_q_in[0];
3382 rsp->rsp_q_out = &ha->iobase->isp82.rsp_q_out[0];
3385 ql_dbg(ql_dbg_multiq, base_vha, 0xc009,
3386 "rsp_q_map=%p req_q_map=%p rsp->req=%p req->rsp=%p.\n",
3387 ha->rsp_q_map, ha->req_q_map, rsp->req, req->rsp);
3388 ql_dbg(ql_dbg_multiq, base_vha, 0xc00a,
3389 "req->req_q_in=%p req->req_q_out=%p "
3390 "rsp->rsp_q_in=%p rsp->rsp_q_out=%p.\n",
3391 req->req_q_in, req->req_q_out,
3392 rsp->rsp_q_in, rsp->rsp_q_out);
3393 ql_dbg(ql_dbg_init, base_vha, 0x003e,
3394 "rsp_q_map=%p req_q_map=%p rsp->req=%p req->rsp=%p.\n",
3395 ha->rsp_q_map, ha->req_q_map, rsp->req, req->rsp);
3396 ql_dbg(ql_dbg_init, base_vha, 0x003f,
3397 "req->req_q_in=%p req->req_q_out=%p rsp->rsp_q_in=%p rsp->rsp_q_out=%p.\n",
3398 req->req_q_in, req->req_q_out, rsp->rsp_q_in, rsp->rsp_q_out);
3400 ha->wq = alloc_workqueue("qla2xxx_wq", WQ_MEM_RECLAIM, 0);
3401 if (unlikely(!ha->wq)) {
3406 if (ha->isp_ops->initialize_adapter(base_vha)) {
3407 ql_log(ql_log_fatal, base_vha, 0x00d6,
3408 "Failed to initialize adapter - Adapter flags %x.\n",
3409 base_vha->device_flags);
3411 if (IS_QLA82XX(ha)) {
3412 qla82xx_idc_lock(ha);
3413 qla82xx_wr_32(ha, QLA82XX_CRB_DEV_STATE,
3414 QLA8XXX_DEV_FAILED);
3415 qla82xx_idc_unlock(ha);
3416 ql_log(ql_log_fatal, base_vha, 0x00d7,
3417 "HW State: FAILED.\n");
3418 } else if (IS_QLA8044(ha)) {
3419 qla8044_idc_lock(ha);
3420 qla8044_wr_direct(base_vha,
3421 QLA8044_CRB_DEV_STATE_INDEX,
3422 QLA8XXX_DEV_FAILED);
3423 qla8044_idc_unlock(ha);
3424 ql_log(ql_log_fatal, base_vha, 0x0150,
3425 "HW State: FAILED.\n");
3433 host->can_queue = QLAFX00_MAX_CANQUEUE;
3435 host->can_queue = req->num_outstanding_cmds - 10;
3437 ql_dbg(ql_dbg_init, base_vha, 0x0032,
3438 "can_queue=%d, req=%p, mgmt_svr_loop_id=%d, sg_tablesize=%d.\n",
3439 host->can_queue, base_vha->req,
3440 base_vha->mgmt_svr_loop_id, host->sg_tablesize);
3442 /* Check if FW supports MQ or not for ISP25xx */
3443 if (IS_QLA25XX(ha) && !(ha->fw_attributes & BIT_6))
3447 bool startit = false;
3449 if (QLA_TGT_MODE_ENABLED())
3452 if (ql2x_ini_mode == QLA2XXX_INI_MODE_ENABLED)
3455 /* Create start of day qpairs for Block MQ */
3456 for (i = 0; i < ha->max_qpairs; i++)
3457 qla2xxx_create_qpair(base_vha, 5, 0, startit);
3459 qla_init_iocb_limit(base_vha);
3461 if (ha->flags.running_gold_fw)
3465 * Startup the kernel thread for this host adapter
3467 ha->dpc_thread = kthread_create(qla2x00_do_dpc, ha,
3468 "%s_dpc", base_vha->host_str);
3469 if (IS_ERR(ha->dpc_thread)) {
3470 ql_log(ql_log_fatal, base_vha, 0x00ed,
3471 "Failed to start DPC thread.\n");
3472 ret = PTR_ERR(ha->dpc_thread);
3473 ha->dpc_thread = NULL;
3476 ql_dbg(ql_dbg_init, base_vha, 0x00ee,
3477 "DPC thread started successfully.\n");
3480 * If we're not coming up in initiator mode, we might sit for
3481 * a while without waking up the dpc thread, which leads to a
3482 * stuck process warning. So just kick the dpc once here and
3483 * let the kthread start (and go back to sleep in qla2x00_do_dpc).
3485 qla2xxx_wake_dpc(base_vha);
3487 INIT_WORK(&ha->board_disable, qla2x00_disable_board_on_pci_error);
3489 if (IS_QLA8031(ha) || IS_MCTP_CAPABLE(ha)) {
3490 sprintf(wq_name, "qla2xxx_%lu_dpc_lp_wq", base_vha->host_no);
3492 alloc_ordered_workqueue("%s", WQ_MEM_RECLAIM, wq_name);
3493 INIT_WORK(&ha->idc_aen, qla83xx_service_idc_aen);
3495 sprintf(wq_name, "qla2xxx_%lu_dpc_hp_wq", base_vha->host_no);
3497 alloc_ordered_workqueue("%s", WQ_MEM_RECLAIM, wq_name);
3498 INIT_WORK(&ha->nic_core_reset, qla83xx_nic_core_reset_work);
3499 INIT_WORK(&ha->idc_state_handler,
3500 qla83xx_idc_state_handler_work);
3501 INIT_WORK(&ha->nic_core_unrecoverable,
3502 qla83xx_nic_core_unrecoverable_work);
3506 list_add_tail(&base_vha->list, &ha->vp_list);
3507 base_vha->host->irq = ha->pdev->irq;
3509 /* Initialized the timer */
3510 qla2x00_start_timer(base_vha, WATCH_INTERVAL);
3511 ql_dbg(ql_dbg_init, base_vha, 0x00ef,
3512 "Started qla2x00_timer with "
3513 "interval=%d.\n", WATCH_INTERVAL);
3514 ql_dbg(ql_dbg_init, base_vha, 0x00f0,
3515 "Detected hba at address=%p.\n",
3518 if (IS_T10_PI_CAPABLE(ha) && ql2xenabledif) {
3519 if (ha->fw_attributes & BIT_4) {
3520 int prot = 0, guard;
3522 base_vha->flags.difdix_supported = 1;
3523 ql_dbg(ql_dbg_init, base_vha, 0x00f1,
3524 "Registering for DIF/DIX type 1 and 3 protection.\n");
3526 scsi_host_set_prot(host, ql2xprotmask);
3528 scsi_host_set_prot(host,
3529 prot | SHOST_DIF_TYPE1_PROTECTION
3530 | SHOST_DIF_TYPE2_PROTECTION
3531 | SHOST_DIF_TYPE3_PROTECTION
3532 | SHOST_DIX_TYPE1_PROTECTION
3533 | SHOST_DIX_TYPE2_PROTECTION
3534 | SHOST_DIX_TYPE3_PROTECTION);
3536 guard = SHOST_DIX_GUARD_CRC;
3538 if (IS_PI_IPGUARD_CAPABLE(ha) &&
3539 (ql2xenabledif > 1 || IS_PI_DIFB_DIX0_CAPABLE(ha)))
3540 guard |= SHOST_DIX_GUARD_IP;
3543 scsi_host_set_guard(host, ql2xprotguard);
3545 scsi_host_set_guard(host, guard);
3547 base_vha->flags.difdix_supported = 0;
3550 ha->isp_ops->enable_intrs(ha);
3552 if (IS_QLAFX00(ha)) {
3553 ret = qlafx00_fx_disc(base_vha,
3554 &base_vha->hw->mr.fcport, FXDISC_GET_CONFIG_INFO);
3555 host->sg_tablesize = (ha->mr.extended_io_enabled) ?
3559 if (IS_T10_PI_CAPABLE(base_vha->hw))
3560 host->dma_alignment = 0x7;
3562 ret = scsi_add_host(host, &pdev->dev);
3566 base_vha->flags.init_done = 1;
3567 base_vha->flags.online = 1;
3568 ha->prev_minidump_failed = 0;
3570 ql_dbg(ql_dbg_init, base_vha, 0x00f2,
3571 "Init done and hba is online.\n");
3573 if (qla_ini_mode_enabled(base_vha) ||
3574 qla_dual_mode_enabled(base_vha))
3575 scsi_scan_host(host);
3577 ql_log(ql_log_info, base_vha, 0x0122,
3578 "skipping scsi_scan_host() for non-initiator port\n");
3580 qla2x00_alloc_sysfs_attr(base_vha);
3582 if (IS_QLAFX00(ha)) {
3583 ret = qlafx00_fx_disc(base_vha,
3584 &base_vha->hw->mr.fcport, FXDISC_GET_PORT_INFO);
3586 /* Register system information */
3587 ret = qlafx00_fx_disc(base_vha,
3588 &base_vha->hw->mr.fcport, FXDISC_REG_HOST_INFO);
3591 qla2x00_init_host_attr(base_vha);
3593 qla2x00_dfs_setup(base_vha);
3595 ql_log(ql_log_info, base_vha, 0x00fb,
3596 "QLogic %s - %s.\n", ha->model_number, ha->model_desc);
3597 ql_log(ql_log_info, base_vha, 0x00fc,
3598 "ISP%04X: %s @ %s hdma%c host#=%ld fw=%s.\n",
3599 pdev->device, ha->isp_ops->pci_info_str(base_vha, pci_info,
3601 pci_name(pdev), ha->flags.enable_64bit_addressing ? '+' : '-',
3603 ha->isp_ops->fw_version_str(base_vha, fw_str, sizeof(fw_str)));
3605 qlt_add_target(ha, base_vha);
3607 clear_bit(PFLG_DRIVER_PROBING, &base_vha->pci_flags);
3609 if (test_bit(UNLOADING, &base_vha->dpc_flags))
3615 qla_enode_stop(base_vha);
3616 qla_edb_stop(base_vha);
3617 vfree(base_vha->scan.l);
3618 if (base_vha->gnl.l) {
3619 dma_free_coherent(&ha->pdev->dev, base_vha->gnl.size,
3620 base_vha->gnl.l, base_vha->gnl.ldma);
3621 base_vha->gnl.l = NULL;
3624 if (base_vha->timer_active)
3625 qla2x00_stop_timer(base_vha);
3626 base_vha->flags.online = 0;
3627 if (ha->dpc_thread) {
3628 struct task_struct *t = ha->dpc_thread;
3630 ha->dpc_thread = NULL;
3634 qla2x00_free_device(base_vha);
3635 scsi_host_put(base_vha->host);
3637 * Need to NULL out local req/rsp after
3638 * qla2x00_free_device => qla2x00_free_queues frees
3639 * what these are pointing to. Or else we'll
3640 * fall over below in qla2x00_free_req/rsp_que.
3646 qla2x00_mem_free(ha);
3647 qla2x00_free_req_que(ha, req);
3648 qla2x00_free_rsp_que(ha, rsp);
3649 qla2x00_clear_drv_active(ha);
3651 iospace_config_failed:
3652 if (IS_P3P_TYPE(ha)) {
3653 if (!ha->nx_pcibase)
3654 iounmap((device_reg_t *)ha->nx_pcibase);
3656 iounmap((device_reg_t *)ha->nxdb_wr_ptr);
3659 iounmap(ha->iobase);
3661 iounmap(ha->cregbase);
3663 pci_release_selected_regions(ha->pdev, ha->bars);
3667 pci_disable_device(pdev);
3671 static void __qla_set_remove_flag(scsi_qla_host_t *base_vha)
3673 scsi_qla_host_t *vp;
3674 unsigned long flags;
3675 struct qla_hw_data *ha;
3682 spin_lock_irqsave(&ha->vport_slock, flags);
3683 list_for_each_entry(vp, &ha->vp_list, list)
3684 set_bit(PFLG_DRIVER_REMOVING, &vp->pci_flags);
3687 * Indicate device removal to prevent future board_disable
3688 * and wait until any pending board_disable has completed.
3690 set_bit(PFLG_DRIVER_REMOVING, &base_vha->pci_flags);
3691 spin_unlock_irqrestore(&ha->vport_slock, flags);
3695 qla2x00_shutdown(struct pci_dev *pdev)
3697 scsi_qla_host_t *vha;
3698 struct qla_hw_data *ha;
3700 vha = pci_get_drvdata(pdev);
3703 ql_log(ql_log_info, vha, 0xfffa,
3704 "Adapter shutdown\n");
3707 * Prevent future board_disable and wait
3708 * until any pending board_disable has completed.
3710 __qla_set_remove_flag(vha);
3711 cancel_work_sync(&ha->board_disable);
3713 if (!atomic_read(&pdev->enable_cnt))
3716 /* Notify ISPFX00 firmware */
3718 qlafx00_driver_shutdown(vha, 20);
3720 /* Turn-off FCE trace */
3721 if (ha->flags.fce_enabled) {
3722 qla2x00_disable_fce_trace(vha, NULL, NULL);
3723 ha->flags.fce_enabled = 0;
3726 /* Turn-off EFT trace */
3728 qla2x00_disable_eft_trace(vha);
3730 if (IS_QLA25XX(ha) || IS_QLA2031(ha) || IS_QLA27XX(ha) ||
3732 if (ha->flags.fw_started)
3733 qla2x00_abort_isp_cleanup(vha);
3735 /* Stop currently executing firmware. */
3736 qla2x00_try_to_stop_firmware(vha);
3740 if (vha->timer_active)
3741 qla2x00_stop_timer(vha);
3743 /* Turn adapter off line */
3744 vha->flags.online = 0;
3746 /* turn-off interrupts on the card */
3747 if (ha->interrupts_on) {
3748 vha->flags.init_done = 0;
3749 ha->isp_ops->disable_intrs(ha);
3752 qla2x00_free_irqs(vha);
3754 qla2x00_free_fw_dump(ha);
3756 pci_disable_device(pdev);
3757 ql_log(ql_log_info, vha, 0xfffe,
3758 "Adapter shutdown successfully.\n");
3761 /* Deletes all the virtual ports for a given ha */
3763 qla2x00_delete_all_vps(struct qla_hw_data *ha, scsi_qla_host_t *base_vha)
3765 scsi_qla_host_t *vha;
3766 unsigned long flags;
3768 mutex_lock(&ha->vport_lock);
3769 while (ha->cur_vport_count) {
3770 spin_lock_irqsave(&ha->vport_slock, flags);
3772 BUG_ON(base_vha->list.next == &ha->vp_list);
3773 /* This assumes first entry in ha->vp_list is always base vha */
3774 vha = list_first_entry(&base_vha->list, scsi_qla_host_t, list);
3775 scsi_host_get(vha->host);
3777 spin_unlock_irqrestore(&ha->vport_slock, flags);
3778 mutex_unlock(&ha->vport_lock);
3780 qla_nvme_delete(vha);
3782 fc_vport_terminate(vha->fc_vport);
3783 scsi_host_put(vha->host);
3785 mutex_lock(&ha->vport_lock);
3787 mutex_unlock(&ha->vport_lock);
3790 /* Stops all deferred work threads */
3792 qla2x00_destroy_deferred_work(struct qla_hw_data *ha)
3794 /* Cancel all work and destroy DPC workqueues */
3795 if (ha->dpc_lp_wq) {
3796 cancel_work_sync(&ha->idc_aen);
3797 destroy_workqueue(ha->dpc_lp_wq);
3798 ha->dpc_lp_wq = NULL;
3801 if (ha->dpc_hp_wq) {
3802 cancel_work_sync(&ha->nic_core_reset);
3803 cancel_work_sync(&ha->idc_state_handler);
3804 cancel_work_sync(&ha->nic_core_unrecoverable);
3805 destroy_workqueue(ha->dpc_hp_wq);
3806 ha->dpc_hp_wq = NULL;
3809 /* Kill the kernel thread for this host */
3810 if (ha->dpc_thread) {
3811 struct task_struct *t = ha->dpc_thread;
3814 * qla2xxx_wake_dpc checks for ->dpc_thread
3815 * so we need to zero it out.
3817 ha->dpc_thread = NULL;
3823 qla2x00_unmap_iobases(struct qla_hw_data *ha)
3825 if (IS_QLA82XX(ha)) {
3827 iounmap((device_reg_t *)ha->nx_pcibase);
3829 iounmap((device_reg_t *)ha->nxdb_wr_ptr);
3832 iounmap(ha->iobase);
3835 iounmap(ha->cregbase);
3838 iounmap(ha->mqiobase);
3841 iounmap(ha->msixbase);
3846 qla2x00_clear_drv_active(struct qla_hw_data *ha)
3848 if (IS_QLA8044(ha)) {
3849 qla8044_idc_lock(ha);
3850 qla8044_clear_drv_active(ha);
3851 qla8044_idc_unlock(ha);
3852 } else if (IS_QLA82XX(ha)) {
3853 qla82xx_idc_lock(ha);
3854 qla82xx_clear_drv_active(ha);
3855 qla82xx_idc_unlock(ha);
3860 qla2x00_remove_one(struct pci_dev *pdev)
3862 scsi_qla_host_t *base_vha;
3863 struct qla_hw_data *ha;
3865 base_vha = pci_get_drvdata(pdev);
3867 ql_log(ql_log_info, base_vha, 0xb079,
3868 "Removing driver\n");
3869 __qla_set_remove_flag(base_vha);
3870 cancel_work_sync(&ha->board_disable);
3873 * If the PCI device is disabled then there was a PCI-disconnect and
3874 * qla2x00_disable_board_on_pci_error has taken care of most of the
3877 if (!atomic_read(&pdev->enable_cnt)) {
3878 dma_free_coherent(&ha->pdev->dev, base_vha->gnl.size,
3879 base_vha->gnl.l, base_vha->gnl.ldma);
3880 base_vha->gnl.l = NULL;
3881 scsi_host_put(base_vha->host);
3883 pci_set_drvdata(pdev, NULL);
3886 qla2x00_wait_for_hba_ready(base_vha);
3889 * if UNLOADING flag is already set, then continue unload,
3890 * where it was set first.
3892 if (test_and_set_bit(UNLOADING, &base_vha->dpc_flags))
3895 if (IS_QLA25XX(ha) || IS_QLA2031(ha) || IS_QLA27XX(ha) ||
3897 if (ha->flags.fw_started)
3898 qla2x00_abort_isp_cleanup(base_vha);
3899 } else if (!IS_QLAFX00(ha)) {
3900 if (IS_QLA8031(ha)) {
3901 ql_dbg(ql_dbg_p3p, base_vha, 0xb07e,
3902 "Clearing fcoe driver presence.\n");
3903 if (qla83xx_clear_drv_presence(base_vha) != QLA_SUCCESS)
3904 ql_dbg(ql_dbg_p3p, base_vha, 0xb079,
3905 "Error while clearing DRV-Presence.\n");
3908 qla2x00_try_to_stop_firmware(base_vha);
3911 qla2x00_wait_for_sess_deletion(base_vha);
3913 qla_nvme_delete(base_vha);
3915 dma_free_coherent(&ha->pdev->dev,
3916 base_vha->gnl.size, base_vha->gnl.l, base_vha->gnl.ldma);
3918 base_vha->gnl.l = NULL;
3919 qla_enode_stop(base_vha);
3920 qla_edb_stop(base_vha);
3922 vfree(base_vha->scan.l);
3925 qlafx00_driver_shutdown(base_vha, 20);
3927 qla2x00_delete_all_vps(ha, base_vha);
3929 qla2x00_dfs_remove(base_vha);
3931 qla84xx_put_chip(base_vha);
3934 if (base_vha->timer_active)
3935 qla2x00_stop_timer(base_vha);
3937 base_vha->flags.online = 0;
3939 /* free DMA memory */
3940 if (ha->exlogin_buf)
3941 qla2x00_free_exlogin_buffer(ha);
3943 /* free DMA memory */
3944 if (ha->exchoffld_buf)
3945 qla2x00_free_exchoffld_buffer(ha);
3947 qla2x00_destroy_deferred_work(ha);
3949 qlt_remove_target(ha, base_vha);
3951 qla2x00_free_sysfs_attr(base_vha, true);
3953 fc_remove_host(base_vha->host);
3955 scsi_remove_host(base_vha->host);
3957 qla2x00_free_device(base_vha);
3959 qla2x00_clear_drv_active(ha);
3961 scsi_host_put(base_vha->host);
3963 qla2x00_unmap_iobases(ha);
3965 pci_release_selected_regions(ha->pdev, ha->bars);
3968 pci_disable_device(pdev);
3972 qla24xx_free_purex_list(struct purex_list *list)
3974 struct purex_item *item, *next;
3977 spin_lock_irqsave(&list->lock, flags);
3978 list_for_each_entry_safe(item, next, &list->head, list) {
3979 list_del(&item->list);
3980 if (item == &item->vha->default_item)
3984 spin_unlock_irqrestore(&list->lock, flags);
3988 qla2x00_free_device(scsi_qla_host_t *vha)
3990 struct qla_hw_data *ha = vha->hw;
3992 qla2x00_abort_all_cmds(vha, DID_NO_CONNECT << 16);
3995 if (vha->timer_active)
3996 qla2x00_stop_timer(vha);
3998 qla25xx_delete_queues(vha);
3999 vha->flags.online = 0;
4001 /* turn-off interrupts on the card */
4002 if (ha->interrupts_on) {
4003 vha->flags.init_done = 0;
4004 ha->isp_ops->disable_intrs(ha);
4007 qla2x00_free_fcports(vha);
4009 qla2x00_free_irqs(vha);
4011 /* Flush the work queue and remove it */
4013 destroy_workqueue(ha->wq);
4018 qla24xx_free_purex_list(&vha->purex_list);
4020 qla2x00_mem_free(ha);
4022 qla82xx_md_free(vha);
4024 qla_edif_sadb_release_free_pool(ha);
4025 qla_edif_sadb_release(ha);
4027 qla2x00_free_queues(ha);
4030 void qla2x00_free_fcports(struct scsi_qla_host *vha)
4032 fc_port_t *fcport, *tfcport;
4034 list_for_each_entry_safe(fcport, tfcport, &vha->vp_fcports, list)
4035 qla2x00_free_fcport(fcport);
4039 qla2x00_schedule_rport_del(struct scsi_qla_host *vha, fc_port_t *fcport)
4046 if (fcport->rport) {
4047 ql_dbg(ql_dbg_disc, fcport->vha, 0x2109,
4048 "%s %8phN. rport %p roles %x\n",
4049 __func__, fcport->port_name, fcport->rport,
4050 fcport->rport->roles);
4051 fc_remote_port_delete(fcport->rport);
4053 qlt_do_generation_tick(vha, &now);
4057 * qla2x00_mark_device_lost Updates fcport state when device goes offline.
4059 * Input: ha = adapter block pointer. fcport = port structure pointer.
4065 void qla2x00_mark_device_lost(scsi_qla_host_t *vha, fc_port_t *fcport,
4068 if (IS_QLAFX00(vha->hw)) {
4069 qla2x00_set_fcport_state(fcport, FCS_DEVICE_LOST);
4070 qla2x00_schedule_rport_del(vha, fcport);
4074 if (atomic_read(&fcport->state) == FCS_ONLINE &&
4075 vha->vp_idx == fcport->vha->vp_idx) {
4076 qla2x00_set_fcport_state(fcport, FCS_DEVICE_LOST);
4077 qla2x00_schedule_rport_del(vha, fcport);
4081 * We may need to retry the login, so don't change the state of the
4082 * port but do the retries.
4084 if (atomic_read(&fcport->state) != FCS_DEVICE_DEAD)
4085 qla2x00_set_fcport_state(fcport, FCS_DEVICE_LOST);
4090 set_bit(RELOGIN_NEEDED, &vha->dpc_flags);
4094 qla2x00_mark_all_devices_lost(scsi_qla_host_t *vha)
4098 ql_dbg(ql_dbg_disc, vha, 0x20f1,
4099 "Mark all dev lost\n");
4101 list_for_each_entry(fcport, &vha->vp_fcports, list) {
4102 if (ql2xfc2target &&
4103 fcport->loop_id != FC_NO_LOOP_ID &&
4104 (fcport->flags & FCF_FCP2_DEVICE) &&
4105 fcport->port_type == FCT_TARGET &&
4106 !qla2x00_reset_active(vha)) {
4107 ql_dbg(ql_dbg_disc, vha, 0x211a,
4108 "Delaying session delete for FCP2 flags 0x%x port_type = 0x%x port_id=%06x %phC",
4109 fcport->flags, fcport->port_type,
4110 fcport->d_id.b24, fcport->port_name);
4113 fcport->scan_state = 0;
4114 qlt_schedule_sess_for_deletion(fcport);
4118 static void qla2x00_set_reserved_loop_ids(struct qla_hw_data *ha)
4122 if (IS_FWI2_CAPABLE(ha))
4125 for (i = 0; i < SNS_FIRST_LOOP_ID; i++)
4126 set_bit(i, ha->loop_id_map);
4127 set_bit(MANAGEMENT_SERVER, ha->loop_id_map);
4128 set_bit(BROADCAST, ha->loop_id_map);
4133 * Allocates adapter memory.
4140 qla2x00_mem_alloc(struct qla_hw_data *ha, uint16_t req_len, uint16_t rsp_len,
4141 struct req_que **req, struct rsp_que **rsp)
4146 if (QLA_TGT_MODE_ENABLED() || EDIF_CAP(ha)) {
4147 ha->vp_map = kcalloc(MAX_MULTI_ID_FABRIC, sizeof(struct qla_vp_map), GFP_KERNEL);
4152 ha->init_cb = dma_alloc_coherent(&ha->pdev->dev, ha->init_cb_size,
4153 &ha->init_cb_dma, GFP_KERNEL);
4155 goto fail_free_vp_map;
4157 rc = btree_init32(&ha->host_map);
4159 goto fail_free_init_cb;
4161 if (qlt_mem_alloc(ha) < 0)
4162 goto fail_free_btree;
4164 ha->gid_list = dma_alloc_coherent(&ha->pdev->dev,
4165 qla2x00_gid_list_size(ha), &ha->gid_list_dma, GFP_KERNEL);
4167 goto fail_free_tgt_mem;
4169 ha->srb_mempool = mempool_create_slab_pool(SRB_MIN_REQ, srb_cachep);
4170 if (!ha->srb_mempool)
4171 goto fail_free_gid_list;
4173 if (IS_P3P_TYPE(ha) || IS_QLA27XX(ha) || (ql2xsecenable && IS_QLA28XX(ha))) {
4174 /* Allocate cache for CT6 Ctx. */
4176 ctx_cachep = kmem_cache_create("qla2xxx_ctx",
4177 sizeof(struct ct6_dsd), 0,
4178 SLAB_HWCACHE_ALIGN, NULL);
4180 goto fail_free_srb_mempool;
4182 ha->ctx_mempool = mempool_create_slab_pool(SRB_MIN_REQ,
4184 if (!ha->ctx_mempool)
4185 goto fail_free_srb_mempool;
4186 ql_dbg_pci(ql_dbg_init, ha->pdev, 0x0021,
4187 "ctx_cachep=%p ctx_mempool=%p.\n",
4188 ctx_cachep, ha->ctx_mempool);
4191 /* Get memory for cached NVRAM */
4192 ha->nvram = kzalloc(MAX_NVRAM_SIZE, GFP_KERNEL);
4194 goto fail_free_ctx_mempool;
4196 snprintf(name, sizeof(name), "%s_%d", QLA2XXX_DRIVER_NAME,
4198 ha->s_dma_pool = dma_pool_create(name, &ha->pdev->dev,
4199 DMA_POOL_SIZE, 8, 0);
4200 if (!ha->s_dma_pool)
4201 goto fail_free_nvram;
4203 ql_dbg_pci(ql_dbg_init, ha->pdev, 0x0022,
4204 "init_cb=%p gid_list=%p, srb_mempool=%p s_dma_pool=%p.\n",
4205 ha->init_cb, ha->gid_list, ha->srb_mempool, ha->s_dma_pool);
4207 if (IS_P3P_TYPE(ha) || ql2xenabledif || (IS_QLA28XX(ha) && ql2xsecenable)) {
4208 ha->dl_dma_pool = dma_pool_create(name, &ha->pdev->dev,
4209 DSD_LIST_DMA_POOL_SIZE, 8, 0);
4210 if (!ha->dl_dma_pool) {
4211 ql_log_pci(ql_log_fatal, ha->pdev, 0x0023,
4212 "Failed to allocate memory for dl_dma_pool.\n");
4213 goto fail_s_dma_pool;
4216 ha->fcp_cmnd_dma_pool = dma_pool_create(name, &ha->pdev->dev,
4217 FCP_CMND_DMA_POOL_SIZE, 8, 0);
4218 if (!ha->fcp_cmnd_dma_pool) {
4219 ql_log_pci(ql_log_fatal, ha->pdev, 0x0024,
4220 "Failed to allocate memory for fcp_cmnd_dma_pool.\n");
4221 goto fail_dl_dma_pool;
4224 if (ql2xenabledif) {
4225 u64 bufsize = DIF_BUNDLING_DMA_POOL_SIZE;
4226 struct dsd_dma *dsd, *nxt;
4228 /* Creata a DMA pool of buffers for DIF bundling */
4229 ha->dif_bundl_pool = dma_pool_create(name,
4230 &ha->pdev->dev, DIF_BUNDLING_DMA_POOL_SIZE, 8, 0);
4231 if (!ha->dif_bundl_pool) {
4232 ql_dbg_pci(ql_dbg_init, ha->pdev, 0x0024,
4233 "%s: failed create dif_bundl_pool\n",
4235 goto fail_dif_bundl_dma_pool;
4238 INIT_LIST_HEAD(&ha->pool.good.head);
4239 INIT_LIST_HEAD(&ha->pool.unusable.head);
4240 ha->pool.good.count = 0;
4241 ha->pool.unusable.count = 0;
4242 for (i = 0; i < 128; i++) {
4243 dsd = kzalloc(sizeof(*dsd), GFP_ATOMIC);
4245 ql_dbg_pci(ql_dbg_init, ha->pdev,
4246 0xe0ee, "%s: failed alloc dsd\n",
4250 ha->dif_bundle_kallocs++;
4252 dsd->dsd_addr = dma_pool_alloc(
4253 ha->dif_bundl_pool, GFP_ATOMIC,
4254 &dsd->dsd_list_dma);
4255 if (!dsd->dsd_addr) {
4256 ql_dbg_pci(ql_dbg_init, ha->pdev,
4258 "%s: failed alloc ->dsd_addr\n",
4261 ha->dif_bundle_kallocs--;
4264 ha->dif_bundle_dma_allocs++;
4267 * if DMA buffer crosses 4G boundary,
4268 * put it on bad list
4270 if (MSD(dsd->dsd_list_dma) ^
4271 MSD(dsd->dsd_list_dma + bufsize)) {
4272 list_add_tail(&dsd->list,
4273 &ha->pool.unusable.head);
4274 ha->pool.unusable.count++;
4276 list_add_tail(&dsd->list,
4277 &ha->pool.good.head);
4278 ha->pool.good.count++;
4282 /* return the good ones back to the pool */
4283 list_for_each_entry_safe(dsd, nxt,
4284 &ha->pool.good.head, list) {
4285 list_del(&dsd->list);
4286 dma_pool_free(ha->dif_bundl_pool,
4287 dsd->dsd_addr, dsd->dsd_list_dma);
4288 ha->dif_bundle_dma_allocs--;
4290 ha->dif_bundle_kallocs--;
4293 ql_dbg_pci(ql_dbg_init, ha->pdev, 0x0024,
4294 "%s: dif dma pool (good=%u unusable=%u)\n",
4295 __func__, ha->pool.good.count,
4296 ha->pool.unusable.count);
4299 ql_dbg_pci(ql_dbg_init, ha->pdev, 0x0025,
4300 "dl_dma_pool=%p fcp_cmnd_dma_pool=%p dif_bundl_pool=%p.\n",
4301 ha->dl_dma_pool, ha->fcp_cmnd_dma_pool,
4302 ha->dif_bundl_pool);
4305 /* Allocate memory for SNS commands */
4306 if (IS_QLA2100(ha) || IS_QLA2200(ha)) {
4307 /* Get consistent memory allocated for SNS commands */
4308 ha->sns_cmd = dma_alloc_coherent(&ha->pdev->dev,
4309 sizeof(struct sns_cmd_pkt), &ha->sns_cmd_dma, GFP_KERNEL);
4312 ql_dbg_pci(ql_dbg_init, ha->pdev, 0x0026,
4313 "sns_cmd: %p.\n", ha->sns_cmd);
4315 /* Get consistent memory allocated for MS IOCB */
4316 ha->ms_iocb = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL,
4320 /* Get consistent memory allocated for CT SNS commands */
4321 ha->ct_sns = dma_alloc_coherent(&ha->pdev->dev,
4322 sizeof(struct ct_sns_pkt), &ha->ct_sns_dma, GFP_KERNEL);
4324 goto fail_free_ms_iocb;
4325 ql_dbg_pci(ql_dbg_init, ha->pdev, 0x0027,
4326 "ms_iocb=%p ct_sns=%p.\n",
4327 ha->ms_iocb, ha->ct_sns);
4330 /* Allocate memory for request ring */
4331 *req = kzalloc(sizeof(struct req_que), GFP_KERNEL);
4333 ql_log_pci(ql_log_fatal, ha->pdev, 0x0028,
4334 "Failed to allocate memory for req.\n");
4337 (*req)->length = req_len;
4338 (*req)->ring = dma_alloc_coherent(&ha->pdev->dev,
4339 ((*req)->length + 1) * sizeof(request_t),
4340 &(*req)->dma, GFP_KERNEL);
4341 if (!(*req)->ring) {
4342 ql_log_pci(ql_log_fatal, ha->pdev, 0x0029,
4343 "Failed to allocate memory for req_ring.\n");
4346 /* Allocate memory for response ring */
4347 *rsp = kzalloc(sizeof(struct rsp_que), GFP_KERNEL);
4349 ql_log_pci(ql_log_fatal, ha->pdev, 0x002a,
4350 "Failed to allocate memory for rsp.\n");
4354 (*rsp)->length = rsp_len;
4355 (*rsp)->ring = dma_alloc_coherent(&ha->pdev->dev,
4356 ((*rsp)->length + 1) * sizeof(response_t),
4357 &(*rsp)->dma, GFP_KERNEL);
4358 if (!(*rsp)->ring) {
4359 ql_log_pci(ql_log_fatal, ha->pdev, 0x002b,
4360 "Failed to allocate memory for rsp_ring.\n");
4365 ql_dbg_pci(ql_dbg_init, ha->pdev, 0x002c,
4366 "req=%p req->length=%d req->ring=%p rsp=%p "
4367 "rsp->length=%d rsp->ring=%p.\n",
4368 *req, (*req)->length, (*req)->ring, *rsp, (*rsp)->length,
4370 /* Allocate memory for NVRAM data for vports */
4371 if (ha->nvram_npiv_size) {
4372 ha->npiv_info = kcalloc(ha->nvram_npiv_size,
4373 sizeof(struct qla_npiv_entry),
4375 if (!ha->npiv_info) {
4376 ql_log_pci(ql_log_fatal, ha->pdev, 0x002d,
4377 "Failed to allocate memory for npiv_info.\n");
4378 goto fail_npiv_info;
4381 ha->npiv_info = NULL;
4383 /* Get consistent memory allocated for EX-INIT-CB. */
4384 if (IS_CNA_CAPABLE(ha) || IS_QLA2031(ha) || IS_QLA27XX(ha) ||
4386 ha->ex_init_cb = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL,
4387 &ha->ex_init_cb_dma);
4388 if (!ha->ex_init_cb)
4389 goto fail_ex_init_cb;
4390 ql_dbg_pci(ql_dbg_init, ha->pdev, 0x002e,
4391 "ex_init_cb=%p.\n", ha->ex_init_cb);
4394 /* Get consistent memory allocated for Special Features-CB. */
4395 if (IS_QLA27XX(ha) || IS_QLA28XX(ha)) {
4396 ha->sf_init_cb = dma_pool_zalloc(ha->s_dma_pool, GFP_KERNEL,
4397 &ha->sf_init_cb_dma);
4398 if (!ha->sf_init_cb)
4399 goto fail_sf_init_cb;
4400 ql_dbg_pci(ql_dbg_init, ha->pdev, 0x0199,
4401 "sf_init_cb=%p.\n", ha->sf_init_cb);
4405 /* Get consistent memory allocated for Async Port-Database. */
4406 if (!IS_FWI2_CAPABLE(ha)) {
4407 ha->async_pd = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL,
4411 ql_dbg_pci(ql_dbg_init, ha->pdev, 0x002f,
4412 "async_pd=%p.\n", ha->async_pd);
4415 INIT_LIST_HEAD(&ha->vp_list);
4417 /* Allocate memory for our loop_id bitmap */
4418 ha->loop_id_map = kcalloc(BITS_TO_LONGS(LOOPID_MAP_SIZE),
4421 if (!ha->loop_id_map)
4422 goto fail_loop_id_map;
4424 qla2x00_set_reserved_loop_ids(ha);
4425 ql_dbg_pci(ql_dbg_init, ha->pdev, 0x0123,
4426 "loop_id_map=%p.\n", ha->loop_id_map);
4429 ha->sfp_data = dma_alloc_coherent(&ha->pdev->dev,
4430 SFP_DEV_SIZE, &ha->sfp_data_dma, GFP_KERNEL);
4431 if (!ha->sfp_data) {
4432 ql_dbg_pci(ql_dbg_init, ha->pdev, 0x011b,
4433 "Unable to allocate memory for SFP read-data.\n");
4437 ha->flt = dma_alloc_coherent(&ha->pdev->dev,
4438 sizeof(struct qla_flt_header) + FLT_REGIONS_SIZE, &ha->flt_dma,
4441 ql_dbg_pci(ql_dbg_init, ha->pdev, 0x011b,
4442 "Unable to allocate memory for FLT.\n");
4443 goto fail_flt_buffer;
4446 /* allocate the purex dma pool */
4447 ha->purex_dma_pool = dma_pool_create(name, &ha->pdev->dev,
4448 ELS_MAX_PAYLOAD, 8, 0);
4450 if (!ha->purex_dma_pool) {
4451 ql_dbg_pci(ql_dbg_init, ha->pdev, 0x011b,
4452 "Unable to allocate purex_dma_pool.\n");
4456 ha->elsrej.size = sizeof(struct fc_els_ls_rjt) + 16;
4457 ha->elsrej.c = dma_alloc_coherent(&ha->pdev->dev,
4461 if (!ha->elsrej.c) {
4462 ql_dbg_pci(ql_dbg_init, ha->pdev, 0xffff,
4463 "Alloc failed for els reject cmd.\n");
4466 ha->elsrej.c->er_cmd = ELS_LS_RJT;
4467 ha->elsrej.c->er_reason = ELS_RJT_LOGIC;
4468 ha->elsrej.c->er_explan = ELS_EXPL_UNAB_DATA;
4470 ha->lsrjt.size = sizeof(struct fcnvme_ls_rjt);
4471 ha->lsrjt.c = dma_alloc_coherent(&ha->pdev->dev, ha->lsrjt.size,
4472 &ha->lsrjt.cdma, GFP_KERNEL);
4474 ql_dbg_pci(ql_dbg_init, ha->pdev, 0xffff,
4475 "Alloc failed for nvme fc reject cmd.\n");
4482 dma_free_coherent(&ha->pdev->dev, ha->elsrej.size,
4483 ha->elsrej.c, ha->elsrej.cdma);
4485 dma_pool_destroy(ha->purex_dma_pool);
4487 dma_free_coherent(&ha->pdev->dev, SFP_DEV_SIZE,
4488 ha->flt, ha->flt_dma);
4491 dma_free_coherent(&ha->pdev->dev, SFP_DEV_SIZE,
4492 ha->sfp_data, ha->sfp_data_dma);
4494 kfree(ha->loop_id_map);
4496 dma_pool_free(ha->s_dma_pool, ha->async_pd, ha->async_pd_dma);
4498 dma_pool_free(ha->s_dma_pool, ha->sf_init_cb, ha->sf_init_cb_dma);
4500 dma_pool_free(ha->s_dma_pool, ha->ex_init_cb, ha->ex_init_cb_dma);
4502 kfree(ha->npiv_info);
4504 dma_free_coherent(&ha->pdev->dev, ((*rsp)->length + 1) *
4505 sizeof(response_t), (*rsp)->ring, (*rsp)->dma);
4506 (*rsp)->ring = NULL;
4512 dma_free_coherent(&ha->pdev->dev, ((*req)->length + 1) *
4513 sizeof(request_t), (*req)->ring, (*req)->dma);
4514 (*req)->ring = NULL;
4520 dma_free_coherent(&ha->pdev->dev, sizeof(struct ct_sns_pkt),
4521 ha->ct_sns, ha->ct_sns_dma);
4525 dma_pool_free(ha->s_dma_pool, ha->ms_iocb, ha->ms_iocb_dma);
4527 ha->ms_iocb_dma = 0;
4530 dma_free_coherent(&ha->pdev->dev, sizeof(struct sns_cmd_pkt),
4531 ha->sns_cmd, ha->sns_cmd_dma);
4533 if (ql2xenabledif) {
4534 struct dsd_dma *dsd, *nxt;
4536 list_for_each_entry_safe(dsd, nxt, &ha->pool.unusable.head,
4538 list_del(&dsd->list);
4539 dma_pool_free(ha->dif_bundl_pool, dsd->dsd_addr,
4541 ha->dif_bundle_dma_allocs--;
4543 ha->dif_bundle_kallocs--;
4544 ha->pool.unusable.count--;
4546 dma_pool_destroy(ha->dif_bundl_pool);
4547 ha->dif_bundl_pool = NULL;
4550 fail_dif_bundl_dma_pool:
4551 if (IS_QLA82XX(ha) || ql2xenabledif) {
4552 dma_pool_destroy(ha->fcp_cmnd_dma_pool);
4553 ha->fcp_cmnd_dma_pool = NULL;
4556 if (IS_QLA82XX(ha) || ql2xenabledif) {
4557 dma_pool_destroy(ha->dl_dma_pool);
4558 ha->dl_dma_pool = NULL;
4561 dma_pool_destroy(ha->s_dma_pool);
4562 ha->s_dma_pool = NULL;
4566 fail_free_ctx_mempool:
4567 mempool_destroy(ha->ctx_mempool);
4568 ha->ctx_mempool = NULL;
4569 fail_free_srb_mempool:
4570 mempool_destroy(ha->srb_mempool);
4571 ha->srb_mempool = NULL;
4573 dma_free_coherent(&ha->pdev->dev, qla2x00_gid_list_size(ha),
4576 ha->gid_list = NULL;
4577 ha->gid_list_dma = 0;
4581 btree_destroy32(&ha->host_map);
4583 dma_free_coherent(&ha->pdev->dev, ha->init_cb_size, ha->init_cb,
4586 ha->init_cb_dma = 0;
4591 ql_log(ql_log_fatal, NULL, 0x0030,
4592 "Memory allocation failure.\n");
4597 qla2x00_set_exlogins_buffer(scsi_qla_host_t *vha)
4600 uint16_t size, max_cnt;
4602 struct qla_hw_data *ha = vha->hw;
4604 /* Return if we don't need to alloacate any extended logins */
4605 if (ql2xexlogins <= MAX_FIBRE_DEVICES_2400)
4608 if (!IS_EXLOGIN_OFFLD_CAPABLE(ha))
4611 ql_log(ql_log_info, vha, 0xd021, "EXLOGIN count: %d.\n", ql2xexlogins);
4613 rval = qla_get_exlogin_status(vha, &size, &max_cnt);
4614 if (rval != QLA_SUCCESS) {
4615 ql_log_pci(ql_log_fatal, ha->pdev, 0xd029,
4616 "Failed to get exlogin status.\n");
4620 temp = (ql2xexlogins > max_cnt) ? max_cnt : ql2xexlogins;
4623 if (temp != ha->exlogin_size) {
4624 qla2x00_free_exlogin_buffer(ha);
4625 ha->exlogin_size = temp;
4627 ql_log(ql_log_info, vha, 0xd024,
4628 "EXLOGIN: max_logins=%d, portdb=0x%x, total=%d.\n",
4629 max_cnt, size, temp);
4631 ql_log(ql_log_info, vha, 0xd025,
4632 "EXLOGIN: requested size=0x%x\n", ha->exlogin_size);
4634 /* Get consistent memory for extended logins */
4635 ha->exlogin_buf = dma_alloc_coherent(&ha->pdev->dev,
4636 ha->exlogin_size, &ha->exlogin_buf_dma, GFP_KERNEL);
4637 if (!ha->exlogin_buf) {
4638 ql_log_pci(ql_log_fatal, ha->pdev, 0xd02a,
4639 "Failed to allocate memory for exlogin_buf_dma.\n");
4644 /* Now configure the dma buffer */
4645 rval = qla_set_exlogin_mem_cfg(vha, ha->exlogin_buf_dma);
4647 ql_log(ql_log_fatal, vha, 0xd033,
4648 "Setup extended login buffer ****FAILED****.\n");
4649 qla2x00_free_exlogin_buffer(ha);
4656 * qla2x00_free_exlogin_buffer
4659 * ha = adapter block pointer
4662 qla2x00_free_exlogin_buffer(struct qla_hw_data *ha)
4664 if (ha->exlogin_buf) {
4665 dma_free_coherent(&ha->pdev->dev, ha->exlogin_size,
4666 ha->exlogin_buf, ha->exlogin_buf_dma);
4667 ha->exlogin_buf = NULL;
4668 ha->exlogin_size = 0;
4673 qla2x00_number_of_exch(scsi_qla_host_t *vha, u32 *ret_cnt, u16 max_cnt)
4676 struct init_cb_81xx *icb = (struct init_cb_81xx *)vha->hw->init_cb;
4677 *ret_cnt = FW_DEF_EXCHANGES_CNT;
4679 if (max_cnt > vha->hw->max_exchg)
4680 max_cnt = vha->hw->max_exchg;
4682 if (qla_ini_mode_enabled(vha)) {
4683 if (vha->ql2xiniexchg > max_cnt)
4684 vha->ql2xiniexchg = max_cnt;
4686 if (vha->ql2xiniexchg > FW_DEF_EXCHANGES_CNT)
4687 *ret_cnt = vha->ql2xiniexchg;
4689 } else if (qla_tgt_mode_enabled(vha)) {
4690 if (vha->ql2xexchoffld > max_cnt) {
4691 vha->ql2xexchoffld = max_cnt;
4692 icb->exchange_count = cpu_to_le16(vha->ql2xexchoffld);
4695 if (vha->ql2xexchoffld > FW_DEF_EXCHANGES_CNT)
4696 *ret_cnt = vha->ql2xexchoffld;
4697 } else if (qla_dual_mode_enabled(vha)) {
4698 temp = vha->ql2xiniexchg + vha->ql2xexchoffld;
4699 if (temp > max_cnt) {
4700 vha->ql2xiniexchg -= (temp - max_cnt)/2;
4701 vha->ql2xexchoffld -= (((temp - max_cnt)/2) + 1);
4703 icb->exchange_count = cpu_to_le16(vha->ql2xexchoffld);
4706 if (temp > FW_DEF_EXCHANGES_CNT)
4712 qla2x00_set_exchoffld_buffer(scsi_qla_host_t *vha)
4716 u32 actual_cnt, totsz;
4717 struct qla_hw_data *ha = vha->hw;
4719 if (!ha->flags.exchoffld_enabled)
4722 if (!IS_EXCHG_OFFLD_CAPABLE(ha))
4726 rval = qla_get_exchoffld_status(vha, &size, &max_cnt);
4727 if (rval != QLA_SUCCESS) {
4728 ql_log_pci(ql_log_fatal, ha->pdev, 0xd012,
4729 "Failed to get exlogin status.\n");
4733 qla2x00_number_of_exch(vha, &actual_cnt, max_cnt);
4734 ql_log(ql_log_info, vha, 0xd014,
4735 "Actual exchange offload count: %d.\n", actual_cnt);
4737 totsz = actual_cnt * size;
4739 if (totsz != ha->exchoffld_size) {
4740 qla2x00_free_exchoffld_buffer(ha);
4741 if (actual_cnt <= FW_DEF_EXCHANGES_CNT) {
4742 ha->exchoffld_size = 0;
4743 ha->flags.exchoffld_enabled = 0;
4747 ha->exchoffld_size = totsz;
4749 ql_log(ql_log_info, vha, 0xd016,
4750 "Exchange offload: max_count=%d, actual count=%d entry sz=0x%x, total sz=0x%x\n",
4751 max_cnt, actual_cnt, size, totsz);
4753 ql_log(ql_log_info, vha, 0xd017,
4754 "Exchange Buffers requested size = 0x%x\n",
4755 ha->exchoffld_size);
4757 /* Get consistent memory for extended logins */
4758 ha->exchoffld_buf = dma_alloc_coherent(&ha->pdev->dev,
4759 ha->exchoffld_size, &ha->exchoffld_buf_dma, GFP_KERNEL);
4760 if (!ha->exchoffld_buf) {
4761 ql_log_pci(ql_log_fatal, ha->pdev, 0xd013,
4762 "Failed to allocate memory for Exchange Offload.\n");
4765 (FW_DEF_EXCHANGES_CNT + REDUCE_EXCHANGES_CNT)) {
4766 ha->max_exchg -= REDUCE_EXCHANGES_CNT;
4767 } else if (ha->max_exchg >
4768 (FW_DEF_EXCHANGES_CNT + 512)) {
4769 ha->max_exchg -= 512;
4771 ha->flags.exchoffld_enabled = 0;
4772 ql_log_pci(ql_log_fatal, ha->pdev, 0xd013,
4773 "Disabling Exchange offload due to lack of memory\n");
4775 ha->exchoffld_size = 0;
4779 } else if (!ha->exchoffld_buf || (actual_cnt <= FW_DEF_EXCHANGES_CNT)) {
4780 /* pathological case */
4781 qla2x00_free_exchoffld_buffer(ha);
4782 ha->exchoffld_size = 0;
4783 ha->flags.exchoffld_enabled = 0;
4784 ql_log(ql_log_info, vha, 0xd016,
4785 "Exchange offload not enable: offld size=%d, actual count=%d entry sz=0x%x, total sz=0x%x.\n",
4786 ha->exchoffld_size, actual_cnt, size, totsz);
4790 /* Now configure the dma buffer */
4791 rval = qla_set_exchoffld_mem_cfg(vha);
4793 ql_log(ql_log_fatal, vha, 0xd02e,
4794 "Setup exchange offload buffer ****FAILED****.\n");
4795 qla2x00_free_exchoffld_buffer(ha);
4797 /* re-adjust number of target exchange */
4798 struct init_cb_81xx *icb = (struct init_cb_81xx *)ha->init_cb;
4800 if (qla_ini_mode_enabled(vha))
4801 icb->exchange_count = 0;
4803 icb->exchange_count = cpu_to_le16(vha->ql2xexchoffld);
4810 * qla2x00_free_exchoffld_buffer
4813 * ha = adapter block pointer
4816 qla2x00_free_exchoffld_buffer(struct qla_hw_data *ha)
4818 if (ha->exchoffld_buf) {
4819 dma_free_coherent(&ha->pdev->dev, ha->exchoffld_size,
4820 ha->exchoffld_buf, ha->exchoffld_buf_dma);
4821 ha->exchoffld_buf = NULL;
4822 ha->exchoffld_size = 0;
4827 * qla2x00_free_fw_dump
4828 * Frees fw dump stuff.
4831 * ha = adapter block pointer
4834 qla2x00_free_fw_dump(struct qla_hw_data *ha)
4836 struct fwdt *fwdt = ha->fwdt;
4840 dma_free_coherent(&ha->pdev->dev,
4841 FCE_SIZE, ha->fce, ha->fce_dma);
4844 dma_free_coherent(&ha->pdev->dev,
4845 EFT_SIZE, ha->eft, ha->eft_dma);
4851 ha->flags.fce_enabled = 0;
4854 ha->fw_dumped = false;
4855 ha->fw_dump_cap_flags = 0;
4856 ha->fw_dump_reading = 0;
4858 ha->fw_dump_len = 0;
4860 for (j = 0; j < 2; j++, fwdt++) {
4861 vfree(fwdt->template);
4862 fwdt->template = NULL;
4869 * Frees all adapter allocated memory.
4872 * ha = adapter block pointer.
4875 qla2x00_mem_free(struct qla_hw_data *ha)
4877 qla2x00_free_fw_dump(ha);
4880 dma_free_coherent(&ha->pdev->dev, MCTP_DUMP_SIZE, ha->mctp_dump,
4882 ha->mctp_dump = NULL;
4884 mempool_destroy(ha->srb_mempool);
4885 ha->srb_mempool = NULL;
4888 dma_free_coherent(&ha->pdev->dev, DCBX_TLV_DATA_SIZE,
4889 ha->dcbx_tlv, ha->dcbx_tlv_dma);
4890 ha->dcbx_tlv = NULL;
4893 dma_free_coherent(&ha->pdev->dev, XGMAC_DATA_SIZE,
4894 ha->xgmac_data, ha->xgmac_data_dma);
4895 ha->xgmac_data = NULL;
4898 dma_free_coherent(&ha->pdev->dev, sizeof(struct sns_cmd_pkt),
4899 ha->sns_cmd, ha->sns_cmd_dma);
4901 ha->sns_cmd_dma = 0;
4904 dma_free_coherent(&ha->pdev->dev, sizeof(struct ct_sns_pkt),
4905 ha->ct_sns, ha->ct_sns_dma);
4910 dma_free_coherent(&ha->pdev->dev, SFP_DEV_SIZE, ha->sfp_data,
4912 ha->sfp_data = NULL;
4915 dma_free_coherent(&ha->pdev->dev,
4916 sizeof(struct qla_flt_header) + FLT_REGIONS_SIZE,
4917 ha->flt, ha->flt_dma);
4922 dma_pool_free(ha->s_dma_pool, ha->ms_iocb, ha->ms_iocb_dma);
4924 ha->ms_iocb_dma = 0;
4927 dma_pool_free(ha->s_dma_pool,
4928 ha->sf_init_cb, ha->sf_init_cb_dma);
4931 dma_pool_free(ha->s_dma_pool,
4932 ha->ex_init_cb, ha->ex_init_cb_dma);
4933 ha->ex_init_cb = NULL;
4934 ha->ex_init_cb_dma = 0;
4937 dma_pool_free(ha->s_dma_pool, ha->async_pd, ha->async_pd_dma);
4938 ha->async_pd = NULL;
4939 ha->async_pd_dma = 0;
4941 dma_pool_destroy(ha->s_dma_pool);
4942 ha->s_dma_pool = NULL;
4945 dma_free_coherent(&ha->pdev->dev, qla2x00_gid_list_size(ha),
4946 ha->gid_list, ha->gid_list_dma);
4947 ha->gid_list = NULL;
4948 ha->gid_list_dma = 0;
4950 if (ha->base_qpair && !list_empty(&ha->base_qpair->dsd_list)) {
4951 struct dsd_dma *dsd_ptr, *tdsd_ptr;
4953 /* clean up allocated prev pool */
4954 list_for_each_entry_safe(dsd_ptr, tdsd_ptr,
4955 &ha->base_qpair->dsd_list, list) {
4956 dma_pool_free(ha->dl_dma_pool, dsd_ptr->dsd_addr,
4957 dsd_ptr->dsd_list_dma);
4958 list_del(&dsd_ptr->list);
4963 dma_pool_destroy(ha->dl_dma_pool);
4964 ha->dl_dma_pool = NULL;
4966 dma_pool_destroy(ha->fcp_cmnd_dma_pool);
4967 ha->fcp_cmnd_dma_pool = NULL;
4969 mempool_destroy(ha->ctx_mempool);
4970 ha->ctx_mempool = NULL;
4972 if (ql2xenabledif && ha->dif_bundl_pool) {
4973 struct dsd_dma *dsd, *nxt;
4975 list_for_each_entry_safe(dsd, nxt, &ha->pool.unusable.head,
4977 list_del(&dsd->list);
4978 dma_pool_free(ha->dif_bundl_pool, dsd->dsd_addr,
4980 ha->dif_bundle_dma_allocs--;
4982 ha->dif_bundle_kallocs--;
4983 ha->pool.unusable.count--;
4985 list_for_each_entry_safe(dsd, nxt, &ha->pool.good.head, list) {
4986 list_del(&dsd->list);
4987 dma_pool_free(ha->dif_bundl_pool, dsd->dsd_addr,
4989 ha->dif_bundle_dma_allocs--;
4991 ha->dif_bundle_kallocs--;
4995 dma_pool_destroy(ha->dif_bundl_pool);
4996 ha->dif_bundl_pool = NULL;
4999 qla_remove_hostmap(ha);
5002 dma_free_coherent(&ha->pdev->dev, ha->init_cb_size,
5003 ha->init_cb, ha->init_cb_dma);
5005 dma_pool_destroy(ha->purex_dma_pool);
5006 ha->purex_dma_pool = NULL;
5009 dma_free_coherent(&ha->pdev->dev, ha->elsrej.size,
5010 ha->elsrej.c, ha->elsrej.cdma);
5011 ha->elsrej.c = NULL;
5015 dma_free_coherent(&ha->pdev->dev, ha->lsrjt.size, ha->lsrjt.c,
5021 ha->init_cb_dma = 0;
5023 vfree(ha->optrom_buffer);
5024 ha->optrom_buffer = NULL;
5027 kfree(ha->npiv_info);
5028 ha->npiv_info = NULL;
5031 kfree(ha->loop_id_map);
5032 ha->sf_init_cb = NULL;
5033 ha->sf_init_cb_dma = 0;
5034 ha->loop_id_map = NULL;
5040 struct scsi_qla_host *qla2x00_create_host(const struct scsi_host_template *sht,
5041 struct qla_hw_data *ha)
5043 struct Scsi_Host *host;
5044 struct scsi_qla_host *vha = NULL;
5046 host = scsi_host_alloc(sht, sizeof(scsi_qla_host_t));
5048 ql_log_pci(ql_log_fatal, ha->pdev, 0x0107,
5049 "Failed to allocate host from the scsi layer, aborting.\n");
5053 /* Clear our data area */
5054 vha = shost_priv(host);
5055 memset(vha, 0, sizeof(scsi_qla_host_t));
5058 vha->host_no = host->host_no;
5061 vha->qlini_mode = ql2x_ini_mode;
5062 vha->ql2xexchoffld = ql2xexchoffld;
5063 vha->ql2xiniexchg = ql2xiniexchg;
5065 INIT_LIST_HEAD(&vha->vp_fcports);
5066 INIT_LIST_HEAD(&vha->work_list);
5067 INIT_LIST_HEAD(&vha->list);
5068 INIT_LIST_HEAD(&vha->qla_cmd_list);
5069 INIT_LIST_HEAD(&vha->logo_list);
5070 INIT_LIST_HEAD(&vha->plogi_ack_list);
5071 INIT_LIST_HEAD(&vha->qp_list);
5072 INIT_LIST_HEAD(&vha->gnl.fcports);
5073 INIT_WORK(&vha->iocb_work, qla2x00_iocb_work_fn);
5075 INIT_LIST_HEAD(&vha->purex_list.head);
5076 spin_lock_init(&vha->purex_list.lock);
5078 spin_lock_init(&vha->work_lock);
5079 spin_lock_init(&vha->cmd_list_lock);
5080 init_waitqueue_head(&vha->fcport_waitQ);
5081 init_waitqueue_head(&vha->vref_waitq);
5082 qla_enode_init(vha);
5086 vha->gnl.size = sizeof(struct get_name_list_extended) *
5087 (ha->max_loop_id + 1);
5088 vha->gnl.l = dma_alloc_coherent(&ha->pdev->dev,
5089 vha->gnl.size, &vha->gnl.ldma, GFP_KERNEL);
5091 ql_log(ql_log_fatal, vha, 0xd04a,
5092 "Alloc failed for name list.\n");
5093 scsi_host_put(vha->host);
5097 /* todo: what about ext login? */
5098 vha->scan.size = ha->max_fibre_devices * sizeof(struct fab_scan_rp);
5099 vha->scan.l = vmalloc(vha->scan.size);
5101 ql_log(ql_log_fatal, vha, 0xd04a,
5102 "Alloc failed for scan database.\n");
5103 dma_free_coherent(&ha->pdev->dev, vha->gnl.size,
5104 vha->gnl.l, vha->gnl.ldma);
5106 scsi_host_put(vha->host);
5109 INIT_DELAYED_WORK(&vha->scan.scan_work, qla_scan_work_fn);
5111 snprintf(vha->host_str, sizeof(vha->host_str), "%s_%lu",
5112 QLA2XXX_DRIVER_NAME, vha->host_no);
5113 ql_dbg(ql_dbg_init, vha, 0x0041,
5114 "Allocated the host=%p hw=%p vha=%p dev_name=%s",
5115 vha->host, vha->hw, vha,
5116 dev_name(&(ha->pdev->dev)));
5121 struct qla_work_evt *
5122 qla2x00_alloc_work(struct scsi_qla_host *vha, enum qla_work_type type)
5124 struct qla_work_evt *e;
5126 if (test_bit(UNLOADING, &vha->dpc_flags))
5129 if (qla_vha_mark_busy(vha))
5132 e = kzalloc(sizeof(struct qla_work_evt), GFP_ATOMIC);
5134 QLA_VHA_MARK_NOT_BUSY(vha);
5138 INIT_LIST_HEAD(&e->list);
5140 e->flags = QLA_EVT_FLAG_FREE;
5145 qla2x00_post_work(struct scsi_qla_host *vha, struct qla_work_evt *e)
5147 unsigned long flags;
5150 spin_lock_irqsave(&vha->work_lock, flags);
5151 list_add_tail(&e->list, &vha->work_list);
5153 if (!test_and_set_bit(IOCB_WORK_ACTIVE, &vha->dpc_flags))
5156 spin_unlock_irqrestore(&vha->work_lock, flags);
5159 queue_work(vha->hw->wq, &vha->iocb_work);
5165 qla2x00_post_aen_work(struct scsi_qla_host *vha, enum fc_host_event_code code,
5168 struct qla_work_evt *e;
5170 e = qla2x00_alloc_work(vha, QLA_EVT_AEN);
5172 return QLA_FUNCTION_FAILED;
5174 e->u.aen.code = code;
5175 e->u.aen.data = data;
5176 return qla2x00_post_work(vha, e);
5180 qla2x00_post_idc_ack_work(struct scsi_qla_host *vha, uint16_t *mb)
5182 struct qla_work_evt *e;
5184 e = qla2x00_alloc_work(vha, QLA_EVT_IDC_ACK);
5186 return QLA_FUNCTION_FAILED;
5188 memcpy(e->u.idc_ack.mb, mb, QLA_IDC_ACK_REGS * sizeof(uint16_t));
5189 return qla2x00_post_work(vha, e);
5192 #define qla2x00_post_async_work(name, type) \
5193 int qla2x00_post_async_##name##_work( \
5194 struct scsi_qla_host *vha, \
5195 fc_port_t *fcport, uint16_t *data) \
5197 struct qla_work_evt *e; \
5199 e = qla2x00_alloc_work(vha, type); \
5201 return QLA_FUNCTION_FAILED; \
5203 e->u.logio.fcport = fcport; \
5205 e->u.logio.data[0] = data[0]; \
5206 e->u.logio.data[1] = data[1]; \
5208 fcport->flags |= FCF_ASYNC_ACTIVE; \
5209 return qla2x00_post_work(vha, e); \
5212 qla2x00_post_async_work(login, QLA_EVT_ASYNC_LOGIN);
5213 qla2x00_post_async_work(logout, QLA_EVT_ASYNC_LOGOUT);
5214 qla2x00_post_async_work(adisc, QLA_EVT_ASYNC_ADISC);
5215 qla2x00_post_async_work(prlo, QLA_EVT_ASYNC_PRLO);
5216 qla2x00_post_async_work(prlo_done, QLA_EVT_ASYNC_PRLO_DONE);
5219 qla2x00_post_uevent_work(struct scsi_qla_host *vha, u32 code)
5221 struct qla_work_evt *e;
5223 e = qla2x00_alloc_work(vha, QLA_EVT_UEVENT);
5225 return QLA_FUNCTION_FAILED;
5227 e->u.uevent.code = code;
5228 return qla2x00_post_work(vha, e);
5232 qla2x00_uevent_emit(struct scsi_qla_host *vha, u32 code)
5234 char event_string[40];
5235 char *envp[] = { event_string, NULL };
5238 case QLA_UEVENT_CODE_FW_DUMP:
5239 snprintf(event_string, sizeof(event_string), "FW_DUMP=%lu",
5246 kobject_uevent_env(&vha->hw->pdev->dev.kobj, KOBJ_CHANGE, envp);
5250 qlafx00_post_aenfx_work(struct scsi_qla_host *vha, uint32_t evtcode,
5251 uint32_t *data, int cnt)
5253 struct qla_work_evt *e;
5255 e = qla2x00_alloc_work(vha, QLA_EVT_AENFX);
5257 return QLA_FUNCTION_FAILED;
5259 e->u.aenfx.evtcode = evtcode;
5260 e->u.aenfx.count = cnt;
5261 memcpy(e->u.aenfx.mbx, data, sizeof(*data) * cnt);
5262 return qla2x00_post_work(vha, e);
5265 void qla24xx_sched_upd_fcport(fc_port_t *fcport)
5267 unsigned long flags;
5269 if (IS_SW_RESV_ADDR(fcport->d_id))
5272 spin_lock_irqsave(&fcport->vha->work_lock, flags);
5273 if (fcport->disc_state == DSC_UPD_FCPORT) {
5274 spin_unlock_irqrestore(&fcport->vha->work_lock, flags);
5277 fcport->jiffies_at_registration = jiffies;
5278 fcport->sec_since_registration = 0;
5279 fcport->next_disc_state = DSC_DELETED;
5280 qla2x00_set_fcport_disc_state(fcport, DSC_UPD_FCPORT);
5281 spin_unlock_irqrestore(&fcport->vha->work_lock, flags);
5283 queue_work(system_unbound_wq, &fcport->reg_work);
5287 void qla24xx_create_new_sess(struct scsi_qla_host *vha, struct qla_work_evt *e)
5289 unsigned long flags;
5290 fc_port_t *fcport = NULL, *tfcp;
5291 struct qlt_plogi_ack_t *pla =
5292 (struct qlt_plogi_ack_t *)e->u.new_sess.pla;
5293 uint8_t free_fcport = 0;
5295 ql_dbg(ql_dbg_disc, vha, 0xffff,
5296 "%s %d %8phC enter\n",
5297 __func__, __LINE__, e->u.new_sess.port_name);
5299 spin_lock_irqsave(&vha->hw->tgt.sess_lock, flags);
5300 fcport = qla2x00_find_fcport_by_wwpn(vha, e->u.new_sess.port_name, 1);
5302 fcport->d_id = e->u.new_sess.id;
5304 fcport->fw_login_state = DSC_LS_PLOGI_PEND;
5305 memcpy(fcport->node_name,
5306 pla->iocb.u.isp24.u.plogi.node_name,
5308 qlt_plogi_ack_link(vha, pla, fcport, QLT_PLOGI_LINK_SAME_WWN);
5309 /* we took an extra ref_count to prevent PLOGI ACK when
5310 * fcport/sess has not been created.
5315 spin_unlock_irqrestore(&vha->hw->tgt.sess_lock, flags);
5316 fcport = qla2x00_alloc_fcport(vha, GFP_KERNEL);
5318 fcport->d_id = e->u.new_sess.id;
5319 fcport->flags |= FCF_FABRIC_DEVICE;
5320 fcport->fw_login_state = DSC_LS_PLOGI_PEND;
5321 fcport->tgt_short_link_down_cnt = 0;
5323 memcpy(fcport->port_name, e->u.new_sess.port_name,
5326 fcport->fc4_type = e->u.new_sess.fc4_type;
5327 if (NVME_PRIORITY(vha->hw, fcport))
5328 fcport->do_prli_nvme = 1;
5330 fcport->do_prli_nvme = 0;
5332 if (e->u.new_sess.fc4_type & FS_FCP_IS_N2N) {
5333 fcport->dm_login_expire = jiffies +
5334 QLA_N2N_WAIT_TIME * HZ;
5335 fcport->fc4_type = FS_FC4TYPE_FCP;
5336 fcport->n2n_flag = 1;
5337 if (vha->flags.nvme_enabled)
5338 fcport->fc4_type |= FS_FC4TYPE_NVME;
5342 ql_dbg(ql_dbg_disc, vha, 0xffff,
5343 "%s %8phC mem alloc fail.\n",
5344 __func__, e->u.new_sess.port_name);
5347 list_del(&pla->list);
5348 kmem_cache_free(qla_tgt_plogi_cachep, pla);
5353 spin_lock_irqsave(&vha->hw->tgt.sess_lock, flags);
5354 /* search again to make sure no one else got ahead */
5355 tfcp = qla2x00_find_fcport_by_wwpn(vha,
5356 e->u.new_sess.port_name, 1);
5358 /* should rarily happen */
5359 ql_dbg(ql_dbg_disc, vha, 0xffff,
5360 "%s %8phC found existing fcport b4 add. DS %d LS %d\n",
5361 __func__, tfcp->port_name, tfcp->disc_state,
5362 tfcp->fw_login_state);
5366 list_add_tail(&fcport->list, &vha->vp_fcports);
5370 qlt_plogi_ack_link(vha, pla, fcport,
5371 QLT_PLOGI_LINK_SAME_WWN);
5375 spin_unlock_irqrestore(&vha->hw->tgt.sess_lock, flags);
5378 fcport->id_changed = 1;
5379 fcport->scan_state = QLA_FCPORT_FOUND;
5380 fcport->chip_reset = vha->hw->base_qpair->chip_reset;
5381 memcpy(fcport->node_name, e->u.new_sess.node_name, WWN_SIZE);
5384 if (pla->iocb.u.isp24.status_subcode == ELS_PRLI) {
5387 fcport->fw_login_state = DSC_LS_PRLI_PEND;
5391 pla->iocb.u.isp24.nport_handle);
5392 fcport->fw_login_state = DSC_LS_PRLI_PEND;
5395 pla->iocb.u.isp24.u.prli.wd3_lo);
5398 fcport->conf_compl_supported = 1;
5400 if ((wd3_lo & BIT_4) == 0)
5401 fcport->port_type = FCT_INITIATOR;
5403 fcport->port_type = FCT_TARGET;
5405 qlt_plogi_ack_unref(vha, pla);
5407 fc_port_t *dfcp = NULL;
5409 spin_lock_irqsave(&vha->hw->tgt.sess_lock, flags);
5410 tfcp = qla2x00_find_fcport_by_nportid(vha,
5411 &e->u.new_sess.id, 1);
5412 if (tfcp && (tfcp != fcport)) {
5414 * We have a conflict fcport with same NportID.
5416 ql_dbg(ql_dbg_disc, vha, 0xffff,
5417 "%s %8phC found conflict b4 add. DS %d LS %d\n",
5418 __func__, tfcp->port_name, tfcp->disc_state,
5419 tfcp->fw_login_state);
5421 switch (tfcp->disc_state) {
5424 case DSC_DELETE_PEND:
5425 fcport->login_pause = 1;
5426 tfcp->conflict = fcport;
5429 fcport->login_pause = 1;
5430 tfcp->conflict = fcport;
5435 spin_unlock_irqrestore(&vha->hw->tgt.sess_lock, flags);
5437 qlt_schedule_sess_for_deletion(tfcp);
5439 if (N2N_TOPO(vha->hw)) {
5440 fcport->flags &= ~FCF_FABRIC_DEVICE;
5441 fcport->keep_nport_handle = 1;
5442 if (vha->flags.nvme_enabled) {
5444 (FS_FC4TYPE_NVME | FS_FC4TYPE_FCP);
5445 fcport->n2n_flag = 1;
5447 fcport->fw_login_state = 0;
5449 schedule_delayed_work(&vha->scan.scan_work, 5);
5451 qla24xx_fcport_handle_login(vha, fcport);
5457 qla2x00_free_fcport(fcport);
5459 list_del(&pla->list);
5460 kmem_cache_free(qla_tgt_plogi_cachep, pla);
5465 static void qla_sp_retry(struct scsi_qla_host *vha, struct qla_work_evt *e)
5467 struct srb *sp = e->u.iosb.sp;
5470 rval = qla2x00_start_sp(sp);
5471 if (rval != QLA_SUCCESS) {
5472 ql_dbg(ql_dbg_disc, vha, 0x2043,
5473 "%s: %s: Re-issue IOCB failed (%d).\n",
5474 __func__, sp->name, rval);
5475 qla24xx_sp_unmap(vha, sp);
5480 qla2x00_do_work(struct scsi_qla_host *vha)
5482 struct qla_work_evt *e, *tmp;
5483 unsigned long flags;
5487 spin_lock_irqsave(&vha->work_lock, flags);
5488 list_splice_init(&vha->work_list, &work);
5489 spin_unlock_irqrestore(&vha->work_lock, flags);
5491 list_for_each_entry_safe(e, tmp, &work, list) {
5495 fc_host_post_event(vha->host, fc_get_event_number(),
5496 e->u.aen.code, e->u.aen.data);
5498 case QLA_EVT_IDC_ACK:
5499 qla81xx_idc_ack(vha, e->u.idc_ack.mb);
5501 case QLA_EVT_ASYNC_LOGIN:
5502 qla2x00_async_login(vha, e->u.logio.fcport,
5505 case QLA_EVT_ASYNC_LOGOUT:
5506 rc = qla2x00_async_logout(vha, e->u.logio.fcport);
5508 case QLA_EVT_ASYNC_ADISC:
5509 qla2x00_async_adisc(vha, e->u.logio.fcport,
5512 case QLA_EVT_UEVENT:
5513 qla2x00_uevent_emit(vha, e->u.uevent.code);
5516 qlafx00_process_aen(vha, e);
5519 qla24xx_sp_unmap(vha, e->u.iosb.sp);
5521 case QLA_EVT_RELOGIN:
5522 qla2x00_relogin(vha);
5524 case QLA_EVT_NEW_SESS:
5525 qla24xx_create_new_sess(vha, e);
5528 qla24xx_async_gpdb(vha, e->u.fcport.fcport,
5532 qla24xx_async_prli(vha, e->u.fcport.fcport);
5535 qla24xx_async_gpsc(vha, e->u.fcport.fcport);
5538 qla24xx_async_gnl(vha, e->u.fcport.fcport);
5541 qla24xx_do_nack_work(vha, e);
5543 case QLA_EVT_ASYNC_PRLO:
5544 rc = qla2x00_async_prlo(vha, e->u.logio.fcport);
5546 case QLA_EVT_ASYNC_PRLO_DONE:
5547 qla2x00_async_prlo_done(vha, e->u.logio.fcport,
5550 case QLA_EVT_SCAN_CMD:
5551 qla_fab_async_scan(vha, e->u.iosb.sp);
5553 case QLA_EVT_SCAN_FINISH:
5554 qla_fab_scan_finish(vha, e->u.iosb.sp);
5556 case QLA_EVT_GFPNID:
5557 qla24xx_async_gfpnid(vha, e->u.fcport.fcport);
5559 case QLA_EVT_SP_RETRY:
5560 qla_sp_retry(vha, e);
5563 qla_do_iidma_work(vha, e->u.fcport.fcport);
5565 case QLA_EVT_ELS_PLOGI:
5566 qla24xx_els_dcmd2_iocb(vha, ELS_DCMD_PLOGI,
5567 e->u.fcport.fcport);
5569 case QLA_EVT_SA_REPLACE:
5570 rc = qla24xx_issue_sa_replace_iocb(vha, e);
5575 /* put 'work' at head of 'vha->work_list' */
5576 spin_lock_irqsave(&vha->work_lock, flags);
5577 list_splice(&work, &vha->work_list);
5578 spin_unlock_irqrestore(&vha->work_lock, flags);
5581 list_del_init(&e->list);
5582 if (e->flags & QLA_EVT_FLAG_FREE)
5585 /* For each work completed decrement vha ref count */
5586 QLA_VHA_MARK_NOT_BUSY(vha);
5590 int qla24xx_post_relogin_work(struct scsi_qla_host *vha)
5592 struct qla_work_evt *e;
5594 e = qla2x00_alloc_work(vha, QLA_EVT_RELOGIN);
5597 set_bit(RELOGIN_NEEDED, &vha->dpc_flags);
5598 return QLA_FUNCTION_FAILED;
5601 return qla2x00_post_work(vha, e);
5604 /* Relogins all the fcports of a vport
5605 * Context: dpc thread
5607 void qla2x00_relogin(struct scsi_qla_host *vha)
5610 int status, relogin_needed = 0;
5611 struct event_arg ea;
5613 list_for_each_entry(fcport, &vha->vp_fcports, list) {
5615 * If the port is not ONLINE then try to login
5616 * to it if we haven't run out of retries.
5618 if (atomic_read(&fcport->state) != FCS_ONLINE &&
5619 fcport->login_retry) {
5620 if (fcport->scan_state != QLA_FCPORT_FOUND ||
5621 fcport->disc_state == DSC_LOGIN_AUTH_PEND ||
5622 fcport->disc_state == DSC_LOGIN_COMPLETE)
5625 if (fcport->flags & (FCF_ASYNC_SENT|FCF_ASYNC_ACTIVE) ||
5626 fcport->disc_state == DSC_DELETE_PEND) {
5629 if (vha->hw->current_topology != ISP_CFG_NL) {
5630 memset(&ea, 0, sizeof(ea));
5632 qla24xx_handle_relogin_event(vha, &ea);
5633 } else if (vha->hw->current_topology ==
5635 IS_QLA2XXX_MIDTYPE(vha->hw)) {
5636 (void)qla24xx_fcport_handle_login(vha,
5638 } else if (vha->hw->current_topology ==
5640 fcport->login_retry--;
5642 qla2x00_local_device_login(vha,
5644 if (status == QLA_SUCCESS) {
5645 fcport->old_loop_id =
5647 ql_dbg(ql_dbg_disc, vha, 0x2003,
5648 "Port login OK: logged in ID 0x%x.\n",
5650 qla2x00_update_fcport
5652 } else if (status == 1) {
5653 set_bit(RELOGIN_NEEDED,
5655 /* retry the login again */
5656 ql_dbg(ql_dbg_disc, vha, 0x2007,
5657 "Retrying %d login again loop_id 0x%x.\n",
5658 fcport->login_retry,
5661 fcport->login_retry = 0;
5664 if (fcport->login_retry == 0 &&
5665 status != QLA_SUCCESS)
5666 qla2x00_clear_loop_id(fcport);
5670 if (test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags))
5675 set_bit(RELOGIN_NEEDED, &vha->dpc_flags);
5677 ql_dbg(ql_dbg_disc, vha, 0x400e,
5681 /* Schedule work on any of the dpc-workqueues */
5683 qla83xx_schedule_work(scsi_qla_host_t *base_vha, int work_code)
5685 struct qla_hw_data *ha = base_vha->hw;
5687 switch (work_code) {
5688 case MBA_IDC_AEN: /* 0x8200 */
5690 queue_work(ha->dpc_lp_wq, &ha->idc_aen);
5693 case QLA83XX_NIC_CORE_RESET: /* 0x1 */
5694 if (!ha->flags.nic_core_reset_hdlr_active) {
5696 queue_work(ha->dpc_hp_wq, &ha->nic_core_reset);
5698 ql_dbg(ql_dbg_p3p, base_vha, 0xb05e,
5699 "NIC Core reset is already active. Skip "
5700 "scheduling it again.\n");
5702 case QLA83XX_IDC_STATE_HANDLER: /* 0x2 */
5704 queue_work(ha->dpc_hp_wq, &ha->idc_state_handler);
5706 case QLA83XX_NIC_CORE_UNRECOVERABLE: /* 0x3 */
5708 queue_work(ha->dpc_hp_wq, &ha->nic_core_unrecoverable);
5711 ql_log(ql_log_warn, base_vha, 0xb05f,
5712 "Unknown work-code=0x%x.\n", work_code);
5718 /* Work: Perform NIC Core Unrecoverable state handling */
5720 qla83xx_nic_core_unrecoverable_work(struct work_struct *work)
5722 struct qla_hw_data *ha =
5723 container_of(work, struct qla_hw_data, nic_core_unrecoverable);
5724 scsi_qla_host_t *base_vha = pci_get_drvdata(ha->pdev);
5725 uint32_t dev_state = 0;
5727 qla83xx_idc_lock(base_vha, 0);
5728 qla83xx_rd_reg(base_vha, QLA83XX_IDC_DEV_STATE, &dev_state);
5729 qla83xx_reset_ownership(base_vha);
5730 if (ha->flags.nic_core_reset_owner) {
5731 ha->flags.nic_core_reset_owner = 0;
5732 qla83xx_wr_reg(base_vha, QLA83XX_IDC_DEV_STATE,
5733 QLA8XXX_DEV_FAILED);
5734 ql_log(ql_log_info, base_vha, 0xb060, "HW State: FAILED.\n");
5735 qla83xx_schedule_work(base_vha, QLA83XX_IDC_STATE_HANDLER);
5737 qla83xx_idc_unlock(base_vha, 0);
5740 /* Work: Execute IDC state handler */
5742 qla83xx_idc_state_handler_work(struct work_struct *work)
5744 struct qla_hw_data *ha =
5745 container_of(work, struct qla_hw_data, idc_state_handler);
5746 scsi_qla_host_t *base_vha = pci_get_drvdata(ha->pdev);
5747 uint32_t dev_state = 0;
5749 qla83xx_idc_lock(base_vha, 0);
5750 qla83xx_rd_reg(base_vha, QLA83XX_IDC_DEV_STATE, &dev_state);
5751 if (dev_state == QLA8XXX_DEV_FAILED ||
5752 dev_state == QLA8XXX_DEV_NEED_QUIESCENT)
5753 qla83xx_idc_state_handler(base_vha);
5754 qla83xx_idc_unlock(base_vha, 0);
5758 qla83xx_check_nic_core_fw_alive(scsi_qla_host_t *base_vha)
5760 int rval = QLA_SUCCESS;
5761 unsigned long heart_beat_wait = jiffies + (1 * HZ);
5762 uint32_t heart_beat_counter1, heart_beat_counter2;
5765 if (time_after(jiffies, heart_beat_wait)) {
5766 ql_dbg(ql_dbg_p3p, base_vha, 0xb07c,
5767 "Nic Core f/w is not alive.\n");
5768 rval = QLA_FUNCTION_FAILED;
5772 qla83xx_idc_lock(base_vha, 0);
5773 qla83xx_rd_reg(base_vha, QLA83XX_FW_HEARTBEAT,
5774 &heart_beat_counter1);
5775 qla83xx_idc_unlock(base_vha, 0);
5777 qla83xx_idc_lock(base_vha, 0);
5778 qla83xx_rd_reg(base_vha, QLA83XX_FW_HEARTBEAT,
5779 &heart_beat_counter2);
5780 qla83xx_idc_unlock(base_vha, 0);
5781 } while (heart_beat_counter1 == heart_beat_counter2);
5786 /* Work: Perform NIC Core Reset handling */
5788 qla83xx_nic_core_reset_work(struct work_struct *work)
5790 struct qla_hw_data *ha =
5791 container_of(work, struct qla_hw_data, nic_core_reset);
5792 scsi_qla_host_t *base_vha = pci_get_drvdata(ha->pdev);
5793 uint32_t dev_state = 0;
5795 if (IS_QLA2031(ha)) {
5796 if (qla2xxx_mctp_dump(base_vha) != QLA_SUCCESS)
5797 ql_log(ql_log_warn, base_vha, 0xb081,
5798 "Failed to dump mctp\n");
5802 if (!ha->flags.nic_core_reset_hdlr_active) {
5803 if (qla83xx_check_nic_core_fw_alive(base_vha) == QLA_SUCCESS) {
5804 qla83xx_idc_lock(base_vha, 0);
5805 qla83xx_rd_reg(base_vha, QLA83XX_IDC_DEV_STATE,
5807 qla83xx_idc_unlock(base_vha, 0);
5808 if (dev_state != QLA8XXX_DEV_NEED_RESET) {
5809 ql_dbg(ql_dbg_p3p, base_vha, 0xb07a,
5810 "Nic Core f/w is alive.\n");
5815 ha->flags.nic_core_reset_hdlr_active = 1;
5816 if (qla83xx_nic_core_reset(base_vha)) {
5817 /* NIC Core reset failed. */
5818 ql_dbg(ql_dbg_p3p, base_vha, 0xb061,
5819 "NIC Core reset failed.\n");
5821 ha->flags.nic_core_reset_hdlr_active = 0;
5825 /* Work: Handle 8200 IDC aens */
5827 qla83xx_service_idc_aen(struct work_struct *work)
5829 struct qla_hw_data *ha =
5830 container_of(work, struct qla_hw_data, idc_aen);
5831 scsi_qla_host_t *base_vha = pci_get_drvdata(ha->pdev);
5832 uint32_t dev_state, idc_control;
5834 qla83xx_idc_lock(base_vha, 0);
5835 qla83xx_rd_reg(base_vha, QLA83XX_IDC_DEV_STATE, &dev_state);
5836 qla83xx_rd_reg(base_vha, QLA83XX_IDC_CONTROL, &idc_control);
5837 qla83xx_idc_unlock(base_vha, 0);
5838 if (dev_state == QLA8XXX_DEV_NEED_RESET) {
5839 if (idc_control & QLA83XX_IDC_GRACEFUL_RESET) {
5840 ql_dbg(ql_dbg_p3p, base_vha, 0xb062,
5841 "Application requested NIC Core Reset.\n");
5842 qla83xx_schedule_work(base_vha, QLA83XX_NIC_CORE_RESET);
5843 } else if (qla83xx_check_nic_core_fw_alive(base_vha) ==
5845 ql_dbg(ql_dbg_p3p, base_vha, 0xb07b,
5846 "Other protocol driver requested NIC Core Reset.\n");
5847 qla83xx_schedule_work(base_vha, QLA83XX_NIC_CORE_RESET);
5849 } else if (dev_state == QLA8XXX_DEV_FAILED ||
5850 dev_state == QLA8XXX_DEV_NEED_QUIESCENT) {
5851 qla83xx_schedule_work(base_vha, QLA83XX_IDC_STATE_HANDLER);
5856 * Control the frequency of IDC lock retries
5858 #define QLA83XX_WAIT_LOGIC_MS 100
5861 qla83xx_force_lock_recovery(scsi_qla_host_t *base_vha)
5865 uint32_t idc_lck_rcvry_stage_mask = 0x3;
5866 uint32_t idc_lck_rcvry_owner_mask = 0x3c;
5867 struct qla_hw_data *ha = base_vha->hw;
5869 ql_dbg(ql_dbg_p3p, base_vha, 0xb086,
5870 "Trying force recovery of the IDC lock.\n");
5872 rval = qla83xx_rd_reg(base_vha, QLA83XX_IDC_LOCK_RECOVERY, &data);
5876 if ((data & idc_lck_rcvry_stage_mask) > 0) {
5879 data = (IDC_LOCK_RECOVERY_STAGE1) | (ha->portnum << 2);
5880 rval = qla83xx_wr_reg(base_vha, QLA83XX_IDC_LOCK_RECOVERY,
5887 rval = qla83xx_rd_reg(base_vha, QLA83XX_IDC_LOCK_RECOVERY,
5892 if (((data & idc_lck_rcvry_owner_mask) >> 2) == ha->portnum) {
5893 data &= (IDC_LOCK_RECOVERY_STAGE2 |
5894 ~(idc_lck_rcvry_stage_mask));
5895 rval = qla83xx_wr_reg(base_vha,
5896 QLA83XX_IDC_LOCK_RECOVERY, data);
5900 /* Forcefully perform IDC UnLock */
5901 rval = qla83xx_rd_reg(base_vha, QLA83XX_DRIVER_UNLOCK,
5905 /* Clear lock-id by setting 0xff */
5906 rval = qla83xx_wr_reg(base_vha, QLA83XX_DRIVER_LOCKID,
5910 /* Clear lock-recovery by setting 0x0 */
5911 rval = qla83xx_wr_reg(base_vha,
5912 QLA83XX_IDC_LOCK_RECOVERY, 0x0);
5923 qla83xx_idc_lock_recovery(scsi_qla_host_t *base_vha)
5925 int rval = QLA_SUCCESS;
5926 uint32_t o_drv_lockid, n_drv_lockid;
5927 unsigned long lock_recovery_timeout;
5929 lock_recovery_timeout = jiffies + QLA83XX_MAX_LOCK_RECOVERY_WAIT;
5931 rval = qla83xx_rd_reg(base_vha, QLA83XX_DRIVER_LOCKID, &o_drv_lockid);
5935 /* MAX wait time before forcing IDC Lock recovery = 2 secs */
5936 if (time_after_eq(jiffies, lock_recovery_timeout)) {
5937 if (qla83xx_force_lock_recovery(base_vha) == QLA_SUCCESS)
5940 return QLA_FUNCTION_FAILED;
5943 rval = qla83xx_rd_reg(base_vha, QLA83XX_DRIVER_LOCKID, &n_drv_lockid);
5947 if (o_drv_lockid == n_drv_lockid) {
5948 msleep(QLA83XX_WAIT_LOGIC_MS);
5958 * Context: task, can sleep
5961 qla83xx_idc_lock(scsi_qla_host_t *base_vha, uint16_t requester_id)
5964 uint32_t lock_owner;
5965 struct qla_hw_data *ha = base_vha->hw;
5969 /* IDC-lock implementation using driver-lock/lock-id remote registers */
5971 if (qla83xx_rd_reg(base_vha, QLA83XX_DRIVER_LOCK, &data)
5974 /* Setting lock-id to our function-number */
5975 qla83xx_wr_reg(base_vha, QLA83XX_DRIVER_LOCKID,
5978 qla83xx_rd_reg(base_vha, QLA83XX_DRIVER_LOCKID,
5980 ql_dbg(ql_dbg_p3p, base_vha, 0xb063,
5981 "Failed to acquire IDC lock, acquired by %d, "
5982 "retrying...\n", lock_owner);
5984 /* Retry/Perform IDC-Lock recovery */
5985 if (qla83xx_idc_lock_recovery(base_vha)
5987 msleep(QLA83XX_WAIT_LOGIC_MS);
5990 ql_log(ql_log_warn, base_vha, 0xb075,
5991 "IDC Lock recovery FAILED.\n");
6000 qla25xx_rdp_rsp_reduce_size(struct scsi_qla_host *vha,
6001 struct purex_entry_24xx *purex)
6004 u32 sid = purex->s_id[2] << 16 | purex->s_id[1] << 8 | purex->s_id[0];
6005 struct port_database_24xx *pdb;
6007 /* Domain Controller is always logged-out. */
6008 /* if RDP request is not from Domain Controller: */
6009 if (sid != 0xfffc01)
6012 ql_dbg(ql_dbg_init, vha, 0x0181, "%s: s_id=%#x\n", __func__, sid);
6014 pdb = kzalloc(sizeof(*pdb), GFP_KERNEL);
6016 ql_dbg(ql_dbg_init, vha, 0x0181,
6017 "%s: Failed allocate pdb\n", __func__);
6018 } else if (qla24xx_get_port_database(vha,
6019 le16_to_cpu(purex->nport_handle), pdb)) {
6020 ql_dbg(ql_dbg_init, vha, 0x0181,
6021 "%s: Failed get pdb sid=%x\n", __func__, sid);
6022 } else if (pdb->current_login_state != PDS_PLOGI_COMPLETE &&
6023 pdb->current_login_state != PDS_PRLI_COMPLETE) {
6024 ql_dbg(ql_dbg_init, vha, 0x0181,
6025 "%s: Port not logged in sid=%#x\n", __func__, sid);
6027 /* RDP request is from logged in port */
6033 vha->hw->isp_ops->fw_version_str(vha, fwstr, sizeof(fwstr));
6034 fwstr[strcspn(fwstr, " ")] = 0;
6035 /* if FW version allows RDP response length upto 2048 bytes: */
6036 if (strcmp(fwstr, "8.09.00") > 0 || strcmp(fwstr, "8.05.65") == 0)
6039 ql_dbg(ql_dbg_init, vha, 0x0181, "%s: fw=%s\n", __func__, fwstr);
6041 /* RDP response length is to be reduced to maximum 256 bytes */
6046 * Function Name: qla24xx_process_purex_iocb
6049 * Prepare a RDP response and send to Fabric switch
6052 * vha: SCSI qla host
6053 * purex: RDP request received by HBA
6055 void qla24xx_process_purex_rdp(struct scsi_qla_host *vha,
6056 struct purex_item *item)
6058 struct qla_hw_data *ha = vha->hw;
6059 struct purex_entry_24xx *purex =
6060 (struct purex_entry_24xx *)&item->iocb;
6061 dma_addr_t rsp_els_dma;
6062 dma_addr_t rsp_payload_dma;
6063 dma_addr_t stat_dma;
6065 struct els_entry_24xx *rsp_els = NULL;
6066 struct rdp_rsp_payload *rsp_payload = NULL;
6067 struct link_statistics *stat = NULL;
6068 uint8_t *sfp = NULL;
6069 uint16_t sfp_flags = 0;
6070 uint rsp_payload_length = sizeof(*rsp_payload);
6073 ql_dbg(ql_dbg_init + ql_dbg_verbose, vha, 0x0180,
6074 "%s: Enter\n", __func__);
6076 ql_dbg(ql_dbg_init + ql_dbg_verbose, vha, 0x0181,
6077 "-------- ELS REQ -------\n");
6078 ql_dump_buffer(ql_dbg_init + ql_dbg_verbose, vha, 0x0182,
6079 purex, sizeof(*purex));
6081 if (qla25xx_rdp_rsp_reduce_size(vha, purex)) {
6082 rsp_payload_length =
6083 offsetof(typeof(*rsp_payload), optical_elmt_desc);
6084 ql_dbg(ql_dbg_init, vha, 0x0181,
6085 "Reducing RSP payload length to %u bytes...\n",
6086 rsp_payload_length);
6089 rsp_els = dma_alloc_coherent(&ha->pdev->dev, sizeof(*rsp_els),
6090 &rsp_els_dma, GFP_KERNEL);
6092 ql_log(ql_log_warn, vha, 0x0183,
6093 "Failed allocate dma buffer ELS RSP.\n");
6097 rsp_payload = dma_alloc_coherent(&ha->pdev->dev, sizeof(*rsp_payload),
6098 &rsp_payload_dma, GFP_KERNEL);
6100 ql_log(ql_log_warn, vha, 0x0184,
6101 "Failed allocate dma buffer ELS RSP payload.\n");
6105 sfp = dma_alloc_coherent(&ha->pdev->dev, SFP_RTDI_LEN,
6106 &sfp_dma, GFP_KERNEL);
6108 stat = dma_alloc_coherent(&ha->pdev->dev, sizeof(*stat),
6109 &stat_dma, GFP_KERNEL);
6111 /* Prepare Response IOCB */
6112 rsp_els->entry_type = ELS_IOCB_TYPE;
6113 rsp_els->entry_count = 1;
6114 rsp_els->sys_define = 0;
6115 rsp_els->entry_status = 0;
6116 rsp_els->handle = 0;
6117 rsp_els->nport_handle = purex->nport_handle;
6118 rsp_els->tx_dsd_count = cpu_to_le16(1);
6119 rsp_els->vp_index = purex->vp_idx;
6120 rsp_els->sof_type = EST_SOFI3;
6121 rsp_els->rx_xchg_address = purex->rx_xchg_addr;
6122 rsp_els->rx_dsd_count = 0;
6123 rsp_els->opcode = purex->els_frame_payload[0];
6125 rsp_els->d_id[0] = purex->s_id[0];
6126 rsp_els->d_id[1] = purex->s_id[1];
6127 rsp_els->d_id[2] = purex->s_id[2];
6129 rsp_els->control_flags = cpu_to_le16(EPD_ELS_ACC);
6130 rsp_els->rx_byte_count = 0;
6131 rsp_els->tx_byte_count = cpu_to_le32(rsp_payload_length);
6133 put_unaligned_le64(rsp_payload_dma, &rsp_els->tx_address);
6134 rsp_els->tx_len = rsp_els->tx_byte_count;
6136 rsp_els->rx_address = 0;
6137 rsp_els->rx_len = 0;
6139 /* Prepare Response Payload */
6140 rsp_payload->hdr.cmd = cpu_to_be32(0x2 << 24); /* LS_ACC */
6141 rsp_payload->hdr.len = cpu_to_be32(le32_to_cpu(rsp_els->tx_byte_count) -
6142 sizeof(rsp_payload->hdr));
6144 /* Link service Request Info Descriptor */
6145 rsp_payload->ls_req_info_desc.desc_tag = cpu_to_be32(0x1);
6146 rsp_payload->ls_req_info_desc.desc_len =
6147 cpu_to_be32(RDP_DESC_LEN(rsp_payload->ls_req_info_desc));
6148 rsp_payload->ls_req_info_desc.req_payload_word_0 =
6149 cpu_to_be32p((uint32_t *)purex->els_frame_payload);
6151 /* Link service Request Info Descriptor 2 */
6152 rsp_payload->ls_req_info_desc2.desc_tag = cpu_to_be32(0x1);
6153 rsp_payload->ls_req_info_desc2.desc_len =
6154 cpu_to_be32(RDP_DESC_LEN(rsp_payload->ls_req_info_desc2));
6155 rsp_payload->ls_req_info_desc2.req_payload_word_0 =
6156 cpu_to_be32p((uint32_t *)purex->els_frame_payload);
6159 rsp_payload->sfp_diag_desc.desc_tag = cpu_to_be32(0x10000);
6160 rsp_payload->sfp_diag_desc.desc_len =
6161 cpu_to_be32(RDP_DESC_LEN(rsp_payload->sfp_diag_desc));
6165 memset(sfp, 0, SFP_RTDI_LEN);
6166 rval = qla2x00_read_sfp(vha, sfp_dma, sfp, 0xa0, 0x7, 2, 0);
6168 /* SFP Flags bits 3-0: Port Tx Laser Type */
6169 if (sfp[0] & BIT_2 || sfp[1] & (BIT_6|BIT_5))
6170 sfp_flags |= BIT_0; /* short wave */
6171 else if (sfp[0] & BIT_1)
6172 sfp_flags |= BIT_1; /* long wave 1310nm */
6173 else if (sfp[1] & BIT_4)
6174 sfp_flags |= BIT_1|BIT_0; /* long wave 1550nm */
6178 memset(sfp, 0, SFP_RTDI_LEN);
6179 rval = qla2x00_read_sfp(vha, sfp_dma, sfp, 0xa0, 0x0, 1, 0);
6181 sfp_flags |= BIT_4; /* optical */
6183 sfp_flags |= BIT_6; /* sfp+ */
6186 rsp_payload->sfp_diag_desc.sfp_flags = cpu_to_be16(sfp_flags);
6188 /* SFP Diagnostics */
6189 memset(sfp, 0, SFP_RTDI_LEN);
6190 rval = qla2x00_read_sfp(vha, sfp_dma, sfp, 0xa2, 0x60, 10, 0);
6192 __be16 *trx = (__force __be16 *)sfp; /* already be16 */
6193 rsp_payload->sfp_diag_desc.temperature = trx[0];
6194 rsp_payload->sfp_diag_desc.vcc = trx[1];
6195 rsp_payload->sfp_diag_desc.tx_bias = trx[2];
6196 rsp_payload->sfp_diag_desc.tx_power = trx[3];
6197 rsp_payload->sfp_diag_desc.rx_power = trx[4];
6201 /* Port Speed Descriptor */
6202 rsp_payload->port_speed_desc.desc_tag = cpu_to_be32(0x10001);
6203 rsp_payload->port_speed_desc.desc_len =
6204 cpu_to_be32(RDP_DESC_LEN(rsp_payload->port_speed_desc));
6205 rsp_payload->port_speed_desc.speed_capab = cpu_to_be16(
6206 qla25xx_fdmi_port_speed_capability(ha));
6207 rsp_payload->port_speed_desc.operating_speed = cpu_to_be16(
6208 qla25xx_fdmi_port_speed_currently(ha));
6210 /* Link Error Status Descriptor */
6211 rsp_payload->ls_err_desc.desc_tag = cpu_to_be32(0x10002);
6212 rsp_payload->ls_err_desc.desc_len =
6213 cpu_to_be32(RDP_DESC_LEN(rsp_payload->ls_err_desc));
6216 rval = qla24xx_get_isp_stats(vha, stat, stat_dma, 0);
6218 rsp_payload->ls_err_desc.link_fail_cnt =
6219 cpu_to_be32(le32_to_cpu(stat->link_fail_cnt));
6220 rsp_payload->ls_err_desc.loss_sync_cnt =
6221 cpu_to_be32(le32_to_cpu(stat->loss_sync_cnt));
6222 rsp_payload->ls_err_desc.loss_sig_cnt =
6223 cpu_to_be32(le32_to_cpu(stat->loss_sig_cnt));
6224 rsp_payload->ls_err_desc.prim_seq_err_cnt =
6225 cpu_to_be32(le32_to_cpu(stat->prim_seq_err_cnt));
6226 rsp_payload->ls_err_desc.inval_xmit_word_cnt =
6227 cpu_to_be32(le32_to_cpu(stat->inval_xmit_word_cnt));
6228 rsp_payload->ls_err_desc.inval_crc_cnt =
6229 cpu_to_be32(le32_to_cpu(stat->inval_crc_cnt));
6230 rsp_payload->ls_err_desc.pn_port_phy_type |= BIT_6;
6234 /* Portname Descriptor */
6235 rsp_payload->port_name_diag_desc.desc_tag = cpu_to_be32(0x10003);
6236 rsp_payload->port_name_diag_desc.desc_len =
6237 cpu_to_be32(RDP_DESC_LEN(rsp_payload->port_name_diag_desc));
6238 memcpy(rsp_payload->port_name_diag_desc.WWNN,
6240 sizeof(rsp_payload->port_name_diag_desc.WWNN));
6241 memcpy(rsp_payload->port_name_diag_desc.WWPN,
6243 sizeof(rsp_payload->port_name_diag_desc.WWPN));
6245 /* F-Port Portname Descriptor */
6246 rsp_payload->port_name_direct_desc.desc_tag = cpu_to_be32(0x10003);
6247 rsp_payload->port_name_direct_desc.desc_len =
6248 cpu_to_be32(RDP_DESC_LEN(rsp_payload->port_name_direct_desc));
6249 memcpy(rsp_payload->port_name_direct_desc.WWNN,
6250 vha->fabric_node_name,
6251 sizeof(rsp_payload->port_name_direct_desc.WWNN));
6252 memcpy(rsp_payload->port_name_direct_desc.WWPN,
6253 vha->fabric_port_name,
6254 sizeof(rsp_payload->port_name_direct_desc.WWPN));
6256 /* Bufer Credit Descriptor */
6257 rsp_payload->buffer_credit_desc.desc_tag = cpu_to_be32(0x10006);
6258 rsp_payload->buffer_credit_desc.desc_len =
6259 cpu_to_be32(RDP_DESC_LEN(rsp_payload->buffer_credit_desc));
6260 rsp_payload->buffer_credit_desc.fcport_b2b = 0;
6261 rsp_payload->buffer_credit_desc.attached_fcport_b2b = cpu_to_be32(0);
6262 rsp_payload->buffer_credit_desc.fcport_rtt = cpu_to_be32(0);
6264 if (ha->flags.plogi_template_valid) {
6266 be16_to_cpu(ha->plogi_els_payld.fl_csp.sp_bb_cred);
6267 rsp_payload->buffer_credit_desc.fcport_b2b = cpu_to_be32(tmp);
6270 if (rsp_payload_length < sizeof(*rsp_payload))
6273 /* Optical Element Descriptor, Temperature */
6274 rsp_payload->optical_elmt_desc[0].desc_tag = cpu_to_be32(0x10007);
6275 rsp_payload->optical_elmt_desc[0].desc_len =
6276 cpu_to_be32(RDP_DESC_LEN(*rsp_payload->optical_elmt_desc));
6277 /* Optical Element Descriptor, Voltage */
6278 rsp_payload->optical_elmt_desc[1].desc_tag = cpu_to_be32(0x10007);
6279 rsp_payload->optical_elmt_desc[1].desc_len =
6280 cpu_to_be32(RDP_DESC_LEN(*rsp_payload->optical_elmt_desc));
6281 /* Optical Element Descriptor, Tx Bias Current */
6282 rsp_payload->optical_elmt_desc[2].desc_tag = cpu_to_be32(0x10007);
6283 rsp_payload->optical_elmt_desc[2].desc_len =
6284 cpu_to_be32(RDP_DESC_LEN(*rsp_payload->optical_elmt_desc));
6285 /* Optical Element Descriptor, Tx Power */
6286 rsp_payload->optical_elmt_desc[3].desc_tag = cpu_to_be32(0x10007);
6287 rsp_payload->optical_elmt_desc[3].desc_len =
6288 cpu_to_be32(RDP_DESC_LEN(*rsp_payload->optical_elmt_desc));
6289 /* Optical Element Descriptor, Rx Power */
6290 rsp_payload->optical_elmt_desc[4].desc_tag = cpu_to_be32(0x10007);
6291 rsp_payload->optical_elmt_desc[4].desc_len =
6292 cpu_to_be32(RDP_DESC_LEN(*rsp_payload->optical_elmt_desc));
6295 memset(sfp, 0, SFP_RTDI_LEN);
6296 rval = qla2x00_read_sfp(vha, sfp_dma, sfp, 0xa2, 0, 64, 0);
6298 __be16 *trx = (__force __be16 *)sfp; /* already be16 */
6300 /* Optical Element Descriptor, Temperature */
6301 rsp_payload->optical_elmt_desc[0].high_alarm = trx[0];
6302 rsp_payload->optical_elmt_desc[0].low_alarm = trx[1];
6303 rsp_payload->optical_elmt_desc[0].high_warn = trx[2];
6304 rsp_payload->optical_elmt_desc[0].low_warn = trx[3];
6305 rsp_payload->optical_elmt_desc[0].element_flags =
6306 cpu_to_be32(1 << 28);
6308 /* Optical Element Descriptor, Voltage */
6309 rsp_payload->optical_elmt_desc[1].high_alarm = trx[4];
6310 rsp_payload->optical_elmt_desc[1].low_alarm = trx[5];
6311 rsp_payload->optical_elmt_desc[1].high_warn = trx[6];
6312 rsp_payload->optical_elmt_desc[1].low_warn = trx[7];
6313 rsp_payload->optical_elmt_desc[1].element_flags =
6314 cpu_to_be32(2 << 28);
6316 /* Optical Element Descriptor, Tx Bias Current */
6317 rsp_payload->optical_elmt_desc[2].high_alarm = trx[8];
6318 rsp_payload->optical_elmt_desc[2].low_alarm = trx[9];
6319 rsp_payload->optical_elmt_desc[2].high_warn = trx[10];
6320 rsp_payload->optical_elmt_desc[2].low_warn = trx[11];
6321 rsp_payload->optical_elmt_desc[2].element_flags =
6322 cpu_to_be32(3 << 28);
6324 /* Optical Element Descriptor, Tx Power */
6325 rsp_payload->optical_elmt_desc[3].high_alarm = trx[12];
6326 rsp_payload->optical_elmt_desc[3].low_alarm = trx[13];
6327 rsp_payload->optical_elmt_desc[3].high_warn = trx[14];
6328 rsp_payload->optical_elmt_desc[3].low_warn = trx[15];
6329 rsp_payload->optical_elmt_desc[3].element_flags =
6330 cpu_to_be32(4 << 28);
6332 /* Optical Element Descriptor, Rx Power */
6333 rsp_payload->optical_elmt_desc[4].high_alarm = trx[16];
6334 rsp_payload->optical_elmt_desc[4].low_alarm = trx[17];
6335 rsp_payload->optical_elmt_desc[4].high_warn = trx[18];
6336 rsp_payload->optical_elmt_desc[4].low_warn = trx[19];
6337 rsp_payload->optical_elmt_desc[4].element_flags =
6338 cpu_to_be32(5 << 28);
6341 memset(sfp, 0, SFP_RTDI_LEN);
6342 rval = qla2x00_read_sfp(vha, sfp_dma, sfp, 0xa2, 112, 64, 0);
6344 /* Temperature high/low alarm/warning */
6345 rsp_payload->optical_elmt_desc[0].element_flags |=
6347 (sfp[0] >> 7 & 1) << 3 |
6348 (sfp[0] >> 6 & 1) << 2 |
6349 (sfp[4] >> 7 & 1) << 1 |
6350 (sfp[4] >> 6 & 1) << 0);
6352 /* Voltage high/low alarm/warning */
6353 rsp_payload->optical_elmt_desc[1].element_flags |=
6355 (sfp[0] >> 5 & 1) << 3 |
6356 (sfp[0] >> 4 & 1) << 2 |
6357 (sfp[4] >> 5 & 1) << 1 |
6358 (sfp[4] >> 4 & 1) << 0);
6360 /* Tx Bias Current high/low alarm/warning */
6361 rsp_payload->optical_elmt_desc[2].element_flags |=
6363 (sfp[0] >> 3 & 1) << 3 |
6364 (sfp[0] >> 2 & 1) << 2 |
6365 (sfp[4] >> 3 & 1) << 1 |
6366 (sfp[4] >> 2 & 1) << 0);
6368 /* Tx Power high/low alarm/warning */
6369 rsp_payload->optical_elmt_desc[3].element_flags |=
6371 (sfp[0] >> 1 & 1) << 3 |
6372 (sfp[0] >> 0 & 1) << 2 |
6373 (sfp[4] >> 1 & 1) << 1 |
6374 (sfp[4] >> 0 & 1) << 0);
6376 /* Rx Power high/low alarm/warning */
6377 rsp_payload->optical_elmt_desc[4].element_flags |=
6379 (sfp[1] >> 7 & 1) << 3 |
6380 (sfp[1] >> 6 & 1) << 2 |
6381 (sfp[5] >> 7 & 1) << 1 |
6382 (sfp[5] >> 6 & 1) << 0);
6386 /* Optical Product Data Descriptor */
6387 rsp_payload->optical_prod_desc.desc_tag = cpu_to_be32(0x10008);
6388 rsp_payload->optical_prod_desc.desc_len =
6389 cpu_to_be32(RDP_DESC_LEN(rsp_payload->optical_prod_desc));
6392 memset(sfp, 0, SFP_RTDI_LEN);
6393 rval = qla2x00_read_sfp(vha, sfp_dma, sfp, 0xa0, 20, 64, 0);
6395 memcpy(rsp_payload->optical_prod_desc.vendor_name,
6397 sizeof(rsp_payload->optical_prod_desc.vendor_name));
6398 memcpy(rsp_payload->optical_prod_desc.part_number,
6400 sizeof(rsp_payload->optical_prod_desc.part_number));
6401 memcpy(rsp_payload->optical_prod_desc.revision,
6403 sizeof(rsp_payload->optical_prod_desc.revision));
6404 memcpy(rsp_payload->optical_prod_desc.serial_number,
6406 sizeof(rsp_payload->optical_prod_desc.serial_number));
6409 memset(sfp, 0, SFP_RTDI_LEN);
6410 rval = qla2x00_read_sfp(vha, sfp_dma, sfp, 0xa0, 84, 8, 0);
6412 memcpy(rsp_payload->optical_prod_desc.date,
6414 sizeof(rsp_payload->optical_prod_desc.date));
6419 ql_dbg(ql_dbg_init, vha, 0x0183,
6420 "Sending ELS Response to RDP Request...\n");
6421 ql_dbg(ql_dbg_init + ql_dbg_verbose, vha, 0x0184,
6422 "-------- ELS RSP -------\n");
6423 ql_dump_buffer(ql_dbg_init + ql_dbg_verbose, vha, 0x0185,
6424 rsp_els, sizeof(*rsp_els));
6425 ql_dbg(ql_dbg_init + ql_dbg_verbose, vha, 0x0186,
6426 "-------- ELS RSP PAYLOAD -------\n");
6427 ql_dump_buffer(ql_dbg_init + ql_dbg_verbose, vha, 0x0187,
6428 rsp_payload, rsp_payload_length);
6430 rval = qla2x00_issue_iocb(vha, rsp_els, rsp_els_dma, 0);
6433 ql_log(ql_log_warn, vha, 0x0188,
6434 "%s: iocb failed to execute -> %x\n", __func__, rval);
6435 } else if (rsp_els->comp_status) {
6436 ql_log(ql_log_warn, vha, 0x0189,
6437 "%s: iocb failed to complete -> completion=%#x subcode=(%#x,%#x)\n",
6438 __func__, rsp_els->comp_status,
6439 rsp_els->error_subcode_1, rsp_els->error_subcode_2);
6441 ql_dbg(ql_dbg_init, vha, 0x018a, "%s: done.\n", __func__);
6446 dma_free_coherent(&ha->pdev->dev, sizeof(*stat),
6449 dma_free_coherent(&ha->pdev->dev, SFP_RTDI_LEN,
6452 dma_free_coherent(&ha->pdev->dev, sizeof(*rsp_payload),
6453 rsp_payload, rsp_payload_dma);
6455 dma_free_coherent(&ha->pdev->dev, sizeof(*rsp_els),
6456 rsp_els, rsp_els_dma);
6460 qla24xx_free_purex_item(struct purex_item *item)
6462 if (item == &item->vha->default_item)
6463 memset(&item->vha->default_item, 0, sizeof(struct purex_item));
6468 void qla24xx_process_purex_list(struct purex_list *list)
6470 struct list_head head = LIST_HEAD_INIT(head);
6471 struct purex_item *item, *next;
6474 spin_lock_irqsave(&list->lock, flags);
6475 list_splice_init(&list->head, &head);
6476 spin_unlock_irqrestore(&list->lock, flags);
6478 list_for_each_entry_safe(item, next, &head, list) {
6479 list_del(&item->list);
6480 item->process_item(item->vha, item);
6481 qla24xx_free_purex_item(item);
6486 * Context: task, can sleep
6489 qla83xx_idc_unlock(scsi_qla_host_t *base_vha, uint16_t requester_id)
6492 uint16_t options = (requester_id << 15) | BIT_7;
6496 struct qla_hw_data *ha = base_vha->hw;
6500 /* IDC-unlock implementation using driver-unlock/lock-id
6505 if (qla83xx_rd_reg(base_vha, QLA83XX_DRIVER_LOCKID, &data)
6507 if (data == ha->portnum) {
6508 qla83xx_rd_reg(base_vha, QLA83XX_DRIVER_UNLOCK, &data);
6509 /* Clearing lock-id by setting 0xff */
6510 qla83xx_wr_reg(base_vha, QLA83XX_DRIVER_LOCKID, 0xff);
6511 } else if (retry < 10) {
6512 /* SV: XXX: IDC unlock retrying needed here? */
6514 /* Retry for IDC-unlock */
6515 msleep(QLA83XX_WAIT_LOGIC_MS);
6517 ql_dbg(ql_dbg_p3p, base_vha, 0xb064,
6518 "Failed to release IDC lock, retrying=%d\n", retry);
6521 } else if (retry < 10) {
6522 /* Retry for IDC-unlock */
6523 msleep(QLA83XX_WAIT_LOGIC_MS);
6525 ql_dbg(ql_dbg_p3p, base_vha, 0xb065,
6526 "Failed to read drv-lockid, retrying=%d\n", retry);
6533 /* XXX: IDC-unlock implementation using access-control mbx */
6536 if (qla83xx_access_control(base_vha, options, 0, 0, NULL)) {
6538 /* Retry for IDC-unlock */
6539 msleep(QLA83XX_WAIT_LOGIC_MS);
6541 ql_dbg(ql_dbg_p3p, base_vha, 0xb066,
6542 "Failed to release IDC lock, retrying=%d\n", retry);
6552 __qla83xx_set_drv_presence(scsi_qla_host_t *vha)
6554 int rval = QLA_SUCCESS;
6555 struct qla_hw_data *ha = vha->hw;
6556 uint32_t drv_presence;
6558 rval = qla83xx_rd_reg(vha, QLA83XX_IDC_DRV_PRESENCE, &drv_presence);
6559 if (rval == QLA_SUCCESS) {
6560 drv_presence |= (1 << ha->portnum);
6561 rval = qla83xx_wr_reg(vha, QLA83XX_IDC_DRV_PRESENCE,
6569 qla83xx_set_drv_presence(scsi_qla_host_t *vha)
6571 int rval = QLA_SUCCESS;
6573 qla83xx_idc_lock(vha, 0);
6574 rval = __qla83xx_set_drv_presence(vha);
6575 qla83xx_idc_unlock(vha, 0);
6581 __qla83xx_clear_drv_presence(scsi_qla_host_t *vha)
6583 int rval = QLA_SUCCESS;
6584 struct qla_hw_data *ha = vha->hw;
6585 uint32_t drv_presence;
6587 rval = qla83xx_rd_reg(vha, QLA83XX_IDC_DRV_PRESENCE, &drv_presence);
6588 if (rval == QLA_SUCCESS) {
6589 drv_presence &= ~(1 << ha->portnum);
6590 rval = qla83xx_wr_reg(vha, QLA83XX_IDC_DRV_PRESENCE,
6598 qla83xx_clear_drv_presence(scsi_qla_host_t *vha)
6600 int rval = QLA_SUCCESS;
6602 qla83xx_idc_lock(vha, 0);
6603 rval = __qla83xx_clear_drv_presence(vha);
6604 qla83xx_idc_unlock(vha, 0);
6610 qla83xx_need_reset_handler(scsi_qla_host_t *vha)
6612 struct qla_hw_data *ha = vha->hw;
6613 uint32_t drv_ack, drv_presence;
6614 unsigned long ack_timeout;
6616 /* Wait for IDC ACK from all functions (DRV-ACK == DRV-PRESENCE) */
6617 ack_timeout = jiffies + (ha->fcoe_reset_timeout * HZ);
6619 qla83xx_rd_reg(vha, QLA83XX_IDC_DRIVER_ACK, &drv_ack);
6620 qla83xx_rd_reg(vha, QLA83XX_IDC_DRV_PRESENCE, &drv_presence);
6621 if ((drv_ack & drv_presence) == drv_presence)
6624 if (time_after_eq(jiffies, ack_timeout)) {
6625 ql_log(ql_log_warn, vha, 0xb067,
6626 "RESET ACK TIMEOUT! drv_presence=0x%x "
6627 "drv_ack=0x%x\n", drv_presence, drv_ack);
6629 * The function(s) which did not ack in time are forced
6630 * to withdraw any further participation in the IDC
6633 if (drv_ack != drv_presence)
6634 qla83xx_wr_reg(vha, QLA83XX_IDC_DRV_PRESENCE,
6639 qla83xx_idc_unlock(vha, 0);
6641 qla83xx_idc_lock(vha, 0);
6644 qla83xx_wr_reg(vha, QLA83XX_IDC_DEV_STATE, QLA8XXX_DEV_COLD);
6645 ql_log(ql_log_info, vha, 0xb068, "HW State: COLD/RE-INIT.\n");
6649 qla83xx_device_bootstrap(scsi_qla_host_t *vha)
6651 int rval = QLA_SUCCESS;
6652 uint32_t idc_control;
6654 qla83xx_wr_reg(vha, QLA83XX_IDC_DEV_STATE, QLA8XXX_DEV_INITIALIZING);
6655 ql_log(ql_log_info, vha, 0xb069, "HW State: INITIALIZING.\n");
6657 /* Clearing IDC-Control Graceful-Reset Bit before resetting f/w */
6658 __qla83xx_get_idc_control(vha, &idc_control);
6659 idc_control &= ~QLA83XX_IDC_GRACEFUL_RESET;
6660 __qla83xx_set_idc_control(vha, 0);
6662 qla83xx_idc_unlock(vha, 0);
6663 rval = qla83xx_restart_nic_firmware(vha);
6664 qla83xx_idc_lock(vha, 0);
6666 if (rval != QLA_SUCCESS) {
6667 ql_log(ql_log_fatal, vha, 0xb06a,
6668 "Failed to restart NIC f/w.\n");
6669 qla83xx_wr_reg(vha, QLA83XX_IDC_DEV_STATE, QLA8XXX_DEV_FAILED);
6670 ql_log(ql_log_info, vha, 0xb06b, "HW State: FAILED.\n");
6672 ql_dbg(ql_dbg_p3p, vha, 0xb06c,
6673 "Success in restarting nic f/w.\n");
6674 qla83xx_wr_reg(vha, QLA83XX_IDC_DEV_STATE, QLA8XXX_DEV_READY);
6675 ql_log(ql_log_info, vha, 0xb06d, "HW State: READY.\n");
6681 /* Assumes idc_lock always held on entry */
6683 qla83xx_idc_state_handler(scsi_qla_host_t *base_vha)
6685 struct qla_hw_data *ha = base_vha->hw;
6686 int rval = QLA_SUCCESS;
6687 unsigned long dev_init_timeout;
6690 /* Wait for MAX-INIT-TIMEOUT for the device to go ready */
6691 dev_init_timeout = jiffies + (ha->fcoe_dev_init_timeout * HZ);
6695 if (time_after_eq(jiffies, dev_init_timeout)) {
6696 ql_log(ql_log_warn, base_vha, 0xb06e,
6697 "Initialization TIMEOUT!\n");
6698 /* Init timeout. Disable further NIC Core
6701 qla83xx_wr_reg(base_vha, QLA83XX_IDC_DEV_STATE,
6702 QLA8XXX_DEV_FAILED);
6703 ql_log(ql_log_info, base_vha, 0xb06f,
6704 "HW State: FAILED.\n");
6707 qla83xx_rd_reg(base_vha, QLA83XX_IDC_DEV_STATE, &dev_state);
6708 switch (dev_state) {
6709 case QLA8XXX_DEV_READY:
6710 if (ha->flags.nic_core_reset_owner)
6711 qla83xx_idc_audit(base_vha,
6712 IDC_AUDIT_COMPLETION);
6713 ha->flags.nic_core_reset_owner = 0;
6714 ql_dbg(ql_dbg_p3p, base_vha, 0xb070,
6715 "Reset_owner reset by 0x%x.\n",
6718 case QLA8XXX_DEV_COLD:
6719 if (ha->flags.nic_core_reset_owner)
6720 rval = qla83xx_device_bootstrap(base_vha);
6722 /* Wait for AEN to change device-state */
6723 qla83xx_idc_unlock(base_vha, 0);
6725 qla83xx_idc_lock(base_vha, 0);
6728 case QLA8XXX_DEV_INITIALIZING:
6729 /* Wait for AEN to change device-state */
6730 qla83xx_idc_unlock(base_vha, 0);
6732 qla83xx_idc_lock(base_vha, 0);
6734 case QLA8XXX_DEV_NEED_RESET:
6735 if (!ql2xdontresethba && ha->flags.nic_core_reset_owner)
6736 qla83xx_need_reset_handler(base_vha);
6738 /* Wait for AEN to change device-state */
6739 qla83xx_idc_unlock(base_vha, 0);
6741 qla83xx_idc_lock(base_vha, 0);
6743 /* reset timeout value after need reset handler */
6744 dev_init_timeout = jiffies +
6745 (ha->fcoe_dev_init_timeout * HZ);
6747 case QLA8XXX_DEV_NEED_QUIESCENT:
6748 /* XXX: DEBUG for now */
6749 qla83xx_idc_unlock(base_vha, 0);
6751 qla83xx_idc_lock(base_vha, 0);
6753 case QLA8XXX_DEV_QUIESCENT:
6754 /* XXX: DEBUG for now */
6755 if (ha->flags.quiesce_owner)
6758 qla83xx_idc_unlock(base_vha, 0);
6760 qla83xx_idc_lock(base_vha, 0);
6761 dev_init_timeout = jiffies +
6762 (ha->fcoe_dev_init_timeout * HZ);
6764 case QLA8XXX_DEV_FAILED:
6765 if (ha->flags.nic_core_reset_owner)
6766 qla83xx_idc_audit(base_vha,
6767 IDC_AUDIT_COMPLETION);
6768 ha->flags.nic_core_reset_owner = 0;
6769 __qla83xx_clear_drv_presence(base_vha);
6770 qla83xx_idc_unlock(base_vha, 0);
6771 qla8xxx_dev_failed_handler(base_vha);
6772 rval = QLA_FUNCTION_FAILED;
6773 qla83xx_idc_lock(base_vha, 0);
6775 case QLA8XXX_BAD_VALUE:
6776 qla83xx_idc_unlock(base_vha, 0);
6778 qla83xx_idc_lock(base_vha, 0);
6781 ql_log(ql_log_warn, base_vha, 0xb071,
6782 "Unknown Device State: %x.\n", dev_state);
6783 qla83xx_idc_unlock(base_vha, 0);
6784 qla8xxx_dev_failed_handler(base_vha);
6785 rval = QLA_FUNCTION_FAILED;
6786 qla83xx_idc_lock(base_vha, 0);
6796 qla2x00_disable_board_on_pci_error(struct work_struct *work)
6798 struct qla_hw_data *ha = container_of(work, struct qla_hw_data,
6800 struct pci_dev *pdev = ha->pdev;
6801 scsi_qla_host_t *base_vha = pci_get_drvdata(ha->pdev);
6803 ql_log(ql_log_warn, base_vha, 0x015b,
6804 "Disabling adapter.\n");
6806 if (!atomic_read(&pdev->enable_cnt)) {
6807 ql_log(ql_log_info, base_vha, 0xfffc,
6808 "PCI device disabled, no action req for PCI error=%lx\n",
6809 base_vha->pci_flags);
6814 * if UNLOADING flag is already set, then continue unload,
6815 * where it was set first.
6817 if (test_and_set_bit(UNLOADING, &base_vha->dpc_flags))
6820 qla2x00_wait_for_sess_deletion(base_vha);
6822 qla2x00_delete_all_vps(ha, base_vha);
6824 qla2x00_abort_all_cmds(base_vha, DID_NO_CONNECT << 16);
6826 qla2x00_dfs_remove(base_vha);
6828 qla84xx_put_chip(base_vha);
6830 if (base_vha->timer_active)
6831 qla2x00_stop_timer(base_vha);
6833 base_vha->flags.online = 0;
6835 qla2x00_destroy_deferred_work(ha);
6838 * Do not try to stop beacon blink as it will issue a mailbox
6841 qla2x00_free_sysfs_attr(base_vha, false);
6843 fc_remove_host(base_vha->host);
6845 scsi_remove_host(base_vha->host);
6847 base_vha->flags.init_done = 0;
6848 qla25xx_delete_queues(base_vha);
6849 qla2x00_free_fcports(base_vha);
6850 qla2x00_free_irqs(base_vha);
6851 qla2x00_mem_free(ha);
6852 qla82xx_md_free(base_vha);
6853 qla2x00_free_queues(ha);
6855 qla2x00_unmap_iobases(ha);
6857 pci_release_selected_regions(ha->pdev, ha->bars);
6858 pci_disable_device(pdev);
6861 * Let qla2x00_remove_one cleanup qla_hw_data on device removal.
6865 /**************************************************************************
6867 * This kernel thread is a task that is schedule by the interrupt handler
6868 * to perform the background processing for interrupts.
6871 * This task always run in the context of a kernel thread. It
6872 * is kick-off by the driver's detect code and starts up
6873 * up one per adapter. It immediately goes to sleep and waits for
6874 * some fibre event. When either the interrupt handler or
6875 * the timer routine detects a event it will one of the task
6876 * bits then wake us up.
6877 **************************************************************************/
6879 qla2x00_do_dpc(void *data)
6881 scsi_qla_host_t *base_vha;
6882 struct qla_hw_data *ha;
6884 struct qla_qpair *qpair;
6886 ha = (struct qla_hw_data *)data;
6887 base_vha = pci_get_drvdata(ha->pdev);
6889 set_user_nice(current, MIN_NICE);
6891 set_current_state(TASK_INTERRUPTIBLE);
6893 ql_dbg(ql_dbg_dpc, base_vha, 0x4000,
6894 "DPC handler sleeping.\n");
6898 if (kthread_should_stop())
6901 if (test_and_clear_bit(DO_EEH_RECOVERY, &base_vha->dpc_flags))
6902 qla_pci_set_eeh_busy(base_vha);
6904 if (!base_vha->flags.init_done || ha->flags.mbox_busy)
6907 if (ha->flags.eeh_busy) {
6908 ql_dbg(ql_dbg_dpc, base_vha, 0x4003,
6909 "eeh_busy=%d.\n", ha->flags.eeh_busy);
6913 if (test_bit(UNLOADING, &base_vha->dpc_flags))
6914 /* don't do any work. Wait to be terminated by kthread_stop */
6919 ql_dbg(ql_dbg_dpc + ql_dbg_verbose, base_vha, 0x4001,
6920 "DPC handler waking up, dpc_flags=0x%lx.\n",
6921 base_vha->dpc_flags);
6923 if (IS_P3P_TYPE(ha)) {
6924 if (IS_QLA8044(ha)) {
6925 if (test_and_clear_bit(ISP_UNRECOVERABLE,
6926 &base_vha->dpc_flags)) {
6927 qla8044_idc_lock(ha);
6928 qla8044_wr_direct(base_vha,
6929 QLA8044_CRB_DEV_STATE_INDEX,
6930 QLA8XXX_DEV_FAILED);
6931 qla8044_idc_unlock(ha);
6932 ql_log(ql_log_info, base_vha, 0x4004,
6933 "HW State: FAILED.\n");
6934 qla8044_device_state_handler(base_vha);
6939 if (test_and_clear_bit(ISP_UNRECOVERABLE,
6940 &base_vha->dpc_flags)) {
6941 qla82xx_idc_lock(ha);
6942 qla82xx_wr_32(ha, QLA82XX_CRB_DEV_STATE,
6943 QLA8XXX_DEV_FAILED);
6944 qla82xx_idc_unlock(ha);
6945 ql_log(ql_log_info, base_vha, 0x0151,
6946 "HW State: FAILED.\n");
6947 qla82xx_device_state_handler(base_vha);
6952 if (test_and_clear_bit(FCOE_CTX_RESET_NEEDED,
6953 &base_vha->dpc_flags)) {
6955 ql_dbg(ql_dbg_dpc, base_vha, 0x4005,
6956 "FCoE context reset scheduled.\n");
6957 if (!(test_and_set_bit(ABORT_ISP_ACTIVE,
6958 &base_vha->dpc_flags))) {
6959 if (qla82xx_fcoe_ctx_reset(base_vha)) {
6960 /* FCoE-ctx reset failed.
6961 * Escalate to chip-reset
6963 set_bit(ISP_ABORT_NEEDED,
6964 &base_vha->dpc_flags);
6966 clear_bit(ABORT_ISP_ACTIVE,
6967 &base_vha->dpc_flags);
6970 ql_dbg(ql_dbg_dpc, base_vha, 0x4006,
6971 "FCoE context reset end.\n");
6973 } else if (IS_QLAFX00(ha)) {
6974 if (test_and_clear_bit(ISP_UNRECOVERABLE,
6975 &base_vha->dpc_flags)) {
6976 ql_dbg(ql_dbg_dpc, base_vha, 0x4020,
6977 "Firmware Reset Recovery\n");
6978 if (qlafx00_reset_initialize(base_vha)) {
6979 /* Failed. Abort isp later. */
6980 if (!test_bit(UNLOADING,
6981 &base_vha->dpc_flags)) {
6982 set_bit(ISP_UNRECOVERABLE,
6983 &base_vha->dpc_flags);
6984 ql_dbg(ql_dbg_dpc, base_vha,
6986 "Reset Recovery Failed\n");
6991 if (test_and_clear_bit(FX00_TARGET_SCAN,
6992 &base_vha->dpc_flags)) {
6993 ql_dbg(ql_dbg_dpc, base_vha, 0x4022,
6994 "ISPFx00 Target Scan scheduled\n");
6995 if (qlafx00_rescan_isp(base_vha)) {
6996 if (!test_bit(UNLOADING,
6997 &base_vha->dpc_flags))
6998 set_bit(ISP_UNRECOVERABLE,
6999 &base_vha->dpc_flags);
7000 ql_dbg(ql_dbg_dpc, base_vha, 0x401e,
7001 "ISPFx00 Target Scan Failed\n");
7003 ql_dbg(ql_dbg_dpc, base_vha, 0x401f,
7004 "ISPFx00 Target Scan End\n");
7006 if (test_and_clear_bit(FX00_HOST_INFO_RESEND,
7007 &base_vha->dpc_flags)) {
7008 ql_dbg(ql_dbg_dpc, base_vha, 0x4023,
7009 "ISPFx00 Host Info resend scheduled\n");
7010 qlafx00_fx_disc(base_vha,
7011 &base_vha->hw->mr.fcport,
7012 FXDISC_REG_HOST_INFO);
7016 if (test_and_clear_bit(DETECT_SFP_CHANGE,
7017 &base_vha->dpc_flags)) {
7019 * - NO-OP -- await next ISP-ABORT. Preferred method
7020 * to minimize disruptions that will occur
7021 * when a forced chip-reset occurs.
7022 * - Force -- ISP-ABORT scheduled.
7024 /* set_bit(ISP_ABORT_NEEDED, &base_vha->dpc_flags); */
7027 if (test_and_clear_bit
7028 (ISP_ABORT_NEEDED, &base_vha->dpc_flags) &&
7029 !test_bit(UNLOADING, &base_vha->dpc_flags)) {
7030 bool do_reset = true;
7032 switch (base_vha->qlini_mode) {
7033 case QLA2XXX_INI_MODE_ENABLED:
7035 case QLA2XXX_INI_MODE_DISABLED:
7036 if (!qla_tgt_mode_enabled(base_vha) &&
7037 !ha->flags.fw_started)
7040 case QLA2XXX_INI_MODE_DUAL:
7041 if (!qla_dual_mode_enabled(base_vha) &&
7042 !ha->flags.fw_started)
7049 if (do_reset && !(test_and_set_bit(ABORT_ISP_ACTIVE,
7050 &base_vha->dpc_flags))) {
7051 base_vha->flags.online = 1;
7052 ql_dbg(ql_dbg_dpc, base_vha, 0x4007,
7053 "ISP abort scheduled.\n");
7054 if (ha->isp_ops->abort_isp(base_vha)) {
7055 /* failed. retry later */
7056 set_bit(ISP_ABORT_NEEDED,
7057 &base_vha->dpc_flags);
7059 clear_bit(ABORT_ISP_ACTIVE,
7060 &base_vha->dpc_flags);
7061 ql_dbg(ql_dbg_dpc, base_vha, 0x4008,
7062 "ISP abort end.\n");
7066 if (test_bit(PROCESS_PUREX_IOCB, &base_vha->dpc_flags)) {
7067 if (atomic_read(&base_vha->loop_state) == LOOP_READY) {
7068 qla24xx_process_purex_list
7069 (&base_vha->purex_list);
7070 clear_bit(PROCESS_PUREX_IOCB,
7071 &base_vha->dpc_flags);
7076 goto loop_resync_check;
7078 if (test_bit(ISP_QUIESCE_NEEDED, &base_vha->dpc_flags)) {
7079 ql_dbg(ql_dbg_dpc, base_vha, 0x4009,
7080 "Quiescence mode scheduled.\n");
7081 if (IS_P3P_TYPE(ha)) {
7083 qla82xx_device_state_handler(base_vha);
7085 qla8044_device_state_handler(base_vha);
7086 clear_bit(ISP_QUIESCE_NEEDED,
7087 &base_vha->dpc_flags);
7088 if (!ha->flags.quiesce_owner) {
7089 qla2x00_perform_loop_resync(base_vha);
7090 if (IS_QLA82XX(ha)) {
7091 qla82xx_idc_lock(ha);
7092 qla82xx_clear_qsnt_ready(
7094 qla82xx_idc_unlock(ha);
7095 } else if (IS_QLA8044(ha)) {
7096 qla8044_idc_lock(ha);
7097 qla8044_clear_qsnt_ready(
7099 qla8044_idc_unlock(ha);
7103 clear_bit(ISP_QUIESCE_NEEDED,
7104 &base_vha->dpc_flags);
7105 qla2x00_quiesce_io(base_vha);
7107 ql_dbg(ql_dbg_dpc, base_vha, 0x400a,
7108 "Quiescence mode end.\n");
7111 if (test_and_clear_bit(RESET_MARKER_NEEDED,
7112 &base_vha->dpc_flags) &&
7113 (!(test_and_set_bit(RESET_ACTIVE, &base_vha->dpc_flags)))) {
7115 ql_dbg(ql_dbg_dpc, base_vha, 0x400b,
7116 "Reset marker scheduled.\n");
7117 qla2x00_rst_aen(base_vha);
7118 clear_bit(RESET_ACTIVE, &base_vha->dpc_flags);
7119 ql_dbg(ql_dbg_dpc, base_vha, 0x400c,
7120 "Reset marker end.\n");
7123 /* Retry each device up to login retry count */
7124 if (test_bit(RELOGIN_NEEDED, &base_vha->dpc_flags) &&
7125 !test_bit(LOOP_RESYNC_NEEDED, &base_vha->dpc_flags) &&
7126 atomic_read(&base_vha->loop_state) != LOOP_DOWN) {
7128 if (!base_vha->relogin_jif ||
7129 time_after_eq(jiffies, base_vha->relogin_jif)) {
7130 base_vha->relogin_jif = jiffies + HZ;
7131 clear_bit(RELOGIN_NEEDED, &base_vha->dpc_flags);
7133 ql_dbg(ql_dbg_disc, base_vha, 0x400d,
7134 "Relogin scheduled.\n");
7135 qla24xx_post_relogin_work(base_vha);
7139 if (!qla2x00_reset_active(base_vha) &&
7140 test_and_clear_bit(LOOP_RESYNC_NEEDED,
7141 &base_vha->dpc_flags)) {
7143 * Allow abort_isp to complete before moving on to scanning.
7145 ql_dbg(ql_dbg_dpc, base_vha, 0x400f,
7146 "Loop resync scheduled.\n");
7148 if (!(test_and_set_bit(LOOP_RESYNC_ACTIVE,
7149 &base_vha->dpc_flags))) {
7151 qla2x00_loop_resync(base_vha);
7153 clear_bit(LOOP_RESYNC_ACTIVE,
7154 &base_vha->dpc_flags);
7157 ql_dbg(ql_dbg_dpc, base_vha, 0x4010,
7158 "Loop resync end.\n");
7164 if (test_bit(NPIV_CONFIG_NEEDED, &base_vha->dpc_flags) &&
7165 atomic_read(&base_vha->loop_state) == LOOP_READY) {
7166 clear_bit(NPIV_CONFIG_NEEDED, &base_vha->dpc_flags);
7167 qla2xxx_flash_npiv_conf(base_vha);
7171 if (!ha->interrupts_on)
7172 ha->isp_ops->enable_intrs(ha);
7174 if (test_and_clear_bit(BEACON_BLINK_NEEDED,
7175 &base_vha->dpc_flags)) {
7176 if (ha->beacon_blink_led == 1)
7177 ha->isp_ops->beacon_blink(base_vha);
7180 /* qpair online check */
7181 if (test_and_clear_bit(QPAIR_ONLINE_CHECK_NEEDED,
7182 &base_vha->dpc_flags)) {
7183 if (ha->flags.eeh_busy ||
7184 ha->flags.pci_channel_io_perm_failure)
7189 mutex_lock(&ha->mq_lock);
7190 list_for_each_entry(qpair, &base_vha->qp_list,
7192 qpair->online = online;
7193 mutex_unlock(&ha->mq_lock);
7196 if (test_and_clear_bit(SET_ZIO_THRESHOLD_NEEDED,
7197 &base_vha->dpc_flags)) {
7198 u16 threshold = ha->nvme_last_rptd_aen + ha->last_zio_threshold;
7200 if (threshold > ha->orig_fw_xcb_count)
7201 threshold = ha->orig_fw_xcb_count;
7203 ql_log(ql_log_info, base_vha, 0xffffff,
7204 "SET ZIO Activity exchange threshold to %d.\n",
7206 if (qla27xx_set_zio_threshold(base_vha, threshold)) {
7207 ql_log(ql_log_info, base_vha, 0xffffff,
7208 "Unable to SET ZIO Activity exchange threshold to %d.\n",
7213 if (!IS_QLAFX00(ha))
7214 qla2x00_do_dpc_all_vps(base_vha);
7216 if (test_and_clear_bit(N2N_LINK_RESET,
7217 &base_vha->dpc_flags)) {
7218 qla2x00_lip_reset(base_vha);
7223 set_current_state(TASK_INTERRUPTIBLE);
7224 } /* End of while(1) */
7225 __set_current_state(TASK_RUNNING);
7227 ql_dbg(ql_dbg_dpc, base_vha, 0x4011,
7228 "DPC handler exiting.\n");
7231 * Make sure that nobody tries to wake us up again.
7239 qla2xxx_wake_dpc(struct scsi_qla_host *vha)
7241 struct qla_hw_data *ha = vha->hw;
7242 struct task_struct *t = ha->dpc_thread;
7244 if (!test_bit(UNLOADING, &vha->dpc_flags) && t)
7250 * Processes asynchronous reset.
7253 * ha = adapter block pointer.
7256 qla2x00_rst_aen(scsi_qla_host_t *vha)
7258 if (vha->flags.online && !vha->flags.reset_active &&
7259 !atomic_read(&vha->loop_down_timer) &&
7260 !(test_bit(ABORT_ISP_ACTIVE, &vha->dpc_flags))) {
7262 clear_bit(RESET_MARKER_NEEDED, &vha->dpc_flags);
7265 * Issue marker command only when we are going to start
7268 vha->marker_needed = 1;
7269 } while (!atomic_read(&vha->loop_down_timer) &&
7270 (test_bit(RESET_MARKER_NEEDED, &vha->dpc_flags)));
7274 static bool qla_do_heartbeat(struct scsi_qla_host *vha)
7276 struct qla_hw_data *ha = vha->hw;
7279 bool do_heartbeat = false;
7282 * Allow do_heartbeat only if we don’t have any active interrupts,
7283 * but there are still IOs outstanding with firmware.
7285 cmpl_cnt = ha->base_qpair->cmd_completion_cnt;
7286 if (cmpl_cnt == ha->base_qpair->prev_completion_cnt &&
7287 cmpl_cnt != ha->base_qpair->cmd_cnt) {
7288 do_heartbeat = true;
7291 ha->base_qpair->prev_completion_cnt = cmpl_cnt;
7293 for (i = 0; i < ha->max_qpairs; i++) {
7294 if (ha->queue_pair_map[i]) {
7295 cmpl_cnt = ha->queue_pair_map[i]->cmd_completion_cnt;
7296 if (cmpl_cnt == ha->queue_pair_map[i]->prev_completion_cnt &&
7297 cmpl_cnt != ha->queue_pair_map[i]->cmd_cnt) {
7298 do_heartbeat = true;
7301 ha->queue_pair_map[i]->prev_completion_cnt = cmpl_cnt;
7306 return do_heartbeat;
7309 static void qla_heart_beat(struct scsi_qla_host *vha, u16 dpc_started)
7311 struct qla_hw_data *ha = vha->hw;
7316 if (vha->hw->flags.eeh_busy || qla2x00_chip_is_down(vha))
7320 * dpc thread cannot run if heartbeat is running at the same time.
7321 * We also do not want to starve heartbeat task. Therefore, do
7322 * heartbeat task at least once every 5 seconds.
7325 time_before(jiffies, ha->last_heartbeat_run_jiffies + 5 * HZ))
7328 if (qla_do_heartbeat(vha)) {
7329 ha->last_heartbeat_run_jiffies = jiffies;
7330 queue_work(ha->wq, &ha->heartbeat_work);
7334 static void qla_wind_down_chip(scsi_qla_host_t *vha)
7336 struct qla_hw_data *ha = vha->hw;
7338 if (!ha->flags.eeh_busy)
7340 if (ha->pci_error_state)
7341 /* system is trying to recover */
7345 * Current system is not handling PCIE error. At this point, this is
7346 * best effort to wind down the adapter.
7348 if (time_after_eq(jiffies, ha->eeh_jif + ql2xdelay_before_pci_error_handling * HZ) &&
7349 !ha->flags.eeh_flush) {
7350 ql_log(ql_log_info, vha, 0x9009,
7351 "PCI Error detected, attempting to reset hardware.\n");
7353 ha->isp_ops->reset_chip(vha);
7354 ha->isp_ops->disable_intrs(ha);
7356 ha->flags.eeh_flush = EEH_FLUSH_RDY;
7357 ha->eeh_jif = jiffies;
7359 } else if (ha->flags.eeh_flush == EEH_FLUSH_RDY &&
7360 time_after_eq(jiffies, ha->eeh_jif + 5 * HZ)) {
7361 pci_clear_master(ha->pdev);
7363 /* flush all command */
7364 qla2x00_abort_isp_cleanup(vha);
7365 ha->flags.eeh_flush = EEH_FLUSH_DONE;
7367 ql_log(ql_log_info, vha, 0x900a,
7368 "PCI Error handling complete, all IOs aborted.\n");
7372 /**************************************************************************
7378 * Context: Interrupt
7379 ***************************************************************************/
7381 qla2x00_timer(struct timer_list *t)
7383 scsi_qla_host_t *vha = timer_container_of(vha, t, timer);
7384 unsigned long cpu_flags = 0;
7389 struct qla_hw_data *ha = vha->hw;
7390 struct req_que *req;
7391 unsigned long flags;
7392 fc_port_t *fcport = NULL;
7394 if (ha->flags.eeh_busy) {
7395 qla_wind_down_chip(vha);
7397 ql_dbg(ql_dbg_timer, vha, 0x6000,
7398 "EEH = %d, restarting timer.\n",
7399 ha->flags.eeh_busy);
7400 qla2x00_restart_timer(vha, WATCH_INTERVAL);
7405 * Hardware read to raise pending EEH errors during mailbox waits. If
7406 * the read returns -1 then disable the board.
7408 if (!pci_channel_offline(ha->pdev)) {
7409 pci_read_config_word(ha->pdev, PCI_VENDOR_ID, &w);
7410 qla2x00_check_reg16_for_disconnect(vha, w);
7413 /* Make sure qla82xx_watchdog is run only for physical port */
7414 if (!vha->vp_idx && IS_P3P_TYPE(ha)) {
7415 if (test_bit(ISP_QUIESCE_NEEDED, &vha->dpc_flags))
7418 qla82xx_watchdog(vha);
7419 else if (IS_QLA8044(ha))
7420 qla8044_watchdog(vha);
7423 if (!vha->vp_idx && IS_QLAFX00(ha))
7424 qlafx00_timer_routine(vha);
7426 if (vha->link_down_time < QLA2XX_MAX_LINK_DOWN_TIME)
7427 vha->link_down_time++;
7429 spin_lock_irqsave(&vha->hw->tgt.sess_lock, flags);
7430 list_for_each_entry(fcport, &vha->vp_fcports, list) {
7431 if (fcport->tgt_link_down_time < QLA2XX_MAX_LINK_DOWN_TIME)
7432 fcport->tgt_link_down_time++;
7434 spin_unlock_irqrestore(&vha->hw->tgt.sess_lock, flags);
7436 /* Loop down handler. */
7437 if (atomic_read(&vha->loop_down_timer) > 0 &&
7438 !(test_bit(ABORT_ISP_ACTIVE, &vha->dpc_flags)) &&
7439 !(test_bit(FCOE_CTX_RESET_NEEDED, &vha->dpc_flags))
7440 && vha->flags.online) {
7442 if (atomic_read(&vha->loop_down_timer) ==
7443 vha->loop_down_abort_time) {
7445 ql_log(ql_log_info, vha, 0x6008,
7446 "Loop down - aborting the queues before time expires.\n");
7448 if (!IS_QLA2100(ha) && vha->link_down_timeout)
7449 atomic_set(&vha->loop_state, LOOP_DEAD);
7452 * Schedule an ISP abort to return any FCP2-device
7455 /* NPIV - scan physical port only */
7457 spin_lock_irqsave(&ha->hardware_lock,
7459 req = ha->req_q_map[0];
7461 index < req->num_outstanding_cmds;
7465 sp = req->outstanding_cmds[index];
7468 if (sp->cmd_type != TYPE_SRB)
7470 if (sp->type != SRB_SCSI_CMD)
7473 if (!(sfcp->flags & FCF_FCP2_DEVICE))
7477 set_bit(FCOE_CTX_RESET_NEEDED,
7480 set_bit(ISP_ABORT_NEEDED,
7484 spin_unlock_irqrestore(&ha->hardware_lock,
7490 /* if the loop has been down for 4 minutes, reinit adapter */
7491 if (atomic_dec_and_test(&vha->loop_down_timer) != 0) {
7492 if (!(vha->device_flags & DFLG_NO_CABLE) && !vha->vp_idx) {
7493 ql_log(ql_log_warn, vha, 0x6009,
7494 "Loop down - aborting ISP.\n");
7497 set_bit(FCOE_CTX_RESET_NEEDED,
7500 set_bit(ISP_ABORT_NEEDED,
7504 ql_dbg(ql_dbg_timer, vha, 0x600a,
7505 "Loop down - seconds remaining %d.\n",
7506 atomic_read(&vha->loop_down_timer));
7508 /* Check if beacon LED needs to be blinked for physical host only */
7509 if (!vha->vp_idx && (ha->beacon_blink_led == 1)) {
7510 /* There is no beacon_blink function for ISP82xx */
7511 if (!IS_P3P_TYPE(ha)) {
7512 set_bit(BEACON_BLINK_NEEDED, &vha->dpc_flags);
7517 /* check if edif running */
7518 if (vha->hw->flags.edif_enabled)
7519 qla_edif_timer(vha);
7521 /* Process any deferred work. */
7522 if (!list_empty(&vha->work_list)) {
7523 unsigned long flags;
7526 spin_lock_irqsave(&vha->work_lock, flags);
7527 if (!test_and_set_bit(IOCB_WORK_ACTIVE, &vha->dpc_flags))
7529 spin_unlock_irqrestore(&vha->work_lock, flags);
7531 queue_work(vha->hw->wq, &vha->iocb_work);
7536 * see if the active AEN count has changed from what was last reported.
7538 index = atomic_read(&ha->nvme_active_aen_cnt);
7540 (index != ha->nvme_last_rptd_aen) &&
7541 ha->zio_mode == QLA_ZIO_MODE_6 &&
7542 !ha->flags.host_shutting_down) {
7543 ha->nvme_last_rptd_aen = atomic_read(&ha->nvme_active_aen_cnt);
7544 ql_log(ql_log_info, vha, 0x3002,
7545 "nvme: Sched: Set ZIO exchange threshold to %d.\n",
7546 ha->nvme_last_rptd_aen);
7547 set_bit(SET_ZIO_THRESHOLD_NEEDED, &vha->dpc_flags);
7552 atomic_read(&ha->zio_threshold) != ha->last_zio_threshold &&
7553 IS_ZIO_THRESHOLD_CAPABLE(ha)) {
7554 ql_log(ql_log_info, vha, 0x3002,
7555 "Sched: Set ZIO exchange threshold to %d.\n",
7556 ha->last_zio_threshold);
7557 ha->last_zio_threshold = atomic_read(&ha->zio_threshold);
7558 set_bit(SET_ZIO_THRESHOLD_NEEDED, &vha->dpc_flags);
7561 qla_adjust_buf(vha);
7563 /* borrowing w to signify dpc will run */
7565 /* Schedule the DPC routine if needed */
7566 if ((test_bit(ISP_ABORT_NEEDED, &vha->dpc_flags) ||
7567 test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags) ||
7569 test_bit(RESET_MARKER_NEEDED, &vha->dpc_flags) ||
7570 test_bit(BEACON_BLINK_NEEDED, &vha->dpc_flags) ||
7571 test_bit(ISP_UNRECOVERABLE, &vha->dpc_flags) ||
7572 test_bit(FCOE_CTX_RESET_NEEDED, &vha->dpc_flags) ||
7573 test_bit(VP_DPC_NEEDED, &vha->dpc_flags) ||
7574 test_bit(RELOGIN_NEEDED, &vha->dpc_flags) ||
7575 test_bit(PROCESS_PUREX_IOCB, &vha->dpc_flags))) {
7576 ql_dbg(ql_dbg_timer, vha, 0x600b,
7577 "isp_abort_needed=%d loop_resync_needed=%d "
7578 "start_dpc=%d reset_marker_needed=%d",
7579 test_bit(ISP_ABORT_NEEDED, &vha->dpc_flags),
7580 test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags),
7581 start_dpc, test_bit(RESET_MARKER_NEEDED, &vha->dpc_flags));
7582 ql_dbg(ql_dbg_timer, vha, 0x600c,
7583 "beacon_blink_needed=%d isp_unrecoverable=%d "
7584 "fcoe_ctx_reset_needed=%d vp_dpc_needed=%d "
7585 "relogin_needed=%d, Process_purex_iocb=%d.\n",
7586 test_bit(BEACON_BLINK_NEEDED, &vha->dpc_flags),
7587 test_bit(ISP_UNRECOVERABLE, &vha->dpc_flags),
7588 test_bit(FCOE_CTX_RESET_NEEDED, &vha->dpc_flags),
7589 test_bit(VP_DPC_NEEDED, &vha->dpc_flags),
7590 test_bit(RELOGIN_NEEDED, &vha->dpc_flags),
7591 test_bit(PROCESS_PUREX_IOCB, &vha->dpc_flags));
7592 qla2xxx_wake_dpc(vha);
7596 qla_heart_beat(vha, w);
7598 qla2x00_restart_timer(vha, WATCH_INTERVAL);
7601 /* Firmware interface routines. */
7603 #define FW_ISP21XX 0
7604 #define FW_ISP22XX 1
7605 #define FW_ISP2300 2
7606 #define FW_ISP2322 3
7607 #define FW_ISP24XX 4
7608 #define FW_ISP25XX 5
7609 #define FW_ISP81XX 6
7610 #define FW_ISP82XX 7
7611 #define FW_ISP2031 8
7612 #define FW_ISP8031 9
7613 #define FW_ISP27XX 10
7614 #define FW_ISP28XX 11
7616 #define FW_FILE_ISP21XX "ql2100_fw.bin"
7617 #define FW_FILE_ISP22XX "ql2200_fw.bin"
7618 #define FW_FILE_ISP2300 "ql2300_fw.bin"
7619 #define FW_FILE_ISP2322 "ql2322_fw.bin"
7620 #define FW_FILE_ISP24XX "ql2400_fw.bin"
7621 #define FW_FILE_ISP25XX "ql2500_fw.bin"
7622 #define FW_FILE_ISP81XX "ql8100_fw.bin"
7623 #define FW_FILE_ISP82XX "ql8200_fw.bin"
7624 #define FW_FILE_ISP2031 "ql2600_fw.bin"
7625 #define FW_FILE_ISP8031 "ql8300_fw.bin"
7626 #define FW_FILE_ISP27XX "ql2700_fw.bin"
7627 #define FW_FILE_ISP28XX "ql2800_fw.bin"
7630 static DEFINE_MUTEX(qla_fw_lock);
7632 static struct fw_blob qla_fw_blobs[] = {
7633 { .name = FW_FILE_ISP21XX, .segs = { 0x1000, 0 }, },
7634 { .name = FW_FILE_ISP22XX, .segs = { 0x1000, 0 }, },
7635 { .name = FW_FILE_ISP2300, .segs = { 0x800, 0 }, },
7636 { .name = FW_FILE_ISP2322, .segs = { 0x800, 0x1c000, 0x1e000, 0 }, },
7637 { .name = FW_FILE_ISP24XX, },
7638 { .name = FW_FILE_ISP25XX, },
7639 { .name = FW_FILE_ISP81XX, },
7640 { .name = FW_FILE_ISP82XX, },
7641 { .name = FW_FILE_ISP2031, },
7642 { .name = FW_FILE_ISP8031, },
7643 { .name = FW_FILE_ISP27XX, },
7644 { .name = FW_FILE_ISP28XX, },
7649 qla2x00_request_firmware(scsi_qla_host_t *vha)
7651 struct qla_hw_data *ha = vha->hw;
7652 struct fw_blob *blob;
7654 if (IS_QLA2100(ha)) {
7655 blob = &qla_fw_blobs[FW_ISP21XX];
7656 } else if (IS_QLA2200(ha)) {
7657 blob = &qla_fw_blobs[FW_ISP22XX];
7658 } else if (IS_QLA2300(ha) || IS_QLA2312(ha) || IS_QLA6312(ha)) {
7659 blob = &qla_fw_blobs[FW_ISP2300];
7660 } else if (IS_QLA2322(ha) || IS_QLA6322(ha)) {
7661 blob = &qla_fw_blobs[FW_ISP2322];
7662 } else if (IS_QLA24XX_TYPE(ha)) {
7663 blob = &qla_fw_blobs[FW_ISP24XX];
7664 } else if (IS_QLA25XX(ha)) {
7665 blob = &qla_fw_blobs[FW_ISP25XX];
7666 } else if (IS_QLA81XX(ha)) {
7667 blob = &qla_fw_blobs[FW_ISP81XX];
7668 } else if (IS_QLA82XX(ha)) {
7669 blob = &qla_fw_blobs[FW_ISP82XX];
7670 } else if (IS_QLA2031(ha)) {
7671 blob = &qla_fw_blobs[FW_ISP2031];
7672 } else if (IS_QLA8031(ha)) {
7673 blob = &qla_fw_blobs[FW_ISP8031];
7674 } else if (IS_QLA27XX(ha)) {
7675 blob = &qla_fw_blobs[FW_ISP27XX];
7676 } else if (IS_QLA28XX(ha)) {
7677 blob = &qla_fw_blobs[FW_ISP28XX];
7685 mutex_lock(&qla_fw_lock);
7689 if (request_firmware(&blob->fw, blob->name, &ha->pdev->dev)) {
7690 ql_log(ql_log_warn, vha, 0x0063,
7691 "Failed to load firmware image (%s).\n", blob->name);
7697 mutex_unlock(&qla_fw_lock);
7702 qla2x00_release_firmware(void)
7704 struct fw_blob *blob;
7706 mutex_lock(&qla_fw_lock);
7707 for (blob = qla_fw_blobs; blob->name; blob++)
7708 release_firmware(blob->fw);
7709 mutex_unlock(&qla_fw_lock);
7712 static void qla_pci_error_cleanup(scsi_qla_host_t *vha)
7714 struct qla_hw_data *ha = vha->hw;
7715 scsi_qla_host_t *base_vha = pci_get_drvdata(ha->pdev);
7716 struct qla_qpair *qpair = NULL;
7717 struct scsi_qla_host *vp, *tvp;
7720 unsigned long flags;
7722 ql_dbg(ql_dbg_aer, vha, 0x9000,
7726 ha->base_qpair->chip_reset = ha->chip_reset;
7727 for (i = 0; i < ha->max_qpairs; i++) {
7728 if (ha->queue_pair_map[i])
7729 ha->queue_pair_map[i]->chip_reset =
7730 ha->base_qpair->chip_reset;
7734 * purge mailbox might take a while. Slot Reset/chip reset
7735 * will take care of the purge
7738 mutex_lock(&ha->mq_lock);
7739 ha->base_qpair->online = 0;
7740 list_for_each_entry(qpair, &base_vha->qp_list, qp_list_elem)
7743 mutex_unlock(&ha->mq_lock);
7745 qla2x00_mark_all_devices_lost(vha);
7747 spin_lock_irqsave(&ha->vport_slock, flags);
7748 list_for_each_entry_safe(vp, tvp, &ha->vp_list, list) {
7749 atomic_inc(&vp->vref_count);
7750 spin_unlock_irqrestore(&ha->vport_slock, flags);
7751 qla2x00_mark_all_devices_lost(vp);
7752 spin_lock_irqsave(&ha->vport_slock, flags);
7753 atomic_dec(&vp->vref_count);
7755 spin_unlock_irqrestore(&ha->vport_slock, flags);
7757 /* Clear all async request states across all VPs. */
7758 list_for_each_entry(fcport, &vha->vp_fcports, list)
7759 fcport->flags &= ~(FCF_LOGIN_NEEDED | FCF_ASYNC_SENT);
7761 spin_lock_irqsave(&ha->vport_slock, flags);
7762 list_for_each_entry_safe(vp, tvp, &ha->vp_list, list) {
7763 atomic_inc(&vp->vref_count);
7764 spin_unlock_irqrestore(&ha->vport_slock, flags);
7765 list_for_each_entry(fcport, &vp->vp_fcports, list)
7766 fcport->flags &= ~(FCF_LOGIN_NEEDED | FCF_ASYNC_SENT);
7767 spin_lock_irqsave(&ha->vport_slock, flags);
7768 atomic_dec(&vp->vref_count);
7770 spin_unlock_irqrestore(&ha->vport_slock, flags);
7774 static pci_ers_result_t
7775 qla2xxx_pci_error_detected(struct pci_dev *pdev, pci_channel_state_t state)
7777 scsi_qla_host_t *vha = pci_get_drvdata(pdev);
7778 struct qla_hw_data *ha = vha->hw;
7779 pci_ers_result_t ret = PCI_ERS_RESULT_NEED_RESET;
7781 ql_log(ql_log_warn, vha, 0x9000,
7782 "PCI error detected, state %x.\n", state);
7783 ha->pci_error_state = QLA_PCI_ERR_DETECTED;
7785 if (!atomic_read(&pdev->enable_cnt)) {
7786 ql_log(ql_log_info, vha, 0xffff,
7787 "PCI device is disabled,state %x\n", state);
7788 ret = PCI_ERS_RESULT_NEED_RESET;
7793 case pci_channel_io_normal:
7794 qla_pci_set_eeh_busy(vha);
7795 if (ql2xmqsupport || ql2xnvmeenable) {
7796 set_bit(QPAIR_ONLINE_CHECK_NEEDED, &vha->dpc_flags);
7797 qla2xxx_wake_dpc(vha);
7799 ret = PCI_ERS_RESULT_CAN_RECOVER;
7801 case pci_channel_io_frozen:
7802 qla_pci_set_eeh_busy(vha);
7803 ret = PCI_ERS_RESULT_NEED_RESET;
7805 case pci_channel_io_perm_failure:
7806 ha->flags.pci_channel_io_perm_failure = 1;
7807 qla2x00_abort_all_cmds(vha, DID_NO_CONNECT << 16);
7808 if (ql2xmqsupport || ql2xnvmeenable) {
7809 set_bit(QPAIR_ONLINE_CHECK_NEEDED, &vha->dpc_flags);
7810 qla2xxx_wake_dpc(vha);
7812 ret = PCI_ERS_RESULT_DISCONNECT;
7815 ql_dbg(ql_dbg_aer, vha, 0x600d,
7816 "PCI error detected returning [%x].\n", ret);
7820 static pci_ers_result_t
7821 qla2xxx_pci_mmio_enabled(struct pci_dev *pdev)
7823 int risc_paused = 0;
7825 unsigned long flags;
7826 scsi_qla_host_t *base_vha = pci_get_drvdata(pdev);
7827 struct qla_hw_data *ha = base_vha->hw;
7828 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
7829 struct device_reg_24xx __iomem *reg24 = &ha->iobase->isp24;
7831 ql_log(ql_log_warn, base_vha, 0x9000,
7834 ha->pci_error_state = QLA_PCI_MMIO_ENABLED;
7837 return PCI_ERS_RESULT_RECOVERED;
7839 if (qla2x00_isp_reg_stat(ha)) {
7840 ql_log(ql_log_info, base_vha, 0x803f,
7841 "During mmio enabled, PCI/Register disconnect still detected.\n");
7845 spin_lock_irqsave(&ha->hardware_lock, flags);
7846 if (IS_QLA2100(ha) || IS_QLA2200(ha)){
7847 stat = rd_reg_word(®->hccr);
7848 if (stat & HCCR_RISC_PAUSE)
7850 } else if (IS_QLA23XX(ha)) {
7851 stat = rd_reg_dword(®->u.isp2300.host_status);
7852 if (stat & HSR_RISC_PAUSED)
7854 } else if (IS_FWI2_CAPABLE(ha)) {
7855 stat = rd_reg_dword(®24->host_status);
7856 if (stat & HSRX_RISC_PAUSED)
7859 spin_unlock_irqrestore(&ha->hardware_lock, flags);
7862 ql_log(ql_log_info, base_vha, 0x9003,
7863 "RISC paused -- mmio_enabled, Dumping firmware.\n");
7864 qla2xxx_dump_fw(base_vha);
7867 /* set PCI_ERS_RESULT_NEED_RESET to trigger call to qla2xxx_pci_slot_reset */
7868 ql_dbg(ql_dbg_aer, base_vha, 0x600d,
7869 "mmio enabled returning.\n");
7870 return PCI_ERS_RESULT_NEED_RESET;
7873 static pci_ers_result_t
7874 qla2xxx_pci_slot_reset(struct pci_dev *pdev)
7876 pci_ers_result_t ret = PCI_ERS_RESULT_DISCONNECT;
7877 scsi_qla_host_t *base_vha = pci_get_drvdata(pdev);
7878 struct qla_hw_data *ha = base_vha->hw;
7880 struct qla_qpair *qpair = NULL;
7882 ql_log(ql_log_warn, base_vha, 0x9004,
7885 ha->pci_error_state = QLA_PCI_SLOT_RESET;
7886 /* Workaround: qla2xxx driver which access hardware earlier
7887 * needs error state to be pci_channel_io_online.
7888 * Otherwise mailbox command timesout.
7890 pdev->error_state = pci_channel_io_normal;
7892 pci_restore_state(pdev);
7894 /* pci_restore_state() clears the saved_state flag of the device
7895 * save restored state which resets saved_state flag
7897 pci_save_state(pdev);
7900 rc = pci_enable_device_mem(pdev);
7902 rc = pci_enable_device(pdev);
7905 ql_log(ql_log_warn, base_vha, 0x9005,
7906 "Can't re-enable PCI device after reset.\n");
7907 goto exit_slot_reset;
7911 if (ha->isp_ops->pci_config(base_vha))
7912 goto exit_slot_reset;
7914 mutex_lock(&ha->mq_lock);
7915 list_for_each_entry(qpair, &base_vha->qp_list, qp_list_elem)
7917 mutex_unlock(&ha->mq_lock);
7919 ha->flags.eeh_busy = 0;
7920 base_vha->flags.online = 1;
7921 set_bit(ABORT_ISP_ACTIVE, &base_vha->dpc_flags);
7922 ha->isp_ops->abort_isp(base_vha);
7923 clear_bit(ABORT_ISP_ACTIVE, &base_vha->dpc_flags);
7925 if (qla2x00_isp_reg_stat(ha)) {
7926 ha->flags.eeh_busy = 1;
7927 qla_pci_error_cleanup(base_vha);
7928 ql_log(ql_log_warn, base_vha, 0x9005,
7929 "Device unable to recover from PCI error.\n");
7931 ret = PCI_ERS_RESULT_RECOVERED;
7935 ql_dbg(ql_dbg_aer, base_vha, 0x900e,
7936 "Slot Reset returning %x.\n", ret);
7942 qla2xxx_pci_resume(struct pci_dev *pdev)
7944 scsi_qla_host_t *base_vha = pci_get_drvdata(pdev);
7945 struct qla_hw_data *ha = base_vha->hw;
7948 ql_log(ql_log_warn, base_vha, 0x900f,
7952 ret = qla2x00_wait_for_hba_online(base_vha);
7953 if (ret != QLA_SUCCESS) {
7954 ql_log(ql_log_fatal, base_vha, 0x9002,
7955 "The device failed to resume I/O from slot/link_reset.\n");
7957 ha->pci_error_state = QLA_PCI_RESUME;
7958 ql_dbg(ql_dbg_aer, base_vha, 0x600d,
7959 "Pci Resume returning.\n");
7962 void qla_pci_set_eeh_busy(struct scsi_qla_host *vha)
7964 struct qla_hw_data *ha = vha->hw;
7965 struct scsi_qla_host *base_vha = pci_get_drvdata(ha->pdev);
7966 bool do_cleanup = false;
7967 unsigned long flags;
7969 if (ha->flags.eeh_busy)
7972 spin_lock_irqsave(&base_vha->work_lock, flags);
7973 if (!ha->flags.eeh_busy) {
7974 ha->eeh_jif = jiffies;
7975 ha->flags.eeh_flush = 0;
7977 ha->flags.eeh_busy = 1;
7980 spin_unlock_irqrestore(&base_vha->work_lock, flags);
7983 qla_pci_error_cleanup(base_vha);
7987 * this routine will schedule a task to pause IO from interrupt context
7988 * if caller sees a PCIE error event (register read = 0xf's)
7990 void qla_schedule_eeh_work(struct scsi_qla_host *vha)
7992 struct qla_hw_data *ha = vha->hw;
7993 struct scsi_qla_host *base_vha = pci_get_drvdata(ha->pdev);
7995 if (ha->flags.eeh_busy)
7998 set_bit(DO_EEH_RECOVERY, &base_vha->dpc_flags);
7999 qla2xxx_wake_dpc(base_vha);
8003 qla_pci_reset_prepare(struct pci_dev *pdev)
8005 scsi_qla_host_t *base_vha = pci_get_drvdata(pdev);
8006 struct qla_hw_data *ha = base_vha->hw;
8007 struct qla_qpair *qpair;
8009 ql_log(ql_log_warn, base_vha, 0xffff,
8013 * PCI FLR/function reset is about to reset the
8014 * slot. Stop the chip to stop all DMA access.
8015 * It is assumed that pci_reset_done will be called
8016 * after FLR to resume Chip operation.
8018 ha->flags.eeh_busy = 1;
8019 mutex_lock(&ha->mq_lock);
8020 list_for_each_entry(qpair, &base_vha->qp_list, qp_list_elem)
8022 mutex_unlock(&ha->mq_lock);
8024 set_bit(ABORT_ISP_ACTIVE, &base_vha->dpc_flags);
8025 qla2x00_abort_isp_cleanup(base_vha);
8026 qla2x00_abort_all_cmds(base_vha, DID_RESET << 16);
8030 qla_pci_reset_done(struct pci_dev *pdev)
8032 scsi_qla_host_t *base_vha = pci_get_drvdata(pdev);
8033 struct qla_hw_data *ha = base_vha->hw;
8034 struct qla_qpair *qpair;
8036 ql_log(ql_log_warn, base_vha, 0xffff,
8040 * FLR just completed by PCI layer. Resume adapter
8042 ha->flags.eeh_busy = 0;
8043 mutex_lock(&ha->mq_lock);
8044 list_for_each_entry(qpair, &base_vha->qp_list, qp_list_elem)
8046 mutex_unlock(&ha->mq_lock);
8048 base_vha->flags.online = 1;
8049 ha->isp_ops->abort_isp(base_vha);
8050 clear_bit(ABORT_ISP_ACTIVE, &base_vha->dpc_flags);
8053 static void qla2xxx_map_queues(struct Scsi_Host *shost)
8055 scsi_qla_host_t *vha = (scsi_qla_host_t *)shost->hostdata;
8056 struct blk_mq_queue_map *qmap = &shost->tag_set.map[HCTX_TYPE_DEFAULT];
8058 if (USER_CTRL_IRQ(vha->hw) || !vha->hw->mqiobase)
8059 blk_mq_map_queues(qmap);
8061 blk_mq_map_hw_queues(qmap, &vha->hw->pdev->dev,
8065 struct scsi_host_template qla2xxx_driver_template = {
8066 .module = THIS_MODULE,
8067 .name = QLA2XXX_DRIVER_NAME,
8068 .queuecommand = qla2xxx_queuecommand,
8070 .eh_timed_out = fc_eh_timed_out,
8071 .eh_abort_handler = qla2xxx_eh_abort,
8072 .eh_should_retry_cmd = fc_eh_should_retry_cmd,
8073 .eh_device_reset_handler = qla2xxx_eh_device_reset,
8074 .eh_target_reset_handler = qla2xxx_eh_target_reset,
8075 .eh_bus_reset_handler = qla2xxx_eh_bus_reset,
8076 .eh_host_reset_handler = qla2xxx_eh_host_reset,
8078 .sdev_configure = qla2xxx_sdev_configure,
8080 .sdev_init = qla2xxx_sdev_init,
8081 .sdev_destroy = qla2xxx_sdev_destroy,
8082 .scan_finished = qla2xxx_scan_finished,
8083 .scan_start = qla2xxx_scan_start,
8084 .change_queue_depth = scsi_change_queue_depth,
8085 .map_queues = qla2xxx_map_queues,
8088 .sg_tablesize = SG_ALL,
8090 .max_sectors = 0xFFFF,
8091 .shost_groups = qla2x00_host_groups,
8093 .supported_mode = MODE_INITIATOR,
8094 .track_queue_depth = 1,
8095 .cmd_size = sizeof(srb_t),
8098 static const struct pci_error_handlers qla2xxx_err_handler = {
8099 .error_detected = qla2xxx_pci_error_detected,
8100 .mmio_enabled = qla2xxx_pci_mmio_enabled,
8101 .slot_reset = qla2xxx_pci_slot_reset,
8102 .resume = qla2xxx_pci_resume,
8103 .reset_prepare = qla_pci_reset_prepare,
8104 .reset_done = qla_pci_reset_done,
8107 static const struct pci_device_id qla2xxx_pci_tbl[] = {
8108 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP2100) },
8109 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP2200) },
8110 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP2300) },
8111 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP2312) },
8112 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP2322) },
8113 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP6312) },
8114 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP6322) },
8115 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP2422) },
8116 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP2432) },
8117 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP8432) },
8118 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP5422) },
8119 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP5432) },
8120 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP2532) },
8121 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP2031) },
8122 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP8001) },
8123 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP8021) },
8124 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP8031) },
8125 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISPF001) },
8126 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP8044) },
8127 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP2071) },
8128 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP2271) },
8129 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP2261) },
8130 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP2061) },
8131 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP2081) },
8132 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP2281) },
8133 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP2089) },
8134 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP2289) },
8137 MODULE_DEVICE_TABLE(pci, qla2xxx_pci_tbl);
8139 static struct pci_driver qla2xxx_pci_driver = {
8140 .name = QLA2XXX_DRIVER_NAME,
8141 .id_table = qla2xxx_pci_tbl,
8142 .probe = qla2x00_probe_one,
8143 .remove = qla2x00_remove_one,
8144 .shutdown = qla2x00_shutdown,
8145 .err_handler = &qla2xxx_err_handler,
8148 static const struct file_operations apidev_fops = {
8149 .owner = THIS_MODULE,
8150 .llseek = noop_llseek,
8154 * qla2x00_module_init - Module initialization.
8157 qla2x00_module_init(void)
8161 BUILD_BUG_ON(sizeof(cmd_a64_entry_t) != 64);
8162 BUILD_BUG_ON(sizeof(cmd_entry_t) != 64);
8163 BUILD_BUG_ON(sizeof(cont_a64_entry_t) != 64);
8164 BUILD_BUG_ON(sizeof(cont_entry_t) != 64);
8165 BUILD_BUG_ON(sizeof(init_cb_t) != 96);
8166 BUILD_BUG_ON(sizeof(mrk_entry_t) != 64);
8167 BUILD_BUG_ON(sizeof(ms_iocb_entry_t) != 64);
8168 BUILD_BUG_ON(sizeof(request_t) != 64);
8169 BUILD_BUG_ON(sizeof(struct abort_entry_24xx) != 64);
8170 BUILD_BUG_ON(sizeof(struct abort_iocb_entry_fx00) != 64);
8171 BUILD_BUG_ON(sizeof(struct abts_entry_24xx) != 64);
8172 BUILD_BUG_ON(sizeof(struct access_chip_84xx) != 64);
8173 BUILD_BUG_ON(sizeof(struct access_chip_rsp_84xx) != 64);
8174 BUILD_BUG_ON(sizeof(struct cmd_bidir) != 64);
8175 BUILD_BUG_ON(sizeof(struct cmd_nvme) != 64);
8176 BUILD_BUG_ON(sizeof(struct cmd_type_6) != 64);
8177 BUILD_BUG_ON(sizeof(struct cmd_type_7) != 64);
8178 BUILD_BUG_ON(sizeof(struct cmd_type_7_fx00) != 64);
8179 BUILD_BUG_ON(sizeof(struct cmd_type_crc_2) != 64);
8180 BUILD_BUG_ON(sizeof(struct ct_entry_24xx) != 64);
8181 BUILD_BUG_ON(sizeof(struct ct_fdmi1_hba_attributes) != 2604);
8182 BUILD_BUG_ON(sizeof(struct ct_fdmi2_hba_attributes) != 4424);
8183 BUILD_BUG_ON(sizeof(struct ct_fdmi2_port_attributes) != 4164);
8184 BUILD_BUG_ON(sizeof(struct ct_fdmi_hba_attr) != 260);
8185 BUILD_BUG_ON(sizeof(struct ct_fdmi_port_attr) != 260);
8186 BUILD_BUG_ON(sizeof(struct ct_rsp_hdr) != 16);
8187 BUILD_BUG_ON(sizeof(struct ctio_crc2_to_fw) != 64);
8188 BUILD_BUG_ON(sizeof(struct device_reg_24xx) != 256);
8189 BUILD_BUG_ON(sizeof(struct device_reg_25xxmq) != 24);
8190 BUILD_BUG_ON(sizeof(struct device_reg_2xxx) != 256);
8191 BUILD_BUG_ON(sizeof(struct device_reg_82xx) != 1288);
8192 BUILD_BUG_ON(sizeof(struct device_reg_fx00) != 216);
8193 BUILD_BUG_ON(sizeof(struct els_entry_24xx) != 64);
8194 BUILD_BUG_ON(sizeof(struct els_sts_entry_24xx) != 64);
8195 BUILD_BUG_ON(sizeof(struct fxdisc_entry_fx00) != 64);
8196 BUILD_BUG_ON(sizeof(struct imm_ntfy_from_isp) != 64);
8197 BUILD_BUG_ON(sizeof(struct init_cb_24xx) != 128);
8198 BUILD_BUG_ON(sizeof(struct init_cb_81xx) != 128);
8199 BUILD_BUG_ON(sizeof(struct logio_entry_24xx) != 64);
8200 BUILD_BUG_ON(sizeof(struct mbx_entry) != 64);
8201 BUILD_BUG_ON(sizeof(struct mid_init_cb_24xx) != 5252);
8202 BUILD_BUG_ON(sizeof(struct mrk_entry_24xx) != 64);
8203 BUILD_BUG_ON(sizeof(struct nvram_24xx) != 512);
8204 BUILD_BUG_ON(sizeof(struct nvram_81xx) != 512);
8205 BUILD_BUG_ON(sizeof(struct pt_ls4_request) != 64);
8206 BUILD_BUG_ON(sizeof(struct pt_ls4_rx_unsol) != 64);
8207 BUILD_BUG_ON(sizeof(struct purex_entry_24xx) != 64);
8208 BUILD_BUG_ON(sizeof(struct qla2100_fw_dump) != 123634);
8209 BUILD_BUG_ON(sizeof(struct qla2300_fw_dump) != 136100);
8210 BUILD_BUG_ON(sizeof(struct qla24xx_fw_dump) != 37976);
8211 BUILD_BUG_ON(sizeof(struct qla25xx_fw_dump) != 39228);
8212 BUILD_BUG_ON(sizeof(struct qla2xxx_fce_chain) != 52);
8213 BUILD_BUG_ON(sizeof(struct qla2xxx_fw_dump) != 136172);
8214 BUILD_BUG_ON(sizeof(struct qla2xxx_mq_chain) != 524);
8215 BUILD_BUG_ON(sizeof(struct qla2xxx_mqueue_chain) != 8);
8216 BUILD_BUG_ON(sizeof(struct qla2xxx_mqueue_header) != 12);
8217 BUILD_BUG_ON(sizeof(struct qla2xxx_offld_chain) != 24);
8218 BUILD_BUG_ON(sizeof(struct qla81xx_fw_dump) != 39420);
8219 BUILD_BUG_ON(sizeof(struct qla82xx_uri_data_desc) != 28);
8220 BUILD_BUG_ON(sizeof(struct qla82xx_uri_table_desc) != 32);
8221 BUILD_BUG_ON(sizeof(struct qla83xx_fw_dump) != 51196);
8222 BUILD_BUG_ON(sizeof(struct qla_fcp_prio_cfg) != FCP_PRIO_CFG_SIZE);
8223 BUILD_BUG_ON(sizeof(struct qla_fdt_layout) != 128);
8224 BUILD_BUG_ON(sizeof(struct qla_flt_header) != 8);
8225 BUILD_BUG_ON(sizeof(struct qla_flt_region) != 16);
8226 BUILD_BUG_ON(sizeof(struct qla_npiv_entry) != 24);
8227 BUILD_BUG_ON(sizeof(struct qla_npiv_header) != 16);
8228 BUILD_BUG_ON(sizeof(struct rdp_rsp_payload) != 336);
8229 BUILD_BUG_ON(sizeof(struct sns_cmd_pkt) != 2064);
8230 BUILD_BUG_ON(sizeof(struct sts_entry_24xx) != 64);
8231 BUILD_BUG_ON(sizeof(struct tsk_mgmt_entry) != 64);
8232 BUILD_BUG_ON(sizeof(struct tsk_mgmt_entry_fx00) != 64);
8233 BUILD_BUG_ON(sizeof(struct verify_chip_entry_84xx) != 64);
8234 BUILD_BUG_ON(sizeof(struct verify_chip_rsp_84xx) != 52);
8235 BUILD_BUG_ON(sizeof(struct vf_evfp_entry_24xx) != 56);
8236 BUILD_BUG_ON(sizeof(struct vp_config_entry_24xx) != 64);
8237 BUILD_BUG_ON(sizeof(struct vp_ctrl_entry_24xx) != 64);
8238 BUILD_BUG_ON(sizeof(struct vp_rpt_id_entry_24xx) != 64);
8239 BUILD_BUG_ON(sizeof(sts21_entry_t) != 64);
8240 BUILD_BUG_ON(sizeof(sts22_entry_t) != 64);
8241 BUILD_BUG_ON(sizeof(sts_cont_entry_t) != 64);
8242 BUILD_BUG_ON(sizeof(sts_entry_t) != 64);
8243 BUILD_BUG_ON(sizeof(sw_info_t) != 32);
8244 BUILD_BUG_ON(sizeof(target_id_t) != 2);
8248 /* Allocate cache for SRBs. */
8249 srb_cachep = kmem_cache_create("qla2xxx_srbs", sizeof(srb_t), 0,
8250 SLAB_HWCACHE_ALIGN, NULL);
8251 if (srb_cachep == NULL) {
8252 ql_log(ql_log_fatal, NULL, 0x0001,
8253 "Unable to allocate SRB cache...Failing load!.\n");
8257 /* Initialize target kmem_cache and mem_pools */
8261 } else if (ret > 0) {
8263 * If initiator mode is explictly disabled by qlt_init(),
8264 * prevent scsi_transport_fc.c:fc_scsi_scan_rport() from
8265 * performing scsi_scan_target() during LOOP UP event.
8267 qla2xxx_transport_functions.disable_target_scan = 1;
8268 qla2xxx_transport_vport_functions.disable_target_scan = 1;
8271 /* Derive version string. */
8272 strcpy(qla2x00_version_str, QLA2XXX_VERSION);
8273 if (ql2xextended_error_logging)
8274 strcat(qla2x00_version_str, "-debug");
8275 if (ql2xextended_error_logging == 1)
8276 ql2xextended_error_logging = QL_DBG_DEFAULT1_MASK;
8278 qla2xxx_transport_template =
8279 fc_attach_transport(&qla2xxx_transport_functions);
8280 if (!qla2xxx_transport_template) {
8281 ql_log(ql_log_fatal, NULL, 0x0002,
8282 "fc_attach_transport failed...Failing load!.\n");
8287 apidev_major = register_chrdev(0, QLA2XXX_APIDEV, &apidev_fops);
8288 if (apidev_major < 0) {
8289 ql_log(ql_log_fatal, NULL, 0x0003,
8290 "Unable to register char device %s.\n", QLA2XXX_APIDEV);
8293 qla2xxx_transport_vport_template =
8294 fc_attach_transport(&qla2xxx_transport_vport_functions);
8295 if (!qla2xxx_transport_vport_template) {
8296 ql_log(ql_log_fatal, NULL, 0x0004,
8297 "fc_attach_transport vport failed...Failing load!.\n");
8301 ql_log(ql_log_info, NULL, 0x0005,
8302 "QLogic Fibre Channel HBA Driver: %s.\n",
8303 qla2x00_version_str);
8304 ret = pci_register_driver(&qla2xxx_pci_driver);
8306 ql_log(ql_log_fatal, NULL, 0x0006,
8307 "pci_register_driver failed...ret=%d Failing load!.\n",
8309 goto release_vport_transport;
8313 release_vport_transport:
8314 fc_release_transport(qla2xxx_transport_vport_template);
8317 if (apidev_major >= 0)
8318 unregister_chrdev(apidev_major, QLA2XXX_APIDEV);
8319 fc_release_transport(qla2xxx_transport_template);
8325 kmem_cache_destroy(srb_cachep);
8332 * qla2x00_module_exit - Module cleanup.
8335 qla2x00_module_exit(void)
8337 pci_unregister_driver(&qla2xxx_pci_driver);
8338 qla2x00_release_firmware();
8339 kmem_cache_destroy(ctx_cachep);
8340 fc_release_transport(qla2xxx_transport_vport_template);
8341 if (apidev_major >= 0)
8342 unregister_chrdev(apidev_major, QLA2XXX_APIDEV);
8343 fc_release_transport(qla2xxx_transport_template);
8345 kmem_cache_destroy(srb_cachep);
8349 module_init(qla2x00_module_init);
8350 module_exit(qla2x00_module_exit);
8352 MODULE_AUTHOR("QLogic Corporation");
8353 MODULE_DESCRIPTION("QLogic Fibre Channel HBA Driver");
8354 MODULE_LICENSE("GPL");
8355 MODULE_FIRMWARE(FW_FILE_ISP21XX);
8356 MODULE_FIRMWARE(FW_FILE_ISP22XX);
8357 MODULE_FIRMWARE(FW_FILE_ISP2300);
8358 MODULE_FIRMWARE(FW_FILE_ISP2322);
8359 MODULE_FIRMWARE(FW_FILE_ISP24XX);
8360 MODULE_FIRMWARE(FW_FILE_ISP25XX);