From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752242AbdK3Jnv convert rfc822-to-8bit (ORCPT ); Thu, 30 Nov 2017 04:43:51 -0500 Received: from smtprelay.synopsys.com ([198.182.47.9]:36392 "EHLO smtprelay.synopsys.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751885AbdK3Jnt (ORCPT ); Thu, 30 Nov 2017 04:43:49 -0500 From: Minas Harutyunyan To: Amelie Delaunay , John Youn , Felipe Balbi , Greg Kroah-Hartman CC: "linux-usb@vger.kernel.org" , "linux-kernel@vger.kernel.org" Subject: Re: [PATCH] usb: dwc2: gadget: fix dwc2_check_param_tx_fifo_sizes Thread-Topic: [PATCH] usb: dwc2: gadget: fix dwc2_check_param_tx_fifo_sizes Thread-Index: AQHTZ43iDJjL9wCywUSjeVEUwQztPw== Date: Thu, 30 Nov 2017 09:43:01 +0000 Message-ID: <410670D7E743164D87FA6160E7907A560113A451C0@am04wembxa.internal.synopsys.com> References: <1511793691-6325-1-git-send-email-amelie.delaunay@st.com> Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-originating-ip: [10.116.70.92] Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 8BIT MIME-Version: 1.0 Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 > --- > 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