RE: [PATCH v6 1/2] usb: musb: Unmapping the dma buffer when switching to PIO mode

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

 



Hi,

Any comments for the below patch?

Regards,
Hema

>-----Original Message-----
>From: Kalliguddi, Hema 
>Sent: Wednesday, May 19, 2010 2:52 PM
>To: linux-usb@xxxxxxxxxxxxxxx
>Cc: Kalliguddi, Hema
>Subject: [PATCH v6 1/2] usb: musb: Unmapping the dma buffer 
>when switching to PIO mode
>
>From: Hema HK  <hemahk@xxxxxx>
>
>Buffer is mapped to dma when dma channel is allocated. buffer needs
>to be unmapped when fallback to PIO mode if dma channel_program 
>fails. 
>
>Signed-off-by: Hema HK <hemahk@xxxxxx>
>---
>Based off  V2.6.34 + gregkh-07-usb-2.6.34.patch
> 
>Addressed some more review comments from Ajay and Sergei.
>
>Index: linux-2.6/drivers/usb/musb/musb_gadget.c
>===================================================================
>--- linux-2.6.orig/drivers/usb/musb/musb_gadget.c
>+++ linux-2.6/drivers/usb/musb/musb_gadget.c
>@@ -92,6 +92,56 @@
> 
> /* 
>---------------------------------------------------------------
>-------- */
> 
>+/* Maps the buffer to dma  */
>+
>+static inline void map_dma_buffer(struct musb_request *request,
>+				struct musb *musb)
>+{
>+	if (request->request.dma == DMA_ADDR_INVALID) {
>+		request->request.dma = dma_map_single(
>+				musb->controller,
>+				request->request.buf,
>+				request->request.length,
>+				request->tx
>+					? DMA_TO_DEVICE
>+					: DMA_FROM_DEVICE);
>+		request->mapped = 1;
>+	} else {
>+		dma_sync_single_for_device(musb->controller,
>+			request->request.dma,
>+			request->request.length,
>+			request->tx
>+				? DMA_TO_DEVICE
>+				: DMA_FROM_DEVICE);
>+		request->mapped = 0;
>+	}
>+}
>+
>+
>+/* Unmap the buffer from dma and maps it back to cpu */
>+static inline void unmap_dma_buffer(struct musb_request *request,
>+				struct musb *musb)
>+{
>+	if (request->mapped) {
>+		dma_unmap_single(musb->controller,
>+			request->request.dma,
>+			request->request.length,
>+			request->tx
>+				? DMA_TO_DEVICE
>+				: DMA_FROM_DEVICE);
>+		request->request.dma = DMA_ADDR_INVALID;
>+		request->mapped = 0;
>+	} else {
>+		dma_sync_single_for_cpu(musb->controller,
>+			request->request.dma,
>+			request->request.length,
>+			request->tx
>+				? DMA_TO_DEVICE
>+				: DMA_FROM_DEVICE);
>+
>+	}
>+}
>+
> /*
>  * Immediately complete a request.
>  *
>@@ -119,24 +169,8 @@ __acquires(ep->musb->lock)
> 
> 	ep->busy = 1;
> 	spin_unlock(&musb->lock);
>-	if (is_dma_capable()) {
>-		if (req->mapped) {
>-			dma_unmap_single(musb->controller,
>-					req->request.dma,
>-					req->request.length,
>-					req->tx
>-						? DMA_TO_DEVICE
>-						: DMA_FROM_DEVICE);
>-			req->request.dma = DMA_ADDR_INVALID;
>-			req->mapped = 0;
>-		} else if (req->request.dma != DMA_ADDR_INVALID)
>-			dma_sync_single_for_cpu(musb->controller,
>-					req->request.dma,
>-					req->request.length,
>-					req->tx
>-						? DMA_TO_DEVICE
>-						: DMA_FROM_DEVICE);
>-	}
>+	if (is_dma_capable() && ep->dma)
>+		unmap_dma_buffer(req, musb);
> 	if (request->status == 0)
> 		DBG(5, "%s done request %p,  %d/%d\n",
> 				ep->end_point.name, request,
>@@ -393,6 +427,13 @@ static void txstate(struct musb *musb, s
> #endif
> 
> 	if (!use_dma) {
>+		/*
>+		 * Unmap the dma buffer back to cpu if dma channel
>+		 * programming fails
>+		 */
>+		if (is_dma_capable() && musb_ep->dma)
>+			unmap_dma_buffer(req, musb);
>+
> 		musb_write_fifo(musb_ep->hw_ep, fifo_count,
> 				(u8 *) (request->buf + 
>request->actual));
> 		request->actual += fifo_count;
>@@ -711,6 +752,13 @@ static void rxstate(struct musb *musb, s
> 					return;
> 			}
> #endif
>+			/*
>+			 * Unmap the dma buffer back to cpu if 
>dma channel
>+			 * programming fails. This buffer is 
>mapped if the
>+			 * channel allocation is successful
>+			 */
>+			if (is_dma_capable())
>+				unmap_dma_buffer(req, musb);
> 
> 			musb_read_fifo(musb_ep->hw_ep, 
>fifo_count, (u8 *)
> 					(request->buf + 
>request->actual));
>@@ -1125,28 +1173,11 @@ static int musb_gadget_queue(struct usb_
> 	request->epnum = musb_ep->current_epnum;
> 	request->tx = musb_ep->is_in;
> 
>-	if (is_dma_capable() && musb_ep->dma) {
>-		if (request->request.dma == DMA_ADDR_INVALID) {
>-			request->request.dma = dma_map_single(
>-					musb->controller,
>-					request->request.buf,
>-					request->request.length,
>-					request->tx
>-						? DMA_TO_DEVICE
>-						: DMA_FROM_DEVICE);
>-			request->mapped = 1;
>-		} else {
>-			dma_sync_single_for_device(musb->controller,
>-					request->request.dma,
>-					request->request.length,
>-					request->tx
>-						? DMA_TO_DEVICE
>-						: DMA_FROM_DEVICE);
>-			request->mapped = 0;
>-		}
>-	} else if (!req->buf) {
>+	if (is_dma_capable() && musb_ep->dma)
>+		map_dma_buffer(request, musb);
>+	else if (!req->buf) 
> 		return -ENODATA;
>-	} else
>+	else
> 		request->mapped = 0;
> 
> 	spin_lock_irqsave(&musb->lock, lockflags);
>--
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