linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [patch libata-dev-2.6 1/5] libata: fix command queue leak when xlat_func fails
@ 2005-02-18 19:50 John W. Linville
  2005-02-18 19:55 ` [patch libata-dev-2.6 2/5] libata: sync SMART ioctls with ATA pass thru spec (T10/04-262r7) John W. Linville
  2005-02-18 20:50 ` [patch libata-dev-2.6 1/5] libata: fix command queue leak when xlat_func fails Jeff Garzik
  0 siblings, 2 replies; 6+ messages in thread
From: John W. Linville @ 2005-02-18 19:50 UTC (permalink / raw)
  To: linux-ide; +Cc: linux-kernel, jgarzik

ata_scsi_translate allocates from the libata command queue by calling
ata_scsi_qc_new.  If xlat_func returns non-zero, control jumps to
err_out which fails to free the allocated command.  Fix is to add a
new API to free unused commands.

Signed-off-by: John W. Linville <linville@tuxdriver.com>
---

 drivers/scsi/libata-core.c |   18 ++++++++++++++++++
 drivers/scsi/libata-scsi.c |    1 +
 drivers/scsi/libata.h      |    1 +
 3 files changed, 20 insertions(+)

--- sata-smart-2.6/drivers/scsi/libata-scsi.c.bugfix	2005-02-17 16:47:04.992924055 -0500
+++ sata-smart-2.6/drivers/scsi/libata-scsi.c	2005-02-17 16:48:48.265138198 -0500
@@ -967,6 +967,7 @@ static void ata_scsi_translate(struct at
 	return;
 
 err_out:
+	ata_qc_free(qc);
 	ata_bad_cdb(cmd, done);
 	DPRINTK("EXIT - badcmd\n");
 }
--- sata-smart-2.6/drivers/scsi/libata-core.c.bugfix	2005-02-17 16:46:44.659638355 -0500
+++ sata-smart-2.6/drivers/scsi/libata-core.c	2005-02-17 16:48:48.269137664 -0500
@@ -2687,6 +2687,24 @@ static void __ata_qc_complete(struct ata
 }
 
 /**
+ *	ata_qc_free - free unused ata_queued_cmd
+ *	@qc: Command to complete
+ *
+ *	Designed to free unused ata_queued_cmd object
+ *	in case something prevents using it.
+ *
+ *	LOCKING:
+ *
+ */
+void ata_qc_free(struct ata_queued_cmd *qc)
+{
+	assert(qc != NULL);	/* ata_qc_from_tag _might_ return NULL */
+	assert(qc->waiting == NULL);	/* nothing should be waiting */
+
+	__ata_qc_complete(qc);
+}
+
+/**
  *	ata_qc_complete - Complete an active ATA command
  *	@qc: Command to complete
  *	@drv_stat: ATA status register contents
--- sata-smart-2.6/drivers/scsi/libata.h.bugfix	2005-02-17 16:46:47.630241808 -0500
+++ sata-smart-2.6/drivers/scsi/libata.h	2005-02-17 16:48:48.306132726 -0500
@@ -37,6 +37,7 @@ struct ata_scsi_args {
 /* libata-core.c */
 extern struct ata_queued_cmd *ata_qc_new_init(struct ata_port *ap,
 				      struct ata_device *dev);
+extern void ata_qc_free(struct ata_queued_cmd *qc);
 extern int ata_qc_issue(struct ata_queued_cmd *qc);
 extern int ata_check_atapi_dma(struct ata_queued_cmd *qc);
 extern int ata_task_ioctl(struct scsi_device *scsidev, void __user *arg);
-- 
John W. Linville
linville@tuxdriver.com

^ permalink raw reply	[flat|nested] 6+ messages in thread

* [patch libata-dev-2.6 2/5] libata: sync SMART ioctls with ATA pass thru spec (T10/04-262r7)
  2005-02-18 19:50 [patch libata-dev-2.6 1/5] libata: fix command queue leak when xlat_func fails John W. Linville
@ 2005-02-18 19:55 ` John W. Linville
  2005-02-18 20:03   ` [patch libata-dev-2.6 3/5] libata: filter SET_FEATURES - XFER MODE from ATA pass thru John W. Linville
  2005-02-18 20:50 ` [patch libata-dev-2.6 1/5] libata: fix command queue leak when xlat_func fails Jeff Garzik
  1 sibling, 1 reply; 6+ messages in thread
From: John W. Linville @ 2005-02-18 19:55 UTC (permalink / raw)
  To: linux-ide, linux-kernel, jgarzik

Minor modifications to the SMART-related ioctls in libata, in
compliance with the latest ATA pass thru spec (T10/04-262r7).

Signed-off-by: John W. Linville <linville@tuxdriver.com>
---

 drivers/scsi/libata-scsi.c |    6 ++++--
 1 files changed, 4 insertions(+), 2 deletions(-)

--- sata-smart-2.6/drivers/scsi/libata-scsi.c.orig	2005-02-01 16:24:01.687622085 -0500
+++ sata-smart-2.6/drivers/scsi/libata-scsi.c	2005-02-01 16:49:18.213876086 -0500
@@ -109,14 +109,16 @@ int ata_cmd_ioctl(struct scsi_device *sc
 			return -ENOMEM;
 
 		scsi_cmd[1]  = (4 << 1); /* PIO Data-in */
+		scsi_cmd[2]  = 0x0e;     /* no off.line or cc, read from dev,
+		                            block count in sector count field */
 		sreq->sr_data_direction = DMA_FROM_DEVICE;
 	} else {
 		scsi_cmd[1]  = (3 << 1); /* Non-data */
+		/* scsi_cmd[2] is already 0 -- no off.line, cc, or data xfer */
 		sreq->sr_data_direction = DMA_NONE;
 	}
 
 	scsi_cmd[0] = ATA_16;
-	scsi_cmd[2] = 0x1f;     /* no off.line or cc, yes all registers */
 
 	scsi_cmd[4] = args[2];
 	if (args[0] == WIN_SMART) { /* hack -- ide driver does this too... */
@@ -179,7 +181,7 @@ int ata_task_ioctl(struct scsi_device *s
 	memset(scsi_cmd, 0, sizeof(scsi_cmd));
 	scsi_cmd[0]  = ATA_16;
 	scsi_cmd[1]  = (3 << 1); /* Non-data */
-	scsi_cmd[2]  = 0x1f;     /* no off.line or cc, yes all registers */
+	/* scsi_cmd[2] is already 0 -- no off.line, cc, or data xfer */
 	scsi_cmd[4]  = args[1];
 	scsi_cmd[6]  = args[2];
 	scsi_cmd[8]  = args[3];
-- 
John W. Linville
linville@tuxdriver.com

^ permalink raw reply	[flat|nested] 6+ messages in thread

* [patch libata-dev-2.6 3/5] libata: filter SET_FEATURES - XFER MODE from ATA pass thru
  2005-02-18 19:55 ` [patch libata-dev-2.6 2/5] libata: sync SMART ioctls with ATA pass thru spec (T10/04-262r7) John W. Linville
@ 2005-02-18 20:03   ` John W. Linville
  2005-02-18 20:06     ` [patch libata-dev-2.6 4/5] libata: minor style changes in ata_scsi_pass_thru John W. Linville
  0 siblings, 1 reply; 6+ messages in thread
From: John W. Linville @ 2005-02-18 20:03 UTC (permalink / raw)
  To: linux-ide, linux-kernel, jgarzik

Filter-out attempts to issue a SET_FEATURES - XFER MODE command
via the ATA pass thru mechanism.

Signed-off-by: John W. Linville <linville@tuxdriver.com>
---

 drivers/scsi/libata-scsi.c |   11 +++++++++++
 1 files changed, 11 insertions(+)

--- sata-smart-2.6/drivers/scsi/libata-scsi.c.filter	2005-02-17 16:49:51.362715273 -0500
+++ sata-smart-2.6/drivers/scsi/libata-scsi.c	2005-02-17 16:50:03.907040725 -0500
@@ -1764,6 +1764,17 @@ ata_scsi_pass_thru(struct ata_queued_cmd
 	}
 
 	/*
+	 * Filter SET_FEATURES - XFER MODE command -- otherwise,
+	 * SET_FEATURES - XFER MODE must be preceded/succeeded
+	 * by an update to hardware-specific registers for each
+	 * controller (i.e. the reason for ->set_piomode(),
+	 * ->set_dmamode(), and ->post_set_mode() hooks).
+	 */
+	if ((tf->command == ATA_CMD_SET_FEATURES)
+	 && (tf->feature == SETFEATURES_XFER))
+		return 1;
+
+	/*
 	 * Set flags so that all registers will be written,
 	 * and pass on write indication (used for PIO/DMA
 	 * setup.)
-- 
John W. Linville
linville@tuxdriver.com

^ permalink raw reply	[flat|nested] 6+ messages in thread

* [patch libata-dev-2.6 4/5] libata: minor style changes in ata_scsi_pass_thru
  2005-02-18 20:03   ` [patch libata-dev-2.6 3/5] libata: filter SET_FEATURES - XFER MODE from ATA pass thru John W. Linville
@ 2005-02-18 20:06     ` John W. Linville
  2005-02-18 20:16       ` [patch libata-dev-2.6 5/5] libata: update ATA pass thru opcodes John W. Linville
  0 siblings, 1 reply; 6+ messages in thread
From: John W. Linville @ 2005-02-18 20:06 UTC (permalink / raw)
  To: linux-ide, linux-kernel, jgarzik

Remove some curlies around single-line if statements.

Signed-off-by: John W. Linville <linville@tuxdriver.com>
---

 drivers/scsi/libata-scsi.c |    9 +++------
 1 files changed, 3 insertions(+), 6 deletions(-)

--- sata-smart-2.6/drivers/scsi/libata-scsi.c.style	2005-02-17 16:50:03.907040725 -0500
+++ sata-smart-2.6/drivers/scsi/libata-scsi.c	2005-02-17 16:50:40.819113315 -0500
@@ -1713,9 +1713,8 @@ ata_scsi_pass_thru(struct ata_queued_cmd
 	struct ata_taskfile *tf = &(qc->tf);
 	struct scsi_cmnd *cmd = qc->scsicmd;
 
-	if ((tf->protocol = ata_scsi_map_proto(scsicmd[1])) == ATA_PROT_UNKNOWN) {
+	if ((tf->protocol = ata_scsi_map_proto(scsicmd[1])) == ATA_PROT_UNKNOWN)
 		return 1;
-	}
 
 	/*
 	 * 12 and 16 byte CDBs use different offsets to
@@ -1734,9 +1733,8 @@ ata_scsi_pass_thru(struct ata_queued_cmd
 			tf->hob_lbam = scsicmd[9];
 			tf->hob_lbah = scsicmd[11];
 			tf->flags |= ATA_TFLAG_LBA48 ;
-		} else {
+		} else
 			tf->flags &= ~ATA_TFLAG_LBA48 ;
-		}
 
 		/*
 		 * Always copy low byte, device and command registers.
@@ -1781,9 +1779,8 @@ ata_scsi_pass_thru(struct ata_queued_cmd
 	 */
 	tf->flags |= (ATA_TFLAG_ISADDR | ATA_TFLAG_DEVICE) ;
 
-	if (cmd->sc_data_direction == SCSI_DATA_WRITE) {
+	if (cmd->sc_data_direction == SCSI_DATA_WRITE)
 		tf->flags |= ATA_TFLAG_WRITE;
-	}
 
 	/*
 	 * Set transfer length.
-- 
John W. Linville
linville@tuxdriver.com

^ permalink raw reply	[flat|nested] 6+ messages in thread

* [patch libata-dev-2.6 5/5] libata: update ATA pass thru opcodes
  2005-02-18 20:06     ` [patch libata-dev-2.6 4/5] libata: minor style changes in ata_scsi_pass_thru John W. Linville
@ 2005-02-18 20:16       ` John W. Linville
  0 siblings, 0 replies; 6+ messages in thread
From: John W. Linville @ 2005-02-18 20:16 UTC (permalink / raw)
  To: linux-ide, linux-kernel, jgarzik

Update ATA pass thru opcodes to match what is specified in the current
ATA pass thru spec (T10/04-262r7).

Signed-off-by: John W. Linville <linville@tuxdriver.com>
---
This part was controversial before, because these opcodes seemed to
overlap with some existing opcodes.  So I contacted the author of
the spec, Curtis Stevens: (quoted without permision)

"The command values in 04-262r7 are correct.  There was an erroneous value
published in the minutes that subsequently got published in SPC.  This has
been corrected.

Command sets are supposed to be qualified by the Inquiry Peripheral Device
Type.  I am a little concerned that some portions of linux depend on opcodes
being the same for all PDTs.  Using reusing opcodes will continue to happen
more frequently as new applications emerge and new devices are created.  The
SCSI opcoded are already overloaded to the point that Service Actions have
become necessary to extend the protocol."

Honestly, I don't know if that clears things up or not.  But, Curtis
seems pretty adamant that the values in the patch below (which match
rev 7 of the spec) are correct.  IMHO, at worst these values are no
more wrong than the ones already there.

So, apply this now, or apply it later... :-)

 include/scsi/scsi.h |    6 +++---
 1 files changed, 3 insertions(+), 3 deletions(-)

--- sata-smart-2.6/include/scsi/scsi.h.orig	2005-02-01 16:22:12.390234346 -0500
+++ sata-smart-2.6/include/scsi/scsi.h	2005-02-01 16:23:02.828491161 -0500
@@ -113,9 +113,9 @@ extern const char *const scsi_device_typ
 /* values for service action in */
 #define	SAI_READ_CAPACITY_16  0x10
 
-/* Temporary values for T10/04-262 until official values are allocated */
-#define	ATA_16		      0x85	/* 16-byte pass-thru [0x85 == unused]*/
-#define	ATA_12		      0xb3	/* 12-byte pass-thru [0xb3 == obsolete set limits command] */
+/* Values for T10/04-262r7 */
+#define	ATA_16		      0x85	/* 16-byte pass-thru */
+#define	ATA_12		      0xa1	/* 12-byte pass-thru */
 
 /*
  *  SCSI Architecture Model (SAM) Status codes. Taken from SAM-3 draft
-- 
John W. Linville
linville@tuxdriver.com

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [patch libata-dev-2.6 1/5] libata: fix command queue leak when xlat_func fails
  2005-02-18 19:50 [patch libata-dev-2.6 1/5] libata: fix command queue leak when xlat_func fails John W. Linville
  2005-02-18 19:55 ` [patch libata-dev-2.6 2/5] libata: sync SMART ioctls with ATA pass thru spec (T10/04-262r7) John W. Linville
@ 2005-02-18 20:50 ` Jeff Garzik
  1 sibling, 0 replies; 6+ messages in thread
From: Jeff Garzik @ 2005-02-18 20:50 UTC (permalink / raw)
  To: John W. Linville; +Cc: linux-ide, linux-kernel

applied all five, thanks


^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2005-02-18 20:50 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2005-02-18 19:50 [patch libata-dev-2.6 1/5] libata: fix command queue leak when xlat_func fails John W. Linville
2005-02-18 19:55 ` [patch libata-dev-2.6 2/5] libata: sync SMART ioctls with ATA pass thru spec (T10/04-262r7) John W. Linville
2005-02-18 20:03   ` [patch libata-dev-2.6 3/5] libata: filter SET_FEATURES - XFER MODE from ATA pass thru John W. Linville
2005-02-18 20:06     ` [patch libata-dev-2.6 4/5] libata: minor style changes in ata_scsi_pass_thru John W. Linville
2005-02-18 20:16       ` [patch libata-dev-2.6 5/5] libata: update ATA pass thru opcodes John W. Linville
2005-02-18 20:50 ` [patch libata-dev-2.6 1/5] libata: fix command queue leak when xlat_func fails Jeff Garzik

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).