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