sunscpalvar.h revision 1.1.2.2 1 1.1.2.2 bouyer /* $NetBSD: sunscpalvar.h,v 1.1.2.2 2001/04/23 09:42:21 bouyer Exp $ */
2 1.1.2.2 bouyer
3 1.1.2.2 bouyer /*
4 1.1.2.2 bouyer * Copyright (c) 2001 Matthew Fredette
5 1.1.2.2 bouyer * Copyright (c) 1995 David Jones, Gordon W. Ross
6 1.1.2.2 bouyer * Copyright (c) 1994 Jarle Greipsland
7 1.1.2.2 bouyer * All rights reserved.
8 1.1.2.2 bouyer *
9 1.1.2.2 bouyer * Redistribution and use in source and binary forms, with or without
10 1.1.2.2 bouyer * modification, are permitted provided that the following conditions
11 1.1.2.2 bouyer * are met:
12 1.1.2.2 bouyer * 1. Redistributions of source code must retain the above copyright
13 1.1.2.2 bouyer * notice, this list of conditions and the following disclaimer.
14 1.1.2.2 bouyer * 2. Redistributions in binary form must reproduce the above copyright
15 1.1.2.2 bouyer * notice, this list of conditions and the following disclaimer in the
16 1.1.2.2 bouyer * documentation and/or other materials provided with the distribution.
17 1.1.2.2 bouyer * 3. The name of the authors may not be used to endorse or promote products
18 1.1.2.2 bouyer * derived from this software without specific prior written permission.
19 1.1.2.2 bouyer * 4. All advertising materials mentioning features or use of this software
20 1.1.2.2 bouyer * must display the following acknowledgement:
21 1.1.2.2 bouyer * This product includes software developed by
22 1.1.2.2 bouyer * David Jones and Gordon Ross
23 1.1.2.2 bouyer *
24 1.1.2.2 bouyer * THIS SOFTWARE IS PROVIDED BY THE AUTHORS ``AS IS'' AND ANY EXPRESS OR
25 1.1.2.2 bouyer * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
26 1.1.2.2 bouyer * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
27 1.1.2.2 bouyer * IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY DIRECT, INDIRECT,
28 1.1.2.2 bouyer * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
29 1.1.2.2 bouyer * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
30 1.1.2.2 bouyer * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
31 1.1.2.2 bouyer * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
32 1.1.2.2 bouyer * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
33 1.1.2.2 bouyer * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
34 1.1.2.2 bouyer */
35 1.1.2.2 bouyer
36 1.1.2.2 bouyer /*
37 1.1.2.2 bouyer * This file defines the interface between the machine-dependent
38 1.1.2.2 bouyer * module and the machine-indepenedent sunscpal.c module.
39 1.1.2.2 bouyer */
40 1.1.2.2 bouyer
41 1.1.2.2 bouyer /*
42 1.1.2.2 bouyer * The sun2 and sparc use real bus_space.
43 1.1.2.2 bouyer */
44 1.1.2.2 bouyer #if defined(sun2) || defined(__sparc__)
45 1.1.2.2 bouyer # define SUNSCPAL_USE_BUS_SPACE
46 1.1.2.2 bouyer #endif
47 1.1.2.2 bouyer /*
48 1.1.2.2 bouyer * The sun2 and sparc use real bus_dma.
49 1.1.2.2 bouyer */
50 1.1.2.2 bouyer #if defined(sun2) || defined(__sparc__)
51 1.1.2.2 bouyer #define SUNSCPAL_USE_BUS_DMA
52 1.1.2.2 bouyer #endif
53 1.1.2.2 bouyer
54 1.1.2.2 bouyer /*
55 1.1.2.2 bouyer * Handy read/write macros
56 1.1.2.2 bouyer */
57 1.1.2.2 bouyer #ifdef SUNSCPAL_USE_BUS_SPACE
58 1.1.2.2 bouyer # include <machine/bus.h>
59 1.1.2.2 bouyer /* bus_space() variety */
60 1.1.2.2 bouyer #define SUNSCPAL_READ_1(sc, reg) bus_space_read_1(sc->sunscpal_regt, \
61 1.1.2.2 bouyer sc->sunscpal_regh, sc->reg)
62 1.1.2.2 bouyer #define SUNSCPAL_WRITE_1(sc, reg, val) bus_space_write_1(sc->sunscpal_regt, \
63 1.1.2.2 bouyer sc->sunscpal_regh, sc->reg, val)
64 1.1.2.2 bouyer #define SUNSCPAL_READ_2(sc, reg) bus_space_read_2(sc->sunscpal_regt, \
65 1.1.2.2 bouyer sc->sunscpal_regh, sc->reg)
66 1.1.2.2 bouyer #define SUNSCPAL_WRITE_2(sc, reg, val) bus_space_write_2(sc->sunscpal_regt, \
67 1.1.2.2 bouyer sc->sunscpal_regh, sc->reg, val)
68 1.1.2.2 bouyer #else
69 1.1.2.2 bouyer /* legacy memory-mapped variety */
70 1.1.2.2 bouyer # define SUNSCPAL_READ_1(sc, reg) (*sc->reg)
71 1.1.2.2 bouyer # define SUNSCPAL_WRITE_1(sc, reg, val) do { *(sc->reg) = val; } while(0)
72 1.1.2.2 bouyer # define SUNSCPAL_READ_2 SUNSCPAL_READ_1
73 1.1.2.2 bouyer # define SUNSCPAL_WRITE_2 SUNSCPAL_WRITE_1
74 1.1.2.2 bouyer #endif
75 1.1.2.2 bouyer
76 1.1.2.2 bouyer #define SUNSCPAL_CLR_INTR(sc) do { SUNSCPAL_READ_2(sc, sunscpal_dma_count); SUNSCPAL_READ_2(sc, sunscpal_icr); } while(0)
77 1.1.2.2 bouyer #define SUNSCPAL_BUSY(sc) (SUNSCPAL_READ_2(sc, sunscpal_icr) & SUNSCPAL_ICR_BUSY)
78 1.1.2.2 bouyer
79 1.1.2.2 bouyer /* These are NOT artibtrary, but map to bits in sunscpal_icr */
80 1.1.2.2 bouyer #define SUNSCPAL_PHASE_DATA_IN (SUNSCPAL_ICR_INPUT_OUTPUT)
81 1.1.2.2 bouyer #define SUNSCPAL_PHASE_DATA_OUT (0)
82 1.1.2.2 bouyer #define SUNSCPAL_PHASE_COMMAND (SUNSCPAL_ICR_COMMAND_DATA)
83 1.1.2.2 bouyer #define SUNSCPAL_PHASE_STATUS (SUNSCPAL_ICR_COMMAND_DATA | \
84 1.1.2.2 bouyer SUNSCPAL_ICR_INPUT_OUTPUT)
85 1.1.2.2 bouyer #define SUNSCPAL_PHASE_MSG_IN (SUNSCPAL_ICR_MESSAGE | \
86 1.1.2.2 bouyer SUNSCPAL_ICR_COMMAND_DATA | \
87 1.1.2.2 bouyer SUNSCPAL_ICR_INPUT_OUTPUT)
88 1.1.2.2 bouyer #define SUNSCPAL_PHASE_MSG_OUT (SUNSCPAL_ICR_MESSAGE | \
89 1.1.2.2 bouyer SUNSCPAL_ICR_COMMAND_DATA)
90 1.1.2.2 bouyer #define SUNSCPAL_PHASE_UNSPEC1 (SUNSCPAL_ICR_MESSAGE | \
91 1.1.2.2 bouyer SUNSCPAL_ICR_INPUT_OUTPUT)
92 1.1.2.2 bouyer #define SUNSCPAL_PHASE_UNSPEC2 (SUNSCPAL_ICR_MESSAGE)
93 1.1.2.2 bouyer #define SUNSCPAL_BYTE_READ(sc, phase) (((phase) & SUNSCPAL_ICR_COMMAND_DATA) ? \
94 1.1.2.2 bouyer SUNSCPAL_READ_1(sc, sunscpal_cmd_stat) : \
95 1.1.2.2 bouyer SUNSCPAL_READ_1(sc, sunscpal_data))
96 1.1.2.2 bouyer #define SUNSCPAL_BYTE_WRITE(sc, phase, b) do { \
97 1.1.2.2 bouyer if ((phase) & SUNSCPAL_ICR_COMMAND_DATA) { \
98 1.1.2.2 bouyer SUNSCPAL_WRITE_1(sc, sunscpal_cmd_stat, b); \
99 1.1.2.2 bouyer } else { \
100 1.1.2.2 bouyer SUNSCPAL_WRITE_1(sc, sunscpal_data, b); \
101 1.1.2.2 bouyer } \
102 1.1.2.2 bouyer } while(0)
103 1.1.2.2 bouyer /*
104 1.1.2.2 bouyer * A mask and a macro for getting the current bus phase.
105 1.1.2.2 bouyer */
106 1.1.2.2 bouyer #define SUNSCPAL_ICR_PHASE_MASK (SUNSCPAL_ICR_MESSAGE | \
107 1.1.2.2 bouyer SUNSCPAL_ICR_COMMAND_DATA | \
108 1.1.2.2 bouyer SUNSCPAL_ICR_INPUT_OUTPUT)
109 1.1.2.2 bouyer #define SUNSCPAL_BUS_PHASE(icr) ((icr) & SUNSCPAL_ICR_PHASE_MASK)
110 1.1.2.2 bouyer
111 1.1.2.2 bouyer /*
112 1.1.2.2 bouyer * This illegal phase is used to prevent the PAL from having
113 1.1.2.2 bouyer * a phase-match condition when we don't want one, such as
114 1.1.2.2 bouyer * when setting up the DMA engine or whatever...
115 1.1.2.2 bouyer */
116 1.1.2.2 bouyer #define SUNSCPAL_PHASE_INVALID SUNSCPAL_PHASE_UNSPEC1
117 1.1.2.2 bouyer
118 1.1.2.2 bouyer /*
119 1.1.2.2 bouyer * Transfers lager than 65535 bytes need to be split-up.
120 1.1.2.2 bouyer * (The DMA count register is only 16 bits.)
121 1.1.2.2 bouyer * Make the size an integer multiple of the page size
122 1.1.2.2 bouyer * to avoid buf/cluster remap problems. (paranoid?)
123 1.1.2.2 bouyer */
124 1.1.2.2 bouyer #define SUNSCPAL_MAX_DMA_LEN 0xE000
125 1.1.2.2 bouyer
126 1.1.2.2 bouyer #ifdef SUNSCPAL_USE_BUS_DMA
127 1.1.2.2 bouyer /*
128 1.1.2.2 bouyer * This structure is used to keep track of mapped DMA requests.
129 1.1.2.2 bouyer */
130 1.1.2.2 bouyer struct sunscpal_dma_handle {
131 1.1.2.2 bouyer int dh_flags;
132 1.1.2.2 bouyer #define SUNSCDH_BUSY 0x01 /* This DH is in use */
133 1.1.2.2 bouyer u_char * dh_mapaddr; /* Original data pointer */
134 1.1.2.2 bouyer int dh_maplen; /* Original data length */
135 1.1.2.2 bouyer bus_dmamap_t dh_dmamap;
136 1.1.2.2 bouyer #define dh_dvma dh_dmamap->dm_segs[0].ds_addr /* VA of buffer in DVMA space */
137 1.1.2.2 bouyer };
138 1.1.2.2 bouyer typedef struct sunscpal_dma_handle *sunscpal_dma_handle_t;
139 1.1.2.2 bouyer #else
140 1.1.2.2 bouyer typedef void *sunscpal_dma_handle_t;
141 1.1.2.2 bouyer #endif
142 1.1.2.2 bouyer
143 1.1.2.2 bouyer /* Per-request state. This is required in order to support reselection. */
144 1.1.2.2 bouyer struct sunscpal_req {
145 1.1.2.2 bouyer struct scsipi_xfer *sr_xs; /* Pointer to xfer struct, NULL=unused */
146 1.1.2.2 bouyer int sr_target, sr_lun; /* For fast access */
147 1.1.2.2 bouyer sunscpal_dma_handle_t sr_dma_hand; /* Current DMA handle */
148 1.1.2.2 bouyer u_char *sr_dataptr; /* Saved data pointer */
149 1.1.2.2 bouyer int sr_datalen;
150 1.1.2.2 bouyer int sr_flags; /* Internal error code */
151 1.1.2.2 bouyer #define SR_IMMED 1 /* Immediate command */
152 1.1.2.2 bouyer #define SR_SENSE 2 /* We are getting sense */
153 1.1.2.2 bouyer #define SR_OVERDUE 4 /* Timeout while not current */
154 1.1.2.2 bouyer #define SR_ERROR 8 /* Error occurred */
155 1.1.2.2 bouyer int sr_status; /* Status code from last cmd */
156 1.1.2.2 bouyer };
157 1.1.2.2 bouyer #define SUNSCPAL_OPENINGS 16 /* How many commands we can enqueue. */
158 1.1.2.2 bouyer
159 1.1.2.2 bouyer
160 1.1.2.2 bouyer struct sunscpal_softc {
161 1.1.2.2 bouyer struct device sc_dev;
162 1.1.2.2 bouyer struct scsipi_link sc_link;
163 1.1.2.2 bouyer struct scsipi_adapter sc_adapter;
164 1.1.2.2 bouyer
165 1.1.2.2 bouyer #ifdef SUNSCPAL_USE_BUS_SPACE
166 1.1.2.2 bouyer /* Pointers to bus_space */
167 1.1.2.2 bouyer bus_space_tag_t sunscpal_regt;
168 1.1.2.2 bouyer bus_space_handle_t sunscpal_regh;
169 1.1.2.2 bouyer
170 1.1.2.2 bouyer /* Pointers to PAL registers. */
171 1.1.2.2 bouyer bus_size_t sunscpal_data;
172 1.1.2.2 bouyer bus_size_t sunscpal_cmd_stat;
173 1.1.2.2 bouyer bus_size_t sunscpal_icr;
174 1.1.2.2 bouyer bus_size_t sunscpal_dma_addr_h;
175 1.1.2.2 bouyer bus_size_t sunscpal_dma_addr_l;
176 1.1.2.2 bouyer bus_size_t sunscpal_dma_count;
177 1.1.2.2 bouyer bus_size_t sunscpal_intvec;
178 1.1.2.2 bouyer #else
179 1.1.2.2 bouyer /* Pointers to PAL registers. See sunscpalreg.h */
180 1.1.2.2 bouyer volatile u_char *sunscpal_data;
181 1.1.2.2 bouyer volatile u_char *sunscpal_cmd_stat;
182 1.1.2.2 bouyer volatile u_short *sunscpal_icr;
183 1.1.2.2 bouyer volatile u_short *sunscpal_dma_addr_h;
184 1.1.2.2 bouyer volatile u_short *sunscpal_dma_addr_l;
185 1.1.2.2 bouyer volatile u_short *sunscpal_dma_count;
186 1.1.2.2 bouyer volatile u_char *sunscpal_intvec;
187 1.1.2.2 bouyer #endif
188 1.1.2.2 bouyer
189 1.1.2.2 bouyer /* Pointers to DMA-related structures */
190 1.1.2.2 bouyer #ifdef SUNSCPAL_USE_BUS_DMA
191 1.1.2.2 bouyer bus_dma_tag_t sunscpal_dmat;
192 1.1.2.2 bouyer #endif
193 1.1.2.2 bouyer sunscpal_dma_handle_t sc_dma_handles;
194 1.1.2.2 bouyer
195 1.1.2.2 bouyer /* Functions set from MD code */
196 1.1.2.2 bouyer #ifndef SUNSCPAL_USE_BUS_DMA
197 1.1.2.2 bouyer void (*sc_dma_alloc) __P((struct sunscpal_softc *));
198 1.1.2.2 bouyer void (*sc_dma_free) __P((struct sunscpal_softc *));
199 1.1.2.2 bouyer
200 1.1.2.2 bouyer void (*sc_dma_setup) __P((struct sunscpal_softc *));
201 1.1.2.2 bouyer #endif
202 1.1.2.2 bouyer
203 1.1.2.2 bouyer void (*sc_intr_on) __P((struct sunscpal_softc *));
204 1.1.2.2 bouyer void (*sc_intr_off) __P((struct sunscpal_softc *));
205 1.1.2.2 bouyer
206 1.1.2.2 bouyer int sc_flags; /* Misc. flags and capabilities */
207 1.1.2.2 bouyer #define SUNSCPAL_FORCE_POLLING 1 /* Do not use interrupts. */
208 1.1.2.2 bouyer #define SUNSCPAL_DISABLE_DMA 2 /* Do not use DMA. */
209 1.1.2.2 bouyer
210 1.1.2.2 bouyer /* Set bits in this to disable parity for some target. */
211 1.1.2.2 bouyer int sc_parity_disable;
212 1.1.2.2 bouyer
213 1.1.2.2 bouyer int sc_min_dma_len; /* Smaller than this is done with PIO */
214 1.1.2.2 bouyer
215 1.1.2.2 bouyer /* Begin MI shared data */
216 1.1.2.2 bouyer
217 1.1.2.2 bouyer int sc_state;
218 1.1.2.2 bouyer #define SUNSCPAL_IDLE 0 /* Ready for new work. */
219 1.1.2.2 bouyer #define SUNSCPAL_WORKING 0x01 /* Some command is in progress. */
220 1.1.2.2 bouyer #define SUNSCPAL_ABORTING 0x02 /* Bailing out */
221 1.1.2.2 bouyer #define SUNSCPAL_DOINGDMA 0x04 /* The FIFO data path is active! */
222 1.1.2.2 bouyer #define SUNSCPAL_DROP_MSGIN 0x10 /* Discard all msgs (parity err detected) */
223 1.1.2.2 bouyer
224 1.1.2.2 bouyer /* The request that has the bus now. */
225 1.1.2.2 bouyer struct sunscpal_req *sc_current;
226 1.1.2.2 bouyer
227 1.1.2.2 bouyer /* Active data pointer for current SCSI command. */
228 1.1.2.2 bouyer u_char *sc_dataptr;
229 1.1.2.2 bouyer int sc_datalen;
230 1.1.2.2 bouyer int sc_reqlen;
231 1.1.2.2 bouyer
232 1.1.2.2 bouyer /* Begin MI private data */
233 1.1.2.2 bouyer
234 1.1.2.2 bouyer /* The number of operations in progress on the bus */
235 1.1.2.2 bouyer volatile int sc_ncmds;
236 1.1.2.2 bouyer
237 1.1.2.2 bouyer /* Ring buffer of pending/active requests */
238 1.1.2.2 bouyer struct sunscpal_req sc_ring[SUNSCPAL_OPENINGS];
239 1.1.2.2 bouyer int sc_rr; /* Round-robin scan pointer */
240 1.1.2.2 bouyer
241 1.1.2.2 bouyer /* Active requests, by target/LUN */
242 1.1.2.2 bouyer struct sunscpal_req *sc_matrix[8][8];
243 1.1.2.2 bouyer
244 1.1.2.2 bouyer /* Message stuff */
245 1.1.2.2 bouyer int sc_prevphase;
246 1.1.2.2 bouyer
247 1.1.2.2 bouyer u_int sc_msgpriq; /* Messages we want to send */
248 1.1.2.2 bouyer u_int sc_msgoutq; /* Messages sent during last MESSAGE OUT */
249 1.1.2.2 bouyer u_int sc_msgout; /* Message last transmitted */
250 1.1.2.2 bouyer #define SEND_DEV_RESET 0x01
251 1.1.2.2 bouyer #define SEND_PARITY_ERROR 0x02
252 1.1.2.2 bouyer #define SEND_ABORT 0x04
253 1.1.2.2 bouyer #define SEND_REJECT 0x08
254 1.1.2.2 bouyer #define SEND_INIT_DET_ERR 0x10
255 1.1.2.2 bouyer #define SEND_IDENTIFY 0x20
256 1.1.2.2 bouyer #define SEND_SDTR 0x40
257 1.1.2.2 bouyer #define SEND_WDTR 0x80
258 1.1.2.2 bouyer #define SUNSCPAL_MAX_MSG_LEN 8
259 1.1.2.2 bouyer u_char sc_omess[SUNSCPAL_MAX_MSG_LEN];
260 1.1.2.2 bouyer u_char *sc_omp; /* Outgoing message pointer */
261 1.1.2.2 bouyer u_char sc_imess[SUNSCPAL_MAX_MSG_LEN];
262 1.1.2.2 bouyer u_char *sc_imp; /* Incoming message pointer */
263 1.1.2.2 bouyer int sc_rev; /* Chip revision */
264 1.1.2.2 bouyer #define SUNSCPAL_VARIANT_501_1006 0
265 1.1.2.2 bouyer #define SUNSCPAL_VARIANT_501_1045 1
266 1.1.2.2 bouyer
267 1.1.2.2 bouyer };
268 1.1.2.2 bouyer
269 1.1.2.2 bouyer void sunscpal_attach __P((struct sunscpal_softc *, int));
270 1.1.2.2 bouyer int sunscpal_detach __P((struct sunscpal_softc *, int));
271 1.1.2.2 bouyer int sunscpal_intr __P((void *));
272 1.1.2.2 bouyer int sunscpal_scsi_cmd __P((struct scsipi_xfer *));
273 1.1.2.2 bouyer int sunscpal_pio_in __P((struct sunscpal_softc *, int, int, u_char *));
274 1.1.2.2 bouyer int sunscpal_pio_out __P((struct sunscpal_softc *, int, int, u_char *));
275 1.1.2.2 bouyer void sunscpal_init __P((struct sunscpal_softc *));
276 1.1.2.2 bouyer
277 1.1.2.2 bouyer /* Options for no-parity, DMA, and interrupts. */
278 1.1.2.2 bouyer #define SUNSCPAL_OPT_NO_PARITY_CHK 0xff
279 1.1.2.2 bouyer #define SUNSCPAL_OPT_FORCE_POLLING 0x100
280 1.1.2.2 bouyer #define SUNSCPAL_OPT_DISABLE_DMA 0x200
281 1.1.2.2 bouyer
282 1.1.2.2 bouyer #ifdef SUNSCPAL_DEBUG
283 1.1.2.2 bouyer struct sunscpal_softc *sunscpal_debug_sc;
284 1.1.2.2 bouyer void sunscpal_trace __P((char *msg, long val));
285 1.1.2.2 bouyer #define SUNSCPAL_TRACE(msg, val) sunscpal_trace(msg, val)
286 1.1.2.2 bouyer #else /* SUNSCPAL_DEBUG */
287 1.1.2.2 bouyer #define SUNSCPAL_TRACE(msg, val) /* nada */
288 1.1.2.2 bouyer #endif /* SUNSCPAL_DEBUG */
289