2003-01-21 03:24:20 +03:00
|
|
|
/* $NetBSD: ss.c,v 1.46 2003/01/21 00:24:20 simonb Exp $ */
|
1996-02-18 23:32:40 +03:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Copyright (c) 1995 Kenneth Stailey. All rights reserved.
|
|
|
|
* modified for configurable scanner support by Joachim Koenig
|
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions
|
|
|
|
* are met:
|
|
|
|
* 1. Redistributions of source code must retain the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer.
|
|
|
|
* 2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer in the
|
|
|
|
* documentation and/or other materials provided with the distribution.
|
|
|
|
* 3. All advertising materials mentioning features or use of this software
|
|
|
|
* must display the following acknowledgement:
|
|
|
|
* This product includes software developed by Kenneth Stailey.
|
|
|
|
* 4. The name of the author may not be used to endorse or promote products
|
|
|
|
* derived from this software without specific prior written permission.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
|
|
|
|
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
|
|
|
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
|
|
|
* IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
|
|
|
|
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
|
|
|
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
|
|
|
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
|
|
|
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|
|
|
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
|
|
|
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
*/
|
|
|
|
|
2001-11-13 09:54:32 +03:00
|
|
|
#include <sys/cdefs.h>
|
2003-01-21 03:24:20 +03:00
|
|
|
__KERNEL_RCSID(0, "$NetBSD: ss.c,v 1.46 2003/01/21 00:24:20 simonb Exp $");
|
2001-11-13 09:54:32 +03:00
|
|
|
|
1996-02-18 23:32:40 +03:00
|
|
|
#include <sys/param.h>
|
|
|
|
#include <sys/systm.h>
|
|
|
|
#include <sys/fcntl.h>
|
|
|
|
#include <sys/errno.h>
|
|
|
|
#include <sys/ioctl.h>
|
|
|
|
#include <sys/malloc.h>
|
|
|
|
#include <sys/buf.h>
|
|
|
|
#include <sys/proc.h>
|
|
|
|
#include <sys/user.h>
|
|
|
|
#include <sys/device.h>
|
1996-03-31 00:47:00 +03:00
|
|
|
#include <sys/conf.h>
|
2001-01-01 21:28:49 +03:00
|
|
|
#include <sys/vnode.h>
|
1996-02-18 23:32:40 +03:00
|
|
|
#include <sys/scanio.h>
|
|
|
|
|
1997-08-27 15:22:52 +04:00
|
|
|
#include <dev/scsipi/scsi_all.h>
|
|
|
|
#include <dev/scsipi/scsipi_all.h>
|
|
|
|
#include <dev/scsipi/scsi_scanner.h>
|
|
|
|
#include <dev/scsipi/scsiconf.h>
|
|
|
|
#include <dev/scsipi/ssvar.h>
|
1996-02-18 23:32:40 +03:00
|
|
|
|
1997-08-27 15:22:52 +04:00
|
|
|
#include <dev/scsipi/ss_mustek.h>
|
1996-02-18 23:32:40 +03:00
|
|
|
|
|
|
|
#define SSMODE(z) ( minor(z) & 0x03)
|
|
|
|
#define SSUNIT(z) ((minor(z) >> 4) )
|
2001-01-01 21:34:12 +03:00
|
|
|
#define SSNMINOR 16
|
1996-02-18 23:32:40 +03:00
|
|
|
|
|
|
|
/*
|
|
|
|
* If the mode is 3 (e.g. minor = 3,7,11,15)
|
|
|
|
* then the device has been openned to set defaults
|
|
|
|
* This mode does NOT ALLOW I/O, only ioctls
|
|
|
|
*/
|
|
|
|
#define MODE_REWIND 0
|
|
|
|
#define MODE_NONREWIND 1
|
|
|
|
#define MODE_CONTROL 3
|
|
|
|
|
2001-01-01 21:28:49 +03:00
|
|
|
int ssmatch(struct device *, struct cfdata *, void *);
|
|
|
|
void ssattach(struct device *, struct device *, void *);
|
|
|
|
int ssdetach(struct device *self, int flags);
|
|
|
|
int ssactivate(struct device *self, enum devact act);
|
1996-02-18 23:32:40 +03:00
|
|
|
|
2002-10-01 03:07:07 +04:00
|
|
|
CFATTACH_DECL(ss, sizeof(struct ss_softc),
|
2002-10-02 20:51:16 +04:00
|
|
|
ssmatch, ssattach, ssdetach, ssactivate);
|
1996-03-17 03:57:14 +03:00
|
|
|
|
1998-01-12 12:49:10 +03:00
|
|
|
extern struct cfdriver ss_cd;
|
1996-02-18 23:32:40 +03:00
|
|
|
|
2002-09-06 17:18:43 +04:00
|
|
|
dev_type_open(ssopen);
|
|
|
|
dev_type_close(ssclose);
|
|
|
|
dev_type_read(ssread);
|
|
|
|
dev_type_ioctl(ssioctl);
|
|
|
|
|
|
|
|
const struct cdevsw ss_cdevsw = {
|
|
|
|
ssopen, ssclose, ssread, nowrite, ssioctl,
|
2002-10-23 13:10:23 +04:00
|
|
|
nostop, notty, nopoll, nommap, nokqfilter,
|
2002-09-06 17:18:43 +04:00
|
|
|
};
|
|
|
|
|
1996-02-18 23:32:40 +03:00
|
|
|
void ssstrategy __P((struct buf *));
|
2001-04-25 21:53:04 +04:00
|
|
|
void ssstart __P((struct scsipi_periph *));
|
1996-03-31 00:47:00 +03:00
|
|
|
void ssminphys __P((struct buf *));
|
1996-02-18 23:32:40 +03:00
|
|
|
|
2001-04-25 21:53:04 +04:00
|
|
|
const struct scsipi_periphsw ss_switch = {
|
1996-02-18 23:32:40 +03:00
|
|
|
NULL,
|
|
|
|
ssstart,
|
|
|
|
NULL,
|
|
|
|
NULL,
|
|
|
|
};
|
|
|
|
|
1997-08-27 15:22:52 +04:00
|
|
|
struct scsipi_inquiry_pattern ss_patterns[] = {
|
1996-02-18 23:32:40 +03:00
|
|
|
{T_SCANNER, T_FIXED,
|
|
|
|
"", "", ""},
|
|
|
|
{T_SCANNER, T_REMOV,
|
|
|
|
"", "", ""},
|
2002-09-15 01:41:24 +04:00
|
|
|
{T_PROCESSOR, T_FIXED,
|
|
|
|
"HP ", "C1130A ", ""},
|
1996-02-18 23:32:40 +03:00
|
|
|
{T_PROCESSOR, T_FIXED,
|
|
|
|
"HP ", "C1750A ", ""},
|
|
|
|
{T_PROCESSOR, T_FIXED,
|
|
|
|
"HP ", "C2500A ", ""},
|
1996-11-29 22:53:32 +03:00
|
|
|
{T_PROCESSOR, T_FIXED,
|
2002-09-15 01:41:24 +04:00
|
|
|
"HP ", "C2520A ", ""},
|
1997-11-19 06:03:15 +03:00
|
|
|
{T_PROCESSOR, T_FIXED,
|
|
|
|
"HP ", "C5110A ", ""},
|
2000-06-01 03:10:39 +04:00
|
|
|
{T_PROCESSOR, T_FIXED,
|
|
|
|
"HP ", "C7670A ", ""},
|
2002-09-15 01:41:24 +04:00
|
|
|
{T_PROCESSOR, T_FIXED,
|
|
|
|
"HP ", "", ""},
|
1996-02-18 23:32:40 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
int
|
2001-01-01 21:28:49 +03:00
|
|
|
ssmatch(struct device *parent, struct cfdata *match, void *aux)
|
1996-02-18 23:32:40 +03:00
|
|
|
{
|
1997-08-27 15:22:52 +04:00
|
|
|
struct scsipibus_attach_args *sa = aux;
|
1996-02-18 23:32:40 +03:00
|
|
|
int priority;
|
|
|
|
|
1997-08-27 15:22:52 +04:00
|
|
|
(void)scsipi_inqmatch(&sa->sa_inqbuf,
|
1997-10-01 05:18:38 +04:00
|
|
|
(caddr_t)ss_patterns, sizeof(ss_patterns) / sizeof(ss_patterns[0]),
|
1996-02-18 23:32:40 +03:00
|
|
|
sizeof(ss_patterns[0]), &priority);
|
|
|
|
return (priority);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* The routine called by the low level scsi routine when it discovers
|
|
|
|
* A device suitable for this driver
|
|
|
|
* If it is a know special, call special attach routine to install
|
|
|
|
* special handlers into the ss_softc structure
|
|
|
|
*/
|
|
|
|
void
|
2001-01-01 21:28:49 +03:00
|
|
|
ssattach(struct device *parent, struct device *self, void *aux)
|
1996-02-18 23:32:40 +03:00
|
|
|
{
|
|
|
|
struct ss_softc *ss = (void *)self;
|
1997-08-27 15:22:52 +04:00
|
|
|
struct scsipibus_attach_args *sa = aux;
|
2001-04-25 21:53:04 +04:00
|
|
|
struct scsipi_periph *periph = sa->sa_periph;
|
1996-02-18 23:32:40 +03:00
|
|
|
|
2001-04-25 21:53:04 +04:00
|
|
|
SC_DEBUG(periph, SCSIPI_DB2, ("ssattach: "));
|
1996-02-18 23:32:40 +03:00
|
|
|
|
1998-04-22 23:44:18 +04:00
|
|
|
ss->flags |= SSF_AUTOCONF;
|
|
|
|
|
1996-02-18 23:32:40 +03:00
|
|
|
/*
|
|
|
|
* Store information needed to contact our base driver
|
|
|
|
*/
|
2001-04-25 21:53:04 +04:00
|
|
|
ss->sc_periph = periph;
|
|
|
|
periph->periph_dev = &ss->sc_dev;
|
|
|
|
periph->periph_switch = &ss_switch;
|
1996-02-18 23:32:40 +03:00
|
|
|
|
2000-01-19 04:00:07 +03:00
|
|
|
printf("\n");
|
|
|
|
|
2002-07-22 18:59:43 +04:00
|
|
|
/*
|
|
|
|
* Set up the buf queue for this device
|
|
|
|
*/
|
|
|
|
bufq_alloc(&ss->buf_queue, BUFQ_FCFS);
|
|
|
|
|
1996-02-18 23:32:40 +03:00
|
|
|
/*
|
|
|
|
* look for non-standard scanners with help of the quirk table
|
|
|
|
* and install functions for special handling
|
|
|
|
*/
|
2001-06-26 16:46:56 +04:00
|
|
|
SC_DEBUG(periph, SCSIPI_DB2, ("ssattach:\n"));
|
2001-01-01 21:28:49 +03:00
|
|
|
if (memcmp(sa->sa_inqbuf.vendor, "MUSTEK", 6) == 0)
|
1996-02-18 23:32:40 +03:00
|
|
|
mustek_attach(ss, sa);
|
2001-01-01 21:28:49 +03:00
|
|
|
if (memcmp(sa->sa_inqbuf.vendor, "HP ", 8) == 0 &&
|
|
|
|
memcmp(sa->sa_inqbuf.product, "ScanJet 5300C", 13) != 0)
|
1996-02-18 23:32:40 +03:00
|
|
|
scanjet_attach(ss, sa);
|
|
|
|
if (ss->special == NULL) {
|
|
|
|
/* XXX add code to restart a SCSI2 scanner, if any */
|
|
|
|
}
|
|
|
|
|
1998-04-22 23:44:18 +04:00
|
|
|
ss->flags &= ~SSF_AUTOCONF;
|
1996-02-18 23:32:40 +03:00
|
|
|
}
|
|
|
|
|
2001-01-01 21:28:49 +03:00
|
|
|
int
|
|
|
|
ssdetach(struct device *self, int flags)
|
|
|
|
{
|
|
|
|
struct ss_softc *ss = (struct ss_softc *) self;
|
|
|
|
struct buf *bp;
|
|
|
|
int s, cmaj, mn;
|
|
|
|
|
|
|
|
/* locate the major number */
|
2002-09-06 17:18:43 +04:00
|
|
|
cmaj = cdevsw_lookup_major(&ss_cdevsw);
|
2001-01-01 21:28:49 +03:00
|
|
|
|
|
|
|
s = splbio();
|
|
|
|
|
|
|
|
/* Kill off any queued buffers. */
|
2002-07-22 18:59:43 +04:00
|
|
|
while ((bp = BUFQ_GET(&ss->buf_queue)) != NULL) {
|
2001-01-01 21:28:49 +03:00
|
|
|
bp->b_error = EIO;
|
|
|
|
bp->b_flags |= B_ERROR;
|
|
|
|
bp->b_resid = bp->b_bcount;
|
|
|
|
biodone(bp);
|
|
|
|
}
|
|
|
|
|
2002-07-22 18:59:43 +04:00
|
|
|
bufq_free(&ss->buf_queue);
|
|
|
|
|
2001-01-01 21:28:49 +03:00
|
|
|
/* Kill off any pending commands. */
|
2001-04-25 21:53:04 +04:00
|
|
|
scsipi_kill_pending(ss->sc_periph);
|
2001-01-01 21:28:49 +03:00
|
|
|
|
|
|
|
splx(s);
|
|
|
|
|
|
|
|
/* Nuke the vnodes for any open instances */
|
|
|
|
mn = SSUNIT(self->dv_unit);
|
2001-01-01 21:34:12 +03:00
|
|
|
vdevgone(cmaj, mn, mn+SSNMINOR-1, VCHR);
|
2001-01-01 21:28:49 +03:00
|
|
|
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
ssactivate(struct device *self, enum devact act)
|
|
|
|
{
|
|
|
|
int rv = 0;
|
|
|
|
|
|
|
|
switch (act) {
|
|
|
|
case DVACT_ACTIVATE:
|
|
|
|
rv = EOPNOTSUPP;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case DVACT_DEACTIVATE:
|
|
|
|
/*
|
|
|
|
* Nothing to do; we key off the device's DVF_ACTIVE.
|
|
|
|
*/
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
return (rv);
|
|
|
|
}
|
|
|
|
|
1996-02-18 23:32:40 +03:00
|
|
|
/*
|
|
|
|
* open the device.
|
|
|
|
*/
|
|
|
|
int
|
2001-01-01 21:28:49 +03:00
|
|
|
ssopen(dev_t dev, int flag, int mode, struct proc *p)
|
1996-02-18 23:32:40 +03:00
|
|
|
{
|
|
|
|
int unit;
|
1996-02-19 02:21:48 +03:00
|
|
|
u_int ssmode;
|
1998-11-20 03:35:39 +03:00
|
|
|
int error;
|
1996-02-18 23:32:40 +03:00
|
|
|
struct ss_softc *ss;
|
2001-04-25 21:53:04 +04:00
|
|
|
struct scsipi_periph *periph;
|
|
|
|
struct scsipi_adapter *adapt;
|
1996-02-18 23:32:40 +03:00
|
|
|
|
|
|
|
unit = SSUNIT(dev);
|
1996-03-17 03:57:14 +03:00
|
|
|
if (unit >= ss_cd.cd_ndevs)
|
1996-02-18 23:32:40 +03:00
|
|
|
return (ENXIO);
|
1996-03-17 03:57:14 +03:00
|
|
|
ss = ss_cd.cd_devs[unit];
|
1996-02-18 23:32:40 +03:00
|
|
|
if (!ss)
|
|
|
|
return (ENXIO);
|
|
|
|
|
2001-01-01 21:28:49 +03:00
|
|
|
if ((ss->sc_dev.dv_flags & DVF_ACTIVE) == 0)
|
|
|
|
return (ENODEV);
|
|
|
|
|
1996-02-19 02:21:48 +03:00
|
|
|
ssmode = SSMODE(dev);
|
1996-02-18 23:32:40 +03:00
|
|
|
|
2001-04-25 21:53:04 +04:00
|
|
|
periph = ss->sc_periph;
|
|
|
|
adapt = periph->periph_channel->chan_adapter;
|
|
|
|
|
|
|
|
SC_DEBUG(periph, SCSIPI_DB1, ("open: dev=0x%x (unit %d (of %d))\n", dev,
|
1996-03-17 03:57:14 +03:00
|
|
|
unit, ss_cd.cd_ndevs));
|
1996-02-18 23:32:40 +03:00
|
|
|
|
2001-04-25 21:53:04 +04:00
|
|
|
if (periph->periph_flags & PERIPH_OPEN) {
|
1996-10-13 03:23:13 +04:00
|
|
|
printf("%s: already open\n", ss->sc_dev.dv_xname);
|
1996-02-18 23:32:40 +03:00
|
|
|
return (EBUSY);
|
|
|
|
}
|
|
|
|
|
2001-04-25 21:53:04 +04:00
|
|
|
if ((error = scsipi_adapter_addref(adapt)) != 0)
|
1998-11-20 03:35:39 +03:00
|
|
|
return (error);
|
|
|
|
|
1996-02-18 23:32:40 +03:00
|
|
|
/*
|
|
|
|
* Catch any unit attention errors.
|
|
|
|
*
|
1999-10-01 02:57:52 +04:00
|
|
|
* XS_CTL_IGNORE_MEDIA_CHANGE: when you have an ADF, some scanners
|
1996-02-18 23:32:40 +03:00
|
|
|
* consider paper to be a changeable media
|
|
|
|
*
|
|
|
|
*/
|
2001-04-25 21:53:04 +04:00
|
|
|
error = scsipi_test_unit_ready(periph,
|
1999-10-01 02:57:52 +04:00
|
|
|
XS_CTL_IGNORE_MEDIA_CHANGE | XS_CTL_IGNORE_ILLEGAL_REQUEST |
|
|
|
|
(ssmode == MODE_CONTROL ? XS_CTL_IGNORE_NOT_READY : 0));
|
1996-02-18 23:32:40 +03:00
|
|
|
if (error)
|
|
|
|
goto bad;
|
|
|
|
|
2001-04-25 21:53:04 +04:00
|
|
|
periph->periph_flags |= PERIPH_OPEN; /* unit attn now errors */
|
1996-02-18 23:32:40 +03:00
|
|
|
|
|
|
|
/*
|
|
|
|
* If the mode is 3 (e.g. minor = 3,7,11,15)
|
|
|
|
* then the device has been opened to set defaults
|
|
|
|
* This mode does NOT ALLOW I/O, only ioctls
|
|
|
|
*/
|
1996-02-19 02:21:48 +03:00
|
|
|
if (ssmode == MODE_CONTROL)
|
1996-02-18 23:32:40 +03:00
|
|
|
return (0);
|
|
|
|
|
2001-04-25 21:53:04 +04:00
|
|
|
SC_DEBUG(periph, SCSIPI_DB2, ("open complete\n"));
|
1996-02-18 23:32:40 +03:00
|
|
|
return (0);
|
|
|
|
|
|
|
|
bad:
|
2001-04-25 21:53:04 +04:00
|
|
|
scsipi_adapter_delref(adapt);
|
|
|
|
periph->periph_flags &= ~PERIPH_OPEN;
|
1996-02-18 23:32:40 +03:00
|
|
|
return (error);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* close the device.. only called if we are the LAST
|
|
|
|
* occurence of an open device
|
|
|
|
*/
|
|
|
|
int
|
2001-01-01 21:28:49 +03:00
|
|
|
ssclose(dev_t dev, int flag, int mode, struct proc *p)
|
1996-02-18 23:32:40 +03:00
|
|
|
{
|
1996-03-17 03:57:14 +03:00
|
|
|
struct ss_softc *ss = ss_cd.cd_devs[SSUNIT(dev)];
|
2001-04-25 21:53:04 +04:00
|
|
|
struct scsipi_periph *periph = ss->sc_periph;
|
|
|
|
struct scsipi_adapter *adapt = periph->periph_channel->chan_adapter;
|
1996-02-18 23:32:40 +03:00
|
|
|
int error;
|
|
|
|
|
2001-04-25 21:53:04 +04:00
|
|
|
SC_DEBUG(ss->sc_periph, SCSIPI_DB1, ("closing\n"));
|
1996-02-18 23:32:40 +03:00
|
|
|
|
|
|
|
if (SSMODE(dev) == MODE_REWIND) {
|
1998-08-19 12:40:31 +04:00
|
|
|
if (ss->special && ss->special->rewind_scanner) {
|
1996-02-18 23:32:40 +03:00
|
|
|
/* call special handler to rewind/abort scan */
|
|
|
|
error = (ss->special->rewind_scanner)(ss);
|
|
|
|
if (error)
|
|
|
|
return (error);
|
|
|
|
} else {
|
|
|
|
/* XXX add code to restart a SCSI2 scanner, if any */
|
|
|
|
}
|
1996-02-18 23:44:40 +03:00
|
|
|
ss->sio.scan_window_size = 0;
|
1996-02-18 23:32:40 +03:00
|
|
|
ss->flags &= ~SSF_TRIGGERED;
|
|
|
|
}
|
1998-11-20 03:35:39 +03:00
|
|
|
|
2001-04-25 21:53:04 +04:00
|
|
|
scsipi_wait_drain(periph);
|
1998-12-08 03:19:27 +03:00
|
|
|
|
2001-04-25 21:53:04 +04:00
|
|
|
scsipi_adapter_delref(adapt);
|
|
|
|
periph->periph_flags &= ~PERIPH_OPEN;
|
1996-02-18 23:32:40 +03:00
|
|
|
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* trim the size of the transfer if needed,
|
|
|
|
* called by physio
|
|
|
|
* basically the smaller of our min and the scsi driver's
|
|
|
|
* minphys
|
|
|
|
*/
|
|
|
|
void
|
2001-01-01 21:28:49 +03:00
|
|
|
ssminphys(struct buf *bp)
|
1996-02-18 23:32:40 +03:00
|
|
|
{
|
2000-03-30 04:00:55 +04:00
|
|
|
struct ss_softc *ss = ss_cd.cd_devs[SSUNIT(bp->b_dev)];
|
2001-04-25 21:53:04 +04:00
|
|
|
struct scsipi_periph *periph = ss->sc_periph;
|
1996-02-18 23:32:40 +03:00
|
|
|
|
2001-04-25 21:53:04 +04:00
|
|
|
(*periph->periph_channel->chan_adapter->adapt_minphys)(bp);
|
1996-02-18 23:32:40 +03:00
|
|
|
|
|
|
|
/*
|
|
|
|
* trim the transfer further for special devices this is
|
|
|
|
* because some scanners only read multiples of a line at a
|
|
|
|
* time, also some cannot disconnect, so the read must be
|
|
|
|
* short enough to happen quickly
|
|
|
|
*/
|
1998-08-19 12:40:31 +04:00
|
|
|
if (ss->special && ss->special->minphys)
|
1996-02-18 23:32:40 +03:00
|
|
|
(ss->special->minphys)(ss, bp);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Do a read on a device for a user process.
|
|
|
|
* Prime scanner at start of read, check uio values, call ssstrategy
|
|
|
|
* via physio for the actual transfer.
|
|
|
|
*/
|
|
|
|
int
|
|
|
|
ssread(dev, uio, flag)
|
|
|
|
dev_t dev;
|
|
|
|
struct uio *uio;
|
|
|
|
int flag;
|
|
|
|
{
|
1996-03-17 03:57:14 +03:00
|
|
|
struct ss_softc *ss = ss_cd.cd_devs[SSUNIT(dev)];
|
1996-02-18 23:32:40 +03:00
|
|
|
int error;
|
|
|
|
|
2001-01-01 21:28:49 +03:00
|
|
|
if ((ss->sc_dev.dv_flags & DVF_ACTIVE) == 0)
|
|
|
|
return (ENODEV);
|
|
|
|
|
1996-02-18 23:32:40 +03:00
|
|
|
/* if the scanner has not yet been started, do it now */
|
|
|
|
if (!(ss->flags & SSF_TRIGGERED)) {
|
1998-08-19 12:40:31 +04:00
|
|
|
if (ss->special && ss->special->trigger_scanner) {
|
1996-02-18 23:32:40 +03:00
|
|
|
error = (ss->special->trigger_scanner)(ss);
|
|
|
|
if (error)
|
|
|
|
return (error);
|
|
|
|
}
|
|
|
|
ss->flags |= SSF_TRIGGERED;
|
|
|
|
}
|
|
|
|
|
|
|
|
return (physio(ssstrategy, NULL, dev, B_READ, ssminphys, uio));
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Actually translate the requested transfer into one the physical
|
|
|
|
* driver can understand The transfer is described by a buf and will
|
|
|
|
* include only one physical transfer.
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
ssstrategy(bp)
|
|
|
|
struct buf *bp;
|
|
|
|
{
|
1996-03-17 03:57:14 +03:00
|
|
|
struct ss_softc *ss = ss_cd.cd_devs[SSUNIT(bp->b_dev)];
|
2001-04-25 21:53:04 +04:00
|
|
|
struct scsipi_periph *periph = ss->sc_periph;
|
1996-02-18 23:32:40 +03:00
|
|
|
int s;
|
|
|
|
|
2001-04-25 21:53:04 +04:00
|
|
|
SC_DEBUG(ss->sc_periph, SCSIPI_DB1,
|
1996-05-05 23:52:50 +04:00
|
|
|
("ssstrategy %ld bytes @ blk %d\n", bp->b_bcount, bp->b_blkno));
|
1996-02-18 23:32:40 +03:00
|
|
|
|
2001-01-01 21:28:49 +03:00
|
|
|
/*
|
|
|
|
* If the device has been made invalid, error out
|
|
|
|
*/
|
|
|
|
if ((ss->sc_dev.dv_flags & DVF_ACTIVE) == 0) {
|
|
|
|
bp->b_flags |= B_ERROR;
|
2001-04-25 21:53:04 +04:00
|
|
|
if (periph->periph_flags & PERIPH_OPEN)
|
2001-01-01 21:28:49 +03:00
|
|
|
bp->b_error = EIO;
|
|
|
|
else
|
|
|
|
bp->b_error = ENODEV;
|
|
|
|
goto done;
|
|
|
|
}
|
|
|
|
|
1999-02-10 15:29:50 +03:00
|
|
|
/* If negative offset, error */
|
|
|
|
if (bp->b_blkno < 0) {
|
|
|
|
bp->b_flags |= B_ERROR;
|
|
|
|
bp->b_error = EINVAL;
|
|
|
|
goto done;
|
|
|
|
}
|
|
|
|
|
1996-02-19 03:06:07 +03:00
|
|
|
if (bp->b_bcount > ss->sio.scan_window_size)
|
|
|
|
bp->b_bcount = ss->sio.scan_window_size;
|
|
|
|
|
1996-02-18 23:32:40 +03:00
|
|
|
/*
|
|
|
|
* If it's a null transfer, return immediatly
|
|
|
|
*/
|
|
|
|
if (bp->b_bcount == 0)
|
|
|
|
goto done;
|
|
|
|
|
|
|
|
s = splbio();
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Place it in the queue of activities for this scanner
|
|
|
|
* at the end (a bit silly because we only have on user..
|
|
|
|
* (but it could fork()))
|
|
|
|
*/
|
2002-07-22 18:59:43 +04:00
|
|
|
BUFQ_PUT(&ss->buf_queue, bp);
|
1996-02-18 23:32:40 +03:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Tell the device to get going on the transfer if it's
|
|
|
|
* not doing anything, otherwise just wait for completion
|
|
|
|
* (All a bit silly if we're only allowing 1 open but..)
|
|
|
|
*/
|
2001-04-25 21:53:04 +04:00
|
|
|
ssstart(ss->sc_periph);
|
1996-02-18 23:32:40 +03:00
|
|
|
|
|
|
|
splx(s);
|
|
|
|
return;
|
|
|
|
done:
|
|
|
|
/*
|
|
|
|
* Correctly set the buf to indicate a completed xfer
|
|
|
|
*/
|
|
|
|
bp->b_resid = bp->b_bcount;
|
|
|
|
biodone(bp);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* ssstart looks to see if there is a buf waiting for the device
|
|
|
|
* and that the device is not already busy. If both are true,
|
|
|
|
* It dequeues the buf and creates a scsi command to perform the
|
1997-08-27 15:22:52 +04:00
|
|
|
* transfer required. The transfer request will call scsipi_done
|
1996-02-18 23:32:40 +03:00
|
|
|
* on completion, which will in turn call this routine again
|
|
|
|
* so that the next queued transfer is performed.
|
|
|
|
* The bufs are queued by the strategy routine (ssstrategy)
|
|
|
|
*
|
|
|
|
* This routine is also called after other non-queued requests
|
|
|
|
* have been made of the scsi driver, to ensure that the queue
|
|
|
|
* continues to be drained.
|
|
|
|
* ssstart() is called at splbio
|
|
|
|
*/
|
|
|
|
void
|
2001-04-25 21:53:04 +04:00
|
|
|
ssstart(periph)
|
|
|
|
struct scsipi_periph *periph;
|
1996-02-18 23:32:40 +03:00
|
|
|
{
|
2001-04-25 21:53:04 +04:00
|
|
|
struct ss_softc *ss = (void *)periph->periph_dev;
|
2000-03-30 04:00:55 +04:00
|
|
|
struct buf *bp;
|
1996-02-18 23:32:40 +03:00
|
|
|
|
2001-04-25 21:53:04 +04:00
|
|
|
SC_DEBUG(periph, SCSIPI_DB2, ("ssstart "));
|
1996-02-18 23:32:40 +03:00
|
|
|
/*
|
|
|
|
* See if there is a buf to do and we are not already
|
|
|
|
* doing one
|
|
|
|
*/
|
2001-04-25 21:53:04 +04:00
|
|
|
while (periph->periph_active < periph->periph_openings) {
|
1996-02-18 23:32:40 +03:00
|
|
|
/* if a special awaits, let it proceed first */
|
2001-04-25 21:53:04 +04:00
|
|
|
if (periph->periph_flags & PERIPH_WAITING) {
|
|
|
|
periph->periph_flags &= ~PERIPH_WAITING;
|
|
|
|
wakeup((caddr_t)periph);
|
1996-02-18 23:32:40 +03:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* See if there is a buf with work for us to do..
|
|
|
|
*/
|
2002-07-22 18:59:43 +04:00
|
|
|
if ((bp = BUFQ_GET(&ss->buf_queue)) == NULL)
|
1996-02-18 23:32:40 +03:00
|
|
|
return;
|
|
|
|
|
1998-08-19 12:40:31 +04:00
|
|
|
if (ss->special && ss->special->read) {
|
1996-02-18 23:32:40 +03:00
|
|
|
(ss->special->read)(ss, bp);
|
|
|
|
} else {
|
|
|
|
/* generic scsi2 scanner read */
|
|
|
|
/* XXX add code for SCSI2 scanner read */
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Perform special action on behalf of the user;
|
|
|
|
* knows about the internals of this device
|
|
|
|
*/
|
|
|
|
int
|
|
|
|
ssioctl(dev, cmd, addr, flag, p)
|
|
|
|
dev_t dev;
|
|
|
|
u_long cmd;
|
|
|
|
caddr_t addr;
|
|
|
|
int flag;
|
|
|
|
struct proc *p;
|
|
|
|
{
|
1996-03-17 03:57:14 +03:00
|
|
|
struct ss_softc *ss = ss_cd.cd_devs[SSUNIT(dev)];
|
1996-02-18 23:32:40 +03:00
|
|
|
int error = 0;
|
|
|
|
struct scan_io *sio;
|
|
|
|
|
2001-01-01 21:28:49 +03:00
|
|
|
if ((ss->sc_dev.dv_flags & DVF_ACTIVE) == 0)
|
|
|
|
return (ENODEV);
|
|
|
|
|
1996-02-18 23:32:40 +03:00
|
|
|
switch (cmd) {
|
|
|
|
case SCIOCGET:
|
1998-08-19 12:40:31 +04:00
|
|
|
if (ss->special && ss->special->get_params) {
|
1996-02-18 23:32:40 +03:00
|
|
|
/* call special handler */
|
1996-02-18 23:41:18 +03:00
|
|
|
error = (ss->special->get_params)(ss);
|
|
|
|
if (error)
|
1996-02-18 23:32:40 +03:00
|
|
|
return (error);
|
|
|
|
} else {
|
|
|
|
/* XXX add code for SCSI2 scanner, if any */
|
|
|
|
return (EOPNOTSUPP);
|
|
|
|
}
|
2001-07-18 22:25:41 +04:00
|
|
|
memcpy(addr, &ss->sio, sizeof(struct scan_io));
|
1996-02-18 23:32:40 +03:00
|
|
|
break;
|
|
|
|
case SCIOCSET:
|
|
|
|
sio = (struct scan_io *)addr;
|
|
|
|
|
1998-08-19 12:40:31 +04:00
|
|
|
if (ss->special && ss->special->set_params) {
|
1996-02-18 23:32:40 +03:00
|
|
|
/* call special handler */
|
1996-02-18 23:41:18 +03:00
|
|
|
error = (ss->special->set_params)(ss, sio);
|
|
|
|
if (error)
|
1996-02-18 23:32:40 +03:00
|
|
|
return (error);
|
|
|
|
} else {
|
|
|
|
/* XXX add code for SCSI2 scanner, if any */
|
|
|
|
return (EOPNOTSUPP);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case SCIOCRESTART:
|
1998-08-19 12:40:31 +04:00
|
|
|
if (ss->special && ss->special->rewind_scanner ) {
|
1996-02-18 23:32:40 +03:00
|
|
|
/* call special handler */
|
1996-02-18 23:41:18 +03:00
|
|
|
error = (ss->special->rewind_scanner)(ss);
|
|
|
|
if (error)
|
1996-02-18 23:32:40 +03:00
|
|
|
return (error);
|
|
|
|
} else
|
|
|
|
/* XXX add code for SCSI2 scanner, if any */
|
|
|
|
return (EOPNOTSUPP);
|
|
|
|
ss->flags &= ~SSF_TRIGGERED;
|
|
|
|
break;
|
|
|
|
#ifdef NOTYET
|
|
|
|
case SCAN_USE_ADF:
|
|
|
|
break;
|
|
|
|
#endif
|
|
|
|
default:
|
2001-04-25 21:53:04 +04:00
|
|
|
return (scsipi_do_ioctl(ss->sc_periph, dev, cmd, addr,
|
|
|
|
flag, p));
|
1996-02-18 23:32:40 +03:00
|
|
|
}
|
|
|
|
return (error);
|
|
|
|
}
|