iop.c revision 1.19.4.3 1 1.19.4.3 he /* $NetBSD: iop.c,v 1.19.4.3 2001/12/09 19:11:16 he Exp $ */
2 1.19.4.2 he
3 1.19.4.2 he /*-
4 1.19.4.2 he * Copyright (c) 2000, 2001 The NetBSD Foundation, Inc.
5 1.19.4.2 he * All rights reserved.
6 1.19.4.2 he *
7 1.19.4.2 he * This code is derived from software contributed to The NetBSD Foundation
8 1.19.4.2 he * by Andrew Doran.
9 1.19.4.2 he *
10 1.19.4.2 he * Redistribution and use in source and binary forms, with or without
11 1.19.4.2 he * modification, are permitted provided that the following conditions
12 1.19.4.2 he * are met:
13 1.19.4.2 he * 1. Redistributions of source code must retain the above copyright
14 1.19.4.2 he * notice, this list of conditions and the following disclaimer.
15 1.19.4.2 he * 2. Redistributions in binary form must reproduce the above copyright
16 1.19.4.2 he * notice, this list of conditions and the following disclaimer in the
17 1.19.4.2 he * documentation and/or other materials provided with the distribution.
18 1.19.4.2 he * 3. All advertising materials mentioning features or use of this software
19 1.19.4.2 he * must display the following acknowledgement:
20 1.19.4.2 he * This product includes software developed by the NetBSD
21 1.19.4.2 he * Foundation, Inc. and its contributors.
22 1.19.4.2 he * 4. Neither the name of The NetBSD Foundation nor the names of its
23 1.19.4.2 he * contributors may be used to endorse or promote products derived
24 1.19.4.2 he * from this software without specific prior written permission.
25 1.19.4.2 he *
26 1.19.4.2 he * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
27 1.19.4.2 he * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
28 1.19.4.2 he * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
29 1.19.4.2 he * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
30 1.19.4.2 he * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
31 1.19.4.2 he * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
32 1.19.4.2 he * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
33 1.19.4.2 he * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
34 1.19.4.2 he * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
35 1.19.4.2 he * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
36 1.19.4.2 he * POSSIBILITY OF SUCH DAMAGE.
37 1.19.4.2 he */
38 1.19.4.2 he
39 1.19.4.2 he /*
40 1.19.4.2 he * Support for I2O IOPs (intelligent I/O processors).
41 1.19.4.2 he */
42 1.19.4.2 he
43 1.19.4.2 he #include "opt_i2o.h"
44 1.19.4.2 he #include "iop.h"
45 1.19.4.2 he
46 1.19.4.2 he #include <sys/param.h>
47 1.19.4.2 he #include <sys/systm.h>
48 1.19.4.2 he #include <sys/kernel.h>
49 1.19.4.2 he #include <sys/device.h>
50 1.19.4.2 he #include <sys/queue.h>
51 1.19.4.2 he #include <sys/proc.h>
52 1.19.4.2 he #include <sys/malloc.h>
53 1.19.4.2 he #include <sys/ioctl.h>
54 1.19.4.2 he #include <sys/endian.h>
55 1.19.4.2 he #include <sys/conf.h>
56 1.19.4.2 he #include <sys/kthread.h>
57 1.19.4.2 he
58 1.19.4.2 he #include <machine/vmparam.h>
59 1.19.4.2 he #include <machine/bus.h>
60 1.19.4.2 he
61 1.19.4.2 he #include <vm/vm.h>
62 1.19.4.2 he
63 1.19.4.2 he #include <dev/i2o/i2o.h>
64 1.19.4.2 he #include <dev/i2o/iopio.h>
65 1.19.4.2 he #include <dev/i2o/iopreg.h>
66 1.19.4.2 he #include <dev/i2o/iopvar.h>
67 1.19.4.2 he
68 1.19.4.2 he #define POLL(ms, cond) \
69 1.19.4.2 he do { \
70 1.19.4.2 he int i; \
71 1.19.4.2 he for (i = (ms) * 10; i; i--) { \
72 1.19.4.2 he if (cond) \
73 1.19.4.2 he break; \
74 1.19.4.2 he DELAY(100); \
75 1.19.4.2 he } \
76 1.19.4.2 he } while (/* CONSTCOND */0);
77 1.19.4.2 he
78 1.19.4.2 he #ifdef I2ODEBUG
79 1.19.4.2 he #define DPRINTF(x) printf x
80 1.19.4.2 he #else
81 1.19.4.2 he #define DPRINTF(x)
82 1.19.4.2 he #endif
83 1.19.4.2 he
84 1.19.4.2 he #ifdef I2OVERBOSE
85 1.19.4.2 he #define IFVERBOSE(x) x
86 1.19.4.2 he #define COMMENT(x) NULL
87 1.19.4.2 he #else
88 1.19.4.2 he #define IFVERBOSE(x)
89 1.19.4.2 he #define COMMENT(x)
90 1.19.4.2 he #endif
91 1.19.4.2 he
92 1.19.4.2 he #define IOP_ICTXHASH_NBUCKETS 16
93 1.19.4.2 he #define IOP_ICTXHASH(ictx) (&iop_ictxhashtbl[(ictx) & iop_ictxhash])
94 1.19.4.2 he
95 1.19.4.2 he #define IOP_MAX_SEGS (((IOP_MAX_XFER + NBPG - 1) / NBPG) + 1)
96 1.19.4.2 he
97 1.19.4.2 he #define IOP_TCTX_SHIFT 12
98 1.19.4.2 he #define IOP_TCTX_MASK ((1 << IOP_TCTX_SHIFT) - 1)
99 1.19.4.2 he
100 1.19.4.2 he static LIST_HEAD(, iop_initiator) *iop_ictxhashtbl;
101 1.19.4.2 he static u_long iop_ictxhash;
102 1.19.4.2 he static void *iop_sdh;
103 1.19.4.2 he static struct i2o_systab *iop_systab;
104 1.19.4.2 he static int iop_systab_size;
105 1.19.4.2 he
106 1.19.4.2 he extern struct cfdriver iop_cd;
107 1.19.4.2 he
108 1.19.4.2 he #define IC_CONFIGURE 0x01
109 1.19.4.2 he #define IC_PRIORITY 0x02
110 1.19.4.2 he
111 1.19.4.2 he struct iop_class {
112 1.19.4.2 he u_short ic_class;
113 1.19.4.2 he u_short ic_flags;
114 1.19.4.2 he #ifdef I2OVERBOSE
115 1.19.4.2 he const char *ic_caption;
116 1.19.4.2 he #endif
117 1.19.4.2 he } static const iop_class[] = {
118 1.19.4.2 he {
119 1.19.4.2 he I2O_CLASS_EXECUTIVE,
120 1.19.4.2 he 0,
121 1.19.4.2 he COMMENT("executive")
122 1.19.4.2 he },
123 1.19.4.2 he {
124 1.19.4.2 he I2O_CLASS_DDM,
125 1.19.4.2 he 0,
126 1.19.4.2 he COMMENT("device driver module")
127 1.19.4.2 he },
128 1.19.4.2 he {
129 1.19.4.2 he I2O_CLASS_RANDOM_BLOCK_STORAGE,
130 1.19.4.2 he IC_CONFIGURE | IC_PRIORITY,
131 1.19.4.2 he IFVERBOSE("random block storage")
132 1.19.4.2 he },
133 1.19.4.2 he {
134 1.19.4.2 he I2O_CLASS_SEQUENTIAL_STORAGE,
135 1.19.4.2 he IC_CONFIGURE | IC_PRIORITY,
136 1.19.4.2 he IFVERBOSE("sequential storage")
137 1.19.4.2 he },
138 1.19.4.2 he {
139 1.19.4.2 he I2O_CLASS_LAN,
140 1.19.4.2 he IC_CONFIGURE | IC_PRIORITY,
141 1.19.4.2 he IFVERBOSE("LAN port")
142 1.19.4.2 he },
143 1.19.4.2 he {
144 1.19.4.2 he I2O_CLASS_WAN,
145 1.19.4.2 he IC_CONFIGURE | IC_PRIORITY,
146 1.19.4.2 he IFVERBOSE("WAN port")
147 1.19.4.2 he },
148 1.19.4.2 he {
149 1.19.4.2 he I2O_CLASS_FIBRE_CHANNEL_PORT,
150 1.19.4.2 he IC_CONFIGURE,
151 1.19.4.2 he IFVERBOSE("fibrechannel port")
152 1.19.4.2 he },
153 1.19.4.2 he {
154 1.19.4.2 he I2O_CLASS_FIBRE_CHANNEL_PERIPHERAL,
155 1.19.4.2 he 0,
156 1.19.4.2 he COMMENT("fibrechannel peripheral")
157 1.19.4.2 he },
158 1.19.4.2 he {
159 1.19.4.2 he I2O_CLASS_SCSI_PERIPHERAL,
160 1.19.4.2 he 0,
161 1.19.4.2 he COMMENT("SCSI peripheral")
162 1.19.4.2 he },
163 1.19.4.2 he {
164 1.19.4.2 he I2O_CLASS_ATE_PORT,
165 1.19.4.2 he IC_CONFIGURE,
166 1.19.4.2 he IFVERBOSE("ATE port")
167 1.19.4.2 he },
168 1.19.4.2 he {
169 1.19.4.2 he I2O_CLASS_ATE_PERIPHERAL,
170 1.19.4.2 he 0,
171 1.19.4.2 he COMMENT("ATE peripheral")
172 1.19.4.2 he },
173 1.19.4.2 he {
174 1.19.4.2 he I2O_CLASS_FLOPPY_CONTROLLER,
175 1.19.4.2 he IC_CONFIGURE,
176 1.19.4.2 he IFVERBOSE("floppy controller")
177 1.19.4.2 he },
178 1.19.4.2 he {
179 1.19.4.2 he I2O_CLASS_FLOPPY_DEVICE,
180 1.19.4.2 he 0,
181 1.19.4.2 he COMMENT("floppy device")
182 1.19.4.2 he },
183 1.19.4.2 he {
184 1.19.4.2 he I2O_CLASS_BUS_ADAPTER_PORT,
185 1.19.4.2 he IC_CONFIGURE,
186 1.19.4.2 he IFVERBOSE("bus adapter port" )
187 1.19.4.2 he },
188 1.19.4.2 he };
189 1.19.4.2 he
190 1.19.4.2 he #if defined(I2ODEBUG) && defined(I2OVERBOSE)
191 1.19.4.2 he static const char * const iop_status[] = {
192 1.19.4.2 he "success",
193 1.19.4.2 he "abort (dirty)",
194 1.19.4.2 he "abort (no data transfer)",
195 1.19.4.2 he "abort (partial transfer)",
196 1.19.4.2 he "error (dirty)",
197 1.19.4.2 he "error (no data transfer)",
198 1.19.4.2 he "error (partial transfer)",
199 1.19.4.2 he "undefined error code",
200 1.19.4.2 he "process abort (dirty)",
201 1.19.4.2 he "process abort (no data transfer)",
202 1.19.4.2 he "process abort (partial transfer)",
203 1.19.4.2 he "transaction error",
204 1.19.4.2 he };
205 1.19.4.2 he #endif
206 1.19.4.2 he
207 1.19.4.2 he static inline u_int32_t iop_inl(struct iop_softc *, int);
208 1.19.4.2 he static inline void iop_outl(struct iop_softc *, int, u_int32_t);
209 1.19.4.2 he
210 1.19.4.2 he static void iop_config_interrupts(struct device *);
211 1.19.4.2 he static void iop_configure_devices(struct iop_softc *, int, int);
212 1.19.4.2 he static void iop_devinfo(int, char *);
213 1.19.4.2 he static int iop_print(void *, const char *);
214 1.19.4.2 he static void iop_shutdown(void *);
215 1.19.4.2 he static int iop_submatch(struct device *, struct cfdata *, void *);
216 1.19.4.2 he static int iop_vendor_print(void *, const char *);
217 1.19.4.2 he
218 1.19.4.2 he static void iop_adjqparam(struct iop_softc *, int);
219 1.19.4.2 he static void iop_create_reconf_thread(void *);
220 1.19.4.2 he static int iop_handle_reply(struct iop_softc *, u_int32_t);
221 1.19.4.2 he static int iop_hrt_get(struct iop_softc *);
222 1.19.4.2 he static int iop_hrt_get0(struct iop_softc *, struct i2o_hrt *, int);
223 1.19.4.2 he static void iop_intr_event(struct device *, struct iop_msg *, void *);
224 1.19.4.2 he static int iop_lct_get0(struct iop_softc *, struct i2o_lct *, int,
225 1.19.4.2 he u_int32_t);
226 1.19.4.2 he static void iop_msg_poll(struct iop_softc *, struct iop_msg *, int);
227 1.19.4.2 he static void iop_msg_wait(struct iop_softc *, struct iop_msg *, int);
228 1.19.4.2 he static int iop_ofifo_init(struct iop_softc *);
229 1.19.4.2 he static int iop_passthrough(struct iop_softc *, struct ioppt *,
230 1.19.4.2 he struct proc *);
231 1.19.4.2 he static void iop_reconf_thread(void *);
232 1.19.4.2 he static void iop_release_mfa(struct iop_softc *, u_int32_t);
233 1.19.4.2 he static int iop_reset(struct iop_softc *);
234 1.19.4.2 he static int iop_systab_set(struct iop_softc *);
235 1.19.4.2 he static void iop_tfn_print(struct iop_softc *, struct i2o_fault_notify *);
236 1.19.4.2 he
237 1.19.4.2 he #ifdef I2ODEBUG
238 1.19.4.2 he static void iop_reply_print(struct iop_softc *, struct i2o_reply *);
239 1.19.4.2 he #endif
240 1.19.4.2 he
241 1.19.4.2 he cdev_decl(iop);
242 1.19.4.2 he
243 1.19.4.2 he static inline u_int32_t
244 1.19.4.2 he iop_inl(struct iop_softc *sc, int off)
245 1.19.4.2 he {
246 1.19.4.2 he
247 1.19.4.2 he bus_space_barrier(sc->sc_iot, sc->sc_ioh, off, 4,
248 1.19.4.2 he BUS_SPACE_BARRIER_WRITE | BUS_SPACE_BARRIER_READ);
249 1.19.4.2 he return (bus_space_read_4(sc->sc_iot, sc->sc_ioh, off));
250 1.19.4.2 he }
251 1.19.4.2 he
252 1.19.4.2 he static inline void
253 1.19.4.2 he iop_outl(struct iop_softc *sc, int off, u_int32_t val)
254 1.19.4.2 he {
255 1.19.4.2 he
256 1.19.4.2 he bus_space_write_4(sc->sc_iot, sc->sc_ioh, off, val);
257 1.19.4.2 he bus_space_barrier(sc->sc_iot, sc->sc_ioh, off, 4,
258 1.19.4.2 he BUS_SPACE_BARRIER_WRITE);
259 1.19.4.2 he }
260 1.19.4.2 he
261 1.19.4.2 he /*
262 1.19.4.2 he * Initialise the IOP and our interface.
263 1.19.4.2 he */
264 1.19.4.2 he void
265 1.19.4.2 he iop_init(struct iop_softc *sc, const char *intrstr)
266 1.19.4.2 he {
267 1.19.4.2 he struct iop_msg *im;
268 1.19.4.2 he int rv, i, j, state, nsegs;
269 1.19.4.2 he u_int32_t mask;
270 1.19.4.2 he char ident[64];
271 1.19.4.2 he
272 1.19.4.2 he state = 0;
273 1.19.4.2 he
274 1.19.4.2 he printf("I2O adapter");
275 1.19.4.2 he
276 1.19.4.2 he if (iop_ictxhashtbl == NULL)
277 1.19.4.2 he iop_ictxhashtbl = hashinit(IOP_ICTXHASH_NBUCKETS,
278 1.19.4.2 he M_DEVBUF, M_NOWAIT, &iop_ictxhash);
279 1.19.4.2 he
280 1.19.4.2 he /* Disable interrupts at the IOP. */
281 1.19.4.2 he mask = iop_inl(sc, IOP_REG_INTR_MASK);
282 1.19.4.2 he iop_outl(sc, IOP_REG_INTR_MASK, mask | IOP_INTR_OFIFO);
283 1.19.4.2 he
284 1.19.4.2 he /* Allocate a scratch DMA map for small miscellaneous shared data. */
285 1.19.4.2 he if (bus_dmamap_create(sc->sc_dmat, NBPG, 1, NBPG, 0,
286 1.19.4.2 he BUS_DMA_NOWAIT | BUS_DMA_ALLOCNOW, &sc->sc_scr_dmamap) != 0) {
287 1.19.4.2 he printf("%s: cannot create scratch dmamap\n",
288 1.19.4.2 he sc->sc_dv.dv_xname);
289 1.19.4.2 he return;
290 1.19.4.2 he }
291 1.19.4.2 he state++;
292 1.19.4.2 he
293 1.19.4.2 he if (bus_dmamem_alloc(sc->sc_dmat, NBPG, NBPG, 0,
294 1.19.4.2 he sc->sc_scr_seg, 1, &nsegs, BUS_DMA_NOWAIT) != 0) {
295 1.19.4.2 he printf("%s: cannot alloc scratch dmamem\n",
296 1.19.4.2 he sc->sc_dv.dv_xname);
297 1.19.4.2 he goto bail_out;
298 1.19.4.2 he }
299 1.19.4.2 he state++;
300 1.19.4.2 he
301 1.19.4.2 he if (bus_dmamem_map(sc->sc_dmat, sc->sc_scr_seg, nsegs, NBPG,
302 1.19.4.2 he &sc->sc_scr, 0)) {
303 1.19.4.2 he printf("%s: cannot map scratch dmamem\n", sc->sc_dv.dv_xname);
304 1.19.4.2 he goto bail_out;
305 1.19.4.2 he }
306 1.19.4.2 he state++;
307 1.19.4.2 he
308 1.19.4.2 he if (bus_dmamap_load(sc->sc_dmat, sc->sc_scr_dmamap, sc->sc_scr,
309 1.19.4.2 he NBPG, NULL, BUS_DMA_NOWAIT)) {
310 1.19.4.2 he printf("%s: cannot load scratch dmamap\n", sc->sc_dv.dv_xname);
311 1.19.4.2 he goto bail_out;
312 1.19.4.2 he }
313 1.19.4.2 he state++;
314 1.19.4.2 he
315 1.19.4.2 he /* Reset the adapter and request status. */
316 1.19.4.2 he if ((rv = iop_reset(sc)) != 0) {
317 1.19.4.2 he printf("%s: not responding (reset)\n", sc->sc_dv.dv_xname);
318 1.19.4.2 he goto bail_out;
319 1.19.4.2 he }
320 1.19.4.2 he
321 1.19.4.2 he if ((rv = iop_status_get(sc, 1)) != 0) {
322 1.19.4.2 he printf("%s: not responding (get status)\n",
323 1.19.4.2 he sc->sc_dv.dv_xname);
324 1.19.4.2 he goto bail_out;
325 1.19.4.2 he }
326 1.19.4.2 he
327 1.19.4.2 he sc->sc_flags |= IOP_HAVESTATUS;
328 1.19.4.2 he iop_strvis(sc, sc->sc_status.productid, sizeof(sc->sc_status.productid),
329 1.19.4.2 he ident, sizeof(ident));
330 1.19.4.2 he printf(" <%s>\n", ident);
331 1.19.4.2 he
332 1.19.4.2 he #ifdef I2ODEBUG
333 1.19.4.2 he printf("%s: orgid=0x%04x version=%d\n", sc->sc_dv.dv_xname,
334 1.19.4.2 he le16toh(sc->sc_status.orgid),
335 1.19.4.2 he (le32toh(sc->sc_status.segnumber) >> 12) & 15);
336 1.19.4.2 he printf("%s: type want have cbase\n", sc->sc_dv.dv_xname);
337 1.19.4.2 he printf("%s: mem %04x %04x %08x\n", sc->sc_dv.dv_xname,
338 1.19.4.2 he le32toh(sc->sc_status.desiredprivmemsize),
339 1.19.4.2 he le32toh(sc->sc_status.currentprivmemsize),
340 1.19.4.2 he le32toh(sc->sc_status.currentprivmembase));
341 1.19.4.2 he printf("%s: i/o %04x %04x %08x\n", sc->sc_dv.dv_xname,
342 1.19.4.2 he le32toh(sc->sc_status.desiredpriviosize),
343 1.19.4.2 he le32toh(sc->sc_status.currentpriviosize),
344 1.19.4.2 he le32toh(sc->sc_status.currentpriviobase));
345 1.19.4.2 he #endif
346 1.19.4.2 he
347 1.19.4.2 he sc->sc_maxob = le32toh(sc->sc_status.maxoutboundmframes);
348 1.19.4.2 he if (sc->sc_maxob > IOP_MAX_OUTBOUND)
349 1.19.4.2 he sc->sc_maxob = IOP_MAX_OUTBOUND;
350 1.19.4.2 he sc->sc_maxib = le32toh(sc->sc_status.maxinboundmframes);
351 1.19.4.2 he if (sc->sc_maxib > IOP_MAX_INBOUND)
352 1.19.4.2 he sc->sc_maxib = IOP_MAX_INBOUND;
353 1.19.4.2 he
354 1.19.4.2 he /* Allocate message wrappers. */
355 1.19.4.2 he im = malloc(sizeof(*im) * sc->sc_maxib, M_DEVBUF, M_NOWAIT);
356 1.19.4.2 he memset(im, 0, sizeof(*im) * sc->sc_maxib);
357 1.19.4.2 he sc->sc_ims = im;
358 1.19.4.2 he SLIST_INIT(&sc->sc_im_freelist);
359 1.19.4.2 he
360 1.19.4.2 he for (i = 0, state++; i < sc->sc_maxib; i++, im++) {
361 1.19.4.2 he rv = bus_dmamap_create(sc->sc_dmat, IOP_MAX_XFER,
362 1.19.4.2 he IOP_MAX_SEGS, IOP_MAX_XFER, 0,
363 1.19.4.2 he BUS_DMA_NOWAIT | BUS_DMA_ALLOCNOW,
364 1.19.4.2 he &im->im_xfer[0].ix_map);
365 1.19.4.2 he if (rv != 0) {
366 1.19.4.2 he printf("%s: couldn't create dmamap (%d)",
367 1.19.4.2 he sc->sc_dv.dv_xname, rv);
368 1.19.4.2 he goto bail_out;
369 1.19.4.2 he }
370 1.19.4.2 he
371 1.19.4.2 he im->im_tctx = i;
372 1.19.4.2 he SLIST_INSERT_HEAD(&sc->sc_im_freelist, im, im_chain);
373 1.19.4.2 he }
374 1.19.4.2 he
375 1.19.4.3 he /* Initialise the IOP's outbound FIFO. */
376 1.19.4.2 he if (iop_ofifo_init(sc) != 0) {
377 1.19.4.2 he printf("%s: unable to init oubound FIFO\n",
378 1.19.4.2 he sc->sc_dv.dv_xname);
379 1.19.4.2 he goto bail_out;
380 1.19.4.2 he }
381 1.19.4.2 he
382 1.19.4.2 he /*
383 1.19.4.2 he * Defer further configuration until (a) interrupts are working and
384 1.19.4.2 he * (b) we have enough information to build the system table.
385 1.19.4.2 he */
386 1.19.4.2 he config_interrupts((struct device *)sc, iop_config_interrupts);
387 1.19.4.2 he
388 1.19.4.2 he /* Configure shutdown hook before we start any device activity. */
389 1.19.4.2 he if (iop_sdh == NULL)
390 1.19.4.2 he iop_sdh = shutdownhook_establish(iop_shutdown, NULL);
391 1.19.4.2 he
392 1.19.4.2 he /* Ensure interrupts are enabled at the IOP. */
393 1.19.4.2 he mask = iop_inl(sc, IOP_REG_INTR_MASK);
394 1.19.4.2 he iop_outl(sc, IOP_REG_INTR_MASK, mask & ~IOP_INTR_OFIFO);
395 1.19.4.2 he
396 1.19.4.2 he if (intrstr != NULL)
397 1.19.4.2 he printf("%s: interrupting at %s\n", sc->sc_dv.dv_xname,
398 1.19.4.2 he intrstr);
399 1.19.4.2 he
400 1.19.4.2 he #ifdef I2ODEBUG
401 1.19.4.2 he printf("%s: queue depths: inbound %d/%d, outbound %d/%d\n",
402 1.19.4.2 he sc->sc_dv.dv_xname, sc->sc_maxib,
403 1.19.4.2 he le32toh(sc->sc_status.maxinboundmframes),
404 1.19.4.2 he sc->sc_maxob, le32toh(sc->sc_status.maxoutboundmframes));
405 1.19.4.2 he #endif
406 1.19.4.2 he
407 1.19.4.2 he lockinit(&sc->sc_conflock, PRIBIO, "iopconf", hz * 30, 0);
408 1.19.4.2 he return;
409 1.19.4.2 he
410 1.19.4.2 he bail_out:
411 1.19.4.2 he if (state > 3) {
412 1.19.4.2 he for (j = 0; j < i; j++)
413 1.19.4.2 he bus_dmamap_destroy(sc->sc_dmat,
414 1.19.4.2 he sc->sc_ims[j].im_xfer[0].ix_map);
415 1.19.4.2 he free(sc->sc_ims, M_DEVBUF);
416 1.19.4.2 he }
417 1.19.4.2 he if (state > 2)
418 1.19.4.2 he bus_dmamap_unload(sc->sc_dmat, sc->sc_scr_dmamap);
419 1.19.4.2 he if (state > 1)
420 1.19.4.2 he bus_dmamem_unmap(sc->sc_dmat, sc->sc_scr, NBPG);
421 1.19.4.2 he if (state > 0)
422 1.19.4.2 he bus_dmamem_free(sc->sc_dmat, sc->sc_scr_seg, nsegs);
423 1.19.4.2 he bus_dmamap_destroy(sc->sc_dmat, sc->sc_scr_dmamap);
424 1.19.4.2 he
425 1.19.4.2 he }
426 1.19.4.2 he
427 1.19.4.2 he /*
428 1.19.4.2 he * Perform autoconfiguration tasks.
429 1.19.4.2 he */
430 1.19.4.2 he static void
431 1.19.4.2 he iop_config_interrupts(struct device *self)
432 1.19.4.2 he {
433 1.19.4.3 he struct iop_attach_args ia;
434 1.19.4.2 he struct iop_softc *sc, *iop;
435 1.19.4.2 he struct i2o_systab_entry *ste;
436 1.19.4.2 he int rv, i, niop;
437 1.19.4.2 he
438 1.19.4.2 he sc = (struct iop_softc *)self;
439 1.19.4.2 he LIST_INIT(&sc->sc_iilist);
440 1.19.4.2 he
441 1.19.4.2 he printf("%s: configuring...\n", sc->sc_dv.dv_xname);
442 1.19.4.2 he
443 1.19.4.2 he if (iop_hrt_get(sc) != 0) {
444 1.19.4.2 he printf("%s: unable to retrieve HRT\n", sc->sc_dv.dv_xname);
445 1.19.4.2 he return;
446 1.19.4.2 he }
447 1.19.4.2 he
448 1.19.4.2 he /*
449 1.19.4.2 he * Build the system table.
450 1.19.4.2 he */
451 1.19.4.2 he if (iop_systab == NULL) {
452 1.19.4.2 he for (i = 0, niop = 0; i < iop_cd.cd_ndevs; i++) {
453 1.19.4.2 he if ((iop = device_lookup(&iop_cd, i)) == NULL)
454 1.19.4.2 he continue;
455 1.19.4.2 he if ((iop->sc_flags & IOP_HAVESTATUS) == 0)
456 1.19.4.2 he continue;
457 1.19.4.2 he if (iop_status_get(iop, 1) != 0) {
458 1.19.4.2 he printf("%s: unable to retrieve status\n",
459 1.19.4.2 he sc->sc_dv.dv_xname);
460 1.19.4.2 he iop->sc_flags &= ~IOP_HAVESTATUS;
461 1.19.4.2 he continue;
462 1.19.4.2 he }
463 1.19.4.2 he niop++;
464 1.19.4.2 he }
465 1.19.4.2 he if (niop == 0)
466 1.19.4.2 he return;
467 1.19.4.2 he
468 1.19.4.2 he i = sizeof(struct i2o_systab_entry) * (niop - 1) +
469 1.19.4.2 he sizeof(struct i2o_systab);
470 1.19.4.2 he iop_systab_size = i;
471 1.19.4.2 he iop_systab = malloc(i, M_DEVBUF, M_NOWAIT);
472 1.19.4.2 he
473 1.19.4.2 he memset(iop_systab, 0, i);
474 1.19.4.2 he iop_systab->numentries = niop;
475 1.19.4.2 he iop_systab->version = I2O_VERSION_11;
476 1.19.4.2 he
477 1.19.4.2 he for (i = 0, ste = iop_systab->entry; i < iop_cd.cd_ndevs; i++) {
478 1.19.4.2 he if ((iop = device_lookup(&iop_cd, i)) == NULL)
479 1.19.4.2 he continue;
480 1.19.4.2 he if ((iop->sc_flags & IOP_HAVESTATUS) == 0)
481 1.19.4.2 he continue;
482 1.19.4.2 he
483 1.19.4.2 he ste->orgid = iop->sc_status.orgid;
484 1.19.4.2 he ste->iopid = iop->sc_dv.dv_unit + 2;
485 1.19.4.2 he ste->segnumber =
486 1.19.4.2 he htole32(le32toh(iop->sc_status.segnumber) & ~4095);
487 1.19.4.2 he ste->iopcaps = iop->sc_status.iopcaps;
488 1.19.4.2 he ste->inboundmsgframesize =
489 1.19.4.2 he iop->sc_status.inboundmframesize;
490 1.19.4.2 he ste->inboundmsgportaddresslow =
491 1.19.4.2 he htole32(iop->sc_memaddr + IOP_REG_IFIFO);
492 1.19.4.2 he ste++;
493 1.19.4.2 he }
494 1.19.4.2 he }
495 1.19.4.2 he
496 1.19.4.2 he /*
497 1.19.4.2 he * Post the system table to the IOP and bring it to the OPERATIONAL
498 1.19.4.2 he * state.
499 1.19.4.2 he */
500 1.19.4.2 he if (iop_systab_set(sc) != 0) {
501 1.19.4.2 he printf("%s: unable to set system table\n", sc->sc_dv.dv_xname);
502 1.19.4.2 he return;
503 1.19.4.2 he }
504 1.19.4.2 he if (iop_simple_cmd(sc, I2O_TID_IOP, I2O_EXEC_SYS_ENABLE, IOP_ICTX, 1,
505 1.19.4.2 he 30000) != 0) {
506 1.19.4.2 he printf("%s: unable to enable system\n", sc->sc_dv.dv_xname);
507 1.19.4.2 he return;
508 1.19.4.2 he }
509 1.19.4.2 he
510 1.19.4.2 he /*
511 1.19.4.2 he * Set up an event handler for this IOP.
512 1.19.4.2 he */
513 1.19.4.2 he sc->sc_eventii.ii_dv = self;
514 1.19.4.2 he sc->sc_eventii.ii_intr = iop_intr_event;
515 1.19.4.2 he sc->sc_eventii.ii_flags = II_NOTCTX | II_UTILITY;
516 1.19.4.2 he sc->sc_eventii.ii_tid = I2O_TID_IOP;
517 1.19.4.2 he iop_initiator_register(sc, &sc->sc_eventii);
518 1.19.4.2 he
519 1.19.4.2 he rv = iop_util_eventreg(sc, &sc->sc_eventii,
520 1.19.4.2 he I2O_EVENT_EXEC_RESOURCE_LIMITS |
521 1.19.4.2 he I2O_EVENT_EXEC_CONNECTION_FAIL |
522 1.19.4.2 he I2O_EVENT_EXEC_ADAPTER_FAULT |
523 1.19.4.2 he I2O_EVENT_EXEC_POWER_FAIL |
524 1.19.4.2 he I2O_EVENT_EXEC_RESET_PENDING |
525 1.19.4.2 he I2O_EVENT_EXEC_RESET_IMMINENT |
526 1.19.4.2 he I2O_EVENT_EXEC_HARDWARE_FAIL |
527 1.19.4.2 he I2O_EVENT_EXEC_XCT_CHANGE |
528 1.19.4.2 he I2O_EVENT_EXEC_DDM_AVAILIBILITY |
529 1.19.4.2 he I2O_EVENT_GEN_DEVICE_RESET |
530 1.19.4.2 he I2O_EVENT_GEN_STATE_CHANGE |
531 1.19.4.2 he I2O_EVENT_GEN_GENERAL_WARNING);
532 1.19.4.2 he if (rv != 0) {
533 1.19.4.2 he printf("%s: unable to register for events", sc->sc_dv.dv_xname);
534 1.19.4.2 he return;
535 1.19.4.2 he }
536 1.19.4.2 he
537 1.19.4.3 he /*
538 1.19.4.3 he * Attempt to match and attach a product-specific extension.
539 1.19.4.3 he */
540 1.19.4.2 he ia.ia_class = I2O_CLASS_ANY;
541 1.19.4.2 he ia.ia_tid = I2O_TID_IOP;
542 1.19.4.2 he config_found_sm(self, &ia, iop_vendor_print, iop_submatch);
543 1.19.4.2 he
544 1.19.4.3 he /*
545 1.19.4.3 he * Start device configuration.
546 1.19.4.3 he */
547 1.19.4.2 he lockmgr(&sc->sc_conflock, LK_EXCLUSIVE, NULL);
548 1.19.4.2 he if ((rv = iop_reconfigure(sc, 0)) == -1) {
549 1.19.4.2 he printf("%s: configure failed (%d)\n", sc->sc_dv.dv_xname, rv);
550 1.19.4.2 he return;
551 1.19.4.2 he }
552 1.19.4.2 he lockmgr(&sc->sc_conflock, LK_RELEASE, NULL);
553 1.19.4.2 he
554 1.19.4.2 he kthread_create(iop_create_reconf_thread, sc);
555 1.19.4.2 he }
556 1.19.4.2 he
557 1.19.4.2 he /*
558 1.19.4.2 he * Create the reconfiguration thread. Called after the standard kernel
559 1.19.4.2 he * threads have been created.
560 1.19.4.2 he */
561 1.19.4.2 he static void
562 1.19.4.2 he iop_create_reconf_thread(void *cookie)
563 1.19.4.2 he {
564 1.19.4.2 he struct iop_softc *sc;
565 1.19.4.2 he int rv;
566 1.19.4.2 he
567 1.19.4.2 he sc = cookie;
568 1.19.4.2 he sc->sc_flags |= IOP_ONLINE;
569 1.19.4.2 he
570 1.19.4.2 he rv = kthread_create1(iop_reconf_thread, sc, &sc->sc_reconf_proc,
571 1.19.4.2 he "%s", sc->sc_dv.dv_xname);
572 1.19.4.2 he if (rv != 0) {
573 1.19.4.2 he printf("%s: unable to create reconfiguration thread (%d)",
574 1.19.4.2 he sc->sc_dv.dv_xname, rv);
575 1.19.4.2 he return;
576 1.19.4.2 he }
577 1.19.4.2 he }
578 1.19.4.2 he
579 1.19.4.2 he /*
580 1.19.4.2 he * Reconfiguration thread; listens for LCT change notification, and
581 1.19.4.2 he * initiates re-configuration if received.
582 1.19.4.2 he */
583 1.19.4.2 he static void
584 1.19.4.2 he iop_reconf_thread(void *cookie)
585 1.19.4.2 he {
586 1.19.4.2 he struct iop_softc *sc;
587 1.19.4.2 he struct i2o_lct lct;
588 1.19.4.2 he u_int32_t chgind;
589 1.19.4.2 he int rv;
590 1.19.4.2 he
591 1.19.4.2 he sc = cookie;
592 1.19.4.2 he chgind = sc->sc_chgind + 1;
593 1.19.4.2 he
594 1.19.4.2 he for (;;) {
595 1.19.4.2 he DPRINTF(("%s: async reconfig: requested 0x%08x\n",
596 1.19.4.2 he sc->sc_dv.dv_xname, chgind));
597 1.19.4.2 he
598 1.19.4.2 he PHOLD(sc->sc_reconf_proc);
599 1.19.4.2 he rv = iop_lct_get0(sc, &lct, sizeof(lct), chgind);
600 1.19.4.2 he PRELE(sc->sc_reconf_proc);
601 1.19.4.2 he
602 1.19.4.2 he DPRINTF(("%s: async reconfig: notified (0x%08x, %d)\n",
603 1.19.4.2 he sc->sc_dv.dv_xname, le32toh(lct.changeindicator), rv));
604 1.19.4.2 he
605 1.19.4.2 he if (rv == 0 &&
606 1.19.4.2 he lockmgr(&sc->sc_conflock, LK_EXCLUSIVE, NULL) == 0) {
607 1.19.4.2 he iop_reconfigure(sc, le32toh(lct.changeindicator));
608 1.19.4.2 he chgind = sc->sc_chgind + 1;
609 1.19.4.2 he lockmgr(&sc->sc_conflock, LK_RELEASE, NULL);
610 1.19.4.2 he }
611 1.19.4.2 he
612 1.19.4.2 he tsleep(iop_reconf_thread, PWAIT, "iopzzz", hz * 5);
613 1.19.4.2 he }
614 1.19.4.2 he }
615 1.19.4.2 he
616 1.19.4.2 he /*
617 1.19.4.2 he * Reconfigure: find new and removed devices.
618 1.19.4.2 he */
619 1.19.4.3 he int
620 1.19.4.2 he iop_reconfigure(struct iop_softc *sc, u_int chgind)
621 1.19.4.2 he {
622 1.19.4.2 he struct iop_msg *im;
623 1.19.4.2 he struct i2o_hba_bus_scan mf;
624 1.19.4.2 he struct i2o_lct_entry *le;
625 1.19.4.2 he struct iop_initiator *ii, *nextii;
626 1.19.4.2 he int rv, tid, i;
627 1.19.4.2 he
628 1.19.4.2 he /*
629 1.19.4.2 he * If the reconfiguration request isn't the result of LCT change
630 1.19.4.2 he * notification, then be more thorough: ask all bus ports to scan
631 1.19.4.2 he * their busses. Wait up to 5 minutes for each bus port to complete
632 1.19.4.2 he * the request.
633 1.19.4.2 he */
634 1.19.4.2 he if (chgind == 0) {
635 1.19.4.2 he if ((rv = iop_lct_get(sc)) != 0) {
636 1.19.4.2 he DPRINTF(("iop_reconfigure: unable to read LCT\n"));
637 1.19.4.2 he return (rv);
638 1.19.4.2 he }
639 1.19.4.2 he
640 1.19.4.2 he le = sc->sc_lct->entry;
641 1.19.4.2 he for (i = 0; i < sc->sc_nlctent; i++, le++) {
642 1.19.4.2 he if ((le16toh(le->classid) & 4095) !=
643 1.19.4.2 he I2O_CLASS_BUS_ADAPTER_PORT)
644 1.19.4.2 he continue;
645 1.19.4.2 he tid = le16toh(le->localtid) & 4095;
646 1.19.4.2 he
647 1.19.4.2 he im = iop_msg_alloc(sc, IM_WAIT);
648 1.19.4.2 he
649 1.19.4.2 he mf.msgflags = I2O_MSGFLAGS(i2o_hba_bus_scan);
650 1.19.4.2 he mf.msgfunc = I2O_MSGFUNC(tid, I2O_HBA_BUS_SCAN);
651 1.19.4.2 he mf.msgictx = IOP_ICTX;
652 1.19.4.2 he mf.msgtctx = im->im_tctx;
653 1.19.4.2 he
654 1.19.4.2 he DPRINTF(("%s: scanning bus %d\n", sc->sc_dv.dv_xname,
655 1.19.4.2 he tid));
656 1.19.4.2 he
657 1.19.4.2 he rv = iop_msg_post(sc, im, &mf, 5*60*1000);
658 1.19.4.2 he iop_msg_free(sc, im);
659 1.19.4.2 he #ifdef I2ODEBUG
660 1.19.4.2 he if (rv != 0)
661 1.19.4.2 he printf("%s: bus scan failed\n",
662 1.19.4.2 he sc->sc_dv.dv_xname);
663 1.19.4.2 he #endif
664 1.19.4.2 he }
665 1.19.4.2 he } else if (chgind <= sc->sc_chgind) {
666 1.19.4.2 he DPRINTF(("%s: LCT unchanged (async)\n", sc->sc_dv.dv_xname));
667 1.19.4.2 he return (0);
668 1.19.4.2 he }
669 1.19.4.2 he
670 1.19.4.2 he /* Re-read the LCT and determine if it has changed. */
671 1.19.4.2 he if ((rv = iop_lct_get(sc)) != 0) {
672 1.19.4.2 he DPRINTF(("iop_reconfigure: unable to re-read LCT\n"));
673 1.19.4.2 he return (rv);
674 1.19.4.2 he }
675 1.19.4.2 he DPRINTF(("%s: %d LCT entries\n", sc->sc_dv.dv_xname, sc->sc_nlctent));
676 1.19.4.2 he
677 1.19.4.2 he chgind = le32toh(sc->sc_lct->changeindicator);
678 1.19.4.2 he if (chgind == sc->sc_chgind) {
679 1.19.4.2 he DPRINTF(("%s: LCT unchanged\n", sc->sc_dv.dv_xname));
680 1.19.4.2 he return (0);
681 1.19.4.2 he }
682 1.19.4.2 he DPRINTF(("%s: LCT changed\n", sc->sc_dv.dv_xname));
683 1.19.4.2 he sc->sc_chgind = chgind;
684 1.19.4.2 he
685 1.19.4.2 he if (sc->sc_tidmap != NULL)
686 1.19.4.2 he free(sc->sc_tidmap, M_DEVBUF);
687 1.19.4.2 he sc->sc_tidmap = malloc(sc->sc_nlctent * sizeof(struct iop_tidmap),
688 1.19.4.2 he M_DEVBUF, M_NOWAIT);
689 1.19.4.2 he memset(sc->sc_tidmap, 0, sizeof(sc->sc_tidmap));
690 1.19.4.2 he
691 1.19.4.2 he /* Allow 1 queued command per device while we're configuring. */
692 1.19.4.2 he iop_adjqparam(sc, 1);
693 1.19.4.2 he
694 1.19.4.2 he /*
695 1.19.4.2 he * Match and attach child devices. We configure high-level devices
696 1.19.4.2 he * first so that any claims will propagate throughout the LCT,
697 1.19.4.2 he * hopefully masking off aliased devices as a result.
698 1.19.4.2 he *
699 1.19.4.2 he * Re-reading the LCT at this point is a little dangerous, but we'll
700 1.19.4.2 he * trust the IOP (and the operator) to behave itself...
701 1.19.4.2 he */
702 1.19.4.2 he iop_configure_devices(sc, IC_CONFIGURE | IC_PRIORITY,
703 1.19.4.2 he IC_CONFIGURE | IC_PRIORITY);
704 1.19.4.2 he if ((rv = iop_lct_get(sc)) != 0)
705 1.19.4.2 he DPRINTF(("iop_reconfigure: unable to re-read LCT\n"));
706 1.19.4.2 he iop_configure_devices(sc, IC_CONFIGURE | IC_PRIORITY,
707 1.19.4.2 he IC_CONFIGURE);
708 1.19.4.2 he
709 1.19.4.2 he for (ii = LIST_FIRST(&sc->sc_iilist); ii != NULL; ii = nextii) {
710 1.19.4.2 he nextii = LIST_NEXT(ii, ii_list);
711 1.19.4.2 he
712 1.19.4.2 he /* Detach devices that were configured, but are now gone. */
713 1.19.4.2 he for (i = 0; i < sc->sc_nlctent; i++)
714 1.19.4.2 he if (ii->ii_tid == sc->sc_tidmap[i].it_tid)
715 1.19.4.2 he break;
716 1.19.4.2 he if (i == sc->sc_nlctent ||
717 1.19.4.2 he (sc->sc_tidmap[i].it_flags & IT_CONFIGURED) == 0)
718 1.19.4.2 he config_detach(ii->ii_dv, DETACH_FORCE);
719 1.19.4.2 he
720 1.19.4.2 he /*
721 1.19.4.2 he * Tell initiators that existed before the re-configuration
722 1.19.4.2 he * to re-configure.
723 1.19.4.2 he */
724 1.19.4.2 he if (ii->ii_reconfig == NULL)
725 1.19.4.2 he continue;
726 1.19.4.2 he if ((rv = (*ii->ii_reconfig)(ii->ii_dv)) != 0)
727 1.19.4.2 he printf("%s: %s failed reconfigure (%d)\n",
728 1.19.4.2 he sc->sc_dv.dv_xname, ii->ii_dv->dv_xname, rv);
729 1.19.4.2 he }
730 1.19.4.2 he
731 1.19.4.2 he /* Re-adjust queue parameters and return. */
732 1.19.4.2 he if (sc->sc_nii != 0)
733 1.19.4.2 he iop_adjqparam(sc, (sc->sc_maxib - sc->sc_nuii - IOP_MF_RESERVE)
734 1.19.4.2 he / sc->sc_nii);
735 1.19.4.2 he
736 1.19.4.2 he return (0);
737 1.19.4.2 he }
738 1.19.4.2 he
739 1.19.4.2 he /*
740 1.19.4.2 he * Configure I2O devices into the system.
741 1.19.4.2 he */
742 1.19.4.2 he static void
743 1.19.4.2 he iop_configure_devices(struct iop_softc *sc, int mask, int maskval)
744 1.19.4.2 he {
745 1.19.4.2 he struct iop_attach_args ia;
746 1.19.4.2 he struct iop_initiator *ii;
747 1.19.4.2 he const struct i2o_lct_entry *le;
748 1.19.4.2 he struct device *dv;
749 1.19.4.2 he int i, j, nent;
750 1.19.4.2 he u_int usertid;
751 1.19.4.2 he
752 1.19.4.2 he nent = sc->sc_nlctent;
753 1.19.4.2 he for (i = 0, le = sc->sc_lct->entry; i < nent; i++, le++) {
754 1.19.4.2 he sc->sc_tidmap[i].it_tid = le16toh(le->localtid) & 4095;
755 1.19.4.2 he
756 1.19.4.2 he /* Ignore the device if it's in use. */
757 1.19.4.2 he usertid = le32toh(le->usertid) & 4095;
758 1.19.4.2 he if (usertid != I2O_TID_NONE && usertid != I2O_TID_HOST)
759 1.19.4.2 he continue;
760 1.19.4.2 he
761 1.19.4.2 he ia.ia_class = le16toh(le->classid) & 4095;
762 1.19.4.2 he ia.ia_tid = sc->sc_tidmap[i].it_tid;
763 1.19.4.2 he
764 1.19.4.2 he /* Ignore uninteresting devices. */
765 1.19.4.2 he for (j = 0; j < sizeof(iop_class) / sizeof(iop_class[0]); j++)
766 1.19.4.2 he if (iop_class[j].ic_class == ia.ia_class)
767 1.19.4.2 he break;
768 1.19.4.2 he if (j < sizeof(iop_class) / sizeof(iop_class[0]) &&
769 1.19.4.2 he (iop_class[j].ic_flags & mask) != maskval)
770 1.19.4.2 he continue;
771 1.19.4.2 he
772 1.19.4.2 he /*
773 1.19.4.2 he * Try to configure the device only if it's not already
774 1.19.4.2 he * configured.
775 1.19.4.2 he */
776 1.19.4.2 he LIST_FOREACH(ii, &sc->sc_iilist, ii_list) {
777 1.19.4.2 he if (ia.ia_tid == ii->ii_tid) {
778 1.19.4.2 he sc->sc_tidmap[i].it_flags |= IT_CONFIGURED;
779 1.19.4.2 he strcpy(sc->sc_tidmap[i].it_dvname,
780 1.19.4.2 he ii->ii_dv->dv_xname);
781 1.19.4.2 he break;
782 1.19.4.2 he }
783 1.19.4.2 he }
784 1.19.4.2 he if (ii != NULL)
785 1.19.4.2 he continue;
786 1.19.4.2 he
787 1.19.4.2 he dv = config_found_sm(&sc->sc_dv, &ia, iop_print, iop_submatch);
788 1.19.4.2 he if (dv != NULL) {
789 1.19.4.2 he sc->sc_tidmap[i].it_flags |= IT_CONFIGURED;
790 1.19.4.2 he strcpy(sc->sc_tidmap[i].it_dvname, dv->dv_xname);
791 1.19.4.2 he }
792 1.19.4.2 he }
793 1.19.4.2 he }
794 1.19.4.2 he
795 1.19.4.2 he /*
796 1.19.4.2 he * Adjust queue parameters for all child devices.
797 1.19.4.2 he */
798 1.19.4.2 he static void
799 1.19.4.2 he iop_adjqparam(struct iop_softc *sc, int mpi)
800 1.19.4.2 he {
801 1.19.4.2 he struct iop_initiator *ii;
802 1.19.4.2 he
803 1.19.4.2 he LIST_FOREACH(ii, &sc->sc_iilist, ii_list)
804 1.19.4.2 he if (ii->ii_adjqparam != NULL)
805 1.19.4.2 he (*ii->ii_adjqparam)(ii->ii_dv, mpi);
806 1.19.4.2 he }
807 1.19.4.2 he
808 1.19.4.2 he static void
809 1.19.4.2 he iop_devinfo(int class, char *devinfo)
810 1.19.4.2 he {
811 1.19.4.2 he #ifdef I2OVERBOSE
812 1.19.4.2 he int i;
813 1.19.4.2 he
814 1.19.4.2 he for (i = 0; i < sizeof(iop_class) / sizeof(iop_class[0]); i++)
815 1.19.4.2 he if (class == iop_class[i].ic_class)
816 1.19.4.2 he break;
817 1.19.4.2 he
818 1.19.4.2 he if (i == sizeof(iop_class) / sizeof(iop_class[0]))
819 1.19.4.2 he sprintf(devinfo, "device (class 0x%x)", class);
820 1.19.4.2 he else
821 1.19.4.2 he strcpy(devinfo, iop_class[i].ic_caption);
822 1.19.4.2 he #else
823 1.19.4.2 he
824 1.19.4.2 he sprintf(devinfo, "device (class 0x%x)", class);
825 1.19.4.2 he #endif
826 1.19.4.2 he }
827 1.19.4.2 he
828 1.19.4.2 he static int
829 1.19.4.2 he iop_print(void *aux, const char *pnp)
830 1.19.4.2 he {
831 1.19.4.2 he struct iop_attach_args *ia;
832 1.19.4.2 he char devinfo[256];
833 1.19.4.2 he
834 1.19.4.2 he ia = aux;
835 1.19.4.2 he
836 1.19.4.2 he if (pnp != NULL) {
837 1.19.4.2 he iop_devinfo(ia->ia_class, devinfo);
838 1.19.4.2 he printf("%s at %s", devinfo, pnp);
839 1.19.4.2 he }
840 1.19.4.2 he printf(" tid %d", ia->ia_tid);
841 1.19.4.2 he return (UNCONF);
842 1.19.4.2 he }
843 1.19.4.2 he
844 1.19.4.2 he static int
845 1.19.4.2 he iop_vendor_print(void *aux, const char *pnp)
846 1.19.4.2 he {
847 1.19.4.2 he
848 1.19.4.3 he return (QUIET);
849 1.19.4.2 he }
850 1.19.4.2 he
851 1.19.4.2 he static int
852 1.19.4.2 he iop_submatch(struct device *parent, struct cfdata *cf, void *aux)
853 1.19.4.2 he {
854 1.19.4.2 he struct iop_attach_args *ia;
855 1.19.4.2 he
856 1.19.4.2 he ia = aux;
857 1.19.4.2 he
858 1.19.4.2 he if (cf->iopcf_tid != IOPCF_TID_DEFAULT && cf->iopcf_tid != ia->ia_tid)
859 1.19.4.2 he return (0);
860 1.19.4.2 he
861 1.19.4.2 he return ((*cf->cf_attach->ca_match)(parent, cf, aux));
862 1.19.4.2 he }
863 1.19.4.2 he
864 1.19.4.2 he /*
865 1.19.4.2 he * Shut down all configured IOPs.
866 1.19.4.2 he */
867 1.19.4.2 he static void
868 1.19.4.2 he iop_shutdown(void *junk)
869 1.19.4.2 he {
870 1.19.4.2 he struct iop_softc *sc;
871 1.19.4.2 he int i;
872 1.19.4.2 he
873 1.19.4.2 he printf("shutting down iop devices...");
874 1.19.4.2 he
875 1.19.4.2 he for (i = 0; i < iop_cd.cd_ndevs; i++) {
876 1.19.4.2 he if ((sc = device_lookup(&iop_cd, i)) == NULL)
877 1.19.4.2 he continue;
878 1.19.4.2 he if ((sc->sc_flags & IOP_ONLINE) == 0)
879 1.19.4.2 he continue;
880 1.19.4.2 he iop_simple_cmd(sc, I2O_TID_IOP, I2O_EXEC_SYS_QUIESCE, IOP_ICTX,
881 1.19.4.2 he 0, 5000);
882 1.19.4.2 he iop_simple_cmd(sc, I2O_TID_IOP, I2O_EXEC_IOP_CLEAR, IOP_ICTX,
883 1.19.4.2 he 0, 1000);
884 1.19.4.2 he }
885 1.19.4.2 he
886 1.19.4.2 he /* Wait. Some boards could still be flushing, stupidly enough. */
887 1.19.4.2 he delay(5000*1000);
888 1.19.4.3 he printf(" done\n");
889 1.19.4.2 he }
890 1.19.4.2 he
891 1.19.4.2 he /*
892 1.19.4.2 he * Retrieve IOP status.
893 1.19.4.2 he */
894 1.19.4.3 he int
895 1.19.4.2 he iop_status_get(struct iop_softc *sc, int nosleep)
896 1.19.4.2 he {
897 1.19.4.2 he struct i2o_exec_status_get mf;
898 1.19.4.2 he struct i2o_status *st;
899 1.19.4.2 he paddr_t pa;
900 1.19.4.2 he int rv, i;
901 1.19.4.2 he
902 1.19.4.2 he pa = sc->sc_scr_seg->ds_addr;
903 1.19.4.2 he st = (struct i2o_status *)sc->sc_scr;
904 1.19.4.2 he
905 1.19.4.2 he mf.msgflags = I2O_MSGFLAGS(i2o_exec_status_get);
906 1.19.4.2 he mf.msgfunc = I2O_MSGFUNC(I2O_TID_IOP, I2O_EXEC_STATUS_GET);
907 1.19.4.2 he mf.reserved[0] = 0;
908 1.19.4.2 he mf.reserved[1] = 0;
909 1.19.4.2 he mf.reserved[2] = 0;
910 1.19.4.2 he mf.reserved[3] = 0;
911 1.19.4.2 he mf.addrlow = (u_int32_t)pa;
912 1.19.4.2 he mf.addrhigh = (u_int32_t)((u_int64_t)pa >> 32);
913 1.19.4.2 he mf.length = sizeof(sc->sc_status);
914 1.19.4.2 he
915 1.19.4.2 he memset(st, 0, sizeof(*st));
916 1.19.4.2 he bus_dmamap_sync(sc->sc_dmat, sc->sc_scr_dmamap, 0, sizeof(*st),
917 1.19.4.2 he BUS_DMASYNC_PREREAD);
918 1.19.4.2 he
919 1.19.4.2 he if ((rv = iop_post(sc, (u_int32_t *)&mf)) != 0)
920 1.19.4.2 he return (rv);
921 1.19.4.2 he
922 1.19.4.2 he for (i = 25; i != 0; i--) {
923 1.19.4.2 he bus_dmamap_sync(sc->sc_dmat, sc->sc_scr_dmamap, 0,
924 1.19.4.2 he sizeof(*st), BUS_DMASYNC_POSTREAD);
925 1.19.4.2 he if (st->syncbyte == 0xff)
926 1.19.4.2 he break;
927 1.19.4.2 he if (nosleep)
928 1.19.4.2 he DELAY(100*1000);
929 1.19.4.2 he else
930 1.19.4.2 he tsleep(iop_status_get, PWAIT, "iopstat", hz / 10);
931 1.19.4.2 he }
932 1.19.4.2 he
933 1.19.4.2 he if (st->syncbyte != 0xff)
934 1.19.4.2 he rv = EIO;
935 1.19.4.2 he else {
936 1.19.4.2 he memcpy(&sc->sc_status, st, sizeof(sc->sc_status));
937 1.19.4.2 he rv = 0;
938 1.19.4.2 he }
939 1.19.4.2 he
940 1.19.4.2 he return (rv);
941 1.19.4.2 he }
942 1.19.4.2 he
943 1.19.4.2 he /*
944 1.19.4.3 he * Initialize and populate the IOP's outbound FIFO.
945 1.19.4.2 he */
946 1.19.4.2 he static int
947 1.19.4.2 he iop_ofifo_init(struct iop_softc *sc)
948 1.19.4.2 he {
949 1.19.4.2 he bus_addr_t addr;
950 1.19.4.2 he bus_dma_segment_t seg;
951 1.19.4.2 he struct i2o_exec_outbound_init *mf;
952 1.19.4.2 he int i, rseg, rv;
953 1.19.4.2 he u_int32_t mb[IOP_MAX_MSG_SIZE / sizeof(u_int32_t)], *sw;
954 1.19.4.2 he
955 1.19.4.2 he sw = (u_int32_t *)sc->sc_scr;
956 1.19.4.2 he
957 1.19.4.2 he mf = (struct i2o_exec_outbound_init *)mb;
958 1.19.4.2 he mf->msgflags = I2O_MSGFLAGS(i2o_exec_outbound_init);
959 1.19.4.2 he mf->msgfunc = I2O_MSGFUNC(I2O_TID_IOP, I2O_EXEC_OUTBOUND_INIT);
960 1.19.4.2 he mf->msgictx = IOP_ICTX;
961 1.19.4.2 he mf->msgtctx = 0;
962 1.19.4.2 he mf->pagesize = NBPG;
963 1.19.4.2 he mf->flags = IOP_INIT_CODE | ((IOP_MAX_MSG_SIZE >> 2) << 16);
964 1.19.4.2 he
965 1.19.4.2 he /*
966 1.19.4.2 he * The I2O spec says that there are two SGLs: one for the status
967 1.19.4.2 he * word, and one for a list of discarded MFAs. It continues to say
968 1.19.4.2 he * that if you don't want to get the list of MFAs, an IGNORE SGL is
969 1.19.4.2 he * necessary; this isn't the case (and is in fact a bad thing).
970 1.19.4.2 he */
971 1.19.4.2 he mb[sizeof(*mf) / sizeof(u_int32_t) + 0] = sizeof(*sw) |
972 1.19.4.2 he I2O_SGL_SIMPLE | I2O_SGL_END_BUFFER | I2O_SGL_END;
973 1.19.4.2 he mb[sizeof(*mf) / sizeof(u_int32_t) + 1] =
974 1.19.4.2 he (u_int32_t)sc->sc_scr_seg->ds_addr;
975 1.19.4.2 he mb[0] += 2 << 16;
976 1.19.4.2 he
977 1.19.4.2 he *sw = 0;
978 1.19.4.2 he bus_dmamap_sync(sc->sc_dmat, sc->sc_scr_dmamap, 0, sizeof(*sw),
979 1.19.4.2 he BUS_DMASYNC_PREREAD);
980 1.19.4.2 he
981 1.19.4.2 he if ((rv = iop_post(sc, mb)) != 0)
982 1.19.4.2 he return (rv);
983 1.19.4.2 he
984 1.19.4.2 he POLL(5000,
985 1.19.4.2 he (bus_dmamap_sync(sc->sc_dmat, sc->sc_scr_dmamap, 0, sizeof(*sw),
986 1.19.4.2 he BUS_DMASYNC_POSTREAD),
987 1.19.4.2 he *sw == htole32(I2O_EXEC_OUTBOUND_INIT_COMPLETE)));
988 1.19.4.2 he
989 1.19.4.2 he if (*sw != htole32(I2O_EXEC_OUTBOUND_INIT_COMPLETE)) {
990 1.19.4.2 he printf("%s: outbound FIFO init failed (%d)\n",
991 1.19.4.2 he sc->sc_dv.dv_xname, le32toh(*sw));
992 1.19.4.2 he return (EIO);
993 1.19.4.2 he }
994 1.19.4.2 he
995 1.19.4.2 he /* Allocate DMA safe memory for the reply frames. */
996 1.19.4.2 he if (sc->sc_rep_phys == 0) {
997 1.19.4.2 he sc->sc_rep_size = sc->sc_maxob * IOP_MAX_MSG_SIZE;
998 1.19.4.2 he
999 1.19.4.2 he rv = bus_dmamem_alloc(sc->sc_dmat, sc->sc_rep_size, NBPG,
1000 1.19.4.2 he 0, &seg, 1, &rseg, BUS_DMA_NOWAIT);
1001 1.19.4.2 he if (rv != 0) {
1002 1.19.4.2 he printf("%s: dma alloc = %d\n", sc->sc_dv.dv_xname,
1003 1.19.4.2 he rv);
1004 1.19.4.2 he return (rv);
1005 1.19.4.2 he }
1006 1.19.4.2 he
1007 1.19.4.2 he rv = bus_dmamem_map(sc->sc_dmat, &seg, rseg, sc->sc_rep_size,
1008 1.19.4.2 he &sc->sc_rep, BUS_DMA_NOWAIT | BUS_DMA_COHERENT);
1009 1.19.4.2 he if (rv != 0) {
1010 1.19.4.2 he printf("%s: dma map = %d\n", sc->sc_dv.dv_xname, rv);
1011 1.19.4.2 he return (rv);
1012 1.19.4.2 he }
1013 1.19.4.2 he
1014 1.19.4.2 he rv = bus_dmamap_create(sc->sc_dmat, sc->sc_rep_size, 1,
1015 1.19.4.2 he sc->sc_rep_size, 0, BUS_DMA_NOWAIT, &sc->sc_rep_dmamap);
1016 1.19.4.2 he if (rv != 0) {
1017 1.19.4.2 he printf("%s: dma create = %d\n", sc->sc_dv.dv_xname,
1018 1.19.4.2 he rv);
1019 1.19.4.2 he return (rv);
1020 1.19.4.2 he }
1021 1.19.4.2 he
1022 1.19.4.2 he rv = bus_dmamap_load(sc->sc_dmat, sc->sc_rep_dmamap,
1023 1.19.4.2 he sc->sc_rep, sc->sc_rep_size, NULL, BUS_DMA_NOWAIT);
1024 1.19.4.2 he if (rv != 0) {
1025 1.19.4.2 he printf("%s: dma load = %d\n", sc->sc_dv.dv_xname, rv);
1026 1.19.4.2 he return (rv);
1027 1.19.4.2 he }
1028 1.19.4.2 he
1029 1.19.4.2 he sc->sc_rep_phys = sc->sc_rep_dmamap->dm_segs[0].ds_addr;
1030 1.19.4.2 he }
1031 1.19.4.2 he
1032 1.19.4.2 he /* Populate the outbound FIFO. */
1033 1.19.4.2 he for (i = sc->sc_maxob, addr = sc->sc_rep_phys; i != 0; i--) {
1034 1.19.4.2 he iop_outl(sc, IOP_REG_OFIFO, (u_int32_t)addr);
1035 1.19.4.2 he addr += IOP_MAX_MSG_SIZE;
1036 1.19.4.2 he }
1037 1.19.4.2 he
1038 1.19.4.2 he return (0);
1039 1.19.4.2 he }
1040 1.19.4.2 he
1041 1.19.4.2 he /*
1042 1.19.4.2 he * Read the specified number of bytes from the IOP's hardware resource table.
1043 1.19.4.2 he */
1044 1.19.4.2 he static int
1045 1.19.4.2 he iop_hrt_get0(struct iop_softc *sc, struct i2o_hrt *hrt, int size)
1046 1.19.4.2 he {
1047 1.19.4.2 he struct iop_msg *im;
1048 1.19.4.2 he int rv;
1049 1.19.4.2 he struct i2o_exec_hrt_get *mf;
1050 1.19.4.2 he u_int32_t mb[IOP_MAX_MSG_SIZE / sizeof(u_int32_t)];
1051 1.19.4.2 he
1052 1.19.4.2 he im = iop_msg_alloc(sc, IM_WAIT);
1053 1.19.4.2 he mf = (struct i2o_exec_hrt_get *)mb;
1054 1.19.4.2 he mf->msgflags = I2O_MSGFLAGS(i2o_exec_hrt_get);
1055 1.19.4.2 he mf->msgfunc = I2O_MSGFUNC(I2O_TID_IOP, I2O_EXEC_HRT_GET);
1056 1.19.4.2 he mf->msgictx = IOP_ICTX;
1057 1.19.4.2 he mf->msgtctx = im->im_tctx;
1058 1.19.4.2 he
1059 1.19.4.2 he iop_msg_map(sc, im, mb, hrt, size, 0, NULL);
1060 1.19.4.2 he rv = iop_msg_post(sc, im, mb, 30000);
1061 1.19.4.2 he iop_msg_unmap(sc, im);
1062 1.19.4.2 he iop_msg_free(sc, im);
1063 1.19.4.2 he return (rv);
1064 1.19.4.2 he }
1065 1.19.4.2 he
1066 1.19.4.2 he /*
1067 1.19.4.2 he * Read the IOP's hardware resource table.
1068 1.19.4.2 he */
1069 1.19.4.2 he static int
1070 1.19.4.2 he iop_hrt_get(struct iop_softc *sc)
1071 1.19.4.2 he {
1072 1.19.4.2 he struct i2o_hrt hrthdr, *hrt;
1073 1.19.4.2 he int size, rv;
1074 1.19.4.2 he
1075 1.19.4.2 he PHOLD(curproc);
1076 1.19.4.2 he rv = iop_hrt_get0(sc, &hrthdr, sizeof(hrthdr));
1077 1.19.4.2 he PRELE(curproc);
1078 1.19.4.2 he if (rv != 0)
1079 1.19.4.2 he return (rv);
1080 1.19.4.2 he
1081 1.19.4.2 he DPRINTF(("%s: %d hrt entries\n", sc->sc_dv.dv_xname,
1082 1.19.4.2 he le16toh(hrthdr.numentries)));
1083 1.19.4.2 he
1084 1.19.4.2 he size = sizeof(struct i2o_hrt) +
1085 1.19.4.2 he (le16toh(hrthdr.numentries) - 1) * sizeof(struct i2o_hrt_entry);
1086 1.19.4.2 he hrt = (struct i2o_hrt *)malloc(size, M_DEVBUF, M_NOWAIT);
1087 1.19.4.2 he
1088 1.19.4.2 he if ((rv = iop_hrt_get0(sc, hrt, size)) != 0) {
1089 1.19.4.2 he free(hrt, M_DEVBUF);
1090 1.19.4.2 he return (rv);
1091 1.19.4.2 he }
1092 1.19.4.2 he
1093 1.19.4.2 he if (sc->sc_hrt != NULL)
1094 1.19.4.2 he free(sc->sc_hrt, M_DEVBUF);
1095 1.19.4.2 he sc->sc_hrt = hrt;
1096 1.19.4.2 he return (0);
1097 1.19.4.2 he }
1098 1.19.4.2 he
1099 1.19.4.2 he /*
1100 1.19.4.2 he * Request the specified number of bytes from the IOP's logical
1101 1.19.4.2 he * configuration table. If a change indicator is specified, this
1102 1.19.4.2 he * is a verbatim notification request, so the caller is prepared
1103 1.19.4.2 he * to wait indefinitely.
1104 1.19.4.2 he */
1105 1.19.4.2 he static int
1106 1.19.4.2 he iop_lct_get0(struct iop_softc *sc, struct i2o_lct *lct, int size,
1107 1.19.4.2 he u_int32_t chgind)
1108 1.19.4.2 he {
1109 1.19.4.2 he struct iop_msg *im;
1110 1.19.4.2 he struct i2o_exec_lct_notify *mf;
1111 1.19.4.2 he int rv;
1112 1.19.4.2 he u_int32_t mb[IOP_MAX_MSG_SIZE / sizeof(u_int32_t)];
1113 1.19.4.2 he
1114 1.19.4.2 he im = iop_msg_alloc(sc, IM_WAIT);
1115 1.19.4.2 he memset(lct, 0, size);
1116 1.19.4.2 he
1117 1.19.4.2 he mf = (struct i2o_exec_lct_notify *)mb;
1118 1.19.4.2 he mf->msgflags = I2O_MSGFLAGS(i2o_exec_lct_notify);
1119 1.19.4.2 he mf->msgfunc = I2O_MSGFUNC(I2O_TID_IOP, I2O_EXEC_LCT_NOTIFY);
1120 1.19.4.2 he mf->msgictx = IOP_ICTX;
1121 1.19.4.2 he mf->msgtctx = im->im_tctx;
1122 1.19.4.2 he mf->classid = I2O_CLASS_ANY;
1123 1.19.4.2 he mf->changeindicator = chgind;
1124 1.19.4.2 he
1125 1.19.4.2 he #ifdef I2ODEBUG
1126 1.19.4.2 he printf("iop_lct_get0: reading LCT");
1127 1.19.4.2 he if (chgind != 0)
1128 1.19.4.2 he printf(" (async)");
1129 1.19.4.2 he printf("\n");
1130 1.19.4.2 he #endif
1131 1.19.4.2 he
1132 1.19.4.2 he iop_msg_map(sc, im, mb, lct, size, 0, NULL);
1133 1.19.4.2 he rv = iop_msg_post(sc, im, mb, (chgind == 0 ? 120*1000 : 0));
1134 1.19.4.2 he iop_msg_unmap(sc, im);
1135 1.19.4.2 he iop_msg_free(sc, im);
1136 1.19.4.2 he return (rv);
1137 1.19.4.2 he }
1138 1.19.4.2 he
1139 1.19.4.2 he /*
1140 1.19.4.2 he * Read the IOP's logical configuration table.
1141 1.19.4.2 he */
1142 1.19.4.2 he int
1143 1.19.4.2 he iop_lct_get(struct iop_softc *sc)
1144 1.19.4.2 he {
1145 1.19.4.2 he int esize, size, rv;
1146 1.19.4.2 he struct i2o_lct *lct;
1147 1.19.4.2 he
1148 1.19.4.2 he esize = le32toh(sc->sc_status.expectedlctsize);
1149 1.19.4.2 he lct = (struct i2o_lct *)malloc(esize, M_DEVBUF, M_WAITOK);
1150 1.19.4.2 he if (lct == NULL)
1151 1.19.4.2 he return (ENOMEM);
1152 1.19.4.2 he
1153 1.19.4.2 he if ((rv = iop_lct_get0(sc, lct, esize, 0)) != 0) {
1154 1.19.4.2 he free(lct, M_DEVBUF);
1155 1.19.4.2 he return (rv);
1156 1.19.4.2 he }
1157 1.19.4.2 he
1158 1.19.4.2 he size = le16toh(lct->tablesize) << 2;
1159 1.19.4.2 he if (esize != size) {
1160 1.19.4.2 he free(lct, M_DEVBUF);
1161 1.19.4.2 he lct = (struct i2o_lct *)malloc(size, M_DEVBUF, M_WAITOK);
1162 1.19.4.2 he if (lct == NULL)
1163 1.19.4.2 he return (ENOMEM);
1164 1.19.4.2 he
1165 1.19.4.2 he if ((rv = iop_lct_get0(sc, lct, size, 0)) != 0) {
1166 1.19.4.2 he free(lct, M_DEVBUF);
1167 1.19.4.2 he return (rv);
1168 1.19.4.2 he }
1169 1.19.4.2 he }
1170 1.19.4.2 he
1171 1.19.4.2 he /* Swap in the new LCT. */
1172 1.19.4.2 he if (sc->sc_lct != NULL)
1173 1.19.4.2 he free(sc->sc_lct, M_DEVBUF);
1174 1.19.4.2 he sc->sc_lct = lct;
1175 1.19.4.2 he sc->sc_nlctent = ((le16toh(sc->sc_lct->tablesize) << 2) -
1176 1.19.4.2 he sizeof(struct i2o_lct) + sizeof(struct i2o_lct_entry)) /
1177 1.19.4.2 he sizeof(struct i2o_lct_entry);
1178 1.19.4.2 he return (0);
1179 1.19.4.2 he }
1180 1.19.4.2 he
1181 1.19.4.2 he /*
1182 1.19.4.2 he * Request the specified parameter group from the target. If an initiator
1183 1.19.4.2 he * is specified (a) don't wait for the operation to complete, but instead
1184 1.19.4.2 he * let the initiator's interrupt handler deal with the reply and (b) place a
1185 1.19.4.2 he * pointer to the parameter group op in the wrapper's `im_dvcontext' field.
1186 1.19.4.2 he */
1187 1.19.4.2 he int
1188 1.19.4.2 he iop_field_get_all(struct iop_softc *sc, int tid, int group, void *buf,
1189 1.19.4.2 he int size, struct iop_initiator *ii)
1190 1.19.4.2 he {
1191 1.19.4.2 he struct iop_msg *im;
1192 1.19.4.2 he struct i2o_util_params_op *mf;
1193 1.19.4.2 he struct i2o_reply *rf;
1194 1.19.4.2 he int rv;
1195 1.19.4.2 he struct iop_pgop *pgop;
1196 1.19.4.2 he u_int32_t mb[IOP_MAX_MSG_SIZE / sizeof(u_int32_t)];
1197 1.19.4.2 he
1198 1.19.4.2 he im = iop_msg_alloc(sc, (ii == NULL ? IM_WAIT : 0) | IM_NOSTATUS);
1199 1.19.4.2 he if ((pgop = malloc(sizeof(*pgop), M_DEVBUF, M_WAITOK)) == NULL) {
1200 1.19.4.2 he iop_msg_free(sc, im);
1201 1.19.4.2 he return (ENOMEM);
1202 1.19.4.2 he }
1203 1.19.4.2 he if ((rf = malloc(sizeof(*rf), M_DEVBUF, M_WAITOK)) == NULL) {
1204 1.19.4.2 he iop_msg_free(sc, im);
1205 1.19.4.2 he free(pgop, M_DEVBUF);
1206 1.19.4.2 he return (ENOMEM);
1207 1.19.4.2 he }
1208 1.19.4.2 he im->im_dvcontext = pgop;
1209 1.19.4.2 he im->im_rb = rf;
1210 1.19.4.2 he
1211 1.19.4.2 he mf = (struct i2o_util_params_op *)mb;
1212 1.19.4.2 he mf->msgflags = I2O_MSGFLAGS(i2o_util_params_op);
1213 1.19.4.2 he mf->msgfunc = I2O_MSGFUNC(tid, I2O_UTIL_PARAMS_GET);
1214 1.19.4.2 he mf->msgictx = IOP_ICTX;
1215 1.19.4.2 he mf->msgtctx = im->im_tctx;
1216 1.19.4.2 he mf->flags = 0;
1217 1.19.4.2 he
1218 1.19.4.2 he pgop->olh.count = htole16(1);
1219 1.19.4.2 he pgop->olh.reserved = htole16(0);
1220 1.19.4.2 he pgop->oat.operation = htole16(I2O_PARAMS_OP_FIELD_GET);
1221 1.19.4.2 he pgop->oat.fieldcount = htole16(0xffff);
1222 1.19.4.2 he pgop->oat.group = htole16(group);
1223 1.19.4.2 he
1224 1.19.4.2 he if (ii == NULL)
1225 1.19.4.2 he PHOLD(curproc);
1226 1.19.4.2 he
1227 1.19.4.2 he memset(buf, 0, size);
1228 1.19.4.2 he iop_msg_map(sc, im, mb, pgop, sizeof(*pgop), 1, NULL);
1229 1.19.4.2 he iop_msg_map(sc, im, mb, buf, size, 0, NULL);
1230 1.19.4.2 he rv = iop_msg_post(sc, im, mb, (ii == NULL ? 30000 : 0));
1231 1.19.4.2 he
1232 1.19.4.2 he if (ii == NULL)
1233 1.19.4.2 he PRELE(curproc);
1234 1.19.4.2 he
1235 1.19.4.2 he /* Detect errors; let partial transfers to count as success. */
1236 1.19.4.2 he if (ii == NULL && rv == 0) {
1237 1.19.4.2 he if (rf->reqstatus == I2O_STATUS_ERROR_PARTIAL_XFER &&
1238 1.19.4.2 he le16toh(rf->detail) == I2O_DSC_UNKNOWN_ERROR)
1239 1.19.4.2 he rv = 0;
1240 1.19.4.2 he else
1241 1.19.4.2 he rv = (rf->reqstatus != 0 ? EIO : 0);
1242 1.19.4.2 he
1243 1.19.4.2 he if (rv != 0)
1244 1.19.4.2 he printf("%s: FIELD_GET failed for tid %d group %d\n",
1245 1.19.4.2 he sc->sc_dv.dv_xname, tid, group);
1246 1.19.4.2 he }
1247 1.19.4.2 he
1248 1.19.4.2 he if (ii == NULL || rv != 0) {
1249 1.19.4.2 he iop_msg_unmap(sc, im);
1250 1.19.4.2 he iop_msg_free(sc, im);
1251 1.19.4.2 he free(pgop, M_DEVBUF);
1252 1.19.4.2 he free(rf, M_DEVBUF);
1253 1.19.4.2 he }
1254 1.19.4.2 he
1255 1.19.4.2 he return (rv);
1256 1.19.4.2 he }
1257 1.19.4.2 he
1258 1.19.4.2 he /*
1259 1.19.4.2 he * Set a single field in a scalar parameter group.
1260 1.19.4.2 he */
1261 1.19.4.2 he int
1262 1.19.4.2 he iop_field_set(struct iop_softc *sc, int tid, int group, void *buf,
1263 1.19.4.2 he int size, int field)
1264 1.19.4.2 he {
1265 1.19.4.2 he struct iop_msg *im;
1266 1.19.4.2 he struct i2o_util_params_op *mf;
1267 1.19.4.2 he struct iop_pgop *pgop;
1268 1.19.4.2 he int rv, totsize;
1269 1.19.4.2 he u_int32_t mb[IOP_MAX_MSG_SIZE / sizeof(u_int32_t)];
1270 1.19.4.2 he
1271 1.19.4.2 he totsize = sizeof(*pgop) + size;
1272 1.19.4.2 he
1273 1.19.4.2 he im = iop_msg_alloc(sc, IM_WAIT);
1274 1.19.4.2 he if ((pgop = malloc(totsize, M_DEVBUF, M_WAITOK)) == NULL) {
1275 1.19.4.2 he iop_msg_free(sc, im);
1276 1.19.4.2 he return (ENOMEM);
1277 1.19.4.2 he }
1278 1.19.4.2 he
1279 1.19.4.2 he mf = (struct i2o_util_params_op *)mb;
1280 1.19.4.2 he mf->msgflags = I2O_MSGFLAGS(i2o_util_params_op);
1281 1.19.4.2 he mf->msgfunc = I2O_MSGFUNC(tid, I2O_UTIL_PARAMS_SET);
1282 1.19.4.2 he mf->msgictx = IOP_ICTX;
1283 1.19.4.2 he mf->msgtctx = im->im_tctx;
1284 1.19.4.2 he mf->flags = 0;
1285 1.19.4.2 he
1286 1.19.4.2 he pgop->olh.count = htole16(1);
1287 1.19.4.2 he pgop->olh.reserved = htole16(0);
1288 1.19.4.2 he pgop->oat.operation = htole16(I2O_PARAMS_OP_FIELD_SET);
1289 1.19.4.2 he pgop->oat.fieldcount = htole16(1);
1290 1.19.4.2 he pgop->oat.group = htole16(group);
1291 1.19.4.2 he pgop->oat.fields[0] = htole16(field);
1292 1.19.4.2 he memcpy(pgop + 1, buf, size);
1293 1.19.4.2 he
1294 1.19.4.2 he iop_msg_map(sc, im, mb, pgop, totsize, 1, NULL);
1295 1.19.4.2 he rv = iop_msg_post(sc, im, mb, 30000);
1296 1.19.4.2 he if (rv != 0)
1297 1.19.4.2 he printf("%s: FIELD_SET failed for tid %d group %d\n",
1298 1.19.4.2 he sc->sc_dv.dv_xname, tid, group);
1299 1.19.4.2 he
1300 1.19.4.2 he iop_msg_unmap(sc, im);
1301 1.19.4.2 he iop_msg_free(sc, im);
1302 1.19.4.2 he free(pgop, M_DEVBUF);
1303 1.19.4.2 he return (rv);
1304 1.19.4.2 he }
1305 1.19.4.2 he
1306 1.19.4.2 he /*
1307 1.19.4.2 he * Delete all rows in a tablular parameter group.
1308 1.19.4.2 he */
1309 1.19.4.2 he int
1310 1.19.4.2 he iop_table_clear(struct iop_softc *sc, int tid, int group)
1311 1.19.4.2 he {
1312 1.19.4.2 he struct iop_msg *im;
1313 1.19.4.2 he struct i2o_util_params_op *mf;
1314 1.19.4.2 he struct iop_pgop pgop;
1315 1.19.4.2 he u_int32_t mb[IOP_MAX_MSG_SIZE / sizeof(u_int32_t)];
1316 1.19.4.2 he int rv;
1317 1.19.4.2 he
1318 1.19.4.2 he im = iop_msg_alloc(sc, IM_WAIT);
1319 1.19.4.2 he
1320 1.19.4.2 he mf = (struct i2o_util_params_op *)mb;
1321 1.19.4.2 he mf->msgflags = I2O_MSGFLAGS(i2o_util_params_op);
1322 1.19.4.2 he mf->msgfunc = I2O_MSGFUNC(tid, I2O_UTIL_PARAMS_SET);
1323 1.19.4.2 he mf->msgictx = IOP_ICTX;
1324 1.19.4.2 he mf->msgtctx = im->im_tctx;
1325 1.19.4.2 he mf->flags = 0;
1326 1.19.4.2 he
1327 1.19.4.2 he pgop.olh.count = htole16(1);
1328 1.19.4.2 he pgop.olh.reserved = htole16(0);
1329 1.19.4.2 he pgop.oat.operation = htole16(I2O_PARAMS_OP_TABLE_CLEAR);
1330 1.19.4.2 he pgop.oat.fieldcount = htole16(0);
1331 1.19.4.2 he pgop.oat.group = htole16(group);
1332 1.19.4.2 he pgop.oat.fields[0] = htole16(0);
1333 1.19.4.2 he
1334 1.19.4.2 he PHOLD(curproc);
1335 1.19.4.2 he iop_msg_map(sc, im, mb, &pgop, sizeof(pgop), 1, NULL);
1336 1.19.4.2 he rv = iop_msg_post(sc, im, mb, 30000);
1337 1.19.4.2 he if (rv != 0)
1338 1.19.4.2 he printf("%s: TABLE_CLEAR failed for tid %d group %d\n",
1339 1.19.4.2 he sc->sc_dv.dv_xname, tid, group);
1340 1.19.4.2 he
1341 1.19.4.2 he iop_msg_unmap(sc, im);
1342 1.19.4.2 he PRELE(curproc);
1343 1.19.4.2 he iop_msg_free(sc, im);
1344 1.19.4.2 he return (rv);
1345 1.19.4.2 he }
1346 1.19.4.2 he
1347 1.19.4.2 he /*
1348 1.19.4.2 he * Add a single row to a tabular parameter group. The row can have only one
1349 1.19.4.2 he * field.
1350 1.19.4.2 he */
1351 1.19.4.2 he int
1352 1.19.4.2 he iop_table_add_row(struct iop_softc *sc, int tid, int group, void *buf,
1353 1.19.4.2 he int size, int row)
1354 1.19.4.2 he {
1355 1.19.4.2 he struct iop_msg *im;
1356 1.19.4.2 he struct i2o_util_params_op *mf;
1357 1.19.4.2 he struct iop_pgop *pgop;
1358 1.19.4.2 he int rv, totsize;
1359 1.19.4.2 he u_int32_t mb[IOP_MAX_MSG_SIZE / sizeof(u_int32_t)];
1360 1.19.4.2 he
1361 1.19.4.2 he totsize = sizeof(*pgop) + sizeof(u_int16_t) * 2 + size;
1362 1.19.4.2 he
1363 1.19.4.2 he im = iop_msg_alloc(sc, IM_WAIT);
1364 1.19.4.2 he if ((pgop = malloc(totsize, M_DEVBUF, M_WAITOK)) == NULL) {
1365 1.19.4.2 he iop_msg_free(sc, im);
1366 1.19.4.2 he return (ENOMEM);
1367 1.19.4.2 he }
1368 1.19.4.2 he
1369 1.19.4.2 he mf = (struct i2o_util_params_op *)mb;
1370 1.19.4.2 he mf->msgflags = I2O_MSGFLAGS(i2o_util_params_op);
1371 1.19.4.2 he mf->msgfunc = I2O_MSGFUNC(tid, I2O_UTIL_PARAMS_SET);
1372 1.19.4.2 he mf->msgictx = IOP_ICTX;
1373 1.19.4.2 he mf->msgtctx = im->im_tctx;
1374 1.19.4.2 he mf->flags = 0;
1375 1.19.4.2 he
1376 1.19.4.2 he pgop->olh.count = htole16(1);
1377 1.19.4.2 he pgop->olh.reserved = htole16(0);
1378 1.19.4.2 he pgop->oat.operation = htole16(I2O_PARAMS_OP_ROW_ADD);
1379 1.19.4.2 he pgop->oat.fieldcount = htole16(1);
1380 1.19.4.2 he pgop->oat.group = htole16(group);
1381 1.19.4.2 he pgop->oat.fields[0] = htole16(0); /* FieldIdx */
1382 1.19.4.2 he pgop->oat.fields[1] = htole16(1); /* RowCount */
1383 1.19.4.2 he pgop->oat.fields[2] = htole16(row); /* KeyValue */
1384 1.19.4.2 he memcpy(&pgop->oat.fields[3], buf, size);
1385 1.19.4.2 he
1386 1.19.4.2 he iop_msg_map(sc, im, mb, pgop, totsize, 1, NULL);
1387 1.19.4.2 he rv = iop_msg_post(sc, im, mb, 30000);
1388 1.19.4.2 he if (rv != 0)
1389 1.19.4.2 he printf("%s: ADD_ROW failed for tid %d group %d row %d\n",
1390 1.19.4.2 he sc->sc_dv.dv_xname, tid, group, row);
1391 1.19.4.2 he
1392 1.19.4.2 he iop_msg_unmap(sc, im);
1393 1.19.4.2 he iop_msg_free(sc, im);
1394 1.19.4.2 he free(pgop, M_DEVBUF);
1395 1.19.4.2 he return (rv);
1396 1.19.4.2 he }
1397 1.19.4.2 he
1398 1.19.4.2 he /*
1399 1.19.4.2 he * Execute a simple command (no parameters).
1400 1.19.4.2 he */
1401 1.19.4.2 he int
1402 1.19.4.2 he iop_simple_cmd(struct iop_softc *sc, int tid, int function, int ictx,
1403 1.19.4.2 he int async, int timo)
1404 1.19.4.2 he {
1405 1.19.4.2 he struct iop_msg *im;
1406 1.19.4.2 he struct i2o_msg mf;
1407 1.19.4.2 he int rv, fl;
1408 1.19.4.2 he
1409 1.19.4.2 he fl = (async != 0 ? IM_WAIT : IM_POLL);
1410 1.19.4.2 he im = iop_msg_alloc(sc, fl);
1411 1.19.4.2 he
1412 1.19.4.2 he mf.msgflags = I2O_MSGFLAGS(i2o_msg);
1413 1.19.4.2 he mf.msgfunc = I2O_MSGFUNC(tid, function);
1414 1.19.4.2 he mf.msgictx = ictx;
1415 1.19.4.2 he mf.msgtctx = im->im_tctx;
1416 1.19.4.2 he
1417 1.19.4.2 he rv = iop_msg_post(sc, im, &mf, timo);
1418 1.19.4.2 he iop_msg_free(sc, im);
1419 1.19.4.2 he return (rv);
1420 1.19.4.2 he }
1421 1.19.4.2 he
1422 1.19.4.2 he /*
1423 1.19.4.2 he * Post the system table to the IOP.
1424 1.19.4.2 he */
1425 1.19.4.2 he static int
1426 1.19.4.2 he iop_systab_set(struct iop_softc *sc)
1427 1.19.4.2 he {
1428 1.19.4.2 he struct i2o_exec_sys_tab_set *mf;
1429 1.19.4.2 he struct iop_msg *im;
1430 1.19.4.2 he bus_space_handle_t bsh;
1431 1.19.4.2 he bus_addr_t boo;
1432 1.19.4.2 he u_int32_t mema[2], ioa[2];
1433 1.19.4.2 he int rv;
1434 1.19.4.2 he u_int32_t mb[IOP_MAX_MSG_SIZE / sizeof(u_int32_t)];
1435 1.19.4.2 he
1436 1.19.4.2 he im = iop_msg_alloc(sc, IM_WAIT);
1437 1.19.4.2 he
1438 1.19.4.2 he mf = (struct i2o_exec_sys_tab_set *)mb;
1439 1.19.4.2 he mf->msgflags = I2O_MSGFLAGS(i2o_exec_sys_tab_set);
1440 1.19.4.2 he mf->msgfunc = I2O_MSGFUNC(I2O_TID_IOP, I2O_EXEC_SYS_TAB_SET);
1441 1.19.4.2 he mf->msgictx = IOP_ICTX;
1442 1.19.4.2 he mf->msgtctx = im->im_tctx;
1443 1.19.4.2 he mf->iopid = (sc->sc_dv.dv_unit + 2) << 12;
1444 1.19.4.2 he mf->segnumber = 0;
1445 1.19.4.2 he
1446 1.19.4.2 he mema[1] = sc->sc_status.desiredprivmemsize;
1447 1.19.4.2 he ioa[1] = sc->sc_status.desiredpriviosize;
1448 1.19.4.2 he
1449 1.19.4.2 he if (mema[1] != 0) {
1450 1.19.4.2 he rv = bus_space_alloc(sc->sc_bus_memt, 0, 0xffffffff,
1451 1.19.4.2 he le32toh(mema[1]), NBPG, 0, 0, &boo, &bsh);
1452 1.19.4.2 he mema[0] = htole32(boo);
1453 1.19.4.2 he if (rv != 0) {
1454 1.19.4.2 he printf("%s: can't alloc priv mem space, err = %d\n",
1455 1.19.4.2 he sc->sc_dv.dv_xname, rv);
1456 1.19.4.2 he mema[0] = 0;
1457 1.19.4.2 he mema[1] = 0;
1458 1.19.4.2 he }
1459 1.19.4.2 he }
1460 1.19.4.2 he
1461 1.19.4.2 he if (ioa[1] != 0) {
1462 1.19.4.2 he rv = bus_space_alloc(sc->sc_bus_iot, 0, 0xffff,
1463 1.19.4.2 he le32toh(ioa[1]), 0, 0, 0, &boo, &bsh);
1464 1.19.4.2 he ioa[0] = htole32(boo);
1465 1.19.4.2 he if (rv != 0) {
1466 1.19.4.2 he printf("%s: can't alloc priv i/o space, err = %d\n",
1467 1.19.4.2 he sc->sc_dv.dv_xname, rv);
1468 1.19.4.2 he ioa[0] = 0;
1469 1.19.4.2 he ioa[1] = 0;
1470 1.19.4.2 he }
1471 1.19.4.2 he }
1472 1.19.4.2 he
1473 1.19.4.2 he PHOLD(curproc);
1474 1.19.4.2 he iop_msg_map(sc, im, mb, iop_systab, iop_systab_size, 1, NULL);
1475 1.19.4.2 he iop_msg_map(sc, im, mb, mema, sizeof(mema), 1, NULL);
1476 1.19.4.2 he iop_msg_map(sc, im, mb, ioa, sizeof(ioa), 1, NULL);
1477 1.19.4.2 he rv = iop_msg_post(sc, im, mb, 5000);
1478 1.19.4.2 he iop_msg_unmap(sc, im);
1479 1.19.4.2 he iop_msg_free(sc, im);
1480 1.19.4.2 he PRELE(curproc);
1481 1.19.4.2 he return (rv);
1482 1.19.4.2 he }
1483 1.19.4.2 he
1484 1.19.4.2 he /*
1485 1.19.4.2 he * Reset the IOP. Must be called with interrupts disabled.
1486 1.19.4.2 he */
1487 1.19.4.2 he static int
1488 1.19.4.2 he iop_reset(struct iop_softc *sc)
1489 1.19.4.2 he {
1490 1.19.4.2 he u_int32_t mfa, *sw;
1491 1.19.4.2 he struct i2o_exec_iop_reset mf;
1492 1.19.4.2 he int rv;
1493 1.19.4.2 he paddr_t pa;
1494 1.19.4.2 he
1495 1.19.4.2 he sw = (u_int32_t *)sc->sc_scr;
1496 1.19.4.2 he pa = sc->sc_scr_seg->ds_addr;
1497 1.19.4.2 he
1498 1.19.4.2 he mf.msgflags = I2O_MSGFLAGS(i2o_exec_iop_reset);
1499 1.19.4.2 he mf.msgfunc = I2O_MSGFUNC(I2O_TID_IOP, I2O_EXEC_IOP_RESET);
1500 1.19.4.2 he mf.reserved[0] = 0;
1501 1.19.4.2 he mf.reserved[1] = 0;
1502 1.19.4.2 he mf.reserved[2] = 0;
1503 1.19.4.2 he mf.reserved[3] = 0;
1504 1.19.4.2 he mf.statuslow = (u_int32_t)pa;
1505 1.19.4.2 he mf.statushigh = (u_int32_t)((u_int64_t)pa >> 32);
1506 1.19.4.2 he
1507 1.19.4.2 he *sw = htole32(0);
1508 1.19.4.2 he bus_dmamap_sync(sc->sc_dmat, sc->sc_scr_dmamap, 0, sizeof(*sw),
1509 1.19.4.2 he BUS_DMASYNC_PREREAD);
1510 1.19.4.2 he
1511 1.19.4.2 he if ((rv = iop_post(sc, (u_int32_t *)&mf)))
1512 1.19.4.2 he return (rv);
1513 1.19.4.2 he
1514 1.19.4.2 he POLL(2500,
1515 1.19.4.2 he (bus_dmamap_sync(sc->sc_dmat, sc->sc_scr_dmamap, 0, sizeof(*sw),
1516 1.19.4.2 he BUS_DMASYNC_POSTREAD), *sw != 0));
1517 1.19.4.2 he if (*sw != htole32(I2O_RESET_IN_PROGRESS)) {
1518 1.19.4.2 he printf("%s: reset rejected, status 0x%x\n",
1519 1.19.4.2 he sc->sc_dv.dv_xname, le32toh(*sw));
1520 1.19.4.2 he return (EIO);
1521 1.19.4.2 he }
1522 1.19.4.2 he
1523 1.19.4.2 he /*
1524 1.19.4.2 he * IOP is now in the INIT state. Wait no more than 10 seconds for
1525 1.19.4.2 he * the inbound queue to become responsive.
1526 1.19.4.2 he */
1527 1.19.4.2 he POLL(10000, (mfa = iop_inl(sc, IOP_REG_IFIFO)) != IOP_MFA_EMPTY);
1528 1.19.4.2 he if (mfa == IOP_MFA_EMPTY) {
1529 1.19.4.2 he printf("%s: reset failed\n", sc->sc_dv.dv_xname);
1530 1.19.4.2 he return (EIO);
1531 1.19.4.2 he }
1532 1.19.4.2 he
1533 1.19.4.2 he iop_release_mfa(sc, mfa);
1534 1.19.4.2 he return (0);
1535 1.19.4.2 he }
1536 1.19.4.2 he
1537 1.19.4.2 he /*
1538 1.19.4.2 he * Register a new initiator. Must be called with the configuration lock
1539 1.19.4.2 he * held.
1540 1.19.4.2 he */
1541 1.19.4.2 he void
1542 1.19.4.2 he iop_initiator_register(struct iop_softc *sc, struct iop_initiator *ii)
1543 1.19.4.2 he {
1544 1.19.4.2 he static int ictxgen;
1545 1.19.4.2 he int s;
1546 1.19.4.2 he
1547 1.19.4.2 he /* 0 is reserved (by us) for system messages. */
1548 1.19.4.2 he ii->ii_ictx = ++ictxgen;
1549 1.19.4.2 he
1550 1.19.4.2 he /*
1551 1.19.4.2 he * `Utility initiators' don't make it onto the per-IOP initiator list
1552 1.19.4.2 he * (which is used only for configuration), but do get one slot on
1553 1.19.4.2 he * the inbound queue.
1554 1.19.4.2 he */
1555 1.19.4.2 he if ((ii->ii_flags & II_UTILITY) == 0) {
1556 1.19.4.2 he LIST_INSERT_HEAD(&sc->sc_iilist, ii, ii_list);
1557 1.19.4.2 he sc->sc_nii++;
1558 1.19.4.2 he } else
1559 1.19.4.2 he sc->sc_nuii++;
1560 1.19.4.2 he
1561 1.19.4.2 he s = splbio();
1562 1.19.4.2 he LIST_INSERT_HEAD(IOP_ICTXHASH(ii->ii_ictx), ii, ii_hash);
1563 1.19.4.2 he splx(s);
1564 1.19.4.2 he }
1565 1.19.4.2 he
1566 1.19.4.2 he /*
1567 1.19.4.2 he * Unregister an initiator. Must be called with the configuration lock
1568 1.19.4.2 he * held.
1569 1.19.4.2 he */
1570 1.19.4.2 he void
1571 1.19.4.2 he iop_initiator_unregister(struct iop_softc *sc, struct iop_initiator *ii)
1572 1.19.4.2 he {
1573 1.19.4.2 he int s;
1574 1.19.4.2 he
1575 1.19.4.2 he if ((ii->ii_flags & II_UTILITY) == 0) {
1576 1.19.4.2 he LIST_REMOVE(ii, ii_list);
1577 1.19.4.2 he sc->sc_nii--;
1578 1.19.4.2 he } else
1579 1.19.4.2 he sc->sc_nuii--;
1580 1.19.4.2 he
1581 1.19.4.2 he s = splbio();
1582 1.19.4.2 he LIST_REMOVE(ii, ii_hash);
1583 1.19.4.2 he splx(s);
1584 1.19.4.2 he }
1585 1.19.4.2 he
1586 1.19.4.2 he /*
1587 1.19.4.2 he * Handle a reply frame from the IOP.
1588 1.19.4.2 he */
1589 1.19.4.2 he static int
1590 1.19.4.2 he iop_handle_reply(struct iop_softc *sc, u_int32_t rmfa)
1591 1.19.4.2 he {
1592 1.19.4.2 he struct iop_msg *im;
1593 1.19.4.2 he struct i2o_reply *rb;
1594 1.19.4.2 he struct i2o_fault_notify *fn;
1595 1.19.4.2 he struct iop_initiator *ii;
1596 1.19.4.2 he u_int off, ictx, tctx, status, size;
1597 1.19.4.2 he
1598 1.19.4.2 he off = (int)(rmfa - sc->sc_rep_phys);
1599 1.19.4.2 he rb = (struct i2o_reply *)(sc->sc_rep + off);
1600 1.19.4.2 he
1601 1.19.4.2 he /* Perform reply queue DMA synchronisation. */
1602 1.19.4.2 he bus_dmamap_sync(sc->sc_dmat, sc->sc_rep_dmamap, off,
1603 1.19.4.2 he IOP_MAX_MSG_SIZE, BUS_DMASYNC_POSTREAD);
1604 1.19.4.2 he if (--sc->sc_curib != 0)
1605 1.19.4.2 he bus_dmamap_sync(sc->sc_dmat, sc->sc_rep_dmamap,
1606 1.19.4.2 he 0, sc->sc_rep_size, BUS_DMASYNC_PREREAD);
1607 1.19.4.2 he
1608 1.19.4.2 he #ifdef I2ODEBUG
1609 1.19.4.2 he if ((le32toh(rb->msgflags) & I2O_MSGFLAGS_64BIT) != 0)
1610 1.19.4.2 he panic("iop_handle_reply: 64-bit reply");
1611 1.19.4.2 he #endif
1612 1.19.4.2 he /*
1613 1.19.4.2 he * Find the initiator.
1614 1.19.4.2 he */
1615 1.19.4.2 he ictx = le32toh(rb->msgictx);
1616 1.19.4.2 he if (ictx == IOP_ICTX)
1617 1.19.4.2 he ii = NULL;
1618 1.19.4.2 he else {
1619 1.19.4.2 he ii = LIST_FIRST(IOP_ICTXHASH(ictx));
1620 1.19.4.2 he for (; ii != NULL; ii = LIST_NEXT(ii, ii_hash))
1621 1.19.4.2 he if (ii->ii_ictx == ictx)
1622 1.19.4.2 he break;
1623 1.19.4.2 he if (ii == NULL) {
1624 1.19.4.2 he #ifdef I2ODEBUG
1625 1.19.4.2 he iop_reply_print(sc, rb);
1626 1.19.4.2 he #endif
1627 1.19.4.2 he printf("%s: WARNING: bad ictx returned (%x)\n",
1628 1.19.4.2 he sc->sc_dv.dv_xname, ictx);
1629 1.19.4.2 he return (-1);
1630 1.19.4.2 he }
1631 1.19.4.2 he }
1632 1.19.4.2 he
1633 1.19.4.2 he /*
1634 1.19.4.2 he * If we received a transport failure notice, we've got to dig the
1635 1.19.4.2 he * transaction context (if any) out of the original message frame,
1636 1.19.4.2 he * and then release the original MFA back to the inbound FIFO.
1637 1.19.4.2 he */
1638 1.19.4.2 he if ((rb->msgflags & I2O_MSGFLAGS_FAIL) != 0) {
1639 1.19.4.2 he status = I2O_STATUS_SUCCESS;
1640 1.19.4.2 he
1641 1.19.4.2 he fn = (struct i2o_fault_notify *)rb;
1642 1.19.4.2 he tctx = iop_inl(sc, fn->lowmfa + 12);
1643 1.19.4.2 he iop_release_mfa(sc, fn->lowmfa);
1644 1.19.4.2 he iop_tfn_print(sc, fn);
1645 1.19.4.2 he } else {
1646 1.19.4.2 he status = rb->reqstatus;
1647 1.19.4.2 he tctx = le32toh(rb->msgtctx);
1648 1.19.4.2 he }
1649 1.19.4.2 he
1650 1.19.4.2 he if (ii == NULL || (ii->ii_flags & II_NOTCTX) == 0) {
1651 1.19.4.2 he /*
1652 1.19.4.2 he * This initiator tracks state using message wrappers.
1653 1.19.4.2 he *
1654 1.19.4.2 he * Find the originating message wrapper, and if requested
1655 1.19.4.2 he * notify the initiator.
1656 1.19.4.2 he */
1657 1.19.4.2 he im = sc->sc_ims + (tctx & IOP_TCTX_MASK);
1658 1.19.4.2 he if ((tctx & IOP_TCTX_MASK) > sc->sc_maxib ||
1659 1.19.4.2 he (im->im_flags & IM_ALLOCED) == 0 ||
1660 1.19.4.2 he tctx != im->im_tctx) {
1661 1.19.4.2 he printf("%s: WARNING: bad tctx returned (0x%08x, %p)\n",
1662 1.19.4.2 he sc->sc_dv.dv_xname, tctx, im);
1663 1.19.4.2 he if (im != NULL)
1664 1.19.4.2 he printf("%s: flags=0x%08x tctx=0x%08x\n",
1665 1.19.4.2 he sc->sc_dv.dv_xname, im->im_flags,
1666 1.19.4.2 he im->im_tctx);
1667 1.19.4.2 he #ifdef I2ODEBUG
1668 1.19.4.2 he if ((rb->msgflags & I2O_MSGFLAGS_FAIL) == 0)
1669 1.19.4.2 he iop_reply_print(sc, rb);
1670 1.19.4.2 he #endif
1671 1.19.4.2 he return (-1);
1672 1.19.4.2 he }
1673 1.19.4.2 he
1674 1.19.4.2 he if ((rb->msgflags & I2O_MSGFLAGS_FAIL) != 0)
1675 1.19.4.2 he im->im_flags |= IM_FAIL;
1676 1.19.4.2 he
1677 1.19.4.2 he #ifdef I2ODEBUG
1678 1.19.4.2 he if ((im->im_flags & IM_REPLIED) != 0)
1679 1.19.4.2 he panic("%s: dup reply", sc->sc_dv.dv_xname);
1680 1.19.4.2 he #endif
1681 1.19.4.2 he im->im_flags |= IM_REPLIED;
1682 1.19.4.2 he
1683 1.19.4.2 he #ifdef I2ODEBUG
1684 1.19.4.2 he if (status != I2O_STATUS_SUCCESS)
1685 1.19.4.2 he iop_reply_print(sc, rb);
1686 1.19.4.2 he #endif
1687 1.19.4.2 he im->im_reqstatus = status;
1688 1.19.4.2 he
1689 1.19.4.2 he /* Copy the reply frame, if requested. */
1690 1.19.4.2 he if (im->im_rb != NULL) {
1691 1.19.4.2 he size = (le32toh(rb->msgflags) >> 14) & ~3;
1692 1.19.4.2 he #ifdef I2ODEBUG
1693 1.19.4.2 he if (size > IOP_MAX_MSG_SIZE)
1694 1.19.4.2 he panic("iop_handle_reply: reply too large");
1695 1.19.4.2 he #endif
1696 1.19.4.2 he memcpy(im->im_rb, rb, size);
1697 1.19.4.2 he }
1698 1.19.4.2 he
1699 1.19.4.2 he /* Notify the initiator. */
1700 1.19.4.2 he if ((im->im_flags & IM_WAIT) != 0)
1701 1.19.4.2 he wakeup(im);
1702 1.19.4.2 he else if ((im->im_flags & (IM_POLL | IM_POLL_INTR)) != IM_POLL)
1703 1.19.4.2 he (*ii->ii_intr)(ii->ii_dv, im, rb);
1704 1.19.4.2 he } else {
1705 1.19.4.2 he /*
1706 1.19.4.2 he * This initiator discards message wrappers.
1707 1.19.4.2 he *
1708 1.19.4.2 he * Simply pass the reply frame to the initiator.
1709 1.19.4.2 he */
1710 1.19.4.2 he (*ii->ii_intr)(ii->ii_dv, NULL, rb);
1711 1.19.4.2 he }
1712 1.19.4.2 he
1713 1.19.4.2 he return (status);
1714 1.19.4.2 he }
1715 1.19.4.2 he
1716 1.19.4.2 he /*
1717 1.19.4.2 he * Handle an interrupt from the IOP.
1718 1.19.4.2 he */
1719 1.19.4.2 he int
1720 1.19.4.2 he iop_intr(void *arg)
1721 1.19.4.2 he {
1722 1.19.4.2 he struct iop_softc *sc;
1723 1.19.4.2 he u_int32_t rmfa;
1724 1.19.4.2 he
1725 1.19.4.2 he sc = arg;
1726 1.19.4.2 he
1727 1.19.4.2 he if ((iop_inl(sc, IOP_REG_INTR_STATUS) & IOP_INTR_OFIFO) == 0)
1728 1.19.4.2 he return (0);
1729 1.19.4.2 he
1730 1.19.4.2 he for (;;) {
1731 1.19.4.2 he /* Double read to account for IOP bug. */
1732 1.19.4.2 he if ((rmfa = iop_inl(sc, IOP_REG_OFIFO)) == IOP_MFA_EMPTY) {
1733 1.19.4.2 he rmfa = iop_inl(sc, IOP_REG_OFIFO);
1734 1.19.4.2 he if (rmfa == IOP_MFA_EMPTY)
1735 1.19.4.2 he break;
1736 1.19.4.2 he }
1737 1.19.4.2 he iop_handle_reply(sc, rmfa);
1738 1.19.4.2 he iop_outl(sc, IOP_REG_OFIFO, rmfa);
1739 1.19.4.2 he }
1740 1.19.4.2 he
1741 1.19.4.2 he return (1);
1742 1.19.4.2 he }
1743 1.19.4.2 he
1744 1.19.4.2 he /*
1745 1.19.4.2 he * Handle an event signalled by the executive.
1746 1.19.4.2 he */
1747 1.19.4.2 he static void
1748 1.19.4.2 he iop_intr_event(struct device *dv, struct iop_msg *im, void *reply)
1749 1.19.4.2 he {
1750 1.19.4.2 he struct i2o_util_event_register_reply *rb;
1751 1.19.4.2 he struct iop_softc *sc;
1752 1.19.4.2 he u_int event;
1753 1.19.4.2 he
1754 1.19.4.2 he sc = (struct iop_softc *)dv;
1755 1.19.4.2 he rb = reply;
1756 1.19.4.2 he
1757 1.19.4.2 he if ((rb->msgflags & I2O_MSGFLAGS_FAIL) != 0)
1758 1.19.4.2 he return;
1759 1.19.4.2 he
1760 1.19.4.2 he event = le32toh(rb->event);
1761 1.19.4.2 he printf("%s: event 0x%08x received\n", dv->dv_xname, event);
1762 1.19.4.2 he }
1763 1.19.4.2 he
1764 1.19.4.2 he /*
1765 1.19.4.2 he * Allocate a message wrapper.
1766 1.19.4.2 he */
1767 1.19.4.2 he struct iop_msg *
1768 1.19.4.2 he iop_msg_alloc(struct iop_softc *sc, int flags)
1769 1.19.4.2 he {
1770 1.19.4.2 he struct iop_msg *im;
1771 1.19.4.2 he static u_int tctxgen;
1772 1.19.4.2 he int s, i;
1773 1.19.4.2 he
1774 1.19.4.2 he #ifdef I2ODEBUG
1775 1.19.4.2 he if ((flags & IM_SYSMASK) != 0)
1776 1.19.4.2 he panic("iop_msg_alloc: system flags specified");
1777 1.19.4.2 he #endif
1778 1.19.4.2 he
1779 1.19.4.2 he s = splbio();
1780 1.19.4.2 he im = SLIST_FIRST(&sc->sc_im_freelist);
1781 1.19.4.2 he #if defined(DIAGNOSTIC) || defined(I2ODEBUG)
1782 1.19.4.2 he if (im == NULL)
1783 1.19.4.2 he panic("iop_msg_alloc: no free wrappers");
1784 1.19.4.2 he #endif
1785 1.19.4.2 he SLIST_REMOVE_HEAD(&sc->sc_im_freelist, im_chain);
1786 1.19.4.2 he splx(s);
1787 1.19.4.2 he
1788 1.19.4.2 he im->im_tctx = (im->im_tctx & IOP_TCTX_MASK) | tctxgen;
1789 1.19.4.2 he tctxgen += (1 << IOP_TCTX_SHIFT);
1790 1.19.4.2 he im->im_flags = flags | IM_ALLOCED;
1791 1.19.4.2 he im->im_rb = NULL;
1792 1.19.4.2 he i = 0;
1793 1.19.4.2 he do {
1794 1.19.4.2 he im->im_xfer[i++].ix_size = 0;
1795 1.19.4.2 he } while (i < IOP_MAX_MSG_XFERS);
1796 1.19.4.2 he
1797 1.19.4.2 he return (im);
1798 1.19.4.2 he }
1799 1.19.4.2 he
1800 1.19.4.2 he /*
1801 1.19.4.2 he * Free a message wrapper.
1802 1.19.4.2 he */
1803 1.19.4.2 he void
1804 1.19.4.2 he iop_msg_free(struct iop_softc *sc, struct iop_msg *im)
1805 1.19.4.2 he {
1806 1.19.4.2 he int s;
1807 1.19.4.2 he
1808 1.19.4.2 he #ifdef I2ODEBUG
1809 1.19.4.2 he if ((im->im_flags & IM_ALLOCED) == 0)
1810 1.19.4.2 he panic("iop_msg_free: wrapper not allocated");
1811 1.19.4.2 he #endif
1812 1.19.4.2 he
1813 1.19.4.2 he im->im_flags = 0;
1814 1.19.4.2 he s = splbio();
1815 1.19.4.2 he SLIST_INSERT_HEAD(&sc->sc_im_freelist, im, im_chain);
1816 1.19.4.2 he splx(s);
1817 1.19.4.2 he }
1818 1.19.4.2 he
1819 1.19.4.2 he /*
1820 1.19.4.2 he * Map a data transfer. Write a scatter-gather list into the message frame.
1821 1.19.4.2 he */
1822 1.19.4.2 he int
1823 1.19.4.2 he iop_msg_map(struct iop_softc *sc, struct iop_msg *im, u_int32_t *mb,
1824 1.19.4.2 he void *xferaddr, int xfersize, int out, struct proc *up)
1825 1.19.4.2 he {
1826 1.19.4.2 he bus_dmamap_t dm;
1827 1.19.4.2 he bus_dma_segment_t *ds;
1828 1.19.4.2 he struct iop_xfer *ix;
1829 1.19.4.2 he u_int rv, i, nsegs, flg, off, xn;
1830 1.19.4.2 he u_int32_t *p;
1831 1.19.4.2 he
1832 1.19.4.2 he for (xn = 0, ix = im->im_xfer; xn < IOP_MAX_MSG_XFERS; xn++, ix++)
1833 1.19.4.2 he if (ix->ix_size == 0)
1834 1.19.4.2 he break;
1835 1.19.4.2 he
1836 1.19.4.2 he #ifdef I2ODEBUG
1837 1.19.4.2 he if (xfersize == 0)
1838 1.19.4.2 he panic("iop_msg_map: null transfer");
1839 1.19.4.2 he if (xfersize > IOP_MAX_XFER)
1840 1.19.4.2 he panic("iop_msg_map: transfer too large");
1841 1.19.4.2 he if (xn == IOP_MAX_MSG_XFERS)
1842 1.19.4.2 he panic("iop_msg_map: too many xfers");
1843 1.19.4.2 he #endif
1844 1.19.4.2 he
1845 1.19.4.2 he /*
1846 1.19.4.2 he * Only the first DMA map is static.
1847 1.19.4.2 he */
1848 1.19.4.2 he if (xn != 0) {
1849 1.19.4.2 he rv = bus_dmamap_create(sc->sc_dmat, IOP_MAX_XFER,
1850 1.19.4.2 he IOP_MAX_SEGS, IOP_MAX_XFER, 0,
1851 1.19.4.2 he BUS_DMA_NOWAIT | BUS_DMA_ALLOCNOW, &ix->ix_map);
1852 1.19.4.2 he if (rv != 0)
1853 1.19.4.2 he return (rv);
1854 1.19.4.2 he }
1855 1.19.4.2 he
1856 1.19.4.2 he dm = ix->ix_map;
1857 1.19.4.2 he rv = bus_dmamap_load(sc->sc_dmat, dm, xferaddr, xfersize, up,
1858 1.19.4.2 he (up == NULL ? BUS_DMA_NOWAIT : 0));
1859 1.19.4.2 he if (rv != 0)
1860 1.19.4.2 he goto bad;
1861 1.19.4.2 he
1862 1.19.4.2 he /*
1863 1.19.4.2 he * How many SIMPLE SG elements can we fit in this message?
1864 1.19.4.2 he */
1865 1.19.4.2 he off = mb[0] >> 16;
1866 1.19.4.2 he p = mb + off;
1867 1.19.4.2 he nsegs = ((IOP_MAX_MSG_SIZE / 4) - off) >> 1;
1868 1.19.4.2 he
1869 1.19.4.2 he if (dm->dm_nsegs > nsegs) {
1870 1.19.4.2 he bus_dmamap_unload(sc->sc_dmat, ix->ix_map);
1871 1.19.4.2 he rv = EFBIG;
1872 1.19.4.2 he DPRINTF(("iop_msg_map: too many segs\n"));
1873 1.19.4.2 he goto bad;
1874 1.19.4.2 he }
1875 1.19.4.2 he
1876 1.19.4.2 he nsegs = dm->dm_nsegs;
1877 1.19.4.2 he xfersize = 0;
1878 1.19.4.2 he
1879 1.19.4.2 he /*
1880 1.19.4.2 he * Write out the SG list.
1881 1.19.4.2 he */
1882 1.19.4.2 he if (out)
1883 1.19.4.2 he flg = I2O_SGL_SIMPLE | I2O_SGL_DATA_OUT;
1884 1.19.4.2 he else
1885 1.19.4.2 he flg = I2O_SGL_SIMPLE;
1886 1.19.4.2 he
1887 1.19.4.2 he for (i = nsegs, ds = dm->dm_segs; i > 1; i--, p += 2, ds++) {
1888 1.19.4.2 he p[0] = (u_int32_t)ds->ds_len | flg;
1889 1.19.4.2 he p[1] = (u_int32_t)ds->ds_addr;
1890 1.19.4.2 he xfersize += ds->ds_len;
1891 1.19.4.2 he }
1892 1.19.4.2 he
1893 1.19.4.2 he p[0] = (u_int32_t)ds->ds_len | flg | I2O_SGL_END_BUFFER;
1894 1.19.4.2 he p[1] = (u_int32_t)ds->ds_addr;
1895 1.19.4.2 he xfersize += ds->ds_len;
1896 1.19.4.2 he
1897 1.19.4.2 he /* Fix up the transfer record, and sync the map. */
1898 1.19.4.2 he ix->ix_flags = (out ? IX_OUT : IX_IN);
1899 1.19.4.2 he ix->ix_size = xfersize;
1900 1.19.4.2 he bus_dmamap_sync(sc->sc_dmat, ix->ix_map, 0, xfersize,
1901 1.19.4.2 he out ? BUS_DMASYNC_POSTWRITE : BUS_DMASYNC_POSTREAD);
1902 1.19.4.2 he
1903 1.19.4.2 he /*
1904 1.19.4.2 he * If this is the first xfer we've mapped for this message, adjust
1905 1.19.4.2 he * the SGL offset field in the message header.
1906 1.19.4.2 he */
1907 1.19.4.2 he if ((im->im_flags & IM_SGLOFFADJ) == 0) {
1908 1.19.4.2 he mb[0] += (mb[0] >> 12) & 0xf0;
1909 1.19.4.2 he im->im_flags |= IM_SGLOFFADJ;
1910 1.19.4.2 he }
1911 1.19.4.2 he mb[0] += (nsegs << 17);
1912 1.19.4.2 he return (0);
1913 1.19.4.2 he
1914 1.19.4.2 he bad:
1915 1.19.4.2 he if (xn != 0)
1916 1.19.4.2 he bus_dmamap_destroy(sc->sc_dmat, ix->ix_map);
1917 1.19.4.2 he return (rv);
1918 1.19.4.2 he }
1919 1.19.4.2 he
1920 1.19.4.2 he /*
1921 1.19.4.2 he * Map a block I/O data transfer (different in that there's only one per
1922 1.19.4.2 he * message maximum, and PAGE addressing may be used). Write a scatter
1923 1.19.4.2 he * gather list into the message frame.
1924 1.19.4.2 he */
1925 1.19.4.2 he int
1926 1.19.4.2 he iop_msg_map_bio(struct iop_softc *sc, struct iop_msg *im, u_int32_t *mb,
1927 1.19.4.2 he void *xferaddr, int xfersize, int out)
1928 1.19.4.2 he {
1929 1.19.4.2 he bus_dma_segment_t *ds;
1930 1.19.4.2 he bus_dmamap_t dm;
1931 1.19.4.2 he struct iop_xfer *ix;
1932 1.19.4.2 he u_int rv, i, nsegs, off, slen, tlen, flg;
1933 1.19.4.2 he paddr_t saddr, eaddr;
1934 1.19.4.2 he u_int32_t *p;
1935 1.19.4.2 he
1936 1.19.4.2 he #ifdef I2ODEBUG
1937 1.19.4.2 he if (xfersize == 0)
1938 1.19.4.2 he panic("iop_msg_map_bio: null transfer");
1939 1.19.4.2 he if (xfersize > IOP_MAX_XFER)
1940 1.19.4.2 he panic("iop_msg_map_bio: transfer too large");
1941 1.19.4.2 he if ((im->im_flags & IM_SGLOFFADJ) != 0)
1942 1.19.4.2 he panic("iop_msg_map_bio: SGLOFFADJ");
1943 1.19.4.2 he #endif
1944 1.19.4.2 he
1945 1.19.4.2 he ix = im->im_xfer;
1946 1.19.4.2 he dm = ix->ix_map;
1947 1.19.4.2 he rv = bus_dmamap_load(sc->sc_dmat, dm, xferaddr, xfersize, NULL,
1948 1.19.4.2 he BUS_DMA_NOWAIT);
1949 1.19.4.2 he if (rv != 0)
1950 1.19.4.2 he return (rv);
1951 1.19.4.2 he
1952 1.19.4.2 he off = mb[0] >> 16;
1953 1.19.4.2 he nsegs = ((IOP_MAX_MSG_SIZE / 4) - off) >> 1;
1954 1.19.4.2 he
1955 1.19.4.2 he /*
1956 1.19.4.2 he * If the transfer is highly fragmented and won't fit using SIMPLE
1957 1.19.4.2 he * elements, use PAGE_LIST elements instead. SIMPLE elements are
1958 1.19.4.2 he * potentially more efficient, both for us and the IOP.
1959 1.19.4.2 he */
1960 1.19.4.2 he if (dm->dm_nsegs > nsegs) {
1961 1.19.4.2 he nsegs = 1;
1962 1.19.4.2 he p = mb + off + 1;
1963 1.19.4.2 he
1964 1.19.4.2 he /* XXX This should be done with a bus_space flag. */
1965 1.19.4.2 he for (i = dm->dm_nsegs, ds = dm->dm_segs; i > 0; i--, ds++) {
1966 1.19.4.2 he slen = ds->ds_len;
1967 1.19.4.2 he saddr = ds->ds_addr;
1968 1.19.4.2 he
1969 1.19.4.2 he while (slen > 0) {
1970 1.19.4.2 he eaddr = (saddr + NBPG) & ~(NBPG - 1);
1971 1.19.4.2 he tlen = min(eaddr - saddr, slen);
1972 1.19.4.2 he slen -= tlen;
1973 1.19.4.2 he *p++ = le32toh(saddr);
1974 1.19.4.2 he saddr = eaddr;
1975 1.19.4.2 he nsegs++;
1976 1.19.4.2 he }
1977 1.19.4.2 he }
1978 1.19.4.2 he
1979 1.19.4.2 he mb[off] = xfersize | I2O_SGL_PAGE_LIST | I2O_SGL_END_BUFFER |
1980 1.19.4.2 he I2O_SGL_END;
1981 1.19.4.2 he if (out)
1982 1.19.4.2 he mb[off] |= I2O_SGL_DATA_OUT;
1983 1.19.4.2 he } else {
1984 1.19.4.2 he p = mb + off;
1985 1.19.4.2 he nsegs = dm->dm_nsegs;
1986 1.19.4.2 he
1987 1.19.4.2 he if (out)
1988 1.19.4.2 he flg = I2O_SGL_SIMPLE | I2O_SGL_DATA_OUT;
1989 1.19.4.2 he else
1990 1.19.4.2 he flg = I2O_SGL_SIMPLE;
1991 1.19.4.2 he
1992 1.19.4.2 he for (i = nsegs, ds = dm->dm_segs; i > 1; i--, p += 2, ds++) {
1993 1.19.4.2 he p[0] = (u_int32_t)ds->ds_len | flg;
1994 1.19.4.2 he p[1] = (u_int32_t)ds->ds_addr;
1995 1.19.4.2 he }
1996 1.19.4.2 he
1997 1.19.4.2 he p[0] = (u_int32_t)ds->ds_len | flg | I2O_SGL_END_BUFFER |
1998 1.19.4.2 he I2O_SGL_END;
1999 1.19.4.2 he p[1] = (u_int32_t)ds->ds_addr;
2000 1.19.4.2 he nsegs <<= 1;
2001 1.19.4.2 he }
2002 1.19.4.2 he
2003 1.19.4.2 he /* Fix up the transfer record, and sync the map. */
2004 1.19.4.2 he ix->ix_flags = (out ? IX_OUT : IX_IN);
2005 1.19.4.2 he ix->ix_size = xfersize;
2006 1.19.4.2 he bus_dmamap_sync(sc->sc_dmat, ix->ix_map, 0, xfersize,
2007 1.19.4.2 he out ? BUS_DMASYNC_POSTWRITE : BUS_DMASYNC_POSTREAD);
2008 1.19.4.2 he
2009 1.19.4.2 he /*
2010 1.19.4.2 he * Adjust the SGL offset and total message size fields. We don't
2011 1.19.4.2 he * set IM_SGLOFFADJ, since it's used only for SIMPLE elements.
2012 1.19.4.2 he */
2013 1.19.4.2 he mb[0] += ((off << 4) + (nsegs << 16));
2014 1.19.4.2 he return (0);
2015 1.19.4.2 he }
2016 1.19.4.2 he
2017 1.19.4.2 he /*
2018 1.19.4.2 he * Unmap all data transfers associated with a message wrapper.
2019 1.19.4.2 he */
2020 1.19.4.2 he void
2021 1.19.4.2 he iop_msg_unmap(struct iop_softc *sc, struct iop_msg *im)
2022 1.19.4.2 he {
2023 1.19.4.2 he struct iop_xfer *ix;
2024 1.19.4.2 he int i;
2025 1.19.4.2 he
2026 1.19.4.2 he #ifdef I2ODEBUG
2027 1.19.4.2 he if (im->im_xfer[0].ix_size == 0)
2028 1.19.4.2 he panic("iop_msg_unmap: no transfers mapped");
2029 1.19.4.2 he #endif
2030 1.19.4.2 he
2031 1.19.4.2 he for (ix = im->im_xfer, i = 0;;) {
2032 1.19.4.2 he bus_dmamap_sync(sc->sc_dmat, ix->ix_map, 0, ix->ix_size,
2033 1.19.4.2 he ix->ix_flags & IX_OUT ? BUS_DMASYNC_POSTWRITE :
2034 1.19.4.2 he BUS_DMASYNC_POSTREAD);
2035 1.19.4.2 he bus_dmamap_unload(sc->sc_dmat, ix->ix_map);
2036 1.19.4.2 he
2037 1.19.4.2 he /* Only the first DMA map is static. */
2038 1.19.4.2 he if (i != 0)
2039 1.19.4.2 he bus_dmamap_destroy(sc->sc_dmat, ix->ix_map);
2040 1.19.4.2 he if ((++ix)->ix_size == 0)
2041 1.19.4.2 he break;
2042 1.19.4.2 he if (++i >= IOP_MAX_MSG_XFERS)
2043 1.19.4.2 he break;
2044 1.19.4.2 he }
2045 1.19.4.2 he }
2046 1.19.4.2 he
2047 1.19.4.2 he /*
2048 1.19.4.2 he * Post a message frame to the IOP's inbound queue.
2049 1.19.4.2 he */
2050 1.19.4.2 he int
2051 1.19.4.2 he iop_post(struct iop_softc *sc, u_int32_t *mb)
2052 1.19.4.2 he {
2053 1.19.4.2 he u_int32_t mfa;
2054 1.19.4.2 he int s;
2055 1.19.4.2 he
2056 1.19.4.2 he #ifdef I2ODEBUG
2057 1.19.4.2 he if ((mb[0] >> 16) > IOP_MAX_MSG_SIZE / 4)
2058 1.19.4.2 he panic("iop_post: frame too large");
2059 1.19.4.2 he #endif
2060 1.19.4.2 he
2061 1.19.4.2 he s = splbio();
2062 1.19.4.2 he
2063 1.19.4.2 he /* Allocate a slot with the IOP. */
2064 1.19.4.2 he if ((mfa = iop_inl(sc, IOP_REG_IFIFO)) == IOP_MFA_EMPTY)
2065 1.19.4.2 he if ((mfa = iop_inl(sc, IOP_REG_IFIFO)) == IOP_MFA_EMPTY) {
2066 1.19.4.2 he splx(s);
2067 1.19.4.2 he printf("%s: mfa not forthcoming\n",
2068 1.19.4.2 he sc->sc_dv.dv_xname);
2069 1.19.4.2 he return (EAGAIN);
2070 1.19.4.2 he }
2071 1.19.4.2 he
2072 1.19.4.2 he /* Perform reply buffer DMA synchronisation. */
2073 1.19.4.2 he if (sc->sc_curib++ == 0)
2074 1.19.4.2 he bus_dmamap_sync(sc->sc_dmat, sc->sc_rep_dmamap, 0,
2075 1.19.4.2 he sc->sc_rep_size, BUS_DMASYNC_PREREAD);
2076 1.19.4.2 he
2077 1.19.4.2 he /* Copy out the message frame. */
2078 1.19.4.2 he bus_space_write_region_4(sc->sc_iot, sc->sc_ioh, mfa, mb, mb[0] >> 16);
2079 1.19.4.2 he bus_space_barrier(sc->sc_iot, sc->sc_ioh, mfa, (mb[0] >> 14) & ~3,
2080 1.19.4.2 he BUS_SPACE_BARRIER_WRITE);
2081 1.19.4.2 he
2082 1.19.4.2 he /* Post the MFA back to the IOP. */
2083 1.19.4.2 he iop_outl(sc, IOP_REG_IFIFO, mfa);
2084 1.19.4.2 he
2085 1.19.4.2 he splx(s);
2086 1.19.4.2 he return (0);
2087 1.19.4.2 he }
2088 1.19.4.2 he
2089 1.19.4.2 he /*
2090 1.19.4.2 he * Post a message to the IOP and deal with completion.
2091 1.19.4.2 he */
2092 1.19.4.2 he int
2093 1.19.4.2 he iop_msg_post(struct iop_softc *sc, struct iop_msg *im, void *xmb, int timo)
2094 1.19.4.2 he {
2095 1.19.4.2 he u_int32_t *mb;
2096 1.19.4.2 he int rv, s;
2097 1.19.4.2 he
2098 1.19.4.2 he mb = xmb;
2099 1.19.4.2 he
2100 1.19.4.2 he /* Terminate the scatter/gather list chain. */
2101 1.19.4.2 he if ((im->im_flags & IM_SGLOFFADJ) != 0)
2102 1.19.4.2 he mb[(mb[0] >> 16) - 2] |= I2O_SGL_END;
2103 1.19.4.2 he
2104 1.19.4.2 he if ((rv = iop_post(sc, mb)) != 0)
2105 1.19.4.2 he return (rv);
2106 1.19.4.2 he
2107 1.19.4.2 he if ((im->im_flags & (IM_POLL | IM_WAIT)) != 0) {
2108 1.19.4.2 he if ((im->im_flags & IM_POLL) != 0)
2109 1.19.4.2 he iop_msg_poll(sc, im, timo);
2110 1.19.4.2 he else
2111 1.19.4.2 he iop_msg_wait(sc, im, timo);
2112 1.19.4.2 he
2113 1.19.4.2 he s = splbio();
2114 1.19.4.2 he if ((im->im_flags & IM_REPLIED) != 0) {
2115 1.19.4.2 he if ((im->im_flags & IM_NOSTATUS) != 0)
2116 1.19.4.2 he rv = 0;
2117 1.19.4.2 he else if ((im->im_flags & IM_FAIL) != 0)
2118 1.19.4.2 he rv = ENXIO;
2119 1.19.4.2 he else if (im->im_reqstatus != I2O_STATUS_SUCCESS)
2120 1.19.4.2 he rv = EIO;
2121 1.19.4.2 he else
2122 1.19.4.2 he rv = 0;
2123 1.19.4.2 he } else
2124 1.19.4.2 he rv = EBUSY;
2125 1.19.4.2 he splx(s);
2126 1.19.4.2 he } else
2127 1.19.4.2 he rv = 0;
2128 1.19.4.2 he
2129 1.19.4.2 he return (rv);
2130 1.19.4.2 he }
2131 1.19.4.2 he
2132 1.19.4.2 he /*
2133 1.19.4.2 he * Spin until the specified message is replied to.
2134 1.19.4.2 he */
2135 1.19.4.2 he static void
2136 1.19.4.2 he iop_msg_poll(struct iop_softc *sc, struct iop_msg *im, int timo)
2137 1.19.4.2 he {
2138 1.19.4.2 he u_int32_t rmfa;
2139 1.19.4.2 he int s, status;
2140 1.19.4.2 he
2141 1.19.4.2 he s = splbio();
2142 1.19.4.2 he
2143 1.19.4.2 he /* Wait for completion. */
2144 1.19.4.2 he for (timo *= 10; timo != 0; timo--) {
2145 1.19.4.2 he if ((iop_inl(sc, IOP_REG_INTR_STATUS) & IOP_INTR_OFIFO) != 0) {
2146 1.19.4.2 he /* Double read to account for IOP bug. */
2147 1.19.4.2 he rmfa = iop_inl(sc, IOP_REG_OFIFO);
2148 1.19.4.2 he if (rmfa == IOP_MFA_EMPTY)
2149 1.19.4.2 he rmfa = iop_inl(sc, IOP_REG_OFIFO);
2150 1.19.4.2 he if (rmfa != IOP_MFA_EMPTY) {
2151 1.19.4.2 he status = iop_handle_reply(sc, rmfa);
2152 1.19.4.2 he
2153 1.19.4.2 he /*
2154 1.19.4.2 he * Return the reply frame to the IOP's
2155 1.19.4.2 he * outbound FIFO.
2156 1.19.4.2 he */
2157 1.19.4.2 he iop_outl(sc, IOP_REG_OFIFO, rmfa);
2158 1.19.4.2 he }
2159 1.19.4.2 he }
2160 1.19.4.2 he if ((im->im_flags & IM_REPLIED) != 0)
2161 1.19.4.2 he break;
2162 1.19.4.2 he DELAY(100);
2163 1.19.4.2 he }
2164 1.19.4.2 he
2165 1.19.4.2 he if (timo == 0) {
2166 1.19.4.2 he #ifdef I2ODEBUG
2167 1.19.4.2 he printf("%s: poll - no reply\n", sc->sc_dv.dv_xname);
2168 1.19.4.2 he if (iop_status_get(sc, 1) != 0)
2169 1.19.4.2 he printf("iop_msg_poll: unable to retrieve status\n");
2170 1.19.4.2 he else
2171 1.19.4.2 he printf("iop_msg_poll: IOP state = %d\n",
2172 1.19.4.2 he (le32toh(sc->sc_status.segnumber) >> 16) & 0xff);
2173 1.19.4.2 he #endif
2174 1.19.4.2 he }
2175 1.19.4.2 he
2176 1.19.4.2 he splx(s);
2177 1.19.4.2 he }
2178 1.19.4.2 he
2179 1.19.4.2 he /*
2180 1.19.4.2 he * Sleep until the specified message is replied to.
2181 1.19.4.2 he */
2182 1.19.4.2 he static void
2183 1.19.4.2 he iop_msg_wait(struct iop_softc *sc, struct iop_msg *im, int timo)
2184 1.19.4.2 he {
2185 1.19.4.2 he int s, rv;
2186 1.19.4.2 he
2187 1.19.4.2 he s = splbio();
2188 1.19.4.2 he if ((im->im_flags & IM_REPLIED) != 0) {
2189 1.19.4.2 he splx(s);
2190 1.19.4.2 he return;
2191 1.19.4.2 he }
2192 1.19.4.2 he rv = tsleep(im, PRIBIO, "iopmsg", timo * hz / 1000);
2193 1.19.4.2 he splx(s);
2194 1.19.4.2 he
2195 1.19.4.2 he #ifdef I2ODEBUG
2196 1.19.4.2 he if (rv != 0) {
2197 1.19.4.2 he printf("iop_msg_wait: tsleep() == %d\n", rv);
2198 1.19.4.2 he if (iop_status_get(sc, 0) != 0)
2199 1.19.4.2 he printf("iop_msg_wait: unable to retrieve status\n");
2200 1.19.4.2 he else
2201 1.19.4.2 he printf("iop_msg_wait: IOP state = %d\n",
2202 1.19.4.2 he (le32toh(sc->sc_status.segnumber) >> 16) & 0xff);
2203 1.19.4.2 he }
2204 1.19.4.2 he #endif
2205 1.19.4.2 he }
2206 1.19.4.2 he
2207 1.19.4.2 he /*
2208 1.19.4.2 he * Release an unused message frame back to the IOP's inbound fifo.
2209 1.19.4.2 he */
2210 1.19.4.2 he static void
2211 1.19.4.2 he iop_release_mfa(struct iop_softc *sc, u_int32_t mfa)
2212 1.19.4.2 he {
2213 1.19.4.2 he
2214 1.19.4.2 he /* Use the frame to issue a no-op. */
2215 1.19.4.2 he iop_outl(sc, mfa, I2O_VERSION_11 | (4 << 16));
2216 1.19.4.2 he iop_outl(sc, mfa + 4, I2O_MSGFUNC(I2O_TID_IOP, I2O_UTIL_NOP));
2217 1.19.4.2 he iop_outl(sc, mfa + 8, 0);
2218 1.19.4.2 he iop_outl(sc, mfa + 12, 0);
2219 1.19.4.2 he
2220 1.19.4.2 he iop_outl(sc, IOP_REG_IFIFO, mfa);
2221 1.19.4.2 he }
2222 1.19.4.2 he
2223 1.19.4.2 he #ifdef I2ODEBUG
2224 1.19.4.2 he /*
2225 1.19.4.2 he * Dump a reply frame header.
2226 1.19.4.2 he */
2227 1.19.4.2 he static void
2228 1.19.4.2 he iop_reply_print(struct iop_softc *sc, struct i2o_reply *rb)
2229 1.19.4.2 he {
2230 1.19.4.2 he u_int function, detail;
2231 1.19.4.2 he #ifdef I2OVERBOSE
2232 1.19.4.2 he const char *statusstr;
2233 1.19.4.2 he #endif
2234 1.19.4.2 he
2235 1.19.4.2 he function = (le32toh(rb->msgfunc) >> 24) & 0xff;
2236 1.19.4.2 he detail = le16toh(rb->detail);
2237 1.19.4.2 he
2238 1.19.4.2 he printf("%s: reply:\n", sc->sc_dv.dv_xname);
2239 1.19.4.2 he
2240 1.19.4.2 he #ifdef I2OVERBOSE
2241 1.19.4.2 he if (rb->reqstatus < sizeof(iop_status) / sizeof(iop_status[0]))
2242 1.19.4.2 he statusstr = iop_status[rb->reqstatus];
2243 1.19.4.2 he else
2244 1.19.4.2 he statusstr = "undefined error code";
2245 1.19.4.2 he
2246 1.19.4.2 he printf("%s: function=0x%02x status=0x%02x (%s)\n",
2247 1.19.4.2 he sc->sc_dv.dv_xname, function, rb->reqstatus, statusstr);
2248 1.19.4.2 he #else
2249 1.19.4.2 he printf("%s: function=0x%02x status=0x%02x\n",
2250 1.19.4.2 he sc->sc_dv.dv_xname, function, rb->reqstatus);
2251 1.19.4.2 he #endif
2252 1.19.4.2 he printf("%s: detail=0x%04x ictx=0x%08x tctx=0x%08x\n",
2253 1.19.4.2 he sc->sc_dv.dv_xname, detail, le32toh(rb->msgictx),
2254 1.19.4.2 he le32toh(rb->msgtctx));
2255 1.19.4.2 he printf("%s: tidi=%d tidt=%d flags=0x%02x\n", sc->sc_dv.dv_xname,
2256 1.19.4.2 he (le32toh(rb->msgfunc) >> 12) & 4095, le32toh(rb->msgfunc) & 4095,
2257 1.19.4.2 he (le32toh(rb->msgflags) >> 8) & 0xff);
2258 1.19.4.2 he }
2259 1.19.4.2 he #endif
2260 1.19.4.2 he
2261 1.19.4.2 he /*
2262 1.19.4.2 he * Dump a transport failure reply.
2263 1.19.4.2 he */
2264 1.19.4.2 he static void
2265 1.19.4.2 he iop_tfn_print(struct iop_softc *sc, struct i2o_fault_notify *fn)
2266 1.19.4.2 he {
2267 1.19.4.2 he
2268 1.19.4.2 he printf("%s: WARNING: transport failure:\n", sc->sc_dv.dv_xname);
2269 1.19.4.2 he
2270 1.19.4.2 he printf("%s: ictx=0x%08x tctx=0x%08x\n", sc->sc_dv.dv_xname,
2271 1.19.4.2 he le32toh(fn->msgictx), le32toh(fn->msgtctx));
2272 1.19.4.2 he printf("%s: failurecode=0x%02x severity=0x%02x\n",
2273 1.19.4.2 he sc->sc_dv.dv_xname, fn->failurecode, fn->severity);
2274 1.19.4.2 he printf("%s: highestver=0x%02x lowestver=0x%02x\n",
2275 1.19.4.2 he sc->sc_dv.dv_xname, fn->highestver, fn->lowestver);
2276 1.19.4.2 he }
2277 1.19.4.2 he
2278 1.19.4.2 he /*
2279 1.19.4.2 he * Translate an I2O ASCII field into a C string.
2280 1.19.4.2 he */
2281 1.19.4.2 he void
2282 1.19.4.2 he iop_strvis(struct iop_softc *sc, const char *src, int slen, char *dst, int dlen)
2283 1.19.4.2 he {
2284 1.19.4.2 he int hc, lc, i, nit;
2285 1.19.4.2 he
2286 1.19.4.2 he dlen--;
2287 1.19.4.2 he lc = 0;
2288 1.19.4.2 he hc = 0;
2289 1.19.4.2 he i = 0;
2290 1.19.4.2 he
2291 1.19.4.2 he /*
2292 1.19.4.2 he * DPT use NUL as a space, whereas AMI use it as a terminator. The
2293 1.19.4.2 he * spec has nothing to say about it. Since AMI fields are usually
2294 1.19.4.2 he * filled with junk after the terminator, ...
2295 1.19.4.2 he */
2296 1.19.4.2 he nit = (le16toh(sc->sc_status.orgid) != I2O_ORG_DPT);
2297 1.19.4.2 he
2298 1.19.4.2 he while (slen-- != 0 && dlen-- != 0) {
2299 1.19.4.2 he if (nit && *src == '\0')
2300 1.19.4.2 he break;
2301 1.19.4.2 he else if (*src <= 0x20 || *src >= 0x7f) {
2302 1.19.4.2 he if (hc)
2303 1.19.4.2 he dst[i++] = ' ';
2304 1.19.4.2 he } else {
2305 1.19.4.2 he hc = 1;
2306 1.19.4.2 he dst[i++] = *src;
2307 1.19.4.2 he lc = i;
2308 1.19.4.2 he }
2309 1.19.4.2 he src++;
2310 1.19.4.2 he }
2311 1.19.4.2 he
2312 1.19.4.2 he dst[lc] = '\0';
2313 1.19.4.2 he }
2314 1.19.4.2 he
2315 1.19.4.2 he /*
2316 1.19.4.2 he * Retrieve the DEVICE_IDENTITY parameter group from the target and dump it.
2317 1.19.4.2 he */
2318 1.19.4.2 he int
2319 1.19.4.2 he iop_print_ident(struct iop_softc *sc, int tid)
2320 1.19.4.2 he {
2321 1.19.4.2 he struct {
2322 1.19.4.2 he struct i2o_param_op_results pr;
2323 1.19.4.2 he struct i2o_param_read_results prr;
2324 1.19.4.2 he struct i2o_param_device_identity di;
2325 1.19.4.2 he } __attribute__ ((__packed__)) p;
2326 1.19.4.2 he char buf[32];
2327 1.19.4.2 he int rv;
2328 1.19.4.2 he
2329 1.19.4.2 he rv = iop_field_get_all(sc, tid, I2O_PARAM_DEVICE_IDENTITY, &p,
2330 1.19.4.2 he sizeof(p), NULL);
2331 1.19.4.2 he if (rv != 0)
2332 1.19.4.2 he return (rv);
2333 1.19.4.2 he
2334 1.19.4.2 he iop_strvis(sc, p.di.vendorinfo, sizeof(p.di.vendorinfo), buf,
2335 1.19.4.2 he sizeof(buf));
2336 1.19.4.2 he printf(" <%s, ", buf);
2337 1.19.4.2 he iop_strvis(sc, p.di.productinfo, sizeof(p.di.productinfo), buf,
2338 1.19.4.2 he sizeof(buf));
2339 1.19.4.2 he printf("%s, ", buf);
2340 1.19.4.2 he iop_strvis(sc, p.di.revlevel, sizeof(p.di.revlevel), buf, sizeof(buf));
2341 1.19.4.2 he printf("%s>", buf);
2342 1.19.4.2 he
2343 1.19.4.2 he return (0);
2344 1.19.4.2 he }
2345 1.19.4.2 he
2346 1.19.4.2 he /*
2347 1.19.4.2 he * Claim or unclaim the specified TID.
2348 1.19.4.2 he */
2349 1.19.4.2 he int
2350 1.19.4.2 he iop_util_claim(struct iop_softc *sc, struct iop_initiator *ii, int release,
2351 1.19.4.2 he int flags)
2352 1.19.4.2 he {
2353 1.19.4.2 he struct iop_msg *im;
2354 1.19.4.2 he struct i2o_util_claim mf;
2355 1.19.4.2 he int rv, func;
2356 1.19.4.2 he
2357 1.19.4.2 he func = release ? I2O_UTIL_CLAIM_RELEASE : I2O_UTIL_CLAIM;
2358 1.19.4.2 he im = iop_msg_alloc(sc, IM_WAIT);
2359 1.19.4.2 he
2360 1.19.4.2 he /* We can use the same structure, as they're identical. */
2361 1.19.4.2 he mf.msgflags = I2O_MSGFLAGS(i2o_util_claim);
2362 1.19.4.2 he mf.msgfunc = I2O_MSGFUNC(ii->ii_tid, func);
2363 1.19.4.2 he mf.msgictx = ii->ii_ictx;
2364 1.19.4.2 he mf.msgtctx = im->im_tctx;
2365 1.19.4.2 he mf.flags = flags;
2366 1.19.4.2 he
2367 1.19.4.2 he rv = iop_msg_post(sc, im, &mf, 5000);
2368 1.19.4.2 he iop_msg_free(sc, im);
2369 1.19.4.2 he return (rv);
2370 1.19.4.2 he }
2371 1.19.4.2 he
2372 1.19.4.2 he /*
2373 1.19.4.2 he * Perform an abort.
2374 1.19.4.2 he */
2375 1.19.4.2 he int iop_util_abort(struct iop_softc *sc, struct iop_initiator *ii, int func,
2376 1.19.4.2 he int tctxabort, int flags)
2377 1.19.4.2 he {
2378 1.19.4.2 he struct iop_msg *im;
2379 1.19.4.2 he struct i2o_util_abort mf;
2380 1.19.4.2 he int rv;
2381 1.19.4.2 he
2382 1.19.4.2 he im = iop_msg_alloc(sc, IM_WAIT);
2383 1.19.4.2 he
2384 1.19.4.2 he mf.msgflags = I2O_MSGFLAGS(i2o_util_abort);
2385 1.19.4.2 he mf.msgfunc = I2O_MSGFUNC(ii->ii_tid, I2O_UTIL_ABORT);
2386 1.19.4.2 he mf.msgictx = ii->ii_ictx;
2387 1.19.4.2 he mf.msgtctx = im->im_tctx;
2388 1.19.4.2 he mf.flags = (func << 24) | flags;
2389 1.19.4.2 he mf.tctxabort = tctxabort;
2390 1.19.4.2 he
2391 1.19.4.2 he rv = iop_msg_post(sc, im, &mf, 5000);
2392 1.19.4.2 he iop_msg_free(sc, im);
2393 1.19.4.2 he return (rv);
2394 1.19.4.2 he }
2395 1.19.4.2 he
2396 1.19.4.2 he /*
2397 1.19.4.2 he * Enable or disable reception of events for the specified device.
2398 1.19.4.2 he */
2399 1.19.4.2 he int iop_util_eventreg(struct iop_softc *sc, struct iop_initiator *ii, int mask)
2400 1.19.4.2 he {
2401 1.19.4.2 he struct i2o_util_event_register mf;
2402 1.19.4.2 he
2403 1.19.4.2 he mf.msgflags = I2O_MSGFLAGS(i2o_util_event_register);
2404 1.19.4.2 he mf.msgfunc = I2O_MSGFUNC(ii->ii_tid, I2O_UTIL_EVENT_REGISTER);
2405 1.19.4.2 he mf.msgictx = ii->ii_ictx;
2406 1.19.4.2 he mf.msgtctx = 0;
2407 1.19.4.2 he mf.eventmask = mask;
2408 1.19.4.2 he
2409 1.19.4.2 he /* This message is replied to only when events are signalled. */
2410 1.19.4.2 he return (iop_post(sc, (u_int32_t *)&mf));
2411 1.19.4.2 he }
2412 1.19.4.2 he
2413 1.19.4.2 he int
2414 1.19.4.2 he iopopen(dev_t dev, int flag, int mode, struct proc *p)
2415 1.19.4.2 he {
2416 1.19.4.2 he struct iop_softc *sc;
2417 1.19.4.2 he
2418 1.19.4.2 he if ((sc = device_lookup(&iop_cd, minor(dev))) == NULL)
2419 1.19.4.2 he return (ENXIO);
2420 1.19.4.2 he if ((sc->sc_flags & IOP_ONLINE) == 0)
2421 1.19.4.2 he return (ENXIO);
2422 1.19.4.2 he if ((sc->sc_flags & IOP_OPEN) != 0)
2423 1.19.4.2 he return (EBUSY);
2424 1.19.4.2 he sc->sc_flags |= IOP_OPEN;
2425 1.19.4.2 he
2426 1.19.4.2 he return (0);
2427 1.19.4.2 he }
2428 1.19.4.2 he
2429 1.19.4.2 he int
2430 1.19.4.2 he iopclose(dev_t dev, int flag, int mode, struct proc *p)
2431 1.19.4.2 he {
2432 1.19.4.2 he struct iop_softc *sc;
2433 1.19.4.2 he
2434 1.19.4.2 he sc = device_lookup(&iop_cd, minor(dev));
2435 1.19.4.2 he sc->sc_flags &= ~IOP_OPEN;
2436 1.19.4.2 he
2437 1.19.4.2 he return (0);
2438 1.19.4.2 he }
2439 1.19.4.2 he
2440 1.19.4.2 he int
2441 1.19.4.2 he iopioctl(dev_t dev, u_long cmd, caddr_t data, int flag, struct proc *p)
2442 1.19.4.2 he {
2443 1.19.4.2 he struct iop_softc *sc;
2444 1.19.4.2 he struct iovec *iov;
2445 1.19.4.2 he int rv, i;
2446 1.19.4.2 he
2447 1.19.4.2 he if (securelevel >= 2)
2448 1.19.4.2 he return (EPERM);
2449 1.19.4.2 he
2450 1.19.4.2 he sc = device_lookup(&iop_cd, minor(dev));
2451 1.19.4.2 he
2452 1.19.4.2 he switch (cmd) {
2453 1.19.4.2 he case IOPIOCPT:
2454 1.19.4.2 he return (iop_passthrough(sc, (struct ioppt *)data, p));
2455 1.19.4.2 he
2456 1.19.4.2 he case IOPIOCGSTATUS:
2457 1.19.4.2 he iov = (struct iovec *)data;
2458 1.19.4.2 he i = sizeof(struct i2o_status);
2459 1.19.4.2 he if (i > iov->iov_len)
2460 1.19.4.2 he i = iov->iov_len;
2461 1.19.4.2 he else
2462 1.19.4.2 he iov->iov_len = i;
2463 1.19.4.2 he if ((rv = iop_status_get(sc, 0)) == 0)
2464 1.19.4.2 he rv = copyout(&sc->sc_status, iov->iov_base, i);
2465 1.19.4.2 he return (rv);
2466 1.19.4.2 he
2467 1.19.4.2 he case IOPIOCGLCT:
2468 1.19.4.2 he case IOPIOCGTIDMAP:
2469 1.19.4.2 he case IOPIOCRECONFIG:
2470 1.19.4.2 he break;
2471 1.19.4.2 he
2472 1.19.4.2 he default:
2473 1.19.4.2 he #if defined(DIAGNOSTIC) || defined(I2ODEBUG)
2474 1.19.4.2 he printf("%s: unknown ioctl %lx\n", sc->sc_dv.dv_xname, cmd);
2475 1.19.4.2 he #endif
2476 1.19.4.2 he return (ENOTTY);
2477 1.19.4.2 he }
2478 1.19.4.2 he
2479 1.19.4.2 he if ((rv = lockmgr(&sc->sc_conflock, LK_SHARED, NULL)) != 0)
2480 1.19.4.2 he return (rv);
2481 1.19.4.2 he
2482 1.19.4.2 he switch (cmd) {
2483 1.19.4.2 he case IOPIOCGLCT:
2484 1.19.4.2 he iov = (struct iovec *)data;
2485 1.19.4.2 he i = le16toh(sc->sc_lct->tablesize) << 2;
2486 1.19.4.2 he if (i > iov->iov_len)
2487 1.19.4.2 he i = iov->iov_len;
2488 1.19.4.2 he else
2489 1.19.4.2 he iov->iov_len = i;
2490 1.19.4.2 he rv = copyout(sc->sc_lct, iov->iov_base, i);
2491 1.19.4.2 he break;
2492 1.19.4.2 he
2493 1.19.4.2 he case IOPIOCRECONFIG:
2494 1.19.4.2 he rv = iop_reconfigure(sc, 0);
2495 1.19.4.2 he break;
2496 1.19.4.2 he
2497 1.19.4.2 he case IOPIOCGTIDMAP:
2498 1.19.4.2 he iov = (struct iovec *)data;
2499 1.19.4.2 he i = sizeof(struct iop_tidmap) * sc->sc_nlctent;
2500 1.19.4.2 he if (i > iov->iov_len)
2501 1.19.4.2 he i = iov->iov_len;
2502 1.19.4.2 he else
2503 1.19.4.2 he iov->iov_len = i;
2504 1.19.4.2 he rv = copyout(sc->sc_tidmap, iov->iov_base, i);
2505 1.19.4.2 he break;
2506 1.19.4.2 he }
2507 1.19.4.2 he
2508 1.19.4.2 he lockmgr(&sc->sc_conflock, LK_RELEASE, NULL);
2509 1.19.4.2 he return (rv);
2510 1.19.4.2 he }
2511 1.19.4.2 he
2512 1.19.4.2 he static int
2513 1.19.4.2 he iop_passthrough(struct iop_softc *sc, struct ioppt *pt, struct proc *p)
2514 1.19.4.2 he {
2515 1.19.4.2 he struct iop_msg *im;
2516 1.19.4.2 he struct i2o_msg *mf;
2517 1.19.4.2 he struct ioppt_buf *ptb;
2518 1.19.4.2 he int rv, i, mapped;
2519 1.19.4.2 he
2520 1.19.4.2 he mf = NULL;
2521 1.19.4.2 he im = NULL;
2522 1.19.4.2 he mapped = 1;
2523 1.19.4.2 he
2524 1.19.4.2 he if (pt->pt_msglen > IOP_MAX_MSG_SIZE ||
2525 1.19.4.2 he pt->pt_msglen > (le16toh(sc->sc_status.inboundmframesize) << 2) ||
2526 1.19.4.2 he pt->pt_msglen < sizeof(struct i2o_msg) ||
2527 1.19.4.2 he pt->pt_nbufs > IOP_MAX_MSG_XFERS ||
2528 1.19.4.2 he pt->pt_nbufs < 0 || pt->pt_replylen < 0 ||
2529 1.19.4.2 he pt->pt_timo < 1000 || pt->pt_timo > 5*60*1000)
2530 1.19.4.2 he return (EINVAL);
2531 1.19.4.2 he
2532 1.19.4.2 he for (i = 0; i < pt->pt_nbufs; i++)
2533 1.19.4.2 he if (pt->pt_bufs[i].ptb_datalen > IOP_MAX_XFER) {
2534 1.19.4.2 he rv = ENOMEM;
2535 1.19.4.2 he goto bad;
2536 1.19.4.2 he }
2537 1.19.4.2 he
2538 1.19.4.2 he mf = malloc(IOP_MAX_MSG_SIZE, M_DEVBUF, M_WAITOK);
2539 1.19.4.2 he if (mf == NULL)
2540 1.19.4.2 he return (ENOMEM);
2541 1.19.4.2 he
2542 1.19.4.2 he if ((rv = copyin(pt->pt_msg, mf, pt->pt_msglen)) != 0)
2543 1.19.4.2 he goto bad;
2544 1.19.4.2 he
2545 1.19.4.2 he im = iop_msg_alloc(sc, IM_WAIT | IM_NOSTATUS);
2546 1.19.4.2 he im->im_rb = (struct i2o_reply *)mf;
2547 1.19.4.2 he mf->msgictx = IOP_ICTX;
2548 1.19.4.2 he mf->msgtctx = im->im_tctx;
2549 1.19.4.2 he
2550 1.19.4.2 he for (i = 0; i < pt->pt_nbufs; i++) {
2551 1.19.4.2 he ptb = &pt->pt_bufs[i];
2552 1.19.4.2 he rv = iop_msg_map(sc, im, (u_int32_t *)mf, ptb->ptb_data,
2553 1.19.4.2 he ptb->ptb_datalen, ptb->ptb_out != 0, p);
2554 1.19.4.2 he if (rv != 0)
2555 1.19.4.2 he goto bad;
2556 1.19.4.2 he mapped = 1;
2557 1.19.4.2 he }
2558 1.19.4.2 he
2559 1.19.4.2 he if ((rv = iop_msg_post(sc, im, mf, pt->pt_timo)) != 0)
2560 1.19.4.2 he goto bad;
2561 1.19.4.2 he
2562 1.19.4.2 he i = (le32toh(im->im_rb->msgflags) >> 14) & ~3;
2563 1.19.4.2 he if (i > IOP_MAX_MSG_SIZE)
2564 1.19.4.2 he i = IOP_MAX_MSG_SIZE;
2565 1.19.4.2 he if (i > pt->pt_replylen)
2566 1.19.4.2 he i = pt->pt_replylen;
2567 1.19.4.2 he rv = copyout(im->im_rb, pt->pt_reply, i);
2568 1.19.4.2 he
2569 1.19.4.2 he bad:
2570 1.19.4.2 he if (mapped != 0)
2571 1.19.4.2 he iop_msg_unmap(sc, im);
2572 1.19.4.2 he if (im != NULL)
2573 1.19.4.2 he iop_msg_free(sc, im);
2574 1.19.4.2 he if (mf != NULL)
2575 1.19.4.2 he free(mf, M_DEVBUF);
2576 1.19.4.2 he return (rv);
2577 1.19.4.2 he }
2578