Skip to contentSkip to conversation

Snoop SET FEATURES - WRITE CACHE ENABLE/DISABLE command

PATCH Superseded zhao, forrest 2 participants 3 messages May 30, 2006 – May 31, 2006

Subsystems (2)

v2 of 5 Superseded Latest is v5 →

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 Snoop SET FEATURES - WRITE CACHE ENABLE/DISABLE command

Hi, all

This is the revised version according to comments from Jeff, Tejun and Mark.

Compared with last version, the changes are:

1 in ata_scsi_qc_complete(), remove the code of checking cdb[0] for ATA_12/16

2 in ata_eh_revalidate(), scsi_rescan_device() is scheduled whether the "write cache enable bit" has changed or not.

Note:
This patch has some code duplication with Tejun's hotplug patch set, here I post the complete patch in order for anyone to test it and report bugs.

Thanks,
Forrest

The patch is against #upstream ef2824073fba9def3cf122e89cc485f66dd71f70

drivers/scsi/libata-core.c +2 -0
index 11df827..27f6023 100644
@@ -69,6 +69,8 @@ static void ata_dev_xfermask(struct ata_
 static unsigned int ata_unique_id = 1;
 static struct workqueue_struct *ata_wq;
 
+struct workqueue_struct *ata_scsi_wq;
+
 int atapi_enabled = 1;
 module_param(atapi_enabled, int, 0444);
 MODULE_PARM_DESC(atapi_enabled, "Enable discovery of ATAPI devices

(0=off, 1=on)");
@@ -5188,6 +5190,8 @@ static void ata_host_init(struct ata_por
ap->msg_enable = ATA_MSG_DRV;

INIT_WORK(&ap->port_task, NULL, NULL);
+ INIT_WORK(&ap->scsi_rescan_task, ata_scsi_dev_rescan, ap);
+
INIT_LIST_HEAD(&ap->eh_done_q);

/* set cable type */
@@ -5593,6 +5597,12 @@ static int __init ata_init(void)
if (!ata_wq)
return -ENOMEM;

+ ata_scsi_wq = create_singlethread_workqueue("ata_scsi");
+ if (!ata_scsi_wq) {
+ destroy_workqueue(ata_wq);
+ return -ENOMEM;
+ }
+
printk(KERN_DEBUG "libata version " DRV_VERSION " loaded.\n"); return 0;
}
@@ -5600,6 +5610,8 @@ static int __init ata_init(void)
static void __exit ata_exit(void)
{
destroy_workqueue(ata_wq);
+ destroy_workqueue(ata_scsi_wq);
+
}

module_init(ata_init);

drivers/scsi/libata-eh.c +2 -0
index 71b45ad..0622ad5 100644
@@ -1356,6 +1356,8 @@ static int ata_eh_revalidate(struct ata_
 			if (rc)
 				break;
 
+			/* schedule the scsi_rescan_device() here */
+			queue_work(ata_scsi_wq, &(ap->scsi_rescan_task));
 			ehc->i.action &= ~ATA_EH_REVALIDATE;
 		}
 	}
drivers/scsi/libata-scsi.c +34 -1
index 9e5cb9f..810f42e 100644
@@ -1269,6 +1269,17 @@ static void ata_scsi_qc_complete(struct 
 	u8 *cdb = cmd->cmnd;
  	int need_sense = (qc->err_mask != 0);
 
+	/* We snoop the SET_FEATURES - Write Cache ON/OFF command, and
+	 * schedule EH_REVALIDATE operation to update the IDENTIFY DEVICE
+	 * cache
+	 */
+	if ((!(cdb[2] & 0x20)) && (qc->tf.command == ATA_CMD_SET_FEATURES) &&
+	    ((qc->tf.feature == SETFEATURES_WC_ON) ||
+	     (qc->tf.feature == SETFEATURES_WC_OFF))) {
+		qc->ap->eh_info.action = ATA_EH_REVALIDATE;
+		ata_port_schedule_eh(qc->ap);
+	}
+
 	/* For ATA pass thru (SAT) commands, generate a sense block if
 	 * user mandated it or if there's an error.  Note that if we
 	 * generate because the user forced us to, a check condition
@@ -2744,9 +2755,31 @@ void ata_scsi_scan_host(struct ata_port 
 		return;
 
 	for (i = 0; i < ATA_MAX_DEVICES; i++) {
+		struct scsi_device *sdev;
+		dev = &ap->device[i];
+
+		if (!ata_dev_enabled(dev) || dev->sdev)
+			continue;
+		sdev = __scsi_add_device(ap->host, 0, i, 0, NULL);
+		if(!IS_ERR(sdev)){
+			dev->sdev = sdev;
+			scsi_device_put(sdev);
+		}
+	}
+}
+
+void ata_scsi_dev_rescan(void *data)
+{
+	struct ata_port *ap = data;
+	struct ata_device *dev;
+	unsigned int i;
+
+	for (i = 0; i < ATA_MAX_DEVICES; i++) {
+
 		dev = &ap->device[i];
 
 		if (ata_dev_enabled(dev))
-			scsi_scan_target(&ap->host->shost_gendev, 0, i, 0, 0);
+			scsi_rescan_device(&(dev->sdev->sdev_gendev));
 	}
 }
+
drivers/scsi/libata.h +1 -0
index b76ad7d..352d332 100644
@@ -39,6 +39,7 @@ struct ata_scsi_args {
 };
 
 /* libata-core.c */
+extern struct workqueue_struct *ata_scsi_wq;
 extern int atapi_enabled;
 extern int atapi_dmadir;
 extern int libata_fua;
@@ -99,6 +100,7 @@ extern void ata_scsi_rbuf_fill(struct at
                         unsigned int (*actor) (struct ata_scsi_args

*args,
u8 *rbuf, unsigned int
buflen));
extern void ata_schedule_scsi_eh(struct Scsi_Host *shost);
+extern void ata_scsi_dev_rescan(void *data);

/* libata-eh.c */
extern enum scsi_eh_timer_return ata_scsi_timed_out(struct scsi_cmnd
*cmd);

include/linux/ata.h +3 -0
index c494e1c..3671af8 100644
@@ -181,6 +181,9 @@ enum {
 	XFER_PIO_0		= 0x08,
 	XFER_PIO_SLOW		= 0x00,
 
+	SETFEATURES_WC_ON	= 0x02, /* Enable write cache */
+	SETFEATURES_WC_OFF	= 0x82, /* Disable write cache */
+
 	/* ATAPI stuff */
 	ATAPI_PKT_DMA		= (1 << 0),
 	ATAPI_DMADIR		= (1 << 2),	/* ATAPI data dir:
include/linux/libata.h +2 -1
index b0ee1c1..9cccb22 100644
@@ -402,6 +402,7 @@ struct ata_device {
 	unsigned long		flags;		/* ATA_DFLAG_xxx */
 	unsigned int		class;		/* ATA_DEV_xxx */
 	unsigned int		devno;		/* 0 or 1 */
+	struct scsi_device	*sdev;		/* attached SCSI device */
 	u16			id[ATA_ID_WORDS]; /* IDENTIFY xxx DEVICE data */
 	u8			pio_mode;
 	u8			dma_mode;
@@ -484,7 +485,7 @@ struct ata_port {
 	struct ata_host_set	*host_set;
 	struct device 		*dev;
 
-	struct work_struct	port_task;
+	struct work_struct	port_task, scsi_rescan_task;
 
 	unsigned int		hsm_task_state;
 
#1 lore raw

Hello, Zhao.

zhao, forrest wrote:
[--snip--]

drivers/scsi/libata-scsi.c static void ata_scsi_qc_complete(struct · line 1276

Quoted 13 lines
drivers/scsi/libata-scsi.c +5 -0
index 9e5cb9f..810f42e 100644
@@ -1269,6 +1269,17 @@ static void ata_scsi_qc_complete(struct 
 	u8 *cdb = cmd->cmnd;
  	int need_sense = (qc->err_mask != 0);
 
+	/* We snoop the SET_FEATURES - Write Cache ON/OFF command, and
+	 * schedule EH_REVALIDATE operation to update the IDENTIFY DEVICE
+	 * cache
+	 */
+	if ((!(cdb[2] & 0x20)) && (qc->tf.command == ATA_CMD_SET_FEATURES) &&

!(cdb[2] & 0x20) seems out of place, and revalidation should be scheduled only when the qc is completing successfully. ie. !need_sense, but if used that way the variable name doesn't make much sense. IMHO, renaming it to something like failed would be better.

drivers/scsi/libata-scsi.c static void ata_scsi_qc_complete(struct · line 1279

Quoted 3 lines
drivers/scsi/libata-scsi.c +3 -0
+	    ((qc->tf.feature == SETFEATURES_WC_ON) ||
+	     (qc->tf.feature == SETFEATURES_WC_OFF))) {
+		qc->ap->eh_info.action = ATA_EH_REVALIDATE;

Please do action |= ATA_EH_REVALIDATE. Also, above schedules revalidation for both devices for a PATA port. Currently, there is no way to specify which device is offending from qc completion path. I'll submit a patch to allow it. After the patch, please add qc->ap->eh_info.dev = qc->dev such that only the affected device is revalidated.

Thanks.

Signature · 1 line
tejun
#2 lore raw
Quoted 10 lines · Tejun Heo

drivers/scsi/libata-scsi.c static void ata_scsi_qc_complete(struct · line 1279

Quoted 3 lines
drivers/scsi/libata-scsi.c +3 -0
+	    ((qc->tf.feature == SETFEATURES_WC_ON) ||
+	     (qc->tf.feature == SETFEATURES_WC_OFF))) {
+		qc->ap->eh_info.action = ATA_EH_REVALIDATE;

Please do action |= ATA_EH_REVALIDATE. Also, above schedules revalidation for both devices for a PATA port. Currently, there is no way to specify which device is offending from qc completion path. I'll submit a patch to allow it. After the patch, please add qc->ap->eh_info.dev = qc->dev such that only the affected device is revalidated.

Please forget about the qc->ap->eh_info.dev = qc->dev stuff. At the second thought, it doesn't seem worth the trouble and seems safer as it currently is.

Signature · 1 line
tejun