xref: /linux/drivers/net/ethernet/meta/fbnic/fbnic_txrx.h (revision a3a02a52bcfcbcc4a637d4b68bf1bc391c9fad02)
1 /* SPDX-License-Identifier: GPL-2.0 */
2 /* Copyright (c) Meta Platforms, Inc. and affiliates. */
3 
4 #ifndef _FBNIC_TXRX_H_
5 #define _FBNIC_TXRX_H_
6 
7 #include <linux/netdevice.h>
8 #include <linux/skbuff.h>
9 #include <linux/types.h>
10 #include <net/xdp.h>
11 
12 struct fbnic_net;
13 
14 /* Guarantee we have space needed for storing the buffer
15  * To store the buffer we need:
16  *	1 descriptor per page
17  *	+ 1 descriptor for skb head
18  *	+ 2 descriptors for metadata and optional metadata
19  *	+ 7 descriptors to keep tail out of the same cacheline as head
20  * If we cannot guarantee that then we should return TX_BUSY
21  */
22 #define FBNIC_MAX_SKB_DESC	(MAX_SKB_FRAGS + 10)
23 #define FBNIC_TX_DESC_WAKEUP	(FBNIC_MAX_SKB_DESC * 2)
24 #define FBNIC_TX_DESC_MIN	roundup_pow_of_two(FBNIC_TX_DESC_WAKEUP)
25 
26 #define FBNIC_MAX_TXQS			128u
27 #define FBNIC_MAX_RXQS			128u
28 
29 #define FBNIC_TXQ_SIZE_DEFAULT		1024
30 #define FBNIC_HPQ_SIZE_DEFAULT		256
31 #define FBNIC_PPQ_SIZE_DEFAULT		256
32 #define FBNIC_RCQ_SIZE_DEFAULT		1024
33 
34 #define FBNIC_RX_TROOM \
35 	SKB_DATA_ALIGN(sizeof(struct skb_shared_info))
36 #define FBNIC_RX_HROOM \
37 	(ALIGN(FBNIC_RX_TROOM + NET_SKB_PAD, 128) - FBNIC_RX_TROOM)
38 #define FBNIC_RX_PAD			0
39 #define FBNIC_RX_MAX_HDR		(1536 - FBNIC_RX_PAD)
40 #define FBNIC_RX_PAYLD_OFFSET		0
41 #define FBNIC_RX_PAYLD_PG_CL		0
42 
43 #define FBNIC_RING_F_DISABLED		BIT(0)
44 #define FBNIC_RING_F_CTX		BIT(1)
45 #define FBNIC_RING_F_STATS		BIT(2)	/* Ring's stats may be used */
46 
47 struct fbnic_pkt_buff {
48 	struct xdp_buff buff;
49 	u32 data_truesize;
50 	u16 data_len;
51 	u16 nr_frags;
52 };
53 
54 /* Pagecnt bias is long max to reserve the last bit to catch overflow
55  * cases where if we overcharge the bias it will flip over to be negative.
56  */
57 #define PAGECNT_BIAS_MAX	LONG_MAX
58 struct fbnic_rx_buf {
59 	struct page *page;
60 	long pagecnt_bias;
61 };
62 
63 struct fbnic_ring {
64 	/* Pointer to buffer specific info */
65 	union {
66 		struct fbnic_pkt_buff *pkt;	/* RCQ */
67 		struct fbnic_rx_buf *rx_buf;	/* BDQ */
68 		void **tx_buf;			/* TWQ */
69 		void *buffer;			/* Generic pointer */
70 	};
71 
72 	u32 __iomem *doorbell;		/* Pointer to CSR space for ring */
73 	__le64 *desc;			/* Descriptor ring memory */
74 	u16 size_mask;			/* Size of ring in descriptors - 1 */
75 	u8 q_idx;			/* Logical netdev ring index */
76 	u8 flags;			/* Ring flags (FBNIC_RING_F_*) */
77 
78 	u32 head, tail;			/* Head/Tail of ring */
79 
80 	/* Slow path fields follow */
81 	dma_addr_t dma;			/* Phys addr of descriptor memory */
82 	size_t size;			/* Size of descriptor ring in memory */
83 };
84 
85 struct fbnic_q_triad {
86 	struct fbnic_ring sub0, sub1, cmpl;
87 };
88 
89 struct fbnic_napi_vector {
90 	struct napi_struct napi;
91 	struct device *dev;		/* Device for DMA unmapping */
92 	struct page_pool *page_pool;
93 	struct fbnic_dev *fbd;
94 	char name[IFNAMSIZ + 9];
95 
96 	u16 v_idx;
97 	u8 txt_count;
98 	u8 rxt_count;
99 
100 	struct list_head napis;
101 
102 	struct fbnic_q_triad qt[];
103 };
104 
105 #define FBNIC_MAX_TXQS			128u
106 #define FBNIC_MAX_RXQS			128u
107 
108 netdev_tx_t fbnic_xmit_frame(struct sk_buff *skb, struct net_device *dev);
109 netdev_features_t
110 fbnic_features_check(struct sk_buff *skb, struct net_device *dev,
111 		     netdev_features_t features);
112 
113 int fbnic_alloc_napi_vectors(struct fbnic_net *fbn);
114 void fbnic_free_napi_vectors(struct fbnic_net *fbn);
115 int fbnic_alloc_resources(struct fbnic_net *fbn);
116 void fbnic_free_resources(struct fbnic_net *fbn);
117 void fbnic_napi_enable(struct fbnic_net *fbn);
118 void fbnic_napi_disable(struct fbnic_net *fbn);
119 void fbnic_enable(struct fbnic_net *fbn);
120 void fbnic_disable(struct fbnic_net *fbn);
121 void fbnic_flush(struct fbnic_net *fbn);
122 void fbnic_fill(struct fbnic_net *fbn);
123 
124 void fbnic_napi_depletion_check(struct net_device *netdev);
125 int fbnic_wait_all_queues_idle(struct fbnic_dev *fbd, bool may_fail);
126 
127 #endif /* _FBNIC_TXRX_H_ */
128