Re: [RFC Patch net-next v1 9/9] r8169: add support for ethtool

Andrew Lunn
2026-04-20T13:11:04Z

> +static int rtl8169_set_channels(struct net_device *dev,
> + struct ethtool_channels *ch)
> +{
> + struct rtl8169_private *tp = netdev_priv(dev);
> + bool if_running = netif_running(dev);
> + int i;
> +
> + if (!tp->rss_support && (ch->rx_count > 1 || ch->tx_count > 1)) {
> + netdev_warn(dev, "This chip does not support multiple channels/RSS.\n");
> + return -EOPNOTSUPP;
> + }
> +
> + if (ch->rx_count == 0 || ch->tx_count == 0)
> + return -EINVAL;
> + if (ch->rx_count > tp->HwSuppNumRxQueues ||
> + ch->tx_count > tp->HwSuppNumTxQueues)
> + return -EINVAL;
> + if (ch->other_count || ch->combined_count)
> + return -EINVAL;
> +
> + if (ch->rx_count == tp->num_rx_rings &&
> + ch->tx_count == tp->num_tx_rings)
> + return 0;
> +
> + if (if_running)
> + rtl8169_close(dev);

I assume this releases all the memory from the rings?

> +
> + tp->num_rx_rings = ch->rx_count;
> + tp->num_tx_rings = ch->tx_count;
> +
> + tp->rss_enable = (tp->num_rx_rings > 1 && tp->rss_support);
> +
> + for (i = 0; i < tp->HwSuppIndirTblEntries; i++) {
> + if (tp->rss_enable)
> + tp->rss_indir_tbl[i] = ethtool_rxfh_indir_default(i, tp->num_rx_rings);
> + else
> + tp->rss_indir_tbl[i] = 0;
> + }
> +
> + if (tp->rss_enable)
> + tp->InitRxDescType = RX_DESC_RING_TYPE_RSS;
> + else
> + tp->InitRxDescType = RX_DESC_RING_TYPE_DEAFULT;
> +
> + if (if_running)
> + return rtl_open(dev);

And this tries to allocate the memory needed for the rings? And if the
system is under memory pressure, it fails and your network is dead?

Please modify the code so that is first allocated the new rings and
then frees the old rings, so you can fail gracefully.

Andrew