Re: [net-next v19 4/7] net: mtip: Add net_device_ops functions to the L2 switch driver

Jakub Kicinski
2025-08-27T19:43:19Z

On Mon, 25 Aug 2025 00:07:33 +0200 Lukasz Majewski wrote:
> + /* Set buffer length and buffer pointer */
> + bufaddr = skb->data;

You can't write (swap) skb->data if the skb is a clone..

> + bdp->cbd_datlen = skb->len;
> +
> + /* On some FEC implementations data must be aligned on
> + * 4-byte boundaries. Use bounce buffers to copy data
> + * and get it aligned.spin
> + */
> + if ((unsigned long)bufaddr & MTIP_ALIGNMENT) {

add
.. ||
(fep->quirks & FEC_QUIRK_SWAP_FRAME && skb_cloned(skb))

here to switch to the local buffer for clones ?

> + unsigned int index;
> +
> + index = bdp - fep->tx_bd_base;
> + memcpy(fep->tx_bounce[index], skb->data, skb->len);
> + bufaddr = fep->tx_bounce[index];
> + }
> +
> + if (fep->quirks & FEC_QUIRK_SWAP_FRAME)
> + swap_buffer(bufaddr, skb->len);

> + if (unlikely(dma_mapping_error(&fep->pdev->dev, bdp->cbd_bufaddr))) {
> + dev_err(&fep->pdev->dev,
> + "Failed to map descriptor tx buffer\n");

All per-packet prints must be rate limited

> + /* Since we have freed up a buffer, the ring is no longer
> + * full.
> + */
> + if (fep->tx_full) {
> + fep->tx_full = 0;
> + if (netif_queue_stopped(dev))
> + netif_wake_queue(dev);
> + }

I must say I'm still quite confused by the netdev management in this
driver. You seem to have 2 netdevs, one per port. There's one
set of queues and one NAPI. Whichever netdev gets up first gets the
NAPI. What makes my head spin is that you seem to record which
netdev/port was doing Rx _last_ and then pass that netdev to
mtip_switch_tx(). Why? Isn't the dev that we're completing Tx for is
best read from skb->dev packet by packet? Also this wake up logic looks
like it will wake up _one_ netdev's queue and then set tx_full = 0, so
presumably it will not wake the other port if both ports queues were
stopped. Why keep tx_full state in the first place? Just check if the
queues is stopped..?