drivers/ieee1394/sbp2: fixes for 2.6.18-rc
cover drivers/ieee1394/sbp2: fixes for 2.6.18-rc
There are a few bug fixes for sbp2 in -mm. Here is a selection of those which I consider important enough and/or simple enough for inclusion into 2.6.18-rc:
1/5 ieee1394: sbp2: workaround for write protect bit of Initio firmware
fix bug #6947 (workaround for a device bug, not a Linux bug per se)
2/5 ieee1394: sbp2: safer agent reset in error handlers
simple and obvious improvement
3/5 ieee1394: sbp2: safer last_orb and next_ORB handling
prerequisite for patch 5/5, and more
4/5 ieee1394: sbp2: discard return value of sbp2_link_orb_command
prerequisite for patch 5/5
5/5 ieee1394: sbp2: handle "sbp2util_node_write_no_wait failed"
fix bug #6948
combined diffstat:
drivers/ieee1394/sbp2.c | 186 +++++++++++++++++++++++++++------------- drivers/ieee1394/sbp2.h | 15 +-- 2 files changed, 133 insertions(+), 68 deletions(-)
Signature · 3 lines
Stefan Richter -=====-=-==- =--- ==-== http://arcgraph.de/sr/
PATCH 1/5 ieee1394: sbp2: workaround for write protect bit of Initio firmware
Yet another mode pages related bug of Initio firmwares was seen. INIC-1530 with a firmware by Initio responded with garbage to MODE SENSE (10). Some HDDs were therefore incorrectly marked as write protected:
http://bugzilla.kernel.org/show_bug.cgi?id=6947
Sbp2 now tells scsi_lib to use MODE SENSE (6) for the one known defective model. The workaround could be expanded to other or perhaps even all model IDs of Initio firmwares if necessary. At least it worked OK with an INIC-2430 with different model ID and without the MS(10) bug.
---
drivers/ieee1394/sbp2.h +2 -1
@@ -237,8 +237,9 @@ struct sbp2_status_block {/* 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 +#define SBP2_WORKAROUND_SKIP_PAGE_08 0x4#define SBP2_WORKAROUND_FIX_CAPACITY 0x8 +#define SBP2_WORKAROUND_MODE_SENSE_6 0x10#define SBP2_WORKAROUND_OVERRIDE 0x100/* This is the two dma types we use for cmd_dma below */
drivers/ieee1394/sbp2.c +15 -3
@@ -168,8 +168,9 @@ module_param_named(workarounds, sbp2_def MODULE_PARM_DESC(workarounds, "Work around device bugs (default = 0" ", 128kB max transfer = " __stringify(SBP2_WORKAROUND_128K_MAX_TRANS) ", 36 byte inquiry = " __stringify(SBP2_WORKAROUND_INQUIRY_36) - ", skip mode page 8 = " __stringify(SBP2_WORKAROUND_MODE_SENSE_8) + ", skip mode page 08 = " __stringify(SBP2_WORKAROUND_SKIP_PAGE_08) ", fix capacity = " __stringify(SBP2_WORKAROUND_FIX_CAPACITY) + ", use mode sense 6 = " __stringify(SBP2_WORKAROUND_MODE_SENSE_6) ", override internal blacklist = " __stringify(SBP2_WORKAROUND_OVERRIDE)", or a combination)" );
@@ -301,6 +302,10 @@ static struct hpsb_protocol_driver sbp2_* The firmware_revision field, masked with 0xffff00, is the best indicator * for the type of bridge chip of a device. It yields a few false positives * but this did not break correctly behaving devices so far. +* +* The order of table entries is from special to general, like for example +* the Initio entries. This order is necessary because once an entry matches, +* the rest of the table is skipped. */ static const struct { u32 firmware_revision;
@@ -311,7 +316,12 @@ static const struct { .firmware_revision = 0x002800, .model_id = 0x001010, .workarounds = SBP2_WORKAROUND_INQUIRY_36 | - SBP2_WORKAROUND_MODE_SENSE_8, + SBP2_WORKAROUND_SKIP_PAGE_08, + }, +/* Initio INIC-1530 with a firmware apparently from Initio */ { + .firmware_revision = 0x000200, + .model_id = 0x000540, + .workarounds = SBP2_WORKAROUND_MODE_SENSE_6, },/* Initio bridges, actually only needed for some older ones */ { .firmware_revision = 0x000200,
@@ -2511,10 +2521,12 @@ static int sbp2scsi_slave_configure(stru sdev->use_10_for_ms =1 ;if (sdev->type ==TYPE_DISK && - scsi_id->workarounds &SBP2_WORKAROUND_MODE_SENSE_8 ) + scsi_id->workarounds &SBP2_WORKAROUND_SKIP_PAGE_08 ) sdev->skip_ms_page_8 =1 ;if (scsi_id->workarounds &SBP2_WORKAROUND_FIX_CAPACITY ) sdev->fix_capacity =1 ; +if (scsi_id->workarounds &SBP2_WORKAROUND_MODE_SENSE_6 ) + sdev->use_10_for_ms =0 ;if (scsi_id->ne->guid_vendor_id ==0x0010b9 &&/* Maxtor's OUI */ (sdev->type ==TYPE_DISK || sdev->type ==TYPE_RBC )) sdev->allow_restart =1 ;
Re: [PATCH 2.6.18-rc4 1/5] ieee1394: sbp2: workaround for write protect bit of Initio firmware
Quoted 5 lines · Stefan Richter
Yet another mode pages related bug of Initio firmwares was seen. INIC-1530 with a firmware by Initio responded with garbage to MODE SENSE (10). Some HDDs were therefore incorrectly marked as write protected:
http://bugzilla.kernel.org/show_bug.cgi?id=6947
Why does sbp2scsi_slave_configure() set "use_10_for_ms" in the first place?
Almost all the other SCSI code seems to default to using the 6-byte version, and then only uses the 10-byte version if they have some specific reason to do so.
I don't think there really is _ever_ any reason to use the 10-byte version if the 6-byte version is expected to work. Is there?
Examples:
- scsi_add_lun() only sets the 10-byte MS for things that are black-listed to set it (BLIST_USE_10_BYTE_MS)
In fact, I don't see _anything_ in the source code that actually does set that, so as far as I can see, scsi_add_lun() _never_ asks to use the 10-byte modesense.
- libata does set the 10-byte modesense for all SATA devices (but scsi_lib.c might clear it if we get a bad status back).
- USB devices set the 10-byte version _only_ if it's a non-disk device, or if the subclass of the device is not SCSI.
Anyway, it would appear that sbp2 is the odd man out in setting up for a 10-byte modesense, and then having to have strange magic rules for clearing it again.
Is there _really_ any reason to use the 10-byte version at all in the first place?
Linus
Re: [PATCH 2.6.18-rc4 1/5] ieee1394: sbp2: workaround for write protect bit of Initio firmware
Quoted 1 line · Linus Torvalds
I don't think there really is _ever_ any reason to use the 10-byte version if the 6-byte version is expected to work. Is there?
Yes, but not really important: 10-byte allows a 16-bit allocation length (additional data section), where 6-byte only allows 8-bit.
However, the mode pages the kernel requests from the device are normally <= 256 bytes.
In general, your intuition is correct. use_10_for_foo is largely meant for the subclass of "SCSI" devices which often don't bother to implement the 6-byte commands, forcing the software driver to emulate 6-byte. use_10_for_foo allows the software driver to eliminate that in-kernel emulation code.
Jeff
Re: [PATCH 2.6.18-rc4 1/5] ieee1394: sbp2: workaround for write protect bit of Initio firmware
In reply to Linus TorvaldsQuoted 11 lines · Linus Torvalds
Quoted 5 lines · Stefan Richter
Yet another mode pages related bug of Initio firmwares was seen. INIC-1530 with a firmware by Initio responded with garbage to MODE SENSE (10). Some HDDs were therefore incorrectly marked as write protected:
http://bugzilla.kernel.org/show_bug.cgi?id=6947Why does
sbp2scsi_slave_configure()set "use_10_for_ms" in the first place?
I suspect that's because the typical command set for ieee1394 devices is RBC which only specifies the 10-byte commands.
Re: [PATCH 2.6.18-rc4 1/5] ieee1394: sbp2: workaround for write protect bit of Initio firmware
Quoted 3 lines · Christoph Hellwig
Quoted 2 lines · Linus Torvalds
Why does
sbp2scsi_slave_configure()set "use_10_for_ms" in the first place?
Good question...
All I can say about it is that older versions of sbp2 enforced the usage of MODE SENSE(10). If the SCSI stack passed down an MS(6), sbp2 converted it to MS(10) and converted returned data back into MS(6) format. It did so for RBC disks, SBC disks, and CD-ROMs.
http://lxr.free-electrons.com/source/drivers/ieee1394/sbp2.c?v=2.4.32#2292
Some months ago all of these command conversions in sbp2 were removed and the use_10_for_ms flag was switched on.
It would be a non-issue if devices simply returned "illegal request" status on a wrong version of MODE SENSE. But these Initio INIC-1530 bridges return "good" status after either MODE SENSE(6) or (10) but bogus data after the latter.
Quoted 2 lines
I suspect that's because the typical command set for ieee1394 devices is RBC which only specifies the 10-byte commands.
RBC actually lists only MODE SENSE(6), not (10). This makes sbp2's old behaviour even more questionable. Nevertheless, INIC-1530 is the very first device that became known to break on MS(10). Everything else seemed to work fine with MS(10) so far. Switching unconditionally to try MS(6) before MS(10) could break any other devices.
I suppose I should set up an SBP-2 target (Oracle has a GPL'd userspace implementation; somebody recently mentioned an as yet unpublished kernelspace implementation) and use this to log which version of MODE SENSE Windows and Mac OS prefer. Firmware coders certainly test their works of art with some variants of these OSs.
PS: Initio's published data sheet mentions RBC support. But their inquiry data indicate a peripheral device type of 0, which is associated with SBC.
PPS: This patch here is not strictly needed. The INIC-1530 can be corrected if the user directly asks Initio for a corrected firmware and firmware uploader (they don't have it on their website) and has access to a Windows PC to run the firmware uploader. But I think Linux users are better served if our driver handles these devices out of the box.
Signature · 3 lines
Stefan Richter -=====-=-==- =--- ==--= http://arcgraph.de/sr/
A message that is not in the archive (sent off-list or not yet received): [email protected]
Re: [PATCH 2.6.18-rc4 1/5] ieee1394: sbp2: workaround for write protect bit of Initio firmware
Quoted 2 lines · Stefan Richter
I finally did my homework.
Thanks for looking into it.
Quoted 3 lines
OS X' and Win XP's SBP-2 drivers send MODE SENSE (6) to RBC disks and to SBC disks. OS X sends MODE SENSE (10) to MMC devices, Win XP seems to send MODE SENSE (6).
I think that clinches it. If WinXP sends the 6-byte version, we should too, since that's effectively what pretty much everybody has tested with (yeah, Apple used to be the main firewire user, but I bet there have been more XP users over the last few years, it's not like it's unusual on PC's any more).
Quoted 7 lines
So it should be safe to remove the
use_10_for_msflag in our sbp2 driver at least for RBC disks and SBC disks. I.e. the proposed "workaround for write protect bit of Initio firmware" will no longer be necessary.Next steps for me to do:
- test all my devices withuse_10_for_msremoved from sbp2,
- prepare patch as candidate for 2.6.19-rc.
Yeah, please send me a patch asap after 2.6.18, so that it can go in very early (regardless of anything else).
Btw, somebody should tell the Oracle Endpoint people to get their target client to support the 6-byte version too, no? Anybody who knows that team?
Linus
Re: [PATCH 2.6.18-rc4 1/5] ieee1394: sbp2: workaround for write protect bit of Initio firmware
Quoted 2 lines · Linus Torvalds
Btw, somebody should tell the Oracle Endpoint people to get their target client to support the 6-byte version too, no? Anybody who knows that team?
At least OS X doesn't complain. I haven't tested Linux-to-Linux yet --- but that's what Endpoint was obviously written for in the first place, potentially with multiple 1394 cards on the target and multiple concurrent initiators. Manish Singh is the author; he will get feedback from me. I think he was around at linux1394-devel occasionally. BTW, Endpoint could be reused to build a transport driver for the upcoming generic SCSI target framework.
svn co http://oss.oracle.com/projects/endpoint/src/
Signature · 3 lines
Stefan Richter -=====-=-==- =--= --=-- http://arcgraph.de/sr/
PATCH 2/5 ieee1394: sbp2: safer agent reset in error handlers
In reply to Stefan RichterThe scsi_host_template's eh_abort_handler and eh_device_reset_handler are allowed to sleep. Use this to run sbp2_agent_reset in the more reliable mode which returns _after_ its write transaction was finished.
---
drivers/ieee1394/sbp2.c +2 -2
@@ -2583,7 +2583,7 @@ static int sbp2scsi_abort(struct scsi_cm/* * Initiate a fetch agent reset. */ -sbp2_agent_reset (scsi_id,0 ); +sbp2_agent_reset (scsi_id,1 );sbp2scsi_complete_all_commands (scsi_id,DID_BUS_BUSY ); }
@@ -2602,7 +2602,7 @@ static int sbp2scsi_reset(struct scsi_cmif (sbp2util_node_is_available (scsi_id)) {SBP2_ERR ("Generating sbp2 fetch agent reset" ); -sbp2_agent_reset (scsi_id,0 ); +sbp2_agent_reset (scsi_id,1 ); }return SUCCESS ;
PATCH 3/5 ieee1394: sbp2: safer last_orb and next_ORB handling
In reply to Stefan RichterThe sbp2 initiator has two ways to tell a target's fetch agent about new command ORBs:
- Write the ORB's address to the ORB_POINTER register. This must not be done while the fetch agent is active.
- Put the ORB's address into the previously submitted ORB's next_ORB field and write to the DOORBELL register. This may be done while the fetch agent is active or suspended. It must not be done while the fetch agent is in reset state.
Sbp2 has a last_orb pointer which indicates in what way a new command should be announced. That pointer is concurrently accessed at various occasions. Furthermore, initiator and target are accessing the next_ORB field of ORBs concurrently and asynchronously.
This patch does:
- Protect all initiator accesses to last_orb by sbp2_command_orb_lock.
- Add pci_dma_sync_single_for_device before a previously submitted ORB's next_ORB field is overwritten.
- Insert a memory barrier between when next_ORB_lo and next_ORB_hi are overwritten. Next_ORB_hi must not be updated before next_ORB_lo.
- Remove the rather unspecific and now superfluous qualifier "volatile" from the next_ORB fields.
- Add comments on how last_orb is connected with what is known about the target's fetch agent's state.
---
drivers/ieee1394/sbp2.h +2 -2
@@ -46,8 +46,8 @@#define ORB_SET_DIRECTION (value) ((value & 0x1) << 27)struct sbp2_command_orb { -volatile u32 next_ORB_hi; -volatile u32 next_ORB_lo; +u32 next_ORB_hi; +u32 next_ORB_lo;u32 data_descriptor_hi;u32 data_descriptor_lo;u32 misc;
drivers/ieee1394/sbp2.c +48 -53
147 lines not on this page · raw message
PATCH 3/5 ieee1394: sbp2: safer last_orb and next_ORB handling
In reply to Stefan RichterThe sbp2 initiator has two ways to tell a target's fetch agent about new command ORBs:
- Write the ORB's address to the ORB_POINTER register. This must not be done while the fetch agent is active.
- Put the ORB's address into the previously submitted ORB's next_ORB field and write to the DOORBELL register. This may be done while the fetch agent is active or suspended. It must not be done while the fetch agent is in reset state.
Sbp2 has a last_orb pointer which indicates in what way a new command should be announced. That pointer is concurrently accessed at various occasions. Furthermore, initiator and target are accessing the next_ORB field of ORBs concurrently and asynchronously.
This patch does:
- Protect all initiator accesses to last_orb by sbp2_command_orb_lock.
- Add pci_dma_sync_single_for_device before a previously submitted ORB's next_ORB field is overwritten.
- Insert a memory barrier between when next_ORB_lo and next_ORB_hi are overwritten. Next_ORB_hi must not be updated before next_ORB_lo.
- Remove the rather unspecific and now superfluous qualifier "volatile" from the next_ORB fields.
- Add comments on how last_orb is connected with what is known about the target's fetch agent's state.
---
drivers/ieee1394/sbp2.h +2 -2
@@ -46,8 +46,8 @@#define ORB_SET_DIRECTION (value) ((value & 0x1) << 27)struct sbp2_command_orb { -volatile u32 next_ORB_hi; -volatile u32 next_ORB_lo; +u32 next_ORB_hi; +u32 next_ORB_lo;u32 data_descriptor_hi;u32 data_descriptor_lo;u32 misc;
drivers/ieee1394/sbp2.c +48 -53
147 lines not on this page · raw message
PATCH 4/5 ieee1394: sbp2: discard return value of sbp2_link_orb_command
In reply to Stefan RichterSince sbp2 is at the moment unable to do anything with the return value of sbp2_link_orb_command, just discard it.
---
drivers/ieee1394/sbp2.c +3 -5
@@ -1974,7 +1974,7 @@ static void sbp2_create_command_orb(stru/* * This function is called in order to begin a regular SBP-2 command. */ -static int sbp2_link_orb_command (struct scsi_id_instance_data *scsi_id, +static void sbp2_link_orb_command (struct scsi_id_instance_data *scsi_id,struct sbp2_command_info *command) {struct sbp2scsi_host_info *hi = scsi_id->hi;
@@ -2040,11 +2040,9 @@ static int sbp2_link_orb_command(structSBP2_ORB_DEBUG ("write to %s register, command orb %p" , last_orb ?"DOORBELL" :"ORB_POINTER" , command_orb); -if (sbp2util_node_write_no_wait (scsi_id->ne, addr, data, length) <0 ) { +if (sbp2util_node_write_no_wait (scsi_id->ne, addr, data, length))SBP2_ERR ("sbp2util_node_write_no_wait failed.\n" ); -return -EIO ; - } -return 0 ; +/* We rely on SCSI EH to deal with _node_write_ failures. */ }/*
drivers/ieee1394/sbp2.h +0 -5
@@ -391,11 +391,6 @@ static int sbp2_logout_device(struct scsstatic int sbp2_handle_status_write (struct hpsb_host *host,int nodeid,int destid,quadlet_t *data,u64 addr,size_t length,u16 flags);static int sbp2_agent_reset (struct scsi_id_instance_data *scsi_id,int wait); -static int sbp2_link_orb_command (struct scsi_id_instance_data *scsi_id, -struct sbp2_command_info *command); -static int sbp2_send_command (struct scsi_id_instance_data *scsi_id, -struct scsi_cmnd *SCpnt, -void (*done)(struct scsi_cmnd *));static unsigned int sbp2_status_to_sense_data (unchar *sbp2_status,unchar *sense_data); static void sbp2_parse_unit_directory(struct scsi_id_instance_data *scsi_id,
PATCH 4/5 ieee1394: sbp2: discard return value of sbp2_link_orb_command
In reply to Stefan RichterSince sbp2 is at the moment unable to do anything with the return value of sbp2_link_orb_command, just discard it.
---
drivers/ieee1394/sbp2.c +3 -5
@@ -1974,7 +1974,7 @@ static void sbp2_create_command_orb(stru/* * This function is called in order to begin a regular SBP-2 command. */ -static int sbp2_link_orb_command (struct scsi_id_instance_data *scsi_id, +static void sbp2_link_orb_command (struct scsi_id_instance_data *scsi_id,struct sbp2_command_info *command) {struct sbp2scsi_host_info *hi = scsi_id->hi;
@@ -2040,11 +2040,9 @@ static int sbp2_link_orb_command(structSBP2_ORB_DEBUG ("write to %s register, command orb %p" , last_orb ?"DOORBELL" :"ORB_POINTER" , command_orb); -if (sbp2util_node_write_no_wait (scsi_id->ne, addr, data, length) <0 ) { +if (sbp2util_node_write_no_wait (scsi_id->ne, addr, data, length))SBP2_ERR ("sbp2util_node_write_no_wait failed.\n" ); -return -EIO ; - } -return 0 ; +/* We rely on SCSI EH to deal with _node_write_ failures. */ }/*
drivers/ieee1394/sbp2.h +0 -5
@@ -391,11 +391,6 @@ static int sbp2_logout_device(struct scsstatic int sbp2_handle_status_write (struct hpsb_host *host,int nodeid,int destid,quadlet_t *data,u64 addr,size_t length,u16 flags);static int sbp2_agent_reset (struct scsi_id_instance_data *scsi_id,int wait); -static int sbp2_link_orb_command (struct scsi_id_instance_data *scsi_id, -struct sbp2_command_info *command); -static int sbp2_send_command (struct scsi_id_instance_data *scsi_id, -struct scsi_cmnd *SCpnt, -void (*done)(struct scsi_cmnd *));static unsigned int sbp2_status_to_sense_data (unchar *sbp2_status,unchar *sense_data); static void sbp2_parse_unit_directory(struct scsi_id_instance_data *scsi_id,
PATCH 5/5 ieee1394: sbp2: handle "sbp2util_node_write_no_wait failed"
In reply to Stefan RichterFix for http://bugzilla.kernel.org/show_bug.cgi?id=6948
Because sbp2 writes to the target's fetch agent's registers from within atomic context, it cannot sleep to guaranteedly get a free transaction label. This may repeatedly lead to "sbp2util_node_write_no_wait failed" and consequently to SCSI command abortion after timeout. A likely cause is that many queue_command softirqs may occur before khpsbpkt (the ieee1394 driver's thread which cleans up after finished transactions) is woken up to recycle tlabels.
Sbp2 now schedules a workqueue job whenever sbp2_link_orb_command fails in sbp2util_node_write_no_wait. The job will reliably get a transaction label because it can sleep.
We use the kernel-wide shared workqueue because it is unlikely that the job itself actually needs to sleep. In the improbable case that it has to sleep, it doesn't need to sleep long since the standard transaction timeout is 100ms.
---
drivers/ieee1394/sbp2.h +3 -0
@@ -345,6 +345,9 @@ struct scsi_id_instance_data {/* Device specific workarounds/brokeness */ unsigned workarounds; + +atomic_t unfinished_reset; +struct work_struct protocol_work; };/* Sbp2 host data structure (one per IEEE1394 host) */
drivers/ieee1394/sbp2.c +66 -5
120 lines not on this page · raw message
PATCH 5/5 ieee1394: sbp2: handle "sbp2util_node_write_no_wait failed"
In reply to Stefan RichterFix for http://bugzilla.kernel.org/show_bug.cgi?id=6948
Because sbp2 writes to the target's fetch agent's registers from within atomic context, it cannot sleep to guaranteedly get a free transaction label. This may repeatedly lead to "sbp2util_node_write_no_wait failed" and consequently to SCSI command abortion after timeout. A likely cause is that many queue_command softirqs may occur before khpsbpkt (the ieee1394 driver's thread which cleans up after finished transactions) is woken up to recycle tlabels.
Sbp2 now schedules a workqueue job whenever sbp2_link_orb_command fails in sbp2util_node_write_no_wait. The job will reliably get a transaction label because it can sleep.
We use the kernel-wide shared workqueue because it is unlikely that the job itself actually needs to sleep. In the improbable case that it has to sleep, it doesn't need to sleep long since the standard transaction timeout is 100ms.
---
drivers/ieee1394/sbp2.h +3 -0
@@ -345,6 +345,9 @@ struct scsi_id_instance_data {/* Device specific workarounds/brokeness */ unsigned workarounds; + +atomic_t unfinished_reset; +struct work_struct protocol_work; };/* Sbp2 host data structure (one per IEEE1394 host) */
drivers/ieee1394/sbp2.c +66 -5
120 lines not on this page · raw message