2 * QLogic Fibre Channel HBA Driver
3 * Copyright (c) 2003-2010 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 int ql2xlogintimeout
= 20;
40 module_param(ql2xlogintimeout
, int, S_IRUGO
|S_IRUSR
);
41 MODULE_PARM_DESC(ql2xlogintimeout
,
42 "Login timeout value in seconds.");
44 int qlport_down_retry
;
45 module_param(qlport_down_retry
, int, S_IRUGO
|S_IRUSR
);
46 MODULE_PARM_DESC(qlport_down_retry
,
47 "Maximum number of command retries to a port that returns "
48 "a PORT-DOWN status.");
50 int ql2xplogiabsentdevice
;
51 module_param(ql2xplogiabsentdevice
, int, S_IRUGO
|S_IWUSR
);
52 MODULE_PARM_DESC(ql2xplogiabsentdevice
,
53 "Option to enable PLOGI to devices that are not present after "
54 "a Fabric scan. This is needed for several broken switches. "
55 "Default is 0 - no PLOGI. 1 - perfom PLOGI.");
57 int ql2xloginretrycount
= 0;
58 module_param(ql2xloginretrycount
, int, S_IRUGO
|S_IRUSR
);
59 MODULE_PARM_DESC(ql2xloginretrycount
,
60 "Specify an alternate value for the NVRAM login retry count.");
62 int ql2xallocfwdump
= 1;
63 module_param(ql2xallocfwdump
, int, S_IRUGO
|S_IRUSR
);
64 MODULE_PARM_DESC(ql2xallocfwdump
,
65 "Option to enable allocation of memory for a firmware dump "
66 "during HBA initialization. Memory allocation requirements "
67 "vary by ISP type. Default is 1 - allocate memory.");
69 int ql2xextended_error_logging
;
70 module_param(ql2xextended_error_logging
, int, S_IRUGO
|S_IWUSR
);
71 MODULE_PARM_DESC(ql2xextended_error_logging
,
72 "Option to enable extended error logging, "
73 "Default is 0 - no logging. 1 - log errors.");
75 int ql2xshiftctondsd
= 6;
76 module_param(ql2xshiftctondsd
, int, S_IRUGO
|S_IRUSR
);
77 MODULE_PARM_DESC(ql2xshiftctondsd
,
78 "Set to control shifting of command type processing "
79 "based on total number of SG elements.");
81 static void qla2x00_free_device(scsi_qla_host_t
*);
84 module_param(ql2xfdmienable
, int, S_IRUGO
|S_IRUSR
);
85 MODULE_PARM_DESC(ql2xfdmienable
,
86 "Enables FDMI registrations. "
87 "0 - no FDMI. Default is 1 - perform FDMI.");
89 #define MAX_Q_DEPTH 32
90 static int ql2xmaxqdepth
= MAX_Q_DEPTH
;
91 module_param(ql2xmaxqdepth
, int, S_IRUGO
|S_IWUSR
);
92 MODULE_PARM_DESC(ql2xmaxqdepth
,
93 "Maximum queue depth to report for target devices.");
95 /* Do not change the value of this after module load */
96 int ql2xenabledif
= 1;
97 module_param(ql2xenabledif
, int, S_IRUGO
|S_IWUSR
);
98 MODULE_PARM_DESC(ql2xenabledif
,
99 " Enable T10-CRC-DIF "
100 " Default is 0 - No DIF Support. 1 - Enable it");
102 int ql2xenablehba_err_chk
;
103 module_param(ql2xenablehba_err_chk
, int, S_IRUGO
|S_IWUSR
);
104 MODULE_PARM_DESC(ql2xenablehba_err_chk
,
105 " Enable T10-CRC-DIF Error isolation by HBA"
106 " Default is 0 - Error isolation disabled, 1 - Enable it");
108 int ql2xiidmaenable
=1;
109 module_param(ql2xiidmaenable
, int, S_IRUGO
|S_IRUSR
);
110 MODULE_PARM_DESC(ql2xiidmaenable
,
111 "Enables iIDMA settings "
112 "Default is 1 - perform iIDMA. 0 - no iIDMA.");
114 int ql2xmaxqueues
= 1;
115 module_param(ql2xmaxqueues
, int, S_IRUGO
|S_IRUSR
);
116 MODULE_PARM_DESC(ql2xmaxqueues
,
117 "Enables MQ settings "
118 "Default is 1 for single queue. Set it to number "
119 "of queues in MQ mode.");
121 int ql2xmultique_tag
;
122 module_param(ql2xmultique_tag
, int, S_IRUGO
|S_IRUSR
);
123 MODULE_PARM_DESC(ql2xmultique_tag
,
124 "Enables CPU affinity settings for the driver "
125 "Default is 0 for no affinity of request and response IO. "
126 "Set it to 1 to turn on the cpu affinity.");
129 module_param(ql2xfwloadbin
, int, S_IRUGO
|S_IRUSR
);
130 MODULE_PARM_DESC(ql2xfwloadbin
,
131 "Option to specify location from which to load ISP firmware:\n"
132 " 2 -- load firmware via the request_firmware() (hotplug)\n"
134 " 1 -- load firmware from flash.\n"
135 " 0 -- use default semantics.\n");
138 module_param(ql2xetsenable
, int, S_IRUGO
|S_IRUSR
);
139 MODULE_PARM_DESC(ql2xetsenable
,
140 "Enables firmware ETS burst."
141 "Default is 0 - skip ETS enablement.");
144 module_param(ql2xdbwr
, int, S_IRUGO
|S_IRUSR
);
145 MODULE_PARM_DESC(ql2xdbwr
,
146 "Option to specify scheme for request queue posting\n"
147 " 0 -- Regular doorbell.\n"
148 " 1 -- CAMRAM doorbell (faster).\n");
150 int ql2xdontresethba
;
151 module_param(ql2xdontresethba
, int, S_IRUGO
|S_IRUSR
);
152 MODULE_PARM_DESC(ql2xdontresethba
,
153 "Option to specify reset behaviour\n"
154 " 0 (Default) -- Reset on failure.\n"
155 " 1 -- Do not reset on failure.\n");
157 int ql2xtargetreset
= 1;
158 module_param(ql2xtargetreset
, int, S_IRUGO
|S_IRUSR
);
159 MODULE_PARM_DESC(ql2xtargetreset
,
160 "Enable target reset."
161 "Default is 1 - use hw defaults.");
164 module_param(ql2xgffidenable
, int, S_IRUGO
|S_IRUSR
);
165 MODULE_PARM_DESC(ql2xgffidenable
,
166 "Enables GFF_ID checks of port type. "
167 "Default is 0 - Do not use GFF_ID information.");
169 int ql2xasynctmfenable
;
170 module_param(ql2xasynctmfenable
, int, S_IRUGO
|S_IRUSR
);
171 MODULE_PARM_DESC(ql2xasynctmfenable
,
172 "Enables issue of TM IOCBs asynchronously via IOCB mechanism"
173 "Default is 0 - Issue TM IOCBs via mailbox mechanism.");
175 * SCSI host template entry points
177 static int qla2xxx_slave_configure(struct scsi_device
* device
);
178 static int qla2xxx_slave_alloc(struct scsi_device
*);
179 static int qla2xxx_scan_finished(struct Scsi_Host
*, unsigned long time
);
180 static void qla2xxx_scan_start(struct Scsi_Host
*);
181 static void qla2xxx_slave_destroy(struct scsi_device
*);
182 static int qla2xxx_queuecommand(struct scsi_cmnd
*cmd
,
183 void (*fn
)(struct scsi_cmnd
*));
184 static int qla2xxx_eh_abort(struct scsi_cmnd
*);
185 static int qla2xxx_eh_device_reset(struct scsi_cmnd
*);
186 static int qla2xxx_eh_target_reset(struct scsi_cmnd
*);
187 static int qla2xxx_eh_bus_reset(struct scsi_cmnd
*);
188 static int qla2xxx_eh_host_reset(struct scsi_cmnd
*);
190 static int qla2x00_change_queue_depth(struct scsi_device
*, int, int);
191 static int qla2x00_change_queue_type(struct scsi_device
*, int);
193 struct scsi_host_template qla2xxx_driver_template
= {
194 .module
= THIS_MODULE
,
195 .name
= QLA2XXX_DRIVER_NAME
,
196 .queuecommand
= qla2xxx_queuecommand
,
198 .eh_abort_handler
= qla2xxx_eh_abort
,
199 .eh_device_reset_handler
= qla2xxx_eh_device_reset
,
200 .eh_target_reset_handler
= qla2xxx_eh_target_reset
,
201 .eh_bus_reset_handler
= qla2xxx_eh_bus_reset
,
202 .eh_host_reset_handler
= qla2xxx_eh_host_reset
,
204 .slave_configure
= qla2xxx_slave_configure
,
206 .slave_alloc
= qla2xxx_slave_alloc
,
207 .slave_destroy
= qla2xxx_slave_destroy
,
208 .scan_finished
= qla2xxx_scan_finished
,
209 .scan_start
= qla2xxx_scan_start
,
210 .change_queue_depth
= qla2x00_change_queue_depth
,
211 .change_queue_type
= qla2x00_change_queue_type
,
214 .use_clustering
= ENABLE_CLUSTERING
,
215 .sg_tablesize
= SG_ALL
,
217 .max_sectors
= 0xFFFF,
218 .shost_attrs
= qla2x00_host_attrs
,
221 static struct scsi_transport_template
*qla2xxx_transport_template
= NULL
;
222 struct scsi_transport_template
*qla2xxx_transport_vport_template
= NULL
;
224 /* TODO Convert to inlines
230 qla2x00_start_timer(scsi_qla_host_t
*vha
, void *func
, unsigned long interval
)
232 init_timer(&vha
->timer
);
233 vha
->timer
.expires
= jiffies
+ interval
* HZ
;
234 vha
->timer
.data
= (unsigned long)vha
;
235 vha
->timer
.function
= (void (*)(unsigned long))func
;
236 add_timer(&vha
->timer
);
237 vha
->timer_active
= 1;
241 qla2x00_restart_timer(scsi_qla_host_t
*vha
, unsigned long interval
)
243 /* Currently used for 82XX only. */
244 if (vha
->device_flags
& DFLG_DEV_FAILED
)
247 mod_timer(&vha
->timer
, jiffies
+ interval
* HZ
);
250 static __inline__
void
251 qla2x00_stop_timer(scsi_qla_host_t
*vha
)
253 del_timer_sync(&vha
->timer
);
254 vha
->timer_active
= 0;
257 static int qla2x00_do_dpc(void *data
);
259 static void qla2x00_rst_aen(scsi_qla_host_t
*);
261 static int qla2x00_mem_alloc(struct qla_hw_data
*, uint16_t, uint16_t,
262 struct req_que
**, struct rsp_que
**);
263 static void qla2x00_mem_free(struct qla_hw_data
*);
264 static void qla2x00_sp_free_dma(srb_t
*);
266 /* -------------------------------------------------------------------------- */
267 static int qla2x00_alloc_queues(struct qla_hw_data
*ha
)
269 ha
->req_q_map
= kzalloc(sizeof(struct req_que
*) * ha
->max_req_queues
,
271 if (!ha
->req_q_map
) {
272 qla_printk(KERN_WARNING
, ha
,
273 "Unable to allocate memory for request queue ptrs\n");
277 ha
->rsp_q_map
= kzalloc(sizeof(struct rsp_que
*) * ha
->max_rsp_queues
,
279 if (!ha
->rsp_q_map
) {
280 qla_printk(KERN_WARNING
, ha
,
281 "Unable to allocate memory for response queue ptrs\n");
284 set_bit(0, ha
->rsp_qid_map
);
285 set_bit(0, ha
->req_qid_map
);
289 kfree(ha
->req_q_map
);
290 ha
->req_q_map
= NULL
;
295 static void qla2x00_free_req_que(struct qla_hw_data
*ha
, struct req_que
*req
)
297 if (req
&& req
->ring
)
298 dma_free_coherent(&ha
->pdev
->dev
,
299 (req
->length
+ 1) * sizeof(request_t
),
300 req
->ring
, req
->dma
);
306 static void qla2x00_free_rsp_que(struct qla_hw_data
*ha
, struct rsp_que
*rsp
)
308 if (rsp
&& rsp
->ring
)
309 dma_free_coherent(&ha
->pdev
->dev
,
310 (rsp
->length
+ 1) * sizeof(response_t
),
311 rsp
->ring
, rsp
->dma
);
317 static void qla2x00_free_queues(struct qla_hw_data
*ha
)
323 for (cnt
= 0; cnt
< ha
->max_req_queues
; cnt
++) {
324 req
= ha
->req_q_map
[cnt
];
325 qla2x00_free_req_que(ha
, req
);
327 kfree(ha
->req_q_map
);
328 ha
->req_q_map
= NULL
;
330 for (cnt
= 0; cnt
< ha
->max_rsp_queues
; cnt
++) {
331 rsp
= ha
->rsp_q_map
[cnt
];
332 qla2x00_free_rsp_que(ha
, rsp
);
334 kfree(ha
->rsp_q_map
);
335 ha
->rsp_q_map
= NULL
;
338 static int qla25xx_setup_mode(struct scsi_qla_host
*vha
)
340 uint16_t options
= 0;
342 struct qla_hw_data
*ha
= vha
->hw
;
344 if (!(ha
->fw_attributes
& BIT_6
)) {
345 qla_printk(KERN_INFO
, ha
,
346 "Firmware is not multi-queue capable\n");
349 if (ql2xmultique_tag
) {
350 /* create a request queue for IO */
352 req
= qla25xx_create_req_que(ha
, options
, 0, 0, -1,
353 QLA_DEFAULT_QUE_QOS
);
355 qla_printk(KERN_WARNING
, ha
,
356 "Can't create request queue\n");
359 ha
->wq
= create_workqueue("qla2xxx_wq");
360 vha
->req
= ha
->req_q_map
[req
];
362 for (ques
= 1; ques
< ha
->max_rsp_queues
; ques
++) {
363 ret
= qla25xx_create_rsp_que(ha
, options
, 0, 0, req
);
365 qla_printk(KERN_WARNING
, ha
,
366 "Response Queue create failed\n");
370 ha
->flags
.cpu_affinity_enabled
= 1;
372 DEBUG2(qla_printk(KERN_INFO
, ha
,
373 "CPU affinity mode enabled, no. of response"
374 " queues:%d, no. of request queues:%d\n",
375 ha
->max_rsp_queues
, ha
->max_req_queues
));
379 qla25xx_delete_queues(vha
);
380 destroy_workqueue(ha
->wq
);
384 kfree(ha
->req_q_map
);
385 kfree(ha
->rsp_q_map
);
386 ha
->max_req_queues
= ha
->max_rsp_queues
= 1;
391 qla2x00_pci_info_str(struct scsi_qla_host
*vha
, char *str
)
393 struct qla_hw_data
*ha
= vha
->hw
;
394 static char *pci_bus_modes
[] = {
395 "33", "66", "100", "133",
400 pci_bus
= (ha
->pci_attr
& (BIT_9
| BIT_10
)) >> 9;
403 strcat(str
, pci_bus_modes
[pci_bus
]);
405 pci_bus
= (ha
->pci_attr
& BIT_8
) >> 8;
407 strcat(str
, pci_bus_modes
[pci_bus
]);
409 strcat(str
, " MHz)");
415 qla24xx_pci_info_str(struct scsi_qla_host
*vha
, char *str
)
417 static char *pci_bus_modes
[] = { "33", "66", "100", "133", };
418 struct qla_hw_data
*ha
= vha
->hw
;
422 pcie_reg
= pci_find_capability(ha
->pdev
, PCI_CAP_ID_EXP
);
425 uint16_t pcie_lstat
, lspeed
, lwidth
;
428 pci_read_config_word(ha
->pdev
, pcie_reg
, &pcie_lstat
);
429 lspeed
= pcie_lstat
& (BIT_0
| BIT_1
| BIT_2
| BIT_3
);
430 lwidth
= (pcie_lstat
&
431 (BIT_4
| BIT_5
| BIT_6
| BIT_7
| BIT_8
| BIT_9
)) >> 4;
433 strcpy(str
, "PCIe (");
435 strcat(str
, "2.5GT/s ");
436 else if (lspeed
== 2)
437 strcat(str
, "5.0GT/s ");
439 strcat(str
, "<unknown> ");
440 snprintf(lwstr
, sizeof(lwstr
), "x%d)", lwidth
);
447 pci_bus
= (ha
->pci_attr
& CSRX_PCIX_BUS_MODE_MASK
) >> 8;
448 if (pci_bus
== 0 || pci_bus
== 8) {
450 strcat(str
, pci_bus_modes
[pci_bus
>> 3]);
454 strcat(str
, "Mode 2");
456 strcat(str
, "Mode 1");
458 strcat(str
, pci_bus_modes
[pci_bus
& ~BIT_2
]);
460 strcat(str
, " MHz)");
466 qla2x00_fw_version_str(struct scsi_qla_host
*vha
, char *str
)
469 struct qla_hw_data
*ha
= vha
->hw
;
471 sprintf(str
, "%d.%02d.%02d ", ha
->fw_major_version
,
472 ha
->fw_minor_version
,
473 ha
->fw_subminor_version
);
475 if (ha
->fw_attributes
& BIT_9
) {
480 switch (ha
->fw_attributes
& 0xFF) {
494 sprintf(un_str
, "(%x)", ha
->fw_attributes
);
498 if (ha
->fw_attributes
& 0x100)
505 qla24xx_fw_version_str(struct scsi_qla_host
*vha
, char *str
)
507 struct qla_hw_data
*ha
= vha
->hw
;
509 sprintf(str
, "%d.%02d.%02d (%x)", ha
->fw_major_version
,
510 ha
->fw_minor_version
, ha
->fw_subminor_version
, ha
->fw_attributes
);
514 static inline srb_t
*
515 qla2x00_get_new_sp(scsi_qla_host_t
*vha
, fc_port_t
*fcport
,
516 struct scsi_cmnd
*cmd
, void (*done
)(struct scsi_cmnd
*))
519 struct qla_hw_data
*ha
= vha
->hw
;
521 sp
= mempool_alloc(ha
->srb_mempool
, GFP_ATOMIC
);
525 atomic_set(&sp
->ref_count
, 1);
529 CMD_SP(cmd
) = (void *)sp
;
530 cmd
->scsi_done
= done
;
537 qla2xxx_queuecommand(struct scsi_cmnd
*cmd
, void (*done
)(struct scsi_cmnd
*))
539 scsi_qla_host_t
*vha
= shost_priv(cmd
->device
->host
);
540 fc_port_t
*fcport
= (struct fc_port
*) cmd
->device
->hostdata
;
541 struct fc_rport
*rport
= starget_to_rport(scsi_target(cmd
->device
));
542 struct qla_hw_data
*ha
= vha
->hw
;
543 struct scsi_qla_host
*base_vha
= pci_get_drvdata(ha
->pdev
);
547 if (ha
->flags
.eeh_busy
) {
548 if (ha
->flags
.pci_channel_io_perm_failure
)
549 cmd
->result
= DID_NO_CONNECT
<< 16;
551 cmd
->result
= DID_REQUEUE
<< 16;
552 goto qc24_fail_command
;
555 rval
= fc_remote_port_chkready(rport
);
558 goto qc24_fail_command
;
561 /* Close window on fcport/rport state-transitioning. */
563 goto qc24_target_busy
;
565 if (!vha
->flags
.difdix_supported
&&
566 scsi_get_prot_op(cmd
) != SCSI_PROT_NORMAL
) {
567 DEBUG2(qla_printk(KERN_ERR
, ha
,
568 "DIF Cap Not Reg, fail DIF capable cmd's:%x\n",
570 cmd
->result
= DID_NO_CONNECT
<< 16;
571 goto qc24_fail_command
;
573 if (atomic_read(&fcport
->state
) != FCS_ONLINE
) {
574 if (atomic_read(&fcport
->state
) == FCS_DEVICE_DEAD
||
575 atomic_read(&base_vha
->loop_state
) == LOOP_DEAD
) {
576 cmd
->result
= DID_NO_CONNECT
<< 16;
577 goto qc24_fail_command
;
579 goto qc24_target_busy
;
582 spin_unlock_irq(vha
->host
->host_lock
);
584 sp
= qla2x00_get_new_sp(base_vha
, fcport
, cmd
, done
);
586 goto qc24_host_busy_lock
;
588 rval
= ha
->isp_ops
->start_scsi(sp
);
589 if (rval
!= QLA_SUCCESS
)
590 goto qc24_host_busy_free_sp
;
592 spin_lock_irq(vha
->host
->host_lock
);
596 qc24_host_busy_free_sp
:
597 qla2x00_sp_free_dma(sp
);
598 mempool_free(sp
, ha
->srb_mempool
);
601 spin_lock_irq(vha
->host
->host_lock
);
602 return SCSI_MLQUEUE_HOST_BUSY
;
605 return SCSI_MLQUEUE_TARGET_BUSY
;
615 * qla2x00_eh_wait_on_command
616 * Waits for the command to be returned by the Firmware for some
620 * cmd = Scsi Command to wait on.
627 qla2x00_eh_wait_on_command(struct scsi_cmnd
*cmd
)
629 #define ABORT_POLLING_PERIOD 1000
630 #define ABORT_WAIT_ITER ((10 * 1000) / (ABORT_POLLING_PERIOD))
631 unsigned long wait_iter
= ABORT_WAIT_ITER
;
632 scsi_qla_host_t
*vha
= shost_priv(cmd
->device
->host
);
633 struct qla_hw_data
*ha
= vha
->hw
;
634 int ret
= QLA_SUCCESS
;
636 if (unlikely(pci_channel_offline(ha
->pdev
)) || ha
->flags
.eeh_busy
) {
637 DEBUG17(qla_printk(KERN_WARNING
, ha
, "return:eh_wait\n"));
641 while (CMD_SP(cmd
) && wait_iter
--) {
642 msleep(ABORT_POLLING_PERIOD
);
645 ret
= QLA_FUNCTION_FAILED
;
651 * qla2x00_wait_for_hba_online
652 * Wait till the HBA is online after going through
653 * <= MAX_RETRIES_OF_ISP_ABORT or
654 * finally HBA is disabled ie marked offline
657 * ha - pointer to host adapter structure
660 * Does context switching-Release SPIN_LOCK
661 * (if any) before calling this routine.
664 * Success (Adapter is online) : 0
665 * Failed (Adapter is offline/disabled) : 1
668 qla2x00_wait_for_hba_online(scsi_qla_host_t
*vha
)
671 unsigned long wait_online
;
672 struct qla_hw_data
*ha
= vha
->hw
;
673 scsi_qla_host_t
*base_vha
= pci_get_drvdata(ha
->pdev
);
675 wait_online
= jiffies
+ (MAX_LOOP_TIMEOUT
* HZ
);
676 while (((test_bit(ISP_ABORT_NEEDED
, &base_vha
->dpc_flags
)) ||
677 test_bit(ABORT_ISP_ACTIVE
, &base_vha
->dpc_flags
) ||
678 test_bit(ISP_ABORT_RETRY
, &base_vha
->dpc_flags
) ||
679 ha
->dpc_active
) && time_before(jiffies
, wait_online
)) {
683 if (base_vha
->flags
.online
)
684 return_status
= QLA_SUCCESS
;
686 return_status
= QLA_FUNCTION_FAILED
;
688 return (return_status
);
692 * qla2x00_wait_for_reset_ready
693 * Wait till the HBA is online after going through
694 * <= MAX_RETRIES_OF_ISP_ABORT or
695 * finally HBA is disabled ie marked offline or flash
696 * operations are in progress.
699 * ha - pointer to host adapter structure
702 * Does context switching-Release SPIN_LOCK
703 * (if any) before calling this routine.
706 * Success (Adapter is online/no flash ops) : 0
707 * Failed (Adapter is offline/disabled/flash ops in progress) : 1
710 qla2x00_wait_for_reset_ready(scsi_qla_host_t
*vha
)
713 unsigned long wait_online
;
714 struct qla_hw_data
*ha
= vha
->hw
;
715 scsi_qla_host_t
*base_vha
= pci_get_drvdata(ha
->pdev
);
717 wait_online
= jiffies
+ (MAX_LOOP_TIMEOUT
* HZ
);
718 while (((test_bit(ISP_ABORT_NEEDED
, &base_vha
->dpc_flags
)) ||
719 test_bit(ABORT_ISP_ACTIVE
, &base_vha
->dpc_flags
) ||
720 test_bit(ISP_ABORT_RETRY
, &base_vha
->dpc_flags
) ||
721 ha
->optrom_state
!= QLA_SWAITING
||
722 ha
->dpc_active
) && time_before(jiffies
, wait_online
))
725 if (base_vha
->flags
.online
&& ha
->optrom_state
== QLA_SWAITING
)
726 return_status
= QLA_SUCCESS
;
728 return_status
= QLA_FUNCTION_FAILED
;
730 DEBUG2(printk("%s return_status=%d\n", __func__
, return_status
));
732 return return_status
;
736 qla2x00_wait_for_chip_reset(scsi_qla_host_t
*vha
)
739 unsigned long wait_reset
;
740 struct qla_hw_data
*ha
= vha
->hw
;
741 scsi_qla_host_t
*base_vha
= pci_get_drvdata(ha
->pdev
);
743 wait_reset
= jiffies
+ (MAX_LOOP_TIMEOUT
* HZ
);
744 while (((test_bit(ISP_ABORT_NEEDED
, &base_vha
->dpc_flags
)) ||
745 test_bit(ABORT_ISP_ACTIVE
, &base_vha
->dpc_flags
) ||
746 test_bit(ISP_ABORT_RETRY
, &base_vha
->dpc_flags
) ||
747 ha
->dpc_active
) && time_before(jiffies
, wait_reset
)) {
751 if (!test_bit(ISP_ABORT_NEEDED
, &base_vha
->dpc_flags
) &&
752 ha
->flags
.chip_reset_done
)
755 if (ha
->flags
.chip_reset_done
)
756 return_status
= QLA_SUCCESS
;
758 return_status
= QLA_FUNCTION_FAILED
;
760 return return_status
;
764 * qla2x00_wait_for_loop_ready
765 * Wait for MAX_LOOP_TIMEOUT(5 min) value for loop
766 * to be in LOOP_READY state.
768 * ha - pointer to host adapter structure
771 * Does context switching-Release SPIN_LOCK
772 * (if any) before calling this routine.
776 * Success (LOOP_READY) : 0
777 * Failed (LOOP_NOT_READY) : 1
780 qla2x00_wait_for_loop_ready(scsi_qla_host_t
*vha
)
782 int return_status
= QLA_SUCCESS
;
783 unsigned long loop_timeout
;
784 struct qla_hw_data
*ha
= vha
->hw
;
785 scsi_qla_host_t
*base_vha
= pci_get_drvdata(ha
->pdev
);
787 /* wait for 5 min at the max for loop to be ready */
788 loop_timeout
= jiffies
+ (MAX_LOOP_TIMEOUT
* HZ
);
790 while ((!atomic_read(&base_vha
->loop_down_timer
) &&
791 atomic_read(&base_vha
->loop_state
) == LOOP_DOWN
) ||
792 atomic_read(&base_vha
->loop_state
) != LOOP_READY
) {
793 if (atomic_read(&base_vha
->loop_state
) == LOOP_DEAD
) {
794 return_status
= QLA_FUNCTION_FAILED
;
798 if (time_after_eq(jiffies
, loop_timeout
)) {
799 return_status
= QLA_FUNCTION_FAILED
;
803 return (return_status
);
807 sp_get(struct srb
*sp
)
809 atomic_inc(&sp
->ref_count
);
812 /**************************************************************************
816 * The abort function will abort the specified command.
819 * cmd = Linux SCSI command packet to be aborted.
822 * Either SUCCESS or FAILED.
825 * Only return FAILED if command not returned by firmware.
826 **************************************************************************/
828 qla2xxx_eh_abort(struct scsi_cmnd
*cmd
)
830 scsi_qla_host_t
*vha
= shost_priv(cmd
->device
->host
);
833 unsigned int id
, lun
;
834 unsigned long serial
;
837 struct qla_hw_data
*ha
= vha
->hw
;
838 struct req_que
*req
= vha
->req
;
842 fc_block_scsi_eh(cmd
);
849 id
= cmd
->device
->id
;
850 lun
= cmd
->device
->lun
;
851 serial
= cmd
->serial_number
;
852 spt
= (srb_t
*) CMD_SP(cmd
);
856 /* Check active list for command command. */
857 spin_lock_irqsave(&ha
->hardware_lock
, flags
);
858 for (i
= 1; i
< MAX_OUTSTANDING_COMMANDS
; i
++) {
859 sp
= req
->outstanding_cmds
[i
];
863 if ((sp
->ctx
) && !(sp
->flags
& SRB_FCP_CMND_DMA_VALID
) &&
869 DEBUG2(printk("%s(%ld): aborting sp %p from RISC."
870 " pid=%ld.\n", __func__
, vha
->host_no
, sp
, serial
));
872 /* Get a reference to the sp and drop the lock.*/
876 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
877 if (ha
->isp_ops
->abort_command(sp
)) {
878 DEBUG2(printk("%s(%ld): abort_command "
879 "mbx failed.\n", __func__
, vha
->host_no
));
882 DEBUG3(printk("%s(%ld): abort_command "
883 "mbx success.\n", __func__
, vha
->host_no
));
886 spin_lock_irqsave(&ha
->hardware_lock
, flags
);
889 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
891 /* Wait for the command to be returned. */
893 if (qla2x00_eh_wait_on_command(cmd
) != QLA_SUCCESS
) {
894 qla_printk(KERN_ERR
, ha
,
895 "scsi(%ld:%d:%d): Abort handler timed out -- %lx "
896 "%x.\n", vha
->host_no
, id
, lun
, serial
, ret
);
902 qla2x00_sp_compl(ha
, sp
);
904 qla_printk(KERN_INFO
, ha
,
905 "scsi(%ld:%d:%d): Abort command issued -- %d %lx %x.\n",
906 vha
->host_no
, id
, lun
, wait
, serial
, ret
);
912 qla2x00_eh_wait_for_pending_commands(scsi_qla_host_t
*vha
, unsigned int t
,
913 unsigned int l
, enum nexus_wait_type type
)
915 int cnt
, match
, status
;
917 struct qla_hw_data
*ha
= vha
->hw
;
921 status
= QLA_SUCCESS
;
923 spin_lock_irqsave(&ha
->hardware_lock
, flags
);
925 for (cnt
= 1; status
== QLA_SUCCESS
&&
926 cnt
< MAX_OUTSTANDING_COMMANDS
; cnt
++) {
927 sp
= req
->outstanding_cmds
[cnt
];
930 if ((sp
->ctx
) && !IS_PROT_IO(sp
))
932 if (vha
->vp_idx
!= sp
->fcport
->vha
->vp_idx
)
940 match
= sp
->cmd
->device
->id
== t
;
943 match
= (sp
->cmd
->device
->id
== t
&&
944 sp
->cmd
->device
->lun
== l
);
950 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
951 status
= qla2x00_eh_wait_on_command(sp
->cmd
);
952 spin_lock_irqsave(&ha
->hardware_lock
, flags
);
954 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
959 static char *reset_errors
[] = {
962 "Task management failed",
963 "Waiting for command completions",
967 __qla2xxx_eh_generic_reset(char *name
, enum nexus_wait_type type
,
968 struct scsi_cmnd
*cmd
, int (*do_reset
)(struct fc_port
*, unsigned int, int))
970 scsi_qla_host_t
*vha
= shost_priv(cmd
->device
->host
);
971 fc_port_t
*fcport
= (struct fc_port
*) cmd
->device
->hostdata
;
974 fc_block_scsi_eh(cmd
);
979 qla_printk(KERN_INFO
, vha
->hw
, "scsi(%ld:%d:%d): %s RESET ISSUED.\n",
980 vha
->host_no
, cmd
->device
->id
, cmd
->device
->lun
, name
);
983 if (qla2x00_wait_for_hba_online(vha
) != QLA_SUCCESS
)
984 goto eh_reset_failed
;
986 if (qla2x00_wait_for_loop_ready(vha
) != QLA_SUCCESS
)
987 goto eh_reset_failed
;
989 if (do_reset(fcport
, cmd
->device
->lun
, cmd
->request
->cpu
+ 1)
991 goto eh_reset_failed
;
993 if (qla2x00_eh_wait_for_pending_commands(vha
, cmd
->device
->id
,
994 cmd
->device
->lun
, type
) != QLA_SUCCESS
)
995 goto eh_reset_failed
;
997 qla_printk(KERN_INFO
, vha
->hw
, "scsi(%ld:%d:%d): %s RESET SUCCEEDED.\n",
998 vha
->host_no
, cmd
->device
->id
, cmd
->device
->lun
, name
);
1003 qla_printk(KERN_INFO
, vha
->hw
, "scsi(%ld:%d:%d): %s RESET FAILED: %s.\n"
1004 , vha
->host_no
, cmd
->device
->id
, cmd
->device
->lun
, name
,
1010 qla2xxx_eh_device_reset(struct scsi_cmnd
*cmd
)
1012 scsi_qla_host_t
*vha
= shost_priv(cmd
->device
->host
);
1013 struct qla_hw_data
*ha
= vha
->hw
;
1015 return __qla2xxx_eh_generic_reset("DEVICE", WAIT_LUN
, cmd
,
1016 ha
->isp_ops
->lun_reset
);
1020 qla2xxx_eh_target_reset(struct scsi_cmnd
*cmd
)
1022 scsi_qla_host_t
*vha
= shost_priv(cmd
->device
->host
);
1023 struct qla_hw_data
*ha
= vha
->hw
;
1025 return __qla2xxx_eh_generic_reset("TARGET", WAIT_TARGET
, cmd
,
1026 ha
->isp_ops
->target_reset
);
1029 /**************************************************************************
1030 * qla2xxx_eh_bus_reset
1033 * The bus reset function will reset the bus and abort any executing
1037 * cmd = Linux SCSI command packet of the command that cause the
1041 * SUCCESS/FAILURE (defined as macro in scsi.h).
1043 **************************************************************************/
1045 qla2xxx_eh_bus_reset(struct scsi_cmnd
*cmd
)
1047 scsi_qla_host_t
*vha
= shost_priv(cmd
->device
->host
);
1048 fc_port_t
*fcport
= (struct fc_port
*) cmd
->device
->hostdata
;
1050 unsigned int id
, lun
;
1051 unsigned long serial
;
1053 fc_block_scsi_eh(cmd
);
1055 id
= cmd
->device
->id
;
1056 lun
= cmd
->device
->lun
;
1057 serial
= cmd
->serial_number
;
1062 qla_printk(KERN_INFO
, vha
->hw
,
1063 "scsi(%ld:%d:%d): BUS RESET ISSUED.\n", vha
->host_no
, id
, lun
);
1065 if (qla2x00_wait_for_hba_online(vha
) != QLA_SUCCESS
) {
1066 DEBUG2(printk("%s failed:board disabled\n",__func__
));
1067 goto eh_bus_reset_done
;
1070 if (qla2x00_wait_for_loop_ready(vha
) == QLA_SUCCESS
) {
1071 if (qla2x00_loop_reset(vha
) == QLA_SUCCESS
)
1075 goto eh_bus_reset_done
;
1077 /* Flush outstanding commands. */
1078 if (qla2x00_eh_wait_for_pending_commands(vha
, 0, 0, WAIT_HOST
) !=
1083 qla_printk(KERN_INFO
, vha
->hw
, "%s: reset %s\n", __func__
,
1084 (ret
== FAILED
) ? "failed" : "succeded");
1089 /**************************************************************************
1090 * qla2xxx_eh_host_reset
1093 * The reset function will reset the Adapter.
1096 * cmd = Linux SCSI command packet of the command that cause the
1100 * Either SUCCESS or FAILED.
1103 **************************************************************************/
1105 qla2xxx_eh_host_reset(struct scsi_cmnd
*cmd
)
1107 scsi_qla_host_t
*vha
= shost_priv(cmd
->device
->host
);
1108 fc_port_t
*fcport
= (struct fc_port
*) cmd
->device
->hostdata
;
1109 struct qla_hw_data
*ha
= vha
->hw
;
1111 unsigned int id
, lun
;
1112 unsigned long serial
;
1113 scsi_qla_host_t
*base_vha
= pci_get_drvdata(ha
->pdev
);
1115 fc_block_scsi_eh(cmd
);
1117 id
= cmd
->device
->id
;
1118 lun
= cmd
->device
->lun
;
1119 serial
= cmd
->serial_number
;
1124 qla_printk(KERN_INFO
, ha
,
1125 "scsi(%ld:%d:%d): ADAPTER RESET ISSUED.\n", vha
->host_no
, id
, lun
);
1127 if (qla2x00_wait_for_reset_ready(vha
) != QLA_SUCCESS
)
1128 goto eh_host_reset_lock
;
1130 qla2x00_wait_for_loop_ready(vha
);
1131 if (vha
!= base_vha
) {
1132 if (qla2x00_vp_abort_isp(vha
))
1133 goto eh_host_reset_lock
;
1135 if (IS_QLA82XX(vha
->hw
)) {
1136 if (!qla82xx_fcoe_ctx_reset(vha
)) {
1137 /* Ctx reset success */
1139 goto eh_host_reset_lock
;
1141 /* fall thru if ctx reset failed */
1144 flush_workqueue(ha
->wq
);
1146 set_bit(ABORT_ISP_ACTIVE
, &base_vha
->dpc_flags
);
1147 if (ha
->isp_ops
->abort_isp(base_vha
)) {
1148 clear_bit(ABORT_ISP_ACTIVE
, &base_vha
->dpc_flags
);
1149 /* failed. schedule dpc to try */
1150 set_bit(ISP_ABORT_NEEDED
, &base_vha
->dpc_flags
);
1152 if (qla2x00_wait_for_hba_online(vha
) != QLA_SUCCESS
)
1153 goto eh_host_reset_lock
;
1155 clear_bit(ABORT_ISP_ACTIVE
, &base_vha
->dpc_flags
);
1158 /* Waiting for command to be returned to OS.*/
1159 if (qla2x00_eh_wait_for_pending_commands(vha
, 0, 0, WAIT_HOST
) ==
1164 qla_printk(KERN_INFO
, ha
, "%s: reset %s\n", __func__
,
1165 (ret
== FAILED
) ? "failed" : "succeded");
1171 * qla2x00_loop_reset
1175 * ha = adapter block pointer.
1181 qla2x00_loop_reset(scsi_qla_host_t
*vha
)
1184 struct fc_port
*fcport
;
1185 struct qla_hw_data
*ha
= vha
->hw
;
1187 if (ql2xtargetreset
== 1 && ha
->flags
.enable_target_reset
) {
1188 list_for_each_entry(fcport
, &vha
->vp_fcports
, list
) {
1189 if (fcport
->port_type
!= FCT_TARGET
)
1192 ret
= ha
->isp_ops
->target_reset(fcport
, 0, 0);
1193 if (ret
!= QLA_SUCCESS
) {
1194 DEBUG2_3(printk("%s(%ld): bus_reset failed: "
1195 "target_reset=%d d_id=%x.\n", __func__
,
1196 vha
->host_no
, ret
, fcport
->d_id
.b24
));
1201 if (ha
->flags
.enable_lip_full_login
&& !IS_QLA8XXX_TYPE(ha
)) {
1202 ret
= qla2x00_full_login_lip(vha
);
1203 if (ret
!= QLA_SUCCESS
) {
1204 DEBUG2_3(printk("%s(%ld): failed: "
1205 "full_login_lip=%d.\n", __func__
, vha
->host_no
,
1208 atomic_set(&vha
->loop_state
, LOOP_DOWN
);
1209 atomic_set(&vha
->loop_down_timer
, LOOP_DOWN_TIME
);
1210 qla2x00_mark_all_devices_lost(vha
, 0);
1211 qla2x00_wait_for_loop_ready(vha
);
1214 if (ha
->flags
.enable_lip_reset
) {
1215 ret
= qla2x00_lip_reset(vha
);
1216 if (ret
!= QLA_SUCCESS
) {
1217 DEBUG2_3(printk("%s(%ld): failed: "
1218 "lip_reset=%d.\n", __func__
, vha
->host_no
, ret
));
1220 qla2x00_wait_for_loop_ready(vha
);
1223 /* Issue marker command only when we are going to start the I/O */
1224 vha
->marker_needed
= 1;
1230 qla2x00_abort_all_cmds(scsi_qla_host_t
*vha
, int res
)
1233 unsigned long flags
;
1235 struct srb_ctx
*ctx
;
1236 struct qla_hw_data
*ha
= vha
->hw
;
1237 struct req_que
*req
;
1239 spin_lock_irqsave(&ha
->hardware_lock
, flags
);
1240 for (que
= 0; que
< ha
->max_req_queues
; que
++) {
1241 req
= ha
->req_q_map
[que
];
1244 for (cnt
= 1; cnt
< MAX_OUTSTANDING_COMMANDS
; cnt
++) {
1245 sp
= req
->outstanding_cmds
[cnt
];
1247 req
->outstanding_cmds
[cnt
] = NULL
;
1249 (sp
->flags
& SRB_FCP_CMND_DMA_VALID
) ||
1251 sp
->cmd
->result
= res
;
1252 qla2x00_sp_compl(ha
, sp
);
1255 if (ctx
->type
== SRB_LOGIN_CMD
||
1256 ctx
->type
== SRB_LOGOUT_CMD
) {
1257 ctx
->u
.iocb_cmd
->free(sp
);
1259 struct fc_bsg_job
*bsg_job
=
1261 if (bsg_job
->request
->msgcode
1264 bsg_job
->req
->errors
= 0;
1265 bsg_job
->reply
->result
= res
;
1266 bsg_job
->job_done(bsg_job
);
1275 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
1279 qla2xxx_slave_alloc(struct scsi_device
*sdev
)
1281 struct fc_rport
*rport
= starget_to_rport(scsi_target(sdev
));
1283 if (!rport
|| fc_remote_port_chkready(rport
))
1286 sdev
->hostdata
= *(fc_port_t
**)rport
->dd_data
;
1292 qla2xxx_slave_configure(struct scsi_device
*sdev
)
1294 scsi_qla_host_t
*vha
= shost_priv(sdev
->host
);
1295 struct qla_hw_data
*ha
= vha
->hw
;
1296 struct fc_rport
*rport
= starget_to_rport(sdev
->sdev_target
);
1297 struct req_que
*req
= vha
->req
;
1299 if (sdev
->tagged_supported
)
1300 scsi_activate_tcq(sdev
, req
->max_q_depth
);
1302 scsi_deactivate_tcq(sdev
, req
->max_q_depth
);
1304 rport
->dev_loss_tmo
= ha
->port_down_retry_count
;
1310 qla2xxx_slave_destroy(struct scsi_device
*sdev
)
1312 sdev
->hostdata
= NULL
;
1315 static void qla2x00_handle_queue_full(struct scsi_device
*sdev
, int qdepth
)
1317 fc_port_t
*fcport
= (struct fc_port
*) sdev
->hostdata
;
1319 if (!scsi_track_queue_full(sdev
, qdepth
))
1322 DEBUG2(qla_printk(KERN_INFO
, fcport
->vha
->hw
,
1323 "scsi(%ld:%d:%d:%d): Queue depth adjusted-down to %d.\n",
1324 fcport
->vha
->host_no
, sdev
->channel
, sdev
->id
, sdev
->lun
,
1325 sdev
->queue_depth
));
1328 static void qla2x00_adjust_sdev_qdepth_up(struct scsi_device
*sdev
, int qdepth
)
1330 fc_port_t
*fcport
= sdev
->hostdata
;
1331 struct scsi_qla_host
*vha
= fcport
->vha
;
1332 struct qla_hw_data
*ha
= vha
->hw
;
1333 struct req_que
*req
= NULL
;
1339 if (req
->max_q_depth
<= sdev
->queue_depth
|| req
->max_q_depth
< qdepth
)
1342 if (sdev
->ordered_tags
)
1343 scsi_adjust_queue_depth(sdev
, MSG_ORDERED_TAG
, qdepth
);
1345 scsi_adjust_queue_depth(sdev
, MSG_SIMPLE_TAG
, qdepth
);
1347 DEBUG2(qla_printk(KERN_INFO
, ha
,
1348 "scsi(%ld:%d:%d:%d): Queue depth adjusted-up to %d.\n",
1349 fcport
->vha
->host_no
, sdev
->channel
, sdev
->id
, sdev
->lun
,
1350 sdev
->queue_depth
));
1354 qla2x00_change_queue_depth(struct scsi_device
*sdev
, int qdepth
, int reason
)
1357 case SCSI_QDEPTH_DEFAULT
:
1358 scsi_adjust_queue_depth(sdev
, scsi_get_tag_type(sdev
), qdepth
);
1360 case SCSI_QDEPTH_QFULL
:
1361 qla2x00_handle_queue_full(sdev
, qdepth
);
1363 case SCSI_QDEPTH_RAMP_UP
:
1364 qla2x00_adjust_sdev_qdepth_up(sdev
, qdepth
);
1370 return sdev
->queue_depth
;
1374 qla2x00_change_queue_type(struct scsi_device
*sdev
, int tag_type
)
1376 if (sdev
->tagged_supported
) {
1377 scsi_set_tag_type(sdev
, tag_type
);
1379 scsi_activate_tcq(sdev
, sdev
->queue_depth
);
1381 scsi_deactivate_tcq(sdev
, sdev
->queue_depth
);
1389 * qla2x00_config_dma_addressing() - Configure OS DMA addressing method.
1392 * At exit, the @ha's flags.enable_64bit_addressing set to indicated
1393 * supported addressing method.
1396 qla2x00_config_dma_addressing(struct qla_hw_data
*ha
)
1398 /* Assume a 32bit DMA mask. */
1399 ha
->flags
.enable_64bit_addressing
= 0;
1401 if (!dma_set_mask(&ha
->pdev
->dev
, DMA_BIT_MASK(64))) {
1402 /* Any upper-dword bits set? */
1403 if (MSD(dma_get_required_mask(&ha
->pdev
->dev
)) &&
1404 !pci_set_consistent_dma_mask(ha
->pdev
, DMA_BIT_MASK(64))) {
1405 /* Ok, a 64bit DMA mask is applicable. */
1406 ha
->flags
.enable_64bit_addressing
= 1;
1407 ha
->isp_ops
->calc_req_entries
= qla2x00_calc_iocbs_64
;
1408 ha
->isp_ops
->build_iocbs
= qla2x00_build_scsi_iocbs_64
;
1413 dma_set_mask(&ha
->pdev
->dev
, DMA_BIT_MASK(32));
1414 pci_set_consistent_dma_mask(ha
->pdev
, DMA_BIT_MASK(32));
1418 qla2x00_enable_intrs(struct qla_hw_data
*ha
)
1420 unsigned long flags
= 0;
1421 struct device_reg_2xxx __iomem
*reg
= &ha
->iobase
->isp
;
1423 spin_lock_irqsave(&ha
->hardware_lock
, flags
);
1424 ha
->interrupts_on
= 1;
1425 /* enable risc and host interrupts */
1426 WRT_REG_WORD(®
->ictrl
, ICR_EN_INT
| ICR_EN_RISC
);
1427 RD_REG_WORD(®
->ictrl
);
1428 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
1433 qla2x00_disable_intrs(struct qla_hw_data
*ha
)
1435 unsigned long flags
= 0;
1436 struct device_reg_2xxx __iomem
*reg
= &ha
->iobase
->isp
;
1438 spin_lock_irqsave(&ha
->hardware_lock
, flags
);
1439 ha
->interrupts_on
= 0;
1440 /* disable risc and host interrupts */
1441 WRT_REG_WORD(®
->ictrl
, 0);
1442 RD_REG_WORD(®
->ictrl
);
1443 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
1447 qla24xx_enable_intrs(struct qla_hw_data
*ha
)
1449 unsigned long flags
= 0;
1450 struct device_reg_24xx __iomem
*reg
= &ha
->iobase
->isp24
;
1452 spin_lock_irqsave(&ha
->hardware_lock
, flags
);
1453 ha
->interrupts_on
= 1;
1454 WRT_REG_DWORD(®
->ictrl
, ICRX_EN_RISC_INT
);
1455 RD_REG_DWORD(®
->ictrl
);
1456 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
1460 qla24xx_disable_intrs(struct qla_hw_data
*ha
)
1462 unsigned long flags
= 0;
1463 struct device_reg_24xx __iomem
*reg
= &ha
->iobase
->isp24
;
1465 if (IS_NOPOLLING_TYPE(ha
))
1467 spin_lock_irqsave(&ha
->hardware_lock
, flags
);
1468 ha
->interrupts_on
= 0;
1469 WRT_REG_DWORD(®
->ictrl
, 0);
1470 RD_REG_DWORD(®
->ictrl
);
1471 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
1474 static struct isp_operations qla2100_isp_ops
= {
1475 .pci_config
= qla2100_pci_config
,
1476 .reset_chip
= qla2x00_reset_chip
,
1477 .chip_diag
= qla2x00_chip_diag
,
1478 .config_rings
= qla2x00_config_rings
,
1479 .reset_adapter
= qla2x00_reset_adapter
,
1480 .nvram_config
= qla2x00_nvram_config
,
1481 .update_fw_options
= qla2x00_update_fw_options
,
1482 .load_risc
= qla2x00_load_risc
,
1483 .pci_info_str
= qla2x00_pci_info_str
,
1484 .fw_version_str
= qla2x00_fw_version_str
,
1485 .intr_handler
= qla2100_intr_handler
,
1486 .enable_intrs
= qla2x00_enable_intrs
,
1487 .disable_intrs
= qla2x00_disable_intrs
,
1488 .abort_command
= qla2x00_abort_command
,
1489 .target_reset
= qla2x00_abort_target
,
1490 .lun_reset
= qla2x00_lun_reset
,
1491 .fabric_login
= qla2x00_login_fabric
,
1492 .fabric_logout
= qla2x00_fabric_logout
,
1493 .calc_req_entries
= qla2x00_calc_iocbs_32
,
1494 .build_iocbs
= qla2x00_build_scsi_iocbs_32
,
1495 .prep_ms_iocb
= qla2x00_prep_ms_iocb
,
1496 .prep_ms_fdmi_iocb
= qla2x00_prep_ms_fdmi_iocb
,
1497 .read_nvram
= qla2x00_read_nvram_data
,
1498 .write_nvram
= qla2x00_write_nvram_data
,
1499 .fw_dump
= qla2100_fw_dump
,
1502 .beacon_blink
= NULL
,
1503 .read_optrom
= qla2x00_read_optrom_data
,
1504 .write_optrom
= qla2x00_write_optrom_data
,
1505 .get_flash_version
= qla2x00_get_flash_version
,
1506 .start_scsi
= qla2x00_start_scsi
,
1507 .abort_isp
= qla2x00_abort_isp
,
1510 static struct isp_operations qla2300_isp_ops
= {
1511 .pci_config
= qla2300_pci_config
,
1512 .reset_chip
= qla2x00_reset_chip
,
1513 .chip_diag
= qla2x00_chip_diag
,
1514 .config_rings
= qla2x00_config_rings
,
1515 .reset_adapter
= qla2x00_reset_adapter
,
1516 .nvram_config
= qla2x00_nvram_config
,
1517 .update_fw_options
= qla2x00_update_fw_options
,
1518 .load_risc
= qla2x00_load_risc
,
1519 .pci_info_str
= qla2x00_pci_info_str
,
1520 .fw_version_str
= qla2x00_fw_version_str
,
1521 .intr_handler
= qla2300_intr_handler
,
1522 .enable_intrs
= qla2x00_enable_intrs
,
1523 .disable_intrs
= qla2x00_disable_intrs
,
1524 .abort_command
= qla2x00_abort_command
,
1525 .target_reset
= qla2x00_abort_target
,
1526 .lun_reset
= qla2x00_lun_reset
,
1527 .fabric_login
= qla2x00_login_fabric
,
1528 .fabric_logout
= qla2x00_fabric_logout
,
1529 .calc_req_entries
= qla2x00_calc_iocbs_32
,
1530 .build_iocbs
= qla2x00_build_scsi_iocbs_32
,
1531 .prep_ms_iocb
= qla2x00_prep_ms_iocb
,
1532 .prep_ms_fdmi_iocb
= qla2x00_prep_ms_fdmi_iocb
,
1533 .read_nvram
= qla2x00_read_nvram_data
,
1534 .write_nvram
= qla2x00_write_nvram_data
,
1535 .fw_dump
= qla2300_fw_dump
,
1536 .beacon_on
= qla2x00_beacon_on
,
1537 .beacon_off
= qla2x00_beacon_off
,
1538 .beacon_blink
= qla2x00_beacon_blink
,
1539 .read_optrom
= qla2x00_read_optrom_data
,
1540 .write_optrom
= qla2x00_write_optrom_data
,
1541 .get_flash_version
= qla2x00_get_flash_version
,
1542 .start_scsi
= qla2x00_start_scsi
,
1543 .abort_isp
= qla2x00_abort_isp
,
1546 static struct isp_operations qla24xx_isp_ops
= {
1547 .pci_config
= qla24xx_pci_config
,
1548 .reset_chip
= qla24xx_reset_chip
,
1549 .chip_diag
= qla24xx_chip_diag
,
1550 .config_rings
= qla24xx_config_rings
,
1551 .reset_adapter
= qla24xx_reset_adapter
,
1552 .nvram_config
= qla24xx_nvram_config
,
1553 .update_fw_options
= qla24xx_update_fw_options
,
1554 .load_risc
= qla24xx_load_risc
,
1555 .pci_info_str
= qla24xx_pci_info_str
,
1556 .fw_version_str
= qla24xx_fw_version_str
,
1557 .intr_handler
= qla24xx_intr_handler
,
1558 .enable_intrs
= qla24xx_enable_intrs
,
1559 .disable_intrs
= qla24xx_disable_intrs
,
1560 .abort_command
= qla24xx_abort_command
,
1561 .target_reset
= qla24xx_abort_target
,
1562 .lun_reset
= qla24xx_lun_reset
,
1563 .fabric_login
= qla24xx_login_fabric
,
1564 .fabric_logout
= qla24xx_fabric_logout
,
1565 .calc_req_entries
= NULL
,
1566 .build_iocbs
= NULL
,
1567 .prep_ms_iocb
= qla24xx_prep_ms_iocb
,
1568 .prep_ms_fdmi_iocb
= qla24xx_prep_ms_fdmi_iocb
,
1569 .read_nvram
= qla24xx_read_nvram_data
,
1570 .write_nvram
= qla24xx_write_nvram_data
,
1571 .fw_dump
= qla24xx_fw_dump
,
1572 .beacon_on
= qla24xx_beacon_on
,
1573 .beacon_off
= qla24xx_beacon_off
,
1574 .beacon_blink
= qla24xx_beacon_blink
,
1575 .read_optrom
= qla24xx_read_optrom_data
,
1576 .write_optrom
= qla24xx_write_optrom_data
,
1577 .get_flash_version
= qla24xx_get_flash_version
,
1578 .start_scsi
= qla24xx_start_scsi
,
1579 .abort_isp
= qla2x00_abort_isp
,
1582 static struct isp_operations qla25xx_isp_ops
= {
1583 .pci_config
= qla25xx_pci_config
,
1584 .reset_chip
= qla24xx_reset_chip
,
1585 .chip_diag
= qla24xx_chip_diag
,
1586 .config_rings
= qla24xx_config_rings
,
1587 .reset_adapter
= qla24xx_reset_adapter
,
1588 .nvram_config
= qla24xx_nvram_config
,
1589 .update_fw_options
= qla24xx_update_fw_options
,
1590 .load_risc
= qla24xx_load_risc
,
1591 .pci_info_str
= qla24xx_pci_info_str
,
1592 .fw_version_str
= qla24xx_fw_version_str
,
1593 .intr_handler
= qla24xx_intr_handler
,
1594 .enable_intrs
= qla24xx_enable_intrs
,
1595 .disable_intrs
= qla24xx_disable_intrs
,
1596 .abort_command
= qla24xx_abort_command
,
1597 .target_reset
= qla24xx_abort_target
,
1598 .lun_reset
= qla24xx_lun_reset
,
1599 .fabric_login
= qla24xx_login_fabric
,
1600 .fabric_logout
= qla24xx_fabric_logout
,
1601 .calc_req_entries
= NULL
,
1602 .build_iocbs
= NULL
,
1603 .prep_ms_iocb
= qla24xx_prep_ms_iocb
,
1604 .prep_ms_fdmi_iocb
= qla24xx_prep_ms_fdmi_iocb
,
1605 .read_nvram
= qla25xx_read_nvram_data
,
1606 .write_nvram
= qla25xx_write_nvram_data
,
1607 .fw_dump
= qla25xx_fw_dump
,
1608 .beacon_on
= qla24xx_beacon_on
,
1609 .beacon_off
= qla24xx_beacon_off
,
1610 .beacon_blink
= qla24xx_beacon_blink
,
1611 .read_optrom
= qla25xx_read_optrom_data
,
1612 .write_optrom
= qla24xx_write_optrom_data
,
1613 .get_flash_version
= qla24xx_get_flash_version
,
1614 .start_scsi
= qla24xx_dif_start_scsi
,
1615 .abort_isp
= qla2x00_abort_isp
,
1618 static struct isp_operations qla81xx_isp_ops
= {
1619 .pci_config
= qla25xx_pci_config
,
1620 .reset_chip
= qla24xx_reset_chip
,
1621 .chip_diag
= qla24xx_chip_diag
,
1622 .config_rings
= qla24xx_config_rings
,
1623 .reset_adapter
= qla24xx_reset_adapter
,
1624 .nvram_config
= qla81xx_nvram_config
,
1625 .update_fw_options
= qla81xx_update_fw_options
,
1626 .load_risc
= qla81xx_load_risc
,
1627 .pci_info_str
= qla24xx_pci_info_str
,
1628 .fw_version_str
= qla24xx_fw_version_str
,
1629 .intr_handler
= qla24xx_intr_handler
,
1630 .enable_intrs
= qla24xx_enable_intrs
,
1631 .disable_intrs
= qla24xx_disable_intrs
,
1632 .abort_command
= qla24xx_abort_command
,
1633 .target_reset
= qla24xx_abort_target
,
1634 .lun_reset
= qla24xx_lun_reset
,
1635 .fabric_login
= qla24xx_login_fabric
,
1636 .fabric_logout
= qla24xx_fabric_logout
,
1637 .calc_req_entries
= NULL
,
1638 .build_iocbs
= NULL
,
1639 .prep_ms_iocb
= qla24xx_prep_ms_iocb
,
1640 .prep_ms_fdmi_iocb
= qla24xx_prep_ms_fdmi_iocb
,
1642 .write_nvram
= NULL
,
1643 .fw_dump
= qla81xx_fw_dump
,
1644 .beacon_on
= qla24xx_beacon_on
,
1645 .beacon_off
= qla24xx_beacon_off
,
1646 .beacon_blink
= qla24xx_beacon_blink
,
1647 .read_optrom
= qla25xx_read_optrom_data
,
1648 .write_optrom
= qla24xx_write_optrom_data
,
1649 .get_flash_version
= qla24xx_get_flash_version
,
1650 .start_scsi
= qla24xx_dif_start_scsi
,
1651 .abort_isp
= qla2x00_abort_isp
,
1654 static struct isp_operations qla82xx_isp_ops
= {
1655 .pci_config
= qla82xx_pci_config
,
1656 .reset_chip
= qla82xx_reset_chip
,
1657 .chip_diag
= qla24xx_chip_diag
,
1658 .config_rings
= qla82xx_config_rings
,
1659 .reset_adapter
= qla24xx_reset_adapter
,
1660 .nvram_config
= qla81xx_nvram_config
,
1661 .update_fw_options
= qla24xx_update_fw_options
,
1662 .load_risc
= qla82xx_load_risc
,
1663 .pci_info_str
= qla82xx_pci_info_str
,
1664 .fw_version_str
= qla24xx_fw_version_str
,
1665 .intr_handler
= qla82xx_intr_handler
,
1666 .enable_intrs
= qla82xx_enable_intrs
,
1667 .disable_intrs
= qla82xx_disable_intrs
,
1668 .abort_command
= qla24xx_abort_command
,
1669 .target_reset
= qla24xx_abort_target
,
1670 .lun_reset
= qla24xx_lun_reset
,
1671 .fabric_login
= qla24xx_login_fabric
,
1672 .fabric_logout
= qla24xx_fabric_logout
,
1673 .calc_req_entries
= NULL
,
1674 .build_iocbs
= NULL
,
1675 .prep_ms_iocb
= qla24xx_prep_ms_iocb
,
1676 .prep_ms_fdmi_iocb
= qla24xx_prep_ms_fdmi_iocb
,
1677 .read_nvram
= qla24xx_read_nvram_data
,
1678 .write_nvram
= qla24xx_write_nvram_data
,
1679 .fw_dump
= qla24xx_fw_dump
,
1680 .beacon_on
= qla24xx_beacon_on
,
1681 .beacon_off
= qla24xx_beacon_off
,
1682 .beacon_blink
= qla24xx_beacon_blink
,
1683 .read_optrom
= qla82xx_read_optrom_data
,
1684 .write_optrom
= qla82xx_write_optrom_data
,
1685 .get_flash_version
= qla24xx_get_flash_version
,
1686 .start_scsi
= qla82xx_start_scsi
,
1687 .abort_isp
= qla82xx_abort_isp
,
1691 qla2x00_set_isp_flags(struct qla_hw_data
*ha
)
1693 ha
->device_type
= DT_EXTENDED_IDS
;
1694 switch (ha
->pdev
->device
) {
1695 case PCI_DEVICE_ID_QLOGIC_ISP2100
:
1696 ha
->device_type
|= DT_ISP2100
;
1697 ha
->device_type
&= ~DT_EXTENDED_IDS
;
1698 ha
->fw_srisc_address
= RISC_START_ADDRESS_2100
;
1700 case PCI_DEVICE_ID_QLOGIC_ISP2200
:
1701 ha
->device_type
|= DT_ISP2200
;
1702 ha
->device_type
&= ~DT_EXTENDED_IDS
;
1703 ha
->fw_srisc_address
= RISC_START_ADDRESS_2100
;
1705 case PCI_DEVICE_ID_QLOGIC_ISP2300
:
1706 ha
->device_type
|= DT_ISP2300
;
1707 ha
->device_type
|= DT_ZIO_SUPPORTED
;
1708 ha
->fw_srisc_address
= RISC_START_ADDRESS_2300
;
1710 case PCI_DEVICE_ID_QLOGIC_ISP2312
:
1711 ha
->device_type
|= DT_ISP2312
;
1712 ha
->device_type
|= DT_ZIO_SUPPORTED
;
1713 ha
->fw_srisc_address
= RISC_START_ADDRESS_2300
;
1715 case PCI_DEVICE_ID_QLOGIC_ISP2322
:
1716 ha
->device_type
|= DT_ISP2322
;
1717 ha
->device_type
|= DT_ZIO_SUPPORTED
;
1718 if (ha
->pdev
->subsystem_vendor
== 0x1028 &&
1719 ha
->pdev
->subsystem_device
== 0x0170)
1720 ha
->device_type
|= DT_OEM_001
;
1721 ha
->fw_srisc_address
= RISC_START_ADDRESS_2300
;
1723 case PCI_DEVICE_ID_QLOGIC_ISP6312
:
1724 ha
->device_type
|= DT_ISP6312
;
1725 ha
->fw_srisc_address
= RISC_START_ADDRESS_2300
;
1727 case PCI_DEVICE_ID_QLOGIC_ISP6322
:
1728 ha
->device_type
|= DT_ISP6322
;
1729 ha
->fw_srisc_address
= RISC_START_ADDRESS_2300
;
1731 case PCI_DEVICE_ID_QLOGIC_ISP2422
:
1732 ha
->device_type
|= DT_ISP2422
;
1733 ha
->device_type
|= DT_ZIO_SUPPORTED
;
1734 ha
->device_type
|= DT_FWI2
;
1735 ha
->device_type
|= DT_IIDMA
;
1736 ha
->fw_srisc_address
= RISC_START_ADDRESS_2400
;
1738 case PCI_DEVICE_ID_QLOGIC_ISP2432
:
1739 ha
->device_type
|= DT_ISP2432
;
1740 ha
->device_type
|= DT_ZIO_SUPPORTED
;
1741 ha
->device_type
|= DT_FWI2
;
1742 ha
->device_type
|= DT_IIDMA
;
1743 ha
->fw_srisc_address
= RISC_START_ADDRESS_2400
;
1745 case PCI_DEVICE_ID_QLOGIC_ISP8432
:
1746 ha
->device_type
|= DT_ISP8432
;
1747 ha
->device_type
|= DT_ZIO_SUPPORTED
;
1748 ha
->device_type
|= DT_FWI2
;
1749 ha
->device_type
|= DT_IIDMA
;
1750 ha
->fw_srisc_address
= RISC_START_ADDRESS_2400
;
1752 case PCI_DEVICE_ID_QLOGIC_ISP5422
:
1753 ha
->device_type
|= DT_ISP5422
;
1754 ha
->device_type
|= DT_FWI2
;
1755 ha
->fw_srisc_address
= RISC_START_ADDRESS_2400
;
1757 case PCI_DEVICE_ID_QLOGIC_ISP5432
:
1758 ha
->device_type
|= DT_ISP5432
;
1759 ha
->device_type
|= DT_FWI2
;
1760 ha
->fw_srisc_address
= RISC_START_ADDRESS_2400
;
1762 case PCI_DEVICE_ID_QLOGIC_ISP2532
:
1763 ha
->device_type
|= DT_ISP2532
;
1764 ha
->device_type
|= DT_ZIO_SUPPORTED
;
1765 ha
->device_type
|= DT_FWI2
;
1766 ha
->device_type
|= DT_IIDMA
;
1767 ha
->fw_srisc_address
= RISC_START_ADDRESS_2400
;
1769 case PCI_DEVICE_ID_QLOGIC_ISP8001
:
1770 ha
->device_type
|= DT_ISP8001
;
1771 ha
->device_type
|= DT_ZIO_SUPPORTED
;
1772 ha
->device_type
|= DT_FWI2
;
1773 ha
->device_type
|= DT_IIDMA
;
1774 ha
->fw_srisc_address
= RISC_START_ADDRESS_2400
;
1776 case PCI_DEVICE_ID_QLOGIC_ISP8021
:
1777 ha
->device_type
|= DT_ISP8021
;
1778 ha
->device_type
|= DT_ZIO_SUPPORTED
;
1779 ha
->device_type
|= DT_FWI2
;
1780 ha
->fw_srisc_address
= RISC_START_ADDRESS_2400
;
1781 /* Initialize 82XX ISP flags */
1782 qla82xx_init_flags(ha
);
1787 ha
->port_no
= !(ha
->portnum
& 1);
1789 /* Get adapter physical port no from interrupt pin register. */
1790 pci_read_config_byte(ha
->pdev
, PCI_INTERRUPT_PIN
, &ha
->port_no
);
1792 if (ha
->port_no
& 1)
1793 ha
->flags
.port0
= 1;
1795 ha
->flags
.port0
= 0;
1799 qla2x00_iospace_config(struct qla_hw_data
*ha
)
1801 resource_size_t pio
;
1806 return qla82xx_iospace_config(ha
);
1808 if (pci_request_selected_regions(ha
->pdev
, ha
->bars
,
1809 QLA2XXX_DRIVER_NAME
)) {
1810 qla_printk(KERN_WARNING
, ha
,
1811 "Failed to reserve PIO/MMIO regions (%s)\n",
1812 pci_name(ha
->pdev
));
1814 goto iospace_error_exit
;
1816 if (!(ha
->bars
& 1))
1819 /* We only need PIO for Flash operations on ISP2312 v2 chips. */
1820 pio
= pci_resource_start(ha
->pdev
, 0);
1821 if (pci_resource_flags(ha
->pdev
, 0) & IORESOURCE_IO
) {
1822 if (pci_resource_len(ha
->pdev
, 0) < MIN_IOBASE_LEN
) {
1823 qla_printk(KERN_WARNING
, ha
,
1824 "Invalid PCI I/O region size (%s)...\n",
1825 pci_name(ha
->pdev
));
1829 qla_printk(KERN_WARNING
, ha
,
1830 "region #0 not a PIO resource (%s)...\n",
1831 pci_name(ha
->pdev
));
1834 ha
->pio_address
= pio
;
1837 /* Use MMIO operations for all accesses. */
1838 if (!(pci_resource_flags(ha
->pdev
, 1) & IORESOURCE_MEM
)) {
1839 qla_printk(KERN_ERR
, ha
,
1840 "region #1 not an MMIO resource (%s), aborting\n",
1841 pci_name(ha
->pdev
));
1842 goto iospace_error_exit
;
1844 if (pci_resource_len(ha
->pdev
, 1) < MIN_IOBASE_LEN
) {
1845 qla_printk(KERN_ERR
, ha
,
1846 "Invalid PCI mem region size (%s), aborting\n",
1847 pci_name(ha
->pdev
));
1848 goto iospace_error_exit
;
1851 ha
->iobase
= ioremap(pci_resource_start(ha
->pdev
, 1), MIN_IOBASE_LEN
);
1853 qla_printk(KERN_ERR
, ha
,
1854 "cannot remap MMIO (%s), aborting\n", pci_name(ha
->pdev
));
1856 goto iospace_error_exit
;
1859 /* Determine queue resources */
1860 ha
->max_req_queues
= ha
->max_rsp_queues
= 1;
1861 if ((ql2xmaxqueues
<= 1 && !ql2xmultique_tag
) ||
1862 (ql2xmaxqueues
> 1 && ql2xmultique_tag
) ||
1863 (!IS_QLA25XX(ha
) && !IS_QLA81XX(ha
)))
1866 ha
->mqiobase
= ioremap(pci_resource_start(ha
->pdev
, 3),
1867 pci_resource_len(ha
->pdev
, 3));
1869 /* Read MSIX vector size of the board */
1870 pci_read_config_word(ha
->pdev
, QLA_PCI_MSIX_CONTROL
, &msix
);
1871 ha
->msix_count
= msix
;
1872 /* Max queues are bounded by available msix vectors */
1873 /* queue 0 uses two msix vectors */
1874 if (ql2xmultique_tag
) {
1875 cpus
= num_online_cpus();
1876 ha
->max_rsp_queues
= (ha
->msix_count
- 1 > cpus
) ?
1877 (cpus
+ 1) : (ha
->msix_count
- 1);
1878 ha
->max_req_queues
= 2;
1879 } else if (ql2xmaxqueues
> 1) {
1880 ha
->max_req_queues
= ql2xmaxqueues
> QLA_MQ_SIZE
?
1881 QLA_MQ_SIZE
: ql2xmaxqueues
;
1882 DEBUG2(qla_printk(KERN_INFO
, ha
, "QoS mode set, max no"
1883 " of request queues:%d\n", ha
->max_req_queues
));
1885 qla_printk(KERN_INFO
, ha
,
1886 "MSI-X vector count: %d\n", msix
);
1888 qla_printk(KERN_INFO
, ha
, "BAR 3 not enabled\n");
1891 ha
->msix_count
= ha
->max_rsp_queues
+ 1;
1899 qla2xxx_scan_start(struct Scsi_Host
*shost
)
1901 scsi_qla_host_t
*vha
= shost_priv(shost
);
1903 if (vha
->hw
->flags
.running_gold_fw
)
1906 set_bit(LOOP_RESYNC_NEEDED
, &vha
->dpc_flags
);
1907 set_bit(LOCAL_LOOP_UPDATE
, &vha
->dpc_flags
);
1908 set_bit(RSCN_UPDATE
, &vha
->dpc_flags
);
1909 set_bit(NPIV_CONFIG_NEEDED
, &vha
->dpc_flags
);
1913 qla2xxx_scan_finished(struct Scsi_Host
*shost
, unsigned long time
)
1915 scsi_qla_host_t
*vha
= shost_priv(shost
);
1919 if (time
> vha
->hw
->loop_reset_delay
* HZ
)
1922 return atomic_read(&vha
->loop_state
) == LOOP_READY
;
1926 * PCI driver interface
1928 static int __devinit
1929 qla2x00_probe_one(struct pci_dev
*pdev
, const struct pci_device_id
*id
)
1932 struct Scsi_Host
*host
;
1933 scsi_qla_host_t
*base_vha
= NULL
;
1934 struct qla_hw_data
*ha
;
1937 struct scsi_host_template
*sht
;
1938 int bars
, max_id
, mem_only
= 0;
1939 uint16_t req_length
= 0, rsp_length
= 0;
1940 struct req_que
*req
= NULL
;
1941 struct rsp_que
*rsp
= NULL
;
1943 bars
= pci_select_bars(pdev
, IORESOURCE_MEM
| IORESOURCE_IO
);
1944 sht
= &qla2xxx_driver_template
;
1945 if (pdev
->device
== PCI_DEVICE_ID_QLOGIC_ISP2422
||
1946 pdev
->device
== PCI_DEVICE_ID_QLOGIC_ISP2432
||
1947 pdev
->device
== PCI_DEVICE_ID_QLOGIC_ISP8432
||
1948 pdev
->device
== PCI_DEVICE_ID_QLOGIC_ISP5422
||
1949 pdev
->device
== PCI_DEVICE_ID_QLOGIC_ISP5432
||
1950 pdev
->device
== PCI_DEVICE_ID_QLOGIC_ISP2532
||
1951 pdev
->device
== PCI_DEVICE_ID_QLOGIC_ISP8001
||
1952 pdev
->device
== PCI_DEVICE_ID_QLOGIC_ISP8021
) {
1953 bars
= pci_select_bars(pdev
, IORESOURCE_MEM
);
1958 if (pci_enable_device_mem(pdev
))
1961 if (pci_enable_device(pdev
))
1965 /* This may fail but that's ok */
1966 pci_enable_pcie_error_reporting(pdev
);
1968 ha
= kzalloc(sizeof(struct qla_hw_data
), GFP_KERNEL
);
1970 DEBUG(printk("Unable to allocate memory for ha\n"));
1975 /* Clear our data area */
1977 ha
->mem_only
= mem_only
;
1978 spin_lock_init(&ha
->hardware_lock
);
1980 /* Set ISP-type information. */
1981 qla2x00_set_isp_flags(ha
);
1983 /* Set EEH reset type to fundamental if required by hba */
1984 if ( IS_QLA24XX(ha
) || IS_QLA25XX(ha
) || IS_QLA81XX(ha
)) {
1985 pdev
->needs_freset
= 1;
1988 /* Configure PCI I/O space */
1989 ret
= qla2x00_iospace_config(ha
);
1991 goto probe_hw_failed
;
1993 qla_printk(KERN_INFO
, ha
,
1994 "Found an ISP%04X, irq %d, iobase 0x%p\n", pdev
->device
, pdev
->irq
,
1997 ha
->prev_topology
= 0;
1998 ha
->init_cb_size
= sizeof(init_cb_t
);
1999 ha
->link_data_rate
= PORT_SPEED_UNKNOWN
;
2000 ha
->optrom_size
= OPTROM_SIZE_2300
;
2002 /* Assign ISP specific operations. */
2003 max_id
= MAX_TARGETS_2200
;
2004 if (IS_QLA2100(ha
)) {
2005 max_id
= MAX_TARGETS_2100
;
2006 ha
->mbx_count
= MAILBOX_REGISTER_COUNT_2100
;
2007 req_length
= REQUEST_ENTRY_CNT_2100
;
2008 rsp_length
= RESPONSE_ENTRY_CNT_2100
;
2009 ha
->max_loop_id
= SNS_LAST_LOOP_ID_2100
;
2010 ha
->gid_list_info_size
= 4;
2011 ha
->flash_conf_off
= ~0;
2012 ha
->flash_data_off
= ~0;
2013 ha
->nvram_conf_off
= ~0;
2014 ha
->nvram_data_off
= ~0;
2015 ha
->isp_ops
= &qla2100_isp_ops
;
2016 } else if (IS_QLA2200(ha
)) {
2017 ha
->mbx_count
= MAILBOX_REGISTER_COUNT
;
2018 req_length
= REQUEST_ENTRY_CNT_2200
;
2019 rsp_length
= RESPONSE_ENTRY_CNT_2100
;
2020 ha
->max_loop_id
= SNS_LAST_LOOP_ID_2100
;
2021 ha
->gid_list_info_size
= 4;
2022 ha
->flash_conf_off
= ~0;
2023 ha
->flash_data_off
= ~0;
2024 ha
->nvram_conf_off
= ~0;
2025 ha
->nvram_data_off
= ~0;
2026 ha
->isp_ops
= &qla2100_isp_ops
;
2027 } else if (IS_QLA23XX(ha
)) {
2028 ha
->mbx_count
= MAILBOX_REGISTER_COUNT
;
2029 req_length
= REQUEST_ENTRY_CNT_2200
;
2030 rsp_length
= RESPONSE_ENTRY_CNT_2300
;
2031 ha
->max_loop_id
= SNS_LAST_LOOP_ID_2300
;
2032 ha
->gid_list_info_size
= 6;
2033 if (IS_QLA2322(ha
) || IS_QLA6322(ha
))
2034 ha
->optrom_size
= OPTROM_SIZE_2322
;
2035 ha
->flash_conf_off
= ~0;
2036 ha
->flash_data_off
= ~0;
2037 ha
->nvram_conf_off
= ~0;
2038 ha
->nvram_data_off
= ~0;
2039 ha
->isp_ops
= &qla2300_isp_ops
;
2040 } else if (IS_QLA24XX_TYPE(ha
)) {
2041 ha
->mbx_count
= MAILBOX_REGISTER_COUNT
;
2042 req_length
= REQUEST_ENTRY_CNT_24XX
;
2043 rsp_length
= RESPONSE_ENTRY_CNT_2300
;
2044 ha
->max_loop_id
= SNS_LAST_LOOP_ID_2300
;
2045 ha
->init_cb_size
= sizeof(struct mid_init_cb_24xx
);
2046 ha
->gid_list_info_size
= 8;
2047 ha
->optrom_size
= OPTROM_SIZE_24XX
;
2048 ha
->nvram_npiv_size
= QLA_MAX_VPORTS_QLA24XX
;
2049 ha
->isp_ops
= &qla24xx_isp_ops
;
2050 ha
->flash_conf_off
= FARX_ACCESS_FLASH_CONF
;
2051 ha
->flash_data_off
= FARX_ACCESS_FLASH_DATA
;
2052 ha
->nvram_conf_off
= FARX_ACCESS_NVRAM_CONF
;
2053 ha
->nvram_data_off
= FARX_ACCESS_NVRAM_DATA
;
2054 } else if (IS_QLA25XX(ha
)) {
2055 ha
->mbx_count
= MAILBOX_REGISTER_COUNT
;
2056 req_length
= REQUEST_ENTRY_CNT_24XX
;
2057 rsp_length
= RESPONSE_ENTRY_CNT_2300
;
2058 ha
->max_loop_id
= SNS_LAST_LOOP_ID_2300
;
2059 ha
->init_cb_size
= sizeof(struct mid_init_cb_24xx
);
2060 ha
->gid_list_info_size
= 8;
2061 ha
->optrom_size
= OPTROM_SIZE_25XX
;
2062 ha
->nvram_npiv_size
= QLA_MAX_VPORTS_QLA25XX
;
2063 ha
->isp_ops
= &qla25xx_isp_ops
;
2064 ha
->flash_conf_off
= FARX_ACCESS_FLASH_CONF
;
2065 ha
->flash_data_off
= FARX_ACCESS_FLASH_DATA
;
2066 ha
->nvram_conf_off
= FARX_ACCESS_NVRAM_CONF
;
2067 ha
->nvram_data_off
= FARX_ACCESS_NVRAM_DATA
;
2068 } else if (IS_QLA81XX(ha
)) {
2069 ha
->mbx_count
= MAILBOX_REGISTER_COUNT
;
2070 req_length
= REQUEST_ENTRY_CNT_24XX
;
2071 rsp_length
= RESPONSE_ENTRY_CNT_2300
;
2072 ha
->max_loop_id
= SNS_LAST_LOOP_ID_2300
;
2073 ha
->init_cb_size
= sizeof(struct mid_init_cb_81xx
);
2074 ha
->gid_list_info_size
= 8;
2075 ha
->optrom_size
= OPTROM_SIZE_81XX
;
2076 ha
->nvram_npiv_size
= QLA_MAX_VPORTS_QLA25XX
;
2077 ha
->isp_ops
= &qla81xx_isp_ops
;
2078 ha
->flash_conf_off
= FARX_ACCESS_FLASH_CONF_81XX
;
2079 ha
->flash_data_off
= FARX_ACCESS_FLASH_DATA_81XX
;
2080 ha
->nvram_conf_off
= ~0;
2081 ha
->nvram_data_off
= ~0;
2082 } else if (IS_QLA82XX(ha
)) {
2083 ha
->mbx_count
= MAILBOX_REGISTER_COUNT
;
2084 req_length
= REQUEST_ENTRY_CNT_82XX
;
2085 rsp_length
= RESPONSE_ENTRY_CNT_82XX
;
2086 ha
->max_loop_id
= SNS_LAST_LOOP_ID_2300
;
2087 ha
->init_cb_size
= sizeof(struct mid_init_cb_81xx
);
2088 ha
->gid_list_info_size
= 8;
2089 ha
->optrom_size
= OPTROM_SIZE_82XX
;
2090 ha
->nvram_npiv_size
= QLA_MAX_VPORTS_QLA25XX
;
2091 ha
->isp_ops
= &qla82xx_isp_ops
;
2092 ha
->flash_conf_off
= FARX_ACCESS_FLASH_CONF
;
2093 ha
->flash_data_off
= FARX_ACCESS_FLASH_DATA
;
2094 ha
->nvram_conf_off
= FARX_ACCESS_NVRAM_CONF
;
2095 ha
->nvram_data_off
= FARX_ACCESS_NVRAM_DATA
;
2098 mutex_init(&ha
->vport_lock
);
2099 init_completion(&ha
->mbx_cmd_comp
);
2100 complete(&ha
->mbx_cmd_comp
);
2101 init_completion(&ha
->mbx_intr_comp
);
2102 init_completion(&ha
->dcbx_comp
);
2104 set_bit(0, (unsigned long *) ha
->vp_idx_map
);
2106 qla2x00_config_dma_addressing(ha
);
2107 ret
= qla2x00_mem_alloc(ha
, req_length
, rsp_length
, &req
, &rsp
);
2109 qla_printk(KERN_WARNING
, ha
,
2110 "[ERROR] Failed to allocate memory for adapter\n");
2112 goto probe_hw_failed
;
2115 req
->max_q_depth
= MAX_Q_DEPTH
;
2116 if (ql2xmaxqdepth
!= 0 && ql2xmaxqdepth
<= 0xffffU
)
2117 req
->max_q_depth
= ql2xmaxqdepth
;
2120 base_vha
= qla2x00_create_host(sht
, ha
);
2122 qla_printk(KERN_WARNING
, ha
,
2123 "[ERROR] Failed to allocate memory for scsi_host\n");
2126 qla2x00_mem_free(ha
);
2127 qla2x00_free_req_que(ha
, req
);
2128 qla2x00_free_rsp_que(ha
, rsp
);
2129 goto probe_hw_failed
;
2132 pci_set_drvdata(pdev
, base_vha
);
2134 host
= base_vha
->host
;
2135 base_vha
->req
= req
;
2136 host
->can_queue
= req
->length
+ 128;
2137 if (IS_QLA2XXX_MIDTYPE(ha
))
2138 base_vha
->mgmt_svr_loop_id
= 10 + base_vha
->vp_idx
;
2140 base_vha
->mgmt_svr_loop_id
= MANAGEMENT_SERVER
+
2143 host
->sg_tablesize
= 32;
2144 host
->max_id
= max_id
;
2145 host
->this_id
= 255;
2146 host
->cmd_per_lun
= 3;
2147 host
->unique_id
= host
->host_no
;
2148 if ((IS_QLA25XX(ha
) || IS_QLA81XX(ha
)) && ql2xenabledif
)
2149 host
->max_cmd_len
= 32;
2151 host
->max_cmd_len
= MAX_CMDSZ
;
2152 host
->max_channel
= MAX_BUSES
- 1;
2153 host
->max_lun
= MAX_LUNS
;
2154 host
->transportt
= qla2xxx_transport_template
;
2155 sht
->vendor_id
= (SCSI_NL_VID_TYPE_PCI
| PCI_VENDOR_ID_QLOGIC
);
2157 /* Set up the irqs */
2158 ret
= qla2x00_request_irqs(ha
, rsp
);
2160 goto probe_init_failed
;
2162 pci_save_state(pdev
);
2164 /* Alloc arrays of request and response ring ptrs */
2166 if (!qla2x00_alloc_queues(ha
)) {
2167 qla_printk(KERN_WARNING
, ha
,
2168 "[ERROR] Failed to allocate memory for queue"
2170 goto probe_init_failed
;
2173 ha
->rsp_q_map
[0] = rsp
;
2174 ha
->req_q_map
[0] = req
;
2177 set_bit(0, ha
->req_qid_map
);
2178 set_bit(0, ha
->rsp_qid_map
);
2179 /* FWI2-capable only. */
2180 req
->req_q_in
= &ha
->iobase
->isp24
.req_q_in
;
2181 req
->req_q_out
= &ha
->iobase
->isp24
.req_q_out
;
2182 rsp
->rsp_q_in
= &ha
->iobase
->isp24
.rsp_q_in
;
2183 rsp
->rsp_q_out
= &ha
->iobase
->isp24
.rsp_q_out
;
2185 req
->req_q_in
= &ha
->mqiobase
->isp25mq
.req_q_in
;
2186 req
->req_q_out
= &ha
->mqiobase
->isp25mq
.req_q_out
;
2187 rsp
->rsp_q_in
= &ha
->mqiobase
->isp25mq
.rsp_q_in
;
2188 rsp
->rsp_q_out
= &ha
->mqiobase
->isp25mq
.rsp_q_out
;
2191 if (IS_QLA82XX(ha
)) {
2192 req
->req_q_out
= &ha
->iobase
->isp82
.req_q_out
[0];
2193 rsp
->rsp_q_in
= &ha
->iobase
->isp82
.rsp_q_in
[0];
2194 rsp
->rsp_q_out
= &ha
->iobase
->isp82
.rsp_q_out
[0];
2197 if (qla2x00_initialize_adapter(base_vha
)) {
2198 qla_printk(KERN_WARNING
, ha
,
2199 "Failed to initialize adapter\n");
2201 DEBUG2(printk("scsi(%ld): Failed to initialize adapter - "
2202 "Adapter flags %x.\n",
2203 base_vha
->host_no
, base_vha
->device_flags
));
2205 if (IS_QLA82XX(ha
)) {
2206 qla82xx_idc_lock(ha
);
2207 qla82xx_wr_32(ha
, QLA82XX_CRB_DEV_STATE
,
2208 QLA82XX_DEV_FAILED
);
2209 qla82xx_idc_unlock(ha
);
2210 qla_printk(KERN_INFO
, ha
, "HW State: FAILED\n");
2218 if (qla25xx_setup_mode(base_vha
)) {
2219 qla_printk(KERN_WARNING
, ha
,
2220 "Can't create queues, falling back to single"
2226 if (ha
->flags
.running_gold_fw
)
2230 * Startup the kernel thread for this host adapter
2232 ha
->dpc_thread
= kthread_create(qla2x00_do_dpc
, ha
,
2233 "%s_dpc", base_vha
->host_str
);
2234 if (IS_ERR(ha
->dpc_thread
)) {
2235 qla_printk(KERN_WARNING
, ha
,
2236 "Unable to start DPC thread!\n");
2237 ret
= PTR_ERR(ha
->dpc_thread
);
2242 list_add_tail(&base_vha
->list
, &ha
->vp_list
);
2243 base_vha
->host
->irq
= ha
->pdev
->irq
;
2245 /* Initialized the timer */
2246 qla2x00_start_timer(base_vha
, qla2x00_timer
, WATCH_INTERVAL
);
2248 DEBUG2(printk("DEBUG: detect hba %ld at address = %p\n",
2249 base_vha
->host_no
, ha
));
2251 if ((IS_QLA25XX(ha
) || IS_QLA81XX(ha
)) && ql2xenabledif
) {
2252 if (ha
->fw_attributes
& BIT_4
) {
2253 base_vha
->flags
.difdix_supported
= 1;
2254 DEBUG18(qla_printk(KERN_INFO
, ha
,
2255 "Registering for DIF/DIX type 1 and 3"
2257 scsi_host_set_prot(host
,
2258 SHOST_DIF_TYPE1_PROTECTION
2259 | SHOST_DIF_TYPE2_PROTECTION
2260 | SHOST_DIF_TYPE3_PROTECTION
2261 | SHOST_DIX_TYPE1_PROTECTION
2262 | SHOST_DIX_TYPE2_PROTECTION
2263 | SHOST_DIX_TYPE3_PROTECTION
);
2264 scsi_host_set_guard(host
, SHOST_DIX_GUARD_CRC
);
2266 base_vha
->flags
.difdix_supported
= 0;
2269 ha
->isp_ops
->enable_intrs(ha
);
2271 ret
= scsi_add_host(host
, &pdev
->dev
);
2275 base_vha
->flags
.init_done
= 1;
2276 base_vha
->flags
.online
= 1;
2278 scsi_scan_host(host
);
2280 qla2x00_alloc_sysfs_attr(base_vha
);
2282 qla2x00_init_host_attr(base_vha
);
2284 qla2x00_dfs_setup(base_vha
);
2286 qla_printk(KERN_INFO
, ha
, "\n"
2287 " QLogic Fibre Channel HBA Driver: %s\n"
2289 " ISP%04X: %s @ %s hdma%c, host#=%ld, fw=%s\n",
2290 qla2x00_version_str
, ha
->model_number
,
2291 ha
->model_desc
? ha
->model_desc
: "", pdev
->device
,
2292 ha
->isp_ops
->pci_info_str(base_vha
, pci_info
), pci_name(pdev
),
2293 ha
->flags
.enable_64bit_addressing
? '+' : '-', base_vha
->host_no
,
2294 ha
->isp_ops
->fw_version_str(base_vha
, fw_str
));
2299 qla2x00_free_req_que(ha
, req
);
2300 qla2x00_free_rsp_que(ha
, rsp
);
2301 ha
->max_req_queues
= ha
->max_rsp_queues
= 0;
2304 if (base_vha
->timer_active
)
2305 qla2x00_stop_timer(base_vha
);
2306 base_vha
->flags
.online
= 0;
2307 if (ha
->dpc_thread
) {
2308 struct task_struct
*t
= ha
->dpc_thread
;
2310 ha
->dpc_thread
= NULL
;
2314 qla2x00_free_device(base_vha
);
2316 scsi_host_put(base_vha
->host
);
2319 if (IS_QLA82XX(ha
)) {
2320 qla82xx_idc_lock(ha
);
2321 qla82xx_clear_drv_active(ha
);
2322 qla82xx_idc_unlock(ha
);
2323 iounmap((device_reg_t __iomem
*)ha
->nx_pcibase
);
2325 iounmap((device_reg_t __iomem
*)ha
->nxdb_wr_ptr
);
2328 iounmap(ha
->iobase
);
2330 pci_release_selected_regions(ha
->pdev
, ha
->bars
);
2335 pci_disable_device(pdev
);
2340 qla2x00_remove_one(struct pci_dev
*pdev
)
2342 scsi_qla_host_t
*base_vha
, *vha
;
2343 struct qla_hw_data
*ha
;
2344 unsigned long flags
;
2346 base_vha
= pci_get_drvdata(pdev
);
2349 spin_lock_irqsave(&ha
->vport_slock
, flags
);
2350 list_for_each_entry(vha
, &ha
->vp_list
, list
) {
2351 atomic_inc(&vha
->vref_count
);
2353 if (vha
&& vha
->fc_vport
) {
2354 spin_unlock_irqrestore(&ha
->vport_slock
, flags
);
2356 fc_vport_terminate(vha
->fc_vport
);
2358 spin_lock_irqsave(&ha
->vport_slock
, flags
);
2361 atomic_dec(&vha
->vref_count
);
2363 spin_unlock_irqrestore(&ha
->vport_slock
, flags
);
2365 set_bit(UNLOADING
, &base_vha
->dpc_flags
);
2367 qla2x00_abort_all_cmds(base_vha
, DID_NO_CONNECT
<< 16);
2369 qla2x00_dfs_remove(base_vha
);
2371 qla84xx_put_chip(base_vha
);
2374 if (base_vha
->timer_active
)
2375 qla2x00_stop_timer(base_vha
);
2377 base_vha
->flags
.online
= 0;
2379 /* Flush the work queue and remove it */
2381 flush_workqueue(ha
->wq
);
2382 destroy_workqueue(ha
->wq
);
2386 /* Kill the kernel thread for this host */
2387 if (ha
->dpc_thread
) {
2388 struct task_struct
*t
= ha
->dpc_thread
;
2391 * qla2xxx_wake_dpc checks for ->dpc_thread
2392 * so we need to zero it out.
2394 ha
->dpc_thread
= NULL
;
2398 qla2x00_free_sysfs_attr(base_vha
);
2400 fc_remove_host(base_vha
->host
);
2402 scsi_remove_host(base_vha
->host
);
2404 qla2x00_free_device(base_vha
);
2406 scsi_host_put(base_vha
->host
);
2408 if (IS_QLA82XX(ha
)) {
2409 qla82xx_idc_lock(ha
);
2410 qla82xx_clear_drv_active(ha
);
2411 qla82xx_idc_unlock(ha
);
2413 iounmap((device_reg_t __iomem
*)ha
->nx_pcibase
);
2415 iounmap((device_reg_t __iomem
*)ha
->nxdb_wr_ptr
);
2418 iounmap(ha
->iobase
);
2421 iounmap(ha
->mqiobase
);
2424 pci_release_selected_regions(ha
->pdev
, ha
->bars
);
2428 pci_disable_pcie_error_reporting(pdev
);
2430 pci_disable_device(pdev
);
2431 pci_set_drvdata(pdev
, NULL
);
2435 qla2x00_free_device(scsi_qla_host_t
*vha
)
2437 struct qla_hw_data
*ha
= vha
->hw
;
2439 qla2x00_abort_all_cmds(vha
, DID_NO_CONNECT
<< 16);
2442 if (vha
->timer_active
)
2443 qla2x00_stop_timer(vha
);
2445 /* Kill the kernel thread for this host */
2446 if (ha
->dpc_thread
) {
2447 struct task_struct
*t
= ha
->dpc_thread
;
2450 * qla2xxx_wake_dpc checks for ->dpc_thread
2451 * so we need to zero it out.
2453 ha
->dpc_thread
= NULL
;
2457 qla25xx_delete_queues(vha
);
2459 if (ha
->flags
.fce_enabled
)
2460 qla2x00_disable_fce_trace(vha
, NULL
, NULL
);
2463 qla2x00_disable_eft_trace(vha
);
2465 /* Stop currently executing firmware. */
2466 qla2x00_try_to_stop_firmware(vha
);
2468 vha
->flags
.online
= 0;
2470 /* turn-off interrupts on the card */
2471 if (ha
->interrupts_on
) {
2472 vha
->flags
.init_done
= 0;
2473 ha
->isp_ops
->disable_intrs(ha
);
2476 qla2x00_free_irqs(vha
);
2478 qla2x00_free_fcports(vha
);
2480 qla2x00_mem_free(ha
);
2482 qla2x00_free_queues(ha
);
2485 void qla2x00_free_fcports(struct scsi_qla_host
*vha
)
2487 fc_port_t
*fcport
, *tfcport
;
2489 list_for_each_entry_safe(fcport
, tfcport
, &vha
->vp_fcports
, list
) {
2490 list_del(&fcport
->list
);
2497 qla2x00_schedule_rport_del(struct scsi_qla_host
*vha
, fc_port_t
*fcport
,
2500 struct fc_rport
*rport
;
2501 scsi_qla_host_t
*base_vha
;
2506 rport
= fcport
->rport
;
2508 base_vha
= pci_get_drvdata(vha
->hw
->pdev
);
2509 spin_lock_irq(vha
->host
->host_lock
);
2510 fcport
->drport
= rport
;
2511 spin_unlock_irq(vha
->host
->host_lock
);
2512 set_bit(FCPORT_UPDATE_NEEDED
, &base_vha
->dpc_flags
);
2513 qla2xxx_wake_dpc(base_vha
);
2515 fc_remote_port_delete(rport
);
2519 * qla2x00_mark_device_lost Updates fcport state when device goes offline.
2521 * Input: ha = adapter block pointer. fcport = port structure pointer.
2527 void qla2x00_mark_device_lost(scsi_qla_host_t
*vha
, fc_port_t
*fcport
,
2528 int do_login
, int defer
)
2530 if (atomic_read(&fcport
->state
) == FCS_ONLINE
&&
2531 vha
->vp_idx
== fcport
->vp_idx
) {
2532 atomic_set(&fcport
->state
, FCS_DEVICE_LOST
);
2533 qla2x00_schedule_rport_del(vha
, fcport
, defer
);
2536 * We may need to retry the login, so don't change the state of the
2537 * port but do the retries.
2539 if (atomic_read(&fcport
->state
) != FCS_DEVICE_DEAD
)
2540 atomic_set(&fcport
->state
, FCS_DEVICE_LOST
);
2545 if (fcport
->login_retry
== 0) {
2546 fcport
->login_retry
= vha
->hw
->login_retry_count
;
2547 set_bit(RELOGIN_NEEDED
, &vha
->dpc_flags
);
2549 DEBUG(printk("scsi(%ld): Port login retry: "
2550 "%02x%02x%02x%02x%02x%02x%02x%02x, "
2551 "id = 0x%04x retry cnt=%d\n",
2553 fcport
->port_name
[0],
2554 fcport
->port_name
[1],
2555 fcport
->port_name
[2],
2556 fcport
->port_name
[3],
2557 fcport
->port_name
[4],
2558 fcport
->port_name
[5],
2559 fcport
->port_name
[6],
2560 fcport
->port_name
[7],
2562 fcport
->login_retry
));
2567 * qla2x00_mark_all_devices_lost
2568 * Updates fcport state when device goes offline.
2571 * ha = adapter block pointer.
2572 * fcport = port structure pointer.
2580 qla2x00_mark_all_devices_lost(scsi_qla_host_t
*vha
, int defer
)
2584 list_for_each_entry(fcport
, &vha
->vp_fcports
, list
) {
2585 if (vha
->vp_idx
!= 0 && vha
->vp_idx
!= fcport
->vp_idx
)
2589 * No point in marking the device as lost, if the device is
2592 if (atomic_read(&fcport
->state
) == FCS_DEVICE_DEAD
)
2594 if (atomic_read(&fcport
->state
) == FCS_ONLINE
) {
2596 qla2x00_schedule_rport_del(vha
, fcport
, defer
);
2597 else if (vha
->vp_idx
== fcport
->vp_idx
)
2598 qla2x00_schedule_rport_del(vha
, fcport
, defer
);
2600 atomic_set(&fcport
->state
, FCS_DEVICE_LOST
);
2606 * Allocates adapter memory.
2613 qla2x00_mem_alloc(struct qla_hw_data
*ha
, uint16_t req_len
, uint16_t rsp_len
,
2614 struct req_que
**req
, struct rsp_que
**rsp
)
2618 ha
->init_cb
= dma_alloc_coherent(&ha
->pdev
->dev
, ha
->init_cb_size
,
2619 &ha
->init_cb_dma
, GFP_KERNEL
);
2623 ha
->gid_list
= dma_alloc_coherent(&ha
->pdev
->dev
, GID_LIST_SIZE
,
2624 &ha
->gid_list_dma
, GFP_KERNEL
);
2626 goto fail_free_init_cb
;
2628 ha
->srb_mempool
= mempool_create_slab_pool(SRB_MIN_REQ
, srb_cachep
);
2629 if (!ha
->srb_mempool
)
2630 goto fail_free_gid_list
;
2632 if (IS_QLA82XX(ha
)) {
2633 /* Allocate cache for CT6 Ctx. */
2635 ctx_cachep
= kmem_cache_create("qla2xxx_ctx",
2636 sizeof(struct ct6_dsd
), 0,
2637 SLAB_HWCACHE_ALIGN
, NULL
);
2639 goto fail_free_gid_list
;
2641 ha
->ctx_mempool
= mempool_create_slab_pool(SRB_MIN_REQ
,
2643 if (!ha
->ctx_mempool
)
2644 goto fail_free_srb_mempool
;
2647 /* Get memory for cached NVRAM */
2648 ha
->nvram
= kzalloc(MAX_NVRAM_SIZE
, GFP_KERNEL
);
2650 goto fail_free_ctx_mempool
;
2652 snprintf(name
, sizeof(name
), "%s_%d", QLA2XXX_DRIVER_NAME
,
2654 ha
->s_dma_pool
= dma_pool_create(name
, &ha
->pdev
->dev
,
2655 DMA_POOL_SIZE
, 8, 0);
2656 if (!ha
->s_dma_pool
)
2657 goto fail_free_nvram
;
2659 if (IS_QLA82XX(ha
) || ql2xenabledif
) {
2660 ha
->dl_dma_pool
= dma_pool_create(name
, &ha
->pdev
->dev
,
2661 DSD_LIST_DMA_POOL_SIZE
, 8, 0);
2662 if (!ha
->dl_dma_pool
) {
2663 qla_printk(KERN_WARNING
, ha
,
2664 "Memory Allocation failed - dl_dma_pool\n");
2665 goto fail_s_dma_pool
;
2668 ha
->fcp_cmnd_dma_pool
= dma_pool_create(name
, &ha
->pdev
->dev
,
2669 FCP_CMND_DMA_POOL_SIZE
, 8, 0);
2670 if (!ha
->fcp_cmnd_dma_pool
) {
2671 qla_printk(KERN_WARNING
, ha
,
2672 "Memory Allocation failed - fcp_cmnd_dma_pool\n");
2673 goto fail_dl_dma_pool
;
2677 /* Allocate memory for SNS commands */
2678 if (IS_QLA2100(ha
) || IS_QLA2200(ha
)) {
2679 /* Get consistent memory allocated for SNS commands */
2680 ha
->sns_cmd
= dma_alloc_coherent(&ha
->pdev
->dev
,
2681 sizeof(struct sns_cmd_pkt
), &ha
->sns_cmd_dma
, GFP_KERNEL
);
2685 /* Get consistent memory allocated for MS IOCB */
2686 ha
->ms_iocb
= dma_pool_alloc(ha
->s_dma_pool
, GFP_KERNEL
,
2690 /* Get consistent memory allocated for CT SNS commands */
2691 ha
->ct_sns
= dma_alloc_coherent(&ha
->pdev
->dev
,
2692 sizeof(struct ct_sns_pkt
), &ha
->ct_sns_dma
, GFP_KERNEL
);
2694 goto fail_free_ms_iocb
;
2697 /* Allocate memory for request ring */
2698 *req
= kzalloc(sizeof(struct req_que
), GFP_KERNEL
);
2700 DEBUG(printk("Unable to allocate memory for req\n"));
2703 (*req
)->length
= req_len
;
2704 (*req
)->ring
= dma_alloc_coherent(&ha
->pdev
->dev
,
2705 ((*req
)->length
+ 1) * sizeof(request_t
),
2706 &(*req
)->dma
, GFP_KERNEL
);
2707 if (!(*req
)->ring
) {
2708 DEBUG(printk("Unable to allocate memory for req_ring\n"));
2711 /* Allocate memory for response ring */
2712 *rsp
= kzalloc(sizeof(struct rsp_que
), GFP_KERNEL
);
2714 qla_printk(KERN_WARNING
, ha
,
2715 "Unable to allocate memory for rsp\n");
2719 (*rsp
)->length
= rsp_len
;
2720 (*rsp
)->ring
= dma_alloc_coherent(&ha
->pdev
->dev
,
2721 ((*rsp
)->length
+ 1) * sizeof(response_t
),
2722 &(*rsp
)->dma
, GFP_KERNEL
);
2723 if (!(*rsp
)->ring
) {
2724 qla_printk(KERN_WARNING
, ha
,
2725 "Unable to allocate memory for rsp_ring\n");
2730 /* Allocate memory for NVRAM data for vports */
2731 if (ha
->nvram_npiv_size
) {
2732 ha
->npiv_info
= kzalloc(sizeof(struct qla_npiv_entry
) *
2733 ha
->nvram_npiv_size
, GFP_KERNEL
);
2734 if (!ha
->npiv_info
) {
2735 qla_printk(KERN_WARNING
, ha
,
2736 "Unable to allocate memory for npiv info\n");
2737 goto fail_npiv_info
;
2740 ha
->npiv_info
= NULL
;
2742 /* Get consistent memory allocated for EX-INIT-CB. */
2743 if (IS_QLA8XXX_TYPE(ha
)) {
2744 ha
->ex_init_cb
= dma_pool_alloc(ha
->s_dma_pool
, GFP_KERNEL
,
2745 &ha
->ex_init_cb_dma
);
2746 if (!ha
->ex_init_cb
)
2747 goto fail_ex_init_cb
;
2750 INIT_LIST_HEAD(&ha
->gbl_dsd_list
);
2752 /* Get consistent memory allocated for Async Port-Database. */
2753 if (!IS_FWI2_CAPABLE(ha
)) {
2754 ha
->async_pd
= dma_pool_alloc(ha
->s_dma_pool
, GFP_KERNEL
,
2760 INIT_LIST_HEAD(&ha
->vp_list
);
2764 dma_pool_free(ha
->s_dma_pool
, ha
->ex_init_cb
, ha
->ex_init_cb_dma
);
2766 kfree(ha
->npiv_info
);
2768 dma_free_coherent(&ha
->pdev
->dev
, ((*rsp
)->length
+ 1) *
2769 sizeof(response_t
), (*rsp
)->ring
, (*rsp
)->dma
);
2770 (*rsp
)->ring
= NULL
;
2775 dma_free_coherent(&ha
->pdev
->dev
, ((*req
)->length
+ 1) *
2776 sizeof(request_t
), (*req
)->ring
, (*req
)->dma
);
2777 (*req
)->ring
= NULL
;
2782 dma_free_coherent(&ha
->pdev
->dev
, sizeof(struct ct_sns_pkt
),
2783 ha
->ct_sns
, ha
->ct_sns_dma
);
2787 dma_pool_free(ha
->s_dma_pool
, ha
->ms_iocb
, ha
->ms_iocb_dma
);
2789 ha
->ms_iocb_dma
= 0;
2791 if (IS_QLA82XX(ha
) || ql2xenabledif
) {
2792 dma_pool_destroy(ha
->fcp_cmnd_dma_pool
);
2793 ha
->fcp_cmnd_dma_pool
= NULL
;
2796 if (IS_QLA82XX(ha
) || ql2xenabledif
) {
2797 dma_pool_destroy(ha
->dl_dma_pool
);
2798 ha
->dl_dma_pool
= NULL
;
2801 dma_pool_destroy(ha
->s_dma_pool
);
2802 ha
->s_dma_pool
= NULL
;
2806 fail_free_ctx_mempool
:
2807 mempool_destroy(ha
->ctx_mempool
);
2808 ha
->ctx_mempool
= NULL
;
2809 fail_free_srb_mempool
:
2810 mempool_destroy(ha
->srb_mempool
);
2811 ha
->srb_mempool
= NULL
;
2813 dma_free_coherent(&ha
->pdev
->dev
, GID_LIST_SIZE
, ha
->gid_list
,
2815 ha
->gid_list
= NULL
;
2816 ha
->gid_list_dma
= 0;
2818 dma_free_coherent(&ha
->pdev
->dev
, ha
->init_cb_size
, ha
->init_cb
,
2821 ha
->init_cb_dma
= 0;
2823 DEBUG(printk("%s: Memory allocation failure\n", __func__
));
2829 * Frees all adapter allocated memory.
2832 * ha = adapter block pointer.
2835 qla2x00_mem_free(struct qla_hw_data
*ha
)
2837 if (ha
->srb_mempool
)
2838 mempool_destroy(ha
->srb_mempool
);
2841 dma_free_coherent(&ha
->pdev
->dev
, FCE_SIZE
, ha
->fce
,
2846 dma_free_coherent(&ha
->pdev
->dev
,
2847 ntohl(ha
->fw_dump
->eft_size
), ha
->eft
, ha
->eft_dma
);
2852 dma_free_coherent(&ha
->pdev
->dev
, DCBX_TLV_DATA_SIZE
,
2853 ha
->dcbx_tlv
, ha
->dcbx_tlv_dma
);
2856 dma_free_coherent(&ha
->pdev
->dev
, XGMAC_DATA_SIZE
,
2857 ha
->xgmac_data
, ha
->xgmac_data_dma
);
2860 dma_free_coherent(&ha
->pdev
->dev
, sizeof(struct sns_cmd_pkt
),
2861 ha
->sns_cmd
, ha
->sns_cmd_dma
);
2864 dma_free_coherent(&ha
->pdev
->dev
, sizeof(struct ct_sns_pkt
),
2865 ha
->ct_sns
, ha
->ct_sns_dma
);
2868 dma_pool_free(ha
->s_dma_pool
, ha
->sfp_data
, ha
->sfp_data_dma
);
2871 dma_pool_free(ha
->s_dma_pool
, ha
->edc_data
, ha
->edc_data_dma
);
2874 dma_pool_free(ha
->s_dma_pool
, ha
->ms_iocb
, ha
->ms_iocb_dma
);
2877 dma_pool_free(ha
->s_dma_pool
,
2878 ha
->ex_init_cb
, ha
->ex_init_cb_dma
);
2881 dma_pool_free(ha
->s_dma_pool
, ha
->async_pd
, ha
->async_pd_dma
);
2884 dma_pool_destroy(ha
->s_dma_pool
);
2887 dma_free_coherent(&ha
->pdev
->dev
, GID_LIST_SIZE
, ha
->gid_list
,
2890 if (IS_QLA82XX(ha
)) {
2891 if (!list_empty(&ha
->gbl_dsd_list
)) {
2892 struct dsd_dma
*dsd_ptr
, *tdsd_ptr
;
2894 /* clean up allocated prev pool */
2895 list_for_each_entry_safe(dsd_ptr
,
2896 tdsd_ptr
, &ha
->gbl_dsd_list
, list
) {
2897 dma_pool_free(ha
->dl_dma_pool
,
2898 dsd_ptr
->dsd_addr
, dsd_ptr
->dsd_list_dma
);
2899 list_del(&dsd_ptr
->list
);
2905 if (ha
->dl_dma_pool
)
2906 dma_pool_destroy(ha
->dl_dma_pool
);
2908 if (ha
->fcp_cmnd_dma_pool
)
2909 dma_pool_destroy(ha
->fcp_cmnd_dma_pool
);
2911 if (ha
->ctx_mempool
)
2912 mempool_destroy(ha
->ctx_mempool
);
2915 dma_free_coherent(&ha
->pdev
->dev
, ha
->init_cb_size
,
2916 ha
->init_cb
, ha
->init_cb_dma
);
2917 vfree(ha
->optrom_buffer
);
2919 kfree(ha
->npiv_info
);
2921 ha
->srb_mempool
= NULL
;
2922 ha
->ctx_mempool
= NULL
;
2926 ha
->sns_cmd_dma
= 0;
2930 ha
->ms_iocb_dma
= 0;
2932 ha
->init_cb_dma
= 0;
2933 ha
->ex_init_cb
= NULL
;
2934 ha
->ex_init_cb_dma
= 0;
2935 ha
->async_pd
= NULL
;
2936 ha
->async_pd_dma
= 0;
2938 ha
->s_dma_pool
= NULL
;
2939 ha
->dl_dma_pool
= NULL
;
2940 ha
->fcp_cmnd_dma_pool
= NULL
;
2942 ha
->gid_list
= NULL
;
2943 ha
->gid_list_dma
= 0;
2947 ha
->fw_dump_reading
= 0;
2950 struct scsi_qla_host
*qla2x00_create_host(struct scsi_host_template
*sht
,
2951 struct qla_hw_data
*ha
)
2953 struct Scsi_Host
*host
;
2954 struct scsi_qla_host
*vha
= NULL
;
2956 host
= scsi_host_alloc(sht
, sizeof(scsi_qla_host_t
));
2959 "qla2xxx: Couldn't allocate host from scsi layer!\n");
2963 /* Clear our data area */
2964 vha
= shost_priv(host
);
2965 memset(vha
, 0, sizeof(scsi_qla_host_t
));
2968 vha
->host_no
= host
->host_no
;
2971 INIT_LIST_HEAD(&vha
->vp_fcports
);
2972 INIT_LIST_HEAD(&vha
->work_list
);
2973 INIT_LIST_HEAD(&vha
->list
);
2975 spin_lock_init(&vha
->work_lock
);
2977 sprintf(vha
->host_str
, "%s_%ld", QLA2XXX_DRIVER_NAME
, vha
->host_no
);
2984 static struct qla_work_evt
*
2985 qla2x00_alloc_work(struct scsi_qla_host
*vha
, enum qla_work_type type
)
2987 struct qla_work_evt
*e
;
2990 QLA_VHA_MARK_BUSY(vha
, bail
);
2994 e
= kzalloc(sizeof(struct qla_work_evt
), GFP_ATOMIC
);
2996 QLA_VHA_MARK_NOT_BUSY(vha
);
3000 INIT_LIST_HEAD(&e
->list
);
3002 e
->flags
= QLA_EVT_FLAG_FREE
;
3007 qla2x00_post_work(struct scsi_qla_host
*vha
, struct qla_work_evt
*e
)
3009 unsigned long flags
;
3011 spin_lock_irqsave(&vha
->work_lock
, flags
);
3012 list_add_tail(&e
->list
, &vha
->work_list
);
3013 spin_unlock_irqrestore(&vha
->work_lock
, flags
);
3014 qla2xxx_wake_dpc(vha
);
3020 qla2x00_post_aen_work(struct scsi_qla_host
*vha
, enum fc_host_event_code code
,
3023 struct qla_work_evt
*e
;
3025 e
= qla2x00_alloc_work(vha
, QLA_EVT_AEN
);
3027 return QLA_FUNCTION_FAILED
;
3029 e
->u
.aen
.code
= code
;
3030 e
->u
.aen
.data
= data
;
3031 return qla2x00_post_work(vha
, e
);
3035 qla2x00_post_idc_ack_work(struct scsi_qla_host
*vha
, uint16_t *mb
)
3037 struct qla_work_evt
*e
;
3039 e
= qla2x00_alloc_work(vha
, QLA_EVT_IDC_ACK
);
3041 return QLA_FUNCTION_FAILED
;
3043 memcpy(e
->u
.idc_ack
.mb
, mb
, QLA_IDC_ACK_REGS
* sizeof(uint16_t));
3044 return qla2x00_post_work(vha
, e
);
3047 #define qla2x00_post_async_work(name, type) \
3048 int qla2x00_post_async_##name##_work( \
3049 struct scsi_qla_host *vha, \
3050 fc_port_t *fcport, uint16_t *data) \
3052 struct qla_work_evt *e; \
3054 e = qla2x00_alloc_work(vha, type); \
3056 return QLA_FUNCTION_FAILED; \
3058 e->u.logio.fcport = fcport; \
3060 e->u.logio.data[0] = data[0]; \
3061 e->u.logio.data[1] = data[1]; \
3063 return qla2x00_post_work(vha, e); \
3066 qla2x00_post_async_work(login
, QLA_EVT_ASYNC_LOGIN
);
3067 qla2x00_post_async_work(login_done
, QLA_EVT_ASYNC_LOGIN_DONE
);
3068 qla2x00_post_async_work(logout
, QLA_EVT_ASYNC_LOGOUT
);
3069 qla2x00_post_async_work(logout_done
, QLA_EVT_ASYNC_LOGOUT_DONE
);
3070 qla2x00_post_async_work(adisc
, QLA_EVT_ASYNC_ADISC
);
3071 qla2x00_post_async_work(adisc_done
, QLA_EVT_ASYNC_ADISC_DONE
);
3074 qla2x00_post_uevent_work(struct scsi_qla_host
*vha
, u32 code
)
3076 struct qla_work_evt
*e
;
3078 e
= qla2x00_alloc_work(vha
, QLA_EVT_UEVENT
);
3080 return QLA_FUNCTION_FAILED
;
3082 e
->u
.uevent
.code
= code
;
3083 return qla2x00_post_work(vha
, e
);
3087 qla2x00_uevent_emit(struct scsi_qla_host
*vha
, u32 code
)
3089 char event_string
[40];
3090 char *envp
[] = { event_string
, NULL
};
3093 case QLA_UEVENT_CODE_FW_DUMP
:
3094 snprintf(event_string
, sizeof(event_string
), "FW_DUMP=%ld",
3101 kobject_uevent_env(&vha
->hw
->pdev
->dev
.kobj
, KOBJ_CHANGE
, envp
);
3105 qla2x00_do_work(struct scsi_qla_host
*vha
)
3107 struct qla_work_evt
*e
, *tmp
;
3108 unsigned long flags
;
3111 spin_lock_irqsave(&vha
->work_lock
, flags
);
3112 list_splice_init(&vha
->work_list
, &work
);
3113 spin_unlock_irqrestore(&vha
->work_lock
, flags
);
3115 list_for_each_entry_safe(e
, tmp
, &work
, list
) {
3116 list_del_init(&e
->list
);
3120 fc_host_post_event(vha
->host
, fc_get_event_number(),
3121 e
->u
.aen
.code
, e
->u
.aen
.data
);
3123 case QLA_EVT_IDC_ACK
:
3124 qla81xx_idc_ack(vha
, e
->u
.idc_ack
.mb
);
3126 case QLA_EVT_ASYNC_LOGIN
:
3127 qla2x00_async_login(vha
, e
->u
.logio
.fcport
,
3130 case QLA_EVT_ASYNC_LOGIN_DONE
:
3131 qla2x00_async_login_done(vha
, e
->u
.logio
.fcport
,
3134 case QLA_EVT_ASYNC_LOGOUT
:
3135 qla2x00_async_logout(vha
, e
->u
.logio
.fcport
);
3137 case QLA_EVT_ASYNC_LOGOUT_DONE
:
3138 qla2x00_async_logout_done(vha
, e
->u
.logio
.fcport
,
3141 case QLA_EVT_ASYNC_ADISC
:
3142 qla2x00_async_adisc(vha
, e
->u
.logio
.fcport
,
3145 case QLA_EVT_ASYNC_ADISC_DONE
:
3146 qla2x00_async_adisc_done(vha
, e
->u
.logio
.fcport
,
3149 case QLA_EVT_UEVENT
:
3150 qla2x00_uevent_emit(vha
, e
->u
.uevent
.code
);
3153 if (e
->flags
& QLA_EVT_FLAG_FREE
)
3156 /* For each work completed decrement vha ref count */
3157 QLA_VHA_MARK_NOT_BUSY(vha
);
3161 /* Relogins all the fcports of a vport
3162 * Context: dpc thread
3164 void qla2x00_relogin(struct scsi_qla_host
*vha
)
3168 uint16_t next_loopid
= 0;
3169 struct qla_hw_data
*ha
= vha
->hw
;
3172 list_for_each_entry(fcport
, &vha
->vp_fcports
, list
) {
3174 * If the port is not ONLINE then try to login
3175 * to it if we haven't run out of retries.
3177 if (atomic_read(&fcport
->state
) != FCS_ONLINE
&&
3178 fcport
->login_retry
&& !(fcport
->flags
& FCF_ASYNC_SENT
)) {
3179 fcport
->login_retry
--;
3180 if (fcport
->flags
& FCF_FABRIC_DEVICE
) {
3181 if (fcport
->flags
& FCF_FCP2_DEVICE
)
3182 ha
->isp_ops
->fabric_logout(vha
,
3184 fcport
->d_id
.b
.domain
,
3185 fcport
->d_id
.b
.area
,
3186 fcport
->d_id
.b
.al_pa
);
3188 if (IS_ALOGIO_CAPABLE(ha
)) {
3189 fcport
->flags
|= FCF_ASYNC_SENT
;
3191 data
[1] = QLA_LOGIO_LOGIN_RETRIED
;
3192 status
= qla2x00_post_async_login_work(
3194 if (status
== QLA_SUCCESS
)
3196 /* Attempt a retry. */
3199 status
= qla2x00_fabric_login(vha
,
3200 fcport
, &next_loopid
);
3202 status
= qla2x00_local_device_login(vha
,
3205 if (status
== QLA_SUCCESS
) {
3206 fcport
->old_loop_id
= fcport
->loop_id
;
3208 DEBUG(printk("scsi(%ld): port login OK: logged "
3209 "in ID 0x%x\n", vha
->host_no
, fcport
->loop_id
));
3211 qla2x00_update_fcport(vha
, fcport
);
3213 } else if (status
== 1) {
3214 set_bit(RELOGIN_NEEDED
, &vha
->dpc_flags
);
3215 /* retry the login again */
3216 DEBUG(printk("scsi(%ld): Retrying"
3217 " %d login again loop_id 0x%x\n",
3218 vha
->host_no
, fcport
->login_retry
,
3221 fcport
->login_retry
= 0;
3224 if (fcport
->login_retry
== 0 && status
!= QLA_SUCCESS
)
3225 fcport
->loop_id
= FC_NO_LOOP_ID
;
3227 if (test_bit(LOOP_RESYNC_NEEDED
, &vha
->dpc_flags
))
3232 /**************************************************************************
3234 * This kernel thread is a task that is schedule by the interrupt handler
3235 * to perform the background processing for interrupts.
3238 * This task always run in the context of a kernel thread. It
3239 * is kick-off by the driver's detect code and starts up
3240 * up one per adapter. It immediately goes to sleep and waits for
3241 * some fibre event. When either the interrupt handler or
3242 * the timer routine detects a event it will one of the task
3243 * bits then wake us up.
3244 **************************************************************************/
3246 qla2x00_do_dpc(void *data
)
3249 scsi_qla_host_t
*base_vha
;
3250 struct qla_hw_data
*ha
;
3252 ha
= (struct qla_hw_data
*)data
;
3253 base_vha
= pci_get_drvdata(ha
->pdev
);
3255 set_user_nice(current
, -20);
3257 while (!kthread_should_stop()) {
3258 DEBUG3(printk("qla2x00: DPC handler sleeping\n"));
3260 set_current_state(TASK_INTERRUPTIBLE
);
3262 __set_current_state(TASK_RUNNING
);
3264 DEBUG3(printk("qla2x00: DPC handler waking up\n"));
3266 /* Initialization not yet finished. Don't do anything yet. */
3267 if (!base_vha
->flags
.init_done
)
3270 if (ha
->flags
.eeh_busy
) {
3271 DEBUG17(qla_printk(KERN_WARNING
, ha
,
3272 "qla2x00_do_dpc: dpc_flags: %lx\n",
3273 base_vha
->dpc_flags
));
3277 DEBUG3(printk("scsi(%ld): DPC handler\n", base_vha
->host_no
));
3281 if (ha
->flags
.mbox_busy
) {
3286 qla2x00_do_work(base_vha
);
3288 if (IS_QLA82XX(ha
)) {
3289 if (test_and_clear_bit(ISP_UNRECOVERABLE
,
3290 &base_vha
->dpc_flags
)) {
3291 qla82xx_idc_lock(ha
);
3292 qla82xx_wr_32(ha
, QLA82XX_CRB_DEV_STATE
,
3293 QLA82XX_DEV_FAILED
);
3294 qla82xx_idc_unlock(ha
);
3295 qla_printk(KERN_INFO
, ha
,
3296 "HW State: FAILED\n");
3297 qla82xx_device_state_handler(base_vha
);
3301 if (test_and_clear_bit(FCOE_CTX_RESET_NEEDED
,
3302 &base_vha
->dpc_flags
)) {
3304 DEBUG(printk(KERN_INFO
3305 "scsi(%ld): dpc: sched "
3306 "qla82xx_fcoe_ctx_reset ha = %p\n",
3307 base_vha
->host_no
, ha
));
3308 if (!(test_and_set_bit(ABORT_ISP_ACTIVE
,
3309 &base_vha
->dpc_flags
))) {
3310 if (qla82xx_fcoe_ctx_reset(base_vha
)) {
3311 /* FCoE-ctx reset failed.
3312 * Escalate to chip-reset
3314 set_bit(ISP_ABORT_NEEDED
,
3315 &base_vha
->dpc_flags
);
3317 clear_bit(ABORT_ISP_ACTIVE
,
3318 &base_vha
->dpc_flags
);
3321 DEBUG(printk("scsi(%ld): dpc:"
3322 " qla82xx_fcoe_ctx_reset end\n",
3323 base_vha
->host_no
));
3327 if (test_and_clear_bit(ISP_ABORT_NEEDED
,
3328 &base_vha
->dpc_flags
)) {
3330 DEBUG(printk("scsi(%ld): dpc: sched "
3331 "qla2x00_abort_isp ha = %p\n",
3332 base_vha
->host_no
, ha
));
3333 if (!(test_and_set_bit(ABORT_ISP_ACTIVE
,
3334 &base_vha
->dpc_flags
))) {
3336 if (ha
->isp_ops
->abort_isp(base_vha
)) {
3337 /* failed. retry later */
3338 set_bit(ISP_ABORT_NEEDED
,
3339 &base_vha
->dpc_flags
);
3341 clear_bit(ABORT_ISP_ACTIVE
,
3342 &base_vha
->dpc_flags
);
3345 DEBUG(printk("scsi(%ld): dpc: qla2x00_abort_isp end\n",
3346 base_vha
->host_no
));
3349 if (test_bit(FCPORT_UPDATE_NEEDED
, &base_vha
->dpc_flags
)) {
3350 qla2x00_update_fcports(base_vha
);
3351 clear_bit(FCPORT_UPDATE_NEEDED
, &base_vha
->dpc_flags
);
3354 if (test_and_clear_bit(RESET_MARKER_NEEDED
,
3355 &base_vha
->dpc_flags
) &&
3356 (!(test_and_set_bit(RESET_ACTIVE
, &base_vha
->dpc_flags
)))) {
3358 DEBUG(printk("scsi(%ld): qla2x00_reset_marker()\n",
3359 base_vha
->host_no
));
3361 qla2x00_rst_aen(base_vha
);
3362 clear_bit(RESET_ACTIVE
, &base_vha
->dpc_flags
);
3365 /* Retry each device up to login retry count */
3366 if ((test_and_clear_bit(RELOGIN_NEEDED
,
3367 &base_vha
->dpc_flags
)) &&
3368 !test_bit(LOOP_RESYNC_NEEDED
, &base_vha
->dpc_flags
) &&
3369 atomic_read(&base_vha
->loop_state
) != LOOP_DOWN
) {
3371 DEBUG(printk("scsi(%ld): qla2x00_port_login()\n",
3372 base_vha
->host_no
));
3373 qla2x00_relogin(base_vha
);
3375 DEBUG(printk("scsi(%ld): qla2x00_port_login - end\n",
3376 base_vha
->host_no
));
3379 if (test_and_clear_bit(LOOP_RESYNC_NEEDED
,
3380 &base_vha
->dpc_flags
)) {
3382 DEBUG(printk("scsi(%ld): qla2x00_loop_resync()\n",
3383 base_vha
->host_no
));
3385 if (!(test_and_set_bit(LOOP_RESYNC_ACTIVE
,
3386 &base_vha
->dpc_flags
))) {
3388 rval
= qla2x00_loop_resync(base_vha
);
3390 clear_bit(LOOP_RESYNC_ACTIVE
,
3391 &base_vha
->dpc_flags
);
3394 DEBUG(printk("scsi(%ld): qla2x00_loop_resync - end\n",
3395 base_vha
->host_no
));
3398 if (test_bit(NPIV_CONFIG_NEEDED
, &base_vha
->dpc_flags
) &&
3399 atomic_read(&base_vha
->loop_state
) == LOOP_READY
) {
3400 clear_bit(NPIV_CONFIG_NEEDED
, &base_vha
->dpc_flags
);
3401 qla2xxx_flash_npiv_conf(base_vha
);
3404 if (!ha
->interrupts_on
)
3405 ha
->isp_ops
->enable_intrs(ha
);
3407 if (test_and_clear_bit(BEACON_BLINK_NEEDED
,
3408 &base_vha
->dpc_flags
))
3409 ha
->isp_ops
->beacon_blink(base_vha
);
3411 qla2x00_do_dpc_all_vps(base_vha
);
3414 } /* End of while(1) */
3416 DEBUG(printk("scsi(%ld): DPC handler exiting\n", base_vha
->host_no
));
3419 * Make sure that nobody tries to wake us up again.
3423 /* Cleanup any residual CTX SRBs. */
3424 qla2x00_abort_all_cmds(base_vha
, DID_NO_CONNECT
<< 16);
3430 qla2xxx_wake_dpc(struct scsi_qla_host
*vha
)
3432 struct qla_hw_data
*ha
= vha
->hw
;
3433 struct task_struct
*t
= ha
->dpc_thread
;
3435 if (!test_bit(UNLOADING
, &vha
->dpc_flags
) && t
)
3441 * Processes asynchronous reset.
3444 * ha = adapter block pointer.
3447 qla2x00_rst_aen(scsi_qla_host_t
*vha
)
3449 if (vha
->flags
.online
&& !vha
->flags
.reset_active
&&
3450 !atomic_read(&vha
->loop_down_timer
) &&
3451 !(test_bit(ABORT_ISP_ACTIVE
, &vha
->dpc_flags
))) {
3453 clear_bit(RESET_MARKER_NEEDED
, &vha
->dpc_flags
);
3456 * Issue marker command only when we are going to start
3459 vha
->marker_needed
= 1;
3460 } while (!atomic_read(&vha
->loop_down_timer
) &&
3461 (test_bit(RESET_MARKER_NEEDED
, &vha
->dpc_flags
)));
3466 qla2x00_sp_free_dma(srb_t
*sp
)
3468 struct scsi_cmnd
*cmd
= sp
->cmd
;
3469 struct qla_hw_data
*ha
= sp
->fcport
->vha
->hw
;
3471 if (sp
->flags
& SRB_DMA_VALID
) {
3472 scsi_dma_unmap(cmd
);
3473 sp
->flags
&= ~SRB_DMA_VALID
;
3476 if (sp
->flags
& SRB_CRC_PROT_DMA_VALID
) {
3477 dma_unmap_sg(&ha
->pdev
->dev
, scsi_prot_sglist(cmd
),
3478 scsi_prot_sg_count(cmd
), cmd
->sc_data_direction
);
3479 sp
->flags
&= ~SRB_CRC_PROT_DMA_VALID
;
3482 if (sp
->flags
& SRB_CRC_CTX_DSD_VALID
) {
3483 /* List assured to be having elements */
3484 qla2x00_clean_dsd_pool(ha
, sp
);
3485 sp
->flags
&= ~SRB_CRC_CTX_DSD_VALID
;
3488 if (sp
->flags
& SRB_CRC_CTX_DMA_VALID
) {
3489 dma_pool_free(ha
->dl_dma_pool
, sp
->ctx
,
3490 ((struct crc_context
*)sp
->ctx
)->crc_ctx_dma
);
3491 sp
->flags
&= ~SRB_CRC_CTX_DMA_VALID
;
3498 qla2x00_sp_final_compl(struct qla_hw_data
*ha
, srb_t
*sp
)
3500 struct scsi_cmnd
*cmd
= sp
->cmd
;
3502 qla2x00_sp_free_dma(sp
);
3504 if (sp
->flags
& SRB_FCP_CMND_DMA_VALID
) {
3505 struct ct6_dsd
*ctx
= sp
->ctx
;
3506 dma_pool_free(ha
->fcp_cmnd_dma_pool
, ctx
->fcp_cmnd
,
3508 list_splice(&ctx
->dsd_list
, &ha
->gbl_dsd_list
);
3509 ha
->gbl_dsd_inuse
-= ctx
->dsd_use_cnt
;
3510 ha
->gbl_dsd_avail
+= ctx
->dsd_use_cnt
;
3511 mempool_free(sp
->ctx
, ha
->ctx_mempool
);
3515 mempool_free(sp
, ha
->srb_mempool
);
3516 cmd
->scsi_done(cmd
);
3520 qla2x00_sp_compl(struct qla_hw_data
*ha
, srb_t
*sp
)
3522 if (atomic_read(&sp
->ref_count
) == 0) {
3523 DEBUG2(qla_printk(KERN_WARNING
, ha
,
3524 "SP reference-count to ZERO -- sp=%p\n", sp
));
3528 if (!atomic_dec_and_test(&sp
->ref_count
))
3530 qla2x00_sp_final_compl(ha
, sp
);
3533 /**************************************************************************
3539 * Context: Interrupt
3540 ***************************************************************************/
3542 qla2x00_timer(scsi_qla_host_t
*vha
)
3544 unsigned long cpu_flags
= 0;
3551 struct qla_hw_data
*ha
= vha
->hw
;
3552 struct req_que
*req
;
3555 qla82xx_watchdog(vha
);
3557 /* Hardware read to raise pending EEH errors during mailbox waits. */
3558 if (!pci_channel_offline(ha
->pdev
))
3559 pci_read_config_word(ha
->pdev
, PCI_VENDOR_ID
, &w
);
3561 * Ports - Port down timer.
3563 * Whenever, a port is in the LOST state we start decrementing its port
3564 * down timer every second until it reaches zero. Once it reaches zero
3565 * the port it marked DEAD.
3568 list_for_each_entry(fcport
, &vha
->vp_fcports
, list
) {
3569 if (fcport
->port_type
!= FCT_TARGET
)
3572 if (atomic_read(&fcport
->state
) == FCS_DEVICE_LOST
) {
3574 if (atomic_read(&fcport
->port_down_timer
) == 0)
3577 if (atomic_dec_and_test(&fcport
->port_down_timer
) != 0)
3578 atomic_set(&fcport
->state
, FCS_DEVICE_DEAD
);
3580 DEBUG(printk("scsi(%ld): fcport-%d - port retry count: "
3583 t
, atomic_read(&fcport
->port_down_timer
)));
3586 } /* End of for fcport */
3589 /* Loop down handler. */
3590 if (atomic_read(&vha
->loop_down_timer
) > 0 &&
3591 !(test_bit(ABORT_ISP_ACTIVE
, &vha
->dpc_flags
))
3592 && vha
->flags
.online
) {
3594 if (atomic_read(&vha
->loop_down_timer
) ==
3595 vha
->loop_down_abort_time
) {
3597 DEBUG(printk("scsi(%ld): Loop Down - aborting the "
3598 "queues before time expire\n",
3601 if (!IS_QLA2100(ha
) && vha
->link_down_timeout
)
3602 atomic_set(&vha
->loop_state
, LOOP_DEAD
);
3605 * Schedule an ISP abort to return any FCP2-device
3608 /* NPIV - scan physical port only */
3610 spin_lock_irqsave(&ha
->hardware_lock
,
3612 req
= ha
->req_q_map
[0];
3614 index
< MAX_OUTSTANDING_COMMANDS
;
3618 sp
= req
->outstanding_cmds
[index
];
3621 if (sp
->ctx
&& !IS_PROT_IO(sp
))
3624 if (!(sfcp
->flags
& FCF_FCP2_DEVICE
))
3627 set_bit(ISP_ABORT_NEEDED
,
3631 spin_unlock_irqrestore(&ha
->hardware_lock
,
3637 /* if the loop has been down for 4 minutes, reinit adapter */
3638 if (atomic_dec_and_test(&vha
->loop_down_timer
) != 0) {
3639 if (!(vha
->device_flags
& DFLG_NO_CABLE
)) {
3640 DEBUG(printk("scsi(%ld): Loop down - "
3643 qla_printk(KERN_WARNING
, ha
,
3644 "Loop down - aborting ISP.\n");
3646 set_bit(ISP_ABORT_NEEDED
, &vha
->dpc_flags
);
3649 DEBUG3(printk("scsi(%ld): Loop Down - seconds remaining %d\n",
3651 atomic_read(&vha
->loop_down_timer
)));
3654 /* Check if beacon LED needs to be blinked */
3655 if (ha
->beacon_blink_led
== 1) {
3656 set_bit(BEACON_BLINK_NEEDED
, &vha
->dpc_flags
);
3660 /* Process any deferred work. */
3661 if (!list_empty(&vha
->work_list
))
3664 /* Schedule the DPC routine if needed */
3665 if ((test_bit(ISP_ABORT_NEEDED
, &vha
->dpc_flags
) ||
3666 test_bit(LOOP_RESYNC_NEEDED
, &vha
->dpc_flags
) ||
3667 test_bit(FCPORT_UPDATE_NEEDED
, &vha
->dpc_flags
) ||
3669 test_bit(RESET_MARKER_NEEDED
, &vha
->dpc_flags
) ||
3670 test_bit(BEACON_BLINK_NEEDED
, &vha
->dpc_flags
) ||
3671 test_bit(ISP_UNRECOVERABLE
, &vha
->dpc_flags
) ||
3672 test_bit(FCOE_CTX_RESET_NEEDED
, &vha
->dpc_flags
) ||
3673 test_bit(VP_DPC_NEEDED
, &vha
->dpc_flags
) ||
3674 test_bit(RELOGIN_NEEDED
, &vha
->dpc_flags
)))
3675 qla2xxx_wake_dpc(vha
);
3677 qla2x00_restart_timer(vha
, WATCH_INTERVAL
);
3680 /* Firmware interface routines. */
3683 #define FW_ISP21XX 0
3684 #define FW_ISP22XX 1
3685 #define FW_ISP2300 2
3686 #define FW_ISP2322 3
3687 #define FW_ISP24XX 4
3688 #define FW_ISP25XX 5
3689 #define FW_ISP81XX 6
3690 #define FW_ISP82XX 7
3692 #define FW_FILE_ISP21XX "ql2100_fw.bin"
3693 #define FW_FILE_ISP22XX "ql2200_fw.bin"
3694 #define FW_FILE_ISP2300 "ql2300_fw.bin"
3695 #define FW_FILE_ISP2322 "ql2322_fw.bin"
3696 #define FW_FILE_ISP24XX "ql2400_fw.bin"
3697 #define FW_FILE_ISP25XX "ql2500_fw.bin"
3698 #define FW_FILE_ISP81XX "ql8100_fw.bin"
3699 #define FW_FILE_ISP82XX "ql8200_fw.bin"
3701 static DEFINE_MUTEX(qla_fw_lock
);
3703 static struct fw_blob qla_fw_blobs
[FW_BLOBS
] = {
3704 { .name
= FW_FILE_ISP21XX
, .segs
= { 0x1000, 0 }, },
3705 { .name
= FW_FILE_ISP22XX
, .segs
= { 0x1000, 0 }, },
3706 { .name
= FW_FILE_ISP2300
, .segs
= { 0x800, 0 }, },
3707 { .name
= FW_FILE_ISP2322
, .segs
= { 0x800, 0x1c000, 0x1e000, 0 }, },
3708 { .name
= FW_FILE_ISP24XX
, },
3709 { .name
= FW_FILE_ISP25XX
, },
3710 { .name
= FW_FILE_ISP81XX
, },
3711 { .name
= FW_FILE_ISP82XX
, },
3715 qla2x00_request_firmware(scsi_qla_host_t
*vha
)
3717 struct qla_hw_data
*ha
= vha
->hw
;
3718 struct fw_blob
*blob
;
3721 if (IS_QLA2100(ha
)) {
3722 blob
= &qla_fw_blobs
[FW_ISP21XX
];
3723 } else if (IS_QLA2200(ha
)) {
3724 blob
= &qla_fw_blobs
[FW_ISP22XX
];
3725 } else if (IS_QLA2300(ha
) || IS_QLA2312(ha
) || IS_QLA6312(ha
)) {
3726 blob
= &qla_fw_blobs
[FW_ISP2300
];
3727 } else if (IS_QLA2322(ha
) || IS_QLA6322(ha
)) {
3728 blob
= &qla_fw_blobs
[FW_ISP2322
];
3729 } else if (IS_QLA24XX_TYPE(ha
)) {
3730 blob
= &qla_fw_blobs
[FW_ISP24XX
];
3731 } else if (IS_QLA25XX(ha
)) {
3732 blob
= &qla_fw_blobs
[FW_ISP25XX
];
3733 } else if (IS_QLA81XX(ha
)) {
3734 blob
= &qla_fw_blobs
[FW_ISP81XX
];
3735 } else if (IS_QLA82XX(ha
)) {
3736 blob
= &qla_fw_blobs
[FW_ISP82XX
];
3739 mutex_lock(&qla_fw_lock
);
3743 if (request_firmware(&blob
->fw
, blob
->name
, &ha
->pdev
->dev
)) {
3744 DEBUG2(printk("scsi(%ld): Failed to load firmware image "
3745 "(%s).\n", vha
->host_no
, blob
->name
));
3752 mutex_unlock(&qla_fw_lock
);
3757 qla2x00_release_firmware(void)
3761 mutex_lock(&qla_fw_lock
);
3762 for (idx
= 0; idx
< FW_BLOBS
; idx
++)
3763 if (qla_fw_blobs
[idx
].fw
)
3764 release_firmware(qla_fw_blobs
[idx
].fw
);
3765 mutex_unlock(&qla_fw_lock
);
3768 static pci_ers_result_t
3769 qla2xxx_pci_error_detected(struct pci_dev
*pdev
, pci_channel_state_t state
)
3771 scsi_qla_host_t
*vha
= pci_get_drvdata(pdev
);
3772 struct qla_hw_data
*ha
= vha
->hw
;
3774 DEBUG2(qla_printk(KERN_WARNING
, ha
, "error_detected:state %x\n",
3778 case pci_channel_io_normal
:
3779 ha
->flags
.eeh_busy
= 0;
3780 return PCI_ERS_RESULT_CAN_RECOVER
;
3781 case pci_channel_io_frozen
:
3782 ha
->flags
.eeh_busy
= 1;
3783 qla2x00_free_irqs(vha
);
3784 pci_disable_device(pdev
);
3785 return PCI_ERS_RESULT_NEED_RESET
;
3786 case pci_channel_io_perm_failure
:
3787 ha
->flags
.pci_channel_io_perm_failure
= 1;
3788 qla2x00_abort_all_cmds(vha
, DID_NO_CONNECT
<< 16);
3789 return PCI_ERS_RESULT_DISCONNECT
;
3791 return PCI_ERS_RESULT_NEED_RESET
;
3794 static pci_ers_result_t
3795 qla2xxx_pci_mmio_enabled(struct pci_dev
*pdev
)
3797 int risc_paused
= 0;
3799 unsigned long flags
;
3800 scsi_qla_host_t
*base_vha
= pci_get_drvdata(pdev
);
3801 struct qla_hw_data
*ha
= base_vha
->hw
;
3802 struct device_reg_2xxx __iomem
*reg
= &ha
->iobase
->isp
;
3803 struct device_reg_24xx __iomem
*reg24
= &ha
->iobase
->isp24
;
3805 spin_lock_irqsave(&ha
->hardware_lock
, flags
);
3806 if (IS_QLA2100(ha
) || IS_QLA2200(ha
)){
3807 stat
= RD_REG_DWORD(®
->hccr
);
3808 if (stat
& HCCR_RISC_PAUSE
)
3810 } else if (IS_QLA23XX(ha
)) {
3811 stat
= RD_REG_DWORD(®
->u
.isp2300
.host_status
);
3812 if (stat
& HSR_RISC_PAUSED
)
3814 } else if (IS_FWI2_CAPABLE(ha
)) {
3815 stat
= RD_REG_DWORD(®24
->host_status
);
3816 if (stat
& HSRX_RISC_PAUSED
)
3819 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
3822 qla_printk(KERN_INFO
, ha
, "RISC paused -- mmio_enabled, "
3823 "Dumping firmware!\n");
3824 ha
->isp_ops
->fw_dump(base_vha
, 0);
3826 return PCI_ERS_RESULT_NEED_RESET
;
3828 return PCI_ERS_RESULT_RECOVERED
;
3831 static pci_ers_result_t
3832 qla2xxx_pci_slot_reset(struct pci_dev
*pdev
)
3834 pci_ers_result_t ret
= PCI_ERS_RESULT_DISCONNECT
;
3835 scsi_qla_host_t
*base_vha
= pci_get_drvdata(pdev
);
3836 struct qla_hw_data
*ha
= base_vha
->hw
;
3837 struct rsp_que
*rsp
;
3838 int rc
, retries
= 10;
3840 DEBUG17(qla_printk(KERN_WARNING
, ha
, "slot_reset\n"));
3842 pdev
->error_state
= pci_channel_io_normal
;
3844 pci_restore_state(pdev
);
3846 /* pci_restore_state() clears the saved_state flag of the device
3847 * save restored state which resets saved_state flag
3849 pci_save_state(pdev
);
3852 rc
= pci_enable_device_mem(pdev
);
3854 rc
= pci_enable_device(pdev
);
3857 qla_printk(KERN_WARNING
, ha
,
3858 "Can't re-enable PCI device after reset.\n");
3862 rsp
= ha
->rsp_q_map
[0];
3863 if (qla2x00_request_irqs(ha
, rsp
))
3866 if (ha
->isp_ops
->pci_config(base_vha
))
3869 while (ha
->flags
.mbox_busy
&& retries
--)
3872 set_bit(ABORT_ISP_ACTIVE
, &base_vha
->dpc_flags
);
3873 if (ha
->isp_ops
->abort_isp(base_vha
) == QLA_SUCCESS
)
3874 ret
= PCI_ERS_RESULT_RECOVERED
;
3875 clear_bit(ABORT_ISP_ACTIVE
, &base_vha
->dpc_flags
);
3878 DEBUG17(qla_printk(KERN_WARNING
, ha
,
3879 "slot_reset-return:ret=%x\n", ret
));
3885 qla2xxx_pci_resume(struct pci_dev
*pdev
)
3887 scsi_qla_host_t
*base_vha
= pci_get_drvdata(pdev
);
3888 struct qla_hw_data
*ha
= base_vha
->hw
;
3891 DEBUG17(qla_printk(KERN_WARNING
, ha
, "pci_resume\n"));
3893 ret
= qla2x00_wait_for_hba_online(base_vha
);
3894 if (ret
!= QLA_SUCCESS
) {
3895 qla_printk(KERN_ERR
, ha
,
3896 "the device failed to resume I/O "
3897 "from slot/link_reset");
3900 pci_cleanup_aer_uncorrect_error_status(pdev
);
3902 ha
->flags
.eeh_busy
= 0;
3905 static struct pci_error_handlers qla2xxx_err_handler
= {
3906 .error_detected
= qla2xxx_pci_error_detected
,
3907 .mmio_enabled
= qla2xxx_pci_mmio_enabled
,
3908 .slot_reset
= qla2xxx_pci_slot_reset
,
3909 .resume
= qla2xxx_pci_resume
,
3912 static struct pci_device_id qla2xxx_pci_tbl
[] = {
3913 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC
, PCI_DEVICE_ID_QLOGIC_ISP2100
) },
3914 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC
, PCI_DEVICE_ID_QLOGIC_ISP2200
) },
3915 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC
, PCI_DEVICE_ID_QLOGIC_ISP2300
) },
3916 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC
, PCI_DEVICE_ID_QLOGIC_ISP2312
) },
3917 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC
, PCI_DEVICE_ID_QLOGIC_ISP2322
) },
3918 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC
, PCI_DEVICE_ID_QLOGIC_ISP6312
) },
3919 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC
, PCI_DEVICE_ID_QLOGIC_ISP6322
) },
3920 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC
, PCI_DEVICE_ID_QLOGIC_ISP2422
) },
3921 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC
, PCI_DEVICE_ID_QLOGIC_ISP2432
) },
3922 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC
, PCI_DEVICE_ID_QLOGIC_ISP8432
) },
3923 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC
, PCI_DEVICE_ID_QLOGIC_ISP5422
) },
3924 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC
, PCI_DEVICE_ID_QLOGIC_ISP5432
) },
3925 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC
, PCI_DEVICE_ID_QLOGIC_ISP2532
) },
3926 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC
, PCI_DEVICE_ID_QLOGIC_ISP8001
) },
3927 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC
, PCI_DEVICE_ID_QLOGIC_ISP8021
) },
3930 MODULE_DEVICE_TABLE(pci
, qla2xxx_pci_tbl
);
3932 static struct pci_driver qla2xxx_pci_driver
= {
3933 .name
= QLA2XXX_DRIVER_NAME
,
3935 .owner
= THIS_MODULE
,
3937 .id_table
= qla2xxx_pci_tbl
,
3938 .probe
= qla2x00_probe_one
,
3939 .remove
= qla2x00_remove_one
,
3940 .err_handler
= &qla2xxx_err_handler
,
3943 static struct file_operations apidev_fops
= {
3944 .owner
= THIS_MODULE
,
3948 * qla2x00_module_init - Module initialization.
3951 qla2x00_module_init(void)
3955 /* Allocate cache for SRBs. */
3956 srb_cachep
= kmem_cache_create("qla2xxx_srbs", sizeof(srb_t
), 0,
3957 SLAB_HWCACHE_ALIGN
, NULL
);
3958 if (srb_cachep
== NULL
) {
3960 "qla2xxx: Unable to allocate SRB cache...Failing load!\n");
3964 /* Derive version string. */
3965 strcpy(qla2x00_version_str
, QLA2XXX_VERSION
);
3966 if (ql2xextended_error_logging
)
3967 strcat(qla2x00_version_str
, "-debug");
3969 qla2xxx_transport_template
=
3970 fc_attach_transport(&qla2xxx_transport_functions
);
3971 if (!qla2xxx_transport_template
) {
3972 kmem_cache_destroy(srb_cachep
);
3976 apidev_major
= register_chrdev(0, QLA2XXX_APIDEV
, &apidev_fops
);
3977 if (apidev_major
< 0) {
3978 printk(KERN_WARNING
"qla2xxx: Unable to register char device "
3979 "%s\n", QLA2XXX_APIDEV
);
3982 qla2xxx_transport_vport_template
=
3983 fc_attach_transport(&qla2xxx_transport_vport_functions
);
3984 if (!qla2xxx_transport_vport_template
) {
3985 kmem_cache_destroy(srb_cachep
);
3986 fc_release_transport(qla2xxx_transport_template
);
3990 printk(KERN_INFO
"QLogic Fibre Channel HBA Driver: %s\n",
3991 qla2x00_version_str
);
3992 ret
= pci_register_driver(&qla2xxx_pci_driver
);
3994 kmem_cache_destroy(srb_cachep
);
3995 fc_release_transport(qla2xxx_transport_template
);
3996 fc_release_transport(qla2xxx_transport_vport_template
);
4002 * qla2x00_module_exit - Module cleanup.
4005 qla2x00_module_exit(void)
4007 unregister_chrdev(apidev_major
, QLA2XXX_APIDEV
);
4008 pci_unregister_driver(&qla2xxx_pci_driver
);
4009 qla2x00_release_firmware();
4010 kmem_cache_destroy(srb_cachep
);
4012 kmem_cache_destroy(ctx_cachep
);
4013 fc_release_transport(qla2xxx_transport_template
);
4014 fc_release_transport(qla2xxx_transport_vport_template
);
4017 module_init(qla2x00_module_init
);
4018 module_exit(qla2x00_module_exit
);
4020 MODULE_AUTHOR("QLogic Corporation");
4021 MODULE_DESCRIPTION("QLogic Fibre Channel HBA Driver");
4022 MODULE_LICENSE("GPL");
4023 MODULE_VERSION(QLA2XXX_VERSION
);
4024 MODULE_FIRMWARE(FW_FILE_ISP21XX
);
4025 MODULE_FIRMWARE(FW_FILE_ISP22XX
);
4026 MODULE_FIRMWARE(FW_FILE_ISP2300
);
4027 MODULE_FIRMWARE(FW_FILE_ISP2322
);
4028 MODULE_FIRMWARE(FW_FILE_ISP24XX
);
4029 MODULE_FIRMWARE(FW_FILE_ISP25XX
);