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/blk-mq-pci.h>
17 #include <linux/refcount.h>
18 #include <linux/crash_dump.h>
19 #include <linux/trace_events.h>
20 #include <linux/trace.h>
22 #include <scsi/scsi_tcq.h>
23 #include <scsi/scsicam.h>
24 #include <scsi/scsi_transport.h>
25 #include <scsi/scsi_transport_fc.h>
27 #include "qla_target.h"
32 char qla2x00_version_str[40];
34 static int apidev_major;
37 * SRB allocation cache
39 struct kmem_cache *srb_cachep;
41 static struct trace_array *qla_trc_array;
43 int ql2xfulldump_on_mpifail;
44 module_param(ql2xfulldump_on_mpifail, int, S_IRUGO | S_IWUSR);
45 MODULE_PARM_DESC(ql2xfulldump_on_mpifail,
46 "Set this to take full dump on MPI hang.");
48 int ql2xenforce_iocb_limit = 2;
49 module_param(ql2xenforce_iocb_limit, int, S_IRUGO | S_IWUSR);
50 MODULE_PARM_DESC(ql2xenforce_iocb_limit,
51 "Enforce IOCB throttling, to avoid FW congestion. (default: 2) "
52 "1: track usage per queue, 2: track usage per adapter");
55 * CT6 CTX allocation cache
57 static struct kmem_cache *ctx_cachep;
59 * error level for logging
61 uint ql_errlev = 0x8001;
64 module_param(ql2xsecenable, int, S_IRUGO);
65 MODULE_PARM_DESC(ql2xsecenable,
66 "Enable/disable security. 0(Default) - Security disabled. 1 - Security enabled.");
68 static int ql2xenableclass2;
69 module_param(ql2xenableclass2, int, S_IRUGO|S_IRUSR);
70 MODULE_PARM_DESC(ql2xenableclass2,
71 "Specify if Class 2 operations are supported from the very "
72 "beginning. Default is 0 - class 2 not supported.");
75 int ql2xlogintimeout = 20;
76 module_param(ql2xlogintimeout, int, S_IRUGO);
77 MODULE_PARM_DESC(ql2xlogintimeout,
78 "Login timeout value in seconds.");
80 int qlport_down_retry;
81 module_param(qlport_down_retry, int, S_IRUGO);
82 MODULE_PARM_DESC(qlport_down_retry,
83 "Maximum number of command retries to a port that returns "
84 "a PORT-DOWN status.");
86 int ql2xplogiabsentdevice;
87 module_param(ql2xplogiabsentdevice, int, S_IRUGO|S_IWUSR);
88 MODULE_PARM_DESC(ql2xplogiabsentdevice,
89 "Option to enable PLOGI to devices that are not present after "
90 "a Fabric scan. This is needed for several broken switches. "
91 "Default is 0 - no PLOGI. 1 - perform PLOGI.");
93 int ql2xloginretrycount;
94 module_param(ql2xloginretrycount, int, S_IRUGO);
95 MODULE_PARM_DESC(ql2xloginretrycount,
96 "Specify an alternate value for the NVRAM login retry count.");
98 int ql2xallocfwdump = 1;
99 module_param(ql2xallocfwdump, int, S_IRUGO);
100 MODULE_PARM_DESC(ql2xallocfwdump,
101 "Option to enable allocation of memory for a firmware dump "
102 "during HBA initialization. Memory allocation requirements "
103 "vary by ISP type. Default is 1 - allocate memory.");
105 int ql2xextended_error_logging;
106 module_param(ql2xextended_error_logging, int, S_IRUGO|S_IWUSR);
107 module_param_named(logging, ql2xextended_error_logging, int, S_IRUGO|S_IWUSR);
108 MODULE_PARM_DESC(ql2xextended_error_logging,
109 "Option to enable extended error logging,\n"
110 "\t\tDefault is 0 - no logging. 0x40000000 - Module Init & Probe.\n"
111 "\t\t0x20000000 - Mailbox Cmnds. 0x10000000 - Device Discovery.\n"
112 "\t\t0x08000000 - IO tracing. 0x04000000 - DPC Thread.\n"
113 "\t\t0x02000000 - Async events. 0x01000000 - Timer routines.\n"
114 "\t\t0x00800000 - User space. 0x00400000 - Task Management.\n"
115 "\t\t0x00200000 - AER/EEH. 0x00100000 - Multi Q.\n"
116 "\t\t0x00080000 - P3P Specific. 0x00040000 - Virtual Port.\n"
117 "\t\t0x00020000 - Buffer Dump. 0x00010000 - Misc.\n"
118 "\t\t0x00008000 - Verbose. 0x00004000 - Target.\n"
119 "\t\t0x00002000 - Target Mgmt. 0x00001000 - Target TMF.\n"
120 "\t\t0x7fffffff - For enabling all logs, can be too many logs.\n"
121 "\t\t0x1e400000 - Preferred value for capturing essential "
122 "debug information (equivalent to old "
123 "ql2xextended_error_logging=1).\n"
124 "\t\tDo LOGICAL OR of the value to enable more than one level");
126 int ql2xextended_error_logging_ktrace = 1;
127 module_param(ql2xextended_error_logging_ktrace, int, S_IRUGO|S_IWUSR);
128 MODULE_PARM_DESC(ql2xextended_error_logging_ktrace,
129 "Same BIT definition as ql2xextended_error_logging, but used to control logging to kernel trace buffer (default=1).\n");
131 int ql2xshiftctondsd = 6;
132 module_param(ql2xshiftctondsd, int, S_IRUGO);
133 MODULE_PARM_DESC(ql2xshiftctondsd,
134 "Set to control shifting of command type processing "
135 "based on total number of SG elements.");
137 int ql2xfdmienable = 1;
138 module_param(ql2xfdmienable, int, S_IRUGO|S_IWUSR);
139 module_param_named(fdmi, ql2xfdmienable, int, S_IRUGO|S_IWUSR);
140 MODULE_PARM_DESC(ql2xfdmienable,
141 "Enables FDMI registrations. "
142 "0 - no FDMI registrations. "
143 "1 - provide FDMI registrations (default).");
145 #define MAX_Q_DEPTH 64
146 static int ql2xmaxqdepth = MAX_Q_DEPTH;
147 module_param(ql2xmaxqdepth, int, S_IRUGO|S_IWUSR);
148 MODULE_PARM_DESC(ql2xmaxqdepth,
149 "Maximum queue depth to set for each LUN. "
152 int ql2xenabledif = 2;
153 module_param(ql2xenabledif, int, S_IRUGO);
154 MODULE_PARM_DESC(ql2xenabledif,
155 " Enable T10-CRC-DIF:\n"
157 " 0 -- No DIF Support\n"
158 " 1 -- Enable DIF for all types\n"
159 " 2 -- Enable DIF for all types, except Type 0.\n");
161 #if (IS_ENABLED(CONFIG_NVME_FC))
162 int ql2xnvmeenable = 1;
166 module_param(ql2xnvmeenable, int, 0644);
167 MODULE_PARM_DESC(ql2xnvmeenable,
168 "Enables NVME support. "
169 "0 - no NVMe. Default is Y");
171 int ql2xenablehba_err_chk = 2;
172 module_param(ql2xenablehba_err_chk, int, S_IRUGO|S_IWUSR);
173 MODULE_PARM_DESC(ql2xenablehba_err_chk,
174 " Enable T10-CRC-DIF Error isolation by HBA:\n"
176 " 0 -- Error isolation disabled\n"
177 " 1 -- Error isolation enabled only for DIX Type 0\n"
178 " 2 -- Error isolation enabled for all Types\n");
180 int ql2xiidmaenable = 1;
181 module_param(ql2xiidmaenable, int, S_IRUGO);
182 MODULE_PARM_DESC(ql2xiidmaenable,
183 "Enables iIDMA settings "
184 "Default is 1 - perform iIDMA. 0 - no iIDMA.");
186 int ql2xmqsupport = 1;
187 module_param(ql2xmqsupport, int, S_IRUGO);
188 MODULE_PARM_DESC(ql2xmqsupport,
189 "Enable on demand multiple queue pairs support "
190 "Default is 1 for supported. "
191 "Set it to 0 to turn off mq qpair support.");
194 module_param(ql2xfwloadbin, int, S_IRUGO|S_IWUSR);
195 module_param_named(fwload, ql2xfwloadbin, int, S_IRUGO|S_IWUSR);
196 MODULE_PARM_DESC(ql2xfwloadbin,
197 "Option to specify location from which to load ISP firmware:.\n"
198 " 2 -- load firmware via the request_firmware() (hotplug).\n"
200 " 1 -- load firmware from flash.\n"
201 " 0 -- use default semantics.\n");
204 module_param(ql2xetsenable, int, S_IRUGO);
205 MODULE_PARM_DESC(ql2xetsenable,
206 "Enables firmware ETS burst."
207 "Default is 0 - skip ETS enablement.");
210 module_param(ql2xdbwr, int, S_IRUGO|S_IWUSR);
211 MODULE_PARM_DESC(ql2xdbwr,
212 "Option to specify scheme for request queue posting.\n"
213 " 0 -- Regular doorbell.\n"
214 " 1 -- CAMRAM doorbell (faster).\n");
217 module_param(ql2xgffidenable, int, S_IRUGO);
218 MODULE_PARM_DESC(ql2xgffidenable,
219 "Enables GFF_ID checks of port type. "
220 "Default is 0 - Do not use GFF_ID information.");
222 int ql2xasynctmfenable = 1;
223 module_param(ql2xasynctmfenable, int, S_IRUGO);
224 MODULE_PARM_DESC(ql2xasynctmfenable,
225 "Enables issue of TM IOCBs asynchronously via IOCB mechanism"
226 "Default is 1 - Issue TM IOCBs via mailbox mechanism.");
228 int ql2xdontresethba;
229 module_param(ql2xdontresethba, int, S_IRUGO|S_IWUSR);
230 MODULE_PARM_DESC(ql2xdontresethba,
231 "Option to specify reset behaviour.\n"
232 " 0 (Default) -- Reset on failure.\n"
233 " 1 -- Do not reset on failure.\n");
235 uint64_t ql2xmaxlun = MAX_LUNS;
236 module_param(ql2xmaxlun, ullong, S_IRUGO);
237 MODULE_PARM_DESC(ql2xmaxlun,
238 "Defines the maximum LU number to register with the SCSI "
239 "midlayer. Default is 65535.");
241 int ql2xmdcapmask = 0x1F;
242 module_param(ql2xmdcapmask, int, S_IRUGO);
243 MODULE_PARM_DESC(ql2xmdcapmask,
244 "Set the Minidump driver capture mask level. "
245 "Default is 0x1F - Can be set to 0x3, 0x7, 0xF, 0x1F, 0x7F.");
247 int ql2xmdenable = 1;
248 module_param(ql2xmdenable, int, S_IRUGO);
249 MODULE_PARM_DESC(ql2xmdenable,
250 "Enable/disable MiniDump. "
251 "0 - MiniDump disabled. "
252 "1 (Default) - MiniDump enabled.");
255 module_param(ql2xexlogins, uint, S_IRUGO|S_IWUSR);
256 MODULE_PARM_DESC(ql2xexlogins,
257 "Number of extended Logins. "
258 "0 (Default)- Disabled.");
260 int ql2xexchoffld = 1024;
261 module_param(ql2xexchoffld, uint, 0644);
262 MODULE_PARM_DESC(ql2xexchoffld,
263 "Number of target exchanges.");
265 int ql2xiniexchg = 1024;
266 module_param(ql2xiniexchg, uint, 0644);
267 MODULE_PARM_DESC(ql2xiniexchg,
268 "Number of initiator exchanges.");
271 module_param(ql2xfwholdabts, int, S_IRUGO);
272 MODULE_PARM_DESC(ql2xfwholdabts,
273 "Allow FW to hold status IOCB until ABTS rsp received. "
274 "0 (Default) Do not set fw option. "
275 "1 - Set fw option to hold ABTS.");
277 int ql2xmvasynctoatio = 1;
278 module_param(ql2xmvasynctoatio, int, S_IRUGO|S_IWUSR);
279 MODULE_PARM_DESC(ql2xmvasynctoatio,
280 "Move PUREX, ABTS RX and RIDA IOCBs to ATIOQ"
281 "0 (Default). Do not move IOCBs"
284 int ql2xautodetectsfp = 1;
285 module_param(ql2xautodetectsfp, int, 0444);
286 MODULE_PARM_DESC(ql2xautodetectsfp,
287 "Detect SFP range and set appropriate distance.\n"
288 "1 (Default): Enable\n");
290 int ql2xenablemsix = 1;
291 module_param(ql2xenablemsix, int, 0444);
292 MODULE_PARM_DESC(ql2xenablemsix,
293 "Set to enable MSI or MSI-X interrupt mechanism.\n"
294 " Default is 1, enable MSI-X interrupt mechanism.\n"
295 " 0 -- enable traditional pin-based mechanism.\n"
296 " 1 -- enable MSI-X interrupt mechanism.\n"
297 " 2 -- enable MSI interrupt mechanism.\n");
299 int qla2xuseresexchforels;
300 module_param(qla2xuseresexchforels, int, 0444);
301 MODULE_PARM_DESC(qla2xuseresexchforels,
302 "Reserve 1/2 of emergency exchanges for ELS.\n"
303 " 0 (default): disabled");
305 static int ql2xprotmask;
306 module_param(ql2xprotmask, int, 0644);
307 MODULE_PARM_DESC(ql2xprotmask,
308 "Override DIF/DIX protection capabilities mask\n"
309 "Default is 0 which sets protection mask based on "
310 "capabilities reported by HBA firmware.\n");
312 static int ql2xprotguard;
313 module_param(ql2xprotguard, int, 0644);
314 MODULE_PARM_DESC(ql2xprotguard, "Override choice of DIX checksum\n"
315 " 0 -- Let HBA firmware decide\n"
316 " 1 -- Force T10 CRC\n"
317 " 2 -- Force IP checksum\n");
319 int ql2xdifbundlinginternalbuffers;
320 module_param(ql2xdifbundlinginternalbuffers, int, 0644);
321 MODULE_PARM_DESC(ql2xdifbundlinginternalbuffers,
322 "Force using internal buffers for DIF information\n"
323 "0 (Default). Based on check.\n"
324 "1 Force using internal buffers\n");
327 module_param(ql2xsmartsan, int, 0444);
328 module_param_named(smartsan, ql2xsmartsan, int, 0444);
329 MODULE_PARM_DESC(ql2xsmartsan,
330 "Send SmartSAN Management Attributes for FDMI Registration."
331 " Default is 0 - No SmartSAN registration,"
332 " 1 - Register SmartSAN Management Attributes.");
335 module_param(ql2xrdpenable, int, 0444);
336 module_param_named(rdpenable, ql2xrdpenable, int, 0444);
337 MODULE_PARM_DESC(ql2xrdpenable,
338 "Enables RDP responses. "
339 "0 - no RDP responses (default). "
340 "1 - provide RDP responses.");
341 int ql2xabts_wait_nvme = 1;
342 module_param(ql2xabts_wait_nvme, int, 0444);
343 MODULE_PARM_DESC(ql2xabts_wait_nvme,
344 "To wait for ABTS response on I/O timeouts for NVMe. (default: 1)");
347 static u32 ql2xdelay_before_pci_error_handling = 5;
348 module_param(ql2xdelay_before_pci_error_handling, uint, 0644);
349 MODULE_PARM_DESC(ql2xdelay_before_pci_error_handling,
350 "Number of seconds delayed before qla begin PCI error self-handling (default: 5).\n");
352 static void qla2x00_clear_drv_active(struct qla_hw_data *);
353 static void qla2x00_free_device(scsi_qla_host_t *);
354 static void qla2xxx_map_queues(struct Scsi_Host *shost);
355 static void qla2x00_destroy_deferred_work(struct qla_hw_data *);
357 u32 ql2xnvme_queues = DEF_NVME_HW_QUEUES;
358 module_param(ql2xnvme_queues, uint, S_IRUGO);
359 MODULE_PARM_DESC(ql2xnvme_queues,
360 "Number of NVMe Queues that can be configured.\n"
361 "Final value will be min(ql2xnvme_queues, num_cpus,num_chip_queues)\n"
362 "1 - Minimum number of queues supported\n"
363 "8 - Default value");
365 int ql2xfc2target = 1;
366 module_param(ql2xfc2target, int, 0444);
367 MODULE_PARM_DESC(qla2xfc2target,
368 "Enables FC2 Target support. "
369 "0 - FC2 Target support is disabled. "
370 "1 - FC2 Target support is enabled (default).");
372 static struct scsi_transport_template *qla2xxx_transport_template = NULL;
373 struct scsi_transport_template *qla2xxx_transport_vport_template = NULL;
375 /* TODO Convert to inlines
381 qla2x00_start_timer(scsi_qla_host_t *vha, unsigned long interval)
383 timer_setup(&vha->timer, qla2x00_timer, 0);
384 vha->timer.expires = jiffies + interval * HZ;
385 add_timer(&vha->timer);
386 vha->timer_active = 1;
390 qla2x00_restart_timer(scsi_qla_host_t *vha, unsigned long interval)
392 /* Currently used for 82XX only. */
393 if (vha->device_flags & DFLG_DEV_FAILED) {
394 ql_dbg(ql_dbg_timer, vha, 0x600d,
395 "Device in a failed state, returning.\n");
399 mod_timer(&vha->timer, jiffies + interval * HZ);
402 static __inline__ void
403 qla2x00_stop_timer(scsi_qla_host_t *vha)
405 del_timer_sync(&vha->timer);
406 vha->timer_active = 0;
409 static int qla2x00_do_dpc(void *data);
411 static void qla2x00_rst_aen(scsi_qla_host_t *);
413 static int qla2x00_mem_alloc(struct qla_hw_data *, uint16_t, uint16_t,
414 struct req_que **, struct rsp_que **);
415 static void qla2x00_free_fw_dump(struct qla_hw_data *);
416 static void qla2x00_mem_free(struct qla_hw_data *);
417 int qla2xxx_mqueuecommand(struct Scsi_Host *host, struct scsi_cmnd *cmd,
418 struct qla_qpair *qpair);
420 /* -------------------------------------------------------------------------- */
421 static void qla_init_base_qpair(struct scsi_qla_host *vha, struct req_que *req,
424 struct qla_hw_data *ha = vha->hw;
426 rsp->qpair = ha->base_qpair;
428 ha->base_qpair->hw = ha;
429 ha->base_qpair->req = req;
430 ha->base_qpair->rsp = rsp;
431 ha->base_qpair->vha = vha;
432 ha->base_qpair->qp_lock_ptr = &ha->hardware_lock;
433 ha->base_qpair->use_shadow_reg = IS_SHADOW_REG_CAPABLE(ha) ? 1 : 0;
434 ha->base_qpair->msix = &ha->msix_entries[QLA_MSIX_RSP_Q];
435 ha->base_qpair->srb_mempool = ha->srb_mempool;
436 INIT_LIST_HEAD(&ha->base_qpair->hints_list);
437 INIT_LIST_HEAD(&ha->base_qpair->dsd_list);
438 ha->base_qpair->enable_class_2 = ql2xenableclass2;
439 /* init qpair to this cpu. Will adjust at run time. */
440 qla_cpu_update(rsp->qpair, raw_smp_processor_id());
441 ha->base_qpair->pdev = ha->pdev;
443 if (IS_QLA27XX(ha) || IS_QLA83XX(ha) || IS_QLA28XX(ha))
444 ha->base_qpair->reqq_start_iocbs = qla_83xx_start_iocbs;
447 static int qla2x00_alloc_queues(struct qla_hw_data *ha, struct req_que *req,
450 scsi_qla_host_t *vha = pci_get_drvdata(ha->pdev);
452 ha->req_q_map = kcalloc(ha->max_req_queues, sizeof(struct req_que *),
454 if (!ha->req_q_map) {
455 ql_log(ql_log_fatal, vha, 0x003b,
456 "Unable to allocate memory for request queue ptrs.\n");
460 ha->rsp_q_map = kcalloc(ha->max_rsp_queues, sizeof(struct rsp_que *),
462 if (!ha->rsp_q_map) {
463 ql_log(ql_log_fatal, vha, 0x003c,
464 "Unable to allocate memory for response queue ptrs.\n");
468 ha->base_qpair = kzalloc(sizeof(struct qla_qpair), GFP_KERNEL);
469 if (ha->base_qpair == NULL) {
470 ql_log(ql_log_warn, vha, 0x00e0,
471 "Failed to allocate base queue pair memory.\n");
472 goto fail_base_qpair;
475 qla_init_base_qpair(vha, req, rsp);
477 if ((ql2xmqsupport || ql2xnvmeenable) && ha->max_qpairs) {
478 ha->queue_pair_map = kcalloc(ha->max_qpairs, sizeof(struct qla_qpair *),
480 if (!ha->queue_pair_map) {
481 ql_log(ql_log_fatal, vha, 0x0180,
482 "Unable to allocate memory for queue pair ptrs.\n");
485 if (qla_mapq_alloc_qp_cpu_map(ha) != 0) {
486 kfree(ha->queue_pair_map);
487 ha->queue_pair_map = NULL;
493 * Make sure we record at least the request and response queue zero in
494 * case we need to free them if part of the probe fails.
496 ha->rsp_q_map[0] = rsp;
497 ha->req_q_map[0] = req;
498 set_bit(0, ha->rsp_qid_map);
499 set_bit(0, ha->req_qid_map);
503 kfree(ha->base_qpair);
504 ha->base_qpair = NULL;
506 kfree(ha->rsp_q_map);
507 ha->rsp_q_map = NULL;
509 kfree(ha->req_q_map);
510 ha->req_q_map = NULL;
515 static void qla2x00_free_req_que(struct qla_hw_data *ha, struct req_que *req)
517 if (IS_QLAFX00(ha)) {
518 if (req && req->ring_fx00)
519 dma_free_coherent(&ha->pdev->dev,
520 (req->length_fx00 + 1) * sizeof(request_t),
521 req->ring_fx00, req->dma_fx00);
522 } else if (req && req->ring)
523 dma_free_coherent(&ha->pdev->dev,
524 (req->length + 1) * sizeof(request_t),
525 req->ring, req->dma);
528 kfree(req->outstanding_cmds);
533 static void qla2x00_free_rsp_que(struct qla_hw_data *ha, struct rsp_que *rsp)
535 if (IS_QLAFX00(ha)) {
536 if (rsp && rsp->ring_fx00)
537 dma_free_coherent(&ha->pdev->dev,
538 (rsp->length_fx00 + 1) * sizeof(request_t),
539 rsp->ring_fx00, rsp->dma_fx00);
540 } else if (rsp && rsp->ring) {
541 dma_free_coherent(&ha->pdev->dev,
542 (rsp->length + 1) * sizeof(response_t),
543 rsp->ring, rsp->dma);
548 static void qla2x00_free_queues(struct qla_hw_data *ha)
555 if (ha->queue_pair_map) {
556 kfree(ha->queue_pair_map);
557 ha->queue_pair_map = NULL;
559 if (ha->base_qpair) {
560 kfree(ha->base_qpair);
561 ha->base_qpair = NULL;
564 qla_mapq_free_qp_cpu_map(ha);
565 spin_lock_irqsave(&ha->hardware_lock, flags);
566 for (cnt = 0; cnt < ha->max_req_queues; cnt++) {
567 if (!test_bit(cnt, ha->req_qid_map))
570 req = ha->req_q_map[cnt];
571 clear_bit(cnt, ha->req_qid_map);
572 ha->req_q_map[cnt] = NULL;
574 spin_unlock_irqrestore(&ha->hardware_lock, flags);
575 qla2x00_free_req_que(ha, req);
576 spin_lock_irqsave(&ha->hardware_lock, flags);
578 spin_unlock_irqrestore(&ha->hardware_lock, flags);
580 kfree(ha->req_q_map);
581 ha->req_q_map = NULL;
584 spin_lock_irqsave(&ha->hardware_lock, flags);
585 for (cnt = 0; cnt < ha->max_rsp_queues; cnt++) {
586 if (!test_bit(cnt, ha->rsp_qid_map))
589 rsp = ha->rsp_q_map[cnt];
590 clear_bit(cnt, ha->rsp_qid_map);
591 ha->rsp_q_map[cnt] = NULL;
592 spin_unlock_irqrestore(&ha->hardware_lock, flags);
593 qla2x00_free_rsp_que(ha, rsp);
594 spin_lock_irqsave(&ha->hardware_lock, flags);
596 spin_unlock_irqrestore(&ha->hardware_lock, flags);
598 kfree(ha->rsp_q_map);
599 ha->rsp_q_map = NULL;
603 qla2x00_pci_info_str(struct scsi_qla_host *vha, char *str, size_t str_len)
605 struct qla_hw_data *ha = vha->hw;
606 static const char *const pci_bus_modes[] = {
607 "33", "66", "100", "133",
611 pci_bus = (ha->pci_attr & (BIT_9 | BIT_10)) >> 9;
613 snprintf(str, str_len, "PCI-X (%s MHz)",
614 pci_bus_modes[pci_bus]);
616 pci_bus = (ha->pci_attr & BIT_8) >> 8;
617 snprintf(str, str_len, "PCI (%s MHz)", pci_bus_modes[pci_bus]);
624 qla24xx_pci_info_str(struct scsi_qla_host *vha, char *str, size_t str_len)
626 static const char *const pci_bus_modes[] = {
627 "33", "66", "100", "133",
629 struct qla_hw_data *ha = vha->hw;
632 if (pci_is_pcie(ha->pdev)) {
633 uint32_t lstat, lspeed, lwidth;
634 const char *speed_str;
636 pcie_capability_read_dword(ha->pdev, PCI_EXP_LNKCAP, &lstat);
637 lspeed = FIELD_GET(PCI_EXP_LNKCAP_SLS, lstat);
638 lwidth = FIELD_GET(PCI_EXP_LNKCAP_MLW, lstat);
642 speed_str = "2.5GT/s";
645 speed_str = "5.0GT/s";
648 speed_str = "8.0GT/s";
651 speed_str = "16.0GT/s";
654 speed_str = "<unknown>";
657 snprintf(str, str_len, "PCIe (%s x%d)", speed_str, lwidth);
662 pci_bus = (ha->pci_attr & CSRX_PCIX_BUS_MODE_MASK) >> 8;
663 if (pci_bus == 0 || pci_bus == 8)
664 snprintf(str, str_len, "PCI (%s MHz)",
665 pci_bus_modes[pci_bus >> 3]);
667 snprintf(str, str_len, "PCI-X Mode %d (%s MHz)",
669 pci_bus_modes[pci_bus & 3]);
675 qla2x00_fw_version_str(struct scsi_qla_host *vha, char *str, size_t size)
678 struct qla_hw_data *ha = vha->hw;
680 snprintf(str, size, "%d.%02d.%02d ", ha->fw_major_version,
681 ha->fw_minor_version, ha->fw_subminor_version);
683 if (ha->fw_attributes & BIT_9) {
688 switch (ha->fw_attributes & 0xFF) {
702 sprintf(un_str, "(%x)", ha->fw_attributes);
706 if (ha->fw_attributes & 0x100)
713 qla24xx_fw_version_str(struct scsi_qla_host *vha, char *str, size_t size)
715 struct qla_hw_data *ha = vha->hw;
717 snprintf(str, size, "%d.%02d.%02d (%x)", ha->fw_major_version,
718 ha->fw_minor_version, ha->fw_subminor_version, ha->fw_attributes);
722 void qla2x00_sp_free_dma(srb_t *sp)
724 struct qla_hw_data *ha = sp->vha->hw;
725 struct scsi_cmnd *cmd = GET_CMD_SP(sp);
727 if (sp->flags & SRB_DMA_VALID) {
729 sp->flags &= ~SRB_DMA_VALID;
732 if (sp->flags & SRB_CRC_PROT_DMA_VALID) {
733 dma_unmap_sg(&ha->pdev->dev, scsi_prot_sglist(cmd),
734 scsi_prot_sg_count(cmd), cmd->sc_data_direction);
735 sp->flags &= ~SRB_CRC_PROT_DMA_VALID;
738 if (sp->flags & SRB_CRC_CTX_DSD_VALID) {
739 /* List assured to be having elements */
740 qla2x00_clean_dsd_pool(ha, sp->u.scmd.crc_ctx);
741 sp->flags &= ~SRB_CRC_CTX_DSD_VALID;
744 if (sp->flags & SRB_CRC_CTX_DMA_VALID) {
745 struct crc_context *ctx0 = sp->u.scmd.crc_ctx;
747 dma_pool_free(ha->dl_dma_pool, ctx0, ctx0->crc_ctx_dma);
748 sp->flags &= ~SRB_CRC_CTX_DMA_VALID;
751 if (sp->flags & SRB_FCP_CMND_DMA_VALID) {
752 struct ct6_dsd *ctx1 = &sp->u.scmd.ct6_ctx;
754 dma_pool_free(ha->fcp_cmnd_dma_pool, ctx1->fcp_cmnd,
756 list_splice(&ctx1->dsd_list, &sp->qpair->dsd_list);
757 sp->qpair->dsd_inuse -= ctx1->dsd_use_cnt;
758 sp->qpair->dsd_avail += ctx1->dsd_use_cnt;
761 if (sp->flags & SRB_GOT_BUF)
762 qla_put_buf(sp->qpair, &sp->u.scmd.buf_dsc);
765 void qla2x00_sp_compl(srb_t *sp, int res)
767 struct scsi_cmnd *cmd = GET_CMD_SP(sp);
768 struct completion *comp = sp->comp;
771 kref_put(&sp->cmd_kref, qla2x00_sp_release);
779 void qla2xxx_qpair_sp_free_dma(srb_t *sp)
781 struct scsi_cmnd *cmd = GET_CMD_SP(sp);
782 struct qla_hw_data *ha = sp->fcport->vha->hw;
784 if (sp->flags & SRB_DMA_VALID) {
786 sp->flags &= ~SRB_DMA_VALID;
789 if (sp->flags & SRB_CRC_PROT_DMA_VALID) {
790 dma_unmap_sg(&ha->pdev->dev, scsi_prot_sglist(cmd),
791 scsi_prot_sg_count(cmd), cmd->sc_data_direction);
792 sp->flags &= ~SRB_CRC_PROT_DMA_VALID;
795 if (sp->flags & SRB_CRC_CTX_DSD_VALID) {
796 /* List assured to be having elements */
797 qla2x00_clean_dsd_pool(ha, sp->u.scmd.crc_ctx);
798 sp->flags &= ~SRB_CRC_CTX_DSD_VALID;
801 if (sp->flags & SRB_DIF_BUNDL_DMA_VALID) {
802 struct crc_context *difctx = sp->u.scmd.crc_ctx;
803 struct dsd_dma *dif_dsd, *nxt_dsd;
805 list_for_each_entry_safe(dif_dsd, nxt_dsd,
806 &difctx->ldif_dma_hndl_list, list) {
807 list_del(&dif_dsd->list);
808 dma_pool_free(ha->dif_bundl_pool, dif_dsd->dsd_addr,
809 dif_dsd->dsd_list_dma);
811 difctx->no_dif_bundl--;
814 list_for_each_entry_safe(dif_dsd, nxt_dsd,
815 &difctx->ldif_dsd_list, list) {
816 list_del(&dif_dsd->list);
817 dma_pool_free(ha->dl_dma_pool, dif_dsd->dsd_addr,
818 dif_dsd->dsd_list_dma);
820 difctx->no_ldif_dsd--;
823 if (difctx->no_ldif_dsd) {
824 ql_dbg(ql_dbg_tgt+ql_dbg_verbose, sp->vha, 0xe022,
825 "%s: difctx->no_ldif_dsd=%x\n",
826 __func__, difctx->no_ldif_dsd);
829 if (difctx->no_dif_bundl) {
830 ql_dbg(ql_dbg_tgt+ql_dbg_verbose, sp->vha, 0xe022,
831 "%s: difctx->no_dif_bundl=%x\n",
832 __func__, difctx->no_dif_bundl);
834 sp->flags &= ~SRB_DIF_BUNDL_DMA_VALID;
837 if (sp->flags & SRB_FCP_CMND_DMA_VALID) {
838 struct ct6_dsd *ctx1 = &sp->u.scmd.ct6_ctx;
840 dma_pool_free(ha->fcp_cmnd_dma_pool, ctx1->fcp_cmnd,
842 list_splice(&ctx1->dsd_list, &sp->qpair->dsd_list);
843 sp->qpair->dsd_inuse -= ctx1->dsd_use_cnt;
844 sp->qpair->dsd_avail += ctx1->dsd_use_cnt;
845 sp->flags &= ~SRB_FCP_CMND_DMA_VALID;
848 if (sp->flags & SRB_CRC_CTX_DMA_VALID) {
849 struct crc_context *ctx0 = sp->u.scmd.crc_ctx;
851 dma_pool_free(ha->dl_dma_pool, ctx0, ctx0->crc_ctx_dma);
852 sp->flags &= ~SRB_CRC_CTX_DMA_VALID;
855 if (sp->flags & SRB_GOT_BUF)
856 qla_put_buf(sp->qpair, &sp->u.scmd.buf_dsc);
859 void qla2xxx_qpair_sp_compl(srb_t *sp, int res)
861 struct scsi_cmnd *cmd = GET_CMD_SP(sp);
862 struct completion *comp = sp->comp;
865 kref_put(&sp->cmd_kref, qla2x00_sp_release);
874 qla2xxx_queuecommand(struct Scsi_Host *host, struct scsi_cmnd *cmd)
876 scsi_qla_host_t *vha = shost_priv(host);
877 fc_port_t *fcport = (struct fc_port *) cmd->device->hostdata;
878 struct fc_rport *rport = starget_to_rport(scsi_target(cmd->device));
879 struct qla_hw_data *ha = vha->hw;
880 struct scsi_qla_host *base_vha = pci_get_drvdata(ha->pdev);
884 if (unlikely(test_bit(UNLOADING, &base_vha->dpc_flags)) ||
885 WARN_ON_ONCE(!rport)) {
886 cmd->result = DID_NO_CONNECT << 16;
887 goto qc24_fail_command;
893 struct qla_qpair *qpair = NULL;
895 tag = blk_mq_unique_tag(scsi_cmd_to_rq(cmd));
896 hwq = blk_mq_unique_tag_to_hwq(tag);
897 qpair = ha->queue_pair_map[hwq];
900 return qla2xxx_mqueuecommand(host, cmd, qpair);
903 if (ha->flags.eeh_busy) {
904 if (ha->flags.pci_channel_io_perm_failure) {
905 ql_dbg(ql_dbg_aer, vha, 0x9010,
906 "PCI Channel IO permanent failure, exiting "
908 cmd->result = DID_NO_CONNECT << 16;
910 ql_dbg(ql_dbg_aer, vha, 0x9011,
911 "EEH_Busy, Requeuing the cmd=%p.\n", cmd);
912 cmd->result = DID_REQUEUE << 16;
914 goto qc24_fail_command;
917 rval = fc_remote_port_chkready(rport);
920 ql_dbg(ql_dbg_io + ql_dbg_verbose, vha, 0x3003,
921 "fc_remote_port_chkready failed for cmd=%p, rval=0x%x.\n",
923 goto qc24_fail_command;
926 if (!vha->flags.difdix_supported &&
927 scsi_get_prot_op(cmd) != SCSI_PROT_NORMAL) {
928 ql_dbg(ql_dbg_io, vha, 0x3004,
929 "DIF Cap not reg, fail DIF capable cmd's:%p.\n",
931 cmd->result = DID_NO_CONNECT << 16;
932 goto qc24_fail_command;
935 if (!fcport || fcport->deleted) {
936 cmd->result = DID_IMM_RETRY << 16;
937 goto qc24_fail_command;
940 if (atomic_read(&fcport->state) != FCS_ONLINE || fcport->deleted) {
941 if (atomic_read(&fcport->state) == FCS_DEVICE_DEAD ||
942 atomic_read(&base_vha->loop_state) == LOOP_DEAD) {
943 ql_dbg(ql_dbg_io, vha, 0x3005,
944 "Returning DNC, fcport_state=%d loop_state=%d.\n",
945 atomic_read(&fcport->state),
946 atomic_read(&base_vha->loop_state));
947 cmd->result = DID_NO_CONNECT << 16;
948 goto qc24_fail_command;
950 goto qc24_target_busy;
954 * Return target busy if we've received a non-zero retry_delay_timer
957 if (fcport->retry_delay_timestamp == 0) {
958 /* retry delay not set */
959 } else if (time_after(jiffies, fcport->retry_delay_timestamp))
960 fcport->retry_delay_timestamp = 0;
962 goto qc24_target_busy;
964 sp = scsi_cmd_priv(cmd);
966 qla2xxx_init_sp(sp, vha, vha->hw->base_qpair, fcport);
968 sp->u.scmd.cmd = cmd;
969 sp->type = SRB_SCSI_CMD;
970 sp->free = qla2x00_sp_free_dma;
971 sp->done = qla2x00_sp_compl;
973 rval = ha->isp_ops->start_scsi(sp);
974 if (rval != QLA_SUCCESS) {
975 ql_dbg(ql_dbg_io + ql_dbg_verbose, vha, 0x3013,
976 "Start scsi failed rval=%d for cmd=%p.\n", rval, cmd);
977 goto qc24_host_busy_free_sp;
982 qc24_host_busy_free_sp:
984 kref_put(&sp->cmd_kref, qla2x00_sp_release);
987 return SCSI_MLQUEUE_TARGET_BUSY;
995 /* For MQ supported I/O */
997 qla2xxx_mqueuecommand(struct Scsi_Host *host, struct scsi_cmnd *cmd,
998 struct qla_qpair *qpair)
1000 scsi_qla_host_t *vha = shost_priv(host);
1001 fc_port_t *fcport = (struct fc_port *) cmd->device->hostdata;
1002 struct fc_rport *rport = starget_to_rport(scsi_target(cmd->device));
1003 struct qla_hw_data *ha = vha->hw;
1004 struct scsi_qla_host *base_vha = pci_get_drvdata(ha->pdev);
1008 rval = rport ? fc_remote_port_chkready(rport) : (DID_NO_CONNECT << 16);
1011 ql_dbg(ql_dbg_io + ql_dbg_verbose, vha, 0x3076,
1012 "fc_remote_port_chkready failed for cmd=%p, rval=0x%x.\n",
1014 goto qc24_fail_command;
1017 if (!qpair->online) {
1018 ql_dbg(ql_dbg_io, vha, 0x3077,
1019 "qpair not online. eeh_busy=%d.\n", ha->flags.eeh_busy);
1020 cmd->result = DID_NO_CONNECT << 16;
1021 goto qc24_fail_command;
1024 if (!fcport || fcport->deleted) {
1025 cmd->result = DID_IMM_RETRY << 16;
1026 goto qc24_fail_command;
1029 if (atomic_read(&fcport->state) != FCS_ONLINE || fcport->deleted) {
1030 if (atomic_read(&fcport->state) == FCS_DEVICE_DEAD ||
1031 atomic_read(&base_vha->loop_state) == LOOP_DEAD) {
1032 ql_dbg(ql_dbg_io, vha, 0x3077,
1033 "Returning DNC, fcport_state=%d loop_state=%d.\n",
1034 atomic_read(&fcport->state),
1035 atomic_read(&base_vha->loop_state));
1036 cmd->result = DID_NO_CONNECT << 16;
1037 goto qc24_fail_command;
1039 goto qc24_target_busy;
1043 * Return target busy if we've received a non-zero retry_delay_timer
1046 if (fcport->retry_delay_timestamp == 0) {
1047 /* retry delay not set */
1048 } else if (time_after(jiffies, fcport->retry_delay_timestamp))
1049 fcport->retry_delay_timestamp = 0;
1051 goto qc24_target_busy;
1053 sp = scsi_cmd_priv(cmd);
1055 qla2xxx_init_sp(sp, vha, qpair, fcport);
1057 sp->u.scmd.cmd = cmd;
1058 sp->type = SRB_SCSI_CMD;
1059 sp->free = qla2xxx_qpair_sp_free_dma;
1060 sp->done = qla2xxx_qpair_sp_compl;
1062 rval = ha->isp_ops->start_scsi_mq(sp);
1063 if (rval != QLA_SUCCESS) {
1064 ql_dbg(ql_dbg_io + ql_dbg_verbose, vha, 0x3078,
1065 "Start scsi failed rval=%d for cmd=%p.\n", rval, cmd);
1066 goto qc24_host_busy_free_sp;
1071 qc24_host_busy_free_sp:
1073 kref_put(&sp->cmd_kref, qla2x00_sp_release);
1076 return SCSI_MLQUEUE_TARGET_BUSY;
1085 * qla2x00_wait_for_hba_online
1086 * Wait till the HBA is online after going through
1087 * <= MAX_RETRIES_OF_ISP_ABORT or
1088 * finally HBA is disabled ie marked offline
1091 * ha - pointer to host adapter structure
1094 * Does context switching-Release SPIN_LOCK
1095 * (if any) before calling this routine.
1098 * Success (Adapter is online) : 0
1099 * Failed (Adapter is offline/disabled) : 1
1102 qla2x00_wait_for_hba_online(scsi_qla_host_t *vha)
1105 unsigned long wait_online;
1106 struct qla_hw_data *ha = vha->hw;
1107 scsi_qla_host_t *base_vha = pci_get_drvdata(ha->pdev);
1109 wait_online = jiffies + (MAX_LOOP_TIMEOUT * HZ);
1110 while (((test_bit(ISP_ABORT_NEEDED, &base_vha->dpc_flags)) ||
1111 test_bit(ABORT_ISP_ACTIVE, &base_vha->dpc_flags) ||
1112 test_bit(ISP_ABORT_RETRY, &base_vha->dpc_flags) ||
1113 ha->dpc_active) && time_before(jiffies, wait_online)) {
1117 if (base_vha->flags.online)
1118 return_status = QLA_SUCCESS;
1120 return_status = QLA_FUNCTION_FAILED;
1122 return (return_status);
1125 static inline int test_fcport_count(scsi_qla_host_t *vha)
1127 struct qla_hw_data *ha = vha->hw;
1128 unsigned long flags;
1130 /* Return 0 = sleep, x=wake */
1132 spin_lock_irqsave(&ha->tgt.sess_lock, flags);
1133 ql_dbg(ql_dbg_init, vha, 0x00ec,
1134 "tgt %p, fcport_count=%d\n",
1135 vha, vha->fcport_count);
1136 res = (vha->fcport_count == 0);
1138 struct fc_port *fcport;
1140 list_for_each_entry(fcport, &vha->vp_fcports, list) {
1141 if (fcport->deleted != QLA_SESS_DELETED) {
1142 /* session(s) may not be fully logged in
1143 * (ie fcport_count=0), but session
1144 * deletion thread(s) may be inflight.
1152 spin_unlock_irqrestore(&ha->tgt.sess_lock, flags);
1158 * qla2x00_wait_for_sess_deletion can only be called from remove_one.
1159 * it has dependency on UNLOADING flag to stop device discovery
1162 qla2x00_wait_for_sess_deletion(scsi_qla_host_t *vha)
1166 qla2x00_mark_all_devices_lost(vha);
1168 for (i = 0; i < 10; i++) {
1169 if (wait_event_timeout(vha->fcport_waitQ,
1170 test_fcport_count(vha), HZ) > 0)
1174 flush_workqueue(vha->hw->wq);
1178 * qla2x00_wait_for_hba_ready
1179 * Wait till the HBA is ready before doing driver unload
1182 * ha - pointer to host adapter structure
1185 * Does context switching-Release SPIN_LOCK
1186 * (if any) before calling this routine.
1190 qla2x00_wait_for_hba_ready(scsi_qla_host_t *vha)
1192 struct qla_hw_data *ha = vha->hw;
1193 scsi_qla_host_t *base_vha = pci_get_drvdata(ha->pdev);
1195 while ((qla2x00_reset_active(vha) || ha->dpc_active ||
1196 ha->flags.mbox_busy) ||
1197 test_bit(FX00_RESET_RECOVERY, &vha->dpc_flags) ||
1198 test_bit(FX00_TARGET_SCAN, &vha->dpc_flags)) {
1199 if (test_bit(UNLOADING, &base_vha->dpc_flags))
1206 qla2x00_wait_for_chip_reset(scsi_qla_host_t *vha)
1209 unsigned long wait_reset;
1210 struct qla_hw_data *ha = vha->hw;
1211 scsi_qla_host_t *base_vha = pci_get_drvdata(ha->pdev);
1213 wait_reset = jiffies + (MAX_LOOP_TIMEOUT * HZ);
1214 while (((test_bit(ISP_ABORT_NEEDED, &base_vha->dpc_flags)) ||
1215 test_bit(ABORT_ISP_ACTIVE, &base_vha->dpc_flags) ||
1216 test_bit(ISP_ABORT_RETRY, &base_vha->dpc_flags) ||
1217 ha->dpc_active) && time_before(jiffies, wait_reset)) {
1221 if (!test_bit(ISP_ABORT_NEEDED, &base_vha->dpc_flags) &&
1222 ha->flags.chip_reset_done)
1225 if (ha->flags.chip_reset_done)
1226 return_status = QLA_SUCCESS;
1228 return_status = QLA_FUNCTION_FAILED;
1230 return return_status;
1233 /**************************************************************************
1237 * The abort function will abort the specified command.
1240 * cmd = Linux SCSI command packet to be aborted.
1243 * Either SUCCESS or FAILED.
1246 * Only return FAILED if command not returned by firmware.
1247 **************************************************************************/
1249 qla2xxx_eh_abort(struct scsi_cmnd *cmd)
1251 scsi_qla_host_t *vha = shost_priv(cmd->device->host);
1252 DECLARE_COMPLETION_ONSTACK(comp);
1258 struct qla_hw_data *ha = vha->hw;
1260 struct qla_qpair *qpair;
1261 unsigned long flags;
1262 int fast_fail_status = SUCCESS;
1264 if (qla2x00_isp_reg_stat(ha)) {
1265 ql_log(ql_log_info, vha, 0x8042,
1266 "PCI/Register disconnect, exiting.\n");
1267 qla_pci_set_eeh_busy(vha);
1271 /* Save any FAST_IO_FAIL value to return later if abort succeeds */
1272 ret = fc_block_scsi_eh(cmd);
1274 fast_fail_status = ret;
1276 sp = scsi_cmd_priv(cmd);
1279 vha->cmd_timeout_cnt++;
1281 if ((sp->fcport && sp->fcport->deleted) || !qpair)
1282 return fast_fail_status != SUCCESS ? fast_fail_status : FAILED;
1284 spin_lock_irqsave(qpair->qp_lock_ptr, flags);
1286 spin_unlock_irqrestore(qpair->qp_lock_ptr, flags);
1289 id = cmd->device->id;
1290 lun = cmd->device->lun;
1292 ql_dbg(ql_dbg_taskm, vha, 0x8002,
1293 "Aborting from RISC nexus=%ld:%d:%llu sp=%p cmd=%p handle=%x\n",
1294 vha->host_no, id, lun, sp, cmd, sp->handle);
1297 * Abort will release the original Command/sp from FW. Let the
1298 * original command call scsi_done. In return, he will wakeup
1299 * this sleeping thread.
1301 rval = ha->isp_ops->abort_command(sp);
1303 ql_dbg(ql_dbg_taskm, vha, 0x8003,
1304 "Abort command mbx cmd=%p, rval=%x.\n", cmd, rval);
1306 /* Wait for the command completion. */
1307 ratov_j = ha->r_a_tov/10 * 4 * 1000;
1308 ratov_j = msecs_to_jiffies(ratov_j);
1311 if (!wait_for_completion_timeout(&comp, ratov_j)) {
1312 ql_dbg(ql_dbg_taskm, vha, 0xffff,
1313 "%s: Abort wait timer (4 * R_A_TOV[%d]) expired\n",
1314 __func__, ha->r_a_tov/10);
1317 ret = fast_fail_status;
1327 ql_log(ql_log_info, vha, 0x801c,
1328 "Abort command issued nexus=%ld:%d:%llu -- %x.\n",
1329 vha->host_no, id, lun, ret);
1334 #define ABORT_POLLING_PERIOD 1000
1335 #define ABORT_WAIT_ITER ((2 * 1000) / (ABORT_POLLING_PERIOD))
1338 * Returns: QLA_SUCCESS or QLA_FUNCTION_FAILED.
1341 __qla2x00_eh_wait_for_pending_commands(struct qla_qpair *qpair, unsigned int t,
1342 uint64_t l, enum nexus_wait_type type)
1344 int cnt, match, status;
1345 unsigned long flags;
1346 scsi_qla_host_t *vha = qpair->vha;
1347 struct req_que *req = qpair->req;
1349 struct scsi_cmnd *cmd;
1350 unsigned long wait_iter = ABORT_WAIT_ITER;
1352 struct qla_hw_data *ha = vha->hw;
1354 status = QLA_SUCCESS;
1356 while (wait_iter--) {
1359 spin_lock_irqsave(qpair->qp_lock_ptr, flags);
1360 for (cnt = 1; cnt < req->num_outstanding_cmds; cnt++) {
1361 sp = req->outstanding_cmds[cnt];
1364 if (sp->type != SRB_SCSI_CMD)
1366 if (vha->vp_idx != sp->vha->vp_idx)
1369 cmd = GET_CMD_SP(sp);
1376 match = sp->fcport->d_id.b24 == t;
1382 match = (sp->fcport->d_id.b24 == t &&
1383 cmd->device->lun == l);
1391 spin_unlock_irqrestore(qpair->qp_lock_ptr, flags);
1393 if (unlikely(pci_channel_offline(ha->pdev)) ||
1394 ha->flags.eeh_busy) {
1395 ql_dbg(ql_dbg_taskm, vha, 0x8005,
1396 "Return:eh_wait.\n");
1401 * SRB_SCSI_CMD is still in the outstanding_cmds array.
1402 * it means scsi_done has not called. Wait for it to
1403 * clear from outstanding_cmds.
1405 msleep(ABORT_POLLING_PERIOD);
1406 spin_lock_irqsave(qpair->qp_lock_ptr, flags);
1409 spin_unlock_irqrestore(qpair->qp_lock_ptr, flags);
1415 if (wait_iter == -1)
1416 status = QLA_FUNCTION_FAILED;
1422 qla2x00_eh_wait_for_pending_commands(scsi_qla_host_t *vha, unsigned int t,
1423 uint64_t l, enum nexus_wait_type type)
1425 struct qla_qpair *qpair;
1426 struct qla_hw_data *ha = vha->hw;
1427 int i, status = QLA_SUCCESS;
1429 status = __qla2x00_eh_wait_for_pending_commands(ha->base_qpair, t, l,
1431 for (i = 0; status == QLA_SUCCESS && i < ha->max_qpairs; i++) {
1432 qpair = ha->queue_pair_map[i];
1435 status = __qla2x00_eh_wait_for_pending_commands(qpair, t, l,
1441 static char *reset_errors[] = {
1444 "Task management failed",
1445 "Waiting for command completions",
1449 qla2xxx_eh_device_reset(struct scsi_cmnd *cmd)
1451 struct scsi_device *sdev = cmd->device;
1452 scsi_qla_host_t *vha = shost_priv(sdev->host);
1453 struct fc_rport *rport = starget_to_rport(scsi_target(sdev));
1454 fc_port_t *fcport = (struct fc_port *) sdev->hostdata;
1455 struct qla_hw_data *ha = vha->hw;
1458 if (qla2x00_isp_reg_stat(ha)) {
1459 ql_log(ql_log_info, vha, 0x803e,
1460 "PCI/Register disconnect, exiting.\n");
1461 qla_pci_set_eeh_busy(vha);
1469 err = fc_block_rport(rport);
1473 if (fcport->deleted)
1476 ql_log(ql_log_info, vha, 0x8009,
1477 "DEVICE RESET ISSUED nexus=%ld:%d:%llu cmd=%p.\n", vha->host_no,
1478 sdev->id, sdev->lun, cmd);
1481 if (qla2x00_wait_for_hba_online(vha) != QLA_SUCCESS) {
1482 ql_log(ql_log_warn, vha, 0x800a,
1483 "Wait for hba online failed for cmd=%p.\n", cmd);
1484 goto eh_reset_failed;
1487 if (ha->isp_ops->lun_reset(fcport, sdev->lun, 1)
1489 ql_log(ql_log_warn, vha, 0x800c,
1490 "do_reset failed for cmd=%p.\n", cmd);
1491 goto eh_reset_failed;
1494 if (qla2x00_eh_wait_for_pending_commands(vha, fcport->d_id.b24,
1496 WAIT_LUN) != QLA_SUCCESS) {
1497 ql_log(ql_log_warn, vha, 0x800d,
1498 "wait for pending cmds failed for cmd=%p.\n", cmd);
1499 goto eh_reset_failed;
1502 ql_log(ql_log_info, vha, 0x800e,
1503 "DEVICE RESET SUCCEEDED nexus:%ld:%d:%llu cmd=%p.\n",
1504 vha->host_no, sdev->id, sdev->lun, cmd);
1509 ql_log(ql_log_info, vha, 0x800f,
1510 "DEVICE RESET FAILED: %s nexus=%ld:%d:%llu cmd=%p.\n",
1511 reset_errors[err], vha->host_no, sdev->id, sdev->lun,
1513 vha->reset_cmd_err_cnt++;
1518 qla2xxx_eh_target_reset(struct scsi_cmnd *cmd)
1520 struct scsi_device *sdev = cmd->device;
1521 struct fc_rport *rport = starget_to_rport(scsi_target(sdev));
1522 scsi_qla_host_t *vha = shost_priv(rport_to_shost(rport));
1523 struct qla_hw_data *ha = vha->hw;
1524 fc_port_t *fcport = *(fc_port_t **)rport->dd_data;
1527 if (qla2x00_isp_reg_stat(ha)) {
1528 ql_log(ql_log_info, vha, 0x803f,
1529 "PCI/Register disconnect, exiting.\n");
1530 qla_pci_set_eeh_busy(vha);
1538 err = fc_block_rport(rport);
1542 if (fcport->deleted)
1545 ql_log(ql_log_info, vha, 0x8009,
1546 "TARGET RESET ISSUED nexus=%ld:%d cmd=%p.\n", vha->host_no,
1550 if (qla2x00_wait_for_hba_online(vha) != QLA_SUCCESS) {
1551 ql_log(ql_log_warn, vha, 0x800a,
1552 "Wait for hba online failed for cmd=%p.\n", cmd);
1553 goto eh_reset_failed;
1556 if (ha->isp_ops->target_reset(fcport, 0, 0) != QLA_SUCCESS) {
1557 ql_log(ql_log_warn, vha, 0x800c,
1558 "target_reset failed for cmd=%p.\n", cmd);
1559 goto eh_reset_failed;
1562 if (qla2x00_eh_wait_for_pending_commands(vha, fcport->d_id.b24, 0,
1563 WAIT_TARGET) != QLA_SUCCESS) {
1564 ql_log(ql_log_warn, vha, 0x800d,
1565 "wait for pending cmds failed for cmd=%p.\n", cmd);
1566 goto eh_reset_failed;
1569 ql_log(ql_log_info, vha, 0x800e,
1570 "TARGET RESET SUCCEEDED nexus:%ld:%d cmd=%p.\n",
1571 vha->host_no, sdev->id, cmd);
1576 ql_log(ql_log_info, vha, 0x800f,
1577 "TARGET RESET FAILED: %s nexus=%ld:%d:%llu cmd=%p.\n",
1578 reset_errors[err], vha->host_no, cmd->device->id, cmd->device->lun,
1580 vha->reset_cmd_err_cnt++;
1584 /**************************************************************************
1585 * qla2xxx_eh_bus_reset
1588 * The bus reset function will reset the bus and abort any executing
1592 * cmd = Linux SCSI command packet of the command that cause the
1596 * SUCCESS/FAILURE (defined as macro in scsi.h).
1598 **************************************************************************/
1600 qla2xxx_eh_bus_reset(struct scsi_cmnd *cmd)
1602 scsi_qla_host_t *vha = shost_priv(cmd->device->host);
1606 struct qla_hw_data *ha = vha->hw;
1608 if (qla2x00_isp_reg_stat(ha)) {
1609 ql_log(ql_log_info, vha, 0x8040,
1610 "PCI/Register disconnect, exiting.\n");
1611 qla_pci_set_eeh_busy(vha);
1615 id = cmd->device->id;
1616 lun = cmd->device->lun;
1618 if (qla2x00_chip_is_down(vha))
1621 ql_log(ql_log_info, vha, 0x8012,
1622 "BUS RESET ISSUED nexus=%ld:%d:%llu.\n", vha->host_no, id, lun);
1624 if (qla2x00_wait_for_hba_online(vha) != QLA_SUCCESS) {
1625 ql_log(ql_log_fatal, vha, 0x8013,
1626 "Wait for hba online failed board disabled.\n");
1627 goto eh_bus_reset_done;
1630 if (qla2x00_loop_reset(vha) == QLA_SUCCESS)
1634 goto eh_bus_reset_done;
1636 /* Flush outstanding commands. */
1637 if (qla2x00_eh_wait_for_pending_commands(vha, 0, 0, WAIT_HOST) !=
1639 ql_log(ql_log_warn, vha, 0x8014,
1640 "Wait for pending commands failed.\n");
1645 ql_log(ql_log_warn, vha, 0x802b,
1646 "BUS RESET %s nexus=%ld:%d:%llu.\n",
1647 (ret == FAILED) ? "FAILED" : "SUCCEEDED", vha->host_no, id, lun);
1652 /**************************************************************************
1653 * qla2xxx_eh_host_reset
1656 * The reset function will reset the Adapter.
1659 * cmd = Linux SCSI command packet of the command that cause the
1663 * Either SUCCESS or FAILED.
1666 **************************************************************************/
1668 qla2xxx_eh_host_reset(struct scsi_cmnd *cmd)
1670 scsi_qla_host_t *vha = shost_priv(cmd->device->host);
1671 struct qla_hw_data *ha = vha->hw;
1675 scsi_qla_host_t *base_vha = pci_get_drvdata(ha->pdev);
1677 if (qla2x00_isp_reg_stat(ha)) {
1678 ql_log(ql_log_info, vha, 0x8041,
1679 "PCI/Register disconnect, exiting.\n");
1680 qla_pci_set_eeh_busy(vha);
1684 id = cmd->device->id;
1685 lun = cmd->device->lun;
1687 ql_log(ql_log_info, vha, 0x8018,
1688 "ADAPTER RESET ISSUED nexus=%ld:%d:%llu.\n", vha->host_no, id, lun);
1691 * No point in issuing another reset if one is active. Also do not
1692 * attempt a reset if we are updating flash.
1694 if (qla2x00_reset_active(vha) || ha->optrom_state != QLA_SWAITING)
1695 goto eh_host_reset_lock;
1697 if (vha != base_vha) {
1698 if (qla2x00_vp_abort_isp(vha))
1699 goto eh_host_reset_lock;
1701 if (IS_P3P_TYPE(vha->hw)) {
1702 if (!qla82xx_fcoe_ctx_reset(vha)) {
1703 /* Ctx reset success */
1705 goto eh_host_reset_lock;
1707 /* fall thru if ctx reset failed */
1710 flush_workqueue(ha->wq);
1712 set_bit(ABORT_ISP_ACTIVE, &base_vha->dpc_flags);
1713 if (ha->isp_ops->abort_isp(base_vha)) {
1714 clear_bit(ABORT_ISP_ACTIVE, &base_vha->dpc_flags);
1715 /* failed. schedule dpc to try */
1716 set_bit(ISP_ABORT_NEEDED, &base_vha->dpc_flags);
1718 if (qla2x00_wait_for_hba_online(vha) != QLA_SUCCESS) {
1719 ql_log(ql_log_warn, vha, 0x802a,
1720 "wait for hba online failed.\n");
1721 goto eh_host_reset_lock;
1724 clear_bit(ABORT_ISP_ACTIVE, &base_vha->dpc_flags);
1727 /* Waiting for command to be returned to OS.*/
1728 if (qla2x00_eh_wait_for_pending_commands(vha, 0, 0, WAIT_HOST) ==
1733 ql_log(ql_log_info, vha, 0x8017,
1734 "ADAPTER RESET %s nexus=%ld:%d:%llu.\n",
1735 (ret == FAILED) ? "FAILED" : "SUCCEEDED", vha->host_no, id, lun);
1741 * qla2x00_loop_reset
1745 * ha = adapter block pointer.
1751 qla2x00_loop_reset(scsi_qla_host_t *vha)
1754 struct qla_hw_data *ha = vha->hw;
1759 if (ha->flags.enable_lip_full_login && !IS_CNA_CAPABLE(ha)) {
1760 atomic_set(&vha->loop_state, LOOP_DOWN);
1761 atomic_set(&vha->loop_down_timer, LOOP_DOWN_TIME);
1762 qla2x00_mark_all_devices_lost(vha);
1763 ret = qla2x00_full_login_lip(vha);
1764 if (ret != QLA_SUCCESS) {
1765 ql_dbg(ql_dbg_taskm, vha, 0x802d,
1766 "full_login_lip=%d.\n", ret);
1770 if (ha->flags.enable_lip_reset) {
1771 ret = qla2x00_lip_reset(vha);
1772 if (ret != QLA_SUCCESS)
1773 ql_dbg(ql_dbg_taskm, vha, 0x802e,
1774 "lip_reset failed (%d).\n", ret);
1777 /* Issue marker command only when we are going to start the I/O */
1778 vha->marker_needed = 1;
1784 * The caller must ensure that no completion interrupts will happen
1785 * while this function is in progress.
1787 static void qla2x00_abort_srb(struct qla_qpair *qp, srb_t *sp, const int res,
1788 unsigned long *flags)
1789 __releases(qp->qp_lock_ptr)
1790 __acquires(qp->qp_lock_ptr)
1792 DECLARE_COMPLETION_ONSTACK(comp);
1793 scsi_qla_host_t *vha = qp->vha;
1794 struct qla_hw_data *ha = vha->hw;
1795 struct scsi_cmnd *cmd = GET_CMD_SP(sp);
1800 lockdep_assert_held(qp->qp_lock_ptr);
1802 if (qla2x00_chip_is_down(vha)) {
1807 if (sp->type == SRB_NVME_CMD || sp->type == SRB_NVME_LS ||
1808 (sp->type == SRB_SCSI_CMD && !ha->flags.eeh_busy &&
1809 !test_bit(ABORT_ISP_ACTIVE, &vha->dpc_flags) &&
1810 !qla2x00_isp_reg_stat(ha))) {
1817 spin_unlock_irqrestore(qp->qp_lock_ptr, *flags);
1819 rval = ha->isp_ops->abort_command(sp);
1820 /* Wait for command completion. */
1822 ratov_j = ha->r_a_tov/10 * 4 * 1000;
1823 ratov_j = msecs_to_jiffies(ratov_j);
1826 if (wait_for_completion_timeout(&comp, ratov_j)) {
1827 ql_dbg(ql_dbg_taskm, vha, 0xffff,
1828 "%s: Abort wait timer (4 * R_A_TOV[%d]) expired\n",
1829 __func__, ha->r_a_tov/10);
1832 /* else FW return SP to driver */
1839 spin_lock_irqsave(qp->qp_lock_ptr, *flags);
1842 if (ret_cmd && blk_mq_request_started(scsi_cmd_to_rq(cmd)))
1856 * The caller must ensure that no completion interrupts will happen
1857 * while this function is in progress.
1860 __qla2x00_abort_all_cmds(struct qla_qpair *qp, int res)
1863 unsigned long flags;
1865 scsi_qla_host_t *vha = qp->vha;
1866 struct qla_hw_data *ha = vha->hw;
1867 struct req_que *req;
1868 struct qla_tgt *tgt = vha->vha_tgt.qla_tgt;
1869 struct qla_tgt_cmd *cmd;
1873 spin_lock_irqsave(qp->qp_lock_ptr, flags);
1875 for (cnt = 1; cnt < req->num_outstanding_cmds; cnt++) {
1876 sp = req->outstanding_cmds[cnt];
1879 * perform lockless completion during driver unload
1881 if (qla2x00_chip_is_down(vha)) {
1882 req->outstanding_cmds[cnt] = NULL;
1883 spin_unlock_irqrestore(qp->qp_lock_ptr, flags);
1885 spin_lock_irqsave(qp->qp_lock_ptr, flags);
1889 switch (sp->cmd_type) {
1891 qla2x00_abort_srb(qp, sp, res, &flags);
1894 if (!vha->hw->tgt.tgt_ops || !tgt ||
1895 qla_ini_mode_enabled(vha)) {
1896 ql_dbg(ql_dbg_tgt_mgt, vha, 0xf003,
1897 "HOST-ABORT-HNDLR: dpc_flags=%lx. Target mode disabled\n",
1901 cmd = (struct qla_tgt_cmd *)sp;
1904 case TYPE_TGT_TMCMD:
1905 /* Skip task management functions. */
1910 req->outstanding_cmds[cnt] = NULL;
1913 spin_unlock_irqrestore(qp->qp_lock_ptr, flags);
1917 * The caller must ensure that no completion interrupts will happen
1918 * while this function is in progress.
1921 qla2x00_abort_all_cmds(scsi_qla_host_t *vha, int res)
1924 struct qla_hw_data *ha = vha->hw;
1926 /* Continue only if initialization complete. */
1927 if (!ha->base_qpair)
1929 __qla2x00_abort_all_cmds(ha->base_qpair, res);
1931 if (!ha->queue_pair_map)
1933 for (que = 0; que < ha->max_qpairs; que++) {
1934 if (!ha->queue_pair_map[que])
1937 __qla2x00_abort_all_cmds(ha->queue_pair_map[que], res);
1942 qla2xxx_slave_alloc(struct scsi_device *sdev)
1944 struct fc_rport *rport = starget_to_rport(scsi_target(sdev));
1946 if (!rport || fc_remote_port_chkready(rport))
1949 sdev->hostdata = *(fc_port_t **)rport->dd_data;
1955 qla2xxx_slave_configure(struct scsi_device *sdev)
1957 scsi_qla_host_t *vha = shost_priv(sdev->host);
1958 struct req_que *req = vha->req;
1960 if (IS_T10_PI_CAPABLE(vha->hw))
1961 blk_queue_update_dma_alignment(sdev->request_queue, 0x7);
1963 scsi_change_queue_depth(sdev, req->max_q_depth);
1968 qla2xxx_slave_destroy(struct scsi_device *sdev)
1970 sdev->hostdata = NULL;
1974 * qla2x00_config_dma_addressing() - Configure OS DMA addressing method.
1977 * At exit, the @ha's flags.enable_64bit_addressing set to indicated
1978 * supported addressing method.
1981 qla2x00_config_dma_addressing(struct qla_hw_data *ha)
1983 /* Assume a 32bit DMA mask. */
1984 ha->flags.enable_64bit_addressing = 0;
1986 if (!dma_set_mask(&ha->pdev->dev, DMA_BIT_MASK(64))) {
1987 /* Any upper-dword bits set? */
1988 if (MSD(dma_get_required_mask(&ha->pdev->dev)) &&
1989 !dma_set_coherent_mask(&ha->pdev->dev, DMA_BIT_MASK(64))) {
1990 /* Ok, a 64bit DMA mask is applicable. */
1991 ha->flags.enable_64bit_addressing = 1;
1992 ha->isp_ops->calc_req_entries = qla2x00_calc_iocbs_64;
1993 ha->isp_ops->build_iocbs = qla2x00_build_scsi_iocbs_64;
1998 dma_set_mask(&ha->pdev->dev, DMA_BIT_MASK(32));
1999 dma_set_coherent_mask(&ha->pdev->dev, DMA_BIT_MASK(32));
2003 qla2x00_enable_intrs(struct qla_hw_data *ha)
2005 unsigned long flags = 0;
2006 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
2008 spin_lock_irqsave(&ha->hardware_lock, flags);
2009 ha->interrupts_on = 1;
2010 /* enable risc and host interrupts */
2011 wrt_reg_word(®->ictrl, ICR_EN_INT | ICR_EN_RISC);
2012 rd_reg_word(®->ictrl);
2013 spin_unlock_irqrestore(&ha->hardware_lock, flags);
2018 qla2x00_disable_intrs(struct qla_hw_data *ha)
2020 unsigned long flags = 0;
2021 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
2023 spin_lock_irqsave(&ha->hardware_lock, flags);
2024 ha->interrupts_on = 0;
2025 /* disable risc and host interrupts */
2026 wrt_reg_word(®->ictrl, 0);
2027 rd_reg_word(®->ictrl);
2028 spin_unlock_irqrestore(&ha->hardware_lock, flags);
2032 qla24xx_enable_intrs(struct qla_hw_data *ha)
2034 unsigned long flags = 0;
2035 struct device_reg_24xx __iomem *reg = &ha->iobase->isp24;
2037 spin_lock_irqsave(&ha->hardware_lock, flags);
2038 ha->interrupts_on = 1;
2039 wrt_reg_dword(®->ictrl, ICRX_EN_RISC_INT);
2040 rd_reg_dword(®->ictrl);
2041 spin_unlock_irqrestore(&ha->hardware_lock, flags);
2045 qla24xx_disable_intrs(struct qla_hw_data *ha)
2047 unsigned long flags = 0;
2048 struct device_reg_24xx __iomem *reg = &ha->iobase->isp24;
2050 if (IS_NOPOLLING_TYPE(ha))
2052 spin_lock_irqsave(&ha->hardware_lock, flags);
2053 ha->interrupts_on = 0;
2054 wrt_reg_dword(®->ictrl, 0);
2055 rd_reg_dword(®->ictrl);
2056 spin_unlock_irqrestore(&ha->hardware_lock, flags);
2060 qla2x00_iospace_config(struct qla_hw_data *ha)
2062 resource_size_t pio;
2065 if (pci_request_selected_regions(ha->pdev, ha->bars,
2066 QLA2XXX_DRIVER_NAME)) {
2067 ql_log_pci(ql_log_fatal, ha->pdev, 0x0011,
2068 "Failed to reserve PIO/MMIO regions (%s), aborting.\n",
2069 pci_name(ha->pdev));
2070 goto iospace_error_exit;
2072 if (!(ha->bars & 1))
2075 /* We only need PIO for Flash operations on ISP2312 v2 chips. */
2076 pio = pci_resource_start(ha->pdev, 0);
2077 if (pci_resource_flags(ha->pdev, 0) & IORESOURCE_IO) {
2078 if (pci_resource_len(ha->pdev, 0) < MIN_IOBASE_LEN) {
2079 ql_log_pci(ql_log_warn, ha->pdev, 0x0012,
2080 "Invalid pci I/O region size (%s).\n",
2081 pci_name(ha->pdev));
2085 ql_log_pci(ql_log_warn, ha->pdev, 0x0013,
2086 "Region #0 no a PIO resource (%s).\n",
2087 pci_name(ha->pdev));
2090 ha->pio_address = pio;
2091 ql_dbg_pci(ql_dbg_init, ha->pdev, 0x0014,
2092 "PIO address=%llu.\n",
2093 (unsigned long long)ha->pio_address);
2096 /* Use MMIO operations for all accesses. */
2097 if (!(pci_resource_flags(ha->pdev, 1) & IORESOURCE_MEM)) {
2098 ql_log_pci(ql_log_fatal, ha->pdev, 0x0015,
2099 "Region #1 not an MMIO resource (%s), aborting.\n",
2100 pci_name(ha->pdev));
2101 goto iospace_error_exit;
2103 if (pci_resource_len(ha->pdev, 1) < MIN_IOBASE_LEN) {
2104 ql_log_pci(ql_log_fatal, ha->pdev, 0x0016,
2105 "Invalid PCI mem region size (%s), aborting.\n",
2106 pci_name(ha->pdev));
2107 goto iospace_error_exit;
2110 ha->iobase = ioremap(pci_resource_start(ha->pdev, 1), MIN_IOBASE_LEN);
2112 ql_log_pci(ql_log_fatal, ha->pdev, 0x0017,
2113 "Cannot remap MMIO (%s), aborting.\n",
2114 pci_name(ha->pdev));
2115 goto iospace_error_exit;
2118 /* Determine queue resources */
2119 ha->max_req_queues = ha->max_rsp_queues = 1;
2120 ha->msix_count = QLA_BASE_VECTORS;
2122 /* Check if FW supports MQ or not */
2123 if (!(ha->fw_attributes & BIT_6))
2126 if (!ql2xmqsupport || !ql2xnvmeenable ||
2127 (!IS_QLA25XX(ha) && !IS_QLA81XX(ha)))
2130 ha->mqiobase = ioremap(pci_resource_start(ha->pdev, 3),
2131 pci_resource_len(ha->pdev, 3));
2133 ql_dbg_pci(ql_dbg_init, ha->pdev, 0x0018,
2134 "MQIO Base=%p.\n", ha->mqiobase);
2135 /* Read MSIX vector size of the board */
2136 pci_read_config_word(ha->pdev, QLA_PCI_MSIX_CONTROL, &msix);
2137 ha->msix_count = msix + 1;
2138 /* Max queues are bounded by available msix vectors */
2139 /* MB interrupt uses 1 vector */
2140 ha->max_req_queues = ha->msix_count - 1;
2141 ha->max_rsp_queues = ha->max_req_queues;
2142 /* Queue pairs is the max value minus the base queue pair */
2143 ha->max_qpairs = ha->max_rsp_queues - 1;
2144 ql_dbg_pci(ql_dbg_init, ha->pdev, 0x0188,
2145 "Max no of queues pairs: %d.\n", ha->max_qpairs);
2147 ql_log_pci(ql_log_info, ha->pdev, 0x001a,
2148 "MSI-X vector count: %d.\n", ha->msix_count);
2150 ql_log_pci(ql_log_info, ha->pdev, 0x001b,
2151 "BAR 3 not enabled.\n");
2154 ql_dbg_pci(ql_dbg_init, ha->pdev, 0x001c,
2155 "MSIX Count: %d.\n", ha->msix_count);
2164 qla83xx_iospace_config(struct qla_hw_data *ha)
2168 if (pci_request_selected_regions(ha->pdev, ha->bars,
2169 QLA2XXX_DRIVER_NAME)) {
2170 ql_log_pci(ql_log_fatal, ha->pdev, 0x0117,
2171 "Failed to reserve PIO/MMIO regions (%s), aborting.\n",
2172 pci_name(ha->pdev));
2174 goto iospace_error_exit;
2177 /* Use MMIO operations for all accesses. */
2178 if (!(pci_resource_flags(ha->pdev, 0) & IORESOURCE_MEM)) {
2179 ql_log_pci(ql_log_warn, ha->pdev, 0x0118,
2180 "Invalid pci I/O region size (%s).\n",
2181 pci_name(ha->pdev));
2182 goto iospace_error_exit;
2184 if (pci_resource_len(ha->pdev, 0) < MIN_IOBASE_LEN) {
2185 ql_log_pci(ql_log_warn, ha->pdev, 0x0119,
2186 "Invalid PCI mem region size (%s), aborting\n",
2187 pci_name(ha->pdev));
2188 goto iospace_error_exit;
2191 ha->iobase = ioremap(pci_resource_start(ha->pdev, 0), MIN_IOBASE_LEN);
2193 ql_log_pci(ql_log_fatal, ha->pdev, 0x011a,
2194 "Cannot remap MMIO (%s), aborting.\n",
2195 pci_name(ha->pdev));
2196 goto iospace_error_exit;
2199 /* 64bit PCI BAR - BAR2 will correspoond to region 4 */
2200 /* 83XX 26XX always use MQ type access for queues
2201 * - mbar 2, a.k.a region 4 */
2202 ha->max_req_queues = ha->max_rsp_queues = 1;
2203 ha->msix_count = QLA_BASE_VECTORS;
2204 ha->mqiobase = ioremap(pci_resource_start(ha->pdev, 4),
2205 pci_resource_len(ha->pdev, 4));
2207 if (!ha->mqiobase) {
2208 ql_log_pci(ql_log_fatal, ha->pdev, 0x011d,
2209 "BAR2/region4 not enabled\n");
2213 ha->msixbase = ioremap(pci_resource_start(ha->pdev, 2),
2214 pci_resource_len(ha->pdev, 2));
2216 /* Read MSIX vector size of the board */
2217 pci_read_config_word(ha->pdev,
2218 QLA_83XX_PCI_MSIX_CONTROL, &msix);
2219 ha->msix_count = (msix & PCI_MSIX_FLAGS_QSIZE) + 1;
2221 * By default, driver uses at least two msix vectors
2224 if (ql2xmqsupport || ql2xnvmeenable) {
2225 /* MB interrupt uses 1 vector */
2226 ha->max_req_queues = ha->msix_count - 1;
2228 /* ATIOQ needs 1 vector. That's 1 less QPair */
2229 if (QLA_TGT_MODE_ENABLED())
2230 ha->max_req_queues--;
2232 ha->max_rsp_queues = ha->max_req_queues;
2234 /* Queue pairs is the max value minus
2235 * the base queue pair */
2236 ha->max_qpairs = ha->max_req_queues - 1;
2237 ql_dbg_pci(ql_dbg_init, ha->pdev, 0x00e3,
2238 "Max no of queues pairs: %d.\n", ha->max_qpairs);
2240 ql_log_pci(ql_log_info, ha->pdev, 0x011c,
2241 "MSI-X vector count: %d.\n", ha->msix_count);
2243 ql_log_pci(ql_log_info, ha->pdev, 0x011e,
2244 "BAR 1 not enabled.\n");
2247 ql_dbg_pci(ql_dbg_init, ha->pdev, 0x011f,
2248 "MSIX Count: %d.\n", ha->msix_count);
2255 static struct isp_operations qla2100_isp_ops = {
2256 .pci_config = qla2100_pci_config,
2257 .reset_chip = qla2x00_reset_chip,
2258 .chip_diag = qla2x00_chip_diag,
2259 .config_rings = qla2x00_config_rings,
2260 .reset_adapter = qla2x00_reset_adapter,
2261 .nvram_config = qla2x00_nvram_config,
2262 .update_fw_options = qla2x00_update_fw_options,
2263 .load_risc = qla2x00_load_risc,
2264 .pci_info_str = qla2x00_pci_info_str,
2265 .fw_version_str = qla2x00_fw_version_str,
2266 .intr_handler = qla2100_intr_handler,
2267 .enable_intrs = qla2x00_enable_intrs,
2268 .disable_intrs = qla2x00_disable_intrs,
2269 .abort_command = qla2x00_abort_command,
2270 .target_reset = qla2x00_abort_target,
2271 .lun_reset = qla2x00_lun_reset,
2272 .fabric_login = qla2x00_login_fabric,
2273 .fabric_logout = qla2x00_fabric_logout,
2274 .calc_req_entries = qla2x00_calc_iocbs_32,
2275 .build_iocbs = qla2x00_build_scsi_iocbs_32,
2276 .prep_ms_iocb = qla2x00_prep_ms_iocb,
2277 .prep_ms_fdmi_iocb = qla2x00_prep_ms_fdmi_iocb,
2278 .read_nvram = qla2x00_read_nvram_data,
2279 .write_nvram = qla2x00_write_nvram_data,
2280 .fw_dump = qla2100_fw_dump,
2283 .beacon_blink = NULL,
2284 .read_optrom = qla2x00_read_optrom_data,
2285 .write_optrom = qla2x00_write_optrom_data,
2286 .get_flash_version = qla2x00_get_flash_version,
2287 .start_scsi = qla2x00_start_scsi,
2288 .start_scsi_mq = NULL,
2289 .abort_isp = qla2x00_abort_isp,
2290 .iospace_config = qla2x00_iospace_config,
2291 .initialize_adapter = qla2x00_initialize_adapter,
2294 static struct isp_operations qla2300_isp_ops = {
2295 .pci_config = qla2300_pci_config,
2296 .reset_chip = qla2x00_reset_chip,
2297 .chip_diag = qla2x00_chip_diag,
2298 .config_rings = qla2x00_config_rings,
2299 .reset_adapter = qla2x00_reset_adapter,
2300 .nvram_config = qla2x00_nvram_config,
2301 .update_fw_options = qla2x00_update_fw_options,
2302 .load_risc = qla2x00_load_risc,
2303 .pci_info_str = qla2x00_pci_info_str,
2304 .fw_version_str = qla2x00_fw_version_str,
2305 .intr_handler = qla2300_intr_handler,
2306 .enable_intrs = qla2x00_enable_intrs,
2307 .disable_intrs = qla2x00_disable_intrs,
2308 .abort_command = qla2x00_abort_command,
2309 .target_reset = qla2x00_abort_target,
2310 .lun_reset = qla2x00_lun_reset,
2311 .fabric_login = qla2x00_login_fabric,
2312 .fabric_logout = qla2x00_fabric_logout,
2313 .calc_req_entries = qla2x00_calc_iocbs_32,
2314 .build_iocbs = qla2x00_build_scsi_iocbs_32,
2315 .prep_ms_iocb = qla2x00_prep_ms_iocb,
2316 .prep_ms_fdmi_iocb = qla2x00_prep_ms_fdmi_iocb,
2317 .read_nvram = qla2x00_read_nvram_data,
2318 .write_nvram = qla2x00_write_nvram_data,
2319 .fw_dump = qla2300_fw_dump,
2320 .beacon_on = qla2x00_beacon_on,
2321 .beacon_off = qla2x00_beacon_off,
2322 .beacon_blink = qla2x00_beacon_blink,
2323 .read_optrom = qla2x00_read_optrom_data,
2324 .write_optrom = qla2x00_write_optrom_data,
2325 .get_flash_version = qla2x00_get_flash_version,
2326 .start_scsi = qla2x00_start_scsi,
2327 .start_scsi_mq = NULL,
2328 .abort_isp = qla2x00_abort_isp,
2329 .iospace_config = qla2x00_iospace_config,
2330 .initialize_adapter = qla2x00_initialize_adapter,
2333 static struct isp_operations qla24xx_isp_ops = {
2334 .pci_config = qla24xx_pci_config,
2335 .reset_chip = qla24xx_reset_chip,
2336 .chip_diag = qla24xx_chip_diag,
2337 .config_rings = qla24xx_config_rings,
2338 .reset_adapter = qla24xx_reset_adapter,
2339 .nvram_config = qla24xx_nvram_config,
2340 .update_fw_options = qla24xx_update_fw_options,
2341 .load_risc = qla24xx_load_risc,
2342 .pci_info_str = qla24xx_pci_info_str,
2343 .fw_version_str = qla24xx_fw_version_str,
2344 .intr_handler = qla24xx_intr_handler,
2345 .enable_intrs = qla24xx_enable_intrs,
2346 .disable_intrs = qla24xx_disable_intrs,
2347 .abort_command = qla24xx_abort_command,
2348 .target_reset = qla24xx_abort_target,
2349 .lun_reset = qla24xx_lun_reset,
2350 .fabric_login = qla24xx_login_fabric,
2351 .fabric_logout = qla24xx_fabric_logout,
2352 .calc_req_entries = NULL,
2353 .build_iocbs = NULL,
2354 .prep_ms_iocb = qla24xx_prep_ms_iocb,
2355 .prep_ms_fdmi_iocb = qla24xx_prep_ms_fdmi_iocb,
2356 .read_nvram = qla24xx_read_nvram_data,
2357 .write_nvram = qla24xx_write_nvram_data,
2358 .fw_dump = qla24xx_fw_dump,
2359 .beacon_on = qla24xx_beacon_on,
2360 .beacon_off = qla24xx_beacon_off,
2361 .beacon_blink = qla24xx_beacon_blink,
2362 .read_optrom = qla24xx_read_optrom_data,
2363 .write_optrom = qla24xx_write_optrom_data,
2364 .get_flash_version = qla24xx_get_flash_version,
2365 .start_scsi = qla24xx_start_scsi,
2366 .start_scsi_mq = NULL,
2367 .abort_isp = qla2x00_abort_isp,
2368 .iospace_config = qla2x00_iospace_config,
2369 .initialize_adapter = qla2x00_initialize_adapter,
2372 static struct isp_operations qla25xx_isp_ops = {
2373 .pci_config = qla25xx_pci_config,
2374 .reset_chip = qla24xx_reset_chip,
2375 .chip_diag = qla24xx_chip_diag,
2376 .config_rings = qla24xx_config_rings,
2377 .reset_adapter = qla24xx_reset_adapter,
2378 .nvram_config = qla24xx_nvram_config,
2379 .update_fw_options = qla24xx_update_fw_options,
2380 .load_risc = qla24xx_load_risc,
2381 .pci_info_str = qla24xx_pci_info_str,
2382 .fw_version_str = qla24xx_fw_version_str,
2383 .intr_handler = qla24xx_intr_handler,
2384 .enable_intrs = qla24xx_enable_intrs,
2385 .disable_intrs = qla24xx_disable_intrs,
2386 .abort_command = qla24xx_abort_command,
2387 .target_reset = qla24xx_abort_target,
2388 .lun_reset = qla24xx_lun_reset,
2389 .fabric_login = qla24xx_login_fabric,
2390 .fabric_logout = qla24xx_fabric_logout,
2391 .calc_req_entries = NULL,
2392 .build_iocbs = NULL,
2393 .prep_ms_iocb = qla24xx_prep_ms_iocb,
2394 .prep_ms_fdmi_iocb = qla24xx_prep_ms_fdmi_iocb,
2395 .read_nvram = qla25xx_read_nvram_data,
2396 .write_nvram = qla25xx_write_nvram_data,
2397 .fw_dump = qla25xx_fw_dump,
2398 .beacon_on = qla24xx_beacon_on,
2399 .beacon_off = qla24xx_beacon_off,
2400 .beacon_blink = qla24xx_beacon_blink,
2401 .read_optrom = qla25xx_read_optrom_data,
2402 .write_optrom = qla24xx_write_optrom_data,
2403 .get_flash_version = qla24xx_get_flash_version,
2404 .start_scsi = qla24xx_dif_start_scsi,
2405 .start_scsi_mq = qla2xxx_dif_start_scsi_mq,
2406 .abort_isp = qla2x00_abort_isp,
2407 .iospace_config = qla2x00_iospace_config,
2408 .initialize_adapter = qla2x00_initialize_adapter,
2411 static struct isp_operations qla81xx_isp_ops = {
2412 .pci_config = qla25xx_pci_config,
2413 .reset_chip = qla24xx_reset_chip,
2414 .chip_diag = qla24xx_chip_diag,
2415 .config_rings = qla24xx_config_rings,
2416 .reset_adapter = qla24xx_reset_adapter,
2417 .nvram_config = qla81xx_nvram_config,
2418 .update_fw_options = qla24xx_update_fw_options,
2419 .load_risc = qla81xx_load_risc,
2420 .pci_info_str = qla24xx_pci_info_str,
2421 .fw_version_str = qla24xx_fw_version_str,
2422 .intr_handler = qla24xx_intr_handler,
2423 .enable_intrs = qla24xx_enable_intrs,
2424 .disable_intrs = qla24xx_disable_intrs,
2425 .abort_command = qla24xx_abort_command,
2426 .target_reset = qla24xx_abort_target,
2427 .lun_reset = qla24xx_lun_reset,
2428 .fabric_login = qla24xx_login_fabric,
2429 .fabric_logout = qla24xx_fabric_logout,
2430 .calc_req_entries = NULL,
2431 .build_iocbs = NULL,
2432 .prep_ms_iocb = qla24xx_prep_ms_iocb,
2433 .prep_ms_fdmi_iocb = qla24xx_prep_ms_fdmi_iocb,
2435 .write_nvram = NULL,
2436 .fw_dump = qla81xx_fw_dump,
2437 .beacon_on = qla24xx_beacon_on,
2438 .beacon_off = qla24xx_beacon_off,
2439 .beacon_blink = qla83xx_beacon_blink,
2440 .read_optrom = qla25xx_read_optrom_data,
2441 .write_optrom = qla24xx_write_optrom_data,
2442 .get_flash_version = qla24xx_get_flash_version,
2443 .start_scsi = qla24xx_dif_start_scsi,
2444 .start_scsi_mq = qla2xxx_dif_start_scsi_mq,
2445 .abort_isp = qla2x00_abort_isp,
2446 .iospace_config = qla2x00_iospace_config,
2447 .initialize_adapter = qla2x00_initialize_adapter,
2450 static struct isp_operations qla82xx_isp_ops = {
2451 .pci_config = qla82xx_pci_config,
2452 .reset_chip = qla82xx_reset_chip,
2453 .chip_diag = qla24xx_chip_diag,
2454 .config_rings = qla82xx_config_rings,
2455 .reset_adapter = qla24xx_reset_adapter,
2456 .nvram_config = qla81xx_nvram_config,
2457 .update_fw_options = qla24xx_update_fw_options,
2458 .load_risc = qla82xx_load_risc,
2459 .pci_info_str = qla24xx_pci_info_str,
2460 .fw_version_str = qla24xx_fw_version_str,
2461 .intr_handler = qla82xx_intr_handler,
2462 .enable_intrs = qla82xx_enable_intrs,
2463 .disable_intrs = qla82xx_disable_intrs,
2464 .abort_command = qla24xx_abort_command,
2465 .target_reset = qla24xx_abort_target,
2466 .lun_reset = qla24xx_lun_reset,
2467 .fabric_login = qla24xx_login_fabric,
2468 .fabric_logout = qla24xx_fabric_logout,
2469 .calc_req_entries = NULL,
2470 .build_iocbs = NULL,
2471 .prep_ms_iocb = qla24xx_prep_ms_iocb,
2472 .prep_ms_fdmi_iocb = qla24xx_prep_ms_fdmi_iocb,
2473 .read_nvram = qla24xx_read_nvram_data,
2474 .write_nvram = qla24xx_write_nvram_data,
2475 .fw_dump = qla82xx_fw_dump,
2476 .beacon_on = qla82xx_beacon_on,
2477 .beacon_off = qla82xx_beacon_off,
2478 .beacon_blink = NULL,
2479 .read_optrom = qla82xx_read_optrom_data,
2480 .write_optrom = qla82xx_write_optrom_data,
2481 .get_flash_version = qla82xx_get_flash_version,
2482 .start_scsi = qla82xx_start_scsi,
2483 .start_scsi_mq = NULL,
2484 .abort_isp = qla82xx_abort_isp,
2485 .iospace_config = qla82xx_iospace_config,
2486 .initialize_adapter = qla2x00_initialize_adapter,
2489 static struct isp_operations qla8044_isp_ops = {
2490 .pci_config = qla82xx_pci_config,
2491 .reset_chip = qla82xx_reset_chip,
2492 .chip_diag = qla24xx_chip_diag,
2493 .config_rings = qla82xx_config_rings,
2494 .reset_adapter = qla24xx_reset_adapter,
2495 .nvram_config = qla81xx_nvram_config,
2496 .update_fw_options = qla24xx_update_fw_options,
2497 .load_risc = qla82xx_load_risc,
2498 .pci_info_str = qla24xx_pci_info_str,
2499 .fw_version_str = qla24xx_fw_version_str,
2500 .intr_handler = qla8044_intr_handler,
2501 .enable_intrs = qla82xx_enable_intrs,
2502 .disable_intrs = qla82xx_disable_intrs,
2503 .abort_command = qla24xx_abort_command,
2504 .target_reset = qla24xx_abort_target,
2505 .lun_reset = qla24xx_lun_reset,
2506 .fabric_login = qla24xx_login_fabric,
2507 .fabric_logout = qla24xx_fabric_logout,
2508 .calc_req_entries = NULL,
2509 .build_iocbs = NULL,
2510 .prep_ms_iocb = qla24xx_prep_ms_iocb,
2511 .prep_ms_fdmi_iocb = qla24xx_prep_ms_fdmi_iocb,
2513 .write_nvram = NULL,
2514 .fw_dump = qla8044_fw_dump,
2515 .beacon_on = qla82xx_beacon_on,
2516 .beacon_off = qla82xx_beacon_off,
2517 .beacon_blink = NULL,
2518 .read_optrom = qla8044_read_optrom_data,
2519 .write_optrom = qla8044_write_optrom_data,
2520 .get_flash_version = qla82xx_get_flash_version,
2521 .start_scsi = qla82xx_start_scsi,
2522 .start_scsi_mq = NULL,
2523 .abort_isp = qla8044_abort_isp,
2524 .iospace_config = qla82xx_iospace_config,
2525 .initialize_adapter = qla2x00_initialize_adapter,
2528 static struct isp_operations qla83xx_isp_ops = {
2529 .pci_config = qla25xx_pci_config,
2530 .reset_chip = qla24xx_reset_chip,
2531 .chip_diag = qla24xx_chip_diag,
2532 .config_rings = qla24xx_config_rings,
2533 .reset_adapter = qla24xx_reset_adapter,
2534 .nvram_config = qla81xx_nvram_config,
2535 .update_fw_options = qla24xx_update_fw_options,
2536 .load_risc = qla81xx_load_risc,
2537 .pci_info_str = qla24xx_pci_info_str,
2538 .fw_version_str = qla24xx_fw_version_str,
2539 .intr_handler = qla24xx_intr_handler,
2540 .enable_intrs = qla24xx_enable_intrs,
2541 .disable_intrs = qla24xx_disable_intrs,
2542 .abort_command = qla24xx_abort_command,
2543 .target_reset = qla24xx_abort_target,
2544 .lun_reset = qla24xx_lun_reset,
2545 .fabric_login = qla24xx_login_fabric,
2546 .fabric_logout = qla24xx_fabric_logout,
2547 .calc_req_entries = NULL,
2548 .build_iocbs = NULL,
2549 .prep_ms_iocb = qla24xx_prep_ms_iocb,
2550 .prep_ms_fdmi_iocb = qla24xx_prep_ms_fdmi_iocb,
2552 .write_nvram = NULL,
2553 .fw_dump = qla83xx_fw_dump,
2554 .beacon_on = qla24xx_beacon_on,
2555 .beacon_off = qla24xx_beacon_off,
2556 .beacon_blink = qla83xx_beacon_blink,
2557 .read_optrom = qla25xx_read_optrom_data,
2558 .write_optrom = qla24xx_write_optrom_data,
2559 .get_flash_version = qla24xx_get_flash_version,
2560 .start_scsi = qla24xx_dif_start_scsi,
2561 .start_scsi_mq = qla2xxx_dif_start_scsi_mq,
2562 .abort_isp = qla2x00_abort_isp,
2563 .iospace_config = qla83xx_iospace_config,
2564 .initialize_adapter = qla2x00_initialize_adapter,
2567 static struct isp_operations qlafx00_isp_ops = {
2568 .pci_config = qlafx00_pci_config,
2569 .reset_chip = qlafx00_soft_reset,
2570 .chip_diag = qlafx00_chip_diag,
2571 .config_rings = qlafx00_config_rings,
2572 .reset_adapter = qlafx00_soft_reset,
2573 .nvram_config = NULL,
2574 .update_fw_options = NULL,
2576 .pci_info_str = qlafx00_pci_info_str,
2577 .fw_version_str = qlafx00_fw_version_str,
2578 .intr_handler = qlafx00_intr_handler,
2579 .enable_intrs = qlafx00_enable_intrs,
2580 .disable_intrs = qlafx00_disable_intrs,
2581 .abort_command = qla24xx_async_abort_command,
2582 .target_reset = qlafx00_abort_target,
2583 .lun_reset = qlafx00_lun_reset,
2584 .fabric_login = NULL,
2585 .fabric_logout = NULL,
2586 .calc_req_entries = NULL,
2587 .build_iocbs = NULL,
2588 .prep_ms_iocb = qla24xx_prep_ms_iocb,
2589 .prep_ms_fdmi_iocb = qla24xx_prep_ms_fdmi_iocb,
2590 .read_nvram = qla24xx_read_nvram_data,
2591 .write_nvram = qla24xx_write_nvram_data,
2593 .beacon_on = qla24xx_beacon_on,
2594 .beacon_off = qla24xx_beacon_off,
2595 .beacon_blink = NULL,
2596 .read_optrom = qla24xx_read_optrom_data,
2597 .write_optrom = qla24xx_write_optrom_data,
2598 .get_flash_version = qla24xx_get_flash_version,
2599 .start_scsi = qlafx00_start_scsi,
2600 .start_scsi_mq = NULL,
2601 .abort_isp = qlafx00_abort_isp,
2602 .iospace_config = qlafx00_iospace_config,
2603 .initialize_adapter = qlafx00_initialize_adapter,
2606 static struct isp_operations qla27xx_isp_ops = {
2607 .pci_config = qla25xx_pci_config,
2608 .reset_chip = qla24xx_reset_chip,
2609 .chip_diag = qla24xx_chip_diag,
2610 .config_rings = qla24xx_config_rings,
2611 .reset_adapter = qla24xx_reset_adapter,
2612 .nvram_config = qla81xx_nvram_config,
2613 .update_fw_options = qla24xx_update_fw_options,
2614 .load_risc = qla81xx_load_risc,
2615 .pci_info_str = qla24xx_pci_info_str,
2616 .fw_version_str = qla24xx_fw_version_str,
2617 .intr_handler = qla24xx_intr_handler,
2618 .enable_intrs = qla24xx_enable_intrs,
2619 .disable_intrs = qla24xx_disable_intrs,
2620 .abort_command = qla24xx_abort_command,
2621 .target_reset = qla24xx_abort_target,
2622 .lun_reset = qla24xx_lun_reset,
2623 .fabric_login = qla24xx_login_fabric,
2624 .fabric_logout = qla24xx_fabric_logout,
2625 .calc_req_entries = NULL,
2626 .build_iocbs = NULL,
2627 .prep_ms_iocb = qla24xx_prep_ms_iocb,
2628 .prep_ms_fdmi_iocb = qla24xx_prep_ms_fdmi_iocb,
2630 .write_nvram = NULL,
2631 .fw_dump = qla27xx_fwdump,
2632 .mpi_fw_dump = qla27xx_mpi_fwdump,
2633 .beacon_on = qla24xx_beacon_on,
2634 .beacon_off = qla24xx_beacon_off,
2635 .beacon_blink = qla83xx_beacon_blink,
2636 .read_optrom = qla25xx_read_optrom_data,
2637 .write_optrom = qla24xx_write_optrom_data,
2638 .get_flash_version = qla24xx_get_flash_version,
2639 .start_scsi = qla24xx_dif_start_scsi,
2640 .start_scsi_mq = qla2xxx_dif_start_scsi_mq,
2641 .abort_isp = qla2x00_abort_isp,
2642 .iospace_config = qla83xx_iospace_config,
2643 .initialize_adapter = qla2x00_initialize_adapter,
2647 qla2x00_set_isp_flags(struct qla_hw_data *ha)
2649 ha->device_type = DT_EXTENDED_IDS;
2650 switch (ha->pdev->device) {
2651 case PCI_DEVICE_ID_QLOGIC_ISP2100:
2652 ha->isp_type |= DT_ISP2100;
2653 ha->device_type &= ~DT_EXTENDED_IDS;
2654 ha->fw_srisc_address = RISC_START_ADDRESS_2100;
2656 case PCI_DEVICE_ID_QLOGIC_ISP2200:
2657 ha->isp_type |= DT_ISP2200;
2658 ha->device_type &= ~DT_EXTENDED_IDS;
2659 ha->fw_srisc_address = RISC_START_ADDRESS_2100;
2661 case PCI_DEVICE_ID_QLOGIC_ISP2300:
2662 ha->isp_type |= DT_ISP2300;
2663 ha->device_type |= DT_ZIO_SUPPORTED;
2664 ha->fw_srisc_address = RISC_START_ADDRESS_2300;
2666 case PCI_DEVICE_ID_QLOGIC_ISP2312:
2667 ha->isp_type |= DT_ISP2312;
2668 ha->device_type |= DT_ZIO_SUPPORTED;
2669 ha->fw_srisc_address = RISC_START_ADDRESS_2300;
2671 case PCI_DEVICE_ID_QLOGIC_ISP2322:
2672 ha->isp_type |= DT_ISP2322;
2673 ha->device_type |= DT_ZIO_SUPPORTED;
2674 if (ha->pdev->subsystem_vendor == 0x1028 &&
2675 ha->pdev->subsystem_device == 0x0170)
2676 ha->device_type |= DT_OEM_001;
2677 ha->fw_srisc_address = RISC_START_ADDRESS_2300;
2679 case PCI_DEVICE_ID_QLOGIC_ISP6312:
2680 ha->isp_type |= DT_ISP6312;
2681 ha->fw_srisc_address = RISC_START_ADDRESS_2300;
2683 case PCI_DEVICE_ID_QLOGIC_ISP6322:
2684 ha->isp_type |= DT_ISP6322;
2685 ha->fw_srisc_address = RISC_START_ADDRESS_2300;
2687 case PCI_DEVICE_ID_QLOGIC_ISP2422:
2688 ha->isp_type |= DT_ISP2422;
2689 ha->device_type |= DT_ZIO_SUPPORTED;
2690 ha->device_type |= DT_FWI2;
2691 ha->device_type |= DT_IIDMA;
2692 ha->fw_srisc_address = RISC_START_ADDRESS_2400;
2694 case PCI_DEVICE_ID_QLOGIC_ISP2432:
2695 ha->isp_type |= DT_ISP2432;
2696 ha->device_type |= DT_ZIO_SUPPORTED;
2697 ha->device_type |= DT_FWI2;
2698 ha->device_type |= DT_IIDMA;
2699 ha->fw_srisc_address = RISC_START_ADDRESS_2400;
2701 case PCI_DEVICE_ID_QLOGIC_ISP8432:
2702 ha->isp_type |= DT_ISP8432;
2703 ha->device_type |= DT_ZIO_SUPPORTED;
2704 ha->device_type |= DT_FWI2;
2705 ha->device_type |= DT_IIDMA;
2706 ha->fw_srisc_address = RISC_START_ADDRESS_2400;
2708 case PCI_DEVICE_ID_QLOGIC_ISP5422:
2709 ha->isp_type |= DT_ISP5422;
2710 ha->device_type |= DT_FWI2;
2711 ha->fw_srisc_address = RISC_START_ADDRESS_2400;
2713 case PCI_DEVICE_ID_QLOGIC_ISP5432:
2714 ha->isp_type |= DT_ISP5432;
2715 ha->device_type |= DT_FWI2;
2716 ha->fw_srisc_address = RISC_START_ADDRESS_2400;
2718 case PCI_DEVICE_ID_QLOGIC_ISP2532:
2719 ha->isp_type |= DT_ISP2532;
2720 ha->device_type |= DT_ZIO_SUPPORTED;
2721 ha->device_type |= DT_FWI2;
2722 ha->device_type |= DT_IIDMA;
2723 ha->fw_srisc_address = RISC_START_ADDRESS_2400;
2725 case PCI_DEVICE_ID_QLOGIC_ISP8001:
2726 ha->isp_type |= DT_ISP8001;
2727 ha->device_type |= DT_ZIO_SUPPORTED;
2728 ha->device_type |= DT_FWI2;
2729 ha->device_type |= DT_IIDMA;
2730 ha->fw_srisc_address = RISC_START_ADDRESS_2400;
2732 case PCI_DEVICE_ID_QLOGIC_ISP8021:
2733 ha->isp_type |= DT_ISP8021;
2734 ha->device_type |= DT_ZIO_SUPPORTED;
2735 ha->device_type |= DT_FWI2;
2736 ha->fw_srisc_address = RISC_START_ADDRESS_2400;
2737 /* Initialize 82XX ISP flags */
2738 qla82xx_init_flags(ha);
2740 case PCI_DEVICE_ID_QLOGIC_ISP8044:
2741 ha->isp_type |= DT_ISP8044;
2742 ha->device_type |= DT_ZIO_SUPPORTED;
2743 ha->device_type |= DT_FWI2;
2744 ha->fw_srisc_address = RISC_START_ADDRESS_2400;
2745 /* Initialize 82XX ISP flags */
2746 qla82xx_init_flags(ha);
2748 case PCI_DEVICE_ID_QLOGIC_ISP2031:
2749 ha->isp_type |= DT_ISP2031;
2750 ha->device_type |= DT_ZIO_SUPPORTED;
2751 ha->device_type |= DT_FWI2;
2752 ha->device_type |= DT_IIDMA;
2753 ha->device_type |= DT_T10_PI;
2754 ha->fw_srisc_address = RISC_START_ADDRESS_2400;
2756 case PCI_DEVICE_ID_QLOGIC_ISP8031:
2757 ha->isp_type |= DT_ISP8031;
2758 ha->device_type |= DT_ZIO_SUPPORTED;
2759 ha->device_type |= DT_FWI2;
2760 ha->device_type |= DT_IIDMA;
2761 ha->device_type |= DT_T10_PI;
2762 ha->fw_srisc_address = RISC_START_ADDRESS_2400;
2764 case PCI_DEVICE_ID_QLOGIC_ISPF001:
2765 ha->isp_type |= DT_ISPFX00;
2767 case PCI_DEVICE_ID_QLOGIC_ISP2071:
2768 ha->isp_type |= DT_ISP2071;
2769 ha->device_type |= DT_ZIO_SUPPORTED;
2770 ha->device_type |= DT_FWI2;
2771 ha->device_type |= DT_IIDMA;
2772 ha->device_type |= DT_T10_PI;
2773 ha->fw_srisc_address = RISC_START_ADDRESS_2400;
2775 case PCI_DEVICE_ID_QLOGIC_ISP2271:
2776 ha->isp_type |= DT_ISP2271;
2777 ha->device_type |= DT_ZIO_SUPPORTED;
2778 ha->device_type |= DT_FWI2;
2779 ha->device_type |= DT_IIDMA;
2780 ha->device_type |= DT_T10_PI;
2781 ha->fw_srisc_address = RISC_START_ADDRESS_2400;
2783 case PCI_DEVICE_ID_QLOGIC_ISP2261:
2784 ha->isp_type |= DT_ISP2261;
2785 ha->device_type |= DT_ZIO_SUPPORTED;
2786 ha->device_type |= DT_FWI2;
2787 ha->device_type |= DT_IIDMA;
2788 ha->device_type |= DT_T10_PI;
2789 ha->fw_srisc_address = RISC_START_ADDRESS_2400;
2791 case PCI_DEVICE_ID_QLOGIC_ISP2081:
2792 case PCI_DEVICE_ID_QLOGIC_ISP2089:
2793 ha->isp_type |= DT_ISP2081;
2794 ha->device_type |= DT_ZIO_SUPPORTED;
2795 ha->device_type |= DT_FWI2;
2796 ha->device_type |= DT_IIDMA;
2797 ha->device_type |= DT_T10_PI;
2798 ha->fw_srisc_address = RISC_START_ADDRESS_2400;
2800 case PCI_DEVICE_ID_QLOGIC_ISP2281:
2801 case PCI_DEVICE_ID_QLOGIC_ISP2289:
2802 ha->isp_type |= DT_ISP2281;
2803 ha->device_type |= DT_ZIO_SUPPORTED;
2804 ha->device_type |= DT_FWI2;
2805 ha->device_type |= DT_IIDMA;
2806 ha->device_type |= DT_T10_PI;
2807 ha->fw_srisc_address = RISC_START_ADDRESS_2400;
2812 ha->port_no = ha->portnum & 1;
2814 /* Get adapter physical port no from interrupt pin register. */
2815 pci_read_config_byte(ha->pdev, PCI_INTERRUPT_PIN, &ha->port_no);
2816 if (IS_QLA25XX(ha) || IS_QLA2031(ha) ||
2817 IS_QLA27XX(ha) || IS_QLA28XX(ha))
2820 ha->port_no = !(ha->port_no & 1);
2823 ql_dbg_pci(ql_dbg_init, ha->pdev, 0x000b,
2824 "device_type=0x%x port=%d fw_srisc_address=0x%x.\n",
2825 ha->device_type, ha->port_no, ha->fw_srisc_address);
2829 qla2xxx_scan_start(struct Scsi_Host *shost)
2831 scsi_qla_host_t *vha = shost_priv(shost);
2833 if (vha->hw->flags.running_gold_fw)
2836 set_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags);
2837 set_bit(LOCAL_LOOP_UPDATE, &vha->dpc_flags);
2838 set_bit(RSCN_UPDATE, &vha->dpc_flags);
2839 set_bit(NPIV_CONFIG_NEEDED, &vha->dpc_flags);
2843 qla2xxx_scan_finished(struct Scsi_Host *shost, unsigned long time)
2845 scsi_qla_host_t *vha = shost_priv(shost);
2847 if (test_bit(UNLOADING, &vha->dpc_flags))
2851 if (time > vha->hw->loop_reset_delay * HZ)
2854 return atomic_read(&vha->loop_state) == LOOP_READY;
2857 static void qla_heartbeat_work_fn(struct work_struct *work)
2859 struct qla_hw_data *ha = container_of(work,
2860 struct qla_hw_data, heartbeat_work);
2861 struct scsi_qla_host *base_vha = pci_get_drvdata(ha->pdev);
2863 if (!ha->flags.mbox_busy && base_vha->flags.init_done)
2864 qla_no_op_mb(base_vha);
2867 static void qla2x00_iocb_work_fn(struct work_struct *work)
2869 struct scsi_qla_host *vha = container_of(work,
2870 struct scsi_qla_host, iocb_work);
2871 struct qla_hw_data *ha = vha->hw;
2872 struct scsi_qla_host *base_vha = pci_get_drvdata(ha->pdev);
2874 unsigned long flags;
2876 if (test_bit(UNLOADING, &base_vha->dpc_flags))
2879 while (!list_empty(&vha->work_list) && i > 0) {
2880 qla2x00_do_work(vha);
2884 spin_lock_irqsave(&vha->work_lock, flags);
2885 clear_bit(IOCB_WORK_ACTIVE, &vha->dpc_flags);
2886 spin_unlock_irqrestore(&vha->work_lock, flags);
2890 qla_trace_init(void)
2892 qla_trc_array = trace_array_get_by_name("qla2xxx");
2893 if (!qla_trc_array) {
2894 ql_log(ql_log_fatal, NULL, 0x0001,
2895 "Unable to create qla2xxx trace instance, instance logging will be disabled.\n");
2899 QLA_TRACE_ENABLE(qla_trc_array);
2903 qla_trace_uninit(void)
2907 trace_array_put(qla_trc_array);
2911 * PCI driver interface
2914 qla2x00_probe_one(struct pci_dev *pdev, const struct pci_device_id *id)
2917 struct Scsi_Host *host;
2918 scsi_qla_host_t *base_vha = NULL;
2919 struct qla_hw_data *ha;
2921 char fw_str[30], wq_name[30];
2922 struct scsi_host_template *sht;
2923 int bars, mem_only = 0;
2924 uint16_t req_length = 0, rsp_length = 0;
2925 struct req_que *req = NULL;
2926 struct rsp_que *rsp = NULL;
2929 bars = pci_select_bars(pdev, IORESOURCE_MEM | IORESOURCE_IO);
2930 sht = &qla2xxx_driver_template;
2931 if (pdev->device == PCI_DEVICE_ID_QLOGIC_ISP2422 ||
2932 pdev->device == PCI_DEVICE_ID_QLOGIC_ISP2432 ||
2933 pdev->device == PCI_DEVICE_ID_QLOGIC_ISP8432 ||
2934 pdev->device == PCI_DEVICE_ID_QLOGIC_ISP5422 ||
2935 pdev->device == PCI_DEVICE_ID_QLOGIC_ISP5432 ||
2936 pdev->device == PCI_DEVICE_ID_QLOGIC_ISP2532 ||
2937 pdev->device == PCI_DEVICE_ID_QLOGIC_ISP8001 ||
2938 pdev->device == PCI_DEVICE_ID_QLOGIC_ISP8021 ||
2939 pdev->device == PCI_DEVICE_ID_QLOGIC_ISP2031 ||
2940 pdev->device == PCI_DEVICE_ID_QLOGIC_ISP8031 ||
2941 pdev->device == PCI_DEVICE_ID_QLOGIC_ISPF001 ||
2942 pdev->device == PCI_DEVICE_ID_QLOGIC_ISP8044 ||
2943 pdev->device == PCI_DEVICE_ID_QLOGIC_ISP2071 ||
2944 pdev->device == PCI_DEVICE_ID_QLOGIC_ISP2271 ||
2945 pdev->device == PCI_DEVICE_ID_QLOGIC_ISP2261 ||
2946 pdev->device == PCI_DEVICE_ID_QLOGIC_ISP2081 ||
2947 pdev->device == PCI_DEVICE_ID_QLOGIC_ISP2281 ||
2948 pdev->device == PCI_DEVICE_ID_QLOGIC_ISP2089 ||
2949 pdev->device == PCI_DEVICE_ID_QLOGIC_ISP2289) {
2950 bars = pci_select_bars(pdev, IORESOURCE_MEM);
2952 ql_dbg_pci(ql_dbg_init, pdev, 0x0007,
2953 "Mem only adapter.\n");
2955 ql_dbg_pci(ql_dbg_init, pdev, 0x0008,
2956 "Bars=%d.\n", bars);
2959 if (pci_enable_device_mem(pdev))
2962 if (pci_enable_device(pdev))
2966 if (is_kdump_kernel()) {
2968 ql2xallocfwdump = 0;
2971 ha = kzalloc(sizeof(struct qla_hw_data), GFP_KERNEL);
2973 ql_log_pci(ql_log_fatal, pdev, 0x0009,
2974 "Unable to allocate memory for ha.\n");
2975 goto disable_device;
2977 ql_dbg_pci(ql_dbg_init, pdev, 0x000a,
2978 "Memory allocated for ha=%p.\n", ha);
2980 INIT_LIST_HEAD(&ha->tgt.q_full_list);
2981 spin_lock_init(&ha->tgt.q_full_lock);
2982 spin_lock_init(&ha->tgt.sess_lock);
2983 spin_lock_init(&ha->tgt.atio_lock);
2985 spin_lock_init(&ha->sadb_lock);
2986 INIT_LIST_HEAD(&ha->sadb_tx_index_list);
2987 INIT_LIST_HEAD(&ha->sadb_rx_index_list);
2989 spin_lock_init(&ha->sadb_fp_lock);
2991 if (qla_edif_sadb_build_free_pool(ha)) {
2993 goto disable_device;
2996 atomic_set(&ha->nvme_active_aen_cnt, 0);
2998 /* Clear our data area */
3000 ha->mem_only = mem_only;
3001 spin_lock_init(&ha->hardware_lock);
3002 spin_lock_init(&ha->vport_slock);
3003 mutex_init(&ha->selflogin_lock);
3004 mutex_init(&ha->optrom_mutex);
3006 /* Set ISP-type information. */
3007 qla2x00_set_isp_flags(ha);
3009 /* Set EEH reset type to fundamental if required by hba */
3010 if (IS_QLA24XX(ha) || IS_QLA25XX(ha) || IS_QLA81XX(ha) ||
3011 IS_QLA83XX(ha) || IS_QLA27XX(ha) || IS_QLA28XX(ha))
3012 pdev->needs_freset = 1;
3014 ha->prev_topology = 0;
3015 ha->init_cb_size = sizeof(init_cb_t);
3016 ha->link_data_rate = PORT_SPEED_UNKNOWN;
3017 ha->optrom_size = OPTROM_SIZE_2300;
3018 ha->max_exchg = FW_MAX_EXCHANGES_CNT;
3019 atomic_set(&ha->num_pend_mbx_stage1, 0);
3020 atomic_set(&ha->num_pend_mbx_stage2, 0);
3021 atomic_set(&ha->zio_threshold, DEFAULT_ZIO_THRESHOLD);
3022 ha->last_zio_threshold = DEFAULT_ZIO_THRESHOLD;
3023 INIT_LIST_HEAD(&ha->tmf_pending);
3024 INIT_LIST_HEAD(&ha->tmf_active);
3026 /* Assign ISP specific operations. */
3027 if (IS_QLA2100(ha)) {
3028 ha->max_fibre_devices = MAX_FIBRE_DEVICES_2100;
3029 ha->mbx_count = MAILBOX_REGISTER_COUNT_2100;
3030 req_length = REQUEST_ENTRY_CNT_2100;
3031 rsp_length = RESPONSE_ENTRY_CNT_2100;
3032 ha->max_loop_id = SNS_LAST_LOOP_ID_2100;
3033 ha->gid_list_info_size = 4;
3034 ha->flash_conf_off = ~0;
3035 ha->flash_data_off = ~0;
3036 ha->nvram_conf_off = ~0;
3037 ha->nvram_data_off = ~0;
3038 ha->isp_ops = &qla2100_isp_ops;
3039 } else if (IS_QLA2200(ha)) {
3040 ha->max_fibre_devices = MAX_FIBRE_DEVICES_2100;
3041 ha->mbx_count = MAILBOX_REGISTER_COUNT_2200;
3042 req_length = REQUEST_ENTRY_CNT_2200;
3043 rsp_length = RESPONSE_ENTRY_CNT_2100;
3044 ha->max_loop_id = SNS_LAST_LOOP_ID_2100;
3045 ha->gid_list_info_size = 4;
3046 ha->flash_conf_off = ~0;
3047 ha->flash_data_off = ~0;
3048 ha->nvram_conf_off = ~0;
3049 ha->nvram_data_off = ~0;
3050 ha->isp_ops = &qla2100_isp_ops;
3051 } else if (IS_QLA23XX(ha)) {
3052 ha->max_fibre_devices = MAX_FIBRE_DEVICES_2100;
3053 ha->mbx_count = MAILBOX_REGISTER_COUNT;
3054 req_length = REQUEST_ENTRY_CNT_2200;
3055 rsp_length = RESPONSE_ENTRY_CNT_2300;
3056 ha->max_loop_id = SNS_LAST_LOOP_ID_2300;
3057 ha->gid_list_info_size = 6;
3058 if (IS_QLA2322(ha) || IS_QLA6322(ha))
3059 ha->optrom_size = OPTROM_SIZE_2322;
3060 ha->flash_conf_off = ~0;
3061 ha->flash_data_off = ~0;
3062 ha->nvram_conf_off = ~0;
3063 ha->nvram_data_off = ~0;
3064 ha->isp_ops = &qla2300_isp_ops;
3065 } else if (IS_QLA24XX_TYPE(ha)) {
3066 ha->max_fibre_devices = MAX_FIBRE_DEVICES_2400;
3067 ha->mbx_count = MAILBOX_REGISTER_COUNT;
3068 req_length = REQUEST_ENTRY_CNT_24XX;
3069 rsp_length = RESPONSE_ENTRY_CNT_2300;
3070 ha->tgt.atio_q_length = ATIO_ENTRY_CNT_24XX;
3071 ha->max_loop_id = SNS_LAST_LOOP_ID_2300;
3072 ha->init_cb_size = sizeof(struct mid_init_cb_24xx);
3073 ha->gid_list_info_size = 8;
3074 ha->optrom_size = OPTROM_SIZE_24XX;
3075 ha->nvram_npiv_size = QLA_MAX_VPORTS_QLA24XX;
3076 ha->isp_ops = &qla24xx_isp_ops;
3077 ha->flash_conf_off = FARX_ACCESS_FLASH_CONF;
3078 ha->flash_data_off = FARX_ACCESS_FLASH_DATA;
3079 ha->nvram_conf_off = FARX_ACCESS_NVRAM_CONF;
3080 ha->nvram_data_off = FARX_ACCESS_NVRAM_DATA;
3081 } else if (IS_QLA25XX(ha)) {
3082 ha->max_fibre_devices = MAX_FIBRE_DEVICES_2400;
3083 ha->mbx_count = MAILBOX_REGISTER_COUNT;
3084 req_length = REQUEST_ENTRY_CNT_24XX;
3085 rsp_length = RESPONSE_ENTRY_CNT_2300;
3086 ha->tgt.atio_q_length = ATIO_ENTRY_CNT_24XX;
3087 ha->max_loop_id = SNS_LAST_LOOP_ID_2300;
3088 ha->init_cb_size = sizeof(struct mid_init_cb_24xx);
3089 ha->gid_list_info_size = 8;
3090 ha->optrom_size = OPTROM_SIZE_25XX;
3091 ha->nvram_npiv_size = QLA_MAX_VPORTS_QLA25XX;
3092 ha->isp_ops = &qla25xx_isp_ops;
3093 ha->flash_conf_off = FARX_ACCESS_FLASH_CONF;
3094 ha->flash_data_off = FARX_ACCESS_FLASH_DATA;
3095 ha->nvram_conf_off = FARX_ACCESS_NVRAM_CONF;
3096 ha->nvram_data_off = FARX_ACCESS_NVRAM_DATA;
3097 } else if (IS_QLA81XX(ha)) {
3098 ha->max_fibre_devices = MAX_FIBRE_DEVICES_2400;
3099 ha->mbx_count = MAILBOX_REGISTER_COUNT;
3100 req_length = REQUEST_ENTRY_CNT_24XX;
3101 rsp_length = RESPONSE_ENTRY_CNT_2300;
3102 ha->tgt.atio_q_length = ATIO_ENTRY_CNT_24XX;
3103 ha->max_loop_id = SNS_LAST_LOOP_ID_2300;
3104 ha->init_cb_size = sizeof(struct mid_init_cb_81xx);
3105 ha->gid_list_info_size = 8;
3106 ha->optrom_size = OPTROM_SIZE_81XX;
3107 ha->nvram_npiv_size = QLA_MAX_VPORTS_QLA25XX;
3108 ha->isp_ops = &qla81xx_isp_ops;
3109 ha->flash_conf_off = FARX_ACCESS_FLASH_CONF_81XX;
3110 ha->flash_data_off = FARX_ACCESS_FLASH_DATA_81XX;
3111 ha->nvram_conf_off = ~0;
3112 ha->nvram_data_off = ~0;
3113 } else if (IS_QLA82XX(ha)) {
3114 ha->max_fibre_devices = MAX_FIBRE_DEVICES_2400;
3115 ha->mbx_count = MAILBOX_REGISTER_COUNT;
3116 req_length = REQUEST_ENTRY_CNT_82XX;
3117 rsp_length = RESPONSE_ENTRY_CNT_82XX;
3118 ha->max_loop_id = SNS_LAST_LOOP_ID_2300;
3119 ha->init_cb_size = sizeof(struct mid_init_cb_81xx);
3120 ha->gid_list_info_size = 8;
3121 ha->optrom_size = OPTROM_SIZE_82XX;
3122 ha->nvram_npiv_size = QLA_MAX_VPORTS_QLA25XX;
3123 ha->isp_ops = &qla82xx_isp_ops;
3124 ha->flash_conf_off = FARX_ACCESS_FLASH_CONF;
3125 ha->flash_data_off = FARX_ACCESS_FLASH_DATA;
3126 ha->nvram_conf_off = FARX_ACCESS_NVRAM_CONF;
3127 ha->nvram_data_off = FARX_ACCESS_NVRAM_DATA;
3128 } else if (IS_QLA8044(ha)) {
3129 ha->max_fibre_devices = MAX_FIBRE_DEVICES_2400;
3130 ha->mbx_count = MAILBOX_REGISTER_COUNT;
3131 req_length = REQUEST_ENTRY_CNT_82XX;
3132 rsp_length = RESPONSE_ENTRY_CNT_82XX;
3133 ha->max_loop_id = SNS_LAST_LOOP_ID_2300;
3134 ha->init_cb_size = sizeof(struct mid_init_cb_81xx);
3135 ha->gid_list_info_size = 8;
3136 ha->optrom_size = OPTROM_SIZE_83XX;
3137 ha->nvram_npiv_size = QLA_MAX_VPORTS_QLA25XX;
3138 ha->isp_ops = &qla8044_isp_ops;
3139 ha->flash_conf_off = FARX_ACCESS_FLASH_CONF;
3140 ha->flash_data_off = FARX_ACCESS_FLASH_DATA;
3141 ha->nvram_conf_off = FARX_ACCESS_NVRAM_CONF;
3142 ha->nvram_data_off = FARX_ACCESS_NVRAM_DATA;
3143 } else if (IS_QLA83XX(ha)) {
3144 ha->portnum = PCI_FUNC(ha->pdev->devfn);
3145 ha->max_fibre_devices = MAX_FIBRE_DEVICES_2400;
3146 ha->mbx_count = MAILBOX_REGISTER_COUNT;
3147 req_length = REQUEST_ENTRY_CNT_83XX;
3148 rsp_length = RESPONSE_ENTRY_CNT_83XX;
3149 ha->tgt.atio_q_length = ATIO_ENTRY_CNT_24XX;
3150 ha->max_loop_id = SNS_LAST_LOOP_ID_2300;
3151 ha->init_cb_size = sizeof(struct mid_init_cb_81xx);
3152 ha->gid_list_info_size = 8;
3153 ha->optrom_size = OPTROM_SIZE_83XX;
3154 ha->nvram_npiv_size = QLA_MAX_VPORTS_QLA25XX;
3155 ha->isp_ops = &qla83xx_isp_ops;
3156 ha->flash_conf_off = FARX_ACCESS_FLASH_CONF_81XX;
3157 ha->flash_data_off = FARX_ACCESS_FLASH_DATA_81XX;
3158 ha->nvram_conf_off = ~0;
3159 ha->nvram_data_off = ~0;
3160 } else if (IS_QLAFX00(ha)) {
3161 ha->max_fibre_devices = MAX_FIBRE_DEVICES_FX00;
3162 ha->mbx_count = MAILBOX_REGISTER_COUNT_FX00;
3163 ha->aen_mbx_count = AEN_MAILBOX_REGISTER_COUNT_FX00;
3164 req_length = REQUEST_ENTRY_CNT_FX00;
3165 rsp_length = RESPONSE_ENTRY_CNT_FX00;
3166 ha->isp_ops = &qlafx00_isp_ops;
3167 ha->port_down_retry_count = 30; /* default value */
3168 ha->mr.fw_hbt_cnt = QLAFX00_HEARTBEAT_INTERVAL;
3169 ha->mr.fw_reset_timer_tick = QLAFX00_RESET_INTERVAL;
3170 ha->mr.fw_critemp_timer_tick = QLAFX00_CRITEMP_INTERVAL;
3171 ha->mr.fw_hbt_en = 1;
3172 ha->mr.host_info_resend = false;
3173 ha->mr.hinfo_resend_timer_tick = QLAFX00_HINFO_RESEND_INTERVAL;
3174 } else if (IS_QLA27XX(ha)) {
3175 ha->portnum = PCI_FUNC(ha->pdev->devfn);
3176 ha->max_fibre_devices = MAX_FIBRE_DEVICES_2400;
3177 ha->mbx_count = MAILBOX_REGISTER_COUNT;
3178 req_length = REQUEST_ENTRY_CNT_83XX;
3179 rsp_length = RESPONSE_ENTRY_CNT_83XX;
3180 ha->tgt.atio_q_length = ATIO_ENTRY_CNT_24XX;
3181 ha->max_loop_id = SNS_LAST_LOOP_ID_2300;
3182 ha->init_cb_size = sizeof(struct mid_init_cb_81xx);
3183 ha->gid_list_info_size = 8;
3184 ha->optrom_size = OPTROM_SIZE_83XX;
3185 ha->nvram_npiv_size = QLA_MAX_VPORTS_QLA25XX;
3186 ha->isp_ops = &qla27xx_isp_ops;
3187 ha->flash_conf_off = FARX_ACCESS_FLASH_CONF_81XX;
3188 ha->flash_data_off = FARX_ACCESS_FLASH_DATA_81XX;
3189 ha->nvram_conf_off = ~0;
3190 ha->nvram_data_off = ~0;
3191 } else if (IS_QLA28XX(ha)) {
3192 ha->portnum = PCI_FUNC(ha->pdev->devfn);
3193 ha->max_fibre_devices = MAX_FIBRE_DEVICES_2400;
3194 ha->mbx_count = MAILBOX_REGISTER_COUNT;
3195 req_length = REQUEST_ENTRY_CNT_83XX;
3196 rsp_length = RESPONSE_ENTRY_CNT_83XX;
3197 ha->tgt.atio_q_length = ATIO_ENTRY_CNT_24XX;
3198 ha->max_loop_id = SNS_LAST_LOOP_ID_2300;
3199 ha->init_cb_size = sizeof(struct mid_init_cb_81xx);
3200 ha->gid_list_info_size = 8;
3201 ha->optrom_size = OPTROM_SIZE_28XX;
3202 ha->nvram_npiv_size = QLA_MAX_VPORTS_QLA25XX;
3203 ha->isp_ops = &qla27xx_isp_ops;
3204 ha->flash_conf_off = FARX_ACCESS_FLASH_CONF_28XX;
3205 ha->flash_data_off = FARX_ACCESS_FLASH_DATA_28XX;
3206 ha->nvram_conf_off = ~0;
3207 ha->nvram_data_off = ~0;
3210 ql_dbg_pci(ql_dbg_init, pdev, 0x001e,
3211 "mbx_count=%d, req_length=%d, "
3212 "rsp_length=%d, max_loop_id=%d, init_cb_size=%d, "
3213 "gid_list_info_size=%d, optrom_size=%d, nvram_npiv_size=%d, "
3214 "max_fibre_devices=%d.\n",
3215 ha->mbx_count, req_length, rsp_length, ha->max_loop_id,
3216 ha->init_cb_size, ha->gid_list_info_size, ha->optrom_size,
3217 ha->nvram_npiv_size, ha->max_fibre_devices);
3218 ql_dbg_pci(ql_dbg_init, pdev, 0x001f,
3219 "isp_ops=%p, flash_conf_off=%d, "
3220 "flash_data_off=%d, nvram_conf_off=%d, nvram_data_off=%d.\n",
3221 ha->isp_ops, ha->flash_conf_off, ha->flash_data_off,
3222 ha->nvram_conf_off, ha->nvram_data_off);
3224 /* Configure PCI I/O space */
3225 ret = ha->isp_ops->iospace_config(ha);
3227 goto iospace_config_failed;
3229 ql_log_pci(ql_log_info, pdev, 0x001d,
3230 "Found an ISP%04X irq %d iobase 0x%p.\n",
3231 pdev->device, pdev->irq, ha->iobase);
3232 mutex_init(&ha->vport_lock);
3233 mutex_init(&ha->mq_lock);
3234 init_completion(&ha->mbx_cmd_comp);
3235 complete(&ha->mbx_cmd_comp);
3236 init_completion(&ha->mbx_intr_comp);
3237 init_completion(&ha->dcbx_comp);
3238 init_completion(&ha->lb_portup_comp);
3240 set_bit(0, (unsigned long *) ha->vp_idx_map);
3242 qla2x00_config_dma_addressing(ha);
3243 ql_dbg_pci(ql_dbg_init, pdev, 0x0020,
3244 "64 Bit addressing is %s.\n",
3245 ha->flags.enable_64bit_addressing ? "enable" :
3247 ret = qla2x00_mem_alloc(ha, req_length, rsp_length, &req, &rsp);
3249 ql_log_pci(ql_log_fatal, pdev, 0x0031,
3250 "Failed to allocate memory for adapter, aborting.\n");
3252 goto probe_hw_failed;
3255 req->max_q_depth = MAX_Q_DEPTH;
3256 if (ql2xmaxqdepth != 0 && ql2xmaxqdepth <= 0xffffU)
3257 req->max_q_depth = ql2xmaxqdepth;
3260 base_vha = qla2x00_create_host(sht, ha);
3263 goto probe_hw_failed;
3266 pci_set_drvdata(pdev, base_vha);
3267 set_bit(PFLG_DRIVER_PROBING, &base_vha->pci_flags);
3269 host = base_vha->host;
3270 base_vha->req = req;
3271 if (IS_QLA2XXX_MIDTYPE(ha))
3272 base_vha->mgmt_svr_loop_id =
3273 qla2x00_reserve_mgmt_server_loop_id(base_vha);
3275 base_vha->mgmt_svr_loop_id = MANAGEMENT_SERVER +
3278 /* Setup fcport template structure. */
3279 ha->mr.fcport.vha = base_vha;
3280 ha->mr.fcport.port_type = FCT_UNKNOWN;
3281 ha->mr.fcport.loop_id = FC_NO_LOOP_ID;
3282 qla2x00_set_fcport_state(&ha->mr.fcport, FCS_UNCONFIGURED);
3283 ha->mr.fcport.supported_classes = FC_COS_UNSPECIFIED;
3284 ha->mr.fcport.scan_state = 1;
3286 qla2xxx_reset_stats(host, QLA2XX_HW_ERROR | QLA2XX_SHT_LNK_DWN |
3287 QLA2XX_INT_ERR | QLA2XX_CMD_TIMEOUT |
3288 QLA2XX_RESET_CMD_ERR | QLA2XX_TGT_SHT_LNK_DOWN);
3290 /* Set the SG table size based on ISP type */
3291 if (!IS_FWI2_CAPABLE(ha)) {
3293 host->sg_tablesize = 32;
3295 if (!IS_QLA82XX(ha))
3296 host->sg_tablesize = QLA_SG_ALL;
3298 host->max_id = ha->max_fibre_devices;
3299 host->cmd_per_lun = 3;
3300 host->unique_id = host->host_no;
3302 if (ql2xenabledif && ql2xenabledif != 2) {
3303 ql_log(ql_log_warn, base_vha, 0x302d,
3304 "Invalid value for ql2xenabledif, resetting it to default (2)\n");
3308 if (IS_T10_PI_CAPABLE(ha) && ql2xenabledif)
3309 host->max_cmd_len = 32;
3311 host->max_cmd_len = MAX_CMDSZ;
3312 host->max_channel = MAX_BUSES - 1;
3313 /* Older HBAs support only 16-bit LUNs */
3314 if (!IS_QLAFX00(ha) && !IS_FWI2_CAPABLE(ha) &&
3315 ql2xmaxlun > 0xffff)
3316 host->max_lun = 0xffff;
3318 host->max_lun = ql2xmaxlun;
3319 host->transportt = qla2xxx_transport_template;
3320 sht->vendor_id = (SCSI_NL_VID_TYPE_PCI | PCI_VENDOR_ID_QLOGIC);
3322 ql_dbg(ql_dbg_init, base_vha, 0x0033,
3323 "max_id=%d this_id=%d "
3324 "cmd_per_len=%d unique_id=%d max_cmd_len=%d max_channel=%d "
3325 "max_lun=%llu transportt=%p, vendor_id=%llu.\n", host->max_id,
3326 host->this_id, host->cmd_per_lun, host->unique_id,
3327 host->max_cmd_len, host->max_channel, host->max_lun,
3328 host->transportt, sht->vendor_id);
3330 INIT_WORK(&ha->heartbeat_work, qla_heartbeat_work_fn);
3332 /* Set up the irqs */
3333 ret = qla2x00_request_irqs(ha, rsp);
3337 /* Alloc arrays of request and response ring ptrs */
3338 ret = qla2x00_alloc_queues(ha, req, rsp);
3340 ql_log(ql_log_fatal, base_vha, 0x003d,
3341 "Failed to allocate memory for queue pointers..."
3348 /* number of hardware queues supported by blk/scsi-mq*/
3349 host->nr_hw_queues = ha->max_qpairs;
3351 ql_dbg(ql_dbg_init, base_vha, 0x0192,
3352 "blk/scsi-mq enabled, HW queues = %d.\n", host->nr_hw_queues);
3354 if (ql2xnvmeenable) {
3355 host->nr_hw_queues = ha->max_qpairs;
3356 ql_dbg(ql_dbg_init, base_vha, 0x0194,
3357 "FC-NVMe support is enabled, HW queues=%d\n",
3358 host->nr_hw_queues);
3360 ql_dbg(ql_dbg_init, base_vha, 0x0193,
3361 "blk/scsi-mq disabled.\n");
3365 qlt_probe_one_stage1(base_vha, ha);
3367 pci_save_state(pdev);
3369 /* Assign back pointers */
3373 if (IS_QLAFX00(ha)) {
3374 ha->rsp_q_map[0] = rsp;
3375 ha->req_q_map[0] = req;
3376 set_bit(0, ha->req_qid_map);
3377 set_bit(0, ha->rsp_qid_map);
3380 /* FWI2-capable only. */
3381 req->req_q_in = &ha->iobase->isp24.req_q_in;
3382 req->req_q_out = &ha->iobase->isp24.req_q_out;
3383 rsp->rsp_q_in = &ha->iobase->isp24.rsp_q_in;
3384 rsp->rsp_q_out = &ha->iobase->isp24.rsp_q_out;
3385 if (ha->mqenable || IS_QLA83XX(ha) || IS_QLA27XX(ha) ||
3387 req->req_q_in = &ha->mqiobase->isp25mq.req_q_in;
3388 req->req_q_out = &ha->mqiobase->isp25mq.req_q_out;
3389 rsp->rsp_q_in = &ha->mqiobase->isp25mq.rsp_q_in;
3390 rsp->rsp_q_out = &ha->mqiobase->isp25mq.rsp_q_out;
3393 if (IS_QLAFX00(ha)) {
3394 req->req_q_in = &ha->iobase->ispfx00.req_q_in;
3395 req->req_q_out = &ha->iobase->ispfx00.req_q_out;
3396 rsp->rsp_q_in = &ha->iobase->ispfx00.rsp_q_in;
3397 rsp->rsp_q_out = &ha->iobase->ispfx00.rsp_q_out;
3400 if (IS_P3P_TYPE(ha)) {
3401 req->req_q_out = &ha->iobase->isp82.req_q_out[0];
3402 rsp->rsp_q_in = &ha->iobase->isp82.rsp_q_in[0];
3403 rsp->rsp_q_out = &ha->iobase->isp82.rsp_q_out[0];
3406 ql_dbg(ql_dbg_multiq, base_vha, 0xc009,
3407 "rsp_q_map=%p req_q_map=%p rsp->req=%p req->rsp=%p.\n",
3408 ha->rsp_q_map, ha->req_q_map, rsp->req, req->rsp);
3409 ql_dbg(ql_dbg_multiq, base_vha, 0xc00a,
3410 "req->req_q_in=%p req->req_q_out=%p "
3411 "rsp->rsp_q_in=%p rsp->rsp_q_out=%p.\n",
3412 req->req_q_in, req->req_q_out,
3413 rsp->rsp_q_in, rsp->rsp_q_out);
3414 ql_dbg(ql_dbg_init, base_vha, 0x003e,
3415 "rsp_q_map=%p req_q_map=%p rsp->req=%p req->rsp=%p.\n",
3416 ha->rsp_q_map, ha->req_q_map, rsp->req, req->rsp);
3417 ql_dbg(ql_dbg_init, base_vha, 0x003f,
3418 "req->req_q_in=%p req->req_q_out=%p rsp->rsp_q_in=%p rsp->rsp_q_out=%p.\n",
3419 req->req_q_in, req->req_q_out, rsp->rsp_q_in, rsp->rsp_q_out);
3421 ha->wq = alloc_workqueue("qla2xxx_wq", WQ_MEM_RECLAIM, 0);
3422 if (unlikely(!ha->wq)) {
3427 if (ha->isp_ops->initialize_adapter(base_vha)) {
3428 ql_log(ql_log_fatal, base_vha, 0x00d6,
3429 "Failed to initialize adapter - Adapter flags %x.\n",
3430 base_vha->device_flags);
3432 if (IS_QLA82XX(ha)) {
3433 qla82xx_idc_lock(ha);
3434 qla82xx_wr_32(ha, QLA82XX_CRB_DEV_STATE,
3435 QLA8XXX_DEV_FAILED);
3436 qla82xx_idc_unlock(ha);
3437 ql_log(ql_log_fatal, base_vha, 0x00d7,
3438 "HW State: FAILED.\n");
3439 } else if (IS_QLA8044(ha)) {
3440 qla8044_idc_lock(ha);
3441 qla8044_wr_direct(base_vha,
3442 QLA8044_CRB_DEV_STATE_INDEX,
3443 QLA8XXX_DEV_FAILED);
3444 qla8044_idc_unlock(ha);
3445 ql_log(ql_log_fatal, base_vha, 0x0150,
3446 "HW State: FAILED.\n");
3454 host->can_queue = QLAFX00_MAX_CANQUEUE;
3456 host->can_queue = req->num_outstanding_cmds - 10;
3458 ql_dbg(ql_dbg_init, base_vha, 0x0032,
3459 "can_queue=%d, req=%p, mgmt_svr_loop_id=%d, sg_tablesize=%d.\n",
3460 host->can_queue, base_vha->req,
3461 base_vha->mgmt_svr_loop_id, host->sg_tablesize);
3463 /* Check if FW supports MQ or not for ISP25xx */
3464 if (IS_QLA25XX(ha) && !(ha->fw_attributes & BIT_6))
3468 bool startit = false;
3470 if (QLA_TGT_MODE_ENABLED())
3473 if (ql2x_ini_mode == QLA2XXX_INI_MODE_ENABLED)
3476 /* Create start of day qpairs for Block MQ */
3477 for (i = 0; i < ha->max_qpairs; i++)
3478 qla2xxx_create_qpair(base_vha, 5, 0, startit);
3480 qla_init_iocb_limit(base_vha);
3482 if (ha->flags.running_gold_fw)
3486 * Startup the kernel thread for this host adapter
3488 ha->dpc_thread = kthread_create(qla2x00_do_dpc, ha,
3489 "%s_dpc", base_vha->host_str);
3490 if (IS_ERR(ha->dpc_thread)) {
3491 ql_log(ql_log_fatal, base_vha, 0x00ed,
3492 "Failed to start DPC thread.\n");
3493 ret = PTR_ERR(ha->dpc_thread);
3494 ha->dpc_thread = NULL;
3497 ql_dbg(ql_dbg_init, base_vha, 0x00ee,
3498 "DPC thread started successfully.\n");
3501 * If we're not coming up in initiator mode, we might sit for
3502 * a while without waking up the dpc thread, which leads to a
3503 * stuck process warning. So just kick the dpc once here and
3504 * let the kthread start (and go back to sleep in qla2x00_do_dpc).
3506 qla2xxx_wake_dpc(base_vha);
3508 INIT_WORK(&ha->board_disable, qla2x00_disable_board_on_pci_error);
3510 if (IS_QLA8031(ha) || IS_MCTP_CAPABLE(ha)) {
3511 sprintf(wq_name, "qla2xxx_%lu_dpc_lp_wq", base_vha->host_no);
3512 ha->dpc_lp_wq = create_singlethread_workqueue(wq_name);
3513 INIT_WORK(&ha->idc_aen, qla83xx_service_idc_aen);
3515 sprintf(wq_name, "qla2xxx_%lu_dpc_hp_wq", base_vha->host_no);
3516 ha->dpc_hp_wq = create_singlethread_workqueue(wq_name);
3517 INIT_WORK(&ha->nic_core_reset, qla83xx_nic_core_reset_work);
3518 INIT_WORK(&ha->idc_state_handler,
3519 qla83xx_idc_state_handler_work);
3520 INIT_WORK(&ha->nic_core_unrecoverable,
3521 qla83xx_nic_core_unrecoverable_work);
3525 list_add_tail(&base_vha->list, &ha->vp_list);
3526 base_vha->host->irq = ha->pdev->irq;
3528 /* Initialized the timer */
3529 qla2x00_start_timer(base_vha, WATCH_INTERVAL);
3530 ql_dbg(ql_dbg_init, base_vha, 0x00ef,
3531 "Started qla2x00_timer with "
3532 "interval=%d.\n", WATCH_INTERVAL);
3533 ql_dbg(ql_dbg_init, base_vha, 0x00f0,
3534 "Detected hba at address=%p.\n",
3537 if (IS_T10_PI_CAPABLE(ha) && ql2xenabledif) {
3538 if (ha->fw_attributes & BIT_4) {
3539 int prot = 0, guard;
3541 base_vha->flags.difdix_supported = 1;
3542 ql_dbg(ql_dbg_init, base_vha, 0x00f1,
3543 "Registering for DIF/DIX type 1 and 3 protection.\n");
3545 scsi_host_set_prot(host, ql2xprotmask);
3547 scsi_host_set_prot(host,
3548 prot | SHOST_DIF_TYPE1_PROTECTION
3549 | SHOST_DIF_TYPE2_PROTECTION
3550 | SHOST_DIF_TYPE3_PROTECTION
3551 | SHOST_DIX_TYPE1_PROTECTION
3552 | SHOST_DIX_TYPE2_PROTECTION
3553 | SHOST_DIX_TYPE3_PROTECTION);
3555 guard = SHOST_DIX_GUARD_CRC;
3557 if (IS_PI_IPGUARD_CAPABLE(ha) &&
3558 (ql2xenabledif > 1 || IS_PI_DIFB_DIX0_CAPABLE(ha)))
3559 guard |= SHOST_DIX_GUARD_IP;
3562 scsi_host_set_guard(host, ql2xprotguard);
3564 scsi_host_set_guard(host, guard);
3566 base_vha->flags.difdix_supported = 0;
3569 ha->isp_ops->enable_intrs(ha);
3571 if (IS_QLAFX00(ha)) {
3572 ret = qlafx00_fx_disc(base_vha,
3573 &base_vha->hw->mr.fcport, FXDISC_GET_CONFIG_INFO);
3574 host->sg_tablesize = (ha->mr.extended_io_enabled) ?
3578 ret = scsi_add_host(host, &pdev->dev);
3582 base_vha->flags.init_done = 1;
3583 base_vha->flags.online = 1;
3584 ha->prev_minidump_failed = 0;
3586 ql_dbg(ql_dbg_init, base_vha, 0x00f2,
3587 "Init done and hba is online.\n");
3589 if (qla_ini_mode_enabled(base_vha) ||
3590 qla_dual_mode_enabled(base_vha))
3591 scsi_scan_host(host);
3593 ql_log(ql_log_info, base_vha, 0x0122,
3594 "skipping scsi_scan_host() for non-initiator port\n");
3596 qla2x00_alloc_sysfs_attr(base_vha);
3598 if (IS_QLAFX00(ha)) {
3599 ret = qlafx00_fx_disc(base_vha,
3600 &base_vha->hw->mr.fcport, FXDISC_GET_PORT_INFO);
3602 /* Register system information */
3603 ret = qlafx00_fx_disc(base_vha,
3604 &base_vha->hw->mr.fcport, FXDISC_REG_HOST_INFO);
3607 qla2x00_init_host_attr(base_vha);
3609 qla2x00_dfs_setup(base_vha);
3611 ql_log(ql_log_info, base_vha, 0x00fb,
3612 "QLogic %s - %s.\n", ha->model_number, ha->model_desc);
3613 ql_log(ql_log_info, base_vha, 0x00fc,
3614 "ISP%04X: %s @ %s hdma%c host#=%ld fw=%s.\n",
3615 pdev->device, ha->isp_ops->pci_info_str(base_vha, pci_info,
3617 pci_name(pdev), ha->flags.enable_64bit_addressing ? '+' : '-',
3619 ha->isp_ops->fw_version_str(base_vha, fw_str, sizeof(fw_str)));
3621 qlt_add_target(ha, base_vha);
3623 clear_bit(PFLG_DRIVER_PROBING, &base_vha->pci_flags);
3625 if (test_bit(UNLOADING, &base_vha->dpc_flags))
3631 qla_enode_stop(base_vha);
3632 qla_edb_stop(base_vha);
3633 vfree(base_vha->scan.l);
3634 if (base_vha->gnl.l) {
3635 dma_free_coherent(&ha->pdev->dev, base_vha->gnl.size,
3636 base_vha->gnl.l, base_vha->gnl.ldma);
3637 base_vha->gnl.l = NULL;
3640 if (base_vha->timer_active)
3641 qla2x00_stop_timer(base_vha);
3642 base_vha->flags.online = 0;
3643 if (ha->dpc_thread) {
3644 struct task_struct *t = ha->dpc_thread;
3646 ha->dpc_thread = NULL;
3650 qla2x00_free_device(base_vha);
3651 scsi_host_put(base_vha->host);
3653 * Need to NULL out local req/rsp after
3654 * qla2x00_free_device => qla2x00_free_queues frees
3655 * what these are pointing to. Or else we'll
3656 * fall over below in qla2x00_free_req/rsp_que.
3662 qla2x00_mem_free(ha);
3663 qla2x00_free_req_que(ha, req);
3664 qla2x00_free_rsp_que(ha, rsp);
3665 qla2x00_clear_drv_active(ha);
3667 iospace_config_failed:
3668 if (IS_P3P_TYPE(ha)) {
3669 if (!ha->nx_pcibase)
3670 iounmap((device_reg_t *)ha->nx_pcibase);
3672 iounmap((device_reg_t *)ha->nxdb_wr_ptr);
3675 iounmap(ha->iobase);
3677 iounmap(ha->cregbase);
3679 pci_release_selected_regions(ha->pdev, ha->bars);
3683 pci_disable_device(pdev);
3687 static void __qla_set_remove_flag(scsi_qla_host_t *base_vha)
3689 scsi_qla_host_t *vp;
3690 unsigned long flags;
3691 struct qla_hw_data *ha;
3698 spin_lock_irqsave(&ha->vport_slock, flags);
3699 list_for_each_entry(vp, &ha->vp_list, list)
3700 set_bit(PFLG_DRIVER_REMOVING, &vp->pci_flags);
3703 * Indicate device removal to prevent future board_disable
3704 * and wait until any pending board_disable has completed.
3706 set_bit(PFLG_DRIVER_REMOVING, &base_vha->pci_flags);
3707 spin_unlock_irqrestore(&ha->vport_slock, flags);
3711 qla2x00_shutdown(struct pci_dev *pdev)
3713 scsi_qla_host_t *vha;
3714 struct qla_hw_data *ha;
3716 vha = pci_get_drvdata(pdev);
3719 ql_log(ql_log_info, vha, 0xfffa,
3720 "Adapter shutdown\n");
3723 * Prevent future board_disable and wait
3724 * until any pending board_disable has completed.
3726 __qla_set_remove_flag(vha);
3727 cancel_work_sync(&ha->board_disable);
3729 if (!atomic_read(&pdev->enable_cnt))
3732 /* Notify ISPFX00 firmware */
3734 qlafx00_driver_shutdown(vha, 20);
3736 /* Turn-off FCE trace */
3737 if (ha->flags.fce_enabled) {
3738 qla2x00_disable_fce_trace(vha, NULL, NULL);
3739 ha->flags.fce_enabled = 0;
3742 /* Turn-off EFT trace */
3744 qla2x00_disable_eft_trace(vha);
3746 if (IS_QLA25XX(ha) || IS_QLA2031(ha) || IS_QLA27XX(ha) ||
3748 if (ha->flags.fw_started)
3749 qla2x00_abort_isp_cleanup(vha);
3751 /* Stop currently executing firmware. */
3752 qla2x00_try_to_stop_firmware(vha);
3756 if (vha->timer_active)
3757 qla2x00_stop_timer(vha);
3759 /* Turn adapter off line */
3760 vha->flags.online = 0;
3762 /* turn-off interrupts on the card */
3763 if (ha->interrupts_on) {
3764 vha->flags.init_done = 0;
3765 ha->isp_ops->disable_intrs(ha);
3768 qla2x00_free_irqs(vha);
3770 qla2x00_free_fw_dump(ha);
3772 pci_disable_device(pdev);
3773 ql_log(ql_log_info, vha, 0xfffe,
3774 "Adapter shutdown successfully.\n");
3777 /* Deletes all the virtual ports for a given ha */
3779 qla2x00_delete_all_vps(struct qla_hw_data *ha, scsi_qla_host_t *base_vha)
3781 scsi_qla_host_t *vha;
3782 unsigned long flags;
3784 mutex_lock(&ha->vport_lock);
3785 while (ha->cur_vport_count) {
3786 spin_lock_irqsave(&ha->vport_slock, flags);
3788 BUG_ON(base_vha->list.next == &ha->vp_list);
3789 /* This assumes first entry in ha->vp_list is always base vha */
3790 vha = list_first_entry(&base_vha->list, scsi_qla_host_t, list);
3791 scsi_host_get(vha->host);
3793 spin_unlock_irqrestore(&ha->vport_slock, flags);
3794 mutex_unlock(&ha->vport_lock);
3796 qla_nvme_delete(vha);
3798 fc_vport_terminate(vha->fc_vport);
3799 scsi_host_put(vha->host);
3801 mutex_lock(&ha->vport_lock);
3803 mutex_unlock(&ha->vport_lock);
3806 /* Stops all deferred work threads */
3808 qla2x00_destroy_deferred_work(struct qla_hw_data *ha)
3810 /* Cancel all work and destroy DPC workqueues */
3811 if (ha->dpc_lp_wq) {
3812 cancel_work_sync(&ha->idc_aen);
3813 destroy_workqueue(ha->dpc_lp_wq);
3814 ha->dpc_lp_wq = NULL;
3817 if (ha->dpc_hp_wq) {
3818 cancel_work_sync(&ha->nic_core_reset);
3819 cancel_work_sync(&ha->idc_state_handler);
3820 cancel_work_sync(&ha->nic_core_unrecoverable);
3821 destroy_workqueue(ha->dpc_hp_wq);
3822 ha->dpc_hp_wq = NULL;
3825 /* Kill the kernel thread for this host */
3826 if (ha->dpc_thread) {
3827 struct task_struct *t = ha->dpc_thread;
3830 * qla2xxx_wake_dpc checks for ->dpc_thread
3831 * so we need to zero it out.
3833 ha->dpc_thread = NULL;
3839 qla2x00_unmap_iobases(struct qla_hw_data *ha)
3841 if (IS_QLA82XX(ha)) {
3843 iounmap((device_reg_t *)ha->nx_pcibase);
3845 iounmap((device_reg_t *)ha->nxdb_wr_ptr);
3848 iounmap(ha->iobase);
3851 iounmap(ha->cregbase);
3854 iounmap(ha->mqiobase);
3857 iounmap(ha->msixbase);
3862 qla2x00_clear_drv_active(struct qla_hw_data *ha)
3864 if (IS_QLA8044(ha)) {
3865 qla8044_idc_lock(ha);
3866 qla8044_clear_drv_active(ha);
3867 qla8044_idc_unlock(ha);
3868 } else if (IS_QLA82XX(ha)) {
3869 qla82xx_idc_lock(ha);
3870 qla82xx_clear_drv_active(ha);
3871 qla82xx_idc_unlock(ha);
3876 qla2x00_remove_one(struct pci_dev *pdev)
3878 scsi_qla_host_t *base_vha;
3879 struct qla_hw_data *ha;
3881 base_vha = pci_get_drvdata(pdev);
3883 ql_log(ql_log_info, base_vha, 0xb079,
3884 "Removing driver\n");
3885 __qla_set_remove_flag(base_vha);
3886 cancel_work_sync(&ha->board_disable);
3889 * If the PCI device is disabled then there was a PCI-disconnect and
3890 * qla2x00_disable_board_on_pci_error has taken care of most of the
3893 if (!atomic_read(&pdev->enable_cnt)) {
3894 dma_free_coherent(&ha->pdev->dev, base_vha->gnl.size,
3895 base_vha->gnl.l, base_vha->gnl.ldma);
3896 base_vha->gnl.l = NULL;
3897 scsi_host_put(base_vha->host);
3899 pci_set_drvdata(pdev, NULL);
3902 qla2x00_wait_for_hba_ready(base_vha);
3905 * if UNLOADING flag is already set, then continue unload,
3906 * where it was set first.
3908 if (test_and_set_bit(UNLOADING, &base_vha->dpc_flags))
3911 if (IS_QLA25XX(ha) || IS_QLA2031(ha) || IS_QLA27XX(ha) ||
3913 if (ha->flags.fw_started)
3914 qla2x00_abort_isp_cleanup(base_vha);
3915 } else if (!IS_QLAFX00(ha)) {
3916 if (IS_QLA8031(ha)) {
3917 ql_dbg(ql_dbg_p3p, base_vha, 0xb07e,
3918 "Clearing fcoe driver presence.\n");
3919 if (qla83xx_clear_drv_presence(base_vha) != QLA_SUCCESS)
3920 ql_dbg(ql_dbg_p3p, base_vha, 0xb079,
3921 "Error while clearing DRV-Presence.\n");
3924 qla2x00_try_to_stop_firmware(base_vha);
3927 qla2x00_wait_for_sess_deletion(base_vha);
3929 qla_nvme_delete(base_vha);
3931 dma_free_coherent(&ha->pdev->dev,
3932 base_vha->gnl.size, base_vha->gnl.l, base_vha->gnl.ldma);
3934 base_vha->gnl.l = NULL;
3935 qla_enode_stop(base_vha);
3936 qla_edb_stop(base_vha);
3938 vfree(base_vha->scan.l);
3941 qlafx00_driver_shutdown(base_vha, 20);
3943 qla2x00_delete_all_vps(ha, base_vha);
3945 qla2x00_dfs_remove(base_vha);
3947 qla84xx_put_chip(base_vha);
3950 if (base_vha->timer_active)
3951 qla2x00_stop_timer(base_vha);
3953 base_vha->flags.online = 0;
3955 /* free DMA memory */
3956 if (ha->exlogin_buf)
3957 qla2x00_free_exlogin_buffer(ha);
3959 /* free DMA memory */
3960 if (ha->exchoffld_buf)
3961 qla2x00_free_exchoffld_buffer(ha);
3963 qla2x00_destroy_deferred_work(ha);
3965 qlt_remove_target(ha, base_vha);
3967 qla2x00_free_sysfs_attr(base_vha, true);
3969 fc_remove_host(base_vha->host);
3971 scsi_remove_host(base_vha->host);
3973 qla2x00_free_device(base_vha);
3975 qla2x00_clear_drv_active(ha);
3977 scsi_host_put(base_vha->host);
3979 qla2x00_unmap_iobases(ha);
3981 pci_release_selected_regions(ha->pdev, ha->bars);
3984 pci_disable_device(pdev);
3988 qla24xx_free_purex_list(struct purex_list *list)
3990 struct purex_item *item, *next;
3993 spin_lock_irqsave(&list->lock, flags);
3994 list_for_each_entry_safe(item, next, &list->head, list) {
3995 list_del(&item->list);
3996 if (item == &item->vha->default_item)
4000 spin_unlock_irqrestore(&list->lock, flags);
4004 qla2x00_free_device(scsi_qla_host_t *vha)
4006 struct qla_hw_data *ha = vha->hw;
4008 qla2x00_abort_all_cmds(vha, DID_NO_CONNECT << 16);
4011 if (vha->timer_active)
4012 qla2x00_stop_timer(vha);
4014 qla25xx_delete_queues(vha);
4015 vha->flags.online = 0;
4017 /* turn-off interrupts on the card */
4018 if (ha->interrupts_on) {
4019 vha->flags.init_done = 0;
4020 ha->isp_ops->disable_intrs(ha);
4023 qla2x00_free_fcports(vha);
4025 qla2x00_free_irqs(vha);
4027 /* Flush the work queue and remove it */
4029 destroy_workqueue(ha->wq);
4034 qla24xx_free_purex_list(&vha->purex_list);
4036 qla2x00_mem_free(ha);
4038 qla82xx_md_free(vha);
4040 qla_edif_sadb_release_free_pool(ha);
4041 qla_edif_sadb_release(ha);
4043 qla2x00_free_queues(ha);
4046 void qla2x00_free_fcports(struct scsi_qla_host *vha)
4048 fc_port_t *fcport, *tfcport;
4050 list_for_each_entry_safe(fcport, tfcport, &vha->vp_fcports, list)
4051 qla2x00_free_fcport(fcport);
4055 qla2x00_schedule_rport_del(struct scsi_qla_host *vha, fc_port_t *fcport)
4062 if (fcport->rport) {
4063 ql_dbg(ql_dbg_disc, fcport->vha, 0x2109,
4064 "%s %8phN. rport %p roles %x\n",
4065 __func__, fcport->port_name, fcport->rport,
4066 fcport->rport->roles);
4067 fc_remote_port_delete(fcport->rport);
4069 qlt_do_generation_tick(vha, &now);
4073 * qla2x00_mark_device_lost Updates fcport state when device goes offline.
4075 * Input: ha = adapter block pointer. fcport = port structure pointer.
4081 void qla2x00_mark_device_lost(scsi_qla_host_t *vha, fc_port_t *fcport,
4084 if (IS_QLAFX00(vha->hw)) {
4085 qla2x00_set_fcport_state(fcport, FCS_DEVICE_LOST);
4086 qla2x00_schedule_rport_del(vha, fcport);
4090 if (atomic_read(&fcport->state) == FCS_ONLINE &&
4091 vha->vp_idx == fcport->vha->vp_idx) {
4092 qla2x00_set_fcport_state(fcport, FCS_DEVICE_LOST);
4093 qla2x00_schedule_rport_del(vha, fcport);
4097 * We may need to retry the login, so don't change the state of the
4098 * port but do the retries.
4100 if (atomic_read(&fcport->state) != FCS_DEVICE_DEAD)
4101 qla2x00_set_fcport_state(fcport, FCS_DEVICE_LOST);
4106 set_bit(RELOGIN_NEEDED, &vha->dpc_flags);
4110 qla2x00_mark_all_devices_lost(scsi_qla_host_t *vha)
4114 ql_dbg(ql_dbg_disc, vha, 0x20f1,
4115 "Mark all dev lost\n");
4117 list_for_each_entry(fcport, &vha->vp_fcports, list) {
4118 if (ql2xfc2target &&
4119 fcport->loop_id != FC_NO_LOOP_ID &&
4120 (fcport->flags & FCF_FCP2_DEVICE) &&
4121 fcport->port_type == FCT_TARGET &&
4122 !qla2x00_reset_active(vha)) {
4123 ql_dbg(ql_dbg_disc, vha, 0x211a,
4124 "Delaying session delete for FCP2 flags 0x%x port_type = 0x%x port_id=%06x %phC",
4125 fcport->flags, fcport->port_type,
4126 fcport->d_id.b24, fcport->port_name);
4129 fcport->scan_state = 0;
4130 qlt_schedule_sess_for_deletion(fcport);
4134 static void qla2x00_set_reserved_loop_ids(struct qla_hw_data *ha)
4138 if (IS_FWI2_CAPABLE(ha))
4141 for (i = 0; i < SNS_FIRST_LOOP_ID; i++)
4142 set_bit(i, ha->loop_id_map);
4143 set_bit(MANAGEMENT_SERVER, ha->loop_id_map);
4144 set_bit(BROADCAST, ha->loop_id_map);
4149 * Allocates adapter memory.
4156 qla2x00_mem_alloc(struct qla_hw_data *ha, uint16_t req_len, uint16_t rsp_len,
4157 struct req_que **req, struct rsp_que **rsp)
4162 if (QLA_TGT_MODE_ENABLED() || EDIF_CAP(ha)) {
4163 ha->vp_map = kcalloc(MAX_MULTI_ID_FABRIC, sizeof(struct qla_vp_map), GFP_KERNEL);
4168 ha->init_cb = dma_alloc_coherent(&ha->pdev->dev, ha->init_cb_size,
4169 &ha->init_cb_dma, GFP_KERNEL);
4171 goto fail_free_vp_map;
4173 rc = btree_init32(&ha->host_map);
4175 goto fail_free_init_cb;
4177 if (qlt_mem_alloc(ha) < 0)
4178 goto fail_free_btree;
4180 ha->gid_list = dma_alloc_coherent(&ha->pdev->dev,
4181 qla2x00_gid_list_size(ha), &ha->gid_list_dma, GFP_KERNEL);
4183 goto fail_free_tgt_mem;
4185 ha->srb_mempool = mempool_create_slab_pool(SRB_MIN_REQ, srb_cachep);
4186 if (!ha->srb_mempool)
4187 goto fail_free_gid_list;
4189 if (IS_P3P_TYPE(ha) || IS_QLA27XX(ha) || (ql2xsecenable && IS_QLA28XX(ha))) {
4190 /* Allocate cache for CT6 Ctx. */
4192 ctx_cachep = kmem_cache_create("qla2xxx_ctx",
4193 sizeof(struct ct6_dsd), 0,
4194 SLAB_HWCACHE_ALIGN, NULL);
4196 goto fail_free_srb_mempool;
4198 ha->ctx_mempool = mempool_create_slab_pool(SRB_MIN_REQ,
4200 if (!ha->ctx_mempool)
4201 goto fail_free_srb_mempool;
4202 ql_dbg_pci(ql_dbg_init, ha->pdev, 0x0021,
4203 "ctx_cachep=%p ctx_mempool=%p.\n",
4204 ctx_cachep, ha->ctx_mempool);
4207 /* Get memory for cached NVRAM */
4208 ha->nvram = kzalloc(MAX_NVRAM_SIZE, GFP_KERNEL);
4210 goto fail_free_ctx_mempool;
4212 snprintf(name, sizeof(name), "%s_%d", QLA2XXX_DRIVER_NAME,
4214 ha->s_dma_pool = dma_pool_create(name, &ha->pdev->dev,
4215 DMA_POOL_SIZE, 8, 0);
4216 if (!ha->s_dma_pool)
4217 goto fail_free_nvram;
4219 ql_dbg_pci(ql_dbg_init, ha->pdev, 0x0022,
4220 "init_cb=%p gid_list=%p, srb_mempool=%p s_dma_pool=%p.\n",
4221 ha->init_cb, ha->gid_list, ha->srb_mempool, ha->s_dma_pool);
4223 if (IS_P3P_TYPE(ha) || ql2xenabledif || (IS_QLA28XX(ha) && ql2xsecenable)) {
4224 ha->dl_dma_pool = dma_pool_create(name, &ha->pdev->dev,
4225 DSD_LIST_DMA_POOL_SIZE, 8, 0);
4226 if (!ha->dl_dma_pool) {
4227 ql_log_pci(ql_log_fatal, ha->pdev, 0x0023,
4228 "Failed to allocate memory for dl_dma_pool.\n");
4229 goto fail_s_dma_pool;
4232 ha->fcp_cmnd_dma_pool = dma_pool_create(name, &ha->pdev->dev,
4233 FCP_CMND_DMA_POOL_SIZE, 8, 0);
4234 if (!ha->fcp_cmnd_dma_pool) {
4235 ql_log_pci(ql_log_fatal, ha->pdev, 0x0024,
4236 "Failed to allocate memory for fcp_cmnd_dma_pool.\n");
4237 goto fail_dl_dma_pool;
4240 if (ql2xenabledif) {
4241 u64 bufsize = DIF_BUNDLING_DMA_POOL_SIZE;
4242 struct dsd_dma *dsd, *nxt;
4244 /* Creata a DMA pool of buffers for DIF bundling */
4245 ha->dif_bundl_pool = dma_pool_create(name,
4246 &ha->pdev->dev, DIF_BUNDLING_DMA_POOL_SIZE, 8, 0);
4247 if (!ha->dif_bundl_pool) {
4248 ql_dbg_pci(ql_dbg_init, ha->pdev, 0x0024,
4249 "%s: failed create dif_bundl_pool\n",
4251 goto fail_dif_bundl_dma_pool;
4254 INIT_LIST_HEAD(&ha->pool.good.head);
4255 INIT_LIST_HEAD(&ha->pool.unusable.head);
4256 ha->pool.good.count = 0;
4257 ha->pool.unusable.count = 0;
4258 for (i = 0; i < 128; i++) {
4259 dsd = kzalloc(sizeof(*dsd), GFP_ATOMIC);
4261 ql_dbg_pci(ql_dbg_init, ha->pdev,
4262 0xe0ee, "%s: failed alloc dsd\n",
4266 ha->dif_bundle_kallocs++;
4268 dsd->dsd_addr = dma_pool_alloc(
4269 ha->dif_bundl_pool, GFP_ATOMIC,
4270 &dsd->dsd_list_dma);
4271 if (!dsd->dsd_addr) {
4272 ql_dbg_pci(ql_dbg_init, ha->pdev,
4274 "%s: failed alloc ->dsd_addr\n",
4277 ha->dif_bundle_kallocs--;
4280 ha->dif_bundle_dma_allocs++;
4283 * if DMA buffer crosses 4G boundary,
4284 * put it on bad list
4286 if (MSD(dsd->dsd_list_dma) ^
4287 MSD(dsd->dsd_list_dma + bufsize)) {
4288 list_add_tail(&dsd->list,
4289 &ha->pool.unusable.head);
4290 ha->pool.unusable.count++;
4292 list_add_tail(&dsd->list,
4293 &ha->pool.good.head);
4294 ha->pool.good.count++;
4298 /* return the good ones back to the pool */
4299 list_for_each_entry_safe(dsd, nxt,
4300 &ha->pool.good.head, list) {
4301 list_del(&dsd->list);
4302 dma_pool_free(ha->dif_bundl_pool,
4303 dsd->dsd_addr, dsd->dsd_list_dma);
4304 ha->dif_bundle_dma_allocs--;
4306 ha->dif_bundle_kallocs--;
4309 ql_dbg_pci(ql_dbg_init, ha->pdev, 0x0024,
4310 "%s: dif dma pool (good=%u unusable=%u)\n",
4311 __func__, ha->pool.good.count,
4312 ha->pool.unusable.count);
4315 ql_dbg_pci(ql_dbg_init, ha->pdev, 0x0025,
4316 "dl_dma_pool=%p fcp_cmnd_dma_pool=%p dif_bundl_pool=%p.\n",
4317 ha->dl_dma_pool, ha->fcp_cmnd_dma_pool,
4318 ha->dif_bundl_pool);
4321 /* Allocate memory for SNS commands */
4322 if (IS_QLA2100(ha) || IS_QLA2200(ha)) {
4323 /* Get consistent memory allocated for SNS commands */
4324 ha->sns_cmd = dma_alloc_coherent(&ha->pdev->dev,
4325 sizeof(struct sns_cmd_pkt), &ha->sns_cmd_dma, GFP_KERNEL);
4328 ql_dbg_pci(ql_dbg_init, ha->pdev, 0x0026,
4329 "sns_cmd: %p.\n", ha->sns_cmd);
4331 /* Get consistent memory allocated for MS IOCB */
4332 ha->ms_iocb = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL,
4336 /* Get consistent memory allocated for CT SNS commands */
4337 ha->ct_sns = dma_alloc_coherent(&ha->pdev->dev,
4338 sizeof(struct ct_sns_pkt), &ha->ct_sns_dma, GFP_KERNEL);
4340 goto fail_free_ms_iocb;
4341 ql_dbg_pci(ql_dbg_init, ha->pdev, 0x0027,
4342 "ms_iocb=%p ct_sns=%p.\n",
4343 ha->ms_iocb, ha->ct_sns);
4346 /* Allocate memory for request ring */
4347 *req = kzalloc(sizeof(struct req_que), GFP_KERNEL);
4349 ql_log_pci(ql_log_fatal, ha->pdev, 0x0028,
4350 "Failed to allocate memory for req.\n");
4353 (*req)->length = req_len;
4354 (*req)->ring = dma_alloc_coherent(&ha->pdev->dev,
4355 ((*req)->length + 1) * sizeof(request_t),
4356 &(*req)->dma, GFP_KERNEL);
4357 if (!(*req)->ring) {
4358 ql_log_pci(ql_log_fatal, ha->pdev, 0x0029,
4359 "Failed to allocate memory for req_ring.\n");
4362 /* Allocate memory for response ring */
4363 *rsp = kzalloc(sizeof(struct rsp_que), GFP_KERNEL);
4365 ql_log_pci(ql_log_fatal, ha->pdev, 0x002a,
4366 "Failed to allocate memory for rsp.\n");
4370 (*rsp)->length = rsp_len;
4371 (*rsp)->ring = dma_alloc_coherent(&ha->pdev->dev,
4372 ((*rsp)->length + 1) * sizeof(response_t),
4373 &(*rsp)->dma, GFP_KERNEL);
4374 if (!(*rsp)->ring) {
4375 ql_log_pci(ql_log_fatal, ha->pdev, 0x002b,
4376 "Failed to allocate memory for rsp_ring.\n");
4381 ql_dbg_pci(ql_dbg_init, ha->pdev, 0x002c,
4382 "req=%p req->length=%d req->ring=%p rsp=%p "
4383 "rsp->length=%d rsp->ring=%p.\n",
4384 *req, (*req)->length, (*req)->ring, *rsp, (*rsp)->length,
4386 /* Allocate memory for NVRAM data for vports */
4387 if (ha->nvram_npiv_size) {
4388 ha->npiv_info = kcalloc(ha->nvram_npiv_size,
4389 sizeof(struct qla_npiv_entry),
4391 if (!ha->npiv_info) {
4392 ql_log_pci(ql_log_fatal, ha->pdev, 0x002d,
4393 "Failed to allocate memory for npiv_info.\n");
4394 goto fail_npiv_info;
4397 ha->npiv_info = NULL;
4399 /* Get consistent memory allocated for EX-INIT-CB. */
4400 if (IS_CNA_CAPABLE(ha) || IS_QLA2031(ha) || IS_QLA27XX(ha) ||
4402 ha->ex_init_cb = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL,
4403 &ha->ex_init_cb_dma);
4404 if (!ha->ex_init_cb)
4405 goto fail_ex_init_cb;
4406 ql_dbg_pci(ql_dbg_init, ha->pdev, 0x002e,
4407 "ex_init_cb=%p.\n", ha->ex_init_cb);
4410 /* Get consistent memory allocated for Special Features-CB. */
4411 if (IS_QLA27XX(ha) || IS_QLA28XX(ha)) {
4412 ha->sf_init_cb = dma_pool_zalloc(ha->s_dma_pool, GFP_KERNEL,
4413 &ha->sf_init_cb_dma);
4414 if (!ha->sf_init_cb)
4415 goto fail_sf_init_cb;
4416 ql_dbg_pci(ql_dbg_init, ha->pdev, 0x0199,
4417 "sf_init_cb=%p.\n", ha->sf_init_cb);
4421 /* Get consistent memory allocated for Async Port-Database. */
4422 if (!IS_FWI2_CAPABLE(ha)) {
4423 ha->async_pd = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL,
4427 ql_dbg_pci(ql_dbg_init, ha->pdev, 0x002f,
4428 "async_pd=%p.\n", ha->async_pd);
4431 INIT_LIST_HEAD(&ha->vp_list);
4433 /* Allocate memory for our loop_id bitmap */
4434 ha->loop_id_map = kcalloc(BITS_TO_LONGS(LOOPID_MAP_SIZE),
4437 if (!ha->loop_id_map)
4438 goto fail_loop_id_map;
4440 qla2x00_set_reserved_loop_ids(ha);
4441 ql_dbg_pci(ql_dbg_init, ha->pdev, 0x0123,
4442 "loop_id_map=%p.\n", ha->loop_id_map);
4445 ha->sfp_data = dma_alloc_coherent(&ha->pdev->dev,
4446 SFP_DEV_SIZE, &ha->sfp_data_dma, GFP_KERNEL);
4447 if (!ha->sfp_data) {
4448 ql_dbg_pci(ql_dbg_init, ha->pdev, 0x011b,
4449 "Unable to allocate memory for SFP read-data.\n");
4453 ha->flt = dma_alloc_coherent(&ha->pdev->dev,
4454 sizeof(struct qla_flt_header) + FLT_REGIONS_SIZE, &ha->flt_dma,
4457 ql_dbg_pci(ql_dbg_init, ha->pdev, 0x011b,
4458 "Unable to allocate memory for FLT.\n");
4459 goto fail_flt_buffer;
4462 /* allocate the purex dma pool */
4463 ha->purex_dma_pool = dma_pool_create(name, &ha->pdev->dev,
4464 ELS_MAX_PAYLOAD, 8, 0);
4466 if (!ha->purex_dma_pool) {
4467 ql_dbg_pci(ql_dbg_init, ha->pdev, 0x011b,
4468 "Unable to allocate purex_dma_pool.\n");
4472 ha->elsrej.size = sizeof(struct fc_els_ls_rjt) + 16;
4473 ha->elsrej.c = dma_alloc_coherent(&ha->pdev->dev,
4477 if (!ha->elsrej.c) {
4478 ql_dbg_pci(ql_dbg_init, ha->pdev, 0xffff,
4479 "Alloc failed for els reject cmd.\n");
4482 ha->elsrej.c->er_cmd = ELS_LS_RJT;
4483 ha->elsrej.c->er_reason = ELS_RJT_LOGIC;
4484 ha->elsrej.c->er_explan = ELS_EXPL_UNAB_DATA;
4486 ha->lsrjt.size = sizeof(struct fcnvme_ls_rjt);
4487 ha->lsrjt.c = dma_alloc_coherent(&ha->pdev->dev, ha->lsrjt.size,
4488 &ha->lsrjt.cdma, GFP_KERNEL);
4490 ql_dbg_pci(ql_dbg_init, ha->pdev, 0xffff,
4491 "Alloc failed for nvme fc reject cmd.\n");
4498 dma_free_coherent(&ha->pdev->dev, ha->elsrej.size,
4499 ha->elsrej.c, ha->elsrej.cdma);
4501 dma_pool_destroy(ha->purex_dma_pool);
4503 dma_free_coherent(&ha->pdev->dev, SFP_DEV_SIZE,
4504 ha->flt, ha->flt_dma);
4507 dma_free_coherent(&ha->pdev->dev, SFP_DEV_SIZE,
4508 ha->sfp_data, ha->sfp_data_dma);
4510 kfree(ha->loop_id_map);
4512 dma_pool_free(ha->s_dma_pool, ha->async_pd, ha->async_pd_dma);
4514 dma_pool_free(ha->s_dma_pool, ha->sf_init_cb, ha->sf_init_cb_dma);
4516 dma_pool_free(ha->s_dma_pool, ha->ex_init_cb, ha->ex_init_cb_dma);
4518 kfree(ha->npiv_info);
4520 dma_free_coherent(&ha->pdev->dev, ((*rsp)->length + 1) *
4521 sizeof(response_t), (*rsp)->ring, (*rsp)->dma);
4522 (*rsp)->ring = NULL;
4528 dma_free_coherent(&ha->pdev->dev, ((*req)->length + 1) *
4529 sizeof(request_t), (*req)->ring, (*req)->dma);
4530 (*req)->ring = NULL;
4536 dma_free_coherent(&ha->pdev->dev, sizeof(struct ct_sns_pkt),
4537 ha->ct_sns, ha->ct_sns_dma);
4541 dma_pool_free(ha->s_dma_pool, ha->ms_iocb, ha->ms_iocb_dma);
4543 ha->ms_iocb_dma = 0;
4546 dma_free_coherent(&ha->pdev->dev, sizeof(struct sns_cmd_pkt),
4547 ha->sns_cmd, ha->sns_cmd_dma);
4549 if (ql2xenabledif) {
4550 struct dsd_dma *dsd, *nxt;
4552 list_for_each_entry_safe(dsd, nxt, &ha->pool.unusable.head,
4554 list_del(&dsd->list);
4555 dma_pool_free(ha->dif_bundl_pool, dsd->dsd_addr,
4557 ha->dif_bundle_dma_allocs--;
4559 ha->dif_bundle_kallocs--;
4560 ha->pool.unusable.count--;
4562 dma_pool_destroy(ha->dif_bundl_pool);
4563 ha->dif_bundl_pool = NULL;
4566 fail_dif_bundl_dma_pool:
4567 if (IS_QLA82XX(ha) || ql2xenabledif) {
4568 dma_pool_destroy(ha->fcp_cmnd_dma_pool);
4569 ha->fcp_cmnd_dma_pool = NULL;
4572 if (IS_QLA82XX(ha) || ql2xenabledif) {
4573 dma_pool_destroy(ha->dl_dma_pool);
4574 ha->dl_dma_pool = NULL;
4577 dma_pool_destroy(ha->s_dma_pool);
4578 ha->s_dma_pool = NULL;
4582 fail_free_ctx_mempool:
4583 mempool_destroy(ha->ctx_mempool);
4584 ha->ctx_mempool = NULL;
4585 fail_free_srb_mempool:
4586 mempool_destroy(ha->srb_mempool);
4587 ha->srb_mempool = NULL;
4589 dma_free_coherent(&ha->pdev->dev, qla2x00_gid_list_size(ha),
4592 ha->gid_list = NULL;
4593 ha->gid_list_dma = 0;
4597 btree_destroy32(&ha->host_map);
4599 dma_free_coherent(&ha->pdev->dev, ha->init_cb_size, ha->init_cb,
4602 ha->init_cb_dma = 0;
4606 ql_log(ql_log_fatal, NULL, 0x0030,
4607 "Memory allocation failure.\n");
4612 qla2x00_set_exlogins_buffer(scsi_qla_host_t *vha)
4615 uint16_t size, max_cnt;
4617 struct qla_hw_data *ha = vha->hw;
4619 /* Return if we don't need to alloacate any extended logins */
4620 if (ql2xexlogins <= MAX_FIBRE_DEVICES_2400)
4623 if (!IS_EXLOGIN_OFFLD_CAPABLE(ha))
4626 ql_log(ql_log_info, vha, 0xd021, "EXLOGIN count: %d.\n", ql2xexlogins);
4628 rval = qla_get_exlogin_status(vha, &size, &max_cnt);
4629 if (rval != QLA_SUCCESS) {
4630 ql_log_pci(ql_log_fatal, ha->pdev, 0xd029,
4631 "Failed to get exlogin status.\n");
4635 temp = (ql2xexlogins > max_cnt) ? max_cnt : ql2xexlogins;
4638 if (temp != ha->exlogin_size) {
4639 qla2x00_free_exlogin_buffer(ha);
4640 ha->exlogin_size = temp;
4642 ql_log(ql_log_info, vha, 0xd024,
4643 "EXLOGIN: max_logins=%d, portdb=0x%x, total=%d.\n",
4644 max_cnt, size, temp);
4646 ql_log(ql_log_info, vha, 0xd025,
4647 "EXLOGIN: requested size=0x%x\n", ha->exlogin_size);
4649 /* Get consistent memory for extended logins */
4650 ha->exlogin_buf = dma_alloc_coherent(&ha->pdev->dev,
4651 ha->exlogin_size, &ha->exlogin_buf_dma, GFP_KERNEL);
4652 if (!ha->exlogin_buf) {
4653 ql_log_pci(ql_log_fatal, ha->pdev, 0xd02a,
4654 "Failed to allocate memory for exlogin_buf_dma.\n");
4659 /* Now configure the dma buffer */
4660 rval = qla_set_exlogin_mem_cfg(vha, ha->exlogin_buf_dma);
4662 ql_log(ql_log_fatal, vha, 0xd033,
4663 "Setup extended login buffer ****FAILED****.\n");
4664 qla2x00_free_exlogin_buffer(ha);
4671 * qla2x00_free_exlogin_buffer
4674 * ha = adapter block pointer
4677 qla2x00_free_exlogin_buffer(struct qla_hw_data *ha)
4679 if (ha->exlogin_buf) {
4680 dma_free_coherent(&ha->pdev->dev, ha->exlogin_size,
4681 ha->exlogin_buf, ha->exlogin_buf_dma);
4682 ha->exlogin_buf = NULL;
4683 ha->exlogin_size = 0;
4688 qla2x00_number_of_exch(scsi_qla_host_t *vha, u32 *ret_cnt, u16 max_cnt)
4691 struct init_cb_81xx *icb = (struct init_cb_81xx *)&vha->hw->init_cb;
4692 *ret_cnt = FW_DEF_EXCHANGES_CNT;
4694 if (max_cnt > vha->hw->max_exchg)
4695 max_cnt = vha->hw->max_exchg;
4697 if (qla_ini_mode_enabled(vha)) {
4698 if (vha->ql2xiniexchg > max_cnt)
4699 vha->ql2xiniexchg = max_cnt;
4701 if (vha->ql2xiniexchg > FW_DEF_EXCHANGES_CNT)
4702 *ret_cnt = vha->ql2xiniexchg;
4704 } else if (qla_tgt_mode_enabled(vha)) {
4705 if (vha->ql2xexchoffld > max_cnt) {
4706 vha->ql2xexchoffld = max_cnt;
4707 icb->exchange_count = cpu_to_le16(vha->ql2xexchoffld);
4710 if (vha->ql2xexchoffld > FW_DEF_EXCHANGES_CNT)
4711 *ret_cnt = vha->ql2xexchoffld;
4712 } else if (qla_dual_mode_enabled(vha)) {
4713 temp = vha->ql2xiniexchg + vha->ql2xexchoffld;
4714 if (temp > max_cnt) {
4715 vha->ql2xiniexchg -= (temp - max_cnt)/2;
4716 vha->ql2xexchoffld -= (((temp - max_cnt)/2) + 1);
4718 icb->exchange_count = cpu_to_le16(vha->ql2xexchoffld);
4721 if (temp > FW_DEF_EXCHANGES_CNT)
4727 qla2x00_set_exchoffld_buffer(scsi_qla_host_t *vha)
4731 u32 actual_cnt, totsz;
4732 struct qla_hw_data *ha = vha->hw;
4734 if (!ha->flags.exchoffld_enabled)
4737 if (!IS_EXCHG_OFFLD_CAPABLE(ha))
4741 rval = qla_get_exchoffld_status(vha, &size, &max_cnt);
4742 if (rval != QLA_SUCCESS) {
4743 ql_log_pci(ql_log_fatal, ha->pdev, 0xd012,
4744 "Failed to get exlogin status.\n");
4748 qla2x00_number_of_exch(vha, &actual_cnt, max_cnt);
4749 ql_log(ql_log_info, vha, 0xd014,
4750 "Actual exchange offload count: %d.\n", actual_cnt);
4752 totsz = actual_cnt * size;
4754 if (totsz != ha->exchoffld_size) {
4755 qla2x00_free_exchoffld_buffer(ha);
4756 if (actual_cnt <= FW_DEF_EXCHANGES_CNT) {
4757 ha->exchoffld_size = 0;
4758 ha->flags.exchoffld_enabled = 0;
4762 ha->exchoffld_size = totsz;
4764 ql_log(ql_log_info, vha, 0xd016,
4765 "Exchange offload: max_count=%d, actual count=%d entry sz=0x%x, total sz=0x%x\n",
4766 max_cnt, actual_cnt, size, totsz);
4768 ql_log(ql_log_info, vha, 0xd017,
4769 "Exchange Buffers requested size = 0x%x\n",
4770 ha->exchoffld_size);
4772 /* Get consistent memory for extended logins */
4773 ha->exchoffld_buf = dma_alloc_coherent(&ha->pdev->dev,
4774 ha->exchoffld_size, &ha->exchoffld_buf_dma, GFP_KERNEL);
4775 if (!ha->exchoffld_buf) {
4776 ql_log_pci(ql_log_fatal, ha->pdev, 0xd013,
4777 "Failed to allocate memory for Exchange Offload.\n");
4780 (FW_DEF_EXCHANGES_CNT + REDUCE_EXCHANGES_CNT)) {
4781 ha->max_exchg -= REDUCE_EXCHANGES_CNT;
4782 } else if (ha->max_exchg >
4783 (FW_DEF_EXCHANGES_CNT + 512)) {
4784 ha->max_exchg -= 512;
4786 ha->flags.exchoffld_enabled = 0;
4787 ql_log_pci(ql_log_fatal, ha->pdev, 0xd013,
4788 "Disabling Exchange offload due to lack of memory\n");
4790 ha->exchoffld_size = 0;
4794 } else if (!ha->exchoffld_buf || (actual_cnt <= FW_DEF_EXCHANGES_CNT)) {
4795 /* pathological case */
4796 qla2x00_free_exchoffld_buffer(ha);
4797 ha->exchoffld_size = 0;
4798 ha->flags.exchoffld_enabled = 0;
4799 ql_log(ql_log_info, vha, 0xd016,
4800 "Exchange offload not enable: offld size=%d, actual count=%d entry sz=0x%x, total sz=0x%x.\n",
4801 ha->exchoffld_size, actual_cnt, size, totsz);
4805 /* Now configure the dma buffer */
4806 rval = qla_set_exchoffld_mem_cfg(vha);
4808 ql_log(ql_log_fatal, vha, 0xd02e,
4809 "Setup exchange offload buffer ****FAILED****.\n");
4810 qla2x00_free_exchoffld_buffer(ha);
4812 /* re-adjust number of target exchange */
4813 struct init_cb_81xx *icb = (struct init_cb_81xx *)ha->init_cb;
4815 if (qla_ini_mode_enabled(vha))
4816 icb->exchange_count = 0;
4818 icb->exchange_count = cpu_to_le16(vha->ql2xexchoffld);
4825 * qla2x00_free_exchoffld_buffer
4828 * ha = adapter block pointer
4831 qla2x00_free_exchoffld_buffer(struct qla_hw_data *ha)
4833 if (ha->exchoffld_buf) {
4834 dma_free_coherent(&ha->pdev->dev, ha->exchoffld_size,
4835 ha->exchoffld_buf, ha->exchoffld_buf_dma);
4836 ha->exchoffld_buf = NULL;
4837 ha->exchoffld_size = 0;
4842 * qla2x00_free_fw_dump
4843 * Frees fw dump stuff.
4846 * ha = adapter block pointer
4849 qla2x00_free_fw_dump(struct qla_hw_data *ha)
4851 struct fwdt *fwdt = ha->fwdt;
4855 dma_free_coherent(&ha->pdev->dev,
4856 FCE_SIZE, ha->fce, ha->fce_dma);
4859 dma_free_coherent(&ha->pdev->dev,
4860 EFT_SIZE, ha->eft, ha->eft_dma);
4866 ha->flags.fce_enabled = 0;
4869 ha->fw_dumped = false;
4870 ha->fw_dump_cap_flags = 0;
4871 ha->fw_dump_reading = 0;
4873 ha->fw_dump_len = 0;
4875 for (j = 0; j < 2; j++, fwdt++) {
4876 vfree(fwdt->template);
4877 fwdt->template = NULL;
4884 * Frees all adapter allocated memory.
4887 * ha = adapter block pointer.
4890 qla2x00_mem_free(struct qla_hw_data *ha)
4892 qla2x00_free_fw_dump(ha);
4895 dma_free_coherent(&ha->pdev->dev, MCTP_DUMP_SIZE, ha->mctp_dump,
4897 ha->mctp_dump = NULL;
4899 mempool_destroy(ha->srb_mempool);
4900 ha->srb_mempool = NULL;
4903 dma_free_coherent(&ha->pdev->dev, DCBX_TLV_DATA_SIZE,
4904 ha->dcbx_tlv, ha->dcbx_tlv_dma);
4905 ha->dcbx_tlv = NULL;
4908 dma_free_coherent(&ha->pdev->dev, XGMAC_DATA_SIZE,
4909 ha->xgmac_data, ha->xgmac_data_dma);
4910 ha->xgmac_data = NULL;
4913 dma_free_coherent(&ha->pdev->dev, sizeof(struct sns_cmd_pkt),
4914 ha->sns_cmd, ha->sns_cmd_dma);
4916 ha->sns_cmd_dma = 0;
4919 dma_free_coherent(&ha->pdev->dev, sizeof(struct ct_sns_pkt),
4920 ha->ct_sns, ha->ct_sns_dma);
4925 dma_free_coherent(&ha->pdev->dev, SFP_DEV_SIZE, ha->sfp_data,
4927 ha->sfp_data = NULL;
4930 dma_free_coherent(&ha->pdev->dev,
4931 sizeof(struct qla_flt_header) + FLT_REGIONS_SIZE,
4932 ha->flt, ha->flt_dma);
4937 dma_pool_free(ha->s_dma_pool, ha->ms_iocb, ha->ms_iocb_dma);
4939 ha->ms_iocb_dma = 0;
4942 dma_pool_free(ha->s_dma_pool,
4943 ha->sf_init_cb, ha->sf_init_cb_dma);
4946 dma_pool_free(ha->s_dma_pool,
4947 ha->ex_init_cb, ha->ex_init_cb_dma);
4948 ha->ex_init_cb = NULL;
4949 ha->ex_init_cb_dma = 0;
4952 dma_pool_free(ha->s_dma_pool, ha->async_pd, ha->async_pd_dma);
4953 ha->async_pd = NULL;
4954 ha->async_pd_dma = 0;
4956 dma_pool_destroy(ha->s_dma_pool);
4957 ha->s_dma_pool = NULL;
4960 dma_free_coherent(&ha->pdev->dev, qla2x00_gid_list_size(ha),
4961 ha->gid_list, ha->gid_list_dma);
4962 ha->gid_list = NULL;
4963 ha->gid_list_dma = 0;
4965 if (ha->base_qpair && !list_empty(&ha->base_qpair->dsd_list)) {
4966 struct dsd_dma *dsd_ptr, *tdsd_ptr;
4968 /* clean up allocated prev pool */
4969 list_for_each_entry_safe(dsd_ptr, tdsd_ptr,
4970 &ha->base_qpair->dsd_list, list) {
4971 dma_pool_free(ha->dl_dma_pool, dsd_ptr->dsd_addr,
4972 dsd_ptr->dsd_list_dma);
4973 list_del(&dsd_ptr->list);
4978 dma_pool_destroy(ha->dl_dma_pool);
4979 ha->dl_dma_pool = NULL;
4981 dma_pool_destroy(ha->fcp_cmnd_dma_pool);
4982 ha->fcp_cmnd_dma_pool = NULL;
4984 mempool_destroy(ha->ctx_mempool);
4985 ha->ctx_mempool = NULL;
4987 if (ql2xenabledif && ha->dif_bundl_pool) {
4988 struct dsd_dma *dsd, *nxt;
4990 list_for_each_entry_safe(dsd, nxt, &ha->pool.unusable.head,
4992 list_del(&dsd->list);
4993 dma_pool_free(ha->dif_bundl_pool, dsd->dsd_addr,
4995 ha->dif_bundle_dma_allocs--;
4997 ha->dif_bundle_kallocs--;
4998 ha->pool.unusable.count--;
5000 list_for_each_entry_safe(dsd, nxt, &ha->pool.good.head, list) {
5001 list_del(&dsd->list);
5002 dma_pool_free(ha->dif_bundl_pool, dsd->dsd_addr,
5004 ha->dif_bundle_dma_allocs--;
5006 ha->dif_bundle_kallocs--;
5010 dma_pool_destroy(ha->dif_bundl_pool);
5011 ha->dif_bundl_pool = NULL;
5014 qla_remove_hostmap(ha);
5017 dma_free_coherent(&ha->pdev->dev, ha->init_cb_size,
5018 ha->init_cb, ha->init_cb_dma);
5020 dma_pool_destroy(ha->purex_dma_pool);
5021 ha->purex_dma_pool = NULL;
5024 dma_free_coherent(&ha->pdev->dev, ha->elsrej.size,
5025 ha->elsrej.c, ha->elsrej.cdma);
5026 ha->elsrej.c = NULL;
5030 dma_free_coherent(&ha->pdev->dev, ha->lsrjt.size, ha->lsrjt.c,
5036 ha->init_cb_dma = 0;
5038 vfree(ha->optrom_buffer);
5039 ha->optrom_buffer = NULL;
5042 kfree(ha->npiv_info);
5043 ha->npiv_info = NULL;
5046 kfree(ha->loop_id_map);
5047 ha->sf_init_cb = NULL;
5048 ha->sf_init_cb_dma = 0;
5049 ha->loop_id_map = NULL;
5055 struct scsi_qla_host *qla2x00_create_host(const struct scsi_host_template *sht,
5056 struct qla_hw_data *ha)
5058 struct Scsi_Host *host;
5059 struct scsi_qla_host *vha = NULL;
5061 host = scsi_host_alloc(sht, sizeof(scsi_qla_host_t));
5063 ql_log_pci(ql_log_fatal, ha->pdev, 0x0107,
5064 "Failed to allocate host from the scsi layer, aborting.\n");
5068 /* Clear our data area */
5069 vha = shost_priv(host);
5070 memset(vha, 0, sizeof(scsi_qla_host_t));
5073 vha->host_no = host->host_no;
5076 vha->qlini_mode = ql2x_ini_mode;
5077 vha->ql2xexchoffld = ql2xexchoffld;
5078 vha->ql2xiniexchg = ql2xiniexchg;
5080 INIT_LIST_HEAD(&vha->vp_fcports);
5081 INIT_LIST_HEAD(&vha->work_list);
5082 INIT_LIST_HEAD(&vha->list);
5083 INIT_LIST_HEAD(&vha->qla_cmd_list);
5084 INIT_LIST_HEAD(&vha->logo_list);
5085 INIT_LIST_HEAD(&vha->plogi_ack_list);
5086 INIT_LIST_HEAD(&vha->qp_list);
5087 INIT_LIST_HEAD(&vha->gnl.fcports);
5088 INIT_WORK(&vha->iocb_work, qla2x00_iocb_work_fn);
5090 INIT_LIST_HEAD(&vha->purex_list.head);
5091 spin_lock_init(&vha->purex_list.lock);
5093 spin_lock_init(&vha->work_lock);
5094 spin_lock_init(&vha->cmd_list_lock);
5095 init_waitqueue_head(&vha->fcport_waitQ);
5096 init_waitqueue_head(&vha->vref_waitq);
5097 qla_enode_init(vha);
5101 vha->gnl.size = sizeof(struct get_name_list_extended) *
5102 (ha->max_loop_id + 1);
5103 vha->gnl.l = dma_alloc_coherent(&ha->pdev->dev,
5104 vha->gnl.size, &vha->gnl.ldma, GFP_KERNEL);
5106 ql_log(ql_log_fatal, vha, 0xd04a,
5107 "Alloc failed for name list.\n");
5108 scsi_host_put(vha->host);
5112 /* todo: what about ext login? */
5113 vha->scan.size = ha->max_fibre_devices * sizeof(struct fab_scan_rp);
5114 vha->scan.l = vmalloc(vha->scan.size);
5116 ql_log(ql_log_fatal, vha, 0xd04a,
5117 "Alloc failed for scan database.\n");
5118 dma_free_coherent(&ha->pdev->dev, vha->gnl.size,
5119 vha->gnl.l, vha->gnl.ldma);
5121 scsi_host_put(vha->host);
5124 INIT_DELAYED_WORK(&vha->scan.scan_work, qla_scan_work_fn);
5126 snprintf(vha->host_str, sizeof(vha->host_str), "%s_%lu",
5127 QLA2XXX_DRIVER_NAME, vha->host_no);
5128 ql_dbg(ql_dbg_init, vha, 0x0041,
5129 "Allocated the host=%p hw=%p vha=%p dev_name=%s",
5130 vha->host, vha->hw, vha,
5131 dev_name(&(ha->pdev->dev)));
5136 struct qla_work_evt *
5137 qla2x00_alloc_work(struct scsi_qla_host *vha, enum qla_work_type type)
5139 struct qla_work_evt *e;
5141 if (test_bit(UNLOADING, &vha->dpc_flags))
5144 if (qla_vha_mark_busy(vha))
5147 e = kzalloc(sizeof(struct qla_work_evt), GFP_ATOMIC);
5149 QLA_VHA_MARK_NOT_BUSY(vha);
5153 INIT_LIST_HEAD(&e->list);
5155 e->flags = QLA_EVT_FLAG_FREE;
5160 qla2x00_post_work(struct scsi_qla_host *vha, struct qla_work_evt *e)
5162 unsigned long flags;
5165 spin_lock_irqsave(&vha->work_lock, flags);
5166 list_add_tail(&e->list, &vha->work_list);
5168 if (!test_and_set_bit(IOCB_WORK_ACTIVE, &vha->dpc_flags))
5171 spin_unlock_irqrestore(&vha->work_lock, flags);
5174 queue_work(vha->hw->wq, &vha->iocb_work);
5180 qla2x00_post_aen_work(struct scsi_qla_host *vha, enum fc_host_event_code code,
5183 struct qla_work_evt *e;
5185 e = qla2x00_alloc_work(vha, QLA_EVT_AEN);
5187 return QLA_FUNCTION_FAILED;
5189 e->u.aen.code = code;
5190 e->u.aen.data = data;
5191 return qla2x00_post_work(vha, e);
5195 qla2x00_post_idc_ack_work(struct scsi_qla_host *vha, uint16_t *mb)
5197 struct qla_work_evt *e;
5199 e = qla2x00_alloc_work(vha, QLA_EVT_IDC_ACK);
5201 return QLA_FUNCTION_FAILED;
5203 memcpy(e->u.idc_ack.mb, mb, QLA_IDC_ACK_REGS * sizeof(uint16_t));
5204 return qla2x00_post_work(vha, e);
5207 #define qla2x00_post_async_work(name, type) \
5208 int qla2x00_post_async_##name##_work( \
5209 struct scsi_qla_host *vha, \
5210 fc_port_t *fcport, uint16_t *data) \
5212 struct qla_work_evt *e; \
5214 e = qla2x00_alloc_work(vha, type); \
5216 return QLA_FUNCTION_FAILED; \
5218 e->u.logio.fcport = fcport; \
5220 e->u.logio.data[0] = data[0]; \
5221 e->u.logio.data[1] = data[1]; \
5223 fcport->flags |= FCF_ASYNC_ACTIVE; \
5224 return qla2x00_post_work(vha, e); \
5227 qla2x00_post_async_work(login, QLA_EVT_ASYNC_LOGIN);
5228 qla2x00_post_async_work(logout, QLA_EVT_ASYNC_LOGOUT);
5229 qla2x00_post_async_work(adisc, QLA_EVT_ASYNC_ADISC);
5230 qla2x00_post_async_work(prlo, QLA_EVT_ASYNC_PRLO);
5231 qla2x00_post_async_work(prlo_done, QLA_EVT_ASYNC_PRLO_DONE);
5234 qla2x00_post_uevent_work(struct scsi_qla_host *vha, u32 code)
5236 struct qla_work_evt *e;
5238 e = qla2x00_alloc_work(vha, QLA_EVT_UEVENT);
5240 return QLA_FUNCTION_FAILED;
5242 e->u.uevent.code = code;
5243 return qla2x00_post_work(vha, e);
5247 qla2x00_uevent_emit(struct scsi_qla_host *vha, u32 code)
5249 char event_string[40];
5250 char *envp[] = { event_string, NULL };
5253 case QLA_UEVENT_CODE_FW_DUMP:
5254 snprintf(event_string, sizeof(event_string), "FW_DUMP=%lu",
5261 kobject_uevent_env(&vha->hw->pdev->dev.kobj, KOBJ_CHANGE, envp);
5265 qlafx00_post_aenfx_work(struct scsi_qla_host *vha, uint32_t evtcode,
5266 uint32_t *data, int cnt)
5268 struct qla_work_evt *e;
5270 e = qla2x00_alloc_work(vha, QLA_EVT_AENFX);
5272 return QLA_FUNCTION_FAILED;
5274 e->u.aenfx.evtcode = evtcode;
5275 e->u.aenfx.count = cnt;
5276 memcpy(e->u.aenfx.mbx, data, sizeof(*data) * cnt);
5277 return qla2x00_post_work(vha, e);
5280 void qla24xx_sched_upd_fcport(fc_port_t *fcport)
5282 unsigned long flags;
5284 if (IS_SW_RESV_ADDR(fcport->d_id))
5287 spin_lock_irqsave(&fcport->vha->work_lock, flags);
5288 if (fcport->disc_state == DSC_UPD_FCPORT) {
5289 spin_unlock_irqrestore(&fcport->vha->work_lock, flags);
5292 fcport->jiffies_at_registration = jiffies;
5293 fcport->sec_since_registration = 0;
5294 fcport->next_disc_state = DSC_DELETED;
5295 qla2x00_set_fcport_disc_state(fcport, DSC_UPD_FCPORT);
5296 spin_unlock_irqrestore(&fcport->vha->work_lock, flags);
5298 queue_work(system_unbound_wq, &fcport->reg_work);
5302 void qla24xx_create_new_sess(struct scsi_qla_host *vha, struct qla_work_evt *e)
5304 unsigned long flags;
5305 fc_port_t *fcport = NULL, *tfcp;
5306 struct qlt_plogi_ack_t *pla =
5307 (struct qlt_plogi_ack_t *)e->u.new_sess.pla;
5308 uint8_t free_fcport = 0;
5310 ql_dbg(ql_dbg_disc, vha, 0xffff,
5311 "%s %d %8phC enter\n",
5312 __func__, __LINE__, e->u.new_sess.port_name);
5314 spin_lock_irqsave(&vha->hw->tgt.sess_lock, flags);
5315 fcport = qla2x00_find_fcport_by_wwpn(vha, e->u.new_sess.port_name, 1);
5317 fcport->d_id = e->u.new_sess.id;
5319 fcport->fw_login_state = DSC_LS_PLOGI_PEND;
5320 memcpy(fcport->node_name,
5321 pla->iocb.u.isp24.u.plogi.node_name,
5323 qlt_plogi_ack_link(vha, pla, fcport, QLT_PLOGI_LINK_SAME_WWN);
5324 /* we took an extra ref_count to prevent PLOGI ACK when
5325 * fcport/sess has not been created.
5330 spin_unlock_irqrestore(&vha->hw->tgt.sess_lock, flags);
5331 fcport = qla2x00_alloc_fcport(vha, GFP_KERNEL);
5333 fcport->d_id = e->u.new_sess.id;
5334 fcport->flags |= FCF_FABRIC_DEVICE;
5335 fcport->fw_login_state = DSC_LS_PLOGI_PEND;
5336 fcport->tgt_short_link_down_cnt = 0;
5338 memcpy(fcport->port_name, e->u.new_sess.port_name,
5341 fcport->fc4_type = e->u.new_sess.fc4_type;
5342 if (NVME_PRIORITY(vha->hw, fcport))
5343 fcport->do_prli_nvme = 1;
5345 fcport->do_prli_nvme = 0;
5347 if (e->u.new_sess.fc4_type & FS_FCP_IS_N2N) {
5348 fcport->dm_login_expire = jiffies +
5349 QLA_N2N_WAIT_TIME * HZ;
5350 fcport->fc4_type = FS_FC4TYPE_FCP;
5351 fcport->n2n_flag = 1;
5352 if (vha->flags.nvme_enabled)
5353 fcport->fc4_type |= FS_FC4TYPE_NVME;
5357 ql_dbg(ql_dbg_disc, vha, 0xffff,
5358 "%s %8phC mem alloc fail.\n",
5359 __func__, e->u.new_sess.port_name);
5362 list_del(&pla->list);
5363 kmem_cache_free(qla_tgt_plogi_cachep, pla);
5368 spin_lock_irqsave(&vha->hw->tgt.sess_lock, flags);
5369 /* search again to make sure no one else got ahead */
5370 tfcp = qla2x00_find_fcport_by_wwpn(vha,
5371 e->u.new_sess.port_name, 1);
5373 /* should rarily happen */
5374 ql_dbg(ql_dbg_disc, vha, 0xffff,
5375 "%s %8phC found existing fcport b4 add. DS %d LS %d\n",
5376 __func__, tfcp->port_name, tfcp->disc_state,
5377 tfcp->fw_login_state);
5381 list_add_tail(&fcport->list, &vha->vp_fcports);
5385 qlt_plogi_ack_link(vha, pla, fcport,
5386 QLT_PLOGI_LINK_SAME_WWN);
5390 spin_unlock_irqrestore(&vha->hw->tgt.sess_lock, flags);
5393 fcport->id_changed = 1;
5394 fcport->scan_state = QLA_FCPORT_FOUND;
5395 fcport->chip_reset = vha->hw->base_qpair->chip_reset;
5396 memcpy(fcport->node_name, e->u.new_sess.node_name, WWN_SIZE);
5399 if (pla->iocb.u.isp24.status_subcode == ELS_PRLI) {
5402 fcport->fw_login_state = DSC_LS_PRLI_PEND;
5406 pla->iocb.u.isp24.nport_handle);
5407 fcport->fw_login_state = DSC_LS_PRLI_PEND;
5410 pla->iocb.u.isp24.u.prli.wd3_lo);
5413 fcport->conf_compl_supported = 1;
5415 if ((wd3_lo & BIT_4) == 0)
5416 fcport->port_type = FCT_INITIATOR;
5418 fcport->port_type = FCT_TARGET;
5420 qlt_plogi_ack_unref(vha, pla);
5422 fc_port_t *dfcp = NULL;
5424 spin_lock_irqsave(&vha->hw->tgt.sess_lock, flags);
5425 tfcp = qla2x00_find_fcport_by_nportid(vha,
5426 &e->u.new_sess.id, 1);
5427 if (tfcp && (tfcp != fcport)) {
5429 * We have a conflict fcport with same NportID.
5431 ql_dbg(ql_dbg_disc, vha, 0xffff,
5432 "%s %8phC found conflict b4 add. DS %d LS %d\n",
5433 __func__, tfcp->port_name, tfcp->disc_state,
5434 tfcp->fw_login_state);
5436 switch (tfcp->disc_state) {
5439 case DSC_DELETE_PEND:
5440 fcport->login_pause = 1;
5441 tfcp->conflict = fcport;
5444 fcport->login_pause = 1;
5445 tfcp->conflict = fcport;
5450 spin_unlock_irqrestore(&vha->hw->tgt.sess_lock, flags);
5452 qlt_schedule_sess_for_deletion(tfcp);
5454 if (N2N_TOPO(vha->hw)) {
5455 fcport->flags &= ~FCF_FABRIC_DEVICE;
5456 fcport->keep_nport_handle = 1;
5457 if (vha->flags.nvme_enabled) {
5459 (FS_FC4TYPE_NVME | FS_FC4TYPE_FCP);
5460 fcport->n2n_flag = 1;
5462 fcport->fw_login_state = 0;
5464 schedule_delayed_work(&vha->scan.scan_work, 5);
5466 qla24xx_fcport_handle_login(vha, fcport);
5472 qla2x00_free_fcport(fcport);
5474 list_del(&pla->list);
5475 kmem_cache_free(qla_tgt_plogi_cachep, pla);
5480 static void qla_sp_retry(struct scsi_qla_host *vha, struct qla_work_evt *e)
5482 struct srb *sp = e->u.iosb.sp;
5485 rval = qla2x00_start_sp(sp);
5486 if (rval != QLA_SUCCESS) {
5487 ql_dbg(ql_dbg_disc, vha, 0x2043,
5488 "%s: %s: Re-issue IOCB failed (%d).\n",
5489 __func__, sp->name, rval);
5490 qla24xx_sp_unmap(vha, sp);
5495 qla2x00_do_work(struct scsi_qla_host *vha)
5497 struct qla_work_evt *e, *tmp;
5498 unsigned long flags;
5502 spin_lock_irqsave(&vha->work_lock, flags);
5503 list_splice_init(&vha->work_list, &work);
5504 spin_unlock_irqrestore(&vha->work_lock, flags);
5506 list_for_each_entry_safe(e, tmp, &work, list) {
5510 fc_host_post_event(vha->host, fc_get_event_number(),
5511 e->u.aen.code, e->u.aen.data);
5513 case QLA_EVT_IDC_ACK:
5514 qla81xx_idc_ack(vha, e->u.idc_ack.mb);
5516 case QLA_EVT_ASYNC_LOGIN:
5517 qla2x00_async_login(vha, e->u.logio.fcport,
5520 case QLA_EVT_ASYNC_LOGOUT:
5521 rc = qla2x00_async_logout(vha, e->u.logio.fcport);
5523 case QLA_EVT_ASYNC_ADISC:
5524 qla2x00_async_adisc(vha, e->u.logio.fcport,
5527 case QLA_EVT_UEVENT:
5528 qla2x00_uevent_emit(vha, e->u.uevent.code);
5531 qlafx00_process_aen(vha, e);
5534 qla24xx_sp_unmap(vha, e->u.iosb.sp);
5536 case QLA_EVT_RELOGIN:
5537 qla2x00_relogin(vha);
5539 case QLA_EVT_NEW_SESS:
5540 qla24xx_create_new_sess(vha, e);
5543 qla24xx_async_gpdb(vha, e->u.fcport.fcport,
5547 qla24xx_async_prli(vha, e->u.fcport.fcport);
5550 qla24xx_async_gpsc(vha, e->u.fcport.fcport);
5553 qla24xx_async_gnl(vha, e->u.fcport.fcport);
5556 qla24xx_do_nack_work(vha, e);
5558 case QLA_EVT_ASYNC_PRLO:
5559 rc = qla2x00_async_prlo(vha, e->u.logio.fcport);
5561 case QLA_EVT_ASYNC_PRLO_DONE:
5562 qla2x00_async_prlo_done(vha, e->u.logio.fcport,
5566 qla24xx_async_gpnft(vha, e->u.gpnft.fc4_type,
5569 case QLA_EVT_GPNFT_DONE:
5570 qla24xx_async_gpnft_done(vha, e->u.iosb.sp);
5572 case QLA_EVT_GNNFT_DONE:
5573 qla24xx_async_gnnft_done(vha, e->u.iosb.sp);
5575 case QLA_EVT_GFPNID:
5576 qla24xx_async_gfpnid(vha, e->u.fcport.fcport);
5578 case QLA_EVT_SP_RETRY:
5579 qla_sp_retry(vha, e);
5582 qla_do_iidma_work(vha, e->u.fcport.fcport);
5584 case QLA_EVT_ELS_PLOGI:
5585 qla24xx_els_dcmd2_iocb(vha, ELS_DCMD_PLOGI,
5586 e->u.fcport.fcport, false);
5588 case QLA_EVT_SA_REPLACE:
5589 rc = qla24xx_issue_sa_replace_iocb(vha, e);
5594 /* put 'work' at head of 'vha->work_list' */
5595 spin_lock_irqsave(&vha->work_lock, flags);
5596 list_splice(&work, &vha->work_list);
5597 spin_unlock_irqrestore(&vha->work_lock, flags);
5600 list_del_init(&e->list);
5601 if (e->flags & QLA_EVT_FLAG_FREE)
5604 /* For each work completed decrement vha ref count */
5605 QLA_VHA_MARK_NOT_BUSY(vha);
5609 int qla24xx_post_relogin_work(struct scsi_qla_host *vha)
5611 struct qla_work_evt *e;
5613 e = qla2x00_alloc_work(vha, QLA_EVT_RELOGIN);
5616 set_bit(RELOGIN_NEEDED, &vha->dpc_flags);
5617 return QLA_FUNCTION_FAILED;
5620 return qla2x00_post_work(vha, e);
5623 /* Relogins all the fcports of a vport
5624 * Context: dpc thread
5626 void qla2x00_relogin(struct scsi_qla_host *vha)
5629 int status, relogin_needed = 0;
5630 struct event_arg ea;
5632 list_for_each_entry(fcport, &vha->vp_fcports, list) {
5634 * If the port is not ONLINE then try to login
5635 * to it if we haven't run out of retries.
5637 if (atomic_read(&fcport->state) != FCS_ONLINE &&
5638 fcport->login_retry) {
5639 if (fcport->scan_state != QLA_FCPORT_FOUND ||
5640 fcport->disc_state == DSC_LOGIN_AUTH_PEND ||
5641 fcport->disc_state == DSC_LOGIN_COMPLETE)
5644 if (fcport->flags & (FCF_ASYNC_SENT|FCF_ASYNC_ACTIVE) ||
5645 fcport->disc_state == DSC_DELETE_PEND) {
5648 if (vha->hw->current_topology != ISP_CFG_NL) {
5649 memset(&ea, 0, sizeof(ea));
5651 qla24xx_handle_relogin_event(vha, &ea);
5652 } else if (vha->hw->current_topology ==
5654 IS_QLA2XXX_MIDTYPE(vha->hw)) {
5655 (void)qla24xx_fcport_handle_login(vha,
5657 } else if (vha->hw->current_topology ==
5659 fcport->login_retry--;
5661 qla2x00_local_device_login(vha,
5663 if (status == QLA_SUCCESS) {
5664 fcport->old_loop_id =
5666 ql_dbg(ql_dbg_disc, vha, 0x2003,
5667 "Port login OK: logged in ID 0x%x.\n",
5669 qla2x00_update_fcport
5671 } else if (status == 1) {
5672 set_bit(RELOGIN_NEEDED,
5674 /* retry the login again */
5675 ql_dbg(ql_dbg_disc, vha, 0x2007,
5676 "Retrying %d login again loop_id 0x%x.\n",
5677 fcport->login_retry,
5680 fcport->login_retry = 0;
5683 if (fcport->login_retry == 0 &&
5684 status != QLA_SUCCESS)
5685 qla2x00_clear_loop_id(fcport);
5689 if (test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags))
5694 set_bit(RELOGIN_NEEDED, &vha->dpc_flags);
5696 ql_dbg(ql_dbg_disc, vha, 0x400e,
5700 /* Schedule work on any of the dpc-workqueues */
5702 qla83xx_schedule_work(scsi_qla_host_t *base_vha, int work_code)
5704 struct qla_hw_data *ha = base_vha->hw;
5706 switch (work_code) {
5707 case MBA_IDC_AEN: /* 0x8200 */
5709 queue_work(ha->dpc_lp_wq, &ha->idc_aen);
5712 case QLA83XX_NIC_CORE_RESET: /* 0x1 */
5713 if (!ha->flags.nic_core_reset_hdlr_active) {
5715 queue_work(ha->dpc_hp_wq, &ha->nic_core_reset);
5717 ql_dbg(ql_dbg_p3p, base_vha, 0xb05e,
5718 "NIC Core reset is already active. Skip "
5719 "scheduling it again.\n");
5721 case QLA83XX_IDC_STATE_HANDLER: /* 0x2 */
5723 queue_work(ha->dpc_hp_wq, &ha->idc_state_handler);
5725 case QLA83XX_NIC_CORE_UNRECOVERABLE: /* 0x3 */
5727 queue_work(ha->dpc_hp_wq, &ha->nic_core_unrecoverable);
5730 ql_log(ql_log_warn, base_vha, 0xb05f,
5731 "Unknown work-code=0x%x.\n", work_code);
5737 /* Work: Perform NIC Core Unrecoverable state handling */
5739 qla83xx_nic_core_unrecoverable_work(struct work_struct *work)
5741 struct qla_hw_data *ha =
5742 container_of(work, struct qla_hw_data, nic_core_unrecoverable);
5743 scsi_qla_host_t *base_vha = pci_get_drvdata(ha->pdev);
5744 uint32_t dev_state = 0;
5746 qla83xx_idc_lock(base_vha, 0);
5747 qla83xx_rd_reg(base_vha, QLA83XX_IDC_DEV_STATE, &dev_state);
5748 qla83xx_reset_ownership(base_vha);
5749 if (ha->flags.nic_core_reset_owner) {
5750 ha->flags.nic_core_reset_owner = 0;
5751 qla83xx_wr_reg(base_vha, QLA83XX_IDC_DEV_STATE,
5752 QLA8XXX_DEV_FAILED);
5753 ql_log(ql_log_info, base_vha, 0xb060, "HW State: FAILED.\n");
5754 qla83xx_schedule_work(base_vha, QLA83XX_IDC_STATE_HANDLER);
5756 qla83xx_idc_unlock(base_vha, 0);
5759 /* Work: Execute IDC state handler */
5761 qla83xx_idc_state_handler_work(struct work_struct *work)
5763 struct qla_hw_data *ha =
5764 container_of(work, struct qla_hw_data, idc_state_handler);
5765 scsi_qla_host_t *base_vha = pci_get_drvdata(ha->pdev);
5766 uint32_t dev_state = 0;
5768 qla83xx_idc_lock(base_vha, 0);
5769 qla83xx_rd_reg(base_vha, QLA83XX_IDC_DEV_STATE, &dev_state);
5770 if (dev_state == QLA8XXX_DEV_FAILED ||
5771 dev_state == QLA8XXX_DEV_NEED_QUIESCENT)
5772 qla83xx_idc_state_handler(base_vha);
5773 qla83xx_idc_unlock(base_vha, 0);
5777 qla83xx_check_nic_core_fw_alive(scsi_qla_host_t *base_vha)
5779 int rval = QLA_SUCCESS;
5780 unsigned long heart_beat_wait = jiffies + (1 * HZ);
5781 uint32_t heart_beat_counter1, heart_beat_counter2;
5784 if (time_after(jiffies, heart_beat_wait)) {
5785 ql_dbg(ql_dbg_p3p, base_vha, 0xb07c,
5786 "Nic Core f/w is not alive.\n");
5787 rval = QLA_FUNCTION_FAILED;
5791 qla83xx_idc_lock(base_vha, 0);
5792 qla83xx_rd_reg(base_vha, QLA83XX_FW_HEARTBEAT,
5793 &heart_beat_counter1);
5794 qla83xx_idc_unlock(base_vha, 0);
5796 qla83xx_idc_lock(base_vha, 0);
5797 qla83xx_rd_reg(base_vha, QLA83XX_FW_HEARTBEAT,
5798 &heart_beat_counter2);
5799 qla83xx_idc_unlock(base_vha, 0);
5800 } while (heart_beat_counter1 == heart_beat_counter2);
5805 /* Work: Perform NIC Core Reset handling */
5807 qla83xx_nic_core_reset_work(struct work_struct *work)
5809 struct qla_hw_data *ha =
5810 container_of(work, struct qla_hw_data, nic_core_reset);
5811 scsi_qla_host_t *base_vha = pci_get_drvdata(ha->pdev);
5812 uint32_t dev_state = 0;
5814 if (IS_QLA2031(ha)) {
5815 if (qla2xxx_mctp_dump(base_vha) != QLA_SUCCESS)
5816 ql_log(ql_log_warn, base_vha, 0xb081,
5817 "Failed to dump mctp\n");
5821 if (!ha->flags.nic_core_reset_hdlr_active) {
5822 if (qla83xx_check_nic_core_fw_alive(base_vha) == QLA_SUCCESS) {
5823 qla83xx_idc_lock(base_vha, 0);
5824 qla83xx_rd_reg(base_vha, QLA83XX_IDC_DEV_STATE,
5826 qla83xx_idc_unlock(base_vha, 0);
5827 if (dev_state != QLA8XXX_DEV_NEED_RESET) {
5828 ql_dbg(ql_dbg_p3p, base_vha, 0xb07a,
5829 "Nic Core f/w is alive.\n");
5834 ha->flags.nic_core_reset_hdlr_active = 1;
5835 if (qla83xx_nic_core_reset(base_vha)) {
5836 /* NIC Core reset failed. */
5837 ql_dbg(ql_dbg_p3p, base_vha, 0xb061,
5838 "NIC Core reset failed.\n");
5840 ha->flags.nic_core_reset_hdlr_active = 0;
5844 /* Work: Handle 8200 IDC aens */
5846 qla83xx_service_idc_aen(struct work_struct *work)
5848 struct qla_hw_data *ha =
5849 container_of(work, struct qla_hw_data, idc_aen);
5850 scsi_qla_host_t *base_vha = pci_get_drvdata(ha->pdev);
5851 uint32_t dev_state, idc_control;
5853 qla83xx_idc_lock(base_vha, 0);
5854 qla83xx_rd_reg(base_vha, QLA83XX_IDC_DEV_STATE, &dev_state);
5855 qla83xx_rd_reg(base_vha, QLA83XX_IDC_CONTROL, &idc_control);
5856 qla83xx_idc_unlock(base_vha, 0);
5857 if (dev_state == QLA8XXX_DEV_NEED_RESET) {
5858 if (idc_control & QLA83XX_IDC_GRACEFUL_RESET) {
5859 ql_dbg(ql_dbg_p3p, base_vha, 0xb062,
5860 "Application requested NIC Core Reset.\n");
5861 qla83xx_schedule_work(base_vha, QLA83XX_NIC_CORE_RESET);
5862 } else if (qla83xx_check_nic_core_fw_alive(base_vha) ==
5864 ql_dbg(ql_dbg_p3p, base_vha, 0xb07b,
5865 "Other protocol driver requested NIC Core Reset.\n");
5866 qla83xx_schedule_work(base_vha, QLA83XX_NIC_CORE_RESET);
5868 } else if (dev_state == QLA8XXX_DEV_FAILED ||
5869 dev_state == QLA8XXX_DEV_NEED_QUIESCENT) {
5870 qla83xx_schedule_work(base_vha, QLA83XX_IDC_STATE_HANDLER);
5875 * Control the frequency of IDC lock retries
5877 #define QLA83XX_WAIT_LOGIC_MS 100
5880 qla83xx_force_lock_recovery(scsi_qla_host_t *base_vha)
5884 uint32_t idc_lck_rcvry_stage_mask = 0x3;
5885 uint32_t idc_lck_rcvry_owner_mask = 0x3c;
5886 struct qla_hw_data *ha = base_vha->hw;
5888 ql_dbg(ql_dbg_p3p, base_vha, 0xb086,
5889 "Trying force recovery of the IDC lock.\n");
5891 rval = qla83xx_rd_reg(base_vha, QLA83XX_IDC_LOCK_RECOVERY, &data);
5895 if ((data & idc_lck_rcvry_stage_mask) > 0) {
5898 data = (IDC_LOCK_RECOVERY_STAGE1) | (ha->portnum << 2);
5899 rval = qla83xx_wr_reg(base_vha, QLA83XX_IDC_LOCK_RECOVERY,
5906 rval = qla83xx_rd_reg(base_vha, QLA83XX_IDC_LOCK_RECOVERY,
5911 if (((data & idc_lck_rcvry_owner_mask) >> 2) == ha->portnum) {
5912 data &= (IDC_LOCK_RECOVERY_STAGE2 |
5913 ~(idc_lck_rcvry_stage_mask));
5914 rval = qla83xx_wr_reg(base_vha,
5915 QLA83XX_IDC_LOCK_RECOVERY, data);
5919 /* Forcefully perform IDC UnLock */
5920 rval = qla83xx_rd_reg(base_vha, QLA83XX_DRIVER_UNLOCK,
5924 /* Clear lock-id by setting 0xff */
5925 rval = qla83xx_wr_reg(base_vha, QLA83XX_DRIVER_LOCKID,
5929 /* Clear lock-recovery by setting 0x0 */
5930 rval = qla83xx_wr_reg(base_vha,
5931 QLA83XX_IDC_LOCK_RECOVERY, 0x0);
5942 qla83xx_idc_lock_recovery(scsi_qla_host_t *base_vha)
5944 int rval = QLA_SUCCESS;
5945 uint32_t o_drv_lockid, n_drv_lockid;
5946 unsigned long lock_recovery_timeout;
5948 lock_recovery_timeout = jiffies + QLA83XX_MAX_LOCK_RECOVERY_WAIT;
5950 rval = qla83xx_rd_reg(base_vha, QLA83XX_DRIVER_LOCKID, &o_drv_lockid);
5954 /* MAX wait time before forcing IDC Lock recovery = 2 secs */
5955 if (time_after_eq(jiffies, lock_recovery_timeout)) {
5956 if (qla83xx_force_lock_recovery(base_vha) == QLA_SUCCESS)
5959 return QLA_FUNCTION_FAILED;
5962 rval = qla83xx_rd_reg(base_vha, QLA83XX_DRIVER_LOCKID, &n_drv_lockid);
5966 if (o_drv_lockid == n_drv_lockid) {
5967 msleep(QLA83XX_WAIT_LOGIC_MS);
5977 * Context: task, can sleep
5980 qla83xx_idc_lock(scsi_qla_host_t *base_vha, uint16_t requester_id)
5983 uint32_t lock_owner;
5984 struct qla_hw_data *ha = base_vha->hw;
5988 /* IDC-lock implementation using driver-lock/lock-id remote registers */
5990 if (qla83xx_rd_reg(base_vha, QLA83XX_DRIVER_LOCK, &data)
5993 /* Setting lock-id to our function-number */
5994 qla83xx_wr_reg(base_vha, QLA83XX_DRIVER_LOCKID,
5997 qla83xx_rd_reg(base_vha, QLA83XX_DRIVER_LOCKID,
5999 ql_dbg(ql_dbg_p3p, base_vha, 0xb063,
6000 "Failed to acquire IDC lock, acquired by %d, "
6001 "retrying...\n", lock_owner);
6003 /* Retry/Perform IDC-Lock recovery */
6004 if (qla83xx_idc_lock_recovery(base_vha)
6006 msleep(QLA83XX_WAIT_LOGIC_MS);
6009 ql_log(ql_log_warn, base_vha, 0xb075,
6010 "IDC Lock recovery FAILED.\n");
6019 qla25xx_rdp_rsp_reduce_size(struct scsi_qla_host *vha,
6020 struct purex_entry_24xx *purex)
6023 u32 sid = purex->s_id[2] << 16 | purex->s_id[1] << 8 | purex->s_id[0];
6024 struct port_database_24xx *pdb;
6026 /* Domain Controller is always logged-out. */
6027 /* if RDP request is not from Domain Controller: */
6028 if (sid != 0xfffc01)
6031 ql_dbg(ql_dbg_init, vha, 0x0181, "%s: s_id=%#x\n", __func__, sid);
6033 pdb = kzalloc(sizeof(*pdb), GFP_KERNEL);
6035 ql_dbg(ql_dbg_init, vha, 0x0181,
6036 "%s: Failed allocate pdb\n", __func__);
6037 } else if (qla24xx_get_port_database(vha,
6038 le16_to_cpu(purex->nport_handle), pdb)) {
6039 ql_dbg(ql_dbg_init, vha, 0x0181,
6040 "%s: Failed get pdb sid=%x\n", __func__, sid);
6041 } else if (pdb->current_login_state != PDS_PLOGI_COMPLETE &&
6042 pdb->current_login_state != PDS_PRLI_COMPLETE) {
6043 ql_dbg(ql_dbg_init, vha, 0x0181,
6044 "%s: Port not logged in sid=%#x\n", __func__, sid);
6046 /* RDP request is from logged in port */
6052 vha->hw->isp_ops->fw_version_str(vha, fwstr, sizeof(fwstr));
6053 fwstr[strcspn(fwstr, " ")] = 0;
6054 /* if FW version allows RDP response length upto 2048 bytes: */
6055 if (strcmp(fwstr, "8.09.00") > 0 || strcmp(fwstr, "8.05.65") == 0)
6058 ql_dbg(ql_dbg_init, vha, 0x0181, "%s: fw=%s\n", __func__, fwstr);
6060 /* RDP response length is to be reduced to maximum 256 bytes */
6065 * Function Name: qla24xx_process_purex_iocb
6068 * Prepare a RDP response and send to Fabric switch
6071 * vha: SCSI qla host
6072 * purex: RDP request received by HBA
6074 void qla24xx_process_purex_rdp(struct scsi_qla_host *vha,
6075 struct purex_item *item)
6077 struct qla_hw_data *ha = vha->hw;
6078 struct purex_entry_24xx *purex =
6079 (struct purex_entry_24xx *)&item->iocb;
6080 dma_addr_t rsp_els_dma;
6081 dma_addr_t rsp_payload_dma;
6082 dma_addr_t stat_dma;
6084 struct els_entry_24xx *rsp_els = NULL;
6085 struct rdp_rsp_payload *rsp_payload = NULL;
6086 struct link_statistics *stat = NULL;
6087 uint8_t *sfp = NULL;
6088 uint16_t sfp_flags = 0;
6089 uint rsp_payload_length = sizeof(*rsp_payload);
6092 ql_dbg(ql_dbg_init + ql_dbg_verbose, vha, 0x0180,
6093 "%s: Enter\n", __func__);
6095 ql_dbg(ql_dbg_init + ql_dbg_verbose, vha, 0x0181,
6096 "-------- ELS REQ -------\n");
6097 ql_dump_buffer(ql_dbg_init + ql_dbg_verbose, vha, 0x0182,
6098 purex, sizeof(*purex));
6100 if (qla25xx_rdp_rsp_reduce_size(vha, purex)) {
6101 rsp_payload_length =
6102 offsetof(typeof(*rsp_payload), optical_elmt_desc);
6103 ql_dbg(ql_dbg_init, vha, 0x0181,
6104 "Reducing RSP payload length to %u bytes...\n",
6105 rsp_payload_length);
6108 rsp_els = dma_alloc_coherent(&ha->pdev->dev, sizeof(*rsp_els),
6109 &rsp_els_dma, GFP_KERNEL);
6111 ql_log(ql_log_warn, vha, 0x0183,
6112 "Failed allocate dma buffer ELS RSP.\n");
6116 rsp_payload = dma_alloc_coherent(&ha->pdev->dev, sizeof(*rsp_payload),
6117 &rsp_payload_dma, GFP_KERNEL);
6119 ql_log(ql_log_warn, vha, 0x0184,
6120 "Failed allocate dma buffer ELS RSP payload.\n");
6124 sfp = dma_alloc_coherent(&ha->pdev->dev, SFP_RTDI_LEN,
6125 &sfp_dma, GFP_KERNEL);
6127 stat = dma_alloc_coherent(&ha->pdev->dev, sizeof(*stat),
6128 &stat_dma, GFP_KERNEL);
6130 /* Prepare Response IOCB */
6131 rsp_els->entry_type = ELS_IOCB_TYPE;
6132 rsp_els->entry_count = 1;
6133 rsp_els->sys_define = 0;
6134 rsp_els->entry_status = 0;
6135 rsp_els->handle = 0;
6136 rsp_els->nport_handle = purex->nport_handle;
6137 rsp_els->tx_dsd_count = cpu_to_le16(1);
6138 rsp_els->vp_index = purex->vp_idx;
6139 rsp_els->sof_type = EST_SOFI3;
6140 rsp_els->rx_xchg_address = purex->rx_xchg_addr;
6141 rsp_els->rx_dsd_count = 0;
6142 rsp_els->opcode = purex->els_frame_payload[0];
6144 rsp_els->d_id[0] = purex->s_id[0];
6145 rsp_els->d_id[1] = purex->s_id[1];
6146 rsp_els->d_id[2] = purex->s_id[2];
6148 rsp_els->control_flags = cpu_to_le16(EPD_ELS_ACC);
6149 rsp_els->rx_byte_count = 0;
6150 rsp_els->tx_byte_count = cpu_to_le32(rsp_payload_length);
6152 put_unaligned_le64(rsp_payload_dma, &rsp_els->tx_address);
6153 rsp_els->tx_len = rsp_els->tx_byte_count;
6155 rsp_els->rx_address = 0;
6156 rsp_els->rx_len = 0;
6158 /* Prepare Response Payload */
6159 rsp_payload->hdr.cmd = cpu_to_be32(0x2 << 24); /* LS_ACC */
6160 rsp_payload->hdr.len = cpu_to_be32(le32_to_cpu(rsp_els->tx_byte_count) -
6161 sizeof(rsp_payload->hdr));
6163 /* Link service Request Info Descriptor */
6164 rsp_payload->ls_req_info_desc.desc_tag = cpu_to_be32(0x1);
6165 rsp_payload->ls_req_info_desc.desc_len =
6166 cpu_to_be32(RDP_DESC_LEN(rsp_payload->ls_req_info_desc));
6167 rsp_payload->ls_req_info_desc.req_payload_word_0 =
6168 cpu_to_be32p((uint32_t *)purex->els_frame_payload);
6170 /* Link service Request Info Descriptor 2 */
6171 rsp_payload->ls_req_info_desc2.desc_tag = cpu_to_be32(0x1);
6172 rsp_payload->ls_req_info_desc2.desc_len =
6173 cpu_to_be32(RDP_DESC_LEN(rsp_payload->ls_req_info_desc2));
6174 rsp_payload->ls_req_info_desc2.req_payload_word_0 =
6175 cpu_to_be32p((uint32_t *)purex->els_frame_payload);
6178 rsp_payload->sfp_diag_desc.desc_tag = cpu_to_be32(0x10000);
6179 rsp_payload->sfp_diag_desc.desc_len =
6180 cpu_to_be32(RDP_DESC_LEN(rsp_payload->sfp_diag_desc));
6184 memset(sfp, 0, SFP_RTDI_LEN);
6185 rval = qla2x00_read_sfp(vha, sfp_dma, sfp, 0xa0, 0x7, 2, 0);
6187 /* SFP Flags bits 3-0: Port Tx Laser Type */
6188 if (sfp[0] & BIT_2 || sfp[1] & (BIT_6|BIT_5))
6189 sfp_flags |= BIT_0; /* short wave */
6190 else if (sfp[0] & BIT_1)
6191 sfp_flags |= BIT_1; /* long wave 1310nm */
6192 else if (sfp[1] & BIT_4)
6193 sfp_flags |= BIT_1|BIT_0; /* long wave 1550nm */
6197 memset(sfp, 0, SFP_RTDI_LEN);
6198 rval = qla2x00_read_sfp(vha, sfp_dma, sfp, 0xa0, 0x0, 1, 0);
6200 sfp_flags |= BIT_4; /* optical */
6202 sfp_flags |= BIT_6; /* sfp+ */
6205 rsp_payload->sfp_diag_desc.sfp_flags = cpu_to_be16(sfp_flags);
6207 /* SFP Diagnostics */
6208 memset(sfp, 0, SFP_RTDI_LEN);
6209 rval = qla2x00_read_sfp(vha, sfp_dma, sfp, 0xa2, 0x60, 10, 0);
6211 __be16 *trx = (__force __be16 *)sfp; /* already be16 */
6212 rsp_payload->sfp_diag_desc.temperature = trx[0];
6213 rsp_payload->sfp_diag_desc.vcc = trx[1];
6214 rsp_payload->sfp_diag_desc.tx_bias = trx[2];
6215 rsp_payload->sfp_diag_desc.tx_power = trx[3];
6216 rsp_payload->sfp_diag_desc.rx_power = trx[4];
6220 /* Port Speed Descriptor */
6221 rsp_payload->port_speed_desc.desc_tag = cpu_to_be32(0x10001);
6222 rsp_payload->port_speed_desc.desc_len =
6223 cpu_to_be32(RDP_DESC_LEN(rsp_payload->port_speed_desc));
6224 rsp_payload->port_speed_desc.speed_capab = cpu_to_be16(
6225 qla25xx_fdmi_port_speed_capability(ha));
6226 rsp_payload->port_speed_desc.operating_speed = cpu_to_be16(
6227 qla25xx_fdmi_port_speed_currently(ha));
6229 /* Link Error Status Descriptor */
6230 rsp_payload->ls_err_desc.desc_tag = cpu_to_be32(0x10002);
6231 rsp_payload->ls_err_desc.desc_len =
6232 cpu_to_be32(RDP_DESC_LEN(rsp_payload->ls_err_desc));
6235 rval = qla24xx_get_isp_stats(vha, stat, stat_dma, 0);
6237 rsp_payload->ls_err_desc.link_fail_cnt =
6238 cpu_to_be32(le32_to_cpu(stat->link_fail_cnt));
6239 rsp_payload->ls_err_desc.loss_sync_cnt =
6240 cpu_to_be32(le32_to_cpu(stat->loss_sync_cnt));
6241 rsp_payload->ls_err_desc.loss_sig_cnt =
6242 cpu_to_be32(le32_to_cpu(stat->loss_sig_cnt));
6243 rsp_payload->ls_err_desc.prim_seq_err_cnt =
6244 cpu_to_be32(le32_to_cpu(stat->prim_seq_err_cnt));
6245 rsp_payload->ls_err_desc.inval_xmit_word_cnt =
6246 cpu_to_be32(le32_to_cpu(stat->inval_xmit_word_cnt));
6247 rsp_payload->ls_err_desc.inval_crc_cnt =
6248 cpu_to_be32(le32_to_cpu(stat->inval_crc_cnt));
6249 rsp_payload->ls_err_desc.pn_port_phy_type |= BIT_6;
6253 /* Portname Descriptor */
6254 rsp_payload->port_name_diag_desc.desc_tag = cpu_to_be32(0x10003);
6255 rsp_payload->port_name_diag_desc.desc_len =
6256 cpu_to_be32(RDP_DESC_LEN(rsp_payload->port_name_diag_desc));
6257 memcpy(rsp_payload->port_name_diag_desc.WWNN,
6259 sizeof(rsp_payload->port_name_diag_desc.WWNN));
6260 memcpy(rsp_payload->port_name_diag_desc.WWPN,
6262 sizeof(rsp_payload->port_name_diag_desc.WWPN));
6264 /* F-Port Portname Descriptor */
6265 rsp_payload->port_name_direct_desc.desc_tag = cpu_to_be32(0x10003);
6266 rsp_payload->port_name_direct_desc.desc_len =
6267 cpu_to_be32(RDP_DESC_LEN(rsp_payload->port_name_direct_desc));
6268 memcpy(rsp_payload->port_name_direct_desc.WWNN,
6269 vha->fabric_node_name,
6270 sizeof(rsp_payload->port_name_direct_desc.WWNN));
6271 memcpy(rsp_payload->port_name_direct_desc.WWPN,
6272 vha->fabric_port_name,
6273 sizeof(rsp_payload->port_name_direct_desc.WWPN));
6275 /* Bufer Credit Descriptor */
6276 rsp_payload->buffer_credit_desc.desc_tag = cpu_to_be32(0x10006);
6277 rsp_payload->buffer_credit_desc.desc_len =
6278 cpu_to_be32(RDP_DESC_LEN(rsp_payload->buffer_credit_desc));
6279 rsp_payload->buffer_credit_desc.fcport_b2b = 0;
6280 rsp_payload->buffer_credit_desc.attached_fcport_b2b = cpu_to_be32(0);
6281 rsp_payload->buffer_credit_desc.fcport_rtt = cpu_to_be32(0);
6283 if (ha->flags.plogi_template_valid) {
6285 be16_to_cpu(ha->plogi_els_payld.fl_csp.sp_bb_cred);
6286 rsp_payload->buffer_credit_desc.fcport_b2b = cpu_to_be32(tmp);
6289 if (rsp_payload_length < sizeof(*rsp_payload))
6292 /* Optical Element Descriptor, Temperature */
6293 rsp_payload->optical_elmt_desc[0].desc_tag = cpu_to_be32(0x10007);
6294 rsp_payload->optical_elmt_desc[0].desc_len =
6295 cpu_to_be32(RDP_DESC_LEN(*rsp_payload->optical_elmt_desc));
6296 /* Optical Element Descriptor, Voltage */
6297 rsp_payload->optical_elmt_desc[1].desc_tag = cpu_to_be32(0x10007);
6298 rsp_payload->optical_elmt_desc[1].desc_len =
6299 cpu_to_be32(RDP_DESC_LEN(*rsp_payload->optical_elmt_desc));
6300 /* Optical Element Descriptor, Tx Bias Current */
6301 rsp_payload->optical_elmt_desc[2].desc_tag = cpu_to_be32(0x10007);
6302 rsp_payload->optical_elmt_desc[2].desc_len =
6303 cpu_to_be32(RDP_DESC_LEN(*rsp_payload->optical_elmt_desc));
6304 /* Optical Element Descriptor, Tx Power */
6305 rsp_payload->optical_elmt_desc[3].desc_tag = cpu_to_be32(0x10007);
6306 rsp_payload->optical_elmt_desc[3].desc_len =
6307 cpu_to_be32(RDP_DESC_LEN(*rsp_payload->optical_elmt_desc));
6308 /* Optical Element Descriptor, Rx Power */
6309 rsp_payload->optical_elmt_desc[4].desc_tag = cpu_to_be32(0x10007);
6310 rsp_payload->optical_elmt_desc[4].desc_len =
6311 cpu_to_be32(RDP_DESC_LEN(*rsp_payload->optical_elmt_desc));
6314 memset(sfp, 0, SFP_RTDI_LEN);
6315 rval = qla2x00_read_sfp(vha, sfp_dma, sfp, 0xa2, 0, 64, 0);
6317 __be16 *trx = (__force __be16 *)sfp; /* already be16 */
6319 /* Optical Element Descriptor, Temperature */
6320 rsp_payload->optical_elmt_desc[0].high_alarm = trx[0];
6321 rsp_payload->optical_elmt_desc[0].low_alarm = trx[1];
6322 rsp_payload->optical_elmt_desc[0].high_warn = trx[2];
6323 rsp_payload->optical_elmt_desc[0].low_warn = trx[3];
6324 rsp_payload->optical_elmt_desc[0].element_flags =
6325 cpu_to_be32(1 << 28);
6327 /* Optical Element Descriptor, Voltage */
6328 rsp_payload->optical_elmt_desc[1].high_alarm = trx[4];
6329 rsp_payload->optical_elmt_desc[1].low_alarm = trx[5];
6330 rsp_payload->optical_elmt_desc[1].high_warn = trx[6];
6331 rsp_payload->optical_elmt_desc[1].low_warn = trx[7];
6332 rsp_payload->optical_elmt_desc[1].element_flags =
6333 cpu_to_be32(2 << 28);
6335 /* Optical Element Descriptor, Tx Bias Current */
6336 rsp_payload->optical_elmt_desc[2].high_alarm = trx[8];
6337 rsp_payload->optical_elmt_desc[2].low_alarm = trx[9];
6338 rsp_payload->optical_elmt_desc[2].high_warn = trx[10];
6339 rsp_payload->optical_elmt_desc[2].low_warn = trx[11];
6340 rsp_payload->optical_elmt_desc[2].element_flags =
6341 cpu_to_be32(3 << 28);
6343 /* Optical Element Descriptor, Tx Power */
6344 rsp_payload->optical_elmt_desc[3].high_alarm = trx[12];
6345 rsp_payload->optical_elmt_desc[3].low_alarm = trx[13];
6346 rsp_payload->optical_elmt_desc[3].high_warn = trx[14];
6347 rsp_payload->optical_elmt_desc[3].low_warn = trx[15];
6348 rsp_payload->optical_elmt_desc[3].element_flags =
6349 cpu_to_be32(4 << 28);
6351 /* Optical Element Descriptor, Rx Power */
6352 rsp_payload->optical_elmt_desc[4].high_alarm = trx[16];
6353 rsp_payload->optical_elmt_desc[4].low_alarm = trx[17];
6354 rsp_payload->optical_elmt_desc[4].high_warn = trx[18];
6355 rsp_payload->optical_elmt_desc[4].low_warn = trx[19];
6356 rsp_payload->optical_elmt_desc[4].element_flags =
6357 cpu_to_be32(5 << 28);
6360 memset(sfp, 0, SFP_RTDI_LEN);
6361 rval = qla2x00_read_sfp(vha, sfp_dma, sfp, 0xa2, 112, 64, 0);
6363 /* Temperature high/low alarm/warning */
6364 rsp_payload->optical_elmt_desc[0].element_flags |=
6366 (sfp[0] >> 7 & 1) << 3 |
6367 (sfp[0] >> 6 & 1) << 2 |
6368 (sfp[4] >> 7 & 1) << 1 |
6369 (sfp[4] >> 6 & 1) << 0);
6371 /* Voltage high/low alarm/warning */
6372 rsp_payload->optical_elmt_desc[1].element_flags |=
6374 (sfp[0] >> 5 & 1) << 3 |
6375 (sfp[0] >> 4 & 1) << 2 |
6376 (sfp[4] >> 5 & 1) << 1 |
6377 (sfp[4] >> 4 & 1) << 0);
6379 /* Tx Bias Current high/low alarm/warning */
6380 rsp_payload->optical_elmt_desc[2].element_flags |=
6382 (sfp[0] >> 3 & 1) << 3 |
6383 (sfp[0] >> 2 & 1) << 2 |
6384 (sfp[4] >> 3 & 1) << 1 |
6385 (sfp[4] >> 2 & 1) << 0);
6387 /* Tx Power high/low alarm/warning */
6388 rsp_payload->optical_elmt_desc[3].element_flags |=
6390 (sfp[0] >> 1 & 1) << 3 |
6391 (sfp[0] >> 0 & 1) << 2 |
6392 (sfp[4] >> 1 & 1) << 1 |
6393 (sfp[4] >> 0 & 1) << 0);
6395 /* Rx Power high/low alarm/warning */
6396 rsp_payload->optical_elmt_desc[4].element_flags |=
6398 (sfp[1] >> 7 & 1) << 3 |
6399 (sfp[1] >> 6 & 1) << 2 |
6400 (sfp[5] >> 7 & 1) << 1 |
6401 (sfp[5] >> 6 & 1) << 0);
6405 /* Optical Product Data Descriptor */
6406 rsp_payload->optical_prod_desc.desc_tag = cpu_to_be32(0x10008);
6407 rsp_payload->optical_prod_desc.desc_len =
6408 cpu_to_be32(RDP_DESC_LEN(rsp_payload->optical_prod_desc));
6411 memset(sfp, 0, SFP_RTDI_LEN);
6412 rval = qla2x00_read_sfp(vha, sfp_dma, sfp, 0xa0, 20, 64, 0);
6414 memcpy(rsp_payload->optical_prod_desc.vendor_name,
6416 sizeof(rsp_payload->optical_prod_desc.vendor_name));
6417 memcpy(rsp_payload->optical_prod_desc.part_number,
6419 sizeof(rsp_payload->optical_prod_desc.part_number));
6420 memcpy(rsp_payload->optical_prod_desc.revision,
6422 sizeof(rsp_payload->optical_prod_desc.revision));
6423 memcpy(rsp_payload->optical_prod_desc.serial_number,
6425 sizeof(rsp_payload->optical_prod_desc.serial_number));
6428 memset(sfp, 0, SFP_RTDI_LEN);
6429 rval = qla2x00_read_sfp(vha, sfp_dma, sfp, 0xa0, 84, 8, 0);
6431 memcpy(rsp_payload->optical_prod_desc.date,
6433 sizeof(rsp_payload->optical_prod_desc.date));
6438 ql_dbg(ql_dbg_init, vha, 0x0183,
6439 "Sending ELS Response to RDP Request...\n");
6440 ql_dbg(ql_dbg_init + ql_dbg_verbose, vha, 0x0184,
6441 "-------- ELS RSP -------\n");
6442 ql_dump_buffer(ql_dbg_init + ql_dbg_verbose, vha, 0x0185,
6443 rsp_els, sizeof(*rsp_els));
6444 ql_dbg(ql_dbg_init + ql_dbg_verbose, vha, 0x0186,
6445 "-------- ELS RSP PAYLOAD -------\n");
6446 ql_dump_buffer(ql_dbg_init + ql_dbg_verbose, vha, 0x0187,
6447 rsp_payload, rsp_payload_length);
6449 rval = qla2x00_issue_iocb(vha, rsp_els, rsp_els_dma, 0);
6452 ql_log(ql_log_warn, vha, 0x0188,
6453 "%s: iocb failed to execute -> %x\n", __func__, rval);
6454 } else if (rsp_els->comp_status) {
6455 ql_log(ql_log_warn, vha, 0x0189,
6456 "%s: iocb failed to complete -> completion=%#x subcode=(%#x,%#x)\n",
6457 __func__, rsp_els->comp_status,
6458 rsp_els->error_subcode_1, rsp_els->error_subcode_2);
6460 ql_dbg(ql_dbg_init, vha, 0x018a, "%s: done.\n", __func__);
6465 dma_free_coherent(&ha->pdev->dev, sizeof(*stat),
6468 dma_free_coherent(&ha->pdev->dev, SFP_RTDI_LEN,
6471 dma_free_coherent(&ha->pdev->dev, sizeof(*rsp_payload),
6472 rsp_payload, rsp_payload_dma);
6474 dma_free_coherent(&ha->pdev->dev, sizeof(*rsp_els),
6475 rsp_els, rsp_els_dma);
6479 qla24xx_free_purex_item(struct purex_item *item)
6481 if (item == &item->vha->default_item)
6482 memset(&item->vha->default_item, 0, sizeof(struct purex_item));
6487 void qla24xx_process_purex_list(struct purex_list *list)
6489 struct list_head head = LIST_HEAD_INIT(head);
6490 struct purex_item *item, *next;
6493 spin_lock_irqsave(&list->lock, flags);
6494 list_splice_init(&list->head, &head);
6495 spin_unlock_irqrestore(&list->lock, flags);
6497 list_for_each_entry_safe(item, next, &head, list) {
6498 list_del(&item->list);
6499 item->process_item(item->vha, item);
6500 qla24xx_free_purex_item(item);
6505 * Context: task, can sleep
6508 qla83xx_idc_unlock(scsi_qla_host_t *base_vha, uint16_t requester_id)
6511 uint16_t options = (requester_id << 15) | BIT_7;
6515 struct qla_hw_data *ha = base_vha->hw;
6519 /* IDC-unlock implementation using driver-unlock/lock-id
6524 if (qla83xx_rd_reg(base_vha, QLA83XX_DRIVER_LOCKID, &data)
6526 if (data == ha->portnum) {
6527 qla83xx_rd_reg(base_vha, QLA83XX_DRIVER_UNLOCK, &data);
6528 /* Clearing lock-id by setting 0xff */
6529 qla83xx_wr_reg(base_vha, QLA83XX_DRIVER_LOCKID, 0xff);
6530 } else if (retry < 10) {
6531 /* SV: XXX: IDC unlock retrying needed here? */
6533 /* Retry for IDC-unlock */
6534 msleep(QLA83XX_WAIT_LOGIC_MS);
6536 ql_dbg(ql_dbg_p3p, base_vha, 0xb064,
6537 "Failed to release IDC lock, retrying=%d\n", retry);
6540 } else if (retry < 10) {
6541 /* Retry for IDC-unlock */
6542 msleep(QLA83XX_WAIT_LOGIC_MS);
6544 ql_dbg(ql_dbg_p3p, base_vha, 0xb065,
6545 "Failed to read drv-lockid, retrying=%d\n", retry);
6552 /* XXX: IDC-unlock implementation using access-control mbx */
6555 if (qla83xx_access_control(base_vha, options, 0, 0, NULL)) {
6557 /* Retry for IDC-unlock */
6558 msleep(QLA83XX_WAIT_LOGIC_MS);
6560 ql_dbg(ql_dbg_p3p, base_vha, 0xb066,
6561 "Failed to release IDC lock, retrying=%d\n", retry);
6571 __qla83xx_set_drv_presence(scsi_qla_host_t *vha)
6573 int rval = QLA_SUCCESS;
6574 struct qla_hw_data *ha = vha->hw;
6575 uint32_t drv_presence;
6577 rval = qla83xx_rd_reg(vha, QLA83XX_IDC_DRV_PRESENCE, &drv_presence);
6578 if (rval == QLA_SUCCESS) {
6579 drv_presence |= (1 << ha->portnum);
6580 rval = qla83xx_wr_reg(vha, QLA83XX_IDC_DRV_PRESENCE,
6588 qla83xx_set_drv_presence(scsi_qla_host_t *vha)
6590 int rval = QLA_SUCCESS;
6592 qla83xx_idc_lock(vha, 0);
6593 rval = __qla83xx_set_drv_presence(vha);
6594 qla83xx_idc_unlock(vha, 0);
6600 __qla83xx_clear_drv_presence(scsi_qla_host_t *vha)
6602 int rval = QLA_SUCCESS;
6603 struct qla_hw_data *ha = vha->hw;
6604 uint32_t drv_presence;
6606 rval = qla83xx_rd_reg(vha, QLA83XX_IDC_DRV_PRESENCE, &drv_presence);
6607 if (rval == QLA_SUCCESS) {
6608 drv_presence &= ~(1 << ha->portnum);
6609 rval = qla83xx_wr_reg(vha, QLA83XX_IDC_DRV_PRESENCE,
6617 qla83xx_clear_drv_presence(scsi_qla_host_t *vha)
6619 int rval = QLA_SUCCESS;
6621 qla83xx_idc_lock(vha, 0);
6622 rval = __qla83xx_clear_drv_presence(vha);
6623 qla83xx_idc_unlock(vha, 0);
6629 qla83xx_need_reset_handler(scsi_qla_host_t *vha)
6631 struct qla_hw_data *ha = vha->hw;
6632 uint32_t drv_ack, drv_presence;
6633 unsigned long ack_timeout;
6635 /* Wait for IDC ACK from all functions (DRV-ACK == DRV-PRESENCE) */
6636 ack_timeout = jiffies + (ha->fcoe_reset_timeout * HZ);
6638 qla83xx_rd_reg(vha, QLA83XX_IDC_DRIVER_ACK, &drv_ack);
6639 qla83xx_rd_reg(vha, QLA83XX_IDC_DRV_PRESENCE, &drv_presence);
6640 if ((drv_ack & drv_presence) == drv_presence)
6643 if (time_after_eq(jiffies, ack_timeout)) {
6644 ql_log(ql_log_warn, vha, 0xb067,
6645 "RESET ACK TIMEOUT! drv_presence=0x%x "
6646 "drv_ack=0x%x\n", drv_presence, drv_ack);
6648 * The function(s) which did not ack in time are forced
6649 * to withdraw any further participation in the IDC
6652 if (drv_ack != drv_presence)
6653 qla83xx_wr_reg(vha, QLA83XX_IDC_DRV_PRESENCE,
6658 qla83xx_idc_unlock(vha, 0);
6660 qla83xx_idc_lock(vha, 0);
6663 qla83xx_wr_reg(vha, QLA83XX_IDC_DEV_STATE, QLA8XXX_DEV_COLD);
6664 ql_log(ql_log_info, vha, 0xb068, "HW State: COLD/RE-INIT.\n");
6668 qla83xx_device_bootstrap(scsi_qla_host_t *vha)
6670 int rval = QLA_SUCCESS;
6671 uint32_t idc_control;
6673 qla83xx_wr_reg(vha, QLA83XX_IDC_DEV_STATE, QLA8XXX_DEV_INITIALIZING);
6674 ql_log(ql_log_info, vha, 0xb069, "HW State: INITIALIZING.\n");
6676 /* Clearing IDC-Control Graceful-Reset Bit before resetting f/w */
6677 __qla83xx_get_idc_control(vha, &idc_control);
6678 idc_control &= ~QLA83XX_IDC_GRACEFUL_RESET;
6679 __qla83xx_set_idc_control(vha, 0);
6681 qla83xx_idc_unlock(vha, 0);
6682 rval = qla83xx_restart_nic_firmware(vha);
6683 qla83xx_idc_lock(vha, 0);
6685 if (rval != QLA_SUCCESS) {
6686 ql_log(ql_log_fatal, vha, 0xb06a,
6687 "Failed to restart NIC f/w.\n");
6688 qla83xx_wr_reg(vha, QLA83XX_IDC_DEV_STATE, QLA8XXX_DEV_FAILED);
6689 ql_log(ql_log_info, vha, 0xb06b, "HW State: FAILED.\n");
6691 ql_dbg(ql_dbg_p3p, vha, 0xb06c,
6692 "Success in restarting nic f/w.\n");
6693 qla83xx_wr_reg(vha, QLA83XX_IDC_DEV_STATE, QLA8XXX_DEV_READY);
6694 ql_log(ql_log_info, vha, 0xb06d, "HW State: READY.\n");
6700 /* Assumes idc_lock always held on entry */
6702 qla83xx_idc_state_handler(scsi_qla_host_t *base_vha)
6704 struct qla_hw_data *ha = base_vha->hw;
6705 int rval = QLA_SUCCESS;
6706 unsigned long dev_init_timeout;
6709 /* Wait for MAX-INIT-TIMEOUT for the device to go ready */
6710 dev_init_timeout = jiffies + (ha->fcoe_dev_init_timeout * HZ);
6714 if (time_after_eq(jiffies, dev_init_timeout)) {
6715 ql_log(ql_log_warn, base_vha, 0xb06e,
6716 "Initialization TIMEOUT!\n");
6717 /* Init timeout. Disable further NIC Core
6720 qla83xx_wr_reg(base_vha, QLA83XX_IDC_DEV_STATE,
6721 QLA8XXX_DEV_FAILED);
6722 ql_log(ql_log_info, base_vha, 0xb06f,
6723 "HW State: FAILED.\n");
6726 qla83xx_rd_reg(base_vha, QLA83XX_IDC_DEV_STATE, &dev_state);
6727 switch (dev_state) {
6728 case QLA8XXX_DEV_READY:
6729 if (ha->flags.nic_core_reset_owner)
6730 qla83xx_idc_audit(base_vha,
6731 IDC_AUDIT_COMPLETION);
6732 ha->flags.nic_core_reset_owner = 0;
6733 ql_dbg(ql_dbg_p3p, base_vha, 0xb070,
6734 "Reset_owner reset by 0x%x.\n",
6737 case QLA8XXX_DEV_COLD:
6738 if (ha->flags.nic_core_reset_owner)
6739 rval = qla83xx_device_bootstrap(base_vha);
6741 /* Wait for AEN to change device-state */
6742 qla83xx_idc_unlock(base_vha, 0);
6744 qla83xx_idc_lock(base_vha, 0);
6747 case QLA8XXX_DEV_INITIALIZING:
6748 /* Wait for AEN to change device-state */
6749 qla83xx_idc_unlock(base_vha, 0);
6751 qla83xx_idc_lock(base_vha, 0);
6753 case QLA8XXX_DEV_NEED_RESET:
6754 if (!ql2xdontresethba && ha->flags.nic_core_reset_owner)
6755 qla83xx_need_reset_handler(base_vha);
6757 /* Wait for AEN to change device-state */
6758 qla83xx_idc_unlock(base_vha, 0);
6760 qla83xx_idc_lock(base_vha, 0);
6762 /* reset timeout value after need reset handler */
6763 dev_init_timeout = jiffies +
6764 (ha->fcoe_dev_init_timeout * HZ);
6766 case QLA8XXX_DEV_NEED_QUIESCENT:
6767 /* XXX: DEBUG for now */
6768 qla83xx_idc_unlock(base_vha, 0);
6770 qla83xx_idc_lock(base_vha, 0);
6772 case QLA8XXX_DEV_QUIESCENT:
6773 /* XXX: DEBUG for now */
6774 if (ha->flags.quiesce_owner)
6777 qla83xx_idc_unlock(base_vha, 0);
6779 qla83xx_idc_lock(base_vha, 0);
6780 dev_init_timeout = jiffies +
6781 (ha->fcoe_dev_init_timeout * HZ);
6783 case QLA8XXX_DEV_FAILED:
6784 if (ha->flags.nic_core_reset_owner)
6785 qla83xx_idc_audit(base_vha,
6786 IDC_AUDIT_COMPLETION);
6787 ha->flags.nic_core_reset_owner = 0;
6788 __qla83xx_clear_drv_presence(base_vha);
6789 qla83xx_idc_unlock(base_vha, 0);
6790 qla8xxx_dev_failed_handler(base_vha);
6791 rval = QLA_FUNCTION_FAILED;
6792 qla83xx_idc_lock(base_vha, 0);
6794 case QLA8XXX_BAD_VALUE:
6795 qla83xx_idc_unlock(base_vha, 0);
6797 qla83xx_idc_lock(base_vha, 0);
6800 ql_log(ql_log_warn, base_vha, 0xb071,
6801 "Unknown Device State: %x.\n", dev_state);
6802 qla83xx_idc_unlock(base_vha, 0);
6803 qla8xxx_dev_failed_handler(base_vha);
6804 rval = QLA_FUNCTION_FAILED;
6805 qla83xx_idc_lock(base_vha, 0);
6815 qla2x00_disable_board_on_pci_error(struct work_struct *work)
6817 struct qla_hw_data *ha = container_of(work, struct qla_hw_data,
6819 struct pci_dev *pdev = ha->pdev;
6820 scsi_qla_host_t *base_vha = pci_get_drvdata(ha->pdev);
6822 ql_log(ql_log_warn, base_vha, 0x015b,
6823 "Disabling adapter.\n");
6825 if (!atomic_read(&pdev->enable_cnt)) {
6826 ql_log(ql_log_info, base_vha, 0xfffc,
6827 "PCI device disabled, no action req for PCI error=%lx\n",
6828 base_vha->pci_flags);
6833 * if UNLOADING flag is already set, then continue unload,
6834 * where it was set first.
6836 if (test_and_set_bit(UNLOADING, &base_vha->dpc_flags))
6839 qla2x00_wait_for_sess_deletion(base_vha);
6841 qla2x00_delete_all_vps(ha, base_vha);
6843 qla2x00_abort_all_cmds(base_vha, DID_NO_CONNECT << 16);
6845 qla2x00_dfs_remove(base_vha);
6847 qla84xx_put_chip(base_vha);
6849 if (base_vha->timer_active)
6850 qla2x00_stop_timer(base_vha);
6852 base_vha->flags.online = 0;
6854 qla2x00_destroy_deferred_work(ha);
6857 * Do not try to stop beacon blink as it will issue a mailbox
6860 qla2x00_free_sysfs_attr(base_vha, false);
6862 fc_remove_host(base_vha->host);
6864 scsi_remove_host(base_vha->host);
6866 base_vha->flags.init_done = 0;
6867 qla25xx_delete_queues(base_vha);
6868 qla2x00_free_fcports(base_vha);
6869 qla2x00_free_irqs(base_vha);
6870 qla2x00_mem_free(ha);
6871 qla82xx_md_free(base_vha);
6872 qla2x00_free_queues(ha);
6874 qla2x00_unmap_iobases(ha);
6876 pci_release_selected_regions(ha->pdev, ha->bars);
6877 pci_disable_device(pdev);
6880 * Let qla2x00_remove_one cleanup qla_hw_data on device removal.
6884 /**************************************************************************
6886 * This kernel thread is a task that is schedule by the interrupt handler
6887 * to perform the background processing for interrupts.
6890 * This task always run in the context of a kernel thread. It
6891 * is kick-off by the driver's detect code and starts up
6892 * up one per adapter. It immediately goes to sleep and waits for
6893 * some fibre event. When either the interrupt handler or
6894 * the timer routine detects a event it will one of the task
6895 * bits then wake us up.
6896 **************************************************************************/
6898 qla2x00_do_dpc(void *data)
6900 scsi_qla_host_t *base_vha;
6901 struct qla_hw_data *ha;
6903 struct qla_qpair *qpair;
6905 ha = (struct qla_hw_data *)data;
6906 base_vha = pci_get_drvdata(ha->pdev);
6908 set_user_nice(current, MIN_NICE);
6910 set_current_state(TASK_INTERRUPTIBLE);
6911 while (!kthread_should_stop()) {
6912 ql_dbg(ql_dbg_dpc, base_vha, 0x4000,
6913 "DPC handler sleeping.\n");
6917 if (test_and_clear_bit(DO_EEH_RECOVERY, &base_vha->dpc_flags))
6918 qla_pci_set_eeh_busy(base_vha);
6920 if (!base_vha->flags.init_done || ha->flags.mbox_busy)
6923 if (ha->flags.eeh_busy) {
6924 ql_dbg(ql_dbg_dpc, base_vha, 0x4003,
6925 "eeh_busy=%d.\n", ha->flags.eeh_busy);
6931 ql_dbg(ql_dbg_dpc + ql_dbg_verbose, base_vha, 0x4001,
6932 "DPC handler waking up, dpc_flags=0x%lx.\n",
6933 base_vha->dpc_flags);
6935 if (test_bit(UNLOADING, &base_vha->dpc_flags))
6938 if (IS_P3P_TYPE(ha)) {
6939 if (IS_QLA8044(ha)) {
6940 if (test_and_clear_bit(ISP_UNRECOVERABLE,
6941 &base_vha->dpc_flags)) {
6942 qla8044_idc_lock(ha);
6943 qla8044_wr_direct(base_vha,
6944 QLA8044_CRB_DEV_STATE_INDEX,
6945 QLA8XXX_DEV_FAILED);
6946 qla8044_idc_unlock(ha);
6947 ql_log(ql_log_info, base_vha, 0x4004,
6948 "HW State: FAILED.\n");
6949 qla8044_device_state_handler(base_vha);
6954 if (test_and_clear_bit(ISP_UNRECOVERABLE,
6955 &base_vha->dpc_flags)) {
6956 qla82xx_idc_lock(ha);
6957 qla82xx_wr_32(ha, QLA82XX_CRB_DEV_STATE,
6958 QLA8XXX_DEV_FAILED);
6959 qla82xx_idc_unlock(ha);
6960 ql_log(ql_log_info, base_vha, 0x0151,
6961 "HW State: FAILED.\n");
6962 qla82xx_device_state_handler(base_vha);
6967 if (test_and_clear_bit(FCOE_CTX_RESET_NEEDED,
6968 &base_vha->dpc_flags)) {
6970 ql_dbg(ql_dbg_dpc, base_vha, 0x4005,
6971 "FCoE context reset scheduled.\n");
6972 if (!(test_and_set_bit(ABORT_ISP_ACTIVE,
6973 &base_vha->dpc_flags))) {
6974 if (qla82xx_fcoe_ctx_reset(base_vha)) {
6975 /* FCoE-ctx reset failed.
6976 * Escalate to chip-reset
6978 set_bit(ISP_ABORT_NEEDED,
6979 &base_vha->dpc_flags);
6981 clear_bit(ABORT_ISP_ACTIVE,
6982 &base_vha->dpc_flags);
6985 ql_dbg(ql_dbg_dpc, base_vha, 0x4006,
6986 "FCoE context reset end.\n");
6988 } else if (IS_QLAFX00(ha)) {
6989 if (test_and_clear_bit(ISP_UNRECOVERABLE,
6990 &base_vha->dpc_flags)) {
6991 ql_dbg(ql_dbg_dpc, base_vha, 0x4020,
6992 "Firmware Reset Recovery\n");
6993 if (qlafx00_reset_initialize(base_vha)) {
6994 /* Failed. Abort isp later. */
6995 if (!test_bit(UNLOADING,
6996 &base_vha->dpc_flags)) {
6997 set_bit(ISP_UNRECOVERABLE,
6998 &base_vha->dpc_flags);
6999 ql_dbg(ql_dbg_dpc, base_vha,
7001 "Reset Recovery Failed\n");
7006 if (test_and_clear_bit(FX00_TARGET_SCAN,
7007 &base_vha->dpc_flags)) {
7008 ql_dbg(ql_dbg_dpc, base_vha, 0x4022,
7009 "ISPFx00 Target Scan scheduled\n");
7010 if (qlafx00_rescan_isp(base_vha)) {
7011 if (!test_bit(UNLOADING,
7012 &base_vha->dpc_flags))
7013 set_bit(ISP_UNRECOVERABLE,
7014 &base_vha->dpc_flags);
7015 ql_dbg(ql_dbg_dpc, base_vha, 0x401e,
7016 "ISPFx00 Target Scan Failed\n");
7018 ql_dbg(ql_dbg_dpc, base_vha, 0x401f,
7019 "ISPFx00 Target Scan End\n");
7021 if (test_and_clear_bit(FX00_HOST_INFO_RESEND,
7022 &base_vha->dpc_flags)) {
7023 ql_dbg(ql_dbg_dpc, base_vha, 0x4023,
7024 "ISPFx00 Host Info resend scheduled\n");
7025 qlafx00_fx_disc(base_vha,
7026 &base_vha->hw->mr.fcport,
7027 FXDISC_REG_HOST_INFO);
7031 if (test_and_clear_bit(DETECT_SFP_CHANGE,
7032 &base_vha->dpc_flags)) {
7034 * - NO-OP -- await next ISP-ABORT. Preferred method
7035 * to minimize disruptions that will occur
7036 * when a forced chip-reset occurs.
7037 * - Force -- ISP-ABORT scheduled.
7039 /* set_bit(ISP_ABORT_NEEDED, &base_vha->dpc_flags); */
7042 if (test_and_clear_bit
7043 (ISP_ABORT_NEEDED, &base_vha->dpc_flags) &&
7044 !test_bit(UNLOADING, &base_vha->dpc_flags)) {
7045 bool do_reset = true;
7047 switch (base_vha->qlini_mode) {
7048 case QLA2XXX_INI_MODE_ENABLED:
7050 case QLA2XXX_INI_MODE_DISABLED:
7051 if (!qla_tgt_mode_enabled(base_vha) &&
7052 !ha->flags.fw_started)
7055 case QLA2XXX_INI_MODE_DUAL:
7056 if (!qla_dual_mode_enabled(base_vha) &&
7057 !ha->flags.fw_started)
7064 if (do_reset && !(test_and_set_bit(ABORT_ISP_ACTIVE,
7065 &base_vha->dpc_flags))) {
7066 base_vha->flags.online = 1;
7067 ql_dbg(ql_dbg_dpc, base_vha, 0x4007,
7068 "ISP abort scheduled.\n");
7069 if (ha->isp_ops->abort_isp(base_vha)) {
7070 /* failed. retry later */
7071 set_bit(ISP_ABORT_NEEDED,
7072 &base_vha->dpc_flags);
7074 clear_bit(ABORT_ISP_ACTIVE,
7075 &base_vha->dpc_flags);
7076 ql_dbg(ql_dbg_dpc, base_vha, 0x4008,
7077 "ISP abort end.\n");
7081 if (test_bit(PROCESS_PUREX_IOCB, &base_vha->dpc_flags)) {
7082 if (atomic_read(&base_vha->loop_state) == LOOP_READY) {
7083 qla24xx_process_purex_list
7084 (&base_vha->purex_list);
7085 clear_bit(PROCESS_PUREX_IOCB,
7086 &base_vha->dpc_flags);
7091 goto loop_resync_check;
7093 if (test_bit(ISP_QUIESCE_NEEDED, &base_vha->dpc_flags)) {
7094 ql_dbg(ql_dbg_dpc, base_vha, 0x4009,
7095 "Quiescence mode scheduled.\n");
7096 if (IS_P3P_TYPE(ha)) {
7098 qla82xx_device_state_handler(base_vha);
7100 qla8044_device_state_handler(base_vha);
7101 clear_bit(ISP_QUIESCE_NEEDED,
7102 &base_vha->dpc_flags);
7103 if (!ha->flags.quiesce_owner) {
7104 qla2x00_perform_loop_resync(base_vha);
7105 if (IS_QLA82XX(ha)) {
7106 qla82xx_idc_lock(ha);
7107 qla82xx_clear_qsnt_ready(
7109 qla82xx_idc_unlock(ha);
7110 } else if (IS_QLA8044(ha)) {
7111 qla8044_idc_lock(ha);
7112 qla8044_clear_qsnt_ready(
7114 qla8044_idc_unlock(ha);
7118 clear_bit(ISP_QUIESCE_NEEDED,
7119 &base_vha->dpc_flags);
7120 qla2x00_quiesce_io(base_vha);
7122 ql_dbg(ql_dbg_dpc, base_vha, 0x400a,
7123 "Quiescence mode end.\n");
7126 if (test_and_clear_bit(RESET_MARKER_NEEDED,
7127 &base_vha->dpc_flags) &&
7128 (!(test_and_set_bit(RESET_ACTIVE, &base_vha->dpc_flags)))) {
7130 ql_dbg(ql_dbg_dpc, base_vha, 0x400b,
7131 "Reset marker scheduled.\n");
7132 qla2x00_rst_aen(base_vha);
7133 clear_bit(RESET_ACTIVE, &base_vha->dpc_flags);
7134 ql_dbg(ql_dbg_dpc, base_vha, 0x400c,
7135 "Reset marker end.\n");
7138 /* Retry each device up to login retry count */
7139 if (test_bit(RELOGIN_NEEDED, &base_vha->dpc_flags) &&
7140 !test_bit(LOOP_RESYNC_NEEDED, &base_vha->dpc_flags) &&
7141 atomic_read(&base_vha->loop_state) != LOOP_DOWN) {
7143 if (!base_vha->relogin_jif ||
7144 time_after_eq(jiffies, base_vha->relogin_jif)) {
7145 base_vha->relogin_jif = jiffies + HZ;
7146 clear_bit(RELOGIN_NEEDED, &base_vha->dpc_flags);
7148 ql_dbg(ql_dbg_disc, base_vha, 0x400d,
7149 "Relogin scheduled.\n");
7150 qla24xx_post_relogin_work(base_vha);
7154 if (!qla2x00_reset_active(base_vha) &&
7155 test_and_clear_bit(LOOP_RESYNC_NEEDED,
7156 &base_vha->dpc_flags)) {
7158 * Allow abort_isp to complete before moving on to scanning.
7160 ql_dbg(ql_dbg_dpc, base_vha, 0x400f,
7161 "Loop resync scheduled.\n");
7163 if (!(test_and_set_bit(LOOP_RESYNC_ACTIVE,
7164 &base_vha->dpc_flags))) {
7166 qla2x00_loop_resync(base_vha);
7168 clear_bit(LOOP_RESYNC_ACTIVE,
7169 &base_vha->dpc_flags);
7172 ql_dbg(ql_dbg_dpc, base_vha, 0x4010,
7173 "Loop resync end.\n");
7179 if (test_bit(NPIV_CONFIG_NEEDED, &base_vha->dpc_flags) &&
7180 atomic_read(&base_vha->loop_state) == LOOP_READY) {
7181 clear_bit(NPIV_CONFIG_NEEDED, &base_vha->dpc_flags);
7182 qla2xxx_flash_npiv_conf(base_vha);
7186 if (!ha->interrupts_on)
7187 ha->isp_ops->enable_intrs(ha);
7189 if (test_and_clear_bit(BEACON_BLINK_NEEDED,
7190 &base_vha->dpc_flags)) {
7191 if (ha->beacon_blink_led == 1)
7192 ha->isp_ops->beacon_blink(base_vha);
7195 /* qpair online check */
7196 if (test_and_clear_bit(QPAIR_ONLINE_CHECK_NEEDED,
7197 &base_vha->dpc_flags)) {
7198 if (ha->flags.eeh_busy ||
7199 ha->flags.pci_channel_io_perm_failure)
7204 mutex_lock(&ha->mq_lock);
7205 list_for_each_entry(qpair, &base_vha->qp_list,
7207 qpair->online = online;
7208 mutex_unlock(&ha->mq_lock);
7211 if (test_and_clear_bit(SET_ZIO_THRESHOLD_NEEDED,
7212 &base_vha->dpc_flags)) {
7213 u16 threshold = ha->nvme_last_rptd_aen + ha->last_zio_threshold;
7215 if (threshold > ha->orig_fw_xcb_count)
7216 threshold = ha->orig_fw_xcb_count;
7218 ql_log(ql_log_info, base_vha, 0xffffff,
7219 "SET ZIO Activity exchange threshold to %d.\n",
7221 if (qla27xx_set_zio_threshold(base_vha, threshold)) {
7222 ql_log(ql_log_info, base_vha, 0xffffff,
7223 "Unable to SET ZIO Activity exchange threshold to %d.\n",
7228 if (!IS_QLAFX00(ha))
7229 qla2x00_do_dpc_all_vps(base_vha);
7231 if (test_and_clear_bit(N2N_LINK_RESET,
7232 &base_vha->dpc_flags)) {
7233 qla2x00_lip_reset(base_vha);
7238 set_current_state(TASK_INTERRUPTIBLE);
7239 } /* End of while(1) */
7240 __set_current_state(TASK_RUNNING);
7242 ql_dbg(ql_dbg_dpc, base_vha, 0x4011,
7243 "DPC handler exiting.\n");
7246 * Make sure that nobody tries to wake us up again.
7250 /* Cleanup any residual CTX SRBs. */
7251 qla2x00_abort_all_cmds(base_vha, DID_NO_CONNECT << 16);
7257 qla2xxx_wake_dpc(struct scsi_qla_host *vha)
7259 struct qla_hw_data *ha = vha->hw;
7260 struct task_struct *t = ha->dpc_thread;
7262 if (!test_bit(UNLOADING, &vha->dpc_flags) && t)
7268 * Processes asynchronous reset.
7271 * ha = adapter block pointer.
7274 qla2x00_rst_aen(scsi_qla_host_t *vha)
7276 if (vha->flags.online && !vha->flags.reset_active &&
7277 !atomic_read(&vha->loop_down_timer) &&
7278 !(test_bit(ABORT_ISP_ACTIVE, &vha->dpc_flags))) {
7280 clear_bit(RESET_MARKER_NEEDED, &vha->dpc_flags);
7283 * Issue marker command only when we are going to start
7286 vha->marker_needed = 1;
7287 } while (!atomic_read(&vha->loop_down_timer) &&
7288 (test_bit(RESET_MARKER_NEEDED, &vha->dpc_flags)));
7292 static bool qla_do_heartbeat(struct scsi_qla_host *vha)
7294 struct qla_hw_data *ha = vha->hw;
7297 bool do_heartbeat = false;
7300 * Allow do_heartbeat only if we don’t have any active interrupts,
7301 * but there are still IOs outstanding with firmware.
7303 cmpl_cnt = ha->base_qpair->cmd_completion_cnt;
7304 if (cmpl_cnt == ha->base_qpair->prev_completion_cnt &&
7305 cmpl_cnt != ha->base_qpair->cmd_cnt) {
7306 do_heartbeat = true;
7309 ha->base_qpair->prev_completion_cnt = cmpl_cnt;
7311 for (i = 0; i < ha->max_qpairs; i++) {
7312 if (ha->queue_pair_map[i]) {
7313 cmpl_cnt = ha->queue_pair_map[i]->cmd_completion_cnt;
7314 if (cmpl_cnt == ha->queue_pair_map[i]->prev_completion_cnt &&
7315 cmpl_cnt != ha->queue_pair_map[i]->cmd_cnt) {
7316 do_heartbeat = true;
7319 ha->queue_pair_map[i]->prev_completion_cnt = cmpl_cnt;
7324 return do_heartbeat;
7327 static void qla_heart_beat(struct scsi_qla_host *vha, u16 dpc_started)
7329 struct qla_hw_data *ha = vha->hw;
7334 if (vha->hw->flags.eeh_busy || qla2x00_chip_is_down(vha))
7338 * dpc thread cannot run if heartbeat is running at the same time.
7339 * We also do not want to starve heartbeat task. Therefore, do
7340 * heartbeat task at least once every 5 seconds.
7343 time_before(jiffies, ha->last_heartbeat_run_jiffies + 5 * HZ))
7346 if (qla_do_heartbeat(vha)) {
7347 ha->last_heartbeat_run_jiffies = jiffies;
7348 queue_work(ha->wq, &ha->heartbeat_work);
7352 static void qla_wind_down_chip(scsi_qla_host_t *vha)
7354 struct qla_hw_data *ha = vha->hw;
7356 if (!ha->flags.eeh_busy)
7358 if (ha->pci_error_state)
7359 /* system is trying to recover */
7363 * Current system is not handling PCIE error. At this point, this is
7364 * best effort to wind down the adapter.
7366 if (time_after_eq(jiffies, ha->eeh_jif + ql2xdelay_before_pci_error_handling * HZ) &&
7367 !ha->flags.eeh_flush) {
7368 ql_log(ql_log_info, vha, 0x9009,
7369 "PCI Error detected, attempting to reset hardware.\n");
7371 ha->isp_ops->reset_chip(vha);
7372 ha->isp_ops->disable_intrs(ha);
7374 ha->flags.eeh_flush = EEH_FLUSH_RDY;
7375 ha->eeh_jif = jiffies;
7377 } else if (ha->flags.eeh_flush == EEH_FLUSH_RDY &&
7378 time_after_eq(jiffies, ha->eeh_jif + 5 * HZ)) {
7379 pci_clear_master(ha->pdev);
7381 /* flush all command */
7382 qla2x00_abort_isp_cleanup(vha);
7383 ha->flags.eeh_flush = EEH_FLUSH_DONE;
7385 ql_log(ql_log_info, vha, 0x900a,
7386 "PCI Error handling complete, all IOs aborted.\n");
7390 /**************************************************************************
7396 * Context: Interrupt
7397 ***************************************************************************/
7399 qla2x00_timer(struct timer_list *t)
7401 scsi_qla_host_t *vha = from_timer(vha, t, timer);
7402 unsigned long cpu_flags = 0;
7407 struct qla_hw_data *ha = vha->hw;
7408 struct req_que *req;
7409 unsigned long flags;
7410 fc_port_t *fcport = NULL;
7412 if (ha->flags.eeh_busy) {
7413 qla_wind_down_chip(vha);
7415 ql_dbg(ql_dbg_timer, vha, 0x6000,
7416 "EEH = %d, restarting timer.\n",
7417 ha->flags.eeh_busy);
7418 qla2x00_restart_timer(vha, WATCH_INTERVAL);
7423 * Hardware read to raise pending EEH errors during mailbox waits. If
7424 * the read returns -1 then disable the board.
7426 if (!pci_channel_offline(ha->pdev)) {
7427 pci_read_config_word(ha->pdev, PCI_VENDOR_ID, &w);
7428 qla2x00_check_reg16_for_disconnect(vha, w);
7431 /* Make sure qla82xx_watchdog is run only for physical port */
7432 if (!vha->vp_idx && IS_P3P_TYPE(ha)) {
7433 if (test_bit(ISP_QUIESCE_NEEDED, &vha->dpc_flags))
7436 qla82xx_watchdog(vha);
7437 else if (IS_QLA8044(ha))
7438 qla8044_watchdog(vha);
7441 if (!vha->vp_idx && IS_QLAFX00(ha))
7442 qlafx00_timer_routine(vha);
7444 if (vha->link_down_time < QLA2XX_MAX_LINK_DOWN_TIME)
7445 vha->link_down_time++;
7447 spin_lock_irqsave(&vha->hw->tgt.sess_lock, flags);
7448 list_for_each_entry(fcport, &vha->vp_fcports, list) {
7449 if (fcport->tgt_link_down_time < QLA2XX_MAX_LINK_DOWN_TIME)
7450 fcport->tgt_link_down_time++;
7452 spin_unlock_irqrestore(&vha->hw->tgt.sess_lock, flags);
7454 /* Loop down handler. */
7455 if (atomic_read(&vha->loop_down_timer) > 0 &&
7456 !(test_bit(ABORT_ISP_ACTIVE, &vha->dpc_flags)) &&
7457 !(test_bit(FCOE_CTX_RESET_NEEDED, &vha->dpc_flags))
7458 && vha->flags.online) {
7460 if (atomic_read(&vha->loop_down_timer) ==
7461 vha->loop_down_abort_time) {
7463 ql_log(ql_log_info, vha, 0x6008,
7464 "Loop down - aborting the queues before time expires.\n");
7466 if (!IS_QLA2100(ha) && vha->link_down_timeout)
7467 atomic_set(&vha->loop_state, LOOP_DEAD);
7470 * Schedule an ISP abort to return any FCP2-device
7473 /* NPIV - scan physical port only */
7475 spin_lock_irqsave(&ha->hardware_lock,
7477 req = ha->req_q_map[0];
7479 index < req->num_outstanding_cmds;
7483 sp = req->outstanding_cmds[index];
7486 if (sp->cmd_type != TYPE_SRB)
7488 if (sp->type != SRB_SCSI_CMD)
7491 if (!(sfcp->flags & FCF_FCP2_DEVICE))
7495 set_bit(FCOE_CTX_RESET_NEEDED,
7498 set_bit(ISP_ABORT_NEEDED,
7502 spin_unlock_irqrestore(&ha->hardware_lock,
7508 /* if the loop has been down for 4 minutes, reinit adapter */
7509 if (atomic_dec_and_test(&vha->loop_down_timer) != 0) {
7510 if (!(vha->device_flags & DFLG_NO_CABLE) && !vha->vp_idx) {
7511 ql_log(ql_log_warn, vha, 0x6009,
7512 "Loop down - aborting ISP.\n");
7515 set_bit(FCOE_CTX_RESET_NEEDED,
7518 set_bit(ISP_ABORT_NEEDED,
7522 ql_dbg(ql_dbg_timer, vha, 0x600a,
7523 "Loop down - seconds remaining %d.\n",
7524 atomic_read(&vha->loop_down_timer));
7526 /* Check if beacon LED needs to be blinked for physical host only */
7527 if (!vha->vp_idx && (ha->beacon_blink_led == 1)) {
7528 /* There is no beacon_blink function for ISP82xx */
7529 if (!IS_P3P_TYPE(ha)) {
7530 set_bit(BEACON_BLINK_NEEDED, &vha->dpc_flags);
7535 /* check if edif running */
7536 if (vha->hw->flags.edif_enabled)
7537 qla_edif_timer(vha);
7539 /* Process any deferred work. */
7540 if (!list_empty(&vha->work_list)) {
7541 unsigned long flags;
7544 spin_lock_irqsave(&vha->work_lock, flags);
7545 if (!test_and_set_bit(IOCB_WORK_ACTIVE, &vha->dpc_flags))
7547 spin_unlock_irqrestore(&vha->work_lock, flags);
7549 queue_work(vha->hw->wq, &vha->iocb_work);
7554 * see if the active AEN count has changed from what was last reported.
7556 index = atomic_read(&ha->nvme_active_aen_cnt);
7558 (index != ha->nvme_last_rptd_aen) &&
7559 ha->zio_mode == QLA_ZIO_MODE_6 &&
7560 !ha->flags.host_shutting_down) {
7561 ha->nvme_last_rptd_aen = atomic_read(&ha->nvme_active_aen_cnt);
7562 ql_log(ql_log_info, vha, 0x3002,
7563 "nvme: Sched: Set ZIO exchange threshold to %d.\n",
7564 ha->nvme_last_rptd_aen);
7565 set_bit(SET_ZIO_THRESHOLD_NEEDED, &vha->dpc_flags);
7570 atomic_read(&ha->zio_threshold) != ha->last_zio_threshold &&
7571 IS_ZIO_THRESHOLD_CAPABLE(ha)) {
7572 ql_log(ql_log_info, vha, 0x3002,
7573 "Sched: Set ZIO exchange threshold to %d.\n",
7574 ha->last_zio_threshold);
7575 ha->last_zio_threshold = atomic_read(&ha->zio_threshold);
7576 set_bit(SET_ZIO_THRESHOLD_NEEDED, &vha->dpc_flags);
7579 qla_adjust_buf(vha);
7581 /* borrowing w to signify dpc will run */
7583 /* Schedule the DPC routine if needed */
7584 if ((test_bit(ISP_ABORT_NEEDED, &vha->dpc_flags) ||
7585 test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags) ||
7587 test_bit(RESET_MARKER_NEEDED, &vha->dpc_flags) ||
7588 test_bit(BEACON_BLINK_NEEDED, &vha->dpc_flags) ||
7589 test_bit(ISP_UNRECOVERABLE, &vha->dpc_flags) ||
7590 test_bit(FCOE_CTX_RESET_NEEDED, &vha->dpc_flags) ||
7591 test_bit(VP_DPC_NEEDED, &vha->dpc_flags) ||
7592 test_bit(RELOGIN_NEEDED, &vha->dpc_flags) ||
7593 test_bit(PROCESS_PUREX_IOCB, &vha->dpc_flags))) {
7594 ql_dbg(ql_dbg_timer, vha, 0x600b,
7595 "isp_abort_needed=%d loop_resync_needed=%d "
7596 "start_dpc=%d reset_marker_needed=%d",
7597 test_bit(ISP_ABORT_NEEDED, &vha->dpc_flags),
7598 test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags),
7599 start_dpc, test_bit(RESET_MARKER_NEEDED, &vha->dpc_flags));
7600 ql_dbg(ql_dbg_timer, vha, 0x600c,
7601 "beacon_blink_needed=%d isp_unrecoverable=%d "
7602 "fcoe_ctx_reset_needed=%d vp_dpc_needed=%d "
7603 "relogin_needed=%d, Process_purex_iocb=%d.\n",
7604 test_bit(BEACON_BLINK_NEEDED, &vha->dpc_flags),
7605 test_bit(ISP_UNRECOVERABLE, &vha->dpc_flags),
7606 test_bit(FCOE_CTX_RESET_NEEDED, &vha->dpc_flags),
7607 test_bit(VP_DPC_NEEDED, &vha->dpc_flags),
7608 test_bit(RELOGIN_NEEDED, &vha->dpc_flags),
7609 test_bit(PROCESS_PUREX_IOCB, &vha->dpc_flags));
7610 qla2xxx_wake_dpc(vha);
7614 qla_heart_beat(vha, w);
7616 qla2x00_restart_timer(vha, WATCH_INTERVAL);
7619 /* Firmware interface routines. */
7621 #define FW_ISP21XX 0
7622 #define FW_ISP22XX 1
7623 #define FW_ISP2300 2
7624 #define FW_ISP2322 3
7625 #define FW_ISP24XX 4
7626 #define FW_ISP25XX 5
7627 #define FW_ISP81XX 6
7628 #define FW_ISP82XX 7
7629 #define FW_ISP2031 8
7630 #define FW_ISP8031 9
7631 #define FW_ISP27XX 10
7632 #define FW_ISP28XX 11
7634 #define FW_FILE_ISP21XX "ql2100_fw.bin"
7635 #define FW_FILE_ISP22XX "ql2200_fw.bin"
7636 #define FW_FILE_ISP2300 "ql2300_fw.bin"
7637 #define FW_FILE_ISP2322 "ql2322_fw.bin"
7638 #define FW_FILE_ISP24XX "ql2400_fw.bin"
7639 #define FW_FILE_ISP25XX "ql2500_fw.bin"
7640 #define FW_FILE_ISP81XX "ql8100_fw.bin"
7641 #define FW_FILE_ISP82XX "ql8200_fw.bin"
7642 #define FW_FILE_ISP2031 "ql2600_fw.bin"
7643 #define FW_FILE_ISP8031 "ql8300_fw.bin"
7644 #define FW_FILE_ISP27XX "ql2700_fw.bin"
7645 #define FW_FILE_ISP28XX "ql2800_fw.bin"
7648 static DEFINE_MUTEX(qla_fw_lock);
7650 static struct fw_blob qla_fw_blobs[] = {
7651 { .name = FW_FILE_ISP21XX, .segs = { 0x1000, 0 }, },
7652 { .name = FW_FILE_ISP22XX, .segs = { 0x1000, 0 }, },
7653 { .name = FW_FILE_ISP2300, .segs = { 0x800, 0 }, },
7654 { .name = FW_FILE_ISP2322, .segs = { 0x800, 0x1c000, 0x1e000, 0 }, },
7655 { .name = FW_FILE_ISP24XX, },
7656 { .name = FW_FILE_ISP25XX, },
7657 { .name = FW_FILE_ISP81XX, },
7658 { .name = FW_FILE_ISP82XX, },
7659 { .name = FW_FILE_ISP2031, },
7660 { .name = FW_FILE_ISP8031, },
7661 { .name = FW_FILE_ISP27XX, },
7662 { .name = FW_FILE_ISP28XX, },
7667 qla2x00_request_firmware(scsi_qla_host_t *vha)
7669 struct qla_hw_data *ha = vha->hw;
7670 struct fw_blob *blob;
7672 if (IS_QLA2100(ha)) {
7673 blob = &qla_fw_blobs[FW_ISP21XX];
7674 } else if (IS_QLA2200(ha)) {
7675 blob = &qla_fw_blobs[FW_ISP22XX];
7676 } else if (IS_QLA2300(ha) || IS_QLA2312(ha) || IS_QLA6312(ha)) {
7677 blob = &qla_fw_blobs[FW_ISP2300];
7678 } else if (IS_QLA2322(ha) || IS_QLA6322(ha)) {
7679 blob = &qla_fw_blobs[FW_ISP2322];
7680 } else if (IS_QLA24XX_TYPE(ha)) {
7681 blob = &qla_fw_blobs[FW_ISP24XX];
7682 } else if (IS_QLA25XX(ha)) {
7683 blob = &qla_fw_blobs[FW_ISP25XX];
7684 } else if (IS_QLA81XX(ha)) {
7685 blob = &qla_fw_blobs[FW_ISP81XX];
7686 } else if (IS_QLA82XX(ha)) {
7687 blob = &qla_fw_blobs[FW_ISP82XX];
7688 } else if (IS_QLA2031(ha)) {
7689 blob = &qla_fw_blobs[FW_ISP2031];
7690 } else if (IS_QLA8031(ha)) {
7691 blob = &qla_fw_blobs[FW_ISP8031];
7692 } else if (IS_QLA27XX(ha)) {
7693 blob = &qla_fw_blobs[FW_ISP27XX];
7694 } else if (IS_QLA28XX(ha)) {
7695 blob = &qla_fw_blobs[FW_ISP28XX];
7703 mutex_lock(&qla_fw_lock);
7707 if (request_firmware(&blob->fw, blob->name, &ha->pdev->dev)) {
7708 ql_log(ql_log_warn, vha, 0x0063,
7709 "Failed to load firmware image (%s).\n", blob->name);
7715 mutex_unlock(&qla_fw_lock);
7720 qla2x00_release_firmware(void)
7722 struct fw_blob *blob;
7724 mutex_lock(&qla_fw_lock);
7725 for (blob = qla_fw_blobs; blob->name; blob++)
7726 release_firmware(blob->fw);
7727 mutex_unlock(&qla_fw_lock);
7730 static void qla_pci_error_cleanup(scsi_qla_host_t *vha)
7732 struct qla_hw_data *ha = vha->hw;
7733 scsi_qla_host_t *base_vha = pci_get_drvdata(ha->pdev);
7734 struct qla_qpair *qpair = NULL;
7735 struct scsi_qla_host *vp, *tvp;
7738 unsigned long flags;
7740 ql_dbg(ql_dbg_aer, vha, 0x9000,
7744 ha->base_qpair->chip_reset = ha->chip_reset;
7745 for (i = 0; i < ha->max_qpairs; i++) {
7746 if (ha->queue_pair_map[i])
7747 ha->queue_pair_map[i]->chip_reset =
7748 ha->base_qpair->chip_reset;
7752 * purge mailbox might take a while. Slot Reset/chip reset
7753 * will take care of the purge
7756 mutex_lock(&ha->mq_lock);
7757 ha->base_qpair->online = 0;
7758 list_for_each_entry(qpair, &base_vha->qp_list, qp_list_elem)
7761 mutex_unlock(&ha->mq_lock);
7763 qla2x00_mark_all_devices_lost(vha);
7765 spin_lock_irqsave(&ha->vport_slock, flags);
7766 list_for_each_entry_safe(vp, tvp, &ha->vp_list, list) {
7767 atomic_inc(&vp->vref_count);
7768 spin_unlock_irqrestore(&ha->vport_slock, flags);
7769 qla2x00_mark_all_devices_lost(vp);
7770 spin_lock_irqsave(&ha->vport_slock, flags);
7771 atomic_dec(&vp->vref_count);
7773 spin_unlock_irqrestore(&ha->vport_slock, flags);
7775 /* Clear all async request states across all VPs. */
7776 list_for_each_entry(fcport, &vha->vp_fcports, list)
7777 fcport->flags &= ~(FCF_LOGIN_NEEDED | FCF_ASYNC_SENT);
7779 spin_lock_irqsave(&ha->vport_slock, flags);
7780 list_for_each_entry_safe(vp, tvp, &ha->vp_list, list) {
7781 atomic_inc(&vp->vref_count);
7782 spin_unlock_irqrestore(&ha->vport_slock, flags);
7783 list_for_each_entry(fcport, &vp->vp_fcports, list)
7784 fcport->flags &= ~(FCF_LOGIN_NEEDED | FCF_ASYNC_SENT);
7785 spin_lock_irqsave(&ha->vport_slock, flags);
7786 atomic_dec(&vp->vref_count);
7788 spin_unlock_irqrestore(&ha->vport_slock, flags);
7792 static pci_ers_result_t
7793 qla2xxx_pci_error_detected(struct pci_dev *pdev, pci_channel_state_t state)
7795 scsi_qla_host_t *vha = pci_get_drvdata(pdev);
7796 struct qla_hw_data *ha = vha->hw;
7797 pci_ers_result_t ret = PCI_ERS_RESULT_NEED_RESET;
7799 ql_log(ql_log_warn, vha, 0x9000,
7800 "PCI error detected, state %x.\n", state);
7801 ha->pci_error_state = QLA_PCI_ERR_DETECTED;
7803 if (!atomic_read(&pdev->enable_cnt)) {
7804 ql_log(ql_log_info, vha, 0xffff,
7805 "PCI device is disabled,state %x\n", state);
7806 ret = PCI_ERS_RESULT_NEED_RESET;
7811 case pci_channel_io_normal:
7812 qla_pci_set_eeh_busy(vha);
7813 if (ql2xmqsupport || ql2xnvmeenable) {
7814 set_bit(QPAIR_ONLINE_CHECK_NEEDED, &vha->dpc_flags);
7815 qla2xxx_wake_dpc(vha);
7817 ret = PCI_ERS_RESULT_CAN_RECOVER;
7819 case pci_channel_io_frozen:
7820 qla_pci_set_eeh_busy(vha);
7821 ret = PCI_ERS_RESULT_NEED_RESET;
7823 case pci_channel_io_perm_failure:
7824 ha->flags.pci_channel_io_perm_failure = 1;
7825 qla2x00_abort_all_cmds(vha, DID_NO_CONNECT << 16);
7826 if (ql2xmqsupport || ql2xnvmeenable) {
7827 set_bit(QPAIR_ONLINE_CHECK_NEEDED, &vha->dpc_flags);
7828 qla2xxx_wake_dpc(vha);
7830 ret = PCI_ERS_RESULT_DISCONNECT;
7833 ql_dbg(ql_dbg_aer, vha, 0x600d,
7834 "PCI error detected returning [%x].\n", ret);
7838 static pci_ers_result_t
7839 qla2xxx_pci_mmio_enabled(struct pci_dev *pdev)
7841 int risc_paused = 0;
7843 unsigned long flags;
7844 scsi_qla_host_t *base_vha = pci_get_drvdata(pdev);
7845 struct qla_hw_data *ha = base_vha->hw;
7846 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
7847 struct device_reg_24xx __iomem *reg24 = &ha->iobase->isp24;
7849 ql_log(ql_log_warn, base_vha, 0x9000,
7852 ha->pci_error_state = QLA_PCI_MMIO_ENABLED;
7855 return PCI_ERS_RESULT_RECOVERED;
7857 if (qla2x00_isp_reg_stat(ha)) {
7858 ql_log(ql_log_info, base_vha, 0x803f,
7859 "During mmio enabled, PCI/Register disconnect still detected.\n");
7863 spin_lock_irqsave(&ha->hardware_lock, flags);
7864 if (IS_QLA2100(ha) || IS_QLA2200(ha)){
7865 stat = rd_reg_word(®->hccr);
7866 if (stat & HCCR_RISC_PAUSE)
7868 } else if (IS_QLA23XX(ha)) {
7869 stat = rd_reg_dword(®->u.isp2300.host_status);
7870 if (stat & HSR_RISC_PAUSED)
7872 } else if (IS_FWI2_CAPABLE(ha)) {
7873 stat = rd_reg_dword(®24->host_status);
7874 if (stat & HSRX_RISC_PAUSED)
7877 spin_unlock_irqrestore(&ha->hardware_lock, flags);
7880 ql_log(ql_log_info, base_vha, 0x9003,
7881 "RISC paused -- mmio_enabled, Dumping firmware.\n");
7882 qla2xxx_dump_fw(base_vha);
7885 /* set PCI_ERS_RESULT_NEED_RESET to trigger call to qla2xxx_pci_slot_reset */
7886 ql_dbg(ql_dbg_aer, base_vha, 0x600d,
7887 "mmio enabled returning.\n");
7888 return PCI_ERS_RESULT_NEED_RESET;
7891 static pci_ers_result_t
7892 qla2xxx_pci_slot_reset(struct pci_dev *pdev)
7894 pci_ers_result_t ret = PCI_ERS_RESULT_DISCONNECT;
7895 scsi_qla_host_t *base_vha = pci_get_drvdata(pdev);
7896 struct qla_hw_data *ha = base_vha->hw;
7898 struct qla_qpair *qpair = NULL;
7900 ql_log(ql_log_warn, base_vha, 0x9004,
7903 ha->pci_error_state = QLA_PCI_SLOT_RESET;
7904 /* Workaround: qla2xxx driver which access hardware earlier
7905 * needs error state to be pci_channel_io_online.
7906 * Otherwise mailbox command timesout.
7908 pdev->error_state = pci_channel_io_normal;
7910 pci_restore_state(pdev);
7912 /* pci_restore_state() clears the saved_state flag of the device
7913 * save restored state which resets saved_state flag
7915 pci_save_state(pdev);
7918 rc = pci_enable_device_mem(pdev);
7920 rc = pci_enable_device(pdev);
7923 ql_log(ql_log_warn, base_vha, 0x9005,
7924 "Can't re-enable PCI device after reset.\n");
7925 goto exit_slot_reset;
7929 if (ha->isp_ops->pci_config(base_vha))
7930 goto exit_slot_reset;
7932 mutex_lock(&ha->mq_lock);
7933 list_for_each_entry(qpair, &base_vha->qp_list, qp_list_elem)
7935 mutex_unlock(&ha->mq_lock);
7937 ha->flags.eeh_busy = 0;
7938 base_vha->flags.online = 1;
7939 set_bit(ABORT_ISP_ACTIVE, &base_vha->dpc_flags);
7940 ha->isp_ops->abort_isp(base_vha);
7941 clear_bit(ABORT_ISP_ACTIVE, &base_vha->dpc_flags);
7943 if (qla2x00_isp_reg_stat(ha)) {
7944 ha->flags.eeh_busy = 1;
7945 qla_pci_error_cleanup(base_vha);
7946 ql_log(ql_log_warn, base_vha, 0x9005,
7947 "Device unable to recover from PCI error.\n");
7949 ret = PCI_ERS_RESULT_RECOVERED;
7953 ql_dbg(ql_dbg_aer, base_vha, 0x900e,
7954 "Slot Reset returning %x.\n", ret);
7960 qla2xxx_pci_resume(struct pci_dev *pdev)
7962 scsi_qla_host_t *base_vha = pci_get_drvdata(pdev);
7963 struct qla_hw_data *ha = base_vha->hw;
7966 ql_log(ql_log_warn, base_vha, 0x900f,
7970 ret = qla2x00_wait_for_hba_online(base_vha);
7971 if (ret != QLA_SUCCESS) {
7972 ql_log(ql_log_fatal, base_vha, 0x9002,
7973 "The device failed to resume I/O from slot/link_reset.\n");
7975 ha->pci_error_state = QLA_PCI_RESUME;
7976 ql_dbg(ql_dbg_aer, base_vha, 0x600d,
7977 "Pci Resume returning.\n");
7980 void qla_pci_set_eeh_busy(struct scsi_qla_host *vha)
7982 struct qla_hw_data *ha = vha->hw;
7983 struct scsi_qla_host *base_vha = pci_get_drvdata(ha->pdev);
7984 bool do_cleanup = false;
7985 unsigned long flags;
7987 if (ha->flags.eeh_busy)
7990 spin_lock_irqsave(&base_vha->work_lock, flags);
7991 if (!ha->flags.eeh_busy) {
7992 ha->eeh_jif = jiffies;
7993 ha->flags.eeh_flush = 0;
7995 ha->flags.eeh_busy = 1;
7998 spin_unlock_irqrestore(&base_vha->work_lock, flags);
8001 qla_pci_error_cleanup(base_vha);
8005 * this routine will schedule a task to pause IO from interrupt context
8006 * if caller sees a PCIE error event (register read = 0xf's)
8008 void qla_schedule_eeh_work(struct scsi_qla_host *vha)
8010 struct qla_hw_data *ha = vha->hw;
8011 struct scsi_qla_host *base_vha = pci_get_drvdata(ha->pdev);
8013 if (ha->flags.eeh_busy)
8016 set_bit(DO_EEH_RECOVERY, &base_vha->dpc_flags);
8017 qla2xxx_wake_dpc(base_vha);
8021 qla_pci_reset_prepare(struct pci_dev *pdev)
8023 scsi_qla_host_t *base_vha = pci_get_drvdata(pdev);
8024 struct qla_hw_data *ha = base_vha->hw;
8025 struct qla_qpair *qpair;
8027 ql_log(ql_log_warn, base_vha, 0xffff,
8031 * PCI FLR/function reset is about to reset the
8032 * slot. Stop the chip to stop all DMA access.
8033 * It is assumed that pci_reset_done will be called
8034 * after FLR to resume Chip operation.
8036 ha->flags.eeh_busy = 1;
8037 mutex_lock(&ha->mq_lock);
8038 list_for_each_entry(qpair, &base_vha->qp_list, qp_list_elem)
8040 mutex_unlock(&ha->mq_lock);
8042 set_bit(ABORT_ISP_ACTIVE, &base_vha->dpc_flags);
8043 qla2x00_abort_isp_cleanup(base_vha);
8044 qla2x00_abort_all_cmds(base_vha, DID_RESET << 16);
8048 qla_pci_reset_done(struct pci_dev *pdev)
8050 scsi_qla_host_t *base_vha = pci_get_drvdata(pdev);
8051 struct qla_hw_data *ha = base_vha->hw;
8052 struct qla_qpair *qpair;
8054 ql_log(ql_log_warn, base_vha, 0xffff,
8058 * FLR just completed by PCI layer. Resume adapter
8060 ha->flags.eeh_busy = 0;
8061 mutex_lock(&ha->mq_lock);
8062 list_for_each_entry(qpair, &base_vha->qp_list, qp_list_elem)
8064 mutex_unlock(&ha->mq_lock);
8066 base_vha->flags.online = 1;
8067 ha->isp_ops->abort_isp(base_vha);
8068 clear_bit(ABORT_ISP_ACTIVE, &base_vha->dpc_flags);
8071 static void qla2xxx_map_queues(struct Scsi_Host *shost)
8073 scsi_qla_host_t *vha = (scsi_qla_host_t *)shost->hostdata;
8074 struct blk_mq_queue_map *qmap = &shost->tag_set.map[HCTX_TYPE_DEFAULT];
8076 if (USER_CTRL_IRQ(vha->hw) || !vha->hw->mqiobase)
8077 blk_mq_map_queues(qmap);
8079 blk_mq_pci_map_queues(qmap, vha->hw->pdev, vha->irq_offset);
8082 struct scsi_host_template qla2xxx_driver_template = {
8083 .module = THIS_MODULE,
8084 .name = QLA2XXX_DRIVER_NAME,
8085 .queuecommand = qla2xxx_queuecommand,
8087 .eh_timed_out = fc_eh_timed_out,
8088 .eh_abort_handler = qla2xxx_eh_abort,
8089 .eh_should_retry_cmd = fc_eh_should_retry_cmd,
8090 .eh_device_reset_handler = qla2xxx_eh_device_reset,
8091 .eh_target_reset_handler = qla2xxx_eh_target_reset,
8092 .eh_bus_reset_handler = qla2xxx_eh_bus_reset,
8093 .eh_host_reset_handler = qla2xxx_eh_host_reset,
8095 .slave_configure = qla2xxx_slave_configure,
8097 .slave_alloc = qla2xxx_slave_alloc,
8098 .slave_destroy = qla2xxx_slave_destroy,
8099 .scan_finished = qla2xxx_scan_finished,
8100 .scan_start = qla2xxx_scan_start,
8101 .change_queue_depth = scsi_change_queue_depth,
8102 .map_queues = qla2xxx_map_queues,
8105 .sg_tablesize = SG_ALL,
8107 .max_sectors = 0xFFFF,
8108 .shost_groups = qla2x00_host_groups,
8110 .supported_mode = MODE_INITIATOR,
8111 .track_queue_depth = 1,
8112 .cmd_size = sizeof(srb_t),
8115 static const struct pci_error_handlers qla2xxx_err_handler = {
8116 .error_detected = qla2xxx_pci_error_detected,
8117 .mmio_enabled = qla2xxx_pci_mmio_enabled,
8118 .slot_reset = qla2xxx_pci_slot_reset,
8119 .resume = qla2xxx_pci_resume,
8120 .reset_prepare = qla_pci_reset_prepare,
8121 .reset_done = qla_pci_reset_done,
8124 static struct pci_device_id qla2xxx_pci_tbl[] = {
8125 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP2100) },
8126 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP2200) },
8127 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP2300) },
8128 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP2312) },
8129 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP2322) },
8130 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP6312) },
8131 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP6322) },
8132 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP2422) },
8133 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP2432) },
8134 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP8432) },
8135 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP5422) },
8136 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP5432) },
8137 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP2532) },
8138 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP2031) },
8139 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP8001) },
8140 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP8021) },
8141 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP8031) },
8142 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISPF001) },
8143 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP8044) },
8144 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP2071) },
8145 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP2271) },
8146 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP2261) },
8147 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP2061) },
8148 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP2081) },
8149 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP2281) },
8150 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP2089) },
8151 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP2289) },
8154 MODULE_DEVICE_TABLE(pci, qla2xxx_pci_tbl);
8156 static struct pci_driver qla2xxx_pci_driver = {
8157 .name = QLA2XXX_DRIVER_NAME,
8159 .owner = THIS_MODULE,
8161 .id_table = qla2xxx_pci_tbl,
8162 .probe = qla2x00_probe_one,
8163 .remove = qla2x00_remove_one,
8164 .shutdown = qla2x00_shutdown,
8165 .err_handler = &qla2xxx_err_handler,
8168 static const struct file_operations apidev_fops = {
8169 .owner = THIS_MODULE,
8170 .llseek = noop_llseek,
8174 * qla2x00_module_init - Module initialization.
8177 qla2x00_module_init(void)
8181 BUILD_BUG_ON(sizeof(cmd_a64_entry_t) != 64);
8182 BUILD_BUG_ON(sizeof(cmd_entry_t) != 64);
8183 BUILD_BUG_ON(sizeof(cont_a64_entry_t) != 64);
8184 BUILD_BUG_ON(sizeof(cont_entry_t) != 64);
8185 BUILD_BUG_ON(sizeof(init_cb_t) != 96);
8186 BUILD_BUG_ON(sizeof(mrk_entry_t) != 64);
8187 BUILD_BUG_ON(sizeof(ms_iocb_entry_t) != 64);
8188 BUILD_BUG_ON(sizeof(request_t) != 64);
8189 BUILD_BUG_ON(sizeof(struct abort_entry_24xx) != 64);
8190 BUILD_BUG_ON(sizeof(struct abort_iocb_entry_fx00) != 64);
8191 BUILD_BUG_ON(sizeof(struct abts_entry_24xx) != 64);
8192 BUILD_BUG_ON(sizeof(struct access_chip_84xx) != 64);
8193 BUILD_BUG_ON(sizeof(struct access_chip_rsp_84xx) != 64);
8194 BUILD_BUG_ON(sizeof(struct cmd_bidir) != 64);
8195 BUILD_BUG_ON(sizeof(struct cmd_nvme) != 64);
8196 BUILD_BUG_ON(sizeof(struct cmd_type_6) != 64);
8197 BUILD_BUG_ON(sizeof(struct cmd_type_7) != 64);
8198 BUILD_BUG_ON(sizeof(struct cmd_type_7_fx00) != 64);
8199 BUILD_BUG_ON(sizeof(struct cmd_type_crc_2) != 64);
8200 BUILD_BUG_ON(sizeof(struct ct_entry_24xx) != 64);
8201 BUILD_BUG_ON(sizeof(struct ct_fdmi1_hba_attributes) != 2604);
8202 BUILD_BUG_ON(sizeof(struct ct_fdmi2_hba_attributes) != 4424);
8203 BUILD_BUG_ON(sizeof(struct ct_fdmi2_port_attributes) != 4164);
8204 BUILD_BUG_ON(sizeof(struct ct_fdmi_hba_attr) != 260);
8205 BUILD_BUG_ON(sizeof(struct ct_fdmi_port_attr) != 260);
8206 BUILD_BUG_ON(sizeof(struct ct_rsp_hdr) != 16);
8207 BUILD_BUG_ON(sizeof(struct ctio_crc2_to_fw) != 64);
8208 BUILD_BUG_ON(sizeof(struct device_reg_24xx) != 256);
8209 BUILD_BUG_ON(sizeof(struct device_reg_25xxmq) != 24);
8210 BUILD_BUG_ON(sizeof(struct device_reg_2xxx) != 256);
8211 BUILD_BUG_ON(sizeof(struct device_reg_82xx) != 1288);
8212 BUILD_BUG_ON(sizeof(struct device_reg_fx00) != 216);
8213 BUILD_BUG_ON(sizeof(struct els_entry_24xx) != 64);
8214 BUILD_BUG_ON(sizeof(struct els_sts_entry_24xx) != 64);
8215 BUILD_BUG_ON(sizeof(struct fxdisc_entry_fx00) != 64);
8216 BUILD_BUG_ON(sizeof(struct imm_ntfy_from_isp) != 64);
8217 BUILD_BUG_ON(sizeof(struct init_cb_24xx) != 128);
8218 BUILD_BUG_ON(sizeof(struct init_cb_81xx) != 128);
8219 BUILD_BUG_ON(sizeof(struct logio_entry_24xx) != 64);
8220 BUILD_BUG_ON(sizeof(struct mbx_entry) != 64);
8221 BUILD_BUG_ON(sizeof(struct mid_init_cb_24xx) != 5252);
8222 BUILD_BUG_ON(sizeof(struct mrk_entry_24xx) != 64);
8223 BUILD_BUG_ON(sizeof(struct nvram_24xx) != 512);
8224 BUILD_BUG_ON(sizeof(struct nvram_81xx) != 512);
8225 BUILD_BUG_ON(sizeof(struct pt_ls4_request) != 64);
8226 BUILD_BUG_ON(sizeof(struct pt_ls4_rx_unsol) != 64);
8227 BUILD_BUG_ON(sizeof(struct purex_entry_24xx) != 64);
8228 BUILD_BUG_ON(sizeof(struct qla2100_fw_dump) != 123634);
8229 BUILD_BUG_ON(sizeof(struct qla2300_fw_dump) != 136100);
8230 BUILD_BUG_ON(sizeof(struct qla24xx_fw_dump) != 37976);
8231 BUILD_BUG_ON(sizeof(struct qla25xx_fw_dump) != 39228);
8232 BUILD_BUG_ON(sizeof(struct qla2xxx_fce_chain) != 52);
8233 BUILD_BUG_ON(sizeof(struct qla2xxx_fw_dump) != 136172);
8234 BUILD_BUG_ON(sizeof(struct qla2xxx_mq_chain) != 524);
8235 BUILD_BUG_ON(sizeof(struct qla2xxx_mqueue_chain) != 8);
8236 BUILD_BUG_ON(sizeof(struct qla2xxx_mqueue_header) != 12);
8237 BUILD_BUG_ON(sizeof(struct qla2xxx_offld_chain) != 24);
8238 BUILD_BUG_ON(sizeof(struct qla81xx_fw_dump) != 39420);
8239 BUILD_BUG_ON(sizeof(struct qla82xx_uri_data_desc) != 28);
8240 BUILD_BUG_ON(sizeof(struct qla82xx_uri_table_desc) != 32);
8241 BUILD_BUG_ON(sizeof(struct qla83xx_fw_dump) != 51196);
8242 BUILD_BUG_ON(sizeof(struct qla_fcp_prio_cfg) != FCP_PRIO_CFG_SIZE);
8243 BUILD_BUG_ON(sizeof(struct qla_fdt_layout) != 128);
8244 BUILD_BUG_ON(sizeof(struct qla_flt_header) != 8);
8245 BUILD_BUG_ON(sizeof(struct qla_flt_region) != 16);
8246 BUILD_BUG_ON(sizeof(struct qla_npiv_entry) != 24);
8247 BUILD_BUG_ON(sizeof(struct qla_npiv_header) != 16);
8248 BUILD_BUG_ON(sizeof(struct rdp_rsp_payload) != 336);
8249 BUILD_BUG_ON(sizeof(struct sns_cmd_pkt) != 2064);
8250 BUILD_BUG_ON(sizeof(struct sts_entry_24xx) != 64);
8251 BUILD_BUG_ON(sizeof(struct tsk_mgmt_entry) != 64);
8252 BUILD_BUG_ON(sizeof(struct tsk_mgmt_entry_fx00) != 64);
8253 BUILD_BUG_ON(sizeof(struct verify_chip_entry_84xx) != 64);
8254 BUILD_BUG_ON(sizeof(struct verify_chip_rsp_84xx) != 52);
8255 BUILD_BUG_ON(sizeof(struct vf_evfp_entry_24xx) != 56);
8256 BUILD_BUG_ON(sizeof(struct vp_config_entry_24xx) != 64);
8257 BUILD_BUG_ON(sizeof(struct vp_ctrl_entry_24xx) != 64);
8258 BUILD_BUG_ON(sizeof(struct vp_rpt_id_entry_24xx) != 64);
8259 BUILD_BUG_ON(sizeof(sts21_entry_t) != 64);
8260 BUILD_BUG_ON(sizeof(sts22_entry_t) != 64);
8261 BUILD_BUG_ON(sizeof(sts_cont_entry_t) != 64);
8262 BUILD_BUG_ON(sizeof(sts_entry_t) != 64);
8263 BUILD_BUG_ON(sizeof(sw_info_t) != 32);
8264 BUILD_BUG_ON(sizeof(target_id_t) != 2);
8268 /* Allocate cache for SRBs. */
8269 srb_cachep = kmem_cache_create("qla2xxx_srbs", sizeof(srb_t), 0,
8270 SLAB_HWCACHE_ALIGN, NULL);
8271 if (srb_cachep == NULL) {
8272 ql_log(ql_log_fatal, NULL, 0x0001,
8273 "Unable to allocate SRB cache...Failing load!.\n");
8277 /* Initialize target kmem_cache and mem_pools */
8281 } else if (ret > 0) {
8283 * If initiator mode is explictly disabled by qlt_init(),
8284 * prevent scsi_transport_fc.c:fc_scsi_scan_rport() from
8285 * performing scsi_scan_target() during LOOP UP event.
8287 qla2xxx_transport_functions.disable_target_scan = 1;
8288 qla2xxx_transport_vport_functions.disable_target_scan = 1;
8291 /* Derive version string. */
8292 strcpy(qla2x00_version_str, QLA2XXX_VERSION);
8293 if (ql2xextended_error_logging)
8294 strcat(qla2x00_version_str, "-debug");
8295 if (ql2xextended_error_logging == 1)
8296 ql2xextended_error_logging = QL_DBG_DEFAULT1_MASK;
8298 qla2xxx_transport_template =
8299 fc_attach_transport(&qla2xxx_transport_functions);
8300 if (!qla2xxx_transport_template) {
8301 ql_log(ql_log_fatal, NULL, 0x0002,
8302 "fc_attach_transport failed...Failing load!.\n");
8307 apidev_major = register_chrdev(0, QLA2XXX_APIDEV, &apidev_fops);
8308 if (apidev_major < 0) {
8309 ql_log(ql_log_fatal, NULL, 0x0003,
8310 "Unable to register char device %s.\n", QLA2XXX_APIDEV);
8313 qla2xxx_transport_vport_template =
8314 fc_attach_transport(&qla2xxx_transport_vport_functions);
8315 if (!qla2xxx_transport_vport_template) {
8316 ql_log(ql_log_fatal, NULL, 0x0004,
8317 "fc_attach_transport vport failed...Failing load!.\n");
8321 ql_log(ql_log_info, NULL, 0x0005,
8322 "QLogic Fibre Channel HBA Driver: %s.\n",
8323 qla2x00_version_str);
8324 ret = pci_register_driver(&qla2xxx_pci_driver);
8326 ql_log(ql_log_fatal, NULL, 0x0006,
8327 "pci_register_driver failed...ret=%d Failing load!.\n",
8329 goto release_vport_transport;
8333 release_vport_transport:
8334 fc_release_transport(qla2xxx_transport_vport_template);
8337 if (apidev_major >= 0)
8338 unregister_chrdev(apidev_major, QLA2XXX_APIDEV);
8339 fc_release_transport(qla2xxx_transport_template);
8345 kmem_cache_destroy(srb_cachep);
8352 * qla2x00_module_exit - Module cleanup.
8355 qla2x00_module_exit(void)
8357 pci_unregister_driver(&qla2xxx_pci_driver);
8358 qla2x00_release_firmware();
8359 kmem_cache_destroy(ctx_cachep);
8360 fc_release_transport(qla2xxx_transport_vport_template);
8361 if (apidev_major >= 0)
8362 unregister_chrdev(apidev_major, QLA2XXX_APIDEV);
8363 fc_release_transport(qla2xxx_transport_template);
8365 kmem_cache_destroy(srb_cachep);
8369 module_init(qla2x00_module_init);
8370 module_exit(qla2x00_module_exit);
8372 MODULE_AUTHOR("QLogic Corporation");
8373 MODULE_DESCRIPTION("QLogic Fibre Channel HBA Driver");
8374 MODULE_LICENSE("GPL");
8375 MODULE_FIRMWARE(FW_FILE_ISP21XX);
8376 MODULE_FIRMWARE(FW_FILE_ISP22XX);
8377 MODULE_FIRMWARE(FW_FILE_ISP2300);
8378 MODULE_FIRMWARE(FW_FILE_ISP2322);
8379 MODULE_FIRMWARE(FW_FILE_ISP24XX);
8380 MODULE_FIRMWARE(FW_FILE_ISP25XX);