Skip to content

Commit 278bc42

Browse files
Ben Hutchingsdavem330
authored andcommitted
ethtool: Define and apply a default policy for RX flow hash indirection
All drivers that support modification of the RX flow hash indirection table initialise it in the same way: RX rings are assigned to table entries in rotation. Make that default policy explicit by having them call a ethtool_rxfh_indir_default() function. In the ethtool core, add support for a zero size value for ETHTOOL_SRXFHINDIR, which resets the table to this default. Partly-suggested-by: Matt Carlson <mcarlson@broadcom.com> Signed-off-by: Ben Hutchings <bhutchings@solarflare.com> Acked-by: Shreyas N Bhatewara <sbhatewara@vmware.com> Signed-off-by: David S. Miller <davem@davemloft.net>
1 parent 7850f63 commit 278bc42

6 files changed

Lines changed: 47 additions & 20 deletions

File tree

‎drivers/net/ethernet/broadcom/bnx2x/bnx2x_cmn.c‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1545,7 +1545,8 @@ static inline int bnx2x_init_rss_pf(struct bnx2x *bp)
15451545
if (bp->multi_mode != ETH_RSS_MODE_DISABLED) {
15461546
for (i = 0; i < sizeof(ind_table); i++)
15471547
ind_table[i] =
1548-
bp->fp->cl_id + (i % num_eth_queues);
1548+
bp->fp->cl_id +
1549+
ethtool_rxfh_indir_default(i, num_eth_queues);
15491550
}
15501551

15511552
/*

‎drivers/net/ethernet/chelsio/cxgb4/cxgb4_main.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3449,7 +3449,7 @@ static int __devinit init_rss(struct adapter *adap)
34493449
if (!pi->rss)
34503450
return -ENOMEM;
34513451
for (j = 0; j < pi->rss_size; j++)
3452-
pi->rss[j] = j % pi->nqsets;
3452+
pi->rss[j] = ethtool_rxfh_indir_default(j, pi->nqsets);
34533453
}
34543454
return 0;
34553455
}

‎drivers/net/ethernet/sfc/efx.c‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1336,7 +1336,8 @@ static int efx_probe_nic(struct efx_nic *efx)
13361336
if (efx->n_channels > 1)
13371337
get_random_bytes(&efx->rx_hash_key, sizeof(efx->rx_hash_key));
13381338
for (i = 0; i < ARRAY_SIZE(efx->rx_indir_table); i++)
1339-
efx->rx_indir_table[i] = i % efx->n_rx_channels;
1339+
efx->rx_indir_table[i] =
1340+
ethtool_rxfh_indir_default(i, efx->n_rx_channels);
13401341

13411342
efx_set_channels(efx);
13421343
netif_set_real_num_tx_queues(efx->net_dev, efx->n_tx_channels);

‎drivers/net/vmxnet3/vmxnet3_drv.c‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2167,7 +2167,8 @@ vmxnet3_setup_driver_shared(struct vmxnet3_adapter *adapter)
21672167
rssConf->indTableSize = VMXNET3_RSS_IND_TABLE_SIZE;
21682168
get_random_bytes(&rssConf->hashKey[0], rssConf->hashKeySize);
21692169
for (i = 0; i < rssConf->indTableSize; i++)
2170-
rssConf->indTable[i] = i % adapter->num_rx_queues;
2170+
rssConf->indTable[i] = ethtool_rxfh_indir_default(
2171+
i, adapter->num_rx_queues);
21712172

21722173
devRead->rssConfDesc.confVer = 1;
21732174
devRead->rssConfDesc.confLen = sizeof(*rssConf);

‎include/linux/ethtool.h‎

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -543,10 +543,15 @@ struct compat_ethtool_rxnfc {
543543
/**
544544
* struct ethtool_rxfh_indir - command to get or set RX flow hash indirection
545545
* @cmd: Specific command number - %ETHTOOL_GRXFHINDIR or %ETHTOOL_SRXFHINDIR
546-
* @size: On entry, the array size of the user buffer, which may be zero
547-
* for %ETHTOOL_GRXFHINDIR. On return from %ETHTOOL_GRXFHINDIR, the
548-
* array size of the hardware indirection table.
546+
* @size: On entry, the array size of the user buffer, which may be zero.
547+
* On return from %ETHTOOL_GRXFHINDIR, the array size of the hardware
548+
* indirection table.
549549
* @ring_index: RX ring/queue index for each hash value
550+
*
551+
* For %ETHTOOL_GRXFHINDIR, a @size of zero means that only the size
552+
* should be returned. For %ETHTOOL_SRXFHINDIR, a @size of zero means
553+
* the table should be reset to default values. This last feature
554+
* is not supported by the original implementations.
550555
*/
551556
struct ethtool_rxfh_indir {
552557
__u32 cmd;
@@ -749,6 +754,18 @@ struct net_device;
749754
/* Some generic methods drivers may use in their ethtool_ops */
750755
u32 ethtool_op_get_link(struct net_device *dev);
751756

757+
/**
758+
* ethtool_rxfh_indir_default - get default value for RX flow hash indirection
759+
* @index: Index in RX flow hash indirection table
760+
* @n_rx_rings: Number of RX rings to use
761+
*
762+
* This function provides the default policy for RX flow hash indirection.
763+
*/
764+
static inline u32 ethtool_rxfh_indir_default(u32 index, u32 n_rx_rings)
765+
{
766+
return index % n_rx_rings;
767+
}
768+
752769
/**
753770
* struct ethtool_ops - optional netdev operations
754771
* @get_settings: Get various device settings including Ethernet link

‎net/core/ethtool.c‎

Lines changed: 20 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -581,31 +581,38 @@ static noinline_for_stack int ethtool_set_rxfh_indir(struct net_device *dev,
581581
sizeof(user_size)))
582582
return -EFAULT;
583583

584-
if (user_size != dev_size)
584+
if (user_size != 0 && user_size != dev_size)
585585
return -EINVAL;
586586

587587
indir = kcalloc(dev_size, sizeof(indir[0]), GFP_USER);
588588
if (!indir)
589589
return -ENOMEM;
590590

591-
if (copy_from_user(indir,
592-
useraddr +
593-
offsetof(struct ethtool_rxfh_indir, ring_index[0]),
594-
dev_size * sizeof(indir[0]))) {
595-
ret = -EFAULT;
596-
goto out;
597-
}
598-
599-
/* Validate ring indices */
600591
rx_rings.cmd = ETHTOOL_GRXRINGS;
601592
ret = dev->ethtool_ops->get_rxnfc(dev, &rx_rings, NULL);
602593
if (ret)
603594
goto out;
604-
for (i = 0; i < dev_size; i++) {
605-
if (indir[i] >= rx_rings.data) {
606-
ret = -EINVAL;
595+
596+
if (user_size == 0) {
597+
for (i = 0; i < dev_size; i++)
598+
indir[i] = ethtool_rxfh_indir_default(i, rx_rings.data);
599+
} else {
600+
if (copy_from_user(indir,
601+
useraddr +
602+
offsetof(struct ethtool_rxfh_indir,
603+
ring_index[0]),
604+
dev_size * sizeof(indir[0]))) {
605+
ret = -EFAULT;
607606
goto out;
608607
}
608+
609+
/* Validate ring indices */
610+
for (i = 0; i < dev_size; i++) {
611+
if (indir[i] >= rx_rings.data) {
612+
ret = -EINVAL;
613+
goto out;
614+
}
615+
}
609616
}
610617

611618
ret = dev->ethtool_ops->set_rxfh_indir(dev, indir);

0 commit comments

Comments
 (0)