Skip to content

Commit ef8e692

Browse files
committed
Merge branch 'net-stmmac-Add-ethtool-support-for-get-set-channels'
Wong Vee Khee says: ==================== net: stmmac: Add ethtool support for get|set channels This patch set is to add support for user to get or set Tx/Rx channel via ethtool. There are two patches that fixes bug introduced on upstream in order to have the feature work. Tested on Intel Tigerlake Platform. ==================== Signed-off-by: David S. Miller <[email protected]>
2 parents 945c570 + 9f19306 commit ef8e692

File tree

3 files changed

+98
-64
lines changed

3 files changed

+98
-64
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: 71 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -176,32 +176,6 @@ static void stmmac_enable_all_queues(struct stmmac_priv *priv)
176176
}
177177
}
178178

179-
/**
180-
* stmmac_stop_all_queues - Stop all queues
181-
* @priv: driver private structure
182-
*/
183-
static void stmmac_stop_all_queues(struct stmmac_priv *priv)
184-
{
185-
u32 tx_queues_cnt = priv->plat->tx_queues_to_use;
186-
u32 queue;
187-
188-
for (queue = 0; queue < tx_queues_cnt; queue++)
189-
netif_tx_stop_queue(netdev_get_tx_queue(priv->dev, queue));
190-
}
191-
192-
/**
193-
* stmmac_start_all_queues - Start all queues
194-
* @priv: driver private structure
195-
*/
196-
static void stmmac_start_all_queues(struct stmmac_priv *priv)
197-
{
198-
u32 tx_queues_cnt = priv->plat->tx_queues_to_use;
199-
u32 queue;
200-
201-
for (queue = 0; queue < tx_queues_cnt; queue++)
202-
netif_tx_start_queue(netdev_get_tx_queue(priv->dev, queue));
203-
}
204-
205179
static void stmmac_service_event_schedule(struct stmmac_priv *priv)
206180
{
207181
if (!test_bit(STMMAC_DOWN, &priv->state) &&
@@ -2732,6 +2706,10 @@ static int stmmac_hw_setup(struct net_device *dev, bool init_ptp)
27322706
stmmac_enable_tbs(priv, priv->ioaddr, enable, chan);
27332707
}
27342708

2709+
/* Configure real RX and TX queues */
2710+
netif_set_real_num_rx_queues(dev, priv->plat->rx_queues_to_use);
2711+
netif_set_real_num_tx_queues(dev, priv->plat->tx_queues_to_use);
2712+
27352713
/* Start the ball rolling... */
27362714
stmmac_start_all_dma(priv);
27372715

@@ -2860,7 +2838,7 @@ static int stmmac_open(struct net_device *dev)
28602838
}
28612839

28622840
stmmac_enable_all_queues(priv);
2863-
stmmac_start_all_queues(priv);
2841+
netif_tx_start_all_queues(priv->dev);
28642842

28652843
return 0;
28662844

@@ -2903,8 +2881,6 @@ static int stmmac_release(struct net_device *dev)
29032881
phylink_stop(priv->phylink);
29042882
phylink_disconnect_phy(priv->phylink);
29052883

2906-
stmmac_stop_all_queues(priv);
2907-
29082884
stmmac_disable_all_queues(priv);
29092885

29102886
for (chan = 0; chan < priv->plat->tx_queues_to_use; chan++)
@@ -4739,6 +4715,69 @@ static int stmmac_hw_init(struct stmmac_priv *priv)
47394715
return 0;
47404716
}
47414717

4718+
static void stmmac_napi_add(struct net_device *dev)
4719+
{
4720+
struct stmmac_priv *priv = netdev_priv(dev);
4721+
u32 queue, maxq;
4722+
4723+
maxq = max(priv->plat->rx_queues_to_use, priv->plat->tx_queues_to_use);
4724+
4725+
for (queue = 0; queue < maxq; queue++) {
4726+
struct stmmac_channel *ch = &priv->channel[queue];
4727+
4728+
ch->priv_data = priv;
4729+
ch->index = queue;
4730+
4731+
if (queue < priv->plat->rx_queues_to_use) {
4732+
netif_napi_add(dev, &ch->rx_napi, stmmac_napi_poll_rx,
4733+
NAPI_POLL_WEIGHT);
4734+
}
4735+
if (queue < priv->plat->tx_queues_to_use) {
4736+
netif_tx_napi_add(dev, &ch->tx_napi,
4737+
stmmac_napi_poll_tx,
4738+
NAPI_POLL_WEIGHT);
4739+
}
4740+
}
4741+
}
4742+
4743+
static void stmmac_napi_del(struct net_device *dev)
4744+
{
4745+
struct stmmac_priv *priv = netdev_priv(dev);
4746+
u32 queue, maxq;
4747+
4748+
maxq = max(priv->plat->rx_queues_to_use, priv->plat->tx_queues_to_use);
4749+
4750+
for (queue = 0; queue < maxq; queue++) {
4751+
struct stmmac_channel *ch = &priv->channel[queue];
4752+
4753+
if (queue < priv->plat->rx_queues_to_use)
4754+
netif_napi_del(&ch->rx_napi);
4755+
if (queue < priv->plat->tx_queues_to_use)
4756+
netif_napi_del(&ch->tx_napi);
4757+
}
4758+
}
4759+
4760+
int stmmac_reinit_queues(struct net_device *dev, u32 rx_cnt, u32 tx_cnt)
4761+
{
4762+
struct stmmac_priv *priv = netdev_priv(dev);
4763+
int ret = 0;
4764+
4765+
if (netif_running(dev))
4766+
stmmac_release(dev);
4767+
4768+
stmmac_napi_del(dev);
4769+
4770+
priv->plat->rx_queues_to_use = rx_cnt;
4771+
priv->plat->tx_queues_to_use = tx_cnt;
4772+
4773+
stmmac_napi_add(dev);
4774+
4775+
if (netif_running(dev))
4776+
ret = stmmac_open(dev);
4777+
4778+
return ret;
4779+
}
4780+
47424781
/**
47434782
* stmmac_dvr_probe
47444783
* @device: device pointer
@@ -4755,7 +4794,7 @@ int stmmac_dvr_probe(struct device *device,
47554794
{
47564795
struct net_device *ndev = NULL;
47574796
struct stmmac_priv *priv;
4758-
u32 queue, rxq, maxq;
4797+
u32 rxq;
47594798
int i, ret = 0;
47604799

47614800
ndev = devm_alloc_etherdev_mqs(device, sizeof(struct stmmac_priv),
@@ -4819,10 +4858,6 @@ int stmmac_dvr_probe(struct device *device,
48194858

48204859
stmmac_check_ether_addr(priv);
48214860

4822-
/* Configure real RX and TX queues */
4823-
netif_set_real_num_rx_queues(ndev, priv->plat->rx_queues_to_use);
4824-
netif_set_real_num_tx_queues(ndev, priv->plat->tx_queues_to_use);
4825-
48264861
ndev->netdev_ops = &stmmac_netdev_ops;
48274862

48284863
ndev->hw_features = NETIF_F_SG | NETIF_F_IP_CSUM | NETIF_F_IPV6_CSUM |
@@ -4920,25 +4955,7 @@ int stmmac_dvr_probe(struct device *device,
49204955
priv->flow_ctrl = FLOW_AUTO; /* RX/TX pause on */
49214956

49224957
/* 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-
}
4958+
stmmac_napi_add(ndev);
49424959

49434960
mutex_init(&priv->lock);
49444961

@@ -5003,14 +5020,7 @@ int stmmac_dvr_probe(struct device *device,
50035020
priv->hw->pcs != STMMAC_PCS_RTBI)
50045021
stmmac_mdio_unregister(ndev);
50055022
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-
}
5023+
stmmac_napi_del(ndev);
50145024
error_hw_init:
50155025
destroy_workqueue(priv->wq);
50165026

@@ -5078,7 +5088,6 @@ int stmmac_suspend(struct device *dev)
50785088
mutex_lock(&priv->lock);
50795089

50805090
netif_device_detach(ndev);
5081-
stmmac_stop_all_queues(priv);
50825091

50835092
stmmac_disable_all_queues(priv);
50845093

@@ -5204,8 +5213,6 @@ int stmmac_resume(struct device *dev)
52045213

52055214
stmmac_enable_all_queues(priv);
52065215

5207-
stmmac_start_all_queues(priv);
5208-
52095216
mutex_unlock(&priv->lock);
52105217

52115218
if (!device_may_wakeup(priv->device) || !priv->plat->pmt) {

0 commit comments

Comments
 (0)