mlxvar.h revision 1.1 1 1.1 ad /* $NetBSD: mlxvar.h,v 1.1 2001/02/04 17:05:12 ad Exp $ */
2 1.1 ad
3 1.1 ad /*-
4 1.1 ad * Copyright (c) 2001 The NetBSD Foundation, Inc.
5 1.1 ad * All rights reserved.
6 1.1 ad *
7 1.1 ad * This code is derived from software contributed to The NetBSD Foundation
8 1.1 ad * by Andrew Doran.
9 1.1 ad *
10 1.1 ad * Redistribution and use in source and binary forms, with or without
11 1.1 ad * modification, are permitted provided that the following conditions
12 1.1 ad * are met:
13 1.1 ad * 1. Redistributions of source code must retain the above copyright
14 1.1 ad * notice, this list of conditions and the following disclaimer.
15 1.1 ad * 2. Redistributions in binary form must reproduce the above copyright
16 1.1 ad * notice, this list of conditions and the following disclaimer in the
17 1.1 ad * documentation and/or other materials provided with the distribution.
18 1.1 ad * 3. All advertising materials mentioning features or use of this software
19 1.1 ad * must display the following acknowledgement:
20 1.1 ad * This product includes software developed by the NetBSD
21 1.1 ad * Foundation, Inc. and its contributors.
22 1.1 ad * 4. Neither the name of The NetBSD Foundation nor the names of its
23 1.1 ad * contributors may be used to endorse or promote products derived
24 1.1 ad * from this software without specific prior written permission.
25 1.1 ad *
26 1.1 ad * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
27 1.1 ad * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
28 1.1 ad * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
29 1.1 ad * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
30 1.1 ad * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
31 1.1 ad * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
32 1.1 ad * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
33 1.1 ad * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
34 1.1 ad * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
35 1.1 ad * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
36 1.1 ad * POSSIBILITY OF SUCH DAMAGE.
37 1.1 ad */
38 1.1 ad
39 1.1 ad /*-
40 1.1 ad * Copyright (c) 1999 Michael Smith
41 1.1 ad * All rights reserved.
42 1.1 ad *
43 1.1 ad * Redistribution and use in source and binary forms, with or without
44 1.1 ad * modification, are permitted provided that the following conditions
45 1.1 ad * are met:
46 1.1 ad * 1. Redistributions of source code must retain the above copyright
47 1.1 ad * notice, this list of conditions and the following disclaimer.
48 1.1 ad * 2. Redistributions in binary form must reproduce the above copyright
49 1.1 ad * notice, this list of conditions and the following disclaimer in the
50 1.1 ad * documentation and/or other materials provided with the distribution.
51 1.1 ad *
52 1.1 ad * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
53 1.1 ad * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
54 1.1 ad * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
55 1.1 ad * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
56 1.1 ad * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
57 1.1 ad * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
58 1.1 ad * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
59 1.1 ad * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
60 1.1 ad * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
61 1.1 ad * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
62 1.1 ad * SUCH DAMAGE.
63 1.1 ad *
64 1.1 ad * from FreeBSD: mlxvar.h,v 1.5.2.2 2000/04/24 19:40:50 msmith Exp
65 1.1 ad */
66 1.1 ad
67 1.1 ad #ifndef _IC_MLXVAR_H_
68 1.1 ad #define _IC_MLXVAR_H_
69 1.1 ad
70 1.1 ad #include "locators.h"
71 1.1 ad
72 1.1 ad /* Older boards allow up to 17 segments and 64kB transfers. */
73 1.1 ad #define MLX_MAX_SEGS 17
74 1.1 ad #define MLX_MAX_XFER 65536
75 1.1 ad #define MLX_SGL_SIZE (sizeof(struct mlx_sgentry) * MLX_MAX_SEGS)
76 1.1 ad
77 1.1 ad /* This shouldn't be ajusted lightly... */
78 1.1 ad #define MLX_MAX_DRIVES 32
79 1.1 ad
80 1.1 ad /* Maximum queue depth, matching the older controllers. */
81 1.1 ad #define MLX_MAX_QUEUECNT 63
82 1.1 ad
83 1.1 ad /* Number of CCBs to reserve for `special' operations. */
84 1.1 ad #define MLX_NCCBS_RESERVE 7
85 1.1 ad
86 1.1 ad /* Structure describing a system drive as attached to the controller. */
87 1.1 ad struct mlx_sysdrive {
88 1.1 ad u_int32_t ms_size;
89 1.1 ad u_short ms_state;
90 1.1 ad u_short ms_raidlevel;
91 1.1 ad struct device *ms_dv;
92 1.1 ad };
93 1.1 ad
94 1.1 ad /* Optional per-CCB context. */
95 1.1 ad struct mlx_ccb;
96 1.1 ad struct mlx_context {
97 1.1 ad void (*mx_handler)(struct mlx_ccb *);
98 1.1 ad void *mx_context;
99 1.1 ad struct device *mx_dv;
100 1.1 ad };
101 1.1 ad
102 1.1 ad /* Command control block. */
103 1.1 ad struct mlx_ccb {
104 1.1 ad union {
105 1.1 ad SIMPLEQ_ENTRY(mlx_ccb) simpleq;
106 1.1 ad SLIST_ENTRY(mlx_ccb) slist;
107 1.1 ad TAILQ_ENTRY(mlx_ccb) tailq;
108 1.1 ad } mc_chain;
109 1.1 ad u_int mc_flags;
110 1.1 ad u_int mc_status;
111 1.1 ad u_int mc_ident;
112 1.1 ad time_t mc_expiry;
113 1.1 ad u_int mc_nsgent;
114 1.1 ad u_int mc_xfer_size;
115 1.1 ad bus_addr_t mc_xfer_phys;
116 1.1 ad bus_dmamap_t mc_xfer_map;
117 1.1 ad struct mlx_context mc_mx;
118 1.1 ad u_int8_t mc_mbox[16];
119 1.1 ad };
120 1.1 ad #define MC_XFER_IN MU_XFER_IN /* Map describes inbound xfer */
121 1.1 ad #define MC_XFER_OUT MU_XFER_OUT /* Map describes outbound xfer */
122 1.1 ad #define MC_WAITING 0x0400 /* We have waiters */
123 1.1 ad
124 1.1 ad /*
125 1.1 ad * Per-controller state.
126 1.1 ad */
127 1.1 ad struct mlx_softc {
128 1.1 ad struct device mlx_dv;
129 1.1 ad bus_space_tag_t mlx_iot;
130 1.1 ad bus_space_handle_t mlx_ioh;
131 1.1 ad bus_dma_tag_t mlx_dmat;
132 1.1 ad bus_dmamap_t mlx_dmamap;
133 1.1 ad void *mlx_ih;
134 1.1 ad
135 1.1 ad SLIST_HEAD(, mlx_ccb) mlx_ccb_freelist;
136 1.1 ad TAILQ_HEAD(, mlx_ccb) mlx_ccb_worklist;
137 1.1 ad SIMPLEQ_HEAD(, mlx_ccb) mlx_ccb_queue;
138 1.1 ad struct mlx_ccb *mlx_ccbs;
139 1.1 ad int mlx_nccbs;
140 1.1 ad int mlx_nccbs_free;
141 1.1 ad
142 1.1 ad caddr_t mlx_sgls;
143 1.1 ad bus_addr_t mlx_sgls_paddr;
144 1.1 ad
145 1.1 ad int (*mlx_submit)(struct mlx_softc *, struct mlx_ccb *);
146 1.1 ad int (*mlx_findcomplete)(struct mlx_softc *, u_int *, u_int *);
147 1.1 ad void (*mlx_intaction)(struct mlx_softc *, int);
148 1.1 ad int (*mlx_fw_handshake)(struct mlx_softc *, int *, int *, int *);
149 1.1 ad
150 1.1 ad int mlx_max_queuecnt;
151 1.1 ad struct mlx_enquiry2 *mlx_enq2;
152 1.1 ad int mlx_iftype;
153 1.1 ad
154 1.1 ad time_t mlx_lastpoll;
155 1.1 ad u_int mlx_lastevent;
156 1.1 ad u_int mlx_currevent;
157 1.1 ad u_int mlx_bg;
158 1.1 ad struct mlx_rebuild_status mlx_rebuildstat;
159 1.1 ad struct mlx_pause mlx_pause;
160 1.1 ad int mlx_flags;
161 1.1 ad
162 1.1 ad struct mlx_sysdrive mlx_sysdrive[MLX_MAX_DRIVES];
163 1.1 ad };
164 1.1 ad
165 1.1 ad #define MLX_BG_CHECK 1 /* we started a check */
166 1.1 ad #define MLX_BG_REBUILD 2 /* we started a rebuild */
167 1.1 ad #define MLX_BG_SPONTANEOUS 3 /* it just happened somehow */
168 1.1 ad
169 1.1 ad #define MLXF_SPINUP_REPORTED 0x0001 /* "spinning up drives" displayed */
170 1.1 ad #define MLXF_EVENTLOG_BUSY 0x0002 /* currently reading event log */
171 1.1 ad #define MLXF_FW_INITTED 0x0004 /* firmware init crap done */
172 1.1 ad #define MLXF_PAUSEWORKS 0x0008 /* channel pause works as expected */
173 1.1 ad #define MLXF_OPEN 0x0010 /* control device is open */
174 1.1 ad #define MLXF_INITOK 0x0020 /* controller initalised OK */
175 1.1 ad #define MLXF_PERIODIC_CTLR 0x0040 /* periodic check running */
176 1.1 ad #define MLXF_PERIODIC_DRIVE 0x0080 /* periodic check running */
177 1.1 ad #define MLXF_PERIODIC_REBUILD 0x0100 /* periodic check running */
178 1.1 ad #define MLXF_EISA 0x0200 /* EISA board */
179 1.1 ad
180 1.1 ad struct mlx_attach_args {
181 1.1 ad int mlxa_unit;
182 1.1 ad };
183 1.1 ad
184 1.1 ad #define mlxacf_unit cf_loc[MLXCF_UNIT]
185 1.1 ad
186 1.1 ad int mlx_flush(struct mlx_softc *, int);
187 1.1 ad void mlx_init(struct mlx_softc *, const char *);
188 1.1 ad int mlx_intr(void *);
189 1.1 ad
190 1.1 ad int mlx_ccb_alloc(struct mlx_softc *, struct mlx_ccb **, int);
191 1.1 ad const char *mlx_ccb_diagnose(struct mlx_ccb *);
192 1.1 ad void mlx_ccb_enqueue(struct mlx_softc *, struct mlx_ccb *);
193 1.1 ad void mlx_ccb_free(struct mlx_softc *, struct mlx_ccb *);
194 1.1 ad int mlx_ccb_map(struct mlx_softc *, struct mlx_ccb *, void *, int, int);
195 1.1 ad int mlx_ccb_poll(struct mlx_softc *, struct mlx_ccb *, int);
196 1.1 ad void mlx_ccb_unmap(struct mlx_softc *, struct mlx_ccb *);
197 1.1 ad int mlx_ccb_wait(struct mlx_softc *, struct mlx_ccb *);
198 1.1 ad
199 1.1 ad static __inline__ void mlx_make_type1(struct mlx_ccb *, u_int8_t, u_int16_t,
200 1.1 ad u_int32_t, u_int8_t, u_int32_t,
201 1.1 ad u_int8_t);
202 1.1 ad static __inline__ void mlx_make_type2(struct mlx_ccb *, u_int8_t, u_int8_t,
203 1.1 ad u_int8_t, u_int8_t, u_int8_t,
204 1.1 ad u_int8_t, u_int8_t, u_int32_t,
205 1.1 ad u_int8_t);
206 1.1 ad static __inline__ void mlx_make_type3(struct mlx_ccb *, u_int8_t, u_int8_t,
207 1.1 ad u_int8_t, u_int16_t, u_int8_t,
208 1.1 ad u_int8_t, u_int32_t, u_int8_t);
209 1.1 ad static __inline__ void mlx_make_type4(struct mlx_ccb *, u_int8_t, u_int16_t,
210 1.1 ad u_int32_t, u_int32_t, u_int8_t);
211 1.1 ad static __inline__ void mlx_make_type5(struct mlx_ccb *, u_int8_t, u_int8_t,
212 1.1 ad u_int8_t, u_int32_t, u_int32_t,
213 1.1 ad u_int8_t);
214 1.1 ad
215 1.1 ad static __inline__ u_int8_t mlx_inb(struct mlx_softc *, int);
216 1.1 ad static __inline__ u_int16_t mlx_inw(struct mlx_softc *, int);
217 1.1 ad static __inline__ u_int32_t mlx_inl(struct mlx_softc *, int);
218 1.1 ad static __inline__ void mlx_outb(struct mlx_softc *, int, u_int8_t);
219 1.1 ad static __inline__ void mlx_outw(struct mlx_softc *, int, u_int16_t);
220 1.1 ad static __inline__ void mlx_outl(struct mlx_softc *, int, u_int32_t);
221 1.1 ad
222 1.1 ad static __inline__ void
223 1.1 ad mlx_make_type1(struct mlx_ccb *mc, u_int8_t code, u_int16_t f1, u_int32_t f2,
224 1.1 ad u_int8_t f3, u_int32_t f4, u_int8_t f5)
225 1.1 ad {
226 1.1 ad
227 1.1 ad mc->mc_mbox[0x0] = code;
228 1.1 ad mc->mc_mbox[0x2] = f1;
229 1.1 ad mc->mc_mbox[0x3] = (((f2 >> 24) & 0x3) << 6) | ((f1 >> 8) & 0x3f);
230 1.1 ad mc->mc_mbox[0x4] = f2;
231 1.1 ad mc->mc_mbox[0x5] = (f2 >> 8);
232 1.1 ad mc->mc_mbox[0x6] = (f2 >> 16);
233 1.1 ad mc->mc_mbox[0x7] = f3;
234 1.1 ad mc->mc_mbox[0x8] = f4;
235 1.1 ad mc->mc_mbox[0x9] = (f4 >> 8);
236 1.1 ad mc->mc_mbox[0xa] = (f4 >> 16);
237 1.1 ad mc->mc_mbox[0xb] = (f4 >> 24);
238 1.1 ad mc->mc_mbox[0xc] = f5;
239 1.1 ad }
240 1.1 ad
241 1.1 ad static __inline__ void
242 1.1 ad mlx_make_type2(struct mlx_ccb *mc, u_int8_t code, u_int8_t f1, u_int8_t f2,
243 1.1 ad u_int8_t f3, u_int8_t f4, u_int8_t f5, u_int8_t f6,
244 1.1 ad u_int32_t f7, u_int8_t f8)
245 1.1 ad {
246 1.1 ad
247 1.1 ad mc->mc_mbox[0x0] = code;
248 1.1 ad mc->mc_mbox[0x2] = f1;
249 1.1 ad mc->mc_mbox[0x3] = f2;
250 1.1 ad mc->mc_mbox[0x4] = f3;
251 1.1 ad mc->mc_mbox[0x5] = f4;
252 1.1 ad mc->mc_mbox[0x6] = f5;
253 1.1 ad mc->mc_mbox[0x7] = f6;
254 1.1 ad mc->mc_mbox[0x8] = f7;
255 1.1 ad mc->mc_mbox[0x9] = (f7 >> 8);
256 1.1 ad mc->mc_mbox[0xa] = (f7 >> 16);
257 1.1 ad mc->mc_mbox[0xb] = (f7 >> 24);
258 1.1 ad mc->mc_mbox[0xc] = f8;
259 1.1 ad }
260 1.1 ad
261 1.1 ad static __inline__ void
262 1.1 ad mlx_make_type3(struct mlx_ccb *mc, u_int8_t code, u_int8_t f1, u_int8_t f2,
263 1.1 ad u_int16_t f3, u_int8_t f4, u_int8_t f5, u_int32_t f6,
264 1.1 ad u_int8_t f7)
265 1.1 ad {
266 1.1 ad
267 1.1 ad mc->mc_mbox[0x0] = code;
268 1.1 ad mc->mc_mbox[0x2] = f1;
269 1.1 ad mc->mc_mbox[0x3] = f2;
270 1.1 ad mc->mc_mbox[0x4] = f3;
271 1.1 ad mc->mc_mbox[0x5] = (f3 >> 8);
272 1.1 ad mc->mc_mbox[0x6] = f4;
273 1.1 ad mc->mc_mbox[0x7] = f5;
274 1.1 ad mc->mc_mbox[0x8] = f6;
275 1.1 ad mc->mc_mbox[0x9] = (f6 >> 8);
276 1.1 ad mc->mc_mbox[0xa] = (f6 >> 16);
277 1.1 ad mc->mc_mbox[0xb] = (f6 >> 24);
278 1.1 ad mc->mc_mbox[0xc] = f7;
279 1.1 ad }
280 1.1 ad
281 1.1 ad static __inline__ void
282 1.1 ad mlx_make_type4(struct mlx_ccb *mc, u_int8_t code, u_int16_t f1, u_int32_t f2,
283 1.1 ad u_int32_t f3, u_int8_t f4)
284 1.1 ad {
285 1.1 ad
286 1.1 ad mc->mc_mbox[0x0] = code;
287 1.1 ad mc->mc_mbox[0x2] = f1;
288 1.1 ad mc->mc_mbox[0x3] = (f1 >> 8);
289 1.1 ad mc->mc_mbox[0x4] = f2;
290 1.1 ad mc->mc_mbox[0x5] = (f2 >> 8);
291 1.1 ad mc->mc_mbox[0x6] = (f2 >> 16);
292 1.1 ad mc->mc_mbox[0x7] = (f2 >> 24);
293 1.1 ad mc->mc_mbox[0x8] = f3;
294 1.1 ad mc->mc_mbox[0x9] = (f3 >> 8);
295 1.1 ad mc->mc_mbox[0xa] = (f3 >> 16);
296 1.1 ad mc->mc_mbox[0xb] = (f3 >> 24);
297 1.1 ad mc->mc_mbox[0xc] = f4;
298 1.1 ad }
299 1.1 ad
300 1.1 ad static __inline__ void
301 1.1 ad mlx_make_type5(struct mlx_ccb *mc, u_int8_t code, u_int8_t f1, u_int8_t f2,
302 1.1 ad u_int32_t f3, u_int32_t f4, u_int8_t f5)
303 1.1 ad {
304 1.1 ad
305 1.1 ad mc->mc_mbox[0x0] = code;
306 1.1 ad mc->mc_mbox[0x2] = f1;
307 1.1 ad mc->mc_mbox[0x3] = f2;
308 1.1 ad mc->mc_mbox[0x4] = f3;
309 1.1 ad mc->mc_mbox[0x5] = (f3 >> 8);
310 1.1 ad mc->mc_mbox[0x6] = (f3 >> 16);
311 1.1 ad mc->mc_mbox[0x7] = (f3 >> 24);
312 1.1 ad mc->mc_mbox[0x8] = f4;
313 1.1 ad mc->mc_mbox[0x9] = (f4 >> 8);
314 1.1 ad mc->mc_mbox[0xa] = (f4 >> 16);
315 1.1 ad mc->mc_mbox[0xb] = (f4 >> 24);
316 1.1 ad mc->mc_mbox[0xc] = f5;
317 1.1 ad }
318 1.1 ad
319 1.1 ad static __inline__ u_int8_t
320 1.1 ad mlx_inb(struct mlx_softc *mlx, int off)
321 1.1 ad {
322 1.1 ad
323 1.1 ad bus_space_barrier(mlx->mlx_iot, mlx->mlx_ioh, off, 1,
324 1.1 ad BUS_SPACE_BARRIER_WRITE | BUS_SPACE_BARRIER_READ);
325 1.1 ad return (bus_space_read_1(mlx->mlx_iot, mlx->mlx_ioh, off));
326 1.1 ad }
327 1.1 ad
328 1.1 ad static __inline__ u_int16_t
329 1.1 ad mlx_inw(struct mlx_softc *mlx, int off)
330 1.1 ad {
331 1.1 ad
332 1.1 ad bus_space_barrier(mlx->mlx_iot, mlx->mlx_ioh, off, 2,
333 1.1 ad BUS_SPACE_BARRIER_WRITE | BUS_SPACE_BARRIER_READ);
334 1.1 ad return (bus_space_read_2(mlx->mlx_iot, mlx->mlx_ioh, off));
335 1.1 ad }
336 1.1 ad
337 1.1 ad static __inline__ u_int32_t
338 1.1 ad mlx_inl(struct mlx_softc *mlx, int off)
339 1.1 ad {
340 1.1 ad
341 1.1 ad bus_space_barrier(mlx->mlx_iot, mlx->mlx_ioh, off, 4,
342 1.1 ad BUS_SPACE_BARRIER_WRITE | BUS_SPACE_BARRIER_READ);
343 1.1 ad return (bus_space_read_4(mlx->mlx_iot, mlx->mlx_ioh, off));
344 1.1 ad }
345 1.1 ad
346 1.1 ad static __inline__ void
347 1.1 ad mlx_outb(struct mlx_softc *mlx, int off, u_int8_t val)
348 1.1 ad {
349 1.1 ad
350 1.1 ad bus_space_write_1(mlx->mlx_iot, mlx->mlx_ioh, off, val);
351 1.1 ad bus_space_barrier(mlx->mlx_iot, mlx->mlx_ioh, off, 1,
352 1.1 ad BUS_SPACE_BARRIER_WRITE);
353 1.1 ad }
354 1.1 ad
355 1.1 ad static __inline__ void
356 1.1 ad mlx_outw(struct mlx_softc *mlx, int off, u_int16_t val)
357 1.1 ad {
358 1.1 ad
359 1.1 ad bus_space_write_2(mlx->mlx_iot, mlx->mlx_ioh, off, val);
360 1.1 ad bus_space_barrier(mlx->mlx_iot, mlx->mlx_ioh, off, 2,
361 1.1 ad BUS_SPACE_BARRIER_WRITE);
362 1.1 ad }
363 1.1 ad
364 1.1 ad static __inline__ void
365 1.1 ad mlx_outl(struct mlx_softc *mlx, int off, u_int32_t val)
366 1.1 ad {
367 1.1 ad
368 1.1 ad bus_space_write_4(mlx->mlx_iot, mlx->mlx_ioh, off, val);
369 1.1 ad bus_space_barrier(mlx->mlx_iot, mlx->mlx_ioh, off, 4,
370 1.1 ad BUS_SPACE_BARRIER_WRITE);
371 1.1 ad }
372 1.1 ad
373 1.1 ad #endif /* !_IC_MLXVAR_H_ */
374