Skip to content

Commit

Permalink
net: ethtool: get rid of get/set_rxfh_context functions
Browse files Browse the repository at this point in the history
Add the RSS context parameters to struct ethtool_rxfh_param and use the
get/set_rxfh to handle the RSS contexts as well.

This is part 2/2 of the fix suggested in [1]:

 - Add a rss_context member to the argument struct and a capability
   like cap_link_lanes_supported to indicate whether driver supports
   rss contexts, then you can remove *et_rxfh_context functions,
   and instead call *et_rxfh() with a non-zero rss_context.

Link: https://lore.kernel.org/netdev/20231121152906.2dd5f487@kernel.org/ [1]
CC: Jesse Brandeburg <jesse.brandeburg@intel.com>
CC: Tony Nguyen <anthony.l.nguyen@intel.com>
CC: Marcin Wojtas <mw@semihalf.com>
CC: Russell King <linux@armlinux.org.uk>
CC: Sunil Goutham <sgoutham@marvell.com>
CC: Geetha sowjanya <gakula@marvell.com>
CC: Subbaraya Sundeep <sbhatta@marvell.com>
CC: hariprasad <hkelam@marvell.com>
CC: Saeed Mahameed <saeedm@nvidia.com>
CC: Leon Romanovsky <leon@kernel.org>
CC: Edward Cree <ecree.xilinx@gmail.com>
CC: Martin Habets <habetsm.xilinx@gmail.com>
Suggested-by: Jakub Kicinski <kuba@kernel.org>
Signed-off-by: Ahmed Zaki <ahmed.zaki@intel.com>
Link: https://lore.kernel.org/r/20231213003321.605376-3-ahmed.zaki@intel.com
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
  • Loading branch information
Ahmed Zaki authored and Jakub Kicinski committed Dec 14, 2023
1 parent fb6e30a commit dcd8dbf
Show file tree
Hide file tree
Showing 14 changed files with 205 additions and 300 deletions.
29 changes: 13 additions & 16 deletions drivers/net/ethernet/intel/ice/ice_ethtool.c
Original file line number Diff line number Diff line change
Expand Up @@ -3195,11 +3195,18 @@ static u32 ice_get_rxfh_indir_size(struct net_device *netdev)
return np->vsi->rss_table_size;
}

/**
* ice_get_rxfh - get the Rx flow hash indirection table
* @netdev: network interface device structure
* @rxfh: pointer to param struct (indir, key, hfunc)
*
* Reads the indirection table directly from the hardware.
*/
static int
ice_get_rxfh_context(struct net_device *netdev,
struct ethtool_rxfh_param *rxfh, u32 rss_context)
ice_get_rxfh(struct net_device *netdev, struct ethtool_rxfh_param *rxfh)
{
struct ice_netdev_priv *np = netdev_priv(netdev);
u32 rss_context = rxfh->rss_context;
struct ice_vsi *vsi = np->vsi;
struct ice_pf *pf = vsi->back;
u16 qcount, offset;
Expand Down Expand Up @@ -3261,19 +3268,6 @@ ice_get_rxfh_context(struct net_device *netdev,
return err;
}

/**
* ice_get_rxfh - get the Rx flow hash indirection table
* @netdev: network interface device structure
* @rxfh: pointer to param struct (indir, key, hfunc)
*
* Reads the indirection table directly from the hardware.
*/
static int
ice_get_rxfh(struct net_device *netdev, struct ethtool_rxfh_param *rxfh)
{
return ice_get_rxfh_context(netdev, rxfh, 0);
}

/**
* ice_set_rxfh - set the Rx flow hash indirection table
* @netdev: network interface device structure
Expand All @@ -3298,6 +3292,9 @@ ice_set_rxfh(struct net_device *netdev, struct ethtool_rxfh_param *rxfh,
rxfh->hfunc != ETH_RSS_HASH_TOP)
return -EOPNOTSUPP;

if (rxfh->rss_context)
return -EOPNOTSUPP;

if (!test_bit(ICE_FLAG_RSS_ENA, pf->flags)) {
/* RSS not supported return error here */
netdev_warn(netdev, "RSS is not configured on this VSI!\n");
Expand Down Expand Up @@ -4215,6 +4212,7 @@ ice_get_module_eeprom(struct net_device *netdev,
}

static const struct ethtool_ops ice_ethtool_ops = {
.cap_rss_ctx_supported = true,
.supported_coalesce_params = ETHTOOL_COALESCE_USECS |
ETHTOOL_COALESCE_USE_ADAPTIVE |
ETHTOOL_COALESCE_RX_USECS_HIGH,
Expand Down Expand Up @@ -4248,7 +4246,6 @@ static const struct ethtool_ops ice_ethtool_ops = {
.set_pauseparam = ice_set_pauseparam,
.get_rxfh_key_size = ice_get_rxfh_key_size,
.get_rxfh_indir_size = ice_get_rxfh_indir_size,
.get_rxfh_context = ice_get_rxfh_context,
.get_rxfh = ice_get_rxfh,
.set_rxfh = ice_set_rxfh,
.get_channels = ice_get_channels,
Expand Down
63 changes: 14 additions & 49 deletions drivers/net/ethernet/marvell/mvpp2/mvpp2_main.c
Original file line number Diff line number Diff line change
Expand Up @@ -5638,47 +5638,7 @@ static int mvpp2_ethtool_get_rxfh(struct net_device *dev,
struct ethtool_rxfh_param *rxfh)
{
struct mvpp2_port *port = netdev_priv(dev);
int ret = 0;

if (!mvpp22_rss_is_supported(port))
return -EOPNOTSUPP;

if (rxfh->indir)
ret = mvpp22_port_rss_ctx_indir_get(port, 0, rxfh->indir);

rxfh->hfunc = ETH_RSS_HASH_CRC32;

return ret;
}

static int mvpp2_ethtool_set_rxfh(struct net_device *dev,
struct ethtool_rxfh_param *rxfh,
struct netlink_ext_ack *extack)
{
struct mvpp2_port *port = netdev_priv(dev);
int ret = 0;

if (!mvpp22_rss_is_supported(port))
return -EOPNOTSUPP;

if (rxfh->hfunc != ETH_RSS_HASH_NO_CHANGE &&
rxfh->hfunc != ETH_RSS_HASH_CRC32)
return -EOPNOTSUPP;

if (rxfh->key)
return -EOPNOTSUPP;

if (rxfh->indir)
ret = mvpp22_port_rss_ctx_indir_set(port, 0, rxfh->indir);

return ret;
}

static int mvpp2_ethtool_get_rxfh_context(struct net_device *dev,
struct ethtool_rxfh_param *rxfh,
u32 rss_context)
{
struct mvpp2_port *port = netdev_priv(dev);
u32 rss_context = rxfh->rss_context;
int ret = 0;

if (!mvpp22_rss_is_supported(port))
Expand All @@ -5695,12 +5655,13 @@ static int mvpp2_ethtool_get_rxfh_context(struct net_device *dev,
return ret;
}

static int mvpp2_ethtool_set_rxfh_context(struct net_device *dev,
struct ethtool_rxfh_param *rxfh,
u32 *rss_context, bool delete)
static int mvpp2_ethtool_set_rxfh(struct net_device *dev,
struct ethtool_rxfh_param *rxfh,
struct netlink_ext_ack *extack)
{
struct mvpp2_port *port = netdev_priv(dev);
int ret;
u32 *rss_context = &rxfh->rss_context;
int ret = 0;

if (!mvpp22_rss_is_supported(port))
return -EOPNOTSUPP;
Expand All @@ -5712,7 +5673,7 @@ static int mvpp2_ethtool_set_rxfh_context(struct net_device *dev,
if (rxfh->key)
return -EOPNOTSUPP;

if (delete)
if (*rss_context && rxfh->rss_delete)
return mvpp22_port_rss_ctx_delete(port, *rss_context);

if (*rss_context == ETH_RXFH_CONTEXT_ALLOC) {
Expand All @@ -5721,8 +5682,13 @@ static int mvpp2_ethtool_set_rxfh_context(struct net_device *dev,
return ret;
}

return mvpp22_port_rss_ctx_indir_set(port, *rss_context, rxfh->indir);
if (rxfh->indir)
ret = mvpp22_port_rss_ctx_indir_set(port, *rss_context,
rxfh->indir);

return ret;
}

/* Device ops */

static const struct net_device_ops mvpp2_netdev_ops = {
Expand All @@ -5742,6 +5708,7 @@ static const struct net_device_ops mvpp2_netdev_ops = {
};

static const struct ethtool_ops mvpp2_eth_tool_ops = {
.cap_rss_ctx_supported = true,
.supported_coalesce_params = ETHTOOL_COALESCE_USECS |
ETHTOOL_COALESCE_MAX_FRAMES,
.nway_reset = mvpp2_ethtool_nway_reset,
Expand All @@ -5764,8 +5731,6 @@ static const struct ethtool_ops mvpp2_eth_tool_ops = {
.get_rxfh_indir_size = mvpp2_ethtool_get_rxfh_indir_size,
.get_rxfh = mvpp2_ethtool_get_rxfh,
.set_rxfh = mvpp2_ethtool_set_rxfh,
.get_rxfh_context = mvpp2_ethtool_get_rxfh_context,
.set_rxfh_context = mvpp2_ethtool_set_rxfh_context,
};

/* Used for PPv2.1, or PPv2.2 with the old Device Tree binding that
Expand Down
63 changes: 25 additions & 38 deletions drivers/net/ethernet/marvell/octeontx2/nic/otx2_ethtool.c
Original file line number Diff line number Diff line change
Expand Up @@ -835,11 +835,12 @@ static int otx2_rss_ctx_create(struct otx2_nic *pfvf,
return 0;
}

/* RSS context configuration */
static int otx2_set_rxfh_context(struct net_device *dev,
struct ethtool_rxfh_param *rxfh,
u32 *rss_context, bool delete)
/* Configure RSS table and hash key */
static int otx2_set_rxfh(struct net_device *dev,
struct ethtool_rxfh_param *rxfh,
struct netlink_ext_ack *extack)
{
u32 rss_context = DEFAULT_RSS_CONTEXT_GROUP;
struct otx2_nic *pfvf = netdev_priv(dev);
struct otx2_rss_ctx *rss_ctx;
struct otx2_rss_info *rss;
Expand All @@ -849,8 +850,11 @@ static int otx2_set_rxfh_context(struct net_device *dev,
rxfh->hfunc != ETH_RSS_HASH_TOP)
return -EOPNOTSUPP;

if (*rss_context != ETH_RXFH_CONTEXT_ALLOC &&
*rss_context >= MAX_RSS_GROUPS)
if (rxfh->rss_context)
rss_context = rxfh->rss_context;

if (rss_context != ETH_RXFH_CONTEXT_ALLOC &&
rss_context >= MAX_RSS_GROUPS)
return -EINVAL;

rss = &pfvf->hw.rss_info;
Expand All @@ -864,28 +868,30 @@ static int otx2_set_rxfh_context(struct net_device *dev,
memcpy(rss->key, rxfh->key, sizeof(rss->key));
otx2_set_rss_key(pfvf);
}
if (delete)
return otx2_rss_ctx_delete(pfvf, *rss_context);
if (rxfh->rss_delete)
return otx2_rss_ctx_delete(pfvf, rss_context);

if (*rss_context == ETH_RXFH_CONTEXT_ALLOC) {
ret = otx2_rss_ctx_create(pfvf, rss_context);
if (rss_context == ETH_RXFH_CONTEXT_ALLOC) {
ret = otx2_rss_ctx_create(pfvf, &rss_context);
rxfh->rss_context = rss_context;
if (ret)
return ret;
}
if (rxfh->indir) {
rss_ctx = rss->rss_ctx[*rss_context];
rss_ctx = rss->rss_ctx[rss_context];
for (idx = 0; idx < rss->rss_size; idx++)
rss_ctx->ind_tbl[idx] = rxfh->indir[idx];
}
otx2_set_rss_table(pfvf, *rss_context);
otx2_set_rss_table(pfvf, rss_context);

return 0;
}

static int otx2_get_rxfh_context(struct net_device *dev,
struct ethtool_rxfh_param *rxfh,
u32 rss_context)
/* Get RSS configuration */
static int otx2_get_rxfh(struct net_device *dev,
struct ethtool_rxfh_param *rxfh)
{
u32 rss_context = DEFAULT_RSS_CONTEXT_GROUP;
struct otx2_nic *pfvf = netdev_priv(dev);
struct otx2_rss_ctx *rss_ctx;
struct otx2_rss_info *rss;
Expand All @@ -895,6 +901,8 @@ static int otx2_get_rxfh_context(struct net_device *dev,
rss = &pfvf->hw.rss_info;

rxfh->hfunc = ETH_RSS_HASH_TOP;
if (rxfh->rss_context)
rss_context = rxfh->rss_context;

if (!indir)
return 0;
Expand Down Expand Up @@ -922,25 +930,6 @@ static int otx2_get_rxfh_context(struct net_device *dev,
return 0;
}

/* Get RSS configuration */
static int otx2_get_rxfh(struct net_device *dev,
struct ethtool_rxfh_param *rxfh)
{
return otx2_get_rxfh_context(dev, rxfh,
DEFAULT_RSS_CONTEXT_GROUP);
}

/* Configure RSS table and hash key */
static int otx2_set_rxfh(struct net_device *dev,
struct ethtool_rxfh_param *rxfh,
struct netlink_ext_ack *extack)
{

u32 rss_context = DEFAULT_RSS_CONTEXT_GROUP;

return otx2_set_rxfh_context(dev, rxfh, &rss_context, 0);
}

static u32 otx2_get_msglevel(struct net_device *netdev)
{
struct otx2_nic *pfvf = netdev_priv(netdev);
Expand Down Expand Up @@ -1321,6 +1310,7 @@ static void otx2_get_fec_stats(struct net_device *netdev,
}

static const struct ethtool_ops otx2_ethtool_ops = {
.cap_rss_ctx_supported = true,
.supported_coalesce_params = ETHTOOL_COALESCE_USECS |
ETHTOOL_COALESCE_MAX_FRAMES |
ETHTOOL_COALESCE_USE_ADAPTIVE,
Expand All @@ -1343,8 +1333,6 @@ static const struct ethtool_ops otx2_ethtool_ops = {
.get_rxfh_indir_size = otx2_get_rxfh_indir_size,
.get_rxfh = otx2_get_rxfh,
.set_rxfh = otx2_set_rxfh,
.get_rxfh_context = otx2_get_rxfh_context,
.set_rxfh_context = otx2_set_rxfh_context,
.get_msglevel = otx2_get_msglevel,
.set_msglevel = otx2_set_msglevel,
.get_pauseparam = otx2_get_pauseparam,
Expand Down Expand Up @@ -1444,6 +1432,7 @@ static int otx2vf_get_link_ksettings(struct net_device *netdev,
}

static const struct ethtool_ops otx2vf_ethtool_ops = {
.cap_rss_ctx_supported = true,
.supported_coalesce_params = ETHTOOL_COALESCE_USECS |
ETHTOOL_COALESCE_MAX_FRAMES |
ETHTOOL_COALESCE_USE_ADAPTIVE,
Expand All @@ -1462,8 +1451,6 @@ static const struct ethtool_ops otx2vf_ethtool_ops = {
.get_rxfh_indir_size = otx2_get_rxfh_indir_size,
.get_rxfh = otx2_get_rxfh,
.set_rxfh = otx2_set_rxfh,
.get_rxfh_context = otx2_get_rxfh_context,
.set_rxfh_context = otx2_set_rxfh_context,
.get_ringparam = otx2_get_ringparam,
.set_ringparam = otx2_set_ringparam,
.get_coalesce = otx2_get_coalesce,
Expand Down
37 changes: 8 additions & 29 deletions drivers/net/ethernet/mellanox/mlx5/core/en_ethtool.c
Original file line number Diff line number Diff line change
Expand Up @@ -1262,11 +1262,10 @@ static u32 mlx5e_get_rxfh_indir_size(struct net_device *netdev)
return mlx5e_ethtool_get_rxfh_indir_size(priv);
}

static int mlx5e_get_rxfh_context(struct net_device *dev,
struct ethtool_rxfh_param *rxfh,
u32 rss_context)
int mlx5e_get_rxfh(struct net_device *netdev, struct ethtool_rxfh_param *rxfh)
{
struct mlx5e_priv *priv = netdev_priv(dev);
struct mlx5e_priv *priv = netdev_priv(netdev);
u32 rss_context = rxfh->rss_context;
int err;

mutex_lock(&priv->state_lock);
Expand All @@ -1276,16 +1275,16 @@ static int mlx5e_get_rxfh_context(struct net_device *dev,
return err;
}

static int mlx5e_set_rxfh_context(struct net_device *dev,
struct ethtool_rxfh_param *rxfh,
u32 *rss_context, bool delete)
int mlx5e_set_rxfh(struct net_device *dev, struct ethtool_rxfh_param *rxfh,
struct netlink_ext_ack *extack)
{
struct mlx5e_priv *priv = netdev_priv(dev);
u32 *rss_context = &rxfh->rss_context;
u8 hfunc = rxfh->hfunc;
int err;

mutex_lock(&priv->state_lock);
if (delete) {
if (*rss_context && rxfh->rss_delete) {
err = mlx5e_rx_res_rss_destroy(priv->rx_res, *rss_context);
goto unlock;
}
Expand All @@ -1307,25 +1306,6 @@ static int mlx5e_set_rxfh_context(struct net_device *dev,
return err;
}

int mlx5e_get_rxfh(struct net_device *netdev, struct ethtool_rxfh_param *rxfh)
{
return mlx5e_get_rxfh_context(netdev, rxfh, 0);
}

int mlx5e_set_rxfh(struct net_device *dev, struct ethtool_rxfh_param *rxfh,
struct netlink_ext_ack *extack)
{
struct mlx5e_priv *priv = netdev_priv(dev);
u8 hfunc = rxfh->hfunc;
int err;

mutex_lock(&priv->state_lock);
err = mlx5e_rx_res_rss_set_rxfh(priv->rx_res, 0, rxfh->indir, rxfh->key,
hfunc == ETH_RSS_HASH_NO_CHANGE ? NULL : &hfunc);
mutex_unlock(&priv->state_lock);
return err;
}

#define MLX5E_PFC_PREVEN_AUTO_TOUT_MSEC 100
#define MLX5E_PFC_PREVEN_TOUT_MAX_MSEC 8000
#define MLX5E_PFC_PREVEN_MINOR_PRECENT 85
Expand Down Expand Up @@ -2402,6 +2382,7 @@ static void mlx5e_get_rmon_stats(struct net_device *netdev,
}

const struct ethtool_ops mlx5e_ethtool_ops = {
.cap_rss_ctx_supported = true,
.supported_coalesce_params = ETHTOOL_COALESCE_USECS |
ETHTOOL_COALESCE_MAX_FRAMES |
ETHTOOL_COALESCE_USE_ADAPTIVE |
Expand All @@ -2424,8 +2405,6 @@ const struct ethtool_ops mlx5e_ethtool_ops = {
.get_rxfh_indir_size = mlx5e_get_rxfh_indir_size,
.get_rxfh = mlx5e_get_rxfh,
.set_rxfh = mlx5e_set_rxfh,
.get_rxfh_context = mlx5e_get_rxfh_context,
.set_rxfh_context = mlx5e_set_rxfh_context,
.get_rxnfc = mlx5e_get_rxnfc,
.set_rxnfc = mlx5e_set_rxnfc,
.get_tunable = mlx5e_get_tunable,
Expand Down
Loading

0 comments on commit dcd8dbf

Please sign in to comment.