2 * QLogic Fibre Channel HBA Driver
3 * Copyright (c) 2003-2014 QLogic Corporation
5 * See LICENSE.qla2xxx for copyright and licensing details.
9 #include <linux/moduleparam.h>
10 #include <linux/vmalloc.h>
11 #include <linux/delay.h>
12 #include <linux/kthread.h>
13 #include <linux/mutex.h>
14 #include <linux/kobject.h>
15 #include <linux/slab.h>
16 #include <linux/blk-mq-pci.h>
17 #include <scsi/scsi_tcq.h>
18 #include <scsi/scsicam.h>
19 #include <scsi/scsi_transport.h>
20 #include <scsi/scsi_transport_fc.h>
22 #include "qla_target.h"
27 char qla2x00_version_str
[40];
29 static int apidev_major
;
32 * SRB allocation cache
34 struct kmem_cache
*srb_cachep
;
37 * CT6 CTX allocation cache
39 static struct kmem_cache
*ctx_cachep
;
41 * error level for logging
43 int ql_errlev
= ql_log_all
;
45 static int ql2xenableclass2
;
46 module_param(ql2xenableclass2
, int, S_IRUGO
|S_IRUSR
);
47 MODULE_PARM_DESC(ql2xenableclass2
,
48 "Specify if Class 2 operations are supported from the very "
49 "beginning. Default is 0 - class 2 not supported.");
52 int ql2xlogintimeout
= 20;
53 module_param(ql2xlogintimeout
, int, S_IRUGO
);
54 MODULE_PARM_DESC(ql2xlogintimeout
,
55 "Login timeout value in seconds.");
57 int qlport_down_retry
;
58 module_param(qlport_down_retry
, int, S_IRUGO
);
59 MODULE_PARM_DESC(qlport_down_retry
,
60 "Maximum number of command retries to a port that returns "
61 "a PORT-DOWN status.");
63 int ql2xplogiabsentdevice
;
64 module_param(ql2xplogiabsentdevice
, int, S_IRUGO
|S_IWUSR
);
65 MODULE_PARM_DESC(ql2xplogiabsentdevice
,
66 "Option to enable PLOGI to devices that are not present after "
67 "a Fabric scan. This is needed for several broken switches. "
68 "Default is 0 - no PLOGI. 1 - perfom PLOGI.");
70 int ql2xloginretrycount
= 0;
71 module_param(ql2xloginretrycount
, int, S_IRUGO
);
72 MODULE_PARM_DESC(ql2xloginretrycount
,
73 "Specify an alternate value for the NVRAM login retry count.");
75 int ql2xallocfwdump
= 1;
76 module_param(ql2xallocfwdump
, int, S_IRUGO
);
77 MODULE_PARM_DESC(ql2xallocfwdump
,
78 "Option to enable allocation of memory for a firmware dump "
79 "during HBA initialization. Memory allocation requirements "
80 "vary by ISP type. Default is 1 - allocate memory.");
82 int ql2xextended_error_logging
;
83 module_param(ql2xextended_error_logging
, int, S_IRUGO
|S_IWUSR
);
84 module_param_named(logging
, ql2xextended_error_logging
, int, S_IRUGO
|S_IWUSR
);
85 MODULE_PARM_DESC(ql2xextended_error_logging
,
86 "Option to enable extended error logging,\n"
87 "\t\tDefault is 0 - no logging. 0x40000000 - Module Init & Probe.\n"
88 "\t\t0x20000000 - Mailbox Cmnds. 0x10000000 - Device Discovery.\n"
89 "\t\t0x08000000 - IO tracing. 0x04000000 - DPC Thread.\n"
90 "\t\t0x02000000 - Async events. 0x01000000 - Timer routines.\n"
91 "\t\t0x00800000 - User space. 0x00400000 - Task Management.\n"
92 "\t\t0x00200000 - AER/EEH. 0x00100000 - Multi Q.\n"
93 "\t\t0x00080000 - P3P Specific. 0x00040000 - Virtual Port.\n"
94 "\t\t0x00020000 - Buffer Dump. 0x00010000 - Misc.\n"
95 "\t\t0x00008000 - Verbose. 0x00004000 - Target.\n"
96 "\t\t0x00002000 - Target Mgmt. 0x00001000 - Target TMF.\n"
97 "\t\t0x7fffffff - For enabling all logs, can be too many logs.\n"
98 "\t\t0x1e400000 - Preferred value for capturing essential "
99 "debug information (equivalent to old "
100 "ql2xextended_error_logging=1).\n"
101 "\t\tDo LOGICAL OR of the value to enable more than one level");
103 int ql2xshiftctondsd
= 6;
104 module_param(ql2xshiftctondsd
, int, S_IRUGO
);
105 MODULE_PARM_DESC(ql2xshiftctondsd
,
106 "Set to control shifting of command type processing "
107 "based on total number of SG elements.");
109 int ql2xfdmienable
=1;
110 module_param(ql2xfdmienable
, int, S_IRUGO
|S_IWUSR
);
111 module_param_named(fdmi
, ql2xfdmienable
, int, S_IRUGO
|S_IWUSR
);
112 MODULE_PARM_DESC(ql2xfdmienable
,
113 "Enables FDMI registrations. "
114 "0 - no FDMI. Default is 1 - perform FDMI.");
116 #define MAX_Q_DEPTH 32
117 static int ql2xmaxqdepth
= MAX_Q_DEPTH
;
118 module_param(ql2xmaxqdepth
, int, S_IRUGO
|S_IWUSR
);
119 MODULE_PARM_DESC(ql2xmaxqdepth
,
120 "Maximum queue depth to set for each LUN. "
123 #if (IS_ENABLED(CONFIG_NVME_FC))
126 int ql2xenabledif
= 2;
128 module_param(ql2xenabledif
, int, S_IRUGO
);
129 MODULE_PARM_DESC(ql2xenabledif
,
130 " Enable T10-CRC-DIF:\n"
132 " 0 -- No DIF Support\n"
133 " 1 -- Enable DIF for all types\n"
134 " 2 -- Enable DIF for all types, except Type 0.\n");
136 #if (IS_ENABLED(CONFIG_NVME_FC))
137 int ql2xnvmeenable
= 1;
141 module_param(ql2xnvmeenable
, int, 0644);
142 MODULE_PARM_DESC(ql2xnvmeenable
,
143 "Enables NVME support. "
144 "0 - no NVMe. Default is Y");
146 int ql2xenablehba_err_chk
= 2;
147 module_param(ql2xenablehba_err_chk
, int, S_IRUGO
|S_IWUSR
);
148 MODULE_PARM_DESC(ql2xenablehba_err_chk
,
149 " Enable T10-CRC-DIF Error isolation by HBA:\n"
151 " 0 -- Error isolation disabled\n"
152 " 1 -- Error isolation enabled only for DIX Type 0\n"
153 " 2 -- Error isolation enabled for all Types\n");
155 int ql2xiidmaenable
=1;
156 module_param(ql2xiidmaenable
, int, S_IRUGO
);
157 MODULE_PARM_DESC(ql2xiidmaenable
,
158 "Enables iIDMA settings "
159 "Default is 1 - perform iIDMA. 0 - no iIDMA.");
161 int ql2xmqsupport
= 1;
162 module_param(ql2xmqsupport
, int, S_IRUGO
);
163 MODULE_PARM_DESC(ql2xmqsupport
,
164 "Enable on demand multiple queue pairs support "
165 "Default is 1 for supported. "
166 "Set it to 0 to turn off mq qpair support.");
169 module_param(ql2xfwloadbin
, int, S_IRUGO
|S_IWUSR
);
170 module_param_named(fwload
, ql2xfwloadbin
, int, S_IRUGO
|S_IWUSR
);
171 MODULE_PARM_DESC(ql2xfwloadbin
,
172 "Option to specify location from which to load ISP firmware:.\n"
173 " 2 -- load firmware via the request_firmware() (hotplug).\n"
175 " 1 -- load firmware from flash.\n"
176 " 0 -- use default semantics.\n");
179 module_param(ql2xetsenable
, int, S_IRUGO
);
180 MODULE_PARM_DESC(ql2xetsenable
,
181 "Enables firmware ETS burst."
182 "Default is 0 - skip ETS enablement.");
185 module_param(ql2xdbwr
, int, S_IRUGO
|S_IWUSR
);
186 MODULE_PARM_DESC(ql2xdbwr
,
187 "Option to specify scheme for request queue posting.\n"
188 " 0 -- Regular doorbell.\n"
189 " 1 -- CAMRAM doorbell (faster).\n");
191 int ql2xtargetreset
= 1;
192 module_param(ql2xtargetreset
, int, S_IRUGO
);
193 MODULE_PARM_DESC(ql2xtargetreset
,
194 "Enable target reset."
195 "Default is 1 - use hw defaults.");
198 module_param(ql2xgffidenable
, int, S_IRUGO
);
199 MODULE_PARM_DESC(ql2xgffidenable
,
200 "Enables GFF_ID checks of port type. "
201 "Default is 0 - Do not use GFF_ID information.");
203 int ql2xasynctmfenable
;
204 module_param(ql2xasynctmfenable
, int, S_IRUGO
);
205 MODULE_PARM_DESC(ql2xasynctmfenable
,
206 "Enables issue of TM IOCBs asynchronously via IOCB mechanism"
207 "Default is 0 - Issue TM IOCBs via mailbox mechanism.");
209 int ql2xdontresethba
;
210 module_param(ql2xdontresethba
, int, S_IRUGO
|S_IWUSR
);
211 MODULE_PARM_DESC(ql2xdontresethba
,
212 "Option to specify reset behaviour.\n"
213 " 0 (Default) -- Reset on failure.\n"
214 " 1 -- Do not reset on failure.\n");
216 uint64_t ql2xmaxlun
= MAX_LUNS
;
217 module_param(ql2xmaxlun
, ullong
, S_IRUGO
);
218 MODULE_PARM_DESC(ql2xmaxlun
,
219 "Defines the maximum LU number to register with the SCSI "
220 "midlayer. Default is 65535.");
222 int ql2xmdcapmask
= 0x1F;
223 module_param(ql2xmdcapmask
, int, S_IRUGO
);
224 MODULE_PARM_DESC(ql2xmdcapmask
,
225 "Set the Minidump driver capture mask level. "
226 "Default is 0x1F - Can be set to 0x3, 0x7, 0xF, 0x1F, 0x7F.");
228 int ql2xmdenable
= 1;
229 module_param(ql2xmdenable
, int, S_IRUGO
);
230 MODULE_PARM_DESC(ql2xmdenable
,
231 "Enable/disable MiniDump. "
232 "0 - MiniDump disabled. "
233 "1 (Default) - MiniDump enabled.");
235 int ql2xexlogins
= 0;
236 module_param(ql2xexlogins
, uint
, S_IRUGO
|S_IWUSR
);
237 MODULE_PARM_DESC(ql2xexlogins
,
238 "Number of extended Logins. "
239 "0 (Default)- Disabled.");
241 int ql2xexchoffld
= 1024;
242 module_param(ql2xexchoffld
, uint
, 0644);
243 MODULE_PARM_DESC(ql2xexchoffld
,
244 "Number of target exchanges.");
246 int ql2xiniexchg
= 1024;
247 module_param(ql2xiniexchg
, uint
, 0644);
248 MODULE_PARM_DESC(ql2xiniexchg
,
249 "Number of initiator exchanges.");
251 int ql2xfwholdabts
= 0;
252 module_param(ql2xfwholdabts
, int, S_IRUGO
);
253 MODULE_PARM_DESC(ql2xfwholdabts
,
254 "Allow FW to hold status IOCB until ABTS rsp received. "
255 "0 (Default) Do not set fw option. "
256 "1 - Set fw option to hold ABTS.");
258 int ql2xmvasynctoatio
= 1;
259 module_param(ql2xmvasynctoatio
, int, S_IRUGO
|S_IWUSR
);
260 MODULE_PARM_DESC(ql2xmvasynctoatio
,
261 "Move PUREX, ABTS RX and RIDA IOCBs to ATIOQ"
262 "0 (Default). Do not move IOCBs"
266 * SCSI host template entry points
268 static int qla2xxx_slave_configure(struct scsi_device
* device
);
269 static int qla2xxx_slave_alloc(struct scsi_device
*);
270 static int qla2xxx_scan_finished(struct Scsi_Host
*, unsigned long time
);
271 static void qla2xxx_scan_start(struct Scsi_Host
*);
272 static void qla2xxx_slave_destroy(struct scsi_device
*);
273 static int qla2xxx_queuecommand(struct Scsi_Host
*h
, struct scsi_cmnd
*cmd
);
274 static int qla2xxx_eh_abort(struct scsi_cmnd
*);
275 static int qla2xxx_eh_device_reset(struct scsi_cmnd
*);
276 static int qla2xxx_eh_target_reset(struct scsi_cmnd
*);
277 static int qla2xxx_eh_bus_reset(struct scsi_cmnd
*);
278 static int qla2xxx_eh_host_reset(struct scsi_cmnd
*);
280 static void qla2x00_clear_drv_active(struct qla_hw_data
*);
281 static void qla2x00_free_device(scsi_qla_host_t
*);
282 static void qla83xx_disable_laser(scsi_qla_host_t
*vha
);
283 static int qla2xxx_map_queues(struct Scsi_Host
*shost
);
284 static void qla2x00_destroy_deferred_work(struct qla_hw_data
*);
286 struct scsi_host_template qla2xxx_driver_template
= {
287 .module
= THIS_MODULE
,
288 .name
= QLA2XXX_DRIVER_NAME
,
289 .queuecommand
= qla2xxx_queuecommand
,
291 .eh_timed_out
= fc_eh_timed_out
,
292 .eh_abort_handler
= qla2xxx_eh_abort
,
293 .eh_device_reset_handler
= qla2xxx_eh_device_reset
,
294 .eh_target_reset_handler
= qla2xxx_eh_target_reset
,
295 .eh_bus_reset_handler
= qla2xxx_eh_bus_reset
,
296 .eh_host_reset_handler
= qla2xxx_eh_host_reset
,
298 .slave_configure
= qla2xxx_slave_configure
,
300 .slave_alloc
= qla2xxx_slave_alloc
,
301 .slave_destroy
= qla2xxx_slave_destroy
,
302 .scan_finished
= qla2xxx_scan_finished
,
303 .scan_start
= qla2xxx_scan_start
,
304 .change_queue_depth
= scsi_change_queue_depth
,
305 .map_queues
= qla2xxx_map_queues
,
308 .use_clustering
= ENABLE_CLUSTERING
,
309 .sg_tablesize
= SG_ALL
,
311 .max_sectors
= 0xFFFF,
312 .shost_attrs
= qla2x00_host_attrs
,
314 .supported_mode
= MODE_INITIATOR
,
315 .track_queue_depth
= 1,
318 static struct scsi_transport_template
*qla2xxx_transport_template
= NULL
;
319 struct scsi_transport_template
*qla2xxx_transport_vport_template
= NULL
;
321 /* TODO Convert to inlines
327 qla2x00_start_timer(scsi_qla_host_t
*vha
, void *func
, unsigned long interval
)
329 init_timer(&vha
->timer
);
330 vha
->timer
.expires
= jiffies
+ interval
* HZ
;
331 vha
->timer
.data
= (unsigned long)vha
;
332 vha
->timer
.function
= (void (*)(unsigned long))func
;
333 add_timer(&vha
->timer
);
334 vha
->timer_active
= 1;
338 qla2x00_restart_timer(scsi_qla_host_t
*vha
, unsigned long interval
)
340 /* Currently used for 82XX only. */
341 if (vha
->device_flags
& DFLG_DEV_FAILED
) {
342 ql_dbg(ql_dbg_timer
, vha
, 0x600d,
343 "Device in a failed state, returning.\n");
347 mod_timer(&vha
->timer
, jiffies
+ interval
* HZ
);
350 static __inline__
void
351 qla2x00_stop_timer(scsi_qla_host_t
*vha
)
353 del_timer_sync(&vha
->timer
);
354 vha
->timer_active
= 0;
357 static int qla2x00_do_dpc(void *data
);
359 static void qla2x00_rst_aen(scsi_qla_host_t
*);
361 static int qla2x00_mem_alloc(struct qla_hw_data
*, uint16_t, uint16_t,
362 struct req_que
**, struct rsp_que
**);
363 static void qla2x00_free_fw_dump(struct qla_hw_data
*);
364 static void qla2x00_mem_free(struct qla_hw_data
*);
365 int qla2xxx_mqueuecommand(struct Scsi_Host
*host
, struct scsi_cmnd
*cmd
,
366 struct qla_qpair
*qpair
);
368 /* -------------------------------------------------------------------------- */
369 static void qla_init_base_qpair(struct scsi_qla_host
*vha
, struct req_que
*req
,
372 struct qla_hw_data
*ha
= vha
->hw
;
373 rsp
->qpair
= ha
->base_qpair
;
375 ha
->base_qpair
->req
= req
;
376 ha
->base_qpair
->rsp
= rsp
;
377 ha
->base_qpair
->vha
= vha
;
378 ha
->base_qpair
->qp_lock_ptr
= &ha
->hardware_lock
;
379 ha
->base_qpair
->use_shadow_reg
= IS_SHADOW_REG_CAPABLE(ha
) ? 1 : 0;
380 ha
->base_qpair
->msix
= &ha
->msix_entries
[QLA_MSIX_RSP_Q
];
381 INIT_LIST_HEAD(&ha
->base_qpair
->hints_list
);
382 ha
->base_qpair
->enable_class_2
= ql2xenableclass2
;
383 /* init qpair to this cpu. Will adjust at run time. */
384 qla_cpu_update(rsp
->qpair
, smp_processor_id());
385 ha
->base_qpair
->pdev
= ha
->pdev
;
387 if (IS_QLA27XX(ha
) || IS_QLA83XX(ha
))
388 ha
->base_qpair
->reqq_start_iocbs
= qla_83xx_start_iocbs
;
391 static int qla2x00_alloc_queues(struct qla_hw_data
*ha
, struct req_que
*req
,
394 scsi_qla_host_t
*vha
= pci_get_drvdata(ha
->pdev
);
395 ha
->req_q_map
= kzalloc(sizeof(struct req_que
*) * ha
->max_req_queues
,
397 if (!ha
->req_q_map
) {
398 ql_log(ql_log_fatal
, vha
, 0x003b,
399 "Unable to allocate memory for request queue ptrs.\n");
403 ha
->rsp_q_map
= kzalloc(sizeof(struct rsp_que
*) * ha
->max_rsp_queues
,
405 if (!ha
->rsp_q_map
) {
406 ql_log(ql_log_fatal
, vha
, 0x003c,
407 "Unable to allocate memory for response queue ptrs.\n");
411 ha
->base_qpair
= kzalloc(sizeof(struct qla_qpair
), GFP_KERNEL
);
412 if (ha
->base_qpair
== NULL
) {
413 ql_log(ql_log_warn
, vha
, 0x00e0,
414 "Failed to allocate base queue pair memory.\n");
415 goto fail_base_qpair
;
418 qla_init_base_qpair(vha
, req
, rsp
);
420 if (ql2xmqsupport
&& ha
->max_qpairs
) {
421 ha
->queue_pair_map
= kcalloc(ha
->max_qpairs
, sizeof(struct qla_qpair
*),
423 if (!ha
->queue_pair_map
) {
424 ql_log(ql_log_fatal
, vha
, 0x0180,
425 "Unable to allocate memory for queue pair ptrs.\n");
431 * Make sure we record at least the request and response queue zero in
432 * case we need to free them if part of the probe fails.
434 ha
->rsp_q_map
[0] = rsp
;
435 ha
->req_q_map
[0] = req
;
436 set_bit(0, ha
->rsp_qid_map
);
437 set_bit(0, ha
->req_qid_map
);
441 kfree(ha
->base_qpair
);
442 ha
->base_qpair
= NULL
;
444 kfree(ha
->rsp_q_map
);
445 ha
->rsp_q_map
= NULL
;
447 kfree(ha
->req_q_map
);
448 ha
->req_q_map
= NULL
;
453 static void qla2x00_free_req_que(struct qla_hw_data
*ha
, struct req_que
*req
)
455 if (IS_QLAFX00(ha
)) {
456 if (req
&& req
->ring_fx00
)
457 dma_free_coherent(&ha
->pdev
->dev
,
458 (req
->length_fx00
+ 1) * sizeof(request_t
),
459 req
->ring_fx00
, req
->dma_fx00
);
460 } else if (req
&& req
->ring
)
461 dma_free_coherent(&ha
->pdev
->dev
,
462 (req
->length
+ 1) * sizeof(request_t
),
463 req
->ring
, req
->dma
);
466 kfree(req
->outstanding_cmds
);
471 static void qla2x00_free_rsp_que(struct qla_hw_data
*ha
, struct rsp_que
*rsp
)
473 if (IS_QLAFX00(ha
)) {
474 if (rsp
&& rsp
->ring
)
475 dma_free_coherent(&ha
->pdev
->dev
,
476 (rsp
->length_fx00
+ 1) * sizeof(request_t
),
477 rsp
->ring_fx00
, rsp
->dma_fx00
);
478 } else if (rsp
&& rsp
->ring
) {
479 dma_free_coherent(&ha
->pdev
->dev
,
480 (rsp
->length
+ 1) * sizeof(response_t
),
481 rsp
->ring
, rsp
->dma
);
486 static void qla2x00_free_queues(struct qla_hw_data
*ha
)
493 if (ha
->queue_pair_map
) {
494 kfree(ha
->queue_pair_map
);
495 ha
->queue_pair_map
= NULL
;
497 if (ha
->base_qpair
) {
498 kfree(ha
->base_qpair
);
499 ha
->base_qpair
= NULL
;
502 spin_lock_irqsave(&ha
->hardware_lock
, flags
);
503 for (cnt
= 0; cnt
< ha
->max_req_queues
; cnt
++) {
504 if (!test_bit(cnt
, ha
->req_qid_map
))
507 req
= ha
->req_q_map
[cnt
];
508 clear_bit(cnt
, ha
->req_qid_map
);
509 ha
->req_q_map
[cnt
] = NULL
;
511 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
512 qla2x00_free_req_que(ha
, req
);
513 spin_lock_irqsave(&ha
->hardware_lock
, flags
);
515 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
517 kfree(ha
->req_q_map
);
518 ha
->req_q_map
= NULL
;
521 spin_lock_irqsave(&ha
->hardware_lock
, flags
);
522 for (cnt
= 0; cnt
< ha
->max_rsp_queues
; cnt
++) {
523 if (!test_bit(cnt
, ha
->rsp_qid_map
))
526 rsp
= ha
->rsp_q_map
[cnt
];
527 clear_bit(cnt
, ha
->rsp_qid_map
);
528 ha
->rsp_q_map
[cnt
] = NULL
;
529 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
530 qla2x00_free_rsp_que(ha
, rsp
);
531 spin_lock_irqsave(&ha
->hardware_lock
, flags
);
533 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
535 kfree(ha
->rsp_q_map
);
536 ha
->rsp_q_map
= NULL
;
540 qla2x00_pci_info_str(struct scsi_qla_host
*vha
, char *str
)
542 struct qla_hw_data
*ha
= vha
->hw
;
543 static char *pci_bus_modes
[] = {
544 "33", "66", "100", "133",
549 pci_bus
= (ha
->pci_attr
& (BIT_9
| BIT_10
)) >> 9;
552 strcat(str
, pci_bus_modes
[pci_bus
]);
554 pci_bus
= (ha
->pci_attr
& BIT_8
) >> 8;
556 strcat(str
, pci_bus_modes
[pci_bus
]);
558 strcat(str
, " MHz)");
564 qla24xx_pci_info_str(struct scsi_qla_host
*vha
, char *str
)
566 static char *pci_bus_modes
[] = { "33", "66", "100", "133", };
567 struct qla_hw_data
*ha
= vha
->hw
;
570 if (pci_is_pcie(ha
->pdev
)) {
572 uint32_t lstat
, lspeed
, lwidth
;
574 pcie_capability_read_dword(ha
->pdev
, PCI_EXP_LNKCAP
, &lstat
);
575 lspeed
= lstat
& PCI_EXP_LNKCAP_SLS
;
576 lwidth
= (lstat
& PCI_EXP_LNKCAP_MLW
) >> 4;
578 strcpy(str
, "PCIe (");
581 strcat(str
, "2.5GT/s ");
584 strcat(str
, "5.0GT/s ");
587 strcat(str
, "8.0GT/s ");
590 strcat(str
, "<unknown> ");
593 snprintf(lwstr
, sizeof(lwstr
), "x%d)", lwidth
);
600 pci_bus
= (ha
->pci_attr
& CSRX_PCIX_BUS_MODE_MASK
) >> 8;
601 if (pci_bus
== 0 || pci_bus
== 8) {
603 strcat(str
, pci_bus_modes
[pci_bus
>> 3]);
607 strcat(str
, "Mode 2");
609 strcat(str
, "Mode 1");
611 strcat(str
, pci_bus_modes
[pci_bus
& ~BIT_2
]);
613 strcat(str
, " MHz)");
619 qla2x00_fw_version_str(struct scsi_qla_host
*vha
, char *str
, size_t size
)
622 struct qla_hw_data
*ha
= vha
->hw
;
624 snprintf(str
, size
, "%d.%02d.%02d ", ha
->fw_major_version
,
625 ha
->fw_minor_version
, ha
->fw_subminor_version
);
627 if (ha
->fw_attributes
& BIT_9
) {
632 switch (ha
->fw_attributes
& 0xFF) {
646 sprintf(un_str
, "(%x)", ha
->fw_attributes
);
650 if (ha
->fw_attributes
& 0x100)
657 qla24xx_fw_version_str(struct scsi_qla_host
*vha
, char *str
, size_t size
)
659 struct qla_hw_data
*ha
= vha
->hw
;
661 snprintf(str
, size
, "%d.%02d.%02d (%x)", ha
->fw_major_version
,
662 ha
->fw_minor_version
, ha
->fw_subminor_version
, ha
->fw_attributes
);
667 qla2x00_sp_free_dma(void *ptr
)
670 struct qla_hw_data
*ha
= sp
->vha
->hw
;
671 struct scsi_cmnd
*cmd
= GET_CMD_SP(sp
);
672 void *ctx
= GET_CMD_CTX_SP(sp
);
674 if (sp
->flags
& SRB_DMA_VALID
) {
676 sp
->flags
&= ~SRB_DMA_VALID
;
679 if (sp
->flags
& SRB_CRC_PROT_DMA_VALID
) {
680 dma_unmap_sg(&ha
->pdev
->dev
, scsi_prot_sglist(cmd
),
681 scsi_prot_sg_count(cmd
), cmd
->sc_data_direction
);
682 sp
->flags
&= ~SRB_CRC_PROT_DMA_VALID
;
688 if (sp
->flags
& SRB_CRC_CTX_DSD_VALID
) {
689 /* List assured to be having elements */
690 qla2x00_clean_dsd_pool(ha
, ctx
);
691 sp
->flags
&= ~SRB_CRC_CTX_DSD_VALID
;
694 if (sp
->flags
& SRB_CRC_CTX_DMA_VALID
) {
695 struct crc_context
*ctx0
= ctx
;
697 dma_pool_free(ha
->dl_dma_pool
, ctx0
, ctx0
->crc_ctx_dma
);
698 sp
->flags
&= ~SRB_CRC_CTX_DMA_VALID
;
701 if (sp
->flags
& SRB_FCP_CMND_DMA_VALID
) {
702 struct ct6_dsd
*ctx1
= ctx
;
704 dma_pool_free(ha
->fcp_cmnd_dma_pool
, ctx1
->fcp_cmnd
,
706 list_splice(&ctx1
->dsd_list
, &ha
->gbl_dsd_list
);
707 ha
->gbl_dsd_inuse
-= ctx1
->dsd_use_cnt
;
708 ha
->gbl_dsd_avail
+= ctx1
->dsd_use_cnt
;
709 mempool_free(ctx1
, ha
->ctx_mempool
);
713 if ((sp
->type
!= SRB_NVME_CMD
) && (sp
->type
!= SRB_NVME_LS
)) {
720 qla2x00_sp_compl(void *ptr
, int res
)
723 struct scsi_cmnd
*cmd
= GET_CMD_SP(sp
);
727 if (atomic_read(&sp
->ref_count
) == 0) {
728 ql_dbg(ql_dbg_io
, sp
->vha
, 0x3015,
729 "SP reference-count to ZERO -- sp=%p cmd=%p.\n",
731 if (ql2xextended_error_logging
& ql_dbg_io
)
732 WARN_ON(atomic_read(&sp
->ref_count
) == 0);
735 if (!atomic_dec_and_test(&sp
->ref_count
))
738 qla2x00_sp_free_dma(sp
);
743 qla2xxx_qpair_sp_free_dma(void *ptr
)
745 srb_t
*sp
= (srb_t
*)ptr
;
746 struct scsi_cmnd
*cmd
= GET_CMD_SP(sp
);
747 struct qla_hw_data
*ha
= sp
->fcport
->vha
->hw
;
748 void *ctx
= GET_CMD_CTX_SP(sp
);
750 if (sp
->flags
& SRB_DMA_VALID
) {
752 sp
->flags
&= ~SRB_DMA_VALID
;
755 if (sp
->flags
& SRB_CRC_PROT_DMA_VALID
) {
756 dma_unmap_sg(&ha
->pdev
->dev
, scsi_prot_sglist(cmd
),
757 scsi_prot_sg_count(cmd
), cmd
->sc_data_direction
);
758 sp
->flags
&= ~SRB_CRC_PROT_DMA_VALID
;
764 if (sp
->flags
& SRB_CRC_CTX_DSD_VALID
) {
765 /* List assured to be having elements */
766 qla2x00_clean_dsd_pool(ha
, ctx
);
767 sp
->flags
&= ~SRB_CRC_CTX_DSD_VALID
;
770 if (sp
->flags
& SRB_CRC_CTX_DMA_VALID
) {
771 struct crc_context
*ctx0
= ctx
;
773 dma_pool_free(ha
->dl_dma_pool
, ctx
, ctx0
->crc_ctx_dma
);
774 sp
->flags
&= ~SRB_CRC_CTX_DMA_VALID
;
777 if (sp
->flags
& SRB_FCP_CMND_DMA_VALID
) {
778 struct ct6_dsd
*ctx1
= ctx
;
779 dma_pool_free(ha
->fcp_cmnd_dma_pool
, ctx1
->fcp_cmnd
,
781 list_splice(&ctx1
->dsd_list
, &ha
->gbl_dsd_list
);
782 ha
->gbl_dsd_inuse
-= ctx1
->dsd_use_cnt
;
783 ha
->gbl_dsd_avail
+= ctx1
->dsd_use_cnt
;
784 mempool_free(ctx1
, ha
->ctx_mempool
);
788 qla2xxx_rel_qpair_sp(sp
->qpair
, sp
);
792 qla2xxx_qpair_sp_compl(void *ptr
, int res
)
795 struct scsi_cmnd
*cmd
= GET_CMD_SP(sp
);
799 if (atomic_read(&sp
->ref_count
) == 0) {
800 ql_dbg(ql_dbg_io
, sp
->fcport
->vha
, 0x3079,
801 "SP reference-count to ZERO -- sp=%p cmd=%p.\n",
803 if (ql2xextended_error_logging
& ql_dbg_io
)
804 WARN_ON(atomic_read(&sp
->ref_count
) == 0);
807 if (!atomic_dec_and_test(&sp
->ref_count
))
810 qla2xxx_qpair_sp_free_dma(sp
);
814 /* If we are SP1 here, we need to still take and release the host_lock as SP1
815 * does not have the changes necessary to avoid taking host->host_lock.
818 qla2xxx_queuecommand(struct Scsi_Host
*host
, struct scsi_cmnd
*cmd
)
820 scsi_qla_host_t
*vha
= shost_priv(host
);
821 fc_port_t
*fcport
= (struct fc_port
*) cmd
->device
->hostdata
;
822 struct fc_rport
*rport
= starget_to_rport(scsi_target(cmd
->device
));
823 struct qla_hw_data
*ha
= vha
->hw
;
824 struct scsi_qla_host
*base_vha
= pci_get_drvdata(ha
->pdev
);
827 struct qla_qpair
*qpair
= NULL
;
831 if (unlikely(test_bit(UNLOADING
, &base_vha
->dpc_flags
))) {
832 cmd
->result
= DID_NO_CONNECT
<< 16;
833 goto qc24_fail_command
;
837 if (shost_use_blk_mq(vha
->host
)) {
838 tag
= blk_mq_unique_tag(cmd
->request
);
839 hwq
= blk_mq_unique_tag_to_hwq(tag
);
840 qpair
= ha
->queue_pair_map
[hwq
];
841 } else if (vha
->vp_idx
&& vha
->qpair
) {
846 return qla2xxx_mqueuecommand(host
, cmd
, qpair
);
849 if (ha
->flags
.eeh_busy
) {
850 if (ha
->flags
.pci_channel_io_perm_failure
) {
851 ql_dbg(ql_dbg_aer
, vha
, 0x9010,
852 "PCI Channel IO permanent failure, exiting "
854 cmd
->result
= DID_NO_CONNECT
<< 16;
856 ql_dbg(ql_dbg_aer
, vha
, 0x9011,
857 "EEH_Busy, Requeuing the cmd=%p.\n", cmd
);
858 cmd
->result
= DID_REQUEUE
<< 16;
860 goto qc24_fail_command
;
863 rval
= fc_remote_port_chkready(rport
);
866 ql_dbg(ql_dbg_io
+ ql_dbg_verbose
, vha
, 0x3003,
867 "fc_remote_port_chkready failed for cmd=%p, rval=0x%x.\n",
869 goto qc24_fail_command
;
872 if (!vha
->flags
.difdix_supported
&&
873 scsi_get_prot_op(cmd
) != SCSI_PROT_NORMAL
) {
874 ql_dbg(ql_dbg_io
, vha
, 0x3004,
875 "DIF Cap not reg, fail DIF capable cmd's:%p.\n",
877 cmd
->result
= DID_NO_CONNECT
<< 16;
878 goto qc24_fail_command
;
882 cmd
->result
= DID_NO_CONNECT
<< 16;
883 goto qc24_fail_command
;
886 if (atomic_read(&fcport
->state
) != FCS_ONLINE
) {
887 if (atomic_read(&fcport
->state
) == FCS_DEVICE_DEAD
||
888 atomic_read(&base_vha
->loop_state
) == LOOP_DEAD
) {
889 ql_dbg(ql_dbg_io
, vha
, 0x3005,
890 "Returning DNC, fcport_state=%d loop_state=%d.\n",
891 atomic_read(&fcport
->state
),
892 atomic_read(&base_vha
->loop_state
));
893 cmd
->result
= DID_NO_CONNECT
<< 16;
894 goto qc24_fail_command
;
896 goto qc24_target_busy
;
900 * Return target busy if we've received a non-zero retry_delay_timer
903 if (fcport
->retry_delay_timestamp
== 0) {
904 /* retry delay not set */
905 } else if (time_after(jiffies
, fcport
->retry_delay_timestamp
))
906 fcport
->retry_delay_timestamp
= 0;
908 goto qc24_target_busy
;
910 sp
= qla2x00_get_sp(vha
, fcport
, GFP_ATOMIC
);
914 sp
->u
.scmd
.cmd
= cmd
;
915 sp
->type
= SRB_SCSI_CMD
;
916 atomic_set(&sp
->ref_count
, 1);
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
:
931 qla2x00_sp_free_dma(sp
);
934 return SCSI_MLQUEUE_HOST_BUSY
;
937 return SCSI_MLQUEUE_TARGET_BUSY
;
945 /* For MQ supported I/O */
947 qla2xxx_mqueuecommand(struct Scsi_Host
*host
, struct scsi_cmnd
*cmd
,
948 struct qla_qpair
*qpair
)
950 scsi_qla_host_t
*vha
= shost_priv(host
);
951 fc_port_t
*fcport
= (struct fc_port
*) cmd
->device
->hostdata
;
952 struct fc_rport
*rport
= starget_to_rport(scsi_target(cmd
->device
));
953 struct qla_hw_data
*ha
= vha
->hw
;
954 struct scsi_qla_host
*base_vha
= pci_get_drvdata(ha
->pdev
);
958 rval
= fc_remote_port_chkready(rport
);
961 ql_dbg(ql_dbg_io
+ ql_dbg_verbose
, vha
, 0x3076,
962 "fc_remote_port_chkready failed for cmd=%p, rval=0x%x.\n",
964 goto qc24_fail_command
;
968 cmd
->result
= DID_NO_CONNECT
<< 16;
969 goto qc24_fail_command
;
972 if (atomic_read(&fcport
->state
) != FCS_ONLINE
) {
973 if (atomic_read(&fcport
->state
) == FCS_DEVICE_DEAD
||
974 atomic_read(&base_vha
->loop_state
) == LOOP_DEAD
) {
975 ql_dbg(ql_dbg_io
, vha
, 0x3077,
976 "Returning DNC, fcport_state=%d loop_state=%d.\n",
977 atomic_read(&fcport
->state
),
978 atomic_read(&base_vha
->loop_state
));
979 cmd
->result
= DID_NO_CONNECT
<< 16;
980 goto qc24_fail_command
;
982 goto qc24_target_busy
;
986 * Return target busy if we've received a non-zero retry_delay_timer
989 if (fcport
->retry_delay_timestamp
== 0) {
990 /* retry delay not set */
991 } else if (time_after(jiffies
, fcport
->retry_delay_timestamp
))
992 fcport
->retry_delay_timestamp
= 0;
994 goto qc24_target_busy
;
996 sp
= qla2xxx_get_qpair_sp(qpair
, fcport
, GFP_ATOMIC
);
1000 sp
->u
.scmd
.cmd
= cmd
;
1001 sp
->type
= SRB_SCSI_CMD
;
1002 atomic_set(&sp
->ref_count
, 1);
1003 CMD_SP(cmd
) = (void *)sp
;
1004 sp
->free
= qla2xxx_qpair_sp_free_dma
;
1005 sp
->done
= qla2xxx_qpair_sp_compl
;
1008 rval
= ha
->isp_ops
->start_scsi_mq(sp
);
1009 if (rval
!= QLA_SUCCESS
) {
1010 ql_dbg(ql_dbg_io
+ ql_dbg_verbose
, vha
, 0x3078,
1011 "Start scsi failed rval=%d for cmd=%p.\n", rval
, cmd
);
1012 if (rval
== QLA_INTERFACE_ERROR
)
1013 goto qc24_fail_command
;
1014 goto qc24_host_busy_free_sp
;
1019 qc24_host_busy_free_sp
:
1020 qla2xxx_qpair_sp_free_dma(sp
);
1023 return SCSI_MLQUEUE_HOST_BUSY
;
1026 return SCSI_MLQUEUE_TARGET_BUSY
;
1029 cmd
->scsi_done(cmd
);
1035 * qla2x00_eh_wait_on_command
1036 * Waits for the command to be returned by the Firmware for some
1040 * cmd = Scsi Command to wait on.
1047 qla2x00_eh_wait_on_command(struct scsi_cmnd
*cmd
)
1049 #define ABORT_POLLING_PERIOD 1000
1050 #define ABORT_WAIT_ITER ((2 * 1000) / (ABORT_POLLING_PERIOD))
1051 unsigned long wait_iter
= ABORT_WAIT_ITER
;
1052 scsi_qla_host_t
*vha
= shost_priv(cmd
->device
->host
);
1053 struct qla_hw_data
*ha
= vha
->hw
;
1054 int ret
= QLA_SUCCESS
;
1056 if (unlikely(pci_channel_offline(ha
->pdev
)) || ha
->flags
.eeh_busy
) {
1057 ql_dbg(ql_dbg_taskm
, vha
, 0x8005,
1058 "Return:eh_wait.\n");
1062 while (CMD_SP(cmd
) && wait_iter
--) {
1063 msleep(ABORT_POLLING_PERIOD
);
1066 ret
= QLA_FUNCTION_FAILED
;
1072 * qla2x00_wait_for_hba_online
1073 * Wait till the HBA is online after going through
1074 * <= MAX_RETRIES_OF_ISP_ABORT or
1075 * finally HBA is disabled ie marked offline
1078 * ha - pointer to host adapter structure
1081 * Does context switching-Release SPIN_LOCK
1082 * (if any) before calling this routine.
1085 * Success (Adapter is online) : 0
1086 * Failed (Adapter is offline/disabled) : 1
1089 qla2x00_wait_for_hba_online(scsi_qla_host_t
*vha
)
1092 unsigned long wait_online
;
1093 struct qla_hw_data
*ha
= vha
->hw
;
1094 scsi_qla_host_t
*base_vha
= pci_get_drvdata(ha
->pdev
);
1096 wait_online
= jiffies
+ (MAX_LOOP_TIMEOUT
* HZ
);
1097 while (((test_bit(ISP_ABORT_NEEDED
, &base_vha
->dpc_flags
)) ||
1098 test_bit(ABORT_ISP_ACTIVE
, &base_vha
->dpc_flags
) ||
1099 test_bit(ISP_ABORT_RETRY
, &base_vha
->dpc_flags
) ||
1100 ha
->dpc_active
) && time_before(jiffies
, wait_online
)) {
1104 if (base_vha
->flags
.online
)
1105 return_status
= QLA_SUCCESS
;
1107 return_status
= QLA_FUNCTION_FAILED
;
1109 return (return_status
);
1112 static inline int test_fcport_count(scsi_qla_host_t
*vha
)
1114 struct qla_hw_data
*ha
= vha
->hw
;
1115 unsigned long flags
;
1118 spin_lock_irqsave(&ha
->tgt
.sess_lock
, flags
);
1119 ql_dbg(ql_dbg_init
, vha
, 0x00ec,
1120 "tgt %p, fcport_count=%d\n",
1121 vha
, vha
->fcport_count
);
1122 res
= (vha
->fcport_count
== 0);
1123 spin_unlock_irqrestore(&ha
->tgt
.sess_lock
, flags
);
1129 * qla2x00_wait_for_sess_deletion can only be called from remove_one.
1130 * it has dependency on UNLOADING flag to stop device discovery
1133 qla2x00_wait_for_sess_deletion(scsi_qla_host_t
*vha
)
1135 qla2x00_mark_all_devices_lost(vha
, 0);
1137 wait_event(vha
->fcport_waitQ
, test_fcport_count(vha
));
1141 * qla2x00_wait_for_hba_ready
1142 * Wait till the HBA is ready before doing driver unload
1145 * ha - pointer to host adapter structure
1148 * Does context switching-Release SPIN_LOCK
1149 * (if any) before calling this routine.
1153 qla2x00_wait_for_hba_ready(scsi_qla_host_t
*vha
)
1155 struct qla_hw_data
*ha
= vha
->hw
;
1156 scsi_qla_host_t
*base_vha
= pci_get_drvdata(ha
->pdev
);
1158 while ((qla2x00_reset_active(vha
) || ha
->dpc_active
||
1159 ha
->flags
.mbox_busy
) ||
1160 test_bit(FX00_RESET_RECOVERY
, &vha
->dpc_flags
) ||
1161 test_bit(FX00_TARGET_SCAN
, &vha
->dpc_flags
)) {
1162 if (test_bit(UNLOADING
, &base_vha
->dpc_flags
))
1169 qla2x00_wait_for_chip_reset(scsi_qla_host_t
*vha
)
1172 unsigned long wait_reset
;
1173 struct qla_hw_data
*ha
= vha
->hw
;
1174 scsi_qla_host_t
*base_vha
= pci_get_drvdata(ha
->pdev
);
1176 wait_reset
= jiffies
+ (MAX_LOOP_TIMEOUT
* HZ
);
1177 while (((test_bit(ISP_ABORT_NEEDED
, &base_vha
->dpc_flags
)) ||
1178 test_bit(ABORT_ISP_ACTIVE
, &base_vha
->dpc_flags
) ||
1179 test_bit(ISP_ABORT_RETRY
, &base_vha
->dpc_flags
) ||
1180 ha
->dpc_active
) && time_before(jiffies
, wait_reset
)) {
1184 if (!test_bit(ISP_ABORT_NEEDED
, &base_vha
->dpc_flags
) &&
1185 ha
->flags
.chip_reset_done
)
1188 if (ha
->flags
.chip_reset_done
)
1189 return_status
= QLA_SUCCESS
;
1191 return_status
= QLA_FUNCTION_FAILED
;
1193 return return_status
;
1197 sp_get(struct srb
*sp
)
1199 atomic_inc(&sp
->ref_count
);
1202 #define ISP_REG_DISCONNECT 0xffffffffU
1203 /**************************************************************************
1204 * qla2x00_isp_reg_stat
1207 * Read the host status register of ISP before aborting the command.
1210 * ha = pointer to host adapter structure.
1214 * Either true or false.
1216 * Note: Return true if there is register disconnect.
1217 **************************************************************************/
1219 uint32_t qla2x00_isp_reg_stat(struct qla_hw_data
*ha
)
1221 struct device_reg_24xx __iomem
*reg
= &ha
->iobase
->isp24
;
1222 struct device_reg_82xx __iomem
*reg82
= &ha
->iobase
->isp82
;
1224 if (IS_P3P_TYPE(ha
))
1225 return ((RD_REG_DWORD(®82
->host_int
)) == ISP_REG_DISCONNECT
);
1227 return ((RD_REG_DWORD(®
->host_status
)) ==
1228 ISP_REG_DISCONNECT
);
1231 /**************************************************************************
1235 * The abort function will abort the specified command.
1238 * cmd = Linux SCSI command packet to be aborted.
1241 * Either SUCCESS or FAILED.
1244 * Only return FAILED if command not returned by firmware.
1245 **************************************************************************/
1247 qla2xxx_eh_abort(struct scsi_cmnd
*cmd
)
1249 scsi_qla_host_t
*vha
= shost_priv(cmd
->device
->host
);
1254 unsigned long flags
;
1256 struct qla_hw_data
*ha
= vha
->hw
;
1258 if (qla2x00_isp_reg_stat(ha
)) {
1259 ql_log(ql_log_info
, vha
, 0x8042,
1260 "PCI/Register disconnect, exiting.\n");
1266 ret
= fc_block_scsi_eh(cmd
);
1271 id
= cmd
->device
->id
;
1272 lun
= cmd
->device
->lun
;
1274 spin_lock_irqsave(&ha
->hardware_lock
, flags
);
1275 sp
= (srb_t
*) CMD_SP(cmd
);
1277 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
1281 ql_dbg(ql_dbg_taskm
, vha
, 0x8002,
1282 "Aborting from RISC nexus=%ld:%d:%llu sp=%p cmd=%p handle=%x\n",
1283 vha
->host_no
, id
, lun
, sp
, cmd
, sp
->handle
);
1285 /* Get a reference to the sp and drop the lock.*/
1288 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
1289 rval
= ha
->isp_ops
->abort_command(sp
);
1291 if (rval
== QLA_FUNCTION_PARAMETER_ERROR
)
1296 ql_dbg(ql_dbg_taskm
, vha
, 0x8003,
1297 "Abort command mbx failed cmd=%p, rval=%x.\n", cmd
, rval
);
1299 ql_dbg(ql_dbg_taskm
, vha
, 0x8004,
1300 "Abort command mbx success cmd=%p.\n", cmd
);
1304 spin_lock_irqsave(&ha
->hardware_lock
, flags
);
1306 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
1308 /* Did the command return during mailbox execution? */
1309 if (ret
== FAILED
&& !CMD_SP(cmd
))
1312 /* Wait for the command to be returned. */
1314 if (qla2x00_eh_wait_on_command(cmd
) != QLA_SUCCESS
) {
1315 ql_log(ql_log_warn
, vha
, 0x8006,
1316 "Abort handler timed out cmd=%p.\n", cmd
);
1321 ql_log(ql_log_info
, vha
, 0x801c,
1322 "Abort command issued nexus=%ld:%d:%llu -- %d %x.\n",
1323 vha
->host_no
, id
, lun
, wait
, ret
);
1329 qla2x00_eh_wait_for_pending_commands(scsi_qla_host_t
*vha
, unsigned int t
,
1330 uint64_t l
, enum nexus_wait_type type
)
1332 int cnt
, match
, status
;
1333 unsigned long flags
;
1334 struct qla_hw_data
*ha
= vha
->hw
;
1335 struct req_que
*req
;
1337 struct scsi_cmnd
*cmd
;
1339 status
= QLA_SUCCESS
;
1341 spin_lock_irqsave(&ha
->hardware_lock
, flags
);
1343 for (cnt
= 1; status
== QLA_SUCCESS
&&
1344 cnt
< req
->num_outstanding_cmds
; cnt
++) {
1345 sp
= req
->outstanding_cmds
[cnt
];
1348 if (sp
->type
!= SRB_SCSI_CMD
)
1350 if (vha
->vp_idx
!= sp
->vha
->vp_idx
)
1353 cmd
= GET_CMD_SP(sp
);
1359 match
= cmd
->device
->id
== t
;
1362 match
= (cmd
->device
->id
== t
&&
1363 cmd
->device
->lun
== l
);
1369 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
1370 status
= qla2x00_eh_wait_on_command(cmd
);
1371 spin_lock_irqsave(&ha
->hardware_lock
, flags
);
1373 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
1378 static char *reset_errors
[] = {
1381 "Task management failed",
1382 "Waiting for command completions",
1386 __qla2xxx_eh_generic_reset(char *name
, enum nexus_wait_type type
,
1387 struct scsi_cmnd
*cmd
, int (*do_reset
)(struct fc_port
*, uint64_t, int))
1389 scsi_qla_host_t
*vha
= shost_priv(cmd
->device
->host
);
1390 fc_port_t
*fcport
= (struct fc_port
*) cmd
->device
->hostdata
;
1397 err
= fc_block_scsi_eh(cmd
);
1401 ql_log(ql_log_info
, vha
, 0x8009,
1402 "%s RESET ISSUED nexus=%ld:%d:%llu cmd=%p.\n", name
, vha
->host_no
,
1403 cmd
->device
->id
, cmd
->device
->lun
, cmd
);
1406 if (qla2x00_wait_for_hba_online(vha
) != QLA_SUCCESS
) {
1407 ql_log(ql_log_warn
, vha
, 0x800a,
1408 "Wait for hba online failed for cmd=%p.\n", cmd
);
1409 goto eh_reset_failed
;
1412 if (do_reset(fcport
, cmd
->device
->lun
, cmd
->request
->cpu
+ 1)
1414 ql_log(ql_log_warn
, vha
, 0x800c,
1415 "do_reset failed for cmd=%p.\n", cmd
);
1416 goto eh_reset_failed
;
1419 if (qla2x00_eh_wait_for_pending_commands(vha
, cmd
->device
->id
,
1420 cmd
->device
->lun
, type
) != QLA_SUCCESS
) {
1421 ql_log(ql_log_warn
, vha
, 0x800d,
1422 "wait for pending cmds failed for cmd=%p.\n", cmd
);
1423 goto eh_reset_failed
;
1426 ql_log(ql_log_info
, vha
, 0x800e,
1427 "%s RESET SUCCEEDED nexus:%ld:%d:%llu cmd=%p.\n", name
,
1428 vha
->host_no
, cmd
->device
->id
, cmd
->device
->lun
, cmd
);
1433 ql_log(ql_log_info
, vha
, 0x800f,
1434 "%s RESET FAILED: %s nexus=%ld:%d:%llu cmd=%p.\n", name
,
1435 reset_errors
[err
], vha
->host_no
, cmd
->device
->id
, cmd
->device
->lun
,
1441 qla2xxx_eh_device_reset(struct scsi_cmnd
*cmd
)
1443 scsi_qla_host_t
*vha
= shost_priv(cmd
->device
->host
);
1444 struct qla_hw_data
*ha
= vha
->hw
;
1446 if (qla2x00_isp_reg_stat(ha
)) {
1447 ql_log(ql_log_info
, vha
, 0x803e,
1448 "PCI/Register disconnect, exiting.\n");
1452 return __qla2xxx_eh_generic_reset("DEVICE", WAIT_LUN
, cmd
,
1453 ha
->isp_ops
->lun_reset
);
1457 qla2xxx_eh_target_reset(struct scsi_cmnd
*cmd
)
1459 scsi_qla_host_t
*vha
= shost_priv(cmd
->device
->host
);
1460 struct qla_hw_data
*ha
= vha
->hw
;
1462 if (qla2x00_isp_reg_stat(ha
)) {
1463 ql_log(ql_log_info
, vha
, 0x803f,
1464 "PCI/Register disconnect, exiting.\n");
1468 return __qla2xxx_eh_generic_reset("TARGET", WAIT_TARGET
, cmd
,
1469 ha
->isp_ops
->target_reset
);
1472 /**************************************************************************
1473 * qla2xxx_eh_bus_reset
1476 * The bus reset function will reset the bus and abort any executing
1480 * cmd = Linux SCSI command packet of the command that cause the
1484 * SUCCESS/FAILURE (defined as macro in scsi.h).
1486 **************************************************************************/
1488 qla2xxx_eh_bus_reset(struct scsi_cmnd
*cmd
)
1490 scsi_qla_host_t
*vha
= shost_priv(cmd
->device
->host
);
1491 fc_port_t
*fcport
= (struct fc_port
*) cmd
->device
->hostdata
;
1495 struct qla_hw_data
*ha
= vha
->hw
;
1497 if (qla2x00_isp_reg_stat(ha
)) {
1498 ql_log(ql_log_info
, vha
, 0x8040,
1499 "PCI/Register disconnect, exiting.\n");
1503 id
= cmd
->device
->id
;
1504 lun
= cmd
->device
->lun
;
1510 ret
= fc_block_scsi_eh(cmd
);
1515 ql_log(ql_log_info
, vha
, 0x8012,
1516 "BUS RESET ISSUED nexus=%ld:%d:%llu.\n", vha
->host_no
, id
, lun
);
1518 if (qla2x00_wait_for_hba_online(vha
) != QLA_SUCCESS
) {
1519 ql_log(ql_log_fatal
, vha
, 0x8013,
1520 "Wait for hba online failed board disabled.\n");
1521 goto eh_bus_reset_done
;
1524 if (qla2x00_loop_reset(vha
) == QLA_SUCCESS
)
1528 goto eh_bus_reset_done
;
1530 /* Flush outstanding commands. */
1531 if (qla2x00_eh_wait_for_pending_commands(vha
, 0, 0, WAIT_HOST
) !=
1533 ql_log(ql_log_warn
, vha
, 0x8014,
1534 "Wait for pending commands failed.\n");
1539 ql_log(ql_log_warn
, vha
, 0x802b,
1540 "BUS RESET %s nexus=%ld:%d:%llu.\n",
1541 (ret
== FAILED
) ? "FAILED" : "SUCCEEDED", vha
->host_no
, id
, lun
);
1546 /**************************************************************************
1547 * qla2xxx_eh_host_reset
1550 * The reset function will reset the Adapter.
1553 * cmd = Linux SCSI command packet of the command that cause the
1557 * Either SUCCESS or FAILED.
1560 **************************************************************************/
1562 qla2xxx_eh_host_reset(struct scsi_cmnd
*cmd
)
1564 scsi_qla_host_t
*vha
= shost_priv(cmd
->device
->host
);
1565 struct qla_hw_data
*ha
= vha
->hw
;
1569 scsi_qla_host_t
*base_vha
= pci_get_drvdata(ha
->pdev
);
1571 if (qla2x00_isp_reg_stat(ha
)) {
1572 ql_log(ql_log_info
, vha
, 0x8041,
1573 "PCI/Register disconnect, exiting.\n");
1574 schedule_work(&ha
->board_disable
);
1578 id
= cmd
->device
->id
;
1579 lun
= cmd
->device
->lun
;
1581 ql_log(ql_log_info
, vha
, 0x8018,
1582 "ADAPTER RESET ISSUED nexus=%ld:%d:%llu.\n", vha
->host_no
, id
, lun
);
1585 * No point in issuing another reset if one is active. Also do not
1586 * attempt a reset if we are updating flash.
1588 if (qla2x00_reset_active(vha
) || ha
->optrom_state
!= QLA_SWAITING
)
1589 goto eh_host_reset_lock
;
1591 if (vha
!= base_vha
) {
1592 if (qla2x00_vp_abort_isp(vha
))
1593 goto eh_host_reset_lock
;
1595 if (IS_P3P_TYPE(vha
->hw
)) {
1596 if (!qla82xx_fcoe_ctx_reset(vha
)) {
1597 /* Ctx reset success */
1599 goto eh_host_reset_lock
;
1601 /* fall thru if ctx reset failed */
1604 flush_workqueue(ha
->wq
);
1606 set_bit(ABORT_ISP_ACTIVE
, &base_vha
->dpc_flags
);
1607 if (ha
->isp_ops
->abort_isp(base_vha
)) {
1608 clear_bit(ABORT_ISP_ACTIVE
, &base_vha
->dpc_flags
);
1609 /* failed. schedule dpc to try */
1610 set_bit(ISP_ABORT_NEEDED
, &base_vha
->dpc_flags
);
1612 if (qla2x00_wait_for_hba_online(vha
) != QLA_SUCCESS
) {
1613 ql_log(ql_log_warn
, vha
, 0x802a,
1614 "wait for hba online failed.\n");
1615 goto eh_host_reset_lock
;
1618 clear_bit(ABORT_ISP_ACTIVE
, &base_vha
->dpc_flags
);
1621 /* Waiting for command to be returned to OS.*/
1622 if (qla2x00_eh_wait_for_pending_commands(vha
, 0, 0, WAIT_HOST
) ==
1627 ql_log(ql_log_info
, vha
, 0x8017,
1628 "ADAPTER RESET %s nexus=%ld:%d:%llu.\n",
1629 (ret
== FAILED
) ? "FAILED" : "SUCCEEDED", vha
->host_no
, id
, lun
);
1635 * qla2x00_loop_reset
1639 * ha = adapter block pointer.
1645 qla2x00_loop_reset(scsi_qla_host_t
*vha
)
1648 struct fc_port
*fcport
;
1649 struct qla_hw_data
*ha
= vha
->hw
;
1651 if (IS_QLAFX00(ha
)) {
1652 return qlafx00_loop_reset(vha
);
1655 if (ql2xtargetreset
== 1 && ha
->flags
.enable_target_reset
) {
1656 list_for_each_entry(fcport
, &vha
->vp_fcports
, list
) {
1657 if (fcport
->port_type
!= FCT_TARGET
)
1660 ret
= ha
->isp_ops
->target_reset(fcport
, 0, 0);
1661 if (ret
!= QLA_SUCCESS
) {
1662 ql_dbg(ql_dbg_taskm
, vha
, 0x802c,
1663 "Bus Reset failed: Reset=%d "
1664 "d_id=%x.\n", ret
, fcport
->d_id
.b24
);
1670 if (ha
->flags
.enable_lip_full_login
&& !IS_CNA_CAPABLE(ha
)) {
1671 atomic_set(&vha
->loop_state
, LOOP_DOWN
);
1672 atomic_set(&vha
->loop_down_timer
, LOOP_DOWN_TIME
);
1673 qla2x00_mark_all_devices_lost(vha
, 0);
1674 ret
= qla2x00_full_login_lip(vha
);
1675 if (ret
!= QLA_SUCCESS
) {
1676 ql_dbg(ql_dbg_taskm
, vha
, 0x802d,
1677 "full_login_lip=%d.\n", ret
);
1681 if (ha
->flags
.enable_lip_reset
) {
1682 ret
= qla2x00_lip_reset(vha
);
1683 if (ret
!= QLA_SUCCESS
)
1684 ql_dbg(ql_dbg_taskm
, vha
, 0x802e,
1685 "lip_reset failed (%d).\n", ret
);
1688 /* Issue marker command only when we are going to start the I/O */
1689 vha
->marker_needed
= 1;
1695 qla2x00_abort_all_cmds(scsi_qla_host_t
*vha
, int res
)
1697 int que
, cnt
, status
;
1698 unsigned long flags
;
1700 struct qla_hw_data
*ha
= vha
->hw
;
1701 struct req_que
*req
;
1702 struct qla_tgt
*tgt
= vha
->vha_tgt
.qla_tgt
;
1703 struct qla_tgt_cmd
*cmd
;
1706 spin_lock_irqsave(&ha
->hardware_lock
, flags
);
1707 for (que
= 0; que
< ha
->max_req_queues
; que
++) {
1708 req
= ha
->req_q_map
[que
];
1711 if (!req
->outstanding_cmds
)
1713 for (cnt
= 1; cnt
< req
->num_outstanding_cmds
; cnt
++) {
1714 sp
= req
->outstanding_cmds
[cnt
];
1716 req
->outstanding_cmds
[cnt
] = NULL
;
1717 if (sp
->cmd_type
== TYPE_SRB
) {
1718 if ((sp
->type
== SRB_NVME_CMD
) ||
1719 (sp
->type
== SRB_NVME_LS
)) {
1721 spin_unlock_irqrestore(
1722 &ha
->hardware_lock
, flags
);
1723 qla_nvme_abort(ha
, sp
);
1725 &ha
->hardware_lock
, flags
);
1726 } else if (GET_CMD_SP(sp
) &&
1727 !ha
->flags
.eeh_busy
&&
1728 (sp
->type
== SRB_SCSI_CMD
)) {
1730 * Don't abort commands in
1731 * adapter during EEH
1732 * recovery as it's not
1733 * accessible/responding.
1735 * Get a reference to the sp
1736 * and drop the lock. The
1737 * reference ensures this
1738 * sp->done() call and not the
1739 * call in qla2xxx_eh_abort()
1740 * ends the SCSI command (with
1744 spin_unlock_irqrestore(
1745 &ha
->hardware_lock
, flags
);
1746 status
= qla2xxx_eh_abort(
1749 &ha
->hardware_lock
, flags
);
1751 * Get rid of extra reference
1752 * if immediate exit from
1755 if (status
== FAILED
&&
1756 (qla2x00_isp_reg_stat(ha
)))
1762 if (!vha
->hw
->tgt
.tgt_ops
|| !tgt
||
1763 qla_ini_mode_enabled(vha
)) {
1765 ql_dbg(ql_dbg_tgt_mgt
,
1767 "HOST-ABORT-HNDLR: dpc_flags=%lx. Target mode disabled\n",
1771 cmd
= (struct qla_tgt_cmd
*)sp
;
1772 qlt_abort_cmd_on_host_reset(cmd
->vha
,
1778 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
1782 qla2xxx_slave_alloc(struct scsi_device
*sdev
)
1784 struct fc_rport
*rport
= starget_to_rport(scsi_target(sdev
));
1786 if (!rport
|| fc_remote_port_chkready(rport
))
1789 sdev
->hostdata
= *(fc_port_t
**)rport
->dd_data
;
1795 qla2xxx_slave_configure(struct scsi_device
*sdev
)
1797 scsi_qla_host_t
*vha
= shost_priv(sdev
->host
);
1798 struct req_que
*req
= vha
->req
;
1800 if (IS_T10_PI_CAPABLE(vha
->hw
))
1801 blk_queue_update_dma_alignment(sdev
->request_queue
, 0x7);
1803 scsi_change_queue_depth(sdev
, req
->max_q_depth
);
1808 qla2xxx_slave_destroy(struct scsi_device
*sdev
)
1810 sdev
->hostdata
= NULL
;
1814 * qla2x00_config_dma_addressing() - Configure OS DMA addressing method.
1817 * At exit, the @ha's flags.enable_64bit_addressing set to indicated
1818 * supported addressing method.
1821 qla2x00_config_dma_addressing(struct qla_hw_data
*ha
)
1823 /* Assume a 32bit DMA mask. */
1824 ha
->flags
.enable_64bit_addressing
= 0;
1826 if (!dma_set_mask(&ha
->pdev
->dev
, DMA_BIT_MASK(64))) {
1827 /* Any upper-dword bits set? */
1828 if (MSD(dma_get_required_mask(&ha
->pdev
->dev
)) &&
1829 !pci_set_consistent_dma_mask(ha
->pdev
, DMA_BIT_MASK(64))) {
1830 /* Ok, a 64bit DMA mask is applicable. */
1831 ha
->flags
.enable_64bit_addressing
= 1;
1832 ha
->isp_ops
->calc_req_entries
= qla2x00_calc_iocbs_64
;
1833 ha
->isp_ops
->build_iocbs
= qla2x00_build_scsi_iocbs_64
;
1838 dma_set_mask(&ha
->pdev
->dev
, DMA_BIT_MASK(32));
1839 pci_set_consistent_dma_mask(ha
->pdev
, DMA_BIT_MASK(32));
1843 qla2x00_enable_intrs(struct qla_hw_data
*ha
)
1845 unsigned long flags
= 0;
1846 struct device_reg_2xxx __iomem
*reg
= &ha
->iobase
->isp
;
1848 spin_lock_irqsave(&ha
->hardware_lock
, flags
);
1849 ha
->interrupts_on
= 1;
1850 /* enable risc and host interrupts */
1851 WRT_REG_WORD(®
->ictrl
, ICR_EN_INT
| ICR_EN_RISC
);
1852 RD_REG_WORD(®
->ictrl
);
1853 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
1858 qla2x00_disable_intrs(struct qla_hw_data
*ha
)
1860 unsigned long flags
= 0;
1861 struct device_reg_2xxx __iomem
*reg
= &ha
->iobase
->isp
;
1863 spin_lock_irqsave(&ha
->hardware_lock
, flags
);
1864 ha
->interrupts_on
= 0;
1865 /* disable risc and host interrupts */
1866 WRT_REG_WORD(®
->ictrl
, 0);
1867 RD_REG_WORD(®
->ictrl
);
1868 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
1872 qla24xx_enable_intrs(struct qla_hw_data
*ha
)
1874 unsigned long flags
= 0;
1875 struct device_reg_24xx __iomem
*reg
= &ha
->iobase
->isp24
;
1877 spin_lock_irqsave(&ha
->hardware_lock
, flags
);
1878 ha
->interrupts_on
= 1;
1879 WRT_REG_DWORD(®
->ictrl
, ICRX_EN_RISC_INT
);
1880 RD_REG_DWORD(®
->ictrl
);
1881 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
1885 qla24xx_disable_intrs(struct qla_hw_data
*ha
)
1887 unsigned long flags
= 0;
1888 struct device_reg_24xx __iomem
*reg
= &ha
->iobase
->isp24
;
1890 if (IS_NOPOLLING_TYPE(ha
))
1892 spin_lock_irqsave(&ha
->hardware_lock
, flags
);
1893 ha
->interrupts_on
= 0;
1894 WRT_REG_DWORD(®
->ictrl
, 0);
1895 RD_REG_DWORD(®
->ictrl
);
1896 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
1900 qla2x00_iospace_config(struct qla_hw_data
*ha
)
1902 resource_size_t pio
;
1905 if (pci_request_selected_regions(ha
->pdev
, ha
->bars
,
1906 QLA2XXX_DRIVER_NAME
)) {
1907 ql_log_pci(ql_log_fatal
, ha
->pdev
, 0x0011,
1908 "Failed to reserve PIO/MMIO regions (%s), aborting.\n",
1909 pci_name(ha
->pdev
));
1910 goto iospace_error_exit
;
1912 if (!(ha
->bars
& 1))
1915 /* We only need PIO for Flash operations on ISP2312 v2 chips. */
1916 pio
= pci_resource_start(ha
->pdev
, 0);
1917 if (pci_resource_flags(ha
->pdev
, 0) & IORESOURCE_IO
) {
1918 if (pci_resource_len(ha
->pdev
, 0) < MIN_IOBASE_LEN
) {
1919 ql_log_pci(ql_log_warn
, ha
->pdev
, 0x0012,
1920 "Invalid pci I/O region size (%s).\n",
1921 pci_name(ha
->pdev
));
1925 ql_log_pci(ql_log_warn
, ha
->pdev
, 0x0013,
1926 "Region #0 no a PIO resource (%s).\n",
1927 pci_name(ha
->pdev
));
1930 ha
->pio_address
= pio
;
1931 ql_dbg_pci(ql_dbg_init
, ha
->pdev
, 0x0014,
1932 "PIO address=%llu.\n",
1933 (unsigned long long)ha
->pio_address
);
1936 /* Use MMIO operations for all accesses. */
1937 if (!(pci_resource_flags(ha
->pdev
, 1) & IORESOURCE_MEM
)) {
1938 ql_log_pci(ql_log_fatal
, ha
->pdev
, 0x0015,
1939 "Region #1 not an MMIO resource (%s), aborting.\n",
1940 pci_name(ha
->pdev
));
1941 goto iospace_error_exit
;
1943 if (pci_resource_len(ha
->pdev
, 1) < MIN_IOBASE_LEN
) {
1944 ql_log_pci(ql_log_fatal
, ha
->pdev
, 0x0016,
1945 "Invalid PCI mem region size (%s), aborting.\n",
1946 pci_name(ha
->pdev
));
1947 goto iospace_error_exit
;
1950 ha
->iobase
= ioremap(pci_resource_start(ha
->pdev
, 1), MIN_IOBASE_LEN
);
1952 ql_log_pci(ql_log_fatal
, ha
->pdev
, 0x0017,
1953 "Cannot remap MMIO (%s), aborting.\n",
1954 pci_name(ha
->pdev
));
1955 goto iospace_error_exit
;
1958 /* Determine queue resources */
1959 ha
->max_req_queues
= ha
->max_rsp_queues
= 1;
1960 ha
->msix_count
= QLA_BASE_VECTORS
;
1961 if (!ql2xmqsupport
|| (!IS_QLA25XX(ha
) && !IS_QLA81XX(ha
)))
1964 ha
->mqiobase
= ioremap(pci_resource_start(ha
->pdev
, 3),
1965 pci_resource_len(ha
->pdev
, 3));
1967 ql_dbg_pci(ql_dbg_init
, ha
->pdev
, 0x0018,
1968 "MQIO Base=%p.\n", ha
->mqiobase
);
1969 /* Read MSIX vector size of the board */
1970 pci_read_config_word(ha
->pdev
, QLA_PCI_MSIX_CONTROL
, &msix
);
1971 ha
->msix_count
= msix
+ 1;
1972 /* Max queues are bounded by available msix vectors */
1973 /* MB interrupt uses 1 vector */
1974 ha
->max_req_queues
= ha
->msix_count
- 1;
1975 ha
->max_rsp_queues
= ha
->max_req_queues
;
1976 /* Queue pairs is the max value minus the base queue pair */
1977 ha
->max_qpairs
= ha
->max_rsp_queues
- 1;
1978 ql_dbg_pci(ql_dbg_init
, ha
->pdev
, 0x0188,
1979 "Max no of queues pairs: %d.\n", ha
->max_qpairs
);
1981 ql_log_pci(ql_log_info
, ha
->pdev
, 0x001a,
1982 "MSI-X vector count: %d.\n", ha
->msix_count
);
1984 ql_log_pci(ql_log_info
, ha
->pdev
, 0x001b,
1985 "BAR 3 not enabled.\n");
1988 ql_dbg_pci(ql_dbg_init
, ha
->pdev
, 0x001c,
1989 "MSIX Count: %d.\n", ha
->msix_count
);
1998 qla83xx_iospace_config(struct qla_hw_data
*ha
)
2002 if (pci_request_selected_regions(ha
->pdev
, ha
->bars
,
2003 QLA2XXX_DRIVER_NAME
)) {
2004 ql_log_pci(ql_log_fatal
, ha
->pdev
, 0x0117,
2005 "Failed to reserve PIO/MMIO regions (%s), aborting.\n",
2006 pci_name(ha
->pdev
));
2008 goto iospace_error_exit
;
2011 /* Use MMIO operations for all accesses. */
2012 if (!(pci_resource_flags(ha
->pdev
, 0) & IORESOURCE_MEM
)) {
2013 ql_log_pci(ql_log_warn
, ha
->pdev
, 0x0118,
2014 "Invalid pci I/O region size (%s).\n",
2015 pci_name(ha
->pdev
));
2016 goto iospace_error_exit
;
2018 if (pci_resource_len(ha
->pdev
, 0) < MIN_IOBASE_LEN
) {
2019 ql_log_pci(ql_log_warn
, ha
->pdev
, 0x0119,
2020 "Invalid PCI mem region size (%s), aborting\n",
2021 pci_name(ha
->pdev
));
2022 goto iospace_error_exit
;
2025 ha
->iobase
= ioremap(pci_resource_start(ha
->pdev
, 0), MIN_IOBASE_LEN
);
2027 ql_log_pci(ql_log_fatal
, ha
->pdev
, 0x011a,
2028 "Cannot remap MMIO (%s), aborting.\n",
2029 pci_name(ha
->pdev
));
2030 goto iospace_error_exit
;
2033 /* 64bit PCI BAR - BAR2 will correspoond to region 4 */
2034 /* 83XX 26XX always use MQ type access for queues
2035 * - mbar 2, a.k.a region 4 */
2036 ha
->max_req_queues
= ha
->max_rsp_queues
= 1;
2037 ha
->msix_count
= QLA_BASE_VECTORS
;
2038 ha
->mqiobase
= ioremap(pci_resource_start(ha
->pdev
, 4),
2039 pci_resource_len(ha
->pdev
, 4));
2041 if (!ha
->mqiobase
) {
2042 ql_log_pci(ql_log_fatal
, ha
->pdev
, 0x011d,
2043 "BAR2/region4 not enabled\n");
2047 ha
->msixbase
= ioremap(pci_resource_start(ha
->pdev
, 2),
2048 pci_resource_len(ha
->pdev
, 2));
2050 /* Read MSIX vector size of the board */
2051 pci_read_config_word(ha
->pdev
,
2052 QLA_83XX_PCI_MSIX_CONTROL
, &msix
);
2053 ha
->msix_count
= (msix
& PCI_MSIX_FLAGS_QSIZE
) + 1;
2055 * By default, driver uses at least two msix vectors
2058 if (ql2xmqsupport
) {
2059 /* MB interrupt uses 1 vector */
2060 ha
->max_req_queues
= ha
->msix_count
- 1;
2062 /* ATIOQ needs 1 vector. That's 1 less QPair */
2063 if (QLA_TGT_MODE_ENABLED())
2064 ha
->max_req_queues
--;
2066 ha
->max_rsp_queues
= ha
->max_req_queues
;
2068 /* Queue pairs is the max value minus
2069 * the base queue pair */
2070 ha
->max_qpairs
= ha
->max_req_queues
- 1;
2071 ql_dbg_pci(ql_dbg_init
, ha
->pdev
, 0x00e3,
2072 "Max no of queues pairs: %d.\n", ha
->max_qpairs
);
2074 ql_log_pci(ql_log_info
, ha
->pdev
, 0x011c,
2075 "MSI-X vector count: %d.\n", ha
->msix_count
);
2077 ql_log_pci(ql_log_info
, ha
->pdev
, 0x011e,
2078 "BAR 1 not enabled.\n");
2081 ql_dbg_pci(ql_dbg_init
, ha
->pdev
, 0x011f,
2082 "MSIX Count: %d.\n", ha
->msix_count
);
2089 static struct isp_operations qla2100_isp_ops
= {
2090 .pci_config
= qla2100_pci_config
,
2091 .reset_chip
= qla2x00_reset_chip
,
2092 .chip_diag
= qla2x00_chip_diag
,
2093 .config_rings
= qla2x00_config_rings
,
2094 .reset_adapter
= qla2x00_reset_adapter
,
2095 .nvram_config
= qla2x00_nvram_config
,
2096 .update_fw_options
= qla2x00_update_fw_options
,
2097 .load_risc
= qla2x00_load_risc
,
2098 .pci_info_str
= qla2x00_pci_info_str
,
2099 .fw_version_str
= qla2x00_fw_version_str
,
2100 .intr_handler
= qla2100_intr_handler
,
2101 .enable_intrs
= qla2x00_enable_intrs
,
2102 .disable_intrs
= qla2x00_disable_intrs
,
2103 .abort_command
= qla2x00_abort_command
,
2104 .target_reset
= qla2x00_abort_target
,
2105 .lun_reset
= qla2x00_lun_reset
,
2106 .fabric_login
= qla2x00_login_fabric
,
2107 .fabric_logout
= qla2x00_fabric_logout
,
2108 .calc_req_entries
= qla2x00_calc_iocbs_32
,
2109 .build_iocbs
= qla2x00_build_scsi_iocbs_32
,
2110 .prep_ms_iocb
= qla2x00_prep_ms_iocb
,
2111 .prep_ms_fdmi_iocb
= qla2x00_prep_ms_fdmi_iocb
,
2112 .read_nvram
= qla2x00_read_nvram_data
,
2113 .write_nvram
= qla2x00_write_nvram_data
,
2114 .fw_dump
= qla2100_fw_dump
,
2117 .beacon_blink
= NULL
,
2118 .read_optrom
= qla2x00_read_optrom_data
,
2119 .write_optrom
= qla2x00_write_optrom_data
,
2120 .get_flash_version
= qla2x00_get_flash_version
,
2121 .start_scsi
= qla2x00_start_scsi
,
2122 .start_scsi_mq
= NULL
,
2123 .abort_isp
= qla2x00_abort_isp
,
2124 .iospace_config
= qla2x00_iospace_config
,
2125 .initialize_adapter
= qla2x00_initialize_adapter
,
2128 static struct isp_operations qla2300_isp_ops
= {
2129 .pci_config
= qla2300_pci_config
,
2130 .reset_chip
= qla2x00_reset_chip
,
2131 .chip_diag
= qla2x00_chip_diag
,
2132 .config_rings
= qla2x00_config_rings
,
2133 .reset_adapter
= qla2x00_reset_adapter
,
2134 .nvram_config
= qla2x00_nvram_config
,
2135 .update_fw_options
= qla2x00_update_fw_options
,
2136 .load_risc
= qla2x00_load_risc
,
2137 .pci_info_str
= qla2x00_pci_info_str
,
2138 .fw_version_str
= qla2x00_fw_version_str
,
2139 .intr_handler
= qla2300_intr_handler
,
2140 .enable_intrs
= qla2x00_enable_intrs
,
2141 .disable_intrs
= qla2x00_disable_intrs
,
2142 .abort_command
= qla2x00_abort_command
,
2143 .target_reset
= qla2x00_abort_target
,
2144 .lun_reset
= qla2x00_lun_reset
,
2145 .fabric_login
= qla2x00_login_fabric
,
2146 .fabric_logout
= qla2x00_fabric_logout
,
2147 .calc_req_entries
= qla2x00_calc_iocbs_32
,
2148 .build_iocbs
= qla2x00_build_scsi_iocbs_32
,
2149 .prep_ms_iocb
= qla2x00_prep_ms_iocb
,
2150 .prep_ms_fdmi_iocb
= qla2x00_prep_ms_fdmi_iocb
,
2151 .read_nvram
= qla2x00_read_nvram_data
,
2152 .write_nvram
= qla2x00_write_nvram_data
,
2153 .fw_dump
= qla2300_fw_dump
,
2154 .beacon_on
= qla2x00_beacon_on
,
2155 .beacon_off
= qla2x00_beacon_off
,
2156 .beacon_blink
= qla2x00_beacon_blink
,
2157 .read_optrom
= qla2x00_read_optrom_data
,
2158 .write_optrom
= qla2x00_write_optrom_data
,
2159 .get_flash_version
= qla2x00_get_flash_version
,
2160 .start_scsi
= qla2x00_start_scsi
,
2161 .start_scsi_mq
= NULL
,
2162 .abort_isp
= qla2x00_abort_isp
,
2163 .iospace_config
= qla2x00_iospace_config
,
2164 .initialize_adapter
= qla2x00_initialize_adapter
,
2167 static struct isp_operations qla24xx_isp_ops
= {
2168 .pci_config
= qla24xx_pci_config
,
2169 .reset_chip
= qla24xx_reset_chip
,
2170 .chip_diag
= qla24xx_chip_diag
,
2171 .config_rings
= qla24xx_config_rings
,
2172 .reset_adapter
= qla24xx_reset_adapter
,
2173 .nvram_config
= qla24xx_nvram_config
,
2174 .update_fw_options
= qla24xx_update_fw_options
,
2175 .load_risc
= qla24xx_load_risc
,
2176 .pci_info_str
= qla24xx_pci_info_str
,
2177 .fw_version_str
= qla24xx_fw_version_str
,
2178 .intr_handler
= qla24xx_intr_handler
,
2179 .enable_intrs
= qla24xx_enable_intrs
,
2180 .disable_intrs
= qla24xx_disable_intrs
,
2181 .abort_command
= qla24xx_abort_command
,
2182 .target_reset
= qla24xx_abort_target
,
2183 .lun_reset
= qla24xx_lun_reset
,
2184 .fabric_login
= qla24xx_login_fabric
,
2185 .fabric_logout
= qla24xx_fabric_logout
,
2186 .calc_req_entries
= NULL
,
2187 .build_iocbs
= NULL
,
2188 .prep_ms_iocb
= qla24xx_prep_ms_iocb
,
2189 .prep_ms_fdmi_iocb
= qla24xx_prep_ms_fdmi_iocb
,
2190 .read_nvram
= qla24xx_read_nvram_data
,
2191 .write_nvram
= qla24xx_write_nvram_data
,
2192 .fw_dump
= qla24xx_fw_dump
,
2193 .beacon_on
= qla24xx_beacon_on
,
2194 .beacon_off
= qla24xx_beacon_off
,
2195 .beacon_blink
= qla24xx_beacon_blink
,
2196 .read_optrom
= qla24xx_read_optrom_data
,
2197 .write_optrom
= qla24xx_write_optrom_data
,
2198 .get_flash_version
= qla24xx_get_flash_version
,
2199 .start_scsi
= qla24xx_start_scsi
,
2200 .start_scsi_mq
= NULL
,
2201 .abort_isp
= qla2x00_abort_isp
,
2202 .iospace_config
= qla2x00_iospace_config
,
2203 .initialize_adapter
= qla2x00_initialize_adapter
,
2206 static struct isp_operations qla25xx_isp_ops
= {
2207 .pci_config
= qla25xx_pci_config
,
2208 .reset_chip
= qla24xx_reset_chip
,
2209 .chip_diag
= qla24xx_chip_diag
,
2210 .config_rings
= qla24xx_config_rings
,
2211 .reset_adapter
= qla24xx_reset_adapter
,
2212 .nvram_config
= qla24xx_nvram_config
,
2213 .update_fw_options
= qla24xx_update_fw_options
,
2214 .load_risc
= qla24xx_load_risc
,
2215 .pci_info_str
= qla24xx_pci_info_str
,
2216 .fw_version_str
= qla24xx_fw_version_str
,
2217 .intr_handler
= qla24xx_intr_handler
,
2218 .enable_intrs
= qla24xx_enable_intrs
,
2219 .disable_intrs
= qla24xx_disable_intrs
,
2220 .abort_command
= qla24xx_abort_command
,
2221 .target_reset
= qla24xx_abort_target
,
2222 .lun_reset
= qla24xx_lun_reset
,
2223 .fabric_login
= qla24xx_login_fabric
,
2224 .fabric_logout
= qla24xx_fabric_logout
,
2225 .calc_req_entries
= NULL
,
2226 .build_iocbs
= NULL
,
2227 .prep_ms_iocb
= qla24xx_prep_ms_iocb
,
2228 .prep_ms_fdmi_iocb
= qla24xx_prep_ms_fdmi_iocb
,
2229 .read_nvram
= qla25xx_read_nvram_data
,
2230 .write_nvram
= qla25xx_write_nvram_data
,
2231 .fw_dump
= qla25xx_fw_dump
,
2232 .beacon_on
= qla24xx_beacon_on
,
2233 .beacon_off
= qla24xx_beacon_off
,
2234 .beacon_blink
= qla24xx_beacon_blink
,
2235 .read_optrom
= qla25xx_read_optrom_data
,
2236 .write_optrom
= qla24xx_write_optrom_data
,
2237 .get_flash_version
= qla24xx_get_flash_version
,
2238 .start_scsi
= qla24xx_dif_start_scsi
,
2239 .start_scsi_mq
= qla2xxx_dif_start_scsi_mq
,
2240 .abort_isp
= qla2x00_abort_isp
,
2241 .iospace_config
= qla2x00_iospace_config
,
2242 .initialize_adapter
= qla2x00_initialize_adapter
,
2245 static struct isp_operations qla81xx_isp_ops
= {
2246 .pci_config
= qla25xx_pci_config
,
2247 .reset_chip
= qla24xx_reset_chip
,
2248 .chip_diag
= qla24xx_chip_diag
,
2249 .config_rings
= qla24xx_config_rings
,
2250 .reset_adapter
= qla24xx_reset_adapter
,
2251 .nvram_config
= qla81xx_nvram_config
,
2252 .update_fw_options
= qla81xx_update_fw_options
,
2253 .load_risc
= qla81xx_load_risc
,
2254 .pci_info_str
= qla24xx_pci_info_str
,
2255 .fw_version_str
= qla24xx_fw_version_str
,
2256 .intr_handler
= qla24xx_intr_handler
,
2257 .enable_intrs
= qla24xx_enable_intrs
,
2258 .disable_intrs
= qla24xx_disable_intrs
,
2259 .abort_command
= qla24xx_abort_command
,
2260 .target_reset
= qla24xx_abort_target
,
2261 .lun_reset
= qla24xx_lun_reset
,
2262 .fabric_login
= qla24xx_login_fabric
,
2263 .fabric_logout
= qla24xx_fabric_logout
,
2264 .calc_req_entries
= NULL
,
2265 .build_iocbs
= NULL
,
2266 .prep_ms_iocb
= qla24xx_prep_ms_iocb
,
2267 .prep_ms_fdmi_iocb
= qla24xx_prep_ms_fdmi_iocb
,
2269 .write_nvram
= NULL
,
2270 .fw_dump
= qla81xx_fw_dump
,
2271 .beacon_on
= qla24xx_beacon_on
,
2272 .beacon_off
= qla24xx_beacon_off
,
2273 .beacon_blink
= qla83xx_beacon_blink
,
2274 .read_optrom
= qla25xx_read_optrom_data
,
2275 .write_optrom
= qla24xx_write_optrom_data
,
2276 .get_flash_version
= qla24xx_get_flash_version
,
2277 .start_scsi
= qla24xx_dif_start_scsi
,
2278 .start_scsi_mq
= qla2xxx_dif_start_scsi_mq
,
2279 .abort_isp
= qla2x00_abort_isp
,
2280 .iospace_config
= qla2x00_iospace_config
,
2281 .initialize_adapter
= qla2x00_initialize_adapter
,
2284 static struct isp_operations qla82xx_isp_ops
= {
2285 .pci_config
= qla82xx_pci_config
,
2286 .reset_chip
= qla82xx_reset_chip
,
2287 .chip_diag
= qla24xx_chip_diag
,
2288 .config_rings
= qla82xx_config_rings
,
2289 .reset_adapter
= qla24xx_reset_adapter
,
2290 .nvram_config
= qla81xx_nvram_config
,
2291 .update_fw_options
= qla24xx_update_fw_options
,
2292 .load_risc
= qla82xx_load_risc
,
2293 .pci_info_str
= qla24xx_pci_info_str
,
2294 .fw_version_str
= qla24xx_fw_version_str
,
2295 .intr_handler
= qla82xx_intr_handler
,
2296 .enable_intrs
= qla82xx_enable_intrs
,
2297 .disable_intrs
= qla82xx_disable_intrs
,
2298 .abort_command
= qla24xx_abort_command
,
2299 .target_reset
= qla24xx_abort_target
,
2300 .lun_reset
= qla24xx_lun_reset
,
2301 .fabric_login
= qla24xx_login_fabric
,
2302 .fabric_logout
= qla24xx_fabric_logout
,
2303 .calc_req_entries
= NULL
,
2304 .build_iocbs
= NULL
,
2305 .prep_ms_iocb
= qla24xx_prep_ms_iocb
,
2306 .prep_ms_fdmi_iocb
= qla24xx_prep_ms_fdmi_iocb
,
2307 .read_nvram
= qla24xx_read_nvram_data
,
2308 .write_nvram
= qla24xx_write_nvram_data
,
2309 .fw_dump
= qla82xx_fw_dump
,
2310 .beacon_on
= qla82xx_beacon_on
,
2311 .beacon_off
= qla82xx_beacon_off
,
2312 .beacon_blink
= NULL
,
2313 .read_optrom
= qla82xx_read_optrom_data
,
2314 .write_optrom
= qla82xx_write_optrom_data
,
2315 .get_flash_version
= qla82xx_get_flash_version
,
2316 .start_scsi
= qla82xx_start_scsi
,
2317 .start_scsi_mq
= NULL
,
2318 .abort_isp
= qla82xx_abort_isp
,
2319 .iospace_config
= qla82xx_iospace_config
,
2320 .initialize_adapter
= qla2x00_initialize_adapter
,
2323 static struct isp_operations qla8044_isp_ops
= {
2324 .pci_config
= qla82xx_pci_config
,
2325 .reset_chip
= qla82xx_reset_chip
,
2326 .chip_diag
= qla24xx_chip_diag
,
2327 .config_rings
= qla82xx_config_rings
,
2328 .reset_adapter
= qla24xx_reset_adapter
,
2329 .nvram_config
= qla81xx_nvram_config
,
2330 .update_fw_options
= qla24xx_update_fw_options
,
2331 .load_risc
= qla82xx_load_risc
,
2332 .pci_info_str
= qla24xx_pci_info_str
,
2333 .fw_version_str
= qla24xx_fw_version_str
,
2334 .intr_handler
= qla8044_intr_handler
,
2335 .enable_intrs
= qla82xx_enable_intrs
,
2336 .disable_intrs
= qla82xx_disable_intrs
,
2337 .abort_command
= qla24xx_abort_command
,
2338 .target_reset
= qla24xx_abort_target
,
2339 .lun_reset
= qla24xx_lun_reset
,
2340 .fabric_login
= qla24xx_login_fabric
,
2341 .fabric_logout
= qla24xx_fabric_logout
,
2342 .calc_req_entries
= NULL
,
2343 .build_iocbs
= NULL
,
2344 .prep_ms_iocb
= qla24xx_prep_ms_iocb
,
2345 .prep_ms_fdmi_iocb
= qla24xx_prep_ms_fdmi_iocb
,
2347 .write_nvram
= NULL
,
2348 .fw_dump
= qla8044_fw_dump
,
2349 .beacon_on
= qla82xx_beacon_on
,
2350 .beacon_off
= qla82xx_beacon_off
,
2351 .beacon_blink
= NULL
,
2352 .read_optrom
= qla8044_read_optrom_data
,
2353 .write_optrom
= qla8044_write_optrom_data
,
2354 .get_flash_version
= qla82xx_get_flash_version
,
2355 .start_scsi
= qla82xx_start_scsi
,
2356 .start_scsi_mq
= NULL
,
2357 .abort_isp
= qla8044_abort_isp
,
2358 .iospace_config
= qla82xx_iospace_config
,
2359 .initialize_adapter
= qla2x00_initialize_adapter
,
2362 static struct isp_operations qla83xx_isp_ops
= {
2363 .pci_config
= qla25xx_pci_config
,
2364 .reset_chip
= qla24xx_reset_chip
,
2365 .chip_diag
= qla24xx_chip_diag
,
2366 .config_rings
= qla24xx_config_rings
,
2367 .reset_adapter
= qla24xx_reset_adapter
,
2368 .nvram_config
= qla81xx_nvram_config
,
2369 .update_fw_options
= qla81xx_update_fw_options
,
2370 .load_risc
= qla81xx_load_risc
,
2371 .pci_info_str
= qla24xx_pci_info_str
,
2372 .fw_version_str
= qla24xx_fw_version_str
,
2373 .intr_handler
= qla24xx_intr_handler
,
2374 .enable_intrs
= qla24xx_enable_intrs
,
2375 .disable_intrs
= qla24xx_disable_intrs
,
2376 .abort_command
= qla24xx_abort_command
,
2377 .target_reset
= qla24xx_abort_target
,
2378 .lun_reset
= qla24xx_lun_reset
,
2379 .fabric_login
= qla24xx_login_fabric
,
2380 .fabric_logout
= qla24xx_fabric_logout
,
2381 .calc_req_entries
= NULL
,
2382 .build_iocbs
= NULL
,
2383 .prep_ms_iocb
= qla24xx_prep_ms_iocb
,
2384 .prep_ms_fdmi_iocb
= qla24xx_prep_ms_fdmi_iocb
,
2386 .write_nvram
= NULL
,
2387 .fw_dump
= qla83xx_fw_dump
,
2388 .beacon_on
= qla24xx_beacon_on
,
2389 .beacon_off
= qla24xx_beacon_off
,
2390 .beacon_blink
= qla83xx_beacon_blink
,
2391 .read_optrom
= qla25xx_read_optrom_data
,
2392 .write_optrom
= qla24xx_write_optrom_data
,
2393 .get_flash_version
= qla24xx_get_flash_version
,
2394 .start_scsi
= qla24xx_dif_start_scsi
,
2395 .start_scsi_mq
= qla2xxx_dif_start_scsi_mq
,
2396 .abort_isp
= qla2x00_abort_isp
,
2397 .iospace_config
= qla83xx_iospace_config
,
2398 .initialize_adapter
= qla2x00_initialize_adapter
,
2401 static struct isp_operations qlafx00_isp_ops
= {
2402 .pci_config
= qlafx00_pci_config
,
2403 .reset_chip
= qlafx00_soft_reset
,
2404 .chip_diag
= qlafx00_chip_diag
,
2405 .config_rings
= qlafx00_config_rings
,
2406 .reset_adapter
= qlafx00_soft_reset
,
2407 .nvram_config
= NULL
,
2408 .update_fw_options
= NULL
,
2410 .pci_info_str
= qlafx00_pci_info_str
,
2411 .fw_version_str
= qlafx00_fw_version_str
,
2412 .intr_handler
= qlafx00_intr_handler
,
2413 .enable_intrs
= qlafx00_enable_intrs
,
2414 .disable_intrs
= qlafx00_disable_intrs
,
2415 .abort_command
= qla24xx_async_abort_command
,
2416 .target_reset
= qlafx00_abort_target
,
2417 .lun_reset
= qlafx00_lun_reset
,
2418 .fabric_login
= NULL
,
2419 .fabric_logout
= NULL
,
2420 .calc_req_entries
= NULL
,
2421 .build_iocbs
= NULL
,
2422 .prep_ms_iocb
= qla24xx_prep_ms_iocb
,
2423 .prep_ms_fdmi_iocb
= qla24xx_prep_ms_fdmi_iocb
,
2424 .read_nvram
= qla24xx_read_nvram_data
,
2425 .write_nvram
= qla24xx_write_nvram_data
,
2427 .beacon_on
= qla24xx_beacon_on
,
2428 .beacon_off
= qla24xx_beacon_off
,
2429 .beacon_blink
= NULL
,
2430 .read_optrom
= qla24xx_read_optrom_data
,
2431 .write_optrom
= qla24xx_write_optrom_data
,
2432 .get_flash_version
= qla24xx_get_flash_version
,
2433 .start_scsi
= qlafx00_start_scsi
,
2434 .start_scsi_mq
= NULL
,
2435 .abort_isp
= qlafx00_abort_isp
,
2436 .iospace_config
= qlafx00_iospace_config
,
2437 .initialize_adapter
= qlafx00_initialize_adapter
,
2440 static struct isp_operations qla27xx_isp_ops
= {
2441 .pci_config
= qla25xx_pci_config
,
2442 .reset_chip
= qla24xx_reset_chip
,
2443 .chip_diag
= qla24xx_chip_diag
,
2444 .config_rings
= qla24xx_config_rings
,
2445 .reset_adapter
= qla24xx_reset_adapter
,
2446 .nvram_config
= qla81xx_nvram_config
,
2447 .update_fw_options
= qla81xx_update_fw_options
,
2448 .load_risc
= qla81xx_load_risc
,
2449 .pci_info_str
= qla24xx_pci_info_str
,
2450 .fw_version_str
= qla24xx_fw_version_str
,
2451 .intr_handler
= qla24xx_intr_handler
,
2452 .enable_intrs
= qla24xx_enable_intrs
,
2453 .disable_intrs
= qla24xx_disable_intrs
,
2454 .abort_command
= qla24xx_abort_command
,
2455 .target_reset
= qla24xx_abort_target
,
2456 .lun_reset
= qla24xx_lun_reset
,
2457 .fabric_login
= qla24xx_login_fabric
,
2458 .fabric_logout
= qla24xx_fabric_logout
,
2459 .calc_req_entries
= NULL
,
2460 .build_iocbs
= NULL
,
2461 .prep_ms_iocb
= qla24xx_prep_ms_iocb
,
2462 .prep_ms_fdmi_iocb
= qla24xx_prep_ms_fdmi_iocb
,
2464 .write_nvram
= NULL
,
2465 .fw_dump
= qla27xx_fwdump
,
2466 .beacon_on
= qla24xx_beacon_on
,
2467 .beacon_off
= qla24xx_beacon_off
,
2468 .beacon_blink
= qla83xx_beacon_blink
,
2469 .read_optrom
= qla25xx_read_optrom_data
,
2470 .write_optrom
= qla24xx_write_optrom_data
,
2471 .get_flash_version
= qla24xx_get_flash_version
,
2472 .start_scsi
= qla24xx_dif_start_scsi
,
2473 .start_scsi_mq
= qla2xxx_dif_start_scsi_mq
,
2474 .abort_isp
= qla2x00_abort_isp
,
2475 .iospace_config
= qla83xx_iospace_config
,
2476 .initialize_adapter
= qla2x00_initialize_adapter
,
2480 qla2x00_set_isp_flags(struct qla_hw_data
*ha
)
2482 ha
->device_type
= DT_EXTENDED_IDS
;
2483 switch (ha
->pdev
->device
) {
2484 case PCI_DEVICE_ID_QLOGIC_ISP2100
:
2485 ha
->isp_type
|= DT_ISP2100
;
2486 ha
->device_type
&= ~DT_EXTENDED_IDS
;
2487 ha
->fw_srisc_address
= RISC_START_ADDRESS_2100
;
2489 case PCI_DEVICE_ID_QLOGIC_ISP2200
:
2490 ha
->isp_type
|= DT_ISP2200
;
2491 ha
->device_type
&= ~DT_EXTENDED_IDS
;
2492 ha
->fw_srisc_address
= RISC_START_ADDRESS_2100
;
2494 case PCI_DEVICE_ID_QLOGIC_ISP2300
:
2495 ha
->isp_type
|= DT_ISP2300
;
2496 ha
->device_type
|= DT_ZIO_SUPPORTED
;
2497 ha
->fw_srisc_address
= RISC_START_ADDRESS_2300
;
2499 case PCI_DEVICE_ID_QLOGIC_ISP2312
:
2500 ha
->isp_type
|= DT_ISP2312
;
2501 ha
->device_type
|= DT_ZIO_SUPPORTED
;
2502 ha
->fw_srisc_address
= RISC_START_ADDRESS_2300
;
2504 case PCI_DEVICE_ID_QLOGIC_ISP2322
:
2505 ha
->isp_type
|= DT_ISP2322
;
2506 ha
->device_type
|= DT_ZIO_SUPPORTED
;
2507 if (ha
->pdev
->subsystem_vendor
== 0x1028 &&
2508 ha
->pdev
->subsystem_device
== 0x0170)
2509 ha
->device_type
|= DT_OEM_001
;
2510 ha
->fw_srisc_address
= RISC_START_ADDRESS_2300
;
2512 case PCI_DEVICE_ID_QLOGIC_ISP6312
:
2513 ha
->isp_type
|= DT_ISP6312
;
2514 ha
->fw_srisc_address
= RISC_START_ADDRESS_2300
;
2516 case PCI_DEVICE_ID_QLOGIC_ISP6322
:
2517 ha
->isp_type
|= DT_ISP6322
;
2518 ha
->fw_srisc_address
= RISC_START_ADDRESS_2300
;
2520 case PCI_DEVICE_ID_QLOGIC_ISP2422
:
2521 ha
->isp_type
|= DT_ISP2422
;
2522 ha
->device_type
|= DT_ZIO_SUPPORTED
;
2523 ha
->device_type
|= DT_FWI2
;
2524 ha
->device_type
|= DT_IIDMA
;
2525 ha
->fw_srisc_address
= RISC_START_ADDRESS_2400
;
2527 case PCI_DEVICE_ID_QLOGIC_ISP2432
:
2528 ha
->isp_type
|= DT_ISP2432
;
2529 ha
->device_type
|= DT_ZIO_SUPPORTED
;
2530 ha
->device_type
|= DT_FWI2
;
2531 ha
->device_type
|= DT_IIDMA
;
2532 ha
->fw_srisc_address
= RISC_START_ADDRESS_2400
;
2534 case PCI_DEVICE_ID_QLOGIC_ISP8432
:
2535 ha
->isp_type
|= DT_ISP8432
;
2536 ha
->device_type
|= DT_ZIO_SUPPORTED
;
2537 ha
->device_type
|= DT_FWI2
;
2538 ha
->device_type
|= DT_IIDMA
;
2539 ha
->fw_srisc_address
= RISC_START_ADDRESS_2400
;
2541 case PCI_DEVICE_ID_QLOGIC_ISP5422
:
2542 ha
->isp_type
|= DT_ISP5422
;
2543 ha
->device_type
|= DT_FWI2
;
2544 ha
->fw_srisc_address
= RISC_START_ADDRESS_2400
;
2546 case PCI_DEVICE_ID_QLOGIC_ISP5432
:
2547 ha
->isp_type
|= DT_ISP5432
;
2548 ha
->device_type
|= DT_FWI2
;
2549 ha
->fw_srisc_address
= RISC_START_ADDRESS_2400
;
2551 case PCI_DEVICE_ID_QLOGIC_ISP2532
:
2552 ha
->isp_type
|= DT_ISP2532
;
2553 ha
->device_type
|= DT_ZIO_SUPPORTED
;
2554 ha
->device_type
|= DT_FWI2
;
2555 ha
->device_type
|= DT_IIDMA
;
2556 ha
->fw_srisc_address
= RISC_START_ADDRESS_2400
;
2558 case PCI_DEVICE_ID_QLOGIC_ISP8001
:
2559 ha
->isp_type
|= DT_ISP8001
;
2560 ha
->device_type
|= DT_ZIO_SUPPORTED
;
2561 ha
->device_type
|= DT_FWI2
;
2562 ha
->device_type
|= DT_IIDMA
;
2563 ha
->fw_srisc_address
= RISC_START_ADDRESS_2400
;
2565 case PCI_DEVICE_ID_QLOGIC_ISP8021
:
2566 ha
->isp_type
|= DT_ISP8021
;
2567 ha
->device_type
|= DT_ZIO_SUPPORTED
;
2568 ha
->device_type
|= DT_FWI2
;
2569 ha
->fw_srisc_address
= RISC_START_ADDRESS_2400
;
2570 /* Initialize 82XX ISP flags */
2571 qla82xx_init_flags(ha
);
2573 case PCI_DEVICE_ID_QLOGIC_ISP8044
:
2574 ha
->isp_type
|= DT_ISP8044
;
2575 ha
->device_type
|= DT_ZIO_SUPPORTED
;
2576 ha
->device_type
|= DT_FWI2
;
2577 ha
->fw_srisc_address
= RISC_START_ADDRESS_2400
;
2578 /* Initialize 82XX ISP flags */
2579 qla82xx_init_flags(ha
);
2581 case PCI_DEVICE_ID_QLOGIC_ISP2031
:
2582 ha
->isp_type
|= DT_ISP2031
;
2583 ha
->device_type
|= DT_ZIO_SUPPORTED
;
2584 ha
->device_type
|= DT_FWI2
;
2585 ha
->device_type
|= DT_IIDMA
;
2586 ha
->device_type
|= DT_T10_PI
;
2587 ha
->fw_srisc_address
= RISC_START_ADDRESS_2400
;
2589 case PCI_DEVICE_ID_QLOGIC_ISP8031
:
2590 ha
->isp_type
|= DT_ISP8031
;
2591 ha
->device_type
|= DT_ZIO_SUPPORTED
;
2592 ha
->device_type
|= DT_FWI2
;
2593 ha
->device_type
|= DT_IIDMA
;
2594 ha
->device_type
|= DT_T10_PI
;
2595 ha
->fw_srisc_address
= RISC_START_ADDRESS_2400
;
2597 case PCI_DEVICE_ID_QLOGIC_ISPF001
:
2598 ha
->isp_type
|= DT_ISPFX00
;
2600 case PCI_DEVICE_ID_QLOGIC_ISP2071
:
2601 ha
->isp_type
|= DT_ISP2071
;
2602 ha
->device_type
|= DT_ZIO_SUPPORTED
;
2603 ha
->device_type
|= DT_FWI2
;
2604 ha
->device_type
|= DT_IIDMA
;
2605 ha
->device_type
|= DT_T10_PI
;
2606 ha
->fw_srisc_address
= RISC_START_ADDRESS_2400
;
2608 case PCI_DEVICE_ID_QLOGIC_ISP2271
:
2609 ha
->isp_type
|= DT_ISP2271
;
2610 ha
->device_type
|= DT_ZIO_SUPPORTED
;
2611 ha
->device_type
|= DT_FWI2
;
2612 ha
->device_type
|= DT_IIDMA
;
2613 ha
->device_type
|= DT_T10_PI
;
2614 ha
->fw_srisc_address
= RISC_START_ADDRESS_2400
;
2616 case PCI_DEVICE_ID_QLOGIC_ISP2261
:
2617 ha
->isp_type
|= DT_ISP2261
;
2618 ha
->device_type
|= DT_ZIO_SUPPORTED
;
2619 ha
->device_type
|= DT_FWI2
;
2620 ha
->device_type
|= DT_IIDMA
;
2621 ha
->device_type
|= DT_T10_PI
;
2622 ha
->fw_srisc_address
= RISC_START_ADDRESS_2400
;
2627 ha
->port_no
= ha
->portnum
& 1;
2629 /* Get adapter physical port no from interrupt pin register. */
2630 pci_read_config_byte(ha
->pdev
, PCI_INTERRUPT_PIN
, &ha
->port_no
);
2634 ha
->port_no
= !(ha
->port_no
& 1);
2637 ql_dbg_pci(ql_dbg_init
, ha
->pdev
, 0x000b,
2638 "device_type=0x%x port=%d fw_srisc_address=0x%x.\n",
2639 ha
->device_type
, ha
->port_no
, ha
->fw_srisc_address
);
2643 qla2xxx_scan_start(struct Scsi_Host
*shost
)
2645 scsi_qla_host_t
*vha
= shost_priv(shost
);
2647 if (vha
->hw
->flags
.running_gold_fw
)
2650 set_bit(LOOP_RESYNC_NEEDED
, &vha
->dpc_flags
);
2651 set_bit(LOCAL_LOOP_UPDATE
, &vha
->dpc_flags
);
2652 set_bit(RSCN_UPDATE
, &vha
->dpc_flags
);
2653 set_bit(NPIV_CONFIG_NEEDED
, &vha
->dpc_flags
);
2657 qla2xxx_scan_finished(struct Scsi_Host
*shost
, unsigned long time
)
2659 scsi_qla_host_t
*vha
= shost_priv(shost
);
2661 if (test_bit(UNLOADING
, &vha
->dpc_flags
))
2665 if (time
> vha
->hw
->loop_reset_delay
* HZ
)
2668 return atomic_read(&vha
->loop_state
) == LOOP_READY
;
2671 static void qla2x00_iocb_work_fn(struct work_struct
*work
)
2673 struct scsi_qla_host
*vha
= container_of(work
,
2674 struct scsi_qla_host
, iocb_work
);
2677 while (!list_empty(&vha
->work_list
)) {
2678 qla2x00_do_work(vha
);
2686 * PCI driver interface
2689 qla2x00_probe_one(struct pci_dev
*pdev
, const struct pci_device_id
*id
)
2692 struct Scsi_Host
*host
;
2693 scsi_qla_host_t
*base_vha
= NULL
;
2694 struct qla_hw_data
*ha
;
2696 char fw_str
[30], wq_name
[30];
2697 struct scsi_host_template
*sht
;
2698 int bars
, mem_only
= 0;
2699 uint16_t req_length
= 0, rsp_length
= 0;
2700 struct req_que
*req
= NULL
;
2701 struct rsp_que
*rsp
= NULL
;
2704 bars
= pci_select_bars(pdev
, IORESOURCE_MEM
| IORESOURCE_IO
);
2705 sht
= &qla2xxx_driver_template
;
2706 if (pdev
->device
== PCI_DEVICE_ID_QLOGIC_ISP2422
||
2707 pdev
->device
== PCI_DEVICE_ID_QLOGIC_ISP2432
||
2708 pdev
->device
== PCI_DEVICE_ID_QLOGIC_ISP8432
||
2709 pdev
->device
== PCI_DEVICE_ID_QLOGIC_ISP5422
||
2710 pdev
->device
== PCI_DEVICE_ID_QLOGIC_ISP5432
||
2711 pdev
->device
== PCI_DEVICE_ID_QLOGIC_ISP2532
||
2712 pdev
->device
== PCI_DEVICE_ID_QLOGIC_ISP8001
||
2713 pdev
->device
== PCI_DEVICE_ID_QLOGIC_ISP8021
||
2714 pdev
->device
== PCI_DEVICE_ID_QLOGIC_ISP2031
||
2715 pdev
->device
== PCI_DEVICE_ID_QLOGIC_ISP8031
||
2716 pdev
->device
== PCI_DEVICE_ID_QLOGIC_ISPF001
||
2717 pdev
->device
== PCI_DEVICE_ID_QLOGIC_ISP8044
||
2718 pdev
->device
== PCI_DEVICE_ID_QLOGIC_ISP2071
||
2719 pdev
->device
== PCI_DEVICE_ID_QLOGIC_ISP2271
||
2720 pdev
->device
== PCI_DEVICE_ID_QLOGIC_ISP2261
) {
2721 bars
= pci_select_bars(pdev
, IORESOURCE_MEM
);
2723 ql_dbg_pci(ql_dbg_init
, pdev
, 0x0007,
2724 "Mem only adapter.\n");
2726 ql_dbg_pci(ql_dbg_init
, pdev
, 0x0008,
2727 "Bars=%d.\n", bars
);
2730 if (pci_enable_device_mem(pdev
))
2733 if (pci_enable_device(pdev
))
2737 /* This may fail but that's ok */
2738 pci_enable_pcie_error_reporting(pdev
);
2740 ha
= kzalloc(sizeof(struct qla_hw_data
), GFP_KERNEL
);
2742 ql_log_pci(ql_log_fatal
, pdev
, 0x0009,
2743 "Unable to allocate memory for ha.\n");
2744 goto disable_device
;
2746 ql_dbg_pci(ql_dbg_init
, pdev
, 0x000a,
2747 "Memory allocated for ha=%p.\n", ha
);
2749 INIT_LIST_HEAD(&ha
->tgt
.q_full_list
);
2750 spin_lock_init(&ha
->tgt
.q_full_lock
);
2751 spin_lock_init(&ha
->tgt
.sess_lock
);
2752 spin_lock_init(&ha
->tgt
.atio_lock
);
2755 /* Clear our data area */
2757 ha
->mem_only
= mem_only
;
2758 spin_lock_init(&ha
->hardware_lock
);
2759 spin_lock_init(&ha
->vport_slock
);
2760 mutex_init(&ha
->selflogin_lock
);
2761 mutex_init(&ha
->optrom_mutex
);
2763 /* Set ISP-type information. */
2764 qla2x00_set_isp_flags(ha
);
2766 /* Set EEH reset type to fundamental if required by hba */
2767 if (IS_QLA24XX(ha
) || IS_QLA25XX(ha
) || IS_QLA81XX(ha
) ||
2768 IS_QLA83XX(ha
) || IS_QLA27XX(ha
))
2769 pdev
->needs_freset
= 1;
2771 ha
->prev_topology
= 0;
2772 ha
->init_cb_size
= sizeof(init_cb_t
);
2773 ha
->link_data_rate
= PORT_SPEED_UNKNOWN
;
2774 ha
->optrom_size
= OPTROM_SIZE_2300
;
2776 /* Assign ISP specific operations. */
2777 if (IS_QLA2100(ha
)) {
2778 ha
->max_fibre_devices
= MAX_FIBRE_DEVICES_2100
;
2779 ha
->mbx_count
= MAILBOX_REGISTER_COUNT_2100
;
2780 req_length
= REQUEST_ENTRY_CNT_2100
;
2781 rsp_length
= RESPONSE_ENTRY_CNT_2100
;
2782 ha
->max_loop_id
= SNS_LAST_LOOP_ID_2100
;
2783 ha
->gid_list_info_size
= 4;
2784 ha
->flash_conf_off
= ~0;
2785 ha
->flash_data_off
= ~0;
2786 ha
->nvram_conf_off
= ~0;
2787 ha
->nvram_data_off
= ~0;
2788 ha
->isp_ops
= &qla2100_isp_ops
;
2789 } else if (IS_QLA2200(ha
)) {
2790 ha
->max_fibre_devices
= MAX_FIBRE_DEVICES_2100
;
2791 ha
->mbx_count
= MAILBOX_REGISTER_COUNT_2200
;
2792 req_length
= REQUEST_ENTRY_CNT_2200
;
2793 rsp_length
= RESPONSE_ENTRY_CNT_2100
;
2794 ha
->max_loop_id
= SNS_LAST_LOOP_ID_2100
;
2795 ha
->gid_list_info_size
= 4;
2796 ha
->flash_conf_off
= ~0;
2797 ha
->flash_data_off
= ~0;
2798 ha
->nvram_conf_off
= ~0;
2799 ha
->nvram_data_off
= ~0;
2800 ha
->isp_ops
= &qla2100_isp_ops
;
2801 } else if (IS_QLA23XX(ha
)) {
2802 ha
->max_fibre_devices
= MAX_FIBRE_DEVICES_2100
;
2803 ha
->mbx_count
= MAILBOX_REGISTER_COUNT
;
2804 req_length
= REQUEST_ENTRY_CNT_2200
;
2805 rsp_length
= RESPONSE_ENTRY_CNT_2300
;
2806 ha
->max_loop_id
= SNS_LAST_LOOP_ID_2300
;
2807 ha
->gid_list_info_size
= 6;
2808 if (IS_QLA2322(ha
) || IS_QLA6322(ha
))
2809 ha
->optrom_size
= OPTROM_SIZE_2322
;
2810 ha
->flash_conf_off
= ~0;
2811 ha
->flash_data_off
= ~0;
2812 ha
->nvram_conf_off
= ~0;
2813 ha
->nvram_data_off
= ~0;
2814 ha
->isp_ops
= &qla2300_isp_ops
;
2815 } else if (IS_QLA24XX_TYPE(ha
)) {
2816 ha
->max_fibre_devices
= MAX_FIBRE_DEVICES_2400
;
2817 ha
->mbx_count
= MAILBOX_REGISTER_COUNT
;
2818 req_length
= REQUEST_ENTRY_CNT_24XX
;
2819 rsp_length
= RESPONSE_ENTRY_CNT_2300
;
2820 ha
->tgt
.atio_q_length
= ATIO_ENTRY_CNT_24XX
;
2821 ha
->max_loop_id
= SNS_LAST_LOOP_ID_2300
;
2822 ha
->init_cb_size
= sizeof(struct mid_init_cb_24xx
);
2823 ha
->gid_list_info_size
= 8;
2824 ha
->optrom_size
= OPTROM_SIZE_24XX
;
2825 ha
->nvram_npiv_size
= QLA_MAX_VPORTS_QLA24XX
;
2826 ha
->isp_ops
= &qla24xx_isp_ops
;
2827 ha
->flash_conf_off
= FARX_ACCESS_FLASH_CONF
;
2828 ha
->flash_data_off
= FARX_ACCESS_FLASH_DATA
;
2829 ha
->nvram_conf_off
= FARX_ACCESS_NVRAM_CONF
;
2830 ha
->nvram_data_off
= FARX_ACCESS_NVRAM_DATA
;
2831 } else if (IS_QLA25XX(ha
)) {
2832 ha
->max_fibre_devices
= MAX_FIBRE_DEVICES_2400
;
2833 ha
->mbx_count
= MAILBOX_REGISTER_COUNT
;
2834 req_length
= REQUEST_ENTRY_CNT_24XX
;
2835 rsp_length
= RESPONSE_ENTRY_CNT_2300
;
2836 ha
->tgt
.atio_q_length
= ATIO_ENTRY_CNT_24XX
;
2837 ha
->max_loop_id
= SNS_LAST_LOOP_ID_2300
;
2838 ha
->init_cb_size
= sizeof(struct mid_init_cb_24xx
);
2839 ha
->gid_list_info_size
= 8;
2840 ha
->optrom_size
= OPTROM_SIZE_25XX
;
2841 ha
->nvram_npiv_size
= QLA_MAX_VPORTS_QLA25XX
;
2842 ha
->isp_ops
= &qla25xx_isp_ops
;
2843 ha
->flash_conf_off
= FARX_ACCESS_FLASH_CONF
;
2844 ha
->flash_data_off
= FARX_ACCESS_FLASH_DATA
;
2845 ha
->nvram_conf_off
= FARX_ACCESS_NVRAM_CONF
;
2846 ha
->nvram_data_off
= FARX_ACCESS_NVRAM_DATA
;
2847 } else if (IS_QLA81XX(ha
)) {
2848 ha
->max_fibre_devices
= MAX_FIBRE_DEVICES_2400
;
2849 ha
->mbx_count
= MAILBOX_REGISTER_COUNT
;
2850 req_length
= REQUEST_ENTRY_CNT_24XX
;
2851 rsp_length
= RESPONSE_ENTRY_CNT_2300
;
2852 ha
->tgt
.atio_q_length
= ATIO_ENTRY_CNT_24XX
;
2853 ha
->max_loop_id
= SNS_LAST_LOOP_ID_2300
;
2854 ha
->init_cb_size
= sizeof(struct mid_init_cb_81xx
);
2855 ha
->gid_list_info_size
= 8;
2856 ha
->optrom_size
= OPTROM_SIZE_81XX
;
2857 ha
->nvram_npiv_size
= QLA_MAX_VPORTS_QLA25XX
;
2858 ha
->isp_ops
= &qla81xx_isp_ops
;
2859 ha
->flash_conf_off
= FARX_ACCESS_FLASH_CONF_81XX
;
2860 ha
->flash_data_off
= FARX_ACCESS_FLASH_DATA_81XX
;
2861 ha
->nvram_conf_off
= ~0;
2862 ha
->nvram_data_off
= ~0;
2863 } else if (IS_QLA82XX(ha
)) {
2864 ha
->max_fibre_devices
= MAX_FIBRE_DEVICES_2400
;
2865 ha
->mbx_count
= MAILBOX_REGISTER_COUNT
;
2866 req_length
= REQUEST_ENTRY_CNT_82XX
;
2867 rsp_length
= RESPONSE_ENTRY_CNT_82XX
;
2868 ha
->max_loop_id
= SNS_LAST_LOOP_ID_2300
;
2869 ha
->init_cb_size
= sizeof(struct mid_init_cb_81xx
);
2870 ha
->gid_list_info_size
= 8;
2871 ha
->optrom_size
= OPTROM_SIZE_82XX
;
2872 ha
->nvram_npiv_size
= QLA_MAX_VPORTS_QLA25XX
;
2873 ha
->isp_ops
= &qla82xx_isp_ops
;
2874 ha
->flash_conf_off
= FARX_ACCESS_FLASH_CONF
;
2875 ha
->flash_data_off
= FARX_ACCESS_FLASH_DATA
;
2876 ha
->nvram_conf_off
= FARX_ACCESS_NVRAM_CONF
;
2877 ha
->nvram_data_off
= FARX_ACCESS_NVRAM_DATA
;
2878 } else if (IS_QLA8044(ha
)) {
2879 ha
->max_fibre_devices
= MAX_FIBRE_DEVICES_2400
;
2880 ha
->mbx_count
= MAILBOX_REGISTER_COUNT
;
2881 req_length
= REQUEST_ENTRY_CNT_82XX
;
2882 rsp_length
= RESPONSE_ENTRY_CNT_82XX
;
2883 ha
->max_loop_id
= SNS_LAST_LOOP_ID_2300
;
2884 ha
->init_cb_size
= sizeof(struct mid_init_cb_81xx
);
2885 ha
->gid_list_info_size
= 8;
2886 ha
->optrom_size
= OPTROM_SIZE_83XX
;
2887 ha
->nvram_npiv_size
= QLA_MAX_VPORTS_QLA25XX
;
2888 ha
->isp_ops
= &qla8044_isp_ops
;
2889 ha
->flash_conf_off
= FARX_ACCESS_FLASH_CONF
;
2890 ha
->flash_data_off
= FARX_ACCESS_FLASH_DATA
;
2891 ha
->nvram_conf_off
= FARX_ACCESS_NVRAM_CONF
;
2892 ha
->nvram_data_off
= FARX_ACCESS_NVRAM_DATA
;
2893 } else if (IS_QLA83XX(ha
)) {
2894 ha
->portnum
= PCI_FUNC(ha
->pdev
->devfn
);
2895 ha
->max_fibre_devices
= MAX_FIBRE_DEVICES_2400
;
2896 ha
->mbx_count
= MAILBOX_REGISTER_COUNT
;
2897 req_length
= REQUEST_ENTRY_CNT_83XX
;
2898 rsp_length
= RESPONSE_ENTRY_CNT_83XX
;
2899 ha
->tgt
.atio_q_length
= ATIO_ENTRY_CNT_24XX
;
2900 ha
->max_loop_id
= SNS_LAST_LOOP_ID_2300
;
2901 ha
->init_cb_size
= sizeof(struct mid_init_cb_81xx
);
2902 ha
->gid_list_info_size
= 8;
2903 ha
->optrom_size
= OPTROM_SIZE_83XX
;
2904 ha
->nvram_npiv_size
= QLA_MAX_VPORTS_QLA25XX
;
2905 ha
->isp_ops
= &qla83xx_isp_ops
;
2906 ha
->flash_conf_off
= FARX_ACCESS_FLASH_CONF_81XX
;
2907 ha
->flash_data_off
= FARX_ACCESS_FLASH_DATA_81XX
;
2908 ha
->nvram_conf_off
= ~0;
2909 ha
->nvram_data_off
= ~0;
2910 } else if (IS_QLAFX00(ha
)) {
2911 ha
->max_fibre_devices
= MAX_FIBRE_DEVICES_FX00
;
2912 ha
->mbx_count
= MAILBOX_REGISTER_COUNT_FX00
;
2913 ha
->aen_mbx_count
= AEN_MAILBOX_REGISTER_COUNT_FX00
;
2914 req_length
= REQUEST_ENTRY_CNT_FX00
;
2915 rsp_length
= RESPONSE_ENTRY_CNT_FX00
;
2916 ha
->isp_ops
= &qlafx00_isp_ops
;
2917 ha
->port_down_retry_count
= 30; /* default value */
2918 ha
->mr
.fw_hbt_cnt
= QLAFX00_HEARTBEAT_INTERVAL
;
2919 ha
->mr
.fw_reset_timer_tick
= QLAFX00_RESET_INTERVAL
;
2920 ha
->mr
.fw_critemp_timer_tick
= QLAFX00_CRITEMP_INTERVAL
;
2921 ha
->mr
.fw_hbt_en
= 1;
2922 ha
->mr
.host_info_resend
= false;
2923 ha
->mr
.hinfo_resend_timer_tick
= QLAFX00_HINFO_RESEND_INTERVAL
;
2924 } else if (IS_QLA27XX(ha
)) {
2925 ha
->portnum
= PCI_FUNC(ha
->pdev
->devfn
);
2926 ha
->max_fibre_devices
= MAX_FIBRE_DEVICES_2400
;
2927 ha
->mbx_count
= MAILBOX_REGISTER_COUNT
;
2928 req_length
= REQUEST_ENTRY_CNT_83XX
;
2929 rsp_length
= RESPONSE_ENTRY_CNT_83XX
;
2930 ha
->tgt
.atio_q_length
= ATIO_ENTRY_CNT_24XX
;
2931 ha
->max_loop_id
= SNS_LAST_LOOP_ID_2300
;
2932 ha
->init_cb_size
= sizeof(struct mid_init_cb_81xx
);
2933 ha
->gid_list_info_size
= 8;
2934 ha
->optrom_size
= OPTROM_SIZE_83XX
;
2935 ha
->nvram_npiv_size
= QLA_MAX_VPORTS_QLA25XX
;
2936 ha
->isp_ops
= &qla27xx_isp_ops
;
2937 ha
->flash_conf_off
= FARX_ACCESS_FLASH_CONF_81XX
;
2938 ha
->flash_data_off
= FARX_ACCESS_FLASH_DATA_81XX
;
2939 ha
->nvram_conf_off
= ~0;
2940 ha
->nvram_data_off
= ~0;
2943 ql_dbg_pci(ql_dbg_init
, pdev
, 0x001e,
2944 "mbx_count=%d, req_length=%d, "
2945 "rsp_length=%d, max_loop_id=%d, init_cb_size=%d, "
2946 "gid_list_info_size=%d, optrom_size=%d, nvram_npiv_size=%d, "
2947 "max_fibre_devices=%d.\n",
2948 ha
->mbx_count
, req_length
, rsp_length
, ha
->max_loop_id
,
2949 ha
->init_cb_size
, ha
->gid_list_info_size
, ha
->optrom_size
,
2950 ha
->nvram_npiv_size
, ha
->max_fibre_devices
);
2951 ql_dbg_pci(ql_dbg_init
, pdev
, 0x001f,
2952 "isp_ops=%p, flash_conf_off=%d, "
2953 "flash_data_off=%d, nvram_conf_off=%d, nvram_data_off=%d.\n",
2954 ha
->isp_ops
, ha
->flash_conf_off
, ha
->flash_data_off
,
2955 ha
->nvram_conf_off
, ha
->nvram_data_off
);
2957 /* Configure PCI I/O space */
2958 ret
= ha
->isp_ops
->iospace_config(ha
);
2960 goto iospace_config_failed
;
2962 ql_log_pci(ql_log_info
, pdev
, 0x001d,
2963 "Found an ISP%04X irq %d iobase 0x%p.\n",
2964 pdev
->device
, pdev
->irq
, ha
->iobase
);
2965 mutex_init(&ha
->vport_lock
);
2966 mutex_init(&ha
->mq_lock
);
2967 init_completion(&ha
->mbx_cmd_comp
);
2968 complete(&ha
->mbx_cmd_comp
);
2969 init_completion(&ha
->mbx_intr_comp
);
2970 init_completion(&ha
->dcbx_comp
);
2971 init_completion(&ha
->lb_portup_comp
);
2973 set_bit(0, (unsigned long *) ha
->vp_idx_map
);
2975 qla2x00_config_dma_addressing(ha
);
2976 ql_dbg_pci(ql_dbg_init
, pdev
, 0x0020,
2977 "64 Bit addressing is %s.\n",
2978 ha
->flags
.enable_64bit_addressing
? "enable" :
2980 ret
= qla2x00_mem_alloc(ha
, req_length
, rsp_length
, &req
, &rsp
);
2982 ql_log_pci(ql_log_fatal
, pdev
, 0x0031,
2983 "Failed to allocate memory for adapter, aborting.\n");
2985 goto probe_hw_failed
;
2988 req
->max_q_depth
= MAX_Q_DEPTH
;
2989 if (ql2xmaxqdepth
!= 0 && ql2xmaxqdepth
<= 0xffffU
)
2990 req
->max_q_depth
= ql2xmaxqdepth
;
2993 base_vha
= qla2x00_create_host(sht
, ha
);
2996 qla2x00_mem_free(ha
);
2997 qla2x00_free_req_que(ha
, req
);
2998 qla2x00_free_rsp_que(ha
, rsp
);
2999 goto probe_hw_failed
;
3002 pci_set_drvdata(pdev
, base_vha
);
3003 set_bit(PFLG_DRIVER_PROBING
, &base_vha
->pci_flags
);
3005 host
= base_vha
->host
;
3006 base_vha
->req
= req
;
3007 if (IS_QLA2XXX_MIDTYPE(ha
))
3008 base_vha
->mgmt_svr_loop_id
= 10 + base_vha
->vp_idx
;
3010 base_vha
->mgmt_svr_loop_id
= MANAGEMENT_SERVER
+
3013 /* Setup fcport template structure. */
3014 ha
->mr
.fcport
.vha
= base_vha
;
3015 ha
->mr
.fcport
.port_type
= FCT_UNKNOWN
;
3016 ha
->mr
.fcport
.loop_id
= FC_NO_LOOP_ID
;
3017 qla2x00_set_fcport_state(&ha
->mr
.fcport
, FCS_UNCONFIGURED
);
3018 ha
->mr
.fcport
.supported_classes
= FC_COS_UNSPECIFIED
;
3019 ha
->mr
.fcport
.scan_state
= 1;
3021 /* Set the SG table size based on ISP type */
3022 if (!IS_FWI2_CAPABLE(ha
)) {
3024 host
->sg_tablesize
= 32;
3026 if (!IS_QLA82XX(ha
))
3027 host
->sg_tablesize
= QLA_SG_ALL
;
3029 host
->max_id
= ha
->max_fibre_devices
;
3030 host
->cmd_per_lun
= 3;
3031 host
->unique_id
= host
->host_no
;
3032 if (IS_T10_PI_CAPABLE(ha
) && ql2xenabledif
)
3033 host
->max_cmd_len
= 32;
3035 host
->max_cmd_len
= MAX_CMDSZ
;
3036 host
->max_channel
= MAX_BUSES
- 1;
3037 /* Older HBAs support only 16-bit LUNs */
3038 if (!IS_QLAFX00(ha
) && !IS_FWI2_CAPABLE(ha
) &&
3039 ql2xmaxlun
> 0xffff)
3040 host
->max_lun
= 0xffff;
3042 host
->max_lun
= ql2xmaxlun
;
3043 host
->transportt
= qla2xxx_transport_template
;
3044 sht
->vendor_id
= (SCSI_NL_VID_TYPE_PCI
| PCI_VENDOR_ID_QLOGIC
);
3046 ql_dbg(ql_dbg_init
, base_vha
, 0x0033,
3047 "max_id=%d this_id=%d "
3048 "cmd_per_len=%d unique_id=%d max_cmd_len=%d max_channel=%d "
3049 "max_lun=%llu transportt=%p, vendor_id=%llu.\n", host
->max_id
,
3050 host
->this_id
, host
->cmd_per_lun
, host
->unique_id
,
3051 host
->max_cmd_len
, host
->max_channel
, host
->max_lun
,
3052 host
->transportt
, sht
->vendor_id
);
3054 /* Set up the irqs */
3055 ret
= qla2x00_request_irqs(ha
, rsp
);
3057 goto probe_init_failed
;
3059 /* Alloc arrays of request and response ring ptrs */
3060 if (!qla2x00_alloc_queues(ha
, req
, rsp
)) {
3061 ql_log(ql_log_fatal
, base_vha
, 0x003d,
3062 "Failed to allocate memory for queue pointers..."
3064 goto probe_init_failed
;
3067 if (ha
->mqenable
&& shost_use_blk_mq(host
)) {
3068 /* number of hardware queues supported by blk/scsi-mq*/
3069 host
->nr_hw_queues
= ha
->max_qpairs
;
3071 ql_dbg(ql_dbg_init
, base_vha
, 0x0192,
3072 "blk/scsi-mq enabled, HW queues = %d.\n", host
->nr_hw_queues
);
3074 ql_dbg(ql_dbg_init
, base_vha
, 0x0193,
3075 "blk/scsi-mq disabled.\n");
3077 qlt_probe_one_stage1(base_vha
, ha
);
3079 pci_save_state(pdev
);
3081 /* Assign back pointers */
3085 if (IS_QLAFX00(ha
)) {
3086 ha
->rsp_q_map
[0] = rsp
;
3087 ha
->req_q_map
[0] = req
;
3088 set_bit(0, ha
->req_qid_map
);
3089 set_bit(0, ha
->rsp_qid_map
);
3092 /* FWI2-capable only. */
3093 req
->req_q_in
= &ha
->iobase
->isp24
.req_q_in
;
3094 req
->req_q_out
= &ha
->iobase
->isp24
.req_q_out
;
3095 rsp
->rsp_q_in
= &ha
->iobase
->isp24
.rsp_q_in
;
3096 rsp
->rsp_q_out
= &ha
->iobase
->isp24
.rsp_q_out
;
3097 if (ha
->mqenable
|| IS_QLA83XX(ha
) || IS_QLA27XX(ha
)) {
3098 req
->req_q_in
= &ha
->mqiobase
->isp25mq
.req_q_in
;
3099 req
->req_q_out
= &ha
->mqiobase
->isp25mq
.req_q_out
;
3100 rsp
->rsp_q_in
= &ha
->mqiobase
->isp25mq
.rsp_q_in
;
3101 rsp
->rsp_q_out
= &ha
->mqiobase
->isp25mq
.rsp_q_out
;
3104 if (IS_QLAFX00(ha
)) {
3105 req
->req_q_in
= &ha
->iobase
->ispfx00
.req_q_in
;
3106 req
->req_q_out
= &ha
->iobase
->ispfx00
.req_q_out
;
3107 rsp
->rsp_q_in
= &ha
->iobase
->ispfx00
.rsp_q_in
;
3108 rsp
->rsp_q_out
= &ha
->iobase
->ispfx00
.rsp_q_out
;
3111 if (IS_P3P_TYPE(ha
)) {
3112 req
->req_q_out
= &ha
->iobase
->isp82
.req_q_out
[0];
3113 rsp
->rsp_q_in
= &ha
->iobase
->isp82
.rsp_q_in
[0];
3114 rsp
->rsp_q_out
= &ha
->iobase
->isp82
.rsp_q_out
[0];
3117 ql_dbg(ql_dbg_multiq
, base_vha
, 0xc009,
3118 "rsp_q_map=%p req_q_map=%p rsp->req=%p req->rsp=%p.\n",
3119 ha
->rsp_q_map
, ha
->req_q_map
, rsp
->req
, req
->rsp
);
3120 ql_dbg(ql_dbg_multiq
, base_vha
, 0xc00a,
3121 "req->req_q_in=%p req->req_q_out=%p "
3122 "rsp->rsp_q_in=%p rsp->rsp_q_out=%p.\n",
3123 req
->req_q_in
, req
->req_q_out
,
3124 rsp
->rsp_q_in
, rsp
->rsp_q_out
);
3125 ql_dbg(ql_dbg_init
, base_vha
, 0x003e,
3126 "rsp_q_map=%p req_q_map=%p rsp->req=%p req->rsp=%p.\n",
3127 ha
->rsp_q_map
, ha
->req_q_map
, rsp
->req
, req
->rsp
);
3128 ql_dbg(ql_dbg_init
, base_vha
, 0x003f,
3129 "req->req_q_in=%p req->req_q_out=%p rsp->rsp_q_in=%p rsp->rsp_q_out=%p.\n",
3130 req
->req_q_in
, req
->req_q_out
, rsp
->rsp_q_in
, rsp
->rsp_q_out
);
3132 if (ha
->isp_ops
->initialize_adapter(base_vha
)) {
3133 ql_log(ql_log_fatal
, base_vha
, 0x00d6,
3134 "Failed to initialize adapter - Adapter flags %x.\n",
3135 base_vha
->device_flags
);
3137 if (IS_QLA82XX(ha
)) {
3138 qla82xx_idc_lock(ha
);
3139 qla82xx_wr_32(ha
, QLA82XX_CRB_DEV_STATE
,
3140 QLA8XXX_DEV_FAILED
);
3141 qla82xx_idc_unlock(ha
);
3142 ql_log(ql_log_fatal
, base_vha
, 0x00d7,
3143 "HW State: FAILED.\n");
3144 } else if (IS_QLA8044(ha
)) {
3145 qla8044_idc_lock(ha
);
3146 qla8044_wr_direct(base_vha
,
3147 QLA8044_CRB_DEV_STATE_INDEX
,
3148 QLA8XXX_DEV_FAILED
);
3149 qla8044_idc_unlock(ha
);
3150 ql_log(ql_log_fatal
, base_vha
, 0x0150,
3151 "HW State: FAILED.\n");
3159 host
->can_queue
= QLAFX00_MAX_CANQUEUE
;
3161 host
->can_queue
= req
->num_outstanding_cmds
- 10;
3163 ql_dbg(ql_dbg_init
, base_vha
, 0x0032,
3164 "can_queue=%d, req=%p, mgmt_svr_loop_id=%d, sg_tablesize=%d.\n",
3165 host
->can_queue
, base_vha
->req
,
3166 base_vha
->mgmt_svr_loop_id
, host
->sg_tablesize
);
3170 bool startit
= false;
3171 ha
->wq
= alloc_workqueue("qla2xxx_wq", WQ_MEM_RECLAIM
, 1);
3173 if (QLA_TGT_MODE_ENABLED()) {
3178 if ((ql2x_ini_mode
== QLA2XXX_INI_MODE_ENABLED
) &&
3179 shost_use_blk_mq(host
)) {
3185 /* Create start of day qpairs for Block MQ */
3186 for (i
= 0; i
< ha
->max_qpairs
; i
++)
3187 qla2xxx_create_qpair(base_vha
, 5, 0, startit
);
3191 if (ha
->flags
.running_gold_fw
)
3195 * Startup the kernel thread for this host adapter
3197 ha
->dpc_thread
= kthread_create(qla2x00_do_dpc
, ha
,
3198 "%s_dpc", base_vha
->host_str
);
3199 if (IS_ERR(ha
->dpc_thread
)) {
3200 ql_log(ql_log_fatal
, base_vha
, 0x00ed,
3201 "Failed to start DPC thread.\n");
3202 ret
= PTR_ERR(ha
->dpc_thread
);
3205 ql_dbg(ql_dbg_init
, base_vha
, 0x00ee,
3206 "DPC thread started successfully.\n");
3209 * If we're not coming up in initiator mode, we might sit for
3210 * a while without waking up the dpc thread, which leads to a
3211 * stuck process warning. So just kick the dpc once here and
3212 * let the kthread start (and go back to sleep in qla2x00_do_dpc).
3214 qla2xxx_wake_dpc(base_vha
);
3216 INIT_WORK(&base_vha
->iocb_work
, qla2x00_iocb_work_fn
);
3217 INIT_WORK(&ha
->board_disable
, qla2x00_disable_board_on_pci_error
);
3219 if (IS_QLA8031(ha
) || IS_MCTP_CAPABLE(ha
)) {
3220 sprintf(wq_name
, "qla2xxx_%lu_dpc_lp_wq", base_vha
->host_no
);
3221 ha
->dpc_lp_wq
= create_singlethread_workqueue(wq_name
);
3222 INIT_WORK(&ha
->idc_aen
, qla83xx_service_idc_aen
);
3224 sprintf(wq_name
, "qla2xxx_%lu_dpc_hp_wq", base_vha
->host_no
);
3225 ha
->dpc_hp_wq
= create_singlethread_workqueue(wq_name
);
3226 INIT_WORK(&ha
->nic_core_reset
, qla83xx_nic_core_reset_work
);
3227 INIT_WORK(&ha
->idc_state_handler
,
3228 qla83xx_idc_state_handler_work
);
3229 INIT_WORK(&ha
->nic_core_unrecoverable
,
3230 qla83xx_nic_core_unrecoverable_work
);
3234 list_add_tail(&base_vha
->list
, &ha
->vp_list
);
3235 base_vha
->host
->irq
= ha
->pdev
->irq
;
3237 /* Initialized the timer */
3238 qla2x00_start_timer(base_vha
, qla2x00_timer
, WATCH_INTERVAL
);
3239 ql_dbg(ql_dbg_init
, base_vha
, 0x00ef,
3240 "Started qla2x00_timer with "
3241 "interval=%d.\n", WATCH_INTERVAL
);
3242 ql_dbg(ql_dbg_init
, base_vha
, 0x00f0,
3243 "Detected hba at address=%p.\n",
3246 if (IS_T10_PI_CAPABLE(ha
) && ql2xenabledif
) {
3247 if (ha
->fw_attributes
& BIT_4
) {
3248 int prot
= 0, guard
;
3249 base_vha
->flags
.difdix_supported
= 1;
3250 ql_dbg(ql_dbg_init
, base_vha
, 0x00f1,
3251 "Registering for DIF/DIX type 1 and 3 protection.\n");
3252 if (ql2xenabledif
== 1)
3253 prot
= SHOST_DIX_TYPE0_PROTECTION
;
3254 scsi_host_set_prot(host
,
3255 prot
| SHOST_DIF_TYPE1_PROTECTION
3256 | SHOST_DIF_TYPE2_PROTECTION
3257 | SHOST_DIF_TYPE3_PROTECTION
3258 | SHOST_DIX_TYPE1_PROTECTION
3259 | SHOST_DIX_TYPE2_PROTECTION
3260 | SHOST_DIX_TYPE3_PROTECTION
);
3262 guard
= SHOST_DIX_GUARD_CRC
;
3264 if (IS_PI_IPGUARD_CAPABLE(ha
) &&
3265 (ql2xenabledif
> 1 || IS_PI_DIFB_DIX0_CAPABLE(ha
)))
3266 guard
|= SHOST_DIX_GUARD_IP
;
3268 scsi_host_set_guard(host
, guard
);
3270 base_vha
->flags
.difdix_supported
= 0;
3273 ha
->isp_ops
->enable_intrs(ha
);
3275 if (IS_QLAFX00(ha
)) {
3276 ret
= qlafx00_fx_disc(base_vha
,
3277 &base_vha
->hw
->mr
.fcport
, FXDISC_GET_CONFIG_INFO
);
3278 host
->sg_tablesize
= (ha
->mr
.extended_io_enabled
) ?
3282 ret
= scsi_add_host(host
, &pdev
->dev
);
3286 base_vha
->flags
.init_done
= 1;
3287 base_vha
->flags
.online
= 1;
3288 ha
->prev_minidump_failed
= 0;
3290 ql_dbg(ql_dbg_init
, base_vha
, 0x00f2,
3291 "Init done and hba is online.\n");
3293 if (qla_ini_mode_enabled(base_vha
) ||
3294 qla_dual_mode_enabled(base_vha
))
3295 scsi_scan_host(host
);
3297 ql_dbg(ql_dbg_init
, base_vha
, 0x0122,
3298 "skipping scsi_scan_host() for non-initiator port\n");
3300 qla2x00_alloc_sysfs_attr(base_vha
);
3302 if (IS_QLAFX00(ha
)) {
3303 ret
= qlafx00_fx_disc(base_vha
,
3304 &base_vha
->hw
->mr
.fcport
, FXDISC_GET_PORT_INFO
);
3306 /* Register system information */
3307 ret
= qlafx00_fx_disc(base_vha
,
3308 &base_vha
->hw
->mr
.fcport
, FXDISC_REG_HOST_INFO
);
3311 qla2x00_init_host_attr(base_vha
);
3313 qla2x00_dfs_setup(base_vha
);
3315 ql_log(ql_log_info
, base_vha
, 0x00fb,
3316 "QLogic %s - %s.\n", ha
->model_number
, ha
->model_desc
);
3317 ql_log(ql_log_info
, base_vha
, 0x00fc,
3318 "ISP%04X: %s @ %s hdma%c host#=%ld fw=%s.\n",
3319 pdev
->device
, ha
->isp_ops
->pci_info_str(base_vha
, pci_info
),
3320 pci_name(pdev
), ha
->flags
.enable_64bit_addressing
? '+' : '-',
3322 ha
->isp_ops
->fw_version_str(base_vha
, fw_str
, sizeof(fw_str
)));
3324 qlt_add_target(ha
, base_vha
);
3326 clear_bit(PFLG_DRIVER_PROBING
, &base_vha
->pci_flags
);
3328 if (test_bit(UNLOADING
, &base_vha
->dpc_flags
))
3334 qla2x00_free_req_que(ha
, req
);
3335 ha
->req_q_map
[0] = NULL
;
3336 clear_bit(0, ha
->req_qid_map
);
3337 qla2x00_free_rsp_que(ha
, rsp
);
3338 ha
->rsp_q_map
[0] = NULL
;
3339 clear_bit(0, ha
->rsp_qid_map
);
3340 ha
->max_req_queues
= ha
->max_rsp_queues
= 0;
3343 if (base_vha
->timer_active
)
3344 qla2x00_stop_timer(base_vha
);
3345 base_vha
->flags
.online
= 0;
3346 if (ha
->dpc_thread
) {
3347 struct task_struct
*t
= ha
->dpc_thread
;
3349 ha
->dpc_thread
= NULL
;
3353 qla2x00_free_device(base_vha
);
3355 scsi_host_put(base_vha
->host
);
3358 qla2x00_clear_drv_active(ha
);
3360 iospace_config_failed
:
3361 if (IS_P3P_TYPE(ha
)) {
3362 if (!ha
->nx_pcibase
)
3363 iounmap((device_reg_t
*)ha
->nx_pcibase
);
3365 iounmap((device_reg_t
*)ha
->nxdb_wr_ptr
);
3368 iounmap(ha
->iobase
);
3370 iounmap(ha
->cregbase
);
3372 pci_release_selected_regions(ha
->pdev
, ha
->bars
);
3376 pci_disable_device(pdev
);
3381 qla2x00_shutdown(struct pci_dev
*pdev
)
3383 scsi_qla_host_t
*vha
;
3384 struct qla_hw_data
*ha
;
3386 if (!atomic_read(&pdev
->enable_cnt
))
3389 vha
= pci_get_drvdata(pdev
);
3392 /* Notify ISPFX00 firmware */
3394 qlafx00_driver_shutdown(vha
, 20);
3396 /* Turn-off FCE trace */
3397 if (ha
->flags
.fce_enabled
) {
3398 qla2x00_disable_fce_trace(vha
, NULL
, NULL
);
3399 ha
->flags
.fce_enabled
= 0;
3402 /* Turn-off EFT trace */
3404 qla2x00_disable_eft_trace(vha
);
3406 /* Stop currently executing firmware. */
3407 qla2x00_try_to_stop_firmware(vha
);
3409 /* Turn adapter off line */
3410 vha
->flags
.online
= 0;
3412 /* turn-off interrupts on the card */
3413 if (ha
->interrupts_on
) {
3414 vha
->flags
.init_done
= 0;
3415 ha
->isp_ops
->disable_intrs(ha
);
3418 qla2x00_free_irqs(vha
);
3420 qla2x00_free_fw_dump(ha
);
3422 pci_disable_pcie_error_reporting(pdev
);
3423 pci_disable_device(pdev
);
3426 /* Deletes all the virtual ports for a given ha */
3428 qla2x00_delete_all_vps(struct qla_hw_data
*ha
, scsi_qla_host_t
*base_vha
)
3430 scsi_qla_host_t
*vha
;
3431 unsigned long flags
;
3433 mutex_lock(&ha
->vport_lock
);
3434 while (ha
->cur_vport_count
) {
3435 spin_lock_irqsave(&ha
->vport_slock
, flags
);
3437 BUG_ON(base_vha
->list
.next
== &ha
->vp_list
);
3438 /* This assumes first entry in ha->vp_list is always base vha */
3439 vha
= list_first_entry(&base_vha
->list
, scsi_qla_host_t
, list
);
3440 scsi_host_get(vha
->host
);
3442 spin_unlock_irqrestore(&ha
->vport_slock
, flags
);
3443 mutex_unlock(&ha
->vport_lock
);
3445 fc_vport_terminate(vha
->fc_vport
);
3446 scsi_host_put(vha
->host
);
3448 mutex_lock(&ha
->vport_lock
);
3450 mutex_unlock(&ha
->vport_lock
);
3453 /* Stops all deferred work threads */
3455 qla2x00_destroy_deferred_work(struct qla_hw_data
*ha
)
3457 /* Cancel all work and destroy DPC workqueues */
3458 if (ha
->dpc_lp_wq
) {
3459 cancel_work_sync(&ha
->idc_aen
);
3460 destroy_workqueue(ha
->dpc_lp_wq
);
3461 ha
->dpc_lp_wq
= NULL
;
3464 if (ha
->dpc_hp_wq
) {
3465 cancel_work_sync(&ha
->nic_core_reset
);
3466 cancel_work_sync(&ha
->idc_state_handler
);
3467 cancel_work_sync(&ha
->nic_core_unrecoverable
);
3468 destroy_workqueue(ha
->dpc_hp_wq
);
3469 ha
->dpc_hp_wq
= NULL
;
3472 /* Kill the kernel thread for this host */
3473 if (ha
->dpc_thread
) {
3474 struct task_struct
*t
= ha
->dpc_thread
;
3477 * qla2xxx_wake_dpc checks for ->dpc_thread
3478 * so we need to zero it out.
3480 ha
->dpc_thread
= NULL
;
3486 qla2x00_unmap_iobases(struct qla_hw_data
*ha
)
3488 if (IS_QLA82XX(ha
)) {
3490 iounmap((device_reg_t
*)ha
->nx_pcibase
);
3492 iounmap((device_reg_t
*)ha
->nxdb_wr_ptr
);
3495 iounmap(ha
->iobase
);
3498 iounmap(ha
->cregbase
);
3501 iounmap(ha
->mqiobase
);
3503 if ((IS_QLA83XX(ha
) || IS_QLA27XX(ha
)) && ha
->msixbase
)
3504 iounmap(ha
->msixbase
);
3509 qla2x00_clear_drv_active(struct qla_hw_data
*ha
)
3511 if (IS_QLA8044(ha
)) {
3512 qla8044_idc_lock(ha
);
3513 qla8044_clear_drv_active(ha
);
3514 qla8044_idc_unlock(ha
);
3515 } else if (IS_QLA82XX(ha
)) {
3516 qla82xx_idc_lock(ha
);
3517 qla82xx_clear_drv_active(ha
);
3518 qla82xx_idc_unlock(ha
);
3523 qla2x00_remove_one(struct pci_dev
*pdev
)
3525 scsi_qla_host_t
*base_vha
;
3526 struct qla_hw_data
*ha
;
3528 base_vha
= pci_get_drvdata(pdev
);
3531 /* Indicate device removal to prevent future board_disable and wait
3532 * until any pending board_disable has completed. */
3533 set_bit(PFLG_DRIVER_REMOVING
, &base_vha
->pci_flags
);
3534 cancel_work_sync(&ha
->board_disable
);
3537 * If the PCI device is disabled then there was a PCI-disconnect and
3538 * qla2x00_disable_board_on_pci_error has taken care of most of the
3541 if (!atomic_read(&pdev
->enable_cnt
)) {
3542 dma_free_coherent(&ha
->pdev
->dev
, base_vha
->gnl
.size
,
3543 base_vha
->gnl
.l
, base_vha
->gnl
.ldma
);
3545 scsi_host_put(base_vha
->host
);
3547 pci_set_drvdata(pdev
, NULL
);
3550 qla2x00_wait_for_hba_ready(base_vha
);
3553 * if UNLOAD flag is already set, then continue unload,
3554 * where it was set first.
3556 if (test_bit(UNLOADING
, &base_vha
->dpc_flags
))
3559 set_bit(UNLOADING
, &base_vha
->dpc_flags
);
3561 qla_nvme_delete(base_vha
);
3563 dma_free_coherent(&ha
->pdev
->dev
,
3564 base_vha
->gnl
.size
, base_vha
->gnl
.l
, base_vha
->gnl
.ldma
);
3567 qlafx00_driver_shutdown(base_vha
, 20);
3569 qla2x00_delete_all_vps(ha
, base_vha
);
3571 if (IS_QLA8031(ha
)) {
3572 ql_dbg(ql_dbg_p3p
, base_vha
, 0xb07e,
3573 "Clearing fcoe driver presence.\n");
3574 if (qla83xx_clear_drv_presence(base_vha
) != QLA_SUCCESS
)
3575 ql_dbg(ql_dbg_p3p
, base_vha
, 0xb079,
3576 "Error while clearing DRV-Presence.\n");
3579 qla2x00_abort_all_cmds(base_vha
, DID_NO_CONNECT
<< 16);
3581 qla2x00_dfs_remove(base_vha
);
3583 qla84xx_put_chip(base_vha
);
3585 /* Laser should be disabled only for ISP2031 */
3587 qla83xx_disable_laser(base_vha
);
3590 if (base_vha
->timer_active
)
3591 qla2x00_stop_timer(base_vha
);
3593 base_vha
->flags
.online
= 0;
3595 /* free DMA memory */
3596 if (ha
->exlogin_buf
)
3597 qla2x00_free_exlogin_buffer(ha
);
3599 /* free DMA memory */
3600 if (ha
->exchoffld_buf
)
3601 qla2x00_free_exchoffld_buffer(ha
);
3603 qla2x00_destroy_deferred_work(ha
);
3605 qlt_remove_target(ha
, base_vha
);
3607 qla2x00_free_sysfs_attr(base_vha
, true);
3609 fc_remove_host(base_vha
->host
);
3610 qlt_remove_target_resources(ha
);
3612 scsi_remove_host(base_vha
->host
);
3614 qla2x00_free_device(base_vha
);
3616 qla2x00_clear_drv_active(ha
);
3618 scsi_host_put(base_vha
->host
);
3620 qla2x00_unmap_iobases(ha
);
3622 pci_release_selected_regions(ha
->pdev
, ha
->bars
);
3625 pci_disable_pcie_error_reporting(pdev
);
3627 pci_disable_device(pdev
);
3631 qla2x00_free_device(scsi_qla_host_t
*vha
)
3633 struct qla_hw_data
*ha
= vha
->hw
;
3635 qla2x00_abort_all_cmds(vha
, DID_NO_CONNECT
<< 16);
3638 if (vha
->timer_active
)
3639 qla2x00_stop_timer(vha
);
3641 qla25xx_delete_queues(vha
);
3643 if (ha
->flags
.fce_enabled
)
3644 qla2x00_disable_fce_trace(vha
, NULL
, NULL
);
3647 qla2x00_disable_eft_trace(vha
);
3649 /* Stop currently executing firmware. */
3650 qla2x00_try_to_stop_firmware(vha
);
3652 vha
->flags
.online
= 0;
3654 /* turn-off interrupts on the card */
3655 if (ha
->interrupts_on
) {
3656 vha
->flags
.init_done
= 0;
3657 ha
->isp_ops
->disable_intrs(ha
);
3660 qla2x00_free_fcports(vha
);
3662 qla2x00_free_irqs(vha
);
3664 /* Flush the work queue and remove it */
3666 flush_workqueue(ha
->wq
);
3667 destroy_workqueue(ha
->wq
);
3672 qla2x00_mem_free(ha
);
3674 qla82xx_md_free(vha
);
3676 qla2x00_free_queues(ha
);
3679 void qla2x00_free_fcports(struct scsi_qla_host
*vha
)
3681 fc_port_t
*fcport
, *tfcport
;
3683 list_for_each_entry_safe(fcport
, tfcport
, &vha
->vp_fcports
, list
) {
3684 list_del(&fcport
->list
);
3685 qla2x00_clear_loop_id(fcport
);
3691 qla2x00_schedule_rport_del(struct scsi_qla_host
*vha
, fc_port_t
*fcport
,
3694 struct fc_rport
*rport
;
3695 scsi_qla_host_t
*base_vha
;
3696 unsigned long flags
;
3701 rport
= fcport
->rport
;
3703 base_vha
= pci_get_drvdata(vha
->hw
->pdev
);
3704 spin_lock_irqsave(vha
->host
->host_lock
, flags
);
3705 fcport
->drport
= rport
;
3706 spin_unlock_irqrestore(vha
->host
->host_lock
, flags
);
3707 qlt_do_generation_tick(vha
, &base_vha
->total_fcport_update_gen
);
3708 set_bit(FCPORT_UPDATE_NEEDED
, &base_vha
->dpc_flags
);
3709 qla2xxx_wake_dpc(base_vha
);
3713 ql_dbg(ql_dbg_disc
, fcport
->vha
, 0x2109,
3714 "%s %8phN. rport %p roles %x\n",
3715 __func__
, fcport
->port_name
, rport
,
3717 fc_remote_port_delete(rport
);
3719 qlt_do_generation_tick(vha
, &now
);
3724 * qla2x00_mark_device_lost Updates fcport state when device goes offline.
3726 * Input: ha = adapter block pointer. fcport = port structure pointer.
3732 void qla2x00_mark_device_lost(scsi_qla_host_t
*vha
, fc_port_t
*fcport
,
3733 int do_login
, int defer
)
3735 if (IS_QLAFX00(vha
->hw
)) {
3736 qla2x00_set_fcport_state(fcport
, FCS_DEVICE_LOST
);
3737 qla2x00_schedule_rport_del(vha
, fcport
, defer
);
3741 if (atomic_read(&fcport
->state
) == FCS_ONLINE
&&
3742 vha
->vp_idx
== fcport
->vha
->vp_idx
) {
3743 qla2x00_set_fcport_state(fcport
, FCS_DEVICE_LOST
);
3744 qla2x00_schedule_rport_del(vha
, fcport
, defer
);
3747 * We may need to retry the login, so don't change the state of the
3748 * port but do the retries.
3750 if (atomic_read(&fcport
->state
) != FCS_DEVICE_DEAD
)
3751 qla2x00_set_fcport_state(fcport
, FCS_DEVICE_LOST
);
3756 set_bit(RELOGIN_NEEDED
, &vha
->dpc_flags
);
3758 if (fcport
->login_retry
== 0) {
3759 fcport
->login_retry
= vha
->hw
->login_retry_count
;
3761 ql_dbg(ql_dbg_disc
, vha
, 0x20a3,
3762 "Port login retry %8phN, lid 0x%04x retry cnt=%d.\n",
3763 fcport
->port_name
, fcport
->loop_id
, fcport
->login_retry
);
3768 * qla2x00_mark_all_devices_lost
3769 * Updates fcport state when device goes offline.
3772 * ha = adapter block pointer.
3773 * fcport = port structure pointer.
3781 qla2x00_mark_all_devices_lost(scsi_qla_host_t
*vha
, int defer
)
3785 ql_dbg(ql_dbg_disc
, vha
, 0x20f1,
3786 "Mark all dev lost\n");
3788 list_for_each_entry(fcport
, &vha
->vp_fcports
, list
) {
3789 fcport
->scan_state
= 0;
3790 qlt_schedule_sess_for_deletion_lock(fcport
);
3792 if (vha
->vp_idx
!= 0 && vha
->vp_idx
!= fcport
->vha
->vp_idx
)
3796 * No point in marking the device as lost, if the device is
3799 if (atomic_read(&fcport
->state
) == FCS_DEVICE_DEAD
)
3801 if (atomic_read(&fcport
->state
) == FCS_ONLINE
) {
3802 qla2x00_set_fcport_state(fcport
, FCS_DEVICE_LOST
);
3804 qla2x00_schedule_rport_del(vha
, fcport
, defer
);
3805 else if (vha
->vp_idx
== fcport
->vha
->vp_idx
)
3806 qla2x00_schedule_rport_del(vha
, fcport
, defer
);
3813 * Allocates adapter memory.
3820 qla2x00_mem_alloc(struct qla_hw_data
*ha
, uint16_t req_len
, uint16_t rsp_len
,
3821 struct req_que
**req
, struct rsp_que
**rsp
)
3825 ha
->init_cb
= dma_alloc_coherent(&ha
->pdev
->dev
, ha
->init_cb_size
,
3826 &ha
->init_cb_dma
, GFP_KERNEL
);
3830 if (qlt_mem_alloc(ha
) < 0)
3831 goto fail_free_init_cb
;
3833 ha
->gid_list
= dma_alloc_coherent(&ha
->pdev
->dev
,
3834 qla2x00_gid_list_size(ha
), &ha
->gid_list_dma
, GFP_KERNEL
);
3836 goto fail_free_tgt_mem
;
3838 ha
->srb_mempool
= mempool_create_slab_pool(SRB_MIN_REQ
, srb_cachep
);
3839 if (!ha
->srb_mempool
)
3840 goto fail_free_gid_list
;
3842 if (IS_P3P_TYPE(ha
)) {
3843 /* Allocate cache for CT6 Ctx. */
3845 ctx_cachep
= kmem_cache_create("qla2xxx_ctx",
3846 sizeof(struct ct6_dsd
), 0,
3847 SLAB_HWCACHE_ALIGN
, NULL
);
3849 goto fail_free_srb_mempool
;
3851 ha
->ctx_mempool
= mempool_create_slab_pool(SRB_MIN_REQ
,
3853 if (!ha
->ctx_mempool
)
3854 goto fail_free_srb_mempool
;
3855 ql_dbg_pci(ql_dbg_init
, ha
->pdev
, 0x0021,
3856 "ctx_cachep=%p ctx_mempool=%p.\n",
3857 ctx_cachep
, ha
->ctx_mempool
);
3860 /* Get memory for cached NVRAM */
3861 ha
->nvram
= kzalloc(MAX_NVRAM_SIZE
, GFP_KERNEL
);
3863 goto fail_free_ctx_mempool
;
3865 snprintf(name
, sizeof(name
), "%s_%d", QLA2XXX_DRIVER_NAME
,
3867 ha
->s_dma_pool
= dma_pool_create(name
, &ha
->pdev
->dev
,
3868 DMA_POOL_SIZE
, 8, 0);
3869 if (!ha
->s_dma_pool
)
3870 goto fail_free_nvram
;
3872 ql_dbg_pci(ql_dbg_init
, ha
->pdev
, 0x0022,
3873 "init_cb=%p gid_list=%p, srb_mempool=%p s_dma_pool=%p.\n",
3874 ha
->init_cb
, ha
->gid_list
, ha
->srb_mempool
, ha
->s_dma_pool
);
3876 if (IS_P3P_TYPE(ha
) || ql2xenabledif
) {
3877 ha
->dl_dma_pool
= dma_pool_create(name
, &ha
->pdev
->dev
,
3878 DSD_LIST_DMA_POOL_SIZE
, 8, 0);
3879 if (!ha
->dl_dma_pool
) {
3880 ql_log_pci(ql_log_fatal
, ha
->pdev
, 0x0023,
3881 "Failed to allocate memory for dl_dma_pool.\n");
3882 goto fail_s_dma_pool
;
3885 ha
->fcp_cmnd_dma_pool
= dma_pool_create(name
, &ha
->pdev
->dev
,
3886 FCP_CMND_DMA_POOL_SIZE
, 8, 0);
3887 if (!ha
->fcp_cmnd_dma_pool
) {
3888 ql_log_pci(ql_log_fatal
, ha
->pdev
, 0x0024,
3889 "Failed to allocate memory for fcp_cmnd_dma_pool.\n");
3890 goto fail_dl_dma_pool
;
3892 ql_dbg_pci(ql_dbg_init
, ha
->pdev
, 0x0025,
3893 "dl_dma_pool=%p fcp_cmnd_dma_pool=%p.\n",
3894 ha
->dl_dma_pool
, ha
->fcp_cmnd_dma_pool
);
3897 /* Allocate memory for SNS commands */
3898 if (IS_QLA2100(ha
) || IS_QLA2200(ha
)) {
3899 /* Get consistent memory allocated for SNS commands */
3900 ha
->sns_cmd
= dma_alloc_coherent(&ha
->pdev
->dev
,
3901 sizeof(struct sns_cmd_pkt
), &ha
->sns_cmd_dma
, GFP_KERNEL
);
3904 ql_dbg_pci(ql_dbg_init
, ha
->pdev
, 0x0026,
3905 "sns_cmd: %p.\n", ha
->sns_cmd
);
3907 /* Get consistent memory allocated for MS IOCB */
3908 ha
->ms_iocb
= dma_pool_alloc(ha
->s_dma_pool
, GFP_KERNEL
,
3912 /* Get consistent memory allocated for CT SNS commands */
3913 ha
->ct_sns
= dma_alloc_coherent(&ha
->pdev
->dev
,
3914 sizeof(struct ct_sns_pkt
), &ha
->ct_sns_dma
, GFP_KERNEL
);
3916 goto fail_free_ms_iocb
;
3917 ql_dbg_pci(ql_dbg_init
, ha
->pdev
, 0x0027,
3918 "ms_iocb=%p ct_sns=%p.\n",
3919 ha
->ms_iocb
, ha
->ct_sns
);
3922 /* Allocate memory for request ring */
3923 *req
= kzalloc(sizeof(struct req_que
), GFP_KERNEL
);
3925 ql_log_pci(ql_log_fatal
, ha
->pdev
, 0x0028,
3926 "Failed to allocate memory for req.\n");
3929 (*req
)->length
= req_len
;
3930 (*req
)->ring
= dma_alloc_coherent(&ha
->pdev
->dev
,
3931 ((*req
)->length
+ 1) * sizeof(request_t
),
3932 &(*req
)->dma
, GFP_KERNEL
);
3933 if (!(*req
)->ring
) {
3934 ql_log_pci(ql_log_fatal
, ha
->pdev
, 0x0029,
3935 "Failed to allocate memory for req_ring.\n");
3938 /* Allocate memory for response ring */
3939 *rsp
= kzalloc(sizeof(struct rsp_que
), GFP_KERNEL
);
3941 ql_log_pci(ql_log_fatal
, ha
->pdev
, 0x002a,
3942 "Failed to allocate memory for rsp.\n");
3946 (*rsp
)->length
= rsp_len
;
3947 (*rsp
)->ring
= dma_alloc_coherent(&ha
->pdev
->dev
,
3948 ((*rsp
)->length
+ 1) * sizeof(response_t
),
3949 &(*rsp
)->dma
, GFP_KERNEL
);
3950 if (!(*rsp
)->ring
) {
3951 ql_log_pci(ql_log_fatal
, ha
->pdev
, 0x002b,
3952 "Failed to allocate memory for rsp_ring.\n");
3957 ql_dbg_pci(ql_dbg_init
, ha
->pdev
, 0x002c,
3958 "req=%p req->length=%d req->ring=%p rsp=%p "
3959 "rsp->length=%d rsp->ring=%p.\n",
3960 *req
, (*req
)->length
, (*req
)->ring
, *rsp
, (*rsp
)->length
,
3962 /* Allocate memory for NVRAM data for vports */
3963 if (ha
->nvram_npiv_size
) {
3964 ha
->npiv_info
= kzalloc(sizeof(struct qla_npiv_entry
) *
3965 ha
->nvram_npiv_size
, GFP_KERNEL
);
3966 if (!ha
->npiv_info
) {
3967 ql_log_pci(ql_log_fatal
, ha
->pdev
, 0x002d,
3968 "Failed to allocate memory for npiv_info.\n");
3969 goto fail_npiv_info
;
3972 ha
->npiv_info
= NULL
;
3974 /* Get consistent memory allocated for EX-INIT-CB. */
3975 if (IS_CNA_CAPABLE(ha
) || IS_QLA2031(ha
) || IS_QLA27XX(ha
)) {
3976 ha
->ex_init_cb
= dma_pool_alloc(ha
->s_dma_pool
, GFP_KERNEL
,
3977 &ha
->ex_init_cb_dma
);
3978 if (!ha
->ex_init_cb
)
3979 goto fail_ex_init_cb
;
3980 ql_dbg_pci(ql_dbg_init
, ha
->pdev
, 0x002e,
3981 "ex_init_cb=%p.\n", ha
->ex_init_cb
);
3984 INIT_LIST_HEAD(&ha
->gbl_dsd_list
);
3986 /* Get consistent memory allocated for Async Port-Database. */
3987 if (!IS_FWI2_CAPABLE(ha
)) {
3988 ha
->async_pd
= dma_pool_alloc(ha
->s_dma_pool
, GFP_KERNEL
,
3992 ql_dbg_pci(ql_dbg_init
, ha
->pdev
, 0x002f,
3993 "async_pd=%p.\n", ha
->async_pd
);
3996 INIT_LIST_HEAD(&ha
->vp_list
);
3998 /* Allocate memory for our loop_id bitmap */
3999 ha
->loop_id_map
= kzalloc(BITS_TO_LONGS(LOOPID_MAP_SIZE
) * sizeof(long),
4001 if (!ha
->loop_id_map
)
4002 goto fail_loop_id_map
;
4004 qla2x00_set_reserved_loop_ids(ha
);
4005 ql_dbg_pci(ql_dbg_init
, ha
->pdev
, 0x0123,
4006 "loop_id_map=%p.\n", ha
->loop_id_map
);
4012 dma_pool_free(ha
->s_dma_pool
, ha
->async_pd
, ha
->async_pd_dma
);
4014 dma_pool_free(ha
->s_dma_pool
, ha
->ex_init_cb
, ha
->ex_init_cb_dma
);
4016 kfree(ha
->npiv_info
);
4018 dma_free_coherent(&ha
->pdev
->dev
, ((*rsp
)->length
+ 1) *
4019 sizeof(response_t
), (*rsp
)->ring
, (*rsp
)->dma
);
4020 (*rsp
)->ring
= NULL
;
4025 dma_free_coherent(&ha
->pdev
->dev
, ((*req
)->length
+ 1) *
4026 sizeof(request_t
), (*req
)->ring
, (*req
)->dma
);
4027 (*req
)->ring
= NULL
;
4032 dma_free_coherent(&ha
->pdev
->dev
, sizeof(struct ct_sns_pkt
),
4033 ha
->ct_sns
, ha
->ct_sns_dma
);
4037 dma_pool_free(ha
->s_dma_pool
, ha
->ms_iocb
, ha
->ms_iocb_dma
);
4039 ha
->ms_iocb_dma
= 0;
4042 dma_free_coherent(&ha
->pdev
->dev
, sizeof(struct sns_cmd_pkt
),
4043 ha
->sns_cmd
, ha
->sns_cmd_dma
);
4045 if (IS_QLA82XX(ha
) || ql2xenabledif
) {
4046 dma_pool_destroy(ha
->fcp_cmnd_dma_pool
);
4047 ha
->fcp_cmnd_dma_pool
= NULL
;
4050 if (IS_QLA82XX(ha
) || ql2xenabledif
) {
4051 dma_pool_destroy(ha
->dl_dma_pool
);
4052 ha
->dl_dma_pool
= NULL
;
4055 dma_pool_destroy(ha
->s_dma_pool
);
4056 ha
->s_dma_pool
= NULL
;
4060 fail_free_ctx_mempool
:
4061 if (ha
->ctx_mempool
)
4062 mempool_destroy(ha
->ctx_mempool
);
4063 ha
->ctx_mempool
= NULL
;
4064 fail_free_srb_mempool
:
4065 if (ha
->srb_mempool
)
4066 mempool_destroy(ha
->srb_mempool
);
4067 ha
->srb_mempool
= NULL
;
4069 dma_free_coherent(&ha
->pdev
->dev
, qla2x00_gid_list_size(ha
),
4072 ha
->gid_list
= NULL
;
4073 ha
->gid_list_dma
= 0;
4077 dma_free_coherent(&ha
->pdev
->dev
, ha
->init_cb_size
, ha
->init_cb
,
4080 ha
->init_cb_dma
= 0;
4082 ql_log(ql_log_fatal
, NULL
, 0x0030,
4083 "Memory allocation failure.\n");
4088 qla2x00_set_exlogins_buffer(scsi_qla_host_t
*vha
)
4091 uint16_t size
, max_cnt
, temp
;
4092 struct qla_hw_data
*ha
= vha
->hw
;
4094 /* Return if we don't need to alloacate any extended logins */
4098 if (!IS_EXLOGIN_OFFLD_CAPABLE(ha
))
4101 ql_log(ql_log_info
, vha
, 0xd021, "EXLOGIN count: %d.\n", ql2xexlogins
);
4103 rval
= qla_get_exlogin_status(vha
, &size
, &max_cnt
);
4104 if (rval
!= QLA_SUCCESS
) {
4105 ql_log_pci(ql_log_fatal
, ha
->pdev
, 0xd029,
4106 "Failed to get exlogin status.\n");
4110 temp
= (ql2xexlogins
> max_cnt
) ? max_cnt
: ql2xexlogins
;
4113 if (temp
!= ha
->exlogin_size
) {
4114 qla2x00_free_exlogin_buffer(ha
);
4115 ha
->exlogin_size
= temp
;
4117 ql_log(ql_log_info
, vha
, 0xd024,
4118 "EXLOGIN: max_logins=%d, portdb=0x%x, total=%d.\n",
4119 max_cnt
, size
, temp
);
4121 ql_log(ql_log_info
, vha
, 0xd025,
4122 "EXLOGIN: requested size=0x%x\n", ha
->exlogin_size
);
4124 /* Get consistent memory for extended logins */
4125 ha
->exlogin_buf
= dma_alloc_coherent(&ha
->pdev
->dev
,
4126 ha
->exlogin_size
, &ha
->exlogin_buf_dma
, GFP_KERNEL
);
4127 if (!ha
->exlogin_buf
) {
4128 ql_log_pci(ql_log_fatal
, ha
->pdev
, 0xd02a,
4129 "Failed to allocate memory for exlogin_buf_dma.\n");
4134 /* Now configure the dma buffer */
4135 rval
= qla_set_exlogin_mem_cfg(vha
, ha
->exlogin_buf_dma
);
4137 ql_log(ql_log_fatal
, vha
, 0xd033,
4138 "Setup extended login buffer ****FAILED****.\n");
4139 qla2x00_free_exlogin_buffer(ha
);
4146 * qla2x00_free_exlogin_buffer
4149 * ha = adapter block pointer
4152 qla2x00_free_exlogin_buffer(struct qla_hw_data
*ha
)
4154 if (ha
->exlogin_buf
) {
4155 dma_free_coherent(&ha
->pdev
->dev
, ha
->exlogin_size
,
4156 ha
->exlogin_buf
, ha
->exlogin_buf_dma
);
4157 ha
->exlogin_buf
= NULL
;
4158 ha
->exlogin_size
= 0;
4163 qla2x00_number_of_exch(scsi_qla_host_t
*vha
, u32
*ret_cnt
, u16 max_cnt
)
4166 *ret_cnt
= FW_DEF_EXCHANGES_CNT
;
4168 if (qla_ini_mode_enabled(vha
)) {
4169 if (ql2xiniexchg
> max_cnt
)
4170 ql2xiniexchg
= max_cnt
;
4172 if (ql2xiniexchg
> FW_DEF_EXCHANGES_CNT
)
4173 *ret_cnt
= ql2xiniexchg
;
4174 } else if (qla_tgt_mode_enabled(vha
)) {
4175 if (ql2xexchoffld
> max_cnt
)
4176 ql2xexchoffld
= max_cnt
;
4178 if (ql2xexchoffld
> FW_DEF_EXCHANGES_CNT
)
4179 *ret_cnt
= ql2xexchoffld
;
4180 } else if (qla_dual_mode_enabled(vha
)) {
4181 temp
= ql2xiniexchg
+ ql2xexchoffld
;
4182 if (temp
> max_cnt
) {
4183 ql2xiniexchg
-= (temp
- max_cnt
)/2;
4184 ql2xexchoffld
-= (((temp
- max_cnt
)/2) + 1);
4188 if (temp
> FW_DEF_EXCHANGES_CNT
)
4194 qla2x00_set_exchoffld_buffer(scsi_qla_host_t
*vha
)
4199 struct qla_hw_data
*ha
= vha
->hw
;
4201 if (!ha
->flags
.exchoffld_enabled
)
4204 if (!IS_EXCHG_OFFLD_CAPABLE(ha
))
4208 rval
= qla_get_exchoffld_status(vha
, &size
, &max_cnt
);
4209 if (rval
!= QLA_SUCCESS
) {
4210 ql_log_pci(ql_log_fatal
, ha
->pdev
, 0xd012,
4211 "Failed to get exlogin status.\n");
4215 qla2x00_number_of_exch(vha
, &temp
, max_cnt
);
4218 if (temp
!= ha
->exchoffld_size
) {
4219 qla2x00_free_exchoffld_buffer(ha
);
4220 ha
->exchoffld_size
= temp
;
4222 ql_log(ql_log_info
, vha
, 0xd016,
4223 "Exchange offload: max_count=%d, buffers=0x%x, total=%d.\n",
4224 max_cnt
, size
, temp
);
4226 ql_log(ql_log_info
, vha
, 0xd017,
4227 "Exchange Buffers requested size = 0x%x\n",
4228 ha
->exchoffld_size
);
4230 /* Get consistent memory for extended logins */
4231 ha
->exchoffld_buf
= dma_alloc_coherent(&ha
->pdev
->dev
,
4232 ha
->exchoffld_size
, &ha
->exchoffld_buf_dma
, GFP_KERNEL
);
4233 if (!ha
->exchoffld_buf
) {
4234 ql_log_pci(ql_log_fatal
, ha
->pdev
, 0xd013,
4235 "Failed to allocate memory for exchoffld_buf_dma.\n");
4240 /* Now configure the dma buffer */
4241 rval
= qla_set_exchoffld_mem_cfg(vha
);
4243 ql_log(ql_log_fatal
, vha
, 0xd02e,
4244 "Setup exchange offload buffer ****FAILED****.\n");
4245 qla2x00_free_exchoffld_buffer(ha
);
4247 /* re-adjust number of target exchange */
4248 struct init_cb_81xx
*icb
= (struct init_cb_81xx
*)ha
->init_cb
;
4250 if (qla_ini_mode_enabled(vha
))
4251 icb
->exchange_count
= 0;
4253 icb
->exchange_count
= cpu_to_le16(ql2xexchoffld
);
4260 * qla2x00_free_exchoffld_buffer
4263 * ha = adapter block pointer
4266 qla2x00_free_exchoffld_buffer(struct qla_hw_data
*ha
)
4268 if (ha
->exchoffld_buf
) {
4269 dma_free_coherent(&ha
->pdev
->dev
, ha
->exchoffld_size
,
4270 ha
->exchoffld_buf
, ha
->exchoffld_buf_dma
);
4271 ha
->exchoffld_buf
= NULL
;
4272 ha
->exchoffld_size
= 0;
4277 * qla2x00_free_fw_dump
4278 * Frees fw dump stuff.
4281 * ha = adapter block pointer
4284 qla2x00_free_fw_dump(struct qla_hw_data
*ha
)
4287 dma_free_coherent(&ha
->pdev
->dev
,
4288 FCE_SIZE
, ha
->fce
, ha
->fce_dma
);
4291 dma_free_coherent(&ha
->pdev
->dev
,
4292 EFT_SIZE
, ha
->eft
, ha
->eft_dma
);
4296 if (ha
->fw_dump_template
)
4297 vfree(ha
->fw_dump_template
);
4304 ha
->fw_dump_cap_flags
= 0;
4305 ha
->fw_dump_reading
= 0;
4307 ha
->fw_dump_len
= 0;
4308 ha
->fw_dump_template
= NULL
;
4309 ha
->fw_dump_template_len
= 0;
4314 * Frees all adapter allocated memory.
4317 * ha = adapter block pointer.
4320 qla2x00_mem_free(struct qla_hw_data
*ha
)
4322 qla2x00_free_fw_dump(ha
);
4325 dma_free_coherent(&ha
->pdev
->dev
, MCTP_DUMP_SIZE
, ha
->mctp_dump
,
4328 if (ha
->srb_mempool
)
4329 mempool_destroy(ha
->srb_mempool
);
4332 dma_free_coherent(&ha
->pdev
->dev
, DCBX_TLV_DATA_SIZE
,
4333 ha
->dcbx_tlv
, ha
->dcbx_tlv_dma
);
4336 dma_free_coherent(&ha
->pdev
->dev
, XGMAC_DATA_SIZE
,
4337 ha
->xgmac_data
, ha
->xgmac_data_dma
);
4340 dma_free_coherent(&ha
->pdev
->dev
, sizeof(struct sns_cmd_pkt
),
4341 ha
->sns_cmd
, ha
->sns_cmd_dma
);
4344 dma_free_coherent(&ha
->pdev
->dev
, sizeof(struct ct_sns_pkt
),
4345 ha
->ct_sns
, ha
->ct_sns_dma
);
4348 dma_pool_free(ha
->s_dma_pool
, ha
->sfp_data
, ha
->sfp_data_dma
);
4351 dma_pool_free(ha
->s_dma_pool
, ha
->ms_iocb
, ha
->ms_iocb_dma
);
4354 dma_pool_free(ha
->s_dma_pool
,
4355 ha
->ex_init_cb
, ha
->ex_init_cb_dma
);
4358 dma_pool_free(ha
->s_dma_pool
, ha
->async_pd
, ha
->async_pd_dma
);
4361 dma_pool_destroy(ha
->s_dma_pool
);
4364 dma_free_coherent(&ha
->pdev
->dev
, qla2x00_gid_list_size(ha
),
4365 ha
->gid_list
, ha
->gid_list_dma
);
4367 if (IS_QLA82XX(ha
)) {
4368 if (!list_empty(&ha
->gbl_dsd_list
)) {
4369 struct dsd_dma
*dsd_ptr
, *tdsd_ptr
;
4371 /* clean up allocated prev pool */
4372 list_for_each_entry_safe(dsd_ptr
,
4373 tdsd_ptr
, &ha
->gbl_dsd_list
, list
) {
4374 dma_pool_free(ha
->dl_dma_pool
,
4375 dsd_ptr
->dsd_addr
, dsd_ptr
->dsd_list_dma
);
4376 list_del(&dsd_ptr
->list
);
4382 if (ha
->dl_dma_pool
)
4383 dma_pool_destroy(ha
->dl_dma_pool
);
4385 if (ha
->fcp_cmnd_dma_pool
)
4386 dma_pool_destroy(ha
->fcp_cmnd_dma_pool
);
4388 if (ha
->ctx_mempool
)
4389 mempool_destroy(ha
->ctx_mempool
);
4394 dma_free_coherent(&ha
->pdev
->dev
, ha
->init_cb_size
,
4395 ha
->init_cb
, ha
->init_cb_dma
);
4396 vfree(ha
->optrom_buffer
);
4398 kfree(ha
->npiv_info
);
4400 kfree(ha
->loop_id_map
);
4402 ha
->srb_mempool
= NULL
;
4403 ha
->ctx_mempool
= NULL
;
4405 ha
->sns_cmd_dma
= 0;
4409 ha
->ms_iocb_dma
= 0;
4411 ha
->init_cb_dma
= 0;
4412 ha
->ex_init_cb
= NULL
;
4413 ha
->ex_init_cb_dma
= 0;
4414 ha
->async_pd
= NULL
;
4415 ha
->async_pd_dma
= 0;
4417 ha
->s_dma_pool
= NULL
;
4418 ha
->dl_dma_pool
= NULL
;
4419 ha
->fcp_cmnd_dma_pool
= NULL
;
4421 ha
->gid_list
= NULL
;
4422 ha
->gid_list_dma
= 0;
4424 ha
->tgt
.atio_ring
= NULL
;
4425 ha
->tgt
.atio_dma
= 0;
4426 ha
->tgt
.tgt_vp_map
= NULL
;
4429 struct scsi_qla_host
*qla2x00_create_host(struct scsi_host_template
*sht
,
4430 struct qla_hw_data
*ha
)
4432 struct Scsi_Host
*host
;
4433 struct scsi_qla_host
*vha
= NULL
;
4435 host
= scsi_host_alloc(sht
, sizeof(scsi_qla_host_t
));
4437 ql_log_pci(ql_log_fatal
, ha
->pdev
, 0x0107,
4438 "Failed to allocate host from the scsi layer, aborting.\n");
4442 /* Clear our data area */
4443 vha
= shost_priv(host
);
4444 memset(vha
, 0, sizeof(scsi_qla_host_t
));
4447 vha
->host_no
= host
->host_no
;
4450 INIT_LIST_HEAD(&vha
->vp_fcports
);
4451 INIT_LIST_HEAD(&vha
->work_list
);
4452 INIT_LIST_HEAD(&vha
->list
);
4453 INIT_LIST_HEAD(&vha
->qla_cmd_list
);
4454 INIT_LIST_HEAD(&vha
->qla_sess_op_cmd_list
);
4455 INIT_LIST_HEAD(&vha
->logo_list
);
4456 INIT_LIST_HEAD(&vha
->plogi_ack_list
);
4457 INIT_LIST_HEAD(&vha
->qp_list
);
4458 INIT_LIST_HEAD(&vha
->gnl
.fcports
);
4459 INIT_LIST_HEAD(&vha
->nvme_rport_list
);
4461 spin_lock_init(&vha
->work_lock
);
4462 spin_lock_init(&vha
->cmd_list_lock
);
4463 init_waitqueue_head(&vha
->fcport_waitQ
);
4464 init_waitqueue_head(&vha
->vref_waitq
);
4466 vha
->gnl
.size
= sizeof(struct get_name_list_extended
) *
4467 (ha
->max_loop_id
+ 1);
4468 vha
->gnl
.l
= dma_alloc_coherent(&ha
->pdev
->dev
,
4469 vha
->gnl
.size
, &vha
->gnl
.ldma
, GFP_KERNEL
);
4471 ql_log(ql_log_fatal
, vha
, 0xd04a,
4472 "Alloc failed for name list.\n");
4473 scsi_remove_host(vha
->host
);
4477 sprintf(vha
->host_str
, "%s_%ld", QLA2XXX_DRIVER_NAME
, vha
->host_no
);
4478 ql_dbg(ql_dbg_init
, vha
, 0x0041,
4479 "Allocated the host=%p hw=%p vha=%p dev_name=%s",
4480 vha
->host
, vha
->hw
, vha
,
4481 dev_name(&(ha
->pdev
->dev
)));
4486 struct qla_work_evt
*
4487 qla2x00_alloc_work(struct scsi_qla_host
*vha
, enum qla_work_type type
)
4489 struct qla_work_evt
*e
;
4492 QLA_VHA_MARK_BUSY(vha
, bail
);
4496 e
= kzalloc(sizeof(struct qla_work_evt
), GFP_ATOMIC
);
4498 QLA_VHA_MARK_NOT_BUSY(vha
);
4502 INIT_LIST_HEAD(&e
->list
);
4504 e
->flags
= QLA_EVT_FLAG_FREE
;
4509 qla2x00_post_work(struct scsi_qla_host
*vha
, struct qla_work_evt
*e
)
4511 unsigned long flags
;
4513 spin_lock_irqsave(&vha
->work_lock
, flags
);
4514 list_add_tail(&e
->list
, &vha
->work_list
);
4515 spin_unlock_irqrestore(&vha
->work_lock
, flags
);
4517 if (QLA_EARLY_LINKUP(vha
->hw
))
4518 schedule_work(&vha
->iocb_work
);
4520 qla2xxx_wake_dpc(vha
);
4526 qla2x00_post_aen_work(struct scsi_qla_host
*vha
, enum fc_host_event_code code
,
4529 struct qla_work_evt
*e
;
4531 e
= qla2x00_alloc_work(vha
, QLA_EVT_AEN
);
4533 return QLA_FUNCTION_FAILED
;
4535 e
->u
.aen
.code
= code
;
4536 e
->u
.aen
.data
= data
;
4537 return qla2x00_post_work(vha
, e
);
4541 qla2x00_post_idc_ack_work(struct scsi_qla_host
*vha
, uint16_t *mb
)
4543 struct qla_work_evt
*e
;
4545 e
= qla2x00_alloc_work(vha
, QLA_EVT_IDC_ACK
);
4547 return QLA_FUNCTION_FAILED
;
4549 memcpy(e
->u
.idc_ack
.mb
, mb
, QLA_IDC_ACK_REGS
* sizeof(uint16_t));
4550 return qla2x00_post_work(vha
, e
);
4553 #define qla2x00_post_async_work(name, type) \
4554 int qla2x00_post_async_##name##_work( \
4555 struct scsi_qla_host *vha, \
4556 fc_port_t *fcport, uint16_t *data) \
4558 struct qla_work_evt *e; \
4560 e = qla2x00_alloc_work(vha, type); \
4562 return QLA_FUNCTION_FAILED; \
4564 e->u.logio.fcport = fcport; \
4566 e->u.logio.data[0] = data[0]; \
4567 e->u.logio.data[1] = data[1]; \
4569 return qla2x00_post_work(vha, e); \
4572 qla2x00_post_async_work(login
, QLA_EVT_ASYNC_LOGIN
);
4573 qla2x00_post_async_work(logout
, QLA_EVT_ASYNC_LOGOUT
);
4574 qla2x00_post_async_work(logout_done
, QLA_EVT_ASYNC_LOGOUT_DONE
);
4575 qla2x00_post_async_work(adisc
, QLA_EVT_ASYNC_ADISC
);
4576 qla2x00_post_async_work(adisc_done
, QLA_EVT_ASYNC_ADISC_DONE
);
4579 qla2x00_post_uevent_work(struct scsi_qla_host
*vha
, u32 code
)
4581 struct qla_work_evt
*e
;
4583 e
= qla2x00_alloc_work(vha
, QLA_EVT_UEVENT
);
4585 return QLA_FUNCTION_FAILED
;
4587 e
->u
.uevent
.code
= code
;
4588 return qla2x00_post_work(vha
, e
);
4592 qla2x00_uevent_emit(struct scsi_qla_host
*vha
, u32 code
)
4594 char event_string
[40];
4595 char *envp
[] = { event_string
, NULL
};
4598 case QLA_UEVENT_CODE_FW_DUMP
:
4599 snprintf(event_string
, sizeof(event_string
), "FW_DUMP=%ld",
4606 kobject_uevent_env(&vha
->hw
->pdev
->dev
.kobj
, KOBJ_CHANGE
, envp
);
4610 qlafx00_post_aenfx_work(struct scsi_qla_host
*vha
, uint32_t evtcode
,
4611 uint32_t *data
, int cnt
)
4613 struct qla_work_evt
*e
;
4615 e
= qla2x00_alloc_work(vha
, QLA_EVT_AENFX
);
4617 return QLA_FUNCTION_FAILED
;
4619 e
->u
.aenfx
.evtcode
= evtcode
;
4620 e
->u
.aenfx
.count
= cnt
;
4621 memcpy(e
->u
.aenfx
.mbx
, data
, sizeof(*data
) * cnt
);
4622 return qla2x00_post_work(vha
, e
);
4625 int qla24xx_post_upd_fcport_work(struct scsi_qla_host
*vha
, fc_port_t
*fcport
)
4627 struct qla_work_evt
*e
;
4629 e
= qla2x00_alloc_work(vha
, QLA_EVT_UPD_FCPORT
);
4631 return QLA_FUNCTION_FAILED
;
4633 e
->u
.fcport
.fcport
= fcport
;
4634 return qla2x00_post_work(vha
, e
);
4638 void qla24xx_create_new_sess(struct scsi_qla_host
*vha
, struct qla_work_evt
*e
)
4640 unsigned long flags
;
4641 fc_port_t
*fcport
= NULL
;
4642 struct qlt_plogi_ack_t
*pla
=
4643 (struct qlt_plogi_ack_t
*)e
->u
.new_sess
.pla
;
4645 spin_lock_irqsave(&vha
->hw
->tgt
.sess_lock
, flags
);
4646 fcport
= qla2x00_find_fcport_by_wwpn(vha
, e
->u
.new_sess
.port_name
, 1);
4648 fcport
->d_id
= e
->u
.new_sess
.id
;
4650 fcport
->fw_login_state
= DSC_LS_PLOGI_PEND
;
4651 qlt_plogi_ack_link(vha
, pla
, fcport
, QLT_PLOGI_LINK_SAME_WWN
);
4652 /* we took an extra ref_count to prevent PLOGI ACK when
4653 * fcport/sess has not been created.
4658 fcport
= qla2x00_alloc_fcport(vha
, GFP_KERNEL
);
4660 fcport
->d_id
= e
->u
.new_sess
.id
;
4661 fcport
->scan_state
= QLA_FCPORT_FOUND
;
4662 fcport
->flags
|= FCF_FABRIC_DEVICE
;
4663 fcport
->fw_login_state
= DSC_LS_PLOGI_PEND
;
4665 memcpy(fcport
->port_name
, e
->u
.new_sess
.port_name
,
4667 list_add_tail(&fcport
->list
, &vha
->vp_fcports
);
4670 qlt_plogi_ack_link(vha
, pla
, fcport
,
4671 QLT_PLOGI_LINK_SAME_WWN
);
4676 spin_unlock_irqrestore(&vha
->hw
->tgt
.sess_lock
, flags
);
4680 qlt_plogi_ack_unref(vha
, pla
);
4682 qla24xx_async_gnl(vha
, fcport
);
4687 qla2x00_do_work(struct scsi_qla_host
*vha
)
4689 struct qla_work_evt
*e
, *tmp
;
4690 unsigned long flags
;
4693 spin_lock_irqsave(&vha
->work_lock
, flags
);
4694 list_splice_init(&vha
->work_list
, &work
);
4695 spin_unlock_irqrestore(&vha
->work_lock
, flags
);
4697 list_for_each_entry_safe(e
, tmp
, &work
, list
) {
4698 list_del_init(&e
->list
);
4702 fc_host_post_event(vha
->host
, fc_get_event_number(),
4703 e
->u
.aen
.code
, e
->u
.aen
.data
);
4705 case QLA_EVT_IDC_ACK
:
4706 qla81xx_idc_ack(vha
, e
->u
.idc_ack
.mb
);
4708 case QLA_EVT_ASYNC_LOGIN
:
4709 qla2x00_async_login(vha
, e
->u
.logio
.fcport
,
4712 case QLA_EVT_ASYNC_LOGOUT
:
4713 qla2x00_async_logout(vha
, e
->u
.logio
.fcport
);
4715 case QLA_EVT_ASYNC_LOGOUT_DONE
:
4716 qla2x00_async_logout_done(vha
, e
->u
.logio
.fcport
,
4719 case QLA_EVT_ASYNC_ADISC
:
4720 qla2x00_async_adisc(vha
, e
->u
.logio
.fcport
,
4723 case QLA_EVT_ASYNC_ADISC_DONE
:
4724 qla2x00_async_adisc_done(vha
, e
->u
.logio
.fcport
,
4727 case QLA_EVT_UEVENT
:
4728 qla2x00_uevent_emit(vha
, e
->u
.uevent
.code
);
4731 qlafx00_process_aen(vha
, e
);
4734 qla24xx_async_gidpn(vha
, e
->u
.fcport
.fcport
);
4737 qla24xx_async_gpnid(vha
, &e
->u
.gpnid
.id
);
4739 case QLA_EVT_GPNID_DONE
:
4740 qla24xx_async_gpnid_done(vha
, e
->u
.iosb
.sp
);
4742 case QLA_EVT_NEW_SESS
:
4743 qla24xx_create_new_sess(vha
, e
);
4746 qla24xx_async_gpdb(vha
, e
->u
.fcport
.fcport
,
4750 qla24xx_async_prli(vha
, e
->u
.fcport
.fcport
);
4753 qla24xx_async_gpsc(vha
, e
->u
.fcport
.fcport
);
4755 case QLA_EVT_UPD_FCPORT
:
4756 qla2x00_update_fcport(vha
, e
->u
.fcport
.fcport
);
4759 qla24xx_async_gnl(vha
, e
->u
.fcport
.fcport
);
4762 qla24xx_do_nack_work(vha
, e
);
4765 if (e
->flags
& QLA_EVT_FLAG_FREE
)
4768 /* For each work completed decrement vha ref count */
4769 QLA_VHA_MARK_NOT_BUSY(vha
);
4773 /* Relogins all the fcports of a vport
4774 * Context: dpc thread
4776 void qla2x00_relogin(struct scsi_qla_host
*vha
)
4780 struct event_arg ea
;
4782 list_for_each_entry(fcport
, &vha
->vp_fcports
, list
) {
4784 * If the port is not ONLINE then try to login
4785 * to it if we haven't run out of retries.
4787 if (atomic_read(&fcport
->state
) != FCS_ONLINE
&&
4788 fcport
->login_retry
&& !(fcport
->flags
& FCF_ASYNC_SENT
)) {
4789 fcport
->login_retry
--;
4790 if (fcport
->flags
& FCF_FABRIC_DEVICE
) {
4791 ql_dbg(ql_dbg_disc
, fcport
->vha
, 0x2108,
4792 "%s %8phC DS %d LS %d\n", __func__
,
4793 fcport
->port_name
, fcport
->disc_state
,
4794 fcport
->fw_login_state
);
4795 memset(&ea
, 0, sizeof(ea
));
4796 ea
.event
= FCME_RELOGIN
;
4798 qla2x00_fcport_event_handler(vha
, &ea
);
4800 status
= qla2x00_local_device_login(vha
,
4802 if (status
== QLA_SUCCESS
) {
4803 fcport
->old_loop_id
= fcport
->loop_id
;
4804 ql_dbg(ql_dbg_disc
, vha
, 0x2003,
4805 "Port login OK: logged in ID 0x%x.\n",
4807 qla2x00_update_fcport(vha
, fcport
);
4808 } else if (status
== 1) {
4809 set_bit(RELOGIN_NEEDED
, &vha
->dpc_flags
);
4810 /* retry the login again */
4811 ql_dbg(ql_dbg_disc
, vha
, 0x2007,
4812 "Retrying %d login again loop_id 0x%x.\n",
4813 fcport
->login_retry
,
4816 fcport
->login_retry
= 0;
4819 if (fcport
->login_retry
== 0 &&
4820 status
!= QLA_SUCCESS
)
4821 qla2x00_clear_loop_id(fcport
);
4824 if (test_bit(LOOP_RESYNC_NEEDED
, &vha
->dpc_flags
))
4829 /* Schedule work on any of the dpc-workqueues */
4831 qla83xx_schedule_work(scsi_qla_host_t
*base_vha
, int work_code
)
4833 struct qla_hw_data
*ha
= base_vha
->hw
;
4835 switch (work_code
) {
4836 case MBA_IDC_AEN
: /* 0x8200 */
4838 queue_work(ha
->dpc_lp_wq
, &ha
->idc_aen
);
4841 case QLA83XX_NIC_CORE_RESET
: /* 0x1 */
4842 if (!ha
->flags
.nic_core_reset_hdlr_active
) {
4844 queue_work(ha
->dpc_hp_wq
, &ha
->nic_core_reset
);
4846 ql_dbg(ql_dbg_p3p
, base_vha
, 0xb05e,
4847 "NIC Core reset is already active. Skip "
4848 "scheduling it again.\n");
4850 case QLA83XX_IDC_STATE_HANDLER
: /* 0x2 */
4852 queue_work(ha
->dpc_hp_wq
, &ha
->idc_state_handler
);
4854 case QLA83XX_NIC_CORE_UNRECOVERABLE
: /* 0x3 */
4856 queue_work(ha
->dpc_hp_wq
, &ha
->nic_core_unrecoverable
);
4859 ql_log(ql_log_warn
, base_vha
, 0xb05f,
4860 "Unknown work-code=0x%x.\n", work_code
);
4866 /* Work: Perform NIC Core Unrecoverable state handling */
4868 qla83xx_nic_core_unrecoverable_work(struct work_struct
*work
)
4870 struct qla_hw_data
*ha
=
4871 container_of(work
, struct qla_hw_data
, nic_core_unrecoverable
);
4872 scsi_qla_host_t
*base_vha
= pci_get_drvdata(ha
->pdev
);
4873 uint32_t dev_state
= 0;
4875 qla83xx_idc_lock(base_vha
, 0);
4876 qla83xx_rd_reg(base_vha
, QLA83XX_IDC_DEV_STATE
, &dev_state
);
4877 qla83xx_reset_ownership(base_vha
);
4878 if (ha
->flags
.nic_core_reset_owner
) {
4879 ha
->flags
.nic_core_reset_owner
= 0;
4880 qla83xx_wr_reg(base_vha
, QLA83XX_IDC_DEV_STATE
,
4881 QLA8XXX_DEV_FAILED
);
4882 ql_log(ql_log_info
, base_vha
, 0xb060, "HW State: FAILED.\n");
4883 qla83xx_schedule_work(base_vha
, QLA83XX_IDC_STATE_HANDLER
);
4885 qla83xx_idc_unlock(base_vha
, 0);
4888 /* Work: Execute IDC state handler */
4890 qla83xx_idc_state_handler_work(struct work_struct
*work
)
4892 struct qla_hw_data
*ha
=
4893 container_of(work
, struct qla_hw_data
, idc_state_handler
);
4894 scsi_qla_host_t
*base_vha
= pci_get_drvdata(ha
->pdev
);
4895 uint32_t dev_state
= 0;
4897 qla83xx_idc_lock(base_vha
, 0);
4898 qla83xx_rd_reg(base_vha
, QLA83XX_IDC_DEV_STATE
, &dev_state
);
4899 if (dev_state
== QLA8XXX_DEV_FAILED
||
4900 dev_state
== QLA8XXX_DEV_NEED_QUIESCENT
)
4901 qla83xx_idc_state_handler(base_vha
);
4902 qla83xx_idc_unlock(base_vha
, 0);
4906 qla83xx_check_nic_core_fw_alive(scsi_qla_host_t
*base_vha
)
4908 int rval
= QLA_SUCCESS
;
4909 unsigned long heart_beat_wait
= jiffies
+ (1 * HZ
);
4910 uint32_t heart_beat_counter1
, heart_beat_counter2
;
4913 if (time_after(jiffies
, heart_beat_wait
)) {
4914 ql_dbg(ql_dbg_p3p
, base_vha
, 0xb07c,
4915 "Nic Core f/w is not alive.\n");
4916 rval
= QLA_FUNCTION_FAILED
;
4920 qla83xx_idc_lock(base_vha
, 0);
4921 qla83xx_rd_reg(base_vha
, QLA83XX_FW_HEARTBEAT
,
4922 &heart_beat_counter1
);
4923 qla83xx_idc_unlock(base_vha
, 0);
4925 qla83xx_idc_lock(base_vha
, 0);
4926 qla83xx_rd_reg(base_vha
, QLA83XX_FW_HEARTBEAT
,
4927 &heart_beat_counter2
);
4928 qla83xx_idc_unlock(base_vha
, 0);
4929 } while (heart_beat_counter1
== heart_beat_counter2
);
4934 /* Work: Perform NIC Core Reset handling */
4936 qla83xx_nic_core_reset_work(struct work_struct
*work
)
4938 struct qla_hw_data
*ha
=
4939 container_of(work
, struct qla_hw_data
, nic_core_reset
);
4940 scsi_qla_host_t
*base_vha
= pci_get_drvdata(ha
->pdev
);
4941 uint32_t dev_state
= 0;
4943 if (IS_QLA2031(ha
)) {
4944 if (qla2xxx_mctp_dump(base_vha
) != QLA_SUCCESS
)
4945 ql_log(ql_log_warn
, base_vha
, 0xb081,
4946 "Failed to dump mctp\n");
4950 if (!ha
->flags
.nic_core_reset_hdlr_active
) {
4951 if (qla83xx_check_nic_core_fw_alive(base_vha
) == QLA_SUCCESS
) {
4952 qla83xx_idc_lock(base_vha
, 0);
4953 qla83xx_rd_reg(base_vha
, QLA83XX_IDC_DEV_STATE
,
4955 qla83xx_idc_unlock(base_vha
, 0);
4956 if (dev_state
!= QLA8XXX_DEV_NEED_RESET
) {
4957 ql_dbg(ql_dbg_p3p
, base_vha
, 0xb07a,
4958 "Nic Core f/w is alive.\n");
4963 ha
->flags
.nic_core_reset_hdlr_active
= 1;
4964 if (qla83xx_nic_core_reset(base_vha
)) {
4965 /* NIC Core reset failed. */
4966 ql_dbg(ql_dbg_p3p
, base_vha
, 0xb061,
4967 "NIC Core reset failed.\n");
4969 ha
->flags
.nic_core_reset_hdlr_active
= 0;
4973 /* Work: Handle 8200 IDC aens */
4975 qla83xx_service_idc_aen(struct work_struct
*work
)
4977 struct qla_hw_data
*ha
=
4978 container_of(work
, struct qla_hw_data
, idc_aen
);
4979 scsi_qla_host_t
*base_vha
= pci_get_drvdata(ha
->pdev
);
4980 uint32_t dev_state
, idc_control
;
4982 qla83xx_idc_lock(base_vha
, 0);
4983 qla83xx_rd_reg(base_vha
, QLA83XX_IDC_DEV_STATE
, &dev_state
);
4984 qla83xx_rd_reg(base_vha
, QLA83XX_IDC_CONTROL
, &idc_control
);
4985 qla83xx_idc_unlock(base_vha
, 0);
4986 if (dev_state
== QLA8XXX_DEV_NEED_RESET
) {
4987 if (idc_control
& QLA83XX_IDC_GRACEFUL_RESET
) {
4988 ql_dbg(ql_dbg_p3p
, base_vha
, 0xb062,
4989 "Application requested NIC Core Reset.\n");
4990 qla83xx_schedule_work(base_vha
, QLA83XX_NIC_CORE_RESET
);
4991 } else if (qla83xx_check_nic_core_fw_alive(base_vha
) ==
4993 ql_dbg(ql_dbg_p3p
, base_vha
, 0xb07b,
4994 "Other protocol driver requested NIC Core Reset.\n");
4995 qla83xx_schedule_work(base_vha
, QLA83XX_NIC_CORE_RESET
);
4997 } else if (dev_state
== QLA8XXX_DEV_FAILED
||
4998 dev_state
== QLA8XXX_DEV_NEED_QUIESCENT
) {
4999 qla83xx_schedule_work(base_vha
, QLA83XX_IDC_STATE_HANDLER
);
5004 qla83xx_wait_logic(void)
5009 if (!in_interrupt()) {
5011 * Wait about 200ms before retrying again.
5012 * This controls the number of retries for single
5018 for (i
= 0; i
< 20; i
++)
5019 cpu_relax(); /* This a nop instr on i386 */
5024 qla83xx_force_lock_recovery(scsi_qla_host_t
*base_vha
)
5028 uint32_t idc_lck_rcvry_stage_mask
= 0x3;
5029 uint32_t idc_lck_rcvry_owner_mask
= 0x3c;
5030 struct qla_hw_data
*ha
= base_vha
->hw
;
5031 ql_dbg(ql_dbg_p3p
, base_vha
, 0xb086,
5032 "Trying force recovery of the IDC lock.\n");
5034 rval
= qla83xx_rd_reg(base_vha
, QLA83XX_IDC_LOCK_RECOVERY
, &data
);
5038 if ((data
& idc_lck_rcvry_stage_mask
) > 0) {
5041 data
= (IDC_LOCK_RECOVERY_STAGE1
) | (ha
->portnum
<< 2);
5042 rval
= qla83xx_wr_reg(base_vha
, QLA83XX_IDC_LOCK_RECOVERY
,
5049 rval
= qla83xx_rd_reg(base_vha
, QLA83XX_IDC_LOCK_RECOVERY
,
5054 if (((data
& idc_lck_rcvry_owner_mask
) >> 2) == ha
->portnum
) {
5055 data
&= (IDC_LOCK_RECOVERY_STAGE2
|
5056 ~(idc_lck_rcvry_stage_mask
));
5057 rval
= qla83xx_wr_reg(base_vha
,
5058 QLA83XX_IDC_LOCK_RECOVERY
, data
);
5062 /* Forcefully perform IDC UnLock */
5063 rval
= qla83xx_rd_reg(base_vha
, QLA83XX_DRIVER_UNLOCK
,
5067 /* Clear lock-id by setting 0xff */
5068 rval
= qla83xx_wr_reg(base_vha
, QLA83XX_DRIVER_LOCKID
,
5072 /* Clear lock-recovery by setting 0x0 */
5073 rval
= qla83xx_wr_reg(base_vha
,
5074 QLA83XX_IDC_LOCK_RECOVERY
, 0x0);
5085 qla83xx_idc_lock_recovery(scsi_qla_host_t
*base_vha
)
5087 int rval
= QLA_SUCCESS
;
5088 uint32_t o_drv_lockid
, n_drv_lockid
;
5089 unsigned long lock_recovery_timeout
;
5091 lock_recovery_timeout
= jiffies
+ QLA83XX_MAX_LOCK_RECOVERY_WAIT
;
5093 rval
= qla83xx_rd_reg(base_vha
, QLA83XX_DRIVER_LOCKID
, &o_drv_lockid
);
5097 /* MAX wait time before forcing IDC Lock recovery = 2 secs */
5098 if (time_after_eq(jiffies
, lock_recovery_timeout
)) {
5099 if (qla83xx_force_lock_recovery(base_vha
) == QLA_SUCCESS
)
5102 return QLA_FUNCTION_FAILED
;
5105 rval
= qla83xx_rd_reg(base_vha
, QLA83XX_DRIVER_LOCKID
, &n_drv_lockid
);
5109 if (o_drv_lockid
== n_drv_lockid
) {
5110 qla83xx_wait_logic();
5120 qla83xx_idc_lock(scsi_qla_host_t
*base_vha
, uint16_t requester_id
)
5122 uint16_t options
= (requester_id
<< 15) | BIT_6
;
5124 uint32_t lock_owner
;
5125 struct qla_hw_data
*ha
= base_vha
->hw
;
5127 /* IDC-lock implementation using driver-lock/lock-id remote registers */
5129 if (qla83xx_rd_reg(base_vha
, QLA83XX_DRIVER_LOCK
, &data
)
5132 /* Setting lock-id to our function-number */
5133 qla83xx_wr_reg(base_vha
, QLA83XX_DRIVER_LOCKID
,
5136 qla83xx_rd_reg(base_vha
, QLA83XX_DRIVER_LOCKID
,
5138 ql_dbg(ql_dbg_p3p
, base_vha
, 0xb063,
5139 "Failed to acquire IDC lock, acquired by %d, "
5140 "retrying...\n", lock_owner
);
5142 /* Retry/Perform IDC-Lock recovery */
5143 if (qla83xx_idc_lock_recovery(base_vha
)
5145 qla83xx_wait_logic();
5148 ql_log(ql_log_warn
, base_vha
, 0xb075,
5149 "IDC Lock recovery FAILED.\n");
5156 /* XXX: IDC-lock implementation using access-control mbx */
5158 if (qla83xx_access_control(base_vha
, options
, 0, 0, NULL
)) {
5159 ql_dbg(ql_dbg_p3p
, base_vha
, 0xb072,
5160 "Failed to acquire IDC lock. retrying...\n");
5161 /* Retry/Perform IDC-Lock recovery */
5162 if (qla83xx_idc_lock_recovery(base_vha
) == QLA_SUCCESS
) {
5163 qla83xx_wait_logic();
5166 ql_log(ql_log_warn
, base_vha
, 0xb076,
5167 "IDC Lock recovery FAILED.\n");
5174 qla83xx_idc_unlock(scsi_qla_host_t
*base_vha
, uint16_t requester_id
)
5177 uint16_t options
= (requester_id
<< 15) | BIT_7
;
5181 struct qla_hw_data
*ha
= base_vha
->hw
;
5183 /* IDC-unlock implementation using driver-unlock/lock-id
5188 if (qla83xx_rd_reg(base_vha
, QLA83XX_DRIVER_LOCKID
, &data
)
5190 if (data
== ha
->portnum
) {
5191 qla83xx_rd_reg(base_vha
, QLA83XX_DRIVER_UNLOCK
, &data
);
5192 /* Clearing lock-id by setting 0xff */
5193 qla83xx_wr_reg(base_vha
, QLA83XX_DRIVER_LOCKID
, 0xff);
5194 } else if (retry
< 10) {
5195 /* SV: XXX: IDC unlock retrying needed here? */
5197 /* Retry for IDC-unlock */
5198 qla83xx_wait_logic();
5200 ql_dbg(ql_dbg_p3p
, base_vha
, 0xb064,
5201 "Failed to release IDC lock, retrying=%d\n", retry
);
5204 } else if (retry
< 10) {
5205 /* Retry for IDC-unlock */
5206 qla83xx_wait_logic();
5208 ql_dbg(ql_dbg_p3p
, base_vha
, 0xb065,
5209 "Failed to read drv-lockid, retrying=%d\n", retry
);
5216 /* XXX: IDC-unlock implementation using access-control mbx */
5219 if (qla83xx_access_control(base_vha
, options
, 0, 0, NULL
)) {
5221 /* Retry for IDC-unlock */
5222 qla83xx_wait_logic();
5224 ql_dbg(ql_dbg_p3p
, base_vha
, 0xb066,
5225 "Failed to release IDC lock, retrying=%d\n", retry
);
5235 __qla83xx_set_drv_presence(scsi_qla_host_t
*vha
)
5237 int rval
= QLA_SUCCESS
;
5238 struct qla_hw_data
*ha
= vha
->hw
;
5239 uint32_t drv_presence
;
5241 rval
= qla83xx_rd_reg(vha
, QLA83XX_IDC_DRV_PRESENCE
, &drv_presence
);
5242 if (rval
== QLA_SUCCESS
) {
5243 drv_presence
|= (1 << ha
->portnum
);
5244 rval
= qla83xx_wr_reg(vha
, QLA83XX_IDC_DRV_PRESENCE
,
5252 qla83xx_set_drv_presence(scsi_qla_host_t
*vha
)
5254 int rval
= QLA_SUCCESS
;
5256 qla83xx_idc_lock(vha
, 0);
5257 rval
= __qla83xx_set_drv_presence(vha
);
5258 qla83xx_idc_unlock(vha
, 0);
5264 __qla83xx_clear_drv_presence(scsi_qla_host_t
*vha
)
5266 int rval
= QLA_SUCCESS
;
5267 struct qla_hw_data
*ha
= vha
->hw
;
5268 uint32_t drv_presence
;
5270 rval
= qla83xx_rd_reg(vha
, QLA83XX_IDC_DRV_PRESENCE
, &drv_presence
);
5271 if (rval
== QLA_SUCCESS
) {
5272 drv_presence
&= ~(1 << ha
->portnum
);
5273 rval
= qla83xx_wr_reg(vha
, QLA83XX_IDC_DRV_PRESENCE
,
5281 qla83xx_clear_drv_presence(scsi_qla_host_t
*vha
)
5283 int rval
= QLA_SUCCESS
;
5285 qla83xx_idc_lock(vha
, 0);
5286 rval
= __qla83xx_clear_drv_presence(vha
);
5287 qla83xx_idc_unlock(vha
, 0);
5293 qla83xx_need_reset_handler(scsi_qla_host_t
*vha
)
5295 struct qla_hw_data
*ha
= vha
->hw
;
5296 uint32_t drv_ack
, drv_presence
;
5297 unsigned long ack_timeout
;
5299 /* Wait for IDC ACK from all functions (DRV-ACK == DRV-PRESENCE) */
5300 ack_timeout
= jiffies
+ (ha
->fcoe_reset_timeout
* HZ
);
5302 qla83xx_rd_reg(vha
, QLA83XX_IDC_DRIVER_ACK
, &drv_ack
);
5303 qla83xx_rd_reg(vha
, QLA83XX_IDC_DRV_PRESENCE
, &drv_presence
);
5304 if ((drv_ack
& drv_presence
) == drv_presence
)
5307 if (time_after_eq(jiffies
, ack_timeout
)) {
5308 ql_log(ql_log_warn
, vha
, 0xb067,
5309 "RESET ACK TIMEOUT! drv_presence=0x%x "
5310 "drv_ack=0x%x\n", drv_presence
, drv_ack
);
5312 * The function(s) which did not ack in time are forced
5313 * to withdraw any further participation in the IDC
5316 if (drv_ack
!= drv_presence
)
5317 qla83xx_wr_reg(vha
, QLA83XX_IDC_DRV_PRESENCE
,
5322 qla83xx_idc_unlock(vha
, 0);
5324 qla83xx_idc_lock(vha
, 0);
5327 qla83xx_wr_reg(vha
, QLA83XX_IDC_DEV_STATE
, QLA8XXX_DEV_COLD
);
5328 ql_log(ql_log_info
, vha
, 0xb068, "HW State: COLD/RE-INIT.\n");
5332 qla83xx_device_bootstrap(scsi_qla_host_t
*vha
)
5334 int rval
= QLA_SUCCESS
;
5335 uint32_t idc_control
;
5337 qla83xx_wr_reg(vha
, QLA83XX_IDC_DEV_STATE
, QLA8XXX_DEV_INITIALIZING
);
5338 ql_log(ql_log_info
, vha
, 0xb069, "HW State: INITIALIZING.\n");
5340 /* Clearing IDC-Control Graceful-Reset Bit before resetting f/w */
5341 __qla83xx_get_idc_control(vha
, &idc_control
);
5342 idc_control
&= ~QLA83XX_IDC_GRACEFUL_RESET
;
5343 __qla83xx_set_idc_control(vha
, 0);
5345 qla83xx_idc_unlock(vha
, 0);
5346 rval
= qla83xx_restart_nic_firmware(vha
);
5347 qla83xx_idc_lock(vha
, 0);
5349 if (rval
!= QLA_SUCCESS
) {
5350 ql_log(ql_log_fatal
, vha
, 0xb06a,
5351 "Failed to restart NIC f/w.\n");
5352 qla83xx_wr_reg(vha
, QLA83XX_IDC_DEV_STATE
, QLA8XXX_DEV_FAILED
);
5353 ql_log(ql_log_info
, vha
, 0xb06b, "HW State: FAILED.\n");
5355 ql_dbg(ql_dbg_p3p
, vha
, 0xb06c,
5356 "Success in restarting nic f/w.\n");
5357 qla83xx_wr_reg(vha
, QLA83XX_IDC_DEV_STATE
, QLA8XXX_DEV_READY
);
5358 ql_log(ql_log_info
, vha
, 0xb06d, "HW State: READY.\n");
5364 /* Assumes idc_lock always held on entry */
5366 qla83xx_idc_state_handler(scsi_qla_host_t
*base_vha
)
5368 struct qla_hw_data
*ha
= base_vha
->hw
;
5369 int rval
= QLA_SUCCESS
;
5370 unsigned long dev_init_timeout
;
5373 /* Wait for MAX-INIT-TIMEOUT for the device to go ready */
5374 dev_init_timeout
= jiffies
+ (ha
->fcoe_dev_init_timeout
* HZ
);
5378 if (time_after_eq(jiffies
, dev_init_timeout
)) {
5379 ql_log(ql_log_warn
, base_vha
, 0xb06e,
5380 "Initialization TIMEOUT!\n");
5381 /* Init timeout. Disable further NIC Core
5384 qla83xx_wr_reg(base_vha
, QLA83XX_IDC_DEV_STATE
,
5385 QLA8XXX_DEV_FAILED
);
5386 ql_log(ql_log_info
, base_vha
, 0xb06f,
5387 "HW State: FAILED.\n");
5390 qla83xx_rd_reg(base_vha
, QLA83XX_IDC_DEV_STATE
, &dev_state
);
5391 switch (dev_state
) {
5392 case QLA8XXX_DEV_READY
:
5393 if (ha
->flags
.nic_core_reset_owner
)
5394 qla83xx_idc_audit(base_vha
,
5395 IDC_AUDIT_COMPLETION
);
5396 ha
->flags
.nic_core_reset_owner
= 0;
5397 ql_dbg(ql_dbg_p3p
, base_vha
, 0xb070,
5398 "Reset_owner reset by 0x%x.\n",
5401 case QLA8XXX_DEV_COLD
:
5402 if (ha
->flags
.nic_core_reset_owner
)
5403 rval
= qla83xx_device_bootstrap(base_vha
);
5405 /* Wait for AEN to change device-state */
5406 qla83xx_idc_unlock(base_vha
, 0);
5408 qla83xx_idc_lock(base_vha
, 0);
5411 case QLA8XXX_DEV_INITIALIZING
:
5412 /* Wait for AEN to change device-state */
5413 qla83xx_idc_unlock(base_vha
, 0);
5415 qla83xx_idc_lock(base_vha
, 0);
5417 case QLA8XXX_DEV_NEED_RESET
:
5418 if (!ql2xdontresethba
&& ha
->flags
.nic_core_reset_owner
)
5419 qla83xx_need_reset_handler(base_vha
);
5421 /* Wait for AEN to change device-state */
5422 qla83xx_idc_unlock(base_vha
, 0);
5424 qla83xx_idc_lock(base_vha
, 0);
5426 /* reset timeout value after need reset handler */
5427 dev_init_timeout
= jiffies
+
5428 (ha
->fcoe_dev_init_timeout
* HZ
);
5430 case QLA8XXX_DEV_NEED_QUIESCENT
:
5431 /* XXX: DEBUG for now */
5432 qla83xx_idc_unlock(base_vha
, 0);
5434 qla83xx_idc_lock(base_vha
, 0);
5436 case QLA8XXX_DEV_QUIESCENT
:
5437 /* XXX: DEBUG for now */
5438 if (ha
->flags
.quiesce_owner
)
5441 qla83xx_idc_unlock(base_vha
, 0);
5443 qla83xx_idc_lock(base_vha
, 0);
5444 dev_init_timeout
= jiffies
+
5445 (ha
->fcoe_dev_init_timeout
* HZ
);
5447 case QLA8XXX_DEV_FAILED
:
5448 if (ha
->flags
.nic_core_reset_owner
)
5449 qla83xx_idc_audit(base_vha
,
5450 IDC_AUDIT_COMPLETION
);
5451 ha
->flags
.nic_core_reset_owner
= 0;
5452 __qla83xx_clear_drv_presence(base_vha
);
5453 qla83xx_idc_unlock(base_vha
, 0);
5454 qla8xxx_dev_failed_handler(base_vha
);
5455 rval
= QLA_FUNCTION_FAILED
;
5456 qla83xx_idc_lock(base_vha
, 0);
5458 case QLA8XXX_BAD_VALUE
:
5459 qla83xx_idc_unlock(base_vha
, 0);
5461 qla83xx_idc_lock(base_vha
, 0);
5464 ql_log(ql_log_warn
, base_vha
, 0xb071,
5465 "Unknown Device State: %x.\n", dev_state
);
5466 qla83xx_idc_unlock(base_vha
, 0);
5467 qla8xxx_dev_failed_handler(base_vha
);
5468 rval
= QLA_FUNCTION_FAILED
;
5469 qla83xx_idc_lock(base_vha
, 0);
5479 qla2x00_disable_board_on_pci_error(struct work_struct
*work
)
5481 struct qla_hw_data
*ha
= container_of(work
, struct qla_hw_data
,
5483 struct pci_dev
*pdev
= ha
->pdev
;
5484 scsi_qla_host_t
*base_vha
= pci_get_drvdata(ha
->pdev
);
5487 * if UNLOAD flag is already set, then continue unload,
5488 * where it was set first.
5490 if (test_bit(UNLOADING
, &base_vha
->dpc_flags
))
5493 ql_log(ql_log_warn
, base_vha
, 0x015b,
5494 "Disabling adapter.\n");
5496 qla2x00_wait_for_sess_deletion(base_vha
);
5498 set_bit(UNLOADING
, &base_vha
->dpc_flags
);
5500 qla2x00_delete_all_vps(ha
, base_vha
);
5502 qla2x00_abort_all_cmds(base_vha
, DID_NO_CONNECT
<< 16);
5504 qla2x00_dfs_remove(base_vha
);
5506 qla84xx_put_chip(base_vha
);
5508 if (base_vha
->timer_active
)
5509 qla2x00_stop_timer(base_vha
);
5511 base_vha
->flags
.online
= 0;
5513 qla2x00_destroy_deferred_work(ha
);
5516 * Do not try to stop beacon blink as it will issue a mailbox
5519 qla2x00_free_sysfs_attr(base_vha
, false);
5521 fc_remove_host(base_vha
->host
);
5523 scsi_remove_host(base_vha
->host
);
5525 base_vha
->flags
.init_done
= 0;
5526 qla25xx_delete_queues(base_vha
);
5527 qla2x00_free_fcports(base_vha
);
5528 qla2x00_free_irqs(base_vha
);
5529 qla2x00_mem_free(ha
);
5530 qla82xx_md_free(base_vha
);
5531 qla2x00_free_queues(ha
);
5533 qla2x00_unmap_iobases(ha
);
5535 pci_release_selected_regions(ha
->pdev
, ha
->bars
);
5536 pci_disable_pcie_error_reporting(pdev
);
5537 pci_disable_device(pdev
);
5540 * Let qla2x00_remove_one cleanup qla_hw_data on device removal.
5544 /**************************************************************************
5546 * This kernel thread is a task that is schedule by the interrupt handler
5547 * to perform the background processing for interrupts.
5550 * This task always run in the context of a kernel thread. It
5551 * is kick-off by the driver's detect code and starts up
5552 * up one per adapter. It immediately goes to sleep and waits for
5553 * some fibre event. When either the interrupt handler or
5554 * the timer routine detects a event it will one of the task
5555 * bits then wake us up.
5556 **************************************************************************/
5558 qla2x00_do_dpc(void *data
)
5560 scsi_qla_host_t
*base_vha
;
5561 struct qla_hw_data
*ha
;
5563 struct qla_qpair
*qpair
;
5565 ha
= (struct qla_hw_data
*)data
;
5566 base_vha
= pci_get_drvdata(ha
->pdev
);
5568 set_user_nice(current
, MIN_NICE
);
5570 set_current_state(TASK_INTERRUPTIBLE
);
5571 while (!kthread_should_stop()) {
5572 ql_dbg(ql_dbg_dpc
, base_vha
, 0x4000,
5573 "DPC handler sleeping.\n");
5577 if (!base_vha
->flags
.init_done
|| ha
->flags
.mbox_busy
)
5580 if (ha
->flags
.eeh_busy
) {
5581 ql_dbg(ql_dbg_dpc
, base_vha
, 0x4003,
5582 "eeh_busy=%d.\n", ha
->flags
.eeh_busy
);
5588 ql_dbg(ql_dbg_dpc
+ ql_dbg_verbose
, base_vha
, 0x4001,
5589 "DPC handler waking up, dpc_flags=0x%lx.\n",
5590 base_vha
->dpc_flags
);
5592 if (test_bit(UNLOADING
, &base_vha
->dpc_flags
))
5595 qla2x00_do_work(base_vha
);
5597 if (IS_P3P_TYPE(ha
)) {
5598 if (IS_QLA8044(ha
)) {
5599 if (test_and_clear_bit(ISP_UNRECOVERABLE
,
5600 &base_vha
->dpc_flags
)) {
5601 qla8044_idc_lock(ha
);
5602 qla8044_wr_direct(base_vha
,
5603 QLA8044_CRB_DEV_STATE_INDEX
,
5604 QLA8XXX_DEV_FAILED
);
5605 qla8044_idc_unlock(ha
);
5606 ql_log(ql_log_info
, base_vha
, 0x4004,
5607 "HW State: FAILED.\n");
5608 qla8044_device_state_handler(base_vha
);
5613 if (test_and_clear_bit(ISP_UNRECOVERABLE
,
5614 &base_vha
->dpc_flags
)) {
5615 qla82xx_idc_lock(ha
);
5616 qla82xx_wr_32(ha
, QLA82XX_CRB_DEV_STATE
,
5617 QLA8XXX_DEV_FAILED
);
5618 qla82xx_idc_unlock(ha
);
5619 ql_log(ql_log_info
, base_vha
, 0x0151,
5620 "HW State: FAILED.\n");
5621 qla82xx_device_state_handler(base_vha
);
5626 if (test_and_clear_bit(FCOE_CTX_RESET_NEEDED
,
5627 &base_vha
->dpc_flags
)) {
5629 ql_dbg(ql_dbg_dpc
, base_vha
, 0x4005,
5630 "FCoE context reset scheduled.\n");
5631 if (!(test_and_set_bit(ABORT_ISP_ACTIVE
,
5632 &base_vha
->dpc_flags
))) {
5633 if (qla82xx_fcoe_ctx_reset(base_vha
)) {
5634 /* FCoE-ctx reset failed.
5635 * Escalate to chip-reset
5637 set_bit(ISP_ABORT_NEEDED
,
5638 &base_vha
->dpc_flags
);
5640 clear_bit(ABORT_ISP_ACTIVE
,
5641 &base_vha
->dpc_flags
);
5644 ql_dbg(ql_dbg_dpc
, base_vha
, 0x4006,
5645 "FCoE context reset end.\n");
5647 } else if (IS_QLAFX00(ha
)) {
5648 if (test_and_clear_bit(ISP_UNRECOVERABLE
,
5649 &base_vha
->dpc_flags
)) {
5650 ql_dbg(ql_dbg_dpc
, base_vha
, 0x4020,
5651 "Firmware Reset Recovery\n");
5652 if (qlafx00_reset_initialize(base_vha
)) {
5653 /* Failed. Abort isp later. */
5654 if (!test_bit(UNLOADING
,
5655 &base_vha
->dpc_flags
)) {
5656 set_bit(ISP_UNRECOVERABLE
,
5657 &base_vha
->dpc_flags
);
5658 ql_dbg(ql_dbg_dpc
, base_vha
,
5660 "Reset Recovery Failed\n");
5665 if (test_and_clear_bit(FX00_TARGET_SCAN
,
5666 &base_vha
->dpc_flags
)) {
5667 ql_dbg(ql_dbg_dpc
, base_vha
, 0x4022,
5668 "ISPFx00 Target Scan scheduled\n");
5669 if (qlafx00_rescan_isp(base_vha
)) {
5670 if (!test_bit(UNLOADING
,
5671 &base_vha
->dpc_flags
))
5672 set_bit(ISP_UNRECOVERABLE
,
5673 &base_vha
->dpc_flags
);
5674 ql_dbg(ql_dbg_dpc
, base_vha
, 0x401e,
5675 "ISPFx00 Target Scan Failed\n");
5677 ql_dbg(ql_dbg_dpc
, base_vha
, 0x401f,
5678 "ISPFx00 Target Scan End\n");
5680 if (test_and_clear_bit(FX00_HOST_INFO_RESEND
,
5681 &base_vha
->dpc_flags
)) {
5682 ql_dbg(ql_dbg_dpc
, base_vha
, 0x4023,
5683 "ISPFx00 Host Info resend scheduled\n");
5684 qlafx00_fx_disc(base_vha
,
5685 &base_vha
->hw
->mr
.fcport
,
5686 FXDISC_REG_HOST_INFO
);
5690 if (test_and_clear_bit(ISP_ABORT_NEEDED
,
5691 &base_vha
->dpc_flags
)) {
5693 ql_dbg(ql_dbg_dpc
, base_vha
, 0x4007,
5694 "ISP abort scheduled.\n");
5695 if (!(test_and_set_bit(ABORT_ISP_ACTIVE
,
5696 &base_vha
->dpc_flags
))) {
5698 if (ha
->isp_ops
->abort_isp(base_vha
)) {
5699 /* failed. retry later */
5700 set_bit(ISP_ABORT_NEEDED
,
5701 &base_vha
->dpc_flags
);
5703 clear_bit(ABORT_ISP_ACTIVE
,
5704 &base_vha
->dpc_flags
);
5707 ql_dbg(ql_dbg_dpc
, base_vha
, 0x4008,
5708 "ISP abort end.\n");
5711 if (test_and_clear_bit(FCPORT_UPDATE_NEEDED
,
5712 &base_vha
->dpc_flags
)) {
5713 qla2x00_update_fcports(base_vha
);
5717 goto loop_resync_check
;
5719 if (test_bit(ISP_QUIESCE_NEEDED
, &base_vha
->dpc_flags
)) {
5720 ql_dbg(ql_dbg_dpc
, base_vha
, 0x4009,
5721 "Quiescence mode scheduled.\n");
5722 if (IS_P3P_TYPE(ha
)) {
5724 qla82xx_device_state_handler(base_vha
);
5726 qla8044_device_state_handler(base_vha
);
5727 clear_bit(ISP_QUIESCE_NEEDED
,
5728 &base_vha
->dpc_flags
);
5729 if (!ha
->flags
.quiesce_owner
) {
5730 qla2x00_perform_loop_resync(base_vha
);
5731 if (IS_QLA82XX(ha
)) {
5732 qla82xx_idc_lock(ha
);
5733 qla82xx_clear_qsnt_ready(
5735 qla82xx_idc_unlock(ha
);
5736 } else if (IS_QLA8044(ha
)) {
5737 qla8044_idc_lock(ha
);
5738 qla8044_clear_qsnt_ready(
5740 qla8044_idc_unlock(ha
);
5744 clear_bit(ISP_QUIESCE_NEEDED
,
5745 &base_vha
->dpc_flags
);
5746 qla2x00_quiesce_io(base_vha
);
5748 ql_dbg(ql_dbg_dpc
, base_vha
, 0x400a,
5749 "Quiescence mode end.\n");
5752 if (test_and_clear_bit(RESET_MARKER_NEEDED
,
5753 &base_vha
->dpc_flags
) &&
5754 (!(test_and_set_bit(RESET_ACTIVE
, &base_vha
->dpc_flags
)))) {
5756 ql_dbg(ql_dbg_dpc
, base_vha
, 0x400b,
5757 "Reset marker scheduled.\n");
5758 qla2x00_rst_aen(base_vha
);
5759 clear_bit(RESET_ACTIVE
, &base_vha
->dpc_flags
);
5760 ql_dbg(ql_dbg_dpc
, base_vha
, 0x400c,
5761 "Reset marker end.\n");
5764 /* Retry each device up to login retry count */
5765 if ((test_and_clear_bit(RELOGIN_NEEDED
,
5766 &base_vha
->dpc_flags
)) &&
5767 !test_bit(LOOP_RESYNC_NEEDED
, &base_vha
->dpc_flags
) &&
5768 atomic_read(&base_vha
->loop_state
) != LOOP_DOWN
) {
5770 ql_dbg(ql_dbg_dpc
, base_vha
, 0x400d,
5771 "Relogin scheduled.\n");
5772 qla2x00_relogin(base_vha
);
5773 ql_dbg(ql_dbg_dpc
, base_vha
, 0x400e,
5777 if (test_and_clear_bit(LOOP_RESYNC_NEEDED
,
5778 &base_vha
->dpc_flags
)) {
5780 ql_dbg(ql_dbg_dpc
, base_vha
, 0x400f,
5781 "Loop resync scheduled.\n");
5783 if (!(test_and_set_bit(LOOP_RESYNC_ACTIVE
,
5784 &base_vha
->dpc_flags
))) {
5786 qla2x00_loop_resync(base_vha
);
5788 clear_bit(LOOP_RESYNC_ACTIVE
,
5789 &base_vha
->dpc_flags
);
5792 ql_dbg(ql_dbg_dpc
, base_vha
, 0x4010,
5793 "Loop resync end.\n");
5799 if (test_bit(NPIV_CONFIG_NEEDED
, &base_vha
->dpc_flags
) &&
5800 atomic_read(&base_vha
->loop_state
) == LOOP_READY
) {
5801 clear_bit(NPIV_CONFIG_NEEDED
, &base_vha
->dpc_flags
);
5802 qla2xxx_flash_npiv_conf(base_vha
);
5806 if (!ha
->interrupts_on
)
5807 ha
->isp_ops
->enable_intrs(ha
);
5809 if (test_and_clear_bit(BEACON_BLINK_NEEDED
,
5810 &base_vha
->dpc_flags
)) {
5811 if (ha
->beacon_blink_led
== 1)
5812 ha
->isp_ops
->beacon_blink(base_vha
);
5815 /* qpair online check */
5816 if (test_and_clear_bit(QPAIR_ONLINE_CHECK_NEEDED
,
5817 &base_vha
->dpc_flags
)) {
5818 if (ha
->flags
.eeh_busy
||
5819 ha
->flags
.pci_channel_io_perm_failure
)
5824 mutex_lock(&ha
->mq_lock
);
5825 list_for_each_entry(qpair
, &base_vha
->qp_list
,
5827 qpair
->online
= online
;
5828 mutex_unlock(&ha
->mq_lock
);
5831 if (!IS_QLAFX00(ha
))
5832 qla2x00_do_dpc_all_vps(base_vha
);
5836 set_current_state(TASK_INTERRUPTIBLE
);
5837 } /* End of while(1) */
5838 __set_current_state(TASK_RUNNING
);
5840 ql_dbg(ql_dbg_dpc
, base_vha
, 0x4011,
5841 "DPC handler exiting.\n");
5844 * Make sure that nobody tries to wake us up again.
5848 /* Cleanup any residual CTX SRBs. */
5849 qla2x00_abort_all_cmds(base_vha
, DID_NO_CONNECT
<< 16);
5855 qla2xxx_wake_dpc(struct scsi_qla_host
*vha
)
5857 struct qla_hw_data
*ha
= vha
->hw
;
5858 struct task_struct
*t
= ha
->dpc_thread
;
5860 if (!test_bit(UNLOADING
, &vha
->dpc_flags
) && t
)
5866 * Processes asynchronous reset.
5869 * ha = adapter block pointer.
5872 qla2x00_rst_aen(scsi_qla_host_t
*vha
)
5874 if (vha
->flags
.online
&& !vha
->flags
.reset_active
&&
5875 !atomic_read(&vha
->loop_down_timer
) &&
5876 !(test_bit(ABORT_ISP_ACTIVE
, &vha
->dpc_flags
))) {
5878 clear_bit(RESET_MARKER_NEEDED
, &vha
->dpc_flags
);
5881 * Issue marker command only when we are going to start
5884 vha
->marker_needed
= 1;
5885 } while (!atomic_read(&vha
->loop_down_timer
) &&
5886 (test_bit(RESET_MARKER_NEEDED
, &vha
->dpc_flags
)));
5890 /**************************************************************************
5896 * Context: Interrupt
5897 ***************************************************************************/
5899 qla2x00_timer(scsi_qla_host_t
*vha
)
5901 unsigned long cpu_flags
= 0;
5906 struct qla_hw_data
*ha
= vha
->hw
;
5907 struct req_que
*req
;
5909 if (ha
->flags
.eeh_busy
) {
5910 ql_dbg(ql_dbg_timer
, vha
, 0x6000,
5911 "EEH = %d, restarting timer.\n",
5912 ha
->flags
.eeh_busy
);
5913 qla2x00_restart_timer(vha
, WATCH_INTERVAL
);
5918 * Hardware read to raise pending EEH errors during mailbox waits. If
5919 * the read returns -1 then disable the board.
5921 if (!pci_channel_offline(ha
->pdev
)) {
5922 pci_read_config_word(ha
->pdev
, PCI_VENDOR_ID
, &w
);
5923 qla2x00_check_reg16_for_disconnect(vha
, w
);
5926 /* Make sure qla82xx_watchdog is run only for physical port */
5927 if (!vha
->vp_idx
&& IS_P3P_TYPE(ha
)) {
5928 if (test_bit(ISP_QUIESCE_NEEDED
, &vha
->dpc_flags
))
5931 qla82xx_watchdog(vha
);
5932 else if (IS_QLA8044(ha
))
5933 qla8044_watchdog(vha
);
5936 if (!vha
->vp_idx
&& IS_QLAFX00(ha
))
5937 qlafx00_timer_routine(vha
);
5939 /* Loop down handler. */
5940 if (atomic_read(&vha
->loop_down_timer
) > 0 &&
5941 !(test_bit(ABORT_ISP_ACTIVE
, &vha
->dpc_flags
)) &&
5942 !(test_bit(FCOE_CTX_RESET_NEEDED
, &vha
->dpc_flags
))
5943 && vha
->flags
.online
) {
5945 if (atomic_read(&vha
->loop_down_timer
) ==
5946 vha
->loop_down_abort_time
) {
5948 ql_log(ql_log_info
, vha
, 0x6008,
5949 "Loop down - aborting the queues before time expires.\n");
5951 if (!IS_QLA2100(ha
) && vha
->link_down_timeout
)
5952 atomic_set(&vha
->loop_state
, LOOP_DEAD
);
5955 * Schedule an ISP abort to return any FCP2-device
5958 /* NPIV - scan physical port only */
5960 spin_lock_irqsave(&ha
->hardware_lock
,
5962 req
= ha
->req_q_map
[0];
5964 index
< req
->num_outstanding_cmds
;
5968 sp
= req
->outstanding_cmds
[index
];
5971 if (sp
->cmd_type
!= TYPE_SRB
)
5973 if (sp
->type
!= SRB_SCSI_CMD
)
5976 if (!(sfcp
->flags
& FCF_FCP2_DEVICE
))
5980 set_bit(FCOE_CTX_RESET_NEEDED
,
5983 set_bit(ISP_ABORT_NEEDED
,
5987 spin_unlock_irqrestore(&ha
->hardware_lock
,
5993 /* if the loop has been down for 4 minutes, reinit adapter */
5994 if (atomic_dec_and_test(&vha
->loop_down_timer
) != 0) {
5995 if (!(vha
->device_flags
& DFLG_NO_CABLE
)) {
5996 ql_log(ql_log_warn
, vha
, 0x6009,
5997 "Loop down - aborting ISP.\n");
6000 set_bit(FCOE_CTX_RESET_NEEDED
,
6003 set_bit(ISP_ABORT_NEEDED
,
6007 ql_dbg(ql_dbg_timer
, vha
, 0x600a,
6008 "Loop down - seconds remaining %d.\n",
6009 atomic_read(&vha
->loop_down_timer
));
6011 /* Check if beacon LED needs to be blinked for physical host only */
6012 if (!vha
->vp_idx
&& (ha
->beacon_blink_led
== 1)) {
6013 /* There is no beacon_blink function for ISP82xx */
6014 if (!IS_P3P_TYPE(ha
)) {
6015 set_bit(BEACON_BLINK_NEEDED
, &vha
->dpc_flags
);
6020 /* Process any deferred work. */
6021 if (!list_empty(&vha
->work_list
))
6026 * see if the active AEN count has changed from what was last reported.
6028 if (atomic_read(&vha
->nvme_active_aen_cnt
) != vha
->nvme_last_rptd_aen
) {
6029 vha
->nvme_last_rptd_aen
=
6030 atomic_read(&vha
->nvme_active_aen_cnt
);
6031 ql_log(ql_log_info
, vha
, 0x3002,
6032 "reporting new aen count of %d to the fw\n",
6033 vha
->nvme_last_rptd_aen
);
6036 /* Schedule the DPC routine if needed */
6037 if ((test_bit(ISP_ABORT_NEEDED
, &vha
->dpc_flags
) ||
6038 test_bit(LOOP_RESYNC_NEEDED
, &vha
->dpc_flags
) ||
6039 test_bit(FCPORT_UPDATE_NEEDED
, &vha
->dpc_flags
) ||
6041 test_bit(RESET_MARKER_NEEDED
, &vha
->dpc_flags
) ||
6042 test_bit(BEACON_BLINK_NEEDED
, &vha
->dpc_flags
) ||
6043 test_bit(ISP_UNRECOVERABLE
, &vha
->dpc_flags
) ||
6044 test_bit(FCOE_CTX_RESET_NEEDED
, &vha
->dpc_flags
) ||
6045 test_bit(VP_DPC_NEEDED
, &vha
->dpc_flags
) ||
6046 test_bit(RELOGIN_NEEDED
, &vha
->dpc_flags
))) {
6047 ql_dbg(ql_dbg_timer
, vha
, 0x600b,
6048 "isp_abort_needed=%d loop_resync_needed=%d "
6049 "fcport_update_needed=%d start_dpc=%d "
6050 "reset_marker_needed=%d",
6051 test_bit(ISP_ABORT_NEEDED
, &vha
->dpc_flags
),
6052 test_bit(LOOP_RESYNC_NEEDED
, &vha
->dpc_flags
),
6053 test_bit(FCPORT_UPDATE_NEEDED
, &vha
->dpc_flags
),
6055 test_bit(RESET_MARKER_NEEDED
, &vha
->dpc_flags
));
6056 ql_dbg(ql_dbg_timer
, vha
, 0x600c,
6057 "beacon_blink_needed=%d isp_unrecoverable=%d "
6058 "fcoe_ctx_reset_needed=%d vp_dpc_needed=%d "
6059 "relogin_needed=%d.\n",
6060 test_bit(BEACON_BLINK_NEEDED
, &vha
->dpc_flags
),
6061 test_bit(ISP_UNRECOVERABLE
, &vha
->dpc_flags
),
6062 test_bit(FCOE_CTX_RESET_NEEDED
, &vha
->dpc_flags
),
6063 test_bit(VP_DPC_NEEDED
, &vha
->dpc_flags
),
6064 test_bit(RELOGIN_NEEDED
, &vha
->dpc_flags
));
6065 qla2xxx_wake_dpc(vha
);
6068 qla2x00_restart_timer(vha
, WATCH_INTERVAL
);
6071 /* Firmware interface routines. */
6074 #define FW_ISP21XX 0
6075 #define FW_ISP22XX 1
6076 #define FW_ISP2300 2
6077 #define FW_ISP2322 3
6078 #define FW_ISP24XX 4
6079 #define FW_ISP25XX 5
6080 #define FW_ISP81XX 6
6081 #define FW_ISP82XX 7
6082 #define FW_ISP2031 8
6083 #define FW_ISP8031 9
6084 #define FW_ISP27XX 10
6086 #define FW_FILE_ISP21XX "ql2100_fw.bin"
6087 #define FW_FILE_ISP22XX "ql2200_fw.bin"
6088 #define FW_FILE_ISP2300 "ql2300_fw.bin"
6089 #define FW_FILE_ISP2322 "ql2322_fw.bin"
6090 #define FW_FILE_ISP24XX "ql2400_fw.bin"
6091 #define FW_FILE_ISP25XX "ql2500_fw.bin"
6092 #define FW_FILE_ISP81XX "ql8100_fw.bin"
6093 #define FW_FILE_ISP82XX "ql8200_fw.bin"
6094 #define FW_FILE_ISP2031 "ql2600_fw.bin"
6095 #define FW_FILE_ISP8031 "ql8300_fw.bin"
6096 #define FW_FILE_ISP27XX "ql2700_fw.bin"
6099 static DEFINE_MUTEX(qla_fw_lock
);
6101 static struct fw_blob qla_fw_blobs
[FW_BLOBS
] = {
6102 { .name
= FW_FILE_ISP21XX
, .segs
= { 0x1000, 0 }, },
6103 { .name
= FW_FILE_ISP22XX
, .segs
= { 0x1000, 0 }, },
6104 { .name
= FW_FILE_ISP2300
, .segs
= { 0x800, 0 }, },
6105 { .name
= FW_FILE_ISP2322
, .segs
= { 0x800, 0x1c000, 0x1e000, 0 }, },
6106 { .name
= FW_FILE_ISP24XX
, },
6107 { .name
= FW_FILE_ISP25XX
, },
6108 { .name
= FW_FILE_ISP81XX
, },
6109 { .name
= FW_FILE_ISP82XX
, },
6110 { .name
= FW_FILE_ISP2031
, },
6111 { .name
= FW_FILE_ISP8031
, },
6112 { .name
= FW_FILE_ISP27XX
, },
6116 qla2x00_request_firmware(scsi_qla_host_t
*vha
)
6118 struct qla_hw_data
*ha
= vha
->hw
;
6119 struct fw_blob
*blob
;
6121 if (IS_QLA2100(ha
)) {
6122 blob
= &qla_fw_blobs
[FW_ISP21XX
];
6123 } else if (IS_QLA2200(ha
)) {
6124 blob
= &qla_fw_blobs
[FW_ISP22XX
];
6125 } else if (IS_QLA2300(ha
) || IS_QLA2312(ha
) || IS_QLA6312(ha
)) {
6126 blob
= &qla_fw_blobs
[FW_ISP2300
];
6127 } else if (IS_QLA2322(ha
) || IS_QLA6322(ha
)) {
6128 blob
= &qla_fw_blobs
[FW_ISP2322
];
6129 } else if (IS_QLA24XX_TYPE(ha
)) {
6130 blob
= &qla_fw_blobs
[FW_ISP24XX
];
6131 } else if (IS_QLA25XX(ha
)) {
6132 blob
= &qla_fw_blobs
[FW_ISP25XX
];
6133 } else if (IS_QLA81XX(ha
)) {
6134 blob
= &qla_fw_blobs
[FW_ISP81XX
];
6135 } else if (IS_QLA82XX(ha
)) {
6136 blob
= &qla_fw_blobs
[FW_ISP82XX
];
6137 } else if (IS_QLA2031(ha
)) {
6138 blob
= &qla_fw_blobs
[FW_ISP2031
];
6139 } else if (IS_QLA8031(ha
)) {
6140 blob
= &qla_fw_blobs
[FW_ISP8031
];
6141 } else if (IS_QLA27XX(ha
)) {
6142 blob
= &qla_fw_blobs
[FW_ISP27XX
];
6147 mutex_lock(&qla_fw_lock
);
6151 if (request_firmware(&blob
->fw
, blob
->name
, &ha
->pdev
->dev
)) {
6152 ql_log(ql_log_warn
, vha
, 0x0063,
6153 "Failed to load firmware image (%s).\n", blob
->name
);
6160 mutex_unlock(&qla_fw_lock
);
6165 qla2x00_release_firmware(void)
6169 mutex_lock(&qla_fw_lock
);
6170 for (idx
= 0; idx
< FW_BLOBS
; idx
++)
6171 release_firmware(qla_fw_blobs
[idx
].fw
);
6172 mutex_unlock(&qla_fw_lock
);
6175 static pci_ers_result_t
6176 qla2xxx_pci_error_detected(struct pci_dev
*pdev
, pci_channel_state_t state
)
6178 scsi_qla_host_t
*vha
= pci_get_drvdata(pdev
);
6179 struct qla_hw_data
*ha
= vha
->hw
;
6181 ql_dbg(ql_dbg_aer
, vha
, 0x9000,
6182 "PCI error detected, state %x.\n", state
);
6185 case pci_channel_io_normal
:
6186 ha
->flags
.eeh_busy
= 0;
6187 if (ql2xmqsupport
) {
6188 set_bit(QPAIR_ONLINE_CHECK_NEEDED
, &vha
->dpc_flags
);
6189 qla2xxx_wake_dpc(vha
);
6191 return PCI_ERS_RESULT_CAN_RECOVER
;
6192 case pci_channel_io_frozen
:
6193 ha
->flags
.eeh_busy
= 1;
6194 /* For ISP82XX complete any pending mailbox cmd */
6195 if (IS_QLA82XX(ha
)) {
6196 ha
->flags
.isp82xx_fw_hung
= 1;
6197 ql_dbg(ql_dbg_aer
, vha
, 0x9001, "Pci channel io frozen\n");
6198 qla82xx_clear_pending_mbx(vha
);
6200 qla2x00_free_irqs(vha
);
6201 pci_disable_device(pdev
);
6202 /* Return back all IOs */
6203 qla2x00_abort_all_cmds(vha
, DID_RESET
<< 16);
6204 if (ql2xmqsupport
) {
6205 set_bit(QPAIR_ONLINE_CHECK_NEEDED
, &vha
->dpc_flags
);
6206 qla2xxx_wake_dpc(vha
);
6208 return PCI_ERS_RESULT_NEED_RESET
;
6209 case pci_channel_io_perm_failure
:
6210 ha
->flags
.pci_channel_io_perm_failure
= 1;
6211 qla2x00_abort_all_cmds(vha
, DID_NO_CONNECT
<< 16);
6212 if (ql2xmqsupport
) {
6213 set_bit(QPAIR_ONLINE_CHECK_NEEDED
, &vha
->dpc_flags
);
6214 qla2xxx_wake_dpc(vha
);
6216 return PCI_ERS_RESULT_DISCONNECT
;
6218 return PCI_ERS_RESULT_NEED_RESET
;
6221 static pci_ers_result_t
6222 qla2xxx_pci_mmio_enabled(struct pci_dev
*pdev
)
6224 int risc_paused
= 0;
6226 unsigned long flags
;
6227 scsi_qla_host_t
*base_vha
= pci_get_drvdata(pdev
);
6228 struct qla_hw_data
*ha
= base_vha
->hw
;
6229 struct device_reg_2xxx __iomem
*reg
= &ha
->iobase
->isp
;
6230 struct device_reg_24xx __iomem
*reg24
= &ha
->iobase
->isp24
;
6233 return PCI_ERS_RESULT_RECOVERED
;
6235 spin_lock_irqsave(&ha
->hardware_lock
, flags
);
6236 if (IS_QLA2100(ha
) || IS_QLA2200(ha
)){
6237 stat
= RD_REG_DWORD(®
->hccr
);
6238 if (stat
& HCCR_RISC_PAUSE
)
6240 } else if (IS_QLA23XX(ha
)) {
6241 stat
= RD_REG_DWORD(®
->u
.isp2300
.host_status
);
6242 if (stat
& HSR_RISC_PAUSED
)
6244 } else if (IS_FWI2_CAPABLE(ha
)) {
6245 stat
= RD_REG_DWORD(®24
->host_status
);
6246 if (stat
& HSRX_RISC_PAUSED
)
6249 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
6252 ql_log(ql_log_info
, base_vha
, 0x9003,
6253 "RISC paused -- mmio_enabled, Dumping firmware.\n");
6254 ha
->isp_ops
->fw_dump(base_vha
, 0);
6256 return PCI_ERS_RESULT_NEED_RESET
;
6258 return PCI_ERS_RESULT_RECOVERED
;
6262 qla82xx_error_recovery(scsi_qla_host_t
*base_vha
)
6264 uint32_t rval
= QLA_FUNCTION_FAILED
;
6265 uint32_t drv_active
= 0;
6266 struct qla_hw_data
*ha
= base_vha
->hw
;
6268 struct pci_dev
*other_pdev
= NULL
;
6270 ql_dbg(ql_dbg_aer
, base_vha
, 0x9006,
6271 "Entered %s.\n", __func__
);
6273 set_bit(ABORT_ISP_ACTIVE
, &base_vha
->dpc_flags
);
6275 if (base_vha
->flags
.online
) {
6276 /* Abort all outstanding commands,
6277 * so as to be requeued later */
6278 qla2x00_abort_isp_cleanup(base_vha
);
6282 fn
= PCI_FUNC(ha
->pdev
->devfn
);
6285 ql_dbg(ql_dbg_aer
, base_vha
, 0x9007,
6286 "Finding pci device at function = 0x%x.\n", fn
);
6288 pci_get_domain_bus_and_slot(pci_domain_nr(ha
->pdev
->bus
),
6289 ha
->pdev
->bus
->number
, PCI_DEVFN(PCI_SLOT(ha
->pdev
->devfn
),
6294 if (atomic_read(&other_pdev
->enable_cnt
)) {
6295 ql_dbg(ql_dbg_aer
, base_vha
, 0x9008,
6296 "Found PCI func available and enable at 0x%x.\n",
6298 pci_dev_put(other_pdev
);
6301 pci_dev_put(other_pdev
);
6306 ql_dbg(ql_dbg_aer
, base_vha
, 0x9009,
6307 "This devfn is reset owner = 0x%x.\n",
6309 qla82xx_idc_lock(ha
);
6311 qla82xx_wr_32(ha
, QLA82XX_CRB_DEV_STATE
,
6312 QLA8XXX_DEV_INITIALIZING
);
6314 qla82xx_wr_32(ha
, QLA82XX_CRB_DRV_IDC_VERSION
,
6315 QLA82XX_IDC_VERSION
);
6317 drv_active
= qla82xx_rd_32(ha
, QLA82XX_CRB_DRV_ACTIVE
);
6318 ql_dbg(ql_dbg_aer
, base_vha
, 0x900a,
6319 "drv_active = 0x%x.\n", drv_active
);
6321 qla82xx_idc_unlock(ha
);
6322 /* Reset if device is not already reset
6323 * drv_active would be 0 if a reset has already been done
6326 rval
= qla82xx_start_firmware(base_vha
);
6329 qla82xx_idc_lock(ha
);
6331 if (rval
!= QLA_SUCCESS
) {
6332 ql_log(ql_log_info
, base_vha
, 0x900b,
6333 "HW State: FAILED.\n");
6334 qla82xx_clear_drv_active(ha
);
6335 qla82xx_wr_32(ha
, QLA82XX_CRB_DEV_STATE
,
6336 QLA8XXX_DEV_FAILED
);
6338 ql_log(ql_log_info
, base_vha
, 0x900c,
6339 "HW State: READY.\n");
6340 qla82xx_wr_32(ha
, QLA82XX_CRB_DEV_STATE
,
6342 qla82xx_idc_unlock(ha
);
6343 ha
->flags
.isp82xx_fw_hung
= 0;
6344 rval
= qla82xx_restart_isp(base_vha
);
6345 qla82xx_idc_lock(ha
);
6346 /* Clear driver state register */
6347 qla82xx_wr_32(ha
, QLA82XX_CRB_DRV_STATE
, 0);
6348 qla82xx_set_drv_active(base_vha
);
6350 qla82xx_idc_unlock(ha
);
6352 ql_dbg(ql_dbg_aer
, base_vha
, 0x900d,
6353 "This devfn is not reset owner = 0x%x.\n",
6355 if ((qla82xx_rd_32(ha
, QLA82XX_CRB_DEV_STATE
) ==
6356 QLA8XXX_DEV_READY
)) {
6357 ha
->flags
.isp82xx_fw_hung
= 0;
6358 rval
= qla82xx_restart_isp(base_vha
);
6359 qla82xx_idc_lock(ha
);
6360 qla82xx_set_drv_active(base_vha
);
6361 qla82xx_idc_unlock(ha
);
6364 clear_bit(ABORT_ISP_ACTIVE
, &base_vha
->dpc_flags
);
6369 static pci_ers_result_t
6370 qla2xxx_pci_slot_reset(struct pci_dev
*pdev
)
6372 pci_ers_result_t ret
= PCI_ERS_RESULT_DISCONNECT
;
6373 scsi_qla_host_t
*base_vha
= pci_get_drvdata(pdev
);
6374 struct qla_hw_data
*ha
= base_vha
->hw
;
6375 struct rsp_que
*rsp
;
6376 int rc
, retries
= 10;
6378 ql_dbg(ql_dbg_aer
, base_vha
, 0x9004,
6381 /* Workaround: qla2xxx driver which access hardware earlier
6382 * needs error state to be pci_channel_io_online.
6383 * Otherwise mailbox command timesout.
6385 pdev
->error_state
= pci_channel_io_normal
;
6387 pci_restore_state(pdev
);
6389 /* pci_restore_state() clears the saved_state flag of the device
6390 * save restored state which resets saved_state flag
6392 pci_save_state(pdev
);
6395 rc
= pci_enable_device_mem(pdev
);
6397 rc
= pci_enable_device(pdev
);
6400 ql_log(ql_log_warn
, base_vha
, 0x9005,
6401 "Can't re-enable PCI device after reset.\n");
6402 goto exit_slot_reset
;
6405 rsp
= ha
->rsp_q_map
[0];
6406 if (qla2x00_request_irqs(ha
, rsp
))
6407 goto exit_slot_reset
;
6409 if (ha
->isp_ops
->pci_config(base_vha
))
6410 goto exit_slot_reset
;
6412 if (IS_QLA82XX(ha
)) {
6413 if (qla82xx_error_recovery(base_vha
) == QLA_SUCCESS
) {
6414 ret
= PCI_ERS_RESULT_RECOVERED
;
6415 goto exit_slot_reset
;
6417 goto exit_slot_reset
;
6420 while (ha
->flags
.mbox_busy
&& retries
--)
6423 set_bit(ABORT_ISP_ACTIVE
, &base_vha
->dpc_flags
);
6424 if (ha
->isp_ops
->abort_isp(base_vha
) == QLA_SUCCESS
)
6425 ret
= PCI_ERS_RESULT_RECOVERED
;
6426 clear_bit(ABORT_ISP_ACTIVE
, &base_vha
->dpc_flags
);
6430 ql_dbg(ql_dbg_aer
, base_vha
, 0x900e,
6431 "slot_reset return %x.\n", ret
);
6437 qla2xxx_pci_resume(struct pci_dev
*pdev
)
6439 scsi_qla_host_t
*base_vha
= pci_get_drvdata(pdev
);
6440 struct qla_hw_data
*ha
= base_vha
->hw
;
6443 ql_dbg(ql_dbg_aer
, base_vha
, 0x900f,
6446 ret
= qla2x00_wait_for_hba_online(base_vha
);
6447 if (ret
!= QLA_SUCCESS
) {
6448 ql_log(ql_log_fatal
, base_vha
, 0x9002,
6449 "The device failed to resume I/O from slot/link_reset.\n");
6452 pci_cleanup_aer_uncorrect_error_status(pdev
);
6454 ha
->flags
.eeh_busy
= 0;
6458 qla83xx_disable_laser(scsi_qla_host_t
*vha
)
6460 uint32_t reg
, data
, fn
;
6461 struct qla_hw_data
*ha
= vha
->hw
;
6462 struct device_reg_24xx __iomem
*isp_reg
= &ha
->iobase
->isp24
;
6464 /* pci func #/port # */
6465 ql_dbg(ql_dbg_init
, vha
, 0x004b,
6466 "Disabling Laser for hba: %p\n", vha
);
6468 fn
= (RD_REG_DWORD(&isp_reg
->ctrl_status
) &
6469 (BIT_15
|BIT_14
|BIT_13
|BIT_12
));
6478 data
= LASER_OFF_2031
;
6480 qla83xx_wr_reg(vha
, reg
, data
);
6483 static int qla2xxx_map_queues(struct Scsi_Host
*shost
)
6485 scsi_qla_host_t
*vha
= (scsi_qla_host_t
*)shost
->hostdata
;
6487 return blk_mq_pci_map_queues(&shost
->tag_set
, vha
->hw
->pdev
);
6490 static const struct pci_error_handlers qla2xxx_err_handler
= {
6491 .error_detected
= qla2xxx_pci_error_detected
,
6492 .mmio_enabled
= qla2xxx_pci_mmio_enabled
,
6493 .slot_reset
= qla2xxx_pci_slot_reset
,
6494 .resume
= qla2xxx_pci_resume
,
6497 static struct pci_device_id qla2xxx_pci_tbl
[] = {
6498 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC
, PCI_DEVICE_ID_QLOGIC_ISP2100
) },
6499 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC
, PCI_DEVICE_ID_QLOGIC_ISP2200
) },
6500 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC
, PCI_DEVICE_ID_QLOGIC_ISP2300
) },
6501 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC
, PCI_DEVICE_ID_QLOGIC_ISP2312
) },
6502 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC
, PCI_DEVICE_ID_QLOGIC_ISP2322
) },
6503 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC
, PCI_DEVICE_ID_QLOGIC_ISP6312
) },
6504 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC
, PCI_DEVICE_ID_QLOGIC_ISP6322
) },
6505 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC
, PCI_DEVICE_ID_QLOGIC_ISP2422
) },
6506 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC
, PCI_DEVICE_ID_QLOGIC_ISP2432
) },
6507 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC
, PCI_DEVICE_ID_QLOGIC_ISP8432
) },
6508 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC
, PCI_DEVICE_ID_QLOGIC_ISP5422
) },
6509 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC
, PCI_DEVICE_ID_QLOGIC_ISP5432
) },
6510 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC
, PCI_DEVICE_ID_QLOGIC_ISP2532
) },
6511 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC
, PCI_DEVICE_ID_QLOGIC_ISP2031
) },
6512 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC
, PCI_DEVICE_ID_QLOGIC_ISP8001
) },
6513 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC
, PCI_DEVICE_ID_QLOGIC_ISP8021
) },
6514 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC
, PCI_DEVICE_ID_QLOGIC_ISP8031
) },
6515 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC
, PCI_DEVICE_ID_QLOGIC_ISPF001
) },
6516 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC
, PCI_DEVICE_ID_QLOGIC_ISP8044
) },
6517 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC
, PCI_DEVICE_ID_QLOGIC_ISP2071
) },
6518 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC
, PCI_DEVICE_ID_QLOGIC_ISP2271
) },
6519 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC
, PCI_DEVICE_ID_QLOGIC_ISP2261
) },
6522 MODULE_DEVICE_TABLE(pci
, qla2xxx_pci_tbl
);
6524 static struct pci_driver qla2xxx_pci_driver
= {
6525 .name
= QLA2XXX_DRIVER_NAME
,
6527 .owner
= THIS_MODULE
,
6529 .id_table
= qla2xxx_pci_tbl
,
6530 .probe
= qla2x00_probe_one
,
6531 .remove
= qla2x00_remove_one
,
6532 .shutdown
= qla2x00_shutdown
,
6533 .err_handler
= &qla2xxx_err_handler
,
6536 static const struct file_operations apidev_fops
= {
6537 .owner
= THIS_MODULE
,
6538 .llseek
= noop_llseek
,
6542 * qla2x00_module_init - Module initialization.
6545 qla2x00_module_init(void)
6549 /* Allocate cache for SRBs. */
6550 srb_cachep
= kmem_cache_create("qla2xxx_srbs", sizeof(srb_t
), 0,
6551 SLAB_HWCACHE_ALIGN
, NULL
);
6552 if (srb_cachep
== NULL
) {
6553 ql_log(ql_log_fatal
, NULL
, 0x0001,
6554 "Unable to allocate SRB cache...Failing load!.\n");
6558 /* Initialize target kmem_cache and mem_pools */
6561 kmem_cache_destroy(srb_cachep
);
6563 } else if (ret
> 0) {
6565 * If initiator mode is explictly disabled by qlt_init(),
6566 * prevent scsi_transport_fc.c:fc_scsi_scan_rport() from
6567 * performing scsi_scan_target() during LOOP UP event.
6569 qla2xxx_transport_functions
.disable_target_scan
= 1;
6570 qla2xxx_transport_vport_functions
.disable_target_scan
= 1;
6573 /* Derive version string. */
6574 strcpy(qla2x00_version_str
, QLA2XXX_VERSION
);
6575 if (ql2xextended_error_logging
)
6576 strcat(qla2x00_version_str
, "-debug");
6578 qla2xxx_transport_template
=
6579 fc_attach_transport(&qla2xxx_transport_functions
);
6580 if (!qla2xxx_transport_template
) {
6581 kmem_cache_destroy(srb_cachep
);
6582 ql_log(ql_log_fatal
, NULL
, 0x0002,
6583 "fc_attach_transport failed...Failing load!.\n");
6588 apidev_major
= register_chrdev(0, QLA2XXX_APIDEV
, &apidev_fops
);
6589 if (apidev_major
< 0) {
6590 ql_log(ql_log_fatal
, NULL
, 0x0003,
6591 "Unable to register char device %s.\n", QLA2XXX_APIDEV
);
6594 qla2xxx_transport_vport_template
=
6595 fc_attach_transport(&qla2xxx_transport_vport_functions
);
6596 if (!qla2xxx_transport_vport_template
) {
6597 kmem_cache_destroy(srb_cachep
);
6599 fc_release_transport(qla2xxx_transport_template
);
6600 ql_log(ql_log_fatal
, NULL
, 0x0004,
6601 "fc_attach_transport vport failed...Failing load!.\n");
6604 ql_log(ql_log_info
, NULL
, 0x0005,
6605 "QLogic Fibre Channel HBA Driver: %s.\n",
6606 qla2x00_version_str
);
6607 ret
= pci_register_driver(&qla2xxx_pci_driver
);
6609 kmem_cache_destroy(srb_cachep
);
6611 fc_release_transport(qla2xxx_transport_template
);
6612 fc_release_transport(qla2xxx_transport_vport_template
);
6613 ql_log(ql_log_fatal
, NULL
, 0x0006,
6614 "pci_register_driver failed...ret=%d Failing load!.\n",
6621 * qla2x00_module_exit - Module cleanup.
6624 qla2x00_module_exit(void)
6626 unregister_chrdev(apidev_major
, QLA2XXX_APIDEV
);
6627 pci_unregister_driver(&qla2xxx_pci_driver
);
6628 qla2x00_release_firmware();
6629 kmem_cache_destroy(srb_cachep
);
6632 kmem_cache_destroy(ctx_cachep
);
6633 fc_release_transport(qla2xxx_transport_template
);
6634 fc_release_transport(qla2xxx_transport_vport_template
);
6637 module_init(qla2x00_module_init
);
6638 module_exit(qla2x00_module_exit
);
6640 MODULE_AUTHOR("QLogic Corporation");
6641 MODULE_DESCRIPTION("QLogic Fibre Channel HBA Driver");
6642 MODULE_LICENSE("GPL");
6643 MODULE_VERSION(QLA2XXX_VERSION
);
6644 MODULE_FIRMWARE(FW_FILE_ISP21XX
);
6645 MODULE_FIRMWARE(FW_FILE_ISP22XX
);
6646 MODULE_FIRMWARE(FW_FILE_ISP2300
);
6647 MODULE_FIRMWARE(FW_FILE_ISP2322
);
6648 MODULE_FIRMWARE(FW_FILE_ISP24XX
);
6649 MODULE_FIRMWARE(FW_FILE_ISP25XX
);