1 /* SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause) */
2 /* Copyright (C) 2015-2019 Netronome Systems, Inc. */
3 
4 #ifndef _NFP_DP_NFD3_H_
5 #define _NFP_DP_NFD3_H_
6 
7 struct sk_buff;
8 struct net_device;
9 
10 /* TX descriptor format */
11 
12 #define NFD3_DESC_TX_EOP		BIT(7)
13 #define NFD3_DESC_TX_OFFSET_MASK	GENMASK(6, 0)
14 #define NFD3_DESC_TX_MSS_MASK		GENMASK(13, 0)
15 
16 /* Flags in the host TX descriptor */
17 #define NFD3_DESC_TX_CSUM		BIT(7)
18 #define NFD3_DESC_TX_IP4_CSUM		BIT(6)
19 #define NFD3_DESC_TX_TCP_CSUM		BIT(5)
20 #define NFD3_DESC_TX_UDP_CSUM		BIT(4)
21 #define NFD3_DESC_TX_VLAN		BIT(3)
22 #define NFD3_DESC_TX_LSO		BIT(2)
23 #define NFD3_DESC_TX_ENCAP		BIT(1)
24 #define NFD3_DESC_TX_O_IP4_CSUM	BIT(0)
25 
26 struct nfp_nfd3_tx_desc {
27 	union {
28 		struct {
29 			u8 dma_addr_hi; /* High bits of host buf address */
30 			__le16 dma_len;	/* Length to DMA for this desc */
31 			u8 offset_eop;	/* Offset in buf where pkt starts +
32 					 * highest bit is eop flag.
33 					 */
34 			__le32 dma_addr_lo; /* Low 32bit of host buf addr */
35 
36 			__le16 mss;	/* MSS to be used for LSO */
37 			u8 lso_hdrlen;	/* LSO, TCP payload offset */
38 			u8 flags;	/* TX Flags, see @NFD3_DESC_TX_* */
39 			union {
40 				struct {
41 					u8 l3_offset; /* L3 header offset */
42 					u8 l4_offset; /* L4 header offset */
43 				};
44 				__le16 vlan; /* VLAN tag to add if indicated */
45 			};
46 			__le16 data_len; /* Length of frame + meta data */
47 		} __packed;
48 		__le32 vals[4];
49 		__le64 vals8[2];
50 	};
51 };
52 
53 /**
54  * struct nfp_nfd3_tx_buf - software TX buffer descriptor
55  * @skb:	normal ring, sk_buff associated with this buffer
56  * @frag:	XDP ring, page frag associated with this buffer
57  * @xdp:	XSK buffer pool handle (for AF_XDP)
58  * @dma_addr:	DMA mapping address of the buffer
59  * @fidx:	Fragment index (-1 for the head and [0..nr_frags-1] for frags)
60  * @pkt_cnt:	Number of packets to be produced out of the skb associated
61  *		with this buffer (valid only on the head's buffer).
62  *		Will be 1 for all non-TSO packets.
63  * @is_xsk_tx:	Flag if buffer is a RX buffer after a XDP_TX action and not a
64  *		buffer from the TX queue (for AF_XDP).
65  * @real_len:	Number of bytes which to be produced out of the skb (valid only
66  *		on the head's buffer). Equal to skb->len for non-TSO packets.
67  */
68 struct nfp_nfd3_tx_buf {
69 	union {
70 		struct sk_buff *skb;
71 		void *frag;
72 		struct xdp_buff *xdp;
73 	};
74 	dma_addr_t dma_addr;
75 	union {
76 		struct {
77 			short int fidx;
78 			u16 pkt_cnt;
79 		};
80 		struct {
81 			bool is_xsk_tx;
82 		};
83 	};
84 	u32 real_len;
85 };
86 
87 void
88 nfp_nfd3_rx_csum(const struct nfp_net_dp *dp, struct nfp_net_r_vector *r_vec,
89 		 const struct nfp_net_rx_desc *rxd,
90 		 const struct nfp_meta_parsed *meta, struct sk_buff *skb);
91 bool
92 nfp_nfd3_parse_meta(struct net_device *netdev, struct nfp_meta_parsed *meta,
93 		    void *data, void *pkt, unsigned int pkt_len, int meta_len);
94 void nfp_nfd3_tx_complete(struct nfp_net_tx_ring *tx_ring, int budget);
95 int nfp_nfd3_poll(struct napi_struct *napi, int budget);
96 netdev_tx_t nfp_nfd3_tx(struct sk_buff *skb, struct net_device *netdev);
97 bool
98 nfp_nfd3_ctrl_tx_one(struct nfp_net *nn, struct nfp_net_r_vector *r_vec,
99 		     struct sk_buff *skb, bool old);
100 void nfp_nfd3_ctrl_poll(struct tasklet_struct *t);
101 void nfp_nfd3_rx_ring_fill_freelist(struct nfp_net_dp *dp,
102 				    struct nfp_net_rx_ring *rx_ring);
103 void nfp_nfd3_xsk_tx_free(struct nfp_nfd3_tx_buf *txbuf);
104 int nfp_nfd3_xsk_poll(struct napi_struct *napi, int budget);
105 
106 #ifndef CONFIG_NFP_NET_IPSEC
107 static inline void nfp_nfd3_ipsec_tx(struct nfp_nfd3_tx_desc *txd, struct sk_buff *skb)
108 {
109 }
110 #else
111 void nfp_nfd3_ipsec_tx(struct nfp_nfd3_tx_desc *txd, struct sk_buff *skb);
112 #endif
113 
114 #endif
115