
On 07/01/2014 02:04 AM, Marek Vasut wrote:
Instead of weird allocation of ci_drv->items_mem and then even weirder distribution of offsets in this memory area into ci_drv->items array, just allocate ci_drv->items as a big slab of aligned memory (replaces ci_drv->items_mem) and let ci_get_qtd() do the distribution of offsets in this memory area.
Signed-off-by: Marek Vasut marex@denx.de Cc: Jörg Krause jkrause@posteo.de Cc: Stephen Warren swarren@wwwdotorg.org
drivers/usb/gadget/ci_udc.c | 19 ++++++------------- drivers/usb/gadget/ci_udc.h | 3 +-- 2 files changed, 7 insertions(+), 15 deletions(-)
V2: Rebase on top of u-boot-usb/master instead of the research branch
diff --git a/drivers/usb/gadget/ci_udc.c b/drivers/usb/gadget/ci_udc.c index 1af6d12..8333db2 100644 --- a/drivers/usb/gadget/ci_udc.c +++ b/drivers/usb/gadget/ci_udc.c @@ -130,7 +130,7 @@ static struct ept_queue_head *ci_get_qh(int ep_num, int dir_in) */ static struct ept_queue_item *ci_get_qtd(int ep_num, int dir_in) {
- return controller.items[(ep_num * 2) + dir_in];
return controller.items + ((ep_num * 2) + dir_in); }
/**
@@ -769,7 +769,6 @@ static int ci_pullup(struct usb_gadget *gadget, int is_on) static int ci_udc_probe(void) { struct ept_queue_head *head;
uint8_t *imem; int i;
const int num = 2 * NUM_ENDPOINTS;
@@ -796,12 +795,12 @@ static int ci_udc_probe(void) * only one of them is used for the endpoint at time, so we can group * them together. */
- controller.items_mem = memalign(ilist_align, ilist_sz);
- if (!controller.items_mem) {
- controller.items = memalign(ilist_align, ilist_sz);
- if (!controller.items) { free(controller.epts); return -ENOMEM; }
- memset(controller.items_mem, 0, ilist_sz);
memset(controller.items, 0, ilist_sz);
for (i = 0; i < 2 * NUM_ENDPOINTS; i++) { /*
@@ -821,12 +820,6 @@ static int ci_udc_probe(void) head->next = TERMINATE; head->info = 0;
imem = controller.items_mem + ((i >> 1) * ilist_ent_sz);
if (i & 1)
imem += sizeof(struct ept_queue_item);
controller.items[i] = (struct ept_queue_item *)imem;
- if (i & 1) { ci_flush_qh(i - 1); ci_flush_qtd(i - 1);
@@ -855,7 +848,7 @@ static int ci_udc_probe(void)
ci_ep_alloc_request(&controller.ep[0].ep, 0); if (!controller.ep0_req) {
free(controller.items_mem);
free(controller.epts); return -ENOMEM; }free(controller.items);
@@ -910,7 +903,7 @@ int usb_gadget_unregister_driver(struct usb_gadget_driver *driver) controller.driver = NULL;
ci_ep_free_request(&controller.ep[0].ep, &controller.ep0_req->req);
- free(controller.items_mem);
free(controller.items); free(controller.epts);
return 0;
diff --git a/drivers/usb/gadget/ci_udc.h b/drivers/usb/gadget/ci_udc.h index c214402..3115b15 100644 --- a/drivers/usb/gadget/ci_udc.h +++ b/drivers/usb/gadget/ci_udc.h @@ -102,8 +102,7 @@ struct ci_drv { struct usb_gadget_driver *driver; struct ehci_ctrl *ctrl; struct ept_queue_head *epts;
- struct ept_queue_item *items[2 * NUM_ENDPOINTS];
- uint8_t *items_mem;
- struct ept_queue_item *items; struct ci_ep ep[NUM_ENDPOINTS]; };
I made a test on u-boot-arm/master before (Test#1) and after applying this patch (Test#2). After a reset I run this script: test_usb=setenv i 64; while test ${i} -gt 0; do echo ${i}; tftp ${rootfs_file}; setexpr i ${i} - 1; done; setenv i;
Both tests (Test#1 and Test#2) runs fine with the script. But if I do run tftp ${rootfs_file} manually from the console, I get the known error starting the fourth run for both Test#1 and Test#2.
I attached a log file for the error.