Skip to contentSkip to conversation

sbp2: workaround for buggy iPods

PATCH In review Stefan Richter 2 participants 9 messages May 27, 2006 – Jun 2, 2006 Documentation

lore
Share & tools
lore
#0 lore raw

cover sbp2: workaround for buggy iPods

There is a firmware bug in several Apple iPods which prevents access to these iPods under certain conditions. The disk size reported by the iPod is one sector too big. Once access to the end of the disk is attempted, the iPod becomes inaccessible. This problem has been known for USB iPods for some time and has recently been discovered to exist with FireWire/USB combo iPods too.

The following patchset is the fix as it exists in Linux 2.6.17-rc. Alas it is rather large, therefore it may be unfit for -stable as it is. If there are objections, I would appreciate suggestions how to better adapt this fix for -stable.

The necessary workaround is added this way:

patch 1/4: sbp2: consolidate workarounds, part one
patch 2/4: sbp2: consolidate workarounds, part two
Infrastructure for existing *unrelated* workarounds is refactored. This concerns (a) module load parameters to activate workarounds,
(b) a hardwired blacklist of known buggy devices, (c) detection of known buggy devices, (d) activation of the various workarounds. Benefits of the refactoring are better readability, extensibility, and finer-grained control.
This is a single patch in 2.6.17-rc; I split it into two due to its size (the essential part and a part affecting comments, log messages etc.).

patch 3/4: add read_capacity workaround for iPod
Extends blacklist and device detection, and adds the actual workaround.

patch 4/4: sbp2: add ability to override hardwired blacklist
As we add more workarounds, potential to adversely affect other devices increases. This patch adds a simple feature as a safety
belt: A new flag for the module load parameter from patch 1/4 tells sbp2 not to use its hardwired blacklist.

Combined diffstat of patches 1/4...4/4:

 Documentation/feature-removal-schedule.txt |    9 +
 drivers/ieee1394/sbp2.c                    |  206 +++++++++++++++++++----------
 drivers/ieee1394/sbp2.h                    |   18 +-
 3 files changed, 159 insertions(+), 74 deletions(-)

So this is much more than is usually acceptable for -stable. Keeping it this big has the benefit of minimal deviation from 2.6.17+, concerning the code as well as sbp2's module load parameters. As I said, I could try to rework this for minimum patch size if so desired by the -stable team. But I suppose I would still end up with a rather big patch.

The impact of leaving this iPod workaround out of -stable is limited because there are a few alternatives:
- Experienced users of affected hardware may compile 2.6.16 and older without support for EFI GUID partition tables. This should make access to the end of the disk rather unlikely.
- Experienced users of affected hardware may switch to 2.6.17+.
- Experienced users or distributors may apply this patchset or a more extensive patchset for the 1394 subsystem on their own. (I am maintaining a bunch of rediffs of current 1394 patches for released kernels.)

Signature · 3 lines
Stefan Richter
-=====-=-==- -=-= ==-==
http://arcgraph.de/sr/
#1 lore raw

PATCH 1/4 sbp2: consolidate workarounds, part one

Grand unification of the three types of workarounds we have so far.

The "skip mode page 8" workaround is now limited to devices which pretend to be of TYPE_DISK instead of TYPE_RBC. This workaround is no longer enabled for Initio bridges.

Patch update in anticipation of more workarounds:
- Add module parameter "workarounds".
- Deprecate parameter "force_inquiry_hack".
- Compose the blacklist of a compound type for better readability and extensibility.
- Remove a now unused #define.

This patch is required for the subsequent patch "sbp2: add read_capacity workaround for iPod". For better readability, the patch is split into the functional part (this one) and a merely cosmetic part (following).

---
rediff for -stable, from commit 24d3bf884e093f9de52d31c97187f4b9b4ad7dcb

 drivers/ieee1394/sbp2.c |   86 +++++++++++++++++++++++++++++++-----------------
 drivers/ieee1394/sbp2.h |    7 +++
 2 files changed, 63 insertions(+), 30 deletions(-)
drivers/ieee1394/sbp2.h +6 -1
Index: linux-2.6.16.18/drivers/ieee1394/sbp2.h
===================================================================
@@ -239,6 +239,11 @@ struct sbp2_status_block {
 #define SBP2_MAX_SECTORS		255	/* Max sectors supported */
 #define SBP2_MAX_CMDS			8	/* This should be safe */
 
+/* Flags for detected oddities and brokeness */
+#define SBP2_WORKAROUND_128K_MAX_TRANS	0x1
+#define SBP2_WORKAROUND_INQUIRY_36	0x2
+#define SBP2_WORKAROUND_MODE_SENSE_8	0x4
+
 /* This is the two dma types we use for cmd_dma below */
 enum cmd_dma_types {
 	CMD_DMA_NONE,
@@ -345,7 +350,7 @@ struct scsi_id_instance_data {
 	struct Scsi_Host *scsi_host;
 
 	/* Device specific workarounds/brokeness */
-	u32 workarounds;
+	unsigned workarounds;
 };
 
 /* Sbp2 host data structure (one per IEEE1394 host) */
drivers/ieee1394/sbp2.c +57 -29

148 lines not on this page · raw message

#2 lore raw

PATCH 2/4 sbp2: consolidate workarounds, part two

rest of the original patch

---
rediff for -stable, from commit 24d3bf884e093f9de52d31c97187f4b9b4ad7dcb

 Documentation/feature-removal-schedule.txt |    9 +++
 drivers/ieee1394/sbp2.c                    |   76 ++++++++++++++---------------
 drivers/ieee1394/sbp2.h                    |    9 ---
 3 files changed, 48 insertions(+), 46 deletions(-)
drivers/ieee1394/sbp2.h +0 -9
Index: linux-2.6.16.18/drivers/ieee1394/sbp2.h
===================================================================
@@ -227,11 +227,6 @@ struct sbp2_status_block {
 #define SBP2_SW_VERSION_ENTRY					0x00010483
 
 /*
- * Other misc defines
- */
-#define SBP2_128KB_BROKEN_FIRMWARE				0xa0b800
-
-/*
  * SCSI specific stuff
  */
 
@@ -273,10 +268,6 @@ struct sbp2_command_info {
 
 };
 
-/* A list of flags for detected oddities and brokeness. */
-#define SBP2_BREAKAGE_128K_MAX_TRANSFER		0x1
-#define SBP2_BREAKAGE_INQUIRY_HACK		0x2
-
 struct sbp2scsi_host_info;
 
 /*
drivers/ieee1394/sbp2.c +39 -37

128 lines not on this page · raw message

Documentation/feature-removal-schedule.txt +9 -0
Index: linux-2.6.16.18/Documentation/feature-removal-schedule.txt
===================================================================
@@ -56,6 +56,15 @@ Who:	Jody McIntyre <scjody@steamballoon.
 
 ---------------------------
 
+What:	sbp2: module parameter "force_inquiry_hack"
+When:	July 2006
+Why:	Superceded by parameter "workarounds". Both parameters are meant to be
+	used ad-hoc and for single devices only, i.e. not in modprobe.conf,
+	therefore the impact of this feature replacement should be low.
+Who:	Stefan Richter <[email protected]>
+
+---------------------------
+
 What:	Video4Linux API 1 ioctls and video_decoder.h from Video devices.
 When:	July 2006
 Why:	V4L1 AP1 was replaced by V4L2 API. during migration from 2.4 to 2.6
#3 lore raw

PATCH 3/4 sbp2: add read_capacity workaround for iPod

Apple decided to copy some USB stupidity over to FireWire. The sector number returned by iPods from read_capacity is one too many. This may cause I/O errors, especially if the kernel is configured for EFI partition support. We use the same workaround as usb-storage but have to check for different model IDs.
http://marc.theaimsgroup.com/?t=114233262300001
https://bugzilla.redhat.com/bugzilla/show_bug.cgi?id=187409

Acknowledgements: Diagnosis and therapy by Mathieu Chouquet-Stringer <[email protected]>, additional data about affected and unaffected Apple hardware from Vladimir Kotal, Sander De Graaf, Bryan Olmstead, Hugh Dixon.

---
rediff for -stable, from commit e9a1c52c7b19d10342226c12f170d7ab644427e2

 drivers/ieee1394/sbp2.c |   49 ++++++++++++++++++++++++++++++++++++++++++++----
 drivers/ieee1394/sbp2.h |    1
 2 files changed, 46 insertions(+), 4 deletions(-)
drivers/ieee1394/sbp2.h +1 -0
Index: linux-2.6.16.18/drivers/ieee1394/sbp2.h
===================================================================
@@ -238,6 +238,7 @@ struct sbp2_status_block {
 #define SBP2_WORKAROUND_128K_MAX_TRANS	0x1
 #define SBP2_WORKAROUND_INQUIRY_36	0x2
 #define SBP2_WORKAROUND_MODE_SENSE_8	0x4
+#define SBP2_WORKAROUND_FIX_CAPACITY	0x8
 
 /* This is the two dma types we use for cmd_dma below */
 enum cmd_dma_types {
drivers/ieee1394/sbp2.c +45 -4

93 lines not on this page · raw message

#4 lore raw

PATCH 4/4 sbp2: add ability to override hardwired blacklist

In case the blacklist with workarounds for device bugs yields a false positive, the module load parameter can now also be used as an override instead of an addition to the blacklist.

---
rediff for -stable, from commit 679c0cd2dd61c825ab910fdbf347a8b7d1dddec4

 drivers/ieee1394/sbp2.c |   29 ++++++++++++++++++-----------
 drivers/ieee1394/sbp2.h |    1 +
 2 files changed, 19 insertions(+), 11 deletions(-)
drivers/ieee1394/sbp2.h +1 -0
Index: linux-2.6.16.18/drivers/ieee1394/sbp2.h
===================================================================
@@ -239,6 +239,7 @@ struct sbp2_status_block {
 #define SBP2_WORKAROUND_INQUIRY_36	0x2
 #define SBP2_WORKAROUND_MODE_SENSE_8	0x4
 #define SBP2_WORKAROUND_FIX_CAPACITY	0x8
+#define SBP2_WORKAROUND_OVERRIDE	0x100
 
 /* This is the two dma types we use for cmd_dma below */
 enum cmd_dma_types {
drivers/ieee1394/sbp2.c +18 -11
Index: linux-2.6.16.18/drivers/ieee1394/sbp2.c
===================================================================
@@ -156,6 +156,11 @@ MODULE_PARM_DESC(exclusive_login, "Exclu
  *   Tell sd_mod to correct the last sector number reported by read_capacity.
  *   Avoids access beyond actual disk limits on devices with an off-by-one bug.
  *   Don't use this with devices which don't have this bug.
+ *
+ * - override internal blacklist
+ *   Instead of adding to the built-in blacklist, use only the workarounds
+ *   specified in the module load parameter.
+ *   Useful if a blacklist entry interfered with a non-broken device.
  */
 static int sbp2_default_workarounds;
 module_param_named(workarounds, sbp2_default_workarounds, int, 0644);
@@ -164,6 +169,7 @@ MODULE_PARM_DESC(workarounds, "Work arou
 	", 36 byte inquiry = "    __stringify(SBP2_WORKAROUND_INQUIRY_36)
 	", skip mode page 8 = "   __stringify(SBP2_WORKAROUND_MODE_SENSE_8)
 	", fix capacity = "       __stringify(SBP2_WORKAROUND_FIX_CAPACITY)
+	", override internal blacklist = " __stringify(SBP2_WORKAROUND_OVERRIDE)
 	", or a combination)");
 
 /* legacy parameter */
@@ -1614,17 +1620,18 @@ static void sbp2_parse_unit_directory(st
 		workarounds |= SBP2_WORKAROUND_INQUIRY_36;
 	}
 
-	for (i = 0; i < ARRAY_SIZE(sbp2_workarounds_table); i++) {
-		if (sbp2_workarounds_table[i].firmware_revision &&
-		    sbp2_workarounds_table[i].firmware_revision !=
-		    (firmware_revision & 0xffff00))
-			continue;
-		if (sbp2_workarounds_table[i].model_id &&
-		    sbp2_workarounds_table[i].model_id != ud->model_id)
-			continue;
-		workarounds |= sbp2_workarounds_table[i].workarounds;
-		break;
-	}
+	if (!(workarounds & SBP2_WORKAROUND_OVERRIDE))
+		for (i = 0; i < ARRAY_SIZE(sbp2_workarounds_table); i++) {
+			if (sbp2_workarounds_table[i].firmware_revision &&
+			    sbp2_workarounds_table[i].firmware_revision !=
+			    (firmware_revision & 0xffff00))
+				continue;
+			if (sbp2_workarounds_table[i].model_id &&
+			    sbp2_workarounds_table[i].model_id != ud->model_id)
+				continue;
+			workarounds |= sbp2_workarounds_table[i].workarounds;
+			break;
+		}
 
 	if (workarounds)
 		SBP2_INFO("Workarounds for node " NODE_BUS_FMT ": 0x%x "
#5 lore raw
In reply to Stefan Richter
Quoted 11 lines · * Stefan Richter ([email protected]) wrote:

There is a firmware bug in several Apple iPods which prevents access to these iPods under certain conditions. The disk size reported by the iPod is one sector too big. Once access to the end of the disk is attempted, the iPod becomes inaccessible. This problem has been known for USB iPods for some time and has recently been discovered to exist with FireWire/USB combo iPods too.

The following patchset is the fix as it exists in Linux 2.6.17-rc. Alas it is rather large, therefore it may be unfit for -stable as it is. If there are objections, I would appreciate suggestions how to better adapt this fix for -stable.

Just to be clear, we're talking about this fix:

+ if (scsi_id->workarounds & SBP2_WORKAROUND_FIX_CAPACITY)
+ sdev->fix_capacity = 1;

with patches 1 and 2 consolidating workaround logic, and 4 adding the command line override.

I'd feel better to let this bit diverge in -stable to have the two-line patch rather than all 4 patches. Could you do detection sbp2_probe(), set a flag in scsi_id_instance_data, and use that in slave_configure?

thanks,
-chris

#6 lore raw
Quoted 2 lines · Chris Wright

I'd feel better to let this bit diverge in -stable to have the two-line patch rather than all 4 patches.

I will see how far I can downsize it. (Will of course take a little more than 2 lines.)

Signature · 3 lines
Stefan Richter
-=====-=-==- -=-= =====
http://arcgraph.de/sr/
#7 lore raw

PATCH 1/1 sbp2: backport read_capacity workaround for iPod

sbp2: backport read_capacity workaround for iPod

There is a firmware bug in several Apple iPods which prevents access to these iPods under certain conditions. The disk size reported by the iPod is one sector too big. Once access to the end of the disk is attempted, the iPod becomes inaccessible. This problem has been known for USB iPods for some time and has recently been discovered to exist with FireWire/USB combo iPods too.

This patch is derived from the fix in Linux 2.6.17, commit e9a1c52c7b19d10342226c12f170d7ab644427e2, to be applicable to 2.6.16.x without prerequisite patches. It hard-wires a workaround for three known affected model numbers (those of 4th generation iPod, iPod Photo, iPod mini).

Note: This patch lacks Linux 2.6.17's ability to enable and disable the workaround via a module parameter.

---

drivers/ieee1394/sbp2.c +11 -0
Index: linux/drivers/ieee1394/sbp2.c
===================================================================
@@ -2491,9 +2491,20 @@ static int sbp2scsi_slave_alloc(struct s
 
 static int sbp2scsi_slave_configure(struct scsi_device *sdev)
 {
+	struct scsi_id_instance_data *scsi_id =
+		(struct scsi_id_instance_data *)sdev->host->hostdata[0];
+
 	blk_queue_dma_alignment(sdev->request_queue, (512 - 1));
 	sdev->use_10_for_rw = 1;
 	sdev->use_10_for_ms = 1;
+
+	if ((scsi_id->sbp2_firmware_revision & 0xffff00) == 0x0a2700 &&
+	    (scsi_id->ud->model_id == 0x000021 /* gen.4 iPod */ ||
+	     scsi_id->ud->model_id == 0x000023 /* iPod mini  */ ||
+	     scsi_id->ud->model_id == 0x00007e /* iPod Photo */ )) {
+		SBP2_INFO("enabling iPod workaround: decrement disk capacity");
+		sdev->fix_capacity = 1;
+	}
 	return 0;
 }
 
#8 lore raw

Re: [stable] [PATCH 2.6.16.19] sbp2: backport read_capacity workaround for iPod

Quoted 1 line · * Stefan Richter ([email protected]) wrote:

sbp2: backport read_capacity workaround for iPod

Thank you for the smaller backport Stefan. Patch queued. -chris