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