Re: [PATCH 4/4] usb: dwc3: gadget: always decrement by 1

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On 8/25/2016 12:38 AM, Felipe Balbi wrote:
> We need to decrement in both cases (enq > deq and
> enq < deq)
> 
> Signed-off-by: Felipe Balbi <felipe.balbi@xxxxxxxxxxxxxxx>
> ---
>  drivers/usb/dwc3/gadget.c | 5 +----
>  1 file changed, 1 insertion(+), 4 deletions(-)
> 
> diff --git a/drivers/usb/dwc3/gadget.c b/drivers/usb/dwc3/gadget.c
> index 594e82595634..e4ef9ed1a143 100644
> --- a/drivers/usb/dwc3/gadget.c
> +++ b/drivers/usb/dwc3/gadget.c
> @@ -884,12 +884,9 @@ static u32 dwc3_calc_trbs_left(struct dwc3_ep *dep)
>  		return DWC3_TRB_NUM - 1;
>  	}
>  
> -	trbs_left = dep->trb_dequeue - dep->trb_enqueue;
> +	trbs_left = dep->trb_dequeue - dep->trb_enqueue - 1;
>  	trbs_left &= (DWC3_TRB_NUM - 1);
>  
> -	if (dep->trb_dequeue < dep->trb_enqueue)
> -		trbs_left--;
> -
>  	return trbs_left;
>  }
>  
> 

Hi Felipe,

I don't think that's right.

The decrement is accounting for the fact that the link TRB is taking
up one of the free spots. That is only the case when the deq < enq.

See the examples below to illustrate this


Example 1 (DWC3_TRB_NUM = 8): After the initial state of the ring,
queue on TRB.

0: TRB <- deq
1: empty <- enq
2: empty
3: empty
4: empty
5: empty
6: empty
7: LINK TRB

enq=1, deq=0

num_free =>
(deq - enq) % DWC3_TRB_NUM =>
(0 - 1) % 8 =>
0xffffffff % 8 =>
7 slots free

One of the free slots is take up by link trb so decrement by 1:

7 - 1 => 6 slots free


Example 2 (DWC3_TRB_NUM = 8): The enqueue pointer has wrapped around
and started enqueue from the beginning of the ring again, but the
dequeue pointer hasn't wrapped yet.

0: TRB
1: empty <- enq
2: empty
3: empty
4: TRB <- deq
5: TRB
6: TRB
7: LINK TRB

enq = 1, deq = 4

num_free =>
(deq - enq) % DWC3_TRB_NUM =>
(4 - 1) % 8 =>
3 slots free

No need to decrement by 1.

Regards,
John
--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html



[Index of Archives]     [Linux Media]     [Linux Input]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]     [Old Linux USB Devel Archive]

  Powered by Linux