diff mbox series

[3/3] usb: dwc3: gadget: Issue END_TRANSFER to retry isoc transfer

Message ID ab34698f56f613cdf63d7d955e94c064a185b001.1584065705.git.thinhn@synopsys.com (mailing list archive)
State Superseded
Headers show
Series usb: dwc3: gadget: Improve isoc starting mechanism | expand

Commit Message

Thinh Nguyen March 13, 2020, 2:18 a.m. UTC
After a number of unsuccessful start isoc attempts due to bus-expiry
status, issue END_TRANSFER command and retry on the next XferNotReady
event.

Signed-off-by: Thinh Nguyen <thinhn@synopsys.com>
---
 drivers/usb/dwc3/gadget.c | 36 +++++++++++++++++++++++++++++++++++-
 1 file changed, 35 insertions(+), 1 deletion(-)

Comments

Felipe Balbi March 13, 2020, 2:38 p.m. UTC | #1
Hi,

Thinh Nguyen <Thinh.Nguyen@synopsys.com> writes:

> After a number of unsuccessful start isoc attempts due to bus-expiry
> status, issue END_TRANSFER command and retry on the next XferNotReady
> event.
>
> Signed-off-by: Thinh Nguyen <thinhn@synopsys.com>
> ---
>  drivers/usb/dwc3/gadget.c | 36 +++++++++++++++++++++++++++++++++++-
>  1 file changed, 35 insertions(+), 1 deletion(-)
>
> diff --git a/drivers/usb/dwc3/gadget.c b/drivers/usb/dwc3/gadget.c
> index f1aae4615cf1..a5ad02987536 100644
> --- a/drivers/usb/dwc3/gadget.c
> +++ b/drivers/usb/dwc3/gadget.c
> @@ -1406,7 +1406,8 @@ static int __dwc3_gadget_start_isoc(struct dwc3_ep *dep)
>  	int ret;
>  	int i;
>  
> -	if (list_empty(&dep->pending_list)) {
> +	if (list_empty(&dep->pending_list) &&
> +	    list_empty(&dep->started_list)) {
>  		dep->flags |= DWC3_EP_PENDING_REQUEST;
>  		return -EAGAIN;
>  	}
> @@ -1429,6 +1430,27 @@ static int __dwc3_gadget_start_isoc(struct dwc3_ep *dep)
>  			break;
>  	}
>  
> +	/*
> +	 * After a number of unsuccessful start attempts due to bus-expiry
> +	 * status, issue END_TRANSFER command and retry on the next XferNotReady
> +	 * event.
> +	 */
> +	if (ret == -EAGAIN) {
> +		struct dwc3_gadget_ep_cmd_params params;
> +		u32 cmd;
> +
> +		cmd = DWC3_DEPCMD_ENDTRANSFER |
> +			DWC3_DEPCMD_CMDIOC |
> +			DWC3_DEPCMD_PARAM(dep->resource_index);
> +
> +		dep->resource_index = 0;
> +		memset(&params, 0, sizeof(params));
> +
> +		ret = dwc3_send_gadget_ep_cmd(dep, cmd, &params);
> +		if (!ret)
> +			dep->flags |= DWC3_EP_END_TRANSFER_PENDING;
> +	}

I like this! Pretty good idea :-) I'll wait for your reply to my
question on the other patch, then start queueing again.
Thinh Nguyen March 13, 2020, 8:01 p.m. UTC | #2
Hi Felipe,

Felipe Balbi wrote:
> Hi,
>
> Thinh Nguyen <Thinh.Nguyen@synopsys.com> writes:
>
>> After a number of unsuccessful start isoc attempts due to bus-expiry
>> status, issue END_TRANSFER command and retry on the next XferNotReady
>> event.
>>
>> Signed-off-by: Thinh Nguyen <thinhn@synopsys.com>
>> ---
>>   drivers/usb/dwc3/gadget.c | 36 +++++++++++++++++++++++++++++++++++-
>>   1 file changed, 35 insertions(+), 1 deletion(-)
>>
>> diff --git a/drivers/usb/dwc3/gadget.c b/drivers/usb/dwc3/gadget.c
>> index f1aae4615cf1..a5ad02987536 100644
>> --- a/drivers/usb/dwc3/gadget.c
>> +++ b/drivers/usb/dwc3/gadget.c
>> @@ -1406,7 +1406,8 @@ static int __dwc3_gadget_start_isoc(struct dwc3_ep *dep)
>>   	int ret;
>>   	int i;
>>   
>> -	if (list_empty(&dep->pending_list)) {
>> +	if (list_empty(&dep->pending_list) &&
>> +	    list_empty(&dep->started_list)) {
>>   		dep->flags |= DWC3_EP_PENDING_REQUEST;
>>   		return -EAGAIN;
>>   	}
>> @@ -1429,6 +1430,27 @@ static int __dwc3_gadget_start_isoc(struct dwc3_ep *dep)
>>   			break;
>>   	}
>>   
>> +	/*
>> +	 * After a number of unsuccessful start attempts due to bus-expiry
>> +	 * status, issue END_TRANSFER command and retry on the next XferNotReady
>> +	 * event.
>> +	 */
>> +	if (ret == -EAGAIN) {
>> +		struct dwc3_gadget_ep_cmd_params params;
>> +		u32 cmd;
>> +
>> +		cmd = DWC3_DEPCMD_ENDTRANSFER |
>> +			DWC3_DEPCMD_CMDIOC |
>> +			DWC3_DEPCMD_PARAM(dep->resource_index);
>> +
>> +		dep->resource_index = 0;
>> +		memset(&params, 0, sizeof(params));
>> +
>> +		ret = dwc3_send_gadget_ep_cmd(dep, cmd, &params);
>> +		if (!ret)
>> +			dep->flags |= DWC3_EP_END_TRANSFER_PENDING;
>> +	}
> I like this! Pretty good idea :-) I'll wait for your reply to my
> question on the other patch, then start queueing again.
>

Great! I mentioned this awhile a go, but I didn't get to work on it 
until now. See https://marc.info/?l=linux-usb&m=156088170723824&w=4

Glad you're back, can you also take a look and queue the other fixes 
that I sent too. There are quite a few patches with these fix dependency 
in my queue that I want to push out.

Thanks,
Thinh
diff mbox series

Patch

diff --git a/drivers/usb/dwc3/gadget.c b/drivers/usb/dwc3/gadget.c
index f1aae4615cf1..a5ad02987536 100644
--- a/drivers/usb/dwc3/gadget.c
+++ b/drivers/usb/dwc3/gadget.c
@@ -1406,7 +1406,8 @@  static int __dwc3_gadget_start_isoc(struct dwc3_ep *dep)
 	int ret;
 	int i;
 
-	if (list_empty(&dep->pending_list)) {
+	if (list_empty(&dep->pending_list) &&
+	    list_empty(&dep->started_list)) {
 		dep->flags |= DWC3_EP_PENDING_REQUEST;
 		return -EAGAIN;
 	}
@@ -1429,6 +1430,27 @@  static int __dwc3_gadget_start_isoc(struct dwc3_ep *dep)
 			break;
 	}
 
+	/*
+	 * After a number of unsuccessful start attempts due to bus-expiry
+	 * status, issue END_TRANSFER command and retry on the next XferNotReady
+	 * event.
+	 */
+	if (ret == -EAGAIN) {
+		struct dwc3_gadget_ep_cmd_params params;
+		u32 cmd;
+
+		cmd = DWC3_DEPCMD_ENDTRANSFER |
+			DWC3_DEPCMD_CMDIOC |
+			DWC3_DEPCMD_PARAM(dep->resource_index);
+
+		dep->resource_index = 0;
+		memset(&params, 0, sizeof(params));
+
+		ret = dwc3_send_gadget_ep_cmd(dep, cmd, &params);
+		if (!ret)
+			dep->flags |= DWC3_EP_END_TRANSFER_PENDING;
+	}
+
 	return ret;
 }
 
@@ -2609,6 +2631,18 @@  static void dwc3_gadget_endpoint_transfer_not_ready(struct dwc3_ep *dep,
 		const struct dwc3_event_depevt *event)
 {
 	dwc3_gadget_endpoint_frame_from_event(dep, event);
+
+	/*
+	 * The XferNotReady event is generated only once before the endpoint
+	 * starts. It will be generated again when END_TRANSFER command is
+	 * issued. For some controller versions, the XferNotReady event may be
+	 * generated while the END_TRANSFER command is still in process. Ignore
+	 * it and wait for the next XferNotReady event after the command is
+	 * completed.
+	 */
+	if (dep->flags & DWC3_EP_END_TRANSFER_PENDING)
+		return;
+
 	(void) __dwc3_gadget_start_isoc(dep);
 }