Bug 32490

Summary: umass support for ATAPI [with patch]
Product: Base System Reporter: larse <larse>
Component: miscAssignee: freebsd-bugs (Nobody) <bugs>
Status: Closed FIXED    
Severity: Affects Only Me    
Priority: Normal    
Version: 4.4-RELEASE   
Hardware: Any   
OS: Any   
Attachments:
Description Flags
smime.p7s none

Description larse 2001-12-04 05:30:00 UTC
This patch (against 4.4-STABLE) is a slight modification of the 6-to-10 conversion patch Gerd Knops posted to the usb-bsd list (http://groups.yahoo.com/group/usb-bsd/message/1233).

I've verified that it enables attaching, mounting and accessing a Pentax Optio 430 digital camera, which identifies itself as an ATAPI device.

Here is Gerd's description of the patch:
> The umass patch below against FreeBSD 4.3-BETA introduces on the fly
> conversion of 6 byte to 10 byte commands (read, write, mode select,
> mode sense). This should make many devices work that previously would
> have needed an explicit da_quirk_table entry in scsi_da.c.
> 
> I tested Sony Memory stick adapter (UTF) and Sony S70 (RBC), both work
> fine now without an entry in da_quirk_table, hence I removed those
> entries with the patch.
> 
> The patch should also bring us closer to support devices like
> USB-CDROMs. However when I tested I got 'Get Max Lun not supported
> (STALLED)', not sure what is causing this.

I'd be great if this could be committed.

Fix: 

533a534,538
> Static int
> umass_6_10_transform __P((struct umass_softc *sc,
> 			     unsigned char *cmd,
> 			     unsigned char **rcmd, int *rcmdlen));
> 
659c664
< #if 0
---
> #if 1
2635a2641,2648
>        /* These commands we can convert 'on the fly' to legal commands */
> 	case READ_6:
> 	case WRITE_6:
> 	case MODE_SELECT_6:
> 	case MODE_SENSE_6:
> 		umass_6_10_transform(sc, cmd, rcmd, rcmdlen);
> 		*rcmdlen = 10;
> 		return 1;               /* success */
2644a2658,2716
> Static int
> umass_6_10_transform(struct umass_softc *sc,
>     unsigned char *cmd,
>     unsigned char **rcmd, int *rcmdlen)
> {
> 	/*
> 	 * This function converts these 6 byte commands to
> 	 * their 10 byte equivalents:
> 	 *
> 	 * READ_6        -> READ_10
> 	 * WRITE_6       -> WRITE_10
> 	 * MODE_SELECT_6 -> MODE_SELECT_10
> 	 * MODE_SENSE_6  -> MODE_SENSE_10
> 	 *
> 	 * NOTE: rcmdlen is NOT modified! The calling code must set
> 	 * it as required for it's context.
> 	 */
> 	KASSERT(*rcmdlen >= 10,
> 	    ("rcmdlen = %d < 10, buffer too small in umass_6_10_transform",
> 		
> 		*rcmdlen));
> 	memset(*rcmd, 0, *rcmdlen);
> 	switch(cmd[0])
> 	    {
> 	    case READ_6:
> 	    case WRITE_6:
> 		    
> 		    if(cmd[0] == WRITE_6) {
> 			    (*rcmd)[0] = WRITE_10;
> 		    } else {
> 			    (*rcmd)[0] = READ_10;
> 		    }
> 		    (*rcmd)[3] = cmd[1];
> 		    (*rcmd)[4] = cmd[2];
> 		    (*rcmd)[5] = cmd[3];
> 		    (*rcmd)[8] = cmd[4];
> 		    (*rcmd)[9] = cmd[5];
> 		    return 1;               /* success */
> 	    case MODE_SELECT_6:
> 		    (*rcmd)[0] = MODE_SELECT_10;
> 		    (*rcmd)[1] = cmd[1];
> 		    (*rcmd)[8] = cmd[4];
> 		    (*rcmd)[9] = cmd[5];
> 		    return 1;               /* success */
> 	    case MODE_SENSE_6:
> 		    (*rcmd)[0] = MODE_SENSE_10;
> 		    (*rcmd)[1] = cmd[1];
> 		    (*rcmd)[2] = cmd[2];
> 		    (*rcmd)[8] = cmd[4];
> 		    (*rcmd)[9] = cmd[5];
> 		    return 1;               /* success */
> 	    }
> 	printf("%s: Unsupported command 0x%02x in umass_6_10_transform",
> 	    USBDEVNAME(sc->sc_dev), cmd[0]);
> 	printf("\n");
> 	return 0;       /* failure */
> }
> 
> 
2688a2761,2762
> 	case SYNCHRONIZE_CACHE:         /* Tested with Sony memory
> 					 * stick adapter */
2693,2701c2767
< 	/* Other UFI commands: FORMAT_UNIT, MODE_SELECT, READ_FORMAT_CAPACITY,
< 	 * VERIFY, WRITE_AND_VERIFY.
< 	 * These should be checked whether they somehow can be made to fit.
< 	 */
< 
< 	/* These commands are known _not_ to work. They should be converted
< 	 * The 6 byte commands can be switched off with a CAM quirk. See
< 	 * the entry for the Y-E data drive.
< 	 */
---
> 	/* 6-bytes commands are converted on the fly */
2705a2772,2776
> 		/* convert on the fly */
> 		umass_6_10_transform(sc, cmd, rcmd, rcmdlen);
> 		return 1;               /* success */
> 		
> 	/* These commands are known _not_ to work. */
2707a2779,2782
> 	/* Other UFI commands: FORMAT_UNIT, MODE_SELECT,
>          * READ_FORMAT_CAPACITY, VERIFY, WRITE_AND_VERIFY. These
>          * should be checked whether they somehow can be made to fit.
>          */
2752,2755c2827
< 	/* These commands are known _not_ to work. They should be converted
< 	 * The 6 byte commands can be switched off with a CAM quirk. See
< 	 * the entry for the Y-E data drive.
< 	 */
---
> 	/* 6-bytes commands are converted on the fly */
2759a2832,2834
> 		umass_6_10_transform(sc, cmd, rcmd, rcmdlen);
> 		return 1;               /* success */
>        /* These commands are known _not_ to work */
Comment 1 Dag-Erling Smørgrav freebsd_committer freebsd_triage 2001-12-04 12:18:26 UTC
Responsible Changed
From-To: freebsd-bugs->sos

Over to Mr ATA.
Comment 2 Søren Schmidt freebsd_committer freebsd_triage 2001-12-04 12:28:14 UTC
Responsible Changed
From-To: sos->freebsd-bugs

This is not an ATA driver matter, its USB..
Comment 3 larse 2001-12-14 01:17:25 UTC
This is an ALTERNATIVE patch that just adds the required quirks to 
scsi_da.c, in case that's preferred. Either this or the original patch 
work for me.

Lars

--- /usr/src/sys/cam/scsi/scsi_da.c     Sun Jul 29 17:48:20 2001
+++ /usr/src/sys/cam/scsi/scsi_da.c     Mon Dec  3 14:52:55 2001
@@ -246,6 +246,14 @@
                 /*quirks*/ DA_Q_NO_6_BYTE|DA_Q_NO_SYNC_CACHE
         },
         {
+               /*
+                * Pentax Optio 430 Digital Camera
+                * (will probably also work for the Optio 330)
+                */
+               {T_DIRECT, SIP_MEDIA_REMOVABLE, "PENTAX", 
"DIGITAL_CAMERA", "*"},
+               /*quirks*/ DA_Q_NO_6_BYTE|DA_Q_NO_SYNC_CACHE
+       },
+       {
                 {T_OPTICAL, SIP_MEDIA_REMOVABLE, "FUJITSU", 
"MCF3064AP", "*"},
                 /*quirks*/ DA_Q_NO_6_BYTE
         }
--- /usr/src/sys/dev/usb/umass.c        Sat Jan  6 14:36:15 2001
+++ /usr/src/sys/dev/usb/umass.c        Mon Dec  3 14:47:47 2001
@@ -575,7 +575,7 @@

         dd = usbd_get_device_descriptor(udev);

-#if 0
+#if 1
         /* XXX ATAPI support is untested. Don't use it for the moment */
         if (UGETW(dd->idVendor) == USB_VENDOR_SHUTTLE
             && UGETW(dd->idProduct) == USB_PRODUCT_SHUTTLE_EUSB) {
@@ -656,7 +656,7 @@
                 break;
         case USUBCLASS_SFF8020I:
         case USUBCLASS_SFF8070I:
-#if 0
+#if 1
                 /* XXX ATAPI support is untested. Don't use it for the 
moment */
                 sc->proto |= PROTO_ATAPI;
                 break;

-- 
Lars Eggert <larse@isi.edu>               Information Sciences Institute
http://www.isi.edu/larse/              University of Southern California
Comment 4 larse 2002-02-05 00:28:43 UTC
Now that 4.5 is out, maybe this could be committed?

Thanks,
Lars
-- 
Lars Eggert <larse@isi.edu>               Information Sciences Institute
http://www.isi.edu/larse/              University of Southern California
Comment 5 Nick Hibma freebsd_committer freebsd_triage 2002-04-10 21:31:50 UTC
State Changed
From-To: open->closed

This patch has been superseded by an implementation by jhb which has 
been committed to current. 

Thanks for the patch though!