Home | History | Annotate | Line # | Download | only in scsipi
ss.c revision 1.1
      1  1.1  mycroft /*	$NetBSD: ss.c,v 1.1 1996/02/18 20:32:46 mycroft 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.1  mycroft 
     33  1.1  mycroft #include <sys/types.h>
     34  1.1  mycroft #include <sys/param.h>
     35  1.1  mycroft #include <sys/systm.h>
     36  1.1  mycroft #include <sys/fcntl.h>
     37  1.1  mycroft #include <sys/errno.h>
     38  1.1  mycroft #include <sys/ioctl.h>
     39  1.1  mycroft #include <sys/malloc.h>
     40  1.1  mycroft #include <sys/buf.h>
     41  1.1  mycroft #include <sys/proc.h>
     42  1.1  mycroft #include <sys/user.h>
     43  1.1  mycroft #include <sys/device.h>
     44  1.1  mycroft #include <sys/conf.h>		/* for cdevsw */
     45  1.1  mycroft #include <sys/scanio.h>
     46  1.1  mycroft 
     47  1.1  mycroft #include <scsi/scsi_all.h>
     48  1.1  mycroft #include <scsi/scsi_scanner.h>
     49  1.1  mycroft #include <scsi/scsiconf.h>
     50  1.1  mycroft #include <scsi/ssvar.h>
     51  1.1  mycroft 
     52  1.1  mycroft #include <scsi/ss_mustek.h>
     53  1.1  mycroft 
     54  1.1  mycroft #define SSMODE(z)	( minor(z)       & 0x03)
     55  1.1  mycroft #define SSUNIT(z)	((minor(z) >> 4)       )
     56  1.1  mycroft 
     57  1.1  mycroft /*
     58  1.1  mycroft  * If the mode is 3 (e.g. minor = 3,7,11,15)
     59  1.1  mycroft  * then the device has been openned to set defaults
     60  1.1  mycroft  * This mode does NOT ALLOW I/O, only ioctls
     61  1.1  mycroft  */
     62  1.1  mycroft #define MODE_REWIND	0
     63  1.1  mycroft #define MODE_NONREWIND	1
     64  1.1  mycroft #define MODE_CONTROL	3
     65  1.1  mycroft 
     66  1.1  mycroft int ssmatch __P((struct device *, void *, void *));
     67  1.1  mycroft void ssattach __P((struct device *, struct device *, void *));
     68  1.1  mycroft 
     69  1.1  mycroft struct cfdriver sscd = {
     70  1.1  mycroft 	NULL, "ss", ssmatch, ssattach, DV_DULL, sizeof(struct ss_softc)
     71  1.1  mycroft };
     72  1.1  mycroft 
     73  1.1  mycroft void    ssstrategy __P((struct buf *));
     74  1.1  mycroft void    ssstart __P((void *));
     75  1.1  mycroft 
     76  1.1  mycroft struct scsi_device ss_switch = {
     77  1.1  mycroft 	NULL,
     78  1.1  mycroft 	ssstart,
     79  1.1  mycroft 	NULL,
     80  1.1  mycroft 	NULL,
     81  1.1  mycroft };
     82  1.1  mycroft 
     83  1.1  mycroft struct scsi_inquiry_pattern ss_patterns[] = {
     84  1.1  mycroft 	{T_SCANNER, T_FIXED,
     85  1.1  mycroft 	 "",         "",                 ""},
     86  1.1  mycroft 	{T_SCANNER, T_REMOV,
     87  1.1  mycroft 	 "",         "",                 ""},
     88  1.1  mycroft 	{T_PROCESSOR, T_FIXED,
     89  1.1  mycroft 	 "HP      ", "C1750A          ", ""},
     90  1.1  mycroft 	{T_PROCESSOR, T_FIXED,
     91  1.1  mycroft 	 "HP      ", "C2500A          ", ""},
     92  1.1  mycroft };
     93  1.1  mycroft 
     94  1.1  mycroft int
     95  1.1  mycroft ssmatch(parent, match, aux)
     96  1.1  mycroft 	struct device *parent;
     97  1.1  mycroft 	void *match, *aux;
     98  1.1  mycroft {
     99  1.1  mycroft 	struct scsibus_attach_args *sa = aux;
    100  1.1  mycroft 	int priority;
    101  1.1  mycroft 
    102  1.1  mycroft 	(void)scsi_inqmatch(sa->sa_inqbuf,
    103  1.1  mycroft 	    (caddr_t)ss_patterns, sizeof(ss_patterns)/sizeof(ss_patterns[0]),
    104  1.1  mycroft 	    sizeof(ss_patterns[0]), &priority);
    105  1.1  mycroft 	return (priority);
    106  1.1  mycroft }
    107  1.1  mycroft 
    108  1.1  mycroft /*
    109  1.1  mycroft  * The routine called by the low level scsi routine when it discovers
    110  1.1  mycroft  * A device suitable for this driver
    111  1.1  mycroft  * If it is a know special, call special attach routine to install
    112  1.1  mycroft  * special handlers into the ss_softc structure
    113  1.1  mycroft  */
    114  1.1  mycroft void
    115  1.1  mycroft ssattach(parent, self, aux)
    116  1.1  mycroft 	struct device *parent, *self;
    117  1.1  mycroft 	void *aux;
    118  1.1  mycroft {
    119  1.1  mycroft 	struct ss_softc *ss = (void *)self;
    120  1.1  mycroft 	struct scsibus_attach_args *sa = aux;
    121  1.1  mycroft 	struct scsi_link *sc_link = sa->sa_sc_link;
    122  1.1  mycroft 
    123  1.1  mycroft 	SC_DEBUG(sc_link, SDEV_DB2, ("ssattach: "));
    124  1.1  mycroft 
    125  1.1  mycroft 	/*
    126  1.1  mycroft 	 * Store information needed to contact our base driver
    127  1.1  mycroft 	 */
    128  1.1  mycroft 	ss->sc_link = sc_link;
    129  1.1  mycroft 	sc_link->device = &ss_switch;
    130  1.1  mycroft 	sc_link->device_softc = ss;
    131  1.1  mycroft 	sc_link->openings = 1;
    132  1.1  mycroft 
    133  1.1  mycroft 	/*
    134  1.1  mycroft 	 * look for non-standard scanners with help of the quirk table
    135  1.1  mycroft 	 * and install functions for special handling
    136  1.1  mycroft 	 */
    137  1.1  mycroft 	SC_DEBUG(sc_link, SDEV_DB2, ("ssattach:\n"));
    138  1.1  mycroft 	if (!bcmp(sa->sa_inqbuf->vendor, "MUSTEK  ", 8))
    139  1.1  mycroft 		mustek_attach(ss, sa);
    140  1.1  mycroft 	if (!bcmp(sa->sa_inqbuf->vendor, "HP      ", 8))
    141  1.1  mycroft 		scanjet_attach(ss, sa);
    142  1.1  mycroft 	if (ss->special == NULL) {
    143  1.1  mycroft 		/* XXX add code to restart a SCSI2 scanner, if any */
    144  1.1  mycroft 	}
    145  1.1  mycroft 
    146  1.1  mycroft 	/*
    147  1.1  mycroft 	 * Set up the buf queue for this device
    148  1.1  mycroft 	 */
    149  1.1  mycroft 	ss->buf_queue.b_active = 0;
    150  1.1  mycroft 	ss->buf_queue.b_actf = 0;
    151  1.1  mycroft 	ss->buf_queue.b_actb = &ss->buf_queue.b_actf;
    152  1.1  mycroft }
    153  1.1  mycroft 
    154  1.1  mycroft /*
    155  1.1  mycroft  * open the device.
    156  1.1  mycroft  */
    157  1.1  mycroft int
    158  1.1  mycroft ssopen(dev, flag, mode, p)
    159  1.1  mycroft 	dev_t dev;
    160  1.1  mycroft 	int flag
    161  1.1  mycroft 	int mode;
    162  1.1  mycroft 	struct proc *p;
    163  1.1  mycroft {
    164  1.1  mycroft 	int unit;
    165  1.1  mycroft 	u_int mode;
    166  1.1  mycroft 	int error = 0;
    167  1.1  mycroft 	struct ss_softc *ss;
    168  1.1  mycroft 	struct scsi_link *sc_link;
    169  1.1  mycroft 
    170  1.1  mycroft 	unit = SSUNIT(dev);
    171  1.1  mycroft 	if (unit >= sscd.cd_ndevs)
    172  1.1  mycroft 		return (ENXIO);
    173  1.1  mycroft 	ss = sscd.cd_devs[unit];
    174  1.1  mycroft 	if (!ss)
    175  1.1  mycroft 		return (ENXIO);
    176  1.1  mycroft 
    177  1.1  mycroft 	mode = SSMODE(dev);
    178  1.1  mycroft 	sc_link = ss->sc_link;
    179  1.1  mycroft 
    180  1.1  mycroft 	SC_DEBUG(sc_link, SDEV_DB1, ("open: dev=0x%x (unit %d (of %d))\n", dev,
    181  1.1  mycroft 	    unit, sscd.cd_ndevs));
    182  1.1  mycroft 
    183  1.1  mycroft 	if (sc_link->flags & SDEV_OPEN) {
    184  1.1  mycroft 		printf("%s: already open\n", ss->sc_dev.dv_xname);
    185  1.1  mycroft 		return (EBUSY);
    186  1.1  mycroft 	}
    187  1.1  mycroft 
    188  1.1  mycroft 	/*
    189  1.1  mycroft 	 * Catch any unit attention errors.
    190  1.1  mycroft 	 *
    191  1.1  mycroft 	 * SCSI_IGNORE_MEDIA_CHANGE: when you have an ADF, some scanners
    192  1.1  mycroft 	 * consider paper to be a changeable media
    193  1.1  mycroft 	 *
    194  1.1  mycroft 	 */
    195  1.1  mycroft 	error = scsi_test_unit_ready(sc_link,
    196  1.1  mycroft 	    SCSI_IGNORE_MEDIA_CHANGE | SCSI_IGNORE_ILLEGAL_REQUEST |
    197  1.1  mycroft 	    (mode == MODE_CONTROL ? SCSI_IGNORE_NOT_READY : 0));
    198  1.1  mycroft 	if (error)
    199  1.1  mycroft 		goto bad;
    200  1.1  mycroft 
    201  1.1  mycroft 	sc_link->flags |= SDEV_OPEN;	/* unit attn are now errors */
    202  1.1  mycroft 
    203  1.1  mycroft 	/*
    204  1.1  mycroft 	 * If the mode is 3 (e.g. minor = 3,7,11,15)
    205  1.1  mycroft 	 * then the device has been opened to set defaults
    206  1.1  mycroft 	 * This mode does NOT ALLOW I/O, only ioctls
    207  1.1  mycroft 	 */
    208  1.1  mycroft 	if (mode == MODE_CONTROL)
    209  1.1  mycroft 		return (0);
    210  1.1  mycroft 
    211  1.1  mycroft 	SC_DEBUG(sc_link, SDEV_DB2, ("open complete\n"));
    212  1.1  mycroft 	return (0);
    213  1.1  mycroft 
    214  1.1  mycroft bad:
    215  1.1  mycroft 	sc_link->flags &= ~SDEV_OPEN;
    216  1.1  mycroft 	return (error);
    217  1.1  mycroft }
    218  1.1  mycroft 
    219  1.1  mycroft /*
    220  1.1  mycroft  * close the device.. only called if we are the LAST
    221  1.1  mycroft  * occurence of an open device
    222  1.1  mycroft  */
    223  1.1  mycroft int
    224  1.1  mycroft ssclose(dev)
    225  1.1  mycroft 	dev_t dev;
    226  1.1  mycroft {
    227  1.1  mycroft 	struct ss_softc *ss = sscd.cd_devs[SSUNIT(dev)];
    228  1.1  mycroft 	int error;
    229  1.1  mycroft 
    230  1.1  mycroft 	SC_DEBUG(ss->sc_link, SDEV_DB1, ("closing\n"));
    231  1.1  mycroft 
    232  1.1  mycroft 	if (SSMODE(dev) == MODE_REWIND) {
    233  1.1  mycroft 		if (ss->special->rewind_scanner) {
    234  1.1  mycroft 			/* call special handler to rewind/abort scan */
    235  1.1  mycroft 			error = (ss->special->rewind_scanner)(ss);
    236  1.1  mycroft 			if (error)
    237  1.1  mycroft 				return (error);
    238  1.1  mycroft 		} else {
    239  1.1  mycroft 			/* XXX add code to restart a SCSI2 scanner, if any */
    240  1.1  mycroft 			ss->sio.scan_window_size = 0;
    241  1.1  mycroft 		}
    242  1.1  mycroft 		ss->flags &= ~SSF_TRIGGERED;
    243  1.1  mycroft 	}
    244  1.1  mycroft 	ss->sc_link->flags &= ~SDEV_OPEN;
    245  1.1  mycroft 
    246  1.1  mycroft 	return (0);
    247  1.1  mycroft }
    248  1.1  mycroft 
    249  1.1  mycroft /*
    250  1.1  mycroft  * trim the size of the transfer if needed,
    251  1.1  mycroft  * called by physio
    252  1.1  mycroft  * basically the smaller of our min and the scsi driver's
    253  1.1  mycroft  * minphys
    254  1.1  mycroft  */
    255  1.1  mycroft void
    256  1.1  mycroft ssminphys(bp)
    257  1.1  mycroft 	struct buf *bp;
    258  1.1  mycroft {
    259  1.1  mycroft 	register struct ss_softc *ss = sscd.cd_devs[SSUNIT(bp->b_dev)];
    260  1.1  mycroft 
    261  1.1  mycroft 	(ss->sc_link->adapter->scsi_minphys)(bp);
    262  1.1  mycroft 
    263  1.1  mycroft 	/*
    264  1.1  mycroft 	 * trim the transfer further for special devices this is
    265  1.1  mycroft 	 * because some scanners only read multiples of a line at a
    266  1.1  mycroft 	 * time, also some cannot disconnect, so the read must be
    267  1.1  mycroft 	 * short enough to happen quickly
    268  1.1  mycroft 	 */
    269  1.1  mycroft 	if (ss->special->minphys)
    270  1.1  mycroft 		(ss->special->minphys)(ss, bp);
    271  1.1  mycroft }
    272  1.1  mycroft 
    273  1.1  mycroft /*
    274  1.1  mycroft  * Do a read on a device for a user process.
    275  1.1  mycroft  * Prime scanner at start of read, check uio values, call ssstrategy
    276  1.1  mycroft  * via physio for the actual transfer.
    277  1.1  mycroft  */
    278  1.1  mycroft int
    279  1.1  mycroft ssread(dev, uio, flag)
    280  1.1  mycroft 	dev_t dev;
    281  1.1  mycroft 	struct uio *uio;
    282  1.1  mycroft 	int flag;
    283  1.1  mycroft {
    284  1.1  mycroft 	struct ss_softc *ss = sscd.cd_devs[SSUNIT(dev)];
    285  1.1  mycroft 	int error;
    286  1.1  mycroft 
    287  1.1  mycroft 	/* if the scanner has not yet been started, do it now */
    288  1.1  mycroft 	if (!(ss->flags & SSF_TRIGGERED)) {
    289  1.1  mycroft 		if (ss->special->trigger_scanner) {
    290  1.1  mycroft 			error = (ss->special->trigger_scanner)(ss);
    291  1.1  mycroft 			if (error)
    292  1.1  mycroft 				return (error);
    293  1.1  mycroft 		}
    294  1.1  mycroft 		ss->flags |= SSF_TRIGGERED;
    295  1.1  mycroft 	}
    296  1.1  mycroft 
    297  1.1  mycroft 	/* in any case, trim it down to window_size */
    298  1.1  mycroft 	if (uio->uio_iov->iov_len > ss->sio.scan_window_size) {
    299  1.1  mycroft 		uio->uio_iov->iov_len = ss->sio.scan_window_size;
    300  1.1  mycroft 
    301  1.1  mycroft 		SC_DEBUG(ss->sc_link, SDEV_DB1,
    302  1.1  mycroft 		    ("ssread: bytes wanted exceeds window size\n"));
    303  1.1  mycroft 		SC_DEBUG(ss->sc_link, SDEV_DB1,
    304  1.1  mycroft 		    ("ssread: xfer reduced to %d\n", uio->uio_iov->iov_len));
    305  1.1  mycroft 	}
    306  1.1  mycroft 
    307  1.1  mycroft 	/*
    308  1.1  mycroft 	 * EOF detection
    309  1.1  mycroft 	 */
    310  1.1  mycroft 
    311  1.1  mycroft 	if (ss->sio.scan_window_size == 0) {
    312  1.1  mycroft 		uio->uio_iov++;
    313  1.1  mycroft 		uio->uio_iovcnt--;
    314  1.1  mycroft 		return (0);
    315  1.1  mycroft 	}
    316  1.1  mycroft 
    317  1.1  mycroft 	return (physio(ssstrategy, NULL, dev, B_READ, ssminphys, uio));
    318  1.1  mycroft }
    319  1.1  mycroft 
    320  1.1  mycroft /*
    321  1.1  mycroft  * Actually translate the requested transfer into one the physical
    322  1.1  mycroft  * driver can understand The transfer is described by a buf and will
    323  1.1  mycroft  * include only one physical transfer.
    324  1.1  mycroft  */
    325  1.1  mycroft void
    326  1.1  mycroft ssstrategy(bp)
    327  1.1  mycroft 	struct buf *bp;
    328  1.1  mycroft {
    329  1.1  mycroft 	struct ss_softc *ss = sscd.cd_devs[SSUNIT(bp->b_dev)];
    330  1.1  mycroft 	struct buf *dp;
    331  1.1  mycroft 	int s;
    332  1.1  mycroft 
    333  1.1  mycroft 	SC_DEBUG(ss->sc_link, SDEV_DB1,
    334  1.1  mycroft 	    ("ssstrategy %d bytes @ blk %d\n", bp->b_bcount, bp->b_blkno));
    335  1.1  mycroft 
    336  1.1  mycroft 	/*
    337  1.1  mycroft 	 * If it's a null transfer, return immediatly
    338  1.1  mycroft 	 */
    339  1.1  mycroft 	if (bp->b_bcount == 0)
    340  1.1  mycroft 		goto done;
    341  1.1  mycroft 
    342  1.1  mycroft 	s = splbio();
    343  1.1  mycroft 
    344  1.1  mycroft 	/*
    345  1.1  mycroft 	 * Place it in the queue of activities for this scanner
    346  1.1  mycroft 	 * at the end (a bit silly because we only have on user..
    347  1.1  mycroft 	 * (but it could fork()))
    348  1.1  mycroft 	 */
    349  1.1  mycroft 	dp = &ss->buf_queue;
    350  1.1  mycroft 	bp->b_actf = NULL;
    351  1.1  mycroft 	bp->b_actb = dp->b_actb;
    352  1.1  mycroft 	*dp->b_actb = bp;
    353  1.1  mycroft 	dp->b_actb = &bp->b_actf;
    354  1.1  mycroft 
    355  1.1  mycroft 	/*
    356  1.1  mycroft 	 * Tell the device to get going on the transfer if it's
    357  1.1  mycroft 	 * not doing anything, otherwise just wait for completion
    358  1.1  mycroft 	 * (All a bit silly if we're only allowing 1 open but..)
    359  1.1  mycroft 	 */
    360  1.1  mycroft 	ssstart(ss);
    361  1.1  mycroft 
    362  1.1  mycroft 	splx(s);
    363  1.1  mycroft 	return;
    364  1.1  mycroft bad:
    365  1.1  mycroft 	bp->b_flags |= B_ERROR;
    366  1.1  mycroft done:
    367  1.1  mycroft 	/*
    368  1.1  mycroft 	 * Correctly set the buf to indicate a completed xfer
    369  1.1  mycroft 	 */
    370  1.1  mycroft 	bp->b_resid = bp->b_bcount;
    371  1.1  mycroft 	biodone(bp);
    372  1.1  mycroft }
    373  1.1  mycroft 
    374  1.1  mycroft /*
    375  1.1  mycroft  * ssstart looks to see if there is a buf waiting for the device
    376  1.1  mycroft  * and that the device is not already busy. If both are true,
    377  1.1  mycroft  * It dequeues the buf and creates a scsi command to perform the
    378  1.1  mycroft  * transfer required. The transfer request will call scsi_done
    379  1.1  mycroft  * on completion, which will in turn call this routine again
    380  1.1  mycroft  * so that the next queued transfer is performed.
    381  1.1  mycroft  * The bufs are queued by the strategy routine (ssstrategy)
    382  1.1  mycroft  *
    383  1.1  mycroft  * This routine is also called after other non-queued requests
    384  1.1  mycroft  * have been made of the scsi driver, to ensure that the queue
    385  1.1  mycroft  * continues to be drained.
    386  1.1  mycroft  * ssstart() is called at splbio
    387  1.1  mycroft  */
    388  1.1  mycroft void
    389  1.1  mycroft ssstart(v)
    390  1.1  mycroft 	void *v;
    391  1.1  mycroft {
    392  1.1  mycroft 	struct ss_softc *ss = v;
    393  1.1  mycroft 	struct scsi_link *sc_link = ss->sc_link;
    394  1.1  mycroft 	register struct buf *bp, *dp;
    395  1.1  mycroft 
    396  1.1  mycroft 	SC_DEBUG(sc_link, SDEV_DB2, ("ssstart "));
    397  1.1  mycroft 	/*
    398  1.1  mycroft 	 * See if there is a buf to do and we are not already
    399  1.1  mycroft 	 * doing one
    400  1.1  mycroft 	 */
    401  1.1  mycroft 	while (sc_link->openings > 0) {
    402  1.1  mycroft 		/* if a special awaits, let it proceed first */
    403  1.1  mycroft 		if (sc_link->flags & SDEV_WAITING) {
    404  1.1  mycroft 			sc_link->flags &= ~SDEV_WAITING;
    405  1.1  mycroft 			wakeup((caddr_t)sc_link);
    406  1.1  mycroft 			return;
    407  1.1  mycroft 		}
    408  1.1  mycroft 
    409  1.1  mycroft 		/*
    410  1.1  mycroft 		 * See if there is a buf with work for us to do..
    411  1.1  mycroft 		 */
    412  1.1  mycroft 		dp = &ss->buf_queue;
    413  1.1  mycroft 		if ((bp = dp->b_actf) == NULL)
    414  1.1  mycroft 			return;
    415  1.1  mycroft 		if ((dp = bp->b_actf) != NULL)
    416  1.1  mycroft 			dp->b_actb = bp->b_actb;
    417  1.1  mycroft 		else
    418  1.1  mycroft 			ss->buf_queue.b_actb = bp->b_actb;
    419  1.1  mycroft 		*bp->b_actb = dp;
    420  1.1  mycroft 
    421  1.1  mycroft 		if (ss->special->read) {
    422  1.1  mycroft 			(ss->special->read)(ss, bp);
    423  1.1  mycroft 		} else {
    424  1.1  mycroft 			/* generic scsi2 scanner read */
    425  1.1  mycroft 			/* XXX add code for SCSI2 scanner read */
    426  1.1  mycroft 		}
    427  1.1  mycroft 	}
    428  1.1  mycroft }
    429  1.1  mycroft 
    430  1.1  mycroft /*
    431  1.1  mycroft  * Perform special action on behalf of the user;
    432  1.1  mycroft  * knows about the internals of this device
    433  1.1  mycroft  */
    434  1.1  mycroft int
    435  1.1  mycroft ssioctl(dev, cmd, addr, flag, p)
    436  1.1  mycroft 	dev_t dev;
    437  1.1  mycroft 	u_long cmd;
    438  1.1  mycroft 	caddr_t addr;
    439  1.1  mycroft 	int flag;
    440  1.1  mycroft 	struct proc *p;
    441  1.1  mycroft {
    442  1.1  mycroft 	struct ss_softc *ss = sscd.cd_devs[SSUNIT(dev)];
    443  1.1  mycroft 	int error = 0;
    444  1.1  mycroft 	int unit;
    445  1.1  mycroft 	struct scan_io *sio;
    446  1.1  mycroft 
    447  1.1  mycroft 	switch (cmd) {
    448  1.1  mycroft 	case SCIOCGET:
    449  1.1  mycroft 		if (ss->special->get_params) {
    450  1.1  mycroft 			/* call special handler */
    451  1.1  mycroft 			if ((error = (ss->special->get_params)(ss)) > 0)
    452  1.1  mycroft 				return (error);
    453  1.1  mycroft 		} else {
    454  1.1  mycroft 			/* XXX add code for SCSI2 scanner, if any */
    455  1.1  mycroft 			return (EOPNOTSUPP);
    456  1.1  mycroft 		}
    457  1.1  mycroft 		bcopy(&ss->sio, addr, sizeof(struct scan_io));
    458  1.1  mycroft 		break;
    459  1.1  mycroft 	case SCIOCSET:
    460  1.1  mycroft 		sio = (struct scan_io *)addr;
    461  1.1  mycroft 
    462  1.1  mycroft 		if (ss->special->set_params) {
    463  1.1  mycroft 			/* call special handler */
    464  1.1  mycroft 			if ((error = (ss->special->set_params)(ss, sio)) > 0)
    465  1.1  mycroft 				return (error);
    466  1.1  mycroft 		} else {
    467  1.1  mycroft 			/* XXX add code for SCSI2 scanner, if any */
    468  1.1  mycroft 			return (EOPNOTSUPP);
    469  1.1  mycroft 		}
    470  1.1  mycroft 		break;
    471  1.1  mycroft 	case SCIOCRESTART:
    472  1.1  mycroft 		if (ss->special->rewind_scanner ) {
    473  1.1  mycroft 			/* call special handler */
    474  1.1  mycroft 			if ((error = (ss->special->rewind_scanner)(ss)) > 0)
    475  1.1  mycroft 				return (error);
    476  1.1  mycroft 		} else
    477  1.1  mycroft 			/* XXX add code for SCSI2 scanner, if any */
    478  1.1  mycroft 			return (EOPNOTSUPP);
    479  1.1  mycroft 		ss->flags &= ~SSF_TRIGGERED;
    480  1.1  mycroft 		break;
    481  1.1  mycroft #ifdef NOTYET
    482  1.1  mycroft 	case SCAN_USE_ADF:
    483  1.1  mycroft 		break;
    484  1.1  mycroft #endif
    485  1.1  mycroft 	default:
    486  1.1  mycroft 		if (SSMODE(dev) != MODE_CONTROL)
    487  1.1  mycroft 			return (ENOTTY);
    488  1.1  mycroft 		return (scsi_do_ioctl(ss->sc_link, dev, cmd, addr, flag, p));
    489  1.1  mycroft 	}
    490  1.1  mycroft 	return (error);
    491  1.1  mycroft }
    492