All of lore.kernel.org
 help / color / mirror / Atom feed
From: Peter Chen <peter.chen@oss.qualcomm.com>
To: Krishna Kurapati <krishna.kurapati@oss.qualcomm.com>
Cc: Thinh Nguyen <Thinh.Nguyen@synopsys.com>,
	Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
	Pratham Pratap <pratham.pratap@oss.qualcomm.com>,
	Jack Pham <jack.pham@oss.qualcomm.com>,
	Wesley Cheng <wesley.cheng@oss.qualcomm.com>,
	linux-arm-msm@vger.kernel.org, linux-usb@vger.kernel.org,
	linux-kernel@vger.kernel.org
Subject: Re: [PATCH RFC 2/2] usb: dwc3: qcom: Vote ICC DDR bandwidth based on connected device speed
Date: Tue, 1 Dec 2026 19:35:08 -0800	[thread overview]
Message-ID: <aw-R7DINHX119b3f@hu-petche-lv.qualcomm.com> (raw)
In-Reply-To: <20261130-dynamic-icc-voting-v1-2-1a05a5320adc@oss.qualcomm.com>

On 26-11-30 23:11:13, Krishna Kurapati wrote:
> In host mode the actual transfer speed is not known at probe time. The
> DDR interconnect bandwidth has historically been voted at the maximum
> (SuperSpeed) value unconditionally,

No unconditionally, just according to static max_speed.
       
> +static bool dwc3_qcom_is_ss_rhport_connected(struct dwc3_qcom *qcom)
> +{
> +	struct dwc3 *dwc = &qcom->dwc;
> +	struct xhci_hcd *xhci;
> +	struct usb_hcd *hcd;
> +	unsigned int i;
> +	u32 portsc;
> +
> +	if (!dwc->xhci)
> +		return false;
> +
> +	hcd = platform_get_drvdata(dwc->xhci);
> +	xhci = hcd_to_xhci(hcd);
> +
> +	for (i = 0; i < xhci->usb3_rhub.num_ports; i++) {
> +		portsc = xhci_portsc_readl(xhci->usb3_rhub.ports[i]);
> +		if ((portsc & PORT_CONNECT) && DEV_SUPERSPEED_ANY(portsc))
> +			return true;
> +	}
> +
> +	return false;
> +}

There is a similar API: dwc3_qcom_read_usb2_speed, would you modify it and for getting
all speed usage?

Besides, please check Bot's comments.

Peter

> +
> +static int dwc3_qcom_host_notifier(struct notifier_block *nb,
> +				   unsigned long event, void *ptr)
> +{
> +	struct dwc3_qcom *qcom = container_of(nb, struct dwc3_qcom, host_nb);
> +	struct dwc3 *dwc = &qcom->dwc;
> +	struct usb_device *udev = ptr;
> +	struct usb_bus *ubus = ptr;
> +
> +	if (!dwc || !dwc->xhci)
> +		return NOTIFY_DONE;
> +
> +	if (event == USB_DEVICE_ADD || event == USB_DEVICE_REMOVE)
> +		ubus = udev->bus;
> +
> +	if (strcmp(dev_name(ubus->sysdev), dev_name(dwc->sysdev)) != 0)
> +		return NOTIFY_DONE;
> +
> +	if (event != USB_DEVICE_ADD && event != USB_DEVICE_REMOVE)
> +		return NOTIFY_DONE;
> +
> +	/*
> +	 * For direct-attach devices, new udev is direct child of root hub
> +	 * i.e. dwc -> xhci -> root_hub -> udev
> +	 * root_hub's udev->parent==NULL, so traverse struct device hierarchy
> +	 */
> +	if (udev->parent && !udev->parent->parent &&
> +			udev->dev.parent->parent == &dwc->xhci->dev) {
> +		if (event == USB_DEVICE_ADD) {
> +			if (!dwc3_qcom_is_ss_rhport_connected(qcom)) {
> +				dwc3_qcom_interconnect_set_ddr_bw(qcom,
> +							USB_SPEED_HIGH);
> +
> +			} else {
> +				dwc3_qcom_interconnect_set_ddr_bw(qcom,
> +							USB_SPEED_SUPER);
> +			}
> +		} else {
> +			dwc3_qcom_interconnect_set_ddr_bw(qcom,
> +						USB_SPEED_UNKNOWN);
> +		}
> +	}
> +
> +	return NOTIFY_DONE;
> +}
> +
>  static void dwc3_qcom_set_role_notifier(struct dwc3 *dwc, enum usb_role next_role)
>  {
>  	struct dwc3_qcom *qcom = to_dwc3_qcom(dwc);
> @@ -617,6 +689,13 @@ static void dwc3_qcom_set_role_notifier(struct dwc3 *dwc, enum usb_role next_rol
>  	pm_runtime_mark_last_busy(qcom->dev);
>  	pm_runtime_put_sync(qcom->dev);
>  
> +	if (next_role == USB_ROLE_HOST) {
> +		qcom->host_nb.notifier_call = dwc3_qcom_host_notifier;
> +		usb_register_notify(&qcom->host_nb);
> +	} else if (qcom->current_role == USB_ROLE_HOST) {
> +		usb_unregister_notify(&qcom->host_nb);
> +	}
> +
>  	/*
>  	 * Current role changes via usb_role_switch_set_role callback protected
>  	 * internally by mutex lock.
> @@ -749,8 +828,12 @@ static int dwc3_qcom_probe(struct platform_device *pdev)
>  			qcom->current_role = USB_ROLE_DEVICE;
>  	}
>  
> -	qcom->dwc.glue_ops = &dwc3_qcom_glue_ops;
> +	if (qcom->current_role == USB_ROLE_HOST) {
> +		qcom->host_nb.notifier_call = dwc3_qcom_host_notifier;
> +		usb_register_notify(&qcom->host_nb);
> +	}
>  
> +	qcom->dwc.glue_ops = &dwc3_qcom_glue_ops;
>  	qcom->dwc.dev = dev;
>  	probe_data.dwc = &qcom->dwc;
>  	probe_data.res = &res;
> @@ -789,6 +872,9 @@ static void dwc3_qcom_remove(struct platform_device *pdev)
>  	if (pm_runtime_resume_and_get(qcom->dev) < 0)
>  		return;
>  
> +	if (qcom->current_role == USB_ROLE_HOST)
> +		usb_unregister_notify(&qcom->host_nb);
> +
>  	dwc3_core_remove(&qcom->dwc);
>  	clk_bulk_disable_unprepare(qcom->num_clocks, qcom->clks);
>  	dwc3_qcom_interconnect_exit(qcom);
> 
> -- 
> 2.34.1
> 

-- 

Thanks,
Peter Chen

  parent reply	other threads:[~2026-12-02  3:35 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-30 17:41 [PATCH RFC 0/2] Support dynamic icc voting based on negotiated usb speed Krishna Kurapati
2026-11-30 17:41 ` [PATCH RFC 1/2] usb: dwc3: qcom: Refactor DDR ICC bandwidth setting into helper Krishna Kurapati
2026-11-30 17:41 ` [PATCH RFC 2/2] usb: dwc3: qcom: Vote ICC DDR bandwidth based on connected device speed Krishna Kurapati
2026-11-30 18:01   ` sashiko-bot
2026-12-01 17:58   ` Val Packett
2026-12-01 18:21     ` Krishna Kurapati
2026-12-02  2:43       ` Peter Chen
2026-12-02  3:35   ` Peter Chen [this message]
2026-11-30 18:01 ` [PATCH RFC 0/2] Support dynamic icc voting based on negotiated usb speed sashiko-bot

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=aw-R7DINHX119b3f@hu-petche-lv.qualcomm.com \
    --to=peter.chen@oss.qualcomm.com \
    --cc=Thinh.Nguyen@synopsys.com \
    --cc=gregkh@linuxfoundation.org \
    --cc=jack.pham@oss.qualcomm.com \
    --cc=krishna.kurapati@oss.qualcomm.com \
    --cc=linux-arm-msm@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-usb@vger.kernel.org \
    --cc=pratham.pratap@oss.qualcomm.com \
    --cc=wesley.cheng@oss.qualcomm.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.