Add a common ethtool_flow_type_mask() helper to mask extension bits from an ethtool flow type. Move the helper to include/linux/ethtool.h and convert mlx5e and mlx5i to use it, removing duplicate implementations. Signed-off-by: Shahar Shitrit --- .../ethernet/mellanox/mlx5/core/en_fs_ethtool.c | 17 ++++++----------- .../ethernet/mellanox/mlx5/core/ipoib/ethtool.c | 7 +------ include/linux/ethtool.h | 6 ++++++ 3 files changed, 13 insertions(+), 17 deletions(-) diff --git a/drivers/net/ethernet/mellanox/mlx5/core/en_fs_ethtool.c b/drivers/net/ethernet/mellanox/mlx5/core/en_fs_ethtool.c index aecfba7deeb0..7247f6cbdb32 100644 --- a/drivers/net/ethernet/mellanox/mlx5/core/en_fs_ethtool.c +++ b/drivers/net/ethernet/mellanox/mlx5/core/en_fs_ethtool.c @@ -53,11 +53,6 @@ struct mlx5e_ethtool_steering { static int flow_type_to_traffic_type(u32 flow_type); -static u32 flow_type_mask(u32 flow_type) -{ - return flow_type & ~(FLOW_EXT | FLOW_MAC_EXT | FLOW_RSS); -} - struct mlx5e_ethtool_rule { struct list_head list; struct ethtool_rx_flow_spec flow_spec; @@ -91,7 +86,7 @@ static struct mlx5e_ethtool_table *get_flow_table(struct mlx5e_priv *priv, int table_size; int prio; - switch (flow_type_mask(fs->flow_type)) { + switch (ethtool_flow_type_mask(fs->flow_type)) { case TCP_V4_FLOW: case UDP_V4_FLOW: case TCP_V6_FLOW: @@ -350,7 +345,7 @@ static int set_flow_attrs(u32 *match_c, u32 *match_v, outer_headers); void *outer_headers_v = MLX5_ADDR_OF(fte_match_param, match_v, outer_headers); - u32 flow_type = flow_type_mask(fs->flow_type); + u32 flow_type = ethtool_flow_type_mask(fs->flow_type); switch (flow_type) { case TCP_V4_FLOW: @@ -435,7 +430,7 @@ static int flow_get_tirn(struct mlx5e_priv *priv, if (!rss) return -ENOENT; - flow_type = flow_type_mask(fs->flow_type); + flow_type = ethtool_flow_type_mask(fs->flow_type); tt = flow_type_to_traffic_type(flow_type); if (tt < 0) return -EINVAL; @@ -673,7 +668,7 @@ static int validate_flow(struct mlx5e_priv *priv, if (fs->ring_cookie >= priv->channels.params.num_channels) return -EINVAL; - switch (flow_type_mask(fs->flow_type)) { + switch (ethtool_flow_type_mask(fs->flow_type)) { case ETHER_FLOW: num_tuples += validate_ethter(fs); break; @@ -906,7 +901,7 @@ int mlx5e_ethtool_set_rxfh_fields(struct mlx5e_priv *priv, rss_idx = nfc->rss_context; - flow_type = flow_type_mask(nfc->flow_type); + flow_type = ethtool_flow_type_mask(nfc->flow_type); tt = flow_type_to_traffic_type(flow_type); if (tt < 0) return tt; @@ -951,7 +946,7 @@ int mlx5e_ethtool_get_rxfh_fields(struct mlx5e_priv *priv, rss_idx = nfc->rss_context; - flow_type = flow_type_mask(nfc->flow_type); + flow_type = ethtool_flow_type_mask(nfc->flow_type); tt = flow_type_to_traffic_type(flow_type); if (tt < 0) return tt; diff --git a/drivers/net/ethernet/mellanox/mlx5/core/ipoib/ethtool.c b/drivers/net/ethernet/mellanox/mlx5/core/ipoib/ethtool.c index 01ddc3def9ac..83eaceddc437 100644 --- a/drivers/net/ethernet/mellanox/mlx5/core/ipoib/ethtool.c +++ b/drivers/net/ethernet/mellanox/mlx5/core/ipoib/ethtool.c @@ -233,11 +233,6 @@ static int mlx5i_get_link_ksettings(struct net_device *netdev, return 0; } -static u32 mlx5i_flow_type_mask(u32 flow_type) -{ - return flow_type & ~(FLOW_EXT | FLOW_MAC_EXT | FLOW_RSS); -} - static int mlx5i_set_rxfh_fields(struct net_device *dev, const struct ethtool_rxfh_fields *cmd, struct netlink_ext_ack *extack) @@ -260,7 +255,7 @@ static int mlx5i_set_rxnfc(struct net_device *dev, struct ethtool_rxnfc *cmd) struct mlx5e_priv *priv = mlx5i_epriv(dev); struct ethtool_rx_flow_spec *fs = &cmd->fs; - if (mlx5i_flow_type_mask(fs->flow_type) == ETHER_FLOW) + if (ethtool_flow_type_mask(fs->flow_type) == ETHER_FLOW) return -EINVAL; return mlx5e_ethtool_set_rxnfc(priv, cmd); diff --git a/include/linux/ethtool.h b/include/linux/ethtool.h index 5d491a98265e..c5d814462eed 100644 --- a/include/linux/ethtool.h +++ b/include/linux/ethtool.h @@ -1566,4 +1566,10 @@ struct ethtool_forced_speed_map { void ethtool_forced_speed_maps_init(struct ethtool_forced_speed_map *maps, u32 size); + +static inline u32 ethtool_flow_type_mask(u32 flow_type) +{ + return flow_type & ~(FLOW_EXT | FLOW_MAC_EXT | FLOW_RSS); +} + #endif /* _LINUX_ETHTOOL_H */ -- 2.49.0