From: Lukasz Majewski <lukma@denx.de>
To: Andrew Lunn <andrew@lunn.ch>
Cc: Andrew Lunn <andrew+netdev@lunn.ch>,
davem@davemloft.net, Eric Dumazet <edumazet@google.com>,
Jakub Kicinski <kuba@kernel.org>, Paolo Abeni <pabeni@redhat.com>,
Rob Herring <robh@kernel.org>,
Krzysztof Kozlowski <krzk+dt@kernel.org>,
Conor Dooley <conor+dt@kernel.org>,
Shawn Guo <shawnguo@kernel.org>,
Sascha Hauer <s.hauer@pengutronix.de>,
Pengutronix Kernel Team <kernel@pengutronix.de>,
Fabio Estevam <festevam@gmail.com>,
Richard Cochran <richardcochran@gmail.com>,
netdev@vger.kernel.org, devicetree@vger.kernel.org,
linux-kernel@vger.kernel.org, imx@lists.linux.dev,
linux-arm-kernel@lists.infradead.org
Subject: Re: [PATCH v3 4/4] net: mtip: The L2 switch driver for imx287
Date: Sun, 6 Apr 2025 23:24:31 +0200 [thread overview]
Message-ID: <20250406232431.48e837e0@wsk> (raw)
In-Reply-To: <8f431197-474e-4cd5-9c3e-d573c3f3e6b5@lunn.ch>
[-- Attachment #1: Type: text/plain, Size: 4693 bytes --]
Hi Andrew,
> > +static void read_atable(struct switch_enet_private *fep, int index,
> > + unsigned long *read_lo, unsigned long
> > *read_hi) +{
> > + unsigned long atable_base = (unsigned long)fep->hwentry;
> > +
> > + *read_lo = readl((const void *)atable_base + (index << 3));
> > + *read_hi = readl((const void *)atable_base + (index << 3)
> > + 4); +}
> > +
> > +static void write_atable(struct switch_enet_private *fep, int
> > index,
> > + unsigned long write_lo, unsigned long
> > write_hi) +{
> > + unsigned long atable_base = (unsigned long)fep->hwentry;
> > +
> > + writel(write_lo, (void *)atable_base + (index << 3));
> > + writel(write_hi, (void *)atable_base + (index << 3) + 4);
> > +}
>
> It would be nice to have the mtip_ prefix on all functions.
Ok.
>
> > +static int mtip_open(struct net_device *dev)
> > +{
> > + struct mtip_ndev_priv *priv = netdev_priv(dev);
> > + struct switch_enet_private *fep = priv->fep;
> > + int ret, port_idx = priv->portnum - 1;
> > +
> > + if (fep->usage_count == 0) {
> > + clk_enable(fep->clk_ipg);
> > + netif_napi_add(dev, &fep->napi, mtip_rx_napi);
> > +
> > + ret = mtip_alloc_buffers(dev);
> > + if (ret)
> > + return ret;
>
> nitpick: You might want to turn the clock off before returning the
> error.
Ok.
>
> > + }
> > +
> > + fep->link[port_idx] = 0;
> > +
> > + /* Probe and connect to PHY when open the interface, if
> > already
> > + * NOT done in the switch driver probe (or when the device
> > is
> > + * re-opened).
> > + */
> > + ret = mtip_mii_probe(dev);
> > + if (ret) {
> > + mtip_free_buffers(dev);
>
> I've not checked. Does this do the opposite of netif_napi_add()?
No, the netif_napi_add() is required here as well.
>
> > +static void mtip_set_multicast_list(struct net_device *dev)
> > +{
> > + unsigned int i, bit, data, crc;
> > +
> > + if (dev->flags & IFF_PROMISC) {
> > + dev_info(&dev->dev, "%s: IFF_PROMISC\n",
> > __func__);
>
> You can save one level of indentation with a return here.
Ok.
>
> > + } else {
> > + if (dev->flags & IFF_ALLMULTI) {
> > + dev_info(&dev->dev, "%s: IFF_ALLMULTI\n",
> > __func__);
>
> and other level here.
Ok.
>
> > + } else {
> > + struct netdev_hw_addr *ha;
> > + u_char *addrs;
> > +
> > + netdev_for_each_mc_addr(ha, dev) {
> > + addrs = ha->addr;
> > + /* Only support group multicast
> > for now */
> > + if (!(*addrs & 1))
> > + continue;
>
> You could pull there CRC caluclation out into a helper. You might also
> want to search the tree and see if it exists somewhere else.
>
The ether_crc_le(ndev->addr_len,·ha->addr); could be the replacement.
However, when I look on the code and compare it with fec_main.c's
set_multicast_list() - it looks like a dead code.
The calculated hash is not used at all (in fec_main.c it is written to
some registers).
I've refactored the code to do similar things, but taking into account
already set switch setup (promisc must be enabled from the outset).
> > +
> > + /* calculate crc32 value of mac
> > address */
> > + crc = 0xffffffff;
> > +
> > + for (i = 0; i < 6; i++) {
>
> Is 6 the lengh of a MAC address? There is a #define for that.
This is not needed and can be replaced with already present function.
>
> > + data = addrs[i];
> > + for (bit = 0; bit < 8;
> > + bit++, data >>= 1) {
> > + crc = (crc >> 1) ^
> > + (((crc ^ data) &
> > 1) ?
> > + CRC32_POLY : 0);
> > + }
> > + }
> > + }
> > + }
> > + }
> > +}
> > +
>
> > +struct switch_enet_private *mtip_netdev_get_priv(const struct
> > net_device *ndev) +{
> > + if (ndev->netdev_ops == &mtip_netdev_ops)
> > + return netdev_priv(ndev);
> > +
> > + return NULL;
> > +}
> > +
>
> > +static int __init mtip_switch_dma_init(struct switch_enet_private
> > *fep) +{
> > + struct cbd_t *bdp, *cbd_base;
> > + int ret, i;
> > +
> > + /* Check mask of the streaming and coherent API */
> > + ret = dma_set_mask_and_coherent(&fep->pdev->dev,
> > DMA_BIT_MASK(32));
> > + if (ret < 0) {
> > + dev_warn(&fep->pdev->dev, "No suitable DMA
> > available\n");
>
> Can you recover from this? Or should it be dev_err()?
>
It was my mistake - of course there shall be dev_err().
> More later...
>
> Andrew
Best regards,
Lukasz Majewski
--
DENX Software Engineering GmbH, Managing Director: Erika Unter
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: (+49)-8142-66989-59 Fax: (+49)-8142-66989-80 Email: lukma@denx.de
[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 488 bytes --]
next prev parent reply other threads:[~2025-04-06 21:24 UTC|newest]
Thread overview: 24+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-03-31 10:31 [PATCH v3 0/4] net: mtip: Add support for MTIP imx287 L2 switch driver Lukasz Majewski
2025-03-31 10:31 ` [PATCH v3 1/4] dt-bindings: net: Add MTIP L2 switch description Lukasz Majewski
2025-03-31 18:13 ` Fabio Estevam
2025-03-31 19:11 ` Lukasz Majewski
2025-03-31 23:55 ` Rob Herring
2025-04-01 10:35 ` Lukasz Majewski
2025-04-01 23:03 ` Rob Herring
2025-04-02 9:09 ` Lukasz Majewski
2025-03-31 10:31 ` [PATCH v3 2/4] ARM: dts: nxp: mxs: Adjust the imx28.dtsi " Lukasz Majewski
2025-04-02 12:22 ` Andrew Lunn
2025-03-31 10:31 ` [PATCH v3 3/4] ARM: dts: nxp: mxs: Adjust XEA board's DTS to support L2 switch Lukasz Majewski
2025-03-31 20:53 ` Stefan Wahren
2025-03-31 21:43 ` Lukasz Majewski
2025-03-31 10:31 ` [PATCH v3 4/4] net: mtip: The L2 switch driver for imx287 Lukasz Majewski
2025-04-02 12:47 ` Andrew Lunn
2025-04-06 21:24 ` Lukasz Majewski [this message]
2025-04-02 17:06 ` Andrew Lunn
2025-04-02 17:25 ` Andrew Lunn
2025-04-07 9:42 ` Lukasz Majewski
2025-03-31 17:10 ` [PATCH v3 0/4] net: mtip: Add support for MTIP imx287 L2 switch driver Jakub Kicinski
2025-03-31 19:11 ` Lukasz Majewski
2025-03-31 20:38 ` Stefan Wahren
2025-03-31 21:42 ` Lukasz Majewski
2025-04-01 16:33 ` Stefan Wahren
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=20250406232431.48e837e0@wsk \
--to=lukma@denx.de \
--cc=andrew+netdev@lunn.ch \
--cc=andrew@lunn.ch \
--cc=conor+dt@kernel.org \
--cc=davem@davemloft.net \
--cc=devicetree@vger.kernel.org \
--cc=edumazet@google.com \
--cc=festevam@gmail.com \
--cc=imx@lists.linux.dev \
--cc=kernel@pengutronix.de \
--cc=krzk+dt@kernel.org \
--cc=kuba@kernel.org \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=linux-kernel@vger.kernel.org \
--cc=netdev@vger.kernel.org \
--cc=pabeni@redhat.com \
--cc=richardcochran@gmail.com \
--cc=robh@kernel.org \
--cc=s.hauer@pengutronix.de \
--cc=shawnguo@kernel.org \
/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).