1995-05-30 08:16:23 +00:00
|
|
|
/*
|
1995-01-08 13:38:38 +00:00
|
|
|
* Copyright (C) 1992, 1993, 1994, HD Associates, Inc.
|
|
|
|
* PO Box 276
|
|
|
|
* Pepperell, MA 01463
|
|
|
|
* 508 433 5266
|
|
|
|
* dufault@hda.com
|
1993-11-18 05:03:27 +00:00
|
|
|
*
|
1995-01-08 13:38:38 +00:00
|
|
|
* This code is contributed to the University of California at Berkeley:
|
1993-11-18 05:03:27 +00:00
|
|
|
*
|
1995-01-08 13:38:38 +00:00
|
|
|
* 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 the University of
|
|
|
|
* California, Berkeley and its contributors.
|
|
|
|
* 4. Neither the name of the University nor the names of its contributors
|
|
|
|
* may be used to endorse or promote products derived from this software
|
|
|
|
* without specific prior written permission.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``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 REGENTS OR CONTRIBUTORS 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.
|
|
|
|
*End copyright
|
|
|
|
*
|
1998-06-07 17:13:14 +00:00
|
|
|
* $Id: scsi_ioctl.c,v 1.30 1998/03/28 10:33:21 bde Exp $
|
1995-01-08 13:38:38 +00:00
|
|
|
*
|
|
|
|
*
|
1993-11-18 05:03:27 +00:00
|
|
|
*/
|
1996-01-05 20:12:53 +00:00
|
|
|
|
|
|
|
#include "opt_bounce.h"
|
1996-07-14 10:46:56 +00:00
|
|
|
#include "opt_scsi.h"
|
1996-01-05 20:12:53 +00:00
|
|
|
|
1993-11-18 05:03:27 +00:00
|
|
|
#include <sys/param.h>
|
1994-05-25 09:21:21 +00:00
|
|
|
#include <sys/systm.h>
|
1993-11-18 05:03:27 +00:00
|
|
|
#include <sys/malloc.h>
|
|
|
|
#include <sys/buf.h>
|
1995-05-03 18:09:20 +00:00
|
|
|
|
1993-11-18 05:03:27 +00:00
|
|
|
#define b_screq b_driver1 /* a patch in buf.h */
|
|
|
|
#define b_sc_link b_driver2 /* a patch in buf.h */
|
1995-05-03 18:09:20 +00:00
|
|
|
|
|
|
|
#include <sys/fcntl.h>
|
1993-11-18 05:03:27 +00:00
|
|
|
#include <sys/proc.h>
|
1998-03-28 10:33:27 +00:00
|
|
|
#include <sys/uio.h>
|
1993-11-18 05:03:27 +00:00
|
|
|
|
|
|
|
#include <scsi/scsiconf.h>
|
1997-03-23 06:33:55 +00:00
|
|
|
#include <scsi/scsi_debug.h>
|
1993-11-18 05:03:27 +00:00
|
|
|
#include <sys/scsiio.h>
|
|
|
|
|
1995-12-14 09:55:16 +00:00
|
|
|
static void scsierr(struct buf *, int); /* XXX ??? */
|
1993-11-18 05:03:27 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* We let the user interpret his own sense in the generic scsi world.
|
|
|
|
* This routine is called at interrupt time if the SCSI_USER bit was set
|
|
|
|
* in the flags passed to scsi_scsi_cmd(). No other completion processing
|
|
|
|
* takes place, even if we are running over another device driver.
|
|
|
|
* The lower level routines that call us here, will free the xs and restart
|
|
|
|
* the device's queue if such exists.
|
|
|
|
*/
|
|
|
|
#ifndef min
|
|
|
|
#define min(A,B) ((A<B) ? A : B )
|
|
|
|
#endif
|
|
|
|
|
|
|
|
void scsi_user_done(xs)
|
|
|
|
struct scsi_xfer *xs;
|
|
|
|
{
|
|
|
|
|
|
|
|
struct buf *bp;
|
|
|
|
scsireq_t *screq;
|
|
|
|
|
|
|
|
bp = xs->bp;
|
|
|
|
if(!bp) { /* ALL user requests must have a buf */
|
|
|
|
sc_print_addr(xs->sc_link);
|
|
|
|
printf("User command with no buf\n");
|
|
|
|
return ;
|
|
|
|
}
|
|
|
|
screq = bp->b_screq;
|
|
|
|
if (!screq) { /* Is it one of ours? (the SCSI_USER bit says it is) */
|
|
|
|
sc_print_addr(xs->sc_link);
|
|
|
|
printf("User command with no request\n");
|
|
|
|
return ;
|
|
|
|
}
|
|
|
|
|
|
|
|
SC_DEBUG(xs->sc_link,SDEV_DB2,("user-done\n"));
|
|
|
|
screq->retsts = 0;
|
|
|
|
screq->status = xs->status;
|
1993-12-19 00:55:01 +00:00
|
|
|
switch((int)xs->error) {
|
1993-11-18 05:03:27 +00:00
|
|
|
case XS_NOERROR:
|
|
|
|
SC_DEBUG(xs->sc_link,SDEV_DB3,("no error\n"));
|
1995-04-14 15:10:44 +00:00
|
|
|
if (xs->flags & SCSI_RESID_VALID)
|
|
|
|
screq->datalen_used = xs->datalen - xs->resid;
|
|
|
|
else
|
|
|
|
screq->datalen_used = xs->datalen;
|
1993-11-18 05:03:27 +00:00
|
|
|
screq->retsts = SCCMD_OK;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case XS_SENSE:
|
|
|
|
SC_DEBUG(xs->sc_link,SDEV_DB3,("have sense\n"));
|
|
|
|
screq->senselen_used = min(sizeof(xs->sense),SENSEBUFLEN);
|
|
|
|
bcopy(&xs->sense,screq->sense,screq->senselen);
|
|
|
|
screq->retsts = SCCMD_SENSE;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case XS_DRIVER_STUFFUP:
|
|
|
|
sc_print_addr(xs->sc_link);
|
|
|
|
printf("host adapter code inconsistency\n");
|
|
|
|
screq->retsts = SCCMD_UNKNOWN;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case XS_TIMEOUT:
|
|
|
|
SC_DEBUG(xs->sc_link,SDEV_DB3,("timeout\n"));
|
|
|
|
screq->retsts = SCCMD_TIMEOUT;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case XS_BUSY:
|
|
|
|
SC_DEBUG(xs->sc_link,SDEV_DB3,("busy\n"));
|
|
|
|
screq->retsts = SCCMD_BUSY;
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
sc_print_addr(xs->sc_link);
|
|
|
|
printf("unknown error category from host adapter code\n");
|
|
|
|
screq->retsts = SCCMD_UNKNOWN;
|
|
|
|
break;
|
|
|
|
}
|
1995-01-19 12:41:36 +00:00
|
|
|
biodone(bp); /* we're waiting on it in scsistrategy() */
|
1993-11-18 05:03:27 +00:00
|
|
|
return; /* it'll free the xs and restart any queue */
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* Pseudo strategy function
|
|
|
|
* Called by scsi_do_ioctl() via physio/physstrat if there is to
|
|
|
|
* be data transfered, and directly if there is no data transfer.
|
1995-05-30 08:16:23 +00:00
|
|
|
*
|
1993-11-18 05:03:27 +00:00
|
|
|
* Can't be used with block devices or raw_read/raw_write directly
|
|
|
|
* from the cdevsw/bdevsw tables because they couldn't have added
|
|
|
|
* the screq structure. [JRE]
|
|
|
|
*/
|
1995-12-14 09:55:16 +00:00
|
|
|
static void
|
|
|
|
scsistrategy(struct buf *bp)
|
1993-11-18 05:03:27 +00:00
|
|
|
{
|
|
|
|
errval err;
|
|
|
|
struct scsi_link *sc_link = bp->b_sc_link;
|
|
|
|
scsireq_t *screq;
|
1996-03-10 07:13:15 +00:00
|
|
|
u_int32_t flags = 0;
|
1993-11-18 05:03:27 +00:00
|
|
|
int s;
|
|
|
|
|
|
|
|
|
|
|
|
if(!sc_link) {
|
|
|
|
printf("user_strat: No link pointer\n");
|
|
|
|
scsierr(bp,EINVAL);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
SC_DEBUG(sc_link,SDEV_DB2,("user_strategy\n"));
|
|
|
|
screq = bp->b_screq;
|
|
|
|
if(!screq) {
|
|
|
|
sc_print_addr(sc_link);
|
|
|
|
printf("No request block\n");
|
|
|
|
scsierr(bp,EINVAL);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* We're in trouble if physio tried to break up the
|
|
|
|
* transfer:
|
|
|
|
*/
|
|
|
|
if (bp->b_bcount != screq->datalen) {
|
|
|
|
sc_print_addr(sc_link);
|
|
|
|
printf("physio split the request.. cannot proceed\n");
|
|
|
|
scsierr(bp, EIO);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (screq->timeout == 0) {
|
|
|
|
scsierr(bp, EINVAL);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (screq->cmdlen > sizeof(struct scsi_generic)) {
|
|
|
|
sc_print_addr(sc_link);
|
|
|
|
printf("cmdlen too big ");
|
|
|
|
scsierr(bp, EFAULT);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (screq->flags & SCCMD_READ)
|
|
|
|
flags |= SCSI_DATA_IN;
|
|
|
|
|
|
|
|
if (screq->flags & SCCMD_WRITE)
|
|
|
|
flags |= SCSI_DATA_OUT;
|
|
|
|
|
|
|
|
if (screq->flags & SCCMD_TARGET)
|
|
|
|
flags |= SCSI_TARGET;
|
|
|
|
|
|
|
|
if (screq->flags & SCCMD_ESCAPE)
|
|
|
|
flags |= SCSI_ESCAPE;
|
1995-05-09 02:38:15 +00:00
|
|
|
|
|
|
|
#ifdef BOUNCE_BUFFERS
|
|
|
|
if (sc_link->flags & SDEV_BOUNCE)
|
|
|
|
vm_bounce_alloc(bp);
|
|
|
|
#endif
|
|
|
|
|
1993-11-18 05:03:27 +00:00
|
|
|
err = scsi_scsi_cmd(sc_link,
|
|
|
|
(struct scsi_generic *)screq->cmd,
|
|
|
|
screq->cmdlen,
|
1997-12-02 21:07:20 +00:00
|
|
|
(u_char *)bp->b_data,
|
1993-11-18 05:03:27 +00:00
|
|
|
screq->datalen,
|
|
|
|
0, /* user must do the retries *//* ignored */
|
|
|
|
screq->timeout,
|
|
|
|
bp,
|
|
|
|
flags | SCSI_USER);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*because there is a bp, scsi_scsi_cmd will return immediatly*/
|
|
|
|
if (err)
|
|
|
|
{
|
|
|
|
scsierr(bp, err);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
SC_DEBUG(sc_link,SDEV_DB3,("about to sleep\n"));
|
|
|
|
s = splbio();
|
|
|
|
while(!(bp->b_flags & B_DONE))
|
|
|
|
{
|
1994-03-20 00:30:59 +00:00
|
|
|
tsleep((caddr_t)bp, PRIBIO, "scsistrat", 0);
|
1993-11-18 05:03:27 +00:00
|
|
|
}
|
|
|
|
splx(s);
|
|
|
|
SC_DEBUG(sc_link,SDEV_DB3,("back from sleep\n"));
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Something (e.g. another driver) has called us
|
|
|
|
* with an sc_link for a target/lun/adapter, and a scsi
|
|
|
|
* specific ioctl to perform, better try.
|
|
|
|
* If user-level type command, we must still be running
|
|
|
|
* in the context of the calling process
|
|
|
|
*/
|
1998-06-07 17:13:14 +00:00
|
|
|
errval scsi_do_ioctl(dev_t dev, u_long cmd, caddr_t addr, int flags,
|
1995-03-04 20:51:10 +00:00
|
|
|
struct proc *p, struct scsi_link *sc_link)
|
1993-11-18 05:03:27 +00:00
|
|
|
{
|
|
|
|
errval ret = 0;
|
|
|
|
|
1995-05-03 18:09:20 +00:00
|
|
|
/* If we can't write the device we can't permit much:
|
|
|
|
*/
|
|
|
|
|
1998-02-01 18:09:50 +00:00
|
|
|
if (cmd != SCIOCIDENTIFY && cmd != SCIOCGETDEVINFO&& !(flags & FWRITE))
|
1995-05-03 18:09:20 +00:00
|
|
|
return EACCES;
|
|
|
|
|
1993-11-18 05:03:27 +00:00
|
|
|
SC_DEBUG(sc_link,SDEV_DB2,("scsi_do_ioctl(0x%x)\n",cmd));
|
|
|
|
switch(cmd)
|
|
|
|
{
|
|
|
|
case SCIOCCOMMAND:
|
|
|
|
{
|
|
|
|
/*
|
|
|
|
* You won't believe this, but the arg copied in
|
|
|
|
* from the user space, is on the kernel stack
|
|
|
|
* for this process, so we can't write
|
|
|
|
* to it at interrupt time..
|
|
|
|
* we need to copy it in and out!
|
|
|
|
* Make a static copy using malloc!
|
|
|
|
*/
|
|
|
|
scsireq_t *screq2 = (scsireq_t *)addr;
|
|
|
|
scsireq_t *screq = (scsireq_t *)addr;
|
|
|
|
int rwflag = (screq->flags & SCCMD_READ) ? B_READ : B_WRITE;
|
|
|
|
struct buf *bp;
|
|
|
|
caddr_t d_addr;
|
|
|
|
int len;
|
|
|
|
|
1995-01-08 13:38:38 +00:00
|
|
|
#if 0 /* XXX dufault@hda.com: This looks too rev dependent. Do it always? */
|
1994-01-14 16:25:31 +00:00
|
|
|
if((unsigned int)screq < (unsigned int)KERNBASE)
|
1995-01-08 13:38:38 +00:00
|
|
|
#endif
|
1993-11-18 05:03:27 +00:00
|
|
|
{
|
|
|
|
screq = malloc(sizeof(scsireq_t),M_TEMP,M_WAITOK);
|
|
|
|
bcopy(screq2,screq,sizeof(scsireq_t));
|
|
|
|
}
|
|
|
|
bp = malloc(sizeof (struct buf),M_TEMP,M_WAITOK);
|
|
|
|
bzero(bp,sizeof(struct buf));
|
|
|
|
d_addr = screq->databuf;
|
|
|
|
bp->b_bcount = len = screq->datalen;
|
|
|
|
bp->b_screq = screq;
|
|
|
|
bp->b_sc_link = sc_link;
|
|
|
|
if (len) {
|
1995-01-08 13:38:38 +00:00
|
|
|
struct uio auio;
|
|
|
|
struct iovec aiov;
|
1995-04-14 15:10:44 +00:00
|
|
|
long cnt;
|
1995-01-08 13:38:38 +00:00
|
|
|
|
|
|
|
aiov.iov_base = d_addr;
|
|
|
|
aiov.iov_len = len;
|
|
|
|
auio.uio_iov = &aiov;
|
|
|
|
auio.uio_iovcnt = 1;
|
|
|
|
|
|
|
|
auio.uio_resid = len;
|
|
|
|
if (auio.uio_resid < 0)
|
|
|
|
return (EINVAL);
|
|
|
|
|
|
|
|
auio.uio_rw = (rwflag == B_READ) ? UIO_READ : UIO_WRITE;
|
|
|
|
auio.uio_segflg = UIO_USERSPACE;
|
|
|
|
auio.uio_procp = curproc;
|
|
|
|
cnt = len;
|
1993-11-18 05:03:27 +00:00
|
|
|
ret = physio(scsistrategy, bp, dev, rwflag,
|
1995-01-08 13:38:38 +00:00
|
|
|
minphys, &auio);
|
1993-11-18 05:03:27 +00:00
|
|
|
} else {
|
|
|
|
/* if no data, no need to translate it.. */
|
1997-12-02 21:07:20 +00:00
|
|
|
bp->b_data = 0;
|
1995-01-08 13:38:38 +00:00
|
|
|
bp->b_dev = dev;
|
1996-03-02 01:49:51 +00:00
|
|
|
bp->b_flags |= B_BUSY;
|
1993-11-18 05:03:27 +00:00
|
|
|
|
|
|
|
scsistrategy(bp);
|
|
|
|
ret = bp->b_error;
|
|
|
|
}
|
|
|
|
free(bp,M_TEMP);
|
1995-01-08 13:38:38 +00:00
|
|
|
#if 0 /* XXX dufault@hda.com: This looks too rev dependent. Do it always? */
|
1994-01-14 16:25:31 +00:00
|
|
|
if((unsigned int)screq2 < (unsigned int)KERNBASE)
|
1995-01-08 13:38:38 +00:00
|
|
|
#endif
|
1993-11-18 05:03:27 +00:00
|
|
|
{
|
|
|
|
bcopy(screq,screq2,sizeof(scsireq_t));
|
|
|
|
free(screq,M_TEMP);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case SCIOCDEBUG:
|
|
|
|
{
|
|
|
|
int level = *((int *)addr);
|
|
|
|
SC_DEBUG(sc_link,SDEV_DB3,("debug set to %d\n",level));
|
|
|
|
sc_link->flags &= ~SDEV_DBX; /*clear debug bits */
|
|
|
|
if(level & 1) sc_link->flags |= SDEV_DB1;
|
|
|
|
if(level & 2) sc_link->flags |= SDEV_DB2;
|
|
|
|
if(level & 4) sc_link->flags |= SDEV_DB3;
|
|
|
|
if(level & 8) sc_link->flags |= SDEV_DB4;
|
|
|
|
ret = 0;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case SCIOCREPROBE:
|
|
|
|
{
|
|
|
|
struct scsi_addr *sca = (struct scsi_addr *) addr;
|
|
|
|
|
|
|
|
ret = scsi_probe_busses(sca->scbus,sca->target,sca->lun);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case SCIOCRECONFIG:
|
|
|
|
case SCIOCDECONFIG:
|
|
|
|
ret = EINVAL;
|
|
|
|
break;
|
1995-05-03 18:09:20 +00:00
|
|
|
|
1993-11-18 05:03:27 +00:00
|
|
|
case SCIOCIDENTIFY:
|
|
|
|
{
|
|
|
|
struct scsi_addr *sca = (struct scsi_addr *) addr;
|
|
|
|
sca->scbus = sc_link->scsibus;
|
|
|
|
sca->target = sc_link->target;
|
|
|
|
sca->lun = sc_link->lun;
|
|
|
|
break;
|
|
|
|
}
|
1998-02-01 04:13:13 +00:00
|
|
|
case SCIOCGETDEVINFO:
|
|
|
|
{
|
|
|
|
struct scsi_devinfo *scd = (struct scsi_devinfo *)addr;
|
|
|
|
struct scsi_link *scl;
|
1998-02-01 18:09:50 +00:00
|
|
|
scl = scsi_link_get(scd->addr.scbus, scd->addr.target,
|
1998-02-01 04:13:13 +00:00
|
|
|
scd->addr.lun);
|
|
|
|
if (scl != 0) {
|
|
|
|
scd->dev = scl->dev;
|
1998-02-01 18:09:50 +00:00
|
|
|
/* XXX buffers better be big enough... */
|
|
|
|
sprintf(scd->devname, "%s%d",
|
|
|
|
scl->device->name, scl->dev_unit);
|
|
|
|
sprintf(scd->adname, "%s%d:%d",
|
|
|
|
scl->adapter->name, scl->adapter_unit,
|
|
|
|
scl->adapter_bus);
|
1998-02-01 04:13:13 +00:00
|
|
|
ret = 0;
|
|
|
|
} else {
|
|
|
|
ret = ENXIO;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
1993-11-18 05:03:27 +00:00
|
|
|
|
|
|
|
default:
|
|
|
|
ret = ENOTTY;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
1993-11-25 01:38:01 +00:00
|
|
|
void
|
1993-11-18 05:03:27 +00:00
|
|
|
scsierr(bp,err)
|
1993-11-25 01:38:01 +00:00
|
|
|
struct buf *bp;
|
|
|
|
int err;
|
1993-11-18 05:03:27 +00:00
|
|
|
{
|
|
|
|
bp->b_flags |= B_ERROR;
|
|
|
|
bp->b_error = err;
|
|
|
|
biodone(bp);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|