All of lore.kernel.org
 help / color / mirror / Atom feed
* LibATA SCSI WRITE_BUFFER to ATA DOWNLOAD_MICROCODE patch
@ 2009-04-01 20:51 salimmu
  2009-04-01 21:11 ` James Bottomley
                   ` (3 more replies)
  0 siblings, 4 replies; 7+ messages in thread
From: salimmu @ 2009-04-01 20:51 UTC (permalink / raw)
  To: linux-ide; +Cc: jgarzik, scameron, mike.miller, steve.cameron

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

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


[-- Attachment #2: linux-2.6.16.60-0.21-atawritebuffer.patch --]
[-- Type: text/plain, Size: 3465 bytes --]

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
--- linux-2.6.16.60-0.21/drivers/ata/libata-scsi.c	2009-03-06 07:45:22.000000000 -0500
+++ linux-2.6.16.60-0.21.ver1.[coderefactor]/drivers/ata/libata-scsi.c	2009-03-09 08:15:36.000000000 -0400
@@ -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;
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
--- linux-2.6.16.60-0.21/include/linux/ata.h	2009-03-06 07:45:53.000000000 -0500
+++ linux-2.6.16.60-0.21.ver1.[coderefactor]/include/linux/ata.h	2009-03-06 06:29:44.000000000 -0500
@@ -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,
Signed-off-by: Imran Salim <imran.salim@hp.com>


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

* Re: LibATA SCSI WRITE_BUFFER to ATA DOWNLOAD_MICROCODE patch
  2009-04-01 20:51 LibATA SCSI WRITE_BUFFER to ATA DOWNLOAD_MICROCODE patch salimmu
@ 2009-04-01 21:11 ` James Bottomley
  2009-04-01 21:23 ` Greg Freemyer
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 7+ messages in thread
From: James Bottomley @ 2009-04-01 21:11 UTC (permalink / raw)
  To: salimmu; +Cc: linux-ide, jgarzik, scameron, mike.miller, steve.cameron

On Wed, 2009-04-01 at 15:51 -0500, salimmu@beardog.cca.cpqcorp.net
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



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

* Re: LibATA SCSI WRITE_BUFFER to ATA DOWNLOAD_MICROCODE patch
  2009-04-01 20:51 LibATA SCSI WRITE_BUFFER to ATA DOWNLOAD_MICROCODE patch salimmu
  2009-04-01 21:11 ` James Bottomley
@ 2009-04-01 21:23 ` Greg Freemyer
  2009-04-02 15:25 ` Miller, Mike (OS Dev)
  2009-04-02 17:25 ` Mark Lord
  3 siblings, 0 replies; 7+ messages in thread
From: Greg Freemyer @ 2009-04-01 21:23 UTC (permalink / raw)
  To: salimmu; +Cc: linux-ide, jgarzik, scameron, mike.miller, steve.cameron

A signature block with the company name misspelled.

I'd look real close at the patch.

On Wed, Apr 1, 2009 at 4:51 PM,  <salimmu@beardog.cca.cpqcorp.net> 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
>
>



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

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

* RE: LibATA SCSI WRITE_BUFFER to ATA DOWNLOAD_MICROCODE patch
  2009-04-01 20:51 LibATA SCSI WRITE_BUFFER to ATA DOWNLOAD_MICROCODE patch salimmu
  2009-04-01 21:11 ` James Bottomley
  2009-04-01 21:23 ` Greg Freemyer
@ 2009-04-02 15:25 ` Miller, Mike (OS Dev)
  2009-04-02 17:25 ` Mark Lord
  3 siblings, 0 replies; 7+ messages in thread
From: Miller, Mike (OS Dev) @ 2009-04-02 15:25 UTC (permalink / raw)
  To: salimmu, linux-ide; +Cc: jgarzik, scameron, Cameron, Steve, Benesh, Scott

 

> -----Original Message-----
> From: salimmu@beardog.cca.cpqcorp.net 
> [mailto:salimmu@beardog.cca.cpqcorp.net] 
> Sent: Wednesday, April 01, 2009 3:51 PM
> To: linux-ide@vger.kernel.org
> Cc: jgarzik@pobox.com; scameron@beardog.cca.cpqcorp.net; 
> Miller, Mike (OS Dev); Cameron, Steve
> Subject: LibATA SCSI WRITE_BUFFER to ATA DOWNLOAD_MICROCODE patch
> 
> 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


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

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

* Re: LibATA SCSI WRITE_BUFFER to ATA DOWNLOAD_MICROCODE patch
  2009-04-01 20:51 LibATA SCSI WRITE_BUFFER to ATA DOWNLOAD_MICROCODE patch salimmu
                   ` (2 preceding siblings ...)
  2009-04-02 15:25 ` Miller, Mike (OS Dev)
@ 2009-04-02 17:25 ` Mark Lord
  2009-04-03 20:07   ` Jeff Garzik
  3 siblings, 1 reply; 7+ messages in thread
From: Mark Lord @ 2009-04-02 17:25 UTC (permalink / raw)
  To: salimmu; +Cc: linux-ide, jgarzik, scameron, mike.miller, steve.cameron

salimmu@beardog.cca.cpqcorp.net 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

???

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

* Re: LibATA SCSI WRITE_BUFFER to ATA DOWNLOAD_MICROCODE patch
  2009-04-02 17:25 ` Mark Lord
@ 2009-04-03 20:07   ` Jeff Garzik
  2009-04-03 20:24     ` James Bottomley
  0 siblings, 1 reply; 7+ messages in thread
From: Jeff Garzik @ 2009-04-03 20:07 UTC (permalink / raw)
  To: Mark Lord, salimmu; +Cc: linux-ide, scameron, mike.miller, steve.cameron

Mark Lord wrote:
> salimmu@beardog.cca.cpqcorp.net 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





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

* Re: LibATA SCSI WRITE_BUFFER to ATA DOWNLOAD_MICROCODE patch
  2009-04-03 20:07   ` Jeff Garzik
@ 2009-04-03 20:24     ` James Bottomley
  0 siblings, 0 replies; 7+ messages in thread
From: James Bottomley @ 2009-04-03 20:24 UTC (permalink / raw)
  To: Jeff Garzik
  Cc: Mark Lord, salimmu, linux-ide, scameron, mike.miller, steve.cameron

On Fri, 2009-04-03 at 16:07 -0400, Jeff Garzik wrote:
> Mark Lord wrote:
> > salimmu@beardog.cca.cpqcorp.net 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...

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



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

end of thread, other threads:[~2009-04-03 20:24 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2009-04-01 20:51 LibATA SCSI WRITE_BUFFER to ATA DOWNLOAD_MICROCODE patch salimmu
2009-04-01 21:11 ` James Bottomley
2009-04-01 21:23 ` Greg Freemyer
2009-04-02 15:25 ` Miller, Mike (OS Dev)
2009-04-02 17:25 ` Mark Lord
2009-04-03 20:07   ` Jeff Garzik
2009-04-03 20:24     ` James Bottomley

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.