From nobody Thu Dec 18 04:59:29 2025 Received: from out-182.mta0.migadu.com (out-182.mta0.migadu.com [91.218.175.182]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 983162522B8 for ; Mon, 12 May 2025 16:10:58 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=91.218.175.182 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1747066260; cv=none; b=rIwUzuO7U1nOLCMwC8f0v+esTI2BmuMhz0pwhiRd16SlRTbUFHeOq7PyAwR5qtUPbWkATJEiRIiOiaWzVvSKSy1QWdcjddjSFg1NQuM7oE/yB9zaU6OWNmn8p/c+oLcJwbcwbsbKufsN2y6158oDLsY7BC0bkQ8JUVDDz0Hag0Q= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1747066260; c=relaxed/simple; bh=pQYMjoP8KLLBE4iI8UXsfZzxIWrzo2b+3EVxDRWtCZQ=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=iK4SfTtdkjVvOk46/bYFDH8goPfCmL5qjbLSNUuKvPlk+PCXKvxwXwR/fjfTVBdcZW0qbIklODT+4VFLSOAZjwqdLls01tuTB5ybd51F19FvPqggyzZiLoX4w7KJHbzBxcw3deqh4x85ZATTfEYml26nzUojRjWv1Ld9kGDPNKQ= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev; spf=pass smtp.mailfrom=linux.dev; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b=nc+Bgtwy; arc=none smtp.client-ip=91.218.175.182 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.dev Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b="nc+Bgtwy" X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1747066256; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=EeW99aUNrHsV5YdlA6peeJca2dzX7zAprTdpjPgwrXI=; b=nc+BgtwyD6WUgjTq34FU4v/XUT/gd7S2C2uHg8VfuGm06cKvltiF4+3XfZ8cow0VT7XEdb Jo7WyqIoOQ/WdQsEzvn/aUjWAEE1E5PwbueKzGmk+Fzh6RgcSJbCS6qX2YnCT44f3m9uL5 FnDOHRNG9wlI2b1Gpgc8P5EYkoWKXW8= From: Sean Anderson To: netdev@vger.kernel.org, Andrew Lunn , "David S . Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Russell King Cc: upstream@airoha.com, Kory Maincent , Simon Horman , Christian Marangi , linux-kernel@vger.kernel.org, Heiner Kallweit , Sean Anderson , Suraj Gupta , Michal Simek , Radhey Shyam Pandey , Robert Hancock , linux-arm-kernel@lists.infradead.org Subject: [net-next PATCH v4 08/11] net: axienet: Convert to use PCS subsystem Date: Mon, 12 May 2025 12:10:10 -0400 Message-Id: <20250512161013.731955-9-sean.anderson@linux.dev> In-Reply-To: <20250512161013.731955-1-sean.anderson@linux.dev> References: <20250512161013.731955-1-sean.anderson@linux.dev> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Migadu-Flow: FLOW_OUT Content-Type: text/plain; charset="utf-8" Convert the AXI Ethernet driver to use the PCS subsystem, including the new Xilinx PCA/PMA driver. Unfortunately, we must use a helper to work with bare MDIO nodes without a compatible. Signed-off-by: Sean Anderson Reviewed-by: Suraj Gupta Tested-by: Suraj Gupta --- Changes in v4: - Convert to dev-less pcs_put Changes in v3: - Select PCS_XILINX unconditionally drivers/net/ethernet/xilinx/Kconfig | 7 ++ drivers/net/ethernet/xilinx/xilinx_axienet.h | 4 +- .../net/ethernet/xilinx/xilinx_axienet_main.c | 104 ++++-------------- drivers/net/pcs/pcs-xilinx.c | 9 +- 4 files changed, 31 insertions(+), 93 deletions(-) diff --git a/drivers/net/ethernet/xilinx/Kconfig b/drivers/net/ethernet/xil= inx/Kconfig index 7502214cc7d5..9f130376e1eb 100644 --- a/drivers/net/ethernet/xilinx/Kconfig +++ b/drivers/net/ethernet/xilinx/Kconfig @@ -25,8 +25,15 @@ config XILINX_EMACLITE =20 config XILINX_AXI_EMAC tristate "Xilinx 10/100/1000 AXI Ethernet support" + depends on COMMON_CLK + depends on GPIOLIB depends on HAS_IOMEM + depends on OF + depends on PCS depends on XILINX_DMA + select MDIO_DEVICE + select OF_DYNAMIC + select PCS_XILINX select PHYLINK select DIMLIB help diff --git a/drivers/net/ethernet/xilinx/xilinx_axienet.h b/drivers/net/eth= ernet/xilinx/xilinx_axienet.h index 5ff742103beb..f46e862245eb 100644 --- a/drivers/net/ethernet/xilinx/xilinx_axienet.h +++ b/drivers/net/ethernet/xilinx/xilinx_axienet.h @@ -473,7 +473,6 @@ struct skbuf_dma_descriptor { * @dev: Pointer to device structure * @phylink: Pointer to phylink instance * @phylink_config: phylink configuration settings - * @pcs_phy: Reference to PCS/PMA PHY if used * @pcs: phylink pcs structure for PCS PHY * @switch_x_sgmii: Whether switchable 1000BaseX/SGMII mode is enabled in = the core * @axi_clk: AXI4-Lite bus clock @@ -553,8 +552,7 @@ struct axienet_local { struct phylink *phylink; struct phylink_config phylink_config; =20 - struct mdio_device *pcs_phy; - struct phylink_pcs pcs; + struct phylink_pcs *pcs; =20 bool switch_x_sgmii; =20 diff --git a/drivers/net/ethernet/xilinx/xilinx_axienet_main.c b/drivers/ne= t/ethernet/xilinx/xilinx_axienet_main.c index 054abf283ab3..9490ecb6fa43 100644 --- a/drivers/net/ethernet/xilinx/xilinx_axienet_main.c +++ b/drivers/net/ethernet/xilinx/xilinx_axienet_main.c @@ -35,6 +35,8 @@ #include #include #include +#include +#include #include #include #include @@ -2519,63 +2521,6 @@ static const struct ethtool_ops axienet_ethtool_ops = =3D { .get_rmon_stats =3D axienet_ethtool_get_rmon_stats, }; =20 -static struct axienet_local *pcs_to_axienet_local(struct phylink_pcs *pcs) -{ - return container_of(pcs, struct axienet_local, pcs); -} - -static void axienet_pcs_get_state(struct phylink_pcs *pcs, - unsigned int neg_mode, - struct phylink_link_state *state) -{ - struct mdio_device *pcs_phy =3D pcs_to_axienet_local(pcs)->pcs_phy; - - phylink_mii_c22_pcs_get_state(pcs_phy, neg_mode, state); -} - -static void axienet_pcs_an_restart(struct phylink_pcs *pcs) -{ - struct mdio_device *pcs_phy =3D pcs_to_axienet_local(pcs)->pcs_phy; - - phylink_mii_c22_pcs_an_restart(pcs_phy); -} - -static int axienet_pcs_config(struct phylink_pcs *pcs, unsigned int neg_mo= de, - phy_interface_t interface, - const unsigned long *advertising, - bool permit_pause_to_mac) -{ - struct mdio_device *pcs_phy =3D pcs_to_axienet_local(pcs)->pcs_phy; - struct net_device *ndev =3D pcs_to_axienet_local(pcs)->ndev; - struct axienet_local *lp =3D netdev_priv(ndev); - int ret; - - if (lp->switch_x_sgmii) { - ret =3D mdiodev_write(pcs_phy, XLNX_MII_STD_SELECT_REG, - interface =3D=3D PHY_INTERFACE_MODE_SGMII ? - XLNX_MII_STD_SELECT_SGMII : 0); - if (ret < 0) { - netdev_warn(ndev, - "Failed to switch PHY interface: %d\n", - ret); - return ret; - } - } - - ret =3D phylink_mii_c22_pcs_config(pcs_phy, interface, advertising, - neg_mode); - if (ret < 0) - netdev_warn(ndev, "Failed to configure PCS: %d\n", ret); - - return ret; -} - -static const struct phylink_pcs_ops axienet_pcs_ops =3D { - .pcs_get_state =3D axienet_pcs_get_state, - .pcs_config =3D axienet_pcs_config, - .pcs_an_restart =3D axienet_pcs_an_restart, -}; - static struct phylink_pcs *axienet_mac_select_pcs(struct phylink_config *c= onfig, phy_interface_t interface) { @@ -2583,8 +2528,8 @@ static struct phylink_pcs *axienet_mac_select_pcs(str= uct phylink_config *config, struct axienet_local *lp =3D netdev_priv(ndev); =20 if (interface =3D=3D PHY_INTERFACE_MODE_1000BASEX || - interface =3D=3D PHY_INTERFACE_MODE_SGMII) - return &lp->pcs; + interface =3D=3D PHY_INTERFACE_MODE_SGMII) + return lp->pcs; =20 return NULL; } @@ -3056,28 +3001,23 @@ static int axienet_probe(struct platform_device *pd= ev) =20 if (lp->phy_mode =3D=3D PHY_INTERFACE_MODE_SGMII || lp->phy_mode =3D=3D PHY_INTERFACE_MODE_1000BASEX) { - np =3D of_parse_phandle(pdev->dev.of_node, "pcs-handle", 0); - if (!np) { - /* Deprecated: Always use "pcs-handle" for pcs_phy. - * Falling back to "phy-handle" here is only for - * backward compatibility with old device trees. - */ - np =3D of_parse_phandle(pdev->dev.of_node, "phy-handle", 0); - } - if (!np) { - dev_err(&pdev->dev, "pcs-handle (preferred) or phy-handle required for = 1000BaseX/SGMII\n"); - ret =3D -EINVAL; - goto cleanup_mdio; - } - lp->pcs_phy =3D of_mdio_find_device(np); - if (!lp->pcs_phy) { - ret =3D -EPROBE_DEFER; - of_node_put(np); + DECLARE_PHY_INTERFACE_MASK(interfaces); + + phy_interface_zero(interfaces); + if (lp->switch_x_sgmii || + lp->phy_mode =3D=3D PHY_INTERFACE_MODE_SGMII) + __set_bit(PHY_INTERFACE_MODE_SGMII, interfaces); + if (lp->switch_x_sgmii || + lp->phy_mode =3D=3D PHY_INTERFACE_MODE_1000BASEX) + __set_bit(PHY_INTERFACE_MODE_1000BASEX, interfaces); + + lp->pcs =3D axienet_xilinx_pcs_get(&pdev->dev, interfaces); + if (IS_ERR(lp->pcs)) { + ret =3D PTR_ERR(lp->pcs); + dev_err_probe(&pdev->dev, ret, + "could not get PCS for 1000BASE-X/SGMII\n"); goto cleanup_mdio; } - of_node_put(np); - lp->pcs.ops =3D &axienet_pcs_ops; - lp->pcs.poll =3D true; } =20 lp->phylink_config.dev =3D &ndev->dev; @@ -3115,8 +3055,6 @@ static int axienet_probe(struct platform_device *pdev) phylink_destroy(lp->phylink); =20 cleanup_mdio: - if (lp->pcs_phy) - put_device(&lp->pcs_phy->dev); if (lp->mii_bus) axienet_mdio_teardown(lp); cleanup_clk: @@ -3139,9 +3077,7 @@ static void axienet_remove(struct platform_device *pd= ev) if (lp->phylink) phylink_destroy(lp->phylink); =20 - if (lp->pcs_phy) - put_device(&lp->pcs_phy->dev); - + pcs_put(lp->pcs); axienet_mdio_teardown(lp); =20 clk_bulk_disable_unprepare(XAE_NUM_MISC_CLOCKS, lp->misc_clks); diff --git a/drivers/net/pcs/pcs-xilinx.c b/drivers/net/pcs/pcs-xilinx.c index cc42e2a22cd2..6405949c1a75 100644 --- a/drivers/net/pcs/pcs-xilinx.c +++ b/drivers/net/pcs/pcs-xilinx.c @@ -354,10 +354,8 @@ static int xilinx_pcs_probe(struct mdio_device *mdiode= v) =20 /* Sanity check */ ret =3D get_phy_c22_id(mdiodev->bus, mdiodev->addr, &phy_id); - if (ret) { - dev_err_probe(dev, ret, "could not read id\n"); - return ret; - } + if (ret) + return dev_err_probe(dev, ret, "could not read id\n"); if ((phy_id & 0xfffffff0) !=3D 0x01740c00) dev_warn(dev, "unknown phy id %x\n", phy_id); =20 @@ -448,8 +446,7 @@ static int axienet_xilinx_pcs_fixup(struct of_changeset= *ocs, if (ret) return ret; =20 - return of_changeset_add_prop_string(ocs, np, "compatible", - "xlnx,pcs"); + return of_changeset_add_prop_string(ocs, np, "compatible", "xlnx,pcs"); #else return -ENODEV; #endif --=20 2.35.1.1320.gc452695387.dirty