From: "Russell King (Oracle)" <linux@armlinux.org.uk>
To: Pawel Dembicki <paweldembicki@gmail.com>
Cc: netdev@vger.kernel.org, Andrew Lunn <andrew@lunn.ch>,
Florian Fainelli <f.fainelli@gmail.com>,
Vladimir Oltean <olteanv@gmail.com>,
"David S. Miller" <davem@davemloft.net>,
Eric Dumazet <edumazet@google.com>,
Jakub Kicinski <kuba@kernel.org>, Paolo Abeni <pabeni@redhat.com>,
Heiner Kallweit <hkallweit1@gmail.com>,
Linus Walleij <linus.walleij@linaro.org>,
linux-kernel@vger.kernel.org
Subject: Re: [PATCH net-next 9/9] net: phy: vitesse: implement downshift in vsc73xx phys
Date: Tue, 30 Jul 2024 00:39:24 +0100 [thread overview]
Message-ID: <ZqgoLC77GeJ1yyYq@shell.armlinux.org.uk> (raw)
In-Reply-To: <20240729210615.279952-10-paweldembicki@gmail.com>
On Mon, Jul 29, 2024 at 11:06:15PM +0200, Pawel Dembicki wrote:
> +static int vsc73xx_get_downshift(struct phy_device *phydev, u8 *data)
> +{
> + int page, val, cnt, enable;
> +
> + page = phy_select_page(phydev, MII_VSC73XX_EXT_PAGE_1E);
> + if (page < 0)
> + return page;
> +
> + val = __phy_read(phydev, MII_VSC73XX_PHY_CTRL_EXT3);
> + if (val < 0)
> + goto restore_page;
> +
> + enable = FIELD_GET(MII_VSC73XX_PHY_CTRL_EXT3_DOWNSHIFT_EN, val);
> + cnt = FIELD_GET(MII_VSC73XX_PHY_CTRL_EXT3_DOWNSHIFT_CNT, val) + 2;
> +
> + *data = enable ? cnt : DOWNSHIFT_DEV_DISABLE;
> +
> +restore_page:
> + phy_restore_page(phydev, page, val);
> + return 0;
If you're going to use phy_select_page()..phy_restore_page(), please
read the documentation. If the __phy_read() fails, then you're
returning zero from this function, but leaving *data uninitialised.
Surely not what you want.
In any case, this complexity is unnecessary.
static int vsc73xx_get_downshift(struct phy_device *phydev, u8 *data)
{
int val, enable, cnt;
val = phy_read_paged(phydev, MII_VSC73XX_EXT_PAGE_1E,
MII_VSC73XX_PHY_CTRL_EXT3);
if (val < 0)
return val;
enable = FIELD_GET(MII_VSC73XX_PHY_CTRL_EXT3_DOWNSHIFT_EN, val);
cnt = FIELD_GET(MII_VSC73XX_PHY_CTRL_EXT3_DOWNSHIFT_CNT, val) + 2;
*data = enable ? cnt : DOWNSHIFT_DEV_DISABLE;
return 0;
}
is all that it needs.
> +}
> +
> +static int vsc73xx_set_downshift(struct phy_device *phydev, u8 cnt)
> +{
> + int page, ret, val;
> +
> + if (cnt > MII_VSC73XX_DOWNSHIFT_MAX)
> + return -E2BIG;
> + else if (cnt == MII_VSC73XX_DOWNSHIFT_INVAL)
> + return -EINVAL;
> +
> + page = phy_select_page(phydev, MII_VSC73XX_EXT_PAGE_1E);
> + if (page < 0)
> + return page;
> +
> + if (!cnt) {
> + ret = __phy_clear_bits(phydev, MII_VSC73XX_PHY_CTRL_EXT3,
> + MII_VSC73XX_PHY_CTRL_EXT3_DOWNSHIFT_EN);
> + } else {
> + val = MII_VSC73XX_PHY_CTRL_EXT3_DOWNSHIFT_EN |
> + FIELD_PREP(MII_VSC73XX_PHY_CTRL_EXT3_DOWNSHIFT_CNT,
> + cnt - 2);
> +
> + ret = __phy_modify(phydev, MII_VSC73XX_PHY_CTRL_EXT3,
> + MII_VSC73XX_PHY_CTRL_EXT3_DOWNSHIFT_EN |
> + MII_VSC73XX_PHY_CTRL_EXT3_DOWNSHIFT_CNT,
> + val);
> + }
> +
> + ret = phy_restore_page(phydev, page, ret);
> + if (ret < 0)
> + return ret;
This is also needlessly over-complex.
u16 mask, val;
...
mask = MII_VSC73XX_PHY_CTRL_EXT3_DOWNSHIFT_EN;
if (!cnt) {
val = 0;
} else {
mask |= MII_VSC73XX_PHY_CTRL_EXT3_DOWNSHIFT_CNT;
val = MII_VSC73XX_PHY_CTRL_EXT3_DOWNSHIFT_EN |
FIELD_PREP(MII_VSC73XX_PHY_CTRL_EXT3_DOWNSHIFT_CNT,
cnt - 2);
}
ret = phy_modify_paged(phydev, MII_VSC73XX_EXT_PAGE_1E,
MII_VSC73XX_PHY_CTRL_EXT3, mask, val);
if (ret < 0)
return ret;
Would be equivalent to your code above, only simpler.
--
RMK's Patch system: https://www.armlinux.org.uk/developer/patches/
FTTP is here! 80Mbps down 10Mbps up. Decent connectivity at last!
next prev parent reply other threads:[~2024-07-29 23:39 UTC|newest]
Thread overview: 18+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-07-29 21:06 [PATCH net-next 0/9] net: dsa: vsc73xx: fix MDIO bus access and PHY operations Pawel Dembicki
2024-07-29 21:06 ` [PATCH net-next 1/9] net: dsa: vsc73xx: fix phylink capabilities Pawel Dembicki
2024-07-29 22:54 ` Andrew Lunn
2024-07-29 23:05 ` Russell King (Oracle)
2024-07-29 21:06 ` [PATCH net-next 2/9] net: dsa: vsc73xx: fix port MAC configuration in full duplex mode Pawel Dembicki
2024-07-29 21:06 ` [PATCH net-next 3/9] net: dsa: vsc73xx: pass value in phy_write operation Pawel Dembicki
2024-07-29 21:06 ` [PATCH net-next 4/9] net: dsa: vsc73xx: use defined values in phy operations Pawel Dembicki
2024-07-29 21:06 ` [PATCH net-next 5/9] net: dsa: vsc73xx: use mutex to mdio operations Pawel Dembicki
2024-07-29 23:07 ` Andrew Lunn
2024-07-29 21:06 ` [PATCH net-next 6/9] net: dsa: vsc73xx: speed up mdio bus to max allowed value Pawel Dembicki
2024-07-29 23:10 ` Andrew Lunn
2024-07-30 18:55 ` Paweł Dembicki
2024-07-30 20:23 ` Andrew Lunn
2024-07-29 21:06 ` [PATCH net-next 7/9] net: dsa: vsc73xx: allow phy resetting Pawel Dembicki
2024-07-29 21:06 ` [PATCH net-next 8/9] net: phy: vitesse: repair vsc73xx autonegotiation Pawel Dembicki
2024-07-29 21:06 ` [PATCH net-next 9/9] net: phy: vitesse: implement downshift in vsc73xx phys Pawel Dembicki
2024-07-29 23:39 ` Russell King (Oracle) [this message]
2024-07-29 22:53 ` [PATCH net-next 0/9] net: dsa: vsc73xx: fix MDIO bus access and PHY operations Andrew Lunn
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=ZqgoLC77GeJ1yyYq@shell.armlinux.org.uk \
--to=linux@armlinux.org.uk \
--cc=andrew@lunn.ch \
--cc=davem@davemloft.net \
--cc=edumazet@google.com \
--cc=f.fainelli@gmail.com \
--cc=hkallweit1@gmail.com \
--cc=kuba@kernel.org \
--cc=linus.walleij@linaro.org \
--cc=linux-kernel@vger.kernel.org \
--cc=netdev@vger.kernel.org \
--cc=olteanv@gmail.com \
--cc=pabeni@redhat.com \
--cc=paweldembicki@gmail.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;
as well as URLs for NNTP newsgroup(s).