[PATCH v2] USB: musb: Prevent Transmit Buffer Descriptor corruption

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



cppi_next_tx_segment is not checking for Transmit Buffer Descriptor ownership before modifying parameters.

Transmit Buffer Descriptor ram is shared between the host processor and the DMA. The "Ownership" bit is set by the host processor to give the DMA ownership of the Transmit Buffer Descriptor, and the bit is cleared by the DMA to return ownership to the host processor.

On USB Tx, when the system is heavily loaded, cppi_next_tx_segment can overwrite a Transmit Buffer Descriptor that is still owned by the DMA, causing DMA truncation error to fire, resulting in a channel abort. This proposed fix adds a check for host processor ownership of the bd and does not proceed to program it until the DMA has ended ownership.


Condition rarely occurs, so USB write speed is not negatively impacted.

Tested on DM365


Signed-off-by: Paul Stuart <paul_stuart@xxxxxxxxxxxx>

---

V2: Wrapped test in unlikely macro as this event _shouldn't_ occur often. Fixed formatting, per Sergei's advice.


--- a/drivers/usb/musb/cppi_dma.c	2010-12-06 20:09:04.000000000 -0800
+++ b/drivers/usb/musb/cppi_dma.c	2010-12-07 11:22:04.000000000 -0800
@@ -625,6 +625,14 @@ cppi_next_tx_segment(struct musb *musb, * size; for RNDIS there _is_ only that last packet.
	 */
	for (i = 0; i < n_bds; ) {
+
+		/* wait for DMA to release ownership of this bd */
+		if (unlikely(bd->hw_options & CPPI_OWN_SET)) {
+			do {
+				cpu_relax();
+			} while (bd->hw_options & CPPI_OWN_SET);
+		}
+		
		if (++i < n_bds && bd->next)
			bd->hw_next = bd->next->dma;
		else

--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[Index of Archives]     [Linux Media]     [Linux Input]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]     [Old Linux USB Devel Archive]

  Powered by Linux