Skip to contentSkip to conversation

LibATA SCSI WRITE_BUFFER to ATA DOWNLOAD_MICROCODE patch

PATCH [email protected] 6 participants 7 messages Apr 1, 2009 – Apr 3, 2009 libata

lore
Share & tools
lore
#0 lore raw

Attach is a patch that adds translation of scsi WRITE_BUFFER to ATA_DOWNLOAD_MICROCODE command. This patch enables firmware flashing of sata drives that are registered as scsi devices under linux; hence scsi to ata translation is needed. This patch provides the translation.

Imran Salim
Hewlett Pacakrd Company
Houston, TX
(281) 514-1531

drivers/ata/libata-scsi.c +75 -0
diff -burp linux-2.6.16.60-0.21/drivers/ata/libata-scsi.c linux-2.6.16.60-0.21.ver1.[coderefactor]/drivers/ata/libata-scsi.c
@@ -1417,6 +1417,78 @@ nothing_to_do:
 	return 1;
 }
 
+/*
+ *	ata_scsi_write_buffer_xlat - Translates SCSI 'Write Buffer' command
+ *	into ATA equivalent 'Download Microcode' command. This function is
+ *	implemented according to following spec.
+ * 		Working Draft American National Standard Information Technology
+ *	 	SCSI/ATA Translation-2 (SAT-2)
+ *	 	T10/1826-D Rev 5 Date: June 22, 2008
+ *	@qc: Storage for translated ATA taskfile
+ *
+ *	RETURNS:
+ *	Zero on success, non-zero on error.
+ */
+static unsigned int ata_scsi_write_buffer_xlat(struct ata_queued_cmd *qc)
+{
+	/* scsi */
+	int mode = 0;
+	int buff_id = 0;
+	int buff_offset = 0;
+	int parm_list_len = 0;
+
+	/* ata */
+	int n_sect = 0;
+
+	struct scsi_cmnd *scmd = qc->scsicmd;
+	const u8 *cdb = scmd->cmnd;
+	struct ata_taskfile *tf = &qc->tf;
+
+	mode = cdb[1] & 0x07; /* First 3 bits 0x07=00000111 */
+	buff_id = cdb[2];
+
+	buff_offset |= cdb[3] << 24;
+	buff_offset |= cdb[4] << 16;
+	buff_offset |= cdb[5];
+
+	parm_list_len |= cdb[6] << 16;
+	parm_list_len |= cdb[7] << 8;
+	parm_list_len |= cdb[8];
+
+	n_sect = parm_list_len / ATA_SECT_SIZE;
+	qc->nsect = n_sect;
+
+	tf->nsect =  n_sect & 0xff;
+	tf->lbal  = (n_sect >> 8) & 0xff;
+	tf->flags |= ATA_TFLAG_DEVICE | ATA_TFLAG_ISADDR | ATA_TFLAG_WRITE;
+
+	switch (mode) {
+	case 0x02:
+		if (buff_id == 0 && buff_offset == 0 && parm_list_len == 512) {
+			tf->command = ATA_CMD_WRITE_BUFFER;
+			tf->protocol = ATA_PROT_PIO;
+		} else {
+			ata_scsi_set_sense(scmd, ILLEGAL_REQUEST, 0x24, 0x0);
+		}
+		break;
+	case 0x05:
+		tf->command = ATA_CMD_DOWNLOAD_MICROCODE;
+		tf->protocol = ATA_PROT_PIO;
+		tf->feature = 7;
+		break;
+	case 0x07:
+		tf->command = ATA_CMD_DOWNLOAD_MICROCODE;
+		tf->protocol = ATA_PROT_PIO;
+		tf->feature = 3;
+		break;
+	default:
+		ata_scsi_set_sense(scmd, ILLEGAL_REQUEST, 0x24, 0x0);
+		return 1;
+	}
+
+	return 0;
+}
+
 static void ata_scsi_qc_complete(struct ata_queued_cmd *qc)
 {
 	struct ata_port *ap = qc->ap;
@@ -2730,6 +2802,9 @@ static inline ata_xlat_func_t ata_get_xl
 	case WRITE_16:
 		return ata_scsi_rw_xlat;
 
+	case WRITE_BUFFER:
+		return ata_scsi_write_buffer_xlat;
+
 	case SYNCHRONIZE_CACHE:
 		if (ata_try_flush_cache(dev))
 			return ata_scsi_flush_xlat;
include/linux/ata.h +2 -0
diff -burp linux-2.6.16.60-0.21/include/linux/ata.h linux-2.6.16.60-0.21.ver1.[coderefactor]/include/linux/ata.h
@@ -130,6 +130,7 @@ enum {
 	ATA_CMD_STANDBY		= 0xE2, /* place in standby power mode */
 	ATA_CMD_IDLE		= 0xE3, /* place in idle power mode */
 	ATA_CMD_EDD		= 0x90,	/* execute device diagnostic */
+	ATA_CMD_DOWNLOAD_MICROCODE = 0x92,
 	ATA_CMD_FLUSH		= 0xE7,
 	ATA_CMD_FLUSH_EXT	= 0xEA,
 	ATA_CMD_ID_ATA		= 0xEC,
@@ -150,6 +151,7 @@ enum {
 	ATA_CMD_WRITE_MULTI	= 0xC5,
 	ATA_CMD_WRITE_MULTI_EXT	= 0x39,
 	ATA_CMD_WRITE_MULTI_FUA_EXT = 0xCE,
+	ATA_CMD_WRITE_BUFFER	= 0xE8,
 	ATA_CMD_SET_FEATURES	= 0xEF,
 	ATA_CMD_PACKET		= 0xA0,
 	ATA_CMD_VERIFY		= 0x40,
#1 lore raw
Quoted 1 line · On Wed, 2009-04-01 at 15:51 -0500, [email protected] wrote:

+ mode = cdb[1] & 0x07; /* First 3 bits 0x07=00000111 */

SPC-3 defines this field as 5 bits; SPC-2 defined it as 4; it was only the ancient SPC standard that defined it as three.

I think you need to up this to 5 bits otherwise you might get interference from line verification attempts using the echo buffer (which is defined as mode 10 ... and would translate to 2 if you just believe the first 3 bits).

James

#2 lore raw
In reply to [email protected]

A signature block with the company name misspelled.

I'd look real close at the patch.

Quoted 8 lines · On Wed, Apr 1, 2009 at 4:51 PM, <[email protected]> wrote:

Attach is a patch that adds translation of scsi WRITE_BUFFER to ATA_DOWNLOAD_MICROCODE command. This patch enables firmware flashing of sata drives that are registered as scsi devices under linux; hence scsi to ata translation is needed. This patch provides the translation.

Imran Salim
Hewlett Pacakrd Company
Houston, TX
(281) 514-1531

Signature · 10 lines
Greg Freemyer
Head of EDD Tape Extraction and Processing team
Litigation Triage Solutions Specialist
http://www.linkedin.com/in/gregfreemyer
First 99 Days Litigation White Paper -
http://www.norcrossgroup.com/forms/whitepapers/99%20Days%20whitepaper.pdf

The Norcross Group
The Intersection of Evidence & Technology
http://www.norcrossgroup.com
#3 lore raw
In reply to [email protected]
Quoted 11 lines

-----Original Message-----
From: [email protected] [mailto:[email protected]]
Sent: Wednesday, April 01, 2009 3:51 PM
To: [email protected]
Cc: [email protected]; [email protected]; Miller, Mike (OS Dev); Cameron, Steve
Subject: LibATA SCSI WRITE_BUFFER to ATA DOWNLOAD_MICROCODE patch

Quoted 1 line

Attach is a patch that adds translation of scsi WRITE_BUFFER

Never send patches as attachments. You're fortunate anyone bothered to look at it. Always send patches inline from a mail client that does not munge up the test.

-- mikem

Quoted 11 lines

to ATA_DOWNLOAD_MICROCODE command. This patch enables firmware flashing of sata drives that are registered as scsi devices under linux; hence scsi to ata translation is needed. This patch provides the translation.

Imran Salim
Hewlett Pacakrd Company
Houston, TX
(281) 514-1531

#4 lore raw
In reply to [email protected]
Quoted 1 line · [email protected] wrote:

Attach is a patch that adds translation of scsi WRITE_BUFFER to ATA_DOWNLOAD_MICROCODE command.\

..

Do we really need or want this extra code in-kernel?

This type of thing is already doable from user-space with SG_IO + ATA_16. Eg. hdparm --fwdownload

???

#5 lore raw
Quoted 8 lines · Mark Lord
Quoted 1 line · [email protected] wrote:

Attach is a patch that adds translation of scsi WRITE_BUFFER to ATA_DOWNLOAD_MICROCODE command.\

..

Do we really need or want this extra code in-kernel?

This type of thing is already doable from user-space with SG_IO + ATA_16. Eg. hdparm --fwdownload

If it can be done in userspace, I don't see much reason to add emulation in libata-scsi.c...

Jeff

#6 lore raw
Quoted 6 lines · Jeff Garzik
Quoted 5 lines · Mark Lord
Quoted 2 lines · [email protected] wrote:

Attach is a patch that adds translation of scsi WRITE_BUFFER to ATA_DOWNLOAD_MICROCODE command.\

..

Quoted 7 lines
Quoted 4 lines

Do we really need or want this extra code in-kernel?

This type of thing is already doable from user-space with SG_IO + ATA_16. Eg. hdparm --fwdownload

If it can be done in userspace, I don't see much reason to add emulation in libata-scsi.c...

The only reason I might be able to see it isn't for firmware download, agreed, since nothing in the kernel would ever use it.

If were were going to add some type of domain validation to the lines in SAS/SATA using write buffer echo tests, it might be more plausible, but that isn't the purpose of the patch.

James