linux-ide.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Jeff Garzik <jgarzik@pobox.com>
To: linux-ide@vger.kernel.org
Cc: Pat LaVarre <p.lavarre@ieee.org>
Subject: [PATCH] atapi request sense work
Date: Tue, 18 May 2004 19:48:10 -0400	[thread overview]
Message-ID: <40AAA0BA.9040307@pobox.com> (raw)
In-Reply-To: <1084920024.3191.8.camel@patibmrh9>

[-- Attachment #1: Type: text/plain, Size: 56 bytes --]

I don't necessarily expect this work, but we'll see...


[-- Attachment #2: patch --]
[-- Type: text/plain, Size: 5523 bytes --]

===== drivers/scsi/libata-core.c 1.64 vs edited =====
--- 1.64/drivers/scsi/libata-core.c	Mon May 17 19:39:49 2004
+++ edited/drivers/scsi/libata-core.c	Tue May 18 19:45:10 2004
@@ -2162,6 +2162,79 @@
 	}
 }
 
+static void atapi_error(struct ata_queued_cmd *qc)
+{
+	struct ata_port *ap = qc->ap;
+	struct ata_taskfile tf;
+	struct scsi_cmnd *cmd = qc->scsicmd;
+	u8 status;
+	u16 len;
+	const u8 request_sense_cdb[16] = {
+		REQUEST_SENSE, 0, 0, 0, SCSI_SENSE_BUFFERSIZE,
+	};
+
+	ata_tf_init(ap, &tf, qc->dev->devno);
+	tf.flags |= ATA_TFLAG_ISADDR | ATA_TFLAG_DEVICE;
+	tf.protocol = ATA_PROT_ATAPI;
+	tf.ctl |= ATA_NIEN;
+	tf.lbam = SCSI_SENSE_BUFFERSIZE & 0xff;
+	tf.command = ATA_CMD_PACKET;
+	ata_tf_to_host(ap, &tf);
+
+	if (ata_busy_sleep(ap, ATA_TMOUT_CDB_QUICK, ATA_TMOUT_CDB))
+		goto err_out;
+
+	status = ata_chk_status(ap);
+	if ((status & ATA_DRQ) == 0)
+		goto err_out;
+
+	/* FIXME: mmio-ize */
+	DPRINTK("send cdb\n");
+	outsl(ap->ioaddr.data_addr, request_sense_cdb,
+	      ap->host->max_cmd_len / 4);
+
+	if (ata_busy_sleep(ap, ATA_TMOUT_CDB_QUICK, ATA_TMOUT_CDB))
+		goto err_out;
+
+	status = ata_chk_status(ap);
+	if ((status & ATA_DRQ) == 0)
+		goto err_out;
+
+	ap->ops->tf_read(ap, &tf);
+	len = tf.lbam;
+	len |= ((u16)tf.lbah) << 8;
+
+	if (len % 4)
+		printk(KERN_WARNING "ata%u: odd ATAPI length %u\n",
+		       ap->id, len);
+	memset(cmd->sense_buffer, 0, sizeof(cmd->sense_buffer));
+	insl(ap->ioaddr.data_addr, cmd->sense_buffer, len / 4);
+
+	if ((cmd->sense_buffer[0] & 0x7e) != 0x70) {
+		u8 err = ata_chk_err(ap);
+		cmd->sense_buffer[0] = 0xf0;
+		cmd->sense_buffer[2] = err >> 4;
+	}
+
+	if (ata_busy_sleep(ap, ATA_TMOUT_CDB_QUICK, ATA_TMOUT_CDB))
+		goto err_out;
+
+	ata_irq_on(ap);
+
+out:
+	cmd->result = SAM_STAT_CHECK_CONDITION;
+	qc->scsidone(cmd);
+	return;
+
+err_out:
+	ata_irq_on(ap); /* re-enable interrupts */
+	cmd->sense_buffer[0] = 0xf0;
+	cmd->sense_buffer[2] = HARDWARE_ERROR;
+	cmd->sense_buffer[7] = 14 - 8;  /* addnl. sense len. FIXME: correct? */
+	cmd->sense_buffer[12] = 0x8; /* logical unit comm failure */
+	goto out;
+}
+
 /**
  *	ata_eng_timeout - Handle timeout of queued command
  *	@ap: Port on which timed-out command is active
@@ -2185,6 +2258,7 @@
 {
 	u8 host_stat, drv_stat;
 	struct ata_queued_cmd *qc;
+	int check_cond = 0;
 
 	DPRINTK("ENTER\n");
 
@@ -2195,16 +2269,30 @@
 		goto out;
 	}
 
-	/* hack alert!  We cannot use the supplied completion
-	 * function from inside the ->eh_strategy_handler() thread.
-	 * libata is the only user of ->eh_strategy_handler() in
-	 * any kernel, so the default scsi_done() assumes it is
-	 * not being called from the SCSI EH.
-	 */
-	qc->scsidone = scsi_finish_command;
+	if (qc->scsicmd) {
+		check_cond = !(qc->scsicmd->eh_eflags & SCSI_EH_CANCEL_CMD);
+
+		/* hack alert!  We cannot use the supplied completion
+		 * function from inside the ->eh_strategy_handler() thread.
+		 * libata is the only user of ->eh_strategy_handler() in
+		 * any kernel, so the default scsi_done() assumes it is
+		 * not being called from the SCSI EH.
+		 */
+		qc->scsidone = scsi_finish_command;
+	}
+
+	/* ATAPI devices */
+	if (qc->dev->class == ATA_DEV_ATAPI) {
+		if (check_cond) {
+			atapi_error(qc);
+			goto out;
+		}
+	}
 
+	/* ATA devices */
 	switch (qc->tf.protocol) {
 	case ATA_PROT_DMA:
+	case ATA_PROT_ATAPI_DMA:
 		if (ap->flags & ATA_FLAG_MMIO) {
 			void *mmio = (void *) ap->ioaddr.bmdma_addr;
 			host_stat = readb(mmio + ATA_DMA_STATUS);
@@ -2217,6 +2305,7 @@
 		ata_dma_complete(qc, host_stat);
 		break;
 
+	case ATA_PROT_ATAPI:
 	case ATA_PROT_NODATA:
 		drv_stat = ata_busy_wait(ap, ATA_BUSY | ATA_DRQ, 1000);
 
@@ -2317,15 +2406,23 @@
 	assert(qc != NULL);	/* ata_qc_from_tag _might_ return NULL */
 	assert(qc->flags & ATA_QCFLAG_ACTIVE);
 
-	if (likely(qc->flags & ATA_QCFLAG_SG))
+	if (likely(qc->flags & ATA_QCFLAG_SG)) {
 		ata_sg_clean(qc);
+		qc->flags &= ~ATA_QCFLAG_SG;
+	}
 
 	if (cmd) {
 		if (unlikely(drv_stat & (ATA_ERR | ATA_BUSY | ATA_DRQ))) {
-			if (is_atapi_taskfile(&qc->tf))
+			if (is_atapi_taskfile(&qc->tf)) {
 				cmd->result = SAM_STAT_CHECK_CONDITION;
-			else
-				ata_to_sense_error(qc);
+				qc->scsidone(cmd);
+				return;
+				/* error handler thread takes
+				 * over from here
+				 */
+			}
+
+			ata_to_sense_error(qc);
 		} else {
 			cmd->result = SAM_STAT_GOOD;
 		}
===== drivers/scsi/libata-scsi.c 1.37 vs edited =====
--- 1.37/drivers/scsi/libata-scsi.c	Mon May 17 19:39:49 2004
+++ edited/drivers/scsi/libata-scsi.c	Tue May 18 19:43:54 2004
@@ -137,7 +137,7 @@
 
 	cmd->result = SAM_STAT_CHECK_CONDITION;
 
-	cmd->sense_buffer[0] = 0x70;
+	cmd->sense_buffer[0] = 0xf0;
 	cmd->sense_buffer[2] = MEDIUM_ERROR;
 	cmd->sense_buffer[7] = 14 - 8;	/* addnl. sense len. FIXME: correct? */
 
@@ -927,7 +927,7 @@
 	DPRINTK("ENTER\n");
 	cmd->result = SAM_STAT_CHECK_CONDITION;
 
-	cmd->sense_buffer[0] = 0x70;
+	cmd->sense_buffer[0] = 0xf0;
 	cmd->sense_buffer[2] = ILLEGAL_REQUEST;
 	cmd->sense_buffer[7] = 14 - 8;	/* addnl. sense len. FIXME: correct? */
 	cmd->sense_buffer[12] = asc;
===== drivers/scsi/libata.h 1.15 vs edited =====
--- 1.15/drivers/scsi/libata.h	Sun May 16 21:33:12 2004
+++ edited/drivers/scsi/libata.h	Tue May 18 19:02:12 2004
@@ -28,6 +28,10 @@
 #define DRV_NAME	"libata"
 #define DRV_VERSION	"1.02"	/* must be exactly four chars */
 
+#ifndef SCSI_EH_CANCEL_CMD
+#define SCSI_EH_CANCEL_CMD	0x0001	/* Cancel this cmd */
+#endif /* SCSI_EH_CANCEL_CMD */
+
 struct ata_scsi_args {
 	struct ata_port		*ap;
 	struct ata_device	*dev;

  parent reply	other threads:[~2004-05-18 23:48 UTC|newest]

Thread overview: 67+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2004-05-16 14:19 [PATCH] libata DMADIR support Pat LaVarre
2004-05-16 23:16 ` Jeff Garzik
2004-05-17 18:48   ` Pat LaVarre
2004-05-17 19:08     ` Jeff Garzik
2004-05-17 21:06       ` Pat LaVarre
2004-05-17 21:40         ` Jeff Garzik
2004-05-17 21:20       ` Pat LaVarre
2004-05-17 21:32         ` Jeff Garzik
2004-05-17 21:34           ` Jeff Garzik
2004-05-17 22:05           ` Pat LaVarre
2004-05-17 22:36             ` Jeff Garzik
2004-05-17 23:04               ` Pat LaVarre
2004-05-18 22:40               ` Pat LaVarre
2004-05-18 23:07                 ` Pat LaVarre
2004-05-18 23:50                   ` Jeff Garzik
2004-05-19 22:47                     ` Pat LaVarre
2004-05-18 23:48                 ` Jeff Garzik [this message]
2004-05-19 20:35                   ` [PATCH] atapi request sense work Pat LaVarre
2004-05-19 22:19                     ` Jeff Garzik
2004-05-19 22:24                   ` Pat LaVarre
2004-05-19 22:27                     ` Pat LaVarre
2004-05-19 22:54                   ` Pat LaVarre
2004-05-21  1:58                     ` Pat LaVarre
     [not found]                       ` <6 E36A 11B-AACB-11D8-8B8A-003065635034@ieee.org>
2004-05-21  2:06                       ` Pat LaVarre
2004-05-21  3:05                         ` Pat LaVarre
2004-05-21  4:04                           ` Jeff Garzik
     [not found]                             ` <1 085153750.6103.33.camel@patibmrh9>
2004-05-21 15:35                             ` Pat LaVarre
2004-05-21 15:46                               ` Bartlomiej Zolnierkiewicz
2004-05-21 17:59                                 ` Pat LaVarre
2004-05-21 20:07                                   ` Pat LaVarre
2004-05-21 21:51                                     ` Jeff Garzik
2004-05-21 23:12                                       ` Pat LaVarre
2004-05-21 23:24                                       ` Pat LaVarre
2004-05-21 23:55                                         ` Jeff Garzik
2004-05-21 23:57                                           ` Pat LaVarre
2004-05-21 23:39                                       ` Pat LaVarre
2004-05-21 23:45                                         ` Jeff Garzik
2004-05-22  0:06                                           ` Pat LaVarre
2004-05-22  0:12                                             ` Pat LaVarre
2004-05-22  0:33                                           ` Pat LaVarre
2004-05-22  1:11                                             ` Pat LaVarre
2004-05-26 21:49                                               ` Pat LaVarre
2004-05-27 23:12                                                 ` Pat LaVarre
2004-05-27 23:32                                                   ` Jeff Garzik
2004-05-27 23:38                                                     ` Pat LaVarre
2004-05-27 23:41                                                       ` Jeff Garzik
2004-05-28  0:13                                                     ` Pat LaVarre
2004-05-28  1:28                                                   ` Pat LaVarre
2004-05-24 15:27                                             ` Pat LaVarre
2004-05-21 21:59                                   ` Pat LaVarre
2004-05-21 18:23                                 ` Danny Cox
2004-05-21 18:39                                   ` Bartlomiej Zolnierkiewicz
2004-05-21 18:55                                     ` [PATCH] kmalloc old_hwif Danny Cox
2004-05-21 19:00                                     ` [PATCH] atapi request sense work Danny Cox
2004-05-21 19:08                                       ` Bartlomiej Zolnierkiewicz
  -- strict thread matches above, loose matches on Subject: below --
2004-05-21 18:45 dwm
2004-05-21 20:44 ` Pat LaVarre
2004-05-30 12:44 Pat LaVarre
2004-05-30 15:15 ` Pat LaVarre
2004-05-31 16:09   ` Pat LaVarre
2004-06-02  0:01     ` Pat LaVarre
2004-06-02 20:52       ` Pat LaVarre
2004-06-02 22:36         ` Pat LaVarre
2004-06-02 22:55           ` Jeff Garzik
2004-06-02 23:53           ` Pat LaVarre
2004-06-03  0:30             ` Pat LaVarre
2004-06-03  0:52               ` Jeff Garzik

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=40AAA0BA.9040307@pobox.com \
    --to=jgarzik@pobox.com \
    --cc=linux-ide@vger.kernel.org \
    --cc=p.lavarre@ieee.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).