,-- On Fri, 1/10/14, Hans Petter Selasky <h...@bitfrost.no> wrote:
,-- On 01/10/14 12:49, Alex Goncharov  wrote:
>> Maybe; but think about the fact correlations: the fact of the two
>> system's upgrade, two identical Seagate units, and  other HDDs being
>> non-stalled.
> 
> If you are running EHCI, there has been no changes in the USB stack,

Apparently, there have been; this is what causes the bogus error:

------------------------------------------------------------------------
r259454 | hselasky | 2013-12-16 03:51:58 -0500 (Mon, 16 Dec 2013) | 11 lines

MFC r244503 and r246565:

Make sure all USB drivers allocate buffer memory
through the USB API and/or busdma.

The following assumptions have been made:
umass - buffers passed from CAM/SCSI layer are OK
network - mbufs are OK.

Some other nits while at it.
------------------------------------------------------------------------

I am attaching the code difference for the two relevant files

----------------------------------------
M       sys/dev/usb/storage/ustorage_fs.c
M       sys/dev/usb/usb_msctest.c
----------------------------------------

in this change set, skipping the irrelevant 'sys/dev/usb/wlan' ones.

Can this be fixed reasonably soon, please? (I miss my HDDs :)

-- Alex
Index: sys/dev/usb/storage/ustorage_fs.c
===================================================================
--- sys/dev/usb/storage/ustorage_fs.c	(revision 259449)
+++ sys/dev/usb/storage/ustorage_fs.c	(revision 259494)
@@ -74,7 +74,7 @@
 /* Define some limits */
 
 #ifndef USTORAGE_FS_BULK_SIZE 
-#define	USTORAGE_FS_BULK_SIZE (1UL << 17)	/* bytes */
+#define	USTORAGE_FS_BULK_SIZE	(1U << 17)	/* bytes */
 #endif
 
 #ifndef	USTORAGE_FS_MAX_LUN
@@ -85,8 +85,6 @@
 #define	USTORAGE_QDATA_MAX	40	/* bytes */
 #endif
 
-#define sc_cmd_data sc_cbw.CBWCDB
-
 /*
  * The SCSI ID string must be exactly 28 characters long
  * exluding the terminating zero.
@@ -176,8 +174,9 @@
 
 struct ustorage_fs_softc {
 
-	ustorage_fs_bbb_cbw_t sc_cbw;	/* Command Wrapper Block */
-	ustorage_fs_bbb_csw_t sc_csw;	/* Command Status Block */
+	ustorage_fs_bbb_cbw_t *sc_cbw;	/* Command Wrapper Block */
+	ustorage_fs_bbb_csw_t *sc_csw;	/* Command Status Block */
+	void *sc_dma_ptr;		/* Main data buffer */
 
 	struct mtx sc_mtx;
 
@@ -275,7 +274,6 @@
 		.endpoint = UE_ADDR_ANY,
 		.direction = UE_DIR_OUT,
 		.bufsize = sizeof(ustorage_fs_bbb_cbw_t),
-		.flags = {.ext_buffer = 1,},
 		.callback = &ustorage_fs_t_bbb_command_callback,
 		.usb_mode = USB_MODE_DEVICE,
 	},
@@ -295,7 +293,7 @@
 		.endpoint = UE_ADDR_ANY,
 		.direction = UE_DIR_OUT,
 		.bufsize = USTORAGE_FS_BULK_SIZE,
-		.flags = {.proxy_buffer = 1,.short_xfer_ok = 1,.ext_buffer = 1},
+		.flags = {.proxy_buffer = 1,.short_xfer_ok = 1},
 		.callback = &ustorage_fs_t_bbb_data_read_callback,
 		.usb_mode = USB_MODE_DEVICE,
 	},
@@ -315,7 +313,7 @@
 		.endpoint = UE_ADDR_ANY,
 		.direction = UE_DIR_IN,
 		.bufsize = sizeof(ustorage_fs_bbb_csw_t),
-		.flags = {.short_xfer_ok = 1,.ext_buffer = 1,},
+		.flags = {.short_xfer_ok = 1},
 		.callback = &ustorage_fs_t_bbb_status_callback,
 		.usb_mode = USB_MODE_DEVICE,
 	},
@@ -409,6 +407,14 @@
 		    "transfers, %s\n", usbd_errstr(err));
 		goto detach;
 	}
+
+	sc->sc_cbw = usbd_xfer_get_frame_buffer(sc->sc_xfer[
+	    USTORAGE_FS_T_BBB_COMMAND], 0);
+	sc->sc_csw = usbd_xfer_get_frame_buffer(sc->sc_xfer[
+	    USTORAGE_FS_T_BBB_STATUS], 0);
+ 	sc->sc_dma_ptr = usbd_xfer_get_frame_buffer(sc->sc_xfer[
+	    USTORAGE_FS_T_BBB_DATA_READ], 0);
+
 	/* start Mass Storage State Machine */
 
 	mtx_lock(&sc->sc_mtx);
@@ -518,7 +524,7 @@
 	switch (USB_GET_STATE(xfer)) {
 	case USB_ST_TRANSFERRED:
 
-		tag = UGETDW(sc->sc_cbw.dCBWSignature);
+		tag = UGETDW(sc->sc_cbw->dCBWSignature);
 
 		if (tag != CBWSIGNATURE) {
 			/* do nothing */
@@ -525,29 +531,29 @@
 			DPRINTF("invalid signature 0x%08x\n", tag);
 			break;
 		}
-		tag = UGETDW(sc->sc_cbw.dCBWTag);
+		tag = UGETDW(sc->sc_cbw->dCBWTag);
 
 		/* echo back tag */
-		USETDW(sc->sc_csw.dCSWTag, tag);
+		USETDW(sc->sc_csw->dCSWTag, tag);
 
 		/* reset status */
-		sc->sc_csw.bCSWStatus = 0;
+		sc->sc_csw->bCSWStatus = 0;
 
 		/* reset data offset, data length and data remainder */
 		sc->sc_transfer.offset = 0;
 		sc->sc_transfer.data_rem =
-		    UGETDW(sc->sc_cbw.dCBWDataTransferLength);
+		    UGETDW(sc->sc_cbw->dCBWDataTransferLength);
 
 		/* reset data flags */
 		sc->sc_transfer.data_short = 0;
 
 		/* extract LUN */
-		sc->sc_transfer.lun = sc->sc_cbw.bCBWLUN;
+		sc->sc_transfer.lun = sc->sc_cbw->bCBWLUN;
 
 		if (sc->sc_transfer.data_rem == 0) {
 			sc->sc_transfer.cbw_dir = DIR_NONE;
 		} else {
-			if (sc->sc_cbw.bCBWFlags & CBWFLAGS_IN) {
+			if (sc->sc_cbw->bCBWFlags & CBWFLAGS_IN) {
 				sc->sc_transfer.cbw_dir = DIR_WRITE;
 			} else {
 				sc->sc_transfer.cbw_dir = DIR_READ;
@@ -554,8 +560,8 @@
 			}
 		}
 
-		sc->sc_transfer.cmd_len = sc->sc_cbw.bCDBLength;
-		if ((sc->sc_transfer.cmd_len > sizeof(sc->sc_cbw.CBWCDB)) ||
+		sc->sc_transfer.cmd_len = sc->sc_cbw->bCDBLength;
+		if ((sc->sc_transfer.cmd_len > sizeof(sc->sc_cbw->CBWCDB)) ||
 		    (sc->sc_transfer.cmd_len == 0)) {
 			/* just halt - this is invalid */
 			DPRINTF("invalid command length %d bytes\n",
@@ -597,9 +603,6 @@
 			usbd_xfer_set_stall(xfer);
 			DPRINTF("stall pipe\n");
 		}
-
-		usbd_xfer_set_frame_data(xfer, 0, &sc->sc_cbw,
-		    sizeof(sc->sc_cbw));
 		usbd_transfer_submit(xfer);
 		break;
 
@@ -616,9 +619,9 @@
 		goto tr_setup;
 	}
 	if (err) {
-		if (sc->sc_csw.bCSWStatus == 0) {
+		if (sc->sc_csw->bCSWStatus == 0) {
 			/* set some default error code */
-			sc->sc_csw.bCSWStatus = CSWSTATUS_FAILED;
+			sc->sc_csw->bCSWStatus = CSWSTATUS_FAILED;
 		}
 		if (sc->sc_transfer.cbw_dir == DIR_READ) {
 			/* dump all data */
@@ -699,6 +702,9 @@
 
 	switch (USB_GET_STATE(xfer)) {
 	case USB_ST_TRANSFERRED:
+		/* XXX copy data from DMA buffer */
+		memcpy(sc->sc_transfer.data_ptr, sc->sc_dma_ptr, actlen);
+
 		sc->sc_transfer.data_rem -= actlen;
 		sc->sc_transfer.data_ptr += actlen;
 		sc->sc_transfer.offset += actlen;
@@ -721,8 +727,7 @@
 			usbd_xfer_set_stall(xfer);
 		}
 
-		usbd_xfer_set_frame_data(xfer, 0, sc->sc_transfer.data_ptr,
-		    max_bulk);
+		usbd_xfer_set_frame_data(xfer, 0, sc->sc_dma_ptr, max_bulk);
 		usbd_transfer_submit(xfer);
 		break;
 
@@ -778,8 +783,10 @@
 			usbd_xfer_set_stall(xfer);
 		}
 
-		usbd_xfer_set_frame_data(xfer, 0, sc->sc_transfer.data_ptr,
-		    max_bulk);
+		/* XXX copy data to DMA buffer */
+		memcpy(sc->sc_dma_ptr, sc->sc_transfer.data_ptr, max_bulk);
+
+		usbd_xfer_set_frame_data(xfer, 0, sc->sc_dma_ptr, max_bulk);
 		usbd_transfer_submit(xfer);
 		break;
 
@@ -813,16 +820,13 @@
 
 	case USB_ST_SETUP:
 tr_setup:
-		USETDW(sc->sc_csw.dCSWSignature, CSWSIGNATURE);
-		USETDW(sc->sc_csw.dCSWDataResidue, sc->sc_transfer.data_rem);
+		USETDW(sc->sc_csw->dCSWSignature, CSWSIGNATURE);
+		USETDW(sc->sc_csw->dCSWDataResidue, sc->sc_transfer.data_rem);
 
 		if (sc->sc_transfer.data_error) {
 			sc->sc_transfer.data_error = 0;
 			usbd_xfer_set_stall(xfer);
 		}
-
-		usbd_xfer_set_frame_data(xfer, 0, &sc->sc_csw,
-		    sizeof(sc->sc_csw));
 		usbd_transfer_submit(xfer);
 		break;
 
@@ -934,17 +938,17 @@
 	/*
 	 * Get the starting Logical Block Address
 	 */
-	lba = get_be32(&sc->sc_cmd_data[2]);
+	lba = get_be32(&sc->sc_cbw->CBWCDB[2]);
 
 	/*
 	 * We allow DPO (Disable Page Out = don't save data in the cache)
 	 * but we don't implement it.
 	 */
-	if ((sc->sc_cmd_data[1] & ~0x10) != 0) {
+	if ((sc->sc_cbw->CBWCDB[1] & ~0x10) != 0) {
 		currlun->sense_data = SS_INVALID_FIELD_IN_CDB;
 		return (1);
 	}
-	vlen = get_be16(&sc->sc_cmd_data[7]);
+	vlen = get_be16(&sc->sc_cbw->CBWCDB[7]);
 	if (vlen == 0) {
 		goto done;
 	}
@@ -1092,8 +1096,8 @@
 {
 	uint8_t *buf = sc->sc_transfer.data_ptr;
 	struct ustorage_fs_lun *currlun = sc->sc_transfer.currlun;
-	uint32_t lba = get_be32(&sc->sc_cmd_data[2]);
-	uint8_t pmi = sc->sc_cmd_data[8];
+	uint32_t lba = get_be32(&sc->sc_cbw->CBWCDB[2]);
+	uint8_t pmi = sc->sc_cbw->CBWCDB[8];
 
 	/* Check the PMI and LBA fields */
 	if ((pmi > 1) || ((pmi == 0) && (lba != 0))) {
@@ -1126,7 +1130,7 @@
 	uint8_t *buf0;
 	uint16_t len;
 	uint16_t limit;
-	uint8_t mscmnd = sc->sc_cmd_data[0];
+	uint8_t mscmnd = sc->sc_cbw->CBWCDB[0];
 	uint8_t pc;
 	uint8_t page_code;
 	uint8_t changeable_values;
@@ -1134,13 +1138,13 @@
 
 	buf0 = buf;
 
-	if ((sc->sc_cmd_data[1] & ~0x08) != 0) {
+	if ((sc->sc_cbw->CBWCDB[1] & ~0x08) != 0) {
 		/* Mask away DBD */
 		currlun->sense_data = SS_INVALID_FIELD_IN_CDB;
 		return (1);
 	}
-	pc = sc->sc_cmd_data[2] >> 6;
-	page_code = sc->sc_cmd_data[2] & 0x3f;
+	pc = sc->sc_cbw->CBWCDB[2] >> 6;
+	page_code = sc->sc_cbw->CBWCDB[2] & 0x3f;
 	if (pc == 3) {
 		currlun->sense_data = SS_SAVING_PARAMETERS_NOT_SUPPORTED;
 		return (1);
@@ -1237,9 +1241,9 @@
 		currlun->sense_data = SS_INVALID_COMMAND;
 		return (1);
 	}
-	immed = sc->sc_cmd_data[1] & 0x01;
-	loej = sc->sc_cmd_data[4] & 0x02;
-	start = sc->sc_cmd_data[4] & 0x01;
+	immed = sc->sc_cbw->CBWCDB[1] & 0x01;
+	loej = sc->sc_cbw->CBWCDB[4] & 0x02;
+	start = sc->sc_cbw->CBWCDB[4] & 0x01;
 
 	if (immed || loej || start) {
 		/* compile fix */
@@ -1264,8 +1268,8 @@
 		currlun->sense_data = SS_INVALID_COMMAND;
 		return (1);
 	}
-	prevent = sc->sc_cmd_data[4] & 0x01;
-	if ((sc->sc_cmd_data[4] & ~0x01) != 0) {
+	prevent = sc->sc_cbw->CBWCDB[4] & 0x01;
+	if ((sc->sc_cbw->CBWCDB[4] & ~0x01) != 0) {
 		/* Mask away Prevent */
 		currlun->sense_data = SS_INVALID_FIELD_IN_CDB;
 		return (1);
@@ -1369,11 +1373,11 @@
 	 * Get the starting Logical Block Address and check that it's not
 	 * too big
 	 */
-	if (sc->sc_cmd_data[0] == SC_READ_6) {
-		lba = (((uint32_t)sc->sc_cmd_data[1]) << 16) |
-		    get_be16(&sc->sc_cmd_data[2]);
+	if (sc->sc_cbw->CBWCDB[0] == SC_READ_6) {
+		lba = (((uint32_t)sc->sc_cbw->CBWCDB[1]) << 16) |
+		    get_be16(&sc->sc_cbw->CBWCDB[2]);
 	} else {
-		lba = get_be32(&sc->sc_cmd_data[2]);
+		lba = get_be32(&sc->sc_cbw->CBWCDB[2]);
 
 		/*
 		 * We allow DPO (Disable Page Out = don't save data in the
@@ -1380,7 +1384,7 @@
 		 * cache) and FUA (Force Unit Access = don't read from the
 		 * cache), but we don't implement them.
 		 */
-		if ((sc->sc_cmd_data[1] & ~0x18) != 0) {
+		if ((sc->sc_cbw->CBWCDB[1] & ~0x18) != 0) {
 			currlun->sense_data = SS_INVALID_FIELD_IN_CDB;
 			return (1);
 		}
@@ -1427,11 +1431,11 @@
 	 * Get the starting Logical Block Address and check that it's not
 	 * too big.
 	 */
-	if (sc->sc_cmd_data[0] == SC_WRITE_6)
-		lba = (((uint32_t)sc->sc_cmd_data[1]) << 16) |
-		    get_be16(&sc->sc_cmd_data[2]);
+	if (sc->sc_cbw->CBWCDB[0] == SC_WRITE_6)
+		lba = (((uint32_t)sc->sc_cbw->CBWCDB[1]) << 16) |
+		    get_be16(&sc->sc_cbw->CBWCDB[2]);
 	else {
-		lba = get_be32(&sc->sc_cmd_data[2]);
+		lba = get_be32(&sc->sc_cbw->CBWCDB[2]);
 
 		/*
 		 * We allow DPO (Disable Page Out = don't save data in the
@@ -1439,11 +1443,11 @@
 		 * medium).  We don't implement DPO; we implement FUA by
 		 * performing synchronous output.
 		 */
-		if ((sc->sc_cmd_data[1] & ~0x18) != 0) {
+		if ((sc->sc_cbw->CBWCDB[1] & ~0x18) != 0) {
 			currlun->sense_data = SS_INVALID_FIELD_IN_CDB;
 			return (1);
 		}
-		if (sc->sc_cmd_data[1] & 0x08) {
+		if (sc->sc_cbw->CBWCDB[1] & 0x08) {
 			/* FUA */
 			/* XXX set SYNC flag here */
 		}
@@ -1483,7 +1487,7 @@
 			 * there must be something wrong about this SCSI
 			 * command
 			 */
-			sc->sc_csw.bCSWStatus = CSWSTATUS_PHASE;
+			sc->sc_csw->bCSWStatus = CSWSTATUS_PHASE;
 			return (1);
 		}
 		/* compute the minimum length */
@@ -1519,7 +1523,7 @@
     uint16_t mask, uint8_t needs_medium)
 {
 	struct ustorage_fs_lun *currlun;
-	uint8_t lun = (sc->sc_cmd_data[1] >> 5);
+	uint8_t lun = (sc->sc_cbw->CBWCDB[1] >> 5);
 	uint8_t i;
 
 	/* Verify the length of the command itself */
@@ -1526,11 +1530,11 @@
 	if (min_cmd_size > sc->sc_transfer.cmd_len) {
 		DPRINTF("%u > %u\n",
 		    min_cmd_size, sc->sc_transfer.cmd_len);
-		sc->sc_csw.bCSWStatus = CSWSTATUS_PHASE;
+		sc->sc_csw->bCSWStatus = CSWSTATUS_PHASE;
 		return (1);
 	}
 	/* Mask away the LUN */
-	sc->sc_cmd_data[1] &= 0x1f;
+	sc->sc_cbw->CBWCDB[1] &= 0x1f;
 
 	/* Check if LUN is correct */
 	if (lun != sc->sc_transfer.lun) {
@@ -1540,7 +1544,7 @@
 	if (sc->sc_transfer.lun <= sc->sc_last_lun) {
 		sc->sc_transfer.currlun = currlun =
 		    sc->sc_lun + sc->sc_transfer.lun;
-		if (sc->sc_cmd_data[0] != SC_REQUEST_SENSE) {
+		if (sc->sc_cbw->CBWCDB[0] != SC_REQUEST_SENSE) {
 			currlun->sense_data = SS_NO_SENSE;
 			currlun->sense_data_info = 0;
 			currlun->info_valid = 0;
@@ -1551,8 +1555,8 @@
 		 * else must fail!
 		 */
 		if ((currlun->unit_attention_data != SS_NO_SENSE) &&
-		    (sc->sc_cmd_data[0] != SC_INQUIRY) &&
-		    (sc->sc_cmd_data[0] != SC_REQUEST_SENSE)) {
+		    (sc->sc_cbw->CBWCDB[0] != SC_INQUIRY) &&
+		    (sc->sc_cbw->CBWCDB[0] != SC_REQUEST_SENSE)) {
 			currlun->sense_data = currlun->unit_attention_data;
 			currlun->unit_attention_data = SS_NO_SENSE;
 			return (1);
@@ -1564,8 +1568,8 @@
 		 * INQUIRY and REQUEST SENSE commands are explicitly allowed
 		 * to use unsupported LUNs; all others may not.
 		 */
-		if ((sc->sc_cmd_data[0] != SC_INQUIRY) &&
-		    (sc->sc_cmd_data[0] != SC_REQUEST_SENSE)) {
+		if ((sc->sc_cbw->CBWCDB[0] != SC_INQUIRY) &&
+		    (sc->sc_cbw->CBWCDB[0] != SC_REQUEST_SENSE)) {
 			return (1);
 		}
 	}
@@ -1575,7 +1579,7 @@
 	 * non-zero.
 	 */
 	for (i = 0; i != min_cmd_size; i++) {
-		if (sc->sc_cmd_data[i] && !(mask & (1UL << i))) {
+		if (sc->sc_cbw->CBWCDB[i] && !(mask & (1UL << i))) {
 			if (currlun) {
 				currlun->sense_data = SS_INVALID_FIELD_IN_CDB;
 			}
@@ -1613,12 +1617,12 @@
 	sc->sc_transfer.data_ptr = sc->sc_qdata;
 
 	DPRINTF("cmd_data[0]=0x%02x, data_rem=0x%08x\n",
-	    sc->sc_cmd_data[0], sc->sc_transfer.data_rem);
+	    sc->sc_cbw->CBWCDB[0], sc->sc_transfer.data_rem);
 
-	switch (sc->sc_cmd_data[0]) {
+	switch (sc->sc_cbw->CBWCDB[0]) {
 	case SC_INQUIRY:
 		sc->sc_transfer.cmd_dir = DIR_WRITE;
-		error = ustorage_fs_min_len(sc, sc->sc_cmd_data[4], -1U);
+		error = ustorage_fs_min_len(sc, sc->sc_cbw->CBWCDB[4], -1U);
 		if (error) {
 			break;
 		}
@@ -1633,7 +1637,7 @@
 
 	case SC_MODE_SELECT_6:
 		sc->sc_transfer.cmd_dir = DIR_READ;
-		error = ustorage_fs_min_len(sc, sc->sc_cmd_data[4], -1U);
+		error = ustorage_fs_min_len(sc, sc->sc_cbw->CBWCDB[4], -1U);
 		if (error) {
 			break;
 		}
@@ -1649,7 +1653,7 @@
 	case SC_MODE_SELECT_10:
 		sc->sc_transfer.cmd_dir = DIR_READ;
 		error = ustorage_fs_min_len(sc,
-		    get_be16(&sc->sc_cmd_data[7]), -1U);
+		    get_be16(&sc->sc_cbw->CBWCDB[7]), -1U);
 		if (error) {
 			break;
 		}
@@ -1664,7 +1668,7 @@
 
 	case SC_MODE_SENSE_6:
 		sc->sc_transfer.cmd_dir = DIR_WRITE;
-		error = ustorage_fs_min_len(sc, sc->sc_cmd_data[4], -1U);
+		error = ustorage_fs_min_len(sc, sc->sc_cbw->CBWCDB[4], -1U);
 		if (error) {
 			break;
 		}
@@ -1680,7 +1684,7 @@
 	case SC_MODE_SENSE_10:
 		sc->sc_transfer.cmd_dir = DIR_WRITE;
 		error = ustorage_fs_min_len(sc,
-		    get_be16(&sc->sc_cmd_data[7]), -1U);
+		    get_be16(&sc->sc_cbw->CBWCDB[7]), -1U);
 		if (error) {
 			break;
 		}
@@ -1708,7 +1712,7 @@
 		break;
 
 	case SC_READ_6:
-		i = sc->sc_cmd_data[4];
+		i = sc->sc_cbw->CBWCDB[4];
 		sc->sc_transfer.cmd_dir = DIR_WRITE;
 		temp = ((i == 0) ? 256UL : i);
 		error = ustorage_fs_min_len(sc, temp << 9, mask9);
@@ -1726,7 +1730,7 @@
 
 	case SC_READ_10:
 		sc->sc_transfer.cmd_dir = DIR_WRITE;
-		temp = get_be16(&sc->sc_cmd_data[7]);
+		temp = get_be16(&sc->sc_cbw->CBWCDB[7]);
 		error = ustorage_fs_min_len(sc, temp << 9, mask9);
 		if (error) {
 			break;
@@ -1742,10 +1746,10 @@
 
 	case SC_READ_12:
 		sc->sc_transfer.cmd_dir = DIR_WRITE;
-		temp = get_be32(&sc->sc_cmd_data[6]);
+		temp = get_be32(&sc->sc_cbw->CBWCDB[6]);
 		if (temp >= (1UL << (32 - 9))) {
 			/* numerical overflow */
-			sc->sc_csw.bCSWStatus = CSWSTATUS_FAILED;
+			sc->sc_csw->bCSWStatus = CSWSTATUS_FAILED;
 			error = 1;
 			break;
 		}
@@ -1776,7 +1780,7 @@
 	case SC_READ_FORMAT_CAPACITIES:
 		sc->sc_transfer.cmd_dir = DIR_WRITE;
 		error = ustorage_fs_min_len(sc,
-		    get_be16(&sc->sc_cmd_data[7]), -1U);
+		    get_be16(&sc->sc_cbw->CBWCDB[7]), -1U);
 		if (error) {
 			break;
 		}
@@ -1791,7 +1795,7 @@
 
 	case SC_REQUEST_SENSE:
 		sc->sc_transfer.cmd_dir = DIR_WRITE;
-		error = ustorage_fs_min_len(sc, sc->sc_cmd_data[4], -1U);
+		error = ustorage_fs_min_len(sc, sc->sc_cbw->CBWCDB[4], -1U);
 		if (error) {
 			break;
 		}
@@ -1860,7 +1864,7 @@
 		break;
 
 	case SC_WRITE_6:
-		i = sc->sc_cmd_data[4];
+		i = sc->sc_cbw->CBWCDB[4];
 		sc->sc_transfer.cmd_dir = DIR_READ;
 		temp = ((i == 0) ? 256UL : i);
 		error = ustorage_fs_min_len(sc, temp << 9, mask9);
@@ -1878,7 +1882,7 @@
 
 	case SC_WRITE_10:
 		sc->sc_transfer.cmd_dir = DIR_READ;
-		temp = get_be16(&sc->sc_cmd_data[7]);
+		temp = get_be16(&sc->sc_cbw->CBWCDB[7]);
 		error = ustorage_fs_min_len(sc, temp << 9, mask9);
 		if (error) {
 			break;
@@ -1894,10 +1898,10 @@
 
 	case SC_WRITE_12:
 		sc->sc_transfer.cmd_dir = DIR_READ;
-		temp = get_be32(&sc->sc_cmd_data[6]);
+		temp = get_be32(&sc->sc_cbw->CBWCDB[6]);
 		if (temp > (mask9 >> 9)) {
 			/* numerical overflow */
-			sc->sc_csw.bCSWStatus = CSWSTATUS_FAILED;
+			sc->sc_csw->bCSWStatus = CSWSTATUS_FAILED;
 			error = 1;
 			break;
 		}
Index: sys/dev/usb/usb_msctest.c
===================================================================
--- sys/dev/usb/usb_msctest.c	(revision 259449)
+++ sys/dev/usb/usb_msctest.c	(revision 259494)
@@ -139,8 +139,8 @@
 struct bbb_transfer {
 	struct mtx mtx;
 	struct cv cv;
-	struct bbb_cbw cbw;
-	struct bbb_csw csw;
+	struct bbb_cbw *cbw;
+	struct bbb_csw *csw;
 
 	struct usb_xfer *xfer[ST_MAX];
 
@@ -158,7 +158,7 @@
 	uint8_t	status_try;
 	int	error;
 
-	uint8_t	buffer[SCSI_MAX_LEN] __aligned(4);
+	uint8_t	*buffer;
 };
 
 static usb_callback_t bbb_command_callback;
@@ -184,7 +184,6 @@
 		.endpoint = UE_ADDR_ANY,
 		.direction = UE_DIR_OUT,
 		.bufsize = sizeof(struct bbb_cbw),
-		.flags = {.ext_buffer = 1,},
 		.callback = &bbb_command_callback,
 		.timeout = 4 * USB_MS_HZ,	/* 4 seconds */
 	},
@@ -193,8 +192,8 @@
 		.type = UE_BULK,
 		.endpoint = UE_ADDR_ANY,
 		.direction = UE_DIR_IN,
-		.bufsize = BULK_SIZE,
-		.flags = {.ext_buffer = 1,.proxy_buffer = 1,.short_xfer_ok = 1,},
+		.bufsize = MAX(SCSI_MAX_LEN, BULK_SIZE),
+		.flags = {.proxy_buffer = 1,.short_xfer_ok = 1,},
 		.callback = &bbb_data_read_callback,
 		.timeout = 4 * USB_MS_HZ,	/* 4 seconds */
 	},
@@ -232,7 +231,7 @@
 		.endpoint = UE_ADDR_ANY,
 		.direction = UE_DIR_IN,
 		.bufsize = sizeof(struct bbb_csw),
-		.flags = {.ext_buffer = 1,.short_xfer_ok = 1,},
+		.flags = {.short_xfer_ok = 1,},
 		.callback = &bbb_status_callback,
 		.timeout = 1 * USB_MS_HZ,	/* 1 second  */
 	},
@@ -241,7 +240,6 @@
 static void
 bbb_done(struct bbb_transfer *sc, int error)
 {
-
 	sc->error = error;
 	sc->state = ST_COMMAND;
 	sc->status_try = 1;
@@ -290,18 +288,17 @@
 
 	case USB_ST_SETUP:
 		sc->status_try = 0;
-		tag = UGETDW(sc->cbw.dCBWTag) + 1;
-		USETDW(sc->cbw.dCBWSignature, CBWSIGNATURE);
-		USETDW(sc->cbw.dCBWTag, tag);
-		USETDW(sc->cbw.dCBWDataTransferLength, (uint32_t)sc->data_len);
-		sc->cbw.bCBWFlags = ((sc->dir == DIR_IN) ? CBWFLAGS_IN : CBWFLAGS_OUT);
-		sc->cbw.bCBWLUN = sc->lun;
-		sc->cbw.bCDBLength = sc->cmd_len;
-		if (sc->cbw.bCDBLength > sizeof(sc->cbw.CBWCDB)) {
-			sc->cbw.bCDBLength = sizeof(sc->cbw.CBWCDB);
+		tag = UGETDW(sc->cbw->dCBWTag) + 1;
+		USETDW(sc->cbw->dCBWSignature, CBWSIGNATURE);
+		USETDW(sc->cbw->dCBWTag, tag);
+		USETDW(sc->cbw->dCBWDataTransferLength, (uint32_t)sc->data_len);
+		sc->cbw->bCBWFlags = ((sc->dir == DIR_IN) ? CBWFLAGS_IN : CBWFLAGS_OUT);
+		sc->cbw->bCBWLUN = sc->lun;
+		sc->cbw->bCDBLength = sc->cmd_len;
+		if (sc->cbw->bCDBLength > sizeof(sc->cbw->CBWCDB)) {
+			sc->cbw->bCDBLength = sizeof(sc->cbw->CBWCDB);
 			DPRINTFN(0, "Truncating long command\n");
 		}
-		usbd_xfer_set_frame_data(xfer, 0, &sc->cbw, sizeof(sc->cbw));
 		usbd_transfer_submit(xfer);
 		break;
 
@@ -430,9 +427,9 @@
 
 		/* very simple status check */
 
-		if (actlen < (int)sizeof(sc->csw)) {
+		if (actlen < (int)sizeof(struct bbb_csw)) {
 			bbb_done(sc, USB_ERR_SHORT_XFER);
-		} else if (sc->csw.bCSWStatus == CSWSTATUS_GOOD) {
+		} else if (sc->csw->bCSWStatus == CSWSTATUS_GOOD) {
 			bbb_done(sc, 0);	/* success */
 		} else {
 			bbb_done(sc, ERR_CSW_FAILED);	/* error */
@@ -440,7 +437,6 @@
 		break;
 
 	case USB_ST_SETUP:
-		usbd_xfer_set_frame_data(xfer, 0, &sc->csw, sizeof(sc->csw));
 		usbd_transfer_submit(xfer);
 		break;
 
@@ -478,9 +474,9 @@
 	sc->data_timeout = (data_timeout + USB_MS_HZ);
 	sc->actlen = 0;
 	sc->cmd_len = cmd_len;
-	memset(&sc->cbw.CBWCDB, 0, sizeof(sc->cbw.CBWCDB));
-	memcpy(&sc->cbw.CBWCDB, cmd_ptr, cmd_len);
-	DPRINTFN(1, "SCSI cmd = %*D\n", (int)cmd_len, (char *)sc->cbw.CBWCDB, ":");
+	memset(&sc->cbw->CBWCDB, 0, sizeof(sc->cbw->CBWCDB));
+	memcpy(&sc->cbw->CBWCDB, cmd_ptr, cmd_len);
+	DPRINTFN(1, "SCSI cmd = %*D\n", (int)cmd_len, (char *)sc->cbw->CBWCDB, ":");
 
 	mtx_lock(&sc->mtx);
 	usbd_transfer_start(sc->xfer[sc->state]);
@@ -549,6 +545,14 @@
 		bbb_detach(sc);
 		return (NULL);
 	}
+	/* store pointer to DMA buffers */
+	sc->buffer = usbd_xfer_get_frame_buffer(
+	    sc->xfer[ST_DATA_RD], 0);
+	sc->cbw = usbd_xfer_get_frame_buffer(
+	    sc->xfer[ST_COMMAND], 0);
+	sc->csw = usbd_xfer_get_frame_buffer(
+	    sc->xfer[ST_STATUS], 0);
+
 	return (sc);
 }
 
_______________________________________________
freebsd-usb@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-usb
To unsubscribe, send any mail to "freebsd-usb-unsubscr...@freebsd.org"

Reply via email to