RFC drivers/usb/storage/libusual
Subsystems (3)
In my tree, I always use the following patchlet, which deconflicts ub and usb-storage:
*** linux-2.6.14-rc1-lem/drivers/usb/storage/usb.c 2005-09-13 12:01:58.000000000 -0700
@@ -152,7 +152,9 @@ static struct usb_device_id storage_usb_
{ USB_INTERFACE_INFO(USB_CLASS_MASS_STORAGE, US_SC_QIC, US_PR_BULK) }, { USB_INTERFACE_INFO(USB_CLASS_MASS_STORAGE, US_SC_UFI, US_PR_BULK) }, { USB_INTERFACE_INFO(USB_CLASS_MASS_STORAGE, US_SC_8070, US_PR_BULK) },
+#if !defined(CONFIG_BLK_DEV_UB) && !defined(CONFIG_BLK_DEV_UB_MODULE)
{ USB_INTERFACE_INFO(USB_CLASS_MASS_STORAGE, US_SC_SCSI, US_PR_BULK) },
+#endif
/* Terminating entry */
{ }
@@ -226,8 +228,10 @@ static struct us_unusual_dev us_unusual_
.useTransport = US_PR_BULK},
{ .useProtocol = US_SC_8070,
.useTransport = US_PR_BULK},
+#if !defined(CONFIG_BLK_DEV_UB) && !defined(CONFIG_BLK_DEV_UB_MODULE)
{ .useProtocol = US_SC_SCSI,
.useTransport = US_PR_BULK},
+#endif
/* Terminating entry */
{ NULL }
This makes hotplug to function in a deterministic way, which is a good thing. The patch is not in Linus' tree. It was there at one point, but Adrian Bunk removed it.
Why? Because he could not be bothered to understand how the hotplug works. Before we say "how stupid", observe that he was very far from being alone. A few other users also enabled UB (despite all the warnings in Kconfig) and then did not know what to do when something did not work for them. And people involved were not morons at all. I had to explain how this was supposed to work to Doug Gilbert and Randy Dunlap, who had considerable experience. This tells me that the mechanisms I used here were unreasonably intricate (to put it mildly).
Simply put, if it's not obvious, it's wrong.
So, I came up with a solution to the problem, which, I hope, is better. It has the following features:
- The usb_device_id table is now shared between ub and usb-storage.
- The table is located physically in a neutral driver, libusual.
- There is only one table. It is not split in any way.
- Userland tricks are not used (not necesserily a good thing).
- Devices can be marked for use by ub or usb-storage without rebuilding or rebooting.
- The scheme can be useful for sharing of devices between HID, Wacom, and Apitek, if we like how it works for the storage.
- Even with every kernel option enabled, the assignment defaults to usb-storage. Users have to add an explicit option to /etc/modprobe.conf before the ub gets hotplugged. Thus, the system addresses the Adrian's original problem.
Patch is attached. I would like someone to look it over and challenge it. The thing looks too complex to me, but I see no other way. Anyone?
Thanks,
-- Pete
drivers/block/Kconfig +2 -1
@@ -358,7 +358,8 @@ config BLK_DEV_UB This driver supports certain USB attached storage devices such as flash keys. - Warning: Enabling this cripples the usb-storage driver. + If you enable this driver, it is recommended to avoid conflicts + with usb-storage by enabling USB_LIBUSUAL. If unsure, say N.
drivers/block/ub.c +13 -3
@@ -29,6 +29,7 @@#include <linux/kernel.h> #include <linux/module.h> #include <linux/usb.h> +#include <linux/usb_usual.h> #include <linux/blkdev.h> #include <linux/devfs_fs_kernel.h> #include <linux/timer.h>
@@ -110,11 +111,13 @@* Definitions which have to be scattered once we understand the layout better. */ +#if 0 /* Subclass and protocol are in usb_usual.h now. */ /* Transport (despite PR in the name) */ #define US_PR_BULK 0x50/* bulk only */ /* Protocol */ #define US_SC_SCSI 0x06/* Transparent */ +#endif /* * This many LUNs per USB device.
@@ -422,13 +425,18 @@ static int ub_probe_lun(struct ub_dev *s/* */ +#ifdef CONFIG_USB_LIBUSUAL + +#define ub_usb_ids storage_usb_ids +#else +static struct usb_device_id ub_usb_ids[] = { -// { USB_DEVICE_VER(0x0781, 0x0002, 0x0009, 0x0009) }, /* SDDR-31 */ {USB_INTERFACE_INFO (USB_CLASS_MASS_STORAGE ,US_SC_SCSI ,US_PR_BULK ) }, { } };MODULE_DEVICE_TABLE (usb, ub_usb_ids); +#endif /* CONFIG_USB_LIBUSUAL */ /* * Find me a way to identify "next free minor" for add_disk(),
@@ -2466,8 +2474,7 @@ static int __init ub_init(void) {int rc; -/* P3 */ printk ("ub: sizeof ub_scsi_cmd %zu ub_dev %zu ub_lun %zu\n" , -sizeof (struct ub_scsi_cmd ),sizeof (struct ub_dev ),sizeof (struct ub_lun )); +usb_usual_set_present (USB_US_TYPE_UB ,1 );if ((rc =register_blkdev (UB_MAJOR ,DRV_NAME )) !=0 ) goto err_regblkdev;
@@ -2482,6 +2489,8 @@ err_register:devfs_remove (DEVFS_NAME );unregister_blkdev (UB_MAJOR ,DRV_NAME ); err_regblkdev: + +usb_usual_set_present (USB_US_TYPE_UB ,0 );return rc; }
@@ -2491,6 +2500,7 @@ static void __exit ub_exit(void)devfs_remove (DEVFS_NAME );unregister_blkdev (UB_MAJOR ,DRV_NAME ); +usb_usual_set_present (USB_US_TYPE_UB ,0 ); }module_init (ub_init);
drivers/usb/storage/Kconfig +14 -0
@@ -123,3 +123,17 @@ config USB_STORAGE_ONETOUCH hard drive's as an input device. An action can be associated with this input in any keybinding software. (e.g. gnome's keyboard short- cuts) + +config USB_LIBUSUAL + bool "The shared table of common (or usual) storage devices" + depends on USB + help + This module contains a table of common (or usual) devices + for usb-storage and ub drivers, and allows to switch binding + of these devices without rebuilding modules. + + Typical syntax of /etc/modprobe.conf is: + + options libusual bias="ub" + + If unsure, say N.
drivers/usb/storage/libusual.c +292 -0
292 lines not on this page · raw message
drivers/usb/storage/Makefile +4 -0
@@ -22,3 +22,7 @@ usb-storage-obj-$(CONFIG_USB_STORAGE_ONE usb-storage-objs := scsiglue.o protocol.o transport.o usb.o \ initializers.o $(usb-storage-obj-y) + +ifneq ($(CONFIG_USB_LIBUSUAL),) + obj-$(CONFIG_USB) += libusual.o +endif
drivers/usb/storage/protocol.h +0 -14
@@ -41,20 +41,6 @@#ifndef _PROTOCOL_H_#define _PROTOCOL_H_ -/* Sub Classes */ - -#define US_SC_RBC 0x01/* Typically, flash devices */ -#define US_SC_8020 0x02/* CD-ROM */ -#define US_SC_QIC 0x03/* QIC-157 Tapes */ -#define US_SC_UFI 0x04/* Floppy */ -#define US_SC_8070 0x05/* Removable media */ -#define US_SC_SCSI 0x06/* Transparent */ -#define US_SC_ISD200 0x07/* ISD200 ATA */ -#define US_SC_MIN US_SC_RBC -#define US_SC_MAX US_SC_ISD200 - -#define US_SC_DEVICE 0xff/* Use device's value */ -/* Protocol handling routines */ extern void usb_stor_ATAPI_command (struct scsi_cmnd *,struct us_data *);extern void usb_stor_qic157_command (struct scsi_cmnd *,struct us_data *);
drivers/usb/storage/scsiglue.c +2 -2
@@ -342,14 +342,14 @@ static int proc_info (struct Scsi_Host */* print product, vendor, and serial number strings */ if (us->pusb_dev->manufacturer) string = us->pusb_dev->manufacturer; -else if (us->unusual_dev->vendorName) +else if (us->unusual_dev && us->unusual_dev->vendorName) string = us->unusual_dev->vendorName;else string ="Unknown" ;SPRINTF (" Vendor: %s\n" , string);if (us->pusb_dev->product) string = us->pusb_dev->product; -else if (us->unusual_dev->productName) +else if (us->unusual_dev && us->unusual_dev->productName) string = us->unusual_dev->productName;else string ="Unknown" ;
drivers/usb/storage/transport.h +0 -30
@@ -44,36 +44,6 @@#include <linux/config.h> #include <linux/blkdev.h> -/* Protocols */ - -#define US_PR_CBI 0x00/* Control/Bulk/Interrupt */ -#define US_PR_CB 0x01/* Control/Bulk w/o interrupt */ -#define US_PR_BULK 0x50/* bulk only */ -#ifdef CONFIG_USB_STORAGE_USBAT -#define US_PR_SCM_ATAPI 0x80/* SCM-ATAPI bridge */ -#endif -#ifdef CONFIG_USB_STORAGE_SDDR09 -#define US_PR_EUSB_SDDR09 0x81/* SCM-SCSI bridge for SDDR-09 */ -#endif -#ifdef CONFIG_USB_STORAGE_SDDR55 -#define US_PR_SDDR55 0x82/* SDDR-55 (made up) */ -#endif -#define US_PR_DPCM_USB 0xf0/* Combination CB/SDDR09 */ - -#ifdef CONFIG_USB_STORAGE_FREECOM -#define US_PR_FREECOM 0xf1/* Freecom */ -#endif - -#ifdef CONFIG_USB_STORAGE_DATAFAB -#define US_PR_DATAFAB 0xf2/* Datafab chipsets */ -#endif - -#ifdef CONFIG_USB_STORAGE_JUMPSHOT -#define US_PR_JUMPSHOT 0xf3/* Lexar Jumpshot */ -#endif - -#define US_PR_DEVICE 0xff/* Use device's value */ -/* * Bulk only data structures */
drivers/usb/storage/unusual_devs.h +195 -249
1,164 lines not on this page · raw message
drivers/usb/storage/usb.c +55 -65
224 lines not on this page · raw message
drivers/usb/storage/usb.h +5 -42
64 lines not on this page · raw message
include/linux/usb_usual.h +134 -0
134 lines not on this page · raw message
Quoted 3 lines · Pete Zaitcev
This makes hotplug to function in a deterministic way, which is a good thing. The patch is not in Linus' tree. It was there at one point, but Adrian Bunk removed it.
I also did not like that patch.
Quoted 11 lines
Why? Because he could not be bothered to understand how the hotplug works. Before we say "how stupid", observe that he was very far from being alone. A few other users also enabled UB (despite all the warnings in
Kconfig) and then did not know what to do when something did not work for them. And people involved were not morons at all. I had to explain how this was supposed to work to Doug Gilbert and Randy Dunlap, who had considerable experience. This tells me that the mechanisms I used here were unreasonably intricate (to put it mildly).Simply put, if it's not obvious, it's wrong.
Ok, fair enough, but it is nice at times to mix ub and usb-storage device controlled devices.
Quoted 3 lines
So, I came up with a solution to the problem, which, I hope, is better. It has the following features:
- Theusb_device_idtable is now shared between ub and usb-storage.
Nice.
Quoted 1 line
- The table is located physically in a neutral driver, libusual.
Also nice. But you might want to rename it to show that this is only for usb storage type devices. And no, I can't think of a better name right now :)
Quoted 1 line
- There is only one table. It is not split in any way.
Nice.
Quoted 1 line
- Userland tricks are not used (not necesserily a good thing).
Hm... more on this below...
Quoted 2 lines
- Devices can be marked for use by ub or usb-storage without rebuilding or rebooting.
How? I missed this in the patch somewhere.
Quoted 2 lines
- The scheme can be useful for sharing of devices between HID, Wacom, and Apitek, if we like how it works for the storage.
Fair enough, so we should rename it :)
Quoted 4 lines
- Even with every kernel option enabled, the assignment defaults to usb-storage. Users have to add an explicit option to
/etc/modprobe.confbefore the ub gets hotplugged. Thus, the system addresses the Adrian's original problem.
Yes, that works better. Kind of. But this seems like a lot of work just to get a "preference". Although the kernel thread hack is fun.
Your patch mixes a few things in that you probably don't need to show how libusual works which bloat the patch. The unusual_devs.h rework comes to mind.
Just to verify that I read this code correct, is this how it all works?
- kernel finds usb device and calls out to hotplug with the device id stuff.
- hotplug scripts load libusual as that is where the mod info is pointing to.
- libusual's probe function gets called.
- kernel thread is spawned and probe fails
- module for "preferred" driver is loaded with a call to request_module
- requested module is loaded.
- requested module's probe is called by core and device is bound to it.
Did I get that correct?
If so, a few comments.
- This only covers the "which module to load" question. Once the module is loaded, it still always grabs the storage devices, even if another module is loaded later on. Isn't that still the same issue we have today? Can't we fix this too?
- request_module() is icky. I keep wanting to get rid of that function, and really don't want to see any further users get added. But that's just my feeling, if there's no other way to do this, I don't mind.
thanks,
greg k-h
Alan Stern
maintainerQuoted 5 lines · Greg KH
If so, a few comments.
- This only covers the "which module to load" question. Once the module is loaded, it still always grabs the storage devices, even if another module is loaded later on. Isn't that still the same issue we have today? Can't we fix this too?
How about exposing modules' id tables through sysfs and allowing a way for entries to be marked valid or invalid? Then a userspace utility program could easily set things up so that normal USB storage devices are accepted by usb-storage and not ub, or the other way around.
The part that Pete tackled, arranging the preferences when the modules _aren't_ loaded, is actually the harder part.
Alan Stern
Quoted 2 lines · Greg KH
Ok, fair enough, but it is nice at times to mix ub and usb-storage device controlled devices.
I mixed them just fine, as long as the protocol was different. The difference now is how we can split devices with same protocol by their IDs.
Quoted 4 lines
Quoted 2 lines
- Devices can be marked for use by ub or usb-storage without rebuilding or rebooting.
How? I missed this in the patch somewhere.
I do it with rmmod ub, rmmod libusual, then changing the module parameter to bias="usb-storage". Then either modprobe usb-storage or replug the device. In Gentoo we could simply rebuild with CONFIG_BLK_DEV_UB unset, but in Fedora this is more useful.
Ultimately I wanted to add some facility to add IDs, but it was too tricky to be included into this first cut.
Quoted 4 lines
Quoted 2 lines
- The scheme can be useful for sharing of devices between HID, Wacom, and Apitek, if we like how it works for the storage.
Fair enough, so we should rename it :)
I was going to have a very similar, but separate shared piece called "libhideous", you know, because it's HIDeous. Then, maybe factor out common parts... Maybe make it part of core, if we find it useful. I'll ask Ping Cheng and Kristian Hoksberg about it. The flow of requests to add another Wacom ID to the exclusion list is not very strong recently.
Quoted 14 lines
Just to verify that I read this code correct, is this how it all works?
- kernel finds usb device and calls out to hotplug with the device id stuff.
- hotplug scripts load libusual as that is where the mod info is pointing to.
- libusual's probe function gets called.
- kernel thread is spawned and probe fails
- module for "preferred" driver is loaded with a call torequest_module
- requested module is loaded.
- requested module's probe is called by core and device is bound to it.
Quoted 1 line
Did I get that correct?
Yes.
It is not the only mode of operation. You can modprobe modules by hand, and also our installer can load them without hotplug. In such case, dependancies cause libusual to be loaded ahead.
Another situation is when modules are built statically. I recommend not to use libusual when building static kernel, and pre-select usb-storage or ub, depending on application. There was company which shipped static ub in arcage game machines. Libusual continues to work but it's rather silly.
Quoted 5 lines
If so, a few comments.
- This only covers the "which module to load" question. Once the module is loaded, it still always grabs the storage devices, even if another module is loaded later on. Isn't that still the same issue we have today? Can't we fix this too?
I am very sorry, I forgot a little piece of code in component driver's probe() routines, like this:
@@ -2168,6 +2176,9 @@ static int ub_probe(struct usb_interface
int rc;
int i;
+ if (USB_US_TYPE(dev_id->driver_info) != USB_US_TYPE_UB)
+ return -ENXIO;
+
rc = -ENOMEM;
if ((sc = kmalloc(sizeof(struct ub_dev), GFP_KERNEL)) == NULL)
goto err_core;
I'll retest and resend a corrected patch.
Quoted 4 lines
-
request_module()is icky. I keep wanting to get rid of that function, and really don't want to see any further users get added. But that's just my feeling, if there's no other way to do this, I don't mind.
Yes, yes, and yes. And also, it looks to me as if I am trying to do something which "obviously" belongs to modprobe or other user mode component. The trouble is, I am unable to find a different solution which would not involve an alias pointing to an alias, and Rusty's modprobe does not allow that. I could hack it up easily, but he put in a comment, "that way lies madness". He probably knew what he was doing.
-- Pete
Quoted 5 lines · Pete Zaitcev
Quoted 4 lines
-
request_module()is icky. I keep wanting to get rid of that function, and really don't want to see any further users get added. But that's just my feeling, if there's no other way to do this, I don't mind.
Quoted 7 lines
Yes, yes, and yes. And also, it looks to me as if I am trying to do something which "obviously" belongs to modprobe or other user mode component. The trouble is, I am unable to find a different solution which would not involve an alias pointing to an alias, and Rusty's modprobe does not allow that. I could hack it up easily, but he put in a comment, "that way lies madness". He probably knew what he was doing.
I just didn't want to do loop detection. In userspace you can use an install command to get the same effect.
Now, why did we want this? In small words...
Rusty.
Signature · 1 line
A bad analogy is like a leaky screwdriver -- Richard Braakman
Quoted 9 lines · Greg KH
Your patch mixes a few things in that you probably don't need to show how libusual works which bloat the patch. The
unusual_devs.hrework comes to mind.- This only covers the "which module to load" question. Once the module is loaded, it still always grabs the storage devices, even if another module is loaded later on. Isn't that still the same issue we have today? Can't we fix this too?
Quoted 4 lines
-
request_module()is icky. I keep wanting to get rid of that function, and really don't want to see any further users get added. But that's just my feeling, if there's no other way to do this, I don't mind.
I addressed the first two concens. The usb-storage gets to keep its 1:1 relation between the two arrays, and the missing checks for device type are added. But unfortunately, request_module() is an intrinsic part of the beast...
So, here it goes. I tested it to build and work with libusual enabled and disabled, by attaching devices which are on the old "unusual" list and generic devices. But it's quite possible that I'm missing something, so if anyone could give it a try, or review again, that would be great.
The old patch had some silly bugs in it. I guess I was too excited and did not test it thoroughly enough. For example:
+ spin_lock_irqsave(&usu_lock, flags);
+ if ((stat[type].fls & (USU_MOD_FL_THREAD|USU_MOD_FL_PRESENT)) != 0) {
+ spin_lock_irqsave(&usu_lock, flags); <===== Lock again?
+ return -ENXIO;
+ }
+ stat[type].fls |= USU_MOD_FL_THREAD;
+ spin_unlock_irqrestore(&usu_lock, flags);
That's the kind of thing I let happen in my patches, so beware :-)
Greetings,
-- Pete
drivers/block/Kconfig +2 -1
@@ -358,7 +358,8 @@ config BLK_DEV_UB This driver supports certain USB attached storage devices such as flash keys. - Warning: Enabling this cripples the usb-storage driver. + If you enable this driver, it is recommended to avoid conflicts + with usb-storage by enabling USB_LIBUSUAL. If unsure, say N.
drivers/block/ub.c +16 -3
@@ -29,6 +29,7 @@#include <linux/kernel.h> #include <linux/module.h> #include <linux/usb.h> +#include <linux/usb_usual.h> #include <linux/blkdev.h> #include <linux/devfs_fs_kernel.h> #include <linux/timer.h>
@@ -110,11 +111,13 @@* Definitions which have to be scattered once we understand the layout better. */ +#if 0 /* Subclass and protocol are in usb_usual.h now. */ /* Transport (despite PR in the name) */ #define US_PR_BULK 0x50/* bulk only */ /* Protocol */ #define US_SC_SCSI 0x06/* Transparent */ +#endif /* * This many LUNs per USB device.
@@ -422,13 +425,18 @@ static int ub_probe_lun(struct ub_dev *s/* */ +#ifdef CONFIG_USB_LIBUSUAL + +#define ub_usb_ids storage_usb_ids +#else +static struct usb_device_id ub_usb_ids[] = { -// { USB_DEVICE_VER(0x0781, 0x0002, 0x0009, 0x0009) }, /* SDDR-31 */ {USB_INTERFACE_INFO (USB_CLASS_MASS_STORAGE ,US_SC_SCSI ,US_PR_BULK ) }, { } };MODULE_DEVICE_TABLE (usb, ub_usb_ids); +#endif /* CONFIG_USB_LIBUSUAL */ /* * Find me a way to identify "next free minor" for add_disk(),
@@ -2168,6 +2176,9 @@ static int ub_probe(struct usb_interfaceint rc;int i; +if (USB_US_TYPE (dev_id->driver_info) !=USB_US_TYPE_UB ) +return -ENXIO ; + rc = -ENOMEM ;if ((sc =kmalloc (sizeof (struct ub_dev ),GFP_KERNEL )) ==NULL ) goto err_core;
@@ -2466,8 +2477,7 @@ static int __init ub_init(void) {int rc; -/* P3 */ printk ("ub: sizeof ub_scsi_cmd %zu ub_dev %zu ub_lun %zu\n" , -sizeof (struct ub_scsi_cmd ),sizeof (struct ub_dev ),sizeof (struct ub_lun )); +usb_usual_set_present (USB_US_TYPE_UB ,1 );if ((rc =register_blkdev (UB_MAJOR ,DRV_NAME )) !=0 ) goto err_regblkdev;
@@ -2482,6 +2492,8 @@ err_register:devfs_remove (DEVFS_NAME );unregister_blkdev (UB_MAJOR ,DRV_NAME ); err_regblkdev: + +usb_usual_set_present (USB_US_TYPE_UB ,0 );return rc; }
@@ -2491,6 +2503,7 @@ static void __exit ub_exit(void)devfs_remove (DEVFS_NAME );unregister_blkdev (UB_MAJOR ,DRV_NAME ); +usb_usual_set_present (USB_US_TYPE_UB ,0 ); }module_init (ub_init);
drivers/usb/storage/Kconfig +14 -0
@@ -123,3 +123,17 @@ config USB_STORAGE_ONETOUCH hard drive's as an input device. An action can be associated with this input in any keybinding software. (e.g. gnome's keyboard short- cuts) + +config USB_LIBUSUAL + bool "The shared table of common (or usual) storage devices" + depends on USB + help + This module contains a table of common (or usual) devices + for usb-storage and ub drivers, and allows to switch binding + of these devices without rebuilding modules. + + Typical syntax of /etc/modprobe.conf is: + + options libusual bias="ub" + + If unsure, say N.
drivers/usb/storage/libusual.c +257 -0
257 lines not on this page · raw message
drivers/usb/storage/Makefile +4 -0
@@ -22,3 +22,7 @@ usb-storage-obj-$(CONFIG_USB_STORAGE_ONE usb-storage-objs := scsiglue.o protocol.o transport.o usb.o \ initializers.o $(usb-storage-obj-y) + +ifneq ($(CONFIG_USB_LIBUSUAL),) + obj-$(CONFIG_USB) += libusual.o +endif
drivers/usb/storage/protocol.h +0 -14
@@ -41,20 +41,6 @@#ifndef _PROTOCOL_H_#define _PROTOCOL_H_ -/* Sub Classes */ - -#define US_SC_RBC 0x01/* Typically, flash devices */ -#define US_SC_8020 0x02/* CD-ROM */ -#define US_SC_QIC 0x03/* QIC-157 Tapes */ -#define US_SC_UFI 0x04/* Floppy */ -#define US_SC_8070 0x05/* Removable media */ -#define US_SC_SCSI 0x06/* Transparent */ -#define US_SC_ISD200 0x07/* ISD200 ATA */ -#define US_SC_MIN US_SC_RBC -#define US_SC_MAX US_SC_ISD200 - -#define US_SC_DEVICE 0xff/* Use device's value */ -/* Protocol handling routines */ extern void usb_stor_ATAPI_command (struct scsi_cmnd *,struct us_data *);extern void usb_stor_qic157_command (struct scsi_cmnd *,struct us_data *);
drivers/usb/storage/transport.h +0 -30
@@ -44,36 +44,6 @@#include <linux/config.h> #include <linux/blkdev.h> -/* Protocols */ - -#define US_PR_CBI 0x00/* Control/Bulk/Interrupt */ -#define US_PR_CB 0x01/* Control/Bulk w/o interrupt */ -#define US_PR_BULK 0x50/* bulk only */ -#ifdef CONFIG_USB_STORAGE_USBAT -#define US_PR_SCM_ATAPI 0x80/* SCM-ATAPI bridge */ -#endif -#ifdef CONFIG_USB_STORAGE_SDDR09 -#define US_PR_EUSB_SDDR09 0x81/* SCM-SCSI bridge for SDDR-09 */ -#endif -#ifdef CONFIG_USB_STORAGE_SDDR55 -#define US_PR_SDDR55 0x82/* SDDR-55 (made up) */ -#endif -#define US_PR_DPCM_USB 0xf0/* Combination CB/SDDR09 */ - -#ifdef CONFIG_USB_STORAGE_FREECOM -#define US_PR_FREECOM 0xf1/* Freecom */ -#endif - -#ifdef CONFIG_USB_STORAGE_DATAFAB -#define US_PR_DATAFAB 0xf2/* Datafab chipsets */ -#endif - -#ifdef CONFIG_USB_STORAGE_JUMPSHOT -#define US_PR_JUMPSHOT 0xf3/* Lexar Jumpshot */ -#endif - -#define US_PR_DEVICE 0xff/* Use device's value */ -/* * Bulk only data structures */
drivers/usb/storage/unusual_devs.h +24 -0
@@ -1093,3 +1093,27 @@ UNUSUAL_DEV( 0x55aa, 0xa103, 0x0000, 0x US_SC_SCSI, US_PR_SDDR55, NULL, US_FL_SINGLE_LUN),#endif + +/* Control/Bulk transport for all SubClass values */ +USUAL_DEV (US_SC_RBC ,US_PR_CB ,USB_US_TYPE_STOR ), +USUAL_DEV (US_SC_8020 ,US_PR_CB ,USB_US_TYPE_STOR ), +USUAL_DEV (US_SC_QIC ,US_PR_CB ,USB_US_TYPE_STOR ), +USUAL_DEV (US_SC_UFI ,US_PR_CB ,USB_US_TYPE_STOR ), +USUAL_DEV (US_SC_8070 ,US_PR_CB ,USB_US_TYPE_STOR ), +USUAL_DEV (US_SC_SCSI ,US_PR_CB ,USB_US_TYPE_STOR ), + +/* Control/Bulk/Interrupt transport for all SubClass values */ +USUAL_DEV (US_SC_RBC ,US_PR_CBI ,USB_US_TYPE_STOR ), +USUAL_DEV (US_SC_8020 ,US_PR_CBI ,USB_US_TYPE_STOR ), +USUAL_DEV (US_SC_QIC ,US_PR_CBI ,USB_US_TYPE_STOR ), +USUAL_DEV (US_SC_UFI ,US_PR_CBI ,USB_US_TYPE_STOR ), +USUAL_DEV (US_SC_8070 ,US_PR_CBI ,USB_US_TYPE_STOR ), +USUAL_DEV (US_SC_SCSI ,US_PR_CBI ,USB_US_TYPE_STOR ), + +/* Bulk-only transport for all SubClass values */ +USUAL_DEV (US_SC_RBC ,US_PR_BULK ,USB_US_TYPE_STOR ), +USUAL_DEV (US_SC_8020 ,US_PR_BULK ,USB_US_TYPE_STOR ), +USUAL_DEV (US_SC_QIC ,US_PR_BULK ,USB_US_TYPE_STOR ), +USUAL_DEV (US_SC_UFI ,US_PR_BULK ,USB_US_TYPE_STOR ), +USUAL_DEV (US_SC_8070 ,US_PR_BULK ,USB_US_TYPE_STOR ), +USUAL_DEV(US_SC_SCSI, US_PR_BULK, 0),
drivers/usb/storage/usb.c +40 -78
210 lines not on this page · raw message
drivers/usb/storage/usb.h +1 -42
57 lines not on this page · raw message
include/linux/usb_usual.h +134 -0
134 lines not on this page · raw message
Alan Stern
maintainerJust a few technical comments on aspects of your patch:
Quoted 3 lines · Pete Zaitcev
diff -urpN -X dontdiff
linux-2.6.14-rc2/drivers/usb/storage/usb.hlinux-2.6.14-rc2-wip/drivers/usb/storage/usb.hdrivers/usb/storage/usb.h +0
-0
...
drivers/usb/storage/usb.h struct us_unusual_dev { · line 69
Quoted 12 lines
drivers/usb/storage/usb.h +0
-11-/* Dynamic flag definitions: used in set_bit() etc. */ -#define US_FLIDX_URB_ACTIVE 18/* 0x00040000 current_urb is in use */ -#define US_FLIDX_SG_ACTIVE 19/* 0x00080000 current_sg is in use */ -#define US_FLIDX_ABORTING 20/* 0x00100000 abort is in progress */ -#define US_FLIDX_DISCONNECTING 21/* 0x00200000 disconnect in progress */ -#define ABORTING_OR_DISCONNECTING ((1UL << US_FLIDX_ABORTING) | \ - (1UL << US_FLIDX_DISCONNECTING)) -#define US_FLIDX_RESETTING 22/* 0x00400000 device reset in progress */ -#define US_FLIDX_TIMED_OUT 23/* 0x00800000 SCSI midlayer timed out */ - -#define USB_STOR_STRING_LEN 32
I would prefer to keep these definitions in the usb-storage driver. They refer to dynamic aspects of an individual device, not static blacklist or ID-matching for all devices of a particular type. As such, they are of no interest to ub or libusual.
include/linux/usb_usual.h line 66
Quoted 8 lines
diff -urpN -X dontdiff
linux-2.6.14-rc2/include/linux/usb_usual.hlinux-2.6.14-rc2-wip/include/linux/usb_usual.hinclude/linux/usb_usual.h +5
-0+/* +* The bias field for libusual and friends. +* Observe that usb-storage blatantly mixes set_bit() and normal +* shift and mask operations on flags, which is strictly illegal. +* And it probably even works for all flags except GO_SLOW and NO_WP_DETECT.
The two types of operations are used to write these flags at strictly different times. The shift/mask operations are used while initializing the data structures and the set_bit-style operations are used after everything has been set up and the device is operational.
Once the device is running, the shift/mask operations are used _only_ for reading, never for writing. This is true for all of the static flags, not just GO_SLOW and NO_WP_DETECT. There shouldn't be anything wrong or illegal about it. I don't see how it could possibly cause any kind of error or problem.
It's true that two separate words could be used for the two kinds of flag bits. But since they coexist peacefully now, there doesn't seem to be any need.
Alan Stern
Quoted 11 lines · Alan Stern
Quoted 2 lines
drivers/usb/storage/usb.h +0
-0...
drivers/usb/storage/usb.h
Quoted 3 lines
drivers/usb/storage/usb.h +0
-3-/* Dynamic flag definitions: used in set_bit() etc. */ -#define US_FLIDX_URB_ACTIVE 18/* 0x00040000 current_urb is in use */ -#define US_FLIDX_SG_ACTIVE 19/* 0x00080000 current_sg is in use */ I would prefer to keep these definitions in the usb-storage driver. They refer to dynamic aspects of an individual device, not static blacklist or ID-matching for all devices of a particular type. As such, they are of no interest to ub or libusual.
OK
Quoted 6 lines
Quoted 3 lines
+ * Observe that usb-storage blatantly mixes
set_bit()and normal
+ * shift and mask operations on flags, which is strictly illegal.
+ * And it probably even works for all flags exceptGO_SLOWandNO_WP_DETECT.Once the device is running, the shift/mask operations are used _only_ for reading, never for writing.
OK
How about now?
---
drivers/block/Kconfig +2 -1
@@ -358,7 +358,8 @@ config BLK_DEV_UB This driver supports certain USB attached storage devices such as flash keys. - Warning: Enabling this cripples the usb-storage driver. + If you enable this driver, it is recommended to avoid conflicts + with usb-storage by enabling USB_LIBUSUAL. If unsure, say N.
drivers/block/ub.c +16 -1
@@ -29,6 +29,7 @@#include <linux/kernel.h> #include <linux/module.h> #include <linux/usb.h> +#include <linux/usb_usual.h> #include <linux/blkdev.h> #include <linux/devfs_fs_kernel.h> #include <linux/timer.h>
@@ -110,11 +111,13 @@* Definitions which have to be scattered once we understand the layout better. */ +#if 0 /* Subclass and protocol are in usb_usual.h now. */ /* Transport (despite PR in the name) */ #define US_PR_BULK 0x50/* bulk only */ /* Protocol */ #define US_SC_SCSI 0x06/* Transparent */ +#endif /* * This many LUNs per USB device.
@@ -422,13 +425,18 @@ static int ub_probe_lun(struct ub_dev *s/* */ +#ifdef CONFIG_USB_LIBUSUAL + +#define ub_usb_ids storage_usb_ids +#else +static struct usb_device_id ub_usb_ids[] = { -// { USB_DEVICE_VER(0x0781, 0x0002, 0x0009, 0x0009) }, /* SDDR-31 */ {USB_INTERFACE_INFO (USB_CLASS_MASS_STORAGE ,US_SC_SCSI ,US_PR_BULK ) }, { } };MODULE_DEVICE_TABLE (usb, ub_usb_ids); +#endif /* CONFIG_USB_LIBUSUAL */ /* * Find me a way to identify "next free minor" for add_disk(),
@@ -2172,6 +2180,9 @@ static int ub_probe(struct usb_interfaceint rc;int i; +if (USB_US_TYPE (dev_id->driver_info) !=USB_US_TYPE_UB ) +return -ENXIO ; + rc = -ENOMEM ;if ((sc =kmalloc (sizeof (struct ub_dev ),GFP_KERNEL )) ==NULL ) goto err_core;
@@ -2472,6 +2483,8 @@ static int __init ub_init(void) {int rc; +usb_usual_set_present (USB_US_TYPE_UB ,1 ); +if ((rc =register_blkdev (UB_MAJOR ,DRV_NAME )) !=0 ) goto err_regblkdev;devfs_mk_dir (DEVFS_NAME );
@@ -2485,6 +2498,7 @@ err_register:devfs_remove (DEVFS_NAME );unregister_blkdev (UB_MAJOR ,DRV_NAME ); err_regblkdev: +usb_usual_set_present (USB_US_TYPE_UB ,0 );return rc; }
@@ -2494,6 +2508,7 @@ static void __exit ub_exit(void)devfs_remove (DEVFS_NAME );unregister_blkdev (UB_MAJOR ,DRV_NAME ); +usb_usual_set_present (USB_US_TYPE_UB ,0 ); }module_init (ub_init);
drivers/usb/storage/Kconfig +14 -0
@@ -123,3 +123,17 @@ config USB_STORAGE_ONETOUCH hard drive's as an input device. An action can be associated with this input in any keybinding software. (e.g. gnome's keyboard short- cuts) + +config USB_LIBUSUAL + bool "The shared table of common (or usual) storage devices" + depends on USB + help + This module contains a table of common (or usual) devices + for usb-storage and ub drivers, and allows to switch binding + of these devices without rebuilding modules. + + Typical syntax of /etc/modprobe.conf is: + + options libusual bias="ub" + + If unsure, say N.
drivers/usb/storage/libusual.c +257 -0
257 lines not on this page · raw message
drivers/usb/storage/Makefile +4 -0
@@ -22,3 +22,7 @@ usb-storage-obj-$(CONFIG_USB_STORAGE_ONE usb-storage-objs := scsiglue.o protocol.o transport.o usb.o \ initializers.o $(usb-storage-obj-y) + +ifneq ($(CONFIG_USB_LIBUSUAL),) + obj-$(CONFIG_USB) += libusual.o +endif
drivers/usb/storage/protocol.h +0 -14
@@ -41,20 +41,6 @@#ifndef _PROTOCOL_H_#define _PROTOCOL_H_ -/* Sub Classes */ - -#define US_SC_RBC 0x01/* Typically, flash devices */ -#define US_SC_8020 0x02/* CD-ROM */ -#define US_SC_QIC 0x03/* QIC-157 Tapes */ -#define US_SC_UFI 0x04/* Floppy */ -#define US_SC_8070 0x05/* Removable media */ -#define US_SC_SCSI 0x06/* Transparent */ -#define US_SC_ISD200 0x07/* ISD200 ATA */ -#define US_SC_MIN US_SC_RBC -#define US_SC_MAX US_SC_ISD200 - -#define US_SC_DEVICE 0xff/* Use device's value */ -/* Protocol handling routines */ extern void usb_stor_ATAPI_command (struct scsi_cmnd *,struct us_data *);extern void usb_stor_qic157_command (struct scsi_cmnd *,struct us_data *);
drivers/usb/storage/transport.h +0 -30
@@ -44,36 +44,6 @@#include <linux/config.h> #include <linux/blkdev.h> -/* Protocols */ - -#define US_PR_CBI 0x00/* Control/Bulk/Interrupt */ -#define US_PR_CB 0x01/* Control/Bulk w/o interrupt */ -#define US_PR_BULK 0x50/* bulk only */ -#ifdef CONFIG_USB_STORAGE_USBAT -#define US_PR_SCM_ATAPI 0x80/* SCM-ATAPI bridge */ -#endif -#ifdef CONFIG_USB_STORAGE_SDDR09 -#define US_PR_EUSB_SDDR09 0x81/* SCM-SCSI bridge for SDDR-09 */ -#endif -#ifdef CONFIG_USB_STORAGE_SDDR55 -#define US_PR_SDDR55 0x82/* SDDR-55 (made up) */ -#endif -#define US_PR_DPCM_USB 0xf0/* Combination CB/SDDR09 */ - -#ifdef CONFIG_USB_STORAGE_FREECOM -#define US_PR_FREECOM 0xf1/* Freecom */ -#endif - -#ifdef CONFIG_USB_STORAGE_DATAFAB -#define US_PR_DATAFAB 0xf2/* Datafab chipsets */ -#endif - -#ifdef CONFIG_USB_STORAGE_JUMPSHOT -#define US_PR_JUMPSHOT 0xf3/* Lexar Jumpshot */ -#endif - -#define US_PR_DEVICE 0xff/* Use device's value */ -/* * Bulk only data structures */
drivers/usb/storage/unusual_devs.h +24 -0
@@ -1093,3 +1093,27 @@ UNUSUAL_DEV( 0x55aa, 0xa103, 0x0000, 0x US_SC_SCSI, US_PR_SDDR55, NULL, US_FL_SINGLE_LUN),#endif + +/* Control/Bulk transport for all SubClass values */ +USUAL_DEV (US_SC_RBC ,US_PR_CB ,USB_US_TYPE_STOR ), +USUAL_DEV (US_SC_8020 ,US_PR_CB ,USB_US_TYPE_STOR ), +USUAL_DEV (US_SC_QIC ,US_PR_CB ,USB_US_TYPE_STOR ), +USUAL_DEV (US_SC_UFI ,US_PR_CB ,USB_US_TYPE_STOR ), +USUAL_DEV (US_SC_8070 ,US_PR_CB ,USB_US_TYPE_STOR ), +USUAL_DEV (US_SC_SCSI ,US_PR_CB ,USB_US_TYPE_STOR ), + +/* Control/Bulk/Interrupt transport for all SubClass values */ +USUAL_DEV (US_SC_RBC ,US_PR_CBI ,USB_US_TYPE_STOR ), +USUAL_DEV (US_SC_8020 ,US_PR_CBI ,USB_US_TYPE_STOR ), +USUAL_DEV (US_SC_QIC ,US_PR_CBI ,USB_US_TYPE_STOR ), +USUAL_DEV (US_SC_UFI ,US_PR_CBI ,USB_US_TYPE_STOR ), +USUAL_DEV (US_SC_8070 ,US_PR_CBI ,USB_US_TYPE_STOR ), +USUAL_DEV (US_SC_SCSI ,US_PR_CBI ,USB_US_TYPE_STOR ), + +/* Bulk-only transport for all SubClass values */ +USUAL_DEV (US_SC_RBC ,US_PR_BULK ,USB_US_TYPE_STOR ), +USUAL_DEV (US_SC_8020 ,US_PR_BULK ,USB_US_TYPE_STOR ), +USUAL_DEV (US_SC_QIC ,US_PR_BULK ,USB_US_TYPE_STOR ), +USUAL_DEV (US_SC_UFI ,US_PR_BULK ,USB_US_TYPE_STOR ), +USUAL_DEV (US_SC_8070 ,US_PR_BULK ,USB_US_TYPE_STOR ), +USUAL_DEV(US_SC_SCSI, US_PR_BULK, 0),
drivers/usb/storage/usb.c +40 -78
210 lines not on this page · raw message
drivers/usb/storage/usb.h +1 -30
@@ -45,6 +45,7 @@#define _USB_H_#include <linux/usb.h> +#include <linux/usb_usual.h> #include <linux/blkdev.h> #include <linux/smp_lock.h> #include <linux/completion.h>
@@ -63,38 +64,8 @@ struct us_unusual_dev {__u8 useProtocol;__u8 useTransport;int (*initFunction)(struct us_data *); -unsigned int flags; }; -/* -* Static flag definitions. We use this roundabout technique so that the -* proc_info() routine can automatically display a message for each flag. -*/ -#define US_DO_ALL_FLAGS \ - US_FLAG(SINGLE_LUN, 0x00000001) \ -/* allow access to only LUN 0 */ \ -US_FLAG (NEED_OVERRIDE ,0x00000002 ) \ - /* unusual_devs entry is necessary */ \ -US_FLAG (SCM_MULT_TARG ,0x00000004 ) \ - /* supports multiple targets */ \ -US_FLAG (FIX_INQUIRY ,0x00000008 ) \ - /* INQUIRY response needs faking */ \ -US_FLAG (FIX_CAPACITY ,0x00000010 ) \ - /* READ CAPACITY response too big */ \ -US_FLAG (IGNORE_RESIDUE ,0x00000020 ) \ - /* reported residue is wrong */ \ -US_FLAG (BULK32 ,0x00000040 ) \ - /* Uses 32-byte CBW length */ \ -US_FLAG (NOT_LOCKABLE ,0x00000080 ) \ - /* PREVENT/ALLOW not supported */ \ -US_FLAG (GO_SLOW ,0x00000100 ) \ - /* Need delay after Command phase */ \ -US_FLAG (NO_WP_DETECT ,0x00000200 ) \ - /* Don't check for write-protect */ \ - -#define US_FLAG (name, value) US_FL_##name = value , -enum {US_DO_ALL_FLAGS }; -#undef US_FLAG/* Dynamic flag definitions: used in set_bit() etc. */ #define US_FLIDX_URB_ACTIVE 18/* 0x00040000 current_urb is in use */
include/linux/usb_usual.h +118 -0
118 lines not on this page · raw message
Alan Stern
maintainerQuoted 20 lines · Pete Zaitcev
Quoted 11 lines · Alan Stern
Quoted 2 lines
drivers/usb/storage/usb.h +0
-0...
drivers/usb/storage/usb.h
Quoted 3 lines
drivers/usb/storage/usb.h +0
-3-/* Dynamic flag definitions: used in set_bit() etc. */ -#define US_FLIDX_URB_ACTIVE 18/* 0x00040000 current_urb is in use */ -#define US_FLIDX_SG_ACTIVE 19/* 0x00080000 current_sg is in use */ I would prefer to keep these definitions in the usb-storage driver. They refer to dynamic aspects of an individual device, not static blacklist or ID-matching for all devices of a particular type. As such, they are of no interest to ub or libusual.
OK
Quoted 3 lines
Quoted 3 lines
+ * Observe that usb-storage blatantly mixes
set_bit()and normal
+ * shift and mask operations on flags, which is strictly illegal.
+ * And it probably even works for all flags exceptGO_SLOWandNO_WP_DETECT.
Quoted 6 lines
Quoted 2 lines
Once the device is running, the shift/mask operations are used _only_ for reading, never for writing.
OK
How about now?
This is better, thank you.
Alan Stern
usb: drivers/usb/storage/libusual
In reply to Greg KHThis patch adds a shim driver libusual, which routes devices between usb-storage and ub according to the common table, based on unusual_devs.h. The help and example syntax is in Kconfig.
---
I think libusual is ready for Andrew's tree now. I realize that the use of request_module is an inkblot in this copybook, so maybe it's not the time for Linus' tree yet. Another concern I have is if we have any races with hotplug, udev, and HAL.
I haven't heard from Adrian yet, but I suppose it's a good sign. No word from Matt Dharm either, which is not so good... But I do have Alan Stern's buy-in.
This version uses unusual_devs practically as-is, so Phil Deibowitz would see no change.
drivers/block/Kconfig +2 -1
@@ -358,7 +358,8 @@ config BLK_DEV_UB This driver supports certain USB attached storage devices such as flash keys. - Warning: Enabling this cripples the usb-storage driver. + If you enable this driver, it is recommended to avoid conflicts + with usb-storage by enabling USB_LIBUSUAL. If unsure, say N.
drivers/block/ub.c +14 -11
@@ -29,6 +29,7 @@#include <linux/kernel.h> #include <linux/module.h> #include <linux/usb.h> +#include <linux/usb_usual.h> #include <linux/blkdev.h> #include <linux/devfs_fs_kernel.h> #include <linux/timer.h>
@@ -107,16 +108,6 @@*/ /* -* Definitions which have to be scattered once we understand the layout better. -*/ - -/* Transport (despite PR in the name) */ -#define US_PR_BULK 0x50/* bulk only */ - -/* Protocol */ -#define US_SC_SCSI 0x06/* Transparent */ - -/* * This many LUNs per USB device. * Every one of them takes a host, see UB_MAX_HOSTS. */
@@ -422,13 +413,18 @@ static int ub_probe_lun(struct ub_dev *s/* */ +#ifdef CONFIG_USB_LIBUSUAL + +#define ub_usb_ids storage_usb_ids +#else +static struct usb_device_id ub_usb_ids[] = { -// { USB_DEVICE_VER(0x0781, 0x0002, 0x0009, 0x0009) }, /* SDDR-31 */ {USB_INTERFACE_INFO (USB_CLASS_MASS_STORAGE ,US_SC_SCSI ,US_PR_BULK ) }, { } };MODULE_DEVICE_TABLE (usb, ub_usb_ids); +#endif /* CONFIG_USB_LIBUSUAL */ /* * Find me a way to identify "next free minor" for add_disk(),
@@ -2172,6 +2168,9 @@ static int ub_probe(struct usb_interfaceint rc;int i; +if (USB_US_TYPE (dev_id->driver_info) !=USB_US_TYPE_UB ) +return -ENXIO ; + rc = -ENOMEM ;if ((sc =kmalloc (sizeof (struct ub_dev ),GFP_KERNEL )) ==NULL ) goto err_core;
@@ -2472,6 +2471,8 @@ static int __init ub_init(void) {int rc; +usb_usual_set_present (USB_US_TYPE_UB ); +if ((rc =register_blkdev (UB_MAJOR ,DRV_NAME )) !=0 ) goto err_regblkdev;devfs_mk_dir (DEVFS_NAME );
@@ -2485,6 +2486,7 @@ err_register:devfs_remove (DEVFS_NAME );unregister_blkdev (UB_MAJOR ,DRV_NAME ); err_regblkdev: +usb_usual_clear_present (USB_US_TYPE_UB );return rc; }
@@ -2494,6 +2496,7 @@ static void __exit ub_exit(void)devfs_remove (DEVFS_NAME );unregister_blkdev (UB_MAJOR ,DRV_NAME ); +usb_usual_clear_present (USB_US_TYPE_UB ); }module_init (ub_init);
drivers/usb/storage/Kconfig +14 -0
@@ -123,3 +123,17 @@ config USB_STORAGE_ONETOUCH hard drive's as an input device. An action can be associated with this input in any keybinding software. (e.g. gnome's keyboard short- cuts) + +config USB_LIBUSUAL + bool "The shared table of common (or usual) storage devices" + depends on USB + help + This module contains a table of common (or usual) devices + for usb-storage and ub drivers, and allows to switch binding + of these devices without rebuilding modules. + + Typical syntax of /etc/modprobe.conf is: + + options libusual bias="ub" + + If unsure, say N.
drivers/usb/storage/libusual.c +268 -0
268 lines not on this page · raw message
drivers/usb/storage/Makefile +4 -0
@@ -22,3 +22,7 @@ usb-storage-obj-$(CONFIG_USB_STORAGE_ONE usb-storage-objs := scsiglue.o protocol.o transport.o usb.o \ initializers.o $(usb-storage-obj-y) + +ifneq ($(CONFIG_USB_LIBUSUAL),) + obj-$(CONFIG_USB) += libusual.o +endif
drivers/usb/storage/protocol.h +0 -14
@@ -41,20 +41,6 @@#ifndef _PROTOCOL_H_#define _PROTOCOL_H_ -/* Sub Classes */ - -#define US_SC_RBC 0x01/* Typically, flash devices */ -#define US_SC_8020 0x02/* CD-ROM */ -#define US_SC_QIC 0x03/* QIC-157 Tapes */ -#define US_SC_UFI 0x04/* Floppy */ -#define US_SC_8070 0x05/* Removable media */ -#define US_SC_SCSI 0x06/* Transparent */ -#define US_SC_ISD200 0x07/* ISD200 ATA */ -#define US_SC_MIN US_SC_RBC -#define US_SC_MAX US_SC_ISD200 - -#define US_SC_DEVICE 0xff/* Use device's value */ -/* Protocol handling routines */ extern void usb_stor_ATAPI_command (struct scsi_cmnd *,struct us_data *);extern void usb_stor_qic157_command (struct scsi_cmnd *,struct us_data *);
drivers/usb/storage/transport.h +0 -31
@@ -41,39 +41,8 @@#ifndef _TRANSPORT_H_#define _TRANSPORT_H_ -#include <linux/config.h> #include <linux/blkdev.h> -/* Protocols */ - -#define US_PR_CBI 0x00/* Control/Bulk/Interrupt */ -#define US_PR_CB 0x01/* Control/Bulk w/o interrupt */ -#define US_PR_BULK 0x50/* bulk only */ -#ifdef CONFIG_USB_STORAGE_USBAT -#define US_PR_SCM_ATAPI 0x80/* SCM-ATAPI bridge */ -#endif -#ifdef CONFIG_USB_STORAGE_SDDR09 -#define US_PR_EUSB_SDDR09 0x81/* SCM-SCSI bridge for SDDR-09 */ -#endif -#ifdef CONFIG_USB_STORAGE_SDDR55 -#define US_PR_SDDR55 0x82/* SDDR-55 (made up) */ -#endif -#define US_PR_DPCM_USB 0xf0/* Combination CB/SDDR09 */ - -#ifdef CONFIG_USB_STORAGE_FREECOM -#define US_PR_FREECOM 0xf1/* Freecom */ -#endif - -#ifdef CONFIG_USB_STORAGE_DATAFAB -#define US_PR_DATAFAB 0xf2/* Datafab chipsets */ -#endif - -#ifdef CONFIG_USB_STORAGE_JUMPSHOT -#define US_PR_JUMPSHOT 0xf3/* Lexar Jumpshot */ -#endif - -#define US_PR_DEVICE 0xff/* Use device's value */ -/* * Bulk only data structures */
drivers/usb/storage/unusual_devs.h +24 -0
@@ -1093,3 +1113,27 @@ UNUSUAL_DEV( 0x55aa, 0xa103, 0x0000, 0x US_SC_SCSI, US_PR_SDDR55, NULL, US_FL_SINGLE_LUN),#endif + +/* Control/Bulk transport for all SubClass values */ +USUAL_DEV (US_SC_RBC ,US_PR_CB ,USB_US_TYPE_STOR ), +USUAL_DEV (US_SC_8020 ,US_PR_CB ,USB_US_TYPE_STOR ), +USUAL_DEV (US_SC_QIC ,US_PR_CB ,USB_US_TYPE_STOR ), +USUAL_DEV (US_SC_UFI ,US_PR_CB ,USB_US_TYPE_STOR ), +USUAL_DEV (US_SC_8070 ,US_PR_CB ,USB_US_TYPE_STOR ), +USUAL_DEV (US_SC_SCSI ,US_PR_CB ,USB_US_TYPE_STOR ), + +/* Control/Bulk/Interrupt transport for all SubClass values */ +USUAL_DEV (US_SC_RBC ,US_PR_CBI ,USB_US_TYPE_STOR ), +USUAL_DEV (US_SC_8020 ,US_PR_CBI ,USB_US_TYPE_STOR ), +USUAL_DEV (US_SC_QIC ,US_PR_CBI ,USB_US_TYPE_STOR ), +USUAL_DEV (US_SC_UFI ,US_PR_CBI ,USB_US_TYPE_STOR ), +USUAL_DEV (US_SC_8070 ,US_PR_CBI ,USB_US_TYPE_STOR ), +USUAL_DEV (US_SC_SCSI ,US_PR_CBI ,USB_US_TYPE_STOR ), + +/* Bulk-only transport for all SubClass values */ +USUAL_DEV (US_SC_RBC ,US_PR_BULK ,USB_US_TYPE_STOR ), +USUAL_DEV (US_SC_8020 ,US_PR_BULK ,USB_US_TYPE_STOR ), +USUAL_DEV (US_SC_QIC ,US_PR_BULK ,USB_US_TYPE_STOR ), +USUAL_DEV (US_SC_UFI ,US_PR_BULK ,USB_US_TYPE_STOR ), +USUAL_DEV (US_SC_8070 ,US_PR_BULK ,USB_US_TYPE_STOR ), +USUAL_DEV(US_SC_SCSI, US_PR_BULK, 0),
drivers/usb/storage/usb.c +40 -78
210 lines not on this page · raw message
drivers/usb/storage/usb.h +1 -30
@@ -45,6 +45,7 @@#define _USB_H_#include <linux/usb.h> +#include <linux/usb_usual.h> #include <linux/blkdev.h> #include <linux/smp_lock.h> #include <linux/completion.h>
@@ -63,38 +64,8 @@ struct us_unusual_dev {__u8 useProtocol;__u8 useTransport;int (*initFunction)(struct us_data *); -unsigned int flags; }; -/* -* Static flag definitions. We use this roundabout technique so that the -* proc_info() routine can automatically display a message for each flag. -*/ -#define US_DO_ALL_FLAGS \ - US_FLAG(SINGLE_LUN, 0x00000001) \ -/* allow access to only LUN 0 */ \ -US_FLAG (NEED_OVERRIDE ,0x00000002 ) \ - /* unusual_devs entry is necessary */ \ -US_FLAG (SCM_MULT_TARG ,0x00000004 ) \ - /* supports multiple targets */ \ -US_FLAG (FIX_INQUIRY ,0x00000008 ) \ - /* INQUIRY response needs faking */ \ -US_FLAG (FIX_CAPACITY ,0x00000010 ) \ - /* READ CAPACITY response too big */ \ -US_FLAG (IGNORE_RESIDUE ,0x00000020 ) \ - /* reported residue is wrong */ \ -US_FLAG (BULK32 ,0x00000040 ) \ - /* Uses 32-byte CBW length */ \ -US_FLAG (NOT_LOCKABLE ,0x00000080 ) \ - /* PREVENT/ALLOW not supported */ \ -US_FLAG (GO_SLOW ,0x00000100 ) \ - /* Need delay after Command phase */ \ -US_FLAG (NO_WP_DETECT ,0x00000200 ) \ - /* Don't check for write-protect */ \ - -#define US_FLAG (name, value) US_FL_##name = value , -enum {US_DO_ALL_FLAGS }; -#undef US_FLAG/* Dynamic flag definitions: used in set_bit() etc. */ #define US_FLIDX_URB_ACTIVE 18/* 0x00040000 current_urb is in use */
include/linux/usb_usual.h +120 -0
120 lines not on this page · raw message
Re: [usb-storage] usb: drivers/usb/storage/libusual
Quoted 8 lines · Pete Zaitcev
This patch adds a shim driver libusual, which routes devices between usb-storage and ub according to the common table, based on
unusual_devs.h. The help and example syntax is inKconfig.Signed-off-by Pete Zaitcev <[email protected]>---
Quoted 8 lines
I think libusual is ready for Andrew's tree now. I realize that the use of
request_moduleis an inkblot in this copybook, so maybe it's not the time for Linus' tree yet. Another concern I have is if we have any races with hotplug, udev, and HAL.I haven't heard from Adrian yet, but I suppose it's a good sign. No word from Matt Dharm either, which is not so good... But I do have Alan Stern's buy-in.
Well, I guess it's time for me to comment, then. I have been watching
with great interest.
I have to say, I totally agree that this is a problem that needs solving. The current situation is a mess....
But, I'm not sure this is much better. It's certainly different, but I fear that we're going to spend a lot of time explaining to end-users a new and less-than-totally-obvious system.
Technically, this is much better than what we have. I'm just not sure about the "end user experience".
And I think I'm totally convinced now that request_module() needs some serious help. Either it needs to go away entirely, or be replaced by a helper, such that request_module() gets a module loaded, but module binding to a device is controlled via another mechanism.
Overall, send it to Andrew's tree. But I'd really like to see it live there for an extended period of time before going to Linus. And I'd also like to see some ideas for the final solution, which would apply to HID devices with the same problem.
I hate solving problems twice. It creates twice as much work for everyone, including distro folks and end-users. Let's figure this out as a more generic driver-binding problem for all drivers once and for all.
Matt
Signature · 6 lines
Matthew Dharm Home: [email protected] Maintainer, Linux USB Mass Storage Driver How would you like this tie wrapped around your hairy round head? -- Greg User Friendly, 9/2/1998
Re: [usb-storage] usb: drivers/usb/storage/libusual
Quoted 3 lines · Matthew Dharm
But, I'm not sure this is much better. It's certainly different, but I fear that we're going to spend a lot of time explaining to end-users a new and less-than-totally-obvious system.
Devices continue to default to usb-storage, regardless if libusual is configured. So, no explanations should be necessary at first. Fedora may be different if we like how it works in Rawhide and let it into a release. Then I would talk to Karsten about documenting this in Fedora handbook.
Although... I may be missing something about the behaviour of end users. I thought that what we had before was transparent, but I was wrong.
I have some hopes for Gentoo users to tell me if libusual is workable actually. They like to try new options as soon as they appear :-)
Quoted 2 lines
And I think I'm totally convinced now that
request_module()needs some serious help. []
I think maybe if this use of it gets visible, it may be easier to implement changes to request_module(), than if I were just mailing to linux-kernel. Patch always speaks louder than words.
Maybe Keith or Rusty will have a look and bust this to bits, from the module-init-tools perspective.
-- Pete
Alan Stern
maintainerQuoted 2 lines · Pete Zaitcev
In my tree, I always use the following patchlet, which deconflicts ub and usb-storage:
...
Quoted 31 lines
This makes hotplug to function in a deterministic way, which is a good thing. The patch is not in Linus' tree. It was there at one point, but Adrian Bunk removed it.
Why? Because he could not be bothered to understand how the hotplug works. Before we say "how stupid", observe that he was very far from being alone. A few other users also enabled UB (despite all the warnings in
Kconfig) and then did not know what to do when something did not work for them. And people involved were not morons at all. I had to explain how this was supposed to work to Doug Gilbert and Randy Dunlap, who had considerable experience. This tells me that the mechanisms I used here were unreasonably intricate (to put it mildly).Simply put, if it's not obvious, it's wrong.
So, I came up with a solution to the problem, which, I hope, is better. It has the following features:
- Theusb_device_idtable is now shared between ub and usb-storage.
- The table is located physically in a neutral driver, libusual.
- There is only one table. It is not split in any way.
- Userland tricks are not used (not necesserily a good thing).
- Devices can be marked for use by ub or usb-storage without rebuilding or rebooting.
- The scheme can be useful for sharing of devices between HID, Wacom, and Apitek, if we like how it works for the storage.
- Even with every kernel option enabled, the assignment defaults to usb-storage. Users have to add an explicit option to/etc/modprobe.confbefore the ub gets hotplugged. Thus, the system addresses the Adrian's original problem.
Quoted 2 lines
Patch is attached. I would like someone to look it over and challenge it. The thing looks too complex to me, but I see no other way. Anyone?
Future plans for usb-storage include the possibility of taking out all its "subdrivers" -- the code to handle devices that don't use the standard transport protocols -- and putting them into separate modules. Those subdrivers are responsible for many of the entries in unusual_devs.h, and clearly each module would need its own device table.
This raises a few questions:
Can your scheme accomodate these "subdriver" modules?
Will the hotplug system work with them? I'm not sure, but it's possible that in some cases the device descriptors will match the generic usb-storage or ub driver as well as the more specialized "subdriver". Will the hotplug system choose the most specific match? Even if it's not currently loaded in memory and the less specific driver is?
Alan Stern
Quoted 3 lines · Alan Stern
On Tue, 27 Sep 2005, Pete Zaitcev wrote:
Can your scheme accomodate these "subdriver" modules?
Yes. We'd have to add a few types, like USB_US_TYPE_USBAT or something.
Quoted 6 lines
Will the hotplug system work with them? I'm not sure, but it's possible that in some cases the device descriptors will match the generic usb-storage or ub driver as well as the more specialized "subdriver". Will the hotplug system choose the most specific match? Even if it's not currently loaded in memory and the less specific driver is?
This problem exists already, in the shape of an Adaptec SCSI adapter with Bulk transport. The ub attaches to it just fine, but then it cannot drive tapes or other non-disk devices behind the adapter.
I solve it by ordering the table so that the more specific entry is ahead of the least specific entries. This is why subdrivers have pointers to a common table and have to test type and reject "other" devices. This is why the table is not split.
I tried to find a way to a) make modprobe to match with v*p* first, then dcb* and other such things, when it looks at modules.alias, and
b) have kernel to find "best fit" instead of "first fit". It can be done. But I thought that if I engage into wholesale improvements like that, I'll miss the window of Fedora Core 5.
Strategically, such approach sounds attractive, and, fortunately for me, does not seem to conflict with that I came up presently. We'll add split tables later, and that may allow to throw out request_module(). Sounds good, just maybe not this month.
-- Pete
Quoted 2 lines · Pete Zaitcev
Patch is attached. I would like someone to look it over and challenge it. The thing looks too complex to me, but I see no other way. Anyone?
OK, so I'm not very familiar with a lot of the code affected here, but since it diddles with unusual_devs, I feel I should chime in. But I'll chime in with a question. ;)
A quick look over the patch shows that there are now two kinds of unusual_dev entries: unusual_dev() and unusual_dev_fl(), where the latter is for entries that don't need to specify SC or PR (i.e., just had US_SC_DEVICE, US_PR_DEVICE in them). While I think that's a reasonable change, it's not clear to me why that's useful to the rest of the patch, or it's just making unusual_devs.h artificially shorter?
Signature · 7 lines
Phil Dibowitz [email protected] Freeware and Technical Pages Insanity Palace of Metallica http://www.phildev.net/ http://www.ipom.com/ "They that can give up essential liberty to obtain a little temporary safety deserve neither liberty nor safety." - Benjamin Franklin, 1759
Quoted 6 lines · Phil Dibowitz
A quick look over the patch shows that there are now two kinds of
unusual_deventries:unusual_dev()andunusual_dev_fl(), where the latter is for entries that don't need to specify SC or PR (i.e., just hadUS_SC_DEVICE,US_PR_DEVICEin them). While I think that's a reasonable change, it's not clear to me why that's useful to the rest of the patch, or it's just makingunusual_devs.hartificially shorter?
Greg asked that too and I skipped his question because I needed an explanation. So here it is now.
I thought that the match list for USB core and the shadow list that usb-storage had were separate. So, libusual receives the first but not the second, which remains in usb-storage. Once they are split like that, I thought it unsafe to continue to use an index to correlate them, so I added extra fields into the list of information specific list to usb-storage, for matching. These fields use more memory, so I thought it would cost nothing to move flags over into driver_info. The resultant savings make usb-storage somewhat shorter than it was before. It is shorter even when libusual is configured off. This is because the second list is about twice shorter now.
I can drop that part of the patch, I just thought it would be safer. If you prefer that, I would suggest moving "normal" devices at the bottom of the list into the unusual_devs.h, to make sure that indexes stay the same. In such case, we won't need dropping commas.
-- Pete