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=1796107571; b=UUCTOjyEikeqnLfYAv/adVP+5qdiYZKny268l1Fhv8PwvCCSBxHfeXcdheNCdKAjjMdm FYfd1i4nRh574gbIbO0G9zROXRu8BQ1Cb0o9rdQi9LNPUrQWAAn6DhgWYR6+FgEhYLOnO Ejc2Qko7ocp7LfESVynP//+IG/26sptNR/Fz1AuUFkhzn7Fvr2Pi+xYb+w3gg8gDaUMP/ yj7kF5K3LVfrfN7CH7PcM7i1nKb3dxdtq3Q/smY2HXVEh+DbWNrMOg1/52iQxv0qRQWEB N7ZO6NrJYRMdWtJT5TOs6PQBvjQTHgTopOSD99XWgBSYqp0Gw3nXe4ZG5IirWg2F91Q== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796107571; h=Received:DKIM-Signature:Subject:From:To:Cc:Date:Message-ID: In-Reply-To:References:X-sashiko-severity:Content-Type: Content-Transfer-Encoding:MIME-Version; bh=A6eG5mS/GJBrl0xkYtjZrKoiuk6rufjdWk7kayta71c=; b=U94wGQKjCN2oeKyYBL5JaQhDgs82EM6nAz4CqT/PlXSjuibDqtslHn6QhHWr08szNf8I TWqpbvljen1ynh4Lw+B416KfKyW4i82wjbaHTfxOqNAHFWcTQdhCbkMVw+gMwVcxSt+hq L0zai1eVNkzIovLfQ1YTKPPOnCY+2ITSUmEmQsGPoqAgUPSPFxjdo6J8m/AQHzFnrczQM Jfl2WMRUhyDrHygB88yTPe3zJBgbv3VYX7DlpVjHs4NAI1Z73al+ZaP5T7cgFbAtOj3e6 8MY5fVkl8ION9Y5jKiO/q9XzWamGkl6xlRjJPtj8WhSiJDCf/YeQLr0Lj/dPiBcYzQg== 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=FsDUk3se; 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 DF0EC606A6A0; Tue, 1 Dec 2026 06:46:11 +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=FsDUk3se Received: by smtp.kernel.org (Postfix) with ESMTPSA id B4DF61F00919; Tue, 1 Dec 2026 06:46:10 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1796107571; bh=A6eG5mS/GJBrl0xkYtjZrKoiuk6rufjdWk7kayta71c=; h=Subject:From:To:Cc:Date:In-Reply-To:References; b=FsDUk3seZC9L6dlZWb/JHeOzN4gqcDd5OZnkWG8KGABC2Xnu1aZqzWdsDzNML5eW9 SO9zicyUmVf5CRtaMp+TSjU+KZWFW1fWVEgQCFGH2YvDI8br36ewJU2FDVw8peJjox 8SotznN+J0wkpK8l/UlTb5aOeUNCLD0ZMSMU9khPZY/rpdW/ydSEmhZXsqedAepYLb ldyePPOXhNlCPZxz0ovZs/q/i5JhIVzHYypFds93Z/WMrUaPIpNZulb3ft4OtSKEN4 ZmAVevptACcCckr4vu0CGPJ7/TcHlN8iw+0WXkX2JSw8UGd0uKOMMcq8Q5NT8T9sN0 lLO414MgXhrVg== Subject: Re: [PATCH net-next v10 11/12] r8152: add TGPHY register access for RTL8157 and RTL8159 From: netdev-bot+sashiko@kernel.org To: hsu.chih.kai@realtek.com Cc: davem@davemloft.net, kuba@kernel.org, netdev@vger.kernel.org, nic_swsd@realtek.com, linux-kernel@vger.kernel.org, linux-usb@vger.kernel.org, edumazet@google.com, bjorn@mork.no, pabeni@redhat.com, andrew+netdev@lunn.ch, mail@birger-koblitz.de Date: Tue, 01 Dec 2026 06:46:10 +0000 Message-ID: <179610757024.3146.14412805988724383466@kernel.org> In-Reply-To: <20261130063123.2408-12-nic_swsd@realtek.com> References: <20261130063123.2408-12-nic_swsd@realtek.com> X-sashiko-severity: Medium Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 8bit X-Mailing-List: linux-usb@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Thank you for your contribution! Sashiko AI review found 3 potential issue(s) to consider. Critical: 0 · High: 0 · Medium: 2 · Low: 1 If you believe none of the issues are legitimate, please reply to each issue of Medium severity or higher and explain why the AI is wrong. If any of them are legitimate and you plan to respin, please let patchwork know by including "pw-bot: cr" as a separate line at the end of your reply (one such reply per series is enough). - [Medium] If the TGPHY busy bit stays set, set_carrier() retries every 100 ms with no limit and no backoff, for as long as the interface is… - [Medium] On RTL8157/8159 a single PHY write can now be dropped while later writes still go through. - [Low] The commit message says rtl_phy_patch_request() 'releases PATCH_REQUEST when a later step fails, so a failed access does not… -- r8152: add TGPHY register access for RTL8157 and RTL8159 This patch adds a TGPHY command channel for PHY register access on RTL8157 and RTL8159. ocp_reg_read() and ocp_reg_write() now go through per-chip rtl_ops.phy_read/phy_write hooks. The PHY accessors and the helpers built on them return int, and selected callers act on failures. > diff --git a/drivers/net/usb/r8152.c b/drivers/net/usb/r8152.c > index 392b7015f4925..b9586c30c04dd 100644 > --- a/drivers/net/usb/r8152.c > +++ b/drivers/net/usb/r8152.c [ ... ] > @@ -1911,100 +1958,221 @@ static void ocp_byte_set_bits(struct r8152 *tp, u16 type, u16 index, u8 set) [ ... ] > +static int wait_tgphy_cmd_ready(struct r8152 *tp) > +{ > + u16 ocp_data; > + int ret; > + > + ret = read_poll_timeout(ocp_read_word, ocp_data, > + test_bit(RTL8152_INACCESSIBLE, &tp->flags) || > + !(ocp_data & TGPHY_CMD_BUSY), > + 2000, 20000, false, tp, > + MCU_TYPE_USB, USB_TGPHY_CMD); > + > + if (ret) > + dev_err_ratelimited(&tp->intf->dev, "TGPHY cmd busy timeout\n"); > + > + return test_bit(RTL8152_INACCESSIBLE, &tp->flags) ? -ENODEV : ret; > +} > + > +static int rtl_tgphy_access(struct r8152 *tp, u16 addr, u16 *data, bool write) > +{ > + u16 cmd = 0; > + int ret; > + > + ret = wait_tgphy_cmd_ready(tp); > + if (ret < 0) > + goto out; [Severity: Medium] On RTL8157/8159, can a single dropped PHY write now corrupt the PHY patch RAM without any error being reported? Before this patch, these chips used the OCP window. There, a failed control transfer goes through r8152_control_msg() and rtl_set_inaccessible(), which blocks every later write. A register sequence therefore either completed or stopped. Here a busy timeout skips this one access and returns -ETIMEDOUT. The device stays accessible, so if the busy bit clears later, the next write goes through. The PHY loaders write OCP_SRAM_ADDR once and then stream data words, relying on the hardware to auto-increment the address. They ignore every return value: drivers/net/usb/r8152.c:rtl8152_fw_phy_nc_apply() { ... ocp_reg_write(tp, OCP_SRAM_ADDR, __le16_to_cpu(phy->fw_reg)); for (i = 0; i < num; i++) ocp_reg_write(tp, OCP_SRAM_DATA, __le16_to_cpu(data[i])); ... } The same pattern appears in rtl8152_fw_phy_union_apply(). It also appears in open-coded SRAM/SRAM2 bursts in r8157_hw_phy_cfg() (0x8f9c, 0x8566, 0x82c8, 0x82a0) and r8159_hw_phy_cfg() (0x81c4). A dropped DATA write would shift every later word down one SRAM address. A dropped ADDR write would send the whole block to wherever the address pointer was left. Nothing reads the data back. rtl8152_apply_firmware() also ignores the errno that rtl_pre_ram_code() now returns, and it still records rtl_fw->version and logs success. The commit message says the sram_*() and hw_phy_cfg callers still ignore the status. Could it also mention, or the code prevent, this partial-stream case? It was not possible with the OCP path. [ ... ] > @@ -4597,36 +4767,52 @@ static inline void rtl_reset_ocp_base(struct r8152 *tp) > static int rtl_phy_patch_request(struct r8152 *tp, bool request, bool wait) > { [ ... ] > - for (i = 0; wait && i < 5000; i++) { > - u32 ocp_data; > + if (ret < 0) > + return ret; > > - if (test_bit(RTL8152_INACCESSIBLE, &tp->flags)) > - return -ENODEV; > + for (i = 0; wait && i < 5000; i++) { > + if (test_bit(RTL8152_INACCESSIBLE, &tp->flags)) { > + ret = -ENODEV; > + goto err; > + } > > usleep_range(1000, 2000); > - ocp_data = ocp_reg_read(tp, OCP_PHY_PATCH_STAT); > - if ((ocp_data & PATCH_READY) ^ check) > + ret = ocp_reg_read(tp, OCP_PHY_PATCH_STAT, &ocp_data); > + if (ret < 0) > + goto err; > + else if ((ocp_data & PATCH_READY) ^ check) > break; > } > [ ... ] > + return 0; > + > +err: > + if (request) > + rtl_phy_patch_request(tp, false, false); > + > + return ret; > } [Severity: Low] The commit message says: rtl_phy_patch_request() returns the errno of a failed write, and releases PATCH_REQUEST when a later step fails, so a failed access does not leave it asserted. Is that guaranteed on this err path? The release is an ocp_reg_clr_bits() read-modify-write of OCP_PHY_PATCH_CMD. It goes through the same TGPHY channel that just failed, and its return value is discarded. Suppose the original failure was a busy timeout, for example on the OCP_PHY_PATCH_STAT read in the wait loop. The release's own wait_tgphy_cmd_ready() would then most likely time out too. PATCH_REQUEST would stay set, and the caller would only see the original errno. The success-path release is also unchecked. This applies to rtl_post_ram_code() and to the r8153b, r8156, r8156b, r8157 and r8159 hw_phy_cfg functions: rtl_phy_patch_request(tp, false, true); A dropped clear there would leave the PHY MCU in patch-request mode until the next full hw_phy_cfg. Could the commit message be reworded, or could the result of the release be checked? [ ... ] > @@ -7240,8 +7482,18 @@ static void set_carrier(struct r8152 *tp) > { > struct net_device *netdev = tp->netdev; > struct napi_struct *napi = &tp->napi; > + int bmsr; > + > + bmsr = r8152_mdio_read(tp, MII_BMSR); > + if (bmsr < 0) { > + if (bmsr != -ENODEV) { > + set_bit(RTL8152_LINK_CHG, &tp->flags); > + schedule_delayed_work(&tp->schedule, HZ / 10); > + } > + return; > + } [Severity: Medium] If the TGPHY busy bit stays set on RTL8157/8159, does this retry forever? wait_tgphy_cmd_ready() returns -ETIMEDOUT without setting RTL8152_INACCESSIBLE, so bmsr is never -ENODEV here. The following chain then repeats every 100 ms with no retry limit or backoff: rtl_work_func_t() set_carrier() r8152_mdio_read(tp, MII_BMSR) rtl_tgphy_access() wait_tgphy_cmd_ready() -> -ETIMEDOUT set_bit(RTL8152_LINK_CHG, &tp->flags) schedule_delayed_work(&tp->schedule, HZ / 10) It only stops when the device is marked inaccessible or the interface goes down. While it runs, each pass does a usb_autopm get/put. Each pass also holds tp->control for 20 to 40 ms out of every 100 ms. The ethtool handlers, the MII ioctls and hw_phy_work all wait on that mutex. Each pass also reaches dev_err_ratelimited(). The default ratelimit of 10 messages per 5 seconds still lets about 2 lines per second through, with no end. Does that match this statement in the commit message? A timeout is logged ratelimited, so a stuck busy bit does not flood the log In addition, delay_autosuspend() returns true whenever the delayed work is pending: if (work_busy(&tp->schedule.work) || sw_linking != hw_linking) return true; rtl8153_in_nway() also returns true on a failed read. Runtime autosuspend would therefore be blocked for as long as the fault lasts. The commit message leaves recovery from a TGPHY timeout to a follow-up series. Should this retry be bounded in the meantime? [ ... ] -- Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261130063123.2408-1-nic_swsd%40realtek.com