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 <ma...@denx.de>
Cc: Jörg Krause <jkra...@posteo.de>
Cc: Stephen Warren <swar...@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.items);
                free(controller.epts);
                return -ENOMEM;
        }
@@ -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.

=> reset
resetting ...
HTLLCLLC

U-Boot 2014.07-rc3-g18e0313 (Jul 01 2014 - 08:32:45)

CPU:   Freescale i.MX28 rev1.2 at 454 MHz
BOOT:  NAND, 3V3
DRAM:  64 MiB
NAND:  128 MiB
In:    serial
Out:   serial
Err:   serial
Net:   usb_ether [PRIME]
Hit any key to stop autoboot:  0 
=> tftp ${rootfs_file}
using ci_udc, OUT ep- IN ep- STATUS ep-
MAC 00:19:b8:00:00:02
HOST MAC 00:19:b8:00:00:01
high speed config #1: 2 mA, Ethernet Gadget, using CDC Ethernet
USB network up!
Using usb_ether device
TFTP from server 10.0.0.1; our IP address is 10.0.0.2
Filename 'rootfs.ubifs'.
Load address: 0x40008000
Loading: #################################################################
         #################################################################
         #################################################################
         #################################################################
         #################################################################
         #################################################################
         #################################################################
         #################################################################
         #################################################################
         #################################################################
         #################################################################
         #################################################################
         #################################################################
         #######################################################
         5.6 MiB/s
done
Bytes transferred = 13205504 (c98000 hex)
=> 
using ci_udc, OUT ep- IN ep- STATUS ep-
MAC 00:19:b8:00:00:02
HOST MAC 00:19:b8:00:00:01
high speed config #1: 2 mA, Ethernet Gadget, using CDC Ethernet
USB network up!
Using usb_ether device
TFTP from server 10.0.0.1; our IP address is 10.0.0.2
Filename 'rootfs.ubifs'.
Load address: 0x40008000
Loading: #################################################################
         #################################################################
         #################################################################
         #################################################################
         #################################################################
         #################################################################
         #################################################################
         #################################################################
         #################################################################
         #################################################################
         #################################################################
         #################################################################
         #################################################################
         #######################################################
         5.6 MiB/s
done
Bytes transferred = 13205504 (c98000 hex)
=> 
using ci_udc, OUT ep- IN ep- STATUS ep-
MAC 00:19:b8:00:00:02
HOST MAC 00:19:b8:00:00:01
high speed config #1: 2 mA, Ethernet Gadget, using CDC Ethernet
USB network up!
Using usb_ether device
TFTP from server 10.0.0.1; our IP address is 10.0.0.2
Filename 'rootfs.ubifs'.
Load address: 0x40008000
Loading: #################################################################
         #################################################################
         #################################################################
         #################################################################
         #################################################################
         #################################################################
         #################################################################
         #################################################################
         #################################################################
         #################################################################
         #################################################################
         #################################################################
         #################################################################
         #######################################################
         5.6 MiB/s
done
Bytes transferred = 13205504 (c98000 hex)
=> 
using ci_udc, OUT ep- IN ep- STATUS ep-
MAC 00:19:b8:00:00:02
HOST MAC 00:19:b8:00:00:01
high speed config #1: 2 mA, Ethernet Gadget, using CDC Ethernet
ERROR: The remote end did not respond in time.
at drivers/usb/gadget/ether.c:2388/usb_eth_init()
=> 
_______________________________________________
U-Boot mailing list
U-Boot@lists.denx.de
http://lists.denx.de/mailman/listinfo/u-boot

Reply via email to