ihavar.h revision 1.1 1 1.1 tsutsui /* $NetBSD: ihavar.h,v 1.1 2001/06/03 13:43:47 tsutsui Exp $ */
2 1.1 tsutsui /*
3 1.1 tsutsui * Initio INI-9xxxU/UW SCSI Device Driver
4 1.1 tsutsui *
5 1.1 tsutsui * Copyright (c) 2000 Ken Westerback
6 1.1 tsutsui * All rights reserved.
7 1.1 tsutsui *
8 1.1 tsutsui * Redistribution and use in source and binary forms, with or without
9 1.1 tsutsui * modification, are permitted provided that the following conditions
10 1.1 tsutsui * are met:
11 1.1 tsutsui * 1. Redistributions of source code must retain the above copyright
12 1.1 tsutsui * notice, this list of conditions and the following disclaimer,
13 1.1 tsutsui * without modification, immediately at the beginning of the file.
14 1.1 tsutsui * 2. The name of the author may not be used to endorse or promote products
15 1.1 tsutsui * derived from this software without specific prior written permission.
16 1.1 tsutsui *
17 1.1 tsutsui * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
18 1.1 tsutsui * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
19 1.1 tsutsui * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
20 1.1 tsutsui * IN NO EVENT SHALL THE AUTHOR OR HIS RELATIVES BE LIABLE FOR ANY DIRECT,
21 1.1 tsutsui * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
22 1.1 tsutsui * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
23 1.1 tsutsui * SERVICES; LOSS OF MIND, USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
24 1.1 tsutsui * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
25 1.1 tsutsui * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
26 1.1 tsutsui * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
27 1.1 tsutsui * THE POSSIBILITY OF SUCH DAMAGE.
28 1.1 tsutsui *
29 1.1 tsutsui *-------------------------------------------------------------------------
30 1.1 tsutsui *
31 1.1 tsutsui * Ported from i91uscsi.h, provided by Initio Corporation, which probably
32 1.1 tsutsui * came from the same people who provided i91u.c:
33 1.1 tsutsui *
34 1.1 tsutsui * Device driver for the INI-9XXXU/UW or INIC-940/950 PCI SCSI Controller.
35 1.1 tsutsui *
36 1.1 tsutsui * FreeBSD
37 1.1 tsutsui *
38 1.1 tsutsui * Written for 386bsd and FreeBSD by
39 1.1 tsutsui * Winston Hung <winstonh (at) initio.com>
40 1.1 tsutsui *
41 1.1 tsutsui * Copyright (c) 1997-99 Initio Corp. All rights reserved.
42 1.1 tsutsui *
43 1.1 tsutsui *-------------------------------------------------------------------------
44 1.1 tsutsui */
45 1.1 tsutsui
46 1.1 tsutsui /*
47 1.1 tsutsui * Ported to NetBSD by Izumi Tsutsui <tsutsui (at) ceres.dti.ne.jp> from OpenBSD:
48 1.1 tsutsui * $OpenBSD: iha.h,v 1.2 2001/02/08 17:35:05 krw Exp $
49 1.1 tsutsui */
50 1.1 tsutsui
51 1.1 tsutsui #define IHA_MAX_SG_ENTRIES 33
52 1.1 tsutsui #define IHA_MAX_TARGETS 16
53 1.1 tsutsui #define IHA_MAX_SCB 32
54 1.1 tsutsui #define IHA_MAX_EXTENDED_MSG 4 /* SDTR(3) and WDTR(4) only */
55 1.1 tsutsui #define IHA_MAX_OFFSET 15
56 1.1 tsutsui
57 1.1 tsutsui #define SCSI_CONDITION_MET 0x04 /* SCSI Status codes not defined */
58 1.1 tsutsui #define SCSI_INTERM_COND_MET 0x14 /* in scsi_all.h */
59 1.1 tsutsui
60 1.1 tsutsui /*
61 1.1 tsutsui * Scatter-Gather Element Structure
62 1.1 tsutsui */
63 1.1 tsutsui struct iha_sg_element {
64 1.1 tsutsui u_int32_t sg_addr; /* Data Pointer */
65 1.1 tsutsui u_int32_t sg_len; /* Data Length */
66 1.1 tsutsui };
67 1.1 tsutsui
68 1.1 tsutsui struct iha_sglist {
69 1.1 tsutsui struct iha_sg_element sg_element[IHA_MAX_SG_ENTRIES];
70 1.1 tsutsui };
71 1.1 tsutsui
72 1.1 tsutsui #define IHA_SG_SIZE (sizeof(struct iha_sglist))
73 1.1 tsutsui
74 1.1 tsutsui /*
75 1.1 tsutsui * iha_scsi_req_q - SCSI Request structure used by the
76 1.1 tsutsui * Tulip (aka inic-950). Note that 32
77 1.1 tsutsui * bit pointers and ints are assumed!
78 1.1 tsutsui */
79 1.1 tsutsui
80 1.1 tsutsui struct iha_scsi_req_q {
81 1.1 tsutsui TAILQ_ENTRY(iha_scsi_req_q) chain;
82 1.1 tsutsui
83 1.1 tsutsui bus_dmamap_t dmap; /* maps xs->buf xfer buffer */
84 1.1 tsutsui
85 1.1 tsutsui int status; /* Current status of the SCB */
86 1.1 tsutsui #define STATUS_QUEUED 0 /* SCB one of Free/Done/Pend */
87 1.1 tsutsui #define STATUS_RENT 1 /* SCB allocated, not queued */
88 1.1 tsutsui #define STATUS_SELECT 2 /* SCB being selected */
89 1.1 tsutsui #define STATUS_BUSY 3 /* SCB I/O is active */
90 1.1 tsutsui int nextstat; /* Next state function to apply */
91 1.1 tsutsui int sg_index; /* Scatter/Gather Index */
92 1.1 tsutsui int sg_max; /* Scatter/Gather # valid entries */
93 1.1 tsutsui int flags; /* SCB Flags (xs->flags + private)*/
94 1.1 tsutsui #define FLAG_RSENS 0x00010000 /* Request Sense sent */
95 1.1 tsutsui #define FLAG_SG 0x00020000 /* Scatter/Gather used */
96 1.1 tsutsui int target; /* Target Id */
97 1.1 tsutsui int lun; /* Lun */
98 1.1 tsutsui
99 1.1 tsutsui u_int32_t bufaddr; /* Data Buffer Physical Addr */
100 1.1 tsutsui u_int32_t buflen; /* Data Allocation Length */
101 1.1 tsutsui int ha_stat; /* Status of Host Adapter */
102 1.1 tsutsui #define HOST_OK 0x00 /* OK - operation a success */
103 1.1 tsutsui #define HOST_TIMED_OUT 0x01 /* Request timed out */
104 1.1 tsutsui #define HOST_SPERR 0x10 /* SCSI parity error */
105 1.1 tsutsui #define HOST_SEL_TOUT 0x11 /* Selection Timeout */
106 1.1 tsutsui #define HOST_DO_DU 0x12 /* Data Over/Underrun */
107 1.1 tsutsui #define HOST_BAD_PHAS 0x14 /* Unexpected SCSI bus phase */
108 1.1 tsutsui #define HOST_SCSI_RST 0x1B /* SCSI bus was reset */
109 1.1 tsutsui #define HOST_DEV_RST 0x1C /* Device was reset */
110 1.1 tsutsui int ta_stat; /* SCSI Status Byte */
111 1.1 tsutsui int timeout; /* in milliseconds */
112 1.1 tsutsui
113 1.1 tsutsui struct scsipi_xfer *xs; /* xs this SCB is executing */
114 1.1 tsutsui struct tcs *tcs; /* tcs for SCB_Target */
115 1.1 tsutsui struct iha_sg_element *sglist;
116 1.1 tsutsui bus_size_t sgoffset; /* xfer buf offset */
117 1.1 tsutsui
118 1.1 tsutsui int senselen; /* Sense Data Allocation Length */
119 1.1 tsutsui u_int32_t senseaddr; /* Sense Data PhysicalAddress */
120 1.1 tsutsui
121 1.1 tsutsui int sg_size; /* # of valid entries in sg_list */
122 1.1 tsutsui u_int32_t sg_addr; /* SGList Physical Address */
123 1.1 tsutsui
124 1.1 tsutsui
125 1.1 tsutsui int cmdlen; /* CDB Length */
126 1.1 tsutsui u_int8_t cmd[12]; /* SCSI Command */
127 1.1 tsutsui
128 1.1 tsutsui u_int8_t scb_id; /* Identity Message */
129 1.1 tsutsui u_int8_t scb_tagmsg; /* Tag Message */
130 1.1 tsutsui u_int8_t scb_tagid; /* Queue Tag */
131 1.1 tsutsui };
132 1.1 tsutsui
133 1.1 tsutsui /*
134 1.1 tsutsui * Target Device Control Structure
135 1.1 tsutsui */
136 1.1 tsutsui struct tcs {
137 1.1 tsutsui int flags;
138 1.1 tsutsui #define FLAG_SCSI_RATE 0x0007 /* Index into tul_rate_tbl[] */
139 1.1 tsutsui #define FLAG_EN_DISC 0x0008 /* Enable disconnect */
140 1.1 tsutsui #define FLAG_NO_SYNC 0x0010 /* No sync data transfer */
141 1.1 tsutsui #define FLAG_NO_WIDE 0x0020 /* No wide data transfer */
142 1.1 tsutsui #define FLAG_1GIGA 0x0040 /* 255 hd/63 sec (64/32) */
143 1.1 tsutsui #define FLAG_SPINUP 0x0080 /* Start disk drive */
144 1.1 tsutsui #define FLAG_WIDE_DONE 0x0100 /* WDTR msg has been sent */
145 1.1 tsutsui #define FLAG_SYNC_DONE 0x0200 /* SDTR msg has been sent */
146 1.1 tsutsui #define FLAG_NO_NEG_SYNC (FLAG_NO_SYNC | FLAG_SYNC_DONE)
147 1.1 tsutsui #define FLAG_NO_NEG_WIDE (FLAG_NO_WIDE | FLAG_WIDE_DONE)
148 1.1 tsutsui #define FLAG_NO_NEGOTIATE (FLAG_NO_NEG_SYNC | FLAG_NO_NEG_WIDE)
149 1.1 tsutsui int period;
150 1.1 tsutsui int offset;
151 1.1 tsutsui int tagcnt;
152 1.1 tsutsui
153 1.1 tsutsui struct iha_scsi_req_q *ntagscb;
154 1.1 tsutsui
155 1.1 tsutsui u_int8_t syncm;
156 1.1 tsutsui u_int8_t sconfig0;
157 1.1 tsutsui };
158 1.1 tsutsui
159 1.1 tsutsui struct iha_softc {
160 1.1 tsutsui struct device sc_dev;
161 1.1 tsutsui
162 1.1 tsutsui bus_space_tag_t sc_iot;
163 1.1 tsutsui bus_space_handle_t sc_ioh;
164 1.1 tsutsui
165 1.1 tsutsui bus_dma_tag_t sc_dmat;
166 1.1 tsutsui bus_dmamap_t sc_dmamap;
167 1.1 tsutsui
168 1.1 tsutsui struct scsipi_adapter sc_adapter;
169 1.1 tsutsui struct scsipi_channel sc_channel;
170 1.1 tsutsui
171 1.1 tsutsui int sc_id;
172 1.1 tsutsui void *sc_ih;
173 1.1 tsutsui
174 1.1 tsutsui /*
175 1.1 tsutsui * Initio specific fields
176 1.1 tsutsui */
177 1.1 tsutsui int sc_flags;
178 1.1 tsutsui #define FLAG_EXPECT_DISC 0x01
179 1.1 tsutsui #define FLAG_EXPECT_SELECT 0x02
180 1.1 tsutsui #define FLAG_EXPECT_RESET 0x10
181 1.1 tsutsui #define FLAG_EXPECT_DONE_DISC 0x20
182 1.1 tsutsui int sc_semaph;
183 1.1 tsutsui #define SEMAPH_IN_MAIN 0x00 /* Already in tulip_main */
184 1.1 tsutsui int sc_phase; /* MSG C/D I/O */
185 1.1 tsutsui #define PHASE_DATA_OUT 0x00 /* 0 0 0 */
186 1.1 tsutsui #define PHASE_DATA_IN 0x01 /* 0 0 1 */
187 1.1 tsutsui #define PHASE_CMD_OUT 0x02 /* 0 1 0 */
188 1.1 tsutsui #define PHASE_STATUS_IN 0x03 /* 0 1 1 */
189 1.1 tsutsui #define PHASE_MSG_OUT 0x06 /* 1 1 0 */
190 1.1 tsutsui #define PHASE_MSG_IN 0x07 /* 1 1 1 */
191 1.1 tsutsui
192 1.1 tsutsui struct iha_scsi_req_q *sc_scb; /* SCB array */
193 1.1 tsutsui struct iha_scsi_req_q *sc_actscb; /* SCB using SCSI bus */
194 1.1 tsutsui struct iha_sglist *sc_sglist;
195 1.1 tsutsui
196 1.1 tsutsui TAILQ_HEAD(, iha_scsi_req_q) sc_freescb,
197 1.1 tsutsui sc_pendscb,
198 1.1 tsutsui sc_donescb;
199 1.1 tsutsui
200 1.1 tsutsui struct tcs sc_tcs[IHA_MAX_TARGETS];
201 1.1 tsutsui
202 1.1 tsutsui u_int8_t sc_msg[IHA_MAX_EXTENDED_MSG]; /* [0] len, [1] Msg Code */
203 1.1 tsutsui u_int8_t sc_sistat;
204 1.1 tsutsui u_int8_t sc_status0;
205 1.1 tsutsui u_int8_t sc_status1;
206 1.1 tsutsui u_int8_t sc_sconf1;
207 1.1 tsutsui };
208 1.1 tsutsui
209 1.1 tsutsui /*
210 1.1 tsutsui * EEPROM for one SCSI Channel
211 1.1 tsutsui */
212 1.1 tsutsui
213 1.1 tsutsui #define EEPROM_SIZE 32
214 1.1 tsutsui #define EEP_LBYTE(x) ((x) & 0xff)
215 1.1 tsutsui #define EEP_HBYTE(x) ((x) >> 8)
216 1.1 tsutsui #define EEP_WORD(l, h) (((h) & 0xff) << 8 | ((l) && 0xff))
217 1.1 tsutsui #define EEP_WAIT() DELAY(5)
218 1.1 tsutsui
219 1.1 tsutsui struct eeprom_adapter {
220 1.1 tsutsui u_int16_t config1; /* 0x00 Channel Adapter SCSI Id */
221 1.1 tsutsui #define CFG_ID_MASK 0x000f
222 1.1 tsutsui #define CFG_ID(cfg) ((cfg) & CFG_ID_MASK)
223 1.1 tsutsui #define CFG_SCSI_RESET 0x0100 /* Reset bus at power up */
224 1.1 tsutsui #define CFG_EN_PAR 0x0200 /* SCSI parity enable */
225 1.1 tsutsui #define CFG_ACT_TERM1 0x0400 /* Enable active term 1 */
226 1.1 tsutsui #define CFG_ACT_TERM2 0x0800 /* Enable active term 2 */
227 1.1 tsutsui #define CFG_AUTO_TERM 0x1000 /* Enable auto terminator */
228 1.1 tsutsui #define CFG_EN_PWR 0x8000 /* Enable power mgmt */
229 1.1 tsutsui #define CFG_DEFAULT (CFG_SCSI_RESET | CFG_AUTO_TERM | CFG_EN_PAR)
230 1.1 tsutsui u_int16_t config2;
231 1.1 tsutsui #define CFG_CFG2(x) EEP_LBYTE(x) /* 0x02 Unused Channel Cfg byte 2*/
232 1.1 tsutsui #define CFG_TARGET(x) EEP_HBYTE(x) /* 0x03 Number of SCSI targets */
233 1.1 tsutsui /* 0x04 Lower bytes of targ flags*/
234 1.1 tsutsui u_int16_t tflags[IHA_MAX_TARGETS / sizeof(u_int16_t)];
235 1.1 tsutsui #define FLAG_DEFAULT (FLAG_NO_WIDE | FLAG_1GIGA | FLAG_EN_DISC)
236 1.1 tsutsui };
237 1.1 tsutsui
238 1.1 tsutsui /*
239 1.1 tsutsui * Tulip (aka ini-950) Serial EEPROM Layout
240 1.1 tsutsui */
241 1.1 tsutsui struct iha_eeprom {
242 1.1 tsutsui /* ---------- Header ------------------------------------------------*/
243 1.1 tsutsui u_int16_t signature; /* 0x00 NVRAM Signature */
244 1.1 tsutsui #define EEP_SIGNATURE 0xC925
245 1.1 tsutsui u_int16_t revision;
246 1.1 tsutsui #define EEP_SIZE(x) EEP_LBYTE(x) /* 0x02 Size of data structure*/
247 1.1 tsutsui #define EEP_REV(x) EEP_HBYTE(x) /* 0x03 Rev. of data structure*/
248 1.1 tsutsui /* ---------- Host Adapter Structure --------------------------------*/
249 1.1 tsutsui u_int16_t model; /* 0x04 Model number */
250 1.1 tsutsui u_int16_t modelinfo;
251 1.1 tsutsui #define EEP_INFO(x) EEP_LBYTE(x) /* 0x06 Model information */
252 1.1 tsutsui #define EEP_CHAN(x) EEP_HBYTE(x) /* 0x07 Number of SCSI channel*/
253 1.1 tsutsui u_int16_t bioscfg; /* 0x08 BIOS configuration 1 */
254 1.1 tsutsui #define EEP_BIOSCFG_ENABLE 0x0001 /* BIOS enable */
255 1.1 tsutsui #define EEP_BIOSCFG_8DRIVE 0x0002 /* Support > 2 drives */
256 1.1 tsutsui #define EEP_BIOSCFG_REMOVABLE 0x0004 /* Support removable drv */
257 1.1 tsutsui #define EEP_BIOSCFG_INT19 0x0008 /* Intercept int 19h */
258 1.1 tsutsui #define EEP_BIOSCFG_BIOSSCAN 0x0010 /* Dynamic BIOS scan */
259 1.1 tsutsui #define EEP_BIOSCFG_LUNSUPPORT 0x0040 /* Support LUN */
260 1.1 tsutsui #define EEP_BIOSCFG_DEFAULT EEP_BIOSCFG_ENABLE
261 1.1 tsutsui u_int16_t hacfg; /* 0x0a Host adapter config 1 */
262 1.1 tsutsui #define EEP_HACFG_BOOTIDMASK 0x000F /* Boot ID number */
263 1.1 tsutsui #define EEP_HACFG_LUNMASK 0x0070 /* Boot LUN number */
264 1.1 tsutsui #define EEP_HACFG_CHANMASK 0x0080 /* Boot Channel number */
265 1.1 tsutsui struct eeprom_adapter adapter[2]; /* 0x0c */
266 1.1 tsutsui u_int16_t reserved[5]; /* 0x34 */
267 1.1 tsutsui
268 1.1 tsutsui /* --------- CheckSum -----------------------------------------------*/
269 1.1 tsutsui u_int16_t checksum; /* 0x3E Checksum of NVRam */
270 1.1 tsutsui };
271 1.1 tsutsui
272 1.1 tsutsui /* Functions used by higher SCSI layers, the kernel, or iha.c and iha_pci.c */
273 1.1 tsutsui
274 1.1 tsutsui int iha_intr(void *);
275 1.1 tsutsui void iha_attach(struct iha_softc *);
276