From: Andrew Lunn <andrew@lunn.ch>
To: Frank Sae <Frank.Sae@motor-comm.com>
Cc: davem@davemloft.net, edumazet@google.com, kuba@kernel.org,
pabeni@redhat.com, netdev@vger.kernel.org,
linux-kernel@vger.kernel.org, xiaogang.fan@motor-comm.com,
fei.zhang@motor-comm.com, hua.sun@motor-comm.com
Subject: Re: [PATCH net-next v2 09/21] motorcomm:yt6801: Implement some hw_ops function
Date: Mon, 25 Nov 2024 15:39:57 +0100 [thread overview]
Message-ID: <cd57707a-2d7e-4549-aab1-d0bd6c24ad35@lunn.ch> (raw)
In-Reply-To: <11e26658-670f-49fa-8001-0654670b541e@motor-comm.com>
On Mon, Nov 25, 2024 at 05:49:19PM +0800, Frank Sae wrote:
> Hi Andrew,
>
> On 2024/11/23 09:03, Andrew Lunn wrote:
> > It took a lot of effort to find your MDIO code. And MDIO bus driver
> > makes a good patch on its own.
> >
>
> Sorry about that.
> There is too many codes in yt6801_hw.c file. If I put the MDIO bus driver
> in one patch, it's would be very difficult to limit to 15 patches.
You can easily limit this to 15 patches. Throw away 75% of the driver
for the moment. Do enough to get link and then send/receive
frames. Forget the rest. You don't need statistics, ethtool, WoL, and
everything else in the first submission. They can all be added later.
You need reviewers in order to get your driver merged. If you give
them a huge driver which is hard to find what they are interested in,
they won't review it, and it will not get merged. So break it up into
a number of patchsets. A minimum driver to just send/receive should be
nice and small, and can be split into 15 patches making it nice and
easy to find bits reviewers are interested in. That should get
reviewed and merged. Then add more and more features in nice small
chunks which are easy to review.
> >> +static int mdio_loop_wait(struct fxgmac_pdata *pdata, u32 max_cnt)
> >> +{
> >> + u32 val, i;
> >> +
> >> + for (i = 0; i < max_cnt; i++) {
> >> + val = rd32_mac(pdata, MAC_MDIO_ADDRESS);
> >> + if ((val & MAC_MDIO_ADDR_BUSY) == 0)
> >> + break;
> >> +
> >> + fsleep(10);
> >> + }
> >> +
> >> + if (i >= max_cnt) {
> >> + WARN_ON(1);
> >> + yt_err(pdata, "%s timeout. used cnt:%d, reg_val=%x.\n",
> >> + __func__, i + 1, val);
> >> +
> >> + return -ETIMEDOUT;
> >> + }
> >
> > Please replace this using one of the helpers in
> > include/linux/iopoll.h.
> >
> >> +#define PHY_WR_CONFIG(reg_offset) (0x8000205 + ((reg_offset) * 0x10000))
> >> +static int fxgmac_phy_write_reg(struct fxgmac_pdata *pdata, u32 reg_id, u32 data)
> >> +{
> >> + int ret;
> >> +
> >> + wr32_mac(pdata, data, MAC_MDIO_DATA);
> >> + wr32_mac(pdata, PHY_WR_CONFIG(reg_id), MAC_MDIO_ADDRESS);
> >> + ret = mdio_loop_wait(pdata, PHY_MDIO_MAX_TRY);
> >> + if (ret < 0)
> >> + return ret;
> >> +
> >> + yt_dbg(pdata, "%s, id:%x %s, ctrl:0x%08x, data:0x%08x\n", __func__,
> >> + reg_id, (ret == 0) ? "ok" : "err", PHY_WR_CONFIG(reg_id), data);
> >> +
> >> + return ret;
> >> +}
> >> +
> >> +#define PHY_RD_CONFIG(reg_offset) (0x800020d + ((reg_offset) * 0x10000))
> >> +static int fxgmac_phy_read_reg(struct fxgmac_pdata *pdata, u32 reg_id)
> >> +{
> >> + u32 val;
> >> + int ret;
> >> +
> >> + wr32_mac(pdata, PHY_RD_CONFIG(reg_id), MAC_MDIO_ADDRESS);
> >> + ret = mdio_loop_wait(pdata, PHY_MDIO_MAX_TRY);
> >> + if (ret < 0)
> >> + return ret;
> >> +
> >> + val = rd32_mac(pdata, MAC_MDIO_DATA); /* Read data */
> >> + yt_dbg(pdata, "%s, id:%x ok, ctrl:0x%08x, val:0x%08x.\n", __func__,
> >> + reg_id, PHY_RD_CONFIG(reg_id), val);
> >> +
> >> + return val;
> >> +}
> >
> > And where is the rest of the MDIO bus driver?
>
> There is no separate reset of MDIO bus driver.
rest, not reset.
An MDIO driver is generally two to five functions to do bus
transactions, and then one or two functions to allocate the bus
structure, fill in the members and register the bus, and maybe a
function to undo that. I would expect these all to be in one
patch. They are not.
At some point, you need to justify your hw_ops structure. Why do you
have this? At the moment it just obfuscate the code. Maybe there is a
good reason for it, but given the size of the driver i've not been
able to find it.
> >> +#define LINK_DOWN 0x800
> >> +#define LINK_UP 0x400
> >> +#define LINK_CHANGE (LINK_DOWN | LINK_UP)
> >> + if ((stats_pre & LINK_CHANGE) != (stats & LINK_CHANGE)) {
> >> + yt_dbg(pdata, "phy link change\n");
> >> + return 1;
> >> + }
> >> +
> >> + return 0;
> >> +unlock:
> >> + phy_unlock_mdio_bus(pdata->phydev);
> >> + yt_err(pdata, "fxgmac_phy_read_reg err!\n");
> >> + return -ETIMEDOUT;
> >> +}
> >
> > You need to rework your PHY interrupt handling. The PHY driver is
> > responsible for handing the interrupt registers in the PHY. Ideally
> > you just want to export an interrupt to phylib, so it can do all the
> > work.
>
> I'm sorry. Could you please give me more information about export
> an interrupt to phylib?
I would actually suggest you first just let phylib poll the PHY. That
gets you something working. You can add interrupt support in a later
patchset. For ideas, look at ksz_common.c:
ds->user_mii_bus->irq[phy] = irq;
You have a whole tree of source code you can look at, there are other
examples of MAC drivers exporting an interrupt controller. And you
might find other ways to do this, look at other MAC drivers. There is
nothing special here, so don't invent something new, copy what other
MAC drivers do.
Andrew
next prev parent reply other threads:[~2024-11-25 14:40 UTC|newest]
Thread overview: 40+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-11-20 10:56 [PATCH net-next v2 00/21] net:yt6801: Add Motorcomm yt6801 PCIe driver Frank Sae
2024-11-20 10:56 ` [PATCH net-next v2 03/21] motorcomm:yt6801: Implement the fxgmac_drv_probe function Frank Sae
2024-11-22 17:30 ` Vadim Fedorenko
2024-11-20 10:56 ` [PATCH net-next v2 04/21] motorcomm:yt6801: Implement the .ndo_open function Frank Sae
2024-11-20 10:56 ` [PATCH net-next v2 05/21] motorcomm:yt6801: Implement the fxgmac_start function Frank Sae
2024-11-22 23:16 ` Andrew Lunn
2024-11-25 9:31 ` Frank Sae
2024-11-25 14:18 ` Andrew Lunn
2024-11-26 3:15 ` Frank Sae
2024-11-26 9:28 ` Frank Sae
2024-11-26 13:48 ` Andrew Lunn
2024-11-20 10:56 ` [PATCH net-next v2 08/21] motorcomm:yt6801: Implement the fxgmac_read_mac_addr function Frank Sae
2024-11-20 10:56 ` [PATCH net-next v2 12/21] motorcomm:yt6801: Implement .ndo_tx_timeout and .ndo_change_mtu functions Frank Sae
2024-11-22 23:19 ` Andrew Lunn
2024-11-20 10:56 ` [PATCH net-next v2 13/21] motorcomm:yt6801: Implement some ethtool_ops function Frank Sae
2024-11-22 22:34 ` Andrew Lunn
2024-11-20 10:56 ` [PATCH net-next v2 14/21] motorcomm:yt6801: Implement the WOL function of ethtool_ops Frank Sae
2024-11-22 23:04 ` Andrew Lunn
2024-11-20 10:56 ` [PATCH net-next v2 15/21] motorcomm:yt6801: Implement pci_driver suspend and resume Frank Sae
2024-11-22 23:10 ` Andrew Lunn
2024-11-20 10:56 ` [PATCH net-next v2 16/21] motorcomm:yt6801: Add a Makefile in the motorcomm folder Frank Sae
2024-11-20 10:56 ` [PATCH net-next v2 17/21] motorcomm:yt6801: Update the Makefile and Kconfig in the motorcomm Frank Sae
2024-11-20 10:56 ` [PATCH net-next v2 18/21] motorcomm:yt6801: Update the Makefile and Kconfig in the ethernet Frank Sae
2024-11-20 10:56 ` [PATCH net-next v2 19/21] ethernet: Update the index.rst in the ethernet documentation folder Frank Sae
2024-11-20 10:56 ` [PATCH net-next v2 20/21] motorcomm:yt6801: Add a yt6801.rst " Frank Sae
2024-11-20 10:56 ` [PATCH net-next v2 21/21] MAINTAINERS:Add the motorcomm ethernet driver entry Frank Sae
2024-11-20 11:14 ` [PATCH net-next v2 11/21] motorcomm:yt6801: Implement some net_device_ops function Frank Sae
2024-11-20 11:14 ` [PATCH net-next v2 09/21] motorcomm:yt6801: Implement some hw_ops function Frank Sae
2024-11-23 1:03 ` Andrew Lunn
2024-11-25 9:49 ` Frank Sae
2024-11-25 14:39 ` Andrew Lunn [this message]
2024-11-26 3:04 ` Frank Sae
2024-11-21 1:52 ` [PATCH net-next v2 07/21] motorcomm:yt6801: Implement the fxgmac_init function Frank Sae
2024-11-21 1:53 ` [PATCH net-next v2 02/21] motorcomm:yt6801: Implement pci_driver shutdown Frank Sae
2024-11-21 1:53 ` [PATCH net-next v2 01/21] motorcomm:yt6801: Add support for a pci table in this module Frank Sae
2024-11-21 1:53 ` [PATCH net-next v2 06/21] motorcomm:yt6801: Implement the poll functions Frank Sae
2024-11-21 6:18 ` [PATCH net-next v2 10/21] motorcomm:yt6801: Implement .ndo_start_xmit function Frank Sae
2024-11-21 9:00 ` [PATCH net-next v2 00/21] net:yt6801: Add Motorcomm yt6801 PCIe driver Paolo Abeni
2024-11-22 22:14 ` Andrew Lunn
2024-11-23 0:45 ` 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=cd57707a-2d7e-4549-aab1-d0bd6c24ad35@lunn.ch \
--to=andrew@lunn.ch \
--cc=Frank.Sae@motor-comm.com \
--cc=davem@davemloft.net \
--cc=edumazet@google.com \
--cc=fei.zhang@motor-comm.com \
--cc=hua.sun@motor-comm.com \
--cc=kuba@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=netdev@vger.kernel.org \
--cc=pabeni@redhat.com \
--cc=xiaogang.fan@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
all inboxes | Powered by JetHome®