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