2 * QLogic Fibre Channel HBA Driver
3 * Copyright (c) 2003-2008 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>
15 #include <scsi/scsi_tcq.h>
16 #include <scsi/scsicam.h>
17 #include <scsi/scsi_transport.h>
18 #include <scsi/scsi_transport_fc.h>
23 char qla2x00_version_str
[40];
26 * SRB allocation cache
28 static struct kmem_cache
*srb_cachep
;
30 int ql2xlogintimeout
= 20;
31 module_param(ql2xlogintimeout
, int, S_IRUGO
|S_IRUSR
);
32 MODULE_PARM_DESC(ql2xlogintimeout
,
33 "Login timeout value in seconds.");
35 int qlport_down_retry
;
36 module_param(qlport_down_retry
, int, S_IRUGO
|S_IRUSR
);
37 MODULE_PARM_DESC(qlport_down_retry
,
38 "Maximum number of command retries to a port that returns "
39 "a PORT-DOWN status.");
41 int ql2xplogiabsentdevice
;
42 module_param(ql2xplogiabsentdevice
, int, S_IRUGO
|S_IWUSR
);
43 MODULE_PARM_DESC(ql2xplogiabsentdevice
,
44 "Option to enable PLOGI to devices that are not present after "
45 "a Fabric scan. This is needed for several broken switches. "
46 "Default is 0 - no PLOGI. 1 - perfom PLOGI.");
48 int ql2xloginretrycount
= 0;
49 module_param(ql2xloginretrycount
, int, S_IRUGO
|S_IRUSR
);
50 MODULE_PARM_DESC(ql2xloginretrycount
,
51 "Specify an alternate value for the NVRAM login retry count.");
53 int ql2xallocfwdump
= 1;
54 module_param(ql2xallocfwdump
, int, S_IRUGO
|S_IRUSR
);
55 MODULE_PARM_DESC(ql2xallocfwdump
,
56 "Option to enable allocation of memory for a firmware dump "
57 "during HBA initialization. Memory allocation requirements "
58 "vary by ISP type. Default is 1 - allocate memory.");
60 int ql2xextended_error_logging
;
61 module_param(ql2xextended_error_logging
, int, S_IRUGO
|S_IWUSR
);
62 MODULE_PARM_DESC(ql2xextended_error_logging
,
63 "Option to enable extended error logging, "
64 "Default is 0 - no logging. 1 - log errors.");
66 static void qla2x00_free_device(scsi_qla_host_t
*);
69 module_param(ql2xfdmienable
, int, S_IRUGO
|S_IRUSR
);
70 MODULE_PARM_DESC(ql2xfdmienable
,
71 "Enables FDMI registratons "
72 "Default is 0 - no FDMI. 1 - perfom FDMI.");
74 #define MAX_Q_DEPTH 32
75 static int ql2xmaxqdepth
= MAX_Q_DEPTH
;
76 module_param(ql2xmaxqdepth
, int, S_IRUGO
|S_IWUSR
);
77 MODULE_PARM_DESC(ql2xmaxqdepth
,
78 "Maximum queue depth to report for target devices.");
80 int ql2xqfullrampup
= 120;
81 module_param(ql2xqfullrampup
, int, S_IRUGO
|S_IWUSR
);
82 MODULE_PARM_DESC(ql2xqfullrampup
,
83 "Number of seconds to wait to begin to ramp-up the queue "
84 "depth for a device after a queue-full condition has been "
85 "detected. Default is 120 seconds.");
87 int ql2xiidmaenable
=1;
88 module_param(ql2xiidmaenable
, int, S_IRUGO
|S_IRUSR
);
89 MODULE_PARM_DESC(ql2xiidmaenable
,
90 "Enables iIDMA settings "
91 "Default is 1 - perform iIDMA. 0 - no iIDMA.");
93 int ql2xmaxqueues
= 1;
94 module_param(ql2xmaxqueues
, int, S_IRUGO
|S_IRUSR
);
95 MODULE_PARM_DESC(ql2xmaxqueues
,
96 "Enables MQ settings "
97 "Default is 1 for single queue. Set it to number \
98 of queues in MQ mode.");
100 * SCSI host template entry points
102 static int qla2xxx_slave_configure(struct scsi_device
* device
);
103 static int qla2xxx_slave_alloc(struct scsi_device
*);
104 static int qla2xxx_scan_finished(struct Scsi_Host
*, unsigned long time
);
105 static void qla2xxx_scan_start(struct Scsi_Host
*);
106 static void qla2xxx_slave_destroy(struct scsi_device
*);
107 static int qla2xxx_queuecommand(struct scsi_cmnd
*cmd
,
108 void (*fn
)(struct scsi_cmnd
*));
109 static int qla2xxx_eh_abort(struct scsi_cmnd
*);
110 static int qla2xxx_eh_device_reset(struct scsi_cmnd
*);
111 static int qla2xxx_eh_target_reset(struct scsi_cmnd
*);
112 static int qla2xxx_eh_bus_reset(struct scsi_cmnd
*);
113 static int qla2xxx_eh_host_reset(struct scsi_cmnd
*);
115 static int qla2x00_change_queue_depth(struct scsi_device
*, int);
116 static int qla2x00_change_queue_type(struct scsi_device
*, int);
118 struct scsi_host_template qla2xxx_driver_template
= {
119 .module
= THIS_MODULE
,
120 .name
= QLA2XXX_DRIVER_NAME
,
121 .queuecommand
= qla2xxx_queuecommand
,
123 .eh_abort_handler
= qla2xxx_eh_abort
,
124 .eh_device_reset_handler
= qla2xxx_eh_device_reset
,
125 .eh_target_reset_handler
= qla2xxx_eh_target_reset
,
126 .eh_bus_reset_handler
= qla2xxx_eh_bus_reset
,
127 .eh_host_reset_handler
= qla2xxx_eh_host_reset
,
129 .slave_configure
= qla2xxx_slave_configure
,
131 .slave_alloc
= qla2xxx_slave_alloc
,
132 .slave_destroy
= qla2xxx_slave_destroy
,
133 .scan_finished
= qla2xxx_scan_finished
,
134 .scan_start
= qla2xxx_scan_start
,
135 .change_queue_depth
= qla2x00_change_queue_depth
,
136 .change_queue_type
= qla2x00_change_queue_type
,
139 .use_clustering
= ENABLE_CLUSTERING
,
140 .sg_tablesize
= SG_ALL
,
142 .max_sectors
= 0xFFFF,
143 .shost_attrs
= qla2x00_host_attrs
,
146 static struct scsi_transport_template
*qla2xxx_transport_template
= NULL
;
147 struct scsi_transport_template
*qla2xxx_transport_vport_template
= NULL
;
149 /* TODO Convert to inlines
155 qla2x00_start_timer(scsi_qla_host_t
*vha
, void *func
, unsigned long interval
)
157 init_timer(&vha
->timer
);
158 vha
->timer
.expires
= jiffies
+ interval
* HZ
;
159 vha
->timer
.data
= (unsigned long)vha
;
160 vha
->timer
.function
= (void (*)(unsigned long))func
;
161 add_timer(&vha
->timer
);
162 vha
->timer_active
= 1;
166 qla2x00_restart_timer(scsi_qla_host_t
*vha
, unsigned long interval
)
168 mod_timer(&vha
->timer
, jiffies
+ interval
* HZ
);
171 static __inline__
void
172 qla2x00_stop_timer(scsi_qla_host_t
*vha
)
174 del_timer_sync(&vha
->timer
);
175 vha
->timer_active
= 0;
178 static int qla2x00_do_dpc(void *data
);
180 static void qla2x00_rst_aen(scsi_qla_host_t
*);
182 static int qla2x00_mem_alloc(struct qla_hw_data
*, uint16_t, uint16_t,
183 struct req_que
**, struct rsp_que
**);
184 static void qla2x00_mem_free(struct qla_hw_data
*);
185 static void qla2x00_sp_free_dma(srb_t
*);
187 /* -------------------------------------------------------------------------- */
188 static int qla2x00_alloc_queues(struct qla_hw_data
*ha
)
190 ha
->req_q_map
= kzalloc(sizeof(struct req_que
*) * ha
->max_queues
,
192 if (!ha
->req_q_map
) {
193 qla_printk(KERN_WARNING
, ha
,
194 "Unable to allocate memory for request queue ptrs\n");
198 ha
->rsp_q_map
= kzalloc(sizeof(struct rsp_que
*) * ha
->max_queues
,
200 if (!ha
->rsp_q_map
) {
201 qla_printk(KERN_WARNING
, ha
,
202 "Unable to allocate memory for response queue ptrs\n");
205 set_bit(0, ha
->rsp_qid_map
);
206 set_bit(0, ha
->req_qid_map
);
210 kfree(ha
->req_q_map
);
211 ha
->req_q_map
= NULL
;
216 static void qla2x00_free_que(struct qla_hw_data
*ha
, struct req_que
*req
,
219 if (rsp
&& rsp
->ring
)
220 dma_free_coherent(&ha
->pdev
->dev
,
221 (rsp
->length
+ 1) * sizeof(response_t
),
222 rsp
->ring
, rsp
->dma
);
226 if (req
&& req
->ring
)
227 dma_free_coherent(&ha
->pdev
->dev
,
228 (req
->length
+ 1) * sizeof(request_t
),
229 req
->ring
, req
->dma
);
235 static void qla2x00_free_queues(struct qla_hw_data
*ha
)
241 for (cnt
= 0; cnt
< ha
->max_queues
; cnt
++) {
242 rsp
= ha
->rsp_q_map
[cnt
];
243 req
= ha
->req_q_map
[cnt
];
244 qla2x00_free_que(ha
, req
, rsp
);
246 kfree(ha
->rsp_q_map
);
247 ha
->rsp_q_map
= NULL
;
249 kfree(ha
->req_q_map
);
250 ha
->req_q_map
= NULL
;
254 qla2x00_pci_info_str(struct scsi_qla_host
*vha
, char *str
)
256 struct qla_hw_data
*ha
= vha
->hw
;
257 static char *pci_bus_modes
[] = {
258 "33", "66", "100", "133",
263 pci_bus
= (ha
->pci_attr
& (BIT_9
| BIT_10
)) >> 9;
266 strcat(str
, pci_bus_modes
[pci_bus
]);
268 pci_bus
= (ha
->pci_attr
& BIT_8
) >> 8;
270 strcat(str
, pci_bus_modes
[pci_bus
]);
272 strcat(str
, " MHz)");
278 qla24xx_pci_info_str(struct scsi_qla_host
*vha
, char *str
)
280 static char *pci_bus_modes
[] = { "33", "66", "100", "133", };
281 struct qla_hw_data
*ha
= vha
->hw
;
285 pcie_reg
= pci_find_capability(ha
->pdev
, PCI_CAP_ID_EXP
);
288 uint16_t pcie_lstat
, lspeed
, lwidth
;
291 pci_read_config_word(ha
->pdev
, pcie_reg
, &pcie_lstat
);
292 lspeed
= pcie_lstat
& (BIT_0
| BIT_1
| BIT_2
| BIT_3
);
293 lwidth
= (pcie_lstat
&
294 (BIT_4
| BIT_5
| BIT_6
| BIT_7
| BIT_8
| BIT_9
)) >> 4;
296 strcpy(str
, "PCIe (");
298 strcat(str
, "2.5GT/s ");
299 else if (lspeed
== 2)
300 strcat(str
, "5.0GT/s ");
302 strcat(str
, "<unknown> ");
303 snprintf(lwstr
, sizeof(lwstr
), "x%d)", lwidth
);
310 pci_bus
= (ha
->pci_attr
& CSRX_PCIX_BUS_MODE_MASK
) >> 8;
311 if (pci_bus
== 0 || pci_bus
== 8) {
313 strcat(str
, pci_bus_modes
[pci_bus
>> 3]);
317 strcat(str
, "Mode 2");
319 strcat(str
, "Mode 1");
321 strcat(str
, pci_bus_modes
[pci_bus
& ~BIT_2
]);
323 strcat(str
, " MHz)");
329 qla2x00_fw_version_str(struct scsi_qla_host
*vha
, char *str
)
332 struct qla_hw_data
*ha
= vha
->hw
;
334 sprintf(str
, "%d.%02d.%02d ", ha
->fw_major_version
,
335 ha
->fw_minor_version
,
336 ha
->fw_subminor_version
);
338 if (ha
->fw_attributes
& BIT_9
) {
343 switch (ha
->fw_attributes
& 0xFF) {
357 sprintf(un_str
, "(%x)", ha
->fw_attributes
);
361 if (ha
->fw_attributes
& 0x100)
368 qla24xx_fw_version_str(struct scsi_qla_host
*vha
, char *str
)
370 struct qla_hw_data
*ha
= vha
->hw
;
372 sprintf(str
, "%d.%02d.%02d (%x)", ha
->fw_major_version
,
373 ha
->fw_minor_version
, ha
->fw_subminor_version
, ha
->fw_attributes
);
377 static inline srb_t
*
378 qla2x00_get_new_sp(scsi_qla_host_t
*vha
, fc_port_t
*fcport
,
379 struct scsi_cmnd
*cmd
, void (*done
)(struct scsi_cmnd
*))
382 struct qla_hw_data
*ha
= vha
->hw
;
384 sp
= mempool_alloc(ha
->srb_mempool
, GFP_ATOMIC
);
390 sp
->que
= ha
->req_q_map
[0];
392 CMD_SP(cmd
) = (void *)sp
;
393 cmd
->scsi_done
= done
;
399 qla2xxx_queuecommand(struct scsi_cmnd
*cmd
, void (*done
)(struct scsi_cmnd
*))
401 scsi_qla_host_t
*vha
= shost_priv(cmd
->device
->host
);
402 fc_port_t
*fcport
= (struct fc_port
*) cmd
->device
->hostdata
;
403 struct fc_rport
*rport
= starget_to_rport(scsi_target(cmd
->device
));
404 struct qla_hw_data
*ha
= vha
->hw
;
405 struct scsi_qla_host
*base_vha
= pci_get_drvdata(ha
->pdev
);
409 if (unlikely(pci_channel_offline(ha
->pdev
))) {
410 cmd
->result
= DID_REQUEUE
<< 16;
411 goto qc24_fail_command
;
414 rval
= fc_remote_port_chkready(rport
);
417 goto qc24_fail_command
;
420 /* Close window on fcport/rport state-transitioning. */
422 goto qc24_target_busy
;
424 if (atomic_read(&fcport
->state
) != FCS_ONLINE
) {
425 if (atomic_read(&fcport
->state
) == FCS_DEVICE_DEAD
||
426 atomic_read(&base_vha
->loop_state
) == LOOP_DEAD
) {
427 cmd
->result
= DID_NO_CONNECT
<< 16;
428 goto qc24_fail_command
;
430 goto qc24_target_busy
;
433 spin_unlock_irq(vha
->host
->host_lock
);
435 sp
= qla2x00_get_new_sp(base_vha
, fcport
, cmd
, done
);
437 goto qc24_host_busy_lock
;
439 rval
= ha
->isp_ops
->start_scsi(sp
);
440 if (rval
!= QLA_SUCCESS
)
441 goto qc24_host_busy_free_sp
;
443 spin_lock_irq(vha
->host
->host_lock
);
447 qc24_host_busy_free_sp
:
448 qla2x00_sp_free_dma(sp
);
449 mempool_free(sp
, ha
->srb_mempool
);
452 spin_lock_irq(vha
->host
->host_lock
);
453 return SCSI_MLQUEUE_HOST_BUSY
;
456 return SCSI_MLQUEUE_TARGET_BUSY
;
466 * qla2x00_eh_wait_on_command
467 * Waits for the command to be returned by the Firmware for some
471 * cmd = Scsi Command to wait on.
478 qla2x00_eh_wait_on_command(struct scsi_cmnd
*cmd
)
480 #define ABORT_POLLING_PERIOD 1000
481 #define ABORT_WAIT_ITER ((10 * 1000) / (ABORT_POLLING_PERIOD))
482 unsigned long wait_iter
= ABORT_WAIT_ITER
;
483 int ret
= QLA_SUCCESS
;
485 while (CMD_SP(cmd
)) {
486 msleep(ABORT_POLLING_PERIOD
);
492 ret
= QLA_FUNCTION_FAILED
;
498 * qla2x00_wait_for_hba_online
499 * Wait till the HBA is online after going through
500 * <= MAX_RETRIES_OF_ISP_ABORT or
501 * finally HBA is disabled ie marked offline
504 * ha - pointer to host adapter structure
507 * Does context switching-Release SPIN_LOCK
508 * (if any) before calling this routine.
511 * Success (Adapter is online) : 0
512 * Failed (Adapter is offline/disabled) : 1
515 qla2x00_wait_for_hba_online(scsi_qla_host_t
*vha
)
518 unsigned long wait_online
;
519 struct qla_hw_data
*ha
= vha
->hw
;
520 scsi_qla_host_t
*base_vha
= pci_get_drvdata(ha
->pdev
);
522 wait_online
= jiffies
+ (MAX_LOOP_TIMEOUT
* HZ
);
523 while (((test_bit(ISP_ABORT_NEEDED
, &base_vha
->dpc_flags
)) ||
524 test_bit(ABORT_ISP_ACTIVE
, &base_vha
->dpc_flags
) ||
525 test_bit(ISP_ABORT_RETRY
, &base_vha
->dpc_flags
) ||
526 ha
->dpc_active
) && time_before(jiffies
, wait_online
)) {
530 if (base_vha
->flags
.online
)
531 return_status
= QLA_SUCCESS
;
533 return_status
= QLA_FUNCTION_FAILED
;
535 return (return_status
);
539 qla2x00_wait_for_chip_reset(scsi_qla_host_t
*vha
)
542 unsigned long wait_reset
;
543 struct qla_hw_data
*ha
= vha
->hw
;
544 scsi_qla_host_t
*base_vha
= pci_get_drvdata(ha
->pdev
);
546 wait_reset
= jiffies
+ (MAX_LOOP_TIMEOUT
* HZ
);
547 while (((test_bit(ISP_ABORT_NEEDED
, &base_vha
->dpc_flags
)) ||
548 test_bit(ABORT_ISP_ACTIVE
, &base_vha
->dpc_flags
) ||
549 test_bit(ISP_ABORT_RETRY
, &base_vha
->dpc_flags
) ||
550 ha
->dpc_active
) && time_before(jiffies
, wait_reset
)) {
554 if (!test_bit(ISP_ABORT_NEEDED
, &base_vha
->dpc_flags
) &&
555 ha
->flags
.chip_reset_done
)
558 if (ha
->flags
.chip_reset_done
)
559 return_status
= QLA_SUCCESS
;
561 return_status
= QLA_FUNCTION_FAILED
;
563 return return_status
;
567 * qla2x00_wait_for_loop_ready
568 * Wait for MAX_LOOP_TIMEOUT(5 min) value for loop
569 * to be in LOOP_READY state.
571 * ha - pointer to host adapter structure
574 * Does context switching-Release SPIN_LOCK
575 * (if any) before calling this routine.
579 * Success (LOOP_READY) : 0
580 * Failed (LOOP_NOT_READY) : 1
583 qla2x00_wait_for_loop_ready(scsi_qla_host_t
*vha
)
585 int return_status
= QLA_SUCCESS
;
586 unsigned long loop_timeout
;
587 struct qla_hw_data
*ha
= vha
->hw
;
588 scsi_qla_host_t
*base_vha
= pci_get_drvdata(ha
->pdev
);
590 /* wait for 5 min at the max for loop to be ready */
591 loop_timeout
= jiffies
+ (MAX_LOOP_TIMEOUT
* HZ
);
593 while ((!atomic_read(&base_vha
->loop_down_timer
) &&
594 atomic_read(&base_vha
->loop_state
) == LOOP_DOWN
) ||
595 atomic_read(&base_vha
->loop_state
) != LOOP_READY
) {
596 if (atomic_read(&base_vha
->loop_state
) == LOOP_DEAD
) {
597 return_status
= QLA_FUNCTION_FAILED
;
601 if (time_after_eq(jiffies
, loop_timeout
)) {
602 return_status
= QLA_FUNCTION_FAILED
;
606 return (return_status
);
610 qla2x00_abort_fcport_cmds(fc_port_t
*fcport
)
615 scsi_qla_host_t
*vha
= fcport
->vha
;
616 struct qla_hw_data
*ha
= vha
->hw
;
619 spin_lock_irqsave(&ha
->hardware_lock
, flags
);
620 for (que
= 0; que
< QLA_MAX_HOST_QUES
; que
++) {
621 id
= vha
->req_ques
[que
];
622 req
= ha
->req_q_map
[id
];
625 for (cnt
= 1; cnt
< MAX_OUTSTANDING_COMMANDS
; cnt
++) {
626 sp
= req
->outstanding_cmds
[cnt
];
629 if (sp
->fcport
!= fcport
)
632 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
633 if (ha
->isp_ops
->abort_command(vha
, sp
, req
)) {
634 DEBUG2(qla_printk(KERN_WARNING
, ha
,
635 "Abort failed -- %lx\n",
636 sp
->cmd
->serial_number
));
638 if (qla2x00_eh_wait_on_command(sp
->cmd
) !=
640 DEBUG2(qla_printk(KERN_WARNING
, ha
,
641 "Abort failed while waiting -- %lx\n",
642 sp
->cmd
->serial_number
));
644 spin_lock_irqsave(&ha
->hardware_lock
, flags
);
647 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
651 qla2x00_block_error_handler(struct scsi_cmnd
*cmnd
)
653 struct Scsi_Host
*shost
= cmnd
->device
->host
;
654 struct fc_rport
*rport
= starget_to_rport(scsi_target(cmnd
->device
));
657 spin_lock_irqsave(shost
->host_lock
, flags
);
658 while (rport
->port_state
== FC_PORTSTATE_BLOCKED
) {
659 spin_unlock_irqrestore(shost
->host_lock
, flags
);
661 spin_lock_irqsave(shost
->host_lock
, flags
);
663 spin_unlock_irqrestore(shost
->host_lock
, flags
);
667 /**************************************************************************
671 * The abort function will abort the specified command.
674 * cmd = Linux SCSI command packet to be aborted.
677 * Either SUCCESS or FAILED.
680 * Only return FAILED if command not returned by firmware.
681 **************************************************************************/
683 qla2xxx_eh_abort(struct scsi_cmnd
*cmd
)
685 scsi_qla_host_t
*vha
= shost_priv(cmd
->device
->host
);
688 unsigned int id
, lun
;
689 unsigned long serial
;
692 struct qla_hw_data
*ha
= vha
->hw
;
696 qla2x00_block_error_handler(cmd
);
703 id
= cmd
->device
->id
;
704 lun
= cmd
->device
->lun
;
705 serial
= cmd
->serial_number
;
706 spt
= (srb_t
*) CMD_SP(cmd
);
711 /* Check active list for command command. */
712 spin_lock_irqsave(&ha
->hardware_lock
, flags
);
713 for (i
= 1; i
< MAX_OUTSTANDING_COMMANDS
; i
++) {
714 sp
= req
->outstanding_cmds
[i
];
722 DEBUG2(printk("%s(%ld): aborting sp %p from RISC."
723 " pid=%ld.\n", __func__
, vha
->host_no
, sp
, serial
));
725 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
726 if (ha
->isp_ops
->abort_command(vha
, sp
, req
)) {
727 DEBUG2(printk("%s(%ld): abort_command "
728 "mbx failed.\n", __func__
, vha
->host_no
));
731 DEBUG3(printk("%s(%ld): abort_command "
732 "mbx success.\n", __func__
, vha
->host_no
));
735 spin_lock_irqsave(&ha
->hardware_lock
, flags
);
738 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
740 /* Wait for the command to be returned. */
742 if (qla2x00_eh_wait_on_command(cmd
) != QLA_SUCCESS
) {
743 qla_printk(KERN_ERR
, ha
,
744 "scsi(%ld:%d:%d): Abort handler timed out -- %lx "
745 "%x.\n", vha
->host_no
, id
, lun
, serial
, ret
);
750 qla_printk(KERN_INFO
, ha
,
751 "scsi(%ld:%d:%d): Abort command issued -- %d %lx %x.\n",
752 vha
->host_no
, id
, lun
, wait
, serial
, ret
);
757 enum nexus_wait_type
{
764 qla2x00_eh_wait_for_pending_commands(scsi_qla_host_t
*vha
, unsigned int t
,
765 unsigned int l
, srb_t
*sp
, enum nexus_wait_type type
)
767 int cnt
, match
, status
;
769 struct qla_hw_data
*ha
= vha
->hw
;
772 status
= QLA_SUCCESS
;
776 spin_lock_irqsave(&ha
->hardware_lock
, flags
);
778 for (cnt
= 1; status
== QLA_SUCCESS
&&
779 cnt
< MAX_OUTSTANDING_COMMANDS
; cnt
++) {
780 sp
= req
->outstanding_cmds
[cnt
];
784 if (vha
->vp_idx
!= sp
->fcport
->vha
->vp_idx
)
792 match
= sp
->cmd
->device
->id
== t
;
795 match
= (sp
->cmd
->device
->id
== t
&&
796 sp
->cmd
->device
->lun
== l
);
802 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
803 status
= qla2x00_eh_wait_on_command(sp
->cmd
);
804 spin_lock_irqsave(&ha
->hardware_lock
, flags
);
806 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
811 static char *reset_errors
[] = {
814 "Task management failed",
815 "Waiting for command completions",
819 __qla2xxx_eh_generic_reset(char *name
, enum nexus_wait_type type
,
820 struct scsi_cmnd
*cmd
, int (*do_reset
)(struct fc_port
*, unsigned int))
822 scsi_qla_host_t
*vha
= shost_priv(cmd
->device
->host
);
823 fc_port_t
*fcport
= (struct fc_port
*) cmd
->device
->hostdata
;
826 qla2x00_block_error_handler(cmd
);
831 qla_printk(KERN_INFO
, vha
->hw
, "scsi(%ld:%d:%d): %s RESET ISSUED.\n",
832 vha
->host_no
, cmd
->device
->id
, cmd
->device
->lun
, name
);
835 if (qla2x00_wait_for_hba_online(vha
) != QLA_SUCCESS
)
836 goto eh_reset_failed
;
838 if (qla2x00_wait_for_loop_ready(vha
) != QLA_SUCCESS
)
839 goto eh_reset_failed
;
841 if (do_reset(fcport
, cmd
->device
->lun
) != QLA_SUCCESS
)
842 goto eh_reset_failed
;
844 if (qla2x00_eh_wait_for_pending_commands(vha
, cmd
->device
->id
,
845 cmd
->device
->lun
, (srb_t
*) CMD_SP(cmd
), type
) != QLA_SUCCESS
)
846 goto eh_reset_failed
;
848 qla_printk(KERN_INFO
, vha
->hw
, "scsi(%ld:%d:%d): %s RESET SUCCEEDED.\n",
849 vha
->host_no
, cmd
->device
->id
, cmd
->device
->lun
, name
);
854 qla_printk(KERN_INFO
, vha
->hw
, "scsi(%ld:%d:%d): %s RESET FAILED: %s.\n"
855 , vha
->host_no
, cmd
->device
->id
, cmd
->device
->lun
, name
,
861 qla2xxx_eh_device_reset(struct scsi_cmnd
*cmd
)
863 scsi_qla_host_t
*vha
= shost_priv(cmd
->device
->host
);
864 struct qla_hw_data
*ha
= vha
->hw
;
866 return __qla2xxx_eh_generic_reset("DEVICE", WAIT_LUN
, cmd
,
867 ha
->isp_ops
->lun_reset
);
871 qla2xxx_eh_target_reset(struct scsi_cmnd
*cmd
)
873 scsi_qla_host_t
*vha
= shost_priv(cmd
->device
->host
);
874 struct qla_hw_data
*ha
= vha
->hw
;
876 return __qla2xxx_eh_generic_reset("TARGET", WAIT_TARGET
, cmd
,
877 ha
->isp_ops
->target_reset
);
880 /**************************************************************************
881 * qla2xxx_eh_bus_reset
884 * The bus reset function will reset the bus and abort any executing
888 * cmd = Linux SCSI command packet of the command that cause the
892 * SUCCESS/FAILURE (defined as macro in scsi.h).
894 **************************************************************************/
896 qla2xxx_eh_bus_reset(struct scsi_cmnd
*cmd
)
898 scsi_qla_host_t
*vha
= shost_priv(cmd
->device
->host
);
899 fc_port_t
*fcport
= (struct fc_port
*) cmd
->device
->hostdata
;
901 unsigned int id
, lun
;
902 unsigned long serial
;
903 srb_t
*sp
= (srb_t
*) CMD_SP(cmd
);
905 qla2x00_block_error_handler(cmd
);
907 id
= cmd
->device
->id
;
908 lun
= cmd
->device
->lun
;
909 serial
= cmd
->serial_number
;
914 qla_printk(KERN_INFO
, vha
->hw
,
915 "scsi(%ld:%d:%d): BUS RESET ISSUED.\n", vha
->host_no
, id
, lun
);
917 if (qla2x00_wait_for_hba_online(vha
) != QLA_SUCCESS
) {
918 DEBUG2(printk("%s failed:board disabled\n",__func__
));
919 goto eh_bus_reset_done
;
922 if (qla2x00_wait_for_loop_ready(vha
) == QLA_SUCCESS
) {
923 if (qla2x00_loop_reset(vha
) == QLA_SUCCESS
)
927 goto eh_bus_reset_done
;
929 /* Flush outstanding commands. */
930 if (qla2x00_eh_wait_for_pending_commands(vha
, 0, 0, sp
, WAIT_HOST
) !=
935 qla_printk(KERN_INFO
, vha
->hw
, "%s: reset %s\n", __func__
,
936 (ret
== FAILED
) ? "failed" : "succeded");
941 /**************************************************************************
942 * qla2xxx_eh_host_reset
945 * The reset function will reset the Adapter.
948 * cmd = Linux SCSI command packet of the command that cause the
952 * Either SUCCESS or FAILED.
955 **************************************************************************/
957 qla2xxx_eh_host_reset(struct scsi_cmnd
*cmd
)
959 scsi_qla_host_t
*vha
= shost_priv(cmd
->device
->host
);
960 fc_port_t
*fcport
= (struct fc_port
*) cmd
->device
->hostdata
;
961 struct qla_hw_data
*ha
= vha
->hw
;
963 unsigned int id
, lun
;
964 unsigned long serial
;
965 srb_t
*sp
= (srb_t
*) CMD_SP(cmd
);
966 scsi_qla_host_t
*base_vha
= pci_get_drvdata(ha
->pdev
);
968 qla2x00_block_error_handler(cmd
);
970 id
= cmd
->device
->id
;
971 lun
= cmd
->device
->lun
;
972 serial
= cmd
->serial_number
;
977 qla_printk(KERN_INFO
, ha
,
978 "scsi(%ld:%d:%d): ADAPTER RESET ISSUED.\n", vha
->host_no
, id
, lun
);
980 if (qla2x00_wait_for_hba_online(vha
) != QLA_SUCCESS
)
981 goto eh_host_reset_lock
;
984 * Fixme-may be dpc thread is active and processing
985 * loop_resync,so wait a while for it to
986 * be completed and then issue big hammer.Otherwise
987 * it may cause I/O failure as big hammer marks the
988 * devices as lost kicking of the port_down_timer
989 * while dpc is stuck for the mailbox to complete.
991 qla2x00_wait_for_loop_ready(vha
);
992 if (vha
!= base_vha
) {
993 if (qla2x00_vp_abort_isp(vha
))
994 goto eh_host_reset_lock
;
996 set_bit(ABORT_ISP_ACTIVE
, &base_vha
->dpc_flags
);
997 if (qla2x00_abort_isp(base_vha
)) {
998 clear_bit(ABORT_ISP_ACTIVE
, &base_vha
->dpc_flags
);
999 /* failed. schedule dpc to try */
1000 set_bit(ISP_ABORT_NEEDED
, &base_vha
->dpc_flags
);
1002 if (qla2x00_wait_for_hba_online(vha
) != QLA_SUCCESS
)
1003 goto eh_host_reset_lock
;
1005 clear_bit(ABORT_ISP_ACTIVE
, &base_vha
->dpc_flags
);
1008 /* Waiting for command to be returned to OS.*/
1009 if (qla2x00_eh_wait_for_pending_commands(vha
, 0, 0, sp
, WAIT_HOST
) ==
1014 qla_printk(KERN_INFO
, ha
, "%s: reset %s\n", __func__
,
1015 (ret
== FAILED
) ? "failed" : "succeded");
1021 * qla2x00_loop_reset
1025 * ha = adapter block pointer.
1031 qla2x00_loop_reset(scsi_qla_host_t
*vha
)
1034 struct fc_port
*fcport
;
1035 struct qla_hw_data
*ha
= vha
->hw
;
1037 if (ha
->flags
.enable_lip_full_login
&& !vha
->vp_idx
) {
1038 ret
= qla2x00_full_login_lip(vha
);
1039 if (ret
!= QLA_SUCCESS
) {
1040 DEBUG2_3(printk("%s(%ld): failed: "
1041 "full_login_lip=%d.\n", __func__
, vha
->host_no
,
1044 atomic_set(&vha
->loop_state
, LOOP_DOWN
);
1045 atomic_set(&vha
->loop_down_timer
, LOOP_DOWN_TIME
);
1046 qla2x00_mark_all_devices_lost(vha
, 0);
1047 qla2x00_wait_for_loop_ready(vha
);
1050 if (ha
->flags
.enable_lip_reset
&& !vha
->vp_idx
) {
1051 ret
= qla2x00_lip_reset(vha
);
1052 if (ret
!= QLA_SUCCESS
) {
1053 DEBUG2_3(printk("%s(%ld): failed: "
1054 "lip_reset=%d.\n", __func__
, vha
->host_no
, ret
));
1056 qla2x00_wait_for_loop_ready(vha
);
1059 if (ha
->flags
.enable_target_reset
) {
1060 list_for_each_entry(fcport
, &vha
->vp_fcports
, list
) {
1061 if (fcport
->port_type
!= FCT_TARGET
)
1064 ret
= ha
->isp_ops
->target_reset(fcport
, 0);
1065 if (ret
!= QLA_SUCCESS
) {
1066 DEBUG2_3(printk("%s(%ld): bus_reset failed: "
1067 "target_reset=%d d_id=%x.\n", __func__
,
1068 vha
->host_no
, ret
, fcport
->d_id
.b24
));
1072 /* Issue marker command only when we are going to start the I/O */
1073 vha
->marker_needed
= 1;
1079 qla2x00_abort_all_cmds(scsi_qla_host_t
*vha
, int res
)
1082 unsigned long flags
;
1084 struct qla_hw_data
*ha
= vha
->hw
;
1085 struct req_que
*req
;
1087 spin_lock_irqsave(&ha
->hardware_lock
, flags
);
1088 for (que
= 0; que
< ha
->max_queues
; que
++) {
1089 req
= ha
->req_q_map
[que
];
1092 for (cnt
= 1; cnt
< MAX_OUTSTANDING_COMMANDS
; cnt
++) {
1093 sp
= req
->outstanding_cmds
[cnt
];
1095 req
->outstanding_cmds
[cnt
] = NULL
;
1096 sp
->cmd
->result
= res
;
1097 qla2x00_sp_compl(ha
, sp
);
1101 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
1105 qla2xxx_slave_alloc(struct scsi_device
*sdev
)
1107 struct fc_rport
*rport
= starget_to_rport(scsi_target(sdev
));
1109 if (!rport
|| fc_remote_port_chkready(rport
))
1112 sdev
->hostdata
= *(fc_port_t
**)rport
->dd_data
;
1118 qla2xxx_slave_configure(struct scsi_device
*sdev
)
1120 scsi_qla_host_t
*vha
= shost_priv(sdev
->host
);
1121 struct qla_hw_data
*ha
= vha
->hw
;
1122 struct fc_rport
*rport
= starget_to_rport(sdev
->sdev_target
);
1123 struct req_que
*req
= ha
->req_q_map
[vha
->req_ques
[0]];
1125 if (sdev
->tagged_supported
)
1126 scsi_activate_tcq(sdev
, req
->max_q_depth
);
1128 scsi_deactivate_tcq(sdev
, req
->max_q_depth
);
1130 rport
->dev_loss_tmo
= ha
->port_down_retry_count
;
1136 qla2xxx_slave_destroy(struct scsi_device
*sdev
)
1138 sdev
->hostdata
= NULL
;
1142 qla2x00_change_queue_depth(struct scsi_device
*sdev
, int qdepth
)
1144 scsi_adjust_queue_depth(sdev
, scsi_get_tag_type(sdev
), qdepth
);
1145 return sdev
->queue_depth
;
1149 qla2x00_change_queue_type(struct scsi_device
*sdev
, int tag_type
)
1151 if (sdev
->tagged_supported
) {
1152 scsi_set_tag_type(sdev
, tag_type
);
1154 scsi_activate_tcq(sdev
, sdev
->queue_depth
);
1156 scsi_deactivate_tcq(sdev
, sdev
->queue_depth
);
1164 * qla2x00_config_dma_addressing() - Configure OS DMA addressing method.
1167 * At exit, the @ha's flags.enable_64bit_addressing set to indicated
1168 * supported addressing method.
1171 qla2x00_config_dma_addressing(struct qla_hw_data
*ha
)
1173 /* Assume a 32bit DMA mask. */
1174 ha
->flags
.enable_64bit_addressing
= 0;
1176 if (!dma_set_mask(&ha
->pdev
->dev
, DMA_64BIT_MASK
)) {
1177 /* Any upper-dword bits set? */
1178 if (MSD(dma_get_required_mask(&ha
->pdev
->dev
)) &&
1179 !pci_set_consistent_dma_mask(ha
->pdev
, DMA_64BIT_MASK
)) {
1180 /* Ok, a 64bit DMA mask is applicable. */
1181 ha
->flags
.enable_64bit_addressing
= 1;
1182 ha
->isp_ops
->calc_req_entries
= qla2x00_calc_iocbs_64
;
1183 ha
->isp_ops
->build_iocbs
= qla2x00_build_scsi_iocbs_64
;
1188 dma_set_mask(&ha
->pdev
->dev
, DMA_32BIT_MASK
);
1189 pci_set_consistent_dma_mask(ha
->pdev
, DMA_32BIT_MASK
);
1193 qla2x00_enable_intrs(struct qla_hw_data
*ha
)
1195 unsigned long flags
= 0;
1196 struct device_reg_2xxx __iomem
*reg
= &ha
->iobase
->isp
;
1198 spin_lock_irqsave(&ha
->hardware_lock
, flags
);
1199 ha
->interrupts_on
= 1;
1200 /* enable risc and host interrupts */
1201 WRT_REG_WORD(®
->ictrl
, ICR_EN_INT
| ICR_EN_RISC
);
1202 RD_REG_WORD(®
->ictrl
);
1203 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
1208 qla2x00_disable_intrs(struct qla_hw_data
*ha
)
1210 unsigned long flags
= 0;
1211 struct device_reg_2xxx __iomem
*reg
= &ha
->iobase
->isp
;
1213 spin_lock_irqsave(&ha
->hardware_lock
, flags
);
1214 ha
->interrupts_on
= 0;
1215 /* disable risc and host interrupts */
1216 WRT_REG_WORD(®
->ictrl
, 0);
1217 RD_REG_WORD(®
->ictrl
);
1218 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
1222 qla24xx_enable_intrs(struct qla_hw_data
*ha
)
1224 unsigned long flags
= 0;
1225 struct device_reg_24xx __iomem
*reg
= &ha
->iobase
->isp24
;
1227 spin_lock_irqsave(&ha
->hardware_lock
, flags
);
1228 ha
->interrupts_on
= 1;
1229 WRT_REG_DWORD(®
->ictrl
, ICRX_EN_RISC_INT
);
1230 RD_REG_DWORD(®
->ictrl
);
1231 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
1235 qla24xx_disable_intrs(struct qla_hw_data
*ha
)
1237 unsigned long flags
= 0;
1238 struct device_reg_24xx __iomem
*reg
= &ha
->iobase
->isp24
;
1240 if (IS_NOPOLLING_TYPE(ha
))
1242 spin_lock_irqsave(&ha
->hardware_lock
, flags
);
1243 ha
->interrupts_on
= 0;
1244 WRT_REG_DWORD(®
->ictrl
, 0);
1245 RD_REG_DWORD(®
->ictrl
);
1246 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
1249 static struct isp_operations qla2100_isp_ops
= {
1250 .pci_config
= qla2100_pci_config
,
1251 .reset_chip
= qla2x00_reset_chip
,
1252 .chip_diag
= qla2x00_chip_diag
,
1253 .config_rings
= qla2x00_config_rings
,
1254 .reset_adapter
= qla2x00_reset_adapter
,
1255 .nvram_config
= qla2x00_nvram_config
,
1256 .update_fw_options
= qla2x00_update_fw_options
,
1257 .load_risc
= qla2x00_load_risc
,
1258 .pci_info_str
= qla2x00_pci_info_str
,
1259 .fw_version_str
= qla2x00_fw_version_str
,
1260 .intr_handler
= qla2100_intr_handler
,
1261 .enable_intrs
= qla2x00_enable_intrs
,
1262 .disable_intrs
= qla2x00_disable_intrs
,
1263 .abort_command
= qla2x00_abort_command
,
1264 .target_reset
= qla2x00_abort_target
,
1265 .lun_reset
= qla2x00_lun_reset
,
1266 .fabric_login
= qla2x00_login_fabric
,
1267 .fabric_logout
= qla2x00_fabric_logout
,
1268 .calc_req_entries
= qla2x00_calc_iocbs_32
,
1269 .build_iocbs
= qla2x00_build_scsi_iocbs_32
,
1270 .prep_ms_iocb
= qla2x00_prep_ms_iocb
,
1271 .prep_ms_fdmi_iocb
= qla2x00_prep_ms_fdmi_iocb
,
1272 .read_nvram
= qla2x00_read_nvram_data
,
1273 .write_nvram
= qla2x00_write_nvram_data
,
1274 .fw_dump
= qla2100_fw_dump
,
1277 .beacon_blink
= NULL
,
1278 .read_optrom
= qla2x00_read_optrom_data
,
1279 .write_optrom
= qla2x00_write_optrom_data
,
1280 .get_flash_version
= qla2x00_get_flash_version
,
1281 .start_scsi
= qla2x00_start_scsi
,
1284 static struct isp_operations qla2300_isp_ops
= {
1285 .pci_config
= qla2300_pci_config
,
1286 .reset_chip
= qla2x00_reset_chip
,
1287 .chip_diag
= qla2x00_chip_diag
,
1288 .config_rings
= qla2x00_config_rings
,
1289 .reset_adapter
= qla2x00_reset_adapter
,
1290 .nvram_config
= qla2x00_nvram_config
,
1291 .update_fw_options
= qla2x00_update_fw_options
,
1292 .load_risc
= qla2x00_load_risc
,
1293 .pci_info_str
= qla2x00_pci_info_str
,
1294 .fw_version_str
= qla2x00_fw_version_str
,
1295 .intr_handler
= qla2300_intr_handler
,
1296 .enable_intrs
= qla2x00_enable_intrs
,
1297 .disable_intrs
= qla2x00_disable_intrs
,
1298 .abort_command
= qla2x00_abort_command
,
1299 .target_reset
= qla2x00_abort_target
,
1300 .lun_reset
= qla2x00_lun_reset
,
1301 .fabric_login
= qla2x00_login_fabric
,
1302 .fabric_logout
= qla2x00_fabric_logout
,
1303 .calc_req_entries
= qla2x00_calc_iocbs_32
,
1304 .build_iocbs
= qla2x00_build_scsi_iocbs_32
,
1305 .prep_ms_iocb
= qla2x00_prep_ms_iocb
,
1306 .prep_ms_fdmi_iocb
= qla2x00_prep_ms_fdmi_iocb
,
1307 .read_nvram
= qla2x00_read_nvram_data
,
1308 .write_nvram
= qla2x00_write_nvram_data
,
1309 .fw_dump
= qla2300_fw_dump
,
1310 .beacon_on
= qla2x00_beacon_on
,
1311 .beacon_off
= qla2x00_beacon_off
,
1312 .beacon_blink
= qla2x00_beacon_blink
,
1313 .read_optrom
= qla2x00_read_optrom_data
,
1314 .write_optrom
= qla2x00_write_optrom_data
,
1315 .get_flash_version
= qla2x00_get_flash_version
,
1316 .start_scsi
= qla2x00_start_scsi
,
1319 static struct isp_operations qla24xx_isp_ops
= {
1320 .pci_config
= qla24xx_pci_config
,
1321 .reset_chip
= qla24xx_reset_chip
,
1322 .chip_diag
= qla24xx_chip_diag
,
1323 .config_rings
= qla24xx_config_rings
,
1324 .reset_adapter
= qla24xx_reset_adapter
,
1325 .nvram_config
= qla24xx_nvram_config
,
1326 .update_fw_options
= qla24xx_update_fw_options
,
1327 .load_risc
= qla24xx_load_risc
,
1328 .pci_info_str
= qla24xx_pci_info_str
,
1329 .fw_version_str
= qla24xx_fw_version_str
,
1330 .intr_handler
= qla24xx_intr_handler
,
1331 .enable_intrs
= qla24xx_enable_intrs
,
1332 .disable_intrs
= qla24xx_disable_intrs
,
1333 .abort_command
= qla24xx_abort_command
,
1334 .target_reset
= qla24xx_abort_target
,
1335 .lun_reset
= qla24xx_lun_reset
,
1336 .fabric_login
= qla24xx_login_fabric
,
1337 .fabric_logout
= qla24xx_fabric_logout
,
1338 .calc_req_entries
= NULL
,
1339 .build_iocbs
= NULL
,
1340 .prep_ms_iocb
= qla24xx_prep_ms_iocb
,
1341 .prep_ms_fdmi_iocb
= qla24xx_prep_ms_fdmi_iocb
,
1342 .read_nvram
= qla24xx_read_nvram_data
,
1343 .write_nvram
= qla24xx_write_nvram_data
,
1344 .fw_dump
= qla24xx_fw_dump
,
1345 .beacon_on
= qla24xx_beacon_on
,
1346 .beacon_off
= qla24xx_beacon_off
,
1347 .beacon_blink
= qla24xx_beacon_blink
,
1348 .read_optrom
= qla24xx_read_optrom_data
,
1349 .write_optrom
= qla24xx_write_optrom_data
,
1350 .get_flash_version
= qla24xx_get_flash_version
,
1351 .start_scsi
= qla24xx_start_scsi
,
1354 static struct isp_operations qla25xx_isp_ops
= {
1355 .pci_config
= qla25xx_pci_config
,
1356 .reset_chip
= qla24xx_reset_chip
,
1357 .chip_diag
= qla24xx_chip_diag
,
1358 .config_rings
= qla24xx_config_rings
,
1359 .reset_adapter
= qla24xx_reset_adapter
,
1360 .nvram_config
= qla24xx_nvram_config
,
1361 .update_fw_options
= qla24xx_update_fw_options
,
1362 .load_risc
= qla24xx_load_risc
,
1363 .pci_info_str
= qla24xx_pci_info_str
,
1364 .fw_version_str
= qla24xx_fw_version_str
,
1365 .intr_handler
= qla24xx_intr_handler
,
1366 .enable_intrs
= qla24xx_enable_intrs
,
1367 .disable_intrs
= qla24xx_disable_intrs
,
1368 .abort_command
= qla24xx_abort_command
,
1369 .target_reset
= qla24xx_abort_target
,
1370 .lun_reset
= qla24xx_lun_reset
,
1371 .fabric_login
= qla24xx_login_fabric
,
1372 .fabric_logout
= qla24xx_fabric_logout
,
1373 .calc_req_entries
= NULL
,
1374 .build_iocbs
= NULL
,
1375 .prep_ms_iocb
= qla24xx_prep_ms_iocb
,
1376 .prep_ms_fdmi_iocb
= qla24xx_prep_ms_fdmi_iocb
,
1377 .read_nvram
= qla25xx_read_nvram_data
,
1378 .write_nvram
= qla25xx_write_nvram_data
,
1379 .fw_dump
= qla25xx_fw_dump
,
1380 .beacon_on
= qla24xx_beacon_on
,
1381 .beacon_off
= qla24xx_beacon_off
,
1382 .beacon_blink
= qla24xx_beacon_blink
,
1383 .read_optrom
= qla25xx_read_optrom_data
,
1384 .write_optrom
= qla24xx_write_optrom_data
,
1385 .get_flash_version
= qla24xx_get_flash_version
,
1386 .start_scsi
= qla24xx_start_scsi
,
1389 static struct isp_operations qla81xx_isp_ops
= {
1390 .pci_config
= qla25xx_pci_config
,
1391 .reset_chip
= qla24xx_reset_chip
,
1392 .chip_diag
= qla24xx_chip_diag
,
1393 .config_rings
= qla24xx_config_rings
,
1394 .reset_adapter
= qla24xx_reset_adapter
,
1395 .nvram_config
= qla81xx_nvram_config
,
1396 .update_fw_options
= qla81xx_update_fw_options
,
1397 .load_risc
= qla81xx_load_risc
,
1398 .pci_info_str
= qla24xx_pci_info_str
,
1399 .fw_version_str
= qla24xx_fw_version_str
,
1400 .intr_handler
= qla24xx_intr_handler
,
1401 .enable_intrs
= qla24xx_enable_intrs
,
1402 .disable_intrs
= qla24xx_disable_intrs
,
1403 .abort_command
= qla24xx_abort_command
,
1404 .target_reset
= qla24xx_abort_target
,
1405 .lun_reset
= qla24xx_lun_reset
,
1406 .fabric_login
= qla24xx_login_fabric
,
1407 .fabric_logout
= qla24xx_fabric_logout
,
1408 .calc_req_entries
= NULL
,
1409 .build_iocbs
= NULL
,
1410 .prep_ms_iocb
= qla24xx_prep_ms_iocb
,
1411 .prep_ms_fdmi_iocb
= qla24xx_prep_ms_fdmi_iocb
,
1412 .read_nvram
= qla25xx_read_nvram_data
,
1413 .write_nvram
= qla25xx_write_nvram_data
,
1414 .fw_dump
= qla81xx_fw_dump
,
1415 .beacon_on
= qla24xx_beacon_on
,
1416 .beacon_off
= qla24xx_beacon_off
,
1417 .beacon_blink
= qla24xx_beacon_blink
,
1418 .read_optrom
= qla25xx_read_optrom_data
,
1419 .write_optrom
= qla24xx_write_optrom_data
,
1420 .get_flash_version
= qla24xx_get_flash_version
,
1421 .start_scsi
= qla24xx_start_scsi
,
1425 qla2x00_set_isp_flags(struct qla_hw_data
*ha
)
1427 ha
->device_type
= DT_EXTENDED_IDS
;
1428 switch (ha
->pdev
->device
) {
1429 case PCI_DEVICE_ID_QLOGIC_ISP2100
:
1430 ha
->device_type
|= DT_ISP2100
;
1431 ha
->device_type
&= ~DT_EXTENDED_IDS
;
1432 ha
->fw_srisc_address
= RISC_START_ADDRESS_2100
;
1434 case PCI_DEVICE_ID_QLOGIC_ISP2200
:
1435 ha
->device_type
|= DT_ISP2200
;
1436 ha
->device_type
&= ~DT_EXTENDED_IDS
;
1437 ha
->fw_srisc_address
= RISC_START_ADDRESS_2100
;
1439 case PCI_DEVICE_ID_QLOGIC_ISP2300
:
1440 ha
->device_type
|= DT_ISP2300
;
1441 ha
->device_type
|= DT_ZIO_SUPPORTED
;
1442 ha
->fw_srisc_address
= RISC_START_ADDRESS_2300
;
1444 case PCI_DEVICE_ID_QLOGIC_ISP2312
:
1445 ha
->device_type
|= DT_ISP2312
;
1446 ha
->device_type
|= DT_ZIO_SUPPORTED
;
1447 ha
->fw_srisc_address
= RISC_START_ADDRESS_2300
;
1449 case PCI_DEVICE_ID_QLOGIC_ISP2322
:
1450 ha
->device_type
|= DT_ISP2322
;
1451 ha
->device_type
|= DT_ZIO_SUPPORTED
;
1452 if (ha
->pdev
->subsystem_vendor
== 0x1028 &&
1453 ha
->pdev
->subsystem_device
== 0x0170)
1454 ha
->device_type
|= DT_OEM_001
;
1455 ha
->fw_srisc_address
= RISC_START_ADDRESS_2300
;
1457 case PCI_DEVICE_ID_QLOGIC_ISP6312
:
1458 ha
->device_type
|= DT_ISP6312
;
1459 ha
->fw_srisc_address
= RISC_START_ADDRESS_2300
;
1461 case PCI_DEVICE_ID_QLOGIC_ISP6322
:
1462 ha
->device_type
|= DT_ISP6322
;
1463 ha
->fw_srisc_address
= RISC_START_ADDRESS_2300
;
1465 case PCI_DEVICE_ID_QLOGIC_ISP2422
:
1466 ha
->device_type
|= DT_ISP2422
;
1467 ha
->device_type
|= DT_ZIO_SUPPORTED
;
1468 ha
->device_type
|= DT_FWI2
;
1469 ha
->device_type
|= DT_IIDMA
;
1470 ha
->fw_srisc_address
= RISC_START_ADDRESS_2400
;
1472 case PCI_DEVICE_ID_QLOGIC_ISP2432
:
1473 ha
->device_type
|= DT_ISP2432
;
1474 ha
->device_type
|= DT_ZIO_SUPPORTED
;
1475 ha
->device_type
|= DT_FWI2
;
1476 ha
->device_type
|= DT_IIDMA
;
1477 ha
->fw_srisc_address
= RISC_START_ADDRESS_2400
;
1479 case PCI_DEVICE_ID_QLOGIC_ISP8432
:
1480 ha
->device_type
|= DT_ISP8432
;
1481 ha
->device_type
|= DT_ZIO_SUPPORTED
;
1482 ha
->device_type
|= DT_FWI2
;
1483 ha
->device_type
|= DT_IIDMA
;
1484 ha
->fw_srisc_address
= RISC_START_ADDRESS_2400
;
1486 case PCI_DEVICE_ID_QLOGIC_ISP5422
:
1487 ha
->device_type
|= DT_ISP5422
;
1488 ha
->device_type
|= DT_FWI2
;
1489 ha
->fw_srisc_address
= RISC_START_ADDRESS_2400
;
1491 case PCI_DEVICE_ID_QLOGIC_ISP5432
:
1492 ha
->device_type
|= DT_ISP5432
;
1493 ha
->device_type
|= DT_FWI2
;
1494 ha
->fw_srisc_address
= RISC_START_ADDRESS_2400
;
1496 case PCI_DEVICE_ID_QLOGIC_ISP2532
:
1497 ha
->device_type
|= DT_ISP2532
;
1498 ha
->device_type
|= DT_ZIO_SUPPORTED
;
1499 ha
->device_type
|= DT_FWI2
;
1500 ha
->device_type
|= DT_IIDMA
;
1501 ha
->fw_srisc_address
= RISC_START_ADDRESS_2400
;
1503 case PCI_DEVICE_ID_QLOGIC_ISP8001
:
1504 ha
->device_type
|= DT_ISP8001
;
1505 ha
->device_type
|= DT_ZIO_SUPPORTED
;
1506 ha
->device_type
|= DT_FWI2
;
1507 ha
->device_type
|= DT_IIDMA
;
1508 ha
->fw_srisc_address
= RISC_START_ADDRESS_2400
;
1514 qla2x00_iospace_config(struct qla_hw_data
*ha
)
1516 resource_size_t pio
;
1519 if (pci_request_selected_regions(ha
->pdev
, ha
->bars
,
1520 QLA2XXX_DRIVER_NAME
)) {
1521 qla_printk(KERN_WARNING
, ha
,
1522 "Failed to reserve PIO/MMIO regions (%s)\n",
1523 pci_name(ha
->pdev
));
1525 goto iospace_error_exit
;
1527 if (!(ha
->bars
& 1))
1530 /* We only need PIO for Flash operations on ISP2312 v2 chips. */
1531 pio
= pci_resource_start(ha
->pdev
, 0);
1532 if (pci_resource_flags(ha
->pdev
, 0) & IORESOURCE_IO
) {
1533 if (pci_resource_len(ha
->pdev
, 0) < MIN_IOBASE_LEN
) {
1534 qla_printk(KERN_WARNING
, ha
,
1535 "Invalid PCI I/O region size (%s)...\n",
1536 pci_name(ha
->pdev
));
1540 qla_printk(KERN_WARNING
, ha
,
1541 "region #0 not a PIO resource (%s)...\n",
1542 pci_name(ha
->pdev
));
1545 ha
->pio_address
= pio
;
1548 /* Use MMIO operations for all accesses. */
1549 if (!(pci_resource_flags(ha
->pdev
, 1) & IORESOURCE_MEM
)) {
1550 qla_printk(KERN_ERR
, ha
,
1551 "region #1 not an MMIO resource (%s), aborting\n",
1552 pci_name(ha
->pdev
));
1553 goto iospace_error_exit
;
1555 if (pci_resource_len(ha
->pdev
, 1) < MIN_IOBASE_LEN
) {
1556 qla_printk(KERN_ERR
, ha
,
1557 "Invalid PCI mem region size (%s), aborting\n",
1558 pci_name(ha
->pdev
));
1559 goto iospace_error_exit
;
1562 ha
->iobase
= ioremap(pci_resource_start(ha
->pdev
, 1), MIN_IOBASE_LEN
);
1564 qla_printk(KERN_ERR
, ha
,
1565 "cannot remap MMIO (%s), aborting\n", pci_name(ha
->pdev
));
1567 goto iospace_error_exit
;
1570 /* Determine queue resources */
1572 if (ql2xmaxqueues
<= 1 || (!IS_QLA25XX(ha
) && !IS_QLA81XX(ha
)))
1574 ha
->mqiobase
= ioremap(pci_resource_start(ha
->pdev
, 3),
1575 pci_resource_len(ha
->pdev
, 3));
1577 /* Read MSIX vector size of the board */
1578 pci_read_config_word(ha
->pdev
, QLA_PCI_MSIX_CONTROL
, &msix
);
1579 ha
->msix_count
= msix
;
1580 /* Max queues are bounded by available msix vectors */
1581 /* queue 0 uses two msix vectors */
1582 if (ha
->msix_count
- 1 < ql2xmaxqueues
)
1583 ha
->max_queues
= ha
->msix_count
- 1;
1584 else if (ql2xmaxqueues
> QLA_MQ_SIZE
)
1585 ha
->max_queues
= QLA_MQ_SIZE
;
1587 ha
->max_queues
= ql2xmaxqueues
;
1588 qla_printk(KERN_INFO
, ha
,
1589 "MSI-X vector count: %d\n", msix
);
1593 ha
->msix_count
= ha
->max_queues
+ 1;
1601 qla2xxx_scan_start(struct Scsi_Host
*shost
)
1603 scsi_qla_host_t
*vha
= shost_priv(shost
);
1605 set_bit(LOOP_RESYNC_NEEDED
, &vha
->dpc_flags
);
1606 set_bit(LOCAL_LOOP_UPDATE
, &vha
->dpc_flags
);
1607 set_bit(RSCN_UPDATE
, &vha
->dpc_flags
);
1608 set_bit(NPIV_CONFIG_NEEDED
, &vha
->dpc_flags
);
1612 qla2xxx_scan_finished(struct Scsi_Host
*shost
, unsigned long time
)
1614 scsi_qla_host_t
*vha
= shost_priv(shost
);
1618 if (time
> vha
->hw
->loop_reset_delay
* HZ
)
1621 return atomic_read(&vha
->loop_state
) == LOOP_READY
;
1625 * PCI driver interface
1627 static int __devinit
1628 qla2x00_probe_one(struct pci_dev
*pdev
, const struct pci_device_id
*id
)
1631 struct Scsi_Host
*host
;
1632 scsi_qla_host_t
*base_vha
= NULL
;
1633 struct qla_hw_data
*ha
;
1636 struct scsi_host_template
*sht
;
1637 int bars
, max_id
, mem_only
= 0;
1638 uint16_t req_length
= 0, rsp_length
= 0;
1639 struct req_que
*req
= NULL
;
1640 struct rsp_que
*rsp
= NULL
;
1642 bars
= pci_select_bars(pdev
, IORESOURCE_MEM
| IORESOURCE_IO
);
1643 sht
= &qla2xxx_driver_template
;
1644 if (pdev
->device
== PCI_DEVICE_ID_QLOGIC_ISP2422
||
1645 pdev
->device
== PCI_DEVICE_ID_QLOGIC_ISP2432
||
1646 pdev
->device
== PCI_DEVICE_ID_QLOGIC_ISP8432
||
1647 pdev
->device
== PCI_DEVICE_ID_QLOGIC_ISP5422
||
1648 pdev
->device
== PCI_DEVICE_ID_QLOGIC_ISP5432
||
1649 pdev
->device
== PCI_DEVICE_ID_QLOGIC_ISP2532
||
1650 pdev
->device
== PCI_DEVICE_ID_QLOGIC_ISP8001
) {
1651 bars
= pci_select_bars(pdev
, IORESOURCE_MEM
);
1656 if (pci_enable_device_mem(pdev
))
1659 if (pci_enable_device(pdev
))
1663 /* This may fail but that's ok */
1664 pci_enable_pcie_error_reporting(pdev
);
1666 ha
= kzalloc(sizeof(struct qla_hw_data
), GFP_KERNEL
);
1668 DEBUG(printk("Unable to allocate memory for ha\n"));
1673 /* Clear our data area */
1675 ha
->mem_only
= mem_only
;
1676 spin_lock_init(&ha
->hardware_lock
);
1678 /* Set ISP-type information. */
1679 qla2x00_set_isp_flags(ha
);
1680 /* Configure PCI I/O space */
1681 ret
= qla2x00_iospace_config(ha
);
1683 goto probe_hw_failed
;
1685 qla_printk(KERN_INFO
, ha
,
1686 "Found an ISP%04X, irq %d, iobase 0x%p\n", pdev
->device
, pdev
->irq
,
1689 ha
->prev_topology
= 0;
1690 ha
->init_cb_size
= sizeof(init_cb_t
);
1691 ha
->link_data_rate
= PORT_SPEED_UNKNOWN
;
1692 ha
->optrom_size
= OPTROM_SIZE_2300
;
1694 /* Assign ISP specific operations. */
1695 max_id
= MAX_TARGETS_2200
;
1696 if (IS_QLA2100(ha
)) {
1697 max_id
= MAX_TARGETS_2100
;
1698 ha
->mbx_count
= MAILBOX_REGISTER_COUNT_2100
;
1699 req_length
= REQUEST_ENTRY_CNT_2100
;
1700 rsp_length
= RESPONSE_ENTRY_CNT_2100
;
1701 ha
->max_loop_id
= SNS_LAST_LOOP_ID_2100
;
1702 ha
->gid_list_info_size
= 4;
1703 ha
->flash_conf_off
= ~0;
1704 ha
->flash_data_off
= ~0;
1705 ha
->nvram_conf_off
= ~0;
1706 ha
->nvram_data_off
= ~0;
1707 ha
->isp_ops
= &qla2100_isp_ops
;
1708 } else if (IS_QLA2200(ha
)) {
1709 ha
->mbx_count
= MAILBOX_REGISTER_COUNT
;
1710 req_length
= REQUEST_ENTRY_CNT_2200
;
1711 rsp_length
= RESPONSE_ENTRY_CNT_2100
;
1712 ha
->max_loop_id
= SNS_LAST_LOOP_ID_2100
;
1713 ha
->gid_list_info_size
= 4;
1714 ha
->flash_conf_off
= ~0;
1715 ha
->flash_data_off
= ~0;
1716 ha
->nvram_conf_off
= ~0;
1717 ha
->nvram_data_off
= ~0;
1718 ha
->isp_ops
= &qla2100_isp_ops
;
1719 } else if (IS_QLA23XX(ha
)) {
1720 ha
->mbx_count
= MAILBOX_REGISTER_COUNT
;
1721 req_length
= REQUEST_ENTRY_CNT_2200
;
1722 rsp_length
= RESPONSE_ENTRY_CNT_2300
;
1723 ha
->max_loop_id
= SNS_LAST_LOOP_ID_2300
;
1724 ha
->gid_list_info_size
= 6;
1725 if (IS_QLA2322(ha
) || IS_QLA6322(ha
))
1726 ha
->optrom_size
= OPTROM_SIZE_2322
;
1727 ha
->flash_conf_off
= ~0;
1728 ha
->flash_data_off
= ~0;
1729 ha
->nvram_conf_off
= ~0;
1730 ha
->nvram_data_off
= ~0;
1731 ha
->isp_ops
= &qla2300_isp_ops
;
1732 } else if (IS_QLA24XX_TYPE(ha
)) {
1733 ha
->mbx_count
= MAILBOX_REGISTER_COUNT
;
1734 req_length
= REQUEST_ENTRY_CNT_24XX
;
1735 rsp_length
= RESPONSE_ENTRY_CNT_2300
;
1736 ha
->max_loop_id
= SNS_LAST_LOOP_ID_2300
;
1737 ha
->init_cb_size
= sizeof(struct mid_init_cb_24xx
);
1738 ha
->gid_list_info_size
= 8;
1739 ha
->optrom_size
= OPTROM_SIZE_24XX
;
1740 ha
->nvram_npiv_size
= QLA_MAX_VPORTS_QLA24XX
;
1741 ha
->isp_ops
= &qla24xx_isp_ops
;
1742 ha
->flash_conf_off
= FARX_ACCESS_FLASH_CONF
;
1743 ha
->flash_data_off
= FARX_ACCESS_FLASH_DATA
;
1744 ha
->nvram_conf_off
= FARX_ACCESS_NVRAM_CONF
;
1745 ha
->nvram_data_off
= FARX_ACCESS_NVRAM_DATA
;
1746 } else if (IS_QLA25XX(ha
)) {
1747 ha
->mbx_count
= MAILBOX_REGISTER_COUNT
;
1748 req_length
= REQUEST_ENTRY_CNT_24XX
;
1749 rsp_length
= RESPONSE_ENTRY_CNT_2300
;
1750 ha
->max_loop_id
= SNS_LAST_LOOP_ID_2300
;
1751 ha
->init_cb_size
= sizeof(struct mid_init_cb_24xx
);
1752 ha
->gid_list_info_size
= 8;
1753 ha
->optrom_size
= OPTROM_SIZE_25XX
;
1754 ha
->nvram_npiv_size
= QLA_MAX_VPORTS_QLA25XX
;
1755 ha
->isp_ops
= &qla25xx_isp_ops
;
1756 ha
->flash_conf_off
= FARX_ACCESS_FLASH_CONF
;
1757 ha
->flash_data_off
= FARX_ACCESS_FLASH_DATA
;
1758 ha
->nvram_conf_off
= FARX_ACCESS_NVRAM_CONF
;
1759 ha
->nvram_data_off
= FARX_ACCESS_NVRAM_DATA
;
1760 } else if (IS_QLA81XX(ha
)) {
1761 ha
->mbx_count
= MAILBOX_REGISTER_COUNT
;
1762 req_length
= REQUEST_ENTRY_CNT_24XX
;
1763 rsp_length
= RESPONSE_ENTRY_CNT_2300
;
1764 ha
->max_loop_id
= SNS_LAST_LOOP_ID_2300
;
1765 ha
->init_cb_size
= sizeof(struct mid_init_cb_81xx
);
1766 ha
->gid_list_info_size
= 8;
1767 ha
->optrom_size
= OPTROM_SIZE_81XX
;
1768 ha
->isp_ops
= &qla81xx_isp_ops
;
1769 ha
->flash_conf_off
= FARX_ACCESS_FLASH_CONF_81XX
;
1770 ha
->flash_data_off
= FARX_ACCESS_FLASH_DATA_81XX
;
1771 ha
->nvram_conf_off
= ~0;
1772 ha
->nvram_data_off
= ~0;
1775 mutex_init(&ha
->vport_lock
);
1776 init_completion(&ha
->mbx_cmd_comp
);
1777 complete(&ha
->mbx_cmd_comp
);
1778 init_completion(&ha
->mbx_intr_comp
);
1780 set_bit(0, (unsigned long *) ha
->vp_idx_map
);
1782 qla2x00_config_dma_addressing(ha
);
1783 ret
= qla2x00_mem_alloc(ha
, req_length
, rsp_length
, &req
, &rsp
);
1785 qla_printk(KERN_WARNING
, ha
,
1786 "[ERROR] Failed to allocate memory for adapter\n");
1788 goto probe_hw_failed
;
1791 req
->max_q_depth
= MAX_Q_DEPTH
;
1792 if (ql2xmaxqdepth
!= 0 && ql2xmaxqdepth
<= 0xffffU
)
1793 req
->max_q_depth
= ql2xmaxqdepth
;
1796 base_vha
= qla2x00_create_host(sht
, ha
);
1798 qla_printk(KERN_WARNING
, ha
,
1799 "[ERROR] Failed to allocate memory for scsi_host\n");
1802 qla2x00_mem_free(ha
);
1803 qla2x00_free_que(ha
, req
, rsp
);
1804 goto probe_hw_failed
;
1807 pci_set_drvdata(pdev
, base_vha
);
1809 host
= base_vha
->host
;
1810 base_vha
->req_ques
[0] = req
->id
;
1811 host
->can_queue
= req
->length
+ 128;
1812 if (IS_QLA2XXX_MIDTYPE(ha
))
1813 base_vha
->mgmt_svr_loop_id
= 10 + base_vha
->vp_idx
;
1815 base_vha
->mgmt_svr_loop_id
= MANAGEMENT_SERVER
+
1818 host
->sg_tablesize
= 32;
1819 host
->max_id
= max_id
;
1820 host
->this_id
= 255;
1821 host
->cmd_per_lun
= 3;
1822 host
->unique_id
= host
->host_no
;
1823 host
->max_cmd_len
= MAX_CMDSZ
;
1824 host
->max_channel
= MAX_BUSES
- 1;
1825 host
->max_lun
= MAX_LUNS
;
1826 host
->transportt
= qla2xxx_transport_template
;
1828 /* Set up the irqs */
1829 ret
= qla2x00_request_irqs(ha
, rsp
);
1831 goto probe_init_failed
;
1832 /* Alloc arrays of request and response ring ptrs */
1833 if (!qla2x00_alloc_queues(ha
)) {
1834 qla_printk(KERN_WARNING
, ha
,
1835 "[ERROR] Failed to allocate memory for queue"
1837 goto probe_init_failed
;
1839 ha
->rsp_q_map
[0] = rsp
;
1840 ha
->req_q_map
[0] = req
;
1842 /* FWI2-capable only. */
1843 req
->req_q_in
= &ha
->iobase
->isp24
.req_q_in
;
1844 req
->req_q_out
= &ha
->iobase
->isp24
.req_q_out
;
1845 rsp
->rsp_q_in
= &ha
->iobase
->isp24
.rsp_q_in
;
1846 rsp
->rsp_q_out
= &ha
->iobase
->isp24
.rsp_q_out
;
1848 req
->req_q_in
= &ha
->mqiobase
->isp25mq
.req_q_in
;
1849 req
->req_q_out
= &ha
->mqiobase
->isp25mq
.req_q_out
;
1850 rsp
->rsp_q_in
= &ha
->mqiobase
->isp25mq
.rsp_q_in
;
1851 rsp
->rsp_q_out
= &ha
->mqiobase
->isp25mq
.rsp_q_out
;
1854 if (qla2x00_initialize_adapter(base_vha
)) {
1855 qla_printk(KERN_WARNING
, ha
,
1856 "Failed to initialize adapter\n");
1858 DEBUG2(printk("scsi(%ld): Failed to initialize adapter - "
1859 "Adapter flags %x.\n",
1860 base_vha
->host_no
, base_vha
->device_flags
));
1867 * Startup the kernel thread for this host adapter
1869 ha
->dpc_thread
= kthread_create(qla2x00_do_dpc
, ha
,
1870 "%s_dpc", base_vha
->host_str
);
1871 if (IS_ERR(ha
->dpc_thread
)) {
1872 qla_printk(KERN_WARNING
, ha
,
1873 "Unable to start DPC thread!\n");
1874 ret
= PTR_ERR(ha
->dpc_thread
);
1878 list_add_tail(&base_vha
->list
, &ha
->vp_list
);
1879 base_vha
->host
->irq
= ha
->pdev
->irq
;
1881 /* Initialized the timer */
1882 qla2x00_start_timer(base_vha
, qla2x00_timer
, WATCH_INTERVAL
);
1884 DEBUG2(printk("DEBUG: detect hba %ld at address = %p\n",
1885 base_vha
->host_no
, ha
));
1887 base_vha
->flags
.init_done
= 1;
1888 base_vha
->flags
.online
= 1;
1890 ret
= scsi_add_host(host
, &pdev
->dev
);
1894 ha
->isp_ops
->enable_intrs(ha
);
1896 scsi_scan_host(host
);
1898 qla2x00_alloc_sysfs_attr(base_vha
);
1900 qla2x00_init_host_attr(base_vha
);
1902 qla2x00_dfs_setup(base_vha
);
1904 qla_printk(KERN_INFO
, ha
, "\n"
1905 " QLogic Fibre Channel HBA Driver: %s\n"
1907 " ISP%04X: %s @ %s hdma%c, host#=%ld, fw=%s\n",
1908 qla2x00_version_str
, ha
->model_number
,
1909 ha
->model_desc
? ha
->model_desc
: "", pdev
->device
,
1910 ha
->isp_ops
->pci_info_str(base_vha
, pci_info
), pci_name(pdev
),
1911 ha
->flags
.enable_64bit_addressing
? '+' : '-', base_vha
->host_no
,
1912 ha
->isp_ops
->fw_version_str(base_vha
, fw_str
));
1917 qla2x00_free_que(ha
, req
, rsp
);
1921 if (base_vha
->timer_active
)
1922 qla2x00_stop_timer(base_vha
);
1923 base_vha
->flags
.online
= 0;
1924 if (ha
->dpc_thread
) {
1925 struct task_struct
*t
= ha
->dpc_thread
;
1927 ha
->dpc_thread
= NULL
;
1931 qla2x00_free_device(base_vha
);
1933 scsi_host_put(base_vha
->host
);
1937 iounmap(ha
->iobase
);
1939 pci_release_selected_regions(ha
->pdev
, ha
->bars
);
1944 pci_disable_device(pdev
);
1949 qla2x00_remove_one(struct pci_dev
*pdev
)
1951 scsi_qla_host_t
*base_vha
, *vha
, *temp
;
1952 struct qla_hw_data
*ha
;
1954 base_vha
= pci_get_drvdata(pdev
);
1957 list_for_each_entry_safe(vha
, temp
, &ha
->vp_list
, list
) {
1958 if (vha
&& vha
->fc_vport
)
1959 fc_vport_terminate(vha
->fc_vport
);
1962 set_bit(UNLOADING
, &base_vha
->dpc_flags
);
1964 qla2x00_abort_all_cmds(base_vha
, DID_NO_CONNECT
<< 16);
1966 qla2x00_dfs_remove(base_vha
);
1968 qla84xx_put_chip(base_vha
);
1971 if (base_vha
->timer_active
)
1972 qla2x00_stop_timer(base_vha
);
1974 base_vha
->flags
.online
= 0;
1976 /* Kill the kernel thread for this host */
1977 if (ha
->dpc_thread
) {
1978 struct task_struct
*t
= ha
->dpc_thread
;
1981 * qla2xxx_wake_dpc checks for ->dpc_thread
1982 * so we need to zero it out.
1984 ha
->dpc_thread
= NULL
;
1988 qla2x00_free_sysfs_attr(base_vha
);
1990 fc_remove_host(base_vha
->host
);
1992 scsi_remove_host(base_vha
->host
);
1994 qla2x00_free_device(base_vha
);
1996 scsi_host_put(base_vha
->host
);
1999 iounmap(ha
->iobase
);
2002 iounmap(ha
->mqiobase
);
2004 pci_release_selected_regions(ha
->pdev
, ha
->bars
);
2008 pci_disable_device(pdev
);
2009 pci_set_drvdata(pdev
, NULL
);
2013 qla2x00_free_device(scsi_qla_host_t
*vha
)
2015 struct qla_hw_data
*ha
= vha
->hw
;
2017 if (ha
->flags
.fce_enabled
)
2018 qla2x00_disable_fce_trace(vha
, NULL
, NULL
);
2021 qla2x00_disable_eft_trace(vha
);
2023 /* Stop currently executing firmware. */
2024 qla2x00_try_to_stop_firmware(vha
);
2026 /* turn-off interrupts on the card */
2027 if (ha
->interrupts_on
)
2028 ha
->isp_ops
->disable_intrs(ha
);
2030 qla2x00_free_irqs(vha
);
2032 qla2x00_mem_free(ha
);
2034 qla2x00_free_queues(ha
);
2038 qla2x00_schedule_rport_del(struct scsi_qla_host
*vha
, fc_port_t
*fcport
,
2041 struct fc_rport
*rport
;
2046 rport
= fcport
->rport
;
2048 spin_lock_irq(vha
->host
->host_lock
);
2049 fcport
->drport
= rport
;
2050 spin_unlock_irq(vha
->host
->host_lock
);
2051 set_bit(FCPORT_UPDATE_NEEDED
, &vha
->dpc_flags
);
2052 qla2xxx_wake_dpc(vha
);
2054 fc_remote_port_delete(rport
);
2058 * qla2x00_mark_device_lost Updates fcport state when device goes offline.
2060 * Input: ha = adapter block pointer. fcport = port structure pointer.
2066 void qla2x00_mark_device_lost(scsi_qla_host_t
*vha
, fc_port_t
*fcport
,
2067 int do_login
, int defer
)
2069 if (atomic_read(&fcport
->state
) == FCS_ONLINE
&&
2070 vha
->vp_idx
== fcport
->vp_idx
) {
2071 atomic_set(&fcport
->state
, FCS_DEVICE_LOST
);
2072 qla2x00_schedule_rport_del(vha
, fcport
, defer
);
2075 * We may need to retry the login, so don't change the state of the
2076 * port but do the retries.
2078 if (atomic_read(&fcport
->state
) != FCS_DEVICE_DEAD
)
2079 atomic_set(&fcport
->state
, FCS_DEVICE_LOST
);
2084 if (fcport
->login_retry
== 0) {
2085 fcport
->login_retry
= vha
->hw
->login_retry_count
;
2086 set_bit(RELOGIN_NEEDED
, &vha
->dpc_flags
);
2088 DEBUG(printk("scsi(%ld): Port login retry: "
2089 "%02x%02x%02x%02x%02x%02x%02x%02x, "
2090 "id = 0x%04x retry cnt=%d\n",
2092 fcport
->port_name
[0],
2093 fcport
->port_name
[1],
2094 fcport
->port_name
[2],
2095 fcport
->port_name
[3],
2096 fcport
->port_name
[4],
2097 fcport
->port_name
[5],
2098 fcport
->port_name
[6],
2099 fcport
->port_name
[7],
2101 fcport
->login_retry
));
2106 * qla2x00_mark_all_devices_lost
2107 * Updates fcport state when device goes offline.
2110 * ha = adapter block pointer.
2111 * fcport = port structure pointer.
2119 qla2x00_mark_all_devices_lost(scsi_qla_host_t
*vha
, int defer
)
2123 list_for_each_entry(fcport
, &vha
->vp_fcports
, list
) {
2124 if (vha
->vp_idx
!= fcport
->vp_idx
)
2127 * No point in marking the device as lost, if the device is
2130 if (atomic_read(&fcport
->state
) == FCS_DEVICE_DEAD
)
2132 if (atomic_read(&fcport
->state
) == FCS_ONLINE
) {
2133 atomic_set(&fcport
->state
, FCS_DEVICE_LOST
);
2134 qla2x00_schedule_rport_del(vha
, fcport
, defer
);
2136 atomic_set(&fcport
->state
, FCS_DEVICE_LOST
);
2142 * Allocates adapter memory.
2149 qla2x00_mem_alloc(struct qla_hw_data
*ha
, uint16_t req_len
, uint16_t rsp_len
,
2150 struct req_que
**req
, struct rsp_que
**rsp
)
2154 ha
->init_cb
= dma_alloc_coherent(&ha
->pdev
->dev
, ha
->init_cb_size
,
2155 &ha
->init_cb_dma
, GFP_KERNEL
);
2159 ha
->gid_list
= dma_alloc_coherent(&ha
->pdev
->dev
, GID_LIST_SIZE
,
2160 &ha
->gid_list_dma
, GFP_KERNEL
);
2162 goto fail_free_init_cb
;
2164 ha
->srb_mempool
= mempool_create_slab_pool(SRB_MIN_REQ
, srb_cachep
);
2165 if (!ha
->srb_mempool
)
2166 goto fail_free_gid_list
;
2168 /* Get memory for cached NVRAM */
2169 ha
->nvram
= kzalloc(MAX_NVRAM_SIZE
, GFP_KERNEL
);
2171 goto fail_free_srb_mempool
;
2173 snprintf(name
, sizeof(name
), "%s_%d", QLA2XXX_DRIVER_NAME
,
2175 ha
->s_dma_pool
= dma_pool_create(name
, &ha
->pdev
->dev
,
2176 DMA_POOL_SIZE
, 8, 0);
2177 if (!ha
->s_dma_pool
)
2178 goto fail_free_nvram
;
2180 /* Allocate memory for SNS commands */
2181 if (IS_QLA2100(ha
) || IS_QLA2200(ha
)) {
2182 /* Get consistent memory allocated for SNS commands */
2183 ha
->sns_cmd
= dma_alloc_coherent(&ha
->pdev
->dev
,
2184 sizeof(struct sns_cmd_pkt
), &ha
->sns_cmd_dma
, GFP_KERNEL
);
2188 /* Get consistent memory allocated for MS IOCB */
2189 ha
->ms_iocb
= dma_pool_alloc(ha
->s_dma_pool
, GFP_KERNEL
,
2193 /* Get consistent memory allocated for CT SNS commands */
2194 ha
->ct_sns
= dma_alloc_coherent(&ha
->pdev
->dev
,
2195 sizeof(struct ct_sns_pkt
), &ha
->ct_sns_dma
, GFP_KERNEL
);
2197 goto fail_free_ms_iocb
;
2200 /* Allocate memory for request ring */
2201 *req
= kzalloc(sizeof(struct req_que
), GFP_KERNEL
);
2203 DEBUG(printk("Unable to allocate memory for req\n"));
2206 (*req
)->length
= req_len
;
2207 (*req
)->ring
= dma_alloc_coherent(&ha
->pdev
->dev
,
2208 ((*req
)->length
+ 1) * sizeof(request_t
),
2209 &(*req
)->dma
, GFP_KERNEL
);
2210 if (!(*req
)->ring
) {
2211 DEBUG(printk("Unable to allocate memory for req_ring\n"));
2214 /* Allocate memory for response ring */
2215 *rsp
= kzalloc(sizeof(struct rsp_que
), GFP_KERNEL
);
2217 qla_printk(KERN_WARNING
, ha
,
2218 "Unable to allocate memory for rsp\n");
2222 (*rsp
)->length
= rsp_len
;
2223 (*rsp
)->ring
= dma_alloc_coherent(&ha
->pdev
->dev
,
2224 ((*rsp
)->length
+ 1) * sizeof(response_t
),
2225 &(*rsp
)->dma
, GFP_KERNEL
);
2226 if (!(*rsp
)->ring
) {
2227 qla_printk(KERN_WARNING
, ha
,
2228 "Unable to allocate memory for rsp_ring\n");
2233 /* Allocate memory for NVRAM data for vports */
2234 if (ha
->nvram_npiv_size
) {
2235 ha
->npiv_info
= kzalloc(sizeof(struct qla_npiv_entry
) *
2236 ha
->nvram_npiv_size
, GFP_KERNEL
);
2237 if (!ha
->npiv_info
) {
2238 qla_printk(KERN_WARNING
, ha
,
2239 "Unable to allocate memory for npiv info\n");
2240 goto fail_npiv_info
;
2243 ha
->npiv_info
= NULL
;
2245 /* Get consistent memory allocated for EX-INIT-CB. */
2246 if (IS_QLA81XX(ha
)) {
2247 ha
->ex_init_cb
= dma_pool_alloc(ha
->s_dma_pool
, GFP_KERNEL
,
2248 &ha
->ex_init_cb_dma
);
2249 if (!ha
->ex_init_cb
)
2250 goto fail_ex_init_cb
;
2253 INIT_LIST_HEAD(&ha
->vp_list
);
2257 kfree(ha
->npiv_info
);
2259 dma_free_coherent(&ha
->pdev
->dev
, ((*rsp
)->length
+ 1) *
2260 sizeof(response_t
), (*rsp
)->ring
, (*rsp
)->dma
);
2261 (*rsp
)->ring
= NULL
;
2266 dma_free_coherent(&ha
->pdev
->dev
, ((*req
)->length
+ 1) *
2267 sizeof(request_t
), (*req
)->ring
, (*req
)->dma
);
2268 (*req
)->ring
= NULL
;
2273 dma_free_coherent(&ha
->pdev
->dev
, sizeof(struct ct_sns_pkt
),
2274 ha
->ct_sns
, ha
->ct_sns_dma
);
2278 dma_pool_free(ha
->s_dma_pool
, ha
->ms_iocb
, ha
->ms_iocb_dma
);
2280 ha
->ms_iocb_dma
= 0;
2282 dma_pool_destroy(ha
->s_dma_pool
);
2283 ha
->s_dma_pool
= NULL
;
2287 fail_free_srb_mempool
:
2288 mempool_destroy(ha
->srb_mempool
);
2289 ha
->srb_mempool
= NULL
;
2291 dma_free_coherent(&ha
->pdev
->dev
, GID_LIST_SIZE
, ha
->gid_list
,
2293 ha
->gid_list
= NULL
;
2294 ha
->gid_list_dma
= 0;
2296 dma_free_coherent(&ha
->pdev
->dev
, ha
->init_cb_size
, ha
->init_cb
,
2299 ha
->init_cb_dma
= 0;
2301 DEBUG(printk("%s: Memory allocation failure\n", __func__
));
2307 * Frees all adapter allocated memory.
2310 * ha = adapter block pointer.
2313 qla2x00_mem_free(struct qla_hw_data
*ha
)
2315 if (ha
->srb_mempool
)
2316 mempool_destroy(ha
->srb_mempool
);
2319 dma_free_coherent(&ha
->pdev
->dev
, FCE_SIZE
, ha
->fce
,
2324 dma_free_coherent(&ha
->pdev
->dev
,
2325 ntohl(ha
->fw_dump
->eft_size
), ha
->eft
, ha
->eft_dma
);
2330 dma_free_coherent(&ha
->pdev
->dev
, sizeof(struct sns_cmd_pkt
),
2331 ha
->sns_cmd
, ha
->sns_cmd_dma
);
2334 dma_free_coherent(&ha
->pdev
->dev
, sizeof(struct ct_sns_pkt
),
2335 ha
->ct_sns
, ha
->ct_sns_dma
);
2338 dma_pool_free(ha
->s_dma_pool
, ha
->sfp_data
, ha
->sfp_data_dma
);
2341 dma_pool_free(ha
->s_dma_pool
, ha
->ms_iocb
, ha
->ms_iocb_dma
);
2344 dma_pool_free(ha
->s_dma_pool
, ha
->ex_init_cb
, ha
->ex_init_cb_dma
);
2347 dma_pool_destroy(ha
->s_dma_pool
);
2350 dma_free_coherent(&ha
->pdev
->dev
, GID_LIST_SIZE
, ha
->gid_list
,
2354 dma_free_coherent(&ha
->pdev
->dev
, ha
->init_cb_size
,
2355 ha
->init_cb
, ha
->init_cb_dma
);
2356 vfree(ha
->optrom_buffer
);
2358 kfree(ha
->npiv_info
);
2360 ha
->srb_mempool
= NULL
;
2364 ha
->sns_cmd_dma
= 0;
2368 ha
->ms_iocb_dma
= 0;
2370 ha
->init_cb_dma
= 0;
2371 ha
->ex_init_cb
= NULL
;
2372 ha
->ex_init_cb_dma
= 0;
2374 ha
->s_dma_pool
= NULL
;
2376 ha
->gid_list
= NULL
;
2377 ha
->gid_list_dma
= 0;
2381 ha
->fw_dump_reading
= 0;
2384 struct scsi_qla_host
*qla2x00_create_host(struct scsi_host_template
*sht
,
2385 struct qla_hw_data
*ha
)
2387 struct Scsi_Host
*host
;
2388 struct scsi_qla_host
*vha
= NULL
;
2390 host
= scsi_host_alloc(sht
, sizeof(scsi_qla_host_t
));
2393 "qla2xxx: Couldn't allocate host from scsi layer!\n");
2397 /* Clear our data area */
2398 vha
= shost_priv(host
);
2399 memset(vha
, 0, sizeof(scsi_qla_host_t
));
2402 vha
->host_no
= host
->host_no
;
2405 INIT_LIST_HEAD(&vha
->vp_fcports
);
2406 INIT_LIST_HEAD(&vha
->work_list
);
2407 INIT_LIST_HEAD(&vha
->list
);
2409 sprintf(vha
->host_str
, "%s_%ld", QLA2XXX_DRIVER_NAME
, vha
->host_no
);
2416 static struct qla_work_evt
*
2417 qla2x00_alloc_work(struct scsi_qla_host
*vha
, enum qla_work_type type
,
2420 struct qla_work_evt
*e
;
2422 e
= kzalloc(sizeof(struct qla_work_evt
), locked
? GFP_ATOMIC
:
2427 INIT_LIST_HEAD(&e
->list
);
2429 e
->flags
= QLA_EVT_FLAG_FREE
;
2434 qla2x00_post_work(struct scsi_qla_host
*vha
, struct qla_work_evt
*e
, int locked
)
2436 unsigned long uninitialized_var(flags
);
2437 struct qla_hw_data
*ha
= vha
->hw
;
2440 spin_lock_irqsave(&ha
->hardware_lock
, flags
);
2441 list_add_tail(&e
->list
, &vha
->work_list
);
2442 qla2xxx_wake_dpc(vha
);
2444 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
2449 qla2x00_post_aen_work(struct scsi_qla_host
*vha
, enum fc_host_event_code code
,
2452 struct qla_work_evt
*e
;
2454 e
= qla2x00_alloc_work(vha
, QLA_EVT_AEN
, 1);
2456 return QLA_FUNCTION_FAILED
;
2458 e
->u
.aen
.code
= code
;
2459 e
->u
.aen
.data
= data
;
2460 return qla2x00_post_work(vha
, e
, 1);
2464 qla2x00_post_idc_ack_work(struct scsi_qla_host
*vha
, uint16_t *mb
)
2466 struct qla_work_evt
*e
;
2468 e
= qla2x00_alloc_work(vha
, QLA_EVT_IDC_ACK
, 1);
2470 return QLA_FUNCTION_FAILED
;
2472 memcpy(e
->u
.idc_ack
.mb
, mb
, QLA_IDC_ACK_REGS
* sizeof(uint16_t));
2473 return qla2x00_post_work(vha
, e
, 1);
2477 qla2x00_do_work(struct scsi_qla_host
*vha
)
2479 struct qla_work_evt
*e
;
2480 struct qla_hw_data
*ha
= vha
->hw
;
2482 spin_lock_irq(&ha
->hardware_lock
);
2483 while (!list_empty(&vha
->work_list
)) {
2484 e
= list_entry(vha
->work_list
.next
, struct qla_work_evt
, list
);
2485 list_del_init(&e
->list
);
2486 spin_unlock_irq(&ha
->hardware_lock
);
2490 fc_host_post_event(vha
->host
, fc_get_event_number(),
2491 e
->u
.aen
.code
, e
->u
.aen
.data
);
2493 case QLA_EVT_IDC_ACK
:
2494 qla81xx_idc_ack(vha
, e
->u
.idc_ack
.mb
);
2497 if (e
->flags
& QLA_EVT_FLAG_FREE
)
2499 spin_lock_irq(&ha
->hardware_lock
);
2501 spin_unlock_irq(&ha
->hardware_lock
);
2503 /* Relogins all the fcports of a vport
2504 * Context: dpc thread
2506 void qla2x00_relogin(struct scsi_qla_host
*vha
)
2510 uint16_t next_loopid
= 0;
2511 struct qla_hw_data
*ha
= vha
->hw
;
2513 list_for_each_entry(fcport
, &vha
->vp_fcports
, list
) {
2515 * If the port is not ONLINE then try to login
2516 * to it if we haven't run out of retries.
2518 if (atomic_read(&fcport
->state
) !=
2519 FCS_ONLINE
&& fcport
->login_retry
) {
2521 if (fcport
->flags
& FCF_FABRIC_DEVICE
) {
2522 if (fcport
->flags
& FCF_TAPE_PRESENT
)
2523 ha
->isp_ops
->fabric_logout(vha
,
2525 fcport
->d_id
.b
.domain
,
2526 fcport
->d_id
.b
.area
,
2527 fcport
->d_id
.b
.al_pa
);
2529 status
= qla2x00_fabric_login(vha
, fcport
,
2532 status
= qla2x00_local_device_login(vha
,
2535 fcport
->login_retry
--;
2536 if (status
== QLA_SUCCESS
) {
2537 fcport
->old_loop_id
= fcport
->loop_id
;
2539 DEBUG(printk("scsi(%ld): port login OK: logged "
2540 "in ID 0x%x\n", vha
->host_no
, fcport
->loop_id
));
2542 qla2x00_update_fcport(vha
, fcport
);
2544 } else if (status
== 1) {
2545 set_bit(RELOGIN_NEEDED
, &vha
->dpc_flags
);
2546 /* retry the login again */
2547 DEBUG(printk("scsi(%ld): Retrying"
2548 " %d login again loop_id 0x%x\n",
2549 vha
->host_no
, fcport
->login_retry
,
2552 fcport
->login_retry
= 0;
2555 if (fcport
->login_retry
== 0 && status
!= QLA_SUCCESS
)
2556 fcport
->loop_id
= FC_NO_LOOP_ID
;
2558 if (test_bit(LOOP_RESYNC_NEEDED
, &vha
->dpc_flags
))
2563 /**************************************************************************
2565 * This kernel thread is a task that is schedule by the interrupt handler
2566 * to perform the background processing for interrupts.
2569 * This task always run in the context of a kernel thread. It
2570 * is kick-off by the driver's detect code and starts up
2571 * up one per adapter. It immediately goes to sleep and waits for
2572 * some fibre event. When either the interrupt handler or
2573 * the timer routine detects a event it will one of the task
2574 * bits then wake us up.
2575 **************************************************************************/
2577 qla2x00_do_dpc(void *data
)
2580 scsi_qla_host_t
*base_vha
;
2581 struct qla_hw_data
*ha
;
2583 ha
= (struct qla_hw_data
*)data
;
2584 base_vha
= pci_get_drvdata(ha
->pdev
);
2586 set_user_nice(current
, -20);
2588 while (!kthread_should_stop()) {
2589 DEBUG3(printk("qla2x00: DPC handler sleeping\n"));
2591 set_current_state(TASK_INTERRUPTIBLE
);
2593 __set_current_state(TASK_RUNNING
);
2595 DEBUG3(printk("qla2x00: DPC handler waking up\n"));
2597 /* Initialization not yet finished. Don't do anything yet. */
2598 if (!base_vha
->flags
.init_done
)
2601 DEBUG3(printk("scsi(%ld): DPC handler\n", base_vha
->host_no
));
2605 if (ha
->flags
.mbox_busy
) {
2610 qla2x00_do_work(base_vha
);
2612 if (test_and_clear_bit(ISP_ABORT_NEEDED
,
2613 &base_vha
->dpc_flags
)) {
2615 DEBUG(printk("scsi(%ld): dpc: sched "
2616 "qla2x00_abort_isp ha = %p\n",
2617 base_vha
->host_no
, ha
));
2618 if (!(test_and_set_bit(ABORT_ISP_ACTIVE
,
2619 &base_vha
->dpc_flags
))) {
2621 if (qla2x00_abort_isp(base_vha
)) {
2622 /* failed. retry later */
2623 set_bit(ISP_ABORT_NEEDED
,
2624 &base_vha
->dpc_flags
);
2626 clear_bit(ABORT_ISP_ACTIVE
,
2627 &base_vha
->dpc_flags
);
2630 DEBUG(printk("scsi(%ld): dpc: qla2x00_abort_isp end\n",
2631 base_vha
->host_no
));
2634 if (test_bit(FCPORT_UPDATE_NEEDED
, &base_vha
->dpc_flags
)) {
2635 qla2x00_update_fcports(base_vha
);
2636 clear_bit(FCPORT_UPDATE_NEEDED
, &base_vha
->dpc_flags
);
2639 if (test_and_clear_bit(RESET_MARKER_NEEDED
,
2640 &base_vha
->dpc_flags
) &&
2641 (!(test_and_set_bit(RESET_ACTIVE
, &base_vha
->dpc_flags
)))) {
2643 DEBUG(printk("scsi(%ld): qla2x00_reset_marker()\n",
2644 base_vha
->host_no
));
2646 qla2x00_rst_aen(base_vha
);
2647 clear_bit(RESET_ACTIVE
, &base_vha
->dpc_flags
);
2650 /* Retry each device up to login retry count */
2651 if ((test_and_clear_bit(RELOGIN_NEEDED
,
2652 &base_vha
->dpc_flags
)) &&
2653 !test_bit(LOOP_RESYNC_NEEDED
, &base_vha
->dpc_flags
) &&
2654 atomic_read(&base_vha
->loop_state
) != LOOP_DOWN
) {
2656 DEBUG(printk("scsi(%ld): qla2x00_port_login()\n",
2657 base_vha
->host_no
));
2658 qla2x00_relogin(base_vha
);
2660 DEBUG(printk("scsi(%ld): qla2x00_port_login - end\n",
2661 base_vha
->host_no
));
2664 if (test_and_clear_bit(LOOP_RESYNC_NEEDED
,
2665 &base_vha
->dpc_flags
)) {
2667 DEBUG(printk("scsi(%ld): qla2x00_loop_resync()\n",
2668 base_vha
->host_no
));
2670 if (!(test_and_set_bit(LOOP_RESYNC_ACTIVE
,
2671 &base_vha
->dpc_flags
))) {
2673 rval
= qla2x00_loop_resync(base_vha
);
2675 clear_bit(LOOP_RESYNC_ACTIVE
,
2676 &base_vha
->dpc_flags
);
2679 DEBUG(printk("scsi(%ld): qla2x00_loop_resync - end\n",
2680 base_vha
->host_no
));
2683 if (test_bit(NPIV_CONFIG_NEEDED
, &base_vha
->dpc_flags
) &&
2684 atomic_read(&base_vha
->loop_state
) == LOOP_READY
) {
2685 clear_bit(NPIV_CONFIG_NEEDED
, &base_vha
->dpc_flags
);
2686 qla2xxx_flash_npiv_conf(base_vha
);
2689 if (!ha
->interrupts_on
)
2690 ha
->isp_ops
->enable_intrs(ha
);
2692 if (test_and_clear_bit(BEACON_BLINK_NEEDED
,
2693 &base_vha
->dpc_flags
))
2694 ha
->isp_ops
->beacon_blink(base_vha
);
2696 qla2x00_do_dpc_all_vps(base_vha
);
2699 } /* End of while(1) */
2701 DEBUG(printk("scsi(%ld): DPC handler exiting\n", base_vha
->host_no
));
2704 * Make sure that nobody tries to wake us up again.
2712 qla2xxx_wake_dpc(struct scsi_qla_host
*vha
)
2714 struct qla_hw_data
*ha
= vha
->hw
;
2715 struct task_struct
*t
= ha
->dpc_thread
;
2717 if (!test_bit(UNLOADING
, &vha
->dpc_flags
) && t
)
2723 * Processes asynchronous reset.
2726 * ha = adapter block pointer.
2729 qla2x00_rst_aen(scsi_qla_host_t
*vha
)
2731 if (vha
->flags
.online
&& !vha
->flags
.reset_active
&&
2732 !atomic_read(&vha
->loop_down_timer
) &&
2733 !(test_bit(ABORT_ISP_ACTIVE
, &vha
->dpc_flags
))) {
2735 clear_bit(RESET_MARKER_NEEDED
, &vha
->dpc_flags
);
2738 * Issue marker command only when we are going to start
2741 vha
->marker_needed
= 1;
2742 } while (!atomic_read(&vha
->loop_down_timer
) &&
2743 (test_bit(RESET_MARKER_NEEDED
, &vha
->dpc_flags
)));
2748 qla2x00_sp_free_dma(srb_t
*sp
)
2750 struct scsi_cmnd
*cmd
= sp
->cmd
;
2752 if (sp
->flags
& SRB_DMA_VALID
) {
2753 scsi_dma_unmap(cmd
);
2754 sp
->flags
&= ~SRB_DMA_VALID
;
2760 qla2x00_sp_compl(struct qla_hw_data
*ha
, srb_t
*sp
)
2762 struct scsi_cmnd
*cmd
= sp
->cmd
;
2764 qla2x00_sp_free_dma(sp
);
2766 mempool_free(sp
, ha
->srb_mempool
);
2768 cmd
->scsi_done(cmd
);
2771 /**************************************************************************
2777 * Context: Interrupt
2778 ***************************************************************************/
2780 qla2x00_timer(scsi_qla_host_t
*vha
)
2782 unsigned long cpu_flags
= 0;
2788 struct qla_hw_data
*ha
= vha
->hw
;
2789 struct req_que
*req
;
2791 * Ports - Port down timer.
2793 * Whenever, a port is in the LOST state we start decrementing its port
2794 * down timer every second until it reaches zero. Once it reaches zero
2795 * the port it marked DEAD.
2798 list_for_each_entry(fcport
, &vha
->vp_fcports
, list
) {
2799 if (fcport
->port_type
!= FCT_TARGET
)
2802 if (atomic_read(&fcport
->state
) == FCS_DEVICE_LOST
) {
2804 if (atomic_read(&fcport
->port_down_timer
) == 0)
2807 if (atomic_dec_and_test(&fcport
->port_down_timer
) != 0)
2808 atomic_set(&fcport
->state
, FCS_DEVICE_DEAD
);
2810 DEBUG(printk("scsi(%ld): fcport-%d - port retry count: "
2813 t
, atomic_read(&fcport
->port_down_timer
)));
2816 } /* End of for fcport */
2819 /* Loop down handler. */
2820 if (atomic_read(&vha
->loop_down_timer
) > 0 &&
2821 !(test_bit(ABORT_ISP_ACTIVE
, &vha
->dpc_flags
))
2822 && vha
->flags
.online
) {
2824 if (atomic_read(&vha
->loop_down_timer
) ==
2825 vha
->loop_down_abort_time
) {
2827 DEBUG(printk("scsi(%ld): Loop Down - aborting the "
2828 "queues before time expire\n",
2831 if (!IS_QLA2100(ha
) && vha
->link_down_timeout
)
2832 atomic_set(&vha
->loop_state
, LOOP_DEAD
);
2834 /* Schedule an ISP abort to return any tape commands. */
2835 /* NPIV - scan physical port only */
2837 spin_lock_irqsave(&ha
->hardware_lock
,
2839 req
= ha
->req_q_map
[0];
2841 index
< MAX_OUTSTANDING_COMMANDS
;
2845 sp
= req
->outstanding_cmds
[index
];
2849 if (!(sfcp
->flags
& FCF_TAPE_PRESENT
))
2852 set_bit(ISP_ABORT_NEEDED
,
2856 spin_unlock_irqrestore(&ha
->hardware_lock
,
2859 set_bit(ABORT_QUEUES_NEEDED
, &vha
->dpc_flags
);
2863 /* if the loop has been down for 4 minutes, reinit adapter */
2864 if (atomic_dec_and_test(&vha
->loop_down_timer
) != 0) {
2865 DEBUG(printk("scsi(%ld): Loop down exceed 4 mins - "
2866 "restarting queues.\n",
2869 set_bit(RESTART_QUEUES_NEEDED
, &vha
->dpc_flags
);
2872 if (!(vha
->device_flags
& DFLG_NO_CABLE
) &&
2874 DEBUG(printk("scsi(%ld): Loop down - "
2877 qla_printk(KERN_WARNING
, ha
,
2878 "Loop down - aborting ISP.\n");
2880 set_bit(ISP_ABORT_NEEDED
, &vha
->dpc_flags
);
2883 DEBUG3(printk("scsi(%ld): Loop Down - seconds remaining %d\n",
2885 atomic_read(&vha
->loop_down_timer
)));
2888 /* Check if beacon LED needs to be blinked */
2889 if (ha
->beacon_blink_led
== 1) {
2890 set_bit(BEACON_BLINK_NEEDED
, &vha
->dpc_flags
);
2894 /* Process any deferred work. */
2895 if (!list_empty(&vha
->work_list
))
2898 /* Schedule the DPC routine if needed */
2899 if ((test_bit(ISP_ABORT_NEEDED
, &vha
->dpc_flags
) ||
2900 test_bit(LOOP_RESYNC_NEEDED
, &vha
->dpc_flags
) ||
2901 test_bit(FCPORT_UPDATE_NEEDED
, &vha
->dpc_flags
) ||
2903 test_bit(RESET_MARKER_NEEDED
, &vha
->dpc_flags
) ||
2904 test_bit(BEACON_BLINK_NEEDED
, &vha
->dpc_flags
) ||
2905 test_bit(VP_DPC_NEEDED
, &vha
->dpc_flags
) ||
2906 test_bit(RELOGIN_NEEDED
, &vha
->dpc_flags
)))
2907 qla2xxx_wake_dpc(vha
);
2909 qla2x00_restart_timer(vha
, WATCH_INTERVAL
);
2912 /* Firmware interface routines. */
2915 #define FW_ISP21XX 0
2916 #define FW_ISP22XX 1
2917 #define FW_ISP2300 2
2918 #define FW_ISP2322 3
2919 #define FW_ISP24XX 4
2920 #define FW_ISP25XX 5
2921 #define FW_ISP81XX 6
2923 #define FW_FILE_ISP21XX "ql2100_fw.bin"
2924 #define FW_FILE_ISP22XX "ql2200_fw.bin"
2925 #define FW_FILE_ISP2300 "ql2300_fw.bin"
2926 #define FW_FILE_ISP2322 "ql2322_fw.bin"
2927 #define FW_FILE_ISP24XX "ql2400_fw.bin"
2928 #define FW_FILE_ISP25XX "ql2500_fw.bin"
2929 #define FW_FILE_ISP81XX "ql8100_fw.bin"
2931 static DEFINE_MUTEX(qla_fw_lock
);
2933 static struct fw_blob qla_fw_blobs
[FW_BLOBS
] = {
2934 { .name
= FW_FILE_ISP21XX
, .segs
= { 0x1000, 0 }, },
2935 { .name
= FW_FILE_ISP22XX
, .segs
= { 0x1000, 0 }, },
2936 { .name
= FW_FILE_ISP2300
, .segs
= { 0x800, 0 }, },
2937 { .name
= FW_FILE_ISP2322
, .segs
= { 0x800, 0x1c000, 0x1e000, 0 }, },
2938 { .name
= FW_FILE_ISP24XX
, },
2939 { .name
= FW_FILE_ISP25XX
, },
2940 { .name
= FW_FILE_ISP81XX
, },
2944 qla2x00_request_firmware(scsi_qla_host_t
*vha
)
2946 struct qla_hw_data
*ha
= vha
->hw
;
2947 struct fw_blob
*blob
;
2950 if (IS_QLA2100(ha
)) {
2951 blob
= &qla_fw_blobs
[FW_ISP21XX
];
2952 } else if (IS_QLA2200(ha
)) {
2953 blob
= &qla_fw_blobs
[FW_ISP22XX
];
2954 } else if (IS_QLA2300(ha
) || IS_QLA2312(ha
) || IS_QLA6312(ha
)) {
2955 blob
= &qla_fw_blobs
[FW_ISP2300
];
2956 } else if (IS_QLA2322(ha
) || IS_QLA6322(ha
)) {
2957 blob
= &qla_fw_blobs
[FW_ISP2322
];
2958 } else if (IS_QLA24XX_TYPE(ha
)) {
2959 blob
= &qla_fw_blobs
[FW_ISP24XX
];
2960 } else if (IS_QLA25XX(ha
)) {
2961 blob
= &qla_fw_blobs
[FW_ISP25XX
];
2962 } else if (IS_QLA81XX(ha
)) {
2963 blob
= &qla_fw_blobs
[FW_ISP81XX
];
2966 mutex_lock(&qla_fw_lock
);
2970 if (request_firmware(&blob
->fw
, blob
->name
, &ha
->pdev
->dev
)) {
2971 DEBUG2(printk("scsi(%ld): Failed to load firmware image "
2972 "(%s).\n", vha
->host_no
, blob
->name
));
2979 mutex_unlock(&qla_fw_lock
);
2984 qla2x00_release_firmware(void)
2988 mutex_lock(&qla_fw_lock
);
2989 for (idx
= 0; idx
< FW_BLOBS
; idx
++)
2990 if (qla_fw_blobs
[idx
].fw
)
2991 release_firmware(qla_fw_blobs
[idx
].fw
);
2992 mutex_unlock(&qla_fw_lock
);
2995 static pci_ers_result_t
2996 qla2xxx_pci_error_detected(struct pci_dev
*pdev
, pci_channel_state_t state
)
2999 case pci_channel_io_normal
:
3000 return PCI_ERS_RESULT_CAN_RECOVER
;
3001 case pci_channel_io_frozen
:
3002 pci_disable_device(pdev
);
3003 return PCI_ERS_RESULT_NEED_RESET
;
3004 case pci_channel_io_perm_failure
:
3005 qla2x00_remove_one(pdev
);
3006 return PCI_ERS_RESULT_DISCONNECT
;
3008 return PCI_ERS_RESULT_NEED_RESET
;
3011 static pci_ers_result_t
3012 qla2xxx_pci_mmio_enabled(struct pci_dev
*pdev
)
3014 int risc_paused
= 0;
3016 unsigned long flags
;
3017 scsi_qla_host_t
*base_vha
= pci_get_drvdata(pdev
);
3018 struct qla_hw_data
*ha
= base_vha
->hw
;
3019 struct device_reg_2xxx __iomem
*reg
= &ha
->iobase
->isp
;
3020 struct device_reg_24xx __iomem
*reg24
= &ha
->iobase
->isp24
;
3022 spin_lock_irqsave(&ha
->hardware_lock
, flags
);
3023 if (IS_QLA2100(ha
) || IS_QLA2200(ha
)){
3024 stat
= RD_REG_DWORD(®
->hccr
);
3025 if (stat
& HCCR_RISC_PAUSE
)
3027 } else if (IS_QLA23XX(ha
)) {
3028 stat
= RD_REG_DWORD(®
->u
.isp2300
.host_status
);
3029 if (stat
& HSR_RISC_PAUSED
)
3031 } else if (IS_FWI2_CAPABLE(ha
)) {
3032 stat
= RD_REG_DWORD(®24
->host_status
);
3033 if (stat
& HSRX_RISC_PAUSED
)
3036 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
3039 qla_printk(KERN_INFO
, ha
, "RISC paused -- mmio_enabled, "
3040 "Dumping firmware!\n");
3041 ha
->isp_ops
->fw_dump(base_vha
, 0);
3043 return PCI_ERS_RESULT_NEED_RESET
;
3045 return PCI_ERS_RESULT_RECOVERED
;
3048 static pci_ers_result_t
3049 qla2xxx_pci_slot_reset(struct pci_dev
*pdev
)
3051 pci_ers_result_t ret
= PCI_ERS_RESULT_DISCONNECT
;
3052 scsi_qla_host_t
*base_vha
= pci_get_drvdata(pdev
);
3053 struct qla_hw_data
*ha
= base_vha
->hw
;
3057 rc
= pci_enable_device_mem(pdev
);
3059 rc
= pci_enable_device(pdev
);
3062 qla_printk(KERN_WARNING
, ha
,
3063 "Can't re-enable PCI device after reset.\n");
3067 pci_set_master(pdev
);
3069 if (ha
->isp_ops
->pci_config(base_vha
))
3072 set_bit(ABORT_ISP_ACTIVE
, &base_vha
->dpc_flags
);
3073 if (qla2x00_abort_isp(base_vha
) == QLA_SUCCESS
)
3074 ret
= PCI_ERS_RESULT_RECOVERED
;
3075 clear_bit(ABORT_ISP_ACTIVE
, &base_vha
->dpc_flags
);
3081 qla2xxx_pci_resume(struct pci_dev
*pdev
)
3083 scsi_qla_host_t
*base_vha
= pci_get_drvdata(pdev
);
3084 struct qla_hw_data
*ha
= base_vha
->hw
;
3087 ret
= qla2x00_wait_for_hba_online(base_vha
);
3088 if (ret
!= QLA_SUCCESS
) {
3089 qla_printk(KERN_ERR
, ha
,
3090 "the device failed to resume I/O "
3091 "from slot/link_reset");
3093 pci_cleanup_aer_uncorrect_error_status(pdev
);
3096 static struct pci_error_handlers qla2xxx_err_handler
= {
3097 .error_detected
= qla2xxx_pci_error_detected
,
3098 .mmio_enabled
= qla2xxx_pci_mmio_enabled
,
3099 .slot_reset
= qla2xxx_pci_slot_reset
,
3100 .resume
= qla2xxx_pci_resume
,
3103 static struct pci_device_id qla2xxx_pci_tbl
[] = {
3104 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC
, PCI_DEVICE_ID_QLOGIC_ISP2100
) },
3105 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC
, PCI_DEVICE_ID_QLOGIC_ISP2200
) },
3106 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC
, PCI_DEVICE_ID_QLOGIC_ISP2300
) },
3107 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC
, PCI_DEVICE_ID_QLOGIC_ISP2312
) },
3108 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC
, PCI_DEVICE_ID_QLOGIC_ISP2322
) },
3109 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC
, PCI_DEVICE_ID_QLOGIC_ISP6312
) },
3110 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC
, PCI_DEVICE_ID_QLOGIC_ISP6322
) },
3111 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC
, PCI_DEVICE_ID_QLOGIC_ISP2422
) },
3112 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC
, PCI_DEVICE_ID_QLOGIC_ISP2432
) },
3113 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC
, PCI_DEVICE_ID_QLOGIC_ISP8432
) },
3114 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC
, PCI_DEVICE_ID_QLOGIC_ISP5422
) },
3115 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC
, PCI_DEVICE_ID_QLOGIC_ISP5432
) },
3116 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC
, PCI_DEVICE_ID_QLOGIC_ISP2532
) },
3117 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC
, PCI_DEVICE_ID_QLOGIC_ISP8001
) },
3120 MODULE_DEVICE_TABLE(pci
, qla2xxx_pci_tbl
);
3122 static struct pci_driver qla2xxx_pci_driver
= {
3123 .name
= QLA2XXX_DRIVER_NAME
,
3125 .owner
= THIS_MODULE
,
3127 .id_table
= qla2xxx_pci_tbl
,
3128 .probe
= qla2x00_probe_one
,
3129 .remove
= qla2x00_remove_one
,
3130 .err_handler
= &qla2xxx_err_handler
,
3134 * qla2x00_module_init - Module initialization.
3137 qla2x00_module_init(void)
3141 /* Allocate cache for SRBs. */
3142 srb_cachep
= kmem_cache_create("qla2xxx_srbs", sizeof(srb_t
), 0,
3143 SLAB_HWCACHE_ALIGN
, NULL
);
3144 if (srb_cachep
== NULL
) {
3146 "qla2xxx: Unable to allocate SRB cache...Failing load!\n");
3150 /* Derive version string. */
3151 strcpy(qla2x00_version_str
, QLA2XXX_VERSION
);
3152 if (ql2xextended_error_logging
)
3153 strcat(qla2x00_version_str
, "-debug");
3155 qla2xxx_transport_template
=
3156 fc_attach_transport(&qla2xxx_transport_functions
);
3157 if (!qla2xxx_transport_template
) {
3158 kmem_cache_destroy(srb_cachep
);
3161 qla2xxx_transport_vport_template
=
3162 fc_attach_transport(&qla2xxx_transport_vport_functions
);
3163 if (!qla2xxx_transport_vport_template
) {
3164 kmem_cache_destroy(srb_cachep
);
3165 fc_release_transport(qla2xxx_transport_template
);
3169 printk(KERN_INFO
"QLogic Fibre Channel HBA Driver: %s\n",
3170 qla2x00_version_str
);
3171 ret
= pci_register_driver(&qla2xxx_pci_driver
);
3173 kmem_cache_destroy(srb_cachep
);
3174 fc_release_transport(qla2xxx_transport_template
);
3175 fc_release_transport(qla2xxx_transport_vport_template
);
3181 * qla2x00_module_exit - Module cleanup.
3184 qla2x00_module_exit(void)
3186 pci_unregister_driver(&qla2xxx_pci_driver
);
3187 qla2x00_release_firmware();
3188 kmem_cache_destroy(srb_cachep
);
3189 fc_release_transport(qla2xxx_transport_template
);
3190 fc_release_transport(qla2xxx_transport_vport_template
);
3193 module_init(qla2x00_module_init
);
3194 module_exit(qla2x00_module_exit
);
3196 MODULE_AUTHOR("QLogic Corporation");
3197 MODULE_DESCRIPTION("QLogic Fibre Channel HBA Driver");
3198 MODULE_LICENSE("GPL");
3199 MODULE_VERSION(QLA2XXX_VERSION
);
3200 MODULE_FIRMWARE(FW_FILE_ISP21XX
);
3201 MODULE_FIRMWARE(FW_FILE_ISP22XX
);
3202 MODULE_FIRMWARE(FW_FILE_ISP2300
);
3203 MODULE_FIRMWARE(FW_FILE_ISP2322
);
3204 MODULE_FIRMWARE(FW_FILE_ISP24XX
);
3205 MODULE_FIRMWARE(FW_FILE_ISP25XX
);
3206 MODULE_FIRMWARE(FW_FILE_ISP81XX
);