2 * QLOGIC LINUX SOFTWARE
4 * QLogic ISP2x00 device driver for Linux 2.6.x
5 * Copyright (C) 2003-2004 QLogic Corporation
8 * This program is free software; you can redistribute it and/or modify it
9 * under the terms of the GNU General Public License as published by the
10 * Free Software Foundation; either version 2, or (at your option) any
13 * This program is distributed in the hope that it will be useful, but
14 * WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * General Public License for more details.
21 #include <linux/moduleparam.h>
22 #include <linux/vmalloc.h>
23 #include <linux/smp_lock.h>
24 #include <linux/delay.h>
26 #include <scsi/scsi_tcq.h>
27 #include <scsi/scsicam.h>
28 #include <scsi/scsi_transport.h>
29 #include <scsi/scsi_transport_fc.h>
34 char qla2x00_version_str
[40];
37 * SRB allocation cache
39 static kmem_cache_t
*srb_cachep
;
42 * Ioctl related information.
46 int ql2xlogintimeout
= 20;
47 module_param(ql2xlogintimeout
, int, S_IRUGO
|S_IRUSR
);
48 MODULE_PARM_DESC(ql2xlogintimeout
,
49 "Login timeout value in seconds.");
51 int qlport_down_retry
= 30;
52 module_param(qlport_down_retry
, int, S_IRUGO
|S_IRUSR
);
53 MODULE_PARM_DESC(qlport_down_retry
,
54 "Maximum number of command retries to a port that returns"
55 "a PORT-DOWN status.");
57 int ql2xplogiabsentdevice
;
58 module_param(ql2xplogiabsentdevice
, int, S_IRUGO
|S_IWUSR
);
59 MODULE_PARM_DESC(ql2xplogiabsentdevice
,
60 "Option to enable PLOGI to devices that are not present after "
61 "a Fabric scan. This is needed for several broken switches."
62 "Default is 0 - no PLOGI. 1 - perfom PLOGI.");
64 int ql2xenablezio
= 0;
65 module_param(ql2xenablezio
, int, S_IRUGO
|S_IRUSR
);
66 MODULE_PARM_DESC(ql2xenablezio
,
67 "Option to enable ZIO:If 1 then enable it otherwise"
68 " use the default set in the NVRAM."
69 " Default is 0 : disabled");
71 int ql2xintrdelaytimer
= 10;
72 module_param(ql2xintrdelaytimer
, int, S_IRUGO
|S_IRUSR
);
73 MODULE_PARM_DESC(ql2xintrdelaytimer
,
74 "ZIO: Waiting time for Firmware before it generates an "
75 "interrupt to the host to notify completion of request.");
77 int ql2xloginretrycount
= 0;
78 module_param(ql2xloginretrycount
, int, S_IRUGO
|S_IRUSR
);
79 MODULE_PARM_DESC(ql2xloginretrycount
,
80 "Specify an alternate value for the NVRAM login retry count.");
82 static void qla2x00_free_device(scsi_qla_host_t
*);
84 static void qla2x00_config_dma_addressing(scsi_qla_host_t
*ha
);
87 * SCSI host template entry points
89 static int qla2xxx_slave_configure(struct scsi_device
* device
);
90 static int qla2xxx_slave_alloc(struct scsi_device
*);
91 static void qla2xxx_slave_destroy(struct scsi_device
*);
92 static int qla2x00_queuecommand(struct scsi_cmnd
*cmd
,
93 void (*fn
)(struct scsi_cmnd
*));
94 static int qla2xxx_eh_abort(struct scsi_cmnd
*);
95 static int qla2xxx_eh_device_reset(struct scsi_cmnd
*);
96 static int qla2xxx_eh_bus_reset(struct scsi_cmnd
*);
97 static int qla2xxx_eh_host_reset(struct scsi_cmnd
*);
98 static int qla2x00_loop_reset(scsi_qla_host_t
*ha
);
99 static int qla2x00_device_reset(scsi_qla_host_t
*, fc_port_t
*);
101 static struct scsi_host_template qla2x00_driver_template
= {
102 .module
= THIS_MODULE
,
104 .queuecommand
= qla2x00_queuecommand
,
106 .eh_abort_handler
= qla2xxx_eh_abort
,
107 .eh_device_reset_handler
= qla2xxx_eh_device_reset
,
108 .eh_bus_reset_handler
= qla2xxx_eh_bus_reset
,
109 .eh_host_reset_handler
= qla2xxx_eh_host_reset
,
111 .slave_configure
= qla2xxx_slave_configure
,
113 .slave_alloc
= qla2xxx_slave_alloc
,
114 .slave_destroy
= qla2xxx_slave_destroy
,
117 .use_clustering
= ENABLE_CLUSTERING
,
118 .sg_tablesize
= SG_ALL
,
121 * The RISC allows for each command to transfer (2^32-1) bytes of data,
122 * which equates to 0x800000 sectors.
124 .max_sectors
= 0xFFFF,
127 static struct scsi_transport_template
*qla2xxx_transport_template
= NULL
;
129 /* TODO Convert to inlines
133 #define WATCH_INTERVAL 1 /* number of seconds */
135 static void qla2x00_timer(scsi_qla_host_t
*);
137 static __inline__
void qla2x00_start_timer(scsi_qla_host_t
*,
138 void *, unsigned long);
139 static __inline__
void qla2x00_restart_timer(scsi_qla_host_t
*, unsigned long);
140 static __inline__
void qla2x00_stop_timer(scsi_qla_host_t
*);
143 qla2x00_start_timer(scsi_qla_host_t
*ha
, void *func
, unsigned long interval
)
145 init_timer(&ha
->timer
);
146 ha
->timer
.expires
= jiffies
+ interval
* HZ
;
147 ha
->timer
.data
= (unsigned long)ha
;
148 ha
->timer
.function
= (void (*)(unsigned long))func
;
149 add_timer(&ha
->timer
);
150 ha
->timer_active
= 1;
154 qla2x00_restart_timer(scsi_qla_host_t
*ha
, unsigned long interval
)
156 mod_timer(&ha
->timer
, jiffies
+ interval
* HZ
);
159 static __inline__
void
160 qla2x00_stop_timer(scsi_qla_host_t
*ha
)
162 del_timer_sync(&ha
->timer
);
163 ha
->timer_active
= 0;
166 static int qla2x00_do_dpc(void *data
);
168 static void qla2x00_rst_aen(scsi_qla_host_t
*);
170 static uint8_t qla2x00_mem_alloc(scsi_qla_host_t
*);
171 static void qla2x00_mem_free(scsi_qla_host_t
*ha
);
172 static int qla2x00_allocate_sp_pool( scsi_qla_host_t
*ha
);
173 static void qla2x00_free_sp_pool(scsi_qla_host_t
*ha
);
174 static srb_t
*qla2x00_get_new_sp(scsi_qla_host_t
*);
175 static void qla2x00_sp_free_dma(scsi_qla_host_t
*, srb_t
*);
176 void qla2x00_sp_compl(scsi_qla_host_t
*ha
, srb_t
*);
178 /* -------------------------------------------------------------------------- */
181 qla2x00_get_pci_info_str(struct scsi_qla_host
*ha
, char *str
)
183 static char *pci_bus_modes
[] = {
184 "33", "66", "100", "133",
189 pci_bus
= (ha
->pci_attr
& (BIT_9
| BIT_10
)) >> 9;
192 strcat(str
, pci_bus_modes
[pci_bus
]);
194 pci_bus
= (ha
->pci_attr
& BIT_8
) >> 8;
196 strcat(str
, pci_bus_modes
[pci_bus
]);
198 strcat(str
, " MHz)");
204 qla2x00_get_fw_version_str(struct scsi_qla_host
*ha
, char *str
)
208 sprintf(str
, "%d.%02d.%02d ", ha
->fw_major_version
,
209 ha
->fw_minor_version
,
210 ha
->fw_subminor_version
);
212 if (ha
->fw_attributes
& BIT_9
) {
217 switch (ha
->fw_attributes
& 0xFF) {
231 sprintf(un_str
, "(%x)", ha
->fw_attributes
);
235 if (ha
->fw_attributes
& 0x100)
241 /**************************************************************************
242 * qla2x00_queuecommand
245 * Queue a command to the controller.
248 * cmd - pointer to Scsi cmd structure
249 * fn - pointer to Scsi done function
255 * The mid-level driver tries to ensures that queuecommand never gets invoked
256 * concurrently with itself or the interrupt handler (although the
257 * interrupt handler may call this routine as part of request-completion
259 **************************************************************************/
261 qla2x00_queuecommand(struct scsi_cmnd
*cmd
, void (*done
)(struct scsi_cmnd
*))
263 scsi_qla_host_t
*ha
= to_qla_host(cmd
->device
->host
);
264 fc_port_t
*fcport
= (struct fc_port
*) cmd
->device
->hostdata
;
269 cmd
->result
= DID_NO_CONNECT
<< 16;
270 goto qc_fail_command
;
273 if (atomic_read(&fcport
->state
) != FCS_ONLINE
) {
274 if (atomic_read(&fcport
->state
) == FCS_DEVICE_DEAD
||
275 atomic_read(&ha
->loop_state
) == LOOP_DEAD
) {
276 cmd
->result
= DID_NO_CONNECT
<< 16;
277 goto qc_fail_command
;
282 spin_unlock_irq(ha
->host
->host_lock
);
284 /* Allocate a command packet from the "sp" pool. */
285 if ((sp
= qla2x00_get_new_sp(ha
)) == NULL
) {
286 goto qc_host_busy_lock
;
294 CMD_SP(cmd
) = (void *)sp
;
295 cmd
->scsi_done
= done
;
297 rval
= qla2x00_start_scsi(sp
);
298 if (rval
!= QLA_SUCCESS
)
299 goto qc_host_busy_free_sp
;
301 /* Manage unprocessed RIO/ZIO commands in response queue. */
302 if (ha
->flags
.online
&& ha
->flags
.process_response_queue
&&
303 ha
->response_ring_ptr
->signature
!= RESPONSE_PROCESSED
) {
306 spin_lock_irqsave(&ha
->hardware_lock
, flags
);
307 qla2x00_process_response_queue(ha
);
308 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
311 spin_lock_irq(ha
->host
->host_lock
);
315 qc_host_busy_free_sp
:
316 qla2x00_sp_free_dma(ha
, sp
);
318 mempool_free(sp
, ha
->srb_mempool
);
321 spin_lock_irq(ha
->host
->host_lock
);
324 return SCSI_MLQUEUE_HOST_BUSY
;
333 * qla2x00_eh_wait_on_command
334 * Waits for the command to be returned by the Firmware for some
338 * ha = actual ha whose done queue will contain the command
339 * returned by firmware.
340 * cmd = Scsi Command to wait on.
341 * flag = Abort/Reset(Bus or Device Reset)
348 qla2x00_eh_wait_on_command(scsi_qla_host_t
*ha
, struct scsi_cmnd
*cmd
)
350 #define ABORT_POLLING_PERIOD HZ
351 #define ABORT_WAIT_ITER ((10 * HZ) / (ABORT_POLLING_PERIOD))
352 unsigned long wait_iter
= ABORT_WAIT_ITER
;
353 int ret
= QLA_SUCCESS
;
355 while (CMD_SP(cmd
)) {
356 set_current_state(TASK_UNINTERRUPTIBLE
);
357 schedule_timeout(ABORT_POLLING_PERIOD
);
363 ret
= QLA_FUNCTION_FAILED
;
369 * qla2x00_wait_for_hba_online
370 * Wait till the HBA is online after going through
371 * <= MAX_RETRIES_OF_ISP_ABORT or
372 * finally HBA is disabled ie marked offline
375 * ha - pointer to host adapter structure
378 * Does context switching-Release SPIN_LOCK
379 * (if any) before calling this routine.
382 * Success (Adapter is online) : 0
383 * Failed (Adapter is offline/disabled) : 1
386 qla2x00_wait_for_hba_online(scsi_qla_host_t
*ha
)
389 unsigned long wait_online
;
391 wait_online
= jiffies
+ (MAX_LOOP_TIMEOUT
* HZ
);
392 while (((test_bit(ISP_ABORT_NEEDED
, &ha
->dpc_flags
)) ||
393 test_bit(ABORT_ISP_ACTIVE
, &ha
->dpc_flags
) ||
394 test_bit(ISP_ABORT_RETRY
, &ha
->dpc_flags
) ||
395 ha
->dpc_active
) && time_before(jiffies
, wait_online
)) {
399 if (ha
->flags
.online
)
400 return_status
= QLA_SUCCESS
;
402 return_status
= QLA_FUNCTION_FAILED
;
404 DEBUG2(printk("%s return_status=%d\n",__func__
,return_status
));
406 return (return_status
);
410 * qla2x00_wait_for_loop_ready
411 * Wait for MAX_LOOP_TIMEOUT(5 min) value for loop
412 * to be in LOOP_READY state.
414 * ha - pointer to host adapter structure
417 * Does context switching-Release SPIN_LOCK
418 * (if any) before calling this routine.
422 * Success (LOOP_READY) : 0
423 * Failed (LOOP_NOT_READY) : 1
426 qla2x00_wait_for_loop_ready(scsi_qla_host_t
*ha
)
428 int return_status
= QLA_SUCCESS
;
429 unsigned long loop_timeout
;
431 /* wait for 5 min at the max for loop to be ready */
432 loop_timeout
= jiffies
+ (MAX_LOOP_TIMEOUT
* HZ
);
434 while ((!atomic_read(&ha
->loop_down_timer
) &&
435 atomic_read(&ha
->loop_state
) == LOOP_DOWN
) ||
436 atomic_read(&ha
->loop_state
) != LOOP_READY
) {
438 if (time_after_eq(jiffies
, loop_timeout
)) {
439 return_status
= QLA_FUNCTION_FAILED
;
443 return (return_status
);
446 /**************************************************************************
450 * The abort function will abort the specified command.
453 * cmd = Linux SCSI command packet to be aborted.
456 * Either SUCCESS or FAILED.
459 **************************************************************************/
461 qla2xxx_eh_abort(struct scsi_cmnd
*cmd
)
463 scsi_qla_host_t
*ha
= to_qla_host(cmd
->device
->host
);
466 unsigned int id
, lun
;
467 unsigned long serial
;
475 id
= cmd
->device
->id
;
476 lun
= cmd
->device
->lun
;
477 serial
= cmd
->serial_number
;
479 /* Check active list for command command. */
480 spin_lock_irqsave(&ha
->hardware_lock
, flags
);
481 for (i
= 1; i
< MAX_OUTSTANDING_COMMANDS
; i
++) {
482 sp
= ha
->outstanding_cmds
[i
];
490 DEBUG2(printk("%s(%ld): aborting sp %p from RISC. pid=%ld "
491 "sp->state=%x\n", __func__
, ha
->host_no
, sp
, serial
,
493 DEBUG3(qla2x00_print_scsi_cmd(cmd
);)
495 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
496 if (qla2x00_abort_command(ha
, sp
)) {
497 DEBUG2(printk("%s(%ld): abort_command "
498 "mbx failed.\n", __func__
, ha
->host_no
));
500 DEBUG3(printk("%s(%ld): abort_command "
501 "mbx success.\n", __func__
, ha
->host_no
));
504 spin_lock_irqsave(&ha
->hardware_lock
, flags
);
508 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
510 /* Wait for the command to be returned. */
511 if (ret
== SUCCESS
) {
512 if (qla2x00_eh_wait_on_command(ha
, cmd
) != QLA_SUCCESS
) {
513 qla_printk(KERN_ERR
, ha
,
514 "scsi(%ld:%d:%d): Abort handler timed out -- %lx "
515 "%x.\n", ha
->host_no
, id
, lun
, serial
, ret
);
519 qla_printk(KERN_INFO
, ha
,
520 "scsi(%ld:%d:%d): Abort command issued -- %lx %x.\n", ha
->host_no
,
521 id
, lun
, serial
, ret
);
526 /**************************************************************************
527 * qla2x00_eh_wait_for_pending_target_commands
530 * Waits for all the commands to come back from the specified target.
533 * ha - pointer to scsi_qla_host structure.
536 * Either SUCCESS or FAILED.
539 **************************************************************************/
541 qla2x00_eh_wait_for_pending_target_commands(scsi_qla_host_t
*ha
, unsigned int t
)
546 struct scsi_cmnd
*cmd
;
552 * Waiting for all commands for the designated target in the active
555 for (cnt
= 1; cnt
< MAX_OUTSTANDING_COMMANDS
; cnt
++) {
556 spin_lock_irqsave(&ha
->hardware_lock
, flags
);
557 sp
= ha
->outstanding_cmds
[cnt
];
560 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
561 if (cmd
->device
->id
== t
) {
562 if (!qla2x00_eh_wait_on_command(ha
, cmd
)) {
568 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
575 /**************************************************************************
576 * qla2xxx_eh_device_reset
579 * The device reset function will reset the target and abort any
580 * executing commands.
582 * NOTE: The use of SP is undefined within this context. Do *NOT*
583 * attempt to use this value, even if you determine it is
587 * cmd = Linux SCSI command packet of the command that cause the
591 * SUCCESS/FAILURE (defined as macro in scsi.h).
593 **************************************************************************/
595 qla2xxx_eh_device_reset(struct scsi_cmnd
*cmd
)
597 scsi_qla_host_t
*ha
= to_qla_host(cmd
->device
->host
);
598 fc_port_t
*fcport
= (struct fc_port
*) cmd
->device
->hostdata
;
601 unsigned int id
, lun
;
602 unsigned long serial
;
606 id
= cmd
->device
->id
;
607 lun
= cmd
->device
->lun
;
608 serial
= cmd
->serial_number
;
610 sp
= (srb_t
*) CMD_SP(cmd
);
614 qla_printk(KERN_INFO
, ha
,
615 "scsi(%ld:%d:%d): DEVICE RESET ISSUED.\n", ha
->host_no
, id
, lun
);
617 if (qla2x00_wait_for_hba_online(ha
) != QLA_SUCCESS
)
618 goto eh_dev_reset_done
;
620 if (qla2x00_wait_for_loop_ready(ha
) == QLA_SUCCESS
) {
621 if (qla2x00_device_reset(ha
, fcport
) == 0)
624 #if defined(LOGOUT_AFTER_DEVICE_RESET)
625 if (ret
== SUCCESS
) {
626 if (fcport
->flags
& FC_FABRIC_DEVICE
) {
627 qla2x00_fabric_logout(ha
, fcport
->loop_id
);
628 qla2x00_mark_device_lost(ha
, fcport
);
633 DEBUG2(printk(KERN_INFO
634 "%s failed: loop not ready\n",__func__
);)
638 DEBUG3(printk("%s(%ld): device reset failed\n",
639 __func__
, ha
->host_no
));
640 qla_printk(KERN_INFO
, ha
, "%s: device reset failed\n",
643 goto eh_dev_reset_done
;
647 * If we are coming down the EH path, wait for all commands to
648 * complete for the device.
650 if (cmd
->device
->host
->eh_active
) {
651 if (qla2x00_eh_wait_for_pending_target_commands(ha
, id
))
655 DEBUG3(printk("%s(%ld): failed while waiting for "
656 "commands\n", __func__
, ha
->host_no
));
657 qla_printk(KERN_INFO
, ha
,
658 "%s: failed while waiting for commands\n",
661 goto eh_dev_reset_done
;
665 qla_printk(KERN_INFO
, ha
,
666 "scsi(%ld:%d:%d): DEVICE RESET SUCCEEDED.\n", ha
->host_no
, id
, lun
);
672 /**************************************************************************
673 * qla2x00_eh_wait_for_pending_commands
676 * Waits for all the commands to come back from the specified host.
679 * ha - pointer to scsi_qla_host structure.
686 **************************************************************************/
688 qla2x00_eh_wait_for_pending_commands(scsi_qla_host_t
*ha
)
693 struct scsi_cmnd
*cmd
;
699 * Waiting for all commands for the designated target in the active
702 for (cnt
= 1; cnt
< MAX_OUTSTANDING_COMMANDS
; cnt
++) {
703 spin_lock_irqsave(&ha
->hardware_lock
, flags
);
704 sp
= ha
->outstanding_cmds
[cnt
];
707 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
708 status
= qla2x00_eh_wait_on_command(ha
, cmd
);
713 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
720 /**************************************************************************
721 * qla2xxx_eh_bus_reset
724 * The bus reset function will reset the bus and abort any executing
728 * cmd = Linux SCSI command packet of the command that cause the
732 * SUCCESS/FAILURE (defined as macro in scsi.h).
734 **************************************************************************/
736 qla2xxx_eh_bus_reset(struct scsi_cmnd
*cmd
)
738 scsi_qla_host_t
*ha
= to_qla_host(cmd
->device
->host
);
739 fc_port_t
*fcport
= (struct fc_port
*) cmd
->device
->hostdata
;
742 unsigned int id
, lun
;
743 unsigned long serial
;
747 id
= cmd
->device
->id
;
748 lun
= cmd
->device
->lun
;
749 serial
= cmd
->serial_number
;
751 sp
= (srb_t
*) CMD_SP(cmd
);
755 qla_printk(KERN_INFO
, ha
,
756 "scsi(%ld:%d:%d): LOOP RESET ISSUED.\n", ha
->host_no
, id
, lun
);
758 if (qla2x00_wait_for_hba_online(ha
) != QLA_SUCCESS
) {
759 DEBUG2(printk("%s failed:board disabled\n",__func__
));
760 goto eh_bus_reset_done
;
763 if (qla2x00_wait_for_loop_ready(ha
) == QLA_SUCCESS
) {
764 if (qla2x00_loop_reset(ha
) == QLA_SUCCESS
)
768 goto eh_bus_reset_done
;
770 /* Waiting for our command in done_queue to be returned to OS.*/
771 if (cmd
->device
->host
->eh_active
)
772 if (!qla2x00_eh_wait_for_pending_commands(ha
))
776 qla_printk(KERN_INFO
, ha
, "%s: reset %s\n", __func__
,
777 (ret
== FAILED
) ? "failed" : "succeded");
782 /**************************************************************************
783 * qla2xxx_eh_host_reset
786 * The reset function will reset the Adapter.
789 * cmd = Linux SCSI command packet of the command that cause the
793 * Either SUCCESS or FAILED.
796 **************************************************************************/
798 qla2xxx_eh_host_reset(struct scsi_cmnd
*cmd
)
800 scsi_qla_host_t
*ha
= to_qla_host(cmd
->device
->host
);
801 fc_port_t
*fcport
= (struct fc_port
*) cmd
->device
->hostdata
;
804 unsigned int id
, lun
;
805 unsigned long serial
;
809 id
= cmd
->device
->id
;
810 lun
= cmd
->device
->lun
;
811 serial
= cmd
->serial_number
;
813 sp
= (srb_t
*) CMD_SP(cmd
);
817 qla_printk(KERN_INFO
, ha
,
818 "scsi(%ld:%d:%d): ADAPTER RESET ISSUED.\n", ha
->host_no
, id
, lun
);
820 if (qla2x00_wait_for_hba_online(ha
) != QLA_SUCCESS
)
821 goto eh_host_reset_lock
;
824 * Fixme-may be dpc thread is active and processing
825 * loop_resync,so wait a while for it to
826 * be completed and then issue big hammer.Otherwise
827 * it may cause I/O failure as big hammer marks the
828 * devices as lost kicking of the port_down_timer
829 * while dpc is stuck for the mailbox to complete.
831 qla2x00_wait_for_loop_ready(ha
);
832 set_bit(ABORT_ISP_ACTIVE
, &ha
->dpc_flags
);
833 if (qla2x00_abort_isp(ha
)) {
834 clear_bit(ABORT_ISP_ACTIVE
, &ha
->dpc_flags
);
835 /* failed. schedule dpc to try */
836 set_bit(ISP_ABORT_NEEDED
, &ha
->dpc_flags
);
838 if (qla2x00_wait_for_hba_online(ha
) != QLA_SUCCESS
)
839 goto eh_host_reset_lock
;
841 clear_bit(ABORT_ISP_ACTIVE
, &ha
->dpc_flags
);
843 /* Waiting for our command in done_queue to be returned to OS.*/
844 if (qla2x00_eh_wait_for_pending_commands(ha
))
848 qla_printk(KERN_INFO
, ha
, "%s: reset %s\n", __func__
,
849 (ret
== FAILED
) ? "failed" : "succeded");
859 * ha = adapter block pointer.
865 qla2x00_loop_reset(scsi_qla_host_t
*ha
)
867 int status
= QLA_SUCCESS
;
868 struct fc_port
*fcport
;
870 if (ha
->flags
.enable_lip_reset
) {
871 status
= qla2x00_lip_reset(ha
);
874 if (status
== QLA_SUCCESS
&& ha
->flags
.enable_target_reset
) {
875 list_for_each_entry(fcport
, &ha
->fcports
, list
) {
876 if (fcport
->port_type
!= FCT_TARGET
)
879 status
= qla2x00_target_reset(ha
, fcport
);
880 if (status
!= QLA_SUCCESS
)
885 if (status
== QLA_SUCCESS
&&
886 ((!ha
->flags
.enable_target_reset
&&
887 !ha
->flags
.enable_lip_reset
) ||
888 ha
->flags
.enable_lip_full_login
)) {
890 status
= qla2x00_full_login_lip(ha
);
893 /* Issue marker command only when we are going to start the I/O */
894 ha
->marker_needed
= 1;
898 DEBUG2_3(printk("%s(%ld): **** FAILED ****\n",
903 DEBUG3(printk("%s(%ld): exiting normally.\n",
912 * qla2x00_device_reset
913 * Issue bus device reset message to the target.
916 * ha = adapter block pointer.
918 * TARGET_QUEUE_LOCK must be released.
919 * ADAPTER_STATE_LOCK must be released.
925 qla2x00_device_reset(scsi_qla_host_t
*ha
, fc_port_t
*reset_fcport
)
927 /* Abort Target command will clear Reservation */
928 return qla2x00_abort_target(reset_fcport
);
932 qla2xxx_slave_alloc(struct scsi_device
*sdev
)
934 scsi_qla_host_t
*ha
= to_qla_host(sdev
->host
);
935 struct fc_rport
*rport
= starget_to_rport(scsi_target(sdev
));
943 list_for_each_entry(fcport
, &ha
->fcports
, list
) {
944 if (rport
->port_name
==
945 be64_to_cpu(*(uint64_t *)fcport
->port_name
)) {
953 sdev
->hostdata
= fcport
;
959 qla2xxx_slave_configure(struct scsi_device
*sdev
)
961 scsi_qla_host_t
*ha
= to_qla_host(sdev
->host
);
962 struct fc_rport
*rport
= starget_to_rport(sdev
->sdev_target
);
964 if (sdev
->tagged_supported
)
965 scsi_activate_tcq(sdev
, 32);
967 scsi_deactivate_tcq(sdev
, 32);
969 rport
->dev_loss_tmo
= ha
->port_down_retry_count
+ 5;
975 qla2xxx_slave_destroy(struct scsi_device
*sdev
)
977 sdev
->hostdata
= NULL
;
981 * qla2x00_config_dma_addressing() - Configure OS DMA addressing method.
984 * At exit, the @ha's flags.enable_64bit_addressing set to indicated
985 * supported addressing method.
988 qla2x00_config_dma_addressing(scsi_qla_host_t
*ha
)
990 /* Assume 32bit DMA address */
991 ha
->flags
.enable_64bit_addressing
= 0;
992 ha
->calc_request_entries
= qla2x00_calc_iocbs_32
;
993 ha
->build_scsi_iocbs
= qla2x00_build_scsi_iocbs_32
;
996 * Given the two variants pci_set_dma_mask(), allow the compiler to
997 * assist in setting the proper dma mask.
999 if (sizeof(dma_addr_t
) > 4) {
1000 if (pci_set_dma_mask(ha
->pdev
, DMA_64BIT_MASK
) == 0) {
1001 ha
->flags
.enable_64bit_addressing
= 1;
1002 ha
->calc_request_entries
= qla2x00_calc_iocbs_64
;
1003 ha
->build_scsi_iocbs
= qla2x00_build_scsi_iocbs_64
;
1005 if (pci_set_consistent_dma_mask(ha
->pdev
,
1007 qla_printk(KERN_DEBUG
, ha
,
1008 "Failed to set 64 bit PCI consistent mask; "
1010 pci_set_consistent_dma_mask(ha
->pdev
,
1014 qla_printk(KERN_DEBUG
, ha
,
1015 "Failed to set 64 bit PCI DMA mask, falling back "
1016 "to 32 bit MASK.\n");
1017 pci_set_dma_mask(ha
->pdev
, DMA_32BIT_MASK
);
1020 pci_set_dma_mask(ha
->pdev
, DMA_32BIT_MASK
);
1025 qla2x00_iospace_config(scsi_qla_host_t
*ha
)
1027 unsigned long pio
, pio_len
, pio_flags
;
1028 unsigned long mmio
, mmio_len
, mmio_flags
;
1030 /* We only need PIO for Flash operations on ISP2312 v2 chips. */
1031 pio
= pci_resource_start(ha
->pdev
, 0);
1032 pio_len
= pci_resource_len(ha
->pdev
, 0);
1033 pio_flags
= pci_resource_flags(ha
->pdev
, 0);
1034 if (pio_flags
& IORESOURCE_IO
) {
1035 if (pio_len
< MIN_IOBASE_LEN
) {
1036 qla_printk(KERN_WARNING
, ha
,
1037 "Invalid PCI I/O region size (%s)...\n",
1038 pci_name(ha
->pdev
));
1042 qla_printk(KERN_WARNING
, ha
,
1043 "region #0 not a PIO resource (%s)...\n",
1044 pci_name(ha
->pdev
));
1048 /* Use MMIO operations for all accesses. */
1049 mmio
= pci_resource_start(ha
->pdev
, 1);
1050 mmio_len
= pci_resource_len(ha
->pdev
, 1);
1051 mmio_flags
= pci_resource_flags(ha
->pdev
, 1);
1053 if (!(mmio_flags
& IORESOURCE_MEM
)) {
1054 qla_printk(KERN_ERR
, ha
,
1055 "region #0 not an MMIO resource (%s), aborting\n",
1056 pci_name(ha
->pdev
));
1057 goto iospace_error_exit
;
1059 if (mmio_len
< MIN_IOBASE_LEN
) {
1060 qla_printk(KERN_ERR
, ha
,
1061 "Invalid PCI mem region size (%s), aborting\n",
1062 pci_name(ha
->pdev
));
1063 goto iospace_error_exit
;
1066 if (pci_request_regions(ha
->pdev
, ha
->brd_info
->drv_name
)) {
1067 qla_printk(KERN_WARNING
, ha
,
1068 "Failed to reserve PIO/MMIO regions (%s)\n",
1069 pci_name(ha
->pdev
));
1071 goto iospace_error_exit
;
1074 ha
->pio_address
= pio
;
1075 ha
->pio_length
= pio_len
;
1076 ha
->iobase
= ioremap(mmio
, MIN_IOBASE_LEN
);
1078 qla_printk(KERN_ERR
, ha
,
1079 "cannot remap MMIO (%s), aborting\n", pci_name(ha
->pdev
));
1081 goto iospace_error_exit
;
1091 * PCI driver interface
1093 int qla2x00_probe_one(struct pci_dev
*pdev
, struct qla_board_info
*brd_info
)
1096 device_reg_t __iomem
*reg
;
1097 struct Scsi_Host
*host
;
1098 scsi_qla_host_t
*ha
;
1099 unsigned long flags
= 0;
1100 unsigned long wait_switch
= 0;
1105 if (pci_enable_device(pdev
))
1108 host
= scsi_host_alloc(&qla2x00_driver_template
,
1109 sizeof(scsi_qla_host_t
));
1112 "qla2xxx: Couldn't allocate host from scsi layer!\n");
1113 goto probe_disable_device
;
1116 /* Clear our data area */
1117 ha
= (scsi_qla_host_t
*)host
->hostdata
;
1118 memset(ha
, 0, sizeof(scsi_qla_host_t
));
1122 ha
->host_no
= host
->host_no
;
1123 ha
->brd_info
= brd_info
;
1124 sprintf(ha
->host_str
, "%s_%ld", ha
->brd_info
->drv_name
, ha
->host_no
);
1126 /* Configure PCI I/O space */
1127 ret
= qla2x00_iospace_config(ha
);
1131 /* Sanitize the information from PCI BIOS. */
1132 host
->irq
= pdev
->irq
;
1134 qla_printk(KERN_INFO
, ha
,
1135 "Found an %s, irq %d, iobase 0x%p\n", ha
->brd_info
->isp_name
,
1136 host
->irq
, ha
->iobase
);
1138 spin_lock_init(&ha
->hardware_lock
);
1140 ha
->prev_topology
= 0;
1141 ha
->ports
= MAX_BUSES
;
1143 if (IS_QLA2100(ha
)) {
1144 host
->max_id
= MAX_TARGETS_2100
;
1145 ha
->mbx_count
= MAILBOX_REGISTER_COUNT_2100
;
1146 ha
->request_q_length
= REQUEST_ENTRY_CNT_2100
;
1147 ha
->response_q_length
= RESPONSE_ENTRY_CNT_2100
;
1148 ha
->last_loop_id
= SNS_LAST_LOOP_ID_2100
;
1149 host
->sg_tablesize
= 32;
1150 } else if (IS_QLA2200(ha
)) {
1151 host
->max_id
= MAX_TARGETS_2200
;
1152 ha
->mbx_count
= MAILBOX_REGISTER_COUNT
;
1153 ha
->request_q_length
= REQUEST_ENTRY_CNT_2200
;
1154 ha
->response_q_length
= RESPONSE_ENTRY_CNT_2100
;
1155 ha
->last_loop_id
= SNS_LAST_LOOP_ID_2100
;
1156 } else /*if (IS_QLA2300(ha))*/ {
1157 host
->max_id
= MAX_TARGETS_2200
;
1158 ha
->mbx_count
= MAILBOX_REGISTER_COUNT
;
1159 ha
->request_q_length
= REQUEST_ENTRY_CNT_2200
;
1160 ha
->response_q_length
= RESPONSE_ENTRY_CNT_2300
;
1161 ha
->last_loop_id
= SNS_LAST_LOOP_ID_2300
;
1163 host
->can_queue
= ha
->request_q_length
+ 128;
1165 /* load the F/W, read paramaters, and init the H/W */
1166 ha
->instance
= num_hosts
;
1168 init_MUTEX(&ha
->mbx_cmd_sem
);
1169 init_MUTEX_LOCKED(&ha
->mbx_intr_sem
);
1171 INIT_LIST_HEAD(&ha
->list
);
1172 INIT_LIST_HEAD(&ha
->fcports
);
1173 INIT_LIST_HEAD(&ha
->rscn_fcports
);
1176 * These locks are used to prevent more than one CPU
1177 * from modifying the queue at the same time. The
1178 * higher level "host_lock" will reduce most
1179 * contention for these locks.
1181 spin_lock_init(&ha
->mbx_reg_lock
);
1184 init_completion(&ha
->dpc_inited
);
1185 init_completion(&ha
->dpc_exited
);
1187 qla2x00_config_dma_addressing(ha
);
1188 if (qla2x00_mem_alloc(ha
)) {
1189 qla_printk(KERN_WARNING
, ha
,
1190 "[ERROR] Failed to allocate memory for adapter\n");
1196 if (qla2x00_initialize_adapter(ha
) &&
1197 !(ha
->device_flags
& DFLG_NO_CABLE
)) {
1199 qla_printk(KERN_WARNING
, ha
,
1200 "Failed to initialize adapter\n");
1202 DEBUG2(printk("scsi(%ld): Failed to initialize adapter - "
1203 "Adapter flags %x.\n",
1204 ha
->host_no
, ha
->device_flags
));
1211 * Startup the kernel thread for this host adapter
1213 ha
->dpc_should_die
= 0;
1214 ha
->dpc_pid
= kernel_thread(qla2x00_do_dpc
, ha
, 0);
1215 if (ha
->dpc_pid
< 0) {
1216 qla_printk(KERN_WARNING
, ha
,
1217 "Unable to start DPC thread!\n");
1222 wait_for_completion(&ha
->dpc_inited
);
1224 host
->this_id
= 255;
1225 host
->cmd_per_lun
= 3;
1226 host
->unique_id
= ha
->instance
;
1227 host
->max_cmd_len
= MAX_CMDSZ
;
1228 host
->max_channel
= ha
->ports
- 1;
1229 host
->max_lun
= MAX_LUNS
;
1230 host
->transportt
= qla2xxx_transport_template
;
1232 if (IS_QLA2100(ha
) || IS_QLA2200(ha
))
1233 ret
= request_irq(host
->irq
, qla2100_intr_handler
,
1234 SA_INTERRUPT
|SA_SHIRQ
, ha
->brd_info
->drv_name
, ha
);
1236 ret
= request_irq(host
->irq
, qla2300_intr_handler
,
1237 SA_INTERRUPT
|SA_SHIRQ
, ha
->brd_info
->drv_name
, ha
);
1239 qla_printk(KERN_WARNING
, ha
,
1240 "Failed to reserve interrupt %d already in use.\n",
1245 /* Initialized the timer */
1246 qla2x00_start_timer(ha
, qla2x00_timer
, WATCH_INTERVAL
);
1248 DEBUG2(printk("DEBUG: detect hba %ld at address = %p\n",
1253 /* Disable ISP interrupts. */
1254 qla2x00_disable_intrs(ha
);
1256 /* Ensure mailbox registers are free. */
1257 spin_lock_irqsave(&ha
->hardware_lock
, flags
);
1258 WRT_REG_WORD(®
->semaphore
, 0);
1259 WRT_REG_WORD(®
->hccr
, HCCR_CLR_RISC_INT
);
1260 WRT_REG_WORD(®
->hccr
, HCCR_CLR_HOST_INT
);
1262 /* Enable proper parity */
1263 if (!IS_QLA2100(ha
) && !IS_QLA2200(ha
)) {
1266 WRT_REG_WORD(®
->hccr
, (HCCR_ENABLE_PARITY
+ 0x1));
1268 /* SRAM, Instruction RAM and GP RAM parity */
1269 WRT_REG_WORD(®
->hccr
, (HCCR_ENABLE_PARITY
+ 0x7));
1271 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
1273 /* Enable chip interrupts. */
1274 qla2x00_enable_intrs(ha
);
1278 * Wait around max loop_reset_delay secs for the devices to come
1279 * on-line. We don't want Linux scanning before we are ready.
1282 for (wait_switch
= jiffies
+ (ha
->loop_reset_delay
* HZ
);
1283 time_before(jiffies
,wait_switch
) &&
1284 !(ha
->device_flags
& (DFLG_NO_CABLE
| DFLG_FABRIC_DEVICES
))
1285 && (ha
->device_flags
& SWITCH_FOUND
) ;) {
1287 qla2x00_check_fabric_devices(ha
);
1292 pci_set_drvdata(pdev
, ha
);
1293 ha
->flags
.init_done
= 1;
1296 ret
= scsi_add_host(host
, &pdev
->dev
);
1300 qla2x00_alloc_sysfs_attr(ha
);
1302 qla2x00_init_host_attr(ha
);
1304 qla_printk(KERN_INFO
, ha
, "\n"
1305 " QLogic Fibre Channel HBA Driver: %s\n"
1307 " %s: %s @ %s hdma%c, host#=%ld, fw=%s\n", qla2x00_version_str
,
1308 ha
->model_number
, ha
->model_desc
? ha
->model_desc
: "",
1309 ha
->brd_info
->isp_name
, qla2x00_get_pci_info_str(ha
, pci_info
),
1310 pci_name(ha
->pdev
), ha
->flags
.enable_64bit_addressing
? '+': '-',
1311 ha
->host_no
, qla2x00_get_fw_version_str(ha
, fw_str
));
1313 /* Go with fc_rport registration. */
1314 list_for_each_entry(fcport
, &ha
->fcports
, list
)
1315 qla2x00_reg_remote_port(ha
, fcport
);
1320 fc_remove_host(ha
->host
);
1322 qla2x00_free_device(ha
);
1324 scsi_host_put(host
);
1326 probe_disable_device
:
1327 pci_disable_device(pdev
);
1332 EXPORT_SYMBOL_GPL(qla2x00_probe_one
);
1334 void qla2x00_remove_one(struct pci_dev
*pdev
)
1336 scsi_qla_host_t
*ha
;
1338 ha
= pci_get_drvdata(pdev
);
1340 qla2x00_free_sysfs_attr(ha
);
1342 fc_remove_host(ha
->host
);
1344 scsi_remove_host(ha
->host
);
1346 qla2x00_free_device(ha
);
1348 scsi_host_put(ha
->host
);
1350 pci_set_drvdata(pdev
, NULL
);
1352 EXPORT_SYMBOL_GPL(qla2x00_remove_one
);
1355 qla2x00_free_device(scsi_qla_host_t
*ha
)
1359 /* Abort any outstanding IO descriptors. */
1360 if (!IS_QLA2100(ha
) && !IS_QLA2200(ha
))
1361 qla2x00_cancel_io_descriptors(ha
);
1363 /* turn-off interrupts on the card */
1364 if (ha
->interrupts_on
)
1365 qla2x00_disable_intrs(ha
);
1368 if (ha
->timer_active
)
1369 qla2x00_stop_timer(ha
);
1371 /* Kill the kernel thread for this host */
1372 if (ha
->dpc_pid
>= 0) {
1373 ha
->dpc_should_die
= 1;
1375 ret
= kill_proc(ha
->dpc_pid
, SIGHUP
, 1);
1377 qla_printk(KERN_ERR
, ha
,
1378 "Unable to signal DPC thread -- (%d)\n", ret
);
1380 /* TODO: SOMETHING MORE??? */
1382 wait_for_completion(&ha
->dpc_exited
);
1386 qla2x00_mem_free(ha
);
1389 ha
->flags
.online
= 0;
1391 /* Detach interrupts */
1393 free_irq(ha
->pdev
->irq
, ha
);
1395 /* release io space registers */
1397 iounmap(ha
->iobase
);
1398 pci_release_regions(ha
->pdev
);
1400 pci_disable_device(ha
->pdev
);
1404 * qla2x00_mark_device_lost Updates fcport state when device goes offline.
1406 * Input: ha = adapter block pointer. fcport = port structure pointer.
1412 void qla2x00_mark_device_lost(scsi_qla_host_t
*ha
, fc_port_t
*fcport
,
1415 if (atomic_read(&fcport
->state
) == FCS_ONLINE
&& fcport
->rport
)
1416 fc_remote_port_block(fcport
->rport
);
1418 * We may need to retry the login, so don't change the state of the
1419 * port but do the retries.
1421 if (atomic_read(&fcport
->state
) != FCS_DEVICE_DEAD
)
1422 atomic_set(&fcport
->state
, FCS_DEVICE_LOST
);
1427 if (fcport
->login_retry
== 0) {
1428 fcport
->login_retry
= ha
->login_retry_count
;
1429 set_bit(RELOGIN_NEEDED
, &ha
->dpc_flags
);
1431 DEBUG(printk("scsi(%ld): Port login retry: "
1432 "%02x%02x%02x%02x%02x%02x%02x%02x, "
1433 "id = 0x%04x retry cnt=%d\n",
1435 fcport
->port_name
[0],
1436 fcport
->port_name
[1],
1437 fcport
->port_name
[2],
1438 fcport
->port_name
[3],
1439 fcport
->port_name
[4],
1440 fcport
->port_name
[5],
1441 fcport
->port_name
[6],
1442 fcport
->port_name
[7],
1444 fcport
->login_retry
));
1449 * qla2x00_mark_all_devices_lost
1450 * Updates fcport state when device goes offline.
1453 * ha = adapter block pointer.
1454 * fcport = port structure pointer.
1462 qla2x00_mark_all_devices_lost(scsi_qla_host_t
*ha
)
1466 list_for_each_entry(fcport
, &ha
->fcports
, list
) {
1467 if (fcport
->port_type
!= FCT_TARGET
)
1471 * No point in marking the device as lost, if the device is
1474 if (atomic_read(&fcport
->state
) == FCS_DEVICE_DEAD
)
1476 if (atomic_read(&fcport
->state
) == FCS_ONLINE
&& fcport
->rport
)
1477 fc_remote_port_block(fcport
->rport
);
1478 atomic_set(&fcport
->state
, FCS_DEVICE_LOST
);
1484 * Allocates adapter memory.
1491 qla2x00_mem_alloc(scsi_qla_host_t
*ha
)
1499 * This will loop only once if everything goes well, else some
1500 * number of retries will be performed to get around a kernel
1501 * bug where available mem is not allocated until after a
1502 * little delay and a retry.
1504 ha
->request_ring
= dma_alloc_coherent(&ha
->pdev
->dev
,
1505 (ha
->request_q_length
+ 1) * sizeof(request_t
),
1506 &ha
->request_dma
, GFP_KERNEL
);
1507 if (ha
->request_ring
== NULL
) {
1508 qla_printk(KERN_WARNING
, ha
,
1509 "Memory Allocation failed - request_ring\n");
1511 qla2x00_mem_free(ha
);
1517 ha
->response_ring
= dma_alloc_coherent(&ha
->pdev
->dev
,
1518 (ha
->response_q_length
+ 1) * sizeof(response_t
),
1519 &ha
->response_dma
, GFP_KERNEL
);
1520 if (ha
->response_ring
== NULL
) {
1521 qla_printk(KERN_WARNING
, ha
,
1522 "Memory Allocation failed - response_ring\n");
1524 qla2x00_mem_free(ha
);
1530 ha
->gid_list
= dma_alloc_coherent(&ha
->pdev
->dev
, GID_LIST_SIZE
,
1531 &ha
->gid_list_dma
, GFP_KERNEL
);
1532 if (ha
->gid_list
== NULL
) {
1533 qla_printk(KERN_WARNING
, ha
,
1534 "Memory Allocation failed - gid_list\n");
1536 qla2x00_mem_free(ha
);
1542 ha
->rlc_rsp
= dma_alloc_coherent(&ha
->pdev
->dev
,
1543 sizeof(rpt_lun_cmd_rsp_t
), &ha
->rlc_rsp_dma
, GFP_KERNEL
);
1544 if (ha
->rlc_rsp
== NULL
) {
1545 qla_printk(KERN_WARNING
, ha
,
1546 "Memory Allocation failed - rlc");
1548 qla2x00_mem_free(ha
);
1554 snprintf(name
, sizeof(name
), "qla2xxx_%ld", ha
->host_no
);
1555 ha
->s_dma_pool
= dma_pool_create(name
, &ha
->pdev
->dev
,
1556 DMA_POOL_SIZE
, 8, 0);
1557 if (ha
->s_dma_pool
== NULL
) {
1558 qla_printk(KERN_WARNING
, ha
,
1559 "Memory Allocation failed - s_dma_pool\n");
1561 qla2x00_mem_free(ha
);
1567 /* get consistent memory allocated for init control block */
1568 ha
->init_cb
= dma_pool_alloc(ha
->s_dma_pool
, GFP_KERNEL
,
1570 if (ha
->init_cb
== NULL
) {
1571 qla_printk(KERN_WARNING
, ha
,
1572 "Memory Allocation failed - init_cb\n");
1574 qla2x00_mem_free(ha
);
1579 memset(ha
->init_cb
, 0, sizeof(init_cb_t
));
1581 /* Get consistent memory allocated for Get Port Database cmd */
1582 ha
->iodesc_pd
= dma_pool_alloc(ha
->s_dma_pool
, GFP_KERNEL
,
1583 &ha
->iodesc_pd_dma
);
1584 if (ha
->iodesc_pd
== NULL
) {
1586 qla_printk(KERN_WARNING
, ha
,
1587 "Memory Allocation failed - iodesc_pd\n");
1589 qla2x00_mem_free(ha
);
1594 memset(ha
->iodesc_pd
, 0, PORT_DATABASE_SIZE
);
1596 /* Allocate ioctl related memory. */
1597 if (qla2x00_alloc_ioctl_mem(ha
)) {
1598 qla_printk(KERN_WARNING
, ha
,
1599 "Memory Allocation failed - ioctl_mem\n");
1601 qla2x00_mem_free(ha
);
1607 if (qla2x00_allocate_sp_pool(ha
)) {
1608 qla_printk(KERN_WARNING
, ha
,
1609 "Memory Allocation failed - "
1610 "qla2x00_allocate_sp_pool()\n");
1612 qla2x00_mem_free(ha
);
1618 /* Allocate memory for SNS commands */
1619 if (IS_QLA2100(ha
) || IS_QLA2200(ha
)) {
1620 /* Get consistent memory allocated for SNS commands */
1621 ha
->sns_cmd
= dma_alloc_coherent(&ha
->pdev
->dev
,
1622 sizeof(struct sns_cmd_pkt
), &ha
->sns_cmd_dma
,
1624 if (ha
->sns_cmd
== NULL
) {
1626 qla_printk(KERN_WARNING
, ha
,
1627 "Memory Allocation failed - sns_cmd\n");
1629 qla2x00_mem_free(ha
);
1634 memset(ha
->sns_cmd
, 0, sizeof(struct sns_cmd_pkt
));
1636 /* Get consistent memory allocated for MS IOCB */
1637 ha
->ms_iocb
= dma_pool_alloc(ha
->s_dma_pool
, GFP_KERNEL
,
1639 if (ha
->ms_iocb
== NULL
) {
1641 qla_printk(KERN_WARNING
, ha
,
1642 "Memory Allocation failed - ms_iocb\n");
1644 qla2x00_mem_free(ha
);
1649 memset(ha
->ms_iocb
, 0, sizeof(ms_iocb_entry_t
));
1652 * Get consistent memory allocated for CT SNS
1655 ha
->ct_sns
= dma_alloc_coherent(&ha
->pdev
->dev
,
1656 sizeof(struct ct_sns_pkt
), &ha
->ct_sns_dma
,
1658 if (ha
->ct_sns
== NULL
) {
1660 qla_printk(KERN_WARNING
, ha
,
1661 "Memory Allocation failed - ct_sns\n");
1663 qla2x00_mem_free(ha
);
1668 memset(ha
->ct_sns
, 0, sizeof(struct ct_sns_pkt
));
1671 /* Done all allocations without any error. */
1674 } while (retry
-- && status
!= 0);
1678 "%s(): **** FAILED ****\n", __func__
);
1686 * Frees all adapter allocated memory.
1689 * ha = adapter block pointer.
1692 qla2x00_mem_free(scsi_qla_host_t
*ha
)
1694 struct list_head
*fcpl
, *fcptemp
;
1696 unsigned long wtime
;/* max wait time if mbx cmd is busy. */
1700 DEBUG2(printk("%s(): ERROR invalid ha pointer.\n", __func__
));
1704 /* Make sure all other threads are stopped. */
1706 while (ha
->dpc_wait
&& wtime
) {
1707 set_current_state(TASK_INTERRUPTIBLE
);
1708 wtime
= schedule_timeout(wtime
);
1711 /* free ioctl memory */
1712 qla2x00_free_ioctl_mem(ha
);
1715 qla2x00_free_sp_pool(ha
);
1718 dma_free_coherent(&ha
->pdev
->dev
, sizeof(struct sns_cmd_pkt
),
1719 ha
->sns_cmd
, ha
->sns_cmd_dma
);
1722 dma_free_coherent(&ha
->pdev
->dev
, sizeof(struct ct_sns_pkt
),
1723 ha
->ct_sns
, ha
->ct_sns_dma
);
1726 dma_pool_free(ha
->s_dma_pool
, ha
->ms_iocb
, ha
->ms_iocb_dma
);
1729 dma_pool_free(ha
->s_dma_pool
, ha
->iodesc_pd
, ha
->iodesc_pd_dma
);
1732 dma_pool_free(ha
->s_dma_pool
, ha
->init_cb
, ha
->init_cb_dma
);
1735 dma_pool_destroy(ha
->s_dma_pool
);
1738 dma_free_coherent(&ha
->pdev
->dev
,
1739 sizeof(rpt_lun_cmd_rsp_t
), ha
->rlc_rsp
,
1743 dma_free_coherent(&ha
->pdev
->dev
, GID_LIST_SIZE
, ha
->gid_list
,
1746 if (ha
->response_ring
)
1747 dma_free_coherent(&ha
->pdev
->dev
,
1748 (ha
->response_q_length
+ 1) * sizeof(response_t
),
1749 ha
->response_ring
, ha
->response_dma
);
1751 if (ha
->request_ring
)
1752 dma_free_coherent(&ha
->pdev
->dev
,
1753 (ha
->request_q_length
+ 1) * sizeof(request_t
),
1754 ha
->request_ring
, ha
->request_dma
);
1757 ha
->sns_cmd_dma
= 0;
1761 ha
->ms_iocb_dma
= 0;
1762 ha
->iodesc_pd
= NULL
;
1763 ha
->iodesc_pd_dma
= 0;
1765 ha
->init_cb_dma
= 0;
1767 ha
->s_dma_pool
= NULL
;
1770 ha
->rlc_rsp_dma
= 0;
1771 ha
->gid_list
= NULL
;
1772 ha
->gid_list_dma
= 0;
1774 ha
->response_ring
= NULL
;
1775 ha
->response_dma
= 0;
1776 ha
->request_ring
= NULL
;
1777 ha
->request_dma
= 0;
1779 list_for_each_safe(fcpl
, fcptemp
, &ha
->fcports
) {
1780 fcport
= list_entry(fcpl
, fc_port_t
, list
);
1783 list_del_init(&fcport
->list
);
1786 INIT_LIST_HEAD(&ha
->fcports
);
1789 free_pages((unsigned long)ha
->fw_dump
, ha
->fw_dump_order
);
1791 if (ha
->fw_dump_buffer
)
1792 vfree(ha
->fw_dump_buffer
);
1795 ha
->fw_dump_reading
= 0;
1796 ha
->fw_dump_buffer
= NULL
;
1800 * qla2x00_allocate_sp_pool
1801 * This routine is called during initialization to allocate
1802 * memory for local srb_t.
1805 * ha = adapter block pointer.
1810 * Note: Sets the ref_count for non Null sp to one.
1813 qla2x00_allocate_sp_pool(scsi_qla_host_t
*ha
)
1818 ha
->srb_mempool
= mempool_create(SRB_MIN_REQ
, mempool_alloc_slab
,
1819 mempool_free_slab
, srb_cachep
);
1820 if (ha
->srb_mempool
== NULL
) {
1821 qla_printk(KERN_INFO
, ha
, "Unable to allocate SRB mempool.\n");
1822 rval
= QLA_FUNCTION_FAILED
;
1828 * This routine frees all adapter allocated memory.
1832 qla2x00_free_sp_pool( scsi_qla_host_t
*ha
)
1834 if (ha
->srb_mempool
) {
1835 mempool_destroy(ha
->srb_mempool
);
1836 ha
->srb_mempool
= NULL
;
1840 /**************************************************************************
1842 * This kernel thread is a task that is schedule by the interrupt handler
1843 * to perform the background processing for interrupts.
1846 * This task always run in the context of a kernel thread. It
1847 * is kick-off by the driver's detect code and starts up
1848 * up one per adapter. It immediately goes to sleep and waits for
1849 * some fibre event. When either the interrupt handler or
1850 * the timer routine detects a event it will one of the task
1851 * bits then wake us up.
1852 **************************************************************************/
1854 qla2x00_do_dpc(void *data
)
1856 DECLARE_MUTEX_LOCKED(sem
);
1857 scsi_qla_host_t
*ha
;
1860 uint16_t next_loopid
;
1862 ha
= (scsi_qla_host_t
*)data
;
1866 daemonize("%s_dpc", ha
->host_str
);
1867 allow_signal(SIGHUP
);
1869 ha
->dpc_wait
= &sem
;
1871 set_user_nice(current
, -20);
1875 complete(&ha
->dpc_inited
);
1878 DEBUG3(printk("qla2x00: DPC handler sleeping\n"));
1880 if (down_interruptible(&sem
))
1883 if (ha
->dpc_should_die
)
1886 DEBUG3(printk("qla2x00: DPC handler waking up\n"));
1888 /* Initialization not yet finished. Don't do anything yet. */
1889 if (!ha
->flags
.init_done
|| ha
->dpc_active
)
1892 DEBUG3(printk("scsi(%ld): DPC handler\n", ha
->host_no
));
1896 if (ha
->flags
.mbox_busy
) {
1901 if (test_and_clear_bit(ISP_ABORT_NEEDED
, &ha
->dpc_flags
)) {
1903 DEBUG(printk("scsi(%ld): dpc: sched "
1904 "qla2x00_abort_isp ha = %p\n",
1906 if (!(test_and_set_bit(ABORT_ISP_ACTIVE
,
1909 if (qla2x00_abort_isp(ha
)) {
1910 /* failed. retry later */
1911 set_bit(ISP_ABORT_NEEDED
,
1914 clear_bit(ABORT_ISP_ACTIVE
, &ha
->dpc_flags
);
1916 DEBUG(printk("scsi(%ld): dpc: qla2x00_abort_isp end\n",
1920 if (test_and_clear_bit(RESET_MARKER_NEEDED
, &ha
->dpc_flags
) &&
1921 (!(test_and_set_bit(RESET_ACTIVE
, &ha
->dpc_flags
)))) {
1923 DEBUG(printk("scsi(%ld): qla2x00_reset_marker()\n",
1926 qla2x00_rst_aen(ha
);
1927 clear_bit(RESET_ACTIVE
, &ha
->dpc_flags
);
1930 /* Retry each device up to login retry count */
1931 if ((test_and_clear_bit(RELOGIN_NEEDED
, &ha
->dpc_flags
)) &&
1932 !test_bit(LOOP_RESYNC_NEEDED
, &ha
->dpc_flags
) &&
1933 atomic_read(&ha
->loop_state
) != LOOP_DOWN
) {
1935 DEBUG(printk("scsi(%ld): qla2x00_port_login()\n",
1939 list_for_each_entry(fcport
, &ha
->fcports
, list
) {
1940 if (fcport
->port_type
!= FCT_TARGET
)
1944 * If the port is not ONLINE then try to login
1945 * to it if we haven't run out of retries.
1947 if (atomic_read(&fcport
->state
) != FCS_ONLINE
&&
1948 fcport
->login_retry
) {
1950 fcport
->login_retry
--;
1951 if (fcport
->flags
& FCF_FABRIC_DEVICE
) {
1954 qla2x00_fabric_logout(
1957 status
= qla2x00_fabric_login(
1958 ha
, fcport
, &next_loopid
);
1961 qla2x00_local_device_login(
1962 ha
, fcport
->loop_id
);
1964 if (status
== QLA_SUCCESS
) {
1965 fcport
->old_loop_id
= fcport
->loop_id
;
1967 DEBUG(printk("scsi(%ld): port login OK: logged in ID 0x%x\n",
1968 ha
->host_no
, fcport
->loop_id
));
1970 fcport
->port_login_retry_count
=
1971 ha
->port_down_retry_count
* PORT_RETRY_TIME
;
1972 atomic_set(&fcport
->state
, FCS_ONLINE
);
1973 atomic_set(&fcport
->port_down_timer
,
1974 ha
->port_down_retry_count
* PORT_RETRY_TIME
);
1976 fcport
->login_retry
= 0;
1977 } else if (status
== 1) {
1978 set_bit(RELOGIN_NEEDED
, &ha
->dpc_flags
);
1979 /* retry the login again */
1980 DEBUG(printk("scsi(%ld): Retrying %d login again loop_id 0x%x\n",
1982 fcport
->login_retry
, fcport
->loop_id
));
1984 fcport
->login_retry
= 0;
1987 if (test_bit(LOOP_RESYNC_NEEDED
, &ha
->dpc_flags
))
1990 DEBUG(printk("scsi(%ld): qla2x00_port_login - end\n",
1994 if ((test_bit(LOGIN_RETRY_NEEDED
, &ha
->dpc_flags
)) &&
1995 atomic_read(&ha
->loop_state
) != LOOP_DOWN
) {
1997 clear_bit(LOGIN_RETRY_NEEDED
, &ha
->dpc_flags
);
1998 DEBUG(printk("scsi(%ld): qla2x00_login_retry()\n",
2001 set_bit(LOOP_RESYNC_NEEDED
, &ha
->dpc_flags
);
2003 DEBUG(printk("scsi(%ld): qla2x00_login_retry - end\n",
2007 if (test_and_clear_bit(LOOP_RESYNC_NEEDED
, &ha
->dpc_flags
)) {
2009 DEBUG(printk("scsi(%ld): qla2x00_loop_resync()\n",
2012 if (!(test_and_set_bit(LOOP_RESYNC_ACTIVE
,
2015 qla2x00_loop_resync(ha
);
2017 clear_bit(LOOP_RESYNC_ACTIVE
, &ha
->dpc_flags
);
2020 DEBUG(printk("scsi(%ld): qla2x00_loop_resync - end\n",
2024 if (test_and_clear_bit(FCPORT_RESCAN_NEEDED
, &ha
->dpc_flags
)) {
2026 DEBUG(printk("scsi(%ld): Rescan flagged fcports...\n",
2029 qla2x00_rescan_fcports(ha
);
2031 DEBUG(printk("scsi(%ld): Rescan flagged fcports..."
2036 if (!ha
->interrupts_on
)
2037 qla2x00_enable_intrs(ha
);
2040 } /* End of while(1) */
2042 DEBUG(printk("scsi(%ld): DPC handler exiting\n", ha
->host_no
));
2045 * Make sure that nobody tries to wake us up again.
2047 ha
->dpc_wait
= NULL
;
2050 complete_and_exit(&ha
->dpc_exited
, 0);
2055 * Processes asynchronous reset.
2058 * ha = adapter block pointer.
2061 qla2x00_rst_aen(scsi_qla_host_t
*ha
)
2063 if (ha
->flags
.online
&& !ha
->flags
.reset_active
&&
2064 !atomic_read(&ha
->loop_down_timer
) &&
2065 !(test_bit(ABORT_ISP_ACTIVE
, &ha
->dpc_flags
))) {
2067 clear_bit(RESET_MARKER_NEEDED
, &ha
->dpc_flags
);
2070 * Issue marker command only when we are going to start
2073 ha
->marker_needed
= 1;
2074 } while (!atomic_read(&ha
->loop_down_timer
) &&
2075 (test_bit(RESET_MARKER_NEEDED
, &ha
->dpc_flags
)));
2081 * This routine will allocate SP from the free queue
2088 qla2x00_get_new_sp(scsi_qla_host_t
*ha
)
2092 sp
= mempool_alloc(ha
->srb_mempool
, GFP_ATOMIC
);
2094 atomic_set(&sp
->ref_count
, 1);
2099 qla2x00_sp_free_dma(scsi_qla_host_t
*ha
, srb_t
*sp
)
2101 struct scsi_cmnd
*cmd
= sp
->cmd
;
2103 if (sp
->flags
& SRB_DMA_VALID
) {
2105 dma_unmap_sg(&ha
->pdev
->dev
, cmd
->request_buffer
,
2106 cmd
->use_sg
, cmd
->sc_data_direction
);
2107 } else if (cmd
->request_bufflen
) {
2108 dma_unmap_single(&ha
->pdev
->dev
, sp
->dma_handle
,
2109 cmd
->request_bufflen
, cmd
->sc_data_direction
);
2111 sp
->flags
&= ~SRB_DMA_VALID
;
2116 qla2x00_sp_compl(scsi_qla_host_t
*ha
, srb_t
*sp
)
2118 struct scsi_cmnd
*cmd
= sp
->cmd
;
2120 qla2x00_sp_free_dma(ha
, sp
);
2123 mempool_free(sp
, ha
->srb_mempool
);
2125 cmd
->scsi_done(cmd
);
2128 /**************************************************************************
2134 * Context: Interrupt
2135 ***************************************************************************/
2137 qla2x00_timer(scsi_qla_host_t
*ha
)
2139 unsigned long cpu_flags
= 0;
2147 * Ports - Port down timer.
2149 * Whenever, a port is in the LOST state we start decrementing its port
2150 * down timer every second until it reaches zero. Once it reaches zero
2151 * the port it marked DEAD.
2154 list_for_each_entry(fcport
, &ha
->fcports
, list
) {
2155 if (fcport
->port_type
!= FCT_TARGET
)
2158 if (atomic_read(&fcport
->state
) == FCS_DEVICE_LOST
) {
2160 if (atomic_read(&fcport
->port_down_timer
) == 0)
2163 if (atomic_dec_and_test(&fcport
->port_down_timer
) != 0)
2164 atomic_set(&fcport
->state
, FCS_DEVICE_DEAD
);
2166 DEBUG(printk("scsi(%ld): fcport-%d - port retry count: "
2169 t
, atomic_read(&fcport
->port_down_timer
)));
2172 } /* End of for fcport */
2175 /* Loop down handler. */
2176 if (atomic_read(&ha
->loop_down_timer
) > 0 &&
2177 !(test_bit(ABORT_ISP_ACTIVE
, &ha
->dpc_flags
)) && ha
->flags
.online
) {
2179 if (atomic_read(&ha
->loop_down_timer
) ==
2180 ha
->loop_down_abort_time
) {
2182 DEBUG(printk("scsi(%ld): Loop Down - aborting the "
2183 "queues before time expire\n",
2186 if (!IS_QLA2100(ha
) && ha
->link_down_timeout
)
2187 atomic_set(&ha
->loop_state
, LOOP_DEAD
);
2189 /* Schedule an ISP abort to return any tape commands. */
2190 spin_lock_irqsave(&ha
->hardware_lock
, cpu_flags
);
2191 for (index
= 1; index
< MAX_OUTSTANDING_COMMANDS
;
2195 sp
= ha
->outstanding_cmds
[index
];
2199 if (!(sfcp
->flags
& FCF_TAPE_PRESENT
))
2202 set_bit(ISP_ABORT_NEEDED
, &ha
->dpc_flags
);
2205 spin_unlock_irqrestore(&ha
->hardware_lock
, cpu_flags
);
2207 set_bit(ABORT_QUEUES_NEEDED
, &ha
->dpc_flags
);
2211 /* if the loop has been down for 4 minutes, reinit adapter */
2212 if (atomic_dec_and_test(&ha
->loop_down_timer
) != 0) {
2213 DEBUG(printk("scsi(%ld): Loop down exceed 4 mins - "
2214 "restarting queues.\n",
2217 set_bit(RESTART_QUEUES_NEEDED
, &ha
->dpc_flags
);
2220 if (!(ha
->device_flags
& DFLG_NO_CABLE
)) {
2221 DEBUG(printk("scsi(%ld): Loop down - "
2224 qla_printk(KERN_WARNING
, ha
,
2225 "Loop down - aborting ISP.\n");
2227 set_bit(ISP_ABORT_NEEDED
, &ha
->dpc_flags
);
2230 DEBUG3(printk("scsi(%ld): Loop Down - seconds remainning %d\n",
2232 atomic_read(&ha
->loop_down_timer
)));
2235 /* Schedule the DPC routine if needed */
2236 if ((test_bit(ISP_ABORT_NEEDED
, &ha
->dpc_flags
) ||
2237 test_bit(LOOP_RESYNC_NEEDED
, &ha
->dpc_flags
) ||
2239 test_bit(LOGIN_RETRY_NEEDED
, &ha
->dpc_flags
) ||
2240 test_bit(RESET_MARKER_NEEDED
, &ha
->dpc_flags
) ||
2241 test_bit(RELOGIN_NEEDED
, &ha
->dpc_flags
)) &&
2242 ha
->dpc_wait
&& !ha
->dpc_active
) {
2247 qla2x00_restart_timer(ha
, WATCH_INTERVAL
);
2250 /* XXX(hch): crude hack to emulate a down_timeout() */
2252 qla2x00_down_timeout(struct semaphore
*sema
, unsigned long timeout
)
2254 const unsigned int step
= HZ
/10;
2257 if (!down_trylock(sema
))
2259 set_current_state(TASK_INTERRUPTIBLE
);
2260 if (schedule_timeout(step
))
2262 } while ((timeout
-= step
) > 0);
2268 * qla2x00_module_init - Module initialization.
2271 qla2x00_module_init(void)
2273 /* Allocate cache for SRBs. */
2274 srb_cachep
= kmem_cache_create("qla2xxx_srbs", sizeof(srb_t
), 0,
2275 SLAB_HWCACHE_ALIGN
, NULL
, NULL
);
2276 if (srb_cachep
== NULL
) {
2278 "qla2xxx: Unable to allocate SRB cache...Failing load!\n");
2282 /* Derive version string. */
2283 strcpy(qla2x00_version_str
, QLA2XXX_VERSION
);
2285 strcat(qla2x00_version_str
, "-debug");
2287 qla2xxx_transport_template
=
2288 fc_attach_transport(&qla2xxx_transport_functions
);
2289 if (!qla2xxx_transport_template
)
2292 printk(KERN_INFO
"QLogic Fibre Channel HBA Driver\n");
2297 * qla2x00_module_exit - Module cleanup.
2300 qla2x00_module_exit(void)
2302 kmem_cache_destroy(srb_cachep
);
2303 fc_release_transport(qla2xxx_transport_template
);
2306 module_init(qla2x00_module_init
);
2307 module_exit(qla2x00_module_exit
);
2309 MODULE_AUTHOR("QLogic Corporation");
2310 MODULE_DESCRIPTION("QLogic Fibre Channel HBA Driver");
2311 MODULE_LICENSE("GPL");
2312 MODULE_VERSION(QLA2XXX_VERSION
);