Skip to contentSkip to conversation

libata: (round 5) add support for ATA_16 on ATAPI

PATCH In review Mark Lord 2 participants 4 messages Feb 2, 2007 – Mar 4, 2007 libata

lore
Share & tools
lore

Mark Lord

author
#0 lore raw

PATCH 1/1 libata: (round 5) add support for ATA_16 on ATAPI

Resending, with a bug fixed, and default ata16_passthru=0.

This patch adds support for issuing ATA_16 passthru commands to ATAPI devices managed by libata. It requires the previous CDB length fix patch.

A boot/module parameter, "ata16_passthru=1" can be used to globally disable this feature, if ever desired.

---

drivers/ata/libata-core.c +0 -0
diff -u --recursive --new-file --exclude-from=old/Documentation/dontdiff old/drivers/ata/libata-core.c new/drivers/ata/libata-core.c
@@ -82,6 +82,10 @@

module_param(atapi_dmadir, int, 0444);
MODULE_PARM_DESC(atapi_dmadir, "Enable ATAPI DMADIR bridge support (0=off, 1=on)");

+int ata16_passthru = 0;
+module_param(ata16_passthru, int, 0444);
+MODULE_PARM_DESC(ata16_passthru, "Enable passthru of SCSI opcode 0x85 to ATAPI devices (0=off, 1=on)"); +
int libata_fua = 0;
module_param_named(fua, libata_fua, int, 0444);
MODULE_PARM_DESC(fua, "FUA support (0=off, 1=on)");

drivers/ata/libata-scsi.c +0 -0
diff -u --recursive --new-file --exclude-from=old/Documentation/dontdiff old/drivers/ata/libata-scsi.c new/drivers/ata/libata-scsi.c
@@ -2688,6 +2688,10 @@
 

static inline ata_xlat_func_t ata_get_xlat_func(struct ata_device *dev, u8 cmd) {
+ if (dev->class == ATA_DEV_ATAPI)
+ if (cmd != ATA_16 || ata16_passthru)
+ return atapi_xlat;
+

	switch (cmd) {
	case READ_6:
	case READ_10:

@@ -2746,27 +2750,28 @@
void (*done)(struct scsi_cmnd *), struct ata_device *dev)
{
- int rc = 0;
-
- if (unlikely(!scmd->cmd_len || scmd->cmd_len > dev->cdb_len)) {
- DPRINTK("bad CDB len=%u, max=%u\n",
- scmd->cmd_len, dev->cdb_len);
+ ata_xlat_func_t xlat_func;
+ int rc = 0, max_len;
+ u8 scsi_op = scmd->cmnd[0];
+
+ if (scsi_op == ATA_16 && dev->class == ATA_DEV_ATAPI && !ata16_passthru)
+ max_len = 16;
+ else
+ max_len = dev->cdb_len;
+ + if (unlikely(!scmd->cmd_len || scmd->cmd_len > max_len)) {
+ DPRINTK("bad CDB len=%u, max=%u\n",

+ 			scmd->cmd_len, max_len);
		scmd->result = DID_ERROR << 16;
		done(scmd);
		return 0;
	}

- if (dev->class == ATA_DEV_ATA) {
- ata_xlat_func_t xlat_func = ata_get_xlat_func(dev,
- scmd->cmnd[0]);
-
- if (xlat_func)
- rc = ata_scsi_translate(dev, scmd, done, xlat_func);
- else
- ata_scsi_simulate(dev, scmd, done);
- } else
- rc = ata_scsi_translate(dev, scmd, done, atapi_xlat);
-
+ xlat_func = ata_get_xlat_func(dev, scsi_op);
+ if (xlat_func)
+ rc = ata_scsi_translate(dev, scmd, done, xlat_func);
+ else

+		ata_scsi_simulate(dev, scmd, done);
	return rc;
}
drivers/ata/libata.h +0 -0
diff -u --recursive --new-file --exclude-from=old/Documentation/dontdiff old/drivers/ata/libata.h new/drivers/ata/libata.h
@@ -47,6 +47,7 @@

extern struct workqueue_struct *ata_aux_wq;
extern int atapi_enabled;
extern int atapi_dmadir;
+extern int ata16_passthru;
extern int libata_fua;
extern struct ata_queued_cmd *ata_qc_new_init(struct ata_device *dev); extern int ata_build_rw_tf(struct ata_taskfile *tf, struct ata_device *dev,

#1 lore raw
Quoted 51 lines · Mark Lord

Resending, with a bug fixed, and default ata16_passthru=0.

This patch adds support for issuing ATA_16 passthru commands to ATAPI devices managed by libata. It requires the previous CDB length fix patch.

A boot/module parameter, "ata16_passthru=1" can be used to globally disable this feature, if ever desired.

---
diff -u --recursive --new-file --exclude-from=old/Documentation/dontdiff old/drivers/ata/libata-core.c new/drivers/ata/libata-core.c

drivers/ata/libata-core.c 2007-02-02 12:29:03.000000000 -0500 renamed from drivers/ata/libata-core.c 2007-02-02 12:29:10.000000000 -0500 +4 -0
@@ -82,6 +82,10 @@
 module_param(atapi_dmadir, int, 0444);
 MODULE_PARM_DESC(atapi_dmadir, "Enable ATAPI DMADIR bridge support (0=off, 1=on)");
 
+int ata16_passthru = 0;
+module_param(ata16_passthru, int, 0444);
+MODULE_PARM_DESC(ata16_passthru, "Enable passthru of SCSI opcode 0x85 
 to ATAPI devices (0=off, 1=on)");
+
 int libata_fua = 0;
 module_param_named(fua, libata_fua, int, 0444);

MODULE_PARM_DESC(fua, "FUA support (0=off, 1=on)");
diff -u --recursive --new-file --exclude-from=old/Documentation/dontdiff old/drivers/ata/libata-scsi.c new/drivers/ata/libata-scsi.c

drivers/ata/libata-scsi.c 2007-02-02 12:29:25.000000000 -0500 renamed from drivers/ata/libata-scsi.c 2007-02-02 12:29:10.000000000 -0500 +6 -5
@@ -2688,6 +2688,10 @@
 
 static inline ata_xlat_func_t ata_get_xlat_func(struct ata_device *dev, u8 cmd)
 {
+    if (dev->class == ATA_DEV_ATAPI)
+        if (cmd != ATA_16 || ata16_passthru)
+            return atapi_xlat;
+
    switch (cmd) {
    case READ_6:
    case READ_10:
@@ -2746,27 +2750,28 @@
                      void (*done)(struct scsi_cmnd *),
                      struct ata_device *dev)
 {
-    int rc = 0;
-
-    if (unlikely(!scmd->cmd_len || scmd->cmd_len > dev->cdb_len)) {
-        DPRINTK("bad CDB len=%u, max=%u\n",
-            scmd->cmd_len, dev->cdb_len);
+    ata_xlat_func_t xlat_func;
+    int rc = 0, max_len;

drivers/ata/libata-scsi.c 2007-02-02 12:29:25.000000000 -0500 line 2764

Quoted 10 lines
drivers/ata/libata-scsi.c 2007-02-02 12:29:25.000000000 -0500 renamed from drivers/ata/libata-scsi.c 2007-02-02 12:29:10.000000000 -0500 +9 -0
+    u8 scsi_op = scmd->cmnd[0];
+
+    if (scsi_op == ATA_16 && dev->class == ATA_DEV_ATAPI && 
 !ata16_passthru)
+        max_len = 16;
+    else
+        max_len = dev->cdb_len;
+ +    if (unlikely(!scmd->cmd_len || scmd->cmd_len > max_len)) {
+         DPRINTK("bad CDB len=%u, max=%u\n",
+             scmd->cmd_len, max_len);

looks like a chompified patch (double '+')

Quoted 12 lines
drivers/ata/libata-scsi.c 2007-02-02 12:29:25.000000000 -0500 renamed from drivers/ata/libata-scsi.c 2007-02-02 12:29:10.000000000 -0500 +0 -7
        scmd->result = DID_ERROR << 16;
        done(scmd);
        return 0;
    }
 
-    if (dev->class == ATA_DEV_ATA) {
-        ata_xlat_func_t xlat_func = ata_get_xlat_func(dev,
-                                  scmd->cmnd[0]);
-
-        if (xlat_func)
-            rc = ata_scsi_translate(dev, scmd, done, xlat_func);
-        else

drivers/ata/libata-scsi.c 2007-02-02 12:29:25.000000000 -0500 line 2775

Quoted 10 lines
drivers/ata/libata-scsi.c 2007-02-02 12:29:25.000000000 -0500 renamed from drivers/ata/libata-scsi.c 2007-02-02 12:29:10.000000000 -0500 +5 -4
-            ata_scsi_simulate(dev, scmd, done);
-    } else
-        rc = ata_scsi_translate(dev, scmd, done, atapi_xlat);
-
+    xlat_func = ata_get_xlat_func(dev, scsi_op);
+    if (xlat_func)
+        rc = ata_scsi_translate(dev, scmd, done, xlat_func);
+    else
+        ata_scsi_simulate(dev, scmd, done);
    return rc;

this looks like a bug? ata_scsi_simulate() should not be called for ATAPI devices.

author
#2 lore raw
Quoted 1 line · Jeff Garzik

Mark Lord wrote:

....

Quoted 10 lines

Review

Quoted 8 lines

+ if (scsi_op == ATA_16 && dev->class == ATA_DEV_ATAPI &&
!ata16_passthru)

(quoted diff) +6 -0
+        max_len = 16;
+    else
+        max_len = dev->cdb_len;
+ +    if (unlikely(!scmd->cmd_len || scmd->cmd_len > max_len)) {
+         DPRINTK("bad CDB len=%u, max=%u\n",
+             scmd->cmd_len, max_len);

looks like a chompified patch (double '+')

Yup. Chompified. There used to be a blank line above that one. I must have hit enter or something while editing the email.

Will resend.
...

Quoted 9 lines

Review

Quoted 6 lines
(quoted diff) +5 -0
+    xlat_func = ata_get_xlat_func(dev, scsi_op);
+    if (xlat_func)
+        rc = ata_scsi_translate(dev, scmd, done, xlat_func);
+    else
+        ata_scsi_simulate(dev, scmd, done);
    return rc;

this looks like a bug? ata_scsi_simulate() should not be called for ATAPI devices.

Notabug. ata_get_xlat_func will always return either atapi_xlat or ata_scsi_pass_thru for ATAPI devices.

Cheers

author
#3 lore raw

PATCH 1/1 libata: (round 6) add support for ATA_16 on ATAPI

Resending, with extra '+' fixed.
Patch is against 2.6.21-rc2.

This patch adds support for issuing ATA_16 passthru commands to ATAPI devices managed by libata. It requires the previous CDB length fix patch.

A boot/module parameter, "ata16_passthru=1" can be used to globally disable this feature, if ever desired.

--- diff -u --recursive --new-file --exclude-from=old/Documentation/dontdiff old/drivers/ata/libata-core.c new/drivers/ata/libata-core.c

drivers/ata/libata-core.c +0 -0
@@ -82,6 +82,10 @@

module_param(atapi_dmadir, int, 0444);
MODULE_PARM_DESC(atapi_dmadir, "Enable ATAPI DMADIR bridge support (0=off, 1=on)");

+int ata16_passthru = 0;
+module_param(ata16_passthru, int, 0444);
+MODULE_PARM_DESC(ata16_passthru, "Enable passthru of SCSI opcode 0x85 to ATAPI devices (0=off, 1=on)"); +
int libata_fua = 0;
module_param_named(fua, libata_fua, int, 0444);
MODULE_PARM_DESC(fua, "FUA support (0=off, 1=on)");

drivers/ata/libata-scsi.c +0 -0
diff -u --recursive --new-file --exclude-from=old/Documentation/dontdiff old/drivers/ata/libata-scsi.c new/drivers/ata/libata-scsi.c
@@ -2688,6 +2688,10 @@
 

static inline ata_xlat_func_t ata_get_xlat_func(struct ata_device *dev, u8 cmd) {
+ if (dev->class == ATA_DEV_ATAPI)
+ if (cmd != ATA_16 || ata16_passthru)
+ return atapi_xlat;
+

	switch (cmd) {
	case READ_6:
	case READ_10:

@@ -2746,27 +2750,28 @@
void (*done)(struct scsi_cmnd *), struct ata_device *dev)
{
- int rc = 0;
-
- if (unlikely(!scmd->cmd_len || scmd->cmd_len > dev->cdb_len)) {
- DPRINTK("bad CDB len=%u, max=%u\n",
- scmd->cmd_len, dev->cdb_len);
+ ata_xlat_func_t xlat_func;
+ int rc = 0, max_len;
+ u8 scsi_op = scmd->cmnd[0];
+
+ if (scsi_op == ATA_16 && dev->class == ATA_DEV_ATAPI && !ata16_passthru)
+ max_len = 16;
+ else
+ max_len = dev->cdb_len;
+ + if (unlikely(!scmd->cmd_len || scmd->cmd_len > max_len)) {
+ DPRINTK("bad CDB len=%u, max=%u\n",

+ 			scmd->cmd_len, max_len);
		scmd->result = DID_ERROR << 16;
		done(scmd);
		return 0;
	}

- if (dev->class == ATA_DEV_ATA) {
- ata_xlat_func_t xlat_func = ata_get_xlat_func(dev,
- scmd->cmnd[0]);
-
- if (xlat_func)
- rc = ata_scsi_translate(dev, scmd, done, xlat_func);
- else
- ata_scsi_simulate(dev, scmd, done);
- } else
- rc = ata_scsi_translate(dev, scmd, done, atapi_xlat);
-
+ xlat_func = ata_get_xlat_func(dev, scsi_op);
+ if (xlat_func)
+ rc = ata_scsi_translate(dev, scmd, done, xlat_func);
+ else

+		ata_scsi_simulate(dev, scmd, done);
	return rc;
}
drivers/ata/libata.h +0 -0
diff -u --recursive --new-file --exclude-from=old/Documentation/dontdiff old/drivers/ata/libata.h new/drivers/ata/libata.h
@@ -47,6 +47,7 @@

extern struct workqueue_struct *ata_aux_wq;
extern int atapi_enabled;
extern int atapi_dmadir;
+extern int ata16_passthru;
extern int libata_fua;
extern struct ata_queued_cmd *ata_qc_new_init(struct ata_device *dev); extern int ata_build_rw_tf(struct ata_taskfile *tf, struct ata_device *dev,