2003-08-24 09:22:26 +00:00
|
|
|
|
/*-
|
2004-01-11 22:08:34 +00:00
|
|
|
|
* Copyright (c) 1998 - 2004 S<EFBFBD>ren Schmidt <sos@FreeBSD.org>
|
2003-08-24 09:22:26 +00:00
|
|
|
|
* All rights reserved.
|
|
|
|
|
*
|
|
|
|
|
* 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,
|
|
|
|
|
* without modification, immediately at the beginning of the file.
|
|
|
|
|
* 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. The name of the author may not be used to endorse or promote products
|
|
|
|
|
* derived from this software without specific prior written permission.
|
|
|
|
|
*
|
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 AUTHOR 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.
|
|
|
|
|
*/
|
|
|
|
|
|
2003-08-24 17:55:58 +00:00
|
|
|
|
#include <sys/cdefs.h>
|
|
|
|
|
__FBSDID("$FreeBSD$");
|
|
|
|
|
|
2003-08-24 09:22:26 +00:00
|
|
|
|
#include "opt_ata.h"
|
|
|
|
|
#include <sys/param.h>
|
|
|
|
|
#include <sys/systm.h>
|
|
|
|
|
#include <sys/ata.h>
|
|
|
|
|
#include <sys/kernel.h>
|
2004-01-28 20:38:51 +00:00
|
|
|
|
#include <sys/bio.h>
|
2003-08-24 09:22:26 +00:00
|
|
|
|
#include <sys/bus.h>
|
|
|
|
|
#include <sys/conf.h>
|
2004-01-11 22:08:34 +00:00
|
|
|
|
#include <sys/sema.h>
|
2003-08-24 09:22:26 +00:00
|
|
|
|
#include <sys/taskqueue.h>
|
2004-01-14 21:26:35 +00:00
|
|
|
|
#include <vm/uma.h>
|
2003-08-24 09:22:26 +00:00
|
|
|
|
#include <machine/bus.h>
|
|
|
|
|
#include <sys/rman.h>
|
|
|
|
|
#include <dev/ata/ata-all.h>
|
|
|
|
|
|
|
|
|
|
/* prototypes */
|
2003-08-25 09:01:49 +00:00
|
|
|
|
static void ata_completed(void *, int);
|
|
|
|
|
static void ata_timeout(struct ata_request *);
|
2003-09-18 09:22:14 +00:00
|
|
|
|
static char *ata_skey2str(u_int8_t);
|
2003-08-24 09:22:26 +00:00
|
|
|
|
|
|
|
|
|
void
|
|
|
|
|
ata_queue_request(struct ata_request *request)
|
|
|
|
|
{
|
2004-01-14 21:26:35 +00:00
|
|
|
|
/* mark request as virgin */
|
2003-08-24 09:22:26 +00:00
|
|
|
|
request->result = request->status = request->error = 0;
|
2004-01-19 15:20:00 +00:00
|
|
|
|
if (!request->callback && !(request->flags & ATA_R_REQUEUE))
|
2004-01-14 21:26:35 +00:00
|
|
|
|
sema_init(&request->done, 0, "ATA request done");
|
2003-08-24 09:22:26 +00:00
|
|
|
|
|
2004-01-19 15:20:00 +00:00
|
|
|
|
/* in IMMEDIATE_MODE we dont queue but call HW directly */
|
|
|
|
|
/* used only during reinit for getparm and config */
|
|
|
|
|
if ((request->device->channel->flags & ATA_IMMEDIATE_MODE) &&
|
|
|
|
|
(request->flags & (ATA_R_CONTROL | ATA_R_IMMEDIATE))) {
|
2003-08-24 09:22:26 +00:00
|
|
|
|
|
2004-01-11 22:08:34 +00:00
|
|
|
|
/* arm timeout */
|
|
|
|
|
if (!request->timeout_handle.callout && !dumping) {
|
|
|
|
|
request->timeout_handle =
|
|
|
|
|
timeout((timeout_t*)ata_timeout, request, request->timeout*hz);
|
|
|
|
|
}
|
2003-08-24 09:22:26 +00:00
|
|
|
|
|
2004-01-11 22:08:34 +00:00
|
|
|
|
/* kick HW into action */
|
2004-01-19 15:20:00 +00:00
|
|
|
|
if (request->device->channel->hw.transaction(request)==ATA_OP_FINISHED){
|
|
|
|
|
if (!request->callback)
|
|
|
|
|
sema_destroy(&request->done);
|
|
|
|
|
return;
|
2004-01-11 22:08:34 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
/* put request on the locked queue at the specified location */
|
|
|
|
|
mtx_lock(&request->device->channel->queue_mtx);
|
2004-01-19 15:20:00 +00:00
|
|
|
|
if (request->flags & ATA_R_IMMEDIATE)
|
2004-01-11 22:08:34 +00:00
|
|
|
|
TAILQ_INSERT_HEAD(&request->device->channel->ata_queue,
|
|
|
|
|
request, chain);
|
|
|
|
|
else
|
|
|
|
|
TAILQ_INSERT_TAIL(&request->device->channel->ata_queue,
|
|
|
|
|
request, chain);
|
|
|
|
|
mtx_unlock(&request->device->channel->queue_mtx);
|
|
|
|
|
|
|
|
|
|
ATA_DEBUG_RQ(request, "queued");
|
|
|
|
|
|
2004-01-28 20:38:51 +00:00
|
|
|
|
ata_start(request->device->channel);
|
2003-08-24 09:22:26 +00:00
|
|
|
|
}
|
2004-01-19 15:20:00 +00:00
|
|
|
|
|
|
|
|
|
/* if this is a requeued request callback/sleep has been setup */
|
|
|
|
|
if (request->flags & ATA_R_REQUEUE)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
/* if this is not a callback wait until request is completed */
|
|
|
|
|
if (!request->callback) {
|
|
|
|
|
ATA_DEBUG_RQ(request, "wait for completition");
|
|
|
|
|
sema_wait(&request->done);
|
2004-01-14 21:26:35 +00:00
|
|
|
|
sema_destroy(&request->done);
|
2004-01-19 15:20:00 +00:00
|
|
|
|
}
|
2003-08-24 09:22:26 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int
|
|
|
|
|
ata_controlcmd(struct ata_device *atadev, u_int8_t command, u_int16_t feature,
|
|
|
|
|
u_int64_t lba, u_int16_t count)
|
|
|
|
|
{
|
|
|
|
|
struct ata_request *request = ata_alloc_request();
|
|
|
|
|
int error = ENOMEM;
|
|
|
|
|
|
|
|
|
|
if (request) {
|
|
|
|
|
request->device = atadev;
|
|
|
|
|
request->u.ata.command = command;
|
|
|
|
|
request->u.ata.lba = lba;
|
|
|
|
|
request->u.ata.count = count;
|
|
|
|
|
request->u.ata.feature = feature;
|
|
|
|
|
request->flags = ATA_R_CONTROL;
|
|
|
|
|
request->timeout = 5;
|
2004-02-06 11:36:50 +00:00
|
|
|
|
request->retries = -1;
|
2003-08-24 09:22:26 +00:00
|
|
|
|
ata_queue_request(request);
|
|
|
|
|
error = request->result;
|
|
|
|
|
ata_free_request(request);
|
|
|
|
|
}
|
|
|
|
|
return error;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int
|
|
|
|
|
ata_atapicmd(struct ata_device *atadev, u_int8_t *ccb, caddr_t data,
|
|
|
|
|
int count, int flags, int timeout)
|
|
|
|
|
{
|
|
|
|
|
struct ata_request *request = ata_alloc_request();
|
2004-02-28 17:47:27 +00:00
|
|
|
|
int error = ENOMEM;
|
2003-08-24 09:22:26 +00:00
|
|
|
|
|
|
|
|
|
if (request) {
|
2004-02-28 17:47:27 +00:00
|
|
|
|
request->device = atadev;
|
2004-01-12 09:33:10 +00:00
|
|
|
|
if ((atadev->param->config & ATA_PROTO_MASK) == ATA_PROTO_ATAPI_12)
|
2004-02-28 17:47:27 +00:00
|
|
|
|
bcopy(ccb, request->u.atapi.ccb, 12);
|
2004-01-12 09:33:10 +00:00
|
|
|
|
else
|
2004-02-28 17:47:27 +00:00
|
|
|
|
bcopy(ccb, request->u.atapi.ccb, 16);
|
2003-08-24 09:22:26 +00:00
|
|
|
|
request->data = data;
|
|
|
|
|
request->bytecount = count;
|
|
|
|
|
request->transfersize = min(request->bytecount, 65534);
|
|
|
|
|
request->flags = flags | ATA_R_ATAPI;
|
|
|
|
|
request->timeout = timeout;
|
|
|
|
|
ata_queue_request(request);
|
|
|
|
|
error = request->result;
|
|
|
|
|
ata_free_request(request);
|
|
|
|
|
}
|
|
|
|
|
return error;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
|
ata_start(struct ata_channel *ch)
|
|
|
|
|
{
|
|
|
|
|
struct ata_request *request;
|
|
|
|
|
|
2004-01-11 22:08:34 +00:00
|
|
|
|
/* if in immediate mode, just skip start requests (stall queue) */
|
|
|
|
|
if (ch->flags & ATA_IMMEDIATE_MODE)
|
|
|
|
|
return;
|
|
|
|
|
|
2003-08-24 09:22:26 +00:00
|
|
|
|
/* lock the ATA HW for this request */
|
2004-01-28 20:38:51 +00:00
|
|
|
|
mtx_lock(&ch->queue_mtx);
|
2003-08-24 09:22:26 +00:00
|
|
|
|
ch->locking(ch, ATA_LF_LOCK);
|
|
|
|
|
if (!ATA_LOCK_CH(ch, ATA_ACTIVE)) {
|
2004-01-28 20:38:51 +00:00
|
|
|
|
mtx_unlock(&ch->queue_mtx);
|
2003-08-24 09:22:26 +00:00
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* if we dont have any work, ask the subdriver(s) */
|
|
|
|
|
if (TAILQ_EMPTY(&ch->ata_queue)) {
|
|
|
|
|
mtx_unlock(&ch->queue_mtx);
|
|
|
|
|
if (ch->device[MASTER].start)
|
|
|
|
|
ch->device[MASTER].start(&ch->device[MASTER]);
|
|
|
|
|
if (ch->device[SLAVE].start)
|
|
|
|
|
ch->device[SLAVE].start(&ch->device[SLAVE]);
|
|
|
|
|
mtx_lock(&ch->queue_mtx);
|
|
|
|
|
}
|
|
|
|
|
if ((request = TAILQ_FIRST(&ch->ata_queue))) {
|
|
|
|
|
TAILQ_REMOVE(&ch->ata_queue, request, chain);
|
|
|
|
|
mtx_unlock(&ch->queue_mtx);
|
|
|
|
|
|
2004-01-11 22:08:34 +00:00
|
|
|
|
ATA_DEBUG_RQ(request, "starting");
|
|
|
|
|
|
2003-08-24 09:22:26 +00:00
|
|
|
|
/* arm timeout */
|
|
|
|
|
if (!request->timeout_handle.callout && !dumping) {
|
|
|
|
|
request->timeout_handle =
|
|
|
|
|
timeout((timeout_t*)ata_timeout, request, request->timeout*hz);
|
|
|
|
|
}
|
|
|
|
|
|
2004-01-28 20:38:51 +00:00
|
|
|
|
/* kick HW into action and wait for interrupt if it flies*/
|
2003-08-24 09:22:26 +00:00
|
|
|
|
if (ch->hw.transaction(request) == ATA_OP_CONTINUES)
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2004-01-28 20:38:51 +00:00
|
|
|
|
/* unlock ATA channel HW */
|
2003-08-24 09:22:26 +00:00
|
|
|
|
ATA_UNLOCK_CH(ch);
|
|
|
|
|
ch->locking(ch, ATA_LF_UNLOCK);
|
2004-01-28 20:38:51 +00:00
|
|
|
|
|
|
|
|
|
/* if we have a request here it failed and should be completed */
|
|
|
|
|
if (request)
|
|
|
|
|
ata_finish(request);
|
|
|
|
|
else
|
|
|
|
|
mtx_unlock(&ch->queue_mtx);
|
2003-08-24 09:22:26 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
|
ata_finish(struct ata_request *request)
|
|
|
|
|
{
|
2004-01-11 22:08:34 +00:00
|
|
|
|
ATA_DEBUG_RQ(request, "taskqueue completition");
|
|
|
|
|
|
2003-08-24 09:22:26 +00:00
|
|
|
|
/* request is done schedule it for completition */
|
2004-01-11 22:08:34 +00:00
|
|
|
|
if (request->device->channel->flags & ATA_IMMEDIATE_MODE) {
|
|
|
|
|
ata_completed(request, 0);
|
|
|
|
|
}
|
|
|
|
|
else {
|
2004-02-17 19:24:11 +00:00
|
|
|
|
if (request->bio && !(request->flags & ATA_R_TIMEOUT))
|
2004-01-28 20:38:51 +00:00
|
|
|
|
bio_taskqueue(request->bio, (bio_task_t *)ata_completed, request);
|
|
|
|
|
else {
|
|
|
|
|
TASK_INIT(&request->task, 0, ata_completed, request);
|
2004-02-17 19:24:11 +00:00
|
|
|
|
taskqueue_enqueue(taskqueue_thread, &request->task);
|
2004-01-28 20:38:51 +00:00
|
|
|
|
}
|
2004-01-11 22:08:34 +00:00
|
|
|
|
}
|
2003-08-24 09:22:26 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* current command finished, clean up and return result */
|
|
|
|
|
static void
|
2004-01-28 20:38:51 +00:00
|
|
|
|
ata_completed(void *context, int dummy)
|
2003-08-24 09:22:26 +00:00
|
|
|
|
{
|
|
|
|
|
struct ata_request *request = (struct ata_request *)context;
|
|
|
|
|
struct ata_channel *channel = request->device->channel;
|
|
|
|
|
|
2004-01-11 22:08:34 +00:00
|
|
|
|
ATA_DEBUG_RQ(request, "completed called");
|
2003-08-24 09:22:26 +00:00
|
|
|
|
|
2004-01-11 22:08:34 +00:00
|
|
|
|
if (request->flags & ATA_R_TIMEOUT) {
|
2003-08-24 09:22:26 +00:00
|
|
|
|
|
2004-01-30 19:16:08 +00:00
|
|
|
|
/* if negative retry count just give up and unlock channel HW */
|
|
|
|
|
if (request->retries < 0) {
|
2004-01-11 22:08:34 +00:00
|
|
|
|
if (!(request->flags & ATA_R_QUIET))
|
|
|
|
|
ata_prtdev(request->device,
|
2004-01-30 19:16:08 +00:00
|
|
|
|
"FAILURE - %s no interrupt\n",
|
2004-01-11 22:08:34 +00:00
|
|
|
|
ata_cmd2str(request));
|
|
|
|
|
request->result = EIO;
|
2004-01-30 19:16:08 +00:00
|
|
|
|
ATA_UNLOCK_CH(channel);
|
|
|
|
|
channel->locking(channel, ATA_LF_UNLOCK);
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
|
|
|
|
|
/* reset controller and devices */
|
|
|
|
|
ata_reinit(channel);
|
|
|
|
|
|
|
|
|
|
/* if retries still permit, reinject this request */
|
|
|
|
|
if (request->retries-- > 0) {
|
|
|
|
|
request->flags &= ~ATA_R_TIMEOUT;
|
|
|
|
|
request->flags |= (ATA_R_IMMEDIATE | ATA_R_REQUEUE);
|
|
|
|
|
ata_queue_request(request);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* otherwise just finish with error */
|
|
|
|
|
else {
|
|
|
|
|
if (!(request->flags & ATA_R_QUIET))
|
|
|
|
|
ata_prtdev(request->device,
|
|
|
|
|
"FAILURE - %s timed out\n",
|
|
|
|
|
ata_cmd2str(request));
|
|
|
|
|
request->result = EIO;
|
|
|
|
|
}
|
2004-01-11 22:08:34 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
/* untimeout request now we have control back */
|
|
|
|
|
untimeout((timeout_t *)ata_timeout, request, request->timeout_handle);
|
|
|
|
|
|
|
|
|
|
/* do the all the magic for completition evt retry etc etc */
|
|
|
|
|
if ((request->status & (ATA_S_CORR | ATA_S_ERROR)) == ATA_S_CORR) {
|
|
|
|
|
ata_prtdev(request->device,
|
|
|
|
|
"WARNING - %s soft error (ECC corrected)",
|
|
|
|
|
ata_cmd2str(request));
|
|
|
|
|
if (!(request->flags & (ATA_R_ATAPI | ATA_R_CONTROL)))
|
|
|
|
|
printf(" LBA=%llu", (unsigned long long)request->u.ata.lba);
|
|
|
|
|
printf("\n");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* if this is a UDMA CRC error, retry request */
|
|
|
|
|
if (request->flags & ATA_R_DMA && request->error & ATA_E_ICRC) {
|
|
|
|
|
if (request->retries-- > 0) {
|
|
|
|
|
ata_prtdev(request->device,
|
|
|
|
|
"WARNING - %s UDMA ICRC error (retrying request)",
|
|
|
|
|
ata_cmd2str(request));
|
|
|
|
|
if (!(request->flags & (ATA_R_ATAPI | ATA_R_CONTROL)))
|
|
|
|
|
printf(" LBA=%llu", (unsigned long long)request->u.ata.lba);
|
|
|
|
|
printf("\n");
|
2004-01-19 15:20:00 +00:00
|
|
|
|
request->flags |= (ATA_R_IMMEDIATE | ATA_R_REQUEUE);
|
2004-01-11 22:08:34 +00:00
|
|
|
|
ata_queue_request(request);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
}
|
2003-08-24 09:22:26 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
switch (request->flags & ATA_R_ATAPI) {
|
2004-01-11 22:08:34 +00:00
|
|
|
|
|
2003-08-24 09:22:26 +00:00
|
|
|
|
/* ATA errors */
|
|
|
|
|
default:
|
|
|
|
|
if (request->status & ATA_S_ERROR) {
|
|
|
|
|
if (!(request->flags & ATA_R_QUIET)) {
|
|
|
|
|
ata_prtdev(request->device,
|
|
|
|
|
"FAILURE - %s status=%b error=%b",
|
|
|
|
|
ata_cmd2str(request),
|
|
|
|
|
request->status, "\20\10BUSY\7READY\6DMA_READY"
|
|
|
|
|
"\5DSC\4DRQ\3CORRECTABLE\2INDEX\1ERROR",
|
|
|
|
|
request->error, "\20\10ICRC\7UNCORRECTABLE"
|
|
|
|
|
"\6MEDIA_CHANGED\5NID_NOT_FOUND\4MEDIA_CHANGE_REQEST"
|
|
|
|
|
"\3ABORTED\2NO_MEDIA\1ILLEGAL_LENGTH");
|
2003-12-15 20:43:17 +00:00
|
|
|
|
if ((request->flags & ATA_R_DMA) &&
|
|
|
|
|
(request->dmastat & ATA_BMSTAT_ERROR))
|
|
|
|
|
printf(" dma=0x%02x", request->dmastat);
|
2004-01-11 22:08:34 +00:00
|
|
|
|
if (!(request->flags & (ATA_R_ATAPI | ATA_R_CONTROL)))
|
2003-12-16 19:41:38 +00:00
|
|
|
|
printf(" LBA=%llu", (unsigned long long)request->u.ata.lba);
|
2003-12-15 20:43:17 +00:00
|
|
|
|
printf("\n");
|
2003-08-24 09:22:26 +00:00
|
|
|
|
}
|
|
|
|
|
|
2003-08-28 08:22:53 +00:00
|
|
|
|
/* SOS this could be more precise ? XXX */
|
2003-08-24 09:22:26 +00:00
|
|
|
|
request->result = EIO;
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
/* ATAPI errors */
|
|
|
|
|
case ATA_R_ATAPI:
|
2003-09-18 09:22:14 +00:00
|
|
|
|
/* skip if result already set */
|
2003-08-24 09:22:26 +00:00
|
|
|
|
if (request->result)
|
|
|
|
|
break;
|
|
|
|
|
|
2004-02-28 17:47:27 +00:00
|
|
|
|
/* if we have a sensekey -> request sense from device */
|
|
|
|
|
if (request->error & ATA_SK_MASK &&
|
|
|
|
|
request->u.atapi.ccb[0] != ATAPI_REQUEST_SENSE) {
|
|
|
|
|
static u_int8_t ccb[16] = { ATAPI_REQUEST_SENSE, 0, 0, 0,
|
|
|
|
|
sizeof(struct atapi_sense),
|
|
|
|
|
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
|
|
|
|
|
|
|
|
|
|
bcopy(ccb, request->u.atapi.ccb, 16);
|
|
|
|
|
request->u.atapi.sense_key = request->error;
|
|
|
|
|
request->data = (caddr_t)&request->u.atapi.sense_data;
|
|
|
|
|
request->bytecount = sizeof(struct atapi_sense);
|
|
|
|
|
request->transfersize = sizeof(struct atapi_sense);
|
|
|
|
|
request->timeout = 5;
|
|
|
|
|
request->flags =
|
|
|
|
|
ATA_R_ATAPI | ATA_R_READ | ATA_R_IMMEDIATE | ATA_R_REQUEUE;
|
|
|
|
|
ata_queue_request(request);
|
|
|
|
|
return;
|
|
|
|
|
}
|
2003-08-24 09:22:26 +00:00
|
|
|
|
|
2004-02-28 17:47:27 +00:00
|
|
|
|
switch (request->u.atapi.sense_key & ATA_SK_MASK) {
|
|
|
|
|
case ATA_SK_RECOVERED_ERROR:
|
|
|
|
|
ata_prtdev(request->device, "WARNING - %s recovered error\n",
|
|
|
|
|
ata_cmd2str(request));
|
|
|
|
|
/* FALLTHROUGH */
|
2003-08-24 09:22:26 +00:00
|
|
|
|
|
2004-02-28 17:47:27 +00:00
|
|
|
|
case ATA_SK_NO_SENSE:
|
|
|
|
|
request->result = 0;
|
|
|
|
|
break;
|
2003-08-24 09:22:26 +00:00
|
|
|
|
|
2004-02-28 17:47:27 +00:00
|
|
|
|
case ATA_SK_NOT_READY:
|
|
|
|
|
request->result = EBUSY;
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case ATA_SK_UNIT_ATTENTION:
|
|
|
|
|
request->device->flags |= ATA_D_MEDIA_CHANGED;
|
|
|
|
|
request->result = EIO;
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
default:
|
|
|
|
|
request->result = EIO;
|
|
|
|
|
if (request->flags & ATA_R_QUIET)
|
2003-08-24 09:22:26 +00:00
|
|
|
|
break;
|
|
|
|
|
|
2004-02-28 17:47:27 +00:00
|
|
|
|
ata_prtdev(request->device,
|
|
|
|
|
"FAILURE - %s %s asc=0x%02x ascq=0x%02x ",
|
|
|
|
|
ata_cmd2str(request), ata_skey2str(
|
|
|
|
|
(request->u.atapi.sense_key & ATA_SK_MASK) >> 4),
|
|
|
|
|
request->u.atapi.sense_data.asc,
|
|
|
|
|
request->u.atapi.sense_data.ascq);
|
|
|
|
|
if (request->u.atapi.sense_data.sksv)
|
|
|
|
|
printf("sks=0x%02x 0x%02x 0x%02x ",
|
|
|
|
|
request->u.atapi.sense_data.sk_specific,
|
|
|
|
|
request->u.atapi.sense_data.sk_specific1,
|
|
|
|
|
request->u.atapi.sense_data.sk_specific2);
|
|
|
|
|
printf("status=%b error=%b\n",
|
|
|
|
|
request->status, "\20\10BUSY\7READY\6DMA"
|
|
|
|
|
"\5DSC\4DRQ\3CORRECTABLE\2INDEX\1ERROR",
|
|
|
|
|
(request->error & ATA_E_MASK),
|
|
|
|
|
"\20\4MEDIA_CHANGE_REQUEST\3ABORTED"
|
|
|
|
|
"\2NO_MEDIA\1ILLEGAL_LENGTH");
|
2003-08-24 09:22:26 +00:00
|
|
|
|
}
|
2004-02-28 17:47:27 +00:00
|
|
|
|
|
|
|
|
|
if (request->error & ATA_E_MASK)
|
|
|
|
|
request->result = EIO;
|
2003-08-24 09:22:26 +00:00
|
|
|
|
}
|
|
|
|
|
|
2004-01-11 22:08:34 +00:00
|
|
|
|
ATA_DEBUG_RQ(request, "completed callback/wakeup");
|
|
|
|
|
|
2003-08-24 09:22:26 +00:00
|
|
|
|
if (request->callback)
|
|
|
|
|
(request->callback)(request);
|
|
|
|
|
else
|
2004-01-11 22:08:34 +00:00
|
|
|
|
sema_post(&request->done);
|
|
|
|
|
|
2003-08-24 09:22:26 +00:00
|
|
|
|
ata_start(channel);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
ata_timeout(struct ata_request *request)
|
|
|
|
|
{
|
2004-01-11 22:08:34 +00:00
|
|
|
|
ATA_DEBUG_RQ(request, "timeout");
|
2003-10-14 16:53:13 +00:00
|
|
|
|
|
2003-08-24 09:22:26 +00:00
|
|
|
|
/* clear timeout etc */
|
|
|
|
|
request->timeout_handle.callout = NULL;
|
|
|
|
|
|
2004-01-11 22:08:34 +00:00
|
|
|
|
if (request->flags & ATA_R_INTR_SEEN) {
|
|
|
|
|
if (request->retries-- > 0) {
|
|
|
|
|
ata_prtdev(request->device,
|
|
|
|
|
"WARNING - %s interrupt was seen but timeout fired",
|
|
|
|
|
ata_cmd2str(request));
|
|
|
|
|
if (!(request->flags & (ATA_R_ATAPI | ATA_R_CONTROL)))
|
|
|
|
|
printf(" LBA=%llu", (unsigned long long)request->u.ata.lba);
|
|
|
|
|
printf("\n");
|
|
|
|
|
|
|
|
|
|
/* re-arm timeout */
|
|
|
|
|
if (!request->timeout_handle.callout && !dumping) {
|
|
|
|
|
request->timeout_handle =
|
|
|
|
|
timeout((timeout_t*)ata_timeout, request,
|
|
|
|
|
request->timeout * hz);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
ata_prtdev(request->device,
|
|
|
|
|
"WARNING - %s interrupt was seen but taskqueue stalled",
|
2003-08-24 09:22:26 +00:00
|
|
|
|
ata_cmd2str(request));
|
2004-01-11 22:08:34 +00:00
|
|
|
|
if (!(request->flags & (ATA_R_ATAPI | ATA_R_CONTROL)))
|
|
|
|
|
printf(" LBA=%llu", (unsigned long long)request->u.ata.lba);
|
|
|
|
|
printf("\n");
|
|
|
|
|
ata_completed(request, 0);
|
|
|
|
|
}
|
2003-08-24 09:22:26 +00:00
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2003-10-07 13:47:40 +00:00
|
|
|
|
/* report that we timed out */
|
2004-01-30 19:16:08 +00:00
|
|
|
|
if (!(request->flags & ATA_R_QUIET) && request->retries > 0) {
|
2003-10-07 13:47:40 +00:00
|
|
|
|
ata_prtdev(request->device,
|
2004-01-11 22:08:34 +00:00
|
|
|
|
"TIMEOUT - %s retrying (%d retr%s left)",
|
2003-10-07 13:47:40 +00:00
|
|
|
|
ata_cmd2str(request), request->retries,
|
|
|
|
|
request->retries == 1 ? "y" : "ies");
|
2004-01-11 22:08:34 +00:00
|
|
|
|
if (!(request->flags & (ATA_R_ATAPI | ATA_R_CONTROL)))
|
|
|
|
|
printf(" LBA=%llu", (unsigned long long)request->u.ata.lba);
|
|
|
|
|
printf("\n");
|
2003-10-07 13:47:40 +00:00
|
|
|
|
}
|
|
|
|
|
|
2004-01-11 22:08:34 +00:00
|
|
|
|
/* now simulate the missing interrupt */
|
|
|
|
|
request->flags |= ATA_R_TIMEOUT;
|
|
|
|
|
request->device->channel->hw.interrupt(request->device->channel);
|
|
|
|
|
return;
|
2003-08-24 09:22:26 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
char *
|
|
|
|
|
ata_cmd2str(struct ata_request *request)
|
|
|
|
|
{
|
|
|
|
|
static char buffer[20];
|
|
|
|
|
|
|
|
|
|
if (request->flags & ATA_R_ATAPI) {
|
|
|
|
|
switch (request->u.atapi.ccb[0]) {
|
|
|
|
|
case 0x00: return ("TEST_UNIT_READY");
|
|
|
|
|
case 0x01: return ("REZERO");
|
|
|
|
|
case 0x03: return ("REQUEST_SENSE");
|
|
|
|
|
case 0x04: return ("FORMAT");
|
|
|
|
|
case 0x08: return ("READ");
|
|
|
|
|
case 0x0a: return ("WRITE");
|
|
|
|
|
case 0x10: return ("WEOF");
|
|
|
|
|
case 0x11: return ("SPACE");
|
2003-09-19 12:46:12 +00:00
|
|
|
|
case 0x12: return ("INQUIRY");
|
2003-08-24 09:22:26 +00:00
|
|
|
|
case 0x15: return ("MODE_SELECT");
|
|
|
|
|
case 0x19: return ("ERASE");
|
|
|
|
|
case 0x1a: return ("MODE_SENSE");
|
|
|
|
|
case 0x1b: return ("START_STOP");
|
|
|
|
|
case 0x1e: return ("PREVENT_ALLOW");
|
|
|
|
|
case 0x23: return ("ATAPI_READ_FORMAT_CAPACITIES");
|
|
|
|
|
case 0x25: return ("READ_CAPACITY");
|
|
|
|
|
case 0x28: return ("READ_BIG");
|
|
|
|
|
case 0x2a: return ("WRITE_BIG");
|
|
|
|
|
case 0x2b: return ("LOCATE");
|
|
|
|
|
case 0x34: return ("READ_POSITION");
|
|
|
|
|
case 0x35: return ("SYNCHRONIZE_CACHE");
|
|
|
|
|
case 0x3b: return ("WRITE_BUFFER");
|
|
|
|
|
case 0x3c: return ("READ_BUFFER");
|
|
|
|
|
case 0x42: return ("READ_SUBCHANNEL");
|
|
|
|
|
case 0x43: return ("READ_TOC");
|
|
|
|
|
case 0x45: return ("PLAY_10");
|
|
|
|
|
case 0x47: return ("PLAY_MSF");
|
|
|
|
|
case 0x48: return ("PLAY_TRACK");
|
|
|
|
|
case 0x4b: return ("PAUSE");
|
|
|
|
|
case 0x51: return ("READ_DISK_INFO");
|
|
|
|
|
case 0x52: return ("READ_TRACK_INFO");
|
|
|
|
|
case 0x53: return ("RESERVE_TRACK");
|
|
|
|
|
case 0x54: return ("SEND_OPC_INFO");
|
|
|
|
|
case 0x55: return ("MODE_SELECT_BIG");
|
|
|
|
|
case 0x58: return ("REPAIR_TRACK");
|
|
|
|
|
case 0x59: return ("READ_MASTER_CUE");
|
|
|
|
|
case 0x5a: return ("MODE_SENSE_BIG");
|
|
|
|
|
case 0x5b: return ("CLOSE_TRACK/SESSION");
|
|
|
|
|
case 0x5c: return ("READ_BUFFER_CAPACITY");
|
|
|
|
|
case 0x5d: return ("SEND_CUE_SHEET");
|
|
|
|
|
case 0xa1: return ("BLANK_CMD");
|
|
|
|
|
case 0xa3: return ("SEND_KEY");
|
|
|
|
|
case 0xa4: return ("REPORT_KEY");
|
|
|
|
|
case 0xa5: return ("PLAY_12");
|
|
|
|
|
case 0xa6: return ("LOAD_UNLOAD");
|
|
|
|
|
case 0xad: return ("READ_DVD_STRUCTURE");
|
|
|
|
|
case 0xb4: return ("PLAY_CD");
|
|
|
|
|
case 0xbb: return ("SET_SPEED");
|
|
|
|
|
case 0xbd: return ("MECH_STATUS");
|
|
|
|
|
case 0xbe: return ("READ_CD");
|
|
|
|
|
case 0xff: return ("POLL_DSC");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
switch (request->u.ata.command) {
|
|
|
|
|
case 0x00: return ("NOP");
|
|
|
|
|
case 0x08: return ("ATAPI_RESET");
|
|
|
|
|
case 0x20: return ("READ");
|
|
|
|
|
case 0x24: return ("READ48");
|
|
|
|
|
case 0x25: return ("READ_DMA48");
|
|
|
|
|
case 0x26: return ("READ_DMA_QUEUED48");
|
|
|
|
|
case 0x29: return ("READ_MUL48");
|
|
|
|
|
case 0x30: return ("WRITE");
|
|
|
|
|
case 0x34: return ("WRITE48");
|
|
|
|
|
case 0x35: return ("WRITE_DMA48");
|
|
|
|
|
case 0x36: return ("WRITE_DMA_QUEUED48");
|
|
|
|
|
case 0x39: return ("WRITE_MUL48");
|
|
|
|
|
case 0xa0: return ("PACKET_CMD");
|
|
|
|
|
case 0xa1: return ("ATAPI_IDENTIFY");
|
|
|
|
|
case 0xa2: return ("SERVICE");
|
|
|
|
|
case 0xc4: return ("READ_MUL");
|
|
|
|
|
case 0xc5: return ("WRITE_MUL");
|
|
|
|
|
case 0xc6: return ("SET_MULTI");
|
|
|
|
|
case 0xc7: return ("READ_DMA_QUEUED");
|
|
|
|
|
case 0xc8: return ("READ_DMA");
|
|
|
|
|
case 0xca: return ("WRITE_DMA");
|
|
|
|
|
case 0xcc: return ("WRITE_DMA_QUEUED");
|
|
|
|
|
case 0xe6: return ("SLEEP");
|
|
|
|
|
case 0xe7: return ("FLUSHCACHE");
|
|
|
|
|
case 0xea: return ("FLUSHCACHE48");
|
|
|
|
|
case 0xec: return ("ATA_IDENTIFY");
|
2004-01-11 22:08:34 +00:00
|
|
|
|
case 0xef:
|
|
|
|
|
switch (request->u.ata.feature) {
|
|
|
|
|
case 0x03: return ("SETFEATURES SET TRANSFER MODE");
|
|
|
|
|
case 0x02: return ("SETFEATURES ENABLE WCACHE");
|
|
|
|
|
case 0x82: return ("SETFEATURES DISABLE WCACHE");
|
|
|
|
|
case 0xaa: return ("SETFEATURES ENABLE RCACHE");
|
|
|
|
|
case 0x55: return ("SETFEATURES DISABLE RCACHE");
|
|
|
|
|
}
|
|
|
|
|
sprintf(buffer, "SETFEATURES 0x%02x", request->u.ata.feature);
|
|
|
|
|
return buffer;
|
2003-08-24 09:22:26 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
sprintf(buffer, "unknown CMD (0x%02x)", request->u.ata.command);
|
|
|
|
|
return buffer;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static char *
|
2003-09-18 09:22:14 +00:00
|
|
|
|
ata_skey2str(u_int8_t skey)
|
2003-08-24 09:22:26 +00:00
|
|
|
|
{
|
|
|
|
|
switch (skey) {
|
|
|
|
|
case 0x00: return ("NO SENSE");
|
|
|
|
|
case 0x01: return ("RECOVERED ERROR");
|
|
|
|
|
case 0x02: return ("NOT READY");
|
|
|
|
|
case 0x03: return ("MEDIUM ERROR");
|
|
|
|
|
case 0x04: return ("HARDWARE ERROR");
|
|
|
|
|
case 0x05: return ("ILLEGAL REQUEST");
|
|
|
|
|
case 0x06: return ("UNIT ATTENTION");
|
|
|
|
|
case 0x07: return ("DATA PROTECT");
|
|
|
|
|
case 0x08: return ("BLANK CHECK");
|
|
|
|
|
case 0x09: return ("VENDOR SPECIFIC");
|
|
|
|
|
case 0x0a: return ("COPY ABORTED");
|
|
|
|
|
case 0x0b: return ("ABORTED COMMAND");
|
|
|
|
|
case 0x0c: return ("EQUAL");
|
|
|
|
|
case 0x0d: return ("VOLUME OVERFLOW");
|
|
|
|
|
case 0x0e: return ("MISCOMPARE");
|
|
|
|
|
case 0x0f: return ("RESERVED");
|
|
|
|
|
default: return("UNKNOWN");
|
|
|
|
|
}
|
|
|
|
|
}
|