linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] usb: dwc2: gadget: fix dwc2_check_param_tx_fifo_sizes
@ 2017-11-27 14:41 Amelie Delaunay
  2017-11-30  9:43 ` Minas Harutyunyan
  0 siblings, 1 reply; 3+ messages in thread
From: Amelie Delaunay @ 2017-11-27 14:41 UTC (permalink / raw)
  To: John Youn, Felipe Balbi, Greg Kroah-Hartman
  Cc: linux-usb, linux-kernel, Amelie Delaunay

In case of OTG mode, with an OTG adapter plugged, the
dwc2_check_param_tx_fifo_sizes function reads DPTXFSIZN registers while
the controller is in Host mode, and, because DPTXFSIZN registers are
Device specific registers, the values read are 0.
Then, g_tx_fifo_size[fifo] values are considered invalid because in the
comparison test, they need to be greater than min and lower than dptxfszn
which is 0.
To fix this issue, force the controller in device mode if needed before
reading the DPTXFSIZN registers, and restore the previous mode if needed
after reading.

Fixes: 3c6aea7344c3 ("usb: dwc2: gadget: Add checking for g-tx-fifo-size
parameter")
Signed-off-by: Amelie Delaunay <amelie.delaunay@st.com>
---
 drivers/usb/dwc2/params.c | 10 ++++++++++
 1 file changed, 10 insertions(+)

diff --git a/drivers/usb/dwc2/params.c b/drivers/usb/dwc2/params.c
index ef73af6..302fefb 100644
--- a/drivers/usb/dwc2/params.c
+++ b/drivers/usb/dwc2/params.c
@@ -469,6 +469,7 @@ static void dwc2_check_param_tx_fifo_sizes(struct dwc2_hsotg *hsotg)
 	int fifo;
 	int min;
 	u32 total = 0;
+	bool forced;
 	u32 dptxfszn;
 
 	fifo_count = dwc2_hsotg_tx_fifo_count(hsotg);
@@ -483,6 +484,12 @@ static void dwc2_check_param_tx_fifo_sizes(struct dwc2_hsotg *hsotg)
 		dwc2_set_param_tx_fifo_sizes(hsotg);
 	}
 
+	/*
+	 * Reading DPTXFSIZN registers requires the controller to be in device
+	 * mode. The mode will be forced, if necessary, to read these values.
+	 */
+	forced = dwc2_force_mode_if_needed(hsotg, false);
+
 	for (fifo = 1; fifo <= fifo_count; fifo++) {
 		dptxfszn = (dwc2_readl(hsotg->regs + DPTXFSIZN(fifo)) &
 			FIFOSIZE_DEPTH_MASK) >> FIFOSIZE_DEPTH_SHIFT;
@@ -495,6 +502,9 @@ static void dwc2_check_param_tx_fifo_sizes(struct dwc2_hsotg *hsotg)
 			hsotg->params.g_tx_fifo_size[fifo] = dptxfszn;
 		}
 	}
+
+	if (forced)
+		dwc2_clear_force_mode(hsotg);
 }
 
 #define CHECK_RANGE(_param, _min, _max, _def) do {			\
-- 
2.7.4

^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH] usb: dwc2: gadget: fix dwc2_check_param_tx_fifo_sizes
  2017-11-27 14:41 [PATCH] usb: dwc2: gadget: fix dwc2_check_param_tx_fifo_sizes Amelie Delaunay
@ 2017-11-30  9:43 ` Minas Harutyunyan
  2017-11-30 13:12   ` Amelie DELAUNAY
  0 siblings, 1 reply; 3+ messages in thread
From: Minas Harutyunyan @ 2017-11-30  9:43 UTC (permalink / raw)
  To: Amelie Delaunay, John Youn, Felipe Balbi, Greg Kroah-Hartman
  Cc: linux-usb, linux-kernel

Hi Amelie,

On 11/27/2017 6:42 PM, Amelie Delaunay wrote:
> In case of OTG mode, with an OTG adapter plugged, the
> dwc2_check_param_tx_fifo_sizes function reads DPTXFSIZN registers while
> the controller is in Host mode, and, because DPTXFSIZN registers are
> Device specific registers, the values read are 0.
> Then, g_tx_fifo_size[fifo] values are considered invalid because in the
> comparison test, they need to be greater than min and lower than dptxfszn
> which is 0.
> To fix this issue, force the controller in device mode if needed before
> reading the DPTXFSIZN registers, and restore the previous mode if needed
> after reading.
> 
> Fixes: 3c6aea7344c3 ("usb: dwc2: gadget: Add checking for g-tx-fifo-size
> parameter")
> Signed-off-by: Amelie Delaunay <amelie.delaunay@st.com>
> ---
>   drivers/usb/dwc2/params.c | 10 ++++++++++
>   1 file changed, 10 insertions(+)
> 
> diff --git a/drivers/usb/dwc2/params.c b/drivers/usb/dwc2/params.c
> index ef73af6..302fefb 100644
> --- a/drivers/usb/dwc2/params.c
> +++ b/drivers/usb/dwc2/params.c
> @@ -469,6 +469,7 @@ static void dwc2_check_param_tx_fifo_sizes(struct dwc2_hsotg *hsotg)
>   	int fifo;
>   	int min;
>   	u32 total = 0;
> +	bool forced;
>   	u32 dptxfszn;
>   
>   	fifo_count = dwc2_hsotg_tx_fifo_count(hsotg);
> @@ -483,6 +484,12 @@ static void dwc2_check_param_tx_fifo_sizes(struct dwc2_hsotg *hsotg)
>   		dwc2_set_param_tx_fifo_sizes(hsotg);
>   	}
>   
> +	/*
> +	 * Reading DPTXFSIZN registers requires the controller to be in device
> +	 * mode. The mode will be forced, if necessary, to read these values.
> +	 */
> +	forced = dwc2_force_mode_if_needed(hsotg, false);
> +
>   	for (fifo = 1; fifo <= fifo_count; fifo++) {
>   		dptxfszn = (dwc2_readl(hsotg->regs + DPTXFSIZN(fifo)) &
>   			FIFOSIZE_DEPTH_MASK) >> FIFOSIZE_DEPTH_SHIFT;
> @@ -495,6 +502,9 @@ static void dwc2_check_param_tx_fifo_sizes(struct dwc2_hsotg *hsotg)
>   			hsotg->params.g_tx_fifo_size[fifo] = dptxfszn;
>   		}
>   	}
> +
> +	if (forced)
> +		dwc2_clear_force_mode(hsotg);
>   }
>   
>   #define CHECK_RANGE(_param, _min, _max, _def) do {			\
> 

I'll recommend to use "[PATCH] usb: dwc2: Fix TxFIFOn sizes and total 
TxFIFO size issues" instead.

Thanks,
Minas

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] usb: dwc2: gadget: fix dwc2_check_param_tx_fifo_sizes
  2017-11-30  9:43 ` Minas Harutyunyan
@ 2017-11-30 13:12   ` Amelie DELAUNAY
  0 siblings, 0 replies; 3+ messages in thread
From: Amelie DELAUNAY @ 2017-11-30 13:12 UTC (permalink / raw)
  To: Minas Harutyunyan, John Youn, Felipe Balbi, Greg Kroah-Hartman
  Cc: linux-usb, linux-kernel

Hi Minas,

On 11/30/2017 10:43 AM, Minas Harutyunyan wrote:
> Hi Amelie,
> 
> On 11/27/2017 6:42 PM, Amelie Delaunay wrote:
>> In case of OTG mode, with an OTG adapter plugged, the
>> dwc2_check_param_tx_fifo_sizes function reads DPTXFSIZN registers while
>> the controller is in Host mode, and, because DPTXFSIZN registers are
>> Device specific registers, the values read are 0.
>> Then, g_tx_fifo_size[fifo] values are considered invalid because in the
>> comparison test, they need to be greater than min and lower than dptxfszn
>> which is 0.
>> To fix this issue, force the controller in device mode if needed before
>> reading the DPTXFSIZN registers, and restore the previous mode if needed
>> after reading.
>>
>> Fixes: 3c6aea7344c3 ("usb: dwc2: gadget: Add checking for g-tx-fifo-size
>> parameter")
>> Signed-off-by: Amelie Delaunay <amelie.delaunay@st.com>
>> ---
>>    drivers/usb/dwc2/params.c | 10 ++++++++++
>>    1 file changed, 10 insertions(+)
>>
>> diff --git a/drivers/usb/dwc2/params.c b/drivers/usb/dwc2/params.c
>> index ef73af6..302fefb 100644
>> --- a/drivers/usb/dwc2/params.c
>> +++ b/drivers/usb/dwc2/params.c
>> @@ -469,6 +469,7 @@ static void dwc2_check_param_tx_fifo_sizes(struct dwc2_hsotg *hsotg)
>>    	int fifo;
>>    	int min;
>>    	u32 total = 0;
>> +	bool forced;
>>    	u32 dptxfszn;
>>    
>>    	fifo_count = dwc2_hsotg_tx_fifo_count(hsotg);
>> @@ -483,6 +484,12 @@ static void dwc2_check_param_tx_fifo_sizes(struct dwc2_hsotg *hsotg)
>>    		dwc2_set_param_tx_fifo_sizes(hsotg);
>>    	}
>>    
>> +	/*
>> +	 * Reading DPTXFSIZN registers requires the controller to be in device
>> +	 * mode. The mode will be forced, if necessary, to read these values.
>> +	 */
>> +	forced = dwc2_force_mode_if_needed(hsotg, false);
>> +
>>    	for (fifo = 1; fifo <= fifo_count; fifo++) {
>>    		dptxfszn = (dwc2_readl(hsotg->regs + DPTXFSIZN(fifo)) &
>>    			FIFOSIZE_DEPTH_MASK) >> FIFOSIZE_DEPTH_SHIFT;
>> @@ -495,6 +502,9 @@ static void dwc2_check_param_tx_fifo_sizes(struct dwc2_hsotg *hsotg)
>>    			hsotg->params.g_tx_fifo_size[fifo] = dptxfszn;
>>    		}
>>    	}
>> +
>> +	if (forced)
>> +		dwc2_clear_force_mode(hsotg);
>>    }
>>    
>>    #define CHECK_RANGE(_param, _min, _max, _def) do {			\
>>
> 
> I'll recommend to use "[PATCH] usb: dwc2: Fix TxFIFOn sizes and total
> TxFIFO size issues" instead.

I've tested your patch and it fixes the issue too. Thank you for warning 
me of the existence of this patch. Mine can be dropped.

Regards,
Amelie
> 
> Thanks,
> Minas
> 

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2017-11-30 13:13 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-11-27 14:41 [PATCH] usb: dwc2: gadget: fix dwc2_check_param_tx_fifo_sizes Amelie Delaunay
2017-11-30  9:43 ` Minas Harutyunyan
2017-11-30 13:12   ` Amelie DELAUNAY

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).