2 * QLogic Fibre Channel HBA Driver
3 * Copyright (c) 2003-2005 QLogic Corporation
5 * See LICENSE.qla2xxx for copyright and licensing details.
9 #include <linux/moduleparam.h>
10 #include <linux/vmalloc.h>
11 #include <linux/smp_lock.h>
12 #include <linux/delay.h>
14 #include <scsi/scsi_tcq.h>
15 #include <scsi/scsicam.h>
16 #include <scsi/scsi_transport.h>
17 #include <scsi/scsi_transport_fc.h>
22 char qla2x00_version_str
[40];
25 * SRB allocation cache
27 static kmem_cache_t
*srb_cachep
;
30 * Ioctl related information.
34 int ql2xlogintimeout
= 20;
35 module_param(ql2xlogintimeout
, int, S_IRUGO
|S_IRUSR
);
36 MODULE_PARM_DESC(ql2xlogintimeout
,
37 "Login timeout value in seconds.");
39 int qlport_down_retry
= 30;
40 module_param(qlport_down_retry
, int, S_IRUGO
|S_IRUSR
);
41 MODULE_PARM_DESC(qlport_down_retry
,
42 "Maximum number of command retries to a port that returns"
43 "a PORT-DOWN status.");
45 int ql2xplogiabsentdevice
;
46 module_param(ql2xplogiabsentdevice
, int, S_IRUGO
|S_IWUSR
);
47 MODULE_PARM_DESC(ql2xplogiabsentdevice
,
48 "Option to enable PLOGI to devices that are not present after "
49 "a Fabric scan. This is needed for several broken switches."
50 "Default is 0 - no PLOGI. 1 - perfom PLOGI.");
52 int ql2xloginretrycount
= 0;
53 module_param(ql2xloginretrycount
, int, S_IRUGO
|S_IRUSR
);
54 MODULE_PARM_DESC(ql2xloginretrycount
,
55 "Specify an alternate value for the NVRAM login retry count.");
58 module_param(ql2xfwloadbin
, int, S_IRUGO
|S_IRUSR
);
59 MODULE_PARM_DESC(ql2xfwloadbin
,
60 "Load ISP2xxx firmware image via hotplug.");
62 static void qla2x00_free_device(scsi_qla_host_t
*);
64 static void qla2x00_config_dma_addressing(scsi_qla_host_t
*ha
);
67 module_param(ql2xfdmienable
, int, S_IRUGO
|S_IRUSR
);
68 MODULE_PARM_DESC(ql2xfdmienable
,
69 "Enables FDMI registratons "
70 "Default is 0 - no FDMI. 1 - perfom FDMI.");
73 * SCSI host template entry points
75 static int qla2xxx_slave_configure(struct scsi_device
* device
);
76 static int qla2xxx_slave_alloc(struct scsi_device
*);
77 static void qla2xxx_slave_destroy(struct scsi_device
*);
78 static int qla2x00_queuecommand(struct scsi_cmnd
*cmd
,
79 void (*fn
)(struct scsi_cmnd
*));
80 static int qla24xx_queuecommand(struct scsi_cmnd
*cmd
,
81 void (*fn
)(struct scsi_cmnd
*));
82 static int qla2xxx_eh_abort(struct scsi_cmnd
*);
83 static int qla2xxx_eh_device_reset(struct scsi_cmnd
*);
84 static int qla2xxx_eh_bus_reset(struct scsi_cmnd
*);
85 static int qla2xxx_eh_host_reset(struct scsi_cmnd
*);
86 static int qla2x00_loop_reset(scsi_qla_host_t
*ha
);
87 static int qla2x00_device_reset(scsi_qla_host_t
*, fc_port_t
*);
89 static int qla2x00_change_queue_depth(struct scsi_device
*, int);
90 static int qla2x00_change_queue_type(struct scsi_device
*, int);
92 static struct scsi_host_template qla2x00_driver_template
= {
93 .module
= THIS_MODULE
,
95 .queuecommand
= qla2x00_queuecommand
,
97 .eh_abort_handler
= qla2xxx_eh_abort
,
98 .eh_device_reset_handler
= qla2xxx_eh_device_reset
,
99 .eh_bus_reset_handler
= qla2xxx_eh_bus_reset
,
100 .eh_host_reset_handler
= qla2xxx_eh_host_reset
,
102 .slave_configure
= qla2xxx_slave_configure
,
104 .slave_alloc
= qla2xxx_slave_alloc
,
105 .slave_destroy
= qla2xxx_slave_destroy
,
106 .change_queue_depth
= qla2x00_change_queue_depth
,
107 .change_queue_type
= qla2x00_change_queue_type
,
110 .use_clustering
= ENABLE_CLUSTERING
,
111 .sg_tablesize
= SG_ALL
,
114 * The RISC allows for each command to transfer (2^32-1) bytes of data,
115 * which equates to 0x800000 sectors.
117 .max_sectors
= 0xFFFF,
118 .shost_attrs
= qla2x00_host_attrs
,
121 static struct scsi_host_template qla24xx_driver_template
= {
122 .module
= THIS_MODULE
,
124 .queuecommand
= qla24xx_queuecommand
,
126 .eh_abort_handler
= qla2xxx_eh_abort
,
127 .eh_device_reset_handler
= qla2xxx_eh_device_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 .change_queue_depth
= qla2x00_change_queue_depth
,
136 .change_queue_type
= qla2x00_change_queue_type
,
139 .use_clustering
= ENABLE_CLUSTERING
,
140 .sg_tablesize
= SG_ALL
,
142 .max_sectors
= 0xFFFF,
143 .shost_attrs
= qla2x00_host_attrs
,
146 static struct scsi_transport_template
*qla2xxx_transport_template
= NULL
;
148 /* TODO Convert to inlines
152 #define WATCH_INTERVAL 1 /* number of seconds */
154 static void qla2x00_timer(scsi_qla_host_t
*);
156 static __inline__
void qla2x00_start_timer(scsi_qla_host_t
*,
157 void *, unsigned long);
158 static __inline__
void qla2x00_restart_timer(scsi_qla_host_t
*, unsigned long);
159 static __inline__
void qla2x00_stop_timer(scsi_qla_host_t
*);
162 qla2x00_start_timer(scsi_qla_host_t
*ha
, void *func
, unsigned long interval
)
164 init_timer(&ha
->timer
);
165 ha
->timer
.expires
= jiffies
+ interval
* HZ
;
166 ha
->timer
.data
= (unsigned long)ha
;
167 ha
->timer
.function
= (void (*)(unsigned long))func
;
168 add_timer(&ha
->timer
);
169 ha
->timer_active
= 1;
173 qla2x00_restart_timer(scsi_qla_host_t
*ha
, unsigned long interval
)
175 mod_timer(&ha
->timer
, jiffies
+ interval
* HZ
);
178 static __inline__
void
179 qla2x00_stop_timer(scsi_qla_host_t
*ha
)
181 del_timer_sync(&ha
->timer
);
182 ha
->timer_active
= 0;
185 static int qla2x00_do_dpc(void *data
);
187 static void qla2x00_rst_aen(scsi_qla_host_t
*);
189 static uint8_t qla2x00_mem_alloc(scsi_qla_host_t
*);
190 static void qla2x00_mem_free(scsi_qla_host_t
*ha
);
191 static int qla2x00_allocate_sp_pool( scsi_qla_host_t
*ha
);
192 static void qla2x00_free_sp_pool(scsi_qla_host_t
*ha
);
193 static void qla2x00_sp_free_dma(scsi_qla_host_t
*, srb_t
*);
194 void qla2x00_sp_compl(scsi_qla_host_t
*ha
, srb_t
*);
196 /* -------------------------------------------------------------------------- */
199 qla2x00_pci_info_str(struct scsi_qla_host
*ha
, char *str
)
201 static char *pci_bus_modes
[] = {
202 "33", "66", "100", "133",
207 pci_bus
= (ha
->pci_attr
& (BIT_9
| BIT_10
)) >> 9;
210 strcat(str
, pci_bus_modes
[pci_bus
]);
212 pci_bus
= (ha
->pci_attr
& BIT_8
) >> 8;
214 strcat(str
, pci_bus_modes
[pci_bus
]);
216 strcat(str
, " MHz)");
222 qla24xx_pci_info_str(struct scsi_qla_host
*ha
, char *str
)
224 static char *pci_bus_modes
[] = { "33", "66", "100", "133", };
228 pcie_reg
= pci_find_capability(ha
->pdev
, PCI_CAP_ID_EXP
);
231 uint16_t pcie_lstat
, lspeed
, lwidth
;
234 pci_read_config_word(ha
->pdev
, pcie_reg
, &pcie_lstat
);
235 lspeed
= pcie_lstat
& (BIT_0
| BIT_1
| BIT_2
| BIT_3
);
236 lwidth
= (pcie_lstat
&
237 (BIT_4
| BIT_5
| BIT_6
| BIT_7
| BIT_8
| BIT_9
)) >> 4;
239 strcpy(str
, "PCIe (");
241 strcat(str
, "2.5Gb/s ");
243 strcat(str
, "<unknown> ");
244 snprintf(lwstr
, sizeof(lwstr
), "x%d)", lwidth
);
251 pci_bus
= (ha
->pci_attr
& CSRX_PCIX_BUS_MODE_MASK
) >> 8;
252 if (pci_bus
== 0 || pci_bus
== 8) {
254 strcat(str
, pci_bus_modes
[pci_bus
>> 3]);
258 strcat(str
, "Mode 2");
260 strcat(str
, "Mode 1");
262 strcat(str
, pci_bus_modes
[pci_bus
& ~BIT_2
]);
264 strcat(str
, " MHz)");
270 qla2x00_fw_version_str(struct scsi_qla_host
*ha
, char *str
)
274 sprintf(str
, "%d.%02d.%02d ", ha
->fw_major_version
,
275 ha
->fw_minor_version
,
276 ha
->fw_subminor_version
);
278 if (ha
->fw_attributes
& BIT_9
) {
283 switch (ha
->fw_attributes
& 0xFF) {
297 sprintf(un_str
, "(%x)", ha
->fw_attributes
);
301 if (ha
->fw_attributes
& 0x100)
308 qla24xx_fw_version_str(struct scsi_qla_host
*ha
, char *str
)
310 sprintf(str
, "%d.%02d.%02d ", ha
->fw_major_version
,
311 ha
->fw_minor_version
,
312 ha
->fw_subminor_version
);
314 if (ha
->fw_attributes
& BIT_0
)
315 strcat(str
, "[Class 2] ");
316 if (ha
->fw_attributes
& BIT_1
)
317 strcat(str
, "[IP] ");
318 if (ha
->fw_attributes
& BIT_2
)
319 strcat(str
, "[Multi-ID] ");
320 if (ha
->fw_attributes
& BIT_13
)
321 strcat(str
, "[Experimental]");
325 static inline srb_t
*
326 qla2x00_get_new_sp(scsi_qla_host_t
*ha
, fc_port_t
*fcport
,
327 struct scsi_cmnd
*cmd
, void (*done
)(struct scsi_cmnd
*))
331 sp
= mempool_alloc(ha
->srb_mempool
, GFP_ATOMIC
);
335 atomic_set(&sp
->ref_count
, 1);
340 CMD_SP(cmd
) = (void *)sp
;
341 cmd
->scsi_done
= done
;
347 qla2x00_queuecommand(struct scsi_cmnd
*cmd
, void (*done
)(struct scsi_cmnd
*))
349 scsi_qla_host_t
*ha
= to_qla_host(cmd
->device
->host
);
350 fc_port_t
*fcport
= (struct fc_port
*) cmd
->device
->hostdata
;
355 cmd
->result
= DID_NO_CONNECT
<< 16;
356 goto qc_fail_command
;
359 if (atomic_read(&fcport
->state
) != FCS_ONLINE
) {
360 if (atomic_read(&fcport
->state
) == FCS_DEVICE_DEAD
||
361 atomic_read(&ha
->loop_state
) == LOOP_DEAD
) {
362 cmd
->result
= DID_NO_CONNECT
<< 16;
363 goto qc_fail_command
;
368 spin_unlock_irq(ha
->host
->host_lock
);
370 sp
= qla2x00_get_new_sp(ha
, fcport
, cmd
, done
);
372 goto qc_host_busy_lock
;
374 rval
= qla2x00_start_scsi(sp
);
375 if (rval
!= QLA_SUCCESS
)
376 goto qc_host_busy_free_sp
;
378 spin_lock_irq(ha
->host
->host_lock
);
382 qc_host_busy_free_sp
:
383 qla2x00_sp_free_dma(ha
, sp
);
384 mempool_free(sp
, ha
->srb_mempool
);
387 spin_lock_irq(ha
->host
->host_lock
);
390 return SCSI_MLQUEUE_HOST_BUSY
;
400 qla24xx_queuecommand(struct scsi_cmnd
*cmd
, void (*done
)(struct scsi_cmnd
*))
402 scsi_qla_host_t
*ha
= to_qla_host(cmd
->device
->host
);
403 fc_port_t
*fcport
= (struct fc_port
*) cmd
->device
->hostdata
;
408 cmd
->result
= DID_NO_CONNECT
<< 16;
409 goto qc24_fail_command
;
412 if (atomic_read(&fcport
->state
) != FCS_ONLINE
) {
413 if (atomic_read(&fcport
->state
) == FCS_DEVICE_DEAD
||
414 atomic_read(&ha
->loop_state
) == LOOP_DEAD
) {
415 cmd
->result
= DID_NO_CONNECT
<< 16;
416 goto qc24_fail_command
;
421 spin_unlock_irq(ha
->host
->host_lock
);
423 sp
= qla2x00_get_new_sp(ha
, fcport
, cmd
, done
);
425 goto qc24_host_busy_lock
;
427 rval
= qla24xx_start_scsi(sp
);
428 if (rval
!= QLA_SUCCESS
)
429 goto qc24_host_busy_free_sp
;
431 spin_lock_irq(ha
->host
->host_lock
);
435 qc24_host_busy_free_sp
:
436 qla2x00_sp_free_dma(ha
, sp
);
437 mempool_free(sp
, ha
->srb_mempool
);
440 spin_lock_irq(ha
->host
->host_lock
);
443 return SCSI_MLQUEUE_HOST_BUSY
;
453 * qla2x00_eh_wait_on_command
454 * Waits for the command to be returned by the Firmware for some
458 * ha = actual ha whose done queue will contain the command
459 * returned by firmware.
460 * cmd = Scsi Command to wait on.
461 * flag = Abort/Reset(Bus or Device Reset)
468 qla2x00_eh_wait_on_command(scsi_qla_host_t
*ha
, struct scsi_cmnd
*cmd
)
470 #define ABORT_POLLING_PERIOD 1000
471 #define ABORT_WAIT_ITER ((10 * 1000) / (ABORT_POLLING_PERIOD))
472 unsigned long wait_iter
= ABORT_WAIT_ITER
;
473 int ret
= QLA_SUCCESS
;
475 while (CMD_SP(cmd
)) {
476 msleep(ABORT_POLLING_PERIOD
);
482 ret
= QLA_FUNCTION_FAILED
;
488 * qla2x00_wait_for_hba_online
489 * Wait till the HBA is online after going through
490 * <= MAX_RETRIES_OF_ISP_ABORT or
491 * finally HBA is disabled ie marked offline
494 * ha - pointer to host adapter structure
497 * Does context switching-Release SPIN_LOCK
498 * (if any) before calling this routine.
501 * Success (Adapter is online) : 0
502 * Failed (Adapter is offline/disabled) : 1
505 qla2x00_wait_for_hba_online(scsi_qla_host_t
*ha
)
508 unsigned long wait_online
;
510 wait_online
= jiffies
+ (MAX_LOOP_TIMEOUT
* HZ
);
511 while (((test_bit(ISP_ABORT_NEEDED
, &ha
->dpc_flags
)) ||
512 test_bit(ABORT_ISP_ACTIVE
, &ha
->dpc_flags
) ||
513 test_bit(ISP_ABORT_RETRY
, &ha
->dpc_flags
) ||
514 ha
->dpc_active
) && time_before(jiffies
, wait_online
)) {
518 if (ha
->flags
.online
)
519 return_status
= QLA_SUCCESS
;
521 return_status
= QLA_FUNCTION_FAILED
;
523 DEBUG2(printk("%s return_status=%d\n",__func__
,return_status
));
525 return (return_status
);
529 * qla2x00_wait_for_loop_ready
530 * Wait for MAX_LOOP_TIMEOUT(5 min) value for loop
531 * to be in LOOP_READY state.
533 * ha - pointer to host adapter structure
536 * Does context switching-Release SPIN_LOCK
537 * (if any) before calling this routine.
541 * Success (LOOP_READY) : 0
542 * Failed (LOOP_NOT_READY) : 1
545 qla2x00_wait_for_loop_ready(scsi_qla_host_t
*ha
)
547 int return_status
= QLA_SUCCESS
;
548 unsigned long loop_timeout
;
550 /* wait for 5 min at the max for loop to be ready */
551 loop_timeout
= jiffies
+ (MAX_LOOP_TIMEOUT
* HZ
);
553 while ((!atomic_read(&ha
->loop_down_timer
) &&
554 atomic_read(&ha
->loop_state
) == LOOP_DOWN
) ||
555 atomic_read(&ha
->loop_state
) != LOOP_READY
) {
557 if (time_after_eq(jiffies
, loop_timeout
)) {
558 return_status
= QLA_FUNCTION_FAILED
;
562 return (return_status
);
565 /**************************************************************************
569 * The abort function will abort the specified command.
572 * cmd = Linux SCSI command packet to be aborted.
575 * Either SUCCESS or FAILED.
578 **************************************************************************/
580 qla2xxx_eh_abort(struct scsi_cmnd
*cmd
)
582 scsi_qla_host_t
*ha
= to_qla_host(cmd
->device
->host
);
585 unsigned int id
, lun
;
586 unsigned long serial
;
594 id
= cmd
->device
->id
;
595 lun
= cmd
->device
->lun
;
596 serial
= cmd
->serial_number
;
598 /* Check active list for command command. */
599 spin_lock_irqsave(&ha
->hardware_lock
, flags
);
600 for (i
= 1; i
< MAX_OUTSTANDING_COMMANDS
; i
++) {
601 sp
= ha
->outstanding_cmds
[i
];
609 DEBUG2(printk("%s(%ld): aborting sp %p from RISC. pid=%ld "
610 "sp->state=%x\n", __func__
, ha
->host_no
, sp
, serial
,
612 DEBUG3(qla2x00_print_scsi_cmd(cmd
);)
614 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
615 if (ha
->isp_ops
.abort_command(ha
, sp
)) {
616 DEBUG2(printk("%s(%ld): abort_command "
617 "mbx failed.\n", __func__
, ha
->host_no
));
619 DEBUG3(printk("%s(%ld): abort_command "
620 "mbx success.\n", __func__
, ha
->host_no
));
623 spin_lock_irqsave(&ha
->hardware_lock
, flags
);
627 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
629 /* Wait for the command to be returned. */
630 if (ret
== SUCCESS
) {
631 if (qla2x00_eh_wait_on_command(ha
, cmd
) != QLA_SUCCESS
) {
632 qla_printk(KERN_ERR
, ha
,
633 "scsi(%ld:%d:%d): Abort handler timed out -- %lx "
634 "%x.\n", ha
->host_no
, id
, lun
, serial
, ret
);
638 qla_printk(KERN_INFO
, ha
,
639 "scsi(%ld:%d:%d): Abort command issued -- %lx %x.\n", ha
->host_no
,
640 id
, lun
, serial
, ret
);
645 /**************************************************************************
646 * qla2x00_eh_wait_for_pending_target_commands
649 * Waits for all the commands to come back from the specified target.
652 * ha - pointer to scsi_qla_host structure.
655 * Either SUCCESS or FAILED.
658 **************************************************************************/
660 qla2x00_eh_wait_for_pending_target_commands(scsi_qla_host_t
*ha
, unsigned int t
)
665 struct scsi_cmnd
*cmd
;
671 * Waiting for all commands for the designated target in the active
674 for (cnt
= 1; cnt
< MAX_OUTSTANDING_COMMANDS
; cnt
++) {
675 spin_lock_irqsave(&ha
->hardware_lock
, flags
);
676 sp
= ha
->outstanding_cmds
[cnt
];
679 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
680 if (cmd
->device
->id
== t
) {
681 if (!qla2x00_eh_wait_on_command(ha
, cmd
)) {
687 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
694 /**************************************************************************
695 * qla2xxx_eh_device_reset
698 * The device reset function will reset the target and abort any
699 * executing commands.
701 * NOTE: The use of SP is undefined within this context. Do *NOT*
702 * attempt to use this value, even if you determine it is
706 * cmd = Linux SCSI command packet of the command that cause the
710 * SUCCESS/FAILURE (defined as macro in scsi.h).
712 **************************************************************************/
714 qla2xxx_eh_device_reset(struct scsi_cmnd
*cmd
)
716 scsi_qla_host_t
*ha
= to_qla_host(cmd
->device
->host
);
717 fc_port_t
*fcport
= (struct fc_port
*) cmd
->device
->hostdata
;
720 unsigned int id
, lun
;
721 unsigned long serial
;
725 id
= cmd
->device
->id
;
726 lun
= cmd
->device
->lun
;
727 serial
= cmd
->serial_number
;
729 sp
= (srb_t
*) CMD_SP(cmd
);
733 qla_printk(KERN_INFO
, ha
,
734 "scsi(%ld:%d:%d): DEVICE RESET ISSUED.\n", ha
->host_no
, id
, lun
);
736 if (qla2x00_wait_for_hba_online(ha
) != QLA_SUCCESS
)
737 goto eh_dev_reset_done
;
739 if (qla2x00_wait_for_loop_ready(ha
) == QLA_SUCCESS
) {
740 if (qla2x00_device_reset(ha
, fcport
) == 0)
743 #if defined(LOGOUT_AFTER_DEVICE_RESET)
744 if (ret
== SUCCESS
) {
745 if (fcport
->flags
& FC_FABRIC_DEVICE
) {
746 ha
->isp_ops
.fabric_logout(ha
, fcport
->loop_id
);
747 qla2x00_mark_device_lost(ha
, fcport
);
752 DEBUG2(printk(KERN_INFO
753 "%s failed: loop not ready\n",__func__
);)
757 DEBUG3(printk("%s(%ld): device reset failed\n",
758 __func__
, ha
->host_no
));
759 qla_printk(KERN_INFO
, ha
, "%s: device reset failed\n",
762 goto eh_dev_reset_done
;
765 /* Flush outstanding commands. */
766 if (qla2x00_eh_wait_for_pending_target_commands(ha
, id
))
769 DEBUG3(printk("%s(%ld): failed while waiting for commands\n",
770 __func__
, ha
->host_no
));
771 qla_printk(KERN_INFO
, ha
,
772 "%s: failed while waiting for commands\n", __func__
);
774 qla_printk(KERN_INFO
, ha
,
775 "scsi(%ld:%d:%d): DEVICE RESET SUCCEEDED.\n", ha
->host_no
,
781 /**************************************************************************
782 * qla2x00_eh_wait_for_pending_commands
785 * Waits for all the commands to come back from the specified host.
788 * ha - pointer to scsi_qla_host structure.
795 **************************************************************************/
797 qla2x00_eh_wait_for_pending_commands(scsi_qla_host_t
*ha
)
802 struct scsi_cmnd
*cmd
;
808 * Waiting for all commands for the designated target in the active
811 for (cnt
= 1; cnt
< MAX_OUTSTANDING_COMMANDS
; cnt
++) {
812 spin_lock_irqsave(&ha
->hardware_lock
, flags
);
813 sp
= ha
->outstanding_cmds
[cnt
];
816 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
817 status
= qla2x00_eh_wait_on_command(ha
, cmd
);
822 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
829 /**************************************************************************
830 * qla2xxx_eh_bus_reset
833 * The bus reset function will reset the bus and abort any executing
837 * cmd = Linux SCSI command packet of the command that cause the
841 * SUCCESS/FAILURE (defined as macro in scsi.h).
843 **************************************************************************/
845 qla2xxx_eh_bus_reset(struct scsi_cmnd
*cmd
)
847 scsi_qla_host_t
*ha
= to_qla_host(cmd
->device
->host
);
848 fc_port_t
*fcport
= (struct fc_port
*) cmd
->device
->hostdata
;
851 unsigned int id
, lun
;
852 unsigned long serial
;
856 id
= cmd
->device
->id
;
857 lun
= cmd
->device
->lun
;
858 serial
= cmd
->serial_number
;
860 sp
= (srb_t
*) CMD_SP(cmd
);
864 qla_printk(KERN_INFO
, ha
,
865 "scsi(%ld:%d:%d): LOOP RESET ISSUED.\n", ha
->host_no
, id
, lun
);
867 if (qla2x00_wait_for_hba_online(ha
) != QLA_SUCCESS
) {
868 DEBUG2(printk("%s failed:board disabled\n",__func__
));
869 goto eh_bus_reset_done
;
872 if (qla2x00_wait_for_loop_ready(ha
) == QLA_SUCCESS
) {
873 if (qla2x00_loop_reset(ha
) == QLA_SUCCESS
)
877 goto eh_bus_reset_done
;
879 /* Flush outstanding commands. */
880 if (!qla2x00_eh_wait_for_pending_commands(ha
))
884 qla_printk(KERN_INFO
, ha
, "%s: reset %s\n", __func__
,
885 (ret
== FAILED
) ? "failed" : "succeded");
890 /**************************************************************************
891 * qla2xxx_eh_host_reset
894 * The reset function will reset the Adapter.
897 * cmd = Linux SCSI command packet of the command that cause the
901 * Either SUCCESS or FAILED.
904 **************************************************************************/
906 qla2xxx_eh_host_reset(struct scsi_cmnd
*cmd
)
908 scsi_qla_host_t
*ha
= to_qla_host(cmd
->device
->host
);
909 fc_port_t
*fcport
= (struct fc_port
*) cmd
->device
->hostdata
;
912 unsigned int id
, lun
;
913 unsigned long serial
;
917 id
= cmd
->device
->id
;
918 lun
= cmd
->device
->lun
;
919 serial
= cmd
->serial_number
;
921 sp
= (srb_t
*) CMD_SP(cmd
);
925 qla_printk(KERN_INFO
, ha
,
926 "scsi(%ld:%d:%d): ADAPTER RESET ISSUED.\n", ha
->host_no
, id
, lun
);
928 if (qla2x00_wait_for_hba_online(ha
) != QLA_SUCCESS
)
929 goto eh_host_reset_lock
;
932 * Fixme-may be dpc thread is active and processing
933 * loop_resync,so wait a while for it to
934 * be completed and then issue big hammer.Otherwise
935 * it may cause I/O failure as big hammer marks the
936 * devices as lost kicking of the port_down_timer
937 * while dpc is stuck for the mailbox to complete.
939 qla2x00_wait_for_loop_ready(ha
);
940 set_bit(ABORT_ISP_ACTIVE
, &ha
->dpc_flags
);
941 if (qla2x00_abort_isp(ha
)) {
942 clear_bit(ABORT_ISP_ACTIVE
, &ha
->dpc_flags
);
943 /* failed. schedule dpc to try */
944 set_bit(ISP_ABORT_NEEDED
, &ha
->dpc_flags
);
946 if (qla2x00_wait_for_hba_online(ha
) != QLA_SUCCESS
)
947 goto eh_host_reset_lock
;
949 clear_bit(ABORT_ISP_ACTIVE
, &ha
->dpc_flags
);
951 /* Waiting for our command in done_queue to be returned to OS.*/
952 if (qla2x00_eh_wait_for_pending_commands(ha
))
956 qla_printk(KERN_INFO
, ha
, "%s: reset %s\n", __func__
,
957 (ret
== FAILED
) ? "failed" : "succeded");
967 * ha = adapter block pointer.
973 qla2x00_loop_reset(scsi_qla_host_t
*ha
)
975 int status
= QLA_SUCCESS
;
976 struct fc_port
*fcport
;
978 if (ha
->flags
.enable_lip_reset
) {
979 status
= qla2x00_lip_reset(ha
);
982 if (status
== QLA_SUCCESS
&& ha
->flags
.enable_target_reset
) {
983 list_for_each_entry(fcport
, &ha
->fcports
, list
) {
984 if (fcport
->port_type
!= FCT_TARGET
)
987 status
= qla2x00_device_reset(ha
, fcport
);
988 if (status
!= QLA_SUCCESS
)
993 if (status
== QLA_SUCCESS
&&
994 ((!ha
->flags
.enable_target_reset
&&
995 !ha
->flags
.enable_lip_reset
) ||
996 ha
->flags
.enable_lip_full_login
)) {
998 status
= qla2x00_full_login_lip(ha
);
1001 /* Issue marker command only when we are going to start the I/O */
1002 ha
->marker_needed
= 1;
1006 DEBUG2_3(printk("%s(%ld): **** FAILED ****\n",
1011 DEBUG3(printk("%s(%ld): exiting normally.\n",
1020 * qla2x00_device_reset
1021 * Issue bus device reset message to the target.
1024 * ha = adapter block pointer.
1026 * TARGET_QUEUE_LOCK must be released.
1027 * ADAPTER_STATE_LOCK must be released.
1033 qla2x00_device_reset(scsi_qla_host_t
*ha
, fc_port_t
*reset_fcport
)
1035 /* Abort Target command will clear Reservation */
1036 return ha
->isp_ops
.abort_target(reset_fcport
);
1040 qla2xxx_slave_alloc(struct scsi_device
*sdev
)
1042 struct fc_rport
*rport
= starget_to_rport(scsi_target(sdev
));
1047 sdev
->hostdata
= rport
->dd_data
;
1053 qla2xxx_slave_configure(struct scsi_device
*sdev
)
1055 scsi_qla_host_t
*ha
= to_qla_host(sdev
->host
);
1056 struct fc_rport
*rport
= starget_to_rport(sdev
->sdev_target
);
1058 if (sdev
->tagged_supported
)
1059 scsi_activate_tcq(sdev
, 32);
1061 scsi_deactivate_tcq(sdev
, 32);
1063 rport
->dev_loss_tmo
= ha
->port_down_retry_count
+ 5;
1069 qla2xxx_slave_destroy(struct scsi_device
*sdev
)
1071 sdev
->hostdata
= NULL
;
1075 qla2x00_change_queue_depth(struct scsi_device
*sdev
, int qdepth
)
1077 scsi_adjust_queue_depth(sdev
, scsi_get_tag_type(sdev
), qdepth
);
1078 return sdev
->queue_depth
;
1082 qla2x00_change_queue_type(struct scsi_device
*sdev
, int tag_type
)
1084 if (sdev
->tagged_supported
) {
1085 scsi_set_tag_type(sdev
, tag_type
);
1087 scsi_activate_tcq(sdev
, sdev
->queue_depth
);
1089 scsi_deactivate_tcq(sdev
, sdev
->queue_depth
);
1097 * qla2x00_config_dma_addressing() - Configure OS DMA addressing method.
1100 * At exit, the @ha's flags.enable_64bit_addressing set to indicated
1101 * supported addressing method.
1104 qla2x00_config_dma_addressing(scsi_qla_host_t
*ha
)
1106 /* Assume a 32bit DMA mask. */
1107 ha
->flags
.enable_64bit_addressing
= 0;
1109 if (!dma_set_mask(&ha
->pdev
->dev
, DMA_64BIT_MASK
)) {
1110 /* Any upper-dword bits set? */
1111 if (MSD(dma_get_required_mask(&ha
->pdev
->dev
)) &&
1112 !pci_set_consistent_dma_mask(ha
->pdev
, DMA_64BIT_MASK
)) {
1113 /* Ok, a 64bit DMA mask is applicable. */
1114 ha
->flags
.enable_64bit_addressing
= 1;
1115 ha
->isp_ops
.calc_req_entries
= qla2x00_calc_iocbs_64
;
1116 ha
->isp_ops
.build_iocbs
= qla2x00_build_scsi_iocbs_64
;
1121 dma_set_mask(&ha
->pdev
->dev
, DMA_32BIT_MASK
);
1122 pci_set_consistent_dma_mask(ha
->pdev
, DMA_32BIT_MASK
);
1126 qla2x00_iospace_config(scsi_qla_host_t
*ha
)
1128 unsigned long pio
, pio_len
, pio_flags
;
1129 unsigned long mmio
, mmio_len
, mmio_flags
;
1131 /* We only need PIO for Flash operations on ISP2312 v2 chips. */
1132 pio
= pci_resource_start(ha
->pdev
, 0);
1133 pio_len
= pci_resource_len(ha
->pdev
, 0);
1134 pio_flags
= pci_resource_flags(ha
->pdev
, 0);
1135 if (pio_flags
& IORESOURCE_IO
) {
1136 if (pio_len
< MIN_IOBASE_LEN
) {
1137 qla_printk(KERN_WARNING
, ha
,
1138 "Invalid PCI I/O region size (%s)...\n",
1139 pci_name(ha
->pdev
));
1143 qla_printk(KERN_WARNING
, ha
,
1144 "region #0 not a PIO resource (%s)...\n",
1145 pci_name(ha
->pdev
));
1149 /* Use MMIO operations for all accesses. */
1150 mmio
= pci_resource_start(ha
->pdev
, 1);
1151 mmio_len
= pci_resource_len(ha
->pdev
, 1);
1152 mmio_flags
= pci_resource_flags(ha
->pdev
, 1);
1154 if (!(mmio_flags
& IORESOURCE_MEM
)) {
1155 qla_printk(KERN_ERR
, ha
,
1156 "region #0 not an MMIO resource (%s), aborting\n",
1157 pci_name(ha
->pdev
));
1158 goto iospace_error_exit
;
1160 if (mmio_len
< MIN_IOBASE_LEN
) {
1161 qla_printk(KERN_ERR
, ha
,
1162 "Invalid PCI mem region size (%s), aborting\n",
1163 pci_name(ha
->pdev
));
1164 goto iospace_error_exit
;
1167 if (pci_request_regions(ha
->pdev
, ha
->brd_info
->drv_name
)) {
1168 qla_printk(KERN_WARNING
, ha
,
1169 "Failed to reserve PIO/MMIO regions (%s)\n",
1170 pci_name(ha
->pdev
));
1172 goto iospace_error_exit
;
1175 ha
->pio_address
= pio
;
1176 ha
->pio_length
= pio_len
;
1177 ha
->iobase
= ioremap(mmio
, MIN_IOBASE_LEN
);
1179 qla_printk(KERN_ERR
, ha
,
1180 "cannot remap MMIO (%s), aborting\n", pci_name(ha
->pdev
));
1182 goto iospace_error_exit
;
1192 qla2x00_enable_intrs(scsi_qla_host_t
*ha
)
1194 unsigned long flags
= 0;
1195 struct device_reg_2xxx __iomem
*reg
= &ha
->iobase
->isp
;
1197 spin_lock_irqsave(&ha
->hardware_lock
, flags
);
1198 ha
->interrupts_on
= 1;
1199 /* enable risc and host interrupts */
1200 WRT_REG_WORD(®
->ictrl
, ICR_EN_INT
| ICR_EN_RISC
);
1201 RD_REG_WORD(®
->ictrl
);
1202 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
1207 qla2x00_disable_intrs(scsi_qla_host_t
*ha
)
1209 unsigned long flags
= 0;
1210 struct device_reg_2xxx __iomem
*reg
= &ha
->iobase
->isp
;
1212 spin_lock_irqsave(&ha
->hardware_lock
, flags
);
1213 ha
->interrupts_on
= 0;
1214 /* disable risc and host interrupts */
1215 WRT_REG_WORD(®
->ictrl
, 0);
1216 RD_REG_WORD(®
->ictrl
);
1217 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
1221 qla24xx_enable_intrs(scsi_qla_host_t
*ha
)
1223 unsigned long flags
= 0;
1224 struct device_reg_24xx __iomem
*reg
= &ha
->iobase
->isp24
;
1226 spin_lock_irqsave(&ha
->hardware_lock
, flags
);
1227 ha
->interrupts_on
= 1;
1228 WRT_REG_DWORD(®
->ictrl
, ICRX_EN_RISC_INT
);
1229 RD_REG_DWORD(®
->ictrl
);
1230 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
1234 qla24xx_disable_intrs(scsi_qla_host_t
*ha
)
1236 unsigned long flags
= 0;
1237 struct device_reg_24xx __iomem
*reg
= &ha
->iobase
->isp24
;
1239 spin_lock_irqsave(&ha
->hardware_lock
, flags
);
1240 ha
->interrupts_on
= 0;
1241 WRT_REG_DWORD(®
->ictrl
, 0);
1242 RD_REG_DWORD(®
->ictrl
);
1243 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
1247 * PCI driver interface
1249 int qla2x00_probe_one(struct pci_dev
*pdev
, struct qla_board_info
*brd_info
)
1252 device_reg_t __iomem
*reg
;
1253 struct Scsi_Host
*host
;
1254 scsi_qla_host_t
*ha
;
1255 unsigned long flags
= 0;
1256 unsigned long wait_switch
= 0;
1261 if (pci_enable_device(pdev
))
1264 host
= scsi_host_alloc(brd_info
->sht
? brd_info
->sht
:
1265 &qla2x00_driver_template
, sizeof(scsi_qla_host_t
));
1268 "qla2xxx: Couldn't allocate host from scsi layer!\n");
1269 goto probe_disable_device
;
1272 /* Clear our data area */
1273 ha
= (scsi_qla_host_t
*)host
->hostdata
;
1274 memset(ha
, 0, sizeof(scsi_qla_host_t
));
1278 ha
->host_no
= host
->host_no
;
1279 ha
->brd_info
= brd_info
;
1280 sprintf(ha
->host_str
, "%s_%ld", ha
->brd_info
->drv_name
, ha
->host_no
);
1284 /* Configure PCI I/O space */
1285 ret
= qla2x00_iospace_config(ha
);
1289 qla_printk(KERN_INFO
, ha
,
1290 "Found an %s, irq %d, iobase 0x%p\n", ha
->brd_info
->isp_name
,
1291 pdev
->irq
, ha
->iobase
);
1293 spin_lock_init(&ha
->hardware_lock
);
1295 ha
->prev_topology
= 0;
1296 ha
->ports
= MAX_BUSES
;
1297 ha
->init_cb_size
= sizeof(init_cb_t
);
1298 ha
->mgmt_svr_loop_id
= MANAGEMENT_SERVER
;
1300 /* Assign ISP specific operations. */
1301 ha
->isp_ops
.pci_config
= qla2100_pci_config
;
1302 ha
->isp_ops
.reset_chip
= qla2x00_reset_chip
;
1303 ha
->isp_ops
.chip_diag
= qla2x00_chip_diag
;
1304 ha
->isp_ops
.config_rings
= qla2x00_config_rings
;
1305 ha
->isp_ops
.reset_adapter
= qla2x00_reset_adapter
;
1306 ha
->isp_ops
.nvram_config
= qla2x00_nvram_config
;
1307 ha
->isp_ops
.update_fw_options
= qla2x00_update_fw_options
;
1308 ha
->isp_ops
.load_risc
= qla2x00_load_risc
;
1309 ha
->isp_ops
.pci_info_str
= qla2x00_pci_info_str
;
1310 ha
->isp_ops
.fw_version_str
= qla2x00_fw_version_str
;
1311 ha
->isp_ops
.intr_handler
= qla2100_intr_handler
;
1312 ha
->isp_ops
.enable_intrs
= qla2x00_enable_intrs
;
1313 ha
->isp_ops
.disable_intrs
= qla2x00_disable_intrs
;
1314 ha
->isp_ops
.abort_command
= qla2x00_abort_command
;
1315 ha
->isp_ops
.abort_target
= qla2x00_abort_target
;
1316 ha
->isp_ops
.fabric_login
= qla2x00_login_fabric
;
1317 ha
->isp_ops
.fabric_logout
= qla2x00_fabric_logout
;
1318 ha
->isp_ops
.calc_req_entries
= qla2x00_calc_iocbs_32
;
1319 ha
->isp_ops
.build_iocbs
= qla2x00_build_scsi_iocbs_32
;
1320 ha
->isp_ops
.prep_ms_iocb
= qla2x00_prep_ms_iocb
;
1321 ha
->isp_ops
.prep_ms_fdmi_iocb
= qla2x00_prep_ms_fdmi_iocb
;
1322 ha
->isp_ops
.read_nvram
= qla2x00_read_nvram_data
;
1323 ha
->isp_ops
.write_nvram
= qla2x00_write_nvram_data
;
1324 ha
->isp_ops
.fw_dump
= qla2100_fw_dump
;
1325 ha
->isp_ops
.ascii_fw_dump
= qla2100_ascii_fw_dump
;
1326 if (IS_QLA2100(ha
)) {
1327 host
->max_id
= MAX_TARGETS_2100
;
1328 ha
->mbx_count
= MAILBOX_REGISTER_COUNT_2100
;
1329 ha
->request_q_length
= REQUEST_ENTRY_CNT_2100
;
1330 ha
->response_q_length
= RESPONSE_ENTRY_CNT_2100
;
1331 ha
->last_loop_id
= SNS_LAST_LOOP_ID_2100
;
1332 host
->sg_tablesize
= 32;
1333 ha
->gid_list_info_size
= 4;
1334 } else if (IS_QLA2200(ha
)) {
1335 host
->max_id
= MAX_TARGETS_2200
;
1336 ha
->mbx_count
= MAILBOX_REGISTER_COUNT
;
1337 ha
->request_q_length
= REQUEST_ENTRY_CNT_2200
;
1338 ha
->response_q_length
= RESPONSE_ENTRY_CNT_2100
;
1339 ha
->last_loop_id
= SNS_LAST_LOOP_ID_2100
;
1340 ha
->gid_list_info_size
= 4;
1341 } else if (IS_QLA23XX(ha
)) {
1342 host
->max_id
= MAX_TARGETS_2200
;
1343 ha
->mbx_count
= MAILBOX_REGISTER_COUNT
;
1344 ha
->request_q_length
= REQUEST_ENTRY_CNT_2200
;
1345 ha
->response_q_length
= RESPONSE_ENTRY_CNT_2300
;
1346 ha
->last_loop_id
= SNS_LAST_LOOP_ID_2300
;
1347 ha
->isp_ops
.pci_config
= qla2300_pci_config
;
1348 ha
->isp_ops
.intr_handler
= qla2300_intr_handler
;
1349 ha
->isp_ops
.fw_dump
= qla2300_fw_dump
;
1350 ha
->isp_ops
.ascii_fw_dump
= qla2300_ascii_fw_dump
;
1351 ha
->gid_list_info_size
= 6;
1352 } else if (IS_QLA24XX(ha
) || IS_QLA25XX(ha
)) {
1353 host
->max_id
= MAX_TARGETS_2200
;
1354 ha
->mbx_count
= MAILBOX_REGISTER_COUNT
;
1355 ha
->request_q_length
= REQUEST_ENTRY_CNT_24XX
;
1356 ha
->response_q_length
= RESPONSE_ENTRY_CNT_2300
;
1357 ha
->last_loop_id
= SNS_LAST_LOOP_ID_2300
;
1358 ha
->init_cb_size
= sizeof(struct init_cb_24xx
);
1359 ha
->mgmt_svr_loop_id
= 10;
1360 ha
->isp_ops
.pci_config
= qla24xx_pci_config
;
1361 ha
->isp_ops
.reset_chip
= qla24xx_reset_chip
;
1362 ha
->isp_ops
.chip_diag
= qla24xx_chip_diag
;
1363 ha
->isp_ops
.config_rings
= qla24xx_config_rings
;
1364 ha
->isp_ops
.reset_adapter
= qla24xx_reset_adapter
;
1365 ha
->isp_ops
.nvram_config
= qla24xx_nvram_config
;
1366 ha
->isp_ops
.update_fw_options
= qla24xx_update_fw_options
;
1367 ha
->isp_ops
.load_risc
= qla24xx_load_risc_flash
;
1369 ha
->isp_ops
.load_risc
= qla24xx_load_risc_hotplug
;
1370 ha
->isp_ops
.pci_info_str
= qla24xx_pci_info_str
;
1371 ha
->isp_ops
.fw_version_str
= qla24xx_fw_version_str
;
1372 ha
->isp_ops
.intr_handler
= qla24xx_intr_handler
;
1373 ha
->isp_ops
.enable_intrs
= qla24xx_enable_intrs
;
1374 ha
->isp_ops
.disable_intrs
= qla24xx_disable_intrs
;
1375 ha
->isp_ops
.abort_command
= qla24xx_abort_command
;
1376 ha
->isp_ops
.abort_target
= qla24xx_abort_target
;
1377 ha
->isp_ops
.fabric_login
= qla24xx_login_fabric
;
1378 ha
->isp_ops
.fabric_logout
= qla24xx_fabric_logout
;
1379 ha
->isp_ops
.prep_ms_iocb
= qla24xx_prep_ms_iocb
;
1380 ha
->isp_ops
.prep_ms_fdmi_iocb
= qla24xx_prep_ms_fdmi_iocb
;
1381 ha
->isp_ops
.read_nvram
= qla24xx_read_nvram_data
;
1382 ha
->isp_ops
.write_nvram
= qla24xx_write_nvram_data
;
1383 ha
->isp_ops
.fw_dump
= qla24xx_fw_dump
;
1384 ha
->isp_ops
.ascii_fw_dump
= qla24xx_ascii_fw_dump
;
1385 ha
->gid_list_info_size
= 8;
1387 host
->can_queue
= ha
->request_q_length
+ 128;
1389 /* load the F/W, read paramaters, and init the H/W */
1390 ha
->instance
= num_hosts
;
1392 init_MUTEX(&ha
->mbx_cmd_sem
);
1393 init_MUTEX_LOCKED(&ha
->mbx_intr_sem
);
1395 INIT_LIST_HEAD(&ha
->list
);
1396 INIT_LIST_HEAD(&ha
->fcports
);
1397 INIT_LIST_HEAD(&ha
->rscn_fcports
);
1400 * These locks are used to prevent more than one CPU
1401 * from modifying the queue at the same time. The
1402 * higher level "host_lock" will reduce most
1403 * contention for these locks.
1405 spin_lock_init(&ha
->mbx_reg_lock
);
1407 init_completion(&ha
->dpc_inited
);
1408 init_completion(&ha
->dpc_exited
);
1410 qla2x00_config_dma_addressing(ha
);
1411 if (qla2x00_mem_alloc(ha
)) {
1412 qla_printk(KERN_WARNING
, ha
,
1413 "[ERROR] Failed to allocate memory for adapter\n");
1419 if (qla2x00_initialize_adapter(ha
) &&
1420 !(ha
->device_flags
& DFLG_NO_CABLE
)) {
1422 qla_printk(KERN_WARNING
, ha
,
1423 "Failed to initialize adapter\n");
1425 DEBUG2(printk("scsi(%ld): Failed to initialize adapter - "
1426 "Adapter flags %x.\n",
1427 ha
->host_no
, ha
->device_flags
));
1434 * Startup the kernel thread for this host adapter
1436 ha
->dpc_should_die
= 0;
1437 ha
->dpc_pid
= kernel_thread(qla2x00_do_dpc
, ha
, 0);
1438 if (ha
->dpc_pid
< 0) {
1439 qla_printk(KERN_WARNING
, ha
,
1440 "Unable to start DPC thread!\n");
1445 wait_for_completion(&ha
->dpc_inited
);
1447 host
->this_id
= 255;
1448 host
->cmd_per_lun
= 3;
1449 host
->unique_id
= ha
->instance
;
1450 host
->max_cmd_len
= MAX_CMDSZ
;
1451 host
->max_channel
= ha
->ports
- 1;
1452 host
->max_lun
= MAX_LUNS
;
1453 host
->transportt
= qla2xxx_transport_template
;
1455 ret
= request_irq(pdev
->irq
, ha
->isp_ops
.intr_handler
,
1456 SA_INTERRUPT
|SA_SHIRQ
, ha
->brd_info
->drv_name
, ha
);
1458 qla_printk(KERN_WARNING
, ha
,
1459 "Failed to reserve interrupt %d already in use.\n",
1463 host
->irq
= pdev
->irq
;
1465 /* Initialized the timer */
1466 qla2x00_start_timer(ha
, qla2x00_timer
, WATCH_INTERVAL
);
1468 DEBUG2(printk("DEBUG: detect hba %ld at address = %p\n",
1471 ha
->isp_ops
.disable_intrs(ha
);
1473 spin_lock_irqsave(&ha
->hardware_lock
, flags
);
1475 if (IS_QLA24XX(ha
) || IS_QLA25XX(ha
)) {
1476 WRT_REG_DWORD(®
->isp24
.hccr
, HCCRX_CLR_HOST_INT
);
1477 WRT_REG_DWORD(®
->isp24
.hccr
, HCCRX_CLR_RISC_INT
);
1479 WRT_REG_WORD(®
->isp
.semaphore
, 0);
1480 WRT_REG_WORD(®
->isp
.hccr
, HCCR_CLR_RISC_INT
);
1481 WRT_REG_WORD(®
->isp
.hccr
, HCCR_CLR_HOST_INT
);
1483 /* Enable proper parity */
1484 if (!IS_QLA2100(ha
) && !IS_QLA2200(ha
)) {
1487 WRT_REG_WORD(®
->isp
.hccr
,
1488 (HCCR_ENABLE_PARITY
+ 0x1));
1490 /* SRAM, Instruction RAM and GP RAM parity */
1491 WRT_REG_WORD(®
->isp
.hccr
,
1492 (HCCR_ENABLE_PARITY
+ 0x7));
1495 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
1497 ha
->isp_ops
.enable_intrs(ha
);
1501 * Wait around max loop_reset_delay secs for the devices to come
1502 * on-line. We don't want Linux scanning before we are ready.
1505 for (wait_switch
= jiffies
+ (ha
->loop_reset_delay
* HZ
);
1506 time_before(jiffies
,wait_switch
) &&
1507 !(ha
->device_flags
& (DFLG_NO_CABLE
| DFLG_FABRIC_DEVICES
))
1508 && (ha
->device_flags
& SWITCH_FOUND
) ;) {
1510 qla2x00_check_fabric_devices(ha
);
1515 pci_set_drvdata(pdev
, ha
);
1516 ha
->flags
.init_done
= 1;
1519 ret
= scsi_add_host(host
, &pdev
->dev
);
1523 qla2x00_alloc_sysfs_attr(ha
);
1525 qla2x00_init_host_attr(ha
);
1527 qla_printk(KERN_INFO
, ha
, "\n"
1528 " QLogic Fibre Channel HBA Driver: %s\n"
1530 " %s: %s @ %s hdma%c, host#=%ld, fw=%s\n", qla2x00_version_str
,
1531 ha
->model_number
, ha
->model_desc
? ha
->model_desc
: "",
1532 ha
->brd_info
->isp_name
, ha
->isp_ops
.pci_info_str(ha
, pci_info
),
1533 pci_name(pdev
), ha
->flags
.enable_64bit_addressing
? '+': '-',
1534 ha
->host_no
, ha
->isp_ops
.fw_version_str(ha
, fw_str
));
1536 /* Go with fc_rport registration. */
1537 list_for_each_entry(fcport
, &ha
->fcports
, list
)
1538 qla2x00_reg_remote_port(ha
, fcport
);
1543 qla2x00_free_device(ha
);
1545 scsi_host_put(host
);
1547 probe_disable_device
:
1548 pci_disable_device(pdev
);
1553 EXPORT_SYMBOL_GPL(qla2x00_probe_one
);
1555 void qla2x00_remove_one(struct pci_dev
*pdev
)
1557 scsi_qla_host_t
*ha
;
1559 ha
= pci_get_drvdata(pdev
);
1561 qla2x00_free_sysfs_attr(ha
);
1563 fc_remove_host(ha
->host
);
1565 scsi_remove_host(ha
->host
);
1567 qla2x00_free_device(ha
);
1569 scsi_host_put(ha
->host
);
1571 pci_set_drvdata(pdev
, NULL
);
1573 EXPORT_SYMBOL_GPL(qla2x00_remove_one
);
1576 qla2x00_free_device(scsi_qla_host_t
*ha
)
1580 /* Abort any outstanding IO descriptors. */
1581 if (!IS_QLA2100(ha
) && !IS_QLA2200(ha
))
1582 qla2x00_cancel_io_descriptors(ha
);
1585 if (ha
->timer_active
)
1586 qla2x00_stop_timer(ha
);
1588 /* Kill the kernel thread for this host */
1589 if (ha
->dpc_pid
>= 0) {
1590 ha
->dpc_should_die
= 1;
1592 ret
= kill_proc(ha
->dpc_pid
, SIGHUP
, 1);
1594 qla_printk(KERN_ERR
, ha
,
1595 "Unable to signal DPC thread -- (%d)\n", ret
);
1597 /* TODO: SOMETHING MORE??? */
1599 wait_for_completion(&ha
->dpc_exited
);
1603 /* Stop currently executing firmware. */
1604 qla2x00_stop_firmware(ha
);
1606 /* turn-off interrupts on the card */
1607 if (ha
->interrupts_on
)
1608 ha
->isp_ops
.disable_intrs(ha
);
1610 qla2x00_mem_free(ha
);
1612 ha
->flags
.online
= 0;
1614 /* Detach interrupts */
1616 free_irq(ha
->pdev
->irq
, ha
);
1618 /* release io space registers */
1620 iounmap(ha
->iobase
);
1621 pci_release_regions(ha
->pdev
);
1623 pci_disable_device(ha
->pdev
);
1627 * qla2x00_mark_device_lost Updates fcport state when device goes offline.
1629 * Input: ha = adapter block pointer. fcport = port structure pointer.
1635 void qla2x00_mark_device_lost(scsi_qla_host_t
*ha
, fc_port_t
*fcport
,
1638 if (atomic_read(&fcport
->state
) == FCS_ONLINE
&& fcport
->rport
)
1639 fc_remote_port_block(fcport
->rport
);
1641 * We may need to retry the login, so don't change the state of the
1642 * port but do the retries.
1644 if (atomic_read(&fcport
->state
) != FCS_DEVICE_DEAD
)
1645 atomic_set(&fcport
->state
, FCS_DEVICE_LOST
);
1650 if (fcport
->login_retry
== 0) {
1651 fcport
->login_retry
= ha
->login_retry_count
;
1652 set_bit(RELOGIN_NEEDED
, &ha
->dpc_flags
);
1654 DEBUG(printk("scsi(%ld): Port login retry: "
1655 "%02x%02x%02x%02x%02x%02x%02x%02x, "
1656 "id = 0x%04x retry cnt=%d\n",
1658 fcport
->port_name
[0],
1659 fcport
->port_name
[1],
1660 fcport
->port_name
[2],
1661 fcport
->port_name
[3],
1662 fcport
->port_name
[4],
1663 fcport
->port_name
[5],
1664 fcport
->port_name
[6],
1665 fcport
->port_name
[7],
1667 fcport
->login_retry
));
1672 * qla2x00_mark_all_devices_lost
1673 * Updates fcport state when device goes offline.
1676 * ha = adapter block pointer.
1677 * fcport = port structure pointer.
1685 qla2x00_mark_all_devices_lost(scsi_qla_host_t
*ha
)
1689 list_for_each_entry(fcport
, &ha
->fcports
, list
) {
1690 if (fcport
->port_type
!= FCT_TARGET
)
1694 * No point in marking the device as lost, if the device is
1697 if (atomic_read(&fcport
->state
) == FCS_DEVICE_DEAD
)
1699 if (atomic_read(&fcport
->state
) == FCS_ONLINE
&& fcport
->rport
)
1700 fc_remote_port_block(fcport
->rport
);
1701 atomic_set(&fcport
->state
, FCS_DEVICE_LOST
);
1707 * Allocates adapter memory.
1714 qla2x00_mem_alloc(scsi_qla_host_t
*ha
)
1722 * This will loop only once if everything goes well, else some
1723 * number of retries will be performed to get around a kernel
1724 * bug where available mem is not allocated until after a
1725 * little delay and a retry.
1727 ha
->request_ring
= dma_alloc_coherent(&ha
->pdev
->dev
,
1728 (ha
->request_q_length
+ 1) * sizeof(request_t
),
1729 &ha
->request_dma
, GFP_KERNEL
);
1730 if (ha
->request_ring
== NULL
) {
1731 qla_printk(KERN_WARNING
, ha
,
1732 "Memory Allocation failed - request_ring\n");
1734 qla2x00_mem_free(ha
);
1740 ha
->response_ring
= dma_alloc_coherent(&ha
->pdev
->dev
,
1741 (ha
->response_q_length
+ 1) * sizeof(response_t
),
1742 &ha
->response_dma
, GFP_KERNEL
);
1743 if (ha
->response_ring
== NULL
) {
1744 qla_printk(KERN_WARNING
, ha
,
1745 "Memory Allocation failed - response_ring\n");
1747 qla2x00_mem_free(ha
);
1753 ha
->gid_list
= dma_alloc_coherent(&ha
->pdev
->dev
, GID_LIST_SIZE
,
1754 &ha
->gid_list_dma
, GFP_KERNEL
);
1755 if (ha
->gid_list
== NULL
) {
1756 qla_printk(KERN_WARNING
, ha
,
1757 "Memory Allocation failed - gid_list\n");
1759 qla2x00_mem_free(ha
);
1765 ha
->rlc_rsp
= dma_alloc_coherent(&ha
->pdev
->dev
,
1766 sizeof(rpt_lun_cmd_rsp_t
), &ha
->rlc_rsp_dma
, GFP_KERNEL
);
1767 if (ha
->rlc_rsp
== NULL
) {
1768 qla_printk(KERN_WARNING
, ha
,
1769 "Memory Allocation failed - rlc");
1771 qla2x00_mem_free(ha
);
1777 snprintf(name
, sizeof(name
), "qla2xxx_%ld", ha
->host_no
);
1778 ha
->s_dma_pool
= dma_pool_create(name
, &ha
->pdev
->dev
,
1779 DMA_POOL_SIZE
, 8, 0);
1780 if (ha
->s_dma_pool
== NULL
) {
1781 qla_printk(KERN_WARNING
, ha
,
1782 "Memory Allocation failed - s_dma_pool\n");
1784 qla2x00_mem_free(ha
);
1790 /* get consistent memory allocated for init control block */
1791 ha
->init_cb
= dma_pool_alloc(ha
->s_dma_pool
, GFP_KERNEL
,
1793 if (ha
->init_cb
== NULL
) {
1794 qla_printk(KERN_WARNING
, ha
,
1795 "Memory Allocation failed - init_cb\n");
1797 qla2x00_mem_free(ha
);
1802 memset(ha
->init_cb
, 0, ha
->init_cb_size
);
1804 /* Get consistent memory allocated for Get Port Database cmd */
1805 ha
->iodesc_pd
= dma_pool_alloc(ha
->s_dma_pool
, GFP_KERNEL
,
1806 &ha
->iodesc_pd_dma
);
1807 if (ha
->iodesc_pd
== NULL
) {
1809 qla_printk(KERN_WARNING
, ha
,
1810 "Memory Allocation failed - iodesc_pd\n");
1812 qla2x00_mem_free(ha
);
1817 memset(ha
->iodesc_pd
, 0, PORT_DATABASE_SIZE
);
1819 /* Allocate ioctl related memory. */
1820 if (qla2x00_alloc_ioctl_mem(ha
)) {
1821 qla_printk(KERN_WARNING
, ha
,
1822 "Memory Allocation failed - ioctl_mem\n");
1824 qla2x00_mem_free(ha
);
1830 if (qla2x00_allocate_sp_pool(ha
)) {
1831 qla_printk(KERN_WARNING
, ha
,
1832 "Memory Allocation failed - "
1833 "qla2x00_allocate_sp_pool()\n");
1835 qla2x00_mem_free(ha
);
1841 /* Allocate memory for SNS commands */
1842 if (IS_QLA2100(ha
) || IS_QLA2200(ha
)) {
1843 /* Get consistent memory allocated for SNS commands */
1844 ha
->sns_cmd
= dma_alloc_coherent(&ha
->pdev
->dev
,
1845 sizeof(struct sns_cmd_pkt
), &ha
->sns_cmd_dma
,
1847 if (ha
->sns_cmd
== NULL
) {
1849 qla_printk(KERN_WARNING
, ha
,
1850 "Memory Allocation failed - sns_cmd\n");
1852 qla2x00_mem_free(ha
);
1857 memset(ha
->sns_cmd
, 0, sizeof(struct sns_cmd_pkt
));
1859 /* Get consistent memory allocated for MS IOCB */
1860 ha
->ms_iocb
= dma_pool_alloc(ha
->s_dma_pool
, GFP_KERNEL
,
1862 if (ha
->ms_iocb
== NULL
) {
1864 qla_printk(KERN_WARNING
, ha
,
1865 "Memory Allocation failed - ms_iocb\n");
1867 qla2x00_mem_free(ha
);
1872 memset(ha
->ms_iocb
, 0, sizeof(ms_iocb_entry_t
));
1875 * Get consistent memory allocated for CT SNS
1878 ha
->ct_sns
= dma_alloc_coherent(&ha
->pdev
->dev
,
1879 sizeof(struct ct_sns_pkt
), &ha
->ct_sns_dma
,
1881 if (ha
->ct_sns
== NULL
) {
1883 qla_printk(KERN_WARNING
, ha
,
1884 "Memory Allocation failed - ct_sns\n");
1886 qla2x00_mem_free(ha
);
1891 memset(ha
->ct_sns
, 0, sizeof(struct ct_sns_pkt
));
1894 /* Done all allocations without any error. */
1897 } while (retry
-- && status
!= 0);
1901 "%s(): **** FAILED ****\n", __func__
);
1909 * Frees all adapter allocated memory.
1912 * ha = adapter block pointer.
1915 qla2x00_mem_free(scsi_qla_host_t
*ha
)
1917 struct list_head
*fcpl
, *fcptemp
;
1919 unsigned int wtime
;/* max wait time if mbx cmd is busy. */
1923 DEBUG2(printk("%s(): ERROR invalid ha pointer.\n", __func__
));
1927 /* Make sure all other threads are stopped. */
1929 while (ha
->dpc_wait
&& wtime
)
1930 wtime
= msleep_interruptible(wtime
);
1932 /* free ioctl memory */
1933 qla2x00_free_ioctl_mem(ha
);
1936 qla2x00_free_sp_pool(ha
);
1939 dma_free_coherent(&ha
->pdev
->dev
, sizeof(struct sns_cmd_pkt
),
1940 ha
->sns_cmd
, ha
->sns_cmd_dma
);
1943 dma_free_coherent(&ha
->pdev
->dev
, sizeof(struct ct_sns_pkt
),
1944 ha
->ct_sns
, ha
->ct_sns_dma
);
1947 dma_pool_free(ha
->s_dma_pool
, ha
->ms_iocb
, ha
->ms_iocb_dma
);
1950 dma_pool_free(ha
->s_dma_pool
, ha
->iodesc_pd
, ha
->iodesc_pd_dma
);
1953 dma_pool_free(ha
->s_dma_pool
, ha
->init_cb
, ha
->init_cb_dma
);
1956 dma_pool_destroy(ha
->s_dma_pool
);
1959 dma_free_coherent(&ha
->pdev
->dev
,
1960 sizeof(rpt_lun_cmd_rsp_t
), ha
->rlc_rsp
,
1964 dma_free_coherent(&ha
->pdev
->dev
, GID_LIST_SIZE
, ha
->gid_list
,
1967 if (ha
->response_ring
)
1968 dma_free_coherent(&ha
->pdev
->dev
,
1969 (ha
->response_q_length
+ 1) * sizeof(response_t
),
1970 ha
->response_ring
, ha
->response_dma
);
1972 if (ha
->request_ring
)
1973 dma_free_coherent(&ha
->pdev
->dev
,
1974 (ha
->request_q_length
+ 1) * sizeof(request_t
),
1975 ha
->request_ring
, ha
->request_dma
);
1978 ha
->sns_cmd_dma
= 0;
1982 ha
->ms_iocb_dma
= 0;
1983 ha
->iodesc_pd
= NULL
;
1984 ha
->iodesc_pd_dma
= 0;
1986 ha
->init_cb_dma
= 0;
1988 ha
->s_dma_pool
= NULL
;
1991 ha
->rlc_rsp_dma
= 0;
1992 ha
->gid_list
= NULL
;
1993 ha
->gid_list_dma
= 0;
1995 ha
->response_ring
= NULL
;
1996 ha
->response_dma
= 0;
1997 ha
->request_ring
= NULL
;
1998 ha
->request_dma
= 0;
2000 list_for_each_safe(fcpl
, fcptemp
, &ha
->fcports
) {
2001 fcport
= list_entry(fcpl
, fc_port_t
, list
);
2004 list_del_init(&fcport
->list
);
2007 INIT_LIST_HEAD(&ha
->fcports
);
2010 free_pages((unsigned long)ha
->fw_dump
, ha
->fw_dump_order
);
2012 vfree(ha
->fw_dump24
);
2014 vfree(ha
->fw_dump_buffer
);
2017 ha
->fw_dump24
= NULL
;
2019 ha
->fw_dump_reading
= 0;
2020 ha
->fw_dump_buffer
= NULL
;
2024 * qla2x00_allocate_sp_pool
2025 * This routine is called during initialization to allocate
2026 * memory for local srb_t.
2029 * ha = adapter block pointer.
2034 * Note: Sets the ref_count for non Null sp to one.
2037 qla2x00_allocate_sp_pool(scsi_qla_host_t
*ha
)
2042 ha
->srb_mempool
= mempool_create(SRB_MIN_REQ
, mempool_alloc_slab
,
2043 mempool_free_slab
, srb_cachep
);
2044 if (ha
->srb_mempool
== NULL
) {
2045 qla_printk(KERN_INFO
, ha
, "Unable to allocate SRB mempool.\n");
2046 rval
= QLA_FUNCTION_FAILED
;
2052 * This routine frees all adapter allocated memory.
2056 qla2x00_free_sp_pool( scsi_qla_host_t
*ha
)
2058 if (ha
->srb_mempool
) {
2059 mempool_destroy(ha
->srb_mempool
);
2060 ha
->srb_mempool
= NULL
;
2064 /**************************************************************************
2066 * This kernel thread is a task that is schedule by the interrupt handler
2067 * to perform the background processing for interrupts.
2070 * This task always run in the context of a kernel thread. It
2071 * is kick-off by the driver's detect code and starts up
2072 * up one per adapter. It immediately goes to sleep and waits for
2073 * some fibre event. When either the interrupt handler or
2074 * the timer routine detects a event it will one of the task
2075 * bits then wake us up.
2076 **************************************************************************/
2078 qla2x00_do_dpc(void *data
)
2080 DECLARE_MUTEX_LOCKED(sem
);
2081 scsi_qla_host_t
*ha
;
2084 uint16_t next_loopid
;
2086 ha
= (scsi_qla_host_t
*)data
;
2090 daemonize("%s_dpc", ha
->host_str
);
2091 allow_signal(SIGHUP
);
2093 ha
->dpc_wait
= &sem
;
2095 set_user_nice(current
, -20);
2099 complete(&ha
->dpc_inited
);
2102 DEBUG3(printk("qla2x00: DPC handler sleeping\n"));
2104 if (down_interruptible(&sem
))
2107 if (ha
->dpc_should_die
)
2110 DEBUG3(printk("qla2x00: DPC handler waking up\n"));
2112 /* Initialization not yet finished. Don't do anything yet. */
2113 if (!ha
->flags
.init_done
|| ha
->dpc_active
)
2116 DEBUG3(printk("scsi(%ld): DPC handler\n", ha
->host_no
));
2120 if (ha
->flags
.mbox_busy
) {
2125 if (test_and_clear_bit(ISP_ABORT_NEEDED
, &ha
->dpc_flags
)) {
2127 DEBUG(printk("scsi(%ld): dpc: sched "
2128 "qla2x00_abort_isp ha = %p\n",
2130 if (!(test_and_set_bit(ABORT_ISP_ACTIVE
,
2133 if (qla2x00_abort_isp(ha
)) {
2134 /* failed. retry later */
2135 set_bit(ISP_ABORT_NEEDED
,
2138 clear_bit(ABORT_ISP_ACTIVE
, &ha
->dpc_flags
);
2140 DEBUG(printk("scsi(%ld): dpc: qla2x00_abort_isp end\n",
2144 if (test_and_clear_bit(RESET_MARKER_NEEDED
, &ha
->dpc_flags
) &&
2145 (!(test_and_set_bit(RESET_ACTIVE
, &ha
->dpc_flags
)))) {
2147 DEBUG(printk("scsi(%ld): qla2x00_reset_marker()\n",
2150 qla2x00_rst_aen(ha
);
2151 clear_bit(RESET_ACTIVE
, &ha
->dpc_flags
);
2154 /* Retry each device up to login retry count */
2155 if ((test_and_clear_bit(RELOGIN_NEEDED
, &ha
->dpc_flags
)) &&
2156 !test_bit(LOOP_RESYNC_NEEDED
, &ha
->dpc_flags
) &&
2157 atomic_read(&ha
->loop_state
) != LOOP_DOWN
) {
2159 DEBUG(printk("scsi(%ld): qla2x00_port_login()\n",
2163 list_for_each_entry(fcport
, &ha
->fcports
, list
) {
2164 if (fcport
->port_type
!= FCT_TARGET
)
2168 * If the port is not ONLINE then try to login
2169 * to it if we haven't run out of retries.
2171 if (atomic_read(&fcport
->state
) != FCS_ONLINE
&&
2172 fcport
->login_retry
) {
2174 fcport
->login_retry
--;
2175 if (fcport
->flags
& FCF_FABRIC_DEVICE
) {
2178 ha
->isp_ops
.fabric_logout(
2179 ha
, fcport
->loop_id
,
2180 fcport
->d_id
.b
.domain
,
2181 fcport
->d_id
.b
.area
,
2182 fcport
->d_id
.b
.al_pa
);
2183 status
= qla2x00_fabric_login(
2184 ha
, fcport
, &next_loopid
);
2187 qla2x00_local_device_login(
2188 ha
, fcport
->loop_id
);
2190 if (status
== QLA_SUCCESS
) {
2191 fcport
->old_loop_id
= fcport
->loop_id
;
2193 DEBUG(printk("scsi(%ld): port login OK: logged in ID 0x%x\n",
2194 ha
->host_no
, fcport
->loop_id
));
2196 fcport
->port_login_retry_count
=
2197 ha
->port_down_retry_count
* PORT_RETRY_TIME
;
2198 atomic_set(&fcport
->state
, FCS_ONLINE
);
2199 atomic_set(&fcport
->port_down_timer
,
2200 ha
->port_down_retry_count
* PORT_RETRY_TIME
);
2202 fcport
->login_retry
= 0;
2203 } else if (status
== 1) {
2204 set_bit(RELOGIN_NEEDED
, &ha
->dpc_flags
);
2205 /* retry the login again */
2206 DEBUG(printk("scsi(%ld): Retrying %d login again loop_id 0x%x\n",
2208 fcport
->login_retry
, fcport
->loop_id
));
2210 fcport
->login_retry
= 0;
2213 if (test_bit(LOOP_RESYNC_NEEDED
, &ha
->dpc_flags
))
2216 DEBUG(printk("scsi(%ld): qla2x00_port_login - end\n",
2220 if ((test_bit(LOGIN_RETRY_NEEDED
, &ha
->dpc_flags
)) &&
2221 atomic_read(&ha
->loop_state
) != LOOP_DOWN
) {
2223 clear_bit(LOGIN_RETRY_NEEDED
, &ha
->dpc_flags
);
2224 DEBUG(printk("scsi(%ld): qla2x00_login_retry()\n",
2227 set_bit(LOOP_RESYNC_NEEDED
, &ha
->dpc_flags
);
2229 DEBUG(printk("scsi(%ld): qla2x00_login_retry - end\n",
2233 if (test_and_clear_bit(LOOP_RESYNC_NEEDED
, &ha
->dpc_flags
)) {
2235 DEBUG(printk("scsi(%ld): qla2x00_loop_resync()\n",
2238 if (!(test_and_set_bit(LOOP_RESYNC_ACTIVE
,
2241 qla2x00_loop_resync(ha
);
2243 clear_bit(LOOP_RESYNC_ACTIVE
, &ha
->dpc_flags
);
2246 DEBUG(printk("scsi(%ld): qla2x00_loop_resync - end\n",
2250 if (test_and_clear_bit(FCPORT_RESCAN_NEEDED
, &ha
->dpc_flags
)) {
2252 DEBUG(printk("scsi(%ld): Rescan flagged fcports...\n",
2255 qla2x00_rescan_fcports(ha
);
2257 DEBUG(printk("scsi(%ld): Rescan flagged fcports..."
2262 if (!ha
->interrupts_on
)
2263 ha
->isp_ops
.enable_intrs(ha
);
2266 } /* End of while(1) */
2268 DEBUG(printk("scsi(%ld): DPC handler exiting\n", ha
->host_no
));
2271 * Make sure that nobody tries to wake us up again.
2273 ha
->dpc_wait
= NULL
;
2276 complete_and_exit(&ha
->dpc_exited
, 0);
2281 * Processes asynchronous reset.
2284 * ha = adapter block pointer.
2287 qla2x00_rst_aen(scsi_qla_host_t
*ha
)
2289 if (ha
->flags
.online
&& !ha
->flags
.reset_active
&&
2290 !atomic_read(&ha
->loop_down_timer
) &&
2291 !(test_bit(ABORT_ISP_ACTIVE
, &ha
->dpc_flags
))) {
2293 clear_bit(RESET_MARKER_NEEDED
, &ha
->dpc_flags
);
2296 * Issue marker command only when we are going to start
2299 ha
->marker_needed
= 1;
2300 } while (!atomic_read(&ha
->loop_down_timer
) &&
2301 (test_bit(RESET_MARKER_NEEDED
, &ha
->dpc_flags
)));
2306 qla2x00_sp_free_dma(scsi_qla_host_t
*ha
, srb_t
*sp
)
2308 struct scsi_cmnd
*cmd
= sp
->cmd
;
2310 if (sp
->flags
& SRB_DMA_VALID
) {
2312 dma_unmap_sg(&ha
->pdev
->dev
, cmd
->request_buffer
,
2313 cmd
->use_sg
, cmd
->sc_data_direction
);
2314 } else if (cmd
->request_bufflen
) {
2315 dma_unmap_single(&ha
->pdev
->dev
, sp
->dma_handle
,
2316 cmd
->request_bufflen
, cmd
->sc_data_direction
);
2318 sp
->flags
&= ~SRB_DMA_VALID
;
2324 qla2x00_sp_compl(scsi_qla_host_t
*ha
, srb_t
*sp
)
2326 struct scsi_cmnd
*cmd
= sp
->cmd
;
2328 qla2x00_sp_free_dma(ha
, sp
);
2330 mempool_free(sp
, ha
->srb_mempool
);
2332 cmd
->scsi_done(cmd
);
2335 /**************************************************************************
2341 * Context: Interrupt
2342 ***************************************************************************/
2344 qla2x00_timer(scsi_qla_host_t
*ha
)
2346 unsigned long cpu_flags
= 0;
2354 * Ports - Port down timer.
2356 * Whenever, a port is in the LOST state we start decrementing its port
2357 * down timer every second until it reaches zero. Once it reaches zero
2358 * the port it marked DEAD.
2361 list_for_each_entry(fcport
, &ha
->fcports
, list
) {
2362 if (fcport
->port_type
!= FCT_TARGET
)
2365 if (atomic_read(&fcport
->state
) == FCS_DEVICE_LOST
) {
2367 if (atomic_read(&fcport
->port_down_timer
) == 0)
2370 if (atomic_dec_and_test(&fcport
->port_down_timer
) != 0)
2371 atomic_set(&fcport
->state
, FCS_DEVICE_DEAD
);
2373 DEBUG(printk("scsi(%ld): fcport-%d - port retry count: "
2376 t
, atomic_read(&fcport
->port_down_timer
)));
2379 } /* End of for fcport */
2382 /* Loop down handler. */
2383 if (atomic_read(&ha
->loop_down_timer
) > 0 &&
2384 !(test_bit(ABORT_ISP_ACTIVE
, &ha
->dpc_flags
)) && ha
->flags
.online
) {
2386 if (atomic_read(&ha
->loop_down_timer
) ==
2387 ha
->loop_down_abort_time
) {
2389 DEBUG(printk("scsi(%ld): Loop Down - aborting the "
2390 "queues before time expire\n",
2393 if (!IS_QLA2100(ha
) && ha
->link_down_timeout
)
2394 atomic_set(&ha
->loop_state
, LOOP_DEAD
);
2396 /* Schedule an ISP abort to return any tape commands. */
2397 spin_lock_irqsave(&ha
->hardware_lock
, cpu_flags
);
2398 for (index
= 1; index
< MAX_OUTSTANDING_COMMANDS
;
2402 sp
= ha
->outstanding_cmds
[index
];
2406 if (!(sfcp
->flags
& FCF_TAPE_PRESENT
))
2409 set_bit(ISP_ABORT_NEEDED
, &ha
->dpc_flags
);
2412 spin_unlock_irqrestore(&ha
->hardware_lock
, cpu_flags
);
2414 set_bit(ABORT_QUEUES_NEEDED
, &ha
->dpc_flags
);
2418 /* if the loop has been down for 4 minutes, reinit adapter */
2419 if (atomic_dec_and_test(&ha
->loop_down_timer
) != 0) {
2420 DEBUG(printk("scsi(%ld): Loop down exceed 4 mins - "
2421 "restarting queues.\n",
2424 set_bit(RESTART_QUEUES_NEEDED
, &ha
->dpc_flags
);
2427 if (!(ha
->device_flags
& DFLG_NO_CABLE
)) {
2428 DEBUG(printk("scsi(%ld): Loop down - "
2431 qla_printk(KERN_WARNING
, ha
,
2432 "Loop down - aborting ISP.\n");
2434 set_bit(ISP_ABORT_NEEDED
, &ha
->dpc_flags
);
2437 DEBUG3(printk("scsi(%ld): Loop Down - seconds remaining %d\n",
2439 atomic_read(&ha
->loop_down_timer
)));
2442 /* Schedule the DPC routine if needed */
2443 if ((test_bit(ISP_ABORT_NEEDED
, &ha
->dpc_flags
) ||
2444 test_bit(LOOP_RESYNC_NEEDED
, &ha
->dpc_flags
) ||
2446 test_bit(LOGIN_RETRY_NEEDED
, &ha
->dpc_flags
) ||
2447 test_bit(RESET_MARKER_NEEDED
, &ha
->dpc_flags
) ||
2448 test_bit(RELOGIN_NEEDED
, &ha
->dpc_flags
)) &&
2449 ha
->dpc_wait
&& !ha
->dpc_active
) {
2454 qla2x00_restart_timer(ha
, WATCH_INTERVAL
);
2457 /* XXX(hch): crude hack to emulate a down_timeout() */
2459 qla2x00_down_timeout(struct semaphore
*sema
, unsigned long timeout
)
2461 const unsigned int step
= 100; /* msecs */
2462 unsigned int iterations
= jiffies_to_msecs(timeout
)/100;
2465 if (!down_trylock(sema
))
2467 if (msleep_interruptible(step
))
2469 } while (--iterations
>= 0);
2474 static struct qla_board_info qla_board_tbl
[] = {
2476 .drv_name
= "qla2400",
2477 .isp_name
= "ISP2422",
2478 .fw_fname
= "ql2400_fw.bin",
2479 .sht
= &qla24xx_driver_template
,
2482 .drv_name
= "qla2400",
2483 .isp_name
= "ISP2432",
2484 .fw_fname
= "ql2400_fw.bin",
2485 .sht
= &qla24xx_driver_template
,
2489 static struct pci_device_id qla2xxx_pci_tbl
[] = {
2491 .vendor
= PCI_VENDOR_ID_QLOGIC
,
2492 .device
= PCI_DEVICE_ID_QLOGIC_ISP2422
,
2493 .subvendor
= PCI_ANY_ID
,
2494 .subdevice
= PCI_ANY_ID
,
2495 .driver_data
= (unsigned long)&qla_board_tbl
[0],
2498 .vendor
= PCI_VENDOR_ID_QLOGIC
,
2499 .device
= PCI_DEVICE_ID_QLOGIC_ISP2432
,
2500 .subvendor
= PCI_ANY_ID
,
2501 .subdevice
= PCI_ANY_ID
,
2502 .driver_data
= (unsigned long)&qla_board_tbl
[1],
2506 MODULE_DEVICE_TABLE(pci
, qla2xxx_pci_tbl
);
2508 static int __devinit
2509 qla2xxx_probe_one(struct pci_dev
*pdev
, const struct pci_device_id
*id
)
2511 return qla2x00_probe_one(pdev
,
2512 (struct qla_board_info
*)id
->driver_data
);
2515 static void __devexit
2516 qla2xxx_remove_one(struct pci_dev
*pdev
)
2518 qla2x00_remove_one(pdev
);
2521 static struct pci_driver qla2xxx_pci_driver
= {
2523 .id_table
= qla2xxx_pci_tbl
,
2524 .probe
= qla2xxx_probe_one
,
2525 .remove
= __devexit_p(qla2xxx_remove_one
),
2529 * qla2x00_module_init - Module initialization.
2532 qla2x00_module_init(void)
2536 /* Allocate cache for SRBs. */
2537 srb_cachep
= kmem_cache_create("qla2xxx_srbs", sizeof(srb_t
), 0,
2538 SLAB_HWCACHE_ALIGN
, NULL
, NULL
);
2539 if (srb_cachep
== NULL
) {
2541 "qla2xxx: Unable to allocate SRB cache...Failing load!\n");
2545 /* Derive version string. */
2546 strcpy(qla2x00_version_str
, QLA2XXX_VERSION
);
2548 strcat(qla2x00_version_str
, "-debug");
2550 qla2xxx_transport_template
=
2551 fc_attach_transport(&qla2xxx_transport_functions
);
2552 if (!qla2xxx_transport_template
)
2555 printk(KERN_INFO
"QLogic Fibre Channel HBA Driver\n");
2556 ret
= pci_module_init(&qla2xxx_pci_driver
);
2558 kmem_cache_destroy(srb_cachep
);
2559 fc_release_transport(qla2xxx_transport_template
);
2565 * qla2x00_module_exit - Module cleanup.
2568 qla2x00_module_exit(void)
2570 pci_unregister_driver(&qla2xxx_pci_driver
);
2571 kmem_cache_destroy(srb_cachep
);
2572 fc_release_transport(qla2xxx_transport_template
);
2575 module_init(qla2x00_module_init
);
2576 module_exit(qla2x00_module_exit
);
2578 MODULE_AUTHOR("QLogic Corporation");
2579 MODULE_DESCRIPTION("QLogic Fibre Channel HBA Driver");
2580 MODULE_LICENSE("GPL");
2581 MODULE_VERSION(QLA2XXX_VERSION
);