Skip to content

Commit

Permalink
mlxsw: spectrum_router: Add support for custom multipath hash policy
Browse files Browse the repository at this point in the history
When this policy is set, only enable the packet fields that were enabled
by user space for multipath hash computation.

Signed-off-by: Ido Schimmel <[email protected]>
Reviewed-by: Petr Machata <[email protected]>
Signed-off-by: David S. Miller <[email protected]>
  • Loading branch information
idosch authored and davem330 committed May 19, 2021
1 parent 01848e0 commit daeabf8
Showing 1 changed file with 85 additions and 0 deletions.
85 changes: 85 additions & 0 deletions drivers/net/ethernet/mellanox/mlxsw/spectrum_router.c
Original file line number Diff line number Diff line change
Expand Up @@ -9647,12 +9647,53 @@ static void mlxsw_sp_mp4_hash_outer_addr(struct mlxsw_sp_mp_hash_config *config)
MLXSW_SP_MP_HASH_FIELD_RANGE_SET(fields, IPV4_DIP0, 4);
}

static void
mlxsw_sp_mp_hash_inner_custom(struct mlxsw_sp_mp_hash_config *config,
u32 hash_fields)
{
unsigned long *inner_headers = config->inner_headers;
unsigned long *inner_fields = config->inner_fields;

/* IPv4 Inner */
MLXSW_SP_MP_HASH_HEADER_SET(inner_headers, IPV4_EN_NOT_TCP_NOT_UDP);
MLXSW_SP_MP_HASH_HEADER_SET(inner_headers, IPV4_EN_TCP_UDP);
if (hash_fields & FIB_MULTIPATH_HASH_FIELD_INNER_SRC_IP)
MLXSW_SP_MP_HASH_FIELD_RANGE_SET(inner_fields, INNER_IPV4_SIP0, 4);
if (hash_fields & FIB_MULTIPATH_HASH_FIELD_INNER_DST_IP)
MLXSW_SP_MP_HASH_FIELD_RANGE_SET(inner_fields, INNER_IPV4_DIP0, 4);
if (hash_fields & FIB_MULTIPATH_HASH_FIELD_INNER_IP_PROTO)
MLXSW_SP_MP_HASH_FIELD_SET(inner_fields, INNER_IPV4_PROTOCOL);
/* IPv6 inner */
MLXSW_SP_MP_HASH_HEADER_SET(inner_headers, IPV6_EN_NOT_TCP_NOT_UDP);
MLXSW_SP_MP_HASH_HEADER_SET(inner_headers, IPV6_EN_TCP_UDP);
if (hash_fields & FIB_MULTIPATH_HASH_FIELD_INNER_SRC_IP) {
MLXSW_SP_MP_HASH_FIELD_SET(inner_fields, INNER_IPV6_SIP0_7);
MLXSW_SP_MP_HASH_FIELD_RANGE_SET(inner_fields, INNER_IPV6_SIP8, 8);
}
if (hash_fields & FIB_MULTIPATH_HASH_FIELD_INNER_DST_IP) {
MLXSW_SP_MP_HASH_FIELD_SET(inner_fields, INNER_IPV6_DIP0_7);
MLXSW_SP_MP_HASH_FIELD_RANGE_SET(inner_fields, INNER_IPV6_DIP8, 8);
}
if (hash_fields & FIB_MULTIPATH_HASH_FIELD_INNER_IP_PROTO)
MLXSW_SP_MP_HASH_FIELD_SET(inner_fields, INNER_IPV6_NEXT_HEADER);
if (hash_fields & FIB_MULTIPATH_HASH_FIELD_INNER_FLOWLABEL)
MLXSW_SP_MP_HASH_FIELD_SET(inner_fields, INNER_IPV6_FLOW_LABEL);
/* L4 inner */
MLXSW_SP_MP_HASH_HEADER_SET(inner_headers, TCP_UDP_EN_IPV4);
MLXSW_SP_MP_HASH_HEADER_SET(inner_headers, TCP_UDP_EN_IPV6);
if (hash_fields & FIB_MULTIPATH_HASH_FIELD_INNER_SRC_PORT)
MLXSW_SP_MP_HASH_FIELD_SET(inner_fields, INNER_TCP_UDP_SPORT);
if (hash_fields & FIB_MULTIPATH_HASH_FIELD_INNER_DST_PORT)
MLXSW_SP_MP_HASH_FIELD_SET(inner_fields, INNER_TCP_UDP_DPORT);
}

static void mlxsw_sp_mp4_hash_init(struct mlxsw_sp *mlxsw_sp,
struct mlxsw_sp_mp_hash_config *config)
{
struct net *net = mlxsw_sp_net(mlxsw_sp);
unsigned long *headers = config->headers;
unsigned long *fields = config->fields;
u32 hash_fields;

switch (net->ipv4.sysctl_fib_multipath_hash_policy) {
case 0:
Expand All @@ -9671,6 +9712,25 @@ static void mlxsw_sp_mp4_hash_init(struct mlxsw_sp *mlxsw_sp,
/* Inner */
mlxsw_sp_mp_hash_inner_l3(config);
break;
case 3:
hash_fields = net->ipv4.sysctl_fib_multipath_hash_fields;
/* Outer */
MLXSW_SP_MP_HASH_HEADER_SET(headers, IPV4_EN_NOT_TCP_NOT_UDP);
MLXSW_SP_MP_HASH_HEADER_SET(headers, IPV4_EN_TCP_UDP);
MLXSW_SP_MP_HASH_HEADER_SET(headers, TCP_UDP_EN_IPV4);
if (hash_fields & FIB_MULTIPATH_HASH_FIELD_SRC_IP)
MLXSW_SP_MP_HASH_FIELD_RANGE_SET(fields, IPV4_SIP0, 4);
if (hash_fields & FIB_MULTIPATH_HASH_FIELD_DST_IP)
MLXSW_SP_MP_HASH_FIELD_RANGE_SET(fields, IPV4_DIP0, 4);
if (hash_fields & FIB_MULTIPATH_HASH_FIELD_IP_PROTO)
MLXSW_SP_MP_HASH_FIELD_SET(fields, IPV4_PROTOCOL);
if (hash_fields & FIB_MULTIPATH_HASH_FIELD_SRC_PORT)
MLXSW_SP_MP_HASH_FIELD_SET(fields, TCP_UDP_SPORT);
if (hash_fields & FIB_MULTIPATH_HASH_FIELD_DST_PORT)
MLXSW_SP_MP_HASH_FIELD_SET(fields, TCP_UDP_DPORT);
/* Inner */
mlxsw_sp_mp_hash_inner_custom(config, hash_fields);
break;
}
}

Expand All @@ -9690,6 +9750,7 @@ static void mlxsw_sp_mp6_hash_outer_addr(struct mlxsw_sp_mp_hash_config *config)
static void mlxsw_sp_mp6_hash_init(struct mlxsw_sp *mlxsw_sp,
struct mlxsw_sp_mp_hash_config *config)
{
u32 hash_fields = ip6_multipath_hash_fields(mlxsw_sp_net(mlxsw_sp));
unsigned long *headers = config->headers;
unsigned long *fields = config->fields;

Expand All @@ -9714,6 +9775,30 @@ static void mlxsw_sp_mp6_hash_init(struct mlxsw_sp *mlxsw_sp,
/* Inner */
mlxsw_sp_mp_hash_inner_l3(config);
break;
case 3:
/* Outer */
MLXSW_SP_MP_HASH_HEADER_SET(headers, IPV6_EN_NOT_TCP_NOT_UDP);
MLXSW_SP_MP_HASH_HEADER_SET(headers, IPV6_EN_TCP_UDP);
MLXSW_SP_MP_HASH_HEADER_SET(headers, TCP_UDP_EN_IPV6);
if (hash_fields & FIB_MULTIPATH_HASH_FIELD_SRC_IP) {
MLXSW_SP_MP_HASH_FIELD_SET(fields, IPV6_SIP0_7);
MLXSW_SP_MP_HASH_FIELD_RANGE_SET(fields, IPV6_SIP8, 8);
}
if (hash_fields & FIB_MULTIPATH_HASH_FIELD_DST_IP) {
MLXSW_SP_MP_HASH_FIELD_SET(fields, IPV6_DIP0_7);
MLXSW_SP_MP_HASH_FIELD_RANGE_SET(fields, IPV6_DIP8, 8);
}
if (hash_fields & FIB_MULTIPATH_HASH_FIELD_IP_PROTO)
MLXSW_SP_MP_HASH_FIELD_SET(fields, IPV6_NEXT_HEADER);
if (hash_fields & FIB_MULTIPATH_HASH_FIELD_FLOWLABEL)
MLXSW_SP_MP_HASH_FIELD_SET(fields, IPV6_FLOW_LABEL);
if (hash_fields & FIB_MULTIPATH_HASH_FIELD_SRC_PORT)
MLXSW_SP_MP_HASH_FIELD_SET(fields, TCP_UDP_SPORT);
if (hash_fields & FIB_MULTIPATH_HASH_FIELD_DST_PORT)
MLXSW_SP_MP_HASH_FIELD_SET(fields, TCP_UDP_DPORT);
/* Inner */
mlxsw_sp_mp_hash_inner_custom(config, hash_fields);
break;
}
}

Expand Down

0 comments on commit daeabf8

Please sign in to comment.