[PATCH] Driver for Toshiba DVD-RAM (SCSI) (kernel 2.2.11)

Reed Meyer (rdm@astro.yale.edu)
Fri, 27 Aug 1999 22:17:37 -0400 (EDT)


Hi all,
Included below is an excerpt from a message I posted on
comp.os.linux.development.system on Aug. 12. It's a patch for
the Toshiba DVD-RAM drive (model SD-W1101; SD-W1111 also
theoretically supported but untested). I modified the patch
from the original one which was for kernel 2.0.36; while I did
test the patch on 2.0.36, I didn't verify it on 2.2.11 because we
don't have 2.2.11 installed here yet. However, it *SHOULD* work
on 2.2.11 because the patch is pretty small and it shouldn't affect
any lines of code that changed between 2.0.36 and 2.2.11.
It has only been verified using the Tekram DC-390 SCSI
controller. However, I believe it should be OK with other
controllers.
Finally, as is noted in the comment lines added to sd.c, the patch
works by changing the default SCSI read/write commands (for SCSI disks)
from 6-byte to 10-byte commands. The SCSI driver (sd.c) only goes to
6-byte commands if the device doesn't like 10-byte ones. In other words,
no advantage is gained (if any exists?) in using 6-byte commands whenever
6-bytes are possible. I honestly don't know if there is any advantage to
using 6-bytes over 10-bytes (do 6-bytes execute faster?), but if there
really is a significant advantage, then maybe this approach isn't great.
Three files follow. The first is a quick-and-dirty pseudo-batch file
which gives instructions for applying the patch. The second is the
patch to sd.c. The third is the patch to scsi.c.

Could you please CC: me any response you have, as I don't subscribe
to this list. Thanks to TechRat for telling me how to post this
patch here. The scsi.c patch is hacked from a Panasonic DVD-RAM patch
sitting at www.jaist.ac.jp/~sight95/linux/dvd-ram/dvd-ram-english.html.

Thanks,
---Reed Meyer
rdm@astro.yale.edu

=============================================================================
File #1: Instructions for patching kernel 2.2.11 for Toshiba DVD-RAM.
=============================================================================

# Patch instructions for Toshiba DVD-RAM / Linux kernel 2.2.11.
# Reed D. Meyer, rdm@astro.yale.edu, 8/12/99. Hacked from
# instructions by sight95@jaist.ac.jp (found at:
# www.jaist.ac.jp/~sight95/linux/dvd-ram/dvd-ram-english.html)
#
# *NOT* tested on kernel 2.2.11. Hacked from a patch for 2.0.36.
# Patch was confirmed *ONLY* for the Tekram DC-390 SCSI controller card!
# Some other I/Fs may not work successfully, and then you need to make some
# changes in the correspond driver to your I/F of the kernel source.

su
cd /usr/src/linux/drivers/scsi
patch -p0 < $DVDRAM/sd.c.patch-2.2.11-toshiba
patch -p0 < $DVDRAM/scsi.c.patch-2.2.11-toshiba
cd /usr/src/linux
make menuconfig
# Check "Support SCSI" to Y or M.
make dep; make clean; make bzImage; make modules; make modules_install
# Do the following only if you're sure you want to copy the new
# vmlinuz + modules to the standard area.
mv System.map /boot
mv arch/i386/boot/bzImage /boot/vmlinuz
# Regenerate the master boot record (re-run the LILO configuration)
# (Make sure to edit /etc/lilo.conf as necessary!)
/sbin/lilo
# Reboot your Linux system.
# Make a partition using "fdisk".
# Make sure that the head sector number of each partition is a multiple of 4
# if there's more than one partition (the logical sector size is 512 bytes but
# the physical block size is 2048 so there'd be problems otherwise).
fdisk /dev/sda
n (make new partition)
p (primary)
1 (select 1 at primary)
1 (start cylinder)
303 (last cylinder: if only make 1 partition.)
w (write & quit)
# Then, format. Note the -b 2048 option to mke2fs! Also, note that
# we use /dev/sda, *NOT* /dev/sda1!
# (If making an MSDOS partition is desired, you might want to try
# passing the option "-s 32" to mkdosfs.)
mke2fs -c -b 2048 /dev/sda
# Make a mount point.
mkdir /dvdram
# Now, you test mount.
mount /dev/sda /dvdram
# (After the test you may modify /etc/fstab. General user can mount using
# the command "mount /dvdram".)
vi /etc/fstab
# Add line:
/dev/sda /dvdram ext2 user,noauto,rw,suid,exec 0 0

=============================================================================
File #2: sd.c.patch-2.2.11-toshiba
=============================================================================

--- sd.c.original Mon Aug 9 15:05:05 1999
+++ sd.c Thu Aug 12 20:12:37 1999
@@ -17,6 +17,15 @@
*
* Modified by Jirka Hanika geo@ff.cuni.cz to support more
* scsi disks using eight major numbers.
+ *
+ * Modified by Reed Meyer <rdm@astro.yale.edu> to support the Toshiba
+ * SD-W1101 DVD-RAM (which doesn't like 6-byte commands). Changed the
+ * default I/O to 10-byte commands, with the minor side-effect that
+ * the driver doesn't use the slightly-faster(?) 6-byte commands
+ * when circumstances allow. I did this so I wouldn't have to write
+ * code specific to the Toshiba DVD-RAM. If you don't like this
+ * approach, flame me. I have no idea whether it makes a substantial
+ * speed improvement by sticking to 6-byte commands.
*/

#include <linux/module.h>
@@ -734,10 +743,10 @@
SCpnt = end_scsi_request(SCpnt, 0, SCpnt->request.nr_sectors);
goto repeat;
}
- cmd[0] = WRITE_6;
+ cmd[0] = WRITE_10;
break;
case READ :
- cmd[0] = READ_6;
+ cmd[0] = READ_10;
break;
default :
panic ("Unknown sd command %d\n", SCpnt->request.cmd);
@@ -1016,12 +1025,11 @@
this_count = this_count << 1;
}

- if (((this_count > 0xff) || (block > 0x1fffff)) && rscsi_disks[dev].ten)
+ if (rscsi_disks[dev].ten) /* Can handle ten-byte commands */
{
if (this_count > 0xffff)
this_count = 0xffff;

- cmd[0] += READ_10 - READ_6 ;
cmd[2] = (unsigned char) (block >> 24) & 0xff;
cmd[3] = (unsigned char) (block >> 16) & 0xff;
cmd[4] = (unsigned char) (block >> 8) & 0xff;
@@ -1030,11 +1038,12 @@
cmd[7] = (unsigned char) (this_count >> 8) & 0xff;
cmd[8] = (unsigned char) this_count & 0xff;
}
- else
+ else /* Can't handle ten-byte commands */
{
if (this_count > 0xff)
this_count = 0xff;

+ cmd[0] -= READ_10 - READ_6 ;
cmd[1] |= (unsigned char) ((block >> 16) & 0x1f);
cmd[2] = (unsigned char) ((block >> 8) & 0xff);
cmd[3] = (unsigned char) block & 0xff;

=============================================================================
File #3: scsi.c.patch-2.2.11-toshiba
=============================================================================

--- scsi.c.original Mon Aug 9 15:04:40 1999
+++ scsi.c Thu Aug 12 20:31:58 1999
@@ -654,6 +654,8 @@
struct Scsi_Device_Template *sdtpnt;
Scsi_Device * SDtail, *SDpnt=*SDpnt2;
int bflags, type=-1;
+ static int TOSH_DVD_RAM[2] = {-1,-1};
+ int org_lun = lun;

SDpnt->host = shpnt;
SDpnt->id = dev;
@@ -661,6 +663,16 @@
SDpnt->channel = channel;
SDpnt->online = TRUE;

+ /* Toshiba SD-W1101/SD-W1111 DVD-RAM adapted from the Panasonic model */
+ if (TOSH_DVD_RAM[0] == channel && TOSH_DVD_RAM[1] == dev && lun == 1) {
+ /* get CD-ROM type */
+ SDpnt->lun = lun = 0;
+ } else {
+ /* clear status */
+ TOSH_DVD_RAM[0] = -1;
+ TOSH_DVD_RAM[1] = -1;
+ }
+
/* Some low level driver could use device->type (DB) */
SDpnt->type = -1;

@@ -773,6 +785,22 @@
scsi_result[1] |= 0x80; /* removable */
}

+ if (!strncmp (scsi_result + 8, "TOSHIBA", 7) &&
+ (!strncmp (scsi_result + 16, "SD-W1101", 8) ||
+ !strncmp (scsi_result + 16, "SD-W1111", 8)) &&
+ scsi_result[0] == TYPE_ROM) {
+ if (TOSH_DVD_RAM[0] == channel && TOSH_DVD_RAM[1] == dev && org_lun == 1)
{
+ /* Toshiba SD-W1101/SD-W1111 DVD-RAM treats as ROM */
+ lun = 1;
+ } else {
+ /* Toshiba SD-W1101/SD-W1111 DVD-RAM treats as MOD */
+ scsi_result[0] = TYPE_MOD;
+ scsi_result[1] |= 0x80; /* removable */
+ TOSH_DVD_RAM[0] = channel;
+ TOSH_DVD_RAM[1] = dev;
+ }
+ }
+
memcpy (SDpnt->vendor, scsi_result + 8, 8);
memcpy (SDpnt->model, scsi_result + 16, 16);
memcpy (SDpnt->rev, scsi_result + 32, 4);
@@ -969,6 +997,12 @@
*/
if (bflags & BLIST_MAX5LUN) {
*max_dev_lun = 5;
+ return 1;
+ }
+
+ /* Toshiba SD-W1101/SD-W1111 DVD-RAM */
+ if (TOSH_DVD_RAM[0] == channel && TOSH_DVD_RAM[1] == dev && org_lun == 1) {
+ *max_dev_lun = 2;
return 1;
}

=============================================================================
END OF FILES
=============================================================================

-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.rutgers.edu
Please read the FAQ at http://www.tux.org/lkml/