Skip to content

Commit 0366f7e

Browse files
elvinongbldavem330
authored andcommitted
net: stmmac: add ethtool support for get/set channels
Restructure NAPI add and delete process so that we can call them accordingly in open() and ethtool_set_channels() accordingly. Introduced stmmac_reinit_queues() to handle the transition needed for changing Rx & Tx channels accordingly. Signed-off-by: Ong Boon Leong <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent 945c570 commit 0366f7e

File tree

3 files changed

+93
-28
lines changed

3 files changed

+93
-28
lines changed

drivers/net/ethernet/stmicro/stmmac/stmmac.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -264,6 +264,7 @@ int stmmac_dvr_probe(struct device *device,
264264
struct stmmac_resources *res);
265265
void stmmac_disable_eee_mode(struct stmmac_priv *priv);
266266
bool stmmac_eee_init(struct stmmac_priv *priv);
267+
int stmmac_reinit_queues(struct net_device *dev, u32 rx_cnt, u32 tx_cnt);
267268

268269
#if IS_ENABLED(CONFIG_STMMAC_SELFTESTS)
269270
void stmmac_selftest_run(struct net_device *dev,

drivers/net/ethernet/stmicro/stmmac/stmmac_ethtool.c

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -840,6 +840,30 @@ static int stmmac_set_rxfh(struct net_device *dev, const u32 *indir,
840840
priv->plat->rx_queues_to_use);
841841
}
842842

843+
static void stmmac_get_channels(struct net_device *dev,
844+
struct ethtool_channels *chan)
845+
{
846+
struct stmmac_priv *priv = netdev_priv(dev);
847+
848+
chan->rx_count = priv->plat->rx_queues_to_use;
849+
chan->tx_count = priv->plat->tx_queues_to_use;
850+
chan->max_rx = priv->dma_cap.number_rx_queues;
851+
chan->max_tx = priv->dma_cap.number_tx_queues;
852+
}
853+
854+
static int stmmac_set_channels(struct net_device *dev,
855+
struct ethtool_channels *chan)
856+
{
857+
struct stmmac_priv *priv = netdev_priv(dev);
858+
859+
if (chan->rx_count > priv->dma_cap.number_rx_queues ||
860+
chan->tx_count > priv->dma_cap.number_tx_queues ||
861+
!chan->rx_count || !chan->tx_count)
862+
return -EINVAL;
863+
864+
return stmmac_reinit_queues(dev, chan->rx_count, chan->tx_count);
865+
}
866+
843867
static int stmmac_get_ts_info(struct net_device *dev,
844868
struct ethtool_ts_info *info)
845869
{
@@ -941,6 +965,8 @@ static const struct ethtool_ops stmmac_ethtool_ops = {
941965
.get_ts_info = stmmac_get_ts_info,
942966
.get_coalesce = stmmac_get_coalesce,
943967
.set_coalesce = stmmac_set_coalesce,
968+
.get_channels = stmmac_get_channels,
969+
.set_channels = stmmac_set_channels,
944970
.get_tunable = stmmac_get_tunable,
945971
.set_tunable = stmmac_set_tunable,
946972
.get_link_ksettings = stmmac_ethtool_get_link_ksettings,

drivers/net/ethernet/stmicro/stmmac/stmmac_main.c

Lines changed: 66 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -4739,6 +4739,69 @@ static int stmmac_hw_init(struct stmmac_priv *priv)
47394739
return 0;
47404740
}
47414741

4742+
static void stmmac_napi_add(struct net_device *dev)
4743+
{
4744+
struct stmmac_priv *priv = netdev_priv(dev);
4745+
u32 queue, maxq;
4746+
4747+
maxq = max(priv->plat->rx_queues_to_use, priv->plat->tx_queues_to_use);
4748+
4749+
for (queue = 0; queue < maxq; queue++) {
4750+
struct stmmac_channel *ch = &priv->channel[queue];
4751+
4752+
ch->priv_data = priv;
4753+
ch->index = queue;
4754+
4755+
if (queue < priv->plat->rx_queues_to_use) {
4756+
netif_napi_add(dev, &ch->rx_napi, stmmac_napi_poll_rx,
4757+
NAPI_POLL_WEIGHT);
4758+
}
4759+
if (queue < priv->plat->tx_queues_to_use) {
4760+
netif_tx_napi_add(dev, &ch->tx_napi,
4761+
stmmac_napi_poll_tx,
4762+
NAPI_POLL_WEIGHT);
4763+
}
4764+
}
4765+
}
4766+
4767+
static void stmmac_napi_del(struct net_device *dev)
4768+
{
4769+
struct stmmac_priv *priv = netdev_priv(dev);
4770+
u32 queue, maxq;
4771+
4772+
maxq = max(priv->plat->rx_queues_to_use, priv->plat->tx_queues_to_use);
4773+
4774+
for (queue = 0; queue < maxq; queue++) {
4775+
struct stmmac_channel *ch = &priv->channel[queue];
4776+
4777+
if (queue < priv->plat->rx_queues_to_use)
4778+
netif_napi_del(&ch->rx_napi);
4779+
if (queue < priv->plat->tx_queues_to_use)
4780+
netif_napi_del(&ch->tx_napi);
4781+
}
4782+
}
4783+
4784+
int stmmac_reinit_queues(struct net_device *dev, u32 rx_cnt, u32 tx_cnt)
4785+
{
4786+
struct stmmac_priv *priv = netdev_priv(dev);
4787+
int ret = 0;
4788+
4789+
if (netif_running(dev))
4790+
stmmac_release(dev);
4791+
4792+
stmmac_napi_del(dev);
4793+
4794+
priv->plat->rx_queues_to_use = rx_cnt;
4795+
priv->plat->tx_queues_to_use = tx_cnt;
4796+
4797+
stmmac_napi_add(dev);
4798+
4799+
if (netif_running(dev))
4800+
ret = stmmac_open(dev);
4801+
4802+
return ret;
4803+
}
4804+
47424805
/**
47434806
* stmmac_dvr_probe
47444807
* @device: device pointer
@@ -4755,7 +4818,7 @@ int stmmac_dvr_probe(struct device *device,
47554818
{
47564819
struct net_device *ndev = NULL;
47574820
struct stmmac_priv *priv;
4758-
u32 queue, rxq, maxq;
4821+
u32 rxq;
47594822
int i, ret = 0;
47604823

47614824
ndev = devm_alloc_etherdev_mqs(device, sizeof(struct stmmac_priv),
@@ -4920,25 +4983,7 @@ int stmmac_dvr_probe(struct device *device,
49204983
priv->flow_ctrl = FLOW_AUTO; /* RX/TX pause on */
49214984

49224985
/* Setup channels NAPI */
4923-
maxq = max(priv->plat->rx_queues_to_use, priv->plat->tx_queues_to_use);
4924-
4925-
for (queue = 0; queue < maxq; queue++) {
4926-
struct stmmac_channel *ch = &priv->channel[queue];
4927-
4928-
spin_lock_init(&ch->lock);
4929-
ch->priv_data = priv;
4930-
ch->index = queue;
4931-
4932-
if (queue < priv->plat->rx_queues_to_use) {
4933-
netif_napi_add(ndev, &ch->rx_napi, stmmac_napi_poll_rx,
4934-
NAPI_POLL_WEIGHT);
4935-
}
4936-
if (queue < priv->plat->tx_queues_to_use) {
4937-
netif_tx_napi_add(ndev, &ch->tx_napi,
4938-
stmmac_napi_poll_tx,
4939-
NAPI_POLL_WEIGHT);
4940-
}
4941-
}
4986+
stmmac_napi_add(ndev);
49424987

49434988
mutex_init(&priv->lock);
49444989

@@ -5003,14 +5048,7 @@ int stmmac_dvr_probe(struct device *device,
50035048
priv->hw->pcs != STMMAC_PCS_RTBI)
50045049
stmmac_mdio_unregister(ndev);
50055050
error_mdio_register:
5006-
for (queue = 0; queue < maxq; queue++) {
5007-
struct stmmac_channel *ch = &priv->channel[queue];
5008-
5009-
if (queue < priv->plat->rx_queues_to_use)
5010-
netif_napi_del(&ch->rx_napi);
5011-
if (queue < priv->plat->tx_queues_to_use)
5012-
netif_napi_del(&ch->tx_napi);
5013-
}
5051+
stmmac_napi_del(ndev);
50145052
error_hw_init:
50155053
destroy_workqueue(priv->wq);
50165054

0 commit comments

Comments
 (0)