2 * QLogic Fibre Channel HBA Driver
3 * Copyright (c) 2003-2011 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>
17 #include <scsi/scsi_tcq.h>
18 #include <scsi/scsicam.h>
19 #include <scsi/scsi_transport.h>
20 #include <scsi/scsi_transport_fc.h>
25 char qla2x00_version_str
[40];
27 static int apidev_major
;
30 * SRB allocation cache
32 static struct kmem_cache
*srb_cachep
;
35 * CT6 CTX allocation cache
37 static struct kmem_cache
*ctx_cachep
;
39 * error level for logging
41 int ql_errlev
= ql_log_all
;
43 int ql2xlogintimeout
= 20;
44 module_param(ql2xlogintimeout
, int, S_IRUGO
);
45 MODULE_PARM_DESC(ql2xlogintimeout
,
46 "Login timeout value in seconds.");
48 int qlport_down_retry
;
49 module_param(qlport_down_retry
, int, S_IRUGO
);
50 MODULE_PARM_DESC(qlport_down_retry
,
51 "Maximum number of command retries to a port that returns "
52 "a PORT-DOWN status.");
54 int ql2xplogiabsentdevice
;
55 module_param(ql2xplogiabsentdevice
, int, S_IRUGO
|S_IWUSR
);
56 MODULE_PARM_DESC(ql2xplogiabsentdevice
,
57 "Option to enable PLOGI to devices that are not present after "
58 "a Fabric scan. This is needed for several broken switches. "
59 "Default is 0 - no PLOGI. 1 - perfom PLOGI.");
61 int ql2xloginretrycount
= 0;
62 module_param(ql2xloginretrycount
, int, S_IRUGO
);
63 MODULE_PARM_DESC(ql2xloginretrycount
,
64 "Specify an alternate value for the NVRAM login retry count.");
66 int ql2xallocfwdump
= 1;
67 module_param(ql2xallocfwdump
, int, S_IRUGO
);
68 MODULE_PARM_DESC(ql2xallocfwdump
,
69 "Option to enable allocation of memory for a firmware dump "
70 "during HBA initialization. Memory allocation requirements "
71 "vary by ISP type. Default is 1 - allocate memory.");
73 int ql2xextended_error_logging
;
74 module_param(ql2xextended_error_logging
, int, S_IRUGO
|S_IWUSR
);
75 MODULE_PARM_DESC(ql2xextended_error_logging
,
76 "Option to enable extended error logging,\n"
77 "\t\tDefault is 0 - no logging. 0x40000000 - Module Init & Probe.\n"
78 "\t\t0x20000000 - Mailbox Cmnds. 0x10000000 - Device Discovery.\n"
79 "\t\t0x08000000 - IO tracing. 0x04000000 - DPC Thread.\n"
80 "\t\t0x02000000 - Async events. 0x01000000 - Timer routines.\n"
81 "\t\t0x00800000 - User space. 0x00400000 - Task Management.\n"
82 "\t\t0x00200000 - AER/EEH. 0x00100000 - Multi Q.\n"
83 "\t\t0x00080000 - P3P Specific. 0x00040000 - Virtual Port.\n"
84 "\t\t0x00020000 - Buffer Dump. 0x00010000 - Misc.\n"
85 "\t\t0x7fffffff - For enabling all logs, can be too many logs.\n"
86 "\t\tDo LOGICAL OR of the value to enable more than one level");
88 int ql2xshiftctondsd
= 6;
89 module_param(ql2xshiftctondsd
, int, S_IRUGO
);
90 MODULE_PARM_DESC(ql2xshiftctondsd
,
91 "Set to control shifting of command type processing "
92 "based on total number of SG elements.");
94 static void qla2x00_free_device(scsi_qla_host_t
*);
97 module_param(ql2xfdmienable
, int, S_IRUGO
);
98 MODULE_PARM_DESC(ql2xfdmienable
,
99 "Enables FDMI registrations. "
100 "0 - no FDMI. Default is 1 - perform FDMI.");
102 #define MAX_Q_DEPTH 32
103 static int ql2xmaxqdepth
= MAX_Q_DEPTH
;
104 module_param(ql2xmaxqdepth
, int, S_IRUGO
|S_IWUSR
);
105 MODULE_PARM_DESC(ql2xmaxqdepth
,
106 "Maximum queue depth to report for target devices.");
108 /* Do not change the value of this after module load */
109 int ql2xenabledif
= 1;
110 module_param(ql2xenabledif
, int, S_IRUGO
|S_IWUSR
);
111 MODULE_PARM_DESC(ql2xenabledif
,
112 " Enable T10-CRC-DIF "
113 " Default is 0 - No DIF Support. 1 - Enable it");
115 int ql2xenablehba_err_chk
;
116 module_param(ql2xenablehba_err_chk
, int, S_IRUGO
|S_IWUSR
);
117 MODULE_PARM_DESC(ql2xenablehba_err_chk
,
118 " Enable T10-CRC-DIF Error isolation by HBA"
119 " Default is 0 - Error isolation disabled, 1 - Enable it");
121 int ql2xiidmaenable
=1;
122 module_param(ql2xiidmaenable
, int, S_IRUGO
);
123 MODULE_PARM_DESC(ql2xiidmaenable
,
124 "Enables iIDMA settings "
125 "Default is 1 - perform iIDMA. 0 - no iIDMA.");
127 int ql2xmaxqueues
= 1;
128 module_param(ql2xmaxqueues
, int, S_IRUGO
);
129 MODULE_PARM_DESC(ql2xmaxqueues
,
130 "Enables MQ settings "
131 "Default is 1 for single queue. Set it to number "
132 "of queues in MQ mode.");
134 int ql2xmultique_tag
;
135 module_param(ql2xmultique_tag
, int, S_IRUGO
);
136 MODULE_PARM_DESC(ql2xmultique_tag
,
137 "Enables CPU affinity settings for the driver "
138 "Default is 0 for no affinity of request and response IO. "
139 "Set it to 1 to turn on the cpu affinity.");
142 module_param(ql2xfwloadbin
, int, S_IRUGO
);
143 MODULE_PARM_DESC(ql2xfwloadbin
,
144 "Option to specify location from which to load ISP firmware:.\n"
145 " 2 -- load firmware via the request_firmware() (hotplug).\n"
147 " 1 -- load firmware from flash.\n"
148 " 0 -- use default semantics.\n");
151 module_param(ql2xetsenable
, int, S_IRUGO
);
152 MODULE_PARM_DESC(ql2xetsenable
,
153 "Enables firmware ETS burst."
154 "Default is 0 - skip ETS enablement.");
157 module_param(ql2xdbwr
, int, S_IRUGO
);
158 MODULE_PARM_DESC(ql2xdbwr
,
159 "Option to specify scheme for request queue posting.\n"
160 " 0 -- Regular doorbell.\n"
161 " 1 -- CAMRAM doorbell (faster).\n");
163 int ql2xtargetreset
= 1;
164 module_param(ql2xtargetreset
, int, S_IRUGO
);
165 MODULE_PARM_DESC(ql2xtargetreset
,
166 "Enable target reset."
167 "Default is 1 - use hw defaults.");
170 module_param(ql2xgffidenable
, int, S_IRUGO
);
171 MODULE_PARM_DESC(ql2xgffidenable
,
172 "Enables GFF_ID checks of port type. "
173 "Default is 0 - Do not use GFF_ID information.");
175 int ql2xasynctmfenable
;
176 module_param(ql2xasynctmfenable
, int, S_IRUGO
);
177 MODULE_PARM_DESC(ql2xasynctmfenable
,
178 "Enables issue of TM IOCBs asynchronously via IOCB mechanism"
179 "Default is 0 - Issue TM IOCBs via mailbox mechanism.");
181 int ql2xdontresethba
;
182 module_param(ql2xdontresethba
, int, S_IRUGO
);
183 MODULE_PARM_DESC(ql2xdontresethba
,
184 "Option to specify reset behaviour.\n"
185 " 0 (Default) -- Reset on failure.\n"
186 " 1 -- Do not reset on failure.\n");
188 uint ql2xmaxlun
= MAX_LUNS
;
189 module_param(ql2xmaxlun
, uint
, S_IRUGO
);
190 MODULE_PARM_DESC(ql2xmaxlun
,
191 "Defines the maximum LU number to register with the SCSI "
192 "midlayer. Default is 65535.");
195 * SCSI host template entry points
197 static int qla2xxx_slave_configure(struct scsi_device
* device
);
198 static int qla2xxx_slave_alloc(struct scsi_device
*);
199 static int qla2xxx_scan_finished(struct Scsi_Host
*, unsigned long time
);
200 static void qla2xxx_scan_start(struct Scsi_Host
*);
201 static void qla2xxx_slave_destroy(struct scsi_device
*);
202 static int qla2xxx_queuecommand(struct Scsi_Host
*h
, struct scsi_cmnd
*cmd
);
203 static int qla2xxx_eh_abort(struct scsi_cmnd
*);
204 static int qla2xxx_eh_device_reset(struct scsi_cmnd
*);
205 static int qla2xxx_eh_target_reset(struct scsi_cmnd
*);
206 static int qla2xxx_eh_bus_reset(struct scsi_cmnd
*);
207 static int qla2xxx_eh_host_reset(struct scsi_cmnd
*);
209 static int qla2x00_change_queue_depth(struct scsi_device
*, int, int);
210 static int qla2x00_change_queue_type(struct scsi_device
*, int);
212 struct scsi_host_template qla2xxx_driver_template
= {
213 .module
= THIS_MODULE
,
214 .name
= QLA2XXX_DRIVER_NAME
,
215 .queuecommand
= qla2xxx_queuecommand
,
217 .eh_abort_handler
= qla2xxx_eh_abort
,
218 .eh_device_reset_handler
= qla2xxx_eh_device_reset
,
219 .eh_target_reset_handler
= qla2xxx_eh_target_reset
,
220 .eh_bus_reset_handler
= qla2xxx_eh_bus_reset
,
221 .eh_host_reset_handler
= qla2xxx_eh_host_reset
,
223 .slave_configure
= qla2xxx_slave_configure
,
225 .slave_alloc
= qla2xxx_slave_alloc
,
226 .slave_destroy
= qla2xxx_slave_destroy
,
227 .scan_finished
= qla2xxx_scan_finished
,
228 .scan_start
= qla2xxx_scan_start
,
229 .change_queue_depth
= qla2x00_change_queue_depth
,
230 .change_queue_type
= qla2x00_change_queue_type
,
233 .use_clustering
= ENABLE_CLUSTERING
,
234 .sg_tablesize
= SG_ALL
,
236 .max_sectors
= 0xFFFF,
237 .shost_attrs
= qla2x00_host_attrs
,
240 static struct scsi_transport_template
*qla2xxx_transport_template
= NULL
;
241 struct scsi_transport_template
*qla2xxx_transport_vport_template
= NULL
;
243 /* TODO Convert to inlines
249 qla2x00_start_timer(scsi_qla_host_t
*vha
, void *func
, unsigned long interval
)
251 init_timer(&vha
->timer
);
252 vha
->timer
.expires
= jiffies
+ interval
* HZ
;
253 vha
->timer
.data
= (unsigned long)vha
;
254 vha
->timer
.function
= (void (*)(unsigned long))func
;
255 add_timer(&vha
->timer
);
256 vha
->timer_active
= 1;
260 qla2x00_restart_timer(scsi_qla_host_t
*vha
, unsigned long interval
)
262 /* Currently used for 82XX only. */
263 if (vha
->device_flags
& DFLG_DEV_FAILED
) {
264 ql_dbg(ql_dbg_timer
, vha
, 0x600d,
265 "Device in a failed state, returning.\n");
269 mod_timer(&vha
->timer
, jiffies
+ interval
* HZ
);
272 static __inline__
void
273 qla2x00_stop_timer(scsi_qla_host_t
*vha
)
275 del_timer_sync(&vha
->timer
);
276 vha
->timer_active
= 0;
279 static int qla2x00_do_dpc(void *data
);
281 static void qla2x00_rst_aen(scsi_qla_host_t
*);
283 static int qla2x00_mem_alloc(struct qla_hw_data
*, uint16_t, uint16_t,
284 struct req_que
**, struct rsp_que
**);
285 static void qla2x00_free_fw_dump(struct qla_hw_data
*);
286 static void qla2x00_mem_free(struct qla_hw_data
*);
287 static void qla2x00_sp_free_dma(srb_t
*);
289 /* -------------------------------------------------------------------------- */
290 static int qla2x00_alloc_queues(struct qla_hw_data
*ha
)
292 scsi_qla_host_t
*vha
= pci_get_drvdata(ha
->pdev
);
293 ha
->req_q_map
= kzalloc(sizeof(struct req_que
*) * ha
->max_req_queues
,
295 if (!ha
->req_q_map
) {
296 ql_log(ql_log_fatal
, vha
, 0x003b,
297 "Unable to allocate memory for request queue ptrs.\n");
301 ha
->rsp_q_map
= kzalloc(sizeof(struct rsp_que
*) * ha
->max_rsp_queues
,
303 if (!ha
->rsp_q_map
) {
304 ql_log(ql_log_fatal
, vha
, 0x003c,
305 "Unable to allocate memory for response queue ptrs.\n");
308 set_bit(0, ha
->rsp_qid_map
);
309 set_bit(0, ha
->req_qid_map
);
313 kfree(ha
->req_q_map
);
314 ha
->req_q_map
= NULL
;
319 static void qla2x00_free_req_que(struct qla_hw_data
*ha
, struct req_que
*req
)
321 if (req
&& req
->ring
)
322 dma_free_coherent(&ha
->pdev
->dev
,
323 (req
->length
+ 1) * sizeof(request_t
),
324 req
->ring
, req
->dma
);
330 static void qla2x00_free_rsp_que(struct qla_hw_data
*ha
, struct rsp_que
*rsp
)
332 if (rsp
&& rsp
->ring
)
333 dma_free_coherent(&ha
->pdev
->dev
,
334 (rsp
->length
+ 1) * sizeof(response_t
),
335 rsp
->ring
, rsp
->dma
);
341 static void qla2x00_free_queues(struct qla_hw_data
*ha
)
347 for (cnt
= 0; cnt
< ha
->max_req_queues
; cnt
++) {
348 req
= ha
->req_q_map
[cnt
];
349 qla2x00_free_req_que(ha
, req
);
351 kfree(ha
->req_q_map
);
352 ha
->req_q_map
= NULL
;
354 for (cnt
= 0; cnt
< ha
->max_rsp_queues
; cnt
++) {
355 rsp
= ha
->rsp_q_map
[cnt
];
356 qla2x00_free_rsp_que(ha
, rsp
);
358 kfree(ha
->rsp_q_map
);
359 ha
->rsp_q_map
= NULL
;
362 static int qla25xx_setup_mode(struct scsi_qla_host
*vha
)
364 uint16_t options
= 0;
366 struct qla_hw_data
*ha
= vha
->hw
;
368 if (!(ha
->fw_attributes
& BIT_6
)) {
369 ql_log(ql_log_warn
, vha
, 0x00d8,
370 "Firmware is not multi-queue capable.\n");
373 if (ql2xmultique_tag
) {
374 /* create a request queue for IO */
376 req
= qla25xx_create_req_que(ha
, options
, 0, 0, -1,
377 QLA_DEFAULT_QUE_QOS
);
379 ql_log(ql_log_warn
, vha
, 0x00e0,
380 "Failed to create request queue.\n");
383 ha
->wq
= alloc_workqueue("qla2xxx_wq", WQ_MEM_RECLAIM
, 1);
384 vha
->req
= ha
->req_q_map
[req
];
386 for (ques
= 1; ques
< ha
->max_rsp_queues
; ques
++) {
387 ret
= qla25xx_create_rsp_que(ha
, options
, 0, 0, req
);
389 ql_log(ql_log_warn
, vha
, 0x00e8,
390 "Failed to create response queue.\n");
394 ha
->flags
.cpu_affinity_enabled
= 1;
395 ql_dbg(ql_dbg_multiq
, vha
, 0xc007,
396 "CPU affinity mode enalbed, "
397 "no. of response queues:%d no. of request queues:%d.\n",
398 ha
->max_rsp_queues
, ha
->max_req_queues
);
399 ql_dbg(ql_dbg_init
, vha
, 0x00e9,
400 "CPU affinity mode enalbed, "
401 "no. of response queues:%d no. of request queues:%d.\n",
402 ha
->max_rsp_queues
, ha
->max_req_queues
);
406 qla25xx_delete_queues(vha
);
407 destroy_workqueue(ha
->wq
);
411 kfree(ha
->req_q_map
);
412 kfree(ha
->rsp_q_map
);
413 ha
->max_req_queues
= ha
->max_rsp_queues
= 1;
418 qla2x00_pci_info_str(struct scsi_qla_host
*vha
, char *str
)
420 struct qla_hw_data
*ha
= vha
->hw
;
421 static char *pci_bus_modes
[] = {
422 "33", "66", "100", "133",
427 pci_bus
= (ha
->pci_attr
& (BIT_9
| BIT_10
)) >> 9;
430 strcat(str
, pci_bus_modes
[pci_bus
]);
432 pci_bus
= (ha
->pci_attr
& BIT_8
) >> 8;
434 strcat(str
, pci_bus_modes
[pci_bus
]);
436 strcat(str
, " MHz)");
442 qla24xx_pci_info_str(struct scsi_qla_host
*vha
, char *str
)
444 static char *pci_bus_modes
[] = { "33", "66", "100", "133", };
445 struct qla_hw_data
*ha
= vha
->hw
;
449 pcie_reg
= pci_find_capability(ha
->pdev
, PCI_CAP_ID_EXP
);
452 uint16_t pcie_lstat
, lspeed
, lwidth
;
455 pci_read_config_word(ha
->pdev
, pcie_reg
, &pcie_lstat
);
456 lspeed
= pcie_lstat
& (BIT_0
| BIT_1
| BIT_2
| BIT_3
);
457 lwidth
= (pcie_lstat
&
458 (BIT_4
| BIT_5
| BIT_6
| BIT_7
| BIT_8
| BIT_9
)) >> 4;
460 strcpy(str
, "PCIe (");
462 strcat(str
, "2.5GT/s ");
463 else if (lspeed
== 2)
464 strcat(str
, "5.0GT/s ");
466 strcat(str
, "<unknown> ");
467 snprintf(lwstr
, sizeof(lwstr
), "x%d)", lwidth
);
474 pci_bus
= (ha
->pci_attr
& CSRX_PCIX_BUS_MODE_MASK
) >> 8;
475 if (pci_bus
== 0 || pci_bus
== 8) {
477 strcat(str
, pci_bus_modes
[pci_bus
>> 3]);
481 strcat(str
, "Mode 2");
483 strcat(str
, "Mode 1");
485 strcat(str
, pci_bus_modes
[pci_bus
& ~BIT_2
]);
487 strcat(str
, " MHz)");
493 qla2x00_fw_version_str(struct scsi_qla_host
*vha
, char *str
)
496 struct qla_hw_data
*ha
= vha
->hw
;
498 sprintf(str
, "%d.%02d.%02d ", ha
->fw_major_version
,
499 ha
->fw_minor_version
,
500 ha
->fw_subminor_version
);
502 if (ha
->fw_attributes
& BIT_9
) {
507 switch (ha
->fw_attributes
& 0xFF) {
521 sprintf(un_str
, "(%x)", ha
->fw_attributes
);
525 if (ha
->fw_attributes
& 0x100)
532 qla24xx_fw_version_str(struct scsi_qla_host
*vha
, char *str
)
534 struct qla_hw_data
*ha
= vha
->hw
;
536 sprintf(str
, "%d.%02d.%02d (%x)", ha
->fw_major_version
,
537 ha
->fw_minor_version
, ha
->fw_subminor_version
, ha
->fw_attributes
);
541 static inline srb_t
*
542 qla2x00_get_new_sp(scsi_qla_host_t
*vha
, fc_port_t
*fcport
,
543 struct scsi_cmnd
*cmd
)
546 struct qla_hw_data
*ha
= vha
->hw
;
548 sp
= mempool_alloc(ha
->srb_mempool
, GFP_ATOMIC
);
550 ql_log(ql_log_warn
, vha
, 0x3006,
551 "Memory allocation failed for sp.\n");
555 atomic_set(&sp
->ref_count
, 1);
559 CMD_SP(cmd
) = (void *)sp
;
566 qla2xxx_queuecommand(struct Scsi_Host
*host
, struct scsi_cmnd
*cmd
)
568 scsi_qla_host_t
*vha
= shost_priv(host
);
569 fc_port_t
*fcport
= (struct fc_port
*) cmd
->device
->hostdata
;
570 struct fc_rport
*rport
= starget_to_rport(scsi_target(cmd
->device
));
571 struct qla_hw_data
*ha
= vha
->hw
;
572 struct scsi_qla_host
*base_vha
= pci_get_drvdata(ha
->pdev
);
576 if (ha
->flags
.eeh_busy
) {
577 if (ha
->flags
.pci_channel_io_perm_failure
) {
578 ql_dbg(ql_dbg_io
, vha
, 0x3001,
579 "PCI Channel IO permanent failure, exiting "
581 cmd
->result
= DID_NO_CONNECT
<< 16;
583 ql_dbg(ql_dbg_io
, vha
, 0x3002,
584 "EEH_Busy, Requeuing the cmd=%p.\n", cmd
);
585 cmd
->result
= DID_REQUEUE
<< 16;
587 goto qc24_fail_command
;
590 rval
= fc_remote_port_chkready(rport
);
593 ql_dbg(ql_dbg_io
, vha
, 0x3003,
594 "fc_remote_port_chkready failed for cmd=%p, rval=0x%x.\n",
596 goto qc24_fail_command
;
599 if (!vha
->flags
.difdix_supported
&&
600 scsi_get_prot_op(cmd
) != SCSI_PROT_NORMAL
) {
601 ql_dbg(ql_dbg_io
, vha
, 0x3004,
602 "DIF Cap not reg, fail DIF capable cmd's:%p.\n",
604 cmd
->result
= DID_NO_CONNECT
<< 16;
605 goto qc24_fail_command
;
607 if (atomic_read(&fcport
->state
) != FCS_ONLINE
) {
608 if (atomic_read(&fcport
->state
) == FCS_DEVICE_DEAD
||
609 atomic_read(&base_vha
->loop_state
) == LOOP_DEAD
) {
610 ql_dbg(ql_dbg_io
, vha
, 0x3005,
611 "Returning DNC, fcport_state=%d loop_state=%d.\n",
612 atomic_read(&fcport
->state
),
613 atomic_read(&base_vha
->loop_state
));
614 cmd
->result
= DID_NO_CONNECT
<< 16;
615 goto qc24_fail_command
;
617 goto qc24_target_busy
;
620 sp
= qla2x00_get_new_sp(base_vha
, fcport
, cmd
);
624 rval
= ha
->isp_ops
->start_scsi(sp
);
625 if (rval
!= QLA_SUCCESS
) {
626 ql_dbg(ql_dbg_io
, vha
, 0x3013,
627 "Start scsi failed rval=%d for cmd=%p.\n", rval
, cmd
);
628 goto qc24_host_busy_free_sp
;
633 qc24_host_busy_free_sp
:
634 qla2x00_sp_free_dma(sp
);
635 mempool_free(sp
, ha
->srb_mempool
);
638 return SCSI_MLQUEUE_HOST_BUSY
;
641 return SCSI_MLQUEUE_TARGET_BUSY
;
650 * qla2x00_eh_wait_on_command
651 * Waits for the command to be returned by the Firmware for some
655 * cmd = Scsi Command to wait on.
662 qla2x00_eh_wait_on_command(struct scsi_cmnd
*cmd
)
664 #define ABORT_POLLING_PERIOD 1000
665 #define ABORT_WAIT_ITER ((10 * 1000) / (ABORT_POLLING_PERIOD))
666 unsigned long wait_iter
= ABORT_WAIT_ITER
;
667 scsi_qla_host_t
*vha
= shost_priv(cmd
->device
->host
);
668 struct qla_hw_data
*ha
= vha
->hw
;
669 int ret
= QLA_SUCCESS
;
671 if (unlikely(pci_channel_offline(ha
->pdev
)) || ha
->flags
.eeh_busy
) {
672 ql_dbg(ql_dbg_taskm
, vha
, 0x8005,
673 "Return:eh_wait.\n");
677 while (CMD_SP(cmd
) && wait_iter
--) {
678 msleep(ABORT_POLLING_PERIOD
);
681 ret
= QLA_FUNCTION_FAILED
;
687 * qla2x00_wait_for_hba_online
688 * Wait till the HBA is online after going through
689 * <= MAX_RETRIES_OF_ISP_ABORT or
690 * finally HBA is disabled ie marked offline
693 * ha - pointer to host adapter structure
696 * Does context switching-Release SPIN_LOCK
697 * (if any) before calling this routine.
700 * Success (Adapter is online) : 0
701 * Failed (Adapter is offline/disabled) : 1
704 qla2x00_wait_for_hba_online(scsi_qla_host_t
*vha
)
707 unsigned long wait_online
;
708 struct qla_hw_data
*ha
= vha
->hw
;
709 scsi_qla_host_t
*base_vha
= pci_get_drvdata(ha
->pdev
);
711 wait_online
= jiffies
+ (MAX_LOOP_TIMEOUT
* HZ
);
712 while (((test_bit(ISP_ABORT_NEEDED
, &base_vha
->dpc_flags
)) ||
713 test_bit(ABORT_ISP_ACTIVE
, &base_vha
->dpc_flags
) ||
714 test_bit(ISP_ABORT_RETRY
, &base_vha
->dpc_flags
) ||
715 ha
->dpc_active
) && time_before(jiffies
, wait_online
)) {
719 if (base_vha
->flags
.online
)
720 return_status
= QLA_SUCCESS
;
722 return_status
= QLA_FUNCTION_FAILED
;
724 return (return_status
);
728 * qla2x00_wait_for_reset_ready
729 * Wait till the HBA is online after going through
730 * <= MAX_RETRIES_OF_ISP_ABORT or
731 * finally HBA is disabled ie marked offline or flash
732 * operations are in progress.
735 * ha - pointer to host adapter structure
738 * Does context switching-Release SPIN_LOCK
739 * (if any) before calling this routine.
742 * Success (Adapter is online/no flash ops) : 0
743 * Failed (Adapter is offline/disabled/flash ops in progress) : 1
746 qla2x00_wait_for_reset_ready(scsi_qla_host_t
*vha
)
749 unsigned long wait_online
;
750 struct qla_hw_data
*ha
= vha
->hw
;
751 scsi_qla_host_t
*base_vha
= pci_get_drvdata(ha
->pdev
);
753 wait_online
= jiffies
+ (MAX_LOOP_TIMEOUT
* HZ
);
754 while (((test_bit(ISP_ABORT_NEEDED
, &base_vha
->dpc_flags
)) ||
755 test_bit(ABORT_ISP_ACTIVE
, &base_vha
->dpc_flags
) ||
756 test_bit(ISP_ABORT_RETRY
, &base_vha
->dpc_flags
) ||
757 ha
->optrom_state
!= QLA_SWAITING
||
758 ha
->dpc_active
) && time_before(jiffies
, wait_online
))
761 if (base_vha
->flags
.online
&& ha
->optrom_state
== QLA_SWAITING
)
762 return_status
= QLA_SUCCESS
;
764 return_status
= QLA_FUNCTION_FAILED
;
766 ql_dbg(ql_dbg_taskm
, vha
, 0x8019,
767 "%s return status=%d.\n", __func__
, return_status
);
769 return return_status
;
773 qla2x00_wait_for_chip_reset(scsi_qla_host_t
*vha
)
776 unsigned long wait_reset
;
777 struct qla_hw_data
*ha
= vha
->hw
;
778 scsi_qla_host_t
*base_vha
= pci_get_drvdata(ha
->pdev
);
780 wait_reset
= jiffies
+ (MAX_LOOP_TIMEOUT
* HZ
);
781 while (((test_bit(ISP_ABORT_NEEDED
, &base_vha
->dpc_flags
)) ||
782 test_bit(ABORT_ISP_ACTIVE
, &base_vha
->dpc_flags
) ||
783 test_bit(ISP_ABORT_RETRY
, &base_vha
->dpc_flags
) ||
784 ha
->dpc_active
) && time_before(jiffies
, wait_reset
)) {
788 if (!test_bit(ISP_ABORT_NEEDED
, &base_vha
->dpc_flags
) &&
789 ha
->flags
.chip_reset_done
)
792 if (ha
->flags
.chip_reset_done
)
793 return_status
= QLA_SUCCESS
;
795 return_status
= QLA_FUNCTION_FAILED
;
797 return return_status
;
801 * qla2x00_wait_for_loop_ready
802 * Wait for MAX_LOOP_TIMEOUT(5 min) value for loop
803 * to be in LOOP_READY state.
805 * ha - pointer to host adapter structure
808 * Does context switching-Release SPIN_LOCK
809 * (if any) before calling this routine.
813 * Success (LOOP_READY) : 0
814 * Failed (LOOP_NOT_READY) : 1
817 qla2x00_wait_for_loop_ready(scsi_qla_host_t
*vha
)
819 int return_status
= QLA_SUCCESS
;
820 unsigned long loop_timeout
;
821 struct qla_hw_data
*ha
= vha
->hw
;
822 scsi_qla_host_t
*base_vha
= pci_get_drvdata(ha
->pdev
);
824 /* wait for 5 min at the max for loop to be ready */
825 loop_timeout
= jiffies
+ (MAX_LOOP_TIMEOUT
* HZ
);
827 while ((!atomic_read(&base_vha
->loop_down_timer
) &&
828 atomic_read(&base_vha
->loop_state
) == LOOP_DOWN
) ||
829 atomic_read(&base_vha
->loop_state
) != LOOP_READY
) {
830 if (atomic_read(&base_vha
->loop_state
) == LOOP_DEAD
) {
831 return_status
= QLA_FUNCTION_FAILED
;
835 if (time_after_eq(jiffies
, loop_timeout
)) {
836 return_status
= QLA_FUNCTION_FAILED
;
840 return (return_status
);
844 sp_get(struct srb
*sp
)
846 atomic_inc(&sp
->ref_count
);
849 /**************************************************************************
853 * The abort function will abort the specified command.
856 * cmd = Linux SCSI command packet to be aborted.
859 * Either SUCCESS or FAILED.
862 * Only return FAILED if command not returned by firmware.
863 **************************************************************************/
865 qla2xxx_eh_abort(struct scsi_cmnd
*cmd
)
867 scsi_qla_host_t
*vha
= shost_priv(cmd
->device
->host
);
870 unsigned int id
, lun
;
873 struct qla_hw_data
*ha
= vha
->hw
;
875 ql_dbg(ql_dbg_taskm
, vha
, 0x8000,
876 "Entered %s for cmd=%p.\n", __func__
, cmd
);
880 ret
= fc_block_scsi_eh(cmd
);
881 ql_dbg(ql_dbg_taskm
, vha
, 0x8001,
882 "Return value of fc_block_scsi_eh=%d.\n", ret
);
887 id
= cmd
->device
->id
;
888 lun
= cmd
->device
->lun
;
890 spin_lock_irqsave(&ha
->hardware_lock
, flags
);
891 sp
= (srb_t
*) CMD_SP(cmd
);
893 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
897 ql_dbg(ql_dbg_taskm
, vha
, 0x8002,
898 "Aborting sp=%p cmd=%p from RISC ", sp
, cmd
);
900 /* Get a reference to the sp and drop the lock.*/
903 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
904 if (ha
->isp_ops
->abort_command(sp
)) {
905 ql_dbg(ql_dbg_taskm
, vha
, 0x8003,
906 "Abort command mbx failed for cmd=%p.\n", cmd
);
908 ql_dbg(ql_dbg_taskm
, vha
, 0x8004,
909 "Abort command mbx success.\n");
912 qla2x00_sp_compl(ha
, sp
);
914 /* Wait for the command to be returned. */
916 if (qla2x00_eh_wait_on_command(cmd
) != QLA_SUCCESS
) {
917 ql_log(ql_log_warn
, vha
, 0x8006,
918 "Abort handler timed out for cmd=%p.\n", cmd
);
923 ql_log(ql_log_info
, vha
, 0x801c,
924 "Abort command issued -- %d %x.\n", wait
, ret
);
930 qla2x00_eh_wait_for_pending_commands(scsi_qla_host_t
*vha
, unsigned int t
,
931 unsigned int l
, enum nexus_wait_type type
)
933 int cnt
, match
, status
;
935 struct qla_hw_data
*ha
= vha
->hw
;
939 status
= QLA_SUCCESS
;
941 spin_lock_irqsave(&ha
->hardware_lock
, flags
);
943 for (cnt
= 1; status
== QLA_SUCCESS
&&
944 cnt
< MAX_OUTSTANDING_COMMANDS
; cnt
++) {
945 sp
= req
->outstanding_cmds
[cnt
];
948 if ((sp
->ctx
) && !IS_PROT_IO(sp
))
950 if (vha
->vp_idx
!= sp
->fcport
->vha
->vp_idx
)
958 match
= sp
->cmd
->device
->id
== t
;
961 match
= (sp
->cmd
->device
->id
== t
&&
962 sp
->cmd
->device
->lun
== l
);
968 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
969 status
= qla2x00_eh_wait_on_command(sp
->cmd
);
970 spin_lock_irqsave(&ha
->hardware_lock
, flags
);
972 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
977 static char *reset_errors
[] = {
980 "Task management failed",
981 "Waiting for command completions",
985 __qla2xxx_eh_generic_reset(char *name
, enum nexus_wait_type type
,
986 struct scsi_cmnd
*cmd
, int (*do_reset
)(struct fc_port
*, unsigned int, int))
988 scsi_qla_host_t
*vha
= shost_priv(cmd
->device
->host
);
989 fc_port_t
*fcport
= (struct fc_port
*) cmd
->device
->hostdata
;
993 ql_log(ql_log_warn
, vha
, 0x8007,
994 "fcport is NULL.\n");
998 err
= fc_block_scsi_eh(cmd
);
999 ql_dbg(ql_dbg_taskm
, vha
, 0x8008,
1000 "fc_block_scsi_eh ret=%d.\n", err
);
1004 ql_log(ql_log_info
, vha
, 0x8009,
1005 "%s RESET ISSUED for id %d lun %d cmd=%p.\n", name
,
1006 cmd
->device
->id
, cmd
->device
->lun
, cmd
);
1009 if (qla2x00_wait_for_hba_online(vha
) != QLA_SUCCESS
) {
1010 ql_log(ql_log_warn
, vha
, 0x800a,
1011 "Wait for hba online failed for cmd=%p.\n", cmd
);
1012 goto eh_reset_failed
;
1015 if (qla2x00_wait_for_loop_ready(vha
) != QLA_SUCCESS
) {
1016 ql_log(ql_log_warn
, vha
, 0x800b,
1017 "Wait for loop ready failed for cmd=%p.\n", cmd
);
1018 goto eh_reset_failed
;
1021 if (do_reset(fcport
, cmd
->device
->lun
, cmd
->request
->cpu
+ 1)
1023 ql_log(ql_log_warn
, vha
, 0x800c,
1024 "do_reset failed for cmd=%p.\n", cmd
);
1025 goto eh_reset_failed
;
1028 if (qla2x00_eh_wait_for_pending_commands(vha
, cmd
->device
->id
,
1029 cmd
->device
->lun
, type
) != QLA_SUCCESS
) {
1030 ql_log(ql_log_warn
, vha
, 0x800d,
1031 "wait for peding cmds failed for cmd=%p.\n", cmd
);
1032 goto eh_reset_failed
;
1035 ql_log(ql_log_info
, vha
, 0x800e,
1036 "%s RESET SUCCEEDED for id %d lun %d cmd=%p.\n", name
,
1037 cmd
->device
->id
, cmd
->device
->lun
, cmd
);
1042 ql_log(ql_log_info
, vha
, 0x800f,
1043 "%s RESET FAILED: %s for id %d lun %d cmd=%p.\n", name
,
1044 reset_errors
[err
], cmd
->device
->id
, cmd
->device
->lun
);
1049 qla2xxx_eh_device_reset(struct scsi_cmnd
*cmd
)
1051 scsi_qla_host_t
*vha
= shost_priv(cmd
->device
->host
);
1052 struct qla_hw_data
*ha
= vha
->hw
;
1054 return __qla2xxx_eh_generic_reset("DEVICE", WAIT_LUN
, cmd
,
1055 ha
->isp_ops
->lun_reset
);
1059 qla2xxx_eh_target_reset(struct scsi_cmnd
*cmd
)
1061 scsi_qla_host_t
*vha
= shost_priv(cmd
->device
->host
);
1062 struct qla_hw_data
*ha
= vha
->hw
;
1064 return __qla2xxx_eh_generic_reset("TARGET", WAIT_TARGET
, cmd
,
1065 ha
->isp_ops
->target_reset
);
1068 /**************************************************************************
1069 * qla2xxx_eh_bus_reset
1072 * The bus reset function will reset the bus and abort any executing
1076 * cmd = Linux SCSI command packet of the command that cause the
1080 * SUCCESS/FAILURE (defined as macro in scsi.h).
1082 **************************************************************************/
1084 qla2xxx_eh_bus_reset(struct scsi_cmnd
*cmd
)
1086 scsi_qla_host_t
*vha
= shost_priv(cmd
->device
->host
);
1087 fc_port_t
*fcport
= (struct fc_port
*) cmd
->device
->hostdata
;
1089 unsigned int id
, lun
;
1091 id
= cmd
->device
->id
;
1092 lun
= cmd
->device
->lun
;
1095 ql_log(ql_log_warn
, vha
, 0x8010,
1096 "fcport is NULL.\n");
1100 ret
= fc_block_scsi_eh(cmd
);
1101 ql_dbg(ql_dbg_taskm
, vha
, 0x8011,
1102 "fc_block_scsi_eh ret=%d.\n", ret
);
1107 ql_log(ql_log_info
, vha
, 0x8012,
1108 "BUS RESET ISSUED for id %d lun %d.\n", id
, lun
);
1110 if (qla2x00_wait_for_hba_online(vha
) != QLA_SUCCESS
) {
1111 ql_log(ql_log_fatal
, vha
, 0x8013,
1112 "Wait for hba online failed board disabled.\n");
1113 goto eh_bus_reset_done
;
1116 if (qla2x00_wait_for_loop_ready(vha
) == QLA_SUCCESS
) {
1117 if (qla2x00_loop_reset(vha
) == QLA_SUCCESS
)
1121 goto eh_bus_reset_done
;
1123 /* Flush outstanding commands. */
1124 if (qla2x00_eh_wait_for_pending_commands(vha
, 0, 0, WAIT_HOST
) !=
1126 ql_log(ql_log_warn
, vha
, 0x8014,
1127 "Wait for pending commands failed.\n");
1132 ql_log(ql_log_warn
, vha
, 0x802b,
1133 "BUS RESET %s.\n", (ret
== FAILED
) ? "FAILED" : "SUCCEDED");
1138 /**************************************************************************
1139 * qla2xxx_eh_host_reset
1142 * The reset function will reset the Adapter.
1145 * cmd = Linux SCSI command packet of the command that cause the
1149 * Either SUCCESS or FAILED.
1152 **************************************************************************/
1154 qla2xxx_eh_host_reset(struct scsi_cmnd
*cmd
)
1156 scsi_qla_host_t
*vha
= shost_priv(cmd
->device
->host
);
1157 fc_port_t
*fcport
= (struct fc_port
*) cmd
->device
->hostdata
;
1158 struct qla_hw_data
*ha
= vha
->hw
;
1160 unsigned int id
, lun
;
1161 scsi_qla_host_t
*base_vha
= pci_get_drvdata(ha
->pdev
);
1163 id
= cmd
->device
->id
;
1164 lun
= cmd
->device
->lun
;
1167 ql_log(ql_log_warn
, vha
, 0x8016,
1168 "fcport is NULL.\n");
1172 ret
= fc_block_scsi_eh(cmd
);
1173 ql_dbg(ql_dbg_taskm
, vha
, 0x8017,
1174 "fc_block_scsi_eh ret=%d.\n", ret
);
1179 ql_log(ql_log_info
, vha
, 0x8018,
1180 "ADAPTER RESET ISSUED for id %d lun %d.\n", id
, lun
);
1182 if (qla2x00_wait_for_reset_ready(vha
) != QLA_SUCCESS
)
1183 goto eh_host_reset_lock
;
1186 * Fixme-may be dpc thread is active and processing
1187 * loop_resync,so wait a while for it to
1188 * be completed and then issue big hammer.Otherwise
1189 * it may cause I/O failure as big hammer marks the
1190 * devices as lost kicking of the port_down_timer
1191 * while dpc is stuck for the mailbox to complete.
1193 qla2x00_wait_for_loop_ready(vha
);
1194 if (vha
!= base_vha
) {
1195 if (qla2x00_vp_abort_isp(vha
))
1196 goto eh_host_reset_lock
;
1198 if (IS_QLA82XX(vha
->hw
)) {
1199 if (!qla82xx_fcoe_ctx_reset(vha
)) {
1200 /* Ctx reset success */
1202 goto eh_host_reset_lock
;
1204 /* fall thru if ctx reset failed */
1207 flush_workqueue(ha
->wq
);
1209 set_bit(ABORT_ISP_ACTIVE
, &base_vha
->dpc_flags
);
1210 if (ha
->isp_ops
->abort_isp(base_vha
)) {
1211 clear_bit(ABORT_ISP_ACTIVE
, &base_vha
->dpc_flags
);
1212 /* failed. schedule dpc to try */
1213 set_bit(ISP_ABORT_NEEDED
, &base_vha
->dpc_flags
);
1215 if (qla2x00_wait_for_hba_online(vha
) != QLA_SUCCESS
) {
1216 ql_log(ql_log_warn
, vha
, 0x802a,
1217 "wait for hba online failed.\n");
1218 goto eh_host_reset_lock
;
1221 clear_bit(ABORT_ISP_ACTIVE
, &base_vha
->dpc_flags
);
1224 /* Waiting for command to be returned to OS.*/
1225 if (qla2x00_eh_wait_for_pending_commands(vha
, 0, 0, WAIT_HOST
) ==
1230 qla_printk(KERN_INFO
, ha
, "%s: reset %s.\n", __func__
,
1231 (ret
== FAILED
) ? "failed" : "succeeded");
1237 * qla2x00_loop_reset
1241 * ha = adapter block pointer.
1247 qla2x00_loop_reset(scsi_qla_host_t
*vha
)
1250 struct fc_port
*fcport
;
1251 struct qla_hw_data
*ha
= vha
->hw
;
1253 if (ql2xtargetreset
== 1 && ha
->flags
.enable_target_reset
) {
1254 list_for_each_entry(fcport
, &vha
->vp_fcports
, list
) {
1255 if (fcport
->port_type
!= FCT_TARGET
)
1258 ret
= ha
->isp_ops
->target_reset(fcport
, 0, 0);
1259 if (ret
!= QLA_SUCCESS
) {
1260 ql_dbg(ql_dbg_taskm
, vha
, 0x802c,
1261 "Bus Reset failed: Target Reset=%d "
1262 "d_id=%x.\n", ret
, fcport
->d_id
.b24
);
1267 if (ha
->flags
.enable_lip_full_login
&& !IS_QLA8XXX_TYPE(ha
)) {
1268 ret
= qla2x00_full_login_lip(vha
);
1269 if (ret
!= QLA_SUCCESS
) {
1270 ql_dbg(ql_dbg_taskm
, vha
, 0x802d,
1271 "full_login_lip=%d.\n", ret
);
1273 atomic_set(&vha
->loop_state
, LOOP_DOWN
);
1274 atomic_set(&vha
->loop_down_timer
, LOOP_DOWN_TIME
);
1275 qla2x00_mark_all_devices_lost(vha
, 0);
1276 qla2x00_wait_for_loop_ready(vha
);
1279 if (ha
->flags
.enable_lip_reset
) {
1280 ret
= qla2x00_lip_reset(vha
);
1281 if (ret
!= QLA_SUCCESS
) {
1282 ql_dbg(ql_dbg_taskm
, vha
, 0x802e,
1283 "lip_reset failed (%d).\n", ret
);
1285 qla2x00_wait_for_loop_ready(vha
);
1288 /* Issue marker command only when we are going to start the I/O */
1289 vha
->marker_needed
= 1;
1295 qla2x00_abort_all_cmds(scsi_qla_host_t
*vha
, int res
)
1298 unsigned long flags
;
1300 struct srb_ctx
*ctx
;
1301 struct qla_hw_data
*ha
= vha
->hw
;
1302 struct req_que
*req
;
1304 spin_lock_irqsave(&ha
->hardware_lock
, flags
);
1305 for (que
= 0; que
< ha
->max_req_queues
; que
++) {
1306 req
= ha
->req_q_map
[que
];
1309 for (cnt
= 1; cnt
< MAX_OUTSTANDING_COMMANDS
; cnt
++) {
1310 sp
= req
->outstanding_cmds
[cnt
];
1312 req
->outstanding_cmds
[cnt
] = NULL
;
1314 (sp
->flags
& SRB_FCP_CMND_DMA_VALID
) ||
1316 sp
->cmd
->result
= res
;
1317 qla2x00_sp_compl(ha
, sp
);
1320 if (ctx
->type
== SRB_LOGIN_CMD
||
1321 ctx
->type
== SRB_LOGOUT_CMD
) {
1322 ctx
->u
.iocb_cmd
->free(sp
);
1324 struct fc_bsg_job
*bsg_job
=
1326 if (bsg_job
->request
->msgcode
1329 bsg_job
->req
->errors
= 0;
1330 bsg_job
->reply
->result
= res
;
1331 bsg_job
->job_done(bsg_job
);
1340 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
1344 qla2xxx_slave_alloc(struct scsi_device
*sdev
)
1346 struct fc_rport
*rport
= starget_to_rport(scsi_target(sdev
));
1348 if (!rport
|| fc_remote_port_chkready(rport
))
1351 sdev
->hostdata
= *(fc_port_t
**)rport
->dd_data
;
1357 qla2xxx_slave_configure(struct scsi_device
*sdev
)
1359 scsi_qla_host_t
*vha
= shost_priv(sdev
->host
);
1360 struct req_que
*req
= vha
->req
;
1362 if (sdev
->tagged_supported
)
1363 scsi_activate_tcq(sdev
, req
->max_q_depth
);
1365 scsi_deactivate_tcq(sdev
, req
->max_q_depth
);
1370 qla2xxx_slave_destroy(struct scsi_device
*sdev
)
1372 sdev
->hostdata
= NULL
;
1375 static void qla2x00_handle_queue_full(struct scsi_device
*sdev
, int qdepth
)
1377 fc_port_t
*fcport
= (struct fc_port
*) sdev
->hostdata
;
1379 if (!scsi_track_queue_full(sdev
, qdepth
))
1382 ql_dbg(ql_dbg_io
, fcport
->vha
, 0x3029,
1383 "Queue depth adjusted-down "
1384 "to %d for scsi(%ld:%d:%d:%d).\n",
1385 sdev
->queue_depth
, fcport
->vha
->host_no
,
1386 sdev
->channel
, sdev
->id
, sdev
->lun
);
1389 static void qla2x00_adjust_sdev_qdepth_up(struct scsi_device
*sdev
, int qdepth
)
1391 fc_port_t
*fcport
= sdev
->hostdata
;
1392 struct scsi_qla_host
*vha
= fcport
->vha
;
1393 struct req_que
*req
= NULL
;
1399 if (req
->max_q_depth
<= sdev
->queue_depth
|| req
->max_q_depth
< qdepth
)
1402 if (sdev
->ordered_tags
)
1403 scsi_adjust_queue_depth(sdev
, MSG_ORDERED_TAG
, qdepth
);
1405 scsi_adjust_queue_depth(sdev
, MSG_SIMPLE_TAG
, qdepth
);
1407 ql_dbg(ql_dbg_io
, vha
, 0x302a,
1408 "Queue depth adjusted-up to %d for "
1409 "scsi(%ld:%d:%d:%d).\n",
1410 sdev
->queue_depth
, fcport
->vha
->host_no
,
1411 sdev
->channel
, sdev
->id
, sdev
->lun
);
1415 qla2x00_change_queue_depth(struct scsi_device
*sdev
, int qdepth
, int reason
)
1418 case SCSI_QDEPTH_DEFAULT
:
1419 scsi_adjust_queue_depth(sdev
, scsi_get_tag_type(sdev
), qdepth
);
1421 case SCSI_QDEPTH_QFULL
:
1422 qla2x00_handle_queue_full(sdev
, qdepth
);
1424 case SCSI_QDEPTH_RAMP_UP
:
1425 qla2x00_adjust_sdev_qdepth_up(sdev
, qdepth
);
1431 return sdev
->queue_depth
;
1435 qla2x00_change_queue_type(struct scsi_device
*sdev
, int tag_type
)
1437 if (sdev
->tagged_supported
) {
1438 scsi_set_tag_type(sdev
, tag_type
);
1440 scsi_activate_tcq(sdev
, sdev
->queue_depth
);
1442 scsi_deactivate_tcq(sdev
, sdev
->queue_depth
);
1450 * qla2x00_config_dma_addressing() - Configure OS DMA addressing method.
1453 * At exit, the @ha's flags.enable_64bit_addressing set to indicated
1454 * supported addressing method.
1457 qla2x00_config_dma_addressing(struct qla_hw_data
*ha
)
1459 /* Assume a 32bit DMA mask. */
1460 ha
->flags
.enable_64bit_addressing
= 0;
1462 if (!dma_set_mask(&ha
->pdev
->dev
, DMA_BIT_MASK(64))) {
1463 /* Any upper-dword bits set? */
1464 if (MSD(dma_get_required_mask(&ha
->pdev
->dev
)) &&
1465 !pci_set_consistent_dma_mask(ha
->pdev
, DMA_BIT_MASK(64))) {
1466 /* Ok, a 64bit DMA mask is applicable. */
1467 ha
->flags
.enable_64bit_addressing
= 1;
1468 ha
->isp_ops
->calc_req_entries
= qla2x00_calc_iocbs_64
;
1469 ha
->isp_ops
->build_iocbs
= qla2x00_build_scsi_iocbs_64
;
1474 dma_set_mask(&ha
->pdev
->dev
, DMA_BIT_MASK(32));
1475 pci_set_consistent_dma_mask(ha
->pdev
, DMA_BIT_MASK(32));
1479 qla2x00_enable_intrs(struct qla_hw_data
*ha
)
1481 unsigned long flags
= 0;
1482 struct device_reg_2xxx __iomem
*reg
= &ha
->iobase
->isp
;
1484 spin_lock_irqsave(&ha
->hardware_lock
, flags
);
1485 ha
->interrupts_on
= 1;
1486 /* enable risc and host interrupts */
1487 WRT_REG_WORD(®
->ictrl
, ICR_EN_INT
| ICR_EN_RISC
);
1488 RD_REG_WORD(®
->ictrl
);
1489 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
1494 qla2x00_disable_intrs(struct qla_hw_data
*ha
)
1496 unsigned long flags
= 0;
1497 struct device_reg_2xxx __iomem
*reg
= &ha
->iobase
->isp
;
1499 spin_lock_irqsave(&ha
->hardware_lock
, flags
);
1500 ha
->interrupts_on
= 0;
1501 /* disable risc and host interrupts */
1502 WRT_REG_WORD(®
->ictrl
, 0);
1503 RD_REG_WORD(®
->ictrl
);
1504 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
1508 qla24xx_enable_intrs(struct qla_hw_data
*ha
)
1510 unsigned long flags
= 0;
1511 struct device_reg_24xx __iomem
*reg
= &ha
->iobase
->isp24
;
1513 spin_lock_irqsave(&ha
->hardware_lock
, flags
);
1514 ha
->interrupts_on
= 1;
1515 WRT_REG_DWORD(®
->ictrl
, ICRX_EN_RISC_INT
);
1516 RD_REG_DWORD(®
->ictrl
);
1517 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
1521 qla24xx_disable_intrs(struct qla_hw_data
*ha
)
1523 unsigned long flags
= 0;
1524 struct device_reg_24xx __iomem
*reg
= &ha
->iobase
->isp24
;
1526 if (IS_NOPOLLING_TYPE(ha
))
1528 spin_lock_irqsave(&ha
->hardware_lock
, flags
);
1529 ha
->interrupts_on
= 0;
1530 WRT_REG_DWORD(®
->ictrl
, 0);
1531 RD_REG_DWORD(®
->ictrl
);
1532 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
1535 static struct isp_operations qla2100_isp_ops
= {
1536 .pci_config
= qla2100_pci_config
,
1537 .reset_chip
= qla2x00_reset_chip
,
1538 .chip_diag
= qla2x00_chip_diag
,
1539 .config_rings
= qla2x00_config_rings
,
1540 .reset_adapter
= qla2x00_reset_adapter
,
1541 .nvram_config
= qla2x00_nvram_config
,
1542 .update_fw_options
= qla2x00_update_fw_options
,
1543 .load_risc
= qla2x00_load_risc
,
1544 .pci_info_str
= qla2x00_pci_info_str
,
1545 .fw_version_str
= qla2x00_fw_version_str
,
1546 .intr_handler
= qla2100_intr_handler
,
1547 .enable_intrs
= qla2x00_enable_intrs
,
1548 .disable_intrs
= qla2x00_disable_intrs
,
1549 .abort_command
= qla2x00_abort_command
,
1550 .target_reset
= qla2x00_abort_target
,
1551 .lun_reset
= qla2x00_lun_reset
,
1552 .fabric_login
= qla2x00_login_fabric
,
1553 .fabric_logout
= qla2x00_fabric_logout
,
1554 .calc_req_entries
= qla2x00_calc_iocbs_32
,
1555 .build_iocbs
= qla2x00_build_scsi_iocbs_32
,
1556 .prep_ms_iocb
= qla2x00_prep_ms_iocb
,
1557 .prep_ms_fdmi_iocb
= qla2x00_prep_ms_fdmi_iocb
,
1558 .read_nvram
= qla2x00_read_nvram_data
,
1559 .write_nvram
= qla2x00_write_nvram_data
,
1560 .fw_dump
= qla2100_fw_dump
,
1563 .beacon_blink
= NULL
,
1564 .read_optrom
= qla2x00_read_optrom_data
,
1565 .write_optrom
= qla2x00_write_optrom_data
,
1566 .get_flash_version
= qla2x00_get_flash_version
,
1567 .start_scsi
= qla2x00_start_scsi
,
1568 .abort_isp
= qla2x00_abort_isp
,
1571 static struct isp_operations qla2300_isp_ops
= {
1572 .pci_config
= qla2300_pci_config
,
1573 .reset_chip
= qla2x00_reset_chip
,
1574 .chip_diag
= qla2x00_chip_diag
,
1575 .config_rings
= qla2x00_config_rings
,
1576 .reset_adapter
= qla2x00_reset_adapter
,
1577 .nvram_config
= qla2x00_nvram_config
,
1578 .update_fw_options
= qla2x00_update_fw_options
,
1579 .load_risc
= qla2x00_load_risc
,
1580 .pci_info_str
= qla2x00_pci_info_str
,
1581 .fw_version_str
= qla2x00_fw_version_str
,
1582 .intr_handler
= qla2300_intr_handler
,
1583 .enable_intrs
= qla2x00_enable_intrs
,
1584 .disable_intrs
= qla2x00_disable_intrs
,
1585 .abort_command
= qla2x00_abort_command
,
1586 .target_reset
= qla2x00_abort_target
,
1587 .lun_reset
= qla2x00_lun_reset
,
1588 .fabric_login
= qla2x00_login_fabric
,
1589 .fabric_logout
= qla2x00_fabric_logout
,
1590 .calc_req_entries
= qla2x00_calc_iocbs_32
,
1591 .build_iocbs
= qla2x00_build_scsi_iocbs_32
,
1592 .prep_ms_iocb
= qla2x00_prep_ms_iocb
,
1593 .prep_ms_fdmi_iocb
= qla2x00_prep_ms_fdmi_iocb
,
1594 .read_nvram
= qla2x00_read_nvram_data
,
1595 .write_nvram
= qla2x00_write_nvram_data
,
1596 .fw_dump
= qla2300_fw_dump
,
1597 .beacon_on
= qla2x00_beacon_on
,
1598 .beacon_off
= qla2x00_beacon_off
,
1599 .beacon_blink
= qla2x00_beacon_blink
,
1600 .read_optrom
= qla2x00_read_optrom_data
,
1601 .write_optrom
= qla2x00_write_optrom_data
,
1602 .get_flash_version
= qla2x00_get_flash_version
,
1603 .start_scsi
= qla2x00_start_scsi
,
1604 .abort_isp
= qla2x00_abort_isp
,
1607 static struct isp_operations qla24xx_isp_ops
= {
1608 .pci_config
= qla24xx_pci_config
,
1609 .reset_chip
= qla24xx_reset_chip
,
1610 .chip_diag
= qla24xx_chip_diag
,
1611 .config_rings
= qla24xx_config_rings
,
1612 .reset_adapter
= qla24xx_reset_adapter
,
1613 .nvram_config
= qla24xx_nvram_config
,
1614 .update_fw_options
= qla24xx_update_fw_options
,
1615 .load_risc
= qla24xx_load_risc
,
1616 .pci_info_str
= qla24xx_pci_info_str
,
1617 .fw_version_str
= qla24xx_fw_version_str
,
1618 .intr_handler
= qla24xx_intr_handler
,
1619 .enable_intrs
= qla24xx_enable_intrs
,
1620 .disable_intrs
= qla24xx_disable_intrs
,
1621 .abort_command
= qla24xx_abort_command
,
1622 .target_reset
= qla24xx_abort_target
,
1623 .lun_reset
= qla24xx_lun_reset
,
1624 .fabric_login
= qla24xx_login_fabric
,
1625 .fabric_logout
= qla24xx_fabric_logout
,
1626 .calc_req_entries
= NULL
,
1627 .build_iocbs
= NULL
,
1628 .prep_ms_iocb
= qla24xx_prep_ms_iocb
,
1629 .prep_ms_fdmi_iocb
= qla24xx_prep_ms_fdmi_iocb
,
1630 .read_nvram
= qla24xx_read_nvram_data
,
1631 .write_nvram
= qla24xx_write_nvram_data
,
1632 .fw_dump
= qla24xx_fw_dump
,
1633 .beacon_on
= qla24xx_beacon_on
,
1634 .beacon_off
= qla24xx_beacon_off
,
1635 .beacon_blink
= qla24xx_beacon_blink
,
1636 .read_optrom
= qla24xx_read_optrom_data
,
1637 .write_optrom
= qla24xx_write_optrom_data
,
1638 .get_flash_version
= qla24xx_get_flash_version
,
1639 .start_scsi
= qla24xx_start_scsi
,
1640 .abort_isp
= qla2x00_abort_isp
,
1643 static struct isp_operations qla25xx_isp_ops
= {
1644 .pci_config
= qla25xx_pci_config
,
1645 .reset_chip
= qla24xx_reset_chip
,
1646 .chip_diag
= qla24xx_chip_diag
,
1647 .config_rings
= qla24xx_config_rings
,
1648 .reset_adapter
= qla24xx_reset_adapter
,
1649 .nvram_config
= qla24xx_nvram_config
,
1650 .update_fw_options
= qla24xx_update_fw_options
,
1651 .load_risc
= qla24xx_load_risc
,
1652 .pci_info_str
= qla24xx_pci_info_str
,
1653 .fw_version_str
= qla24xx_fw_version_str
,
1654 .intr_handler
= qla24xx_intr_handler
,
1655 .enable_intrs
= qla24xx_enable_intrs
,
1656 .disable_intrs
= qla24xx_disable_intrs
,
1657 .abort_command
= qla24xx_abort_command
,
1658 .target_reset
= qla24xx_abort_target
,
1659 .lun_reset
= qla24xx_lun_reset
,
1660 .fabric_login
= qla24xx_login_fabric
,
1661 .fabric_logout
= qla24xx_fabric_logout
,
1662 .calc_req_entries
= NULL
,
1663 .build_iocbs
= NULL
,
1664 .prep_ms_iocb
= qla24xx_prep_ms_iocb
,
1665 .prep_ms_fdmi_iocb
= qla24xx_prep_ms_fdmi_iocb
,
1666 .read_nvram
= qla25xx_read_nvram_data
,
1667 .write_nvram
= qla25xx_write_nvram_data
,
1668 .fw_dump
= qla25xx_fw_dump
,
1669 .beacon_on
= qla24xx_beacon_on
,
1670 .beacon_off
= qla24xx_beacon_off
,
1671 .beacon_blink
= qla24xx_beacon_blink
,
1672 .read_optrom
= qla25xx_read_optrom_data
,
1673 .write_optrom
= qla24xx_write_optrom_data
,
1674 .get_flash_version
= qla24xx_get_flash_version
,
1675 .start_scsi
= qla24xx_dif_start_scsi
,
1676 .abort_isp
= qla2x00_abort_isp
,
1679 static struct isp_operations qla81xx_isp_ops
= {
1680 .pci_config
= qla25xx_pci_config
,
1681 .reset_chip
= qla24xx_reset_chip
,
1682 .chip_diag
= qla24xx_chip_diag
,
1683 .config_rings
= qla24xx_config_rings
,
1684 .reset_adapter
= qla24xx_reset_adapter
,
1685 .nvram_config
= qla81xx_nvram_config
,
1686 .update_fw_options
= qla81xx_update_fw_options
,
1687 .load_risc
= qla81xx_load_risc
,
1688 .pci_info_str
= qla24xx_pci_info_str
,
1689 .fw_version_str
= qla24xx_fw_version_str
,
1690 .intr_handler
= qla24xx_intr_handler
,
1691 .enable_intrs
= qla24xx_enable_intrs
,
1692 .disable_intrs
= qla24xx_disable_intrs
,
1693 .abort_command
= qla24xx_abort_command
,
1694 .target_reset
= qla24xx_abort_target
,
1695 .lun_reset
= qla24xx_lun_reset
,
1696 .fabric_login
= qla24xx_login_fabric
,
1697 .fabric_logout
= qla24xx_fabric_logout
,
1698 .calc_req_entries
= NULL
,
1699 .build_iocbs
= NULL
,
1700 .prep_ms_iocb
= qla24xx_prep_ms_iocb
,
1701 .prep_ms_fdmi_iocb
= qla24xx_prep_ms_fdmi_iocb
,
1703 .write_nvram
= NULL
,
1704 .fw_dump
= qla81xx_fw_dump
,
1705 .beacon_on
= qla24xx_beacon_on
,
1706 .beacon_off
= qla24xx_beacon_off
,
1707 .beacon_blink
= qla24xx_beacon_blink
,
1708 .read_optrom
= qla25xx_read_optrom_data
,
1709 .write_optrom
= qla24xx_write_optrom_data
,
1710 .get_flash_version
= qla24xx_get_flash_version
,
1711 .start_scsi
= qla24xx_dif_start_scsi
,
1712 .abort_isp
= qla2x00_abort_isp
,
1715 static struct isp_operations qla82xx_isp_ops
= {
1716 .pci_config
= qla82xx_pci_config
,
1717 .reset_chip
= qla82xx_reset_chip
,
1718 .chip_diag
= qla24xx_chip_diag
,
1719 .config_rings
= qla82xx_config_rings
,
1720 .reset_adapter
= qla24xx_reset_adapter
,
1721 .nvram_config
= qla81xx_nvram_config
,
1722 .update_fw_options
= qla24xx_update_fw_options
,
1723 .load_risc
= qla82xx_load_risc
,
1724 .pci_info_str
= qla82xx_pci_info_str
,
1725 .fw_version_str
= qla24xx_fw_version_str
,
1726 .intr_handler
= qla82xx_intr_handler
,
1727 .enable_intrs
= qla82xx_enable_intrs
,
1728 .disable_intrs
= qla82xx_disable_intrs
,
1729 .abort_command
= qla24xx_abort_command
,
1730 .target_reset
= qla24xx_abort_target
,
1731 .lun_reset
= qla24xx_lun_reset
,
1732 .fabric_login
= qla24xx_login_fabric
,
1733 .fabric_logout
= qla24xx_fabric_logout
,
1734 .calc_req_entries
= NULL
,
1735 .build_iocbs
= NULL
,
1736 .prep_ms_iocb
= qla24xx_prep_ms_iocb
,
1737 .prep_ms_fdmi_iocb
= qla24xx_prep_ms_fdmi_iocb
,
1738 .read_nvram
= qla24xx_read_nvram_data
,
1739 .write_nvram
= qla24xx_write_nvram_data
,
1740 .fw_dump
= qla24xx_fw_dump
,
1741 .beacon_on
= qla24xx_beacon_on
,
1742 .beacon_off
= qla24xx_beacon_off
,
1743 .beacon_blink
= qla24xx_beacon_blink
,
1744 .read_optrom
= qla82xx_read_optrom_data
,
1745 .write_optrom
= qla82xx_write_optrom_data
,
1746 .get_flash_version
= qla24xx_get_flash_version
,
1747 .start_scsi
= qla82xx_start_scsi
,
1748 .abort_isp
= qla82xx_abort_isp
,
1752 qla2x00_set_isp_flags(struct qla_hw_data
*ha
)
1754 ha
->device_type
= DT_EXTENDED_IDS
;
1755 switch (ha
->pdev
->device
) {
1756 case PCI_DEVICE_ID_QLOGIC_ISP2100
:
1757 ha
->device_type
|= DT_ISP2100
;
1758 ha
->device_type
&= ~DT_EXTENDED_IDS
;
1759 ha
->fw_srisc_address
= RISC_START_ADDRESS_2100
;
1761 case PCI_DEVICE_ID_QLOGIC_ISP2200
:
1762 ha
->device_type
|= DT_ISP2200
;
1763 ha
->device_type
&= ~DT_EXTENDED_IDS
;
1764 ha
->fw_srisc_address
= RISC_START_ADDRESS_2100
;
1766 case PCI_DEVICE_ID_QLOGIC_ISP2300
:
1767 ha
->device_type
|= DT_ISP2300
;
1768 ha
->device_type
|= DT_ZIO_SUPPORTED
;
1769 ha
->fw_srisc_address
= RISC_START_ADDRESS_2300
;
1771 case PCI_DEVICE_ID_QLOGIC_ISP2312
:
1772 ha
->device_type
|= DT_ISP2312
;
1773 ha
->device_type
|= DT_ZIO_SUPPORTED
;
1774 ha
->fw_srisc_address
= RISC_START_ADDRESS_2300
;
1776 case PCI_DEVICE_ID_QLOGIC_ISP2322
:
1777 ha
->device_type
|= DT_ISP2322
;
1778 ha
->device_type
|= DT_ZIO_SUPPORTED
;
1779 if (ha
->pdev
->subsystem_vendor
== 0x1028 &&
1780 ha
->pdev
->subsystem_device
== 0x0170)
1781 ha
->device_type
|= DT_OEM_001
;
1782 ha
->fw_srisc_address
= RISC_START_ADDRESS_2300
;
1784 case PCI_DEVICE_ID_QLOGIC_ISP6312
:
1785 ha
->device_type
|= DT_ISP6312
;
1786 ha
->fw_srisc_address
= RISC_START_ADDRESS_2300
;
1788 case PCI_DEVICE_ID_QLOGIC_ISP6322
:
1789 ha
->device_type
|= DT_ISP6322
;
1790 ha
->fw_srisc_address
= RISC_START_ADDRESS_2300
;
1792 case PCI_DEVICE_ID_QLOGIC_ISP2422
:
1793 ha
->device_type
|= DT_ISP2422
;
1794 ha
->device_type
|= DT_ZIO_SUPPORTED
;
1795 ha
->device_type
|= DT_FWI2
;
1796 ha
->device_type
|= DT_IIDMA
;
1797 ha
->fw_srisc_address
= RISC_START_ADDRESS_2400
;
1799 case PCI_DEVICE_ID_QLOGIC_ISP2432
:
1800 ha
->device_type
|= DT_ISP2432
;
1801 ha
->device_type
|= DT_ZIO_SUPPORTED
;
1802 ha
->device_type
|= DT_FWI2
;
1803 ha
->device_type
|= DT_IIDMA
;
1804 ha
->fw_srisc_address
= RISC_START_ADDRESS_2400
;
1806 case PCI_DEVICE_ID_QLOGIC_ISP8432
:
1807 ha
->device_type
|= DT_ISP8432
;
1808 ha
->device_type
|= DT_ZIO_SUPPORTED
;
1809 ha
->device_type
|= DT_FWI2
;
1810 ha
->device_type
|= DT_IIDMA
;
1811 ha
->fw_srisc_address
= RISC_START_ADDRESS_2400
;
1813 case PCI_DEVICE_ID_QLOGIC_ISP5422
:
1814 ha
->device_type
|= DT_ISP5422
;
1815 ha
->device_type
|= DT_FWI2
;
1816 ha
->fw_srisc_address
= RISC_START_ADDRESS_2400
;
1818 case PCI_DEVICE_ID_QLOGIC_ISP5432
:
1819 ha
->device_type
|= DT_ISP5432
;
1820 ha
->device_type
|= DT_FWI2
;
1821 ha
->fw_srisc_address
= RISC_START_ADDRESS_2400
;
1823 case PCI_DEVICE_ID_QLOGIC_ISP2532
:
1824 ha
->device_type
|= DT_ISP2532
;
1825 ha
->device_type
|= DT_ZIO_SUPPORTED
;
1826 ha
->device_type
|= DT_FWI2
;
1827 ha
->device_type
|= DT_IIDMA
;
1828 ha
->fw_srisc_address
= RISC_START_ADDRESS_2400
;
1830 case PCI_DEVICE_ID_QLOGIC_ISP8001
:
1831 ha
->device_type
|= DT_ISP8001
;
1832 ha
->device_type
|= DT_ZIO_SUPPORTED
;
1833 ha
->device_type
|= DT_FWI2
;
1834 ha
->device_type
|= DT_IIDMA
;
1835 ha
->fw_srisc_address
= RISC_START_ADDRESS_2400
;
1837 case PCI_DEVICE_ID_QLOGIC_ISP8021
:
1838 ha
->device_type
|= DT_ISP8021
;
1839 ha
->device_type
|= DT_ZIO_SUPPORTED
;
1840 ha
->device_type
|= DT_FWI2
;
1841 ha
->fw_srisc_address
= RISC_START_ADDRESS_2400
;
1842 /* Initialize 82XX ISP flags */
1843 qla82xx_init_flags(ha
);
1848 ha
->port_no
= !(ha
->portnum
& 1);
1850 /* Get adapter physical port no from interrupt pin register. */
1851 pci_read_config_byte(ha
->pdev
, PCI_INTERRUPT_PIN
, &ha
->port_no
);
1853 if (ha
->port_no
& 1)
1854 ha
->flags
.port0
= 1;
1856 ha
->flags
.port0
= 0;
1857 ql_dbg_pci(ql_dbg_init
, ha
->pdev
, 0x000b,
1858 "device_type=0x%x port=%d fw_srisc_address=%p.\n",
1859 ha
->device_type
, ha
->flags
.port0
, ha
->fw_srisc_address
);
1863 qla2x00_iospace_config(struct qla_hw_data
*ha
)
1865 resource_size_t pio
;
1870 return qla82xx_iospace_config(ha
);
1872 if (pci_request_selected_regions(ha
->pdev
, ha
->bars
,
1873 QLA2XXX_DRIVER_NAME
)) {
1874 ql_log_pci(ql_log_fatal
, ha
->pdev
, 0x0011,
1875 "Failed to reserve PIO/MMIO regions (%s), aborting.\n",
1876 pci_name(ha
->pdev
));
1877 goto iospace_error_exit
;
1879 if (!(ha
->bars
& 1))
1882 /* We only need PIO for Flash operations on ISP2312 v2 chips. */
1883 pio
= pci_resource_start(ha
->pdev
, 0);
1884 if (pci_resource_flags(ha
->pdev
, 0) & IORESOURCE_IO
) {
1885 if (pci_resource_len(ha
->pdev
, 0) < MIN_IOBASE_LEN
) {
1886 ql_log_pci(ql_log_warn
, ha
->pdev
, 0x0012,
1887 "Invalid pci I/O region size (%s).\n",
1888 pci_name(ha
->pdev
));
1892 ql_log_pci(ql_log_warn
, ha
->pdev
, 0x0013,
1893 "Region #0 no a PIO resource (%s).\n",
1894 pci_name(ha
->pdev
));
1897 ha
->pio_address
= pio
;
1898 ql_dbg_pci(ql_dbg_init
, ha
->pdev
, 0x0014,
1899 "PIO address=%p.\n",
1903 /* Use MMIO operations for all accesses. */
1904 if (!(pci_resource_flags(ha
->pdev
, 1) & IORESOURCE_MEM
)) {
1905 ql_log_pci(ql_log_fatal
, ha
->pdev
, 0x0015,
1906 "Region #1 not an MMIO resource (%s), aborting.\n",
1907 pci_name(ha
->pdev
));
1908 goto iospace_error_exit
;
1910 if (pci_resource_len(ha
->pdev
, 1) < MIN_IOBASE_LEN
) {
1911 ql_log_pci(ql_log_fatal
, ha
->pdev
, 0x0016,
1912 "Invalid PCI mem region size (%s), aborting.\n",
1913 pci_name(ha
->pdev
));
1914 goto iospace_error_exit
;
1917 ha
->iobase
= ioremap(pci_resource_start(ha
->pdev
, 1), MIN_IOBASE_LEN
);
1919 ql_log_pci(ql_log_fatal
, ha
->pdev
, 0x0017,
1920 "Cannot remap MMIO (%s), aborting.\n",
1921 pci_name(ha
->pdev
));
1922 goto iospace_error_exit
;
1925 /* Determine queue resources */
1926 ha
->max_req_queues
= ha
->max_rsp_queues
= 1;
1927 if ((ql2xmaxqueues
<= 1 && !ql2xmultique_tag
) ||
1928 (ql2xmaxqueues
> 1 && ql2xmultique_tag
) ||
1929 (!IS_QLA25XX(ha
) && !IS_QLA81XX(ha
)))
1932 ha
->mqiobase
= ioremap(pci_resource_start(ha
->pdev
, 3),
1933 pci_resource_len(ha
->pdev
, 3));
1935 ql_dbg_pci(ql_dbg_init
, ha
->pdev
, 0x0018,
1936 "MQIO Base=%p.\n", ha
->mqiobase
);
1937 /* Read MSIX vector size of the board */
1938 pci_read_config_word(ha
->pdev
, QLA_PCI_MSIX_CONTROL
, &msix
);
1939 ha
->msix_count
= msix
;
1940 /* Max queues are bounded by available msix vectors */
1941 /* queue 0 uses two msix vectors */
1942 if (ql2xmultique_tag
) {
1943 cpus
= num_online_cpus();
1944 ha
->max_rsp_queues
= (ha
->msix_count
- 1 > cpus
) ?
1945 (cpus
+ 1) : (ha
->msix_count
- 1);
1946 ha
->max_req_queues
= 2;
1947 } else if (ql2xmaxqueues
> 1) {
1948 ha
->max_req_queues
= ql2xmaxqueues
> QLA_MQ_SIZE
?
1949 QLA_MQ_SIZE
: ql2xmaxqueues
;
1950 ql_dbg_pci(ql_dbg_multiq
, ha
->pdev
, 0xc008,
1951 "QoS mode set, max no of request queues:%d.\n",
1952 ha
->max_req_queues
);
1953 ql_dbg_pci(ql_dbg_init
, ha
->pdev
, 0x0019,
1954 "QoS mode set, max no of request queues:%d.\n",
1955 ha
->max_req_queues
);
1957 ql_log_pci(ql_log_info
, ha
->pdev
, 0x001a,
1958 "MSI-X vector count: %d.\n", msix
);
1960 ql_log_pci(ql_log_info
, ha
->pdev
, 0x001b,
1961 "BAR 3 not enabled.\n");
1964 ha
->msix_count
= ha
->max_rsp_queues
+ 1;
1965 ql_dbg_pci(ql_dbg_init
, ha
->pdev
, 0x001c,
1966 "MSIX Count:%d.\n", ha
->msix_count
);
1974 qla2xxx_scan_start(struct Scsi_Host
*shost
)
1976 scsi_qla_host_t
*vha
= shost_priv(shost
);
1978 if (vha
->hw
->flags
.running_gold_fw
)
1981 set_bit(LOOP_RESYNC_NEEDED
, &vha
->dpc_flags
);
1982 set_bit(LOCAL_LOOP_UPDATE
, &vha
->dpc_flags
);
1983 set_bit(RSCN_UPDATE
, &vha
->dpc_flags
);
1984 set_bit(NPIV_CONFIG_NEEDED
, &vha
->dpc_flags
);
1988 qla2xxx_scan_finished(struct Scsi_Host
*shost
, unsigned long time
)
1990 scsi_qla_host_t
*vha
= shost_priv(shost
);
1994 if (time
> vha
->hw
->loop_reset_delay
* HZ
)
1997 return atomic_read(&vha
->loop_state
) == LOOP_READY
;
2001 * PCI driver interface
2003 static int __devinit
2004 qla2x00_probe_one(struct pci_dev
*pdev
, const struct pci_device_id
*id
)
2007 struct Scsi_Host
*host
;
2008 scsi_qla_host_t
*base_vha
= NULL
;
2009 struct qla_hw_data
*ha
;
2012 struct scsi_host_template
*sht
;
2013 int bars
, max_id
, mem_only
= 0;
2014 uint16_t req_length
= 0, rsp_length
= 0;
2015 struct req_que
*req
= NULL
;
2016 struct rsp_que
*rsp
= NULL
;
2018 bars
= pci_select_bars(pdev
, IORESOURCE_MEM
| IORESOURCE_IO
);
2019 sht
= &qla2xxx_driver_template
;
2020 if (pdev
->device
== PCI_DEVICE_ID_QLOGIC_ISP2422
||
2021 pdev
->device
== PCI_DEVICE_ID_QLOGIC_ISP2432
||
2022 pdev
->device
== PCI_DEVICE_ID_QLOGIC_ISP8432
||
2023 pdev
->device
== PCI_DEVICE_ID_QLOGIC_ISP5422
||
2024 pdev
->device
== PCI_DEVICE_ID_QLOGIC_ISP5432
||
2025 pdev
->device
== PCI_DEVICE_ID_QLOGIC_ISP2532
||
2026 pdev
->device
== PCI_DEVICE_ID_QLOGIC_ISP8001
||
2027 pdev
->device
== PCI_DEVICE_ID_QLOGIC_ISP8021
) {
2028 bars
= pci_select_bars(pdev
, IORESOURCE_MEM
);
2030 ql_dbg_pci(ql_dbg_init
, pdev
, 0x0007,
2031 "Mem only adapter.\n");
2033 ql_dbg_pci(ql_dbg_init
, pdev
, 0x0008,
2034 "Bars=%d.\n", bars
);
2037 if (pci_enable_device_mem(pdev
))
2040 if (pci_enable_device(pdev
))
2044 /* This may fail but that's ok */
2045 pci_enable_pcie_error_reporting(pdev
);
2047 ha
= kzalloc(sizeof(struct qla_hw_data
), GFP_KERNEL
);
2049 ql_log_pci(ql_log_fatal
, pdev
, 0x0009,
2050 "Unable to allocate memory for ha.\n");
2053 ql_dbg_pci(ql_dbg_init
, pdev
, 0x000a,
2054 "Memory allocated for ha=%p.\n", ha
);
2057 /* Clear our data area */
2059 ha
->mem_only
= mem_only
;
2060 spin_lock_init(&ha
->hardware_lock
);
2061 spin_lock_init(&ha
->vport_slock
);
2063 /* Set ISP-type information. */
2064 qla2x00_set_isp_flags(ha
);
2066 /* Set EEH reset type to fundamental if required by hba */
2067 if ( IS_QLA24XX(ha
) || IS_QLA25XX(ha
) || IS_QLA81XX(ha
)) {
2068 pdev
->needs_freset
= 1;
2071 /* Configure PCI I/O space */
2072 ret
= qla2x00_iospace_config(ha
);
2074 goto probe_hw_failed
;
2076 ql_log_pci(ql_log_info
, pdev
, 0x001d,
2077 "Found an ISP%04X irq %d iobase 0x%p.\n",
2078 pdev
->device
, pdev
->irq
, ha
->iobase
);
2079 ha
->prev_topology
= 0;
2080 ha
->init_cb_size
= sizeof(init_cb_t
);
2081 ha
->link_data_rate
= PORT_SPEED_UNKNOWN
;
2082 ha
->optrom_size
= OPTROM_SIZE_2300
;
2084 /* Assign ISP specific operations. */
2085 max_id
= MAX_TARGETS_2200
;
2086 if (IS_QLA2100(ha
)) {
2087 max_id
= MAX_TARGETS_2100
;
2088 ha
->mbx_count
= MAILBOX_REGISTER_COUNT_2100
;
2089 req_length
= REQUEST_ENTRY_CNT_2100
;
2090 rsp_length
= RESPONSE_ENTRY_CNT_2100
;
2091 ha
->max_loop_id
= SNS_LAST_LOOP_ID_2100
;
2092 ha
->gid_list_info_size
= 4;
2093 ha
->flash_conf_off
= ~0;
2094 ha
->flash_data_off
= ~0;
2095 ha
->nvram_conf_off
= ~0;
2096 ha
->nvram_data_off
= ~0;
2097 ha
->isp_ops
= &qla2100_isp_ops
;
2098 } else if (IS_QLA2200(ha
)) {
2099 ha
->mbx_count
= MAILBOX_REGISTER_COUNT
;
2100 req_length
= REQUEST_ENTRY_CNT_2200
;
2101 rsp_length
= RESPONSE_ENTRY_CNT_2100
;
2102 ha
->max_loop_id
= SNS_LAST_LOOP_ID_2100
;
2103 ha
->gid_list_info_size
= 4;
2104 ha
->flash_conf_off
= ~0;
2105 ha
->flash_data_off
= ~0;
2106 ha
->nvram_conf_off
= ~0;
2107 ha
->nvram_data_off
= ~0;
2108 ha
->isp_ops
= &qla2100_isp_ops
;
2109 } else if (IS_QLA23XX(ha
)) {
2110 ha
->mbx_count
= MAILBOX_REGISTER_COUNT
;
2111 req_length
= REQUEST_ENTRY_CNT_2200
;
2112 rsp_length
= RESPONSE_ENTRY_CNT_2300
;
2113 ha
->max_loop_id
= SNS_LAST_LOOP_ID_2300
;
2114 ha
->gid_list_info_size
= 6;
2115 if (IS_QLA2322(ha
) || IS_QLA6322(ha
))
2116 ha
->optrom_size
= OPTROM_SIZE_2322
;
2117 ha
->flash_conf_off
= ~0;
2118 ha
->flash_data_off
= ~0;
2119 ha
->nvram_conf_off
= ~0;
2120 ha
->nvram_data_off
= ~0;
2121 ha
->isp_ops
= &qla2300_isp_ops
;
2122 } else if (IS_QLA24XX_TYPE(ha
)) {
2123 ha
->mbx_count
= MAILBOX_REGISTER_COUNT
;
2124 req_length
= REQUEST_ENTRY_CNT_24XX
;
2125 rsp_length
= RESPONSE_ENTRY_CNT_2300
;
2126 ha
->max_loop_id
= SNS_LAST_LOOP_ID_2300
;
2127 ha
->init_cb_size
= sizeof(struct mid_init_cb_24xx
);
2128 ha
->gid_list_info_size
= 8;
2129 ha
->optrom_size
= OPTROM_SIZE_24XX
;
2130 ha
->nvram_npiv_size
= QLA_MAX_VPORTS_QLA24XX
;
2131 ha
->isp_ops
= &qla24xx_isp_ops
;
2132 ha
->flash_conf_off
= FARX_ACCESS_FLASH_CONF
;
2133 ha
->flash_data_off
= FARX_ACCESS_FLASH_DATA
;
2134 ha
->nvram_conf_off
= FARX_ACCESS_NVRAM_CONF
;
2135 ha
->nvram_data_off
= FARX_ACCESS_NVRAM_DATA
;
2136 } else if (IS_QLA25XX(ha
)) {
2137 ha
->mbx_count
= MAILBOX_REGISTER_COUNT
;
2138 req_length
= REQUEST_ENTRY_CNT_24XX
;
2139 rsp_length
= RESPONSE_ENTRY_CNT_2300
;
2140 ha
->max_loop_id
= SNS_LAST_LOOP_ID_2300
;
2141 ha
->init_cb_size
= sizeof(struct mid_init_cb_24xx
);
2142 ha
->gid_list_info_size
= 8;
2143 ha
->optrom_size
= OPTROM_SIZE_25XX
;
2144 ha
->nvram_npiv_size
= QLA_MAX_VPORTS_QLA25XX
;
2145 ha
->isp_ops
= &qla25xx_isp_ops
;
2146 ha
->flash_conf_off
= FARX_ACCESS_FLASH_CONF
;
2147 ha
->flash_data_off
= FARX_ACCESS_FLASH_DATA
;
2148 ha
->nvram_conf_off
= FARX_ACCESS_NVRAM_CONF
;
2149 ha
->nvram_data_off
= FARX_ACCESS_NVRAM_DATA
;
2150 } else if (IS_QLA81XX(ha
)) {
2151 ha
->mbx_count
= MAILBOX_REGISTER_COUNT
;
2152 req_length
= REQUEST_ENTRY_CNT_24XX
;
2153 rsp_length
= RESPONSE_ENTRY_CNT_2300
;
2154 ha
->max_loop_id
= SNS_LAST_LOOP_ID_2300
;
2155 ha
->init_cb_size
= sizeof(struct mid_init_cb_81xx
);
2156 ha
->gid_list_info_size
= 8;
2157 ha
->optrom_size
= OPTROM_SIZE_81XX
;
2158 ha
->nvram_npiv_size
= QLA_MAX_VPORTS_QLA25XX
;
2159 ha
->isp_ops
= &qla81xx_isp_ops
;
2160 ha
->flash_conf_off
= FARX_ACCESS_FLASH_CONF_81XX
;
2161 ha
->flash_data_off
= FARX_ACCESS_FLASH_DATA_81XX
;
2162 ha
->nvram_conf_off
= ~0;
2163 ha
->nvram_data_off
= ~0;
2164 } else if (IS_QLA82XX(ha
)) {
2165 ha
->mbx_count
= MAILBOX_REGISTER_COUNT
;
2166 req_length
= REQUEST_ENTRY_CNT_82XX
;
2167 rsp_length
= RESPONSE_ENTRY_CNT_82XX
;
2168 ha
->max_loop_id
= SNS_LAST_LOOP_ID_2300
;
2169 ha
->init_cb_size
= sizeof(struct mid_init_cb_81xx
);
2170 ha
->gid_list_info_size
= 8;
2171 ha
->optrom_size
= OPTROM_SIZE_82XX
;
2172 ha
->nvram_npiv_size
= QLA_MAX_VPORTS_QLA25XX
;
2173 ha
->isp_ops
= &qla82xx_isp_ops
;
2174 ha
->flash_conf_off
= FARX_ACCESS_FLASH_CONF
;
2175 ha
->flash_data_off
= FARX_ACCESS_FLASH_DATA
;
2176 ha
->nvram_conf_off
= FARX_ACCESS_NVRAM_CONF
;
2177 ha
->nvram_data_off
= FARX_ACCESS_NVRAM_DATA
;
2179 ql_dbg_pci(ql_dbg_init
, pdev
, 0x001e,
2180 "mbx_count=%d, req_length=%d, "
2181 "rsp_length=%d, max_loop_id=%d, init_cb_size=%d, "
2182 "gid_list_info_size=%d, optrom_size=%d, nvram_npiv_size=%d, .\n",
2183 ha
->mbx_count
, req_length
, rsp_length
, ha
->max_loop_id
,
2184 ha
->init_cb_size
, ha
->gid_list_info_size
, ha
->optrom_size
,
2185 ha
->nvram_npiv_size
);
2186 ql_dbg_pci(ql_dbg_init
, pdev
, 0x001f,
2187 "isp_ops=%p, flash_conf_off=%d, "
2188 "flash_data_off=%d, nvram_conf_off=%d, nvram_data_off=%d.\n",
2189 ha
->isp_ops
, ha
->flash_conf_off
, ha
->flash_data_off
,
2190 ha
->nvram_conf_off
, ha
->nvram_data_off
);
2191 mutex_init(&ha
->vport_lock
);
2192 init_completion(&ha
->mbx_cmd_comp
);
2193 complete(&ha
->mbx_cmd_comp
);
2194 init_completion(&ha
->mbx_intr_comp
);
2195 init_completion(&ha
->dcbx_comp
);
2197 set_bit(0, (unsigned long *) ha
->vp_idx_map
);
2199 qla2x00_config_dma_addressing(ha
);
2200 ql_dbg_pci(ql_dbg_init
, pdev
, 0x0020,
2201 "64 Bit addressing is %s.\n",
2202 ha
->flags
.enable_64bit_addressing
? "enable" :
2204 ret
= qla2x00_mem_alloc(ha
, req_length
, rsp_length
, &req
, &rsp
);
2206 ql_log_pci(ql_log_fatal
, pdev
, 0x0031,
2207 "Failed to allocate memory for adapter, aborting.\n");
2209 goto probe_hw_failed
;
2212 req
->max_q_depth
= MAX_Q_DEPTH
;
2213 if (ql2xmaxqdepth
!= 0 && ql2xmaxqdepth
<= 0xffffU
)
2214 req
->max_q_depth
= ql2xmaxqdepth
;
2217 base_vha
= qla2x00_create_host(sht
, ha
);
2220 qla2x00_mem_free(ha
);
2221 qla2x00_free_req_que(ha
, req
);
2222 qla2x00_free_rsp_que(ha
, rsp
);
2223 goto probe_hw_failed
;
2226 pci_set_drvdata(pdev
, base_vha
);
2228 host
= base_vha
->host
;
2229 base_vha
->req
= req
;
2230 host
->can_queue
= req
->length
+ 128;
2231 if (IS_QLA2XXX_MIDTYPE(ha
))
2232 base_vha
->mgmt_svr_loop_id
= 10 + base_vha
->vp_idx
;
2234 base_vha
->mgmt_svr_loop_id
= MANAGEMENT_SERVER
+
2237 /* Set the SG table size based on ISP type */
2238 if (!IS_FWI2_CAPABLE(ha
)) {
2240 host
->sg_tablesize
= 32;
2242 if (!IS_QLA82XX(ha
))
2243 host
->sg_tablesize
= QLA_SG_ALL
;
2245 ql_dbg(ql_dbg_init
, base_vha
, 0x0032,
2246 "can_queue=%d, req=%p, "
2247 "mgmt_svr_loop_id=%d, sg_tablesize=%d.\n",
2248 host
->can_queue
, base_vha
->req
,
2249 base_vha
->mgmt_svr_loop_id
, host
->sg_tablesize
);
2250 host
->max_id
= max_id
;
2251 host
->this_id
= 255;
2252 host
->cmd_per_lun
= 3;
2253 host
->unique_id
= host
->host_no
;
2254 if ((IS_QLA25XX(ha
) || IS_QLA81XX(ha
)) && ql2xenabledif
)
2255 host
->max_cmd_len
= 32;
2257 host
->max_cmd_len
= MAX_CMDSZ
;
2258 host
->max_channel
= MAX_BUSES
- 1;
2259 host
->max_lun
= ql2xmaxlun
;
2260 host
->transportt
= qla2xxx_transport_template
;
2261 sht
->vendor_id
= (SCSI_NL_VID_TYPE_PCI
| PCI_VENDOR_ID_QLOGIC
);
2263 ql_dbg(ql_dbg_init
, base_vha
, 0x0033,
2264 "max_id=%d this_id=%d "
2265 "cmd_per_len=%d unique_id=%d max_cmd_len=%d max_channel=%d "
2266 "max_lun=%d transportt=%p, vendor_id=%d.\n", host
->max_id
,
2267 host
->this_id
, host
->cmd_per_lun
, host
->unique_id
,
2268 host
->max_cmd_len
, host
->max_channel
, host
->max_lun
,
2269 host
->transportt
, sht
->vendor_id
);
2271 /* Set up the irqs */
2272 ret
= qla2x00_request_irqs(ha
, rsp
);
2274 goto probe_init_failed
;
2276 pci_save_state(pdev
);
2278 /* Alloc arrays of request and response ring ptrs */
2280 if (!qla2x00_alloc_queues(ha
)) {
2281 ql_log(ql_log_fatal
, base_vha
, 0x003d,
2282 "Failed to allocate memory for queue pointers.. aborting.\n");
2283 goto probe_init_failed
;
2286 ha
->rsp_q_map
[0] = rsp
;
2287 ha
->req_q_map
[0] = req
;
2290 set_bit(0, ha
->req_qid_map
);
2291 set_bit(0, ha
->rsp_qid_map
);
2292 /* FWI2-capable only. */
2293 req
->req_q_in
= &ha
->iobase
->isp24
.req_q_in
;
2294 req
->req_q_out
= &ha
->iobase
->isp24
.req_q_out
;
2295 rsp
->rsp_q_in
= &ha
->iobase
->isp24
.rsp_q_in
;
2296 rsp
->rsp_q_out
= &ha
->iobase
->isp24
.rsp_q_out
;
2298 req
->req_q_in
= &ha
->mqiobase
->isp25mq
.req_q_in
;
2299 req
->req_q_out
= &ha
->mqiobase
->isp25mq
.req_q_out
;
2300 rsp
->rsp_q_in
= &ha
->mqiobase
->isp25mq
.rsp_q_in
;
2301 rsp
->rsp_q_out
= &ha
->mqiobase
->isp25mq
.rsp_q_out
;
2304 if (IS_QLA82XX(ha
)) {
2305 req
->req_q_out
= &ha
->iobase
->isp82
.req_q_out
[0];
2306 rsp
->rsp_q_in
= &ha
->iobase
->isp82
.rsp_q_in
[0];
2307 rsp
->rsp_q_out
= &ha
->iobase
->isp82
.rsp_q_out
[0];
2310 ql_dbg(ql_dbg_multiq
, base_vha
, 0xc009,
2311 "rsp_q_map=%p req_q_map=%p rsp->req=%p req->rsp=%p.\n",
2312 ha
->rsp_q_map
, ha
->req_q_map
, rsp
->req
, req
->rsp
);
2313 ql_dbg(ql_dbg_multiq
, base_vha
, 0xc00a,
2314 "req->req_q_in=%p req->req_q_out=%p "
2315 "rsp->rsp_q_in=%p rsp->rsp_q_out=%p.\n",
2316 req
->req_q_in
, req
->req_q_out
,
2317 rsp
->rsp_q_in
, rsp
->rsp_q_out
);
2318 ql_dbg(ql_dbg_init
, base_vha
, 0x003e,
2319 "rsp_q_map=%p req_q_map=%p rsp->req=%p req->rsp=%p.\n",
2320 ha
->rsp_q_map
, ha
->req_q_map
, rsp
->req
, req
->rsp
);
2321 ql_dbg(ql_dbg_init
, base_vha
, 0x003f,
2322 "req->req_q_in=%p req->req_q_out=%p rsp->rsp_q_in=%p rsp->rsp_q_out=%p.\n",
2323 req
->req_q_in
, req
->req_q_out
, rsp
->rsp_q_in
, rsp
->rsp_q_out
);
2325 if (qla2x00_initialize_adapter(base_vha
)) {
2326 ql_log(ql_log_fatal
, base_vha
, 0x00d6,
2327 "Failed to initialize adapter - Adapter flags %x.\n",
2328 base_vha
->device_flags
);
2330 if (IS_QLA82XX(ha
)) {
2331 qla82xx_idc_lock(ha
);
2332 qla82xx_wr_32(ha
, QLA82XX_CRB_DEV_STATE
,
2333 QLA82XX_DEV_FAILED
);
2334 qla82xx_idc_unlock(ha
);
2335 ql_log(ql_log_fatal
, base_vha
, 0x00d7,
2336 "HW State: FAILED.\n");
2344 if (qla25xx_setup_mode(base_vha
)) {
2345 ql_log(ql_log_warn
, base_vha
, 0x00ec,
2346 "Failed to create queues, falling back to single queue mode.\n");
2351 if (ha
->flags
.running_gold_fw
)
2355 * Startup the kernel thread for this host adapter
2357 ha
->dpc_thread
= kthread_create(qla2x00_do_dpc
, ha
,
2358 "%s_dpc", base_vha
->host_str
);
2359 if (IS_ERR(ha
->dpc_thread
)) {
2360 ql_log(ql_log_fatal
, base_vha
, 0x00ed,
2361 "Failed to start DPC thread.\n");
2362 ret
= PTR_ERR(ha
->dpc_thread
);
2365 ql_dbg(ql_dbg_init
, base_vha
, 0x00ee,
2366 "DPC thread started successfully.\n");
2369 list_add_tail(&base_vha
->list
, &ha
->vp_list
);
2370 base_vha
->host
->irq
= ha
->pdev
->irq
;
2372 /* Initialized the timer */
2373 qla2x00_start_timer(base_vha
, qla2x00_timer
, WATCH_INTERVAL
);
2374 ql_dbg(ql_dbg_init
, base_vha
, 0x00ef,
2375 "Started qla2x00_timer with "
2376 "interval=%d.\n", WATCH_INTERVAL
);
2377 ql_dbg(ql_dbg_init
, base_vha
, 0x00f0,
2378 "Detected hba at address=%p.\n",
2381 if ((IS_QLA25XX(ha
) || IS_QLA81XX(ha
)) && ql2xenabledif
) {
2382 if (ha
->fw_attributes
& BIT_4
) {
2383 base_vha
->flags
.difdix_supported
= 1;
2384 ql_dbg(ql_dbg_init
, base_vha
, 0x00f1,
2385 "Registering for DIF/DIX type 1 and 3 protection.\n");
2386 scsi_host_set_prot(host
,
2387 SHOST_DIF_TYPE1_PROTECTION
2388 | SHOST_DIF_TYPE2_PROTECTION
2389 | SHOST_DIF_TYPE3_PROTECTION
2390 | SHOST_DIX_TYPE1_PROTECTION
2391 | SHOST_DIX_TYPE2_PROTECTION
2392 | SHOST_DIX_TYPE3_PROTECTION
);
2393 scsi_host_set_guard(host
, SHOST_DIX_GUARD_CRC
);
2395 base_vha
->flags
.difdix_supported
= 0;
2398 ha
->isp_ops
->enable_intrs(ha
);
2400 ret
= scsi_add_host(host
, &pdev
->dev
);
2404 base_vha
->flags
.init_done
= 1;
2405 base_vha
->flags
.online
= 1;
2407 ql_dbg(ql_dbg_init
, base_vha
, 0x00f2,
2408 "Init done and hba is online.\n");
2410 scsi_scan_host(host
);
2412 qla2x00_alloc_sysfs_attr(base_vha
);
2414 qla2x00_init_host_attr(base_vha
);
2416 qla2x00_dfs_setup(base_vha
);
2418 ql_log(ql_log_info
, base_vha
, 0x00fa,
2419 "QLogic Fibre Channed HBA Driver: %s.\n",
2420 qla2x00_version_str
);
2421 ql_log(ql_log_info
, base_vha
, 0x00fb,
2422 "QLogic %s - %s.\n",
2423 ha
->model_number
, ha
->model_desc
? ha
->model_desc
: "");
2424 ql_log(ql_log_info
, base_vha
, 0x00fc,
2425 "ISP%04X: %s @ %s hdma%c host#=%ld fw=%s.\n",
2426 pdev
->device
, ha
->isp_ops
->pci_info_str(base_vha
, pci_info
),
2427 pci_name(pdev
), ha
->flags
.enable_64bit_addressing
? '+' : '-',
2429 ha
->isp_ops
->fw_version_str(base_vha
, fw_str
));
2434 qla2x00_free_req_que(ha
, req
);
2435 qla2x00_free_rsp_que(ha
, rsp
);
2436 ha
->max_req_queues
= ha
->max_rsp_queues
= 0;
2439 if (base_vha
->timer_active
)
2440 qla2x00_stop_timer(base_vha
);
2441 base_vha
->flags
.online
= 0;
2442 if (ha
->dpc_thread
) {
2443 struct task_struct
*t
= ha
->dpc_thread
;
2445 ha
->dpc_thread
= NULL
;
2449 qla2x00_free_device(base_vha
);
2451 scsi_host_put(base_vha
->host
);
2454 if (IS_QLA82XX(ha
)) {
2455 qla82xx_idc_lock(ha
);
2456 qla82xx_clear_drv_active(ha
);
2457 qla82xx_idc_unlock(ha
);
2458 iounmap((device_reg_t __iomem
*)ha
->nx_pcibase
);
2460 iounmap((device_reg_t __iomem
*)ha
->nxdb_wr_ptr
);
2463 iounmap(ha
->iobase
);
2465 pci_release_selected_regions(ha
->pdev
, ha
->bars
);
2470 pci_disable_device(pdev
);
2475 qla2x00_shutdown(struct pci_dev
*pdev
)
2477 scsi_qla_host_t
*vha
;
2478 struct qla_hw_data
*ha
;
2480 vha
= pci_get_drvdata(pdev
);
2483 /* Turn-off FCE trace */
2484 if (ha
->flags
.fce_enabled
) {
2485 qla2x00_disable_fce_trace(vha
, NULL
, NULL
);
2486 ha
->flags
.fce_enabled
= 0;
2489 /* Turn-off EFT trace */
2491 qla2x00_disable_eft_trace(vha
);
2493 /* Stop currently executing firmware. */
2494 qla2x00_try_to_stop_firmware(vha
);
2496 /* Turn adapter off line */
2497 vha
->flags
.online
= 0;
2499 /* turn-off interrupts on the card */
2500 if (ha
->interrupts_on
) {
2501 vha
->flags
.init_done
= 0;
2502 ha
->isp_ops
->disable_intrs(ha
);
2505 qla2x00_free_irqs(vha
);
2507 qla2x00_free_fw_dump(ha
);
2511 qla2x00_remove_one(struct pci_dev
*pdev
)
2513 scsi_qla_host_t
*base_vha
, *vha
;
2514 struct qla_hw_data
*ha
;
2515 unsigned long flags
;
2517 base_vha
= pci_get_drvdata(pdev
);
2520 mutex_lock(&ha
->vport_lock
);
2521 while (ha
->cur_vport_count
) {
2522 struct Scsi_Host
*scsi_host
;
2524 spin_lock_irqsave(&ha
->vport_slock
, flags
);
2526 BUG_ON(base_vha
->list
.next
== &ha
->vp_list
);
2527 /* This assumes first entry in ha->vp_list is always base vha */
2528 vha
= list_first_entry(&base_vha
->list
, scsi_qla_host_t
, list
);
2529 scsi_host
= scsi_host_get(vha
->host
);
2531 spin_unlock_irqrestore(&ha
->vport_slock
, flags
);
2532 mutex_unlock(&ha
->vport_lock
);
2534 fc_vport_terminate(vha
->fc_vport
);
2535 scsi_host_put(vha
->host
);
2537 mutex_lock(&ha
->vport_lock
);
2539 mutex_unlock(&ha
->vport_lock
);
2541 set_bit(UNLOADING
, &base_vha
->dpc_flags
);
2543 qla2x00_abort_all_cmds(base_vha
, DID_NO_CONNECT
<< 16);
2545 qla2x00_dfs_remove(base_vha
);
2547 qla84xx_put_chip(base_vha
);
2550 if (base_vha
->timer_active
)
2551 qla2x00_stop_timer(base_vha
);
2553 base_vha
->flags
.online
= 0;
2555 /* Flush the work queue and remove it */
2557 flush_workqueue(ha
->wq
);
2558 destroy_workqueue(ha
->wq
);
2562 /* Kill the kernel thread for this host */
2563 if (ha
->dpc_thread
) {
2564 struct task_struct
*t
= ha
->dpc_thread
;
2567 * qla2xxx_wake_dpc checks for ->dpc_thread
2568 * so we need to zero it out.
2570 ha
->dpc_thread
= NULL
;
2574 qla2x00_free_sysfs_attr(base_vha
);
2576 fc_remove_host(base_vha
->host
);
2578 scsi_remove_host(base_vha
->host
);
2580 qla2x00_free_device(base_vha
);
2582 scsi_host_put(base_vha
->host
);
2584 if (IS_QLA82XX(ha
)) {
2585 qla82xx_idc_lock(ha
);
2586 qla82xx_clear_drv_active(ha
);
2587 qla82xx_idc_unlock(ha
);
2589 iounmap((device_reg_t __iomem
*)ha
->nx_pcibase
);
2591 iounmap((device_reg_t __iomem
*)ha
->nxdb_wr_ptr
);
2594 iounmap(ha
->iobase
);
2597 iounmap(ha
->mqiobase
);
2600 pci_release_selected_regions(ha
->pdev
, ha
->bars
);
2604 pci_disable_pcie_error_reporting(pdev
);
2606 pci_disable_device(pdev
);
2607 pci_set_drvdata(pdev
, NULL
);
2611 qla2x00_free_device(scsi_qla_host_t
*vha
)
2613 struct qla_hw_data
*ha
= vha
->hw
;
2615 qla2x00_abort_all_cmds(vha
, DID_NO_CONNECT
<< 16);
2618 if (vha
->timer_active
)
2619 qla2x00_stop_timer(vha
);
2621 /* Kill the kernel thread for this host */
2622 if (ha
->dpc_thread
) {
2623 struct task_struct
*t
= ha
->dpc_thread
;
2626 * qla2xxx_wake_dpc checks for ->dpc_thread
2627 * so we need to zero it out.
2629 ha
->dpc_thread
= NULL
;
2633 qla25xx_delete_queues(vha
);
2635 if (ha
->flags
.fce_enabled
)
2636 qla2x00_disable_fce_trace(vha
, NULL
, NULL
);
2639 qla2x00_disable_eft_trace(vha
);
2641 /* Stop currently executing firmware. */
2642 qla2x00_try_to_stop_firmware(vha
);
2644 vha
->flags
.online
= 0;
2646 /* turn-off interrupts on the card */
2647 if (ha
->interrupts_on
) {
2648 vha
->flags
.init_done
= 0;
2649 ha
->isp_ops
->disable_intrs(ha
);
2652 qla2x00_free_irqs(vha
);
2654 qla2x00_free_fcports(vha
);
2656 qla2x00_mem_free(ha
);
2658 qla2x00_free_queues(ha
);
2661 void qla2x00_free_fcports(struct scsi_qla_host
*vha
)
2663 fc_port_t
*fcport
, *tfcport
;
2665 list_for_each_entry_safe(fcport
, tfcport
, &vha
->vp_fcports
, list
) {
2666 list_del(&fcport
->list
);
2673 qla2x00_schedule_rport_del(struct scsi_qla_host
*vha
, fc_port_t
*fcport
,
2676 struct fc_rport
*rport
;
2677 scsi_qla_host_t
*base_vha
;
2678 unsigned long flags
;
2683 rport
= fcport
->rport
;
2685 base_vha
= pci_get_drvdata(vha
->hw
->pdev
);
2686 spin_lock_irqsave(vha
->host
->host_lock
, flags
);
2687 fcport
->drport
= rport
;
2688 spin_unlock_irqrestore(vha
->host
->host_lock
, flags
);
2689 set_bit(FCPORT_UPDATE_NEEDED
, &base_vha
->dpc_flags
);
2690 qla2xxx_wake_dpc(base_vha
);
2692 fc_remote_port_delete(rport
);
2696 * qla2x00_mark_device_lost Updates fcport state when device goes offline.
2698 * Input: ha = adapter block pointer. fcport = port structure pointer.
2704 void qla2x00_mark_device_lost(scsi_qla_host_t
*vha
, fc_port_t
*fcport
,
2705 int do_login
, int defer
)
2707 if (atomic_read(&fcport
->state
) == FCS_ONLINE
&&
2708 vha
->vp_idx
== fcport
->vp_idx
) {
2709 qla2x00_set_fcport_state(fcport
, FCS_DEVICE_LOST
);
2710 qla2x00_schedule_rport_del(vha
, fcport
, defer
);
2713 * We may need to retry the login, so don't change the state of the
2714 * port but do the retries.
2716 if (atomic_read(&fcport
->state
) != FCS_DEVICE_DEAD
)
2717 qla2x00_set_fcport_state(fcport
, FCS_DEVICE_LOST
);
2722 if (fcport
->login_retry
== 0) {
2723 fcport
->login_retry
= vha
->hw
->login_retry_count
;
2724 set_bit(RELOGIN_NEEDED
, &vha
->dpc_flags
);
2726 ql_dbg(ql_dbg_disc
, vha
, 0x2067,
2728 "%02x%02x%02x%02x%02x%02x%02x%02x, "
2729 "id = 0x%04x retry cnt=%d.\n",
2730 fcport
->port_name
[0], fcport
->port_name
[1],
2731 fcport
->port_name
[2], fcport
->port_name
[3],
2732 fcport
->port_name
[4], fcport
->port_name
[5],
2733 fcport
->port_name
[6], fcport
->port_name
[7],
2734 fcport
->loop_id
, fcport
->login_retry
);
2739 * qla2x00_mark_all_devices_lost
2740 * Updates fcport state when device goes offline.
2743 * ha = adapter block pointer.
2744 * fcport = port structure pointer.
2752 qla2x00_mark_all_devices_lost(scsi_qla_host_t
*vha
, int defer
)
2756 list_for_each_entry(fcport
, &vha
->vp_fcports
, list
) {
2757 if (vha
->vp_idx
!= 0 && vha
->vp_idx
!= fcport
->vp_idx
)
2761 * No point in marking the device as lost, if the device is
2764 if (atomic_read(&fcport
->state
) == FCS_DEVICE_DEAD
)
2766 if (atomic_read(&fcport
->state
) == FCS_ONLINE
) {
2767 qla2x00_set_fcport_state(fcport
, FCS_DEVICE_LOST
);
2769 qla2x00_schedule_rport_del(vha
, fcport
, defer
);
2770 else if (vha
->vp_idx
== fcport
->vp_idx
)
2771 qla2x00_schedule_rport_del(vha
, fcport
, defer
);
2778 * Allocates adapter memory.
2785 qla2x00_mem_alloc(struct qla_hw_data
*ha
, uint16_t req_len
, uint16_t rsp_len
,
2786 struct req_que
**req
, struct rsp_que
**rsp
)
2790 ha
->init_cb
= dma_alloc_coherent(&ha
->pdev
->dev
, ha
->init_cb_size
,
2791 &ha
->init_cb_dma
, GFP_KERNEL
);
2795 ha
->gid_list
= dma_alloc_coherent(&ha
->pdev
->dev
, GID_LIST_SIZE
,
2796 &ha
->gid_list_dma
, GFP_KERNEL
);
2798 goto fail_free_init_cb
;
2800 ha
->srb_mempool
= mempool_create_slab_pool(SRB_MIN_REQ
, srb_cachep
);
2801 if (!ha
->srb_mempool
)
2802 goto fail_free_gid_list
;
2804 if (IS_QLA82XX(ha
)) {
2805 /* Allocate cache for CT6 Ctx. */
2807 ctx_cachep
= kmem_cache_create("qla2xxx_ctx",
2808 sizeof(struct ct6_dsd
), 0,
2809 SLAB_HWCACHE_ALIGN
, NULL
);
2811 goto fail_free_gid_list
;
2813 ha
->ctx_mempool
= mempool_create_slab_pool(SRB_MIN_REQ
,
2815 if (!ha
->ctx_mempool
)
2816 goto fail_free_srb_mempool
;
2817 ql_dbg_pci(ql_dbg_init
, ha
->pdev
, 0x0021,
2818 "ctx_cachep=%p ctx_mempool=%p.\n",
2819 ctx_cachep
, ha
->ctx_mempool
);
2822 /* Get memory for cached NVRAM */
2823 ha
->nvram
= kzalloc(MAX_NVRAM_SIZE
, GFP_KERNEL
);
2825 goto fail_free_ctx_mempool
;
2827 snprintf(name
, sizeof(name
), "%s_%d", QLA2XXX_DRIVER_NAME
,
2829 ha
->s_dma_pool
= dma_pool_create(name
, &ha
->pdev
->dev
,
2830 DMA_POOL_SIZE
, 8, 0);
2831 if (!ha
->s_dma_pool
)
2832 goto fail_free_nvram
;
2834 ql_dbg_pci(ql_dbg_init
, ha
->pdev
, 0x0022,
2835 "init_cb=%p gid_list=%p, srb_mempool=%p s_dma_pool=%p.\n",
2836 ha
->init_cb
, ha
->gid_list
, ha
->srb_mempool
, ha
->s_dma_pool
);
2838 if (IS_QLA82XX(ha
) || ql2xenabledif
) {
2839 ha
->dl_dma_pool
= dma_pool_create(name
, &ha
->pdev
->dev
,
2840 DSD_LIST_DMA_POOL_SIZE
, 8, 0);
2841 if (!ha
->dl_dma_pool
) {
2842 ql_log_pci(ql_log_fatal
, ha
->pdev
, 0x0023,
2843 "Failed to allocate memory for dl_dma_pool.\n");
2844 goto fail_s_dma_pool
;
2847 ha
->fcp_cmnd_dma_pool
= dma_pool_create(name
, &ha
->pdev
->dev
,
2848 FCP_CMND_DMA_POOL_SIZE
, 8, 0);
2849 if (!ha
->fcp_cmnd_dma_pool
) {
2850 ql_log_pci(ql_log_fatal
, ha
->pdev
, 0x0024,
2851 "Failed to allocate memory for fcp_cmnd_dma_pool.\n");
2852 goto fail_dl_dma_pool
;
2854 ql_dbg_pci(ql_dbg_init
, ha
->pdev
, 0x0025,
2855 "dl_dma_pool=%p fcp_cmnd_dma_pool=%p.\n",
2856 ha
->dl_dma_pool
, ha
->fcp_cmnd_dma_pool
);
2859 /* Allocate memory for SNS commands */
2860 if (IS_QLA2100(ha
) || IS_QLA2200(ha
)) {
2861 /* Get consistent memory allocated for SNS commands */
2862 ha
->sns_cmd
= dma_alloc_coherent(&ha
->pdev
->dev
,
2863 sizeof(struct sns_cmd_pkt
), &ha
->sns_cmd_dma
, GFP_KERNEL
);
2866 ql_dbg_pci(ql_dbg_init
, ha
->pdev
, 0x0026,
2867 "sns_cmd.\n", ha
->sns_cmd
);
2869 /* Get consistent memory allocated for MS IOCB */
2870 ha
->ms_iocb
= dma_pool_alloc(ha
->s_dma_pool
, GFP_KERNEL
,
2874 /* Get consistent memory allocated for CT SNS commands */
2875 ha
->ct_sns
= dma_alloc_coherent(&ha
->pdev
->dev
,
2876 sizeof(struct ct_sns_pkt
), &ha
->ct_sns_dma
, GFP_KERNEL
);
2878 goto fail_free_ms_iocb
;
2879 ql_dbg_pci(ql_dbg_init
, ha
->pdev
, 0x0027,
2880 "ms_iocb=%p ct_sns=%p.\n",
2881 ha
->ms_iocb
, ha
->ct_sns
);
2884 /* Allocate memory for request ring */
2885 *req
= kzalloc(sizeof(struct req_que
), GFP_KERNEL
);
2887 ql_log_pci(ql_log_fatal
, ha
->pdev
, 0x0028,
2888 "Failed to allocate memory for req.\n");
2891 (*req
)->length
= req_len
;
2892 (*req
)->ring
= dma_alloc_coherent(&ha
->pdev
->dev
,
2893 ((*req
)->length
+ 1) * sizeof(request_t
),
2894 &(*req
)->dma
, GFP_KERNEL
);
2895 if (!(*req
)->ring
) {
2896 ql_log_pci(ql_log_fatal
, ha
->pdev
, 0x0029,
2897 "Failed to allocate memory for req_ring.\n");
2900 /* Allocate memory for response ring */
2901 *rsp
= kzalloc(sizeof(struct rsp_que
), GFP_KERNEL
);
2903 ql_log_pci(ql_log_fatal
, ha
->pdev
, 0x002a,
2904 "Failed to allocate memory for rsp.\n");
2908 (*rsp
)->length
= rsp_len
;
2909 (*rsp
)->ring
= dma_alloc_coherent(&ha
->pdev
->dev
,
2910 ((*rsp
)->length
+ 1) * sizeof(response_t
),
2911 &(*rsp
)->dma
, GFP_KERNEL
);
2912 if (!(*rsp
)->ring
) {
2913 ql_log_pci(ql_log_fatal
, ha
->pdev
, 0x002b,
2914 "Failed to allocate memory for rsp_ring.\n");
2919 ql_dbg_pci(ql_dbg_init
, ha
->pdev
, 0x002c,
2920 "req=%p req->length=%d req->ring=%p rsp=%p "
2921 "rsp->length=%d rsp->ring=%p.\n",
2922 *req
, (*req
)->length
, (*req
)->ring
, *rsp
, (*rsp
)->length
,
2924 /* Allocate memory for NVRAM data for vports */
2925 if (ha
->nvram_npiv_size
) {
2926 ha
->npiv_info
= kzalloc(sizeof(struct qla_npiv_entry
) *
2927 ha
->nvram_npiv_size
, GFP_KERNEL
);
2928 if (!ha
->npiv_info
) {
2929 ql_log_pci(ql_log_fatal
, ha
->pdev
, 0x002d,
2930 "Failed to allocate memory for npiv_info.\n");
2931 goto fail_npiv_info
;
2934 ha
->npiv_info
= NULL
;
2936 /* Get consistent memory allocated for EX-INIT-CB. */
2937 if (IS_QLA8XXX_TYPE(ha
)) {
2938 ha
->ex_init_cb
= dma_pool_alloc(ha
->s_dma_pool
, GFP_KERNEL
,
2939 &ha
->ex_init_cb_dma
);
2940 if (!ha
->ex_init_cb
)
2941 goto fail_ex_init_cb
;
2942 ql_dbg_pci(ql_dbg_init
, ha
->pdev
, 0x002e,
2943 "ex_init_cb=%p.\n", ha
->ex_init_cb
);
2946 INIT_LIST_HEAD(&ha
->gbl_dsd_list
);
2948 /* Get consistent memory allocated for Async Port-Database. */
2949 if (!IS_FWI2_CAPABLE(ha
)) {
2950 ha
->async_pd
= dma_pool_alloc(ha
->s_dma_pool
, GFP_KERNEL
,
2954 ql_dbg_pci(ql_dbg_init
, ha
->pdev
, 0x002f,
2955 "async_pd=%p.\n", ha
->async_pd
);
2958 INIT_LIST_HEAD(&ha
->vp_list
);
2962 dma_pool_free(ha
->s_dma_pool
, ha
->ex_init_cb
, ha
->ex_init_cb_dma
);
2964 kfree(ha
->npiv_info
);
2966 dma_free_coherent(&ha
->pdev
->dev
, ((*rsp
)->length
+ 1) *
2967 sizeof(response_t
), (*rsp
)->ring
, (*rsp
)->dma
);
2968 (*rsp
)->ring
= NULL
;
2973 dma_free_coherent(&ha
->pdev
->dev
, ((*req
)->length
+ 1) *
2974 sizeof(request_t
), (*req
)->ring
, (*req
)->dma
);
2975 (*req
)->ring
= NULL
;
2980 dma_free_coherent(&ha
->pdev
->dev
, sizeof(struct ct_sns_pkt
),
2981 ha
->ct_sns
, ha
->ct_sns_dma
);
2985 dma_pool_free(ha
->s_dma_pool
, ha
->ms_iocb
, ha
->ms_iocb_dma
);
2987 ha
->ms_iocb_dma
= 0;
2989 if (IS_QLA82XX(ha
) || ql2xenabledif
) {
2990 dma_pool_destroy(ha
->fcp_cmnd_dma_pool
);
2991 ha
->fcp_cmnd_dma_pool
= NULL
;
2994 if (IS_QLA82XX(ha
) || ql2xenabledif
) {
2995 dma_pool_destroy(ha
->dl_dma_pool
);
2996 ha
->dl_dma_pool
= NULL
;
2999 dma_pool_destroy(ha
->s_dma_pool
);
3000 ha
->s_dma_pool
= NULL
;
3004 fail_free_ctx_mempool
:
3005 mempool_destroy(ha
->ctx_mempool
);
3006 ha
->ctx_mempool
= NULL
;
3007 fail_free_srb_mempool
:
3008 mempool_destroy(ha
->srb_mempool
);
3009 ha
->srb_mempool
= NULL
;
3011 dma_free_coherent(&ha
->pdev
->dev
, GID_LIST_SIZE
, ha
->gid_list
,
3013 ha
->gid_list
= NULL
;
3014 ha
->gid_list_dma
= 0;
3016 dma_free_coherent(&ha
->pdev
->dev
, ha
->init_cb_size
, ha
->init_cb
,
3019 ha
->init_cb_dma
= 0;
3021 ql_log(ql_log_fatal
, NULL
, 0x0030,
3022 "Memory allocation failure.\n");
3027 * qla2x00_free_fw_dump
3028 * Frees fw dump stuff.
3031 * ha = adapter block pointer.
3034 qla2x00_free_fw_dump(struct qla_hw_data
*ha
)
3037 dma_free_coherent(&ha
->pdev
->dev
, FCE_SIZE
, ha
->fce
,
3042 dma_free_coherent(&ha
->pdev
->dev
,
3043 ntohl(ha
->fw_dump
->eft_size
), ha
->eft
, ha
->eft_dma
);
3052 ha
->fw_dump_reading
= 0;
3057 * Frees all adapter allocated memory.
3060 * ha = adapter block pointer.
3063 qla2x00_mem_free(struct qla_hw_data
*ha
)
3065 qla2x00_free_fw_dump(ha
);
3067 if (ha
->srb_mempool
)
3068 mempool_destroy(ha
->srb_mempool
);
3071 dma_free_coherent(&ha
->pdev
->dev
, DCBX_TLV_DATA_SIZE
,
3072 ha
->dcbx_tlv
, ha
->dcbx_tlv_dma
);
3075 dma_free_coherent(&ha
->pdev
->dev
, XGMAC_DATA_SIZE
,
3076 ha
->xgmac_data
, ha
->xgmac_data_dma
);
3079 dma_free_coherent(&ha
->pdev
->dev
, sizeof(struct sns_cmd_pkt
),
3080 ha
->sns_cmd
, ha
->sns_cmd_dma
);
3083 dma_free_coherent(&ha
->pdev
->dev
, sizeof(struct ct_sns_pkt
),
3084 ha
->ct_sns
, ha
->ct_sns_dma
);
3087 dma_pool_free(ha
->s_dma_pool
, ha
->sfp_data
, ha
->sfp_data_dma
);
3090 dma_pool_free(ha
->s_dma_pool
, ha
->edc_data
, ha
->edc_data_dma
);
3093 dma_pool_free(ha
->s_dma_pool
, ha
->ms_iocb
, ha
->ms_iocb_dma
);
3096 dma_pool_free(ha
->s_dma_pool
,
3097 ha
->ex_init_cb
, ha
->ex_init_cb_dma
);
3100 dma_pool_free(ha
->s_dma_pool
, ha
->async_pd
, ha
->async_pd_dma
);
3103 dma_pool_destroy(ha
->s_dma_pool
);
3106 dma_free_coherent(&ha
->pdev
->dev
, GID_LIST_SIZE
, ha
->gid_list
,
3109 if (IS_QLA82XX(ha
)) {
3110 if (!list_empty(&ha
->gbl_dsd_list
)) {
3111 struct dsd_dma
*dsd_ptr
, *tdsd_ptr
;
3113 /* clean up allocated prev pool */
3114 list_for_each_entry_safe(dsd_ptr
,
3115 tdsd_ptr
, &ha
->gbl_dsd_list
, list
) {
3116 dma_pool_free(ha
->dl_dma_pool
,
3117 dsd_ptr
->dsd_addr
, dsd_ptr
->dsd_list_dma
);
3118 list_del(&dsd_ptr
->list
);
3124 if (ha
->dl_dma_pool
)
3125 dma_pool_destroy(ha
->dl_dma_pool
);
3127 if (ha
->fcp_cmnd_dma_pool
)
3128 dma_pool_destroy(ha
->fcp_cmnd_dma_pool
);
3130 if (ha
->ctx_mempool
)
3131 mempool_destroy(ha
->ctx_mempool
);
3134 dma_free_coherent(&ha
->pdev
->dev
, ha
->init_cb_size
,
3135 ha
->init_cb
, ha
->init_cb_dma
);
3136 vfree(ha
->optrom_buffer
);
3138 kfree(ha
->npiv_info
);
3140 ha
->srb_mempool
= NULL
;
3141 ha
->ctx_mempool
= NULL
;
3143 ha
->sns_cmd_dma
= 0;
3147 ha
->ms_iocb_dma
= 0;
3149 ha
->init_cb_dma
= 0;
3150 ha
->ex_init_cb
= NULL
;
3151 ha
->ex_init_cb_dma
= 0;
3152 ha
->async_pd
= NULL
;
3153 ha
->async_pd_dma
= 0;
3155 ha
->s_dma_pool
= NULL
;
3156 ha
->dl_dma_pool
= NULL
;
3157 ha
->fcp_cmnd_dma_pool
= NULL
;
3159 ha
->gid_list
= NULL
;
3160 ha
->gid_list_dma
= 0;
3163 struct scsi_qla_host
*qla2x00_create_host(struct scsi_host_template
*sht
,
3164 struct qla_hw_data
*ha
)
3166 struct Scsi_Host
*host
;
3167 struct scsi_qla_host
*vha
= NULL
;
3169 host
= scsi_host_alloc(sht
, sizeof(scsi_qla_host_t
));
3171 ql_log_pci(ql_log_fatal
, ha
->pdev
, 0x0107,
3172 "Failed to allocate host from the scsi layer, aborting.\n");
3176 /* Clear our data area */
3177 vha
= shost_priv(host
);
3178 memset(vha
, 0, sizeof(scsi_qla_host_t
));
3181 vha
->host_no
= host
->host_no
;
3184 INIT_LIST_HEAD(&vha
->vp_fcports
);
3185 INIT_LIST_HEAD(&vha
->work_list
);
3186 INIT_LIST_HEAD(&vha
->list
);
3188 spin_lock_init(&vha
->work_lock
);
3190 sprintf(vha
->host_str
, "%s_%ld", QLA2XXX_DRIVER_NAME
, vha
->host_no
);
3191 ql_dbg(ql_dbg_init
, vha
, 0x0041,
3192 "Allocated the host=%p hw=%p vha=%p dev_name=%s",
3193 vha
->host
, vha
->hw
, vha
,
3194 dev_name(&(ha
->pdev
->dev
)));
3202 static struct qla_work_evt
*
3203 qla2x00_alloc_work(struct scsi_qla_host
*vha
, enum qla_work_type type
)
3205 struct qla_work_evt
*e
;
3208 QLA_VHA_MARK_BUSY(vha
, bail
);
3212 e
= kzalloc(sizeof(struct qla_work_evt
), GFP_ATOMIC
);
3214 QLA_VHA_MARK_NOT_BUSY(vha
);
3218 INIT_LIST_HEAD(&e
->list
);
3220 e
->flags
= QLA_EVT_FLAG_FREE
;
3225 qla2x00_post_work(struct scsi_qla_host
*vha
, struct qla_work_evt
*e
)
3227 unsigned long flags
;
3229 spin_lock_irqsave(&vha
->work_lock
, flags
);
3230 list_add_tail(&e
->list
, &vha
->work_list
);
3231 spin_unlock_irqrestore(&vha
->work_lock
, flags
);
3232 qla2xxx_wake_dpc(vha
);
3238 qla2x00_post_aen_work(struct scsi_qla_host
*vha
, enum fc_host_event_code code
,
3241 struct qla_work_evt
*e
;
3243 e
= qla2x00_alloc_work(vha
, QLA_EVT_AEN
);
3245 return QLA_FUNCTION_FAILED
;
3247 e
->u
.aen
.code
= code
;
3248 e
->u
.aen
.data
= data
;
3249 return qla2x00_post_work(vha
, e
);
3253 qla2x00_post_idc_ack_work(struct scsi_qla_host
*vha
, uint16_t *mb
)
3255 struct qla_work_evt
*e
;
3257 e
= qla2x00_alloc_work(vha
, QLA_EVT_IDC_ACK
);
3259 return QLA_FUNCTION_FAILED
;
3261 memcpy(e
->u
.idc_ack
.mb
, mb
, QLA_IDC_ACK_REGS
* sizeof(uint16_t));
3262 return qla2x00_post_work(vha
, e
);
3265 #define qla2x00_post_async_work(name, type) \
3266 int qla2x00_post_async_##name##_work( \
3267 struct scsi_qla_host *vha, \
3268 fc_port_t *fcport, uint16_t *data) \
3270 struct qla_work_evt *e; \
3272 e = qla2x00_alloc_work(vha, type); \
3274 return QLA_FUNCTION_FAILED; \
3276 e->u.logio.fcport = fcport; \
3278 e->u.logio.data[0] = data[0]; \
3279 e->u.logio.data[1] = data[1]; \
3281 return qla2x00_post_work(vha, e); \
3284 qla2x00_post_async_work(login
, QLA_EVT_ASYNC_LOGIN
);
3285 qla2x00_post_async_work(login_done
, QLA_EVT_ASYNC_LOGIN_DONE
);
3286 qla2x00_post_async_work(logout
, QLA_EVT_ASYNC_LOGOUT
);
3287 qla2x00_post_async_work(logout_done
, QLA_EVT_ASYNC_LOGOUT_DONE
);
3288 qla2x00_post_async_work(adisc
, QLA_EVT_ASYNC_ADISC
);
3289 qla2x00_post_async_work(adisc_done
, QLA_EVT_ASYNC_ADISC_DONE
);
3292 qla2x00_post_uevent_work(struct scsi_qla_host
*vha
, u32 code
)
3294 struct qla_work_evt
*e
;
3296 e
= qla2x00_alloc_work(vha
, QLA_EVT_UEVENT
);
3298 return QLA_FUNCTION_FAILED
;
3300 e
->u
.uevent
.code
= code
;
3301 return qla2x00_post_work(vha
, e
);
3305 qla2x00_uevent_emit(struct scsi_qla_host
*vha
, u32 code
)
3307 char event_string
[40];
3308 char *envp
[] = { event_string
, NULL
};
3311 case QLA_UEVENT_CODE_FW_DUMP
:
3312 snprintf(event_string
, sizeof(event_string
), "FW_DUMP=%ld",
3319 kobject_uevent_env(&vha
->hw
->pdev
->dev
.kobj
, KOBJ_CHANGE
, envp
);
3323 qla2x00_do_work(struct scsi_qla_host
*vha
)
3325 struct qla_work_evt
*e
, *tmp
;
3326 unsigned long flags
;
3329 spin_lock_irqsave(&vha
->work_lock
, flags
);
3330 list_splice_init(&vha
->work_list
, &work
);
3331 spin_unlock_irqrestore(&vha
->work_lock
, flags
);
3333 list_for_each_entry_safe(e
, tmp
, &work
, list
) {
3334 list_del_init(&e
->list
);
3338 fc_host_post_event(vha
->host
, fc_get_event_number(),
3339 e
->u
.aen
.code
, e
->u
.aen
.data
);
3341 case QLA_EVT_IDC_ACK
:
3342 qla81xx_idc_ack(vha
, e
->u
.idc_ack
.mb
);
3344 case QLA_EVT_ASYNC_LOGIN
:
3345 qla2x00_async_login(vha
, e
->u
.logio
.fcport
,
3348 case QLA_EVT_ASYNC_LOGIN_DONE
:
3349 qla2x00_async_login_done(vha
, e
->u
.logio
.fcport
,
3352 case QLA_EVT_ASYNC_LOGOUT
:
3353 qla2x00_async_logout(vha
, e
->u
.logio
.fcport
);
3355 case QLA_EVT_ASYNC_LOGOUT_DONE
:
3356 qla2x00_async_logout_done(vha
, e
->u
.logio
.fcport
,
3359 case QLA_EVT_ASYNC_ADISC
:
3360 qla2x00_async_adisc(vha
, e
->u
.logio
.fcport
,
3363 case QLA_EVT_ASYNC_ADISC_DONE
:
3364 qla2x00_async_adisc_done(vha
, e
->u
.logio
.fcport
,
3367 case QLA_EVT_UEVENT
:
3368 qla2x00_uevent_emit(vha
, e
->u
.uevent
.code
);
3371 if (e
->flags
& QLA_EVT_FLAG_FREE
)
3374 /* For each work completed decrement vha ref count */
3375 QLA_VHA_MARK_NOT_BUSY(vha
);
3379 /* Relogins all the fcports of a vport
3380 * Context: dpc thread
3382 void qla2x00_relogin(struct scsi_qla_host
*vha
)
3386 uint16_t next_loopid
= 0;
3387 struct qla_hw_data
*ha
= vha
->hw
;
3390 list_for_each_entry(fcport
, &vha
->vp_fcports
, list
) {
3392 * If the port is not ONLINE then try to login
3393 * to it if we haven't run out of retries.
3395 if (atomic_read(&fcport
->state
) != FCS_ONLINE
&&
3396 fcport
->login_retry
&& !(fcport
->flags
& FCF_ASYNC_SENT
)) {
3397 fcport
->login_retry
--;
3398 if (fcport
->flags
& FCF_FABRIC_DEVICE
) {
3399 if (fcport
->flags
& FCF_FCP2_DEVICE
)
3400 ha
->isp_ops
->fabric_logout(vha
,
3402 fcport
->d_id
.b
.domain
,
3403 fcport
->d_id
.b
.area
,
3404 fcport
->d_id
.b
.al_pa
);
3406 if (fcport
->loop_id
== FC_NO_LOOP_ID
) {
3407 fcport
->loop_id
= next_loopid
=
3408 ha
->min_external_loopid
;
3409 status
= qla2x00_find_new_loop_id(
3411 if (status
!= QLA_SUCCESS
) {
3412 /* Ran out of IDs to use */
3417 if (IS_ALOGIO_CAPABLE(ha
)) {
3418 fcport
->flags
|= FCF_ASYNC_SENT
;
3420 data
[1] = QLA_LOGIO_LOGIN_RETRIED
;
3421 status
= qla2x00_post_async_login_work(
3423 if (status
== QLA_SUCCESS
)
3425 /* Attempt a retry. */
3428 status
= qla2x00_fabric_login(vha
,
3429 fcport
, &next_loopid
);
3431 status
= qla2x00_local_device_login(vha
,
3434 if (status
== QLA_SUCCESS
) {
3435 fcport
->old_loop_id
= fcport
->loop_id
;
3437 ql_dbg(ql_dbg_disc
, vha
, 0x2003,
3438 "Port login OK: logged in ID 0x%x.\n",
3441 qla2x00_update_fcport(vha
, fcport
);
3443 } else if (status
== 1) {
3444 set_bit(RELOGIN_NEEDED
, &vha
->dpc_flags
);
3445 /* retry the login again */
3446 ql_dbg(ql_dbg_disc
, vha
, 0x2007,
3447 "Retrying %d login again loop_id 0x%x.\n",
3448 fcport
->login_retry
, fcport
->loop_id
);
3450 fcport
->login_retry
= 0;
3453 if (fcport
->login_retry
== 0 && status
!= QLA_SUCCESS
)
3454 fcport
->loop_id
= FC_NO_LOOP_ID
;
3456 if (test_bit(LOOP_RESYNC_NEEDED
, &vha
->dpc_flags
))
3461 /**************************************************************************
3463 * This kernel thread is a task that is schedule by the interrupt handler
3464 * to perform the background processing for interrupts.
3467 * This task always run in the context of a kernel thread. It
3468 * is kick-off by the driver's detect code and starts up
3469 * up one per adapter. It immediately goes to sleep and waits for
3470 * some fibre event. When either the interrupt handler or
3471 * the timer routine detects a event it will one of the task
3472 * bits then wake us up.
3473 **************************************************************************/
3475 qla2x00_do_dpc(void *data
)
3478 scsi_qla_host_t
*base_vha
;
3479 struct qla_hw_data
*ha
;
3481 ha
= (struct qla_hw_data
*)data
;
3482 base_vha
= pci_get_drvdata(ha
->pdev
);
3484 set_user_nice(current
, -20);
3486 set_current_state(TASK_INTERRUPTIBLE
);
3487 while (!kthread_should_stop()) {
3488 ql_dbg(ql_dbg_dpc
, base_vha
, 0x4000,
3489 "DPC handler sleeping.\n");
3492 __set_current_state(TASK_RUNNING
);
3494 ql_dbg(ql_dbg_dpc
, base_vha
, 0x4001,
3495 "DPC handler waking up.\n");
3496 ql_dbg(ql_dbg_dpc
, base_vha
, 0x4002,
3497 "dpc_flags=0x%lx.\n", base_vha
->dpc_flags
);
3499 /* Initialization not yet finished. Don't do anything yet. */
3500 if (!base_vha
->flags
.init_done
)
3503 if (ha
->flags
.eeh_busy
) {
3504 ql_dbg(ql_dbg_dpc
, base_vha
, 0x4003,
3505 "eeh_busy=%d.\n", ha
->flags
.eeh_busy
);
3511 if (ha
->flags
.mbox_busy
) {
3516 qla2x00_do_work(base_vha
);
3518 if (IS_QLA82XX(ha
)) {
3519 if (test_and_clear_bit(ISP_UNRECOVERABLE
,
3520 &base_vha
->dpc_flags
)) {
3521 qla82xx_idc_lock(ha
);
3522 qla82xx_wr_32(ha
, QLA82XX_CRB_DEV_STATE
,
3523 QLA82XX_DEV_FAILED
);
3524 qla82xx_idc_unlock(ha
);
3525 ql_log(ql_log_info
, base_vha
, 0x4004,
3526 "HW State: FAILED.\n");
3527 qla82xx_device_state_handler(base_vha
);
3531 if (test_and_clear_bit(FCOE_CTX_RESET_NEEDED
,
3532 &base_vha
->dpc_flags
)) {
3534 ql_dbg(ql_dbg_dpc
, base_vha
, 0x4005,
3535 "FCoE context reset scheduled.\n");
3536 if (!(test_and_set_bit(ABORT_ISP_ACTIVE
,
3537 &base_vha
->dpc_flags
))) {
3538 if (qla82xx_fcoe_ctx_reset(base_vha
)) {
3539 /* FCoE-ctx reset failed.
3540 * Escalate to chip-reset
3542 set_bit(ISP_ABORT_NEEDED
,
3543 &base_vha
->dpc_flags
);
3545 clear_bit(ABORT_ISP_ACTIVE
,
3546 &base_vha
->dpc_flags
);
3549 ql_dbg(ql_dbg_dpc
, base_vha
, 0x4006,
3550 "FCoE context reset end.\n");
3554 if (test_and_clear_bit(ISP_ABORT_NEEDED
,
3555 &base_vha
->dpc_flags
)) {
3557 ql_dbg(ql_dbg_dpc
, base_vha
, 0x4007,
3558 "ISP abort scheduled.\n");
3559 if (!(test_and_set_bit(ABORT_ISP_ACTIVE
,
3560 &base_vha
->dpc_flags
))) {
3562 if (ha
->isp_ops
->abort_isp(base_vha
)) {
3563 /* failed. retry later */
3564 set_bit(ISP_ABORT_NEEDED
,
3565 &base_vha
->dpc_flags
);
3567 clear_bit(ABORT_ISP_ACTIVE
,
3568 &base_vha
->dpc_flags
);
3571 ql_dbg(ql_dbg_dpc
, base_vha
, 0x4008,
3572 "ISP abort end.\n");
3575 if (test_bit(FCPORT_UPDATE_NEEDED
, &base_vha
->dpc_flags
)) {
3576 qla2x00_update_fcports(base_vha
);
3577 clear_bit(FCPORT_UPDATE_NEEDED
, &base_vha
->dpc_flags
);
3580 if (test_bit(ISP_QUIESCE_NEEDED
, &base_vha
->dpc_flags
)) {
3581 ql_dbg(ql_dbg_dpc
, base_vha
, 0x4009,
3582 "Quiescence mode scheduled.\n");
3583 qla82xx_device_state_handler(base_vha
);
3584 clear_bit(ISP_QUIESCE_NEEDED
, &base_vha
->dpc_flags
);
3585 if (!ha
->flags
.quiesce_owner
) {
3586 qla2x00_perform_loop_resync(base_vha
);
3588 qla82xx_idc_lock(ha
);
3589 qla82xx_clear_qsnt_ready(base_vha
);
3590 qla82xx_idc_unlock(ha
);
3592 ql_dbg(ql_dbg_dpc
, base_vha
, 0x400a,
3593 "Quiescence mode end.\n");
3596 if (test_and_clear_bit(RESET_MARKER_NEEDED
,
3597 &base_vha
->dpc_flags
) &&
3598 (!(test_and_set_bit(RESET_ACTIVE
, &base_vha
->dpc_flags
)))) {
3600 ql_dbg(ql_dbg_dpc
, base_vha
, 0x400b,
3601 "Reset marker scheduled.\n");
3602 qla2x00_rst_aen(base_vha
);
3603 clear_bit(RESET_ACTIVE
, &base_vha
->dpc_flags
);
3604 ql_dbg(ql_dbg_dpc
, base_vha
, 0x400c,
3605 "Reset marker end.\n");
3608 /* Retry each device up to login retry count */
3609 if ((test_and_clear_bit(RELOGIN_NEEDED
,
3610 &base_vha
->dpc_flags
)) &&
3611 !test_bit(LOOP_RESYNC_NEEDED
, &base_vha
->dpc_flags
) &&
3612 atomic_read(&base_vha
->loop_state
) != LOOP_DOWN
) {
3614 ql_dbg(ql_dbg_dpc
, base_vha
, 0x400d,
3615 "Relogin scheduled.\n");
3616 qla2x00_relogin(base_vha
);
3617 ql_dbg(ql_dbg_dpc
, base_vha
, 0x400e,
3621 if (test_and_clear_bit(LOOP_RESYNC_NEEDED
,
3622 &base_vha
->dpc_flags
)) {
3624 ql_dbg(ql_dbg_dpc
, base_vha
, 0x400f,
3625 "Loop resync scheduled.\n");
3627 if (!(test_and_set_bit(LOOP_RESYNC_ACTIVE
,
3628 &base_vha
->dpc_flags
))) {
3630 rval
= qla2x00_loop_resync(base_vha
);
3632 clear_bit(LOOP_RESYNC_ACTIVE
,
3633 &base_vha
->dpc_flags
);
3636 ql_dbg(ql_dbg_dpc
, base_vha
, 0x4010,
3637 "Loop resync end.\n");
3640 if (test_bit(NPIV_CONFIG_NEEDED
, &base_vha
->dpc_flags
) &&
3641 atomic_read(&base_vha
->loop_state
) == LOOP_READY
) {
3642 clear_bit(NPIV_CONFIG_NEEDED
, &base_vha
->dpc_flags
);
3643 qla2xxx_flash_npiv_conf(base_vha
);
3646 if (!ha
->interrupts_on
)
3647 ha
->isp_ops
->enable_intrs(ha
);
3649 if (test_and_clear_bit(BEACON_BLINK_NEEDED
,
3650 &base_vha
->dpc_flags
))
3651 ha
->isp_ops
->beacon_blink(base_vha
);
3653 qla2x00_do_dpc_all_vps(base_vha
);
3656 set_current_state(TASK_INTERRUPTIBLE
);
3657 } /* End of while(1) */
3658 __set_current_state(TASK_RUNNING
);
3660 ql_dbg(ql_dbg_dpc
, base_vha
, 0x4011,
3661 "DPC handler exiting.\n");
3664 * Make sure that nobody tries to wake us up again.
3668 /* Cleanup any residual CTX SRBs. */
3669 qla2x00_abort_all_cmds(base_vha
, DID_NO_CONNECT
<< 16);
3675 qla2xxx_wake_dpc(struct scsi_qla_host
*vha
)
3677 struct qla_hw_data
*ha
= vha
->hw
;
3678 struct task_struct
*t
= ha
->dpc_thread
;
3680 if (!test_bit(UNLOADING
, &vha
->dpc_flags
) && t
)
3686 * Processes asynchronous reset.
3689 * ha = adapter block pointer.
3692 qla2x00_rst_aen(scsi_qla_host_t
*vha
)
3694 if (vha
->flags
.online
&& !vha
->flags
.reset_active
&&
3695 !atomic_read(&vha
->loop_down_timer
) &&
3696 !(test_bit(ABORT_ISP_ACTIVE
, &vha
->dpc_flags
))) {
3698 clear_bit(RESET_MARKER_NEEDED
, &vha
->dpc_flags
);
3701 * Issue marker command only when we are going to start
3704 vha
->marker_needed
= 1;
3705 } while (!atomic_read(&vha
->loop_down_timer
) &&
3706 (test_bit(RESET_MARKER_NEEDED
, &vha
->dpc_flags
)));
3711 qla2x00_sp_free_dma(srb_t
*sp
)
3713 struct scsi_cmnd
*cmd
= sp
->cmd
;
3714 struct qla_hw_data
*ha
= sp
->fcport
->vha
->hw
;
3716 if (sp
->flags
& SRB_DMA_VALID
) {
3717 scsi_dma_unmap(cmd
);
3718 sp
->flags
&= ~SRB_DMA_VALID
;
3721 if (sp
->flags
& SRB_CRC_PROT_DMA_VALID
) {
3722 dma_unmap_sg(&ha
->pdev
->dev
, scsi_prot_sglist(cmd
),
3723 scsi_prot_sg_count(cmd
), cmd
->sc_data_direction
);
3724 sp
->flags
&= ~SRB_CRC_PROT_DMA_VALID
;
3727 if (sp
->flags
& SRB_CRC_CTX_DSD_VALID
) {
3728 /* List assured to be having elements */
3729 qla2x00_clean_dsd_pool(ha
, sp
);
3730 sp
->flags
&= ~SRB_CRC_CTX_DSD_VALID
;
3733 if (sp
->flags
& SRB_CRC_CTX_DMA_VALID
) {
3734 dma_pool_free(ha
->dl_dma_pool
, sp
->ctx
,
3735 ((struct crc_context
*)sp
->ctx
)->crc_ctx_dma
);
3736 sp
->flags
&= ~SRB_CRC_CTX_DMA_VALID
;
3743 qla2x00_sp_final_compl(struct qla_hw_data
*ha
, srb_t
*sp
)
3745 struct scsi_cmnd
*cmd
= sp
->cmd
;
3747 qla2x00_sp_free_dma(sp
);
3749 if (sp
->flags
& SRB_FCP_CMND_DMA_VALID
) {
3750 struct ct6_dsd
*ctx
= sp
->ctx
;
3751 dma_pool_free(ha
->fcp_cmnd_dma_pool
, ctx
->fcp_cmnd
,
3753 list_splice(&ctx
->dsd_list
, &ha
->gbl_dsd_list
);
3754 ha
->gbl_dsd_inuse
-= ctx
->dsd_use_cnt
;
3755 ha
->gbl_dsd_avail
+= ctx
->dsd_use_cnt
;
3756 mempool_free(sp
->ctx
, ha
->ctx_mempool
);
3760 mempool_free(sp
, ha
->srb_mempool
);
3761 cmd
->scsi_done(cmd
);
3765 qla2x00_sp_compl(struct qla_hw_data
*ha
, srb_t
*sp
)
3767 if (atomic_read(&sp
->ref_count
) == 0) {
3768 ql_dbg(ql_dbg_io
, sp
->fcport
->vha
, 0x3015,
3769 "SP reference-count to ZERO -- sp=%p cmd=%p.\n",
3771 if (ql2xextended_error_logging
& ql_dbg_io
)
3775 if (!atomic_dec_and_test(&sp
->ref_count
))
3777 qla2x00_sp_final_compl(ha
, sp
);
3780 /**************************************************************************
3786 * Context: Interrupt
3787 ***************************************************************************/
3789 qla2x00_timer(scsi_qla_host_t
*vha
)
3791 unsigned long cpu_flags
= 0;
3796 struct qla_hw_data
*ha
= vha
->hw
;
3797 struct req_que
*req
;
3799 if (ha
->flags
.eeh_busy
) {
3800 ql_dbg(ql_dbg_timer
, vha
, 0x6000,
3801 "EEH = %d, restarting timer.\n",
3802 ha
->flags
.eeh_busy
);
3803 qla2x00_restart_timer(vha
, WATCH_INTERVAL
);
3807 /* Hardware read to raise pending EEH errors during mailbox waits. */
3808 if (!pci_channel_offline(ha
->pdev
))
3809 pci_read_config_word(ha
->pdev
, PCI_VENDOR_ID
, &w
);
3811 /* Make sure qla82xx_watchdog is run only for physical port */
3812 if (!vha
->vp_idx
&& IS_QLA82XX(ha
)) {
3813 if (test_bit(ISP_QUIESCE_NEEDED
, &vha
->dpc_flags
))
3815 qla82xx_watchdog(vha
);
3818 /* Loop down handler. */
3819 if (atomic_read(&vha
->loop_down_timer
) > 0 &&
3820 !(test_bit(ABORT_ISP_ACTIVE
, &vha
->dpc_flags
)) &&
3821 !(test_bit(FCOE_CTX_RESET_NEEDED
, &vha
->dpc_flags
))
3822 && vha
->flags
.online
) {
3824 if (atomic_read(&vha
->loop_down_timer
) ==
3825 vha
->loop_down_abort_time
) {
3827 ql_log(ql_log_info
, vha
, 0x6008,
3828 "Loop down - aborting the queues before time expires.\n");
3830 if (!IS_QLA2100(ha
) && vha
->link_down_timeout
)
3831 atomic_set(&vha
->loop_state
, LOOP_DEAD
);
3834 * Schedule an ISP abort to return any FCP2-device
3837 /* NPIV - scan physical port only */
3839 spin_lock_irqsave(&ha
->hardware_lock
,
3841 req
= ha
->req_q_map
[0];
3843 index
< MAX_OUTSTANDING_COMMANDS
;
3847 sp
= req
->outstanding_cmds
[index
];
3850 if (sp
->ctx
&& !IS_PROT_IO(sp
))
3853 if (!(sfcp
->flags
& FCF_FCP2_DEVICE
))
3857 set_bit(FCOE_CTX_RESET_NEEDED
,
3860 set_bit(ISP_ABORT_NEEDED
,
3864 spin_unlock_irqrestore(&ha
->hardware_lock
,
3870 /* if the loop has been down for 4 minutes, reinit adapter */
3871 if (atomic_dec_and_test(&vha
->loop_down_timer
) != 0) {
3872 if (!(vha
->device_flags
& DFLG_NO_CABLE
)) {
3873 ql_log(ql_log_warn
, vha
, 0x6009,
3874 "Loop down - aborting ISP.\n");
3877 set_bit(FCOE_CTX_RESET_NEEDED
,
3880 set_bit(ISP_ABORT_NEEDED
,
3884 ql_dbg(ql_dbg_timer
, vha
, 0x600a,
3885 "Loop down - seconds remaining %d.\n",
3886 atomic_read(&vha
->loop_down_timer
));
3889 /* Check if beacon LED needs to be blinked for physical host only */
3890 if (!vha
->vp_idx
&& (ha
->beacon_blink_led
== 1)) {
3891 set_bit(BEACON_BLINK_NEEDED
, &vha
->dpc_flags
);
3895 /* Process any deferred work. */
3896 if (!list_empty(&vha
->work_list
))
3899 /* Schedule the DPC routine if needed */
3900 if ((test_bit(ISP_ABORT_NEEDED
, &vha
->dpc_flags
) ||
3901 test_bit(LOOP_RESYNC_NEEDED
, &vha
->dpc_flags
) ||
3902 test_bit(FCPORT_UPDATE_NEEDED
, &vha
->dpc_flags
) ||
3904 test_bit(RESET_MARKER_NEEDED
, &vha
->dpc_flags
) ||
3905 test_bit(BEACON_BLINK_NEEDED
, &vha
->dpc_flags
) ||
3906 test_bit(ISP_UNRECOVERABLE
, &vha
->dpc_flags
) ||
3907 test_bit(FCOE_CTX_RESET_NEEDED
, &vha
->dpc_flags
) ||
3908 test_bit(VP_DPC_NEEDED
, &vha
->dpc_flags
) ||
3909 test_bit(RELOGIN_NEEDED
, &vha
->dpc_flags
))) {
3910 ql_dbg(ql_dbg_timer
, vha
, 0x600b,
3911 "isp_abort_needed=%d loop_resync_needed=%d "
3912 "fcport_update_needed=%d start_dpc=%d "
3913 "reset_marker_needed=%d",
3914 test_bit(ISP_ABORT_NEEDED
, &vha
->dpc_flags
),
3915 test_bit(LOOP_RESYNC_NEEDED
, &vha
->dpc_flags
),
3916 test_bit(FCPORT_UPDATE_NEEDED
, &vha
->dpc_flags
),
3918 test_bit(RESET_MARKER_NEEDED
, &vha
->dpc_flags
));
3919 ql_dbg(ql_dbg_timer
, vha
, 0x600c,
3920 "beacon_blink_needed=%d isp_unrecoverable=%d "
3921 "fcoe_ctx_reset_needed=%d vp_dpc_needed=%d "
3922 "relogin_needed=%d.\n",
3923 test_bit(BEACON_BLINK_NEEDED
, &vha
->dpc_flags
),
3924 test_bit(ISP_UNRECOVERABLE
, &vha
->dpc_flags
),
3925 test_bit(FCOE_CTX_RESET_NEEDED
, &vha
->dpc_flags
),
3926 test_bit(VP_DPC_NEEDED
, &vha
->dpc_flags
),
3927 test_bit(RELOGIN_NEEDED
, &vha
->dpc_flags
));
3928 qla2xxx_wake_dpc(vha
);
3931 qla2x00_restart_timer(vha
, WATCH_INTERVAL
);
3934 /* Firmware interface routines. */
3937 #define FW_ISP21XX 0
3938 #define FW_ISP22XX 1
3939 #define FW_ISP2300 2
3940 #define FW_ISP2322 3
3941 #define FW_ISP24XX 4
3942 #define FW_ISP25XX 5
3943 #define FW_ISP81XX 6
3944 #define FW_ISP82XX 7
3946 #define FW_FILE_ISP21XX "ql2100_fw.bin"
3947 #define FW_FILE_ISP22XX "ql2200_fw.bin"
3948 #define FW_FILE_ISP2300 "ql2300_fw.bin"
3949 #define FW_FILE_ISP2322 "ql2322_fw.bin"
3950 #define FW_FILE_ISP24XX "ql2400_fw.bin"
3951 #define FW_FILE_ISP25XX "ql2500_fw.bin"
3952 #define FW_FILE_ISP81XX "ql8100_fw.bin"
3953 #define FW_FILE_ISP82XX "ql8200_fw.bin"
3955 static DEFINE_MUTEX(qla_fw_lock
);
3957 static struct fw_blob qla_fw_blobs
[FW_BLOBS
] = {
3958 { .name
= FW_FILE_ISP21XX
, .segs
= { 0x1000, 0 }, },
3959 { .name
= FW_FILE_ISP22XX
, .segs
= { 0x1000, 0 }, },
3960 { .name
= FW_FILE_ISP2300
, .segs
= { 0x800, 0 }, },
3961 { .name
= FW_FILE_ISP2322
, .segs
= { 0x800, 0x1c000, 0x1e000, 0 }, },
3962 { .name
= FW_FILE_ISP24XX
, },
3963 { .name
= FW_FILE_ISP25XX
, },
3964 { .name
= FW_FILE_ISP81XX
, },
3965 { .name
= FW_FILE_ISP82XX
, },
3969 qla2x00_request_firmware(scsi_qla_host_t
*vha
)
3971 struct qla_hw_data
*ha
= vha
->hw
;
3972 struct fw_blob
*blob
;
3975 if (IS_QLA2100(ha
)) {
3976 blob
= &qla_fw_blobs
[FW_ISP21XX
];
3977 } else if (IS_QLA2200(ha
)) {
3978 blob
= &qla_fw_blobs
[FW_ISP22XX
];
3979 } else if (IS_QLA2300(ha
) || IS_QLA2312(ha
) || IS_QLA6312(ha
)) {
3980 blob
= &qla_fw_blobs
[FW_ISP2300
];
3981 } else if (IS_QLA2322(ha
) || IS_QLA6322(ha
)) {
3982 blob
= &qla_fw_blobs
[FW_ISP2322
];
3983 } else if (IS_QLA24XX_TYPE(ha
)) {
3984 blob
= &qla_fw_blobs
[FW_ISP24XX
];
3985 } else if (IS_QLA25XX(ha
)) {
3986 blob
= &qla_fw_blobs
[FW_ISP25XX
];
3987 } else if (IS_QLA81XX(ha
)) {
3988 blob
= &qla_fw_blobs
[FW_ISP81XX
];
3989 } else if (IS_QLA82XX(ha
)) {
3990 blob
= &qla_fw_blobs
[FW_ISP82XX
];
3993 mutex_lock(&qla_fw_lock
);
3997 if (request_firmware(&blob
->fw
, blob
->name
, &ha
->pdev
->dev
)) {
3998 ql_log(ql_log_warn
, vha
, 0x0063,
3999 "Failed to load firmware image (%s).\n", blob
->name
);
4006 mutex_unlock(&qla_fw_lock
);
4011 qla2x00_release_firmware(void)
4015 mutex_lock(&qla_fw_lock
);
4016 for (idx
= 0; idx
< FW_BLOBS
; idx
++)
4017 if (qla_fw_blobs
[idx
].fw
)
4018 release_firmware(qla_fw_blobs
[idx
].fw
);
4019 mutex_unlock(&qla_fw_lock
);
4022 static pci_ers_result_t
4023 qla2xxx_pci_error_detected(struct pci_dev
*pdev
, pci_channel_state_t state
)
4025 scsi_qla_host_t
*vha
= pci_get_drvdata(pdev
);
4026 struct qla_hw_data
*ha
= vha
->hw
;
4028 ql_dbg(ql_dbg_aer
, vha
, 0x9000,
4029 "PCI error detected, state %x.\n", state
);
4032 case pci_channel_io_normal
:
4033 ha
->flags
.eeh_busy
= 0;
4034 return PCI_ERS_RESULT_CAN_RECOVER
;
4035 case pci_channel_io_frozen
:
4036 ha
->flags
.eeh_busy
= 1;
4037 /* For ISP82XX complete any pending mailbox cmd */
4038 if (IS_QLA82XX(ha
)) {
4039 ha
->flags
.isp82xx_fw_hung
= 1;
4040 if (ha
->flags
.mbox_busy
) {
4041 ha
->flags
.mbox_int
= 1;
4042 ql_dbg(ql_dbg_aer
, vha
, 0x9001,
4043 "Due to pci channel io frozen, doing premature "
4044 "completion of mbx command.\n");
4045 complete(&ha
->mbx_intr_comp
);
4048 qla2x00_free_irqs(vha
);
4049 pci_disable_device(pdev
);
4050 /* Return back all IOs */
4051 qla2x00_abort_all_cmds(vha
, DID_RESET
<< 16);
4052 return PCI_ERS_RESULT_NEED_RESET
;
4053 case pci_channel_io_perm_failure
:
4054 ha
->flags
.pci_channel_io_perm_failure
= 1;
4055 qla2x00_abort_all_cmds(vha
, DID_NO_CONNECT
<< 16);
4056 return PCI_ERS_RESULT_DISCONNECT
;
4058 return PCI_ERS_RESULT_NEED_RESET
;
4061 static pci_ers_result_t
4062 qla2xxx_pci_mmio_enabled(struct pci_dev
*pdev
)
4064 int risc_paused
= 0;
4066 unsigned long flags
;
4067 scsi_qla_host_t
*base_vha
= pci_get_drvdata(pdev
);
4068 struct qla_hw_data
*ha
= base_vha
->hw
;
4069 struct device_reg_2xxx __iomem
*reg
= &ha
->iobase
->isp
;
4070 struct device_reg_24xx __iomem
*reg24
= &ha
->iobase
->isp24
;
4073 return PCI_ERS_RESULT_RECOVERED
;
4075 spin_lock_irqsave(&ha
->hardware_lock
, flags
);
4076 if (IS_QLA2100(ha
) || IS_QLA2200(ha
)){
4077 stat
= RD_REG_DWORD(®
->hccr
);
4078 if (stat
& HCCR_RISC_PAUSE
)
4080 } else if (IS_QLA23XX(ha
)) {
4081 stat
= RD_REG_DWORD(®
->u
.isp2300
.host_status
);
4082 if (stat
& HSR_RISC_PAUSED
)
4084 } else if (IS_FWI2_CAPABLE(ha
)) {
4085 stat
= RD_REG_DWORD(®24
->host_status
);
4086 if (stat
& HSRX_RISC_PAUSED
)
4089 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
4092 ql_log(ql_log_info
, base_vha
, 0x9003,
4093 "RISC paused -- mmio_enabled, Dumping firmware.\n");
4094 ha
->isp_ops
->fw_dump(base_vha
, 0);
4096 return PCI_ERS_RESULT_NEED_RESET
;
4098 return PCI_ERS_RESULT_RECOVERED
;
4101 uint32_t qla82xx_error_recovery(scsi_qla_host_t
*base_vha
)
4103 uint32_t rval
= QLA_FUNCTION_FAILED
;
4104 uint32_t drv_active
= 0;
4105 struct qla_hw_data
*ha
= base_vha
->hw
;
4107 struct pci_dev
*other_pdev
= NULL
;
4109 ql_dbg(ql_dbg_aer
, base_vha
, 0x9006,
4110 "Entered %s.\n", __func__
);
4112 set_bit(ABORT_ISP_ACTIVE
, &base_vha
->dpc_flags
);
4114 if (base_vha
->flags
.online
) {
4115 /* Abort all outstanding commands,
4116 * so as to be requeued later */
4117 qla2x00_abort_isp_cleanup(base_vha
);
4121 fn
= PCI_FUNC(ha
->pdev
->devfn
);
4124 ql_dbg(ql_dbg_aer
, base_vha
, 0x9007,
4125 "Finding pci device at function = 0x%x.\n", fn
);
4127 pci_get_domain_bus_and_slot(pci_domain_nr(ha
->pdev
->bus
),
4128 ha
->pdev
->bus
->number
, PCI_DEVFN(PCI_SLOT(ha
->pdev
->devfn
),
4133 if (atomic_read(&other_pdev
->enable_cnt
)) {
4134 ql_dbg(ql_dbg_aer
, base_vha
, 0x9008,
4135 "Found PCI func available and enable at 0x%x.\n",
4137 pci_dev_put(other_pdev
);
4140 pci_dev_put(other_pdev
);
4145 ql_dbg(ql_dbg_aer
, base_vha
, 0x9009,
4146 "This devfn is reset owner = 0x%x.\n",
4148 qla82xx_idc_lock(ha
);
4150 qla82xx_wr_32(ha
, QLA82XX_CRB_DEV_STATE
,
4151 QLA82XX_DEV_INITIALIZING
);
4153 qla82xx_wr_32(ha
, QLA82XX_CRB_DRV_IDC_VERSION
,
4154 QLA82XX_IDC_VERSION
);
4156 drv_active
= qla82xx_rd_32(ha
, QLA82XX_CRB_DRV_ACTIVE
);
4157 ql_dbg(ql_dbg_aer
, base_vha
, 0x900a,
4158 "drv_active = 0x%x.\n", drv_active
);
4160 qla82xx_idc_unlock(ha
);
4161 /* Reset if device is not already reset
4162 * drv_active would be 0 if a reset has already been done
4165 rval
= qla82xx_start_firmware(base_vha
);
4168 qla82xx_idc_lock(ha
);
4170 if (rval
!= QLA_SUCCESS
) {
4171 ql_log(ql_log_info
, base_vha
, 0x900b,
4172 "HW State: FAILED.\n");
4173 qla82xx_clear_drv_active(ha
);
4174 qla82xx_wr_32(ha
, QLA82XX_CRB_DEV_STATE
,
4175 QLA82XX_DEV_FAILED
);
4177 ql_log(ql_log_info
, base_vha
, 0x900c,
4178 "HW State: READY.\n");
4179 qla82xx_wr_32(ha
, QLA82XX_CRB_DEV_STATE
,
4181 qla82xx_idc_unlock(ha
);
4182 ha
->flags
.isp82xx_fw_hung
= 0;
4183 rval
= qla82xx_restart_isp(base_vha
);
4184 qla82xx_idc_lock(ha
);
4185 /* Clear driver state register */
4186 qla82xx_wr_32(ha
, QLA82XX_CRB_DRV_STATE
, 0);
4187 qla82xx_set_drv_active(base_vha
);
4189 qla82xx_idc_unlock(ha
);
4191 ql_dbg(ql_dbg_aer
, base_vha
, 0x900d,
4192 "This devfn is not reset owner = 0x%x.\n",
4194 if ((qla82xx_rd_32(ha
, QLA82XX_CRB_DEV_STATE
) ==
4195 QLA82XX_DEV_READY
)) {
4196 ha
->flags
.isp82xx_fw_hung
= 0;
4197 rval
= qla82xx_restart_isp(base_vha
);
4198 qla82xx_idc_lock(ha
);
4199 qla82xx_set_drv_active(base_vha
);
4200 qla82xx_idc_unlock(ha
);
4203 clear_bit(ABORT_ISP_ACTIVE
, &base_vha
->dpc_flags
);
4208 static pci_ers_result_t
4209 qla2xxx_pci_slot_reset(struct pci_dev
*pdev
)
4211 pci_ers_result_t ret
= PCI_ERS_RESULT_DISCONNECT
;
4212 scsi_qla_host_t
*base_vha
= pci_get_drvdata(pdev
);
4213 struct qla_hw_data
*ha
= base_vha
->hw
;
4214 struct rsp_que
*rsp
;
4215 int rc
, retries
= 10;
4217 ql_dbg(ql_dbg_aer
, base_vha
, 0x9004,
4220 /* Workaround: qla2xxx driver which access hardware earlier
4221 * needs error state to be pci_channel_io_online.
4222 * Otherwise mailbox command timesout.
4224 pdev
->error_state
= pci_channel_io_normal
;
4226 pci_restore_state(pdev
);
4228 /* pci_restore_state() clears the saved_state flag of the device
4229 * save restored state which resets saved_state flag
4231 pci_save_state(pdev
);
4234 rc
= pci_enable_device_mem(pdev
);
4236 rc
= pci_enable_device(pdev
);
4239 ql_log(ql_log_warn
, base_vha
, 0x9005,
4240 "Can't re-enable PCI device after reset.\n");
4241 goto exit_slot_reset
;
4244 rsp
= ha
->rsp_q_map
[0];
4245 if (qla2x00_request_irqs(ha
, rsp
))
4246 goto exit_slot_reset
;
4248 if (ha
->isp_ops
->pci_config(base_vha
))
4249 goto exit_slot_reset
;
4251 if (IS_QLA82XX(ha
)) {
4252 if (qla82xx_error_recovery(base_vha
) == QLA_SUCCESS
) {
4253 ret
= PCI_ERS_RESULT_RECOVERED
;
4254 goto exit_slot_reset
;
4256 goto exit_slot_reset
;
4259 while (ha
->flags
.mbox_busy
&& retries
--)
4262 set_bit(ABORT_ISP_ACTIVE
, &base_vha
->dpc_flags
);
4263 if (ha
->isp_ops
->abort_isp(base_vha
) == QLA_SUCCESS
)
4264 ret
= PCI_ERS_RESULT_RECOVERED
;
4265 clear_bit(ABORT_ISP_ACTIVE
, &base_vha
->dpc_flags
);
4269 ql_dbg(ql_dbg_aer
, base_vha
, 0x900e,
4270 "slot_reset return %x.\n", ret
);
4276 qla2xxx_pci_resume(struct pci_dev
*pdev
)
4278 scsi_qla_host_t
*base_vha
= pci_get_drvdata(pdev
);
4279 struct qla_hw_data
*ha
= base_vha
->hw
;
4282 ql_dbg(ql_dbg_aer
, base_vha
, 0x900f,
4285 ret
= qla2x00_wait_for_hba_online(base_vha
);
4286 if (ret
!= QLA_SUCCESS
) {
4287 ql_log(ql_log_fatal
, base_vha
, 0x9002,
4288 "The device failed to resume I/O from slot/link_reset.\n");
4291 pci_cleanup_aer_uncorrect_error_status(pdev
);
4293 ha
->flags
.eeh_busy
= 0;
4296 static struct pci_error_handlers qla2xxx_err_handler
= {
4297 .error_detected
= qla2xxx_pci_error_detected
,
4298 .mmio_enabled
= qla2xxx_pci_mmio_enabled
,
4299 .slot_reset
= qla2xxx_pci_slot_reset
,
4300 .resume
= qla2xxx_pci_resume
,
4303 static struct pci_device_id qla2xxx_pci_tbl
[] = {
4304 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC
, PCI_DEVICE_ID_QLOGIC_ISP2100
) },
4305 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC
, PCI_DEVICE_ID_QLOGIC_ISP2200
) },
4306 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC
, PCI_DEVICE_ID_QLOGIC_ISP2300
) },
4307 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC
, PCI_DEVICE_ID_QLOGIC_ISP2312
) },
4308 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC
, PCI_DEVICE_ID_QLOGIC_ISP2322
) },
4309 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC
, PCI_DEVICE_ID_QLOGIC_ISP6312
) },
4310 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC
, PCI_DEVICE_ID_QLOGIC_ISP6322
) },
4311 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC
, PCI_DEVICE_ID_QLOGIC_ISP2422
) },
4312 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC
, PCI_DEVICE_ID_QLOGIC_ISP2432
) },
4313 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC
, PCI_DEVICE_ID_QLOGIC_ISP8432
) },
4314 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC
, PCI_DEVICE_ID_QLOGIC_ISP5422
) },
4315 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC
, PCI_DEVICE_ID_QLOGIC_ISP5432
) },
4316 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC
, PCI_DEVICE_ID_QLOGIC_ISP2532
) },
4317 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC
, PCI_DEVICE_ID_QLOGIC_ISP8001
) },
4318 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC
, PCI_DEVICE_ID_QLOGIC_ISP8021
) },
4321 MODULE_DEVICE_TABLE(pci
, qla2xxx_pci_tbl
);
4323 static struct pci_driver qla2xxx_pci_driver
= {
4324 .name
= QLA2XXX_DRIVER_NAME
,
4326 .owner
= THIS_MODULE
,
4328 .id_table
= qla2xxx_pci_tbl
,
4329 .probe
= qla2x00_probe_one
,
4330 .remove
= qla2x00_remove_one
,
4331 .shutdown
= qla2x00_shutdown
,
4332 .err_handler
= &qla2xxx_err_handler
,
4335 static struct file_operations apidev_fops
= {
4336 .owner
= THIS_MODULE
,
4337 .llseek
= noop_llseek
,
4341 * qla2x00_module_init - Module initialization.
4344 qla2x00_module_init(void)
4348 /* Allocate cache for SRBs. */
4349 srb_cachep
= kmem_cache_create("qla2xxx_srbs", sizeof(srb_t
), 0,
4350 SLAB_HWCACHE_ALIGN
, NULL
);
4351 if (srb_cachep
== NULL
) {
4352 ql_log(ql_log_fatal
, NULL
, 0x0001,
4353 "Unable to allocate SRB cache...Failing load!.\n");
4357 /* Derive version string. */
4358 strcpy(qla2x00_version_str
, QLA2XXX_VERSION
);
4359 if (ql2xextended_error_logging
)
4360 strcat(qla2x00_version_str
, "-debug");
4362 qla2xxx_transport_template
=
4363 fc_attach_transport(&qla2xxx_transport_functions
);
4364 if (!qla2xxx_transport_template
) {
4365 kmem_cache_destroy(srb_cachep
);
4366 ql_log(ql_log_fatal
, NULL
, 0x0002,
4367 "fc_attach_transport failed...Failing load!.\n");
4371 apidev_major
= register_chrdev(0, QLA2XXX_APIDEV
, &apidev_fops
);
4372 if (apidev_major
< 0) {
4373 ql_log(ql_log_fatal
, NULL
, 0x0003,
4374 "Unable to register char device %s.\n", QLA2XXX_APIDEV
);
4377 qla2xxx_transport_vport_template
=
4378 fc_attach_transport(&qla2xxx_transport_vport_functions
);
4379 if (!qla2xxx_transport_vport_template
) {
4380 kmem_cache_destroy(srb_cachep
);
4381 fc_release_transport(qla2xxx_transport_template
);
4382 ql_log(ql_log_fatal
, NULL
, 0x0004,
4383 "fc_attach_transport vport failed...Failing load!.\n");
4386 ql_log(ql_log_info
, NULL
, 0x0005,
4387 "QLogic Fibre Channel HBA Driver: %s.\n",
4388 qla2x00_version_str
);
4389 ret
= pci_register_driver(&qla2xxx_pci_driver
);
4391 kmem_cache_destroy(srb_cachep
);
4392 fc_release_transport(qla2xxx_transport_template
);
4393 fc_release_transport(qla2xxx_transport_vport_template
);
4394 ql_log(ql_log_fatal
, NULL
, 0x0006,
4395 "pci_register_driver failed...ret=%d Failing load!.\n",
4402 * qla2x00_module_exit - Module cleanup.
4405 qla2x00_module_exit(void)
4407 unregister_chrdev(apidev_major
, QLA2XXX_APIDEV
);
4408 pci_unregister_driver(&qla2xxx_pci_driver
);
4409 qla2x00_release_firmware();
4410 kmem_cache_destroy(srb_cachep
);
4412 kmem_cache_destroy(ctx_cachep
);
4413 fc_release_transport(qla2xxx_transport_template
);
4414 fc_release_transport(qla2xxx_transport_vport_template
);
4417 module_init(qla2x00_module_init
);
4418 module_exit(qla2x00_module_exit
);
4420 MODULE_AUTHOR("QLogic Corporation");
4421 MODULE_DESCRIPTION("QLogic Fibre Channel HBA Driver");
4422 MODULE_LICENSE("GPL");
4423 MODULE_VERSION(QLA2XXX_VERSION
);
4424 MODULE_FIRMWARE(FW_FILE_ISP21XX
);
4425 MODULE_FIRMWARE(FW_FILE_ISP22XX
);
4426 MODULE_FIRMWARE(FW_FILE_ISP2300
);
4427 MODULE_FIRMWARE(FW_FILE_ISP2322
);
4428 MODULE_FIRMWARE(FW_FILE_ISP24XX
);
4429 MODULE_FIRMWARE(FW_FILE_ISP25XX
);