ed_mca.c revision 1.2.2.2 1 1.2.2.2 bouyer /* $NetBSD: ed_mca.c,v 1.2.2.2 2001/04/21 17:48:52 bouyer Exp $ */
2 1.2.2.2 bouyer
3 1.2.2.2 bouyer /*
4 1.2.2.2 bouyer * Copyright (c) 2001 The NetBSD Foundation, Inc.
5 1.2.2.2 bouyer *
6 1.2.2.2 bouyer * This code is derived from software contributed to The NetBSD Foundation
7 1.2.2.2 bouyer * by Jaromir Dolecek.
8 1.2.2.2 bouyer *
9 1.2.2.2 bouyer * Redistribution and use in source and binary forms, with or without
10 1.2.2.2 bouyer * modification, are permitted provided that the following conditions
11 1.2.2.2 bouyer * are met:
12 1.2.2.2 bouyer * 1. Redistributions of source code must retain the above copyright
13 1.2.2.2 bouyer * notice, this list of conditions and the following disclaimer.
14 1.2.2.2 bouyer * 2. Redistributions in binary form must reproduce the above copyright
15 1.2.2.2 bouyer * notice, this list of conditions and the following disclaimer in the
16 1.2.2.2 bouyer * documentation and/or other materials provided with the distribution.
17 1.2.2.2 bouyer * 3. All advertising materials mentioning features or use of this software
18 1.2.2.2 bouyer * must display the following acknowledgement:
19 1.2.2.2 bouyer * This product includes software developed by the NetBSD
20 1.2.2.2 bouyer * Foundation, Inc. and its contributors.
21 1.2.2.2 bouyer * 4. The name of the author may not be used to endorse or promote products
22 1.2.2.2 bouyer * derived from this software without specific prior written permission.
23 1.2.2.2 bouyer *
24 1.2.2.2 bouyer * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
25 1.2.2.2 bouyer * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
26 1.2.2.2 bouyer * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
27 1.2.2.2 bouyer * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
28 1.2.2.2 bouyer * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
29 1.2.2.2 bouyer * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
30 1.2.2.2 bouyer * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
31 1.2.2.2 bouyer * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
32 1.2.2.2 bouyer * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
33 1.2.2.2 bouyer * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
34 1.2.2.2 bouyer */
35 1.2.2.2 bouyer
36 1.2.2.2 bouyer /*
37 1.2.2.2 bouyer * Disk goo for MCA ESDI controller driver.
38 1.2.2.2 bouyer */
39 1.2.2.2 bouyer
40 1.2.2.2 bouyer #include "rnd.h"
41 1.2.2.2 bouyer
42 1.2.2.2 bouyer #include <sys/param.h>
43 1.2.2.2 bouyer #include <sys/systm.h>
44 1.2.2.2 bouyer #include <sys/kernel.h>
45 1.2.2.2 bouyer #include <sys/conf.h>
46 1.2.2.2 bouyer #include <sys/file.h>
47 1.2.2.2 bouyer #include <sys/stat.h>
48 1.2.2.2 bouyer #include <sys/ioctl.h>
49 1.2.2.2 bouyer #include <sys/buf.h>
50 1.2.2.2 bouyer #include <sys/uio.h>
51 1.2.2.2 bouyer #include <sys/malloc.h>
52 1.2.2.2 bouyer #include <sys/device.h>
53 1.2.2.2 bouyer #include <sys/disklabel.h>
54 1.2.2.2 bouyer #include <sys/disk.h>
55 1.2.2.2 bouyer #include <sys/syslog.h>
56 1.2.2.2 bouyer #include <sys/proc.h>
57 1.2.2.2 bouyer #include <sys/vnode.h>
58 1.2.2.2 bouyer #include <sys/kthread.h>
59 1.2.2.2 bouyer #if NRND > 0
60 1.2.2.2 bouyer #include <sys/rnd.h>
61 1.2.2.2 bouyer #endif
62 1.2.2.2 bouyer
63 1.2.2.2 bouyer #include <machine/intr.h>
64 1.2.2.2 bouyer #include <machine/bus.h>
65 1.2.2.2 bouyer
66 1.2.2.2 bouyer #include <dev/mca/dasdreg.h>
67 1.2.2.2 bouyer #include <dev/mca/edvar.h>
68 1.2.2.2 bouyer #include <dev/mca/dasdvar.h>
69 1.2.2.2 bouyer
70 1.2.2.2 bouyer /* #define WDCDEBUG */
71 1.2.2.2 bouyer
72 1.2.2.2 bouyer #ifdef WDCDEBUG
73 1.2.2.2 bouyer #define WDCDEBUG_PRINT(args, level) printf args
74 1.2.2.2 bouyer #else
75 1.2.2.2 bouyer #define WDCDEBUG_PRINT(args, level)
76 1.2.2.2 bouyer #endif
77 1.2.2.2 bouyer
78 1.2.2.2 bouyer #define EDLABELDEV(dev) (MAKEDISKDEV(major(dev), DISKUNIT(dev), RAW_PART))
79 1.2.2.2 bouyer
80 1.2.2.2 bouyer #define ED_BB_SIZE 65536
81 1.2.2.2 bouyer
82 1.2.2.2 bouyer /* XXX: these should go elsewhere */
83 1.2.2.2 bouyer cdev_decl(edmca);
84 1.2.2.2 bouyer bdev_decl(edmca);
85 1.2.2.2 bouyer
86 1.2.2.2 bouyer static int ed_mca_probe __P((struct device *, struct cfdata *, void *));
87 1.2.2.2 bouyer static void ed_mca_attach __P((struct device *, struct device *, void *));
88 1.2.2.2 bouyer
89 1.2.2.2 bouyer struct cfattach ed_mca_ca = {
90 1.2.2.2 bouyer sizeof(struct ed_softc), ed_mca_probe, ed_mca_attach
91 1.2.2.2 bouyer };
92 1.2.2.2 bouyer
93 1.2.2.2 bouyer extern struct cfdriver ed_cd;
94 1.2.2.2 bouyer
95 1.2.2.2 bouyer static int ed_get_params __P((struct ed_softc *));
96 1.2.2.2 bouyer static int ed_lock __P((struct ed_softc *));
97 1.2.2.2 bouyer static void ed_unlock __P((struct ed_softc *));
98 1.2.2.2 bouyer static void edgetdisklabel __P((struct ed_softc *));
99 1.2.2.2 bouyer static void edgetdefaultlabel __P((struct ed_softc *, struct disklabel *));
100 1.2.2.2 bouyer static void ed_shutdown __P((void*));
101 1.2.2.2 bouyer // static void edstart __P((void *));
102 1.2.2.2 bouyer static void __edstart __P((struct ed_softc*, struct buf *));
103 1.2.2.2 bouyer static void bad144intern __P((struct ed_softc *));
104 1.2.2.2 bouyer static void edworker __P((void *));
105 1.2.2.2 bouyer static void ed_spawn_worker __P((void *));
106 1.2.2.2 bouyer static void edmcadone __P((struct ed_softc *));
107 1.2.2.2 bouyer
108 1.2.2.2 bouyer static struct dkdriver eddkdriver = { edmcastrategy };
109 1.2.2.2 bouyer
110 1.2.2.2 bouyer /*
111 1.2.2.2 bouyer * Just check if it's possible to identify the disk.
112 1.2.2.2 bouyer */
113 1.2.2.2 bouyer static int
114 1.2.2.2 bouyer ed_mca_probe(parent, match, aux)
115 1.2.2.2 bouyer struct device *parent;
116 1.2.2.2 bouyer struct cfdata *match;
117 1.2.2.2 bouyer void *aux;
118 1.2.2.2 bouyer {
119 1.2.2.2 bouyer u_int16_t cmd_args[2];
120 1.2.2.2 bouyer struct dasd_mca_softc *sc = (void *) parent;
121 1.2.2.2 bouyer struct ed_attach_args *eda = (void *) aux;
122 1.2.2.2 bouyer
123 1.2.2.2 bouyer /*
124 1.2.2.2 bouyer * Get Device Configuration (09).
125 1.2.2.2 bouyer */
126 1.2.2.2 bouyer cmd_args[0] = 6; /* Options: 00s110, s: 0=Physical 1=Pseudo */
127 1.2.2.2 bouyer cmd_args[1] = 0;
128 1.2.2.2 bouyer if (dasd_run_cmd(sc, CMD_GET_DEV_CONF, eda->sc_devno, cmd_args, 2, 0))
129 1.2.2.2 bouyer return (0);
130 1.2.2.2 bouyer
131 1.2.2.2 bouyer return (1);
132 1.2.2.2 bouyer }
133 1.2.2.2 bouyer
134 1.2.2.2 bouyer static void
135 1.2.2.2 bouyer ed_mca_attach(parent, self, aux)
136 1.2.2.2 bouyer struct device *parent, *self;
137 1.2.2.2 bouyer void *aux;
138 1.2.2.2 bouyer {
139 1.2.2.2 bouyer struct ed_softc *ed = (void *) self;
140 1.2.2.2 bouyer struct dasd_mca_softc *sc = (void *) parent;
141 1.2.2.2 bouyer struct ed_attach_args *eda = (void *) aux;
142 1.2.2.2 bouyer char pbuf[8];
143 1.2.2.2 bouyer int error, nsegs;
144 1.2.2.2 bouyer
145 1.2.2.2 bouyer ed->dasd_softc = sc;
146 1.2.2.2 bouyer ed->sc_dmat = eda->sc_dmat;
147 1.2.2.2 bouyer ed->sc_devno = eda->sc_devno;
148 1.2.2.2 bouyer dasd_add_disk(sc, ed, eda->sc_devno);
149 1.2.2.2 bouyer
150 1.2.2.2 bouyer BUFQ_INIT(&ed->sc_q);
151 1.2.2.2 bouyer spinlockinit(&ed->sc_q_lock, "edbqlock", 0);
152 1.2.2.2 bouyer
153 1.2.2.2 bouyer if (ed_get_params(ed)) {
154 1.2.2.2 bouyer printf(": IDENTIFY failed, no disk found\n");
155 1.2.2.2 bouyer return;
156 1.2.2.2 bouyer }
157 1.2.2.2 bouyer
158 1.2.2.2 bouyer format_bytes(pbuf, sizeof(pbuf),
159 1.2.2.2 bouyer (u_int64_t) ed->sc_capacity * DEV_BSIZE);
160 1.2.2.2 bouyer printf(": %s, %u cyl, %u head, %u sec, 512 bytes/sect x %u sectors\n",
161 1.2.2.2 bouyer pbuf,
162 1.2.2.2 bouyer ed->cyl, ed->heads, ed->sectors,
163 1.2.2.2 bouyer ed->sc_capacity);
164 1.2.2.2 bouyer
165 1.2.2.2 bouyer printf("%s: %u spares/cyl, %s.%s.%s.%s.%s\n",
166 1.2.2.2 bouyer ed->sc_dev.dv_xname, ed->spares,
167 1.2.2.2 bouyer (ed->drv_flags & (1 << 0)) ? "NoRetries" : "Retries",
168 1.2.2.2 bouyer (ed->drv_flags & (1 << 1)) ? "Removable" : "Fixed",
169 1.2.2.2 bouyer (ed->drv_flags & (1 << 2)) ? "SkewedFormat" : "NoSkew",
170 1.2.2.2 bouyer (ed->drv_flags & (1 << 3)) ? "ZeroDefect" : "Defects",
171 1.2.2.2 bouyer (ed->drv_flags & (1 << 4)) ? "InvalidSecondary" : "SeconOK"
172 1.2.2.2 bouyer );
173 1.2.2.2 bouyer
174 1.2.2.2 bouyer /* Create a DMA map for mapping individual transfer bufs */
175 1.2.2.2 bouyer if ((error = bus_dmamap_create(ed->sc_dmat, 65536, 1,
176 1.2.2.2 bouyer 65536, 0, BUS_DMA_WAITOK | BUS_DMA_ALLOCNOW,
177 1.2.2.2 bouyer &ed->dmamap_xfer)) != 0) {
178 1.2.2.2 bouyer printf("%s: unable to create xfer DMA map, error=%d\n",
179 1.2.2.2 bouyer ed->sc_dev.dv_xname, error);
180 1.2.2.2 bouyer return;
181 1.2.2.2 bouyer }
182 1.2.2.2 bouyer
183 1.2.2.2 bouyer /*
184 1.2.2.2 bouyer * Allocate DMA memory used in case where passed buf isn't
185 1.2.2.2 bouyer * physically contiguous.
186 1.2.2.2 bouyer */
187 1.2.2.2 bouyer ed->sc_dmam_sz = ED_BB_SIZE;
188 1.2.2.2 bouyer if ((error = bus_dmamem_alloc(ed->sc_dmat, ed->sc_dmam_sz,
189 1.2.2.2 bouyer 65536, 65536, ed->sc_dmam, 1, &nsegs,
190 1.2.2.2 bouyer BUS_DMA_WAITOK|BUS_DMA_STREAMING)) != 0) {
191 1.2.2.2 bouyer printf("%s: unable to allocate DMA memory for xfer, errno=%d\n",
192 1.2.2.2 bouyer ed->sc_dev.dv_xname, error);
193 1.2.2.2 bouyer bus_dmamap_destroy(ed->sc_dmat, ed->dmamap_xfer);
194 1.2.2.2 bouyer return;
195 1.2.2.2 bouyer }
196 1.2.2.2 bouyer /*
197 1.2.2.2 bouyer * Map the memory.
198 1.2.2.2 bouyer */
199 1.2.2.2 bouyer if ((error = bus_dmamem_map(ed->sc_dmat, ed->sc_dmam, 1,
200 1.2.2.2 bouyer ed->sc_dmam_sz, &ed->sc_dmamkva, BUS_DMA_WAITOK)) != 0) {
201 1.2.2.2 bouyer printf("%s: unable to map DMA memory, error=%d\n",
202 1.2.2.2 bouyer ed->sc_dev.dv_xname, error);
203 1.2.2.2 bouyer bus_dmamem_free(ed->sc_dmat, ed->sc_dmam, 1);
204 1.2.2.2 bouyer bus_dmamap_destroy(ed->sc_dmat, ed->dmamap_xfer);
205 1.2.2.2 bouyer return;
206 1.2.2.2 bouyer }
207 1.2.2.2 bouyer
208 1.2.2.2 bouyer
209 1.2.2.2 bouyer /*
210 1.2.2.2 bouyer * Initialize and attach the disk structure.
211 1.2.2.2 bouyer */
212 1.2.2.2 bouyer ed->sc_dk.dk_driver = &eddkdriver;
213 1.2.2.2 bouyer ed->sc_dk.dk_name = ed->sc_dev.dv_xname;
214 1.2.2.2 bouyer disk_attach(&ed->sc_dk);
215 1.2.2.2 bouyer #if 0
216 1.2.2.2 bouyer wd->sc_wdc_bio.lp = wd->sc_dk.dk_label;
217 1.2.2.2 bouyer #endif
218 1.2.2.2 bouyer ed->sc_sdhook = shutdownhook_establish(ed_shutdown, ed);
219 1.2.2.2 bouyer if (ed->sc_sdhook == NULL)
220 1.2.2.2 bouyer printf("%s: WARNING: unable to establish shutdown hook\n",
221 1.2.2.2 bouyer ed->sc_dev.dv_xname);
222 1.2.2.2 bouyer #if NRND > 0
223 1.2.2.2 bouyer rnd_attach_source(&ed->rnd_source, ed->sc_dev.dv_xname,
224 1.2.2.2 bouyer RND_TYPE_DISK, 0);
225 1.2.2.2 bouyer #endif
226 1.2.2.2 bouyer
227 1.2.2.2 bouyer config_pending_incr();
228 1.2.2.2 bouyer kthread_create(ed_spawn_worker, (void *) ed);
229 1.2.2.2 bouyer }
230 1.2.2.2 bouyer
231 1.2.2.2 bouyer void
232 1.2.2.2 bouyer ed_spawn_worker(arg)
233 1.2.2.2 bouyer void *arg;
234 1.2.2.2 bouyer {
235 1.2.2.2 bouyer struct ed_softc *ed = (struct ed_softc *) arg;
236 1.2.2.2 bouyer int error;
237 1.2.2.2 bouyer
238 1.2.2.2 bouyer /* Now, everything is ready, start a kthread */
239 1.2.2.2 bouyer if ((error = kthread_create1(edworker, ed, &ed->sc_worker,
240 1.2.2.2 bouyer "%s", ed->sc_dev.dv_xname))) {
241 1.2.2.2 bouyer printf("%s: cannot spawn worker thread: errno=%d\n",
242 1.2.2.2 bouyer ed->sc_dev.dv_xname, error);
243 1.2.2.2 bouyer panic("ed_spawn_worker");
244 1.2.2.2 bouyer }
245 1.2.2.2 bouyer }
246 1.2.2.2 bouyer
247 1.2.2.2 bouyer /*
248 1.2.2.2 bouyer * Read/write routine for a buffer. Validates the arguments and schedules the
249 1.2.2.2 bouyer * transfer. Does not wait for the transfer to complete.
250 1.2.2.2 bouyer */
251 1.2.2.2 bouyer void
252 1.2.2.2 bouyer edmcastrategy(bp)
253 1.2.2.2 bouyer struct buf *bp;
254 1.2.2.2 bouyer {
255 1.2.2.2 bouyer struct ed_softc *wd = device_lookup(&ed_cd, DISKUNIT(bp->b_dev));
256 1.2.2.2 bouyer struct disklabel *lp = wd->sc_dk.dk_label;
257 1.2.2.2 bouyer daddr_t blkno;
258 1.2.2.2 bouyer int s;
259 1.2.2.2 bouyer
260 1.2.2.2 bouyer WDCDEBUG_PRINT(("edmcastrategy (%s)\n", wd->sc_dev.dv_xname),
261 1.2.2.2 bouyer DEBUG_XFERS);
262 1.2.2.2 bouyer
263 1.2.2.2 bouyer /* Valid request? */
264 1.2.2.2 bouyer if (bp->b_blkno < 0 ||
265 1.2.2.2 bouyer (bp->b_bcount % lp->d_secsize) != 0 ||
266 1.2.2.2 bouyer (bp->b_bcount / lp->d_secsize) >= (1 << NBBY)) {
267 1.2.2.2 bouyer bp->b_error = EINVAL;
268 1.2.2.2 bouyer goto bad;
269 1.2.2.2 bouyer }
270 1.2.2.2 bouyer
271 1.2.2.2 bouyer /* If device invalidated (e.g. media change, door open), error. */
272 1.2.2.2 bouyer if ((wd->sc_flags & WDF_LOADED) == 0) {
273 1.2.2.2 bouyer bp->b_error = EIO;
274 1.2.2.2 bouyer goto bad;
275 1.2.2.2 bouyer }
276 1.2.2.2 bouyer
277 1.2.2.2 bouyer /* If it's a null transfer, return immediately. */
278 1.2.2.2 bouyer if (bp->b_bcount == 0)
279 1.2.2.2 bouyer goto done;
280 1.2.2.2 bouyer
281 1.2.2.2 bouyer /*
282 1.2.2.2 bouyer * Do bounds checking, adjust transfer. if error, process.
283 1.2.2.2 bouyer * If end of partition, just return.
284 1.2.2.2 bouyer */
285 1.2.2.2 bouyer if (DISKPART(bp->b_dev) != RAW_PART &&
286 1.2.2.2 bouyer bounds_check_with_label(bp, wd->sc_dk.dk_label,
287 1.2.2.2 bouyer (wd->sc_flags & (WDF_WLABEL|WDF_LABELLING)) != 0) <= 0)
288 1.2.2.2 bouyer goto done;
289 1.2.2.2 bouyer
290 1.2.2.2 bouyer /*
291 1.2.2.2 bouyer * Now convert the block number to absolute and put it in
292 1.2.2.2 bouyer * terms of the device's logical block size.
293 1.2.2.2 bouyer */
294 1.2.2.2 bouyer if (lp->d_secsize >= DEV_BSIZE)
295 1.2.2.2 bouyer blkno = bp->b_blkno / (lp->d_secsize / DEV_BSIZE);
296 1.2.2.2 bouyer else
297 1.2.2.2 bouyer blkno = bp->b_blkno * (DEV_BSIZE / lp->d_secsize);
298 1.2.2.2 bouyer
299 1.2.2.2 bouyer if (DISKPART(bp->b_dev) != RAW_PART)
300 1.2.2.2 bouyer blkno += lp->d_partitions[DISKPART(bp->b_dev)].p_offset;
301 1.2.2.2 bouyer
302 1.2.2.2 bouyer bp->b_rawblkno = blkno;
303 1.2.2.2 bouyer
304 1.2.2.2 bouyer /* Queue transfer on drive, activate drive and controller if idle. */
305 1.2.2.2 bouyer s = splbio();
306 1.2.2.2 bouyer simple_lock(&wd->sc_q_lock);
307 1.2.2.2 bouyer disksort_blkno(&wd->sc_q, bp);
308 1.2.2.2 bouyer simple_unlock(&wd->sc_q_lock);
309 1.2.2.2 bouyer
310 1.2.2.2 bouyer /* Ring the worker thread */
311 1.2.2.2 bouyer wd->sc_flags |= EDF_PROCESS_QUEUE;
312 1.2.2.2 bouyer wakeup_one(&wd->sc_q);
313 1.2.2.2 bouyer
314 1.2.2.2 bouyer splx(s);
315 1.2.2.2 bouyer return;
316 1.2.2.2 bouyer bad:
317 1.2.2.2 bouyer bp->b_flags |= B_ERROR;
318 1.2.2.2 bouyer done:
319 1.2.2.2 bouyer /* Toss transfer; we're done early. */
320 1.2.2.2 bouyer bp->b_resid = bp->b_bcount;
321 1.2.2.2 bouyer biodone(bp);
322 1.2.2.2 bouyer }
323 1.2.2.2 bouyer
324 1.2.2.2 bouyer #if 0
325 1.2.2.2 bouyer /*
326 1.2.2.2 bouyer * Queue a drive for I/O.
327 1.2.2.2 bouyer */
328 1.2.2.2 bouyer static void
329 1.2.2.2 bouyer edstart(arg)
330 1.2.2.2 bouyer void *arg;
331 1.2.2.2 bouyer {
332 1.2.2.2 bouyer struct ed_softc *wd = arg;
333 1.2.2.2 bouyer struct buf *bp;
334 1.2.2.2 bouyer
335 1.2.2.2 bouyer WDCDEBUG_PRINT(("edstart %s\n", wd->sc_dev.dv_xname),
336 1.2.2.2 bouyer DEBUG_XFERS);
337 1.2.2.2 bouyer while (wd->openings > 0) {
338 1.2.2.2 bouyer
339 1.2.2.2 bouyer /* Is there a buf for us ? */
340 1.2.2.2 bouyer if ((bp = BUFQ_FIRST(&wd->sc_q)) == NULL)
341 1.2.2.2 bouyer return;
342 1.2.2.2 bouyer BUFQ_REMOVE(&wd->sc_q, bp);
343 1.2.2.2 bouyer
344 1.2.2.2 bouyer /*
345 1.2.2.2 bouyer * Make the command. First lock the device
346 1.2.2.2 bouyer */
347 1.2.2.2 bouyer wd->openings--;
348 1.2.2.2 bouyer
349 1.2.2.2 bouyer wd->retries = 0;
350 1.2.2.2 bouyer __edstart(wd, bp);
351 1.2.2.2 bouyer }
352 1.2.2.2 bouyer }
353 1.2.2.2 bouyer #endif
354 1.2.2.2 bouyer
355 1.2.2.2 bouyer static void
356 1.2.2.2 bouyer __edstart(ed, bp)
357 1.2.2.2 bouyer struct ed_softc *ed;
358 1.2.2.2 bouyer struct buf *bp;
359 1.2.2.2 bouyer {
360 1.2.2.2 bouyer u_int16_t cmd_args[4];
361 1.2.2.2 bouyer int error = 0;
362 1.2.2.2 bouyer u_int16_t track;
363 1.2.2.2 bouyer u_int16_t cyl;
364 1.2.2.2 bouyer u_int8_t head;
365 1.2.2.2 bouyer u_int8_t sector;
366 1.2.2.2 bouyer
367 1.2.2.2 bouyer WDCDEBUG_PRINT(("__edstart %s: %lu %lu %u\n", ed->sc_dev.dv_xname,
368 1.2.2.2 bouyer bp->b_bcount, bp->b_resid, bp->b_rawblkno),
369 1.2.2.2 bouyer DEBUG_XFERS);
370 1.2.2.2 bouyer
371 1.2.2.2 bouyer ed->sc_bp = bp;
372 1.2.2.2 bouyer
373 1.2.2.2 bouyer /* Get physical bus mapping for buf */
374 1.2.2.2 bouyer if ((error = bus_dmamap_load(ed->sc_dmat, ed->dmamap_xfer,
375 1.2.2.2 bouyer bp->b_data, bp->b_bcount, NULL,
376 1.2.2.2 bouyer BUS_DMA_WAITOK|BUS_DMA_STREAMING)) != 0) {
377 1.2.2.2 bouyer
378 1.2.2.2 bouyer #ifdef DEBUG
379 1.2.2.2 bouyer if (bp->b_bcount > ed->sc_dmam_sz)
380 1.2.2.2 bouyer panic("%s: edstart: bp->b_bcount: %lu > %lu",
381 1.2.2.2 bouyer ed->sc_dev.dv_xname,
382 1.2.2.2 bouyer bp->b_bcount, ed->sc_dmam_sz
383 1.2.2.2 bouyer );
384 1.2.2.2 bouyer #endif
385 1.2.2.2 bouyer /*
386 1.2.2.2 bouyer * Use our DMA safe memory to get data to/from device.
387 1.2.2.2 bouyer * For write, copy the data from buf to it now, too.
388 1.2.2.2 bouyer */
389 1.2.2.2 bouyer if ((error = bus_dmamap_load(ed->sc_dmat, ed->dmamap_xfer,
390 1.2.2.2 bouyer ed->sc_dmamkva, bp->b_bcount, NULL,
391 1.2.2.2 bouyer BUS_DMA_WAITOK|BUS_DMA_STREAMING)) != 0) {
392 1.2.2.2 bouyer printf("%s: unable to load raw data for xfer, errno=%d\n",
393 1.2.2.2 bouyer ed->sc_dev.dv_xname, error);
394 1.2.2.2 bouyer goto out;
395 1.2.2.2 bouyer }
396 1.2.2.2 bouyer ed->sc_flags |= EDF_BOUNCEBUF;
397 1.2.2.2 bouyer
398 1.2.2.2 bouyer /* If data write, copy the data to our bounce buffer. */
399 1.2.2.2 bouyer if ((bp->b_flags & B_READ) == 0)
400 1.2.2.2 bouyer memcpy(ed->sc_dmamkva, bp->b_data, bp->b_bcount);
401 1.2.2.2 bouyer }
402 1.2.2.2 bouyer ed->sc_flags |= EDF_DMAMAP_LOADED;
403 1.2.2.2 bouyer
404 1.2.2.2 bouyer track = bp->b_rawblkno / ed->sectors;
405 1.2.2.2 bouyer head = track % ed->heads;
406 1.2.2.2 bouyer cyl = track / ed->heads;
407 1.2.2.2 bouyer sector = bp->b_rawblkno % ed->sectors;
408 1.2.2.2 bouyer
409 1.2.2.2 bouyer WDCDEBUG_PRINT(("__edstart %s: map: %u %u %u\n", ed->sc_dev.dv_xname,
410 1.2.2.2 bouyer cyl, sector, head),
411 1.2.2.2 bouyer DEBUG_XFERS);
412 1.2.2.2 bouyer
413 1.2.2.2 bouyer /* Instrumentation. */
414 1.2.2.2 bouyer disk_busy(&ed->sc_dk);
415 1.2.2.2 bouyer ed->sc_dk_busy++;
416 1.2.2.2 bouyer
417 1.2.2.2 bouyer /* Read or Write Data command */
418 1.2.2.2 bouyer cmd_args[0] = 2; /* Options 0000010 */
419 1.2.2.2 bouyer cmd_args[1] = bp->b_bcount / DEV_BSIZE;
420 1.2.2.2 bouyer cmd_args[2] = ((cyl & 0x1f) << 11) | (head << 5) | sector;
421 1.2.2.2 bouyer cmd_args[3] = ((cyl & 0x3E0) >> 5);
422 1.2.2.2 bouyer if (dasd_run_cmd(ed->dasd_softc,
423 1.2.2.2 bouyer (bp->b_flags & B_READ) ? CMD_READ_DATA : CMD_WRITE_DATA,
424 1.2.2.2 bouyer ed->sc_devno, cmd_args, 4, 1)) {
425 1.2.2.2 bouyer printf("%s: data i/o command failed\n", ed->sc_dev.dv_xname);
426 1.2.2.2 bouyer error = EIO;
427 1.2.2.2 bouyer }
428 1.2.2.2 bouyer
429 1.2.2.2 bouyer out:
430 1.2.2.2 bouyer if (error)
431 1.2.2.2 bouyer ed->sc_error = error;
432 1.2.2.2 bouyer }
433 1.2.2.2 bouyer
434 1.2.2.2 bouyer
435 1.2.2.2 bouyer static void
436 1.2.2.2 bouyer edmcadone(ed)
437 1.2.2.2 bouyer struct ed_softc *ed;
438 1.2.2.2 bouyer {
439 1.2.2.2 bouyer struct buf *bp = ed->sc_bp;
440 1.2.2.2 bouyer
441 1.2.2.2 bouyer WDCDEBUG_PRINT(("eddone %s\n", ed->sc_dev.dv_xname),
442 1.2.2.2 bouyer DEBUG_XFERS);
443 1.2.2.2 bouyer
444 1.2.2.2 bouyer if (ed->sc_error) {
445 1.2.2.2 bouyer bp->b_error = ed->sc_error;
446 1.2.2.2 bouyer bp->b_flags |= B_ERROR;
447 1.2.2.2 bouyer }
448 1.2.2.2 bouyer
449 1.2.2.2 bouyer /* If no error and using bounce buffer, copy the data now. */
450 1.2.2.2 bouyer if ((bp->b_flags & B_ERROR) == 0 && (ed->sc_flags & EDF_BOUNCEBUF)
451 1.2.2.2 bouyer && (bp->b_flags & B_READ)) {
452 1.2.2.2 bouyer memcpy(bp->b_data, ed->sc_dmamkva, bp->b_bcount);
453 1.2.2.2 bouyer ed->sc_flags &= ~EDF_BOUNCEBUF;
454 1.2.2.2 bouyer }
455 1.2.2.2 bouyer
456 1.2.2.2 bouyer /* Unload buf from DMA map */
457 1.2.2.2 bouyer if (ed->sc_flags & EDF_DMAMAP_LOADED) {
458 1.2.2.2 bouyer bus_dmamap_unload(ed->sc_dmat, ed->dmamap_xfer);
459 1.2.2.2 bouyer ed->sc_flags &= ~EDF_DMAMAP_LOADED;
460 1.2.2.2 bouyer }
461 1.2.2.2 bouyer
462 1.2.2.2 bouyer /* If disk was busied, unbusy it now */
463 1.2.2.2 bouyer if (ed->sc_dk_busy > 0) {
464 1.2.2.2 bouyer disk_unbusy(&ed->sc_dk, (bp->b_bcount - bp->b_resid));
465 1.2.2.2 bouyer ed->sc_dk_busy--;
466 1.2.2.2 bouyer }
467 1.2.2.2 bouyer
468 1.2.2.2 bouyer #if NRND > 0
469 1.2.2.2 bouyer rnd_add_uint32(&ed->rnd_source, bp->b_blkno);
470 1.2.2.2 bouyer #endif
471 1.2.2.2 bouyer biodone(bp);
472 1.2.2.2 bouyer }
473 1.2.2.2 bouyer
474 1.2.2.2 bouyer #if 0
475 1.2.2.2 bouyer void
476 1.2.2.2 bouyer edmcarestart(v)
477 1.2.2.2 bouyer void *v;
478 1.2.2.2 bouyer {
479 1.2.2.2 bouyer struct ed_softc *wd = v;
480 1.2.2.2 bouyer struct buf *bp = wd->sc_bp;
481 1.2.2.2 bouyer int s;
482 1.2.2.2 bouyer WDCDEBUG_PRINT(("wdrestart %s\n", wd->sc_dev.dv_xname),
483 1.2.2.2 bouyer DEBUG_XFERS);
484 1.2.2.2 bouyer
485 1.2.2.2 bouyer s = splbio();
486 1.2.2.2 bouyer __edstart(v, bp);
487 1.2.2.2 bouyer splx(s);
488 1.2.2.2 bouyer }
489 1.2.2.2 bouyer #endif
490 1.2.2.2 bouyer
491 1.2.2.2 bouyer int
492 1.2.2.2 bouyer edmcaread(dev, uio, flags)
493 1.2.2.2 bouyer dev_t dev;
494 1.2.2.2 bouyer struct uio *uio;
495 1.2.2.2 bouyer int flags;
496 1.2.2.2 bouyer {
497 1.2.2.2 bouyer WDCDEBUG_PRINT(("edread\n"), DEBUG_XFERS);
498 1.2.2.2 bouyer return (physio(edmcastrategy, NULL, dev, B_READ, minphys, uio));
499 1.2.2.2 bouyer }
500 1.2.2.2 bouyer
501 1.2.2.2 bouyer int
502 1.2.2.2 bouyer edmcawrite(dev, uio, flags)
503 1.2.2.2 bouyer dev_t dev;
504 1.2.2.2 bouyer struct uio *uio;
505 1.2.2.2 bouyer int flags;
506 1.2.2.2 bouyer {
507 1.2.2.2 bouyer WDCDEBUG_PRINT(("edwrite\n"), DEBUG_XFERS);
508 1.2.2.2 bouyer return (physio(edmcastrategy, NULL, dev, B_WRITE, minphys, uio));
509 1.2.2.2 bouyer }
510 1.2.2.2 bouyer
511 1.2.2.2 bouyer /*
512 1.2.2.2 bouyer * Wait interruptibly for an exclusive lock.
513 1.2.2.2 bouyer *
514 1.2.2.2 bouyer * XXX
515 1.2.2.2 bouyer * Several drivers do this; it should be abstracted and made MP-safe.
516 1.2.2.2 bouyer */
517 1.2.2.2 bouyer static int
518 1.2.2.2 bouyer ed_lock(wd)
519 1.2.2.2 bouyer struct ed_softc *wd;
520 1.2.2.2 bouyer {
521 1.2.2.2 bouyer int error;
522 1.2.2.2 bouyer int s;
523 1.2.2.2 bouyer
524 1.2.2.2 bouyer WDCDEBUG_PRINT(("ed_lock\n"), DEBUG_FUNCS);
525 1.2.2.2 bouyer
526 1.2.2.2 bouyer s = splbio();
527 1.2.2.2 bouyer
528 1.2.2.2 bouyer while ((wd->sc_flags & WDF_LOCKED) != 0) {
529 1.2.2.2 bouyer wd->sc_flags |= WDF_WANTED;
530 1.2.2.2 bouyer if ((error = tsleep(wd, PRIBIO | PCATCH,
531 1.2.2.2 bouyer "wdlck", 0)) != 0) {
532 1.2.2.2 bouyer splx(s);
533 1.2.2.2 bouyer return error;
534 1.2.2.2 bouyer }
535 1.2.2.2 bouyer }
536 1.2.2.2 bouyer wd->sc_flags |= WDF_LOCKED;
537 1.2.2.2 bouyer splx(s);
538 1.2.2.2 bouyer return 0;
539 1.2.2.2 bouyer }
540 1.2.2.2 bouyer
541 1.2.2.2 bouyer /*
542 1.2.2.2 bouyer * Unlock and wake up any waiters.
543 1.2.2.2 bouyer */
544 1.2.2.2 bouyer static void
545 1.2.2.2 bouyer ed_unlock(wd)
546 1.2.2.2 bouyer struct ed_softc *wd;
547 1.2.2.2 bouyer {
548 1.2.2.2 bouyer
549 1.2.2.2 bouyer WDCDEBUG_PRINT(("ed_unlock\n"), DEBUG_FUNCS);
550 1.2.2.2 bouyer
551 1.2.2.2 bouyer wd->sc_flags &= ~WDF_LOCKED;
552 1.2.2.2 bouyer if ((wd->sc_flags & WDF_WANTED) != 0) {
553 1.2.2.2 bouyer wd->sc_flags &= ~WDF_WANTED;
554 1.2.2.2 bouyer wakeup(wd);
555 1.2.2.2 bouyer }
556 1.2.2.2 bouyer }
557 1.2.2.2 bouyer
558 1.2.2.2 bouyer int
559 1.2.2.2 bouyer edmcaopen(dev, flag, fmt, p)
560 1.2.2.2 bouyer dev_t dev;
561 1.2.2.2 bouyer int flag, fmt;
562 1.2.2.2 bouyer struct proc *p;
563 1.2.2.2 bouyer {
564 1.2.2.2 bouyer struct ed_softc *wd;
565 1.2.2.2 bouyer int part, error;
566 1.2.2.2 bouyer
567 1.2.2.2 bouyer WDCDEBUG_PRINT(("edopen\n"), DEBUG_FUNCS);
568 1.2.2.2 bouyer wd = device_lookup(&ed_cd, DISKUNIT(dev));
569 1.2.2.2 bouyer if (wd == NULL)
570 1.2.2.2 bouyer return (ENXIO);
571 1.2.2.2 bouyer
572 1.2.2.2 bouyer if ((error = ed_lock(wd)) != 0)
573 1.2.2.2 bouyer goto bad4;
574 1.2.2.2 bouyer
575 1.2.2.2 bouyer if (wd->sc_dk.dk_openmask != 0) {
576 1.2.2.2 bouyer /*
577 1.2.2.2 bouyer * If any partition is open, but the disk has been invalidated,
578 1.2.2.2 bouyer * disallow further opens.
579 1.2.2.2 bouyer */
580 1.2.2.2 bouyer if ((wd->sc_flags & WDF_LOADED) == 0) {
581 1.2.2.2 bouyer error = EIO;
582 1.2.2.2 bouyer goto bad3;
583 1.2.2.2 bouyer }
584 1.2.2.2 bouyer } else {
585 1.2.2.2 bouyer if ((wd->sc_flags & WDF_LOADED) == 0) {
586 1.2.2.2 bouyer wd->sc_flags |= WDF_LOADED;
587 1.2.2.2 bouyer
588 1.2.2.2 bouyer /* Load the physical device parameters. */
589 1.2.2.2 bouyer ed_get_params(wd);
590 1.2.2.2 bouyer
591 1.2.2.2 bouyer /* Load the partition info if not already loaded. */
592 1.2.2.2 bouyer edgetdisklabel(wd);
593 1.2.2.2 bouyer }
594 1.2.2.2 bouyer }
595 1.2.2.2 bouyer
596 1.2.2.2 bouyer part = DISKPART(dev);
597 1.2.2.2 bouyer
598 1.2.2.2 bouyer /* Check that the partition exists. */
599 1.2.2.2 bouyer if (part != RAW_PART &&
600 1.2.2.2 bouyer (part >= wd->sc_dk.dk_label->d_npartitions ||
601 1.2.2.2 bouyer wd->sc_dk.dk_label->d_partitions[part].p_fstype == FS_UNUSED)) {
602 1.2.2.2 bouyer error = ENXIO;
603 1.2.2.2 bouyer goto bad;
604 1.2.2.2 bouyer }
605 1.2.2.2 bouyer
606 1.2.2.2 bouyer /* Insure only one open at a time. */
607 1.2.2.2 bouyer switch (fmt) {
608 1.2.2.2 bouyer case S_IFCHR:
609 1.2.2.2 bouyer wd->sc_dk.dk_copenmask |= (1 << part);
610 1.2.2.2 bouyer break;
611 1.2.2.2 bouyer case S_IFBLK:
612 1.2.2.2 bouyer wd->sc_dk.dk_bopenmask |= (1 << part);
613 1.2.2.2 bouyer break;
614 1.2.2.2 bouyer }
615 1.2.2.2 bouyer wd->sc_dk.dk_openmask =
616 1.2.2.2 bouyer wd->sc_dk.dk_copenmask | wd->sc_dk.dk_bopenmask;
617 1.2.2.2 bouyer
618 1.2.2.2 bouyer ed_unlock(wd);
619 1.2.2.2 bouyer return 0;
620 1.2.2.2 bouyer
621 1.2.2.2 bouyer bad:
622 1.2.2.2 bouyer if (wd->sc_dk.dk_openmask == 0) {
623 1.2.2.2 bouyer }
624 1.2.2.2 bouyer
625 1.2.2.2 bouyer bad3:
626 1.2.2.2 bouyer ed_unlock(wd);
627 1.2.2.2 bouyer bad4:
628 1.2.2.2 bouyer return (error);
629 1.2.2.2 bouyer }
630 1.2.2.2 bouyer
631 1.2.2.2 bouyer int
632 1.2.2.2 bouyer edmcaclose(dev, flag, fmt, p)
633 1.2.2.2 bouyer dev_t dev;
634 1.2.2.2 bouyer int flag, fmt;
635 1.2.2.2 bouyer struct proc *p;
636 1.2.2.2 bouyer {
637 1.2.2.2 bouyer struct ed_softc *wd = device_lookup(&ed_cd, DISKUNIT(dev));
638 1.2.2.2 bouyer int part = DISKPART(dev);
639 1.2.2.2 bouyer int error;
640 1.2.2.2 bouyer
641 1.2.2.2 bouyer WDCDEBUG_PRINT(("edmcaclose\n"), DEBUG_FUNCS);
642 1.2.2.2 bouyer if ((error = ed_lock(wd)) != 0)
643 1.2.2.2 bouyer return error;
644 1.2.2.2 bouyer
645 1.2.2.2 bouyer switch (fmt) {
646 1.2.2.2 bouyer case S_IFCHR:
647 1.2.2.2 bouyer wd->sc_dk.dk_copenmask &= ~(1 << part);
648 1.2.2.2 bouyer break;
649 1.2.2.2 bouyer case S_IFBLK:
650 1.2.2.2 bouyer wd->sc_dk.dk_bopenmask &= ~(1 << part);
651 1.2.2.2 bouyer break;
652 1.2.2.2 bouyer }
653 1.2.2.2 bouyer wd->sc_dk.dk_openmask =
654 1.2.2.2 bouyer wd->sc_dk.dk_copenmask | wd->sc_dk.dk_bopenmask;
655 1.2.2.2 bouyer
656 1.2.2.2 bouyer if (wd->sc_dk.dk_openmask == 0) {
657 1.2.2.2 bouyer #if 0
658 1.2.2.2 bouyer wd_flushcache(wd, AT_WAIT);
659 1.2.2.2 bouyer #endif
660 1.2.2.2 bouyer /* XXXX Must wait for I/O to complete! */
661 1.2.2.2 bouyer
662 1.2.2.2 bouyer if (! (wd->sc_flags & WDF_KLABEL))
663 1.2.2.2 bouyer wd->sc_flags &= ~WDF_LOADED;
664 1.2.2.2 bouyer }
665 1.2.2.2 bouyer
666 1.2.2.2 bouyer ed_unlock(wd);
667 1.2.2.2 bouyer
668 1.2.2.2 bouyer return 0;
669 1.2.2.2 bouyer }
670 1.2.2.2 bouyer
671 1.2.2.2 bouyer static void
672 1.2.2.2 bouyer edgetdefaultlabel(wd, lp)
673 1.2.2.2 bouyer struct ed_softc *wd;
674 1.2.2.2 bouyer struct disklabel *lp;
675 1.2.2.2 bouyer {
676 1.2.2.2 bouyer WDCDEBUG_PRINT(("edgetdefaultlabel\n"), DEBUG_FUNCS);
677 1.2.2.2 bouyer memset(lp, 0, sizeof(struct disklabel));
678 1.2.2.2 bouyer
679 1.2.2.2 bouyer lp->d_secsize = DEV_BSIZE;
680 1.2.2.2 bouyer lp->d_ntracks = wd->heads;
681 1.2.2.2 bouyer lp->d_nsectors = wd->sectors;
682 1.2.2.2 bouyer lp->d_ncylinders = wd->cyl;
683 1.2.2.2 bouyer lp->d_secpercyl = lp->d_ntracks * lp->d_nsectors;
684 1.2.2.2 bouyer
685 1.2.2.2 bouyer lp->d_type = DTYPE_ESDI;
686 1.2.2.2 bouyer
687 1.2.2.2 bouyer strncpy(lp->d_typename, "ESDI", 16);
688 1.2.2.2 bouyer strncpy(lp->d_packname, "fictitious", 16);
689 1.2.2.2 bouyer lp->d_secperunit = wd->sc_capacity;
690 1.2.2.2 bouyer lp->d_rpm = 3600;
691 1.2.2.2 bouyer lp->d_interleave = 1;
692 1.2.2.2 bouyer lp->d_flags = 0;
693 1.2.2.2 bouyer
694 1.2.2.2 bouyer lp->d_partitions[RAW_PART].p_offset = 0;
695 1.2.2.2 bouyer lp->d_partitions[RAW_PART].p_size =
696 1.2.2.2 bouyer lp->d_secperunit * (lp->d_secsize / DEV_BSIZE);
697 1.2.2.2 bouyer lp->d_partitions[RAW_PART].p_fstype = FS_UNUSED;
698 1.2.2.2 bouyer lp->d_npartitions = RAW_PART + 1;
699 1.2.2.2 bouyer
700 1.2.2.2 bouyer lp->d_magic = DISKMAGIC;
701 1.2.2.2 bouyer lp->d_magic2 = DISKMAGIC;
702 1.2.2.2 bouyer lp->d_checksum = dkcksum(lp);
703 1.2.2.2 bouyer }
704 1.2.2.2 bouyer
705 1.2.2.2 bouyer /*
706 1.2.2.2 bouyer * Fabricate a default disk label, and try to read the correct one.
707 1.2.2.2 bouyer */
708 1.2.2.2 bouyer static void
709 1.2.2.2 bouyer edgetdisklabel(wd)
710 1.2.2.2 bouyer struct ed_softc *wd;
711 1.2.2.2 bouyer {
712 1.2.2.2 bouyer struct disklabel *lp = wd->sc_dk.dk_label;
713 1.2.2.2 bouyer char *errstring;
714 1.2.2.2 bouyer
715 1.2.2.2 bouyer WDCDEBUG_PRINT(("edgetdisklabel\n"), DEBUG_FUNCS);
716 1.2.2.2 bouyer
717 1.2.2.2 bouyer memset(wd->sc_dk.dk_cpulabel, 0, sizeof(struct cpu_disklabel));
718 1.2.2.2 bouyer
719 1.2.2.2 bouyer edgetdefaultlabel(wd, lp);
720 1.2.2.2 bouyer
721 1.2.2.2 bouyer #if 0
722 1.2.2.2 bouyer wd->sc_badsect[0] = -1;
723 1.2.2.2 bouyer
724 1.2.2.2 bouyer if (wd->drvp->state > RECAL)
725 1.2.2.2 bouyer wd->drvp->drive_flags |= DRIVE_RESET;
726 1.2.2.2 bouyer #endif
727 1.2.2.2 bouyer errstring = readdisklabel(MAKEDISKDEV(0, wd->sc_dev.dv_unit, RAW_PART),
728 1.2.2.2 bouyer edmcastrategy, lp, wd->sc_dk.dk_cpulabel);
729 1.2.2.2 bouyer if (errstring) {
730 1.2.2.2 bouyer /*
731 1.2.2.2 bouyer * This probably happened because the drive's default
732 1.2.2.2 bouyer * geometry doesn't match the DOS geometry. We
733 1.2.2.2 bouyer * assume the DOS geometry is now in the label and try
734 1.2.2.2 bouyer * again. XXX This is a kluge.
735 1.2.2.2 bouyer */
736 1.2.2.2 bouyer #if 0
737 1.2.2.2 bouyer if (wd->drvp->state > RECAL)
738 1.2.2.2 bouyer wd->drvp->drive_flags |= DRIVE_RESET;
739 1.2.2.2 bouyer #endif
740 1.2.2.2 bouyer errstring = readdisklabel(MAKEDISKDEV(0, wd->sc_dev.dv_unit,
741 1.2.2.2 bouyer RAW_PART), edmcastrategy, lp, wd->sc_dk.dk_cpulabel);
742 1.2.2.2 bouyer }
743 1.2.2.2 bouyer if (errstring) {
744 1.2.2.2 bouyer printf("%s: %s\n", wd->sc_dev.dv_xname, errstring);
745 1.2.2.2 bouyer return;
746 1.2.2.2 bouyer }
747 1.2.2.2 bouyer
748 1.2.2.2 bouyer #if 0
749 1.2.2.2 bouyer if (wd->drvp->state > RECAL)
750 1.2.2.2 bouyer wd->drvp->drive_flags |= DRIVE_RESET;
751 1.2.2.2 bouyer #endif
752 1.2.2.2 bouyer #ifdef HAS_BAD144_HANDLING
753 1.2.2.2 bouyer if ((lp->d_flags & D_BADSECT) != 0)
754 1.2.2.2 bouyer bad144intern(wd);
755 1.2.2.2 bouyer #endif
756 1.2.2.2 bouyer }
757 1.2.2.2 bouyer
758 1.2.2.2 bouyer int
759 1.2.2.2 bouyer edmcaioctl(dev, xfer, addr, flag, p)
760 1.2.2.2 bouyer dev_t dev;
761 1.2.2.2 bouyer u_long xfer;
762 1.2.2.2 bouyer caddr_t addr;
763 1.2.2.2 bouyer int flag;
764 1.2.2.2 bouyer struct proc *p;
765 1.2.2.2 bouyer {
766 1.2.2.2 bouyer struct ed_softc *wd = device_lookup(&ed_cd, DISKUNIT(dev));
767 1.2.2.2 bouyer int error;
768 1.2.2.2 bouyer #ifdef __HAVE_OLD_DISKLABEL
769 1.2.2.2 bouyer struct disklabel newlabel;
770 1.2.2.2 bouyer #endif
771 1.2.2.2 bouyer
772 1.2.2.2 bouyer WDCDEBUG_PRINT(("wdioctl\n"), DEBUG_FUNCS);
773 1.2.2.2 bouyer
774 1.2.2.2 bouyer if ((wd->sc_flags & WDF_LOADED) == 0)
775 1.2.2.2 bouyer return EIO;
776 1.2.2.2 bouyer
777 1.2.2.2 bouyer switch (xfer) {
778 1.2.2.2 bouyer #ifdef HAS_BAD144_HANDLING
779 1.2.2.2 bouyer case DIOCSBAD:
780 1.2.2.2 bouyer if ((flag & FWRITE) == 0)
781 1.2.2.2 bouyer return EBADF;
782 1.2.2.2 bouyer wd->sc_dk.dk_cpulabel->bad = *(struct dkbad *)addr;
783 1.2.2.2 bouyer wd->sc_dk.dk_label->d_flags |= D_BADSECT;
784 1.2.2.2 bouyer bad144intern(wd);
785 1.2.2.2 bouyer return 0;
786 1.2.2.2 bouyer #endif
787 1.2.2.2 bouyer
788 1.2.2.2 bouyer case DIOCGDINFO:
789 1.2.2.2 bouyer *(struct disklabel *)addr = *(wd->sc_dk.dk_label);
790 1.2.2.2 bouyer return 0;
791 1.2.2.2 bouyer #ifdef __HAVE_OLD_DISKLABEL
792 1.2.2.2 bouyer case ODIOCGDINFO:
793 1.2.2.2 bouyer newlabel = *(wd->sc_dk.dk_label);
794 1.2.2.2 bouyer if (newlabel.d_npartitions > OLDMAXPARTITIONS)
795 1.2.2.2 bouyer return ENOTTY;
796 1.2.2.2 bouyer memcpy(addr, &newlabel, sizeof (struct olddisklabel));
797 1.2.2.2 bouyer return 0;
798 1.2.2.2 bouyer #endif
799 1.2.2.2 bouyer
800 1.2.2.2 bouyer case DIOCGPART:
801 1.2.2.2 bouyer ((struct partinfo *)addr)->disklab = wd->sc_dk.dk_label;
802 1.2.2.2 bouyer ((struct partinfo *)addr)->part =
803 1.2.2.2 bouyer &wd->sc_dk.dk_label->d_partitions[DISKPART(dev)];
804 1.2.2.2 bouyer return 0;
805 1.2.2.2 bouyer
806 1.2.2.2 bouyer case DIOCWDINFO:
807 1.2.2.2 bouyer case DIOCSDINFO:
808 1.2.2.2 bouyer #ifdef __HAVE_OLD_DISKLABEL
809 1.2.2.2 bouyer case ODIOCWDINFO:
810 1.2.2.2 bouyer case ODIOCSDINFO:
811 1.2.2.2 bouyer #endif
812 1.2.2.2 bouyer {
813 1.2.2.2 bouyer struct disklabel *lp;
814 1.2.2.2 bouyer
815 1.2.2.2 bouyer #ifdef __HAVE_OLD_DISKLABEL
816 1.2.2.2 bouyer if (xfer == ODIOCSDINFO || xfer == ODIOCWDINFO) {
817 1.2.2.2 bouyer memset(&newlabel, 0, sizeof newlabel);
818 1.2.2.2 bouyer memcpy(&newlabel, addr, sizeof (struct olddisklabel));
819 1.2.2.2 bouyer lp = &newlabel;
820 1.2.2.2 bouyer } else
821 1.2.2.2 bouyer #endif
822 1.2.2.2 bouyer lp = (struct disklabel *)addr;
823 1.2.2.2 bouyer
824 1.2.2.2 bouyer if ((flag & FWRITE) == 0)
825 1.2.2.2 bouyer return EBADF;
826 1.2.2.2 bouyer
827 1.2.2.2 bouyer if ((error = ed_lock(wd)) != 0)
828 1.2.2.2 bouyer return error;
829 1.2.2.2 bouyer wd->sc_flags |= WDF_LABELLING;
830 1.2.2.2 bouyer
831 1.2.2.2 bouyer error = setdisklabel(wd->sc_dk.dk_label,
832 1.2.2.2 bouyer lp, /*wd->sc_dk.dk_openmask : */0,
833 1.2.2.2 bouyer wd->sc_dk.dk_cpulabel);
834 1.2.2.2 bouyer if (error == 0) {
835 1.2.2.2 bouyer #if 0
836 1.2.2.2 bouyer if (wd->drvp->state > RECAL)
837 1.2.2.2 bouyer wd->drvp->drive_flags |= DRIVE_RESET;
838 1.2.2.2 bouyer #endif
839 1.2.2.2 bouyer if (xfer == DIOCWDINFO
840 1.2.2.2 bouyer #ifdef __HAVE_OLD_DISKLABEL
841 1.2.2.2 bouyer || xfer == ODIOCWDINFO
842 1.2.2.2 bouyer #endif
843 1.2.2.2 bouyer )
844 1.2.2.2 bouyer error = writedisklabel(EDLABELDEV(dev),
845 1.2.2.2 bouyer edmcastrategy, wd->sc_dk.dk_label,
846 1.2.2.2 bouyer wd->sc_dk.dk_cpulabel);
847 1.2.2.2 bouyer }
848 1.2.2.2 bouyer
849 1.2.2.2 bouyer wd->sc_flags &= ~WDF_LABELLING;
850 1.2.2.2 bouyer ed_unlock(wd);
851 1.2.2.2 bouyer return error;
852 1.2.2.2 bouyer }
853 1.2.2.2 bouyer
854 1.2.2.2 bouyer case DIOCKLABEL:
855 1.2.2.2 bouyer if (*(int *)addr)
856 1.2.2.2 bouyer wd->sc_flags |= WDF_KLABEL;
857 1.2.2.2 bouyer else
858 1.2.2.2 bouyer wd->sc_flags &= ~WDF_KLABEL;
859 1.2.2.2 bouyer return 0;
860 1.2.2.2 bouyer
861 1.2.2.2 bouyer case DIOCWLABEL:
862 1.2.2.2 bouyer if ((flag & FWRITE) == 0)
863 1.2.2.2 bouyer return EBADF;
864 1.2.2.2 bouyer if (*(int *)addr)
865 1.2.2.2 bouyer wd->sc_flags |= WDF_WLABEL;
866 1.2.2.2 bouyer else
867 1.2.2.2 bouyer wd->sc_flags &= ~WDF_WLABEL;
868 1.2.2.2 bouyer return 0;
869 1.2.2.2 bouyer
870 1.2.2.2 bouyer case DIOCGDEFLABEL:
871 1.2.2.2 bouyer edgetdefaultlabel(wd, (struct disklabel *)addr);
872 1.2.2.2 bouyer return 0;
873 1.2.2.2 bouyer #ifdef __HAVE_OLD_DISKLABEL
874 1.2.2.2 bouyer case ODIOCGDEFLABEL:
875 1.2.2.2 bouyer edgetdefaultlabel(wd, &newlabel);
876 1.2.2.2 bouyer if (newlabel.d_npartitions > OLDMAXPARTITIONS)
877 1.2.2.2 bouyer return ENOTTY;
878 1.2.2.2 bouyer memcpy(addr, &newlabel, sizeof (struct olddisklabel));
879 1.2.2.2 bouyer return 0;
880 1.2.2.2 bouyer #endif
881 1.2.2.2 bouyer
882 1.2.2.2 bouyer #ifdef notyet
883 1.2.2.2 bouyer case DIOCWFORMAT:
884 1.2.2.2 bouyer if ((flag & FWRITE) == 0)
885 1.2.2.2 bouyer return EBADF;
886 1.2.2.2 bouyer {
887 1.2.2.2 bouyer register struct format_op *fop;
888 1.2.2.2 bouyer struct iovec aiov;
889 1.2.2.2 bouyer struct uio auio;
890 1.2.2.2 bouyer
891 1.2.2.2 bouyer fop = (struct format_op *)addr;
892 1.2.2.2 bouyer aiov.iov_base = fop->df_buf;
893 1.2.2.2 bouyer aiov.iov_len = fop->df_count;
894 1.2.2.2 bouyer auio.uio_iov = &aiov;
895 1.2.2.2 bouyer auio.uio_iovcnt = 1;
896 1.2.2.2 bouyer auio.uio_resid = fop->df_count;
897 1.2.2.2 bouyer auio.uio_segflg = 0;
898 1.2.2.2 bouyer auio.uio_offset =
899 1.2.2.2 bouyer fop->df_startblk * wd->sc_dk.dk_label->d_secsize;
900 1.2.2.2 bouyer auio.uio_procp = p;
901 1.2.2.2 bouyer error = physio(wdformat, NULL, dev, B_WRITE, minphys,
902 1.2.2.2 bouyer &auio);
903 1.2.2.2 bouyer fop->df_count -= auio.uio_resid;
904 1.2.2.2 bouyer fop->df_reg[0] = wdc->sc_status;
905 1.2.2.2 bouyer fop->df_reg[1] = wdc->sc_error;
906 1.2.2.2 bouyer return error;
907 1.2.2.2 bouyer }
908 1.2.2.2 bouyer #endif
909 1.2.2.2 bouyer
910 1.2.2.2 bouyer default:
911 1.2.2.2 bouyer return ENOTTY;
912 1.2.2.2 bouyer }
913 1.2.2.2 bouyer
914 1.2.2.2 bouyer #ifdef DIAGNOSTIC
915 1.2.2.2 bouyer panic("wdioctl: impossible");
916 1.2.2.2 bouyer #endif
917 1.2.2.2 bouyer }
918 1.2.2.2 bouyer
919 1.2.2.2 bouyer #if 0
920 1.2.2.2 bouyer #ifdef B_FORMAT
921 1.2.2.2 bouyer int
922 1.2.2.2 bouyer edmcaformat(struct buf *bp)
923 1.2.2.2 bouyer {
924 1.2.2.2 bouyer
925 1.2.2.2 bouyer bp->b_flags |= B_FORMAT;
926 1.2.2.2 bouyer return edmcastrategy(bp);
927 1.2.2.2 bouyer }
928 1.2.2.2 bouyer #endif
929 1.2.2.2 bouyer #endif
930 1.2.2.2 bouyer
931 1.2.2.2 bouyer int
932 1.2.2.2 bouyer edmcasize(dev)
933 1.2.2.2 bouyer dev_t dev;
934 1.2.2.2 bouyer {
935 1.2.2.2 bouyer struct ed_softc *wd;
936 1.2.2.2 bouyer int part, omask;
937 1.2.2.2 bouyer int size;
938 1.2.2.2 bouyer
939 1.2.2.2 bouyer WDCDEBUG_PRINT(("edsize\n"), DEBUG_FUNCS);
940 1.2.2.2 bouyer
941 1.2.2.2 bouyer wd = device_lookup(&ed_cd, DISKUNIT(dev));
942 1.2.2.2 bouyer if (wd == NULL)
943 1.2.2.2 bouyer return (-1);
944 1.2.2.2 bouyer
945 1.2.2.2 bouyer part = DISKPART(dev);
946 1.2.2.2 bouyer omask = wd->sc_dk.dk_openmask & (1 << part);
947 1.2.2.2 bouyer
948 1.2.2.2 bouyer if (omask == 0 && edmcaopen(dev, 0, S_IFBLK, NULL) != 0)
949 1.2.2.2 bouyer return (-1);
950 1.2.2.2 bouyer if (wd->sc_dk.dk_label->d_partitions[part].p_fstype != FS_SWAP)
951 1.2.2.2 bouyer size = -1;
952 1.2.2.2 bouyer else
953 1.2.2.2 bouyer size = wd->sc_dk.dk_label->d_partitions[part].p_size *
954 1.2.2.2 bouyer (wd->sc_dk.dk_label->d_secsize / DEV_BSIZE);
955 1.2.2.2 bouyer if (omask == 0 && edmcaclose(dev, 0, S_IFBLK, NULL) != 0)
956 1.2.2.2 bouyer return (-1);
957 1.2.2.2 bouyer return (size);
958 1.2.2.2 bouyer }
959 1.2.2.2 bouyer
960 1.2.2.2 bouyer /* #define WD_DUMP_NOT_TRUSTED if you just want to watch */
961 1.2.2.2 bouyer static int wddoingadump = 0;
962 1.2.2.2 bouyer static int wddumprecalibrated = 0;
963 1.2.2.2 bouyer
964 1.2.2.2 bouyer /*
965 1.2.2.2 bouyer * Dump core after a system crash.
966 1.2.2.2 bouyer */
967 1.2.2.2 bouyer int
968 1.2.2.2 bouyer edmcadump(dev, blkno, va, size)
969 1.2.2.2 bouyer dev_t dev;
970 1.2.2.2 bouyer daddr_t blkno;
971 1.2.2.2 bouyer caddr_t va;
972 1.2.2.2 bouyer size_t size;
973 1.2.2.2 bouyer {
974 1.2.2.2 bouyer struct ed_softc *wd; /* disk unit to do the I/O */
975 1.2.2.2 bouyer struct disklabel *lp; /* disk's disklabel */
976 1.2.2.2 bouyer int part; // , err;
977 1.2.2.2 bouyer int nblks; /* total number of sectors left to write */
978 1.2.2.2 bouyer
979 1.2.2.2 bouyer /* Check if recursive dump; if so, punt. */
980 1.2.2.2 bouyer if (wddoingadump)
981 1.2.2.2 bouyer return EFAULT;
982 1.2.2.2 bouyer wddoingadump = 1;
983 1.2.2.2 bouyer
984 1.2.2.2 bouyer wd = device_lookup(&ed_cd, DISKUNIT(dev));
985 1.2.2.2 bouyer if (wd == NULL)
986 1.2.2.2 bouyer return (ENXIO);
987 1.2.2.2 bouyer
988 1.2.2.2 bouyer part = DISKPART(dev);
989 1.2.2.2 bouyer
990 1.2.2.2 bouyer #if 0
991 1.2.2.2 bouyer /* Make sure it was initialized. */
992 1.2.2.2 bouyer if (wd->drvp->state < READY)
993 1.2.2.2 bouyer return ENXIO;
994 1.2.2.2 bouyer #endif
995 1.2.2.2 bouyer
996 1.2.2.2 bouyer /* Convert to disk sectors. Request must be a multiple of size. */
997 1.2.2.2 bouyer lp = wd->sc_dk.dk_label;
998 1.2.2.2 bouyer if ((size % lp->d_secsize) != 0)
999 1.2.2.2 bouyer return EFAULT;
1000 1.2.2.2 bouyer nblks = size / lp->d_secsize;
1001 1.2.2.2 bouyer blkno = blkno / (lp->d_secsize / DEV_BSIZE);
1002 1.2.2.2 bouyer
1003 1.2.2.2 bouyer /* Check transfer bounds against partition size. */
1004 1.2.2.2 bouyer if ((blkno < 0) || ((blkno + nblks) > lp->d_partitions[part].p_size))
1005 1.2.2.2 bouyer return EINVAL;
1006 1.2.2.2 bouyer
1007 1.2.2.2 bouyer /* Offset block number to start of partition. */
1008 1.2.2.2 bouyer blkno += lp->d_partitions[part].p_offset;
1009 1.2.2.2 bouyer
1010 1.2.2.2 bouyer /* Recalibrate, if first dump transfer. */
1011 1.2.2.2 bouyer if (wddumprecalibrated == 0) {
1012 1.2.2.2 bouyer wddumprecalibrated = 1;
1013 1.2.2.2 bouyer #if 0
1014 1.2.2.2 bouyer wd->drvp->state = RESET;
1015 1.2.2.2 bouyer #endif
1016 1.2.2.2 bouyer }
1017 1.2.2.2 bouyer
1018 1.2.2.2 bouyer while (nblks > 0) {
1019 1.2.2.2 bouyer #if 0
1020 1.2.2.2 bouyer wd->sc_wdc_bio.blkno = blkno;
1021 1.2.2.2 bouyer wd->sc_wdc_bio.flags = ATA_POLL;
1022 1.2.2.2 bouyer wd->sc_wdc_bio.bcount = lp->d_secsize;
1023 1.2.2.2 bouyer wd->sc_wdc_bio.databuf = va;
1024 1.2.2.2 bouyer #ifndef WD_DUMP_NOT_TRUSTED
1025 1.2.2.2 bouyer switch (wdc_ata_bio(wd->drvp, &wd->sc_wdc_bio)) {
1026 1.2.2.2 bouyer case WDC_TRY_AGAIN:
1027 1.2.2.2 bouyer panic("wddump: try again");
1028 1.2.2.2 bouyer break;
1029 1.2.2.2 bouyer case WDC_QUEUED:
1030 1.2.2.2 bouyer panic("wddump: polled command has been queued");
1031 1.2.2.2 bouyer break;
1032 1.2.2.2 bouyer case WDC_COMPLETE:
1033 1.2.2.2 bouyer break;
1034 1.2.2.2 bouyer }
1035 1.2.2.2 bouyer if (err != 0) {
1036 1.2.2.2 bouyer printf("\n");
1037 1.2.2.2 bouyer return err;
1038 1.2.2.2 bouyer }
1039 1.2.2.2 bouyer #else /* WD_DUMP_NOT_TRUSTED */
1040 1.2.2.2 bouyer /* Let's just talk about this first... */
1041 1.2.2.2 bouyer printf("ed%d: dump addr 0x%x, cylin %d, head %d, sector %d\n",
1042 1.2.2.2 bouyer unit, va, cylin, head, sector);
1043 1.2.2.2 bouyer delay(500 * 1000); /* half a second */
1044 1.2.2.2 bouyer #endif
1045 1.2.2.2 bouyer #endif /* 0 */
1046 1.2.2.2 bouyer
1047 1.2.2.2 bouyer /* update block count */
1048 1.2.2.2 bouyer nblks -= 1;
1049 1.2.2.2 bouyer blkno += 1;
1050 1.2.2.2 bouyer va += lp->d_secsize;
1051 1.2.2.2 bouyer }
1052 1.2.2.2 bouyer
1053 1.2.2.2 bouyer wddoingadump = 0;
1054 1.2.2.2 bouyer return (ESPIPE);
1055 1.2.2.2 bouyer }
1056 1.2.2.2 bouyer
1057 1.2.2.2 bouyer #ifdef HAS_BAD144_HANDLING
1058 1.2.2.2 bouyer /*
1059 1.2.2.2 bouyer * Internalize the bad sector table.
1060 1.2.2.2 bouyer */
1061 1.2.2.2 bouyer static void
1062 1.2.2.2 bouyer bad144intern(wd)
1063 1.2.2.2 bouyer struct ed_softc *wd;
1064 1.2.2.2 bouyer {
1065 1.2.2.2 bouyer struct dkbad *bt = &wd->sc_dk.dk_cpulabel->bad;
1066 1.2.2.2 bouyer struct disklabel *lp = wd->sc_dk.dk_label;
1067 1.2.2.2 bouyer int i = 0;
1068 1.2.2.2 bouyer
1069 1.2.2.2 bouyer WDCDEBUG_PRINT(("bad144intern\n"), DEBUG_XFERS);
1070 1.2.2.2 bouyer
1071 1.2.2.2 bouyer for (; i < NBT_BAD; i++) {
1072 1.2.2.2 bouyer if (bt->bt_bad[i].bt_cyl == 0xffff)
1073 1.2.2.2 bouyer break;
1074 1.2.2.2 bouyer wd->sc_badsect[i] =
1075 1.2.2.2 bouyer bt->bt_bad[i].bt_cyl * lp->d_secpercyl +
1076 1.2.2.2 bouyer (bt->bt_bad[i].bt_trksec >> 8) * lp->d_nsectors +
1077 1.2.2.2 bouyer (bt->bt_bad[i].bt_trksec & 0xff);
1078 1.2.2.2 bouyer }
1079 1.2.2.2 bouyer for (; i < NBT_BAD+1; i++)
1080 1.2.2.2 bouyer wd->sc_badsect[i] = -1;
1081 1.2.2.2 bouyer }
1082 1.2.2.2 bouyer #endif
1083 1.2.2.2 bouyer
1084 1.2.2.2 bouyer static int
1085 1.2.2.2 bouyer ed_get_params(ed)
1086 1.2.2.2 bouyer struct ed_softc *ed;
1087 1.2.2.2 bouyer {
1088 1.2.2.2 bouyer u_int16_t cmd_args[2];
1089 1.2.2.2 bouyer
1090 1.2.2.2 bouyer /*
1091 1.2.2.2 bouyer * Get Device Configuration (09).
1092 1.2.2.2 bouyer */
1093 1.2.2.2 bouyer cmd_args[0] = 6; /* Options: 00s110, s: 0=Physical 1=Pseudo */
1094 1.2.2.2 bouyer cmd_args[1] = 0;
1095 1.2.2.2 bouyer if (dasd_run_cmd(ed->dasd_softc, CMD_GET_DEV_CONF, ed->sc_devno, cmd_args, 2, 0))
1096 1.2.2.2 bouyer return (1);
1097 1.2.2.2 bouyer
1098 1.2.2.2 bouyer ed->spares = ed->sc_status_block[1] >> 8;
1099 1.2.2.2 bouyer ed->drv_flags = ed->sc_status_block[1] & 0x1f;
1100 1.2.2.2 bouyer ed->rba = ed->sc_status_block[2] |
1101 1.2.2.2 bouyer (ed->sc_status_block[3] << 16);
1102 1.2.2.2 bouyer /* Instead of using:
1103 1.2.2.2 bouyer ed->cyl = ed->sc_status_block[4];
1104 1.2.2.2 bouyer ed->heads = ed->sc_status_block[5] & 0xff;
1105 1.2.2.2 bouyer ed->sectors = ed->sc_status_block[5] >> 8;
1106 1.2.2.2 bouyer * we fabricate the numbers from RBA count, so that
1107 1.2.2.2 bouyer * number of sectors is 32 and heads 64. This seems
1108 1.2.2.2 bouyer * to be necessary for integrated ESDI controller.
1109 1.2.2.2 bouyer */
1110 1.2.2.2 bouyer ed->sectors = 32;
1111 1.2.2.2 bouyer ed->heads = 64;
1112 1.2.2.2 bouyer ed->cyl = ed->rba / (ed->heads * ed->sectors);
1113 1.2.2.2 bouyer ed->sc_capacity = ed->rba;
1114 1.2.2.2 bouyer
1115 1.2.2.2 bouyer return (0);
1116 1.2.2.2 bouyer }
1117 1.2.2.2 bouyer
1118 1.2.2.2 bouyer /*
1119 1.2.2.2 bouyer * Our shutdown hook. We attempt to park disk's head only.
1120 1.2.2.2 bouyer */
1121 1.2.2.2 bouyer void
1122 1.2.2.2 bouyer ed_shutdown(arg)
1123 1.2.2.2 bouyer void *arg;
1124 1.2.2.2 bouyer {
1125 1.2.2.2 bouyer #if 0
1126 1.2.2.2 bouyer struct ed_softc *ed = arg;
1127 1.2.2.2 bouyer u_int16_t cmd_args[2];
1128 1.2.2.2 bouyer
1129 1.2.2.2 bouyer /* Issue Park Head command */
1130 1.2.2.2 bouyer cmd_args[0] = 6; /* Options: 000110 */
1131 1.2.2.2 bouyer cmd_args[1] = 0;
1132 1.2.2.2 bouyer (void) dasd_run_cmd(ed->dasd_softc, CMD_PARK_HEAD, ed->sc_devno,
1133 1.2.2.2 bouyer cmd_args, 2, 0);
1134 1.2.2.2 bouyer #endif
1135 1.2.2.2 bouyer }
1136 1.2.2.2 bouyer
1137 1.2.2.2 bouyer /*
1138 1.2.2.2 bouyer * Main worker thread function.
1139 1.2.2.2 bouyer */
1140 1.2.2.2 bouyer void
1141 1.2.2.2 bouyer edworker(arg)
1142 1.2.2.2 bouyer void *arg;
1143 1.2.2.2 bouyer {
1144 1.2.2.2 bouyer struct ed_softc *ed = (struct ed_softc *) arg;
1145 1.2.2.2 bouyer struct buf *bp;
1146 1.2.2.2 bouyer int s;
1147 1.2.2.2 bouyer
1148 1.2.2.2 bouyer config_pending_decr();
1149 1.2.2.2 bouyer
1150 1.2.2.2 bouyer for(;;) {
1151 1.2.2.2 bouyer /* Wait until awakened */
1152 1.2.2.2 bouyer (void) tsleep(&ed->sc_q, PRIBIO, "edidle", 0);
1153 1.2.2.2 bouyer
1154 1.2.2.2 bouyer if ((ed->sc_flags & EDF_PROCESS_QUEUE) == 0)
1155 1.2.2.2 bouyer panic("edworker: expecting process queue");
1156 1.2.2.2 bouyer ed->sc_flags &= ~EDF_PROCESS_QUEUE;
1157 1.2.2.2 bouyer
1158 1.2.2.2 bouyer for(;;) {
1159 1.2.2.2 bouyer /* Is there a buf for us ? */
1160 1.2.2.2 bouyer simple_lock(&ed->sc_q_lock);
1161 1.2.2.2 bouyer if ((bp = BUFQ_FIRST(&ed->sc_q)) == NULL) {
1162 1.2.2.2 bouyer simple_unlock(&ed->sc_q_lock);
1163 1.2.2.2 bouyer break;
1164 1.2.2.2 bouyer }
1165 1.2.2.2 bouyer BUFQ_REMOVE(&ed->sc_q, bp);
1166 1.2.2.2 bouyer simple_unlock(&ed->sc_q_lock);
1167 1.2.2.2 bouyer
1168 1.2.2.2 bouyer /* Schedule i/o operation */
1169 1.2.2.2 bouyer s = splbio();
1170 1.2.2.2 bouyer __edstart(ed, bp);
1171 1.2.2.2 bouyer splx(s);
1172 1.2.2.2 bouyer
1173 1.2.2.2 bouyer /*
1174 1.2.2.2 bouyer * Wait until the command executes; dasd_intr() wakes
1175 1.2.2.2 bouyer * as up.
1176 1.2.2.2 bouyer */
1177 1.2.2.2 bouyer (void) tsleep(&ed->dasd_softc, PRIBIO, "edwrk", 0);
1178 1.2.2.2 bouyer
1179 1.2.2.2 bouyer /* Handle i/o results */
1180 1.2.2.2 bouyer s = splbio();
1181 1.2.2.2 bouyer edmcadone(ed);
1182 1.2.2.2 bouyer splx(s);
1183 1.2.2.2 bouyer }
1184 1.2.2.2 bouyer }
1185 1.2.2.2 bouyer }
1186