The prepared memory for the qhead needs to be contiguos and 2K aligned. We change the code from allocating extra buffer for every ep qhead to one big area. This patch lowers the amount of code to prepare the memory. Signed-off-by: Michael Grzeschik <m.grzeschik@xxxxxxxxxxxxxx> --- drivers/usb/chipidea/ci.h | 9 +++++++-- drivers/usb/chipidea/udc.c | 31 ++++++++++++++----------------- drivers/usb/chipidea/udc.h | 2 +- 3 files changed, 22 insertions(+), 20 deletions(-) diff --git a/drivers/usb/chipidea/ci.h b/drivers/usb/chipidea/ci.h index e25d126..12eca83 100644 --- a/drivers/usb/chipidea/ci.h +++ b/drivers/usb/chipidea/ci.h @@ -110,7 +110,7 @@ struct hw_bank { * @is_otg: if the device is otg-capable * @work: work for role changing * @wq: workqueue thread - * @qh_pool: allocation pool for queue heads + * @qh: allocation struct for queue heads * @td_pool: allocation pool for transfer descriptors * @gadget: device side representation for peripheral controller * @driver: gadget driver @@ -142,7 +142,12 @@ struct ci13xxx { struct work_struct vbus_work; struct workqueue_struct *wq; - struct dma_pool *qh_pool; + struct { + struct ci13xxx_qh *ptr; + dma_addr_t dma; + size_t size; + } qh; + struct dma_pool *td_pool; struct usb_gadget gadget; diff --git a/drivers/usb/chipidea/udc.c b/drivers/usb/chipidea/udc.c index a0a0a64..c9f0a1a 100644 --- a/drivers/usb/chipidea/udc.c +++ b/drivers/usb/chipidea/udc.c @@ -23,6 +23,7 @@ #include <linux/irq.h> #include <linux/kernel.h> #include <linux/slab.h> +#include <linux/sizes.h> #include <linux/pm_runtime.h> #include <linux/usb/ch9.h> #include <linux/usb/gadget.h> @@ -1417,7 +1418,7 @@ static int ci13xxx_vbus_session(struct usb_gadget *_gadget, int is_active) pm_runtime_get_sync(&_gadget->dev); hw_device_reset(ci, USBMODE_CM_DC); hw_enable_vbus_intr(ci); - hw_device_state(ci, ci->ep0out->qh.dma); + hw_device_state(ci, ci->qh.dma); } else { hw_device_state(ci, 0); if (ci->platdata->notify_event) @@ -1520,8 +1521,8 @@ static int init_eps(struct ci13xxx *ci) mEp->ep.maxpacket = (unsigned short)~0; INIT_LIST_HEAD(&mEp->qh.queue); - mEp->qh.ptr = dma_pool_alloc(ci->qh_pool, GFP_KERNEL, - &mEp->qh.dma); + mEp->qh.ptr = &ci->qh.ptr[i * 2 + j]; + if (mEp->qh.ptr == NULL) retval = -ENOMEM; else @@ -1549,13 +1550,8 @@ static int init_eps(struct ci13xxx *ci) static void destroy_eps(struct ci13xxx *ci) { - int i; - - for (i = 0; i < ci->hw_ep_max; i++) { - struct ci13xxx_ep *mEp = &ci->ci13xxx_ep[i]; - - dma_pool_free(ci->qh_pool, mEp->qh.ptr, mEp->qh.dma); - } + dma_free_coherent(ci->dev, ci->qh.size, + ci->qh.ptr, ci->qh.dma); } /** @@ -1601,7 +1597,7 @@ static int ci13xxx_start(struct usb_gadget *gadget, } } - retval = hw_device_state(ci, ci->ep0out->qh.dma); + retval = hw_device_state(ci, ci->qh.dma); if (retval) pm_runtime_put_sync(&ci->gadget.dev); @@ -1747,11 +1743,14 @@ static int udc_start(struct ci13xxx *ci) ci->gadget.dev.parent = dev; ci->gadget.dev.release = udc_release; + ci->qh.size = ci->hw_ep_max * sizeof(struct ci13xxx_qh); + ci->qh.size = ALIGN(ci->qh.size, SZ_2K); + /* alloc resources */ - ci->qh_pool = dma_pool_create("ci13xxx_qh", dev, - sizeof(struct ci13xxx_qh), - 64, CI13XXX_PAGE_SIZE); - if (ci->qh_pool == NULL) + ci->qh.ptr = dma_alloc_coherent(dev, ci->qh.size, + &ci->qh.dma, GFP_ATOMIC); + + if (ci->qh.ptr == NULL) return -ENOMEM; ci->td_pool = dma_pool_create("ci13xxx_td", dev, @@ -1831,7 +1830,6 @@ destroy_eps: free_pools: dma_pool_destroy(ci->td_pool); free_qh_pool: - dma_pool_destroy(ci->qh_pool); return retval; } @@ -1853,7 +1851,6 @@ static void udc_stop(struct ci13xxx *ci) destroy_eps(ci); dma_pool_destroy(ci->td_pool); - dma_pool_destroy(ci->qh_pool); if (!IS_ERR_OR_NULL(ci->transceiver)) { otg_set_peripheral(ci->transceiver->otg, NULL); diff --git a/drivers/usb/chipidea/udc.h b/drivers/usb/chipidea/udc.h index d12e8b5..59c091b 100644 --- a/drivers/usb/chipidea/udc.h +++ b/drivers/usb/chipidea/udc.h @@ -57,7 +57,7 @@ struct ci13xxx_qh { /* 9 */ u32 RESERVED; struct usb_ctrlrequest setup; -} __attribute__ ((packed, aligned(4))); +} __attribute__ ((packed, aligned(64))); /** * struct ci13xxx_req - usb request representation -- 1.8.2.rc2 -- To unsubscribe from this list: send the line "unsubscribe stable" in the body of a message to majordomo@xxxxxxxxxxxxxxx More majordomo info at http://vger.kernel.org/majordomo-info.html