[prev in list] [next in list] [prev in thread] [next in thread] 

List:       packet-writing
Subject:    SUMMARY: 2.4.21 packet-mode UDF CDRW via USB from external ATAPI burner
From:       Frantisek Rysanek <Frantisek.Rysanek () post ! cz>
Date:       2003-08-28 10:42:52
[Download RAW message or body]

Dear everyone,


this message is a summary/result of a private e-mail exchange with
a few Linux kernel developers. The two active participants were
Peter Osterlund and Matthew Dharm.

I was trying to get packet-written UDF to work with the following
hardware setup:

[Linux PC]->[USB]->[USB/IDE converter]->[ATAPI CDRW drive]

USB/IDE converter was one of
1) Cypress Semiconductor CY7C68300  (USB2)
2) ScanLogic SL11R-IDE (USB 1.1)

ATAPI CDRW drive was one of
1) NEC DVD_RW ND-1300A
2) RICOH CD-R/RW MP7240A

The Linux kernel version was 2.4.21.

As posted earlier and documented elsewhere, for packet writing
to CD-ROM drives, you need the packet-writing kernel patch
and you need to set up /dev/pktcdvd* device nodes.
You also need to download the udf-tools package, containing
some user-space utils, most importantly pktsetup and cdrwtool.

As documented elsewhere, IDE/ATAPI devices attached via
a USB converter appear in Linux as dynamically added SCSI
devices - the CD drives appear as /dev/scd*.
The emulation magic is done by the usb-storage module. 


My symptoms were the following:
1) UDF formatting using cdrwtool and CD burning using cdrecord
    was possible at least with the Cypress chip (USB2). The ScanLogic
    chip tended to corrupt such long track-at-once writes for some
    reason, either due to an individual hardware failure or due to
    a design flaw, or maybe due to USB1.1 - I don't know.
2) it was possible to run pktsetup and to mount the media RW
3) write attempts generated heaps of I/O errors and nothing
    got actually written.
4) which could be checked by unmounting the CD and
    remounting it read-only from the base device scd*
   (which worked flawless)
5) with native ATAPI/IDE attachment (no USB), the software
    setup worked flawless.

An additional symptom is that, when attached via the USB converter,
the ATAPI CDRW drive is detected as a scsi1 cdrom, rather than
a scsi3-mmc cdrw.


The reason is the following:
In Linux 2.4, the usb-storage module does a SCSI emulation.
My limited knowledge suggests that SCSI and ATAPI share
a common subset of the command sets. There are two standard
formats of the SCSI commands: 6byte and 10byte.
There's a special MODE_SENSE command, that allows the host
computer to learn about the capabilities of a particular SCSI
(cdrom?) device - read-only, read-write, CD/DVD etc.
My ATAPI devices only accept the 10byte MODE_SENSE.
I don't know if this is an inherent ATAPI feature or practical
implementation flaw that goes unnoticed under Microsoft and Apple
OS'es (as suggested by others).
The pktcdvd.o module (for UDF packet writing on CDRW) uses
the standard SCSI CDrom interface (the sr.o module) to access
the SCSI drives, and hence also USB-storage / ATAPI devices.
The sr.o module uses 6byte MODE_SENSE to get the device capabilities.
The usb-storage module is able to translate the 6byte MODE_SENSE
to 10byte, if inited properly. However, it does not act accordingly on the
basis of just detecting an ATAPI CDROM. The particular init parameters
have to be configured in drivers/usb/storage/unusual_devs.h, for
a particular *USB/IDE converter*. The defaults for my converters
do not include 6byte-to-10byte translation.

Why cdrecord and cdrwtool do work: they're using the SCSI-generic
interface, rather than the SCSI-cdrom interface. And they're doing their
own detection (MODE_SENSE). And, CDrecord has been used to
dealing with ATAPI CDRW drives via a SCSI emulation for quite some
time now. The cdrwtool seems to be inspired by cdrecord in this
respect.


Solution:
Compile-time configuration change is required, in a header file
(not accessible via config/menuconfig).
I had to modify one section and add one section to the unusual_devs.h.
See the patch attached below my signature.

There are two possible modifications to unusual_devs.h:
either you can stick to the default US_SC_SCSI protocol and just
add the US_FL_MODE_XLATE flag (can be OR'ed with other flags),
or you can replace the US_SC_SCSI protocol by one of US_SC_8020
or US_SC_8070. Deeper in the usb-storage guts, this is essentially
equivalent to adding the US_FL_MODE_XLATE flag to the transparent
SCSI handler. Matthew Dharm says that this is _not_quite_ equivalent
- I'm not sure.

Thanks to Peter Osterlund for suggesting the US_SC_8020 tag and
thanks to Matthew Dharm for spending his time discussing the
usb-storage guts with me. Thanks to both for the debugging 
hints.
Matthew Dharm went on to suggest that this should really be solved
in sr.o, in the get_capabilites() function, that should try 10byte
MODE_SENSE and fall back to 6byte. Which is a point for
further improvements in sr.c and has already been suggested
by Matthew Dharm at the relevant addresses...
Meanwhile, the 2.6.x is knocking on the door, coming with a ton of
reworks and improvements in USB/SCSI/IDE, a new runtime
hot-swappable device inventory model etc.


Other implications:
Due to the way usb-storage is implemented in kernel 2.4.21, there
is no way in terms of compile-time configuration to enable 6-to-10byte
command translation for all ATAPI CDRW drives in general.
The default is "no translation" and everyone needs to turn this on for
their particular converter USB/IDE converter chip (rather than
for a particular ATAPI drive). Which involves modifying or adding
a section in unusual_devs.h.


Debugging hints:
Turn on USB debugging, verbose USB storage debugging,
verbose SCSI debugging and kernel debugging in 'make menuconfig'.
Set PACKET_DEBUG to 2 in include/linux/pktcdvd.h .
Don't forget to turn on kernel debug logging in syslog.conf
&& /etc/init.d/syslog restart
The messages from usb-storage come out as kern.=debug .
I myself have set up logging of all kernel messages into
a dedicated file:
# add this line to /etc/systlog.conf
kern.*       /var/log/kerndebug


Thanks to everyone involved for their time and effort.

Frank Rysanek



############## now for the patch ############

Please note another patch that had to be applied in order to make the ScanLogic
SL11R chip work (merged in my patch below). The patch was originally applied by
Gunther Meyer a long time ago, disapproved of by Leif Sawyer shortly afterwards,
but seems to be necessary even now - without it, usb-storage.o hangs upon
insmod.
One other unnecessary modification is the additional debugging stub in
drivers/usb/storage/transport.c that shows whether the translation works.

If you're only interested in 6-to-10byte translation, focus on unusual_devs.h
and the flag US_FL_MODE_XLATE.
Please note that this patch is hardware-specific to my USB/IDE converters
- but you shouldn't have a problem to roll your own section in unusual_devs.h
if you have a different converter chip with the same symptoms.

############### file 2.4.21-USB_packet_UDF_CDRW.patch ################

diff -Naur linux-2.4.21-pkt/drivers/usb/storage/transport.c linux/drivers/usb/storage/transport.c
--- linux-2.4.21-pkt/drivers/usb/storage/transport.c	2003-06-13 16:51:37.000000000 +0200
+++ linux/drivers/usb/storage/transport.c	2003-08-27 14:14:47.000000000 +0200
@@ -627,6 +627,10 @@
 	int need_auto_sense;
 	int result;
 
+	US_DEBUGP("usb_stor_invoke_transport():\n");
+	US_DEBUGP("  obtained this from the protocol handler:\n");
+	US_DEBUG(usb_stor_show_command(us->srb));
+	
 	/* send the command to the transport layer */
 	result = us->transport(srb, us);
 
@@ -1251,7 +1255,8 @@
 		  le32_to_cpu(bcs->Signature), bcs->Tag, 
 		  bcs->Residue, bcs->Status);
 	if (bcs->Signature != cpu_to_le32(US_BULK_CS_SIGN) || 
-	    bcs->Tag != bcb->Tag || 
+/*	    bcs->Tag != bcb->Tag || */
+            ((bcs->Tag != bcb->Tag) && !(us->flags & US_FL_QUIRKS_TAG)) ||
 	    bcs->Status > US_BULK_STAT_PHASE || partial != 13) {
 		US_DEBUGP("Bulk logical error\n");
 		ret = USB_STOR_TRANSPORT_ERROR;
diff -Naur linux-2.4.21-pkt/drivers/usb/storage/unusual_devs.h linux/drivers/usb/storage/unusual_devs.h
--- linux-2.4.21-pkt/drivers/usb/storage/unusual_devs.h	2003-08-20 09:33:08.000000000 +0200
+++ linux/drivers/usb/storage/unusual_devs.h	2003-08-27 14:07:18.000000000 +0200
@@ -120,13 +120,40 @@
 
 /* Reported by Peter Wächtler <pwaechtler@loewe-komp.de>
  * The device needs the flags only.
+ * 
+ * Update by Gunther Meyer <gunther.mayer@gmx.net>:
+ * Firmware 2.60 needs US_FL_QUIRKS_TAG here! Bugger device.
+ *
+ * Update by Frank Rysanek <Frantisek.Rysanek@post.cz>:
+ * For proper detection of ATAPI MMC CD-RW drives, so that
+ * they're any use for packet-written UDF, this device also
+ * needs the US_FL_MODE_XLATE flag.
+ * In combination with the US_SC_SCSI protocol, this flag
+ * causes translation of the 6byte MODE_SENSE commands to
+ * the corresponding 10byte format.
  */
-UNUSUAL_DEV(  0x04ce, 0x0002, 0x0074, 0x0074,
+UNUSUAL_DEV(  0x04ce, 0x0002, 0x0000, 0x9999,
 		"ScanLogic",
 		"SL11R-IDE",
 		US_SC_SCSI, US_PR_BULK, NULL,
-		US_FL_FIX_INQUIRY),
+		US_FL_QUIRKS_TAG | US_FL_MODE_XLATE),
 
+/* Reported by Frank Rysanek <Frantisek.Rysanek@post.cz>.
+ * For proper detection of ATAPI MMC CD-RW drives, so that
+ * they're any use for packet-written UDF, this device also
+ * needs the US_FL_MODE_XLATE flag.
+ * In combination with the US_SC_SCSI protocol, this flag
+ * causes translation of the 6byte MODE_SENSE commands to
+ * the corresponding 10byte format.
+ * Otherwise the device is perfectly generic,
+ * For read-only CDRom access this entry is not needed.
+ */
+UNUSUAL_DEV(  0x04b4, 0x6830, 0x0000, 0x9999,
+		"Cypress Semiconductor",
+		"CY7C68300 USB2/IDE converter",
+		US_SC_SCSI, US_PR_BULK, NULL,
+		US_FL_MODE_XLATE), 
+		
 /* Reported by Kriston Fincher <kriston@airmail.net>
  * Patch submitted by Sean Millichamp <sean@bruenor.org>
  * This is to support the Panasonic PalmCam PV-SD4090
diff -Naur linux-2.4.21-pkt/drivers/usb/storage/usb.h linux/drivers/usb/storage/usb.h
--- linux-2.4.21-pkt/drivers/usb/storage/usb.h	2003-08-20 09:33:06.000000000 +0200
+++ linux/drivers/usb/storage/usb.h	2003-08-20 09:50:08.000000000 +0200
@@ -103,6 +103,9 @@
 #define US_FL_IGNORE_SER      0x00000010 /* Ignore the serial number given  */
 #define US_FL_SCM_MULT_TARG   0x00000020 /* supports multiple targets */
 #define US_FL_FIX_INQUIRY     0x00000040 /* INQUIRY response needs fixing */
+#define US_FL_QUIRKS_TAG      0x00000080 /* the buggy device doesn't echo the tag
+                                             in the status response !*/
+
 
 #define USB_STOR_STRING_LEN 32

-- 
To unsubscribe, e-mail: packet-writing-unsubscribe@suse.com
For additional commands, e-mail: packet-writing-help@suse.com

[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic