Skip to content

Commit 0212e5d

Browse files
jdamato-fslydavem330
authored andcommitted
net/mlx5: Fix flowhash key set/get for custom RSS
mlx5 flow hash field retrieval and set only worked on the default RSS context as of commit f01cc58 ("net/mlx5e: Support multiple RSS contexts"), not custom RSS contexts. For example, before this patch attempting to retrieve the flow hash fields for RSS context 1 fails: $ sudo ethtool -u eth1 rx-flow-hash tcp4 context 1 Cannot get RX network flow hashing options: Invalid argument This patch fixes getting and setting the flow hash fields for contexts other than the default context. Getting the flow hash fields for RSS context 1: $ sudo ethtool -u eth1 rx-flow-hash tcp4 context 1 For RSS context 1: TCP over IPV4 flows use these fields for computing Hash flow key: IP DA Now, setting the flash hash fields to a custom value: $ sudo ethtool -U eth1 rx-flow-hash tcp4 sdfn context 1 And retrieving them again: $ sudo ethtool -u eth1 rx-flow-hash tcp4 context 1 For RSS context 1: TCP over IPV4 flows use these fields for computing Hash flow key: IP SA IP DA L4 bytes 0 & 1 [TCP/UDP src port] L4 bytes 2 & 3 [TCP/UDP dst port] Signed-off-by: Joe Damato <jdamato@fastly.com> Reviewed-by: Tariq Toukan <tariqt@nvidia.com> Signed-off-by: David S. Miller <davem@davemloft.net>
1 parent 801b27e commit 0212e5d

File tree

3 files changed

+48
-17
lines changed

3 files changed

+48
-17
lines changed

drivers/net/ethernet/mellanox/mlx5/core/en/rx_res.c

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -218,17 +218,32 @@ int mlx5e_rx_res_rss_set_rxfh(struct mlx5e_rx_res *res, u32 rss_idx,
218218
return mlx5e_rss_set_rxfh(rss, indir, key, hfunc, res->rss_rqns, res->rss_nch);
219219
}
220220

221-
u8 mlx5e_rx_res_rss_get_hash_fields(struct mlx5e_rx_res *res, enum mlx5_traffic_types tt)
221+
int mlx5e_rx_res_rss_get_hash_fields(struct mlx5e_rx_res *res, u32 rss_idx,
222+
enum mlx5_traffic_types tt)
222223
{
223-
struct mlx5e_rss *rss = res->rss[0];
224+
struct mlx5e_rss *rss;
225+
226+
if (rss_idx >= MLX5E_MAX_NUM_RSS)
227+
return -EINVAL;
228+
229+
rss = res->rss[rss_idx];
230+
if (!rss)
231+
return -ENOENT;
224232

225233
return mlx5e_rss_get_hash_fields(rss, tt);
226234
}
227235

228-
int mlx5e_rx_res_rss_set_hash_fields(struct mlx5e_rx_res *res, enum mlx5_traffic_types tt,
229-
u8 rx_hash_fields)
236+
int mlx5e_rx_res_rss_set_hash_fields(struct mlx5e_rx_res *res, u32 rss_idx,
237+
enum mlx5_traffic_types tt, u8 rx_hash_fields)
230238
{
231-
struct mlx5e_rss *rss = res->rss[0];
239+
struct mlx5e_rss *rss;
240+
241+
if (rss_idx >= MLX5E_MAX_NUM_RSS)
242+
return -EINVAL;
243+
244+
rss = res->rss[rss_idx];
245+
if (!rss)
246+
return -ENOENT;
232247

233248
return mlx5e_rss_set_hash_fields(rss, tt, rx_hash_fields);
234249
}

drivers/net/ethernet/mellanox/mlx5/core/en/rx_res.h

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,9 +48,10 @@ int mlx5e_rx_res_rss_get_rxfh(struct mlx5e_rx_res *res, u32 rss_idx,
4848
int mlx5e_rx_res_rss_set_rxfh(struct mlx5e_rx_res *res, u32 rss_idx,
4949
const u32 *indir, const u8 *key, const u8 *hfunc);
5050

51-
u8 mlx5e_rx_res_rss_get_hash_fields(struct mlx5e_rx_res *res, enum mlx5_traffic_types tt);
52-
int mlx5e_rx_res_rss_set_hash_fields(struct mlx5e_rx_res *res, enum mlx5_traffic_types tt,
53-
u8 rx_hash_fields);
51+
int mlx5e_rx_res_rss_get_hash_fields(struct mlx5e_rx_res *res, u32 rss_idx,
52+
enum mlx5_traffic_types tt);
53+
int mlx5e_rx_res_rss_set_hash_fields(struct mlx5e_rx_res *res, u32 rss_idx,
54+
enum mlx5_traffic_types tt, u8 rx_hash_fields);
5455
int mlx5e_rx_res_packet_merge_set_param(struct mlx5e_rx_res *res,
5556
struct mlx5e_packet_merge_param *pkt_merge_param);
5657

drivers/net/ethernet/mellanox/mlx5/core/en_fs_ethtool.c

Lines changed: 24 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -900,21 +900,27 @@ static int mlx5e_set_rss_hash_opt(struct mlx5e_priv *priv,
900900
struct ethtool_rxnfc *nfc)
901901
{
902902
u8 rx_hash_field = 0;
903+
u32 flow_type = 0;
904+
u32 rss_idx = 0;
903905
int err;
904906
int tt;
905907

906-
tt = flow_type_to_traffic_type(nfc->flow_type);
908+
if (nfc->flow_type & FLOW_RSS)
909+
rss_idx = nfc->rss_context;
910+
911+
flow_type = flow_type_mask(nfc->flow_type);
912+
tt = flow_type_to_traffic_type(flow_type);
907913
if (tt < 0)
908914
return tt;
909915

910916
/* RSS does not support anything other than hashing to queues
911917
* on src IP, dest IP, TCP/UDP src port and TCP/UDP dest
912918
* port.
913919
*/
914-
if (nfc->flow_type != TCP_V4_FLOW &&
915-
nfc->flow_type != TCP_V6_FLOW &&
916-
nfc->flow_type != UDP_V4_FLOW &&
917-
nfc->flow_type != UDP_V6_FLOW)
920+
if (flow_type != TCP_V4_FLOW &&
921+
flow_type != TCP_V6_FLOW &&
922+
flow_type != UDP_V4_FLOW &&
923+
flow_type != UDP_V6_FLOW)
918924
return -EOPNOTSUPP;
919925

920926
if (nfc->data & ~(RXH_IP_SRC | RXH_IP_DST |
@@ -931,7 +937,7 @@ static int mlx5e_set_rss_hash_opt(struct mlx5e_priv *priv,
931937
rx_hash_field |= MLX5_HASH_FIELD_SEL_L4_DPORT;
932938

933939
mutex_lock(&priv->state_lock);
934-
err = mlx5e_rx_res_rss_set_hash_fields(priv->rx_res, tt, rx_hash_field);
940+
err = mlx5e_rx_res_rss_set_hash_fields(priv->rx_res, rss_idx, tt, rx_hash_field);
935941
mutex_unlock(&priv->state_lock);
936942

937943
return err;
@@ -940,14 +946,23 @@ static int mlx5e_set_rss_hash_opt(struct mlx5e_priv *priv,
940946
static int mlx5e_get_rss_hash_opt(struct mlx5e_priv *priv,
941947
struct ethtool_rxnfc *nfc)
942948
{
943-
u32 hash_field = 0;
949+
int hash_field = 0;
950+
u32 flow_type = 0;
951+
u32 rss_idx = 0;
944952
int tt;
945953

946-
tt = flow_type_to_traffic_type(nfc->flow_type);
954+
if (nfc->flow_type & FLOW_RSS)
955+
rss_idx = nfc->rss_context;
956+
957+
flow_type = flow_type_mask(nfc->flow_type);
958+
tt = flow_type_to_traffic_type(flow_type);
947959
if (tt < 0)
948960
return tt;
949961

950-
hash_field = mlx5e_rx_res_rss_get_hash_fields(priv->rx_res, tt);
962+
hash_field = mlx5e_rx_res_rss_get_hash_fields(priv->rx_res, rss_idx, tt);
963+
if (hash_field < 0)
964+
return hash_field;
965+
951966
nfc->data = 0;
952967

953968
if (hash_field & MLX5_HASH_FIELD_SEL_SRC_IP)

0 commit comments

Comments
 (0)