2005-12-11 15:16:03 +03:00
|
|
|
/* $NetBSD: atapi_base.c,v 1.26 2005/12/11 12:23:50 christos Exp $ */
|
1997-08-27 15:22:52 +04:00
|
|
|
|
1998-08-15 14:10:47 +04:00
|
|
|
/*-
|
2004-09-18 03:30:22 +04:00
|
|
|
* Copyright (c) 1998, 1999, 2004 The NetBSD Foundation, Inc.
|
1998-08-15 14:10:47 +04:00
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* This code is derived from software contributed to The NetBSD Foundation
|
2001-04-25 21:53:04 +04:00
|
|
|
* by Charles M. Hannum; by Jason R. Thorpe of the Numerical Aerospace
|
|
|
|
* Simulation Facility, NASA Ames Research Center.
|
1997-08-27 15:22:52 +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-15 14:10:47 +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.
|
1997-08-27 15:22:52 +04:00
|
|
|
*
|
1998-08-15 14:10:47 +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.
|
1997-08-27 15:22:52 +04:00
|
|
|
*/
|
|
|
|
|
2001-11-13 09:54:32 +03:00
|
|
|
#include <sys/cdefs.h>
|
2005-12-11 15:16:03 +03:00
|
|
|
__KERNEL_RCSID(0, "$NetBSD: atapi_base.c,v 1.26 2005/12/11 12:23:50 christos Exp $");
|
2001-11-13 09:54:32 +03:00
|
|
|
|
1997-08-27 15:22:52 +04:00
|
|
|
#include <sys/param.h>
|
|
|
|
#include <sys/systm.h>
|
|
|
|
#include <sys/kernel.h>
|
|
|
|
#include <sys/buf.h>
|
|
|
|
#include <sys/uio.h>
|
|
|
|
#include <sys/malloc.h>
|
|
|
|
#include <sys/errno.h>
|
|
|
|
#include <sys/device.h>
|
|
|
|
#include <sys/proc.h>
|
|
|
|
|
|
|
|
#include <dev/scsipi/scsipi_all.h>
|
1998-01-15 05:21:27 +03:00
|
|
|
#include <dev/scsipi/scsipiconf.h>
|
1997-08-27 15:22:52 +04:00
|
|
|
#include <dev/scsipi/atapiconf.h>
|
|
|
|
#include <dev/scsipi/scsipi_base.h>
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Look at the returned sense and act on the error, determining
|
|
|
|
* the unix error number to pass back. (0 = report no error)
|
|
|
|
*
|
|
|
|
* THIS IS THE DEFAULT ERROR HANDLER
|
|
|
|
*/
|
1997-10-01 05:18:38 +04:00
|
|
|
int
|
2004-08-21 21:40:25 +04:00
|
|
|
atapi_interpret_sense(struct scsipi_xfer *xs)
|
1997-08-27 15:22:52 +04:00
|
|
|
{
|
2001-04-25 21:53:04 +04:00
|
|
|
struct scsipi_periph *periph = xs->xs_periph;
|
1997-08-27 15:22:52 +04:00
|
|
|
int key, error;
|
2005-05-30 02:00:50 +04:00
|
|
|
const char *msg = NULL;
|
1997-08-27 15:22:52 +04:00
|
|
|
|
|
|
|
/*
|
|
|
|
* If the device has it's own error handler, call it first.
|
|
|
|
* If it returns a legit error value, return that, otherwise
|
|
|
|
* it wants us to continue with normal error processing.
|
|
|
|
*/
|
2001-04-25 21:53:04 +04:00
|
|
|
if (periph->periph_switch->psw_error != NULL) {
|
|
|
|
SC_DEBUG(periph, SCSIPI_DB2,
|
1997-08-27 15:22:52 +04:00
|
|
|
("calling private err_handler()\n"));
|
2001-04-25 21:53:04 +04:00
|
|
|
error = (*periph->periph_switch->psw_error)(xs);
|
|
|
|
if (error != EJUSTRETURN)
|
|
|
|
return (error);
|
1997-08-27 15:22:52 +04:00
|
|
|
}
|
1998-11-17 17:45:39 +03:00
|
|
|
/*
|
|
|
|
* otherwise use the default, call the generic sense handler if we have
|
|
|
|
* more than the sense key
|
|
|
|
*/
|
|
|
|
if (xs->error == XS_SENSE)
|
|
|
|
return (scsipi_interpret_sense(xs));
|
|
|
|
|
|
|
|
key = (xs->sense.atapi_sense & 0xf0) >> 4;
|
1997-08-27 15:22:52 +04:00
|
|
|
switch (key) {
|
1998-07-11 04:52:09 +04:00
|
|
|
case SKEY_RECOVERED_ERROR:
|
1997-08-27 15:22:52 +04:00
|
|
|
msg = "soft error (corrected)";
|
1998-07-01 21:16:46 +04:00
|
|
|
case SKEY_NO_SENSE:
|
1997-08-27 15:22:52 +04:00
|
|
|
if (xs->resid == xs->datalen)
|
|
|
|
xs->resid = 0; /* not short read */
|
1998-07-01 21:16:46 +04:00
|
|
|
error = 0;
|
|
|
|
break;
|
|
|
|
case SKEY_NOT_READY:
|
2001-04-25 21:53:04 +04:00
|
|
|
if ((periph->periph_flags & PERIPH_REMOVABLE) != 0)
|
|
|
|
periph->periph_flags &= ~PERIPH_MEDIA_LOADED;
|
1999-10-01 02:57:52 +04:00
|
|
|
if ((xs->xs_control & XS_CTL_IGNORE_NOT_READY) != 0)
|
1997-10-01 05:18:38 +04:00
|
|
|
return (0);
|
1999-10-01 02:57:52 +04:00
|
|
|
if ((xs->xs_control & XS_CTL_SILENT) != 0)
|
1997-10-01 05:18:38 +04:00
|
|
|
return (EIO);
|
1997-08-27 15:22:52 +04:00
|
|
|
msg = "not ready";
|
|
|
|
error = EIO;
|
|
|
|
break;
|
1998-07-01 21:16:46 +04:00
|
|
|
case SKEY_MEDIUM_ERROR: /* MEDIUM ERROR */
|
1997-08-27 15:22:52 +04:00
|
|
|
msg = "medium error";
|
|
|
|
error = EIO;
|
|
|
|
break;
|
1998-07-01 21:16:46 +04:00
|
|
|
case SKEY_HARDWARE_ERROR:
|
1997-08-27 15:22:52 +04:00
|
|
|
msg = "non-media hardware failure";
|
|
|
|
error = EIO;
|
|
|
|
break;
|
1998-07-01 21:16:46 +04:00
|
|
|
case SKEY_ILLEGAL_REQUEST:
|
1999-10-01 02:57:52 +04:00
|
|
|
if ((xs->xs_control &
|
|
|
|
XS_CTL_IGNORE_ILLEGAL_REQUEST) != 0)
|
1997-10-01 05:18:38 +04:00
|
|
|
return (0);
|
1999-10-01 02:57:52 +04:00
|
|
|
if ((xs->xs_control & XS_CTL_SILENT) != 0)
|
1997-10-01 05:18:38 +04:00
|
|
|
return (EIO);
|
1997-08-27 15:22:52 +04:00
|
|
|
msg = "illegal request";
|
|
|
|
error = EINVAL;
|
|
|
|
break;
|
1998-07-01 21:16:46 +04:00
|
|
|
case SKEY_UNIT_ATTENTION:
|
2001-04-25 21:53:04 +04:00
|
|
|
if ((periph->periph_flags & PERIPH_REMOVABLE) != 0)
|
|
|
|
periph->periph_flags &= ~PERIPH_MEDIA_LOADED;
|
1999-10-01 02:57:52 +04:00
|
|
|
if ((xs->xs_control &
|
|
|
|
XS_CTL_IGNORE_MEDIA_CHANGE) != 0 ||
|
1997-08-27 15:22:52 +04:00
|
|
|
/* XXX Should reupload any transient state. */
|
2001-04-25 21:53:04 +04:00
|
|
|
(periph->periph_flags & PERIPH_REMOVABLE) == 0)
|
1997-10-01 05:18:38 +04:00
|
|
|
return (ERESTART);
|
1999-10-01 02:57:52 +04:00
|
|
|
if ((xs->xs_control & XS_CTL_SILENT) != 0)
|
1997-10-01 05:18:38 +04:00
|
|
|
return (EIO);
|
1997-08-27 15:22:52 +04:00
|
|
|
msg = "unit attention";
|
|
|
|
error = EIO;
|
|
|
|
break;
|
2005-02-21 03:29:06 +03:00
|
|
|
case SKEY_DATA_PROTECT:
|
1997-08-27 15:22:52 +04:00
|
|
|
msg = "readonly device";
|
1997-12-31 00:36:51 +03:00
|
|
|
error = EROFS;
|
1997-08-27 15:22:52 +04:00
|
|
|
break;
|
1998-07-01 21:16:46 +04:00
|
|
|
case SKEY_ABORTED_COMMAND:
|
1997-08-27 15:22:52 +04:00
|
|
|
msg = "command aborted";
|
2004-03-11 00:57:31 +03:00
|
|
|
if (xs->xs_retries != 0) {
|
|
|
|
xs->xs_retries--;
|
|
|
|
error = ERESTART;
|
|
|
|
} else
|
|
|
|
error = EIO;
|
1997-08-27 15:22:52 +04:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
error = EIO;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!key) {
|
|
|
|
if (xs->sense.atapi_sense & 0x01) {
|
|
|
|
/* Illegal length indication */
|
|
|
|
msg = "ATA illegal length indication";
|
|
|
|
error = EIO;
|
|
|
|
}
|
|
|
|
if (xs->sense.atapi_sense & 0x02) { /* vol overflow */
|
|
|
|
msg = "ATA volume overflow";
|
|
|
|
error = ENOSPC;
|
|
|
|
}
|
|
|
|
if (xs->sense.atapi_sense & 0x04) { /* Aborted command */
|
|
|
|
msg = "ATA command aborted";
|
2004-03-11 00:57:31 +03:00
|
|
|
if (xs->xs_retries != 0) {
|
|
|
|
xs->xs_retries--;
|
|
|
|
error = ERESTART;
|
|
|
|
} else
|
|
|
|
error = EIO;
|
1997-08-27 15:22:52 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
if (msg) {
|
2001-04-25 21:53:04 +04:00
|
|
|
scsipi_printaddr(periph);
|
1997-08-27 15:22:52 +04:00
|
|
|
printf("%s\n", msg);
|
|
|
|
} else {
|
|
|
|
if (error) {
|
2001-04-25 21:53:04 +04:00
|
|
|
scsipi_printaddr(periph);
|
1997-08-27 15:22:52 +04:00
|
|
|
printf("unknown error code %d\n",
|
|
|
|
xs->sense.atapi_sense);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
1997-10-01 05:18:38 +04:00
|
|
|
return (error);
|
1997-08-27 15:22:52 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Utility routines often used in SCSI stuff
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Print out the scsi_link structure's address info.
|
|
|
|
*/
|
|
|
|
void
|
2004-08-21 21:40:25 +04:00
|
|
|
atapi_print_addr(struct scsipi_periph *periph)
|
1997-08-27 15:22:52 +04:00
|
|
|
{
|
2001-04-25 21:53:04 +04:00
|
|
|
struct scsipi_channel *chan = periph->periph_channel;
|
|
|
|
struct scsipi_adapter *adapt = chan->chan_adapter;
|
1997-08-27 15:22:52 +04:00
|
|
|
|
2001-04-25 21:53:04 +04:00
|
|
|
printf("%s(%s:%d:%d): ", periph->periph_dev != NULL ?
|
|
|
|
periph->periph_dev->dv_xname : "probe",
|
|
|
|
adapt->adapt_dev->dv_xname,
|
|
|
|
chan->chan_channel, periph->periph_target);
|
1997-08-27 15:22:52 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* ask the atapi driver to perform a command for us.
|
|
|
|
* tell it where to read/write the data, and how
|
|
|
|
* long the data is supposed to be. If we have a buf
|
|
|
|
* to associate with the transfer, we need that too.
|
|
|
|
*/
|
2004-09-18 03:30:22 +04:00
|
|
|
void
|
|
|
|
atapi_scsipi_cmd(struct scsipi_xfer *xs)
|
1997-08-27 15:22:52 +04:00
|
|
|
{
|
2004-09-18 03:30:22 +04:00
|
|
|
struct scsipi_periph *periph = xs->xs_periph;
|
1997-08-27 15:22:52 +04:00
|
|
|
|
2001-04-25 21:53:04 +04:00
|
|
|
SC_DEBUG(periph, SCSIPI_DB2, ("atapi_cmd\n"));
|
1997-08-27 15:22:52 +04:00
|
|
|
|
2001-04-25 21:53:04 +04:00
|
|
|
xs->cmdlen = (periph->periph_cap & PERIPH_CAP_CMD16) ? 16 : 12;
|
1997-08-27 15:22:52 +04:00
|
|
|
}
|