mlxvar.h revision 1.2 1 /* $NetBSD: mlxvar.h,v 1.2 2001/05/06 19:53:04 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 };
165
166 #define MLX_BG_CHECK 1 /* we started a check */
167 #define MLX_BG_REBUILD 2 /* we started a rebuild */
168 #define MLX_BG_SPONTANEOUS 3 /* it just happened somehow */
169
170 #define MLXF_SPINUP_REPORTED 0x0001 /* "spinning up drives" displayed */
171 #define MLXF_EVENTLOG_BUSY 0x0002 /* currently reading event log */
172 #define MLXF_FW_INITTED 0x0004 /* firmware init crap done */
173 #define MLXF_PAUSEWORKS 0x0008 /* channel pause works as expected */
174 #define MLXF_OPEN 0x0010 /* control device is open */
175 #define MLXF_INITOK 0x0020 /* controller initalised OK */
176 #define MLXF_PERIODIC_CTLR 0x0040 /* periodic check running */
177 #define MLXF_PERIODIC_DRIVE 0x0080 /* periodic check running */
178 #define MLXF_PERIODIC_REBUILD 0x0100 /* periodic check running */
179 #define MLXF_EISA 0x0200 /* EISA board */
180
181 struct mlx_attach_args {
182 int mlxa_unit;
183 };
184
185 #define mlxacf_unit cf_loc[MLXCF_UNIT]
186
187 int mlx_flush(struct mlx_softc *, int);
188 void mlx_init(struct mlx_softc *, const char *);
189 int mlx_intr(void *);
190
191 int mlx_ccb_alloc(struct mlx_softc *, struct mlx_ccb **, int);
192 const char *mlx_ccb_diagnose(struct mlx_ccb *);
193 void mlx_ccb_enqueue(struct mlx_softc *, struct mlx_ccb *);
194 void mlx_ccb_free(struct mlx_softc *, struct mlx_ccb *);
195 int mlx_ccb_map(struct mlx_softc *, struct mlx_ccb *, void *, int, int);
196 int mlx_ccb_poll(struct mlx_softc *, struct mlx_ccb *, int);
197 void mlx_ccb_unmap(struct mlx_softc *, struct mlx_ccb *);
198 int mlx_ccb_wait(struct mlx_softc *, struct mlx_ccb *);
199
200 static __inline__ void mlx_make_type1(struct mlx_ccb *, u_int8_t, u_int16_t,
201 u_int32_t, u_int8_t, u_int32_t,
202 u_int8_t);
203 static __inline__ void mlx_make_type2(struct mlx_ccb *, u_int8_t, u_int8_t,
204 u_int8_t, u_int8_t, u_int8_t,
205 u_int8_t, u_int8_t, u_int32_t,
206 u_int8_t);
207 static __inline__ void mlx_make_type3(struct mlx_ccb *, u_int8_t, u_int8_t,
208 u_int8_t, u_int16_t, u_int8_t,
209 u_int8_t, u_int32_t, u_int8_t);
210 static __inline__ void mlx_make_type4(struct mlx_ccb *, u_int8_t, u_int16_t,
211 u_int32_t, u_int32_t, u_int8_t);
212 static __inline__ void mlx_make_type5(struct mlx_ccb *, u_int8_t, u_int8_t,
213 u_int8_t, u_int32_t, u_int32_t,
214 u_int8_t);
215
216 static __inline__ u_int8_t mlx_inb(struct mlx_softc *, int);
217 static __inline__ u_int16_t mlx_inw(struct mlx_softc *, int);
218 static __inline__ u_int32_t mlx_inl(struct mlx_softc *, int);
219 static __inline__ void mlx_outb(struct mlx_softc *, int, u_int8_t);
220 static __inline__ void mlx_outw(struct mlx_softc *, int, u_int16_t);
221 static __inline__ void mlx_outl(struct mlx_softc *, int, u_int32_t);
222
223 static __inline__ void
224 mlx_make_type1(struct mlx_ccb *mc, u_int8_t code, u_int16_t f1, u_int32_t f2,
225 u_int8_t f3, u_int32_t f4, u_int8_t f5)
226 {
227
228 mc->mc_mbox[0x0] = code;
229 mc->mc_mbox[0x2] = f1;
230 mc->mc_mbox[0x3] = (((f2 >> 24) & 0x3) << 6) | ((f1 >> 8) & 0x3f);
231 mc->mc_mbox[0x4] = f2;
232 mc->mc_mbox[0x5] = (f2 >> 8);
233 mc->mc_mbox[0x6] = (f2 >> 16);
234 mc->mc_mbox[0x7] = f3;
235 mc->mc_mbox[0x8] = f4;
236 mc->mc_mbox[0x9] = (f4 >> 8);
237 mc->mc_mbox[0xa] = (f4 >> 16);
238 mc->mc_mbox[0xb] = (f4 >> 24);
239 mc->mc_mbox[0xc] = f5;
240 }
241
242 static __inline__ void
243 mlx_make_type2(struct mlx_ccb *mc, u_int8_t code, u_int8_t f1, u_int8_t f2,
244 u_int8_t f3, u_int8_t f4, u_int8_t f5, u_int8_t f6,
245 u_int32_t f7, u_int8_t f8)
246 {
247
248 mc->mc_mbox[0x0] = code;
249 mc->mc_mbox[0x2] = f1;
250 mc->mc_mbox[0x3] = f2;
251 mc->mc_mbox[0x4] = f3;
252 mc->mc_mbox[0x5] = f4;
253 mc->mc_mbox[0x6] = f5;
254 mc->mc_mbox[0x7] = f6;
255 mc->mc_mbox[0x8] = f7;
256 mc->mc_mbox[0x9] = (f7 >> 8);
257 mc->mc_mbox[0xa] = (f7 >> 16);
258 mc->mc_mbox[0xb] = (f7 >> 24);
259 mc->mc_mbox[0xc] = f8;
260 }
261
262 static __inline__ void
263 mlx_make_type3(struct mlx_ccb *mc, u_int8_t code, u_int8_t f1, u_int8_t f2,
264 u_int16_t f3, u_int8_t f4, u_int8_t f5, u_int32_t f6,
265 u_int8_t f7)
266 {
267
268 mc->mc_mbox[0x0] = code;
269 mc->mc_mbox[0x2] = f1;
270 mc->mc_mbox[0x3] = f2;
271 mc->mc_mbox[0x4] = f3;
272 mc->mc_mbox[0x5] = (f3 >> 8);
273 mc->mc_mbox[0x6] = f4;
274 mc->mc_mbox[0x7] = f5;
275 mc->mc_mbox[0x8] = f6;
276 mc->mc_mbox[0x9] = (f6 >> 8);
277 mc->mc_mbox[0xa] = (f6 >> 16);
278 mc->mc_mbox[0xb] = (f6 >> 24);
279 mc->mc_mbox[0xc] = f7;
280 }
281
282 static __inline__ void
283 mlx_make_type4(struct mlx_ccb *mc, u_int8_t code, u_int16_t f1, u_int32_t f2,
284 u_int32_t f3, u_int8_t f4)
285 {
286
287 mc->mc_mbox[0x0] = code;
288 mc->mc_mbox[0x2] = f1;
289 mc->mc_mbox[0x3] = (f1 >> 8);
290 mc->mc_mbox[0x4] = f2;
291 mc->mc_mbox[0x5] = (f2 >> 8);
292 mc->mc_mbox[0x6] = (f2 >> 16);
293 mc->mc_mbox[0x7] = (f2 >> 24);
294 mc->mc_mbox[0x8] = f3;
295 mc->mc_mbox[0x9] = (f3 >> 8);
296 mc->mc_mbox[0xa] = (f3 >> 16);
297 mc->mc_mbox[0xb] = (f3 >> 24);
298 mc->mc_mbox[0xc] = f4;
299 }
300
301 static __inline__ void
302 mlx_make_type5(struct mlx_ccb *mc, u_int8_t code, u_int8_t f1, u_int8_t f2,
303 u_int32_t f3, u_int32_t f4, u_int8_t f5)
304 {
305
306 mc->mc_mbox[0x0] = code;
307 mc->mc_mbox[0x2] = f1;
308 mc->mc_mbox[0x3] = f2;
309 mc->mc_mbox[0x4] = f3;
310 mc->mc_mbox[0x5] = (f3 >> 8);
311 mc->mc_mbox[0x6] = (f3 >> 16);
312 mc->mc_mbox[0x7] = (f3 >> 24);
313 mc->mc_mbox[0x8] = f4;
314 mc->mc_mbox[0x9] = (f4 >> 8);
315 mc->mc_mbox[0xa] = (f4 >> 16);
316 mc->mc_mbox[0xb] = (f4 >> 24);
317 mc->mc_mbox[0xc] = f5;
318 }
319
320 static __inline__ u_int8_t
321 mlx_inb(struct mlx_softc *mlx, int off)
322 {
323
324 bus_space_barrier(mlx->mlx_iot, mlx->mlx_ioh, off, 1,
325 BUS_SPACE_BARRIER_WRITE | BUS_SPACE_BARRIER_READ);
326 return (bus_space_read_1(mlx->mlx_iot, mlx->mlx_ioh, off));
327 }
328
329 static __inline__ u_int16_t
330 mlx_inw(struct mlx_softc *mlx, int off)
331 {
332
333 bus_space_barrier(mlx->mlx_iot, mlx->mlx_ioh, off, 2,
334 BUS_SPACE_BARRIER_WRITE | BUS_SPACE_BARRIER_READ);
335 return (bus_space_read_2(mlx->mlx_iot, mlx->mlx_ioh, off));
336 }
337
338 static __inline__ u_int32_t
339 mlx_inl(struct mlx_softc *mlx, int off)
340 {
341
342 bus_space_barrier(mlx->mlx_iot, mlx->mlx_ioh, off, 4,
343 BUS_SPACE_BARRIER_WRITE | BUS_SPACE_BARRIER_READ);
344 return (bus_space_read_4(mlx->mlx_iot, mlx->mlx_ioh, off));
345 }
346
347 static __inline__ void
348 mlx_outb(struct mlx_softc *mlx, int off, u_int8_t val)
349 {
350
351 bus_space_write_1(mlx->mlx_iot, mlx->mlx_ioh, off, val);
352 bus_space_barrier(mlx->mlx_iot, mlx->mlx_ioh, off, 1,
353 BUS_SPACE_BARRIER_WRITE);
354 }
355
356 static __inline__ void
357 mlx_outw(struct mlx_softc *mlx, int off, u_int16_t val)
358 {
359
360 bus_space_write_2(mlx->mlx_iot, mlx->mlx_ioh, off, val);
361 bus_space_barrier(mlx->mlx_iot, mlx->mlx_ioh, off, 2,
362 BUS_SPACE_BARRIER_WRITE);
363 }
364
365 static __inline__ void
366 mlx_outl(struct mlx_softc *mlx, int off, u_int32_t val)
367 {
368
369 bus_space_write_4(mlx->mlx_iot, mlx->mlx_ioh, off, val);
370 bus_space_barrier(mlx->mlx_iot, mlx->mlx_ioh, off, 4,
371 BUS_SPACE_BARRIER_WRITE);
372 }
373
374 #endif /* !_IC_MLXVAR_H_ */
375