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
;
31 int ql2xlogintimeout
= 20;
32 module_param(ql2xlogintimeout
, int, S_IRUGO
|S_IRUSR
);
33 MODULE_PARM_DESC(ql2xlogintimeout
,
34 "Login timeout value in seconds.");
36 int qlport_down_retry
;
37 module_param(qlport_down_retry
, int, S_IRUGO
|S_IRUSR
);
38 MODULE_PARM_DESC(qlport_down_retry
,
39 "Maximum number of command retries to a port that returns "
40 "a PORT-DOWN status.");
42 int ql2xplogiabsentdevice
;
43 module_param(ql2xplogiabsentdevice
, int, S_IRUGO
|S_IWUSR
);
44 MODULE_PARM_DESC(ql2xplogiabsentdevice
,
45 "Option to enable PLOGI to devices that are not present after "
46 "a Fabric scan. This is needed for several broken switches. "
47 "Default is 0 - no PLOGI. 1 - perfom PLOGI.");
49 int ql2xloginretrycount
= 0;
50 module_param(ql2xloginretrycount
, int, S_IRUGO
|S_IRUSR
);
51 MODULE_PARM_DESC(ql2xloginretrycount
,
52 "Specify an alternate value for the NVRAM login retry count.");
54 int ql2xallocfwdump
= 1;
55 module_param(ql2xallocfwdump
, int, S_IRUGO
|S_IRUSR
);
56 MODULE_PARM_DESC(ql2xallocfwdump
,
57 "Option to enable allocation of memory for a firmware dump "
58 "during HBA initialization. Memory allocation requirements "
59 "vary by ISP type. Default is 1 - allocate memory.");
61 int ql2xextended_error_logging
;
62 module_param(ql2xextended_error_logging
, int, S_IRUGO
|S_IWUSR
);
63 MODULE_PARM_DESC(ql2xextended_error_logging
,
64 "Option to enable extended error logging, "
65 "Default is 0 - no logging. 1 - log errors.");
67 static void qla2x00_free_device(scsi_qla_host_t
*);
69 static void qla2x00_config_dma_addressing(scsi_qla_host_t
*ha
);
72 module_param(ql2xfdmienable
, int, S_IRUGO
|S_IRUSR
);
73 MODULE_PARM_DESC(ql2xfdmienable
,
74 "Enables FDMI registratons "
75 "Default is 0 - no FDMI. 1 - perfom FDMI.");
77 #define MAX_Q_DEPTH 32
78 static int ql2xmaxqdepth
= MAX_Q_DEPTH
;
79 module_param(ql2xmaxqdepth
, int, S_IRUGO
|S_IWUSR
);
80 MODULE_PARM_DESC(ql2xmaxqdepth
,
81 "Maximum queue depth to report for target devices.");
83 int ql2xqfullrampup
= 120;
84 module_param(ql2xqfullrampup
, int, S_IRUGO
|S_IWUSR
);
85 MODULE_PARM_DESC(ql2xqfullrampup
,
86 "Number of seconds to wait to begin to ramp-up the queue "
87 "depth for a device after a queue-full condition has been "
88 "detected. Default is 120 seconds.");
91 * SCSI host template entry points
93 static int qla2xxx_slave_configure(struct scsi_device
* device
);
94 static int qla2xxx_slave_alloc(struct scsi_device
*);
95 static int qla2xxx_scan_finished(struct Scsi_Host
*, unsigned long time
);
96 static void qla2xxx_scan_start(struct Scsi_Host
*);
97 static void qla2xxx_slave_destroy(struct scsi_device
*);
98 static int qla2x00_queuecommand(struct scsi_cmnd
*cmd
,
99 void (*fn
)(struct scsi_cmnd
*));
100 static int qla24xx_queuecommand(struct scsi_cmnd
*cmd
,
101 void (*fn
)(struct scsi_cmnd
*));
102 static int qla2xxx_eh_abort(struct scsi_cmnd
*);
103 static int qla2xxx_eh_device_reset(struct scsi_cmnd
*);
104 static int qla2xxx_eh_target_reset(struct scsi_cmnd
*);
105 static int qla2xxx_eh_bus_reset(struct scsi_cmnd
*);
106 static int qla2xxx_eh_host_reset(struct scsi_cmnd
*);
108 static int qla2x00_change_queue_depth(struct scsi_device
*, int);
109 static int qla2x00_change_queue_type(struct scsi_device
*, int);
111 static struct scsi_host_template qla2x00_driver_template
= {
112 .module
= THIS_MODULE
,
113 .name
= QLA2XXX_DRIVER_NAME
,
114 .queuecommand
= qla2x00_queuecommand
,
116 .eh_abort_handler
= qla2xxx_eh_abort
,
117 .eh_device_reset_handler
= qla2xxx_eh_device_reset
,
118 .eh_target_reset_handler
= qla2xxx_eh_target_reset
,
119 .eh_bus_reset_handler
= qla2xxx_eh_bus_reset
,
120 .eh_host_reset_handler
= qla2xxx_eh_host_reset
,
122 .slave_configure
= qla2xxx_slave_configure
,
124 .slave_alloc
= qla2xxx_slave_alloc
,
125 .slave_destroy
= qla2xxx_slave_destroy
,
126 .scan_finished
= qla2xxx_scan_finished
,
127 .scan_start
= qla2xxx_scan_start
,
128 .change_queue_depth
= qla2x00_change_queue_depth
,
129 .change_queue_type
= qla2x00_change_queue_type
,
132 .use_clustering
= ENABLE_CLUSTERING
,
133 .sg_tablesize
= SG_ALL
,
136 * The RISC allows for each command to transfer (2^32-1) bytes of data,
137 * which equates to 0x800000 sectors.
139 .max_sectors
= 0xFFFF,
140 .shost_attrs
= qla2x00_host_attrs
,
143 struct scsi_host_template qla24xx_driver_template
= {
144 .module
= THIS_MODULE
,
145 .name
= QLA2XXX_DRIVER_NAME
,
146 .queuecommand
= qla24xx_queuecommand
,
148 .eh_abort_handler
= qla2xxx_eh_abort
,
149 .eh_device_reset_handler
= qla2xxx_eh_device_reset
,
150 .eh_target_reset_handler
= qla2xxx_eh_target_reset
,
151 .eh_bus_reset_handler
= qla2xxx_eh_bus_reset
,
152 .eh_host_reset_handler
= qla2xxx_eh_host_reset
,
154 .slave_configure
= qla2xxx_slave_configure
,
156 .slave_alloc
= qla2xxx_slave_alloc
,
157 .slave_destroy
= qla2xxx_slave_destroy
,
158 .scan_finished
= qla2xxx_scan_finished
,
159 .scan_start
= qla2xxx_scan_start
,
160 .change_queue_depth
= qla2x00_change_queue_depth
,
161 .change_queue_type
= qla2x00_change_queue_type
,
164 .use_clustering
= ENABLE_CLUSTERING
,
165 .sg_tablesize
= SG_ALL
,
167 .max_sectors
= 0xFFFF,
168 .shost_attrs
= qla2x00_host_attrs
,
171 static struct scsi_transport_template
*qla2xxx_transport_template
= NULL
;
172 struct scsi_transport_template
*qla2xxx_transport_vport_template
= NULL
;
174 /* TODO Convert to inlines
180 qla2x00_start_timer(scsi_qla_host_t
*ha
, void *func
, unsigned long interval
)
182 init_timer(&ha
->timer
);
183 ha
->timer
.expires
= jiffies
+ interval
* HZ
;
184 ha
->timer
.data
= (unsigned long)ha
;
185 ha
->timer
.function
= (void (*)(unsigned long))func
;
186 add_timer(&ha
->timer
);
187 ha
->timer_active
= 1;
191 qla2x00_restart_timer(scsi_qla_host_t
*ha
, unsigned long interval
)
193 mod_timer(&ha
->timer
, jiffies
+ interval
* HZ
);
196 static __inline__
void
197 qla2x00_stop_timer(scsi_qla_host_t
*ha
)
199 del_timer_sync(&ha
->timer
);
200 ha
->timer_active
= 0;
203 static int qla2x00_do_dpc(void *data
);
205 static void qla2x00_rst_aen(scsi_qla_host_t
*);
207 static int qla2x00_mem_alloc(scsi_qla_host_t
*);
208 static void qla2x00_mem_free(scsi_qla_host_t
*ha
);
209 static void qla2x00_sp_free_dma(scsi_qla_host_t
*, srb_t
*);
211 /* -------------------------------------------------------------------------- */
214 qla2x00_pci_info_str(struct scsi_qla_host
*ha
, char *str
)
216 static char *pci_bus_modes
[] = {
217 "33", "66", "100", "133",
222 pci_bus
= (ha
->pci_attr
& (BIT_9
| BIT_10
)) >> 9;
225 strcat(str
, pci_bus_modes
[pci_bus
]);
227 pci_bus
= (ha
->pci_attr
& BIT_8
) >> 8;
229 strcat(str
, pci_bus_modes
[pci_bus
]);
231 strcat(str
, " MHz)");
237 qla24xx_pci_info_str(struct scsi_qla_host
*ha
, char *str
)
239 static char *pci_bus_modes
[] = { "33", "66", "100", "133", };
243 pcie_reg
= pci_find_capability(ha
->pdev
, PCI_CAP_ID_EXP
);
246 uint16_t pcie_lstat
, lspeed
, lwidth
;
249 pci_read_config_word(ha
->pdev
, pcie_reg
, &pcie_lstat
);
250 lspeed
= pcie_lstat
& (BIT_0
| BIT_1
| BIT_2
| BIT_3
);
251 lwidth
= (pcie_lstat
&
252 (BIT_4
| BIT_5
| BIT_6
| BIT_7
| BIT_8
| BIT_9
)) >> 4;
254 strcpy(str
, "PCIe (");
256 strcat(str
, "2.5GT/s ");
257 else if (lspeed
== 2)
258 strcat(str
, "5.0GT/s ");
260 strcat(str
, "<unknown> ");
261 snprintf(lwstr
, sizeof(lwstr
), "x%d)", lwidth
);
268 pci_bus
= (ha
->pci_attr
& CSRX_PCIX_BUS_MODE_MASK
) >> 8;
269 if (pci_bus
== 0 || pci_bus
== 8) {
271 strcat(str
, pci_bus_modes
[pci_bus
>> 3]);
275 strcat(str
, "Mode 2");
277 strcat(str
, "Mode 1");
279 strcat(str
, pci_bus_modes
[pci_bus
& ~BIT_2
]);
281 strcat(str
, " MHz)");
287 qla2x00_fw_version_str(struct scsi_qla_host
*ha
, char *str
)
291 sprintf(str
, "%d.%02d.%02d ", ha
->fw_major_version
,
292 ha
->fw_minor_version
,
293 ha
->fw_subminor_version
);
295 if (ha
->fw_attributes
& BIT_9
) {
300 switch (ha
->fw_attributes
& 0xFF) {
314 sprintf(un_str
, "(%x)", ha
->fw_attributes
);
318 if (ha
->fw_attributes
& 0x100)
325 qla24xx_fw_version_str(struct scsi_qla_host
*ha
, char *str
)
327 sprintf(str
, "%d.%02d.%02d ", ha
->fw_major_version
,
328 ha
->fw_minor_version
,
329 ha
->fw_subminor_version
);
331 if (ha
->fw_attributes
& BIT_0
)
332 strcat(str
, "[Class 2] ");
333 if (ha
->fw_attributes
& BIT_1
)
334 strcat(str
, "[IP] ");
335 if (ha
->fw_attributes
& BIT_2
)
336 strcat(str
, "[Multi-ID] ");
337 if (ha
->fw_attributes
& BIT_3
)
338 strcat(str
, "[SB-2] ");
339 if (ha
->fw_attributes
& BIT_4
)
340 strcat(str
, "[T10 CRC] ");
341 if (ha
->fw_attributes
& BIT_5
)
342 strcat(str
, "[VI] ");
343 if (ha
->fw_attributes
& BIT_10
)
344 strcat(str
, "[84XX] ");
345 if (ha
->fw_attributes
& BIT_13
)
346 strcat(str
, "[Experimental]");
350 static inline srb_t
*
351 qla2x00_get_new_sp(scsi_qla_host_t
*ha
, fc_port_t
*fcport
,
352 struct scsi_cmnd
*cmd
, void (*done
)(struct scsi_cmnd
*))
356 sp
= mempool_alloc(ha
->srb_mempool
, GFP_ATOMIC
);
364 CMD_SP(cmd
) = (void *)sp
;
365 cmd
->scsi_done
= done
;
371 qla2x00_queuecommand(struct scsi_cmnd
*cmd
, void (*done
)(struct scsi_cmnd
*))
373 scsi_qla_host_t
*ha
= shost_priv(cmd
->device
->host
);
374 fc_port_t
*fcport
= (struct fc_port
*) cmd
->device
->hostdata
;
375 struct fc_rport
*rport
= starget_to_rport(scsi_target(cmd
->device
));
379 if (unlikely(pci_channel_offline(ha
->pdev
))) {
380 cmd
->result
= DID_REQUEUE
<< 16;
381 goto qc_fail_command
;
384 rval
= fc_remote_port_chkready(rport
);
387 goto qc_fail_command
;
390 /* Close window on fcport/rport state-transitioning. */
391 if (fcport
->drport
) {
392 cmd
->result
= DID_IMM_RETRY
<< 16;
393 goto qc_fail_command
;
396 if (atomic_read(&fcport
->state
) != FCS_ONLINE
) {
397 if (atomic_read(&fcport
->state
) == FCS_DEVICE_DEAD
||
398 atomic_read(&ha
->loop_state
) == LOOP_DEAD
) {
399 cmd
->result
= DID_NO_CONNECT
<< 16;
400 goto qc_fail_command
;
405 spin_unlock_irq(ha
->host
->host_lock
);
407 sp
= qla2x00_get_new_sp(ha
, fcport
, cmd
, done
);
409 goto qc_host_busy_lock
;
411 rval
= qla2x00_start_scsi(sp
);
412 if (rval
!= QLA_SUCCESS
)
413 goto qc_host_busy_free_sp
;
415 spin_lock_irq(ha
->host
->host_lock
);
419 qc_host_busy_free_sp
:
420 qla2x00_sp_free_dma(ha
, sp
);
421 mempool_free(sp
, ha
->srb_mempool
);
424 spin_lock_irq(ha
->host
->host_lock
);
427 return SCSI_MLQUEUE_HOST_BUSY
;
437 qla24xx_queuecommand(struct scsi_cmnd
*cmd
, void (*done
)(struct scsi_cmnd
*))
439 scsi_qla_host_t
*ha
= shost_priv(cmd
->device
->host
);
440 fc_port_t
*fcport
= (struct fc_port
*) cmd
->device
->hostdata
;
441 struct fc_rport
*rport
= starget_to_rport(scsi_target(cmd
->device
));
444 scsi_qla_host_t
*pha
= to_qla_parent(ha
);
446 if (unlikely(pci_channel_offline(ha
->pdev
))) {
447 cmd
->result
= DID_REQUEUE
<< 16;
448 goto qc24_fail_command
;
451 rval
= fc_remote_port_chkready(rport
);
454 goto qc24_fail_command
;
457 /* Close window on fcport/rport state-transitioning. */
458 if (fcport
->drport
) {
459 cmd
->result
= DID_IMM_RETRY
<< 16;
460 goto qc24_fail_command
;
463 if (atomic_read(&fcport
->state
) != FCS_ONLINE
) {
464 if (atomic_read(&fcport
->state
) == FCS_DEVICE_DEAD
||
465 atomic_read(&pha
->loop_state
) == LOOP_DEAD
) {
466 cmd
->result
= DID_NO_CONNECT
<< 16;
467 goto qc24_fail_command
;
472 spin_unlock_irq(ha
->host
->host_lock
);
474 sp
= qla2x00_get_new_sp(pha
, fcport
, cmd
, done
);
476 goto qc24_host_busy_lock
;
478 rval
= qla24xx_start_scsi(sp
);
479 if (rval
!= QLA_SUCCESS
)
480 goto qc24_host_busy_free_sp
;
482 spin_lock_irq(ha
->host
->host_lock
);
486 qc24_host_busy_free_sp
:
487 qla2x00_sp_free_dma(pha
, sp
);
488 mempool_free(sp
, pha
->srb_mempool
);
491 spin_lock_irq(ha
->host
->host_lock
);
494 return SCSI_MLQUEUE_HOST_BUSY
;
504 * qla2x00_eh_wait_on_command
505 * Waits for the command to be returned by the Firmware for some
509 * ha = actual ha whose done queue will contain the command
510 * returned by firmware.
511 * cmd = Scsi Command to wait on.
512 * flag = Abort/Reset(Bus or Device Reset)
519 qla2x00_eh_wait_on_command(scsi_qla_host_t
*ha
, struct scsi_cmnd
*cmd
)
521 #define ABORT_POLLING_PERIOD 1000
522 #define ABORT_WAIT_ITER ((10 * 1000) / (ABORT_POLLING_PERIOD))
523 unsigned long wait_iter
= ABORT_WAIT_ITER
;
524 int ret
= QLA_SUCCESS
;
526 while (CMD_SP(cmd
)) {
527 msleep(ABORT_POLLING_PERIOD
);
533 ret
= QLA_FUNCTION_FAILED
;
539 * qla2x00_wait_for_hba_online
540 * Wait till the HBA is online after going through
541 * <= MAX_RETRIES_OF_ISP_ABORT or
542 * finally HBA is disabled ie marked offline
545 * ha - pointer to host adapter structure
548 * Does context switching-Release SPIN_LOCK
549 * (if any) before calling this routine.
552 * Success (Adapter is online) : 0
553 * Failed (Adapter is offline/disabled) : 1
556 qla2x00_wait_for_hba_online(scsi_qla_host_t
*ha
)
559 unsigned long wait_online
;
560 scsi_qla_host_t
*pha
= to_qla_parent(ha
);
562 wait_online
= jiffies
+ (MAX_LOOP_TIMEOUT
* HZ
);
563 while (((test_bit(ISP_ABORT_NEEDED
, &pha
->dpc_flags
)) ||
564 test_bit(ABORT_ISP_ACTIVE
, &pha
->dpc_flags
) ||
565 test_bit(ISP_ABORT_RETRY
, &pha
->dpc_flags
) ||
566 pha
->dpc_active
) && time_before(jiffies
, wait_online
)) {
570 if (pha
->flags
.online
)
571 return_status
= QLA_SUCCESS
;
573 return_status
= QLA_FUNCTION_FAILED
;
575 return (return_status
);
579 * qla2x00_wait_for_loop_ready
580 * Wait for MAX_LOOP_TIMEOUT(5 min) value for loop
581 * to be in LOOP_READY state.
583 * ha - pointer to host adapter structure
586 * Does context switching-Release SPIN_LOCK
587 * (if any) before calling this routine.
591 * Success (LOOP_READY) : 0
592 * Failed (LOOP_NOT_READY) : 1
595 qla2x00_wait_for_loop_ready(scsi_qla_host_t
*ha
)
597 int return_status
= QLA_SUCCESS
;
598 unsigned long loop_timeout
;
599 scsi_qla_host_t
*pha
= to_qla_parent(ha
);
601 /* wait for 5 min at the max for loop to be ready */
602 loop_timeout
= jiffies
+ (MAX_LOOP_TIMEOUT
* HZ
);
604 while ((!atomic_read(&pha
->loop_down_timer
) &&
605 atomic_read(&pha
->loop_state
) == LOOP_DOWN
) ||
606 atomic_read(&pha
->loop_state
) != LOOP_READY
) {
607 if (atomic_read(&pha
->loop_state
) == LOOP_DEAD
) {
608 return_status
= QLA_FUNCTION_FAILED
;
612 if (time_after_eq(jiffies
, loop_timeout
)) {
613 return_status
= QLA_FUNCTION_FAILED
;
617 return (return_status
);
621 qla2x00_abort_fcport_cmds(fc_port_t
*fcport
)
626 scsi_qla_host_t
*ha
= fcport
->ha
;
627 scsi_qla_host_t
*pha
= to_qla_parent(ha
);
629 spin_lock_irqsave(&pha
->hardware_lock
, flags
);
630 for (cnt
= 1; cnt
< MAX_OUTSTANDING_COMMANDS
; cnt
++) {
631 sp
= pha
->outstanding_cmds
[cnt
];
634 if (sp
->fcport
!= fcport
)
637 spin_unlock_irqrestore(&pha
->hardware_lock
, flags
);
638 if (ha
->isp_ops
->abort_command(ha
, sp
)) {
639 DEBUG2(qla_printk(KERN_WARNING
, ha
,
640 "Abort failed -- %lx\n", sp
->cmd
->serial_number
));
642 if (qla2x00_eh_wait_on_command(ha
, sp
->cmd
) !=
644 DEBUG2(qla_printk(KERN_WARNING
, ha
,
645 "Abort failed while waiting -- %lx\n",
646 sp
->cmd
->serial_number
));
649 spin_lock_irqsave(&pha
->hardware_lock
, flags
);
651 spin_unlock_irqrestore(&pha
->hardware_lock
, flags
);
655 qla2x00_block_error_handler(struct scsi_cmnd
*cmnd
)
657 struct Scsi_Host
*shost
= cmnd
->device
->host
;
658 struct fc_rport
*rport
= starget_to_rport(scsi_target(cmnd
->device
));
661 spin_lock_irqsave(shost
->host_lock
, flags
);
662 while (rport
->port_state
== FC_PORTSTATE_BLOCKED
) {
663 spin_unlock_irqrestore(shost
->host_lock
, flags
);
665 spin_lock_irqsave(shost
->host_lock
, flags
);
667 spin_unlock_irqrestore(shost
->host_lock
, flags
);
671 /**************************************************************************
675 * The abort function will abort the specified command.
678 * cmd = Linux SCSI command packet to be aborted.
681 * Either SUCCESS or FAILED.
684 * Only return FAILED if command not returned by firmware.
685 **************************************************************************/
687 qla2xxx_eh_abort(struct scsi_cmnd
*cmd
)
689 scsi_qla_host_t
*ha
= shost_priv(cmd
->device
->host
);
692 unsigned int id
, lun
;
693 unsigned long serial
;
696 scsi_qla_host_t
*pha
= to_qla_parent(ha
);
698 qla2x00_block_error_handler(cmd
);
705 id
= cmd
->device
->id
;
706 lun
= cmd
->device
->lun
;
707 serial
= cmd
->serial_number
;
709 /* Check active list for command command. */
710 spin_lock_irqsave(&pha
->hardware_lock
, flags
);
711 for (i
= 1; i
< MAX_OUTSTANDING_COMMANDS
; i
++) {
712 sp
= pha
->outstanding_cmds
[i
];
720 DEBUG2(printk("%s(%ld): aborting sp %p from RISC. pid=%ld.\n",
721 __func__
, ha
->host_no
, sp
, serial
));
723 spin_unlock_irqrestore(&pha
->hardware_lock
, flags
);
724 if (ha
->isp_ops
->abort_command(ha
, sp
)) {
725 DEBUG2(printk("%s(%ld): abort_command "
726 "mbx failed.\n", __func__
, ha
->host_no
));
728 DEBUG3(printk("%s(%ld): abort_command "
729 "mbx success.\n", __func__
, ha
->host_no
));
732 spin_lock_irqsave(&pha
->hardware_lock
, flags
);
736 spin_unlock_irqrestore(&pha
->hardware_lock
, flags
);
738 /* Wait for the command to be returned. */
740 if (qla2x00_eh_wait_on_command(ha
, cmd
) != QLA_SUCCESS
) {
741 qla_printk(KERN_ERR
, ha
,
742 "scsi(%ld:%d:%d): Abort handler timed out -- %lx "
743 "%x.\n", ha
->host_no
, id
, lun
, serial
, ret
);
748 qla_printk(KERN_INFO
, ha
,
749 "scsi(%ld:%d:%d): Abort command issued -- %d %lx %x.\n",
750 ha
->host_no
, id
, lun
, wait
, serial
, ret
);
755 enum nexus_wait_type
{
762 qla2x00_eh_wait_for_pending_commands(scsi_qla_host_t
*ha
, unsigned int t
,
763 unsigned int l
, enum nexus_wait_type type
)
765 int cnt
, match
, status
;
768 scsi_qla_host_t
*pha
= to_qla_parent(ha
);
770 status
= QLA_SUCCESS
;
771 spin_lock_irqsave(&pha
->hardware_lock
, flags
);
772 for (cnt
= 1; status
== QLA_SUCCESS
&& cnt
< MAX_OUTSTANDING_COMMANDS
;
774 sp
= pha
->outstanding_cmds
[cnt
];
777 if (ha
->vp_idx
!= sp
->ha
->vp_idx
)
785 match
= sp
->cmd
->device
->id
== t
;
788 match
= (sp
->cmd
->device
->id
== t
&&
789 sp
->cmd
->device
->lun
== l
);
795 spin_unlock_irqrestore(&pha
->hardware_lock
, flags
);
796 status
= qla2x00_eh_wait_on_command(ha
, sp
->cmd
);
797 spin_lock_irqsave(&pha
->hardware_lock
, flags
);
799 spin_unlock_irqrestore(&pha
->hardware_lock
, flags
);
804 static char *reset_errors
[] = {
807 "Task management failed",
808 "Waiting for command completions",
812 __qla2xxx_eh_generic_reset(char *name
, enum nexus_wait_type type
,
813 struct scsi_cmnd
*cmd
, int (*do_reset
)(struct fc_port
*, unsigned int))
815 scsi_qla_host_t
*ha
= shost_priv(cmd
->device
->host
);
816 fc_port_t
*fcport
= (struct fc_port
*) cmd
->device
->hostdata
;
819 qla2x00_block_error_handler(cmd
);
824 qla_printk(KERN_INFO
, ha
, "scsi(%ld:%d:%d): %s RESET ISSUED.\n",
825 ha
->host_no
, cmd
->device
->id
, cmd
->device
->lun
, name
);
828 if (qla2x00_wait_for_hba_online(ha
) != QLA_SUCCESS
)
829 goto eh_reset_failed
;
831 if (qla2x00_wait_for_loop_ready(ha
) != QLA_SUCCESS
)
832 goto eh_reset_failed
;
834 if (do_reset(fcport
, cmd
->device
->lun
) != QLA_SUCCESS
)
835 goto eh_reset_failed
;
837 if (qla2x00_eh_wait_for_pending_commands(ha
, cmd
->device
->id
,
838 cmd
->device
->lun
, type
) != QLA_SUCCESS
)
839 goto eh_reset_failed
;
841 qla_printk(KERN_INFO
, ha
, "scsi(%ld:%d:%d): %s RESET SUCCEEDED.\n",
842 ha
->host_no
, cmd
->device
->id
, cmd
->device
->lun
, name
);
847 qla_printk(KERN_INFO
, ha
, "scsi(%ld:%d:%d): %s RESET FAILED: %s.\n",
848 ha
->host_no
, cmd
->device
->id
, cmd
->device
->lun
, name
,
854 qla2xxx_eh_device_reset(struct scsi_cmnd
*cmd
)
856 scsi_qla_host_t
*ha
= shost_priv(cmd
->device
->host
);
858 return __qla2xxx_eh_generic_reset("DEVICE", WAIT_LUN
, cmd
,
859 ha
->isp_ops
->lun_reset
);
863 qla2xxx_eh_target_reset(struct scsi_cmnd
*cmd
)
865 scsi_qla_host_t
*ha
= shost_priv(cmd
->device
->host
);
867 return __qla2xxx_eh_generic_reset("TARGET", WAIT_TARGET
, cmd
,
868 ha
->isp_ops
->target_reset
);
871 /**************************************************************************
872 * qla2xxx_eh_bus_reset
875 * The bus reset function will reset the bus and abort any executing
879 * cmd = Linux SCSI command packet of the command that cause the
883 * SUCCESS/FAILURE (defined as macro in scsi.h).
885 **************************************************************************/
887 qla2xxx_eh_bus_reset(struct scsi_cmnd
*cmd
)
889 scsi_qla_host_t
*ha
= shost_priv(cmd
->device
->host
);
890 scsi_qla_host_t
*pha
= to_qla_parent(ha
);
891 fc_port_t
*fcport
= (struct fc_port
*) cmd
->device
->hostdata
;
893 unsigned int id
, lun
;
894 unsigned long serial
;
896 qla2x00_block_error_handler(cmd
);
898 id
= cmd
->device
->id
;
899 lun
= cmd
->device
->lun
;
900 serial
= cmd
->serial_number
;
905 qla_printk(KERN_INFO
, ha
,
906 "scsi(%ld:%d:%d): LOOP RESET ISSUED.\n", ha
->host_no
, id
, lun
);
908 if (qla2x00_wait_for_hba_online(ha
) != QLA_SUCCESS
) {
909 DEBUG2(printk("%s failed:board disabled\n",__func__
));
910 goto eh_bus_reset_done
;
913 if (qla2x00_wait_for_loop_ready(ha
) == QLA_SUCCESS
) {
914 if (qla2x00_loop_reset(ha
) == QLA_SUCCESS
)
918 goto eh_bus_reset_done
;
920 /* Flush outstanding commands. */
921 if (qla2x00_eh_wait_for_pending_commands(pha
, 0, 0, WAIT_HOST
) !=
926 qla_printk(KERN_INFO
, ha
, "%s: reset %s\n", __func__
,
927 (ret
== FAILED
) ? "failed" : "succeded");
932 /**************************************************************************
933 * qla2xxx_eh_host_reset
936 * The reset function will reset the Adapter.
939 * cmd = Linux SCSI command packet of the command that cause the
943 * Either SUCCESS or FAILED.
946 **************************************************************************/
948 qla2xxx_eh_host_reset(struct scsi_cmnd
*cmd
)
950 scsi_qla_host_t
*ha
= shost_priv(cmd
->device
->host
);
951 fc_port_t
*fcport
= (struct fc_port
*) cmd
->device
->hostdata
;
953 unsigned int id
, lun
;
954 unsigned long serial
;
955 scsi_qla_host_t
*pha
= to_qla_parent(ha
);
957 qla2x00_block_error_handler(cmd
);
959 id
= cmd
->device
->id
;
960 lun
= cmd
->device
->lun
;
961 serial
= cmd
->serial_number
;
966 qla_printk(KERN_INFO
, ha
,
967 "scsi(%ld:%d:%d): ADAPTER RESET ISSUED.\n", ha
->host_no
, id
, lun
);
969 if (qla2x00_wait_for_hba_online(ha
) != QLA_SUCCESS
)
970 goto eh_host_reset_lock
;
973 * Fixme-may be dpc thread is active and processing
974 * loop_resync,so wait a while for it to
975 * be completed and then issue big hammer.Otherwise
976 * it may cause I/O failure as big hammer marks the
977 * devices as lost kicking of the port_down_timer
978 * while dpc is stuck for the mailbox to complete.
980 qla2x00_wait_for_loop_ready(ha
);
981 set_bit(ABORT_ISP_ACTIVE
, &pha
->dpc_flags
);
982 if (qla2x00_abort_isp(pha
)) {
983 clear_bit(ABORT_ISP_ACTIVE
, &pha
->dpc_flags
);
984 /* failed. schedule dpc to try */
985 set_bit(ISP_ABORT_NEEDED
, &pha
->dpc_flags
);
987 if (qla2x00_wait_for_hba_online(ha
) != QLA_SUCCESS
)
988 goto eh_host_reset_lock
;
990 clear_bit(ABORT_ISP_ACTIVE
, &pha
->dpc_flags
);
992 /* Waiting for our command in done_queue to be returned to OS.*/
993 if (qla2x00_eh_wait_for_pending_commands(pha
, 0, 0, WAIT_HOST
) ==
998 qla2x00_vp_abort_isp(ha
);
1001 qla_printk(KERN_INFO
, ha
, "%s: reset %s\n", __func__
,
1002 (ret
== FAILED
) ? "failed" : "succeded");
1008 * qla2x00_loop_reset
1012 * ha = adapter block pointer.
1018 qla2x00_loop_reset(scsi_qla_host_t
*ha
)
1021 struct fc_port
*fcport
;
1023 if (ha
->flags
.enable_lip_full_login
) {
1024 ret
= qla2x00_full_login_lip(ha
);
1025 if (ret
!= QLA_SUCCESS
) {
1026 DEBUG2_3(printk("%s(%ld): bus_reset failed: "
1027 "full_login_lip=%d.\n", __func__
, ha
->host_no
,
1030 atomic_set(&ha
->loop_state
, LOOP_DOWN
);
1031 atomic_set(&ha
->loop_down_timer
, LOOP_DOWN_TIME
);
1032 qla2x00_mark_all_devices_lost(ha
, 0);
1033 qla2x00_wait_for_loop_ready(ha
);
1036 if (ha
->flags
.enable_lip_reset
) {
1037 ret
= qla2x00_lip_reset(ha
);
1038 if (ret
!= QLA_SUCCESS
) {
1039 DEBUG2_3(printk("%s(%ld): bus_reset failed: "
1040 "lip_reset=%d.\n", __func__
, ha
->host_no
, ret
));
1042 qla2x00_wait_for_loop_ready(ha
);
1045 if (ha
->flags
.enable_target_reset
) {
1046 list_for_each_entry(fcport
, &ha
->fcports
, list
) {
1047 if (fcport
->port_type
!= FCT_TARGET
)
1050 ret
= ha
->isp_ops
->target_reset(fcport
, 0);
1051 if (ret
!= QLA_SUCCESS
) {
1052 DEBUG2_3(printk("%s(%ld): bus_reset failed: "
1053 "target_reset=%d d_id=%x.\n", __func__
,
1054 ha
->host_no
, ret
, fcport
->d_id
.b24
));
1059 /* Issue marker command only when we are going to start the I/O */
1060 ha
->marker_needed
= 1;
1066 qla2x00_abort_all_cmds(scsi_qla_host_t
*ha
, int res
)
1069 unsigned long flags
;
1072 spin_lock_irqsave(&ha
->hardware_lock
, flags
);
1073 for (cnt
= 1; cnt
< MAX_OUTSTANDING_COMMANDS
; cnt
++) {
1074 sp
= ha
->outstanding_cmds
[cnt
];
1076 ha
->outstanding_cmds
[cnt
] = NULL
;
1078 sp
->cmd
->result
= res
;
1079 sp
->cmd
->host_scribble
= (unsigned char *)NULL
;
1080 qla2x00_sp_compl(ha
, sp
);
1083 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
1087 qla2xxx_slave_alloc(struct scsi_device
*sdev
)
1089 struct fc_rport
*rport
= starget_to_rport(scsi_target(sdev
));
1091 if (!rport
|| fc_remote_port_chkready(rport
))
1094 sdev
->hostdata
= *(fc_port_t
**)rport
->dd_data
;
1100 qla2xxx_slave_configure(struct scsi_device
*sdev
)
1102 scsi_qla_host_t
*ha
= shost_priv(sdev
->host
);
1103 struct fc_rport
*rport
= starget_to_rport(sdev
->sdev_target
);
1105 if (sdev
->tagged_supported
)
1106 scsi_activate_tcq(sdev
, ha
->max_q_depth
);
1108 scsi_deactivate_tcq(sdev
, ha
->max_q_depth
);
1110 rport
->dev_loss_tmo
= ha
->port_down_retry_count
+ 5;
1116 qla2xxx_slave_destroy(struct scsi_device
*sdev
)
1118 sdev
->hostdata
= NULL
;
1122 qla2x00_change_queue_depth(struct scsi_device
*sdev
, int qdepth
)
1124 scsi_adjust_queue_depth(sdev
, scsi_get_tag_type(sdev
), qdepth
);
1125 return sdev
->queue_depth
;
1129 qla2x00_change_queue_type(struct scsi_device
*sdev
, int tag_type
)
1131 if (sdev
->tagged_supported
) {
1132 scsi_set_tag_type(sdev
, tag_type
);
1134 scsi_activate_tcq(sdev
, sdev
->queue_depth
);
1136 scsi_deactivate_tcq(sdev
, sdev
->queue_depth
);
1144 * qla2x00_config_dma_addressing() - Configure OS DMA addressing method.
1147 * At exit, the @ha's flags.enable_64bit_addressing set to indicated
1148 * supported addressing method.
1151 qla2x00_config_dma_addressing(scsi_qla_host_t
*ha
)
1153 /* Assume a 32bit DMA mask. */
1154 ha
->flags
.enable_64bit_addressing
= 0;
1156 if (!dma_set_mask(&ha
->pdev
->dev
, DMA_64BIT_MASK
)) {
1157 /* Any upper-dword bits set? */
1158 if (MSD(dma_get_required_mask(&ha
->pdev
->dev
)) &&
1159 !pci_set_consistent_dma_mask(ha
->pdev
, DMA_64BIT_MASK
)) {
1160 /* Ok, a 64bit DMA mask is applicable. */
1161 ha
->flags
.enable_64bit_addressing
= 1;
1162 ha
->isp_ops
->calc_req_entries
= qla2x00_calc_iocbs_64
;
1163 ha
->isp_ops
->build_iocbs
= qla2x00_build_scsi_iocbs_64
;
1168 dma_set_mask(&ha
->pdev
->dev
, DMA_32BIT_MASK
);
1169 pci_set_consistent_dma_mask(ha
->pdev
, DMA_32BIT_MASK
);
1173 qla2x00_enable_intrs(scsi_qla_host_t
*ha
)
1175 unsigned long flags
= 0;
1176 struct device_reg_2xxx __iomem
*reg
= &ha
->iobase
->isp
;
1178 spin_lock_irqsave(&ha
->hardware_lock
, flags
);
1179 ha
->interrupts_on
= 1;
1180 /* enable risc and host interrupts */
1181 WRT_REG_WORD(®
->ictrl
, ICR_EN_INT
| ICR_EN_RISC
);
1182 RD_REG_WORD(®
->ictrl
);
1183 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
1188 qla2x00_disable_intrs(scsi_qla_host_t
*ha
)
1190 unsigned long flags
= 0;
1191 struct device_reg_2xxx __iomem
*reg
= &ha
->iobase
->isp
;
1193 spin_lock_irqsave(&ha
->hardware_lock
, flags
);
1194 ha
->interrupts_on
= 0;
1195 /* disable risc and host interrupts */
1196 WRT_REG_WORD(®
->ictrl
, 0);
1197 RD_REG_WORD(®
->ictrl
);
1198 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
1202 qla24xx_enable_intrs(scsi_qla_host_t
*ha
)
1204 unsigned long flags
= 0;
1205 struct device_reg_24xx __iomem
*reg
= &ha
->iobase
->isp24
;
1207 spin_lock_irqsave(&ha
->hardware_lock
, flags
);
1208 ha
->interrupts_on
= 1;
1209 WRT_REG_DWORD(®
->ictrl
, ICRX_EN_RISC_INT
);
1210 RD_REG_DWORD(®
->ictrl
);
1211 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
1215 qla24xx_disable_intrs(scsi_qla_host_t
*ha
)
1217 unsigned long flags
= 0;
1218 struct device_reg_24xx __iomem
*reg
= &ha
->iobase
->isp24
;
1220 spin_lock_irqsave(&ha
->hardware_lock
, flags
);
1221 ha
->interrupts_on
= 0;
1222 WRT_REG_DWORD(®
->ictrl
, 0);
1223 RD_REG_DWORD(®
->ictrl
);
1224 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
1227 static struct isp_operations qla2100_isp_ops
= {
1228 .pci_config
= qla2100_pci_config
,
1229 .reset_chip
= qla2x00_reset_chip
,
1230 .chip_diag
= qla2x00_chip_diag
,
1231 .config_rings
= qla2x00_config_rings
,
1232 .reset_adapter
= qla2x00_reset_adapter
,
1233 .nvram_config
= qla2x00_nvram_config
,
1234 .update_fw_options
= qla2x00_update_fw_options
,
1235 .load_risc
= qla2x00_load_risc
,
1236 .pci_info_str
= qla2x00_pci_info_str
,
1237 .fw_version_str
= qla2x00_fw_version_str
,
1238 .intr_handler
= qla2100_intr_handler
,
1239 .enable_intrs
= qla2x00_enable_intrs
,
1240 .disable_intrs
= qla2x00_disable_intrs
,
1241 .abort_command
= qla2x00_abort_command
,
1242 .target_reset
= qla2x00_abort_target
,
1243 .lun_reset
= qla2x00_lun_reset
,
1244 .fabric_login
= qla2x00_login_fabric
,
1245 .fabric_logout
= qla2x00_fabric_logout
,
1246 .calc_req_entries
= qla2x00_calc_iocbs_32
,
1247 .build_iocbs
= qla2x00_build_scsi_iocbs_32
,
1248 .prep_ms_iocb
= qla2x00_prep_ms_iocb
,
1249 .prep_ms_fdmi_iocb
= qla2x00_prep_ms_fdmi_iocb
,
1250 .read_nvram
= qla2x00_read_nvram_data
,
1251 .write_nvram
= qla2x00_write_nvram_data
,
1252 .fw_dump
= qla2100_fw_dump
,
1255 .beacon_blink
= NULL
,
1256 .read_optrom
= qla2x00_read_optrom_data
,
1257 .write_optrom
= qla2x00_write_optrom_data
,
1258 .get_flash_version
= qla2x00_get_flash_version
,
1261 static struct isp_operations qla2300_isp_ops
= {
1262 .pci_config
= qla2300_pci_config
,
1263 .reset_chip
= qla2x00_reset_chip
,
1264 .chip_diag
= qla2x00_chip_diag
,
1265 .config_rings
= qla2x00_config_rings
,
1266 .reset_adapter
= qla2x00_reset_adapter
,
1267 .nvram_config
= qla2x00_nvram_config
,
1268 .update_fw_options
= qla2x00_update_fw_options
,
1269 .load_risc
= qla2x00_load_risc
,
1270 .pci_info_str
= qla2x00_pci_info_str
,
1271 .fw_version_str
= qla2x00_fw_version_str
,
1272 .intr_handler
= qla2300_intr_handler
,
1273 .enable_intrs
= qla2x00_enable_intrs
,
1274 .disable_intrs
= qla2x00_disable_intrs
,
1275 .abort_command
= qla2x00_abort_command
,
1276 .target_reset
= qla2x00_abort_target
,
1277 .lun_reset
= qla2x00_lun_reset
,
1278 .fabric_login
= qla2x00_login_fabric
,
1279 .fabric_logout
= qla2x00_fabric_logout
,
1280 .calc_req_entries
= qla2x00_calc_iocbs_32
,
1281 .build_iocbs
= qla2x00_build_scsi_iocbs_32
,
1282 .prep_ms_iocb
= qla2x00_prep_ms_iocb
,
1283 .prep_ms_fdmi_iocb
= qla2x00_prep_ms_fdmi_iocb
,
1284 .read_nvram
= qla2x00_read_nvram_data
,
1285 .write_nvram
= qla2x00_write_nvram_data
,
1286 .fw_dump
= qla2300_fw_dump
,
1287 .beacon_on
= qla2x00_beacon_on
,
1288 .beacon_off
= qla2x00_beacon_off
,
1289 .beacon_blink
= qla2x00_beacon_blink
,
1290 .read_optrom
= qla2x00_read_optrom_data
,
1291 .write_optrom
= qla2x00_write_optrom_data
,
1292 .get_flash_version
= qla2x00_get_flash_version
,
1295 static struct isp_operations qla24xx_isp_ops
= {
1296 .pci_config
= qla24xx_pci_config
,
1297 .reset_chip
= qla24xx_reset_chip
,
1298 .chip_diag
= qla24xx_chip_diag
,
1299 .config_rings
= qla24xx_config_rings
,
1300 .reset_adapter
= qla24xx_reset_adapter
,
1301 .nvram_config
= qla24xx_nvram_config
,
1302 .update_fw_options
= qla24xx_update_fw_options
,
1303 .load_risc
= qla24xx_load_risc
,
1304 .pci_info_str
= qla24xx_pci_info_str
,
1305 .fw_version_str
= qla24xx_fw_version_str
,
1306 .intr_handler
= qla24xx_intr_handler
,
1307 .enable_intrs
= qla24xx_enable_intrs
,
1308 .disable_intrs
= qla24xx_disable_intrs
,
1309 .abort_command
= qla24xx_abort_command
,
1310 .target_reset
= qla24xx_abort_target
,
1311 .lun_reset
= qla24xx_lun_reset
,
1312 .fabric_login
= qla24xx_login_fabric
,
1313 .fabric_logout
= qla24xx_fabric_logout
,
1314 .calc_req_entries
= NULL
,
1315 .build_iocbs
= NULL
,
1316 .prep_ms_iocb
= qla24xx_prep_ms_iocb
,
1317 .prep_ms_fdmi_iocb
= qla24xx_prep_ms_fdmi_iocb
,
1318 .read_nvram
= qla24xx_read_nvram_data
,
1319 .write_nvram
= qla24xx_write_nvram_data
,
1320 .fw_dump
= qla24xx_fw_dump
,
1321 .beacon_on
= qla24xx_beacon_on
,
1322 .beacon_off
= qla24xx_beacon_off
,
1323 .beacon_blink
= qla24xx_beacon_blink
,
1324 .read_optrom
= qla24xx_read_optrom_data
,
1325 .write_optrom
= qla24xx_write_optrom_data
,
1326 .get_flash_version
= qla24xx_get_flash_version
,
1329 static struct isp_operations qla25xx_isp_ops
= {
1330 .pci_config
= qla25xx_pci_config
,
1331 .reset_chip
= qla24xx_reset_chip
,
1332 .chip_diag
= qla24xx_chip_diag
,
1333 .config_rings
= qla24xx_config_rings
,
1334 .reset_adapter
= qla24xx_reset_adapter
,
1335 .nvram_config
= qla24xx_nvram_config
,
1336 .update_fw_options
= qla24xx_update_fw_options
,
1337 .load_risc
= qla24xx_load_risc
,
1338 .pci_info_str
= qla24xx_pci_info_str
,
1339 .fw_version_str
= qla24xx_fw_version_str
,
1340 .intr_handler
= qla24xx_intr_handler
,
1341 .enable_intrs
= qla24xx_enable_intrs
,
1342 .disable_intrs
= qla24xx_disable_intrs
,
1343 .abort_command
= qla24xx_abort_command
,
1344 .target_reset
= qla24xx_abort_target
,
1345 .lun_reset
= qla24xx_lun_reset
,
1346 .fabric_login
= qla24xx_login_fabric
,
1347 .fabric_logout
= qla24xx_fabric_logout
,
1348 .calc_req_entries
= NULL
,
1349 .build_iocbs
= NULL
,
1350 .prep_ms_iocb
= qla24xx_prep_ms_iocb
,
1351 .prep_ms_fdmi_iocb
= qla24xx_prep_ms_fdmi_iocb
,
1352 .read_nvram
= qla25xx_read_nvram_data
,
1353 .write_nvram
= qla25xx_write_nvram_data
,
1354 .fw_dump
= qla25xx_fw_dump
,
1355 .beacon_on
= qla24xx_beacon_on
,
1356 .beacon_off
= qla24xx_beacon_off
,
1357 .beacon_blink
= qla24xx_beacon_blink
,
1358 .read_optrom
= qla25xx_read_optrom_data
,
1359 .write_optrom
= qla24xx_write_optrom_data
,
1360 .get_flash_version
= qla24xx_get_flash_version
,
1364 qla2x00_set_isp_flags(scsi_qla_host_t
*ha
)
1366 ha
->device_type
= DT_EXTENDED_IDS
;
1367 switch (ha
->pdev
->device
) {
1368 case PCI_DEVICE_ID_QLOGIC_ISP2100
:
1369 ha
->device_type
|= DT_ISP2100
;
1370 ha
->device_type
&= ~DT_EXTENDED_IDS
;
1371 ha
->fw_srisc_address
= RISC_START_ADDRESS_2100
;
1373 case PCI_DEVICE_ID_QLOGIC_ISP2200
:
1374 ha
->device_type
|= DT_ISP2200
;
1375 ha
->device_type
&= ~DT_EXTENDED_IDS
;
1376 ha
->fw_srisc_address
= RISC_START_ADDRESS_2100
;
1378 case PCI_DEVICE_ID_QLOGIC_ISP2300
:
1379 ha
->device_type
|= DT_ISP2300
;
1380 ha
->device_type
|= DT_ZIO_SUPPORTED
;
1381 ha
->fw_srisc_address
= RISC_START_ADDRESS_2300
;
1383 case PCI_DEVICE_ID_QLOGIC_ISP2312
:
1384 ha
->device_type
|= DT_ISP2312
;
1385 ha
->device_type
|= DT_ZIO_SUPPORTED
;
1386 ha
->fw_srisc_address
= RISC_START_ADDRESS_2300
;
1388 case PCI_DEVICE_ID_QLOGIC_ISP2322
:
1389 ha
->device_type
|= DT_ISP2322
;
1390 ha
->device_type
|= DT_ZIO_SUPPORTED
;
1391 if (ha
->pdev
->subsystem_vendor
== 0x1028 &&
1392 ha
->pdev
->subsystem_device
== 0x0170)
1393 ha
->device_type
|= DT_OEM_001
;
1394 ha
->fw_srisc_address
= RISC_START_ADDRESS_2300
;
1396 case PCI_DEVICE_ID_QLOGIC_ISP6312
:
1397 ha
->device_type
|= DT_ISP6312
;
1398 ha
->fw_srisc_address
= RISC_START_ADDRESS_2300
;
1400 case PCI_DEVICE_ID_QLOGIC_ISP6322
:
1401 ha
->device_type
|= DT_ISP6322
;
1402 ha
->fw_srisc_address
= RISC_START_ADDRESS_2300
;
1404 case PCI_DEVICE_ID_QLOGIC_ISP2422
:
1405 ha
->device_type
|= DT_ISP2422
;
1406 ha
->device_type
|= DT_ZIO_SUPPORTED
;
1407 ha
->device_type
|= DT_FWI2
;
1408 ha
->device_type
|= DT_IIDMA
;
1409 ha
->fw_srisc_address
= RISC_START_ADDRESS_2400
;
1411 case PCI_DEVICE_ID_QLOGIC_ISP2432
:
1412 ha
->device_type
|= DT_ISP2432
;
1413 ha
->device_type
|= DT_ZIO_SUPPORTED
;
1414 ha
->device_type
|= DT_FWI2
;
1415 ha
->device_type
|= DT_IIDMA
;
1416 ha
->fw_srisc_address
= RISC_START_ADDRESS_2400
;
1418 case PCI_DEVICE_ID_QLOGIC_ISP8432
:
1419 ha
->device_type
|= DT_ISP8432
;
1420 ha
->device_type
|= DT_ZIO_SUPPORTED
;
1421 ha
->device_type
|= DT_FWI2
;
1422 ha
->device_type
|= DT_IIDMA
;
1423 ha
->fw_srisc_address
= RISC_START_ADDRESS_2400
;
1425 case PCI_DEVICE_ID_QLOGIC_ISP5422
:
1426 ha
->device_type
|= DT_ISP5422
;
1427 ha
->device_type
|= DT_FWI2
;
1428 ha
->fw_srisc_address
= RISC_START_ADDRESS_2400
;
1430 case PCI_DEVICE_ID_QLOGIC_ISP5432
:
1431 ha
->device_type
|= DT_ISP5432
;
1432 ha
->device_type
|= DT_FWI2
;
1433 ha
->fw_srisc_address
= RISC_START_ADDRESS_2400
;
1435 case PCI_DEVICE_ID_QLOGIC_ISP2532
:
1436 ha
->device_type
|= DT_ISP2532
;
1437 ha
->device_type
|= DT_ZIO_SUPPORTED
;
1438 ha
->device_type
|= DT_FWI2
;
1439 ha
->device_type
|= DT_IIDMA
;
1440 ha
->fw_srisc_address
= RISC_START_ADDRESS_2400
;
1446 qla2x00_iospace_config(scsi_qla_host_t
*ha
)
1448 resource_size_t pio
;
1450 if (pci_request_selected_regions(ha
->pdev
, ha
->bars
,
1451 QLA2XXX_DRIVER_NAME
)) {
1452 qla_printk(KERN_WARNING
, ha
,
1453 "Failed to reserve PIO/MMIO regions (%s)\n",
1454 pci_name(ha
->pdev
));
1456 goto iospace_error_exit
;
1458 if (!(ha
->bars
& 1))
1461 /* We only need PIO for Flash operations on ISP2312 v2 chips. */
1462 pio
= pci_resource_start(ha
->pdev
, 0);
1463 if (pci_resource_flags(ha
->pdev
, 0) & IORESOURCE_IO
) {
1464 if (pci_resource_len(ha
->pdev
, 0) < MIN_IOBASE_LEN
) {
1465 qla_printk(KERN_WARNING
, ha
,
1466 "Invalid PCI I/O region size (%s)...\n",
1467 pci_name(ha
->pdev
));
1471 qla_printk(KERN_WARNING
, ha
,
1472 "region #0 not a PIO resource (%s)...\n",
1473 pci_name(ha
->pdev
));
1476 ha
->pio_address
= pio
;
1479 /* Use MMIO operations for all accesses. */
1480 if (!(pci_resource_flags(ha
->pdev
, 1) & IORESOURCE_MEM
)) {
1481 qla_printk(KERN_ERR
, ha
,
1482 "region #1 not an MMIO resource (%s), aborting\n",
1483 pci_name(ha
->pdev
));
1484 goto iospace_error_exit
;
1486 if (pci_resource_len(ha
->pdev
, 1) < MIN_IOBASE_LEN
) {
1487 qla_printk(KERN_ERR
, ha
,
1488 "Invalid PCI mem region size (%s), aborting\n",
1489 pci_name(ha
->pdev
));
1490 goto iospace_error_exit
;
1493 ha
->iobase
= ioremap(pci_resource_start(ha
->pdev
, 1), MIN_IOBASE_LEN
);
1495 qla_printk(KERN_ERR
, ha
,
1496 "cannot remap MMIO (%s), aborting\n", pci_name(ha
->pdev
));
1498 goto iospace_error_exit
;
1508 qla2xxx_scan_start(struct Scsi_Host
*shost
)
1510 scsi_qla_host_t
*ha
= shost_priv(shost
);
1512 set_bit(LOOP_RESYNC_NEEDED
, &ha
->dpc_flags
);
1513 set_bit(LOCAL_LOOP_UPDATE
, &ha
->dpc_flags
);
1514 set_bit(RSCN_UPDATE
, &ha
->dpc_flags
);
1518 qla2xxx_scan_finished(struct Scsi_Host
*shost
, unsigned long time
)
1520 scsi_qla_host_t
*ha
= shost_priv(shost
);
1524 if (time
> ha
->loop_reset_delay
* HZ
)
1527 return atomic_read(&ha
->loop_state
) == LOOP_READY
;
1531 * PCI driver interface
1533 static int __devinit
1534 qla2x00_probe_one(struct pci_dev
*pdev
, const struct pci_device_id
*id
)
1537 struct Scsi_Host
*host
;
1538 scsi_qla_host_t
*ha
;
1541 struct scsi_host_template
*sht
;
1542 int bars
, mem_only
= 0;
1544 bars
= pci_select_bars(pdev
, IORESOURCE_MEM
| IORESOURCE_IO
);
1545 sht
= &qla2x00_driver_template
;
1546 if (pdev
->device
== PCI_DEVICE_ID_QLOGIC_ISP2422
||
1547 pdev
->device
== PCI_DEVICE_ID_QLOGIC_ISP2432
||
1548 pdev
->device
== PCI_DEVICE_ID_QLOGIC_ISP8432
||
1549 pdev
->device
== PCI_DEVICE_ID_QLOGIC_ISP5422
||
1550 pdev
->device
== PCI_DEVICE_ID_QLOGIC_ISP5432
||
1551 pdev
->device
== PCI_DEVICE_ID_QLOGIC_ISP2532
) {
1552 bars
= pci_select_bars(pdev
, IORESOURCE_MEM
);
1553 sht
= &qla24xx_driver_template
;
1558 if (pci_enable_device_mem(pdev
))
1561 if (pci_enable_device(pdev
))
1565 if (pci_find_aer_capability(pdev
))
1566 if (pci_enable_pcie_error_reporting(pdev
))
1569 host
= scsi_host_alloc(sht
, sizeof(scsi_qla_host_t
));
1572 "qla2xxx: Couldn't allocate host from scsi layer!\n");
1573 goto probe_disable_device
;
1576 /* Clear our data area */
1577 ha
= shost_priv(host
);
1578 memset(ha
, 0, sizeof(scsi_qla_host_t
));
1582 ha
->host_no
= host
->host_no
;
1583 sprintf(ha
->host_str
, "%s_%ld", QLA2XXX_DRIVER_NAME
, ha
->host_no
);
1586 ha
->mem_only
= mem_only
;
1587 spin_lock_init(&ha
->hardware_lock
);
1589 /* Set ISP-type information. */
1590 qla2x00_set_isp_flags(ha
);
1592 /* Configure PCI I/O space */
1593 ret
= qla2x00_iospace_config(ha
);
1597 qla_printk(KERN_INFO
, ha
,
1598 "Found an ISP%04X, irq %d, iobase 0x%p\n", pdev
->device
, pdev
->irq
,
1601 ha
->prev_topology
= 0;
1602 ha
->init_cb_size
= sizeof(init_cb_t
);
1603 ha
->mgmt_svr_loop_id
= MANAGEMENT_SERVER
+ ha
->vp_idx
;
1604 ha
->link_data_rate
= PORT_SPEED_UNKNOWN
;
1605 ha
->optrom_size
= OPTROM_SIZE_2300
;
1607 ha
->max_q_depth
= MAX_Q_DEPTH
;
1608 if (ql2xmaxqdepth
!= 0 && ql2xmaxqdepth
<= 0xffffU
)
1609 ha
->max_q_depth
= ql2xmaxqdepth
;
1611 /* Assign ISP specific operations. */
1612 if (IS_QLA2100(ha
)) {
1613 host
->max_id
= MAX_TARGETS_2100
;
1614 ha
->mbx_count
= MAILBOX_REGISTER_COUNT_2100
;
1615 ha
->request_q_length
= REQUEST_ENTRY_CNT_2100
;
1616 ha
->response_q_length
= RESPONSE_ENTRY_CNT_2100
;
1617 ha
->last_loop_id
= SNS_LAST_LOOP_ID_2100
;
1618 host
->sg_tablesize
= 32;
1619 ha
->gid_list_info_size
= 4;
1620 ha
->isp_ops
= &qla2100_isp_ops
;
1621 } else if (IS_QLA2200(ha
)) {
1622 host
->max_id
= MAX_TARGETS_2200
;
1623 ha
->mbx_count
= MAILBOX_REGISTER_COUNT
;
1624 ha
->request_q_length
= REQUEST_ENTRY_CNT_2200
;
1625 ha
->response_q_length
= RESPONSE_ENTRY_CNT_2100
;
1626 ha
->last_loop_id
= SNS_LAST_LOOP_ID_2100
;
1627 ha
->gid_list_info_size
= 4;
1628 ha
->isp_ops
= &qla2100_isp_ops
;
1629 } else if (IS_QLA23XX(ha
)) {
1630 host
->max_id
= MAX_TARGETS_2200
;
1631 ha
->mbx_count
= MAILBOX_REGISTER_COUNT
;
1632 ha
->request_q_length
= REQUEST_ENTRY_CNT_2200
;
1633 ha
->response_q_length
= RESPONSE_ENTRY_CNT_2300
;
1634 ha
->last_loop_id
= SNS_LAST_LOOP_ID_2300
;
1635 ha
->gid_list_info_size
= 6;
1636 if (IS_QLA2322(ha
) || IS_QLA6322(ha
))
1637 ha
->optrom_size
= OPTROM_SIZE_2322
;
1638 ha
->isp_ops
= &qla2300_isp_ops
;
1639 } else if (IS_QLA24XX_TYPE(ha
)) {
1640 host
->max_id
= MAX_TARGETS_2200
;
1641 ha
->mbx_count
= MAILBOX_REGISTER_COUNT
;
1642 ha
->request_q_length
= REQUEST_ENTRY_CNT_24XX
;
1643 ha
->response_q_length
= RESPONSE_ENTRY_CNT_2300
;
1644 ha
->last_loop_id
= SNS_LAST_LOOP_ID_2300
;
1645 ha
->init_cb_size
= sizeof(struct mid_init_cb_24xx
);
1646 ha
->mgmt_svr_loop_id
= 10 + ha
->vp_idx
;
1647 ha
->gid_list_info_size
= 8;
1648 ha
->optrom_size
= OPTROM_SIZE_24XX
;
1649 ha
->isp_ops
= &qla24xx_isp_ops
;
1650 } else if (IS_QLA25XX(ha
)) {
1651 host
->max_id
= MAX_TARGETS_2200
;
1652 ha
->mbx_count
= MAILBOX_REGISTER_COUNT
;
1653 ha
->request_q_length
= REQUEST_ENTRY_CNT_24XX
;
1654 ha
->response_q_length
= RESPONSE_ENTRY_CNT_2300
;
1655 ha
->last_loop_id
= SNS_LAST_LOOP_ID_2300
;
1656 ha
->init_cb_size
= sizeof(struct mid_init_cb_24xx
);
1657 ha
->mgmt_svr_loop_id
= 10 + ha
->vp_idx
;
1658 ha
->gid_list_info_size
= 8;
1659 ha
->optrom_size
= OPTROM_SIZE_25XX
;
1660 ha
->isp_ops
= &qla25xx_isp_ops
;
1661 ha
->hw_event_start
= PCI_FUNC(pdev
->devfn
) ?
1662 FA_HW_EVENT1_ADDR
: FA_HW_EVENT0_ADDR
;
1664 host
->can_queue
= ha
->request_q_length
+ 128;
1666 /* load the F/W, read paramaters, and init the H/W */
1667 ha
->instance
= num_hosts
;
1669 mutex_init(&ha
->vport_lock
);
1670 init_completion(&ha
->mbx_cmd_comp
);
1671 complete(&ha
->mbx_cmd_comp
);
1672 init_completion(&ha
->mbx_intr_comp
);
1674 INIT_LIST_HEAD(&ha
->list
);
1675 INIT_LIST_HEAD(&ha
->fcports
);
1676 INIT_LIST_HEAD(&ha
->vp_list
);
1677 INIT_LIST_HEAD(&ha
->work_list
);
1679 set_bit(0, (unsigned long *) ha
->vp_idx_map
);
1681 qla2x00_config_dma_addressing(ha
);
1682 if (qla2x00_mem_alloc(ha
)) {
1683 qla_printk(KERN_WARNING
, ha
,
1684 "[ERROR] Failed to allocate memory for adapter\n");
1690 if (qla2x00_initialize_adapter(ha
)) {
1691 qla_printk(KERN_WARNING
, ha
,
1692 "Failed to initialize adapter\n");
1694 DEBUG2(printk("scsi(%ld): Failed to initialize adapter - "
1695 "Adapter flags %x.\n",
1696 ha
->host_no
, ha
->device_flags
));
1703 * Startup the kernel thread for this host adapter
1705 ha
->dpc_thread
= kthread_create(qla2x00_do_dpc
, ha
,
1706 "%s_dpc", ha
->host_str
);
1707 if (IS_ERR(ha
->dpc_thread
)) {
1708 qla_printk(KERN_WARNING
, ha
,
1709 "Unable to start DPC thread!\n");
1710 ret
= PTR_ERR(ha
->dpc_thread
);
1714 host
->this_id
= 255;
1715 host
->cmd_per_lun
= 3;
1716 host
->unique_id
= ha
->instance
;
1717 host
->max_cmd_len
= MAX_CMDSZ
;
1718 host
->max_channel
= MAX_BUSES
- 1;
1719 host
->max_lun
= MAX_LUNS
;
1720 host
->transportt
= qla2xxx_transport_template
;
1722 ret
= qla2x00_request_irqs(ha
);
1726 /* Initialized the timer */
1727 qla2x00_start_timer(ha
, qla2x00_timer
, WATCH_INTERVAL
);
1729 DEBUG2(printk("DEBUG: detect hba %ld at address = %p\n",
1732 pci_set_drvdata(pdev
, ha
);
1734 ha
->flags
.init_done
= 1;
1735 ha
->flags
.online
= 1;
1739 ret
= scsi_add_host(host
, &pdev
->dev
);
1743 scsi_scan_host(host
);
1745 qla2x00_alloc_sysfs_attr(ha
);
1747 qla2x00_init_host_attr(ha
);
1749 qla2x00_dfs_setup(ha
);
1751 qla_printk(KERN_INFO
, ha
, "\n"
1752 " QLogic Fibre Channel HBA Driver: %s\n"
1754 " ISP%04X: %s @ %s hdma%c, host#=%ld, fw=%s\n",
1755 qla2x00_version_str
, ha
->model_number
,
1756 ha
->model_desc
? ha
->model_desc
: "", pdev
->device
,
1757 ha
->isp_ops
->pci_info_str(ha
, pci_info
), pci_name(pdev
),
1758 ha
->flags
.enable_64bit_addressing
? '+': '-', ha
->host_no
,
1759 ha
->isp_ops
->fw_version_str(ha
, fw_str
));
1764 qla2x00_free_device(ha
);
1766 scsi_host_put(host
);
1768 probe_disable_device
:
1769 pci_disable_device(pdev
);
1776 qla2x00_remove_one(struct pci_dev
*pdev
)
1778 scsi_qla_host_t
*ha
;
1780 ha
= pci_get_drvdata(pdev
);
1782 qla2x00_dfs_remove(ha
);
1784 qla84xx_put_chip(ha
);
1786 qla2x00_free_sysfs_attr(ha
);
1788 fc_remove_host(ha
->host
);
1790 scsi_remove_host(ha
->host
);
1792 qla2x00_free_device(ha
);
1794 scsi_host_put(ha
->host
);
1796 pci_disable_device(pdev
);
1797 pci_set_drvdata(pdev
, NULL
);
1801 qla2x00_free_device(scsi_qla_host_t
*ha
)
1803 qla2x00_abort_all_cmds(ha
, DID_NO_CONNECT
<< 16);
1806 if (ha
->timer_active
)
1807 qla2x00_stop_timer(ha
);
1809 ha
->flags
.online
= 0;
1811 /* Kill the kernel thread for this host */
1812 if (ha
->dpc_thread
) {
1813 struct task_struct
*t
= ha
->dpc_thread
;
1816 * qla2xxx_wake_dpc checks for ->dpc_thread
1817 * so we need to zero it out.
1819 ha
->dpc_thread
= NULL
;
1823 if (ha
->flags
.fce_enabled
)
1824 qla2x00_disable_fce_trace(ha
, NULL
, NULL
);
1827 qla2x00_disable_eft_trace(ha
);
1829 /* Stop currently executing firmware. */
1830 qla2x00_try_to_stop_firmware(ha
);
1832 /* turn-off interrupts on the card */
1833 if (ha
->interrupts_on
)
1834 ha
->isp_ops
->disable_intrs(ha
);
1836 qla2x00_mem_free(ha
);
1838 qla2x00_free_irqs(ha
);
1840 /* release io space registers */
1842 iounmap(ha
->iobase
);
1843 pci_release_selected_regions(ha
->pdev
, ha
->bars
);
1847 qla2x00_schedule_rport_del(struct scsi_qla_host
*ha
, fc_port_t
*fcport
,
1850 struct fc_rport
*rport
;
1855 rport
= fcport
->rport
;
1857 spin_lock_irq(ha
->host
->host_lock
);
1858 fcport
->drport
= rport
;
1859 spin_unlock_irq(ha
->host
->host_lock
);
1860 set_bit(FCPORT_UPDATE_NEEDED
, &ha
->dpc_flags
);
1861 qla2xxx_wake_dpc(ha
);
1863 fc_remote_port_delete(rport
);
1867 * qla2x00_mark_device_lost Updates fcport state when device goes offline.
1869 * Input: ha = adapter block pointer. fcport = port structure pointer.
1875 void qla2x00_mark_device_lost(scsi_qla_host_t
*ha
, fc_port_t
*fcport
,
1876 int do_login
, int defer
)
1878 if (atomic_read(&fcport
->state
) == FCS_ONLINE
&&
1879 ha
->vp_idx
== fcport
->vp_idx
)
1880 qla2x00_schedule_rport_del(ha
, fcport
, defer
);
1883 * We may need to retry the login, so don't change the state of the
1884 * port but do the retries.
1886 if (atomic_read(&fcport
->state
) != FCS_DEVICE_DEAD
)
1887 atomic_set(&fcport
->state
, FCS_DEVICE_LOST
);
1892 if (fcport
->login_retry
== 0) {
1893 fcport
->login_retry
= ha
->login_retry_count
;
1894 set_bit(RELOGIN_NEEDED
, &ha
->dpc_flags
);
1896 DEBUG(printk("scsi(%ld): Port login retry: "
1897 "%02x%02x%02x%02x%02x%02x%02x%02x, "
1898 "id = 0x%04x retry cnt=%d\n",
1900 fcport
->port_name
[0],
1901 fcport
->port_name
[1],
1902 fcport
->port_name
[2],
1903 fcport
->port_name
[3],
1904 fcport
->port_name
[4],
1905 fcport
->port_name
[5],
1906 fcport
->port_name
[6],
1907 fcport
->port_name
[7],
1909 fcport
->login_retry
));
1914 * qla2x00_mark_all_devices_lost
1915 * Updates fcport state when device goes offline.
1918 * ha = adapter block pointer.
1919 * fcport = port structure pointer.
1927 qla2x00_mark_all_devices_lost(scsi_qla_host_t
*ha
, int defer
)
1930 scsi_qla_host_t
*pha
= to_qla_parent(ha
);
1932 list_for_each_entry(fcport
, &pha
->fcports
, list
) {
1933 if (ha
->vp_idx
!= 0 && ha
->vp_idx
!= fcport
->vp_idx
)
1936 * No point in marking the device as lost, if the device is
1939 if (atomic_read(&fcport
->state
) == FCS_DEVICE_DEAD
)
1941 if (atomic_read(&fcport
->state
) == FCS_ONLINE
) {
1943 qla2x00_schedule_rport_del(ha
, fcport
, defer
);
1944 else if (ha
->vp_idx
== fcport
->vp_idx
)
1945 qla2x00_schedule_rport_del(ha
, fcport
, defer
);
1947 atomic_set(&fcport
->state
, FCS_DEVICE_LOST
);
1951 qla2xxx_wake_dpc(ha
);
1956 * Allocates adapter memory.
1963 qla2x00_mem_alloc(scsi_qla_host_t
*ha
)
1967 ha
->request_ring
= dma_alloc_coherent(&ha
->pdev
->dev
,
1968 (ha
->request_q_length
+ 1) * sizeof(request_t
), &ha
->request_dma
,
1970 if (!ha
->request_ring
)
1973 ha
->response_ring
= dma_alloc_coherent(&ha
->pdev
->dev
,
1974 (ha
->response_q_length
+ 1) * sizeof(response_t
),
1975 &ha
->response_dma
, GFP_KERNEL
);
1976 if (!ha
->response_ring
)
1977 goto fail_free_request_ring
;
1979 ha
->gid_list
= dma_alloc_coherent(&ha
->pdev
->dev
, GID_LIST_SIZE
,
1980 &ha
->gid_list_dma
, GFP_KERNEL
);
1982 goto fail_free_response_ring
;
1984 ha
->init_cb
= dma_alloc_coherent(&ha
->pdev
->dev
, ha
->init_cb_size
,
1985 &ha
->init_cb_dma
, GFP_KERNEL
);
1987 goto fail_free_gid_list
;
1989 snprintf(name
, sizeof(name
), "%s_%ld", QLA2XXX_DRIVER_NAME
,
1991 ha
->s_dma_pool
= dma_pool_create(name
, &ha
->pdev
->dev
,
1992 DMA_POOL_SIZE
, 8, 0);
1993 if (!ha
->s_dma_pool
)
1994 goto fail_free_init_cb
;
1996 ha
->srb_mempool
= mempool_create_slab_pool(SRB_MIN_REQ
, srb_cachep
);
1997 if (!ha
->srb_mempool
)
1998 goto fail_free_s_dma_pool
;
2000 /* Get memory for cached NVRAM */
2001 ha
->nvram
= kzalloc(MAX_NVRAM_SIZE
, GFP_KERNEL
);
2003 goto fail_free_srb_mempool
;
2005 /* Allocate memory for SNS commands */
2006 if (IS_QLA2100(ha
) || IS_QLA2200(ha
)) {
2007 /* Get consistent memory allocated for SNS commands */
2008 ha
->sns_cmd
= dma_alloc_coherent(&ha
->pdev
->dev
,
2009 sizeof(struct sns_cmd_pkt
), &ha
->sns_cmd_dma
, GFP_KERNEL
);
2011 goto fail_free_nvram
;
2013 /* Get consistent memory allocated for MS IOCB */
2014 ha
->ms_iocb
= dma_pool_alloc(ha
->s_dma_pool
, GFP_KERNEL
,
2017 goto fail_free_nvram
;
2019 /* Get consistent memory allocated for CT SNS commands */
2020 ha
->ct_sns
= dma_alloc_coherent(&ha
->pdev
->dev
,
2021 sizeof(struct ct_sns_pkt
), &ha
->ct_sns_dma
, GFP_KERNEL
);
2023 goto fail_free_ms_iocb
;
2029 dma_pool_free(ha
->s_dma_pool
, ha
->ms_iocb
, ha
->ms_iocb_dma
);
2031 ha
->ms_iocb_dma
= 0;
2035 fail_free_srb_mempool
:
2036 mempool_destroy(ha
->srb_mempool
);
2037 ha
->srb_mempool
= NULL
;
2038 fail_free_s_dma_pool
:
2039 dma_pool_destroy(ha
->s_dma_pool
);
2040 ha
->s_dma_pool
= NULL
;
2042 dma_free_coherent(&ha
->pdev
->dev
, ha
->init_cb_size
, ha
->init_cb
,
2045 ha
->init_cb_dma
= 0;
2047 dma_free_coherent(&ha
->pdev
->dev
, GID_LIST_SIZE
, ha
->gid_list
,
2049 ha
->gid_list
= NULL
;
2050 ha
->gid_list_dma
= 0;
2051 fail_free_response_ring
:
2052 dma_free_coherent(&ha
->pdev
->dev
, (ha
->response_q_length
+ 1) *
2053 sizeof(response_t
), ha
->response_ring
, ha
->response_dma
);
2054 ha
->response_ring
= NULL
;
2055 ha
->response_dma
= 0;
2056 fail_free_request_ring
:
2057 dma_free_coherent(&ha
->pdev
->dev
, (ha
->request_q_length
+ 1) *
2058 sizeof(request_t
), ha
->request_ring
, ha
->request_dma
);
2059 ha
->request_ring
= NULL
;
2060 ha
->request_dma
= 0;
2067 * Frees all adapter allocated memory.
2070 * ha = adapter block pointer.
2073 qla2x00_mem_free(scsi_qla_host_t
*ha
)
2075 struct list_head
*fcpl
, *fcptemp
;
2078 if (ha
->srb_mempool
)
2079 mempool_destroy(ha
->srb_mempool
);
2082 dma_free_coherent(&ha
->pdev
->dev
, FCE_SIZE
, ha
->fce
,
2087 dma_free_coherent(&ha
->pdev
->dev
,
2088 ntohl(ha
->fw_dump
->eft_size
), ha
->eft
, ha
->eft_dma
);
2093 dma_free_coherent(&ha
->pdev
->dev
, sizeof(struct sns_cmd_pkt
),
2094 ha
->sns_cmd
, ha
->sns_cmd_dma
);
2097 dma_free_coherent(&ha
->pdev
->dev
, sizeof(struct ct_sns_pkt
),
2098 ha
->ct_sns
, ha
->ct_sns_dma
);
2101 dma_pool_free(ha
->s_dma_pool
, ha
->sfp_data
, ha
->sfp_data_dma
);
2104 dma_pool_free(ha
->s_dma_pool
, ha
->ms_iocb
, ha
->ms_iocb_dma
);
2107 dma_pool_destroy(ha
->s_dma_pool
);
2110 dma_free_coherent(&ha
->pdev
->dev
, ha
->init_cb_size
,
2111 ha
->init_cb
, ha
->init_cb_dma
);
2114 dma_free_coherent(&ha
->pdev
->dev
, GID_LIST_SIZE
, ha
->gid_list
,
2117 if (ha
->response_ring
)
2118 dma_free_coherent(&ha
->pdev
->dev
,
2119 (ha
->response_q_length
+ 1) * sizeof(response_t
),
2120 ha
->response_ring
, ha
->response_dma
);
2122 if (ha
->request_ring
)
2123 dma_free_coherent(&ha
->pdev
->dev
,
2124 (ha
->request_q_length
+ 1) * sizeof(request_t
),
2125 ha
->request_ring
, ha
->request_dma
);
2127 ha
->srb_mempool
= NULL
;
2131 ha
->sns_cmd_dma
= 0;
2135 ha
->ms_iocb_dma
= 0;
2137 ha
->init_cb_dma
= 0;
2139 ha
->s_dma_pool
= NULL
;
2141 ha
->gid_list
= NULL
;
2142 ha
->gid_list_dma
= 0;
2144 ha
->response_ring
= NULL
;
2145 ha
->response_dma
= 0;
2146 ha
->request_ring
= NULL
;
2147 ha
->request_dma
= 0;
2149 list_for_each_safe(fcpl
, fcptemp
, &ha
->fcports
) {
2150 fcport
= list_entry(fcpl
, fc_port_t
, list
);
2153 list_del_init(&fcport
->list
);
2156 INIT_LIST_HEAD(&ha
->fcports
);
2160 ha
->fw_dump_reading
= 0;
2162 vfree(ha
->optrom_buffer
);
2166 static struct qla_work_evt
*
2167 qla2x00_alloc_work(struct scsi_qla_host
*ha
, enum qla_work_type type
,
2170 struct qla_work_evt
*e
;
2172 e
= kzalloc(sizeof(struct qla_work_evt
), locked
? GFP_ATOMIC
:
2177 INIT_LIST_HEAD(&e
->list
);
2179 e
->flags
= QLA_EVT_FLAG_FREE
;
2184 qla2x00_post_work(struct scsi_qla_host
*ha
, struct qla_work_evt
*e
, int locked
)
2186 unsigned long flags
;
2187 scsi_qla_host_t
*pha
= to_qla_parent(ha
);
2190 spin_lock_irqsave(&pha
->hardware_lock
, flags
);
2191 list_add_tail(&e
->list
, &ha
->work_list
);
2192 qla2xxx_wake_dpc(ha
);
2194 spin_unlock_irqrestore(&pha
->hardware_lock
, flags
);
2199 qla2x00_post_aen_work(struct scsi_qla_host
*ha
, enum fc_host_event_code code
,
2202 struct qla_work_evt
*e
;
2204 e
= qla2x00_alloc_work(ha
, QLA_EVT_AEN
, 1);
2206 return QLA_FUNCTION_FAILED
;
2208 e
->u
.aen
.code
= code
;
2209 e
->u
.aen
.data
= data
;
2210 return qla2x00_post_work(ha
, e
, 1);
2214 qla2x00_post_hwe_work(struct scsi_qla_host
*ha
, uint16_t code
, uint16_t d1
,
2215 uint16_t d2
, uint16_t d3
)
2217 struct qla_work_evt
*e
;
2219 e
= qla2x00_alloc_work(ha
, QLA_EVT_HWE_LOG
, 1);
2221 return QLA_FUNCTION_FAILED
;
2223 e
->u
.hwe
.code
= code
;
2227 return qla2x00_post_work(ha
, e
, 1);
2231 qla2x00_do_work(struct scsi_qla_host
*ha
)
2233 struct qla_work_evt
*e
;
2234 scsi_qla_host_t
*pha
= to_qla_parent(ha
);
2236 spin_lock_irq(&pha
->hardware_lock
);
2237 while (!list_empty(&ha
->work_list
)) {
2238 e
= list_entry(ha
->work_list
.next
, struct qla_work_evt
, list
);
2239 list_del_init(&e
->list
);
2240 spin_unlock_irq(&pha
->hardware_lock
);
2244 fc_host_post_event(ha
->host
, fc_get_event_number(),
2245 e
->u
.aen
.code
, e
->u
.aen
.data
);
2247 case QLA_EVT_HWE_LOG
:
2248 qla2xxx_hw_event_log(ha
, e
->u
.hwe
.code
, e
->u
.hwe
.d1
,
2249 e
->u
.hwe
.d2
, e
->u
.hwe
.d3
);
2252 if (e
->flags
& QLA_EVT_FLAG_FREE
)
2254 spin_lock_irq(&pha
->hardware_lock
);
2256 spin_unlock_irq(&pha
->hardware_lock
);
2259 /**************************************************************************
2261 * This kernel thread is a task that is schedule by the interrupt handler
2262 * to perform the background processing for interrupts.
2265 * This task always run in the context of a kernel thread. It
2266 * is kick-off by the driver's detect code and starts up
2267 * up one per adapter. It immediately goes to sleep and waits for
2268 * some fibre event. When either the interrupt handler or
2269 * the timer routine detects a event it will one of the task
2270 * bits then wake us up.
2271 **************************************************************************/
2273 qla2x00_do_dpc(void *data
)
2276 scsi_qla_host_t
*ha
;
2279 uint16_t next_loopid
;
2280 struct scsi_qla_host
*vha
;
2284 ha
= (scsi_qla_host_t
*)data
;
2286 set_user_nice(current
, -20);
2288 while (!kthread_should_stop()) {
2289 DEBUG3(printk("qla2x00: DPC handler sleeping\n"));
2291 set_current_state(TASK_INTERRUPTIBLE
);
2293 __set_current_state(TASK_RUNNING
);
2295 DEBUG3(printk("qla2x00: DPC handler waking up\n"));
2297 /* Initialization not yet finished. Don't do anything yet. */
2298 if (!ha
->flags
.init_done
)
2301 DEBUG3(printk("scsi(%ld): DPC handler\n", ha
->host_no
));
2305 if (ha
->flags
.mbox_busy
) {
2310 qla2x00_do_work(ha
);
2312 if (test_and_clear_bit(ISP_ABORT_NEEDED
, &ha
->dpc_flags
)) {
2314 DEBUG(printk("scsi(%ld): dpc: sched "
2315 "qla2x00_abort_isp ha = %p\n",
2317 if (!(test_and_set_bit(ABORT_ISP_ACTIVE
,
2320 if (qla2x00_abort_isp(ha
)) {
2321 /* failed. retry later */
2322 set_bit(ISP_ABORT_NEEDED
,
2325 clear_bit(ABORT_ISP_ACTIVE
, &ha
->dpc_flags
);
2328 for_each_mapped_vp_idx(ha
, i
) {
2329 list_for_each_entry(vha
, &ha
->vp_list
,
2331 if (i
== vha
->vp_idx
) {
2332 set_bit(ISP_ABORT_NEEDED
,
2339 DEBUG(printk("scsi(%ld): dpc: qla2x00_abort_isp end\n",
2343 if (test_and_clear_bit(FCPORT_UPDATE_NEEDED
, &ha
->dpc_flags
))
2344 qla2x00_update_fcports(ha
);
2346 if (test_and_clear_bit(RESET_MARKER_NEEDED
, &ha
->dpc_flags
) &&
2347 (!(test_and_set_bit(RESET_ACTIVE
, &ha
->dpc_flags
)))) {
2349 DEBUG(printk("scsi(%ld): qla2x00_reset_marker()\n",
2352 qla2x00_rst_aen(ha
);
2353 clear_bit(RESET_ACTIVE
, &ha
->dpc_flags
);
2356 /* Retry each device up to login retry count */
2357 if ((test_and_clear_bit(RELOGIN_NEEDED
, &ha
->dpc_flags
)) &&
2358 !test_bit(LOOP_RESYNC_NEEDED
, &ha
->dpc_flags
) &&
2359 atomic_read(&ha
->loop_state
) != LOOP_DOWN
) {
2361 DEBUG(printk("scsi(%ld): qla2x00_port_login()\n",
2365 list_for_each_entry(fcport
, &ha
->fcports
, list
) {
2367 * If the port is not ONLINE then try to login
2368 * to it if we haven't run out of retries.
2370 if (atomic_read(&fcport
->state
) != FCS_ONLINE
&&
2371 fcport
->login_retry
) {
2373 if (fcport
->flags
& FCF_FABRIC_DEVICE
) {
2376 ha
->isp_ops
->fabric_logout(
2377 ha
, fcport
->loop_id
,
2378 fcport
->d_id
.b
.domain
,
2379 fcport
->d_id
.b
.area
,
2380 fcport
->d_id
.b
.al_pa
);
2381 status
= qla2x00_fabric_login(
2382 ha
, fcport
, &next_loopid
);
2385 qla2x00_local_device_login(
2388 fcport
->login_retry
--;
2389 if (status
== QLA_SUCCESS
) {
2390 fcport
->old_loop_id
= fcport
->loop_id
;
2392 DEBUG(printk("scsi(%ld): port login OK: logged in ID 0x%x\n",
2393 ha
->host_no
, fcport
->loop_id
));
2395 qla2x00_update_fcport(ha
,
2397 } else if (status
== 1) {
2398 set_bit(RELOGIN_NEEDED
, &ha
->dpc_flags
);
2399 /* retry the login again */
2400 DEBUG(printk("scsi(%ld): Retrying %d login again loop_id 0x%x\n",
2402 fcport
->login_retry
, fcport
->loop_id
));
2404 fcport
->login_retry
= 0;
2406 if (fcport
->login_retry
== 0 && status
!= QLA_SUCCESS
)
2407 fcport
->loop_id
= FC_NO_LOOP_ID
;
2409 if (test_bit(LOOP_RESYNC_NEEDED
, &ha
->dpc_flags
))
2412 DEBUG(printk("scsi(%ld): qla2x00_port_login - end\n",
2416 if (test_and_clear_bit(LOOP_RESYNC_NEEDED
, &ha
->dpc_flags
)) {
2418 DEBUG(printk("scsi(%ld): qla2x00_loop_resync()\n",
2421 if (!(test_and_set_bit(LOOP_RESYNC_ACTIVE
,
2424 rval
= qla2x00_loop_resync(ha
);
2426 clear_bit(LOOP_RESYNC_ACTIVE
, &ha
->dpc_flags
);
2429 DEBUG(printk("scsi(%ld): qla2x00_loop_resync - end\n",
2433 if (!ha
->interrupts_on
)
2434 ha
->isp_ops
->enable_intrs(ha
);
2436 if (test_and_clear_bit(BEACON_BLINK_NEEDED
, &ha
->dpc_flags
))
2437 ha
->isp_ops
->beacon_blink(ha
);
2439 qla2x00_do_dpc_all_vps(ha
);
2442 } /* End of while(1) */
2444 DEBUG(printk("scsi(%ld): DPC handler exiting\n", ha
->host_no
));
2447 * Make sure that nobody tries to wake us up again.
2455 qla2xxx_wake_dpc(scsi_qla_host_t
*ha
)
2458 wake_up_process(ha
->dpc_thread
);
2463 * Processes asynchronous reset.
2466 * ha = adapter block pointer.
2469 qla2x00_rst_aen(scsi_qla_host_t
*ha
)
2471 if (ha
->flags
.online
&& !ha
->flags
.reset_active
&&
2472 !atomic_read(&ha
->loop_down_timer
) &&
2473 !(test_bit(ABORT_ISP_ACTIVE
, &ha
->dpc_flags
))) {
2475 clear_bit(RESET_MARKER_NEEDED
, &ha
->dpc_flags
);
2478 * Issue marker command only when we are going to start
2481 ha
->marker_needed
= 1;
2482 } while (!atomic_read(&ha
->loop_down_timer
) &&
2483 (test_bit(RESET_MARKER_NEEDED
, &ha
->dpc_flags
)));
2488 qla2x00_sp_free_dma(scsi_qla_host_t
*ha
, srb_t
*sp
)
2490 struct scsi_cmnd
*cmd
= sp
->cmd
;
2492 if (sp
->flags
& SRB_DMA_VALID
) {
2493 scsi_dma_unmap(cmd
);
2494 sp
->flags
&= ~SRB_DMA_VALID
;
2500 qla2x00_sp_compl(scsi_qla_host_t
*ha
, srb_t
*sp
)
2502 struct scsi_cmnd
*cmd
= sp
->cmd
;
2504 qla2x00_sp_free_dma(ha
, sp
);
2506 mempool_free(sp
, ha
->srb_mempool
);
2508 cmd
->scsi_done(cmd
);
2511 /**************************************************************************
2517 * Context: Interrupt
2518 ***************************************************************************/
2520 qla2x00_timer(scsi_qla_host_t
*ha
)
2522 unsigned long cpu_flags
= 0;
2528 scsi_qla_host_t
*pha
= to_qla_parent(ha
);
2531 * Ports - Port down timer.
2533 * Whenever, a port is in the LOST state we start decrementing its port
2534 * down timer every second until it reaches zero. Once it reaches zero
2535 * the port it marked DEAD.
2538 list_for_each_entry(fcport
, &ha
->fcports
, list
) {
2539 if (fcport
->port_type
!= FCT_TARGET
)
2542 if (atomic_read(&fcport
->state
) == FCS_DEVICE_LOST
) {
2544 if (atomic_read(&fcport
->port_down_timer
) == 0)
2547 if (atomic_dec_and_test(&fcport
->port_down_timer
) != 0)
2548 atomic_set(&fcport
->state
, FCS_DEVICE_DEAD
);
2550 DEBUG(printk("scsi(%ld): fcport-%d - port retry count: "
2553 t
, atomic_read(&fcport
->port_down_timer
)));
2556 } /* End of for fcport */
2559 /* Loop down handler. */
2560 if (atomic_read(&ha
->loop_down_timer
) > 0 &&
2561 !(test_bit(ABORT_ISP_ACTIVE
, &ha
->dpc_flags
)) && ha
->flags
.online
) {
2563 if (atomic_read(&ha
->loop_down_timer
) ==
2564 ha
->loop_down_abort_time
) {
2566 DEBUG(printk("scsi(%ld): Loop Down - aborting the "
2567 "queues before time expire\n",
2570 if (!IS_QLA2100(ha
) && ha
->link_down_timeout
)
2571 atomic_set(&ha
->loop_state
, LOOP_DEAD
);
2573 /* Schedule an ISP abort to return any tape commands. */
2574 /* NPIV - scan physical port only */
2576 spin_lock_irqsave(&ha
->hardware_lock
,
2579 index
< MAX_OUTSTANDING_COMMANDS
;
2583 sp
= ha
->outstanding_cmds
[index
];
2587 if (!(sfcp
->flags
& FCF_TAPE_PRESENT
))
2590 set_bit(ISP_ABORT_NEEDED
,
2594 spin_unlock_irqrestore(&ha
->hardware_lock
,
2597 set_bit(ABORT_QUEUES_NEEDED
, &ha
->dpc_flags
);
2601 /* if the loop has been down for 4 minutes, reinit adapter */
2602 if (atomic_dec_and_test(&ha
->loop_down_timer
) != 0) {
2603 DEBUG(printk("scsi(%ld): Loop down exceed 4 mins - "
2604 "restarting queues.\n",
2607 set_bit(RESTART_QUEUES_NEEDED
, &ha
->dpc_flags
);
2610 if (!(ha
->device_flags
& DFLG_NO_CABLE
) &&
2612 DEBUG(printk("scsi(%ld): Loop down - "
2615 qla_printk(KERN_WARNING
, ha
,
2616 "Loop down - aborting ISP.\n");
2618 set_bit(ISP_ABORT_NEEDED
, &ha
->dpc_flags
);
2621 DEBUG3(printk("scsi(%ld): Loop Down - seconds remaining %d\n",
2623 atomic_read(&ha
->loop_down_timer
)));
2626 /* Check if beacon LED needs to be blinked */
2627 if (ha
->beacon_blink_led
== 1) {
2628 set_bit(BEACON_BLINK_NEEDED
, &ha
->dpc_flags
);
2632 /* Process any deferred work. */
2633 if (!list_empty(&ha
->work_list
))
2636 /* Schedule the DPC routine if needed */
2637 if ((test_bit(ISP_ABORT_NEEDED
, &ha
->dpc_flags
) ||
2638 test_bit(LOOP_RESYNC_NEEDED
, &ha
->dpc_flags
) ||
2639 test_bit(FCPORT_UPDATE_NEEDED
, &ha
->dpc_flags
) ||
2641 test_bit(RESET_MARKER_NEEDED
, &ha
->dpc_flags
) ||
2642 test_bit(BEACON_BLINK_NEEDED
, &ha
->dpc_flags
) ||
2643 test_bit(VP_DPC_NEEDED
, &ha
->dpc_flags
) ||
2644 test_bit(RELOGIN_NEEDED
, &ha
->dpc_flags
)))
2645 qla2xxx_wake_dpc(pha
);
2647 qla2x00_restart_timer(ha
, WATCH_INTERVAL
);
2650 /* Firmware interface routines. */
2653 #define FW_ISP21XX 0
2654 #define FW_ISP22XX 1
2655 #define FW_ISP2300 2
2656 #define FW_ISP2322 3
2657 #define FW_ISP24XX 4
2658 #define FW_ISP25XX 5
2660 #define FW_FILE_ISP21XX "ql2100_fw.bin"
2661 #define FW_FILE_ISP22XX "ql2200_fw.bin"
2662 #define FW_FILE_ISP2300 "ql2300_fw.bin"
2663 #define FW_FILE_ISP2322 "ql2322_fw.bin"
2664 #define FW_FILE_ISP24XX "ql2400_fw.bin"
2665 #define FW_FILE_ISP25XX "ql2500_fw.bin"
2667 static DEFINE_MUTEX(qla_fw_lock
);
2669 static struct fw_blob qla_fw_blobs
[FW_BLOBS
] = {
2670 { .name
= FW_FILE_ISP21XX
, .segs
= { 0x1000, 0 }, },
2671 { .name
= FW_FILE_ISP22XX
, .segs
= { 0x1000, 0 }, },
2672 { .name
= FW_FILE_ISP2300
, .segs
= { 0x800, 0 }, },
2673 { .name
= FW_FILE_ISP2322
, .segs
= { 0x800, 0x1c000, 0x1e000, 0 }, },
2674 { .name
= FW_FILE_ISP24XX
, },
2675 { .name
= FW_FILE_ISP25XX
, },
2679 qla2x00_request_firmware(scsi_qla_host_t
*ha
)
2681 struct fw_blob
*blob
;
2684 if (IS_QLA2100(ha
)) {
2685 blob
= &qla_fw_blobs
[FW_ISP21XX
];
2686 } else if (IS_QLA2200(ha
)) {
2687 blob
= &qla_fw_blobs
[FW_ISP22XX
];
2688 } else if (IS_QLA2300(ha
) || IS_QLA2312(ha
) || IS_QLA6312(ha
)) {
2689 blob
= &qla_fw_blobs
[FW_ISP2300
];
2690 } else if (IS_QLA2322(ha
) || IS_QLA6322(ha
)) {
2691 blob
= &qla_fw_blobs
[FW_ISP2322
];
2692 } else if (IS_QLA24XX_TYPE(ha
)) {
2693 blob
= &qla_fw_blobs
[FW_ISP24XX
];
2694 } else if (IS_QLA25XX(ha
)) {
2695 blob
= &qla_fw_blobs
[FW_ISP25XX
];
2698 mutex_lock(&qla_fw_lock
);
2702 if (request_firmware(&blob
->fw
, blob
->name
, &ha
->pdev
->dev
)) {
2703 DEBUG2(printk("scsi(%ld): Failed to load firmware image "
2704 "(%s).\n", ha
->host_no
, blob
->name
));
2711 mutex_unlock(&qla_fw_lock
);
2716 qla2x00_release_firmware(void)
2720 mutex_lock(&qla_fw_lock
);
2721 for (idx
= 0; idx
< FW_BLOBS
; idx
++)
2722 if (qla_fw_blobs
[idx
].fw
)
2723 release_firmware(qla_fw_blobs
[idx
].fw
);
2724 mutex_unlock(&qla_fw_lock
);
2727 static pci_ers_result_t
2728 qla2xxx_pci_error_detected(struct pci_dev
*pdev
, pci_channel_state_t state
)
2731 case pci_channel_io_normal
:
2732 return PCI_ERS_RESULT_CAN_RECOVER
;
2733 case pci_channel_io_frozen
:
2734 pci_disable_device(pdev
);
2735 return PCI_ERS_RESULT_NEED_RESET
;
2736 case pci_channel_io_perm_failure
:
2737 qla2x00_remove_one(pdev
);
2738 return PCI_ERS_RESULT_DISCONNECT
;
2740 return PCI_ERS_RESULT_NEED_RESET
;
2743 static pci_ers_result_t
2744 qla2xxx_pci_mmio_enabled(struct pci_dev
*pdev
)
2746 int risc_paused
= 0;
2748 unsigned long flags
;
2749 scsi_qla_host_t
*ha
= pci_get_drvdata(pdev
);
2750 struct device_reg_2xxx __iomem
*reg
= &ha
->iobase
->isp
;
2751 struct device_reg_24xx __iomem
*reg24
= &ha
->iobase
->isp24
;
2753 spin_lock_irqsave(&ha
->hardware_lock
, flags
);
2754 if (IS_QLA2100(ha
) || IS_QLA2200(ha
)){
2755 stat
= RD_REG_DWORD(®
->hccr
);
2756 if (stat
& HCCR_RISC_PAUSE
)
2758 } else if (IS_QLA23XX(ha
)) {
2759 stat
= RD_REG_DWORD(®
->u
.isp2300
.host_status
);
2760 if (stat
& HSR_RISC_PAUSED
)
2762 } else if (IS_FWI2_CAPABLE(ha
)) {
2763 stat
= RD_REG_DWORD(®24
->host_status
);
2764 if (stat
& HSRX_RISC_PAUSED
)
2767 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
2770 qla_printk(KERN_INFO
, ha
, "RISC paused -- mmio_enabled, "
2771 "Dumping firmware!\n");
2772 ha
->isp_ops
->fw_dump(ha
, 0);
2774 return PCI_ERS_RESULT_NEED_RESET
;
2776 return PCI_ERS_RESULT_RECOVERED
;
2779 static pci_ers_result_t
2780 qla2xxx_pci_slot_reset(struct pci_dev
*pdev
)
2782 pci_ers_result_t ret
= PCI_ERS_RESULT_DISCONNECT
;
2783 scsi_qla_host_t
*ha
= pci_get_drvdata(pdev
);
2787 rc
= pci_enable_device_mem(pdev
);
2789 rc
= pci_enable_device(pdev
);
2792 qla_printk(KERN_WARNING
, ha
,
2793 "Can't re-enable PCI device after reset.\n");
2797 pci_set_master(pdev
);
2799 if (ha
->isp_ops
->pci_config(ha
))
2802 set_bit(ABORT_ISP_ACTIVE
, &ha
->dpc_flags
);
2803 if (qla2x00_abort_isp(ha
)== QLA_SUCCESS
)
2804 ret
= PCI_ERS_RESULT_RECOVERED
;
2805 clear_bit(ABORT_ISP_ACTIVE
, &ha
->dpc_flags
);
2811 qla2xxx_pci_resume(struct pci_dev
*pdev
)
2813 scsi_qla_host_t
*ha
= pci_get_drvdata(pdev
);
2816 ret
= qla2x00_wait_for_hba_online(ha
);
2817 if (ret
!= QLA_SUCCESS
) {
2818 qla_printk(KERN_ERR
, ha
,
2819 "the device failed to resume I/O "
2820 "from slot/link_reset");
2822 pci_cleanup_aer_uncorrect_error_status(pdev
);
2825 static struct pci_error_handlers qla2xxx_err_handler
= {
2826 .error_detected
= qla2xxx_pci_error_detected
,
2827 .mmio_enabled
= qla2xxx_pci_mmio_enabled
,
2828 .slot_reset
= qla2xxx_pci_slot_reset
,
2829 .resume
= qla2xxx_pci_resume
,
2832 static struct pci_device_id qla2xxx_pci_tbl
[] = {
2833 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC
, PCI_DEVICE_ID_QLOGIC_ISP2100
) },
2834 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC
, PCI_DEVICE_ID_QLOGIC_ISP2200
) },
2835 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC
, PCI_DEVICE_ID_QLOGIC_ISP2300
) },
2836 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC
, PCI_DEVICE_ID_QLOGIC_ISP2312
) },
2837 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC
, PCI_DEVICE_ID_QLOGIC_ISP2322
) },
2838 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC
, PCI_DEVICE_ID_QLOGIC_ISP6312
) },
2839 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC
, PCI_DEVICE_ID_QLOGIC_ISP6322
) },
2840 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC
, PCI_DEVICE_ID_QLOGIC_ISP2422
) },
2841 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC
, PCI_DEVICE_ID_QLOGIC_ISP2432
) },
2842 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC
, PCI_DEVICE_ID_QLOGIC_ISP8432
) },
2843 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC
, PCI_DEVICE_ID_QLOGIC_ISP5422
) },
2844 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC
, PCI_DEVICE_ID_QLOGIC_ISP5432
) },
2845 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC
, PCI_DEVICE_ID_QLOGIC_ISP2532
) },
2848 MODULE_DEVICE_TABLE(pci
, qla2xxx_pci_tbl
);
2850 static struct pci_driver qla2xxx_pci_driver
= {
2851 .name
= QLA2XXX_DRIVER_NAME
,
2853 .owner
= THIS_MODULE
,
2855 .id_table
= qla2xxx_pci_tbl
,
2856 .probe
= qla2x00_probe_one
,
2857 .remove
= qla2x00_remove_one
,
2858 .err_handler
= &qla2xxx_err_handler
,
2862 * qla2x00_module_init - Module initialization.
2865 qla2x00_module_init(void)
2869 /* Allocate cache for SRBs. */
2870 srb_cachep
= kmem_cache_create("qla2xxx_srbs", sizeof(srb_t
), 0,
2871 SLAB_HWCACHE_ALIGN
, NULL
);
2872 if (srb_cachep
== NULL
) {
2874 "qla2xxx: Unable to allocate SRB cache...Failing load!\n");
2878 /* Derive version string. */
2879 strcpy(qla2x00_version_str
, QLA2XXX_VERSION
);
2880 if (ql2xextended_error_logging
)
2881 strcat(qla2x00_version_str
, "-debug");
2883 qla2xxx_transport_template
=
2884 fc_attach_transport(&qla2xxx_transport_functions
);
2885 if (!qla2xxx_transport_template
) {
2886 kmem_cache_destroy(srb_cachep
);
2889 qla2xxx_transport_vport_template
=
2890 fc_attach_transport(&qla2xxx_transport_vport_functions
);
2891 if (!qla2xxx_transport_vport_template
) {
2892 kmem_cache_destroy(srb_cachep
);
2893 fc_release_transport(qla2xxx_transport_template
);
2897 printk(KERN_INFO
"QLogic Fibre Channel HBA Driver: %s\n",
2898 qla2x00_version_str
);
2899 ret
= pci_register_driver(&qla2xxx_pci_driver
);
2901 kmem_cache_destroy(srb_cachep
);
2902 fc_release_transport(qla2xxx_transport_template
);
2903 fc_release_transport(qla2xxx_transport_vport_template
);
2909 * qla2x00_module_exit - Module cleanup.
2912 qla2x00_module_exit(void)
2914 pci_unregister_driver(&qla2xxx_pci_driver
);
2915 qla2x00_release_firmware();
2916 kmem_cache_destroy(srb_cachep
);
2917 fc_release_transport(qla2xxx_transport_template
);
2918 fc_release_transport(qla2xxx_transport_vport_template
);
2921 module_init(qla2x00_module_init
);
2922 module_exit(qla2x00_module_exit
);
2924 MODULE_AUTHOR("QLogic Corporation");
2925 MODULE_DESCRIPTION("QLogic Fibre Channel HBA Driver");
2926 MODULE_LICENSE("GPL");
2927 MODULE_VERSION(QLA2XXX_VERSION
);
2928 MODULE_FIRMWARE(FW_FILE_ISP21XX
);
2929 MODULE_FIRMWARE(FW_FILE_ISP22XX
);
2930 MODULE_FIRMWARE(FW_FILE_ISP2300
);
2931 MODULE_FIRMWARE(FW_FILE_ISP2322
);
2932 MODULE_FIRMWARE(FW_FILE_ISP24XX
);
2933 MODULE_FIRMWARE(FW_FILE_ISP25XX
);