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