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=1796231907; b=KVPu3FRdKAaEGQJ21ahyICBdQjFvTNAh2NyMUA/BqyKlpsLWwuvaEDqzVI2o7FlG8D3c bHv5Ph60l7sbigut60JY+2Q0TFVazW53A5LPGbFNDQ7VPJ7+iMbJcOPMj+BbvzprUHXZU PCUDDpDXtf4OC/qaw6X1mneVkx6kgbU1EilNdsxRMw0xalIahqDtxAo6zEXPH7ltjiNpQ VTuzVe9tB2PP8efIzxKuPxpU3mOBR9V2dsy28bqkn9LxqyJ1MNCsqe+viI8kr5PvpMRCJ 48r0rAqH71zuI184KMX+m9bcey/4YUfL/6+hqrigB/0GXly9LLnkGtfOwFc7UxurVyQ== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796231907; 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=TcQL7rWLyiCxlDXshow0qSOgcJqMxIhM61JXwmJx4ng=; b=MjUfzxliqDLV0OGEpzeFcKAY56/5zyl+8Bk5YJwkbNjqG1x8/dwvPDHECcGaJTTLvJ+r fgQznFUeizjPwjO88hoJeeA0DxqVX+EHw+85Z2RcMSoCIpsQG2O/P7jKw7wJ1UuJD+wz1 6+/fWjOhl6mY9Da4srox6SyDQoqZBbTlSE2v+tnpqPD71VOCVQzbnpDZDUaPuly+CsVqQ ET2VBdQXbBEfAjwimtLltgAFsHe9pGYBaHsU4bLdo1AsFZCwP71FTZSXtKQD6HHbSYXkg 4kPi4lJA4c36L9x6FhYbZ3jO2gdOCzUOVyq47efeOgt1t1118s+9C2GyEIE4EqqA/2w== 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=J2YpXNDw; 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 E87CA606A31A for ; Wed, 2 Dec 2026 17:18:26 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org E87CA606A31A 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=J2YpXNDw Received: from smtpout-01.galae.net (smtpout-01.galae.net [212.83.139.233]) by smtpout-02.galae.net (Postfix) with ESMTPS id 654481A18E5; Wed, 2 Dec 2026 17:18:25 +0000 (UTC) Received: from mail.galae.net (mail.galae.net [212.83.136.155]) by smtpout-01.galae.net (Postfix) with ESMTPS id 383716075F; Wed, 2 Dec 2026 17:18:25 +0000 (UTC) Received: from [127.0.0.1] (localhost [127.0.0.1]) by localhost (Mailerdaemon) with ESMTPSA id 2D8FF11EA1808; Wed, 02 Dec 2026 18:18:21 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=dkim; t=1796231904; h=from:subject:date:message-id:to:cc:mime-version:content-type: content-transfer-encoding:in-reply-to:references; bh=TcQL7rWLyiCxlDXshow0qSOgcJqMxIhM61JXwmJx4ng=; b=J2YpXNDwIRi4gSjxHhDdIYR4ckQ9VhEq107T93jnRS/+NepSQOy3G7cXcNp7rDEp4lHVde pznfaSrm4jiaH8/osLLMrwPZjNl6HI8708gfXbwT+UH2y31N4jEukvjcyhi5pfE1A0CY8H vp4iBRJHSckI2Tew0/2tbrbcyMFsJ/JYSfCB3jLIMyFLT7vBm0JdqD0OuQN/iyUZnbS+DP LtrxBZ7LFZuMk9+PTWlaQfOgpzLFXefPgqR9ktV9rop9eDM70Bz7/7WPE6UOIUMzclTrHN ON6vLq7Gmeg0Tyqjmcbh7EZkll8vkahy/QbCJxg313MTL8fUM5D/j78rp80Tqw== From: Benjamin Robin To: sashiko-reviews@lists.linux.dev Cc: devicetree@vger.kernel.org, dri-devel@lists.freedesktop.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 v2 21/22] phy: cadence-torrent: rewrite Torrent PHY driver Date: Wed, 02 Dec 2026 18:18:20 +0100 Message-ID: In-Reply-To: References: <20261202-phy-cadence-torrent-ng-v2-0-0b493387347b@bootlin.com> <20261202-phy-cadence-torrent-ng-v2-21-0b493387347b@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 Wednesday, December 2, 2026 at 4:38=E2=80=AFPM, sashiko-bot@kernel.org w= rote: > Thank you for your contribution! Sashiko AI review found 8 potential > issues to consider: > - [High] phy: cadence-torrent: broken QSGMII mode check in > tp_add_phy_from_of_subnode() > - [High] phy: cadence-torrent: divide-by-zero in tp_dp_update_pll_freq() > - [High] phy: cadence-torrent: NULL dereference of base in > tp_dp_find_used_lanes() > - [High] phy: cadence-torrent: A3 timeout on unused DP lanes and partial > lane config > - [High] phy: cadence-torrent: NULL deref, div-by-zero, and reset bug if > preconfigured > - [Medium] phy: cadence-torrent: wrong std1 initialization in > tp_calc_pll_fb_div_modes() > - [Medium] phy: cadence-torrent: broken dual-refclk validation in > tp_ref_clk_init() > - [Medium] phy: cadence-torrent: rejected standard swap with clk1 in > tp_find_link_cfg() > -- >=20 > commit 107a7c6a980951f00c775c6427a095f0f4912099 > Author: Benjamin Robin >=20 > phy: cadence-torrent: rewrite Torrent PHY driver >=20 > This commit rewrites the Cadence Torrent PHY driver to compute reference > clock and PLL register values at run time and select protocol, revision, > and process-node settings from compact configuration tables instead of > hard-coded register arrays. >=20 > > diff --git a/drivers/phy/cadence/phy-cadence-torrent.c b/drivers/phy/ca= dence/phy-cadence-torrent.c > > index 7c4c20b005a95..21ad6c30a3f20 100644 > > --- a/drivers/phy/cadence/phy-cadence-torrent.c > > +++ b/drivers/phy/cadence/phy-cadence-torrent.c >=20 > [ ... ] >=20 > > +static void tp_calc_pll_fb_div_modes(struct tp_data *tp_data) > > + if ((std0->flags & STD_FLAG_PCIE_ML) || std1->type =3D=3D STD_TYPE_N= ONE) > > + tp_data->plls[PLL1_MODE0].fb_div_mode =3D div_mode; > > + else > > + tp_data->plls[PLL1_MODE0].fb_div_mode =3D PLL_FB_DIV_MODE_FBR; >=20 > [Severity: Medium] > Should std1 be initialized to &tp_data->standards[1] instead of > &tp_data->standards[0]? >=20 > Because std1 points to standards[0], std1->type =3D=3D STD_TYPE_NONE is a= lways > false inside the std0->type =3D=3D STD_TYPE_PCIE branch, so single-link P= CIe > configurations set plls[PLL1_MODE0].fb_div_mode to PLL_FB_DIV_MODE_FBR > instead of div_mode. This is indeed a bug, and will be fixed in v3. > [ ... ] >=20 > > +static int tp_dp_update_pll_freq(struct tp_data *tp_data, const struct= tp_link *link, > > + enum tp_pll_id pll_id, u32 bit_rate, bool ssc) > > { > > - struct tp_refclk_driver *refclk =3D tp_refclk_driver_to_clk_data(hw); > > - > > - tp_reg_field_write(&refclk->fields[CMN_CDIAG_REFCLK_DRV0_CTRL_6], 0); > > - tp_reg_field_write(&refclk->fields[CMN_CDIAG_REFCLK_DRV0_CTRL_5], 1); > > - tp_reg_field_write(&refclk->fields[CMN_CDIAG_REFCLK_DRV0_CTRL_1], 0); > > + const struct tp_link_cfg *link_cfg =3D tp_data->link_cfg; > > + struct tp_pll_data *pll =3D &tp_data->plls[pll_id]; > > + u32 pll_freq_khz =3D 0; > > + u16 val; > > =20 > > - return 0; > > -} > > + if (link_cfg->pll_freq[pll_id] !=3D PLL_DP) > > + return -EINVAL; > > =20 > > -static void tp_refclk_driver_disable(struct clk_hw *hw) > > -{ > > - struct tp_refclk_driver *refclk =3D tp_refclk_driver_to_clk_data(hw); > > + pll_freq_khz =3D tp_dp_pll_freq_from_bit_rate(bit_rate); > > + if (pll_freq_khz =3D=3D 0) > > + return -EINVAL; > > =20 > > - tp_reg_field_write(&refclk->fields[CMN_CDIAG_REFCLK_DRV0_CTRL_1], 1); > > -} > > + pll->freq_khz =3D pll_freq_khz; > > + pll->ssc =3D ssc; > > + pll->fractional_mode =3D tp_is_pll_fractional_mode_required(pll); > > =20 > > -static int tp_refclk_driver_is_enabled(struct clk_hw *hw) > > -{ > > - struct tp_refclk_driver *refclk =3D tp_refclk_driver_to_clk_data(hw); > > - u16 val; > > + val =3D tp_dp_pll_clk_sel_from_bit_rate(bit_rate); > > + tp_reg_write(&tp_data->reg_common_cdb, CMN_PDIAG_PLLx_CLK_SEL_Mx(pll_= id), val); > > =20 > > - val =3D tp_reg_field_read(&refclk->fields[CMN_CDIAG_REFCLK_DRV0_CTRL_= 1]); > > - return !val; > > -} > > + val =3D tp_dp_xcvr_diag_hsclk_div_from_bit_rate(bit_rate); > > + tp_write_lanes_reg(tp_data->reg_tx_lane_cdb, link->mlane, link->max_l= anes, > > + XCVR_DIAG_HSCLK_DIV, val); > > =20 > > -static u8 tp_refclk_driver_get_parent(struct clk_hw *hw) > > -{ > > - struct tp_refclk_driver *refclk =3D tp_refclk_driver_to_clk_data(hw); > > - u16 val; > > + tp_write_pll_lock_tmr(tp_data, pll_id); > > + tp_write_pll_regs(tp_data, pll_id); >=20 > [Severity: High] > Can tp_dp_update_pll_freq() divide by zero when tp_data->already_configur= ed > was true at probe time? >=20 > When tp_data->already_configured is true, cdns_torrent_phy_probe() skips > both tp_ref_clks_init() and tp_configure_links() (and tp_resume_noirq() > also skips tp_configure_links() -> tp_init_plls_data() if nb_phy_on > 0 a= nd > the PHY remained configured), leaving tp_data->ref_clk_khz and > pll->ref_clk_khz at 0. Calling phy_configure() with opts->dp.set_rate set > then reaches tp_dp_update_pll_freq(), where > tp_is_pll_fractional_mode_required() and tp_write_pll_regs() divide by > pll->ref_clk_khz. This is indeed a bug. Previously the configuration was completely disabled. In the v3 the rate configuration will only be allowed if the reference clock was initialized. =20 > [ ... ] >=20 > > +/* Configure link rate as required. */ > > +static int tp_dp_set_rate(struct tp_data *tp_data, struct tp_link *lin= k, > > + const struct phy_configure_opts_dp *dp) > > +{ > > + int ret; > > =20 > > -static const struct cdns_torrent_vals usb_sgmii_xcvr_diag_ln_vals =3D { > > - .reg_pairs =3D usb_sgmii_xcvr_diag_ln_regs, > > - .num_regs =3D ARRAY_SIZE(usb_sgmii_xcvr_diag_ln_regs), > > -}; > > + ret =3D tp_dptx_set_power_state(tp_data, link->mlane, link->max_lanes= , POWERSTATE_A3); > > + if (ret) > > + return ret; >=20 > [Severity: High] > Does tp_dptx_set_power_state() time out here when reconfiguring the link > rate while link->num_lanes < link->max_lanes? >=20 > When fewer than link->max_lanes lanes are active (for example 1 or 2 lanes > on a 4-lane DP link) and phy_configure() updates the link rate without > changing the lane count, the active lanes are in POWERSTATE_A0 while unus= ed > lanes are held in reset with PHY_PMA_XCVR_PLLCLK_EN cleared. Passing > link->max_lanes to tp_dptx_set_power_state() causes (read_val & mask) to = be > non-zero, and readl_poll_timeout() then waits for the reset lanes to > acknowledge POWERSTATE_A3 in PHY_PMA_XCVR_POWER_STATE_ACK and fails with > -ETIMEDOUT. >=20 > In addition, tp_configure_links() programs per-lane CDB registers only up > to link->num_lanes instead of link->max_lanes, which leaves upper lanes > unconfigured after a suspend/resume cycle if the lane count is later > increased. This might be an issue. In v3 for the lanes in reset, do not try to go to POWERSTATE_A3 (ask 0), so it should fix the issue. =20 > [ ... ] >=20 > > +static int tp_phy_on(struct phy *phy) > > +{ > > + struct tp_link *link =3D phy_get_drvdata(phy); > > + struct tp_data *tp_data =3D dev_get_drvdata(phy->dev.parent); > > + u16 val; > > + int ret; > > =20 > > -static const struct cdns_torrent_vals pcie_sgmii_xcvr_diag_ln_vals =3D= { > > - .reg_pairs =3D pcie_sgmii_xcvr_diag_ln_regs, > > - .num_regs =3D ARRAY_SIZE(pcie_sgmii_xcvr_diag_ln_regs), > > -}; > > + guard(mutex)(&tp_data->lock); > > =20 > > -static const struct cdns_torrent_vals sgmii_pcie_xcvr_diag_ln_vals =3D= { > > - .reg_pairs =3D sgmii_pcie_xcvr_diag_ln_regs, > > - .num_regs =3D ARRAY_SIZE(sgmii_pcie_xcvr_diag_ln_regs), > > -}; > > + if (tp_data->already_configured) { > > + /* Give 5ms to 10ms delay for the PIPE clock to be stable */ > > + usleep_range(5000, 10000); > > + tp_data->nb_phy_on++; > > + return 0; > > + } >=20 > [ ... ] >=20 > > +static int tp_phy_off(struct phy *phy) > > +{ > > + struct tp_link *link =3D phy_get_drvdata(phy); > > + struct tp_data *tp_data =3D dev_get_drvdata(phy->dev.parent); > > + int ret; > > =20 > > -static const struct cdns_torrent_vals qsgmii_100_no_ssc_cmn_vals =3D { > > - .reg_pairs =3D qsgmii_100_no_ssc_cmn_regs, > > - .num_regs =3D ARRAY_SIZE(qsgmii_100_no_ssc_cmn_regs), > > -}; > > + guard(mutex)(&tp_data->lock); > > =20 > > -static const struct cdns_torrent_vals qsgmii_100_no_ssc_tx_ln_vals =3D= { > > - .reg_pairs =3D qsgmii_100_no_ssc_tx_ln_regs, > > - .num_regs =3D ARRAY_SIZE(qsgmii_100_no_ssc_tx_ln_regs), > > -}; > > + ret =3D tp_control_link_reset(link, true); > > + if (ret) > > + return ret; > > =20 > > -static const struct cdns_torrent_vals ti_qsgmii_100_no_ssc_tx_ln_vals = =3D { > > - .reg_pairs =3D ti_qsgmii_100_no_ssc_tx_ln_regs, > > - .num_regs =3D ARRAY_SIZE(ti_qsgmii_100_no_ssc_tx_ln_regs), > > -}; > > + if (tp_data->nb_phy_on =3D=3D 1) { > > + ret =3D reset_control_assert(tp_data->phy_rst); > > + if (ret) > > + return ret; > > + } > > =20 > > -static const struct cdns_torrent_vals qsgmii_100_no_ssc_rx_ln_vals =3D= { > > - .reg_pairs =3D qsgmii_100_no_ssc_rx_ln_regs, > > - .num_regs =3D ARRAY_SIZE(qsgmii_100_no_ssc_rx_ln_regs), > > -}; > > + tp_data->nb_phy_on--; > > + return 0; > > +} >=20 > [Severity: High] > What happens if a pre-configured PHY (tp_data->already_configured =3D=3D = true) > is powered off and then powered back on? >=20 > tp_phy_off() asserts link->lnk_rst and tp_data->phy_rst without clearing > tp_data->already_configured, so a subsequent tp_phy_on() takes the early > already_configured return and leaves both resets asserted and the PHY > unconfigured. In addition, when tp_data->already_configured is true at > probe time, tp_dp_find_used_lanes() dereferences tp_data->base while it is > still NULL and tp_dp_update_pll_freq() divides by zero because > ref_clk_khz is never initialized. This might be an issue. In v3 if already_configured then the resets will be controlled normally from tp_phy_on(). The NULL dereference is indeed a bug. To fix it tp_dp_reg_base_init() will be called earlier in the probe. > [ ... ] >=20 > > +static int tp_ref_clk_init(const struct tp_data *tp_data, struct clk *= clk, const char *name, > > + u32 *p_ref_clk_khz) > > +{ > > + struct device *dev =3D tp_data->dev; > > + u32 ref_clk_rate; > > + int ret; > > =20 > > - {CDNS_TORRENT_KEY(CLK_100_MHZ, CLK_100_MHZ, TYPE_QSGMII, TYPE_SGMII, = NO_SSC), &qsgmii_100_no_ssc_rx_ln_vals}, > > + ret =3D clk_prepare_enable(clk); > > + if (ret) { > > + dev_err(dev, "Failed to prepare %s ref clock: %d\n", name, ret); > > + return ret; > > + } > > =20 > > - {CDNS_TORRENT_KEY(CLK_100_MHZ, CLK_100_MHZ, TYPE_QSGMII, TYPE_USB, NO= _SSC), &qsgmii_100_no_ssc_rx_ln_vals}, > > - {CDNS_TORRENT_KEY(CLK_100_MHZ, CLK_100_MHZ, TYPE_QSGMII, TYPE_USB, EX= TERNAL_SSC), &qsgmii_100_no_ssc_rx_ln_vals}, > > - {CDNS_TORRENT_KEY(CLK_100_MHZ, CLK_100_MHZ, TYPE_QSGMII, TYPE_USB, IN= TERNAL_SSC), &qsgmii_100_no_ssc_rx_ln_vals}, > > + 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; > > + } > > =20 > > - {CDNS_TORRENT_KEY(CLK_100_MHZ, CLK_100_MHZ, TYPE_USB, TYPE_NONE, NO_S= SC), &usb_100_no_ssc_rx_ln_vals}, > > - {CDNS_TORRENT_KEY(CLK_100_MHZ, CLK_100_MHZ, TYPE_USB, TYPE_NONE, EXTE= RNAL_SSC), &usb_100_no_ssc_rx_ln_vals}, > > - {CDNS_TORRENT_KEY(CLK_100_MHZ, CLK_100_MHZ, TYPE_USB, TYPE_NONE, INTE= RNAL_SSC), &usb_100_no_ssc_rx_ln_vals}, > > + for (u8 i =3D 0; i < tp_data->nb_links; ++i) { > > + if (!tp_is_ref_freq_supported(tp_data->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 validating ref_clk_rate against all links in tp_data->links[] reject > valid dual-reference-clock configurations? >=20 > When both refclk (PLL0) and pll1_refclk (PLL1) are provided, > tp_ref_clks_init() calls tp_ref_clk_init() for each clock, and this loop > requires both frequencies to be supported by every link's standard. A > setup such as SATA at 100 MHz on PLL0 with USXGMII at 156.25 MHz on PLL1 > fails probe with -EINVAL because 156.25 MHz is not in SATA's supported > frequency list (freq_set4). I largely agree with this remark, but this is the current behavior of the Cadence "Torrent Programmers Guide" spreadsheet. So for now, keep the same behavior as documented by Cadence, but that seems a bit strange. > [ ... ] >=20 > > + switch (phy_type) { > > + case PHY_TYPE_PCIE: > > + std_type =3D STD_TYPE_PCIE; > > + break; > > + case PHY_TYPE_USB3: > > + std_type =3D STD_TYPE_USB_TXRX; > > + supported_flags =3D CDNS_TORRENT_MODE_USB_G1 | CDNS_TORRENT_MODE_USB= _IO_11V; > > + break; > > + case PHY_TYPE_DP: > > + std_type =3D STD_TYPE_DP; > > + break; > > + case PHY_TYPE_XAUI: > > + std_type =3D STD_TYPE_XAUI; > > + supported_flags =3D CDNS_TORRENT_MODE_XAUI_LP; > > + break; > > + case PHY_TYPE_SGMII: > > + std_type =3D STD_TYPE_SGMII; > > + supported_flags =3D CDNS_TORRENT_MODE_2500_BASEX; > > + break; > > + case PHY_TYPE_QSGMII: > > + std_type =3D STD_TYPE_SGMII; > > + link_flags |=3D STD_FLAG_QSGMII; > > + break; > > + case PHY_TYPE_SATA: > > + std_type =3D STD_TYPE_SATA; > > + supported_flags =3D CDNS_TORRENT_MODE_SATA_LP; > > + break; > > + case PHY_TYPE_USXGMII: > > + std_type =3D STD_TYPE_USXGMII; > > + break; > > + default: > > + dev_err(dev, "Unsupported protocol: %u\n", phy_type); > > + return -EINVAL; > > + } > > =20 > > - {CDNS_TORRENT_KEY(CLK_100_MHZ, CLK_100_MHZ, TYPE_USB, TYPE_PCIE, NO_S= SC), &usb_100_no_ssc_tx_ln_vals}, > > - {CDNS_TORRENT_KEY(CLK_100_MHZ, CLK_100_MHZ, TYPE_USB, TYPE_PCIE, EXTE= RNAL_SSC), &usb_100_no_ssc_tx_ln_vals}, > > - {CDNS_TORRENT_KEY(CLK_100_MHZ, CLK_100_MHZ, TYPE_USB, TYPE_PCIE, INTE= RNAL_SSC), &usb_100_no_ssc_tx_ln_vals}, > > + if (link_flags & ~supported_flags) { > > + dev_err(dev, "Unsupported modes 0x%X for this PHY type %u\n", > > + link_flags, std_type); > > + return -EINVAL; > > + } >=20 > [Severity: High] > Does PHY_TYPE_QSGMII always fail this check with -EINVAL? >=20 > The PHY_TYPE_QSGMII case sets STD_FLAG_QSGMII in link_flags while leaving > supported_flags at 0, so (link_flags & ~supported_flags) is always > non-zero. This is indeed a bug introduced while refactoring and removing the QSGMII f= lag from dt-bindings. This will be fixed in v3. =20 > [ ... ] >=20 > > + link_cfg =3D tp_find_link_cfg_from_standards(std0, std1); > > =20 > > - {CDNS_TORRENT_KEY(CLK_100_MHZ, CLK_100_MHZ, TYPE_USB, TYPE_PCIE_ML, N= O_SSC), &usb_100_no_ssc_cmn_vals}, > > - {CDNS_TORRENT_KEY(CLK_100_MHZ, CLK_100_MHZ, TYPE_USB, TYPE_PCIE_ML, E= XTERNAL_SSC), &usb_100_no_ssc_cmn_vals}, > > - {CDNS_TORRENT_KEY(CLK_100_MHZ, CLK_100_MHZ, TYPE_USB, TYPE_PCIE_ML, I= NTERNAL_SSC), &usb_100_no_ssc_cmn_vals}, > > + /* Only swap the two standards if PLL1 has no dedicated reference clo= ck. If > > + * there are two DTS PHY nodes and the `pll1_refclk` reference clock = is > > + * specified, the user assumes the PLL1 reference clock will be used = for the > > + * second DTS PHY node. If the standards are swapped, this clock woul= d be used > > + * for the first DTS PHY node instead, which could be a problem, for = example > > + * with USXGMII, which prefers a 156.25 MHz reference clock. > > + */ > > + if (!link_cfg && !tp_data->clk1) { > > + link_cfg =3D tp_find_link_cfg_from_standards(std1, std0); > > + if (link_cfg) { > > + /* Swap the 2 standards */ > > + swap(tp_data->standards[0], tp_data->standards[1]); > > + > > + for (u8 i =3D 0; i < tp_data->nb_links; ++i) > > + tp_data->links[i].std_idx ^=3D 1; > > + } > > + } >=20 > [Severity: Medium] > Does gating the (std1, std0) fallback lookup on !tp_data->clk1 break dual > reference clock setups where the first DT subnode uses the protocol routed > to PLL1? >=20 > tp_add_phy_from_of_subnode() populates standards[0] and standards[1] in DT > subnode order (typically ascending lane address, such as phy@0 then phy@2= ), > whereas in tp_link_cfgs[] std0 is always clocked by PLL0 (refclk) and std1 > by PLL1 (pll1_refclk), and most protocol pairs only exist in one PLL > assignment order (for example, PCIe must be std0 on PLL0). If phy@0 is > USXGMII (clocked by pll1_refclk on PLL1) and phy@2 is PCIe (clocked by > refclk on PLL0), tp_find_link_cfg_from_standards(std0, std1) returns NULL > and !tp_data->clk1 prevents swapping them to match their required PLL0 and > PLL1 assignment, failing probe with -EINVAL. The analysis is correct: this is currently not supported. If a user really wants to do that, they have to declare the sub-nodes in the "right" order: PCIe first, then USXGMII, even if the USXGMII reg is 0 (the first lane is lane 0). To support this use case, the only solution would be to add a new DTS property to indicate which PLL to use. The "old" driver behavior is even more broken in this regard, so the new code should not introduce any issue. > [ ... ] >=20 > > + tp_data->already_configured =3D tp_is_already_configured(tp_data); > > + if (!tp_data->already_configured) { > > + ret =3D tp_ref_clks_init(tp_data); > > + if (ret) > > + goto cleanup; > > + } else { > > + tp_init_already_configured_links_opts(tp_data); > > + } > > =20 > > - {CDNS_TORRENT_KEY(CLK_100_MHZ, CLK_100_MHZ, TYPE_USB, TYPE_QSGMII, NO= _SSC), &usb_100_no_ssc_tx_ln_vals}, > > - {CDNS_TORRENT_KEY(CLK_100_MHZ, CLK_100_MHZ, TYPE_USB, TYPE_QSGMII, EX= TERNAL_SSC), &usb_100_no_ssc_tx_ln_vals}, > > - {CDNS_TORRENT_KEY(CLK_100_MHZ, CLK_100_MHZ, TYPE_USB, TYPE_QSGMII, IN= TERNAL_SSC), &usb_100_no_ssc_tx_ln_vals}, > > + ret =3D tp_read_techno_revision(tp_data); > > + if (ret) > > + goto cleanup; > > =20 > > - {CDNS_TORRENT_KEY(CLK_100_MHZ, CLK_100_MHZ, TYPE_USB, TYPE_DP, NO_SSC= ), &usb_100_no_ssc_tx_ln_vals}, > > + tp_check_multiple_pcie_links(tp_data); > > =20 > > - {CDNS_TORRENT_KEY(CLK_100_MHZ, CLK_100_MHZ, TYPE_XAUI, TYPE_PCIE, NO_= SSC), &ti_xaui_100_no_ssc_tx_ln_vals}, > > + ret =3D tp_find_link_cfg(tp_data); > > + if (ret) > > + goto cleanup; > > =20 > > - {CDNS_TORRENT_KEY(CLK_156_25_MHZ, CLK_156_25_MHZ, TYPE_USXGMII, TYPE_= NONE, NO_SSC), &usxgmii_156_25_no_ssc_tx_ln_vals}, > > + ret =3D tp_dp_reg_base_init(pdev, tp_data); > > + if (ret) > > + goto cleanup; >=20 > [Severity: High] > Does tp_init_already_configured_links_opts() dereference a NULL > tp_data->base when a DisplayPort link is present? >=20 > For DisplayPort links, tp_init_already_configured_links_opts() calls > tp_dp_find_used_lanes() -> tp_reg_dptx_read(tp_data, PHY_RESET), which > reads from tp_data->base before tp_dp_reg_base_init() maps the DPTX > registers. This is indeed a bug, which was already mentioned: > In addition, when tp_data->already_configured is true at > probe time, tp_dp_find_used_lanes() dereferences tp_data->base while it is > still NULL and tp_dp_update_pll_freq() divides by zero because > ref_clk_khz is never initialized. To fix it tp_dp_reg_base_init() will be called earlier in the probe. =2D-=20 Benjamin Robin, Bootlin Embedded Linux and Kernel engineering https://bootlin.com