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
*);
68 static void qla2x00_config_dma_addressing(scsi_qla_host_t
*ha
);
71 module_param(ql2xfdmienable
, int, S_IRUGO
|S_IRUSR
);
72 MODULE_PARM_DESC(ql2xfdmienable
,
73 "Enables FDMI registratons "
74 "Default is 0 - no FDMI. 1 - perfom FDMI.");
76 #define MAX_Q_DEPTH 32
77 static int ql2xmaxqdepth
= MAX_Q_DEPTH
;
78 module_param(ql2xmaxqdepth
, int, S_IRUGO
|S_IWUSR
);
79 MODULE_PARM_DESC(ql2xmaxqdepth
,
80 "Maximum queue depth to report for target devices.");
82 int ql2xqfullrampup
= 120;
83 module_param(ql2xqfullrampup
, int, S_IRUGO
|S_IWUSR
);
84 MODULE_PARM_DESC(ql2xqfullrampup
,
85 "Number of seconds to wait to begin to ramp-up the queue "
86 "depth for a device after a queue-full condition has been "
87 "detected. Default is 120 seconds.");
89 int ql2xiidmaenable
=1;
90 module_param(ql2xiidmaenable
, int, S_IRUGO
|S_IRUSR
);
91 MODULE_PARM_DESC(ql2xiidmaenable
,
92 "Enables iIDMA settings "
93 "Default is 1 - perform iIDMA. 0 - no iIDMA.");
95 int ql2xmaxqueues
= 1;
96 module_param(ql2xmaxqueues
, int, S_IRUGO
|S_IRUSR
);
97 MODULE_PARM_DESC(ql2xmaxqueues
,
98 "Enables MQ settings "
99 "Default is 1 for single queue. Set it to number \
100 of queues in MQ mode.");
102 * SCSI host template entry points
104 static int qla2xxx_slave_configure(struct scsi_device
* device
);
105 static int qla2xxx_slave_alloc(struct scsi_device
*);
106 static int qla2xxx_scan_finished(struct Scsi_Host
*, unsigned long time
);
107 static void qla2xxx_scan_start(struct Scsi_Host
*);
108 static void qla2xxx_slave_destroy(struct scsi_device
*);
109 static int qla2x00_queuecommand(struct scsi_cmnd
*cmd
,
110 void (*fn
)(struct scsi_cmnd
*));
111 static int qla24xx_queuecommand(struct scsi_cmnd
*cmd
,
112 void (*fn
)(struct scsi_cmnd
*));
113 static int qla2xxx_eh_abort(struct scsi_cmnd
*);
114 static int qla2xxx_eh_device_reset(struct scsi_cmnd
*);
115 static int qla2xxx_eh_target_reset(struct scsi_cmnd
*);
116 static int qla2xxx_eh_bus_reset(struct scsi_cmnd
*);
117 static int qla2xxx_eh_host_reset(struct scsi_cmnd
*);
119 static int qla2x00_change_queue_depth(struct scsi_device
*, int);
120 static int qla2x00_change_queue_type(struct scsi_device
*, int);
122 static struct scsi_host_template qla2x00_driver_template
= {
123 .module
= THIS_MODULE
,
124 .name
= QLA2XXX_DRIVER_NAME
,
125 .queuecommand
= qla2x00_queuecommand
,
127 .eh_abort_handler
= qla2xxx_eh_abort
,
128 .eh_device_reset_handler
= qla2xxx_eh_device_reset
,
129 .eh_target_reset_handler
= qla2xxx_eh_target_reset
,
130 .eh_bus_reset_handler
= qla2xxx_eh_bus_reset
,
131 .eh_host_reset_handler
= qla2xxx_eh_host_reset
,
133 .slave_configure
= qla2xxx_slave_configure
,
135 .slave_alloc
= qla2xxx_slave_alloc
,
136 .slave_destroy
= qla2xxx_slave_destroy
,
137 .scan_finished
= qla2xxx_scan_finished
,
138 .scan_start
= qla2xxx_scan_start
,
139 .change_queue_depth
= qla2x00_change_queue_depth
,
140 .change_queue_type
= qla2x00_change_queue_type
,
143 .use_clustering
= ENABLE_CLUSTERING
,
144 .sg_tablesize
= SG_ALL
,
147 * The RISC allows for each command to transfer (2^32-1) bytes of data,
148 * which equates to 0x800000 sectors.
150 .max_sectors
= 0xFFFF,
151 .shost_attrs
= qla2x00_host_attrs
,
154 struct scsi_host_template qla24xx_driver_template
= {
155 .module
= THIS_MODULE
,
156 .name
= QLA2XXX_DRIVER_NAME
,
157 .queuecommand
= qla24xx_queuecommand
,
159 .eh_abort_handler
= qla2xxx_eh_abort
,
160 .eh_device_reset_handler
= qla2xxx_eh_device_reset
,
161 .eh_target_reset_handler
= qla2xxx_eh_target_reset
,
162 .eh_bus_reset_handler
= qla2xxx_eh_bus_reset
,
163 .eh_host_reset_handler
= qla2xxx_eh_host_reset
,
165 .slave_configure
= qla2xxx_slave_configure
,
167 .slave_alloc
= qla2xxx_slave_alloc
,
168 .slave_destroy
= qla2xxx_slave_destroy
,
169 .scan_finished
= qla2xxx_scan_finished
,
170 .scan_start
= qla2xxx_scan_start
,
171 .change_queue_depth
= qla2x00_change_queue_depth
,
172 .change_queue_type
= qla2x00_change_queue_type
,
175 .use_clustering
= ENABLE_CLUSTERING
,
176 .sg_tablesize
= SG_ALL
,
178 .max_sectors
= 0xFFFF,
179 .shost_attrs
= qla2x00_host_attrs
,
182 static struct scsi_transport_template
*qla2xxx_transport_template
= NULL
;
183 struct scsi_transport_template
*qla2xxx_transport_vport_template
= NULL
;
185 /* TODO Convert to inlines
191 qla2x00_start_timer(scsi_qla_host_t
*vha
, void *func
, unsigned long interval
)
193 init_timer(&vha
->timer
);
194 vha
->timer
.expires
= jiffies
+ interval
* HZ
;
195 vha
->timer
.data
= (unsigned long)vha
;
196 vha
->timer
.function
= (void (*)(unsigned long))func
;
197 add_timer(&vha
->timer
);
198 vha
->timer_active
= 1;
202 qla2x00_restart_timer(scsi_qla_host_t
*vha
, unsigned long interval
)
204 mod_timer(&vha
->timer
, jiffies
+ interval
* HZ
);
207 static __inline__
void
208 qla2x00_stop_timer(scsi_qla_host_t
*vha
)
210 del_timer_sync(&vha
->timer
);
211 vha
->timer_active
= 0;
214 static int qla2x00_do_dpc(void *data
);
216 static void qla2x00_rst_aen(scsi_qla_host_t
*);
218 static int qla2x00_mem_alloc(struct qla_hw_data
*, uint16_t, uint16_t,
219 struct req_que
**, struct rsp_que
**);
220 static void qla2x00_mem_free(struct qla_hw_data
*);
221 static void qla2x00_sp_free_dma(srb_t
*);
223 /* -------------------------------------------------------------------------- */
224 static int qla2x00_alloc_queues(struct qla_hw_data
*ha
)
226 ha
->req_q_map
= kzalloc(sizeof(struct req_que
*) * ha
->max_queues
,
228 if (!ha
->req_q_map
) {
229 qla_printk(KERN_WARNING
, ha
,
230 "Unable to allocate memory for request queue ptrs\n");
234 ha
->rsp_q_map
= kzalloc(sizeof(struct rsp_que
*) * ha
->max_queues
,
236 if (!ha
->rsp_q_map
) {
237 qla_printk(KERN_WARNING
, ha
,
238 "Unable to allocate memory for response queue ptrs\n");
241 set_bit(0, ha
->rsp_qid_map
);
242 set_bit(0, ha
->req_qid_map
);
246 kfree(ha
->req_q_map
);
247 ha
->req_q_map
= NULL
;
252 static void qla2x00_free_que(struct qla_hw_data
*ha
, struct req_que
*req
,
255 if (rsp
&& rsp
->ring
)
256 dma_free_coherent(&ha
->pdev
->dev
,
257 (rsp
->length
+ 1) * sizeof(response_t
),
258 rsp
->ring
, rsp
->dma
);
262 if (req
&& req
->ring
)
263 dma_free_coherent(&ha
->pdev
->dev
,
264 (req
->length
+ 1) * sizeof(request_t
),
265 req
->ring
, req
->dma
);
271 static void qla2x00_free_queues(struct qla_hw_data
*ha
)
277 for (cnt
= 0; cnt
< ha
->max_queues
; cnt
++) {
278 rsp
= ha
->rsp_q_map
[cnt
];
279 req
= ha
->req_q_map
[cnt
];
280 qla2x00_free_que(ha
, req
, rsp
);
282 kfree(ha
->rsp_q_map
);
283 ha
->rsp_q_map
= NULL
;
285 kfree(ha
->req_q_map
);
286 ha
->req_q_map
= NULL
;
290 qla2x00_pci_info_str(struct scsi_qla_host
*vha
, char *str
)
292 struct qla_hw_data
*ha
= vha
->hw
;
293 static char *pci_bus_modes
[] = {
294 "33", "66", "100", "133",
299 pci_bus
= (ha
->pci_attr
& (BIT_9
| BIT_10
)) >> 9;
302 strcat(str
, pci_bus_modes
[pci_bus
]);
304 pci_bus
= (ha
->pci_attr
& BIT_8
) >> 8;
306 strcat(str
, pci_bus_modes
[pci_bus
]);
308 strcat(str
, " MHz)");
314 qla24xx_pci_info_str(struct scsi_qla_host
*vha
, char *str
)
316 static char *pci_bus_modes
[] = { "33", "66", "100", "133", };
317 struct qla_hw_data
*ha
= vha
->hw
;
321 pcie_reg
= pci_find_capability(ha
->pdev
, PCI_CAP_ID_EXP
);
324 uint16_t pcie_lstat
, lspeed
, lwidth
;
327 pci_read_config_word(ha
->pdev
, pcie_reg
, &pcie_lstat
);
328 lspeed
= pcie_lstat
& (BIT_0
| BIT_1
| BIT_2
| BIT_3
);
329 lwidth
= (pcie_lstat
&
330 (BIT_4
| BIT_5
| BIT_6
| BIT_7
| BIT_8
| BIT_9
)) >> 4;
332 strcpy(str
, "PCIe (");
334 strcat(str
, "2.5GT/s ");
335 else if (lspeed
== 2)
336 strcat(str
, "5.0GT/s ");
338 strcat(str
, "<unknown> ");
339 snprintf(lwstr
, sizeof(lwstr
), "x%d)", lwidth
);
346 pci_bus
= (ha
->pci_attr
& CSRX_PCIX_BUS_MODE_MASK
) >> 8;
347 if (pci_bus
== 0 || pci_bus
== 8) {
349 strcat(str
, pci_bus_modes
[pci_bus
>> 3]);
353 strcat(str
, "Mode 2");
355 strcat(str
, "Mode 1");
357 strcat(str
, pci_bus_modes
[pci_bus
& ~BIT_2
]);
359 strcat(str
, " MHz)");
365 qla2x00_fw_version_str(struct scsi_qla_host
*vha
, char *str
)
368 struct qla_hw_data
*ha
= vha
->hw
;
370 sprintf(str
, "%d.%02d.%02d ", ha
->fw_major_version
,
371 ha
->fw_minor_version
,
372 ha
->fw_subminor_version
);
374 if (ha
->fw_attributes
& BIT_9
) {
379 switch (ha
->fw_attributes
& 0xFF) {
393 sprintf(un_str
, "(%x)", ha
->fw_attributes
);
397 if (ha
->fw_attributes
& 0x100)
404 qla24xx_fw_version_str(struct scsi_qla_host
*vha
, char *str
)
406 struct qla_hw_data
*ha
= vha
->hw
;
408 sprintf(str
, "%d.%02d.%02d (%x)", ha
->fw_major_version
,
409 ha
->fw_minor_version
, ha
->fw_subminor_version
, ha
->fw_attributes
);
413 static inline srb_t
*
414 qla2x00_get_new_sp(scsi_qla_host_t
*vha
, fc_port_t
*fcport
,
415 struct scsi_cmnd
*cmd
, void (*done
)(struct scsi_cmnd
*))
418 struct qla_hw_data
*ha
= vha
->hw
;
420 sp
= mempool_alloc(ha
->srb_mempool
, GFP_ATOMIC
);
426 sp
->que
= ha
->req_q_map
[0];
428 CMD_SP(cmd
) = (void *)sp
;
429 cmd
->scsi_done
= done
;
435 qla2x00_queuecommand(struct scsi_cmnd
*cmd
, void (*done
)(struct scsi_cmnd
*))
437 scsi_qla_host_t
*vha
= shost_priv(cmd
->device
->host
);
438 fc_port_t
*fcport
= (struct fc_port
*) cmd
->device
->hostdata
;
439 struct fc_rport
*rport
= starget_to_rport(scsi_target(cmd
->device
));
440 struct qla_hw_data
*ha
= vha
->hw
;
444 if (unlikely(pci_channel_offline(ha
->pdev
))) {
445 cmd
->result
= DID_REQUEUE
<< 16;
446 goto qc_fail_command
;
449 rval
= fc_remote_port_chkready(rport
);
452 goto qc_fail_command
;
455 /* Close window on fcport/rport state-transitioning. */
459 if (atomic_read(&fcport
->state
) != FCS_ONLINE
) {
460 if (atomic_read(&fcport
->state
) == FCS_DEVICE_DEAD
||
461 atomic_read(&vha
->loop_state
) == LOOP_DEAD
) {
462 cmd
->result
= DID_NO_CONNECT
<< 16;
463 goto qc_fail_command
;
468 spin_unlock_irq(vha
->host
->host_lock
);
470 sp
= qla2x00_get_new_sp(vha
, fcport
, cmd
, done
);
472 goto qc_host_busy_lock
;
474 rval
= ha
->isp_ops
->start_scsi(sp
);
475 if (rval
!= QLA_SUCCESS
)
476 goto qc_host_busy_free_sp
;
478 spin_lock_irq(vha
->host
->host_lock
);
482 qc_host_busy_free_sp
:
483 qla2x00_sp_free_dma(sp
);
484 mempool_free(sp
, ha
->srb_mempool
);
487 spin_lock_irq(vha
->host
->host_lock
);
488 return SCSI_MLQUEUE_HOST_BUSY
;
491 return SCSI_MLQUEUE_TARGET_BUSY
;
501 qla24xx_queuecommand(struct scsi_cmnd
*cmd
, void (*done
)(struct scsi_cmnd
*))
503 scsi_qla_host_t
*vha
= shost_priv(cmd
->device
->host
);
504 fc_port_t
*fcport
= (struct fc_port
*) cmd
->device
->hostdata
;
505 struct fc_rport
*rport
= starget_to_rport(scsi_target(cmd
->device
));
506 struct qla_hw_data
*ha
= vha
->hw
;
507 struct scsi_qla_host
*base_vha
= pci_get_drvdata(ha
->pdev
);
511 if (unlikely(pci_channel_offline(ha
->pdev
))) {
512 cmd
->result
= DID_REQUEUE
<< 16;
513 goto qc24_fail_command
;
516 rval
= fc_remote_port_chkready(rport
);
519 goto qc24_fail_command
;
522 /* Close window on fcport/rport state-transitioning. */
524 goto qc24_target_busy
;
526 if (atomic_read(&fcport
->state
) != FCS_ONLINE
) {
527 if (atomic_read(&fcport
->state
) == FCS_DEVICE_DEAD
||
528 atomic_read(&base_vha
->loop_state
) == LOOP_DEAD
) {
529 cmd
->result
= DID_NO_CONNECT
<< 16;
530 goto qc24_fail_command
;
532 goto qc24_target_busy
;
535 spin_unlock_irq(vha
->host
->host_lock
);
537 sp
= qla2x00_get_new_sp(base_vha
, fcport
, cmd
, done
);
539 goto qc24_host_busy_lock
;
541 rval
= ha
->isp_ops
->start_scsi(sp
);
542 if (rval
!= QLA_SUCCESS
)
543 goto qc24_host_busy_free_sp
;
545 spin_lock_irq(vha
->host
->host_lock
);
549 qc24_host_busy_free_sp
:
550 qla2x00_sp_free_dma(sp
);
551 mempool_free(sp
, ha
->srb_mempool
);
554 spin_lock_irq(vha
->host
->host_lock
);
555 return SCSI_MLQUEUE_HOST_BUSY
;
558 return SCSI_MLQUEUE_TARGET_BUSY
;
568 * qla2x00_eh_wait_on_command
569 * Waits for the command to be returned by the Firmware for some
573 * cmd = Scsi Command to wait on.
580 qla2x00_eh_wait_on_command(struct scsi_cmnd
*cmd
)
582 #define ABORT_POLLING_PERIOD 1000
583 #define ABORT_WAIT_ITER ((10 * 1000) / (ABORT_POLLING_PERIOD))
584 unsigned long wait_iter
= ABORT_WAIT_ITER
;
585 int ret
= QLA_SUCCESS
;
587 while (CMD_SP(cmd
)) {
588 msleep(ABORT_POLLING_PERIOD
);
594 ret
= QLA_FUNCTION_FAILED
;
600 * qla2x00_wait_for_hba_online
601 * Wait till the HBA is online after going through
602 * <= MAX_RETRIES_OF_ISP_ABORT or
603 * finally HBA is disabled ie marked offline
606 * ha - pointer to host adapter structure
609 * Does context switching-Release SPIN_LOCK
610 * (if any) before calling this routine.
613 * Success (Adapter is online) : 0
614 * Failed (Adapter is offline/disabled) : 1
617 qla2x00_wait_for_hba_online(scsi_qla_host_t
*vha
)
620 unsigned long wait_online
;
621 struct qla_hw_data
*ha
= vha
->hw
;
622 scsi_qla_host_t
*base_vha
= pci_get_drvdata(ha
->pdev
);
624 wait_online
= jiffies
+ (MAX_LOOP_TIMEOUT
* HZ
);
625 while (((test_bit(ISP_ABORT_NEEDED
, &base_vha
->dpc_flags
)) ||
626 test_bit(ABORT_ISP_ACTIVE
, &base_vha
->dpc_flags
) ||
627 test_bit(ISP_ABORT_RETRY
, &base_vha
->dpc_flags
) ||
628 ha
->dpc_active
) && time_before(jiffies
, wait_online
)) {
632 if (base_vha
->flags
.online
)
633 return_status
= QLA_SUCCESS
;
635 return_status
= QLA_FUNCTION_FAILED
;
637 return (return_status
);
641 * qla2x00_wait_for_loop_ready
642 * Wait for MAX_LOOP_TIMEOUT(5 min) value for loop
643 * to be in LOOP_READY state.
645 * ha - pointer to host adapter structure
648 * Does context switching-Release SPIN_LOCK
649 * (if any) before calling this routine.
653 * Success (LOOP_READY) : 0
654 * Failed (LOOP_NOT_READY) : 1
657 qla2x00_wait_for_loop_ready(scsi_qla_host_t
*vha
)
659 int return_status
= QLA_SUCCESS
;
660 unsigned long loop_timeout
;
661 struct qla_hw_data
*ha
= vha
->hw
;
662 scsi_qla_host_t
*base_vha
= pci_get_drvdata(ha
->pdev
);
664 /* wait for 5 min at the max for loop to be ready */
665 loop_timeout
= jiffies
+ (MAX_LOOP_TIMEOUT
* HZ
);
667 while ((!atomic_read(&base_vha
->loop_down_timer
) &&
668 atomic_read(&base_vha
->loop_state
) == LOOP_DOWN
) ||
669 atomic_read(&base_vha
->loop_state
) != LOOP_READY
) {
670 if (atomic_read(&base_vha
->loop_state
) == LOOP_DEAD
) {
671 return_status
= QLA_FUNCTION_FAILED
;
675 if (time_after_eq(jiffies
, loop_timeout
)) {
676 return_status
= QLA_FUNCTION_FAILED
;
680 return (return_status
);
684 qla2x00_abort_fcport_cmds(fc_port_t
*fcport
)
689 scsi_qla_host_t
*vha
= fcport
->vha
;
690 struct qla_hw_data
*ha
= vha
->hw
;
693 spin_lock_irqsave(&ha
->hardware_lock
, flags
);
694 for (que
= 0; que
< QLA_MAX_HOST_QUES
; que
++) {
695 id
= vha
->req_ques
[que
];
696 req
= ha
->req_q_map
[id
];
699 for (cnt
= 1; cnt
< MAX_OUTSTANDING_COMMANDS
; cnt
++) {
700 sp
= req
->outstanding_cmds
[cnt
];
703 if (sp
->fcport
!= fcport
)
706 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
707 if (ha
->isp_ops
->abort_command(vha
, sp
, req
)) {
708 DEBUG2(qla_printk(KERN_WARNING
, ha
,
709 "Abort failed -- %lx\n",
710 sp
->cmd
->serial_number
));
712 if (qla2x00_eh_wait_on_command(sp
->cmd
) !=
714 DEBUG2(qla_printk(KERN_WARNING
, ha
,
715 "Abort failed while waiting -- %lx\n",
716 sp
->cmd
->serial_number
));
718 spin_lock_irqsave(&ha
->hardware_lock
, flags
);
721 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
725 qla2x00_block_error_handler(struct scsi_cmnd
*cmnd
)
727 struct Scsi_Host
*shost
= cmnd
->device
->host
;
728 struct fc_rport
*rport
= starget_to_rport(scsi_target(cmnd
->device
));
731 spin_lock_irqsave(shost
->host_lock
, flags
);
732 while (rport
->port_state
== FC_PORTSTATE_BLOCKED
) {
733 spin_unlock_irqrestore(shost
->host_lock
, flags
);
735 spin_lock_irqsave(shost
->host_lock
, flags
);
737 spin_unlock_irqrestore(shost
->host_lock
, flags
);
741 /**************************************************************************
745 * The abort function will abort the specified command.
748 * cmd = Linux SCSI command packet to be aborted.
751 * Either SUCCESS or FAILED.
754 * Only return FAILED if command not returned by firmware.
755 **************************************************************************/
757 qla2xxx_eh_abort(struct scsi_cmnd
*cmd
)
759 scsi_qla_host_t
*vha
= shost_priv(cmd
->device
->host
);
762 unsigned int id
, lun
;
763 unsigned long serial
;
766 struct qla_hw_data
*ha
= vha
->hw
;
770 qla2x00_block_error_handler(cmd
);
777 id
= cmd
->device
->id
;
778 lun
= cmd
->device
->lun
;
779 serial
= cmd
->serial_number
;
780 spt
= (srb_t
*) CMD_SP(cmd
);
785 /* Check active list for command command. */
786 spin_lock_irqsave(&ha
->hardware_lock
, flags
);
787 for (i
= 1; i
< MAX_OUTSTANDING_COMMANDS
; i
++) {
788 sp
= req
->outstanding_cmds
[i
];
796 DEBUG2(printk("%s(%ld): aborting sp %p from RISC."
797 " pid=%ld.\n", __func__
, vha
->host_no
, sp
, serial
));
799 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
800 if (ha
->isp_ops
->abort_command(vha
, sp
, req
)) {
801 DEBUG2(printk("%s(%ld): abort_command "
802 "mbx failed.\n", __func__
, vha
->host_no
));
805 DEBUG3(printk("%s(%ld): abort_command "
806 "mbx success.\n", __func__
, vha
->host_no
));
809 spin_lock_irqsave(&ha
->hardware_lock
, flags
);
812 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
814 /* Wait for the command to be returned. */
816 if (qla2x00_eh_wait_on_command(cmd
) != QLA_SUCCESS
) {
817 qla_printk(KERN_ERR
, ha
,
818 "scsi(%ld:%d:%d): Abort handler timed out -- %lx "
819 "%x.\n", vha
->host_no
, id
, lun
, serial
, ret
);
824 qla_printk(KERN_INFO
, ha
,
825 "scsi(%ld:%d:%d): Abort command issued -- %d %lx %x.\n",
826 vha
->host_no
, id
, lun
, wait
, serial
, ret
);
831 enum nexus_wait_type
{
838 qla2x00_eh_wait_for_pending_commands(scsi_qla_host_t
*vha
, unsigned int t
,
839 unsigned int l
, srb_t
*sp
, enum nexus_wait_type type
)
841 int cnt
, match
, status
;
843 struct qla_hw_data
*ha
= vha
->hw
;
846 status
= QLA_SUCCESS
;
850 spin_lock_irqsave(&ha
->hardware_lock
, flags
);
852 for (cnt
= 1; status
== QLA_SUCCESS
&&
853 cnt
< MAX_OUTSTANDING_COMMANDS
; cnt
++) {
854 sp
= req
->outstanding_cmds
[cnt
];
858 if (vha
->vp_idx
!= sp
->fcport
->vha
->vp_idx
)
866 match
= sp
->cmd
->device
->id
== t
;
869 match
= (sp
->cmd
->device
->id
== t
&&
870 sp
->cmd
->device
->lun
== l
);
876 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
877 status
= qla2x00_eh_wait_on_command(sp
->cmd
);
878 spin_lock_irqsave(&ha
->hardware_lock
, flags
);
880 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
885 static char *reset_errors
[] = {
888 "Task management failed",
889 "Waiting for command completions",
893 __qla2xxx_eh_generic_reset(char *name
, enum nexus_wait_type type
,
894 struct scsi_cmnd
*cmd
, int (*do_reset
)(struct fc_port
*, unsigned int))
896 scsi_qla_host_t
*vha
= shost_priv(cmd
->device
->host
);
897 fc_port_t
*fcport
= (struct fc_port
*) cmd
->device
->hostdata
;
900 qla2x00_block_error_handler(cmd
);
905 qla_printk(KERN_INFO
, vha
->hw
, "scsi(%ld:%d:%d): %s RESET ISSUED.\n",
906 vha
->host_no
, cmd
->device
->id
, cmd
->device
->lun
, name
);
909 if (qla2x00_wait_for_hba_online(vha
) != QLA_SUCCESS
)
910 goto eh_reset_failed
;
912 if (qla2x00_wait_for_loop_ready(vha
) != QLA_SUCCESS
)
913 goto eh_reset_failed
;
915 if (do_reset(fcport
, cmd
->device
->lun
) != QLA_SUCCESS
)
916 goto eh_reset_failed
;
918 if (qla2x00_eh_wait_for_pending_commands(vha
, cmd
->device
->id
,
919 cmd
->device
->lun
, (srb_t
*) CMD_SP(cmd
), type
) != QLA_SUCCESS
)
920 goto eh_reset_failed
;
922 qla_printk(KERN_INFO
, vha
->hw
, "scsi(%ld:%d:%d): %s RESET SUCCEEDED.\n",
923 vha
->host_no
, cmd
->device
->id
, cmd
->device
->lun
, name
);
928 qla_printk(KERN_INFO
, vha
->hw
, "scsi(%ld:%d:%d): %s RESET FAILED: %s.\n"
929 , vha
->host_no
, cmd
->device
->id
, cmd
->device
->lun
, name
,
935 qla2xxx_eh_device_reset(struct scsi_cmnd
*cmd
)
937 scsi_qla_host_t
*vha
= shost_priv(cmd
->device
->host
);
938 struct qla_hw_data
*ha
= vha
->hw
;
940 return __qla2xxx_eh_generic_reset("DEVICE", WAIT_LUN
, cmd
,
941 ha
->isp_ops
->lun_reset
);
945 qla2xxx_eh_target_reset(struct scsi_cmnd
*cmd
)
947 scsi_qla_host_t
*vha
= shost_priv(cmd
->device
->host
);
948 struct qla_hw_data
*ha
= vha
->hw
;
950 return __qla2xxx_eh_generic_reset("TARGET", WAIT_TARGET
, cmd
,
951 ha
->isp_ops
->target_reset
);
954 /**************************************************************************
955 * qla2xxx_eh_bus_reset
958 * The bus reset function will reset the bus and abort any executing
962 * cmd = Linux SCSI command packet of the command that cause the
966 * SUCCESS/FAILURE (defined as macro in scsi.h).
968 **************************************************************************/
970 qla2xxx_eh_bus_reset(struct scsi_cmnd
*cmd
)
972 scsi_qla_host_t
*vha
= shost_priv(cmd
->device
->host
);
973 fc_port_t
*fcport
= (struct fc_port
*) cmd
->device
->hostdata
;
975 unsigned int id
, lun
;
976 unsigned long serial
;
977 srb_t
*sp
= (srb_t
*) CMD_SP(cmd
);
979 qla2x00_block_error_handler(cmd
);
981 id
= cmd
->device
->id
;
982 lun
= cmd
->device
->lun
;
983 serial
= cmd
->serial_number
;
988 qla_printk(KERN_INFO
, vha
->hw
,
989 "scsi(%ld:%d:%d): BUS RESET ISSUED.\n", vha
->host_no
, id
, lun
);
991 if (qla2x00_wait_for_hba_online(vha
) != QLA_SUCCESS
) {
992 DEBUG2(printk("%s failed:board disabled\n",__func__
));
993 goto eh_bus_reset_done
;
996 if (qla2x00_wait_for_loop_ready(vha
) == QLA_SUCCESS
) {
997 if (qla2x00_loop_reset(vha
) == QLA_SUCCESS
)
1001 goto eh_bus_reset_done
;
1003 /* Flush outstanding commands. */
1004 if (qla2x00_eh_wait_for_pending_commands(vha
, 0, 0, sp
, WAIT_HOST
) !=
1009 qla_printk(KERN_INFO
, vha
->hw
, "%s: reset %s\n", __func__
,
1010 (ret
== FAILED
) ? "failed" : "succeded");
1015 /**************************************************************************
1016 * qla2xxx_eh_host_reset
1019 * The reset function will reset the Adapter.
1022 * cmd = Linux SCSI command packet of the command that cause the
1026 * Either SUCCESS or FAILED.
1029 **************************************************************************/
1031 qla2xxx_eh_host_reset(struct scsi_cmnd
*cmd
)
1033 scsi_qla_host_t
*vha
= shost_priv(cmd
->device
->host
);
1034 fc_port_t
*fcport
= (struct fc_port
*) cmd
->device
->hostdata
;
1035 struct qla_hw_data
*ha
= vha
->hw
;
1037 unsigned int id
, lun
;
1038 unsigned long serial
;
1039 srb_t
*sp
= (srb_t
*) CMD_SP(cmd
);
1040 scsi_qla_host_t
*base_vha
= pci_get_drvdata(ha
->pdev
);
1042 qla2x00_block_error_handler(cmd
);
1044 id
= cmd
->device
->id
;
1045 lun
= cmd
->device
->lun
;
1046 serial
= cmd
->serial_number
;
1051 qla_printk(KERN_INFO
, ha
,
1052 "scsi(%ld:%d:%d): ADAPTER RESET ISSUED.\n", vha
->host_no
, id
, lun
);
1054 if (qla2x00_wait_for_hba_online(vha
) != QLA_SUCCESS
)
1055 goto eh_host_reset_lock
;
1058 * Fixme-may be dpc thread is active and processing
1059 * loop_resync,so wait a while for it to
1060 * be completed and then issue big hammer.Otherwise
1061 * it may cause I/O failure as big hammer marks the
1062 * devices as lost kicking of the port_down_timer
1063 * while dpc is stuck for the mailbox to complete.
1065 qla2x00_wait_for_loop_ready(vha
);
1066 if (vha
!= base_vha
) {
1067 if (qla2x00_vp_abort_isp(vha
))
1068 goto eh_host_reset_lock
;
1070 set_bit(ABORT_ISP_ACTIVE
, &base_vha
->dpc_flags
);
1071 if (qla2x00_abort_isp(base_vha
)) {
1072 clear_bit(ABORT_ISP_ACTIVE
, &base_vha
->dpc_flags
);
1073 /* failed. schedule dpc to try */
1074 set_bit(ISP_ABORT_NEEDED
, &base_vha
->dpc_flags
);
1076 if (qla2x00_wait_for_hba_online(vha
) != QLA_SUCCESS
)
1077 goto eh_host_reset_lock
;
1079 clear_bit(ABORT_ISP_ACTIVE
, &base_vha
->dpc_flags
);
1082 /* Waiting for command to be returned to OS.*/
1083 if (qla2x00_eh_wait_for_pending_commands(vha
, 0, 0, sp
, WAIT_HOST
) ==
1088 qla_printk(KERN_INFO
, ha
, "%s: reset %s\n", __func__
,
1089 (ret
== FAILED
) ? "failed" : "succeded");
1095 * qla2x00_loop_reset
1099 * ha = adapter block pointer.
1105 qla2x00_loop_reset(scsi_qla_host_t
*vha
)
1108 struct fc_port
*fcport
;
1109 struct qla_hw_data
*ha
= vha
->hw
;
1111 if (ha
->flags
.enable_lip_full_login
&& !vha
->vp_idx
) {
1112 ret
= qla2x00_full_login_lip(vha
);
1113 if (ret
!= QLA_SUCCESS
) {
1114 DEBUG2_3(printk("%s(%ld): failed: "
1115 "full_login_lip=%d.\n", __func__
, vha
->host_no
,
1118 atomic_set(&vha
->loop_state
, LOOP_DOWN
);
1119 atomic_set(&vha
->loop_down_timer
, LOOP_DOWN_TIME
);
1120 qla2x00_mark_all_devices_lost(vha
, 0);
1121 qla2x00_wait_for_loop_ready(vha
);
1124 if (ha
->flags
.enable_lip_reset
&& !vha
->vp_idx
) {
1125 ret
= qla2x00_lip_reset(vha
);
1126 if (ret
!= QLA_SUCCESS
) {
1127 DEBUG2_3(printk("%s(%ld): failed: "
1128 "lip_reset=%d.\n", __func__
, vha
->host_no
, ret
));
1130 qla2x00_wait_for_loop_ready(vha
);
1133 if (ha
->flags
.enable_target_reset
) {
1134 list_for_each_entry(fcport
, &vha
->vp_fcports
, list
) {
1135 if (fcport
->port_type
!= FCT_TARGET
)
1138 ret
= ha
->isp_ops
->target_reset(fcport
, 0);
1139 if (ret
!= QLA_SUCCESS
) {
1140 DEBUG2_3(printk("%s(%ld): bus_reset failed: "
1141 "target_reset=%d d_id=%x.\n", __func__
,
1142 vha
->host_no
, ret
, fcport
->d_id
.b24
));
1146 /* Issue marker command only when we are going to start the I/O */
1147 vha
->marker_needed
= 1;
1153 qla2x00_abort_all_cmds(scsi_qla_host_t
*vha
, int res
)
1156 unsigned long flags
;
1158 struct qla_hw_data
*ha
= vha
->hw
;
1159 struct req_que
*req
;
1161 spin_lock_irqsave(&ha
->hardware_lock
, flags
);
1162 for (que
= 0; que
< ha
->max_queues
; que
++) {
1163 req
= ha
->req_q_map
[que
];
1166 for (cnt
= 1; cnt
< MAX_OUTSTANDING_COMMANDS
; cnt
++) {
1167 sp
= req
->outstanding_cmds
[cnt
];
1168 if (sp
&& sp
->fcport
->vha
== vha
) {
1169 req
->outstanding_cmds
[cnt
] = NULL
;
1170 sp
->cmd
->result
= res
;
1171 qla2x00_sp_compl(ha
, sp
);
1175 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
1179 qla2xxx_slave_alloc(struct scsi_device
*sdev
)
1181 struct fc_rport
*rport
= starget_to_rport(scsi_target(sdev
));
1183 if (!rport
|| fc_remote_port_chkready(rport
))
1186 sdev
->hostdata
= *(fc_port_t
**)rport
->dd_data
;
1192 qla2xxx_slave_configure(struct scsi_device
*sdev
)
1194 scsi_qla_host_t
*vha
= shost_priv(sdev
->host
);
1195 struct qla_hw_data
*ha
= vha
->hw
;
1196 struct fc_rport
*rport
= starget_to_rport(sdev
->sdev_target
);
1197 struct req_que
*req
= ha
->req_q_map
[vha
->req_ques
[0]];
1199 if (sdev
->tagged_supported
)
1200 scsi_activate_tcq(sdev
, req
->max_q_depth
);
1202 scsi_deactivate_tcq(sdev
, req
->max_q_depth
);
1204 rport
->dev_loss_tmo
= ha
->port_down_retry_count
;
1210 qla2xxx_slave_destroy(struct scsi_device
*sdev
)
1212 sdev
->hostdata
= NULL
;
1216 qla2x00_change_queue_depth(struct scsi_device
*sdev
, int qdepth
)
1218 scsi_adjust_queue_depth(sdev
, scsi_get_tag_type(sdev
), qdepth
);
1219 return sdev
->queue_depth
;
1223 qla2x00_change_queue_type(struct scsi_device
*sdev
, int tag_type
)
1225 if (sdev
->tagged_supported
) {
1226 scsi_set_tag_type(sdev
, tag_type
);
1228 scsi_activate_tcq(sdev
, sdev
->queue_depth
);
1230 scsi_deactivate_tcq(sdev
, sdev
->queue_depth
);
1238 * qla2x00_config_dma_addressing() - Configure OS DMA addressing method.
1241 * At exit, the @ha's flags.enable_64bit_addressing set to indicated
1242 * supported addressing method.
1245 qla2x00_config_dma_addressing(scsi_qla_host_t
*vha
)
1247 struct qla_hw_data
*ha
= vha
->hw
;
1248 /* Assume a 32bit DMA mask. */
1249 ha
->flags
.enable_64bit_addressing
= 0;
1251 if (!dma_set_mask(&ha
->pdev
->dev
, DMA_64BIT_MASK
)) {
1252 /* Any upper-dword bits set? */
1253 if (MSD(dma_get_required_mask(&ha
->pdev
->dev
)) &&
1254 !pci_set_consistent_dma_mask(ha
->pdev
, DMA_64BIT_MASK
)) {
1255 /* Ok, a 64bit DMA mask is applicable. */
1256 ha
->flags
.enable_64bit_addressing
= 1;
1257 ha
->isp_ops
->calc_req_entries
= qla2x00_calc_iocbs_64
;
1258 ha
->isp_ops
->build_iocbs
= qla2x00_build_scsi_iocbs_64
;
1263 dma_set_mask(&ha
->pdev
->dev
, DMA_32BIT_MASK
);
1264 pci_set_consistent_dma_mask(ha
->pdev
, DMA_32BIT_MASK
);
1268 qla2x00_enable_intrs(struct qla_hw_data
*ha
)
1270 unsigned long flags
= 0;
1271 struct device_reg_2xxx __iomem
*reg
= &ha
->iobase
->isp
;
1273 spin_lock_irqsave(&ha
->hardware_lock
, flags
);
1274 ha
->interrupts_on
= 1;
1275 /* enable risc and host interrupts */
1276 WRT_REG_WORD(®
->ictrl
, ICR_EN_INT
| ICR_EN_RISC
);
1277 RD_REG_WORD(®
->ictrl
);
1278 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
1283 qla2x00_disable_intrs(struct qla_hw_data
*ha
)
1285 unsigned long flags
= 0;
1286 struct device_reg_2xxx __iomem
*reg
= &ha
->iobase
->isp
;
1288 spin_lock_irqsave(&ha
->hardware_lock
, flags
);
1289 ha
->interrupts_on
= 0;
1290 /* disable risc and host interrupts */
1291 WRT_REG_WORD(®
->ictrl
, 0);
1292 RD_REG_WORD(®
->ictrl
);
1293 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
1297 qla24xx_enable_intrs(struct qla_hw_data
*ha
)
1299 unsigned long flags
= 0;
1300 struct device_reg_24xx __iomem
*reg
= &ha
->iobase
->isp24
;
1302 spin_lock_irqsave(&ha
->hardware_lock
, flags
);
1303 ha
->interrupts_on
= 1;
1304 WRT_REG_DWORD(®
->ictrl
, ICRX_EN_RISC_INT
);
1305 RD_REG_DWORD(®
->ictrl
);
1306 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
1310 qla24xx_disable_intrs(struct qla_hw_data
*ha
)
1312 unsigned long flags
= 0;
1313 struct device_reg_24xx __iomem
*reg
= &ha
->iobase
->isp24
;
1315 if (IS_NOPOLLING_TYPE(ha
))
1317 spin_lock_irqsave(&ha
->hardware_lock
, flags
);
1318 ha
->interrupts_on
= 0;
1319 WRT_REG_DWORD(®
->ictrl
, 0);
1320 RD_REG_DWORD(®
->ictrl
);
1321 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
1324 static struct isp_operations qla2100_isp_ops
= {
1325 .pci_config
= qla2100_pci_config
,
1326 .reset_chip
= qla2x00_reset_chip
,
1327 .chip_diag
= qla2x00_chip_diag
,
1328 .config_rings
= qla2x00_config_rings
,
1329 .reset_adapter
= qla2x00_reset_adapter
,
1330 .nvram_config
= qla2x00_nvram_config
,
1331 .update_fw_options
= qla2x00_update_fw_options
,
1332 .load_risc
= qla2x00_load_risc
,
1333 .pci_info_str
= qla2x00_pci_info_str
,
1334 .fw_version_str
= qla2x00_fw_version_str
,
1335 .intr_handler
= qla2100_intr_handler
,
1336 .enable_intrs
= qla2x00_enable_intrs
,
1337 .disable_intrs
= qla2x00_disable_intrs
,
1338 .abort_command
= qla2x00_abort_command
,
1339 .target_reset
= qla2x00_abort_target
,
1340 .lun_reset
= qla2x00_lun_reset
,
1341 .fabric_login
= qla2x00_login_fabric
,
1342 .fabric_logout
= qla2x00_fabric_logout
,
1343 .calc_req_entries
= qla2x00_calc_iocbs_32
,
1344 .build_iocbs
= qla2x00_build_scsi_iocbs_32
,
1345 .prep_ms_iocb
= qla2x00_prep_ms_iocb
,
1346 .prep_ms_fdmi_iocb
= qla2x00_prep_ms_fdmi_iocb
,
1347 .read_nvram
= qla2x00_read_nvram_data
,
1348 .write_nvram
= qla2x00_write_nvram_data
,
1349 .fw_dump
= qla2100_fw_dump
,
1352 .beacon_blink
= NULL
,
1353 .read_optrom
= qla2x00_read_optrom_data
,
1354 .write_optrom
= qla2x00_write_optrom_data
,
1355 .get_flash_version
= qla2x00_get_flash_version
,
1356 .start_scsi
= qla2x00_start_scsi
,
1357 .wrt_req_reg
= NULL
,
1358 .wrt_rsp_reg
= NULL
,
1362 static struct isp_operations qla2300_isp_ops
= {
1363 .pci_config
= qla2300_pci_config
,
1364 .reset_chip
= qla2x00_reset_chip
,
1365 .chip_diag
= qla2x00_chip_diag
,
1366 .config_rings
= qla2x00_config_rings
,
1367 .reset_adapter
= qla2x00_reset_adapter
,
1368 .nvram_config
= qla2x00_nvram_config
,
1369 .update_fw_options
= qla2x00_update_fw_options
,
1370 .load_risc
= qla2x00_load_risc
,
1371 .pci_info_str
= qla2x00_pci_info_str
,
1372 .fw_version_str
= qla2x00_fw_version_str
,
1373 .intr_handler
= qla2300_intr_handler
,
1374 .enable_intrs
= qla2x00_enable_intrs
,
1375 .disable_intrs
= qla2x00_disable_intrs
,
1376 .abort_command
= qla2x00_abort_command
,
1377 .target_reset
= qla2x00_abort_target
,
1378 .lun_reset
= qla2x00_lun_reset
,
1379 .fabric_login
= qla2x00_login_fabric
,
1380 .fabric_logout
= qla2x00_fabric_logout
,
1381 .calc_req_entries
= qla2x00_calc_iocbs_32
,
1382 .build_iocbs
= qla2x00_build_scsi_iocbs_32
,
1383 .prep_ms_iocb
= qla2x00_prep_ms_iocb
,
1384 .prep_ms_fdmi_iocb
= qla2x00_prep_ms_fdmi_iocb
,
1385 .read_nvram
= qla2x00_read_nvram_data
,
1386 .write_nvram
= qla2x00_write_nvram_data
,
1387 .fw_dump
= qla2300_fw_dump
,
1388 .beacon_on
= qla2x00_beacon_on
,
1389 .beacon_off
= qla2x00_beacon_off
,
1390 .beacon_blink
= qla2x00_beacon_blink
,
1391 .read_optrom
= qla2x00_read_optrom_data
,
1392 .write_optrom
= qla2x00_write_optrom_data
,
1393 .get_flash_version
= qla2x00_get_flash_version
,
1394 .start_scsi
= qla2x00_start_scsi
,
1395 .wrt_req_reg
= NULL
,
1396 .wrt_rsp_reg
= NULL
,
1400 static struct isp_operations qla24xx_isp_ops
= {
1401 .pci_config
= qla24xx_pci_config
,
1402 .reset_chip
= qla24xx_reset_chip
,
1403 .chip_diag
= qla24xx_chip_diag
,
1404 .config_rings
= qla24xx_config_rings
,
1405 .reset_adapter
= qla24xx_reset_adapter
,
1406 .nvram_config
= qla24xx_nvram_config
,
1407 .update_fw_options
= qla24xx_update_fw_options
,
1408 .load_risc
= qla24xx_load_risc
,
1409 .pci_info_str
= qla24xx_pci_info_str
,
1410 .fw_version_str
= qla24xx_fw_version_str
,
1411 .intr_handler
= qla24xx_intr_handler
,
1412 .enable_intrs
= qla24xx_enable_intrs
,
1413 .disable_intrs
= qla24xx_disable_intrs
,
1414 .abort_command
= qla24xx_abort_command
,
1415 .target_reset
= qla24xx_abort_target
,
1416 .lun_reset
= qla24xx_lun_reset
,
1417 .fabric_login
= qla24xx_login_fabric
,
1418 .fabric_logout
= qla24xx_fabric_logout
,
1419 .calc_req_entries
= NULL
,
1420 .build_iocbs
= NULL
,
1421 .prep_ms_iocb
= qla24xx_prep_ms_iocb
,
1422 .prep_ms_fdmi_iocb
= qla24xx_prep_ms_fdmi_iocb
,
1423 .read_nvram
= qla24xx_read_nvram_data
,
1424 .write_nvram
= qla24xx_write_nvram_data
,
1425 .fw_dump
= qla24xx_fw_dump
,
1426 .beacon_on
= qla24xx_beacon_on
,
1427 .beacon_off
= qla24xx_beacon_off
,
1428 .beacon_blink
= qla24xx_beacon_blink
,
1429 .read_optrom
= qla24xx_read_optrom_data
,
1430 .write_optrom
= qla24xx_write_optrom_data
,
1431 .get_flash_version
= qla24xx_get_flash_version
,
1432 .start_scsi
= qla24xx_start_scsi
,
1433 .wrt_req_reg
= qla24xx_wrt_req_reg
,
1434 .wrt_rsp_reg
= qla24xx_wrt_rsp_reg
,
1435 .rd_req_reg
= qla24xx_rd_req_reg
,
1438 static struct isp_operations qla25xx_isp_ops
= {
1439 .pci_config
= qla25xx_pci_config
,
1440 .reset_chip
= qla24xx_reset_chip
,
1441 .chip_diag
= qla24xx_chip_diag
,
1442 .config_rings
= qla24xx_config_rings
,
1443 .reset_adapter
= qla24xx_reset_adapter
,
1444 .nvram_config
= qla24xx_nvram_config
,
1445 .update_fw_options
= qla24xx_update_fw_options
,
1446 .load_risc
= qla24xx_load_risc
,
1447 .pci_info_str
= qla24xx_pci_info_str
,
1448 .fw_version_str
= qla24xx_fw_version_str
,
1449 .intr_handler
= qla24xx_intr_handler
,
1450 .enable_intrs
= qla24xx_enable_intrs
,
1451 .disable_intrs
= qla24xx_disable_intrs
,
1452 .abort_command
= qla24xx_abort_command
,
1453 .target_reset
= qla24xx_abort_target
,
1454 .lun_reset
= qla24xx_lun_reset
,
1455 .fabric_login
= qla24xx_login_fabric
,
1456 .fabric_logout
= qla24xx_fabric_logout
,
1457 .calc_req_entries
= NULL
,
1458 .build_iocbs
= NULL
,
1459 .prep_ms_iocb
= qla24xx_prep_ms_iocb
,
1460 .prep_ms_fdmi_iocb
= qla24xx_prep_ms_fdmi_iocb
,
1461 .read_nvram
= qla25xx_read_nvram_data
,
1462 .write_nvram
= qla25xx_write_nvram_data
,
1463 .fw_dump
= qla25xx_fw_dump
,
1464 .beacon_on
= qla24xx_beacon_on
,
1465 .beacon_off
= qla24xx_beacon_off
,
1466 .beacon_blink
= qla24xx_beacon_blink
,
1467 .read_optrom
= qla25xx_read_optrom_data
,
1468 .write_optrom
= qla24xx_write_optrom_data
,
1469 .get_flash_version
= qla24xx_get_flash_version
,
1470 .start_scsi
= qla24xx_start_scsi
,
1471 .wrt_req_reg
= qla24xx_wrt_req_reg
,
1472 .wrt_rsp_reg
= qla24xx_wrt_rsp_reg
,
1473 .rd_req_reg
= qla24xx_rd_req_reg
,
1476 static struct isp_operations qla81xx_isp_ops
= {
1477 .pci_config
= qla25xx_pci_config
,
1478 .reset_chip
= qla24xx_reset_chip
,
1479 .chip_diag
= qla24xx_chip_diag
,
1480 .config_rings
= qla24xx_config_rings
,
1481 .reset_adapter
= qla24xx_reset_adapter
,
1482 .nvram_config
= qla81xx_nvram_config
,
1483 .update_fw_options
= qla81xx_update_fw_options
,
1484 .load_risc
= qla81xx_load_risc
,
1485 .pci_info_str
= qla24xx_pci_info_str
,
1486 .fw_version_str
= qla24xx_fw_version_str
,
1487 .intr_handler
= qla24xx_intr_handler
,
1488 .enable_intrs
= qla24xx_enable_intrs
,
1489 .disable_intrs
= qla24xx_disable_intrs
,
1490 .abort_command
= qla24xx_abort_command
,
1491 .target_reset
= qla24xx_abort_target
,
1492 .lun_reset
= qla24xx_lun_reset
,
1493 .fabric_login
= qla24xx_login_fabric
,
1494 .fabric_logout
= qla24xx_fabric_logout
,
1495 .calc_req_entries
= NULL
,
1496 .build_iocbs
= NULL
,
1497 .prep_ms_iocb
= qla24xx_prep_ms_iocb
,
1498 .prep_ms_fdmi_iocb
= qla24xx_prep_ms_fdmi_iocb
,
1499 .read_nvram
= qla25xx_read_nvram_data
,
1500 .write_nvram
= qla25xx_write_nvram_data
,
1501 .fw_dump
= qla81xx_fw_dump
,
1502 .beacon_on
= qla24xx_beacon_on
,
1503 .beacon_off
= qla24xx_beacon_off
,
1504 .beacon_blink
= qla24xx_beacon_blink
,
1505 .read_optrom
= qla25xx_read_optrom_data
,
1506 .write_optrom
= qla24xx_write_optrom_data
,
1507 .get_flash_version
= qla24xx_get_flash_version
,
1508 .start_scsi
= qla24xx_start_scsi
,
1509 .wrt_req_reg
= qla24xx_wrt_req_reg
,
1510 .wrt_rsp_reg
= qla24xx_wrt_rsp_reg
,
1511 .rd_req_reg
= qla24xx_rd_req_reg
,
1515 qla2x00_set_isp_flags(struct qla_hw_data
*ha
)
1517 ha
->device_type
= DT_EXTENDED_IDS
;
1518 switch (ha
->pdev
->device
) {
1519 case PCI_DEVICE_ID_QLOGIC_ISP2100
:
1520 ha
->device_type
|= DT_ISP2100
;
1521 ha
->device_type
&= ~DT_EXTENDED_IDS
;
1522 ha
->fw_srisc_address
= RISC_START_ADDRESS_2100
;
1524 case PCI_DEVICE_ID_QLOGIC_ISP2200
:
1525 ha
->device_type
|= DT_ISP2200
;
1526 ha
->device_type
&= ~DT_EXTENDED_IDS
;
1527 ha
->fw_srisc_address
= RISC_START_ADDRESS_2100
;
1529 case PCI_DEVICE_ID_QLOGIC_ISP2300
:
1530 ha
->device_type
|= DT_ISP2300
;
1531 ha
->device_type
|= DT_ZIO_SUPPORTED
;
1532 ha
->fw_srisc_address
= RISC_START_ADDRESS_2300
;
1534 case PCI_DEVICE_ID_QLOGIC_ISP2312
:
1535 ha
->device_type
|= DT_ISP2312
;
1536 ha
->device_type
|= DT_ZIO_SUPPORTED
;
1537 ha
->fw_srisc_address
= RISC_START_ADDRESS_2300
;
1539 case PCI_DEVICE_ID_QLOGIC_ISP2322
:
1540 ha
->device_type
|= DT_ISP2322
;
1541 ha
->device_type
|= DT_ZIO_SUPPORTED
;
1542 if (ha
->pdev
->subsystem_vendor
== 0x1028 &&
1543 ha
->pdev
->subsystem_device
== 0x0170)
1544 ha
->device_type
|= DT_OEM_001
;
1545 ha
->fw_srisc_address
= RISC_START_ADDRESS_2300
;
1547 case PCI_DEVICE_ID_QLOGIC_ISP6312
:
1548 ha
->device_type
|= DT_ISP6312
;
1549 ha
->fw_srisc_address
= RISC_START_ADDRESS_2300
;
1551 case PCI_DEVICE_ID_QLOGIC_ISP6322
:
1552 ha
->device_type
|= DT_ISP6322
;
1553 ha
->fw_srisc_address
= RISC_START_ADDRESS_2300
;
1555 case PCI_DEVICE_ID_QLOGIC_ISP2422
:
1556 ha
->device_type
|= DT_ISP2422
;
1557 ha
->device_type
|= DT_ZIO_SUPPORTED
;
1558 ha
->device_type
|= DT_FWI2
;
1559 ha
->device_type
|= DT_IIDMA
;
1560 ha
->fw_srisc_address
= RISC_START_ADDRESS_2400
;
1562 case PCI_DEVICE_ID_QLOGIC_ISP2432
:
1563 ha
->device_type
|= DT_ISP2432
;
1564 ha
->device_type
|= DT_ZIO_SUPPORTED
;
1565 ha
->device_type
|= DT_FWI2
;
1566 ha
->device_type
|= DT_IIDMA
;
1567 ha
->fw_srisc_address
= RISC_START_ADDRESS_2400
;
1569 case PCI_DEVICE_ID_QLOGIC_ISP8432
:
1570 ha
->device_type
|= DT_ISP8432
;
1571 ha
->device_type
|= DT_ZIO_SUPPORTED
;
1572 ha
->device_type
|= DT_FWI2
;
1573 ha
->device_type
|= DT_IIDMA
;
1574 ha
->fw_srisc_address
= RISC_START_ADDRESS_2400
;
1576 case PCI_DEVICE_ID_QLOGIC_ISP5422
:
1577 ha
->device_type
|= DT_ISP5422
;
1578 ha
->device_type
|= DT_FWI2
;
1579 ha
->fw_srisc_address
= RISC_START_ADDRESS_2400
;
1581 case PCI_DEVICE_ID_QLOGIC_ISP5432
:
1582 ha
->device_type
|= DT_ISP5432
;
1583 ha
->device_type
|= DT_FWI2
;
1584 ha
->fw_srisc_address
= RISC_START_ADDRESS_2400
;
1586 case PCI_DEVICE_ID_QLOGIC_ISP2532
:
1587 ha
->device_type
|= DT_ISP2532
;
1588 ha
->device_type
|= DT_ZIO_SUPPORTED
;
1589 ha
->device_type
|= DT_FWI2
;
1590 ha
->device_type
|= DT_IIDMA
;
1591 ha
->fw_srisc_address
= RISC_START_ADDRESS_2400
;
1593 case PCI_DEVICE_ID_QLOGIC_ISP8001
:
1594 ha
->device_type
|= DT_ISP8001
;
1595 ha
->device_type
|= DT_ZIO_SUPPORTED
;
1596 ha
->device_type
|= DT_FWI2
;
1597 ha
->device_type
|= DT_IIDMA
;
1598 ha
->fw_srisc_address
= RISC_START_ADDRESS_2400
;
1604 qla2x00_iospace_config(struct qla_hw_data
*ha
)
1606 resource_size_t pio
;
1609 if (pci_request_selected_regions(ha
->pdev
, ha
->bars
,
1610 QLA2XXX_DRIVER_NAME
)) {
1611 qla_printk(KERN_WARNING
, ha
,
1612 "Failed to reserve PIO/MMIO regions (%s)\n",
1613 pci_name(ha
->pdev
));
1615 goto iospace_error_exit
;
1617 if (!(ha
->bars
& 1))
1620 /* We only need PIO for Flash operations on ISP2312 v2 chips. */
1621 pio
= pci_resource_start(ha
->pdev
, 0);
1622 if (pci_resource_flags(ha
->pdev
, 0) & IORESOURCE_IO
) {
1623 if (pci_resource_len(ha
->pdev
, 0) < MIN_IOBASE_LEN
) {
1624 qla_printk(KERN_WARNING
, ha
,
1625 "Invalid PCI I/O region size (%s)...\n",
1626 pci_name(ha
->pdev
));
1630 qla_printk(KERN_WARNING
, ha
,
1631 "region #0 not a PIO resource (%s)...\n",
1632 pci_name(ha
->pdev
));
1635 ha
->pio_address
= pio
;
1638 /* Use MMIO operations for all accesses. */
1639 if (!(pci_resource_flags(ha
->pdev
, 1) & IORESOURCE_MEM
)) {
1640 qla_printk(KERN_ERR
, ha
,
1641 "region #1 not an MMIO resource (%s), aborting\n",
1642 pci_name(ha
->pdev
));
1643 goto iospace_error_exit
;
1645 if (pci_resource_len(ha
->pdev
, 1) < MIN_IOBASE_LEN
) {
1646 qla_printk(KERN_ERR
, ha
,
1647 "Invalid PCI mem region size (%s), aborting\n",
1648 pci_name(ha
->pdev
));
1649 goto iospace_error_exit
;
1652 ha
->iobase
= ioremap(pci_resource_start(ha
->pdev
, 1), MIN_IOBASE_LEN
);
1654 qla_printk(KERN_ERR
, ha
,
1655 "cannot remap MMIO (%s), aborting\n", pci_name(ha
->pdev
));
1657 goto iospace_error_exit
;
1660 /* Determine queue resources */
1662 if (ql2xmaxqueues
<= 1 || (!IS_QLA25XX(ha
) && !IS_QLA81XX(ha
)))
1664 ha
->mqiobase
= ioremap(pci_resource_start(ha
->pdev
, 3),
1665 pci_resource_len(ha
->pdev
, 3));
1667 /* Read MSIX vector size of the board */
1668 pci_read_config_word(ha
->pdev
, QLA_PCI_MSIX_CONTROL
, &msix
);
1669 ha
->msix_count
= msix
;
1670 /* Max queues are bounded by available msix vectors */
1671 /* queue 0 uses two msix vectors */
1672 if (ha
->msix_count
- 1 < ql2xmaxqueues
)
1673 ha
->max_queues
= ha
->msix_count
- 1;
1674 else if (ql2xmaxqueues
> QLA_MQ_SIZE
)
1675 ha
->max_queues
= QLA_MQ_SIZE
;
1677 ha
->max_queues
= ql2xmaxqueues
;
1678 qla_printk(KERN_INFO
, ha
,
1679 "MSI-X vector count: %d\n", msix
);
1683 ha
->msix_count
= ha
->max_queues
+ 1;
1691 qla2xxx_scan_start(struct Scsi_Host
*shost
)
1693 scsi_qla_host_t
*vha
= shost_priv(shost
);
1695 set_bit(LOOP_RESYNC_NEEDED
, &vha
->dpc_flags
);
1696 set_bit(LOCAL_LOOP_UPDATE
, &vha
->dpc_flags
);
1697 set_bit(RSCN_UPDATE
, &vha
->dpc_flags
);
1698 set_bit(NPIV_CONFIG_NEEDED
, &vha
->dpc_flags
);
1702 qla2xxx_scan_finished(struct Scsi_Host
*shost
, unsigned long time
)
1704 scsi_qla_host_t
*vha
= shost_priv(shost
);
1708 if (time
> vha
->hw
->loop_reset_delay
* HZ
)
1711 return atomic_read(&vha
->loop_state
) == LOOP_READY
;
1715 * PCI driver interface
1717 static int __devinit
1718 qla2x00_probe_one(struct pci_dev
*pdev
, const struct pci_device_id
*id
)
1721 struct Scsi_Host
*host
;
1722 scsi_qla_host_t
*base_vha
= NULL
;
1723 struct qla_hw_data
*ha
;
1726 struct scsi_host_template
*sht
;
1727 int bars
, max_id
, mem_only
= 0;
1728 uint16_t req_length
= 0, rsp_length
= 0;
1729 struct req_que
*req
= NULL
;
1730 struct rsp_que
*rsp
= NULL
;
1732 bars
= pci_select_bars(pdev
, IORESOURCE_MEM
| IORESOURCE_IO
);
1733 sht
= &qla2x00_driver_template
;
1734 if (pdev
->device
== PCI_DEVICE_ID_QLOGIC_ISP2422
||
1735 pdev
->device
== PCI_DEVICE_ID_QLOGIC_ISP2432
||
1736 pdev
->device
== PCI_DEVICE_ID_QLOGIC_ISP8432
||
1737 pdev
->device
== PCI_DEVICE_ID_QLOGIC_ISP5422
||
1738 pdev
->device
== PCI_DEVICE_ID_QLOGIC_ISP5432
||
1739 pdev
->device
== PCI_DEVICE_ID_QLOGIC_ISP2532
||
1740 pdev
->device
== PCI_DEVICE_ID_QLOGIC_ISP8001
) {
1741 bars
= pci_select_bars(pdev
, IORESOURCE_MEM
);
1742 sht
= &qla24xx_driver_template
;
1747 if (pci_enable_device_mem(pdev
))
1750 if (pci_enable_device(pdev
))
1754 /* This may fail but that's ok */
1755 pci_enable_pcie_error_reporting(pdev
);
1757 ha
= kzalloc(sizeof(struct qla_hw_data
), GFP_KERNEL
);
1759 DEBUG(printk("Unable to allocate memory for ha\n"));
1764 /* Clear our data area */
1766 ha
->mem_only
= mem_only
;
1767 spin_lock_init(&ha
->hardware_lock
);
1769 /* Set ISP-type information. */
1770 qla2x00_set_isp_flags(ha
);
1771 /* Configure PCI I/O space */
1772 ret
= qla2x00_iospace_config(ha
);
1774 goto probe_hw_failed
;
1776 qla_printk(KERN_INFO
, ha
,
1777 "Found an ISP%04X, irq %d, iobase 0x%p\n", pdev
->device
, pdev
->irq
,
1780 ha
->prev_topology
= 0;
1781 ha
->init_cb_size
= sizeof(init_cb_t
);
1782 ha
->link_data_rate
= PORT_SPEED_UNKNOWN
;
1783 ha
->optrom_size
= OPTROM_SIZE_2300
;
1785 /* Assign ISP specific operations. */
1786 max_id
= MAX_TARGETS_2200
;
1787 if (IS_QLA2100(ha
)) {
1788 max_id
= MAX_TARGETS_2100
;
1789 ha
->mbx_count
= MAILBOX_REGISTER_COUNT_2100
;
1790 req_length
= REQUEST_ENTRY_CNT_2100
;
1791 rsp_length
= RESPONSE_ENTRY_CNT_2100
;
1792 ha
->max_loop_id
= SNS_LAST_LOOP_ID_2100
;
1793 ha
->gid_list_info_size
= 4;
1794 ha
->flash_conf_off
= ~0;
1795 ha
->flash_data_off
= ~0;
1796 ha
->nvram_conf_off
= ~0;
1797 ha
->nvram_data_off
= ~0;
1798 ha
->isp_ops
= &qla2100_isp_ops
;
1799 } else if (IS_QLA2200(ha
)) {
1800 ha
->mbx_count
= MAILBOX_REGISTER_COUNT
;
1801 req_length
= REQUEST_ENTRY_CNT_2200
;
1802 rsp_length
= RESPONSE_ENTRY_CNT_2100
;
1803 ha
->max_loop_id
= SNS_LAST_LOOP_ID_2100
;
1804 ha
->gid_list_info_size
= 4;
1805 ha
->flash_conf_off
= ~0;
1806 ha
->flash_data_off
= ~0;
1807 ha
->nvram_conf_off
= ~0;
1808 ha
->nvram_data_off
= ~0;
1809 ha
->isp_ops
= &qla2100_isp_ops
;
1810 } else if (IS_QLA23XX(ha
)) {
1811 ha
->mbx_count
= MAILBOX_REGISTER_COUNT
;
1812 req_length
= REQUEST_ENTRY_CNT_2200
;
1813 rsp_length
= RESPONSE_ENTRY_CNT_2300
;
1814 ha
->max_loop_id
= SNS_LAST_LOOP_ID_2300
;
1815 ha
->gid_list_info_size
= 6;
1816 if (IS_QLA2322(ha
) || IS_QLA6322(ha
))
1817 ha
->optrom_size
= OPTROM_SIZE_2322
;
1818 ha
->flash_conf_off
= ~0;
1819 ha
->flash_data_off
= ~0;
1820 ha
->nvram_conf_off
= ~0;
1821 ha
->nvram_data_off
= ~0;
1822 ha
->isp_ops
= &qla2300_isp_ops
;
1823 } else if (IS_QLA24XX_TYPE(ha
)) {
1824 ha
->mbx_count
= MAILBOX_REGISTER_COUNT
;
1825 req_length
= REQUEST_ENTRY_CNT_24XX
;
1826 rsp_length
= RESPONSE_ENTRY_CNT_2300
;
1827 ha
->max_loop_id
= SNS_LAST_LOOP_ID_2300
;
1828 ha
->init_cb_size
= sizeof(struct mid_init_cb_24xx
);
1829 ha
->gid_list_info_size
= 8;
1830 ha
->optrom_size
= OPTROM_SIZE_24XX
;
1831 ha
->nvram_npiv_size
= QLA_MAX_VPORTS_QLA24XX
;
1832 ha
->isp_ops
= &qla24xx_isp_ops
;
1833 ha
->flash_conf_off
= FARX_ACCESS_FLASH_CONF
;
1834 ha
->flash_data_off
= FARX_ACCESS_FLASH_DATA
;
1835 ha
->nvram_conf_off
= FARX_ACCESS_NVRAM_CONF
;
1836 ha
->nvram_data_off
= FARX_ACCESS_NVRAM_DATA
;
1837 } else if (IS_QLA25XX(ha
)) {
1838 ha
->mbx_count
= MAILBOX_REGISTER_COUNT
;
1839 req_length
= REQUEST_ENTRY_CNT_24XX
;
1840 rsp_length
= RESPONSE_ENTRY_CNT_2300
;
1841 ha
->max_loop_id
= SNS_LAST_LOOP_ID_2300
;
1842 ha
->init_cb_size
= sizeof(struct mid_init_cb_24xx
);
1843 ha
->gid_list_info_size
= 8;
1844 ha
->optrom_size
= OPTROM_SIZE_25XX
;
1845 ha
->nvram_npiv_size
= QLA_MAX_VPORTS_QLA25XX
;
1846 ha
->isp_ops
= &qla25xx_isp_ops
;
1847 ha
->flash_conf_off
= FARX_ACCESS_FLASH_CONF
;
1848 ha
->flash_data_off
= FARX_ACCESS_FLASH_DATA
;
1849 ha
->nvram_conf_off
= FARX_ACCESS_NVRAM_CONF
;
1850 ha
->nvram_data_off
= FARX_ACCESS_NVRAM_DATA
;
1851 } else if (IS_QLA81XX(ha
)) {
1852 ha
->mbx_count
= MAILBOX_REGISTER_COUNT
;
1853 req_length
= REQUEST_ENTRY_CNT_24XX
;
1854 rsp_length
= RESPONSE_ENTRY_CNT_2300
;
1855 ha
->max_loop_id
= SNS_LAST_LOOP_ID_2300
;
1856 ha
->init_cb_size
= sizeof(struct mid_init_cb_81xx
);
1857 ha
->gid_list_info_size
= 8;
1858 ha
->optrom_size
= OPTROM_SIZE_81XX
;
1859 ha
->isp_ops
= &qla81xx_isp_ops
;
1860 ha
->flash_conf_off
= FARX_ACCESS_FLASH_CONF_81XX
;
1861 ha
->flash_data_off
= FARX_ACCESS_FLASH_DATA_81XX
;
1862 ha
->nvram_conf_off
= ~0;
1863 ha
->nvram_data_off
= ~0;
1866 mutex_init(&ha
->vport_lock
);
1867 init_completion(&ha
->mbx_cmd_comp
);
1868 complete(&ha
->mbx_cmd_comp
);
1869 init_completion(&ha
->mbx_intr_comp
);
1871 set_bit(0, (unsigned long *) ha
->vp_idx_map
);
1873 ret
= qla2x00_mem_alloc(ha
, req_length
, rsp_length
, &req
, &rsp
);
1875 qla_printk(KERN_WARNING
, ha
,
1876 "[ERROR] Failed to allocate memory for adapter\n");
1878 goto probe_hw_failed
;
1881 req
->max_q_depth
= MAX_Q_DEPTH
;
1882 if (ql2xmaxqdepth
!= 0 && ql2xmaxqdepth
<= 0xffffU
)
1883 req
->max_q_depth
= ql2xmaxqdepth
;
1886 base_vha
= qla2x00_create_host(sht
, ha
);
1888 qla_printk(KERN_WARNING
, ha
,
1889 "[ERROR] Failed to allocate memory for scsi_host\n");
1892 qla2x00_mem_free(ha
);
1893 qla2x00_free_que(ha
, req
, rsp
);
1894 goto probe_hw_failed
;
1897 pci_set_drvdata(pdev
, base_vha
);
1899 qla2x00_config_dma_addressing(base_vha
);
1901 host
= base_vha
->host
;
1902 base_vha
->req_ques
[0] = req
->id
;
1903 host
->can_queue
= req
->length
+ 128;
1904 if (IS_QLA2XXX_MIDTYPE(ha
))
1905 base_vha
->mgmt_svr_loop_id
= 10 + base_vha
->vp_idx
;
1907 base_vha
->mgmt_svr_loop_id
= MANAGEMENT_SERVER
+
1910 host
->sg_tablesize
= 32;
1911 host
->max_id
= max_id
;
1912 host
->this_id
= 255;
1913 host
->cmd_per_lun
= 3;
1914 host
->unique_id
= host
->host_no
;
1915 host
->max_cmd_len
= MAX_CMDSZ
;
1916 host
->max_channel
= MAX_BUSES
- 1;
1917 host
->max_lun
= MAX_LUNS
;
1918 host
->transportt
= qla2xxx_transport_template
;
1920 /* Set up the irqs */
1921 ret
= qla2x00_request_irqs(ha
, rsp
);
1923 goto probe_init_failed
;
1924 /* Alloc arrays of request and response ring ptrs */
1925 if (!qla2x00_alloc_queues(ha
)) {
1926 qla_printk(KERN_WARNING
, ha
,
1927 "[ERROR] Failed to allocate memory for queue"
1929 goto probe_init_failed
;
1931 ha
->rsp_q_map
[0] = rsp
;
1932 ha
->req_q_map
[0] = req
;
1935 ha
->isp_ops
->wrt_req_reg
= qla25xx_wrt_req_reg
;
1936 ha
->isp_ops
->wrt_rsp_reg
= qla25xx_wrt_rsp_reg
;
1937 ha
->isp_ops
->rd_req_reg
= qla25xx_rd_req_reg
;
1940 if (qla2x00_initialize_adapter(base_vha
)) {
1941 qla_printk(KERN_WARNING
, ha
,
1942 "Failed to initialize adapter\n");
1944 DEBUG2(printk("scsi(%ld): Failed to initialize adapter - "
1945 "Adapter flags %x.\n",
1946 base_vha
->host_no
, base_vha
->device_flags
));
1953 * Startup the kernel thread for this host adapter
1955 ha
->dpc_thread
= kthread_create(qla2x00_do_dpc
, ha
,
1956 "%s_dpc", base_vha
->host_str
);
1957 if (IS_ERR(ha
->dpc_thread
)) {
1958 qla_printk(KERN_WARNING
, ha
,
1959 "Unable to start DPC thread!\n");
1960 ret
= PTR_ERR(ha
->dpc_thread
);
1964 list_add_tail(&base_vha
->list
, &ha
->vp_list
);
1965 base_vha
->host
->irq
= ha
->pdev
->irq
;
1967 /* Initialized the timer */
1968 qla2x00_start_timer(base_vha
, qla2x00_timer
, WATCH_INTERVAL
);
1970 DEBUG2(printk("DEBUG: detect hba %ld at address = %p\n",
1971 base_vha
->host_no
, ha
));
1973 base_vha
->flags
.init_done
= 1;
1974 base_vha
->flags
.online
= 1;
1976 ret
= scsi_add_host(host
, &pdev
->dev
);
1980 ha
->isp_ops
->enable_intrs(ha
);
1982 scsi_scan_host(host
);
1984 qla2x00_alloc_sysfs_attr(base_vha
);
1986 qla2x00_init_host_attr(base_vha
);
1988 qla2x00_dfs_setup(base_vha
);
1990 qla_printk(KERN_INFO
, ha
, "\n"
1991 " QLogic Fibre Channel HBA Driver: %s\n"
1993 " ISP%04X: %s @ %s hdma%c, host#=%ld, fw=%s\n",
1994 qla2x00_version_str
, ha
->model_number
,
1995 ha
->model_desc
? ha
->model_desc
: "", pdev
->device
,
1996 ha
->isp_ops
->pci_info_str(base_vha
, pci_info
), pci_name(pdev
),
1997 ha
->flags
.enable_64bit_addressing
? '+' : '-', base_vha
->host_no
,
1998 ha
->isp_ops
->fw_version_str(base_vha
, fw_str
));
2003 qla2x00_free_que(ha
, req
, rsp
);
2007 qla2x00_free_device(base_vha
);
2009 scsi_host_put(base_vha
->host
);
2013 iounmap(ha
->iobase
);
2015 pci_release_selected_regions(ha
->pdev
, ha
->bars
);
2020 pci_disable_device(pdev
);
2025 qla2x00_remove_one(struct pci_dev
*pdev
)
2027 scsi_qla_host_t
*base_vha
, *vha
, *temp
;
2028 struct qla_hw_data
*ha
;
2030 base_vha
= pci_get_drvdata(pdev
);
2033 list_for_each_entry_safe(vha
, temp
, &ha
->vp_list
, list
) {
2034 if (vha
&& vha
->fc_vport
)
2035 fc_vport_terminate(vha
->fc_vport
);
2038 set_bit(UNLOADING
, &base_vha
->dpc_flags
);
2040 qla2x00_dfs_remove(base_vha
);
2042 qla84xx_put_chip(base_vha
);
2044 qla2x00_free_sysfs_attr(base_vha
);
2046 fc_remove_host(base_vha
->host
);
2048 scsi_remove_host(base_vha
->host
);
2050 qla2x00_free_device(base_vha
);
2052 scsi_host_put(base_vha
->host
);
2055 iounmap(ha
->iobase
);
2058 iounmap(ha
->mqiobase
);
2060 pci_release_selected_regions(ha
->pdev
, ha
->bars
);
2064 pci_disable_device(pdev
);
2065 pci_set_drvdata(pdev
, NULL
);
2069 qla2x00_free_device(scsi_qla_host_t
*vha
)
2071 struct qla_hw_data
*ha
= vha
->hw
;
2072 qla2x00_abort_all_cmds(vha
, DID_NO_CONNECT
<< 16);
2075 if (vha
->timer_active
)
2076 qla2x00_stop_timer(vha
);
2078 vha
->flags
.online
= 0;
2080 /* Kill the kernel thread for this host */
2081 if (ha
->dpc_thread
) {
2082 struct task_struct
*t
= ha
->dpc_thread
;
2085 * qla2xxx_wake_dpc checks for ->dpc_thread
2086 * so we need to zero it out.
2088 ha
->dpc_thread
= NULL
;
2092 if (ha
->flags
.fce_enabled
)
2093 qla2x00_disable_fce_trace(vha
, NULL
, NULL
);
2096 qla2x00_disable_eft_trace(vha
);
2098 /* Stop currently executing firmware. */
2099 qla2x00_try_to_stop_firmware(vha
);
2101 /* turn-off interrupts on the card */
2102 if (ha
->interrupts_on
)
2103 ha
->isp_ops
->disable_intrs(ha
);
2105 qla2x00_free_irqs(vha
);
2107 qla2x00_mem_free(ha
);
2109 qla2x00_free_queues(ha
);
2113 qla2x00_schedule_rport_del(struct scsi_qla_host
*vha
, fc_port_t
*fcport
,
2116 struct fc_rport
*rport
;
2121 rport
= fcport
->rport
;
2123 spin_lock_irq(vha
->host
->host_lock
);
2124 fcport
->drport
= rport
;
2125 spin_unlock_irq(vha
->host
->host_lock
);
2126 set_bit(FCPORT_UPDATE_NEEDED
, &vha
->dpc_flags
);
2127 qla2xxx_wake_dpc(vha
);
2129 fc_remote_port_delete(rport
);
2133 * qla2x00_mark_device_lost Updates fcport state when device goes offline.
2135 * Input: ha = adapter block pointer. fcport = port structure pointer.
2141 void qla2x00_mark_device_lost(scsi_qla_host_t
*vha
, fc_port_t
*fcport
,
2142 int do_login
, int defer
)
2144 if (atomic_read(&fcport
->state
) == FCS_ONLINE
&&
2145 vha
->vp_idx
== fcport
->vp_idx
) {
2146 atomic_set(&fcport
->state
, FCS_DEVICE_LOST
);
2147 qla2x00_schedule_rport_del(vha
, fcport
, defer
);
2150 * We may need to retry the login, so don't change the state of the
2151 * port but do the retries.
2153 if (atomic_read(&fcport
->state
) != FCS_DEVICE_DEAD
)
2154 atomic_set(&fcport
->state
, FCS_DEVICE_LOST
);
2159 if (fcport
->login_retry
== 0) {
2160 fcport
->login_retry
= vha
->hw
->login_retry_count
;
2161 set_bit(RELOGIN_NEEDED
, &vha
->dpc_flags
);
2163 DEBUG(printk("scsi(%ld): Port login retry: "
2164 "%02x%02x%02x%02x%02x%02x%02x%02x, "
2165 "id = 0x%04x retry cnt=%d\n",
2167 fcport
->port_name
[0],
2168 fcport
->port_name
[1],
2169 fcport
->port_name
[2],
2170 fcport
->port_name
[3],
2171 fcport
->port_name
[4],
2172 fcport
->port_name
[5],
2173 fcport
->port_name
[6],
2174 fcport
->port_name
[7],
2176 fcport
->login_retry
));
2181 * qla2x00_mark_all_devices_lost
2182 * Updates fcport state when device goes offline.
2185 * ha = adapter block pointer.
2186 * fcport = port structure pointer.
2194 qla2x00_mark_all_devices_lost(scsi_qla_host_t
*vha
, int defer
)
2198 list_for_each_entry(fcport
, &vha
->vp_fcports
, list
) {
2199 if (vha
->vp_idx
!= fcport
->vp_idx
)
2202 * No point in marking the device as lost, if the device is
2205 if (atomic_read(&fcport
->state
) == FCS_DEVICE_DEAD
)
2207 if (atomic_read(&fcport
->state
) == FCS_ONLINE
) {
2208 atomic_set(&fcport
->state
, FCS_DEVICE_LOST
);
2209 qla2x00_schedule_rport_del(vha
, fcport
, defer
);
2211 atomic_set(&fcport
->state
, FCS_DEVICE_LOST
);
2217 * Allocates adapter memory.
2224 qla2x00_mem_alloc(struct qla_hw_data
*ha
, uint16_t req_len
, uint16_t rsp_len
,
2225 struct req_que
**req
, struct rsp_que
**rsp
)
2229 ha
->init_cb_size
= sizeof(init_cb_t
);
2230 if (IS_QLA2XXX_MIDTYPE(ha
))
2231 ha
->init_cb_size
= sizeof(struct mid_init_cb_24xx
);
2233 ha
->init_cb
= dma_alloc_coherent(&ha
->pdev
->dev
, ha
->init_cb_size
,
2234 &ha
->init_cb_dma
, GFP_KERNEL
);
2238 ha
->gid_list
= dma_alloc_coherent(&ha
->pdev
->dev
, GID_LIST_SIZE
,
2239 &ha
->gid_list_dma
, GFP_KERNEL
);
2241 goto fail_free_init_cb
;
2243 ha
->srb_mempool
= mempool_create_slab_pool(SRB_MIN_REQ
, srb_cachep
);
2244 if (!ha
->srb_mempool
)
2245 goto fail_free_gid_list
;
2247 /* Get memory for cached NVRAM */
2248 ha
->nvram
= kzalloc(MAX_NVRAM_SIZE
, GFP_KERNEL
);
2250 goto fail_free_srb_mempool
;
2252 snprintf(name
, sizeof(name
), "%s_%d", QLA2XXX_DRIVER_NAME
,
2254 ha
->s_dma_pool
= dma_pool_create(name
, &ha
->pdev
->dev
,
2255 DMA_POOL_SIZE
, 8, 0);
2256 if (!ha
->s_dma_pool
)
2257 goto fail_free_nvram
;
2259 /* Allocate memory for SNS commands */
2260 if (IS_QLA2100(ha
) || IS_QLA2200(ha
)) {
2261 /* Get consistent memory allocated for SNS commands */
2262 ha
->sns_cmd
= dma_alloc_coherent(&ha
->pdev
->dev
,
2263 sizeof(struct sns_cmd_pkt
), &ha
->sns_cmd_dma
, GFP_KERNEL
);
2267 /* Get consistent memory allocated for MS IOCB */
2268 ha
->ms_iocb
= dma_pool_alloc(ha
->s_dma_pool
, GFP_KERNEL
,
2272 /* Get consistent memory allocated for CT SNS commands */
2273 ha
->ct_sns
= dma_alloc_coherent(&ha
->pdev
->dev
,
2274 sizeof(struct ct_sns_pkt
), &ha
->ct_sns_dma
, GFP_KERNEL
);
2276 goto fail_free_ms_iocb
;
2279 /* Allocate memory for request ring */
2280 *req
= kzalloc(sizeof(struct req_que
), GFP_KERNEL
);
2282 DEBUG(printk("Unable to allocate memory for req\n"));
2285 (*req
)->length
= req_len
;
2286 (*req
)->ring
= dma_alloc_coherent(&ha
->pdev
->dev
,
2287 ((*req
)->length
+ 1) * sizeof(request_t
),
2288 &(*req
)->dma
, GFP_KERNEL
);
2289 if (!(*req
)->ring
) {
2290 DEBUG(printk("Unable to allocate memory for req_ring\n"));
2293 /* Allocate memory for response ring */
2294 *rsp
= kzalloc(sizeof(struct rsp_que
), GFP_KERNEL
);
2296 qla_printk(KERN_WARNING
, ha
,
2297 "Unable to allocate memory for rsp\n");
2301 (*rsp
)->length
= rsp_len
;
2302 (*rsp
)->ring
= dma_alloc_coherent(&ha
->pdev
->dev
,
2303 ((*rsp
)->length
+ 1) * sizeof(response_t
),
2304 &(*rsp
)->dma
, GFP_KERNEL
);
2305 if (!(*rsp
)->ring
) {
2306 qla_printk(KERN_WARNING
, ha
,
2307 "Unable to allocate memory for rsp_ring\n");
2312 /* Allocate memory for NVRAM data for vports */
2313 if (ha
->nvram_npiv_size
) {
2314 ha
->npiv_info
= kzalloc(sizeof(struct qla_npiv_entry
) *
2315 ha
->nvram_npiv_size
, GFP_KERNEL
);
2316 if (!ha
->npiv_info
) {
2317 qla_printk(KERN_WARNING
, ha
,
2318 "Unable to allocate memory for npiv info\n");
2319 goto fail_npiv_info
;
2322 ha
->npiv_info
= NULL
;
2324 INIT_LIST_HEAD(&ha
->vp_list
);
2328 dma_free_coherent(&ha
->pdev
->dev
, ((*rsp
)->length
+ 1) *
2329 sizeof(response_t
), (*rsp
)->ring
, (*rsp
)->dma
);
2330 (*rsp
)->ring
= NULL
;
2335 dma_free_coherent(&ha
->pdev
->dev
, ((*req
)->length
+ 1) *
2336 sizeof(request_t
), (*req
)->ring
, (*req
)->dma
);
2337 (*req
)->ring
= NULL
;
2342 dma_free_coherent(&ha
->pdev
->dev
, sizeof(struct ct_sns_pkt
),
2343 ha
->ct_sns
, ha
->ct_sns_dma
);
2347 dma_pool_free(ha
->s_dma_pool
, ha
->ms_iocb
, ha
->ms_iocb_dma
);
2349 ha
->ms_iocb_dma
= 0;
2351 dma_pool_destroy(ha
->s_dma_pool
);
2352 ha
->s_dma_pool
= NULL
;
2356 fail_free_srb_mempool
:
2357 mempool_destroy(ha
->srb_mempool
);
2358 ha
->srb_mempool
= NULL
;
2360 dma_free_coherent(&ha
->pdev
->dev
, GID_LIST_SIZE
, ha
->gid_list
,
2362 ha
->gid_list
= NULL
;
2363 ha
->gid_list_dma
= 0;
2365 dma_free_coherent(&ha
->pdev
->dev
, ha
->init_cb_size
, ha
->init_cb
,
2368 ha
->init_cb_dma
= 0;
2370 DEBUG(printk("%s: Memory allocation failure\n", __func__
));
2376 * Frees all adapter allocated memory.
2379 * ha = adapter block pointer.
2382 qla2x00_mem_free(struct qla_hw_data
*ha
)
2384 if (ha
->srb_mempool
)
2385 mempool_destroy(ha
->srb_mempool
);
2388 dma_free_coherent(&ha
->pdev
->dev
, FCE_SIZE
, ha
->fce
,
2393 dma_free_coherent(&ha
->pdev
->dev
,
2394 ntohl(ha
->fw_dump
->eft_size
), ha
->eft
, ha
->eft_dma
);
2399 dma_free_coherent(&ha
->pdev
->dev
, sizeof(struct sns_cmd_pkt
),
2400 ha
->sns_cmd
, ha
->sns_cmd_dma
);
2403 dma_free_coherent(&ha
->pdev
->dev
, sizeof(struct ct_sns_pkt
),
2404 ha
->ct_sns
, ha
->ct_sns_dma
);
2407 dma_pool_free(ha
->s_dma_pool
, ha
->sfp_data
, ha
->sfp_data_dma
);
2410 dma_pool_free(ha
->s_dma_pool
, ha
->ms_iocb
, ha
->ms_iocb_dma
);
2413 dma_pool_destroy(ha
->s_dma_pool
);
2417 dma_free_coherent(&ha
->pdev
->dev
, GID_LIST_SIZE
, ha
->gid_list
,
2422 dma_free_coherent(&ha
->pdev
->dev
, ha
->init_cb_size
,
2423 ha
->init_cb
, ha
->init_cb_dma
);
2424 vfree(ha
->optrom_buffer
);
2426 kfree(ha
->npiv_info
);
2428 ha
->srb_mempool
= NULL
;
2432 ha
->sns_cmd_dma
= 0;
2436 ha
->ms_iocb_dma
= 0;
2438 ha
->init_cb_dma
= 0;
2440 ha
->s_dma_pool
= NULL
;
2442 ha
->gid_list
= NULL
;
2443 ha
->gid_list_dma
= 0;
2447 ha
->fw_dump_reading
= 0;
2450 struct scsi_qla_host
*qla2x00_create_host(struct scsi_host_template
*sht
,
2451 struct qla_hw_data
*ha
)
2453 struct Scsi_Host
*host
;
2454 struct scsi_qla_host
*vha
= NULL
;
2456 host
= scsi_host_alloc(sht
, sizeof(scsi_qla_host_t
));
2459 "qla2xxx: Couldn't allocate host from scsi layer!\n");
2463 /* Clear our data area */
2464 vha
= shost_priv(host
);
2465 memset(vha
, 0, sizeof(scsi_qla_host_t
));
2468 vha
->host_no
= host
->host_no
;
2471 INIT_LIST_HEAD(&vha
->vp_fcports
);
2472 INIT_LIST_HEAD(&vha
->work_list
);
2473 INIT_LIST_HEAD(&vha
->list
);
2475 sprintf(vha
->host_str
, "%s_%ld", QLA2XXX_DRIVER_NAME
, vha
->host_no
);
2482 static struct qla_work_evt
*
2483 qla2x00_alloc_work(struct scsi_qla_host
*vha
, enum qla_work_type type
,
2486 struct qla_work_evt
*e
;
2488 e
= kzalloc(sizeof(struct qla_work_evt
), locked
? GFP_ATOMIC
:
2493 INIT_LIST_HEAD(&e
->list
);
2495 e
->flags
= QLA_EVT_FLAG_FREE
;
2500 qla2x00_post_work(struct scsi_qla_host
*vha
, struct qla_work_evt
*e
, int locked
)
2502 unsigned long uninitialized_var(flags
);
2503 struct qla_hw_data
*ha
= vha
->hw
;
2506 spin_lock_irqsave(&ha
->hardware_lock
, flags
);
2507 list_add_tail(&e
->list
, &vha
->work_list
);
2508 qla2xxx_wake_dpc(vha
);
2510 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
2515 qla2x00_post_aen_work(struct scsi_qla_host
*vha
, enum fc_host_event_code code
,
2518 struct qla_work_evt
*e
;
2520 e
= qla2x00_alloc_work(vha
, QLA_EVT_AEN
, 1);
2522 return QLA_FUNCTION_FAILED
;
2524 e
->u
.aen
.code
= code
;
2525 e
->u
.aen
.data
= data
;
2526 return qla2x00_post_work(vha
, e
, 1);
2530 qla2x00_do_work(struct scsi_qla_host
*vha
)
2532 struct qla_work_evt
*e
;
2533 struct qla_hw_data
*ha
= vha
->hw
;
2535 spin_lock_irq(&ha
->hardware_lock
);
2536 while (!list_empty(&vha
->work_list
)) {
2537 e
= list_entry(vha
->work_list
.next
, struct qla_work_evt
, list
);
2538 list_del_init(&e
->list
);
2539 spin_unlock_irq(&ha
->hardware_lock
);
2543 fc_host_post_event(vha
->host
, fc_get_event_number(),
2544 e
->u
.aen
.code
, e
->u
.aen
.data
);
2547 if (e
->flags
& QLA_EVT_FLAG_FREE
)
2549 spin_lock_irq(&ha
->hardware_lock
);
2551 spin_unlock_irq(&ha
->hardware_lock
);
2553 /* Relogins all the fcports of a vport
2554 * Context: dpc thread
2556 void qla2x00_relogin(struct scsi_qla_host
*vha
)
2560 uint16_t next_loopid
= 0;
2561 struct qla_hw_data
*ha
= vha
->hw
;
2563 list_for_each_entry(fcport
, &vha
->vp_fcports
, list
) {
2565 * If the port is not ONLINE then try to login
2566 * to it if we haven't run out of retries.
2568 if (atomic_read(&fcport
->state
) !=
2569 FCS_ONLINE
&& fcport
->login_retry
) {
2571 if (fcport
->flags
& FCF_FABRIC_DEVICE
) {
2572 if (fcport
->flags
& FCF_TAPE_PRESENT
)
2573 ha
->isp_ops
->fabric_logout(vha
,
2575 fcport
->d_id
.b
.domain
,
2576 fcport
->d_id
.b
.area
,
2577 fcport
->d_id
.b
.al_pa
);
2579 status
= qla2x00_fabric_login(vha
, fcport
,
2582 status
= qla2x00_local_device_login(vha
,
2585 fcport
->login_retry
--;
2586 if (status
== QLA_SUCCESS
) {
2587 fcport
->old_loop_id
= fcport
->loop_id
;
2589 DEBUG(printk("scsi(%ld): port login OK: logged "
2590 "in ID 0x%x\n", vha
->host_no
, fcport
->loop_id
));
2592 qla2x00_update_fcport(vha
, fcport
);
2594 } else if (status
== 1) {
2595 set_bit(RELOGIN_NEEDED
, &vha
->dpc_flags
);
2596 /* retry the login again */
2597 DEBUG(printk("scsi(%ld): Retrying"
2598 " %d login again loop_id 0x%x\n",
2599 vha
->host_no
, fcport
->login_retry
,
2602 fcport
->login_retry
= 0;
2605 if (fcport
->login_retry
== 0 && status
!= QLA_SUCCESS
)
2606 fcport
->loop_id
= FC_NO_LOOP_ID
;
2608 if (test_bit(LOOP_RESYNC_NEEDED
, &vha
->dpc_flags
))
2613 /**************************************************************************
2615 * This kernel thread is a task that is schedule by the interrupt handler
2616 * to perform the background processing for interrupts.
2619 * This task always run in the context of a kernel thread. It
2620 * is kick-off by the driver's detect code and starts up
2621 * up one per adapter. It immediately goes to sleep and waits for
2622 * some fibre event. When either the interrupt handler or
2623 * the timer routine detects a event it will one of the task
2624 * bits then wake us up.
2625 **************************************************************************/
2627 qla2x00_do_dpc(void *data
)
2630 scsi_qla_host_t
*base_vha
;
2631 struct qla_hw_data
*ha
;
2633 ha
= (struct qla_hw_data
*)data
;
2634 base_vha
= pci_get_drvdata(ha
->pdev
);
2636 set_user_nice(current
, -20);
2638 while (!kthread_should_stop()) {
2639 DEBUG3(printk("qla2x00: DPC handler sleeping\n"));
2641 set_current_state(TASK_INTERRUPTIBLE
);
2643 __set_current_state(TASK_RUNNING
);
2645 DEBUG3(printk("qla2x00: DPC handler waking up\n"));
2647 /* Initialization not yet finished. Don't do anything yet. */
2648 if (!base_vha
->flags
.init_done
)
2651 DEBUG3(printk("scsi(%ld): DPC handler\n", base_vha
->host_no
));
2655 if (ha
->flags
.mbox_busy
) {
2660 qla2x00_do_work(base_vha
);
2662 if (test_and_clear_bit(ISP_ABORT_NEEDED
,
2663 &base_vha
->dpc_flags
)) {
2665 DEBUG(printk("scsi(%ld): dpc: sched "
2666 "qla2x00_abort_isp ha = %p\n",
2667 base_vha
->host_no
, ha
));
2668 if (!(test_and_set_bit(ABORT_ISP_ACTIVE
,
2669 &base_vha
->dpc_flags
))) {
2671 if (qla2x00_abort_isp(base_vha
)) {
2672 /* failed. retry later */
2673 set_bit(ISP_ABORT_NEEDED
,
2674 &base_vha
->dpc_flags
);
2676 clear_bit(ABORT_ISP_ACTIVE
,
2677 &base_vha
->dpc_flags
);
2680 DEBUG(printk("scsi(%ld): dpc: qla2x00_abort_isp end\n",
2681 base_vha
->host_no
));
2684 if (test_bit(FCPORT_UPDATE_NEEDED
, &base_vha
->dpc_flags
)) {
2685 qla2x00_update_fcports(base_vha
);
2686 clear_bit(FCPORT_UPDATE_NEEDED
, &base_vha
->dpc_flags
);
2689 if (test_and_clear_bit(RESET_MARKER_NEEDED
,
2690 &base_vha
->dpc_flags
) &&
2691 (!(test_and_set_bit(RESET_ACTIVE
, &base_vha
->dpc_flags
)))) {
2693 DEBUG(printk("scsi(%ld): qla2x00_reset_marker()\n",
2694 base_vha
->host_no
));
2696 qla2x00_rst_aen(base_vha
);
2697 clear_bit(RESET_ACTIVE
, &base_vha
->dpc_flags
);
2700 /* Retry each device up to login retry count */
2701 if ((test_and_clear_bit(RELOGIN_NEEDED
,
2702 &base_vha
->dpc_flags
)) &&
2703 !test_bit(LOOP_RESYNC_NEEDED
, &base_vha
->dpc_flags
) &&
2704 atomic_read(&base_vha
->loop_state
) != LOOP_DOWN
) {
2706 DEBUG(printk("scsi(%ld): qla2x00_port_login()\n",
2707 base_vha
->host_no
));
2708 qla2x00_relogin(base_vha
);
2710 DEBUG(printk("scsi(%ld): qla2x00_port_login - end\n",
2711 base_vha
->host_no
));
2714 if (test_and_clear_bit(LOOP_RESYNC_NEEDED
,
2715 &base_vha
->dpc_flags
)) {
2717 DEBUG(printk("scsi(%ld): qla2x00_loop_resync()\n",
2718 base_vha
->host_no
));
2720 if (!(test_and_set_bit(LOOP_RESYNC_ACTIVE
,
2721 &base_vha
->dpc_flags
))) {
2723 rval
= qla2x00_loop_resync(base_vha
);
2725 clear_bit(LOOP_RESYNC_ACTIVE
,
2726 &base_vha
->dpc_flags
);
2729 DEBUG(printk("scsi(%ld): qla2x00_loop_resync - end\n",
2730 base_vha
->host_no
));
2733 if (test_bit(NPIV_CONFIG_NEEDED
, &base_vha
->dpc_flags
) &&
2734 atomic_read(&base_vha
->loop_state
) == LOOP_READY
) {
2735 clear_bit(NPIV_CONFIG_NEEDED
, &base_vha
->dpc_flags
);
2736 qla2xxx_flash_npiv_conf(base_vha
);
2739 if (!ha
->interrupts_on
)
2740 ha
->isp_ops
->enable_intrs(ha
);
2742 if (test_and_clear_bit(BEACON_BLINK_NEEDED
,
2743 &base_vha
->dpc_flags
))
2744 ha
->isp_ops
->beacon_blink(base_vha
);
2746 qla2x00_do_dpc_all_vps(base_vha
);
2749 } /* End of while(1) */
2751 DEBUG(printk("scsi(%ld): DPC handler exiting\n", base_vha
->host_no
));
2754 * Make sure that nobody tries to wake us up again.
2762 qla2xxx_wake_dpc(struct scsi_qla_host
*vha
)
2764 struct qla_hw_data
*ha
= vha
->hw
;
2765 struct task_struct
*t
= ha
->dpc_thread
;
2767 if (!test_bit(UNLOADING
, &vha
->dpc_flags
) && t
)
2773 * Processes asynchronous reset.
2776 * ha = adapter block pointer.
2779 qla2x00_rst_aen(scsi_qla_host_t
*vha
)
2781 if (vha
->flags
.online
&& !vha
->flags
.reset_active
&&
2782 !atomic_read(&vha
->loop_down_timer
) &&
2783 !(test_bit(ABORT_ISP_ACTIVE
, &vha
->dpc_flags
))) {
2785 clear_bit(RESET_MARKER_NEEDED
, &vha
->dpc_flags
);
2788 * Issue marker command only when we are going to start
2791 vha
->marker_needed
= 1;
2792 } while (!atomic_read(&vha
->loop_down_timer
) &&
2793 (test_bit(RESET_MARKER_NEEDED
, &vha
->dpc_flags
)));
2798 qla2x00_sp_free_dma(srb_t
*sp
)
2800 struct scsi_cmnd
*cmd
= sp
->cmd
;
2802 if (sp
->flags
& SRB_DMA_VALID
) {
2803 scsi_dma_unmap(cmd
);
2804 sp
->flags
&= ~SRB_DMA_VALID
;
2810 qla2x00_sp_compl(struct qla_hw_data
*ha
, srb_t
*sp
)
2812 struct scsi_cmnd
*cmd
= sp
->cmd
;
2814 qla2x00_sp_free_dma(sp
);
2816 mempool_free(sp
, ha
->srb_mempool
);
2818 cmd
->scsi_done(cmd
);
2821 /**************************************************************************
2827 * Context: Interrupt
2828 ***************************************************************************/
2830 qla2x00_timer(scsi_qla_host_t
*vha
)
2832 unsigned long cpu_flags
= 0;
2838 struct qla_hw_data
*ha
= vha
->hw
;
2839 struct req_que
*req
;
2841 * Ports - Port down timer.
2843 * Whenever, a port is in the LOST state we start decrementing its port
2844 * down timer every second until it reaches zero. Once it reaches zero
2845 * the port it marked DEAD.
2848 list_for_each_entry(fcport
, &vha
->vp_fcports
, list
) {
2849 if (fcport
->port_type
!= FCT_TARGET
)
2852 if (atomic_read(&fcport
->state
) == FCS_DEVICE_LOST
) {
2854 if (atomic_read(&fcport
->port_down_timer
) == 0)
2857 if (atomic_dec_and_test(&fcport
->port_down_timer
) != 0)
2858 atomic_set(&fcport
->state
, FCS_DEVICE_DEAD
);
2860 DEBUG(printk("scsi(%ld): fcport-%d - port retry count: "
2863 t
, atomic_read(&fcport
->port_down_timer
)));
2866 } /* End of for fcport */
2869 /* Loop down handler. */
2870 if (atomic_read(&vha
->loop_down_timer
) > 0 &&
2871 !(test_bit(ABORT_ISP_ACTIVE
, &vha
->dpc_flags
))
2872 && vha
->flags
.online
) {
2874 if (atomic_read(&vha
->loop_down_timer
) ==
2875 vha
->loop_down_abort_time
) {
2877 DEBUG(printk("scsi(%ld): Loop Down - aborting the "
2878 "queues before time expire\n",
2881 if (!IS_QLA2100(ha
) && vha
->link_down_timeout
)
2882 atomic_set(&vha
->loop_state
, LOOP_DEAD
);
2884 /* Schedule an ISP abort to return any tape commands. */
2885 /* NPIV - scan physical port only */
2887 spin_lock_irqsave(&ha
->hardware_lock
,
2889 req
= ha
->req_q_map
[0];
2891 index
< MAX_OUTSTANDING_COMMANDS
;
2895 sp
= req
->outstanding_cmds
[index
];
2899 if (!(sfcp
->flags
& FCF_TAPE_PRESENT
))
2902 set_bit(ISP_ABORT_NEEDED
,
2906 spin_unlock_irqrestore(&ha
->hardware_lock
,
2909 set_bit(ABORT_QUEUES_NEEDED
, &vha
->dpc_flags
);
2913 /* if the loop has been down for 4 minutes, reinit adapter */
2914 if (atomic_dec_and_test(&vha
->loop_down_timer
) != 0) {
2915 DEBUG(printk("scsi(%ld): Loop down exceed 4 mins - "
2916 "restarting queues.\n",
2919 set_bit(RESTART_QUEUES_NEEDED
, &vha
->dpc_flags
);
2922 if (!(vha
->device_flags
& DFLG_NO_CABLE
) &&
2924 DEBUG(printk("scsi(%ld): Loop down - "
2927 qla_printk(KERN_WARNING
, ha
,
2928 "Loop down - aborting ISP.\n");
2930 set_bit(ISP_ABORT_NEEDED
, &vha
->dpc_flags
);
2933 DEBUG3(printk("scsi(%ld): Loop Down - seconds remaining %d\n",
2935 atomic_read(&vha
->loop_down_timer
)));
2938 /* Check if beacon LED needs to be blinked */
2939 if (ha
->beacon_blink_led
== 1) {
2940 set_bit(BEACON_BLINK_NEEDED
, &vha
->dpc_flags
);
2944 /* Process any deferred work. */
2945 if (!list_empty(&vha
->work_list
))
2948 /* Schedule the DPC routine if needed */
2949 if ((test_bit(ISP_ABORT_NEEDED
, &vha
->dpc_flags
) ||
2950 test_bit(LOOP_RESYNC_NEEDED
, &vha
->dpc_flags
) ||
2951 test_bit(FCPORT_UPDATE_NEEDED
, &vha
->dpc_flags
) ||
2953 test_bit(RESET_MARKER_NEEDED
, &vha
->dpc_flags
) ||
2954 test_bit(BEACON_BLINK_NEEDED
, &vha
->dpc_flags
) ||
2955 test_bit(VP_DPC_NEEDED
, &vha
->dpc_flags
) ||
2956 test_bit(RELOGIN_NEEDED
, &vha
->dpc_flags
)))
2957 qla2xxx_wake_dpc(vha
);
2959 qla2x00_restart_timer(vha
, WATCH_INTERVAL
);
2962 /* Firmware interface routines. */
2965 #define FW_ISP21XX 0
2966 #define FW_ISP22XX 1
2967 #define FW_ISP2300 2
2968 #define FW_ISP2322 3
2969 #define FW_ISP24XX 4
2970 #define FW_ISP25XX 5
2971 #define FW_ISP81XX 6
2973 #define FW_FILE_ISP21XX "ql2100_fw.bin"
2974 #define FW_FILE_ISP22XX "ql2200_fw.bin"
2975 #define FW_FILE_ISP2300 "ql2300_fw.bin"
2976 #define FW_FILE_ISP2322 "ql2322_fw.bin"
2977 #define FW_FILE_ISP24XX "ql2400_fw.bin"
2978 #define FW_FILE_ISP25XX "ql2500_fw.bin"
2979 #define FW_FILE_ISP81XX "ql8100_fw.bin"
2981 static DEFINE_MUTEX(qla_fw_lock
);
2983 static struct fw_blob qla_fw_blobs
[FW_BLOBS
] = {
2984 { .name
= FW_FILE_ISP21XX
, .segs
= { 0x1000, 0 }, },
2985 { .name
= FW_FILE_ISP22XX
, .segs
= { 0x1000, 0 }, },
2986 { .name
= FW_FILE_ISP2300
, .segs
= { 0x800, 0 }, },
2987 { .name
= FW_FILE_ISP2322
, .segs
= { 0x800, 0x1c000, 0x1e000, 0 }, },
2988 { .name
= FW_FILE_ISP24XX
, },
2989 { .name
= FW_FILE_ISP25XX
, },
2990 { .name
= FW_FILE_ISP81XX
, },
2994 qla2x00_request_firmware(scsi_qla_host_t
*vha
)
2996 struct qla_hw_data
*ha
= vha
->hw
;
2997 struct fw_blob
*blob
;
3000 if (IS_QLA2100(ha
)) {
3001 blob
= &qla_fw_blobs
[FW_ISP21XX
];
3002 } else if (IS_QLA2200(ha
)) {
3003 blob
= &qla_fw_blobs
[FW_ISP22XX
];
3004 } else if (IS_QLA2300(ha
) || IS_QLA2312(ha
) || IS_QLA6312(ha
)) {
3005 blob
= &qla_fw_blobs
[FW_ISP2300
];
3006 } else if (IS_QLA2322(ha
) || IS_QLA6322(ha
)) {
3007 blob
= &qla_fw_blobs
[FW_ISP2322
];
3008 } else if (IS_QLA24XX_TYPE(ha
)) {
3009 blob
= &qla_fw_blobs
[FW_ISP24XX
];
3010 } else if (IS_QLA25XX(ha
)) {
3011 blob
= &qla_fw_blobs
[FW_ISP25XX
];
3012 } else if (IS_QLA81XX(ha
)) {
3013 blob
= &qla_fw_blobs
[FW_ISP81XX
];
3016 mutex_lock(&qla_fw_lock
);
3020 if (request_firmware(&blob
->fw
, blob
->name
, &ha
->pdev
->dev
)) {
3021 DEBUG2(printk("scsi(%ld): Failed to load firmware image "
3022 "(%s).\n", vha
->host_no
, blob
->name
));
3029 mutex_unlock(&qla_fw_lock
);
3034 qla2x00_release_firmware(void)
3038 mutex_lock(&qla_fw_lock
);
3039 for (idx
= 0; idx
< FW_BLOBS
; idx
++)
3040 if (qla_fw_blobs
[idx
].fw
)
3041 release_firmware(qla_fw_blobs
[idx
].fw
);
3042 mutex_unlock(&qla_fw_lock
);
3045 static pci_ers_result_t
3046 qla2xxx_pci_error_detected(struct pci_dev
*pdev
, pci_channel_state_t state
)
3049 case pci_channel_io_normal
:
3050 return PCI_ERS_RESULT_CAN_RECOVER
;
3051 case pci_channel_io_frozen
:
3052 pci_disable_device(pdev
);
3053 return PCI_ERS_RESULT_NEED_RESET
;
3054 case pci_channel_io_perm_failure
:
3055 qla2x00_remove_one(pdev
);
3056 return PCI_ERS_RESULT_DISCONNECT
;
3058 return PCI_ERS_RESULT_NEED_RESET
;
3061 static pci_ers_result_t
3062 qla2xxx_pci_mmio_enabled(struct pci_dev
*pdev
)
3064 int risc_paused
= 0;
3066 unsigned long flags
;
3067 scsi_qla_host_t
*base_vha
= pci_get_drvdata(pdev
);
3068 struct qla_hw_data
*ha
= base_vha
->hw
;
3069 struct device_reg_2xxx __iomem
*reg
= &ha
->iobase
->isp
;
3070 struct device_reg_24xx __iomem
*reg24
= &ha
->iobase
->isp24
;
3072 spin_lock_irqsave(&ha
->hardware_lock
, flags
);
3073 if (IS_QLA2100(ha
) || IS_QLA2200(ha
)){
3074 stat
= RD_REG_DWORD(®
->hccr
);
3075 if (stat
& HCCR_RISC_PAUSE
)
3077 } else if (IS_QLA23XX(ha
)) {
3078 stat
= RD_REG_DWORD(®
->u
.isp2300
.host_status
);
3079 if (stat
& HSR_RISC_PAUSED
)
3081 } else if (IS_FWI2_CAPABLE(ha
)) {
3082 stat
= RD_REG_DWORD(®24
->host_status
);
3083 if (stat
& HSRX_RISC_PAUSED
)
3086 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
3089 qla_printk(KERN_INFO
, ha
, "RISC paused -- mmio_enabled, "
3090 "Dumping firmware!\n");
3091 ha
->isp_ops
->fw_dump(base_vha
, 0);
3093 return PCI_ERS_RESULT_NEED_RESET
;
3095 return PCI_ERS_RESULT_RECOVERED
;
3098 static pci_ers_result_t
3099 qla2xxx_pci_slot_reset(struct pci_dev
*pdev
)
3101 pci_ers_result_t ret
= PCI_ERS_RESULT_DISCONNECT
;
3102 scsi_qla_host_t
*base_vha
= pci_get_drvdata(pdev
);
3103 struct qla_hw_data
*ha
= base_vha
->hw
;
3107 rc
= pci_enable_device_mem(pdev
);
3109 rc
= pci_enable_device(pdev
);
3112 qla_printk(KERN_WARNING
, ha
,
3113 "Can't re-enable PCI device after reset.\n");
3117 pci_set_master(pdev
);
3119 if (ha
->isp_ops
->pci_config(base_vha
))
3122 set_bit(ABORT_ISP_ACTIVE
, &base_vha
->dpc_flags
);
3123 if (qla2x00_abort_isp(base_vha
) == QLA_SUCCESS
)
3124 ret
= PCI_ERS_RESULT_RECOVERED
;
3125 clear_bit(ABORT_ISP_ACTIVE
, &base_vha
->dpc_flags
);
3131 qla2xxx_pci_resume(struct pci_dev
*pdev
)
3133 scsi_qla_host_t
*base_vha
= pci_get_drvdata(pdev
);
3134 struct qla_hw_data
*ha
= base_vha
->hw
;
3137 ret
= qla2x00_wait_for_hba_online(base_vha
);
3138 if (ret
!= QLA_SUCCESS
) {
3139 qla_printk(KERN_ERR
, ha
,
3140 "the device failed to resume I/O "
3141 "from slot/link_reset");
3143 pci_cleanup_aer_uncorrect_error_status(pdev
);
3146 static struct pci_error_handlers qla2xxx_err_handler
= {
3147 .error_detected
= qla2xxx_pci_error_detected
,
3148 .mmio_enabled
= qla2xxx_pci_mmio_enabled
,
3149 .slot_reset
= qla2xxx_pci_slot_reset
,
3150 .resume
= qla2xxx_pci_resume
,
3153 static struct pci_device_id qla2xxx_pci_tbl
[] = {
3154 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC
, PCI_DEVICE_ID_QLOGIC_ISP2100
) },
3155 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC
, PCI_DEVICE_ID_QLOGIC_ISP2200
) },
3156 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC
, PCI_DEVICE_ID_QLOGIC_ISP2300
) },
3157 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC
, PCI_DEVICE_ID_QLOGIC_ISP2312
) },
3158 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC
, PCI_DEVICE_ID_QLOGIC_ISP2322
) },
3159 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC
, PCI_DEVICE_ID_QLOGIC_ISP6312
) },
3160 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC
, PCI_DEVICE_ID_QLOGIC_ISP6322
) },
3161 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC
, PCI_DEVICE_ID_QLOGIC_ISP2422
) },
3162 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC
, PCI_DEVICE_ID_QLOGIC_ISP2432
) },
3163 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC
, PCI_DEVICE_ID_QLOGIC_ISP8432
) },
3164 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC
, PCI_DEVICE_ID_QLOGIC_ISP5422
) },
3165 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC
, PCI_DEVICE_ID_QLOGIC_ISP5432
) },
3166 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC
, PCI_DEVICE_ID_QLOGIC_ISP2532
) },
3167 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC
, PCI_DEVICE_ID_QLOGIC_ISP8001
) },
3170 MODULE_DEVICE_TABLE(pci
, qla2xxx_pci_tbl
);
3172 static struct pci_driver qla2xxx_pci_driver
= {
3173 .name
= QLA2XXX_DRIVER_NAME
,
3175 .owner
= THIS_MODULE
,
3177 .id_table
= qla2xxx_pci_tbl
,
3178 .probe
= qla2x00_probe_one
,
3179 .remove
= qla2x00_remove_one
,
3180 .err_handler
= &qla2xxx_err_handler
,
3184 * qla2x00_module_init - Module initialization.
3187 qla2x00_module_init(void)
3191 /* Allocate cache for SRBs. */
3192 srb_cachep
= kmem_cache_create("qla2xxx_srbs", sizeof(srb_t
), 0,
3193 SLAB_HWCACHE_ALIGN
, NULL
);
3194 if (srb_cachep
== NULL
) {
3196 "qla2xxx: Unable to allocate SRB cache...Failing load!\n");
3200 /* Derive version string. */
3201 strcpy(qla2x00_version_str
, QLA2XXX_VERSION
);
3202 if (ql2xextended_error_logging
)
3203 strcat(qla2x00_version_str
, "-debug");
3205 qla2xxx_transport_template
=
3206 fc_attach_transport(&qla2xxx_transport_functions
);
3207 if (!qla2xxx_transport_template
) {
3208 kmem_cache_destroy(srb_cachep
);
3211 qla2xxx_transport_vport_template
=
3212 fc_attach_transport(&qla2xxx_transport_vport_functions
);
3213 if (!qla2xxx_transport_vport_template
) {
3214 kmem_cache_destroy(srb_cachep
);
3215 fc_release_transport(qla2xxx_transport_template
);
3219 printk(KERN_INFO
"QLogic Fibre Channel HBA Driver: %s\n",
3220 qla2x00_version_str
);
3221 ret
= pci_register_driver(&qla2xxx_pci_driver
);
3223 kmem_cache_destroy(srb_cachep
);
3224 fc_release_transport(qla2xxx_transport_template
);
3225 fc_release_transport(qla2xxx_transport_vport_template
);
3231 * qla2x00_module_exit - Module cleanup.
3234 qla2x00_module_exit(void)
3236 pci_unregister_driver(&qla2xxx_pci_driver
);
3237 qla2x00_release_firmware();
3238 kmem_cache_destroy(srb_cachep
);
3239 fc_release_transport(qla2xxx_transport_template
);
3240 fc_release_transport(qla2xxx_transport_vport_template
);
3243 module_init(qla2x00_module_init
);
3244 module_exit(qla2x00_module_exit
);
3246 MODULE_AUTHOR("QLogic Corporation");
3247 MODULE_DESCRIPTION("QLogic Fibre Channel HBA Driver");
3248 MODULE_LICENSE("GPL");
3249 MODULE_VERSION(QLA2XXX_VERSION
);
3250 MODULE_FIRMWARE(FW_FILE_ISP21XX
);
3251 MODULE_FIRMWARE(FW_FILE_ISP22XX
);
3252 MODULE_FIRMWARE(FW_FILE_ISP2300
);
3253 MODULE_FIRMWARE(FW_FILE_ISP2322
);
3254 MODULE_FIRMWARE(FW_FILE_ISP24XX
);
3255 MODULE_FIRMWARE(FW_FILE_ISP25XX
);
3256 MODULE_FIRMWARE(FW_FILE_ISP81XX
);