linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: "Roberts-Thomson, James" <James.Roberts-Thomson@NBNZ.CO.NZ>
To: "'Alan Stern'" <stern@rowland.harvard.edu>
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:45:16 +1200	[thread overview]
Message-ID: <40BC5D4C2DD333449FBDE8AE961E0C334F9385@psexc03.nbnz.co.nz> (raw)

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

All,

> > Can you try adding delays before, after, and inbetween the calls to 
> > sd_read_capacity, sd_read_write_protect_flag, and 
> sd_read_cache_type, 
> > all near the end of sd_revalidate_disk?
> 
> Yes, will do this and post results.

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?

Thanks,

James Roberts-Thomson
----------
Hardware:  The parts of a computer system that can be kicked.

Mailing list Readers:  Please ignore the following disclaimer - this email
is explicitly declared to be non confidential and does not contain
privileged information.


This communication is confidential and may contain privileged material.
If you are not the intended recipient you must not use, disclose, copy or retain it.
If you have received it in error please immediately notify me by return email
and delete the emails.
Thank you.

[-- Attachment #2: oti-usb-key-v2.patch --]
[-- Type: application/octet-stream, Size: 1119 bytes --]

--- /home/n202042/src/kernel2612/linux-2.6.12/drivers/scsi/sd.c	2005-06-18 07:48:29.000000000 +1200
+++ /usr/src/linux/drivers/scsi/sd.c	2005-07-11 15:40:45.000000000 +1200
@@ -89,6 +89,10 @@
 #define SD_MAX_RETRIES		5
 #define SD_PASSTHROUGH_RETRIES	1
 
+static unsigned int firmware_delay = 0;
+module_param(firmware_delay, uint, S_IRUGO | S_IWUSR);
+MODULE_PARM_DESC(firmware_delay, "Optional number of seconds delay for dodgy USB keys to settle");
+
 static void scsi_disk_release(struct kref *kref);
 
 struct scsi_disk {
@@ -1080,6 +1084,12 @@ sd_spinup_disk(struct scsi_disk *sdkp, c
 			/* Wait 1 second for next try */
 			msleep(1000);
 			printk(".");
+		} else if (sense_valid && sshdr.sense_key == UNIT_ATTENTION && firmware_delay > 0 ) {
+				/* Some USB flash drives need a small delay (perhaps to allow internal firmware
+				 * time to initialise
+				 */
+				printk(KERN_NOTICE "%s: Allowing time for firmware initialisation\n", diskname);
+				msleep(firmware_delay * HZ);
 		} else {
 			/* we don't understand the sense code, so it's
 			 * probably pointless to loop */

             reply	other threads:[~2005-07-11  3:45 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2005-07-11  3:45 Roberts-Thomson, James [this message]
2005-07-11 19:27 ` [linux-usb-devel] Kernel unable to read partition table on US B Memory Key Alan Stern
  -- 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=40BC5D4C2DD333449FBDE8AE961E0C334F9385@psexc03.nbnz.co.nz \
    --to=james.roberts-thomson@nbnz.co.nz \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-usb-devel@lists.sourceforge.net \
    --cc=s.rivoir@gts.it \
    --cc=stern@rowland.harvard.edu \
    /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).