[SCSI] remove some dead code in qla2xxx
[linux-2.6/verdex.git] / drivers / scsi / qla2xxx / qla_os.c
blob7f8d747bd5e546e3b753ce06e3568f32d0a0ec07
1 /*
2 * QLOGIC LINUX SOFTWARE
4 * QLogic ISP2x00 device driver for Linux 2.6.x
5 * Copyright (C) 2003-2004 QLogic Corporation
6 * (www.qlogic.com)
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
11 * later version.
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.
19 #include "qla_def.h"
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>
32 * Driver version
34 char qla2x00_version_str[40];
37 * SRB allocation cache
39 static kmem_cache_t *srb_cachep;
42 * Ioctl related information.
44 static int num_hosts;
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,
103 .name = "qla2xxx",
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,
115 .this_id = -1,
116 .cmd_per_lun = 3,
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
131 * Timer routines
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 *);
142 static inline void
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;
153 static inline void
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 /* -------------------------------------------------------------------------- */
180 static char *
181 qla2x00_get_pci_info_str(struct scsi_qla_host *ha, char *str)
183 static char *pci_bus_modes[] = {
184 "33", "66", "100", "133",
186 uint16_t pci_bus;
188 strcpy(str, "PCI");
189 pci_bus = (ha->pci_attr & (BIT_9 | BIT_10)) >> 9;
190 if (pci_bus) {
191 strcat(str, "-X (");
192 strcat(str, pci_bus_modes[pci_bus]);
193 } else {
194 pci_bus = (ha->pci_attr & BIT_8) >> 8;
195 strcat(str, " (");
196 strcat(str, pci_bus_modes[pci_bus]);
198 strcat(str, " MHz)");
200 return (str);
203 char *
204 qla2x00_get_fw_version_str(struct scsi_qla_host *ha, char *str)
206 char un_str[10];
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) {
213 strcat(str, "FLX");
214 return (str);
217 switch (ha->fw_attributes & 0xFF) {
218 case 0x7:
219 strcat(str, "EF");
220 break;
221 case 0x17:
222 strcat(str, "TP");
223 break;
224 case 0x37:
225 strcat(str, "IP");
226 break;
227 case 0x77:
228 strcat(str, "VI");
229 break;
230 default:
231 sprintf(un_str, "(%x)", ha->fw_attributes);
232 strcat(str, un_str);
233 break;
235 if (ha->fw_attributes & 0x100)
236 strcat(str, "X");
238 return (str);
241 /**************************************************************************
242 * qla2x00_queuecommand
244 * Description:
245 * Queue a command to the controller.
247 * Input:
248 * cmd - pointer to Scsi cmd structure
249 * fn - pointer to Scsi done function
251 * Returns:
252 * 0 - Always
254 * Note:
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
258 * handling).
259 **************************************************************************/
260 static int
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;
265 srb_t *sp;
266 int rval;
268 if (!fcport) {
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;
279 goto qc_host_busy;
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;
289 sp->ha = ha;
290 sp->fcport = fcport;
291 sp->cmd = cmd;
292 sp->flags = 0;
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) {
304 unsigned long flags;
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);
313 return 0;
315 qc_host_busy_free_sp:
316 qla2x00_sp_free_dma(ha, sp);
317 CMD_SP(cmd) = NULL;
318 mempool_free(sp, ha->srb_mempool);
320 qc_host_busy_lock:
321 spin_lock_irq(ha->host->host_lock);
323 qc_host_busy:
324 return SCSI_MLQUEUE_HOST_BUSY;
326 qc_fail_command:
327 done(cmd);
329 return 0;
333 * qla2x00_eh_wait_on_command
334 * Waits for the command to be returned by the Firmware for some
335 * max time.
337 * Input:
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)
343 * Return:
344 * Not Found : 0
345 * Found : 1
347 static int
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);
359 if (--wait_iter)
360 break;
362 if (CMD_SP(cmd))
363 ret = QLA_FUNCTION_FAILED;
365 return ret;
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
374 * Input:
375 * ha - pointer to host adapter structure
377 * Note:
378 * Does context switching-Release SPIN_LOCK
379 * (if any) before calling this routine.
381 * Return:
382 * Success (Adapter is online) : 0
383 * Failed (Adapter is offline/disabled) : 1
385 static int
386 qla2x00_wait_for_hba_online(scsi_qla_host_t *ha)
388 int return_status;
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)) {
397 msleep(1000);
399 if (ha->flags.online)
400 return_status = QLA_SUCCESS;
401 else
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.
413 * Input:
414 * ha - pointer to host adapter structure
416 * Note:
417 * Does context switching-Release SPIN_LOCK
418 * (if any) before calling this routine.
421 * Return:
422 * Success (LOOP_READY) : 0
423 * Failed (LOOP_NOT_READY) : 1
425 static inline int
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) {
437 msleep(1000);
438 if (time_after_eq(jiffies, loop_timeout)) {
439 return_status = QLA_FUNCTION_FAILED;
440 break;
443 return (return_status);
446 /**************************************************************************
447 * qla2xxx_eh_abort
449 * Description:
450 * The abort function will abort the specified command.
452 * Input:
453 * cmd = Linux SCSI command packet to be aborted.
455 * Returns:
456 * Either SUCCESS or FAILED.
458 * Note:
459 **************************************************************************/
461 qla2xxx_eh_abort(struct scsi_cmnd *cmd)
463 scsi_qla_host_t *ha = to_qla_host(cmd->device->host);
464 srb_t *sp;
465 int ret, i;
466 unsigned int id, lun;
467 unsigned long serial;
469 if (!CMD_SP(cmd))
470 return FAILED;
472 ret = FAILED;
474 id = cmd->device->id;
475 lun = cmd->device->lun;
476 serial = cmd->serial_number;
478 /* Check active list for command command. */
479 spin_unlock_irq(ha->host->host_lock);
480 spin_lock(&ha->hardware_lock);
481 for (i = 1; i < MAX_OUTSTANDING_COMMANDS; i++) {
482 sp = ha->outstanding_cmds[i];
484 if (sp == NULL)
485 continue;
487 if (sp->cmd != cmd)
488 continue;
490 DEBUG2(printk("%s(%ld): aborting sp %p from RISC. pid=%ld "
491 "sp->state=%x\n", __func__, ha->host_no, sp, serial,
492 sp->state));
493 DEBUG3(qla2x00_print_scsi_cmd(cmd);)
495 spin_unlock(&ha->hardware_lock);
496 if (qla2x00_abort_command(ha, sp)) {
497 DEBUG2(printk("%s(%ld): abort_command "
498 "mbx failed.\n", __func__, ha->host_no));
499 } else {
500 DEBUG3(printk("%s(%ld): abort_command "
501 "mbx success.\n", __func__, ha->host_no));
502 ret = SUCCESS;
504 spin_lock(&ha->hardware_lock);
506 break;
509 /* Wait for the command to be returned. */
510 if (ret == SUCCESS) {
511 spin_unlock(&ha->hardware_lock);
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);
517 spin_lock(&ha->hardware_lock);
519 spin_lock_irq(ha->host->host_lock);
521 qla_printk(KERN_INFO, ha,
522 "scsi(%ld:%d:%d): Abort command issued -- %lx %x.\n", ha->host_no,
523 id, lun, serial, ret);
525 return ret;
528 /**************************************************************************
529 * qla2x00_eh_wait_for_pending_target_commands
531 * Description:
532 * Waits for all the commands to come back from the specified target.
534 * Input:
535 * ha - pointer to scsi_qla_host structure.
536 * t - target
537 * Returns:
538 * Either SUCCESS or FAILED.
540 * Note:
541 **************************************************************************/
542 static int
543 qla2x00_eh_wait_for_pending_target_commands(scsi_qla_host_t *ha, unsigned int t)
545 int cnt;
546 int status;
547 srb_t *sp;
548 struct scsi_cmnd *cmd;
550 status = 0;
553 * Waiting for all commands for the designated target in the active
554 * array
556 for (cnt = 1; cnt < MAX_OUTSTANDING_COMMANDS; cnt++) {
557 spin_lock(&ha->hardware_lock);
558 sp = ha->outstanding_cmds[cnt];
559 if (sp) {
560 cmd = sp->cmd;
561 spin_unlock(&ha->hardware_lock);
562 if (cmd->device->id == t) {
563 if (!qla2x00_eh_wait_on_command(ha, cmd)) {
564 status = 1;
565 break;
568 } else {
569 spin_unlock(&ha->hardware_lock);
572 return (status);
576 /**************************************************************************
577 * qla2xxx_eh_device_reset
579 * Description:
580 * The device reset function will reset the target and abort any
581 * executing commands.
583 * NOTE: The use of SP is undefined within this context. Do *NOT*
584 * attempt to use this value, even if you determine it is
585 * non-null.
587 * Input:
588 * cmd = Linux SCSI command packet of the command that cause the
589 * bus device reset.
591 * Returns:
592 * SUCCESS/FAILURE (defined as macro in scsi.h).
594 **************************************************************************/
596 qla2xxx_eh_device_reset(struct scsi_cmnd *cmd)
598 scsi_qla_host_t *ha = to_qla_host(cmd->device->host);
599 fc_port_t *fcport = (struct fc_port *) cmd->device->hostdata;
600 srb_t *sp;
601 int ret;
602 unsigned int id, lun;
603 unsigned long serial;
605 ret = FAILED;
607 id = cmd->device->id;
608 lun = cmd->device->lun;
609 serial = cmd->serial_number;
611 sp = (srb_t *) CMD_SP(cmd);
612 if (!sp || !fcport)
613 return ret;
615 qla_printk(KERN_INFO, ha,
616 "scsi(%ld:%d:%d): DEVICE RESET ISSUED.\n", ha->host_no, id, lun);
618 spin_unlock_irq(ha->host->host_lock);
620 if (qla2x00_wait_for_hba_online(ha) != QLA_SUCCESS) {
621 spin_lock_irq(ha->host->host_lock);
622 goto eh_dev_reset_done;
625 if (qla2x00_wait_for_loop_ready(ha) == QLA_SUCCESS) {
626 if (qla2x00_device_reset(ha, fcport) == 0)
627 ret = SUCCESS;
629 #if defined(LOGOUT_AFTER_DEVICE_RESET)
630 if (ret == SUCCESS) {
631 if (fcport->flags & FC_FABRIC_DEVICE) {
632 qla2x00_fabric_logout(ha, fcport->loop_id);
633 qla2x00_mark_device_lost(ha, fcport);
636 #endif
637 } else {
638 DEBUG2(printk(KERN_INFO
639 "%s failed: loop not ready\n",__func__);)
642 if (ret == FAILED) {
643 DEBUG3(printk("%s(%ld): device reset failed\n",
644 __func__, ha->host_no));
645 qla_printk(KERN_INFO, ha, "%s: device reset failed\n",
646 __func__);
648 goto eh_dev_reset_done;
652 * If we are coming down the EH path, wait for all commands to
653 * complete for the device.
655 if (cmd->device->host->eh_active) {
656 if (qla2x00_eh_wait_for_pending_target_commands(ha, id))
657 ret = FAILED;
659 if (ret == FAILED) {
660 DEBUG3(printk("%s(%ld): failed while waiting for "
661 "commands\n", __func__, ha->host_no));
662 qla_printk(KERN_INFO, ha,
663 "%s: failed while waiting for commands\n",
664 __func__);
666 goto eh_dev_reset_done;
670 qla_printk(KERN_INFO, ha,
671 "scsi(%ld:%d:%d): DEVICE RESET SUCCEEDED.\n", ha->host_no, id, lun);
673 eh_dev_reset_done:
674 spin_lock_irq(ha->host->host_lock);
676 return ret;
679 /**************************************************************************
680 * qla2x00_eh_wait_for_pending_commands
682 * Description:
683 * Waits for all the commands to come back from the specified host.
685 * Input:
686 * ha - pointer to scsi_qla_host structure.
688 * Returns:
689 * 1 : SUCCESS
690 * 0 : FAILED
692 * Note:
693 **************************************************************************/
694 static int
695 qla2x00_eh_wait_for_pending_commands(scsi_qla_host_t *ha)
697 int cnt;
698 int status;
699 srb_t *sp;
700 struct scsi_cmnd *cmd;
702 status = 1;
705 * Waiting for all commands for the designated target in the active
706 * array
708 for (cnt = 1; cnt < MAX_OUTSTANDING_COMMANDS; cnt++) {
709 spin_lock(&ha->hardware_lock);
710 sp = ha->outstanding_cmds[cnt];
711 if (sp) {
712 cmd = sp->cmd;
713 spin_unlock(&ha->hardware_lock);
714 status = qla2x00_eh_wait_on_command(ha, cmd);
715 if (status == 0)
716 break;
718 else {
719 spin_unlock(&ha->hardware_lock);
722 return (status);
726 /**************************************************************************
727 * qla2xxx_eh_bus_reset
729 * Description:
730 * The bus reset function will reset the bus and abort any executing
731 * commands.
733 * Input:
734 * cmd = Linux SCSI command packet of the command that cause the
735 * bus reset.
737 * Returns:
738 * SUCCESS/FAILURE (defined as macro in scsi.h).
740 **************************************************************************/
742 qla2xxx_eh_bus_reset(struct scsi_cmnd *cmd)
744 scsi_qla_host_t *ha = to_qla_host(cmd->device->host);
745 fc_port_t *fcport = (struct fc_port *) cmd->device->hostdata;
746 srb_t *sp;
747 int ret;
748 unsigned int id, lun;
749 unsigned long serial;
751 ret = FAILED;
753 id = cmd->device->id;
754 lun = cmd->device->lun;
755 serial = cmd->serial_number;
757 sp = (srb_t *) CMD_SP(cmd);
758 if (!sp || !fcport)
759 return ret;
761 qla_printk(KERN_INFO, ha,
762 "scsi(%ld:%d:%d): LOOP RESET ISSUED.\n", ha->host_no, id, lun);
764 spin_unlock_irq(ha->host->host_lock);
766 if (qla2x00_wait_for_hba_online(ha) != QLA_SUCCESS) {
767 DEBUG2(printk("%s failed:board disabled\n",__func__));
768 goto eh_bus_reset_done;
771 if (qla2x00_wait_for_loop_ready(ha) == QLA_SUCCESS) {
772 if (qla2x00_loop_reset(ha) == QLA_SUCCESS)
773 ret = SUCCESS;
775 if (ret == FAILED)
776 goto eh_bus_reset_done;
778 /* Waiting for our command in done_queue to be returned to OS.*/
779 if (cmd->device->host->eh_active)
780 if (!qla2x00_eh_wait_for_pending_commands(ha))
781 ret = FAILED;
783 eh_bus_reset_done:
784 qla_printk(KERN_INFO, ha, "%s: reset %s\n", __func__,
785 (ret == FAILED) ? "failed" : "succeded");
787 spin_lock_irq(ha->host->host_lock);
789 return ret;
792 /**************************************************************************
793 * qla2xxx_eh_host_reset
795 * Description:
796 * The reset function will reset the Adapter.
798 * Input:
799 * cmd = Linux SCSI command packet of the command that cause the
800 * adapter reset.
802 * Returns:
803 * Either SUCCESS or FAILED.
805 * Note:
806 **************************************************************************/
808 qla2xxx_eh_host_reset(struct scsi_cmnd *cmd)
810 scsi_qla_host_t *ha = to_qla_host(cmd->device->host);
811 fc_port_t *fcport = (struct fc_port *) cmd->device->hostdata;
812 srb_t *sp;
813 int ret;
814 unsigned int id, lun;
815 unsigned long serial;
817 ret = FAILED;
819 id = cmd->device->id;
820 lun = cmd->device->lun;
821 serial = cmd->serial_number;
823 sp = (srb_t *) CMD_SP(cmd);
824 if (!sp || !fcport)
825 return ret;
827 qla_printk(KERN_INFO, ha,
828 "scsi(%ld:%d:%d): ADAPTER RESET ISSUED.\n", ha->host_no, id, lun);
830 spin_unlock_irq(ha->host->host_lock);
832 if (qla2x00_wait_for_hba_online(ha) != QLA_SUCCESS)
833 goto eh_host_reset_lock;
836 * Fixme-may be dpc thread is active and processing
837 * loop_resync,so wait a while for it to
838 * be completed and then issue big hammer.Otherwise
839 * it may cause I/O failure as big hammer marks the
840 * devices as lost kicking of the port_down_timer
841 * while dpc is stuck for the mailbox to complete.
843 qla2x00_wait_for_loop_ready(ha);
844 set_bit(ABORT_ISP_ACTIVE, &ha->dpc_flags);
845 if (qla2x00_abort_isp(ha)) {
846 clear_bit(ABORT_ISP_ACTIVE, &ha->dpc_flags);
847 /* failed. schedule dpc to try */
848 set_bit(ISP_ABORT_NEEDED, &ha->dpc_flags);
850 if (qla2x00_wait_for_hba_online(ha) != QLA_SUCCESS)
851 goto eh_host_reset_lock;
853 clear_bit(ABORT_ISP_ACTIVE, &ha->dpc_flags);
855 /* Waiting for our command in done_queue to be returned to OS.*/
856 if (qla2x00_eh_wait_for_pending_commands(ha))
857 ret = SUCCESS;
859 eh_host_reset_lock:
860 spin_lock_irq(ha->host->host_lock);
862 qla_printk(KERN_INFO, ha, "%s: reset %s\n", __func__,
863 (ret == FAILED) ? "failed" : "succeded");
865 return ret;
869 * qla2x00_loop_reset
870 * Issue loop reset.
872 * Input:
873 * ha = adapter block pointer.
875 * Returns:
876 * 0 = success
878 static int
879 qla2x00_loop_reset(scsi_qla_host_t *ha)
881 int status = QLA_SUCCESS;
882 struct fc_port *fcport;
884 if (ha->flags.enable_lip_reset) {
885 status = qla2x00_lip_reset(ha);
888 if (status == QLA_SUCCESS && ha->flags.enable_target_reset) {
889 list_for_each_entry(fcport, &ha->fcports, list) {
890 if (fcport->port_type != FCT_TARGET)
891 continue;
893 status = qla2x00_target_reset(ha, fcport);
894 if (status != QLA_SUCCESS)
895 break;
899 if (status == QLA_SUCCESS &&
900 ((!ha->flags.enable_target_reset &&
901 !ha->flags.enable_lip_reset) ||
902 ha->flags.enable_lip_full_login)) {
904 status = qla2x00_full_login_lip(ha);
907 /* Issue marker command only when we are going to start the I/O */
908 ha->marker_needed = 1;
910 if (status) {
911 /* Empty */
912 DEBUG2_3(printk("%s(%ld): **** FAILED ****\n",
913 __func__,
914 ha->host_no);)
915 } else {
916 /* Empty */
917 DEBUG3(printk("%s(%ld): exiting normally.\n",
918 __func__,
919 ha->host_no);)
922 return(status);
926 * qla2x00_device_reset
927 * Issue bus device reset message to the target.
929 * Input:
930 * ha = adapter block pointer.
931 * t = SCSI ID.
932 * TARGET_QUEUE_LOCK must be released.
933 * ADAPTER_STATE_LOCK must be released.
935 * Context:
936 * Kernel context.
938 static int
939 qla2x00_device_reset(scsi_qla_host_t *ha, fc_port_t *reset_fcport)
941 /* Abort Target command will clear Reservation */
942 return qla2x00_abort_target(reset_fcport);
945 static int
946 qla2xxx_slave_alloc(struct scsi_device *sdev)
948 scsi_qla_host_t *ha = to_qla_host(sdev->host);
949 struct fc_rport *rport = starget_to_rport(scsi_target(sdev));
950 fc_port_t *fcport;
951 int found;
953 if (!rport)
954 return -ENXIO;
956 found = 0;
957 list_for_each_entry(fcport, &ha->fcports, list) {
958 if (rport->port_name ==
959 be64_to_cpu(*(uint64_t *)fcport->port_name)) {
960 found++;
961 break;
964 if (!found)
965 return -ENXIO;
967 sdev->hostdata = fcport;
969 return 0;
972 static int
973 qla2xxx_slave_configure(struct scsi_device *sdev)
975 scsi_qla_host_t *ha = to_qla_host(sdev->host);
976 struct fc_rport *rport = starget_to_rport(sdev->sdev_target);
978 if (sdev->tagged_supported)
979 scsi_activate_tcq(sdev, 32);
980 else
981 scsi_deactivate_tcq(sdev, 32);
983 rport->dev_loss_tmo = ha->port_down_retry_count + 5;
985 return 0;
988 static void
989 qla2xxx_slave_destroy(struct scsi_device *sdev)
991 sdev->hostdata = NULL;
995 * qla2x00_config_dma_addressing() - Configure OS DMA addressing method.
996 * @ha: HA context
998 * At exit, the @ha's flags.enable_64bit_addressing set to indicated
999 * supported addressing method.
1001 static void
1002 qla2x00_config_dma_addressing(scsi_qla_host_t *ha)
1004 /* Assume 32bit DMA address */
1005 ha->flags.enable_64bit_addressing = 0;
1006 ha->calc_request_entries = qla2x00_calc_iocbs_32;
1007 ha->build_scsi_iocbs = qla2x00_build_scsi_iocbs_32;
1010 * Given the two variants pci_set_dma_mask(), allow the compiler to
1011 * assist in setting the proper dma mask.
1013 if (sizeof(dma_addr_t) > 4) {
1014 if (pci_set_dma_mask(ha->pdev, DMA_64BIT_MASK) == 0) {
1015 ha->flags.enable_64bit_addressing = 1;
1016 ha->calc_request_entries = qla2x00_calc_iocbs_64;
1017 ha->build_scsi_iocbs = qla2x00_build_scsi_iocbs_64;
1019 if (pci_set_consistent_dma_mask(ha->pdev,
1020 DMA_64BIT_MASK)) {
1021 qla_printk(KERN_DEBUG, ha,
1022 "Failed to set 64 bit PCI consistent mask; "
1023 "using 32 bit.\n");
1024 pci_set_consistent_dma_mask(ha->pdev,
1025 DMA_32BIT_MASK);
1027 } else {
1028 qla_printk(KERN_DEBUG, ha,
1029 "Failed to set 64 bit PCI DMA mask, falling back "
1030 "to 32 bit MASK.\n");
1031 pci_set_dma_mask(ha->pdev, DMA_32BIT_MASK);
1033 } else {
1034 pci_set_dma_mask(ha->pdev, DMA_32BIT_MASK);
1038 static int
1039 qla2x00_iospace_config(scsi_qla_host_t *ha)
1041 unsigned long pio, pio_len, pio_flags;
1042 unsigned long mmio, mmio_len, mmio_flags;
1044 /* We only need PIO for Flash operations on ISP2312 v2 chips. */
1045 pio = pci_resource_start(ha->pdev, 0);
1046 pio_len = pci_resource_len(ha->pdev, 0);
1047 pio_flags = pci_resource_flags(ha->pdev, 0);
1048 if (pio_flags & IORESOURCE_IO) {
1049 if (pio_len < MIN_IOBASE_LEN) {
1050 qla_printk(KERN_WARNING, ha,
1051 "Invalid PCI I/O region size (%s)...\n",
1052 pci_name(ha->pdev));
1053 pio = 0;
1055 } else {
1056 qla_printk(KERN_WARNING, ha,
1057 "region #0 not a PIO resource (%s)...\n",
1058 pci_name(ha->pdev));
1059 pio = 0;
1062 /* Use MMIO operations for all accesses. */
1063 mmio = pci_resource_start(ha->pdev, 1);
1064 mmio_len = pci_resource_len(ha->pdev, 1);
1065 mmio_flags = pci_resource_flags(ha->pdev, 1);
1067 if (!(mmio_flags & IORESOURCE_MEM)) {
1068 qla_printk(KERN_ERR, ha,
1069 "region #0 not an MMIO resource (%s), aborting\n",
1070 pci_name(ha->pdev));
1071 goto iospace_error_exit;
1073 if (mmio_len < MIN_IOBASE_LEN) {
1074 qla_printk(KERN_ERR, ha,
1075 "Invalid PCI mem region size (%s), aborting\n",
1076 pci_name(ha->pdev));
1077 goto iospace_error_exit;
1080 if (pci_request_regions(ha->pdev, ha->brd_info->drv_name)) {
1081 qla_printk(KERN_WARNING, ha,
1082 "Failed to reserve PIO/MMIO regions (%s)\n",
1083 pci_name(ha->pdev));
1085 goto iospace_error_exit;
1088 ha->pio_address = pio;
1089 ha->pio_length = pio_len;
1090 ha->iobase = ioremap(mmio, MIN_IOBASE_LEN);
1091 if (!ha->iobase) {
1092 qla_printk(KERN_ERR, ha,
1093 "cannot remap MMIO (%s), aborting\n", pci_name(ha->pdev));
1095 goto iospace_error_exit;
1098 return (0);
1100 iospace_error_exit:
1101 return (-ENOMEM);
1105 * PCI driver interface
1107 int qla2x00_probe_one(struct pci_dev *pdev, struct qla_board_info *brd_info)
1109 int ret;
1110 device_reg_t __iomem *reg;
1111 struct Scsi_Host *host;
1112 scsi_qla_host_t *ha;
1113 unsigned long flags = 0;
1114 unsigned long wait_switch = 0;
1115 char pci_info[20];
1116 char fw_str[30];
1117 fc_port_t *fcport;
1119 if (pci_enable_device(pdev))
1120 return -1;
1122 host = scsi_host_alloc(&qla2x00_driver_template,
1123 sizeof(scsi_qla_host_t));
1124 if (host == NULL) {
1125 printk(KERN_WARNING
1126 "qla2xxx: Couldn't allocate host from scsi layer!\n");
1127 goto probe_disable_device;
1130 /* Clear our data area */
1131 ha = (scsi_qla_host_t *)host->hostdata;
1132 memset(ha, 0, sizeof(scsi_qla_host_t));
1134 ha->pdev = pdev;
1135 ha->host = host;
1136 ha->host_no = host->host_no;
1137 ha->brd_info = brd_info;
1138 sprintf(ha->host_str, "%s_%ld", ha->brd_info->drv_name, ha->host_no);
1140 /* Configure PCI I/O space */
1141 ret = qla2x00_iospace_config(ha);
1142 if (ret != 0) {
1143 goto probe_alloc_failed;
1146 /* Sanitize the information from PCI BIOS. */
1147 host->irq = pdev->irq;
1149 qla_printk(KERN_INFO, ha,
1150 "Found an %s, irq %d, iobase 0x%p\n", ha->brd_info->isp_name,
1151 host->irq, ha->iobase);
1153 spin_lock_init(&ha->hardware_lock);
1155 ha->prev_topology = 0;
1156 ha->ports = MAX_BUSES;
1158 if (IS_QLA2100(ha)) {
1159 host->max_id = MAX_TARGETS_2100;
1160 ha->mbx_count = MAILBOX_REGISTER_COUNT_2100;
1161 ha->request_q_length = REQUEST_ENTRY_CNT_2100;
1162 ha->response_q_length = RESPONSE_ENTRY_CNT_2100;
1163 ha->last_loop_id = SNS_LAST_LOOP_ID_2100;
1164 host->sg_tablesize = 32;
1165 } else if (IS_QLA2200(ha)) {
1166 host->max_id = MAX_TARGETS_2200;
1167 ha->mbx_count = MAILBOX_REGISTER_COUNT;
1168 ha->request_q_length = REQUEST_ENTRY_CNT_2200;
1169 ha->response_q_length = RESPONSE_ENTRY_CNT_2100;
1170 ha->last_loop_id = SNS_LAST_LOOP_ID_2100;
1171 } else /*if (IS_QLA2300(ha))*/ {
1172 host->max_id = MAX_TARGETS_2200;
1173 ha->mbx_count = MAILBOX_REGISTER_COUNT;
1174 ha->request_q_length = REQUEST_ENTRY_CNT_2200;
1175 ha->response_q_length = RESPONSE_ENTRY_CNT_2300;
1176 ha->last_loop_id = SNS_LAST_LOOP_ID_2300;
1178 host->can_queue = ha->request_q_length + 128;
1180 /* load the F/W, read paramaters, and init the H/W */
1181 ha->instance = num_hosts;
1183 init_MUTEX(&ha->mbx_cmd_sem);
1184 init_MUTEX_LOCKED(&ha->mbx_intr_sem);
1186 INIT_LIST_HEAD(&ha->list);
1187 INIT_LIST_HEAD(&ha->fcports);
1188 INIT_LIST_HEAD(&ha->rscn_fcports);
1191 * These locks are used to prevent more than one CPU
1192 * from modifying the queue at the same time. The
1193 * higher level "host_lock" will reduce most
1194 * contention for these locks.
1196 spin_lock_init(&ha->mbx_reg_lock);
1198 ha->dpc_pid = -1;
1199 init_completion(&ha->dpc_inited);
1200 init_completion(&ha->dpc_exited);
1202 qla2x00_config_dma_addressing(ha);
1203 if (qla2x00_mem_alloc(ha)) {
1204 qla_printk(KERN_WARNING, ha,
1205 "[ERROR] Failed to allocate memory for adapter\n");
1207 goto probe_alloc_failed;
1210 pci_set_drvdata(pdev, ha);
1211 host->this_id = 255;
1212 host->cmd_per_lun = 3;
1213 host->unique_id = ha->instance;
1214 host->max_cmd_len = MAX_CMDSZ;
1215 host->max_channel = ha->ports - 1;
1216 host->max_lun = MAX_LUNS;
1217 host->transportt = qla2xxx_transport_template;
1218 if (scsi_add_host(host, &pdev->dev))
1219 goto probe_alloc_failed;
1221 qla2x00_alloc_sysfs_attr(ha);
1223 if (qla2x00_initialize_adapter(ha) &&
1224 !(ha->device_flags & DFLG_NO_CABLE)) {
1226 qla_printk(KERN_WARNING, ha,
1227 "Failed to initialize adapter\n");
1229 DEBUG2(printk("scsi(%ld): Failed to initialize adapter - "
1230 "Adapter flags %x.\n",
1231 ha->host_no, ha->device_flags));
1233 goto probe_failed;
1236 qla2x00_init_host_attr(ha);
1239 * Startup the kernel thread for this host adapter
1241 ha->dpc_should_die = 0;
1242 ha->dpc_pid = kernel_thread(qla2x00_do_dpc, ha, 0);
1243 if (ha->dpc_pid < 0) {
1244 qla_printk(KERN_WARNING, ha,
1245 "Unable to start DPC thread!\n");
1247 goto probe_failed;
1249 wait_for_completion(&ha->dpc_inited);
1251 if (IS_QLA2100(ha) || IS_QLA2200(ha))
1252 ret = request_irq(host->irq, qla2100_intr_handler,
1253 SA_INTERRUPT|SA_SHIRQ, ha->brd_info->drv_name, ha);
1254 else
1255 ret = request_irq(host->irq, qla2300_intr_handler,
1256 SA_INTERRUPT|SA_SHIRQ, ha->brd_info->drv_name, ha);
1257 if (ret != 0) {
1258 qla_printk(KERN_WARNING, ha,
1259 "Failed to reserve interrupt %d already in use.\n",
1260 host->irq);
1261 goto probe_failed;
1264 /* Initialized the timer */
1265 qla2x00_start_timer(ha, qla2x00_timer, WATCH_INTERVAL);
1267 DEBUG2(printk("DEBUG: detect hba %ld at address = %p\n",
1268 ha->host_no, ha));
1270 reg = ha->iobase;
1272 /* Disable ISP interrupts. */
1273 qla2x00_disable_intrs(ha);
1275 /* Ensure mailbox registers are free. */
1276 spin_lock_irqsave(&ha->hardware_lock, flags);
1277 WRT_REG_WORD(&reg->semaphore, 0);
1278 WRT_REG_WORD(&reg->hccr, HCCR_CLR_RISC_INT);
1279 WRT_REG_WORD(&reg->hccr, HCCR_CLR_HOST_INT);
1281 /* Enable proper parity */
1282 if (!IS_QLA2100(ha) && !IS_QLA2200(ha)) {
1283 if (IS_QLA2300(ha))
1284 /* SRAM parity */
1285 WRT_REG_WORD(&reg->hccr, (HCCR_ENABLE_PARITY + 0x1));
1286 else
1287 /* SRAM, Instruction RAM and GP RAM parity */
1288 WRT_REG_WORD(&reg->hccr, (HCCR_ENABLE_PARITY + 0x7));
1290 spin_unlock_irqrestore(&ha->hardware_lock, flags);
1292 /* Enable chip interrupts. */
1293 qla2x00_enable_intrs(ha);
1295 /* v2.19.5b6 */
1297 * Wait around max loop_reset_delay secs for the devices to come
1298 * on-line. We don't want Linux scanning before we are ready.
1301 for (wait_switch = jiffies + (ha->loop_reset_delay * HZ);
1302 time_before(jiffies,wait_switch) &&
1303 !(ha->device_flags & (DFLG_NO_CABLE | DFLG_FABRIC_DEVICES))
1304 && (ha->device_flags & SWITCH_FOUND) ;) {
1306 qla2x00_check_fabric_devices(ha);
1308 msleep(10);
1311 ha->flags.init_done = 1;
1312 num_hosts++;
1314 qla_printk(KERN_INFO, ha, "\n"
1315 " QLogic Fibre Channel HBA Driver: %s\n"
1316 " QLogic %s - %s\n"
1317 " %s: %s @ %s hdma%c, host#=%ld, fw=%s\n", qla2x00_version_str,
1318 ha->model_number, ha->model_desc ? ha->model_desc: "",
1319 ha->brd_info->isp_name, qla2x00_get_pci_info_str(ha, pci_info),
1320 pci_name(ha->pdev), ha->flags.enable_64bit_addressing ? '+': '-',
1321 ha->host_no, qla2x00_get_fw_version_str(ha, fw_str));
1323 /* Go with fc_rport registration. */
1324 list_for_each_entry(fcport, &ha->fcports, list)
1325 qla2x00_reg_remote_port(ha, fcport);
1327 return 0;
1329 probe_failed:
1330 fc_remove_host(ha->host);
1332 scsi_remove_host(host);
1334 probe_alloc_failed:
1335 qla2x00_free_device(ha);
1337 scsi_host_put(host);
1339 probe_disable_device:
1340 pci_disable_device(pdev);
1342 return -1;
1344 EXPORT_SYMBOL_GPL(qla2x00_probe_one);
1346 void qla2x00_remove_one(struct pci_dev *pdev)
1348 scsi_qla_host_t *ha;
1350 ha = pci_get_drvdata(pdev);
1352 qla2x00_free_sysfs_attr(ha);
1354 fc_remove_host(ha->host);
1356 scsi_remove_host(ha->host);
1358 qla2x00_free_device(ha);
1360 scsi_host_put(ha->host);
1362 pci_set_drvdata(pdev, NULL);
1364 EXPORT_SYMBOL_GPL(qla2x00_remove_one);
1366 static void
1367 qla2x00_free_device(scsi_qla_host_t *ha)
1369 int ret;
1371 /* Abort any outstanding IO descriptors. */
1372 if (!IS_QLA2100(ha) && !IS_QLA2200(ha))
1373 qla2x00_cancel_io_descriptors(ha);
1375 /* turn-off interrupts on the card */
1376 if (ha->interrupts_on)
1377 qla2x00_disable_intrs(ha);
1379 /* Disable timer */
1380 if (ha->timer_active)
1381 qla2x00_stop_timer(ha);
1383 /* Kill the kernel thread for this host */
1384 if (ha->dpc_pid >= 0) {
1385 ha->dpc_should_die = 1;
1386 wmb();
1387 ret = kill_proc(ha->dpc_pid, SIGHUP, 1);
1388 if (ret) {
1389 qla_printk(KERN_ERR, ha,
1390 "Unable to signal DPC thread -- (%d)\n", ret);
1392 /* TODO: SOMETHING MORE??? */
1393 } else {
1394 wait_for_completion(&ha->dpc_exited);
1398 qla2x00_mem_free(ha);
1401 ha->flags.online = 0;
1403 /* Detach interrupts */
1404 if (ha->pdev->irq)
1405 free_irq(ha->pdev->irq, ha);
1407 /* release io space registers */
1408 if (ha->iobase)
1409 iounmap(ha->iobase);
1410 pci_release_regions(ha->pdev);
1412 pci_disable_device(ha->pdev);
1416 * qla2x00_mark_device_lost Updates fcport state when device goes offline.
1418 * Input: ha = adapter block pointer. fcport = port structure pointer.
1420 * Return: None.
1422 * Context:
1424 void qla2x00_mark_device_lost(scsi_qla_host_t *ha, fc_port_t *fcport,
1425 int do_login)
1427 if (atomic_read(&fcport->state) == FCS_ONLINE && fcport->rport)
1428 fc_remote_port_block(fcport->rport);
1430 * We may need to retry the login, so don't change the state of the
1431 * port but do the retries.
1433 if (atomic_read(&fcport->state) != FCS_DEVICE_DEAD)
1434 atomic_set(&fcport->state, FCS_DEVICE_LOST);
1436 if (!do_login)
1437 return;
1439 if (fcport->login_retry == 0) {
1440 fcport->login_retry = ha->login_retry_count;
1441 set_bit(RELOGIN_NEEDED, &ha->dpc_flags);
1443 DEBUG(printk("scsi(%ld): Port login retry: "
1444 "%02x%02x%02x%02x%02x%02x%02x%02x, "
1445 "id = 0x%04x retry cnt=%d\n",
1446 ha->host_no,
1447 fcport->port_name[0],
1448 fcport->port_name[1],
1449 fcport->port_name[2],
1450 fcport->port_name[3],
1451 fcport->port_name[4],
1452 fcport->port_name[5],
1453 fcport->port_name[6],
1454 fcport->port_name[7],
1455 fcport->loop_id,
1456 fcport->login_retry));
1461 * qla2x00_mark_all_devices_lost
1462 * Updates fcport state when device goes offline.
1464 * Input:
1465 * ha = adapter block pointer.
1466 * fcport = port structure pointer.
1468 * Return:
1469 * None.
1471 * Context:
1473 void
1474 qla2x00_mark_all_devices_lost(scsi_qla_host_t *ha)
1476 fc_port_t *fcport;
1478 list_for_each_entry(fcport, &ha->fcports, list) {
1479 if (fcport->port_type != FCT_TARGET)
1480 continue;
1483 * No point in marking the device as lost, if the device is
1484 * already DEAD.
1486 if (atomic_read(&fcport->state) == FCS_DEVICE_DEAD)
1487 continue;
1488 if (atomic_read(&fcport->state) == FCS_ONLINE && fcport->rport)
1489 fc_remote_port_block(fcport->rport);
1490 atomic_set(&fcport->state, FCS_DEVICE_LOST);
1495 * qla2x00_mem_alloc
1496 * Allocates adapter memory.
1498 * Returns:
1499 * 0 = success.
1500 * 1 = failure.
1502 static uint8_t
1503 qla2x00_mem_alloc(scsi_qla_host_t *ha)
1505 char name[16];
1506 uint8_t status = 1;
1507 int retry= 10;
1509 do {
1511 * This will loop only once if everything goes well, else some
1512 * number of retries will be performed to get around a kernel
1513 * bug where available mem is not allocated until after a
1514 * little delay and a retry.
1516 ha->request_ring = dma_alloc_coherent(&ha->pdev->dev,
1517 (ha->request_q_length + 1) * sizeof(request_t),
1518 &ha->request_dma, GFP_KERNEL);
1519 if (ha->request_ring == NULL) {
1520 qla_printk(KERN_WARNING, ha,
1521 "Memory Allocation failed - request_ring\n");
1523 qla2x00_mem_free(ha);
1524 msleep(100);
1526 continue;
1529 ha->response_ring = dma_alloc_coherent(&ha->pdev->dev,
1530 (ha->response_q_length + 1) * sizeof(response_t),
1531 &ha->response_dma, GFP_KERNEL);
1532 if (ha->response_ring == NULL) {
1533 qla_printk(KERN_WARNING, ha,
1534 "Memory Allocation failed - response_ring\n");
1536 qla2x00_mem_free(ha);
1537 msleep(100);
1539 continue;
1542 ha->gid_list = dma_alloc_coherent(&ha->pdev->dev, GID_LIST_SIZE,
1543 &ha->gid_list_dma, GFP_KERNEL);
1544 if (ha->gid_list == NULL) {
1545 qla_printk(KERN_WARNING, ha,
1546 "Memory Allocation failed - gid_list\n");
1548 qla2x00_mem_free(ha);
1549 msleep(100);
1551 continue;
1554 ha->rlc_rsp = dma_alloc_coherent(&ha->pdev->dev,
1555 sizeof(rpt_lun_cmd_rsp_t), &ha->rlc_rsp_dma, GFP_KERNEL);
1556 if (ha->rlc_rsp == NULL) {
1557 qla_printk(KERN_WARNING, ha,
1558 "Memory Allocation failed - rlc");
1560 qla2x00_mem_free(ha);
1561 msleep(100);
1563 continue;
1566 snprintf(name, sizeof(name), "qla2xxx_%ld", ha->host_no);
1567 ha->s_dma_pool = dma_pool_create(name, &ha->pdev->dev,
1568 DMA_POOL_SIZE, 8, 0);
1569 if (ha->s_dma_pool == NULL) {
1570 qla_printk(KERN_WARNING, ha,
1571 "Memory Allocation failed - s_dma_pool\n");
1573 qla2x00_mem_free(ha);
1574 msleep(100);
1576 continue;
1579 /* get consistent memory allocated for init control block */
1580 ha->init_cb = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL,
1581 &ha->init_cb_dma);
1582 if (ha->init_cb == NULL) {
1583 qla_printk(KERN_WARNING, ha,
1584 "Memory Allocation failed - init_cb\n");
1586 qla2x00_mem_free(ha);
1587 msleep(100);
1589 continue;
1591 memset(ha->init_cb, 0, sizeof(init_cb_t));
1593 /* Get consistent memory allocated for Get Port Database cmd */
1594 ha->iodesc_pd = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL,
1595 &ha->iodesc_pd_dma);
1596 if (ha->iodesc_pd == NULL) {
1597 /* error */
1598 qla_printk(KERN_WARNING, ha,
1599 "Memory Allocation failed - iodesc_pd\n");
1601 qla2x00_mem_free(ha);
1602 msleep(100);
1604 continue;
1606 memset(ha->iodesc_pd, 0, PORT_DATABASE_SIZE);
1608 /* Allocate ioctl related memory. */
1609 if (qla2x00_alloc_ioctl_mem(ha)) {
1610 qla_printk(KERN_WARNING, ha,
1611 "Memory Allocation failed - ioctl_mem\n");
1613 qla2x00_mem_free(ha);
1614 msleep(100);
1616 continue;
1619 if (qla2x00_allocate_sp_pool(ha)) {
1620 qla_printk(KERN_WARNING, ha,
1621 "Memory Allocation failed - "
1622 "qla2x00_allocate_sp_pool()\n");
1624 qla2x00_mem_free(ha);
1625 msleep(100);
1627 continue;
1630 /* Allocate memory for SNS commands */
1631 if (IS_QLA2100(ha) || IS_QLA2200(ha)) {
1632 /* Get consistent memory allocated for SNS commands */
1633 ha->sns_cmd = dma_alloc_coherent(&ha->pdev->dev,
1634 sizeof(struct sns_cmd_pkt), &ha->sns_cmd_dma,
1635 GFP_KERNEL);
1636 if (ha->sns_cmd == NULL) {
1637 /* error */
1638 qla_printk(KERN_WARNING, ha,
1639 "Memory Allocation failed - sns_cmd\n");
1641 qla2x00_mem_free(ha);
1642 msleep(100);
1644 continue;
1646 memset(ha->sns_cmd, 0, sizeof(struct sns_cmd_pkt));
1647 } else {
1648 /* Get consistent memory allocated for MS IOCB */
1649 ha->ms_iocb = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL,
1650 &ha->ms_iocb_dma);
1651 if (ha->ms_iocb == NULL) {
1652 /* error */
1653 qla_printk(KERN_WARNING, ha,
1654 "Memory Allocation failed - ms_iocb\n");
1656 qla2x00_mem_free(ha);
1657 msleep(100);
1659 continue;
1661 memset(ha->ms_iocb, 0, sizeof(ms_iocb_entry_t));
1664 * Get consistent memory allocated for CT SNS
1665 * commands
1667 ha->ct_sns = dma_alloc_coherent(&ha->pdev->dev,
1668 sizeof(struct ct_sns_pkt), &ha->ct_sns_dma,
1669 GFP_KERNEL);
1670 if (ha->ct_sns == NULL) {
1671 /* error */
1672 qla_printk(KERN_WARNING, ha,
1673 "Memory Allocation failed - ct_sns\n");
1675 qla2x00_mem_free(ha);
1676 msleep(100);
1678 continue;
1680 memset(ha->ct_sns, 0, sizeof(struct ct_sns_pkt));
1683 /* Done all allocations without any error. */
1684 status = 0;
1686 } while (retry-- && status != 0);
1688 if (status) {
1689 printk(KERN_WARNING
1690 "%s(): **** FAILED ****\n", __func__);
1693 return(status);
1697 * qla2x00_mem_free
1698 * Frees all adapter allocated memory.
1700 * Input:
1701 * ha = adapter block pointer.
1703 static void
1704 qla2x00_mem_free(scsi_qla_host_t *ha)
1706 struct list_head *fcpl, *fcptemp;
1707 fc_port_t *fcport;
1708 unsigned long wtime;/* max wait time if mbx cmd is busy. */
1710 if (ha == NULL) {
1711 /* error */
1712 DEBUG2(printk("%s(): ERROR invalid ha pointer.\n", __func__));
1713 return;
1716 /* Make sure all other threads are stopped. */
1717 wtime = 60 * HZ;
1718 while (ha->dpc_wait && wtime) {
1719 set_current_state(TASK_INTERRUPTIBLE);
1720 wtime = schedule_timeout(wtime);
1723 /* free ioctl memory */
1724 qla2x00_free_ioctl_mem(ha);
1726 /* free sp pool */
1727 qla2x00_free_sp_pool(ha);
1729 if (ha->sns_cmd)
1730 dma_free_coherent(&ha->pdev->dev, sizeof(struct sns_cmd_pkt),
1731 ha->sns_cmd, ha->sns_cmd_dma);
1733 if (ha->ct_sns)
1734 dma_free_coherent(&ha->pdev->dev, sizeof(struct ct_sns_pkt),
1735 ha->ct_sns, ha->ct_sns_dma);
1737 if (ha->ms_iocb)
1738 dma_pool_free(ha->s_dma_pool, ha->ms_iocb, ha->ms_iocb_dma);
1740 if (ha->iodesc_pd)
1741 dma_pool_free(ha->s_dma_pool, ha->iodesc_pd, ha->iodesc_pd_dma);
1743 if (ha->init_cb)
1744 dma_pool_free(ha->s_dma_pool, ha->init_cb, ha->init_cb_dma);
1746 if (ha->s_dma_pool)
1747 dma_pool_destroy(ha->s_dma_pool);
1749 if (ha->rlc_rsp)
1750 dma_free_coherent(&ha->pdev->dev,
1751 sizeof(rpt_lun_cmd_rsp_t), ha->rlc_rsp,
1752 ha->rlc_rsp_dma);
1754 if (ha->gid_list)
1755 dma_free_coherent(&ha->pdev->dev, GID_LIST_SIZE, ha->gid_list,
1756 ha->gid_list_dma);
1758 if (ha->response_ring)
1759 dma_free_coherent(&ha->pdev->dev,
1760 (ha->response_q_length + 1) * sizeof(response_t),
1761 ha->response_ring, ha->response_dma);
1763 if (ha->request_ring)
1764 dma_free_coherent(&ha->pdev->dev,
1765 (ha->request_q_length + 1) * sizeof(request_t),
1766 ha->request_ring, ha->request_dma);
1768 ha->sns_cmd = NULL;
1769 ha->sns_cmd_dma = 0;
1770 ha->ct_sns = NULL;
1771 ha->ct_sns_dma = 0;
1772 ha->ms_iocb = NULL;
1773 ha->ms_iocb_dma = 0;
1774 ha->iodesc_pd = NULL;
1775 ha->iodesc_pd_dma = 0;
1776 ha->init_cb = NULL;
1777 ha->init_cb_dma = 0;
1779 ha->s_dma_pool = NULL;
1781 ha->rlc_rsp = NULL;
1782 ha->rlc_rsp_dma = 0;
1783 ha->gid_list = NULL;
1784 ha->gid_list_dma = 0;
1786 ha->response_ring = NULL;
1787 ha->response_dma = 0;
1788 ha->request_ring = NULL;
1789 ha->request_dma = 0;
1791 list_for_each_safe(fcpl, fcptemp, &ha->fcports) {
1792 fcport = list_entry(fcpl, fc_port_t, list);
1794 /* fc ports */
1795 list_del_init(&fcport->list);
1796 kfree(fcport);
1798 INIT_LIST_HEAD(&ha->fcports);
1800 if (ha->fw_dump)
1801 free_pages((unsigned long)ha->fw_dump, ha->fw_dump_order);
1803 if (ha->fw_dump_buffer)
1804 vfree(ha->fw_dump_buffer);
1806 ha->fw_dump = NULL;
1807 ha->fw_dump_reading = 0;
1808 ha->fw_dump_buffer = NULL;
1812 * qla2x00_allocate_sp_pool
1813 * This routine is called during initialization to allocate
1814 * memory for local srb_t.
1816 * Input:
1817 * ha = adapter block pointer.
1819 * Context:
1820 * Kernel context.
1822 * Note: Sets the ref_count for non Null sp to one.
1824 static int
1825 qla2x00_allocate_sp_pool(scsi_qla_host_t *ha)
1827 int rval;
1829 rval = QLA_SUCCESS;
1830 ha->srb_mempool = mempool_create(SRB_MIN_REQ, mempool_alloc_slab,
1831 mempool_free_slab, srb_cachep);
1832 if (ha->srb_mempool == NULL) {
1833 qla_printk(KERN_INFO, ha, "Unable to allocate SRB mempool.\n");
1834 rval = QLA_FUNCTION_FAILED;
1836 return (rval);
1840 * This routine frees all adapter allocated memory.
1843 static void
1844 qla2x00_free_sp_pool( scsi_qla_host_t *ha)
1846 if (ha->srb_mempool) {
1847 mempool_destroy(ha->srb_mempool);
1848 ha->srb_mempool = NULL;
1852 /**************************************************************************
1853 * qla2x00_do_dpc
1854 * This kernel thread is a task that is schedule by the interrupt handler
1855 * to perform the background processing for interrupts.
1857 * Notes:
1858 * This task always run in the context of a kernel thread. It
1859 * is kick-off by the driver's detect code and starts up
1860 * up one per adapter. It immediately goes to sleep and waits for
1861 * some fibre event. When either the interrupt handler or
1862 * the timer routine detects a event it will one of the task
1863 * bits then wake us up.
1864 **************************************************************************/
1865 static int
1866 qla2x00_do_dpc(void *data)
1868 DECLARE_MUTEX_LOCKED(sem);
1869 scsi_qla_host_t *ha;
1870 fc_port_t *fcport;
1871 uint8_t status;
1872 uint16_t next_loopid;
1874 ha = (scsi_qla_host_t *)data;
1876 lock_kernel();
1878 daemonize("%s_dpc", ha->host_str);
1879 allow_signal(SIGHUP);
1881 ha->dpc_wait = &sem;
1883 set_user_nice(current, -20);
1885 unlock_kernel();
1887 complete(&ha->dpc_inited);
1889 while (1) {
1890 DEBUG3(printk("qla2x00: DPC handler sleeping\n"));
1892 if (down_interruptible(&sem))
1893 break;
1895 if (ha->dpc_should_die)
1896 break;
1898 DEBUG3(printk("qla2x00: DPC handler waking up\n"));
1900 /* Initialization not yet finished. Don't do anything yet. */
1901 if (!ha->flags.init_done || ha->dpc_active)
1902 continue;
1904 DEBUG3(printk("scsi(%ld): DPC handler\n", ha->host_no));
1906 ha->dpc_active = 1;
1908 if (ha->flags.mbox_busy) {
1909 ha->dpc_active = 0;
1910 continue;
1913 if (test_and_clear_bit(ISP_ABORT_NEEDED, &ha->dpc_flags)) {
1915 DEBUG(printk("scsi(%ld): dpc: sched "
1916 "qla2x00_abort_isp ha = %p\n",
1917 ha->host_no, ha));
1918 if (!(test_and_set_bit(ABORT_ISP_ACTIVE,
1919 &ha->dpc_flags))) {
1921 if (qla2x00_abort_isp(ha)) {
1922 /* failed. retry later */
1923 set_bit(ISP_ABORT_NEEDED,
1924 &ha->dpc_flags);
1926 clear_bit(ABORT_ISP_ACTIVE, &ha->dpc_flags);
1928 DEBUG(printk("scsi(%ld): dpc: qla2x00_abort_isp end\n",
1929 ha->host_no));
1932 if (test_and_clear_bit(RESET_MARKER_NEEDED, &ha->dpc_flags) &&
1933 (!(test_and_set_bit(RESET_ACTIVE, &ha->dpc_flags)))) {
1935 DEBUG(printk("scsi(%ld): qla2x00_reset_marker()\n",
1936 ha->host_no));
1938 qla2x00_rst_aen(ha);
1939 clear_bit(RESET_ACTIVE, &ha->dpc_flags);
1942 /* Retry each device up to login retry count */
1943 if ((test_and_clear_bit(RELOGIN_NEEDED, &ha->dpc_flags)) &&
1944 !test_bit(LOOP_RESYNC_NEEDED, &ha->dpc_flags) &&
1945 atomic_read(&ha->loop_state) != LOOP_DOWN) {
1947 DEBUG(printk("scsi(%ld): qla2x00_port_login()\n",
1948 ha->host_no));
1950 next_loopid = 0;
1951 list_for_each_entry(fcport, &ha->fcports, list) {
1952 if (fcport->port_type != FCT_TARGET)
1953 continue;
1956 * If the port is not ONLINE then try to login
1957 * to it if we haven't run out of retries.
1959 if (atomic_read(&fcport->state) != FCS_ONLINE &&
1960 fcport->login_retry) {
1962 fcport->login_retry--;
1963 if (fcport->flags & FCF_FABRIC_DEVICE) {
1964 if (fcport->flags &
1965 FCF_TAPE_PRESENT)
1966 qla2x00_fabric_logout(
1968 fcport->loop_id);
1969 status = qla2x00_fabric_login(
1970 ha, fcport, &next_loopid);
1971 } else
1972 status =
1973 qla2x00_local_device_login(
1974 ha, fcport->loop_id);
1976 if (status == QLA_SUCCESS) {
1977 fcport->old_loop_id = fcport->loop_id;
1979 DEBUG(printk("scsi(%ld): port login OK: logged in ID 0x%x\n",
1980 ha->host_no, fcport->loop_id));
1982 fcport->port_login_retry_count =
1983 ha->port_down_retry_count * PORT_RETRY_TIME;
1984 atomic_set(&fcport->state, FCS_ONLINE);
1985 atomic_set(&fcport->port_down_timer,
1986 ha->port_down_retry_count * PORT_RETRY_TIME);
1988 fcport->login_retry = 0;
1989 } else if (status == 1) {
1990 set_bit(RELOGIN_NEEDED, &ha->dpc_flags);
1991 /* retry the login again */
1992 DEBUG(printk("scsi(%ld): Retrying %d login again loop_id 0x%x\n",
1993 ha->host_no,
1994 fcport->login_retry, fcport->loop_id));
1995 } else {
1996 fcport->login_retry = 0;
1999 if (test_bit(LOOP_RESYNC_NEEDED, &ha->dpc_flags))
2000 break;
2002 DEBUG(printk("scsi(%ld): qla2x00_port_login - end\n",
2003 ha->host_no));
2006 if ((test_bit(LOGIN_RETRY_NEEDED, &ha->dpc_flags)) &&
2007 atomic_read(&ha->loop_state) != LOOP_DOWN) {
2009 clear_bit(LOGIN_RETRY_NEEDED, &ha->dpc_flags);
2010 DEBUG(printk("scsi(%ld): qla2x00_login_retry()\n",
2011 ha->host_no));
2013 set_bit(LOOP_RESYNC_NEEDED, &ha->dpc_flags);
2015 DEBUG(printk("scsi(%ld): qla2x00_login_retry - end\n",
2016 ha->host_no));
2019 if (test_and_clear_bit(LOOP_RESYNC_NEEDED, &ha->dpc_flags)) {
2021 DEBUG(printk("scsi(%ld): qla2x00_loop_resync()\n",
2022 ha->host_no));
2024 if (!(test_and_set_bit(LOOP_RESYNC_ACTIVE,
2025 &ha->dpc_flags))) {
2027 qla2x00_loop_resync(ha);
2029 clear_bit(LOOP_RESYNC_ACTIVE, &ha->dpc_flags);
2032 DEBUG(printk("scsi(%ld): qla2x00_loop_resync - end\n",
2033 ha->host_no));
2036 if (test_and_clear_bit(FCPORT_RESCAN_NEEDED, &ha->dpc_flags)) {
2038 DEBUG(printk("scsi(%ld): Rescan flagged fcports...\n",
2039 ha->host_no));
2041 qla2x00_rescan_fcports(ha);
2043 DEBUG(printk("scsi(%ld): Rescan flagged fcports..."
2044 "end.\n",
2045 ha->host_no));
2048 if (!ha->interrupts_on)
2049 qla2x00_enable_intrs(ha);
2051 ha->dpc_active = 0;
2052 } /* End of while(1) */
2054 DEBUG(printk("scsi(%ld): DPC handler exiting\n", ha->host_no));
2057 * Make sure that nobody tries to wake us up again.
2059 ha->dpc_wait = NULL;
2060 ha->dpc_active = 0;
2062 complete_and_exit(&ha->dpc_exited, 0);
2066 * qla2x00_rst_aen
2067 * Processes asynchronous reset.
2069 * Input:
2070 * ha = adapter block pointer.
2072 static void
2073 qla2x00_rst_aen(scsi_qla_host_t *ha)
2075 if (ha->flags.online && !ha->flags.reset_active &&
2076 !atomic_read(&ha->loop_down_timer) &&
2077 !(test_bit(ABORT_ISP_ACTIVE, &ha->dpc_flags))) {
2078 do {
2079 clear_bit(RESET_MARKER_NEEDED, &ha->dpc_flags);
2082 * Issue marker command only when we are going to start
2083 * the I/O.
2085 ha->marker_needed = 1;
2086 } while (!atomic_read(&ha->loop_down_timer) &&
2087 (test_bit(RESET_MARKER_NEEDED, &ha->dpc_flags)));
2093 * This routine will allocate SP from the free queue
2094 * input:
2095 * scsi_qla_host_t *
2096 * output:
2097 * srb_t * or NULL
2099 static srb_t *
2100 qla2x00_get_new_sp(scsi_qla_host_t *ha)
2102 srb_t *sp;
2104 sp = mempool_alloc(ha->srb_mempool, GFP_ATOMIC);
2105 if (sp)
2106 atomic_set(&sp->ref_count, 1);
2107 return (sp);
2110 static void
2111 qla2x00_sp_free_dma(scsi_qla_host_t *ha, srb_t *sp)
2113 struct scsi_cmnd *cmd = sp->cmd;
2115 if (sp->flags & SRB_DMA_VALID) {
2116 if (cmd->use_sg) {
2117 dma_unmap_sg(&ha->pdev->dev, cmd->request_buffer,
2118 cmd->use_sg, cmd->sc_data_direction);
2119 } else if (cmd->request_bufflen) {
2120 dma_unmap_single(&ha->pdev->dev, sp->dma_handle,
2121 cmd->request_bufflen, cmd->sc_data_direction);
2123 sp->flags &= ~SRB_DMA_VALID;
2127 void
2128 qla2x00_sp_compl(scsi_qla_host_t *ha, srb_t *sp)
2130 struct scsi_cmnd *cmd = sp->cmd;
2132 qla2x00_sp_free_dma(ha, sp);
2134 CMD_SP(cmd) = NULL;
2135 mempool_free(sp, ha->srb_mempool);
2137 cmd->scsi_done(cmd);
2140 /**************************************************************************
2141 * qla2x00_timer
2143 * Description:
2144 * One second timer
2146 * Context: Interrupt
2147 ***************************************************************************/
2148 static void
2149 qla2x00_timer(scsi_qla_host_t *ha)
2151 unsigned long cpu_flags = 0;
2152 fc_port_t *fcport;
2153 int start_dpc = 0;
2154 int index;
2155 srb_t *sp;
2156 int t;
2159 * Ports - Port down timer.
2161 * Whenever, a port is in the LOST state we start decrementing its port
2162 * down timer every second until it reaches zero. Once it reaches zero
2163 * the port it marked DEAD.
2165 t = 0;
2166 list_for_each_entry(fcport, &ha->fcports, list) {
2167 if (fcport->port_type != FCT_TARGET)
2168 continue;
2170 if (atomic_read(&fcport->state) == FCS_DEVICE_LOST) {
2172 if (atomic_read(&fcport->port_down_timer) == 0)
2173 continue;
2175 if (atomic_dec_and_test(&fcport->port_down_timer) != 0)
2176 atomic_set(&fcport->state, FCS_DEVICE_DEAD);
2178 DEBUG(printk("scsi(%ld): fcport-%d - port retry count: "
2179 "%d remainning\n",
2180 ha->host_no,
2181 t, atomic_read(&fcport->port_down_timer)));
2183 t++;
2184 } /* End of for fcport */
2187 /* Loop down handler. */
2188 if (atomic_read(&ha->loop_down_timer) > 0 &&
2189 !(test_bit(ABORT_ISP_ACTIVE, &ha->dpc_flags)) && ha->flags.online) {
2191 if (atomic_read(&ha->loop_down_timer) ==
2192 ha->loop_down_abort_time) {
2194 DEBUG(printk("scsi(%ld): Loop Down - aborting the "
2195 "queues before time expire\n",
2196 ha->host_no));
2198 if (!IS_QLA2100(ha) && ha->link_down_timeout)
2199 atomic_set(&ha->loop_state, LOOP_DEAD);
2201 /* Schedule an ISP abort to return any tape commands. */
2202 spin_lock_irqsave(&ha->hardware_lock, cpu_flags);
2203 for (index = 1; index < MAX_OUTSTANDING_COMMANDS;
2204 index++) {
2205 fc_port_t *sfcp;
2207 sp = ha->outstanding_cmds[index];
2208 if (!sp)
2209 continue;
2210 sfcp = sp->fcport;
2211 if (!(sfcp->flags & FCF_TAPE_PRESENT))
2212 continue;
2214 set_bit(ISP_ABORT_NEEDED, &ha->dpc_flags);
2215 break;
2217 spin_unlock_irqrestore(&ha->hardware_lock, cpu_flags);
2219 set_bit(ABORT_QUEUES_NEEDED, &ha->dpc_flags);
2220 start_dpc++;
2223 /* if the loop has been down for 4 minutes, reinit adapter */
2224 if (atomic_dec_and_test(&ha->loop_down_timer) != 0) {
2225 DEBUG(printk("scsi(%ld): Loop down exceed 4 mins - "
2226 "restarting queues.\n",
2227 ha->host_no));
2229 set_bit(RESTART_QUEUES_NEEDED, &ha->dpc_flags);
2230 start_dpc++;
2232 if (!(ha->device_flags & DFLG_NO_CABLE)) {
2233 DEBUG(printk("scsi(%ld): Loop down - "
2234 "aborting ISP.\n",
2235 ha->host_no));
2236 qla_printk(KERN_WARNING, ha,
2237 "Loop down - aborting ISP.\n");
2239 set_bit(ISP_ABORT_NEEDED, &ha->dpc_flags);
2242 DEBUG3(printk("scsi(%ld): Loop Down - seconds remainning %d\n",
2243 ha->host_no,
2244 atomic_read(&ha->loop_down_timer)));
2247 /* Schedule the DPC routine if needed */
2248 if ((test_bit(ISP_ABORT_NEEDED, &ha->dpc_flags) ||
2249 test_bit(LOOP_RESYNC_NEEDED, &ha->dpc_flags) ||
2250 start_dpc ||
2251 test_bit(LOGIN_RETRY_NEEDED, &ha->dpc_flags) ||
2252 test_bit(RESET_MARKER_NEEDED, &ha->dpc_flags) ||
2253 test_bit(RELOGIN_NEEDED, &ha->dpc_flags)) &&
2254 ha->dpc_wait && !ha->dpc_active) {
2256 up(ha->dpc_wait);
2259 qla2x00_restart_timer(ha, WATCH_INTERVAL);
2262 /* XXX(hch): crude hack to emulate a down_timeout() */
2264 qla2x00_down_timeout(struct semaphore *sema, unsigned long timeout)
2266 const unsigned int step = HZ/10;
2268 do {
2269 if (!down_trylock(sema))
2270 return 0;
2271 set_current_state(TASK_INTERRUPTIBLE);
2272 if (schedule_timeout(step))
2273 break;
2274 } while ((timeout -= step) > 0);
2276 return -ETIMEDOUT;
2280 * qla2x00_module_init - Module initialization.
2282 static int __init
2283 qla2x00_module_init(void)
2285 /* Allocate cache for SRBs. */
2286 srb_cachep = kmem_cache_create("qla2xxx_srbs", sizeof(srb_t), 0,
2287 SLAB_HWCACHE_ALIGN, NULL, NULL);
2288 if (srb_cachep == NULL) {
2289 printk(KERN_ERR
2290 "qla2xxx: Unable to allocate SRB cache...Failing load!\n");
2291 return -ENOMEM;
2294 /* Derive version string. */
2295 strcpy(qla2x00_version_str, QLA2XXX_VERSION);
2296 #if DEBUG_QLA2100
2297 strcat(qla2x00_version_str, "-debug");
2298 #endif
2299 qla2xxx_transport_template =
2300 fc_attach_transport(&qla2xxx_transport_functions);
2301 if (!qla2xxx_transport_template)
2302 return -ENODEV;
2304 printk(KERN_INFO "QLogic Fibre Channel HBA Driver\n");
2305 return 0;
2309 * qla2x00_module_exit - Module cleanup.
2311 static void __exit
2312 qla2x00_module_exit(void)
2314 kmem_cache_destroy(srb_cachep);
2315 fc_release_transport(qla2xxx_transport_template);
2318 module_init(qla2x00_module_init);
2319 module_exit(qla2x00_module_exit);
2321 MODULE_AUTHOR("QLogic Corporation");
2322 MODULE_DESCRIPTION("QLogic Fibre Channel HBA Driver");
2323 MODULE_LICENSE("GPL");
2324 MODULE_VERSION(QLA2XXX_VERSION);