Skip to content

Commit 2be6967

Browse files
Saeed Mahameeddavem330
authored andcommitted
net/mlx5e: Support ETH_RSS_HASH_XOR
The ConnectX-4 HW implements inverted XOR8. To make it act as XOR we re-order the HW RSS indirection table. Set XOR to be the default RSS hash function and add ethtool API to control it. Signed-off-by: Saeed Mahameed <[email protected]> Signed-off-by: Amir Vadai <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent fda19e8 commit 2be6967

File tree

4 files changed

+79
-13
lines changed

4 files changed

+79
-13
lines changed

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -195,6 +195,7 @@ struct mlx5e_params {
195195
u16 rx_hash_log_tbl_sz;
196196
bool lro_en;
197197
u32 lro_wqe_sz;
198+
u8 rss_hfunc;
198199
};
199200

200201
enum {

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

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -662,6 +662,43 @@ static int mlx5e_set_settings(struct net_device *netdev,
662662
return err;
663663
}
664664

665+
static int mlx5e_get_rxfh(struct net_device *netdev, u32 *indir, u8 *key,
666+
u8 *hfunc)
667+
{
668+
struct mlx5e_priv *priv = netdev_priv(netdev);
669+
670+
if (hfunc)
671+
*hfunc = priv->params.rss_hfunc;
672+
673+
return 0;
674+
}
675+
676+
static int mlx5e_set_rxfh(struct net_device *netdev, const u32 *indir,
677+
const u8 *key, const u8 hfunc)
678+
{
679+
struct mlx5e_priv *priv = netdev_priv(netdev);
680+
int err = 0;
681+
682+
if (hfunc == ETH_RSS_HASH_NO_CHANGE)
683+
return 0;
684+
685+
if ((hfunc != ETH_RSS_HASH_XOR) &&
686+
(hfunc != ETH_RSS_HASH_TOP))
687+
return -EINVAL;
688+
689+
mutex_lock(&priv->state_lock);
690+
691+
priv->params.rss_hfunc = hfunc;
692+
if (test_bit(MLX5E_STATE_OPENED, &priv->state)) {
693+
mlx5e_close_locked(priv->netdev);
694+
err = mlx5e_open_locked(priv->netdev);
695+
}
696+
697+
mutex_unlock(&priv->state_lock);
698+
699+
return err;
700+
}
701+
665702
const struct ethtool_ops mlx5e_ethtool_ops = {
666703
.get_drvinfo = mlx5e_get_drvinfo,
667704
.get_link = ethtool_op_get_link,
@@ -676,4 +713,6 @@ const struct ethtool_ops mlx5e_ethtool_ops = {
676713
.set_coalesce = mlx5e_set_coalesce,
677714
.get_settings = mlx5e_get_settings,
678715
.set_settings = mlx5e_set_settings,
716+
.get_rxfh = mlx5e_get_rxfh,
717+
.set_rxfh = mlx5e_set_rxfh,
679718
};

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

Lines changed: 36 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1158,6 +1158,24 @@ static void mlx5e_close_tises(struct mlx5e_priv *priv)
11581158
mlx5e_close_tis(priv, tc);
11591159
}
11601160

1161+
static int mlx5e_rx_hash_fn(int hfunc)
1162+
{
1163+
return (hfunc == ETH_RSS_HASH_TOP) ?
1164+
MLX5_RX_HASH_FN_TOEPLITZ :
1165+
MLX5_RX_HASH_FN_INVERTED_XOR8;
1166+
}
1167+
1168+
static int mlx5e_bits_invert(unsigned long a, int size)
1169+
{
1170+
int inv = 0;
1171+
int i;
1172+
1173+
for (i = 0; i < size; i++)
1174+
inv |= (test_bit(size - i - 1, &a) ? 1 : 0) << i;
1175+
1176+
return inv;
1177+
}
1178+
11611179
static int mlx5e_open_rqt(struct mlx5e_priv *priv)
11621180
{
11631181
struct mlx5_core_dev *mdev = priv->mdev;
@@ -1166,11 +1184,10 @@ static int mlx5e_open_rqt(struct mlx5e_priv *priv)
11661184
void *rqtc;
11671185
int inlen;
11681186
int err;
1169-
int sz;
1187+
int log_tbl_sz = priv->params.rx_hash_log_tbl_sz;
1188+
int sz = 1 << log_tbl_sz;
11701189
int i;
11711190

1172-
sz = 1 << priv->params.rx_hash_log_tbl_sz;
1173-
11741191
inlen = MLX5_ST_SZ_BYTES(create_rqt_in) + sizeof(u32) * sz;
11751192
in = mlx5_vzalloc(inlen);
11761193
if (!in)
@@ -1182,8 +1199,12 @@ static int mlx5e_open_rqt(struct mlx5e_priv *priv)
11821199
MLX5_SET(rqtc, rqtc, rqt_max_size, sz);
11831200

11841201
for (i = 0; i < sz; i++) {
1185-
int ix = i % priv->params.num_channels;
1202+
int ix = i;
1203+
1204+
if (priv->params.rss_hfunc == ETH_RSS_HASH_XOR)
1205+
ix = mlx5e_bits_invert(i, log_tbl_sz);
11861206

1207+
ix = ix % priv->params.num_channels;
11871208
MLX5_SET(rqtc, rqtc, rq_num[i], priv->channel[ix]->rq.rqn);
11881209
}
11891210

@@ -1254,12 +1275,16 @@ static void mlx5e_build_tir_ctx(struct mlx5e_priv *priv, u32 *tirc, int tt)
12541275
MLX5_SET(tirc, tirc, indirect_table,
12551276
priv->rqtn);
12561277
MLX5_SET(tirc, tirc, rx_hash_fn,
1257-
MLX5_TIRC_RX_HASH_FN_HASH_TOEPLITZ);
1258-
MLX5_SET(tirc, tirc, rx_hash_symmetric, 1);
1259-
netdev_rss_key_fill(MLX5_ADDR_OF(tirc, tirc,
1260-
rx_hash_toeplitz_key),
1261-
MLX5_FLD_SZ_BYTES(tirc,
1262-
rx_hash_toeplitz_key));
1278+
mlx5e_rx_hash_fn(priv->params.rss_hfunc));
1279+
if (priv->params.rss_hfunc == ETH_RSS_HASH_TOP) {
1280+
void *rss_key = MLX5_ADDR_OF(tirc, tirc,
1281+
rx_hash_toeplitz_key);
1282+
size_t len = MLX5_FLD_SZ_BYTES(tirc,
1283+
rx_hash_toeplitz_key);
1284+
1285+
MLX5_SET(tirc, tirc, rx_hash_symmetric, 1);
1286+
netdev_rss_key_fill(rss_key, len);
1287+
}
12631288
break;
12641289
}
12651290

@@ -1700,6 +1725,7 @@ static void mlx5e_build_netdev_priv(struct mlx5_core_dev *mdev,
17001725
MLX5E_PARAMS_DEFAULT_RX_HASH_LOG_TBL_SZ;
17011726
priv->params.num_tc = 1;
17021727
priv->params.default_vlan_prio = 0;
1728+
priv->params.rss_hfunc = ETH_RSS_HASH_XOR;
17031729

17041730
priv->params.lro_en = false && !!MLX5_CAP_ETH(priv->mdev, lro_cap);
17051731
priv->params.lro_wqe_sz =

include/linux/mlx5/mlx5_ifc.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1936,9 +1936,9 @@ enum {
19361936
};
19371937

19381938
enum {
1939-
MLX5_TIRC_RX_HASH_FN_HASH_NONE = 0x0,
1940-
MLX5_TIRC_RX_HASH_FN_HASH_INVERTED_XOR8 = 0x1,
1941-
MLX5_TIRC_RX_HASH_FN_HASH_TOEPLITZ = 0x2,
1939+
MLX5_RX_HASH_FN_NONE = 0x0,
1940+
MLX5_RX_HASH_FN_INVERTED_XOR8 = 0x1,
1941+
MLX5_RX_HASH_FN_TOEPLITZ = 0x2,
19421942
};
19431943

19441944
enum {

0 commit comments

Comments
 (0)