1// SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause)
2/* Copyright (C) 2018 Netronome Systems, Inc */
3/* Copyright (C) 2021 Corigine, Inc */
4
5#include <net/xfrm.h>
6
7#include "../nfp_net.h"
8#include "nfd3.h"
9
10void nfp_nfd3_ipsec_tx(struct nfp_nfd3_tx_desc *txd, struct sk_buff *skb)
11{
12 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;
16
17 if (x->xso.dev && (x->xso.dev->features & NETIF_F_HW_ESP_TX_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 }
38 }
39}
40

source code of linux/drivers/net/ethernet/netronome/nfp/nfd3/ipsec.c