Module Name:    src
Committed By:   drochner
Date:           Mon Aug 20 10:32:32 UTC 2012

Modified Files:
        src/sys/dev/usb: umass_scsipi.c

Log Message:
For devices which don't claim SPC-3, don't request 32 bytes of sense
data but just 18. Some devices signal an error if the transfer length
is not exactly what the device expects, and it is hard to deal with
these errors afterwards.
This makes a number of USB memory sticks and SD card readers work
which were not usable before.


To generate a diff of this commit:
cvs rdiff -u -r1.45 -r1.46 src/sys/dev/usb/umass_scsipi.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/dev/usb/umass_scsipi.c
diff -u src/sys/dev/usb/umass_scsipi.c:1.45 src/sys/dev/usb/umass_scsipi.c:1.46
--- src/sys/dev/usb/umass_scsipi.c:1.45	Fri Apr 20 20:23:21 2012
+++ src/sys/dev/usb/umass_scsipi.c	Mon Aug 20 10:32:31 2012
@@ -1,4 +1,4 @@
-/*	$NetBSD: umass_scsipi.c,v 1.45 2012/04/20 20:23:21 bouyer Exp $	*/
+/*	$NetBSD: umass_scsipi.c,v 1.46 2012/08/20 10:32:31 drochner Exp $	*/
 
 /*
  * Copyright (c) 2001, 2003, 2012 The NetBSD Foundation, Inc.
@@ -31,7 +31,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: umass_scsipi.c,v 1.45 2012/04/20 20:23:21 bouyer Exp $");
+__KERNEL_RCSID(0, "$NetBSD: umass_scsipi.c,v 1.46 2012/08/20 10:32:31 drochner Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_umass.h"
@@ -398,7 +398,7 @@ umass_scsipi_cb(struct umass_softc *sc, 
 	struct umass_scsipi_softc *scbus = (struct umass_scsipi_softc *)sc->bus;
 	struct scsipi_xfer *xs = priv;
 	struct scsipi_periph *periph = xs->xs_periph;
-	int cmdlen;
+	int cmdlen, senselen;
 	int s;
 #ifdef UMASS_DEBUG
 	struct timeval tv;
@@ -426,16 +426,20 @@ umass_scsipi_cb(struct umass_softc *sc, 
 		scbus->sc_sense_cmd.opcode = SCSI_REQUEST_SENSE;
 		scbus->sc_sense_cmd.byte2 = periph->periph_lun <<
 		    SCSI_CMD_LUN_SHIFT;
-		scbus->sc_sense_cmd.length = sizeof(xs->sense);
 
 		if (sc->sc_cmd == UMASS_CPROTO_UFI ||
 		    sc->sc_cmd == UMASS_CPROTO_ATAPI)
 			cmdlen = UFI_COMMAND_LENGTH;	/* XXX */
 		else
 			cmdlen = sizeof(scbus->sc_sense_cmd);
+		if (periph->periph_version < 0x05) /* SPC-3 */
+			senselen = 18;
+		else
+			senselen = sizeof(xs->sense);
+		scbus->sc_sense_cmd.length = senselen;
 		sc->sc_methods->wire_xfer(sc, periph->periph_lun,
 					  &scbus->sc_sense_cmd, cmdlen,
-					  &xs->sense, sizeof(xs->sense),
+					  &xs->sense, senselen,
 					  DIR_IN, xs->timeout, 0,
 					  umass_scsipi_sense_cb, xs);
 		return;

Reply via email to