From: Paolo Abeni <pabeni@redhat.com>
To: Oleksij Rempel <o.rempel@pengutronix.de>,
"David S. Miller" <davem@davemloft.net>,
Eric Dumazet <edumazet@google.com>,
Jakub Kicinski <kuba@kernel.org>,
Woojung Huh <woojung.huh@microchip.com>,
Andrew Lunn <andrew+netdev@lunn.ch>,
Russell King <rmk+kernel@armlinux.org.uk>,
Thangaraj Samynathan <Thangaraj.S@microchip.com>,
Rengarajan Sundararajan <Rengarajan.S@microchip.com>
Cc: kernel@pengutronix.de, linux-kernel@vger.kernel.org,
netdev@vger.kernel.org, UNGLinuxDriver@microchip.com,
Phil Elwell <phil@raspberrypi.org>,
Maxime Chevallier <maxime.chevallier@bootlin.com>,
Simon Horman <horms@kernel.org>
Subject: Re: [PATCH net-next v7 08/12] net: usb: lan78xx: Convert to PHYLINK for improved PHY and MAC management
Date: Fri, 2 May 2025 11:36:08 +0200 [thread overview]
Message-ID: <5c42675c-5143-43dc-94cd-701711ff5fa6@redhat.com> (raw)
In-Reply-To: <20250428130542.3879769-9-o.rempel@pengutronix.de>
On 4/28/25 3:05 PM, Oleksij Rempel wrote:
[...]
> @@ -2619,28 +2530,100 @@ static int lan78xx_configure_flowcontrol(struct lan78xx_net *dev,
> return lan78xx_write_reg(dev, FLOW, flow);
> }
>
> +static void lan78xx_mac_link_up(struct phylink_config *config,
> + struct phy_device *phy,
> + unsigned int mode, phy_interface_t interface,
> + int speed, int duplex,
> + bool tx_pause, bool rx_pause)
> +{
> + struct net_device *net = to_net_dev(config->dev);
> + struct lan78xx_net *dev = netdev_priv(net);
> + u32 mac_cr = 0;
> + int ret;
> +
> + switch (speed) {
> + case SPEED_1000:
> + mac_cr |= MAC_CR_SPEED_1000_;
> + break;
> + case SPEED_100:
> + mac_cr |= MAC_CR_SPEED_100_;
> + break;
> + case SPEED_10:
> + mac_cr |= MAC_CR_SPEED_10_;
> + break;
> + default:
> + netdev_err(dev->net, "Unsupported speed %d\n", speed);
> + return;
> + }
> +
> + if (duplex == DUPLEX_FULL)
> + mac_cr |= MAC_CR_FULL_DUPLEX_;
> +
> + /* make sure TXEN and RXEN are disabled before reconfiguring MAC */
> + ret = lan78xx_update_reg(dev, MAC_CR, MAC_CR_SPEED_MASK_ |
> + MAC_CR_FULL_DUPLEX_ | MAC_CR_EEE_EN_, mac_cr);
> + if (ret < 0)
> + goto link_up_fail;
> +
> + ret = lan78xx_configure_flowcontrol(dev, tx_pause, rx_pause);
> + if (ret < 0)
> + goto link_up_fail;
> +
> + ret = lan78xx_configure_usb(dev, speed);
> + if (ret < 0)
> + goto link_up_fail;
> +
> + lan78xx_rx_urb_submit_all(dev);
> +
> + ret = lan78xx_flush_rx_fifo(dev);
> + if (ret < 0)
> + goto link_up_fail;
> +
> + ret = lan78xx_flush_tx_fifo(dev);
> + if (ret < 0)
> + goto link_up_fail;
> +
> + ret = lan78xx_start_tx_path(dev);
> + if (ret < 0)
> + goto link_up_fail;
> +
> + ret = lan78xx_start_rx_path(dev);
> + if (ret < 0)
> + goto link_up_fail;
> +
> + return;
Minor nit: a blank line here would make IMHO the code more readable.
> +link_up_fail:
> + netdev_err(dev->net, "Failed to set MAC up with error %pe\n",
> + ERR_PTR(ret));
> +}
[...]
> static int lan78xx_phy_init(struct lan78xx_net *dev)
> {
> - __ETHTOOL_DECLARE_LINK_MODE_MASK(fc) = { 0, };
> - int ret;
> - u32 mii_adv;
> struct phy_device *phydev;
> + int ret;
>
> phydev = lan78xx_get_phy(dev);
> + /* phydev can be NULL if no PHY is found and the chip is LAN7801,
> + * which will use a fixed link later.
> + * If an error occurs, return the error code immediately.
> + */
> if (IS_ERR(phydev))
> return PTR_ERR(phydev);
>
> + ret = lan78xx_phylink_setup(dev);
> + if (ret < 0)
> + return ret;
> +
> + /* If no PHY is found, set up a fixed link. It is very specific to
> + * the LAN7801 and is used in special cases like EVB-KSZ9897-1 where
> + * LAN7801 acts as a USB-to-Ethernet interface to a switch without
> + * a visible PHY.
> + */
> + if (!phydev) {
> + ret = lan78xx_set_fixed_link(dev);
> + if (ret < 0)
> + return ret;
> + }
> +
> ret = lan78xx_mac_prepare_for_phy(dev);
> if (ret < 0)
> - goto free_phy;
> + return ret;
lan78xx_phy_init() now does not perform any cleanup on error forcing the
caller to do the phy cleanup when lan78xx_phy_init() fails, which is
imho cunter-intuitive.
> @@ -3449,31 +3435,9 @@ static int lan78xx_open(struct net_device *net)
> }
> }
>
> - ret = lan78xx_flush_rx_fifo(dev);
> - if (ret < 0)
> - goto done;
> - ret = lan78xx_flush_tx_fifo(dev);
> - if (ret < 0)
> - goto done;
> -
> - ret = lan78xx_start_tx_path(dev);
> - if (ret < 0)
> - goto done;
> - ret = lan78xx_start_rx_path(dev);
> - if (ret < 0)
> - goto done;
> -
> - lan78xx_init_stats(dev);
> -
> - set_bit(EVENT_DEV_OPEN, &dev->flags);
> + phylink_start(dev->phylink);
>
> netif_start_queue(net);
I guess this should be called after lan78xx_start_tx_path(), which is
not guarateed anymore after this patch
/P
next prev parent reply other threads:[~2025-05-02 9:36 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-04-28 13:05 [PATCH net-next v7 00/12] Convert LAN78xx to PHYLINK Oleksij Rempel
2025-04-28 13:05 ` [PATCH net-next v7 01/12] net: usb: lan78xx: Improve error handling in PHY initialization Oleksij Rempel
2025-04-28 13:05 ` [PATCH net-next v7 02/12] net: usb: lan78xx: remove explicit check for missing PHY driver Oleksij Rempel
2025-04-28 13:05 ` [PATCH net-next v7 03/12] net: usb: lan78xx: refactor PHY init to separate detection and MAC configuration Oleksij Rempel
2025-04-28 13:05 ` [PATCH net-next v7 04/12] net: usb: lan78xx: move LED DT configuration to helper Oleksij Rempel
2025-04-28 13:05 ` [PATCH net-next v7 05/12] net: usb: lan78xx: Extract PHY interrupt acknowledgment " Oleksij Rempel
2025-04-28 13:05 ` [PATCH net-next v7 06/12] net: usb: lan78xx: Refactor USB link power configuration into helper Oleksij Rempel
2025-04-28 13:05 ` [PATCH net-next v7 07/12] net: usb: lan78xx: Extract flow control configuration to helper Oleksij Rempel
2025-04-28 13:05 ` [PATCH net-next v7 08/12] net: usb: lan78xx: Convert to PHYLINK for improved PHY and MAC management Oleksij Rempel
2025-05-02 9:36 ` Paolo Abeni [this message]
2025-05-02 9:39 ` Paolo Abeni
2025-04-28 13:05 ` [PATCH net-next v7 09/12] net: usb: lan78xx: Use ethtool_op_get_link to reflect current link status Oleksij Rempel
2025-04-28 13:05 ` [PATCH net-next v7 10/12] net: usb: lan78xx: port link settings to phylink API Oleksij Rempel
2025-04-28 13:05 ` [PATCH net-next v7 11/12] net: usb: lan78xx: Integrate EEE support with phylink LPI API Oleksij Rempel
2025-04-28 13:05 ` [PATCH net-next v7 12/12] net: usb: lan78xx: remove unused struct members Oleksij Rempel
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=5c42675c-5143-43dc-94cd-701711ff5fa6@redhat.com \
--to=pabeni@redhat.com \
--cc=Rengarajan.S@microchip.com \
--cc=Thangaraj.S@microchip.com \
--cc=UNGLinuxDriver@microchip.com \
--cc=andrew+netdev@lunn.ch \
--cc=davem@davemloft.net \
--cc=edumazet@google.com \
--cc=horms@kernel.org \
--cc=kernel@pengutronix.de \
--cc=kuba@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=maxime.chevallier@bootlin.com \
--cc=netdev@vger.kernel.org \
--cc=o.rempel@pengutronix.de \
--cc=phil@raspberrypi.org \
--cc=rmk+kernel@armlinux.org.uk \
--cc=woojung.huh@microchip.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox