From nobody Sun Nov 24 06:13:25 2024 Received: from relay1-d.mail.gandi.net (relay1-d.mail.gandi.net [217.70.183.193]) (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 E45462194AA; Thu, 7 Nov 2024 17:03:11 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=217.70.183.193 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730998996; cv=none; b=JH1E9OtP7GVFThmzP4STl83zh3O15JAhJ+q+0XcxslzFM/2e0koTG5B5GulR59UuSyg6MXJC5jIqbHLUlfjjSR7e92jsqOFRPgx7VW1+WIJYn6xAdAmcKa2l8TcK3zyh8+pXw80V/L0OcNqPBZ1yxg+4qkoGwOOhtv0HjgRUt+k= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730998996; c=relaxed/simple; bh=KJBAmMwAem737ua9u2IveMUP2U+vzQ0HKfPPQ1G5cZI=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=HFBV15U0RVVg3Gu9KB0CCx3onZ+CZQLzEcmXoIAUPnJwgDl7VAkcQHPHiYvDtEEWbI96Gj4D1F72WF8pLlcchpdLm8G/OFNkxtwcrPpoWB0ZTydXUXvErWaA5EbjTtsECT6AewGdSd/pH3YjuG0HoGFQM50He6I1WSHRMlpWnQs= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=bootlin.com; spf=pass smtp.mailfrom=bootlin.com; dkim=pass (2048-bit key) header.d=bootlin.com header.i=@bootlin.com header.b=cV4RJ02K; arc=none smtp.client-ip=217.70.183.193 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.b="cV4RJ02K" Received: by mail.gandi.net (Postfix) with ESMTPSA id 84051240010; Thu, 7 Nov 2024 17:03:09 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=gm1; t=1730998990; 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=yGftyA+3TjwSi4jztRcRdZXVFb6mlDb7o3s4PkJNec8=; b=cV4RJ02KulSkgy7RoPhzVTZJoHOnokc8SIhumyIm1XDfLvi2PsRUYkad+zKyL335ejELsQ Y9CY7cESyynqwEcvi4oFnTMfnyL2TN2AvEy1ErWhNaOMAr72tTRo2pAnax9ZV/Wsolh9Cc EvHku5U/O/Mmwe+vpNW9q7c1fqSLrBjLEb+QlRVix1wHInTgXS7bdpJdmxhawFzgNTIoeP 9N7x5H/ze4AUdSRdQ9CELYGGWrCMbU02tuAnZksGplckvoP1Wc7D4wTLBRuHBttZ8d/oDj PMEKgiM6U78DBac+qh8fsmqBGR01FTHRyXtS1EfB9SAv6VNKAlCP3+P0LHd+Ug== From: Maxime Chevallier To: davem@davemloft.net, Andrew Lunn , Jakub Kicinski , Eric Dumazet , Paolo Abeni , Russell King , Christophe Leroy , Heiner Kallweit Cc: Maxime Chevallier , netdev@vger.kernel.org, linux-kernel@vger.kernel.org, thomas.petazzoni@bootlin.com, Herve Codina , =?UTF-8?q?Uwe=20Kleine-K=C3=B6nig?= , linuxppc-dev@lists.ozlabs.org Subject: [PATCH net-next 7/7] net: freescale: ucc_geth: phylink conversion Date: Thu, 7 Nov 2024 18:02:54 +0100 Message-ID: <20241107170255.1058124-8-maxime.chevallier@bootlin.com> X-Mailer: git-send-email 2.47.0 In-Reply-To: <20241107170255.1058124-1-maxime.chevallier@bootlin.com> References: <20241107170255.1058124-1-maxime.chevallier@bootlin.com> 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-GND-Sasl: maxime.chevallier@bootlin.com Content-Type: text/plain; charset="utf-8" ucc_geth is quite capable in terms of supported interfaces, and even includes an externally controlled PCS (well, TBI). Port that driver to phylink. Signed-off-by: Maxime Chevallier --- drivers/net/ethernet/freescale/Kconfig | 3 +- drivers/net/ethernet/freescale/ucc_geth.c | 516 ++++++++---------- drivers/net/ethernet/freescale/ucc_geth.h | 13 +- .../net/ethernet/freescale/ucc_geth_ethtool.c | 61 +-- 4 files changed, 236 insertions(+), 357 deletions(-) diff --git a/drivers/net/ethernet/freescale/Kconfig b/drivers/net/ethernet/= freescale/Kconfig index 75401d2a5fb4..a2d7300925a8 100644 --- a/drivers/net/ethernet/freescale/Kconfig +++ b/drivers/net/ethernet/freescale/Kconfig @@ -81,8 +81,7 @@ config UCC_GETH tristate "Freescale QE Gigabit Ethernet" depends on QUICC_ENGINE && PPC32 select FSL_PQ_MDIO - select PHYLIB - select FIXED_PHY + select PHYLINK help This driver supports the Gigabit Ethernet mode of the QUICC Engine, which is available on some Freescale SOCs. diff --git a/drivers/net/ethernet/freescale/ucc_geth.c b/drivers/net/ethern= et/freescale/ucc_geth.c index 0ec4ea95ad6d..df74ebd8dbe8 100644 --- a/drivers/net/ethernet/freescale/ucc_geth.c +++ b/drivers/net/ethernet/freescale/ucc_geth.c @@ -26,7 +26,7 @@ #include #include #include -#include +#include #include #include #include @@ -34,6 +34,7 @@ #include #include #include +#include =20 #include #include @@ -1258,89 +1259,6 @@ static int init_min_frame_len(u16 min_frame_length, return 0; } =20 -static int adjust_enet_interface(struct ucc_geth_private *ugeth) -{ - struct ucc_geth_info *ug_info; - struct ucc_geth __iomem *ug_regs; - struct ucc_fast __iomem *uf_regs; - u32 upsmr, maccfg2; - u16 value; - - ugeth_vdbg("%s: IN", __func__); - - ug_info =3D ugeth->ug_info; - ug_regs =3D ugeth->ug_regs; - uf_regs =3D ugeth->uccf->uf_regs; - - /* Set MACCFG2 */ - maccfg2 =3D in_be32(&ug_regs->maccfg2); - - /* Disable frame length check */ - maccfg2 &=3D ~MACCFG2_LC; - maccfg2 &=3D ~MACCFG2_INTERFACE_MODE_MASK; - if ((ugeth->max_speed =3D=3D SPEED_10) || - (ugeth->max_speed =3D=3D SPEED_100)) - maccfg2 |=3D MACCFG2_INTERFACE_MODE_NIBBLE; - else if (ugeth->max_speed =3D=3D SPEED_1000) - maccfg2 |=3D MACCFG2_INTERFACE_MODE_BYTE; - maccfg2 |=3D ug_info->padAndCrc; - out_be32(&ug_regs->maccfg2, maccfg2); - - /* Set UPSMR */ - upsmr =3D in_be32(&uf_regs->upsmr); - upsmr &=3D ~(UCC_GETH_UPSMR_RPM | UCC_GETH_UPSMR_R10M | - UCC_GETH_UPSMR_TBIM | UCC_GETH_UPSMR_RMM); - if ((ugeth->phy_interface =3D=3D PHY_INTERFACE_MODE_RMII) || - (ugeth->phy_interface =3D=3D PHY_INTERFACE_MODE_RGMII) || - (ugeth->phy_interface =3D=3D PHY_INTERFACE_MODE_RGMII_ID) || - (ugeth->phy_interface =3D=3D PHY_INTERFACE_MODE_RGMII_RXID) || - (ugeth->phy_interface =3D=3D PHY_INTERFACE_MODE_RGMII_TXID) || - (ugeth->phy_interface =3D=3D PHY_INTERFACE_MODE_RTBI)) { - if (ugeth->phy_interface !=3D PHY_INTERFACE_MODE_RMII) - upsmr |=3D UCC_GETH_UPSMR_RPM; - switch (ugeth->max_speed) { - case SPEED_10: - upsmr |=3D UCC_GETH_UPSMR_R10M; - fallthrough; - case SPEED_100: - if (ugeth->phy_interface !=3D PHY_INTERFACE_MODE_RTBI) - upsmr |=3D UCC_GETH_UPSMR_RMM; - } - } - if ((ugeth->phy_interface =3D=3D PHY_INTERFACE_MODE_TBI) || - (ugeth->phy_interface =3D=3D PHY_INTERFACE_MODE_RTBI)) { - upsmr |=3D UCC_GETH_UPSMR_TBIM; - } - if (ugeth->phy_interface =3D=3D PHY_INTERFACE_MODE_SGMII) - upsmr |=3D UCC_GETH_UPSMR_SGMM; - - out_be32(&uf_regs->upsmr, upsmr); - - /* Disable autonegotiation in tbi mode, because by default it - comes up in autonegotiation mode. */ - /* Note that this depends on proper setting in utbipar register. */ - if ((ugeth->phy_interface =3D=3D PHY_INTERFACE_MODE_TBI) || - (ugeth->phy_interface =3D=3D PHY_INTERFACE_MODE_RTBI)) { - struct ucc_geth_info *ug_info =3D ugeth->ug_info; - struct phy_device *tbiphy; - - if (!ug_info->tbi_node) - pr_warn("TBI mode requires that the device tree specify a tbi-handle\n"= ); - - tbiphy =3D of_phy_find_device(ug_info->tbi_node); - if (!tbiphy) - pr_warn("Could not get TBI device\n"); - - value =3D phy_read(tbiphy, ENET_TBI_MII_CR); - value &=3D ~0x1000; /* Turn off autonegotiation */ - phy_write(tbiphy, ENET_TBI_MII_CR, value); - - put_device(&tbiphy->mdio.dev); - } - - return 0; -} - static int ugeth_graceful_stop_tx(struct ucc_geth_private *ugeth) { struct ucc_fast_private *uccf; @@ -1512,113 +1430,6 @@ static void ugeth_activate(struct ucc_geth_private = *ugeth) __netdev_watchdog_up(ugeth->ndev); } =20 -static void ugeth_link_up(struct ucc_geth_private *ugeth, - struct phy_device *phy, - phy_interface_t interface, int speed, int duplex) -{ - struct ucc_geth __iomem *ug_regs =3D ugeth->ug_regs; - struct ucc_fast __iomem *uf_regs =3D ugeth->uccf->uf_regs; - u32 tempval =3D in_be32(&ug_regs->maccfg2); - u32 upsmr =3D in_be32(&uf_regs->upsmr); - int new_state =3D 0; - - /* Now we make sure that we can be in full duplex mode. - * If not, we operate in half-duplex mode. - */ - if (duplex !=3D ugeth->oldduplex) { - new_state =3D 1; - if (duplex =3D=3D DUPLEX_HALF) - tempval &=3D ~(MACCFG2_FDX); - else - tempval |=3D MACCFG2_FDX; - ugeth->oldduplex =3D duplex; - } - - if (speed !=3D ugeth->oldspeed) { - new_state =3D 1; - switch (speed) { - case SPEED_1000: - tempval =3D ((tempval & - ~(MACCFG2_INTERFACE_MODE_MASK)) | - MACCFG2_INTERFACE_MODE_BYTE); - break; - case SPEED_100: - case SPEED_10: - tempval =3D ((tempval & - ~(MACCFG2_INTERFACE_MODE_MASK)) | - MACCFG2_INTERFACE_MODE_NIBBLE); - /* if reduced mode, re-set UPSMR.R10M */ - if (interface =3D=3D PHY_INTERFACE_MODE_RMII || - phy_interface_mode_is_rgmii(interface) || - interface =3D=3D PHY_INTERFACE_MODE_RTBI) { - if (speed =3D=3D SPEED_10) - upsmr |=3D UCC_GETH_UPSMR_R10M; - else - upsmr &=3D ~UCC_GETH_UPSMR_R10M; - } - break; - default: - if (netif_msg_link(ugeth)) - pr_warn("%s: Speed (%d) is not 10/100/1000!", - netdev_name(ugeth->ndev), speed); - break; - } - ugeth->oldspeed =3D speed; - } - - if (!ugeth->oldlink) { - new_state =3D 1; - ugeth->oldlink =3D 1; - } - - if (new_state) { - /* - * To change the MAC configuration we need to disable - * the controller. To do so, we have to either grab - * ugeth->lock, which is a bad idea since 'graceful - * stop' commands might take quite a while, or we can - * quiesce driver's activity. - */ - ugeth_quiesce(ugeth); - ugeth_disable(ugeth, COMM_DIR_RX_AND_TX); - - out_be32(&ug_regs->maccfg2, tempval); - out_be32(&uf_regs->upsmr, upsmr); - - ugeth_enable(ugeth, COMM_DIR_RX_AND_TX); - ugeth_activate(ugeth); - } - - if (netif_msg_link(ugeth)) - phy_print_status(phy); -} - -static void ugeth_link_down(struct ucc_geth_private *ugeth) -{ - ugeth->oldlink =3D 0; - ugeth->oldspeed =3D 0; - ugeth->oldduplex =3D -1; -} - -/* Called every time the controller might need to be made - * aware of new link state. The PHY code conveys this - * information through variables in the ugeth structure, and this - * function converts those variables into the appropriate - * register values, and can bring down the device if needed. - */ - -static void adjust_link(struct net_device *dev) -{ - struct ucc_geth_private *ugeth =3D netdev_priv(dev); - struct phy_device *phydev =3D dev->phydev; - - if (phydev->link) - ugeth_link_up(ugeth, phydev, phydev->interface, - phydev->speed, phydev->duplex); - else - ugeth_link_down(ugeth); -} - /* Initialize TBI PHY interface for communicating with the * SERDES lynx PHY on the chip. We communicate with this PHY * through the MDIO bus on each controller, treating it as a @@ -1666,32 +1477,152 @@ static void uec_configure_serdes(struct net_device= *dev) put_device(&tbiphy->mdio.dev); } =20 -/* Configure the PHY for dev. - * returns 0 if success. -1 if failure - */ -static int init_phy(struct net_device *dev) +static bool phy_interface_mode_is_reduced(phy_interface_t interface) +{ + return phy_interface_mode_is_rgmii(interface) || + interface =3D=3D PHY_INTERFACE_MODE_RMII || + interface =3D=3D PHY_INTERFACE_MODE_RTBI; +} + +static void ugeth_mac_link_up(struct phylink_config *config, struct phy_de= vice *phy, + unsigned int mode, phy_interface_t interface, + int speed, int duplex, bool tx_pause, bool rx_pause) { - struct ucc_geth_private *priv =3D netdev_priv(dev); - struct ucc_geth_info *ug_info =3D priv->ug_info; - struct phy_device *phydev; + struct net_device *ndev =3D to_net_dev(config->dev); + struct ucc_geth_private *ugeth =3D netdev_priv(ndev); + struct ucc_geth_info *ug_info =3D ugeth->ug_info; + struct ucc_geth __iomem *ug_regs =3D ugeth->ug_regs; + struct ucc_fast __iomem *uf_regs =3D ugeth->uccf->uf_regs; + u32 old_maccfg2, maccfg2 =3D in_be32(&ug_regs->maccfg2); + u32 old_upsmr, upsmr =3D in_be32(&uf_regs->upsmr); =20 - priv->oldlink =3D 0; - priv->oldspeed =3D 0; - priv->oldduplex =3D -1; + old_maccfg2 =3D maccfg2; + old_upsmr =3D upsmr; =20 - phydev =3D of_phy_connect(dev, ug_info->phy_node, &adjust_link, 0, - priv->phy_interface); - if (!phydev) { - dev_err(&dev->dev, "Could not attach to PHY\n"); - return -ENODEV; + /* No length check */ + maccfg2 &=3D ~MACCFG2_LC; + maccfg2 &=3D ~MACCFG2_INTERFACE_MODE_MASK; + upsmr &=3D ~(UCC_GETH_UPSMR_RPM | UCC_GETH_UPSMR_R10M | + UCC_GETH_UPSMR_TBIM | UCC_GETH_UPSMR_RMM); + + if (speed =3D=3D SPEED_10 || speed =3D=3D SPEED_100) + maccfg2 |=3D MACCFG2_INTERFACE_MODE_NIBBLE; + else if (speed =3D=3D SPEED_1000) + maccfg2 |=3D MACCFG2_INTERFACE_MODE_BYTE; + + maccfg2 |=3D ug_info->padAndCrc; + + if (phy_interface_mode_is_reduced(interface)) { + + if (interface !=3D PHY_INTERFACE_MODE_RMII) + upsmr |=3D UCC_GETH_UPSMR_RPM; + + switch (speed) { + case SPEED_10: + upsmr |=3D UCC_GETH_UPSMR_R10M; + fallthrough; + case SPEED_100: + if (interface !=3D PHY_INTERFACE_MODE_RTBI) + upsmr |=3D UCC_GETH_UPSMR_RMM; + } } =20 - if (priv->phy_interface =3D=3D PHY_INTERFACE_MODE_SGMII) - uec_configure_serdes(dev); + if (interface =3D=3D PHY_INTERFACE_MODE_TBI || + interface =3D=3D PHY_INTERFACE_MODE_RTBI) + upsmr |=3D UCC_GETH_UPSMR_TBIM; + + if (interface =3D=3D PHY_INTERFACE_MODE_SGMII) + upsmr |=3D UCC_GETH_UPSMR_SGMM; =20 - phy_set_max_speed(phydev, priv->max_speed); + if (duplex =3D=3D DUPLEX_HALF) + maccfg2 &=3D ~(MACCFG2_FDX); + else + maccfg2 |=3D MACCFG2_FDX; =20 - return 0; + if (maccfg2 !=3D old_maccfg2 || upsmr !=3D old_upsmr) { + /* + * To change the MAC configuration we need to disable + * the controller. To do so, we have to either grab + * ugeth->lock, which is a bad idea since 'graceful + * stop' commands might take quite a while, or we can + * quiesce driver's activity. + */ + ugeth_quiesce(ugeth); + ugeth_disable(ugeth, COMM_DIR_RX_AND_TX); + + out_be32(&ug_regs->maccfg2, maccfg2); + out_be32(&uf_regs->upsmr, upsmr); + + ugeth_enable(ugeth, COMM_DIR_RX_AND_TX); + ugeth_activate(ugeth); + } + + if (interface =3D=3D PHY_INTERFACE_MODE_SGMII) + uec_configure_serdes(ndev); + + if (!phylink_autoneg_inband(mode)) { + ug_info->aufc =3D 0; + ug_info->receiveFlowControl =3D rx_pause; + ug_info->transmitFlowControl =3D tx_pause; + + init_flow_control_params(ug_info->aufc, + ug_info->receiveFlowControl, + ug_info->transmitFlowControl, + ug_info->pausePeriod, + ug_info->extensionField, + &ugeth->uccf->uf_regs->upsmr, + &ugeth->ug_regs->uempr, + &ugeth->ug_regs->maccfg1); + } + + ugeth_enable(ugeth, COMM_DIR_RX_AND_TX); +} + +static void ugeth_mac_link_down(struct phylink_config *config, + unsigned int mode, phy_interface_t interface) +{ + struct net_device *ndev =3D to_net_dev(config->dev); + struct ucc_geth_private *ugeth =3D netdev_priv(ndev); + + ugeth_disable(ugeth, COMM_DIR_RX_AND_TX); +} + +static void ugeth_mac_config(struct phylink_config *config, unsigned int m= ode, + const struct phylink_link_state *state) +{ + struct net_device *ndev =3D to_net_dev(config->dev); + struct ucc_geth_private *ugeth =3D netdev_priv(ndev); + struct ucc_geth_info *ug_info =3D ugeth->ug_info; + u16 value; + + if (state->interface =3D=3D PHY_INTERFACE_MODE_TBI || + state->interface =3D=3D PHY_INTERFACE_MODE_RTBI) { + struct phy_device *tbiphy; + + if (!ug_info->tbi_node) + pr_warn("TBI mode requires that the device tree specify a tbi-handle\n"= ); + + tbiphy =3D of_phy_find_device(ug_info->tbi_node); + if (!tbiphy) + pr_warn("Could not get TBI device\n"); + + value =3D phy_read(tbiphy, ENET_TBI_MII_CR); + value &=3D ~0x1000; /* Turn off autonegotiation */ + phy_write(tbiphy, ENET_TBI_MII_CR, value); + + put_device(&tbiphy->mdio.dev); + } + + if (phylink_autoneg_inband(mode)) { + ug_info->aufc =3D 1; + + init_flow_control_params(ug_info->aufc, 1, 1, + ug_info->pausePeriod, + ug_info->extensionField, + &ugeth->uccf->uf_regs->upsmr, + &ugeth->ug_regs->uempr, + &ugeth->ug_regs->maccfg1); + } } =20 static void ugeth_dump_regs(struct ucc_geth_private *ugeth) @@ -1963,7 +1894,6 @@ static void ucc_geth_set_multi(struct net_device *dev) static void ucc_geth_stop(struct ucc_geth_private *ugeth) { struct ucc_geth __iomem *ug_regs =3D ugeth->ug_regs; - struct phy_device *phydev =3D ugeth->ndev->phydev; =20 ugeth_vdbg("%s: IN", __func__); =20 @@ -1972,7 +1902,7 @@ static void ucc_geth_stop(struct ucc_geth_private *ug= eth) * Must be done before disabling the controller * or deadlock may happen. */ - phy_stop(phydev); + phylink_stop(ugeth->phylink); =20 /* Disable the controller */ ugeth_disable(ugeth, COMM_DIR_RX_AND_TX); @@ -3214,12 +3144,6 @@ static int ucc_geth_init_mac(struct ucc_geth_private= *ugeth) goto err; } =20 - err =3D adjust_enet_interface(ugeth); - if (err) { - netif_err(ugeth, ifup, dev, "Cannot configure net device, aborting\n"); - goto err; - } - /* Set MACSTNADDR1, MACSTNADDR2 */ /* For more details see the hardware spec. */ init_mac_station_addr_regs(dev->dev_addr[0], @@ -3231,12 +3155,6 @@ static int ucc_geth_init_mac(struct ucc_geth_private= *ugeth) &ugeth->ug_regs->macstnaddr1, &ugeth->ug_regs->macstnaddr2); =20 - err =3D ugeth_enable(ugeth, COMM_DIR_RX_AND_TX); - if (err) { - netif_err(ugeth, ifup, dev, "Cannot enable net device, aborting\n"); - goto err; - } - return 0; err: ucc_geth_stop(ugeth); @@ -3259,10 +3177,10 @@ static int ucc_geth_open(struct net_device *dev) return -EINVAL; } =20 - err =3D init_phy(dev); + err =3D phylink_of_phy_connect(ugeth->phylink, ugeth->dev->of_node, 0); if (err) { - netif_err(ugeth, ifup, dev, "Cannot initialize PHY, aborting\n"); - return err; + dev_err(&dev->dev, "Could not attach to PHY\n"); + return -ENODEV; } =20 err =3D ucc_geth_init_mac(ugeth); @@ -3278,7 +3196,7 @@ static int ucc_geth_open(struct net_device *dev) goto err; } =20 - phy_start(dev->phydev); + phylink_start(ugeth->phylink); napi_enable(&ugeth->napi); netdev_reset_queue(dev); netif_start_queue(dev); @@ -3305,7 +3223,7 @@ static int ucc_geth_close(struct net_device *dev) =20 cancel_work_sync(&ugeth->timeout_work); ucc_geth_stop(ugeth); - phy_disconnect(dev->phydev); + phylink_disconnect_phy(ugeth->phylink); =20 free_irq(ugeth->ug_info->uf_info.irq, ugeth->ndev); =20 @@ -3339,7 +3257,7 @@ static void ucc_geth_timeout_work(struct work_struct = *work) ucc_geth_stop(ugeth); ucc_geth_init_mac(ugeth); /* Must start PHY here */ - phy_start(dev->phydev); + phylink_start(ugeth->phylink); netif_tx_start_all_queues(dev); } =20 @@ -3381,10 +3299,12 @@ static int ucc_geth_suspend(struct platform_device = *ofdev, pm_message_t state) setbits32(ugeth->uccf->p_uccm, UCC_GETH_UCCE_MPD); setbits32(&ugeth->ug_regs->maccfg2, MACCFG2_MPE); ucc_fast_enable(ugeth->uccf, COMM_DIR_RX_AND_TX); - } else if (!(ugeth->wol_en & WAKE_PHY)) { - phy_stop(ndev->phydev); } =20 + rtnl_lock(); + phylink_suspend(ugeth->phylink, ugeth->wol_en); + rtnl_unlock(); + return 0; } =20 @@ -3418,12 +3338,9 @@ static int ucc_geth_resume(struct platform_device *o= fdev) } } =20 - ugeth->oldlink =3D 0; - ugeth->oldspeed =3D 0; - ugeth->oldduplex =3D -1; - - phy_stop(ndev->phydev); - phy_start(ndev->phydev); + rtnl_lock(); + phylink_resume(ugeth->phylink); + rtnl_unlock(); =20 napi_enable(&ugeth->napi); netif_device_attach(ndev); @@ -3438,13 +3355,12 @@ static int ucc_geth_resume(struct platform_device *= ofdev) =20 static int ucc_geth_ioctl(struct net_device *dev, struct ifreq *rq, int cm= d) { + struct ucc_geth_private *ugeth =3D netdev_priv(dev); + if (!netif_running(dev)) return -EINVAL; =20 - if (!dev->phydev) - return -ENODEV; - - return phy_mii_ioctl(dev->phydev, rq, cmd); + return phylink_mii_ioctl(ugeth->phylink, rq, cmd); } =20 static const struct net_device_ops ucc_geth_netdev_ops =3D { @@ -3452,7 +3368,6 @@ static const struct net_device_ops ucc_geth_netdev_op= s =3D { .ndo_stop =3D ucc_geth_close, .ndo_start_xmit =3D ucc_geth_start_xmit, .ndo_validate_addr =3D eth_validate_addr, - .ndo_change_carrier =3D fixed_phy_change_carrier, .ndo_set_mac_address =3D ucc_geth_set_mac_addr, .ndo_set_rx_mode =3D ucc_geth_set_multi, .ndo_tx_timeout =3D ucc_geth_timeout, @@ -3492,6 +3407,12 @@ static int ucc_geth_parse_clock(struct device_node *= np, const char *which, return 0; } =20 +struct phylink_mac_ops ugeth_mac_ops =3D { + .mac_link_up =3D ugeth_mac_link_up, + .mac_link_down =3D ugeth_mac_link_down, + .mac_config =3D ugeth_mac_config, +}; + static int ucc_geth_probe(struct platform_device* ofdev) { struct device *device =3D &ofdev->dev; @@ -3499,8 +3420,10 @@ static int ucc_geth_probe(struct platform_device* of= dev) struct net_device *dev =3D NULL; struct ucc_geth_private *ugeth =3D NULL; struct ucc_geth_info *ug_info; + struct device_node *phy_node; + struct phylink *phylink; struct resource res; - int err, ucc_num, max_speed =3D 0; + int err, ucc_num; const unsigned int *prop; phy_interface_t phy_interface; =20 @@ -3538,26 +3461,19 @@ static int ucc_geth_probe(struct platform_device* o= fdev) ug_info->uf_info.regs =3D res.start; ug_info->uf_info.irq =3D irq_of_parse_and_map(np, 0); =20 - ug_info->phy_node =3D of_parse_phandle(np, "phy-handle", 0); - if (!ug_info->phy_node && of_phy_is_fixed_link(np)) { - /* - * In the case of a fixed PHY, the DT node associated - * to the PHY is the Ethernet MAC DT node. - */ - err =3D of_phy_register_fixed_link(np); - if (err) - return err; - ug_info->phy_node =3D of_node_get(np); - } - /* Find the TBI PHY node. If it's not there, we don't support SGMII */ ug_info->tbi_node =3D of_parse_phandle(np, "tbi-handle", 0); =20 - prop =3D of_get_property(ug_info->phy_node, "interface", NULL); - if (prop) { - dev_err(&ofdev->dev, - "Device-tree property 'interface' is no longer supported. Please use 'p= hy-connection-type' instead."); - goto err_put_tbi; + phy_node =3D of_parse_phandle(np, "phy-handle", 0); + if (phy_node) { + prop =3D of_get_property(phy_node, "interface", NULL); + if (prop) { + dev_err(&ofdev->dev, + "Device-tree property 'interface' is no longer supported. Please use '= phy-connection-type' instead."); + of_node_put(phy_node); + goto err_put_tbi; + } + of_node_put(phy_node); } =20 err =3D of_get_phy_mode(np, &phy_interface); @@ -3566,28 +3482,13 @@ static int ucc_geth_probe(struct platform_device* o= fdev) goto err_put_tbi; } =20 - /* get speed, or derive from PHY interface */ - if (max_speed =3D=3D 0) - switch (phy_interface) { - case PHY_INTERFACE_MODE_GMII: - case PHY_INTERFACE_MODE_RGMII: - case PHY_INTERFACE_MODE_RGMII_ID: - case PHY_INTERFACE_MODE_RGMII_RXID: - case PHY_INTERFACE_MODE_RGMII_TXID: - case PHY_INTERFACE_MODE_TBI: - case PHY_INTERFACE_MODE_RTBI: - case PHY_INTERFACE_MODE_SGMII: - max_speed =3D SPEED_1000; - break; - default: - max_speed =3D SPEED_100; - break; - } - - if (max_speed =3D=3D SPEED_1000) { + if (phy_interface =3D=3D PHY_INTERFACE_MODE_GMII || + phy_interface_mode_is_rgmii(phy_interface) || + phy_interface =3D=3D PHY_INTERFACE_MODE_TBI || + phy_interface =3D=3D PHY_INTERFACE_MODE_RTBI || + phy_interface =3D=3D PHY_INTERFACE_MODE_SGMII) { unsigned int snums =3D qe_get_num_of_snums(); =20 - /* configure muram FIFOs for gigabit operation */ ug_info->uf_info.urfs =3D UCC_GETH_URFS_GIGA_INIT; ug_info->uf_info.urfet =3D UCC_GETH_URFET_GIGA_INIT; ug_info->uf_info.urfset =3D UCC_GETH_URFSET_GIGA_INIT; @@ -3616,7 +3517,7 @@ static int ucc_geth_probe(struct platform_device* ofd= ev) dev =3D devm_alloc_etherdev(&ofdev->dev, sizeof(*ugeth)); if (!dev) { err =3D -ENOMEM; - goto err_deregister_fixed_link; + goto err_put_tbi; } =20 ugeth =3D netdev_priv(dev); @@ -3643,23 +3544,50 @@ static int ucc_geth_probe(struct platform_device* o= fdev) dev->max_mtu =3D 1518; =20 ugeth->msg_enable =3D netif_msg_init(debug.msg_enable, UGETH_MSG_DEFAULT); - ugeth->phy_interface =3D phy_interface; - ugeth->max_speed =3D max_speed; =20 - /* Carrier starts down, phylib will bring it up */ - netif_carrier_off(dev); + ugeth->phylink_config.dev =3D &dev->dev; + ugeth->phylink_config.type =3D PHYLINK_NETDEV; + + ugeth->phylink_config.mac_capabilities =3D + MAC_SYM_PAUSE | MAC_10 | MAC_100 | MAC_1000FD; + + __set_bit(PHY_INTERFACE_MODE_MII, + ugeth->phylink_config.supported_interfaces); + __set_bit(PHY_INTERFACE_MODE_RMII, + ugeth->phylink_config.supported_interfaces); + __set_bit(PHY_INTERFACE_MODE_GMII, + ugeth->phylink_config.supported_interfaces); + phy_interface_set_rgmii(ugeth->phylink_config.supported_interfaces); + + if (ug_info->tbi_node) { + __set_bit(PHY_INTERFACE_MODE_SGMII, + ugeth->phylink_config.supported_interfaces); + __set_bit(PHY_INTERFACE_MODE_TBI, + ugeth->phylink_config.supported_interfaces); + __set_bit(PHY_INTERFACE_MODE_RTBI, + ugeth->phylink_config.supported_interfaces); + } + + phylink =3D phylink_create(&ugeth->phylink_config, dev_fwnode(&dev->dev), + phy_interface, &ugeth_mac_ops); + if (IS_ERR(phylink)) { + err =3D PTR_ERR(phylink); + goto err_put_tbi; + } + + ugeth->phylink =3D phylink; =20 err =3D devm_register_netdev(&ofdev->dev, dev); if (err) { if (netif_msg_probe(ugeth)) pr_err("%s: Cannot register net device, aborting\n", dev->name); - goto err_deregister_fixed_link; + goto err_destroy_phylink; } =20 err =3D of_get_ethdev_address(np, dev); if (err =3D=3D -EPROBE_DEFER) - goto err_deregister_fixed_link; + goto err_destroy_phylink; =20 ugeth->ug_info =3D ug_info; ugeth->dev =3D device; @@ -3668,12 +3596,11 @@ static int ucc_geth_probe(struct platform_device* o= fdev) =20 return 0; =20 -err_deregister_fixed_link: - if (of_phy_is_fixed_link(np)) - of_phy_deregister_fixed_link(np); +err_destroy_phylink: + phylink_destroy(phylink); err_put_tbi: of_node_put(ug_info->tbi_node); - of_node_put(ug_info->phy_node); + return err; } =20 @@ -3681,13 +3608,10 @@ static void ucc_geth_remove(struct platform_device*= ofdev) { struct net_device *dev =3D platform_get_drvdata(ofdev); struct ucc_geth_private *ugeth =3D netdev_priv(dev); - struct device_node *np =3D ofdev->dev.of_node; =20 ucc_geth_memclean(ugeth); - if (of_phy_is_fixed_link(np)) - of_phy_deregister_fixed_link(np); + phylink_destroy(ugeth->phylink); of_node_put(ugeth->ug_info->tbi_node); - of_node_put(ugeth->ug_info->phy_node); } =20 static const struct of_device_id ucc_geth_match[] =3D { diff --git a/drivers/net/ethernet/freescale/ucc_geth.h b/drivers/net/ethern= et/freescale/ucc_geth.h index 42fbbdf14ff2..0a3c2645e16b 100644 --- a/drivers/net/ethernet/freescale/ucc_geth.h +++ b/drivers/net/ethernet/freescale/ucc_geth.h @@ -16,6 +16,7 @@ =20 #include #include +#include #include =20 #include @@ -1074,6 +1075,9 @@ struct ucc_geth_tad_params { u16 vid; }; =20 +struct phylink; +struct phylink_config; + /* GETH protocol initialization structure */ struct ucc_geth_info { struct ucc_fast_info uf_info; @@ -1124,7 +1128,6 @@ struct ucc_geth_info { u32 eventRegMask; u16 pausePeriod; u16 extensionField; - struct device_node *phy_node; struct device_node *tbi_node; u8 weightfactor[NUM_TX_QUEUES]; u8 interruptcoalescingmaxvalue[NUM_RX_QUEUES]; @@ -1209,14 +1212,12 @@ struct ucc_geth_private { u16 skb_dirtytx[NUM_TX_QUEUES]; =20 struct ugeth_mii_info *mii_info; - phy_interface_t phy_interface; - int max_speed; uint32_t msg_enable; - int oldspeed; - int oldduplex; - int oldlink; int wol_en; =20 + struct phylink *phylink; + struct phylink_config phylink_config; + struct device_node *node; }; =20 diff --git a/drivers/net/ethernet/freescale/ucc_geth_ethtool.c b/drivers/ne= t/ethernet/freescale/ucc_geth_ethtool.c index 2a085f8f34b2..661521960cba 100644 --- a/drivers/net/ethernet/freescale/ucc_geth_ethtool.c +++ b/drivers/net/ethernet/freescale/ucc_geth_ethtool.c @@ -103,26 +103,18 @@ static const char rx_fw_stat_gstrings[][ETH_GSTRING_L= EN] =3D { static int uec_get_ksettings(struct net_device *netdev, struct ethtool_link_ksettings= *cmd) { - struct phy_device *phydev =3D netdev->phydev; - - if (!phydev) - return -ENODEV; - - phy_ethtool_ksettings_get(phydev, cmd); + struct ucc_geth_private *ugeth =3D netdev_priv(netdev); =20 - return 0; + return phylink_ethtool_ksettings_get(ugeth->phylink, cmd); } =20 static int uec_set_ksettings(struct net_device *netdev, const struct ethtool_link_ksettings *cmd) { - struct phy_device *phydev =3D netdev->phydev; - - if (!phydev) - return -ENODEV; + struct ucc_geth_private *ugeth =3D netdev_priv(netdev); =20 - return phy_ethtool_ksettings_set(phydev, cmd); + return phylink_ethtool_ksettings_set(ugeth->phylink, cmd); } =20 static void @@ -130,15 +122,8 @@ uec_get_pauseparam(struct net_device *netdev, struct ethtool_pauseparam *pause) { struct ucc_geth_private *ugeth =3D netdev_priv(netdev); - struct phy_device *phydev =3D netdev->phydev; - - if (phydev) - pause->autoneg =3D phydev->autoneg; =20 - if (ugeth->ug_info->receiveFlowControl) - pause->rx_pause =3D 1; - if (ugeth->ug_info->transmitFlowControl) - pause->tx_pause =3D 1; + return phylink_ethtool_get_pauseparam(ugeth->phylink, pause); } =20 static int @@ -146,31 +131,11 @@ uec_set_pauseparam(struct net_device *netdev, struct ethtool_pauseparam *pause) { struct ucc_geth_private *ugeth =3D netdev_priv(netdev); - struct phy_device *phydev =3D netdev->phydev; - int ret =3D 0; =20 ugeth->ug_info->receiveFlowControl =3D pause->rx_pause; ugeth->ug_info->transmitFlowControl =3D pause->tx_pause; =20 - if (phydev && phydev->autoneg) { - if (netif_running(netdev)) { - /* FIXME: automatically restart */ - netdev_info(netdev, "Please re-open the interface\n"); - } - } else { - struct ucc_geth_info *ug_info =3D ugeth->ug_info; - - ret =3D init_flow_control_params(ug_info->aufc, - ug_info->receiveFlowControl, - ug_info->transmitFlowControl, - ug_info->pausePeriod, - ug_info->extensionField, - &ugeth->uccf->uf_regs->upsmr, - &ugeth->ug_regs->uempr, - &ugeth->ug_regs->maccfg1); - } - - return ret; + return phylink_ethtool_set_pauseparam(ugeth->phylink, pause); } =20 static uint32_t @@ -344,13 +309,8 @@ uec_get_drvinfo(struct net_device *netdev, static void uec_get_wol(struct net_device *netdev, struct ethtool_wolinfo = *wol) { struct ucc_geth_private *ugeth =3D netdev_priv(netdev); - struct phy_device *phydev =3D netdev->phydev; =20 - wol->supported =3D 0; - wol->wolopts =3D 0; - - if (phydev) - phy_ethtool_get_wol(phydev, wol); + phylink_ethtool_get_wol(ugeth->phylink, wol); =20 if (qe_alive_during_sleep()) wol->supported |=3D WAKE_MAGIC; @@ -361,19 +321,14 @@ static void uec_get_wol(struct net_device *netdev, st= ruct ethtool_wolinfo *wol) static int uec_set_wol(struct net_device *netdev, struct ethtool_wolinfo *= wol) { struct ucc_geth_private *ugeth =3D netdev_priv(netdev); - struct phy_device *phydev =3D netdev->phydev; int ret =3D 0; =20 if (wol->wolopts & ~(WAKE_PHY | WAKE_MAGIC)) return -EINVAL; - else if ((wol->wolopts & WAKE_PHY) && !phydev) - return -EINVAL; else if (wol->wolopts & WAKE_MAGIC && !qe_alive_during_sleep()) return -EINVAL; =20 - if (wol->wolopts & WAKE_PHY) - ret =3D phy_ethtool_set_wol(phydev, wol); - + ret =3D phylink_ethtool_set_wol(ugeth->phylink, wol); if (ret) return ret; =20 --=20 2.47.0