From: Kyle Switch <kyle.switch@motor-comm.com>
To: Andrew Lunn <andrew@lunn.ch>
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: Fri, 17 Jul 2026 13:31:29 +0800 [thread overview]
Message-ID: <135b1c98-ab20-4201-b8fb-117423e134d4@motor-comm.com> (raw)
In-Reply-To: <6bb415f2-5e41-4002-90e5-3d37d881b391@lunn.ch>
On 7/17/26 01:16, Andrew Lunn wrote:
>> +#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;
>
Ans: Fixed in v3 patch, Please help check in updated patch.
>> +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 ()?
Ans: remove the unnecessary and redundant judgment in v3 patch.
>
>> + 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?
Ans: Fixed in v3 patch.
>
>> + 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.
Ans: Fix all BMCR bit in V3.
>
>> + /* 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.
Ans: Fixed in v3 patch using phy_read_poll_timeout to wait softret done.
>
>> + 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.
Ans: Fixed in v3 patch, to rename the function based on
its approximate functionality
>
>> +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.
>
Ans: All standard BMCR registers operations have been replaced in the v3 patch.
However, for some extend registers, they are designed to optimize
the performance of phy8824. If they are also replaced, the entire function may
become bloated, so they have not been replaced for the time being.
>> + 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().
Ans: yes, it will be fixed in V3 using phydev_dbg().
>
> Andrew
prev parent reply other threads:[~2026-07-17 5:31 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
2026-07-17 5:31 ` Kyle Switch [this message]
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=135b1c98-ab20-4201-b8fb-117423e134d4@motor-comm.com \
--to=kyle.switch@motor-comm.com \
--cc=Frank.Sae@motor-comm.com \
--cc=andrew@lunn.ch \
--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=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