Skip to content

Commit 3179a56

Browse files
idoschdavem330
authored andcommitted
mlxsw: spectrum_nve: Breakout common code to a common function
The configuration of a VXLAN tunnel in Spectrum-1 and Spectrum-2 is largely the same. To avoid code duplication, breakout the common parts to a common function that can be invoked from the ASIC-specific code. Signed-off-by: Ido Schimmel <[email protected]> Reviewed-by: Petr Machata <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent eff42aa commit 3179a56

File tree

1 file changed

+19
-11
lines changed

1 file changed

+19
-11
lines changed

drivers/net/ethernet/mellanox/mlxsw/spectrum_nve_vxlan.c

Lines changed: 19 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -112,32 +112,40 @@ static int mlxsw_sp_nve_parsing_set(struct mlxsw_sp *mlxsw_sp,
112112
return mlxsw_reg_write(mlxsw_sp->core, MLXSW_REG(mprs), mprs_pl);
113113
}
114114

115+
static void
116+
mlxsw_sp_nve_vxlan_config_prepare(char *tngcr_pl,
117+
const struct mlxsw_sp_nve_config *config)
118+
{
119+
u8 udp_sport;
120+
121+
mlxsw_reg_tngcr_pack(tngcr_pl, MLXSW_REG_TNGCR_TYPE_VXLAN, true,
122+
config->ttl);
123+
/* VxLAN driver's default UDP source port range is 32768 (0x8000)
124+
* to 60999 (0xee47). Set the upper 8 bits of the UDP source port
125+
* to a random number between 0x80 and 0xee
126+
*/
127+
get_random_bytes(&udp_sport, sizeof(udp_sport));
128+
udp_sport = (udp_sport % (0xee - 0x80 + 1)) + 0x80;
129+
mlxsw_reg_tngcr_nve_udp_sport_prefix_set(tngcr_pl, udp_sport);
130+
mlxsw_reg_tngcr_usipv4_set(tngcr_pl, be32_to_cpu(config->ul_sip.addr4));
131+
}
132+
115133
static int
116134
mlxsw_sp1_nve_vxlan_config_set(struct mlxsw_sp *mlxsw_sp,
117135
const struct mlxsw_sp_nve_config *config)
118136
{
119137
char tngcr_pl[MLXSW_REG_TNGCR_LEN];
120138
u16 ul_vr_id;
121-
u8 udp_sport;
122139
int err;
123140

124141
err = mlxsw_sp_router_tb_id_vr_id(mlxsw_sp, config->ul_tb_id,
125142
&ul_vr_id);
126143
if (err)
127144
return err;
128145

129-
mlxsw_reg_tngcr_pack(tngcr_pl, MLXSW_REG_TNGCR_TYPE_VXLAN, true,
130-
config->ttl);
131-
/* VxLAN driver's default UDP source port range is 32768 (0x8000)
132-
* to 60999 (0xee47). Set the upper 8 bits of the UDP source port
133-
* to a random number between 0x80 and 0xee
134-
*/
135-
get_random_bytes(&udp_sport, sizeof(udp_sport));
136-
udp_sport = (udp_sport % (0xee - 0x80 + 1)) + 0x80;
137-
mlxsw_reg_tngcr_nve_udp_sport_prefix_set(tngcr_pl, udp_sport);
146+
mlxsw_sp_nve_vxlan_config_prepare(tngcr_pl, config);
138147
mlxsw_reg_tngcr_learn_enable_set(tngcr_pl, config->learning_en);
139148
mlxsw_reg_tngcr_underlay_virtual_router_set(tngcr_pl, ul_vr_id);
140-
mlxsw_reg_tngcr_usipv4_set(tngcr_pl, be32_to_cpu(config->ul_sip.addr4));
141149

142150
return mlxsw_reg_write(mlxsw_sp->core, MLXSW_REG(tngcr), tngcr_pl);
143151
}

0 commit comments

Comments
 (0)