Add support for Ratoc U2SCX
Subsystems (2)
Hi,
this patchset add support for Ratoc U2SCX USB/SCSI converters. For additional information see http://www.ratocsystems.com/english/products/U2SCX.html.
Regards
Sven
Sven Schnelle (2):
usb/storage: add SCSI ID and LUN to debug output
usb-storage: Add support for Ratoc U2SCX multiple device mode
drivers/usb/storage/debug.c | 3 ++- drivers/usb/storage/initializers.c | 27 +++++++++++++++++++++++++++ drivers/usb/storage/initializers.h | 2 ++ drivers/usb/storage/unusual_devs.h | 5 +++++ 4 files changed, 36 insertions(+), 1 deletion(-)
Signature · 1 line
2.24.1
PATCH 1/2 usb/storage: add SCSI ID and LUN to debug output
Add the LUN and SCSI ID to the debug output so it is a bit easier to figure out which device is actually adressed.
--- drivers/usb/storage/debug.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/usb/storage/debug.c +2 -1
@@ -136,7 +136,8 @@ void usb_stor_show_command(const struct us_data *us, struct scsi_cmnd *srb)case WRITE_LONG_2 : what ="WRITE_LONG_2" ;break ;default : what ="(unknown command)" ;break ; } -usb_stor_dbg (us,"Command %s (%d bytes)\n" , what, srb->cmd_len); +usb_stor_dbg (us,"ID %d:%lld Command %s (%d bytes)\n" , + srb->device->id, srb->device->lun, what, srb->cmd_len);usb_stor_dbg (us,"bytes: %*ph\n" ,min_t (int, srb->cmd_len,16 ), (const unsigned char *)srb->cmnd); }
Signature · 1 line
2.24.1
PATCH 2/2 usb-storage: Add support for Ratoc U2SCX multiple device mode
In reply to Sven SchnelleThe Ratoc U2SCX can support more than one device but uses another USB ID in that case (0584:0222) with a Vendor specific class. The used protocol is still USB Mass storage, but we need to fetch the maximum LUN number as otherwise the controller would address all devices on the SCSI bus when an invalid LUN is probed. It looks like U2SCX maps SCSI ID to LUN numbers, so we must not enable US_FL_SCM_MULT_TARG.
dmesg with the driver enabled looks like this:
[ 133.157337] usb 1-2: new high-speed USB device number 6 using xhci_hcd [ 133.170273] usb 1-2: New USB device found, idVendor=0584, idProduct=0222, bcdDevice= 1.11 [ 133.170279] usb 1-2: New USB device strings: Mfr=1, Product=3, SerialNumber=2 [ 133.170283] usb 1-2: Product: USB-SCSI Converter [ 133.170286] usb 1-2: Manufacturer: RATOCSystems,Inc. [ 133.170289] usb 1-2: SerialNumber: 020301002197 [ 133.171576] usb-storage 1-2:1.0: USB Mass Storage device detected [ 133.172084] scsi host1: usb-storage 1-2:1.0 [ 134.199245] scsi 1:0:0:0: CD-ROM HL-DT-ST DVDRAM GSA-4163B A100 PQ: 0 ANSI: 2 [ 134.202744] scsi 1:0:0:1: Direct-Access SyQuest SQ5200C A0L PQ: 0 ANSI: 2 [ 134.219300] scsi 1:0:0:2: Direct-Access SyQuest SQ3270S 1_24 PQ: 0 ANSI: 2 [ 134.224660] sr 1:0:0:0: Power-on or device reset occurred [ 134.343256] sr 1:0:0:0: [sr0] scsi3-mmc drive: 40x/40x writer dvd-ram cd/rw xa/form2 cdda tray [ 134.343262] cdrom: Uniform CD-ROM driver Revision: 3.20 [ 134.350873] sr 1:0:0:0: Attached scsi CD-ROM sr0 [ 134.351120] sr 1:0:0:0: Attached scsi generic sg1 type 5 [ 134.351438] sd 1:0:0:1: Attached scsi generic sg2 type 0 [ 134.351685] sd 1:0:0:2: Attached scsi generic sg3 type 0 [ 134.362141] sd 1:0:0:1: Power-on or device reset occurred [ 134.483977] sd 1:0:0:1: [sdb] Attached SCSI removable disk [ 134.513922] sd 1:0:0:2: Power-on or device reset occurred [ 134.579802] sd 1:0:0:2: [sdc] Spinning up disk... [ 135.602397] ...... [ 141.707017] sd 1:0:0:1: [sdb] Spinning up disk... [ 151.346332] .ready [ 151.353990] sd 1:0:0:2: [sdc] 524288 512-byte logical blocks: (268 MB/256 MiB) [ 151.361560] sd 1:0:0:2: [sdc] Write Protect is off [ 151.361566] sd 1:0:0:2: [sdc] Mode Sense: 99 00 00 08 [ 151.368868] sd 1:0:0:2: [sdc] Write cache: disabled, read cache: enabled, doesn't support DPO or FUA [ 151.428485] sdc: sdc1 [ 151.465364] sd 1:0:0:2: [sdc] Attached SCSI removable disk [ 152.178231] .....ready [ 156.535115] sd 1:0:0:1: [sdb] 173456 512-byte logical blocks: (88.8 MB/84.7 MiB) [ 156.606445] sdb: sdb1
--- drivers/usb/storage/initializers.c | 27 +++++++++++++++++++++++++++ drivers/usb/storage/initializers.h | 2 ++ drivers/usb/storage/unusual_devs.h | 5 +++++ 3 files changed, 34 insertions(+)
drivers/usb/storage/initializers.c +27 -0
@@ -44,6 +44,33 @@ int usb_stor_euscsi_init(struct us_data *us)return 0 ; } +/* Function to get the maximum LUN (Logical Unit number) from Ratoc. */ +int usb_stor_ratoc_u2scx_init (struct us_data *us) +{ +int i, result; +uint8_t *idmap = (uint8_t *)us->iobuf; + + result =usb_stor_control_msg (us, us->recv_ctrl_pipe, +0xe6 ,USB_DIR_IN |USB_TYPE_VENDOR | +USB_RECIP_INTERFACE , +0x0 ,0x0 , idmap,8 ,5 *HZ ); + +if (result <0 ) { +usb_stor_dbg (us,"fetching max lun failed: %d\n" , result); +return result; + } + +for (i =0 ; i <7 ; i++) { +if (idmap[i] ==0xff ) +break ; + } + +if (i ==0 ) +return -EIO ; + + us->max_lun = i -1 ; +return 0 ; +}/* * This function is required to activate all four slots on the UCR-61S2B * flash reader
drivers/usb/storage/initializers.h +2 -0
@@ -37,3 +37,5 @@ int usb_stor_ucr61s2b_init(struct us_data *us);/* This places the HUAWEI E220 devices in multi-port mode */ int usb_stor_huawei_e220_init (struct us_data *us); + +int usb_stor_ratoc_u2scx_init (struct us_data *us);
drivers/usb/storage/unusual_devs.h +5 -0
@@ -2372,6 +2372,11 @@ UNUSUAL_DEV( 0xed10, 0x7636, 0x0001, 0x0001, "Digital MP3 Audio Player", USB_SC_DEVICE, USB_PR_DEVICE, NULL, US_FL_NOT_LOCKABLE ), +UNUSUAL_DEV(0x0584, 0x0222, 0x0000, 0xffff, + "Ratoc", + "U2SCX USB SCSI converter", + USB_SC_DEVICE, USB_PR_DEVICE, usb_stor_ratoc_u2scx_init, 0), +/* Unusual uas devices */ #if IS_ENABLED (CONFIG_USB_UAS )#include "unusual_uas.h"
Signature · 1 line
2.24.1
Alan Stern
maintainerRe: [PATCH 2/2] usb-storage: Add support for Ratoc U2SCX multiple device mode
Quoted 36 lines · Sven Schnelle
The Ratoc U2SCX can support more than one device but uses another USB ID in that case (0584:0222) with a Vendor specific class. The used protocol is still USB Mass storage, but we need to fetch the maximum LUN number as otherwise the controller would address all devices on the SCSI bus when an invalid LUN is probed. It looks like U2SCX maps SCSI ID to LUN numbers, so we must not enable
US_FL_SCM_MULT_TARG.dmesg with the driver enabled looks like this:
[ 133.157337] usb 1-2: new high-speed USB device number 6 using xhci_hcd [ 133.170273] usb 1-2: New USB device found, idVendor=0584, idProduct=0222, bcdDevice= 1.11 [ 133.170279] usb 1-2: New USB device strings: Mfr=1, Product=3, SerialNumber=2 [ 133.170283] usb 1-2: Product: USB-SCSI Converter [ 133.170286] usb 1-2: Manufacturer: RATOCSystems,Inc. [ 133.170289] usb 1-2: SerialNumber: 020301002197 [ 133.171576] usb-storage 1-2:1.0: USB Mass Storage device detected [ 133.172084] scsi host1: usb-storage 1-2:1.0 [ 134.199245] scsi 1:0:0:0: CD-ROM HL-DT-ST DVDRAM GSA-4163B A100 PQ: 0 ANSI: 2 [ 134.202744] scsi 1:0:0:1: Direct-Access SyQuest SQ5200C A0L PQ: 0 ANSI: 2 [ 134.219300] scsi 1:0:0:2: Direct-Access SyQuest SQ3270S 1_24 PQ: 0 ANSI: 2 [ 134.224660] sr 1:0:0:0: Power-on or device reset occurred [ 134.343256] sr 1:0:0:0: [sr0] scsi3-mmc drive: 40x/40x writer dvd-ram cd/rw xa/form2 cdda tray [ 134.343262] cdrom: Uniform CD-ROM driver Revision: 3.20 [ 134.350873] sr 1:0:0:0: Attached scsi CD-ROM sr0 [ 134.351120] sr 1:0:0:0: Attached scsi generic sg1 type 5 [ 134.351438] sd 1:0:0:1: Attached scsi generic sg2 type 0 [ 134.351685] sd 1:0:0:2: Attached scsi generic sg3 type 0 [ 134.362141] sd 1:0:0:1: Power-on or device reset occurred [ 134.483977] sd 1:0:0:1: [sdb] Attached SCSI removable disk [ 134.513922] sd 1:0:0:2: Power-on or device reset occurred [ 134.579802] sd 1:0:0:2: [sdc] Spinning up disk... [ 135.602397] ...... [ 141.707017] sd 1:0:0:1: [sdb] Spinning up disk... [ 151.346332] .ready [ 151.353990] sd 1:0:0:2: [sdc] 524288 512-byte logical blocks: (268 MB/256 MiB)
Quoted 8 lines
[ 151.361560] sd 1:0:0:2: [sdc] Write Protect is off [ 151.361566] sd 1:0:0:2: [sdc] Mode Sense: 99 00 00 08 [ 151.368868] sd 1:0:0:2: [sdc] Write cache: disabled, read cache: enabled, doesn't support DPO or FUA [ 151.428485] sdc: sdc1 [ 151.465364] sd 1:0:0:2: [sdc] Attached SCSI removable disk [ 152.178231] .....ready [ 156.535115] sd 1:0:0:1: [sdb] 173456 512-byte logical blocks: (88.8 MB/84.7 MiB) [ 156.606445] sdb: sdb1
Isn't this the same as we would see for any multi-LUN device? What's so special about this log that you thought including it here was important?
Quoted 12 lines
Signed-off-by Sven Schnelle <[email protected]>--- drivers/usb/storage/initializers.c | 27 +++++++++++++++++++++++++++ drivers/usb/storage/initializers.h | 2 ++ drivers/usb/storage/unusual_devs.h | 5 +++++ 3 files changed, 34 insertions(+)drivers/usb/storage/initializers.c +0
-0
drivers/usb/storage/initializers.c int usb_stor_euscsi_init(struct us_data *us) · line 47
Quoted 4 lines
drivers/usb/storage/initializers.c +1
-0@@ -44,6 +44,33 @@ int usb_stor_euscsi_init(struct us_data *us)return 0 ; } +/* Function to get the maximum LUN (Logical Unit number) from Ratoc. */
People reading this code almost certainly already know what "LUN" stands for. You don't have to remind them.
Quoted 4 lines
drivers/usb/storage/initializers.c +4
-0+int usb_stor_ratoc_u2scx_init (struct us_data *us) +{ +int i, result; +uint8_t *idmap = (uint8_t *)us->iobuf;
drivers/usb/storage/initializers.c int usb_stor_euscsi_init(struct us_data *us) · line 61
Quoted 10 lines
drivers/usb/storage/initializers.c +10
-0+ + result =usb_stor_control_msg (us, us->recv_ctrl_pipe, +0xe6 ,USB_DIR_IN |USB_TYPE_VENDOR | +USB_RECIP_INTERFACE , +0x0 ,0x0 , idmap,8 ,5 *HZ ); + +if (result <0 ) { +usb_stor_dbg (us,"fetching max lun failed: %d\n" , result); +return result; + }
You don't want to check that the device actually returned 8 bytes of data? What if it returned fewer?
drivers/usb/storage/initializers.c int usb_stor_euscsi_init(struct us_data *us) · line 64
Quoted 3 lines
drivers/usb/storage/initializers.c +3
-0+ +for (i =0 ; i <7 ; i++) { +if (idmap[i] ==0xff )
You didn't initialize the contents of idmap. So if the device returned fewer than 7 bytes, what makes you think the extra value will be 0xff?
Quoted 27 lines
drivers/usb/storage/initializers.c +9
-0+break ; + } + +if (i ==0 ) +return -EIO ; + + us->max_lun = i -1 ; +return 0 ; +}/* * This function is required to activate all four slots on the UCR-61S2B * flash reader drivers/usb/storage/initializers.h +2
-0@@ -37,3 +37,5 @@ int usb_stor_ucr61s2b_init(struct us_data *us);/* This places the HUAWEI E220 devices in multi-port mode */ int usb_stor_huawei_e220_init (struct us_data *us); + +int usb_stor_ratoc_u2scx_init (struct us_data *us);drivers/usb/storage/unusual_devs.h +0
-0
drivers/usb/storage/unusual_devs.h UNUSUAL_DEV( 0xed10, 0x7636, 0x0001, 0x0001, · line 2379
Quoted 8 lines
drivers/usb/storage/unusual_devs.h +5
-0@@ -2372,6 +2372,11 @@ UNUSUAL_DEV( 0xed10, 0x7636, 0x0001, 0x0001, "Digital MP3 Audio Player", USB_SC_DEVICE, USB_PR_DEVICE, NULL, US_FL_NOT_LOCKABLE ), +UNUSUAL_DEV (0x0584 ,0x0222 ,0x0000 ,0xffff , +"Ratoc" , +"U2SCX USB SCSI converter" , + USB_SC_DEVICE, USB_PR_DEVICE, usb_stor_ratoc_u2scx_init, 0), +
Please read the comments at the start of the file, in particular the part describing how the entries should e sorted.
Alan Stern
Quoted 4 lines
drivers/usb/storage/unusual_devs.h +0
-0/* Unusual uas devices */ #if IS_ENABLED (CONFIG_USB_UAS )#include "unusual_uas.h"