1 // SPDX-License-Identifier: GPL-2.0-only
3 * QLogic Fibre Channel HBA Driver
4 * Copyright (c) 2003-2014 QLogic Corporation
8 #include <linux/moduleparam.h>
9 #include <linux/vmalloc.h>
10 #include <linux/delay.h>
11 #include <linux/kthread.h>
12 #include <linux/mutex.h>
13 #include <linux/kobject.h>
14 #include <linux/slab.h>
15 #include <linux/blk-mq-pci.h>
16 #include <linux/refcount.h>
17 #include <linux/crash_dump.h>
19 #include <scsi/scsi_tcq.h>
20 #include <scsi/scsicam.h>
21 #include <scsi/scsi_transport.h>
22 #include <scsi/scsi_transport_fc.h>
24 #include "qla_target.h"
29 char qla2x00_version_str[40];
31 static int apidev_major;
34 * SRB allocation cache
36 struct kmem_cache *srb_cachep;
38 int ql2xfulldump_on_mpifail;
39 module_param(ql2xfulldump_on_mpifail, int, S_IRUGO | S_IWUSR);
40 MODULE_PARM_DESC(ql2xfulldump_on_mpifail,
41 "Set this to take full dump on MPI hang.");
43 int ql2xenforce_iocb_limit = 1;
44 module_param(ql2xenforce_iocb_limit, int, S_IRUGO | S_IWUSR);
45 MODULE_PARM_DESC(ql2xenforce_iocb_limit,
46 "Enforce IOCB throttling, to avoid FW congestion. (default: 1)");
49 * CT6 CTX allocation cache
51 static struct kmem_cache *ctx_cachep;
53 * error level for logging
55 uint ql_errlev = 0x8001;
57 static int ql2xenableclass2;
58 module_param(ql2xenableclass2, int, S_IRUGO|S_IRUSR);
59 MODULE_PARM_DESC(ql2xenableclass2,
60 "Specify if Class 2 operations are supported from the very "
61 "beginning. Default is 0 - class 2 not supported.");
64 int ql2xlogintimeout = 20;
65 module_param(ql2xlogintimeout, int, S_IRUGO);
66 MODULE_PARM_DESC(ql2xlogintimeout,
67 "Login timeout value in seconds.");
69 int qlport_down_retry;
70 module_param(qlport_down_retry, int, S_IRUGO);
71 MODULE_PARM_DESC(qlport_down_retry,
72 "Maximum number of command retries to a port that returns "
73 "a PORT-DOWN status.");
75 int ql2xplogiabsentdevice;
76 module_param(ql2xplogiabsentdevice, int, S_IRUGO|S_IWUSR);
77 MODULE_PARM_DESC(ql2xplogiabsentdevice,
78 "Option to enable PLOGI to devices that are not present after "
79 "a Fabric scan. This is needed for several broken switches. "
80 "Default is 0 - no PLOGI. 1 - perform PLOGI.");
82 int ql2xloginretrycount;
83 module_param(ql2xloginretrycount, int, S_IRUGO);
84 MODULE_PARM_DESC(ql2xloginretrycount,
85 "Specify an alternate value for the NVRAM login retry count.");
87 int ql2xallocfwdump = 1;
88 module_param(ql2xallocfwdump, int, S_IRUGO);
89 MODULE_PARM_DESC(ql2xallocfwdump,
90 "Option to enable allocation of memory for a firmware dump "
91 "during HBA initialization. Memory allocation requirements "
92 "vary by ISP type. Default is 1 - allocate memory.");
94 int ql2xextended_error_logging;
95 module_param(ql2xextended_error_logging, int, S_IRUGO|S_IWUSR);
96 module_param_named(logging, ql2xextended_error_logging, int, S_IRUGO|S_IWUSR);
97 MODULE_PARM_DESC(ql2xextended_error_logging,
98 "Option to enable extended error logging,\n"
99 "\t\tDefault is 0 - no logging. 0x40000000 - Module Init & Probe.\n"
100 "\t\t0x20000000 - Mailbox Cmnds. 0x10000000 - Device Discovery.\n"
101 "\t\t0x08000000 - IO tracing. 0x04000000 - DPC Thread.\n"
102 "\t\t0x02000000 - Async events. 0x01000000 - Timer routines.\n"
103 "\t\t0x00800000 - User space. 0x00400000 - Task Management.\n"
104 "\t\t0x00200000 - AER/EEH. 0x00100000 - Multi Q.\n"
105 "\t\t0x00080000 - P3P Specific. 0x00040000 - Virtual Port.\n"
106 "\t\t0x00020000 - Buffer Dump. 0x00010000 - Misc.\n"
107 "\t\t0x00008000 - Verbose. 0x00004000 - Target.\n"
108 "\t\t0x00002000 - Target Mgmt. 0x00001000 - Target TMF.\n"
109 "\t\t0x7fffffff - For enabling all logs, can be too many logs.\n"
110 "\t\t0x1e400000 - Preferred value for capturing essential "
111 "debug information (equivalent to old "
112 "ql2xextended_error_logging=1).\n"
113 "\t\tDo LOGICAL OR of the value to enable more than one level");
115 int ql2xshiftctondsd = 6;
116 module_param(ql2xshiftctondsd, int, S_IRUGO);
117 MODULE_PARM_DESC(ql2xshiftctondsd,
118 "Set to control shifting of command type processing "
119 "based on total number of SG elements.");
121 int ql2xfdmienable = 1;
122 module_param(ql2xfdmienable, int, S_IRUGO|S_IWUSR);
123 module_param_named(fdmi, ql2xfdmienable, int, S_IRUGO|S_IWUSR);
124 MODULE_PARM_DESC(ql2xfdmienable,
125 "Enables FDMI registrations. "
126 "0 - no FDMI registrations. "
127 "1 - provide FDMI registrations (default).");
129 #define MAX_Q_DEPTH 64
130 static int ql2xmaxqdepth = MAX_Q_DEPTH;
131 module_param(ql2xmaxqdepth, int, S_IRUGO|S_IWUSR);
132 MODULE_PARM_DESC(ql2xmaxqdepth,
133 "Maximum queue depth to set for each LUN. "
136 int ql2xenabledif = 2;
137 module_param(ql2xenabledif, int, S_IRUGO);
138 MODULE_PARM_DESC(ql2xenabledif,
139 " Enable T10-CRC-DIF:\n"
141 " 0 -- No DIF Support\n"
142 " 1 -- Enable DIF for all types\n"
143 " 2 -- Enable DIF for all types, except Type 0.\n");
145 #if (IS_ENABLED(CONFIG_NVME_FC))
146 int ql2xnvmeenable = 1;
150 module_param(ql2xnvmeenable, int, 0644);
151 MODULE_PARM_DESC(ql2xnvmeenable,
152 "Enables NVME support. "
153 "0 - no NVMe. Default is Y");
155 int ql2xenablehba_err_chk = 2;
156 module_param(ql2xenablehba_err_chk, int, S_IRUGO|S_IWUSR);
157 MODULE_PARM_DESC(ql2xenablehba_err_chk,
158 " Enable T10-CRC-DIF Error isolation by HBA:\n"
160 " 0 -- Error isolation disabled\n"
161 " 1 -- Error isolation enabled only for DIX Type 0\n"
162 " 2 -- Error isolation enabled for all Types\n");
164 int ql2xiidmaenable = 1;
165 module_param(ql2xiidmaenable, int, S_IRUGO);
166 MODULE_PARM_DESC(ql2xiidmaenable,
167 "Enables iIDMA settings "
168 "Default is 1 - perform iIDMA. 0 - no iIDMA.");
170 int ql2xmqsupport = 1;
171 module_param(ql2xmqsupport, int, S_IRUGO);
172 MODULE_PARM_DESC(ql2xmqsupport,
173 "Enable on demand multiple queue pairs support "
174 "Default is 1 for supported. "
175 "Set it to 0 to turn off mq qpair support.");
178 module_param(ql2xfwloadbin, int, S_IRUGO|S_IWUSR);
179 module_param_named(fwload, ql2xfwloadbin, int, S_IRUGO|S_IWUSR);
180 MODULE_PARM_DESC(ql2xfwloadbin,
181 "Option to specify location from which to load ISP firmware:.\n"
182 " 2 -- load firmware via the reject_firmware() (hotplug).\n"
184 " 1 -- load firmware from flash.\n"
185 " 0 -- use default semantics.\n");
188 module_param(ql2xetsenable, int, S_IRUGO);
189 MODULE_PARM_DESC(ql2xetsenable,
190 "Enables firmware ETS burst."
191 "Default is 0 - skip ETS enablement.");
194 module_param(ql2xdbwr, int, S_IRUGO|S_IWUSR);
195 MODULE_PARM_DESC(ql2xdbwr,
196 "Option to specify scheme for request queue posting.\n"
197 " 0 -- Regular doorbell.\n"
198 " 1 -- CAMRAM doorbell (faster).\n");
201 module_param(ql2xgffidenable, int, S_IRUGO);
202 MODULE_PARM_DESC(ql2xgffidenable,
203 "Enables GFF_ID checks of port type. "
204 "Default is 0 - Do not use GFF_ID information.");
206 int ql2xasynctmfenable = 1;
207 module_param(ql2xasynctmfenable, int, S_IRUGO);
208 MODULE_PARM_DESC(ql2xasynctmfenable,
209 "Enables issue of TM IOCBs asynchronously via IOCB mechanism"
210 "Default is 1 - Issue TM IOCBs via mailbox mechanism.");
212 int ql2xdontresethba;
213 module_param(ql2xdontresethba, int, S_IRUGO|S_IWUSR);
214 MODULE_PARM_DESC(ql2xdontresethba,
215 "Option to specify reset behaviour.\n"
216 " 0 (Default) -- Reset on failure.\n"
217 " 1 -- Do not reset on failure.\n");
219 uint64_t ql2xmaxlun = MAX_LUNS;
220 module_param(ql2xmaxlun, ullong, S_IRUGO);
221 MODULE_PARM_DESC(ql2xmaxlun,
222 "Defines the maximum LU number to register with the SCSI "
223 "midlayer. Default is 65535.");
225 int ql2xmdcapmask = 0x1F;
226 module_param(ql2xmdcapmask, int, S_IRUGO);
227 MODULE_PARM_DESC(ql2xmdcapmask,
228 "Set the Minidump driver capture mask level. "
229 "Default is 0x1F - Can be set to 0x3, 0x7, 0xF, 0x1F, 0x7F.");
231 int ql2xmdenable = 1;
232 module_param(ql2xmdenable, int, S_IRUGO);
233 MODULE_PARM_DESC(ql2xmdenable,
234 "Enable/disable MiniDump. "
235 "0 - MiniDump disabled. "
236 "1 (Default) - MiniDump enabled.");
239 module_param(ql2xexlogins, uint, S_IRUGO|S_IWUSR);
240 MODULE_PARM_DESC(ql2xexlogins,
241 "Number of extended Logins. "
242 "0 (Default)- Disabled.");
244 int ql2xexchoffld = 1024;
245 module_param(ql2xexchoffld, uint, 0644);
246 MODULE_PARM_DESC(ql2xexchoffld,
247 "Number of target exchanges.");
249 int ql2xiniexchg = 1024;
250 module_param(ql2xiniexchg, uint, 0644);
251 MODULE_PARM_DESC(ql2xiniexchg,
252 "Number of initiator exchanges.");
255 module_param(ql2xfwholdabts, int, S_IRUGO);
256 MODULE_PARM_DESC(ql2xfwholdabts,
257 "Allow FW to hold status IOCB until ABTS rsp received. "
258 "0 (Default) Do not set fw option. "
259 "1 - Set fw option to hold ABTS.");
261 int ql2xmvasynctoatio = 1;
262 module_param(ql2xmvasynctoatio, int, S_IRUGO|S_IWUSR);
263 MODULE_PARM_DESC(ql2xmvasynctoatio,
264 "Move PUREX, ABTS RX and RIDA IOCBs to ATIOQ"
265 "0 (Default). Do not move IOCBs"
268 int ql2xautodetectsfp = 1;
269 module_param(ql2xautodetectsfp, int, 0444);
270 MODULE_PARM_DESC(ql2xautodetectsfp,
271 "Detect SFP range and set appropriate distance.\n"
272 "1 (Default): Enable\n");
274 int ql2xenablemsix = 1;
275 module_param(ql2xenablemsix, int, 0444);
276 MODULE_PARM_DESC(ql2xenablemsix,
277 "Set to enable MSI or MSI-X interrupt mechanism.\n"
278 " Default is 1, enable MSI-X interrupt mechanism.\n"
279 " 0 -- enable traditional pin-based mechanism.\n"
280 " 1 -- enable MSI-X interrupt mechanism.\n"
281 " 2 -- enable MSI interrupt mechanism.\n");
283 int qla2xuseresexchforels;
284 module_param(qla2xuseresexchforels, int, 0444);
285 MODULE_PARM_DESC(qla2xuseresexchforels,
286 "Reserve 1/2 of emergency exchanges for ELS.\n"
287 " 0 (default): disabled");
289 static int ql2xprotmask;
290 module_param(ql2xprotmask, int, 0644);
291 MODULE_PARM_DESC(ql2xprotmask,
292 "Override DIF/DIX protection capabilities mask\n"
293 "Default is 0 which sets protection mask based on "
294 "capabilities reported by HBA firmware.\n");
296 static int ql2xprotguard;
297 module_param(ql2xprotguard, int, 0644);
298 MODULE_PARM_DESC(ql2xprotguard, "Override choice of DIX checksum\n"
299 " 0 -- Let HBA firmware decide\n"
300 " 1 -- Force T10 CRC\n"
301 " 2 -- Force IP checksum\n");
303 int ql2xdifbundlinginternalbuffers;
304 module_param(ql2xdifbundlinginternalbuffers, int, 0644);
305 MODULE_PARM_DESC(ql2xdifbundlinginternalbuffers,
306 "Force using internal buffers for DIF information\n"
307 "0 (Default). Based on check.\n"
308 "1 Force using internal buffers\n");
311 module_param(ql2xsmartsan, int, 0444);
312 module_param_named(smartsan, ql2xsmartsan, int, 0444);
313 MODULE_PARM_DESC(ql2xsmartsan,
314 "Send SmartSAN Management Attributes for FDMI Registration."
315 " Default is 0 - No SmartSAN registration,"
316 " 1 - Register SmartSAN Management Attributes.");
319 module_param(ql2xrdpenable, int, 0444);
320 module_param_named(rdpenable, ql2xrdpenable, int, 0444);
321 MODULE_PARM_DESC(ql2xrdpenable,
322 "Enables RDP responses. "
323 "0 - no RDP responses (default). "
324 "1 - provide RDP responses.");
326 static void qla2x00_clear_drv_active(struct qla_hw_data *);
327 static void qla2x00_free_device(scsi_qla_host_t *);
328 static int qla2xxx_map_queues(struct Scsi_Host *shost);
329 static void qla2x00_destroy_deferred_work(struct qla_hw_data *);
332 static struct scsi_transport_template *qla2xxx_transport_template = NULL;
333 struct scsi_transport_template *qla2xxx_transport_vport_template = NULL;
335 /* TODO Convert to inlines
341 qla2x00_start_timer(scsi_qla_host_t *vha, unsigned long interval)
343 timer_setup(&vha->timer, qla2x00_timer, 0);
344 vha->timer.expires = jiffies + interval * HZ;
345 add_timer(&vha->timer);
346 vha->timer_active = 1;
350 qla2x00_restart_timer(scsi_qla_host_t *vha, unsigned long interval)
352 /* Currently used for 82XX only. */
353 if (vha->device_flags & DFLG_DEV_FAILED) {
354 ql_dbg(ql_dbg_timer, vha, 0x600d,
355 "Device in a failed state, returning.\n");
359 mod_timer(&vha->timer, jiffies + interval * HZ);
362 static __inline__ void
363 qla2x00_stop_timer(scsi_qla_host_t *vha)
365 del_timer_sync(&vha->timer);
366 vha->timer_active = 0;
369 static int qla2x00_do_dpc(void *data);
371 static void qla2x00_rst_aen(scsi_qla_host_t *);
373 static int qla2x00_mem_alloc(struct qla_hw_data *, uint16_t, uint16_t,
374 struct req_que **, struct rsp_que **);
375 static void qla2x00_free_fw_dump(struct qla_hw_data *);
376 static void qla2x00_mem_free(struct qla_hw_data *);
377 int qla2xxx_mqueuecommand(struct Scsi_Host *host, struct scsi_cmnd *cmd,
378 struct qla_qpair *qpair);
380 /* -------------------------------------------------------------------------- */
381 static void qla_init_base_qpair(struct scsi_qla_host *vha, struct req_que *req,
384 struct qla_hw_data *ha = vha->hw;
386 rsp->qpair = ha->base_qpair;
388 ha->base_qpair->hw = ha;
389 ha->base_qpair->req = req;
390 ha->base_qpair->rsp = rsp;
391 ha->base_qpair->vha = vha;
392 ha->base_qpair->qp_lock_ptr = &ha->hardware_lock;
393 ha->base_qpair->use_shadow_reg = IS_SHADOW_REG_CAPABLE(ha) ? 1 : 0;
394 ha->base_qpair->msix = &ha->msix_entries[QLA_MSIX_RSP_Q];
395 ha->base_qpair->srb_mempool = ha->srb_mempool;
396 INIT_LIST_HEAD(&ha->base_qpair->hints_list);
397 ha->base_qpair->enable_class_2 = ql2xenableclass2;
398 /* init qpair to this cpu. Will adjust at run time. */
399 qla_cpu_update(rsp->qpair, raw_smp_processor_id());
400 ha->base_qpair->pdev = ha->pdev;
402 if (IS_QLA27XX(ha) || IS_QLA83XX(ha) || IS_QLA28XX(ha))
403 ha->base_qpair->reqq_start_iocbs = qla_83xx_start_iocbs;
406 static int qla2x00_alloc_queues(struct qla_hw_data *ha, struct req_que *req,
409 scsi_qla_host_t *vha = pci_get_drvdata(ha->pdev);
411 ha->req_q_map = kcalloc(ha->max_req_queues, sizeof(struct req_que *),
413 if (!ha->req_q_map) {
414 ql_log(ql_log_fatal, vha, 0x003b,
415 "Unable to allocate memory for request queue ptrs.\n");
419 ha->rsp_q_map = kcalloc(ha->max_rsp_queues, sizeof(struct rsp_que *),
421 if (!ha->rsp_q_map) {
422 ql_log(ql_log_fatal, vha, 0x003c,
423 "Unable to allocate memory for response queue ptrs.\n");
427 ha->base_qpair = kzalloc(sizeof(struct qla_qpair), GFP_KERNEL);
428 if (ha->base_qpair == NULL) {
429 ql_log(ql_log_warn, vha, 0x00e0,
430 "Failed to allocate base queue pair memory.\n");
431 goto fail_base_qpair;
434 qla_init_base_qpair(vha, req, rsp);
436 if ((ql2xmqsupport || ql2xnvmeenable) && ha->max_qpairs) {
437 ha->queue_pair_map = kcalloc(ha->max_qpairs, sizeof(struct qla_qpair *),
439 if (!ha->queue_pair_map) {
440 ql_log(ql_log_fatal, vha, 0x0180,
441 "Unable to allocate memory for queue pair ptrs.\n");
447 * Make sure we record at least the request and response queue zero in
448 * case we need to free them if part of the probe fails.
450 ha->rsp_q_map[0] = rsp;
451 ha->req_q_map[0] = req;
452 set_bit(0, ha->rsp_qid_map);
453 set_bit(0, ha->req_qid_map);
457 kfree(ha->base_qpair);
458 ha->base_qpair = NULL;
460 kfree(ha->rsp_q_map);
461 ha->rsp_q_map = NULL;
463 kfree(ha->req_q_map);
464 ha->req_q_map = NULL;
469 static void qla2x00_free_req_que(struct qla_hw_data *ha, struct req_que *req)
471 if (IS_QLAFX00(ha)) {
472 if (req && req->ring_fx00)
473 dma_free_coherent(&ha->pdev->dev,
474 (req->length_fx00 + 1) * sizeof(request_t),
475 req->ring_fx00, req->dma_fx00);
476 } else if (req && req->ring)
477 dma_free_coherent(&ha->pdev->dev,
478 (req->length + 1) * sizeof(request_t),
479 req->ring, req->dma);
482 kfree(req->outstanding_cmds);
487 static void qla2x00_free_rsp_que(struct qla_hw_data *ha, struct rsp_que *rsp)
489 if (IS_QLAFX00(ha)) {
490 if (rsp && rsp->ring_fx00)
491 dma_free_coherent(&ha->pdev->dev,
492 (rsp->length_fx00 + 1) * sizeof(request_t),
493 rsp->ring_fx00, rsp->dma_fx00);
494 } else if (rsp && rsp->ring) {
495 dma_free_coherent(&ha->pdev->dev,
496 (rsp->length + 1) * sizeof(response_t),
497 rsp->ring, rsp->dma);
502 static void qla2x00_free_queues(struct qla_hw_data *ha)
509 if (ha->queue_pair_map) {
510 kfree(ha->queue_pair_map);
511 ha->queue_pair_map = NULL;
513 if (ha->base_qpair) {
514 kfree(ha->base_qpair);
515 ha->base_qpair = NULL;
518 spin_lock_irqsave(&ha->hardware_lock, flags);
519 for (cnt = 0; cnt < ha->max_req_queues; cnt++) {
520 if (!test_bit(cnt, ha->req_qid_map))
523 req = ha->req_q_map[cnt];
524 clear_bit(cnt, ha->req_qid_map);
525 ha->req_q_map[cnt] = NULL;
527 spin_unlock_irqrestore(&ha->hardware_lock, flags);
528 qla2x00_free_req_que(ha, req);
529 spin_lock_irqsave(&ha->hardware_lock, flags);
531 spin_unlock_irqrestore(&ha->hardware_lock, flags);
533 kfree(ha->req_q_map);
534 ha->req_q_map = NULL;
537 spin_lock_irqsave(&ha->hardware_lock, flags);
538 for (cnt = 0; cnt < ha->max_rsp_queues; cnt++) {
539 if (!test_bit(cnt, ha->rsp_qid_map))
542 rsp = ha->rsp_q_map[cnt];
543 clear_bit(cnt, ha->rsp_qid_map);
544 ha->rsp_q_map[cnt] = NULL;
545 spin_unlock_irqrestore(&ha->hardware_lock, flags);
546 qla2x00_free_rsp_que(ha, rsp);
547 spin_lock_irqsave(&ha->hardware_lock, flags);
549 spin_unlock_irqrestore(&ha->hardware_lock, flags);
551 kfree(ha->rsp_q_map);
552 ha->rsp_q_map = NULL;
556 qla2x00_pci_info_str(struct scsi_qla_host *vha, char *str, size_t str_len)
558 struct qla_hw_data *ha = vha->hw;
559 static const char *const pci_bus_modes[] = {
560 "33", "66", "100", "133",
564 pci_bus = (ha->pci_attr & (BIT_9 | BIT_10)) >> 9;
566 snprintf(str, str_len, "PCI-X (%s MHz)",
567 pci_bus_modes[pci_bus]);
569 pci_bus = (ha->pci_attr & BIT_8) >> 8;
570 snprintf(str, str_len, "PCI (%s MHz)", pci_bus_modes[pci_bus]);
577 qla24xx_pci_info_str(struct scsi_qla_host *vha, char *str, size_t str_len)
579 static const char *const pci_bus_modes[] = {
580 "33", "66", "100", "133",
582 struct qla_hw_data *ha = vha->hw;
585 if (pci_is_pcie(ha->pdev)) {
586 uint32_t lstat, lspeed, lwidth;
587 const char *speed_str;
589 pcie_capability_read_dword(ha->pdev, PCI_EXP_LNKCAP, &lstat);
590 lspeed = lstat & PCI_EXP_LNKCAP_SLS;
591 lwidth = (lstat & PCI_EXP_LNKCAP_MLW) >> 4;
595 speed_str = "2.5GT/s";
598 speed_str = "5.0GT/s";
601 speed_str = "8.0GT/s";
604 speed_str = "16.0GT/s";
607 speed_str = "<unknown>";
610 snprintf(str, str_len, "PCIe (%s x%d)", speed_str, lwidth);
615 pci_bus = (ha->pci_attr & CSRX_PCIX_BUS_MODE_MASK) >> 8;
616 if (pci_bus == 0 || pci_bus == 8)
617 snprintf(str, str_len, "PCI (%s MHz)",
618 pci_bus_modes[pci_bus >> 3]);
620 snprintf(str, str_len, "PCI-X Mode %d (%s MHz)",
622 pci_bus_modes[pci_bus & 3]);
628 qla2x00_fw_version_str(struct scsi_qla_host *vha, char *str, size_t size)
631 struct qla_hw_data *ha = vha->hw;
633 snprintf(str, size, "%d.%02d.%02d ", ha->fw_major_version,
634 ha->fw_minor_version, ha->fw_subminor_version);
636 if (ha->fw_attributes & BIT_9) {
641 switch (ha->fw_attributes & 0xFF) {
655 sprintf(un_str, "(%x)", ha->fw_attributes);
659 if (ha->fw_attributes & 0x100)
666 qla24xx_fw_version_str(struct scsi_qla_host *vha, char *str, size_t size)
668 struct qla_hw_data *ha = vha->hw;
670 snprintf(str, size, "%d.%02d.%02d (%x)", ha->fw_major_version,
671 ha->fw_minor_version, ha->fw_subminor_version, ha->fw_attributes);
675 void qla2x00_sp_free_dma(srb_t *sp)
677 struct qla_hw_data *ha = sp->vha->hw;
678 struct scsi_cmnd *cmd = GET_CMD_SP(sp);
680 if (sp->flags & SRB_DMA_VALID) {
682 sp->flags &= ~SRB_DMA_VALID;
685 if (sp->flags & SRB_CRC_PROT_DMA_VALID) {
686 dma_unmap_sg(&ha->pdev->dev, scsi_prot_sglist(cmd),
687 scsi_prot_sg_count(cmd), cmd->sc_data_direction);
688 sp->flags &= ~SRB_CRC_PROT_DMA_VALID;
691 if (sp->flags & SRB_CRC_CTX_DSD_VALID) {
692 /* List assured to be having elements */
693 qla2x00_clean_dsd_pool(ha, sp->u.scmd.crc_ctx);
694 sp->flags &= ~SRB_CRC_CTX_DSD_VALID;
697 if (sp->flags & SRB_CRC_CTX_DMA_VALID) {
698 struct crc_context *ctx0 = sp->u.scmd.crc_ctx;
700 dma_pool_free(ha->dl_dma_pool, ctx0, ctx0->crc_ctx_dma);
701 sp->flags &= ~SRB_CRC_CTX_DMA_VALID;
704 if (sp->flags & SRB_FCP_CMND_DMA_VALID) {
705 struct ct6_dsd *ctx1 = sp->u.scmd.ct6_ctx;
707 dma_pool_free(ha->fcp_cmnd_dma_pool, ctx1->fcp_cmnd,
709 list_splice(&ctx1->dsd_list, &ha->gbl_dsd_list);
710 ha->gbl_dsd_inuse -= ctx1->dsd_use_cnt;
711 ha->gbl_dsd_avail += ctx1->dsd_use_cnt;
712 mempool_free(ctx1, ha->ctx_mempool);
716 void qla2x00_sp_compl(srb_t *sp, int res)
718 struct scsi_cmnd *cmd = GET_CMD_SP(sp);
719 struct completion *comp = sp->comp;
729 void qla2xxx_qpair_sp_free_dma(srb_t *sp)
731 struct scsi_cmnd *cmd = GET_CMD_SP(sp);
732 struct qla_hw_data *ha = sp->fcport->vha->hw;
734 if (sp->flags & SRB_DMA_VALID) {
736 sp->flags &= ~SRB_DMA_VALID;
739 if (sp->flags & SRB_CRC_PROT_DMA_VALID) {
740 dma_unmap_sg(&ha->pdev->dev, scsi_prot_sglist(cmd),
741 scsi_prot_sg_count(cmd), cmd->sc_data_direction);
742 sp->flags &= ~SRB_CRC_PROT_DMA_VALID;
745 if (sp->flags & SRB_CRC_CTX_DSD_VALID) {
746 /* List assured to be having elements */
747 qla2x00_clean_dsd_pool(ha, sp->u.scmd.crc_ctx);
748 sp->flags &= ~SRB_CRC_CTX_DSD_VALID;
751 if (sp->flags & SRB_DIF_BUNDL_DMA_VALID) {
752 struct crc_context *difctx = sp->u.scmd.crc_ctx;
753 struct dsd_dma *dif_dsd, *nxt_dsd;
755 list_for_each_entry_safe(dif_dsd, nxt_dsd,
756 &difctx->ldif_dma_hndl_list, list) {
757 list_del(&dif_dsd->list);
758 dma_pool_free(ha->dif_bundl_pool, dif_dsd->dsd_addr,
759 dif_dsd->dsd_list_dma);
761 difctx->no_dif_bundl--;
764 list_for_each_entry_safe(dif_dsd, nxt_dsd,
765 &difctx->ldif_dsd_list, list) {
766 list_del(&dif_dsd->list);
767 dma_pool_free(ha->dl_dma_pool, dif_dsd->dsd_addr,
768 dif_dsd->dsd_list_dma);
770 difctx->no_ldif_dsd--;
773 if (difctx->no_ldif_dsd) {
774 ql_dbg(ql_dbg_tgt+ql_dbg_verbose, sp->vha, 0xe022,
775 "%s: difctx->no_ldif_dsd=%x\n",
776 __func__, difctx->no_ldif_dsd);
779 if (difctx->no_dif_bundl) {
780 ql_dbg(ql_dbg_tgt+ql_dbg_verbose, sp->vha, 0xe022,
781 "%s: difctx->no_dif_bundl=%x\n",
782 __func__, difctx->no_dif_bundl);
784 sp->flags &= ~SRB_DIF_BUNDL_DMA_VALID;
787 if (sp->flags & SRB_FCP_CMND_DMA_VALID) {
788 struct ct6_dsd *ctx1 = sp->u.scmd.ct6_ctx;
790 dma_pool_free(ha->fcp_cmnd_dma_pool, ctx1->fcp_cmnd,
792 list_splice(&ctx1->dsd_list, &ha->gbl_dsd_list);
793 ha->gbl_dsd_inuse -= ctx1->dsd_use_cnt;
794 ha->gbl_dsd_avail += ctx1->dsd_use_cnt;
795 mempool_free(ctx1, ha->ctx_mempool);
796 sp->flags &= ~SRB_FCP_CMND_DMA_VALID;
799 if (sp->flags & SRB_CRC_CTX_DMA_VALID) {
800 struct crc_context *ctx0 = sp->u.scmd.crc_ctx;
802 dma_pool_free(ha->dl_dma_pool, ctx0, ctx0->crc_ctx_dma);
803 sp->flags &= ~SRB_CRC_CTX_DMA_VALID;
807 void qla2xxx_qpair_sp_compl(srb_t *sp, int res)
809 struct scsi_cmnd *cmd = GET_CMD_SP(sp);
810 struct completion *comp = sp->comp;
821 qla2xxx_queuecommand(struct Scsi_Host *host, struct scsi_cmnd *cmd)
823 scsi_qla_host_t *vha = shost_priv(host);
824 fc_port_t *fcport = (struct fc_port *) cmd->device->hostdata;
825 struct fc_rport *rport = starget_to_rport(scsi_target(cmd->device));
826 struct qla_hw_data *ha = vha->hw;
827 struct scsi_qla_host *base_vha = pci_get_drvdata(ha->pdev);
831 if (unlikely(test_bit(UNLOADING, &base_vha->dpc_flags)) ||
832 WARN_ON_ONCE(!rport)) {
833 cmd->result = DID_NO_CONNECT << 16;
834 goto qc24_fail_command;
840 struct qla_qpair *qpair = NULL;
842 tag = blk_mq_unique_tag(scsi_cmd_to_rq(cmd));
843 hwq = blk_mq_unique_tag_to_hwq(tag);
844 qpair = ha->queue_pair_map[hwq];
847 return qla2xxx_mqueuecommand(host, cmd, qpair);
850 if (ha->flags.eeh_busy) {
851 if (ha->flags.pci_channel_io_perm_failure) {
852 ql_dbg(ql_dbg_aer, vha, 0x9010,
853 "PCI Channel IO permanent failure, exiting "
855 cmd->result = DID_NO_CONNECT << 16;
857 ql_dbg(ql_dbg_aer, vha, 0x9011,
858 "EEH_Busy, Requeuing the cmd=%p.\n", cmd);
859 cmd->result = DID_REQUEUE << 16;
861 goto qc24_fail_command;
864 rval = fc_remote_port_chkready(rport);
867 ql_dbg(ql_dbg_io + ql_dbg_verbose, vha, 0x3003,
868 "fc_remote_port_chkready failed for cmd=%p, rval=0x%x.\n",
870 goto qc24_fail_command;
873 if (!vha->flags.difdix_supported &&
874 scsi_get_prot_op(cmd) != SCSI_PROT_NORMAL) {
875 ql_dbg(ql_dbg_io, vha, 0x3004,
876 "DIF Cap not reg, fail DIF capable cmd's:%p.\n",
878 cmd->result = DID_NO_CONNECT << 16;
879 goto qc24_fail_command;
882 if (!fcport || fcport->deleted) {
883 cmd->result = DID_IMM_RETRY << 16;
884 goto qc24_fail_command;
887 if (atomic_read(&fcport->state) != FCS_ONLINE || fcport->deleted) {
888 if (atomic_read(&fcport->state) == FCS_DEVICE_DEAD ||
889 atomic_read(&base_vha->loop_state) == LOOP_DEAD) {
890 ql_dbg(ql_dbg_io, vha, 0x3005,
891 "Returning DNC, fcport_state=%d loop_state=%d.\n",
892 atomic_read(&fcport->state),
893 atomic_read(&base_vha->loop_state));
894 cmd->result = DID_NO_CONNECT << 16;
895 goto qc24_fail_command;
897 goto qc24_target_busy;
901 * Return target busy if we've received a non-zero retry_delay_timer
904 if (fcport->retry_delay_timestamp == 0) {
905 /* retry delay not set */
906 } else if (time_after(jiffies, fcport->retry_delay_timestamp))
907 fcport->retry_delay_timestamp = 0;
909 goto qc24_target_busy;
911 sp = scsi_cmd_priv(cmd);
912 qla2xxx_init_sp(sp, vha, vha->hw->base_qpair, fcport);
914 sp->u.scmd.cmd = cmd;
915 sp->type = SRB_SCSI_CMD;
917 CMD_SP(cmd) = (void *)sp;
918 sp->free = qla2x00_sp_free_dma;
919 sp->done = qla2x00_sp_compl;
921 rval = ha->isp_ops->start_scsi(sp);
922 if (rval != QLA_SUCCESS) {
923 ql_dbg(ql_dbg_io + ql_dbg_verbose, vha, 0x3013,
924 "Start scsi failed rval=%d for cmd=%p.\n", rval, cmd);
925 goto qc24_host_busy_free_sp;
930 qc24_host_busy_free_sp:
934 return SCSI_MLQUEUE_TARGET_BUSY;
942 /* For MQ supported I/O */
944 qla2xxx_mqueuecommand(struct Scsi_Host *host, struct scsi_cmnd *cmd,
945 struct qla_qpair *qpair)
947 scsi_qla_host_t *vha = shost_priv(host);
948 fc_port_t *fcport = (struct fc_port *) cmd->device->hostdata;
949 struct fc_rport *rport = starget_to_rport(scsi_target(cmd->device));
950 struct qla_hw_data *ha = vha->hw;
951 struct scsi_qla_host *base_vha = pci_get_drvdata(ha->pdev);
955 rval = rport ? fc_remote_port_chkready(rport) : FC_PORTSTATE_OFFLINE;
958 ql_dbg(ql_dbg_io + ql_dbg_verbose, vha, 0x3076,
959 "fc_remote_port_chkready failed for cmd=%p, rval=0x%x.\n",
961 goto qc24_fail_command;
964 if (!qpair->online) {
965 ql_dbg(ql_dbg_io, vha, 0x3077,
966 "qpair not online. eeh_busy=%d.\n", ha->flags.eeh_busy);
967 cmd->result = DID_NO_CONNECT << 16;
968 goto qc24_fail_command;
971 if (!fcport || fcport->deleted) {
972 cmd->result = DID_IMM_RETRY << 16;
973 goto qc24_fail_command;
976 if (atomic_read(&fcport->state) != FCS_ONLINE || fcport->deleted) {
977 if (atomic_read(&fcport->state) == FCS_DEVICE_DEAD ||
978 atomic_read(&base_vha->loop_state) == LOOP_DEAD) {
979 ql_dbg(ql_dbg_io, vha, 0x3077,
980 "Returning DNC, fcport_state=%d loop_state=%d.\n",
981 atomic_read(&fcport->state),
982 atomic_read(&base_vha->loop_state));
983 cmd->result = DID_NO_CONNECT << 16;
984 goto qc24_fail_command;
986 goto qc24_target_busy;
990 * Return target busy if we've received a non-zero retry_delay_timer
993 if (fcport->retry_delay_timestamp == 0) {
994 /* retry delay not set */
995 } else if (time_after(jiffies, fcport->retry_delay_timestamp))
996 fcport->retry_delay_timestamp = 0;
998 goto qc24_target_busy;
1000 sp = scsi_cmd_priv(cmd);
1001 qla2xxx_init_sp(sp, vha, qpair, fcport);
1003 sp->u.scmd.cmd = cmd;
1004 sp->type = SRB_SCSI_CMD;
1005 CMD_SP(cmd) = (void *)sp;
1006 sp->free = qla2xxx_qpair_sp_free_dma;
1007 sp->done = qla2xxx_qpair_sp_compl;
1009 rval = ha->isp_ops->start_scsi_mq(sp);
1010 if (rval != QLA_SUCCESS) {
1011 ql_dbg(ql_dbg_io + ql_dbg_verbose, vha, 0x3078,
1012 "Start scsi failed rval=%d for cmd=%p.\n", rval, cmd);
1013 goto qc24_host_busy_free_sp;
1018 qc24_host_busy_free_sp:
1022 return SCSI_MLQUEUE_TARGET_BUSY;
1025 cmd->scsi_done(cmd);
1031 * qla2x00_eh_wait_on_command
1032 * Waits for the command to be returned by the Firmware for some
1036 * cmd = Scsi Command to wait on.
1039 * Completed in time : QLA_SUCCESS
1040 * Did not complete in time : QLA_FUNCTION_FAILED
1043 qla2x00_eh_wait_on_command(struct scsi_cmnd *cmd)
1045 #define ABORT_POLLING_PERIOD 1000
1046 #define ABORT_WAIT_ITER ((2 * 1000) / (ABORT_POLLING_PERIOD))
1047 unsigned long wait_iter = ABORT_WAIT_ITER;
1048 scsi_qla_host_t *vha = shost_priv(cmd->device->host);
1049 struct qla_hw_data *ha = vha->hw;
1050 int ret = QLA_SUCCESS;
1052 if (unlikely(pci_channel_offline(ha->pdev)) || ha->flags.eeh_busy) {
1053 ql_dbg(ql_dbg_taskm, vha, 0x8005,
1054 "Return:eh_wait.\n");
1058 while (CMD_SP(cmd) && wait_iter--) {
1059 msleep(ABORT_POLLING_PERIOD);
1062 ret = QLA_FUNCTION_FAILED;
1068 * qla2x00_wait_for_hba_online
1069 * Wait till the HBA is online after going through
1070 * <= MAX_RETRIES_OF_ISP_ABORT or
1071 * finally HBA is disabled ie marked offline
1074 * ha - pointer to host adapter structure
1077 * Does context switching-Release SPIN_LOCK
1078 * (if any) before calling this routine.
1081 * Success (Adapter is online) : 0
1082 * Failed (Adapter is offline/disabled) : 1
1085 qla2x00_wait_for_hba_online(scsi_qla_host_t *vha)
1088 unsigned long wait_online;
1089 struct qla_hw_data *ha = vha->hw;
1090 scsi_qla_host_t *base_vha = pci_get_drvdata(ha->pdev);
1092 wait_online = jiffies + (MAX_LOOP_TIMEOUT * HZ);
1093 while (((test_bit(ISP_ABORT_NEEDED, &base_vha->dpc_flags)) ||
1094 test_bit(ABORT_ISP_ACTIVE, &base_vha->dpc_flags) ||
1095 test_bit(ISP_ABORT_RETRY, &base_vha->dpc_flags) ||
1096 ha->dpc_active) && time_before(jiffies, wait_online)) {
1100 if (base_vha->flags.online)
1101 return_status = QLA_SUCCESS;
1103 return_status = QLA_FUNCTION_FAILED;
1105 return (return_status);
1108 static inline int test_fcport_count(scsi_qla_host_t *vha)
1110 struct qla_hw_data *ha = vha->hw;
1111 unsigned long flags;
1114 spin_lock_irqsave(&ha->tgt.sess_lock, flags);
1115 ql_dbg(ql_dbg_init, vha, 0x00ec,
1116 "tgt %p, fcport_count=%d\n",
1117 vha, vha->fcport_count);
1118 res = (vha->fcport_count == 0);
1119 spin_unlock_irqrestore(&ha->tgt.sess_lock, flags);
1125 * qla2x00_wait_for_sess_deletion can only be called from remove_one.
1126 * it has dependency on UNLOADING flag to stop device discovery
1129 qla2x00_wait_for_sess_deletion(scsi_qla_host_t *vha)
1133 qla2x00_mark_all_devices_lost(vha);
1135 for (i = 0; i < 10; i++) {
1136 if (wait_event_timeout(vha->fcport_waitQ,
1137 test_fcport_count(vha), HZ) > 0)
1141 flush_workqueue(vha->hw->wq);
1145 * qla2x00_wait_for_hba_ready
1146 * Wait till the HBA is ready before doing driver unload
1149 * ha - pointer to host adapter structure
1152 * Does context switching-Release SPIN_LOCK
1153 * (if any) before calling this routine.
1157 qla2x00_wait_for_hba_ready(scsi_qla_host_t *vha)
1159 struct qla_hw_data *ha = vha->hw;
1160 scsi_qla_host_t *base_vha = pci_get_drvdata(ha->pdev);
1162 while ((qla2x00_reset_active(vha) || ha->dpc_active ||
1163 ha->flags.mbox_busy) ||
1164 test_bit(FX00_RESET_RECOVERY, &vha->dpc_flags) ||
1165 test_bit(FX00_TARGET_SCAN, &vha->dpc_flags)) {
1166 if (test_bit(UNLOADING, &base_vha->dpc_flags))
1173 qla2x00_wait_for_chip_reset(scsi_qla_host_t *vha)
1176 unsigned long wait_reset;
1177 struct qla_hw_data *ha = vha->hw;
1178 scsi_qla_host_t *base_vha = pci_get_drvdata(ha->pdev);
1180 wait_reset = jiffies + (MAX_LOOP_TIMEOUT * HZ);
1181 while (((test_bit(ISP_ABORT_NEEDED, &base_vha->dpc_flags)) ||
1182 test_bit(ABORT_ISP_ACTIVE, &base_vha->dpc_flags) ||
1183 test_bit(ISP_ABORT_RETRY, &base_vha->dpc_flags) ||
1184 ha->dpc_active) && time_before(jiffies, wait_reset)) {
1188 if (!test_bit(ISP_ABORT_NEEDED, &base_vha->dpc_flags) &&
1189 ha->flags.chip_reset_done)
1192 if (ha->flags.chip_reset_done)
1193 return_status = QLA_SUCCESS;
1195 return_status = QLA_FUNCTION_FAILED;
1197 return return_status;
1200 /**************************************************************************
1204 * The abort function will abort the specified command.
1207 * cmd = Linux SCSI command packet to be aborted.
1210 * Either SUCCESS or FAILED.
1213 * Only return FAILED if command not returned by firmware.
1214 **************************************************************************/
1216 qla2xxx_eh_abort(struct scsi_cmnd *cmd)
1218 scsi_qla_host_t *vha = shost_priv(cmd->device->host);
1219 DECLARE_COMPLETION_ONSTACK(comp);
1225 struct qla_hw_data *ha = vha->hw;
1227 struct qla_qpair *qpair;
1228 unsigned long flags;
1229 int fast_fail_status = SUCCESS;
1231 if (qla2x00_isp_reg_stat(ha)) {
1232 ql_log(ql_log_info, vha, 0x8042,
1233 "PCI/Register disconnect, exiting.\n");
1234 qla_pci_set_eeh_busy(vha);
1238 /* Save any FAST_IO_FAIL value to return later if abort succeeds */
1239 ret = fc_block_scsi_eh(cmd);
1241 fast_fail_status = ret;
1243 sp = scsi_cmd_priv(cmd);
1246 if ((sp->fcport && sp->fcport->deleted) || !qpair)
1247 return fast_fail_status != SUCCESS ? fast_fail_status : FAILED;
1249 spin_lock_irqsave(qpair->qp_lock_ptr, flags);
1251 spin_unlock_irqrestore(qpair->qp_lock_ptr, flags);
1254 id = cmd->device->id;
1255 lun = cmd->device->lun;
1257 ql_dbg(ql_dbg_taskm, vha, 0x8002,
1258 "Aborting from RISC nexus=%ld:%d:%llu sp=%p cmd=%p handle=%x\n",
1259 vha->host_no, id, lun, sp, cmd, sp->handle);
1262 * Abort will release the original Command/sp from FW. Let the
1263 * original command call scsi_done. In return, he will wakeup
1264 * this sleeping thread.
1266 rval = ha->isp_ops->abort_command(sp);
1268 ql_dbg(ql_dbg_taskm, vha, 0x8003,
1269 "Abort command mbx cmd=%p, rval=%x.\n", cmd, rval);
1271 /* Wait for the command completion. */
1272 ratov_j = ha->r_a_tov/10 * 4 * 1000;
1273 ratov_j = msecs_to_jiffies(ratov_j);
1276 if (!wait_for_completion_timeout(&comp, ratov_j)) {
1277 ql_dbg(ql_dbg_taskm, vha, 0xffff,
1278 "%s: Abort wait timer (4 * R_A_TOV[%d]) expired\n",
1279 __func__, ha->r_a_tov/10);
1282 ret = fast_fail_status;
1292 ql_log(ql_log_info, vha, 0x801c,
1293 "Abort command issued nexus=%ld:%d:%llu -- %x.\n",
1294 vha->host_no, id, lun, ret);
1300 * Returns: QLA_SUCCESS or QLA_FUNCTION_FAILED.
1303 qla2x00_eh_wait_for_pending_commands(scsi_qla_host_t *vha, unsigned int t,
1304 uint64_t l, enum nexus_wait_type type)
1306 int cnt, match, status;
1307 unsigned long flags;
1308 struct qla_hw_data *ha = vha->hw;
1309 struct req_que *req;
1311 struct scsi_cmnd *cmd;
1313 status = QLA_SUCCESS;
1315 spin_lock_irqsave(&ha->hardware_lock, flags);
1317 for (cnt = 1; status == QLA_SUCCESS &&
1318 cnt < req->num_outstanding_cmds; cnt++) {
1319 sp = req->outstanding_cmds[cnt];
1322 if (sp->type != SRB_SCSI_CMD)
1324 if (vha->vp_idx != sp->vha->vp_idx)
1327 cmd = GET_CMD_SP(sp);
1333 match = cmd->device->id == t;
1336 match = (cmd->device->id == t &&
1337 cmd->device->lun == l);
1343 spin_unlock_irqrestore(&ha->hardware_lock, flags);
1344 status = qla2x00_eh_wait_on_command(cmd);
1345 spin_lock_irqsave(&ha->hardware_lock, flags);
1347 spin_unlock_irqrestore(&ha->hardware_lock, flags);
1352 static char *reset_errors[] = {
1355 "Task management failed",
1356 "Waiting for command completions",
1360 __qla2xxx_eh_generic_reset(char *name, enum nexus_wait_type type,
1361 struct scsi_cmnd *cmd, int (*do_reset)(struct fc_port *, uint64_t, int))
1363 scsi_qla_host_t *vha = shost_priv(cmd->device->host);
1364 fc_port_t *fcport = (struct fc_port *) cmd->device->hostdata;
1371 err = fc_block_scsi_eh(cmd);
1375 if (fcport->deleted)
1378 ql_log(ql_log_info, vha, 0x8009,
1379 "%s RESET ISSUED nexus=%ld:%d:%llu cmd=%p.\n", name, vha->host_no,
1380 cmd->device->id, cmd->device->lun, cmd);
1383 if (qla2x00_wait_for_hba_online(vha) != QLA_SUCCESS) {
1384 ql_log(ql_log_warn, vha, 0x800a,
1385 "Wait for hba online failed for cmd=%p.\n", cmd);
1386 goto eh_reset_failed;
1389 if (do_reset(fcport, cmd->device->lun, 1)
1391 ql_log(ql_log_warn, vha, 0x800c,
1392 "do_reset failed for cmd=%p.\n", cmd);
1393 goto eh_reset_failed;
1396 if (qla2x00_eh_wait_for_pending_commands(vha, cmd->device->id,
1397 cmd->device->lun, type) != QLA_SUCCESS) {
1398 ql_log(ql_log_warn, vha, 0x800d,
1399 "wait for pending cmds failed for cmd=%p.\n", cmd);
1400 goto eh_reset_failed;
1403 ql_log(ql_log_info, vha, 0x800e,
1404 "%s RESET SUCCEEDED nexus:%ld:%d:%llu cmd=%p.\n", name,
1405 vha->host_no, cmd->device->id, cmd->device->lun, cmd);
1410 ql_log(ql_log_info, vha, 0x800f,
1411 "%s RESET FAILED: %s nexus=%ld:%d:%llu cmd=%p.\n", name,
1412 reset_errors[err], vha->host_no, cmd->device->id, cmd->device->lun,
1418 qla2xxx_eh_device_reset(struct scsi_cmnd *cmd)
1420 scsi_qla_host_t *vha = shost_priv(cmd->device->host);
1421 struct qla_hw_data *ha = vha->hw;
1423 if (qla2x00_isp_reg_stat(ha)) {
1424 ql_log(ql_log_info, vha, 0x803e,
1425 "PCI/Register disconnect, exiting.\n");
1426 qla_pci_set_eeh_busy(vha);
1430 return __qla2xxx_eh_generic_reset("DEVICE", WAIT_LUN, cmd,
1431 ha->isp_ops->lun_reset);
1435 qla2xxx_eh_target_reset(struct scsi_cmnd *cmd)
1437 scsi_qla_host_t *vha = shost_priv(cmd->device->host);
1438 struct qla_hw_data *ha = vha->hw;
1440 if (qla2x00_isp_reg_stat(ha)) {
1441 ql_log(ql_log_info, vha, 0x803f,
1442 "PCI/Register disconnect, exiting.\n");
1443 qla_pci_set_eeh_busy(vha);
1447 return __qla2xxx_eh_generic_reset("TARGET", WAIT_TARGET, cmd,
1448 ha->isp_ops->target_reset);
1451 /**************************************************************************
1452 * qla2xxx_eh_bus_reset
1455 * The bus reset function will reset the bus and abort any executing
1459 * cmd = Linux SCSI command packet of the command that cause the
1463 * SUCCESS/FAILURE (defined as macro in scsi.h).
1465 **************************************************************************/
1467 qla2xxx_eh_bus_reset(struct scsi_cmnd *cmd)
1469 scsi_qla_host_t *vha = shost_priv(cmd->device->host);
1470 fc_port_t *fcport = (struct fc_port *) cmd->device->hostdata;
1474 struct qla_hw_data *ha = vha->hw;
1476 if (qla2x00_isp_reg_stat(ha)) {
1477 ql_log(ql_log_info, vha, 0x8040,
1478 "PCI/Register disconnect, exiting.\n");
1479 qla_pci_set_eeh_busy(vha);
1483 id = cmd->device->id;
1484 lun = cmd->device->lun;
1490 ret = fc_block_scsi_eh(cmd);
1495 if (qla2x00_chip_is_down(vha))
1498 ql_log(ql_log_info, vha, 0x8012,
1499 "BUS RESET ISSUED nexus=%ld:%d:%llu.\n", vha->host_no, id, lun);
1501 if (qla2x00_wait_for_hba_online(vha) != QLA_SUCCESS) {
1502 ql_log(ql_log_fatal, vha, 0x8013,
1503 "Wait for hba online failed board disabled.\n");
1504 goto eh_bus_reset_done;
1507 if (qla2x00_loop_reset(vha) == QLA_SUCCESS)
1511 goto eh_bus_reset_done;
1513 /* Flush outstanding commands. */
1514 if (qla2x00_eh_wait_for_pending_commands(vha, 0, 0, WAIT_HOST) !=
1516 ql_log(ql_log_warn, vha, 0x8014,
1517 "Wait for pending commands failed.\n");
1522 ql_log(ql_log_warn, vha, 0x802b,
1523 "BUS RESET %s nexus=%ld:%d:%llu.\n",
1524 (ret == FAILED) ? "FAILED" : "SUCCEEDED", vha->host_no, id, lun);
1529 /**************************************************************************
1530 * qla2xxx_eh_host_reset
1533 * The reset function will reset the Adapter.
1536 * cmd = Linux SCSI command packet of the command that cause the
1540 * Either SUCCESS or FAILED.
1543 **************************************************************************/
1545 qla2xxx_eh_host_reset(struct scsi_cmnd *cmd)
1547 scsi_qla_host_t *vha = shost_priv(cmd->device->host);
1548 struct qla_hw_data *ha = vha->hw;
1552 scsi_qla_host_t *base_vha = pci_get_drvdata(ha->pdev);
1554 if (qla2x00_isp_reg_stat(ha)) {
1555 ql_log(ql_log_info, vha, 0x8041,
1556 "PCI/Register disconnect, exiting.\n");
1557 qla_pci_set_eeh_busy(vha);
1561 id = cmd->device->id;
1562 lun = cmd->device->lun;
1564 ql_log(ql_log_info, vha, 0x8018,
1565 "ADAPTER RESET ISSUED nexus=%ld:%d:%llu.\n", vha->host_no, id, lun);
1568 * No point in issuing another reset if one is active. Also do not
1569 * attempt a reset if we are updating flash.
1571 if (qla2x00_reset_active(vha) || ha->optrom_state != QLA_SWAITING)
1572 goto eh_host_reset_lock;
1574 if (vha != base_vha) {
1575 if (qla2x00_vp_abort_isp(vha))
1576 goto eh_host_reset_lock;
1578 if (IS_P3P_TYPE(vha->hw)) {
1579 if (!qla82xx_fcoe_ctx_reset(vha)) {
1580 /* Ctx reset success */
1582 goto eh_host_reset_lock;
1584 /* fall thru if ctx reset failed */
1587 flush_workqueue(ha->wq);
1589 set_bit(ABORT_ISP_ACTIVE, &base_vha->dpc_flags);
1590 if (ha->isp_ops->abort_isp(base_vha)) {
1591 clear_bit(ABORT_ISP_ACTIVE, &base_vha->dpc_flags);
1592 /* failed. schedule dpc to try */
1593 set_bit(ISP_ABORT_NEEDED, &base_vha->dpc_flags);
1595 if (qla2x00_wait_for_hba_online(vha) != QLA_SUCCESS) {
1596 ql_log(ql_log_warn, vha, 0x802a,
1597 "wait for hba online failed.\n");
1598 goto eh_host_reset_lock;
1601 clear_bit(ABORT_ISP_ACTIVE, &base_vha->dpc_flags);
1604 /* Waiting for command to be returned to OS.*/
1605 if (qla2x00_eh_wait_for_pending_commands(vha, 0, 0, WAIT_HOST) ==
1610 ql_log(ql_log_info, vha, 0x8017,
1611 "ADAPTER RESET %s nexus=%ld:%d:%llu.\n",
1612 (ret == FAILED) ? "FAILED" : "SUCCEEDED", vha->host_no, id, lun);
1618 * qla2x00_loop_reset
1622 * ha = adapter block pointer.
1628 qla2x00_loop_reset(scsi_qla_host_t *vha)
1631 struct qla_hw_data *ha = vha->hw;
1636 if (ha->flags.enable_lip_full_login && !IS_CNA_CAPABLE(ha)) {
1637 atomic_set(&vha->loop_state, LOOP_DOWN);
1638 atomic_set(&vha->loop_down_timer, LOOP_DOWN_TIME);
1639 qla2x00_mark_all_devices_lost(vha);
1640 ret = qla2x00_full_login_lip(vha);
1641 if (ret != QLA_SUCCESS) {
1642 ql_dbg(ql_dbg_taskm, vha, 0x802d,
1643 "full_login_lip=%d.\n", ret);
1647 if (ha->flags.enable_lip_reset) {
1648 ret = qla2x00_lip_reset(vha);
1649 if (ret != QLA_SUCCESS)
1650 ql_dbg(ql_dbg_taskm, vha, 0x802e,
1651 "lip_reset failed (%d).\n", ret);
1654 /* Issue marker command only when we are going to start the I/O */
1655 vha->marker_needed = 1;
1661 * The caller must ensure that no completion interrupts will happen
1662 * while this function is in progress.
1664 static void qla2x00_abort_srb(struct qla_qpair *qp, srb_t *sp, const int res,
1665 unsigned long *flags)
1666 __releases(qp->qp_lock_ptr)
1667 __acquires(qp->qp_lock_ptr)
1669 DECLARE_COMPLETION_ONSTACK(comp);
1670 scsi_qla_host_t *vha = qp->vha;
1671 struct qla_hw_data *ha = vha->hw;
1672 struct scsi_cmnd *cmd = GET_CMD_SP(sp);
1677 lockdep_assert_held(qp->qp_lock_ptr);
1679 if (qla2x00_chip_is_down(vha)) {
1684 if (sp->type == SRB_NVME_CMD || sp->type == SRB_NVME_LS ||
1685 (sp->type == SRB_SCSI_CMD && !ha->flags.eeh_busy &&
1686 !test_bit(ABORT_ISP_ACTIVE, &vha->dpc_flags) &&
1687 !qla2x00_isp_reg_stat(ha))) {
1694 spin_unlock_irqrestore(qp->qp_lock_ptr, *flags);
1696 rval = ha->isp_ops->abort_command(sp);
1697 /* Wait for command completion. */
1699 ratov_j = ha->r_a_tov/10 * 4 * 1000;
1700 ratov_j = msecs_to_jiffies(ratov_j);
1703 if (wait_for_completion_timeout(&comp, ratov_j)) {
1704 ql_dbg(ql_dbg_taskm, vha, 0xffff,
1705 "%s: Abort wait timer (4 * R_A_TOV[%d]) expired\n",
1706 __func__, ha->r_a_tov/10);
1709 /* else FW return SP to driver */
1716 spin_lock_irqsave(qp->qp_lock_ptr, *flags);
1719 if (ret_cmd && blk_mq_request_started(scsi_cmd_to_rq(cmd)))
1733 * The caller must ensure that no completion interrupts will happen
1734 * while this function is in progress.
1737 __qla2x00_abort_all_cmds(struct qla_qpair *qp, int res)
1740 unsigned long flags;
1742 scsi_qla_host_t *vha = qp->vha;
1743 struct qla_hw_data *ha = vha->hw;
1744 struct req_que *req;
1745 struct qla_tgt *tgt = vha->vha_tgt.qla_tgt;
1746 struct qla_tgt_cmd *cmd;
1750 spin_lock_irqsave(qp->qp_lock_ptr, flags);
1752 for (cnt = 1; cnt < req->num_outstanding_cmds; cnt++) {
1753 sp = req->outstanding_cmds[cnt];
1756 * perform lockless completion during driver unload
1758 if (qla2x00_chip_is_down(vha)) {
1759 req->outstanding_cmds[cnt] = NULL;
1760 spin_unlock_irqrestore(qp->qp_lock_ptr, flags);
1762 spin_lock_irqsave(qp->qp_lock_ptr, flags);
1766 switch (sp->cmd_type) {
1768 qla2x00_abort_srb(qp, sp, res, &flags);
1771 if (!vha->hw->tgt.tgt_ops || !tgt ||
1772 qla_ini_mode_enabled(vha)) {
1773 ql_dbg(ql_dbg_tgt_mgt, vha, 0xf003,
1774 "HOST-ABORT-HNDLR: dpc_flags=%lx. Target mode disabled\n",
1778 cmd = (struct qla_tgt_cmd *)sp;
1781 case TYPE_TGT_TMCMD:
1782 /* Skip task management functions. */
1787 req->outstanding_cmds[cnt] = NULL;
1790 spin_unlock_irqrestore(qp->qp_lock_ptr, flags);
1794 * The caller must ensure that no completion interrupts will happen
1795 * while this function is in progress.
1798 qla2x00_abort_all_cmds(scsi_qla_host_t *vha, int res)
1801 struct qla_hw_data *ha = vha->hw;
1803 /* Continue only if initialization complete. */
1804 if (!ha->base_qpair)
1806 __qla2x00_abort_all_cmds(ha->base_qpair, res);
1808 if (!ha->queue_pair_map)
1810 for (que = 0; que < ha->max_qpairs; que++) {
1811 if (!ha->queue_pair_map[que])
1814 __qla2x00_abort_all_cmds(ha->queue_pair_map[que], res);
1819 qla2xxx_slave_alloc(struct scsi_device *sdev)
1821 struct fc_rport *rport = starget_to_rport(scsi_target(sdev));
1823 if (!rport || fc_remote_port_chkready(rport))
1826 sdev->hostdata = *(fc_port_t **)rport->dd_data;
1832 qla2xxx_slave_configure(struct scsi_device *sdev)
1834 scsi_qla_host_t *vha = shost_priv(sdev->host);
1835 struct req_que *req = vha->req;
1837 if (IS_T10_PI_CAPABLE(vha->hw))
1838 blk_queue_update_dma_alignment(sdev->request_queue, 0x7);
1840 scsi_change_queue_depth(sdev, req->max_q_depth);
1845 qla2xxx_slave_destroy(struct scsi_device *sdev)
1847 sdev->hostdata = NULL;
1851 * qla2x00_config_dma_addressing() - Configure OS DMA addressing method.
1854 * At exit, the @ha's flags.enable_64bit_addressing set to indicated
1855 * supported addressing method.
1858 qla2x00_config_dma_addressing(struct qla_hw_data *ha)
1860 /* Assume a 32bit DMA mask. */
1861 ha->flags.enable_64bit_addressing = 0;
1863 if (!dma_set_mask(&ha->pdev->dev, DMA_BIT_MASK(64))) {
1864 /* Any upper-dword bits set? */
1865 if (MSD(dma_get_required_mask(&ha->pdev->dev)) &&
1866 !dma_set_coherent_mask(&ha->pdev->dev, DMA_BIT_MASK(64))) {
1867 /* Ok, a 64bit DMA mask is applicable. */
1868 ha->flags.enable_64bit_addressing = 1;
1869 ha->isp_ops->calc_req_entries = qla2x00_calc_iocbs_64;
1870 ha->isp_ops->build_iocbs = qla2x00_build_scsi_iocbs_64;
1875 dma_set_mask(&ha->pdev->dev, DMA_BIT_MASK(32));
1876 dma_set_coherent_mask(&ha->pdev->dev, DMA_BIT_MASK(32));
1880 qla2x00_enable_intrs(struct qla_hw_data *ha)
1882 unsigned long flags = 0;
1883 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
1885 spin_lock_irqsave(&ha->hardware_lock, flags);
1886 ha->interrupts_on = 1;
1887 /* enable risc and host interrupts */
1888 wrt_reg_word(®->ictrl, ICR_EN_INT | ICR_EN_RISC);
1889 rd_reg_word(®->ictrl);
1890 spin_unlock_irqrestore(&ha->hardware_lock, flags);
1895 qla2x00_disable_intrs(struct qla_hw_data *ha)
1897 unsigned long flags = 0;
1898 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
1900 spin_lock_irqsave(&ha->hardware_lock, flags);
1901 ha->interrupts_on = 0;
1902 /* disable risc and host interrupts */
1903 wrt_reg_word(®->ictrl, 0);
1904 rd_reg_word(®->ictrl);
1905 spin_unlock_irqrestore(&ha->hardware_lock, flags);
1909 qla24xx_enable_intrs(struct qla_hw_data *ha)
1911 unsigned long flags = 0;
1912 struct device_reg_24xx __iomem *reg = &ha->iobase->isp24;
1914 spin_lock_irqsave(&ha->hardware_lock, flags);
1915 ha->interrupts_on = 1;
1916 wrt_reg_dword(®->ictrl, ICRX_EN_RISC_INT);
1917 rd_reg_dword(®->ictrl);
1918 spin_unlock_irqrestore(&ha->hardware_lock, flags);
1922 qla24xx_disable_intrs(struct qla_hw_data *ha)
1924 unsigned long flags = 0;
1925 struct device_reg_24xx __iomem *reg = &ha->iobase->isp24;
1927 if (IS_NOPOLLING_TYPE(ha))
1929 spin_lock_irqsave(&ha->hardware_lock, flags);
1930 ha->interrupts_on = 0;
1931 wrt_reg_dword(®->ictrl, 0);
1932 rd_reg_dword(®->ictrl);
1933 spin_unlock_irqrestore(&ha->hardware_lock, flags);
1937 qla2x00_iospace_config(struct qla_hw_data *ha)
1939 resource_size_t pio;
1942 if (pci_request_selected_regions(ha->pdev, ha->bars,
1943 QLA2XXX_DRIVER_NAME)) {
1944 ql_log_pci(ql_log_fatal, ha->pdev, 0x0011,
1945 "Failed to reserve PIO/MMIO regions (%s), aborting.\n",
1946 pci_name(ha->pdev));
1947 goto iospace_error_exit;
1949 if (!(ha->bars & 1))
1952 /* We only need PIO for Flash operations on ISP2312 v2 chips. */
1953 pio = pci_resource_start(ha->pdev, 0);
1954 if (pci_resource_flags(ha->pdev, 0) & IORESOURCE_IO) {
1955 if (pci_resource_len(ha->pdev, 0) < MIN_IOBASE_LEN) {
1956 ql_log_pci(ql_log_warn, ha->pdev, 0x0012,
1957 "Invalid pci I/O region size (%s).\n",
1958 pci_name(ha->pdev));
1962 ql_log_pci(ql_log_warn, ha->pdev, 0x0013,
1963 "Region #0 no a PIO resource (%s).\n",
1964 pci_name(ha->pdev));
1967 ha->pio_address = pio;
1968 ql_dbg_pci(ql_dbg_init, ha->pdev, 0x0014,
1969 "PIO address=%llu.\n",
1970 (unsigned long long)ha->pio_address);
1973 /* Use MMIO operations for all accesses. */
1974 if (!(pci_resource_flags(ha->pdev, 1) & IORESOURCE_MEM)) {
1975 ql_log_pci(ql_log_fatal, ha->pdev, 0x0015,
1976 "Region #1 not an MMIO resource (%s), aborting.\n",
1977 pci_name(ha->pdev));
1978 goto iospace_error_exit;
1980 if (pci_resource_len(ha->pdev, 1) < MIN_IOBASE_LEN) {
1981 ql_log_pci(ql_log_fatal, ha->pdev, 0x0016,
1982 "Invalid PCI mem region size (%s), aborting.\n",
1983 pci_name(ha->pdev));
1984 goto iospace_error_exit;
1987 ha->iobase = ioremap(pci_resource_start(ha->pdev, 1), MIN_IOBASE_LEN);
1989 ql_log_pci(ql_log_fatal, ha->pdev, 0x0017,
1990 "Cannot remap MMIO (%s), aborting.\n",
1991 pci_name(ha->pdev));
1992 goto iospace_error_exit;
1995 /* Determine queue resources */
1996 ha->max_req_queues = ha->max_rsp_queues = 1;
1997 ha->msix_count = QLA_BASE_VECTORS;
1999 /* Check if FW supports MQ or not */
2000 if (!(ha->fw_attributes & BIT_6))
2003 if (!ql2xmqsupport || !ql2xnvmeenable ||
2004 (!IS_QLA25XX(ha) && !IS_QLA81XX(ha)))
2007 ha->mqiobase = ioremap(pci_resource_start(ha->pdev, 3),
2008 pci_resource_len(ha->pdev, 3));
2010 ql_dbg_pci(ql_dbg_init, ha->pdev, 0x0018,
2011 "MQIO Base=%p.\n", ha->mqiobase);
2012 /* Read MSIX vector size of the board */
2013 pci_read_config_word(ha->pdev, QLA_PCI_MSIX_CONTROL, &msix);
2014 ha->msix_count = msix + 1;
2015 /* Max queues are bounded by available msix vectors */
2016 /* MB interrupt uses 1 vector */
2017 ha->max_req_queues = ha->msix_count - 1;
2018 ha->max_rsp_queues = ha->max_req_queues;
2019 /* Queue pairs is the max value minus the base queue pair */
2020 ha->max_qpairs = ha->max_rsp_queues - 1;
2021 ql_dbg_pci(ql_dbg_init, ha->pdev, 0x0188,
2022 "Max no of queues pairs: %d.\n", ha->max_qpairs);
2024 ql_log_pci(ql_log_info, ha->pdev, 0x001a,
2025 "MSI-X vector count: %d.\n", ha->msix_count);
2027 ql_log_pci(ql_log_info, ha->pdev, 0x001b,
2028 "BAR 3 not enabled.\n");
2031 ql_dbg_pci(ql_dbg_init, ha->pdev, 0x001c,
2032 "MSIX Count: %d.\n", ha->msix_count);
2041 qla83xx_iospace_config(struct qla_hw_data *ha)
2045 if (pci_request_selected_regions(ha->pdev, ha->bars,
2046 QLA2XXX_DRIVER_NAME)) {
2047 ql_log_pci(ql_log_fatal, ha->pdev, 0x0117,
2048 "Failed to reserve PIO/MMIO regions (%s), aborting.\n",
2049 pci_name(ha->pdev));
2051 goto iospace_error_exit;
2054 /* Use MMIO operations for all accesses. */
2055 if (!(pci_resource_flags(ha->pdev, 0) & IORESOURCE_MEM)) {
2056 ql_log_pci(ql_log_warn, ha->pdev, 0x0118,
2057 "Invalid pci I/O region size (%s).\n",
2058 pci_name(ha->pdev));
2059 goto iospace_error_exit;
2061 if (pci_resource_len(ha->pdev, 0) < MIN_IOBASE_LEN) {
2062 ql_log_pci(ql_log_warn, ha->pdev, 0x0119,
2063 "Invalid PCI mem region size (%s), aborting\n",
2064 pci_name(ha->pdev));
2065 goto iospace_error_exit;
2068 ha->iobase = ioremap(pci_resource_start(ha->pdev, 0), MIN_IOBASE_LEN);
2070 ql_log_pci(ql_log_fatal, ha->pdev, 0x011a,
2071 "Cannot remap MMIO (%s), aborting.\n",
2072 pci_name(ha->pdev));
2073 goto iospace_error_exit;
2076 /* 64bit PCI BAR - BAR2 will correspoond to region 4 */
2077 /* 83XX 26XX always use MQ type access for queues
2078 * - mbar 2, a.k.a region 4 */
2079 ha->max_req_queues = ha->max_rsp_queues = 1;
2080 ha->msix_count = QLA_BASE_VECTORS;
2081 ha->mqiobase = ioremap(pci_resource_start(ha->pdev, 4),
2082 pci_resource_len(ha->pdev, 4));
2084 if (!ha->mqiobase) {
2085 ql_log_pci(ql_log_fatal, ha->pdev, 0x011d,
2086 "BAR2/region4 not enabled\n");
2090 ha->msixbase = ioremap(pci_resource_start(ha->pdev, 2),
2091 pci_resource_len(ha->pdev, 2));
2093 /* Read MSIX vector size of the board */
2094 pci_read_config_word(ha->pdev,
2095 QLA_83XX_PCI_MSIX_CONTROL, &msix);
2096 ha->msix_count = (msix & PCI_MSIX_FLAGS_QSIZE) + 1;
2098 * By default, driver uses at least two msix vectors
2101 if (ql2xmqsupport || ql2xnvmeenable) {
2102 /* MB interrupt uses 1 vector */
2103 ha->max_req_queues = ha->msix_count - 1;
2105 /* ATIOQ needs 1 vector. That's 1 less QPair */
2106 if (QLA_TGT_MODE_ENABLED())
2107 ha->max_req_queues--;
2109 ha->max_rsp_queues = ha->max_req_queues;
2111 /* Queue pairs is the max value minus
2112 * the base queue pair */
2113 ha->max_qpairs = ha->max_req_queues - 1;
2114 ql_dbg_pci(ql_dbg_init, ha->pdev, 0x00e3,
2115 "Max no of queues pairs: %d.\n", ha->max_qpairs);
2117 ql_log_pci(ql_log_info, ha->pdev, 0x011c,
2118 "MSI-X vector count: %d.\n", ha->msix_count);
2120 ql_log_pci(ql_log_info, ha->pdev, 0x011e,
2121 "BAR 1 not enabled.\n");
2124 ql_dbg_pci(ql_dbg_init, ha->pdev, 0x011f,
2125 "MSIX Count: %d.\n", ha->msix_count);
2132 static struct isp_operations qla2100_isp_ops = {
2133 .pci_config = qla2100_pci_config,
2134 .reset_chip = qla2x00_reset_chip,
2135 .chip_diag = qla2x00_chip_diag,
2136 .config_rings = qla2x00_config_rings,
2137 .reset_adapter = qla2x00_reset_adapter,
2138 .nvram_config = qla2x00_nvram_config,
2139 .update_fw_options = qla2x00_update_fw_options,
2140 .load_risc = qla2x00_load_risc,
2141 .pci_info_str = qla2x00_pci_info_str,
2142 .fw_version_str = qla2x00_fw_version_str,
2143 .intr_handler = qla2100_intr_handler,
2144 .enable_intrs = qla2x00_enable_intrs,
2145 .disable_intrs = qla2x00_disable_intrs,
2146 .abort_command = qla2x00_abort_command,
2147 .target_reset = qla2x00_abort_target,
2148 .lun_reset = qla2x00_lun_reset,
2149 .fabric_login = qla2x00_login_fabric,
2150 .fabric_logout = qla2x00_fabric_logout,
2151 .calc_req_entries = qla2x00_calc_iocbs_32,
2152 .build_iocbs = qla2x00_build_scsi_iocbs_32,
2153 .prep_ms_iocb = qla2x00_prep_ms_iocb,
2154 .prep_ms_fdmi_iocb = qla2x00_prep_ms_fdmi_iocb,
2155 .read_nvram = qla2x00_read_nvram_data,
2156 .write_nvram = qla2x00_write_nvram_data,
2157 .fw_dump = qla2100_fw_dump,
2160 .beacon_blink = NULL,
2161 .read_optrom = qla2x00_read_optrom_data,
2162 .write_optrom = qla2x00_write_optrom_data,
2163 .get_flash_version = qla2x00_get_flash_version,
2164 .start_scsi = qla2x00_start_scsi,
2165 .start_scsi_mq = NULL,
2166 .abort_isp = qla2x00_abort_isp,
2167 .iospace_config = qla2x00_iospace_config,
2168 .initialize_adapter = qla2x00_initialize_adapter,
2171 static struct isp_operations qla2300_isp_ops = {
2172 .pci_config = qla2300_pci_config,
2173 .reset_chip = qla2x00_reset_chip,
2174 .chip_diag = qla2x00_chip_diag,
2175 .config_rings = qla2x00_config_rings,
2176 .reset_adapter = qla2x00_reset_adapter,
2177 .nvram_config = qla2x00_nvram_config,
2178 .update_fw_options = qla2x00_update_fw_options,
2179 .load_risc = qla2x00_load_risc,
2180 .pci_info_str = qla2x00_pci_info_str,
2181 .fw_version_str = qla2x00_fw_version_str,
2182 .intr_handler = qla2300_intr_handler,
2183 .enable_intrs = qla2x00_enable_intrs,
2184 .disable_intrs = qla2x00_disable_intrs,
2185 .abort_command = qla2x00_abort_command,
2186 .target_reset = qla2x00_abort_target,
2187 .lun_reset = qla2x00_lun_reset,
2188 .fabric_login = qla2x00_login_fabric,
2189 .fabric_logout = qla2x00_fabric_logout,
2190 .calc_req_entries = qla2x00_calc_iocbs_32,
2191 .build_iocbs = qla2x00_build_scsi_iocbs_32,
2192 .prep_ms_iocb = qla2x00_prep_ms_iocb,
2193 .prep_ms_fdmi_iocb = qla2x00_prep_ms_fdmi_iocb,
2194 .read_nvram = qla2x00_read_nvram_data,
2195 .write_nvram = qla2x00_write_nvram_data,
2196 .fw_dump = qla2300_fw_dump,
2197 .beacon_on = qla2x00_beacon_on,
2198 .beacon_off = qla2x00_beacon_off,
2199 .beacon_blink = qla2x00_beacon_blink,
2200 .read_optrom = qla2x00_read_optrom_data,
2201 .write_optrom = qla2x00_write_optrom_data,
2202 .get_flash_version = qla2x00_get_flash_version,
2203 .start_scsi = qla2x00_start_scsi,
2204 .start_scsi_mq = NULL,
2205 .abort_isp = qla2x00_abort_isp,
2206 .iospace_config = qla2x00_iospace_config,
2207 .initialize_adapter = qla2x00_initialize_adapter,
2210 static struct isp_operations qla24xx_isp_ops = {
2211 .pci_config = qla24xx_pci_config,
2212 .reset_chip = qla24xx_reset_chip,
2213 .chip_diag = qla24xx_chip_diag,
2214 .config_rings = qla24xx_config_rings,
2215 .reset_adapter = qla24xx_reset_adapter,
2216 .nvram_config = qla24xx_nvram_config,
2217 .update_fw_options = qla24xx_update_fw_options,
2218 .load_risc = qla24xx_load_risc,
2219 .pci_info_str = qla24xx_pci_info_str,
2220 .fw_version_str = qla24xx_fw_version_str,
2221 .intr_handler = qla24xx_intr_handler,
2222 .enable_intrs = qla24xx_enable_intrs,
2223 .disable_intrs = qla24xx_disable_intrs,
2224 .abort_command = qla24xx_abort_command,
2225 .target_reset = qla24xx_abort_target,
2226 .lun_reset = qla24xx_lun_reset,
2227 .fabric_login = qla24xx_login_fabric,
2228 .fabric_logout = qla24xx_fabric_logout,
2229 .calc_req_entries = NULL,
2230 .build_iocbs = NULL,
2231 .prep_ms_iocb = qla24xx_prep_ms_iocb,
2232 .prep_ms_fdmi_iocb = qla24xx_prep_ms_fdmi_iocb,
2233 .read_nvram = qla24xx_read_nvram_data,
2234 .write_nvram = qla24xx_write_nvram_data,
2235 .fw_dump = qla24xx_fw_dump,
2236 .beacon_on = qla24xx_beacon_on,
2237 .beacon_off = qla24xx_beacon_off,
2238 .beacon_blink = qla24xx_beacon_blink,
2239 .read_optrom = qla24xx_read_optrom_data,
2240 .write_optrom = qla24xx_write_optrom_data,
2241 .get_flash_version = qla24xx_get_flash_version,
2242 .start_scsi = qla24xx_start_scsi,
2243 .start_scsi_mq = NULL,
2244 .abort_isp = qla2x00_abort_isp,
2245 .iospace_config = qla2x00_iospace_config,
2246 .initialize_adapter = qla2x00_initialize_adapter,
2249 static struct isp_operations qla25xx_isp_ops = {
2250 .pci_config = qla25xx_pci_config,
2251 .reset_chip = qla24xx_reset_chip,
2252 .chip_diag = qla24xx_chip_diag,
2253 .config_rings = qla24xx_config_rings,
2254 .reset_adapter = qla24xx_reset_adapter,
2255 .nvram_config = qla24xx_nvram_config,
2256 .update_fw_options = qla24xx_update_fw_options,
2257 .load_risc = qla24xx_load_risc,
2258 .pci_info_str = qla24xx_pci_info_str,
2259 .fw_version_str = qla24xx_fw_version_str,
2260 .intr_handler = qla24xx_intr_handler,
2261 .enable_intrs = qla24xx_enable_intrs,
2262 .disable_intrs = qla24xx_disable_intrs,
2263 .abort_command = qla24xx_abort_command,
2264 .target_reset = qla24xx_abort_target,
2265 .lun_reset = qla24xx_lun_reset,
2266 .fabric_login = qla24xx_login_fabric,
2267 .fabric_logout = qla24xx_fabric_logout,
2268 .calc_req_entries = NULL,
2269 .build_iocbs = NULL,
2270 .prep_ms_iocb = qla24xx_prep_ms_iocb,
2271 .prep_ms_fdmi_iocb = qla24xx_prep_ms_fdmi_iocb,
2272 .read_nvram = qla25xx_read_nvram_data,
2273 .write_nvram = qla25xx_write_nvram_data,
2274 .fw_dump = qla25xx_fw_dump,
2275 .beacon_on = qla24xx_beacon_on,
2276 .beacon_off = qla24xx_beacon_off,
2277 .beacon_blink = qla24xx_beacon_blink,
2278 .read_optrom = qla25xx_read_optrom_data,
2279 .write_optrom = qla24xx_write_optrom_data,
2280 .get_flash_version = qla24xx_get_flash_version,
2281 .start_scsi = qla24xx_dif_start_scsi,
2282 .start_scsi_mq = qla2xxx_dif_start_scsi_mq,
2283 .abort_isp = qla2x00_abort_isp,
2284 .iospace_config = qla2x00_iospace_config,
2285 .initialize_adapter = qla2x00_initialize_adapter,
2288 static struct isp_operations qla81xx_isp_ops = {
2289 .pci_config = qla25xx_pci_config,
2290 .reset_chip = qla24xx_reset_chip,
2291 .chip_diag = qla24xx_chip_diag,
2292 .config_rings = qla24xx_config_rings,
2293 .reset_adapter = qla24xx_reset_adapter,
2294 .nvram_config = qla81xx_nvram_config,
2295 .update_fw_options = qla24xx_update_fw_options,
2296 .load_risc = qla81xx_load_risc,
2297 .pci_info_str = qla24xx_pci_info_str,
2298 .fw_version_str = qla24xx_fw_version_str,
2299 .intr_handler = qla24xx_intr_handler,
2300 .enable_intrs = qla24xx_enable_intrs,
2301 .disable_intrs = qla24xx_disable_intrs,
2302 .abort_command = qla24xx_abort_command,
2303 .target_reset = qla24xx_abort_target,
2304 .lun_reset = qla24xx_lun_reset,
2305 .fabric_login = qla24xx_login_fabric,
2306 .fabric_logout = qla24xx_fabric_logout,
2307 .calc_req_entries = NULL,
2308 .build_iocbs = NULL,
2309 .prep_ms_iocb = qla24xx_prep_ms_iocb,
2310 .prep_ms_fdmi_iocb = qla24xx_prep_ms_fdmi_iocb,
2312 .write_nvram = NULL,
2313 .fw_dump = qla81xx_fw_dump,
2314 .beacon_on = qla24xx_beacon_on,
2315 .beacon_off = qla24xx_beacon_off,
2316 .beacon_blink = qla83xx_beacon_blink,
2317 .read_optrom = qla25xx_read_optrom_data,
2318 .write_optrom = qla24xx_write_optrom_data,
2319 .get_flash_version = qla24xx_get_flash_version,
2320 .start_scsi = qla24xx_dif_start_scsi,
2321 .start_scsi_mq = qla2xxx_dif_start_scsi_mq,
2322 .abort_isp = qla2x00_abort_isp,
2323 .iospace_config = qla2x00_iospace_config,
2324 .initialize_adapter = qla2x00_initialize_adapter,
2327 static struct isp_operations qla82xx_isp_ops = {
2328 .pci_config = qla82xx_pci_config,
2329 .reset_chip = qla82xx_reset_chip,
2330 .chip_diag = qla24xx_chip_diag,
2331 .config_rings = qla82xx_config_rings,
2332 .reset_adapter = qla24xx_reset_adapter,
2333 .nvram_config = qla81xx_nvram_config,
2334 .update_fw_options = qla24xx_update_fw_options,
2335 .load_risc = qla82xx_load_risc,
2336 .pci_info_str = qla24xx_pci_info_str,
2337 .fw_version_str = qla24xx_fw_version_str,
2338 .intr_handler = qla82xx_intr_handler,
2339 .enable_intrs = qla82xx_enable_intrs,
2340 .disable_intrs = qla82xx_disable_intrs,
2341 .abort_command = qla24xx_abort_command,
2342 .target_reset = qla24xx_abort_target,
2343 .lun_reset = qla24xx_lun_reset,
2344 .fabric_login = qla24xx_login_fabric,
2345 .fabric_logout = qla24xx_fabric_logout,
2346 .calc_req_entries = NULL,
2347 .build_iocbs = NULL,
2348 .prep_ms_iocb = qla24xx_prep_ms_iocb,
2349 .prep_ms_fdmi_iocb = qla24xx_prep_ms_fdmi_iocb,
2350 .read_nvram = qla24xx_read_nvram_data,
2351 .write_nvram = qla24xx_write_nvram_data,
2352 .fw_dump = qla82xx_fw_dump,
2353 .beacon_on = qla82xx_beacon_on,
2354 .beacon_off = qla82xx_beacon_off,
2355 .beacon_blink = NULL,
2356 .read_optrom = qla82xx_read_optrom_data,
2357 .write_optrom = qla82xx_write_optrom_data,
2358 .get_flash_version = qla82xx_get_flash_version,
2359 .start_scsi = qla82xx_start_scsi,
2360 .start_scsi_mq = NULL,
2361 .abort_isp = qla82xx_abort_isp,
2362 .iospace_config = qla82xx_iospace_config,
2363 .initialize_adapter = qla2x00_initialize_adapter,
2366 static struct isp_operations qla8044_isp_ops = {
2367 .pci_config = qla82xx_pci_config,
2368 .reset_chip = qla82xx_reset_chip,
2369 .chip_diag = qla24xx_chip_diag,
2370 .config_rings = qla82xx_config_rings,
2371 .reset_adapter = qla24xx_reset_adapter,
2372 .nvram_config = qla81xx_nvram_config,
2373 .update_fw_options = qla24xx_update_fw_options,
2374 .load_risc = qla82xx_load_risc,
2375 .pci_info_str = qla24xx_pci_info_str,
2376 .fw_version_str = qla24xx_fw_version_str,
2377 .intr_handler = qla8044_intr_handler,
2378 .enable_intrs = qla82xx_enable_intrs,
2379 .disable_intrs = qla82xx_disable_intrs,
2380 .abort_command = qla24xx_abort_command,
2381 .target_reset = qla24xx_abort_target,
2382 .lun_reset = qla24xx_lun_reset,
2383 .fabric_login = qla24xx_login_fabric,
2384 .fabric_logout = qla24xx_fabric_logout,
2385 .calc_req_entries = NULL,
2386 .build_iocbs = NULL,
2387 .prep_ms_iocb = qla24xx_prep_ms_iocb,
2388 .prep_ms_fdmi_iocb = qla24xx_prep_ms_fdmi_iocb,
2390 .write_nvram = NULL,
2391 .fw_dump = qla8044_fw_dump,
2392 .beacon_on = qla82xx_beacon_on,
2393 .beacon_off = qla82xx_beacon_off,
2394 .beacon_blink = NULL,
2395 .read_optrom = qla8044_read_optrom_data,
2396 .write_optrom = qla8044_write_optrom_data,
2397 .get_flash_version = qla82xx_get_flash_version,
2398 .start_scsi = qla82xx_start_scsi,
2399 .start_scsi_mq = NULL,
2400 .abort_isp = qla8044_abort_isp,
2401 .iospace_config = qla82xx_iospace_config,
2402 .initialize_adapter = qla2x00_initialize_adapter,
2405 static struct isp_operations qla83xx_isp_ops = {
2406 .pci_config = qla25xx_pci_config,
2407 .reset_chip = qla24xx_reset_chip,
2408 .chip_diag = qla24xx_chip_diag,
2409 .config_rings = qla24xx_config_rings,
2410 .reset_adapter = qla24xx_reset_adapter,
2411 .nvram_config = qla81xx_nvram_config,
2412 .update_fw_options = qla24xx_update_fw_options,
2413 .load_risc = qla81xx_load_risc,
2414 .pci_info_str = qla24xx_pci_info_str,
2415 .fw_version_str = qla24xx_fw_version_str,
2416 .intr_handler = qla24xx_intr_handler,
2417 .enable_intrs = qla24xx_enable_intrs,
2418 .disable_intrs = qla24xx_disable_intrs,
2419 .abort_command = qla24xx_abort_command,
2420 .target_reset = qla24xx_abort_target,
2421 .lun_reset = qla24xx_lun_reset,
2422 .fabric_login = qla24xx_login_fabric,
2423 .fabric_logout = qla24xx_fabric_logout,
2424 .calc_req_entries = NULL,
2425 .build_iocbs = NULL,
2426 .prep_ms_iocb = qla24xx_prep_ms_iocb,
2427 .prep_ms_fdmi_iocb = qla24xx_prep_ms_fdmi_iocb,
2429 .write_nvram = NULL,
2430 .fw_dump = qla83xx_fw_dump,
2431 .beacon_on = qla24xx_beacon_on,
2432 .beacon_off = qla24xx_beacon_off,
2433 .beacon_blink = qla83xx_beacon_blink,
2434 .read_optrom = qla25xx_read_optrom_data,
2435 .write_optrom = qla24xx_write_optrom_data,
2436 .get_flash_version = qla24xx_get_flash_version,
2437 .start_scsi = qla24xx_dif_start_scsi,
2438 .start_scsi_mq = qla2xxx_dif_start_scsi_mq,
2439 .abort_isp = qla2x00_abort_isp,
2440 .iospace_config = qla83xx_iospace_config,
2441 .initialize_adapter = qla2x00_initialize_adapter,
2444 static struct isp_operations qlafx00_isp_ops = {
2445 .pci_config = qlafx00_pci_config,
2446 .reset_chip = qlafx00_soft_reset,
2447 .chip_diag = qlafx00_chip_diag,
2448 .config_rings = qlafx00_config_rings,
2449 .reset_adapter = qlafx00_soft_reset,
2450 .nvram_config = NULL,
2451 .update_fw_options = NULL,
2453 .pci_info_str = qlafx00_pci_info_str,
2454 .fw_version_str = qlafx00_fw_version_str,
2455 .intr_handler = qlafx00_intr_handler,
2456 .enable_intrs = qlafx00_enable_intrs,
2457 .disable_intrs = qlafx00_disable_intrs,
2458 .abort_command = qla24xx_async_abort_command,
2459 .target_reset = qlafx00_abort_target,
2460 .lun_reset = qlafx00_lun_reset,
2461 .fabric_login = NULL,
2462 .fabric_logout = NULL,
2463 .calc_req_entries = NULL,
2464 .build_iocbs = NULL,
2465 .prep_ms_iocb = qla24xx_prep_ms_iocb,
2466 .prep_ms_fdmi_iocb = qla24xx_prep_ms_fdmi_iocb,
2467 .read_nvram = qla24xx_read_nvram_data,
2468 .write_nvram = qla24xx_write_nvram_data,
2470 .beacon_on = qla24xx_beacon_on,
2471 .beacon_off = qla24xx_beacon_off,
2472 .beacon_blink = NULL,
2473 .read_optrom = qla24xx_read_optrom_data,
2474 .write_optrom = qla24xx_write_optrom_data,
2475 .get_flash_version = qla24xx_get_flash_version,
2476 .start_scsi = qlafx00_start_scsi,
2477 .start_scsi_mq = NULL,
2478 .abort_isp = qlafx00_abort_isp,
2479 .iospace_config = qlafx00_iospace_config,
2480 .initialize_adapter = qlafx00_initialize_adapter,
2483 static struct isp_operations qla27xx_isp_ops = {
2484 .pci_config = qla25xx_pci_config,
2485 .reset_chip = qla24xx_reset_chip,
2486 .chip_diag = qla24xx_chip_diag,
2487 .config_rings = qla24xx_config_rings,
2488 .reset_adapter = qla24xx_reset_adapter,
2489 .nvram_config = qla81xx_nvram_config,
2490 .update_fw_options = qla24xx_update_fw_options,
2491 .load_risc = qla81xx_load_risc,
2492 .pci_info_str = qla24xx_pci_info_str,
2493 .fw_version_str = qla24xx_fw_version_str,
2494 .intr_handler = qla24xx_intr_handler,
2495 .enable_intrs = qla24xx_enable_intrs,
2496 .disable_intrs = qla24xx_disable_intrs,
2497 .abort_command = qla24xx_abort_command,
2498 .target_reset = qla24xx_abort_target,
2499 .lun_reset = qla24xx_lun_reset,
2500 .fabric_login = qla24xx_login_fabric,
2501 .fabric_logout = qla24xx_fabric_logout,
2502 .calc_req_entries = NULL,
2503 .build_iocbs = NULL,
2504 .prep_ms_iocb = qla24xx_prep_ms_iocb,
2505 .prep_ms_fdmi_iocb = qla24xx_prep_ms_fdmi_iocb,
2507 .write_nvram = NULL,
2508 .fw_dump = qla27xx_fwdump,
2509 .mpi_fw_dump = qla27xx_mpi_fwdump,
2510 .beacon_on = qla24xx_beacon_on,
2511 .beacon_off = qla24xx_beacon_off,
2512 .beacon_blink = qla83xx_beacon_blink,
2513 .read_optrom = qla25xx_read_optrom_data,
2514 .write_optrom = qla24xx_write_optrom_data,
2515 .get_flash_version = qla24xx_get_flash_version,
2516 .start_scsi = qla24xx_dif_start_scsi,
2517 .start_scsi_mq = qla2xxx_dif_start_scsi_mq,
2518 .abort_isp = qla2x00_abort_isp,
2519 .iospace_config = qla83xx_iospace_config,
2520 .initialize_adapter = qla2x00_initialize_adapter,
2524 qla2x00_set_isp_flags(struct qla_hw_data *ha)
2526 ha->device_type = DT_EXTENDED_IDS;
2527 switch (ha->pdev->device) {
2528 case PCI_DEVICE_ID_QLOGIC_ISP2100:
2529 ha->isp_type |= DT_ISP2100;
2530 ha->device_type &= ~DT_EXTENDED_IDS;
2531 ha->fw_srisc_address = RISC_START_ADDRESS_2100;
2533 case PCI_DEVICE_ID_QLOGIC_ISP2200:
2534 ha->isp_type |= DT_ISP2200;
2535 ha->device_type &= ~DT_EXTENDED_IDS;
2536 ha->fw_srisc_address = RISC_START_ADDRESS_2100;
2538 case PCI_DEVICE_ID_QLOGIC_ISP2300:
2539 ha->isp_type |= DT_ISP2300;
2540 ha->device_type |= DT_ZIO_SUPPORTED;
2541 ha->fw_srisc_address = RISC_START_ADDRESS_2300;
2543 case PCI_DEVICE_ID_QLOGIC_ISP2312:
2544 ha->isp_type |= DT_ISP2312;
2545 ha->device_type |= DT_ZIO_SUPPORTED;
2546 ha->fw_srisc_address = RISC_START_ADDRESS_2300;
2548 case PCI_DEVICE_ID_QLOGIC_ISP2322:
2549 ha->isp_type |= DT_ISP2322;
2550 ha->device_type |= DT_ZIO_SUPPORTED;
2551 if (ha->pdev->subsystem_vendor == 0x1028 &&
2552 ha->pdev->subsystem_device == 0x0170)
2553 ha->device_type |= DT_OEM_001;
2554 ha->fw_srisc_address = RISC_START_ADDRESS_2300;
2556 case PCI_DEVICE_ID_QLOGIC_ISP6312:
2557 ha->isp_type |= DT_ISP6312;
2558 ha->fw_srisc_address = RISC_START_ADDRESS_2300;
2560 case PCI_DEVICE_ID_QLOGIC_ISP6322:
2561 ha->isp_type |= DT_ISP6322;
2562 ha->fw_srisc_address = RISC_START_ADDRESS_2300;
2564 case PCI_DEVICE_ID_QLOGIC_ISP2422:
2565 ha->isp_type |= DT_ISP2422;
2566 ha->device_type |= DT_ZIO_SUPPORTED;
2567 ha->device_type |= DT_FWI2;
2568 ha->device_type |= DT_IIDMA;
2569 ha->fw_srisc_address = RISC_START_ADDRESS_2400;
2571 case PCI_DEVICE_ID_QLOGIC_ISP2432:
2572 ha->isp_type |= DT_ISP2432;
2573 ha->device_type |= DT_ZIO_SUPPORTED;
2574 ha->device_type |= DT_FWI2;
2575 ha->device_type |= DT_IIDMA;
2576 ha->fw_srisc_address = RISC_START_ADDRESS_2400;
2578 case PCI_DEVICE_ID_QLOGIC_ISP8432:
2579 ha->isp_type |= DT_ISP8432;
2580 ha->device_type |= DT_ZIO_SUPPORTED;
2581 ha->device_type |= DT_FWI2;
2582 ha->device_type |= DT_IIDMA;
2583 ha->fw_srisc_address = RISC_START_ADDRESS_2400;
2585 case PCI_DEVICE_ID_QLOGIC_ISP5422:
2586 ha->isp_type |= DT_ISP5422;
2587 ha->device_type |= DT_FWI2;
2588 ha->fw_srisc_address = RISC_START_ADDRESS_2400;
2590 case PCI_DEVICE_ID_QLOGIC_ISP5432:
2591 ha->isp_type |= DT_ISP5432;
2592 ha->device_type |= DT_FWI2;
2593 ha->fw_srisc_address = RISC_START_ADDRESS_2400;
2595 case PCI_DEVICE_ID_QLOGIC_ISP2532:
2596 ha->isp_type |= DT_ISP2532;
2597 ha->device_type |= DT_ZIO_SUPPORTED;
2598 ha->device_type |= DT_FWI2;
2599 ha->device_type |= DT_IIDMA;
2600 ha->fw_srisc_address = RISC_START_ADDRESS_2400;
2602 case PCI_DEVICE_ID_QLOGIC_ISP8001:
2603 ha->isp_type |= DT_ISP8001;
2604 ha->device_type |= DT_ZIO_SUPPORTED;
2605 ha->device_type |= DT_FWI2;
2606 ha->device_type |= DT_IIDMA;
2607 ha->fw_srisc_address = RISC_START_ADDRESS_2400;
2609 case PCI_DEVICE_ID_QLOGIC_ISP8021:
2610 ha->isp_type |= DT_ISP8021;
2611 ha->device_type |= DT_ZIO_SUPPORTED;
2612 ha->device_type |= DT_FWI2;
2613 ha->fw_srisc_address = RISC_START_ADDRESS_2400;
2614 /* Initialize 82XX ISP flags */
2615 qla82xx_init_flags(ha);
2617 case PCI_DEVICE_ID_QLOGIC_ISP8044:
2618 ha->isp_type |= DT_ISP8044;
2619 ha->device_type |= DT_ZIO_SUPPORTED;
2620 ha->device_type |= DT_FWI2;
2621 ha->fw_srisc_address = RISC_START_ADDRESS_2400;
2622 /* Initialize 82XX ISP flags */
2623 qla82xx_init_flags(ha);
2625 case PCI_DEVICE_ID_QLOGIC_ISP2031:
2626 ha->isp_type |= DT_ISP2031;
2627 ha->device_type |= DT_ZIO_SUPPORTED;
2628 ha->device_type |= DT_FWI2;
2629 ha->device_type |= DT_IIDMA;
2630 ha->device_type |= DT_T10_PI;
2631 ha->fw_srisc_address = RISC_START_ADDRESS_2400;
2633 case PCI_DEVICE_ID_QLOGIC_ISP8031:
2634 ha->isp_type |= DT_ISP8031;
2635 ha->device_type |= DT_ZIO_SUPPORTED;
2636 ha->device_type |= DT_FWI2;
2637 ha->device_type |= DT_IIDMA;
2638 ha->device_type |= DT_T10_PI;
2639 ha->fw_srisc_address = RISC_START_ADDRESS_2400;
2641 case PCI_DEVICE_ID_QLOGIC_ISPF001:
2642 ha->isp_type |= DT_ISPFX00;
2644 case PCI_DEVICE_ID_QLOGIC_ISP2071:
2645 ha->isp_type |= DT_ISP2071;
2646 ha->device_type |= DT_ZIO_SUPPORTED;
2647 ha->device_type |= DT_FWI2;
2648 ha->device_type |= DT_IIDMA;
2649 ha->device_type |= DT_T10_PI;
2650 ha->fw_srisc_address = RISC_START_ADDRESS_2400;
2652 case PCI_DEVICE_ID_QLOGIC_ISP2271:
2653 ha->isp_type |= DT_ISP2271;
2654 ha->device_type |= DT_ZIO_SUPPORTED;
2655 ha->device_type |= DT_FWI2;
2656 ha->device_type |= DT_IIDMA;
2657 ha->device_type |= DT_T10_PI;
2658 ha->fw_srisc_address = RISC_START_ADDRESS_2400;
2660 case PCI_DEVICE_ID_QLOGIC_ISP2261:
2661 ha->isp_type |= DT_ISP2261;
2662 ha->device_type |= DT_ZIO_SUPPORTED;
2663 ha->device_type |= DT_FWI2;
2664 ha->device_type |= DT_IIDMA;
2665 ha->device_type |= DT_T10_PI;
2666 ha->fw_srisc_address = RISC_START_ADDRESS_2400;
2668 case PCI_DEVICE_ID_QLOGIC_ISP2081:
2669 case PCI_DEVICE_ID_QLOGIC_ISP2089:
2670 ha->isp_type |= DT_ISP2081;
2671 ha->device_type |= DT_ZIO_SUPPORTED;
2672 ha->device_type |= DT_FWI2;
2673 ha->device_type |= DT_IIDMA;
2674 ha->device_type |= DT_T10_PI;
2675 ha->fw_srisc_address = RISC_START_ADDRESS_2400;
2677 case PCI_DEVICE_ID_QLOGIC_ISP2281:
2678 case PCI_DEVICE_ID_QLOGIC_ISP2289:
2679 ha->isp_type |= DT_ISP2281;
2680 ha->device_type |= DT_ZIO_SUPPORTED;
2681 ha->device_type |= DT_FWI2;
2682 ha->device_type |= DT_IIDMA;
2683 ha->device_type |= DT_T10_PI;
2684 ha->fw_srisc_address = RISC_START_ADDRESS_2400;
2689 ha->port_no = ha->portnum & 1;
2691 /* Get adapter physical port no from interrupt pin register. */
2692 pci_read_config_byte(ha->pdev, PCI_INTERRUPT_PIN, &ha->port_no);
2693 if (IS_QLA25XX(ha) || IS_QLA2031(ha) ||
2694 IS_QLA27XX(ha) || IS_QLA28XX(ha))
2697 ha->port_no = !(ha->port_no & 1);
2700 ql_dbg_pci(ql_dbg_init, ha->pdev, 0x000b,
2701 "device_type=0x%x port=%d fw_srisc_address=0x%x.\n",
2702 ha->device_type, ha->port_no, ha->fw_srisc_address);
2706 qla2xxx_scan_start(struct Scsi_Host *shost)
2708 scsi_qla_host_t *vha = shost_priv(shost);
2710 if (vha->hw->flags.running_gold_fw)
2713 set_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags);
2714 set_bit(LOCAL_LOOP_UPDATE, &vha->dpc_flags);
2715 set_bit(RSCN_UPDATE, &vha->dpc_flags);
2716 set_bit(NPIV_CONFIG_NEEDED, &vha->dpc_flags);
2720 qla2xxx_scan_finished(struct Scsi_Host *shost, unsigned long time)
2722 scsi_qla_host_t *vha = shost_priv(shost);
2724 if (test_bit(UNLOADING, &vha->dpc_flags))
2728 if (time > vha->hw->loop_reset_delay * HZ)
2731 return atomic_read(&vha->loop_state) == LOOP_READY;
2734 static void qla2x00_iocb_work_fn(struct work_struct *work)
2736 struct scsi_qla_host *vha = container_of(work,
2737 struct scsi_qla_host, iocb_work);
2738 struct qla_hw_data *ha = vha->hw;
2739 struct scsi_qla_host *base_vha = pci_get_drvdata(ha->pdev);
2741 unsigned long flags;
2743 if (test_bit(UNLOADING, &base_vha->dpc_flags))
2746 while (!list_empty(&vha->work_list) && i > 0) {
2747 qla2x00_do_work(vha);
2751 spin_lock_irqsave(&vha->work_lock, flags);
2752 clear_bit(IOCB_WORK_ACTIVE, &vha->dpc_flags);
2753 spin_unlock_irqrestore(&vha->work_lock, flags);
2757 * PCI driver interface
2760 qla2x00_probe_one(struct pci_dev *pdev, const struct pci_device_id *id)
2763 struct Scsi_Host *host;
2764 scsi_qla_host_t *base_vha = NULL;
2765 struct qla_hw_data *ha;
2767 char fw_str[30], wq_name[30];
2768 struct scsi_host_template *sht;
2769 int bars, mem_only = 0;
2770 uint16_t req_length = 0, rsp_length = 0;
2771 struct req_que *req = NULL;
2772 struct rsp_que *rsp = NULL;
2775 bars = pci_select_bars(pdev, IORESOURCE_MEM | IORESOURCE_IO);
2776 sht = &qla2xxx_driver_template;
2777 if (pdev->device == PCI_DEVICE_ID_QLOGIC_ISP2422 ||
2778 pdev->device == PCI_DEVICE_ID_QLOGIC_ISP2432 ||
2779 pdev->device == PCI_DEVICE_ID_QLOGIC_ISP8432 ||
2780 pdev->device == PCI_DEVICE_ID_QLOGIC_ISP5422 ||
2781 pdev->device == PCI_DEVICE_ID_QLOGIC_ISP5432 ||
2782 pdev->device == PCI_DEVICE_ID_QLOGIC_ISP2532 ||
2783 pdev->device == PCI_DEVICE_ID_QLOGIC_ISP8001 ||
2784 pdev->device == PCI_DEVICE_ID_QLOGIC_ISP8021 ||
2785 pdev->device == PCI_DEVICE_ID_QLOGIC_ISP2031 ||
2786 pdev->device == PCI_DEVICE_ID_QLOGIC_ISP8031 ||
2787 pdev->device == PCI_DEVICE_ID_QLOGIC_ISPF001 ||
2788 pdev->device == PCI_DEVICE_ID_QLOGIC_ISP8044 ||
2789 pdev->device == PCI_DEVICE_ID_QLOGIC_ISP2071 ||
2790 pdev->device == PCI_DEVICE_ID_QLOGIC_ISP2271 ||
2791 pdev->device == PCI_DEVICE_ID_QLOGIC_ISP2261 ||
2792 pdev->device == PCI_DEVICE_ID_QLOGIC_ISP2081 ||
2793 pdev->device == PCI_DEVICE_ID_QLOGIC_ISP2281 ||
2794 pdev->device == PCI_DEVICE_ID_QLOGIC_ISP2089 ||
2795 pdev->device == PCI_DEVICE_ID_QLOGIC_ISP2289) {
2796 bars = pci_select_bars(pdev, IORESOURCE_MEM);
2798 ql_dbg_pci(ql_dbg_init, pdev, 0x0007,
2799 "Mem only adapter.\n");
2801 ql_dbg_pci(ql_dbg_init, pdev, 0x0008,
2802 "Bars=%d.\n", bars);
2805 if (pci_enable_device_mem(pdev))
2808 if (pci_enable_device(pdev))
2812 if (is_kdump_kernel()) {
2814 ql2xallocfwdump = 0;
2817 /* This may fail but that's ok */
2818 pci_enable_pcie_error_reporting(pdev);
2820 ha = kzalloc(sizeof(struct qla_hw_data), GFP_KERNEL);
2822 ql_log_pci(ql_log_fatal, pdev, 0x0009,
2823 "Unable to allocate memory for ha.\n");
2824 goto disable_device;
2826 ql_dbg_pci(ql_dbg_init, pdev, 0x000a,
2827 "Memory allocated for ha=%p.\n", ha);
2829 INIT_LIST_HEAD(&ha->tgt.q_full_list);
2830 spin_lock_init(&ha->tgt.q_full_lock);
2831 spin_lock_init(&ha->tgt.sess_lock);
2832 spin_lock_init(&ha->tgt.atio_lock);
2834 atomic_set(&ha->nvme_active_aen_cnt, 0);
2836 /* Clear our data area */
2838 ha->mem_only = mem_only;
2839 spin_lock_init(&ha->hardware_lock);
2840 spin_lock_init(&ha->vport_slock);
2841 mutex_init(&ha->selflogin_lock);
2842 mutex_init(&ha->optrom_mutex);
2844 /* Set ISP-type information. */
2845 qla2x00_set_isp_flags(ha);
2847 /* Set EEH reset type to fundamental if required by hba */
2848 if (IS_QLA24XX(ha) || IS_QLA25XX(ha) || IS_QLA81XX(ha) ||
2849 IS_QLA83XX(ha) || IS_QLA27XX(ha) || IS_QLA28XX(ha))
2850 pdev->needs_freset = 1;
2852 ha->prev_topology = 0;
2853 ha->init_cb_size = sizeof(init_cb_t);
2854 ha->link_data_rate = PORT_SPEED_UNKNOWN;
2855 ha->optrom_size = OPTROM_SIZE_2300;
2856 ha->max_exchg = FW_MAX_EXCHANGES_CNT;
2857 atomic_set(&ha->num_pend_mbx_stage1, 0);
2858 atomic_set(&ha->num_pend_mbx_stage2, 0);
2859 atomic_set(&ha->zio_threshold, DEFAULT_ZIO_THRESHOLD);
2860 ha->last_zio_threshold = DEFAULT_ZIO_THRESHOLD;
2862 /* Assign ISP specific operations. */
2863 if (IS_QLA2100(ha)) {
2864 ha->max_fibre_devices = MAX_FIBRE_DEVICES_2100;
2865 ha->mbx_count = MAILBOX_REGISTER_COUNT_2100;
2866 req_length = REQUEST_ENTRY_CNT_2100;
2867 rsp_length = RESPONSE_ENTRY_CNT_2100;
2868 ha->max_loop_id = SNS_LAST_LOOP_ID_2100;
2869 ha->gid_list_info_size = 4;
2870 ha->flash_conf_off = ~0;
2871 ha->flash_data_off = ~0;
2872 ha->nvram_conf_off = ~0;
2873 ha->nvram_data_off = ~0;
2874 ha->isp_ops = &qla2100_isp_ops;
2875 } else if (IS_QLA2200(ha)) {
2876 ha->max_fibre_devices = MAX_FIBRE_DEVICES_2100;
2877 ha->mbx_count = MAILBOX_REGISTER_COUNT_2200;
2878 req_length = REQUEST_ENTRY_CNT_2200;
2879 rsp_length = RESPONSE_ENTRY_CNT_2100;
2880 ha->max_loop_id = SNS_LAST_LOOP_ID_2100;
2881 ha->gid_list_info_size = 4;
2882 ha->flash_conf_off = ~0;
2883 ha->flash_data_off = ~0;
2884 ha->nvram_conf_off = ~0;
2885 ha->nvram_data_off = ~0;
2886 ha->isp_ops = &qla2100_isp_ops;
2887 } else if (IS_QLA23XX(ha)) {
2888 ha->max_fibre_devices = MAX_FIBRE_DEVICES_2100;
2889 ha->mbx_count = MAILBOX_REGISTER_COUNT;
2890 req_length = REQUEST_ENTRY_CNT_2200;
2891 rsp_length = RESPONSE_ENTRY_CNT_2300;
2892 ha->max_loop_id = SNS_LAST_LOOP_ID_2300;
2893 ha->gid_list_info_size = 6;
2894 if (IS_QLA2322(ha) || IS_QLA6322(ha))
2895 ha->optrom_size = OPTROM_SIZE_2322;
2896 ha->flash_conf_off = ~0;
2897 ha->flash_data_off = ~0;
2898 ha->nvram_conf_off = ~0;
2899 ha->nvram_data_off = ~0;
2900 ha->isp_ops = &qla2300_isp_ops;
2901 } else if (IS_QLA24XX_TYPE(ha)) {
2902 ha->max_fibre_devices = MAX_FIBRE_DEVICES_2400;
2903 ha->mbx_count = MAILBOX_REGISTER_COUNT;
2904 req_length = REQUEST_ENTRY_CNT_24XX;
2905 rsp_length = RESPONSE_ENTRY_CNT_2300;
2906 ha->tgt.atio_q_length = ATIO_ENTRY_CNT_24XX;
2907 ha->max_loop_id = SNS_LAST_LOOP_ID_2300;
2908 ha->init_cb_size = sizeof(struct mid_init_cb_24xx);
2909 ha->gid_list_info_size = 8;
2910 ha->optrom_size = OPTROM_SIZE_24XX;
2911 ha->nvram_npiv_size = QLA_MAX_VPORTS_QLA24XX;
2912 ha->isp_ops = &qla24xx_isp_ops;
2913 ha->flash_conf_off = FARX_ACCESS_FLASH_CONF;
2914 ha->flash_data_off = FARX_ACCESS_FLASH_DATA;
2915 ha->nvram_conf_off = FARX_ACCESS_NVRAM_CONF;
2916 ha->nvram_data_off = FARX_ACCESS_NVRAM_DATA;
2917 } else if (IS_QLA25XX(ha)) {
2918 ha->max_fibre_devices = MAX_FIBRE_DEVICES_2400;
2919 ha->mbx_count = MAILBOX_REGISTER_COUNT;
2920 req_length = REQUEST_ENTRY_CNT_24XX;
2921 rsp_length = RESPONSE_ENTRY_CNT_2300;
2922 ha->tgt.atio_q_length = ATIO_ENTRY_CNT_24XX;
2923 ha->max_loop_id = SNS_LAST_LOOP_ID_2300;
2924 ha->init_cb_size = sizeof(struct mid_init_cb_24xx);
2925 ha->gid_list_info_size = 8;
2926 ha->optrom_size = OPTROM_SIZE_25XX;
2927 ha->nvram_npiv_size = QLA_MAX_VPORTS_QLA25XX;
2928 ha->isp_ops = &qla25xx_isp_ops;
2929 ha->flash_conf_off = FARX_ACCESS_FLASH_CONF;
2930 ha->flash_data_off = FARX_ACCESS_FLASH_DATA;
2931 ha->nvram_conf_off = FARX_ACCESS_NVRAM_CONF;
2932 ha->nvram_data_off = FARX_ACCESS_NVRAM_DATA;
2933 } else if (IS_QLA81XX(ha)) {
2934 ha->max_fibre_devices = MAX_FIBRE_DEVICES_2400;
2935 ha->mbx_count = MAILBOX_REGISTER_COUNT;
2936 req_length = REQUEST_ENTRY_CNT_24XX;
2937 rsp_length = RESPONSE_ENTRY_CNT_2300;
2938 ha->tgt.atio_q_length = ATIO_ENTRY_CNT_24XX;
2939 ha->max_loop_id = SNS_LAST_LOOP_ID_2300;
2940 ha->init_cb_size = sizeof(struct mid_init_cb_81xx);
2941 ha->gid_list_info_size = 8;
2942 ha->optrom_size = OPTROM_SIZE_81XX;
2943 ha->nvram_npiv_size = QLA_MAX_VPORTS_QLA25XX;
2944 ha->isp_ops = &qla81xx_isp_ops;
2945 ha->flash_conf_off = FARX_ACCESS_FLASH_CONF_81XX;
2946 ha->flash_data_off = FARX_ACCESS_FLASH_DATA_81XX;
2947 ha->nvram_conf_off = ~0;
2948 ha->nvram_data_off = ~0;
2949 } else if (IS_QLA82XX(ha)) {
2950 ha->max_fibre_devices = MAX_FIBRE_DEVICES_2400;
2951 ha->mbx_count = MAILBOX_REGISTER_COUNT;
2952 req_length = REQUEST_ENTRY_CNT_82XX;
2953 rsp_length = RESPONSE_ENTRY_CNT_82XX;
2954 ha->max_loop_id = SNS_LAST_LOOP_ID_2300;
2955 ha->init_cb_size = sizeof(struct mid_init_cb_81xx);
2956 ha->gid_list_info_size = 8;
2957 ha->optrom_size = OPTROM_SIZE_82XX;
2958 ha->nvram_npiv_size = QLA_MAX_VPORTS_QLA25XX;
2959 ha->isp_ops = &qla82xx_isp_ops;
2960 ha->flash_conf_off = FARX_ACCESS_FLASH_CONF;
2961 ha->flash_data_off = FARX_ACCESS_FLASH_DATA;
2962 ha->nvram_conf_off = FARX_ACCESS_NVRAM_CONF;
2963 ha->nvram_data_off = FARX_ACCESS_NVRAM_DATA;
2964 } else if (IS_QLA8044(ha)) {
2965 ha->max_fibre_devices = MAX_FIBRE_DEVICES_2400;
2966 ha->mbx_count = MAILBOX_REGISTER_COUNT;
2967 req_length = REQUEST_ENTRY_CNT_82XX;
2968 rsp_length = RESPONSE_ENTRY_CNT_82XX;
2969 ha->max_loop_id = SNS_LAST_LOOP_ID_2300;
2970 ha->init_cb_size = sizeof(struct mid_init_cb_81xx);
2971 ha->gid_list_info_size = 8;
2972 ha->optrom_size = OPTROM_SIZE_83XX;
2973 ha->nvram_npiv_size = QLA_MAX_VPORTS_QLA25XX;
2974 ha->isp_ops = &qla8044_isp_ops;
2975 ha->flash_conf_off = FARX_ACCESS_FLASH_CONF;
2976 ha->flash_data_off = FARX_ACCESS_FLASH_DATA;
2977 ha->nvram_conf_off = FARX_ACCESS_NVRAM_CONF;
2978 ha->nvram_data_off = FARX_ACCESS_NVRAM_DATA;
2979 } else if (IS_QLA83XX(ha)) {
2980 ha->portnum = PCI_FUNC(ha->pdev->devfn);
2981 ha->max_fibre_devices = MAX_FIBRE_DEVICES_2400;
2982 ha->mbx_count = MAILBOX_REGISTER_COUNT;
2983 req_length = REQUEST_ENTRY_CNT_83XX;
2984 rsp_length = RESPONSE_ENTRY_CNT_83XX;
2985 ha->tgt.atio_q_length = ATIO_ENTRY_CNT_24XX;
2986 ha->max_loop_id = SNS_LAST_LOOP_ID_2300;
2987 ha->init_cb_size = sizeof(struct mid_init_cb_81xx);
2988 ha->gid_list_info_size = 8;
2989 ha->optrom_size = OPTROM_SIZE_83XX;
2990 ha->nvram_npiv_size = QLA_MAX_VPORTS_QLA25XX;
2991 ha->isp_ops = &qla83xx_isp_ops;
2992 ha->flash_conf_off = FARX_ACCESS_FLASH_CONF_81XX;
2993 ha->flash_data_off = FARX_ACCESS_FLASH_DATA_81XX;
2994 ha->nvram_conf_off = ~0;
2995 ha->nvram_data_off = ~0;
2996 } else if (IS_QLAFX00(ha)) {
2997 ha->max_fibre_devices = MAX_FIBRE_DEVICES_FX00;
2998 ha->mbx_count = MAILBOX_REGISTER_COUNT_FX00;
2999 ha->aen_mbx_count = AEN_MAILBOX_REGISTER_COUNT_FX00;
3000 req_length = REQUEST_ENTRY_CNT_FX00;
3001 rsp_length = RESPONSE_ENTRY_CNT_FX00;
3002 ha->isp_ops = &qlafx00_isp_ops;
3003 ha->port_down_retry_count = 30; /* default value */
3004 ha->mr.fw_hbt_cnt = QLAFX00_HEARTBEAT_INTERVAL;
3005 ha->mr.fw_reset_timer_tick = QLAFX00_RESET_INTERVAL;
3006 ha->mr.fw_critemp_timer_tick = QLAFX00_CRITEMP_INTERVAL;
3007 ha->mr.fw_hbt_en = 1;
3008 ha->mr.host_info_resend = false;
3009 ha->mr.hinfo_resend_timer_tick = QLAFX00_HINFO_RESEND_INTERVAL;
3010 } else if (IS_QLA27XX(ha)) {
3011 ha->portnum = PCI_FUNC(ha->pdev->devfn);
3012 ha->max_fibre_devices = MAX_FIBRE_DEVICES_2400;
3013 ha->mbx_count = MAILBOX_REGISTER_COUNT;
3014 req_length = REQUEST_ENTRY_CNT_83XX;
3015 rsp_length = RESPONSE_ENTRY_CNT_83XX;
3016 ha->tgt.atio_q_length = ATIO_ENTRY_CNT_24XX;
3017 ha->max_loop_id = SNS_LAST_LOOP_ID_2300;
3018 ha->init_cb_size = sizeof(struct mid_init_cb_81xx);
3019 ha->gid_list_info_size = 8;
3020 ha->optrom_size = OPTROM_SIZE_83XX;
3021 ha->nvram_npiv_size = QLA_MAX_VPORTS_QLA25XX;
3022 ha->isp_ops = &qla27xx_isp_ops;
3023 ha->flash_conf_off = FARX_ACCESS_FLASH_CONF_81XX;
3024 ha->flash_data_off = FARX_ACCESS_FLASH_DATA_81XX;
3025 ha->nvram_conf_off = ~0;
3026 ha->nvram_data_off = ~0;
3027 } else if (IS_QLA28XX(ha)) {
3028 ha->portnum = PCI_FUNC(ha->pdev->devfn);
3029 ha->max_fibre_devices = MAX_FIBRE_DEVICES_2400;
3030 ha->mbx_count = MAILBOX_REGISTER_COUNT;
3031 req_length = REQUEST_ENTRY_CNT_24XX;
3032 rsp_length = RESPONSE_ENTRY_CNT_2300;
3033 ha->tgt.atio_q_length = ATIO_ENTRY_CNT_24XX;
3034 ha->max_loop_id = SNS_LAST_LOOP_ID_2300;
3035 ha->init_cb_size = sizeof(struct mid_init_cb_81xx);
3036 ha->gid_list_info_size = 8;
3037 ha->optrom_size = OPTROM_SIZE_28XX;
3038 ha->nvram_npiv_size = QLA_MAX_VPORTS_QLA25XX;
3039 ha->isp_ops = &qla27xx_isp_ops;
3040 ha->flash_conf_off = FARX_ACCESS_FLASH_CONF_28XX;
3041 ha->flash_data_off = FARX_ACCESS_FLASH_DATA_28XX;
3042 ha->nvram_conf_off = ~0;
3043 ha->nvram_data_off = ~0;
3046 ql_dbg_pci(ql_dbg_init, pdev, 0x001e,
3047 "mbx_count=%d, req_length=%d, "
3048 "rsp_length=%d, max_loop_id=%d, init_cb_size=%d, "
3049 "gid_list_info_size=%d, optrom_size=%d, nvram_npiv_size=%d, "
3050 "max_fibre_devices=%d.\n",
3051 ha->mbx_count, req_length, rsp_length, ha->max_loop_id,
3052 ha->init_cb_size, ha->gid_list_info_size, ha->optrom_size,
3053 ha->nvram_npiv_size, ha->max_fibre_devices);
3054 ql_dbg_pci(ql_dbg_init, pdev, 0x001f,
3055 "isp_ops=%p, flash_conf_off=%d, "
3056 "flash_data_off=%d, nvram_conf_off=%d, nvram_data_off=%d.\n",
3057 ha->isp_ops, ha->flash_conf_off, ha->flash_data_off,
3058 ha->nvram_conf_off, ha->nvram_data_off);
3060 /* Configure PCI I/O space */
3061 ret = ha->isp_ops->iospace_config(ha);
3063 goto iospace_config_failed;
3065 ql_log_pci(ql_log_info, pdev, 0x001d,
3066 "Found an ISP%04X irq %d iobase 0x%p.\n",
3067 pdev->device, pdev->irq, ha->iobase);
3068 mutex_init(&ha->vport_lock);
3069 mutex_init(&ha->mq_lock);
3070 init_completion(&ha->mbx_cmd_comp);
3071 complete(&ha->mbx_cmd_comp);
3072 init_completion(&ha->mbx_intr_comp);
3073 init_completion(&ha->dcbx_comp);
3074 init_completion(&ha->lb_portup_comp);
3076 set_bit(0, (unsigned long *) ha->vp_idx_map);
3078 qla2x00_config_dma_addressing(ha);
3079 ql_dbg_pci(ql_dbg_init, pdev, 0x0020,
3080 "64 Bit addressing is %s.\n",
3081 ha->flags.enable_64bit_addressing ? "enable" :
3083 ret = qla2x00_mem_alloc(ha, req_length, rsp_length, &req, &rsp);
3085 ql_log_pci(ql_log_fatal, pdev, 0x0031,
3086 "Failed to allocate memory for adapter, aborting.\n");
3088 goto probe_hw_failed;
3091 req->max_q_depth = MAX_Q_DEPTH;
3092 if (ql2xmaxqdepth != 0 && ql2xmaxqdepth <= 0xffffU)
3093 req->max_q_depth = ql2xmaxqdepth;
3096 base_vha = qla2x00_create_host(sht, ha);
3099 goto probe_hw_failed;
3102 pci_set_drvdata(pdev, base_vha);
3103 set_bit(PFLG_DRIVER_PROBING, &base_vha->pci_flags);
3105 host = base_vha->host;
3106 base_vha->req = req;
3107 if (IS_QLA2XXX_MIDTYPE(ha))
3108 base_vha->mgmt_svr_loop_id =
3109 qla2x00_reserve_mgmt_server_loop_id(base_vha);
3111 base_vha->mgmt_svr_loop_id = MANAGEMENT_SERVER +
3114 /* Setup fcport template structure. */
3115 ha->mr.fcport.vha = base_vha;
3116 ha->mr.fcport.port_type = FCT_UNKNOWN;
3117 ha->mr.fcport.loop_id = FC_NO_LOOP_ID;
3118 qla2x00_set_fcport_state(&ha->mr.fcport, FCS_UNCONFIGURED);
3119 ha->mr.fcport.supported_classes = FC_COS_UNSPECIFIED;
3120 ha->mr.fcport.scan_state = 1;
3122 /* Set the SG table size based on ISP type */
3123 if (!IS_FWI2_CAPABLE(ha)) {
3125 host->sg_tablesize = 32;
3127 if (!IS_QLA82XX(ha))
3128 host->sg_tablesize = QLA_SG_ALL;
3130 host->max_id = ha->max_fibre_devices;
3131 host->cmd_per_lun = 3;
3132 host->unique_id = host->host_no;
3134 if (ql2xenabledif && ql2xenabledif != 2) {
3135 ql_log(ql_log_warn, base_vha, 0x302d,
3136 "Invalid value for ql2xenabledif, resetting it to default (2)\n");
3140 if (IS_T10_PI_CAPABLE(ha) && ql2xenabledif)
3141 host->max_cmd_len = 32;
3143 host->max_cmd_len = MAX_CMDSZ;
3144 host->max_channel = MAX_BUSES - 1;
3145 /* Older HBAs support only 16-bit LUNs */
3146 if (!IS_QLAFX00(ha) && !IS_FWI2_CAPABLE(ha) &&
3147 ql2xmaxlun > 0xffff)
3148 host->max_lun = 0xffff;
3150 host->max_lun = ql2xmaxlun;
3151 host->transportt = qla2xxx_transport_template;
3152 sht->vendor_id = (SCSI_NL_VID_TYPE_PCI | PCI_VENDOR_ID_QLOGIC);
3154 ql_dbg(ql_dbg_init, base_vha, 0x0033,
3155 "max_id=%d this_id=%d "
3156 "cmd_per_len=%d unique_id=%d max_cmd_len=%d max_channel=%d "
3157 "max_lun=%llu transportt=%p, vendor_id=%llu.\n", host->max_id,
3158 host->this_id, host->cmd_per_lun, host->unique_id,
3159 host->max_cmd_len, host->max_channel, host->max_lun,
3160 host->transportt, sht->vendor_id);
3162 INIT_WORK(&base_vha->iocb_work, qla2x00_iocb_work_fn);
3164 /* Set up the irqs */
3165 ret = qla2x00_request_irqs(ha, rsp);
3169 /* Alloc arrays of request and response ring ptrs */
3170 ret = qla2x00_alloc_queues(ha, req, rsp);
3172 ql_log(ql_log_fatal, base_vha, 0x003d,
3173 "Failed to allocate memory for queue pointers..."
3180 /* number of hardware queues supported by blk/scsi-mq*/
3181 host->nr_hw_queues = ha->max_qpairs;
3183 ql_dbg(ql_dbg_init, base_vha, 0x0192,
3184 "blk/scsi-mq enabled, HW queues = %d.\n", host->nr_hw_queues);
3186 if (ql2xnvmeenable) {
3187 host->nr_hw_queues = ha->max_qpairs;
3188 ql_dbg(ql_dbg_init, base_vha, 0x0194,
3189 "FC-NVMe support is enabled, HW queues=%d\n",
3190 host->nr_hw_queues);
3192 ql_dbg(ql_dbg_init, base_vha, 0x0193,
3193 "blk/scsi-mq disabled.\n");
3197 qlt_probe_one_stage1(base_vha, ha);
3199 pci_save_state(pdev);
3201 /* Assign back pointers */
3205 if (IS_QLAFX00(ha)) {
3206 ha->rsp_q_map[0] = rsp;
3207 ha->req_q_map[0] = req;
3208 set_bit(0, ha->req_qid_map);
3209 set_bit(0, ha->rsp_qid_map);
3212 /* FWI2-capable only. */
3213 req->req_q_in = &ha->iobase->isp24.req_q_in;
3214 req->req_q_out = &ha->iobase->isp24.req_q_out;
3215 rsp->rsp_q_in = &ha->iobase->isp24.rsp_q_in;
3216 rsp->rsp_q_out = &ha->iobase->isp24.rsp_q_out;
3217 if (ha->mqenable || IS_QLA83XX(ha) || IS_QLA27XX(ha) ||
3219 req->req_q_in = &ha->mqiobase->isp25mq.req_q_in;
3220 req->req_q_out = &ha->mqiobase->isp25mq.req_q_out;
3221 rsp->rsp_q_in = &ha->mqiobase->isp25mq.rsp_q_in;
3222 rsp->rsp_q_out = &ha->mqiobase->isp25mq.rsp_q_out;
3225 if (IS_QLAFX00(ha)) {
3226 req->req_q_in = &ha->iobase->ispfx00.req_q_in;
3227 req->req_q_out = &ha->iobase->ispfx00.req_q_out;
3228 rsp->rsp_q_in = &ha->iobase->ispfx00.rsp_q_in;
3229 rsp->rsp_q_out = &ha->iobase->ispfx00.rsp_q_out;
3232 if (IS_P3P_TYPE(ha)) {
3233 req->req_q_out = &ha->iobase->isp82.req_q_out[0];
3234 rsp->rsp_q_in = &ha->iobase->isp82.rsp_q_in[0];
3235 rsp->rsp_q_out = &ha->iobase->isp82.rsp_q_out[0];
3238 ql_dbg(ql_dbg_multiq, base_vha, 0xc009,
3239 "rsp_q_map=%p req_q_map=%p rsp->req=%p req->rsp=%p.\n",
3240 ha->rsp_q_map, ha->req_q_map, rsp->req, req->rsp);
3241 ql_dbg(ql_dbg_multiq, base_vha, 0xc00a,
3242 "req->req_q_in=%p req->req_q_out=%p "
3243 "rsp->rsp_q_in=%p rsp->rsp_q_out=%p.\n",
3244 req->req_q_in, req->req_q_out,
3245 rsp->rsp_q_in, rsp->rsp_q_out);
3246 ql_dbg(ql_dbg_init, base_vha, 0x003e,
3247 "rsp_q_map=%p req_q_map=%p rsp->req=%p req->rsp=%p.\n",
3248 ha->rsp_q_map, ha->req_q_map, rsp->req, req->rsp);
3249 ql_dbg(ql_dbg_init, base_vha, 0x003f,
3250 "req->req_q_in=%p req->req_q_out=%p rsp->rsp_q_in=%p rsp->rsp_q_out=%p.\n",
3251 req->req_q_in, req->req_q_out, rsp->rsp_q_in, rsp->rsp_q_out);
3253 ha->wq = alloc_workqueue("qla2xxx_wq", 0, 0);
3254 if (unlikely(!ha->wq)) {
3259 if (ha->isp_ops->initialize_adapter(base_vha)) {
3260 ql_log(ql_log_fatal, base_vha, 0x00d6,
3261 "Failed to initialize adapter - Adapter flags %x.\n",
3262 base_vha->device_flags);
3264 if (IS_QLA82XX(ha)) {
3265 qla82xx_idc_lock(ha);
3266 qla82xx_wr_32(ha, QLA82XX_CRB_DEV_STATE,
3267 QLA8XXX_DEV_FAILED);
3268 qla82xx_idc_unlock(ha);
3269 ql_log(ql_log_fatal, base_vha, 0x00d7,
3270 "HW State: FAILED.\n");
3271 } else if (IS_QLA8044(ha)) {
3272 qla8044_idc_lock(ha);
3273 qla8044_wr_direct(base_vha,
3274 QLA8044_CRB_DEV_STATE_INDEX,
3275 QLA8XXX_DEV_FAILED);
3276 qla8044_idc_unlock(ha);
3277 ql_log(ql_log_fatal, base_vha, 0x0150,
3278 "HW State: FAILED.\n");
3286 host->can_queue = QLAFX00_MAX_CANQUEUE;
3288 host->can_queue = req->num_outstanding_cmds - 10;
3290 ql_dbg(ql_dbg_init, base_vha, 0x0032,
3291 "can_queue=%d, req=%p, mgmt_svr_loop_id=%d, sg_tablesize=%d.\n",
3292 host->can_queue, base_vha->req,
3293 base_vha->mgmt_svr_loop_id, host->sg_tablesize);
3296 bool startit = false;
3298 if (QLA_TGT_MODE_ENABLED())
3301 if (ql2x_ini_mode == QLA2XXX_INI_MODE_ENABLED)
3304 /* Create start of day qpairs for Block MQ */
3305 for (i = 0; i < ha->max_qpairs; i++)
3306 qla2xxx_create_qpair(base_vha, 5, 0, startit);
3308 qla_init_iocb_limit(base_vha);
3310 if (ha->flags.running_gold_fw)
3314 * Startup the kernel thread for this host adapter
3316 ha->dpc_thread = kthread_create(qla2x00_do_dpc, ha,
3317 "%s_dpc", base_vha->host_str);
3318 if (IS_ERR(ha->dpc_thread)) {
3319 ql_log(ql_log_fatal, base_vha, 0x00ed,
3320 "Failed to start DPC thread.\n");
3321 ret = PTR_ERR(ha->dpc_thread);
3322 ha->dpc_thread = NULL;
3325 ql_dbg(ql_dbg_init, base_vha, 0x00ee,
3326 "DPC thread started successfully.\n");
3329 * If we're not coming up in initiator mode, we might sit for
3330 * a while without waking up the dpc thread, which leads to a
3331 * stuck process warning. So just kick the dpc once here and
3332 * let the kthread start (and go back to sleep in qla2x00_do_dpc).
3334 qla2xxx_wake_dpc(base_vha);
3336 INIT_WORK(&ha->board_disable, qla2x00_disable_board_on_pci_error);
3338 if (IS_QLA8031(ha) || IS_MCTP_CAPABLE(ha)) {
3339 sprintf(wq_name, "qla2xxx_%lu_dpc_lp_wq", base_vha->host_no);
3340 ha->dpc_lp_wq = create_singlethread_workqueue(wq_name);
3341 INIT_WORK(&ha->idc_aen, qla83xx_service_idc_aen);
3343 sprintf(wq_name, "qla2xxx_%lu_dpc_hp_wq", base_vha->host_no);
3344 ha->dpc_hp_wq = create_singlethread_workqueue(wq_name);
3345 INIT_WORK(&ha->nic_core_reset, qla83xx_nic_core_reset_work);
3346 INIT_WORK(&ha->idc_state_handler,
3347 qla83xx_idc_state_handler_work);
3348 INIT_WORK(&ha->nic_core_unrecoverable,
3349 qla83xx_nic_core_unrecoverable_work);
3353 list_add_tail(&base_vha->list, &ha->vp_list);
3354 base_vha->host->irq = ha->pdev->irq;
3356 /* Initialized the timer */
3357 qla2x00_start_timer(base_vha, WATCH_INTERVAL);
3358 ql_dbg(ql_dbg_init, base_vha, 0x00ef,
3359 "Started qla2x00_timer with "
3360 "interval=%d.\n", WATCH_INTERVAL);
3361 ql_dbg(ql_dbg_init, base_vha, 0x00f0,
3362 "Detected hba at address=%p.\n",
3365 if (IS_T10_PI_CAPABLE(ha) && ql2xenabledif) {
3366 if (ha->fw_attributes & BIT_4) {
3367 int prot = 0, guard;
3369 base_vha->flags.difdix_supported = 1;
3370 ql_dbg(ql_dbg_init, base_vha, 0x00f1,
3371 "Registering for DIF/DIX type 1 and 3 protection.\n");
3373 scsi_host_set_prot(host, ql2xprotmask);
3375 scsi_host_set_prot(host,
3376 prot | SHOST_DIF_TYPE1_PROTECTION
3377 | SHOST_DIF_TYPE2_PROTECTION
3378 | SHOST_DIF_TYPE3_PROTECTION
3379 | SHOST_DIX_TYPE1_PROTECTION
3380 | SHOST_DIX_TYPE2_PROTECTION
3381 | SHOST_DIX_TYPE3_PROTECTION);
3383 guard = SHOST_DIX_GUARD_CRC;
3385 if (IS_PI_IPGUARD_CAPABLE(ha) &&
3386 (ql2xenabledif > 1 || IS_PI_DIFB_DIX0_CAPABLE(ha)))
3387 guard |= SHOST_DIX_GUARD_IP;
3390 scsi_host_set_guard(host, ql2xprotguard);
3392 scsi_host_set_guard(host, guard);
3394 base_vha->flags.difdix_supported = 0;
3397 ha->isp_ops->enable_intrs(ha);
3399 if (IS_QLAFX00(ha)) {
3400 ret = qlafx00_fx_disc(base_vha,
3401 &base_vha->hw->mr.fcport, FXDISC_GET_CONFIG_INFO);
3402 host->sg_tablesize = (ha->mr.extended_io_enabled) ?
3406 ret = scsi_add_host(host, &pdev->dev);
3410 base_vha->flags.init_done = 1;
3411 base_vha->flags.online = 1;
3412 ha->prev_minidump_failed = 0;
3414 ql_dbg(ql_dbg_init, base_vha, 0x00f2,
3415 "Init done and hba is online.\n");
3417 if (qla_ini_mode_enabled(base_vha) ||
3418 qla_dual_mode_enabled(base_vha))
3419 scsi_scan_host(host);
3421 ql_dbg(ql_dbg_init, base_vha, 0x0122,
3422 "skipping scsi_scan_host() for non-initiator port\n");
3424 qla2x00_alloc_sysfs_attr(base_vha);
3426 if (IS_QLAFX00(ha)) {
3427 ret = qlafx00_fx_disc(base_vha,
3428 &base_vha->hw->mr.fcport, FXDISC_GET_PORT_INFO);
3430 /* Register system information */
3431 ret = qlafx00_fx_disc(base_vha,
3432 &base_vha->hw->mr.fcport, FXDISC_REG_HOST_INFO);
3435 qla2x00_init_host_attr(base_vha);
3437 qla2x00_dfs_setup(base_vha);
3439 ql_log(ql_log_info, base_vha, 0x00fb,
3440 "QLogic %s - %s.\n", ha->model_number, ha->model_desc);
3441 ql_log(ql_log_info, base_vha, 0x00fc,
3442 "ISP%04X: %s @ %s hdma%c host#=%ld fw=%s.\n",
3443 pdev->device, ha->isp_ops->pci_info_str(base_vha, pci_info,
3445 pci_name(pdev), ha->flags.enable_64bit_addressing ? '+' : '-',
3447 ha->isp_ops->fw_version_str(base_vha, fw_str, sizeof(fw_str)));
3449 qlt_add_target(ha, base_vha);
3451 clear_bit(PFLG_DRIVER_PROBING, &base_vha->pci_flags);
3453 if (test_bit(UNLOADING, &base_vha->dpc_flags))
3459 if (base_vha->gnl.l) {
3460 dma_free_coherent(&ha->pdev->dev, base_vha->gnl.size,
3461 base_vha->gnl.l, base_vha->gnl.ldma);
3462 base_vha->gnl.l = NULL;
3465 if (base_vha->timer_active)
3466 qla2x00_stop_timer(base_vha);
3467 base_vha->flags.online = 0;
3468 if (ha->dpc_thread) {
3469 struct task_struct *t = ha->dpc_thread;
3471 ha->dpc_thread = NULL;
3475 qla2x00_free_device(base_vha);
3476 scsi_host_put(base_vha->host);
3478 * Need to NULL out local req/rsp after
3479 * qla2x00_free_device => qla2x00_free_queues frees
3480 * what these are pointing to. Or else we'll
3481 * fall over below in qla2x00_free_req/rsp_que.
3487 qla2x00_mem_free(ha);
3488 qla2x00_free_req_que(ha, req);
3489 qla2x00_free_rsp_que(ha, rsp);
3490 qla2x00_clear_drv_active(ha);
3492 iospace_config_failed:
3493 if (IS_P3P_TYPE(ha)) {
3494 if (!ha->nx_pcibase)
3495 iounmap((device_reg_t *)ha->nx_pcibase);
3497 iounmap((device_reg_t *)ha->nxdb_wr_ptr);
3500 iounmap(ha->iobase);
3502 iounmap(ha->cregbase);
3504 pci_release_selected_regions(ha->pdev, ha->bars);
3508 pci_disable_device(pdev);
3512 static void __qla_set_remove_flag(scsi_qla_host_t *base_vha)
3514 scsi_qla_host_t *vp;
3515 unsigned long flags;
3516 struct qla_hw_data *ha;
3523 spin_lock_irqsave(&ha->vport_slock, flags);
3524 list_for_each_entry(vp, &ha->vp_list, list)
3525 set_bit(PFLG_DRIVER_REMOVING, &vp->pci_flags);
3528 * Indicate device removal to prevent future board_disable
3529 * and wait until any pending board_disable has completed.
3531 set_bit(PFLG_DRIVER_REMOVING, &base_vha->pci_flags);
3532 spin_unlock_irqrestore(&ha->vport_slock, flags);
3536 qla2x00_shutdown(struct pci_dev *pdev)
3538 scsi_qla_host_t *vha;
3539 struct qla_hw_data *ha;
3541 vha = pci_get_drvdata(pdev);
3544 ql_log(ql_log_info, vha, 0xfffa,
3545 "Adapter shutdown\n");
3548 * Prevent future board_disable and wait
3549 * until any pending board_disable has completed.
3551 __qla_set_remove_flag(vha);
3552 cancel_work_sync(&ha->board_disable);
3554 if (!atomic_read(&pdev->enable_cnt))
3557 /* Notify ISPFX00 firmware */
3559 qlafx00_driver_shutdown(vha, 20);
3561 /* Turn-off FCE trace */
3562 if (ha->flags.fce_enabled) {
3563 qla2x00_disable_fce_trace(vha, NULL, NULL);
3564 ha->flags.fce_enabled = 0;
3567 /* Turn-off EFT trace */
3569 qla2x00_disable_eft_trace(vha);
3571 if (IS_QLA25XX(ha) || IS_QLA2031(ha) || IS_QLA27XX(ha) ||
3573 if (ha->flags.fw_started)
3574 qla2x00_abort_isp_cleanup(vha);
3576 /* Stop currently executing firmware. */
3577 qla2x00_try_to_stop_firmware(vha);
3581 if (vha->timer_active)
3582 qla2x00_stop_timer(vha);
3584 /* Turn adapter off line */
3585 vha->flags.online = 0;
3587 /* turn-off interrupts on the card */
3588 if (ha->interrupts_on) {
3589 vha->flags.init_done = 0;
3590 ha->isp_ops->disable_intrs(ha);
3593 qla2x00_free_irqs(vha);
3595 qla2x00_free_fw_dump(ha);
3597 pci_disable_device(pdev);
3598 ql_log(ql_log_info, vha, 0xfffe,
3599 "Adapter shutdown successfully.\n");
3602 /* Deletes all the virtual ports for a given ha */
3604 qla2x00_delete_all_vps(struct qla_hw_data *ha, scsi_qla_host_t *base_vha)
3606 scsi_qla_host_t *vha;
3607 unsigned long flags;
3609 mutex_lock(&ha->vport_lock);
3610 while (ha->cur_vport_count) {
3611 spin_lock_irqsave(&ha->vport_slock, flags);
3613 BUG_ON(base_vha->list.next == &ha->vp_list);
3614 /* This assumes first entry in ha->vp_list is always base vha */
3615 vha = list_first_entry(&base_vha->list, scsi_qla_host_t, list);
3616 scsi_host_get(vha->host);
3618 spin_unlock_irqrestore(&ha->vport_slock, flags);
3619 mutex_unlock(&ha->vport_lock);
3621 qla_nvme_delete(vha);
3623 fc_vport_terminate(vha->fc_vport);
3624 scsi_host_put(vha->host);
3626 mutex_lock(&ha->vport_lock);
3628 mutex_unlock(&ha->vport_lock);
3631 /* Stops all deferred work threads */
3633 qla2x00_destroy_deferred_work(struct qla_hw_data *ha)
3635 /* Cancel all work and destroy DPC workqueues */
3636 if (ha->dpc_lp_wq) {
3637 cancel_work_sync(&ha->idc_aen);
3638 destroy_workqueue(ha->dpc_lp_wq);
3639 ha->dpc_lp_wq = NULL;
3642 if (ha->dpc_hp_wq) {
3643 cancel_work_sync(&ha->nic_core_reset);
3644 cancel_work_sync(&ha->idc_state_handler);
3645 cancel_work_sync(&ha->nic_core_unrecoverable);
3646 destroy_workqueue(ha->dpc_hp_wq);
3647 ha->dpc_hp_wq = NULL;
3650 /* Kill the kernel thread for this host */
3651 if (ha->dpc_thread) {
3652 struct task_struct *t = ha->dpc_thread;
3655 * qla2xxx_wake_dpc checks for ->dpc_thread
3656 * so we need to zero it out.
3658 ha->dpc_thread = NULL;
3664 qla2x00_unmap_iobases(struct qla_hw_data *ha)
3666 if (IS_QLA82XX(ha)) {
3668 iounmap((device_reg_t *)ha->nx_pcibase);
3670 iounmap((device_reg_t *)ha->nxdb_wr_ptr);
3673 iounmap(ha->iobase);
3676 iounmap(ha->cregbase);
3679 iounmap(ha->mqiobase);
3682 iounmap(ha->msixbase);
3687 qla2x00_clear_drv_active(struct qla_hw_data *ha)
3689 if (IS_QLA8044(ha)) {
3690 qla8044_idc_lock(ha);
3691 qla8044_clear_drv_active(ha);
3692 qla8044_idc_unlock(ha);
3693 } else if (IS_QLA82XX(ha)) {
3694 qla82xx_idc_lock(ha);
3695 qla82xx_clear_drv_active(ha);
3696 qla82xx_idc_unlock(ha);
3701 qla2x00_remove_one(struct pci_dev *pdev)
3703 scsi_qla_host_t *base_vha;
3704 struct qla_hw_data *ha;
3706 base_vha = pci_get_drvdata(pdev);
3708 ql_log(ql_log_info, base_vha, 0xb079,
3709 "Removing driver\n");
3710 __qla_set_remove_flag(base_vha);
3711 cancel_work_sync(&ha->board_disable);
3714 * If the PCI device is disabled then there was a PCI-disconnect and
3715 * qla2x00_disable_board_on_pci_error has taken care of most of the
3718 if (!atomic_read(&pdev->enable_cnt)) {
3719 dma_free_coherent(&ha->pdev->dev, base_vha->gnl.size,
3720 base_vha->gnl.l, base_vha->gnl.ldma);
3721 base_vha->gnl.l = NULL;
3722 scsi_host_put(base_vha->host);
3724 pci_set_drvdata(pdev, NULL);
3727 qla2x00_wait_for_hba_ready(base_vha);
3730 * if UNLOADING flag is already set, then continue unload,
3731 * where it was set first.
3733 if (test_and_set_bit(UNLOADING, &base_vha->dpc_flags))
3736 if (IS_QLA25XX(ha) || IS_QLA2031(ha) || IS_QLA27XX(ha) ||
3738 if (ha->flags.fw_started)
3739 qla2x00_abort_isp_cleanup(base_vha);
3740 } else if (!IS_QLAFX00(ha)) {
3741 if (IS_QLA8031(ha)) {
3742 ql_dbg(ql_dbg_p3p, base_vha, 0xb07e,
3743 "Clearing fcoe driver presence.\n");
3744 if (qla83xx_clear_drv_presence(base_vha) != QLA_SUCCESS)
3745 ql_dbg(ql_dbg_p3p, base_vha, 0xb079,
3746 "Error while clearing DRV-Presence.\n");
3749 qla2x00_try_to_stop_firmware(base_vha);
3752 qla2x00_wait_for_sess_deletion(base_vha);
3754 qla_nvme_delete(base_vha);
3756 dma_free_coherent(&ha->pdev->dev,
3757 base_vha->gnl.size, base_vha->gnl.l, base_vha->gnl.ldma);
3759 base_vha->gnl.l = NULL;
3761 vfree(base_vha->scan.l);
3764 qlafx00_driver_shutdown(base_vha, 20);
3766 qla2x00_delete_all_vps(ha, base_vha);
3768 qla2x00_dfs_remove(base_vha);
3770 qla84xx_put_chip(base_vha);
3773 if (base_vha->timer_active)
3774 qla2x00_stop_timer(base_vha);
3776 base_vha->flags.online = 0;
3778 /* free DMA memory */
3779 if (ha->exlogin_buf)
3780 qla2x00_free_exlogin_buffer(ha);
3782 /* free DMA memory */
3783 if (ha->exchoffld_buf)
3784 qla2x00_free_exchoffld_buffer(ha);
3786 qla2x00_destroy_deferred_work(ha);
3788 qlt_remove_target(ha, base_vha);
3790 qla2x00_free_sysfs_attr(base_vha, true);
3792 fc_remove_host(base_vha->host);
3793 qlt_remove_target_resources(ha);
3795 scsi_remove_host(base_vha->host);
3797 qla2x00_free_device(base_vha);
3799 qla2x00_clear_drv_active(ha);
3801 scsi_host_put(base_vha->host);
3803 qla2x00_unmap_iobases(ha);
3805 pci_release_selected_regions(ha->pdev, ha->bars);
3808 pci_disable_pcie_error_reporting(pdev);
3810 pci_disable_device(pdev);
3814 qla24xx_free_purex_list(struct purex_list *list)
3816 struct list_head *item, *next;
3819 spin_lock_irqsave(&list->lock, flags);
3820 list_for_each_safe(item, next, &list->head) {
3822 kfree(list_entry(item, struct purex_item, list));
3824 spin_unlock_irqrestore(&list->lock, flags);
3828 qla2x00_free_device(scsi_qla_host_t *vha)
3830 struct qla_hw_data *ha = vha->hw;
3832 qla2x00_abort_all_cmds(vha, DID_NO_CONNECT << 16);
3835 if (vha->timer_active)
3836 qla2x00_stop_timer(vha);
3838 qla25xx_delete_queues(vha);
3839 vha->flags.online = 0;
3841 /* turn-off interrupts on the card */
3842 if (ha->interrupts_on) {
3843 vha->flags.init_done = 0;
3844 ha->isp_ops->disable_intrs(ha);
3847 qla2x00_free_fcports(vha);
3849 qla2x00_free_irqs(vha);
3851 /* Flush the work queue and remove it */
3853 flush_workqueue(ha->wq);
3854 destroy_workqueue(ha->wq);
3859 qla24xx_free_purex_list(&vha->purex_list);
3861 qla2x00_mem_free(ha);
3863 qla82xx_md_free(vha);
3865 qla2x00_free_queues(ha);
3868 void qla2x00_free_fcports(struct scsi_qla_host *vha)
3870 fc_port_t *fcport, *tfcport;
3872 list_for_each_entry_safe(fcport, tfcport, &vha->vp_fcports, list)
3873 qla2x00_free_fcport(fcport);
3877 qla2x00_schedule_rport_del(struct scsi_qla_host *vha, fc_port_t *fcport)
3884 if (fcport->rport) {
3885 ql_dbg(ql_dbg_disc, fcport->vha, 0x2109,
3886 "%s %8phN. rport %p roles %x\n",
3887 __func__, fcport->port_name, fcport->rport,
3888 fcport->rport->roles);
3889 fc_remote_port_delete(fcport->rport);
3891 qlt_do_generation_tick(vha, &now);
3895 * qla2x00_mark_device_lost Updates fcport state when device goes offline.
3897 * Input: ha = adapter block pointer. fcport = port structure pointer.
3903 void qla2x00_mark_device_lost(scsi_qla_host_t *vha, fc_port_t *fcport,
3906 if (IS_QLAFX00(vha->hw)) {
3907 qla2x00_set_fcport_state(fcport, FCS_DEVICE_LOST);
3908 qla2x00_schedule_rport_del(vha, fcport);
3912 if (atomic_read(&fcport->state) == FCS_ONLINE &&
3913 vha->vp_idx == fcport->vha->vp_idx) {
3914 qla2x00_set_fcport_state(fcport, FCS_DEVICE_LOST);
3915 qla2x00_schedule_rport_del(vha, fcport);
3918 * We may need to retry the login, so don't change the state of the
3919 * port but do the retries.
3921 if (atomic_read(&fcport->state) != FCS_DEVICE_DEAD)
3922 qla2x00_set_fcport_state(fcport, FCS_DEVICE_LOST);
3927 set_bit(RELOGIN_NEEDED, &vha->dpc_flags);
3931 qla2x00_mark_all_devices_lost(scsi_qla_host_t *vha)
3935 ql_dbg(ql_dbg_disc, vha, 0x20f1,
3936 "Mark all dev lost\n");
3938 list_for_each_entry(fcport, &vha->vp_fcports, list) {
3939 if (fcport->loop_id != FC_NO_LOOP_ID &&
3940 (fcport->flags & FCF_FCP2_DEVICE) &&
3941 fcport->port_type == FCT_TARGET &&
3942 !qla2x00_reset_active(vha)) {
3943 ql_dbg(ql_dbg_disc, vha, 0x211a,
3944 "Delaying session delete for FCP2 flags 0x%x port_type = 0x%x port_id=%06x %phC",
3945 fcport->flags, fcport->port_type,
3946 fcport->d_id.b24, fcport->port_name);
3949 fcport->scan_state = 0;
3950 qlt_schedule_sess_for_deletion(fcport);
3954 static void qla2x00_set_reserved_loop_ids(struct qla_hw_data *ha)
3958 if (IS_FWI2_CAPABLE(ha))
3961 for (i = 0; i < SNS_FIRST_LOOP_ID; i++)
3962 set_bit(i, ha->loop_id_map);
3963 set_bit(MANAGEMENT_SERVER, ha->loop_id_map);
3964 set_bit(BROADCAST, ha->loop_id_map);
3969 * Allocates adapter memory.
3976 qla2x00_mem_alloc(struct qla_hw_data *ha, uint16_t req_len, uint16_t rsp_len,
3977 struct req_que **req, struct rsp_que **rsp)
3981 ha->init_cb = dma_alloc_coherent(&ha->pdev->dev, ha->init_cb_size,
3982 &ha->init_cb_dma, GFP_KERNEL);
3986 if (qlt_mem_alloc(ha) < 0)
3987 goto fail_free_init_cb;
3989 ha->gid_list = dma_alloc_coherent(&ha->pdev->dev,
3990 qla2x00_gid_list_size(ha), &ha->gid_list_dma, GFP_KERNEL);
3992 goto fail_free_tgt_mem;
3994 ha->srb_mempool = mempool_create_slab_pool(SRB_MIN_REQ, srb_cachep);
3995 if (!ha->srb_mempool)
3996 goto fail_free_gid_list;
3998 if (IS_P3P_TYPE(ha)) {
3999 /* Allocate cache for CT6 Ctx. */
4001 ctx_cachep = kmem_cache_create("qla2xxx_ctx",
4002 sizeof(struct ct6_dsd), 0,
4003 SLAB_HWCACHE_ALIGN, NULL);
4005 goto fail_free_srb_mempool;
4007 ha->ctx_mempool = mempool_create_slab_pool(SRB_MIN_REQ,
4009 if (!ha->ctx_mempool)
4010 goto fail_free_srb_mempool;
4011 ql_dbg_pci(ql_dbg_init, ha->pdev, 0x0021,
4012 "ctx_cachep=%p ctx_mempool=%p.\n",
4013 ctx_cachep, ha->ctx_mempool);
4016 /* Get memory for cached NVRAM */
4017 ha->nvram = kzalloc(MAX_NVRAM_SIZE, GFP_KERNEL);
4019 goto fail_free_ctx_mempool;
4021 snprintf(name, sizeof(name), "%s_%d", QLA2XXX_DRIVER_NAME,
4023 ha->s_dma_pool = dma_pool_create(name, &ha->pdev->dev,
4024 DMA_POOL_SIZE, 8, 0);
4025 if (!ha->s_dma_pool)
4026 goto fail_free_nvram;
4028 ql_dbg_pci(ql_dbg_init, ha->pdev, 0x0022,
4029 "init_cb=%p gid_list=%p, srb_mempool=%p s_dma_pool=%p.\n",
4030 ha->init_cb, ha->gid_list, ha->srb_mempool, ha->s_dma_pool);
4032 if (IS_P3P_TYPE(ha) || ql2xenabledif) {
4033 ha->dl_dma_pool = dma_pool_create(name, &ha->pdev->dev,
4034 DSD_LIST_DMA_POOL_SIZE, 8, 0);
4035 if (!ha->dl_dma_pool) {
4036 ql_log_pci(ql_log_fatal, ha->pdev, 0x0023,
4037 "Failed to allocate memory for dl_dma_pool.\n");
4038 goto fail_s_dma_pool;
4041 ha->fcp_cmnd_dma_pool = dma_pool_create(name, &ha->pdev->dev,
4042 FCP_CMND_DMA_POOL_SIZE, 8, 0);
4043 if (!ha->fcp_cmnd_dma_pool) {
4044 ql_log_pci(ql_log_fatal, ha->pdev, 0x0024,
4045 "Failed to allocate memory for fcp_cmnd_dma_pool.\n");
4046 goto fail_dl_dma_pool;
4049 if (ql2xenabledif) {
4050 u64 bufsize = DIF_BUNDLING_DMA_POOL_SIZE;
4051 struct dsd_dma *dsd, *nxt;
4053 /* Creata a DMA pool of buffers for DIF bundling */
4054 ha->dif_bundl_pool = dma_pool_create(name,
4055 &ha->pdev->dev, DIF_BUNDLING_DMA_POOL_SIZE, 8, 0);
4056 if (!ha->dif_bundl_pool) {
4057 ql_dbg_pci(ql_dbg_init, ha->pdev, 0x0024,
4058 "%s: failed create dif_bundl_pool\n",
4060 goto fail_dif_bundl_dma_pool;
4063 INIT_LIST_HEAD(&ha->pool.good.head);
4064 INIT_LIST_HEAD(&ha->pool.unusable.head);
4065 ha->pool.good.count = 0;
4066 ha->pool.unusable.count = 0;
4067 for (i = 0; i < 128; i++) {
4068 dsd = kzalloc(sizeof(*dsd), GFP_ATOMIC);
4070 ql_dbg_pci(ql_dbg_init, ha->pdev,
4071 0xe0ee, "%s: failed alloc dsd\n",
4075 ha->dif_bundle_kallocs++;
4077 dsd->dsd_addr = dma_pool_alloc(
4078 ha->dif_bundl_pool, GFP_ATOMIC,
4079 &dsd->dsd_list_dma);
4080 if (!dsd->dsd_addr) {
4081 ql_dbg_pci(ql_dbg_init, ha->pdev,
4083 "%s: failed alloc ->dsd_addr\n",
4086 ha->dif_bundle_kallocs--;
4089 ha->dif_bundle_dma_allocs++;
4092 * if DMA buffer crosses 4G boundary,
4093 * put it on bad list
4095 if (MSD(dsd->dsd_list_dma) ^
4096 MSD(dsd->dsd_list_dma + bufsize)) {
4097 list_add_tail(&dsd->list,
4098 &ha->pool.unusable.head);
4099 ha->pool.unusable.count++;
4101 list_add_tail(&dsd->list,
4102 &ha->pool.good.head);
4103 ha->pool.good.count++;
4107 /* return the good ones back to the pool */
4108 list_for_each_entry_safe(dsd, nxt,
4109 &ha->pool.good.head, list) {
4110 list_del(&dsd->list);
4111 dma_pool_free(ha->dif_bundl_pool,
4112 dsd->dsd_addr, dsd->dsd_list_dma);
4113 ha->dif_bundle_dma_allocs--;
4115 ha->dif_bundle_kallocs--;
4118 ql_dbg_pci(ql_dbg_init, ha->pdev, 0x0024,
4119 "%s: dif dma pool (good=%u unusable=%u)\n",
4120 __func__, ha->pool.good.count,
4121 ha->pool.unusable.count);
4124 ql_dbg_pci(ql_dbg_init, ha->pdev, 0x0025,
4125 "dl_dma_pool=%p fcp_cmnd_dma_pool=%p dif_bundl_pool=%p.\n",
4126 ha->dl_dma_pool, ha->fcp_cmnd_dma_pool,
4127 ha->dif_bundl_pool);
4130 /* Allocate memory for SNS commands */
4131 if (IS_QLA2100(ha) || IS_QLA2200(ha)) {
4132 /* Get consistent memory allocated for SNS commands */
4133 ha->sns_cmd = dma_alloc_coherent(&ha->pdev->dev,
4134 sizeof(struct sns_cmd_pkt), &ha->sns_cmd_dma, GFP_KERNEL);
4137 ql_dbg_pci(ql_dbg_init, ha->pdev, 0x0026,
4138 "sns_cmd: %p.\n", ha->sns_cmd);
4140 /* Get consistent memory allocated for MS IOCB */
4141 ha->ms_iocb = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL,
4145 /* Get consistent memory allocated for CT SNS commands */
4146 ha->ct_sns = dma_alloc_coherent(&ha->pdev->dev,
4147 sizeof(struct ct_sns_pkt), &ha->ct_sns_dma, GFP_KERNEL);
4149 goto fail_free_ms_iocb;
4150 ql_dbg_pci(ql_dbg_init, ha->pdev, 0x0027,
4151 "ms_iocb=%p ct_sns=%p.\n",
4152 ha->ms_iocb, ha->ct_sns);
4155 /* Allocate memory for request ring */
4156 *req = kzalloc(sizeof(struct req_que), GFP_KERNEL);
4158 ql_log_pci(ql_log_fatal, ha->pdev, 0x0028,
4159 "Failed to allocate memory for req.\n");
4162 (*req)->length = req_len;
4163 (*req)->ring = dma_alloc_coherent(&ha->pdev->dev,
4164 ((*req)->length + 1) * sizeof(request_t),
4165 &(*req)->dma, GFP_KERNEL);
4166 if (!(*req)->ring) {
4167 ql_log_pci(ql_log_fatal, ha->pdev, 0x0029,
4168 "Failed to allocate memory for req_ring.\n");
4171 /* Allocate memory for response ring */
4172 *rsp = kzalloc(sizeof(struct rsp_que), GFP_KERNEL);
4174 ql_log_pci(ql_log_fatal, ha->pdev, 0x002a,
4175 "Failed to allocate memory for rsp.\n");
4179 (*rsp)->length = rsp_len;
4180 (*rsp)->ring = dma_alloc_coherent(&ha->pdev->dev,
4181 ((*rsp)->length + 1) * sizeof(response_t),
4182 &(*rsp)->dma, GFP_KERNEL);
4183 if (!(*rsp)->ring) {
4184 ql_log_pci(ql_log_fatal, ha->pdev, 0x002b,
4185 "Failed to allocate memory for rsp_ring.\n");
4190 ql_dbg_pci(ql_dbg_init, ha->pdev, 0x002c,
4191 "req=%p req->length=%d req->ring=%p rsp=%p "
4192 "rsp->length=%d rsp->ring=%p.\n",
4193 *req, (*req)->length, (*req)->ring, *rsp, (*rsp)->length,
4195 /* Allocate memory for NVRAM data for vports */
4196 if (ha->nvram_npiv_size) {
4197 ha->npiv_info = kcalloc(ha->nvram_npiv_size,
4198 sizeof(struct qla_npiv_entry),
4200 if (!ha->npiv_info) {
4201 ql_log_pci(ql_log_fatal, ha->pdev, 0x002d,
4202 "Failed to allocate memory for npiv_info.\n");
4203 goto fail_npiv_info;
4206 ha->npiv_info = NULL;
4208 /* Get consistent memory allocated for EX-INIT-CB. */
4209 if (IS_CNA_CAPABLE(ha) || IS_QLA2031(ha) || IS_QLA27XX(ha) ||
4211 ha->ex_init_cb = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL,
4212 &ha->ex_init_cb_dma);
4213 if (!ha->ex_init_cb)
4214 goto fail_ex_init_cb;
4215 ql_dbg_pci(ql_dbg_init, ha->pdev, 0x002e,
4216 "ex_init_cb=%p.\n", ha->ex_init_cb);
4219 /* Get consistent memory allocated for Special Features-CB. */
4220 if (IS_QLA27XX(ha) || IS_QLA28XX(ha)) {
4221 ha->sf_init_cb = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL,
4222 &ha->sf_init_cb_dma);
4223 if (!ha->sf_init_cb)
4224 goto fail_sf_init_cb;
4225 memset(ha->sf_init_cb, 0, sizeof(struct init_sf_cb));
4226 ql_dbg_pci(ql_dbg_init, ha->pdev, 0x0199,
4227 "sf_init_cb=%p.\n", ha->sf_init_cb);
4230 INIT_LIST_HEAD(&ha->gbl_dsd_list);
4232 /* Get consistent memory allocated for Async Port-Database. */
4233 if (!IS_FWI2_CAPABLE(ha)) {
4234 ha->async_pd = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL,
4238 ql_dbg_pci(ql_dbg_init, ha->pdev, 0x002f,
4239 "async_pd=%p.\n", ha->async_pd);
4242 INIT_LIST_HEAD(&ha->vp_list);
4244 /* Allocate memory for our loop_id bitmap */
4245 ha->loop_id_map = kcalloc(BITS_TO_LONGS(LOOPID_MAP_SIZE),
4248 if (!ha->loop_id_map)
4249 goto fail_loop_id_map;
4251 qla2x00_set_reserved_loop_ids(ha);
4252 ql_dbg_pci(ql_dbg_init, ha->pdev, 0x0123,
4253 "loop_id_map=%p.\n", ha->loop_id_map);
4256 ha->sfp_data = dma_alloc_coherent(&ha->pdev->dev,
4257 SFP_DEV_SIZE, &ha->sfp_data_dma, GFP_KERNEL);
4258 if (!ha->sfp_data) {
4259 ql_dbg_pci(ql_dbg_init, ha->pdev, 0x011b,
4260 "Unable to allocate memory for SFP read-data.\n");
4264 ha->flt = dma_alloc_coherent(&ha->pdev->dev,
4265 sizeof(struct qla_flt_header) + FLT_REGIONS_SIZE, &ha->flt_dma,
4268 ql_dbg_pci(ql_dbg_init, ha->pdev, 0x011b,
4269 "Unable to allocate memory for FLT.\n");
4270 goto fail_flt_buffer;
4276 dma_free_coherent(&ha->pdev->dev, SFP_DEV_SIZE,
4277 ha->sfp_data, ha->sfp_data_dma);
4279 kfree(ha->loop_id_map);
4281 dma_pool_free(ha->s_dma_pool, ha->async_pd, ha->async_pd_dma);
4283 dma_pool_free(ha->s_dma_pool, ha->sf_init_cb, ha->sf_init_cb_dma);
4285 dma_pool_free(ha->s_dma_pool, ha->ex_init_cb, ha->ex_init_cb_dma);
4287 kfree(ha->npiv_info);
4289 dma_free_coherent(&ha->pdev->dev, ((*rsp)->length + 1) *
4290 sizeof(response_t), (*rsp)->ring, (*rsp)->dma);
4291 (*rsp)->ring = NULL;
4297 dma_free_coherent(&ha->pdev->dev, ((*req)->length + 1) *
4298 sizeof(request_t), (*req)->ring, (*req)->dma);
4299 (*req)->ring = NULL;
4305 dma_free_coherent(&ha->pdev->dev, sizeof(struct ct_sns_pkt),
4306 ha->ct_sns, ha->ct_sns_dma);
4310 dma_pool_free(ha->s_dma_pool, ha->ms_iocb, ha->ms_iocb_dma);
4312 ha->ms_iocb_dma = 0;
4315 dma_free_coherent(&ha->pdev->dev, sizeof(struct sns_cmd_pkt),
4316 ha->sns_cmd, ha->sns_cmd_dma);
4318 if (ql2xenabledif) {
4319 struct dsd_dma *dsd, *nxt;
4321 list_for_each_entry_safe(dsd, nxt, &ha->pool.unusable.head,
4323 list_del(&dsd->list);
4324 dma_pool_free(ha->dif_bundl_pool, dsd->dsd_addr,
4326 ha->dif_bundle_dma_allocs--;
4328 ha->dif_bundle_kallocs--;
4329 ha->pool.unusable.count--;
4331 dma_pool_destroy(ha->dif_bundl_pool);
4332 ha->dif_bundl_pool = NULL;
4335 fail_dif_bundl_dma_pool:
4336 if (IS_QLA82XX(ha) || ql2xenabledif) {
4337 dma_pool_destroy(ha->fcp_cmnd_dma_pool);
4338 ha->fcp_cmnd_dma_pool = NULL;
4341 if (IS_QLA82XX(ha) || ql2xenabledif) {
4342 dma_pool_destroy(ha->dl_dma_pool);
4343 ha->dl_dma_pool = NULL;
4346 dma_pool_destroy(ha->s_dma_pool);
4347 ha->s_dma_pool = NULL;
4351 fail_free_ctx_mempool:
4352 mempool_destroy(ha->ctx_mempool);
4353 ha->ctx_mempool = NULL;
4354 fail_free_srb_mempool:
4355 mempool_destroy(ha->srb_mempool);
4356 ha->srb_mempool = NULL;
4358 dma_free_coherent(&ha->pdev->dev, qla2x00_gid_list_size(ha),
4361 ha->gid_list = NULL;
4362 ha->gid_list_dma = 0;
4366 dma_free_coherent(&ha->pdev->dev, ha->init_cb_size, ha->init_cb,
4369 ha->init_cb_dma = 0;
4371 ql_log(ql_log_fatal, NULL, 0x0030,
4372 "Memory allocation failure.\n");
4377 qla2x00_set_exlogins_buffer(scsi_qla_host_t *vha)
4380 uint16_t size, max_cnt;
4382 struct qla_hw_data *ha = vha->hw;
4384 /* Return if we don't need to alloacate any extended logins */
4385 if (ql2xexlogins <= MAX_FIBRE_DEVICES_2400)
4388 if (!IS_EXLOGIN_OFFLD_CAPABLE(ha))
4391 ql_log(ql_log_info, vha, 0xd021, "EXLOGIN count: %d.\n", ql2xexlogins);
4393 rval = qla_get_exlogin_status(vha, &size, &max_cnt);
4394 if (rval != QLA_SUCCESS) {
4395 ql_log_pci(ql_log_fatal, ha->pdev, 0xd029,
4396 "Failed to get exlogin status.\n");
4400 temp = (ql2xexlogins > max_cnt) ? max_cnt : ql2xexlogins;
4403 if (temp != ha->exlogin_size) {
4404 qla2x00_free_exlogin_buffer(ha);
4405 ha->exlogin_size = temp;
4407 ql_log(ql_log_info, vha, 0xd024,
4408 "EXLOGIN: max_logins=%d, portdb=0x%x, total=%d.\n",
4409 max_cnt, size, temp);
4411 ql_log(ql_log_info, vha, 0xd025,
4412 "EXLOGIN: requested size=0x%x\n", ha->exlogin_size);
4414 /* Get consistent memory for extended logins */
4415 ha->exlogin_buf = dma_alloc_coherent(&ha->pdev->dev,
4416 ha->exlogin_size, &ha->exlogin_buf_dma, GFP_KERNEL);
4417 if (!ha->exlogin_buf) {
4418 ql_log_pci(ql_log_fatal, ha->pdev, 0xd02a,
4419 "Failed to allocate memory for exlogin_buf_dma.\n");
4424 /* Now configure the dma buffer */
4425 rval = qla_set_exlogin_mem_cfg(vha, ha->exlogin_buf_dma);
4427 ql_log(ql_log_fatal, vha, 0xd033,
4428 "Setup extended login buffer ****FAILED****.\n");
4429 qla2x00_free_exlogin_buffer(ha);
4436 * qla2x00_free_exlogin_buffer
4439 * ha = adapter block pointer
4442 qla2x00_free_exlogin_buffer(struct qla_hw_data *ha)
4444 if (ha->exlogin_buf) {
4445 dma_free_coherent(&ha->pdev->dev, ha->exlogin_size,
4446 ha->exlogin_buf, ha->exlogin_buf_dma);
4447 ha->exlogin_buf = NULL;
4448 ha->exlogin_size = 0;
4453 qla2x00_number_of_exch(scsi_qla_host_t *vha, u32 *ret_cnt, u16 max_cnt)
4456 struct init_cb_81xx *icb = (struct init_cb_81xx *)&vha->hw->init_cb;
4457 *ret_cnt = FW_DEF_EXCHANGES_CNT;
4459 if (max_cnt > vha->hw->max_exchg)
4460 max_cnt = vha->hw->max_exchg;
4462 if (qla_ini_mode_enabled(vha)) {
4463 if (vha->ql2xiniexchg > max_cnt)
4464 vha->ql2xiniexchg = max_cnt;
4466 if (vha->ql2xiniexchg > FW_DEF_EXCHANGES_CNT)
4467 *ret_cnt = vha->ql2xiniexchg;
4469 } else if (qla_tgt_mode_enabled(vha)) {
4470 if (vha->ql2xexchoffld > max_cnt) {
4471 vha->ql2xexchoffld = max_cnt;
4472 icb->exchange_count = cpu_to_le16(vha->ql2xexchoffld);
4475 if (vha->ql2xexchoffld > FW_DEF_EXCHANGES_CNT)
4476 *ret_cnt = vha->ql2xexchoffld;
4477 } else if (qla_dual_mode_enabled(vha)) {
4478 temp = vha->ql2xiniexchg + vha->ql2xexchoffld;
4479 if (temp > max_cnt) {
4480 vha->ql2xiniexchg -= (temp - max_cnt)/2;
4481 vha->ql2xexchoffld -= (((temp - max_cnt)/2) + 1);
4483 icb->exchange_count = cpu_to_le16(vha->ql2xexchoffld);
4486 if (temp > FW_DEF_EXCHANGES_CNT)
4492 qla2x00_set_exchoffld_buffer(scsi_qla_host_t *vha)
4496 u32 actual_cnt, totsz;
4497 struct qla_hw_data *ha = vha->hw;
4499 if (!ha->flags.exchoffld_enabled)
4502 if (!IS_EXCHG_OFFLD_CAPABLE(ha))
4506 rval = qla_get_exchoffld_status(vha, &size, &max_cnt);
4507 if (rval != QLA_SUCCESS) {
4508 ql_log_pci(ql_log_fatal, ha->pdev, 0xd012,
4509 "Failed to get exlogin status.\n");
4513 qla2x00_number_of_exch(vha, &actual_cnt, max_cnt);
4514 ql_log(ql_log_info, vha, 0xd014,
4515 "Actual exchange offload count: %d.\n", actual_cnt);
4517 totsz = actual_cnt * size;
4519 if (totsz != ha->exchoffld_size) {
4520 qla2x00_free_exchoffld_buffer(ha);
4521 if (actual_cnt <= FW_DEF_EXCHANGES_CNT) {
4522 ha->exchoffld_size = 0;
4523 ha->flags.exchoffld_enabled = 0;
4527 ha->exchoffld_size = totsz;
4529 ql_log(ql_log_info, vha, 0xd016,
4530 "Exchange offload: max_count=%d, actual count=%d entry sz=0x%x, total sz=0x%x\n",
4531 max_cnt, actual_cnt, size, totsz);
4533 ql_log(ql_log_info, vha, 0xd017,
4534 "Exchange Buffers requested size = 0x%x\n",
4535 ha->exchoffld_size);
4537 /* Get consistent memory for extended logins */
4538 ha->exchoffld_buf = dma_alloc_coherent(&ha->pdev->dev,
4539 ha->exchoffld_size, &ha->exchoffld_buf_dma, GFP_KERNEL);
4540 if (!ha->exchoffld_buf) {
4541 ql_log_pci(ql_log_fatal, ha->pdev, 0xd013,
4542 "Failed to allocate memory for Exchange Offload.\n");
4545 (FW_DEF_EXCHANGES_CNT + REDUCE_EXCHANGES_CNT)) {
4546 ha->max_exchg -= REDUCE_EXCHANGES_CNT;
4547 } else if (ha->max_exchg >
4548 (FW_DEF_EXCHANGES_CNT + 512)) {
4549 ha->max_exchg -= 512;
4551 ha->flags.exchoffld_enabled = 0;
4552 ql_log_pci(ql_log_fatal, ha->pdev, 0xd013,
4553 "Disabling Exchange offload due to lack of memory\n");
4555 ha->exchoffld_size = 0;
4559 } else if (!ha->exchoffld_buf || (actual_cnt <= FW_DEF_EXCHANGES_CNT)) {
4560 /* pathological case */
4561 qla2x00_free_exchoffld_buffer(ha);
4562 ha->exchoffld_size = 0;
4563 ha->flags.exchoffld_enabled = 0;
4564 ql_log(ql_log_info, vha, 0xd016,
4565 "Exchange offload not enable: offld size=%d, actual count=%d entry sz=0x%x, total sz=0x%x.\n",
4566 ha->exchoffld_size, actual_cnt, size, totsz);
4570 /* Now configure the dma buffer */
4571 rval = qla_set_exchoffld_mem_cfg(vha);
4573 ql_log(ql_log_fatal, vha, 0xd02e,
4574 "Setup exchange offload buffer ****FAILED****.\n");
4575 qla2x00_free_exchoffld_buffer(ha);
4577 /* re-adjust number of target exchange */
4578 struct init_cb_81xx *icb = (struct init_cb_81xx *)ha->init_cb;
4580 if (qla_ini_mode_enabled(vha))
4581 icb->exchange_count = 0;
4583 icb->exchange_count = cpu_to_le16(vha->ql2xexchoffld);
4590 * qla2x00_free_exchoffld_buffer
4593 * ha = adapter block pointer
4596 qla2x00_free_exchoffld_buffer(struct qla_hw_data *ha)
4598 if (ha->exchoffld_buf) {
4599 dma_free_coherent(&ha->pdev->dev, ha->exchoffld_size,
4600 ha->exchoffld_buf, ha->exchoffld_buf_dma);
4601 ha->exchoffld_buf = NULL;
4602 ha->exchoffld_size = 0;
4607 * qla2x00_free_fw_dump
4608 * Frees fw dump stuff.
4611 * ha = adapter block pointer
4614 qla2x00_free_fw_dump(struct qla_hw_data *ha)
4616 struct fwdt *fwdt = ha->fwdt;
4620 dma_free_coherent(&ha->pdev->dev,
4621 FCE_SIZE, ha->fce, ha->fce_dma);
4624 dma_free_coherent(&ha->pdev->dev,
4625 EFT_SIZE, ha->eft, ha->eft_dma);
4632 ha->flags.fce_enabled = 0;
4635 ha->fw_dumped = false;
4636 ha->fw_dump_cap_flags = 0;
4637 ha->fw_dump_reading = 0;
4639 ha->fw_dump_len = 0;
4641 for (j = 0; j < 2; j++, fwdt++) {
4643 vfree(fwdt->template);
4644 fwdt->template = NULL;
4651 * Frees all adapter allocated memory.
4654 * ha = adapter block pointer.
4657 qla2x00_mem_free(struct qla_hw_data *ha)
4659 qla2x00_free_fw_dump(ha);
4662 dma_free_coherent(&ha->pdev->dev, MCTP_DUMP_SIZE, ha->mctp_dump,
4664 ha->mctp_dump = NULL;
4666 mempool_destroy(ha->srb_mempool);
4667 ha->srb_mempool = NULL;
4670 dma_free_coherent(&ha->pdev->dev, DCBX_TLV_DATA_SIZE,
4671 ha->dcbx_tlv, ha->dcbx_tlv_dma);
4672 ha->dcbx_tlv = NULL;
4675 dma_free_coherent(&ha->pdev->dev, XGMAC_DATA_SIZE,
4676 ha->xgmac_data, ha->xgmac_data_dma);
4677 ha->xgmac_data = NULL;
4680 dma_free_coherent(&ha->pdev->dev, sizeof(struct sns_cmd_pkt),
4681 ha->sns_cmd, ha->sns_cmd_dma);
4683 ha->sns_cmd_dma = 0;
4686 dma_free_coherent(&ha->pdev->dev, sizeof(struct ct_sns_pkt),
4687 ha->ct_sns, ha->ct_sns_dma);
4692 dma_free_coherent(&ha->pdev->dev, SFP_DEV_SIZE, ha->sfp_data,
4694 ha->sfp_data = NULL;
4697 dma_free_coherent(&ha->pdev->dev,
4698 sizeof(struct qla_flt_header) + FLT_REGIONS_SIZE,
4699 ha->flt, ha->flt_dma);
4704 dma_pool_free(ha->s_dma_pool, ha->ms_iocb, ha->ms_iocb_dma);
4706 ha->ms_iocb_dma = 0;
4709 dma_pool_free(ha->s_dma_pool,
4710 ha->sf_init_cb, ha->sf_init_cb_dma);
4713 dma_pool_free(ha->s_dma_pool,
4714 ha->ex_init_cb, ha->ex_init_cb_dma);
4715 ha->ex_init_cb = NULL;
4716 ha->ex_init_cb_dma = 0;
4719 dma_pool_free(ha->s_dma_pool, ha->async_pd, ha->async_pd_dma);
4720 ha->async_pd = NULL;
4721 ha->async_pd_dma = 0;
4723 dma_pool_destroy(ha->s_dma_pool);
4724 ha->s_dma_pool = NULL;
4727 dma_free_coherent(&ha->pdev->dev, qla2x00_gid_list_size(ha),
4728 ha->gid_list, ha->gid_list_dma);
4729 ha->gid_list = NULL;
4730 ha->gid_list_dma = 0;
4732 if (IS_QLA82XX(ha)) {
4733 if (!list_empty(&ha->gbl_dsd_list)) {
4734 struct dsd_dma *dsd_ptr, *tdsd_ptr;
4736 /* clean up allocated prev pool */
4737 list_for_each_entry_safe(dsd_ptr,
4738 tdsd_ptr, &ha->gbl_dsd_list, list) {
4739 dma_pool_free(ha->dl_dma_pool,
4740 dsd_ptr->dsd_addr, dsd_ptr->dsd_list_dma);
4741 list_del(&dsd_ptr->list);
4747 dma_pool_destroy(ha->dl_dma_pool);
4748 ha->dl_dma_pool = NULL;
4750 dma_pool_destroy(ha->fcp_cmnd_dma_pool);
4751 ha->fcp_cmnd_dma_pool = NULL;
4753 mempool_destroy(ha->ctx_mempool);
4754 ha->ctx_mempool = NULL;
4756 if (ql2xenabledif && ha->dif_bundl_pool) {
4757 struct dsd_dma *dsd, *nxt;
4759 list_for_each_entry_safe(dsd, nxt, &ha->pool.unusable.head,
4761 list_del(&dsd->list);
4762 dma_pool_free(ha->dif_bundl_pool, dsd->dsd_addr,
4764 ha->dif_bundle_dma_allocs--;
4766 ha->dif_bundle_kallocs--;
4767 ha->pool.unusable.count--;
4769 list_for_each_entry_safe(dsd, nxt, &ha->pool.good.head, list) {
4770 list_del(&dsd->list);
4771 dma_pool_free(ha->dif_bundl_pool, dsd->dsd_addr,
4773 ha->dif_bundle_dma_allocs--;
4775 ha->dif_bundle_kallocs--;
4779 dma_pool_destroy(ha->dif_bundl_pool);
4780 ha->dif_bundl_pool = NULL;
4785 dma_free_coherent(&ha->pdev->dev, ha->init_cb_size,
4786 ha->init_cb, ha->init_cb_dma);
4788 ha->init_cb_dma = 0;
4790 vfree(ha->optrom_buffer);
4791 ha->optrom_buffer = NULL;
4794 kfree(ha->npiv_info);
4795 ha->npiv_info = NULL;
4798 kfree(ha->loop_id_map);
4799 ha->sf_init_cb = NULL;
4800 ha->sf_init_cb_dma = 0;
4801 ha->loop_id_map = NULL;
4804 struct scsi_qla_host *qla2x00_create_host(struct scsi_host_template *sht,
4805 struct qla_hw_data *ha)
4807 struct Scsi_Host *host;
4808 struct scsi_qla_host *vha = NULL;
4810 host = scsi_host_alloc(sht, sizeof(scsi_qla_host_t));
4812 ql_log_pci(ql_log_fatal, ha->pdev, 0x0107,
4813 "Failed to allocate host from the scsi layer, aborting.\n");
4817 /* Clear our data area */
4818 vha = shost_priv(host);
4819 memset(vha, 0, sizeof(scsi_qla_host_t));
4822 vha->host_no = host->host_no;
4825 vha->qlini_mode = ql2x_ini_mode;
4826 vha->ql2xexchoffld = ql2xexchoffld;
4827 vha->ql2xiniexchg = ql2xiniexchg;
4829 INIT_LIST_HEAD(&vha->vp_fcports);
4830 INIT_LIST_HEAD(&vha->work_list);
4831 INIT_LIST_HEAD(&vha->list);
4832 INIT_LIST_HEAD(&vha->qla_cmd_list);
4833 INIT_LIST_HEAD(&vha->qla_sess_op_cmd_list);
4834 INIT_LIST_HEAD(&vha->logo_list);
4835 INIT_LIST_HEAD(&vha->plogi_ack_list);
4836 INIT_LIST_HEAD(&vha->qp_list);
4837 INIT_LIST_HEAD(&vha->gnl.fcports);
4838 INIT_LIST_HEAD(&vha->gpnid_list);
4839 INIT_WORK(&vha->iocb_work, qla2x00_iocb_work_fn);
4841 INIT_LIST_HEAD(&vha->purex_list.head);
4842 spin_lock_init(&vha->purex_list.lock);
4844 spin_lock_init(&vha->work_lock);
4845 spin_lock_init(&vha->cmd_list_lock);
4846 init_waitqueue_head(&vha->fcport_waitQ);
4847 init_waitqueue_head(&vha->vref_waitq);
4849 vha->gnl.size = sizeof(struct get_name_list_extended) *
4850 (ha->max_loop_id + 1);
4851 vha->gnl.l = dma_alloc_coherent(&ha->pdev->dev,
4852 vha->gnl.size, &vha->gnl.ldma, GFP_KERNEL);
4854 ql_log(ql_log_fatal, vha, 0xd04a,
4855 "Alloc failed for name list.\n");
4856 scsi_host_put(vha->host);
4860 /* todo: what about ext login? */
4861 vha->scan.size = ha->max_fibre_devices * sizeof(struct fab_scan_rp);
4862 vha->scan.l = vmalloc(vha->scan.size);
4864 ql_log(ql_log_fatal, vha, 0xd04a,
4865 "Alloc failed for scan database.\n");
4866 dma_free_coherent(&ha->pdev->dev, vha->gnl.size,
4867 vha->gnl.l, vha->gnl.ldma);
4869 scsi_host_put(vha->host);
4872 INIT_DELAYED_WORK(&vha->scan.scan_work, qla_scan_work_fn);
4874 snprintf(vha->host_str, sizeof(vha->host_str), "%s_%lu",
4875 QLA2XXX_DRIVER_NAME, vha->host_no);
4876 ql_dbg(ql_dbg_init, vha, 0x0041,
4877 "Allocated the host=%p hw=%p vha=%p dev_name=%s",
4878 vha->host, vha->hw, vha,
4879 dev_name(&(ha->pdev->dev)));
4884 struct qla_work_evt *
4885 qla2x00_alloc_work(struct scsi_qla_host *vha, enum qla_work_type type)
4887 struct qla_work_evt *e;
4890 if (test_bit(UNLOADING, &vha->dpc_flags))
4893 QLA_VHA_MARK_BUSY(vha, bail);
4897 e = kzalloc(sizeof(struct qla_work_evt), GFP_ATOMIC);
4899 QLA_VHA_MARK_NOT_BUSY(vha);
4903 INIT_LIST_HEAD(&e->list);
4905 e->flags = QLA_EVT_FLAG_FREE;
4910 qla2x00_post_work(struct scsi_qla_host *vha, struct qla_work_evt *e)
4912 unsigned long flags;
4915 spin_lock_irqsave(&vha->work_lock, flags);
4916 list_add_tail(&e->list, &vha->work_list);
4918 if (!test_and_set_bit(IOCB_WORK_ACTIVE, &vha->dpc_flags))
4921 spin_unlock_irqrestore(&vha->work_lock, flags);
4924 queue_work(vha->hw->wq, &vha->iocb_work);
4930 qla2x00_post_aen_work(struct scsi_qla_host *vha, enum fc_host_event_code code,
4933 struct qla_work_evt *e;
4935 e = qla2x00_alloc_work(vha, QLA_EVT_AEN);
4937 return QLA_FUNCTION_FAILED;
4939 e->u.aen.code = code;
4940 e->u.aen.data = data;
4941 return qla2x00_post_work(vha, e);
4945 qla2x00_post_idc_ack_work(struct scsi_qla_host *vha, uint16_t *mb)
4947 struct qla_work_evt *e;
4949 e = qla2x00_alloc_work(vha, QLA_EVT_IDC_ACK);
4951 return QLA_FUNCTION_FAILED;
4953 memcpy(e->u.idc_ack.mb, mb, QLA_IDC_ACK_REGS * sizeof(uint16_t));
4954 return qla2x00_post_work(vha, e);
4957 #define qla2x00_post_async_work(name, type) \
4958 int qla2x00_post_async_##name##_work( \
4959 struct scsi_qla_host *vha, \
4960 fc_port_t *fcport, uint16_t *data) \
4962 struct qla_work_evt *e; \
4964 e = qla2x00_alloc_work(vha, type); \
4966 return QLA_FUNCTION_FAILED; \
4968 e->u.logio.fcport = fcport; \
4970 e->u.logio.data[0] = data[0]; \
4971 e->u.logio.data[1] = data[1]; \
4973 fcport->flags |= FCF_ASYNC_ACTIVE; \
4974 return qla2x00_post_work(vha, e); \
4977 qla2x00_post_async_work(login, QLA_EVT_ASYNC_LOGIN);
4978 qla2x00_post_async_work(logout, QLA_EVT_ASYNC_LOGOUT);
4979 qla2x00_post_async_work(adisc, QLA_EVT_ASYNC_ADISC);
4980 qla2x00_post_async_work(prlo, QLA_EVT_ASYNC_PRLO);
4981 qla2x00_post_async_work(prlo_done, QLA_EVT_ASYNC_PRLO_DONE);
4984 qla2x00_post_uevent_work(struct scsi_qla_host *vha, u32 code)
4986 struct qla_work_evt *e;
4988 e = qla2x00_alloc_work(vha, QLA_EVT_UEVENT);
4990 return QLA_FUNCTION_FAILED;
4992 e->u.uevent.code = code;
4993 return qla2x00_post_work(vha, e);
4997 qla2x00_uevent_emit(struct scsi_qla_host *vha, u32 code)
4999 char event_string[40];
5000 char *envp[] = { event_string, NULL };
5003 case QLA_UEVENT_CODE_FW_DUMP:
5004 snprintf(event_string, sizeof(event_string), "FW_DUMP=%lu",
5011 kobject_uevent_env(&vha->hw->pdev->dev.kobj, KOBJ_CHANGE, envp);
5015 qlafx00_post_aenfx_work(struct scsi_qla_host *vha, uint32_t evtcode,
5016 uint32_t *data, int cnt)
5018 struct qla_work_evt *e;
5020 e = qla2x00_alloc_work(vha, QLA_EVT_AENFX);
5022 return QLA_FUNCTION_FAILED;
5024 e->u.aenfx.evtcode = evtcode;
5025 e->u.aenfx.count = cnt;
5026 memcpy(e->u.aenfx.mbx, data, sizeof(*data) * cnt);
5027 return qla2x00_post_work(vha, e);
5030 void qla24xx_sched_upd_fcport(fc_port_t *fcport)
5032 unsigned long flags;
5034 if (IS_SW_RESV_ADDR(fcport->d_id))
5037 spin_lock_irqsave(&fcport->vha->work_lock, flags);
5038 if (fcport->disc_state == DSC_UPD_FCPORT) {
5039 spin_unlock_irqrestore(&fcport->vha->work_lock, flags);
5042 fcport->jiffies_at_registration = jiffies;
5043 fcport->sec_since_registration = 0;
5044 fcport->next_disc_state = DSC_DELETED;
5045 qla2x00_set_fcport_disc_state(fcport, DSC_UPD_FCPORT);
5046 spin_unlock_irqrestore(&fcport->vha->work_lock, flags);
5048 queue_work(system_unbound_wq, &fcport->reg_work);
5052 void qla24xx_create_new_sess(struct scsi_qla_host *vha, struct qla_work_evt *e)
5054 unsigned long flags;
5055 fc_port_t *fcport = NULL, *tfcp;
5056 struct qlt_plogi_ack_t *pla =
5057 (struct qlt_plogi_ack_t *)e->u.new_sess.pla;
5058 uint8_t free_fcport = 0;
5060 ql_dbg(ql_dbg_disc, vha, 0xffff,
5061 "%s %d %8phC enter\n",
5062 __func__, __LINE__, e->u.new_sess.port_name);
5064 spin_lock_irqsave(&vha->hw->tgt.sess_lock, flags);
5065 fcport = qla2x00_find_fcport_by_wwpn(vha, e->u.new_sess.port_name, 1);
5067 fcport->d_id = e->u.new_sess.id;
5069 fcport->fw_login_state = DSC_LS_PLOGI_PEND;
5070 memcpy(fcport->node_name,
5071 pla->iocb.u.isp24.u.plogi.node_name,
5073 qlt_plogi_ack_link(vha, pla, fcport, QLT_PLOGI_LINK_SAME_WWN);
5074 /* we took an extra ref_count to prevent PLOGI ACK when
5075 * fcport/sess has not been created.
5080 spin_unlock_irqrestore(&vha->hw->tgt.sess_lock, flags);
5081 fcport = qla2x00_alloc_fcport(vha, GFP_KERNEL);
5083 fcport->d_id = e->u.new_sess.id;
5084 fcport->flags |= FCF_FABRIC_DEVICE;
5085 fcport->fw_login_state = DSC_LS_PLOGI_PEND;
5087 memcpy(fcport->port_name, e->u.new_sess.port_name,
5090 fcport->fc4_type = e->u.new_sess.fc4_type;
5091 if (e->u.new_sess.fc4_type & FS_FCP_IS_N2N) {
5092 fcport->dm_login_expire = jiffies +
5093 QLA_N2N_WAIT_TIME * HZ;
5094 fcport->fc4_type = FS_FC4TYPE_FCP;
5095 fcport->n2n_flag = 1;
5096 if (vha->flags.nvme_enabled)
5097 fcport->fc4_type |= FS_FC4TYPE_NVME;
5101 ql_dbg(ql_dbg_disc, vha, 0xffff,
5102 "%s %8phC mem alloc fail.\n",
5103 __func__, e->u.new_sess.port_name);
5106 list_del(&pla->list);
5107 kmem_cache_free(qla_tgt_plogi_cachep, pla);
5112 spin_lock_irqsave(&vha->hw->tgt.sess_lock, flags);
5113 /* search again to make sure no one else got ahead */
5114 tfcp = qla2x00_find_fcport_by_wwpn(vha,
5115 e->u.new_sess.port_name, 1);
5117 /* should rarily happen */
5118 ql_dbg(ql_dbg_disc, vha, 0xffff,
5119 "%s %8phC found existing fcport b4 add. DS %d LS %d\n",
5120 __func__, tfcp->port_name, tfcp->disc_state,
5121 tfcp->fw_login_state);
5125 list_add_tail(&fcport->list, &vha->vp_fcports);
5129 qlt_plogi_ack_link(vha, pla, fcport,
5130 QLT_PLOGI_LINK_SAME_WWN);
5134 spin_unlock_irqrestore(&vha->hw->tgt.sess_lock, flags);
5137 fcport->id_changed = 1;
5138 fcport->scan_state = QLA_FCPORT_FOUND;
5139 fcport->chip_reset = vha->hw->base_qpair->chip_reset;
5140 memcpy(fcport->node_name, e->u.new_sess.node_name, WWN_SIZE);
5143 if (pla->iocb.u.isp24.status_subcode == ELS_PRLI) {
5146 fcport->fw_login_state = DSC_LS_PRLI_PEND;
5150 pla->iocb.u.isp24.nport_handle);
5151 fcport->fw_login_state = DSC_LS_PRLI_PEND;
5154 pla->iocb.u.isp24.u.prli.wd3_lo);
5157 fcport->conf_compl_supported = 1;
5159 if ((wd3_lo & BIT_4) == 0)
5160 fcport->port_type = FCT_INITIATOR;
5162 fcport->port_type = FCT_TARGET;
5164 qlt_plogi_ack_unref(vha, pla);
5166 fc_port_t *dfcp = NULL;
5168 spin_lock_irqsave(&vha->hw->tgt.sess_lock, flags);
5169 tfcp = qla2x00_find_fcport_by_nportid(vha,
5170 &e->u.new_sess.id, 1);
5171 if (tfcp && (tfcp != fcport)) {
5173 * We have a conflict fcport with same NportID.
5175 ql_dbg(ql_dbg_disc, vha, 0xffff,
5176 "%s %8phC found conflict b4 add. DS %d LS %d\n",
5177 __func__, tfcp->port_name, tfcp->disc_state,
5178 tfcp->fw_login_state);
5180 switch (tfcp->disc_state) {
5183 case DSC_DELETE_PEND:
5184 fcport->login_pause = 1;
5185 tfcp->conflict = fcport;
5188 fcport->login_pause = 1;
5189 tfcp->conflict = fcport;
5194 spin_unlock_irqrestore(&vha->hw->tgt.sess_lock, flags);
5196 qlt_schedule_sess_for_deletion(tfcp);
5198 if (N2N_TOPO(vha->hw)) {
5199 fcport->flags &= ~FCF_FABRIC_DEVICE;
5200 fcport->keep_nport_handle = 1;
5201 if (vha->flags.nvme_enabled) {
5203 (FS_FC4TYPE_NVME | FS_FC4TYPE_FCP);
5204 fcport->n2n_flag = 1;
5206 fcport->fw_login_state = 0;
5208 schedule_delayed_work(&vha->scan.scan_work, 5);
5210 qla24xx_fcport_handle_login(vha, fcport);
5216 qla2x00_free_fcport(fcport);
5218 list_del(&pla->list);
5219 kmem_cache_free(qla_tgt_plogi_cachep, pla);
5224 static void qla_sp_retry(struct scsi_qla_host *vha, struct qla_work_evt *e)
5226 struct srb *sp = e->u.iosb.sp;
5229 rval = qla2x00_start_sp(sp);
5230 if (rval != QLA_SUCCESS) {
5231 ql_dbg(ql_dbg_disc, vha, 0x2043,
5232 "%s: %s: Re-issue IOCB failed (%d).\n",
5233 __func__, sp->name, rval);
5234 qla24xx_sp_unmap(vha, sp);
5239 qla2x00_do_work(struct scsi_qla_host *vha)
5241 struct qla_work_evt *e, *tmp;
5242 unsigned long flags;
5246 spin_lock_irqsave(&vha->work_lock, flags);
5247 list_splice_init(&vha->work_list, &work);
5248 spin_unlock_irqrestore(&vha->work_lock, flags);
5250 list_for_each_entry_safe(e, tmp, &work, list) {
5254 fc_host_post_event(vha->host, fc_get_event_number(),
5255 e->u.aen.code, e->u.aen.data);
5257 case QLA_EVT_IDC_ACK:
5258 qla81xx_idc_ack(vha, e->u.idc_ack.mb);
5260 case QLA_EVT_ASYNC_LOGIN:
5261 qla2x00_async_login(vha, e->u.logio.fcport,
5264 case QLA_EVT_ASYNC_LOGOUT:
5265 rc = qla2x00_async_logout(vha, e->u.logio.fcport);
5267 case QLA_EVT_ASYNC_ADISC:
5268 qla2x00_async_adisc(vha, e->u.logio.fcport,
5271 case QLA_EVT_UEVENT:
5272 qla2x00_uevent_emit(vha, e->u.uevent.code);
5275 qlafx00_process_aen(vha, e);
5278 qla24xx_async_gpnid(vha, &e->u.gpnid.id);
5281 qla24xx_sp_unmap(vha, e->u.iosb.sp);
5283 case QLA_EVT_RELOGIN:
5284 qla2x00_relogin(vha);
5286 case QLA_EVT_NEW_SESS:
5287 qla24xx_create_new_sess(vha, e);
5290 qla24xx_async_gpdb(vha, e->u.fcport.fcport,
5294 qla24xx_async_prli(vha, e->u.fcport.fcport);
5297 qla24xx_async_gpsc(vha, e->u.fcport.fcport);
5300 qla24xx_async_gnl(vha, e->u.fcport.fcport);
5303 qla24xx_do_nack_work(vha, e);
5305 case QLA_EVT_ASYNC_PRLO:
5306 rc = qla2x00_async_prlo(vha, e->u.logio.fcport);
5308 case QLA_EVT_ASYNC_PRLO_DONE:
5309 qla2x00_async_prlo_done(vha, e->u.logio.fcport,
5313 qla24xx_async_gpnft(vha, e->u.gpnft.fc4_type,
5316 case QLA_EVT_GPNFT_DONE:
5317 qla24xx_async_gpnft_done(vha, e->u.iosb.sp);
5319 case QLA_EVT_GNNFT_DONE:
5320 qla24xx_async_gnnft_done(vha, e->u.iosb.sp);
5323 qla24xx_async_gnnid(vha, e->u.fcport.fcport);
5325 case QLA_EVT_GFPNID:
5326 qla24xx_async_gfpnid(vha, e->u.fcport.fcport);
5328 case QLA_EVT_SP_RETRY:
5329 qla_sp_retry(vha, e);
5332 qla_do_iidma_work(vha, e->u.fcport.fcport);
5334 case QLA_EVT_ELS_PLOGI:
5335 qla24xx_els_dcmd2_iocb(vha, ELS_DCMD_PLOGI,
5336 e->u.fcport.fcport, false);
5341 /* put 'work' at head of 'vha->work_list' */
5342 spin_lock_irqsave(&vha->work_lock, flags);
5343 list_splice(&work, &vha->work_list);
5344 spin_unlock_irqrestore(&vha->work_lock, flags);
5347 list_del_init(&e->list);
5348 if (e->flags & QLA_EVT_FLAG_FREE)
5351 /* For each work completed decrement vha ref count */
5352 QLA_VHA_MARK_NOT_BUSY(vha);
5356 int qla24xx_post_relogin_work(struct scsi_qla_host *vha)
5358 struct qla_work_evt *e;
5360 e = qla2x00_alloc_work(vha, QLA_EVT_RELOGIN);
5363 set_bit(RELOGIN_NEEDED, &vha->dpc_flags);
5364 return QLA_FUNCTION_FAILED;
5367 return qla2x00_post_work(vha, e);
5370 /* Relogins all the fcports of a vport
5371 * Context: dpc thread
5373 void qla2x00_relogin(struct scsi_qla_host *vha)
5376 int status, relogin_needed = 0;
5377 struct event_arg ea;
5379 list_for_each_entry(fcport, &vha->vp_fcports, list) {
5381 * If the port is not ONLINE then try to login
5382 * to it if we haven't run out of retries.
5384 if (atomic_read(&fcport->state) != FCS_ONLINE &&
5385 fcport->login_retry) {
5386 if (fcport->scan_state != QLA_FCPORT_FOUND ||
5387 fcport->disc_state == DSC_LOGIN_COMPLETE)
5390 if (fcport->flags & (FCF_ASYNC_SENT|FCF_ASYNC_ACTIVE) ||
5391 fcport->disc_state == DSC_DELETE_PEND) {
5394 if (vha->hw->current_topology != ISP_CFG_NL) {
5395 memset(&ea, 0, sizeof(ea));
5397 qla24xx_handle_relogin_event(vha, &ea);
5398 } else if (vha->hw->current_topology ==
5400 IS_QLA2XXX_MIDTYPE(vha->hw)) {
5401 (void)qla24xx_fcport_handle_login(vha,
5403 } else if (vha->hw->current_topology ==
5405 fcport->login_retry--;
5407 qla2x00_local_device_login(vha,
5409 if (status == QLA_SUCCESS) {
5410 fcport->old_loop_id =
5412 ql_dbg(ql_dbg_disc, vha, 0x2003,
5413 "Port login OK: logged in ID 0x%x.\n",
5415 qla2x00_update_fcport
5417 } else if (status == 1) {
5418 set_bit(RELOGIN_NEEDED,
5420 /* retry the login again */
5421 ql_dbg(ql_dbg_disc, vha, 0x2007,
5422 "Retrying %d login again loop_id 0x%x.\n",
5423 fcport->login_retry,
5426 fcport->login_retry = 0;
5429 if (fcport->login_retry == 0 &&
5430 status != QLA_SUCCESS)
5431 qla2x00_clear_loop_id(fcport);
5435 if (test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags))
5440 set_bit(RELOGIN_NEEDED, &vha->dpc_flags);
5442 ql_dbg(ql_dbg_disc, vha, 0x400e,
5446 /* Schedule work on any of the dpc-workqueues */
5448 qla83xx_schedule_work(scsi_qla_host_t *base_vha, int work_code)
5450 struct qla_hw_data *ha = base_vha->hw;
5452 switch (work_code) {
5453 case MBA_IDC_AEN: /* 0x8200 */
5455 queue_work(ha->dpc_lp_wq, &ha->idc_aen);
5458 case QLA83XX_NIC_CORE_RESET: /* 0x1 */
5459 if (!ha->flags.nic_core_reset_hdlr_active) {
5461 queue_work(ha->dpc_hp_wq, &ha->nic_core_reset);
5463 ql_dbg(ql_dbg_p3p, base_vha, 0xb05e,
5464 "NIC Core reset is already active. Skip "
5465 "scheduling it again.\n");
5467 case QLA83XX_IDC_STATE_HANDLER: /* 0x2 */
5469 queue_work(ha->dpc_hp_wq, &ha->idc_state_handler);
5471 case QLA83XX_NIC_CORE_UNRECOVERABLE: /* 0x3 */
5473 queue_work(ha->dpc_hp_wq, &ha->nic_core_unrecoverable);
5476 ql_log(ql_log_warn, base_vha, 0xb05f,
5477 "Unknown work-code=0x%x.\n", work_code);
5483 /* Work: Perform NIC Core Unrecoverable state handling */
5485 qla83xx_nic_core_unrecoverable_work(struct work_struct *work)
5487 struct qla_hw_data *ha =
5488 container_of(work, struct qla_hw_data, nic_core_unrecoverable);
5489 scsi_qla_host_t *base_vha = pci_get_drvdata(ha->pdev);
5490 uint32_t dev_state = 0;
5492 qla83xx_idc_lock(base_vha, 0);
5493 qla83xx_rd_reg(base_vha, QLA83XX_IDC_DEV_STATE, &dev_state);
5494 qla83xx_reset_ownership(base_vha);
5495 if (ha->flags.nic_core_reset_owner) {
5496 ha->flags.nic_core_reset_owner = 0;
5497 qla83xx_wr_reg(base_vha, QLA83XX_IDC_DEV_STATE,
5498 QLA8XXX_DEV_FAILED);
5499 ql_log(ql_log_info, base_vha, 0xb060, "HW State: FAILED.\n");
5500 qla83xx_schedule_work(base_vha, QLA83XX_IDC_STATE_HANDLER);
5502 qla83xx_idc_unlock(base_vha, 0);
5505 /* Work: Execute IDC state handler */
5507 qla83xx_idc_state_handler_work(struct work_struct *work)
5509 struct qla_hw_data *ha =
5510 container_of(work, struct qla_hw_data, idc_state_handler);
5511 scsi_qla_host_t *base_vha = pci_get_drvdata(ha->pdev);
5512 uint32_t dev_state = 0;
5514 qla83xx_idc_lock(base_vha, 0);
5515 qla83xx_rd_reg(base_vha, QLA83XX_IDC_DEV_STATE, &dev_state);
5516 if (dev_state == QLA8XXX_DEV_FAILED ||
5517 dev_state == QLA8XXX_DEV_NEED_QUIESCENT)
5518 qla83xx_idc_state_handler(base_vha);
5519 qla83xx_idc_unlock(base_vha, 0);
5523 qla83xx_check_nic_core_fw_alive(scsi_qla_host_t *base_vha)
5525 int rval = QLA_SUCCESS;
5526 unsigned long heart_beat_wait = jiffies + (1 * HZ);
5527 uint32_t heart_beat_counter1, heart_beat_counter2;
5530 if (time_after(jiffies, heart_beat_wait)) {
5531 ql_dbg(ql_dbg_p3p, base_vha, 0xb07c,
5532 "Nic Core f/w is not alive.\n");
5533 rval = QLA_FUNCTION_FAILED;
5537 qla83xx_idc_lock(base_vha, 0);
5538 qla83xx_rd_reg(base_vha, QLA83XX_FW_HEARTBEAT,
5539 &heart_beat_counter1);
5540 qla83xx_idc_unlock(base_vha, 0);
5542 qla83xx_idc_lock(base_vha, 0);
5543 qla83xx_rd_reg(base_vha, QLA83XX_FW_HEARTBEAT,
5544 &heart_beat_counter2);
5545 qla83xx_idc_unlock(base_vha, 0);
5546 } while (heart_beat_counter1 == heart_beat_counter2);
5551 /* Work: Perform NIC Core Reset handling */
5553 qla83xx_nic_core_reset_work(struct work_struct *work)
5555 struct qla_hw_data *ha =
5556 container_of(work, struct qla_hw_data, nic_core_reset);
5557 scsi_qla_host_t *base_vha = pci_get_drvdata(ha->pdev);
5558 uint32_t dev_state = 0;
5560 if (IS_QLA2031(ha)) {
5561 if (qla2xxx_mctp_dump(base_vha) != QLA_SUCCESS)
5562 ql_log(ql_log_warn, base_vha, 0xb081,
5563 "Failed to dump mctp\n");
5567 if (!ha->flags.nic_core_reset_hdlr_active) {
5568 if (qla83xx_check_nic_core_fw_alive(base_vha) == QLA_SUCCESS) {
5569 qla83xx_idc_lock(base_vha, 0);
5570 qla83xx_rd_reg(base_vha, QLA83XX_IDC_DEV_STATE,
5572 qla83xx_idc_unlock(base_vha, 0);
5573 if (dev_state != QLA8XXX_DEV_NEED_RESET) {
5574 ql_dbg(ql_dbg_p3p, base_vha, 0xb07a,
5575 "Nic Core f/w is alive.\n");
5580 ha->flags.nic_core_reset_hdlr_active = 1;
5581 if (qla83xx_nic_core_reset(base_vha)) {
5582 /* NIC Core reset failed. */
5583 ql_dbg(ql_dbg_p3p, base_vha, 0xb061,
5584 "NIC Core reset failed.\n");
5586 ha->flags.nic_core_reset_hdlr_active = 0;
5590 /* Work: Handle 8200 IDC aens */
5592 qla83xx_service_idc_aen(struct work_struct *work)
5594 struct qla_hw_data *ha =
5595 container_of(work, struct qla_hw_data, idc_aen);
5596 scsi_qla_host_t *base_vha = pci_get_drvdata(ha->pdev);
5597 uint32_t dev_state, idc_control;
5599 qla83xx_idc_lock(base_vha, 0);
5600 qla83xx_rd_reg(base_vha, QLA83XX_IDC_DEV_STATE, &dev_state);
5601 qla83xx_rd_reg(base_vha, QLA83XX_IDC_CONTROL, &idc_control);
5602 qla83xx_idc_unlock(base_vha, 0);
5603 if (dev_state == QLA8XXX_DEV_NEED_RESET) {
5604 if (idc_control & QLA83XX_IDC_GRACEFUL_RESET) {
5605 ql_dbg(ql_dbg_p3p, base_vha, 0xb062,
5606 "Application requested NIC Core Reset.\n");
5607 qla83xx_schedule_work(base_vha, QLA83XX_NIC_CORE_RESET);
5608 } else if (qla83xx_check_nic_core_fw_alive(base_vha) ==
5610 ql_dbg(ql_dbg_p3p, base_vha, 0xb07b,
5611 "Other protocol driver requested NIC Core Reset.\n");
5612 qla83xx_schedule_work(base_vha, QLA83XX_NIC_CORE_RESET);
5614 } else if (dev_state == QLA8XXX_DEV_FAILED ||
5615 dev_state == QLA8XXX_DEV_NEED_QUIESCENT) {
5616 qla83xx_schedule_work(base_vha, QLA83XX_IDC_STATE_HANDLER);
5621 qla83xx_wait_logic(void)
5626 if (!in_interrupt()) {
5628 * Wait about 200ms before retrying again.
5629 * This controls the number of retries for single
5635 for (i = 0; i < 20; i++)
5636 cpu_relax(); /* This a nop instr on i386 */
5641 qla83xx_force_lock_recovery(scsi_qla_host_t *base_vha)
5645 uint32_t idc_lck_rcvry_stage_mask = 0x3;
5646 uint32_t idc_lck_rcvry_owner_mask = 0x3c;
5647 struct qla_hw_data *ha = base_vha->hw;
5649 ql_dbg(ql_dbg_p3p, base_vha, 0xb086,
5650 "Trying force recovery of the IDC lock.\n");
5652 rval = qla83xx_rd_reg(base_vha, QLA83XX_IDC_LOCK_RECOVERY, &data);
5656 if ((data & idc_lck_rcvry_stage_mask) > 0) {
5659 data = (IDC_LOCK_RECOVERY_STAGE1) | (ha->portnum << 2);
5660 rval = qla83xx_wr_reg(base_vha, QLA83XX_IDC_LOCK_RECOVERY,
5667 rval = qla83xx_rd_reg(base_vha, QLA83XX_IDC_LOCK_RECOVERY,
5672 if (((data & idc_lck_rcvry_owner_mask) >> 2) == ha->portnum) {
5673 data &= (IDC_LOCK_RECOVERY_STAGE2 |
5674 ~(idc_lck_rcvry_stage_mask));
5675 rval = qla83xx_wr_reg(base_vha,
5676 QLA83XX_IDC_LOCK_RECOVERY, data);
5680 /* Forcefully perform IDC UnLock */
5681 rval = qla83xx_rd_reg(base_vha, QLA83XX_DRIVER_UNLOCK,
5685 /* Clear lock-id by setting 0xff */
5686 rval = qla83xx_wr_reg(base_vha, QLA83XX_DRIVER_LOCKID,
5690 /* Clear lock-recovery by setting 0x0 */
5691 rval = qla83xx_wr_reg(base_vha,
5692 QLA83XX_IDC_LOCK_RECOVERY, 0x0);
5703 qla83xx_idc_lock_recovery(scsi_qla_host_t *base_vha)
5705 int rval = QLA_SUCCESS;
5706 uint32_t o_drv_lockid, n_drv_lockid;
5707 unsigned long lock_recovery_timeout;
5709 lock_recovery_timeout = jiffies + QLA83XX_MAX_LOCK_RECOVERY_WAIT;
5711 rval = qla83xx_rd_reg(base_vha, QLA83XX_DRIVER_LOCKID, &o_drv_lockid);
5715 /* MAX wait time before forcing IDC Lock recovery = 2 secs */
5716 if (time_after_eq(jiffies, lock_recovery_timeout)) {
5717 if (qla83xx_force_lock_recovery(base_vha) == QLA_SUCCESS)
5720 return QLA_FUNCTION_FAILED;
5723 rval = qla83xx_rd_reg(base_vha, QLA83XX_DRIVER_LOCKID, &n_drv_lockid);
5727 if (o_drv_lockid == n_drv_lockid) {
5728 qla83xx_wait_logic();
5738 qla83xx_idc_lock(scsi_qla_host_t *base_vha, uint16_t requester_id)
5741 uint32_t lock_owner;
5742 struct qla_hw_data *ha = base_vha->hw;
5744 /* IDC-lock implementation using driver-lock/lock-id remote registers */
5746 if (qla83xx_rd_reg(base_vha, QLA83XX_DRIVER_LOCK, &data)
5749 /* Setting lock-id to our function-number */
5750 qla83xx_wr_reg(base_vha, QLA83XX_DRIVER_LOCKID,
5753 qla83xx_rd_reg(base_vha, QLA83XX_DRIVER_LOCKID,
5755 ql_dbg(ql_dbg_p3p, base_vha, 0xb063,
5756 "Failed to acquire IDC lock, acquired by %d, "
5757 "retrying...\n", lock_owner);
5759 /* Retry/Perform IDC-Lock recovery */
5760 if (qla83xx_idc_lock_recovery(base_vha)
5762 qla83xx_wait_logic();
5765 ql_log(ql_log_warn, base_vha, 0xb075,
5766 "IDC Lock recovery FAILED.\n");
5775 qla25xx_rdp_rsp_reduce_size(struct scsi_qla_host *vha,
5776 struct purex_entry_24xx *purex)
5779 u32 sid = purex->s_id[2] << 16 | purex->s_id[1] << 8 | purex->s_id[0];
5780 struct port_database_24xx *pdb;
5782 /* Domain Controller is always logged-out. */
5783 /* if RDP request is not from Domain Controller: */
5784 if (sid != 0xfffc01)
5787 ql_dbg(ql_dbg_init, vha, 0x0181, "%s: s_id=%#x\n", __func__, sid);
5789 pdb = kzalloc(sizeof(*pdb), GFP_KERNEL);
5791 ql_dbg(ql_dbg_init, vha, 0x0181,
5792 "%s: Failed allocate pdb\n", __func__);
5793 } else if (qla24xx_get_port_database(vha,
5794 le16_to_cpu(purex->nport_handle), pdb)) {
5795 ql_dbg(ql_dbg_init, vha, 0x0181,
5796 "%s: Failed get pdb sid=%x\n", __func__, sid);
5797 } else if (pdb->current_login_state != PDS_PLOGI_COMPLETE &&
5798 pdb->current_login_state != PDS_PRLI_COMPLETE) {
5799 ql_dbg(ql_dbg_init, vha, 0x0181,
5800 "%s: Port not logged in sid=%#x\n", __func__, sid);
5802 /* RDP request is from logged in port */
5808 vha->hw->isp_ops->fw_version_str(vha, fwstr, sizeof(fwstr));
5809 fwstr[strcspn(fwstr, " ")] = 0;
5810 /* if FW version allows RDP response length upto 2048 bytes: */
5811 if (strcmp(fwstr, "8.09.00") > 0 || strcmp(fwstr, "8.05.65") == 0)
5814 ql_dbg(ql_dbg_init, vha, 0x0181, "%s: fw=%s\n", __func__, fwstr);
5816 /* RDP response length is to be reduced to maximum 256 bytes */
5821 * Function Name: qla24xx_process_purex_iocb
5824 * Prepare a RDP response and send to Fabric switch
5827 * vha: SCSI qla host
5828 * purex: RDP request received by HBA
5830 void qla24xx_process_purex_rdp(struct scsi_qla_host *vha,
5831 struct purex_item *item)
5833 struct qla_hw_data *ha = vha->hw;
5834 struct purex_entry_24xx *purex =
5835 (struct purex_entry_24xx *)&item->iocb;
5836 dma_addr_t rsp_els_dma;
5837 dma_addr_t rsp_payload_dma;
5838 dma_addr_t stat_dma;
5840 struct els_entry_24xx *rsp_els = NULL;
5841 struct rdp_rsp_payload *rsp_payload = NULL;
5842 struct link_statistics *stat = NULL;
5843 uint8_t *sfp = NULL;
5844 uint16_t sfp_flags = 0;
5845 uint rsp_payload_length = sizeof(*rsp_payload);
5848 ql_dbg(ql_dbg_init + ql_dbg_verbose, vha, 0x0180,
5849 "%s: Enter\n", __func__);
5851 ql_dbg(ql_dbg_init + ql_dbg_verbose, vha, 0x0181,
5852 "-------- ELS REQ -------\n");
5853 ql_dump_buffer(ql_dbg_init + ql_dbg_verbose, vha, 0x0182,
5854 purex, sizeof(*purex));
5856 if (qla25xx_rdp_rsp_reduce_size(vha, purex)) {
5857 rsp_payload_length =
5858 offsetof(typeof(*rsp_payload), optical_elmt_desc);
5859 ql_dbg(ql_dbg_init, vha, 0x0181,
5860 "Reducing RSP payload length to %u bytes...\n",
5861 rsp_payload_length);
5864 rsp_els = dma_alloc_coherent(&ha->pdev->dev, sizeof(*rsp_els),
5865 &rsp_els_dma, GFP_KERNEL);
5867 ql_log(ql_log_warn, vha, 0x0183,
5868 "Failed allocate dma buffer ELS RSP.\n");
5872 rsp_payload = dma_alloc_coherent(&ha->pdev->dev, sizeof(*rsp_payload),
5873 &rsp_payload_dma, GFP_KERNEL);
5875 ql_log(ql_log_warn, vha, 0x0184,
5876 "Failed allocate dma buffer ELS RSP payload.\n");
5880 sfp = dma_alloc_coherent(&ha->pdev->dev, SFP_RTDI_LEN,
5881 &sfp_dma, GFP_KERNEL);
5883 stat = dma_alloc_coherent(&ha->pdev->dev, sizeof(*stat),
5884 &stat_dma, GFP_KERNEL);
5886 /* Prepare Response IOCB */
5887 rsp_els->entry_type = ELS_IOCB_TYPE;
5888 rsp_els->entry_count = 1;
5889 rsp_els->sys_define = 0;
5890 rsp_els->entry_status = 0;
5891 rsp_els->handle = 0;
5892 rsp_els->nport_handle = purex->nport_handle;
5893 rsp_els->tx_dsd_count = cpu_to_le16(1);
5894 rsp_els->vp_index = purex->vp_idx;
5895 rsp_els->sof_type = EST_SOFI3;
5896 rsp_els->rx_xchg_address = purex->rx_xchg_addr;
5897 rsp_els->rx_dsd_count = 0;
5898 rsp_els->opcode = purex->els_frame_payload[0];
5900 rsp_els->d_id[0] = purex->s_id[0];
5901 rsp_els->d_id[1] = purex->s_id[1];
5902 rsp_els->d_id[2] = purex->s_id[2];
5904 rsp_els->control_flags = cpu_to_le16(EPD_ELS_ACC);
5905 rsp_els->rx_byte_count = 0;
5906 rsp_els->tx_byte_count = cpu_to_le32(rsp_payload_length);
5908 put_unaligned_le64(rsp_payload_dma, &rsp_els->tx_address);
5909 rsp_els->tx_len = rsp_els->tx_byte_count;
5911 rsp_els->rx_address = 0;
5912 rsp_els->rx_len = 0;
5914 /* Prepare Response Payload */
5915 rsp_payload->hdr.cmd = cpu_to_be32(0x2 << 24); /* LS_ACC */
5916 rsp_payload->hdr.len = cpu_to_be32(le32_to_cpu(rsp_els->tx_byte_count) -
5917 sizeof(rsp_payload->hdr));
5919 /* Link service Request Info Descriptor */
5920 rsp_payload->ls_req_info_desc.desc_tag = cpu_to_be32(0x1);
5921 rsp_payload->ls_req_info_desc.desc_len =
5922 cpu_to_be32(RDP_DESC_LEN(rsp_payload->ls_req_info_desc));
5923 rsp_payload->ls_req_info_desc.req_payload_word_0 =
5924 cpu_to_be32p((uint32_t *)purex->els_frame_payload);
5926 /* Link service Request Info Descriptor 2 */
5927 rsp_payload->ls_req_info_desc2.desc_tag = cpu_to_be32(0x1);
5928 rsp_payload->ls_req_info_desc2.desc_len =
5929 cpu_to_be32(RDP_DESC_LEN(rsp_payload->ls_req_info_desc2));
5930 rsp_payload->ls_req_info_desc2.req_payload_word_0 =
5931 cpu_to_be32p((uint32_t *)purex->els_frame_payload);
5934 rsp_payload->sfp_diag_desc.desc_tag = cpu_to_be32(0x10000);
5935 rsp_payload->sfp_diag_desc.desc_len =
5936 cpu_to_be32(RDP_DESC_LEN(rsp_payload->sfp_diag_desc));
5940 memset(sfp, 0, SFP_RTDI_LEN);
5941 rval = qla2x00_read_sfp(vha, sfp_dma, sfp, 0xa0, 0x7, 2, 0);
5943 /* SFP Flags bits 3-0: Port Tx Laser Type */
5944 if (sfp[0] & BIT_2 || sfp[1] & (BIT_6|BIT_5))
5945 sfp_flags |= BIT_0; /* short wave */
5946 else if (sfp[0] & BIT_1)
5947 sfp_flags |= BIT_1; /* long wave 1310nm */
5948 else if (sfp[1] & BIT_4)
5949 sfp_flags |= BIT_1|BIT_0; /* long wave 1550nm */
5953 memset(sfp, 0, SFP_RTDI_LEN);
5954 rval = qla2x00_read_sfp(vha, sfp_dma, sfp, 0xa0, 0x0, 1, 0);
5956 sfp_flags |= BIT_4; /* optical */
5958 sfp_flags |= BIT_6; /* sfp+ */
5961 rsp_payload->sfp_diag_desc.sfp_flags = cpu_to_be16(sfp_flags);
5963 /* SFP Diagnostics */
5964 memset(sfp, 0, SFP_RTDI_LEN);
5965 rval = qla2x00_read_sfp(vha, sfp_dma, sfp, 0xa2, 0x60, 10, 0);
5967 __be16 *trx = (__force __be16 *)sfp; /* already be16 */
5968 rsp_payload->sfp_diag_desc.temperature = trx[0];
5969 rsp_payload->sfp_diag_desc.vcc = trx[1];
5970 rsp_payload->sfp_diag_desc.tx_bias = trx[2];
5971 rsp_payload->sfp_diag_desc.tx_power = trx[3];
5972 rsp_payload->sfp_diag_desc.rx_power = trx[4];
5976 /* Port Speed Descriptor */
5977 rsp_payload->port_speed_desc.desc_tag = cpu_to_be32(0x10001);
5978 rsp_payload->port_speed_desc.desc_len =
5979 cpu_to_be32(RDP_DESC_LEN(rsp_payload->port_speed_desc));
5980 rsp_payload->port_speed_desc.speed_capab = cpu_to_be16(
5981 qla25xx_fdmi_port_speed_capability(ha));
5982 rsp_payload->port_speed_desc.operating_speed = cpu_to_be16(
5983 qla25xx_fdmi_port_speed_currently(ha));
5985 /* Link Error Status Descriptor */
5986 rsp_payload->ls_err_desc.desc_tag = cpu_to_be32(0x10002);
5987 rsp_payload->ls_err_desc.desc_len =
5988 cpu_to_be32(RDP_DESC_LEN(rsp_payload->ls_err_desc));
5991 rval = qla24xx_get_isp_stats(vha, stat, stat_dma, 0);
5993 rsp_payload->ls_err_desc.link_fail_cnt =
5994 cpu_to_be32(le32_to_cpu(stat->link_fail_cnt));
5995 rsp_payload->ls_err_desc.loss_sync_cnt =
5996 cpu_to_be32(le32_to_cpu(stat->loss_sync_cnt));
5997 rsp_payload->ls_err_desc.loss_sig_cnt =
5998 cpu_to_be32(le32_to_cpu(stat->loss_sig_cnt));
5999 rsp_payload->ls_err_desc.prim_seq_err_cnt =
6000 cpu_to_be32(le32_to_cpu(stat->prim_seq_err_cnt));
6001 rsp_payload->ls_err_desc.inval_xmit_word_cnt =
6002 cpu_to_be32(le32_to_cpu(stat->inval_xmit_word_cnt));
6003 rsp_payload->ls_err_desc.inval_crc_cnt =
6004 cpu_to_be32(le32_to_cpu(stat->inval_crc_cnt));
6005 rsp_payload->ls_err_desc.pn_port_phy_type |= BIT_6;
6009 /* Portname Descriptor */
6010 rsp_payload->port_name_diag_desc.desc_tag = cpu_to_be32(0x10003);
6011 rsp_payload->port_name_diag_desc.desc_len =
6012 cpu_to_be32(RDP_DESC_LEN(rsp_payload->port_name_diag_desc));
6013 memcpy(rsp_payload->port_name_diag_desc.WWNN,
6015 sizeof(rsp_payload->port_name_diag_desc.WWNN));
6016 memcpy(rsp_payload->port_name_diag_desc.WWPN,
6018 sizeof(rsp_payload->port_name_diag_desc.WWPN));
6020 /* F-Port Portname Descriptor */
6021 rsp_payload->port_name_direct_desc.desc_tag = cpu_to_be32(0x10003);
6022 rsp_payload->port_name_direct_desc.desc_len =
6023 cpu_to_be32(RDP_DESC_LEN(rsp_payload->port_name_direct_desc));
6024 memcpy(rsp_payload->port_name_direct_desc.WWNN,
6025 vha->fabric_node_name,
6026 sizeof(rsp_payload->port_name_direct_desc.WWNN));
6027 memcpy(rsp_payload->port_name_direct_desc.WWPN,
6028 vha->fabric_port_name,
6029 sizeof(rsp_payload->port_name_direct_desc.WWPN));
6031 /* Bufer Credit Descriptor */
6032 rsp_payload->buffer_credit_desc.desc_tag = cpu_to_be32(0x10006);
6033 rsp_payload->buffer_credit_desc.desc_len =
6034 cpu_to_be32(RDP_DESC_LEN(rsp_payload->buffer_credit_desc));
6035 rsp_payload->buffer_credit_desc.fcport_b2b = 0;
6036 rsp_payload->buffer_credit_desc.attached_fcport_b2b = cpu_to_be32(0);
6037 rsp_payload->buffer_credit_desc.fcport_rtt = cpu_to_be32(0);
6039 if (ha->flags.plogi_template_valid) {
6041 be16_to_cpu(ha->plogi_els_payld.fl_csp.sp_bb_cred);
6042 rsp_payload->buffer_credit_desc.fcport_b2b = cpu_to_be32(tmp);
6045 if (rsp_payload_length < sizeof(*rsp_payload))
6048 /* Optical Element Descriptor, Temperature */
6049 rsp_payload->optical_elmt_desc[0].desc_tag = cpu_to_be32(0x10007);
6050 rsp_payload->optical_elmt_desc[0].desc_len =
6051 cpu_to_be32(RDP_DESC_LEN(*rsp_payload->optical_elmt_desc));
6052 /* Optical Element Descriptor, Voltage */
6053 rsp_payload->optical_elmt_desc[1].desc_tag = cpu_to_be32(0x10007);
6054 rsp_payload->optical_elmt_desc[1].desc_len =
6055 cpu_to_be32(RDP_DESC_LEN(*rsp_payload->optical_elmt_desc));
6056 /* Optical Element Descriptor, Tx Bias Current */
6057 rsp_payload->optical_elmt_desc[2].desc_tag = cpu_to_be32(0x10007);
6058 rsp_payload->optical_elmt_desc[2].desc_len =
6059 cpu_to_be32(RDP_DESC_LEN(*rsp_payload->optical_elmt_desc));
6060 /* Optical Element Descriptor, Tx Power */
6061 rsp_payload->optical_elmt_desc[3].desc_tag = cpu_to_be32(0x10007);
6062 rsp_payload->optical_elmt_desc[3].desc_len =
6063 cpu_to_be32(RDP_DESC_LEN(*rsp_payload->optical_elmt_desc));
6064 /* Optical Element Descriptor, Rx Power */
6065 rsp_payload->optical_elmt_desc[4].desc_tag = cpu_to_be32(0x10007);
6066 rsp_payload->optical_elmt_desc[4].desc_len =
6067 cpu_to_be32(RDP_DESC_LEN(*rsp_payload->optical_elmt_desc));
6070 memset(sfp, 0, SFP_RTDI_LEN);
6071 rval = qla2x00_read_sfp(vha, sfp_dma, sfp, 0xa2, 0, 64, 0);
6073 __be16 *trx = (__force __be16 *)sfp; /* already be16 */
6075 /* Optical Element Descriptor, Temperature */
6076 rsp_payload->optical_elmt_desc[0].high_alarm = trx[0];
6077 rsp_payload->optical_elmt_desc[0].low_alarm = trx[1];
6078 rsp_payload->optical_elmt_desc[0].high_warn = trx[2];
6079 rsp_payload->optical_elmt_desc[0].low_warn = trx[3];
6080 rsp_payload->optical_elmt_desc[0].element_flags =
6081 cpu_to_be32(1 << 28);
6083 /* Optical Element Descriptor, Voltage */
6084 rsp_payload->optical_elmt_desc[1].high_alarm = trx[4];
6085 rsp_payload->optical_elmt_desc[1].low_alarm = trx[5];
6086 rsp_payload->optical_elmt_desc[1].high_warn = trx[6];
6087 rsp_payload->optical_elmt_desc[1].low_warn = trx[7];
6088 rsp_payload->optical_elmt_desc[1].element_flags =
6089 cpu_to_be32(2 << 28);
6091 /* Optical Element Descriptor, Tx Bias Current */
6092 rsp_payload->optical_elmt_desc[2].high_alarm = trx[8];
6093 rsp_payload->optical_elmt_desc[2].low_alarm = trx[9];
6094 rsp_payload->optical_elmt_desc[2].high_warn = trx[10];
6095 rsp_payload->optical_elmt_desc[2].low_warn = trx[11];
6096 rsp_payload->optical_elmt_desc[2].element_flags =
6097 cpu_to_be32(3 << 28);
6099 /* Optical Element Descriptor, Tx Power */
6100 rsp_payload->optical_elmt_desc[3].high_alarm = trx[12];
6101 rsp_payload->optical_elmt_desc[3].low_alarm = trx[13];
6102 rsp_payload->optical_elmt_desc[3].high_warn = trx[14];
6103 rsp_payload->optical_elmt_desc[3].low_warn = trx[15];
6104 rsp_payload->optical_elmt_desc[3].element_flags =
6105 cpu_to_be32(4 << 28);
6107 /* Optical Element Descriptor, Rx Power */
6108 rsp_payload->optical_elmt_desc[4].high_alarm = trx[16];
6109 rsp_payload->optical_elmt_desc[4].low_alarm = trx[17];
6110 rsp_payload->optical_elmt_desc[4].high_warn = trx[18];
6111 rsp_payload->optical_elmt_desc[4].low_warn = trx[19];
6112 rsp_payload->optical_elmt_desc[4].element_flags =
6113 cpu_to_be32(5 << 28);
6116 memset(sfp, 0, SFP_RTDI_LEN);
6117 rval = qla2x00_read_sfp(vha, sfp_dma, sfp, 0xa2, 112, 64, 0);
6119 /* Temperature high/low alarm/warning */
6120 rsp_payload->optical_elmt_desc[0].element_flags |=
6122 (sfp[0] >> 7 & 1) << 3 |
6123 (sfp[0] >> 6 & 1) << 2 |
6124 (sfp[4] >> 7 & 1) << 1 |
6125 (sfp[4] >> 6 & 1) << 0);
6127 /* Voltage high/low alarm/warning */
6128 rsp_payload->optical_elmt_desc[1].element_flags |=
6130 (sfp[0] >> 5 & 1) << 3 |
6131 (sfp[0] >> 4 & 1) << 2 |
6132 (sfp[4] >> 5 & 1) << 1 |
6133 (sfp[4] >> 4 & 1) << 0);
6135 /* Tx Bias Current high/low alarm/warning */
6136 rsp_payload->optical_elmt_desc[2].element_flags |=
6138 (sfp[0] >> 3 & 1) << 3 |
6139 (sfp[0] >> 2 & 1) << 2 |
6140 (sfp[4] >> 3 & 1) << 1 |
6141 (sfp[4] >> 2 & 1) << 0);
6143 /* Tx Power high/low alarm/warning */
6144 rsp_payload->optical_elmt_desc[3].element_flags |=
6146 (sfp[0] >> 1 & 1) << 3 |
6147 (sfp[0] >> 0 & 1) << 2 |
6148 (sfp[4] >> 1 & 1) << 1 |
6149 (sfp[4] >> 0 & 1) << 0);
6151 /* Rx Power high/low alarm/warning */
6152 rsp_payload->optical_elmt_desc[4].element_flags |=
6154 (sfp[1] >> 7 & 1) << 3 |
6155 (sfp[1] >> 6 & 1) << 2 |
6156 (sfp[5] >> 7 & 1) << 1 |
6157 (sfp[5] >> 6 & 1) << 0);
6161 /* Optical Product Data Descriptor */
6162 rsp_payload->optical_prod_desc.desc_tag = cpu_to_be32(0x10008);
6163 rsp_payload->optical_prod_desc.desc_len =
6164 cpu_to_be32(RDP_DESC_LEN(rsp_payload->optical_prod_desc));
6167 memset(sfp, 0, SFP_RTDI_LEN);
6168 rval = qla2x00_read_sfp(vha, sfp_dma, sfp, 0xa0, 20, 64, 0);
6170 memcpy(rsp_payload->optical_prod_desc.vendor_name,
6172 sizeof(rsp_payload->optical_prod_desc.vendor_name));
6173 memcpy(rsp_payload->optical_prod_desc.part_number,
6175 sizeof(rsp_payload->optical_prod_desc.part_number));
6176 memcpy(rsp_payload->optical_prod_desc.revision,
6178 sizeof(rsp_payload->optical_prod_desc.revision));
6179 memcpy(rsp_payload->optical_prod_desc.serial_number,
6181 sizeof(rsp_payload->optical_prod_desc.serial_number));
6184 memset(sfp, 0, SFP_RTDI_LEN);
6185 rval = qla2x00_read_sfp(vha, sfp_dma, sfp, 0xa0, 84, 8, 0);
6187 memcpy(rsp_payload->optical_prod_desc.date,
6189 sizeof(rsp_payload->optical_prod_desc.date));
6194 ql_dbg(ql_dbg_init, vha, 0x0183,
6195 "Sending ELS Response to RDP Request...\n");
6196 ql_dbg(ql_dbg_init + ql_dbg_verbose, vha, 0x0184,
6197 "-------- ELS RSP -------\n");
6198 ql_dump_buffer(ql_dbg_init + ql_dbg_verbose, vha, 0x0185,
6199 rsp_els, sizeof(*rsp_els));
6200 ql_dbg(ql_dbg_init + ql_dbg_verbose, vha, 0x0186,
6201 "-------- ELS RSP PAYLOAD -------\n");
6202 ql_dump_buffer(ql_dbg_init + ql_dbg_verbose, vha, 0x0187,
6203 rsp_payload, rsp_payload_length);
6205 rval = qla2x00_issue_iocb(vha, rsp_els, rsp_els_dma, 0);
6208 ql_log(ql_log_warn, vha, 0x0188,
6209 "%s: iocb failed to execute -> %x\n", __func__, rval);
6210 } else if (rsp_els->comp_status) {
6211 ql_log(ql_log_warn, vha, 0x0189,
6212 "%s: iocb failed to complete -> completion=%#x subcode=(%#x,%#x)\n",
6213 __func__, rsp_els->comp_status,
6214 rsp_els->error_subcode_1, rsp_els->error_subcode_2);
6216 ql_dbg(ql_dbg_init, vha, 0x018a, "%s: done.\n", __func__);
6221 dma_free_coherent(&ha->pdev->dev, sizeof(*stat),
6224 dma_free_coherent(&ha->pdev->dev, SFP_RTDI_LEN,
6227 dma_free_coherent(&ha->pdev->dev, sizeof(*rsp_payload),
6228 rsp_payload, rsp_payload_dma);
6230 dma_free_coherent(&ha->pdev->dev, sizeof(*rsp_els),
6231 rsp_els, rsp_els_dma);
6235 qla24xx_free_purex_item(struct purex_item *item)
6237 if (item == &item->vha->default_item)
6238 memset(&item->vha->default_item, 0, sizeof(struct purex_item));
6243 void qla24xx_process_purex_list(struct purex_list *list)
6245 struct list_head head = LIST_HEAD_INIT(head);
6246 struct purex_item *item, *next;
6249 spin_lock_irqsave(&list->lock, flags);
6250 list_splice_init(&list->head, &head);
6251 spin_unlock_irqrestore(&list->lock, flags);
6253 list_for_each_entry_safe(item, next, &head, list) {
6254 list_del(&item->list);
6255 item->process_item(item->vha, item);
6256 qla24xx_free_purex_item(item);
6261 qla83xx_idc_unlock(scsi_qla_host_t *base_vha, uint16_t requester_id)
6264 uint16_t options = (requester_id << 15) | BIT_7;
6268 struct qla_hw_data *ha = base_vha->hw;
6270 /* IDC-unlock implementation using driver-unlock/lock-id
6275 if (qla83xx_rd_reg(base_vha, QLA83XX_DRIVER_LOCKID, &data)
6277 if (data == ha->portnum) {
6278 qla83xx_rd_reg(base_vha, QLA83XX_DRIVER_UNLOCK, &data);
6279 /* Clearing lock-id by setting 0xff */
6280 qla83xx_wr_reg(base_vha, QLA83XX_DRIVER_LOCKID, 0xff);
6281 } else if (retry < 10) {
6282 /* SV: XXX: IDC unlock retrying needed here? */
6284 /* Retry for IDC-unlock */
6285 qla83xx_wait_logic();
6287 ql_dbg(ql_dbg_p3p, base_vha, 0xb064,
6288 "Failed to release IDC lock, retrying=%d\n", retry);
6291 } else if (retry < 10) {
6292 /* Retry for IDC-unlock */
6293 qla83xx_wait_logic();
6295 ql_dbg(ql_dbg_p3p, base_vha, 0xb065,
6296 "Failed to read drv-lockid, retrying=%d\n", retry);
6303 /* XXX: IDC-unlock implementation using access-control mbx */
6306 if (qla83xx_access_control(base_vha, options, 0, 0, NULL)) {
6308 /* Retry for IDC-unlock */
6309 qla83xx_wait_logic();
6311 ql_dbg(ql_dbg_p3p, base_vha, 0xb066,
6312 "Failed to release IDC lock, retrying=%d\n", retry);
6322 __qla83xx_set_drv_presence(scsi_qla_host_t *vha)
6324 int rval = QLA_SUCCESS;
6325 struct qla_hw_data *ha = vha->hw;
6326 uint32_t drv_presence;
6328 rval = qla83xx_rd_reg(vha, QLA83XX_IDC_DRV_PRESENCE, &drv_presence);
6329 if (rval == QLA_SUCCESS) {
6330 drv_presence |= (1 << ha->portnum);
6331 rval = qla83xx_wr_reg(vha, QLA83XX_IDC_DRV_PRESENCE,
6339 qla83xx_set_drv_presence(scsi_qla_host_t *vha)
6341 int rval = QLA_SUCCESS;
6343 qla83xx_idc_lock(vha, 0);
6344 rval = __qla83xx_set_drv_presence(vha);
6345 qla83xx_idc_unlock(vha, 0);
6351 __qla83xx_clear_drv_presence(scsi_qla_host_t *vha)
6353 int rval = QLA_SUCCESS;
6354 struct qla_hw_data *ha = vha->hw;
6355 uint32_t drv_presence;
6357 rval = qla83xx_rd_reg(vha, QLA83XX_IDC_DRV_PRESENCE, &drv_presence);
6358 if (rval == QLA_SUCCESS) {
6359 drv_presence &= ~(1 << ha->portnum);
6360 rval = qla83xx_wr_reg(vha, QLA83XX_IDC_DRV_PRESENCE,
6368 qla83xx_clear_drv_presence(scsi_qla_host_t *vha)
6370 int rval = QLA_SUCCESS;
6372 qla83xx_idc_lock(vha, 0);
6373 rval = __qla83xx_clear_drv_presence(vha);
6374 qla83xx_idc_unlock(vha, 0);
6380 qla83xx_need_reset_handler(scsi_qla_host_t *vha)
6382 struct qla_hw_data *ha = vha->hw;
6383 uint32_t drv_ack, drv_presence;
6384 unsigned long ack_timeout;
6386 /* Wait for IDC ACK from all functions (DRV-ACK == DRV-PRESENCE) */
6387 ack_timeout = jiffies + (ha->fcoe_reset_timeout * HZ);
6389 qla83xx_rd_reg(vha, QLA83XX_IDC_DRIVER_ACK, &drv_ack);
6390 qla83xx_rd_reg(vha, QLA83XX_IDC_DRV_PRESENCE, &drv_presence);
6391 if ((drv_ack & drv_presence) == drv_presence)
6394 if (time_after_eq(jiffies, ack_timeout)) {
6395 ql_log(ql_log_warn, vha, 0xb067,
6396 "RESET ACK TIMEOUT! drv_presence=0x%x "
6397 "drv_ack=0x%x\n", drv_presence, drv_ack);
6399 * The function(s) which did not ack in time are forced
6400 * to withdraw any further participation in the IDC
6403 if (drv_ack != drv_presence)
6404 qla83xx_wr_reg(vha, QLA83XX_IDC_DRV_PRESENCE,
6409 qla83xx_idc_unlock(vha, 0);
6411 qla83xx_idc_lock(vha, 0);
6414 qla83xx_wr_reg(vha, QLA83XX_IDC_DEV_STATE, QLA8XXX_DEV_COLD);
6415 ql_log(ql_log_info, vha, 0xb068, "HW State: COLD/RE-INIT.\n");
6419 qla83xx_device_bootstrap(scsi_qla_host_t *vha)
6421 int rval = QLA_SUCCESS;
6422 uint32_t idc_control;
6424 qla83xx_wr_reg(vha, QLA83XX_IDC_DEV_STATE, QLA8XXX_DEV_INITIALIZING);
6425 ql_log(ql_log_info, vha, 0xb069, "HW State: INITIALIZING.\n");
6427 /* Clearing IDC-Control Graceful-Reset Bit before resetting f/w */
6428 __qla83xx_get_idc_control(vha, &idc_control);
6429 idc_control &= ~QLA83XX_IDC_GRACEFUL_RESET;
6430 __qla83xx_set_idc_control(vha, 0);
6432 qla83xx_idc_unlock(vha, 0);
6433 rval = qla83xx_restart_nic_firmware(vha);
6434 qla83xx_idc_lock(vha, 0);
6436 if (rval != QLA_SUCCESS) {
6437 ql_log(ql_log_fatal, vha, 0xb06a,
6438 "Failed to restart NIC f/w.\n");
6439 qla83xx_wr_reg(vha, QLA83XX_IDC_DEV_STATE, QLA8XXX_DEV_FAILED);
6440 ql_log(ql_log_info, vha, 0xb06b, "HW State: FAILED.\n");
6442 ql_dbg(ql_dbg_p3p, vha, 0xb06c,
6443 "Success in restarting nic f/w.\n");
6444 qla83xx_wr_reg(vha, QLA83XX_IDC_DEV_STATE, QLA8XXX_DEV_READY);
6445 ql_log(ql_log_info, vha, 0xb06d, "HW State: READY.\n");
6451 /* Assumes idc_lock always held on entry */
6453 qla83xx_idc_state_handler(scsi_qla_host_t *base_vha)
6455 struct qla_hw_data *ha = base_vha->hw;
6456 int rval = QLA_SUCCESS;
6457 unsigned long dev_init_timeout;
6460 /* Wait for MAX-INIT-TIMEOUT for the device to go ready */
6461 dev_init_timeout = jiffies + (ha->fcoe_dev_init_timeout * HZ);
6465 if (time_after_eq(jiffies, dev_init_timeout)) {
6466 ql_log(ql_log_warn, base_vha, 0xb06e,
6467 "Initialization TIMEOUT!\n");
6468 /* Init timeout. Disable further NIC Core
6471 qla83xx_wr_reg(base_vha, QLA83XX_IDC_DEV_STATE,
6472 QLA8XXX_DEV_FAILED);
6473 ql_log(ql_log_info, base_vha, 0xb06f,
6474 "HW State: FAILED.\n");
6477 qla83xx_rd_reg(base_vha, QLA83XX_IDC_DEV_STATE, &dev_state);
6478 switch (dev_state) {
6479 case QLA8XXX_DEV_READY:
6480 if (ha->flags.nic_core_reset_owner)
6481 qla83xx_idc_audit(base_vha,
6482 IDC_AUDIT_COMPLETION);
6483 ha->flags.nic_core_reset_owner = 0;
6484 ql_dbg(ql_dbg_p3p, base_vha, 0xb070,
6485 "Reset_owner reset by 0x%x.\n",
6488 case QLA8XXX_DEV_COLD:
6489 if (ha->flags.nic_core_reset_owner)
6490 rval = qla83xx_device_bootstrap(base_vha);
6492 /* Wait for AEN to change device-state */
6493 qla83xx_idc_unlock(base_vha, 0);
6495 qla83xx_idc_lock(base_vha, 0);
6498 case QLA8XXX_DEV_INITIALIZING:
6499 /* Wait for AEN to change device-state */
6500 qla83xx_idc_unlock(base_vha, 0);
6502 qla83xx_idc_lock(base_vha, 0);
6504 case QLA8XXX_DEV_NEED_RESET:
6505 if (!ql2xdontresethba && ha->flags.nic_core_reset_owner)
6506 qla83xx_need_reset_handler(base_vha);
6508 /* Wait for AEN to change device-state */
6509 qla83xx_idc_unlock(base_vha, 0);
6511 qla83xx_idc_lock(base_vha, 0);
6513 /* reset timeout value after need reset handler */
6514 dev_init_timeout = jiffies +
6515 (ha->fcoe_dev_init_timeout * HZ);
6517 case QLA8XXX_DEV_NEED_QUIESCENT:
6518 /* XXX: DEBUG for now */
6519 qla83xx_idc_unlock(base_vha, 0);
6521 qla83xx_idc_lock(base_vha, 0);
6523 case QLA8XXX_DEV_QUIESCENT:
6524 /* XXX: DEBUG for now */
6525 if (ha->flags.quiesce_owner)
6528 qla83xx_idc_unlock(base_vha, 0);
6530 qla83xx_idc_lock(base_vha, 0);
6531 dev_init_timeout = jiffies +
6532 (ha->fcoe_dev_init_timeout * HZ);
6534 case QLA8XXX_DEV_FAILED:
6535 if (ha->flags.nic_core_reset_owner)
6536 qla83xx_idc_audit(base_vha,
6537 IDC_AUDIT_COMPLETION);
6538 ha->flags.nic_core_reset_owner = 0;
6539 __qla83xx_clear_drv_presence(base_vha);
6540 qla83xx_idc_unlock(base_vha, 0);
6541 qla8xxx_dev_failed_handler(base_vha);
6542 rval = QLA_FUNCTION_FAILED;
6543 qla83xx_idc_lock(base_vha, 0);
6545 case QLA8XXX_BAD_VALUE:
6546 qla83xx_idc_unlock(base_vha, 0);
6548 qla83xx_idc_lock(base_vha, 0);
6551 ql_log(ql_log_warn, base_vha, 0xb071,
6552 "Unknown Device State: %x.\n", dev_state);
6553 qla83xx_idc_unlock(base_vha, 0);
6554 qla8xxx_dev_failed_handler(base_vha);
6555 rval = QLA_FUNCTION_FAILED;
6556 qla83xx_idc_lock(base_vha, 0);
6566 qla2x00_disable_board_on_pci_error(struct work_struct *work)
6568 struct qla_hw_data *ha = container_of(work, struct qla_hw_data,
6570 struct pci_dev *pdev = ha->pdev;
6571 scsi_qla_host_t *base_vha = pci_get_drvdata(ha->pdev);
6573 ql_log(ql_log_warn, base_vha, 0x015b,
6574 "Disabling adapter.\n");
6576 if (!atomic_read(&pdev->enable_cnt)) {
6577 ql_log(ql_log_info, base_vha, 0xfffc,
6578 "PCI device disabled, no action req for PCI error=%lx\n",
6579 base_vha->pci_flags);
6584 * if UNLOADING flag is already set, then continue unload,
6585 * where it was set first.
6587 if (test_and_set_bit(UNLOADING, &base_vha->dpc_flags))
6590 qla2x00_wait_for_sess_deletion(base_vha);
6592 qla2x00_delete_all_vps(ha, base_vha);
6594 qla2x00_abort_all_cmds(base_vha, DID_NO_CONNECT << 16);
6596 qla2x00_dfs_remove(base_vha);
6598 qla84xx_put_chip(base_vha);
6600 if (base_vha->timer_active)
6601 qla2x00_stop_timer(base_vha);
6603 base_vha->flags.online = 0;
6605 qla2x00_destroy_deferred_work(ha);
6608 * Do not try to stop beacon blink as it will issue a mailbox
6611 qla2x00_free_sysfs_attr(base_vha, false);
6613 fc_remove_host(base_vha->host);
6615 scsi_remove_host(base_vha->host);
6617 base_vha->flags.init_done = 0;
6618 qla25xx_delete_queues(base_vha);
6619 qla2x00_free_fcports(base_vha);
6620 qla2x00_free_irqs(base_vha);
6621 qla2x00_mem_free(ha);
6622 qla82xx_md_free(base_vha);
6623 qla2x00_free_queues(ha);
6625 qla2x00_unmap_iobases(ha);
6627 pci_release_selected_regions(ha->pdev, ha->bars);
6628 pci_disable_pcie_error_reporting(pdev);
6629 pci_disable_device(pdev);
6632 * Let qla2x00_remove_one cleanup qla_hw_data on device removal.
6636 /**************************************************************************
6638 * This kernel thread is a task that is schedule by the interrupt handler
6639 * to perform the background processing for interrupts.
6642 * This task always run in the context of a kernel thread. It
6643 * is kick-off by the driver's detect code and starts up
6644 * up one per adapter. It immediately goes to sleep and waits for
6645 * some fibre event. When either the interrupt handler or
6646 * the timer routine detects a event it will one of the task
6647 * bits then wake us up.
6648 **************************************************************************/
6650 qla2x00_do_dpc(void *data)
6652 scsi_qla_host_t *base_vha;
6653 struct qla_hw_data *ha;
6655 struct qla_qpair *qpair;
6657 ha = (struct qla_hw_data *)data;
6658 base_vha = pci_get_drvdata(ha->pdev);
6660 set_user_nice(current, MIN_NICE);
6662 set_current_state(TASK_INTERRUPTIBLE);
6663 while (!kthread_should_stop()) {
6664 ql_dbg(ql_dbg_dpc, base_vha, 0x4000,
6665 "DPC handler sleeping.\n");
6669 if (test_and_clear_bit(DO_EEH_RECOVERY, &base_vha->dpc_flags))
6670 qla_pci_set_eeh_busy(base_vha);
6672 if (!base_vha->flags.init_done || ha->flags.mbox_busy)
6675 if (ha->flags.eeh_busy) {
6676 ql_dbg(ql_dbg_dpc, base_vha, 0x4003,
6677 "eeh_busy=%d.\n", ha->flags.eeh_busy);
6683 ql_dbg(ql_dbg_dpc + ql_dbg_verbose, base_vha, 0x4001,
6684 "DPC handler waking up, dpc_flags=0x%lx.\n",
6685 base_vha->dpc_flags);
6687 if (test_bit(UNLOADING, &base_vha->dpc_flags))
6690 if (IS_P3P_TYPE(ha)) {
6691 if (IS_QLA8044(ha)) {
6692 if (test_and_clear_bit(ISP_UNRECOVERABLE,
6693 &base_vha->dpc_flags)) {
6694 qla8044_idc_lock(ha);
6695 qla8044_wr_direct(base_vha,
6696 QLA8044_CRB_DEV_STATE_INDEX,
6697 QLA8XXX_DEV_FAILED);
6698 qla8044_idc_unlock(ha);
6699 ql_log(ql_log_info, base_vha, 0x4004,
6700 "HW State: FAILED.\n");
6701 qla8044_device_state_handler(base_vha);
6706 if (test_and_clear_bit(ISP_UNRECOVERABLE,
6707 &base_vha->dpc_flags)) {
6708 qla82xx_idc_lock(ha);
6709 qla82xx_wr_32(ha, QLA82XX_CRB_DEV_STATE,
6710 QLA8XXX_DEV_FAILED);
6711 qla82xx_idc_unlock(ha);
6712 ql_log(ql_log_info, base_vha, 0x0151,
6713 "HW State: FAILED.\n");
6714 qla82xx_device_state_handler(base_vha);
6719 if (test_and_clear_bit(FCOE_CTX_RESET_NEEDED,
6720 &base_vha->dpc_flags)) {
6722 ql_dbg(ql_dbg_dpc, base_vha, 0x4005,
6723 "FCoE context reset scheduled.\n");
6724 if (!(test_and_set_bit(ABORT_ISP_ACTIVE,
6725 &base_vha->dpc_flags))) {
6726 if (qla82xx_fcoe_ctx_reset(base_vha)) {
6727 /* FCoE-ctx reset failed.
6728 * Escalate to chip-reset
6730 set_bit(ISP_ABORT_NEEDED,
6731 &base_vha->dpc_flags);
6733 clear_bit(ABORT_ISP_ACTIVE,
6734 &base_vha->dpc_flags);
6737 ql_dbg(ql_dbg_dpc, base_vha, 0x4006,
6738 "FCoE context reset end.\n");
6740 } else if (IS_QLAFX00(ha)) {
6741 if (test_and_clear_bit(ISP_UNRECOVERABLE,
6742 &base_vha->dpc_flags)) {
6743 ql_dbg(ql_dbg_dpc, base_vha, 0x4020,
6744 "Firmware Reset Recovery\n");
6745 if (qlafx00_reset_initialize(base_vha)) {
6746 /* Failed. Abort isp later. */
6747 if (!test_bit(UNLOADING,
6748 &base_vha->dpc_flags)) {
6749 set_bit(ISP_UNRECOVERABLE,
6750 &base_vha->dpc_flags);
6751 ql_dbg(ql_dbg_dpc, base_vha,
6753 "Reset Recovery Failed\n");
6758 if (test_and_clear_bit(FX00_TARGET_SCAN,
6759 &base_vha->dpc_flags)) {
6760 ql_dbg(ql_dbg_dpc, base_vha, 0x4022,
6761 "ISPFx00 Target Scan scheduled\n");
6762 if (qlafx00_rescan_isp(base_vha)) {
6763 if (!test_bit(UNLOADING,
6764 &base_vha->dpc_flags))
6765 set_bit(ISP_UNRECOVERABLE,
6766 &base_vha->dpc_flags);
6767 ql_dbg(ql_dbg_dpc, base_vha, 0x401e,
6768 "ISPFx00 Target Scan Failed\n");
6770 ql_dbg(ql_dbg_dpc, base_vha, 0x401f,
6771 "ISPFx00 Target Scan End\n");
6773 if (test_and_clear_bit(FX00_HOST_INFO_RESEND,
6774 &base_vha->dpc_flags)) {
6775 ql_dbg(ql_dbg_dpc, base_vha, 0x4023,
6776 "ISPFx00 Host Info resend scheduled\n");
6777 qlafx00_fx_disc(base_vha,
6778 &base_vha->hw->mr.fcport,
6779 FXDISC_REG_HOST_INFO);
6783 if (test_and_clear_bit(DETECT_SFP_CHANGE,
6784 &base_vha->dpc_flags)) {
6786 * - NO-OP -- await next ISP-ABORT. Preferred method
6787 * to minimize disruptions that will occur
6788 * when a forced chip-reset occurs.
6789 * - Force -- ISP-ABORT scheduled.
6791 /* set_bit(ISP_ABORT_NEEDED, &base_vha->dpc_flags); */
6794 if (test_and_clear_bit
6795 (ISP_ABORT_NEEDED, &base_vha->dpc_flags) &&
6796 !test_bit(UNLOADING, &base_vha->dpc_flags)) {
6797 bool do_reset = true;
6799 switch (base_vha->qlini_mode) {
6800 case QLA2XXX_INI_MODE_ENABLED:
6802 case QLA2XXX_INI_MODE_DISABLED:
6803 if (!qla_tgt_mode_enabled(base_vha) &&
6804 !ha->flags.fw_started)
6807 case QLA2XXX_INI_MODE_DUAL:
6808 if (!qla_dual_mode_enabled(base_vha) &&
6809 !ha->flags.fw_started)
6816 if (do_reset && !(test_and_set_bit(ABORT_ISP_ACTIVE,
6817 &base_vha->dpc_flags))) {
6818 base_vha->flags.online = 1;
6819 ql_dbg(ql_dbg_dpc, base_vha, 0x4007,
6820 "ISP abort scheduled.\n");
6821 if (ha->isp_ops->abort_isp(base_vha)) {
6822 /* failed. retry later */
6823 set_bit(ISP_ABORT_NEEDED,
6824 &base_vha->dpc_flags);
6826 clear_bit(ABORT_ISP_ACTIVE,
6827 &base_vha->dpc_flags);
6828 ql_dbg(ql_dbg_dpc, base_vha, 0x4008,
6829 "ISP abort end.\n");
6833 if (test_bit(PROCESS_PUREX_IOCB, &base_vha->dpc_flags)) {
6834 if (atomic_read(&base_vha->loop_state) == LOOP_READY) {
6835 qla24xx_process_purex_list
6836 (&base_vha->purex_list);
6837 clear_bit(PROCESS_PUREX_IOCB,
6838 &base_vha->dpc_flags);
6842 if (test_and_clear_bit(FCPORT_UPDATE_NEEDED,
6843 &base_vha->dpc_flags)) {
6844 qla2x00_update_fcports(base_vha);
6848 goto loop_resync_check;
6850 if (test_bit(ISP_QUIESCE_NEEDED, &base_vha->dpc_flags)) {
6851 ql_dbg(ql_dbg_dpc, base_vha, 0x4009,
6852 "Quiescence mode scheduled.\n");
6853 if (IS_P3P_TYPE(ha)) {
6855 qla82xx_device_state_handler(base_vha);
6857 qla8044_device_state_handler(base_vha);
6858 clear_bit(ISP_QUIESCE_NEEDED,
6859 &base_vha->dpc_flags);
6860 if (!ha->flags.quiesce_owner) {
6861 qla2x00_perform_loop_resync(base_vha);
6862 if (IS_QLA82XX(ha)) {
6863 qla82xx_idc_lock(ha);
6864 qla82xx_clear_qsnt_ready(
6866 qla82xx_idc_unlock(ha);
6867 } else if (IS_QLA8044(ha)) {
6868 qla8044_idc_lock(ha);
6869 qla8044_clear_qsnt_ready(
6871 qla8044_idc_unlock(ha);
6875 clear_bit(ISP_QUIESCE_NEEDED,
6876 &base_vha->dpc_flags);
6877 qla2x00_quiesce_io(base_vha);
6879 ql_dbg(ql_dbg_dpc, base_vha, 0x400a,
6880 "Quiescence mode end.\n");
6883 if (test_and_clear_bit(RESET_MARKER_NEEDED,
6884 &base_vha->dpc_flags) &&
6885 (!(test_and_set_bit(RESET_ACTIVE, &base_vha->dpc_flags)))) {
6887 ql_dbg(ql_dbg_dpc, base_vha, 0x400b,
6888 "Reset marker scheduled.\n");
6889 qla2x00_rst_aen(base_vha);
6890 clear_bit(RESET_ACTIVE, &base_vha->dpc_flags);
6891 ql_dbg(ql_dbg_dpc, base_vha, 0x400c,
6892 "Reset marker end.\n");
6895 /* Retry each device up to login retry count */
6896 if (test_bit(RELOGIN_NEEDED, &base_vha->dpc_flags) &&
6897 !test_bit(LOOP_RESYNC_NEEDED, &base_vha->dpc_flags) &&
6898 atomic_read(&base_vha->loop_state) != LOOP_DOWN) {
6900 if (!base_vha->relogin_jif ||
6901 time_after_eq(jiffies, base_vha->relogin_jif)) {
6902 base_vha->relogin_jif = jiffies + HZ;
6903 clear_bit(RELOGIN_NEEDED, &base_vha->dpc_flags);
6905 ql_dbg(ql_dbg_disc, base_vha, 0x400d,
6906 "Relogin scheduled.\n");
6907 qla24xx_post_relogin_work(base_vha);
6911 if (!qla2x00_reset_active(base_vha) &&
6912 test_and_clear_bit(LOOP_RESYNC_NEEDED,
6913 &base_vha->dpc_flags)) {
6915 * Allow abort_isp to complete before moving on to scanning.
6917 ql_dbg(ql_dbg_dpc, base_vha, 0x400f,
6918 "Loop resync scheduled.\n");
6920 if (!(test_and_set_bit(LOOP_RESYNC_ACTIVE,
6921 &base_vha->dpc_flags))) {
6923 qla2x00_loop_resync(base_vha);
6925 clear_bit(LOOP_RESYNC_ACTIVE,
6926 &base_vha->dpc_flags);
6929 ql_dbg(ql_dbg_dpc, base_vha, 0x4010,
6930 "Loop resync end.\n");
6936 if (test_bit(NPIV_CONFIG_NEEDED, &base_vha->dpc_flags) &&
6937 atomic_read(&base_vha->loop_state) == LOOP_READY) {
6938 clear_bit(NPIV_CONFIG_NEEDED, &base_vha->dpc_flags);
6939 qla2xxx_flash_npiv_conf(base_vha);
6943 if (!ha->interrupts_on)
6944 ha->isp_ops->enable_intrs(ha);
6946 if (test_and_clear_bit(BEACON_BLINK_NEEDED,
6947 &base_vha->dpc_flags)) {
6948 if (ha->beacon_blink_led == 1)
6949 ha->isp_ops->beacon_blink(base_vha);
6952 /* qpair online check */
6953 if (test_and_clear_bit(QPAIR_ONLINE_CHECK_NEEDED,
6954 &base_vha->dpc_flags)) {
6955 if (ha->flags.eeh_busy ||
6956 ha->flags.pci_channel_io_perm_failure)
6961 mutex_lock(&ha->mq_lock);
6962 list_for_each_entry(qpair, &base_vha->qp_list,
6964 qpair->online = online;
6965 mutex_unlock(&ha->mq_lock);
6968 if (test_and_clear_bit(SET_ZIO_THRESHOLD_NEEDED,
6969 &base_vha->dpc_flags)) {
6970 u16 threshold = ha->nvme_last_rptd_aen + ha->last_zio_threshold;
6972 if (threshold > ha->orig_fw_xcb_count)
6973 threshold = ha->orig_fw_xcb_count;
6975 ql_log(ql_log_info, base_vha, 0xffffff,
6976 "SET ZIO Activity exchange threshold to %d.\n",
6978 if (qla27xx_set_zio_threshold(base_vha, threshold)) {
6979 ql_log(ql_log_info, base_vha, 0xffffff,
6980 "Unable to SET ZIO Activity exchange threshold to %d.\n",
6985 if (!IS_QLAFX00(ha))
6986 qla2x00_do_dpc_all_vps(base_vha);
6988 if (test_and_clear_bit(N2N_LINK_RESET,
6989 &base_vha->dpc_flags)) {
6990 qla2x00_lip_reset(base_vha);
6995 set_current_state(TASK_INTERRUPTIBLE);
6996 } /* End of while(1) */
6997 __set_current_state(TASK_RUNNING);
6999 ql_dbg(ql_dbg_dpc, base_vha, 0x4011,
7000 "DPC handler exiting.\n");
7003 * Make sure that nobody tries to wake us up again.
7007 /* Cleanup any residual CTX SRBs. */
7008 qla2x00_abort_all_cmds(base_vha, DID_NO_CONNECT << 16);
7014 qla2xxx_wake_dpc(struct scsi_qla_host *vha)
7016 struct qla_hw_data *ha = vha->hw;
7017 struct task_struct *t = ha->dpc_thread;
7019 if (!test_bit(UNLOADING, &vha->dpc_flags) && t)
7025 * Processes asynchronous reset.
7028 * ha = adapter block pointer.
7031 qla2x00_rst_aen(scsi_qla_host_t *vha)
7033 if (vha->flags.online && !vha->flags.reset_active &&
7034 !atomic_read(&vha->loop_down_timer) &&
7035 !(test_bit(ABORT_ISP_ACTIVE, &vha->dpc_flags))) {
7037 clear_bit(RESET_MARKER_NEEDED, &vha->dpc_flags);
7040 * Issue marker command only when we are going to start
7043 vha->marker_needed = 1;
7044 } while (!atomic_read(&vha->loop_down_timer) &&
7045 (test_bit(RESET_MARKER_NEEDED, &vha->dpc_flags)));
7049 /**************************************************************************
7055 * Context: Interrupt
7056 ***************************************************************************/
7058 qla2x00_timer(struct timer_list *t)
7060 scsi_qla_host_t *vha = from_timer(vha, t, timer);
7061 unsigned long cpu_flags = 0;
7066 struct qla_hw_data *ha = vha->hw;
7067 struct req_que *req;
7069 if (ha->flags.eeh_busy) {
7070 ql_dbg(ql_dbg_timer, vha, 0x6000,
7071 "EEH = %d, restarting timer.\n",
7072 ha->flags.eeh_busy);
7073 qla2x00_restart_timer(vha, WATCH_INTERVAL);
7078 * Hardware read to raise pending EEH errors during mailbox waits. If
7079 * the read returns -1 then disable the board.
7081 if (!pci_channel_offline(ha->pdev)) {
7082 pci_read_config_word(ha->pdev, PCI_VENDOR_ID, &w);
7083 qla2x00_check_reg16_for_disconnect(vha, w);
7086 /* Make sure qla82xx_watchdog is run only for physical port */
7087 if (!vha->vp_idx && IS_P3P_TYPE(ha)) {
7088 if (test_bit(ISP_QUIESCE_NEEDED, &vha->dpc_flags))
7091 qla82xx_watchdog(vha);
7092 else if (IS_QLA8044(ha))
7093 qla8044_watchdog(vha);
7096 if (!vha->vp_idx && IS_QLAFX00(ha))
7097 qlafx00_timer_routine(vha);
7099 /* Loop down handler. */
7100 if (atomic_read(&vha->loop_down_timer) > 0 &&
7101 !(test_bit(ABORT_ISP_ACTIVE, &vha->dpc_flags)) &&
7102 !(test_bit(FCOE_CTX_RESET_NEEDED, &vha->dpc_flags))
7103 && vha->flags.online) {
7105 if (atomic_read(&vha->loop_down_timer) ==
7106 vha->loop_down_abort_time) {
7108 ql_log(ql_log_info, vha, 0x6008,
7109 "Loop down - aborting the queues before time expires.\n");
7111 if (!IS_QLA2100(ha) && vha->link_down_timeout)
7112 atomic_set(&vha->loop_state, LOOP_DEAD);
7115 * Schedule an ISP abort to return any FCP2-device
7118 /* NPIV - scan physical port only */
7120 spin_lock_irqsave(&ha->hardware_lock,
7122 req = ha->req_q_map[0];
7124 index < req->num_outstanding_cmds;
7128 sp = req->outstanding_cmds[index];
7131 if (sp->cmd_type != TYPE_SRB)
7133 if (sp->type != SRB_SCSI_CMD)
7136 if (!(sfcp->flags & FCF_FCP2_DEVICE))
7140 set_bit(FCOE_CTX_RESET_NEEDED,
7143 set_bit(ISP_ABORT_NEEDED,
7147 spin_unlock_irqrestore(&ha->hardware_lock,
7153 /* if the loop has been down for 4 minutes, reinit adapter */
7154 if (atomic_dec_and_test(&vha->loop_down_timer) != 0) {
7155 if (!(vha->device_flags & DFLG_NO_CABLE) && !vha->vp_idx) {
7156 ql_log(ql_log_warn, vha, 0x6009,
7157 "Loop down - aborting ISP.\n");
7160 set_bit(FCOE_CTX_RESET_NEEDED,
7163 set_bit(ISP_ABORT_NEEDED,
7167 ql_dbg(ql_dbg_timer, vha, 0x600a,
7168 "Loop down - seconds remaining %d.\n",
7169 atomic_read(&vha->loop_down_timer));
7171 /* Check if beacon LED needs to be blinked for physical host only */
7172 if (!vha->vp_idx && (ha->beacon_blink_led == 1)) {
7173 /* There is no beacon_blink function for ISP82xx */
7174 if (!IS_P3P_TYPE(ha)) {
7175 set_bit(BEACON_BLINK_NEEDED, &vha->dpc_flags);
7180 /* Process any deferred work. */
7181 if (!list_empty(&vha->work_list)) {
7182 unsigned long flags;
7185 spin_lock_irqsave(&vha->work_lock, flags);
7186 if (!test_and_set_bit(IOCB_WORK_ACTIVE, &vha->dpc_flags))
7188 spin_unlock_irqrestore(&vha->work_lock, flags);
7190 queue_work(vha->hw->wq, &vha->iocb_work);
7195 * see if the active AEN count has changed from what was last reported.
7197 index = atomic_read(&ha->nvme_active_aen_cnt);
7199 (index != ha->nvme_last_rptd_aen) &&
7200 ha->zio_mode == QLA_ZIO_MODE_6 &&
7201 !ha->flags.host_shutting_down) {
7202 ha->nvme_last_rptd_aen = atomic_read(&ha->nvme_active_aen_cnt);
7203 ql_log(ql_log_info, vha, 0x3002,
7204 "nvme: Sched: Set ZIO exchange threshold to %d.\n",
7205 ha->nvme_last_rptd_aen);
7206 set_bit(SET_ZIO_THRESHOLD_NEEDED, &vha->dpc_flags);
7211 atomic_read(&ha->zio_threshold) != ha->last_zio_threshold &&
7212 IS_ZIO_THRESHOLD_CAPABLE(ha)) {
7213 ql_log(ql_log_info, vha, 0x3002,
7214 "Sched: Set ZIO exchange threshold to %d.\n",
7215 ha->last_zio_threshold);
7216 ha->last_zio_threshold = atomic_read(&ha->zio_threshold);
7217 set_bit(SET_ZIO_THRESHOLD_NEEDED, &vha->dpc_flags);
7221 /* Schedule the DPC routine if needed */
7222 if ((test_bit(ISP_ABORT_NEEDED, &vha->dpc_flags) ||
7223 test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags) ||
7224 test_bit(FCPORT_UPDATE_NEEDED, &vha->dpc_flags) ||
7226 test_bit(RESET_MARKER_NEEDED, &vha->dpc_flags) ||
7227 test_bit(BEACON_BLINK_NEEDED, &vha->dpc_flags) ||
7228 test_bit(ISP_UNRECOVERABLE, &vha->dpc_flags) ||
7229 test_bit(FCOE_CTX_RESET_NEEDED, &vha->dpc_flags) ||
7230 test_bit(VP_DPC_NEEDED, &vha->dpc_flags) ||
7231 test_bit(RELOGIN_NEEDED, &vha->dpc_flags) ||
7232 test_bit(PROCESS_PUREX_IOCB, &vha->dpc_flags))) {
7233 ql_dbg(ql_dbg_timer, vha, 0x600b,
7234 "isp_abort_needed=%d loop_resync_needed=%d "
7235 "fcport_update_needed=%d start_dpc=%d "
7236 "reset_marker_needed=%d",
7237 test_bit(ISP_ABORT_NEEDED, &vha->dpc_flags),
7238 test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags),
7239 test_bit(FCPORT_UPDATE_NEEDED, &vha->dpc_flags),
7241 test_bit(RESET_MARKER_NEEDED, &vha->dpc_flags));
7242 ql_dbg(ql_dbg_timer, vha, 0x600c,
7243 "beacon_blink_needed=%d isp_unrecoverable=%d "
7244 "fcoe_ctx_reset_needed=%d vp_dpc_needed=%d "
7245 "relogin_needed=%d, Process_purex_iocb=%d.\n",
7246 test_bit(BEACON_BLINK_NEEDED, &vha->dpc_flags),
7247 test_bit(ISP_UNRECOVERABLE, &vha->dpc_flags),
7248 test_bit(FCOE_CTX_RESET_NEEDED, &vha->dpc_flags),
7249 test_bit(VP_DPC_NEEDED, &vha->dpc_flags),
7250 test_bit(RELOGIN_NEEDED, &vha->dpc_flags),
7251 test_bit(PROCESS_PUREX_IOCB, &vha->dpc_flags));
7252 qla2xxx_wake_dpc(vha);
7255 qla2x00_restart_timer(vha, WATCH_INTERVAL);
7258 /* Firmware interface routines. */
7260 #define FW_ISP21XX 0
7261 #define FW_ISP22XX 1
7262 #define FW_ISP2300 2
7263 #define FW_ISP2322 3
7264 #define FW_ISP24XX 4
7265 #define FW_ISP25XX 5
7266 #define FW_ISP81XX 6
7267 #define FW_ISP82XX 7
7268 #define FW_ISP2031 8
7269 #define FW_ISP8031 9
7270 #define FW_ISP27XX 10
7271 #define FW_ISP28XX 11
7273 #define FW_FILE_ISP21XX "/*(DEBLOBBED)*/"
7274 #define FW_FILE_ISP22XX "/*(DEBLOBBED)*/"
7275 #define FW_FILE_ISP2300 "/*(DEBLOBBED)*/"
7276 #define FW_FILE_ISP2322 "/*(DEBLOBBED)*/"
7277 #define FW_FILE_ISP24XX "/*(DEBLOBBED)*/"
7278 #define FW_FILE_ISP25XX "/*(DEBLOBBED)*/"
7279 #define FW_FILE_ISP81XX "/*(DEBLOBBED)*/"
7280 #define FW_FILE_ISP82XX "/*(DEBLOBBED)*/"
7281 #define FW_FILE_ISP2031 "/*(DEBLOBBED)*/"
7282 #define FW_FILE_ISP8031 "/*(DEBLOBBED)*/"
7283 #define FW_FILE_ISP27XX "/*(DEBLOBBED)*/"
7284 #define FW_FILE_ISP28XX "/*(DEBLOBBED)*/"
7287 static DEFINE_MUTEX(qla_fw_lock);
7289 static struct fw_blob qla_fw_blobs[] = {
7290 { .name = FW_FILE_ISP21XX, .segs = { 0x1000, 0 }, },
7291 { .name = FW_FILE_ISP22XX, .segs = { 0x1000, 0 }, },
7292 { .name = FW_FILE_ISP2300, .segs = { 0x800, 0 }, },
7293 { .name = FW_FILE_ISP2322, .segs = { 0x800, 0x1c000, 0x1e000, 0 }, },
7294 { .name = FW_FILE_ISP24XX, },
7295 { .name = FW_FILE_ISP25XX, },
7296 { .name = FW_FILE_ISP81XX, },
7297 { .name = FW_FILE_ISP82XX, },
7298 { .name = FW_FILE_ISP2031, },
7299 { .name = FW_FILE_ISP8031, },
7300 { .name = FW_FILE_ISP27XX, },
7301 { .name = FW_FILE_ISP28XX, },
7306 qla2x00_request_firmware(scsi_qla_host_t *vha)
7308 struct qla_hw_data *ha = vha->hw;
7309 struct fw_blob *blob;
7311 if (IS_QLA2100(ha)) {
7312 blob = &qla_fw_blobs[FW_ISP21XX];
7313 } else if (IS_QLA2200(ha)) {
7314 blob = &qla_fw_blobs[FW_ISP22XX];
7315 } else if (IS_QLA2300(ha) || IS_QLA2312(ha) || IS_QLA6312(ha)) {
7316 blob = &qla_fw_blobs[FW_ISP2300];
7317 } else if (IS_QLA2322(ha) || IS_QLA6322(ha)) {
7318 blob = &qla_fw_blobs[FW_ISP2322];
7319 } else if (IS_QLA24XX_TYPE(ha)) {
7320 blob = &qla_fw_blobs[FW_ISP24XX];
7321 } else if (IS_QLA25XX(ha)) {
7322 blob = &qla_fw_blobs[FW_ISP25XX];
7323 } else if (IS_QLA81XX(ha)) {
7324 blob = &qla_fw_blobs[FW_ISP81XX];
7325 } else if (IS_QLA82XX(ha)) {
7326 blob = &qla_fw_blobs[FW_ISP82XX];
7327 } else if (IS_QLA2031(ha)) {
7328 blob = &qla_fw_blobs[FW_ISP2031];
7329 } else if (IS_QLA8031(ha)) {
7330 blob = &qla_fw_blobs[FW_ISP8031];
7331 } else if (IS_QLA27XX(ha)) {
7332 blob = &qla_fw_blobs[FW_ISP27XX];
7333 } else if (IS_QLA28XX(ha)) {
7334 blob = &qla_fw_blobs[FW_ISP28XX];
7342 mutex_lock(&qla_fw_lock);
7346 if (reject_firmware(&blob->fw, blob->name, &ha->pdev->dev)) {
7347 ql_log(ql_log_warn, vha, 0x0063,
7348 "Failed to load firmware image (%s).\n", blob->name);
7354 mutex_unlock(&qla_fw_lock);
7359 qla2x00_release_firmware(void)
7361 struct fw_blob *blob;
7363 mutex_lock(&qla_fw_lock);
7364 for (blob = qla_fw_blobs; blob->name; blob++)
7365 release_firmware(blob->fw);
7366 mutex_unlock(&qla_fw_lock);
7369 static void qla_pci_error_cleanup(scsi_qla_host_t *vha)
7371 struct qla_hw_data *ha = vha->hw;
7372 scsi_qla_host_t *base_vha = pci_get_drvdata(ha->pdev);
7373 struct qla_qpair *qpair = NULL;
7374 struct scsi_qla_host *vp;
7377 unsigned long flags;
7379 ql_dbg(ql_dbg_aer, vha, 0x9000,
7383 ha->base_qpair->chip_reset = ha->chip_reset;
7384 for (i = 0; i < ha->max_qpairs; i++) {
7385 if (ha->queue_pair_map[i])
7386 ha->queue_pair_map[i]->chip_reset =
7387 ha->base_qpair->chip_reset;
7391 * purge mailbox might take a while. Slot Reset/chip reset
7392 * will take care of the purge
7395 mutex_lock(&ha->mq_lock);
7396 ha->base_qpair->online = 0;
7397 list_for_each_entry(qpair, &base_vha->qp_list, qp_list_elem)
7400 mutex_unlock(&ha->mq_lock);
7402 qla2x00_mark_all_devices_lost(vha);
7404 spin_lock_irqsave(&ha->vport_slock, flags);
7405 list_for_each_entry(vp, &ha->vp_list, list) {
7406 atomic_inc(&vp->vref_count);
7407 spin_unlock_irqrestore(&ha->vport_slock, flags);
7408 qla2x00_mark_all_devices_lost(vp);
7409 spin_lock_irqsave(&ha->vport_slock, flags);
7410 atomic_dec(&vp->vref_count);
7412 spin_unlock_irqrestore(&ha->vport_slock, flags);
7414 /* Clear all async request states across all VPs. */
7415 list_for_each_entry(fcport, &vha->vp_fcports, list)
7416 fcport->flags &= ~(FCF_LOGIN_NEEDED | FCF_ASYNC_SENT);
7418 spin_lock_irqsave(&ha->vport_slock, flags);
7419 list_for_each_entry(vp, &ha->vp_list, list) {
7420 atomic_inc(&vp->vref_count);
7421 spin_unlock_irqrestore(&ha->vport_slock, flags);
7422 list_for_each_entry(fcport, &vp->vp_fcports, list)
7423 fcport->flags &= ~(FCF_LOGIN_NEEDED | FCF_ASYNC_SENT);
7424 spin_lock_irqsave(&ha->vport_slock, flags);
7425 atomic_dec(&vp->vref_count);
7427 spin_unlock_irqrestore(&ha->vport_slock, flags);
7431 static pci_ers_result_t
7432 qla2xxx_pci_error_detected(struct pci_dev *pdev, pci_channel_state_t state)
7434 scsi_qla_host_t *vha = pci_get_drvdata(pdev);
7435 struct qla_hw_data *ha = vha->hw;
7436 pci_ers_result_t ret = PCI_ERS_RESULT_NEED_RESET;
7438 ql_log(ql_log_warn, vha, 0x9000,
7439 "PCI error detected, state %x.\n", state);
7440 ha->pci_error_state = QLA_PCI_ERR_DETECTED;
7442 if (!atomic_read(&pdev->enable_cnt)) {
7443 ql_log(ql_log_info, vha, 0xffff,
7444 "PCI device is disabled,state %x\n", state);
7445 ret = PCI_ERS_RESULT_NEED_RESET;
7450 case pci_channel_io_normal:
7451 ha->flags.eeh_busy = 0;
7452 if (ql2xmqsupport || ql2xnvmeenable) {
7453 set_bit(QPAIR_ONLINE_CHECK_NEEDED, &vha->dpc_flags);
7454 qla2xxx_wake_dpc(vha);
7456 ret = PCI_ERS_RESULT_CAN_RECOVER;
7458 case pci_channel_io_frozen:
7459 qla_pci_set_eeh_busy(vha);
7460 ret = PCI_ERS_RESULT_NEED_RESET;
7462 case pci_channel_io_perm_failure:
7463 ha->flags.pci_channel_io_perm_failure = 1;
7464 qla2x00_abort_all_cmds(vha, DID_NO_CONNECT << 16);
7465 if (ql2xmqsupport || ql2xnvmeenable) {
7466 set_bit(QPAIR_ONLINE_CHECK_NEEDED, &vha->dpc_flags);
7467 qla2xxx_wake_dpc(vha);
7469 ret = PCI_ERS_RESULT_DISCONNECT;
7472 ql_dbg(ql_dbg_aer, vha, 0x600d,
7473 "PCI error detected returning [%x].\n", ret);
7477 static pci_ers_result_t
7478 qla2xxx_pci_mmio_enabled(struct pci_dev *pdev)
7480 int risc_paused = 0;
7482 unsigned long flags;
7483 scsi_qla_host_t *base_vha = pci_get_drvdata(pdev);
7484 struct qla_hw_data *ha = base_vha->hw;
7485 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
7486 struct device_reg_24xx __iomem *reg24 = &ha->iobase->isp24;
7488 ql_log(ql_log_warn, base_vha, 0x9000,
7491 ha->pci_error_state = QLA_PCI_MMIO_ENABLED;
7493 return PCI_ERS_RESULT_RECOVERED;
7495 spin_lock_irqsave(&ha->hardware_lock, flags);
7496 if (IS_QLA2100(ha) || IS_QLA2200(ha)){
7497 stat = rd_reg_word(®->hccr);
7498 if (stat & HCCR_RISC_PAUSE)
7500 } else if (IS_QLA23XX(ha)) {
7501 stat = rd_reg_dword(®->u.isp2300.host_status);
7502 if (stat & HSR_RISC_PAUSED)
7504 } else if (IS_FWI2_CAPABLE(ha)) {
7505 stat = rd_reg_dword(®24->host_status);
7506 if (stat & HSRX_RISC_PAUSED)
7509 spin_unlock_irqrestore(&ha->hardware_lock, flags);
7512 ql_log(ql_log_info, base_vha, 0x9003,
7513 "RISC paused -- mmio_enabled, Dumping firmware.\n");
7514 qla2xxx_dump_fw(base_vha);
7516 /* set PCI_ERS_RESULT_NEED_RESET to trigger call to qla2xxx_pci_slot_reset */
7517 ql_dbg(ql_dbg_aer, base_vha, 0x600d,
7518 "mmio enabled returning.\n");
7519 return PCI_ERS_RESULT_NEED_RESET;
7522 static pci_ers_result_t
7523 qla2xxx_pci_slot_reset(struct pci_dev *pdev)
7525 pci_ers_result_t ret = PCI_ERS_RESULT_DISCONNECT;
7526 scsi_qla_host_t *base_vha = pci_get_drvdata(pdev);
7527 struct qla_hw_data *ha = base_vha->hw;
7529 struct qla_qpair *qpair = NULL;
7531 ql_log(ql_log_warn, base_vha, 0x9004,
7534 ha->pci_error_state = QLA_PCI_SLOT_RESET;
7535 /* Workaround: qla2xxx driver which access hardware earlier
7536 * needs error state to be pci_channel_io_online.
7537 * Otherwise mailbox command timesout.
7539 pdev->error_state = pci_channel_io_normal;
7541 pci_restore_state(pdev);
7543 /* pci_restore_state() clears the saved_state flag of the device
7544 * save restored state which resets saved_state flag
7546 pci_save_state(pdev);
7549 rc = pci_enable_device_mem(pdev);
7551 rc = pci_enable_device(pdev);
7554 ql_log(ql_log_warn, base_vha, 0x9005,
7555 "Can't re-enable PCI device after reset.\n");
7556 goto exit_slot_reset;
7560 if (ha->isp_ops->pci_config(base_vha))
7561 goto exit_slot_reset;
7563 mutex_lock(&ha->mq_lock);
7564 list_for_each_entry(qpair, &base_vha->qp_list, qp_list_elem)
7566 mutex_unlock(&ha->mq_lock);
7568 ha->flags.eeh_busy = 0;
7569 base_vha->flags.online = 1;
7570 set_bit(ABORT_ISP_ACTIVE, &base_vha->dpc_flags);
7571 ha->isp_ops->abort_isp(base_vha);
7572 clear_bit(ABORT_ISP_ACTIVE, &base_vha->dpc_flags);
7574 if (qla2x00_isp_reg_stat(ha)) {
7575 ha->flags.eeh_busy = 1;
7576 qla_pci_error_cleanup(base_vha);
7577 ql_log(ql_log_warn, base_vha, 0x9005,
7578 "Device unable to recover from PCI error.\n");
7580 ret = PCI_ERS_RESULT_RECOVERED;
7584 ql_dbg(ql_dbg_aer, base_vha, 0x900e,
7585 "Slot Reset returning %x.\n", ret);
7591 qla2xxx_pci_resume(struct pci_dev *pdev)
7593 scsi_qla_host_t *base_vha = pci_get_drvdata(pdev);
7594 struct qla_hw_data *ha = base_vha->hw;
7597 ql_log(ql_log_warn, base_vha, 0x900f,
7601 ret = qla2x00_wait_for_hba_online(base_vha);
7602 if (ret != QLA_SUCCESS) {
7603 ql_log(ql_log_fatal, base_vha, 0x9002,
7604 "The device failed to resume I/O from slot/link_reset.\n");
7606 ha->pci_error_state = QLA_PCI_RESUME;
7607 ql_dbg(ql_dbg_aer, base_vha, 0x600d,
7608 "Pci Resume returning.\n");
7611 void qla_pci_set_eeh_busy(struct scsi_qla_host *vha)
7613 struct qla_hw_data *ha = vha->hw;
7614 struct scsi_qla_host *base_vha = pci_get_drvdata(ha->pdev);
7615 bool do_cleanup = false;
7616 unsigned long flags;
7618 if (ha->flags.eeh_busy)
7621 spin_lock_irqsave(&base_vha->work_lock, flags);
7622 if (!ha->flags.eeh_busy) {
7623 ha->flags.eeh_busy = 1;
7626 spin_unlock_irqrestore(&base_vha->work_lock, flags);
7629 qla_pci_error_cleanup(base_vha);
7633 * this routine will schedule a task to pause IO from interrupt context
7634 * if caller sees a PCIE error event (register read = 0xf's)
7636 void qla_schedule_eeh_work(struct scsi_qla_host *vha)
7638 struct qla_hw_data *ha = vha->hw;
7639 struct scsi_qla_host *base_vha = pci_get_drvdata(ha->pdev);
7641 if (ha->flags.eeh_busy)
7644 set_bit(DO_EEH_RECOVERY, &base_vha->dpc_flags);
7645 qla2xxx_wake_dpc(base_vha);
7649 qla_pci_reset_prepare(struct pci_dev *pdev)
7651 scsi_qla_host_t *base_vha = pci_get_drvdata(pdev);
7652 struct qla_hw_data *ha = base_vha->hw;
7653 struct qla_qpair *qpair;
7655 ql_log(ql_log_warn, base_vha, 0xffff,
7659 * PCI FLR/function reset is about to reset the
7660 * slot. Stop the chip to stop all DMA access.
7661 * It is assumed that pci_reset_done will be called
7662 * after FLR to resume Chip operation.
7664 ha->flags.eeh_busy = 1;
7665 mutex_lock(&ha->mq_lock);
7666 list_for_each_entry(qpair, &base_vha->qp_list, qp_list_elem)
7668 mutex_unlock(&ha->mq_lock);
7670 set_bit(ABORT_ISP_ACTIVE, &base_vha->dpc_flags);
7671 qla2x00_abort_isp_cleanup(base_vha);
7672 qla2x00_abort_all_cmds(base_vha, DID_RESET << 16);
7676 qla_pci_reset_done(struct pci_dev *pdev)
7678 scsi_qla_host_t *base_vha = pci_get_drvdata(pdev);
7679 struct qla_hw_data *ha = base_vha->hw;
7680 struct qla_qpair *qpair;
7682 ql_log(ql_log_warn, base_vha, 0xffff,
7686 * FLR just completed by PCI layer. Resume adapter
7688 ha->flags.eeh_busy = 0;
7689 mutex_lock(&ha->mq_lock);
7690 list_for_each_entry(qpair, &base_vha->qp_list, qp_list_elem)
7692 mutex_unlock(&ha->mq_lock);
7694 base_vha->flags.online = 1;
7695 ha->isp_ops->abort_isp(base_vha);
7696 clear_bit(ABORT_ISP_ACTIVE, &base_vha->dpc_flags);
7699 static int qla2xxx_map_queues(struct Scsi_Host *shost)
7702 scsi_qla_host_t *vha = (scsi_qla_host_t *)shost->hostdata;
7703 struct blk_mq_queue_map *qmap = &shost->tag_set.map[HCTX_TYPE_DEFAULT];
7705 if (USER_CTRL_IRQ(vha->hw) || !vha->hw->mqiobase)
7706 rc = blk_mq_map_queues(qmap);
7708 rc = blk_mq_pci_map_queues(qmap, vha->hw->pdev, vha->irq_offset);
7712 struct scsi_host_template qla2xxx_driver_template = {
7713 .module = THIS_MODULE,
7714 .name = QLA2XXX_DRIVER_NAME,
7715 .queuecommand = qla2xxx_queuecommand,
7717 .eh_timed_out = fc_eh_timed_out,
7718 .eh_abort_handler = qla2xxx_eh_abort,
7719 .eh_device_reset_handler = qla2xxx_eh_device_reset,
7720 .eh_target_reset_handler = qla2xxx_eh_target_reset,
7721 .eh_bus_reset_handler = qla2xxx_eh_bus_reset,
7722 .eh_host_reset_handler = qla2xxx_eh_host_reset,
7724 .slave_configure = qla2xxx_slave_configure,
7726 .slave_alloc = qla2xxx_slave_alloc,
7727 .slave_destroy = qla2xxx_slave_destroy,
7728 .scan_finished = qla2xxx_scan_finished,
7729 .scan_start = qla2xxx_scan_start,
7730 .change_queue_depth = scsi_change_queue_depth,
7731 .map_queues = qla2xxx_map_queues,
7734 .sg_tablesize = SG_ALL,
7736 .max_sectors = 0xFFFF,
7737 .shost_attrs = qla2x00_host_attrs,
7739 .supported_mode = MODE_INITIATOR,
7740 .track_queue_depth = 1,
7741 .cmd_size = sizeof(srb_t),
7744 static const struct pci_error_handlers qla2xxx_err_handler = {
7745 .error_detected = qla2xxx_pci_error_detected,
7746 .mmio_enabled = qla2xxx_pci_mmio_enabled,
7747 .slot_reset = qla2xxx_pci_slot_reset,
7748 .resume = qla2xxx_pci_resume,
7749 .reset_prepare = qla_pci_reset_prepare,
7750 .reset_done = qla_pci_reset_done,
7753 static struct pci_device_id qla2xxx_pci_tbl[] = {
7754 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP2100) },
7755 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP2200) },
7756 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP2300) },
7757 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP2312) },
7758 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP2322) },
7759 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP6312) },
7760 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP6322) },
7761 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP2422) },
7762 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP2432) },
7763 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP8432) },
7764 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP5422) },
7765 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP5432) },
7766 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP2532) },
7767 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP2031) },
7768 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP8001) },
7769 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP8021) },
7770 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP8031) },
7771 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISPF001) },
7772 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP8044) },
7773 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP2071) },
7774 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP2271) },
7775 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP2261) },
7776 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP2061) },
7777 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP2081) },
7778 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP2281) },
7779 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP2089) },
7780 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP2289) },
7783 MODULE_DEVICE_TABLE(pci, qla2xxx_pci_tbl);
7785 static struct pci_driver qla2xxx_pci_driver = {
7786 .name = QLA2XXX_DRIVER_NAME,
7788 .owner = THIS_MODULE,
7790 .id_table = qla2xxx_pci_tbl,
7791 .probe = qla2x00_probe_one,
7792 .remove = qla2x00_remove_one,
7793 .shutdown = qla2x00_shutdown,
7794 .err_handler = &qla2xxx_err_handler,
7797 static const struct file_operations apidev_fops = {
7798 .owner = THIS_MODULE,
7799 .llseek = noop_llseek,
7803 * qla2x00_module_init - Module initialization.
7806 qla2x00_module_init(void)
7810 BUILD_BUG_ON(sizeof(cmd_a64_entry_t) != 64);
7811 BUILD_BUG_ON(sizeof(cmd_entry_t) != 64);
7812 BUILD_BUG_ON(sizeof(cont_a64_entry_t) != 64);
7813 BUILD_BUG_ON(sizeof(cont_entry_t) != 64);
7814 BUILD_BUG_ON(sizeof(init_cb_t) != 96);
7815 BUILD_BUG_ON(sizeof(mrk_entry_t) != 64);
7816 BUILD_BUG_ON(sizeof(ms_iocb_entry_t) != 64);
7817 BUILD_BUG_ON(sizeof(request_t) != 64);
7818 BUILD_BUG_ON(sizeof(struct abort_entry_24xx) != 64);
7819 BUILD_BUG_ON(sizeof(struct abort_iocb_entry_fx00) != 64);
7820 BUILD_BUG_ON(sizeof(struct abts_entry_24xx) != 64);
7821 BUILD_BUG_ON(sizeof(struct access_chip_84xx) != 64);
7822 BUILD_BUG_ON(sizeof(struct access_chip_rsp_84xx) != 64);
7823 BUILD_BUG_ON(sizeof(struct cmd_bidir) != 64);
7824 BUILD_BUG_ON(sizeof(struct cmd_nvme) != 64);
7825 BUILD_BUG_ON(sizeof(struct cmd_type_6) != 64);
7826 BUILD_BUG_ON(sizeof(struct cmd_type_7) != 64);
7827 BUILD_BUG_ON(sizeof(struct cmd_type_7_fx00) != 64);
7828 BUILD_BUG_ON(sizeof(struct cmd_type_crc_2) != 64);
7829 BUILD_BUG_ON(sizeof(struct ct_entry_24xx) != 64);
7830 BUILD_BUG_ON(sizeof(struct ct_fdmi1_hba_attributes) != 2344);
7831 BUILD_BUG_ON(sizeof(struct ct_fdmi2_hba_attributes) != 4424);
7832 BUILD_BUG_ON(sizeof(struct ct_fdmi2_port_attributes) != 4164);
7833 BUILD_BUG_ON(sizeof(struct ct_fdmi_hba_attr) != 260);
7834 BUILD_BUG_ON(sizeof(struct ct_fdmi_port_attr) != 260);
7835 BUILD_BUG_ON(sizeof(struct ct_rsp_hdr) != 16);
7836 BUILD_BUG_ON(sizeof(struct ctio_crc2_to_fw) != 64);
7837 BUILD_BUG_ON(sizeof(struct device_reg_24xx) != 256);
7838 BUILD_BUG_ON(sizeof(struct device_reg_25xxmq) != 24);
7839 BUILD_BUG_ON(sizeof(struct device_reg_2xxx) != 256);
7840 BUILD_BUG_ON(sizeof(struct device_reg_82xx) != 1288);
7841 BUILD_BUG_ON(sizeof(struct device_reg_fx00) != 216);
7842 BUILD_BUG_ON(sizeof(struct els_entry_24xx) != 64);
7843 BUILD_BUG_ON(sizeof(struct els_sts_entry_24xx) != 64);
7844 BUILD_BUG_ON(sizeof(struct fxdisc_entry_fx00) != 64);
7845 BUILD_BUG_ON(sizeof(struct imm_ntfy_from_isp) != 64);
7846 BUILD_BUG_ON(sizeof(struct init_cb_24xx) != 128);
7847 BUILD_BUG_ON(sizeof(struct init_cb_81xx) != 128);
7848 BUILD_BUG_ON(sizeof(struct logio_entry_24xx) != 64);
7849 BUILD_BUG_ON(sizeof(struct mbx_entry) != 64);
7850 BUILD_BUG_ON(sizeof(struct mid_init_cb_24xx) != 5252);
7851 BUILD_BUG_ON(sizeof(struct mrk_entry_24xx) != 64);
7852 BUILD_BUG_ON(sizeof(struct nvram_24xx) != 512);
7853 BUILD_BUG_ON(sizeof(struct nvram_81xx) != 512);
7854 BUILD_BUG_ON(sizeof(struct pt_ls4_request) != 64);
7855 BUILD_BUG_ON(sizeof(struct pt_ls4_rx_unsol) != 64);
7856 BUILD_BUG_ON(sizeof(struct purex_entry_24xx) != 64);
7857 BUILD_BUG_ON(sizeof(struct qla2100_fw_dump) != 123634);
7858 BUILD_BUG_ON(sizeof(struct qla2300_fw_dump) != 136100);
7859 BUILD_BUG_ON(sizeof(struct qla24xx_fw_dump) != 37976);
7860 BUILD_BUG_ON(sizeof(struct qla25xx_fw_dump) != 39228);
7861 BUILD_BUG_ON(sizeof(struct qla2xxx_fce_chain) != 52);
7862 BUILD_BUG_ON(sizeof(struct qla2xxx_fw_dump) != 136172);
7863 BUILD_BUG_ON(sizeof(struct qla2xxx_mq_chain) != 524);
7864 BUILD_BUG_ON(sizeof(struct qla2xxx_mqueue_chain) != 8);
7865 BUILD_BUG_ON(sizeof(struct qla2xxx_mqueue_header) != 12);
7866 BUILD_BUG_ON(sizeof(struct qla2xxx_offld_chain) != 24);
7867 BUILD_BUG_ON(sizeof(struct qla81xx_fw_dump) != 39420);
7868 BUILD_BUG_ON(sizeof(struct qla82xx_uri_data_desc) != 28);
7869 BUILD_BUG_ON(sizeof(struct qla82xx_uri_table_desc) != 32);
7870 BUILD_BUG_ON(sizeof(struct qla83xx_fw_dump) != 51196);
7871 BUILD_BUG_ON(sizeof(struct qla_fcp_prio_cfg) != FCP_PRIO_CFG_SIZE);
7872 BUILD_BUG_ON(sizeof(struct qla_fdt_layout) != 128);
7873 BUILD_BUG_ON(sizeof(struct qla_flt_header) != 8);
7874 BUILD_BUG_ON(sizeof(struct qla_flt_region) != 16);
7875 BUILD_BUG_ON(sizeof(struct qla_npiv_entry) != 24);
7876 BUILD_BUG_ON(sizeof(struct qla_npiv_header) != 16);
7877 BUILD_BUG_ON(sizeof(struct rdp_rsp_payload) != 336);
7878 BUILD_BUG_ON(sizeof(struct sns_cmd_pkt) != 2064);
7879 BUILD_BUG_ON(sizeof(struct sts_entry_24xx) != 64);
7880 BUILD_BUG_ON(sizeof(struct tsk_mgmt_entry) != 64);
7881 BUILD_BUG_ON(sizeof(struct tsk_mgmt_entry_fx00) != 64);
7882 BUILD_BUG_ON(sizeof(struct verify_chip_entry_84xx) != 64);
7883 BUILD_BUG_ON(sizeof(struct verify_chip_rsp_84xx) != 52);
7884 BUILD_BUG_ON(sizeof(struct vf_evfp_entry_24xx) != 56);
7885 BUILD_BUG_ON(sizeof(struct vp_config_entry_24xx) != 64);
7886 BUILD_BUG_ON(sizeof(struct vp_ctrl_entry_24xx) != 64);
7887 BUILD_BUG_ON(sizeof(struct vp_rpt_id_entry_24xx) != 64);
7888 BUILD_BUG_ON(sizeof(sts21_entry_t) != 64);
7889 BUILD_BUG_ON(sizeof(sts22_entry_t) != 64);
7890 BUILD_BUG_ON(sizeof(sts_cont_entry_t) != 64);
7891 BUILD_BUG_ON(sizeof(sts_entry_t) != 64);
7892 BUILD_BUG_ON(sizeof(sw_info_t) != 32);
7893 BUILD_BUG_ON(sizeof(target_id_t) != 2);
7895 /* Allocate cache for SRBs. */
7896 srb_cachep = kmem_cache_create("qla2xxx_srbs", sizeof(srb_t), 0,
7897 SLAB_HWCACHE_ALIGN, NULL);
7898 if (srb_cachep == NULL) {
7899 ql_log(ql_log_fatal, NULL, 0x0001,
7900 "Unable to allocate SRB cache...Failing load!.\n");
7904 /* Initialize target kmem_cache and mem_pools */
7908 } else if (ret > 0) {
7910 * If initiator mode is explictly disabled by qlt_init(),
7911 * prevent scsi_transport_fc.c:fc_scsi_scan_rport() from
7912 * performing scsi_scan_target() during LOOP UP event.
7914 qla2xxx_transport_functions.disable_target_scan = 1;
7915 qla2xxx_transport_vport_functions.disable_target_scan = 1;
7918 /* Derive version string. */
7919 strcpy(qla2x00_version_str, QLA2XXX_VERSION);
7920 if (ql2xextended_error_logging)
7921 strcat(qla2x00_version_str, "-debug");
7922 if (ql2xextended_error_logging == 1)
7923 ql2xextended_error_logging = QL_DBG_DEFAULT1_MASK;
7925 if (ql2x_ini_mode == QLA2XXX_INI_MODE_DUAL)
7926 qla_insert_tgt_attrs();
7928 qla2xxx_transport_template =
7929 fc_attach_transport(&qla2xxx_transport_functions);
7930 if (!qla2xxx_transport_template) {
7931 ql_log(ql_log_fatal, NULL, 0x0002,
7932 "fc_attach_transport failed...Failing load!.\n");
7937 apidev_major = register_chrdev(0, QLA2XXX_APIDEV, &apidev_fops);
7938 if (apidev_major < 0) {
7939 ql_log(ql_log_fatal, NULL, 0x0003,
7940 "Unable to register char device %s.\n", QLA2XXX_APIDEV);
7943 qla2xxx_transport_vport_template =
7944 fc_attach_transport(&qla2xxx_transport_vport_functions);
7945 if (!qla2xxx_transport_vport_template) {
7946 ql_log(ql_log_fatal, NULL, 0x0004,
7947 "fc_attach_transport vport failed...Failing load!.\n");
7951 ql_log(ql_log_info, NULL, 0x0005,
7952 "QLogic Fibre Channel HBA Driver: %s.\n",
7953 qla2x00_version_str);
7954 ret = pci_register_driver(&qla2xxx_pci_driver);
7956 ql_log(ql_log_fatal, NULL, 0x0006,
7957 "pci_register_driver failed...ret=%d Failing load!.\n",
7959 goto release_vport_transport;
7963 release_vport_transport:
7964 fc_release_transport(qla2xxx_transport_vport_template);
7967 if (apidev_major >= 0)
7968 unregister_chrdev(apidev_major, QLA2XXX_APIDEV);
7969 fc_release_transport(qla2xxx_transport_template);
7975 kmem_cache_destroy(srb_cachep);
7980 * qla2x00_module_exit - Module cleanup.
7983 qla2x00_module_exit(void)
7985 pci_unregister_driver(&qla2xxx_pci_driver);
7986 qla2x00_release_firmware();
7987 kmem_cache_destroy(ctx_cachep);
7988 fc_release_transport(qla2xxx_transport_vport_template);
7989 if (apidev_major >= 0)
7990 unregister_chrdev(apidev_major, QLA2XXX_APIDEV);
7991 fc_release_transport(qla2xxx_transport_template);
7993 kmem_cache_destroy(srb_cachep);
7996 module_init(qla2x00_module_init);
7997 module_exit(qla2x00_module_exit);
7999 MODULE_AUTHOR("QLogic Corporation");
8000 MODULE_DESCRIPTION("QLogic Fibre Channel HBA Driver");
8001 MODULE_LICENSE("GPL");