Commit daeabf89 authored by Ido Schimmel's avatar Ido Schimmel Committed by David S. Miller

mlxsw: spectrum_router: Add support for custom multipath hash policy

When this policy is set, only enable the packet fields that were enabled
by user space for multipath hash computation.
Signed-off-by: default avatarIdo Schimmel <idosch@nvidia.com>
Reviewed-by: default avatarPetr Machata <petrm@nvidia.com>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent 01848e05
......@@ -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:
......@@ -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;
}
}
......@@ -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;
......@@ -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;
}
}
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment