Skip to content

Commit 3e04419

Browse files
wanghuanhuan12davem330
authored andcommitted
nfp: fix incorrectly set csum flag for nfd3 path
The csum flag of IPsec packet are set repeatedly. Therefore, the csum flag set of IPsec and non-IPsec packet need to be distinguished. As the ipv6 header does not have a csum field, so l3-csum flag is not required to be set for ipv6 case. L4-csum flag include the tcp csum flag and udp csum flag, we shouldn't set the udp and tcp csum flag at the same time for one packet, should set l4-csum flag according to the transport layer is tcp or udp. Fixes: 57f273a ("nfp: add framework to support ipsec offloading") Signed-off-by: Huanhuan Wang <[email protected]> Reviewed-by: Louis Peens <[email protected]> Signed-off-by: Simon Horman <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent 84cba18 commit 3e04419

File tree

2 files changed

+27
-5
lines changed

2 files changed

+27
-5
lines changed

drivers/net/ethernet/netronome/nfp/nfd3/dp.c

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -324,14 +324,15 @@ netdev_tx_t nfp_nfd3_tx(struct sk_buff *skb, struct net_device *netdev)
324324

325325
/* Do not reorder - tso may adjust pkt cnt, vlan may override fields */
326326
nfp_nfd3_tx_tso(r_vec, txbuf, txd, skb, md_bytes);
327-
nfp_nfd3_tx_csum(dp, r_vec, txbuf, txd, skb);
327+
if (ipsec)
328+
nfp_nfd3_ipsec_tx(txd, skb);
329+
else
330+
nfp_nfd3_tx_csum(dp, r_vec, txbuf, txd, skb);
328331
if (skb_vlan_tag_present(skb) && dp->ctrl & NFP_NET_CFG_CTRL_TXVLAN) {
329332
txd->flags |= NFD3_DESC_TX_VLAN;
330333
txd->vlan = cpu_to_le16(skb_vlan_tag_get(skb));
331334
}
332335

333-
if (ipsec)
334-
nfp_nfd3_ipsec_tx(txd, skb);
335336
/* Gather DMA */
336337
if (nr_frags > 0) {
337338
__le64 second_half;

drivers/net/ethernet/netronome/nfp/nfd3/ipsec.c

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,30 @@
1010
void nfp_nfd3_ipsec_tx(struct nfp_nfd3_tx_desc *txd, struct sk_buff *skb)
1111
{
1212
struct xfrm_state *x = xfrm_input_state(skb);
13+
struct xfrm_offload *xo = xfrm_offload(skb);
14+
struct iphdr *iph = ip_hdr(skb);
15+
int l4_proto;
1316

1417
if (x->xso.dev && (x->xso.dev->features & NETIF_F_HW_ESP_TX_CSUM)) {
15-
txd->flags |= NFD3_DESC_TX_CSUM | NFD3_DESC_TX_IP4_CSUM |
16-
NFD3_DESC_TX_TCP_CSUM | NFD3_DESC_TX_UDP_CSUM;
18+
txd->flags |= NFD3_DESC_TX_CSUM;
19+
20+
if (iph->version == 4)
21+
txd->flags |= NFD3_DESC_TX_IP4_CSUM;
22+
23+
if (x->props.mode == XFRM_MODE_TRANSPORT)
24+
l4_proto = xo->proto;
25+
else if (x->props.mode == XFRM_MODE_TUNNEL)
26+
l4_proto = xo->inner_ipproto;
27+
else
28+
return;
29+
30+
switch (l4_proto) {
31+
case IPPROTO_UDP:
32+
txd->flags |= NFD3_DESC_TX_UDP_CSUM;
33+
return;
34+
case IPPROTO_TCP:
35+
txd->flags |= NFD3_DESC_TX_TCP_CSUM;
36+
return;
37+
}
1738
}
1839
}

0 commit comments

Comments
 (0)