ahareg.h revision 1.6 1 1.6 mycroft /* $NetBSD: ahareg.h,v 1.6 1997/09/09 18:56:15 mycroft Exp $ */
2 1.3 thorpej
3 1.3 thorpej /*-
4 1.3 thorpej * Copyright (c) 1997 The NetBSD Foundation, Inc.
5 1.3 thorpej * All rights reserved.
6 1.3 thorpej *
7 1.3 thorpej * This code is derived from software contributed to The NetBSD Foundation
8 1.3 thorpej * by Jason R. Thorpe of the Numerical Aerospace Simulation Facility,
9 1.3 thorpej * NASA Ames Research Center.
10 1.3 thorpej *
11 1.3 thorpej * Redistribution and use in source and binary forms, with or without
12 1.3 thorpej * modification, are permitted provided that the following conditions
13 1.3 thorpej * are met:
14 1.3 thorpej * 1. Redistributions of source code must retain the above copyright
15 1.3 thorpej * notice, this list of conditions and the following disclaimer.
16 1.3 thorpej * 2. Redistributions in binary form must reproduce the above copyright
17 1.3 thorpej * notice, this list of conditions and the following disclaimer in the
18 1.3 thorpej * documentation and/or other materials provided with the distribution.
19 1.3 thorpej * 3. All advertising materials mentioning features or use of this software
20 1.3 thorpej * must display the following acknowledgement:
21 1.3 thorpej * This product includes software developed by the NetBSD
22 1.3 thorpej * Foundation, Inc. and its contributors.
23 1.3 thorpej * 4. Neither the name of The NetBSD Foundation nor the names of its
24 1.3 thorpej * contributors may be used to endorse or promote products derived
25 1.3 thorpej * from this software without specific prior written permission.
26 1.3 thorpej *
27 1.3 thorpej * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
28 1.3 thorpej * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
29 1.3 thorpej * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
30 1.3 thorpej * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
31 1.3 thorpej * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
32 1.3 thorpej * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
33 1.3 thorpej * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
34 1.3 thorpej * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
35 1.3 thorpej * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
36 1.3 thorpej * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
37 1.3 thorpej * POSSIBILITY OF SUCH DAMAGE.
38 1.3 thorpej */
39 1.1 mycroft
40 1.1 mycroft /*
41 1.1 mycroft * Copyright (c) 1994, 1996 Charles M. Hannum. All rights reserved.
42 1.1 mycroft *
43 1.1 mycroft * Redistribution and use in source and binary forms, with or without
44 1.1 mycroft * modification, are permitted provided that the following conditions
45 1.1 mycroft * are met:
46 1.1 mycroft * 1. Redistributions of source code must retain the above copyright
47 1.1 mycroft * notice, this list of conditions and the following disclaimer.
48 1.1 mycroft * 2. Redistributions in binary form must reproduce the above copyright
49 1.1 mycroft * notice, this list of conditions and the following disclaimer in the
50 1.1 mycroft * documentation and/or other materials provided with the distribution.
51 1.1 mycroft * 3. All advertising materials mentioning features or use of this software
52 1.1 mycroft * must display the following acknowledgement:
53 1.1 mycroft * This product includes software developed by Charles M. Hannum.
54 1.1 mycroft * 4. The name of the author may not be used to endorse or promote products
55 1.1 mycroft * derived from this software without specific prior written permission.
56 1.1 mycroft *
57 1.1 mycroft * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
58 1.1 mycroft * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
59 1.1 mycroft * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
60 1.1 mycroft * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
61 1.1 mycroft * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
62 1.1 mycroft * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
63 1.1 mycroft * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
64 1.1 mycroft * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
65 1.1 mycroft * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
66 1.1 mycroft * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
67 1.1 mycroft */
68 1.1 mycroft
69 1.1 mycroft /*
70 1.1 mycroft * Originally written by Julian Elischer (julian (at) tfs.com)
71 1.1 mycroft * for TRW Financial Systems for use under the MACH(2.5) operating system.
72 1.1 mycroft *
73 1.1 mycroft * TRW Financial Systems, in accordance with their agreement with Carnegie
74 1.1 mycroft * Mellon University, makes this software available to CMU to distribute
75 1.1 mycroft * or use in any manner that they see fit as long as this message is kept with
76 1.1 mycroft * the software. For this reason TFS also grants any other persons or
77 1.1 mycroft * organisations permission to use or modify this software.
78 1.1 mycroft *
79 1.1 mycroft * TFS supplies this software to be publicly redistributed
80 1.1 mycroft * on the understanding that TFS is not responsible for the correct
81 1.1 mycroft * functioning of this software in any circumstances.
82 1.1 mycroft */
83 1.1 mycroft
84 1.1 mycroft typedef u_int8_t physaddr[3];
85 1.1 mycroft typedef u_int8_t physlen[3];
86 1.1 mycroft #define ltophys _lto3b
87 1.1 mycroft #define phystol _3btol
88 1.1 mycroft
89 1.1 mycroft /*
90 1.1 mycroft * I/O port offsets
91 1.1 mycroft */
92 1.1 mycroft #define AHA_CTRL_PORT 0 /* control (wo) */
93 1.1 mycroft #define AHA_STAT_PORT 0 /* status (ro) */
94 1.1 mycroft #define AHA_CMD_PORT 1 /* command (wo) */
95 1.1 mycroft #define AHA_DATA_PORT 1 /* data (ro) */
96 1.1 mycroft #define AHA_INTR_PORT 2 /* interrupt status (ro) */
97 1.1 mycroft
98 1.1 mycroft /*
99 1.1 mycroft * AHA_CTRL bits
100 1.1 mycroft */
101 1.1 mycroft #define AHA_CTRL_HRST 0x80 /* Hardware reset */
102 1.1 mycroft #define AHA_CTRL_SRST 0x40 /* Software reset */
103 1.1 mycroft #define AHA_CTRL_IRST 0x20 /* Interrupt reset */
104 1.1 mycroft #define AHA_CTRL_SCRST 0x10 /* SCSI bus reset */
105 1.1 mycroft
106 1.1 mycroft /*
107 1.1 mycroft * AHA_STAT bits
108 1.1 mycroft */
109 1.1 mycroft #define AHA_STAT_STST 0x80 /* Self test in Progress */
110 1.1 mycroft #define AHA_STAT_DIAGF 0x40 /* Diagnostic Failure */
111 1.1 mycroft #define AHA_STAT_INIT 0x20 /* Mbx Init required */
112 1.1 mycroft #define AHA_STAT_IDLE 0x10 /* Host Adapter Idle */
113 1.1 mycroft #define AHA_STAT_CDF 0x08 /* cmd/data out port full */
114 1.1 mycroft #define AHA_STAT_DF 0x04 /* Data in port full */
115 1.1 mycroft #define AHA_STAT_INVDCMD 0x01 /* Invalid command */
116 1.1 mycroft
117 1.1 mycroft /*
118 1.1 mycroft * AHA_CMD opcodes
119 1.1 mycroft */
120 1.1 mycroft #define AHA_NOP 0x00 /* No operation */
121 1.1 mycroft #define AHA_MBX_INIT 0x01 /* Mbx initialization */
122 1.1 mycroft #define AHA_START_SCSI 0x02 /* start scsi command */
123 1.1 mycroft #define AHA_INQUIRE_REVISION 0x04 /* Adapter Inquiry */
124 1.1 mycroft #define AHA_MBO_INTR_EN 0x05 /* Enable MBO available interrupt */
125 1.1 mycroft #if 0
126 1.1 mycroft #define AHA_SEL_TIMEOUT_SET 0x06 /* set selection time-out */
127 1.1 mycroft #define AHA_BUS_ON_TIME_SET 0x07 /* set bus-on time */
128 1.1 mycroft #define AHA_BUS_OFF_TIME_SET 0x08 /* set bus-off time */
129 1.1 mycroft #define AHA_SPEED_SET 0x09 /* set transfer speed */
130 1.1 mycroft #endif
131 1.1 mycroft #define AHA_INQUIRE_DEVICES 0x0a /* return installed devices 0-7 */
132 1.1 mycroft #define AHA_INQUIRE_CONFIG 0x0b /* return configuration data */
133 1.1 mycroft #define AHA_TARGET_EN 0x0c /* enable target mode */
134 1.1 mycroft #define AHA_INQUIRE_SETUP 0x0d /* return setup data */
135 1.1 mycroft #define AHA_ECHO 0x1e /* Echo command data */
136 1.1 mycroft #define AHA_INQUIRE_DEVICES_2 0x23 /* return installed devices 8-15 */
137 1.1 mycroft #define AHA_EXT_BIOS 0x28 /* return extended bios info */
138 1.1 mycroft #define AHA_MBX_ENABLE 0x29 /* enable mail box interface */
139 1.1 mycroft
140 1.1 mycroft /*
141 1.1 mycroft * AHA_INTR bits
142 1.1 mycroft */
143 1.1 mycroft #define AHA_INTR_ANYINTR 0x80 /* Any interrupt */
144 1.1 mycroft #define AHA_INTR_SCRD 0x08 /* SCSI reset detected */
145 1.1 mycroft #define AHA_INTR_HACC 0x04 /* Command complete */
146 1.1 mycroft #define AHA_INTR_MBOA 0x02 /* MBX out empty */
147 1.1 mycroft #define AHA_INTR_MBIF 0x01 /* MBX in full */
148 1.1 mycroft
149 1.1 mycroft struct aha_mbx_out {
150 1.1 mycroft u_char cmd;
151 1.1 mycroft physaddr ccb_addr;
152 1.1 mycroft };
153 1.1 mycroft
154 1.1 mycroft struct aha_mbx_in {
155 1.1 mycroft u_char stat;
156 1.1 mycroft physaddr ccb_addr;
157 1.1 mycroft };
158 1.1 mycroft
159 1.1 mycroft /*
160 1.1 mycroft * mbo.cmd values
161 1.1 mycroft */
162 1.1 mycroft #define AHA_MBO_FREE 0x0 /* MBO entry is free */
163 1.1 mycroft #define AHA_MBO_START 0x1 /* MBO activate entry */
164 1.1 mycroft #define AHA_MBO_ABORT 0x2 /* MBO abort entry */
165 1.1 mycroft
166 1.1 mycroft /*
167 1.1 mycroft * mbi.stat values
168 1.1 mycroft */
169 1.1 mycroft #define AHA_MBI_FREE 0x0 /* MBI entry is free */
170 1.1 mycroft #define AHA_MBI_OK 0x1 /* completed without error */
171 1.1 mycroft #define AHA_MBI_ABORT 0x2 /* aborted ccb */
172 1.1 mycroft #define AHA_MBI_UNKNOWN 0x3 /* Tried to abort invalid CCB */
173 1.1 mycroft #define AHA_MBI_ERROR 0x4 /* Completed with error */
174 1.1 mycroft
175 1.1 mycroft /* FOR OLD VERSIONS OF THE !%$@ this may have to be 16 (yuk) */
176 1.1 mycroft #define AHA_NSEG 17 /* Number of scatter gather segments <= 16 */
177 1.1 mycroft /* allow 64 K i/o (min) */
178 1.1 mycroft
179 1.1 mycroft struct aha_scat_gath {
180 1.1 mycroft physlen seg_len;
181 1.1 mycroft physaddr seg_addr;
182 1.1 mycroft };
183 1.1 mycroft
184 1.1 mycroft struct aha_ccb {
185 1.1 mycroft u_char opcode;
186 1.1 mycroft u_char lun:3;
187 1.1 mycroft u_char data_in:1; /* must be 0 */
188 1.1 mycroft u_char data_out:1; /* must be 0 */
189 1.1 mycroft u_char target:3;
190 1.1 mycroft u_char scsi_cmd_length;
191 1.1 mycroft u_char req_sense_length;
192 1.1 mycroft physlen data_length;
193 1.1 mycroft physaddr data_addr;
194 1.1 mycroft physaddr link_addr;
195 1.1 mycroft u_char link_id;
196 1.1 mycroft u_char host_stat;
197 1.1 mycroft u_char target_stat;
198 1.1 mycroft u_char reserved[2];
199 1.1 mycroft struct scsi_generic scsi_cmd;
200 1.5 bouyer struct scsipi_sense_data scsi_sense;
201 1.1 mycroft struct aha_scat_gath scat_gath[AHA_NSEG];
202 1.1 mycroft /*----------------------------------------------------------------*/
203 1.1 mycroft TAILQ_ENTRY(aha_ccb) chain;
204 1.1 mycroft struct aha_ccb *nexthash;
205 1.6 mycroft u_long hashkey;
206 1.5 bouyer struct scsipi_xfer *xs; /* the scsipi_xfer for this cmd */
207 1.1 mycroft int flags;
208 1.1 mycroft #define CCB_ALLOC 0x01
209 1.1 mycroft #define CCB_ABORT 0x02
210 1.1 mycroft #ifdef AHADIAG
211 1.1 mycroft #define CCB_SENDING 0x04
212 1.1 mycroft #endif
213 1.1 mycroft int timeout;
214 1.3 thorpej
215 1.3 thorpej /*
216 1.3 thorpej * DMA maps used by the CCB. These maps are created
217 1.3 thorpej * in aha_init_ccb().
218 1.3 thorpej */
219 1.3 thorpej
220 1.3 thorpej /*
221 1.3 thorpej * This DMA map maps an individual CCB. This map is permanently
222 1.3 thorpej * loaded in aha_init_ccb().
223 1.3 thorpej */
224 1.3 thorpej bus_dmamap_t dmamap_self;
225 1.3 thorpej
226 1.3 thorpej /*
227 1.3 thorpej * This DMA map maps the buffer involved in the transfer.
228 1.3 thorpej * Its contents are loaded into "scat_gath" above.
229 1.3 thorpej */
230 1.3 thorpej bus_dmamap_t dmamap_xfer;
231 1.1 mycroft };
232 1.1 mycroft
233 1.1 mycroft /*
234 1.1 mycroft * opcode fields
235 1.1 mycroft */
236 1.1 mycroft #define AHA_INITIATOR_CCB 0x00 /* SCSI Initiator CCB */
237 1.1 mycroft #define AHA_TARGET_CCB 0x01 /* SCSI Target CCB */
238 1.1 mycroft #define AHA_INIT_SCAT_GATH_CCB 0x02 /* SCSI Initiator with scatter gather */
239 1.1 mycroft #define AHA_RESET_CCB 0x81 /* SCSI Bus reset */
240 1.1 mycroft
241 1.1 mycroft /*
242 1.1 mycroft * aha_ccb.host_stat values
243 1.1 mycroft */
244 1.1 mycroft #define AHA_OK 0x00 /* cmd ok */
245 1.1 mycroft #define AHA_LINK_OK 0x0a /* Link cmd ok */
246 1.1 mycroft #define AHA_LINK_IT 0x0b /* Link cmd ok + int */
247 1.1 mycroft #define AHA_SEL_TIMEOUT 0x11 /* Selection time out */
248 1.1 mycroft #define AHA_OVER_UNDER 0x12 /* Data over/under run */
249 1.1 mycroft #define AHA_BUS_FREE 0x13 /* Bus dropped at unexpected time */
250 1.1 mycroft #define AHA_INV_BUS 0x14 /* Invalid bus phase/sequence */
251 1.1 mycroft #define AHA_BAD_MBO 0x15 /* Incorrect MBO cmd */
252 1.1 mycroft #define AHA_BAD_CCB 0x16 /* Incorrect ccb opcode */
253 1.1 mycroft #define AHA_BAD_LINK 0x17 /* Not same values of LUN for links */
254 1.1 mycroft #define AHA_INV_TARGET 0x18 /* Invalid target direction */
255 1.1 mycroft #define AHA_CCB_DUP 0x19 /* Duplicate CCB received */
256 1.1 mycroft #define AHA_INV_CCB 0x1a /* Invalid CCB or segment list */
257 1.1 mycroft
258 1.1 mycroft struct aha_revision {
259 1.1 mycroft struct {
260 1.1 mycroft u_char opcode;
261 1.1 mycroft } cmd;
262 1.1 mycroft struct {
263 1.1 mycroft u_char boardid; /* type of board */
264 1.1 mycroft /* 0x31 = AHA-1540 */
265 1.1 mycroft /* 0x41 = AHA-1540A/1542A/1542B */
266 1.1 mycroft /* 0x42 = AHA-1640 */
267 1.1 mycroft /* 0x43 = AHA-1542C */
268 1.1 mycroft /* 0x44 = AHA-1542CF */
269 1.1 mycroft /* 0x45 = AHA-1542CF, BIOS v2.01 */
270 1.1 mycroft /* 0x46 = AHA-1542CP */
271 1.1 mycroft u_char spec_opts; /* special options ID */
272 1.1 mycroft /* 0x41 = Board is standard model */
273 1.1 mycroft u_char revision_1; /* firmware revision [0-9A-Z] */
274 1.1 mycroft u_char revision_2; /* firmware revision [0-9A-Z] */
275 1.1 mycroft } reply;
276 1.1 mycroft };
277 1.1 mycroft
278 1.1 mycroft struct aha_extbios {
279 1.1 mycroft struct {
280 1.1 mycroft u_char opcode;
281 1.1 mycroft } cmd;
282 1.1 mycroft struct {
283 1.1 mycroft u_char flags; /* Bit 3 == 1 extended bios enabled */
284 1.1 mycroft u_char mailboxlock; /* mail box lock code to unlock it */
285 1.1 mycroft } reply;
286 1.1 mycroft };
287 1.1 mycroft
288 1.1 mycroft struct aha_toggle {
289 1.1 mycroft struct {
290 1.1 mycroft u_char opcode;
291 1.1 mycroft u_char enable;
292 1.1 mycroft } cmd;
293 1.1 mycroft };
294 1.1 mycroft
295 1.1 mycroft struct aha_config {
296 1.1 mycroft struct {
297 1.1 mycroft u_char opcode;
298 1.1 mycroft } cmd;
299 1.1 mycroft struct {
300 1.1 mycroft u_char chan;
301 1.1 mycroft u_char intr;
302 1.1 mycroft u_char scsi_dev:3;
303 1.1 mycroft u_char :5;
304 1.1 mycroft } reply;
305 1.1 mycroft };
306 1.1 mycroft
307 1.1 mycroft struct aha_mailbox {
308 1.1 mycroft struct {
309 1.1 mycroft u_char opcode;
310 1.1 mycroft u_char nmbx;
311 1.1 mycroft physaddr addr;
312 1.1 mycroft } cmd;
313 1.1 mycroft };
314 1.1 mycroft
315 1.1 mycroft struct aha_unlock {
316 1.1 mycroft struct {
317 1.1 mycroft u_char opcode;
318 1.1 mycroft u_char junk;
319 1.1 mycroft u_char magic;
320 1.1 mycroft } cmd;
321 1.1 mycroft };
322 1.1 mycroft
323 1.1 mycroft struct aha_devices {
324 1.1 mycroft struct {
325 1.1 mycroft u_char opcode;
326 1.1 mycroft } cmd;
327 1.1 mycroft struct {
328 1.4 hannken u_char lun_map[8];
329 1.1 mycroft } reply;
330 1.1 mycroft };
331 1.1 mycroft
332 1.1 mycroft struct aha_setup {
333 1.1 mycroft struct {
334 1.1 mycroft u_char opcode;
335 1.1 mycroft u_char len;
336 1.1 mycroft } cmd;
337 1.1 mycroft struct {
338 1.1 mycroft u_char sync_neg:1;
339 1.1 mycroft u_char parity:1;
340 1.1 mycroft u_char :6;
341 1.1 mycroft u_char speed;
342 1.1 mycroft u_char bus_on;
343 1.1 mycroft u_char bus_off;
344 1.1 mycroft u_char num_mbx;
345 1.1 mycroft u_char mbx[3];
346 1.1 mycroft struct {
347 1.1 mycroft u_char offset:4;
348 1.1 mycroft u_char period:3;
349 1.1 mycroft u_char valid:1;
350 1.1 mycroft } sync[8];
351 1.1 mycroft u_char disc_sts;
352 1.1 mycroft } reply;
353 1.1 mycroft };
354 1.1 mycroft
355 1.1 mycroft #define INT9 0x01
356 1.1 mycroft #define INT10 0x02
357 1.1 mycroft #define INT11 0x04
358 1.1 mycroft #define INT12 0x08
359 1.1 mycroft #define INT14 0x20
360 1.1 mycroft #define INT15 0x40
361 1.1 mycroft
362 1.1 mycroft #define EISADMA 0x00
363 1.1 mycroft #define CHAN0 0x01
364 1.1 mycroft #define CHAN5 0x20
365 1.1 mycroft #define CHAN6 0x40
366 1.1 mycroft #define CHAN7 0x80
367