From 70eaeb03c1fc173b1a7c11ad627d8cc8bbfe3e6c Mon Sep 17 00:00:00 2001 From: Peng Fan Date: Fri, 28 Aug 2015 09:20:30 +0800 Subject: usb: gadget: ci_udc: implement usb_ep_ops dequeue callback MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Implement endpoint dequeue callback function. Without this function, uboot will hang when executing fastboot comamnd. See following flow: "fastboot_tx_write_str->fastboot_tx_write->usb_ep_dequeue->ep->ops->dequeue" without implement ci_udc dequeue function, ep->ops->dequeue is NULL, then uboot will hang. Tested on mx6qsabresd board with fastboot enabled. Signed-off-by: Peng Fan Tested-by: Fabio Estevam Cc: "Ɓukasz Majewski" Cc: Marek Vasut diff --git a/drivers/usb/gadget/ci_udc.c b/drivers/usb/gadget/ci_udc.c index 3e8eb87..c0d23a4 100644 --- a/drivers/usb/gadget/ci_udc.c +++ b/drivers/usb/gadget/ci_udc.c @@ -87,6 +87,7 @@ static int ci_ep_enable(struct usb_ep *ep, static int ci_ep_disable(struct usb_ep *ep); static int ci_ep_queue(struct usb_ep *ep, struct usb_request *req, gfp_t gfp_flags); +static int ci_ep_dequeue(struct usb_ep *ep, struct usb_request *req); static struct usb_request * ci_ep_alloc_request(struct usb_ep *ep, unsigned int gfp_flags); static void ci_ep_free_request(struct usb_ep *ep, struct usb_request *_req); @@ -99,6 +100,7 @@ static struct usb_ep_ops ci_ep_ops = { .enable = ci_ep_enable, .disable = ci_ep_disable, .queue = ci_ep_queue, + .dequeue = ci_ep_dequeue, .alloc_request = ci_ep_alloc_request, .free_request = ci_ep_free_request, }; @@ -525,6 +527,30 @@ static void ci_ep_submit_next_request(struct ci_ep *ci_ep) writel(bit, &udc->epprime); } +static int ci_ep_dequeue(struct usb_ep *_ep, struct usb_request *_req) +{ + struct ci_ep *ci_ep = container_of(_ep, struct ci_ep, ep); + struct ci_req *ci_req; + + list_for_each_entry(ci_req, &ci_ep->queue, queue) { + if (&ci_req->req == _req) + break; + } + + if (&ci_req->req != _req) + return -EINVAL; + + list_del_init(&ci_req->queue); + + if (ci_req->req.status == -EINPROGRESS) { + ci_req->req.status = -ECONNRESET; + if (ci_req->req.complete) + ci_req->req.complete(_ep, _req); + } + + return 0; +} + static int ci_ep_queue(struct usb_ep *ep, struct usb_request *req, gfp_t gfp_flags) { -- cgit v0.10.2 From b337b3b2a53f112a217f4bd31307b02f830bb787 Mon Sep 17 00:00:00 2001 From: Stephen Warren Date: Fri, 11 Sep 2015 17:10:02 -0600 Subject: usb: ci_udc: fix emissions of ZLPs Commit 6a132416359e "ci_udc: Update the ci_udc driver to support bulk transfers" caused the value of "len" to change without updating subsquent users of that variable in ci_ep_submit_next_request(). This caused the code that detects when to emit ZLPs (Zero Length Packets) never to trigger, which in turn caused host timeouts when a ZLP was required, which in turn broke tests/dfu/, even despite the assertion in that commit's description that "These changes are tested for both the DFU and lthor." Fix this by modifying the added dtd iteration code not to modify "len", but rather to keep state in a separate variable. Rename the variables while we're at it so they describe their purpose better. Fixes: 6a132416359e ("ci_udc: Update the ci_udc driver to support bulk transfers") Cc: Siva Durga Prasad Paladugu Signed-off-by: Stephen Warren diff --git a/drivers/usb/gadget/ci_udc.c b/drivers/usb/gadget/ci_udc.c index c0d23a4..1ba5054 100644 --- a/drivers/usb/gadget/ci_udc.c +++ b/drivers/usb/gadget/ci_udc.c @@ -426,7 +426,7 @@ static void ci_ep_submit_next_request(struct ci_ep *ci_ep) int bit, num, len, in; struct ci_req *ci_req; u8 *buf; - uint32_t length, actlen; + uint32_t len_left, len_this_dtd; struct ept_queue_item *dtd, *qtd; ci_ep->req_primed = true; @@ -444,25 +444,23 @@ static void ci_ep_submit_next_request(struct ci_ep *ci_ep) ci_req->dtd_count = 0; buf = ci_req->hw_buf; - actlen = 0; + len_left = len; dtd = item; do { - length = min(ci_req->req.length - actlen, - (unsigned)EP_MAX_LENGTH_TRANSFER); + len_this_dtd = min(len_left, (unsigned)EP_MAX_LENGTH_TRANSFER); - dtd->info = INFO_BYTES(length) | INFO_ACTIVE; + dtd->info = INFO_BYTES(len_this_dtd) | INFO_ACTIVE; dtd->page0 = (unsigned long)buf; dtd->page1 = ((unsigned long)buf & 0xfffff000) + 0x1000; dtd->page2 = ((unsigned long)buf & 0xfffff000) + 0x2000; dtd->page3 = ((unsigned long)buf & 0xfffff000) + 0x3000; dtd->page4 = ((unsigned long)buf & 0xfffff000) + 0x4000; - len -= length; - actlen += length; - buf += length; + len_left -= len_this_dtd; + buf += len_this_dtd; - if (len) { + if (len_left) { qtd = (struct ept_queue_item *) memalign(ILIST_ALIGN, ILIST_ENT_SZ); dtd->next = (unsigned long)qtd; @@ -471,7 +469,7 @@ static void ci_ep_submit_next_request(struct ci_ep *ci_ep) } ci_req->dtd_count++; - } while (len); + } while (len_left); item = dtd; /* -- cgit v0.10.2