linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Alan Stern <stern@rowland.harvard.edu>
To: "Roberts-Thomson, James" <James.Roberts-Thomson@NBNZ.CO.NZ>
Cc: "'Stefano Rivoir'" <s.rivoir@gts.it>,
	"'Kernel development list'" <linux-kernel@vger.kernel.org>,
	"'USB development list'" <linux-usb-devel@lists.sourceforge.net>
Subject: RE: [linux-usb-devel] Kernel unable to read partition table on US B Memory Key
Date: Mon, 11 Jul 2005 15:27:22 -0400 (EDT)	[thread overview]
Message-ID: <Pine.LNX.4.44L0.0507111506570.6399-100000@iolanthe.rowland.org> (raw)
In-Reply-To: <40BC5D4C2DD333449FBDE8AE961E0C334F9385@psexc03.nbnz.co.nz>

On Mon, 11 Jul 2005, Roberts-Thomson, James wrote:

> OK, it turns out that for this particular key, a two second pause after
> "sd_spinup_disk" is called and before "sd_read_capacity" will make it work.
> The 'dmesg' (or syslog) output is still ugly, however; but once I realised
> that it was "sd_spinup_disk" that:
> 
> A) needed the delay, and 
> B) causes the first ugly message to be printed in the first place, then a
> better patch came to mind.
> 
> So, after combining Alan's suggestion to use "msleep" rather than my
> previous convoluted method, and moving the location of the pause to inside
> sd_spinup_disk (and targeting it to remove the first "ugly"), I came up with
> a better patch, which is attached.
> 
> This patch adds the module parameter 'firmware_delay', and will cause a
> pause for "firmware_delay" seconds inside sd_spinup_disk when the first SCSI
> command returns UNIT_ATTENTION as the sense key.
> 
> Again, I have deliberately made the default value for this parameter 0,
> which means that the end-user will need to ensure insmod or modprobe
> supplies a >0 value to firmware_delay before the patch takes effect.
> 
> I'm not sure what the procedure is for getting this patch officially
> recognised for inclusion into the kernel - Alan, are you able to "sponsor"
> this patch for inclusion?

How about the patch below instead?  It's a bit easier to use, in that it 
doesn't require users to know about a new parameter.  Also it retries at 
1-second intervals for up to 5 seconds, which makes it a little more 
flexible.  If this works for you, I'll submit it for inclusion in the 
official kernel.

Alan Stern


Index: usb-2.6/drivers/scsi/sd.c
===================================================================
--- usb-2.6.orig/drivers/scsi/sd.c
+++ usb-2.6/drivers/scsi/sd.c
@@ -987,7 +987,7 @@ static void
 sd_spinup_disk(struct scsi_disk *sdkp, char *diskname,
 	       struct scsi_request *SRpnt, unsigned char *buffer) {
 	unsigned char cmd[10];
-	unsigned long spintime_value = 0;
+	unsigned long spintime_expire = 0;
 	int retries, spintime;
 	unsigned int the_result;
 	struct scsi_sense_hdr sshdr;
@@ -1074,12 +1074,27 @@ sd_spinup_disk(struct scsi_disk *sdkp, c
 				scsi_wait_req(SRpnt, (void *)cmd, 
 					      (void *) buffer, 0/*512*/, 
 					      SD_TIMEOUT, SD_MAX_RETRIES);
-				spintime_value = jiffies;
+				spintime_expire = jiffies + 100 * HZ;
+				spintime = 1;
 			}
-			spintime = 1;
 			/* Wait 1 second for next try */
 			msleep(1000);
 			printk(".");
+
+		/*
+		 * Wait for USB flash devices with slow firmware.
+		 * Yes, this sense key/ASC combination shouldn't
+		 * occur here.  It's typical of these devices.
+		 */
+		} else if (sense_valid &&
+				sshdr.sense_key == UNIT_ATTENTION &&
+				sshdr.asc == 0x28) {
+			if (!spintime) {
+				spintime_expire = jiffies + 5 * HZ;
+				spintime = 1;
+			}
+			/* Wait 1 second for next try */
+			msleep(1000);
 		} else {
 			/* we don't understand the sense code, so it's
 			 * probably pointless to loop */
@@ -1091,8 +1106,7 @@ sd_spinup_disk(struct scsi_disk *sdkp, c
 			break;
 		}
 				
-	} while (spintime &&
-		 time_after(spintime_value + 100 * HZ, jiffies));
+	} while (spintime && time_before_eq(jiffies, spintime_expire));
 
 	if (spintime) {
 		if (scsi_status_is_good(the_result))


  reply	other threads:[~2005-07-11 19:27 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2005-07-11  3:45 [linux-usb-devel] Kernel unable to read partition table on US B Memory Key Roberts-Thomson, James
2005-07-11 19:27 ` Alan Stern [this message]
  -- strict thread matches above, loose matches on Subject: below --
2005-07-11 23:32 Roberts-Thomson, James
2005-07-11  0:07 Roberts-Thomson, James
2005-07-06  2:48 Roberts-Thomson, James
2005-07-06 14:30 ` Alan Stern
2005-07-05 21:19 Roberts-Thomson, James
2005-07-05 22:08 ` Alan Stern

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=Pine.LNX.4.44L0.0507111506570.6399-100000@iolanthe.rowland.org \
    --to=stern@rowland.harvard.edu \
    --cc=James.Roberts-Thomson@NBNZ.CO.NZ \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-usb-devel@lists.sourceforge.net \
    --cc=s.rivoir@gts.it \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).