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.");
57 #if defined(CONFIG_SCSI_QLA2XXX_EMBEDDED_FIRMWARE)
59 module_param(ql2xfwloadflash
, int, S_IRUGO
|S_IRUSR
);
60 MODULE_PARM_DESC(ql2xfwloadflash
,
61 "Load ISP24xx firmware image from FLASH (onboard memory).");
64 static void qla2x00_free_device(scsi_qla_host_t
*);
66 static void qla2x00_config_dma_addressing(scsi_qla_host_t
*ha
);
69 module_param(ql2xfdmienable
, int, S_IRUGO
|S_IRUSR
);
70 MODULE_PARM_DESC(ql2xfdmienable
,
71 "Enables FDMI registratons "
72 "Default is 0 - no FDMI. 1 - perfom FDMI.");
75 * SCSI host template entry points
77 static int qla2xxx_slave_configure(struct scsi_device
* device
);
78 static int qla2xxx_slave_alloc(struct scsi_device
*);
79 static void qla2xxx_slave_destroy(struct scsi_device
*);
80 static int qla2x00_queuecommand(struct scsi_cmnd
*cmd
,
81 void (*fn
)(struct scsi_cmnd
*));
82 static int qla24xx_queuecommand(struct scsi_cmnd
*cmd
,
83 void (*fn
)(struct scsi_cmnd
*));
84 static int qla2xxx_eh_abort(struct scsi_cmnd
*);
85 static int qla2xxx_eh_device_reset(struct scsi_cmnd
*);
86 static int qla2xxx_eh_bus_reset(struct scsi_cmnd
*);
87 static int qla2xxx_eh_host_reset(struct scsi_cmnd
*);
88 static int qla2x00_loop_reset(scsi_qla_host_t
*ha
);
89 static int qla2x00_device_reset(scsi_qla_host_t
*, fc_port_t
*);
91 static int qla2x00_change_queue_depth(struct scsi_device
*, int);
92 static int qla2x00_change_queue_type(struct scsi_device
*, int);
94 static struct scsi_host_template qla2x00_driver_template
= {
95 .module
= THIS_MODULE
,
97 .queuecommand
= qla2x00_queuecommand
,
99 .eh_abort_handler
= qla2xxx_eh_abort
,
100 .eh_device_reset_handler
= qla2xxx_eh_device_reset
,
101 .eh_bus_reset_handler
= qla2xxx_eh_bus_reset
,
102 .eh_host_reset_handler
= qla2xxx_eh_host_reset
,
104 .slave_configure
= qla2xxx_slave_configure
,
106 .slave_alloc
= qla2xxx_slave_alloc
,
107 .slave_destroy
= qla2xxx_slave_destroy
,
108 .change_queue_depth
= qla2x00_change_queue_depth
,
109 .change_queue_type
= qla2x00_change_queue_type
,
112 .use_clustering
= ENABLE_CLUSTERING
,
113 .sg_tablesize
= SG_ALL
,
116 * The RISC allows for each command to transfer (2^32-1) bytes of data,
117 * which equates to 0x800000 sectors.
119 .max_sectors
= 0xFFFF,
120 .shost_attrs
= qla2x00_host_attrs
,
123 static struct scsi_host_template qla24xx_driver_template
= {
124 .module
= THIS_MODULE
,
126 .queuecommand
= qla24xx_queuecommand
,
128 .eh_abort_handler
= qla2xxx_eh_abort
,
129 .eh_device_reset_handler
= qla2xxx_eh_device_reset
,
130 .eh_bus_reset_handler
= qla2xxx_eh_bus_reset
,
131 .eh_host_reset_handler
= qla2xxx_eh_host_reset
,
133 .slave_configure
= qla2xxx_slave_configure
,
135 .slave_alloc
= qla2xxx_slave_alloc
,
136 .slave_destroy
= qla2xxx_slave_destroy
,
137 .change_queue_depth
= qla2x00_change_queue_depth
,
138 .change_queue_type
= qla2x00_change_queue_type
,
141 .use_clustering
= ENABLE_CLUSTERING
,
142 .sg_tablesize
= SG_ALL
,
144 .max_sectors
= 0xFFFF,
145 .shost_attrs
= qla2x00_host_attrs
,
148 static struct scsi_transport_template
*qla2xxx_transport_template
= NULL
;
150 /* TODO Convert to inlines
154 #define WATCH_INTERVAL 1 /* number of seconds */
156 static void qla2x00_timer(scsi_qla_host_t
*);
158 static __inline__
void qla2x00_start_timer(scsi_qla_host_t
*,
159 void *, unsigned long);
160 static __inline__
void qla2x00_restart_timer(scsi_qla_host_t
*, unsigned long);
161 static __inline__
void qla2x00_stop_timer(scsi_qla_host_t
*);
164 qla2x00_start_timer(scsi_qla_host_t
*ha
, void *func
, unsigned long interval
)
166 init_timer(&ha
->timer
);
167 ha
->timer
.expires
= jiffies
+ interval
* HZ
;
168 ha
->timer
.data
= (unsigned long)ha
;
169 ha
->timer
.function
= (void (*)(unsigned long))func
;
170 add_timer(&ha
->timer
);
171 ha
->timer_active
= 1;
175 qla2x00_restart_timer(scsi_qla_host_t
*ha
, unsigned long interval
)
177 mod_timer(&ha
->timer
, jiffies
+ interval
* HZ
);
180 static __inline__
void
181 qla2x00_stop_timer(scsi_qla_host_t
*ha
)
183 del_timer_sync(&ha
->timer
);
184 ha
->timer_active
= 0;
187 static int qla2x00_do_dpc(void *data
);
189 static void qla2x00_rst_aen(scsi_qla_host_t
*);
191 static uint8_t qla2x00_mem_alloc(scsi_qla_host_t
*);
192 static void qla2x00_mem_free(scsi_qla_host_t
*ha
);
193 static int qla2x00_allocate_sp_pool( scsi_qla_host_t
*ha
);
194 static void qla2x00_free_sp_pool(scsi_qla_host_t
*ha
);
195 static void qla2x00_sp_free_dma(scsi_qla_host_t
*, srb_t
*);
196 void qla2x00_sp_compl(scsi_qla_host_t
*ha
, srb_t
*);
198 /* -------------------------------------------------------------------------- */
201 qla2x00_pci_info_str(struct scsi_qla_host
*ha
, char *str
)
203 static char *pci_bus_modes
[] = {
204 "33", "66", "100", "133",
209 pci_bus
= (ha
->pci_attr
& (BIT_9
| BIT_10
)) >> 9;
212 strcat(str
, pci_bus_modes
[pci_bus
]);
214 pci_bus
= (ha
->pci_attr
& BIT_8
) >> 8;
216 strcat(str
, pci_bus_modes
[pci_bus
]);
218 strcat(str
, " MHz)");
224 qla24xx_pci_info_str(struct scsi_qla_host
*ha
, char *str
)
226 static char *pci_bus_modes
[] = { "33", "66", "100", "133", };
230 pcie_reg
= pci_find_capability(ha
->pdev
, PCI_CAP_ID_EXP
);
233 uint16_t pcie_lstat
, lspeed
, lwidth
;
236 pci_read_config_word(ha
->pdev
, pcie_reg
, &pcie_lstat
);
237 lspeed
= pcie_lstat
& (BIT_0
| BIT_1
| BIT_2
| BIT_3
);
238 lwidth
= (pcie_lstat
&
239 (BIT_4
| BIT_5
| BIT_6
| BIT_7
| BIT_8
| BIT_9
)) >> 4;
241 strcpy(str
, "PCIe (");
243 strcat(str
, "2.5Gb/s ");
245 strcat(str
, "<unknown> ");
246 snprintf(lwstr
, sizeof(lwstr
), "x%d)", lwidth
);
253 pci_bus
= (ha
->pci_attr
& CSRX_PCIX_BUS_MODE_MASK
) >> 8;
254 if (pci_bus
== 0 || pci_bus
== 8) {
256 strcat(str
, pci_bus_modes
[pci_bus
>> 3]);
260 strcat(str
, "Mode 2");
262 strcat(str
, "Mode 1");
264 strcat(str
, pci_bus_modes
[pci_bus
& ~BIT_2
]);
266 strcat(str
, " MHz)");
272 qla2x00_fw_version_str(struct scsi_qla_host
*ha
, char *str
)
276 sprintf(str
, "%d.%02d.%02d ", ha
->fw_major_version
,
277 ha
->fw_minor_version
,
278 ha
->fw_subminor_version
);
280 if (ha
->fw_attributes
& BIT_9
) {
285 switch (ha
->fw_attributes
& 0xFF) {
299 sprintf(un_str
, "(%x)", ha
->fw_attributes
);
303 if (ha
->fw_attributes
& 0x100)
310 qla24xx_fw_version_str(struct scsi_qla_host
*ha
, char *str
)
312 sprintf(str
, "%d.%02d.%02d ", ha
->fw_major_version
,
313 ha
->fw_minor_version
,
314 ha
->fw_subminor_version
);
316 if (ha
->fw_attributes
& BIT_0
)
317 strcat(str
, "[Class 2] ");
318 if (ha
->fw_attributes
& BIT_1
)
319 strcat(str
, "[IP] ");
320 if (ha
->fw_attributes
& BIT_2
)
321 strcat(str
, "[Multi-ID] ");
322 if (ha
->fw_attributes
& BIT_13
)
323 strcat(str
, "[Experimental]");
327 static inline srb_t
*
328 qla2x00_get_new_sp(scsi_qla_host_t
*ha
, fc_port_t
*fcport
,
329 struct scsi_cmnd
*cmd
, void (*done
)(struct scsi_cmnd
*))
333 sp
= mempool_alloc(ha
->srb_mempool
, GFP_ATOMIC
);
337 atomic_set(&sp
->ref_count
, 1);
342 CMD_SP(cmd
) = (void *)sp
;
343 cmd
->scsi_done
= done
;
349 qla2x00_queuecommand(struct scsi_cmnd
*cmd
, void (*done
)(struct scsi_cmnd
*))
351 scsi_qla_host_t
*ha
= to_qla_host(cmd
->device
->host
);
352 fc_port_t
*fcport
= (struct fc_port
*) cmd
->device
->hostdata
;
353 struct fc_rport
*rport
= starget_to_rport(scsi_target(cmd
->device
));
357 rval
= fc_remote_port_chkready(rport
);
360 goto qc_fail_command
;
363 if (atomic_read(&fcport
->state
) != FCS_ONLINE
) {
364 if (atomic_read(&fcport
->state
) == FCS_DEVICE_DEAD
||
365 atomic_read(&ha
->loop_state
) == LOOP_DEAD
) {
366 cmd
->result
= DID_NO_CONNECT
<< 16;
367 goto qc_fail_command
;
372 spin_unlock_irq(ha
->host
->host_lock
);
374 sp
= qla2x00_get_new_sp(ha
, fcport
, cmd
, done
);
376 goto qc_host_busy_lock
;
378 rval
= qla2x00_start_scsi(sp
);
379 if (rval
!= QLA_SUCCESS
)
380 goto qc_host_busy_free_sp
;
382 spin_lock_irq(ha
->host
->host_lock
);
386 qc_host_busy_free_sp
:
387 qla2x00_sp_free_dma(ha
, sp
);
388 mempool_free(sp
, ha
->srb_mempool
);
391 spin_lock_irq(ha
->host
->host_lock
);
394 return SCSI_MLQUEUE_HOST_BUSY
;
404 qla24xx_queuecommand(struct scsi_cmnd
*cmd
, void (*done
)(struct scsi_cmnd
*))
406 scsi_qla_host_t
*ha
= to_qla_host(cmd
->device
->host
);
407 fc_port_t
*fcport
= (struct fc_port
*) cmd
->device
->hostdata
;
408 struct fc_rport
*rport
= starget_to_rport(scsi_target(cmd
->device
));
412 rval
= fc_remote_port_chkready(rport
);
415 goto qc24_fail_command
;
418 if (atomic_read(&fcport
->state
) != FCS_ONLINE
) {
419 if (atomic_read(&fcport
->state
) == FCS_DEVICE_DEAD
||
420 atomic_read(&ha
->loop_state
) == LOOP_DEAD
) {
421 cmd
->result
= DID_NO_CONNECT
<< 16;
422 goto qc24_fail_command
;
427 spin_unlock_irq(ha
->host
->host_lock
);
429 sp
= qla2x00_get_new_sp(ha
, fcport
, cmd
, done
);
431 goto qc24_host_busy_lock
;
433 rval
= qla24xx_start_scsi(sp
);
434 if (rval
!= QLA_SUCCESS
)
435 goto qc24_host_busy_free_sp
;
437 spin_lock_irq(ha
->host
->host_lock
);
441 qc24_host_busy_free_sp
:
442 qla2x00_sp_free_dma(ha
, sp
);
443 mempool_free(sp
, ha
->srb_mempool
);
446 spin_lock_irq(ha
->host
->host_lock
);
449 return SCSI_MLQUEUE_HOST_BUSY
;
459 * qla2x00_eh_wait_on_command
460 * Waits for the command to be returned by the Firmware for some
464 * ha = actual ha whose done queue will contain the command
465 * returned by firmware.
466 * cmd = Scsi Command to wait on.
467 * flag = Abort/Reset(Bus or Device Reset)
474 qla2x00_eh_wait_on_command(scsi_qla_host_t
*ha
, struct scsi_cmnd
*cmd
)
476 #define ABORT_POLLING_PERIOD 1000
477 #define ABORT_WAIT_ITER ((10 * 1000) / (ABORT_POLLING_PERIOD))
478 unsigned long wait_iter
= ABORT_WAIT_ITER
;
479 int ret
= QLA_SUCCESS
;
481 while (CMD_SP(cmd
)) {
482 msleep(ABORT_POLLING_PERIOD
);
488 ret
= QLA_FUNCTION_FAILED
;
494 * qla2x00_wait_for_hba_online
495 * Wait till the HBA is online after going through
496 * <= MAX_RETRIES_OF_ISP_ABORT or
497 * finally HBA is disabled ie marked offline
500 * ha - pointer to host adapter structure
503 * Does context switching-Release SPIN_LOCK
504 * (if any) before calling this routine.
507 * Success (Adapter is online) : 0
508 * Failed (Adapter is offline/disabled) : 1
511 qla2x00_wait_for_hba_online(scsi_qla_host_t
*ha
)
514 unsigned long wait_online
;
516 wait_online
= jiffies
+ (MAX_LOOP_TIMEOUT
* HZ
);
517 while (((test_bit(ISP_ABORT_NEEDED
, &ha
->dpc_flags
)) ||
518 test_bit(ABORT_ISP_ACTIVE
, &ha
->dpc_flags
) ||
519 test_bit(ISP_ABORT_RETRY
, &ha
->dpc_flags
) ||
520 ha
->dpc_active
) && time_before(jiffies
, wait_online
)) {
524 if (ha
->flags
.online
)
525 return_status
= QLA_SUCCESS
;
527 return_status
= QLA_FUNCTION_FAILED
;
529 DEBUG2(printk("%s return_status=%d\n",__func__
,return_status
));
531 return (return_status
);
535 * qla2x00_wait_for_loop_ready
536 * Wait for MAX_LOOP_TIMEOUT(5 min) value for loop
537 * to be in LOOP_READY state.
539 * ha - pointer to host adapter structure
542 * Does context switching-Release SPIN_LOCK
543 * (if any) before calling this routine.
547 * Success (LOOP_READY) : 0
548 * Failed (LOOP_NOT_READY) : 1
551 qla2x00_wait_for_loop_ready(scsi_qla_host_t
*ha
)
553 int return_status
= QLA_SUCCESS
;
554 unsigned long loop_timeout
;
556 /* wait for 5 min at the max for loop to be ready */
557 loop_timeout
= jiffies
+ (MAX_LOOP_TIMEOUT
* HZ
);
559 while ((!atomic_read(&ha
->loop_down_timer
) &&
560 atomic_read(&ha
->loop_state
) == LOOP_DOWN
) ||
561 atomic_read(&ha
->loop_state
) != LOOP_READY
) {
563 if (time_after_eq(jiffies
, loop_timeout
)) {
564 return_status
= QLA_FUNCTION_FAILED
;
568 return (return_status
);
571 /**************************************************************************
575 * The abort function will abort the specified command.
578 * cmd = Linux SCSI command packet to be aborted.
581 * Either SUCCESS or FAILED.
584 **************************************************************************/
586 qla2xxx_eh_abort(struct scsi_cmnd
*cmd
)
588 scsi_qla_host_t
*ha
= to_qla_host(cmd
->device
->host
);
591 unsigned int id
, lun
;
592 unsigned long serial
;
600 id
= cmd
->device
->id
;
601 lun
= cmd
->device
->lun
;
602 serial
= cmd
->serial_number
;
604 /* Check active list for command command. */
605 spin_lock_irqsave(&ha
->hardware_lock
, flags
);
606 for (i
= 1; i
< MAX_OUTSTANDING_COMMANDS
; i
++) {
607 sp
= ha
->outstanding_cmds
[i
];
615 DEBUG2(printk("%s(%ld): aborting sp %p from RISC. pid=%ld "
616 "sp->state=%x\n", __func__
, ha
->host_no
, sp
, serial
,
618 DEBUG3(qla2x00_print_scsi_cmd(cmd
);)
620 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
621 if (ha
->isp_ops
.abort_command(ha
, sp
)) {
622 DEBUG2(printk("%s(%ld): abort_command "
623 "mbx failed.\n", __func__
, ha
->host_no
));
625 DEBUG3(printk("%s(%ld): abort_command "
626 "mbx success.\n", __func__
, ha
->host_no
));
629 spin_lock_irqsave(&ha
->hardware_lock
, flags
);
633 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
635 /* Wait for the command to be returned. */
636 if (ret
== SUCCESS
) {
637 if (qla2x00_eh_wait_on_command(ha
, cmd
) != QLA_SUCCESS
) {
638 qla_printk(KERN_ERR
, ha
,
639 "scsi(%ld:%d:%d): Abort handler timed out -- %lx "
640 "%x.\n", ha
->host_no
, id
, lun
, serial
, ret
);
644 qla_printk(KERN_INFO
, ha
,
645 "scsi(%ld:%d:%d): Abort command issued -- %lx %x.\n", ha
->host_no
,
646 id
, lun
, serial
, ret
);
651 /**************************************************************************
652 * qla2x00_eh_wait_for_pending_target_commands
655 * Waits for all the commands to come back from the specified target.
658 * ha - pointer to scsi_qla_host structure.
661 * Either SUCCESS or FAILED.
664 **************************************************************************/
666 qla2x00_eh_wait_for_pending_target_commands(scsi_qla_host_t
*ha
, unsigned int t
)
671 struct scsi_cmnd
*cmd
;
677 * Waiting for all commands for the designated target in the active
680 for (cnt
= 1; cnt
< MAX_OUTSTANDING_COMMANDS
; cnt
++) {
681 spin_lock_irqsave(&ha
->hardware_lock
, flags
);
682 sp
= ha
->outstanding_cmds
[cnt
];
685 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
686 if (cmd
->device
->id
== t
) {
687 if (!qla2x00_eh_wait_on_command(ha
, cmd
)) {
693 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
700 /**************************************************************************
701 * qla2xxx_eh_device_reset
704 * The device reset function will reset the target and abort any
705 * executing commands.
707 * NOTE: The use of SP is undefined within this context. Do *NOT*
708 * attempt to use this value, even if you determine it is
712 * cmd = Linux SCSI command packet of the command that cause the
716 * SUCCESS/FAILURE (defined as macro in scsi.h).
718 **************************************************************************/
720 qla2xxx_eh_device_reset(struct scsi_cmnd
*cmd
)
722 scsi_qla_host_t
*ha
= to_qla_host(cmd
->device
->host
);
723 fc_port_t
*fcport
= (struct fc_port
*) cmd
->device
->hostdata
;
726 unsigned int id
, lun
;
727 unsigned long serial
;
731 id
= cmd
->device
->id
;
732 lun
= cmd
->device
->lun
;
733 serial
= cmd
->serial_number
;
735 sp
= (srb_t
*) CMD_SP(cmd
);
739 qla_printk(KERN_INFO
, ha
,
740 "scsi(%ld:%d:%d): DEVICE RESET ISSUED.\n", ha
->host_no
, id
, lun
);
742 if (qla2x00_wait_for_hba_online(ha
) != QLA_SUCCESS
)
743 goto eh_dev_reset_done
;
745 if (qla2x00_wait_for_loop_ready(ha
) == QLA_SUCCESS
) {
746 if (qla2x00_device_reset(ha
, fcport
) == 0)
749 #if defined(LOGOUT_AFTER_DEVICE_RESET)
750 if (ret
== SUCCESS
) {
751 if (fcport
->flags
& FC_FABRIC_DEVICE
) {
752 ha
->isp_ops
.fabric_logout(ha
, fcport
->loop_id
);
753 qla2x00_mark_device_lost(ha
, fcport
);
758 DEBUG2(printk(KERN_INFO
759 "%s failed: loop not ready\n",__func__
);)
763 DEBUG3(printk("%s(%ld): device reset failed\n",
764 __func__
, ha
->host_no
));
765 qla_printk(KERN_INFO
, ha
, "%s: device reset failed\n",
768 goto eh_dev_reset_done
;
771 /* Flush outstanding commands. */
772 if (qla2x00_eh_wait_for_pending_target_commands(ha
, id
))
775 DEBUG3(printk("%s(%ld): failed while waiting for commands\n",
776 __func__
, ha
->host_no
));
777 qla_printk(KERN_INFO
, ha
,
778 "%s: failed while waiting for commands\n", __func__
);
780 qla_printk(KERN_INFO
, ha
,
781 "scsi(%ld:%d:%d): DEVICE RESET SUCCEEDED.\n", ha
->host_no
,
787 /**************************************************************************
788 * qla2x00_eh_wait_for_pending_commands
791 * Waits for all the commands to come back from the specified host.
794 * ha - pointer to scsi_qla_host structure.
801 **************************************************************************/
803 qla2x00_eh_wait_for_pending_commands(scsi_qla_host_t
*ha
)
808 struct scsi_cmnd
*cmd
;
814 * Waiting for all commands for the designated target in the active
817 for (cnt
= 1; cnt
< MAX_OUTSTANDING_COMMANDS
; cnt
++) {
818 spin_lock_irqsave(&ha
->hardware_lock
, flags
);
819 sp
= ha
->outstanding_cmds
[cnt
];
822 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
823 status
= qla2x00_eh_wait_on_command(ha
, cmd
);
828 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
835 /**************************************************************************
836 * qla2xxx_eh_bus_reset
839 * The bus reset function will reset the bus and abort any executing
843 * cmd = Linux SCSI command packet of the command that cause the
847 * SUCCESS/FAILURE (defined as macro in scsi.h).
849 **************************************************************************/
851 qla2xxx_eh_bus_reset(struct scsi_cmnd
*cmd
)
853 scsi_qla_host_t
*ha
= to_qla_host(cmd
->device
->host
);
854 fc_port_t
*fcport
= (struct fc_port
*) cmd
->device
->hostdata
;
857 unsigned int id
, lun
;
858 unsigned long serial
;
862 id
= cmd
->device
->id
;
863 lun
= cmd
->device
->lun
;
864 serial
= cmd
->serial_number
;
866 sp
= (srb_t
*) CMD_SP(cmd
);
870 qla_printk(KERN_INFO
, ha
,
871 "scsi(%ld:%d:%d): LOOP RESET ISSUED.\n", ha
->host_no
, id
, lun
);
873 if (qla2x00_wait_for_hba_online(ha
) != QLA_SUCCESS
) {
874 DEBUG2(printk("%s failed:board disabled\n",__func__
));
875 goto eh_bus_reset_done
;
878 if (qla2x00_wait_for_loop_ready(ha
) == QLA_SUCCESS
) {
879 if (qla2x00_loop_reset(ha
) == QLA_SUCCESS
)
883 goto eh_bus_reset_done
;
885 /* Flush outstanding commands. */
886 if (!qla2x00_eh_wait_for_pending_commands(ha
))
890 qla_printk(KERN_INFO
, ha
, "%s: reset %s\n", __func__
,
891 (ret
== FAILED
) ? "failed" : "succeded");
896 /**************************************************************************
897 * qla2xxx_eh_host_reset
900 * The reset function will reset the Adapter.
903 * cmd = Linux SCSI command packet of the command that cause the
907 * Either SUCCESS or FAILED.
910 **************************************************************************/
912 qla2xxx_eh_host_reset(struct scsi_cmnd
*cmd
)
914 scsi_qla_host_t
*ha
= to_qla_host(cmd
->device
->host
);
915 fc_port_t
*fcport
= (struct fc_port
*) cmd
->device
->hostdata
;
918 unsigned int id
, lun
;
919 unsigned long serial
;
923 id
= cmd
->device
->id
;
924 lun
= cmd
->device
->lun
;
925 serial
= cmd
->serial_number
;
927 sp
= (srb_t
*) CMD_SP(cmd
);
931 qla_printk(KERN_INFO
, ha
,
932 "scsi(%ld:%d:%d): ADAPTER RESET ISSUED.\n", ha
->host_no
, id
, lun
);
934 if (qla2x00_wait_for_hba_online(ha
) != QLA_SUCCESS
)
935 goto eh_host_reset_lock
;
938 * Fixme-may be dpc thread is active and processing
939 * loop_resync,so wait a while for it to
940 * be completed and then issue big hammer.Otherwise
941 * it may cause I/O failure as big hammer marks the
942 * devices as lost kicking of the port_down_timer
943 * while dpc is stuck for the mailbox to complete.
945 qla2x00_wait_for_loop_ready(ha
);
946 set_bit(ABORT_ISP_ACTIVE
, &ha
->dpc_flags
);
947 if (qla2x00_abort_isp(ha
)) {
948 clear_bit(ABORT_ISP_ACTIVE
, &ha
->dpc_flags
);
949 /* failed. schedule dpc to try */
950 set_bit(ISP_ABORT_NEEDED
, &ha
->dpc_flags
);
952 if (qla2x00_wait_for_hba_online(ha
) != QLA_SUCCESS
)
953 goto eh_host_reset_lock
;
955 clear_bit(ABORT_ISP_ACTIVE
, &ha
->dpc_flags
);
957 /* Waiting for our command in done_queue to be returned to OS.*/
958 if (qla2x00_eh_wait_for_pending_commands(ha
))
962 qla_printk(KERN_INFO
, ha
, "%s: reset %s\n", __func__
,
963 (ret
== FAILED
) ? "failed" : "succeded");
973 * ha = adapter block pointer.
979 qla2x00_loop_reset(scsi_qla_host_t
*ha
)
981 int status
= QLA_SUCCESS
;
982 struct fc_port
*fcport
;
984 if (ha
->flags
.enable_lip_reset
) {
985 status
= qla2x00_lip_reset(ha
);
988 if (status
== QLA_SUCCESS
&& ha
->flags
.enable_target_reset
) {
989 list_for_each_entry(fcport
, &ha
->fcports
, list
) {
990 if (fcport
->port_type
!= FCT_TARGET
)
993 status
= qla2x00_device_reset(ha
, fcport
);
994 if (status
!= QLA_SUCCESS
)
999 if (status
== QLA_SUCCESS
&&
1000 ((!ha
->flags
.enable_target_reset
&&
1001 !ha
->flags
.enable_lip_reset
) ||
1002 ha
->flags
.enable_lip_full_login
)) {
1004 status
= qla2x00_full_login_lip(ha
);
1007 /* Issue marker command only when we are going to start the I/O */
1008 ha
->marker_needed
= 1;
1012 DEBUG2_3(printk("%s(%ld): **** FAILED ****\n",
1017 DEBUG3(printk("%s(%ld): exiting normally.\n",
1026 * qla2x00_device_reset
1027 * Issue bus device reset message to the target.
1030 * ha = adapter block pointer.
1032 * TARGET_QUEUE_LOCK must be released.
1033 * ADAPTER_STATE_LOCK must be released.
1039 qla2x00_device_reset(scsi_qla_host_t
*ha
, fc_port_t
*reset_fcport
)
1041 /* Abort Target command will clear Reservation */
1042 return ha
->isp_ops
.abort_target(reset_fcport
);
1046 qla2xxx_slave_alloc(struct scsi_device
*sdev
)
1048 struct fc_rport
*rport
= starget_to_rport(scsi_target(sdev
));
1050 if (!rport
|| fc_remote_port_chkready(rport
))
1053 sdev
->hostdata
= *(fc_port_t
**)rport
->dd_data
;
1059 qla2xxx_slave_configure(struct scsi_device
*sdev
)
1061 scsi_qla_host_t
*ha
= to_qla_host(sdev
->host
);
1062 struct fc_rport
*rport
= starget_to_rport(sdev
->sdev_target
);
1064 if (sdev
->tagged_supported
)
1065 scsi_activate_tcq(sdev
, 32);
1067 scsi_deactivate_tcq(sdev
, 32);
1069 rport
->dev_loss_tmo
= ha
->port_down_retry_count
+ 5;
1075 qla2xxx_slave_destroy(struct scsi_device
*sdev
)
1077 sdev
->hostdata
= NULL
;
1081 qla2x00_change_queue_depth(struct scsi_device
*sdev
, int qdepth
)
1083 scsi_adjust_queue_depth(sdev
, scsi_get_tag_type(sdev
), qdepth
);
1084 return sdev
->queue_depth
;
1088 qla2x00_change_queue_type(struct scsi_device
*sdev
, int tag_type
)
1090 if (sdev
->tagged_supported
) {
1091 scsi_set_tag_type(sdev
, tag_type
);
1093 scsi_activate_tcq(sdev
, sdev
->queue_depth
);
1095 scsi_deactivate_tcq(sdev
, sdev
->queue_depth
);
1103 * qla2x00_config_dma_addressing() - Configure OS DMA addressing method.
1106 * At exit, the @ha's flags.enable_64bit_addressing set to indicated
1107 * supported addressing method.
1110 qla2x00_config_dma_addressing(scsi_qla_host_t
*ha
)
1112 /* Assume a 32bit DMA mask. */
1113 ha
->flags
.enable_64bit_addressing
= 0;
1115 if (!dma_set_mask(&ha
->pdev
->dev
, DMA_64BIT_MASK
)) {
1116 /* Any upper-dword bits set? */
1117 if (MSD(dma_get_required_mask(&ha
->pdev
->dev
)) &&
1118 !pci_set_consistent_dma_mask(ha
->pdev
, DMA_64BIT_MASK
)) {
1119 /* Ok, a 64bit DMA mask is applicable. */
1120 ha
->flags
.enable_64bit_addressing
= 1;
1121 ha
->isp_ops
.calc_req_entries
= qla2x00_calc_iocbs_64
;
1122 ha
->isp_ops
.build_iocbs
= qla2x00_build_scsi_iocbs_64
;
1127 dma_set_mask(&ha
->pdev
->dev
, DMA_32BIT_MASK
);
1128 pci_set_consistent_dma_mask(ha
->pdev
, DMA_32BIT_MASK
);
1132 qla2x00_iospace_config(scsi_qla_host_t
*ha
)
1134 unsigned long pio
, pio_len
, pio_flags
;
1135 unsigned long mmio
, mmio_len
, mmio_flags
;
1137 /* We only need PIO for Flash operations on ISP2312 v2 chips. */
1138 pio
= pci_resource_start(ha
->pdev
, 0);
1139 pio_len
= pci_resource_len(ha
->pdev
, 0);
1140 pio_flags
= pci_resource_flags(ha
->pdev
, 0);
1141 if (pio_flags
& IORESOURCE_IO
) {
1142 if (pio_len
< MIN_IOBASE_LEN
) {
1143 qla_printk(KERN_WARNING
, ha
,
1144 "Invalid PCI I/O region size (%s)...\n",
1145 pci_name(ha
->pdev
));
1149 qla_printk(KERN_WARNING
, ha
,
1150 "region #0 not a PIO resource (%s)...\n",
1151 pci_name(ha
->pdev
));
1155 /* Use MMIO operations for all accesses. */
1156 mmio
= pci_resource_start(ha
->pdev
, 1);
1157 mmio_len
= pci_resource_len(ha
->pdev
, 1);
1158 mmio_flags
= pci_resource_flags(ha
->pdev
, 1);
1160 if (!(mmio_flags
& IORESOURCE_MEM
)) {
1161 qla_printk(KERN_ERR
, ha
,
1162 "region #0 not an MMIO resource (%s), aborting\n",
1163 pci_name(ha
->pdev
));
1164 goto iospace_error_exit
;
1166 if (mmio_len
< MIN_IOBASE_LEN
) {
1167 qla_printk(KERN_ERR
, ha
,
1168 "Invalid PCI mem region size (%s), aborting\n",
1169 pci_name(ha
->pdev
));
1170 goto iospace_error_exit
;
1173 if (pci_request_regions(ha
->pdev
, ha
->brd_info
->drv_name
)) {
1174 qla_printk(KERN_WARNING
, ha
,
1175 "Failed to reserve PIO/MMIO regions (%s)\n",
1176 pci_name(ha
->pdev
));
1178 goto iospace_error_exit
;
1181 ha
->pio_address
= pio
;
1182 ha
->pio_length
= pio_len
;
1183 ha
->iobase
= ioremap(mmio
, MIN_IOBASE_LEN
);
1185 qla_printk(KERN_ERR
, ha
,
1186 "cannot remap MMIO (%s), aborting\n", pci_name(ha
->pdev
));
1188 goto iospace_error_exit
;
1198 qla2x00_enable_intrs(scsi_qla_host_t
*ha
)
1200 unsigned long flags
= 0;
1201 struct device_reg_2xxx __iomem
*reg
= &ha
->iobase
->isp
;
1203 spin_lock_irqsave(&ha
->hardware_lock
, flags
);
1204 ha
->interrupts_on
= 1;
1205 /* enable risc and host interrupts */
1206 WRT_REG_WORD(®
->ictrl
, ICR_EN_INT
| ICR_EN_RISC
);
1207 RD_REG_WORD(®
->ictrl
);
1208 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
1213 qla2x00_disable_intrs(scsi_qla_host_t
*ha
)
1215 unsigned long flags
= 0;
1216 struct device_reg_2xxx __iomem
*reg
= &ha
->iobase
->isp
;
1218 spin_lock_irqsave(&ha
->hardware_lock
, flags
);
1219 ha
->interrupts_on
= 0;
1220 /* disable risc and host interrupts */
1221 WRT_REG_WORD(®
->ictrl
, 0);
1222 RD_REG_WORD(®
->ictrl
);
1223 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
1227 qla24xx_enable_intrs(scsi_qla_host_t
*ha
)
1229 unsigned long flags
= 0;
1230 struct device_reg_24xx __iomem
*reg
= &ha
->iobase
->isp24
;
1232 spin_lock_irqsave(&ha
->hardware_lock
, flags
);
1233 ha
->interrupts_on
= 1;
1234 WRT_REG_DWORD(®
->ictrl
, ICRX_EN_RISC_INT
);
1235 RD_REG_DWORD(®
->ictrl
);
1236 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
1240 qla24xx_disable_intrs(scsi_qla_host_t
*ha
)
1242 unsigned long flags
= 0;
1243 struct device_reg_24xx __iomem
*reg
= &ha
->iobase
->isp24
;
1245 spin_lock_irqsave(&ha
->hardware_lock
, flags
);
1246 ha
->interrupts_on
= 0;
1247 WRT_REG_DWORD(®
->ictrl
, 0);
1248 RD_REG_DWORD(®
->ictrl
);
1249 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
1253 * PCI driver interface
1255 int qla2x00_probe_one(struct pci_dev
*pdev
, struct qla_board_info
*brd_info
)
1258 device_reg_t __iomem
*reg
;
1259 struct Scsi_Host
*host
;
1260 scsi_qla_host_t
*ha
;
1261 unsigned long flags
= 0;
1262 unsigned long wait_switch
= 0;
1266 struct scsi_host_template
*sht
;
1268 if (pci_enable_device(pdev
))
1271 sht
= &qla2x00_driver_template
;
1272 if (pdev
->device
== PCI_DEVICE_ID_QLOGIC_ISP2422
||
1273 pdev
->device
== PCI_DEVICE_ID_QLOGIC_ISP2432
)
1274 sht
= &qla24xx_driver_template
;
1275 host
= scsi_host_alloc(sht
, sizeof(scsi_qla_host_t
));
1278 "qla2xxx: Couldn't allocate host from scsi layer!\n");
1279 goto probe_disable_device
;
1282 /* Clear our data area */
1283 ha
= (scsi_qla_host_t
*)host
->hostdata
;
1284 memset(ha
, 0, sizeof(scsi_qla_host_t
));
1288 ha
->host_no
= host
->host_no
;
1289 ha
->brd_info
= brd_info
;
1290 sprintf(ha
->host_str
, "%s_%ld", ha
->brd_info
->drv_name
, ha
->host_no
);
1294 /* Configure PCI I/O space */
1295 ret
= qla2x00_iospace_config(ha
);
1299 qla_printk(KERN_INFO
, ha
,
1300 "Found an ISP%04X, irq %d, iobase 0x%p\n", pdev
->device
, pdev
->irq
,
1303 spin_lock_init(&ha
->hardware_lock
);
1305 ha
->prev_topology
= 0;
1306 ha
->ports
= MAX_BUSES
;
1307 ha
->init_cb_size
= sizeof(init_cb_t
);
1308 ha
->mgmt_svr_loop_id
= MANAGEMENT_SERVER
;
1310 /* Assign ISP specific operations. */
1311 ha
->isp_ops
.pci_config
= qla2100_pci_config
;
1312 ha
->isp_ops
.reset_chip
= qla2x00_reset_chip
;
1313 ha
->isp_ops
.chip_diag
= qla2x00_chip_diag
;
1314 ha
->isp_ops
.config_rings
= qla2x00_config_rings
;
1315 ha
->isp_ops
.reset_adapter
= qla2x00_reset_adapter
;
1316 ha
->isp_ops
.nvram_config
= qla2x00_nvram_config
;
1317 ha
->isp_ops
.update_fw_options
= qla2x00_update_fw_options
;
1318 ha
->isp_ops
.load_risc
= qla2x00_load_risc
;
1319 ha
->isp_ops
.pci_info_str
= qla2x00_pci_info_str
;
1320 ha
->isp_ops
.fw_version_str
= qla2x00_fw_version_str
;
1321 ha
->isp_ops
.intr_handler
= qla2100_intr_handler
;
1322 ha
->isp_ops
.enable_intrs
= qla2x00_enable_intrs
;
1323 ha
->isp_ops
.disable_intrs
= qla2x00_disable_intrs
;
1324 ha
->isp_ops
.abort_command
= qla2x00_abort_command
;
1325 ha
->isp_ops
.abort_target
= qla2x00_abort_target
;
1326 ha
->isp_ops
.fabric_login
= qla2x00_login_fabric
;
1327 ha
->isp_ops
.fabric_logout
= qla2x00_fabric_logout
;
1328 ha
->isp_ops
.calc_req_entries
= qla2x00_calc_iocbs_32
;
1329 ha
->isp_ops
.build_iocbs
= qla2x00_build_scsi_iocbs_32
;
1330 ha
->isp_ops
.prep_ms_iocb
= qla2x00_prep_ms_iocb
;
1331 ha
->isp_ops
.prep_ms_fdmi_iocb
= qla2x00_prep_ms_fdmi_iocb
;
1332 ha
->isp_ops
.read_nvram
= qla2x00_read_nvram_data
;
1333 ha
->isp_ops
.write_nvram
= qla2x00_write_nvram_data
;
1334 ha
->isp_ops
.fw_dump
= qla2100_fw_dump
;
1335 ha
->isp_ops
.ascii_fw_dump
= qla2100_ascii_fw_dump
;
1336 if (IS_QLA2100(ha
)) {
1337 host
->max_id
= MAX_TARGETS_2100
;
1338 ha
->mbx_count
= MAILBOX_REGISTER_COUNT_2100
;
1339 ha
->request_q_length
= REQUEST_ENTRY_CNT_2100
;
1340 ha
->response_q_length
= RESPONSE_ENTRY_CNT_2100
;
1341 ha
->last_loop_id
= SNS_LAST_LOOP_ID_2100
;
1342 host
->sg_tablesize
= 32;
1343 ha
->gid_list_info_size
= 4;
1344 } else if (IS_QLA2200(ha
)) {
1345 host
->max_id
= MAX_TARGETS_2200
;
1346 ha
->mbx_count
= MAILBOX_REGISTER_COUNT
;
1347 ha
->request_q_length
= REQUEST_ENTRY_CNT_2200
;
1348 ha
->response_q_length
= RESPONSE_ENTRY_CNT_2100
;
1349 ha
->last_loop_id
= SNS_LAST_LOOP_ID_2100
;
1350 ha
->gid_list_info_size
= 4;
1351 } else if (IS_QLA23XX(ha
)) {
1352 host
->max_id
= MAX_TARGETS_2200
;
1353 ha
->mbx_count
= MAILBOX_REGISTER_COUNT
;
1354 ha
->request_q_length
= REQUEST_ENTRY_CNT_2200
;
1355 ha
->response_q_length
= RESPONSE_ENTRY_CNT_2300
;
1356 ha
->last_loop_id
= SNS_LAST_LOOP_ID_2300
;
1357 ha
->isp_ops
.pci_config
= qla2300_pci_config
;
1358 ha
->isp_ops
.intr_handler
= qla2300_intr_handler
;
1359 ha
->isp_ops
.fw_dump
= qla2300_fw_dump
;
1360 ha
->isp_ops
.ascii_fw_dump
= qla2300_ascii_fw_dump
;
1361 ha
->gid_list_info_size
= 6;
1362 } else if (IS_QLA24XX(ha
) || IS_QLA25XX(ha
)) {
1363 host
->max_id
= MAX_TARGETS_2200
;
1364 ha
->mbx_count
= MAILBOX_REGISTER_COUNT
;
1365 ha
->request_q_length
= REQUEST_ENTRY_CNT_24XX
;
1366 ha
->response_q_length
= RESPONSE_ENTRY_CNT_2300
;
1367 ha
->last_loop_id
= SNS_LAST_LOOP_ID_2300
;
1368 ha
->init_cb_size
= sizeof(struct init_cb_24xx
);
1369 ha
->mgmt_svr_loop_id
= 10;
1370 ha
->isp_ops
.pci_config
= qla24xx_pci_config
;
1371 ha
->isp_ops
.reset_chip
= qla24xx_reset_chip
;
1372 ha
->isp_ops
.chip_diag
= qla24xx_chip_diag
;
1373 ha
->isp_ops
.config_rings
= qla24xx_config_rings
;
1374 ha
->isp_ops
.reset_adapter
= qla24xx_reset_adapter
;
1375 ha
->isp_ops
.nvram_config
= qla24xx_nvram_config
;
1376 ha
->isp_ops
.update_fw_options
= qla24xx_update_fw_options
;
1377 ha
->isp_ops
.load_risc
= qla24xx_load_risc
;
1378 #if defined(CONFIG_SCSI_QLA2XXX_EMBEDDED_FIRMWARE)
1379 if (ql2xfwloadflash
)
1380 ha
->isp_ops
.load_risc
= qla24xx_load_risc_flash
;
1382 ha
->isp_ops
.pci_info_str
= qla24xx_pci_info_str
;
1383 ha
->isp_ops
.fw_version_str
= qla24xx_fw_version_str
;
1384 ha
->isp_ops
.intr_handler
= qla24xx_intr_handler
;
1385 ha
->isp_ops
.enable_intrs
= qla24xx_enable_intrs
;
1386 ha
->isp_ops
.disable_intrs
= qla24xx_disable_intrs
;
1387 ha
->isp_ops
.abort_command
= qla24xx_abort_command
;
1388 ha
->isp_ops
.abort_target
= qla24xx_abort_target
;
1389 ha
->isp_ops
.fabric_login
= qla24xx_login_fabric
;
1390 ha
->isp_ops
.fabric_logout
= qla24xx_fabric_logout
;
1391 ha
->isp_ops
.prep_ms_iocb
= qla24xx_prep_ms_iocb
;
1392 ha
->isp_ops
.prep_ms_fdmi_iocb
= qla24xx_prep_ms_fdmi_iocb
;
1393 ha
->isp_ops
.read_nvram
= qla24xx_read_nvram_data
;
1394 ha
->isp_ops
.write_nvram
= qla24xx_write_nvram_data
;
1395 ha
->isp_ops
.fw_dump
= qla24xx_fw_dump
;
1396 ha
->isp_ops
.ascii_fw_dump
= qla24xx_ascii_fw_dump
;
1397 ha
->gid_list_info_size
= 8;
1399 host
->can_queue
= ha
->request_q_length
+ 128;
1401 /* load the F/W, read paramaters, and init the H/W */
1402 ha
->instance
= num_hosts
;
1404 init_MUTEX(&ha
->mbx_cmd_sem
);
1405 init_MUTEX_LOCKED(&ha
->mbx_intr_sem
);
1407 INIT_LIST_HEAD(&ha
->list
);
1408 INIT_LIST_HEAD(&ha
->fcports
);
1409 INIT_LIST_HEAD(&ha
->rscn_fcports
);
1412 * These locks are used to prevent more than one CPU
1413 * from modifying the queue at the same time. The
1414 * higher level "host_lock" will reduce most
1415 * contention for these locks.
1417 spin_lock_init(&ha
->mbx_reg_lock
);
1419 init_completion(&ha
->dpc_inited
);
1420 init_completion(&ha
->dpc_exited
);
1422 qla2x00_config_dma_addressing(ha
);
1423 if (qla2x00_mem_alloc(ha
)) {
1424 qla_printk(KERN_WARNING
, ha
,
1425 "[ERROR] Failed to allocate memory for adapter\n");
1431 if (qla2x00_initialize_adapter(ha
) &&
1432 !(ha
->device_flags
& DFLG_NO_CABLE
)) {
1434 qla_printk(KERN_WARNING
, ha
,
1435 "Failed to initialize adapter\n");
1437 DEBUG2(printk("scsi(%ld): Failed to initialize adapter - "
1438 "Adapter flags %x.\n",
1439 ha
->host_no
, ha
->device_flags
));
1446 * Startup the kernel thread for this host adapter
1448 ha
->dpc_should_die
= 0;
1449 ha
->dpc_pid
= kernel_thread(qla2x00_do_dpc
, ha
, 0);
1450 if (ha
->dpc_pid
< 0) {
1451 qla_printk(KERN_WARNING
, ha
,
1452 "Unable to start DPC thread!\n");
1457 wait_for_completion(&ha
->dpc_inited
);
1459 host
->this_id
= 255;
1460 host
->cmd_per_lun
= 3;
1461 host
->unique_id
= ha
->instance
;
1462 host
->max_cmd_len
= MAX_CMDSZ
;
1463 host
->max_channel
= ha
->ports
- 1;
1464 host
->max_lun
= MAX_LUNS
;
1465 host
->transportt
= qla2xxx_transport_template
;
1467 ret
= request_irq(pdev
->irq
, ha
->isp_ops
.intr_handler
,
1468 SA_INTERRUPT
|SA_SHIRQ
, ha
->brd_info
->drv_name
, ha
);
1470 qla_printk(KERN_WARNING
, ha
,
1471 "Failed to reserve interrupt %d already in use.\n",
1475 host
->irq
= pdev
->irq
;
1477 /* Initialized the timer */
1478 qla2x00_start_timer(ha
, qla2x00_timer
, WATCH_INTERVAL
);
1480 DEBUG2(printk("DEBUG: detect hba %ld at address = %p\n",
1483 ha
->isp_ops
.disable_intrs(ha
);
1485 spin_lock_irqsave(&ha
->hardware_lock
, flags
);
1487 if (IS_QLA24XX(ha
) || IS_QLA25XX(ha
)) {
1488 WRT_REG_DWORD(®
->isp24
.hccr
, HCCRX_CLR_HOST_INT
);
1489 WRT_REG_DWORD(®
->isp24
.hccr
, HCCRX_CLR_RISC_INT
);
1491 WRT_REG_WORD(®
->isp
.semaphore
, 0);
1492 WRT_REG_WORD(®
->isp
.hccr
, HCCR_CLR_RISC_INT
);
1493 WRT_REG_WORD(®
->isp
.hccr
, HCCR_CLR_HOST_INT
);
1495 /* Enable proper parity */
1496 if (!IS_QLA2100(ha
) && !IS_QLA2200(ha
)) {
1499 WRT_REG_WORD(®
->isp
.hccr
,
1500 (HCCR_ENABLE_PARITY
+ 0x1));
1502 /* SRAM, Instruction RAM and GP RAM parity */
1503 WRT_REG_WORD(®
->isp
.hccr
,
1504 (HCCR_ENABLE_PARITY
+ 0x7));
1507 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
1509 ha
->isp_ops
.enable_intrs(ha
);
1513 * Wait around max loop_reset_delay secs for the devices to come
1514 * on-line. We don't want Linux scanning before we are ready.
1517 for (wait_switch
= jiffies
+ (ha
->loop_reset_delay
* HZ
);
1518 time_before(jiffies
,wait_switch
) &&
1519 !(ha
->device_flags
& (DFLG_NO_CABLE
| DFLG_FABRIC_DEVICES
))
1520 && (ha
->device_flags
& SWITCH_FOUND
) ;) {
1522 qla2x00_check_fabric_devices(ha
);
1527 pci_set_drvdata(pdev
, ha
);
1528 ha
->flags
.init_done
= 1;
1531 ret
= scsi_add_host(host
, &pdev
->dev
);
1535 qla2x00_alloc_sysfs_attr(ha
);
1537 qla2x00_init_host_attr(ha
);
1539 qla_printk(KERN_INFO
, ha
, "\n"
1540 " QLogic Fibre Channel HBA Driver: %s\n"
1542 " ISP%04X: %s @ %s hdma%c, host#=%ld, fw=%s\n",
1543 qla2x00_version_str
, ha
->model_number
,
1544 ha
->model_desc
? ha
->model_desc
: "", pdev
->device
,
1545 ha
->isp_ops
.pci_info_str(ha
, pci_info
), pci_name(pdev
),
1546 ha
->flags
.enable_64bit_addressing
? '+': '-', ha
->host_no
,
1547 ha
->isp_ops
.fw_version_str(ha
, fw_str
));
1549 /* Go with fc_rport registration. */
1550 list_for_each_entry(fcport
, &ha
->fcports
, list
)
1551 qla2x00_reg_remote_port(ha
, fcport
);
1556 qla2x00_free_device(ha
);
1558 scsi_host_put(host
);
1560 probe_disable_device
:
1561 pci_disable_device(pdev
);
1566 EXPORT_SYMBOL_GPL(qla2x00_probe_one
);
1568 void qla2x00_remove_one(struct pci_dev
*pdev
)
1570 scsi_qla_host_t
*ha
;
1572 ha
= pci_get_drvdata(pdev
);
1574 qla2x00_free_sysfs_attr(ha
);
1576 fc_remove_host(ha
->host
);
1578 scsi_remove_host(ha
->host
);
1580 qla2x00_free_device(ha
);
1582 scsi_host_put(ha
->host
);
1584 pci_set_drvdata(pdev
, NULL
);
1586 EXPORT_SYMBOL_GPL(qla2x00_remove_one
);
1589 qla2x00_free_device(scsi_qla_host_t
*ha
)
1593 /* Abort any outstanding IO descriptors. */
1594 if (!IS_QLA2100(ha
) && !IS_QLA2200(ha
))
1595 qla2x00_cancel_io_descriptors(ha
);
1598 if (ha
->timer_active
)
1599 qla2x00_stop_timer(ha
);
1601 /* Kill the kernel thread for this host */
1602 if (ha
->dpc_pid
>= 0) {
1603 ha
->dpc_should_die
= 1;
1605 ret
= kill_proc(ha
->dpc_pid
, SIGHUP
, 1);
1607 qla_printk(KERN_ERR
, ha
,
1608 "Unable to signal DPC thread -- (%d)\n", ret
);
1610 /* TODO: SOMETHING MORE??? */
1612 wait_for_completion(&ha
->dpc_exited
);
1616 /* Stop currently executing firmware. */
1617 qla2x00_stop_firmware(ha
);
1619 /* turn-off interrupts on the card */
1620 if (ha
->interrupts_on
)
1621 ha
->isp_ops
.disable_intrs(ha
);
1623 qla2x00_mem_free(ha
);
1625 ha
->flags
.online
= 0;
1627 /* Detach interrupts */
1629 free_irq(ha
->pdev
->irq
, ha
);
1631 /* release io space registers */
1633 iounmap(ha
->iobase
);
1634 pci_release_regions(ha
->pdev
);
1636 pci_disable_device(ha
->pdev
);
1640 * qla2x00_mark_device_lost Updates fcport state when device goes offline.
1642 * Input: ha = adapter block pointer. fcport = port structure pointer.
1648 void qla2x00_mark_device_lost(scsi_qla_host_t
*ha
, fc_port_t
*fcport
,
1651 if (atomic_read(&fcport
->state
) == FCS_ONLINE
&& fcport
->rport
)
1652 schedule_work(&fcport
->rport_del_work
);
1655 * We may need to retry the login, so don't change the state of the
1656 * port but do the retries.
1658 if (atomic_read(&fcport
->state
) != FCS_DEVICE_DEAD
)
1659 atomic_set(&fcport
->state
, FCS_DEVICE_LOST
);
1664 if (fcport
->login_retry
== 0) {
1665 fcport
->login_retry
= ha
->login_retry_count
;
1666 set_bit(RELOGIN_NEEDED
, &ha
->dpc_flags
);
1668 DEBUG(printk("scsi(%ld): Port login retry: "
1669 "%02x%02x%02x%02x%02x%02x%02x%02x, "
1670 "id = 0x%04x retry cnt=%d\n",
1672 fcport
->port_name
[0],
1673 fcport
->port_name
[1],
1674 fcport
->port_name
[2],
1675 fcport
->port_name
[3],
1676 fcport
->port_name
[4],
1677 fcport
->port_name
[5],
1678 fcport
->port_name
[6],
1679 fcport
->port_name
[7],
1681 fcport
->login_retry
));
1686 * qla2x00_mark_all_devices_lost
1687 * Updates fcport state when device goes offline.
1690 * ha = adapter block pointer.
1691 * fcport = port structure pointer.
1699 qla2x00_mark_all_devices_lost(scsi_qla_host_t
*ha
)
1703 list_for_each_entry(fcport
, &ha
->fcports
, list
) {
1704 if (fcport
->port_type
!= FCT_TARGET
)
1708 * No point in marking the device as lost, if the device is
1711 if (atomic_read(&fcport
->state
) == FCS_DEVICE_DEAD
)
1713 if (atomic_read(&fcport
->state
) == FCS_ONLINE
&& fcport
->rport
)
1714 schedule_work(&fcport
->rport_del_work
);
1715 atomic_set(&fcport
->state
, FCS_DEVICE_LOST
);
1721 * Allocates adapter memory.
1728 qla2x00_mem_alloc(scsi_qla_host_t
*ha
)
1736 * This will loop only once if everything goes well, else some
1737 * number of retries will be performed to get around a kernel
1738 * bug where available mem is not allocated until after a
1739 * little delay and a retry.
1741 ha
->request_ring
= dma_alloc_coherent(&ha
->pdev
->dev
,
1742 (ha
->request_q_length
+ 1) * sizeof(request_t
),
1743 &ha
->request_dma
, GFP_KERNEL
);
1744 if (ha
->request_ring
== NULL
) {
1745 qla_printk(KERN_WARNING
, ha
,
1746 "Memory Allocation failed - request_ring\n");
1748 qla2x00_mem_free(ha
);
1754 ha
->response_ring
= dma_alloc_coherent(&ha
->pdev
->dev
,
1755 (ha
->response_q_length
+ 1) * sizeof(response_t
),
1756 &ha
->response_dma
, GFP_KERNEL
);
1757 if (ha
->response_ring
== NULL
) {
1758 qla_printk(KERN_WARNING
, ha
,
1759 "Memory Allocation failed - response_ring\n");
1761 qla2x00_mem_free(ha
);
1767 ha
->gid_list
= dma_alloc_coherent(&ha
->pdev
->dev
, GID_LIST_SIZE
,
1768 &ha
->gid_list_dma
, GFP_KERNEL
);
1769 if (ha
->gid_list
== NULL
) {
1770 qla_printk(KERN_WARNING
, ha
,
1771 "Memory Allocation failed - gid_list\n");
1773 qla2x00_mem_free(ha
);
1779 ha
->rlc_rsp
= dma_alloc_coherent(&ha
->pdev
->dev
,
1780 sizeof(rpt_lun_cmd_rsp_t
), &ha
->rlc_rsp_dma
, GFP_KERNEL
);
1781 if (ha
->rlc_rsp
== NULL
) {
1782 qla_printk(KERN_WARNING
, ha
,
1783 "Memory Allocation failed - rlc");
1785 qla2x00_mem_free(ha
);
1791 snprintf(name
, sizeof(name
), "qla2xxx_%ld", ha
->host_no
);
1792 ha
->s_dma_pool
= dma_pool_create(name
, &ha
->pdev
->dev
,
1793 DMA_POOL_SIZE
, 8, 0);
1794 if (ha
->s_dma_pool
== NULL
) {
1795 qla_printk(KERN_WARNING
, ha
,
1796 "Memory Allocation failed - s_dma_pool\n");
1798 qla2x00_mem_free(ha
);
1804 /* get consistent memory allocated for init control block */
1805 ha
->init_cb
= dma_pool_alloc(ha
->s_dma_pool
, GFP_KERNEL
,
1807 if (ha
->init_cb
== NULL
) {
1808 qla_printk(KERN_WARNING
, ha
,
1809 "Memory Allocation failed - init_cb\n");
1811 qla2x00_mem_free(ha
);
1816 memset(ha
->init_cb
, 0, ha
->init_cb_size
);
1818 /* Get consistent memory allocated for Get Port Database cmd */
1819 ha
->iodesc_pd
= dma_pool_alloc(ha
->s_dma_pool
, GFP_KERNEL
,
1820 &ha
->iodesc_pd_dma
);
1821 if (ha
->iodesc_pd
== NULL
) {
1823 qla_printk(KERN_WARNING
, ha
,
1824 "Memory Allocation failed - iodesc_pd\n");
1826 qla2x00_mem_free(ha
);
1831 memset(ha
->iodesc_pd
, 0, PORT_DATABASE_SIZE
);
1833 /* Allocate ioctl related memory. */
1834 if (qla2x00_alloc_ioctl_mem(ha
)) {
1835 qla_printk(KERN_WARNING
, ha
,
1836 "Memory Allocation failed - ioctl_mem\n");
1838 qla2x00_mem_free(ha
);
1844 if (qla2x00_allocate_sp_pool(ha
)) {
1845 qla_printk(KERN_WARNING
, ha
,
1846 "Memory Allocation failed - "
1847 "qla2x00_allocate_sp_pool()\n");
1849 qla2x00_mem_free(ha
);
1855 /* Allocate memory for SNS commands */
1856 if (IS_QLA2100(ha
) || IS_QLA2200(ha
)) {
1857 /* Get consistent memory allocated for SNS commands */
1858 ha
->sns_cmd
= dma_alloc_coherent(&ha
->pdev
->dev
,
1859 sizeof(struct sns_cmd_pkt
), &ha
->sns_cmd_dma
,
1861 if (ha
->sns_cmd
== NULL
) {
1863 qla_printk(KERN_WARNING
, ha
,
1864 "Memory Allocation failed - sns_cmd\n");
1866 qla2x00_mem_free(ha
);
1871 memset(ha
->sns_cmd
, 0, sizeof(struct sns_cmd_pkt
));
1873 /* Get consistent memory allocated for MS IOCB */
1874 ha
->ms_iocb
= dma_pool_alloc(ha
->s_dma_pool
, GFP_KERNEL
,
1876 if (ha
->ms_iocb
== NULL
) {
1878 qla_printk(KERN_WARNING
, ha
,
1879 "Memory Allocation failed - ms_iocb\n");
1881 qla2x00_mem_free(ha
);
1886 memset(ha
->ms_iocb
, 0, sizeof(ms_iocb_entry_t
));
1889 * Get consistent memory allocated for CT SNS
1892 ha
->ct_sns
= dma_alloc_coherent(&ha
->pdev
->dev
,
1893 sizeof(struct ct_sns_pkt
), &ha
->ct_sns_dma
,
1895 if (ha
->ct_sns
== NULL
) {
1897 qla_printk(KERN_WARNING
, ha
,
1898 "Memory Allocation failed - ct_sns\n");
1900 qla2x00_mem_free(ha
);
1905 memset(ha
->ct_sns
, 0, sizeof(struct ct_sns_pkt
));
1908 /* Done all allocations without any error. */
1911 } while (retry
-- && status
!= 0);
1915 "%s(): **** FAILED ****\n", __func__
);
1923 * Frees all adapter allocated memory.
1926 * ha = adapter block pointer.
1929 qla2x00_mem_free(scsi_qla_host_t
*ha
)
1931 struct list_head
*fcpl
, *fcptemp
;
1933 unsigned int wtime
;/* max wait time if mbx cmd is busy. */
1937 DEBUG2(printk("%s(): ERROR invalid ha pointer.\n", __func__
));
1941 /* Make sure all other threads are stopped. */
1943 while (ha
->dpc_wait
&& wtime
)
1944 wtime
= msleep_interruptible(wtime
);
1946 /* free ioctl memory */
1947 qla2x00_free_ioctl_mem(ha
);
1950 qla2x00_free_sp_pool(ha
);
1953 dma_free_coherent(&ha
->pdev
->dev
, sizeof(struct sns_cmd_pkt
),
1954 ha
->sns_cmd
, ha
->sns_cmd_dma
);
1957 dma_free_coherent(&ha
->pdev
->dev
, sizeof(struct ct_sns_pkt
),
1958 ha
->ct_sns
, ha
->ct_sns_dma
);
1961 dma_pool_free(ha
->s_dma_pool
, ha
->ms_iocb
, ha
->ms_iocb_dma
);
1964 dma_pool_free(ha
->s_dma_pool
, ha
->iodesc_pd
, ha
->iodesc_pd_dma
);
1967 dma_pool_free(ha
->s_dma_pool
, ha
->init_cb
, ha
->init_cb_dma
);
1970 dma_pool_destroy(ha
->s_dma_pool
);
1973 dma_free_coherent(&ha
->pdev
->dev
,
1974 sizeof(rpt_lun_cmd_rsp_t
), ha
->rlc_rsp
,
1978 dma_free_coherent(&ha
->pdev
->dev
, GID_LIST_SIZE
, ha
->gid_list
,
1981 if (ha
->response_ring
)
1982 dma_free_coherent(&ha
->pdev
->dev
,
1983 (ha
->response_q_length
+ 1) * sizeof(response_t
),
1984 ha
->response_ring
, ha
->response_dma
);
1986 if (ha
->request_ring
)
1987 dma_free_coherent(&ha
->pdev
->dev
,
1988 (ha
->request_q_length
+ 1) * sizeof(request_t
),
1989 ha
->request_ring
, ha
->request_dma
);
1992 ha
->sns_cmd_dma
= 0;
1996 ha
->ms_iocb_dma
= 0;
1997 ha
->iodesc_pd
= NULL
;
1998 ha
->iodesc_pd_dma
= 0;
2000 ha
->init_cb_dma
= 0;
2002 ha
->s_dma_pool
= NULL
;
2005 ha
->rlc_rsp_dma
= 0;
2006 ha
->gid_list
= NULL
;
2007 ha
->gid_list_dma
= 0;
2009 ha
->response_ring
= NULL
;
2010 ha
->response_dma
= 0;
2011 ha
->request_ring
= NULL
;
2012 ha
->request_dma
= 0;
2014 list_for_each_safe(fcpl
, fcptemp
, &ha
->fcports
) {
2015 fcport
= list_entry(fcpl
, fc_port_t
, list
);
2018 list_del_init(&fcport
->list
);
2021 INIT_LIST_HEAD(&ha
->fcports
);
2024 free_pages((unsigned long)ha
->fw_dump
, ha
->fw_dump_order
);
2026 vfree(ha
->fw_dump24
);
2028 vfree(ha
->fw_dump_buffer
);
2031 ha
->fw_dump24
= NULL
;
2033 ha
->fw_dump_reading
= 0;
2034 ha
->fw_dump_buffer
= NULL
;
2038 * qla2x00_allocate_sp_pool
2039 * This routine is called during initialization to allocate
2040 * memory for local srb_t.
2043 * ha = adapter block pointer.
2048 * Note: Sets the ref_count for non Null sp to one.
2051 qla2x00_allocate_sp_pool(scsi_qla_host_t
*ha
)
2056 ha
->srb_mempool
= mempool_create(SRB_MIN_REQ
, mempool_alloc_slab
,
2057 mempool_free_slab
, srb_cachep
);
2058 if (ha
->srb_mempool
== NULL
) {
2059 qla_printk(KERN_INFO
, ha
, "Unable to allocate SRB mempool.\n");
2060 rval
= QLA_FUNCTION_FAILED
;
2066 * This routine frees all adapter allocated memory.
2070 qla2x00_free_sp_pool( scsi_qla_host_t
*ha
)
2072 if (ha
->srb_mempool
) {
2073 mempool_destroy(ha
->srb_mempool
);
2074 ha
->srb_mempool
= NULL
;
2078 /**************************************************************************
2080 * This kernel thread is a task that is schedule by the interrupt handler
2081 * to perform the background processing for interrupts.
2084 * This task always run in the context of a kernel thread. It
2085 * is kick-off by the driver's detect code and starts up
2086 * up one per adapter. It immediately goes to sleep and waits for
2087 * some fibre event. When either the interrupt handler or
2088 * the timer routine detects a event it will one of the task
2089 * bits then wake us up.
2090 **************************************************************************/
2092 qla2x00_do_dpc(void *data
)
2094 DECLARE_MUTEX_LOCKED(sem
);
2095 scsi_qla_host_t
*ha
;
2098 uint16_t next_loopid
;
2100 ha
= (scsi_qla_host_t
*)data
;
2104 daemonize("%s_dpc", ha
->host_str
);
2105 allow_signal(SIGHUP
);
2107 ha
->dpc_wait
= &sem
;
2109 set_user_nice(current
, -20);
2113 complete(&ha
->dpc_inited
);
2116 DEBUG3(printk("qla2x00: DPC handler sleeping\n"));
2118 if (down_interruptible(&sem
))
2121 if (ha
->dpc_should_die
)
2124 DEBUG3(printk("qla2x00: DPC handler waking up\n"));
2126 /* Initialization not yet finished. Don't do anything yet. */
2127 if (!ha
->flags
.init_done
|| ha
->dpc_active
)
2130 DEBUG3(printk("scsi(%ld): DPC handler\n", ha
->host_no
));
2134 if (ha
->flags
.mbox_busy
) {
2139 if (test_and_clear_bit(ISP_ABORT_NEEDED
, &ha
->dpc_flags
)) {
2141 DEBUG(printk("scsi(%ld): dpc: sched "
2142 "qla2x00_abort_isp ha = %p\n",
2144 if (!(test_and_set_bit(ABORT_ISP_ACTIVE
,
2147 if (qla2x00_abort_isp(ha
)) {
2148 /* failed. retry later */
2149 set_bit(ISP_ABORT_NEEDED
,
2152 clear_bit(ABORT_ISP_ACTIVE
, &ha
->dpc_flags
);
2154 DEBUG(printk("scsi(%ld): dpc: qla2x00_abort_isp end\n",
2158 if (test_and_clear_bit(LOOP_RESET_NEEDED
, &ha
->dpc_flags
)) {
2159 DEBUG(printk("scsi(%ld): dpc: sched loop_reset()\n",
2161 qla2x00_loop_reset(ha
);
2164 if (test_and_clear_bit(RESET_MARKER_NEEDED
, &ha
->dpc_flags
) &&
2165 (!(test_and_set_bit(RESET_ACTIVE
, &ha
->dpc_flags
)))) {
2167 DEBUG(printk("scsi(%ld): qla2x00_reset_marker()\n",
2170 qla2x00_rst_aen(ha
);
2171 clear_bit(RESET_ACTIVE
, &ha
->dpc_flags
);
2174 /* Retry each device up to login retry count */
2175 if ((test_and_clear_bit(RELOGIN_NEEDED
, &ha
->dpc_flags
)) &&
2176 !test_bit(LOOP_RESYNC_NEEDED
, &ha
->dpc_flags
) &&
2177 atomic_read(&ha
->loop_state
) != LOOP_DOWN
) {
2179 DEBUG(printk("scsi(%ld): qla2x00_port_login()\n",
2183 list_for_each_entry(fcport
, &ha
->fcports
, list
) {
2184 if (fcport
->port_type
!= FCT_TARGET
)
2188 * If the port is not ONLINE then try to login
2189 * to it if we haven't run out of retries.
2191 if (atomic_read(&fcport
->state
) != FCS_ONLINE
&&
2192 fcport
->login_retry
) {
2194 fcport
->login_retry
--;
2195 if (fcport
->flags
& FCF_FABRIC_DEVICE
) {
2198 ha
->isp_ops
.fabric_logout(
2199 ha
, fcport
->loop_id
,
2200 fcport
->d_id
.b
.domain
,
2201 fcport
->d_id
.b
.area
,
2202 fcport
->d_id
.b
.al_pa
);
2203 status
= qla2x00_fabric_login(
2204 ha
, fcport
, &next_loopid
);
2207 qla2x00_local_device_login(
2208 ha
, fcport
->loop_id
);
2210 if (status
== QLA_SUCCESS
) {
2211 fcport
->old_loop_id
= fcport
->loop_id
;
2213 DEBUG(printk("scsi(%ld): port login OK: logged in ID 0x%x\n",
2214 ha
->host_no
, fcport
->loop_id
));
2216 fcport
->port_login_retry_count
=
2217 ha
->port_down_retry_count
* PORT_RETRY_TIME
;
2218 atomic_set(&fcport
->state
, FCS_ONLINE
);
2219 atomic_set(&fcport
->port_down_timer
,
2220 ha
->port_down_retry_count
* PORT_RETRY_TIME
);
2222 fcport
->login_retry
= 0;
2223 } else if (status
== 1) {
2224 set_bit(RELOGIN_NEEDED
, &ha
->dpc_flags
);
2225 /* retry the login again */
2226 DEBUG(printk("scsi(%ld): Retrying %d login again loop_id 0x%x\n",
2228 fcport
->login_retry
, fcport
->loop_id
));
2230 fcport
->login_retry
= 0;
2233 if (test_bit(LOOP_RESYNC_NEEDED
, &ha
->dpc_flags
))
2236 DEBUG(printk("scsi(%ld): qla2x00_port_login - end\n",
2240 if ((test_bit(LOGIN_RETRY_NEEDED
, &ha
->dpc_flags
)) &&
2241 atomic_read(&ha
->loop_state
) != LOOP_DOWN
) {
2243 clear_bit(LOGIN_RETRY_NEEDED
, &ha
->dpc_flags
);
2244 DEBUG(printk("scsi(%ld): qla2x00_login_retry()\n",
2247 set_bit(LOOP_RESYNC_NEEDED
, &ha
->dpc_flags
);
2249 DEBUG(printk("scsi(%ld): qla2x00_login_retry - end\n",
2253 if (test_and_clear_bit(LOOP_RESYNC_NEEDED
, &ha
->dpc_flags
)) {
2255 DEBUG(printk("scsi(%ld): qla2x00_loop_resync()\n",
2258 if (!(test_and_set_bit(LOOP_RESYNC_ACTIVE
,
2261 qla2x00_loop_resync(ha
);
2263 clear_bit(LOOP_RESYNC_ACTIVE
, &ha
->dpc_flags
);
2266 DEBUG(printk("scsi(%ld): qla2x00_loop_resync - end\n",
2270 if (test_and_clear_bit(FCPORT_RESCAN_NEEDED
, &ha
->dpc_flags
)) {
2272 DEBUG(printk("scsi(%ld): Rescan flagged fcports...\n",
2275 qla2x00_rescan_fcports(ha
);
2277 DEBUG(printk("scsi(%ld): Rescan flagged fcports..."
2282 if (!ha
->interrupts_on
)
2283 ha
->isp_ops
.enable_intrs(ha
);
2286 } /* End of while(1) */
2288 DEBUG(printk("scsi(%ld): DPC handler exiting\n", ha
->host_no
));
2291 * Make sure that nobody tries to wake us up again.
2293 ha
->dpc_wait
= NULL
;
2296 complete_and_exit(&ha
->dpc_exited
, 0);
2301 * Processes asynchronous reset.
2304 * ha = adapter block pointer.
2307 qla2x00_rst_aen(scsi_qla_host_t
*ha
)
2309 if (ha
->flags
.online
&& !ha
->flags
.reset_active
&&
2310 !atomic_read(&ha
->loop_down_timer
) &&
2311 !(test_bit(ABORT_ISP_ACTIVE
, &ha
->dpc_flags
))) {
2313 clear_bit(RESET_MARKER_NEEDED
, &ha
->dpc_flags
);
2316 * Issue marker command only when we are going to start
2319 ha
->marker_needed
= 1;
2320 } while (!atomic_read(&ha
->loop_down_timer
) &&
2321 (test_bit(RESET_MARKER_NEEDED
, &ha
->dpc_flags
)));
2326 qla2x00_sp_free_dma(scsi_qla_host_t
*ha
, srb_t
*sp
)
2328 struct scsi_cmnd
*cmd
= sp
->cmd
;
2330 if (sp
->flags
& SRB_DMA_VALID
) {
2332 dma_unmap_sg(&ha
->pdev
->dev
, cmd
->request_buffer
,
2333 cmd
->use_sg
, cmd
->sc_data_direction
);
2334 } else if (cmd
->request_bufflen
) {
2335 dma_unmap_single(&ha
->pdev
->dev
, sp
->dma_handle
,
2336 cmd
->request_bufflen
, cmd
->sc_data_direction
);
2338 sp
->flags
&= ~SRB_DMA_VALID
;
2344 qla2x00_sp_compl(scsi_qla_host_t
*ha
, srb_t
*sp
)
2346 struct scsi_cmnd
*cmd
= sp
->cmd
;
2348 qla2x00_sp_free_dma(ha
, sp
);
2350 mempool_free(sp
, ha
->srb_mempool
);
2352 cmd
->scsi_done(cmd
);
2355 /**************************************************************************
2361 * Context: Interrupt
2362 ***************************************************************************/
2364 qla2x00_timer(scsi_qla_host_t
*ha
)
2366 unsigned long cpu_flags
= 0;
2374 * Ports - Port down timer.
2376 * Whenever, a port is in the LOST state we start decrementing its port
2377 * down timer every second until it reaches zero. Once it reaches zero
2378 * the port it marked DEAD.
2381 list_for_each_entry(fcport
, &ha
->fcports
, list
) {
2382 if (fcport
->port_type
!= FCT_TARGET
)
2385 if (atomic_read(&fcport
->state
) == FCS_DEVICE_LOST
) {
2387 if (atomic_read(&fcport
->port_down_timer
) == 0)
2390 if (atomic_dec_and_test(&fcport
->port_down_timer
) != 0)
2391 atomic_set(&fcport
->state
, FCS_DEVICE_DEAD
);
2393 DEBUG(printk("scsi(%ld): fcport-%d - port retry count: "
2396 t
, atomic_read(&fcport
->port_down_timer
)));
2399 } /* End of for fcport */
2402 /* Loop down handler. */
2403 if (atomic_read(&ha
->loop_down_timer
) > 0 &&
2404 !(test_bit(ABORT_ISP_ACTIVE
, &ha
->dpc_flags
)) && ha
->flags
.online
) {
2406 if (atomic_read(&ha
->loop_down_timer
) ==
2407 ha
->loop_down_abort_time
) {
2409 DEBUG(printk("scsi(%ld): Loop Down - aborting the "
2410 "queues before time expire\n",
2413 if (!IS_QLA2100(ha
) && ha
->link_down_timeout
)
2414 atomic_set(&ha
->loop_state
, LOOP_DEAD
);
2416 /* Schedule an ISP abort to return any tape commands. */
2417 spin_lock_irqsave(&ha
->hardware_lock
, cpu_flags
);
2418 for (index
= 1; index
< MAX_OUTSTANDING_COMMANDS
;
2422 sp
= ha
->outstanding_cmds
[index
];
2426 if (!(sfcp
->flags
& FCF_TAPE_PRESENT
))
2429 set_bit(ISP_ABORT_NEEDED
, &ha
->dpc_flags
);
2432 spin_unlock_irqrestore(&ha
->hardware_lock
, cpu_flags
);
2434 set_bit(ABORT_QUEUES_NEEDED
, &ha
->dpc_flags
);
2438 /* if the loop has been down for 4 minutes, reinit adapter */
2439 if (atomic_dec_and_test(&ha
->loop_down_timer
) != 0) {
2440 DEBUG(printk("scsi(%ld): Loop down exceed 4 mins - "
2441 "restarting queues.\n",
2444 set_bit(RESTART_QUEUES_NEEDED
, &ha
->dpc_flags
);
2447 if (!(ha
->device_flags
& DFLG_NO_CABLE
)) {
2448 DEBUG(printk("scsi(%ld): Loop down - "
2451 qla_printk(KERN_WARNING
, ha
,
2452 "Loop down - aborting ISP.\n");
2454 set_bit(ISP_ABORT_NEEDED
, &ha
->dpc_flags
);
2457 DEBUG3(printk("scsi(%ld): Loop Down - seconds remaining %d\n",
2459 atomic_read(&ha
->loop_down_timer
)));
2462 /* Schedule the DPC routine if needed */
2463 if ((test_bit(ISP_ABORT_NEEDED
, &ha
->dpc_flags
) ||
2464 test_bit(LOOP_RESYNC_NEEDED
, &ha
->dpc_flags
) ||
2465 test_bit(LOOP_RESET_NEEDED
, &ha
->dpc_flags
) ||
2467 test_bit(LOGIN_RETRY_NEEDED
, &ha
->dpc_flags
) ||
2468 test_bit(RESET_MARKER_NEEDED
, &ha
->dpc_flags
) ||
2469 test_bit(RELOGIN_NEEDED
, &ha
->dpc_flags
)) &&
2470 ha
->dpc_wait
&& !ha
->dpc_active
) {
2475 qla2x00_restart_timer(ha
, WATCH_INTERVAL
);
2478 /* XXX(hch): crude hack to emulate a down_timeout() */
2480 qla2x00_down_timeout(struct semaphore
*sema
, unsigned long timeout
)
2482 const unsigned int step
= 100; /* msecs */
2483 unsigned int iterations
= jiffies_to_msecs(timeout
)/100;
2486 if (!down_trylock(sema
))
2488 if (msleep_interruptible(step
))
2490 } while (--iterations
>= 0);
2495 #if defined(CONFIG_SCSI_QLA2XXX_EMBEDDED_FIRMWARE)
2497 #define qla2x00_release_firmware() do { } while (0)
2498 #define qla2x00_pci_module_init() (0)
2499 #define qla2x00_pci_module_exit() do { } while (0)
2501 #else /* !defined(CONFIG_SCSI_QLA2XXX_EMBEDDED_FIRMWARE) */
2503 /* Firmware interface routines. */
2506 #define FW_ISP21XX 0
2507 #define FW_ISP22XX 1
2508 #define FW_ISP2300 2
2509 #define FW_ISP2322 3
2510 #define FW_ISP63XX 4
2511 #define FW_ISP24XX 5
2513 static DECLARE_MUTEX(qla_fw_lock
);
2515 static struct fw_blob qla_fw_blobs
[FW_BLOBS
] = {
2516 { .name
= "ql2100_fw.bin", .segs
= { 0x1000, 0 }, },
2517 { .name
= "ql2200_fw.bin", .segs
= { 0x1000, 0 }, },
2518 { .name
= "ql2300_fw.bin", .segs
= { 0x800, 0 }, },
2519 { .name
= "ql2322_fw.bin", .segs
= { 0x800, 0x1c000, 0x1e000, 0 }, },
2520 { .name
= "ql6312_fw.bin", .segs
= { 0x800, 0 }, },
2521 { .name
= "ql2400_fw.bin", },
2525 qla2x00_request_firmware(scsi_qla_host_t
*ha
)
2527 struct fw_blob
*blob
;
2530 if (IS_QLA2100(ha
)) {
2531 blob
= &qla_fw_blobs
[FW_ISP21XX
];
2532 } else if (IS_QLA2200(ha
)) {
2533 blob
= &qla_fw_blobs
[FW_ISP22XX
];
2534 } else if (IS_QLA2300(ha
) || IS_QLA2312(ha
)) {
2535 blob
= &qla_fw_blobs
[FW_ISP2300
];
2536 } else if (IS_QLA2322(ha
)) {
2537 blob
= &qla_fw_blobs
[FW_ISP2322
];
2538 } else if (IS_QLA6312(ha
) || IS_QLA6322(ha
)) {
2539 blob
= &qla_fw_blobs
[FW_ISP63XX
];
2540 } else if (IS_QLA24XX(ha
)) {
2541 blob
= &qla_fw_blobs
[FW_ISP24XX
];
2548 if (request_firmware(&blob
->fw
, blob
->name
, &ha
->pdev
->dev
)) {
2549 DEBUG2(printk("scsi(%ld): Failed to load firmware image "
2550 "(%s).\n", ha
->host_no
, blob
->name
));
2562 qla2x00_release_firmware(void)
2567 for (idx
= 0; idx
< FW_BLOBS
; idx
++)
2568 if (qla_fw_blobs
[idx
].fw
)
2569 release_firmware(qla_fw_blobs
[idx
].fw
);
2573 static struct qla_board_info qla_board_tbl
= {
2574 .drv_name
= "qla2xxx",
2577 static struct pci_device_id qla2xxx_pci_tbl
[] = {
2578 { PCI_VENDOR_ID_QLOGIC
, PCI_DEVICE_ID_QLOGIC_ISP2100
,
2579 PCI_ANY_ID
, PCI_ANY_ID
, },
2580 { PCI_VENDOR_ID_QLOGIC
, PCI_DEVICE_ID_QLOGIC_ISP2200
,
2581 PCI_ANY_ID
, PCI_ANY_ID
, },
2582 { PCI_VENDOR_ID_QLOGIC
, PCI_DEVICE_ID_QLOGIC_ISP2300
,
2583 PCI_ANY_ID
, PCI_ANY_ID
, },
2584 { PCI_VENDOR_ID_QLOGIC
, PCI_DEVICE_ID_QLOGIC_ISP2312
,
2585 PCI_ANY_ID
, PCI_ANY_ID
, },
2586 { PCI_VENDOR_ID_QLOGIC
, PCI_DEVICE_ID_QLOGIC_ISP2322
,
2587 PCI_ANY_ID
, PCI_ANY_ID
, },
2588 { PCI_VENDOR_ID_QLOGIC
, PCI_DEVICE_ID_QLOGIC_ISP6312
,
2589 PCI_ANY_ID
, PCI_ANY_ID
, },
2590 { PCI_VENDOR_ID_QLOGIC
, PCI_DEVICE_ID_QLOGIC_ISP6322
,
2591 PCI_ANY_ID
, PCI_ANY_ID
, },
2592 { PCI_VENDOR_ID_QLOGIC
, PCI_DEVICE_ID_QLOGIC_ISP2422
,
2593 PCI_ANY_ID
, PCI_ANY_ID
, },
2594 { PCI_VENDOR_ID_QLOGIC
, PCI_DEVICE_ID_QLOGIC_ISP2432
,
2595 PCI_ANY_ID
, PCI_ANY_ID
, },
2598 MODULE_DEVICE_TABLE(pci
, qla2xxx_pci_tbl
);
2600 static int __devinit
2601 qla2xxx_probe_one(struct pci_dev
*pdev
, const struct pci_device_id
*id
)
2603 return qla2x00_probe_one(pdev
, &qla_board_tbl
);
2606 static void __devexit
2607 qla2xxx_remove_one(struct pci_dev
*pdev
)
2609 qla2x00_remove_one(pdev
);
2612 static struct pci_driver qla2xxx_pci_driver
= {
2615 .owner
= THIS_MODULE
,
2617 .id_table
= qla2xxx_pci_tbl
,
2618 .probe
= qla2xxx_probe_one
,
2619 .remove
= __devexit_p(qla2xxx_remove_one
),
2623 qla2x00_pci_module_init(void)
2625 return pci_module_init(&qla2xxx_pci_driver
);
2629 qla2x00_pci_module_exit(void)
2631 pci_unregister_driver(&qla2xxx_pci_driver
);
2637 * qla2x00_module_init - Module initialization.
2640 qla2x00_module_init(void)
2644 /* Allocate cache for SRBs. */
2645 srb_cachep
= kmem_cache_create("qla2xxx_srbs", sizeof(srb_t
), 0,
2646 SLAB_HWCACHE_ALIGN
, NULL
, NULL
);
2647 if (srb_cachep
== NULL
) {
2649 "qla2xxx: Unable to allocate SRB cache...Failing load!\n");
2653 /* Derive version string. */
2654 strcpy(qla2x00_version_str
, QLA2XXX_VERSION
);
2655 #if defined(CONFIG_SCSI_QLA2XXX_EMBEDDED_FIRMWARE)
2656 strcat(qla2x00_version_str
, "-fw");
2659 strcat(qla2x00_version_str
, "-debug");
2661 qla2xxx_transport_template
=
2662 fc_attach_transport(&qla2xxx_transport_functions
);
2663 if (!qla2xxx_transport_template
)
2666 printk(KERN_INFO
"QLogic Fibre Channel HBA Driver\n");
2667 ret
= qla2x00_pci_module_init();
2669 kmem_cache_destroy(srb_cachep
);
2670 fc_release_transport(qla2xxx_transport_template
);
2676 * qla2x00_module_exit - Module cleanup.
2679 qla2x00_module_exit(void)
2681 qla2x00_pci_module_exit();
2682 qla2x00_release_firmware();
2683 kmem_cache_destroy(srb_cachep
);
2684 fc_release_transport(qla2xxx_transport_template
);
2687 module_init(qla2x00_module_init
);
2688 module_exit(qla2x00_module_exit
);
2690 MODULE_AUTHOR("QLogic Corporation");
2691 MODULE_DESCRIPTION("QLogic Fibre Channel HBA Driver");
2692 MODULE_LICENSE("GPL");
2693 MODULE_VERSION(QLA2XXX_VERSION
);