Re: usb/160299: MicroSDHC-to-USB adapters do not work in FreeBSD 8.x

2014-04-19 Thread linimon
Synopsis: MicroSDHC-to-USB adapters do not work in FreeBSD 8.x

State-Changed-From-To: open->closed
State-Changed-By: linimon
State-Changed-When: Sun Apr 20 02:55:21 UTC 2014
State-Changed-Why: 
committed and MFCed.


Responsible-Changed-From-To: freebsd-usb->hselasky
Responsible-Changed-By: linimon
Responsible-Changed-When: Sun Apr 20 02:55:21 UTC 2014
Responsible-Changed-Why: 

http://www.freebsd.org/cgi/query-pr.cgi?pr=160299
___
freebsd-usb@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-usb
To unsubscribe, send any mail to "freebsd-usb-unsubscr...@freebsd.org"


Re: usb/160299: MicroSDHC-to-USB adapters do not work in FreeBSD 8.x

2011-08-30 Thread Brett Glass
The following reply was made to PR usb/160299; it has been noted by GNATS.

From: Brett Glass 
To: Hans Petter Selasky , freebsd-usb@freebsd.org
Cc: Brett Glass , freebsd-gnats-sub...@freebsd.org
Subject: Re: usb/160299: MicroSDHC-to-USB adapters do not work in
  FreeBSD 8.x
Date: Tue, 30 Aug 2011 10:36:02 -0600

 Hans:
 
 This would help. Empirical testing of the device isn't as good as
 recognizing that it's a flash drive or flash adapter, but it might
 help with unusual devices such as cellular phones and USB CD-ROM
 drives.
 
 --Brett Glass
 
___
freebsd-usb@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-usb
To unsubscribe, send any mail to "freebsd-usb-unsubscr...@freebsd.org"


Re: usb/160299: MicroSDHC-to-USB adapters do not work in FreeBSD 8.x

2011-08-30 Thread Brett Glass

Hans:

This would help. Empirical testing of the device isn't as good as
recognizing that it's a flash drive or flash adapter, but it might
help with unusual devices such as cellular phones and USB CD-ROM
drives.

--Brett Glass

___
freebsd-usb@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-usb
To unsubscribe, send any mail to "freebsd-usb-unsubscr...@freebsd.org"


Re: usb/160299: MicroSDHC-to-USB adapters do not work in FreeBSD 8.x

2011-08-30 Thread Hans Petter Selasky
The following reply was made to PR usb/160299; it has been noted by GNATS.

From: Hans Petter Selasky 
To: freebsd-usb@freebsd.org
Cc: Brett Glass ,
 freebsd-gnats-sub...@freebsd.org
Subject: Re: usb/160299: MicroSDHC-to-USB adapters do not work in FreeBSD 8.x
Date: Tue, 30 Aug 2011 13:26:58 +0200

 --Boundary-00=_CkMXOqbZCgU0ukV
 Content-Type: text/plain;
   charset="iso-8859-15"
 Content-Transfer-Encoding: 7bit
 
 > >Fix:
 > This behavior is so common that it should not be characterized as a quirk
 > but as a general property of USB flash devices. All USB flash storage
 > devices should have SYNCHRONIZE CACHE and similar SCSI commands disabled
 > by default. These commands should, of course, be enabled for USB-attached
 > ATAPI rotating media, which supports them.
 > 
 > >Release-Note:
 > >Audit-Trail:
 > 
 > >Unformatted:
 
 Hi,
 
 Can everyone using 8-stable or 9-current try this patch and see if it breaks 
 your mass storage device or not:
 
 1) Get latest 8-stable or 9-current sources in /usr/src
 
 2) Apply patch:
 
 cd /usr/src
 cat msc_auto_quirk.patch | patch
 
 3) Build and install new kernel
 
 4) Report back.
 
 --HPS
 
 --Boundary-00=_CkMXOqbZCgU0ukV
 Content-Type: text/x-patch;
   charset="iso-8859-15";
   name="msc_auto_quirk.patch"
 Content-Transfer-Encoding: 7bit
 Content-Disposition: inline;
filename="msc_auto_quirk.patch"
 
 === sys/dev/usb/quirk/usb_quirk.c
 ==
 --- sys/dev/usb/quirk/usb_quirk.c  (revision 225095)
 +++ sys/dev/usb/quirk/usb_quirk.c  (local)
 @@ -148,12 +148,10 @@
UQ_MSC_FORCE_PROTO_SCSI),
USB_QUIRK(AIPTEK, POCKETCAM3M, 0x, 0x, UQ_MSC_FORCE_WIRE_BBB,
UQ_MSC_FORCE_PROTO_SCSI),
 -  USB_QUIRK(AIPTEK2, SUNPLUS_TECH, 0x, 0x, UQ_MSC_NO_SYNC_CACHE),
USB_QUIRK(ALCOR, SDCR_6335, 0x, 0x, UQ_MSC_NO_TEST_UNIT_READY,
UQ_MSC_NO_SYNC_CACHE),
USB_QUIRK(ALCOR, SDCR_6362, 0x, 0x, UQ_MSC_NO_TEST_UNIT_READY,
UQ_MSC_NO_SYNC_CACHE),
 -  USB_QUIRK(ALCOR, AU6390, 0x, 0x, UQ_MSC_NO_SYNC_CACHE),
USB_QUIRK(ALCOR, UMCR_9361, 0x, 0x, UQ_MSC_FORCE_WIRE_BBB,
UQ_MSC_FORCE_PROTO_SCSI, UQ_MSC_NO_GETMAXLUN),
USB_QUIRK(ALCOR, TRANSCEND, 0x, 0x, UQ_MSC_NO_GETMAXLUN,
 @@ -173,14 +171,12 @@
USB_QUIRK(CENTURY, EX35QUAT, 0x, 0x, UQ_MSC_FORCE_WIRE_BBB,
UQ_MSC_FORCE_PROTO_SCSI, UQ_MSC_FORCE_SHORT_INQ,
UQ_MSC_NO_START_STOP, UQ_MSC_IGNORE_RESIDUE),
 -  USB_QUIRK(CENTURY, EX35SW4_SB4, 0x, 0x, UQ_MSC_NO_SYNC_CACHE),
USB_QUIRK(CYPRESS, XX6830XX, 0x, 0x, UQ_MSC_NO_GETMAXLUN,
UQ_MSC_NO_SYNC_CACHE),
USB_QUIRK(DESKNOTE, UCR_61S2B, 0x, 0x, UQ_MSC_FORCE_WIRE_BBB,
UQ_MSC_FORCE_PROTO_SCSI),
USB_QUIRK(DMI, CFSM_RW, 0x, 0x, UQ_MSC_FORCE_PROTO_SCSI,
UQ_MSC_NO_GETMAXLUN),
 -  USB_QUIRK(DMI, DISK, 0x000, 0x, UQ_MSC_NO_SYNC_CACHE),
USB_QUIRK(EPSON, STYLUS_875DC, 0x, 0x, UQ_MSC_FORCE_WIRE_CBI,
UQ_MSC_FORCE_PROTO_SCSI, UQ_MSC_NO_INQUIRY),
USB_QUIRK(EPSON, STYLUS_895, 0x, 0x, UQ_MSC_FORCE_WIRE_BBB,
 @@ -188,7 +184,6 @@
USB_QUIRK(FEIYA, 5IN1, 0x, 0x, UQ_MSC_FORCE_WIRE_BBB,
UQ_MSC_FORCE_PROTO_SCSI),
USB_QUIRK(FREECOM, DVD, 0x, 0x, UQ_MSC_FORCE_PROTO_SCSI),
 -  USB_QUIRK(FREECOM, HDD, 0x, 0x, UQ_MSC_NO_SYNC_CACHE),
USB_QUIRK(FUJIPHOTO, MASS0100, 0x, 0x, UQ_MSC_FORCE_WIRE_CBI_I,
UQ_MSC_FORCE_PROTO_ATAPI, UQ_MSC_NO_RS_CLEAR_UA, 
UQ_MSC_NO_SYNC_CACHE),
USB_QUIRK(GENESYS, GL641USB2IDE, 0x, 0x, UQ_MSC_FORCE_WIRE_BBB,
 @@ -232,7 +227,6 @@
USB_QUIRK(IOMEGA, ZIP100, 0x, 0x, UQ_MSC_FORCE_WIRE_BBB,
UQ_MSC_FORCE_PROTO_SCSI,
UQ_MSC_NO_TEST_UNIT_READY), /* XXX ZIP drives can also use ATAPI */
 -  USB_QUIRK(JMICRON, JM20336, 0x, 0x, UQ_MSC_NO_SYNC_CACHE),
USB_QUIRK(JMICRON, JM20337, 0x, 0x, UQ_MSC_FORCE_WIRE_BBB,
UQ_MSC_FORCE_PROTO_SCSI,
UQ_MSC_NO_SYNC_CACHE),
 @@ -279,8 +273,6 @@
UQ_MSC_FORCE_PROTO_ATAPI),
USB_QUIRK(MYSON, HEDEN, 0x, 0x, UQ_MSC_IGNORE_RESIDUE,
UQ_MSC_NO_SYNC_CACHE),
 -  USB_QUIRK(MYSON, HEDEN_8813, 0x, 0x, UQ_MSC_NO_SYNC_CACHE),
 -  USB_QUIRK(MYSON, STARREADER, 0x, 0x, UQ_MSC_NO_SYNC_CACHE),
USB_QUIRK(NEODIO, ND3260, 0x, 0x, UQ_MSC_FORCE_WIRE_BBB,
UQ_MSC_FORCE_PROTO_SCSI, UQ_MSC_FORCE_SHORT_INQ),
USB_QUIRK(NETAC, CF_CARD, 0x, 0x, UQ_MSC_FORCE_WIRE_BBB,
 @@ -317,7 +309,6 @@
USB_QUIRK(PANASONIC, KXLCB35AN, 0x, 0x, UQ_MSC_FORCE_WIRE_BBB,
UQ_MSC_FORCE_PROTO_SCSI),
USB_QUIRK(PANASONIC, LS120CAM, 

Re: usb/160299: MicroSDHC-to-USB adapters do not work in FreeBSD 8.x

2011-08-30 Thread Hans Petter Selasky
> >Fix:
> This behavior is so common that it should not be characterized as a quirk
> but as a general property of USB flash devices. All USB flash storage
> devices should have SYNCHRONIZE CACHE and similar SCSI commands disabled
> by default. These commands should, of course, be enabled for USB-attached
> ATAPI rotating media, which supports them.
> 
> >Release-Note:
> >Audit-Trail:
> 
> >Unformatted:

Hi,

Can everyone using 8-stable or 9-current try this patch and see if it breaks 
your mass storage device or not:

1) Get latest 8-stable or 9-current sources in /usr/src

2) Apply patch:

cd /usr/src
cat msc_auto_quirk.patch | patch

3) Build and install new kernel

4) Report back.

--HPS
=== sys/dev/usb/quirk/usb_quirk.c
==
--- sys/dev/usb/quirk/usb_quirk.c	(revision 225095)
+++ sys/dev/usb/quirk/usb_quirk.c	(local)
@@ -148,12 +148,10 @@
 	UQ_MSC_FORCE_PROTO_SCSI),
 	USB_QUIRK(AIPTEK, POCKETCAM3M, 0x, 0x, UQ_MSC_FORCE_WIRE_BBB,
 	UQ_MSC_FORCE_PROTO_SCSI),
-	USB_QUIRK(AIPTEK2, SUNPLUS_TECH, 0x, 0x, UQ_MSC_NO_SYNC_CACHE),
 	USB_QUIRK(ALCOR, SDCR_6335, 0x, 0x, UQ_MSC_NO_TEST_UNIT_READY,
 	UQ_MSC_NO_SYNC_CACHE),
 	USB_QUIRK(ALCOR, SDCR_6362, 0x, 0x, UQ_MSC_NO_TEST_UNIT_READY,
 	UQ_MSC_NO_SYNC_CACHE),
-	USB_QUIRK(ALCOR, AU6390, 0x, 0x, UQ_MSC_NO_SYNC_CACHE),
 	USB_QUIRK(ALCOR, UMCR_9361, 0x, 0x, UQ_MSC_FORCE_WIRE_BBB,
 	UQ_MSC_FORCE_PROTO_SCSI, UQ_MSC_NO_GETMAXLUN),
 	USB_QUIRK(ALCOR, TRANSCEND, 0x, 0x, UQ_MSC_NO_GETMAXLUN,
@@ -173,14 +171,12 @@
 	USB_QUIRK(CENTURY, EX35QUAT, 0x, 0x, UQ_MSC_FORCE_WIRE_BBB,
 	UQ_MSC_FORCE_PROTO_SCSI, UQ_MSC_FORCE_SHORT_INQ,
 	UQ_MSC_NO_START_STOP, UQ_MSC_IGNORE_RESIDUE),
-	USB_QUIRK(CENTURY, EX35SW4_SB4, 0x, 0x, UQ_MSC_NO_SYNC_CACHE),
 	USB_QUIRK(CYPRESS, XX6830XX, 0x, 0x, UQ_MSC_NO_GETMAXLUN,
 	UQ_MSC_NO_SYNC_CACHE),
 	USB_QUIRK(DESKNOTE, UCR_61S2B, 0x, 0x, UQ_MSC_FORCE_WIRE_BBB,
 	UQ_MSC_FORCE_PROTO_SCSI),
 	USB_QUIRK(DMI, CFSM_RW, 0x, 0x, UQ_MSC_FORCE_PROTO_SCSI,
 	UQ_MSC_NO_GETMAXLUN),
-	USB_QUIRK(DMI, DISK, 0x000, 0x, UQ_MSC_NO_SYNC_CACHE),
 	USB_QUIRK(EPSON, STYLUS_875DC, 0x, 0x, UQ_MSC_FORCE_WIRE_CBI,
 	UQ_MSC_FORCE_PROTO_SCSI, UQ_MSC_NO_INQUIRY),
 	USB_QUIRK(EPSON, STYLUS_895, 0x, 0x, UQ_MSC_FORCE_WIRE_BBB,
@@ -188,7 +184,6 @@
 	USB_QUIRK(FEIYA, 5IN1, 0x, 0x, UQ_MSC_FORCE_WIRE_BBB,
 	UQ_MSC_FORCE_PROTO_SCSI),
 	USB_QUIRK(FREECOM, DVD, 0x, 0x, UQ_MSC_FORCE_PROTO_SCSI),
-	USB_QUIRK(FREECOM, HDD, 0x, 0x, UQ_MSC_NO_SYNC_CACHE),
 	USB_QUIRK(FUJIPHOTO, MASS0100, 0x, 0x, UQ_MSC_FORCE_WIRE_CBI_I,
 	UQ_MSC_FORCE_PROTO_ATAPI, UQ_MSC_NO_RS_CLEAR_UA, UQ_MSC_NO_SYNC_CACHE),
 	USB_QUIRK(GENESYS, GL641USB2IDE, 0x, 0x, UQ_MSC_FORCE_WIRE_BBB,
@@ -232,7 +227,6 @@
 	USB_QUIRK(IOMEGA, ZIP100, 0x, 0x, UQ_MSC_FORCE_WIRE_BBB,
 	UQ_MSC_FORCE_PROTO_SCSI,
 	UQ_MSC_NO_TEST_UNIT_READY), /* XXX ZIP drives can also use ATAPI */
-	USB_QUIRK(JMICRON, JM20336, 0x, 0x, UQ_MSC_NO_SYNC_CACHE),
 	USB_QUIRK(JMICRON, JM20337, 0x, 0x, UQ_MSC_FORCE_WIRE_BBB,
 	UQ_MSC_FORCE_PROTO_SCSI,
 	UQ_MSC_NO_SYNC_CACHE),
@@ -279,8 +273,6 @@
 	UQ_MSC_FORCE_PROTO_ATAPI),
 	USB_QUIRK(MYSON, HEDEN, 0x, 0x, UQ_MSC_IGNORE_RESIDUE,
 	UQ_MSC_NO_SYNC_CACHE),
-	USB_QUIRK(MYSON, HEDEN_8813, 0x, 0x, UQ_MSC_NO_SYNC_CACHE),
-	USB_QUIRK(MYSON, STARREADER, 0x, 0x, UQ_MSC_NO_SYNC_CACHE),
 	USB_QUIRK(NEODIO, ND3260, 0x, 0x, UQ_MSC_FORCE_WIRE_BBB,
 	UQ_MSC_FORCE_PROTO_SCSI, UQ_MSC_FORCE_SHORT_INQ),
 	USB_QUIRK(NETAC, CF_CARD, 0x, 0x, UQ_MSC_FORCE_WIRE_BBB,
@@ -317,7 +309,6 @@
 	USB_QUIRK(PANASONIC, KXLCB35AN, 0x, 0x, UQ_MSC_FORCE_WIRE_BBB,
 	UQ_MSC_FORCE_PROTO_SCSI),
 	USB_QUIRK(PANASONIC, LS120CAM, 0x, 0x, UQ_MSC_FORCE_PROTO_UFI),
-	USB_QUIRK(PHILIPS, SPE3030CC, 0x, 0x, UQ_MSC_NO_SYNC_CACHE),
 	USB_QUIRK(PLEXTOR, 40_12_40U, 0x, 0x, UQ_MSC_FORCE_WIRE_BBB,
 	UQ_MSC_FORCE_PROTO_SCSI, UQ_MSC_NO_TEST_UNIT_READY),
 	USB_QUIRK(PNY, ATTACHE2, 0x, 0x, UQ_MSC_FORCE_WIRE_BBB,
@@ -328,7 +319,6 @@
 	USB_QUIRK_VP(USB_VENDOR_SAMSUNG_TECHWIN,
 	USB_PRODUCT_SAMSUNG_TECHWIN_DIGIMAX_410, UQ_MSC_FORCE_WIRE_BBB,
 	UQ_MSC_FORCE_PROTO_SCSI, UQ_MSC_NO_INQUIRY),
-	USB_QUIRK(SAMSUNG, YP_U4, 0x, 0x, UQ_MSC_NO_SYNC_CACHE),
 	USB_QUIRK(SANDISK, SDDR05A, 0x, 0x, UQ_MSC_FORCE_WIRE_CBI,
 	UQ_MSC_FORCE_PROTO_SCSI, UQ_MSC_READ_CAP_OFFBY1,
 	UQ_MSC_NO_GETMAXLUN),
@@ -448,12 +438,6 @@
 	UQ_MSC_FORCE_PROTO_ATAPI),
 	USB_QUIRK(MEIZU, M6_SL, 0x, 0x, UQ_MSC_FORCE_WIRE_BBB,
 	UQ_MSC_FORCE_PROTO_SCSI, UQ_MSC_NO_INQUIRY, UQ_MSC_NO_SYNC_CACHE),
-	USB_QUIRK(ACTIONS, MP4, 0x, 0x, UQ_MSC_FORCE_WIRE_BBB,
-	UQ_MSC_FORCE_PROTO_SCSI, UQ_MSC_NO_SYNC_CACHE),
-	USB_QUIRK(ASUS, GMSC, 0x, 0x, UQ_MSC_NO_SYNC_CACHE),
-	USB

Re: usb/160299: MicroSDHC-to-USB adapters do not work in FreeBSD 8.x

2011-08-30 Thread Hans Petter Selasky
The following reply was made to PR usb/160299; it has been noted by GNATS.

From: Hans Petter Selasky 
To: freebsd-usb@freebsd.org
Cc: Brett Glass ,
 freebsd-gnats-sub...@freebsd.org
Subject: Re: usb/160299: MicroSDHC-to-USB adapters do not work in FreeBSD 8.x
Date: Tue, 30 Aug 2011 10:59:52 +0200

 --Boundary-00=_IaKXO97fubXM8EQ
 Content-Type: Text/Plain;
   charset="iso-8859-15"
 Content-Transfer-Encoding: 7bit
 
 On Monday 29 August 2011 23:05:30 Brett Glass wrote:
 > >Number: 160299
 > >Category:   usb
 > >Synopsis:   MicroSDHC-to-USB adapters do not work in FreeBSD 8.x
 > >Confidential:   no
 > >Severity:   serious
 > >Priority:   high
 > >Responsible:freebsd-usb
 > >State:  open
 > >Quarter:
 > >Keywords:
 > >Date-Required:
 > >Class:  sw-bug
 > >Submitter-Id:   current-users
 > >Arrival-Date:   Mon Aug 29 21:10:08 UTC 2011
 > >Closed-Date:
 > >Last-Modified:
 > >Originator: Brett Glass
 > >Release:FreeBSD 8.1-RELEASE
 > 
 > >Organization:
 > LARIAT
 > 
 > >Environment:
 > 
 > >Description:
 > I have tried MicroSDHC cards from several different vendors (Kingston,
 > Sandisk, etc.), with different MicroSDHC-to-USB adapters (also Kingston
 > and Sandisk), in FreeBSD 8.x systems. All cause SCSI errors such as
 > 
 > (da1:umass-sim1:1:0:0): SYNCHRONIZE CACHE(10). CDB: 35 0 0 0 0 0 0 0 0 0
 > (da1:umass-sim1:1:0:0): SCSI sense: Error code 0x52
 > 
 > Some USB flash memory sticks also produce similar errors. In all cases the
 > system sometimes hangs in the driver and the memory card or stick gets
 > quite warm, as if the system is trying the failed operation again and
 > again.
 > 
 > It appears that the problem, which has existed since FreeBSD 4.x, is that
 > the system expects to be able to issue SCSI commands to flash drives
 > (which are not SCSI drives). As a search of recent PRs reveals, this
 > problem has been addressed as a "quirk" on a per-device basis for many
 > individual devices (including memory sticks and cell phones that emulate
 > them), but keeps recurring as new ones are released. A more general fix is
 > needed.
 > 
 > >How-To-Repeat:
 > Place a MicroSDHC card in a USB adapter and insert in a FreeBSD 8.x
 > machine. Try to read and write it.
 > 
 > >Fix:
 > This behavior is so common that it should not be characterized as a quirk
 > but as a general property of USB flash devices. All USB flash storage
 > devices should have SYNCHRONIZE CACHE and similar SCSI commands disabled
 > by default. These commands should, of course, be enabled for USB-attached
 > ATAPI rotating media, which supports them.
 > 
 > >Release-Note:
 > >Audit-Trail:
 > 
 > >Unformatted:
 
 Hi,
 
 Can you try the attached patch and report back. Should work on 8-stable and 9-
 current.
 
 --HPS
 
 --Boundary-00=_IaKXO97fubXM8EQ
 Content-Type: text/x-patch;
   charset="iso-8859-15";
   name="msc_auto_quirk.patch"
 Content-Transfer-Encoding: 7bit
 Content-Disposition: inline;
filename="msc_auto_quirk.patch"
 
 === sys/dev/usb/quirk/usb_quirk.c
 ==
 --- sys/dev/usb/quirk/usb_quirk.c  (revision 225095)
 +++ sys/dev/usb/quirk/usb_quirk.c  (local)
 @@ -567,9 +567,9 @@
uint16_t x;
uint16_t y;
  
 -  if (quirk == UQ_NONE) {
 -  return (0);
 -  }
 +  if (quirk == UQ_NONE)
 +  goto done;
 +
mtx_lock(&usb_quirk_mtx);
  
for (x = 0; x != USB_DEV_QUIRKS_MAX; x++) {
 @@ -603,7 +603,8 @@
break;
}
mtx_unlock(&usb_quirk_mtx);
 -  return (0);
 +done:
 +  return (usb_test_quirk_w(info, quirk));
  }
  
  static struct usb_quirk_entry *
 === sys/dev/usb/usb_device.c
 ==
 --- sys/dev/usb/usb_device.c   (revision 225095)
 +++ sys/dev/usb/usb_device.c   (local)
 @@ -1239,8 +1239,10 @@
  usb_init_attach_arg(struct usb_device *udev,
  struct usb_attach_arg *uaa)
  {
 -  bzero(uaa, sizeof(*uaa));
 +  uint8_t x;
  
 +  memset(uaa, 0, sizeof(*uaa));
 +
uaa->device = udev;
uaa->usb_mode = udev->flags.usb_mode;
uaa->port = udev->port_no;
 @@ -1254,6 +1256,9 @@
uaa->info.bDeviceProtocol = udev->ddesc.bDeviceProtocol;
uaa->info.bConfigIndex = udev->curr_config_index;
uaa->info.bConfigNum = udev->curr_config_no;
 +
 +  for (x = 0; x != USB_MAX_AUTO_QUIRK; x++)
 +  uaa->info.autoQuirk[x] = udev->autoQuirk[x];
  }
  
  /**
 @@ -1850,7 +1855,23 

Re: usb/160299: MicroSDHC-to-USB adapters do not work in FreeBSD 8.x

2011-08-30 Thread Hans Petter Selasky
On Monday 29 August 2011 23:05:30 Brett Glass wrote:
> >Number: 160299
> >Category:   usb
> >Synopsis:   MicroSDHC-to-USB adapters do not work in FreeBSD 8.x
> >Confidential:   no
> >Severity:   serious
> >Priority:   high
> >Responsible:freebsd-usb
> >State:  open
> >Quarter:
> >Keywords:
> >Date-Required:
> >Class:  sw-bug
> >Submitter-Id:   current-users
> >Arrival-Date:   Mon Aug 29 21:10:08 UTC 2011
> >Closed-Date:
> >Last-Modified:
> >Originator: Brett Glass
> >Release:FreeBSD 8.1-RELEASE
> 
> >Organization:
> LARIAT
> 
> >Environment:
> 
> >Description:
> I have tried MicroSDHC cards from several different vendors (Kingston,
> Sandisk, etc.), with different MicroSDHC-to-USB adapters (also Kingston
> and Sandisk), in FreeBSD 8.x systems. All cause SCSI errors such as
> 
> (da1:umass-sim1:1:0:0): SYNCHRONIZE CACHE(10). CDB: 35 0 0 0 0 0 0 0 0 0
> (da1:umass-sim1:1:0:0): SCSI sense: Error code 0x52
> 
> Some USB flash memory sticks also produce similar errors. In all cases the
> system sometimes hangs in the driver and the memory card or stick gets
> quite warm, as if the system is trying the failed operation again and
> again.
> 
> It appears that the problem, which has existed since FreeBSD 4.x, is that
> the system expects to be able to issue SCSI commands to flash drives
> (which are not SCSI drives). As a search of recent PRs reveals, this
> problem has been addressed as a "quirk" on a per-device basis for many
> individual devices (including memory sticks and cell phones that emulate
> them), but keeps recurring as new ones are released. A more general fix is
> needed.
> 
> >How-To-Repeat:
> Place a MicroSDHC card in a USB adapter and insert in a FreeBSD 8.x
> machine. Try to read and write it.
> 
> >Fix:
> This behavior is so common that it should not be characterized as a quirk
> but as a general property of USB flash devices. All USB flash storage
> devices should have SYNCHRONIZE CACHE and similar SCSI commands disabled
> by default. These commands should, of course, be enabled for USB-attached
> ATAPI rotating media, which supports them.
> 
> >Release-Note:
> >Audit-Trail:
> 
> >Unformatted:

Hi,

Can you try the attached patch and report back. Should work on 8-stable and 9-
current.

--HPS
=== sys/dev/usb/quirk/usb_quirk.c
==
--- sys/dev/usb/quirk/usb_quirk.c	(revision 225095)
+++ sys/dev/usb/quirk/usb_quirk.c	(local)
@@ -567,9 +567,9 @@
 	uint16_t x;
 	uint16_t y;
 
-	if (quirk == UQ_NONE) {
-		return (0);
-	}
+	if (quirk == UQ_NONE)
+		goto done;
+
 	mtx_lock(&usb_quirk_mtx);
 
 	for (x = 0; x != USB_DEV_QUIRKS_MAX; x++) {
@@ -603,7 +603,8 @@
 		break;
 	}
 	mtx_unlock(&usb_quirk_mtx);
-	return (0);
+done:
+	return (usb_test_quirk_w(info, quirk));
 }
 
 static struct usb_quirk_entry *
=== sys/dev/usb/usb_device.c
==
--- sys/dev/usb/usb_device.c	(revision 225095)
+++ sys/dev/usb/usb_device.c	(local)
@@ -1239,8 +1239,10 @@
 usb_init_attach_arg(struct usb_device *udev,
 struct usb_attach_arg *uaa)
 {
-	bzero(uaa, sizeof(*uaa));
+	uint8_t x;
 
+	memset(uaa, 0, sizeof(*uaa));
+
 	uaa->device = udev;
 	uaa->usb_mode = udev->flags.usb_mode;
 	uaa->port = udev->port_no;
@@ -1254,6 +1256,9 @@
 	uaa->info.bDeviceProtocol = udev->ddesc.bDeviceProtocol;
 	uaa->info.bConfigIndex = udev->curr_config_index;
 	uaa->info.bConfigNum = udev->curr_config_no;
+
+	for (x = 0; x != USB_MAX_AUTO_QUIRK; x++)
+		uaa->info.autoQuirk[x] = udev->autoQuirk[x];
 }
 
 /**
@@ -1850,7 +1855,23 @@
 			}
 		}
 	}
+	if (set_config_failed == 0 && config_index == 0 &&
+	usb_test_quirk(&uaa, UQ_MSC_NO_SYNC_CACHE) == 0) {
 
+		/*
+		 * Try to figure out if there are any MSC quirks we
+		 * should apply automatically:
+		 */
+		err = usb_msc_auto_quirk(udev, 0);
+
+		if (err != 0) {
+			usbd_add_dynamic_quirk(udev, UQ_MSC_NO_SYNC_CACHE);
+
+			set_config_failed = 1;
+			goto repeat_set_config;
+		}
+	}
+
 config_done:
 	DPRINTF("new dev (addr %d), udev=%p, parent_hub=%p\n",
 	udev->address, udev, udev->parent_hub);
@@ -2698,3 +2719,16 @@
 	return (0);			/* success */
 }
 
+usb_error_t
+usbd_add_dynamic_quirk(struct usb_device *udev, uint16_t quirk)
+{
+	uint8_t x;
+
+	for (x = 0; x != USB_MAX_AUTO_QUIRK; x++) {
+		if (udev->autoQuirk[x] == 0) {
+			udev->autoQuirk[x] = quirk;
+			return (0);	/* success */
+		}
+	}
+	return (USB_ERR_NOMEM);
+}
=== sys/dev/usb/usb_device.h
==
--- sys/dev/usb/usb_device.h	(revision 225095)
+++ sys/dev/usb/usb_device.h	(local)
@@ -149,6 +149,7 @@
 
 	uint16_t power;			/* mA the device uses */
 	uint16_t langid;		/* language for strings */
+	uint16_t autoQuirk[USB_MAX_AUTO_QUIRK];		/* dynamic quirks */
 
 	uint8_t	address;		/* device addess */
 	uint8_t	device_index;		/* devi

usb/160299: MicroSDHC-to-USB adapters do not work in FreeBSD 8.x

2011-08-29 Thread Brett Glass

>Number: 160299
>Category:   usb
>Synopsis:   MicroSDHC-to-USB adapters do not work in FreeBSD 8.x
>Confidential:   no
>Severity:   serious
>Priority:   high
>Responsible:freebsd-usb
>State:  open
>Quarter:
>Keywords:   
>Date-Required:
>Class:  sw-bug
>Submitter-Id:   current-users
>Arrival-Date:   Mon Aug 29 21:10:08 UTC 2011
>Closed-Date:
>Last-Modified:
>Originator: Brett Glass
>Release:FreeBSD 8.1-RELEASE
>Organization:
LARIAT
>Environment:
>Description:
I have tried MicroSDHC cards from several different vendors (Kingston, Sandisk, 
etc.), with different MicroSDHC-to-USB adapters (also Kingston and Sandisk), in 
FreeBSD 8.x systems. All cause SCSI errors such as

(da1:umass-sim1:1:0:0): SYNCHRONIZE CACHE(10). CDB: 35 0 0 0 0 0 0 0 0 0
(da1:umass-sim1:1:0:0): SCSI sense: Error code 0x52

Some USB flash memory sticks also produce similar errors. In all cases the 
system sometimes hangs in the driver and the memory card or stick gets quite 
warm, as if the system is trying the failed operation again and again.

It appears that the problem, which has existed since FreeBSD 4.x, is that the 
system expects to be able to issue SCSI commands to flash drives (which are not 
SCSI drives). As a search of recent PRs reveals, this problem has been 
addressed as a "quirk" on a per-device basis for many individual devices 
(including memory sticks and cell phones that emulate them), but keeps 
recurring as new ones are released. A more general fix is needed.
>How-To-Repeat:
Place a MicroSDHC card in a USB adapter and insert in a FreeBSD 8.x machine. 
Try to read and write it.
>Fix:
This behavior is so common that it should not be characterized as a quirk but 
as a general property of USB flash devices. All USB flash storage devices 
should have SYNCHRONIZE CACHE and similar SCSI commands disabled by default. 
These commands should, of course, be enabled for USB-attached ATAPI rotating 
media, which supports them.

>Release-Note:
>Audit-Trail:
>Unformatted:
___
freebsd-usb@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-usb
To unsubscribe, send any mail to "freebsd-usb-unsubscr...@freebsd.org"