Skip to content

Commit cac018b

Browse files
Moshe ShemeshSaeed Mahameed
authored andcommitted
net/mlx5e: Take SW parser code to a separate function
Refactor mlx5e_ipsec_set_swp() code, split the part which sets the eseg software parser (SWP) offsets and flags, so it can be used in a downstream patch by other mlx5e functionality which needs to set eseg SWP. The new function mlx5e_set_eseg_swp() is useful for setting swp for both outer and inner headers. It also handles the special ipsec case of xfrm mode transfer. Signed-off-by: Moshe Shemesh <[email protected]> Signed-off-by: Saeed Mahameed <[email protected]>
1 parent 974eff2 commit cac018b

File tree

2 files changed

+53
-24
lines changed

2 files changed

+53
-24
lines changed

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

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -884,6 +884,47 @@ static inline bool mlx5e_tunnel_inner_ft_supported(struct mlx5_core_dev *mdev)
884884
MLX5_CAP_FLOWTABLE_NIC_RX(mdev, ft_field_support.inner_ip_version));
885885
}
886886

887+
struct mlx5e_swp_spec {
888+
__be16 l3_proto;
889+
u8 l4_proto;
890+
u8 is_tun;
891+
__be16 tun_l3_proto;
892+
u8 tun_l4_proto;
893+
};
894+
895+
static inline void
896+
mlx5e_set_eseg_swp(struct sk_buff *skb, struct mlx5_wqe_eth_seg *eseg,
897+
struct mlx5e_swp_spec *swp_spec)
898+
{
899+
/* SWP offsets are in 2-bytes words */
900+
eseg->swp_outer_l3_offset = skb_network_offset(skb) / 2;
901+
if (swp_spec->l3_proto == htons(ETH_P_IPV6))
902+
eseg->swp_flags |= MLX5_ETH_WQE_SWP_OUTER_L3_IPV6;
903+
if (swp_spec->l4_proto) {
904+
eseg->swp_outer_l4_offset = skb_transport_offset(skb) / 2;
905+
if (swp_spec->l4_proto == IPPROTO_UDP)
906+
eseg->swp_flags |= MLX5_ETH_WQE_SWP_OUTER_L4_UDP;
907+
}
908+
909+
if (swp_spec->is_tun) {
910+
eseg->swp_inner_l3_offset = skb_inner_network_offset(skb) / 2;
911+
if (swp_spec->tun_l3_proto == htons(ETH_P_IPV6))
912+
eseg->swp_flags |= MLX5_ETH_WQE_SWP_INNER_L3_IPV6;
913+
} else { /* typically for ipsec when xfrm mode != XFRM_MODE_TUNNEL */
914+
eseg->swp_inner_l3_offset = skb_network_offset(skb) / 2;
915+
if (swp_spec->l3_proto == htons(ETH_P_IPV6))
916+
eseg->swp_flags |= MLX5_ETH_WQE_SWP_INNER_L3_IPV6;
917+
}
918+
switch (swp_spec->tun_l4_proto) {
919+
case IPPROTO_UDP:
920+
eseg->swp_flags |= MLX5_ETH_WQE_SWP_INNER_L4_UDP;
921+
/* fall through */
922+
case IPPROTO_TCP:
923+
eseg->swp_inner_l4_offset = skb_inner_transport_offset(skb) / 2;
924+
break;
925+
}
926+
}
927+
887928
static inline void mlx5e_sq_fetch_wqe(struct mlx5e_txqsq *sq,
888929
struct mlx5e_tx_wqe **wqe,
889930
u16 *pi)

drivers/net/ethernet/mellanox/mlx5/core/en_accel/ipsec_rxtx.c

Lines changed: 12 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ static void mlx5e_ipsec_set_swp(struct sk_buff *skb,
136136
struct mlx5_wqe_eth_seg *eseg, u8 mode,
137137
struct xfrm_offload *xo)
138138
{
139-
u8 proto;
139+
struct mlx5e_swp_spec swp_spec = {};
140140

141141
/* Tunnel Mode:
142142
* SWP: OutL3 InL3 InL4
@@ -146,35 +146,23 @@ static void mlx5e_ipsec_set_swp(struct sk_buff *skb,
146146
* SWP: OutL3 InL4
147147
* InL3
148148
* Pkt: MAC IP ESP L4
149-
*
150-
* Offsets are in 2-byte words, counting from start of frame
151149
*/
152-
eseg->swp_outer_l3_offset = skb_network_offset(skb) / 2;
153-
if (skb->protocol == htons(ETH_P_IPV6))
154-
eseg->swp_flags |= MLX5_ETH_WQE_SWP_OUTER_L3_IPV6;
155-
156-
if (mode == XFRM_MODE_TUNNEL) {
157-
eseg->swp_inner_l3_offset = skb_inner_network_offset(skb) / 2;
150+
swp_spec.l3_proto = skb->protocol;
151+
swp_spec.is_tun = mode == XFRM_MODE_TUNNEL;
152+
if (swp_spec.is_tun) {
158153
if (xo->proto == IPPROTO_IPV6) {
159-
eseg->swp_flags |= MLX5_ETH_WQE_SWP_INNER_L3_IPV6;
160-
proto = inner_ipv6_hdr(skb)->nexthdr;
154+
swp_spec.tun_l3_proto = htons(ETH_P_IPV6);
155+
swp_spec.tun_l4_proto = inner_ipv6_hdr(skb)->nexthdr;
161156
} else {
162-
proto = inner_ip_hdr(skb)->protocol;
157+
swp_spec.tun_l3_proto = htons(ETH_P_IP);
158+
swp_spec.tun_l4_proto = inner_ip_hdr(skb)->protocol;
163159
}
164160
} else {
165-
eseg->swp_inner_l3_offset = skb_network_offset(skb) / 2;
166-
if (skb->protocol == htons(ETH_P_IPV6))
167-
eseg->swp_flags |= MLX5_ETH_WQE_SWP_INNER_L3_IPV6;
168-
proto = xo->proto;
169-
}
170-
switch (proto) {
171-
case IPPROTO_UDP:
172-
eseg->swp_flags |= MLX5_ETH_WQE_SWP_INNER_L4_UDP;
173-
/* Fall through */
174-
case IPPROTO_TCP:
175-
eseg->swp_inner_l4_offset = skb_inner_transport_offset(skb) / 2;
176-
break;
161+
swp_spec.tun_l3_proto = skb->protocol;
162+
swp_spec.tun_l4_proto = xo->proto;
177163
}
164+
165+
mlx5e_set_eseg_swp(skb, eseg, &swp_spec);
178166
}
179167

180168
void mlx5e_ipsec_set_iv_esn(struct sk_buff *skb, struct xfrm_state *x,

0 commit comments

Comments
 (0)