GitLab has been upgraded to 13.3.6. If you encounter any issues mail code@riscosopen.org

Commit 7dd2c2bc authored by Jeffrey Lee's avatar Jeffrey Lee

Fix handling of short control transfers

Detail:
  c/musb - Updated musb_ep0_host() to treat a short control packet as the end of the transfer, as mandated by the USB spec. Also updated a few other pieces of code to ensure the transfer length is reported correctly if an error occurs.
  c/cmodule - Fix potential null pointer dereference when debugging enabled
  Makefile - Fix lack of DPRINTF() debug output in debug builds due to USB_DEBUG not being defined
Admin:
  Tested on BB-xM with high processor vectors
  Fixes 99% of connected devices failing to initialise following the change to the device initialisation logic made to USBDriver in NetBSD-0_82 (initial device descriptor requests now request more data than is likely to be available, triggering a short packet/xfer response)


Version 0.21. Tagged as 'MUSBDriver-0_21'
parent 6d64761f
......@@ -31,7 +31,7 @@ CUSTOMEXP = custom
#
DEBUG ?= FALSE
ifeq (${DEBUG},TRUE)
CFLAGS += -DDEBUGLIB -DMUSB_DEBUG
CFLAGS += -DDEBUGLIB -DMUSB_DEBUG -DUSB_DEBUG
CMHGDEFINES += -DMUSB_DEBUG
LIBS += ${DEBUGLIBS} ${NET5LIBS}
endif
......
/* (0.20)
/* (0.21)
*
* This file is automatically maintained by srccommit, do not edit manually.
* Last processed by srccommit version: 1.1.
*
*/
#define Module_MajorVersion_CMHG 0.20
#define Module_MajorVersion_CMHG 0.21
#define Module_MinorVersion_CMHG
#define Module_Date_CMHG 06 May 2014
#define Module_Date_CMHG 27 May 2014
#define Module_MajorVersion "0.20"
#define Module_Version 20
#define Module_MajorVersion "0.21"
#define Module_Version 21
#define Module_MinorVersion ""
#define Module_Date "06 May 2014"
#define Module_Date "27 May 2014"
#define Module_ApplicationDate "06-May-14"
#define Module_ApplicationDate "27-May-14"
#define Module_ComponentName "MUSBDriver"
#define Module_ComponentPath "mixed/RiscOS/Sources/HWSupport/USB/Controllers/MUSBDriver"
#define Module_FullVersion "0.20"
#define Module_HelpVersion "0.20 (06 May 2014)"
#define Module_LibraryVersionInfo "0:20"
#define Module_FullVersion "0.21"
#define Module_HelpVersion "0.21 (27 May 2014)"
#define Module_LibraryVersionInfo "0:21"
......@@ -221,7 +221,8 @@ _kernel_oserror* module_init (const char *cmd_tail, int podule_base, void *pw)
debug_set_unbuffered_files (TRUE);
#ifdef MUSB_DEBUG
musbdebug = atoi(getenv("musbdebug"));
const char *c = getenv("musbdebug");
musbdebug = (c?atoi(c):0);
// musbdebug = 11;
#endif
......
......@@ -604,6 +604,10 @@ static void musb_ep0_host(musb_softc_t *sc)
ex->xfer.status = USBD_STALLED;
else /* HOST_CSR0_ERROR */
ex->xfer.status = USBD_IOERROR;
/* Ensure we correctly report any partial transfer */
ex->xfer.actlen = ex->xfer.length-epipe->remain;
complete=1;
csro = 0;
updated=1;
......@@ -667,6 +671,17 @@ static void musb_ep0_host(musb_softc_t *sc)
epipe->buf = musb_fiforead(musb_base,0,epipe->buf,count);
CSR_CLEAR(HOST_CSR0_RXPKTRDY);
updated=1;
/* If it was a short packet (not max packet size) then we're done. */
usb_endpoint_descriptor_t *ed = epipe->pipe.endpoint->edesc;
if(count != UGETW(ed->wMaxPacketSize))
{
/* Transition to OUT_STATUS */
sc->host_ep0_state = HOST_EP0_STATE_OUT_STATUS;
CSR_SET(HOST_CSR0_STATUSPKT | HOST_CSR0_TXPKTRDY);
updated=1;
goto end;
}
}
}
/* Do we need more data? */
......@@ -725,7 +740,7 @@ static void musb_ep0_host(musb_softc_t *sc)
{
/* We're good! */
ex->xfer.status = USBD_NORMAL_COMPLETION;
ex->xfer.actlen = ex->xfer.length;
ex->xfer.actlen = ex->xfer.length-epipe->remain;
complete=1;
goto end;
}
......@@ -780,6 +795,10 @@ static void musb_receive_host(musb_softc_t *sc,int ep)
ex->xfer.status = USBD_STALLED;
else /* HOST_RXCSR_ERROR */
ex->xfer.status = USBD_IOERROR;
/* Ensure we correctly report any partial transfer */
ex->xfer.actlen = ex->xfer.length-epipe->remain;
complete=1;
csro = 0; /* Clear all of RXCSR so any offending flags (e.g. REQPKT) don't cause another error when the transfer fails for the second time */
updated=1;
......@@ -966,6 +985,10 @@ static void musb_transmit_host(musb_softc_t *sc,int ep)
ex->xfer.status = USBD_STALLED;
else /* HOST_TXCSR_ERROR */
ex->xfer.status = USBD_IOERROR;
/* Ensure we correctly report any partial transfer */
ex->xfer.actlen = ex->xfer.length-epipe->remain;
complete=1;
/* Abort by flushing the FIFO */
csro = csr | HOST_TXCSR_FLUSHFIFO;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment