[Patch net-next v6 7/7] r8169: support setting rx queue numbers via ethtool
From: javen <hidden>
Date: 2026-05-26 08:11:56
Also in:
lkml
Subsystem:
8169 10/100/1000 gigabit ethernet driver, networking drivers, the rest · Maintainers:
Heiner Kallweit, Andrew Lunn, "David S. Miller", Eric Dumazet, Jakub Kicinski, Paolo Abeni, Linus Torvalds
From: Javen Xu <redacted> This patch add support for changing rx queues by ethtool. We can set rx 1, 2, 4, 8 by ethtool -L eth1 rx num. Signed-off-by: Javen Xu <redacted> --- Changes in v2: - no changes Changes in v3: - no changes Changes in v4: - remove rss_support and rss_enable - remove some zero-initialized - use kzalloc_objs instead of kcalloc Changes in v5: - no changes Changes in v6: - change subject of this patch - defer the assignment of tp->init_rx_desc_type until after rtl8169_down() - call netif_set_real_num_rx_queues() to synchronize the new rx queue number with networking core --- drivers/net/ethernet/realtek/r8169_main.c | 125 ++++++++++++++++++++++ 1 file changed, 125 insertions(+)
diff --git a/drivers/net/ethernet/realtek/r8169_main.c b/drivers/net/ethernet/realtek/r8169_main.c
index bf031f09437f..039465cd7ee1 100644
--- a/drivers/net/ethernet/realtek/r8169_main.c
+++ b/drivers/net/ethernet/realtek/r8169_main.c@@ -6253,6 +6253,129 @@ static void r8169_init_napi(struct rtl8169_private *tp) devm_add_action_or_reset(&tp->pci_dev->dev, r8169_del_napi_action, tp); } +static void rtl8169_get_channels(struct net_device *dev, + struct ethtool_channels *ch) +{ + struct rtl8169_private *tp = netdev_priv(dev); + + ch->max_rx = tp->hw_supp_num_rx_queues; + ch->max_tx = 1; + + ch->rx_count = tp->num_rx_rings; + ch->tx_count = 1; +} + +static int rtl8169_realloc_rx(struct rtl8169_private *tp, + struct rtl8169_rx_ring *new_rx, + int new_count) +{ + int i, ret; + + for (i = 0; i < new_count; i++) { + struct rtl8169_rx_ring *ring = &new_rx[i]; + + ring->rx_desc_array = dma_alloc_coherent(&tp->pci_dev->dev, + R8169_RX_RING_BYTES, + &ring->rx_phy_addr, + GFP_KERNEL); + if (!ring->rx_desc_array) { + ret = -ENOMEM; + goto err_free; + } + + memset(ring->rx_databuff, 0, sizeof(ring->rx_databuff)); + ret = rtl8169_rx_fill(tp, ring); + if (ret) { + dma_free_coherent(&tp->pci_dev->dev, R8169_RX_RING_BYTES, + ring->rx_desc_array, ring->rx_phy_addr); + goto err_free; + } + } + return 0; + +err_free: + while (--i >= 0) { + rtl8169_rx_clear(tp, &new_rx[i]); + dma_free_coherent(&tp->pci_dev->dev, R8169_RX_RING_BYTES, + new_rx[i].rx_desc_array, new_rx[i].rx_phy_addr); + } + return ret; +} + +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); + enum rx_desc_type old_rx_desc_type; + enum rx_desc_type new_desc_type; + struct rtl8169_rx_ring *new_rx; + int i, ret; + + old_rx_desc_type = tp->init_rx_desc_type; + + if (!rtl_hw_support_rss(tp)) { + netdev_warn(dev, "This chip does not support multiple channels/RSS.\n"); + return -EOPNOTSUPP; + } + + if (ch->rx_count > R8169_MAX_RX_QUEUES) + return -EINVAL; + + new_desc_type = ch->rx_count > 1 ? RX_DESC_TYPE_RSS : RX_DESC_TYPE_DEFAULT; + + if (!if_running) { + tp->num_rx_rings = ch->rx_count; + tp->init_rx_desc_type = new_desc_type; + return 0; + } + + netif_stop_queue(dev); + rtl8169_down(tp); + + new_rx = kzalloc_objs(*new_rx, R8169_MAX_RX_QUEUES); + if (!new_rx) + return -ENOMEM; + + tp->init_rx_desc_type = new_desc_type; + ret = rtl8169_realloc_rx(tp, new_rx, ch->rx_count); + if (ret) { + tp->init_rx_desc_type = old_rx_desc_type; + kfree(new_rx); + return ret; + } + + for (i = 0; i < tp->num_rx_rings; i++) + rtl8169_rx_clear(tp, &tp->rx_ring[i]); + rtl8169_free_rx_desc(tp); + + tp->num_rx_rings = ch->rx_count; + + memset(tp->rx_ring, 0, sizeof(tp->rx_ring)); + memcpy(tp->rx_ring, new_rx, sizeof(*new_rx) * ch->rx_count); + + for (i = 0; i < tp->rss_data->hw_supp_indir_tbl_entries; i++) { + if (ch->rx_count > 1) + tp->rss_data->rss_indir_tbl[i] = + ethtool_rxfh_indir_default(i, tp->num_rx_rings); + else + tp->rss_data->rss_indir_tbl[i] = 0; + } + + rtl_set_irq_mask(tp); + + rtl8169_up(tp); + netif_start_queue(dev); + + ret = netif_set_real_num_rx_queues(dev, ch->rx_count); + if (ret) + netdev_warn(dev, "Failed to set real num rx queues\n"); + + kfree(new_rx); + + return 0; +} + static const struct ethtool_ops rtl8169_ethtool_ops = { .supported_coalesce_params = ETHTOOL_COALESCE_USECS | ETHTOOL_COALESCE_MAX_FRAMES,
@@ -6271,6 +6394,8 @@ static const struct ethtool_ops rtl8169_ethtool_ops = { .nway_reset = phy_ethtool_nway_reset, .get_eee = rtl8169_get_eee, .set_eee = rtl8169_set_eee, + .get_channels = rtl8169_get_channels, + .set_channels = rtl8169_set_channels, .get_link_ksettings = phy_ethtool_get_link_ksettings, .set_link_ksettings = rtl8169_set_link_ksettings, .get_ringparam = rtl8169_get_ringparam,
--
2.43.0