usb: musb: gadget: fix dma length in txstate

DMA length should not go beyond the availabe space
of request buffer, so fix it.

Also set max_len of cppi dma channel as max size of
int type, so make musb dma handling happier.

Signed-off-by: Ming Lei <tom.leiming@gmail.com>
Cc: David Brownell <dbrownell@users.sourceforge.net>
Cc: Anand Gadiyar <gadiyar@ti.com>
Cc: Mike Frysinger <vapier@gentoo.org>
Cc: Sergei Shtylyov <sshtylyov@ru.mvista.com>
Signed-off-by: Felipe Balbi <balbi@ti.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
This commit is contained in:
Ming Lei 2010-09-20 10:32:06 +03:00 committed by Greg Kroah-Hartman
parent bb27bc2c11
commit 66af83ddf7
2 changed files with 10 additions and 9 deletions

View File

@ -322,6 +322,7 @@ cppi_channel_allocate(struct dma_controller *c,
index, transmit ? 'T' : 'R', cppi_ch); index, transmit ? 'T' : 'R', cppi_ch);
cppi_ch->hw_ep = ep; cppi_ch->hw_ep = ep;
cppi_ch->channel.status = MUSB_DMA_STATUS_FREE; cppi_ch->channel.status = MUSB_DMA_STATUS_FREE;
cppi_ch->channel.max_len = 0x7fffffff;
DBG(4, "Allocate CPPI%d %cX\n", index, transmit ? 'T' : 'R'); DBG(4, "Allocate CPPI%d %cX\n", index, transmit ? 'T' : 'R');
return &cppi_ch->channel; return &cppi_ch->channel;

View File

@ -300,6 +300,11 @@ static void txstate(struct musb *musb, struct musb_request *req)
#ifndef CONFIG_MUSB_PIO_ONLY #ifndef CONFIG_MUSB_PIO_ONLY
if (is_dma_capable() && musb_ep->dma) { if (is_dma_capable() && musb_ep->dma) {
struct dma_controller *c = musb->dma_controller; struct dma_controller *c = musb->dma_controller;
size_t request_size;
/* setup DMA, then program endpoint CSR */
request_size = min_t(size_t, request->length - request->actual,
musb_ep->dma->max_len);
use_dma = (request->dma != DMA_ADDR_INVALID); use_dma = (request->dma != DMA_ADDR_INVALID);
@ -307,11 +312,6 @@ static void txstate(struct musb *musb, struct musb_request *req)
#ifdef CONFIG_USB_INVENTRA_DMA #ifdef CONFIG_USB_INVENTRA_DMA
{ {
size_t request_size;
/* setup DMA, then program endpoint CSR */
request_size = min_t(size_t, request->length,
musb_ep->dma->max_len);
if (request_size < musb_ep->packet_sz) if (request_size < musb_ep->packet_sz)
musb_ep->dma->desired_mode = 0; musb_ep->dma->desired_mode = 0;
else else
@ -373,8 +373,8 @@ static void txstate(struct musb *musb, struct musb_request *req)
use_dma = use_dma && c->channel_program( use_dma = use_dma && c->channel_program(
musb_ep->dma, musb_ep->packet_sz, musb_ep->dma, musb_ep->packet_sz,
0, 0,
request->dma, request->dma + request->actual,
request->length); request_size);
if (!use_dma) { if (!use_dma) {
c->channel_release(musb_ep->dma); c->channel_release(musb_ep->dma);
musb_ep->dma = NULL; musb_ep->dma = NULL;
@ -386,8 +386,8 @@ static void txstate(struct musb *musb, struct musb_request *req)
use_dma = use_dma && c->channel_program( use_dma = use_dma && c->channel_program(
musb_ep->dma, musb_ep->packet_sz, musb_ep->dma, musb_ep->packet_sz,
request->zero, request->zero,
request->dma, request->dma + request->actual,
request->length); request_size);
#endif #endif
} }
#endif #endif