dpti.c revision 1.1 1 1.1 ad /* $NetBSD: dpti.c,v 1.1 2001/09/21 23:44:20 ad Exp $ */
2 1.1 ad
3 1.1 ad /*-
4 1.1 ad * Copyright (c) 2001 The NetBSD Foundation, Inc.
5 1.1 ad * All rights reserved.
6 1.1 ad *
7 1.1 ad * This code is derived from software contributed to The NetBSD Foundation
8 1.1 ad * by Andrew Doran.
9 1.1 ad *
10 1.1 ad * Redistribution and use in source and binary forms, with or without
11 1.1 ad * modification, are permitted provided that the following conditions
12 1.1 ad * are met:
13 1.1 ad * 1. Redistributions of source code must retain the above copyright
14 1.1 ad * notice, this list of conditions and the following disclaimer.
15 1.1 ad * 2. Redistributions in binary form must reproduce the above copyright
16 1.1 ad * notice, this list of conditions and the following disclaimer in the
17 1.1 ad * documentation and/or other materials provided with the distribution.
18 1.1 ad * 3. All advertising materials mentioning features or use of this software
19 1.1 ad * must display the following acknowledgement:
20 1.1 ad * This product includes software developed by the NetBSD
21 1.1 ad * Foundation, Inc. and its contributors.
22 1.1 ad * 4. Neither the name of The NetBSD Foundation nor the names of its
23 1.1 ad * contributors may be used to endorse or promote products derived
24 1.1 ad * from this software without specific prior written permission.
25 1.1 ad *
26 1.1 ad * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
27 1.1 ad * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
28 1.1 ad * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
29 1.1 ad * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
30 1.1 ad * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
31 1.1 ad * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
32 1.1 ad * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
33 1.1 ad * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
34 1.1 ad * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
35 1.1 ad * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
36 1.1 ad * POSSIBILITY OF SUCH DAMAGE.
37 1.1 ad */
38 1.1 ad
39 1.1 ad /*
40 1.1 ad * Copyright (c) 1996-2000 Distributed Processing Technology Corporation
41 1.1 ad * Copyright (c) 2000 Adaptec Corporation
42 1.1 ad * All rights reserved.
43 1.1 ad *
44 1.1 ad * TERMS AND CONDITIONS OF USE
45 1.1 ad *
46 1.1 ad * Redistribution and use in source form, with or without modification, are
47 1.1 ad * permitted provided that redistributions of source code must retain the
48 1.1 ad * above copyright notice, this list of conditions and the following disclaimer.
49 1.1 ad *
50 1.1 ad * This software is provided `as is' by Adaptec and any express or implied
51 1.1 ad * warranties, including, but not limited to, the implied warranties of
52 1.1 ad * merchantability and fitness for a particular purpose, are disclaimed. In no
53 1.1 ad * event shall Adaptec be liable for any direct, indirect, incidental, special,
54 1.1 ad * exemplary or consequential damages (including, but not limited to,
55 1.1 ad * procurement of substitute goods or services; loss of use, data, or profits;
56 1.1 ad * or business interruptions) however caused and on any theory of liability,
57 1.1 ad * whether in contract, strict liability, or tort (including negligence or
58 1.1 ad * otherwise) arising in any way out of the use of this driver software, even
59 1.1 ad * if advised of the possibility of such damage.
60 1.1 ad */
61 1.1 ad
62 1.1 ad /*
63 1.1 ad * Adaptec/DPT I2O control interface.
64 1.1 ad */
65 1.1 ad
66 1.1 ad #include "opt_i2o.h"
67 1.1 ad
68 1.1 ad #include <sys/param.h>
69 1.1 ad #include <sys/systm.h>
70 1.1 ad #include <sys/kernel.h>
71 1.1 ad #include <sys/device.h>
72 1.1 ad #include <sys/queue.h>
73 1.1 ad #include <sys/proc.h>
74 1.1 ad #include <sys/endian.h>
75 1.1 ad #include <sys/malloc.h>
76 1.1 ad #include <sys/conf.h>
77 1.1 ad #include <sys/ioctl.h>
78 1.1 ad
79 1.1 ad #include <machine/bus.h>
80 1.1 ad
81 1.1 ad #include <dev/i2o/i2o.h>
82 1.1 ad #include <dev/i2o/i2odpt.h>
83 1.1 ad #include <dev/i2o/iopio.h>
84 1.1 ad #include <dev/i2o/iopvar.h>
85 1.1 ad #include <dev/i2o/dptivar.h>
86 1.1 ad
87 1.1 ad #include <compat/linux/common/linux_types.h>
88 1.1 ad #include <compat/linux/common/linux_ioctl.h>
89 1.1 ad
90 1.1 ad #ifdef I2ODEBUG
91 1.1 ad #define DPRINTF(x) printf x
92 1.1 ad #else
93 1.1 ad #define DPRINTF(x)
94 1.1 ad #endif
95 1.1 ad
96 1.1 ad static struct dpt_sig dpti_sig = {
97 1.1 ad { 'd', 'P', 't', 'S', 'i', 'G'}, SIG_VERSION, PROC_INTEL,
98 1.1 ad PROC_386 | PROC_486 | PROC_PENTIUM | PROC_SEXIUM, FT_HBADRVR, 0,
99 1.1 ad OEM_DPT, OS_FREE_BSD, CAP_ABOVE16MB, DEV_ALL,
100 1.1 ad ADF_ALL_SC5,
101 1.1 ad 0, 0, DPTI_VERSION, DPTI_REVISION, DPTI_SUBREVISION,
102 1.1 ad DPTI_MONTH, DPTI_DAY, DPTI_YEAR,
103 1.1 ad ""
104 1.1 ad };
105 1.1 ad
106 1.1 ad void dpti_attach(struct device *, struct device *, void *);
107 1.1 ad int dpti_blinkled(struct dpti_softc *);
108 1.1 ad int dpti_ctlrinfo(struct dpti_softc *, u_long, caddr_t);
109 1.1 ad int dpti_match(struct device *, struct cfdata *, void *);
110 1.1 ad int dpti_passthrough(struct dpti_softc *, caddr_t, struct proc *);
111 1.1 ad int dpti_sysinfo(struct dpti_softc *, u_long, caddr_t);
112 1.1 ad
113 1.1 ad cdev_decl(dpti);
114 1.1 ad
115 1.1 ad extern struct cfdriver dpti_cd;
116 1.1 ad
117 1.1 ad struct cfattach dpti_ca = {
118 1.1 ad sizeof(struct dpti_softc), dpti_match, dpti_attach
119 1.1 ad };
120 1.1 ad
121 1.1 ad int
122 1.1 ad dpti_match(struct device *parent, struct cfdata *match, void *aux)
123 1.1 ad {
124 1.1 ad struct iop_attach_args *ia;
125 1.1 ad struct iop_softc *iop;
126 1.1 ad
127 1.1 ad ia = aux;
128 1.1 ad iop = (struct iop_softc *)parent;
129 1.1 ad
130 1.1 ad if (ia->ia_class != I2O_CLASS_ANY || ia->ia_tid != I2O_TID_IOP)
131 1.1 ad return (0);
132 1.1 ad
133 1.1 ad if (le16toh(iop->sc_status.orgid) != I2O_ORG_DPT)
134 1.1 ad return (0);
135 1.1 ad
136 1.1 ad return (1);
137 1.1 ad }
138 1.1 ad
139 1.1 ad void
140 1.1 ad dpti_attach(struct device *parent, struct device *self, void *aux)
141 1.1 ad {
142 1.1 ad struct iop_softc *iop;
143 1.1 ad struct dpti_softc *sc;
144 1.1 ad struct {
145 1.1 ad struct i2o_param_op_results pr;
146 1.1 ad struct i2o_param_read_results prr;
147 1.1 ad struct i2o_dpt_param_exec_iop_buffers dib;
148 1.1 ad } __attribute__ ((__packed__)) param;
149 1.1 ad int rv;
150 1.1 ad
151 1.1 ad sc = (struct dpti_softc *)self;
152 1.1 ad iop = (struct iop_softc *)parent;
153 1.1 ad
154 1.1 ad /*
155 1.1 ad * Tell the world what we are. The description in the signature
156 1.1 ad * must be no more than 46 bytes long (see dptivar.h).
157 1.1 ad */
158 1.1 ad printf(": DPT/Adaptec SCSI RAID management interface\n");
159 1.1 ad sprintf(dpti_sig.dsDescription, "NetBSD %s I2O OSM", osrelease);
160 1.1 ad
161 1.1 ad rv = iop_field_get_all(iop, I2O_TID_IOP,
162 1.1 ad I2O_DPT_PARAM_EXEC_IOP_BUFFERS, ¶m,
163 1.1 ad sizeof(param), NULL);
164 1.1 ad if (rv != 0)
165 1.1 ad return;
166 1.1 ad
167 1.1 ad sc->sc_blinkled = le32toh(param.dib.serialoutputoff) + 8;
168 1.1 ad }
169 1.1 ad
170 1.1 ad int
171 1.1 ad dptiopen(dev_t dev, int flag, int mode, struct proc *p)
172 1.1 ad {
173 1.1 ad
174 1.1 ad if (securelevel > 1)
175 1.1 ad return (EPERM);
176 1.1 ad if (device_lookup(&dpti_cd, minor(dev)) == NULL)
177 1.1 ad return (ENXIO);
178 1.1 ad
179 1.1 ad return (0);
180 1.1 ad }
181 1.1 ad
182 1.1 ad int
183 1.1 ad dpticlose(dev_t dev, int flag, int mode, struct proc *p)
184 1.1 ad {
185 1.1 ad
186 1.1 ad return (0);
187 1.1 ad }
188 1.1 ad
189 1.1 ad int
190 1.1 ad dptiioctl(dev_t dev, u_long cmd, caddr_t data, int flag, struct proc *p)
191 1.1 ad {
192 1.1 ad struct iop_softc *iop;
193 1.1 ad struct dpti_softc *sc;
194 1.1 ad struct ioctl_pt *pt;
195 1.1 ad int i, size;
196 1.1 ad
197 1.1 ad sc = device_lookup(&dpti_cd, minor(dev));
198 1.1 ad iop = (struct iop_softc *)sc->sc_dv.dv_parent;
199 1.1 ad
200 1.1 ad /*
201 1.1 ad * Currently, we only take ioctls passed down from the Linux
202 1.1 ad * emulation layer.
203 1.1 ad */
204 1.1 ad if (cmd == PTIOCLINUX) {
205 1.1 ad pt = (struct ioctl_pt *)data;
206 1.1 ad cmd = pt->com;
207 1.1 ad data = pt->data;
208 1.1 ad } else
209 1.1 ad return (ENOTTY);
210 1.1 ad
211 1.1 ad size = IOCPARM_LEN(cmd);
212 1.1 ad
213 1.1 ad switch (cmd & 0xffff) {
214 1.1 ad case DPT_SIGNATURE:
215 1.1 ad if (size > sizeof(dpti_sig))
216 1.1 ad size = sizeof(dpti_sig);
217 1.1 ad memcpy(data, &dpti_sig, size);
218 1.1 ad return (0);
219 1.1 ad
220 1.1 ad case DPT_CTRLINFO:
221 1.1 ad return (dpti_ctlrinfo(sc, cmd, data));
222 1.1 ad
223 1.1 ad case DPT_SYSINFO:
224 1.1 ad return (dpti_sysinfo(sc, cmd, data));
225 1.1 ad
226 1.1 ad case DPT_BLINKLED:
227 1.1 ad if ((i = dpti_blinkled(sc)) == -1)
228 1.1 ad i = 0;
229 1.1 ad
230 1.1 ad if (size == 0)
231 1.1 ad return (copyout(&i, *(caddr_t *)data, sizeof(i)));
232 1.1 ad
233 1.1 ad *(int *)data = i;
234 1.1 ad return (0);
235 1.1 ad
236 1.1 ad case DPT_TARGET_BUSY:
237 1.1 ad /*
238 1.1 ad * XXX This is here to stop linux_machdepioctl() from
239 1.1 ad * whining about an unknown ioctl. Really, it should be
240 1.1 ad * implemented.
241 1.1 ad */
242 1.1 ad return (EIO);
243 1.1 ad
244 1.1 ad case DPT_I2OUSRCMD:
245 1.1 ad return (dpti_passthrough(sc, data, p));
246 1.1 ad
247 1.1 ad case DPT_I2ORESETCMD:
248 1.1 ad printf("%s: I2ORESETCMD not implemented\n",
249 1.1 ad sc->sc_dv.dv_xname);
250 1.1 ad return (ENOTTY);
251 1.1 ad
252 1.1 ad case DPT_I2ORESCANCMD:
253 1.1 ad return (iop_reconfigure(iop, 0));
254 1.1 ad
255 1.1 ad default:
256 1.1 ad return (ENOTTY);
257 1.1 ad }
258 1.1 ad }
259 1.1 ad
260 1.1 ad int
261 1.1 ad dpti_blinkled(struct dpti_softc *sc)
262 1.1 ad {
263 1.1 ad struct iop_softc *iop;
264 1.1 ad u_int v;
265 1.1 ad
266 1.1 ad iop = (struct iop_softc *)sc->sc_dv.dv_parent;
267 1.1 ad
268 1.1 ad v = bus_space_read_1(iop->sc_iot, iop->sc_ioh, sc->sc_blinkled + 0);
269 1.1 ad if (v == 0xbc) {
270 1.1 ad v = bus_space_read_1(iop->sc_iot, iop->sc_ioh,
271 1.1 ad sc->sc_blinkled + 1);
272 1.1 ad return (v);
273 1.1 ad }
274 1.1 ad
275 1.1 ad return (-1);
276 1.1 ad }
277 1.1 ad
278 1.1 ad int
279 1.1 ad dpti_ctlrinfo(struct dpti_softc *sc, u_long cmd, caddr_t data)
280 1.1 ad {
281 1.1 ad struct dpt_ctlrinfo CtlrInfo;
282 1.1 ad struct iop_softc *iop;
283 1.1 ad int rv, i;
284 1.1 ad
285 1.1 ad iop = (struct iop_softc *)sc->sc_dv.dv_parent;
286 1.1 ad
287 1.1 ad memset(&CtlrInfo, 0, sizeof(CtlrInfo));
288 1.1 ad
289 1.1 ad CtlrInfo.length = sizeof(CtlrInfo) - sizeof(u_int16_t);
290 1.1 ad CtlrInfo.drvrHBAnum = sc->sc_dv.dv_unit;
291 1.1 ad CtlrInfo.baseAddr = iop->sc_memaddr;
292 1.1 ad if ((i = dpti_blinkled(sc)) == -1)
293 1.1 ad i = 0;
294 1.1 ad CtlrInfo.blinkState = i;
295 1.1 ad CtlrInfo.pciBusNum = iop->sc_pcibus;
296 1.1 ad CtlrInfo.pciDeviceNum = iop->sc_pcidev;
297 1.1 ad CtlrInfo.hbaFlags = FLG_OSD_PCI_VALID | FLG_OSD_DMA | FLG_OSD_I2O;
298 1.1 ad CtlrInfo.Interrupt = 10; /* XXX */
299 1.1 ad
300 1.1 ad if (IOCPARM_LEN(cmd) > sizeof(*data)) {
301 1.1 ad bcopy(&CtlrInfo, data, sizeof(CtlrInfo));
302 1.1 ad rv = 0;
303 1.1 ad } else
304 1.1 ad rv = copyout(&CtlrInfo, *(caddr_t *)data,
305 1.1 ad sizeof(CtlrInfo));
306 1.1 ad
307 1.1 ad return (rv);
308 1.1 ad }
309 1.1 ad
310 1.1 ad int
311 1.1 ad dpti_sysinfo(struct dpti_softc *sc, u_long cmd, caddr_t data)
312 1.1 ad {
313 1.1 ad
314 1.1 ad /*
315 1.1 ad * XXX Not currently implemented, since it involves reading from the
316 1.1 ad * IBM PC CMOS and grovelling around in ISA expansion card space,
317 1.1 ad * which is kind of disgusting. The DPT utilities don't seem to
318 1.1 ad * mind. :-)
319 1.1 ad */
320 1.1 ad return (EIO);
321 1.1 ad }
322 1.1 ad
323 1.1 ad int
324 1.1 ad dpti_passthrough(struct dpti_softc *sc, caddr_t data, struct proc *proc)
325 1.1 ad {
326 1.1 ad struct iop_softc *iop;
327 1.1 ad struct i2o_msg mh, *mf;
328 1.1 ad struct i2o_reply rh;
329 1.1 ad struct iop_msg *im;
330 1.1 ad struct dpti_ptbuf bufs[IOP_MAX_MSG_XFERS];
331 1.1 ad u_int32_t mbtmp[IOP_MAX_MSG_SIZE / sizeof(u_int32_t)];
332 1.1 ad u_int32_t rbtmp[IOP_MAX_MSG_SIZE / sizeof(u_int32_t)];
333 1.1 ad int rv, msgsize, repsize, sgoff, i, mapped, nbuf;
334 1.1 ad u_int32_t *p, *pmax;
335 1.1 ad
336 1.1 ad iop = (struct iop_softc *)sc->sc_dv.dv_parent;
337 1.1 ad
338 1.1 ad if ((rv = dpti_blinkled(sc)) != -1) {
339 1.1 ad if (rv != 0) {
340 1.1 ad printf("%s: adapter blinkled = 0x%02x\n",
341 1.1 ad sc->sc_dv.dv_xname, rv);
342 1.1 ad return (EIO);
343 1.1 ad }
344 1.1 ad }
345 1.1 ad
346 1.1 ad /*
347 1.1 ad * Copy in the message frame header and determine the size of the
348 1.1 ad * full message frame.
349 1.1 ad */
350 1.1 ad if ((rv = copyin(data, &mh, sizeof(mh))) != 0) {
351 1.1 ad DPRINTF(("%s: message copyin failed\n",
352 1.1 ad sc->sc_dv.dv_xname));
353 1.1 ad return (rv);
354 1.1 ad }
355 1.1 ad
356 1.1 ad msgsize = (mh.msgflags >> 14) & ~3;
357 1.1 ad if (msgsize < sizeof(mh) || msgsize >= IOP_MAX_MSG_SIZE) {
358 1.1 ad DPRINTF(("%s: bad message frame size\n",
359 1.1 ad sc->sc_dv.dv_xname));
360 1.1 ad return (EINVAL);
361 1.1 ad }
362 1.1 ad
363 1.1 ad /*
364 1.1 ad * Handle special commands.
365 1.1 ad *
366 1.1 ad * XXX We'll need to handle all of these later for online firmware
367 1.1 ad * upgrades. Swish or what, eh?
368 1.1 ad */
369 1.1 ad switch (mh.msgfunc >> 24) {
370 1.1 ad case I2O_EXEC_IOP_RESET:
371 1.1 ad printf("dpti%s: I2O_EXEC_IOP_RESET not implemented\n",
372 1.1 ad sc->sc_dv.dv_xname);
373 1.1 ad return (EIO);
374 1.1 ad
375 1.1 ad case I2O_EXEC_OUTBOUND_INIT:
376 1.1 ad printf("dpti%s: I2O_EXEC_OUTBOUND_INIT not implemented\n",
377 1.1 ad sc->sc_dv.dv_xname);
378 1.1 ad return (EIO);
379 1.1 ad
380 1.1 ad case I2O_EXEC_SYS_TAB_SET:
381 1.1 ad printf("dpti%s: I2O_EXEC_SYS_TAB_SET not implemented\n",
382 1.1 ad sc->sc_dv.dv_xname);
383 1.1 ad return (EIO);
384 1.1 ad
385 1.1 ad case I2O_EXEC_STATUS_GET:
386 1.1 ad iop_status_get(iop, 0);
387 1.1 ad rv = copyout(&iop->sc_status, data + msgsize,
388 1.1 ad sizeof(iop->sc_status));
389 1.1 ad return (rv);
390 1.1 ad }
391 1.1 ad
392 1.1 ad /*
393 1.1 ad * Copy in the full message frame.
394 1.1 ad */
395 1.1 ad if ((rv = copyin(data, mbtmp, msgsize)) != 0) {
396 1.1 ad DPRINTF(("%s: full message copyin failed\n",
397 1.1 ad sc->sc_dv.dv_xname));
398 1.1 ad return (rv);
399 1.1 ad }
400 1.1 ad
401 1.1 ad /*
402 1.1 ad * Determine the size of the reply frame, and copy it in.
403 1.1 ad */
404 1.1 ad if ((rv = copyin(data + msgsize, &rh, sizeof(rh))) != 0) {
405 1.1 ad DPRINTF(("%s: reply copyin failed\n",
406 1.1 ad sc->sc_dv.dv_xname));
407 1.1 ad return (rv);
408 1.1 ad }
409 1.1 ad
410 1.1 ad repsize = (rh.msgflags >> 14) & ~3;
411 1.1 ad if (repsize < sizeof(rh) || repsize >= IOP_MAX_MSG_SIZE) {
412 1.1 ad DPRINTF(("%s: bad reply header size\n",
413 1.1 ad sc->sc_dv.dv_xname));
414 1.1 ad return (EINVAL);
415 1.1 ad }
416 1.1 ad
417 1.1 ad if ((rv = copyin(data + msgsize, rbtmp, repsize)) != 0) {
418 1.1 ad DPRINTF(("%s: reply too large\n", sc->sc_dv.dv_xname));
419 1.1 ad return (rv);
420 1.1 ad }
421 1.1 ad
422 1.1 ad /*
423 1.1 ad * If the message has a scatter gather list, it must be comprised of
424 1.1 ad * simple elements. If any one transfer contains multiple segments,
425 1.1 ad * we allocate a temporary buffer for it; otherwise, the buffer will
426 1.1 ad * be mapped directly. XXX Lies! We don't do scatter-gather yet.
427 1.1 ad */
428 1.1 ad if ((sgoff = ((mh.msgflags >> 4) & 15)) != 0) {
429 1.1 ad if ((sgoff + 2) > (msgsize >> 2)) {
430 1.1 ad DPRINTF(("%s: invalid message size fields\n",
431 1.1 ad sc->sc_dv.dv_xname));
432 1.1 ad return (EINVAL);
433 1.1 ad }
434 1.1 ad } else
435 1.1 ad nbuf = -1;
436 1.1 ad
437 1.1 ad if (sgoff != 0) {
438 1.1 ad p = mbtmp + sgoff;
439 1.1 ad pmax = mbtmp + (msgsize >> 2);
440 1.1 ad
441 1.1 ad for (nbuf = 0; nbuf < IOP_MAX_MSG_XFERS; nbuf++) {
442 1.1 ad if (p > pmax - 2) {
443 1.1 ad DPRINTF(("%s: invalid SGL (1)\n",
444 1.1 ad sc->sc_dv.dv_xname));
445 1.1 ad return (EINVAL);
446 1.1 ad }
447 1.1 ad
448 1.1 ad if ((p[0] & 0x30000000) != I2O_SGL_SIMPLE) {
449 1.1 ad DPRINTF(("%s: invalid SGL (2)\n",
450 1.1 ad sc->sc_dv.dv_xname));
451 1.1 ad return (EINVAL);
452 1.1 ad }
453 1.1 ad
454 1.1 ad bufs[nbuf].db_out = (p[0] & I2O_SGL_DATA_OUT) != 0;
455 1.1 ad
456 1.1 ad if ((p[0] & I2O_SGL_END_BUFFER) != 0) {
457 1.1 ad if ((p[0] & 0x00ffffff) > IOP_MAX_XFER) {
458 1.1 ad DPRINTF(("%s: buffer too large\n",
459 1.1 ad sc->sc_dv.dv_xname));
460 1.1 ad return (EINVAL);
461 1.1 ad }
462 1.1 ad
463 1.1 ad bufs[nbuf].db_ptr = (caddr_t)p[1];
464 1.1 ad bufs[nbuf].db_proc = proc;
465 1.1 ad bufs[nbuf].db_size = p[0] & 0x00ffffff;
466 1.1 ad
467 1.1 ad if ((p[0] & I2O_SGL_END) != 0)
468 1.1 ad break;
469 1.1 ad
470 1.1 ad p += 2;
471 1.1 ad continue;
472 1.1 ad }
473 1.1 ad
474 1.1 ad printf("%s: scatter-gather not implemented\n",
475 1.1 ad sc->sc_dv.dv_xname);
476 1.1 ad return (EIO);
477 1.1 ad }
478 1.1 ad
479 1.1 ad if (nbuf == IOP_MAX_MSG_XFERS) {
480 1.1 ad DPRINTF(("%s: too many transfers\n",
481 1.1 ad sc->sc_dv.dv_xname));
482 1.1 ad return (EINVAL);
483 1.1 ad }
484 1.1 ad }
485 1.1 ad
486 1.1 ad /*
487 1.1 ad * Allocate a wrapper, and adjust the message header fields to
488 1.1 ad * indicate that no scatter-gather list is currently present.
489 1.1 ad */
490 1.1 ad im = iop_msg_alloc(iop, IM_WAIT | IM_NOSTATUS);
491 1.1 ad im->im_rb = (struct i2o_reply *)rbtmp;
492 1.1 ad mf = (struct i2o_msg *)mbtmp;
493 1.1 ad mf->msgictx = IOP_ICTX;
494 1.1 ad mf->msgtctx = im->im_tctx;
495 1.1 ad mapped = 0;
496 1.1 ad
497 1.1 ad if (sgoff != 0)
498 1.1 ad mf->msgflags = (mf->msgflags & 0xff0f) | (sgoff << 16);
499 1.1 ad
500 1.1 ad /*
501 1.1 ad * Map the data transfer(s).
502 1.1 ad */
503 1.1 ad for (i = 0; i <= nbuf; i++) {
504 1.1 ad rv = iop_msg_map(iop, im, mbtmp, bufs[i].db_ptr,
505 1.1 ad bufs[i].db_size, bufs[i].db_out, bufs[i].db_proc);
506 1.1 ad if (rv != 0) {
507 1.1 ad DPRINTF(("%s: msg_map failed\n",
508 1.1 ad sc->sc_dv.dv_xname));
509 1.1 ad goto bad;
510 1.1 ad }
511 1.1 ad mapped = 1;
512 1.1 ad }
513 1.1 ad
514 1.1 ad /*
515 1.1 ad * Start the command and sleep until it completes.
516 1.1 ad */
517 1.1 ad if (sc->sc_nactive++ >= 2)
518 1.1 ad tsleep(&sc->sc_nactive, PRIBIO, "dptislp", 0);
519 1.1 ad
520 1.1 ad if ((rv = iop_msg_post(iop, im, mbtmp, 5*60*1000)) != 0)
521 1.1 ad goto bad;
522 1.1 ad
523 1.1 ad /*
524 1.1 ad * Copy out the reply frame.
525 1.1 ad */
526 1.1 ad if ((rv = copyout(rbtmp, data + msgsize, repsize)) != 0)
527 1.1 ad DPRINTF(("%s: reply copyout() failed\n",
528 1.1 ad sc->sc_dv.dv_xname));
529 1.1 ad
530 1.1 ad bad:
531 1.1 ad sc->sc_nactive--;
532 1.1 ad wakeup_one(&sc->sc_nactive);
533 1.1 ad
534 1.1 ad if (mapped)
535 1.1 ad iop_msg_unmap(iop, im);
536 1.1 ad
537 1.1 ad iop_msg_free(iop, im);
538 1.1 ad return (rv);
539 1.1 ad }
540