提交 a0807881 编写于 作者: F Felipe Balbi

usb: dwc3: handle pending unaligned Control OUT data phase correctly

When DWC3_EP_PENDING_REQUEST flag is set for a Control OUT Data
phase transfer, we would be missing the proper handling for
unaligned OUT requests, thus hanging a transfer.

Since proper handling is already done on dwc3_ep0_do_control_data(),
we simply re-factor that function so it can be re-used from
__dwc3_gadget_ep0_queue().
Reported-by: NPratyush Anand <pratyush.anand@st.com>
Signed-off-by: NFelipe Balbi <balbi@ti.com>
上级 4552a0ca
...@@ -55,6 +55,8 @@ ...@@ -55,6 +55,8 @@
#include "io.h" #include "io.h"
static void dwc3_ep0_do_control_status(struct dwc3 *dwc, u32 epnum); static void dwc3_ep0_do_control_status(struct dwc3 *dwc, u32 epnum);
static void __dwc3_ep0_do_control_data(struct dwc3 *dwc,
struct dwc3_ep *dep, struct dwc3_request *req);
static const char *dwc3_ep0_state_string(enum dwc3_ep0_state state) static const char *dwc3_ep0_state_string(enum dwc3_ep0_state state)
{ {
...@@ -150,9 +152,8 @@ static int __dwc3_gadget_ep0_queue(struct dwc3_ep *dep, ...@@ -150,9 +152,8 @@ static int __dwc3_gadget_ep0_queue(struct dwc3_ep *dep,
return 0; return 0;
} }
ret = dwc3_ep0_start_trans(dwc, direction, __dwc3_ep0_do_control_data(dwc, dwc->eps[direction], req);
req->request.dma, req->request.length,
DWC3_TRBCTL_CONTROL_DATA);
dep->flags &= ~(DWC3_EP_PENDING_REQUEST | dep->flags &= ~(DWC3_EP_PENDING_REQUEST |
DWC3_EP0_DIR_IN); DWC3_EP0_DIR_IN);
} else if (dwc->delayed_status) { } else if (dwc->delayed_status) {
...@@ -787,35 +788,23 @@ static void dwc3_ep0_do_control_setup(struct dwc3 *dwc, ...@@ -787,35 +788,23 @@ static void dwc3_ep0_do_control_setup(struct dwc3 *dwc,
dwc3_ep0_out_start(dwc); dwc3_ep0_out_start(dwc);
} }
static void dwc3_ep0_do_control_data(struct dwc3 *dwc, static void __dwc3_ep0_do_control_data(struct dwc3 *dwc,
const struct dwc3_event_depevt *event) struct dwc3_ep *dep, struct dwc3_request *req)
{ {
struct dwc3_ep *dep;
struct dwc3_request *req;
int ret; int ret;
dep = dwc->eps[0]; req->direction = !!dep->number;
if (list_empty(&dep->request_list)) {
dev_vdbg(dwc->dev, "pending request for EP0 Data phase\n");
dep->flags |= DWC3_EP_PENDING_REQUEST;
if (event->endpoint_number)
dep->flags |= DWC3_EP0_DIR_IN;
return;
}
req = next_request(&dep->request_list);
req->direction = !!event->endpoint_number;
if (req->request.length == 0) { if (req->request.length == 0) {
ret = dwc3_ep0_start_trans(dwc, event->endpoint_number, ret = dwc3_ep0_start_trans(dwc, dep->number,
dwc->ctrl_req_addr, 0, dwc->ctrl_req_addr, 0,
DWC3_TRBCTL_CONTROL_DATA); DWC3_TRBCTL_CONTROL_DATA);
} else if ((req->request.length % dep->endpoint.maxpacket) } else if ((req->request.length % dep->endpoint.maxpacket)
&& (event->endpoint_number == 0)) { && (dep->number == 0)) {
u32 transfer_size;
ret = usb_gadget_map_request(&dwc->gadget, &req->request, ret = usb_gadget_map_request(&dwc->gadget, &req->request,
event->endpoint_number); dep->number);
if (ret) { if (ret) {
dev_dbg(dwc->dev, "failed to map request\n"); dev_dbg(dwc->dev, "failed to map request\n");
return; return;
...@@ -823,6 +812,9 @@ static void dwc3_ep0_do_control_data(struct dwc3 *dwc, ...@@ -823,6 +812,9 @@ static void dwc3_ep0_do_control_data(struct dwc3 *dwc,
WARN_ON(req->request.length > DWC3_EP0_BOUNCE_SIZE); WARN_ON(req->request.length > DWC3_EP0_BOUNCE_SIZE);
transfer_size = roundup(req->request.length,
(u32) dep->endpoint.maxpacket);
dwc->ep0_bounced = true; dwc->ep0_bounced = true;
/* /*
...@@ -830,25 +822,47 @@ static void dwc3_ep0_do_control_data(struct dwc3 *dwc, ...@@ -830,25 +822,47 @@ static void dwc3_ep0_do_control_data(struct dwc3 *dwc,
* DWC3_EP0_BOUNCE_SIZE we will need two chained * DWC3_EP0_BOUNCE_SIZE we will need two chained
* TRBs to handle the transfer. * TRBs to handle the transfer.
*/ */
ret = dwc3_ep0_start_trans(dwc, event->endpoint_number, ret = dwc3_ep0_start_trans(dwc, dep->number,
dwc->ep0_bounce_addr, dep->endpoint.maxpacket, dwc->ep0_bounce_addr, transfer_size,
DWC3_TRBCTL_CONTROL_DATA); DWC3_TRBCTL_CONTROL_DATA);
} else { } else {
ret = usb_gadget_map_request(&dwc->gadget, &req->request, ret = usb_gadget_map_request(&dwc->gadget, &req->request,
event->endpoint_number); dep->number);
if (ret) { if (ret) {
dev_dbg(dwc->dev, "failed to map request\n"); dev_dbg(dwc->dev, "failed to map request\n");
return; return;
} }
ret = dwc3_ep0_start_trans(dwc, event->endpoint_number, ret = dwc3_ep0_start_trans(dwc, dep->number, req->request.dma,
req->request.dma, req->request.length, req->request.length, DWC3_TRBCTL_CONTROL_DATA);
DWC3_TRBCTL_CONTROL_DATA);
} }
WARN_ON(ret < 0); WARN_ON(ret < 0);
} }
static void dwc3_ep0_do_control_data(struct dwc3 *dwc,
const struct dwc3_event_depevt *event)
{
struct dwc3_ep *dep;
struct dwc3_request *req;
dep = dwc->eps[0];
if (list_empty(&dep->request_list)) {
dev_vdbg(dwc->dev, "pending request for EP0 Data phase\n");
dep->flags |= DWC3_EP_PENDING_REQUEST;
if (event->endpoint_number)
dep->flags |= DWC3_EP0_DIR_IN;
return;
}
req = next_request(&dep->request_list);
dep = dwc->eps[event->endpoint_number];
__dwc3_ep0_do_control_data(dwc, dep, req);
}
static int dwc3_ep0_start_control_status(struct dwc3_ep *dep) static int dwc3_ep0_start_control_status(struct dwc3_ep *dep)
{ {
struct dwc3 *dwc = dep->dwc; struct dwc3 *dwc = dep->dwc;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册