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 qla2x00_queuecommand(struct scsi_cmnd
*cmd
,
108 void (*fn
)(struct scsi_cmnd
*));
109 static int qla24xx_queuecommand(struct scsi_cmnd
*cmd
,
110 void (*fn
)(struct scsi_cmnd
*));
111 static int qla2xxx_eh_abort(struct scsi_cmnd
*);
112 static int qla2xxx_eh_device_reset(struct scsi_cmnd
*);
113 static int qla2xxx_eh_target_reset(struct scsi_cmnd
*);
114 static int qla2xxx_eh_bus_reset(struct scsi_cmnd
*);
115 static int qla2xxx_eh_host_reset(struct scsi_cmnd
*);
117 static int qla2x00_change_queue_depth(struct scsi_device
*, int);
118 static int qla2x00_change_queue_type(struct scsi_device
*, int);
120 static struct scsi_host_template qla2x00_driver_template
= {
121 .module
= THIS_MODULE
,
122 .name
= QLA2XXX_DRIVER_NAME
,
123 .queuecommand
= qla2x00_queuecommand
,
125 .eh_abort_handler
= qla2xxx_eh_abort
,
126 .eh_device_reset_handler
= qla2xxx_eh_device_reset
,
127 .eh_target_reset_handler
= qla2xxx_eh_target_reset
,
128 .eh_bus_reset_handler
= qla2xxx_eh_bus_reset
,
129 .eh_host_reset_handler
= qla2xxx_eh_host_reset
,
131 .slave_configure
= qla2xxx_slave_configure
,
133 .slave_alloc
= qla2xxx_slave_alloc
,
134 .slave_destroy
= qla2xxx_slave_destroy
,
135 .scan_finished
= qla2xxx_scan_finished
,
136 .scan_start
= qla2xxx_scan_start
,
137 .change_queue_depth
= qla2x00_change_queue_depth
,
138 .change_queue_type
= qla2x00_change_queue_type
,
141 .use_clustering
= ENABLE_CLUSTERING
,
142 .sg_tablesize
= SG_ALL
,
145 * The RISC allows for each command to transfer (2^32-1) bytes of data,
146 * which equates to 0x800000 sectors.
148 .max_sectors
= 0xFFFF,
149 .shost_attrs
= qla2x00_host_attrs
,
152 struct scsi_host_template qla24xx_driver_template
= {
153 .module
= THIS_MODULE
,
154 .name
= QLA2XXX_DRIVER_NAME
,
155 .queuecommand
= qla24xx_queuecommand
,
157 .eh_abort_handler
= qla2xxx_eh_abort
,
158 .eh_device_reset_handler
= qla2xxx_eh_device_reset
,
159 .eh_target_reset_handler
= qla2xxx_eh_target_reset
,
160 .eh_bus_reset_handler
= qla2xxx_eh_bus_reset
,
161 .eh_host_reset_handler
= qla2xxx_eh_host_reset
,
163 .slave_configure
= qla2xxx_slave_configure
,
165 .slave_alloc
= qla2xxx_slave_alloc
,
166 .slave_destroy
= qla2xxx_slave_destroy
,
167 .scan_finished
= qla2xxx_scan_finished
,
168 .scan_start
= qla2xxx_scan_start
,
169 .change_queue_depth
= qla2x00_change_queue_depth
,
170 .change_queue_type
= qla2x00_change_queue_type
,
173 .use_clustering
= ENABLE_CLUSTERING
,
174 .sg_tablesize
= SG_ALL
,
176 .max_sectors
= 0xFFFF,
177 .shost_attrs
= qla2x00_host_attrs
,
180 static struct scsi_transport_template
*qla2xxx_transport_template
= NULL
;
181 struct scsi_transport_template
*qla2xxx_transport_vport_template
= NULL
;
183 /* TODO Convert to inlines
189 qla2x00_start_timer(scsi_qla_host_t
*vha
, void *func
, unsigned long interval
)
191 init_timer(&vha
->timer
);
192 vha
->timer
.expires
= jiffies
+ interval
* HZ
;
193 vha
->timer
.data
= (unsigned long)vha
;
194 vha
->timer
.function
= (void (*)(unsigned long))func
;
195 add_timer(&vha
->timer
);
196 vha
->timer_active
= 1;
200 qla2x00_restart_timer(scsi_qla_host_t
*vha
, unsigned long interval
)
202 mod_timer(&vha
->timer
, jiffies
+ interval
* HZ
);
205 static __inline__
void
206 qla2x00_stop_timer(scsi_qla_host_t
*vha
)
208 del_timer_sync(&vha
->timer
);
209 vha
->timer_active
= 0;
212 static int qla2x00_do_dpc(void *data
);
214 static void qla2x00_rst_aen(scsi_qla_host_t
*);
216 static int qla2x00_mem_alloc(struct qla_hw_data
*, uint16_t, uint16_t,
217 struct req_que
**, struct rsp_que
**);
218 static void qla2x00_mem_free(struct qla_hw_data
*);
219 static void qla2x00_sp_free_dma(srb_t
*);
221 /* -------------------------------------------------------------------------- */
222 static int qla2x00_alloc_queues(struct qla_hw_data
*ha
)
224 ha
->req_q_map
= kzalloc(sizeof(struct req_que
*) * ha
->max_queues
,
226 if (!ha
->req_q_map
) {
227 qla_printk(KERN_WARNING
, ha
,
228 "Unable to allocate memory for request queue ptrs\n");
232 ha
->rsp_q_map
= kzalloc(sizeof(struct rsp_que
*) * ha
->max_queues
,
234 if (!ha
->rsp_q_map
) {
235 qla_printk(KERN_WARNING
, ha
,
236 "Unable to allocate memory for response queue ptrs\n");
239 set_bit(0, ha
->rsp_qid_map
);
240 set_bit(0, ha
->req_qid_map
);
244 kfree(ha
->req_q_map
);
245 ha
->req_q_map
= NULL
;
250 static void qla2x00_free_que(struct qla_hw_data
*ha
, struct req_que
*req
,
253 if (rsp
&& rsp
->ring
)
254 dma_free_coherent(&ha
->pdev
->dev
,
255 (rsp
->length
+ 1) * sizeof(response_t
),
256 rsp
->ring
, rsp
->dma
);
260 if (req
&& req
->ring
)
261 dma_free_coherent(&ha
->pdev
->dev
,
262 (req
->length
+ 1) * sizeof(request_t
),
263 req
->ring
, req
->dma
);
269 static void qla2x00_free_queues(struct qla_hw_data
*ha
)
275 for (cnt
= 0; cnt
< ha
->max_queues
; cnt
++) {
276 rsp
= ha
->rsp_q_map
[cnt
];
277 req
= ha
->req_q_map
[cnt
];
278 qla2x00_free_que(ha
, req
, rsp
);
280 kfree(ha
->rsp_q_map
);
281 ha
->rsp_q_map
= NULL
;
283 kfree(ha
->req_q_map
);
284 ha
->req_q_map
= NULL
;
288 qla2x00_pci_info_str(struct scsi_qla_host
*vha
, char *str
)
290 struct qla_hw_data
*ha
= vha
->hw
;
291 static char *pci_bus_modes
[] = {
292 "33", "66", "100", "133",
297 pci_bus
= (ha
->pci_attr
& (BIT_9
| BIT_10
)) >> 9;
300 strcat(str
, pci_bus_modes
[pci_bus
]);
302 pci_bus
= (ha
->pci_attr
& BIT_8
) >> 8;
304 strcat(str
, pci_bus_modes
[pci_bus
]);
306 strcat(str
, " MHz)");
312 qla24xx_pci_info_str(struct scsi_qla_host
*vha
, char *str
)
314 static char *pci_bus_modes
[] = { "33", "66", "100", "133", };
315 struct qla_hw_data
*ha
= vha
->hw
;
319 pcie_reg
= pci_find_capability(ha
->pdev
, PCI_CAP_ID_EXP
);
322 uint16_t pcie_lstat
, lspeed
, lwidth
;
325 pci_read_config_word(ha
->pdev
, pcie_reg
, &pcie_lstat
);
326 lspeed
= pcie_lstat
& (BIT_0
| BIT_1
| BIT_2
| BIT_3
);
327 lwidth
= (pcie_lstat
&
328 (BIT_4
| BIT_5
| BIT_6
| BIT_7
| BIT_8
| BIT_9
)) >> 4;
330 strcpy(str
, "PCIe (");
332 strcat(str
, "2.5GT/s ");
333 else if (lspeed
== 2)
334 strcat(str
, "5.0GT/s ");
336 strcat(str
, "<unknown> ");
337 snprintf(lwstr
, sizeof(lwstr
), "x%d)", lwidth
);
344 pci_bus
= (ha
->pci_attr
& CSRX_PCIX_BUS_MODE_MASK
) >> 8;
345 if (pci_bus
== 0 || pci_bus
== 8) {
347 strcat(str
, pci_bus_modes
[pci_bus
>> 3]);
351 strcat(str
, "Mode 2");
353 strcat(str
, "Mode 1");
355 strcat(str
, pci_bus_modes
[pci_bus
& ~BIT_2
]);
357 strcat(str
, " MHz)");
363 qla2x00_fw_version_str(struct scsi_qla_host
*vha
, char *str
)
366 struct qla_hw_data
*ha
= vha
->hw
;
368 sprintf(str
, "%d.%02d.%02d ", ha
->fw_major_version
,
369 ha
->fw_minor_version
,
370 ha
->fw_subminor_version
);
372 if (ha
->fw_attributes
& BIT_9
) {
377 switch (ha
->fw_attributes
& 0xFF) {
391 sprintf(un_str
, "(%x)", ha
->fw_attributes
);
395 if (ha
->fw_attributes
& 0x100)
402 qla24xx_fw_version_str(struct scsi_qla_host
*vha
, char *str
)
404 struct qla_hw_data
*ha
= vha
->hw
;
406 sprintf(str
, "%d.%02d.%02d (%x)", ha
->fw_major_version
,
407 ha
->fw_minor_version
, ha
->fw_subminor_version
, ha
->fw_attributes
);
411 static inline srb_t
*
412 qla2x00_get_new_sp(scsi_qla_host_t
*vha
, fc_port_t
*fcport
,
413 struct scsi_cmnd
*cmd
, void (*done
)(struct scsi_cmnd
*))
416 struct qla_hw_data
*ha
= vha
->hw
;
418 sp
= mempool_alloc(ha
->srb_mempool
, GFP_ATOMIC
);
424 sp
->que
= ha
->req_q_map
[0];
426 CMD_SP(cmd
) = (void *)sp
;
427 cmd
->scsi_done
= done
;
433 qla2x00_queuecommand(struct scsi_cmnd
*cmd
, void (*done
)(struct scsi_cmnd
*))
435 scsi_qla_host_t
*vha
= shost_priv(cmd
->device
->host
);
436 fc_port_t
*fcport
= (struct fc_port
*) cmd
->device
->hostdata
;
437 struct fc_rport
*rport
= starget_to_rport(scsi_target(cmd
->device
));
438 struct qla_hw_data
*ha
= vha
->hw
;
442 if (unlikely(pci_channel_offline(ha
->pdev
))) {
443 cmd
->result
= DID_REQUEUE
<< 16;
444 goto qc_fail_command
;
447 rval
= fc_remote_port_chkready(rport
);
450 goto qc_fail_command
;
453 /* Close window on fcport/rport state-transitioning. */
457 if (atomic_read(&fcport
->state
) != FCS_ONLINE
) {
458 if (atomic_read(&fcport
->state
) == FCS_DEVICE_DEAD
||
459 atomic_read(&vha
->loop_state
) == LOOP_DEAD
) {
460 cmd
->result
= DID_NO_CONNECT
<< 16;
461 goto qc_fail_command
;
466 spin_unlock_irq(vha
->host
->host_lock
);
468 sp
= qla2x00_get_new_sp(vha
, fcport
, cmd
, done
);
470 goto qc_host_busy_lock
;
472 rval
= ha
->isp_ops
->start_scsi(sp
);
473 if (rval
!= QLA_SUCCESS
)
474 goto qc_host_busy_free_sp
;
476 spin_lock_irq(vha
->host
->host_lock
);
480 qc_host_busy_free_sp
:
481 qla2x00_sp_free_dma(sp
);
482 mempool_free(sp
, ha
->srb_mempool
);
485 spin_lock_irq(vha
->host
->host_lock
);
486 return SCSI_MLQUEUE_HOST_BUSY
;
489 return SCSI_MLQUEUE_TARGET_BUSY
;
499 qla24xx_queuecommand(struct scsi_cmnd
*cmd
, void (*done
)(struct scsi_cmnd
*))
501 scsi_qla_host_t
*vha
= shost_priv(cmd
->device
->host
);
502 fc_port_t
*fcport
= (struct fc_port
*) cmd
->device
->hostdata
;
503 struct fc_rport
*rport
= starget_to_rport(scsi_target(cmd
->device
));
504 struct qla_hw_data
*ha
= vha
->hw
;
505 struct scsi_qla_host
*base_vha
= pci_get_drvdata(ha
->pdev
);
509 if (unlikely(pci_channel_offline(ha
->pdev
))) {
510 cmd
->result
= DID_REQUEUE
<< 16;
511 goto qc24_fail_command
;
514 rval
= fc_remote_port_chkready(rport
);
517 goto qc24_fail_command
;
520 /* Close window on fcport/rport state-transitioning. */
522 goto qc24_target_busy
;
524 if (atomic_read(&fcport
->state
) != FCS_ONLINE
) {
525 if (atomic_read(&fcport
->state
) == FCS_DEVICE_DEAD
||
526 atomic_read(&base_vha
->loop_state
) == LOOP_DEAD
) {
527 cmd
->result
= DID_NO_CONNECT
<< 16;
528 goto qc24_fail_command
;
530 goto qc24_target_busy
;
533 spin_unlock_irq(vha
->host
->host_lock
);
535 sp
= qla2x00_get_new_sp(base_vha
, fcport
, cmd
, done
);
537 goto qc24_host_busy_lock
;
539 rval
= ha
->isp_ops
->start_scsi(sp
);
540 if (rval
!= QLA_SUCCESS
)
541 goto qc24_host_busy_free_sp
;
543 spin_lock_irq(vha
->host
->host_lock
);
547 qc24_host_busy_free_sp
:
548 qla2x00_sp_free_dma(sp
);
549 mempool_free(sp
, ha
->srb_mempool
);
552 spin_lock_irq(vha
->host
->host_lock
);
553 return SCSI_MLQUEUE_HOST_BUSY
;
556 return SCSI_MLQUEUE_TARGET_BUSY
;
566 * qla2x00_eh_wait_on_command
567 * Waits for the command to be returned by the Firmware for some
571 * cmd = Scsi Command to wait on.
578 qla2x00_eh_wait_on_command(struct scsi_cmnd
*cmd
)
580 #define ABORT_POLLING_PERIOD 1000
581 #define ABORT_WAIT_ITER ((10 * 1000) / (ABORT_POLLING_PERIOD))
582 unsigned long wait_iter
= ABORT_WAIT_ITER
;
583 int ret
= QLA_SUCCESS
;
585 while (CMD_SP(cmd
)) {
586 msleep(ABORT_POLLING_PERIOD
);
592 ret
= QLA_FUNCTION_FAILED
;
598 * qla2x00_wait_for_hba_online
599 * Wait till the HBA is online after going through
600 * <= MAX_RETRIES_OF_ISP_ABORT or
601 * finally HBA is disabled ie marked offline
604 * ha - pointer to host adapter structure
607 * Does context switching-Release SPIN_LOCK
608 * (if any) before calling this routine.
611 * Success (Adapter is online) : 0
612 * Failed (Adapter is offline/disabled) : 1
615 qla2x00_wait_for_hba_online(scsi_qla_host_t
*vha
)
618 unsigned long wait_online
;
619 struct qla_hw_data
*ha
= vha
->hw
;
620 scsi_qla_host_t
*base_vha
= pci_get_drvdata(ha
->pdev
);
622 wait_online
= jiffies
+ (MAX_LOOP_TIMEOUT
* HZ
);
623 while (((test_bit(ISP_ABORT_NEEDED
, &base_vha
->dpc_flags
)) ||
624 test_bit(ABORT_ISP_ACTIVE
, &base_vha
->dpc_flags
) ||
625 test_bit(ISP_ABORT_RETRY
, &base_vha
->dpc_flags
) ||
626 ha
->dpc_active
) && time_before(jiffies
, wait_online
)) {
630 if (base_vha
->flags
.online
)
631 return_status
= QLA_SUCCESS
;
633 return_status
= QLA_FUNCTION_FAILED
;
635 return (return_status
);
639 * qla2x00_wait_for_loop_ready
640 * Wait for MAX_LOOP_TIMEOUT(5 min) value for loop
641 * to be in LOOP_READY state.
643 * ha - pointer to host adapter structure
646 * Does context switching-Release SPIN_LOCK
647 * (if any) before calling this routine.
651 * Success (LOOP_READY) : 0
652 * Failed (LOOP_NOT_READY) : 1
655 qla2x00_wait_for_loop_ready(scsi_qla_host_t
*vha
)
657 int return_status
= QLA_SUCCESS
;
658 unsigned long loop_timeout
;
659 struct qla_hw_data
*ha
= vha
->hw
;
660 scsi_qla_host_t
*base_vha
= pci_get_drvdata(ha
->pdev
);
662 /* wait for 5 min at the max for loop to be ready */
663 loop_timeout
= jiffies
+ (MAX_LOOP_TIMEOUT
* HZ
);
665 while ((!atomic_read(&base_vha
->loop_down_timer
) &&
666 atomic_read(&base_vha
->loop_state
) == LOOP_DOWN
) ||
667 atomic_read(&base_vha
->loop_state
) != LOOP_READY
) {
668 if (atomic_read(&base_vha
->loop_state
) == LOOP_DEAD
) {
669 return_status
= QLA_FUNCTION_FAILED
;
673 if (time_after_eq(jiffies
, loop_timeout
)) {
674 return_status
= QLA_FUNCTION_FAILED
;
678 return (return_status
);
682 qla2x00_abort_fcport_cmds(fc_port_t
*fcport
)
687 scsi_qla_host_t
*vha
= fcport
->vha
;
688 struct qla_hw_data
*ha
= vha
->hw
;
691 spin_lock_irqsave(&ha
->hardware_lock
, flags
);
692 for (que
= 0; que
< QLA_MAX_HOST_QUES
; que
++) {
693 id
= vha
->req_ques
[que
];
694 req
= ha
->req_q_map
[id
];
697 for (cnt
= 1; cnt
< MAX_OUTSTANDING_COMMANDS
; cnt
++) {
698 sp
= req
->outstanding_cmds
[cnt
];
701 if (sp
->fcport
!= fcport
)
704 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
705 if (ha
->isp_ops
->abort_command(vha
, sp
, req
)) {
706 DEBUG2(qla_printk(KERN_WARNING
, ha
,
707 "Abort failed -- %lx\n",
708 sp
->cmd
->serial_number
));
710 if (qla2x00_eh_wait_on_command(sp
->cmd
) !=
712 DEBUG2(qla_printk(KERN_WARNING
, ha
,
713 "Abort failed while waiting -- %lx\n",
714 sp
->cmd
->serial_number
));
716 spin_lock_irqsave(&ha
->hardware_lock
, flags
);
719 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
723 qla2x00_block_error_handler(struct scsi_cmnd
*cmnd
)
725 struct Scsi_Host
*shost
= cmnd
->device
->host
;
726 struct fc_rport
*rport
= starget_to_rport(scsi_target(cmnd
->device
));
729 spin_lock_irqsave(shost
->host_lock
, flags
);
730 while (rport
->port_state
== FC_PORTSTATE_BLOCKED
) {
731 spin_unlock_irqrestore(shost
->host_lock
, flags
);
733 spin_lock_irqsave(shost
->host_lock
, flags
);
735 spin_unlock_irqrestore(shost
->host_lock
, flags
);
739 /**************************************************************************
743 * The abort function will abort the specified command.
746 * cmd = Linux SCSI command packet to be aborted.
749 * Either SUCCESS or FAILED.
752 * Only return FAILED if command not returned by firmware.
753 **************************************************************************/
755 qla2xxx_eh_abort(struct scsi_cmnd
*cmd
)
757 scsi_qla_host_t
*vha
= shost_priv(cmd
->device
->host
);
760 unsigned int id
, lun
;
761 unsigned long serial
;
764 struct qla_hw_data
*ha
= vha
->hw
;
768 qla2x00_block_error_handler(cmd
);
775 id
= cmd
->device
->id
;
776 lun
= cmd
->device
->lun
;
777 serial
= cmd
->serial_number
;
778 spt
= (srb_t
*) CMD_SP(cmd
);
783 /* Check active list for command command. */
784 spin_lock_irqsave(&ha
->hardware_lock
, flags
);
785 for (i
= 1; i
< MAX_OUTSTANDING_COMMANDS
; i
++) {
786 sp
= req
->outstanding_cmds
[i
];
794 DEBUG2(printk("%s(%ld): aborting sp %p from RISC."
795 " pid=%ld.\n", __func__
, vha
->host_no
, sp
, serial
));
797 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
798 if (ha
->isp_ops
->abort_command(vha
, sp
, req
)) {
799 DEBUG2(printk("%s(%ld): abort_command "
800 "mbx failed.\n", __func__
, vha
->host_no
));
803 DEBUG3(printk("%s(%ld): abort_command "
804 "mbx success.\n", __func__
, vha
->host_no
));
807 spin_lock_irqsave(&ha
->hardware_lock
, flags
);
810 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
812 /* Wait for the command to be returned. */
814 if (qla2x00_eh_wait_on_command(cmd
) != QLA_SUCCESS
) {
815 qla_printk(KERN_ERR
, ha
,
816 "scsi(%ld:%d:%d): Abort handler timed out -- %lx "
817 "%x.\n", vha
->host_no
, id
, lun
, serial
, ret
);
822 qla_printk(KERN_INFO
, ha
,
823 "scsi(%ld:%d:%d): Abort command issued -- %d %lx %x.\n",
824 vha
->host_no
, id
, lun
, wait
, serial
, ret
);
829 enum nexus_wait_type
{
836 qla2x00_eh_wait_for_pending_commands(scsi_qla_host_t
*vha
, unsigned int t
,
837 unsigned int l
, srb_t
*sp
, enum nexus_wait_type type
)
839 int cnt
, match
, status
;
841 struct qla_hw_data
*ha
= vha
->hw
;
844 status
= QLA_SUCCESS
;
848 spin_lock_irqsave(&ha
->hardware_lock
, flags
);
850 for (cnt
= 1; status
== QLA_SUCCESS
&&
851 cnt
< MAX_OUTSTANDING_COMMANDS
; cnt
++) {
852 sp
= req
->outstanding_cmds
[cnt
];
856 if (vha
->vp_idx
!= sp
->fcport
->vha
->vp_idx
)
864 match
= sp
->cmd
->device
->id
== t
;
867 match
= (sp
->cmd
->device
->id
== t
&&
868 sp
->cmd
->device
->lun
== l
);
874 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
875 status
= qla2x00_eh_wait_on_command(sp
->cmd
);
876 spin_lock_irqsave(&ha
->hardware_lock
, flags
);
878 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
883 static char *reset_errors
[] = {
886 "Task management failed",
887 "Waiting for command completions",
891 __qla2xxx_eh_generic_reset(char *name
, enum nexus_wait_type type
,
892 struct scsi_cmnd
*cmd
, int (*do_reset
)(struct fc_port
*, unsigned int))
894 scsi_qla_host_t
*vha
= shost_priv(cmd
->device
->host
);
895 fc_port_t
*fcport
= (struct fc_port
*) cmd
->device
->hostdata
;
898 qla2x00_block_error_handler(cmd
);
903 qla_printk(KERN_INFO
, vha
->hw
, "scsi(%ld:%d:%d): %s RESET ISSUED.\n",
904 vha
->host_no
, cmd
->device
->id
, cmd
->device
->lun
, name
);
907 if (qla2x00_wait_for_hba_online(vha
) != QLA_SUCCESS
)
908 goto eh_reset_failed
;
910 if (qla2x00_wait_for_loop_ready(vha
) != QLA_SUCCESS
)
911 goto eh_reset_failed
;
913 if (do_reset(fcport
, cmd
->device
->lun
) != QLA_SUCCESS
)
914 goto eh_reset_failed
;
916 if (qla2x00_eh_wait_for_pending_commands(vha
, cmd
->device
->id
,
917 cmd
->device
->lun
, (srb_t
*) CMD_SP(cmd
), type
) != QLA_SUCCESS
)
918 goto eh_reset_failed
;
920 qla_printk(KERN_INFO
, vha
->hw
, "scsi(%ld:%d:%d): %s RESET SUCCEEDED.\n",
921 vha
->host_no
, cmd
->device
->id
, cmd
->device
->lun
, name
);
926 qla_printk(KERN_INFO
, vha
->hw
, "scsi(%ld:%d:%d): %s RESET FAILED: %s.\n"
927 , vha
->host_no
, cmd
->device
->id
, cmd
->device
->lun
, name
,
933 qla2xxx_eh_device_reset(struct scsi_cmnd
*cmd
)
935 scsi_qla_host_t
*vha
= shost_priv(cmd
->device
->host
);
936 struct qla_hw_data
*ha
= vha
->hw
;
938 return __qla2xxx_eh_generic_reset("DEVICE", WAIT_LUN
, cmd
,
939 ha
->isp_ops
->lun_reset
);
943 qla2xxx_eh_target_reset(struct scsi_cmnd
*cmd
)
945 scsi_qla_host_t
*vha
= shost_priv(cmd
->device
->host
);
946 struct qla_hw_data
*ha
= vha
->hw
;
948 return __qla2xxx_eh_generic_reset("TARGET", WAIT_TARGET
, cmd
,
949 ha
->isp_ops
->target_reset
);
952 /**************************************************************************
953 * qla2xxx_eh_bus_reset
956 * The bus reset function will reset the bus and abort any executing
960 * cmd = Linux SCSI command packet of the command that cause the
964 * SUCCESS/FAILURE (defined as macro in scsi.h).
966 **************************************************************************/
968 qla2xxx_eh_bus_reset(struct scsi_cmnd
*cmd
)
970 scsi_qla_host_t
*vha
= shost_priv(cmd
->device
->host
);
971 fc_port_t
*fcport
= (struct fc_port
*) cmd
->device
->hostdata
;
973 unsigned int id
, lun
;
974 unsigned long serial
;
975 srb_t
*sp
= (srb_t
*) CMD_SP(cmd
);
977 qla2x00_block_error_handler(cmd
);
979 id
= cmd
->device
->id
;
980 lun
= cmd
->device
->lun
;
981 serial
= cmd
->serial_number
;
986 qla_printk(KERN_INFO
, vha
->hw
,
987 "scsi(%ld:%d:%d): BUS RESET ISSUED.\n", vha
->host_no
, id
, lun
);
989 if (qla2x00_wait_for_hba_online(vha
) != QLA_SUCCESS
) {
990 DEBUG2(printk("%s failed:board disabled\n",__func__
));
991 goto eh_bus_reset_done
;
994 if (qla2x00_wait_for_loop_ready(vha
) == QLA_SUCCESS
) {
995 if (qla2x00_loop_reset(vha
) == QLA_SUCCESS
)
999 goto eh_bus_reset_done
;
1001 /* Flush outstanding commands. */
1002 if (qla2x00_eh_wait_for_pending_commands(vha
, 0, 0, sp
, WAIT_HOST
) !=
1007 qla_printk(KERN_INFO
, vha
->hw
, "%s: reset %s\n", __func__
,
1008 (ret
== FAILED
) ? "failed" : "succeded");
1013 /**************************************************************************
1014 * qla2xxx_eh_host_reset
1017 * The reset function will reset the Adapter.
1020 * cmd = Linux SCSI command packet of the command that cause the
1024 * Either SUCCESS or FAILED.
1027 **************************************************************************/
1029 qla2xxx_eh_host_reset(struct scsi_cmnd
*cmd
)
1031 scsi_qla_host_t
*vha
= shost_priv(cmd
->device
->host
);
1032 fc_port_t
*fcport
= (struct fc_port
*) cmd
->device
->hostdata
;
1033 struct qla_hw_data
*ha
= vha
->hw
;
1035 unsigned int id
, lun
;
1036 unsigned long serial
;
1037 srb_t
*sp
= (srb_t
*) CMD_SP(cmd
);
1038 scsi_qla_host_t
*base_vha
= pci_get_drvdata(ha
->pdev
);
1040 qla2x00_block_error_handler(cmd
);
1042 id
= cmd
->device
->id
;
1043 lun
= cmd
->device
->lun
;
1044 serial
= cmd
->serial_number
;
1049 qla_printk(KERN_INFO
, ha
,
1050 "scsi(%ld:%d:%d): ADAPTER RESET ISSUED.\n", vha
->host_no
, id
, lun
);
1052 if (qla2x00_wait_for_hba_online(vha
) != QLA_SUCCESS
)
1053 goto eh_host_reset_lock
;
1056 * Fixme-may be dpc thread is active and processing
1057 * loop_resync,so wait a while for it to
1058 * be completed and then issue big hammer.Otherwise
1059 * it may cause I/O failure as big hammer marks the
1060 * devices as lost kicking of the port_down_timer
1061 * while dpc is stuck for the mailbox to complete.
1063 qla2x00_wait_for_loop_ready(vha
);
1064 if (vha
!= base_vha
) {
1065 if (qla2x00_vp_abort_isp(vha
))
1066 goto eh_host_reset_lock
;
1068 set_bit(ABORT_ISP_ACTIVE
, &base_vha
->dpc_flags
);
1069 if (qla2x00_abort_isp(base_vha
)) {
1070 clear_bit(ABORT_ISP_ACTIVE
, &base_vha
->dpc_flags
);
1071 /* failed. schedule dpc to try */
1072 set_bit(ISP_ABORT_NEEDED
, &base_vha
->dpc_flags
);
1074 if (qla2x00_wait_for_hba_online(vha
) != QLA_SUCCESS
)
1075 goto eh_host_reset_lock
;
1077 clear_bit(ABORT_ISP_ACTIVE
, &base_vha
->dpc_flags
);
1080 /* Waiting for command to be returned to OS.*/
1081 if (qla2x00_eh_wait_for_pending_commands(vha
, 0, 0, sp
, WAIT_HOST
) ==
1086 qla_printk(KERN_INFO
, ha
, "%s: reset %s\n", __func__
,
1087 (ret
== FAILED
) ? "failed" : "succeded");
1093 * qla2x00_loop_reset
1097 * ha = adapter block pointer.
1103 qla2x00_loop_reset(scsi_qla_host_t
*vha
)
1106 struct fc_port
*fcport
;
1107 struct qla_hw_data
*ha
= vha
->hw
;
1109 if (ha
->flags
.enable_lip_full_login
&& !vha
->vp_idx
) {
1110 ret
= qla2x00_full_login_lip(vha
);
1111 if (ret
!= QLA_SUCCESS
) {
1112 DEBUG2_3(printk("%s(%ld): failed: "
1113 "full_login_lip=%d.\n", __func__
, vha
->host_no
,
1116 atomic_set(&vha
->loop_state
, LOOP_DOWN
);
1117 atomic_set(&vha
->loop_down_timer
, LOOP_DOWN_TIME
);
1118 qla2x00_mark_all_devices_lost(vha
, 0);
1119 qla2x00_wait_for_loop_ready(vha
);
1122 if (ha
->flags
.enable_lip_reset
&& !vha
->vp_idx
) {
1123 ret
= qla2x00_lip_reset(vha
);
1124 if (ret
!= QLA_SUCCESS
) {
1125 DEBUG2_3(printk("%s(%ld): failed: "
1126 "lip_reset=%d.\n", __func__
, vha
->host_no
, ret
));
1128 qla2x00_wait_for_loop_ready(vha
);
1131 if (ha
->flags
.enable_target_reset
) {
1132 list_for_each_entry(fcport
, &vha
->vp_fcports
, list
) {
1133 if (fcport
->port_type
!= FCT_TARGET
)
1136 ret
= ha
->isp_ops
->target_reset(fcport
, 0);
1137 if (ret
!= QLA_SUCCESS
) {
1138 DEBUG2_3(printk("%s(%ld): bus_reset failed: "
1139 "target_reset=%d d_id=%x.\n", __func__
,
1140 vha
->host_no
, ret
, fcport
->d_id
.b24
));
1144 /* Issue marker command only when we are going to start the I/O */
1145 vha
->marker_needed
= 1;
1151 qla2x00_abort_all_cmds(scsi_qla_host_t
*vha
, int res
)
1154 unsigned long flags
;
1156 struct qla_hw_data
*ha
= vha
->hw
;
1157 struct req_que
*req
;
1159 spin_lock_irqsave(&ha
->hardware_lock
, flags
);
1160 for (que
= 0; que
< ha
->max_queues
; que
++) {
1161 req
= ha
->req_q_map
[que
];
1164 for (cnt
= 1; cnt
< MAX_OUTSTANDING_COMMANDS
; cnt
++) {
1165 sp
= req
->outstanding_cmds
[cnt
];
1166 if (sp
&& sp
->fcport
->vha
== vha
) {
1167 req
->outstanding_cmds
[cnt
] = NULL
;
1168 sp
->cmd
->result
= res
;
1169 qla2x00_sp_compl(ha
, sp
);
1173 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
1177 qla2xxx_slave_alloc(struct scsi_device
*sdev
)
1179 struct fc_rport
*rport
= starget_to_rport(scsi_target(sdev
));
1181 if (!rport
|| fc_remote_port_chkready(rport
))
1184 sdev
->hostdata
= *(fc_port_t
**)rport
->dd_data
;
1190 qla2xxx_slave_configure(struct scsi_device
*sdev
)
1192 scsi_qla_host_t
*vha
= shost_priv(sdev
->host
);
1193 struct qla_hw_data
*ha
= vha
->hw
;
1194 struct fc_rport
*rport
= starget_to_rport(sdev
->sdev_target
);
1195 struct req_que
*req
= ha
->req_q_map
[vha
->req_ques
[0]];
1197 if (sdev
->tagged_supported
)
1198 scsi_activate_tcq(sdev
, req
->max_q_depth
);
1200 scsi_deactivate_tcq(sdev
, req
->max_q_depth
);
1202 rport
->dev_loss_tmo
= ha
->port_down_retry_count
;
1208 qla2xxx_slave_destroy(struct scsi_device
*sdev
)
1210 sdev
->hostdata
= NULL
;
1214 qla2x00_change_queue_depth(struct scsi_device
*sdev
, int qdepth
)
1216 scsi_adjust_queue_depth(sdev
, scsi_get_tag_type(sdev
), qdepth
);
1217 return sdev
->queue_depth
;
1221 qla2x00_change_queue_type(struct scsi_device
*sdev
, int tag_type
)
1223 if (sdev
->tagged_supported
) {
1224 scsi_set_tag_type(sdev
, tag_type
);
1226 scsi_activate_tcq(sdev
, sdev
->queue_depth
);
1228 scsi_deactivate_tcq(sdev
, sdev
->queue_depth
);
1236 * qla2x00_config_dma_addressing() - Configure OS DMA addressing method.
1239 * At exit, the @ha's flags.enable_64bit_addressing set to indicated
1240 * supported addressing method.
1243 qla2x00_config_dma_addressing(struct qla_hw_data
*ha
)
1245 /* Assume a 32bit DMA mask. */
1246 ha
->flags
.enable_64bit_addressing
= 0;
1248 if (!dma_set_mask(&ha
->pdev
->dev
, DMA_64BIT_MASK
)) {
1249 /* Any upper-dword bits set? */
1250 if (MSD(dma_get_required_mask(&ha
->pdev
->dev
)) &&
1251 !pci_set_consistent_dma_mask(ha
->pdev
, DMA_64BIT_MASK
)) {
1252 /* Ok, a 64bit DMA mask is applicable. */
1253 ha
->flags
.enable_64bit_addressing
= 1;
1254 ha
->isp_ops
->calc_req_entries
= qla2x00_calc_iocbs_64
;
1255 ha
->isp_ops
->build_iocbs
= qla2x00_build_scsi_iocbs_64
;
1260 dma_set_mask(&ha
->pdev
->dev
, DMA_32BIT_MASK
);
1261 pci_set_consistent_dma_mask(ha
->pdev
, DMA_32BIT_MASK
);
1265 qla2x00_enable_intrs(struct qla_hw_data
*ha
)
1267 unsigned long flags
= 0;
1268 struct device_reg_2xxx __iomem
*reg
= &ha
->iobase
->isp
;
1270 spin_lock_irqsave(&ha
->hardware_lock
, flags
);
1271 ha
->interrupts_on
= 1;
1272 /* enable risc and host interrupts */
1273 WRT_REG_WORD(®
->ictrl
, ICR_EN_INT
| ICR_EN_RISC
);
1274 RD_REG_WORD(®
->ictrl
);
1275 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
1280 qla2x00_disable_intrs(struct qla_hw_data
*ha
)
1282 unsigned long flags
= 0;
1283 struct device_reg_2xxx __iomem
*reg
= &ha
->iobase
->isp
;
1285 spin_lock_irqsave(&ha
->hardware_lock
, flags
);
1286 ha
->interrupts_on
= 0;
1287 /* disable risc and host interrupts */
1288 WRT_REG_WORD(®
->ictrl
, 0);
1289 RD_REG_WORD(®
->ictrl
);
1290 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
1294 qla24xx_enable_intrs(struct qla_hw_data
*ha
)
1296 unsigned long flags
= 0;
1297 struct device_reg_24xx __iomem
*reg
= &ha
->iobase
->isp24
;
1299 spin_lock_irqsave(&ha
->hardware_lock
, flags
);
1300 ha
->interrupts_on
= 1;
1301 WRT_REG_DWORD(®
->ictrl
, ICRX_EN_RISC_INT
);
1302 RD_REG_DWORD(®
->ictrl
);
1303 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
1307 qla24xx_disable_intrs(struct qla_hw_data
*ha
)
1309 unsigned long flags
= 0;
1310 struct device_reg_24xx __iomem
*reg
= &ha
->iobase
->isp24
;
1312 if (IS_NOPOLLING_TYPE(ha
))
1314 spin_lock_irqsave(&ha
->hardware_lock
, flags
);
1315 ha
->interrupts_on
= 0;
1316 WRT_REG_DWORD(®
->ictrl
, 0);
1317 RD_REG_DWORD(®
->ictrl
);
1318 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
1321 static struct isp_operations qla2100_isp_ops
= {
1322 .pci_config
= qla2100_pci_config
,
1323 .reset_chip
= qla2x00_reset_chip
,
1324 .chip_diag
= qla2x00_chip_diag
,
1325 .config_rings
= qla2x00_config_rings
,
1326 .reset_adapter
= qla2x00_reset_adapter
,
1327 .nvram_config
= qla2x00_nvram_config
,
1328 .update_fw_options
= qla2x00_update_fw_options
,
1329 .load_risc
= qla2x00_load_risc
,
1330 .pci_info_str
= qla2x00_pci_info_str
,
1331 .fw_version_str
= qla2x00_fw_version_str
,
1332 .intr_handler
= qla2100_intr_handler
,
1333 .enable_intrs
= qla2x00_enable_intrs
,
1334 .disable_intrs
= qla2x00_disable_intrs
,
1335 .abort_command
= qla2x00_abort_command
,
1336 .target_reset
= qla2x00_abort_target
,
1337 .lun_reset
= qla2x00_lun_reset
,
1338 .fabric_login
= qla2x00_login_fabric
,
1339 .fabric_logout
= qla2x00_fabric_logout
,
1340 .calc_req_entries
= qla2x00_calc_iocbs_32
,
1341 .build_iocbs
= qla2x00_build_scsi_iocbs_32
,
1342 .prep_ms_iocb
= qla2x00_prep_ms_iocb
,
1343 .prep_ms_fdmi_iocb
= qla2x00_prep_ms_fdmi_iocb
,
1344 .read_nvram
= qla2x00_read_nvram_data
,
1345 .write_nvram
= qla2x00_write_nvram_data
,
1346 .fw_dump
= qla2100_fw_dump
,
1349 .beacon_blink
= NULL
,
1350 .read_optrom
= qla2x00_read_optrom_data
,
1351 .write_optrom
= qla2x00_write_optrom_data
,
1352 .get_flash_version
= qla2x00_get_flash_version
,
1353 .start_scsi
= qla2x00_start_scsi
,
1354 .wrt_req_reg
= NULL
,
1355 .wrt_rsp_reg
= NULL
,
1359 static struct isp_operations qla2300_isp_ops
= {
1360 .pci_config
= qla2300_pci_config
,
1361 .reset_chip
= qla2x00_reset_chip
,
1362 .chip_diag
= qla2x00_chip_diag
,
1363 .config_rings
= qla2x00_config_rings
,
1364 .reset_adapter
= qla2x00_reset_adapter
,
1365 .nvram_config
= qla2x00_nvram_config
,
1366 .update_fw_options
= qla2x00_update_fw_options
,
1367 .load_risc
= qla2x00_load_risc
,
1368 .pci_info_str
= qla2x00_pci_info_str
,
1369 .fw_version_str
= qla2x00_fw_version_str
,
1370 .intr_handler
= qla2300_intr_handler
,
1371 .enable_intrs
= qla2x00_enable_intrs
,
1372 .disable_intrs
= qla2x00_disable_intrs
,
1373 .abort_command
= qla2x00_abort_command
,
1374 .target_reset
= qla2x00_abort_target
,
1375 .lun_reset
= qla2x00_lun_reset
,
1376 .fabric_login
= qla2x00_login_fabric
,
1377 .fabric_logout
= qla2x00_fabric_logout
,
1378 .calc_req_entries
= qla2x00_calc_iocbs_32
,
1379 .build_iocbs
= qla2x00_build_scsi_iocbs_32
,
1380 .prep_ms_iocb
= qla2x00_prep_ms_iocb
,
1381 .prep_ms_fdmi_iocb
= qla2x00_prep_ms_fdmi_iocb
,
1382 .read_nvram
= qla2x00_read_nvram_data
,
1383 .write_nvram
= qla2x00_write_nvram_data
,
1384 .fw_dump
= qla2300_fw_dump
,
1385 .beacon_on
= qla2x00_beacon_on
,
1386 .beacon_off
= qla2x00_beacon_off
,
1387 .beacon_blink
= qla2x00_beacon_blink
,
1388 .read_optrom
= qla2x00_read_optrom_data
,
1389 .write_optrom
= qla2x00_write_optrom_data
,
1390 .get_flash_version
= qla2x00_get_flash_version
,
1391 .start_scsi
= qla2x00_start_scsi
,
1392 .wrt_req_reg
= NULL
,
1393 .wrt_rsp_reg
= NULL
,
1397 static struct isp_operations qla24xx_isp_ops
= {
1398 .pci_config
= qla24xx_pci_config
,
1399 .reset_chip
= qla24xx_reset_chip
,
1400 .chip_diag
= qla24xx_chip_diag
,
1401 .config_rings
= qla24xx_config_rings
,
1402 .reset_adapter
= qla24xx_reset_adapter
,
1403 .nvram_config
= qla24xx_nvram_config
,
1404 .update_fw_options
= qla24xx_update_fw_options
,
1405 .load_risc
= qla24xx_load_risc
,
1406 .pci_info_str
= qla24xx_pci_info_str
,
1407 .fw_version_str
= qla24xx_fw_version_str
,
1408 .intr_handler
= qla24xx_intr_handler
,
1409 .enable_intrs
= qla24xx_enable_intrs
,
1410 .disable_intrs
= qla24xx_disable_intrs
,
1411 .abort_command
= qla24xx_abort_command
,
1412 .target_reset
= qla24xx_abort_target
,
1413 .lun_reset
= qla24xx_lun_reset
,
1414 .fabric_login
= qla24xx_login_fabric
,
1415 .fabric_logout
= qla24xx_fabric_logout
,
1416 .calc_req_entries
= NULL
,
1417 .build_iocbs
= NULL
,
1418 .prep_ms_iocb
= qla24xx_prep_ms_iocb
,
1419 .prep_ms_fdmi_iocb
= qla24xx_prep_ms_fdmi_iocb
,
1420 .read_nvram
= qla24xx_read_nvram_data
,
1421 .write_nvram
= qla24xx_write_nvram_data
,
1422 .fw_dump
= qla24xx_fw_dump
,
1423 .beacon_on
= qla24xx_beacon_on
,
1424 .beacon_off
= qla24xx_beacon_off
,
1425 .beacon_blink
= qla24xx_beacon_blink
,
1426 .read_optrom
= qla24xx_read_optrom_data
,
1427 .write_optrom
= qla24xx_write_optrom_data
,
1428 .get_flash_version
= qla24xx_get_flash_version
,
1429 .start_scsi
= qla24xx_start_scsi
,
1430 .wrt_req_reg
= qla24xx_wrt_req_reg
,
1431 .wrt_rsp_reg
= qla24xx_wrt_rsp_reg
,
1432 .rd_req_reg
= qla24xx_rd_req_reg
,
1435 static struct isp_operations qla25xx_isp_ops
= {
1436 .pci_config
= qla25xx_pci_config
,
1437 .reset_chip
= qla24xx_reset_chip
,
1438 .chip_diag
= qla24xx_chip_diag
,
1439 .config_rings
= qla24xx_config_rings
,
1440 .reset_adapter
= qla24xx_reset_adapter
,
1441 .nvram_config
= qla24xx_nvram_config
,
1442 .update_fw_options
= qla24xx_update_fw_options
,
1443 .load_risc
= qla24xx_load_risc
,
1444 .pci_info_str
= qla24xx_pci_info_str
,
1445 .fw_version_str
= qla24xx_fw_version_str
,
1446 .intr_handler
= qla24xx_intr_handler
,
1447 .enable_intrs
= qla24xx_enable_intrs
,
1448 .disable_intrs
= qla24xx_disable_intrs
,
1449 .abort_command
= qla24xx_abort_command
,
1450 .target_reset
= qla24xx_abort_target
,
1451 .lun_reset
= qla24xx_lun_reset
,
1452 .fabric_login
= qla24xx_login_fabric
,
1453 .fabric_logout
= qla24xx_fabric_logout
,
1454 .calc_req_entries
= NULL
,
1455 .build_iocbs
= NULL
,
1456 .prep_ms_iocb
= qla24xx_prep_ms_iocb
,
1457 .prep_ms_fdmi_iocb
= qla24xx_prep_ms_fdmi_iocb
,
1458 .read_nvram
= qla25xx_read_nvram_data
,
1459 .write_nvram
= qla25xx_write_nvram_data
,
1460 .fw_dump
= qla25xx_fw_dump
,
1461 .beacon_on
= qla24xx_beacon_on
,
1462 .beacon_off
= qla24xx_beacon_off
,
1463 .beacon_blink
= qla24xx_beacon_blink
,
1464 .read_optrom
= qla25xx_read_optrom_data
,
1465 .write_optrom
= qla24xx_write_optrom_data
,
1466 .get_flash_version
= qla24xx_get_flash_version
,
1467 .start_scsi
= qla24xx_start_scsi
,
1468 .wrt_req_reg
= qla24xx_wrt_req_reg
,
1469 .wrt_rsp_reg
= qla24xx_wrt_rsp_reg
,
1470 .rd_req_reg
= qla24xx_rd_req_reg
,
1473 static struct isp_operations qla81xx_isp_ops
= {
1474 .pci_config
= qla25xx_pci_config
,
1475 .reset_chip
= qla24xx_reset_chip
,
1476 .chip_diag
= qla24xx_chip_diag
,
1477 .config_rings
= qla24xx_config_rings
,
1478 .reset_adapter
= qla24xx_reset_adapter
,
1479 .nvram_config
= qla81xx_nvram_config
,
1480 .update_fw_options
= qla81xx_update_fw_options
,
1481 .load_risc
= qla81xx_load_risc
,
1482 .pci_info_str
= qla24xx_pci_info_str
,
1483 .fw_version_str
= qla24xx_fw_version_str
,
1484 .intr_handler
= qla24xx_intr_handler
,
1485 .enable_intrs
= qla24xx_enable_intrs
,
1486 .disable_intrs
= qla24xx_disable_intrs
,
1487 .abort_command
= qla24xx_abort_command
,
1488 .target_reset
= qla24xx_abort_target
,
1489 .lun_reset
= qla24xx_lun_reset
,
1490 .fabric_login
= qla24xx_login_fabric
,
1491 .fabric_logout
= qla24xx_fabric_logout
,
1492 .calc_req_entries
= NULL
,
1493 .build_iocbs
= NULL
,
1494 .prep_ms_iocb
= qla24xx_prep_ms_iocb
,
1495 .prep_ms_fdmi_iocb
= qla24xx_prep_ms_fdmi_iocb
,
1496 .read_nvram
= qla25xx_read_nvram_data
,
1497 .write_nvram
= qla25xx_write_nvram_data
,
1498 .fw_dump
= qla81xx_fw_dump
,
1499 .beacon_on
= qla24xx_beacon_on
,
1500 .beacon_off
= qla24xx_beacon_off
,
1501 .beacon_blink
= qla24xx_beacon_blink
,
1502 .read_optrom
= qla25xx_read_optrom_data
,
1503 .write_optrom
= qla24xx_write_optrom_data
,
1504 .get_flash_version
= qla24xx_get_flash_version
,
1505 .start_scsi
= qla24xx_start_scsi
,
1506 .wrt_req_reg
= qla24xx_wrt_req_reg
,
1507 .wrt_rsp_reg
= qla24xx_wrt_rsp_reg
,
1508 .rd_req_reg
= qla24xx_rd_req_reg
,
1512 qla2x00_set_isp_flags(struct qla_hw_data
*ha
)
1514 ha
->device_type
= DT_EXTENDED_IDS
;
1515 switch (ha
->pdev
->device
) {
1516 case PCI_DEVICE_ID_QLOGIC_ISP2100
:
1517 ha
->device_type
|= DT_ISP2100
;
1518 ha
->device_type
&= ~DT_EXTENDED_IDS
;
1519 ha
->fw_srisc_address
= RISC_START_ADDRESS_2100
;
1521 case PCI_DEVICE_ID_QLOGIC_ISP2200
:
1522 ha
->device_type
|= DT_ISP2200
;
1523 ha
->device_type
&= ~DT_EXTENDED_IDS
;
1524 ha
->fw_srisc_address
= RISC_START_ADDRESS_2100
;
1526 case PCI_DEVICE_ID_QLOGIC_ISP2300
:
1527 ha
->device_type
|= DT_ISP2300
;
1528 ha
->device_type
|= DT_ZIO_SUPPORTED
;
1529 ha
->fw_srisc_address
= RISC_START_ADDRESS_2300
;
1531 case PCI_DEVICE_ID_QLOGIC_ISP2312
:
1532 ha
->device_type
|= DT_ISP2312
;
1533 ha
->device_type
|= DT_ZIO_SUPPORTED
;
1534 ha
->fw_srisc_address
= RISC_START_ADDRESS_2300
;
1536 case PCI_DEVICE_ID_QLOGIC_ISP2322
:
1537 ha
->device_type
|= DT_ISP2322
;
1538 ha
->device_type
|= DT_ZIO_SUPPORTED
;
1539 if (ha
->pdev
->subsystem_vendor
== 0x1028 &&
1540 ha
->pdev
->subsystem_device
== 0x0170)
1541 ha
->device_type
|= DT_OEM_001
;
1542 ha
->fw_srisc_address
= RISC_START_ADDRESS_2300
;
1544 case PCI_DEVICE_ID_QLOGIC_ISP6312
:
1545 ha
->device_type
|= DT_ISP6312
;
1546 ha
->fw_srisc_address
= RISC_START_ADDRESS_2300
;
1548 case PCI_DEVICE_ID_QLOGIC_ISP6322
:
1549 ha
->device_type
|= DT_ISP6322
;
1550 ha
->fw_srisc_address
= RISC_START_ADDRESS_2300
;
1552 case PCI_DEVICE_ID_QLOGIC_ISP2422
:
1553 ha
->device_type
|= DT_ISP2422
;
1554 ha
->device_type
|= DT_ZIO_SUPPORTED
;
1555 ha
->device_type
|= DT_FWI2
;
1556 ha
->device_type
|= DT_IIDMA
;
1557 ha
->fw_srisc_address
= RISC_START_ADDRESS_2400
;
1559 case PCI_DEVICE_ID_QLOGIC_ISP2432
:
1560 ha
->device_type
|= DT_ISP2432
;
1561 ha
->device_type
|= DT_ZIO_SUPPORTED
;
1562 ha
->device_type
|= DT_FWI2
;
1563 ha
->device_type
|= DT_IIDMA
;
1564 ha
->fw_srisc_address
= RISC_START_ADDRESS_2400
;
1566 case PCI_DEVICE_ID_QLOGIC_ISP8432
:
1567 ha
->device_type
|= DT_ISP8432
;
1568 ha
->device_type
|= DT_ZIO_SUPPORTED
;
1569 ha
->device_type
|= DT_FWI2
;
1570 ha
->device_type
|= DT_IIDMA
;
1571 ha
->fw_srisc_address
= RISC_START_ADDRESS_2400
;
1573 case PCI_DEVICE_ID_QLOGIC_ISP5422
:
1574 ha
->device_type
|= DT_ISP5422
;
1575 ha
->device_type
|= DT_FWI2
;
1576 ha
->fw_srisc_address
= RISC_START_ADDRESS_2400
;
1578 case PCI_DEVICE_ID_QLOGIC_ISP5432
:
1579 ha
->device_type
|= DT_ISP5432
;
1580 ha
->device_type
|= DT_FWI2
;
1581 ha
->fw_srisc_address
= RISC_START_ADDRESS_2400
;
1583 case PCI_DEVICE_ID_QLOGIC_ISP2532
:
1584 ha
->device_type
|= DT_ISP2532
;
1585 ha
->device_type
|= DT_ZIO_SUPPORTED
;
1586 ha
->device_type
|= DT_FWI2
;
1587 ha
->device_type
|= DT_IIDMA
;
1588 ha
->fw_srisc_address
= RISC_START_ADDRESS_2400
;
1590 case PCI_DEVICE_ID_QLOGIC_ISP8001
:
1591 ha
->device_type
|= DT_ISP8001
;
1592 ha
->device_type
|= DT_ZIO_SUPPORTED
;
1593 ha
->device_type
|= DT_FWI2
;
1594 ha
->device_type
|= DT_IIDMA
;
1595 ha
->fw_srisc_address
= RISC_START_ADDRESS_2400
;
1601 qla2x00_iospace_config(struct qla_hw_data
*ha
)
1603 resource_size_t pio
;
1606 if (pci_request_selected_regions(ha
->pdev
, ha
->bars
,
1607 QLA2XXX_DRIVER_NAME
)) {
1608 qla_printk(KERN_WARNING
, ha
,
1609 "Failed to reserve PIO/MMIO regions (%s)\n",
1610 pci_name(ha
->pdev
));
1612 goto iospace_error_exit
;
1614 if (!(ha
->bars
& 1))
1617 /* We only need PIO for Flash operations on ISP2312 v2 chips. */
1618 pio
= pci_resource_start(ha
->pdev
, 0);
1619 if (pci_resource_flags(ha
->pdev
, 0) & IORESOURCE_IO
) {
1620 if (pci_resource_len(ha
->pdev
, 0) < MIN_IOBASE_LEN
) {
1621 qla_printk(KERN_WARNING
, ha
,
1622 "Invalid PCI I/O region size (%s)...\n",
1623 pci_name(ha
->pdev
));
1627 qla_printk(KERN_WARNING
, ha
,
1628 "region #0 not a PIO resource (%s)...\n",
1629 pci_name(ha
->pdev
));
1632 ha
->pio_address
= pio
;
1635 /* Use MMIO operations for all accesses. */
1636 if (!(pci_resource_flags(ha
->pdev
, 1) & IORESOURCE_MEM
)) {
1637 qla_printk(KERN_ERR
, ha
,
1638 "region #1 not an MMIO resource (%s), aborting\n",
1639 pci_name(ha
->pdev
));
1640 goto iospace_error_exit
;
1642 if (pci_resource_len(ha
->pdev
, 1) < MIN_IOBASE_LEN
) {
1643 qla_printk(KERN_ERR
, ha
,
1644 "Invalid PCI mem region size (%s), aborting\n",
1645 pci_name(ha
->pdev
));
1646 goto iospace_error_exit
;
1649 ha
->iobase
= ioremap(pci_resource_start(ha
->pdev
, 1), MIN_IOBASE_LEN
);
1651 qla_printk(KERN_ERR
, ha
,
1652 "cannot remap MMIO (%s), aborting\n", pci_name(ha
->pdev
));
1654 goto iospace_error_exit
;
1657 /* Determine queue resources */
1659 if (ql2xmaxqueues
<= 1 || (!IS_QLA25XX(ha
) && !IS_QLA81XX(ha
)))
1661 ha
->mqiobase
= ioremap(pci_resource_start(ha
->pdev
, 3),
1662 pci_resource_len(ha
->pdev
, 3));
1664 /* Read MSIX vector size of the board */
1665 pci_read_config_word(ha
->pdev
, QLA_PCI_MSIX_CONTROL
, &msix
);
1666 ha
->msix_count
= msix
;
1667 /* Max queues are bounded by available msix vectors */
1668 /* queue 0 uses two msix vectors */
1669 if (ha
->msix_count
- 1 < ql2xmaxqueues
)
1670 ha
->max_queues
= ha
->msix_count
- 1;
1671 else if (ql2xmaxqueues
> QLA_MQ_SIZE
)
1672 ha
->max_queues
= QLA_MQ_SIZE
;
1674 ha
->max_queues
= ql2xmaxqueues
;
1675 qla_printk(KERN_INFO
, ha
,
1676 "MSI-X vector count: %d\n", msix
);
1680 ha
->msix_count
= ha
->max_queues
+ 1;
1688 qla2xxx_scan_start(struct Scsi_Host
*shost
)
1690 scsi_qla_host_t
*vha
= shost_priv(shost
);
1692 set_bit(LOOP_RESYNC_NEEDED
, &vha
->dpc_flags
);
1693 set_bit(LOCAL_LOOP_UPDATE
, &vha
->dpc_flags
);
1694 set_bit(RSCN_UPDATE
, &vha
->dpc_flags
);
1695 set_bit(NPIV_CONFIG_NEEDED
, &vha
->dpc_flags
);
1699 qla2xxx_scan_finished(struct Scsi_Host
*shost
, unsigned long time
)
1701 scsi_qla_host_t
*vha
= shost_priv(shost
);
1705 if (time
> vha
->hw
->loop_reset_delay
* HZ
)
1708 return atomic_read(&vha
->loop_state
) == LOOP_READY
;
1712 * PCI driver interface
1714 static int __devinit
1715 qla2x00_probe_one(struct pci_dev
*pdev
, const struct pci_device_id
*id
)
1718 struct Scsi_Host
*host
;
1719 scsi_qla_host_t
*base_vha
= NULL
;
1720 struct qla_hw_data
*ha
;
1723 struct scsi_host_template
*sht
;
1724 int bars
, max_id
, mem_only
= 0;
1725 uint16_t req_length
= 0, rsp_length
= 0;
1726 struct req_que
*req
= NULL
;
1727 struct rsp_que
*rsp
= NULL
;
1729 bars
= pci_select_bars(pdev
, IORESOURCE_MEM
| IORESOURCE_IO
);
1730 sht
= &qla2x00_driver_template
;
1731 if (pdev
->device
== PCI_DEVICE_ID_QLOGIC_ISP2422
||
1732 pdev
->device
== PCI_DEVICE_ID_QLOGIC_ISP2432
||
1733 pdev
->device
== PCI_DEVICE_ID_QLOGIC_ISP8432
||
1734 pdev
->device
== PCI_DEVICE_ID_QLOGIC_ISP5422
||
1735 pdev
->device
== PCI_DEVICE_ID_QLOGIC_ISP5432
||
1736 pdev
->device
== PCI_DEVICE_ID_QLOGIC_ISP2532
||
1737 pdev
->device
== PCI_DEVICE_ID_QLOGIC_ISP8001
) {
1738 bars
= pci_select_bars(pdev
, IORESOURCE_MEM
);
1739 sht
= &qla24xx_driver_template
;
1744 if (pci_enable_device_mem(pdev
))
1747 if (pci_enable_device(pdev
))
1751 /* This may fail but that's ok */
1752 pci_enable_pcie_error_reporting(pdev
);
1754 ha
= kzalloc(sizeof(struct qla_hw_data
), GFP_KERNEL
);
1756 DEBUG(printk("Unable to allocate memory for ha\n"));
1761 /* Clear our data area */
1763 ha
->mem_only
= mem_only
;
1764 spin_lock_init(&ha
->hardware_lock
);
1766 /* Set ISP-type information. */
1767 qla2x00_set_isp_flags(ha
);
1768 /* Configure PCI I/O space */
1769 ret
= qla2x00_iospace_config(ha
);
1771 goto probe_hw_failed
;
1773 qla_printk(KERN_INFO
, ha
,
1774 "Found an ISP%04X, irq %d, iobase 0x%p\n", pdev
->device
, pdev
->irq
,
1777 ha
->prev_topology
= 0;
1778 ha
->init_cb_size
= sizeof(init_cb_t
);
1779 ha
->link_data_rate
= PORT_SPEED_UNKNOWN
;
1780 ha
->optrom_size
= OPTROM_SIZE_2300
;
1782 /* Assign ISP specific operations. */
1783 max_id
= MAX_TARGETS_2200
;
1784 if (IS_QLA2100(ha
)) {
1785 max_id
= MAX_TARGETS_2100
;
1786 ha
->mbx_count
= MAILBOX_REGISTER_COUNT_2100
;
1787 req_length
= REQUEST_ENTRY_CNT_2100
;
1788 rsp_length
= RESPONSE_ENTRY_CNT_2100
;
1789 ha
->max_loop_id
= SNS_LAST_LOOP_ID_2100
;
1790 ha
->gid_list_info_size
= 4;
1791 ha
->flash_conf_off
= ~0;
1792 ha
->flash_data_off
= ~0;
1793 ha
->nvram_conf_off
= ~0;
1794 ha
->nvram_data_off
= ~0;
1795 ha
->isp_ops
= &qla2100_isp_ops
;
1796 } else if (IS_QLA2200(ha
)) {
1797 ha
->mbx_count
= MAILBOX_REGISTER_COUNT
;
1798 req_length
= REQUEST_ENTRY_CNT_2200
;
1799 rsp_length
= RESPONSE_ENTRY_CNT_2100
;
1800 ha
->max_loop_id
= SNS_LAST_LOOP_ID_2100
;
1801 ha
->gid_list_info_size
= 4;
1802 ha
->flash_conf_off
= ~0;
1803 ha
->flash_data_off
= ~0;
1804 ha
->nvram_conf_off
= ~0;
1805 ha
->nvram_data_off
= ~0;
1806 ha
->isp_ops
= &qla2100_isp_ops
;
1807 } else if (IS_QLA23XX(ha
)) {
1808 ha
->mbx_count
= MAILBOX_REGISTER_COUNT
;
1809 req_length
= REQUEST_ENTRY_CNT_2200
;
1810 rsp_length
= RESPONSE_ENTRY_CNT_2300
;
1811 ha
->max_loop_id
= SNS_LAST_LOOP_ID_2300
;
1812 ha
->gid_list_info_size
= 6;
1813 if (IS_QLA2322(ha
) || IS_QLA6322(ha
))
1814 ha
->optrom_size
= OPTROM_SIZE_2322
;
1815 ha
->flash_conf_off
= ~0;
1816 ha
->flash_data_off
= ~0;
1817 ha
->nvram_conf_off
= ~0;
1818 ha
->nvram_data_off
= ~0;
1819 ha
->isp_ops
= &qla2300_isp_ops
;
1820 } else if (IS_QLA24XX_TYPE(ha
)) {
1821 ha
->mbx_count
= MAILBOX_REGISTER_COUNT
;
1822 req_length
= REQUEST_ENTRY_CNT_24XX
;
1823 rsp_length
= RESPONSE_ENTRY_CNT_2300
;
1824 ha
->max_loop_id
= SNS_LAST_LOOP_ID_2300
;
1825 ha
->init_cb_size
= sizeof(struct mid_init_cb_24xx
);
1826 ha
->gid_list_info_size
= 8;
1827 ha
->optrom_size
= OPTROM_SIZE_24XX
;
1828 ha
->nvram_npiv_size
= QLA_MAX_VPORTS_QLA24XX
;
1829 ha
->isp_ops
= &qla24xx_isp_ops
;
1830 ha
->flash_conf_off
= FARX_ACCESS_FLASH_CONF
;
1831 ha
->flash_data_off
= FARX_ACCESS_FLASH_DATA
;
1832 ha
->nvram_conf_off
= FARX_ACCESS_NVRAM_CONF
;
1833 ha
->nvram_data_off
= FARX_ACCESS_NVRAM_DATA
;
1834 } else if (IS_QLA25XX(ha
)) {
1835 ha
->mbx_count
= MAILBOX_REGISTER_COUNT
;
1836 req_length
= REQUEST_ENTRY_CNT_24XX
;
1837 rsp_length
= RESPONSE_ENTRY_CNT_2300
;
1838 ha
->max_loop_id
= SNS_LAST_LOOP_ID_2300
;
1839 ha
->init_cb_size
= sizeof(struct mid_init_cb_24xx
);
1840 ha
->gid_list_info_size
= 8;
1841 ha
->optrom_size
= OPTROM_SIZE_25XX
;
1842 ha
->nvram_npiv_size
= QLA_MAX_VPORTS_QLA25XX
;
1843 ha
->isp_ops
= &qla25xx_isp_ops
;
1844 ha
->flash_conf_off
= FARX_ACCESS_FLASH_CONF
;
1845 ha
->flash_data_off
= FARX_ACCESS_FLASH_DATA
;
1846 ha
->nvram_conf_off
= FARX_ACCESS_NVRAM_CONF
;
1847 ha
->nvram_data_off
= FARX_ACCESS_NVRAM_DATA
;
1848 } else if (IS_QLA81XX(ha
)) {
1849 ha
->mbx_count
= MAILBOX_REGISTER_COUNT
;
1850 req_length
= REQUEST_ENTRY_CNT_24XX
;
1851 rsp_length
= RESPONSE_ENTRY_CNT_2300
;
1852 ha
->max_loop_id
= SNS_LAST_LOOP_ID_2300
;
1853 ha
->init_cb_size
= sizeof(struct mid_init_cb_81xx
);
1854 ha
->gid_list_info_size
= 8;
1855 ha
->optrom_size
= OPTROM_SIZE_81XX
;
1856 ha
->isp_ops
= &qla81xx_isp_ops
;
1857 ha
->flash_conf_off
= FARX_ACCESS_FLASH_CONF_81XX
;
1858 ha
->flash_data_off
= FARX_ACCESS_FLASH_DATA_81XX
;
1859 ha
->nvram_conf_off
= ~0;
1860 ha
->nvram_data_off
= ~0;
1863 mutex_init(&ha
->vport_lock
);
1864 init_completion(&ha
->mbx_cmd_comp
);
1865 complete(&ha
->mbx_cmd_comp
);
1866 init_completion(&ha
->mbx_intr_comp
);
1868 set_bit(0, (unsigned long *) ha
->vp_idx_map
);
1870 qla2x00_config_dma_addressing(ha
);
1871 ret
= qla2x00_mem_alloc(ha
, req_length
, rsp_length
, &req
, &rsp
);
1873 qla_printk(KERN_WARNING
, ha
,
1874 "[ERROR] Failed to allocate memory for adapter\n");
1876 goto probe_hw_failed
;
1879 req
->max_q_depth
= MAX_Q_DEPTH
;
1880 if (ql2xmaxqdepth
!= 0 && ql2xmaxqdepth
<= 0xffffU
)
1881 req
->max_q_depth
= ql2xmaxqdepth
;
1884 base_vha
= qla2x00_create_host(sht
, ha
);
1886 qla_printk(KERN_WARNING
, ha
,
1887 "[ERROR] Failed to allocate memory for scsi_host\n");
1890 qla2x00_mem_free(ha
);
1891 qla2x00_free_que(ha
, req
, rsp
);
1892 goto probe_hw_failed
;
1895 pci_set_drvdata(pdev
, base_vha
);
1897 host
= base_vha
->host
;
1898 base_vha
->req_ques
[0] = req
->id
;
1899 host
->can_queue
= req
->length
+ 128;
1900 if (IS_QLA2XXX_MIDTYPE(ha
))
1901 base_vha
->mgmt_svr_loop_id
= 10 + base_vha
->vp_idx
;
1903 base_vha
->mgmt_svr_loop_id
= MANAGEMENT_SERVER
+
1906 host
->sg_tablesize
= 32;
1907 host
->max_id
= max_id
;
1908 host
->this_id
= 255;
1909 host
->cmd_per_lun
= 3;
1910 host
->unique_id
= host
->host_no
;
1911 host
->max_cmd_len
= MAX_CMDSZ
;
1912 host
->max_channel
= MAX_BUSES
- 1;
1913 host
->max_lun
= MAX_LUNS
;
1914 host
->transportt
= qla2xxx_transport_template
;
1916 /* Set up the irqs */
1917 ret
= qla2x00_request_irqs(ha
, rsp
);
1919 goto probe_init_failed
;
1920 /* Alloc arrays of request and response ring ptrs */
1921 if (!qla2x00_alloc_queues(ha
)) {
1922 qla_printk(KERN_WARNING
, ha
,
1923 "[ERROR] Failed to allocate memory for queue"
1925 goto probe_init_failed
;
1927 ha
->rsp_q_map
[0] = rsp
;
1928 ha
->req_q_map
[0] = req
;
1931 ha
->isp_ops
->wrt_req_reg
= qla25xx_wrt_req_reg
;
1932 ha
->isp_ops
->wrt_rsp_reg
= qla25xx_wrt_rsp_reg
;
1933 ha
->isp_ops
->rd_req_reg
= qla25xx_rd_req_reg
;
1936 if (qla2x00_initialize_adapter(base_vha
)) {
1937 qla_printk(KERN_WARNING
, ha
,
1938 "Failed to initialize adapter\n");
1940 DEBUG2(printk("scsi(%ld): Failed to initialize adapter - "
1941 "Adapter flags %x.\n",
1942 base_vha
->host_no
, base_vha
->device_flags
));
1949 * Startup the kernel thread for this host adapter
1951 ha
->dpc_thread
= kthread_create(qla2x00_do_dpc
, ha
,
1952 "%s_dpc", base_vha
->host_str
);
1953 if (IS_ERR(ha
->dpc_thread
)) {
1954 qla_printk(KERN_WARNING
, ha
,
1955 "Unable to start DPC thread!\n");
1956 ret
= PTR_ERR(ha
->dpc_thread
);
1960 list_add_tail(&base_vha
->list
, &ha
->vp_list
);
1961 base_vha
->host
->irq
= ha
->pdev
->irq
;
1963 /* Initialized the timer */
1964 qla2x00_start_timer(base_vha
, qla2x00_timer
, WATCH_INTERVAL
);
1966 DEBUG2(printk("DEBUG: detect hba %ld at address = %p\n",
1967 base_vha
->host_no
, ha
));
1969 base_vha
->flags
.init_done
= 1;
1970 base_vha
->flags
.online
= 1;
1972 ret
= scsi_add_host(host
, &pdev
->dev
);
1976 ha
->isp_ops
->enable_intrs(ha
);
1978 scsi_scan_host(host
);
1980 qla2x00_alloc_sysfs_attr(base_vha
);
1982 qla2x00_init_host_attr(base_vha
);
1984 qla2x00_dfs_setup(base_vha
);
1986 qla_printk(KERN_INFO
, ha
, "\n"
1987 " QLogic Fibre Channel HBA Driver: %s\n"
1989 " ISP%04X: %s @ %s hdma%c, host#=%ld, fw=%s\n",
1990 qla2x00_version_str
, ha
->model_number
,
1991 ha
->model_desc
? ha
->model_desc
: "", pdev
->device
,
1992 ha
->isp_ops
->pci_info_str(base_vha
, pci_info
), pci_name(pdev
),
1993 ha
->flags
.enable_64bit_addressing
? '+' : '-', base_vha
->host_no
,
1994 ha
->isp_ops
->fw_version_str(base_vha
, fw_str
));
1999 qla2x00_free_que(ha
, req
, rsp
);
2003 qla2x00_free_device(base_vha
);
2005 scsi_host_put(base_vha
->host
);
2009 iounmap(ha
->iobase
);
2011 pci_release_selected_regions(ha
->pdev
, ha
->bars
);
2016 pci_disable_device(pdev
);
2021 qla2x00_remove_one(struct pci_dev
*pdev
)
2023 scsi_qla_host_t
*base_vha
, *vha
, *temp
;
2024 struct qla_hw_data
*ha
;
2026 base_vha
= pci_get_drvdata(pdev
);
2029 list_for_each_entry_safe(vha
, temp
, &ha
->vp_list
, list
) {
2030 if (vha
&& vha
->fc_vport
)
2031 fc_vport_terminate(vha
->fc_vport
);
2034 set_bit(UNLOADING
, &base_vha
->dpc_flags
);
2036 qla2x00_dfs_remove(base_vha
);
2038 qla84xx_put_chip(base_vha
);
2040 qla2x00_free_sysfs_attr(base_vha
);
2042 fc_remove_host(base_vha
->host
);
2044 scsi_remove_host(base_vha
->host
);
2046 qla2x00_free_device(base_vha
);
2048 scsi_host_put(base_vha
->host
);
2051 iounmap(ha
->iobase
);
2054 iounmap(ha
->mqiobase
);
2056 pci_release_selected_regions(ha
->pdev
, ha
->bars
);
2060 pci_disable_device(pdev
);
2061 pci_set_drvdata(pdev
, NULL
);
2065 qla2x00_free_device(scsi_qla_host_t
*vha
)
2067 struct qla_hw_data
*ha
= vha
->hw
;
2068 qla2x00_abort_all_cmds(vha
, DID_NO_CONNECT
<< 16);
2071 if (vha
->timer_active
)
2072 qla2x00_stop_timer(vha
);
2074 vha
->flags
.online
= 0;
2076 /* Kill the kernel thread for this host */
2077 if (ha
->dpc_thread
) {
2078 struct task_struct
*t
= ha
->dpc_thread
;
2081 * qla2xxx_wake_dpc checks for ->dpc_thread
2082 * so we need to zero it out.
2084 ha
->dpc_thread
= NULL
;
2088 if (ha
->flags
.fce_enabled
)
2089 qla2x00_disable_fce_trace(vha
, NULL
, NULL
);
2092 qla2x00_disable_eft_trace(vha
);
2094 /* Stop currently executing firmware. */
2095 qla2x00_try_to_stop_firmware(vha
);
2097 /* turn-off interrupts on the card */
2098 if (ha
->interrupts_on
)
2099 ha
->isp_ops
->disable_intrs(ha
);
2101 qla2x00_free_irqs(vha
);
2103 qla2x00_mem_free(ha
);
2105 qla2x00_free_queues(ha
);
2109 qla2x00_schedule_rport_del(struct scsi_qla_host
*vha
, fc_port_t
*fcport
,
2112 struct fc_rport
*rport
;
2117 rport
= fcport
->rport
;
2119 spin_lock_irq(vha
->host
->host_lock
);
2120 fcport
->drport
= rport
;
2121 spin_unlock_irq(vha
->host
->host_lock
);
2122 set_bit(FCPORT_UPDATE_NEEDED
, &vha
->dpc_flags
);
2123 qla2xxx_wake_dpc(vha
);
2125 fc_remote_port_delete(rport
);
2129 * qla2x00_mark_device_lost Updates fcport state when device goes offline.
2131 * Input: ha = adapter block pointer. fcport = port structure pointer.
2137 void qla2x00_mark_device_lost(scsi_qla_host_t
*vha
, fc_port_t
*fcport
,
2138 int do_login
, int defer
)
2140 if (atomic_read(&fcport
->state
) == FCS_ONLINE
&&
2141 vha
->vp_idx
== fcport
->vp_idx
) {
2142 atomic_set(&fcport
->state
, FCS_DEVICE_LOST
);
2143 qla2x00_schedule_rport_del(vha
, fcport
, defer
);
2146 * We may need to retry the login, so don't change the state of the
2147 * port but do the retries.
2149 if (atomic_read(&fcport
->state
) != FCS_DEVICE_DEAD
)
2150 atomic_set(&fcport
->state
, FCS_DEVICE_LOST
);
2155 if (fcport
->login_retry
== 0) {
2156 fcport
->login_retry
= vha
->hw
->login_retry_count
;
2157 set_bit(RELOGIN_NEEDED
, &vha
->dpc_flags
);
2159 DEBUG(printk("scsi(%ld): Port login retry: "
2160 "%02x%02x%02x%02x%02x%02x%02x%02x, "
2161 "id = 0x%04x retry cnt=%d\n",
2163 fcport
->port_name
[0],
2164 fcport
->port_name
[1],
2165 fcport
->port_name
[2],
2166 fcport
->port_name
[3],
2167 fcport
->port_name
[4],
2168 fcport
->port_name
[5],
2169 fcport
->port_name
[6],
2170 fcport
->port_name
[7],
2172 fcport
->login_retry
));
2177 * qla2x00_mark_all_devices_lost
2178 * Updates fcport state when device goes offline.
2181 * ha = adapter block pointer.
2182 * fcport = port structure pointer.
2190 qla2x00_mark_all_devices_lost(scsi_qla_host_t
*vha
, int defer
)
2194 list_for_each_entry(fcport
, &vha
->vp_fcports
, list
) {
2195 if (vha
->vp_idx
!= fcport
->vp_idx
)
2198 * No point in marking the device as lost, if the device is
2201 if (atomic_read(&fcport
->state
) == FCS_DEVICE_DEAD
)
2203 if (atomic_read(&fcport
->state
) == FCS_ONLINE
) {
2204 atomic_set(&fcport
->state
, FCS_DEVICE_LOST
);
2205 qla2x00_schedule_rport_del(vha
, fcport
, defer
);
2207 atomic_set(&fcport
->state
, FCS_DEVICE_LOST
);
2213 * Allocates adapter memory.
2220 qla2x00_mem_alloc(struct qla_hw_data
*ha
, uint16_t req_len
, uint16_t rsp_len
,
2221 struct req_que
**req
, struct rsp_que
**rsp
)
2225 ha
->init_cb_size
= sizeof(init_cb_t
);
2226 if (IS_QLA2XXX_MIDTYPE(ha
))
2227 ha
->init_cb_size
= sizeof(struct mid_init_cb_24xx
);
2229 ha
->init_cb
= dma_alloc_coherent(&ha
->pdev
->dev
, ha
->init_cb_size
,
2230 &ha
->init_cb_dma
, GFP_KERNEL
);
2234 ha
->gid_list
= dma_alloc_coherent(&ha
->pdev
->dev
, GID_LIST_SIZE
,
2235 &ha
->gid_list_dma
, GFP_KERNEL
);
2237 goto fail_free_init_cb
;
2239 ha
->srb_mempool
= mempool_create_slab_pool(SRB_MIN_REQ
, srb_cachep
);
2240 if (!ha
->srb_mempool
)
2241 goto fail_free_gid_list
;
2243 /* Get memory for cached NVRAM */
2244 ha
->nvram
= kzalloc(MAX_NVRAM_SIZE
, GFP_KERNEL
);
2246 goto fail_free_srb_mempool
;
2248 snprintf(name
, sizeof(name
), "%s_%d", QLA2XXX_DRIVER_NAME
,
2250 ha
->s_dma_pool
= dma_pool_create(name
, &ha
->pdev
->dev
,
2251 DMA_POOL_SIZE
, 8, 0);
2252 if (!ha
->s_dma_pool
)
2253 goto fail_free_nvram
;
2255 /* Allocate memory for SNS commands */
2256 if (IS_QLA2100(ha
) || IS_QLA2200(ha
)) {
2257 /* Get consistent memory allocated for SNS commands */
2258 ha
->sns_cmd
= dma_alloc_coherent(&ha
->pdev
->dev
,
2259 sizeof(struct sns_cmd_pkt
), &ha
->sns_cmd_dma
, GFP_KERNEL
);
2263 /* Get consistent memory allocated for MS IOCB */
2264 ha
->ms_iocb
= dma_pool_alloc(ha
->s_dma_pool
, GFP_KERNEL
,
2268 /* Get consistent memory allocated for CT SNS commands */
2269 ha
->ct_sns
= dma_alloc_coherent(&ha
->pdev
->dev
,
2270 sizeof(struct ct_sns_pkt
), &ha
->ct_sns_dma
, GFP_KERNEL
);
2272 goto fail_free_ms_iocb
;
2275 /* Allocate memory for request ring */
2276 *req
= kzalloc(sizeof(struct req_que
), GFP_KERNEL
);
2278 DEBUG(printk("Unable to allocate memory for req\n"));
2281 (*req
)->length
= req_len
;
2282 (*req
)->ring
= dma_alloc_coherent(&ha
->pdev
->dev
,
2283 ((*req
)->length
+ 1) * sizeof(request_t
),
2284 &(*req
)->dma
, GFP_KERNEL
);
2285 if (!(*req
)->ring
) {
2286 DEBUG(printk("Unable to allocate memory for req_ring\n"));
2289 /* Allocate memory for response ring */
2290 *rsp
= kzalloc(sizeof(struct rsp_que
), GFP_KERNEL
);
2292 qla_printk(KERN_WARNING
, ha
,
2293 "Unable to allocate memory for rsp\n");
2297 (*rsp
)->length
= rsp_len
;
2298 (*rsp
)->ring
= dma_alloc_coherent(&ha
->pdev
->dev
,
2299 ((*rsp
)->length
+ 1) * sizeof(response_t
),
2300 &(*rsp
)->dma
, GFP_KERNEL
);
2301 if (!(*rsp
)->ring
) {
2302 qla_printk(KERN_WARNING
, ha
,
2303 "Unable to allocate memory for rsp_ring\n");
2308 /* Allocate memory for NVRAM data for vports */
2309 if (ha
->nvram_npiv_size
) {
2310 ha
->npiv_info
= kzalloc(sizeof(struct qla_npiv_entry
) *
2311 ha
->nvram_npiv_size
, GFP_KERNEL
);
2312 if (!ha
->npiv_info
) {
2313 qla_printk(KERN_WARNING
, ha
,
2314 "Unable to allocate memory for npiv info\n");
2315 goto fail_npiv_info
;
2318 ha
->npiv_info
= NULL
;
2320 INIT_LIST_HEAD(&ha
->vp_list
);
2324 dma_free_coherent(&ha
->pdev
->dev
, ((*rsp
)->length
+ 1) *
2325 sizeof(response_t
), (*rsp
)->ring
, (*rsp
)->dma
);
2326 (*rsp
)->ring
= NULL
;
2331 dma_free_coherent(&ha
->pdev
->dev
, ((*req
)->length
+ 1) *
2332 sizeof(request_t
), (*req
)->ring
, (*req
)->dma
);
2333 (*req
)->ring
= NULL
;
2338 dma_free_coherent(&ha
->pdev
->dev
, sizeof(struct ct_sns_pkt
),
2339 ha
->ct_sns
, ha
->ct_sns_dma
);
2343 dma_pool_free(ha
->s_dma_pool
, ha
->ms_iocb
, ha
->ms_iocb_dma
);
2345 ha
->ms_iocb_dma
= 0;
2347 dma_pool_destroy(ha
->s_dma_pool
);
2348 ha
->s_dma_pool
= NULL
;
2352 fail_free_srb_mempool
:
2353 mempool_destroy(ha
->srb_mempool
);
2354 ha
->srb_mempool
= NULL
;
2356 dma_free_coherent(&ha
->pdev
->dev
, GID_LIST_SIZE
, ha
->gid_list
,
2358 ha
->gid_list
= NULL
;
2359 ha
->gid_list_dma
= 0;
2361 dma_free_coherent(&ha
->pdev
->dev
, ha
->init_cb_size
, ha
->init_cb
,
2364 ha
->init_cb_dma
= 0;
2366 DEBUG(printk("%s: Memory allocation failure\n", __func__
));
2372 * Frees all adapter allocated memory.
2375 * ha = adapter block pointer.
2378 qla2x00_mem_free(struct qla_hw_data
*ha
)
2380 if (ha
->srb_mempool
)
2381 mempool_destroy(ha
->srb_mempool
);
2384 dma_free_coherent(&ha
->pdev
->dev
, FCE_SIZE
, ha
->fce
,
2389 dma_free_coherent(&ha
->pdev
->dev
,
2390 ntohl(ha
->fw_dump
->eft_size
), ha
->eft
, ha
->eft_dma
);
2395 dma_free_coherent(&ha
->pdev
->dev
, sizeof(struct sns_cmd_pkt
),
2396 ha
->sns_cmd
, ha
->sns_cmd_dma
);
2399 dma_free_coherent(&ha
->pdev
->dev
, sizeof(struct ct_sns_pkt
),
2400 ha
->ct_sns
, ha
->ct_sns_dma
);
2403 dma_pool_free(ha
->s_dma_pool
, ha
->sfp_data
, ha
->sfp_data_dma
);
2406 dma_pool_free(ha
->s_dma_pool
, ha
->ms_iocb
, ha
->ms_iocb_dma
);
2409 dma_pool_destroy(ha
->s_dma_pool
);
2413 dma_free_coherent(&ha
->pdev
->dev
, GID_LIST_SIZE
, ha
->gid_list
,
2418 dma_free_coherent(&ha
->pdev
->dev
, ha
->init_cb_size
,
2419 ha
->init_cb
, ha
->init_cb_dma
);
2420 vfree(ha
->optrom_buffer
);
2422 kfree(ha
->npiv_info
);
2424 ha
->srb_mempool
= NULL
;
2428 ha
->sns_cmd_dma
= 0;
2432 ha
->ms_iocb_dma
= 0;
2434 ha
->init_cb_dma
= 0;
2436 ha
->s_dma_pool
= NULL
;
2438 ha
->gid_list
= NULL
;
2439 ha
->gid_list_dma
= 0;
2443 ha
->fw_dump_reading
= 0;
2446 struct scsi_qla_host
*qla2x00_create_host(struct scsi_host_template
*sht
,
2447 struct qla_hw_data
*ha
)
2449 struct Scsi_Host
*host
;
2450 struct scsi_qla_host
*vha
= NULL
;
2452 host
= scsi_host_alloc(sht
, sizeof(scsi_qla_host_t
));
2455 "qla2xxx: Couldn't allocate host from scsi layer!\n");
2459 /* Clear our data area */
2460 vha
= shost_priv(host
);
2461 memset(vha
, 0, sizeof(scsi_qla_host_t
));
2464 vha
->host_no
= host
->host_no
;
2467 INIT_LIST_HEAD(&vha
->vp_fcports
);
2468 INIT_LIST_HEAD(&vha
->work_list
);
2469 INIT_LIST_HEAD(&vha
->list
);
2471 sprintf(vha
->host_str
, "%s_%ld", QLA2XXX_DRIVER_NAME
, vha
->host_no
);
2478 static struct qla_work_evt
*
2479 qla2x00_alloc_work(struct scsi_qla_host
*vha
, enum qla_work_type type
,
2482 struct qla_work_evt
*e
;
2484 e
= kzalloc(sizeof(struct qla_work_evt
), locked
? GFP_ATOMIC
:
2489 INIT_LIST_HEAD(&e
->list
);
2491 e
->flags
= QLA_EVT_FLAG_FREE
;
2496 qla2x00_post_work(struct scsi_qla_host
*vha
, struct qla_work_evt
*e
, int locked
)
2498 unsigned long uninitialized_var(flags
);
2499 struct qla_hw_data
*ha
= vha
->hw
;
2502 spin_lock_irqsave(&ha
->hardware_lock
, flags
);
2503 list_add_tail(&e
->list
, &vha
->work_list
);
2504 qla2xxx_wake_dpc(vha
);
2506 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
2511 qla2x00_post_aen_work(struct scsi_qla_host
*vha
, enum fc_host_event_code code
,
2514 struct qla_work_evt
*e
;
2516 e
= qla2x00_alloc_work(vha
, QLA_EVT_AEN
, 1);
2518 return QLA_FUNCTION_FAILED
;
2520 e
->u
.aen
.code
= code
;
2521 e
->u
.aen
.data
= data
;
2522 return qla2x00_post_work(vha
, e
, 1);
2526 qla2x00_do_work(struct scsi_qla_host
*vha
)
2528 struct qla_work_evt
*e
;
2529 struct qla_hw_data
*ha
= vha
->hw
;
2531 spin_lock_irq(&ha
->hardware_lock
);
2532 while (!list_empty(&vha
->work_list
)) {
2533 e
= list_entry(vha
->work_list
.next
, struct qla_work_evt
, list
);
2534 list_del_init(&e
->list
);
2535 spin_unlock_irq(&ha
->hardware_lock
);
2539 fc_host_post_event(vha
->host
, fc_get_event_number(),
2540 e
->u
.aen
.code
, e
->u
.aen
.data
);
2543 if (e
->flags
& QLA_EVT_FLAG_FREE
)
2545 spin_lock_irq(&ha
->hardware_lock
);
2547 spin_unlock_irq(&ha
->hardware_lock
);
2549 /* Relogins all the fcports of a vport
2550 * Context: dpc thread
2552 void qla2x00_relogin(struct scsi_qla_host
*vha
)
2556 uint16_t next_loopid
= 0;
2557 struct qla_hw_data
*ha
= vha
->hw
;
2559 list_for_each_entry(fcport
, &vha
->vp_fcports
, list
) {
2561 * If the port is not ONLINE then try to login
2562 * to it if we haven't run out of retries.
2564 if (atomic_read(&fcport
->state
) !=
2565 FCS_ONLINE
&& fcport
->login_retry
) {
2567 if (fcport
->flags
& FCF_FABRIC_DEVICE
) {
2568 if (fcport
->flags
& FCF_TAPE_PRESENT
)
2569 ha
->isp_ops
->fabric_logout(vha
,
2571 fcport
->d_id
.b
.domain
,
2572 fcport
->d_id
.b
.area
,
2573 fcport
->d_id
.b
.al_pa
);
2575 status
= qla2x00_fabric_login(vha
, fcport
,
2578 status
= qla2x00_local_device_login(vha
,
2581 fcport
->login_retry
--;
2582 if (status
== QLA_SUCCESS
) {
2583 fcport
->old_loop_id
= fcport
->loop_id
;
2585 DEBUG(printk("scsi(%ld): port login OK: logged "
2586 "in ID 0x%x\n", vha
->host_no
, fcport
->loop_id
));
2588 qla2x00_update_fcport(vha
, fcport
);
2590 } else if (status
== 1) {
2591 set_bit(RELOGIN_NEEDED
, &vha
->dpc_flags
);
2592 /* retry the login again */
2593 DEBUG(printk("scsi(%ld): Retrying"
2594 " %d login again loop_id 0x%x\n",
2595 vha
->host_no
, fcport
->login_retry
,
2598 fcport
->login_retry
= 0;
2601 if (fcport
->login_retry
== 0 && status
!= QLA_SUCCESS
)
2602 fcport
->loop_id
= FC_NO_LOOP_ID
;
2604 if (test_bit(LOOP_RESYNC_NEEDED
, &vha
->dpc_flags
))
2609 /**************************************************************************
2611 * This kernel thread is a task that is schedule by the interrupt handler
2612 * to perform the background processing for interrupts.
2615 * This task always run in the context of a kernel thread. It
2616 * is kick-off by the driver's detect code and starts up
2617 * up one per adapter. It immediately goes to sleep and waits for
2618 * some fibre event. When either the interrupt handler or
2619 * the timer routine detects a event it will one of the task
2620 * bits then wake us up.
2621 **************************************************************************/
2623 qla2x00_do_dpc(void *data
)
2626 scsi_qla_host_t
*base_vha
;
2627 struct qla_hw_data
*ha
;
2629 ha
= (struct qla_hw_data
*)data
;
2630 base_vha
= pci_get_drvdata(ha
->pdev
);
2632 set_user_nice(current
, -20);
2634 while (!kthread_should_stop()) {
2635 DEBUG3(printk("qla2x00: DPC handler sleeping\n"));
2637 set_current_state(TASK_INTERRUPTIBLE
);
2639 __set_current_state(TASK_RUNNING
);
2641 DEBUG3(printk("qla2x00: DPC handler waking up\n"));
2643 /* Initialization not yet finished. Don't do anything yet. */
2644 if (!base_vha
->flags
.init_done
)
2647 DEBUG3(printk("scsi(%ld): DPC handler\n", base_vha
->host_no
));
2651 if (ha
->flags
.mbox_busy
) {
2656 qla2x00_do_work(base_vha
);
2658 if (test_and_clear_bit(ISP_ABORT_NEEDED
,
2659 &base_vha
->dpc_flags
)) {
2661 DEBUG(printk("scsi(%ld): dpc: sched "
2662 "qla2x00_abort_isp ha = %p\n",
2663 base_vha
->host_no
, ha
));
2664 if (!(test_and_set_bit(ABORT_ISP_ACTIVE
,
2665 &base_vha
->dpc_flags
))) {
2667 if (qla2x00_abort_isp(base_vha
)) {
2668 /* failed. retry later */
2669 set_bit(ISP_ABORT_NEEDED
,
2670 &base_vha
->dpc_flags
);
2672 clear_bit(ABORT_ISP_ACTIVE
,
2673 &base_vha
->dpc_flags
);
2676 DEBUG(printk("scsi(%ld): dpc: qla2x00_abort_isp end\n",
2677 base_vha
->host_no
));
2680 if (test_bit(FCPORT_UPDATE_NEEDED
, &base_vha
->dpc_flags
)) {
2681 qla2x00_update_fcports(base_vha
);
2682 clear_bit(FCPORT_UPDATE_NEEDED
, &base_vha
->dpc_flags
);
2685 if (test_and_clear_bit(RESET_MARKER_NEEDED
,
2686 &base_vha
->dpc_flags
) &&
2687 (!(test_and_set_bit(RESET_ACTIVE
, &base_vha
->dpc_flags
)))) {
2689 DEBUG(printk("scsi(%ld): qla2x00_reset_marker()\n",
2690 base_vha
->host_no
));
2692 qla2x00_rst_aen(base_vha
);
2693 clear_bit(RESET_ACTIVE
, &base_vha
->dpc_flags
);
2696 /* Retry each device up to login retry count */
2697 if ((test_and_clear_bit(RELOGIN_NEEDED
,
2698 &base_vha
->dpc_flags
)) &&
2699 !test_bit(LOOP_RESYNC_NEEDED
, &base_vha
->dpc_flags
) &&
2700 atomic_read(&base_vha
->loop_state
) != LOOP_DOWN
) {
2702 DEBUG(printk("scsi(%ld): qla2x00_port_login()\n",
2703 base_vha
->host_no
));
2704 qla2x00_relogin(base_vha
);
2706 DEBUG(printk("scsi(%ld): qla2x00_port_login - end\n",
2707 base_vha
->host_no
));
2710 if (test_and_clear_bit(LOOP_RESYNC_NEEDED
,
2711 &base_vha
->dpc_flags
)) {
2713 DEBUG(printk("scsi(%ld): qla2x00_loop_resync()\n",
2714 base_vha
->host_no
));
2716 if (!(test_and_set_bit(LOOP_RESYNC_ACTIVE
,
2717 &base_vha
->dpc_flags
))) {
2719 rval
= qla2x00_loop_resync(base_vha
);
2721 clear_bit(LOOP_RESYNC_ACTIVE
,
2722 &base_vha
->dpc_flags
);
2725 DEBUG(printk("scsi(%ld): qla2x00_loop_resync - end\n",
2726 base_vha
->host_no
));
2729 if (test_bit(NPIV_CONFIG_NEEDED
, &base_vha
->dpc_flags
) &&
2730 atomic_read(&base_vha
->loop_state
) == LOOP_READY
) {
2731 clear_bit(NPIV_CONFIG_NEEDED
, &base_vha
->dpc_flags
);
2732 qla2xxx_flash_npiv_conf(base_vha
);
2735 if (!ha
->interrupts_on
)
2736 ha
->isp_ops
->enable_intrs(ha
);
2738 if (test_and_clear_bit(BEACON_BLINK_NEEDED
,
2739 &base_vha
->dpc_flags
))
2740 ha
->isp_ops
->beacon_blink(base_vha
);
2742 qla2x00_do_dpc_all_vps(base_vha
);
2745 } /* End of while(1) */
2747 DEBUG(printk("scsi(%ld): DPC handler exiting\n", base_vha
->host_no
));
2750 * Make sure that nobody tries to wake us up again.
2758 qla2xxx_wake_dpc(struct scsi_qla_host
*vha
)
2760 struct qla_hw_data
*ha
= vha
->hw
;
2761 struct task_struct
*t
= ha
->dpc_thread
;
2763 if (!test_bit(UNLOADING
, &vha
->dpc_flags
) && t
)
2769 * Processes asynchronous reset.
2772 * ha = adapter block pointer.
2775 qla2x00_rst_aen(scsi_qla_host_t
*vha
)
2777 if (vha
->flags
.online
&& !vha
->flags
.reset_active
&&
2778 !atomic_read(&vha
->loop_down_timer
) &&
2779 !(test_bit(ABORT_ISP_ACTIVE
, &vha
->dpc_flags
))) {
2781 clear_bit(RESET_MARKER_NEEDED
, &vha
->dpc_flags
);
2784 * Issue marker command only when we are going to start
2787 vha
->marker_needed
= 1;
2788 } while (!atomic_read(&vha
->loop_down_timer
) &&
2789 (test_bit(RESET_MARKER_NEEDED
, &vha
->dpc_flags
)));
2794 qla2x00_sp_free_dma(srb_t
*sp
)
2796 struct scsi_cmnd
*cmd
= sp
->cmd
;
2798 if (sp
->flags
& SRB_DMA_VALID
) {
2799 scsi_dma_unmap(cmd
);
2800 sp
->flags
&= ~SRB_DMA_VALID
;
2806 qla2x00_sp_compl(struct qla_hw_data
*ha
, srb_t
*sp
)
2808 struct scsi_cmnd
*cmd
= sp
->cmd
;
2810 qla2x00_sp_free_dma(sp
);
2812 mempool_free(sp
, ha
->srb_mempool
);
2814 cmd
->scsi_done(cmd
);
2817 /**************************************************************************
2823 * Context: Interrupt
2824 ***************************************************************************/
2826 qla2x00_timer(scsi_qla_host_t
*vha
)
2828 unsigned long cpu_flags
= 0;
2834 struct qla_hw_data
*ha
= vha
->hw
;
2835 struct req_que
*req
;
2837 * Ports - Port down timer.
2839 * Whenever, a port is in the LOST state we start decrementing its port
2840 * down timer every second until it reaches zero. Once it reaches zero
2841 * the port it marked DEAD.
2844 list_for_each_entry(fcport
, &vha
->vp_fcports
, list
) {
2845 if (fcport
->port_type
!= FCT_TARGET
)
2848 if (atomic_read(&fcport
->state
) == FCS_DEVICE_LOST
) {
2850 if (atomic_read(&fcport
->port_down_timer
) == 0)
2853 if (atomic_dec_and_test(&fcport
->port_down_timer
) != 0)
2854 atomic_set(&fcport
->state
, FCS_DEVICE_DEAD
);
2856 DEBUG(printk("scsi(%ld): fcport-%d - port retry count: "
2859 t
, atomic_read(&fcport
->port_down_timer
)));
2862 } /* End of for fcport */
2865 /* Loop down handler. */
2866 if (atomic_read(&vha
->loop_down_timer
) > 0 &&
2867 !(test_bit(ABORT_ISP_ACTIVE
, &vha
->dpc_flags
))
2868 && vha
->flags
.online
) {
2870 if (atomic_read(&vha
->loop_down_timer
) ==
2871 vha
->loop_down_abort_time
) {
2873 DEBUG(printk("scsi(%ld): Loop Down - aborting the "
2874 "queues before time expire\n",
2877 if (!IS_QLA2100(ha
) && vha
->link_down_timeout
)
2878 atomic_set(&vha
->loop_state
, LOOP_DEAD
);
2880 /* Schedule an ISP abort to return any tape commands. */
2881 /* NPIV - scan physical port only */
2883 spin_lock_irqsave(&ha
->hardware_lock
,
2885 req
= ha
->req_q_map
[0];
2887 index
< MAX_OUTSTANDING_COMMANDS
;
2891 sp
= req
->outstanding_cmds
[index
];
2895 if (!(sfcp
->flags
& FCF_TAPE_PRESENT
))
2898 set_bit(ISP_ABORT_NEEDED
,
2902 spin_unlock_irqrestore(&ha
->hardware_lock
,
2905 set_bit(ABORT_QUEUES_NEEDED
, &vha
->dpc_flags
);
2909 /* if the loop has been down for 4 minutes, reinit adapter */
2910 if (atomic_dec_and_test(&vha
->loop_down_timer
) != 0) {
2911 DEBUG(printk("scsi(%ld): Loop down exceed 4 mins - "
2912 "restarting queues.\n",
2915 set_bit(RESTART_QUEUES_NEEDED
, &vha
->dpc_flags
);
2918 if (!(vha
->device_flags
& DFLG_NO_CABLE
) &&
2920 DEBUG(printk("scsi(%ld): Loop down - "
2923 qla_printk(KERN_WARNING
, ha
,
2924 "Loop down - aborting ISP.\n");
2926 set_bit(ISP_ABORT_NEEDED
, &vha
->dpc_flags
);
2929 DEBUG3(printk("scsi(%ld): Loop Down - seconds remaining %d\n",
2931 atomic_read(&vha
->loop_down_timer
)));
2934 /* Check if beacon LED needs to be blinked */
2935 if (ha
->beacon_blink_led
== 1) {
2936 set_bit(BEACON_BLINK_NEEDED
, &vha
->dpc_flags
);
2940 /* Process any deferred work. */
2941 if (!list_empty(&vha
->work_list
))
2944 /* Schedule the DPC routine if needed */
2945 if ((test_bit(ISP_ABORT_NEEDED
, &vha
->dpc_flags
) ||
2946 test_bit(LOOP_RESYNC_NEEDED
, &vha
->dpc_flags
) ||
2947 test_bit(FCPORT_UPDATE_NEEDED
, &vha
->dpc_flags
) ||
2949 test_bit(RESET_MARKER_NEEDED
, &vha
->dpc_flags
) ||
2950 test_bit(BEACON_BLINK_NEEDED
, &vha
->dpc_flags
) ||
2951 test_bit(VP_DPC_NEEDED
, &vha
->dpc_flags
) ||
2952 test_bit(RELOGIN_NEEDED
, &vha
->dpc_flags
)))
2953 qla2xxx_wake_dpc(vha
);
2955 qla2x00_restart_timer(vha
, WATCH_INTERVAL
);
2958 /* Firmware interface routines. */
2961 #define FW_ISP21XX 0
2962 #define FW_ISP22XX 1
2963 #define FW_ISP2300 2
2964 #define FW_ISP2322 3
2965 #define FW_ISP24XX 4
2966 #define FW_ISP25XX 5
2967 #define FW_ISP81XX 6
2969 #define FW_FILE_ISP21XX "ql2100_fw.bin"
2970 #define FW_FILE_ISP22XX "ql2200_fw.bin"
2971 #define FW_FILE_ISP2300 "ql2300_fw.bin"
2972 #define FW_FILE_ISP2322 "ql2322_fw.bin"
2973 #define FW_FILE_ISP24XX "ql2400_fw.bin"
2974 #define FW_FILE_ISP25XX "ql2500_fw.bin"
2975 #define FW_FILE_ISP81XX "ql8100_fw.bin"
2977 static DEFINE_MUTEX(qla_fw_lock
);
2979 static struct fw_blob qla_fw_blobs
[FW_BLOBS
] = {
2980 { .name
= FW_FILE_ISP21XX
, .segs
= { 0x1000, 0 }, },
2981 { .name
= FW_FILE_ISP22XX
, .segs
= { 0x1000, 0 }, },
2982 { .name
= FW_FILE_ISP2300
, .segs
= { 0x800, 0 }, },
2983 { .name
= FW_FILE_ISP2322
, .segs
= { 0x800, 0x1c000, 0x1e000, 0 }, },
2984 { .name
= FW_FILE_ISP24XX
, },
2985 { .name
= FW_FILE_ISP25XX
, },
2986 { .name
= FW_FILE_ISP81XX
, },
2990 qla2x00_request_firmware(scsi_qla_host_t
*vha
)
2992 struct qla_hw_data
*ha
= vha
->hw
;
2993 struct fw_blob
*blob
;
2996 if (IS_QLA2100(ha
)) {
2997 blob
= &qla_fw_blobs
[FW_ISP21XX
];
2998 } else if (IS_QLA2200(ha
)) {
2999 blob
= &qla_fw_blobs
[FW_ISP22XX
];
3000 } else if (IS_QLA2300(ha
) || IS_QLA2312(ha
) || IS_QLA6312(ha
)) {
3001 blob
= &qla_fw_blobs
[FW_ISP2300
];
3002 } else if (IS_QLA2322(ha
) || IS_QLA6322(ha
)) {
3003 blob
= &qla_fw_blobs
[FW_ISP2322
];
3004 } else if (IS_QLA24XX_TYPE(ha
)) {
3005 blob
= &qla_fw_blobs
[FW_ISP24XX
];
3006 } else if (IS_QLA25XX(ha
)) {
3007 blob
= &qla_fw_blobs
[FW_ISP25XX
];
3008 } else if (IS_QLA81XX(ha
)) {
3009 blob
= &qla_fw_blobs
[FW_ISP81XX
];
3012 mutex_lock(&qla_fw_lock
);
3016 if (request_firmware(&blob
->fw
, blob
->name
, &ha
->pdev
->dev
)) {
3017 DEBUG2(printk("scsi(%ld): Failed to load firmware image "
3018 "(%s).\n", vha
->host_no
, blob
->name
));
3025 mutex_unlock(&qla_fw_lock
);
3030 qla2x00_release_firmware(void)
3034 mutex_lock(&qla_fw_lock
);
3035 for (idx
= 0; idx
< FW_BLOBS
; idx
++)
3036 if (qla_fw_blobs
[idx
].fw
)
3037 release_firmware(qla_fw_blobs
[idx
].fw
);
3038 mutex_unlock(&qla_fw_lock
);
3041 static pci_ers_result_t
3042 qla2xxx_pci_error_detected(struct pci_dev
*pdev
, pci_channel_state_t state
)
3045 case pci_channel_io_normal
:
3046 return PCI_ERS_RESULT_CAN_RECOVER
;
3047 case pci_channel_io_frozen
:
3048 pci_disable_device(pdev
);
3049 return PCI_ERS_RESULT_NEED_RESET
;
3050 case pci_channel_io_perm_failure
:
3051 qla2x00_remove_one(pdev
);
3052 return PCI_ERS_RESULT_DISCONNECT
;
3054 return PCI_ERS_RESULT_NEED_RESET
;
3057 static pci_ers_result_t
3058 qla2xxx_pci_mmio_enabled(struct pci_dev
*pdev
)
3060 int risc_paused
= 0;
3062 unsigned long flags
;
3063 scsi_qla_host_t
*base_vha
= pci_get_drvdata(pdev
);
3064 struct qla_hw_data
*ha
= base_vha
->hw
;
3065 struct device_reg_2xxx __iomem
*reg
= &ha
->iobase
->isp
;
3066 struct device_reg_24xx __iomem
*reg24
= &ha
->iobase
->isp24
;
3068 spin_lock_irqsave(&ha
->hardware_lock
, flags
);
3069 if (IS_QLA2100(ha
) || IS_QLA2200(ha
)){
3070 stat
= RD_REG_DWORD(®
->hccr
);
3071 if (stat
& HCCR_RISC_PAUSE
)
3073 } else if (IS_QLA23XX(ha
)) {
3074 stat
= RD_REG_DWORD(®
->u
.isp2300
.host_status
);
3075 if (stat
& HSR_RISC_PAUSED
)
3077 } else if (IS_FWI2_CAPABLE(ha
)) {
3078 stat
= RD_REG_DWORD(®24
->host_status
);
3079 if (stat
& HSRX_RISC_PAUSED
)
3082 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
3085 qla_printk(KERN_INFO
, ha
, "RISC paused -- mmio_enabled, "
3086 "Dumping firmware!\n");
3087 ha
->isp_ops
->fw_dump(base_vha
, 0);
3089 return PCI_ERS_RESULT_NEED_RESET
;
3091 return PCI_ERS_RESULT_RECOVERED
;
3094 static pci_ers_result_t
3095 qla2xxx_pci_slot_reset(struct pci_dev
*pdev
)
3097 pci_ers_result_t ret
= PCI_ERS_RESULT_DISCONNECT
;
3098 scsi_qla_host_t
*base_vha
= pci_get_drvdata(pdev
);
3099 struct qla_hw_data
*ha
= base_vha
->hw
;
3103 rc
= pci_enable_device_mem(pdev
);
3105 rc
= pci_enable_device(pdev
);
3108 qla_printk(KERN_WARNING
, ha
,
3109 "Can't re-enable PCI device after reset.\n");
3113 pci_set_master(pdev
);
3115 if (ha
->isp_ops
->pci_config(base_vha
))
3118 set_bit(ABORT_ISP_ACTIVE
, &base_vha
->dpc_flags
);
3119 if (qla2x00_abort_isp(base_vha
) == QLA_SUCCESS
)
3120 ret
= PCI_ERS_RESULT_RECOVERED
;
3121 clear_bit(ABORT_ISP_ACTIVE
, &base_vha
->dpc_flags
);
3127 qla2xxx_pci_resume(struct pci_dev
*pdev
)
3129 scsi_qla_host_t
*base_vha
= pci_get_drvdata(pdev
);
3130 struct qla_hw_data
*ha
= base_vha
->hw
;
3133 ret
= qla2x00_wait_for_hba_online(base_vha
);
3134 if (ret
!= QLA_SUCCESS
) {
3135 qla_printk(KERN_ERR
, ha
,
3136 "the device failed to resume I/O "
3137 "from slot/link_reset");
3139 pci_cleanup_aer_uncorrect_error_status(pdev
);
3142 static struct pci_error_handlers qla2xxx_err_handler
= {
3143 .error_detected
= qla2xxx_pci_error_detected
,
3144 .mmio_enabled
= qla2xxx_pci_mmio_enabled
,
3145 .slot_reset
= qla2xxx_pci_slot_reset
,
3146 .resume
= qla2xxx_pci_resume
,
3149 static struct pci_device_id qla2xxx_pci_tbl
[] = {
3150 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC
, PCI_DEVICE_ID_QLOGIC_ISP2100
) },
3151 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC
, PCI_DEVICE_ID_QLOGIC_ISP2200
) },
3152 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC
, PCI_DEVICE_ID_QLOGIC_ISP2300
) },
3153 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC
, PCI_DEVICE_ID_QLOGIC_ISP2312
) },
3154 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC
, PCI_DEVICE_ID_QLOGIC_ISP2322
) },
3155 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC
, PCI_DEVICE_ID_QLOGIC_ISP6312
) },
3156 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC
, PCI_DEVICE_ID_QLOGIC_ISP6322
) },
3157 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC
, PCI_DEVICE_ID_QLOGIC_ISP2422
) },
3158 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC
, PCI_DEVICE_ID_QLOGIC_ISP2432
) },
3159 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC
, PCI_DEVICE_ID_QLOGIC_ISP8432
) },
3160 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC
, PCI_DEVICE_ID_QLOGIC_ISP5422
) },
3161 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC
, PCI_DEVICE_ID_QLOGIC_ISP5432
) },
3162 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC
, PCI_DEVICE_ID_QLOGIC_ISP2532
) },
3163 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC
, PCI_DEVICE_ID_QLOGIC_ISP8001
) },
3166 MODULE_DEVICE_TABLE(pci
, qla2xxx_pci_tbl
);
3168 static struct pci_driver qla2xxx_pci_driver
= {
3169 .name
= QLA2XXX_DRIVER_NAME
,
3171 .owner
= THIS_MODULE
,
3173 .id_table
= qla2xxx_pci_tbl
,
3174 .probe
= qla2x00_probe_one
,
3175 .remove
= qla2x00_remove_one
,
3176 .err_handler
= &qla2xxx_err_handler
,
3180 * qla2x00_module_init - Module initialization.
3183 qla2x00_module_init(void)
3187 /* Allocate cache for SRBs. */
3188 srb_cachep
= kmem_cache_create("qla2xxx_srbs", sizeof(srb_t
), 0,
3189 SLAB_HWCACHE_ALIGN
, NULL
);
3190 if (srb_cachep
== NULL
) {
3192 "qla2xxx: Unable to allocate SRB cache...Failing load!\n");
3196 /* Derive version string. */
3197 strcpy(qla2x00_version_str
, QLA2XXX_VERSION
);
3198 if (ql2xextended_error_logging
)
3199 strcat(qla2x00_version_str
, "-debug");
3201 qla2xxx_transport_template
=
3202 fc_attach_transport(&qla2xxx_transport_functions
);
3203 if (!qla2xxx_transport_template
) {
3204 kmem_cache_destroy(srb_cachep
);
3207 qla2xxx_transport_vport_template
=
3208 fc_attach_transport(&qla2xxx_transport_vport_functions
);
3209 if (!qla2xxx_transport_vport_template
) {
3210 kmem_cache_destroy(srb_cachep
);
3211 fc_release_transport(qla2xxx_transport_template
);
3215 printk(KERN_INFO
"QLogic Fibre Channel HBA Driver: %s\n",
3216 qla2x00_version_str
);
3217 ret
= pci_register_driver(&qla2xxx_pci_driver
);
3219 kmem_cache_destroy(srb_cachep
);
3220 fc_release_transport(qla2xxx_transport_template
);
3221 fc_release_transport(qla2xxx_transport_vport_template
);
3227 * qla2x00_module_exit - Module cleanup.
3230 qla2x00_module_exit(void)
3232 pci_unregister_driver(&qla2xxx_pci_driver
);
3233 qla2x00_release_firmware();
3234 kmem_cache_destroy(srb_cachep
);
3235 fc_release_transport(qla2xxx_transport_template
);
3236 fc_release_transport(qla2xxx_transport_vport_template
);
3239 module_init(qla2x00_module_init
);
3240 module_exit(qla2x00_module_exit
);
3242 MODULE_AUTHOR("QLogic Corporation");
3243 MODULE_DESCRIPTION("QLogic Fibre Channel HBA Driver");
3244 MODULE_LICENSE("GPL");
3245 MODULE_VERSION(QLA2XXX_VERSION
);
3246 MODULE_FIRMWARE(FW_FILE_ISP21XX
);
3247 MODULE_FIRMWARE(FW_FILE_ISP22XX
);
3248 MODULE_FIRMWARE(FW_FILE_ISP2300
);
3249 MODULE_FIRMWARE(FW_FILE_ISP2322
);
3250 MODULE_FIRMWARE(FW_FILE_ISP24XX
);
3251 MODULE_FIRMWARE(FW_FILE_ISP25XX
);
3252 MODULE_FIRMWARE(FW_FILE_ISP81XX
);