1c10d12e3SJakub Kicinski /* SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause) */
2c10d12e3SJakub Kicinski /* Copyright (C) 2019 Netronome Systems, Inc. */
3c10d12e3SJakub Kicinski
4c10d12e3SJakub Kicinski #ifndef _NFP_DP_NFDK_H_
5c10d12e3SJakub Kicinski #define _NFP_DP_NFDK_H_
6c10d12e3SJakub Kicinski
7c10d12e3SJakub Kicinski #include <linux/bitops.h>
8c10d12e3SJakub Kicinski #include <linux/types.h>
9c10d12e3SJakub Kicinski
10c10d12e3SJakub Kicinski #define NFDK_TX_DESC_PER_SIMPLE_PKT 2
11c10d12e3SJakub Kicinski
12c10d12e3SJakub Kicinski #define NFDK_TX_MAX_DATA_PER_HEAD SZ_4K
13c10d12e3SJakub Kicinski #define NFDK_TX_MAX_DATA_PER_DESC SZ_16K
14c10d12e3SJakub Kicinski #define NFDK_TX_DESC_BLOCK_SZ 256
15c10d12e3SJakub Kicinski #define NFDK_TX_DESC_BLOCK_CNT (NFDK_TX_DESC_BLOCK_SZ / \
16c10d12e3SJakub Kicinski sizeof(struct nfp_nfdk_tx_desc))
17c10d12e3SJakub Kicinski #define NFDK_TX_DESC_STOP_CNT (NFDK_TX_DESC_BLOCK_CNT * \
18c10d12e3SJakub Kicinski NFDK_TX_DESC_PER_SIMPLE_PKT)
19c10d12e3SJakub Kicinski #define NFDK_TX_MAX_DATA_PER_BLOCK SZ_64K
20c10d12e3SJakub Kicinski #define NFDK_TX_DESC_GATHER_MAX 17
21c10d12e3SJakub Kicinski
22c10d12e3SJakub Kicinski /* TX descriptor format */
23c10d12e3SJakub Kicinski
24c10d12e3SJakub Kicinski #define NFDK_DESC_TX_MSS_MASK GENMASK(13, 0)
25c10d12e3SJakub Kicinski
26c10d12e3SJakub Kicinski #define NFDK_DESC_TX_CHAIN_META BIT(3)
27c10d12e3SJakub Kicinski #define NFDK_DESC_TX_ENCAP BIT(2)
28c10d12e3SJakub Kicinski #define NFDK_DESC_TX_L4_CSUM BIT(1)
29c10d12e3SJakub Kicinski #define NFDK_DESC_TX_L3_CSUM BIT(0)
30c10d12e3SJakub Kicinski
31c10d12e3SJakub Kicinski #define NFDK_DESC_TX_DMA_LEN_HEAD GENMASK(11, 0)
32c10d12e3SJakub Kicinski #define NFDK_DESC_TX_TYPE_HEAD GENMASK(15, 12)
33c10d12e3SJakub Kicinski #define NFDK_DESC_TX_DMA_LEN GENMASK(13, 0)
34c10d12e3SJakub Kicinski #define NFDK_DESC_TX_TYPE_NOP 0
35c10d12e3SJakub Kicinski #define NFDK_DESC_TX_TYPE_GATHER 1
36c10d12e3SJakub Kicinski #define NFDK_DESC_TX_TYPE_TSO 2
37c10d12e3SJakub Kicinski #define NFDK_DESC_TX_TYPE_SIMPLE 8
38c10d12e3SJakub Kicinski #define NFDK_DESC_TX_EOP BIT(14)
39c10d12e3SJakub Kicinski
40c10d12e3SJakub Kicinski #define NFDK_META_LEN GENMASK(7, 0)
41c10d12e3SJakub Kicinski #define NFDK_META_FIELDS GENMASK(31, 8)
42c10d12e3SJakub Kicinski
43c10d12e3SJakub Kicinski #define D_BLOCK_CPL(idx) (NFDK_TX_DESC_BLOCK_CNT - \
44c10d12e3SJakub Kicinski (idx) % NFDK_TX_DESC_BLOCK_CNT)
45c10d12e3SJakub Kicinski
46c10d12e3SJakub Kicinski struct nfp_nfdk_tx_desc {
47c10d12e3SJakub Kicinski union {
48c10d12e3SJakub Kicinski struct {
49c6fbbf1eSFei Qin __le16 dma_addr_hi; /* High bits of host buf address */
50c10d12e3SJakub Kicinski __le16 dma_len_type; /* Length to DMA for this desc */
51c10d12e3SJakub Kicinski __le32 dma_addr_lo; /* Low 32bit of host buf addr */
52c10d12e3SJakub Kicinski };
53c10d12e3SJakub Kicinski
54c10d12e3SJakub Kicinski struct {
55c10d12e3SJakub Kicinski __le16 mss; /* MSS to be used for LSO */
56c10d12e3SJakub Kicinski u8 lso_hdrlen; /* LSO, TCP payload offset */
57c10d12e3SJakub Kicinski u8 lso_totsegs; /* LSO, total segments */
58c10d12e3SJakub Kicinski u8 l3_offset; /* L3 header offset */
59c10d12e3SJakub Kicinski u8 l4_offset; /* L4 header offset */
60c10d12e3SJakub Kicinski __le16 lso_meta_res; /* Rsvd bits in TSO metadata */
61c10d12e3SJakub Kicinski };
62c10d12e3SJakub Kicinski
63c10d12e3SJakub Kicinski struct {
64c10d12e3SJakub Kicinski u8 flags; /* TX Flags, see @NFDK_DESC_TX_* */
65c10d12e3SJakub Kicinski u8 reserved[7]; /* meta byte placeholder */
66c10d12e3SJakub Kicinski };
67c10d12e3SJakub Kicinski
68c10d12e3SJakub Kicinski __le32 vals[2];
69c10d12e3SJakub Kicinski __le64 raw;
70c10d12e3SJakub Kicinski };
71c10d12e3SJakub Kicinski };
72c10d12e3SJakub Kicinski
73d9d95049SYinjun Zhang /* The device don't make use of the 2 or 3 least significant bits of the address
74d9d95049SYinjun Zhang * due to alignment constraints. The driver can make use of those bits to carry
75d9d95049SYinjun Zhang * information about the buffer before giving it to the device.
76d9d95049SYinjun Zhang *
77d9d95049SYinjun Zhang * NOTE: The driver must clear the lower bits before handing the buffer to the
78d9d95049SYinjun Zhang * device.
79d9d95049SYinjun Zhang *
80d9d95049SYinjun Zhang * - NFDK_TX_BUF_INFO_SOP - Start of a packet
81d9d95049SYinjun Zhang * Mark the buffer as a start of a packet. This is used in the XDP TX process
82d9d95049SYinjun Zhang * to stash virtual and DMA address so that they can be recycled when the TX
83d9d95049SYinjun Zhang * operation is completed.
84d9d95049SYinjun Zhang */
85d9d95049SYinjun Zhang #define NFDK_TX_BUF_PTR(val) ((val) & ~(sizeof(void *) - 1))
86d9d95049SYinjun Zhang #define NFDK_TX_BUF_INFO(val) ((val) & (sizeof(void *) - 1))
87d9d95049SYinjun Zhang #define NFDK_TX_BUF_INFO_SOP BIT(0)
88d9d95049SYinjun Zhang
89c10d12e3SJakub Kicinski struct nfp_nfdk_tx_buf {
90c10d12e3SJakub Kicinski union {
91c10d12e3SJakub Kicinski /* First slot */
92c10d12e3SJakub Kicinski union {
93c10d12e3SJakub Kicinski struct sk_buff *skb;
94c10d12e3SJakub Kicinski void *frag;
95d9d95049SYinjun Zhang unsigned long val;
96c10d12e3SJakub Kicinski };
97c10d12e3SJakub Kicinski
98c10d12e3SJakub Kicinski /* 1 + nr_frags next slots */
99c10d12e3SJakub Kicinski dma_addr_t dma_addr;
100c10d12e3SJakub Kicinski
101c10d12e3SJakub Kicinski /* TSO (optional) */
102c10d12e3SJakub Kicinski struct {
103c10d12e3SJakub Kicinski u32 pkt_cnt;
104c10d12e3SJakub Kicinski u32 real_len;
105c10d12e3SJakub Kicinski };
106c10d12e3SJakub Kicinski
107c10d12e3SJakub Kicinski u64 raw;
108c10d12e3SJakub Kicinski };
109c10d12e3SJakub Kicinski };
110c10d12e3SJakub Kicinski
nfp_nfdk_headlen_to_segs(unsigned int headlen)111c10d12e3SJakub Kicinski static inline int nfp_nfdk_headlen_to_segs(unsigned int headlen)
112c10d12e3SJakub Kicinski {
113c10d12e3SJakub Kicinski /* First descriptor fits less data, so adjust for that */
114c10d12e3SJakub Kicinski return DIV_ROUND_UP(headlen +
115c10d12e3SJakub Kicinski NFDK_TX_MAX_DATA_PER_DESC -
116c10d12e3SJakub Kicinski NFDK_TX_MAX_DATA_PER_HEAD,
117c10d12e3SJakub Kicinski NFDK_TX_MAX_DATA_PER_DESC);
118c10d12e3SJakub Kicinski }
119c10d12e3SJakub Kicinski
120c10d12e3SJakub Kicinski int nfp_nfdk_poll(struct napi_struct *napi, int budget);
121c10d12e3SJakub Kicinski netdev_tx_t nfp_nfdk_tx(struct sk_buff *skb, struct net_device *netdev);
122c10d12e3SJakub Kicinski bool
123c10d12e3SJakub Kicinski nfp_nfdk_ctrl_tx_one(struct nfp_net *nn, struct nfp_net_r_vector *r_vec,
124c10d12e3SJakub Kicinski struct sk_buff *skb, bool old);
125c10d12e3SJakub Kicinski void nfp_nfdk_ctrl_poll(struct tasklet_struct *t);
126c10d12e3SJakub Kicinski void nfp_nfdk_rx_ring_fill_freelist(struct nfp_net_dp *dp,
127c10d12e3SJakub Kicinski struct nfp_net_rx_ring *rx_ring);
128*436396f2SHuanhuan Wang #ifndef CONFIG_NFP_NET_IPSEC
nfp_nfdk_ipsec_tx(u64 flags,struct sk_buff * skb)129*436396f2SHuanhuan Wang static inline u64 nfp_nfdk_ipsec_tx(u64 flags, struct sk_buff *skb)
130*436396f2SHuanhuan Wang {
131*436396f2SHuanhuan Wang return flags;
132*436396f2SHuanhuan Wang }
133*436396f2SHuanhuan Wang #else
134*436396f2SHuanhuan Wang u64 nfp_nfdk_ipsec_tx(u64 flags, struct sk_buff *skb);
135*436396f2SHuanhuan Wang #endif
136c10d12e3SJakub Kicinski #endif
137