Home | History | Annotate | Line # | Download | only in scsipi
scsipi_ioctl.c revision 1.63.22.2
      1  1.63.22.2  ad /*	$NetBSD: scsipi_ioctl.c,v 1.63.22.2 2007/07/29 12:50:24 ad Exp $	*/
      2  1.63.22.2  ad 
      3  1.63.22.2  ad /*-
      4  1.63.22.2  ad  * Copyright (c) 1998, 2004 The NetBSD Foundation, Inc.
      5  1.63.22.2  ad  * All rights reserved.
      6  1.63.22.2  ad  *
      7  1.63.22.2  ad  * This code is derived from software contributed to The NetBSD Foundation
      8  1.63.22.2  ad  * by Charles M. Hannum.
      9  1.63.22.2  ad  *
     10  1.63.22.2  ad  * Redistribution and use in source and binary forms, with or without
     11  1.63.22.2  ad  * modification, are permitted provided that the following conditions
     12  1.63.22.2  ad  * are met:
     13  1.63.22.2  ad  * 1. Redistributions of source code must retain the above copyright
     14  1.63.22.2  ad  *    notice, this list of conditions and the following disclaimer.
     15  1.63.22.2  ad  * 2. Redistributions in binary form must reproduce the above copyright
     16  1.63.22.2  ad  *    notice, this list of conditions and the following disclaimer in the
     17  1.63.22.2  ad  *    documentation and/or other materials provided with the distribution.
     18  1.63.22.2  ad  * 3. All advertising materials mentioning features or use of this software
     19  1.63.22.2  ad  *    must display the following acknowledgement:
     20  1.63.22.2  ad  *        This product includes software developed by the NetBSD
     21  1.63.22.2  ad  *        Foundation, Inc. and its contributors.
     22  1.63.22.2  ad  * 4. Neither the name of The NetBSD Foundation nor the names of its
     23  1.63.22.2  ad  *    contributors may be used to endorse or promote products derived
     24  1.63.22.2  ad  *    from this software without specific prior written permission.
     25  1.63.22.2  ad  *
     26  1.63.22.2  ad  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
     27  1.63.22.2  ad  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     28  1.63.22.2  ad  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     29  1.63.22.2  ad  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
     30  1.63.22.2  ad  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     31  1.63.22.2  ad  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     32  1.63.22.2  ad  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     33  1.63.22.2  ad  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     34  1.63.22.2  ad  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     35  1.63.22.2  ad  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     36  1.63.22.2  ad  * POSSIBILITY OF SUCH DAMAGE.
     37  1.63.22.2  ad  */
     38  1.63.22.2  ad 
     39  1.63.22.2  ad /*
     40  1.63.22.2  ad  * Contributed by HD Associates (hd (at) world.std.com).
     41  1.63.22.2  ad  * Copyright (c) 1992, 1993 HD Associates
     42  1.63.22.2  ad  *
     43  1.63.22.2  ad  * Berkeley style copyright.
     44  1.63.22.2  ad  */
     45  1.63.22.2  ad 
     46  1.63.22.2  ad #include <sys/cdefs.h>
     47  1.63.22.2  ad __KERNEL_RCSID(0, "$NetBSD: scsipi_ioctl.c,v 1.63.22.2 2007/07/29 12:50:24 ad Exp $");
     48  1.63.22.2  ad 
     49  1.63.22.2  ad #include "opt_compat_freebsd.h"
     50  1.63.22.2  ad #include "opt_compat_netbsd.h"
     51  1.63.22.2  ad 
     52  1.63.22.2  ad #include <sys/param.h>
     53  1.63.22.2  ad #include <sys/errno.h>
     54  1.63.22.2  ad #include <sys/systm.h>
     55  1.63.22.2  ad #include <sys/malloc.h>
     56  1.63.22.2  ad #include <sys/buf.h>
     57  1.63.22.2  ad #include <sys/proc.h>
     58  1.63.22.2  ad #include <sys/device.h>
     59  1.63.22.2  ad #include <sys/fcntl.h>
     60  1.63.22.2  ad 
     61  1.63.22.2  ad #include <dev/scsipi/scsipi_all.h>
     62  1.63.22.2  ad #include <dev/scsipi/scsipiconf.h>
     63  1.63.22.2  ad #include <dev/scsipi/scsipi_base.h>
     64  1.63.22.2  ad #include <dev/scsipi/scsiconf.h>
     65  1.63.22.2  ad #include <sys/scsiio.h>
     66  1.63.22.2  ad 
     67  1.63.22.2  ad #include "scsibus.h"
     68  1.63.22.2  ad #include "atapibus.h"
     69  1.63.22.2  ad 
     70  1.63.22.2  ad struct scsi_ioctl {
     71  1.63.22.2  ad 	LIST_ENTRY(scsi_ioctl) si_list;
     72  1.63.22.2  ad 	struct buf si_bp;
     73  1.63.22.2  ad 	struct uio si_uio;
     74  1.63.22.2  ad 	struct iovec si_iov;
     75  1.63.22.2  ad 	scsireq_t si_screq;
     76  1.63.22.2  ad 	struct scsipi_periph *si_periph;
     77  1.63.22.2  ad };
     78  1.63.22.2  ad 
     79  1.63.22.2  ad static LIST_HEAD(, scsi_ioctl) si_head;
     80  1.63.22.2  ad 
     81  1.63.22.2  ad static struct scsi_ioctl *
     82  1.63.22.2  ad si_get(void)
     83  1.63.22.2  ad {
     84  1.63.22.2  ad 	struct scsi_ioctl *si;
     85  1.63.22.2  ad 	int s;
     86  1.63.22.2  ad 
     87  1.63.22.2  ad 	si = malloc(sizeof(struct scsi_ioctl), M_TEMP, M_WAITOK|M_ZERO);
     88  1.63.22.2  ad 	simple_lock_init(&si->si_bp.b_interlock);
     89  1.63.22.2  ad 	s = splbio();
     90  1.63.22.2  ad 	LIST_INSERT_HEAD(&si_head, si, si_list);
     91  1.63.22.2  ad 	splx(s);
     92  1.63.22.2  ad 	return (si);
     93  1.63.22.2  ad }
     94  1.63.22.2  ad 
     95  1.63.22.2  ad static void
     96  1.63.22.2  ad si_free(struct scsi_ioctl *si)
     97  1.63.22.2  ad {
     98  1.63.22.2  ad 	int s;
     99  1.63.22.2  ad 
    100  1.63.22.2  ad 	s = splbio();
    101  1.63.22.2  ad 	LIST_REMOVE(si, si_list);
    102  1.63.22.2  ad 	splx(s);
    103  1.63.22.2  ad 	free(si, M_TEMP);
    104  1.63.22.2  ad }
    105  1.63.22.2  ad 
    106  1.63.22.2  ad static struct scsi_ioctl *
    107  1.63.22.2  ad si_find(struct buf *bp)
    108  1.63.22.2  ad {
    109  1.63.22.2  ad 	struct scsi_ioctl *si;
    110  1.63.22.2  ad 	int s;
    111  1.63.22.2  ad 
    112  1.63.22.2  ad 	s = splbio();
    113  1.63.22.2  ad 	for (si = si_head.lh_first; si != 0; si = si->si_list.le_next)
    114  1.63.22.2  ad 		if (bp == &si->si_bp)
    115  1.63.22.2  ad 			break;
    116  1.63.22.2  ad 	splx(s);
    117  1.63.22.2  ad 	return (si);
    118  1.63.22.2  ad }
    119  1.63.22.2  ad 
    120  1.63.22.2  ad /*
    121  1.63.22.2  ad  * We let the user interpret his own sense in the generic scsi world.
    122  1.63.22.2  ad  * This routine is called at interrupt time if the XS_CTL_USERCMD bit was set
    123  1.63.22.2  ad  * in the flags passed to scsi_scsipi_cmd(). No other completion processing
    124  1.63.22.2  ad  * takes place, even if we are running over another device driver.
    125  1.63.22.2  ad  * The lower level routines that call us here, will free the xs and restart
    126  1.63.22.2  ad  * the device's queue if such exists.
    127  1.63.22.2  ad  */
    128  1.63.22.2  ad void
    129  1.63.22.2  ad scsipi_user_done(struct scsipi_xfer *xs)
    130  1.63.22.2  ad {
    131  1.63.22.2  ad 	struct buf *bp;
    132  1.63.22.2  ad 	struct scsi_ioctl *si;
    133  1.63.22.2  ad 	scsireq_t *screq;
    134  1.63.22.2  ad 	struct scsipi_periph *periph = xs->xs_periph;
    135  1.63.22.2  ad 	int s;
    136  1.63.22.2  ad 
    137  1.63.22.2  ad 	bp = xs->bp;
    138  1.63.22.2  ad #ifdef DIAGNOSTIC
    139  1.63.22.2  ad 	if (bp == NULL) {
    140  1.63.22.2  ad 		scsipi_printaddr(periph);
    141  1.63.22.2  ad 		printf("user command with no buf\n");
    142  1.63.22.2  ad 		panic("scsipi_user_done");
    143  1.63.22.2  ad 	}
    144  1.63.22.2  ad #endif
    145  1.63.22.2  ad 	si = si_find(bp);
    146  1.63.22.2  ad #ifdef DIAGNOSTIC
    147  1.63.22.2  ad 	if (si == NULL) {
    148  1.63.22.2  ad 		scsipi_printaddr(periph);
    149  1.63.22.2  ad 		printf("user command with no ioctl\n");
    150  1.63.22.2  ad 		panic("scsipi_user_done");
    151  1.63.22.2  ad 	}
    152  1.63.22.2  ad #endif
    153  1.63.22.2  ad 
    154  1.63.22.2  ad 	screq = &si->si_screq;
    155  1.63.22.2  ad 
    156  1.63.22.2  ad 	SC_DEBUG(xs->xs_periph, SCSIPI_DB2, ("user-done\n"));
    157  1.63.22.2  ad 
    158  1.63.22.2  ad 	screq->retsts = 0;
    159  1.63.22.2  ad 	screq->status = xs->status;
    160  1.63.22.2  ad 	switch (xs->error) {
    161  1.63.22.2  ad 	case XS_NOERROR:
    162  1.63.22.2  ad 		SC_DEBUG(periph, SCSIPI_DB3, ("no error\n"));
    163  1.63.22.2  ad 		screq->datalen_used =
    164  1.63.22.2  ad 		    xs->datalen - xs->resid;	/* probably rubbish */
    165  1.63.22.2  ad 		screq->retsts = SCCMD_OK;
    166  1.63.22.2  ad 		break;
    167  1.63.22.2  ad 	case XS_SENSE:
    168  1.63.22.2  ad 		SC_DEBUG(periph, SCSIPI_DB3, ("have sense\n"));
    169  1.63.22.2  ad 		screq->senselen_used = min(sizeof(xs->sense.scsi_sense),
    170  1.63.22.2  ad 		    SENSEBUFLEN);
    171  1.63.22.2  ad 		memcpy(screq->sense, &xs->sense.scsi_sense, screq->senselen);
    172  1.63.22.2  ad 		screq->retsts = SCCMD_SENSE;
    173  1.63.22.2  ad 		break;
    174  1.63.22.2  ad 	case XS_SHORTSENSE:
    175  1.63.22.2  ad 		SC_DEBUG(periph, SCSIPI_DB3, ("have short sense\n"));
    176  1.63.22.2  ad 		screq->senselen_used = min(sizeof(xs->sense.atapi_sense),
    177  1.63.22.2  ad 		    SENSEBUFLEN);
    178  1.63.22.2  ad 		memcpy(screq->sense, &xs->sense.scsi_sense, screq->senselen);
    179  1.63.22.2  ad 		screq->retsts = SCCMD_UNKNOWN; /* XXX need a shortsense here */
    180  1.63.22.2  ad 		break;
    181  1.63.22.2  ad 	case XS_DRIVER_STUFFUP:
    182  1.63.22.2  ad 		scsipi_printaddr(periph);
    183  1.63.22.2  ad 		printf("passthrough: adapter inconsistency\n");
    184  1.63.22.2  ad 		screq->retsts = SCCMD_UNKNOWN;
    185  1.63.22.2  ad 		break;
    186  1.63.22.2  ad 	case XS_SELTIMEOUT:
    187  1.63.22.2  ad 		SC_DEBUG(periph, SCSIPI_DB3, ("seltimeout\n"));
    188  1.63.22.2  ad 		screq->retsts = SCCMD_TIMEOUT;
    189  1.63.22.2  ad 		break;
    190  1.63.22.2  ad 	case XS_TIMEOUT:
    191  1.63.22.2  ad 		SC_DEBUG(periph, SCSIPI_DB3, ("timeout\n"));
    192  1.63.22.2  ad 		screq->retsts = SCCMD_TIMEOUT;
    193  1.63.22.2  ad 		break;
    194  1.63.22.2  ad 	case XS_BUSY:
    195  1.63.22.2  ad 		SC_DEBUG(periph, SCSIPI_DB3, ("busy\n"));
    196  1.63.22.2  ad 		screq->retsts = SCCMD_BUSY;
    197  1.63.22.2  ad 		break;
    198  1.63.22.2  ad 	default:
    199  1.63.22.2  ad 		scsipi_printaddr(periph);
    200  1.63.22.2  ad 		printf("unknown error category %d from adapter\n",
    201  1.63.22.2  ad 		    xs->error);
    202  1.63.22.2  ad 		screq->retsts = SCCMD_UNKNOWN;
    203  1.63.22.2  ad 		break;
    204  1.63.22.2  ad 	}
    205  1.63.22.2  ad 
    206  1.63.22.2  ad 	if (xs->xs_control & XS_CTL_ASYNC) {
    207  1.63.22.2  ad 		s = splbio();
    208  1.63.22.2  ad 		scsipi_put_xs(xs);
    209  1.63.22.2  ad 		splx(s);
    210  1.63.22.2  ad 	}
    211  1.63.22.2  ad }
    212  1.63.22.2  ad 
    213  1.63.22.2  ad 
    214  1.63.22.2  ad /* Pseudo strategy function
    215  1.63.22.2  ad  * Called by scsipi_do_ioctl() via physio/physstrat if there is to
    216  1.63.22.2  ad  * be data transfered, and directly if there is no data transfer.
    217  1.63.22.2  ad  *
    218  1.63.22.2  ad  * Should I reorganize this so it returns to physio instead
    219  1.63.22.2  ad  * of sleeping in scsiio_scsipi_cmd?  Is there any advantage, other
    220  1.63.22.2  ad  * than avoiding the probable duplicate wakeup in iodone? [PD]
    221  1.63.22.2  ad  *
    222  1.63.22.2  ad  * No, seems ok to me... [JRE]
    223  1.63.22.2  ad  * (I don't see any duplicate wakeups)
    224  1.63.22.2  ad  *
    225  1.63.22.2  ad  * Can't be used with block devices or raw_read/raw_write directly
    226  1.63.22.2  ad  * from the cdevsw/bdevsw tables because they couldn't have added
    227  1.63.22.2  ad  * the screq structure. [JRE]
    228  1.63.22.2  ad  */
    229  1.63.22.2  ad static void
    230  1.63.22.2  ad scsistrategy(struct buf *bp)
    231  1.63.22.2  ad {
    232  1.63.22.2  ad 	struct scsi_ioctl *si;
    233  1.63.22.2  ad 	scsireq_t *screq;
    234  1.63.22.2  ad 	struct scsipi_periph *periph;
    235  1.63.22.2  ad 	int error;
    236  1.63.22.2  ad 	int flags = 0;
    237  1.63.22.2  ad 
    238  1.63.22.2  ad 	si = si_find(bp);
    239  1.63.22.2  ad 	if (si == NULL) {
    240  1.63.22.2  ad 		printf("scsistrategy: "
    241  1.63.22.2  ad 		    "No matching ioctl request found in queue\n");
    242  1.63.22.2  ad 		error = EINVAL;
    243  1.63.22.2  ad 		goto done;
    244  1.63.22.2  ad 	}
    245  1.63.22.2  ad 	screq = &si->si_screq;
    246  1.63.22.2  ad 	periph = si->si_periph;
    247  1.63.22.2  ad 	SC_DEBUG(periph, SCSIPI_DB2, ("user_strategy\n"));
    248  1.63.22.2  ad 
    249  1.63.22.2  ad 	/*
    250  1.63.22.2  ad 	 * We're in trouble if physio tried to break up the transfer.
    251  1.63.22.2  ad 	 */
    252  1.63.22.2  ad 	if (bp->b_bcount != screq->datalen) {
    253  1.63.22.2  ad 		scsipi_printaddr(periph);
    254  1.63.22.2  ad 		printf("physio split the request.. cannot proceed\n");
    255  1.63.22.2  ad 		error = EIO;
    256  1.63.22.2  ad 		goto done;
    257  1.63.22.2  ad 	}
    258  1.63.22.2  ad 
    259  1.63.22.2  ad 	if (screq->timeout == 0) {
    260  1.63.22.2  ad 		error = EINVAL;
    261  1.63.22.2  ad 		goto done;
    262  1.63.22.2  ad 	}
    263  1.63.22.2  ad 
    264  1.63.22.2  ad 	if (screq->cmdlen > sizeof(struct scsipi_generic)) {
    265  1.63.22.2  ad 		scsipi_printaddr(periph);
    266  1.63.22.2  ad 		printf("cmdlen too big\n");
    267  1.63.22.2  ad 		error = EFAULT;
    268  1.63.22.2  ad 		goto done;
    269  1.63.22.2  ad 	}
    270  1.63.22.2  ad 
    271  1.63.22.2  ad 	if ((screq->flags & SCCMD_READ) && screq->datalen > 0)
    272  1.63.22.2  ad 		flags |= XS_CTL_DATA_IN;
    273  1.63.22.2  ad 	if ((screq->flags & SCCMD_WRITE) && screq->datalen > 0)
    274  1.63.22.2  ad 		flags |= XS_CTL_DATA_OUT;
    275  1.63.22.2  ad 	if (screq->flags & SCCMD_TARGET)
    276  1.63.22.2  ad 		flags |= XS_CTL_TARGET;
    277  1.63.22.2  ad 	if (screq->flags & SCCMD_ESCAPE)
    278  1.63.22.2  ad 		flags |= XS_CTL_ESCAPE;
    279  1.63.22.2  ad 
    280  1.63.22.2  ad 	error = scsipi_command(periph, (void *)screq->cmd, screq->cmdlen,
    281  1.63.22.2  ad 	    (void *)bp->b_data, screq->datalen,
    282  1.63.22.2  ad 	    0, /* user must do the retries *//* ignored */
    283  1.63.22.2  ad 	    screq->timeout, bp, flags | XS_CTL_USERCMD);
    284  1.63.22.2  ad 
    285  1.63.22.2  ad done:
    286  1.63.22.2  ad 	bp->b_error = error;
    287  1.63.22.2  ad 	biodone(bp);
    288  1.63.22.2  ad 	return;
    289  1.63.22.2  ad }
    290  1.63.22.2  ad 
    291  1.63.22.2  ad /*
    292  1.63.22.2  ad  * Something (e.g. another driver) has called us
    293  1.63.22.2  ad  * with a periph and a scsi-specific ioctl to perform,
    294  1.63.22.2  ad  * better try.  If user-level type command, we must
    295  1.63.22.2  ad  * still be running in the context of the calling process
    296  1.63.22.2  ad  */
    297  1.63.22.2  ad int
    298  1.63.22.2  ad scsipi_do_ioctl(struct scsipi_periph *periph, dev_t dev, u_long cmd,
    299  1.63.22.2  ad     void *addr, int flag, struct lwp *l)
    300  1.63.22.2  ad {
    301  1.63.22.2  ad 	int error;
    302  1.63.22.2  ad 
    303  1.63.22.2  ad 	SC_DEBUG(periph, SCSIPI_DB2, ("scsipi_do_ioctl(0x%lx)\n", cmd));
    304  1.63.22.2  ad 
    305  1.63.22.2  ad 	if (addr == NULL)
    306  1.63.22.2  ad 		return EINVAL;
    307  1.63.22.2  ad 
    308  1.63.22.2  ad 	/* Check for the safe-ness of this request. */
    309  1.63.22.2  ad 	switch (cmd) {
    310  1.63.22.2  ad 	case OSCIOCIDENTIFY:
    311  1.63.22.2  ad 	case SCIOCIDENTIFY:
    312  1.63.22.2  ad 		break;
    313  1.63.22.2  ad 	case SCIOCCOMMAND:
    314  1.63.22.2  ad 		if ((((scsireq_t *)addr)->flags & SCCMD_READ) == 0 &&
    315  1.63.22.2  ad 		    (flag & FWRITE) == 0)
    316  1.63.22.2  ad 			return (EBADF);
    317  1.63.22.2  ad 		break;
    318  1.63.22.2  ad 	default:
    319  1.63.22.2  ad 		if ((flag & FWRITE) == 0)
    320  1.63.22.2  ad 			return (EBADF);
    321  1.63.22.2  ad 	}
    322  1.63.22.2  ad 
    323  1.63.22.2  ad 	switch (cmd) {
    324  1.63.22.2  ad 	case SCIOCCOMMAND: {
    325  1.63.22.2  ad 		scsireq_t *screq = (scsireq_t *)addr;
    326  1.63.22.2  ad 		struct scsi_ioctl *si;
    327  1.63.22.2  ad 		int len;
    328  1.63.22.2  ad 
    329  1.63.22.2  ad 		si = si_get();
    330  1.63.22.2  ad 		si->si_screq = *screq;
    331  1.63.22.2  ad 		si->si_periph = periph;
    332  1.63.22.2  ad 		len = screq->datalen;
    333  1.63.22.2  ad 		if (len) {
    334  1.63.22.2  ad 			si->si_iov.iov_base = screq->databuf;
    335  1.63.22.2  ad 			si->si_iov.iov_len = len;
    336  1.63.22.2  ad 			si->si_uio.uio_iov = &si->si_iov;
    337  1.63.22.2  ad 			si->si_uio.uio_iovcnt = 1;
    338  1.63.22.2  ad 			si->si_uio.uio_resid = len;
    339  1.63.22.2  ad 			si->si_uio.uio_offset = 0;
    340  1.63.22.2  ad 			si->si_uio.uio_rw =
    341  1.63.22.2  ad 			    (screq->flags & SCCMD_READ) ? UIO_READ : UIO_WRITE;
    342  1.63.22.2  ad 			if ((flag & FKIOCTL) == 0) {
    343  1.63.22.2  ad 				si->si_uio.uio_vmspace = l->l_proc->p_vmspace;
    344  1.63.22.2  ad 			} else {
    345  1.63.22.2  ad 				UIO_SETUP_SYSSPACE(&si->si_uio);
    346  1.63.22.2  ad 			}
    347  1.63.22.2  ad 			error = physio(scsistrategy, &si->si_bp, dev,
    348  1.63.22.2  ad 			    (screq->flags & SCCMD_READ) ? B_READ : B_WRITE,
    349  1.63.22.2  ad 			    periph->periph_channel->chan_adapter->adapt_minphys,
    350  1.63.22.2  ad 			    &si->si_uio);
    351  1.63.22.2  ad 		} else {
    352  1.63.22.2  ad 			/* if no data, no need to translate it.. */
    353  1.63.22.2  ad 			si->si_bp.b_flags = 0;
    354  1.63.22.2  ad 			si->si_bp.b_data = 0;
    355  1.63.22.2  ad 			si->si_bp.b_bcount = 0;
    356  1.63.22.2  ad 			si->si_bp.b_dev = dev;
    357  1.63.22.2  ad 			si->si_bp.b_proc = l->l_proc;
    358  1.63.22.2  ad 			scsistrategy(&si->si_bp);
    359  1.63.22.2  ad 			error = si->si_bp.b_error;
    360  1.63.22.2  ad 		}
    361  1.63.22.2  ad 		*screq = si->si_screq;
    362  1.63.22.2  ad 		si_free(si);
    363  1.63.22.2  ad 		return (error);
    364  1.63.22.2  ad 	}
    365  1.63.22.2  ad 	case SCIOCDEBUG: {
    366  1.63.22.2  ad 		int level = *((int *)addr);
    367  1.63.22.2  ad 
    368  1.63.22.2  ad 		SC_DEBUG(periph, SCSIPI_DB3, ("debug set to %d\n", level));
    369  1.63.22.2  ad 		periph->periph_dbflags = 0;
    370  1.63.22.2  ad 		if (level & 1)
    371  1.63.22.2  ad 			periph->periph_dbflags |= SCSIPI_DB1;
    372  1.63.22.2  ad 		if (level & 2)
    373  1.63.22.2  ad 			periph->periph_dbflags |= SCSIPI_DB2;
    374  1.63.22.2  ad 		if (level & 4)
    375  1.63.22.2  ad 			periph->periph_dbflags |= SCSIPI_DB3;
    376  1.63.22.2  ad 		if (level & 8)
    377  1.63.22.2  ad 			periph->periph_dbflags |= SCSIPI_DB4;
    378  1.63.22.2  ad 		return (0);
    379  1.63.22.2  ad 	}
    380  1.63.22.2  ad 	case SCIOCRECONFIG:
    381  1.63.22.2  ad 	case SCIOCDECONFIG:
    382  1.63.22.2  ad 		return (EINVAL);
    383  1.63.22.2  ad 	case SCIOCIDENTIFY: {
    384  1.63.22.2  ad 		struct scsi_addr *sca = (struct scsi_addr *)addr;
    385  1.63.22.2  ad 
    386  1.63.22.2  ad 		switch (scsipi_periph_bustype(periph)) {
    387  1.63.22.2  ad 		case SCSIPI_BUSTYPE_SCSI:
    388  1.63.22.2  ad 			sca->type = TYPE_SCSI;
    389  1.63.22.2  ad 			sca->addr.scsi.scbus =
    390  1.63.22.2  ad 			    device_unit(device_parent(periph->periph_dev));
    391  1.63.22.2  ad 			sca->addr.scsi.target = periph->periph_target;
    392  1.63.22.2  ad 			sca->addr.scsi.lun = periph->periph_lun;
    393  1.63.22.2  ad 			return (0);
    394  1.63.22.2  ad 		case SCSIPI_BUSTYPE_ATAPI:
    395  1.63.22.2  ad 			sca->type = TYPE_ATAPI;
    396  1.63.22.2  ad 			sca->addr.atapi.atbus =
    397  1.63.22.2  ad 			    device_unit(device_parent(periph->periph_dev));
    398  1.63.22.2  ad 			sca->addr.atapi.drive = periph->periph_target;
    399  1.63.22.2  ad 			return (0);
    400  1.63.22.2  ad 		}
    401  1.63.22.2  ad 		return (ENXIO);
    402  1.63.22.2  ad 	}
    403  1.63.22.2  ad #if defined(COMPAT_12) || defined(COMPAT_FREEBSD)
    404  1.63.22.2  ad 	/* SCIOCIDENTIFY before ATAPI staff merge */
    405  1.63.22.2  ad 	case OSCIOCIDENTIFY: {
    406  1.63.22.2  ad 		struct oscsi_addr *sca = (struct oscsi_addr *)addr;
    407  1.63.22.2  ad 
    408  1.63.22.2  ad 		switch (scsipi_periph_bustype(periph)) {
    409  1.63.22.2  ad 		case SCSIPI_BUSTYPE_SCSI:
    410  1.63.22.2  ad 			sca->scbus =
    411  1.63.22.2  ad 			    device_unit(device_parent(periph->periph_dev));
    412  1.63.22.2  ad 			sca->target = periph->periph_target;
    413  1.63.22.2  ad 			sca->lun = periph->periph_lun;
    414  1.63.22.2  ad 			return (0);
    415  1.63.22.2  ad 		}
    416  1.63.22.2  ad 		return (ENODEV);
    417  1.63.22.2  ad 	}
    418  1.63.22.2  ad #endif
    419  1.63.22.2  ad 	default:
    420  1.63.22.2  ad 		return (ENOTTY);
    421  1.63.22.2  ad 	}
    422  1.63.22.2  ad 
    423  1.63.22.2  ad #ifdef DIAGNOSTIC
    424  1.63.22.2  ad 	panic("scsipi_do_ioctl: impossible");
    425  1.63.22.2  ad #endif
    426  1.63.22.2  ad }
    427