Skip to contentSkip to conversation

libata: Prepare for hard drives w/ non-512 sector sizes

PATCH In review Jeff Garzik 2 participants 6 messages Apr 8, 2009 libata

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 libata: Prepare for hard drives w/ non-512 sector sizes

I checked this into libata-dev.git#sectsize and #NEXT... comments welcome. It's willy's patch, cut down such that it introduces no major behavior changes [READ CAPACITY improves slightly].

commit 6644d0c1ced895087c176db8a4bfbdb3982c2848

Author: Jeff Garzik <[email protected]>
Date:   Wed Apr 8 02:52:58 2009 -0400

[libata] Prepare for hard drives with non-512 sector sizes

This converts libata to use variables for storing sector size, in several places. Sector size is now only hardcoded in one place.

Much of this content originated in a patch by Matthew Wilcox. I mainly removed content from his patch, to arrive at this.

drivers/ata/libata-core.c +11 -0
index e7ea77c..c0c27b4 100644
@@ -2387,6 +2387,7 @@ int ata_dev_configure(struct ata_device *dev)
 	dev->max_sectors = 0;
 	dev->cdb_len = 0;
 	dev->n_sectors = 0;
+	dev->sect_size = ATA_SECT_SIZE;
 	dev->cylinders = 0;
 	dev->heads = 0;
 	dev->sectors = 0;
@@ -2428,6 +2429,16 @@ int ata_dev_configure(struct ata_device *dev)
 
 		dev->n_sectors = ata_id_n_sectors(id);
 
+		if (dev->sect_size != ata_id_sect_size(id)) {
+			ata_dev_printk(dev, KERN_ERR,
+				       "internal sector size %lld does not "
+				       "match drive-supplied size %lld\n",
+				       dev->sect_size,
+				       ata_id_sect_size(id));
+			rc = -EINVAL;
+			goto err_out_nosup;
+		}
+
 		/* get current R/W Multiple count setting */
 		if ((dev->id[47] >> 8) == 0x80 && (dev->id[59] & 0x100)) {
 			unsigned int max = dev->id[47] & 0xff;
drivers/ata/libata-scsi.c +35 -11

98 lines not on this page · raw message

include/linux/ata.h +19 -0
index cb79b7a..fdefc01 100644
@@ -788,6 +788,25 @@ static inline int ata_drive_40wire_relaxed(const u16 *dev_id)
 	return 1;
 }
 
+/*
+ * ATA supports sector sizes up to 2^33 - 1.  The reported sector size may
+ * not be a power of two.  The extra bytes are used for user-visible data
+ * integrity calculations.  Note this is not the same as the ECC which is
+ * accessed through the SCT Command Transport or READ / WRITE LONG.
+ */
+static inline u64 ata_id_sect_size(const u16 *id)
+{
+	u16 word_106 = id[106];
+	u64 sz;
+
+	if ((word_106 & 0xc000) != 0x4000)
+		return ATA_SECT_SIZE;
+	if (!(word_106 & (1 << 12)))
+		return ATA_SECT_SIZE;
+	sz = (id[117] | ((u64)id[118] << 16)) * 2;
+	return sz;
+}
+
 static inline int atapi_cdb_len(const u16 *dev_id)
 {
 	u16 tmp = dev_id[ATA_ID_CONFIG] & 0x3;
include/linux/libata.h +1 -0
index b450a26..08a5ae4 100644
@@ -584,6 +584,7 @@ struct ata_device {
 #endif
 	/* n_sector is CLEAR_BEGIN, read comment above CLEAR_BEGIN */
 	u64			n_sectors;	/* size of device, if ATA */
+	u64			sect_size;	/* Logical, not physical */
 	unsigned int		class;		/* ATA_DEV_xxx */
 	unsigned long		unpark_deadline;
 
#1 lore raw
Quoted 3 lines · Jeff Garzik

I checked this into libata-dev.git#sectsize and #NEXT... comments welcome. It's willy's patch, cut down such that it introduces no major behavior changes [READ CAPACITY improves slightly].

Umm. If you wanted me to split the patch up, why didn't you ask?

I really do think I should be credited as 'Author' here. You credit me in the patch description, but the automated tools don't show that.

drivers/ata/libata-scsi.c saving_not_supp: · line 2361

Quoted 9 lines
drivers/ata/libata-scsi.c +4 -1
@@ -2354,10 +2355,25 @@ saving_not_supp:
  */
 static unsigned int ata_scsiop_read_cap(struct ata_scsi_args *args, u8 *rbuf)
 {
-	u64 last_lba = args->dev->n_sectors - 1; /* LBA of the last block */
+	struct ata_device *dev = args->dev;
+	u64 last_lba = dev->n_sectors - 1; /* LBA of the last block */
+	u32 sector_size;
+	u8 log_per_phys = 1;

This was a bug I had fixed, but possibly not sent out. It should be 0, not 1 (it's the power of 2, not the raw count).

Signature · 4 lines
Matthew Wilcox				Intel Open Source Technology Centre
"Bill, look, we understand that you're interested in selling us this
operating system, but compare it to ours.  We can't possibly take such
a retrograde step."
#2 lore raw
Quoted 6 lines · Matthew Wilcox
Quoted 3 lines · Jeff Garzik

I checked this into libata-dev.git#sectsize and #NEXT... comments welcome. It's willy's patch, cut down such that it introduces no major behavior changes [READ CAPACITY improves slightly].

Umm. If you wanted me to split the patch up, why didn't you ask?

I've had trouble until recently simply getting you to post patches at all. It was faster and simpler for me to do it myself.

Quoted 2 lines

I really do think I should be credited as 'Author' here. You credit me in the patch description, but the automated tools don't show that.

If that is your preference, that's fine. I did it this way to avoid your taking the blame for anything I did, while still noting in the patch description you did the original work.

Quoted 4 lines
Quoted 4 lines
drivers/ata/libata-scsi.c +0 -0
@@ -2354,10 +2355,25 @@ saving_not_supp:
  */
 static unsigned int ata_scsiop_read_cap(struct ata_scsi_args *args, u8 *rbuf)
 {
Quoted 8 lines

drivers/ata/libata-scsi.c saving_not_supp: · line 2361

Quoted 5 lines
drivers/ata/libata-scsi.c +4 -1
-	u64 last_lba = args->dev->n_sectors - 1; /* LBA of the last block */
+	struct ata_device *dev = args->dev;
+	u64 last_lba = dev->n_sectors - 1; /* LBA of the last block */
+	u32 sector_size;
+	u8 log_per_phys = 1;

This was a bug I had fixed, but possibly not sent out. It should be 0, not 1 (it's the power of 2, not the raw count).

Ok.

Jeff

#3 lore raw
Quoted 10 lines · Jeff Garzik
Quoted 6 lines · Matthew Wilcox
Quoted 3 lines · Jeff Garzik

I checked this into libata-dev.git#sectsize and #NEXT... comments welcome. It's willy's patch, cut down such that it introduces no major behavior changes [READ CAPACITY improves slightly].

Umm. If you wanted me to split the patch up, why didn't you ask?

I've had trouble until recently simply getting you to post patches at all. It was faster and simpler for me to do it myself.

?! Are you referring to the one incident where you asked me if I had any patches for 2.6.30, I pointed at the TRIM patches and you quibbled that I hadn't reposted the updates, only a git tree?

Quoted 6 lines
Quoted 2 lines

I really do think I should be credited as 'Author' here. You credit me in the patch description, but the automated tools don't show that.

If that is your preference, that's fine. I did it this way to avoid your taking the blame for anything I did, while still noting in the patch description you did the original work.

Yes, that's my preference. It's also the documented way to do things in SubmittingPatches.

I'll be offline for the next week and unable to respond to email after today.

Signature · 4 lines
Matthew Wilcox				Intel Open Source Technology Centre
"Bill, look, we understand that you're interested in selling us this
operating system, but compare it to ours.  We can't possibly take such
a retrograde step."
#4 lore raw
Quoted 6 lines · Matthew Wilcox
Quoted 5 lines · Jeff Garzik
Quoted 4 lines · Matthew Wilcox
Quoted 3 lines · Jeff Garzik

I checked this into libata-dev.git#sectsize and #NEXT... comments welcome. It's willy's patch, cut down such that it introduces no major behavior changes [READ CAPACITY improves slightly].

Quoted 6 lines
Quoted 2 lines
Quoted 1 line

Umm. If you wanted me to split the patch up, why didn't you ask?

I've had trouble until recently simply getting you to post patches at all. It was faster and simpler for me to do it myself.

?! Are you referring to the one incident where you asked me if I had any patches for 2.6.30, I pointed at the TRIM patches and you quibbled that I hadn't reposted the updates, only a git tree?

On multiple occasions. You're the only one I have to poke to get updates on pending libata patches, in some cases, patches that really should have gone upstream long ago.

Quoted 6 lines
Quoted 3 lines
Quoted 2 lines

I really do think I should be credited as 'Author' here. You credit me in the patch description, but the automated tools don't show that.

If that is your preference, that's fine. I did it this way to avoid your taking the blame for anything I did, while still noting in the patch description you did the original work.

Yes, that's my preference. It's also the documented way to do things in SubmittingPatches.

The patch was changed from your original work, in several places. That makes the issue of From header not so clear cut. See what I said about blame etc. in the original email :) If there were bugs in my changes, you would probably be annoyed to get bug reports about that :)

Jeff

#5 lore raw
Quoted 8 lines · Jeff Garzik
Quoted 3 lines · Matthew Wilcox

?! Are you referring to the one incident where you asked me if I had any patches for 2.6.30, I pointed at the TRIM patches and you quibbled that I hadn't reposted the updates, only a git tree?

On multiple occasions. You're the only one I have to poke to get updates on pending libata patches, in some cases, patches that really should have gone upstream long ago.

I send patches and get no feedback from the maintainer (you). So I work on other things instead. The 4k sector size support is largely theoretical anyway, given that every _SATA_ vendor I've heard from is planning on doing 4k physical / 512 byte logical sectors. SAS is a different matter, but is irrelevant to this series of patches.

Signature · 4 lines
Matthew Wilcox				Intel Open Source Technology Centre
"Bill, look, we understand that you're interested in selling us this
operating system, but compare it to ours.  We can't possibly take such
a retrograde step."