cfc09d1645fc035e51e3dd209653acbe27a1f492
[dpdk.git] / drivers / net / sfc / sfc_tso.h
1 /* SPDX-License-Identifier: BSD-3-Clause
2  *
3  * Copyright(c) 2019-2021 Xilinx, Inc.
4  * Copyright(c) 2018-2019 Solarflare Communications Inc.
5  *
6  * This software was jointly developed between OKTET Labs (under contract
7  * for Solarflare) and Solarflare Communications, Inc.
8  */
9
10 #ifndef _SFC_TSO_H
11 #define _SFC_TSO_H
12
13 #ifdef __cplusplus
14 extern "C" {
15 #endif
16
17 /** Standard TSO header length */
18 #define SFC_TSOH_STD_LEN        256
19
20 /** The number of TSO option descriptors that precede the packet descriptors */
21 #define SFC_EF10_TSO_OPT_DESCS_NUM      2
22
23 /**
24  * The number of DMA descriptors for TSO header that may or may not precede the
25  * packet's payload descriptors
26  */
27 #define SFC_EF10_TSO_HDR_DESCS_NUM      1
28
29 static inline uint16_t
30 sfc_tso_ip4_get_ipid(const uint8_t *pkt_hdrp, size_t ip_hdr_off)
31 {
32         const struct rte_ipv4_hdr *ip_hdrp;
33         uint16_t ipid;
34
35         ip_hdrp = (const struct rte_ipv4_hdr *)(pkt_hdrp + ip_hdr_off);
36         rte_memcpy(&ipid, &ip_hdrp->packet_id, sizeof(ipid));
37
38         return rte_be_to_cpu_16(ipid);
39 }
40
41 static inline void
42 sfc_tso_outer_udp_fix_len(const struct rte_mbuf *m, uint8_t *tsoh)
43 {
44         rte_be16_t len = rte_cpu_to_be_16(m->l2_len + m->l3_len + m->l4_len +
45                                           m->tso_segsz);
46
47         rte_memcpy(tsoh + m->outer_l2_len + m->outer_l3_len +
48                    offsetof(struct rte_udp_hdr, dgram_len),
49                    &len, sizeof(len));
50 }
51
52 static inline void
53 sfc_tso_innermost_ip_fix_len(const struct rte_mbuf *m, uint8_t *tsoh,
54                              size_t iph_ofst)
55 {
56         size_t ip_payload_len = m->l4_len + m->tso_segsz;
57         size_t field_ofst;
58         rte_be16_t len;
59
60         if (m->ol_flags & PKT_TX_IPV4) {
61                 field_ofst = offsetof(struct rte_ipv4_hdr, total_length);
62                 len = rte_cpu_to_be_16(m->l3_len + ip_payload_len);
63         } else {
64                 field_ofst = offsetof(struct rte_ipv6_hdr, payload_len);
65                 len = rte_cpu_to_be_16(ip_payload_len);
66         }
67
68         rte_memcpy(tsoh + iph_ofst + field_ofst, &len, sizeof(len));
69 }
70
71 unsigned int sfc_tso_prepare_header(uint8_t *tsoh, size_t header_len,
72                                     struct rte_mbuf **in_seg, size_t *in_off);
73
74 #ifdef __cplusplus
75 }
76 #endif
77
78 #endif  /* _SFC_TSO_H */