From: Andrew Lunn <andrew@lunn.ch>
To: Kyle Switch <kyle.switch@motor-comm.com>
Cc: Frank.Sae@motor-comm.com, hkallweit1@gmail.com,
linux@armlinux.org.uk, davem@davemloft.net, edumazet@google.com,
kuba@kernel.org, pabeni@redhat.com, netdev@vger.kernel.org,
linux-kernel@vger.kernel.org, jianmin.wang@motor-comm.com,
xiaolin.xu@motor-comm.com, ming.xu@motor-comm.com,
jie.han@motor-comm.com
Subject: Re: [Patch net-next v2 2/2] net: phy: Add driver for Motorcomm Quad 2.5GbE phy
Date: Thu, 16 Jul 2026 19:16:11 +0200 [thread overview]
Message-ID: <6bb415f2-5e41-4002-90e5-3d37d881b391@lunn.ch> (raw)
In-Reply-To: <20260715121012.1113552-1-kyle.switch@motor-comm.com>
> +#define YT8824_RSSR_SPACE_MASK BIT(0)
> +#define YT8824_RSSR_FIBER_SPACE (0x1)
> +#define YT8824_RSSR_UTP_SPACE (0x0)
Since there are only two pages, one bit:
> +/**
> + * yt8824_read_page() - read reg page
> + * @phydev: a pointer to a &struct phy_device
> + *
> + * returns current reg space of yt8824 (YT8824_RSSR_FIBER_SPACE/
> + * YT8824_RSSR_UTP_SPACE) or negative errno code
> + */
> +static int yt8824_read_page(struct phy_device *phydev)
> +{
> + int old_page;
> +
> + old_page = ytphy_read_top_ext_with_lock(phydev, YT8521_REG_SPACE_SELECT_REG);
> + if (old_page < 0)
> + return old_page;
> +
> + if ((old_page & YT8824_RSSR_SPACE_MASK) == YT8824_RSSR_FIBER_SPACE)
> + return YT8824_RSSR_FIBER_SPACE;
> +
> + return YT8824_RSSR_UTP_SPACE;
You can simplify this to just
return old_page & YT8824_RSSR_SPACE_MASK;
> +static int yt8824_write_page(struct phy_device *phydev, int page)
> +{
> + int old_page;
> + u16 data;
> +
> + old_page = ytphy_read_top_ext_with_lock(phydev, YT8521_REG_SPACE_SELECT_REG);
> + data = old_page & (~(0x1));
Use YT8824_RSSR_SPACE_MASK here.
> + data |= page;
> +
> + return ytphy_write_top_ext_with_lock(phydev, YT8521_REG_SPACE_SELECT_REG, data);
> +};
> +
> +/**
> + * configuration YT8824 to one template test mode.
> + */
> +static int yt8824_soft_reset_step1_paged(struct phy_device *phydev,
> + int reg_space)
> +{
> + int old_page;
> + int ret = 0;
> +
> + old_page = phy_select_page(phydev, reg_space);
> + if (old_page < 0)
> + goto err_restore_page;
> +
> + if (old_page >= 0) {
What is the purpose of this if ()?
> + if (reg_space == YT8824_RSSR_UTP_SPACE) {
> + ret = __phy_write_mmd(phydev, 0x1, 0x0084, 0x2000);
No magic numbers. 0x0084 is probably not a vendor register either, so
please use its proper name. And is 0x2000 a value, or should it bit it
use the BIT() macro?
> + ret = __phy_read(phydev, MII_BMCR);
> + if (ret < 0)
> + goto err_restore_page;
> + ret |= BMCR_RESET;
> + ret = __phy_write(phydev, MII_BMCR, ret);
> + if (ret < 0)
> + goto err_restore_page;
> + do {
> + msleep(50);
> + ret = __phy_read(phydev, MII_BMCR);
> + if (ret < 0)
> + goto err_restore_page;
> + } while ((ret & BMCR_RESET) && --retry);
> + ret = __phy_read(phydev, MII_BMCR);
> + if (ret < 0)
> + goto err_restore_page;
> + /* disable isolation */
> + ret &= ~BIT(10);
That is probably a standard BMCR bit, so there should be a#define for
it.
> + /* soft reset */
> + ret |= BMCR_RESET;
> + ret = __phy_write(phydev, MII_BMCR, ret);
> + if (ret < 0)
> + return ret;
> + do {
> + msleep(50);
> + ret = __phy_read(phydev, MII_BMCR);
> + if (ret < 0)
> + goto err_restore_page;
> + } while ((ret & BMCR_RESET) && --retry);
> + if (ret & BMCR_RESET)
> + goto err_restore_page;
Look at all the duplicated code here. Please add some helpers.
Also take a look at phy_device.c, and follow what it does.
> + if (phydev->interface == PHY_INTERFACE_MODE_INTERNAL) {
> + /* invalid test mode */
> + ret = yt8824_soft_reset_step1_paged(phydev,
> + YT8824_RSSR_UTP_SPACE);
Why not call this function
yt8824_soft_reset_invalid_test_mode_paged(). Having the comment is a
big hint your function naming is bad.
> +static int yt8824_internal_config_init_paged(struct phy_device *phydev,
> + int reg_space)
> +{
> + struct yt8521_priv *priv = phydev->priv;
> + int old_page;
> + int port = 0;
> + int ret = 0;
> +
> + old_page = phy_select_page(phydev, reg_space);
> + if (old_page < 0)
> + goto err_restore_page;
> +
> + port = phydev->mdio.addr - priv->phy_base_addr;
> + ret = ytphy_write_ext(phydev, 0x1, 0x3);
> + if (ret < 0)
> + goto err_restore_page;
> + ret = __phy_write(phydev, MII_BMCR, 0x1900);
All the magic numbers need to be replaced. But this is especially bad,
because BMCR is well documented and has all its bits covered with
existing #define's.
> + netdev_info(phydev->attached_dev,
> + "%s done, phy addr: %d, phy base addr = %d\n",
> + __func__, phydev->mdio.addr, priv->phy_base_addr);
Very unusual. This is a PHY driver, so it should be using
phy_info(). But i also think this should be _dgb().
Andrew
next prev parent reply other threads:[~2026-07-16 17:16 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-07-15 12:10 [Patch net-next v2 2/2] net: phy: Add driver for Motorcomm Quad 2.5GbE phy Kyle Switch
2026-07-16 16:48 ` Andrew Lunn
2026-07-16 17:16 ` Andrew Lunn [this message]
2026-07-17 5:31 ` Kyle Switch
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=6bb415f2-5e41-4002-90e5-3d37d881b391@lunn.ch \
--to=andrew@lunn.ch \
--cc=Frank.Sae@motor-comm.com \
--cc=davem@davemloft.net \
--cc=edumazet@google.com \
--cc=hkallweit1@gmail.com \
--cc=jianmin.wang@motor-comm.com \
--cc=jie.han@motor-comm.com \
--cc=kuba@kernel.org \
--cc=kyle.switch@motor-comm.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux@armlinux.org.uk \
--cc=ming.xu@motor-comm.com \
--cc=netdev@vger.kernel.org \
--cc=pabeni@redhat.com \
--cc=xiaolin.xu@motor-comm.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