ftp://ftp.kernel.org/pub/linux/kernel/v2.6/linux-2.6.6.tar.bz2
[linux-2.6.git] / drivers / scsi / ini9100u.h
1 /**************************************************************************
2  * Initio 9100 device driver for Linux.
3  *
4  * Copyright (c) 1994-1998 Initio Corporation
5  * All rights reserved.
6  *
7  * This program is free software; you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License as published by
9  * the Free Software Foundation; either version 2, or (at your option)
10  * any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this program; see the file COPYING.  If not, write to
19  * the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
20  *
21  * --------------------------------------------------------------------------
22  *
23  * Redistribution and use in source and binary forms, with or without
24  * modification, are permitted provided that the following conditions
25  * are met:
26  * 1. Redistributions of source code must retain the above copyright
27  *    notice, this list of conditions, and the following disclaimer,
28  *    without modification, immediately at the beginning of the file.
29  * 2. Redistributions in binary form must reproduce the above copyright
30  *    notice, this list of conditions and the following disclaimer in the
31  *    documentation and/or other materials provided with the distribution.
32  * 3. The name of the author may not be used to endorse or promote products
33  *    derived from this software without specific prior written permission.
34  *
35  * Where this Software is combined with software released under the terms of 
36  * the GNU General Public License ("GPL") and the terms of the GPL would require the 
37  * combined work to also be released under the terms of the GPL, the terms
38  * and conditions of this License will apply in addition to those of the
39  * GPL with the exception of any terms or conditions of this License that
40  * conflict with, or are expressly prohibited by, the GPL.
41  *
42  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
43  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
44  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
45  * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR
46  * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
47  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
48  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
49  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
50  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
51  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
52  * SUCH DAMAGE.
53  *
54  *************************************************************************
55  *
56  * Module: ini9100u.h
57  * Description: INI-9100U/UW LINUX device driver header
58  * Revision History:
59  * 06/18/96 Harry Chen, Initial Version 1.00A (Beta)
60  * 06/23/98 hc  - v1.01k
61  *              - Get it work for kernel version >= 2.1.75
62  * 12/09/98 bv  - v1.03a
63  *              - Removed unused code
64  * 12/13/98 bv  - v1.03b
65  *              - Add spinlocks to HCS structure.
66  * 21/01/99 bv  - v1.03e
67  *              - Added PCI_ID structure
68  **************************************************************************/
69
70 #ifndef CVT_LINUX_VERSION
71 #define CVT_LINUX_VERSION(V,P,S)        (((V) * 65536) + ((P) * 256) + (S))
72 #endif
73
74 #ifndef LINUX_VERSION_CODE
75 #include <linux/version.h>
76 #endif
77 #include <linux/types.h>
78
79 extern int i91u_detect(Scsi_Host_Template *);
80 extern int i91u_release(struct Scsi_Host *);
81 extern int i91u_command(Scsi_Cmnd *);
82 extern int i91u_queue(Scsi_Cmnd *, void (*done) (Scsi_Cmnd *));
83 extern int i91u_abort(Scsi_Cmnd *);
84 extern int i91u_reset(Scsi_Cmnd *, unsigned int);
85 extern int i91u_biosparam(struct scsi_device *, struct block_device *,
86                 sector_t, int *);
87
88 #define i91u_REVID "Initio INI-9X00U/UW SCSI device driver; Revision: 1.03g"
89
90 #define VIRT_TO_BUS(i)  (unsigned int) virt_to_bus((void *)(i))
91 #define ULONG   unsigned long
92 #define USHORT  unsigned short
93 #define UCHAR   unsigned char
94 #define BYTE    u8
95 #define WORD    unsigned short
96 #define DWORD   unsigned long
97 #define UBYTE   u8
98 #define UWORD   unsigned short
99 #define UDWORD  unsigned long
100 #define U32   u32
101
102 #ifndef TRUE
103 #define TRUE     (1)            /* boolean true  */
104 #endif
105 #ifndef FALSE
106 #define FALSE    (0)            /* boolean false */
107 #endif
108 #ifndef FAILURE
109 #define FAILURE  (-1)
110 #endif
111
112 #define i91u_MAXQUEUE           2
113 #define TOTAL_SG_ENTRY          32
114 #define MAX_TARGETS             16
115 #define SENSE_SIZE              14
116
117 #define INI_VENDOR_ID   0x1101  /* Initio's PCI vendor ID       */
118 #define DMX_VENDOR_ID   0x134a  /* Domex's PCI vendor ID        */
119 #define I950_DEVICE_ID  0x9500  /* Initio's inic-950 product ID   */
120 #define I940_DEVICE_ID  0x9400  /* Initio's inic-940 product ID   */
121 #define I935_DEVICE_ID  0x9401  /* Initio's inic-935 product ID   */
122 #define I920_DEVICE_ID  0x0002  /* Initio's other product ID      */
123
124 /************************************************************************/
125 /*              Vendor ID/Device ID Pair Structure                      */
126 /************************************************************************/
127 typedef struct PCI_ID_Struc {
128         unsigned short vendor_id;
129         unsigned short device_id;
130 } PCI_ID;
131
132 /************************************************************************/
133 /*              Scatter-Gather Element Structure                        */
134 /************************************************************************/
135 typedef struct SG_Struc {
136         U32 SG_Ptr;             /* Data Pointer */
137         U32 SG_Len;             /* Data Length */
138 } SG;
139
140 /***********************************************************************
141                 SCSI Control Block
142 ************************************************************************/
143 typedef struct Scsi_Ctrl_Blk {
144         U32 SCB_InitioReserved[9];      /* 0 */
145
146         UBYTE SCB_Opcode;       /*24 SCB command code */
147         UBYTE SCB_Flags;        /*25 SCB Flags */
148         UBYTE SCB_Target;       /*26 Target Id */
149         UBYTE SCB_Lun;          /*27 Lun */
150         U32 SCB_BufPtr;         /*28 Data Buffer Pointer */
151         U32 SCB_BufLen;         /*2C Data Allocation Length */
152         UBYTE SCB_SGLen;        /*30 SG list # */
153         UBYTE SCB_SenseLen;     /*31 Sense Allocation Length */
154         UBYTE SCB_HaStat;       /*32 */
155         UBYTE SCB_TaStat;       /*33 */
156         UBYTE SCB_CDBLen;       /*34 CDB Length */
157         UBYTE SCB_Ident;        /*35 Identify */
158         UBYTE SCB_TagMsg;       /*36 Tag Message */
159         UBYTE SCB_TagId;        /*37 Queue Tag */
160         UBYTE SCB_CDB[12];      /*38 */
161         U32 SCB_SGPAddr;        /*44 SG List/Sense Buf phy. Addr. */
162         U32 SCB_SensePtr;       /*48 Sense data pointer */
163         void (*SCB_Post) (BYTE *, BYTE *);      /*4C POST routine */
164         Scsi_Cmnd *SCB_Srb;     /*50 SRB Pointer */
165         SG SCB_SGList[TOTAL_SG_ENTRY];  /*54 Start of SG list */
166 } SCB;
167
168 /* Opcodes of SCB_Opcode */
169 #define ExecSCSI        0x1
170 #define BusDevRst       0x2
171 #define AbortCmd        0x3
172
173 /* Bit Definition for SCB_Flags */
174 #define SCF_DONE        0x01
175 #define SCF_POST        0x02
176 #define SCF_SENSE       0x04
177 #define SCF_DIR         0x18
178 #define SCF_NO_DCHK     0x00
179 #define SCF_DIN         0x08
180 #define SCF_DOUT        0x10
181 #define SCF_NO_XF       0x18
182 #define SCF_POLL        0x40
183 #define SCF_SG          0x80
184
185 /* Error Codes for SCB_HaStat */
186 #define HOST_SEL_TOUT   0x11
187 #define HOST_DO_DU      0x12
188 #define HOST_BUS_FREE   0x13
189 #define HOST_BAD_PHAS   0x14
190 #define HOST_INV_CMD    0x16
191 #define HOST_SCSI_RST   0x1B
192 #define HOST_DEV_RST    0x1C
193
194 /* Error Codes for SCB_TaStat */
195 #define TARGET_CHKCOND  0x02
196 #define TARGET_BUSY     0x08
197
198 /* Queue tag msg: Simple_quque_tag, Head_of_queue_tag, Ordered_queue_tag */
199 #define MSG_STAG        0x20
200 #define MSG_HTAG        0x21
201 #define MSG_OTAG        0x22
202
203 /***********************************************************************
204                 Target Device Control Structure
205 **********************************************************************/
206
207 typedef struct Tar_Ctrl_Struc {
208         ULONG TCS_InitioReserved;       /* 0 */
209
210         UWORD TCS_DrvFlags;     /* 4 */
211         UBYTE TCS_DrvHead;      /* 6 */
212         UBYTE TCS_DrvSector;    /* 7 */
213 } TCS;
214
215 /***********************************************************************
216                 Target Device Control Structure
217 **********************************************************************/
218 /* Bit Definition for TCF_DrvFlags */
219 #define TCF_DRV_255_63          0x0400
220
221 /***********************************************************************
222               Host Adapter Control Structure
223 ************************************************************************/
224 typedef struct Ha_Ctrl_Struc {
225         UWORD HCS_Base;         /* 00 */
226         UWORD HCS_BIOS;         /* 02 */
227         UBYTE HCS_Intr;         /* 04 */
228         UBYTE HCS_SCSI_ID;      /* 05 */
229         UBYTE HCS_MaxTar;       /* 06 */
230         UBYTE HCS_NumScbs;      /* 07 */
231
232         UBYTE HCS_Flags;        /* 08 */
233         UBYTE HCS_Index;        /* 09 */
234         UBYTE HCS_Reserved[2];  /* 0a */
235         ULONG HCS_InitioReserved[27];   /* 0C */
236         TCS HCS_Tcs[16];        /* 78 -> 16 Targets */
237         Scsi_Cmnd *pSRB_head;   /* SRB save queue header     */
238         Scsi_Cmnd *pSRB_tail;   /* SRB save queue tail       */
239         spinlock_t HCS_AvailLock;
240         spinlock_t HCS_SemaphLock;
241         spinlock_t pSRB_lock;
242         struct pci_dev *pci_dev;
243 } HCS;
244
245 /* Bit Definition for HCB_Flags */
246 #define HCF_EXPECT_RESET        0x10
247
248 /* SCSI related definition                                              */
249 #define DISC_NOT_ALLOW          0x80    /* Disconnect is not allowed    */
250 #define DISC_ALLOW              0xC0    /* Disconnect is allowed        */