dpti.c revision 1.1.2.5 1 1.1.2.5 nathanw /* $NetBSD: dpti.c,v 1.1.2.5 2002/06/20 03:44:24 nathanw Exp $ */
2 1.1.2.2 nathanw
3 1.1.2.2 nathanw /*-
4 1.1.2.2 nathanw * Copyright (c) 2001 The NetBSD Foundation, Inc.
5 1.1.2.2 nathanw * All rights reserved.
6 1.1.2.2 nathanw *
7 1.1.2.2 nathanw * This code is derived from software contributed to The NetBSD Foundation
8 1.1.2.2 nathanw * by Andrew Doran.
9 1.1.2.2 nathanw *
10 1.1.2.2 nathanw * Redistribution and use in source and binary forms, with or without
11 1.1.2.2 nathanw * modification, are permitted provided that the following conditions
12 1.1.2.2 nathanw * are met:
13 1.1.2.2 nathanw * 1. Redistributions of source code must retain the above copyright
14 1.1.2.2 nathanw * notice, this list of conditions and the following disclaimer.
15 1.1.2.2 nathanw * 2. Redistributions in binary form must reproduce the above copyright
16 1.1.2.2 nathanw * notice, this list of conditions and the following disclaimer in the
17 1.1.2.2 nathanw * documentation and/or other materials provided with the distribution.
18 1.1.2.2 nathanw * 3. All advertising materials mentioning features or use of this software
19 1.1.2.2 nathanw * must display the following acknowledgement:
20 1.1.2.2 nathanw * This product includes software developed by the NetBSD
21 1.1.2.2 nathanw * Foundation, Inc. and its contributors.
22 1.1.2.2 nathanw * 4. Neither the name of The NetBSD Foundation nor the names of its
23 1.1.2.2 nathanw * contributors may be used to endorse or promote products derived
24 1.1.2.2 nathanw * from this software without specific prior written permission.
25 1.1.2.2 nathanw *
26 1.1.2.2 nathanw * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
27 1.1.2.2 nathanw * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
28 1.1.2.2 nathanw * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
29 1.1.2.2 nathanw * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
30 1.1.2.2 nathanw * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
31 1.1.2.2 nathanw * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
32 1.1.2.2 nathanw * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
33 1.1.2.2 nathanw * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
34 1.1.2.2 nathanw * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
35 1.1.2.2 nathanw * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
36 1.1.2.2 nathanw * POSSIBILITY OF SUCH DAMAGE.
37 1.1.2.2 nathanw */
38 1.1.2.2 nathanw
39 1.1.2.2 nathanw /*
40 1.1.2.2 nathanw * Copyright (c) 1996-2000 Distributed Processing Technology Corporation
41 1.1.2.2 nathanw * Copyright (c) 2000 Adaptec Corporation
42 1.1.2.2 nathanw * All rights reserved.
43 1.1.2.2 nathanw *
44 1.1.2.2 nathanw * TERMS AND CONDITIONS OF USE
45 1.1.2.2 nathanw *
46 1.1.2.2 nathanw * Redistribution and use in source form, with or without modification, are
47 1.1.2.2 nathanw * permitted provided that redistributions of source code must retain the
48 1.1.2.2 nathanw * above copyright notice, this list of conditions and the following disclaimer.
49 1.1.2.2 nathanw *
50 1.1.2.2 nathanw * This software is provided `as is' by Adaptec and any express or implied
51 1.1.2.2 nathanw * warranties, including, but not limited to, the implied warranties of
52 1.1.2.2 nathanw * merchantability and fitness for a particular purpose, are disclaimed. In no
53 1.1.2.2 nathanw * event shall Adaptec be liable for any direct, indirect, incidental, special,
54 1.1.2.2 nathanw * exemplary or consequential damages (including, but not limited to,
55 1.1.2.2 nathanw * procurement of substitute goods or services; loss of use, data, or profits;
56 1.1.2.2 nathanw * or business interruptions) however caused and on any theory of liability,
57 1.1.2.2 nathanw * whether in contract, strict liability, or tort (including negligence or
58 1.1.2.2 nathanw * otherwise) arising in any way out of the use of this driver software, even
59 1.1.2.2 nathanw * if advised of the possibility of such damage.
60 1.1.2.2 nathanw */
61 1.1.2.2 nathanw
62 1.1.2.2 nathanw /*
63 1.1.2.2 nathanw * Adaptec/DPT I2O control interface.
64 1.1.2.2 nathanw */
65 1.1.2.2 nathanw
66 1.1.2.4 nathanw #include <sys/cdefs.h>
67 1.1.2.5 nathanw __KERNEL_RCSID(0, "$NetBSD: dpti.c,v 1.1.2.5 2002/06/20 03:44:24 nathanw Exp $");
68 1.1.2.4 nathanw
69 1.1.2.2 nathanw #include "opt_i2o.h"
70 1.1.2.2 nathanw
71 1.1.2.2 nathanw #include <sys/param.h>
72 1.1.2.2 nathanw #include <sys/systm.h>
73 1.1.2.2 nathanw #include <sys/kernel.h>
74 1.1.2.2 nathanw #include <sys/device.h>
75 1.1.2.2 nathanw #include <sys/queue.h>
76 1.1.2.2 nathanw #include <sys/proc.h>
77 1.1.2.2 nathanw #include <sys/endian.h>
78 1.1.2.2 nathanw #include <sys/malloc.h>
79 1.1.2.2 nathanw #include <sys/conf.h>
80 1.1.2.2 nathanw #include <sys/ioctl.h>
81 1.1.2.2 nathanw
82 1.1.2.3 nathanw #include <uvm/uvm_extern.h>
83 1.1.2.3 nathanw
84 1.1.2.2 nathanw #include <machine/bus.h>
85 1.1.2.3 nathanw #ifdef i386
86 1.1.2.3 nathanw #include <machine/pio.h>
87 1.1.2.3 nathanw #endif
88 1.1.2.2 nathanw
89 1.1.2.2 nathanw #include <dev/i2o/i2o.h>
90 1.1.2.2 nathanw #include <dev/i2o/i2odpt.h>
91 1.1.2.2 nathanw #include <dev/i2o/iopio.h>
92 1.1.2.2 nathanw #include <dev/i2o/iopvar.h>
93 1.1.2.2 nathanw #include <dev/i2o/dptivar.h>
94 1.1.2.2 nathanw
95 1.1.2.2 nathanw #ifdef I2ODEBUG
96 1.1.2.2 nathanw #define DPRINTF(x) printf x
97 1.1.2.2 nathanw #else
98 1.1.2.2 nathanw #define DPRINTF(x)
99 1.1.2.2 nathanw #endif
100 1.1.2.2 nathanw
101 1.1.2.2 nathanw static struct dpt_sig dpti_sig = {
102 1.1.2.3 nathanw { 'd', 'P', 't', 'S', 'i', 'G'},
103 1.1.2.3 nathanw SIG_VERSION,
104 1.1.2.3 nathanw #if defined(i386)
105 1.1.2.3 nathanw PROC_INTEL,
106 1.1.2.3 nathanw #elif defined(powerpc)
107 1.1.2.3 nathanw PROC_POWERPC,
108 1.1.2.3 nathanw #elif defined(alpha)
109 1.1.2.3 nathanw PROC_ALPHA,
110 1.1.2.5 nathanw #elif defined(__mips__)
111 1.1.2.3 nathanw PROC_MIPS,
112 1.1.2.3 nathanw #elif defined(sparc64)
113 1.1.2.3 nathanw PROC_ULTRASPARC,
114 1.1.2.3 nathanw #endif
115 1.1.2.3 nathanw #if defined(i386)
116 1.1.2.3 nathanw PROC_386 | PROC_486 | PROC_PENTIUM | PROC_SEXIUM,
117 1.1.2.3 nathanw #else
118 1.1.2.3 nathanw 0,
119 1.1.2.3 nathanw #endif
120 1.1.2.3 nathanw FT_HBADRVR,
121 1.1.2.3 nathanw 0,
122 1.1.2.3 nathanw OEM_DPT,
123 1.1.2.3 nathanw OS_FREE_BSD, /* XXX */
124 1.1.2.3 nathanw CAP_ABOVE16MB,
125 1.1.2.3 nathanw DEV_ALL,
126 1.1.2.2 nathanw ADF_ALL_SC5,
127 1.1.2.3 nathanw 0,
128 1.1.2.3 nathanw 0,
129 1.1.2.3 nathanw DPTI_VERSION,
130 1.1.2.3 nathanw DPTI_REVISION,
131 1.1.2.3 nathanw DPTI_SUBREVISION,
132 1.1.2.3 nathanw DPTI_MONTH,
133 1.1.2.3 nathanw DPTI_DAY,
134 1.1.2.3 nathanw DPTI_YEAR,
135 1.1.2.3 nathanw "" /* Will be filled later */
136 1.1.2.2 nathanw };
137 1.1.2.2 nathanw
138 1.1.2.2 nathanw void dpti_attach(struct device *, struct device *, void *);
139 1.1.2.2 nathanw int dpti_blinkled(struct dpti_softc *);
140 1.1.2.2 nathanw int dpti_ctlrinfo(struct dpti_softc *, u_long, caddr_t);
141 1.1.2.2 nathanw int dpti_match(struct device *, struct cfdata *, void *);
142 1.1.2.2 nathanw int dpti_passthrough(struct dpti_softc *, caddr_t, struct proc *);
143 1.1.2.2 nathanw int dpti_sysinfo(struct dpti_softc *, u_long, caddr_t);
144 1.1.2.2 nathanw
145 1.1.2.2 nathanw cdev_decl(dpti);
146 1.1.2.2 nathanw
147 1.1.2.2 nathanw extern struct cfdriver dpti_cd;
148 1.1.2.2 nathanw
149 1.1.2.2 nathanw struct cfattach dpti_ca = {
150 1.1.2.2 nathanw sizeof(struct dpti_softc), dpti_match, dpti_attach
151 1.1.2.2 nathanw };
152 1.1.2.2 nathanw
153 1.1.2.2 nathanw int
154 1.1.2.2 nathanw dpti_match(struct device *parent, struct cfdata *match, void *aux)
155 1.1.2.2 nathanw {
156 1.1.2.2 nathanw struct iop_attach_args *ia;
157 1.1.2.2 nathanw struct iop_softc *iop;
158 1.1.2.2 nathanw
159 1.1.2.2 nathanw ia = aux;
160 1.1.2.2 nathanw iop = (struct iop_softc *)parent;
161 1.1.2.2 nathanw
162 1.1.2.2 nathanw if (ia->ia_class != I2O_CLASS_ANY || ia->ia_tid != I2O_TID_IOP)
163 1.1.2.2 nathanw return (0);
164 1.1.2.2 nathanw
165 1.1.2.2 nathanw if (le16toh(iop->sc_status.orgid) != I2O_ORG_DPT)
166 1.1.2.2 nathanw return (0);
167 1.1.2.2 nathanw
168 1.1.2.2 nathanw return (1);
169 1.1.2.2 nathanw }
170 1.1.2.2 nathanw
171 1.1.2.2 nathanw void
172 1.1.2.2 nathanw dpti_attach(struct device *parent, struct device *self, void *aux)
173 1.1.2.2 nathanw {
174 1.1.2.2 nathanw struct iop_softc *iop;
175 1.1.2.2 nathanw struct dpti_softc *sc;
176 1.1.2.2 nathanw struct {
177 1.1.2.2 nathanw struct i2o_param_op_results pr;
178 1.1.2.2 nathanw struct i2o_param_read_results prr;
179 1.1.2.2 nathanw struct i2o_dpt_param_exec_iop_buffers dib;
180 1.1.2.2 nathanw } __attribute__ ((__packed__)) param;
181 1.1.2.2 nathanw int rv;
182 1.1.2.2 nathanw
183 1.1.2.2 nathanw sc = (struct dpti_softc *)self;
184 1.1.2.2 nathanw iop = (struct iop_softc *)parent;
185 1.1.2.2 nathanw
186 1.1.2.2 nathanw /*
187 1.1.2.2 nathanw * Tell the world what we are. The description in the signature
188 1.1.2.2 nathanw * must be no more than 46 bytes long (see dptivar.h).
189 1.1.2.2 nathanw */
190 1.1.2.3 nathanw printf(": DPT/Adaptec RAID management interface\n");
191 1.1.2.2 nathanw sprintf(dpti_sig.dsDescription, "NetBSD %s I2O OSM", osrelease);
192 1.1.2.2 nathanw
193 1.1.2.2 nathanw rv = iop_field_get_all(iop, I2O_TID_IOP,
194 1.1.2.2 nathanw I2O_DPT_PARAM_EXEC_IOP_BUFFERS, ¶m,
195 1.1.2.2 nathanw sizeof(param), NULL);
196 1.1.2.2 nathanw if (rv != 0)
197 1.1.2.2 nathanw return;
198 1.1.2.2 nathanw
199 1.1.2.2 nathanw sc->sc_blinkled = le32toh(param.dib.serialoutputoff) + 8;
200 1.1.2.2 nathanw }
201 1.1.2.2 nathanw
202 1.1.2.2 nathanw int
203 1.1.2.2 nathanw dptiopen(dev_t dev, int flag, int mode, struct proc *p)
204 1.1.2.2 nathanw {
205 1.1.2.2 nathanw
206 1.1.2.2 nathanw if (securelevel > 1)
207 1.1.2.2 nathanw return (EPERM);
208 1.1.2.2 nathanw if (device_lookup(&dpti_cd, minor(dev)) == NULL)
209 1.1.2.2 nathanw return (ENXIO);
210 1.1.2.2 nathanw
211 1.1.2.2 nathanw return (0);
212 1.1.2.2 nathanw }
213 1.1.2.2 nathanw
214 1.1.2.2 nathanw int
215 1.1.2.2 nathanw dpticlose(dev_t dev, int flag, int mode, struct proc *p)
216 1.1.2.2 nathanw {
217 1.1.2.2 nathanw
218 1.1.2.2 nathanw return (0);
219 1.1.2.2 nathanw }
220 1.1.2.2 nathanw
221 1.1.2.2 nathanw int
222 1.1.2.2 nathanw dptiioctl(dev_t dev, u_long cmd, caddr_t data, int flag, struct proc *p)
223 1.1.2.2 nathanw {
224 1.1.2.2 nathanw struct iop_softc *iop;
225 1.1.2.2 nathanw struct dpti_softc *sc;
226 1.1.2.2 nathanw struct ioctl_pt *pt;
227 1.1.2.3 nathanw int i, size, rv;
228 1.1.2.2 nathanw
229 1.1.2.2 nathanw sc = device_lookup(&dpti_cd, minor(dev));
230 1.1.2.2 nathanw iop = (struct iop_softc *)sc->sc_dv.dv_parent;
231 1.1.2.2 nathanw
232 1.1.2.2 nathanw /*
233 1.1.2.2 nathanw * Currently, we only take ioctls passed down from the Linux
234 1.1.2.2 nathanw * emulation layer.
235 1.1.2.2 nathanw */
236 1.1.2.2 nathanw if (cmd == PTIOCLINUX) {
237 1.1.2.2 nathanw pt = (struct ioctl_pt *)data;
238 1.1.2.2 nathanw cmd = pt->com;
239 1.1.2.2 nathanw data = pt->data;
240 1.1.2.2 nathanw } else
241 1.1.2.2 nathanw return (ENOTTY);
242 1.1.2.2 nathanw
243 1.1.2.2 nathanw size = IOCPARM_LEN(cmd);
244 1.1.2.2 nathanw
245 1.1.2.2 nathanw switch (cmd & 0xffff) {
246 1.1.2.2 nathanw case DPT_SIGNATURE:
247 1.1.2.2 nathanw if (size > sizeof(dpti_sig))
248 1.1.2.2 nathanw size = sizeof(dpti_sig);
249 1.1.2.2 nathanw memcpy(data, &dpti_sig, size);
250 1.1.2.2 nathanw return (0);
251 1.1.2.2 nathanw
252 1.1.2.2 nathanw case DPT_CTRLINFO:
253 1.1.2.2 nathanw return (dpti_ctlrinfo(sc, cmd, data));
254 1.1.2.2 nathanw
255 1.1.2.2 nathanw case DPT_SYSINFO:
256 1.1.2.2 nathanw return (dpti_sysinfo(sc, cmd, data));
257 1.1.2.2 nathanw
258 1.1.2.2 nathanw case DPT_BLINKLED:
259 1.1.2.2 nathanw if ((i = dpti_blinkled(sc)) == -1)
260 1.1.2.2 nathanw i = 0;
261 1.1.2.2 nathanw
262 1.1.2.2 nathanw if (size == 0)
263 1.1.2.2 nathanw return (copyout(&i, *(caddr_t *)data, sizeof(i)));
264 1.1.2.2 nathanw
265 1.1.2.2 nathanw *(int *)data = i;
266 1.1.2.2 nathanw return (0);
267 1.1.2.2 nathanw
268 1.1.2.2 nathanw case DPT_TARGET_BUSY:
269 1.1.2.2 nathanw /*
270 1.1.2.2 nathanw * XXX This is here to stop linux_machdepioctl() from
271 1.1.2.2 nathanw * whining about an unknown ioctl. Really, it should be
272 1.1.2.2 nathanw * implemented.
273 1.1.2.2 nathanw */
274 1.1.2.2 nathanw return (EIO);
275 1.1.2.2 nathanw
276 1.1.2.2 nathanw case DPT_I2OUSRCMD:
277 1.1.2.3 nathanw if (sc->sc_nactive++ >= 2)
278 1.1.2.3 nathanw tsleep(&sc->sc_nactive, PRIBIO, "dptislp", 0);
279 1.1.2.3 nathanw
280 1.1.2.3 nathanw rv = dpti_passthrough(sc, data, p);
281 1.1.2.3 nathanw
282 1.1.2.3 nathanw sc->sc_nactive--;
283 1.1.2.3 nathanw wakeup_one(&sc->sc_nactive);
284 1.1.2.3 nathanw return (rv);
285 1.1.2.2 nathanw
286 1.1.2.2 nathanw case DPT_I2ORESETCMD:
287 1.1.2.2 nathanw printf("%s: I2ORESETCMD not implemented\n",
288 1.1.2.2 nathanw sc->sc_dv.dv_xname);
289 1.1.2.3 nathanw return (EOPNOTSUPP);
290 1.1.2.2 nathanw
291 1.1.2.2 nathanw case DPT_I2ORESCANCMD:
292 1.1.2.2 nathanw return (iop_reconfigure(iop, 0));
293 1.1.2.2 nathanw
294 1.1.2.2 nathanw default:
295 1.1.2.2 nathanw return (ENOTTY);
296 1.1.2.2 nathanw }
297 1.1.2.2 nathanw }
298 1.1.2.2 nathanw
299 1.1.2.2 nathanw int
300 1.1.2.2 nathanw dpti_blinkled(struct dpti_softc *sc)
301 1.1.2.2 nathanw {
302 1.1.2.2 nathanw struct iop_softc *iop;
303 1.1.2.2 nathanw u_int v;
304 1.1.2.2 nathanw
305 1.1.2.2 nathanw iop = (struct iop_softc *)sc->sc_dv.dv_parent;
306 1.1.2.2 nathanw
307 1.1.2.2 nathanw v = bus_space_read_1(iop->sc_iot, iop->sc_ioh, sc->sc_blinkled + 0);
308 1.1.2.2 nathanw if (v == 0xbc) {
309 1.1.2.2 nathanw v = bus_space_read_1(iop->sc_iot, iop->sc_ioh,
310 1.1.2.2 nathanw sc->sc_blinkled + 1);
311 1.1.2.2 nathanw return (v);
312 1.1.2.2 nathanw }
313 1.1.2.2 nathanw
314 1.1.2.2 nathanw return (-1);
315 1.1.2.2 nathanw }
316 1.1.2.2 nathanw
317 1.1.2.2 nathanw int
318 1.1.2.2 nathanw dpti_ctlrinfo(struct dpti_softc *sc, u_long cmd, caddr_t data)
319 1.1.2.2 nathanw {
320 1.1.2.3 nathanw struct dpt_ctlrinfo info;
321 1.1.2.2 nathanw struct iop_softc *iop;
322 1.1.2.2 nathanw int rv, i;
323 1.1.2.2 nathanw
324 1.1.2.2 nathanw iop = (struct iop_softc *)sc->sc_dv.dv_parent;
325 1.1.2.2 nathanw
326 1.1.2.3 nathanw memset(&info, 0, sizeof(info));
327 1.1.2.2 nathanw
328 1.1.2.3 nathanw info.length = sizeof(info) - sizeof(u_int16_t);
329 1.1.2.3 nathanw info.drvrHBAnum = sc->sc_dv.dv_unit;
330 1.1.2.3 nathanw info.baseAddr = iop->sc_memaddr;
331 1.1.2.2 nathanw if ((i = dpti_blinkled(sc)) == -1)
332 1.1.2.2 nathanw i = 0;
333 1.1.2.3 nathanw info.blinkState = i;
334 1.1.2.3 nathanw info.pciBusNum = iop->sc_pcibus;
335 1.1.2.3 nathanw info.pciDeviceNum = iop->sc_pcidev;
336 1.1.2.3 nathanw info.hbaFlags = FLG_OSD_PCI_VALID | FLG_OSD_DMA | FLG_OSD_I2O;
337 1.1.2.3 nathanw info.Interrupt = 10; /* XXX */
338 1.1.2.2 nathanw
339 1.1.2.2 nathanw if (IOCPARM_LEN(cmd) > sizeof(*data)) {
340 1.1.2.3 nathanw memcpy(data, &info, min(sizeof(info), IOCPARM_LEN(cmd)));
341 1.1.2.2 nathanw rv = 0;
342 1.1.2.2 nathanw } else
343 1.1.2.3 nathanw rv = copyout(&info, *(caddr_t *)data, sizeof(info));
344 1.1.2.2 nathanw
345 1.1.2.2 nathanw return (rv);
346 1.1.2.2 nathanw }
347 1.1.2.2 nathanw
348 1.1.2.2 nathanw int
349 1.1.2.2 nathanw dpti_sysinfo(struct dpti_softc *sc, u_long cmd, caddr_t data)
350 1.1.2.2 nathanw {
351 1.1.2.3 nathanw struct dpt_sysinfo info;
352 1.1.2.3 nathanw int rv;
353 1.1.2.3 nathanw #ifdef i386
354 1.1.2.3 nathanw int i, j;
355 1.1.2.3 nathanw #endif
356 1.1.2.3 nathanw
357 1.1.2.3 nathanw memset(&info, 0, sizeof(info));
358 1.1.2.3 nathanw
359 1.1.2.3 nathanw #ifdef i386
360 1.1.2.3 nathanw outb (0x70, 0x12);
361 1.1.2.3 nathanw i = inb(0x71);
362 1.1.2.3 nathanw j = i >> 4;
363 1.1.2.3 nathanw if (i == 0x0f) {
364 1.1.2.3 nathanw outb (0x70, 0x19);
365 1.1.2.3 nathanw j = inb (0x71);
366 1.1.2.3 nathanw }
367 1.1.2.3 nathanw info.drive0CMOS = j;
368 1.1.2.3 nathanw
369 1.1.2.3 nathanw j = i & 0x0f;
370 1.1.2.3 nathanw if (i == 0x0f) {
371 1.1.2.3 nathanw outb (0x70, 0x1a);
372 1.1.2.3 nathanw j = inb (0x71);
373 1.1.2.3 nathanw }
374 1.1.2.3 nathanw info.drive1CMOS = j;
375 1.1.2.3 nathanw info.processorFamily = dpti_sig.dsProcessorFamily;
376 1.1.2.3 nathanw
377 1.1.2.3 nathanw /*
378 1.1.2.3 nathanw * Get the conventional memory size from CMOS.
379 1.1.2.3 nathanw */
380 1.1.2.3 nathanw outb(0x70, 0x16);
381 1.1.2.3 nathanw j = inb(0x71);
382 1.1.2.3 nathanw j <<= 8;
383 1.1.2.3 nathanw outb(0x70, 0x15);
384 1.1.2.3 nathanw j |= inb(0x71);
385 1.1.2.3 nathanw info.conventionalMemSize = j;
386 1.1.2.3 nathanw
387 1.1.2.3 nathanw /*
388 1.1.2.3 nathanw * Get the extended memory size from CMOS.
389 1.1.2.3 nathanw */
390 1.1.2.3 nathanw outb(0x70, 0x31);
391 1.1.2.3 nathanw j = inb(0x71);
392 1.1.2.3 nathanw j <<= 8;
393 1.1.2.3 nathanw outb(0x70, 0x30);
394 1.1.2.3 nathanw j |= inb(0x71);
395 1.1.2.3 nathanw info.extendedMemSize = j;
396 1.1.2.3 nathanw
397 1.1.2.3 nathanw switch (cpu_class) {
398 1.1.2.3 nathanw case CPUCLASS_386:
399 1.1.2.3 nathanw info.processorType = PROC_386;
400 1.1.2.3 nathanw break;
401 1.1.2.3 nathanw case CPUCLASS_486:
402 1.1.2.3 nathanw info.processorType = PROC_486;
403 1.1.2.3 nathanw break;
404 1.1.2.3 nathanw case CPUCLASS_586:
405 1.1.2.3 nathanw info.processorType = PROC_PENTIUM;
406 1.1.2.3 nathanw break;
407 1.1.2.3 nathanw case CPUCLASS_686:
408 1.1.2.3 nathanw default:
409 1.1.2.3 nathanw info.processorType = PROC_SEXIUM;
410 1.1.2.3 nathanw break;
411 1.1.2.3 nathanw }
412 1.1.2.3 nathanw
413 1.1.2.3 nathanw info.flags = SI_CMOS_Valid | SI_BusTypeValid |
414 1.1.2.3 nathanw SI_MemorySizeValid | SI_NO_SmartROM;
415 1.1.2.3 nathanw #else
416 1.1.2.3 nathanw info.flags = SI_BusTypeValid | SI_NO_SmartROM;
417 1.1.2.3 nathanw #endif
418 1.1.2.3 nathanw
419 1.1.2.3 nathanw info.busType = SI_PCI_BUS;
420 1.1.2.2 nathanw
421 1.1.2.2 nathanw /*
422 1.1.2.3 nathanw * Copy out the info structure to the user.
423 1.1.2.2 nathanw */
424 1.1.2.3 nathanw if (IOCPARM_LEN(cmd) > sizeof(*data)) {
425 1.1.2.3 nathanw memcpy(data, &info, min(sizeof(info), IOCPARM_LEN(cmd)));
426 1.1.2.3 nathanw rv = 0;
427 1.1.2.3 nathanw } else
428 1.1.2.3 nathanw rv = copyout(&info, *(caddr_t *)data, sizeof(info));
429 1.1.2.3 nathanw
430 1.1.2.3 nathanw return (rv);
431 1.1.2.2 nathanw }
432 1.1.2.2 nathanw
433 1.1.2.2 nathanw int
434 1.1.2.2 nathanw dpti_passthrough(struct dpti_softc *sc, caddr_t data, struct proc *proc)
435 1.1.2.2 nathanw {
436 1.1.2.2 nathanw struct iop_softc *iop;
437 1.1.2.2 nathanw struct i2o_msg mh, *mf;
438 1.1.2.2 nathanw struct i2o_reply rh;
439 1.1.2.2 nathanw struct iop_msg *im;
440 1.1.2.2 nathanw struct dpti_ptbuf bufs[IOP_MAX_MSG_XFERS];
441 1.1.2.2 nathanw u_int32_t mbtmp[IOP_MAX_MSG_SIZE / sizeof(u_int32_t)];
442 1.1.2.2 nathanw u_int32_t rbtmp[IOP_MAX_MSG_SIZE / sizeof(u_int32_t)];
443 1.1.2.3 nathanw int rv, msgsize, repsize, sgoff, i, mapped, nbuf, nfrag, j, sz;
444 1.1.2.3 nathanw u_int32_t *p, *pmax, *pstart;
445 1.1.2.2 nathanw
446 1.1.2.2 nathanw iop = (struct iop_softc *)sc->sc_dv.dv_parent;
447 1.1.2.3 nathanw im = NULL;
448 1.1.2.2 nathanw
449 1.1.2.2 nathanw if ((rv = dpti_blinkled(sc)) != -1) {
450 1.1.2.2 nathanw if (rv != 0) {
451 1.1.2.2 nathanw printf("%s: adapter blinkled = 0x%02x\n",
452 1.1.2.2 nathanw sc->sc_dv.dv_xname, rv);
453 1.1.2.2 nathanw return (EIO);
454 1.1.2.2 nathanw }
455 1.1.2.2 nathanw }
456 1.1.2.2 nathanw
457 1.1.2.2 nathanw /*
458 1.1.2.2 nathanw * Copy in the message frame header and determine the size of the
459 1.1.2.2 nathanw * full message frame.
460 1.1.2.2 nathanw */
461 1.1.2.2 nathanw if ((rv = copyin(data, &mh, sizeof(mh))) != 0) {
462 1.1.2.2 nathanw DPRINTF(("%s: message copyin failed\n",
463 1.1.2.2 nathanw sc->sc_dv.dv_xname));
464 1.1.2.2 nathanw return (rv);
465 1.1.2.2 nathanw }
466 1.1.2.2 nathanw
467 1.1.2.2 nathanw msgsize = (mh.msgflags >> 14) & ~3;
468 1.1.2.2 nathanw if (msgsize < sizeof(mh) || msgsize >= IOP_MAX_MSG_SIZE) {
469 1.1.2.2 nathanw DPRINTF(("%s: bad message frame size\n",
470 1.1.2.2 nathanw sc->sc_dv.dv_xname));
471 1.1.2.2 nathanw return (EINVAL);
472 1.1.2.2 nathanw }
473 1.1.2.2 nathanw
474 1.1.2.2 nathanw /*
475 1.1.2.2 nathanw * Handle special commands.
476 1.1.2.2 nathanw */
477 1.1.2.2 nathanw switch (mh.msgfunc >> 24) {
478 1.1.2.2 nathanw case I2O_EXEC_IOP_RESET:
479 1.1.2.3 nathanw printf("%s: I2O_EXEC_IOP_RESET not implemented\n",
480 1.1.2.2 nathanw sc->sc_dv.dv_xname);
481 1.1.2.3 nathanw return (EOPNOTSUPP);
482 1.1.2.2 nathanw
483 1.1.2.2 nathanw case I2O_EXEC_OUTBOUND_INIT:
484 1.1.2.3 nathanw printf("%s: I2O_EXEC_OUTBOUND_INIT not implemented\n",
485 1.1.2.2 nathanw sc->sc_dv.dv_xname);
486 1.1.2.3 nathanw return (EOPNOTSUPP);
487 1.1.2.2 nathanw
488 1.1.2.2 nathanw case I2O_EXEC_SYS_TAB_SET:
489 1.1.2.3 nathanw printf("%s: I2O_EXEC_SYS_TAB_SET not implemented\n",
490 1.1.2.2 nathanw sc->sc_dv.dv_xname);
491 1.1.2.3 nathanw return (EOPNOTSUPP);
492 1.1.2.2 nathanw
493 1.1.2.2 nathanw case I2O_EXEC_STATUS_GET:
494 1.1.2.3 nathanw if ((rv = iop_status_get(iop, 0)) == 0)
495 1.1.2.3 nathanw rv = copyout(&iop->sc_status, data + msgsize,
496 1.1.2.3 nathanw sizeof(iop->sc_status));
497 1.1.2.2 nathanw return (rv);
498 1.1.2.2 nathanw }
499 1.1.2.2 nathanw
500 1.1.2.2 nathanw /*
501 1.1.2.2 nathanw * Copy in the full message frame.
502 1.1.2.2 nathanw */
503 1.1.2.2 nathanw if ((rv = copyin(data, mbtmp, msgsize)) != 0) {
504 1.1.2.2 nathanw DPRINTF(("%s: full message copyin failed\n",
505 1.1.2.2 nathanw sc->sc_dv.dv_xname));
506 1.1.2.2 nathanw return (rv);
507 1.1.2.2 nathanw }
508 1.1.2.2 nathanw
509 1.1.2.2 nathanw /*
510 1.1.2.2 nathanw * Determine the size of the reply frame, and copy it in.
511 1.1.2.2 nathanw */
512 1.1.2.2 nathanw if ((rv = copyin(data + msgsize, &rh, sizeof(rh))) != 0) {
513 1.1.2.2 nathanw DPRINTF(("%s: reply copyin failed\n",
514 1.1.2.2 nathanw sc->sc_dv.dv_xname));
515 1.1.2.2 nathanw return (rv);
516 1.1.2.2 nathanw }
517 1.1.2.2 nathanw
518 1.1.2.2 nathanw repsize = (rh.msgflags >> 14) & ~3;
519 1.1.2.2 nathanw if (repsize < sizeof(rh) || repsize >= IOP_MAX_MSG_SIZE) {
520 1.1.2.2 nathanw DPRINTF(("%s: bad reply header size\n",
521 1.1.2.2 nathanw sc->sc_dv.dv_xname));
522 1.1.2.2 nathanw return (EINVAL);
523 1.1.2.2 nathanw }
524 1.1.2.2 nathanw
525 1.1.2.2 nathanw if ((rv = copyin(data + msgsize, rbtmp, repsize)) != 0) {
526 1.1.2.2 nathanw DPRINTF(("%s: reply too large\n", sc->sc_dv.dv_xname));
527 1.1.2.2 nathanw return (rv);
528 1.1.2.2 nathanw }
529 1.1.2.2 nathanw
530 1.1.2.2 nathanw /*
531 1.1.2.2 nathanw * If the message has a scatter gather list, it must be comprised of
532 1.1.2.2 nathanw * simple elements. If any one transfer contains multiple segments,
533 1.1.2.2 nathanw * we allocate a temporary buffer for it; otherwise, the buffer will
534 1.1.2.3 nathanw * be mapped directly.
535 1.1.2.2 nathanw */
536 1.1.2.2 nathanw if ((sgoff = ((mh.msgflags >> 4) & 15)) != 0) {
537 1.1.2.2 nathanw if ((sgoff + 2) > (msgsize >> 2)) {
538 1.1.2.2 nathanw DPRINTF(("%s: invalid message size fields\n",
539 1.1.2.2 nathanw sc->sc_dv.dv_xname));
540 1.1.2.2 nathanw return (EINVAL);
541 1.1.2.2 nathanw }
542 1.1.2.3 nathanw
543 1.1.2.3 nathanw memset(bufs, 0, sizeof(bufs));
544 1.1.2.2 nathanw } else
545 1.1.2.2 nathanw nbuf = -1;
546 1.1.2.2 nathanw
547 1.1.2.3 nathanw rv = EINVAL;
548 1.1.2.3 nathanw
549 1.1.2.2 nathanw if (sgoff != 0) {
550 1.1.2.2 nathanw p = mbtmp + sgoff;
551 1.1.2.3 nathanw pmax = mbtmp + (msgsize >> 2) - 2;
552 1.1.2.2 nathanw
553 1.1.2.3 nathanw for (nbuf = 0; nbuf < IOP_MAX_MSG_XFERS; nbuf++, p += 2) {
554 1.1.2.3 nathanw if (p > pmax) {
555 1.1.2.2 nathanw DPRINTF(("%s: invalid SGL (1)\n",
556 1.1.2.2 nathanw sc->sc_dv.dv_xname));
557 1.1.2.3 nathanw goto bad;
558 1.1.2.2 nathanw }
559 1.1.2.2 nathanw
560 1.1.2.2 nathanw if ((p[0] & 0x30000000) != I2O_SGL_SIMPLE) {
561 1.1.2.2 nathanw DPRINTF(("%s: invalid SGL (2)\n",
562 1.1.2.2 nathanw sc->sc_dv.dv_xname));
563 1.1.2.3 nathanw goto bad;
564 1.1.2.2 nathanw }
565 1.1.2.2 nathanw
566 1.1.2.2 nathanw bufs[nbuf].db_out = (p[0] & I2O_SGL_DATA_OUT) != 0;
567 1.1.2.3 nathanw bufs[nbuf].db_ptr = NULL;
568 1.1.2.2 nathanw
569 1.1.2.2 nathanw if ((p[0] & I2O_SGL_END_BUFFER) != 0) {
570 1.1.2.2 nathanw if ((p[0] & 0x00ffffff) > IOP_MAX_XFER) {
571 1.1.2.2 nathanw DPRINTF(("%s: buffer too large\n",
572 1.1.2.2 nathanw sc->sc_dv.dv_xname));
573 1.1.2.3 nathanw goto bad;
574 1.1.2.2 nathanw }
575 1.1.2.2 nathanw
576 1.1.2.2 nathanw bufs[nbuf].db_ptr = (caddr_t)p[1];
577 1.1.2.2 nathanw bufs[nbuf].db_proc = proc;
578 1.1.2.2 nathanw bufs[nbuf].db_size = p[0] & 0x00ffffff;
579 1.1.2.2 nathanw
580 1.1.2.2 nathanw if ((p[0] & I2O_SGL_END) != 0)
581 1.1.2.2 nathanw break;
582 1.1.2.2 nathanw
583 1.1.2.2 nathanw continue;
584 1.1.2.2 nathanw }
585 1.1.2.2 nathanw
586 1.1.2.3 nathanw /*
587 1.1.2.3 nathanw * The buffer has multiple segments. Determine the
588 1.1.2.3 nathanw * total size.
589 1.1.2.3 nathanw */
590 1.1.2.3 nathanw nfrag = 0;
591 1.1.2.3 nathanw sz = 0;
592 1.1.2.3 nathanw for (pstart = p; p <= pmax; p += 2) {
593 1.1.2.3 nathanw if (nfrag == DPTI_MAX_SEGS) {
594 1.1.2.3 nathanw DPRINTF(("%s: too many segments\n",
595 1.1.2.3 nathanw sc->sc_dv.dv_xname));
596 1.1.2.3 nathanw goto bad;
597 1.1.2.3 nathanw }
598 1.1.2.3 nathanw
599 1.1.2.3 nathanw bufs[nbuf].db_frags[nfrag].iov_len =
600 1.1.2.3 nathanw p[0] & 0x00ffffff;
601 1.1.2.3 nathanw bufs[nbuf].db_frags[nfrag].iov_base =
602 1.1.2.3 nathanw (void *)p[1];
603 1.1.2.3 nathanw
604 1.1.2.3 nathanw sz += p[0] & 0x00ffffff;
605 1.1.2.3 nathanw nfrag++;
606 1.1.2.3 nathanw
607 1.1.2.3 nathanw if ((p[0] & I2O_SGL_END) != 0) {
608 1.1.2.3 nathanw if ((p[0] & I2O_SGL_END_BUFFER) == 0) {
609 1.1.2.3 nathanw DPRINTF((
610 1.1.2.3 nathanw "%s: invalid SGL (3)\n",
611 1.1.2.3 nathanw sc->sc_dv.dv_xname));
612 1.1.2.3 nathanw goto bad;
613 1.1.2.3 nathanw }
614 1.1.2.3 nathanw break;
615 1.1.2.3 nathanw }
616 1.1.2.3 nathanw if ((p[0] & I2O_SGL_END_BUFFER) != 0)
617 1.1.2.3 nathanw break;
618 1.1.2.3 nathanw }
619 1.1.2.3 nathanw bufs[nbuf].db_nfrag = nfrag;
620 1.1.2.3 nathanw
621 1.1.2.3 nathanw if (p > pmax) {
622 1.1.2.3 nathanw DPRINTF(("%s: invalid SGL (4)\n",
623 1.1.2.3 nathanw sc->sc_dv.dv_xname));
624 1.1.2.3 nathanw goto bad;
625 1.1.2.3 nathanw }
626 1.1.2.3 nathanw
627 1.1.2.3 nathanw if (sz > IOP_MAX_XFER) {
628 1.1.2.3 nathanw DPRINTF(("%s: buffer too large\n",
629 1.1.2.3 nathanw sc->sc_dv.dv_xname));
630 1.1.2.3 nathanw goto bad;
631 1.1.2.3 nathanw }
632 1.1.2.3 nathanw
633 1.1.2.3 nathanw bufs[nbuf].db_size = sz;
634 1.1.2.3 nathanw bufs[nbuf].db_ptr = malloc(sz, M_DEVBUF, M_WAITOK);
635 1.1.2.3 nathanw if (bufs[nbuf].db_ptr == NULL) {
636 1.1.2.3 nathanw DPRINTF(("%s: allocation failure\n",
637 1.1.2.3 nathanw sc->sc_dv.dv_xname));
638 1.1.2.3 nathanw rv = ENOMEM;
639 1.1.2.3 nathanw goto bad;
640 1.1.2.3 nathanw }
641 1.1.2.3 nathanw
642 1.1.2.3 nathanw for (i = 0, sz = 0; i < bufs[nbuf].db_nfrag; i++) {
643 1.1.2.3 nathanw rv = copyin(bufs[nbuf].db_frags[i].iov_base,
644 1.1.2.3 nathanw bufs[nbuf].db_ptr + sz,
645 1.1.2.3 nathanw bufs[nbuf].db_frags[i].iov_len);
646 1.1.2.3 nathanw if (rv != 0) {
647 1.1.2.3 nathanw DPRINTF(("%s: frag copyin\n",
648 1.1.2.3 nathanw sc->sc_dv.dv_xname));
649 1.1.2.3 nathanw goto bad;
650 1.1.2.3 nathanw }
651 1.1.2.3 nathanw sz += bufs[nbuf].db_frags[i].iov_len;
652 1.1.2.3 nathanw }
653 1.1.2.3 nathanw
654 1.1.2.3 nathanw if ((p[0] & I2O_SGL_END) != 0)
655 1.1.2.3 nathanw break;
656 1.1.2.2 nathanw }
657 1.1.2.2 nathanw
658 1.1.2.2 nathanw if (nbuf == IOP_MAX_MSG_XFERS) {
659 1.1.2.2 nathanw DPRINTF(("%s: too many transfers\n",
660 1.1.2.2 nathanw sc->sc_dv.dv_xname));
661 1.1.2.3 nathanw goto bad;
662 1.1.2.2 nathanw }
663 1.1.2.2 nathanw }
664 1.1.2.2 nathanw
665 1.1.2.2 nathanw /*
666 1.1.2.2 nathanw * Allocate a wrapper, and adjust the message header fields to
667 1.1.2.2 nathanw * indicate that no scatter-gather list is currently present.
668 1.1.2.2 nathanw */
669 1.1.2.3 nathanw mapped = 0;
670 1.1.2.3 nathanw
671 1.1.2.2 nathanw im = iop_msg_alloc(iop, IM_WAIT | IM_NOSTATUS);
672 1.1.2.2 nathanw im->im_rb = (struct i2o_reply *)rbtmp;
673 1.1.2.2 nathanw mf = (struct i2o_msg *)mbtmp;
674 1.1.2.2 nathanw mf->msgictx = IOP_ICTX;
675 1.1.2.2 nathanw mf->msgtctx = im->im_tctx;
676 1.1.2.2 nathanw
677 1.1.2.2 nathanw if (sgoff != 0)
678 1.1.2.2 nathanw mf->msgflags = (mf->msgflags & 0xff0f) | (sgoff << 16);
679 1.1.2.2 nathanw
680 1.1.2.2 nathanw /*
681 1.1.2.2 nathanw * Map the data transfer(s).
682 1.1.2.2 nathanw */
683 1.1.2.2 nathanw for (i = 0; i <= nbuf; i++) {
684 1.1.2.2 nathanw rv = iop_msg_map(iop, im, mbtmp, bufs[i].db_ptr,
685 1.1.2.2 nathanw bufs[i].db_size, bufs[i].db_out, bufs[i].db_proc);
686 1.1.2.2 nathanw if (rv != 0) {
687 1.1.2.3 nathanw DPRINTF(("%s: msg_map failed, rv = %d\n",
688 1.1.2.3 nathanw sc->sc_dv.dv_xname, rv));
689 1.1.2.2 nathanw goto bad;
690 1.1.2.2 nathanw }
691 1.1.2.2 nathanw mapped = 1;
692 1.1.2.2 nathanw }
693 1.1.2.2 nathanw
694 1.1.2.2 nathanw /*
695 1.1.2.2 nathanw * Start the command and sleep until it completes.
696 1.1.2.2 nathanw */
697 1.1.2.2 nathanw if ((rv = iop_msg_post(iop, im, mbtmp, 5*60*1000)) != 0)
698 1.1.2.2 nathanw goto bad;
699 1.1.2.2 nathanw
700 1.1.2.2 nathanw /*
701 1.1.2.2 nathanw * Copy out the reply frame.
702 1.1.2.2 nathanw */
703 1.1.2.2 nathanw if ((rv = copyout(rbtmp, data + msgsize, repsize)) != 0)
704 1.1.2.2 nathanw DPRINTF(("%s: reply copyout() failed\n",
705 1.1.2.2 nathanw sc->sc_dv.dv_xname));
706 1.1.2.2 nathanw
707 1.1.2.2 nathanw bad:
708 1.1.2.3 nathanw /*
709 1.1.2.3 nathanw * Free resources and return to the caller.
710 1.1.2.3 nathanw */
711 1.1.2.3 nathanw if (im != NULL) {
712 1.1.2.3 nathanw if (mapped)
713 1.1.2.3 nathanw iop_msg_unmap(iop, im);
714 1.1.2.3 nathanw iop_msg_free(iop, im);
715 1.1.2.3 nathanw }
716 1.1.2.3 nathanw
717 1.1.2.3 nathanw for (i = 0; i <= nbuf; i++) {
718 1.1.2.3 nathanw if (bufs[i].db_proc != NULL)
719 1.1.2.3 nathanw continue;
720 1.1.2.3 nathanw
721 1.1.2.3 nathanw if (!bufs[i].db_out && rv == 0) {
722 1.1.2.3 nathanw for (j = 0, sz = 0; j < bufs[i].db_nfrag; j++) {
723 1.1.2.3 nathanw rv = copyout(bufs[i].db_ptr + sz,
724 1.1.2.3 nathanw bufs[i].db_frags[j].iov_base,
725 1.1.2.3 nathanw bufs[i].db_frags[j].iov_len);
726 1.1.2.3 nathanw if (rv != 0)
727 1.1.2.3 nathanw break;
728 1.1.2.3 nathanw sz += bufs[i].db_frags[j].iov_len;
729 1.1.2.3 nathanw }
730 1.1.2.3 nathanw }
731 1.1.2.2 nathanw
732 1.1.2.3 nathanw if (bufs[i].db_ptr != NULL)
733 1.1.2.3 nathanw free(bufs[i].db_ptr, M_DEVBUF);
734 1.1.2.3 nathanw }
735 1.1.2.2 nathanw
736 1.1.2.2 nathanw return (rv);
737 1.1.2.2 nathanw }
738