2005-02-01 03:19:34 +03:00
|
|
|
/* $NetBSD: ss.c,v 1.59 2005/02/01 00:19:34 reinoud 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>
|
2005-02-01 03:19:34 +03:00
|
|
|
__KERNEL_RCSID(0, "$NetBSD: ss.c,v 1.59 2005/02/01 00:19:34 reinoud 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>
|
2004-10-28 11:07:35 +04:00
|
|
|
#include <sys/bufq.h>
|
1996-02-18 23:32:40 +03:00
|
|
|
#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
|
|
|
|
|
2004-08-22 02:02:31 +04:00
|
|
|
static int ssmatch(struct device *, struct cfdata *, void *);
|
|
|
|
static void ssattach(struct device *, struct device *, void *);
|
|
|
|
static int ssdetach(struct device *self, int flags);
|
|
|
|
static 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
|
|
|
|
2004-08-22 02:02:31 +04:00
|
|
|
static dev_type_open(ssopen);
|
|
|
|
static dev_type_close(ssclose);
|
|
|
|
static dev_type_read(ssread);
|
|
|
|
static dev_type_ioctl(ssioctl);
|
2002-09-06 17:18:43 +04:00
|
|
|
|
|
|
|
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
|
|
|
};
|
|
|
|
|
2004-08-22 02:02:31 +04:00
|
|
|
static void ssstrategy(struct buf *);
|
|
|
|
static void ssstart(struct scsipi_periph *);
|
2004-09-18 03:10:50 +04:00
|
|
|
static void ssdone(struct scsipi_xfer *, int);
|
2004-08-22 02:02:31 +04:00
|
|
|
static void ssminphys(struct buf *);
|
1996-02-18 23:32:40 +03:00
|
|
|
|
2004-08-22 02:02:31 +04:00
|
|
|
static const struct scsipi_periphsw ss_switch = {
|
1996-02-18 23:32:40 +03:00
|
|
|
NULL,
|
|
|
|
ssstart,
|
|
|
|
NULL,
|
2004-09-18 03:10:50 +04:00
|
|
|
ssdone,
|
1996-02-18 23:32:40 +03:00
|
|
|
};
|
|
|
|
|
2004-08-22 02:02:31 +04:00
|
|
|
static const 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
|
|
|
};
|
|
|
|
|
2004-08-22 02:02:31 +04:00
|
|
|
static 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
|
|
|
|
*/
|
2004-08-22 02:02:31 +04:00
|
|
|
static 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);
|
|
|
|
|
Improve handling of memory shortage, to fix problems like:
sd3(mpt0:0:1:0): unable to allocate scsipi_xfer
sd3: not queued, error 12
Havard Eidnes's analysis of this problem is that the scsipi_xfer pool is
competing for resources with other pools, including the the inode and vnode
pools which can grow quite large.
*_scsipi_cmd(): don't biodone the buffer if scsipi_make_xs() fails, let the
caller deal with the problem
start function of block devices drivers: dequeue the buffer after the
scsipi_command() call. If scsipi_command() fails with ENOMEM don't dequeue
the buffer, and schedule a callout to call the start function after
some delay.
scsipi_init(): prime the scsipi_xfer_pool with one page. This ensure that
there is always some scsipi_xfer to play with. If scsipi_command() fails
because of pool_get(), we're sure there will be resources available later,
when the pending commands have completed.
Reviewed by Jason Thorpe and Havard Eidnes.
Todo: remove the "unable to allocate scsipi_xfer" and "not queued, error %d"
printfs, but I choose to keep them for now, to help make sure the code does
what it should.
2004-08-28 00:37:28 +04:00
|
|
|
callout_init(&ss->sc_callout);
|
|
|
|
|
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
|
|
|
}
|
|
|
|
|
2004-08-22 02:02:31 +04:00
|
|
|
static int
|
2001-01-01 21:28:49 +03:00
|
|
|
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
|
|
|
|
Improve handling of memory shortage, to fix problems like:
sd3(mpt0:0:1:0): unable to allocate scsipi_xfer
sd3: not queued, error 12
Havard Eidnes's analysis of this problem is that the scsipi_xfer pool is
competing for resources with other pools, including the the inode and vnode
pools which can grow quite large.
*_scsipi_cmd(): don't biodone the buffer if scsipi_make_xs() fails, let the
caller deal with the problem
start function of block devices drivers: dequeue the buffer after the
scsipi_command() call. If scsipi_command() fails with ENOMEM don't dequeue
the buffer, and schedule a callout to call the start function after
some delay.
scsipi_init(): prime the scsipi_xfer_pool with one page. This ensure that
there is always some scsipi_xfer to play with. If scsipi_command() fails
because of pool_get(), we're sure there will be resources available later,
when the pending commands have completed.
Reviewed by Jason Thorpe and Havard Eidnes.
Todo: remove the "unable to allocate scsipi_xfer" and "not queued, error %d"
printfs, but I choose to keep them for now, to help make sure the code does
what it should.
2004-08-28 00:37:28 +04:00
|
|
|
/* kill any pending restart */
|
|
|
|
callout_stop(&ss->sc_callout);
|
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
2004-08-22 02:02:31 +04:00
|
|
|
static int
|
2001-01-01 21:28:49 +03:00
|
|
|
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.
|
|
|
|
*/
|
2004-08-22 02:02:31 +04:00
|
|
|
static int
|
2003-06-30 02:28:00 +04:00
|
|
|
ssopen(dev_t dev, int flag, int mode, struct proc *p)
|
1996-02-18 23:32:40 +03:00
|
|
|
{
|
|
|
|
int unit;
|
2005-02-01 03:19:34 +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
|
|
|
|
*/
|
2004-08-22 02:02:31 +04:00
|
|
|
static int
|
2003-06-30 02:28:00 +04: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
|
|
|
|
*/
|
2004-08-22 02:02:31 +04:00
|
|
|
static 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
|
|
|
|
2004-03-14 03:17:37 +03:00
|
|
|
scsipi_adapter_minphys(periph->periph_channel, 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.
|
|
|
|
*/
|
2004-08-22 02:02:31 +04:00
|
|
|
static int
|
|
|
|
ssread(dev_t dev, struct uio *uio, int flag)
|
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)];
|
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.
|
|
|
|
*/
|
2004-08-22 02:02:31 +04:00
|
|
|
static void
|
|
|
|
ssstrategy(struct buf *bp)
|
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(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,
|
2004-10-17 21:49:04 +04:00
|
|
|
("ssstrategy %d bytes @ blk %" PRId64 "\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
|
|
|
|
*/
|
2004-08-22 02:02:31 +04:00
|
|
|
static void
|
|
|
|
ssstart(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..
|
|
|
|
*/
|
Improve handling of memory shortage, to fix problems like:
sd3(mpt0:0:1:0): unable to allocate scsipi_xfer
sd3: not queued, error 12
Havard Eidnes's analysis of this problem is that the scsipi_xfer pool is
competing for resources with other pools, including the the inode and vnode
pools which can grow quite large.
*_scsipi_cmd(): don't biodone the buffer if scsipi_make_xs() fails, let the
caller deal with the problem
start function of block devices drivers: dequeue the buffer after the
scsipi_command() call. If scsipi_command() fails with ENOMEM don't dequeue
the buffer, and schedule a callout to call the start function after
some delay.
scsipi_init(): prime the scsipi_xfer_pool with one page. This ensure that
there is always some scsipi_xfer to play with. If scsipi_command() fails
because of pool_get(), we're sure there will be resources available later,
when the pending commands have completed.
Reviewed by Jason Thorpe and Havard Eidnes.
Todo: remove the "unable to allocate scsipi_xfer" and "not queued, error %d"
printfs, but I choose to keep them for now, to help make sure the code does
what it should.
2004-08-28 00:37:28 +04:00
|
|
|
if ((bp = BUFQ_PEEK(&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 */
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2004-09-18 03:13:02 +04:00
|
|
|
void
|
Improve handling of memory shortage, to fix problems like:
sd3(mpt0:0:1:0): unable to allocate scsipi_xfer
sd3: not queued, error 12
Havard Eidnes's analysis of this problem is that the scsipi_xfer pool is
competing for resources with other pools, including the the inode and vnode
pools which can grow quite large.
*_scsipi_cmd(): don't biodone the buffer if scsipi_make_xs() fails, let the
caller deal with the problem
start function of block devices drivers: dequeue the buffer after the
scsipi_command() call. If scsipi_command() fails with ENOMEM don't dequeue
the buffer, and schedule a callout to call the start function after
some delay.
scsipi_init(): prime the scsipi_xfer_pool with one page. This ensure that
there is always some scsipi_xfer to play with. If scsipi_command() fails
because of pool_get(), we're sure there will be resources available later,
when the pending commands have completed.
Reviewed by Jason Thorpe and Havard Eidnes.
Todo: remove the "unable to allocate scsipi_xfer" and "not queued, error %d"
printfs, but I choose to keep them for now, to help make sure the code does
what it should.
2004-08-28 00:37:28 +04:00
|
|
|
ssrestart(void *v)
|
|
|
|
{
|
|
|
|
int s = splbio();
|
|
|
|
ssstart((struct scsipi_periph *)v);
|
|
|
|
splx(s);
|
|
|
|
}
|
2004-09-18 03:10:50 +04:00
|
|
|
|
|
|
|
static void
|
|
|
|
ssdone(struct scsipi_xfer *xs, int error)
|
|
|
|
{
|
|
|
|
struct buf *bp = xs->bp;
|
|
|
|
|
|
|
|
if (bp) {
|
|
|
|
bp->b_error = error;
|
|
|
|
bp->b_resid = xs->resid;
|
|
|
|
if (error)
|
|
|
|
bp->b_flags |= B_ERROR;
|
|
|
|
biodone(bp);
|
|
|
|
}
|
|
|
|
}
|
Improve handling of memory shortage, to fix problems like:
sd3(mpt0:0:1:0): unable to allocate scsipi_xfer
sd3: not queued, error 12
Havard Eidnes's analysis of this problem is that the scsipi_xfer pool is
competing for resources with other pools, including the the inode and vnode
pools which can grow quite large.
*_scsipi_cmd(): don't biodone the buffer if scsipi_make_xs() fails, let the
caller deal with the problem
start function of block devices drivers: dequeue the buffer after the
scsipi_command() call. If scsipi_command() fails with ENOMEM don't dequeue
the buffer, and schedule a callout to call the start function after
some delay.
scsipi_init(): prime the scsipi_xfer_pool with one page. This ensure that
there is always some scsipi_xfer to play with. If scsipi_command() fails
because of pool_get(), we're sure there will be resources available later,
when the pending commands have completed.
Reviewed by Jason Thorpe and Havard Eidnes.
Todo: remove the "unable to allocate scsipi_xfer" and "not queued, error %d"
printfs, but I choose to keep them for now, to help make sure the code does
what it should.
2004-08-28 00:37:28 +04:00
|
|
|
|
|
|
|
|
1996-02-18 23:32:40 +03:00
|
|
|
/*
|
|
|
|
* Perform special action on behalf of the user;
|
|
|
|
* knows about the internals of this device
|
|
|
|
*/
|
|
|
|
int
|
2005-02-01 03:19:34 +03:00
|
|
|
ssioctl(dev_t dev, u_long cmd, caddr_t addr, int flag, 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)];
|
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,
|
2003-06-30 02:28:00 +04:00
|
|
|
flag, p));
|
1996-02-18 23:32:40 +03:00
|
|
|
}
|
|
|
|
return (error);
|
|
|
|
}
|