From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796050744; b=PZofmwbqkGSL+8kJimWZ7rm2o8Oo2wdTjFsdsgQB7ff7RU628qxAJoRjGlYY4q0Q2Isx jZotDmDXJKuSBiurpLON0NmIR4m6v1x1GPXWKTgmVkff5H+jgHumGeRdgl0io7jFHTgvD g4PrXcRWllsnu6JnfOdL9UIr/jgxHB/3epGovoU09klJJ2VyNYYrNAYB0DXgMbI2PfLTM CGdHptOSsXPaROSbcPK2iayhOl86RYJVqzCUfFe+H53Y7w8aul4cooSe68tTKXc4F9GUa QdvElsRxHPwwq8Pe94Q+AswZzp5zEAe5Xko66pT1ka0zeDpORF1WpoKgVX3nwXDh0Aw== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796050744; h=Received:DKIM-Signature:Message-ID:From:Subject:Reply-To:To:Cc: In-Reply-To:References:Content-Type:Content-Transfer-Encoding:Date; bh=BmBMRFI/Q7mjDar/Ybs7Hgfc7deOZ4lI1edCY0R+hMk=; b=o5S9vcoDRSD43rH6bb14jffKUhpXkq9WY+ILhlUVqDRIPls0UTjx6aWPDQTiJwiyPYGH RIpm6tNGmeY+zs/cU1fi0hunI6L/UXkaNnD8SNOCarGvrPuJL+00jz1A7jC23ioWaS+QI +vdrwBKkCVMJ5XQkVoqXBf67YQ13P++7DA9mVnXQe+0wsiChCs2RDKUwPrKpnZuS/rRc0 JHVemGtoLYyHgoWIFbNYsXMltPUvwiRTY0CYry54dz2J20dWMLJz4BhGNQXYeUZXfEK0a 3A/GoP4LI6+DJPX+4RhQ1Ah19KbF1/pB++MRw9Q8LkFyEbKa8s1jmxxT6Q+YoVEVGhA== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=BtLJELTR; arc=none smtp.remote-ip=100.103.45.18 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id CE2AC606A31C for ; Mon, 30 Nov 2026 14:59:04 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=BtLJELTR Received: by smtp.kernel.org (Postfix) with ESMTPSA id 4B1911F00897; Mon, 30 Nov 2026 14:59:04 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1796050744; bh=BmBMRFI/Q7mjDar/Ybs7Hgfc7deOZ4lI1edCY0R+hMk=; h=From:Subject:Reply-To:To:Cc:In-Reply-To:References:Date; b=BtLJELTRNdwLlmpkX9n+OdGMkjkL9x1aXzL7NNdCbABP5xpVbGAZh9jCoyAekHYJc sLd6INOQhrAoMoK9gPxQgK9rR8wOT/isKF2qlolhofllh9RlqU26rwbV8Z+vXuQvom taB+3tryQeEGFgB7uxWNxHTDKqYj2Ytz7KYXY2BhbiW2St1zu4XG+dXiLStLSEzZyF e5gn+J4eUvPDMAPpKtK/TDDNsI7W7sKHpW2M6zYpNZk1ccfJRPe+VAVTHJjJn4sfEI bCnZpCNseqSotlaOh5DyL32aj9sCgfXPuumWkpwwYyw0ZcsLd4XWzEBX8BO4pafajd zbZY6Cbz6cN5Q== Message-ID: From: sashiko-bot@kernel.org Subject: Re: [PATCH] usb: dwc2: Skip HCD PHY setup when a role switch is used Reply-To: sashiko-reviews@lists.linux.dev To: "Chen-Yu Yeh" Cc: linux-usb@vger.kernel.org In-Reply-To: <20261130144132.619573-1-chenyou910331@gmail.com> References: <20261130144132.619573-1-chenyou910331@gmail.com> Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Date: Mon, 30 Nov 2026 14:59:03 +0000 X-Mailing-List: linux-usb@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list Thank you for your contribution! Sashiko AI review found 2 potential issues to consider: - [High] usb: dwc2: missing Signed-off-by trailer in commit message above tearline - [High] usb: dwc2: skipping HCD PHY setup in dwc2_hcd_init() without DRD phy_set_mode() -- commit c46a379897b380450cfb9fdaa8a88e3e6943d4dc Author: Chen-Yu Yeh > usb: dwc2: Skip HCD PHY setup when a role switch is used > > When a USB role switch is registered, dwc2_drd_init() sets the PHY mode > according to the default role. Later in probe, dwc2_hcd_init() calls > usb_add_hcd(), which initializes the PHY again and unconditionally sets > it to host mode. This overrides the role chosen at boot. > > With role-switch-default-mode =3D "peripheral", the controller is forced > into device mode while the PHY is left in host mode, so the gadget is > never enumerated by the remote host: > > phy phy-3000000.syscon:phy@48.0: set mode 6 <- dwc2_drd_init() > phy phy-3000000.syscon:phy@48.0: set mode 5 <- usb_add_hcd() > phy phy-3000000.syscon:phy@48.0: set mode 1 <- usb_add_hcd() > > Set skip_phy_initialization when a role switch is present, so the DRD > code is the only place that sets the PHY mode. This is safe because > dwc2_lowlevel_hw_enable() already initializes and powers on the PHY > earlier in probe. Without a role switch, the behaviour is unchanged. > > Tested on Milk-V Duo 256M (SG2002). Besides the "set mode" messages, > the PHY state was read from the USB PHY control register 0x03000048: > 0x3c0 means the ID is overridden to device, 0x142 means the ID is > overridden to host with VBUS enabled. > > 1) role-switch-default-mode =3D "peripheral", Duo connected to a PC > > Before this patch: > set mode 6, 5, 1 > 0x03000048 =3D 0x142 > the PC does not see any gadget > > After this patch: > set mode 6 > 0x03000048 =3D 0x3c0 > the PC sees the g_ether gadget: > ID 0525:a4a2 Netchip Technology, Inc. Linux-USB Ethernet/RNDIS Gadget > > 2) role-switch-default-mode =3D "host", Duo on the IO board, USB stick > plugged in before boot > > After this patch: > set mode 1 > 0x03000048 =3D 0x142 > usb 1-1: new high-speed USB device number 2 using dwc2 > hub 1-1:1.0: 4 ports detected > usb 1-1.1: new high-speed USB device number 3 using dwc2 > sda: sda1 sda2 sda3 sda4 > Unplugging and replugging the stick enumerates it again at high > speed. > > 3) Role changes through sysfs, same setup as 1), three rounds > > echo host: set mode 1, 0x03000048 =3D 0x142 > echo device: set mode 6, 0x03000048 =3D 0x3c0, UDC "configured" > echo device while already in device: set mode 6, 0x3c0 > echo none: 0x03000048 =3D 0x3c0 (default role) > > 4) dr_mode =3D "host" without usb-role-switch, Duo on the IO board > (regression test, role_sw is NULL so nothing is skipped) > > set mode 5, 1 (still set by usb_add_hcd()) > 0x03000048 =3D 0x142 > /sys/class/usb_role/ is empty > hub and USB stick enumerated at high speed, sda1-sda4 present [Severity: High] The Signed-off-by trailer was placed below the --- separator and was stripped when the patch was applied, leaving the commit message without a Signed-off-by line. > diff --git a/drivers/usb/dwc2/hcd.c b/drivers/usb/dwc2/hcd.c > index 40ab50538334a..98d3b110769e2 100644 > --- a/drivers/usb/dwc2/hcd.c > +++ b/drivers/usb/dwc2/hcd.c > @@ -5334,6 +5334,16 @@ int dwc2_hcd_init(struct dwc2_hsotg *hsotg) > if (!IS_ERR_OR_NULL(hsotg->uphy)) > otg_set_host(hsotg->uphy->otg, &hcd->self); > =20 > + /* > + * With a role switch, the PHY mode is set by the dwc2 DRD code > + * according to the role. Without this flag, usb_add_hcd() would > + * set the PHY to host mode and override the role chosen at boot. > + * Skipping is safe because dwc2_lowlevel_hw_enable() already > + * initializes and powers on the PHY. > + */ > + if (hsotg->role_sw) > + hcd->skip_phy_initialization =3D 1; > + > /* > * Finish generic HCD initialization and start the HCD. This function > * allocates the DMA buffer pool, registers the USB bus, requests the [Severity: High] Does setting hcd->skip_phy_initialization leave hsotg->phy without any mode configured when hsotg->role_sw is used? In this tree, the prerequisite patch adding phy_set_mode() calls to drivers/usb/dwc2/drd.c is not present: dwc2_ovr_init() and dwc2_drd_role_sw_set() only update GOTGCTL and call dwc2_force_mode(), and __dwc2_lowlevel_hw_enable() only calls phy_init() and phy_power_on(). Bypassing usb_phy_roothub_set_mode() in usb_add_hcd() causes a regression where phy_set_mode() is never called on hsotg->phy for either host or peripheral mode, leaving PHYs that rely on .set_mode unconfigured. --=20 Sashiko AI review =C2=B7 https://sashiko.dev/#/patchset/20261130144132.6195= 73-1-chenyou910331@gmail.com?part=3D1