* Re: [PATCH RFC 2/2] usb: dwc3: qcom: Vote ICC DDR bandwidth based on connected device speed
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-02 3:35 ` Peter Chen
2 siblings, 0 replies; 9+ messages in thread
From: sashiko-bot @ 2026-11-30 18:01 UTC (permalink / raw)
To: Krishna Kurapati; +Cc: linux-usb
Thank you for your contribution! Sashiko AI review found 5 potential
issues to consider:
- [High] usb: dwc3: qcom: link failure when CONFIG_USB or
CONFIG_USB_XHCI_HCD is disabled
- [High] usb: dwc3: qcom: use-after-free of host_nb on dwc3_qcom_probe()
error paths
- [Medium] usb: dwc3: qcom: USB_DEVICE_REMOVE votes SuperSpeed DDR bw in
dwc3_qcom_host_notifier()
- [Medium] usb: dwc3: qcom: broken host_nb lifecycle and DDR bw
restoration on role switch
- [Medium] usb: dwc3: qcom: host_nb teardown race and leak in
dwc3_qcom_remove()
--
commit ce9731ed7069be9723645845ce1017e310a2280b
Author: Krishna Kurapati <krishna.kurapati@oss.qualcomm.com>
usb: dwc3: qcom: Vote ICC DDR bandwidth based on connected device speed
This commit registers a USB bus notifier in host mode to vote DDR
interconnect bandwidth according to whether a SuperSpeed device is
connected to the DWC3 root hub.
> diff --git a/drivers/usb/dwc3/dwc3-qcom.c b/drivers/usb/dwc3/dwc3-qcom.c
> index 52ec7a0709ef4..fdec21b304206 100644
> --- a/drivers/usb/dwc3/dwc3-qcom.c
> +++ b/drivers/usb/dwc3/dwc3-qcom.c
> @@ -21,6 +21,9 @@
> #include <linux/usb.h>
> #include "core.h"
> #include "glue.h"
> +#include "../host/xhci.h"
> +#include "../host/xhci-port.h"
> +#include "../host/xhci-caps.h"
[ ... ]
> @@ -597,6 +601,74 @@ static int dwc3_qcom_setup_irq(struct dwc3_qcom *qcom, struct platform_device *p
> return 0;
> }
>
> +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;
> +}
[Severity: High]
Does this break linking when CONFIG_USB or CONFIG_USB_XHCI_HCD is disabled,
or when CONFIG_USB_DWC3_QCOM is built-in with modular USB/xHCI?
CONFIG_USB_DWC3_QCOM can be built for gadget-only configurations (notice the
CONFIG_USB guard in dwc3_qcom_read_usb2_speed()). usb_register_notify(),
usb_unregister_notify(), and usb_hcd_is_primary_hcd() (via hcd_to_xhci())
have no stubs when CONFIG_USB is disabled, and xhci_portsc_readl() has no
stub when CONFIG_USB_XHCI_HCD is disabled.
Also, ../host/xhci-caps.h does not appear to be used in this file.
> +
> +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;
> +}
[Severity: Medium]
Does passing USB_SPEED_UNKNOWN on USB_DEVICE_REMOVE raise the DDR bandwidth
vote back to SuperSpeed instead of dropping it?
drivers/usb/dwc3/dwc3-qcom.c:dwc3_qcom_interconnect_set_ddr_bw() {
if (max_speed >= USB_SPEED_SUPER || max_speed == USB_SPEED_UNKNOWN)
ret = icc_set_bw(qcom->icc_path_ddr,
USB_MEMORY_AVG_SS_BW, USB_MEMORY_PEAK_SS_BW);
else
ret = icc_set_bw(qcom->icc_path_ddr,
USB_MEMORY_AVG_HS_BW, USB_MEMORY_PEAK_HS_BW);
}
Unplugging a Full-Speed or High-Speed device therefore votes SuperSpeed DDR
bandwidth while the bus is idle, including on controllers restricted to
maximum-speed = "high-speed" in Devicetree. On multi-port controllers or
when a USB 3.x hub disconnects one of its companion root-hub children, this
also overwrites the bandwidth vote without checking the remaining root-hub
ports.
> +
> 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)
[Severity: Medium]
When switching out of USB_ROLE_HOST after a Full/High-Speed host session,
does unregistering qcom->host_nb here leave the DDR bandwidth vote stuck at
USB_SPEED_HIGH for subsequent SuperSpeed device mode?
dwc3_qcom_set_role_notifier() runs as the .pre_set_role callback before
dwc3_set_mode() queues dwc->drd_work to run dwc3_host_exit(), so
qcom->host_nb is already unregistered when the root-hub devices are removed
and nothing restores qcom->icc_path_ddr to usb_get_maximum_speed(dwc->dev).
In addition, when dwc3_usb_role_switch_set() receives USB_ROLE_NONE with
role_switch_default_mode == USB_DR_MODE_HOST, it keeps the controller in
DWC3_GCTL_PRTCAP_HOST mode but passes USB_ROLE_NONE to dwc3_pre_set_role(),
which unregisters qcom->host_nb while still in host mode. Conversely, on
extcon OTG controllers booting with a host cable attached, dwc3_qcom_probe()
sets qcom->current_role = USB_ROLE_DEVICE and dwc3_drd_init() ->
dwc3_drd_update() enters host mode without calling dwc3_pre_set_role(), so
qcom->host_nb is never registered.
> 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;
[Severity: High]
If dwc3_core_probe() or dwc3_qcom_interconnect_init() fails (for example
with -EPROBE_DEFER), does dwc3_qcom_probe() return without unregistering
qcom->host_nb?
Because qcom is allocated with devm_kzalloc_obj(), probe failure frees qcom
while qcom->host_nb remains linked in usb_notifier_list, causing a
use-after-free on the next USB bus notification or probe retry. Moreover,
registering the notifier before dwc3_qcom_interconnect_init() means any
notification during dwc3_core_probe() or its remove_core error unwind can
call dwc3_qcom_interconnect_set_ddr_bw() while qcom->icc_path_ddr is NULL,
an ERR_PTR, or already released via icc_put().
> @@ -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);
[Severity: Medium]
Can qcom->host_nb remain registered in usb_notifier_list after
dwc3_qcom_remove() returns?
If pm_runtime_resume_and_get() fails, dwc3_qcom_remove() returns early
before usb_unregister_notify(&qcom->host_nb), and devm then frees qcom.
Even when runtime resume succeeds, dwc->role_sw and dwc->edev are not
unregistered until dwc3_core_remove() -> dwc3_core_exit_mode() ->
dwc3_drd_exit(), so a concurrent dwc3_qcom_set_role_notifier() can run
between usb_unregister_notify() and dwc3_core_remove() (or skip updating
qcom->current_role if its own pm_runtime_resume_and_get() fails) and leave
qcom->host_nb registered after qcom is freed.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261130-dynamic-icc-voting-v1-0-1a05a5320adc@oss.qualcomm.com?part=2
^ permalink raw reply [flat|nested] 9+ messages in thread* Re: [PATCH RFC 2/2] usb: dwc3: qcom: Vote ICC DDR bandwidth based on connected device speed
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 3:35 ` Peter Chen
2 siblings, 1 reply; 9+ messages in thread
From: Val Packett @ 2026-12-01 17:58 UTC (permalink / raw)
To: Krishna Kurapati, Thinh Nguyen, Greg Kroah-Hartman
Cc: Pratham Pratap, Jack Pham, Wesley Cheng, Peter Chen,
linux-arm-msm, linux-usb, linux-kernel
Hi,
On 11/30/26 2:41 PM, 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, wasting power when only a
> Full/High-Speed device is attached.
>
> Add a USB notifier that fires on USB_DEVICE_ADD / USB_DEVICE_REMOVE for
> devices directly attached to the DWC3 root hub. On addition, inspect
> all USB 3.x root-hub ports via xhci_portsc_readl(). If at least one
> SuperSpeed connection is active, vote SS bandwidth, otherwise vote HS
> bandwidth. On removal, drop the vote back to the idle/unknown level.
>
> [..]
> @@ -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;
> [..]
Seems like it might be registering with a NULL function ptr or something?
CONFIG_DEBUG_NOTIFIERS's `!func_ptr_is_kernel_text(nb->notifier_call)`
check fires when busses are probed upon booting:
[ 17.606811] xhci-hcd xhci-hcd.1.auto: xHCI Host Controller
[ 17.606825] ------------[ cut here ]------------
[ 17.606826] Invalid notifier called!
[ 17.606833] WARNING: kernel/notifier.c:80 at
notifier_call_chain+0x80/0x1b0, CPU#0: kworker/0:0/10
[ 17.607029] CPU: 0 UID: 0 PID: 10 Comm: kworker/0:0 Tainted: G W
7.4.0-rc5-next-20261130-uwu+ #250 PREEMPT(full)
[ 17.607034] Tainted: [W]=WARN
[ 17.607035] Hardware name: Dell Inc. Latitude 7455/0FK7MX, BIOS
2.13.0 09/19/2025
[ 17.607037] Workqueue: events_freezable __dwc3_set_mode
[ 17.607045] pstate: 61400009 (nZCv daif +PAN -UAO -TCO +DIT -SSBS
BTYPE=--)
[ 17.607091] Call trace:
[ 17.607093] notifier_call_chain+0x80/0x1b0 (P)
[ 17.607097] blocking_notifier_call_chain+0x4c/0x80
[ 17.607100] usb_notify_add_bus+0x28/0x40
[ 17.607105] usb_register_bus+0x88/0xb8
[ 17.607111] usb_add_hcd+0x144/0x4b0
[ 17.607115] xhci_plat_probe+0x4f4/0x6f0
...
Thanks,
~val
^ permalink raw reply [flat|nested] 9+ messages in thread* Re: [PATCH RFC 2/2] usb: dwc3: qcom: Vote ICC DDR bandwidth based on connected device speed
2026-12-01 17:58 ` Val Packett
@ 2026-12-01 18:21 ` Krishna Kurapati
2026-12-02 2:43 ` Peter Chen
0 siblings, 1 reply; 9+ messages in thread
From: Krishna Kurapati @ 2026-12-01 18:21 UTC (permalink / raw)
To: Val Packett
Cc: Thinh Nguyen, Greg Kroah-Hartman, Pratham Pratap, Jack Pham,
Wesley Cheng, Peter Chen, linux-arm-msm, linux-usb, linux-kernel
On 12/1/2026 11:28 PM, Val Packett wrote:
> Hi,
>
> On 11/30/26 2:41 PM, 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, wasting power when only a
>> Full/High-Speed device is attached.
>>
>> Add a USB notifier that fires on USB_DEVICE_ADD / USB_DEVICE_REMOVE for
>> devices directly attached to the DWC3 root hub. On addition, inspect
>> all USB 3.x root-hub ports via xhci_portsc_readl(). If at least one
>> SuperSpeed connection is active, vote SS bandwidth, otherwise vote HS
>> bandwidth. On removal, drop the vote back to the idle/unknown level.
>>
>> [..]
>> @@ -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;
>> [..]
>
> Seems like it might be registering with a NULL function ptr or something?
>
> CONFIG_DEBUG_NOTIFIERS's `!func_ptr_is_kernel_text(nb->notifier_call)`
> check fires when busses are probed upon booting:
>
>
> [ 17.606811] xhci-hcd xhci-hcd.1.auto: xHCI Host Controller
> [ 17.606825] ------------[ cut here ]------------
> [ 17.606826] Invalid notifier called!
> [ 17.606833] WARNING: kernel/notifier.c:80 at
> notifier_call_chain+0x80/0x1b0, CPU#0: kworker/0:0/10
> [ 17.607029] CPU: 0 UID: 0 PID: 10 Comm: kworker/0:0 Tainted: G W
> 7.4.0-rc5-next-20261130-uwu+ #250 PREEMPT(full)
> [ 17.607034] Tainted: [W]=WARN
> [ 17.607035] Hardware name: Dell Inc. Latitude 7455/0FK7MX, BIOS
> 2.13.0 09/19/2025
> [ 17.607037] Workqueue: events_freezable __dwc3_set_mode
> [ 17.607045] pstate: 61400009 (nZCv daif +PAN -UAO -TCO +DIT -SSBS
> BTYPE=--)
> [ 17.607091] Call trace:
> [ 17.607093] notifier_call_chain+0x80/0x1b0 (P)
> [ 17.607097] blocking_notifier_call_chain+0x4c/0x80
> [ 17.607100] usb_notify_add_bus+0x28/0x40
> [ 17.607105] usb_register_bus+0x88/0xb8
> [ 17.607111] usb_add_hcd+0x144/0x4b0
> [ 17.607115] xhci_plat_probe+0x4f4/0x6f0
>
I did hit a NULL ptr deref when I was testing this but i fixed it before
sending. I did test this on standalone (dr_mode==host) and
(dr_mode==otg). Will try to repro this particular crash and fix it
before sending next version. Thanks for reporting this.
Regards,
Krishna,
^ permalink raw reply [flat|nested] 9+ messages in thread* Re: [PATCH RFC 2/2] usb: dwc3: qcom: Vote ICC DDR bandwidth based on connected device speed
2026-12-01 18:21 ` Krishna Kurapati
@ 2026-12-02 2:43 ` Peter Chen
0 siblings, 0 replies; 9+ messages in thread
From: Peter Chen @ 2026-12-02 2:43 UTC (permalink / raw)
To: Krishna Kurapati
Cc: Val Packett, Thinh Nguyen, Greg Kroah-Hartman, Pratham Pratap,
Jack Pham, Wesley Cheng, linux-arm-msm, linux-usb, linux-kernel
On 26-12-01 23:51:17, Krishna Kurapati wrote:
>
>
> On 12/1/2026 11:28 PM, Val Packett wrote:
> > Hi,
> >
> > On 11/30/26 2:41 PM, 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, wasting power when only a
> > > Full/High-Speed device is attached.
> > >
> > > Add a USB notifier that fires on USB_DEVICE_ADD / USB_DEVICE_REMOVE for
> > > devices directly attached to the DWC3 root hub. On addition, inspect
> > > all USB 3.x root-hub ports via xhci_portsc_readl(). If at least one
> > > SuperSpeed connection is active, vote SS bandwidth, otherwise vote HS
> > > bandwidth. On removal, drop the vote back to the idle/unknown level.
> > >
> > > [..]
> > > @@ -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;
> > > [..]
> >
> > Seems like it might be registering with a NULL function ptr or something?
> >
> > CONFIG_DEBUG_NOTIFIERS's `!func_ptr_is_kernel_text(nb->notifier_call)`
> > check fires when busses are probed upon booting:
> >
> >
> > [ 17.606811] xhci-hcd xhci-hcd.1.auto: xHCI Host Controller
> > [ 17.606825] ------------[ cut here ]------------
> > [ 17.606826] Invalid notifier called!
> > [ 17.606833] WARNING: kernel/notifier.c:80 at
> > notifier_call_chain+0x80/0x1b0, CPU#0: kworker/0:0/10
> > [ 17.607029] CPU: 0 UID: 0 PID: 10 Comm: kworker/0:0 Tainted: G W
> > 7.4.0-rc5-next-20261130-uwu+ #250 PREEMPT(full)
> > [ 17.607034] Tainted: [W]=WARN
> > [ 17.607035] Hardware name: Dell Inc. Latitude 7455/0FK7MX, BIOS
> > 2.13.0 09/19/2025
> > [ 17.607037] Workqueue: events_freezable __dwc3_set_mode
> > [ 17.607045] pstate: 61400009 (nZCv daif +PAN -UAO -TCO +DIT -SSBS
> > BTYPE=--)
> > [ 17.607091] Call trace:
> > [ 17.607093] notifier_call_chain+0x80/0x1b0 (P)
> > [ 17.607097] blocking_notifier_call_chain+0x4c/0x80
> > [ 17.607100] usb_notify_add_bus+0x28/0x40
> > [ 17.607105] usb_register_bus+0x88/0xb8
> > [ 17.607111] usb_add_hcd+0x144/0x4b0
> > [ 17.607115] xhci_plat_probe+0x4f4/0x6f0
> >
> I did hit a NULL ptr deref when I was testing this but i fixed it before
> sending. I did test this on standalone (dr_mode==host) and (dr_mode==otg).
> Will try to repro this particular crash and fix it before sending next
> version. Thanks for reporting this.
>
It probably dues to Bot's comment:
- [High] usb: dwc3: qcom: use-after-free of host_nb on dwc3_qcom_probe()
error paths
If the 1st time Qcom USB probe fails, it leaves a stale entry for block notifier
chain, and when the 2nd time Qcom USB probe executes, it will visit that
stale entry.
--
Thanks,
Peter Chen
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [PATCH RFC 2/2] usb: dwc3: qcom: Vote ICC DDR bandwidth based on connected device speed
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-02 3:35 ` Peter Chen
2 siblings, 0 replies; 9+ messages in thread
From: Peter Chen @ 2026-12-02 3:35 UTC (permalink / raw)
To: Krishna Kurapati
Cc: Thinh Nguyen, Greg Kroah-Hartman, Pratham Pratap, Jack Pham,
Wesley Cheng, linux-arm-msm, linux-usb, linux-kernel
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
^ permalink raw reply [flat|nested] 9+ messages in thread