xref: /freebsd/sys/dev/gve/gve_dqo.h (revision 2348ac893d10f06d2d84e1e4bd5ca9f1c5da92d8)
1d438b4efSShailend Chand /*-
2d438b4efSShailend Chand  * SPDX-License-Identifier: BSD-3-Clause
3d438b4efSShailend Chand  *
4d438b4efSShailend Chand  * Copyright (c) 2024 Google LLC
5d438b4efSShailend Chand  *
6d438b4efSShailend Chand  * Redistribution and use in source and binary forms, with or without modification,
7d438b4efSShailend Chand  * are permitted provided that the following conditions are met:
8d438b4efSShailend Chand  *
9d438b4efSShailend Chand  * 1. Redistributions of source code must retain the above copyright notice, this
10d438b4efSShailend Chand  *    list of conditions and the following disclaimer.
11d438b4efSShailend Chand  *
12d438b4efSShailend Chand  * 2. Redistributions in binary form must reproduce the above copyright notice,
13d438b4efSShailend Chand  *    this list of conditions and the following disclaimer in the documentation
14d438b4efSShailend Chand  *    and/or other materials provided with the distribution.
15d438b4efSShailend Chand  *
16d438b4efSShailend Chand  * 3. Neither the name of the copyright holder nor the names of its contributors
17d438b4efSShailend Chand  *    may be used to endorse or promote products derived from this software without
18d438b4efSShailend Chand  *    specific prior written permission.
19d438b4efSShailend Chand  *
20d438b4efSShailend Chand  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
21d438b4efSShailend Chand  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
22d438b4efSShailend Chand  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
23d438b4efSShailend Chand  * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
24d438b4efSShailend Chand  * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
25d438b4efSShailend Chand  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
26d438b4efSShailend Chand  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
27d438b4efSShailend Chand  * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
28d438b4efSShailend Chand  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
29d438b4efSShailend Chand  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30d438b4efSShailend Chand  */
31d438b4efSShailend Chand 
32d438b4efSShailend Chand /* GVE DQO Descriptor formats */
33d438b4efSShailend Chand 
34d438b4efSShailend Chand #ifndef _GVE_DESC_DQO_H_
35d438b4efSShailend Chand #define _GVE_DESC_DQO_H_
36d438b4efSShailend Chand 
37d438b4efSShailend Chand #include "gve_plat.h"
38d438b4efSShailend Chand 
39d438b4efSShailend Chand #define GVE_ITR_ENABLE_BIT_DQO BIT(0)
40d438b4efSShailend Chand #define GVE_ITR_NO_UPDATE_DQO (3 << 3)
41d438b4efSShailend Chand #define GVE_ITR_INTERVAL_DQO_SHIFT 5
42d438b4efSShailend Chand #define GVE_ITR_INTERVAL_DQO_MASK ((1 << 12) - 1)
43d438b4efSShailend Chand #define GVE_TX_IRQ_RATELIMIT_US_DQO 50
44d438b4efSShailend Chand #define GVE_RX_IRQ_RATELIMIT_US_DQO 20
45d438b4efSShailend Chand 
46d438b4efSShailend Chand #define GVE_TX_MAX_HDR_SIZE_DQO 255
47d438b4efSShailend Chand #define GVE_TX_MIN_TSO_MSS_DQO 88
48d438b4efSShailend Chand 
49d438b4efSShailend Chand /*
50d438b4efSShailend Chand  * Ringing the doorbell too often can hurt performance.
51d438b4efSShailend Chand  *
52d438b4efSShailend Chand  * HW requires this value to be at least 8.
53d438b4efSShailend Chand  */
54d438b4efSShailend Chand #define GVE_RX_BUF_THRESH_DQO 32
55d438b4efSShailend Chand 
56d438b4efSShailend Chand /*
57d438b4efSShailend Chand  * Start dropping RX fragments if at least these many
58d438b4efSShailend Chand  * buffers cannot be posted to the NIC.
59d438b4efSShailend Chand  */
60*2348ac89SShailend Chand #define GVE_RX_DQO_MIN_PENDING_BUFS 128
61*2348ac89SShailend Chand 
62*2348ac89SShailend Chand #define GVE_DQ_NUM_FRAGS_IN_PAGE (PAGE_SIZE / GVE_DEFAULT_RX_BUFFER_SIZE)
63*2348ac89SShailend Chand 
64*2348ac89SShailend Chand /*
65*2348ac89SShailend Chand  * gve_rx_qpl_buf_id_dqo's 11 bit wide buf_id field limits the total
66*2348ac89SShailend Chand  * number of pages per QPL to 2048.
67*2348ac89SShailend Chand  */
68*2348ac89SShailend Chand #define GVE_RX_NUM_QPL_PAGES_DQO 2048
69*2348ac89SShailend Chand 
70*2348ac89SShailend Chand /* 2K TX buffers for DQO-QPL */
71*2348ac89SShailend Chand #define GVE_TX_BUF_SHIFT_DQO 11
72*2348ac89SShailend Chand #define GVE_TX_BUF_SIZE_DQO BIT(GVE_TX_BUF_SHIFT_DQO)
73*2348ac89SShailend Chand #define GVE_TX_BUFS_PER_PAGE_DQO (PAGE_SIZE >> GVE_TX_BUF_SHIFT_DQO)
74*2348ac89SShailend Chand 
75*2348ac89SShailend Chand #define GVE_TX_NUM_QPL_PAGES_DQO 512
76d438b4efSShailend Chand 
77d438b4efSShailend Chand /* Basic TX descriptor (DTYPE 0x0C) */
78d438b4efSShailend Chand struct gve_tx_pkt_desc_dqo {
79d438b4efSShailend Chand 	__le64 buf_addr;
80d438b4efSShailend Chand 
81d438b4efSShailend Chand 	/* Must be GVE_TX_PKT_DESC_DTYPE_DQO (0xc) */
82d438b4efSShailend Chand 	uint8_t dtype:5;
83d438b4efSShailend Chand 
84d438b4efSShailend Chand 	/* Denotes the last descriptor of a packet. */
85d438b4efSShailend Chand 	uint8_t end_of_packet:1;
86d438b4efSShailend Chand 	uint8_t checksum_offload_enable:1;
87d438b4efSShailend Chand 
88d438b4efSShailend Chand 	/* If set, will generate a descriptor completion for this descriptor. */
89d438b4efSShailend Chand 	uint8_t report_event:1;
90d438b4efSShailend Chand 	uint8_t reserved0;
91d438b4efSShailend Chand 	__le16 reserved1;
92d438b4efSShailend Chand 
93d438b4efSShailend Chand 	/* The TX completion for this packet will contain this tag. */
94d438b4efSShailend Chand 	__le16 compl_tag;
95d438b4efSShailend Chand 	uint16_t buf_size:14;
96d438b4efSShailend Chand 	uint16_t reserved2:2;
97d438b4efSShailend Chand } __packed;
98d438b4efSShailend Chand _Static_assert(sizeof(struct gve_tx_pkt_desc_dqo) == 16,
99d438b4efSShailend Chand     "gve: bad dqo desc struct length");
100d438b4efSShailend Chand 
101d438b4efSShailend Chand #define GVE_TX_PKT_DESC_DTYPE_DQO 0xc
102d438b4efSShailend Chand 
103d438b4efSShailend Chand /*
104d438b4efSShailend Chand  * Maximum number of data descriptors allowed per packet, or per-TSO segment.
105d438b4efSShailend Chand  */
106d438b4efSShailend Chand #define GVE_TX_MAX_DATA_DESCS_DQO 10
107d438b4efSShailend Chand #define GVE_TX_MAX_BUF_SIZE_DQO ((16 * 1024) - 1)
108d438b4efSShailend Chand #define GVE_TSO_MAXSIZE_DQO IP_MAXPACKET
109d438b4efSShailend Chand 
110d438b4efSShailend Chand _Static_assert(GVE_TX_MAX_BUF_SIZE_DQO * GVE_TX_MAX_DATA_DESCS_DQO >=
111d438b4efSShailend Chand     GVE_TSO_MAXSIZE_DQO,
112d438b4efSShailend Chand     "gve: bad tso parameters");
113d438b4efSShailend Chand 
114d438b4efSShailend Chand /*
115d438b4efSShailend Chand  * "report_event" on TX packet descriptors may only be reported on the last
116d438b4efSShailend Chand  * descriptor of a TX packet, and they must be spaced apart with at least this
117d438b4efSShailend Chand  * value.
118d438b4efSShailend Chand  */
119d438b4efSShailend Chand #define GVE_TX_MIN_RE_INTERVAL 32
120d438b4efSShailend Chand 
121d438b4efSShailend Chand struct gve_tx_context_cmd_dtype {
122d438b4efSShailend Chand 	uint8_t dtype:5;
123d438b4efSShailend Chand 	uint8_t tso:1;
124d438b4efSShailend Chand 	uint8_t reserved1:2;
125d438b4efSShailend Chand 	uint8_t reserved2;
126d438b4efSShailend Chand };
127d438b4efSShailend Chand 
128d438b4efSShailend Chand _Static_assert(sizeof(struct gve_tx_context_cmd_dtype) == 2,
129d438b4efSShailend Chand     "gve: bad dqo desc struct length");
130d438b4efSShailend Chand 
131d438b4efSShailend Chand /*
132d438b4efSShailend Chand  * TX Native TSO Context DTYPE (0x05)
133d438b4efSShailend Chand  *
134d438b4efSShailend Chand  * "flex" fields allow the driver to send additional packet context to HW.
135d438b4efSShailend Chand  */
136d438b4efSShailend Chand struct gve_tx_tso_context_desc_dqo {
137d438b4efSShailend Chand 	/* The L4 payload bytes that should be segmented. */
138d438b4efSShailend Chand 	uint32_t tso_total_len:24;
139d438b4efSShailend Chand 	uint32_t flex10:8;
140d438b4efSShailend Chand 
141d438b4efSShailend Chand 	/* Max segment size in TSO excluding headers. */
142d438b4efSShailend Chand 	uint16_t mss:14;
143d438b4efSShailend Chand 	uint16_t reserved:2;
144d438b4efSShailend Chand 
145d438b4efSShailend Chand 	uint8_t header_len; /* Header length to use for TSO offload */
146d438b4efSShailend Chand 	uint8_t flex11;
147d438b4efSShailend Chand 	struct gve_tx_context_cmd_dtype cmd_dtype;
148d438b4efSShailend Chand 	uint8_t flex0;
149d438b4efSShailend Chand 	uint8_t flex5;
150d438b4efSShailend Chand 	uint8_t flex6;
151d438b4efSShailend Chand 	uint8_t flex7;
152d438b4efSShailend Chand 	uint8_t flex8;
153d438b4efSShailend Chand 	uint8_t flex9;
154d438b4efSShailend Chand } __packed;
155d438b4efSShailend Chand _Static_assert(sizeof(struct gve_tx_tso_context_desc_dqo) == 16,
156d438b4efSShailend Chand     "gve: bad dqo desc struct length");
157d438b4efSShailend Chand 
158d438b4efSShailend Chand #define GVE_TX_TSO_CTX_DESC_DTYPE_DQO 0x5
159d438b4efSShailend Chand 
160d438b4efSShailend Chand /* General context descriptor for sending metadata. */
161d438b4efSShailend Chand struct gve_tx_general_context_desc_dqo {
162d438b4efSShailend Chand 	uint8_t flex4;
163d438b4efSShailend Chand 	uint8_t flex5;
164d438b4efSShailend Chand 	uint8_t flex6;
165d438b4efSShailend Chand 	uint8_t flex7;
166d438b4efSShailend Chand 	uint8_t flex8;
167d438b4efSShailend Chand 	uint8_t flex9;
168d438b4efSShailend Chand 	uint8_t flex10;
169d438b4efSShailend Chand 	uint8_t flex11;
170d438b4efSShailend Chand 	struct gve_tx_context_cmd_dtype cmd_dtype;
171d438b4efSShailend Chand 	uint16_t reserved;
172d438b4efSShailend Chand 	uint8_t flex0;
173d438b4efSShailend Chand 	uint8_t flex1;
174d438b4efSShailend Chand 	uint8_t flex2;
175d438b4efSShailend Chand 	uint8_t flex3;
176d438b4efSShailend Chand } __packed;
177d438b4efSShailend Chand _Static_assert(sizeof(struct gve_tx_general_context_desc_dqo) == 16,
178d438b4efSShailend Chand     "gve: bad dqo desc struct length");
179d438b4efSShailend Chand 
180d438b4efSShailend Chand #define GVE_TX_GENERAL_CTX_DESC_DTYPE_DQO 0x4
181d438b4efSShailend Chand 
182d438b4efSShailend Chand /*
183d438b4efSShailend Chand  * Logical structure of metadata which is packed into context descriptor flex
184d438b4efSShailend Chand  * fields.
185d438b4efSShailend Chand  */
186d438b4efSShailend Chand struct gve_tx_metadata_dqo {
187d438b4efSShailend Chand 	union {
188d438b4efSShailend Chand 		struct {
189d438b4efSShailend Chand 			uint8_t version;
190d438b4efSShailend Chand 
191d438b4efSShailend Chand 			/*
192d438b4efSShailend Chand 			 * A zero value means no l4_hash was associated with the
193d438b4efSShailend Chand 			 * mbuf.
194d438b4efSShailend Chand 			 */
195d438b4efSShailend Chand 			uint16_t path_hash:15;
196d438b4efSShailend Chand 
197d438b4efSShailend Chand 			/*
198d438b4efSShailend Chand 			 * Should be set to 1 if the flow associated with the
199d438b4efSShailend Chand 			 * mbuf had a rehash from the TCP stack.
200d438b4efSShailend Chand 			 */
201d438b4efSShailend Chand 			uint16_t rehash_event:1;
202d438b4efSShailend Chand 		}  __packed;
203d438b4efSShailend Chand 		uint8_t bytes[12];
204d438b4efSShailend Chand 	};
205d438b4efSShailend Chand }  __packed;
206d438b4efSShailend Chand _Static_assert(sizeof(struct gve_tx_metadata_dqo) == 12,
207d438b4efSShailend Chand     "gve: bad dqo desc struct length");
208d438b4efSShailend Chand 
209d438b4efSShailend Chand #define GVE_TX_METADATA_VERSION_DQO 0
210d438b4efSShailend Chand 
211d438b4efSShailend Chand /* TX completion descriptor */
212d438b4efSShailend Chand struct gve_tx_compl_desc_dqo {
213d438b4efSShailend Chand 	/* For types 0-4 this is the TX queue ID associated with this
214d438b4efSShailend Chand 	 * completion.
215d438b4efSShailend Chand 	 */
216d438b4efSShailend Chand 	uint16_t id:11;
217d438b4efSShailend Chand 
218d438b4efSShailend Chand 	/* See: GVE_COMPL_TYPE_DQO* */
219d438b4efSShailend Chand 	uint16_t type:3;
220d438b4efSShailend Chand 	uint16_t reserved0:1;
221d438b4efSShailend Chand 
222d438b4efSShailend Chand 	/* Flipped by HW to notify the descriptor is populated. */
223d438b4efSShailend Chand 	uint16_t generation:1;
224d438b4efSShailend Chand 	union {
225d438b4efSShailend Chand 		/* For descriptor completions, this is the last index fetched
226d438b4efSShailend Chand 		 * by HW + 1.
227d438b4efSShailend Chand 		 */
228d438b4efSShailend Chand 		__le16 tx_head;
229d438b4efSShailend Chand 
230d438b4efSShailend Chand 		/* For packet completions, this is the completion tag set on the
231d438b4efSShailend Chand 		 * TX packet descriptors.
232d438b4efSShailend Chand 		 */
233d438b4efSShailend Chand 		__le16 completion_tag;
234d438b4efSShailend Chand 	};
235d438b4efSShailend Chand 	__le32 reserved1;
236d438b4efSShailend Chand } __packed;
237d438b4efSShailend Chand _Static_assert(sizeof(struct gve_tx_compl_desc_dqo) == 8,
238d438b4efSShailend Chand     "gve: bad dqo desc struct length");
239d438b4efSShailend Chand 
240d438b4efSShailend Chand union gve_tx_desc_dqo {
241d438b4efSShailend Chand 	struct gve_tx_pkt_desc_dqo pkt;
242d438b4efSShailend Chand 	struct gve_tx_tso_context_desc_dqo tso_ctx;
243d438b4efSShailend Chand 	struct gve_tx_general_context_desc_dqo general_ctx;
244d438b4efSShailend Chand };
245d438b4efSShailend Chand 
246d438b4efSShailend Chand #define GVE_COMPL_TYPE_DQO_PKT 0x2 /* Packet completion */
247d438b4efSShailend Chand #define GVE_COMPL_TYPE_DQO_DESC 0x4 /* Descriptor completion */
248d438b4efSShailend Chand 
249d438b4efSShailend Chand /* Descriptor to post buffers to HW on buffer queue. */
250d438b4efSShailend Chand struct gve_rx_desc_dqo {
251d438b4efSShailend Chand 	__le16 buf_id; /* ID returned in Rx completion descriptor */
252d438b4efSShailend Chand 	__le16 reserved0;
253d438b4efSShailend Chand 	__le32 reserved1;
254d438b4efSShailend Chand 	__le64 buf_addr; /* DMA address of the buffer */
255d438b4efSShailend Chand 	__le64 header_buf_addr;
256d438b4efSShailend Chand 	__le64 reserved2;
257d438b4efSShailend Chand } __packed;
258d438b4efSShailend Chand _Static_assert(sizeof(struct gve_rx_desc_dqo) == 32,
259d438b4efSShailend Chand     "gve: bad dqo desc struct length");
260d438b4efSShailend Chand 
261d438b4efSShailend Chand /* Descriptor for HW to notify SW of new packets received on RX queue. */
262d438b4efSShailend Chand struct gve_rx_compl_desc_dqo {
263d438b4efSShailend Chand 	/* Must be 1 */
264d438b4efSShailend Chand 	uint8_t rxdid:4;
265d438b4efSShailend Chand 	uint8_t reserved0:4;
266d438b4efSShailend Chand 
267d438b4efSShailend Chand 	/* Packet originated from this system rather than the network. */
268d438b4efSShailend Chand 	uint8_t loopback:1;
269d438b4efSShailend Chand 	/* Set when IPv6 packet contains a destination options header or routing
270d438b4efSShailend Chand 	 * header.
271d438b4efSShailend Chand 	 */
272d438b4efSShailend Chand 	uint8_t ipv6_ex_add:1;
273d438b4efSShailend Chand 	/* Invalid packet was received. */
274d438b4efSShailend Chand 	uint8_t rx_error:1;
275d438b4efSShailend Chand 	uint8_t reserved1:5;
276d438b4efSShailend Chand 
277d438b4efSShailend Chand 	uint16_t packet_type:10;
278d438b4efSShailend Chand 	uint16_t ip_hdr_err:1;
279d438b4efSShailend Chand 	uint16_t udp_len_err:1;
280d438b4efSShailend Chand 	uint16_t raw_cs_invalid:1;
281d438b4efSShailend Chand 	uint16_t reserved2:3;
282d438b4efSShailend Chand 
283d438b4efSShailend Chand 	uint16_t packet_len:14;
284d438b4efSShailend Chand 	/* Flipped by HW to notify the descriptor is populated. */
285d438b4efSShailend Chand 	uint16_t generation:1;
286d438b4efSShailend Chand 	/* Should be zero. */
287d438b4efSShailend Chand 	uint16_t buffer_queue_id:1;
288d438b4efSShailend Chand 
289d438b4efSShailend Chand 	uint16_t header_len:10;
290d438b4efSShailend Chand 	uint16_t rsc:1;
291d438b4efSShailend Chand 	uint16_t split_header:1;
292d438b4efSShailend Chand 	uint16_t reserved3:4;
293d438b4efSShailend Chand 
294d438b4efSShailend Chand 	uint8_t descriptor_done:1;
295d438b4efSShailend Chand 	uint8_t end_of_packet:1;
296d438b4efSShailend Chand 	uint8_t header_buffer_overflow:1;
297d438b4efSShailend Chand 	uint8_t l3_l4_processed:1;
298d438b4efSShailend Chand 	uint8_t csum_ip_err:1;
299d438b4efSShailend Chand 	uint8_t csum_l4_err:1;
300d438b4efSShailend Chand 	uint8_t csum_external_ip_err:1;
301d438b4efSShailend Chand 	uint8_t csum_external_udp_err:1;
302d438b4efSShailend Chand 
303d438b4efSShailend Chand 	uint8_t status_error1;
304d438b4efSShailend Chand 
305d438b4efSShailend Chand 	__le16 reserved5;
306d438b4efSShailend Chand 	__le16 buf_id; /* Buffer ID which was sent on the buffer queue. */
307d438b4efSShailend Chand 
308d438b4efSShailend Chand 	union {
309d438b4efSShailend Chand 		/* Packet checksum. */
310d438b4efSShailend Chand 		__le16 raw_cs;
311d438b4efSShailend Chand 		/* Segment length for RSC packets. */
312d438b4efSShailend Chand 		__le16 rsc_seg_len;
313d438b4efSShailend Chand 	};
314d438b4efSShailend Chand 	__le32 hash;
315d438b4efSShailend Chand 	__le32 reserved6;
316d438b4efSShailend Chand 	__le64 reserved7;
317d438b4efSShailend Chand } __packed;
318d438b4efSShailend Chand 
319d438b4efSShailend Chand _Static_assert(sizeof(struct gve_rx_compl_desc_dqo) == 32,
320d438b4efSShailend Chand     "gve: bad dqo desc struct length");
321d438b4efSShailend Chand #endif /* _GVE_DESC_DQO_H_ */
322