public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH repost 3] [SCSI] Retrieve the Caching mode page
@ 2010-11-22 16:56 Luben Tuikov
  2010-11-22 17:07 ` Linus Torvalds
  0 siblings, 1 reply; 25+ messages in thread
From: Luben Tuikov @ 2010-11-22 16:56 UTC (permalink / raw)
  To: linux-kernel, linux-scsi, linux-usb, Greg KH, James Bottomley,
	Linus Torvalds

Some kernel transport drivers unconditionally disable
retrieval of the Caching mode page. One such for example is
the BBB/CBI transport over USB.  Such a restraint is too
harsh as some devices do support the Caching mode
page. Unconditionally enabling the retrieval of this mode
page over those transports at their transport code level may
result in some devices failing and becoming unusable.

This patch implements a method of retrieving the Caching
mode page without unconditionally enabling it in the
transports which unconditionally disable it. The idea is to
ask for all supported pages, page code 0x3F, and then search
for the Caching mode page in the mode parameter data
returned. The sd driver already asks for all the mode pages
supported by the attached device by setting the page code to
0x3F in order to find out if the media is write protected by
reading the WP bit in the Device Specific Parameter
field. It then attempts to retrieve only the Caching mode
page by setting the page code to 8 and actually attempting
to retrieve it if and only if the transport allows it.

The method implemented here is that if the transport doesn't
allow retrieval of the Caching mode page and the device is
not RBC, then we ask for all pages supported by setting the
page code to 0x3F (similarly to how the WP bit is retrieved
above), and then we search for the Caching mode page in the
mode parameter data returned.

With this patch, devices over SATA, report this (no change):

Oct 22 18:45:58 localhost kernel: sd 0:0:0:0: [sda] 976773168 512-byte logical blocks: (500 GB/465 GiB)
Oct 22 18:45:58 localhost kernel: sd 0:0:0:0: Attached scsi generic sg0 type 0
Oct 22 18:45:58 localhost kernel: sd 0:0:0:0: [sda] Write Protect is off
Oct 22 18:45:58 localhost kernel: sd 0:0:0:0: [sda] Mode Sense: 00 3a 00 00
Oct 22 18:45:58 localhost kernel: sd 0:0:0:0: [sda] Write cache: enabled, read cache: enabled, doesn't support DPO or FUA

Smart devices report their Caching mode page. This is a
change where we'd previously see the kernel making
assumption about the device's cache being write-through:

Oct 22 18:45:58 localhost kernel: sd 6:0:0:0: Attached scsi generic sg2 type 0
Oct 22 18:45:58 localhost kernel: sd 6:0:0:0: [sdb] 610472646 4096-byte logical blocks: (2.50 TB/2.27 TiB)
Oct 22 18:45:58 localhost kernel: sd 6:0:0:0: [sdb] Write Protect is off
Oct 22 18:45:58 localhost kernel: sd 6:0:0:0: [sdb] Mode Sense: 47 00 10 08
Oct 22 18:45:58 localhost kernel: sd 6:0:0:0: [sdb] Write cache: enabled, read cache: enabled, supports DPO and FUA

And "dumb" devices over BBB, are correctly shown not to
support reporting the Caching mode page:

Oct 22 18:49:06 localhost kernel: sd 7:0:0:0: [sdc] 15663104 512-byte logical blocks: (8.01 GB/7.46 GiB)
Oct 22 18:49:06 localhost kernel: sd 7:0:0:0: [sdc] Write Protect is off
Oct 22 18:49:06 localhost kernel: sd 7:0:0:0: [sdc] Mode Sense: 23 00 00 00
Oct 22 18:49:06 localhost kernel: sd 7:0:0:0: [sdc] No Caching mode page present
Oct 22 18:49:06 localhost kernel: sd 7:0:0:0: [sdc] Assuming drive cache: write through

Signed-off-by: Luben Tuikov <ltuikov@yahoo.com>
---
 drivers/scsi/sd.c |   63 +++++++++++++++++++++++++++++++++++++++-------------
 1 files changed, 47 insertions(+), 16 deletions(-)

diff --git a/drivers/scsi/sd.c b/drivers/scsi/sd.c
index ffa0689..81e83d7 100644
--- a/drivers/scsi/sd.c
+++ b/drivers/scsi/sd.c
@@ -1867,10 +1867,14 @@ sd_read_cache_type(struct scsi_disk *sdkp, unsigned char *buffer)
        int old_rcd = sdkp->RCD;
        int old_dpofua = sdkp->DPOFUA;
 
-       if (sdp->skip_ms_page_8)
-               goto defaults;
-
-       if (sdp->type == TYPE_RBC) {
+       if (sdp->skip_ms_page_8) {
+               if (sdp->type == TYPE_RBC)
+                       goto defaults;
+               else {
+                       modepage = 0x3F;
+                       dbd = 0;
+               }
+       } else if (sdp->type == TYPE_RBC) {
                modepage = 6;
                dbd = 8;
        } else {
@@ -1898,13 +1902,11 @@ sd_read_cache_type(struct scsi_disk *sdkp, unsigned char *buffer)
         */
        if (len < 3)
                goto bad_sense;
-       if (len > 20)
-               len = 20;
-
-       /* Take headers and block descriptors into account */
-       len += data.header_length + data.block_descriptor_length;
-       if (len > SD_BUF_SIZE)
-               goto bad_sense;
+       else if (len > SD_BUF_SIZE) {
+               sd_printk(KERN_NOTICE, sdkp, "Truncating mode parameter "
+                         "data from %d to %d bytes\n", len, SD_BUF_SIZE);
+               len = SD_BUF_SIZE;
+       }
 
        /* Get the data */
        res = sd_do_mode_sense(sdp, dbd, modepage, buffer, len, &data, &sshdr);
@@ -1912,16 +1914,45 @@ sd_read_cache_type(struct scsi_disk *sdkp, unsigned char *buffer)
        if (scsi_status_is_good(res)) {
                int offset = data.header_length + data.block_descriptor_length;
 
-               if (offset >= SD_BUF_SIZE - 2) {
-                       sd_printk(KERN_ERR, sdkp, "Malformed MODE SENSE response\n");
-                       goto defaults;
+               while (offset < len) {
+                       u8 page_code = buffer[offset] & 0x3F;
+                       u8 spf       = buffer[offset] & 0x40;
+
+                       if (page_code == 8 || page_code == 6) {
+                               /* We're interested only in the first 3 bytes.
+                                */
+                               if (len - offset <= 2) {
+                                       sd_printk(KERN_ERR, sdkp, "Incomplete "
+                                                 "mode parameter data\n");
+                                       goto defaults;
+                               } else {
+                                       modepage = page_code;
+                                       goto Page_found;
+                               }
+                       } else {
+                               /* Go to the next page */
+                               if (spf && len - offset > 3)
+                                       offset += 4 + (buffer[offset+2] << 8) +
+                                               buffer[offset+3];
+                               else if (!spf && len - offset > 1)
+                                       offset += 2 + buffer[offset+1];
+                               else {
+                                       sd_printk(KERN_ERR, sdkp, "Incomplete "
+                                                 "mode parameter data\n");
+                                       goto defaults;
+                               }
+                       }
                }
 
-               if ((buffer[offset] & 0x3f) != modepage) {
+               if (modepage == 0x3F) {
+                       sd_printk(KERN_ERR, sdkp, "No Caching mode page "
+                                 "present\n");
+                       goto defaults;
+               } else if ((buffer[offset] & 0x3f) != modepage) {
                        sd_printk(KERN_ERR, sdkp, "Got wrong page\n");
                        goto defaults;
                }
-
+       Page_found:
                if (modepage == 8) {
                        sdkp->WCE = ((buffer[offset + 2] & 0x04) != 0);
                        sdkp->RCD = ((buffer[offset + 2] & 0x01) != 0);
-- 
1.7.2.2.165.gbc382


^ permalink raw reply related	[flat|nested] 25+ messages in thread
* Re: [PATCH repost 3] [SCSI] Retrieve the Caching mode page
@ 2010-11-23  8:43 Luben Tuikov
  0 siblings, 0 replies; 25+ messages in thread
From: Luben Tuikov @ 2010-11-23  8:43 UTC (permalink / raw)
  To: Douglas Gilbert, Matthew Dharm
  Cc: Linus Torvalds, linux-kernel, linux-scsi, linux-usb, Greg KH,
	James Bottomley

--- On Mon, 11/22/10, Matthew Dharm <mdharm-kernel@one-eyed-alien.net> wrote:

> That said, Luben's patch is kinda slick.

Thank you.

> sd-modalready asks for a lot of
> mode page data; it does this so that it's request matches
> the observed
> behavior of a "popular" Redmond, WA-based OS.  Luben's
> patch just searches
> through that data to see if it can find what it is looking
> for, rather than
> rqeuesting a specific mode page later (which may not be
> supported).

Yes, devices wouldn't sense a change in requests. The patch preserves this quality of device discovery.

   Luben


^ permalink raw reply	[flat|nested] 25+ messages in thread
* Re: [PATCH repost 3] [SCSI] Retrieve the Caching mode page
@ 2010-12-05 20:53 Luben Tuikov
  0 siblings, 0 replies; 25+ messages in thread
From: Luben Tuikov @ 2010-12-05 20:53 UTC (permalink / raw)
  To: James Bottomley
  Cc: Matthew Dharm, Linus Torvalds, linux-kernel, linux-scsi,
	linux-usb, Greg KH

--- On Wed, 11/24/10, Luben Tuikov <ltuikov@yahoo.com> wrote:
> 
> CBI/BBB isn't supposed to be, nor is designed to support
> SAM-modern devices. So while REQUEST LUN /may/ work on some
> devices which implement it in their firmware, it is NOT a
> requirement for those devices as they are not required to
> adhere to any SAM version. Those transport protocols define
> a class-specific request to get the maximum LUN, and another
> to reset the target port (instead of I_T Reset or LU Reset).
> They also do not support SCSI Status completion of the
> command, nor Autosense. They also do not provide TMFs. They
> provide none of the SCSI transport protocol services in
> support of the Execute Command procedure call. The SCSI
> layer shouldn't be trying to guess their "SCSI version", and
> or treat them as real SCSI devices sending REPORT LUNs, etc.
> commands.
> 
> Newer, modern transport protocols over USB, are part of
> SAM, and it is devices who connect via those protocols that
> are being disadvantaged, due to the adoption (assumption) of
> CBI/BBB well into the SCSI layer.
> 
> To this effect, the transport protocol can tell upper
> layers if the device is true SCSI (new usb transports or
> other) or hybrid (usb-storage). In the former case, the
> device is a SCSI device, in the latter, only basic commands
> should be attempted.
> 
> This isn't to say that firmware for those devices wouldn't
> be buggy. Of course it will, and most will probably port
> their legacy FW over to the new SPTL, but the protocol
> requirements are there by design (i.e. there is no longer
> Get Max Lun class-specific request, the application client
> has to send REPORT LUNS, and FW has to answer it) and we
> have to accommodate that.
> 
> It is in this spirit that this patch doesn't change wire
> behavior, but simply parses data returned by a command
> already supported by older protocols.

Did anyone pick up this patch?

    Luben


^ permalink raw reply	[flat|nested] 25+ messages in thread
* Re: [PATCH repost 3] [SCSI] Retrieve the Caching mode page
@ 2010-12-08  0:02 Luben Tuikov
  2010-12-08  0:12 ` Greg KH
  0 siblings, 1 reply; 25+ messages in thread
From: Luben Tuikov @ 2010-12-08  0:02 UTC (permalink / raw)
  To: James Bottomley
  Cc: Matthew Dharm, Linus Torvalds, linux-kernel, linux-scsi,
	linux-usb, Greg KH

--- On Sun, 12/5/10, Luben Tuikov <ltuikov@yahoo.com> wrote:
> --- On Wed, 11/24/10, Luben Tuikov
> <ltuikov@yahoo.com>
> wrote:
> > 
> > CBI/BBB isn't supposed to be, nor is designed to
> support
> > SAM-modern devices. So while REQUEST LUN /may/ work on
> some
> > devices which implement it in their firmware, it is
> NOT a
> > requirement for those devices as they are not required
> to
> > adhere to any SAM version. Those transport protocols
> define
> > a class-specific request to get the maximum LUN, and
> another
> > to reset the target port (instead of I_T Reset or LU
> Reset).
> > They also do not support SCSI Status completion of
> the
> > command, nor Autosense. They also do not provide TMFs.
> They
> > provide none of the SCSI transport protocol services
> in
> > support of the Execute Command procedure call. The
> SCSI
> > layer shouldn't be trying to guess their "SCSI
> version", and
> > or treat them as real SCSI devices sending REPORT
> LUNs, etc.
> > commands.
> > 
> > Newer, modern transport protocols over USB, are part
> of
> > SAM, and it is devices who connect via those protocols
> that
> > are being disadvantaged, due to the adoption
> (assumption) of
> > CBI/BBB well into the SCSI layer.
> > 
> > To this effect, the transport protocol can tell upper
> > layers if the device is true SCSI (new usb transports
> or
> > other) or hybrid (usb-storage). In the former case,
> the
> > device is a SCSI device, in the latter, only basic
> commands
> > should be attempted.
> > 
> > This isn't to say that firmware for those devices
> wouldn't
> > be buggy. Of course it will, and most will probably
> port
> > their legacy FW over to the new SPTL, but the
> protocol
> > requirements are there by design (i.e. there is no
> longer
> > Get Max Lun class-specific request, the application
> client
> > has to send REPORT LUNS, and FW has to answer it) and
> we
> > have to accommodate that.
> > 
> > It is in this spirit that this patch doesn't change
> wire
> > behavior, but simply parses data returned by a
> command
> > already supported by older protocols.
> 
> Did anyone pick up this patch?

It's been over 6 weeks now that this patch's been in these mailing lists.
Will anyone pick up this patch, or should I stop posting it every week? Please let me know--it's been posted here 6 times in the last 6 weeks.

Thanks,
   Luben


^ permalink raw reply	[flat|nested] 25+ messages in thread

end of thread, other threads:[~2010-12-08 16:00 UTC | newest]

Thread overview: 25+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2010-11-22 16:56 [PATCH repost 3] [SCSI] Retrieve the Caching mode page Luben Tuikov
2010-11-22 17:07 ` Linus Torvalds
2010-11-22 19:02   ` Douglas Gilbert
2010-11-23  4:59     ` Matthew Dharm
2010-11-23 18:40       ` Douglas Gilbert
2010-11-22 20:02   ` Luben Tuikov
2010-11-23  5:00     ` Matthew Dharm
2010-11-23  9:25       ` Luben Tuikov
2010-11-23 14:30         ` Matthew Dharm
2010-11-24  9:02           ` Luben Tuikov
2010-11-24 10:10             ` James Bottomley
2010-11-24 14:48               ` Christoph Hellwig
2010-11-24 14:49               ` Alan Stern
2010-11-24 14:58                 ` James Bottomley
2010-11-24 16:55               ` Luben Tuikov
  -- strict thread matches above, loose matches on Subject: below --
2010-11-23  8:43 Luben Tuikov
2010-12-05 20:53 Luben Tuikov
2010-12-08  0:02 Luben Tuikov
2010-12-08  0:12 ` Greg KH
2010-12-08  5:05   ` James Bottomley
2010-12-08  8:01     ` Luben Tuikov
2010-12-08 15:16     ` Alan Stern
2010-12-08 15:43       ` James Bottomley
2010-12-08 15:57         ` Alan Stern
2010-12-08 16:00           ` Matthew Wilcox

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox