usb: dwc3: add cancelled reasons for dwc3 requests
Subsystems (2)
PATCH v2 1/1 usb: dwc3: add cancelled reasons for dwc3 requests
Currently, when dwc3 handles request cancelled, dwc3 just returns -ECONNRESET for all requests. It will cause USB function drivers can't know if the requests are cancelled by other reasons.
This patch will replace DWC3_REQUEST_STATUS_CANCELLED with the reasons below.
- DWC3_REQUEST_STATUS_DISCONNECTED
- DWC3_REQUEST_STATUS_DEQUEUED
- DWC3_REQUEST_STATUS_STALLED
--- drivers/usb/dwc3/core.h | 12 +++++++----- drivers/usb/dwc3/gadget.c | 21 +++++++++++++++++---- drivers/usb/dwc3/gadget.h | 6 ++++-- 3 files changed, 28 insertions(+), 11 deletions(-)
drivers/usb/dwc3/core.h +7 -5
@@ -908,11 +908,13 @@ struct dwc3_request {unsigned int remaining;unsigned int status; -#define DWC3_REQUEST_STATUS_QUEUED 0 -#define DWC3_REQUEST_STATUS_STARTED 1 -#define DWC3_REQUEST_STATUS_CANCELLED 2 -#define DWC3_REQUEST_STATUS_COMPLETED 3 -#define DWC3_REQUEST_STATUS_UNKNOWN -1 +#define DWC3_REQUEST_STATUS_QUEUED 0 +#define DWC3_REQUEST_STATUS_STARTED 1 +#define DWC3_REQUEST_STATUS_DISCONNECTED 2 +#define DWC3_REQUEST_STATUS_DEQUEUED 3 +#define DWC3_REQUEST_STATUS_STALLED 4 +#define DWC3_REQUEST_STATUS_COMPLETED 5 +#define DWC3_REQUEST_STATUS_UNKNOWN -1u8 epnum;struct dwc3_trb *trb;
drivers/usb/dwc3/gadget.c +17 -4
@@ -1402,7 +1402,7 @@ static int __dwc3_gadget_kick_transfer(struct dwc3_ep *dep)dwc3_stop_active_transfer (dep, true, true);list_for_each_entry_safe (req, tmp, &dep->started_list, list) -dwc3_gadget_move_cancelled_request (req); +dwc3_gadget_move_cancelled_request (req,DWC3_REQUEST_STATUS_DEQUEUED );/* If ep isn't started, then there's no end transfer pending */ if (!(dep->flags &DWC3_EP_END_TRANSFER_PENDING ))
@@ -1732,7 +1732,19 @@ static void dwc3_gadget_ep_cleanup_cancelled_requests(struct dwc3_ep *dep)list_for_each_entry_safe (req, tmp, &dep->cancelled_list, list) {dwc3_gadget_ep_skip_trbs (dep, req); -dwc3_gadget_giveback (dep, req, -ECONNRESET ); +switch (req->status) { +case DWC3_REQUEST_STATUS_DISCONNECTED : +dwc3_gadget_giveback (dep, req, -ESHUTDOWN ); +break ; +case DWC3_REQUEST_STATUS_DEQUEUED : +dwc3_gadget_giveback (dep, req, -ECONNRESET ); +break ; +case DWC3_REQUEST_STATUS_STALLED : +dwc3_gadget_giveback (dep, req, -EPIPE ); +break ; +default : +break ; + } } }
@@ -1776,7 +1788,8 @@ static int dwc3_gadget_ep_dequeue(struct usb_ep *ep,* cancelled. */ list_for_each_entry_safe (r, t, &dep->started_list, list) -dwc3_gadget_move_cancelled_request (r); +dwc3_gadget_move_cancelled_request (r, +DWC3_REQUEST_STATUS_DEQUEUED ); dep->flags &= ~DWC3_EP_WAIT_TRANSFER_COMPLETE ;
@@ -1848,7 +1861,7 @@ int __dwc3_gadget_ep_set_halt(struct dwc3_ep *dep, int value, int protocol)dwc3_stop_active_transfer (dep, true, true);list_for_each_entry_safe (req, tmp, &dep->started_list, list) -dwc3_gadget_move_cancelled_request (req); +dwc3_gadget_move_cancelled_request (req,DWC3_REQUEST_STATUS_STALLED );if (dep->flags &DWC3_EP_END_TRANSFER_PENDING ) { dep->flags |=DWC3_EP_PENDING_CLEAR_STALL ;
drivers/usb/dwc3/gadget.h +4 -2
@@ -90,15 +90,17 @@ static inline void dwc3_gadget_move_started_request(struct dwc3_request *req)/** * dwc3_gadget_move_cancelled_request - move @req to the cancelled_list * @req: the request to be moved +* @reason: cancelled reason for the dwc3 request * * Caller should take care of locking. This function will move @req from its * current list to the endpoint's cancelled_list. */ -static inline void dwc3_gadget_move_cancelled_request (struct dwc3_request *req) +static inline void dwc3_gadget_move_cancelled_request (struct dwc3_request *req, +unsigned int reason) {struct dwc3_ep *dep = req->dep; - req->status =DWC3_REQUEST_STATUS_CANCELLED ; + req->status = reason;list_move_tail (&req->list, &dep->cancelled_list); }
Signature · 1 line
2.31.0.291.g576ba9dcdaf-goog
Thinh Nguyen
maintainerHi Ray,
Quoted 59 lines · Ray Chi
Currently, when dwc3 handles request cancelled, dwc3 just returns
-ECONNRESETfor all requests. It will cause USB function drivers can't know if the requests are cancelled by other reasons.This patch will replace
DWC3_REQUEST_STATUS_CANCELLEDwith the reasons below.
-DWC3_REQUEST_STATUS_DISCONNECTED
-DWC3_REQUEST_STATUS_DEQUEUED
-DWC3_REQUEST_STATUS_STALLEDSigned-off-by Ray Chi <[email protected]>--- drivers/usb/dwc3/core.h | 12 +++++++----- drivers/usb/dwc3/gadget.c | 21 +++++++++++++++++---- drivers/usb/dwc3/gadget.h | 6 ++++-- 3 files changed, 28 insertions(+), 11 deletions(-)drivers/usb/dwc3/core.h +7
-5@@ -908,11 +908,13 @@ struct dwc3_request {unsigned int remaining;unsigned int status; -#define DWC3_REQUEST_STATUS_QUEUED 0 -#define DWC3_REQUEST_STATUS_STARTED 1 -#define DWC3_REQUEST_STATUS_CANCELLED 2 -#define DWC3_REQUEST_STATUS_COMPLETED 3 -#define DWC3_REQUEST_STATUS_UNKNOWN -1 +#define DWC3_REQUEST_STATUS_QUEUED 0 +#define DWC3_REQUEST_STATUS_STARTED 1 +#define DWC3_REQUEST_STATUS_DISCONNECTED 2 +#define DWC3_REQUEST_STATUS_DEQUEUED 3 +#define DWC3_REQUEST_STATUS_STALLED 4 +#define DWC3_REQUEST_STATUS_COMPLETED 5 +#define DWC3_REQUEST_STATUS_UNKNOWN -1u8 epnum;struct dwc3_trb *trb;drivers/usb/dwc3/gadget.c +2
-2@@ -1402,7 +1402,7 @@ static int __dwc3_gadget_kick_transfer(struct dwc3_ep *dep)dwc3_stop_active_transfer (dep, true, true);list_for_each_entry_safe (req, tmp, &dep->started_list, list) -dwc3_gadget_move_cancelled_request (req); +dwc3_gadget_move_cancelled_request (req,DWC3_REQUEST_STATUS_DEQUEUED );/* If ep isn't started, then there's no end transfer pending */ if (!(dep->flags &DWC3_EP_END_TRANSFER_PENDING ))@@ -1732,7 +1732,19 @@ static void dwc3_gadget_ep_cleanup_cancelled_requests(struct dwc3_ep *dep)list_for_each_entry_safe (req, tmp, &dep->cancelled_list, list) {dwc3_gadget_ep_skip_trbs (dep, req); -dwc3_gadget_giveback (dep, req, -ECONNRESET ); +switch (req->status) {
drivers/usb/dwc3/gadget.c static void dwc3_gadget_ep_cleanup_cancelled_requests(struct dwc3_ep *dep) · line 1745
Quoted 10 lines
drivers/usb/dwc3/gadget.c +10
-0+case DWC3_REQUEST_STATUS_DISCONNECTED : +dwc3_gadget_giveback (dep, req, -ESHUTDOWN ); +break ; +case DWC3_REQUEST_STATUS_DEQUEUED : +dwc3_gadget_giveback (dep, req, -ECONNRESET ); +break ; +case DWC3_REQUEST_STATUS_STALLED : +dwc3_gadget_giveback (dep, req, -EPIPE ); +break ; +default :
Also giveback the request for default case here, but with -ECONNRESET and a dev_err() print here indicating driver bug. The rest of the patch looks good.
Thanks,
Thinh
Quoted 49 lines
drivers/usb/dwc3/gadget.c +5
-2+break ; + } } }@@ -1776,7 +1788,8 @@ static int dwc3_gadget_ep_dequeue(struct usb_ep *ep,* cancelled. */ list_for_each_entry_safe (r, t, &dep->started_list, list) -dwc3_gadget_move_cancelled_request (r); +dwc3_gadget_move_cancelled_request (r, +DWC3_REQUEST_STATUS_DEQUEUED ); dep->flags &= ~DWC3_EP_WAIT_TRANSFER_COMPLETE ;@@ -1848,7 +1861,7 @@ int __dwc3_gadget_ep_set_halt(struct dwc3_ep *dep, int value, int protocol)dwc3_stop_active_transfer (dep, true, true);list_for_each_entry_safe (req, tmp, &dep->started_list, list) -dwc3_gadget_move_cancelled_request (req); +dwc3_gadget_move_cancelled_request (req,DWC3_REQUEST_STATUS_STALLED );if (dep->flags &DWC3_EP_END_TRANSFER_PENDING ) { dep->flags |=DWC3_EP_PENDING_CLEAR_STALL ;drivers/usb/dwc3/gadget.h +4
-2@@ -90,15 +90,17 @@ static inline void dwc3_gadget_move_started_request(struct dwc3_request *req)/** * dwc3_gadget_move_cancelled_request - move @req to the cancelled_list * @req: the request to be moved +* @reason: cancelled reason for the dwc3 request * * Caller should take care of locking. This function will move @req from its * current list to the endpoint's cancelled_list. */ -static inline void dwc3_gadget_move_cancelled_request (struct dwc3_request *req) +static inline void dwc3_gadget_move_cancelled_request (struct dwc3_request *req, +unsigned int reason) {struct dwc3_ep *dep = req->dep; - req->status =DWC3_REQUEST_STATUS_CANCELLED ; + req->status = reason;list_move_tail (&req->list, &dep->cancelled_list); }