From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=185.246.84.56 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796227346; b=XpbzrAfgqBsyIIHvGSfguKeGR1IrCMHHI1pW4sEF3W9lzqg6YGO0SCELpltaoOiNptQL sx7tk1WkR8NoO+E6zG/nC5qm1DgiHudqCk7jHIU8XcKI8wlwWLtzqtbehxZPZLnfYZ580 oZK0WDLW0Dvl8VJp8m7EoIRjVgdzivJgL03TVMrhcAWqxd0Cw+rwzBbFSMXlJci3fQRRb yhXxCVEeSgqFewoMujikDEXOOFkY/PXUJEJ5igXXWMvrtjX92TBrhtCNKHraUHRB2YVPt g+3W39UH8wEzuhePMKll3j3pwuLgzRhSvi15Nnh0JssdXuy3vz/Y1MH+hAnuTu4cX3Q== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796227346; h=DMARC-Filter:Received:Received:Received:DKIM-Signature:From:To:Cc: Subject:Date:Message-ID:In-Reply-To:References:MIME-Version: Content-Transfer-Encoding:Content-Type:X-Last-TLS-Session-Version; bh=SQyTUkxaLcyHVB0aOLpddwWglRtmY+RoxocpRb/dWBg=; b=RuSLZXWOwKU/4l8v1X0STJtRZArDWdtLQgzu2lqMEcotqSjuZfzJxlabYXrxBrfLNpiJ 9VOUnVpW6AeDgf6QDMTHJ3wTCW3OTItWBLTMJAgSGOOBCpXFPZTKVHabFCC0lx5Pl/nN4 g1CmfPsVWmIiFTh95pjQmqk7iN7wtj2JjU6bJs+IwxmTp6Ym3zMESyTINMupwwn51i7C2 LQLCfzUn4gc3MZ6WcE2ZnnK0UD2D5Y1EcU/M2OYpSDyVJb0d5NkDO0J4gwoXtbm5aqCCz z2fX0GXonXsmFKYvnx5wckBlvYHLxMkYzh2mVeT11rfB0LcRms4EVmHZLh4AHtlqHhg== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=bootlin.com; spf=pass smtp.mailfrom=bootlin.com; dkim=pass header.d=bootlin.com header.i=@bootlin.com header.a=rsa-sha256 header.s=dkim header.b=crE8ia77; arc=none smtp.remote-ip=185.246.84.56 Received: from smtpout-02.galae.net (smtpout-02.galae.net [185.246.84.56]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 7FB34606A33A for ; Wed, 2 Dec 2026 16:02:24 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 7FB34606A33A Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=bootlin.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=bootlin.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=bootlin.com header.i=@bootlin.com header.a=rsa-sha256 header.s=dkim header.b=crE8ia77 Received: from smtpout-01.galae.net (smtpout-01.galae.net [212.83.139.233]) by smtpout-02.galae.net (Postfix) with ESMTPS id CDD631A18DE; Wed, 2 Dec 2026 16:02:22 +0000 (UTC) Received: from mail.galae.net (mail.galae.net [212.83.136.155]) by smtpout-01.galae.net (Postfix) with ESMTPS id 9BDB66075F; Wed, 2 Dec 2026 16:02:22 +0000 (UTC) Received: from [127.0.0.1] (localhost [127.0.0.1]) by localhost (Mailerdaemon) with ESMTPSA id 9750611EA1C42; Wed, 02 Dec 2026 17:02:19 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=dkim; t=1796227342; h=from:subject:date:message-id:to:cc:mime-version:content-type: content-transfer-encoding:in-reply-to:references; bh=SQyTUkxaLcyHVB0aOLpddwWglRtmY+RoxocpRb/dWBg=; b=crE8ia77HU3GQDhteB0qHiZKcwetDwDl9OPi/iELFyx/46TBjf8KoNU1bVPksT3Mt429v/ iBTuBtlP7C1OZt5pGvXWN2jvWxJf6fKaSsk8d3ho0U9EXrZondPP2kV7kHM/lehqaQ7vYL hOjg05tZ/ChiprCUHbqQyPh7tp6Bx2bXDbSaZ6kCZ4lzV3eGfKAOXcAVZ/THJbR3aBvSi+ Dr7fkHZ6cZ9B4FJdpBFmh2mkvDxsxDPPTomHLMj4Ihw9+sggyC6veMjs1426zcas4njFnN C17WMpAfo7Kz37Ebfw57ig20aqog4AMuV6vOCd9oE3qQrGchHKGaSEpMF5woOg== From: Benjamin Robin To: sashiko-reviews@lists.linux.dev Cc: devicetree@vger.kernel.org, linux-phy@lists.infradead.org, robh@kernel.org, conor+dt@kernel.org, vkoul@kernel.org, neil.armstrong@linaro.org, olteanv@gmail.com Subject: Re: [PATCH 4/4] phy: cadence-torrent: rewrite Torrent PHY driver Date: Wed, 02 Dec 2026 17:02:18 +0100 Message-ID: <5K7Md9-NTQeBZUihR_WipA@bootlin.com> In-Reply-To: References: <20261120-phy-cadence-torrent-ng-v1-0-da2db7125cd7@bootlin.com> <20261120-phy-cadence-torrent-ng-v1-4-da2db7125cd7@bootlin.com> X-Mailing-List: devicetree@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" X-Last-TLS-Session-Version: TLSv1.3 On Friday, November 20, 2026 at 2:33=E2=80=AFPM, sashiko-bot@kernel.org wro= te: > Thank you for your contribution! Sashiko AI review found 14 potential > issues to consider: > - [High] phy: cadence-torrent: 32-bit shift overflow in > tp_write_pll_regs() > - [High] phy: cadence-torrent: CDB register access before apb_rst > deassertion > - [High] phy: cadence-torrent: DP init and configure break cdns-mhdp8546 > consumer > - [High] phy: cadence-torrent: missing mlane shift in > tp_dptx_set_pll_en() and lanes > - [High] phy: cadence-torrent: nb_phy_on underflow in tp_phy_off() when > preconfigured > - [High] phy: cadence-torrent: tp_resume_noirq() leaves active links > held in reset > - [Medium] phy: cadence-torrent: REV_R110 enum typo in > tp_write_pll_cp_padj() > - [Medium] phy: cadence-torrent: unreachable FBR mode in > tp_calc_pcie_pll_fb_div_mode() > - [Medium] phy: cadence-torrent: stale SSC and divider regs in > tp_write_pll_regs() > - [Medium] phy: cadence-torrent: unbalanced clk disable in > tp_phy_cleanup() > - [Medium] phy: cadence-torrent: skipped refclk check in > tp_ref_clks_init() > - [Medium] phy: cadence-torrent: missed PCIe ML flag in > tp_check_multiple_pcie_links() > - [Medium] phy: cadence-torrent: rejected standard swap with clk1 in > tp_find_link_cfg() > - [Medium] phy: cadence-torrent: unchecked tp_dp_run() and missing reset > rollback > -- >=20 > commit 3480ec972d0cd2d542d547f1d45d7f4f38415bc8 > Author: Benjamin Robin >=20 > phy: cadence-torrent: rewrite Torrent PHY driver >=20 > This commit rewrites the Cadence Torrent PHY driver to compute clock and > PLL register values at runtime and look up remaining protocol, revision, > and process-node register settings per register instead of using static > register tables. >=20 > > diff --git a/drivers/phy/cadence/phy-cadence-torrent.c b/drivers/phy/ca= dence/phy-cadence-torrent.c > > index 1e178aa2ffd76..74a65f0f4b242 100644 > > --- a/drivers/phy/cadence/phy-cadence-torrent.c > > +++ b/drivers/phy/cadence/phy-cadence-torrent.c >=20 > [ ... ] >=20 > > @@ -394,5453 +515,4629 @@ enum phy_powerstate { > > POWERSTATE_A3 =3D 3, > > }; > > =20 > > +static const struct tp_link_cfg tp_link_cfgs[] =3D { > > + { > > + /* PLL 0 M0: PCIe, PLL 0 M1: PCIe, PLL 1: None */ > > + .std0 =3D STD0_PCIE_SL, .std1 =3D STD1_NONE, > > + .pll_freq =3D { PLL_10_00_GHZ, PLL_8_00_GHZ, PLL_8_00_GHZ }, > > + .phy_pll_cfg =3D 0x0001, > > + .pll_clk_sel =3D { 0x0601, 0x0400, 0x0400 }, > > + .xcvr_diag_plldrc_ctrl =3D { 0x0012, 0x0012 }, > > + .xcvr_diag_hsclk_sel =3D { 0x0000, 0x0000 }, > > + .xcvr_diag_hsclk_div =3D { 0x0001, 0x0001 }, > > + }, >=20 > [ ... ] >=20 > > +static enum tp_pll_fb_div_mode tp_calc_pcie_pll_fb_div_mode(const stru= ct tp_phy *tp_phy) > > +{ > > + u32 tech_tag =3D tp_phy->tech_tag; > > + enum tp_revision rev =3D tp_phy->rev; > > + enum tp_pll_fb_div_mode div_mode; > > + > > + if (tech_tag & (TECH_TSMC_16 | TECH_TSMC_12)) { > > + if (rev =3D=3D REV_R100) { > > + if (tp_phy->plls[PLL1_MODE0].freq_khz =3D=3D 0) > > + div_mode =3D PLL_FB_DIV_MODE_FBR; > > + else > > + div_mode =3D PLL_FB_DIV_MODE_D32; > > + } else { >=20 > [Severity: Medium] > Can tp_phy->plls[PLL1_MODE0].freq_khz ever be 0 here? >=20 > Every entry in tp_link_cfgs[], including single-link PCIe (STD0_PCIE_SL > with STD1_NONE), sets pll_freq[PLL1_MODE0] to a non-zero frequency > (PLL_8_00_GHZ) rather than PLL_UNUSED. Because tp_init_plls_data() > populates plls[PLL1_MODE0].freq_khz from pll_freq[PLL1_MODE0] before > calling tp_calc_pll_fb_div_modes(), single-link PCIe on TSMC 16nm/12nm > REV_R100 hardware always selects PLL_FB_DIV_MODE_D32 instead of > PLL_FB_DIV_MODE_FBR, misprogramming the PLL control, VCO calibration, and > lock registers. It was indeed a bug, and fixed in v2. If there is no second standard we should select PLL_FB_DIV_MODE_FBR.=20 > [ ... ] >=20 > > +static void tp_write_pll_cp_padj(const struct tp_phy *tp_phy, enum tp_= pll_id pll_id) > > +{ > > + u32 tech_tag =3D tp_phy->tech_tag; > > + u32 rev_msk =3D BIT(tp_phy->rev); > > + const struct tp_pll_data *pll =3D &tp_phy->plls[pll_id]; > > + u16 val; > > + > > + /* PLL charge pump proportional path adjust register */ > > + if (pll->freq_khz < 8000000) { > > + val =3D 0x0B17; > > + } else if (pll->fractional_mode) { > > + if (tech_tag & TECH_TSMC_7) > > + val =3D 0x0B17; > > + else if (tech_tag & (TECH_SS_5 | TECH_SS_7)) > > + val =3D 0x0309; > > + else > > + val =3D 0x0509; /* TSMC_5, TSMC_12, TSMC_16, TSMC_16_0805 */ > > + } else if (pll->freq_khz >=3D 10000000) { > > + if (tech_tag & TECH_TSMC_7) > > + val =3D (rev_msk & (REV_MSK_R100 | REV_MSK_R110)) ? 0x0023 : 0x0035; > > + else if (tech_tag & TECH_TSMC_5) > > + val =3D (pll_id =3D=3D PLL0_MODE0) ? 0x002D : 0x0035; > > + else if (tech_tag & (TECH_SS_5 | TECH_SS_7)) > > + val =3D 0x013E; > > + else > > + val =3D 0x0028; /* TSMC_12, TSMC_16, TSMC_16_0805 */ > > + } else { > > + if (tech_tag & TECH_TSMC_16) > > + val =3D (rev_msk & REV_MSK_R100) ? 0x0028 : 0x0128; > > + else if (tech_tag & TECH_TSMC_16_0805) > > + val =3D 0x0128; > > + else if (tech_tag & TECH_TSMC_12) > > + val =3D 0x0028; > > + else if (tech_tag & TECH_TSMC_7) > > + val =3D (rev_msk & (REV_MSK_R100 | REV_R110)) ? 0x001D : 0x0031; >=20 > [Severity: Medium] > Should REV_R110 be REV_MSK_R110 in the TECH_TSMC_7 check? REV_R110 is > the enum value 1 (equal to REV_MSK_R100) rather than BIT(REV_R110), so R1= 10 > hardware (rev_msk =3D=3D 0x2) never matches and programs > CMN_PDIAG_PLLx_CP_PADJ_Mx with 0x0031 instead of 0x001D for 8 GHz > integer-mode PLLs. It was indeed a bug, and fixed in v2. Use the correct macro. =20 > [ ... ] >=20 > > +static void tp_write_pll_fd_div_regs(const struct tp_phy *tp_phy, enum= tp_pll_id pll_id, > > + u32 div_ratio) > > +{ > > + const struct tp_reg_base *base =3D &tp_phy->reg_common_cdb; > > + const struct tp_pll_data *pll =3D &tp_phy->plls[pll_id]; > > + u32 tech_tag =3D tp_phy->tech_tag; > > + u16 high_div; > > + u16 low_div; > > + > > + /* In fractional mode, we use default/reset value */ > > + if (pll->fractional_mode) > > + return; > > + > > + if (pll_id =3D=3D PLL0_MODE0 && pll->ref_clk_khz =3D=3D 100000 && pll= =2D>freq_khz =3D=3D 10000000) { > > + /* 100 MHz refclk, 10 GHz PLL */ > > + if (tech_tag & (TECH_TSMC_12 | TECH_TSMC_16 | TECH_TSMC_16_0805)) { > > + high_div =3D 30; > > + low_div =3D 12; > > + } else { > > + high_div =3D 36; > > + low_div =3D 6; > > + } > > + } else if (pll->ref_clk_khz =3D=3D 100000 && pll->freq_khz =3D=3D 800= 0000) { > > + /* 100 MHz refclk, 8 GHz PLL */ > > + if (tech_tag & (TECH_TSMC_12 | TECH_TSMC_16 | TECH_TSMC_16_0805)) { > > + high_div =3D 16; > > + low_div =3D 16; > > + } else { > > + high_div =3D 28; > > + low_div =3D 4; > > + } > > + } else { > > + /* Generic calculations */ > > + > > + /* PLL high integer divider val: EVEN(div_ratio_2 * 67/100) - 4 */ > > + high_div =3D DIV_ROUND_UP((div_ratio >> 1) * 67U, 100U); > > + high_div -=3D (high_div & 1U) ? 3U : 4U; > > + > > + /* PLL low integer divider val: div_ratio_2 - 8 - high_div */ > > + low_div =3D (div_ratio >> 1) - 8 - high_div; > > + } > > + > > + tp_reg_write(base, CMN_PLLx_DSM_FBH_OVRD_Mx(pll_id), high_div); > > + tp_reg_write(base, CMN_PLLx_DSM_FBL_OVRD_Mx(pll_id), low_div); > > +} > > + > > +static void tp_write_pll_itrim_reg(const struct tp_phy *tp_phy, enum t= p_pll_id pll_id) > > +{ > > + const struct tp_reg_base *base =3D &tp_phy->reg_common_cdb; > > + const struct tp_pll_data *pll =3D &tp_phy->plls[pll_id]; > > + > > + if (tp_phy->tech_tag & TECH_TSMC_ALL) { > > + u16 val =3D (pll->freq_khz >=3D 10000000) ? 0x003F : 0x007F; > > + > > + tp_reg_write(base, CMN_PDIAG_PLLx_ITRIM_Mx(pll_id), val); > > + } > > +} > > + > > +static void tp_write_pll_regs(const struct tp_phy *tp_phy, enum tp_pll= _id pll_id) > > +{ > > + const struct tp_reg_base *base =3D &tp_phy->reg_common_cdb; > > + const struct tp_pll_data *pll =3D &tp_phy->plls[pll_id]; > > + u32 fd_div_prescale; > > + u32 div_ratio; > > + u16 fracdivl; > > + u16 val; > > + > > + if (pll_id !=3D PLL0_MODE1) > > + tp_write_pll_vco_regs(tp_phy, pll_id); > > + > > + /* Divide ratio */ > > + div_ratio =3D pll->freq_khz / pll->ref_clk_khz; > > + > > + /* PLL feedback divider prescale */ > > + fd_div_prescale =3D ((!pll->fractional_mode) || (div_ratio > 512)) ? = 1 : 0; > > + > > + /* PLL integer divider value */ > > + val =3D (pll->fractional_mode) ? (div_ratio >> fd_div_prescale) : 0; > > + tp_reg_write(base, CMN_PLLx_INTDIV_Mx(pll_id), val); > > + > > + /* PLL fractional divider value */ > > + if (pll->fractional_mode) { > > + u32 den =3D pll->ref_clk_khz << fd_div_prescale; > > + u32 rem =3D pll->freq_khz % den; > > + > > + fracdivl =3D DIV_ROUND_CLOSEST(rem << 16, den); > > + } else { > > + fracdivl =3D 0; > > + } > > + > > + tp_reg_write(base, CMN_PLLx_FRACDIVL_Mx(pll_id), fracdivl); > > + tp_reg_write(base, CMN_PLLx_FRACDIVH_Mx(pll_id), pll->fractional_mode= ? 2 : 0); > > + > > + /* PLL high threshold value */ > > + if (pll->fractional_mode) { > > + /* EVEN(CEIL((fracdivl/65536 + (div_ratio >> fd_div_prescale)) * 2 /= 3)) */ > > + u32 num =3D fracdivl + (div_ratio << (16 - fd_div_prescale)); >=20 > [Severity: High] > Can rem << 16 overflow 32-bit u32 when computing fracdivl in > tp_write_pll_regs()? >=20 > When rem >=3D 65535 (for example, DisplayPort at the default 8100 Mbps ra= te > with a supported 156.25 MHz reference clock, where den =3D 156250 and > rem =3D 131250), rem << 16 overflows u32 and corrupts both > CMN_PLLx_FRACDIVL_Mx and CMN_PLLx_HIGH_THR_Mx (producing fracdivl =3D 0x0= 04B > instead of 0xD70A). Also, when fd_div_prescale =3D=3D 1 and div_ratio is= odd > (e.g. 20 MHz refclk with 10.3125 GHz USXGMII where div_ratio =3D 515), > div_ratio << (16 - fd_div_prescale) retains bit 0 of div_ratio instead of > using (div_ratio >> fd_div_prescale) << 16, double-counting the odd > remainder already included in fracdivl. It was indeed a bug, and fixed in v2. This part of the computation is now done in 64 bits. Also the computation when fd_div_prescale =3D=3D 1 and div_ratio is odd was fixed. > > + > > + val =3D DIV_ROUND_UP(num, 3 << 15); > > + if (val & 1) > > + val++; > > + } else { > > + val =3D 0; > > + } > > + > > + tp_reg_write(base, CMN_PLLx_HIGH_THR_Mx(pll_id), val); > > + > > + /* PLL delta sigma modulator diagnostics register */ > > + tp_reg_write(base, CMN_PLLx_DSM_DIAG_Mx(pll_id), > > + pll->fractional_mode ? 0x0004 : 0x4004); > > + > > + /* PLL high and low integer divider value */ > > + tp_write_pll_fd_div_regs(tp_phy, pll_id, div_ratio); > > + > > + if (pll->ssc) > > + tp_write_ssc_ctrl(tp_phy, pll_id, fd_div_prescale); >=20 > [Severity: Medium] > Does dynamic DisplayPort rate reconfiguration leave stale values in > CMN_PLLx_SS_CTRL1_Mx..CTRL4_Mx and CMN_PLLx_DSM_FBH/FBL_OVRD_Mx? >=20 > When tp_dp_update_pll_freq() -> tp_write_pll_regs() reconfigures a DP link > from SSC enabled to SSC disabled, skipping tp_write_ssc_ctrl() leaves > CMN_PLLx_SS_CTRL1_Mx..CTRL4_Mx enabled in hardware while VCO and lock > counters are programmed for non-SSC operation. Similarly, if a DP PLL > switches from integer mode (e.g. 2.7/5.4 Gbps with 100 MHz refclk and no > SSC) to fractional mode, returning early in tp_write_pll_fd_div_regs() > leaves the previous integer divider overrides in CMN_PLLx_DSM_FBH_OVRD_Mx > and CMN_PLLx_DSM_FBL_OVRD_Mx instead of restoring their reset values. It was indeed a bug, and fixed in v2. CMN_PLLx_SS_CTRL1_Mx is now written to 2 when SSC is disabled. But returning early in tp_write_pll_fd_div_regs() is fine, a comment was added when returning early to explain why. > [ ... ] >=20 > > +static int tp_dptx_set_pll_en(const struct tp_phy *tp_phy, u32 num_lan= es, bool enable) > > +{ > > + void __iomem *addr; > > + u32 pll_ack_val; > > + u32 rd_val; > > + int ret; > > + > > + /* Used to determine which bits to check for or enable in PHY_PMA_XCV= R_PLLCLK_EN reg */ > > + u32 pll_bits; > > + /* Used to enable or disable lanes. */ > > + u32 pll_val; > > + > > + /* Select reg value and mask, depending on enabled lane count. */ > > + pll_val =3D tp_reg_dptx_read(tp_phy, PHY_PMA_XCVR_PLLCLK_EN); > > + > > + if (enable) { > > + pll_bits =3D ((1 << num_lanes) - 1); > > + pll_val |=3D pll_bits; > > + pll_ack_val =3D pll_bits; > > + } else { > > + pll_bits =3D ((1 << num_lanes) - 1); > > + pll_val &=3D (~pll_bits); > > + pll_ack_val =3D 0; > > + } >=20 > [ ... ] >=20 > > +static void tp_dp_set_lanes(const struct tp_phy *tp_phy, struct tp_lin= k *link, u32 num_lanes) > > +{ > > + u32 pma_tx_elec_idle_mask; > > + u8 used_lane_mask; > > + u8 all_lane_mask; > > + u32 pll_clk_en; > > + u32 pwr_state; > > + u32 value; > > + u32 mlane =3D link->mlane; > > + > > + used_lane_mask =3D ((1U << num_lanes) - 1) << mlane; > > + all_lane_mask =3D ((1U << link->max_lanes) - 1) << mlane; >=20 > [ ... ] >=20 > > + /* Clear requested power state set PLL clock enable to 0 on all used = lanes. */ > > + pwr_state =3D tp_reg_dptx_read(tp_phy, PHY_PMA_XCVR_POWER_STATE_REQ); > > + pll_clk_en =3D tp_reg_dptx_read(tp_phy, PHY_PMA_XCVR_PLLCLK_EN); > > + > > + for (u32 i =3D 0; i < num_lanes; ++i) > > + pwr_state &=3D ~(PMA_XCVR_POWER_STATE_REQ_LN_MASK << PHY_POWER_STATE= _LN(mlane + i)); > > + > > + pll_clk_en &=3D ~used_lane_mask; > > + > > + tp_reg_dptx_write(tp_phy, PHY_PMA_XCVR_POWER_STATE_REQ, pwr_state); > > + tp_reg_dptx_write(tp_phy, PHY_PMA_XCVR_PLLCLK_EN, pll_clk_en); > > + > > + /* release master lane reset */ > > + value |=3D 1 << mlane; > > + tp_reg_dptx_write(tp_phy, PHY_RESET, value); > > + > > + /* update the number of used lanes */\n+ link->num_lanes =3D num_lane= s; > > +} >=20 > [Severity: High] > Should pll_bits in tp_dptx_set_pll_en() be shifted by link->mlane? >=20 > Unlike tp_dp_set_lanes() and tp_dptx_set_power_state(), tp_dptx_set_pll_e= n() > computes pll_bits =3D ((1 << num_lanes) - 1) without shifting by link->ml= ane, > so any DisplayPort link with mlane > 0 modifies PHY_PMA_XCVR_PLLCLK_EN for > lane 0 and times out polling PHY_PMA_XCVR_PLLCLK_EN_ACK. >=20 > In addition, tp_dp_set_lanes() only clears PHY_PMA_XCVR_POWER_STATE_REQ a= nd > PHY_PMA_XCVR_PLLCLK_EN across used_lane_mask instead of all_lane_mask, > leaving disabled lanes' PLLCLK_EN bits set when reducing the lane count. > And when both set_lanes and set_rate are requested in tp_phy_configure(), > running tp_dp_set_lanes() before tp_dp_set_rate() resets the lanes, clears > PLLCLK_EN, and updates link->num_lanes before tp_dp_set_rate() transitions > the previously active lanes to POWERSTATE_A3 (while tp_write_lanes_reg() > also only programs link->num_lanes instead of link->max_lanes). It was indeed a bug, and fixed in v2. Fixed various register values that were not shifted by link->mlane. Also now clear PHY_PMA_XCVR_POWER_STATE_REQ and PHY_PMA_XCVR_PLLCLK_EN across all lanes (max_lanes) > [ ... ] >=20 > > +static int tp_phy_configure(struct phy *phy, union phy_configure_opts = *opts) > > +{ > > + struct tp_phy *tp_phy =3D dev_get_drvdata(phy->dev.parent); > > + struct tp_link *link =3D phy_get_drvdata(phy); > > + bool run_needed =3D false; > > + int ret; > > + > > + guard(mutex)(&tp_phy->lock); > > + > > + if (tp_phy->already_configured) > > + return 0; > > + > > + if (link->type !=3D STD_TYPE_DP) > > + return -EINVAL; > > + > > + ret =3D tp_dp_verify_config(link, &opts->dp); > > + if (ret) { > > + dev_err(&phy->dev, "invalid params for phy configure\n"); > > + return ret; > > + } > > + > > + if (opts->dp.set_lanes && opts->dp.lanes !=3D link->num_lanes) { > > + tp_dp_set_lanes(tp_phy, link, opts->dp.lanes); > > + run_needed =3D true; > > + } > > + > > + if (opts->dp.set_rate) { > > + ret =3D tp_dp_set_rate(tp_phy, link, &opts->dp); > > + if (ret) { > > + dev_err(&phy->dev, "Set rate failed\n"); > > + return ret; > > + } > > + run_needed =3D true; > > + } > > + > > + if (opts->dp.set_voltages) > > + tp_dp_set_voltages(tp_phy, link, &opts->dp); > > + > > + if (phy->power_count && run_needed) > > + ret =3D tp_dp_run(tp_phy, link); > > + > > + return ret; > > +} >=20 > [Severity: High] > Does moving DisplayPort reset deassertion and tp_dp_run() out of > tp_phy_init() and gating tp_dp_run() on phy->power_count break > cdns-mhdp8546? >=20 > The in-tree DisplayPort bridge consumer > (drivers/gpu/drm/bridge/cadence/cdns-mhdp8546-core.c) calls phy_init() in > cdns_mhdp_probe() and phy_configure() in cdns_mhdp_link_training_init(), > but never calls phy_power_on(). Because tp_dp_phy_init() no longer > deasserts phy_rst/lnk_rst or starts the DP PLL and lanes, and > tp_phy_configure() skips tp_dp_run() when phy->power_count is 0, the PHY > remains held in reset and tp_dp_set_rate() polls PHY_PMA_CMN_CTRL2 on an > unstarted PHY. This is fine, the series depends on a patch that add the calls to phy_power_on() / phy_power_off() > > + > > +static int tp_phy_on(struct phy *phy) > > +{ > > + struct tp_link *link =3D phy_get_drvdata(phy); > > + struct tp_phy *tp_phy =3D dev_get_drvdata(phy->dev.parent); > > + u16 val; > > + int ret; > > + > > + guard(mutex)(&tp_phy->lock); > > + > > + if (tp_phy->already_configured) { > > + /* Give 5ms to 10ms delay for the PIPE clock to be stable */ > > + usleep_range(5000, 10000); > > + return 0; > > + } > > + > > + if (tp_phy->nb_phy_on =3D=3D 0) { > > + /* Take the PHY out of reset */ > > + ret =3D reset_control_deassert(tp_phy->phy_rst); > > + if (ret) > > + return ret; > > + } > > + > > + /* Take the PHY lane group out of reset */ > > + ret =3D reset_control_deassert(link->lnk_rst); > > + if (ret) > > + return ret; > > + > > + /* > > + * Wait for cmn_ready assertion > > + * PHY_PMA_CMN_CTRL1[0] =3D=3D 1 > > + */ > > + ret =3D read_poll_timeout(tp_reg_read, val, val & 1, 1000, PLL_LOCK_T= IMEOUT, false, > > + &tp_phy->reg_phy_pma_common_cdb, PHY_PMA_CMN_CTRL1); > > + if (ret) { > > + dev_err(tp_phy->dev, "Timeout waiting for CMN ready\n"); > > + return ret; > > + } > > + > > + if (link->type =3D=3D STD_TYPE_DP) { > > + tp_dp_run(tp_phy, link); > > + } else if (link->type =3D=3D STD_TYPE_PCIE || link->type =3D=3D STD_T= YPE_USB_TXRX) { > > + struct tp_reg_base *reg_base; > > + > > + reg_base =3D &tp_phy->reg_phy_pcs_lane_cdb[link->mlane]; > > + ret =3D read_poll_timeout(tp_reg_read, val, (val & 2) =3D=3D 0, 1000, > > + PLL_LOCK_TIMEOUT, false, reg_base, > > + PHY_PCS_ISO_LINK_CTRL); > > + if (ret < 0) { > > + dev_err(tp_phy->dev, "Timeout waiting for PHY status ready\n"); > > + return ret; > > + } > > + } > > + > > + tp_phy->nb_phy_on++; > > + return 0; > > +} >=20 > [Severity: Medium] > Should tp_phy_on() check the return value of tp_dp_run() and re-assert > link->lnk_rst and tp_phy->phy_rst on error? >=20 > Right now a timeout in tp_dp_run() is ignored and tp_phy_on() increments > nb_phy_on and returns 0. Conversely, if deasserting link->lnk_rst or > polling PHY_PMA_CMN_CTRL1 or PHY_PCS_ISO_LINK_CTRL fails, tp_phy_on() > returns an error without re-asserting the resets it deasserted and without > incrementing phy->power_count, so tp_phy_off() will not be called to clean > them up. It was indeed a bug, and fixed in v2. Return value of tp_dp_run() is now taken into account. Also reset handling was completely rework. > > + > > +static int tp_phy_off(struct phy *phy) > > +{ > > + struct tp_link *inst =3D phy_get_drvdata(phy); > > + struct tp_phy *tp_phy =3D dev_get_drvdata(phy->dev.parent); > > + int ret; > > + > > + guard(mutex)(&tp_phy->lock); > > + > > + ret =3D reset_control_assert(inst->lnk_rst); > > + if (ret) > > + return ret; > > + > > + if (tp_phy->nb_phy_on =3D=3D 1) { > > + ret =3D reset_control_assert(tp_phy->phy_rst); > > + if (ret) > > + return ret; > > + } > > + > > + tp_phy->nb_phy_on--; > > + return 0; > > +} >=20 > [Severity: High] > Can tp_phy_off() underflow tp_phy->nb_phy_on when tp_phy->already_configu= red > is true? >=20 > When tp_phy->already_configured is true, tp_phy_on() returns early without > incrementing nb_phy_on (leaving it at 0), but tp_phy_off() has no > already_configured check: it asserts inst->lnk_rst and decrements the u8 > nb_phy_on counter from 0 to 255. A subsequent phy_power_on() then either > returns early with inst->lnk_rst still asserted, or after system suspend > clears already_configured, sees nb_phy_on !=3D 0, skips deasserting > tp_phy->phy_rst, and times out waiting for CMN ready. It was indeed a bug, and fixed in v2. Increment nb_phy_on when returning ea= rly. =20 > [ ... ] >=20 > > +static int tp_ref_clk_init(const struct tp_phy *tp_phy, struct clk *cl= k, const char *name, > > + u32 *p_ref_clk_khz) > > +{ > > + struct device *dev =3D tp_phy->dev; > > + u32 ref_clk_rate; > > + int ret; > > + > > + ret =3D clk_prepare_enable(clk); > > + if (ret) { > > + dev_err(dev, "Failed to prepare %s ref clock: %d\n", name, ret); > > + return ret; > > + } > > + > > + ref_clk_rate =3D clk_get_rate(clk); > > + if (!ref_clk_rate) { > > + dev_err(dev, "Failed to get %s ref clock rate\n", name); > > + ret =3D -EINVAL; > > + goto disable_clk; > > + } > > + > > + for (u8 i =3D 0; i < tp_phy->nb_links; ++i) { > > + if (!tp_is_ref_freq_supported(tp_phy->links[i].type, ref_clk_rate)) { > > + dev_err(dev, "Invalid ref clock rate: %u Hz\n", ref_clk_rate); > > + ret =3D -EINVAL; > > + goto disable_clk; > > + } > > + } >=20 > [Severity: Medium] > Does this loop skip reference clock validation during probe and reject > valid dual-refclk configurations during resume? >=20 > In cdns_torrent_phy_probe(), tp_ref_clks_init() is called before the child > subnodes are parsed, so tp_phy->nb_links is 0 and this loop does not run > at probe time (allowing unsupported clock rates, or rates < 1000 Hz that > set ref_clk_khz to 0 and divide by zero in tp_write_pll_regs()). Then in > tp_resume_noirq(), where nb_links > 0, tp_ref_clk_init() checks every link > against both tp_phy->clk and tp_phy->clk1 instead of only the links using > that PLL, failing resume with -EINVAL when PLL0 and PLL1 use different > protocol-specific reference frequencies. It was indeed a bug, and fixed in v2. The functions call were reordered. =20 > [ ... ] >=20 > > +static void tp_check_multiple_pcie_links(struct tp_phy *tp_phy) > > +{ > > + struct tp_standard *std0 =3D &tp_phy->standards[0]; > > + u32 num_pcie_links =3D 0; > > + > > + /* First check if the first standard is PCIe */ > > + if (std0->type !=3D STD_TYPE_PCIE) > > + return; > > + > > + /* Count the number of links with PCIe protocol. */ > > + for (u8 i =3D 0; i < tp_phy->nb_links; ++i) { > > + if (tp_phy->links[i].type =3D=3D STD_TYPE_PCIE) > > + num_pcie_links++; > > + } > > + > > + /* PCIe Multilink configuration can be supported along with a non-PCI= e protocol. > > + * Such configurations are handled by adding a flag named STD_FLAG_PC= IE_ML > > + */ > > + if (num_pcie_links > 1) > > + std0->flags |=3D STD_FLAG_PCIE_ML; > > +} >=20 > [Severity: Medium] > Does tp_check_multiple_pcie_links() miss multi-link PCIe when a non-PCIe > subnode appears first in Device Tree? >=20 > tp_add_phy_from_of_subnode() populates tp_phy->standards[] in DT subnode > order, so if phy@0 is USB or SGMII and phy@1 and phy@2 are PCIe, PCIe is = in > standards[1] when tp_check_multiple_pcie_links() runs. Because > tp_check_multiple_pcie_links() only checks standards[0], it returns witho= ut > setting STD_FLAG_PCIE_ML, and when tp_find_link_cfg() subsequently swaps > standards[0] and standards[1], the driver matches single-link PCIe > (STD0_PCIE_SL) instead of multi-link PCIe (STD0_PCIE_ML). It was indeed a bug, and fixed in v2. Both standards are now checked. > [ ... ] >=20 > > +static int tp_find_link_cfg(struct tp_phy *tp_phy) > > +{ > > + const struct tp_link_cfg *link_cfg; > > + struct device *dev =3D tp_phy->dev; > > + struct tp_standard *std0 =3D &tp_phy->standards[0]; > > + struct tp_standard *std1 =3D &tp_phy->standards[1]; > > + > > + /* Verify the validity of standard index in links */ > > + for (u8 i =3D 0; i < tp_phy->nb_links; ++i) { > > + const struct tp_link *link =3D &tp_phy->links[i]; > > + > > + if (WARN_ON(link->std_idx >=3D MAX_NUM_STANDARDS)) > > + return -EINVAL; > > + } > > + > > + link_cfg =3D tp_find_link_cfg_from_standards(std0, std1); > > + > > + /* Only swap the two standards if PLL1 has no dedicated reference clo= ck */ > > + if (!link_cfg && !tp_phy->clk1) { > > + link_cfg =3D tp_find_link_cfg_from_standards(std1, std0); > > + if (link_cfg) { > > + /* Swap the 2 standards */ > > + swap(tp_phy->standards[0], tp_phy->standards[1]); > > + > > + for (u8 i =3D 0; i < tp_phy->nb_links; ++i) > > + tp_phy->links[i].std_idx ^=3D 1; > > + } > > + } >=20 > [Severity: Medium] > Why is swapping standards[0] and standards[1] disallowed when tp_phy->clk1 > is present? >=20 > standards[0] and standards[1] are populated in DT child subnode order (la= ne > order), whereas tp_link_cfgs[] orders entries by PLL assignment (std0 on > PLL0 clocked by refclk, std1 on PLL1 clocked by pll1_refclk). When > pll1_refclk is provided and the protocol on lower lanes (phy@0) uses PLL1 > (for example, USXGMII on phy@0 with PLL1 at 156.25 MHz and PCIe on phy@2 > with PLL0 at 100 MHz), refusing to swap standards[0] and standards[1] > causes tp_find_link_cfg() to fail probe with -EINVAL. A better comment was added to explain why swapping standards are disallowed when clk1 is present. > [ ... ] >=20 > > +static void tp_phy_cleanup(const struct tp_phy *tp_phy) > > +{ > > + reset_control_assert(tp_phy->phy_rst); > > + reset_control_assert(tp_phy->apb_rst); > > + > > + for (u8 i =3D 0; i < tp_phy->nb_links; ++i) { > > + reset_control_assert(tp_phy->links[i].lnk_rst); > > + reset_control_put(tp_phy->links[i].lnk_rst); > > + } > > + > > + clk_disable_unprepare(tp_phy->clk1); > > + clk_disable_unprepare(tp_phy->clk); > > + tp_clk_cleanup(tp_phy); > > +} >=20 > [Severity: Medium] > Can tp_phy_cleanup() call clk_disable_unprepare() on clocks that were nev= er > enabled or were already disabled? >=20 > In cdns_torrent_phy_probe(), jumping to cleanup when tp_of_get_clk() fails > on pll1_refclk after acquiring tp_phy->clk, when tp_ref_clks_init() fails > (after already disabling any clock it enabled), or when tp_phy->already_c= onfigured > is true (where tp_ref_clks_init() is skipped, which also affects > cdns_torrent_phy_remove()) unconditionally calls clk_disable_unprepare() = on > tp_phy->clk1 and tp_phy->clk, triggering clock enable/prepare count > underflow warnings. It was indeed a bug, and fixed in v2. A new variable was added named ref_clks_initialized to track the state of ref clocks init. > [ ... ] >=20 > > +static int tp_suspend_noirq(struct device *dev) > > +{ > > + struct tp_phy *tp_phy =3D dev_get_drvdata(dev); > > + > > + tp_refclk_driver_suspend(tp_phy); > > + > > + for (u8 i =3D 0; i < tp_phy->nb_links; ++i) > > + reset_control_assert(tp_phy->links[i].lnk_rst); > > + > > + reset_control_assert(tp_phy->phy_rst); > > + reset_control_assert(tp_phy->apb_rst); > > + > > + if (tp_phy->already_configured) { > > + tp_phy->already_configured =3D false; > > + } else { > > + clk_disable_unprepare(tp_phy->clk1); > > + clk_disable_unprepare(tp_phy->clk); > > + } > > + > > + return 0; > > +} > > + > > +static int tp_resume_noirq(struct device *dev) > > +{ > > + int ret; > > + struct tp_phy *tp_phy =3D dev_get_drvdata(dev); > > + > > + ret =3D tp_refclk_driver_resume(tp_phy); > > + if (ret) > > + return ret; > > + > > + ret =3D tp_ref_clks_init(tp_phy); > > + if (ret) > > + return ret; > > + > > + /* Enable APB */ > > + reset_control_deassert(tp_phy->apb_rst); > > + > > + ret =3D tp_configure_links(tp_phy); > > + if (ret) > > + goto put_lnk_rst; > > + > > + return 0; >=20 > [Severity: High] > Does tp_resume_noirq() leave active links held in reset after suspend? >=20 > tp_suspend_noirq() asserts lnk_rst for every link and asserts phy_rst > without changing tp_phy->nb_phy_on, but tp_resume_noirq() only deasserts > apb_rst and calls tp_configure_links() without deasserting phy_rst or > lnk_rst. Consumers that keep their PHY powered on across suspend (such as > am65-cpsw-nuss for SGMII/QSGMII/USXGMII) are left held in reset after > resume, and sibling consumers on the same SERDES that call > phy_power_off()/phy_power_on() across suspend/resume (such as pci-j721e) > see tp_phy->nb_phy_on !=3D 0 in tp_phy_on(), skip deasserting phy_rst, and > time out waiting for CMN ready. It was indeed a bug, and fixed in v2. The suspend/resume part was completely reworked. > > + > > +put_lnk_rst: > > + > > + for (u8 i =3D 0; i < tp_phy->nb_links; ++i) > > + reset_control_assert(tp_phy->links[i].lnk_rst); > > + > > + reset_control_assert(tp_phy->apb_rst); > > + reset_control_assert(tp_phy->phy_rst); > > + > > + clk_disable_unprepare(tp_phy->clk1); > > + clk_disable_unprepare(tp_phy->clk); > > + > > + return ret; > > +} > > + > > +static DEFINE_NOIRQ_DEV_PM_OPS(tp_pm_ops, tp_suspend_noirq, tp_resume_= noirq); > > + > > +static int cdns_torrent_phy_probe(struct platform_device *pdev) > > +{ >=20 > [ ... ] >=20 > > + tp_reg_bases_init(tp_phy); > > + tp_reg_fields_init(tp_phy); > > + > > + ret =3D tp_read_techno_revision(tp_phy); > > + if (ret) > > + return ret; > > + > > + ret =3D tp_clk_register(tp_phy); > > + if (ret) > > + return ret; > > + > > + ret =3D tp_of_get_reset(tp_phy); > > + if (ret) > > + goto cleanup; > > + > > + ret =3D tp_of_get_clk(tp_phy); > > + if (ret) > > + goto cleanup; > > + > > + tp_phy->already_configured =3D tp_is_already_configured(tp_phy); > > + if (!tp_phy->already_configured) { > > + ret =3D tp_ref_clks_init(tp_phy); > > + if (ret) > > + goto cleanup; > > + > > + /* Enable APB */ > > + reset_control_deassert(tp_phy->apb_rst); > > + } >=20 > [Severity: High] > Are CDB registers accessed here and in tp_resume_noirq() while > tp_phy->apb_rst is still asserted? >=20 > cdns_torrent_phy_probe() reads the PHY ID registers in > tp_read_techno_revision(), writes CMN_CDIAG_REFCLK_DRV0_CTRL in > tp_clk_register(), and reads PHY_PMA_CMN_CTRL1 in > tp_is_already_configured() before tp_of_get_reset() and > reset_control_deassert(tp_phy->apb_rst) run. Similarly, tp_resume_noirq() > calls tp_refclk_driver_resume() (reading and writing > CMN_CDIAG_REFCLK_DRV0_CTRL) before deasserting tp_phy->apb_rst, which was > asserted in tp_suspend_noirq(). On platforms using the torrent_apb reset > (or when re-probing after driver removal, which asserts apb_rst), accessi= ng > CDB registers while APB is in reset can fail probe with -ENODEV, lose > register writes, or fault. It was indeed a bug, and fixed in v2. APB reset is now deasserted before accessing any register. =2D-=20 Benjamin Robin, Bootlin Embedded Linux and Kernel engineering https://bootlin.com