Hi, >-----Original Message----- >From: Sergei Shtylyov [mailto:sshtylyov@xxxxxxxxxx] >Sent: Tuesday, May 18, 2010 7:27 PM >To: Kalliguddi, Hema >Cc: linux-usb@xxxxxxxxxxxxxxx >Subject: Re: [PATCH V5] usb: musb: Unmapping the dma buffer >when switching to PIO mode > >Hello. > >Hema HK wrote: > >> 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 review comments and removed the unnecessary debug print. > >> 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,57 @@ >> >> /* >--------------------------------------------------------------- >-------- */ >> >> +/* 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 +170,11 @@ __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()) >> + if (ep->dma) { >> + unmap_dma_buffer(req, musb); >> + } > > This could be collapsed into single *if* statement, and {} are not >needed. Run your patches thru scripts/checkpatch.pl before submitting >please. Yes. I will do it. I am running scripts/checkpatch.pl before submitting and I am not finding any warnings or errors. > >> if (request->status == 0) >> DBG(5, "%s done request %p, %d/%d\n", >> ep->end_point.name, request, >> @@ -198,6 +236,7 @@ static void nuke(struct musb_ep *ep, con >> } >> } >> >> + >> /* >--------------------------------------------------------------- >-------- */ >> >> /* Data transfers - pure PIO, pure DMA, or mixed mode */ >> @@ -393,6 +432,14 @@ 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()) >> + if (musb_ep->dma) > > This could be collapsed into single *if* as well... > OK. >> + unmap_dma_buffer(req, musb); >> + >> musb_write_fifo(musb_ep->hw_ep, fifo_count, >> (u8 *) (request->buf + >request->actual)); >> request->actual += fifo_count; > >WBR, Sergei >-- 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