ss.c revision 1.33.2.3 1 1.33.2.3 nathanw /* $NetBSD: ss.c,v 1.33.2.3 2001/11/14 19:16:05 nathanw Exp $ */
2 1.1 mycroft
3 1.1 mycroft /*
4 1.1 mycroft * Copyright (c) 1995 Kenneth Stailey. All rights reserved.
5 1.1 mycroft * modified for configurable scanner support by Joachim Koenig
6 1.1 mycroft *
7 1.1 mycroft * Redistribution and use in source and binary forms, with or without
8 1.1 mycroft * modification, are permitted provided that the following conditions
9 1.1 mycroft * are met:
10 1.1 mycroft * 1. Redistributions of source code must retain the above copyright
11 1.1 mycroft * notice, this list of conditions and the following disclaimer.
12 1.1 mycroft * 2. Redistributions in binary form must reproduce the above copyright
13 1.1 mycroft * notice, this list of conditions and the following disclaimer in the
14 1.1 mycroft * documentation and/or other materials provided with the distribution.
15 1.1 mycroft * 3. All advertising materials mentioning features or use of this software
16 1.1 mycroft * must display the following acknowledgement:
17 1.1 mycroft * This product includes software developed by Kenneth Stailey.
18 1.1 mycroft * 4. The name of the author may not be used to endorse or promote products
19 1.1 mycroft * derived from this software without specific prior written permission.
20 1.1 mycroft *
21 1.1 mycroft * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
22 1.1 mycroft * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
23 1.1 mycroft * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
24 1.1 mycroft * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
25 1.1 mycroft * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
26 1.1 mycroft * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
27 1.1 mycroft * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
28 1.1 mycroft * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29 1.1 mycroft * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
30 1.1 mycroft * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31 1.1 mycroft */
32 1.33.2.3 nathanw
33 1.33.2.3 nathanw #include <sys/cdefs.h>
34 1.33.2.3 nathanw __KERNEL_RCSID(0, "$NetBSD: ss.c,v 1.33.2.3 2001/11/14 19:16:05 nathanw Exp $");
35 1.1 mycroft
36 1.1 mycroft #include <sys/types.h>
37 1.1 mycroft #include <sys/param.h>
38 1.1 mycroft #include <sys/systm.h>
39 1.1 mycroft #include <sys/fcntl.h>
40 1.1 mycroft #include <sys/errno.h>
41 1.1 mycroft #include <sys/ioctl.h>
42 1.1 mycroft #include <sys/malloc.h>
43 1.1 mycroft #include <sys/buf.h>
44 1.1 mycroft #include <sys/proc.h>
45 1.1 mycroft #include <sys/user.h>
46 1.1 mycroft #include <sys/device.h>
47 1.9 christos #include <sys/conf.h>
48 1.32 augustss #include <sys/vnode.h>
49 1.1 mycroft #include <sys/scanio.h>
50 1.1 mycroft
51 1.16 bouyer #include <dev/scsipi/scsi_all.h>
52 1.16 bouyer #include <dev/scsipi/scsipi_all.h>
53 1.16 bouyer #include <dev/scsipi/scsi_scanner.h>
54 1.16 bouyer #include <dev/scsipi/scsiconf.h>
55 1.16 bouyer #include <dev/scsipi/ssvar.h>
56 1.1 mycroft
57 1.16 bouyer #include <dev/scsipi/ss_mustek.h>
58 1.1 mycroft
59 1.1 mycroft #define SSMODE(z) ( minor(z) & 0x03)
60 1.1 mycroft #define SSUNIT(z) ((minor(z) >> 4) )
61 1.33 augustss #define SSNMINOR 16
62 1.1 mycroft
63 1.1 mycroft /*
64 1.1 mycroft * If the mode is 3 (e.g. minor = 3,7,11,15)
65 1.1 mycroft * then the device has been openned to set defaults
66 1.1 mycroft * This mode does NOT ALLOW I/O, only ioctls
67 1.1 mycroft */
68 1.1 mycroft #define MODE_REWIND 0
69 1.1 mycroft #define MODE_NONREWIND 1
70 1.1 mycroft #define MODE_CONTROL 3
71 1.1 mycroft
72 1.32 augustss int ssmatch(struct device *, struct cfdata *, void *);
73 1.32 augustss void ssattach(struct device *, struct device *, void *);
74 1.32 augustss int ssdetach(struct device *self, int flags);
75 1.32 augustss int ssactivate(struct device *self, enum devact act);
76 1.1 mycroft
77 1.8 thorpej struct cfattach ss_ca = {
78 1.32 augustss sizeof(struct ss_softc), ssmatch, ssattach, ssdetach, ssactivate
79 1.8 thorpej };
80 1.8 thorpej
81 1.19 thorpej extern struct cfdriver ss_cd;
82 1.1 mycroft
83 1.1 mycroft void ssstrategy __P((struct buf *));
84 1.33.2.1 nathanw void ssstart __P((struct scsipi_periph *));
85 1.9 christos void ssminphys __P((struct buf *));
86 1.1 mycroft
87 1.33.2.1 nathanw const struct scsipi_periphsw ss_switch = {
88 1.1 mycroft NULL,
89 1.1 mycroft ssstart,
90 1.1 mycroft NULL,
91 1.1 mycroft NULL,
92 1.1 mycroft };
93 1.1 mycroft
94 1.16 bouyer struct scsipi_inquiry_pattern ss_patterns[] = {
95 1.1 mycroft {T_SCANNER, T_FIXED,
96 1.1 mycroft "", "", ""},
97 1.1 mycroft {T_SCANNER, T_REMOV,
98 1.1 mycroft "", "", ""},
99 1.1 mycroft {T_PROCESSOR, T_FIXED,
100 1.1 mycroft "HP ", "C1750A ", ""},
101 1.1 mycroft {T_PROCESSOR, T_FIXED,
102 1.1 mycroft "HP ", "C2500A ", ""},
103 1.14 thorpej {T_PROCESSOR, T_FIXED,
104 1.14 thorpej "HP ", "C1130A ", ""},
105 1.18 augustss {T_PROCESSOR, T_FIXED,
106 1.18 augustss "HP ", "C5110A ", ""},
107 1.31 phil {T_PROCESSOR, T_FIXED,
108 1.31 phil "HP ", "C7670A ", ""},
109 1.1 mycroft };
110 1.1 mycroft
111 1.1 mycroft int
112 1.32 augustss ssmatch(struct device *parent, struct cfdata *match, void *aux)
113 1.1 mycroft {
114 1.16 bouyer struct scsipibus_attach_args *sa = aux;
115 1.1 mycroft int priority;
116 1.1 mycroft
117 1.16 bouyer (void)scsipi_inqmatch(&sa->sa_inqbuf,
118 1.17 enami (caddr_t)ss_patterns, sizeof(ss_patterns) / sizeof(ss_patterns[0]),
119 1.1 mycroft sizeof(ss_patterns[0]), &priority);
120 1.1 mycroft return (priority);
121 1.1 mycroft }
122 1.1 mycroft
123 1.1 mycroft /*
124 1.1 mycroft * The routine called by the low level scsi routine when it discovers
125 1.1 mycroft * A device suitable for this driver
126 1.1 mycroft * If it is a know special, call special attach routine to install
127 1.1 mycroft * special handlers into the ss_softc structure
128 1.1 mycroft */
129 1.1 mycroft void
130 1.32 augustss ssattach(struct device *parent, struct device *self, void *aux)
131 1.1 mycroft {
132 1.1 mycroft struct ss_softc *ss = (void *)self;
133 1.16 bouyer struct scsipibus_attach_args *sa = aux;
134 1.33.2.1 nathanw struct scsipi_periph *periph = sa->sa_periph;
135 1.1 mycroft
136 1.33.2.1 nathanw SC_DEBUG(periph, SCSIPI_DB2, ("ssattach: "));
137 1.1 mycroft
138 1.20 pk ss->flags |= SSF_AUTOCONF;
139 1.20 pk
140 1.1 mycroft /*
141 1.1 mycroft * Store information needed to contact our base driver
142 1.1 mycroft */
143 1.33.2.1 nathanw ss->sc_periph = periph;
144 1.33.2.1 nathanw periph->periph_dev = &ss->sc_dev;
145 1.33.2.1 nathanw periph->periph_switch = &ss_switch;
146 1.28 abs
147 1.28 abs printf("\n");
148 1.1 mycroft
149 1.1 mycroft /*
150 1.1 mycroft * look for non-standard scanners with help of the quirk table
151 1.1 mycroft * and install functions for special handling
152 1.1 mycroft */
153 1.33.2.2 nathanw SC_DEBUG(periph, SCSIPI_DB2, ("ssattach:\n"));
154 1.32 augustss if (memcmp(sa->sa_inqbuf.vendor, "MUSTEK", 6) == 0)
155 1.1 mycroft mustek_attach(ss, sa);
156 1.32 augustss if (memcmp(sa->sa_inqbuf.vendor, "HP ", 8) == 0 &&
157 1.32 augustss memcmp(sa->sa_inqbuf.product, "ScanJet 5300C", 13) != 0)
158 1.1 mycroft scanjet_attach(ss, sa);
159 1.1 mycroft if (ss->special == NULL) {
160 1.1 mycroft /* XXX add code to restart a SCSI2 scanner, if any */
161 1.1 mycroft }
162 1.1 mycroft
163 1.1 mycroft /*
164 1.1 mycroft * Set up the buf queue for this device
165 1.1 mycroft */
166 1.29 thorpej BUFQ_INIT(&ss->buf_queue);
167 1.20 pk ss->flags &= ~SSF_AUTOCONF;
168 1.1 mycroft }
169 1.1 mycroft
170 1.32 augustss int
171 1.32 augustss ssdetach(struct device *self, int flags)
172 1.32 augustss {
173 1.32 augustss struct ss_softc *ss = (struct ss_softc *) self;
174 1.32 augustss struct buf *bp;
175 1.32 augustss int s, cmaj, mn;
176 1.32 augustss
177 1.32 augustss /* locate the major number */
178 1.32 augustss for (cmaj = 0; cmaj <= nchrdev; cmaj++)
179 1.32 augustss if (cdevsw[cmaj].d_open == ssopen)
180 1.32 augustss break;
181 1.32 augustss
182 1.32 augustss s = splbio();
183 1.32 augustss
184 1.32 augustss /* Kill off any queued buffers. */
185 1.32 augustss while ((bp = BUFQ_FIRST(&ss->buf_queue)) != NULL) {
186 1.32 augustss BUFQ_REMOVE(&ss->buf_queue, bp);
187 1.32 augustss bp->b_error = EIO;
188 1.32 augustss bp->b_flags |= B_ERROR;
189 1.32 augustss bp->b_resid = bp->b_bcount;
190 1.32 augustss biodone(bp);
191 1.32 augustss }
192 1.32 augustss
193 1.32 augustss /* Kill off any pending commands. */
194 1.33.2.1 nathanw scsipi_kill_pending(ss->sc_periph);
195 1.32 augustss
196 1.32 augustss splx(s);
197 1.32 augustss
198 1.32 augustss /* Nuke the vnodes for any open instances */
199 1.32 augustss mn = SSUNIT(self->dv_unit);
200 1.33 augustss vdevgone(cmaj, mn, mn+SSNMINOR-1, VCHR);
201 1.32 augustss
202 1.32 augustss return (0);
203 1.32 augustss }
204 1.32 augustss
205 1.32 augustss int
206 1.32 augustss ssactivate(struct device *self, enum devact act)
207 1.32 augustss {
208 1.32 augustss int rv = 0;
209 1.32 augustss
210 1.32 augustss switch (act) {
211 1.32 augustss case DVACT_ACTIVATE:
212 1.32 augustss rv = EOPNOTSUPP;
213 1.32 augustss break;
214 1.32 augustss
215 1.32 augustss case DVACT_DEACTIVATE:
216 1.32 augustss /*
217 1.32 augustss * Nothing to do; we key off the device's DVF_ACTIVE.
218 1.32 augustss */
219 1.32 augustss break;
220 1.32 augustss }
221 1.32 augustss return (rv);
222 1.32 augustss }
223 1.32 augustss
224 1.1 mycroft /*
225 1.1 mycroft * open the device.
226 1.1 mycroft */
227 1.1 mycroft int
228 1.32 augustss ssopen(dev_t dev, int flag, int mode, struct proc *p)
229 1.1 mycroft {
230 1.1 mycroft int unit;
231 1.5 mycroft u_int ssmode;
232 1.23 thorpej int error;
233 1.1 mycroft struct ss_softc *ss;
234 1.33.2.1 nathanw struct scsipi_periph *periph;
235 1.33.2.1 nathanw struct scsipi_adapter *adapt;
236 1.1 mycroft
237 1.1 mycroft unit = SSUNIT(dev);
238 1.8 thorpej if (unit >= ss_cd.cd_ndevs)
239 1.1 mycroft return (ENXIO);
240 1.8 thorpej ss = ss_cd.cd_devs[unit];
241 1.1 mycroft if (!ss)
242 1.1 mycroft return (ENXIO);
243 1.1 mycroft
244 1.32 augustss if ((ss->sc_dev.dv_flags & DVF_ACTIVE) == 0)
245 1.32 augustss return (ENODEV);
246 1.32 augustss
247 1.5 mycroft ssmode = SSMODE(dev);
248 1.1 mycroft
249 1.33.2.1 nathanw periph = ss->sc_periph;
250 1.33.2.1 nathanw adapt = periph->periph_channel->chan_adapter;
251 1.33.2.1 nathanw
252 1.33.2.1 nathanw SC_DEBUG(periph, SCSIPI_DB1, ("open: dev=0x%x (unit %d (of %d))\n", dev,
253 1.8 thorpej unit, ss_cd.cd_ndevs));
254 1.1 mycroft
255 1.33.2.1 nathanw if (periph->periph_flags & PERIPH_OPEN) {
256 1.13 christos printf("%s: already open\n", ss->sc_dev.dv_xname);
257 1.1 mycroft return (EBUSY);
258 1.1 mycroft }
259 1.1 mycroft
260 1.33.2.1 nathanw if ((error = scsipi_adapter_addref(adapt)) != 0)
261 1.23 thorpej return (error);
262 1.23 thorpej
263 1.1 mycroft /*
264 1.1 mycroft * Catch any unit attention errors.
265 1.1 mycroft *
266 1.26 thorpej * XS_CTL_IGNORE_MEDIA_CHANGE: when you have an ADF, some scanners
267 1.1 mycroft * consider paper to be a changeable media
268 1.1 mycroft *
269 1.1 mycroft */
270 1.33.2.1 nathanw error = scsipi_test_unit_ready(periph,
271 1.26 thorpej XS_CTL_IGNORE_MEDIA_CHANGE | XS_CTL_IGNORE_ILLEGAL_REQUEST |
272 1.26 thorpej (ssmode == MODE_CONTROL ? XS_CTL_IGNORE_NOT_READY : 0));
273 1.1 mycroft if (error)
274 1.1 mycroft goto bad;
275 1.1 mycroft
276 1.33.2.1 nathanw periph->periph_flags |= PERIPH_OPEN; /* unit attn now errors */
277 1.1 mycroft
278 1.1 mycroft /*
279 1.1 mycroft * If the mode is 3 (e.g. minor = 3,7,11,15)
280 1.1 mycroft * then the device has been opened to set defaults
281 1.1 mycroft * This mode does NOT ALLOW I/O, only ioctls
282 1.1 mycroft */
283 1.5 mycroft if (ssmode == MODE_CONTROL)
284 1.1 mycroft return (0);
285 1.1 mycroft
286 1.33.2.1 nathanw SC_DEBUG(periph, SCSIPI_DB2, ("open complete\n"));
287 1.1 mycroft return (0);
288 1.1 mycroft
289 1.1 mycroft bad:
290 1.33.2.1 nathanw scsipi_adapter_delref(adapt);
291 1.33.2.1 nathanw periph->periph_flags &= ~PERIPH_OPEN;
292 1.1 mycroft return (error);
293 1.1 mycroft }
294 1.1 mycroft
295 1.1 mycroft /*
296 1.1 mycroft * close the device.. only called if we are the LAST
297 1.1 mycroft * occurence of an open device
298 1.1 mycroft */
299 1.1 mycroft int
300 1.32 augustss ssclose(dev_t dev, int flag, int mode, struct proc *p)
301 1.1 mycroft {
302 1.8 thorpej struct ss_softc *ss = ss_cd.cd_devs[SSUNIT(dev)];
303 1.33.2.1 nathanw struct scsipi_periph *periph = ss->sc_periph;
304 1.33.2.1 nathanw struct scsipi_adapter *adapt = periph->periph_channel->chan_adapter;
305 1.1 mycroft int error;
306 1.1 mycroft
307 1.33.2.1 nathanw SC_DEBUG(ss->sc_periph, SCSIPI_DB1, ("closing\n"));
308 1.1 mycroft
309 1.1 mycroft if (SSMODE(dev) == MODE_REWIND) {
310 1.21 explorer if (ss->special && ss->special->rewind_scanner) {
311 1.1 mycroft /* call special handler to rewind/abort scan */
312 1.1 mycroft error = (ss->special->rewind_scanner)(ss);
313 1.1 mycroft if (error)
314 1.1 mycroft return (error);
315 1.1 mycroft } else {
316 1.1 mycroft /* XXX add code to restart a SCSI2 scanner, if any */
317 1.1 mycroft }
318 1.4 mycroft ss->sio.scan_window_size = 0;
319 1.1 mycroft ss->flags &= ~SSF_TRIGGERED;
320 1.1 mycroft }
321 1.24 thorpej
322 1.33.2.1 nathanw scsipi_wait_drain(periph);
323 1.23 thorpej
324 1.33.2.1 nathanw scsipi_adapter_delref(adapt);
325 1.33.2.1 nathanw periph->periph_flags &= ~PERIPH_OPEN;
326 1.1 mycroft
327 1.1 mycroft return (0);
328 1.1 mycroft }
329 1.1 mycroft
330 1.1 mycroft /*
331 1.1 mycroft * trim the size of the transfer if needed,
332 1.1 mycroft * called by physio
333 1.1 mycroft * basically the smaller of our min and the scsi driver's
334 1.1 mycroft * minphys
335 1.1 mycroft */
336 1.1 mycroft void
337 1.32 augustss ssminphys(struct buf *bp)
338 1.1 mycroft {
339 1.30 augustss struct ss_softc *ss = ss_cd.cd_devs[SSUNIT(bp->b_dev)];
340 1.33.2.1 nathanw struct scsipi_periph *periph = ss->sc_periph;
341 1.1 mycroft
342 1.33.2.1 nathanw (*periph->periph_channel->chan_adapter->adapt_minphys)(bp);
343 1.1 mycroft
344 1.1 mycroft /*
345 1.1 mycroft * trim the transfer further for special devices this is
346 1.1 mycroft * because some scanners only read multiples of a line at a
347 1.1 mycroft * time, also some cannot disconnect, so the read must be
348 1.1 mycroft * short enough to happen quickly
349 1.1 mycroft */
350 1.21 explorer if (ss->special && ss->special->minphys)
351 1.1 mycroft (ss->special->minphys)(ss, bp);
352 1.1 mycroft }
353 1.1 mycroft
354 1.1 mycroft /*
355 1.1 mycroft * Do a read on a device for a user process.
356 1.1 mycroft * Prime scanner at start of read, check uio values, call ssstrategy
357 1.1 mycroft * via physio for the actual transfer.
358 1.1 mycroft */
359 1.1 mycroft int
360 1.1 mycroft ssread(dev, uio, flag)
361 1.1 mycroft dev_t dev;
362 1.1 mycroft struct uio *uio;
363 1.1 mycroft int flag;
364 1.1 mycroft {
365 1.8 thorpej struct ss_softc *ss = ss_cd.cd_devs[SSUNIT(dev)];
366 1.1 mycroft int error;
367 1.1 mycroft
368 1.32 augustss if ((ss->sc_dev.dv_flags & DVF_ACTIVE) == 0)
369 1.32 augustss return (ENODEV);
370 1.32 augustss
371 1.1 mycroft /* if the scanner has not yet been started, do it now */
372 1.1 mycroft if (!(ss->flags & SSF_TRIGGERED)) {
373 1.21 explorer if (ss->special && ss->special->trigger_scanner) {
374 1.1 mycroft error = (ss->special->trigger_scanner)(ss);
375 1.1 mycroft if (error)
376 1.1 mycroft return (error);
377 1.1 mycroft }
378 1.1 mycroft ss->flags |= SSF_TRIGGERED;
379 1.1 mycroft }
380 1.1 mycroft
381 1.1 mycroft return (physio(ssstrategy, NULL, dev, B_READ, ssminphys, uio));
382 1.1 mycroft }
383 1.1 mycroft
384 1.1 mycroft /*
385 1.1 mycroft * Actually translate the requested transfer into one the physical
386 1.1 mycroft * driver can understand The transfer is described by a buf and will
387 1.1 mycroft * include only one physical transfer.
388 1.1 mycroft */
389 1.1 mycroft void
390 1.1 mycroft ssstrategy(bp)
391 1.1 mycroft struct buf *bp;
392 1.1 mycroft {
393 1.8 thorpej struct ss_softc *ss = ss_cd.cd_devs[SSUNIT(bp->b_dev)];
394 1.33.2.1 nathanw struct scsipi_periph *periph = ss->sc_periph;
395 1.1 mycroft int s;
396 1.1 mycroft
397 1.33.2.1 nathanw SC_DEBUG(ss->sc_periph, SCSIPI_DB1,
398 1.10 christos ("ssstrategy %ld bytes @ blk %d\n", bp->b_bcount, bp->b_blkno));
399 1.25 bouyer
400 1.32 augustss /*
401 1.32 augustss * If the device has been made invalid, error out
402 1.32 augustss */
403 1.32 augustss if ((ss->sc_dev.dv_flags & DVF_ACTIVE) == 0) {
404 1.32 augustss bp->b_flags |= B_ERROR;
405 1.33.2.1 nathanw if (periph->periph_flags & PERIPH_OPEN)
406 1.32 augustss bp->b_error = EIO;
407 1.32 augustss else
408 1.32 augustss bp->b_error = ENODEV;
409 1.32 augustss goto done;
410 1.32 augustss }
411 1.32 augustss
412 1.25 bouyer /* If negative offset, error */
413 1.25 bouyer if (bp->b_blkno < 0) {
414 1.25 bouyer bp->b_flags |= B_ERROR;
415 1.25 bouyer bp->b_error = EINVAL;
416 1.25 bouyer goto done;
417 1.25 bouyer }
418 1.6 mycroft
419 1.6 mycroft if (bp->b_bcount > ss->sio.scan_window_size)
420 1.6 mycroft bp->b_bcount = ss->sio.scan_window_size;
421 1.1 mycroft
422 1.1 mycroft /*
423 1.1 mycroft * If it's a null transfer, return immediatly
424 1.1 mycroft */
425 1.1 mycroft if (bp->b_bcount == 0)
426 1.1 mycroft goto done;
427 1.1 mycroft
428 1.1 mycroft s = splbio();
429 1.1 mycroft
430 1.1 mycroft /*
431 1.1 mycroft * Place it in the queue of activities for this scanner
432 1.1 mycroft * at the end (a bit silly because we only have on user..
433 1.1 mycroft * (but it could fork()))
434 1.1 mycroft */
435 1.29 thorpej BUFQ_INSERT_TAIL(&ss->buf_queue, bp);
436 1.1 mycroft
437 1.1 mycroft /*
438 1.1 mycroft * Tell the device to get going on the transfer if it's
439 1.1 mycroft * not doing anything, otherwise just wait for completion
440 1.1 mycroft * (All a bit silly if we're only allowing 1 open but..)
441 1.1 mycroft */
442 1.33.2.1 nathanw ssstart(ss->sc_periph);
443 1.1 mycroft
444 1.1 mycroft splx(s);
445 1.1 mycroft return;
446 1.1 mycroft bp->b_flags |= B_ERROR;
447 1.1 mycroft done:
448 1.1 mycroft /*
449 1.1 mycroft * Correctly set the buf to indicate a completed xfer
450 1.1 mycroft */
451 1.1 mycroft bp->b_resid = bp->b_bcount;
452 1.1 mycroft biodone(bp);
453 1.1 mycroft }
454 1.1 mycroft
455 1.1 mycroft /*
456 1.1 mycroft * ssstart looks to see if there is a buf waiting for the device
457 1.1 mycroft * and that the device is not already busy. If both are true,
458 1.1 mycroft * It dequeues the buf and creates a scsi command to perform the
459 1.16 bouyer * transfer required. The transfer request will call scsipi_done
460 1.1 mycroft * on completion, which will in turn call this routine again
461 1.1 mycroft * so that the next queued transfer is performed.
462 1.1 mycroft * The bufs are queued by the strategy routine (ssstrategy)
463 1.1 mycroft *
464 1.1 mycroft * This routine is also called after other non-queued requests
465 1.1 mycroft * have been made of the scsi driver, to ensure that the queue
466 1.1 mycroft * continues to be drained.
467 1.1 mycroft * ssstart() is called at splbio
468 1.1 mycroft */
469 1.1 mycroft void
470 1.33.2.1 nathanw ssstart(periph)
471 1.33.2.1 nathanw struct scsipi_periph *periph;
472 1.1 mycroft {
473 1.33.2.1 nathanw struct ss_softc *ss = (void *)periph->periph_dev;
474 1.30 augustss struct buf *bp;
475 1.1 mycroft
476 1.33.2.1 nathanw SC_DEBUG(periph, SCSIPI_DB2, ("ssstart "));
477 1.1 mycroft /*
478 1.1 mycroft * See if there is a buf to do and we are not already
479 1.1 mycroft * doing one
480 1.1 mycroft */
481 1.33.2.1 nathanw while (periph->periph_active < periph->periph_openings) {
482 1.1 mycroft /* if a special awaits, let it proceed first */
483 1.33.2.1 nathanw if (periph->periph_flags & PERIPH_WAITING) {
484 1.33.2.1 nathanw periph->periph_flags &= ~PERIPH_WAITING;
485 1.33.2.1 nathanw wakeup((caddr_t)periph);
486 1.1 mycroft return;
487 1.1 mycroft }
488 1.1 mycroft
489 1.1 mycroft /*
490 1.1 mycroft * See if there is a buf with work for us to do..
491 1.1 mycroft */
492 1.29 thorpej if ((bp = BUFQ_FIRST(&ss->buf_queue)) == NULL)
493 1.1 mycroft return;
494 1.29 thorpej BUFQ_REMOVE(&ss->buf_queue, bp);
495 1.1 mycroft
496 1.21 explorer if (ss->special && ss->special->read) {
497 1.1 mycroft (ss->special->read)(ss, bp);
498 1.1 mycroft } else {
499 1.1 mycroft /* generic scsi2 scanner read */
500 1.1 mycroft /* XXX add code for SCSI2 scanner read */
501 1.1 mycroft }
502 1.1 mycroft }
503 1.1 mycroft }
504 1.1 mycroft
505 1.1 mycroft /*
506 1.1 mycroft * Perform special action on behalf of the user;
507 1.1 mycroft * knows about the internals of this device
508 1.1 mycroft */
509 1.1 mycroft int
510 1.1 mycroft ssioctl(dev, cmd, addr, flag, p)
511 1.1 mycroft dev_t dev;
512 1.1 mycroft u_long cmd;
513 1.1 mycroft caddr_t addr;
514 1.1 mycroft int flag;
515 1.1 mycroft struct proc *p;
516 1.1 mycroft {
517 1.8 thorpej struct ss_softc *ss = ss_cd.cd_devs[SSUNIT(dev)];
518 1.1 mycroft int error = 0;
519 1.1 mycroft struct scan_io *sio;
520 1.32 augustss
521 1.32 augustss if ((ss->sc_dev.dv_flags & DVF_ACTIVE) == 0)
522 1.32 augustss return (ENODEV);
523 1.1 mycroft
524 1.1 mycroft switch (cmd) {
525 1.1 mycroft case SCIOCGET:
526 1.21 explorer if (ss->special && ss->special->get_params) {
527 1.1 mycroft /* call special handler */
528 1.3 mycroft error = (ss->special->get_params)(ss);
529 1.3 mycroft if (error)
530 1.1 mycroft return (error);
531 1.1 mycroft } else {
532 1.1 mycroft /* XXX add code for SCSI2 scanner, if any */
533 1.1 mycroft return (EOPNOTSUPP);
534 1.1 mycroft }
535 1.33.2.2 nathanw memcpy(addr, &ss->sio, sizeof(struct scan_io));
536 1.1 mycroft break;
537 1.1 mycroft case SCIOCSET:
538 1.1 mycroft sio = (struct scan_io *)addr;
539 1.1 mycroft
540 1.21 explorer if (ss->special && ss->special->set_params) {
541 1.1 mycroft /* call special handler */
542 1.3 mycroft error = (ss->special->set_params)(ss, sio);
543 1.3 mycroft if (error)
544 1.1 mycroft return (error);
545 1.1 mycroft } else {
546 1.1 mycroft /* XXX add code for SCSI2 scanner, if any */
547 1.1 mycroft return (EOPNOTSUPP);
548 1.1 mycroft }
549 1.1 mycroft break;
550 1.1 mycroft case SCIOCRESTART:
551 1.21 explorer if (ss->special && ss->special->rewind_scanner ) {
552 1.1 mycroft /* call special handler */
553 1.3 mycroft error = (ss->special->rewind_scanner)(ss);
554 1.3 mycroft if (error)
555 1.1 mycroft return (error);
556 1.1 mycroft } else
557 1.1 mycroft /* XXX add code for SCSI2 scanner, if any */
558 1.1 mycroft return (EOPNOTSUPP);
559 1.1 mycroft ss->flags &= ~SSF_TRIGGERED;
560 1.1 mycroft break;
561 1.1 mycroft #ifdef NOTYET
562 1.1 mycroft case SCAN_USE_ADF:
563 1.1 mycroft break;
564 1.1 mycroft #endif
565 1.1 mycroft default:
566 1.33.2.1 nathanw return (scsipi_do_ioctl(ss->sc_periph, dev, cmd, addr,
567 1.33.2.1 nathanw flag, p));
568 1.1 mycroft }
569 1.1 mycroft return (error);
570 1.1 mycroft }
571