2 * QLogic Fibre Channel HBA Driver
3 * Copyright (c) 2003-2011 QLogic Corporation
5 * See LICENSE.qla2xxx for copyright and licensing details.
9 #include <linux/moduleparam.h>
10 #include <linux/vmalloc.h>
11 #include <linux/delay.h>
12 #include <linux/kthread.h>
13 #include <linux/mutex.h>
14 #include <linux/kobject.h>
15 #include <linux/slab.h>
17 #include <scsi/scsi_tcq.h>
18 #include <scsi/scsicam.h>
19 #include <scsi/scsi_transport.h>
20 #include <scsi/scsi_transport_fc.h>
25 char qla2x00_version_str
[40];
27 static int apidev_major
;
30 * SRB allocation cache
32 static struct kmem_cache
*srb_cachep
;
35 * CT6 CTX allocation cache
37 static struct kmem_cache
*ctx_cachep
;
39 int ql2xlogintimeout
= 20;
40 module_param(ql2xlogintimeout
, int, S_IRUGO
);
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
);
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
);
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
);
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
);
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
);
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
);
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
);
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
);
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
);
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
);
139 MODULE_PARM_DESC(ql2xetsenable
,
140 "Enables firmware ETS burst."
141 "Default is 0 - skip ETS enablement.");
144 module_param(ql2xdbwr
, int, S_IRUGO
);
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 ql2xtargetreset
= 1;
151 module_param(ql2xtargetreset
, int, S_IRUGO
);
152 MODULE_PARM_DESC(ql2xtargetreset
,
153 "Enable target reset."
154 "Default is 1 - use hw defaults.");
157 module_param(ql2xgffidenable
, int, S_IRUGO
);
158 MODULE_PARM_DESC(ql2xgffidenable
,
159 "Enables GFF_ID checks of port type. "
160 "Default is 0 - Do not use GFF_ID information.");
162 int ql2xasynctmfenable
;
163 module_param(ql2xasynctmfenable
, int, S_IRUGO
);
164 MODULE_PARM_DESC(ql2xasynctmfenable
,
165 "Enables issue of TM IOCBs asynchronously via IOCB mechanism"
166 "Default is 0 - Issue TM IOCBs via mailbox mechanism.");
168 int ql2xdontresethba
;
169 module_param(ql2xdontresethba
, int, S_IRUGO
);
170 MODULE_PARM_DESC(ql2xdontresethba
,
171 "Option to specify reset behaviour\n"
172 " 0 (Default) -- Reset on failure.\n"
173 " 1 -- Do not reset on failure.\n");
175 uint ql2xmaxlun
= MAX_LUNS
;
176 module_param(ql2xmaxlun
, uint
, S_IRUGO
);
177 MODULE_PARM_DESC(ql2xmaxlun
,
178 "Defines the maximum LU number to register with the SCSI "
179 "midlayer. Default is 65535.");
182 * SCSI host template entry points
184 static int qla2xxx_slave_configure(struct scsi_device
* device
);
185 static int qla2xxx_slave_alloc(struct scsi_device
*);
186 static int qla2xxx_scan_finished(struct Scsi_Host
*, unsigned long time
);
187 static void qla2xxx_scan_start(struct Scsi_Host
*);
188 static void qla2xxx_slave_destroy(struct scsi_device
*);
189 static int qla2xxx_queuecommand(struct Scsi_Host
*h
, struct scsi_cmnd
*cmd
);
190 static int qla2xxx_eh_abort(struct scsi_cmnd
*);
191 static int qla2xxx_eh_device_reset(struct scsi_cmnd
*);
192 static int qla2xxx_eh_target_reset(struct scsi_cmnd
*);
193 static int qla2xxx_eh_bus_reset(struct scsi_cmnd
*);
194 static int qla2xxx_eh_host_reset(struct scsi_cmnd
*);
196 static int qla2x00_change_queue_depth(struct scsi_device
*, int, int);
197 static int qla2x00_change_queue_type(struct scsi_device
*, int);
199 struct scsi_host_template qla2xxx_driver_template
= {
200 .module
= THIS_MODULE
,
201 .name
= QLA2XXX_DRIVER_NAME
,
202 .queuecommand
= qla2xxx_queuecommand
,
204 .eh_abort_handler
= qla2xxx_eh_abort
,
205 .eh_device_reset_handler
= qla2xxx_eh_device_reset
,
206 .eh_target_reset_handler
= qla2xxx_eh_target_reset
,
207 .eh_bus_reset_handler
= qla2xxx_eh_bus_reset
,
208 .eh_host_reset_handler
= qla2xxx_eh_host_reset
,
210 .slave_configure
= qla2xxx_slave_configure
,
212 .slave_alloc
= qla2xxx_slave_alloc
,
213 .slave_destroy
= qla2xxx_slave_destroy
,
214 .scan_finished
= qla2xxx_scan_finished
,
215 .scan_start
= qla2xxx_scan_start
,
216 .change_queue_depth
= qla2x00_change_queue_depth
,
217 .change_queue_type
= qla2x00_change_queue_type
,
220 .use_clustering
= ENABLE_CLUSTERING
,
221 .sg_tablesize
= SG_ALL
,
223 .max_sectors
= 0xFFFF,
224 .shost_attrs
= qla2x00_host_attrs
,
227 static struct scsi_transport_template
*qla2xxx_transport_template
= NULL
;
228 struct scsi_transport_template
*qla2xxx_transport_vport_template
= NULL
;
230 /* TODO Convert to inlines
236 qla2x00_start_timer(scsi_qla_host_t
*vha
, void *func
, unsigned long interval
)
238 init_timer(&vha
->timer
);
239 vha
->timer
.expires
= jiffies
+ interval
* HZ
;
240 vha
->timer
.data
= (unsigned long)vha
;
241 vha
->timer
.function
= (void (*)(unsigned long))func
;
242 add_timer(&vha
->timer
);
243 vha
->timer_active
= 1;
247 qla2x00_restart_timer(scsi_qla_host_t
*vha
, unsigned long interval
)
249 /* Currently used for 82XX only. */
250 if (vha
->device_flags
& DFLG_DEV_FAILED
)
253 mod_timer(&vha
->timer
, jiffies
+ interval
* HZ
);
256 static __inline__
void
257 qla2x00_stop_timer(scsi_qla_host_t
*vha
)
259 del_timer_sync(&vha
->timer
);
260 vha
->timer_active
= 0;
263 static int qla2x00_do_dpc(void *data
);
265 static void qla2x00_rst_aen(scsi_qla_host_t
*);
267 static int qla2x00_mem_alloc(struct qla_hw_data
*, uint16_t, uint16_t,
268 struct req_que
**, struct rsp_que
**);
269 static void qla2x00_free_fw_dump(struct qla_hw_data
*);
270 static void qla2x00_mem_free(struct qla_hw_data
*);
271 static void qla2x00_sp_free_dma(srb_t
*);
273 /* -------------------------------------------------------------------------- */
274 static int qla2x00_alloc_queues(struct qla_hw_data
*ha
)
276 ha
->req_q_map
= kzalloc(sizeof(struct req_que
*) * ha
->max_req_queues
,
278 if (!ha
->req_q_map
) {
279 qla_printk(KERN_WARNING
, ha
,
280 "Unable to allocate memory for request queue ptrs\n");
284 ha
->rsp_q_map
= kzalloc(sizeof(struct rsp_que
*) * ha
->max_rsp_queues
,
286 if (!ha
->rsp_q_map
) {
287 qla_printk(KERN_WARNING
, ha
,
288 "Unable to allocate memory for response queue ptrs\n");
291 set_bit(0, ha
->rsp_qid_map
);
292 set_bit(0, ha
->req_qid_map
);
296 kfree(ha
->req_q_map
);
297 ha
->req_q_map
= NULL
;
302 static void qla2x00_free_req_que(struct qla_hw_data
*ha
, struct req_que
*req
)
304 if (req
&& req
->ring
)
305 dma_free_coherent(&ha
->pdev
->dev
,
306 (req
->length
+ 1) * sizeof(request_t
),
307 req
->ring
, req
->dma
);
313 static void qla2x00_free_rsp_que(struct qla_hw_data
*ha
, struct rsp_que
*rsp
)
315 if (rsp
&& rsp
->ring
)
316 dma_free_coherent(&ha
->pdev
->dev
,
317 (rsp
->length
+ 1) * sizeof(response_t
),
318 rsp
->ring
, rsp
->dma
);
324 static void qla2x00_free_queues(struct qla_hw_data
*ha
)
330 for (cnt
= 0; cnt
< ha
->max_req_queues
; cnt
++) {
331 req
= ha
->req_q_map
[cnt
];
332 qla2x00_free_req_que(ha
, req
);
334 kfree(ha
->req_q_map
);
335 ha
->req_q_map
= NULL
;
337 for (cnt
= 0; cnt
< ha
->max_rsp_queues
; cnt
++) {
338 rsp
= ha
->rsp_q_map
[cnt
];
339 qla2x00_free_rsp_que(ha
, rsp
);
341 kfree(ha
->rsp_q_map
);
342 ha
->rsp_q_map
= NULL
;
345 static int qla25xx_setup_mode(struct scsi_qla_host
*vha
)
347 uint16_t options
= 0;
349 struct qla_hw_data
*ha
= vha
->hw
;
351 if (!(ha
->fw_attributes
& BIT_6
)) {
352 qla_printk(KERN_INFO
, ha
,
353 "Firmware is not multi-queue capable\n");
356 if (ql2xmultique_tag
) {
357 /* create a request queue for IO */
359 req
= qla25xx_create_req_que(ha
, options
, 0, 0, -1,
360 QLA_DEFAULT_QUE_QOS
);
362 qla_printk(KERN_WARNING
, ha
,
363 "Can't create request queue\n");
366 ha
->wq
= alloc_workqueue("qla2xxx_wq", WQ_MEM_RECLAIM
, 1);
367 vha
->req
= ha
->req_q_map
[req
];
369 for (ques
= 1; ques
< ha
->max_rsp_queues
; ques
++) {
370 ret
= qla25xx_create_rsp_que(ha
, options
, 0, 0, req
);
372 qla_printk(KERN_WARNING
, ha
,
373 "Response Queue create failed\n");
377 ha
->flags
.cpu_affinity_enabled
= 1;
379 DEBUG2(qla_printk(KERN_INFO
, ha
,
380 "CPU affinity mode enabled, no. of response"
381 " queues:%d, no. of request queues:%d\n",
382 ha
->max_rsp_queues
, ha
->max_req_queues
));
386 qla25xx_delete_queues(vha
);
387 destroy_workqueue(ha
->wq
);
391 kfree(ha
->req_q_map
);
392 kfree(ha
->rsp_q_map
);
393 ha
->max_req_queues
= ha
->max_rsp_queues
= 1;
398 qla2x00_pci_info_str(struct scsi_qla_host
*vha
, char *str
)
400 struct qla_hw_data
*ha
= vha
->hw
;
401 static char *pci_bus_modes
[] = {
402 "33", "66", "100", "133",
407 pci_bus
= (ha
->pci_attr
& (BIT_9
| BIT_10
)) >> 9;
410 strcat(str
, pci_bus_modes
[pci_bus
]);
412 pci_bus
= (ha
->pci_attr
& BIT_8
) >> 8;
414 strcat(str
, pci_bus_modes
[pci_bus
]);
416 strcat(str
, " MHz)");
422 qla24xx_pci_info_str(struct scsi_qla_host
*vha
, char *str
)
424 static char *pci_bus_modes
[] = { "33", "66", "100", "133", };
425 struct qla_hw_data
*ha
= vha
->hw
;
429 pcie_reg
= pci_find_capability(ha
->pdev
, PCI_CAP_ID_EXP
);
432 uint16_t pcie_lstat
, lspeed
, lwidth
;
435 pci_read_config_word(ha
->pdev
, pcie_reg
, &pcie_lstat
);
436 lspeed
= pcie_lstat
& (BIT_0
| BIT_1
| BIT_2
| BIT_3
);
437 lwidth
= (pcie_lstat
&
438 (BIT_4
| BIT_5
| BIT_6
| BIT_7
| BIT_8
| BIT_9
)) >> 4;
440 strcpy(str
, "PCIe (");
442 strcat(str
, "2.5GT/s ");
443 else if (lspeed
== 2)
444 strcat(str
, "5.0GT/s ");
446 strcat(str
, "<unknown> ");
447 snprintf(lwstr
, sizeof(lwstr
), "x%d)", lwidth
);
454 pci_bus
= (ha
->pci_attr
& CSRX_PCIX_BUS_MODE_MASK
) >> 8;
455 if (pci_bus
== 0 || pci_bus
== 8) {
457 strcat(str
, pci_bus_modes
[pci_bus
>> 3]);
461 strcat(str
, "Mode 2");
463 strcat(str
, "Mode 1");
465 strcat(str
, pci_bus_modes
[pci_bus
& ~BIT_2
]);
467 strcat(str
, " MHz)");
473 qla2x00_fw_version_str(struct scsi_qla_host
*vha
, char *str
)
476 struct qla_hw_data
*ha
= vha
->hw
;
478 sprintf(str
, "%d.%02d.%02d ", ha
->fw_major_version
,
479 ha
->fw_minor_version
,
480 ha
->fw_subminor_version
);
482 if (ha
->fw_attributes
& BIT_9
) {
487 switch (ha
->fw_attributes
& 0xFF) {
501 sprintf(un_str
, "(%x)", ha
->fw_attributes
);
505 if (ha
->fw_attributes
& 0x100)
512 qla24xx_fw_version_str(struct scsi_qla_host
*vha
, char *str
)
514 struct qla_hw_data
*ha
= vha
->hw
;
516 sprintf(str
, "%d.%02d.%02d (%x)", ha
->fw_major_version
,
517 ha
->fw_minor_version
, ha
->fw_subminor_version
, ha
->fw_attributes
);
521 static inline srb_t
*
522 qla2x00_get_new_sp(scsi_qla_host_t
*vha
, fc_port_t
*fcport
,
523 struct scsi_cmnd
*cmd
)
526 struct qla_hw_data
*ha
= vha
->hw
;
528 sp
= mempool_alloc(ha
->srb_mempool
, GFP_ATOMIC
);
532 atomic_set(&sp
->ref_count
, 1);
536 CMD_SP(cmd
) = (void *)sp
;
543 qla2xxx_queuecommand(struct Scsi_Host
*host
, struct scsi_cmnd
*cmd
)
545 scsi_qla_host_t
*vha
= shost_priv(host
);
546 fc_port_t
*fcport
= (struct fc_port
*) cmd
->device
->hostdata
;
547 struct fc_rport
*rport
= starget_to_rport(scsi_target(cmd
->device
));
548 struct qla_hw_data
*ha
= vha
->hw
;
549 struct scsi_qla_host
*base_vha
= pci_get_drvdata(ha
->pdev
);
553 if (ha
->flags
.eeh_busy
) {
554 if (ha
->flags
.pci_channel_io_perm_failure
)
555 cmd
->result
= DID_NO_CONNECT
<< 16;
557 cmd
->result
= DID_REQUEUE
<< 16;
558 goto qc24_fail_command
;
561 rval
= fc_remote_port_chkready(rport
);
564 goto qc24_fail_command
;
567 if (!vha
->flags
.difdix_supported
&&
568 scsi_get_prot_op(cmd
) != SCSI_PROT_NORMAL
) {
569 DEBUG2(qla_printk(KERN_ERR
, ha
,
570 "DIF Cap Not Reg, fail DIF capable cmd's:%x\n",
572 cmd
->result
= DID_NO_CONNECT
<< 16;
573 goto qc24_fail_command
;
575 if (atomic_read(&fcport
->state
) != FCS_ONLINE
) {
576 if (atomic_read(&fcport
->state
) == FCS_DEVICE_DEAD
||
577 atomic_read(&base_vha
->loop_state
) == LOOP_DEAD
) {
578 cmd
->result
= DID_NO_CONNECT
<< 16;
579 goto qc24_fail_command
;
581 goto qc24_target_busy
;
584 sp
= qla2x00_get_new_sp(base_vha
, fcport
, cmd
);
588 rval
= ha
->isp_ops
->start_scsi(sp
);
589 if (rval
!= QLA_SUCCESS
)
590 goto qc24_host_busy_free_sp
;
594 qc24_host_busy_free_sp
:
595 qla2x00_sp_free_dma(sp
);
596 mempool_free(sp
, ha
->srb_mempool
);
599 return SCSI_MLQUEUE_HOST_BUSY
;
602 return SCSI_MLQUEUE_TARGET_BUSY
;
611 * qla2x00_eh_wait_on_command
612 * Waits for the command to be returned by the Firmware for some
616 * cmd = Scsi Command to wait on.
623 qla2x00_eh_wait_on_command(struct scsi_cmnd
*cmd
)
625 #define ABORT_POLLING_PERIOD 1000
626 #define ABORT_WAIT_ITER ((10 * 1000) / (ABORT_POLLING_PERIOD))
627 unsigned long wait_iter
= ABORT_WAIT_ITER
;
628 scsi_qla_host_t
*vha
= shost_priv(cmd
->device
->host
);
629 struct qla_hw_data
*ha
= vha
->hw
;
630 int ret
= QLA_SUCCESS
;
632 if (unlikely(pci_channel_offline(ha
->pdev
)) || ha
->flags
.eeh_busy
) {
633 DEBUG17(qla_printk(KERN_WARNING
, ha
, "return:eh_wait\n"));
637 while (CMD_SP(cmd
) && wait_iter
--) {
638 msleep(ABORT_POLLING_PERIOD
);
641 ret
= QLA_FUNCTION_FAILED
;
647 * qla2x00_wait_for_hba_online
648 * Wait till the HBA is online after going through
649 * <= MAX_RETRIES_OF_ISP_ABORT or
650 * finally HBA is disabled ie marked offline
653 * ha - pointer to host adapter structure
656 * Does context switching-Release SPIN_LOCK
657 * (if any) before calling this routine.
660 * Success (Adapter is online) : 0
661 * Failed (Adapter is offline/disabled) : 1
664 qla2x00_wait_for_hba_online(scsi_qla_host_t
*vha
)
667 unsigned long wait_online
;
668 struct qla_hw_data
*ha
= vha
->hw
;
669 scsi_qla_host_t
*base_vha
= pci_get_drvdata(ha
->pdev
);
671 wait_online
= jiffies
+ (MAX_LOOP_TIMEOUT
* HZ
);
672 while (((test_bit(ISP_ABORT_NEEDED
, &base_vha
->dpc_flags
)) ||
673 test_bit(ABORT_ISP_ACTIVE
, &base_vha
->dpc_flags
) ||
674 test_bit(ISP_ABORT_RETRY
, &base_vha
->dpc_flags
) ||
675 ha
->dpc_active
) && time_before(jiffies
, wait_online
)) {
679 if (base_vha
->flags
.online
)
680 return_status
= QLA_SUCCESS
;
682 return_status
= QLA_FUNCTION_FAILED
;
684 return (return_status
);
688 * qla2x00_wait_for_reset_ready
689 * Wait till the HBA is online after going through
690 * <= MAX_RETRIES_OF_ISP_ABORT or
691 * finally HBA is disabled ie marked offline or flash
692 * operations are in progress.
695 * ha - pointer to host adapter structure
698 * Does context switching-Release SPIN_LOCK
699 * (if any) before calling this routine.
702 * Success (Adapter is online/no flash ops) : 0
703 * Failed (Adapter is offline/disabled/flash ops in progress) : 1
706 qla2x00_wait_for_reset_ready(scsi_qla_host_t
*vha
)
709 unsigned long wait_online
;
710 struct qla_hw_data
*ha
= vha
->hw
;
711 scsi_qla_host_t
*base_vha
= pci_get_drvdata(ha
->pdev
);
713 wait_online
= jiffies
+ (MAX_LOOP_TIMEOUT
* HZ
);
714 while (((test_bit(ISP_ABORT_NEEDED
, &base_vha
->dpc_flags
)) ||
715 test_bit(ABORT_ISP_ACTIVE
, &base_vha
->dpc_flags
) ||
716 test_bit(ISP_ABORT_RETRY
, &base_vha
->dpc_flags
) ||
717 ha
->optrom_state
!= QLA_SWAITING
||
718 ha
->dpc_active
) && time_before(jiffies
, wait_online
))
721 if (base_vha
->flags
.online
&& ha
->optrom_state
== QLA_SWAITING
)
722 return_status
= QLA_SUCCESS
;
724 return_status
= QLA_FUNCTION_FAILED
;
726 DEBUG2(printk("%s return_status=%d\n", __func__
, return_status
));
728 return return_status
;
732 qla2x00_wait_for_chip_reset(scsi_qla_host_t
*vha
)
735 unsigned long wait_reset
;
736 struct qla_hw_data
*ha
= vha
->hw
;
737 scsi_qla_host_t
*base_vha
= pci_get_drvdata(ha
->pdev
);
739 wait_reset
= jiffies
+ (MAX_LOOP_TIMEOUT
* HZ
);
740 while (((test_bit(ISP_ABORT_NEEDED
, &base_vha
->dpc_flags
)) ||
741 test_bit(ABORT_ISP_ACTIVE
, &base_vha
->dpc_flags
) ||
742 test_bit(ISP_ABORT_RETRY
, &base_vha
->dpc_flags
) ||
743 ha
->dpc_active
) && time_before(jiffies
, wait_reset
)) {
747 if (!test_bit(ISP_ABORT_NEEDED
, &base_vha
->dpc_flags
) &&
748 ha
->flags
.chip_reset_done
)
751 if (ha
->flags
.chip_reset_done
)
752 return_status
= QLA_SUCCESS
;
754 return_status
= QLA_FUNCTION_FAILED
;
756 return return_status
;
760 * qla2x00_wait_for_loop_ready
761 * Wait for MAX_LOOP_TIMEOUT(5 min) value for loop
762 * to be in LOOP_READY state.
764 * ha - pointer to host adapter structure
767 * Does context switching-Release SPIN_LOCK
768 * (if any) before calling this routine.
772 * Success (LOOP_READY) : 0
773 * Failed (LOOP_NOT_READY) : 1
776 qla2x00_wait_for_loop_ready(scsi_qla_host_t
*vha
)
778 int return_status
= QLA_SUCCESS
;
779 unsigned long loop_timeout
;
780 struct qla_hw_data
*ha
= vha
->hw
;
781 scsi_qla_host_t
*base_vha
= pci_get_drvdata(ha
->pdev
);
783 /* wait for 5 min at the max for loop to be ready */
784 loop_timeout
= jiffies
+ (MAX_LOOP_TIMEOUT
* HZ
);
786 while ((!atomic_read(&base_vha
->loop_down_timer
) &&
787 atomic_read(&base_vha
->loop_state
) == LOOP_DOWN
) ||
788 atomic_read(&base_vha
->loop_state
) != LOOP_READY
) {
789 if (atomic_read(&base_vha
->loop_state
) == LOOP_DEAD
) {
790 return_status
= QLA_FUNCTION_FAILED
;
794 if (time_after_eq(jiffies
, loop_timeout
)) {
795 return_status
= QLA_FUNCTION_FAILED
;
799 return (return_status
);
803 sp_get(struct srb
*sp
)
805 atomic_inc(&sp
->ref_count
);
808 /**************************************************************************
812 * The abort function will abort the specified command.
815 * cmd = Linux SCSI command packet to be aborted.
818 * Either SUCCESS or FAILED.
821 * Only return FAILED if command not returned by firmware.
822 **************************************************************************/
824 qla2xxx_eh_abort(struct scsi_cmnd
*cmd
)
826 scsi_qla_host_t
*vha
= shost_priv(cmd
->device
->host
);
829 unsigned int id
, lun
;
832 struct qla_hw_data
*ha
= vha
->hw
;
837 ret
= fc_block_scsi_eh(cmd
);
842 id
= cmd
->device
->id
;
843 lun
= cmd
->device
->lun
;
845 spin_lock_irqsave(&ha
->hardware_lock
, flags
);
846 sp
= (srb_t
*) CMD_SP(cmd
);
848 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
852 DEBUG2(printk("%s(%ld): aborting sp %p from RISC.",
853 __func__
, vha
->host_no
, sp
));
855 /* Get a reference to the sp and drop the lock.*/
858 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
859 if (ha
->isp_ops
->abort_command(sp
)) {
860 DEBUG2(printk("%s(%ld): abort_command "
861 "mbx failed.\n", __func__
, vha
->host_no
));
864 DEBUG3(printk("%s(%ld): abort_command "
865 "mbx success.\n", __func__
, vha
->host_no
));
868 qla2x00_sp_compl(ha
, sp
);
870 /* Wait for the command to be returned. */
872 if (qla2x00_eh_wait_on_command(cmd
) != QLA_SUCCESS
) {
873 qla_printk(KERN_ERR
, ha
,
874 "scsi(%ld:%d:%d): Abort handler timed out -- %x.\n",
875 vha
->host_no
, id
, lun
, ret
);
880 qla_printk(KERN_INFO
, ha
,
881 "scsi(%ld:%d:%d): Abort command issued -- %d %x.\n",
882 vha
->host_no
, id
, lun
, wait
, ret
);
888 qla2x00_eh_wait_for_pending_commands(scsi_qla_host_t
*vha
, unsigned int t
,
889 unsigned int l
, enum nexus_wait_type type
)
891 int cnt
, match
, status
;
893 struct qla_hw_data
*ha
= vha
->hw
;
897 status
= QLA_SUCCESS
;
899 spin_lock_irqsave(&ha
->hardware_lock
, flags
);
901 for (cnt
= 1; status
== QLA_SUCCESS
&&
902 cnt
< MAX_OUTSTANDING_COMMANDS
; cnt
++) {
903 sp
= req
->outstanding_cmds
[cnt
];
906 if ((sp
->ctx
) && !IS_PROT_IO(sp
))
908 if (vha
->vp_idx
!= sp
->fcport
->vha
->vp_idx
)
916 match
= sp
->cmd
->device
->id
== t
;
919 match
= (sp
->cmd
->device
->id
== t
&&
920 sp
->cmd
->device
->lun
== l
);
926 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
927 status
= qla2x00_eh_wait_on_command(sp
->cmd
);
928 spin_lock_irqsave(&ha
->hardware_lock
, flags
);
930 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
935 static char *reset_errors
[] = {
938 "Task management failed",
939 "Waiting for command completions",
943 __qla2xxx_eh_generic_reset(char *name
, enum nexus_wait_type type
,
944 struct scsi_cmnd
*cmd
, int (*do_reset
)(struct fc_port
*, unsigned int, int))
946 scsi_qla_host_t
*vha
= shost_priv(cmd
->device
->host
);
947 fc_port_t
*fcport
= (struct fc_port
*) cmd
->device
->hostdata
;
953 err
= fc_block_scsi_eh(cmd
);
957 qla_printk(KERN_INFO
, vha
->hw
, "scsi(%ld:%d:%d): %s RESET ISSUED.\n",
958 vha
->host_no
, cmd
->device
->id
, cmd
->device
->lun
, name
);
961 if (qla2x00_wait_for_hba_online(vha
) != QLA_SUCCESS
)
962 goto eh_reset_failed
;
964 if (qla2x00_wait_for_loop_ready(vha
) != QLA_SUCCESS
)
965 goto eh_reset_failed
;
967 if (do_reset(fcport
, cmd
->device
->lun
, cmd
->request
->cpu
+ 1)
969 goto eh_reset_failed
;
971 if (qla2x00_eh_wait_for_pending_commands(vha
, cmd
->device
->id
,
972 cmd
->device
->lun
, type
) != QLA_SUCCESS
)
973 goto eh_reset_failed
;
975 qla_printk(KERN_INFO
, vha
->hw
, "scsi(%ld:%d:%d): %s RESET SUCCEEDED.\n",
976 vha
->host_no
, cmd
->device
->id
, cmd
->device
->lun
, name
);
981 qla_printk(KERN_INFO
, vha
->hw
, "scsi(%ld:%d:%d): %s RESET FAILED: %s.\n"
982 , vha
->host_no
, cmd
->device
->id
, cmd
->device
->lun
, name
,
988 qla2xxx_eh_device_reset(struct scsi_cmnd
*cmd
)
990 scsi_qla_host_t
*vha
= shost_priv(cmd
->device
->host
);
991 struct qla_hw_data
*ha
= vha
->hw
;
993 return __qla2xxx_eh_generic_reset("DEVICE", WAIT_LUN
, cmd
,
994 ha
->isp_ops
->lun_reset
);
998 qla2xxx_eh_target_reset(struct scsi_cmnd
*cmd
)
1000 scsi_qla_host_t
*vha
= shost_priv(cmd
->device
->host
);
1001 struct qla_hw_data
*ha
= vha
->hw
;
1003 return __qla2xxx_eh_generic_reset("TARGET", WAIT_TARGET
, cmd
,
1004 ha
->isp_ops
->target_reset
);
1007 /**************************************************************************
1008 * qla2xxx_eh_bus_reset
1011 * The bus reset function will reset the bus and abort any executing
1015 * cmd = Linux SCSI command packet of the command that cause the
1019 * SUCCESS/FAILURE (defined as macro in scsi.h).
1021 **************************************************************************/
1023 qla2xxx_eh_bus_reset(struct scsi_cmnd
*cmd
)
1025 scsi_qla_host_t
*vha
= shost_priv(cmd
->device
->host
);
1026 fc_port_t
*fcport
= (struct fc_port
*) cmd
->device
->hostdata
;
1028 unsigned int id
, lun
;
1030 id
= cmd
->device
->id
;
1031 lun
= cmd
->device
->lun
;
1036 ret
= fc_block_scsi_eh(cmd
);
1041 qla_printk(KERN_INFO
, vha
->hw
,
1042 "scsi(%ld:%d:%d): BUS RESET ISSUED.\n", vha
->host_no
, id
, lun
);
1044 if (qla2x00_wait_for_hba_online(vha
) != QLA_SUCCESS
) {
1045 DEBUG2(printk("%s failed:board disabled\n",__func__
));
1046 goto eh_bus_reset_done
;
1049 if (qla2x00_wait_for_loop_ready(vha
) == QLA_SUCCESS
) {
1050 if (qla2x00_loop_reset(vha
) == QLA_SUCCESS
)
1054 goto eh_bus_reset_done
;
1056 /* Flush outstanding commands. */
1057 if (qla2x00_eh_wait_for_pending_commands(vha
, 0, 0, WAIT_HOST
) !=
1062 qla_printk(KERN_INFO
, vha
->hw
, "%s: reset %s\n", __func__
,
1063 (ret
== FAILED
) ? "failed" : "succeeded");
1068 /**************************************************************************
1069 * qla2xxx_eh_host_reset
1072 * The reset function will reset the Adapter.
1075 * cmd = Linux SCSI command packet of the command that cause the
1079 * Either SUCCESS or FAILED.
1082 **************************************************************************/
1084 qla2xxx_eh_host_reset(struct scsi_cmnd
*cmd
)
1086 scsi_qla_host_t
*vha
= shost_priv(cmd
->device
->host
);
1087 fc_port_t
*fcport
= (struct fc_port
*) cmd
->device
->hostdata
;
1088 struct qla_hw_data
*ha
= vha
->hw
;
1090 unsigned int id
, lun
;
1091 scsi_qla_host_t
*base_vha
= pci_get_drvdata(ha
->pdev
);
1093 id
= cmd
->device
->id
;
1094 lun
= cmd
->device
->lun
;
1099 ret
= fc_block_scsi_eh(cmd
);
1104 qla_printk(KERN_INFO
, ha
,
1105 "scsi(%ld:%d:%d): ADAPTER RESET ISSUED.\n", vha
->host_no
, id
, lun
);
1107 if (qla2x00_wait_for_reset_ready(vha
) != QLA_SUCCESS
)
1108 goto eh_host_reset_lock
;
1111 * Fixme-may be dpc thread is active and processing
1112 * loop_resync,so wait a while for it to
1113 * be completed and then issue big hammer.Otherwise
1114 * it may cause I/O failure as big hammer marks the
1115 * devices as lost kicking of the port_down_timer
1116 * while dpc is stuck for the mailbox to complete.
1118 qla2x00_wait_for_loop_ready(vha
);
1119 if (vha
!= base_vha
) {
1120 if (qla2x00_vp_abort_isp(vha
))
1121 goto eh_host_reset_lock
;
1123 if (IS_QLA82XX(vha
->hw
)) {
1124 if (!qla82xx_fcoe_ctx_reset(vha
)) {
1125 /* Ctx reset success */
1127 goto eh_host_reset_lock
;
1129 /* fall thru if ctx reset failed */
1132 flush_workqueue(ha
->wq
);
1134 set_bit(ABORT_ISP_ACTIVE
, &base_vha
->dpc_flags
);
1135 if (ha
->isp_ops
->abort_isp(base_vha
)) {
1136 clear_bit(ABORT_ISP_ACTIVE
, &base_vha
->dpc_flags
);
1137 /* failed. schedule dpc to try */
1138 set_bit(ISP_ABORT_NEEDED
, &base_vha
->dpc_flags
);
1140 if (qla2x00_wait_for_hba_online(vha
) != QLA_SUCCESS
)
1141 goto eh_host_reset_lock
;
1143 clear_bit(ABORT_ISP_ACTIVE
, &base_vha
->dpc_flags
);
1146 /* Waiting for command to be returned to OS.*/
1147 if (qla2x00_eh_wait_for_pending_commands(vha
, 0, 0, WAIT_HOST
) ==
1152 qla_printk(KERN_INFO
, ha
, "%s: reset %s\n", __func__
,
1153 (ret
== FAILED
) ? "failed" : "succeeded");
1159 * qla2x00_loop_reset
1163 * ha = adapter block pointer.
1169 qla2x00_loop_reset(scsi_qla_host_t
*vha
)
1172 struct fc_port
*fcport
;
1173 struct qla_hw_data
*ha
= vha
->hw
;
1175 if (ql2xtargetreset
== 1 && ha
->flags
.enable_target_reset
) {
1176 list_for_each_entry(fcport
, &vha
->vp_fcports
, list
) {
1177 if (fcport
->port_type
!= FCT_TARGET
)
1180 ret
= ha
->isp_ops
->target_reset(fcport
, 0, 0);
1181 if (ret
!= QLA_SUCCESS
) {
1182 DEBUG2_3(printk("%s(%ld): bus_reset failed: "
1183 "target_reset=%d d_id=%x.\n", __func__
,
1184 vha
->host_no
, ret
, fcport
->d_id
.b24
));
1189 if (ha
->flags
.enable_lip_full_login
&& !IS_QLA8XXX_TYPE(ha
)) {
1190 ret
= qla2x00_full_login_lip(vha
);
1191 if (ret
!= QLA_SUCCESS
) {
1192 DEBUG2_3(printk("%s(%ld): failed: "
1193 "full_login_lip=%d.\n", __func__
, vha
->host_no
,
1196 atomic_set(&vha
->loop_state
, LOOP_DOWN
);
1197 atomic_set(&vha
->loop_down_timer
, LOOP_DOWN_TIME
);
1198 qla2x00_mark_all_devices_lost(vha
, 0);
1199 qla2x00_wait_for_loop_ready(vha
);
1202 if (ha
->flags
.enable_lip_reset
) {
1203 ret
= qla2x00_lip_reset(vha
);
1204 if (ret
!= QLA_SUCCESS
) {
1205 DEBUG2_3(printk("%s(%ld): failed: "
1206 "lip_reset=%d.\n", __func__
, vha
->host_no
, ret
));
1208 qla2x00_wait_for_loop_ready(vha
);
1211 /* Issue marker command only when we are going to start the I/O */
1212 vha
->marker_needed
= 1;
1218 qla2x00_abort_all_cmds(scsi_qla_host_t
*vha
, int res
)
1221 unsigned long flags
;
1223 struct srb_ctx
*ctx
;
1224 struct qla_hw_data
*ha
= vha
->hw
;
1225 struct req_que
*req
;
1227 spin_lock_irqsave(&ha
->hardware_lock
, flags
);
1228 for (que
= 0; que
< ha
->max_req_queues
; que
++) {
1229 req
= ha
->req_q_map
[que
];
1232 for (cnt
= 1; cnt
< MAX_OUTSTANDING_COMMANDS
; cnt
++) {
1233 sp
= req
->outstanding_cmds
[cnt
];
1235 req
->outstanding_cmds
[cnt
] = NULL
;
1237 (sp
->flags
& SRB_FCP_CMND_DMA_VALID
) ||
1239 sp
->cmd
->result
= res
;
1240 qla2x00_sp_compl(ha
, sp
);
1243 if (ctx
->type
== SRB_LOGIN_CMD
||
1244 ctx
->type
== SRB_LOGOUT_CMD
) {
1245 ctx
->u
.iocb_cmd
->free(sp
);
1247 struct fc_bsg_job
*bsg_job
=
1249 if (bsg_job
->request
->msgcode
1252 bsg_job
->req
->errors
= 0;
1253 bsg_job
->reply
->result
= res
;
1254 bsg_job
->job_done(bsg_job
);
1263 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
1267 qla2xxx_slave_alloc(struct scsi_device
*sdev
)
1269 struct fc_rport
*rport
= starget_to_rport(scsi_target(sdev
));
1271 if (!rport
|| fc_remote_port_chkready(rport
))
1274 sdev
->hostdata
= *(fc_port_t
**)rport
->dd_data
;
1280 qla2xxx_slave_configure(struct scsi_device
*sdev
)
1282 scsi_qla_host_t
*vha
= shost_priv(sdev
->host
);
1283 struct req_que
*req
= vha
->req
;
1285 if (sdev
->tagged_supported
)
1286 scsi_activate_tcq(sdev
, req
->max_q_depth
);
1288 scsi_deactivate_tcq(sdev
, req
->max_q_depth
);
1293 qla2xxx_slave_destroy(struct scsi_device
*sdev
)
1295 sdev
->hostdata
= NULL
;
1298 static void qla2x00_handle_queue_full(struct scsi_device
*sdev
, int qdepth
)
1300 fc_port_t
*fcport
= (struct fc_port
*) sdev
->hostdata
;
1302 if (!scsi_track_queue_full(sdev
, qdepth
))
1305 DEBUG2(qla_printk(KERN_INFO
, fcport
->vha
->hw
,
1306 "scsi(%ld:%d:%d:%d): Queue depth adjusted-down to %d.\n",
1307 fcport
->vha
->host_no
, sdev
->channel
, sdev
->id
, sdev
->lun
,
1308 sdev
->queue_depth
));
1311 static void qla2x00_adjust_sdev_qdepth_up(struct scsi_device
*sdev
, int qdepth
)
1313 fc_port_t
*fcport
= sdev
->hostdata
;
1314 struct scsi_qla_host
*vha
= fcport
->vha
;
1315 struct qla_hw_data
*ha
= vha
->hw
;
1316 struct req_que
*req
= NULL
;
1322 if (req
->max_q_depth
<= sdev
->queue_depth
|| req
->max_q_depth
< qdepth
)
1325 if (sdev
->ordered_tags
)
1326 scsi_adjust_queue_depth(sdev
, MSG_ORDERED_TAG
, qdepth
);
1328 scsi_adjust_queue_depth(sdev
, MSG_SIMPLE_TAG
, qdepth
);
1330 DEBUG2(qla_printk(KERN_INFO
, ha
,
1331 "scsi(%ld:%d:%d:%d): Queue depth adjusted-up to %d.\n",
1332 fcport
->vha
->host_no
, sdev
->channel
, sdev
->id
, sdev
->lun
,
1333 sdev
->queue_depth
));
1337 qla2x00_change_queue_depth(struct scsi_device
*sdev
, int qdepth
, int reason
)
1340 case SCSI_QDEPTH_DEFAULT
:
1341 scsi_adjust_queue_depth(sdev
, scsi_get_tag_type(sdev
), qdepth
);
1343 case SCSI_QDEPTH_QFULL
:
1344 qla2x00_handle_queue_full(sdev
, qdepth
);
1346 case SCSI_QDEPTH_RAMP_UP
:
1347 qla2x00_adjust_sdev_qdepth_up(sdev
, qdepth
);
1353 return sdev
->queue_depth
;
1357 qla2x00_change_queue_type(struct scsi_device
*sdev
, int tag_type
)
1359 if (sdev
->tagged_supported
) {
1360 scsi_set_tag_type(sdev
, tag_type
);
1362 scsi_activate_tcq(sdev
, sdev
->queue_depth
);
1364 scsi_deactivate_tcq(sdev
, sdev
->queue_depth
);
1372 * qla2x00_config_dma_addressing() - Configure OS DMA addressing method.
1375 * At exit, the @ha's flags.enable_64bit_addressing set to indicated
1376 * supported addressing method.
1379 qla2x00_config_dma_addressing(struct qla_hw_data
*ha
)
1381 /* Assume a 32bit DMA mask. */
1382 ha
->flags
.enable_64bit_addressing
= 0;
1384 if (!dma_set_mask(&ha
->pdev
->dev
, DMA_BIT_MASK(64))) {
1385 /* Any upper-dword bits set? */
1386 if (MSD(dma_get_required_mask(&ha
->pdev
->dev
)) &&
1387 !pci_set_consistent_dma_mask(ha
->pdev
, DMA_BIT_MASK(64))) {
1388 /* Ok, a 64bit DMA mask is applicable. */
1389 ha
->flags
.enable_64bit_addressing
= 1;
1390 ha
->isp_ops
->calc_req_entries
= qla2x00_calc_iocbs_64
;
1391 ha
->isp_ops
->build_iocbs
= qla2x00_build_scsi_iocbs_64
;
1396 dma_set_mask(&ha
->pdev
->dev
, DMA_BIT_MASK(32));
1397 pci_set_consistent_dma_mask(ha
->pdev
, DMA_BIT_MASK(32));
1401 qla2x00_enable_intrs(struct qla_hw_data
*ha
)
1403 unsigned long flags
= 0;
1404 struct device_reg_2xxx __iomem
*reg
= &ha
->iobase
->isp
;
1406 spin_lock_irqsave(&ha
->hardware_lock
, flags
);
1407 ha
->interrupts_on
= 1;
1408 /* enable risc and host interrupts */
1409 WRT_REG_WORD(®
->ictrl
, ICR_EN_INT
| ICR_EN_RISC
);
1410 RD_REG_WORD(®
->ictrl
);
1411 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
1416 qla2x00_disable_intrs(struct qla_hw_data
*ha
)
1418 unsigned long flags
= 0;
1419 struct device_reg_2xxx __iomem
*reg
= &ha
->iobase
->isp
;
1421 spin_lock_irqsave(&ha
->hardware_lock
, flags
);
1422 ha
->interrupts_on
= 0;
1423 /* disable risc and host interrupts */
1424 WRT_REG_WORD(®
->ictrl
, 0);
1425 RD_REG_WORD(®
->ictrl
);
1426 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
1430 qla24xx_enable_intrs(struct qla_hw_data
*ha
)
1432 unsigned long flags
= 0;
1433 struct device_reg_24xx __iomem
*reg
= &ha
->iobase
->isp24
;
1435 spin_lock_irqsave(&ha
->hardware_lock
, flags
);
1436 ha
->interrupts_on
= 1;
1437 WRT_REG_DWORD(®
->ictrl
, ICRX_EN_RISC_INT
);
1438 RD_REG_DWORD(®
->ictrl
);
1439 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
1443 qla24xx_disable_intrs(struct qla_hw_data
*ha
)
1445 unsigned long flags
= 0;
1446 struct device_reg_24xx __iomem
*reg
= &ha
->iobase
->isp24
;
1448 if (IS_NOPOLLING_TYPE(ha
))
1450 spin_lock_irqsave(&ha
->hardware_lock
, flags
);
1451 ha
->interrupts_on
= 0;
1452 WRT_REG_DWORD(®
->ictrl
, 0);
1453 RD_REG_DWORD(®
->ictrl
);
1454 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
1457 static struct isp_operations qla2100_isp_ops
= {
1458 .pci_config
= qla2100_pci_config
,
1459 .reset_chip
= qla2x00_reset_chip
,
1460 .chip_diag
= qla2x00_chip_diag
,
1461 .config_rings
= qla2x00_config_rings
,
1462 .reset_adapter
= qla2x00_reset_adapter
,
1463 .nvram_config
= qla2x00_nvram_config
,
1464 .update_fw_options
= qla2x00_update_fw_options
,
1465 .load_risc
= qla2x00_load_risc
,
1466 .pci_info_str
= qla2x00_pci_info_str
,
1467 .fw_version_str
= qla2x00_fw_version_str
,
1468 .intr_handler
= qla2100_intr_handler
,
1469 .enable_intrs
= qla2x00_enable_intrs
,
1470 .disable_intrs
= qla2x00_disable_intrs
,
1471 .abort_command
= qla2x00_abort_command
,
1472 .target_reset
= qla2x00_abort_target
,
1473 .lun_reset
= qla2x00_lun_reset
,
1474 .fabric_login
= qla2x00_login_fabric
,
1475 .fabric_logout
= qla2x00_fabric_logout
,
1476 .calc_req_entries
= qla2x00_calc_iocbs_32
,
1477 .build_iocbs
= qla2x00_build_scsi_iocbs_32
,
1478 .prep_ms_iocb
= qla2x00_prep_ms_iocb
,
1479 .prep_ms_fdmi_iocb
= qla2x00_prep_ms_fdmi_iocb
,
1480 .read_nvram
= qla2x00_read_nvram_data
,
1481 .write_nvram
= qla2x00_write_nvram_data
,
1482 .fw_dump
= qla2100_fw_dump
,
1485 .beacon_blink
= NULL
,
1486 .read_optrom
= qla2x00_read_optrom_data
,
1487 .write_optrom
= qla2x00_write_optrom_data
,
1488 .get_flash_version
= qla2x00_get_flash_version
,
1489 .start_scsi
= qla2x00_start_scsi
,
1490 .abort_isp
= qla2x00_abort_isp
,
1493 static struct isp_operations qla2300_isp_ops
= {
1494 .pci_config
= qla2300_pci_config
,
1495 .reset_chip
= qla2x00_reset_chip
,
1496 .chip_diag
= qla2x00_chip_diag
,
1497 .config_rings
= qla2x00_config_rings
,
1498 .reset_adapter
= qla2x00_reset_adapter
,
1499 .nvram_config
= qla2x00_nvram_config
,
1500 .update_fw_options
= qla2x00_update_fw_options
,
1501 .load_risc
= qla2x00_load_risc
,
1502 .pci_info_str
= qla2x00_pci_info_str
,
1503 .fw_version_str
= qla2x00_fw_version_str
,
1504 .intr_handler
= qla2300_intr_handler
,
1505 .enable_intrs
= qla2x00_enable_intrs
,
1506 .disable_intrs
= qla2x00_disable_intrs
,
1507 .abort_command
= qla2x00_abort_command
,
1508 .target_reset
= qla2x00_abort_target
,
1509 .lun_reset
= qla2x00_lun_reset
,
1510 .fabric_login
= qla2x00_login_fabric
,
1511 .fabric_logout
= qla2x00_fabric_logout
,
1512 .calc_req_entries
= qla2x00_calc_iocbs_32
,
1513 .build_iocbs
= qla2x00_build_scsi_iocbs_32
,
1514 .prep_ms_iocb
= qla2x00_prep_ms_iocb
,
1515 .prep_ms_fdmi_iocb
= qla2x00_prep_ms_fdmi_iocb
,
1516 .read_nvram
= qla2x00_read_nvram_data
,
1517 .write_nvram
= qla2x00_write_nvram_data
,
1518 .fw_dump
= qla2300_fw_dump
,
1519 .beacon_on
= qla2x00_beacon_on
,
1520 .beacon_off
= qla2x00_beacon_off
,
1521 .beacon_blink
= qla2x00_beacon_blink
,
1522 .read_optrom
= qla2x00_read_optrom_data
,
1523 .write_optrom
= qla2x00_write_optrom_data
,
1524 .get_flash_version
= qla2x00_get_flash_version
,
1525 .start_scsi
= qla2x00_start_scsi
,
1526 .abort_isp
= qla2x00_abort_isp
,
1529 static struct isp_operations qla24xx_isp_ops
= {
1530 .pci_config
= qla24xx_pci_config
,
1531 .reset_chip
= qla24xx_reset_chip
,
1532 .chip_diag
= qla24xx_chip_diag
,
1533 .config_rings
= qla24xx_config_rings
,
1534 .reset_adapter
= qla24xx_reset_adapter
,
1535 .nvram_config
= qla24xx_nvram_config
,
1536 .update_fw_options
= qla24xx_update_fw_options
,
1537 .load_risc
= qla24xx_load_risc
,
1538 .pci_info_str
= qla24xx_pci_info_str
,
1539 .fw_version_str
= qla24xx_fw_version_str
,
1540 .intr_handler
= qla24xx_intr_handler
,
1541 .enable_intrs
= qla24xx_enable_intrs
,
1542 .disable_intrs
= qla24xx_disable_intrs
,
1543 .abort_command
= qla24xx_abort_command
,
1544 .target_reset
= qla24xx_abort_target
,
1545 .lun_reset
= qla24xx_lun_reset
,
1546 .fabric_login
= qla24xx_login_fabric
,
1547 .fabric_logout
= qla24xx_fabric_logout
,
1548 .calc_req_entries
= NULL
,
1549 .build_iocbs
= NULL
,
1550 .prep_ms_iocb
= qla24xx_prep_ms_iocb
,
1551 .prep_ms_fdmi_iocb
= qla24xx_prep_ms_fdmi_iocb
,
1552 .read_nvram
= qla24xx_read_nvram_data
,
1553 .write_nvram
= qla24xx_write_nvram_data
,
1554 .fw_dump
= qla24xx_fw_dump
,
1555 .beacon_on
= qla24xx_beacon_on
,
1556 .beacon_off
= qla24xx_beacon_off
,
1557 .beacon_blink
= qla24xx_beacon_blink
,
1558 .read_optrom
= qla24xx_read_optrom_data
,
1559 .write_optrom
= qla24xx_write_optrom_data
,
1560 .get_flash_version
= qla24xx_get_flash_version
,
1561 .start_scsi
= qla24xx_start_scsi
,
1562 .abort_isp
= qla2x00_abort_isp
,
1565 static struct isp_operations qla25xx_isp_ops
= {
1566 .pci_config
= qla25xx_pci_config
,
1567 .reset_chip
= qla24xx_reset_chip
,
1568 .chip_diag
= qla24xx_chip_diag
,
1569 .config_rings
= qla24xx_config_rings
,
1570 .reset_adapter
= qla24xx_reset_adapter
,
1571 .nvram_config
= qla24xx_nvram_config
,
1572 .update_fw_options
= qla24xx_update_fw_options
,
1573 .load_risc
= qla24xx_load_risc
,
1574 .pci_info_str
= qla24xx_pci_info_str
,
1575 .fw_version_str
= qla24xx_fw_version_str
,
1576 .intr_handler
= qla24xx_intr_handler
,
1577 .enable_intrs
= qla24xx_enable_intrs
,
1578 .disable_intrs
= qla24xx_disable_intrs
,
1579 .abort_command
= qla24xx_abort_command
,
1580 .target_reset
= qla24xx_abort_target
,
1581 .lun_reset
= qla24xx_lun_reset
,
1582 .fabric_login
= qla24xx_login_fabric
,
1583 .fabric_logout
= qla24xx_fabric_logout
,
1584 .calc_req_entries
= NULL
,
1585 .build_iocbs
= NULL
,
1586 .prep_ms_iocb
= qla24xx_prep_ms_iocb
,
1587 .prep_ms_fdmi_iocb
= qla24xx_prep_ms_fdmi_iocb
,
1588 .read_nvram
= qla25xx_read_nvram_data
,
1589 .write_nvram
= qla25xx_write_nvram_data
,
1590 .fw_dump
= qla25xx_fw_dump
,
1591 .beacon_on
= qla24xx_beacon_on
,
1592 .beacon_off
= qla24xx_beacon_off
,
1593 .beacon_blink
= qla24xx_beacon_blink
,
1594 .read_optrom
= qla25xx_read_optrom_data
,
1595 .write_optrom
= qla24xx_write_optrom_data
,
1596 .get_flash_version
= qla24xx_get_flash_version
,
1597 .start_scsi
= qla24xx_dif_start_scsi
,
1598 .abort_isp
= qla2x00_abort_isp
,
1601 static struct isp_operations qla81xx_isp_ops
= {
1602 .pci_config
= qla25xx_pci_config
,
1603 .reset_chip
= qla24xx_reset_chip
,
1604 .chip_diag
= qla24xx_chip_diag
,
1605 .config_rings
= qla24xx_config_rings
,
1606 .reset_adapter
= qla24xx_reset_adapter
,
1607 .nvram_config
= qla81xx_nvram_config
,
1608 .update_fw_options
= qla81xx_update_fw_options
,
1609 .load_risc
= qla81xx_load_risc
,
1610 .pci_info_str
= qla24xx_pci_info_str
,
1611 .fw_version_str
= qla24xx_fw_version_str
,
1612 .intr_handler
= qla24xx_intr_handler
,
1613 .enable_intrs
= qla24xx_enable_intrs
,
1614 .disable_intrs
= qla24xx_disable_intrs
,
1615 .abort_command
= qla24xx_abort_command
,
1616 .target_reset
= qla24xx_abort_target
,
1617 .lun_reset
= qla24xx_lun_reset
,
1618 .fabric_login
= qla24xx_login_fabric
,
1619 .fabric_logout
= qla24xx_fabric_logout
,
1620 .calc_req_entries
= NULL
,
1621 .build_iocbs
= NULL
,
1622 .prep_ms_iocb
= qla24xx_prep_ms_iocb
,
1623 .prep_ms_fdmi_iocb
= qla24xx_prep_ms_fdmi_iocb
,
1625 .write_nvram
= NULL
,
1626 .fw_dump
= qla81xx_fw_dump
,
1627 .beacon_on
= qla24xx_beacon_on
,
1628 .beacon_off
= qla24xx_beacon_off
,
1629 .beacon_blink
= qla24xx_beacon_blink
,
1630 .read_optrom
= qla25xx_read_optrom_data
,
1631 .write_optrom
= qla24xx_write_optrom_data
,
1632 .get_flash_version
= qla24xx_get_flash_version
,
1633 .start_scsi
= qla24xx_dif_start_scsi
,
1634 .abort_isp
= qla2x00_abort_isp
,
1637 static struct isp_operations qla82xx_isp_ops
= {
1638 .pci_config
= qla82xx_pci_config
,
1639 .reset_chip
= qla82xx_reset_chip
,
1640 .chip_diag
= qla24xx_chip_diag
,
1641 .config_rings
= qla82xx_config_rings
,
1642 .reset_adapter
= qla24xx_reset_adapter
,
1643 .nvram_config
= qla81xx_nvram_config
,
1644 .update_fw_options
= qla24xx_update_fw_options
,
1645 .load_risc
= qla82xx_load_risc
,
1646 .pci_info_str
= qla82xx_pci_info_str
,
1647 .fw_version_str
= qla24xx_fw_version_str
,
1648 .intr_handler
= qla82xx_intr_handler
,
1649 .enable_intrs
= qla82xx_enable_intrs
,
1650 .disable_intrs
= qla82xx_disable_intrs
,
1651 .abort_command
= qla24xx_abort_command
,
1652 .target_reset
= qla24xx_abort_target
,
1653 .lun_reset
= qla24xx_lun_reset
,
1654 .fabric_login
= qla24xx_login_fabric
,
1655 .fabric_logout
= qla24xx_fabric_logout
,
1656 .calc_req_entries
= NULL
,
1657 .build_iocbs
= NULL
,
1658 .prep_ms_iocb
= qla24xx_prep_ms_iocb
,
1659 .prep_ms_fdmi_iocb
= qla24xx_prep_ms_fdmi_iocb
,
1660 .read_nvram
= qla24xx_read_nvram_data
,
1661 .write_nvram
= qla24xx_write_nvram_data
,
1662 .fw_dump
= qla24xx_fw_dump
,
1663 .beacon_on
= qla24xx_beacon_on
,
1664 .beacon_off
= qla24xx_beacon_off
,
1665 .beacon_blink
= qla24xx_beacon_blink
,
1666 .read_optrom
= qla82xx_read_optrom_data
,
1667 .write_optrom
= qla82xx_write_optrom_data
,
1668 .get_flash_version
= qla24xx_get_flash_version
,
1669 .start_scsi
= qla82xx_start_scsi
,
1670 .abort_isp
= qla82xx_abort_isp
,
1674 qla2x00_set_isp_flags(struct qla_hw_data
*ha
)
1676 ha
->device_type
= DT_EXTENDED_IDS
;
1677 switch (ha
->pdev
->device
) {
1678 case PCI_DEVICE_ID_QLOGIC_ISP2100
:
1679 ha
->device_type
|= DT_ISP2100
;
1680 ha
->device_type
&= ~DT_EXTENDED_IDS
;
1681 ha
->fw_srisc_address
= RISC_START_ADDRESS_2100
;
1683 case PCI_DEVICE_ID_QLOGIC_ISP2200
:
1684 ha
->device_type
|= DT_ISP2200
;
1685 ha
->device_type
&= ~DT_EXTENDED_IDS
;
1686 ha
->fw_srisc_address
= RISC_START_ADDRESS_2100
;
1688 case PCI_DEVICE_ID_QLOGIC_ISP2300
:
1689 ha
->device_type
|= DT_ISP2300
;
1690 ha
->device_type
|= DT_ZIO_SUPPORTED
;
1691 ha
->fw_srisc_address
= RISC_START_ADDRESS_2300
;
1693 case PCI_DEVICE_ID_QLOGIC_ISP2312
:
1694 ha
->device_type
|= DT_ISP2312
;
1695 ha
->device_type
|= DT_ZIO_SUPPORTED
;
1696 ha
->fw_srisc_address
= RISC_START_ADDRESS_2300
;
1698 case PCI_DEVICE_ID_QLOGIC_ISP2322
:
1699 ha
->device_type
|= DT_ISP2322
;
1700 ha
->device_type
|= DT_ZIO_SUPPORTED
;
1701 if (ha
->pdev
->subsystem_vendor
== 0x1028 &&
1702 ha
->pdev
->subsystem_device
== 0x0170)
1703 ha
->device_type
|= DT_OEM_001
;
1704 ha
->fw_srisc_address
= RISC_START_ADDRESS_2300
;
1706 case PCI_DEVICE_ID_QLOGIC_ISP6312
:
1707 ha
->device_type
|= DT_ISP6312
;
1708 ha
->fw_srisc_address
= RISC_START_ADDRESS_2300
;
1710 case PCI_DEVICE_ID_QLOGIC_ISP6322
:
1711 ha
->device_type
|= DT_ISP6322
;
1712 ha
->fw_srisc_address
= RISC_START_ADDRESS_2300
;
1714 case PCI_DEVICE_ID_QLOGIC_ISP2422
:
1715 ha
->device_type
|= DT_ISP2422
;
1716 ha
->device_type
|= DT_ZIO_SUPPORTED
;
1717 ha
->device_type
|= DT_FWI2
;
1718 ha
->device_type
|= DT_IIDMA
;
1719 ha
->fw_srisc_address
= RISC_START_ADDRESS_2400
;
1721 case PCI_DEVICE_ID_QLOGIC_ISP2432
:
1722 ha
->device_type
|= DT_ISP2432
;
1723 ha
->device_type
|= DT_ZIO_SUPPORTED
;
1724 ha
->device_type
|= DT_FWI2
;
1725 ha
->device_type
|= DT_IIDMA
;
1726 ha
->fw_srisc_address
= RISC_START_ADDRESS_2400
;
1728 case PCI_DEVICE_ID_QLOGIC_ISP8432
:
1729 ha
->device_type
|= DT_ISP8432
;
1730 ha
->device_type
|= DT_ZIO_SUPPORTED
;
1731 ha
->device_type
|= DT_FWI2
;
1732 ha
->device_type
|= DT_IIDMA
;
1733 ha
->fw_srisc_address
= RISC_START_ADDRESS_2400
;
1735 case PCI_DEVICE_ID_QLOGIC_ISP5422
:
1736 ha
->device_type
|= DT_ISP5422
;
1737 ha
->device_type
|= DT_FWI2
;
1738 ha
->fw_srisc_address
= RISC_START_ADDRESS_2400
;
1740 case PCI_DEVICE_ID_QLOGIC_ISP5432
:
1741 ha
->device_type
|= DT_ISP5432
;
1742 ha
->device_type
|= DT_FWI2
;
1743 ha
->fw_srisc_address
= RISC_START_ADDRESS_2400
;
1745 case PCI_DEVICE_ID_QLOGIC_ISP2532
:
1746 ha
->device_type
|= DT_ISP2532
;
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_ISP8001
:
1753 ha
->device_type
|= DT_ISP8001
;
1754 ha
->device_type
|= DT_ZIO_SUPPORTED
;
1755 ha
->device_type
|= DT_FWI2
;
1756 ha
->device_type
|= DT_IIDMA
;
1757 ha
->fw_srisc_address
= RISC_START_ADDRESS_2400
;
1759 case PCI_DEVICE_ID_QLOGIC_ISP8021
:
1760 ha
->device_type
|= DT_ISP8021
;
1761 ha
->device_type
|= DT_ZIO_SUPPORTED
;
1762 ha
->device_type
|= DT_FWI2
;
1763 ha
->fw_srisc_address
= RISC_START_ADDRESS_2400
;
1764 /* Initialize 82XX ISP flags */
1765 qla82xx_init_flags(ha
);
1770 ha
->port_no
= !(ha
->portnum
& 1);
1772 /* Get adapter physical port no from interrupt pin register. */
1773 pci_read_config_byte(ha
->pdev
, PCI_INTERRUPT_PIN
, &ha
->port_no
);
1775 if (ha
->port_no
& 1)
1776 ha
->flags
.port0
= 1;
1778 ha
->flags
.port0
= 0;
1782 qla2x00_iospace_config(struct qla_hw_data
*ha
)
1784 resource_size_t pio
;
1789 return qla82xx_iospace_config(ha
);
1791 if (pci_request_selected_regions(ha
->pdev
, ha
->bars
,
1792 QLA2XXX_DRIVER_NAME
)) {
1793 qla_printk(KERN_WARNING
, ha
,
1794 "Failed to reserve PIO/MMIO regions (%s)\n",
1795 pci_name(ha
->pdev
));
1797 goto iospace_error_exit
;
1799 if (!(ha
->bars
& 1))
1802 /* We only need PIO for Flash operations on ISP2312 v2 chips. */
1803 pio
= pci_resource_start(ha
->pdev
, 0);
1804 if (pci_resource_flags(ha
->pdev
, 0) & IORESOURCE_IO
) {
1805 if (pci_resource_len(ha
->pdev
, 0) < MIN_IOBASE_LEN
) {
1806 qla_printk(KERN_WARNING
, ha
,
1807 "Invalid PCI I/O region size (%s)...\n",
1808 pci_name(ha
->pdev
));
1812 qla_printk(KERN_WARNING
, ha
,
1813 "region #0 not a PIO resource (%s)...\n",
1814 pci_name(ha
->pdev
));
1817 ha
->pio_address
= pio
;
1820 /* Use MMIO operations for all accesses. */
1821 if (!(pci_resource_flags(ha
->pdev
, 1) & IORESOURCE_MEM
)) {
1822 qla_printk(KERN_ERR
, ha
,
1823 "region #1 not an MMIO resource (%s), aborting\n",
1824 pci_name(ha
->pdev
));
1825 goto iospace_error_exit
;
1827 if (pci_resource_len(ha
->pdev
, 1) < MIN_IOBASE_LEN
) {
1828 qla_printk(KERN_ERR
, ha
,
1829 "Invalid PCI mem region size (%s), aborting\n",
1830 pci_name(ha
->pdev
));
1831 goto iospace_error_exit
;
1834 ha
->iobase
= ioremap(pci_resource_start(ha
->pdev
, 1), MIN_IOBASE_LEN
);
1836 qla_printk(KERN_ERR
, ha
,
1837 "cannot remap MMIO (%s), aborting\n", pci_name(ha
->pdev
));
1839 goto iospace_error_exit
;
1842 /* Determine queue resources */
1843 ha
->max_req_queues
= ha
->max_rsp_queues
= 1;
1844 if ((ql2xmaxqueues
<= 1 && !ql2xmultique_tag
) ||
1845 (ql2xmaxqueues
> 1 && ql2xmultique_tag
) ||
1846 (!IS_QLA25XX(ha
) && !IS_QLA81XX(ha
)))
1849 ha
->mqiobase
= ioremap(pci_resource_start(ha
->pdev
, 3),
1850 pci_resource_len(ha
->pdev
, 3));
1852 /* Read MSIX vector size of the board */
1853 pci_read_config_word(ha
->pdev
, QLA_PCI_MSIX_CONTROL
, &msix
);
1854 ha
->msix_count
= msix
;
1855 /* Max queues are bounded by available msix vectors */
1856 /* queue 0 uses two msix vectors */
1857 if (ql2xmultique_tag
) {
1858 cpus
= num_online_cpus();
1859 ha
->max_rsp_queues
= (ha
->msix_count
- 1 > cpus
) ?
1860 (cpus
+ 1) : (ha
->msix_count
- 1);
1861 ha
->max_req_queues
= 2;
1862 } else if (ql2xmaxqueues
> 1) {
1863 ha
->max_req_queues
= ql2xmaxqueues
> QLA_MQ_SIZE
?
1864 QLA_MQ_SIZE
: ql2xmaxqueues
;
1865 DEBUG2(qla_printk(KERN_INFO
, ha
, "QoS mode set, max no"
1866 " of request queues:%d\n", ha
->max_req_queues
));
1868 qla_printk(KERN_INFO
, ha
,
1869 "MSI-X vector count: %d\n", msix
);
1871 qla_printk(KERN_INFO
, ha
, "BAR 3 not enabled\n");
1874 ha
->msix_count
= ha
->max_rsp_queues
+ 1;
1882 qla2xxx_scan_start(struct Scsi_Host
*shost
)
1884 scsi_qla_host_t
*vha
= shost_priv(shost
);
1886 if (vha
->hw
->flags
.running_gold_fw
)
1889 set_bit(LOOP_RESYNC_NEEDED
, &vha
->dpc_flags
);
1890 set_bit(LOCAL_LOOP_UPDATE
, &vha
->dpc_flags
);
1891 set_bit(RSCN_UPDATE
, &vha
->dpc_flags
);
1892 set_bit(NPIV_CONFIG_NEEDED
, &vha
->dpc_flags
);
1896 qla2xxx_scan_finished(struct Scsi_Host
*shost
, unsigned long time
)
1898 scsi_qla_host_t
*vha
= shost_priv(shost
);
1902 if (time
> vha
->hw
->loop_reset_delay
* HZ
)
1905 return atomic_read(&vha
->loop_state
) == LOOP_READY
;
1909 * PCI driver interface
1911 static int __devinit
1912 qla2x00_probe_one(struct pci_dev
*pdev
, const struct pci_device_id
*id
)
1915 struct Scsi_Host
*host
;
1916 scsi_qla_host_t
*base_vha
= NULL
;
1917 struct qla_hw_data
*ha
;
1920 struct scsi_host_template
*sht
;
1921 int bars
, max_id
, mem_only
= 0;
1922 uint16_t req_length
= 0, rsp_length
= 0;
1923 struct req_que
*req
= NULL
;
1924 struct rsp_que
*rsp
= NULL
;
1926 bars
= pci_select_bars(pdev
, IORESOURCE_MEM
| IORESOURCE_IO
);
1927 sht
= &qla2xxx_driver_template
;
1928 if (pdev
->device
== PCI_DEVICE_ID_QLOGIC_ISP2422
||
1929 pdev
->device
== PCI_DEVICE_ID_QLOGIC_ISP2432
||
1930 pdev
->device
== PCI_DEVICE_ID_QLOGIC_ISP8432
||
1931 pdev
->device
== PCI_DEVICE_ID_QLOGIC_ISP5422
||
1932 pdev
->device
== PCI_DEVICE_ID_QLOGIC_ISP5432
||
1933 pdev
->device
== PCI_DEVICE_ID_QLOGIC_ISP2532
||
1934 pdev
->device
== PCI_DEVICE_ID_QLOGIC_ISP8001
||
1935 pdev
->device
== PCI_DEVICE_ID_QLOGIC_ISP8021
) {
1936 bars
= pci_select_bars(pdev
, IORESOURCE_MEM
);
1941 if (pci_enable_device_mem(pdev
))
1944 if (pci_enable_device(pdev
))
1948 /* This may fail but that's ok */
1949 pci_enable_pcie_error_reporting(pdev
);
1951 ha
= kzalloc(sizeof(struct qla_hw_data
), GFP_KERNEL
);
1953 DEBUG(printk("Unable to allocate memory for ha\n"));
1958 /* Clear our data area */
1960 ha
->mem_only
= mem_only
;
1961 spin_lock_init(&ha
->hardware_lock
);
1962 spin_lock_init(&ha
->vport_slock
);
1964 /* Set ISP-type information. */
1965 qla2x00_set_isp_flags(ha
);
1967 /* Set EEH reset type to fundamental if required by hba */
1968 if ( IS_QLA24XX(ha
) || IS_QLA25XX(ha
) || IS_QLA81XX(ha
)) {
1969 pdev
->needs_freset
= 1;
1972 /* Configure PCI I/O space */
1973 ret
= qla2x00_iospace_config(ha
);
1975 goto probe_hw_failed
;
1977 qla_printk(KERN_INFO
, ha
,
1978 "Found an ISP%04X, irq %d, iobase 0x%p\n", pdev
->device
, pdev
->irq
,
1981 ha
->prev_topology
= 0;
1982 ha
->init_cb_size
= sizeof(init_cb_t
);
1983 ha
->link_data_rate
= PORT_SPEED_UNKNOWN
;
1984 ha
->optrom_size
= OPTROM_SIZE_2300
;
1986 /* Assign ISP specific operations. */
1987 max_id
= MAX_TARGETS_2200
;
1988 if (IS_QLA2100(ha
)) {
1989 max_id
= MAX_TARGETS_2100
;
1990 ha
->mbx_count
= MAILBOX_REGISTER_COUNT_2100
;
1991 req_length
= REQUEST_ENTRY_CNT_2100
;
1992 rsp_length
= RESPONSE_ENTRY_CNT_2100
;
1993 ha
->max_loop_id
= SNS_LAST_LOOP_ID_2100
;
1994 ha
->gid_list_info_size
= 4;
1995 ha
->flash_conf_off
= ~0;
1996 ha
->flash_data_off
= ~0;
1997 ha
->nvram_conf_off
= ~0;
1998 ha
->nvram_data_off
= ~0;
1999 ha
->isp_ops
= &qla2100_isp_ops
;
2000 } else if (IS_QLA2200(ha
)) {
2001 ha
->mbx_count
= MAILBOX_REGISTER_COUNT
;
2002 req_length
= REQUEST_ENTRY_CNT_2200
;
2003 rsp_length
= RESPONSE_ENTRY_CNT_2100
;
2004 ha
->max_loop_id
= SNS_LAST_LOOP_ID_2100
;
2005 ha
->gid_list_info_size
= 4;
2006 ha
->flash_conf_off
= ~0;
2007 ha
->flash_data_off
= ~0;
2008 ha
->nvram_conf_off
= ~0;
2009 ha
->nvram_data_off
= ~0;
2010 ha
->isp_ops
= &qla2100_isp_ops
;
2011 } else if (IS_QLA23XX(ha
)) {
2012 ha
->mbx_count
= MAILBOX_REGISTER_COUNT
;
2013 req_length
= REQUEST_ENTRY_CNT_2200
;
2014 rsp_length
= RESPONSE_ENTRY_CNT_2300
;
2015 ha
->max_loop_id
= SNS_LAST_LOOP_ID_2300
;
2016 ha
->gid_list_info_size
= 6;
2017 if (IS_QLA2322(ha
) || IS_QLA6322(ha
))
2018 ha
->optrom_size
= OPTROM_SIZE_2322
;
2019 ha
->flash_conf_off
= ~0;
2020 ha
->flash_data_off
= ~0;
2021 ha
->nvram_conf_off
= ~0;
2022 ha
->nvram_data_off
= ~0;
2023 ha
->isp_ops
= &qla2300_isp_ops
;
2024 } else if (IS_QLA24XX_TYPE(ha
)) {
2025 ha
->mbx_count
= MAILBOX_REGISTER_COUNT
;
2026 req_length
= REQUEST_ENTRY_CNT_24XX
;
2027 rsp_length
= RESPONSE_ENTRY_CNT_2300
;
2028 ha
->max_loop_id
= SNS_LAST_LOOP_ID_2300
;
2029 ha
->init_cb_size
= sizeof(struct mid_init_cb_24xx
);
2030 ha
->gid_list_info_size
= 8;
2031 ha
->optrom_size
= OPTROM_SIZE_24XX
;
2032 ha
->nvram_npiv_size
= QLA_MAX_VPORTS_QLA24XX
;
2033 ha
->isp_ops
= &qla24xx_isp_ops
;
2034 ha
->flash_conf_off
= FARX_ACCESS_FLASH_CONF
;
2035 ha
->flash_data_off
= FARX_ACCESS_FLASH_DATA
;
2036 ha
->nvram_conf_off
= FARX_ACCESS_NVRAM_CONF
;
2037 ha
->nvram_data_off
= FARX_ACCESS_NVRAM_DATA
;
2038 } else if (IS_QLA25XX(ha
)) {
2039 ha
->mbx_count
= MAILBOX_REGISTER_COUNT
;
2040 req_length
= REQUEST_ENTRY_CNT_24XX
;
2041 rsp_length
= RESPONSE_ENTRY_CNT_2300
;
2042 ha
->max_loop_id
= SNS_LAST_LOOP_ID_2300
;
2043 ha
->init_cb_size
= sizeof(struct mid_init_cb_24xx
);
2044 ha
->gid_list_info_size
= 8;
2045 ha
->optrom_size
= OPTROM_SIZE_25XX
;
2046 ha
->nvram_npiv_size
= QLA_MAX_VPORTS_QLA25XX
;
2047 ha
->isp_ops
= &qla25xx_isp_ops
;
2048 ha
->flash_conf_off
= FARX_ACCESS_FLASH_CONF
;
2049 ha
->flash_data_off
= FARX_ACCESS_FLASH_DATA
;
2050 ha
->nvram_conf_off
= FARX_ACCESS_NVRAM_CONF
;
2051 ha
->nvram_data_off
= FARX_ACCESS_NVRAM_DATA
;
2052 } else if (IS_QLA81XX(ha
)) {
2053 ha
->mbx_count
= MAILBOX_REGISTER_COUNT
;
2054 req_length
= REQUEST_ENTRY_CNT_24XX
;
2055 rsp_length
= RESPONSE_ENTRY_CNT_2300
;
2056 ha
->max_loop_id
= SNS_LAST_LOOP_ID_2300
;
2057 ha
->init_cb_size
= sizeof(struct mid_init_cb_81xx
);
2058 ha
->gid_list_info_size
= 8;
2059 ha
->optrom_size
= OPTROM_SIZE_81XX
;
2060 ha
->nvram_npiv_size
= QLA_MAX_VPORTS_QLA25XX
;
2061 ha
->isp_ops
= &qla81xx_isp_ops
;
2062 ha
->flash_conf_off
= FARX_ACCESS_FLASH_CONF_81XX
;
2063 ha
->flash_data_off
= FARX_ACCESS_FLASH_DATA_81XX
;
2064 ha
->nvram_conf_off
= ~0;
2065 ha
->nvram_data_off
= ~0;
2066 } else if (IS_QLA82XX(ha
)) {
2067 ha
->mbx_count
= MAILBOX_REGISTER_COUNT
;
2068 req_length
= REQUEST_ENTRY_CNT_82XX
;
2069 rsp_length
= RESPONSE_ENTRY_CNT_82XX
;
2070 ha
->max_loop_id
= SNS_LAST_LOOP_ID_2300
;
2071 ha
->init_cb_size
= sizeof(struct mid_init_cb_81xx
);
2072 ha
->gid_list_info_size
= 8;
2073 ha
->optrom_size
= OPTROM_SIZE_82XX
;
2074 ha
->nvram_npiv_size
= QLA_MAX_VPORTS_QLA25XX
;
2075 ha
->isp_ops
= &qla82xx_isp_ops
;
2076 ha
->flash_conf_off
= FARX_ACCESS_FLASH_CONF
;
2077 ha
->flash_data_off
= FARX_ACCESS_FLASH_DATA
;
2078 ha
->nvram_conf_off
= FARX_ACCESS_NVRAM_CONF
;
2079 ha
->nvram_data_off
= FARX_ACCESS_NVRAM_DATA
;
2082 mutex_init(&ha
->vport_lock
);
2083 init_completion(&ha
->mbx_cmd_comp
);
2084 complete(&ha
->mbx_cmd_comp
);
2085 init_completion(&ha
->mbx_intr_comp
);
2086 init_completion(&ha
->dcbx_comp
);
2088 set_bit(0, (unsigned long *) ha
->vp_idx_map
);
2090 qla2x00_config_dma_addressing(ha
);
2091 ret
= qla2x00_mem_alloc(ha
, req_length
, rsp_length
, &req
, &rsp
);
2093 qla_printk(KERN_WARNING
, ha
,
2094 "[ERROR] Failed to allocate memory for adapter\n");
2096 goto probe_hw_failed
;
2099 req
->max_q_depth
= MAX_Q_DEPTH
;
2100 if (ql2xmaxqdepth
!= 0 && ql2xmaxqdepth
<= 0xffffU
)
2101 req
->max_q_depth
= ql2xmaxqdepth
;
2104 base_vha
= qla2x00_create_host(sht
, ha
);
2106 qla_printk(KERN_WARNING
, ha
,
2107 "[ERROR] Failed to allocate memory for scsi_host\n");
2110 qla2x00_mem_free(ha
);
2111 qla2x00_free_req_que(ha
, req
);
2112 qla2x00_free_rsp_que(ha
, rsp
);
2113 goto probe_hw_failed
;
2116 pci_set_drvdata(pdev
, base_vha
);
2118 host
= base_vha
->host
;
2119 base_vha
->req
= req
;
2120 host
->can_queue
= req
->length
+ 128;
2121 if (IS_QLA2XXX_MIDTYPE(ha
))
2122 base_vha
->mgmt_svr_loop_id
= 10 + base_vha
->vp_idx
;
2124 base_vha
->mgmt_svr_loop_id
= MANAGEMENT_SERVER
+
2127 /* Set the SG table size based on ISP type */
2128 if (!IS_FWI2_CAPABLE(ha
)) {
2130 host
->sg_tablesize
= 32;
2132 if (!IS_QLA82XX(ha
))
2133 host
->sg_tablesize
= QLA_SG_ALL
;
2136 host
->max_id
= max_id
;
2137 host
->this_id
= 255;
2138 host
->cmd_per_lun
= 3;
2139 host
->unique_id
= host
->host_no
;
2140 if ((IS_QLA25XX(ha
) || IS_QLA81XX(ha
)) && ql2xenabledif
)
2141 host
->max_cmd_len
= 32;
2143 host
->max_cmd_len
= MAX_CMDSZ
;
2144 host
->max_channel
= MAX_BUSES
- 1;
2145 host
->max_lun
= ql2xmaxlun
;
2146 host
->transportt
= qla2xxx_transport_template
;
2147 sht
->vendor_id
= (SCSI_NL_VID_TYPE_PCI
| PCI_VENDOR_ID_QLOGIC
);
2149 /* Set up the irqs */
2150 ret
= qla2x00_request_irqs(ha
, rsp
);
2152 goto probe_init_failed
;
2154 pci_save_state(pdev
);
2156 /* Alloc arrays of request and response ring ptrs */
2158 if (!qla2x00_alloc_queues(ha
)) {
2159 qla_printk(KERN_WARNING
, ha
,
2160 "[ERROR] Failed to allocate memory for queue"
2162 goto probe_init_failed
;
2165 ha
->rsp_q_map
[0] = rsp
;
2166 ha
->req_q_map
[0] = req
;
2169 set_bit(0, ha
->req_qid_map
);
2170 set_bit(0, ha
->rsp_qid_map
);
2171 /* FWI2-capable only. */
2172 req
->req_q_in
= &ha
->iobase
->isp24
.req_q_in
;
2173 req
->req_q_out
= &ha
->iobase
->isp24
.req_q_out
;
2174 rsp
->rsp_q_in
= &ha
->iobase
->isp24
.rsp_q_in
;
2175 rsp
->rsp_q_out
= &ha
->iobase
->isp24
.rsp_q_out
;
2177 req
->req_q_in
= &ha
->mqiobase
->isp25mq
.req_q_in
;
2178 req
->req_q_out
= &ha
->mqiobase
->isp25mq
.req_q_out
;
2179 rsp
->rsp_q_in
= &ha
->mqiobase
->isp25mq
.rsp_q_in
;
2180 rsp
->rsp_q_out
= &ha
->mqiobase
->isp25mq
.rsp_q_out
;
2183 if (IS_QLA82XX(ha
)) {
2184 req
->req_q_out
= &ha
->iobase
->isp82
.req_q_out
[0];
2185 rsp
->rsp_q_in
= &ha
->iobase
->isp82
.rsp_q_in
[0];
2186 rsp
->rsp_q_out
= &ha
->iobase
->isp82
.rsp_q_out
[0];
2189 if (qla2x00_initialize_adapter(base_vha
)) {
2190 qla_printk(KERN_WARNING
, ha
,
2191 "Failed to initialize adapter\n");
2193 DEBUG2(printk("scsi(%ld): Failed to initialize adapter - "
2194 "Adapter flags %x.\n",
2195 base_vha
->host_no
, base_vha
->device_flags
));
2197 if (IS_QLA82XX(ha
)) {
2198 qla82xx_idc_lock(ha
);
2199 qla82xx_wr_32(ha
, QLA82XX_CRB_DEV_STATE
,
2200 QLA82XX_DEV_FAILED
);
2201 qla82xx_idc_unlock(ha
);
2202 qla_printk(KERN_INFO
, ha
, "HW State: FAILED\n");
2210 if (qla25xx_setup_mode(base_vha
)) {
2211 qla_printk(KERN_WARNING
, ha
,
2212 "Can't create queues, falling back to single"
2218 if (ha
->flags
.running_gold_fw
)
2222 * Startup the kernel thread for this host adapter
2224 ha
->dpc_thread
= kthread_create(qla2x00_do_dpc
, ha
,
2225 "%s_dpc", base_vha
->host_str
);
2226 if (IS_ERR(ha
->dpc_thread
)) {
2227 qla_printk(KERN_WARNING
, ha
,
2228 "Unable to start DPC thread!\n");
2229 ret
= PTR_ERR(ha
->dpc_thread
);
2234 list_add_tail(&base_vha
->list
, &ha
->vp_list
);
2235 base_vha
->host
->irq
= ha
->pdev
->irq
;
2237 /* Initialized the timer */
2238 qla2x00_start_timer(base_vha
, qla2x00_timer
, WATCH_INTERVAL
);
2240 DEBUG2(printk("DEBUG: detect hba %ld at address = %p\n",
2241 base_vha
->host_no
, ha
));
2243 if ((IS_QLA25XX(ha
) || IS_QLA81XX(ha
)) && ql2xenabledif
) {
2244 if (ha
->fw_attributes
& BIT_4
) {
2245 base_vha
->flags
.difdix_supported
= 1;
2246 DEBUG18(qla_printk(KERN_INFO
, ha
,
2247 "Registering for DIF/DIX type 1 and 3"
2249 scsi_host_set_prot(host
,
2250 SHOST_DIF_TYPE1_PROTECTION
2251 | SHOST_DIF_TYPE2_PROTECTION
2252 | SHOST_DIF_TYPE3_PROTECTION
2253 | SHOST_DIX_TYPE1_PROTECTION
2254 | SHOST_DIX_TYPE2_PROTECTION
2255 | SHOST_DIX_TYPE3_PROTECTION
);
2256 scsi_host_set_guard(host
, SHOST_DIX_GUARD_CRC
);
2258 base_vha
->flags
.difdix_supported
= 0;
2261 ha
->isp_ops
->enable_intrs(ha
);
2263 ret
= scsi_add_host(host
, &pdev
->dev
);
2267 base_vha
->flags
.init_done
= 1;
2268 base_vha
->flags
.online
= 1;
2270 scsi_scan_host(host
);
2272 qla2x00_alloc_sysfs_attr(base_vha
);
2274 qla2x00_init_host_attr(base_vha
);
2276 qla2x00_dfs_setup(base_vha
);
2278 qla_printk(KERN_INFO
, ha
, "\n"
2279 " QLogic Fibre Channel HBA Driver: %s\n"
2281 " ISP%04X: %s @ %s hdma%c, host#=%ld, fw=%s\n",
2282 qla2x00_version_str
, ha
->model_number
,
2283 ha
->model_desc
? ha
->model_desc
: "", pdev
->device
,
2284 ha
->isp_ops
->pci_info_str(base_vha
, pci_info
), pci_name(pdev
),
2285 ha
->flags
.enable_64bit_addressing
? '+' : '-', base_vha
->host_no
,
2286 ha
->isp_ops
->fw_version_str(base_vha
, fw_str
));
2291 qla2x00_free_req_que(ha
, req
);
2292 qla2x00_free_rsp_que(ha
, rsp
);
2293 ha
->max_req_queues
= ha
->max_rsp_queues
= 0;
2296 if (base_vha
->timer_active
)
2297 qla2x00_stop_timer(base_vha
);
2298 base_vha
->flags
.online
= 0;
2299 if (ha
->dpc_thread
) {
2300 struct task_struct
*t
= ha
->dpc_thread
;
2302 ha
->dpc_thread
= NULL
;
2306 qla2x00_free_device(base_vha
);
2308 scsi_host_put(base_vha
->host
);
2311 if (IS_QLA82XX(ha
)) {
2312 qla82xx_idc_lock(ha
);
2313 qla82xx_clear_drv_active(ha
);
2314 qla82xx_idc_unlock(ha
);
2315 iounmap((device_reg_t __iomem
*)ha
->nx_pcibase
);
2317 iounmap((device_reg_t __iomem
*)ha
->nxdb_wr_ptr
);
2320 iounmap(ha
->iobase
);
2322 pci_release_selected_regions(ha
->pdev
, ha
->bars
);
2327 pci_disable_device(pdev
);
2332 qla2x00_shutdown(struct pci_dev
*pdev
)
2334 scsi_qla_host_t
*vha
;
2335 struct qla_hw_data
*ha
;
2337 vha
= pci_get_drvdata(pdev
);
2340 /* Turn-off FCE trace */
2341 if (ha
->flags
.fce_enabled
) {
2342 qla2x00_disable_fce_trace(vha
, NULL
, NULL
);
2343 ha
->flags
.fce_enabled
= 0;
2346 /* Turn-off EFT trace */
2348 qla2x00_disable_eft_trace(vha
);
2350 /* Stop currently executing firmware. */
2351 qla2x00_try_to_stop_firmware(vha
);
2353 /* Turn adapter off line */
2354 vha
->flags
.online
= 0;
2356 /* turn-off interrupts on the card */
2357 if (ha
->interrupts_on
) {
2358 vha
->flags
.init_done
= 0;
2359 ha
->isp_ops
->disable_intrs(ha
);
2362 qla2x00_free_irqs(vha
);
2364 qla2x00_free_fw_dump(ha
);
2368 qla2x00_remove_one(struct pci_dev
*pdev
)
2370 scsi_qla_host_t
*base_vha
, *vha
;
2371 struct qla_hw_data
*ha
;
2372 unsigned long flags
;
2374 base_vha
= pci_get_drvdata(pdev
);
2377 mutex_lock(&ha
->vport_lock
);
2378 while (ha
->cur_vport_count
) {
2379 struct Scsi_Host
*scsi_host
;
2381 spin_lock_irqsave(&ha
->vport_slock
, flags
);
2383 BUG_ON(base_vha
->list
.next
== &ha
->vp_list
);
2384 /* This assumes first entry in ha->vp_list is always base vha */
2385 vha
= list_first_entry(&base_vha
->list
, scsi_qla_host_t
, list
);
2386 scsi_host
= scsi_host_get(vha
->host
);
2388 spin_unlock_irqrestore(&ha
->vport_slock
, flags
);
2389 mutex_unlock(&ha
->vport_lock
);
2391 fc_vport_terminate(vha
->fc_vport
);
2392 scsi_host_put(vha
->host
);
2394 mutex_lock(&ha
->vport_lock
);
2396 mutex_unlock(&ha
->vport_lock
);
2398 set_bit(UNLOADING
, &base_vha
->dpc_flags
);
2400 qla2x00_abort_all_cmds(base_vha
, DID_NO_CONNECT
<< 16);
2402 qla2x00_dfs_remove(base_vha
);
2404 qla84xx_put_chip(base_vha
);
2407 if (base_vha
->timer_active
)
2408 qla2x00_stop_timer(base_vha
);
2410 base_vha
->flags
.online
= 0;
2412 /* Flush the work queue and remove it */
2414 flush_workqueue(ha
->wq
);
2415 destroy_workqueue(ha
->wq
);
2419 /* Kill the kernel thread for this host */
2420 if (ha
->dpc_thread
) {
2421 struct task_struct
*t
= ha
->dpc_thread
;
2424 * qla2xxx_wake_dpc checks for ->dpc_thread
2425 * so we need to zero it out.
2427 ha
->dpc_thread
= NULL
;
2431 qla2x00_free_sysfs_attr(base_vha
);
2433 fc_remove_host(base_vha
->host
);
2435 scsi_remove_host(base_vha
->host
);
2437 qla2x00_free_device(base_vha
);
2439 scsi_host_put(base_vha
->host
);
2441 if (IS_QLA82XX(ha
)) {
2442 qla82xx_idc_lock(ha
);
2443 qla82xx_clear_drv_active(ha
);
2444 qla82xx_idc_unlock(ha
);
2446 iounmap((device_reg_t __iomem
*)ha
->nx_pcibase
);
2448 iounmap((device_reg_t __iomem
*)ha
->nxdb_wr_ptr
);
2451 iounmap(ha
->iobase
);
2454 iounmap(ha
->mqiobase
);
2457 pci_release_selected_regions(ha
->pdev
, ha
->bars
);
2461 pci_disable_pcie_error_reporting(pdev
);
2463 pci_disable_device(pdev
);
2464 pci_set_drvdata(pdev
, NULL
);
2468 qla2x00_free_device(scsi_qla_host_t
*vha
)
2470 struct qla_hw_data
*ha
= vha
->hw
;
2472 qla2x00_abort_all_cmds(vha
, DID_NO_CONNECT
<< 16);
2475 if (vha
->timer_active
)
2476 qla2x00_stop_timer(vha
);
2478 /* Kill the kernel thread for this host */
2479 if (ha
->dpc_thread
) {
2480 struct task_struct
*t
= ha
->dpc_thread
;
2483 * qla2xxx_wake_dpc checks for ->dpc_thread
2484 * so we need to zero it out.
2486 ha
->dpc_thread
= NULL
;
2490 qla25xx_delete_queues(vha
);
2492 if (ha
->flags
.fce_enabled
)
2493 qla2x00_disable_fce_trace(vha
, NULL
, NULL
);
2496 qla2x00_disable_eft_trace(vha
);
2498 /* Stop currently executing firmware. */
2499 qla2x00_try_to_stop_firmware(vha
);
2501 vha
->flags
.online
= 0;
2503 /* turn-off interrupts on the card */
2504 if (ha
->interrupts_on
) {
2505 vha
->flags
.init_done
= 0;
2506 ha
->isp_ops
->disable_intrs(ha
);
2509 qla2x00_free_irqs(vha
);
2511 qla2x00_free_fcports(vha
);
2513 qla2x00_mem_free(ha
);
2515 qla2x00_free_queues(ha
);
2518 void qla2x00_free_fcports(struct scsi_qla_host
*vha
)
2520 fc_port_t
*fcport
, *tfcport
;
2522 list_for_each_entry_safe(fcport
, tfcport
, &vha
->vp_fcports
, list
) {
2523 list_del(&fcport
->list
);
2530 qla2x00_schedule_rport_del(struct scsi_qla_host
*vha
, fc_port_t
*fcport
,
2533 struct fc_rport
*rport
;
2534 scsi_qla_host_t
*base_vha
;
2535 unsigned long flags
;
2540 rport
= fcport
->rport
;
2542 base_vha
= pci_get_drvdata(vha
->hw
->pdev
);
2543 spin_lock_irqsave(vha
->host
->host_lock
, flags
);
2544 fcport
->drport
= rport
;
2545 spin_unlock_irqrestore(vha
->host
->host_lock
, flags
);
2546 set_bit(FCPORT_UPDATE_NEEDED
, &base_vha
->dpc_flags
);
2547 qla2xxx_wake_dpc(base_vha
);
2549 fc_remote_port_delete(rport
);
2553 * qla2x00_mark_device_lost Updates fcport state when device goes offline.
2555 * Input: ha = adapter block pointer. fcport = port structure pointer.
2561 void qla2x00_mark_device_lost(scsi_qla_host_t
*vha
, fc_port_t
*fcport
,
2562 int do_login
, int defer
)
2564 if (atomic_read(&fcport
->state
) == FCS_ONLINE
&&
2565 vha
->vp_idx
== fcport
->vp_idx
) {
2566 qla2x00_set_fcport_state(fcport
, FCS_DEVICE_LOST
);
2567 qla2x00_schedule_rport_del(vha
, fcport
, defer
);
2570 * We may need to retry the login, so don't change the state of the
2571 * port but do the retries.
2573 if (atomic_read(&fcport
->state
) != FCS_DEVICE_DEAD
)
2574 qla2x00_set_fcport_state(fcport
, FCS_DEVICE_LOST
);
2579 if (fcport
->login_retry
== 0) {
2580 fcport
->login_retry
= vha
->hw
->login_retry_count
;
2581 set_bit(RELOGIN_NEEDED
, &vha
->dpc_flags
);
2583 DEBUG(printk("scsi(%ld): Port login retry: "
2584 "%02x%02x%02x%02x%02x%02x%02x%02x, "
2585 "id = 0x%04x retry cnt=%d\n",
2587 fcport
->port_name
[0],
2588 fcport
->port_name
[1],
2589 fcport
->port_name
[2],
2590 fcport
->port_name
[3],
2591 fcport
->port_name
[4],
2592 fcport
->port_name
[5],
2593 fcport
->port_name
[6],
2594 fcport
->port_name
[7],
2596 fcport
->login_retry
));
2601 * qla2x00_mark_all_devices_lost
2602 * Updates fcport state when device goes offline.
2605 * ha = adapter block pointer.
2606 * fcport = port structure pointer.
2614 qla2x00_mark_all_devices_lost(scsi_qla_host_t
*vha
, int defer
)
2618 list_for_each_entry(fcport
, &vha
->vp_fcports
, list
) {
2619 if (vha
->vp_idx
!= 0 && vha
->vp_idx
!= fcport
->vp_idx
)
2623 * No point in marking the device as lost, if the device is
2626 if (atomic_read(&fcport
->state
) == FCS_DEVICE_DEAD
)
2628 if (atomic_read(&fcport
->state
) == FCS_ONLINE
) {
2629 qla2x00_set_fcport_state(fcport
, FCS_DEVICE_LOST
);
2631 qla2x00_schedule_rport_del(vha
, fcport
, defer
);
2632 else if (vha
->vp_idx
== fcport
->vp_idx
)
2633 qla2x00_schedule_rport_del(vha
, fcport
, defer
);
2640 * Allocates adapter memory.
2647 qla2x00_mem_alloc(struct qla_hw_data
*ha
, uint16_t req_len
, uint16_t rsp_len
,
2648 struct req_que
**req
, struct rsp_que
**rsp
)
2652 ha
->init_cb
= dma_alloc_coherent(&ha
->pdev
->dev
, ha
->init_cb_size
,
2653 &ha
->init_cb_dma
, GFP_KERNEL
);
2657 ha
->gid_list
= dma_alloc_coherent(&ha
->pdev
->dev
, GID_LIST_SIZE
,
2658 &ha
->gid_list_dma
, GFP_KERNEL
);
2660 goto fail_free_init_cb
;
2662 ha
->srb_mempool
= mempool_create_slab_pool(SRB_MIN_REQ
, srb_cachep
);
2663 if (!ha
->srb_mempool
)
2664 goto fail_free_gid_list
;
2666 if (IS_QLA82XX(ha
)) {
2667 /* Allocate cache for CT6 Ctx. */
2669 ctx_cachep
= kmem_cache_create("qla2xxx_ctx",
2670 sizeof(struct ct6_dsd
), 0,
2671 SLAB_HWCACHE_ALIGN
, NULL
);
2673 goto fail_free_gid_list
;
2675 ha
->ctx_mempool
= mempool_create_slab_pool(SRB_MIN_REQ
,
2677 if (!ha
->ctx_mempool
)
2678 goto fail_free_srb_mempool
;
2681 /* Get memory for cached NVRAM */
2682 ha
->nvram
= kzalloc(MAX_NVRAM_SIZE
, GFP_KERNEL
);
2684 goto fail_free_ctx_mempool
;
2686 snprintf(name
, sizeof(name
), "%s_%d", QLA2XXX_DRIVER_NAME
,
2688 ha
->s_dma_pool
= dma_pool_create(name
, &ha
->pdev
->dev
,
2689 DMA_POOL_SIZE
, 8, 0);
2690 if (!ha
->s_dma_pool
)
2691 goto fail_free_nvram
;
2693 if (IS_QLA82XX(ha
) || ql2xenabledif
) {
2694 ha
->dl_dma_pool
= dma_pool_create(name
, &ha
->pdev
->dev
,
2695 DSD_LIST_DMA_POOL_SIZE
, 8, 0);
2696 if (!ha
->dl_dma_pool
) {
2697 qla_printk(KERN_WARNING
, ha
,
2698 "Memory Allocation failed - dl_dma_pool\n");
2699 goto fail_s_dma_pool
;
2702 ha
->fcp_cmnd_dma_pool
= dma_pool_create(name
, &ha
->pdev
->dev
,
2703 FCP_CMND_DMA_POOL_SIZE
, 8, 0);
2704 if (!ha
->fcp_cmnd_dma_pool
) {
2705 qla_printk(KERN_WARNING
, ha
,
2706 "Memory Allocation failed - fcp_cmnd_dma_pool\n");
2707 goto fail_dl_dma_pool
;
2711 /* Allocate memory for SNS commands */
2712 if (IS_QLA2100(ha
) || IS_QLA2200(ha
)) {
2713 /* Get consistent memory allocated for SNS commands */
2714 ha
->sns_cmd
= dma_alloc_coherent(&ha
->pdev
->dev
,
2715 sizeof(struct sns_cmd_pkt
), &ha
->sns_cmd_dma
, GFP_KERNEL
);
2719 /* Get consistent memory allocated for MS IOCB */
2720 ha
->ms_iocb
= dma_pool_alloc(ha
->s_dma_pool
, GFP_KERNEL
,
2724 /* Get consistent memory allocated for CT SNS commands */
2725 ha
->ct_sns
= dma_alloc_coherent(&ha
->pdev
->dev
,
2726 sizeof(struct ct_sns_pkt
), &ha
->ct_sns_dma
, GFP_KERNEL
);
2728 goto fail_free_ms_iocb
;
2731 /* Allocate memory for request ring */
2732 *req
= kzalloc(sizeof(struct req_que
), GFP_KERNEL
);
2734 DEBUG(printk("Unable to allocate memory for req\n"));
2737 (*req
)->length
= req_len
;
2738 (*req
)->ring
= dma_alloc_coherent(&ha
->pdev
->dev
,
2739 ((*req
)->length
+ 1) * sizeof(request_t
),
2740 &(*req
)->dma
, GFP_KERNEL
);
2741 if (!(*req
)->ring
) {
2742 DEBUG(printk("Unable to allocate memory for req_ring\n"));
2745 /* Allocate memory for response ring */
2746 *rsp
= kzalloc(sizeof(struct rsp_que
), GFP_KERNEL
);
2748 qla_printk(KERN_WARNING
, ha
,
2749 "Unable to allocate memory for rsp\n");
2753 (*rsp
)->length
= rsp_len
;
2754 (*rsp
)->ring
= dma_alloc_coherent(&ha
->pdev
->dev
,
2755 ((*rsp
)->length
+ 1) * sizeof(response_t
),
2756 &(*rsp
)->dma
, GFP_KERNEL
);
2757 if (!(*rsp
)->ring
) {
2758 qla_printk(KERN_WARNING
, ha
,
2759 "Unable to allocate memory for rsp_ring\n");
2764 /* Allocate memory for NVRAM data for vports */
2765 if (ha
->nvram_npiv_size
) {
2766 ha
->npiv_info
= kzalloc(sizeof(struct qla_npiv_entry
) *
2767 ha
->nvram_npiv_size
, GFP_KERNEL
);
2768 if (!ha
->npiv_info
) {
2769 qla_printk(KERN_WARNING
, ha
,
2770 "Unable to allocate memory for npiv info\n");
2771 goto fail_npiv_info
;
2774 ha
->npiv_info
= NULL
;
2776 /* Get consistent memory allocated for EX-INIT-CB. */
2777 if (IS_QLA8XXX_TYPE(ha
)) {
2778 ha
->ex_init_cb
= dma_pool_alloc(ha
->s_dma_pool
, GFP_KERNEL
,
2779 &ha
->ex_init_cb_dma
);
2780 if (!ha
->ex_init_cb
)
2781 goto fail_ex_init_cb
;
2784 INIT_LIST_HEAD(&ha
->gbl_dsd_list
);
2786 /* Get consistent memory allocated for Async Port-Database. */
2787 if (!IS_FWI2_CAPABLE(ha
)) {
2788 ha
->async_pd
= dma_pool_alloc(ha
->s_dma_pool
, GFP_KERNEL
,
2794 INIT_LIST_HEAD(&ha
->vp_list
);
2798 dma_pool_free(ha
->s_dma_pool
, ha
->ex_init_cb
, ha
->ex_init_cb_dma
);
2800 kfree(ha
->npiv_info
);
2802 dma_free_coherent(&ha
->pdev
->dev
, ((*rsp
)->length
+ 1) *
2803 sizeof(response_t
), (*rsp
)->ring
, (*rsp
)->dma
);
2804 (*rsp
)->ring
= NULL
;
2809 dma_free_coherent(&ha
->pdev
->dev
, ((*req
)->length
+ 1) *
2810 sizeof(request_t
), (*req
)->ring
, (*req
)->dma
);
2811 (*req
)->ring
= NULL
;
2816 dma_free_coherent(&ha
->pdev
->dev
, sizeof(struct ct_sns_pkt
),
2817 ha
->ct_sns
, ha
->ct_sns_dma
);
2821 dma_pool_free(ha
->s_dma_pool
, ha
->ms_iocb
, ha
->ms_iocb_dma
);
2823 ha
->ms_iocb_dma
= 0;
2825 if (IS_QLA82XX(ha
) || ql2xenabledif
) {
2826 dma_pool_destroy(ha
->fcp_cmnd_dma_pool
);
2827 ha
->fcp_cmnd_dma_pool
= NULL
;
2830 if (IS_QLA82XX(ha
) || ql2xenabledif
) {
2831 dma_pool_destroy(ha
->dl_dma_pool
);
2832 ha
->dl_dma_pool
= NULL
;
2835 dma_pool_destroy(ha
->s_dma_pool
);
2836 ha
->s_dma_pool
= NULL
;
2840 fail_free_ctx_mempool
:
2841 mempool_destroy(ha
->ctx_mempool
);
2842 ha
->ctx_mempool
= NULL
;
2843 fail_free_srb_mempool
:
2844 mempool_destroy(ha
->srb_mempool
);
2845 ha
->srb_mempool
= NULL
;
2847 dma_free_coherent(&ha
->pdev
->dev
, GID_LIST_SIZE
, ha
->gid_list
,
2849 ha
->gid_list
= NULL
;
2850 ha
->gid_list_dma
= 0;
2852 dma_free_coherent(&ha
->pdev
->dev
, ha
->init_cb_size
, ha
->init_cb
,
2855 ha
->init_cb_dma
= 0;
2857 DEBUG(printk("%s: Memory allocation failure\n", __func__
));
2862 * qla2x00_free_fw_dump
2863 * Frees fw dump stuff.
2866 * ha = adapter block pointer.
2869 qla2x00_free_fw_dump(struct qla_hw_data
*ha
)
2872 dma_free_coherent(&ha
->pdev
->dev
, FCE_SIZE
, ha
->fce
,
2877 dma_free_coherent(&ha
->pdev
->dev
,
2878 ntohl(ha
->fw_dump
->eft_size
), ha
->eft
, ha
->eft_dma
);
2887 ha
->fw_dump_reading
= 0;
2892 * Frees all adapter allocated memory.
2895 * ha = adapter block pointer.
2898 qla2x00_mem_free(struct qla_hw_data
*ha
)
2900 qla2x00_free_fw_dump(ha
);
2902 if (ha
->srb_mempool
)
2903 mempool_destroy(ha
->srb_mempool
);
2906 dma_free_coherent(&ha
->pdev
->dev
, DCBX_TLV_DATA_SIZE
,
2907 ha
->dcbx_tlv
, ha
->dcbx_tlv_dma
);
2910 dma_free_coherent(&ha
->pdev
->dev
, XGMAC_DATA_SIZE
,
2911 ha
->xgmac_data
, ha
->xgmac_data_dma
);
2914 dma_free_coherent(&ha
->pdev
->dev
, sizeof(struct sns_cmd_pkt
),
2915 ha
->sns_cmd
, ha
->sns_cmd_dma
);
2918 dma_free_coherent(&ha
->pdev
->dev
, sizeof(struct ct_sns_pkt
),
2919 ha
->ct_sns
, ha
->ct_sns_dma
);
2922 dma_pool_free(ha
->s_dma_pool
, ha
->sfp_data
, ha
->sfp_data_dma
);
2925 dma_pool_free(ha
->s_dma_pool
, ha
->edc_data
, ha
->edc_data_dma
);
2928 dma_pool_free(ha
->s_dma_pool
, ha
->ms_iocb
, ha
->ms_iocb_dma
);
2931 dma_pool_free(ha
->s_dma_pool
,
2932 ha
->ex_init_cb
, ha
->ex_init_cb_dma
);
2935 dma_pool_free(ha
->s_dma_pool
, ha
->async_pd
, ha
->async_pd_dma
);
2938 dma_pool_destroy(ha
->s_dma_pool
);
2941 dma_free_coherent(&ha
->pdev
->dev
, GID_LIST_SIZE
, ha
->gid_list
,
2944 if (IS_QLA82XX(ha
)) {
2945 if (!list_empty(&ha
->gbl_dsd_list
)) {
2946 struct dsd_dma
*dsd_ptr
, *tdsd_ptr
;
2948 /* clean up allocated prev pool */
2949 list_for_each_entry_safe(dsd_ptr
,
2950 tdsd_ptr
, &ha
->gbl_dsd_list
, list
) {
2951 dma_pool_free(ha
->dl_dma_pool
,
2952 dsd_ptr
->dsd_addr
, dsd_ptr
->dsd_list_dma
);
2953 list_del(&dsd_ptr
->list
);
2959 if (ha
->dl_dma_pool
)
2960 dma_pool_destroy(ha
->dl_dma_pool
);
2962 if (ha
->fcp_cmnd_dma_pool
)
2963 dma_pool_destroy(ha
->fcp_cmnd_dma_pool
);
2965 if (ha
->ctx_mempool
)
2966 mempool_destroy(ha
->ctx_mempool
);
2969 dma_free_coherent(&ha
->pdev
->dev
, ha
->init_cb_size
,
2970 ha
->init_cb
, ha
->init_cb_dma
);
2971 vfree(ha
->optrom_buffer
);
2973 kfree(ha
->npiv_info
);
2975 ha
->srb_mempool
= NULL
;
2976 ha
->ctx_mempool
= NULL
;
2978 ha
->sns_cmd_dma
= 0;
2982 ha
->ms_iocb_dma
= 0;
2984 ha
->init_cb_dma
= 0;
2985 ha
->ex_init_cb
= NULL
;
2986 ha
->ex_init_cb_dma
= 0;
2987 ha
->async_pd
= NULL
;
2988 ha
->async_pd_dma
= 0;
2990 ha
->s_dma_pool
= NULL
;
2991 ha
->dl_dma_pool
= NULL
;
2992 ha
->fcp_cmnd_dma_pool
= NULL
;
2994 ha
->gid_list
= NULL
;
2995 ha
->gid_list_dma
= 0;
2998 struct scsi_qla_host
*qla2x00_create_host(struct scsi_host_template
*sht
,
2999 struct qla_hw_data
*ha
)
3001 struct Scsi_Host
*host
;
3002 struct scsi_qla_host
*vha
= NULL
;
3004 host
= scsi_host_alloc(sht
, sizeof(scsi_qla_host_t
));
3007 "qla2xxx: Couldn't allocate host from scsi layer!\n");
3011 /* Clear our data area */
3012 vha
= shost_priv(host
);
3013 memset(vha
, 0, sizeof(scsi_qla_host_t
));
3016 vha
->host_no
= host
->host_no
;
3019 INIT_LIST_HEAD(&vha
->vp_fcports
);
3020 INIT_LIST_HEAD(&vha
->work_list
);
3021 INIT_LIST_HEAD(&vha
->list
);
3023 spin_lock_init(&vha
->work_lock
);
3025 sprintf(vha
->host_str
, "%s_%ld", QLA2XXX_DRIVER_NAME
, vha
->host_no
);
3032 static struct qla_work_evt
*
3033 qla2x00_alloc_work(struct scsi_qla_host
*vha
, enum qla_work_type type
)
3035 struct qla_work_evt
*e
;
3038 QLA_VHA_MARK_BUSY(vha
, bail
);
3042 e
= kzalloc(sizeof(struct qla_work_evt
), GFP_ATOMIC
);
3044 QLA_VHA_MARK_NOT_BUSY(vha
);
3048 INIT_LIST_HEAD(&e
->list
);
3050 e
->flags
= QLA_EVT_FLAG_FREE
;
3055 qla2x00_post_work(struct scsi_qla_host
*vha
, struct qla_work_evt
*e
)
3057 unsigned long flags
;
3059 spin_lock_irqsave(&vha
->work_lock
, flags
);
3060 list_add_tail(&e
->list
, &vha
->work_list
);
3061 spin_unlock_irqrestore(&vha
->work_lock
, flags
);
3062 qla2xxx_wake_dpc(vha
);
3068 qla2x00_post_aen_work(struct scsi_qla_host
*vha
, enum fc_host_event_code code
,
3071 struct qla_work_evt
*e
;
3073 e
= qla2x00_alloc_work(vha
, QLA_EVT_AEN
);
3075 return QLA_FUNCTION_FAILED
;
3077 e
->u
.aen
.code
= code
;
3078 e
->u
.aen
.data
= data
;
3079 return qla2x00_post_work(vha
, e
);
3083 qla2x00_post_idc_ack_work(struct scsi_qla_host
*vha
, uint16_t *mb
)
3085 struct qla_work_evt
*e
;
3087 e
= qla2x00_alloc_work(vha
, QLA_EVT_IDC_ACK
);
3089 return QLA_FUNCTION_FAILED
;
3091 memcpy(e
->u
.idc_ack
.mb
, mb
, QLA_IDC_ACK_REGS
* sizeof(uint16_t));
3092 return qla2x00_post_work(vha
, e
);
3095 #define qla2x00_post_async_work(name, type) \
3096 int qla2x00_post_async_##name##_work( \
3097 struct scsi_qla_host *vha, \
3098 fc_port_t *fcport, uint16_t *data) \
3100 struct qla_work_evt *e; \
3102 e = qla2x00_alloc_work(vha, type); \
3104 return QLA_FUNCTION_FAILED; \
3106 e->u.logio.fcport = fcport; \
3108 e->u.logio.data[0] = data[0]; \
3109 e->u.logio.data[1] = data[1]; \
3111 return qla2x00_post_work(vha, e); \
3114 qla2x00_post_async_work(login
, QLA_EVT_ASYNC_LOGIN
);
3115 qla2x00_post_async_work(login_done
, QLA_EVT_ASYNC_LOGIN_DONE
);
3116 qla2x00_post_async_work(logout
, QLA_EVT_ASYNC_LOGOUT
);
3117 qla2x00_post_async_work(logout_done
, QLA_EVT_ASYNC_LOGOUT_DONE
);
3118 qla2x00_post_async_work(adisc
, QLA_EVT_ASYNC_ADISC
);
3119 qla2x00_post_async_work(adisc_done
, QLA_EVT_ASYNC_ADISC_DONE
);
3122 qla2x00_post_uevent_work(struct scsi_qla_host
*vha
, u32 code
)
3124 struct qla_work_evt
*e
;
3126 e
= qla2x00_alloc_work(vha
, QLA_EVT_UEVENT
);
3128 return QLA_FUNCTION_FAILED
;
3130 e
->u
.uevent
.code
= code
;
3131 return qla2x00_post_work(vha
, e
);
3135 qla2x00_uevent_emit(struct scsi_qla_host
*vha
, u32 code
)
3137 char event_string
[40];
3138 char *envp
[] = { event_string
, NULL
};
3141 case QLA_UEVENT_CODE_FW_DUMP
:
3142 snprintf(event_string
, sizeof(event_string
), "FW_DUMP=%ld",
3149 kobject_uevent_env(&vha
->hw
->pdev
->dev
.kobj
, KOBJ_CHANGE
, envp
);
3153 qla2x00_do_work(struct scsi_qla_host
*vha
)
3155 struct qla_work_evt
*e
, *tmp
;
3156 unsigned long flags
;
3159 spin_lock_irqsave(&vha
->work_lock
, flags
);
3160 list_splice_init(&vha
->work_list
, &work
);
3161 spin_unlock_irqrestore(&vha
->work_lock
, flags
);
3163 list_for_each_entry_safe(e
, tmp
, &work
, list
) {
3164 list_del_init(&e
->list
);
3168 fc_host_post_event(vha
->host
, fc_get_event_number(),
3169 e
->u
.aen
.code
, e
->u
.aen
.data
);
3171 case QLA_EVT_IDC_ACK
:
3172 qla81xx_idc_ack(vha
, e
->u
.idc_ack
.mb
);
3174 case QLA_EVT_ASYNC_LOGIN
:
3175 qla2x00_async_login(vha
, e
->u
.logio
.fcport
,
3178 case QLA_EVT_ASYNC_LOGIN_DONE
:
3179 qla2x00_async_login_done(vha
, e
->u
.logio
.fcport
,
3182 case QLA_EVT_ASYNC_LOGOUT
:
3183 qla2x00_async_logout(vha
, e
->u
.logio
.fcport
);
3185 case QLA_EVT_ASYNC_LOGOUT_DONE
:
3186 qla2x00_async_logout_done(vha
, e
->u
.logio
.fcport
,
3189 case QLA_EVT_ASYNC_ADISC
:
3190 qla2x00_async_adisc(vha
, e
->u
.logio
.fcport
,
3193 case QLA_EVT_ASYNC_ADISC_DONE
:
3194 qla2x00_async_adisc_done(vha
, e
->u
.logio
.fcport
,
3197 case QLA_EVT_UEVENT
:
3198 qla2x00_uevent_emit(vha
, e
->u
.uevent
.code
);
3201 if (e
->flags
& QLA_EVT_FLAG_FREE
)
3204 /* For each work completed decrement vha ref count */
3205 QLA_VHA_MARK_NOT_BUSY(vha
);
3209 /* Relogins all the fcports of a vport
3210 * Context: dpc thread
3212 void qla2x00_relogin(struct scsi_qla_host
*vha
)
3216 uint16_t next_loopid
= 0;
3217 struct qla_hw_data
*ha
= vha
->hw
;
3220 list_for_each_entry(fcport
, &vha
->vp_fcports
, list
) {
3222 * If the port is not ONLINE then try to login
3223 * to it if we haven't run out of retries.
3225 if (atomic_read(&fcport
->state
) != FCS_ONLINE
&&
3226 fcport
->login_retry
&& !(fcport
->flags
& FCF_ASYNC_SENT
)) {
3227 fcport
->login_retry
--;
3228 if (fcport
->flags
& FCF_FABRIC_DEVICE
) {
3229 if (fcport
->flags
& FCF_FCP2_DEVICE
)
3230 ha
->isp_ops
->fabric_logout(vha
,
3232 fcport
->d_id
.b
.domain
,
3233 fcport
->d_id
.b
.area
,
3234 fcport
->d_id
.b
.al_pa
);
3236 if (fcport
->loop_id
== FC_NO_LOOP_ID
) {
3237 fcport
->loop_id
= next_loopid
=
3238 ha
->min_external_loopid
;
3239 status
= qla2x00_find_new_loop_id(
3241 if (status
!= QLA_SUCCESS
) {
3242 /* Ran out of IDs to use */
3247 if (IS_ALOGIO_CAPABLE(ha
)) {
3248 fcport
->flags
|= FCF_ASYNC_SENT
;
3250 data
[1] = QLA_LOGIO_LOGIN_RETRIED
;
3251 status
= qla2x00_post_async_login_work(
3253 if (status
== QLA_SUCCESS
)
3255 /* Attempt a retry. */
3258 status
= qla2x00_fabric_login(vha
,
3259 fcport
, &next_loopid
);
3261 status
= qla2x00_local_device_login(vha
,
3264 if (status
== QLA_SUCCESS
) {
3265 fcport
->old_loop_id
= fcport
->loop_id
;
3267 DEBUG(printk("scsi(%ld): port login OK: logged "
3268 "in ID 0x%x\n", vha
->host_no
, fcport
->loop_id
));
3270 qla2x00_update_fcport(vha
, fcport
);
3272 } else if (status
== 1) {
3273 set_bit(RELOGIN_NEEDED
, &vha
->dpc_flags
);
3274 /* retry the login again */
3275 DEBUG(printk("scsi(%ld): Retrying"
3276 " %d login again loop_id 0x%x\n",
3277 vha
->host_no
, fcport
->login_retry
,
3280 fcport
->login_retry
= 0;
3283 if (fcport
->login_retry
== 0 && status
!= QLA_SUCCESS
)
3284 fcport
->loop_id
= FC_NO_LOOP_ID
;
3286 if (test_bit(LOOP_RESYNC_NEEDED
, &vha
->dpc_flags
))
3291 /**************************************************************************
3293 * This kernel thread is a task that is schedule by the interrupt handler
3294 * to perform the background processing for interrupts.
3297 * This task always run in the context of a kernel thread. It
3298 * is kick-off by the driver's detect code and starts up
3299 * up one per adapter. It immediately goes to sleep and waits for
3300 * some fibre event. When either the interrupt handler or
3301 * the timer routine detects a event it will one of the task
3302 * bits then wake us up.
3303 **************************************************************************/
3305 qla2x00_do_dpc(void *data
)
3308 scsi_qla_host_t
*base_vha
;
3309 struct qla_hw_data
*ha
;
3311 ha
= (struct qla_hw_data
*)data
;
3312 base_vha
= pci_get_drvdata(ha
->pdev
);
3314 set_user_nice(current
, -20);
3316 set_current_state(TASK_INTERRUPTIBLE
);
3317 while (!kthread_should_stop()) {
3318 DEBUG3(printk("qla2x00: DPC handler sleeping\n"));
3321 __set_current_state(TASK_RUNNING
);
3323 DEBUG3(printk("qla2x00: DPC handler waking up\n"));
3325 /* Initialization not yet finished. Don't do anything yet. */
3326 if (!base_vha
->flags
.init_done
)
3329 if (ha
->flags
.eeh_busy
) {
3330 DEBUG17(qla_printk(KERN_WARNING
, ha
,
3331 "qla2x00_do_dpc: dpc_flags: %lx\n",
3332 base_vha
->dpc_flags
));
3336 DEBUG3(printk("scsi(%ld): DPC handler\n", base_vha
->host_no
));
3340 if (ha
->flags
.mbox_busy
) {
3345 qla2x00_do_work(base_vha
);
3347 if (IS_QLA82XX(ha
)) {
3348 if (test_and_clear_bit(ISP_UNRECOVERABLE
,
3349 &base_vha
->dpc_flags
)) {
3350 qla82xx_idc_lock(ha
);
3351 qla82xx_wr_32(ha
, QLA82XX_CRB_DEV_STATE
,
3352 QLA82XX_DEV_FAILED
);
3353 qla82xx_idc_unlock(ha
);
3354 qla_printk(KERN_INFO
, ha
,
3355 "HW State: FAILED\n");
3356 qla82xx_device_state_handler(base_vha
);
3360 if (test_and_clear_bit(FCOE_CTX_RESET_NEEDED
,
3361 &base_vha
->dpc_flags
)) {
3363 DEBUG(printk(KERN_INFO
3364 "scsi(%ld): dpc: sched "
3365 "qla82xx_fcoe_ctx_reset ha = %p\n",
3366 base_vha
->host_no
, ha
));
3367 if (!(test_and_set_bit(ABORT_ISP_ACTIVE
,
3368 &base_vha
->dpc_flags
))) {
3369 if (qla82xx_fcoe_ctx_reset(base_vha
)) {
3370 /* FCoE-ctx reset failed.
3371 * Escalate to chip-reset
3373 set_bit(ISP_ABORT_NEEDED
,
3374 &base_vha
->dpc_flags
);
3376 clear_bit(ABORT_ISP_ACTIVE
,
3377 &base_vha
->dpc_flags
);
3380 DEBUG(printk("scsi(%ld): dpc:"
3381 " qla82xx_fcoe_ctx_reset end\n",
3382 base_vha
->host_no
));
3386 if (test_and_clear_bit(ISP_ABORT_NEEDED
,
3387 &base_vha
->dpc_flags
)) {
3389 DEBUG(printk("scsi(%ld): dpc: sched "
3390 "qla2x00_abort_isp ha = %p\n",
3391 base_vha
->host_no
, ha
));
3392 if (!(test_and_set_bit(ABORT_ISP_ACTIVE
,
3393 &base_vha
->dpc_flags
))) {
3395 if (ha
->isp_ops
->abort_isp(base_vha
)) {
3396 /* failed. retry later */
3397 set_bit(ISP_ABORT_NEEDED
,
3398 &base_vha
->dpc_flags
);
3400 clear_bit(ABORT_ISP_ACTIVE
,
3401 &base_vha
->dpc_flags
);
3404 DEBUG(printk("scsi(%ld): dpc: qla2x00_abort_isp end\n",
3405 base_vha
->host_no
));
3408 if (test_bit(FCPORT_UPDATE_NEEDED
, &base_vha
->dpc_flags
)) {
3409 qla2x00_update_fcports(base_vha
);
3410 clear_bit(FCPORT_UPDATE_NEEDED
, &base_vha
->dpc_flags
);
3413 if (test_bit(ISP_QUIESCE_NEEDED
, &base_vha
->dpc_flags
)) {
3414 DEBUG(printk(KERN_INFO
"scsi(%ld): dpc: sched "
3415 "qla2x00_quiesce_needed ha = %p\n",
3416 base_vha
->host_no
, ha
));
3417 qla82xx_device_state_handler(base_vha
);
3418 clear_bit(ISP_QUIESCE_NEEDED
, &base_vha
->dpc_flags
);
3419 if (!ha
->flags
.quiesce_owner
) {
3420 qla2x00_perform_loop_resync(base_vha
);
3422 qla82xx_idc_lock(ha
);
3423 qla82xx_clear_qsnt_ready(base_vha
);
3424 qla82xx_idc_unlock(ha
);
3428 if (test_and_clear_bit(RESET_MARKER_NEEDED
,
3429 &base_vha
->dpc_flags
) &&
3430 (!(test_and_set_bit(RESET_ACTIVE
, &base_vha
->dpc_flags
)))) {
3432 DEBUG(printk("scsi(%ld): qla2x00_reset_marker()\n",
3433 base_vha
->host_no
));
3435 qla2x00_rst_aen(base_vha
);
3436 clear_bit(RESET_ACTIVE
, &base_vha
->dpc_flags
);
3439 /* Retry each device up to login retry count */
3440 if ((test_and_clear_bit(RELOGIN_NEEDED
,
3441 &base_vha
->dpc_flags
)) &&
3442 !test_bit(LOOP_RESYNC_NEEDED
, &base_vha
->dpc_flags
) &&
3443 atomic_read(&base_vha
->loop_state
) != LOOP_DOWN
) {
3445 DEBUG(printk("scsi(%ld): qla2x00_port_login()\n",
3446 base_vha
->host_no
));
3447 qla2x00_relogin(base_vha
);
3449 DEBUG(printk("scsi(%ld): qla2x00_port_login - end\n",
3450 base_vha
->host_no
));
3453 if (test_and_clear_bit(LOOP_RESYNC_NEEDED
,
3454 &base_vha
->dpc_flags
)) {
3456 DEBUG(printk("scsi(%ld): qla2x00_loop_resync()\n",
3457 base_vha
->host_no
));
3459 if (!(test_and_set_bit(LOOP_RESYNC_ACTIVE
,
3460 &base_vha
->dpc_flags
))) {
3462 rval
= qla2x00_loop_resync(base_vha
);
3464 clear_bit(LOOP_RESYNC_ACTIVE
,
3465 &base_vha
->dpc_flags
);
3468 DEBUG(printk("scsi(%ld): qla2x00_loop_resync - end\n",
3469 base_vha
->host_no
));
3472 if (test_bit(NPIV_CONFIG_NEEDED
, &base_vha
->dpc_flags
) &&
3473 atomic_read(&base_vha
->loop_state
) == LOOP_READY
) {
3474 clear_bit(NPIV_CONFIG_NEEDED
, &base_vha
->dpc_flags
);
3475 qla2xxx_flash_npiv_conf(base_vha
);
3478 if (!ha
->interrupts_on
)
3479 ha
->isp_ops
->enable_intrs(ha
);
3481 if (test_and_clear_bit(BEACON_BLINK_NEEDED
,
3482 &base_vha
->dpc_flags
))
3483 ha
->isp_ops
->beacon_blink(base_vha
);
3485 qla2x00_do_dpc_all_vps(base_vha
);
3488 set_current_state(TASK_INTERRUPTIBLE
);
3489 } /* End of while(1) */
3490 __set_current_state(TASK_RUNNING
);
3492 DEBUG(printk("scsi(%ld): DPC handler exiting\n", base_vha
->host_no
));
3495 * Make sure that nobody tries to wake us up again.
3499 /* Cleanup any residual CTX SRBs. */
3500 qla2x00_abort_all_cmds(base_vha
, DID_NO_CONNECT
<< 16);
3506 qla2xxx_wake_dpc(struct scsi_qla_host
*vha
)
3508 struct qla_hw_data
*ha
= vha
->hw
;
3509 struct task_struct
*t
= ha
->dpc_thread
;
3511 if (!test_bit(UNLOADING
, &vha
->dpc_flags
) && t
)
3517 * Processes asynchronous reset.
3520 * ha = adapter block pointer.
3523 qla2x00_rst_aen(scsi_qla_host_t
*vha
)
3525 if (vha
->flags
.online
&& !vha
->flags
.reset_active
&&
3526 !atomic_read(&vha
->loop_down_timer
) &&
3527 !(test_bit(ABORT_ISP_ACTIVE
, &vha
->dpc_flags
))) {
3529 clear_bit(RESET_MARKER_NEEDED
, &vha
->dpc_flags
);
3532 * Issue marker command only when we are going to start
3535 vha
->marker_needed
= 1;
3536 } while (!atomic_read(&vha
->loop_down_timer
) &&
3537 (test_bit(RESET_MARKER_NEEDED
, &vha
->dpc_flags
)));
3542 qla2x00_sp_free_dma(srb_t
*sp
)
3544 struct scsi_cmnd
*cmd
= sp
->cmd
;
3545 struct qla_hw_data
*ha
= sp
->fcport
->vha
->hw
;
3547 if (sp
->flags
& SRB_DMA_VALID
) {
3548 scsi_dma_unmap(cmd
);
3549 sp
->flags
&= ~SRB_DMA_VALID
;
3552 if (sp
->flags
& SRB_CRC_PROT_DMA_VALID
) {
3553 dma_unmap_sg(&ha
->pdev
->dev
, scsi_prot_sglist(cmd
),
3554 scsi_prot_sg_count(cmd
), cmd
->sc_data_direction
);
3555 sp
->flags
&= ~SRB_CRC_PROT_DMA_VALID
;
3558 if (sp
->flags
& SRB_CRC_CTX_DSD_VALID
) {
3559 /* List assured to be having elements */
3560 qla2x00_clean_dsd_pool(ha
, sp
);
3561 sp
->flags
&= ~SRB_CRC_CTX_DSD_VALID
;
3564 if (sp
->flags
& SRB_CRC_CTX_DMA_VALID
) {
3565 dma_pool_free(ha
->dl_dma_pool
, sp
->ctx
,
3566 ((struct crc_context
*)sp
->ctx
)->crc_ctx_dma
);
3567 sp
->flags
&= ~SRB_CRC_CTX_DMA_VALID
;
3574 qla2x00_sp_final_compl(struct qla_hw_data
*ha
, srb_t
*sp
)
3576 struct scsi_cmnd
*cmd
= sp
->cmd
;
3578 qla2x00_sp_free_dma(sp
);
3580 if (sp
->flags
& SRB_FCP_CMND_DMA_VALID
) {
3581 struct ct6_dsd
*ctx
= sp
->ctx
;
3582 dma_pool_free(ha
->fcp_cmnd_dma_pool
, ctx
->fcp_cmnd
,
3584 list_splice(&ctx
->dsd_list
, &ha
->gbl_dsd_list
);
3585 ha
->gbl_dsd_inuse
-= ctx
->dsd_use_cnt
;
3586 ha
->gbl_dsd_avail
+= ctx
->dsd_use_cnt
;
3587 mempool_free(sp
->ctx
, ha
->ctx_mempool
);
3591 mempool_free(sp
, ha
->srb_mempool
);
3592 cmd
->scsi_done(cmd
);
3596 qla2x00_sp_compl(struct qla_hw_data
*ha
, srb_t
*sp
)
3598 if (atomic_read(&sp
->ref_count
) == 0) {
3599 DEBUG2(qla_printk(KERN_WARNING
, ha
,
3600 "SP reference-count to ZERO -- sp=%p\n", sp
));
3604 if (!atomic_dec_and_test(&sp
->ref_count
))
3606 qla2x00_sp_final_compl(ha
, sp
);
3609 /**************************************************************************
3615 * Context: Interrupt
3616 ***************************************************************************/
3618 qla2x00_timer(scsi_qla_host_t
*vha
)
3620 unsigned long cpu_flags
= 0;
3625 struct qla_hw_data
*ha
= vha
->hw
;
3626 struct req_que
*req
;
3628 if (ha
->flags
.eeh_busy
) {
3629 qla2x00_restart_timer(vha
, WATCH_INTERVAL
);
3633 /* Hardware read to raise pending EEH errors during mailbox waits. */
3634 if (!pci_channel_offline(ha
->pdev
))
3635 pci_read_config_word(ha
->pdev
, PCI_VENDOR_ID
, &w
);
3637 /* Make sure qla82xx_watchdog is run only for physical port */
3638 if (!vha
->vp_idx
&& IS_QLA82XX(ha
)) {
3639 if (test_bit(ISP_QUIESCE_NEEDED
, &vha
->dpc_flags
))
3641 qla82xx_watchdog(vha
);
3644 /* Loop down handler. */
3645 if (atomic_read(&vha
->loop_down_timer
) > 0 &&
3646 !(test_bit(ABORT_ISP_ACTIVE
, &vha
->dpc_flags
)) &&
3647 !(test_bit(FCOE_CTX_RESET_NEEDED
, &vha
->dpc_flags
))
3648 && vha
->flags
.online
) {
3650 if (atomic_read(&vha
->loop_down_timer
) ==
3651 vha
->loop_down_abort_time
) {
3653 DEBUG(printk("scsi(%ld): Loop Down - aborting the "
3654 "queues before time expire\n",
3657 if (!IS_QLA2100(ha
) && vha
->link_down_timeout
)
3658 atomic_set(&vha
->loop_state
, LOOP_DEAD
);
3661 * Schedule an ISP abort to return any FCP2-device
3664 /* NPIV - scan physical port only */
3666 spin_lock_irqsave(&ha
->hardware_lock
,
3668 req
= ha
->req_q_map
[0];
3670 index
< MAX_OUTSTANDING_COMMANDS
;
3674 sp
= req
->outstanding_cmds
[index
];
3677 if (sp
->ctx
&& !IS_PROT_IO(sp
))
3680 if (!(sfcp
->flags
& FCF_FCP2_DEVICE
))
3684 set_bit(FCOE_CTX_RESET_NEEDED
,
3687 set_bit(ISP_ABORT_NEEDED
,
3691 spin_unlock_irqrestore(&ha
->hardware_lock
,
3697 /* if the loop has been down for 4 minutes, reinit adapter */
3698 if (atomic_dec_and_test(&vha
->loop_down_timer
) != 0) {
3699 if (!(vha
->device_flags
& DFLG_NO_CABLE
)) {
3700 DEBUG(printk("scsi(%ld): Loop down - "
3703 qla_printk(KERN_WARNING
, ha
,
3704 "Loop down - aborting ISP.\n");
3707 set_bit(FCOE_CTX_RESET_NEEDED
,
3710 set_bit(ISP_ABORT_NEEDED
,
3714 DEBUG3(printk("scsi(%ld): Loop Down - seconds remaining %d\n",
3716 atomic_read(&vha
->loop_down_timer
)));
3719 /* Check if beacon LED needs to be blinked for physical host only */
3720 if (!vha
->vp_idx
&& (ha
->beacon_blink_led
== 1)) {
3721 set_bit(BEACON_BLINK_NEEDED
, &vha
->dpc_flags
);
3725 /* Process any deferred work. */
3726 if (!list_empty(&vha
->work_list
))
3729 /* Schedule the DPC routine if needed */
3730 if ((test_bit(ISP_ABORT_NEEDED
, &vha
->dpc_flags
) ||
3731 test_bit(LOOP_RESYNC_NEEDED
, &vha
->dpc_flags
) ||
3732 test_bit(FCPORT_UPDATE_NEEDED
, &vha
->dpc_flags
) ||
3734 test_bit(RESET_MARKER_NEEDED
, &vha
->dpc_flags
) ||
3735 test_bit(BEACON_BLINK_NEEDED
, &vha
->dpc_flags
) ||
3736 test_bit(ISP_UNRECOVERABLE
, &vha
->dpc_flags
) ||
3737 test_bit(FCOE_CTX_RESET_NEEDED
, &vha
->dpc_flags
) ||
3738 test_bit(VP_DPC_NEEDED
, &vha
->dpc_flags
) ||
3739 test_bit(RELOGIN_NEEDED
, &vha
->dpc_flags
)))
3740 qla2xxx_wake_dpc(vha
);
3742 qla2x00_restart_timer(vha
, WATCH_INTERVAL
);
3745 /* Firmware interface routines. */
3748 #define FW_ISP21XX 0
3749 #define FW_ISP22XX 1
3750 #define FW_ISP2300 2
3751 #define FW_ISP2322 3
3752 #define FW_ISP24XX 4
3753 #define FW_ISP25XX 5
3754 #define FW_ISP81XX 6
3755 #define FW_ISP82XX 7
3757 #define FW_FILE_ISP21XX "ql2100_fw.bin"
3758 #define FW_FILE_ISP22XX "ql2200_fw.bin"
3759 #define FW_FILE_ISP2300 "ql2300_fw.bin"
3760 #define FW_FILE_ISP2322 "ql2322_fw.bin"
3761 #define FW_FILE_ISP24XX "ql2400_fw.bin"
3762 #define FW_FILE_ISP25XX "ql2500_fw.bin"
3763 #define FW_FILE_ISP81XX "ql8100_fw.bin"
3764 #define FW_FILE_ISP82XX "ql8200_fw.bin"
3766 static DEFINE_MUTEX(qla_fw_lock
);
3768 static struct fw_blob qla_fw_blobs
[FW_BLOBS
] = {
3769 { .name
= FW_FILE_ISP21XX
, .segs
= { 0x1000, 0 }, },
3770 { .name
= FW_FILE_ISP22XX
, .segs
= { 0x1000, 0 }, },
3771 { .name
= FW_FILE_ISP2300
, .segs
= { 0x800, 0 }, },
3772 { .name
= FW_FILE_ISP2322
, .segs
= { 0x800, 0x1c000, 0x1e000, 0 }, },
3773 { .name
= FW_FILE_ISP24XX
, },
3774 { .name
= FW_FILE_ISP25XX
, },
3775 { .name
= FW_FILE_ISP81XX
, },
3776 { .name
= FW_FILE_ISP82XX
, },
3780 qla2x00_request_firmware(scsi_qla_host_t
*vha
)
3782 struct qla_hw_data
*ha
= vha
->hw
;
3783 struct fw_blob
*blob
;
3786 if (IS_QLA2100(ha
)) {
3787 blob
= &qla_fw_blobs
[FW_ISP21XX
];
3788 } else if (IS_QLA2200(ha
)) {
3789 blob
= &qla_fw_blobs
[FW_ISP22XX
];
3790 } else if (IS_QLA2300(ha
) || IS_QLA2312(ha
) || IS_QLA6312(ha
)) {
3791 blob
= &qla_fw_blobs
[FW_ISP2300
];
3792 } else if (IS_QLA2322(ha
) || IS_QLA6322(ha
)) {
3793 blob
= &qla_fw_blobs
[FW_ISP2322
];
3794 } else if (IS_QLA24XX_TYPE(ha
)) {
3795 blob
= &qla_fw_blobs
[FW_ISP24XX
];
3796 } else if (IS_QLA25XX(ha
)) {
3797 blob
= &qla_fw_blobs
[FW_ISP25XX
];
3798 } else if (IS_QLA81XX(ha
)) {
3799 blob
= &qla_fw_blobs
[FW_ISP81XX
];
3800 } else if (IS_QLA82XX(ha
)) {
3801 blob
= &qla_fw_blobs
[FW_ISP82XX
];
3804 mutex_lock(&qla_fw_lock
);
3808 if (request_firmware(&blob
->fw
, blob
->name
, &ha
->pdev
->dev
)) {
3809 DEBUG2(printk("scsi(%ld): Failed to load firmware image "
3810 "(%s).\n", vha
->host_no
, blob
->name
));
3817 mutex_unlock(&qla_fw_lock
);
3822 qla2x00_release_firmware(void)
3826 mutex_lock(&qla_fw_lock
);
3827 for (idx
= 0; idx
< FW_BLOBS
; idx
++)
3828 if (qla_fw_blobs
[idx
].fw
)
3829 release_firmware(qla_fw_blobs
[idx
].fw
);
3830 mutex_unlock(&qla_fw_lock
);
3833 static pci_ers_result_t
3834 qla2xxx_pci_error_detected(struct pci_dev
*pdev
, pci_channel_state_t state
)
3836 scsi_qla_host_t
*vha
= pci_get_drvdata(pdev
);
3837 struct qla_hw_data
*ha
= vha
->hw
;
3839 DEBUG2(qla_printk(KERN_WARNING
, ha
, "error_detected:state %x\n",
3843 case pci_channel_io_normal
:
3844 ha
->flags
.eeh_busy
= 0;
3845 return PCI_ERS_RESULT_CAN_RECOVER
;
3846 case pci_channel_io_frozen
:
3847 ha
->flags
.eeh_busy
= 1;
3848 /* For ISP82XX complete any pending mailbox cmd */
3849 if (IS_QLA82XX(ha
)) {
3850 ha
->flags
.isp82xx_fw_hung
= 1;
3851 if (ha
->flags
.mbox_busy
) {
3852 ha
->flags
.mbox_int
= 1;
3853 DEBUG2(qla_printk(KERN_ERR
, ha
,
3854 "Due to pci channel io frozen, doing premature "
3855 "completion of mbx command\n"));
3856 complete(&ha
->mbx_intr_comp
);
3859 qla2x00_free_irqs(vha
);
3860 pci_disable_device(pdev
);
3861 /* Return back all IOs */
3862 qla2x00_abort_all_cmds(vha
, DID_RESET
<< 16);
3863 return PCI_ERS_RESULT_NEED_RESET
;
3864 case pci_channel_io_perm_failure
:
3865 ha
->flags
.pci_channel_io_perm_failure
= 1;
3866 qla2x00_abort_all_cmds(vha
, DID_NO_CONNECT
<< 16);
3867 return PCI_ERS_RESULT_DISCONNECT
;
3869 return PCI_ERS_RESULT_NEED_RESET
;
3872 static pci_ers_result_t
3873 qla2xxx_pci_mmio_enabled(struct pci_dev
*pdev
)
3875 int risc_paused
= 0;
3877 unsigned long flags
;
3878 scsi_qla_host_t
*base_vha
= pci_get_drvdata(pdev
);
3879 struct qla_hw_data
*ha
= base_vha
->hw
;
3880 struct device_reg_2xxx __iomem
*reg
= &ha
->iobase
->isp
;
3881 struct device_reg_24xx __iomem
*reg24
= &ha
->iobase
->isp24
;
3884 return PCI_ERS_RESULT_RECOVERED
;
3886 spin_lock_irqsave(&ha
->hardware_lock
, flags
);
3887 if (IS_QLA2100(ha
) || IS_QLA2200(ha
)){
3888 stat
= RD_REG_DWORD(®
->hccr
);
3889 if (stat
& HCCR_RISC_PAUSE
)
3891 } else if (IS_QLA23XX(ha
)) {
3892 stat
= RD_REG_DWORD(®
->u
.isp2300
.host_status
);
3893 if (stat
& HSR_RISC_PAUSED
)
3895 } else if (IS_FWI2_CAPABLE(ha
)) {
3896 stat
= RD_REG_DWORD(®24
->host_status
);
3897 if (stat
& HSRX_RISC_PAUSED
)
3900 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
3903 qla_printk(KERN_INFO
, ha
, "RISC paused -- mmio_enabled, "
3904 "Dumping firmware!\n");
3905 ha
->isp_ops
->fw_dump(base_vha
, 0);
3907 return PCI_ERS_RESULT_NEED_RESET
;
3909 return PCI_ERS_RESULT_RECOVERED
;
3912 uint32_t qla82xx_error_recovery(scsi_qla_host_t
*base_vha
)
3914 uint32_t rval
= QLA_FUNCTION_FAILED
;
3915 uint32_t drv_active
= 0;
3916 struct qla_hw_data
*ha
= base_vha
->hw
;
3918 struct pci_dev
*other_pdev
= NULL
;
3920 DEBUG17(qla_printk(KERN_INFO
, ha
,
3921 "scsi(%ld): In qla82xx_error_recovery\n", base_vha
->host_no
));
3923 set_bit(ABORT_ISP_ACTIVE
, &base_vha
->dpc_flags
);
3925 if (base_vha
->flags
.online
) {
3926 /* Abort all outstanding commands,
3927 * so as to be requeued later */
3928 qla2x00_abort_isp_cleanup(base_vha
);
3932 fn
= PCI_FUNC(ha
->pdev
->devfn
);
3935 DEBUG17(qla_printk(KERN_INFO
, ha
,
3936 "Finding pci device at function = 0x%x\n", fn
));
3938 pci_get_domain_bus_and_slot(pci_domain_nr(ha
->pdev
->bus
),
3939 ha
->pdev
->bus
->number
, PCI_DEVFN(PCI_SLOT(ha
->pdev
->devfn
),
3944 if (atomic_read(&other_pdev
->enable_cnt
)) {
3945 DEBUG17(qla_printk(KERN_INFO
, ha
,
3946 "Found PCI func available and enabled at 0x%x\n",
3948 pci_dev_put(other_pdev
);
3951 pci_dev_put(other_pdev
);
3956 DEBUG17(qla_printk(KERN_INFO
, ha
,
3957 "This devfn is reset owner = 0x%x\n", ha
->pdev
->devfn
));
3958 qla82xx_idc_lock(ha
);
3960 qla82xx_wr_32(ha
, QLA82XX_CRB_DEV_STATE
,
3961 QLA82XX_DEV_INITIALIZING
);
3963 qla82xx_wr_32(ha
, QLA82XX_CRB_DRV_IDC_VERSION
,
3964 QLA82XX_IDC_VERSION
);
3966 drv_active
= qla82xx_rd_32(ha
, QLA82XX_CRB_DRV_ACTIVE
);
3967 DEBUG17(qla_printk(KERN_INFO
, ha
,
3968 "drv_active = 0x%x\n", drv_active
));
3970 qla82xx_idc_unlock(ha
);
3971 /* Reset if device is not already reset
3972 * drv_active would be 0 if a reset has already been done
3975 rval
= qla82xx_start_firmware(base_vha
);
3978 qla82xx_idc_lock(ha
);
3980 if (rval
!= QLA_SUCCESS
) {
3981 qla_printk(KERN_INFO
, ha
, "HW State: FAILED\n");
3982 qla82xx_clear_drv_active(ha
);
3983 qla82xx_wr_32(ha
, QLA82XX_CRB_DEV_STATE
,
3984 QLA82XX_DEV_FAILED
);
3986 qla_printk(KERN_INFO
, ha
, "HW State: READY\n");
3987 qla82xx_wr_32(ha
, QLA82XX_CRB_DEV_STATE
,
3989 qla82xx_idc_unlock(ha
);
3990 ha
->flags
.isp82xx_fw_hung
= 0;
3991 rval
= qla82xx_restart_isp(base_vha
);
3992 qla82xx_idc_lock(ha
);
3993 /* Clear driver state register */
3994 qla82xx_wr_32(ha
, QLA82XX_CRB_DRV_STATE
, 0);
3995 qla82xx_set_drv_active(base_vha
);
3997 qla82xx_idc_unlock(ha
);
3999 DEBUG17(qla_printk(KERN_INFO
, ha
,
4000 "This devfn is not reset owner = 0x%x\n", ha
->pdev
->devfn
));
4001 if ((qla82xx_rd_32(ha
, QLA82XX_CRB_DEV_STATE
) ==
4002 QLA82XX_DEV_READY
)) {
4003 ha
->flags
.isp82xx_fw_hung
= 0;
4004 rval
= qla82xx_restart_isp(base_vha
);
4005 qla82xx_idc_lock(ha
);
4006 qla82xx_set_drv_active(base_vha
);
4007 qla82xx_idc_unlock(ha
);
4010 clear_bit(ABORT_ISP_ACTIVE
, &base_vha
->dpc_flags
);
4015 static pci_ers_result_t
4016 qla2xxx_pci_slot_reset(struct pci_dev
*pdev
)
4018 pci_ers_result_t ret
= PCI_ERS_RESULT_DISCONNECT
;
4019 scsi_qla_host_t
*base_vha
= pci_get_drvdata(pdev
);
4020 struct qla_hw_data
*ha
= base_vha
->hw
;
4021 struct rsp_que
*rsp
;
4022 int rc
, retries
= 10;
4024 DEBUG17(qla_printk(KERN_WARNING
, ha
, "slot_reset\n"));
4026 /* Workaround: qla2xxx driver which access hardware earlier
4027 * needs error state to be pci_channel_io_online.
4028 * Otherwise mailbox command timesout.
4030 pdev
->error_state
= pci_channel_io_normal
;
4032 pci_restore_state(pdev
);
4034 /* pci_restore_state() clears the saved_state flag of the device
4035 * save restored state which resets saved_state flag
4037 pci_save_state(pdev
);
4040 rc
= pci_enable_device_mem(pdev
);
4042 rc
= pci_enable_device(pdev
);
4045 qla_printk(KERN_WARNING
, ha
,
4046 "Can't re-enable PCI device after reset.\n");
4047 goto exit_slot_reset
;
4050 rsp
= ha
->rsp_q_map
[0];
4051 if (qla2x00_request_irqs(ha
, rsp
))
4052 goto exit_slot_reset
;
4054 if (ha
->isp_ops
->pci_config(base_vha
))
4055 goto exit_slot_reset
;
4057 if (IS_QLA82XX(ha
)) {
4058 if (qla82xx_error_recovery(base_vha
) == QLA_SUCCESS
) {
4059 ret
= PCI_ERS_RESULT_RECOVERED
;
4060 goto exit_slot_reset
;
4062 goto exit_slot_reset
;
4065 while (ha
->flags
.mbox_busy
&& retries
--)
4068 set_bit(ABORT_ISP_ACTIVE
, &base_vha
->dpc_flags
);
4069 if (ha
->isp_ops
->abort_isp(base_vha
) == QLA_SUCCESS
)
4070 ret
= PCI_ERS_RESULT_RECOVERED
;
4071 clear_bit(ABORT_ISP_ACTIVE
, &base_vha
->dpc_flags
);
4075 DEBUG17(qla_printk(KERN_WARNING
, ha
,
4076 "slot_reset-return:ret=%x\n", ret
));
4082 qla2xxx_pci_resume(struct pci_dev
*pdev
)
4084 scsi_qla_host_t
*base_vha
= pci_get_drvdata(pdev
);
4085 struct qla_hw_data
*ha
= base_vha
->hw
;
4088 DEBUG17(qla_printk(KERN_WARNING
, ha
, "pci_resume\n"));
4090 ret
= qla2x00_wait_for_hba_online(base_vha
);
4091 if (ret
!= QLA_SUCCESS
) {
4092 qla_printk(KERN_ERR
, ha
,
4093 "the device failed to resume I/O "
4094 "from slot/link_reset");
4097 pci_cleanup_aer_uncorrect_error_status(pdev
);
4099 ha
->flags
.eeh_busy
= 0;
4102 static struct pci_error_handlers qla2xxx_err_handler
= {
4103 .error_detected
= qla2xxx_pci_error_detected
,
4104 .mmio_enabled
= qla2xxx_pci_mmio_enabled
,
4105 .slot_reset
= qla2xxx_pci_slot_reset
,
4106 .resume
= qla2xxx_pci_resume
,
4109 static struct pci_device_id qla2xxx_pci_tbl
[] = {
4110 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC
, PCI_DEVICE_ID_QLOGIC_ISP2100
) },
4111 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC
, PCI_DEVICE_ID_QLOGIC_ISP2200
) },
4112 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC
, PCI_DEVICE_ID_QLOGIC_ISP2300
) },
4113 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC
, PCI_DEVICE_ID_QLOGIC_ISP2312
) },
4114 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC
, PCI_DEVICE_ID_QLOGIC_ISP2322
) },
4115 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC
, PCI_DEVICE_ID_QLOGIC_ISP6312
) },
4116 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC
, PCI_DEVICE_ID_QLOGIC_ISP6322
) },
4117 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC
, PCI_DEVICE_ID_QLOGIC_ISP2422
) },
4118 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC
, PCI_DEVICE_ID_QLOGIC_ISP2432
) },
4119 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC
, PCI_DEVICE_ID_QLOGIC_ISP8432
) },
4120 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC
, PCI_DEVICE_ID_QLOGIC_ISP5422
) },
4121 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC
, PCI_DEVICE_ID_QLOGIC_ISP5432
) },
4122 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC
, PCI_DEVICE_ID_QLOGIC_ISP2532
) },
4123 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC
, PCI_DEVICE_ID_QLOGIC_ISP8001
) },
4124 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC
, PCI_DEVICE_ID_QLOGIC_ISP8021
) },
4127 MODULE_DEVICE_TABLE(pci
, qla2xxx_pci_tbl
);
4129 static struct pci_driver qla2xxx_pci_driver
= {
4130 .name
= QLA2XXX_DRIVER_NAME
,
4132 .owner
= THIS_MODULE
,
4134 .id_table
= qla2xxx_pci_tbl
,
4135 .probe
= qla2x00_probe_one
,
4136 .remove
= qla2x00_remove_one
,
4137 .shutdown
= qla2x00_shutdown
,
4138 .err_handler
= &qla2xxx_err_handler
,
4141 static struct file_operations apidev_fops
= {
4142 .owner
= THIS_MODULE
,
4143 .llseek
= noop_llseek
,
4147 * qla2x00_module_init - Module initialization.
4150 qla2x00_module_init(void)
4154 /* Allocate cache for SRBs. */
4155 srb_cachep
= kmem_cache_create("qla2xxx_srbs", sizeof(srb_t
), 0,
4156 SLAB_HWCACHE_ALIGN
, NULL
);
4157 if (srb_cachep
== NULL
) {
4159 "qla2xxx: Unable to allocate SRB cache...Failing load!\n");
4163 /* Derive version string. */
4164 strcpy(qla2x00_version_str
, QLA2XXX_VERSION
);
4165 if (ql2xextended_error_logging
)
4166 strcat(qla2x00_version_str
, "-debug");
4168 qla2xxx_transport_template
=
4169 fc_attach_transport(&qla2xxx_transport_functions
);
4170 if (!qla2xxx_transport_template
) {
4171 kmem_cache_destroy(srb_cachep
);
4175 apidev_major
= register_chrdev(0, QLA2XXX_APIDEV
, &apidev_fops
);
4176 if (apidev_major
< 0) {
4177 printk(KERN_WARNING
"qla2xxx: Unable to register char device "
4178 "%s\n", QLA2XXX_APIDEV
);
4181 qla2xxx_transport_vport_template
=
4182 fc_attach_transport(&qla2xxx_transport_vport_functions
);
4183 if (!qla2xxx_transport_vport_template
) {
4184 kmem_cache_destroy(srb_cachep
);
4185 fc_release_transport(qla2xxx_transport_template
);
4189 printk(KERN_INFO
"QLogic Fibre Channel HBA Driver: %s\n",
4190 qla2x00_version_str
);
4191 ret
= pci_register_driver(&qla2xxx_pci_driver
);
4193 kmem_cache_destroy(srb_cachep
);
4194 fc_release_transport(qla2xxx_transport_template
);
4195 fc_release_transport(qla2xxx_transport_vport_template
);
4201 * qla2x00_module_exit - Module cleanup.
4204 qla2x00_module_exit(void)
4206 unregister_chrdev(apidev_major
, QLA2XXX_APIDEV
);
4207 pci_unregister_driver(&qla2xxx_pci_driver
);
4208 qla2x00_release_firmware();
4209 kmem_cache_destroy(srb_cachep
);
4211 kmem_cache_destroy(ctx_cachep
);
4212 fc_release_transport(qla2xxx_transport_template
);
4213 fc_release_transport(qla2xxx_transport_vport_template
);
4216 module_init(qla2x00_module_init
);
4217 module_exit(qla2x00_module_exit
);
4219 MODULE_AUTHOR("QLogic Corporation");
4220 MODULE_DESCRIPTION("QLogic Fibre Channel HBA Driver");
4221 MODULE_LICENSE("GPL");
4222 MODULE_VERSION(QLA2XXX_VERSION
);
4223 MODULE_FIRMWARE(FW_FILE_ISP21XX
);
4224 MODULE_FIRMWARE(FW_FILE_ISP22XX
);
4225 MODULE_FIRMWARE(FW_FILE_ISP2300
);
4226 MODULE_FIRMWARE(FW_FILE_ISP2322
);
4227 MODULE_FIRMWARE(FW_FILE_ISP24XX
);
4228 MODULE_FIRMWARE(FW_FILE_ISP25XX
);