From a6da3a41cb335d300af82d6fee39437d54c238bb Mon Sep 17 00:00:00 2001 From: Alex Forencich Date: Wed, 3 May 2023 01:35:01 -0700 Subject: [PATCH] modules/mqnic: Implement ethtool channels API Signed-off-by: Alex Forencich --- modules/mqnic/mqnic_ethtool.c | 53 +++++++++++++++++++++++++++++++++++ modules/mqnic/mqnic_netdev.c | 3 ++ 2 files changed, 56 insertions(+) diff --git a/modules/mqnic/mqnic_ethtool.c b/modules/mqnic/mqnic_ethtool.c index 543f788bb..4c468df21 100644 --- a/modules/mqnic/mqnic_ethtool.c +++ b/modules/mqnic/mqnic_ethtool.c @@ -146,6 +146,57 @@ static int mqnic_set_ringparam(struct net_device *ndev, return ret; } +static void mqnic_get_channels(struct net_device *ndev, + struct ethtool_channels *channel) +{ + struct mqnic_priv *priv = netdev_priv(ndev); + + channel->max_rx = mqnic_res_get_count(priv->interface->rxq_res); + channel->max_tx = mqnic_res_get_count(priv->interface->txq_res); + + channel->rx_count = priv->rxq_count; + channel->tx_count = priv->txq_count; +} + +static int mqnic_set_channels(struct net_device *ndev, + struct ethtool_channels *channel) +{ + struct mqnic_priv *priv = netdev_priv(ndev); + u32 txq_count, rxq_count; + int port_up = priv->port_up; + int ret = 0; + + rxq_count = channel->rx_count; + txq_count = channel->tx_count; + + if (rxq_count == priv->rxq_count && + txq_count == priv->txq_count) + return 0; + + dev_info(priv->dev, "New TX channel count: %d", txq_count); + dev_info(priv->dev, "New RX channel count: %d", rxq_count); + + mutex_lock(&priv->mdev->state_lock); + + if (port_up) + mqnic_stop_port(ndev); + + priv->txq_count = txq_count; + priv->rxq_count = rxq_count; + + if (port_up) { + ret = mqnic_start_port(ndev); + + if (ret) + dev_err(priv->dev, "%s: Failed to start port on interface %d netdev %d: %d", + __func__, priv->interface->index, priv->index, ret); + } + + mutex_unlock(&priv->mdev->state_lock); + + return ret; +} + static int mqnic_get_ts_info(struct net_device *ndev, struct ethtool_ts_info *info) { @@ -433,6 +484,8 @@ const struct ethtool_ops mqnic_ethtool_ops = { .get_link = ethtool_op_get_link, .get_ringparam = mqnic_get_ringparam, .set_ringparam = mqnic_set_ringparam, + .get_channels = mqnic_get_channels, + .set_channels = mqnic_set_channels, .get_ts_info = mqnic_get_ts_info, .get_module_info = mqnic_get_module_info, .get_module_eeprom = mqnic_get_module_eeprom, diff --git a/modules/mqnic/mqnic_netdev.c b/modules/mqnic/mqnic_netdev.c index e2a6183e3..0d2771cd8 100644 --- a/modules/mqnic/mqnic_netdev.c +++ b/modules/mqnic/mqnic_netdev.c @@ -53,6 +53,9 @@ int mqnic_start_port(struct net_device *ndev) dev_info(mdev->dev, "%s on interface %d netdev %d", __func__, priv->interface->index, priv->index); + netif_set_real_num_tx_queues(ndev, priv->txq_count); + netif_set_real_num_rx_queues(ndev, priv->rxq_count); + desc_block_size = min_t(u32, priv->interface->max_desc_block_size, 4); // set up RX queues