Home | History | Annotate | Line # | Download | only in usb
umass_scsipi.c revision 1.8
      1 /*	$NetBSD: umass_scsipi.c,v 1.8 2003/01/21 20:56:57 augustss Exp $	*/
      2 
      3 /*
      4  * Copyright (c) 2001 The NetBSD Foundation, Inc.
      5  * All rights reserved.
      6  *
      7  * This code is derived from software contributed to The NetBSD Foundation
      8  * by Lennart Augustsson (lennart (at) augustsson.net) at
      9  * Carlstedt Research & Technology.
     10  *
     11  * Redistribution and use in source and binary forms, with or without
     12  * modification, are permitted provided that the following conditions
     13  * are met:
     14  * 1. Redistributions of source code must retain the above copyright
     15  *    notice, this list of conditions and the following disclaimer.
     16  * 2. Redistributions in binary form must reproduce the above copyright
     17  *    notice, this list of conditions and the following disclaimer in the
     18  *    documentation and/or other materials provided with the distribution.
     19  * 3. All advertising materials mentioning features or use of this software
     20  *    must display the following acknowledgement:
     21  *        This product includes software developed by the NetBSD
     22  *        Foundation, Inc. and its contributors.
     23  * 4. Neither the name of The NetBSD Foundation nor the names of its
     24  *    contributors may be used to endorse or promote products derived
     25  *    from this software without specific prior written permission.
     26  *
     27  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
     28  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     29  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     30  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
     31  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     32  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     33  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     34  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     35  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     36  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     37  * POSSIBILITY OF SUCH DAMAGE.
     38  */
     39 
     40 #include <sys/cdefs.h>
     41 __KERNEL_RCSID(0, "$NetBSD: umass_scsipi.c,v 1.8 2003/01/21 20:56:57 augustss Exp $");
     42 
     43 #include "atapibus.h"
     44 #include "scsibus.h"
     45 
     46 #include <sys/param.h>
     47 #include <sys/systm.h>
     48 #include <sys/kernel.h>
     49 #include <sys/conf.h>
     50 #include <sys/buf.h>
     51 #include <sys/device.h>
     52 #include <sys/ioctl.h>
     53 #include <sys/malloc.h>
     54 
     55 /* SCSI & ATAPI */
     56 #include <sys/scsiio.h>
     57 #include <dev/scsipi/scsi_all.h>
     58 #include <dev/scsipi/scsipi_all.h>
     59 #include <dev/scsipi/scsiconf.h>
     60 
     61 #include <dev/scsipi/atapiconf.h>
     62 
     63 #include <dev/scsipi/scsipi_disk.h>
     64 #include <dev/scsipi/scsi_disk.h>
     65 #include <dev/scsipi/scsi_changer.h>
     66 
     67 #include <dev/scsipi/atapi_disk.h>
     68 
     69 #include <sys/disk.h>		/* XXX */
     70 #include <dev/scsipi/sdvar.h>	/* XXX */
     71 
     72 /* USB */
     73 #include <dev/usb/usb.h>
     74 #include <dev/usb/usbdi.h>
     75 #include <dev/usb/usbdi_util.h>
     76 #include <dev/usb/usbdevs.h>
     77 
     78 #include <dev/usb/umassvar.h>
     79 #include <dev/usb/umass_scsipi.h>
     80 
     81 struct umass_scsipi_softc {
     82 	struct umassbus_softc	base;
     83 
     84 	struct atapi_adapter	sc_atapi_adapter;
     85 #define sc_adapter sc_atapi_adapter._generic
     86 	struct scsipi_channel sc_channel;
     87 	usbd_status		sc_sync_status;
     88 	struct scsipi_sense	sc_sense_cmd;
     89 };
     90 
     91 
     92 #define SHORT_INQUIRY_LENGTH    36 /* XXX */
     93 
     94 #define UMASS_SCSIID_HOST	0x00
     95 #define UMASS_SCSIID_DEVICE	0x01
     96 
     97 #define UMASS_ATAPI_DRIVE	0
     98 
     99 Static void umass_scsipi_request(struct scsipi_channel *,
    100 				 scsipi_adapter_req_t, void *);
    101 Static void umass_scsipi_minphys(struct buf *bp);
    102 Static int umass_scsipi_ioctl(struct scsipi_channel *, u_long,
    103 			      caddr_t, int, usb_proc_ptr );
    104 Static int umass_scsipi_getgeom(struct scsipi_periph *periph,
    105 				struct disk_parms *, u_long sectors);
    106 
    107 Static void umass_scsipi_cb(struct umass_softc *sc, void *priv,
    108 			    int residue, int status);
    109 Static void umass_scsipi_sense_cb(struct umass_softc *sc, void *priv,
    110 				  int residue, int status);
    111 
    112 Static struct umass_scsipi_softc *umass_scsipi_setup(struct umass_softc *sc);
    113 
    114 Static int scsipiprint(void *aux, const char *pnp);
    115 
    116 #if NATAPIBUS > 0
    117 Static void umass_atapi_probe_device(struct atapibus_softc *, int);
    118 
    119 const struct scsipi_bustype umass_atapi_bustype = {
    120 	SCSIPI_BUSTYPE_ATAPI,
    121 	atapi_scsipi_cmd,
    122 	atapi_interpret_sense,
    123 	atapi_print_addr,
    124 	scsi_kill_pending,
    125 };
    126 #endif
    127 
    128 
    129 #if NSCSIBUS > 0
    130 int
    131 umass_scsi_attach(struct umass_softc *sc)
    132 {
    133 	struct umass_scsipi_softc *scbus;
    134 
    135 	scbus = umass_scsipi_setup(sc);
    136 
    137 	scbus->sc_channel.chan_bustype = &scsi_bustype;
    138 	scbus->sc_channel.chan_ntargets = UMASS_SCSIID_DEVICE + 1;
    139 	scbus->sc_channel.chan_nluns = sc->maxlun + 1;
    140 	scbus->sc_channel.chan_id = UMASS_SCSIID_HOST;
    141 	DPRINTF(UDMASS_USB, ("%s: umass_attach_bus: SCSI\n",
    142 			     USBDEVNAME(sc->sc_dev)));
    143 	scbus->base.sc_child =
    144 	    config_found(&sc->sc_dev, &scbus->sc_channel, scsipiprint);
    145 
    146 	return (0);
    147 }
    148 #endif
    149 
    150 #if NATAPIBUS > 0
    151 int
    152 umass_atapi_attach(struct umass_softc *sc)
    153 {
    154 	struct umass_scsipi_softc *scbus;
    155 
    156 	scbus = umass_scsipi_setup(sc);
    157 	scbus->sc_atapi_adapter.atapi_probe_device =  umass_atapi_probe_device;
    158 
    159 	scbus->sc_channel.chan_bustype = &umass_atapi_bustype;
    160 	scbus->sc_channel.chan_ntargets = 2;
    161 	scbus->sc_channel.chan_nluns = 1;
    162 
    163 	scbus->sc_channel.chan_defquirks |= sc->sc_busquirks;
    164 	DPRINTF(UDMASS_USB, ("%s: umass_attach_bus: ATAPI\n",
    165 			     USBDEVNAME(sc->sc_dev)));
    166 	scbus->base.sc_child =
    167 	    config_found(&sc->sc_dev, &scbus->sc_channel, scsipiprint);
    168 
    169 	return (0);
    170 }
    171 #endif
    172 
    173 Static struct umass_scsipi_softc *
    174 umass_scsipi_setup(struct umass_softc *sc)
    175 {
    176 	struct umass_scsipi_softc *scbus;
    177 
    178 	scbus = malloc(sizeof *scbus, M_DEVBUF, M_WAITOK | M_ZERO);
    179 	sc->bus = &scbus->base;
    180 
    181 	/* Only use big commands for USB SCSI devices. */
    182 	sc->sc_busquirks |= PQUIRK_ONLYBIG;
    183 
    184 	/* Fill in the adapter. */
    185 	memset(&scbus->sc_adapter, 0, sizeof(scbus->sc_adapter));
    186 	scbus->sc_adapter.adapt_dev = &sc->sc_dev;
    187 	scbus->sc_adapter.adapt_nchannels = 1;
    188 	scbus->sc_adapter.adapt_request = umass_scsipi_request;
    189 	scbus->sc_adapter.adapt_minphys = umass_scsipi_minphys;
    190 	scbus->sc_adapter.adapt_ioctl = umass_scsipi_ioctl;
    191 	scbus->sc_adapter.adapt_getgeom = umass_scsipi_getgeom;
    192 
    193 	/* Fill in the channel. */
    194 	memset(&scbus->sc_channel, 0, sizeof(scbus->sc_channel));
    195 	scbus->sc_channel.chan_adapter = &scbus->sc_adapter;
    196 	scbus->sc_channel.chan_channel = 0;
    197 	scbus->sc_channel.chan_flags = SCSIPI_CHAN_OPENINGS;
    198 	scbus->sc_channel.chan_openings = 1;
    199 	scbus->sc_channel.chan_max_periph = 1;
    200 	scbus->sc_channel.chan_defquirks |= sc->sc_busquirks;
    201 
    202 	return (scbus);
    203 }
    204 
    205 Static int
    206 scsipiprint(void *aux, const char *pnp)
    207 {
    208 	struct scsipi_channel *chan = aux;
    209 
    210 	if (chan->chan_bustype->bustype_type == SCSIPI_BUSTYPE_SCSI) {
    211 #if NSCSIBUS > 0
    212 		return (scsiprint(aux, pnp));
    213 #else
    214 		if (pnp)
    215 			aprint_normal("scsibus at %s", pnp);
    216 		return (UNCONF);
    217 #endif
    218 	} else {
    219 #if NATAPIBUS > 0
    220 		return (atapiprint(aux, pnp));
    221 #else
    222 		if (pnp)
    223 			aprint_normal("atapibus at %s", pnp);
    224 		return (UNCONF);
    225 #endif
    226 	}
    227 }
    228 
    229 Static void
    230 umass_scsipi_request(struct scsipi_channel *chan,
    231 		scsipi_adapter_req_t req, void *arg)
    232 {
    233 	struct scsipi_adapter *adapt = chan->chan_adapter;
    234 	struct scsipi_periph *periph;
    235 	struct scsipi_xfer *xs;
    236 	struct umass_softc *sc = (void *)adapt->adapt_dev;
    237 	struct umass_scsipi_softc *scbus = (struct umass_scsipi_softc *)sc->bus;
    238 	struct scsipi_generic *cmd, trcmd;
    239 	int cmdlen;
    240 	int dir;
    241 #ifdef UMASS_DEBUG
    242 	microtime(&sc->tv);
    243 #endif
    244 	switch(req) {
    245 	case ADAPTER_REQ_RUN_XFER:
    246 		xs = arg;
    247 		periph = xs->xs_periph;
    248 		DIF(UDMASS_UPPER, periph->periph_dbflags |= SCSIPI_DEBUG_FLAGS);
    249 
    250 		DPRINTF(UDMASS_CMD, ("%s: umass_scsi_cmd: at %lu.%06lu: %d:%d "
    251 		    "xs=%p cmd=0x%02x datalen=%d (quirks=0x%x, poll=%d)\n",
    252 		    USBDEVNAME(sc->sc_dev), sc->tv.tv_sec, sc->tv.tv_usec,
    253 		    periph->periph_target, periph->periph_lun,
    254 		    xs, xs->cmd->opcode, xs->datalen,
    255 		    periph->periph_quirks, xs->xs_control & XS_CTL_POLL));
    256 #if defined(USB_DEBUG) && defined(SCSIPI_DEBUG)
    257 		if (umassdebug & UDMASS_SCSI)
    258 			show_scsipi_xs(xs);
    259 		else if (umassdebug & ~UDMASS_CMD)
    260 			show_scsipi_cmd(xs);
    261 #endif
    262 
    263 		if (sc->sc_dying) {
    264 			xs->error = XS_DRIVER_STUFFUP;
    265 			goto done;
    266 		}
    267 
    268 #ifdef UMASS_DEBUG
    269 		if (chan->chan_bustype->bustype_type == SCSIPI_BUSTYPE_ATAPI ?
    270 		    periph->periph_target != UMASS_ATAPI_DRIVE :
    271 		    periph->periph_target != UMASS_SCSIID_DEVICE) {
    272 			DPRINTF(UDMASS_SCSI, ("%s: wrong SCSI ID %d\n",
    273 			    USBDEVNAME(sc->sc_dev),
    274 			    periph->periph_target));
    275 			xs->error = XS_DRIVER_STUFFUP;
    276 			goto done;
    277 		}
    278 #endif
    279 
    280 		cmd = xs->cmd;
    281 		cmdlen = xs->cmdlen;
    282 
    283 		/* XXX should use transform */
    284 
    285 		if (cmd->opcode == START_STOP &&
    286 		    (sc->sc_quirks & UMASS_QUIRK_NO_START_STOP)) {
    287 			/*printf("%s: START_STOP\n", USBDEVNAME(sc->sc_dev));*/
    288 			xs->error = XS_NOERROR;
    289 			goto done;
    290 		}
    291 
    292 		if (cmd->opcode == INQUIRY &&
    293 		    (sc->sc_quirks & UMASS_QUIRK_FORCE_SHORT_INQUIRY)) {
    294 			/*
    295 			 * Some drives wedge when asked for full inquiry
    296 			 * information.
    297 			 */
    298 			memcpy(&trcmd, cmd, sizeof trcmd);
    299 			trcmd.bytes[4] = SHORT_INQUIRY_LENGTH;
    300 			cmd = &trcmd;
    301 			xs->datalen = SHORT_INQUIRY_LENGTH;
    302 		}
    303 
    304 		dir = DIR_NONE;
    305 		if (xs->datalen) {
    306 			switch (xs->xs_control &
    307 			    (XS_CTL_DATA_IN | XS_CTL_DATA_OUT)) {
    308 			case XS_CTL_DATA_IN:
    309 				dir = DIR_IN;
    310 				break;
    311 			case XS_CTL_DATA_OUT:
    312 				dir = DIR_OUT;
    313 				break;
    314 			}
    315 		}
    316 
    317 		if (xs->datalen > UMASS_MAX_TRANSFER_SIZE) {
    318 			printf("umass_cmd: large datalen, %d\n", xs->datalen);
    319 			xs->error = XS_DRIVER_STUFFUP;
    320 			goto done;
    321 		}
    322 
    323 		if (xs->xs_control & XS_CTL_POLL) {
    324 			/* Use sync transfer. XXX Broken! */
    325 			DPRINTF(UDMASS_SCSI,
    326 			    ("umass_scsi_cmd: sync dir=%d\n", dir));
    327 			sc->sc_xfer_flags = USBD_SYNCHRONOUS;
    328 			scbus->sc_sync_status = USBD_INVAL;
    329 			sc->sc_methods->wire_xfer(sc, periph->periph_lun, cmd,
    330 						  cmdlen, xs->data,
    331 						  xs->datalen, dir,
    332 						  xs->timeout, 0, xs);
    333 			sc->sc_xfer_flags = 0;
    334 			DPRINTF(UDMASS_SCSI, ("umass_scsi_cmd: done err=%d\n",
    335 					      scbus->sc_sync_status));
    336 			switch (scbus->sc_sync_status) {
    337 			case USBD_NORMAL_COMPLETION:
    338 				xs->error = XS_NOERROR;
    339 				break;
    340 			case USBD_TIMEOUT:
    341 				xs->error = XS_TIMEOUT;
    342 				break;
    343 			default:
    344 				xs->error = XS_DRIVER_STUFFUP;
    345 				break;
    346 			}
    347 			goto done;
    348 		} else {
    349 			DPRINTF(UDMASS_SCSI,
    350 			    ("umass_scsi_cmd: async dir=%d, cmdlen=%d"
    351 				      " datalen=%d\n",
    352 				      dir, cmdlen, xs->datalen));
    353 			sc->sc_methods->wire_xfer(sc, periph->periph_lun, cmd,
    354 						  cmdlen, xs->data,
    355 						  xs->datalen, dir,
    356 						  xs->timeout,
    357 						  umass_scsipi_cb, xs);
    358 			return;
    359 		}
    360 
    361 		/* Return if command finishes early. */
    362  done:
    363 		scsipi_done(xs);
    364 		return;
    365 	default:
    366 		/* Not supported, nothing to do. */
    367 		;
    368 	}
    369 }
    370 
    371 Static void
    372 umass_scsipi_minphys(struct buf *bp)
    373 {
    374 #ifdef DIAGNOSTIC
    375 	if (bp->b_bcount <= 0) {
    376 		printf("umass_scsipi_minphys count(%ld) <= 0\n",
    377 		       bp->b_bcount);
    378 		bp->b_bcount = UMASS_MAX_TRANSFER_SIZE;
    379 	}
    380 #endif
    381 	if (bp->b_bcount > UMASS_MAX_TRANSFER_SIZE)
    382 		bp->b_bcount = UMASS_MAX_TRANSFER_SIZE;
    383 	minphys(bp);
    384 }
    385 
    386 int
    387 umass_scsipi_ioctl(struct scsipi_channel *chan, u_long cmd, caddr_t arg,
    388 		   int flag, usb_proc_ptr p)
    389 {
    390 	/*struct umass_softc *sc = link->adapter_softc;*/
    391 	/*struct umass_scsipi_softc *scbus = sc->bus;*/
    392 
    393 	switch (cmd) {
    394 #if 0
    395 	case SCBUSIORESET:
    396 		ccb->ccb_h.status = CAM_REQ_INPROG;
    397 		umass_reset(sc, umass_cam_cb, (void *) ccb);
    398 		return (0);
    399 #endif
    400 	default:
    401 		return (ENOTTY);
    402 	}
    403 }
    404 
    405 Static int
    406 umass_scsipi_getgeom(struct scsipi_periph *periph, struct disk_parms *dp,
    407 		     u_long sectors)
    408 {
    409 	struct umass_softc *sc =
    410 	    (void *)periph->periph_channel->chan_adapter->adapt_dev;
    411 
    412 	/* If it's not a floppy, we don't know what to do. */
    413 	if (sc->sc_cmd != UMASS_CPROTO_UFI)
    414 		return (0);
    415 
    416 	switch (sectors) {
    417 	case 1440:
    418 		/* Most likely a single density 3.5" floppy. */
    419 		dp->heads = 2;
    420 		dp->sectors = 9;
    421 		dp->cyls = 80;
    422 		return (1);
    423 	case 2880:
    424 		/* Most likely a double density 3.5" floppy. */
    425 		dp->heads = 2;
    426 		dp->sectors = 18;
    427 		dp->cyls = 80;
    428 		return (1);
    429 	default:
    430 		return (0);
    431 	}
    432 }
    433 
    434 Static void
    435 umass_scsipi_cb(struct umass_softc *sc, void *priv, int residue, int status)
    436 {
    437 	struct umass_scsipi_softc *scbus = (struct umass_scsipi_softc *)sc->bus;
    438 	struct scsipi_xfer *xs = priv;
    439 	struct scsipi_periph *periph = xs->xs_periph;
    440 	int cmdlen;
    441 	int s;
    442 #ifdef UMASS_DEBUG
    443 	struct timeval tv;
    444 	u_int delta;
    445 	microtime(&tv);
    446 	delta = (tv.tv_sec - sc->tv.tv_sec) * 1000000 + tv.tv_usec - sc->tv.tv_usec;
    447 #endif
    448 
    449 	DPRINTF(UDMASS_CMD,("umass_scsipi_cb: at %lu.%06lu, delta=%u: xs=%p residue=%d"
    450 	    " status=%d\n", tv.tv_sec, tv.tv_usec, delta, xs, residue, status));
    451 
    452 	xs->resid = residue;
    453 
    454 	switch (status) {
    455 	case STATUS_CMD_OK:
    456 		xs->error = XS_NOERROR;
    457 		break;
    458 
    459 	case STATUS_CMD_UNKNOWN:
    460 		/* we can't issue REQUEST SENSE */
    461 		if (xs->xs_periph->periph_quirks & PQUIRK_NOSENSE) {
    462 			/*
    463 			 * If no residue and no other USB error,
    464 			 * command succeeded.
    465 			 */
    466 			if (residue == 0) {
    467 				xs->error = XS_NOERROR;
    468 				break;
    469 			}
    470 
    471 			/*
    472 			 * Some devices return a short INQUIRY
    473 			 * response, omitting response data from the
    474 			 * "vendor specific data" on...
    475 			 */
    476 			if (xs->cmd->opcode == INQUIRY &&
    477 			    residue < xs->datalen) {
    478 				xs->error = XS_NOERROR;
    479 				break;
    480 			}
    481 
    482 			xs->error = XS_DRIVER_STUFFUP;
    483 			break;
    484 		}
    485 		/* FALLTHROUGH */
    486 	case STATUS_CMD_FAILED:
    487 		/* fetch sense data */
    488 		memset(&scbus->sc_sense_cmd, 0, sizeof(scbus->sc_sense_cmd));
    489 		scbus->sc_sense_cmd.opcode = REQUEST_SENSE;
    490 		scbus->sc_sense_cmd.byte2 = periph->periph_lun <<
    491 		    SCSI_CMD_LUN_SHIFT;
    492 		scbus->sc_sense_cmd.length = sizeof(xs->sense);
    493 
    494 		cmdlen = sizeof(scbus->sc_sense_cmd);
    495 		if (sc->sc_cmd == UMASS_CPROTO_UFI) /* XXX */
    496 			cmdlen = UFI_COMMAND_LENGTH;
    497 		sc->sc_methods->wire_xfer(sc, periph->periph_lun,
    498 					  &scbus->sc_sense_cmd, cmdlen,
    499 					  &xs->sense, sizeof(xs->sense),
    500 					  DIR_IN, xs->timeout,
    501 					  umass_scsipi_sense_cb, xs);
    502 		return;
    503 
    504 	case STATUS_WIRE_FAILED:
    505 		xs->error = XS_RESET;
    506 		break;
    507 
    508 	default:
    509 		panic("%s: Unknown status %d in umass_scsipi_cb",
    510 			USBDEVNAME(sc->sc_dev), status);
    511 	}
    512 
    513 	DPRINTF(UDMASS_CMD,("umass_scsipi_cb: at %lu.%06lu: return xs->error="
    514             "%d, xs->xs_status=0x%x xs->resid=%d\n",
    515 	     tv.tv_sec, tv.tv_usec,
    516 	     xs->error, xs->xs_status, xs->resid));
    517 
    518 	s = splbio();
    519 	scsipi_done(xs);
    520 	splx(s);
    521 }
    522 
    523 /*
    524  * Finalise a completed autosense operation
    525  */
    526 Static void
    527 umass_scsipi_sense_cb(struct umass_softc *sc, void *priv, int residue,
    528 		      int status)
    529 {
    530 	struct scsipi_xfer *xs = priv;
    531 	int s;
    532 
    533 	DPRINTF(UDMASS_CMD,("umass_scsipi_sense_cb: xs=%p residue=%d "
    534 		"status=%d\n", xs, residue, status));
    535 
    536 	switch (status) {
    537 	case STATUS_CMD_OK:
    538 	case STATUS_CMD_UNKNOWN:
    539 		/* getting sense data succeeded */
    540 		if (xs->cmd->opcode == INQUIRY && (xs->resid < xs->datalen ||
    541 		    (sc->sc_quirks & UMASS_QUIRK_RS_NO_CLEAR_UA /* XXX */))) {
    542 			/*
    543 			 * Some drivers return SENSE errors even after INQUIRY.
    544 			 * The upper layer doesn't like that.
    545 			 */
    546 			xs->error = XS_NOERROR;
    547 			break;
    548 		}
    549 		/* XXX look at residue */
    550 		if (residue == 0 || residue == 14)/* XXX */
    551 			xs->error = XS_SENSE;
    552 		else
    553 			xs->error = XS_SHORTSENSE;
    554 		break;
    555 	default:
    556 		DPRINTF(UDMASS_SCSI, ("%s: Autosense failed, status %d\n",
    557 			USBDEVNAME(sc->sc_dev), status));
    558 		xs->error = XS_DRIVER_STUFFUP;
    559 		break;
    560 	}
    561 
    562 	xs->xs_status |= XS_STS_DONE;
    563 
    564 	DPRINTF(UDMASS_CMD,("umass_scsipi_sense_cb: return xs->error=%d, "
    565 		"xs->xs_status=0x%x xs->resid=%d\n", xs->error, xs->xs_status,
    566 		xs->resid));
    567 
    568 	s = splbio();
    569 	scsipi_done(xs);
    570 	splx(s);
    571 }
    572 
    573 #if NATAPIBUS > 0
    574 Static void
    575 umass_atapi_probe_device(struct atapibus_softc *atapi, int target)
    576 {
    577 	struct scsipi_channel *chan = atapi->sc_channel;
    578 	struct scsipi_periph *periph;
    579 	struct scsipibus_attach_args sa;
    580 	char vendor[33], product[65], revision[17];
    581 	struct scsipi_inquiry_data inqbuf;
    582 
    583 	DPRINTF(UDMASS_SCSI,("umass_atapi_probe_device: atapi=%p target=%d\n",
    584 			     atapi, target));
    585 
    586 	if (target != UMASS_ATAPI_DRIVE)	/* only probe drive 0 */
    587 		return;
    588 
    589 	/* skip if already attached */
    590 	if (scsipi_lookup_periph(chan, target, 0) != NULL)
    591 		return;
    592 
    593 	periph = scsipi_alloc_periph(M_NOWAIT);
    594 	if (periph == NULL) {
    595 		printf("%s: can't allocate link for drive %d\n",
    596 		       atapi->sc_dev.dv_xname, target);
    597 		return;
    598 	}
    599 
    600 	DIF(UDMASS_UPPER, periph->periph_dbflags |= 1); /* XXX 1 */
    601 	periph->periph_channel = chan;
    602 	periph->periph_switch = &atapi_probe_periphsw;
    603 	periph->periph_target = target;
    604 	periph->periph_quirks = chan->chan_defquirks;
    605 
    606 	DPRINTF(UDMASS_SCSI, ("umass_atapi_probe_device: doing inquiry\n"));
    607 	/* Now go ask the device all about itself. */
    608 	memset(&inqbuf, 0, sizeof(inqbuf));
    609 	if (scsipi_inquire(periph, &inqbuf,
    610 	    XS_CTL_DISCOVERY | XS_CTL_DATA_ONSTACK) != 0) {
    611 		DPRINTF(UDMASS_SCSI, ("umass_atapi_probe_device: "
    612 		    "scsipi_inquire failed\n"));
    613 		free(periph, M_DEVBUF);
    614 		return;
    615 	}
    616 
    617 	scsipi_strvis(vendor, 33, inqbuf.vendor, 8);
    618 	scsipi_strvis(product, 65, inqbuf.product, 16);
    619 	scsipi_strvis(revision, 17, inqbuf.revision, 4);
    620 
    621 	sa.sa_periph = periph;
    622 	sa.sa_inqbuf.type = inqbuf.device;
    623 	sa.sa_inqbuf.removable = inqbuf.dev_qual2 & SID_REMOVABLE ?
    624 	    T_REMOV : T_FIXED;
    625 	if (sa.sa_inqbuf.removable)
    626 		periph->periph_flags |= PERIPH_REMOVABLE;
    627 	sa.sa_inqbuf.vendor = vendor;
    628 	sa.sa_inqbuf.product = product;
    629 	sa.sa_inqbuf.revision = revision;
    630 	sa.sa_inqptr = NULL;
    631 
    632 	DPRINTF(UDMASS_SCSI, ("umass_atapi_probedev: doing atapi_probedev on "
    633 			      "'%s' '%s' '%s'\n", vendor, product, revision));
    634 	atapi_probe_device(atapi, target, periph, &sa);
    635 	/* atapi_probe_device() frees the periph when there is no device.*/
    636 }
    637 #endif
    638