2003-02-23 11:50:58 +03:00
|
|
|
/* $NetBSD: scsipi_ioctl.c,v 1.44 2003/02/23 08:50:59 yamt Exp $ */
|
1994-06-29 10:39:25 +04:00
|
|
|
|
1998-08-17 04:49:01 +04:00
|
|
|
/*-
|
|
|
|
* Copyright (c) 1998 The NetBSD Foundation, Inc.
|
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* This code is derived from software contributed to The NetBSD Foundation
|
|
|
|
* by Charles M. Hannum.
|
1994-03-29 08:29:20 +04: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:
|
1998-08-17 04:49:01 +04:00
|
|
|
* This product includes software developed by the NetBSD
|
|
|
|
* Foundation, Inc. and its contributors.
|
|
|
|
* 4. Neither the name of The NetBSD Foundation nor the names of its
|
|
|
|
* contributors may be used to endorse or promote products derived
|
|
|
|
* from this software without specific prior written permission.
|
1994-03-29 08:29:20 +04:00
|
|
|
*
|
1998-08-17 04:49:01 +04:00
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. 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 FOUNDATION 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.
|
1994-03-29 08:29:20 +04:00
|
|
|
*/
|
|
|
|
|
1997-10-01 05:18:38 +04:00
|
|
|
/*
|
1993-11-24 07:52:44 +03:00
|
|
|
* Contributed by HD Associates (hd@world.std.com).
|
|
|
|
* Copyright (c) 1992, 1993 HD Associates
|
|
|
|
*
|
1997-10-01 05:18:38 +04:00
|
|
|
* Berkeley style copyright.
|
1993-11-24 07:52:44 +03:00
|
|
|
*/
|
1993-11-24 12:45:04 +03:00
|
|
|
|
2001-11-13 09:54:32 +03:00
|
|
|
#include <sys/cdefs.h>
|
2003-02-23 11:50:58 +03:00
|
|
|
__KERNEL_RCSID(0, "$NetBSD: scsipi_ioctl.c,v 1.44 2003/02/23 08:50:59 yamt Exp $");
|
2001-11-13 09:54:32 +03:00
|
|
|
|
1998-06-26 02:49:18 +04:00
|
|
|
#include "opt_compat_freebsd.h"
|
1998-07-05 12:49:30 +04:00
|
|
|
#include "opt_compat_netbsd.h"
|
1998-06-26 02:49:18 +04:00
|
|
|
|
1993-11-24 07:52:44 +03:00
|
|
|
#include <sys/param.h>
|
2001-11-15 12:47:59 +03:00
|
|
|
#include <sys/errno.h>
|
1995-09-26 22:26:48 +03:00
|
|
|
#include <sys/systm.h>
|
1993-11-24 07:52:44 +03:00
|
|
|
#include <sys/malloc.h>
|
|
|
|
#include <sys/buf.h>
|
|
|
|
#include <sys/proc.h>
|
|
|
|
#include <sys/device.h>
|
1996-09-13 04:35:59 +04:00
|
|
|
#include <sys/fcntl.h>
|
1993-11-24 07:52:44 +03:00
|
|
|
|
1997-08-27 15:22:52 +04:00
|
|
|
#include <dev/scsipi/scsipi_all.h>
|
|
|
|
#include <dev/scsipi/scsipiconf.h>
|
2001-04-25 21:53:04 +04:00
|
|
|
#include <dev/scsipi/scsipi_base.h>
|
1997-08-27 15:22:52 +04:00
|
|
|
#include <dev/scsipi/scsiconf.h>
|
1993-11-24 07:52:44 +03:00
|
|
|
#include <sys/scsiio.h>
|
1997-10-01 05:18:38 +04:00
|
|
|
|
1997-08-27 15:22:52 +04:00
|
|
|
#include "scsibus.h"
|
|
|
|
#include "atapibus.h"
|
1993-11-24 07:52:44 +03:00
|
|
|
|
1994-03-29 08:29:20 +04:00
|
|
|
struct scsi_ioctl {
|
1994-12-01 14:53:56 +03:00
|
|
|
LIST_ENTRY(scsi_ioctl) si_list;
|
|
|
|
struct buf si_bp;
|
1994-10-20 23:31:23 +03:00
|
|
|
struct uio si_uio;
|
|
|
|
struct iovec si_iov;
|
1994-12-01 14:53:56 +03:00
|
|
|
scsireq_t si_screq;
|
2001-04-25 21:53:04 +04:00
|
|
|
struct scsipi_periph *si_periph;
|
1994-12-01 14:53:56 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
LIST_HEAD(, scsi_ioctl) si_head;
|
1994-03-29 08:29:20 +04:00
|
|
|
|
1997-10-01 05:18:38 +04:00
|
|
|
struct scsi_ioctl *si_find __P((struct buf *));
|
|
|
|
void si_free __P((struct scsi_ioctl *));
|
|
|
|
struct scsi_ioctl *si_get __P((void));
|
|
|
|
void scsistrategy __P((struct buf *));
|
1996-02-15 00:46:52 +03:00
|
|
|
|
1994-03-29 08:29:20 +04:00
|
|
|
struct scsi_ioctl *
|
1994-12-01 14:53:56 +03:00
|
|
|
si_get()
|
1994-03-29 08:29:20 +04:00
|
|
|
{
|
|
|
|
struct scsi_ioctl *si;
|
1994-12-01 14:53:56 +03:00
|
|
|
int s;
|
1994-03-29 08:29:20 +04:00
|
|
|
|
2002-01-12 19:29:30 +03:00
|
|
|
si = malloc(sizeof(struct scsi_ioctl), M_TEMP, M_WAITOK|M_ZERO);
|
2003-02-23 11:50:58 +03:00
|
|
|
simple_lock_init(&si->si_bp.b_interlock);
|
1994-12-01 14:53:56 +03:00
|
|
|
s = splbio();
|
|
|
|
LIST_INSERT_HEAD(&si_head, si, si_list);
|
|
|
|
splx(s);
|
|
|
|
return (si);
|
1994-03-29 08:29:20 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
si_free(si)
|
|
|
|
struct scsi_ioctl *si;
|
|
|
|
{
|
1994-12-01 14:53:56 +03:00
|
|
|
int s;
|
1994-03-29 08:29:20 +04:00
|
|
|
|
1994-12-01 14:53:56 +03:00
|
|
|
s = splbio();
|
|
|
|
LIST_REMOVE(si, si_list);
|
1994-03-29 08:29:20 +04:00
|
|
|
splx(s);
|
1994-12-01 14:53:56 +03:00
|
|
|
free(si, M_TEMP);
|
1994-03-29 08:29:20 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
struct scsi_ioctl *
|
|
|
|
si_find(bp)
|
|
|
|
struct buf *bp;
|
|
|
|
{
|
|
|
|
struct scsi_ioctl *si;
|
1994-12-01 14:53:56 +03:00
|
|
|
int s;
|
1994-03-29 08:29:20 +04:00
|
|
|
|
1994-12-01 14:53:56 +03:00
|
|
|
s = splbio();
|
|
|
|
for (si = si_head.lh_first; si != 0; si = si->si_list.le_next)
|
|
|
|
if (bp == &si->si_bp)
|
|
|
|
break;
|
1994-03-29 08:29:20 +04:00
|
|
|
splx(s);
|
1994-12-01 14:53:56 +03:00
|
|
|
return (si);
|
1994-03-29 08:29:20 +04:00
|
|
|
}
|
1993-11-24 07:52:44 +03:00
|
|
|
|
|
|
|
/*
|
|
|
|
* We let the user interpret his own sense in the generic scsi world.
|
1999-10-01 02:57:52 +04:00
|
|
|
* This routine is called at interrupt time if the XS_CTL_USERCMD bit was set
|
1997-08-27 15:22:52 +04:00
|
|
|
* in the flags passed to scsi_scsipi_cmd(). No other completion processing
|
1993-11-24 07:52:44 +03:00
|
|
|
* 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.
|
|
|
|
*/
|
1993-11-24 12:45:04 +03:00
|
|
|
void
|
1997-08-27 15:22:52 +04:00
|
|
|
scsipi_user_done(xs)
|
|
|
|
struct scsipi_xfer *xs;
|
1993-11-24 12:45:04 +03:00
|
|
|
{
|
|
|
|
struct buf *bp;
|
1994-03-29 08:29:20 +04:00
|
|
|
struct scsi_ioctl *si;
|
1994-12-01 15:12:08 +03:00
|
|
|
scsireq_t *screq;
|
2001-04-25 21:53:04 +04:00
|
|
|
struct scsipi_periph *periph = xs->xs_periph;
|
|
|
|
int s;
|
1993-11-24 07:52:44 +03:00
|
|
|
|
|
|
|
bp = xs->bp;
|
2001-04-25 21:53:04 +04:00
|
|
|
#ifdef DIAGNOSTIC
|
|
|
|
if (bp == NULL) {
|
|
|
|
scsipi_printaddr(periph);
|
|
|
|
printf("user command with no buf\n");
|
|
|
|
panic("scsipi_user_done");
|
1993-11-24 07:52:44 +03:00
|
|
|
}
|
2001-04-25 21:53:04 +04:00
|
|
|
#endif
|
1994-03-29 08:29:20 +04:00
|
|
|
si = si_find(bp);
|
2001-04-25 21:53:04 +04:00
|
|
|
#ifdef DIAGNOSTIC
|
1997-10-01 05:18:38 +04:00
|
|
|
if (si == NULL) {
|
2001-04-25 21:53:04 +04:00
|
|
|
scsipi_printaddr(periph);
|
|
|
|
printf("user command with no ioctl\n");
|
|
|
|
panic("scsipi_user_done");
|
1994-03-29 08:29:20 +04:00
|
|
|
}
|
2001-04-25 21:53:04 +04:00
|
|
|
#endif
|
|
|
|
|
1994-10-23 22:24:01 +03:00
|
|
|
screq = &si->si_screq;
|
2001-04-25 21:53:04 +04:00
|
|
|
|
|
|
|
SC_DEBUG(xs->xs_periph, SCSIPI_DB2, ("user-done\n"));
|
1994-12-01 15:12:08 +03:00
|
|
|
|
1993-11-24 07:52:44 +03:00
|
|
|
screq->retsts = 0;
|
|
|
|
screq->status = xs->status;
|
1994-10-23 22:24:01 +03:00
|
|
|
switch (xs->error) {
|
1993-11-24 12:45:04 +03:00
|
|
|
case XS_NOERROR:
|
2001-04-25 21:53:04 +04:00
|
|
|
SC_DEBUG(periph, SCSIPI_DB3, ("no error\n"));
|
1997-10-01 05:18:38 +04:00
|
|
|
screq->datalen_used =
|
|
|
|
xs->datalen - xs->resid; /* probably rubbish */
|
1993-11-24 07:52:44 +03:00
|
|
|
screq->retsts = SCCMD_OK;
|
|
|
|
break;
|
1993-11-24 12:45:04 +03:00
|
|
|
case XS_SENSE:
|
2001-04-25 21:53:04 +04:00
|
|
|
SC_DEBUG(periph, SCSIPI_DB3, ("have sense\n"));
|
1997-10-01 05:18:38 +04:00
|
|
|
screq->senselen_used = min(sizeof(xs->sense.scsi_sense),
|
|
|
|
SENSEBUFLEN);
|
2001-04-25 21:53:04 +04:00
|
|
|
memcpy(screq->sense, &xs->sense.scsi_sense, screq->senselen);
|
1993-11-24 07:52:44 +03:00
|
|
|
screq->retsts = SCCMD_SENSE;
|
|
|
|
break;
|
1998-11-17 17:38:42 +03:00
|
|
|
case XS_SHORTSENSE:
|
2001-04-25 21:53:04 +04:00
|
|
|
SC_DEBUG(periph, SCSIPI_DB3, ("have short sense\n"));
|
1998-11-17 17:38:42 +03:00
|
|
|
screq->senselen_used = min(sizeof(xs->sense.atapi_sense),
|
|
|
|
SENSEBUFLEN);
|
2001-07-18 22:25:41 +04:00
|
|
|
memcpy(screq->sense, &xs->sense.scsi_sense, screq->senselen);
|
1998-11-17 17:38:42 +03:00
|
|
|
screq->retsts = SCCMD_UNKNOWN; /* XXX need a shortsense here */
|
|
|
|
break;
|
1993-11-24 12:45:04 +03:00
|
|
|
case XS_DRIVER_STUFFUP:
|
2001-04-25 21:53:04 +04:00
|
|
|
scsipi_printaddr(periph);
|
|
|
|
printf("passthrough: adapter inconsistency\n");
|
1993-11-24 07:52:44 +03:00
|
|
|
screq->retsts = SCCMD_UNKNOWN;
|
|
|
|
break;
|
1999-01-12 01:07:08 +03:00
|
|
|
case XS_SELTIMEOUT:
|
2001-04-25 21:53:04 +04:00
|
|
|
SC_DEBUG(periph, SCSIPI_DB3, ("seltimeout\n"));
|
1999-01-12 01:07:08 +03:00
|
|
|
screq->retsts = SCCMD_TIMEOUT;
|
|
|
|
break;
|
1993-11-24 12:45:04 +03:00
|
|
|
case XS_TIMEOUT:
|
2001-04-25 21:53:04 +04:00
|
|
|
SC_DEBUG(periph, SCSIPI_DB3, ("timeout\n"));
|
1993-11-24 07:52:44 +03:00
|
|
|
screq->retsts = SCCMD_TIMEOUT;
|
|
|
|
break;
|
1993-11-24 12:45:04 +03:00
|
|
|
case XS_BUSY:
|
2001-04-25 21:53:04 +04:00
|
|
|
SC_DEBUG(periph, SCSIPI_DB3, ("busy\n"));
|
1993-11-24 07:52:44 +03:00
|
|
|
screq->retsts = SCCMD_BUSY;
|
|
|
|
break;
|
|
|
|
default:
|
2001-04-25 21:53:04 +04:00
|
|
|
scsipi_printaddr(periph);
|
|
|
|
printf("unknown error category %d from adapter\n",
|
1999-01-12 01:07:08 +03:00
|
|
|
xs->error);
|
1993-11-24 07:52:44 +03:00
|
|
|
screq->retsts = SCCMD_UNKNOWN;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
biodone(bp); /* we're waiting on it in scsi_strategy() */
|
2001-04-25 21:53:04 +04:00
|
|
|
|
|
|
|
if (xs->xs_control & XS_CTL_ASYNC) {
|
|
|
|
s = splbio();
|
|
|
|
scsipi_put_xs(xs);
|
|
|
|
splx(s);
|
|
|
|
}
|
1993-11-24 07:52:44 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* Pseudo strategy function
|
1997-08-27 15:22:52 +04:00
|
|
|
* Called by scsipi_do_ioctl() via physio/physstrat if there is to
|
1993-11-24 07:52:44 +03:00
|
|
|
* be data transfered, and directly if there is no data transfer.
|
1997-10-01 05:18:38 +04:00
|
|
|
*
|
1993-11-24 07:52:44 +03:00
|
|
|
* Should I reorganize this so it returns to physio instead
|
1997-08-27 15:22:52 +04:00
|
|
|
* of sleeping in scsiio_scsipi_cmd? Is there any advantage, other
|
1993-11-24 07:52:44 +03:00
|
|
|
* than avoiding the probable duplicate wakeup in iodone? [PD]
|
|
|
|
*
|
|
|
|
* No, seems ok to me... [JRE]
|
|
|
|
* (I don't see any duplicate wakeups)
|
|
|
|
*
|
|
|
|
* 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]
|
|
|
|
*/
|
1994-03-29 08:29:20 +04:00
|
|
|
void
|
|
|
|
scsistrategy(bp)
|
|
|
|
struct buf *bp;
|
1993-11-24 07:52:44 +03:00
|
|
|
{
|
1994-03-29 08:29:20 +04:00
|
|
|
struct scsi_ioctl *si;
|
1993-11-24 07:52:44 +03:00
|
|
|
scsireq_t *screq;
|
2001-04-25 21:53:04 +04:00
|
|
|
struct scsipi_periph *periph;
|
1994-12-01 15:12:08 +03:00
|
|
|
int error;
|
1994-04-11 07:53:58 +04:00
|
|
|
int flags = 0;
|
1993-11-24 07:52:44 +03:00
|
|
|
int s;
|
|
|
|
|
1994-03-29 08:29:20 +04:00
|
|
|
si = si_find(bp);
|
1997-10-01 05:18:38 +04:00
|
|
|
if (si == NULL) {
|
1996-10-13 03:23:13 +04:00
|
|
|
printf("user_strat: No ioctl\n");
|
1994-12-01 15:04:43 +03:00
|
|
|
error = EINVAL;
|
|
|
|
goto bad;
|
1994-03-29 08:29:20 +04:00
|
|
|
}
|
1994-10-23 22:24:01 +03:00
|
|
|
screq = &si->si_screq;
|
2001-04-25 21:53:04 +04:00
|
|
|
periph = si->si_periph;
|
|
|
|
SC_DEBUG(periph, SCSIPI_DB2, ("user_strategy\n"));
|
1993-11-24 07:52:44 +03:00
|
|
|
|
1994-03-29 08:29:20 +04:00
|
|
|
/*
|
|
|
|
* We're in trouble if physio tried to break up the transfer.
|
1993-11-24 07:52:44 +03:00
|
|
|
*/
|
|
|
|
if (bp->b_bcount != screq->datalen) {
|
2001-04-25 21:53:04 +04:00
|
|
|
scsipi_printaddr(periph);
|
1996-10-13 03:23:13 +04:00
|
|
|
printf("physio split the request.. cannot proceed\n");
|
1994-12-01 15:04:43 +03:00
|
|
|
error = EIO;
|
|
|
|
goto bad;
|
1993-11-24 07:52:44 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
if (screq->timeout == 0) {
|
1994-12-01 15:04:43 +03:00
|
|
|
error = EINVAL;
|
|
|
|
goto bad;
|
1993-11-24 07:52:44 +03:00
|
|
|
}
|
|
|
|
|
1997-08-27 15:22:52 +04:00
|
|
|
if (screq->cmdlen > sizeof(struct scsipi_generic)) {
|
2001-04-25 21:53:04 +04:00
|
|
|
scsipi_printaddr(periph);
|
1996-10-13 03:23:13 +04:00
|
|
|
printf("cmdlen too big\n");
|
1994-12-01 15:04:43 +03:00
|
|
|
error = EFAULT;
|
|
|
|
goto bad;
|
1993-11-24 07:52:44 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
if (screq->flags & SCCMD_READ)
|
1999-10-01 02:57:52 +04:00
|
|
|
flags |= XS_CTL_DATA_IN;
|
1993-11-24 07:52:44 +03:00
|
|
|
if (screq->flags & SCCMD_WRITE)
|
1999-10-01 02:57:52 +04:00
|
|
|
flags |= XS_CTL_DATA_OUT;
|
1993-11-24 07:52:44 +03:00
|
|
|
if (screq->flags & SCCMD_TARGET)
|
1999-10-01 02:57:52 +04:00
|
|
|
flags |= XS_CTL_TARGET;
|
1993-11-24 07:52:44 +03:00
|
|
|
if (screq->flags & SCCMD_ESCAPE)
|
1999-10-01 02:57:52 +04:00
|
|
|
flags |= XS_CTL_ESCAPE;
|
1993-11-24 12:45:04 +03:00
|
|
|
|
2001-04-25 21:53:04 +04:00
|
|
|
error = scsipi_command(periph,
|
1997-10-01 05:18:38 +04:00
|
|
|
(struct scsipi_generic *)screq->cmd, screq->cmdlen,
|
|
|
|
(u_char *)bp->b_data, screq->datalen,
|
1994-03-29 08:29:20 +04:00
|
|
|
0, /* user must do the retries *//* ignored */
|
1999-10-01 02:57:52 +04:00
|
|
|
screq->timeout, bp, flags | XS_CTL_USERCMD | XS_CTL_ASYNC);
|
1993-11-24 07:52:44 +03:00
|
|
|
|
1997-08-27 15:22:52 +04:00
|
|
|
/* because there is a bp, scsi_scsipi_cmd will return immediatly */
|
1994-12-01 15:04:43 +03:00
|
|
|
if (error)
|
|
|
|
goto bad;
|
|
|
|
|
2001-04-25 21:53:04 +04:00
|
|
|
SC_DEBUG(periph, SCSIPI_DB3, ("about to sleep\n"));
|
1993-11-24 07:52:44 +03:00
|
|
|
s = splbio();
|
1994-12-01 15:04:43 +03:00
|
|
|
while ((bp->b_flags & B_DONE) == 0)
|
1993-11-24 12:45:04 +03:00
|
|
|
tsleep(bp, PRIBIO, "scistr", 0);
|
1993-11-24 07:52:44 +03:00
|
|
|
splx(s);
|
2001-04-25 21:53:04 +04:00
|
|
|
SC_DEBUG(periph, SCSIPI_DB3, ("back from sleep\n"));
|
1994-12-01 15:04:43 +03:00
|
|
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
bad:
|
|
|
|
bp->b_flags |= B_ERROR;
|
|
|
|
bp->b_error = error;
|
|
|
|
biodone(bp);
|
1993-11-24 07:52:44 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Something (e.g. another driver) has called us
|
2001-04-25 21:53:04 +04:00
|
|
|
* with a periph 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
|
1993-11-24 07:52:44 +03:00
|
|
|
*/
|
1993-11-24 12:45:04 +03:00
|
|
|
int
|
2001-04-25 21:53:04 +04:00
|
|
|
scsipi_do_ioctl(periph, dev, cmd, addr, flag, p)
|
|
|
|
struct scsipi_periph *periph;
|
1994-10-20 23:31:23 +03:00
|
|
|
dev_t dev;
|
1994-10-31 00:43:03 +03:00
|
|
|
u_long cmd;
|
1994-03-29 08:29:20 +04:00
|
|
|
caddr_t addr;
|
1994-12-28 22:42:47 +03:00
|
|
|
int flag;
|
|
|
|
struct proc *p;
|
1993-11-24 07:52:44 +03:00
|
|
|
{
|
1994-03-29 08:29:20 +04:00
|
|
|
int error;
|
1993-11-24 07:52:44 +03:00
|
|
|
|
2001-04-25 21:53:04 +04:00
|
|
|
SC_DEBUG(periph, SCSIPI_DB2, ("scsipi_do_ioctl(0x%lx)\n", cmd));
|
1994-12-01 14:53:56 +03:00
|
|
|
|
1996-09-13 04:35:59 +04:00
|
|
|
/* Check for the safe-ness of this request. */
|
|
|
|
switch (cmd) {
|
1998-06-15 12:16:01 +04:00
|
|
|
case OSCIOCIDENTIFY:
|
1996-09-13 04:35:59 +04:00
|
|
|
case SCIOCIDENTIFY:
|
|
|
|
break;
|
1997-04-27 02:24:46 +04:00
|
|
|
case SCIOCCOMMAND:
|
|
|
|
if ((((scsireq_t *)addr)->flags & SCCMD_READ) == 0 &&
|
|
|
|
(flag & FWRITE) == 0)
|
1997-10-01 05:18:38 +04:00
|
|
|
return (EBADF);
|
1997-04-27 02:24:46 +04:00
|
|
|
break;
|
1996-09-13 04:35:59 +04:00
|
|
|
default:
|
|
|
|
if ((flag & FWRITE) == 0)
|
1997-10-01 05:18:38 +04:00
|
|
|
return (EBADF);
|
1996-09-13 04:35:59 +04:00
|
|
|
}
|
|
|
|
|
1997-10-01 05:18:38 +04:00
|
|
|
switch (cmd) {
|
1994-03-29 08:29:20 +04:00
|
|
|
case SCIOCCOMMAND: {
|
|
|
|
scsireq_t *screq = (scsireq_t *)addr;
|
1994-10-20 23:31:23 +03:00
|
|
|
struct scsi_ioctl *si;
|
1994-03-29 08:29:20 +04:00
|
|
|
int len;
|
|
|
|
|
1994-12-01 14:53:56 +03:00
|
|
|
si = si_get();
|
1994-10-23 22:24:01 +03:00
|
|
|
si->si_screq = *screq;
|
2001-04-25 21:53:04 +04:00
|
|
|
si->si_periph = periph;
|
1994-12-28 22:42:47 +03:00
|
|
|
len = screq->datalen;
|
1994-03-29 08:29:20 +04:00
|
|
|
if (len) {
|
1994-12-01 14:53:56 +03:00
|
|
|
si->si_iov.iov_base = screq->databuf;
|
1994-10-20 23:31:23 +03:00
|
|
|
si->si_iov.iov_len = len;
|
|
|
|
si->si_uio.uio_iov = &si->si_iov;
|
|
|
|
si->si_uio.uio_iovcnt = 1;
|
1994-12-01 15:36:35 +03:00
|
|
|
si->si_uio.uio_resid = len;
|
1994-10-20 23:31:23 +03:00
|
|
|
si->si_uio.uio_offset = 0;
|
|
|
|
si->si_uio.uio_segflg = UIO_USERSPACE;
|
1997-10-01 05:18:38 +04:00
|
|
|
si->si_uio.uio_rw =
|
1994-10-20 23:31:23 +03:00
|
|
|
(screq->flags & SCCMD_READ) ? UIO_READ : UIO_WRITE;
|
1994-12-28 22:42:47 +03:00
|
|
|
si->si_uio.uio_procp = p;
|
1994-12-01 14:53:56 +03:00
|
|
|
error = physio(scsistrategy, &si->si_bp, dev,
|
1994-10-20 23:31:23 +03:00
|
|
|
(screq->flags & SCCMD_READ) ? B_READ : B_WRITE,
|
2001-04-25 21:53:04 +04:00
|
|
|
periph->periph_channel->chan_adapter->adapt_minphys,
|
|
|
|
&si->si_uio);
|
1994-03-29 08:29:20 +04:00
|
|
|
} else {
|
|
|
|
/* if no data, no need to translate it.. */
|
1994-12-28 22:42:47 +03:00
|
|
|
si->si_bp.b_flags = 0;
|
1994-12-01 14:53:56 +03:00
|
|
|
si->si_bp.b_data = 0;
|
1994-12-28 22:42:47 +03:00
|
|
|
si->si_bp.b_bcount = 0;
|
1994-12-01 15:26:37 +03:00
|
|
|
si->si_bp.b_dev = dev;
|
1994-12-28 22:42:47 +03:00
|
|
|
si->si_bp.b_proc = p;
|
1994-12-01 14:53:56 +03:00
|
|
|
scsistrategy(&si->si_bp);
|
|
|
|
error = si->si_bp.b_error;
|
1993-11-24 07:52:44 +03:00
|
|
|
}
|
1994-12-28 22:42:47 +03:00
|
|
|
*screq = si->si_screq;
|
1994-12-01 14:53:56 +03:00
|
|
|
si_free(si);
|
1997-10-01 05:18:38 +04:00
|
|
|
return (error);
|
1994-03-29 08:29:20 +04:00
|
|
|
}
|
|
|
|
case SCIOCDEBUG: {
|
|
|
|
int level = *((int *)addr);
|
|
|
|
|
2001-04-25 21:53:04 +04:00
|
|
|
SC_DEBUG(periph, SCSIPI_DB3, ("debug set to %d\n", level));
|
|
|
|
periph->periph_dbflags = 0;
|
1994-03-29 08:29:20 +04:00
|
|
|
if (level & 1)
|
2001-04-25 21:53:04 +04:00
|
|
|
periph->periph_dbflags |= SCSIPI_DB1;
|
1994-03-29 08:29:20 +04:00
|
|
|
if (level & 2)
|
2001-04-25 21:53:04 +04:00
|
|
|
periph->periph_dbflags |= SCSIPI_DB2;
|
1994-03-29 08:29:20 +04:00
|
|
|
if (level & 4)
|
2001-04-25 21:53:04 +04:00
|
|
|
periph->periph_dbflags |= SCSIPI_DB3;
|
1994-03-29 08:29:20 +04:00
|
|
|
if (level & 8)
|
2001-04-25 21:53:04 +04:00
|
|
|
periph->periph_dbflags |= SCSIPI_DB4;
|
1997-10-01 05:18:38 +04:00
|
|
|
return (0);
|
1994-03-29 08:29:20 +04:00
|
|
|
}
|
|
|
|
case SCIOCRECONFIG:
|
|
|
|
case SCIOCDECONFIG:
|
1997-10-01 05:18:38 +04:00
|
|
|
return (EINVAL);
|
1994-03-29 08:29:20 +04:00
|
|
|
case SCIOCIDENTIFY: {
|
|
|
|
struct scsi_addr *sca = (struct scsi_addr *)addr;
|
1997-10-01 05:18:38 +04:00
|
|
|
|
2001-04-25 21:53:04 +04:00
|
|
|
switch (scsipi_periph_bustype(periph)) {
|
|
|
|
case SCSIPI_BUSTYPE_SCSI:
|
1997-08-27 15:22:52 +04:00
|
|
|
sca->type = TYPE_SCSI;
|
2001-04-25 21:53:04 +04:00
|
|
|
sca->addr.scsi.scbus =
|
|
|
|
periph->periph_dev->dv_parent->dv_unit;
|
|
|
|
sca->addr.scsi.target = periph->periph_target;
|
|
|
|
sca->addr.scsi.lun = periph->periph_lun;
|
1997-10-01 05:18:38 +04:00
|
|
|
return (0);
|
2001-04-25 21:53:04 +04:00
|
|
|
case SCSIPI_BUSTYPE_ATAPI:
|
1997-08-27 15:22:52 +04:00
|
|
|
sca->type = TYPE_ATAPI;
|
2001-04-25 21:53:04 +04:00
|
|
|
sca->addr.atapi.atbus =
|
|
|
|
periph->periph_dev->dv_parent->dv_unit;
|
|
|
|
sca->addr.atapi.drive = periph->periph_target;
|
1997-10-01 05:18:38 +04:00
|
|
|
return (0);
|
1997-08-27 15:22:52 +04:00
|
|
|
}
|
1997-10-01 05:18:38 +04:00
|
|
|
return (ENXIO);
|
1994-03-29 08:29:20 +04:00
|
|
|
}
|
1997-09-19 04:59:49 +04:00
|
|
|
#if defined(COMPAT_12) || defined(COMPAT_FREEBSD)
|
|
|
|
/* SCIOCIDENTIFY before ATAPI staff merge */
|
|
|
|
case OSCIOCIDENTIFY: {
|
|
|
|
struct oscsi_addr *sca = (struct oscsi_addr *)addr;
|
|
|
|
|
2001-04-25 21:53:04 +04:00
|
|
|
switch (scsipi_periph_bustype(periph)) {
|
|
|
|
case SCSIPI_BUSTYPE_SCSI:
|
|
|
|
sca->scbus = periph->periph_dev->dv_parent->dv_unit;
|
|
|
|
sca->target = periph->periph_target;
|
|
|
|
sca->lun = periph->periph_lun;
|
1997-10-01 05:18:38 +04:00
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
return (ENODEV);
|
1997-09-19 04:59:49 +04:00
|
|
|
}
|
|
|
|
#endif
|
1994-03-29 08:29:20 +04:00
|
|
|
default:
|
1997-10-01 05:18:38 +04:00
|
|
|
return (ENOTTY);
|
1993-11-24 07:52:44 +03:00
|
|
|
}
|
|
|
|
|
1994-03-29 08:29:20 +04:00
|
|
|
#ifdef DIAGNOSTIC
|
1997-08-27 15:22:52 +04:00
|
|
|
panic("scsipi_do_ioctl: impossible");
|
1994-03-29 08:29:20 +04:00
|
|
|
#endif
|
1993-11-24 07:52:44 +03:00
|
|
|
}
|