ChangeSet 1.1338, 2003/10/09 10:26:58-07:00, david-b@pacbell.net [PATCH] USB: minor net2280 cleanup This holds minor net2280 cleanups: - Cleaner handling for cases where dma_alloc_coherent() must be used instead of kmalloc(). (Kmalloc is more memory-efficient for the "small buffers" case.) Both MIPS cases should work, as well as others. - Prefetch cachelines on PIO paths. The first of those gets rid of one usage, no longer useful now that 2.4 and 2.6 versions have forked. drivers/usb/gadget/net2280.c | 47 +++++++++++++++++++++---------------------- 1 files changed, 24 insertions(+), 23 deletions(-) diff -Nru a/drivers/usb/gadget/net2280.c b/drivers/usb/gadget/net2280.c --- a/drivers/usb/gadget/net2280.c Fri Oct 10 16:02:56 2003 +++ b/drivers/usb/gadget/net2280.c Fri Oct 10 16:02:56 2003 @@ -50,7 +50,6 @@ #define DEBUG 1 // #define VERBOSE /* extra debug messages (success too) */ -#include #include #include #include @@ -431,6 +430,9 @@ #elif defined(CONFIG_PPC) && !defined(CONFIG_NOT_COHERENT_CACHE) #define USE_KMALLOC +#elif defined(CONFIG_MIPS) && !defined(CONFIG_NONCOHERENT_IO) +#define USE_KMALLOC + /* FIXME there are other cases, including an x86-64 one ... */ #endif @@ -452,31 +454,23 @@ ep = container_of (_ep, struct net2280_ep, ep); if (!_ep) return 0; - *dma = DMA_ADDR_INVALID; - if (ep->dma) { -#if defined(USE_KMALLOC) - retval = kmalloc (bytes, gfp_flags); - if (retval) - *dma = virt_to_phys (retval); -#elif LINUX_VERSION_CODE > KERNEL_VERSION(2,5,58) -#warning Using dma_alloc_consistent even with sub-page allocations +#if defined(USE_KMALLOC) + retval = kmalloc(bytes, gfp_flags); + if (retval) + *dma = virt_to_phys(retval); +#else + if (ep->dma) { /* the main problem with this call is that it wastes memory * on typical 1/N page allocations: it allocates 1-N pages. */ - retval = dma_alloc_coherent (&ep->dev->pdev->dev, +#warning Using dma_alloc_coherent even with buffers smaller than a page. + retval = dma_alloc_coherent(&ep->dev->pdev->dev, bytes, dma, gfp_flags); -#else -#error No dma-coherent memory allocator is available - /* pci_alloc_consistent works, but pci_free_consistent() - * isn't safe in_interrupt(). plus, in addition to the - * 1/Nth page weakness, it doesn't understand gfp_flags. - */ -#endif } else - retval = kmalloc (bytes, gfp_flags); - + retval = kmalloc(bytes, gfp_flags); +#endif return retval; } @@ -489,9 +483,14 @@ ) { /* free memory into the right allocator */ #ifndef USE_KMALLOC - if (dma != DMA_ADDR_INVALID) - dma_free_coherent (ep->dev->pdev, bytes, dma); - else + if (dma != DMA_ADDR_INVALID) { + struct net2280_ep *ep; + + ep = container_of(_ep, struct net2280_ep, ep); + if (!_ep) + return; + dma_free_coherent(&ep->dev->pdev->dev, bytes, buf, dma); + } else #endif kfree (buf); } @@ -516,8 +515,9 @@ /* INVARIANT: fifo is currently empty. (testable) */ if (req) { - total = req->length - req->actual; buf = req->buf + req->actual; + prefetch (buf); + total = req->length - req->actual; } else { total = 0; buf = 0; @@ -615,6 +615,7 @@ /* never overflow the rx buffer. the fifo reads packets until * it sees a short one; we might not be ready for them all. */ + prefetchw (buf); count = readl (®s->ep_avail); tmp = req->req.length - req->req.actual; if (count > tmp) {