From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-8.4 required=3.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH, MAILING_LIST_MULTI,SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED, USER_AGENT_SANE_1 autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 7CFD6C4CECD for ; Tue, 17 Sep 2019 19:45:05 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 492F02067B for ; Tue, 17 Sep 2019 19:45:05 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=chromium.org header.i=@chromium.org header.b="Gax5dwca" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726353AbfIQTpE (ORCPT ); Tue, 17 Sep 2019 15:45:04 -0400 Received: from mail-pg1-f193.google.com ([209.85.215.193]:35708 "EHLO mail-pg1-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725862AbfIQTpE (ORCPT ); Tue, 17 Sep 2019 15:45:04 -0400 Received: by mail-pg1-f193.google.com with SMTP id a24so2556299pgj.2 for ; Tue, 17 Sep 2019 12:45:03 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to:user-agent; bh=Tgg2KV4/EfN+uMmiVDhI108boK8SBjqK7o3+PbMCrCI=; b=Gax5dwcaedmEQcUPRLs3NtZVA81kF/AfrQ45bLDX1BwPZ21Ler+XLbfh4zFY9jr6k7 nSMFXqsSY3Eu/Ff9B3tIad+HkZbIxfIFxcrpCD2/1sAjrg/JK/JM0SnvVHv7a9yJTEwT XeRLeOd0sl+4ky4EPSysETsBbBLoeTIRzGiuk= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to:user-agent; bh=Tgg2KV4/EfN+uMmiVDhI108boK8SBjqK7o3+PbMCrCI=; b=lY9KtWb12cHT0CxMX1Uf/AyUfveFedEoRa4cq1gAkvOo+2Vt2iVtDfFcw88tGZpHv/ hM/p6fY2xcgi7jsJTlU0L1Iniz1NhyT10jwMuC0PCUVpz3UCWWf8n+ILxs4hyLFn9txG OzxAL/IjD8+FrCVys89kKELeu6lkpFbB5HOwwURpkdrZ7RRKhO7dyvGkH2ul7XLZHQwd TUcN+LIChU3FALPdsvuVh/evT2E0SCG2PABaORP7+BSyTyxunfzLgQsOn0TMlDREpNRq XeyGCtEjw1JBAwA2uM1pp5rk42zzkgJOBS5IuY8xVx3seeEdjlNJB6k/7Oz3s8dEHsiV rsDw== X-Gm-Message-State: APjAAAVzhbJjnfcG9MNAUge+W8kGUdA++CcAyEAQGKsnypLTNzNesy3j ddkJYe2Yk893irtwZT6cFC/ZFA== X-Google-Smtp-Source: APXvYqwrZzEmLy6eO6PsNKzFBDcGp2OXEi0+GJ13UPfgamTyrLgYSPrOjFB9fJ4t+9h46xvAnPZClA== X-Received: by 2002:a65:5309:: with SMTP id m9mr510537pgq.266.1568749503244; Tue, 17 Sep 2019 12:45:03 -0700 (PDT) Received: from localhost ([2620:15c:202:1:75a:3f6e:21d:9374]) by smtp.gmail.com with ESMTPSA id 31sm3435103pgr.55.2019.09.17.12.45.01 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Tue, 17 Sep 2019 12:45:01 -0700 (PDT) Date: Tue, 17 Sep 2019 12:44:59 -0700 From: Matthias Kaehlcke To: Chandana Kishori Chiluveru Cc: balbi@kernel.org, agross@kernel.org, david.brown@linaro.org, linux-usb@vger.kernel.org, linux-arm-msm@vger.kernel.org Subject: Re: [PATCH V3 2/3] usb: dwc3: qcom: Add interconnect support in dwc3 driver Message-ID: <20190917194459.GK133864@google.com> References: <1568718649-20124-1-git-send-email-cchiluve@codeaurora.org> <1568718649-20124-3-git-send-email-cchiluve@codeaurora.org> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline In-Reply-To: <1568718649-20124-3-git-send-email-cchiluve@codeaurora.org> User-Agent: Mutt/1.10.1 (2018-07-13) Sender: linux-usb-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-usb@vger.kernel.org On Tue, Sep 17, 2019 at 04:40:48PM +0530, Chandana Kishori Chiluveru wrote: > Add interconnect support in dwc3-qcom driver to vote for bus > bandwidth. > > This requires for two different paths - from USB master to > DDR slave. The other is from APPS master to USB slave. > > Signed-off-by: Chandana Kishori Chiluveru > --- > drivers/usb/dwc3/dwc3-qcom.c | 145 ++++++++++++++++++++++++++++++++++++++++++- > 1 file changed, 143 insertions(+), 2 deletions(-) > > diff --git a/drivers/usb/dwc3/dwc3-qcom.c b/drivers/usb/dwc3/dwc3-qcom.c > index 184df4d..2a2f5af 100644 > --- a/drivers/usb/dwc3/dwc3-qcom.c > +++ b/drivers/usb/dwc3/dwc3-qcom.c > > ... > > +/** > + * dwc3_qcom_interconnect_init() - Get interconnect path handles nit: "Initialize the interconnect" or similar? > + * @qcom: Pointer to the concerned usb core. > + * > + */ > +static int dwc3_qcom_interconnect_init(struct dwc3_qcom *qcom) > +{ > + struct device *dev = qcom->dev; > + int ret; > + > + qcom->usb_ddr_icc_path = of_icc_get(dev, "usb-ddr"); > + if (IS_ERR(qcom->usb_ddr_icc_path)) { > + dev_err(dev, "Error: (%ld) failed getting usb-ddr path\n", > + PTR_ERR(qcom->usb_ddr_icc_path)); > + return PTR_ERR(qcom->usb_ddr_icc_path); > + } > + > + qcom->apps_usb_icc_path = of_icc_get(dev, "apps-usb"); > + if (IS_ERR(qcom->apps_usb_icc_path)) { > + dev_err(dev, "Error: (%ld) failed getting apps-usb path\n", > + PTR_ERR(qcom->apps_usb_icc_path)); > + return PTR_ERR(qcom->apps_usb_icc_path); > + } > + > + ret = dwc3_qcom_interconnect_enable(qcom); > + if (ret) { > + dev_err(dev, "failed to enable interconnect %d\n", ret); nit: 'interconnect: %d', otherwise the message could be read as 'failed to enable interconnect number N'. > + return ret; > + } > + > + return 0; > +} > + > +/** > + * dwc3_qcom_interconnect_exit() - Release interconnect path handles > + * @qcom: Pointer to the concerned usb core. > + * > + * This function is used to release interconnect path handle. > + */ > +static void dwc3_qcom_interconnect_exit(struct dwc3_qcom *qcom) > +{ > + icc_put(qcom->usb_ddr_icc_path); > + icc_put(qcom->apps_usb_icc_path); > +} > + > +/* Currently we only use bandwidth level, so just "enable" interconnects */ > +static int dwc3_qcom_interconnect_enable(struct dwc3_qcom *qcom) > +{ > + struct dwc3 *dwc; > + int ret; > + > + dwc = platform_get_drvdata(qcom->dwc3); > + if (!dwc) { > + dev_err(qcom->dev, "Failed to get dwc3 device\n"); > + return -EPROBE_DEFER; > + } I understand the need for the/some check (see https://patchwork.kernel.org/patch/11146903/#22885491 and my reply), but I'm not convinced it should be done here. The function can be called from other contexts than _probe(), so returning -EPROBE_DEFER seems wrong, although I understand that you want _probe() to return this value. I would suggest to do this (or another) check early in _probe(). Returning -EPROBE_DEFER from that context makes sense, and it should be the only time the check is actually needed. As commented on v2 I don't particularly like the idea of using a half initialized struct (dwc3), even more when what is initialized or not varies at runtime (since dwc3_probe() and qwc3_qcom_probe() appear to run in parallel). IIUC device_is_bound() returns true when a device is fully initialized (i.e. it's _probe() completed), I'd suggest to evaluate to use it instead of checking the drvdata. In this case the drvdata check should be ok, but in general these kind of races don't seem a good idea, maybe tomorrow someone wants to access another struct member, which isn't always initialized. Others: please correct me if using half-initialized structs is routine in kernel drivers or device_is_bound() is the wrong tool. > + > + if (dwc->maximum_speed == USB_SPEED_SUPER) { > + ret = icc_set_bw(qcom->usb_ddr_icc_path, > + USB_MEMORY_AVG_SS_BW, USB_MEMORY_PEAK_SS_BW); > + if (ret) > + return ret; > + } else { > + ret = icc_set_bw(qcom->usb_ddr_icc_path, > + USB_MEMORY_AVG_HS_BW, USB_MEMORY_PEAK_HS_BW); > + if (ret) > + return ret; > + } > + > + ret = icc_set_bw(qcom->apps_usb_icc_path, > + APPS_USB_AVG_BW, APPS_USB_PEAK_BW); > + if (ret) > + goto err_disable_mem_path; > + > + return 0; > + > +err_disable_mem_path: > + icc_set_bw(qcom->usb_ddr_icc_path, 0, 0); > + > + return ret; > +} > + > +/* To disable an interconnect, we just set its bandwidth to 0 */ > +static int dwc3_qcom_interconnect_disable(struct dwc3_qcom *qcom) > +{ > + struct dwc3 *dwc = platform_get_drvdata(qcom->dwc3); > + int ret; > + > + ret = icc_set_bw(qcom->usb_ddr_icc_path, 0, 0); > + if (ret) > + return ret; > + > + ret = icc_set_bw(qcom->apps_usb_icc_path, 0, 0); > + if (ret) > + goto err_reenable_memory_path; > + > + return 0; > + > + /* Re-enable things in the event of an error */ > +err_reenable_memory_path: > + if (dwc->maximum_speed == USB_SPEED_SUPER) > + icc_set_bw(qcom->usb_ddr_icc_path, > + USB_MEMORY_AVG_SS_BW, USB_MEMORY_PEAK_SS_BW); > + else > + icc_set_bw(qcom->usb_ddr_icc_path, > + USB_MEMORY_AVG_HS_BW, USB_MEMORY_PEAK_HS_BW); This is essentially the same as in _interconnect_enable(). You could consider a helper function (inline?) for 'enabling' the memory path, which would make things more compact and also allow to get rid of the goto: if (ret) qcom_dwc3_interconnect_enable_mempath(qcom); return ret; > + > + return ret; > +} > + > static irqreturn_t qcom_dwc3_resume_irq(int irq, void *data) > { > struct dwc3_qcom *qcom = data; > @@ -494,6 +626,12 @@ static int dwc3_qcom_probe(struct platform_device *pdev) > goto depopulate; > } > > + ret = dwc3_qcom_interconnect_init(qcom); > + if (ret) { > + dev_err(dev, "failed to init interconnect handles %d\n", ret); nit: remove 'handles' (and add ':' before the error code), it's an implementation detail, and now _icc_init() also calls _icc_enable(), hence it's not only the handles.