patch-2.2.3 linux/drivers/scsi/qlogicfc.c

Next file: linux/drivers/scsi/qlogicfc.h
Previous file: linux/drivers/scsi/ncr53c8xx.h
Back to the patch index
Back to the overall index

diff -u --recursive --new-file v2.2.2/linux/drivers/scsi/qlogicfc.c linux/drivers/scsi/qlogicfc.c
@@ -0,0 +1,1937 @@
+/*
+ * QLogic ISP2100 SCSI-FCP
+ * Written by Erik H. Moe, ehm@cris.com
+ * Copyright 1995, Erik H. Moe
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License as published by the
+ * Free Software Foundation; either version 2, or (at your option) any
+ * later version.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * General Public License for more details.
+ */
+
+/* Renamed and updated to 1.3.x by Michael Griffith <grif@cs.ucr.edu> */
+
+/* This is a version of the isp1020 driver which was modified by
+ * Chris Loveland <cwl@iol.unh.edu> to support the isp2100
+ */
+
+/*
+ * $Date: 1995/09/22 02:23:15 $
+ * $Revision: 0.5 $
+ *
+ * $Log: isp1020.c,v $
+ * Revision 0.5  1995/09/22  02:23:15  root
+ * do auto request sense
+ *
+ * Revision 0.4  1995/08/07  04:44:33  root
+ * supply firmware with driver.
+ * numerous bug fixes/general cleanup of code.
+ *
+ * Revision 0.3  1995/07/16  16:15:39  root
+ * added reset/abort code.
+ *
+ * Revision 0.2  1995/06/29  03:14:19  root
+ * fixed biosparam.
+ * added queue protocol.
+ *
+ * Revision 0.1  1995/06/25  01:55:45  root
+ * Initial release.
+ *
+ */
+
+#include <linux/blk.h>
+#include <linux/kernel.h>
+#include <linux/string.h>
+#include <linux/ioport.h>
+#include <linux/sched.h>
+#include <linux/types.h>
+#include <linux/pci.h>
+#include <linux/delay.h>
+#include <linux/unistd.h>
+#include <asm/io.h>
+#include <asm/irq.h>
+#include <asm/spinlock.h>
+
+#include "sd.h"
+#include "hosts.h"
+#include "qlogicfc.h"
+
+/* Configuration section **************************************************** */
+
+/* Set the following macro to 1 to reload the ISP2100's firmware.  This is
+   version 1.13 of the firmware. */
+
+#define RELOAD_FIRMWARE		1
+
+#define USE_NVRAM_DEFAULTS      1
+
+
+/* Set the following to 1 to include fabric support, fabric support is 
+ * currently not as well tested as the other aspects of the driver */
+
+#define ISP2100_FABRIC          0
+
+/*  Macros used for debugging */
+/*
+#define DEBUG_ISP2100		1
+#define DEBUG_ISP2100_INT	1
+#define DEBUG_ISP2100_INTR	1
+#define DEBUG_ISP2100_SETUP	1
+
+#define DEBUG_ISP2100_FABRIC    1
+*/
+/* #define TRACE_ISP             1 */
+
+
+#define DEFAULT_LOOP_COUNT	10000000
+
+/* End Configuration section ************************************************ */
+
+#include <linux/module.h>
+
+#if TRACE_ISP
+
+#define TRACE_BUF_LEN	(32*1024)
+
+struct {
+	u_long next;
+	struct {
+		u_long time;
+		u_int index;
+		u_int addr;
+		u_char *name;
+	} buf[TRACE_BUF_LEN];
+} trace;
+
+#define TRACE(w, i, a)						\
+{								\
+	unsigned long flags;					\
+								\
+	save_flags(flags);					\
+	cli();							\
+	trace.buf[trace.next].name  = (w);			\
+	trace.buf[trace.next].time  = jiffies;			\
+	trace.buf[trace.next].index = (i);			\
+	trace.buf[trace.next].addr  = (long) (a);		\
+	trace.next = (trace.next + 1) & (TRACE_BUF_LEN - 1);	\
+	restore_flags(flags);					\
+}
+
+#else
+#define TRACE(w, i, a)
+#endif
+
+#if DEBUG_ISP2100_FABRIC
+#define DEBUG_FABRIC(x)	x
+#else
+#define DEBUG_FABRIC(x)
+#endif				/* DEBUG_ISP2100_FABRIC */
+
+
+#if DEBUG_ISP2100
+#define ENTER(x)	printk("isp2100 : entering %s()\n", x);
+#define LEAVE(x)	printk("isp2100 : leaving %s()\n", x);
+#define DEBUG(x)	x
+#else
+#define ENTER(x)
+#define LEAVE(x)
+#define DEBUG(x)
+#endif				/* DEBUG_ISP2100 */
+
+#if DEBUG_ISP2100_INTR
+#define ENTER_INTR(x)	printk("isp2100 : entering %s()\n", x);
+#define LEAVE_INTR(x)	printk("isp2100 : leaving %s()\n", x);
+#define DEBUG_INTR(x)	x
+#else
+#define ENTER_INTR(x)
+#define LEAVE_INTR(x)
+#define DEBUG_INTR(x)
+#endif				/* DEBUG ISP2100_INTR */
+
+
+#if defined(__i386__)
+#define virt_to_bus_low32(x)   virt_to_bus(x)
+#define virt_to_bus_high32(x)  0x0
+#define bus_to_virt_low32(x)   bus_to_virt(x)
+#define bus_to_virt_high32(x)  0x0
+#elif defined(__alpha__)
+#define virt_to_bus_low32(x)   ((u32) (0xffffffff & virt_to_bus(x)))
+#define virt_to_bus_high32(x)  ((u32) (0xffffffff & (virt_to_bus(x)>>32)))
+#define bus_to_virt_low32(x)   ((u32) (0xffffffff & bus_to_virt(x)))
+#define bus_to_virt_high32(x)  ((u32) (0xffffffff & (bus_to_virt(x)>>32)))
+#endif
+
+#define ISP2100_REV_ID	1
+#define ISP2100_REV_ID3        3
+
+#define MAX_TARGETS	16
+#define MAX_LUNS	8
+
+/* host configuration and control registers */
+#define HOST_HCCR	0xc0	/* host command and control */
+
+/* pci bus interface registers */
+#define FLASH_BIOS_ADDR	0x00
+#define FLASH_BIOS_DATA	0x02
+#define ISP_CTRL_STATUS	0x06	/* configuration register #1 */
+#define PCI_INTER_CTL	0x08	/* pci interupt control */
+#define PCI_INTER_STS	0x0a	/* pci interupt status */
+#define PCI_SEMAPHORE	0x0c	/* pci semaphore */
+#define PCI_NVRAM	0x0e	/* pci nvram interface */
+
+/* mailbox registers */
+#define MBOX0		0x10	/* mailbox 0 */
+#define MBOX1		0x12	/* mailbox 1 */
+#define MBOX2		0x14	/* mailbox 2 */
+#define MBOX3		0x16	/* mailbox 3 */
+#define MBOX4		0x18	/* mailbox 4 */
+#define MBOX5		0x1a	/* mailbox 5 */
+#define MBOX6		0x1c	/* mailbox 6 */
+#define MBOX7		0x1e	/* mailbox 7 */
+
+/* mailbox command complete status codes */
+#define MBOX_COMMAND_COMPLETE		0x4000
+#define INVALID_COMMAND			0x4001
+#define HOST_INTERFACE_ERROR		0x4002
+#define TEST_FAILED			0x4003
+#define COMMAND_ERROR			0x4005
+#define COMMAND_PARAM_ERROR		0x4006
+#define PORT_ID_USED                    0x4007
+#define LOOP_ID_USED                    0x4008
+#define ALL_IDS_USED                    0x4009
+
+/* async event status codes */
+#define RESET_DETECTED  		0x8001
+#define SYSTEM_ERROR			0x8002
+#define REQUEST_TRANSFER_ERROR		0x8003
+#define RESPONSE_TRANSFER_ERROR		0x8004
+#define REQUEST_QUEUE_WAKEUP		0x8005
+#define LIP_OCCURED                     0x8010
+#define LOOP_UP                         0x8011
+#define LOOP_DOWN                       0x8012
+#define LIP_RECEIVED                    0x8013
+#define PORT_DB_CHANGED                 0x8014
+#define CHANGE_NOTIFICATION             0x8015
+#define SCSI_COMMAND_COMPLETE           0x8020
+
+struct Entry_header {
+	u_char entry_type;
+	u_char entry_cnt;
+	u_char sys_def_1;
+	u_char flags;
+};
+
+/* entry header type commands */
+#define ENTRY_COMMAND		0x19
+#define ENTRY_CONTINUATION	0x0a
+#define ENTRY_STATUS		0x03
+#define ENTRY_MARKER		0x04
+
+/* entry header flag definitions */
+#define EFLAG_BUSY		2
+#define EFLAG_BAD_HEADER	4
+#define EFLAG_BAD_PAYLOAD	8
+
+struct dataseg {
+	u_int d_base_lo;
+	u_int d_base_high;
+	u_int d_count;
+};
+
+struct Command_Entry {
+	struct Entry_header hdr;
+	u_int handle;
+	u_char target_lun;
+	u_char target_id;
+	u_short rsvd1;
+	u_short control_flags;
+	u_short rsvd2;
+	u_short time_out;
+	u_short segment_cnt;
+	u_char cdb[16];
+	u_int total_byte_cnt;
+	struct dataseg dataseg[2];
+};
+
+/* command entry control flag definitions */
+#define CFLAG_NODISC		0x01
+#define CFLAG_HEAD_TAG		0x02
+#define CFLAG_ORDERED_TAG	0x04
+#define CFLAG_SIMPLE_TAG	0x08
+#define CFLAG_TAR_RTN		0x10
+#define CFLAG_READ		0x20
+#define CFLAG_WRITE		0x40
+
+struct Ext_Command_Entry {
+	struct Entry_header hdr;
+	u_int handle;
+	u_char target_lun;
+	u_char target_id;
+	u_short cdb_length;
+	u_short control_flags;
+	u_short rsvd;
+	u_short time_out;
+	u_short segment_cnt;
+	u_char cdb[44];
+};
+
+struct Continuation_Entry {
+	struct Entry_header hdr;
+	struct dataseg dataseg[5];
+};
+
+struct Marker_Entry {
+	struct Entry_header hdr;
+	u_int reserved;
+	u_char target_lun;
+	u_char target_id;
+	u_char modifier;
+	u_char rsvd;
+	u_char rsvds[52];
+};
+
+/* marker entry modifier definitions */
+#define SYNC_DEVICE	0
+#define SYNC_TARGET	1
+#define SYNC_ALL	2
+
+struct Status_Entry {
+	struct Entry_header hdr;
+	u_int handle;
+	u_short scsi_status;
+	u_short completion_status;
+	u_short state_flags;
+	u_short status_flags;
+	u_short res_info_len;
+	u_short req_sense_len;
+	u_int residual;
+	u_char res_info[8];
+	u_char req_sense_data[32];
+};
+
+/* status entry completion status definitions */
+#define CS_COMPLETE			0x0000
+#define CS_INCOMPLETE			0x0001
+#define CS_DMA_ERROR			0x0002
+#define CS_TRANSPORT_ERROR		0x0003
+#define CS_RESET_OCCURRED		0x0004
+#define CS_ABORTED			0x0005
+#define CS_TIMEOUT			0x0006
+#define CS_DATA_OVERRUN			0x0007
+#define CS_ABORT_MSG_FAILED		0x000e
+#define CS_REJECT_MSG_FAILED		0x000f
+#define CS_DATA_UNDERRUN		0x0015
+#define CS_PORT_UNAVAILABLE             0x0028
+#define CS_PORT_LOGGED_OUT              0x0029
+#define CS_PORT_CONFIG_CHANGED		0x002a
+
+/* status entry state flag definitions */
+#define SF_SENT_CDB			0x0400
+#define SF_TRANSFERRED_DATA		0x0800
+#define SF_GOT_STATUS			0x1000
+
+/* status entry status flag definitions */
+#define STF_BUS_RESET			0x0008
+#define STF_DEVICE_RESET		0x0010
+#define STF_ABORTED			0x0020
+#define STF_TIMEOUT			0x0040
+
+/* interupt control commands */
+#define ISP_EN_INT			0x8000
+#define ISP_EN_RISC			0x0008
+
+/* host control commands */
+#define HCCR_NOP			0x0000
+#define HCCR_RESET			0x1000
+#define HCCR_PAUSE			0x2000
+#define HCCR_RELEASE			0x3000
+#define HCCR_SINGLE_STEP		0x4000
+#define HCCR_SET_HOST_INTR		0x5000
+#define HCCR_CLEAR_HOST_INTR		0x6000
+#define HCCR_CLEAR_RISC_INTR		0x7000
+#define HCCR_BP_ENABLE			0x8000
+#define HCCR_BIOS_DISABLE		0x9000
+#define HCCR_TEST_MODE			0xf000
+
+#define RISC_BUSY			0x0004
+
+/* mailbox commands */
+#define MBOX_NO_OP			0x0000
+#define MBOX_LOAD_RAM			0x0001
+#define MBOX_EXEC_FIRMWARE		0x0002
+#define MBOX_DUMP_RAM			0x0003
+#define MBOX_WRITE_RAM_WORD		0x0004
+#define MBOX_READ_RAM_WORD		0x0005
+#define MBOX_MAILBOX_REG_TEST		0x0006
+#define MBOX_VERIFY_CHECKSUM		0x0007
+#define MBOX_ABOUT_FIRMWARE		0x0008
+#define MBOX_LOAD_RISC_RAM              0x0009
+#define MBOX_DUMP_RISC_RAM              0x000a
+#define MBOX_CHECK_FIRMWARE		0x000e
+#define MBOX_INIT_REQ_QUEUE		0x0010
+#define MBOX_INIT_RES_QUEUE		0x0011
+#define MBOX_EXECUTE_IOCB		0x0012
+#define MBOX_WAKE_UP			0x0013
+#define MBOX_STOP_FIRMWARE		0x0014
+#define MBOX_ABORT_IOCB			0x0015
+#define MBOX_ABORT_DEVICE		0x0016
+#define MBOX_ABORT_TARGET		0x0017
+#define MBOX_BUS_RESET			0x0018
+#define MBOX_STOP_QUEUE			0x0019
+#define MBOX_START_QUEUE		0x001a
+#define MBOX_SINGLE_STEP_QUEUE		0x001b
+#define MBOX_ABORT_QUEUE		0x001c
+#define MBOX_GET_DEV_QUEUE_STATUS	0x001d
+#define MBOX_GET_FIRMWARE_STATUS	0x001f
+#define MBOX_GET_INIT_SCSI_ID		0x0020
+#define MBOX_GET_RETRY_COUNT		0x0022
+#define MBOX_GET_TARGET_PARAMS		0x0028
+#define MBOX_GET_DEV_QUEUE_PARAMS	0x0029
+#define MBOX_SET_RETRY_COUNT		0x0032
+#define MBOX_SET_TARGET_PARAMS		0x0038
+#define MBOX_SET_DEV_QUEUE_PARAMS	0x0039
+#define MBOX_EXECUTE_IOCB64             0x0054
+#define MBOX_INIT_FIRMWARE              0x0060
+#define MBOX_GET_INIT_CB                0x0061
+#define MBOX_INIT_LIP			0x0062
+#define MBOX_GET_POS_MAP                0x0063
+#define MBOX_GET_PORT_DB                0x0064
+#define MBOX_CLEAR_ACA                  0x0065
+#define MBOX_TARGET_RESET               0x0066
+#define MBOX_CLEAR_TASK_SET             0x0067
+#define MBOX_ABORT_TASK_SET             0x0068
+#define MBOX_GET_FIRMWARE_STATE         0x0069
+#define MBOX_GET_PORT_NAME              0x006a
+#define MBOX_SEND_SNS                   0x006e
+#define MBOX_PORT_LOGIN                 0x006f
+#define MBOX_SEND_CHANGE_REQUEST        0x0070
+#define MBOX_PORT_LOGOUT                0x0071
+
+#include "qlogicfc_asm.c"
+
+/* Each element in mbox_param is an 8 bit bitmap where each bit indicates
+   if that mbox should be copied as input.  For example 0x2 would mean
+   only copy mbox1. */
+
+const u_char mbox_param[] =
+{
+	0x01,			/* MBOX_NO_OP */
+	0x1f,			/* MBOX_LOAD_RAM */
+	0x03,			/* MBOX_EXEC_FIRMWARE */
+	0x1f,			/* MBOX_DUMP_RAM */
+	0x07,			/* MBOX_WRITE_RAM_WORD */
+	0x03,			/* MBOX_READ_RAM_WORD */
+	0xff,			/* MBOX_MAILBOX_REG_TEST */
+	0x03,			/* MBOX_VERIFY_CHECKSUM */
+	0x01,			/* MBOX_ABOUT_FIRMWARE */
+	0xff,			/* MBOX_LOAD_RISC_RAM */
+	0xff,			/* MBOX_DUMP_RISC_RAM */
+	0x00,			/* 0x000b */
+	0x00,			/* 0x000c */
+	0x00,			/* 0x000d */
+	0x01,			/* MBOX_CHECK_FIRMWARE */
+	0x00,			/* 0x000f */
+	0x1f,			/* MBOX_INIT_REQ_QUEUE */
+	0x2f,			/* MBOX_INIT_RES_QUEUE */
+	0x0f,			/* MBOX_EXECUTE_IOCB */
+	0x03,			/* MBOX_WAKE_UP */
+	0x01,			/* MBOX_STOP_FIRMWARE */
+	0x0f,			/* MBOX_ABORT_IOCB */
+	0x03,			/* MBOX_ABORT_DEVICE */
+	0x07,			/* MBOX_ABORT_TARGET */
+	0x03,			/* MBOX_BUS_RESET */
+	0x03,			/* MBOX_STOP_QUEUE */
+	0x03,			/* MBOX_START_QUEUE */
+	0x03,			/* MBOX_SINGLE_STEP_QUEUE */
+	0x03,			/* MBOX_ABORT_QUEUE */
+	0x03,			/* MBOX_GET_DEV_QUEUE_STATUS */
+	0x00,			/* 0x001e */
+	0x01,			/* MBOX_GET_FIRMWARE_STATUS */
+	0x01,			/* MBOX_GET_INIT_SCSI_ID */
+	0x00,			/* 0x0021 */
+	0x01,			/* MBOX_GET_RETRY_COUNT */
+	0x00,			/* 0x0023 */
+	0x00,			/* 0x0024 */
+	0x00,			/* 0x0025 */
+	0x00,			/* 0x0026 */
+	0x00,			/* 0x0027 */
+	0x03,			/* MBOX_GET_TARGET_PARAMS */
+	0x03,			/* MBOX_GET_DEV_QUEUE_PARAMS */
+	0x00,			/* 0x002a */
+	0x00,			/* 0x002b */
+	0x00,			/* 0x002c */
+	0x00,			/* 0x002d */
+	0x00,			/* 0x002e */
+	0x00,			/* 0x002f */
+	0x00,			/* 0x0030 */
+	0x00,			/* 0x0031 */
+	0x07,			/* MBOX_SET_RETRY_COUNT */
+	0x00,			/* 0x0033 */
+	0x00,			/* 0x0034 */
+	0x00,			/* 0x0035 */
+	0x00,			/* 0x0036 */
+	0x00,			/* 0x0037 */
+	0x0f,			/* MBOX_SET_TARGET_PARAMS */
+	0x0f,			/* MBOX_SET_DEV_QUEUE_PARAMS */
+	0x00,			/* 0x003a */
+	0x00,			/* 0x003b */
+	0x00,			/* 0x003c */
+	0x00,			/* 0x003d */
+	0x00,			/* 0x003e */
+	0x00,			/* 0x003f */
+	0x00,			/* 0x0040 */
+	0x00,			/* 0x0041 */
+	0x00,			/* 0x0042 */
+	0x00,			/* 0x0043 */
+	0x00,			/* 0x0044 */
+	0x00,			/* 0x0045 */
+	0x00,			/* 0x0046 */
+	0x00,			/* 0x0047 */
+	0x00,			/* 0x0048 */
+	0x00,			/* 0x0049 */
+	0x00,			/* 0x004a */
+	0x00,			/* 0x004b */
+	0x00,			/* 0x004c */
+	0x00,			/* 0x004d */
+	0x00,			/* 0x004e */
+	0x00,			/* 0x004f */
+	0x00,			/* 0x0050 */
+	0x00,			/* 0x0051 */
+	0x00,			/* 0x0052 */
+	0x00,			/* 0x0053 */
+	0xcf,			/* MBOX_EXECUTE_IOCB64 */
+	0x00,			/* 0x0055 */
+	0x00,			/* 0x0056 */
+	0x00,			/* 0x0057 */
+	0x00,			/* 0x0058 */
+	0x00,			/* 0x0059 */
+	0x00,			/* 0x005a */
+	0x00,			/* 0x005b */
+	0x00,			/* 0x005c */
+	0x00,			/* 0x005d */
+	0x00,			/* 0x005e */
+	0x00,			/* 0x005f */
+	0xff,			/* MBOX_INIT_FIRMWARE */
+	0xcd,			/* MBOX_GET_INIT_CB */
+	0x01,			/* MBOX_INIT_LIP */
+	0xcd,			/* MBOX_GET_POS_MAP */
+	0xcf,			/* MBOX_GET_PORT_DB */
+	0x03,			/* MBOX_CLEAR_ACA */
+	0x03,			/* MBOX_TARGET_RESET */
+	0x03,			/* MBOX_CLEAR_TASK_SET */
+	0x03,			/* MBOX_ABORT_TASK_SET */
+	0x01,			/* MBOX_GET_FIRMWARE_STATE */
+	0x03,			/* MBOX_GET_PORT_NAME */
+	0x00,			/* 0x006b */
+	0x00,			/* 0x006c */
+	0x00,			/* 0x006d */
+	0xcf,			/* MBOX_SEND_SNS */
+	0x0f,			/* MBOX_PORT_LOGIN */
+	0x03,			/* MBOX_SEND_CHANGE_REQUEST */
+	0x03,			/* MBOX_PORT_LOGOUT */
+};
+
+#define MAX_MBOX_COMMAND	(sizeof(mbox_param)/sizeof(u_short))
+
+
+struct id_name_map {
+	u64 wwn;
+	u_char loop_id;
+};
+
+struct sns_cb {
+	u_short len;
+	u_short res1;
+	u_int response_low;
+	u_int response_high;
+	u_short sub_len;
+	u_short res2;
+	u_short data[22];
+};
+
+/* address of instance of this struct is passed to adapter to initialize things
+ */
+struct init_cb {
+	u_char version;
+	u_char reseverd1[1];
+	u_short firm_opts;
+	u_short max_frame_len;
+	u_short max_iocb;
+	u_short exec_throttle;
+	u_char retry_cnt;
+	u_char retry_delay;
+	u_short node_name[4];
+	u_short hard_addr;
+	u_char reserved2[10];
+	u_short req_queue_out;
+	u_short res_queue_in;
+	u_short req_queue_len;
+	u_short res_queue_len;
+	u_int req_queue_addr_lo;
+	u_int req_queue_addr_high;
+	u_int res_queue_addr_lo;
+	u_int res_queue_addr_high;
+};
+
+/*
+ * The result queue can be quite a bit smaller since continuation entries
+ * do not show up there:
+ */
+#define RES_QUEUE_LEN		((QLOGICFC_REQ_QUEUE_LEN + 1) / 8 - 1)
+#define QUEUE_ENTRY_LEN		64
+
+#if ISP2100_FABRIC
+#define QLOGICFC_MAX_ID    0xff
+#else
+#define QLOGICFC_MAX_ID    0x80
+#endif
+
+struct isp2100_hostdata {
+	u_char revision;
+	struct pci_dev *pci_dev;
+	/* result and request queues (shared with isp2100): */
+	u_int req_in_ptr;	/* index of next request slot */
+	u_int res_out_ptr;	/* index of next result slot */
+
+	/* this is here so the queues are nicely aligned */
+	long send_marker;	/* do we need to send a marker? */
+
+	char res[RES_QUEUE_LEN + 1][QUEUE_ENTRY_LEN];
+	char req[QLOGICFC_REQ_QUEUE_LEN + 1][QUEUE_ENTRY_LEN];
+	struct init_cb control_block;
+	int loop_up;
+	unsigned long int tag_ages[126];
+	Scsi_Cmnd *handle_ptrs[QLOGICFC_REQ_QUEUE_LEN + 1];
+	unsigned long handle_serials[QLOGICFC_REQ_QUEUE_LEN + 1];
+	struct id_name_map port_db[QLOGICFC_MAX_ID + 1];
+	u_char mbox_done;
+	u64 wwn;
+	u_int port_id;
+	u_char queued;
+};
+
+
+/* queue length's _must_ be power of two: */
+#define QUEUE_DEPTH(in, out, ql)	((in - out) & (ql))
+#define REQ_QUEUE_DEPTH(in, out)	QUEUE_DEPTH(in, out, 		     \
+						    QLOGICFC_REQ_QUEUE_LEN)
+#define RES_QUEUE_DEPTH(in, out)	QUEUE_DEPTH(in, out, RES_QUEUE_LEN)
+
+static void isp2100_enable_irqs(struct Scsi_Host *);
+static void isp2100_disable_irqs(struct Scsi_Host *);
+static int isp2100_init(struct Scsi_Host *);
+static int isp2100_reset_hardware(struct Scsi_Host *);
+static int isp2100_mbox_command(struct Scsi_Host *, u_short[]);
+static int isp2100_return_status(struct Status_Entry *);
+static void isp2100_intr_handler(int, void *, struct pt_regs *);
+static void do_isp2100_intr_handler(int, void *, struct pt_regs *);
+static int isp2100_make_portdb(struct Scsi_Host *);
+
+#if ISP2100_FABRIC
+static int isp2100_init_fabric(struct Scsi_Host *, struct id_name_map *, int);
+#endif
+
+#if USE_NVRAM_DEFAULTS
+static int isp2100_get_nvram_defaults(struct Scsi_Host *, struct init_cb *);
+static u_short isp2100_read_nvram_word(struct Scsi_Host *, u_short);
+#endif
+
+#if DEBUG_ISP2100
+static void isp2100_print_scsi_cmd(Scsi_Cmnd *);
+#endif
+
+#if DEBUG_ISP2100_INTR
+static void isp2100_print_status_entry(struct Status_Entry *);
+#endif
+
+static struct proc_dir_entry proc_scsi_isp2100 =
+{
+	PROC_SCSI_QLOGICFC, 7, "isp2100",
+	S_IFDIR | S_IRUGO | S_IXUGO, 2
+};
+
+
+static inline void isp2100_enable_irqs(struct Scsi_Host *host)
+{
+	outw(ISP_EN_INT | ISP_EN_RISC, host->io_port + PCI_INTER_CTL);
+}
+
+
+static inline void isp2100_disable_irqs(struct Scsi_Host *host)
+{
+	outw(0x0, host->io_port + PCI_INTER_CTL);
+}
+
+
+int isp2100_detect(Scsi_Host_Template * tmpt)
+{
+	int hosts = 0;
+	int wait_time;
+	struct Scsi_Host *host = NULL;
+	struct isp2100_hostdata *hostdata;
+	struct pci_dev *pdev = NULL;
+
+	ENTER("isp2100_detect");
+
+	tmpt->proc_dir = &proc_scsi_isp2100;
+
+	if (pci_present() == 0) {
+		printk("qlogicfc : PCI not present\n");
+		return 0;
+	}
+	while ((pdev = pci_find_device(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP2100, pdev))) {
+
+		host = scsi_register(tmpt, sizeof(struct isp2100_hostdata));
+		host->max_id = QLOGICFC_MAX_ID + 1;
+		host->hostt->use_new_eh_code = 1;
+		hostdata = (struct isp2100_hostdata *) host->hostdata;
+
+		memset(hostdata, 0, sizeof(struct isp2100_hostdata));
+		hostdata->pci_dev = pdev;
+
+		hostdata->queued = 0;
+		/* set up the control block */
+		hostdata->control_block.version = 0x0f;
+		hostdata->control_block.firm_opts = 0x010c;
+		hostdata->control_block.max_frame_len = 2048;
+		hostdata->control_block.max_iocb = 256;
+		hostdata->control_block.exec_throttle = 8;
+		hostdata->control_block.retry_delay = 5;
+		hostdata->control_block.retry_cnt = 0;
+		hostdata->control_block.node_name[0] = 0x0020;
+		hostdata->control_block.node_name[1] = 0xE000;
+		hostdata->control_block.node_name[2] = 0x008B;
+		hostdata->control_block.node_name[3] = 0x0000;
+		hostdata->control_block.hard_addr = 0x0003;
+		hostdata->control_block.req_queue_len = QLOGICFC_REQ_QUEUE_LEN + 1;
+		hostdata->control_block.res_queue_len = RES_QUEUE_LEN + 1;
+		hostdata->control_block.res_queue_addr_lo = virt_to_bus_low32(&hostdata->res);
+		hostdata->control_block.res_queue_addr_high = virt_to_bus_high32(&hostdata->res);
+		hostdata->control_block.req_queue_addr_lo = virt_to_bus_low32(&hostdata->req);
+		hostdata->control_block.req_queue_addr_high = virt_to_bus_high32(&hostdata->req);
+
+		hostdata->loop_up = 0;
+
+		if (isp2100_init(host) || isp2100_reset_hardware(host)) {
+			scsi_unregister(host);
+			continue;
+		}
+		host->this_id = tmpt->this_id;
+
+		if (request_irq(host->irq, do_isp2100_intr_handler, SA_INTERRUPT | SA_SHIRQ, "qlogicfc", host)) {
+			printk("qlogicfc : interrupt %d already in use\n",
+			       host->irq);
+			scsi_unregister(host);
+			continue;
+		}
+		if (check_region(host->io_port, 0xff)) {
+			printk("qlogicfc : i/o region 0x%lx-0x%lx already "
+			       "in use\n",
+			       host->io_port, host->io_port + 0xff);
+			free_irq(host->irq, host);
+			scsi_unregister(host);
+			continue;
+		}
+		request_region(host->io_port, 0xff, "qlogicfc");
+
+		outw(0x0, host->io_port + PCI_SEMAPHORE);
+		outw(HCCR_CLEAR_RISC_INTR, host->io_port + HOST_HCCR);
+		isp2100_enable_irqs(host);
+		/* wait for the loop to come up */
+		for (wait_time = jiffies + 20 * HZ; wait_time > jiffies && hostdata->loop_up == 0;)
+			barrier();
+
+		if (hostdata->loop_up == 0) {
+			printk("qlogicfc: loop is not up\n");
+			release_region(host->io_port, 0xff);
+			free_irq(host->irq, host);
+			scsi_unregister(host);
+			continue;
+		}
+		hosts++;
+	}
+
+
+	/* this busy loop should not be needed but the isp2100 seems to need 
+	   some time before recognizing it is attached to a fabric */
+
+#if ISP2100_FABRIC
+	for (wait_time = jiffies + 5 * HZ; wait_time > jiffies;)
+		barrier();
+#endif
+
+	LEAVE("isp2100_detect");
+
+	return hosts;
+}
+
+
+static int isp2100_make_portdb(struct Scsi_Host *host)
+{
+
+	short param[8];
+	int i, j;
+	struct id_name_map temp[QLOGICFC_MAX_ID + 1];
+	struct isp2100_hostdata *hostdata;
+
+	isp2100_disable_irqs(host);
+
+	memset(temp, 0, sizeof(temp));
+	hostdata = (struct isp2100_hostdata *) host->hostdata;
+
+#if ISP2100_FABRIC
+	for (i = 0x81; i < QLOGICFC_MAX_ID; i++) {
+		param[0] = MBOX_PORT_LOGOUT;
+		param[1] = i << 8;
+		param[2] = 0;
+		param[3] = 0;
+
+		isp2100_mbox_command(host, param);
+
+		if (param[0] != MBOX_COMMAND_COMPLETE) {
+			printk("logout failed %x  %x\n", i, param[0]);
+		}
+	}
+#endif
+
+
+	param[0] = MBOX_GET_INIT_SCSI_ID;
+
+	isp2100_mbox_command(host, param);
+
+	if (param[0] == MBOX_COMMAND_COMPLETE) {
+		host->this_id = param[1];
+		hostdata->port_id = ((u_int) param[3]) << 16;
+		hostdata->port_id |= param[2];
+	}
+
+	for (i = 0, j = 0; i <= QLOGICFC_MAX_ID; i++) {
+	        temp[i].loop_id = host->this_id;
+
+		param[0] = MBOX_GET_PORT_NAME;
+		param[1] = (i << 8) & 0xff00;
+
+		isp2100_mbox_command(host, param);
+
+		if (param[0] == MBOX_COMMAND_COMPLETE) {
+			temp[j].loop_id = i;
+			temp[j].wwn = ((u64) (param[2] & 0xff)) << 56;
+			temp[j].wwn |= ((u64) ((param[2] >> 8) & 0xff)) << 48;
+			temp[j].wwn |= ((u64) (param[3] & 0xff)) << 40;
+			temp[j].wwn |= ((u64) ((param[3] >> 8) & 0xff)) << 32;
+			temp[j].wwn |= ((u64) (param[6] & 0xff)) << 24;
+			temp[j].wwn |= ((u64) ((param[6] >> 8) & 0xff)) << 16;
+			temp[j].wwn |= ((u64) (param[7] & 0xff)) << 8;
+			temp[j].wwn |= ((u64) ((param[7] >> 8) & 0xff));
+
+			j++;
+
+		}
+	}
+
+
+#if ISP2100_FABRIC
+	isp2100_init_fabric(host, temp, j);
+#endif
+
+	for (i = 0; i <= QLOGICFC_MAX_ID; i++) {
+		if (temp[i].wwn != hostdata->port_db[i].wwn) {
+			for (j = 0; j <= QLOGICFC_MAX_ID; j++) {
+				if (temp[j].wwn == hostdata->port_db[i].wwn) {
+					hostdata->port_db[i].loop_id = temp[j].loop_id;
+					break;
+				}
+			}
+			if (j == QLOGICFC_MAX_ID + 1)
+				hostdata->port_db[i].loop_id = host->this_id;
+
+			for (j = 0; j <= QLOGICFC_MAX_ID; j++) {
+				if (hostdata->port_db[j].wwn == temp[i].wwn || !hostdata->port_db[j].wwn) {
+					break;
+				}
+			}
+			if (j == QLOGICFC_MAX_ID + 1)
+				printk("qlogicfc.c: Too many scsi devices, no more room in port map.\n");
+			if (!hostdata->port_db[j].wwn) {
+				hostdata->port_db[j].loop_id = temp[i].loop_id;
+				hostdata->port_db[j].wwn = temp[i].wwn;
+			}
+		} else
+			hostdata->port_db[i].loop_id = temp[i].loop_id;
+
+	}
+
+	isp2100_enable_irqs(host);
+
+	return 0;
+}
+
+
+#if ISP2100_FABRIC
+
+int isp2100_init_fabric(struct Scsi_Host *host, struct id_name_map *port_db, int j)
+{
+
+	u_short param[8];
+	u64 wwn;
+	int done = 0;
+	u_short loop_id = 0x81;
+	u_short scsi_id = j;
+	u_int port_id;
+	struct sns_cb req;
+	u_char sns_response[608];
+	struct isp2100_hostdata *hostdata;
+
+	hostdata = (struct isp2100_hostdata *) host->hostdata;
+
+	DEBUG_FABRIC(printk("qlogicfc.c: Checking for a fabric.\n"));
+	param[0] = MBOX_GET_PORT_NAME;
+	param[1] = 0x7E00;
+
+	isp2100_mbox_command(host, param);
+
+	if (param[0] != MBOX_COMMAND_COMPLETE) {
+		DEBUG_FABRIC(printk("fabric check result %x\n", param[0]));
+		return 0;
+	}
+	printk("qlogicfc.c: Fabric found.\n");
+
+
+	port_id = hostdata->port_id;
+	while (!done) {
+		memset(&req, 0, sizeof(req));
+
+		req.len = 304;
+		req.response_low = virt_to_bus_low32(sns_response);
+		req.response_high = virt_to_bus_high32(sns_response);
+		req.sub_len = 6;
+		req.data[0] = 0x0100;
+		req.data[4] = (u_short) (port_id & 0xffff);
+		req.data[5] = (u_short) (port_id >> 16 & 0xffff);
+
+		param[0] = MBOX_SEND_SNS;
+		param[1] = 14;
+		param[2] = virt_to_bus_low32(&req) >> 16;
+		param[3] = virt_to_bus_low32(&req);
+		param[6] = virt_to_bus_high32(&req) >> 16;
+		param[7] = virt_to_bus_high32(&req);
+
+		isp2100_mbox_command(host, param);
+
+		if (param[0] == MBOX_COMMAND_COMPLETE) {
+			DEBUG_FABRIC(printk("found node %02x%02x%02x%02x%02x%02x%02x%02x ", sns_response[20], sns_response[21], sns_response[22], sns_response[23], sns_response[24], sns_response[25], sns_response[26], sns_response[27]));
+			DEBUG_FABRIC(printk("  port id: %02x%02x%02x\n", sns_response[17], sns_response[18], sns_response[19]));
+			port_id = ((u_int) sns_response[17]) << 16;
+			port_id |= ((u_int) sns_response[18]) << 8;
+			port_id |= ((u_int) sns_response[19]);
+			wwn = ((u64) sns_response[20]) << 56;
+			wwn |= ((u64) sns_response[21]) << 48;
+			wwn |= ((u64) sns_response[22]) << 40;
+			wwn |= ((u64) sns_response[23]) << 32;
+			wwn |= ((u64) sns_response[24]) << 24;
+			wwn |= ((u64) sns_response[25]) << 16;
+			wwn |= ((u64) sns_response[26]) << 8;
+			wwn |= ((u64) sns_response[27]);
+			if (hostdata->port_id >> 8 != port_id >> 8) {
+				DEBUG_FABRIC(printk("adding a fabric port: %x\n", port_id));
+				param[0] = MBOX_PORT_LOGIN;
+				param[1] = loop_id << 8;
+				param[2] = (u_short) (port_id >> 16);
+				param[3] = (u_short) (port_id);
+
+				isp2100_mbox_command(host, param);
+
+				if (param[0] == MBOX_COMMAND_COMPLETE) {
+					port_db[scsi_id].wwn = wwn;
+					port_db[scsi_id].loop_id = loop_id;
+					loop_id++;
+					scsi_id++;
+				} else {
+					printk("qlogicfc.c: Error performing port login %x\n", param[0]);
+					DEBUG_FABRIC(printk("loop_id: %x\n", loop_id));
+				}
+
+			}
+			if (hostdata->port_id == port_id)
+				done = 1;
+		} else {
+			printk("qlogicfc.c: Get All Next failed %x.\n", param[0]);
+			return 0;
+		}
+	}
+
+	return 1;
+}
+
+#endif				/* ISP2100_FABRIC */
+
+
+int isp2100_release(struct Scsi_Host *host)
+{
+	struct isp2100_hostdata *hostdata;
+
+	ENTER("isp2100_release");
+
+	hostdata = (struct isp2100_hostdata *) host->hostdata;
+
+	outw(0x0, host->io_port + PCI_INTER_CTL);
+	free_irq(host->irq, host);
+
+	release_region(host->io_port, 0xff);
+
+	LEAVE("isp2100_release");
+
+	return 0;
+}
+
+
+const char *isp2100_info(struct Scsi_Host *host)
+{
+	static char buf[80];
+	struct isp2100_hostdata *hostdata;
+	ENTER("isp2100_info");
+
+	hostdata = (struct isp2100_hostdata *) host->hostdata;
+	sprintf(buf,
+		"QLogic ISP2100 SCSI on PCI bus %02x device %02x irq %d base 0x%lx",
+		hostdata->pci_dev->bus->number, hostdata->pci_dev->devfn, host->irq,
+		host->io_port);
+
+
+	LEAVE("isp2100_info");
+
+	return buf;
+}
+
+
+/*
+ * The middle SCSI layer ensures that queuecommand never gets invoked
+ * concurrently with itself or the interrupt handler (though the
+ * interrupt handler may call this routine as part of
+ * request-completion handling).
+ */
+int isp2100_queuecommand(Scsi_Cmnd * Cmnd, void (*done) (Scsi_Cmnd *))
+{
+	int i, sg_count, n, num_free;
+	u_int in_ptr, out_ptr;
+	struct dataseg *ds;
+	struct scatterlist *sg;
+	struct Command_Entry *cmd;
+	struct Continuation_Entry *cont;
+	struct Scsi_Host *host;
+	struct isp2100_hostdata *hostdata;
+
+	ENTER("isp2100_queuecommand");
+
+	host = Cmnd->host;
+	hostdata = (struct isp2100_hostdata *) host->hostdata;
+	Cmnd->scsi_done = done;
+
+	DEBUG(isp2100_print_scsi_cmd(Cmnd));
+
+	if (hostdata->loop_up == 2) {
+		hostdata->loop_up = 1;
+		isp2100_make_portdb(host);
+		for (i = 0; hostdata->port_db[i].wwn != 0; i++) {
+			DEBUG(printk("wwn: %08x%08x  scsi_id: %x  loop_id: %x\n", (u_int) (hostdata->port_db[i].wwn >> 32), (u_int) hostdata->port_db[i].wwn, i, hostdata->port_db[i].loop_id));
+		}
+	}
+	if (hostdata->loop_up == -1) {
+		printk("qlogicfc.c: The firmware is dead, just return.\n");
+		host->max_id = 0;
+		return 0;
+	}
+	out_ptr = inw(host->io_port + MBOX4);
+	in_ptr = hostdata->req_in_ptr;
+
+	DEBUG(printk("qlogicfc : request queue depth %d\n",
+		     REQ_QUEUE_DEPTH(in_ptr, out_ptr)));
+
+	cmd = (struct Command_Entry *) &hostdata->req[in_ptr][0];
+	in_ptr = (in_ptr + 1) & QLOGICFC_REQ_QUEUE_LEN;
+	if (in_ptr == out_ptr) {
+		DEBUG(printk("qlogicfc : request queue overflow\n"));
+		return 1;
+	}
+	if (hostdata->send_marker) {
+		struct Marker_Entry *marker;
+
+		TRACE("queue marker", in_ptr, 0);
+
+		DEBUG(printk("qlogicfc : adding marker entry\n"));
+		marker = (struct Marker_Entry *) cmd;
+		memset(marker, 0, sizeof(struct Marker_Entry));
+
+		marker->hdr.entry_type = ENTRY_MARKER;
+		marker->hdr.entry_cnt = 1;
+		marker->modifier = SYNC_ALL;
+
+		hostdata->send_marker = 0;
+
+		if (((in_ptr + 1) & QLOGICFC_REQ_QUEUE_LEN) == out_ptr) {
+			outw(in_ptr, host->io_port + MBOX4);
+			hostdata->req_in_ptr = in_ptr;
+			DEBUG(printk("qlogicfc : request queue overflow\n"));
+			return 1;
+		}
+		cmd = (struct Command_Entry *) &hostdata->req[in_ptr][0];
+		in_ptr = (in_ptr + 1) & QLOGICFC_REQ_QUEUE_LEN;
+	}
+	TRACE("queue command", in_ptr, Cmnd);
+
+	memset(cmd, 0, sizeof(struct Command_Entry));
+
+	/* find a free handle mapping slot */
+	for (i = in_ptr; i != (in_ptr - 1) && hostdata->handle_ptrs[i]; i = ((i + 1) % (QLOGICFC_REQ_QUEUE_LEN + 1)));
+
+	if (!hostdata->handle_ptrs[i]) {
+		cmd->handle = i;
+		hostdata->handle_ptrs[i] = Cmnd;
+		hostdata->handle_serials[i] = Cmnd->serial_number;
+	} else
+		printk("qlogicfc: no handle slots, this should not happen.\n");
+
+	cmd->hdr.entry_type = ENTRY_COMMAND;
+	cmd->hdr.entry_cnt = 1;
+	cmd->target_lun = Cmnd->lun;
+	cmd->target_id = hostdata->port_db[Cmnd->target].loop_id;
+	cmd->total_byte_cnt = (u_int) Cmnd->request_bufflen;
+	cmd->time_out = SCSI_TIMEOUT / HZ;
+
+	memcpy(cmd->cdb, Cmnd->cmnd, Cmnd->cmd_len);
+
+	if (Cmnd->use_sg) {
+		cmd->segment_cnt = sg_count = Cmnd->use_sg;
+		sg = (struct scatterlist *) Cmnd->request_buffer;
+		ds = cmd->dataseg;
+		/* fill in first two sg entries: */
+		n = sg_count;
+		if (n > 2)
+			n = 2;
+		for (i = 0; i < n; i++) {
+			ds[i].d_base_lo = virt_to_bus_low32(sg->address);
+			ds[i].d_base_high = virt_to_bus_high32(sg->address);
+			ds[i].d_count = sg->length;
+			++sg;
+		}
+		sg_count -= 2;
+
+		while (sg_count > 0) {
+			++cmd->hdr.entry_cnt;
+			cont = (struct Continuation_Entry *)
+			    &hostdata->req[in_ptr][0];
+			memset(cont, 0, sizeof(struct Continuation_Entry));
+			in_ptr = (in_ptr + 1) & QLOGICFC_REQ_QUEUE_LEN;
+			if (in_ptr == out_ptr) {
+				DEBUG(printk("isp2100: unexpected request queue overflow\n"));
+				return 1;
+			}
+			TRACE("queue continuation", in_ptr, 0);
+			cont->hdr.entry_type = ENTRY_CONTINUATION;
+			ds = cont->dataseg;
+			n = sg_count;
+			if (n > 5)
+				n = 5;
+			for (i = 0; i < n; ++i) {
+				ds[i].d_base_lo = virt_to_bus_low32(sg->address);
+				ds[i].d_base_high = virt_to_bus_high32(sg->address);
+				ds[i].d_count = sg->length;
+				++sg;
+			}
+			sg_count -= n;
+		}
+	} else {
+		cmd->dataseg[0].d_base_lo = virt_to_bus_low32(Cmnd->request_buffer);
+		cmd->dataseg[0].d_base_high = virt_to_bus_high32(Cmnd->request_buffer);
+		cmd->dataseg[0].d_count =
+		    (u_int) Cmnd->request_bufflen;
+		cmd->segment_cnt = 1;
+	}
+
+	switch (Cmnd->cmnd[0]) {
+	case WRITE_10:
+	case WRITE_6:
+	case WRITE_BUFFER:
+		cmd->control_flags = CFLAG_WRITE;
+		break;
+	case REQUEST_SENSE:
+		/* scsi.c expects sense info in a different buffer */
+		cmd->dataseg[0].d_base_lo = virt_to_bus_low32(Cmnd->sense_buffer);
+		cmd->dataseg[0].d_base_high = virt_to_bus_high32(Cmnd->sense_buffer);
+		cmd->segment_cnt = 1;
+		cmd->control_flags = CFLAG_READ;
+		break;
+	default:
+		cmd->control_flags = CFLAG_READ;
+		break;
+	}
+
+
+	if (Cmnd->device->tagged_supported) {
+		switch (Cmnd->tag) {
+		case SIMPLE_QUEUE_TAG:
+			cmd->control_flags |= CFLAG_SIMPLE_TAG;
+			break;
+		case HEAD_OF_QUEUE_TAG:
+			cmd->control_flags |= CFLAG_HEAD_TAG;
+			break;
+		case ORDERED_QUEUE_TAG:
+			cmd->control_flags |= CFLAG_ORDERED_TAG;
+			break;
+		default:
+			if ((jiffies - hostdata->tag_ages[Cmnd->target]) > (5 * HZ)) {
+				cmd->control_flags |= CFLAG_ORDERED_TAG;
+				hostdata->tag_ages[Cmnd->target] = jiffies;
+			} else
+				cmd->control_flags |= CFLAG_SIMPLE_TAG;
+		}
+	}
+	outw(in_ptr, host->io_port + MBOX4);
+	hostdata->req_in_ptr = in_ptr;
+
+	hostdata->queued++;
+
+	num_free = QLOGICFC_REQ_QUEUE_LEN - REQ_QUEUE_DEPTH(in_ptr, out_ptr);
+	num_free = num_free - 2;
+	host->can_queue = hostdata->queued + num_free;
+	if (host->can_queue > QLOGICFC_REQ_QUEUE_LEN)
+		host->can_queue = QLOGICFC_REQ_QUEUE_LEN;
+	host->sg_tablesize = QLOGICFC_MAX_SG(num_free);
+
+	/* this is really gross */
+	if (host->can_queue < host->host_busy){
+	        if (host->can_queue+2 < host->host_busy) 
+		  printk("qlogicfc.c crosses its fingers.\n");
+		host->can_queue = host->host_busy;
+	}
+
+	LEAVE("isp2100_queuecommand");
+
+	return 0;
+}
+
+
+#define ASYNC_EVENT_INTERRUPT	0x01
+
+
+void do_isp2100_intr_handler(int irq, void *dev_id, struct pt_regs *regs)
+{
+	unsigned long flags;
+
+	spin_lock_irqsave(&io_request_lock, flags);
+	isp2100_intr_handler(irq, dev_id, regs);
+	spin_unlock_irqrestore(&io_request_lock, flags);
+}
+
+void isp2100_intr_handler(int irq, void *dev_id, struct pt_regs *regs)
+{
+	Scsi_Cmnd *Cmnd;
+	struct Status_Entry *sts;
+	struct Scsi_Host *host = dev_id;
+	struct isp2100_hostdata *hostdata;
+	u_int in_ptr, out_ptr, handle, num_free;
+	u_short status;
+
+	ENTER_INTR("isp2100_intr_handler");
+
+	hostdata = (struct isp2100_hostdata *) host->hostdata;
+
+	DEBUG_INTR(printk("qlogicfc : interrupt on line %d\n", irq));
+
+	if (!(inw(host->io_port + PCI_INTER_STS) & 0x08)) {
+		/* spurious interrupts can happen legally */
+		DEBUG_INTR(printk("qlogicfc: got spurious interrupt\n"));
+		return;
+	}
+	in_ptr = inw(host->io_port + MBOX5);
+	out_ptr = hostdata->res_out_ptr;
+
+	if ((inw(host->io_port + PCI_SEMAPHORE) & ASYNC_EVENT_INTERRUPT)) {
+		status = inw(host->io_port + MBOX0);
+
+		DEBUG_INTR(printk("qlogicfc : mbox completion status: %x\n",
+				  status));
+
+		switch (status) {
+		case LOOP_UP:
+			hostdata->loop_up = 2;
+			break;
+		case LOOP_DOWN:
+			hostdata->loop_up = 0;
+			break;
+		case LIP_OCCURED:
+		case CHANGE_NOTIFICATION:
+		case PORT_DB_CHANGED:
+		case LIP_RECEIVED:
+			if (hostdata->loop_up == 1)
+				hostdata->loop_up = 2;
+			break;
+		case SYSTEM_ERROR:
+			printk("The firmware just choked.\n");
+			hostdata->loop_up = -1;
+			break;
+		case SCSI_COMMAND_COMPLETE:
+			handle = inw(host->io_port + MBOX1) | (inw(host->io_port + MBOX2) << 16);
+			Cmnd = hostdata->handle_ptrs[handle];
+			hostdata->handle_ptrs[handle] = NULL;
+			hostdata->handle_serials[handle] = 0;
+			hostdata->queued--;
+			if (Cmnd != NULL) {
+				Cmnd->result = 0x0;
+				(*Cmnd->scsi_done) (Cmnd);
+			} else
+				printk("qlogicfc.c: got a null value out of handle_ptrs, this sucks\n");
+			break;
+		case MBOX_COMMAND_COMPLETE:
+		case INVALID_COMMAND:
+		case HOST_INTERFACE_ERROR:
+		case TEST_FAILED:
+		case COMMAND_ERROR:
+		case COMMAND_PARAM_ERROR:
+		case PORT_ID_USED:
+		case LOOP_ID_USED:
+		case ALL_IDS_USED:
+			hostdata->mbox_done = 1;
+			outw(HCCR_CLEAR_RISC_INTR, host->io_port + HOST_HCCR);
+			return;
+		default:
+			printk("qlogicfc: got an unknown status? %x\n", status);
+		}
+		outw(0x0, host->io_port + PCI_SEMAPHORE);
+	} else {
+		DEBUG_INTR(printk("qlogicfc : response queue update\n"));
+		DEBUG_INTR(printk("qlogicfc : response queue depth %d\n", RES_QUEUE_DEPTH(in_ptr, out_ptr)));
+
+		while (out_ptr != in_ptr) {
+			sts = (struct Status_Entry *) &hostdata->res[out_ptr][0];
+			out_ptr = (out_ptr + 1) & RES_QUEUE_LEN;
+			Cmnd = hostdata->handle_ptrs[sts->handle];
+
+			hostdata->handle_ptrs[sts->handle] = NULL;
+
+			if (hostdata->handle_serials[sts->handle] != Cmnd->serial_number) {
+				hostdata->queued--;
+				hostdata->handle_serials[sts->handle] = 0;
+				outw(out_ptr, host->io_port + MBOX5);
+				continue;
+			}
+			hostdata->handle_serials[sts->handle] = 0;
+
+			TRACE("done", out_ptr, Cmnd);
+			DEBUG_INTR(isp2100_print_status_entry(sts));
+			if (sts->hdr.entry_type == ENTRY_STATUS) {
+				Cmnd->result = isp2100_return_status(sts);
+			} else {
+				outw(out_ptr, host->io_port + MBOX5);
+				continue;
+			}
+
+			if (sts->completion_status == CS_RESET_OCCURRED
+			    || sts->completion_status == CS_ABORTED
+			    || (sts->status_flags & STF_BUS_RESET))
+				hostdata->send_marker = 1;
+
+			if (sts->scsi_status & 0x0200)
+				memcpy(Cmnd->sense_buffer, sts->req_sense_data,
+				       sizeof(Cmnd->sense_buffer));
+
+			outw(out_ptr, host->io_port + MBOX5);
+
+			hostdata->queued--;
+			if (Cmnd->scsi_done != NULL) {
+				(*Cmnd->scsi_done) (Cmnd);
+			} else
+				printk("Ouch, scsi done is NULL\n");
+		}
+		hostdata->res_out_ptr = out_ptr;
+	}
+
+
+	out_ptr = inw(host->io_port + MBOX4);
+	in_ptr = hostdata->req_in_ptr;
+
+	num_free = QLOGICFC_REQ_QUEUE_LEN - REQ_QUEUE_DEPTH(in_ptr, out_ptr);
+	num_free = num_free-2;
+	host->can_queue = hostdata->queued + num_free;
+	if (host->can_queue > QLOGICFC_REQ_QUEUE_LEN)
+		host->can_queue = QLOGICFC_REQ_QUEUE_LEN;
+	host->sg_tablesize = QLOGICFC_MAX_SG(num_free);
+
+	if (host->can_queue < host->host_busy){
+	        if (host->can_queue+2 < host->host_busy) 
+		        DEBUG(printk("qlogicfc crosses its fingers.\n"));
+		host->can_queue = host->host_busy;
+	}
+
+	outw(HCCR_CLEAR_RISC_INTR, host->io_port + HOST_HCCR);
+	LEAVE_INTR("isp2100_intr_handler");
+}
+
+
+static int isp2100_return_status(struct Status_Entry *sts)
+{
+	int host_status = DID_ERROR;
+#if DEBUG_ISP2100_INTR
+	static char *reason[] =
+	{
+		"DID_OK",
+		"DID_NO_CONNECT",
+		"DID_BUS_BUSY",
+		"DID_TIME_OUT",
+		"DID_BAD_TARGET",
+		"DID_ABORT",
+		"DID_PARITY",
+		"DID_ERROR",
+		"DID_RESET",
+		"DID_BAD_INTR"
+	};
+#endif				/* DEBUG_ISP2100_INTR */
+
+	ENTER("isp2100_return_status");
+
+	DEBUG(printk("qlogicfc : completion status = 0x%04x\n",
+		     sts->completion_status));
+
+	switch (sts->completion_status) {
+	case CS_COMPLETE:
+		host_status = DID_OK;
+		break;
+	case CS_INCOMPLETE:
+		if (!(sts->state_flags & SF_SENT_CDB))
+			host_status = DID_ERROR;
+		else if (!(sts->state_flags & SF_TRANSFERRED_DATA))
+			host_status = DID_ERROR;
+		else if (!(sts->state_flags & SF_GOT_STATUS))
+			host_status = DID_ERROR;
+		break;
+	case CS_DMA_ERROR:
+	case CS_TRANSPORT_ERROR:
+		host_status = DID_ERROR;
+		break;
+	case CS_RESET_OCCURRED:
+		host_status = DID_RESET;
+		break;
+	case CS_ABORTED:
+		host_status = DID_ABORT;
+		break;
+	case CS_TIMEOUT:
+		host_status = DID_TIME_OUT;
+		break;
+	case CS_DATA_OVERRUN:
+	case CS_ABORT_MSG_FAILED:
+		host_status = DID_ERROR;
+		break;
+	case CS_DATA_UNDERRUN:
+		host_status = DID_OK;
+		break;
+	case CS_PORT_UNAVAILABLE:
+	case CS_PORT_LOGGED_OUT:
+	case CS_PORT_CONFIG_CHANGED:
+		host_status = DID_BAD_TARGET;
+		break;
+	default:
+		printk("qlogicfc : unknown completion status 0x%04x\n",
+		       sts->completion_status);
+		host_status = DID_ERROR;
+		break;
+	}
+
+	DEBUG_INTR(printk("qlogicfc : host status (%s) scsi status %x\n",
+			  reason[host_status], sts->scsi_status));
+
+	LEAVE("isp2100_return_status");
+
+	return (sts->scsi_status & STATUS_MASK) | (host_status << 16);
+}
+
+
+int isp2100_abort(Scsi_Cmnd * Cmnd)
+{
+	u_short param[8];
+	int i;
+	struct Scsi_Host *host;
+	struct isp2100_hostdata *hostdata;
+	int return_status = SCSI_ABORT_SUCCESS;
+
+	ENTER("isp2100_abort");
+
+	host = Cmnd->host;
+	hostdata = (struct isp2100_hostdata *) host->hostdata;
+
+	for (i = 0; i < QLOGICFC_REQ_QUEUE_LEN; i++)
+		if (hostdata->handle_ptrs[i] == Cmnd)
+			break;
+
+	if (i == QLOGICFC_REQ_QUEUE_LEN)
+		return SCSI_ABORT_ERROR;
+
+	isp2100_disable_irqs(host);
+
+	param[0] = MBOX_ABORT_IOCB;
+	param[1] = (((u_short) Cmnd->target) << 8) | Cmnd->lun;
+	param[2] = i >> 16;
+	param[3] = i & 0xffff;
+
+	isp2100_mbox_command(host, param);
+
+	if (param[0] != MBOX_COMMAND_COMPLETE) {
+		printk("qlogicfc : scsi abort failure: %x\n", param[0]);
+		if (param[0] == 0x4005)
+			Cmnd->result = DID_ERROR << 16;
+		if (param[0] == 0x4006)
+			Cmnd->result = DID_BAD_TARGET << 16;
+		(*Cmnd->scsi_done) (Cmnd);
+		return_status = SCSI_ABORT_ERROR;
+	}
+	isp2100_enable_irqs(host);
+
+	LEAVE("isp2100_abort");
+
+	return return_status;
+}
+
+
+int isp2100_reset(Scsi_Cmnd * Cmnd, unsigned int reset_flags)
+{
+	u_short param[8];
+	struct Scsi_Host *host;
+	struct isp2100_hostdata *hostdata;
+	int return_status = SCSI_RESET_SUCCESS;
+
+	ENTER("isp2100_reset");
+
+	host = Cmnd->host;
+	hostdata = (struct isp2100_hostdata *) host->hostdata;
+	param[0] = MBOX_BUS_RESET;
+	param[1] = 3;
+
+	isp2100_disable_irqs(host);
+
+	isp2100_mbox_command(host, param);
+
+	if (param[0] != MBOX_COMMAND_COMPLETE) {
+		printk("qlogicfc : scsi bus reset failure: %x\n", param[0]);
+		return_status = SCSI_RESET_ERROR;
+	}
+	isp2100_enable_irqs(host);
+
+	LEAVE("isp2100_reset");
+
+	return return_status;;
+}
+
+
+int isp2100_biosparam(Disk * disk, kdev_t n, int ip[])
+{
+	int size = disk->capacity;
+
+	ENTER("isp2100_biosparam");
+
+	ip[0] = 64;
+	ip[1] = 32;
+	ip[2] = size >> 11;
+	if (ip[2] > 1024) {
+		ip[0] = 255;
+		ip[1] = 63;
+		ip[2] = size / (ip[0] * ip[1]);
+		if (ip[2] > 1023)
+			ip[2] = 1023;
+	}
+	LEAVE("isp2100_biosparam");
+
+	return 0;
+}
+
+
+static int isp2100_reset_hardware(struct Scsi_Host *host)
+{
+	u_short param[8];
+	struct isp2100_hostdata *hostdata;
+	int loop_count;
+
+	ENTER("isp2100_reset_hardware");
+
+	outw(0x01, host->io_port + ISP_CTRL_STATUS);
+	outw(HCCR_RESET, host->io_port + HOST_HCCR);
+	outw(HCCR_RELEASE, host->io_port + HOST_HCCR);
+	outw(HCCR_BIOS_DISABLE, host->io_port + HOST_HCCR);
+
+	loop_count = DEFAULT_LOOP_COUNT;
+	while (--loop_count && inw(host->io_port + HOST_HCCR) == RISC_BUSY)
+		barrier();
+	if (!loop_count)
+		printk("qlogicfc: reset_hardware loop timeout\n");
+
+
+
+#if DEBUG_ISP2100
+	printk("qlogicfc : mbox 0 0x%04x \n", inw(host->io_port + MBOX0));
+	printk("qlogicfc : mbox 1 0x%04x \n", inw(host->io_port + MBOX1));
+	printk("qlogicfc : mbox 2 0x%04x \n", inw(host->io_port + MBOX2));
+	printk("qlogicfc : mbox 3 0x%04x \n", inw(host->io_port + MBOX3));
+	printk("qlogicfc : mbox 4 0x%04x \n", inw(host->io_port + MBOX4));
+	printk("qlogicfc : mbox 5 0x%04x \n", inw(host->io_port + MBOX5));
+	printk("qlogicfc : mbox 6 0x%04x \n", inw(host->io_port + MBOX6));
+	printk("qlogicfc : mbox 7 0x%04x \n", inw(host->io_port + MBOX7));
+#endif				/* DEBUG_ISP2100 */
+
+	DEBUG(printk("qlogicfc : verifying checksum\n"));
+
+#if RELOAD_FIRMWARE
+	{
+		int i;
+		for (i = 0; i < risc_code_length01; i++) {
+			param[0] = MBOX_WRITE_RAM_WORD;
+			param[1] = risc_code_addr01 + i;
+			param[2] = risc_code01[i];
+
+			isp2100_mbox_command(host, param);
+
+			if (param[0] != MBOX_COMMAND_COMPLETE) {
+				printk("qlogicfc : firmware load failure\n");
+				return 1;
+			}
+		}
+	}
+#endif				/* RELOAD_FIRMWARE */
+
+	param[0] = MBOX_VERIFY_CHECKSUM;
+	param[1] = risc_code_addr01;
+
+	isp2100_mbox_command(host, param);
+
+	if (param[0] != MBOX_COMMAND_COMPLETE) {
+		printk("qlogicfc : ram checksum failure\n");
+		return 1;
+	}
+	DEBUG(printk("qlogicfc : executing firmware\n"));
+
+	param[0] = MBOX_EXEC_FIRMWARE;
+	param[1] = risc_code_addr01;
+
+	isp2100_mbox_command(host, param);
+
+	param[0] = MBOX_ABOUT_FIRMWARE;
+
+	isp2100_mbox_command(host, param);
+
+	if (param[0] != MBOX_COMMAND_COMPLETE) {
+		printk("qlogicfc : about firmware failure\n");
+		return 1;
+	}
+	DEBUG(printk("qlogicfc : firmware major revision %d\n", param[1]));
+	DEBUG(printk("qlogicfc : firmware minor revision %d\n", param[2]));
+
+	hostdata = (struct isp2100_hostdata *) host->hostdata;
+
+#ifdef USE_NVRAM_DEFAULTS
+
+	if (isp2100_get_nvram_defaults(host, &hostdata->control_block) != 0) {
+		printk("qlogicfc: Could not read from NVRAM\n");
+	}
+#endif
+
+	hostdata->wwn = (u64) (hostdata->control_block.node_name[0]) << 56;
+	hostdata->wwn |= (u64) (hostdata->control_block.node_name[0] & 0xff00) << 48;
+	hostdata->wwn |= (u64) (hostdata->control_block.node_name[1] & 0xff00) << 24;
+	hostdata->wwn |= (u64) (hostdata->control_block.node_name[1] & 0x00ff) << 48;
+	hostdata->wwn |= (u64) (hostdata->control_block.node_name[2] & 0x00ff) << 24;
+	hostdata->wwn |= (u64) (hostdata->control_block.node_name[2] & 0xff00) << 8;
+	hostdata->wwn |= (u64) (hostdata->control_block.node_name[3] & 0x00ff) << 8;
+	hostdata->wwn |= (u64) (hostdata->control_block.node_name[3] & 0xff00) >> 8;
+
+	param[0] = MBOX_INIT_FIRMWARE;
+	param[2] = (u_short) (virt_to_bus_low32(&hostdata->control_block) >> 16);
+	param[3] = (u_short) (virt_to_bus_low32(&hostdata->control_block) & 0xffff);
+	param[4] = 0;
+	param[5] = 0;
+	param[6] = (u_short) (virt_to_bus_high32(&hostdata->control_block) >> 16);
+	param[7] = (u_short) (virt_to_bus_high32(&hostdata->control_block) & 0xffff);
+	isp2100_mbox_command(host, param);
+	if (param[0] != MBOX_COMMAND_COMPLETE) {
+		printk("qlogicfc.c: Ouch 0x%04x\n", param[0]);
+		return 1;
+	}
+	param[0] = MBOX_GET_FIRMWARE_STATE;
+	isp2100_mbox_command(host, param);
+	if (param[0] != MBOX_COMMAND_COMPLETE) {
+		printk("qlogicfc.c: 0x%04x\n", param[0]);
+		return 1;
+	}
+
+	LEAVE("isp2100_reset_hardware");
+
+	return 0;
+}
+
+#ifdef USE_NVRAM_DEFAULTS
+
+static int isp2100_get_nvram_defaults(struct Scsi_Host *host, struct init_cb *control_block)
+{
+
+	u_short value;
+	if (isp2100_read_nvram_word(host, 0) != 0x5349)
+		return 1;
+
+	control_block->max_frame_len = isp2100_read_nvram_word(host, 5);
+	control_block->max_iocb = isp2100_read_nvram_word(host, 6);
+	control_block->exec_throttle = isp2100_read_nvram_word(host, 7);
+	value = isp2100_read_nvram_word(host, 8);
+	control_block->node_name[0] = isp2100_read_nvram_word(host, 9);
+	control_block->node_name[1] = isp2100_read_nvram_word(host, 10);
+	control_block->node_name[2] = isp2100_read_nvram_word(host, 11);
+	control_block->node_name[3] = isp2100_read_nvram_word(host, 12);
+	control_block->hard_addr = isp2100_read_nvram_word(host, 13);
+
+	return 0;
+
+}
+
+#endif
+
+static int isp2100_init(struct Scsi_Host *sh)
+{
+	u_int io_base;
+	struct isp2100_hostdata *hostdata;
+	u_char revision;
+	u_int irq;
+	u_short command;
+	struct pci_dev *pdev;
+
+
+	ENTER("isp2100_init");
+
+	hostdata = (struct isp2100_hostdata *) sh->hostdata;
+	pdev = hostdata->pci_dev;
+
+	if (pci_read_config_word(pdev, PCI_COMMAND, &command)
+	  || pci_read_config_byte(pdev, PCI_CLASS_REVISION, &revision)) {
+		printk("qlogicfc : error reading PCI configuration\n");
+		return 1;
+	}
+	io_base = pdev->base_address[0];
+	irq = pdev->irq;
+
+
+
+	if (pdev->vendor != PCI_VENDOR_ID_QLOGIC) {
+		printk("qlogicfc : 0x%04x is not QLogic vendor ID\n",
+		       pdev->vendor);
+		return 1;
+	}
+	if (pdev->device != PCI_DEVICE_ID_QLOGIC_ISP2100) {
+		printk("qlogicfc : 0x%04x does not match ISP2100 device id\n",
+		       pdev->device);
+		return 1;
+	}
+	if (command & PCI_COMMAND_IO && (io_base & 3) == 1)
+		io_base &= PCI_BASE_ADDRESS_IO_MASK;
+	else {
+		printk("qlogicfc : i/o mapping is disabled\n");
+		return 1;
+	}
+
+	if (!(command & PCI_COMMAND_MASTER)) {
+		printk("qlogicfc : bus mastering is disabled\n");
+		return 1;
+	}
+	if (revision != ISP2100_REV_ID && revision != ISP2100_REV_ID3)
+		printk("qlogicfc : new isp2100 revision ID (%d)\n", revision);
+
+
+	hostdata->revision = revision;
+
+	sh->irq = irq;
+	sh->io_port = io_base;
+
+	LEAVE("isp2100_init");
+
+	return 0;
+}
+
+#if USE_NVRAM_DEFAULTS
+
+#define NVRAM_DELAY() udelay(10)	/* 10 microsecond delay */
+
+
+u_short isp2100_read_nvram_word(struct Scsi_Host * host, u_short byte)
+{
+	int i;
+	u_short value, output, input;
+
+	outw(0x2, host->io_port + PCI_NVRAM);
+	NVRAM_DELAY();
+	outw(0x3, host->io_port + PCI_NVRAM);
+	NVRAM_DELAY();
+
+	byte &= 0xff;
+	byte |= 0x0600;
+	for (i = 10; i >= 0; i--) {
+		output = ((byte >> i) & 0x1) ? 0x4 : 0x0;
+		outw(output | 0x2, host->io_port + PCI_NVRAM);
+		NVRAM_DELAY();
+		outw(output | 0x3, host->io_port + PCI_NVRAM);
+		NVRAM_DELAY();
+		outw(output | 0x2, host->io_port + PCI_NVRAM);
+		NVRAM_DELAY();
+	}
+
+	for (i = 0xf, value = 0; i >= 0; i--) {
+		value <<= 1;
+		outw(0x3, host->io_port + PCI_NVRAM);
+		NVRAM_DELAY();
+		input = inw(host->io_port + PCI_NVRAM);
+		NVRAM_DELAY();
+		outw(0x2, host->io_port + PCI_NVRAM);
+		NVRAM_DELAY();
+		if (input & 0x8)
+			value |= 1;
+	}
+
+	outw(0x0, host->io_port + PCI_NVRAM);
+	NVRAM_DELAY();
+
+	return value;
+}
+
+
+#endif				/* USE_NVRAM_DEFAULTS */
+
+
+
+/*
+ * currently, this is only called during initialization or abort/reset,
+ * at which times interrupts are disabled, so polling is OK, I guess...
+ */
+static int isp2100_mbox_command(struct Scsi_Host *host, u_short param[])
+{
+	int loop_count;
+	struct isp2100_hostdata *hostdata = (struct isp2100_hostdata *) host->hostdata;
+
+	if (mbox_param[param[0]] == 0)
+		return 1;
+
+	loop_count = DEFAULT_LOOP_COUNT;
+	while (--loop_count && inw(host->io_port + HOST_HCCR) & 0x0080)
+		barrier();
+	if (!loop_count) {
+		printk("qlogicfc: mbox_command loop timeout #1\n");
+		param[0] = 0x4006;
+		return 1;
+	}
+	hostdata->mbox_done = 0;
+
+	if (mbox_param[param[0]] == 0)
+		printk("qlogicfc: invalid mbox command\n");
+
+	if (mbox_param[param[0]] & 0x80)
+		outw(param[7], host->io_port + MBOX7);
+	if (mbox_param[param[0]] & 0x40)
+		outw(param[6], host->io_port + MBOX6);
+	if (mbox_param[param[0]] & 0x20)
+		outw(param[5], host->io_port + MBOX5);
+	if (mbox_param[param[0]] & 0x10)
+		outw(param[4], host->io_port + MBOX4);
+	if (mbox_param[param[0]] & 0x08)
+		outw(param[3], host->io_port + MBOX3);
+	if (mbox_param[param[0]] & 0x04)
+		outw(param[2], host->io_port + MBOX2);
+	if (mbox_param[param[0]] & 0x02)
+		outw(param[1], host->io_port + MBOX1);
+	if (mbox_param[param[0]] & 0x01)
+		outw(param[0], host->io_port + MBOX0);
+
+
+	outw(HCCR_SET_HOST_INTR, host->io_port + HOST_HCCR);
+
+	while (1) {
+		loop_count = DEFAULT_LOOP_COUNT;
+		while (--loop_count && !(inw(host->io_port + PCI_INTER_STS) & 0x08)) {
+			barrier();
+		}
+
+		if (!loop_count) {
+			printk("qlogicfc: mbox_command loop timeout #2\n");
+			break;
+		}
+		isp2100_intr_handler(host->irq, host, NULL);
+
+		if (hostdata->mbox_done == 1)
+			break;
+
+	}
+
+	loop_count = DEFAULT_LOOP_COUNT;
+	while (--loop_count && inw(host->io_port + MBOX0) == 0x04) {
+		barrier();
+	}
+	if (!loop_count)
+		printk("qlogicfc: mbox_command loop timeout #3\n");
+
+	param[7] = inw(host->io_port + MBOX7);
+	param[6] = inw(host->io_port + MBOX6);
+	param[5] = inw(host->io_port + MBOX5);
+	param[4] = inw(host->io_port + MBOX4);
+	param[3] = inw(host->io_port + MBOX3);
+	param[2] = inw(host->io_port + MBOX2);
+	param[1] = inw(host->io_port + MBOX1);
+	param[0] = inw(host->io_port + MBOX0);
+
+
+	outw(0x0, host->io_port + PCI_SEMAPHORE);
+
+	if (inw(host->io_port + HOST_HCCR) & 0x0080) {
+		printk("mbox op is still pending\n");
+	}
+	return 0;
+}
+
+
+#if DEBUG_ISP2100_INTR
+
+void isp2100_print_status_entry(struct Status_Entry *status)
+{
+	printk("qlogicfc : entry count = 0x%02x, type = 0x%02x, flags = 0x%02x\n",
+	status->hdr.entry_cnt, status->hdr.entry_type, status->hdr.flags);
+	printk("qlogicfc : scsi status = 0x%04x, completion status = 0x%04x\n",
+	       status->scsi_status, status->completion_status);
+	printk("qlogicfc : state flags = 0x%04x, status flags = 0x%04x\n",
+	       status->state_flags, status->status_flags);
+	printk("qlogicfc : response info length = 0x%04x, request sense length = 0x%04x\n",
+	       status->res_info_len, status->req_sense_len);
+	printk("qlogicfc : residual transfer length = 0x%08x, response = 0x%02x\n", status->residual, status->res_info[3]);
+
+}
+
+#endif				/* DEBUG_ISP2100_INTR */
+
+
+#if DEBUG_ISP2100
+
+void isp2100_print_scsi_cmd(Scsi_Cmnd * cmd)
+{
+	int i;
+
+	printk("qlogicfc : target = 0x%02x, lun = 0x%02x, cmd_len = 0x%02x\n",
+	       cmd->target, cmd->lun, cmd->cmd_len);
+	printk("qlogicfc : command = ");
+	for (i = 0; i < cmd->cmd_len; i++)
+		printk("0x%02x ", cmd->cmnd[i]);
+	printk("\n");
+}
+
+#endif				/* DEBUG_ISP2100 */
+
+
+#ifdef MODULE
+
+Scsi_Host_Template driver_template = QLOGICFC;
+
+#include "scsi_module.c"
+
+#endif

FUNET's LINUX-ADM group, linux-adm@nic.funet.fi
TCL-scripts by Sam Shen (who was at: slshen@lbl.gov)