Branch data Line data Source code
1 : : /* SPDX-License-Identifier: BSD-3-Clause
2 : : * Copyright(C) 2022 Intel Corporation
3 : : */
4 : :
5 : : #ifndef _GVE_ETHDEV_H_
6 : : #define _GVE_ETHDEV_H_
7 : :
8 : : #include <ethdev_driver.h>
9 : : #include <ethdev_pci.h>
10 : : #include <rte_ether.h>
11 : : #include <rte_pci.h>
12 : :
13 : : #include "base/gve.h"
14 : :
15 : : /* TODO: this is a workaround to ensure that Tx complq is enough */
16 : : #define DQO_TX_MULTIPLIER 4
17 : :
18 : : #define GVE_DEFAULT_MAX_RING_SIZE 1024
19 : : #define GVE_DEFAULT_MIN_RX_RING_SIZE 512
20 : : #define GVE_DEFAULT_MIN_TX_RING_SIZE 256
21 : :
22 : : #define GVE_DEFAULT_RX_FREE_THRESH 64
23 : : #define GVE_DEFAULT_TX_FREE_THRESH 32
24 : : #define GVE_DEFAULT_TX_RS_THRESH 32
25 : : #define GVE_TX_MAX_FREE_SZ 512
26 : :
27 : : #define GVE_RX_BUF_ALIGN_DQO 128
28 : : #define GVE_RX_MIN_BUF_SIZE_DQO 1024
29 : : #define GVE_RX_MAX_BUF_SIZE_DQO ((16 * 1024) - GVE_RX_BUF_ALIGN_DQO)
30 : : #define GVE_MAX_QUEUE_SIZE_DQO 4096
31 : :
32 : : #define GVE_RX_BUF_ALIGN_GQI 2048
33 : : #define GVE_RX_MIN_BUF_SIZE_GQI 2048
34 : : #define GVE_RX_MAX_BUF_SIZE_GQI 4096
35 : :
36 : : #define GVE_RSS_HASH_KEY_SIZE 40
37 : : #define GVE_RSS_INDIR_SIZE 128
38 : :
39 : : #define GVE_TX_CKSUM_OFFLOAD_MASK ( \
40 : : RTE_MBUF_F_TX_L4_MASK | \
41 : : RTE_MBUF_F_TX_TCP_SEG)
42 : :
43 : : #define GVE_TX_CKSUM_OFFLOAD_MASK_DQO ( \
44 : : GVE_TX_CKSUM_OFFLOAD_MASK | \
45 : : RTE_MBUF_F_TX_IP_CKSUM)
46 : :
47 : : #define GVE_RTE_RSS_OFFLOAD_ALL ( \
48 : : RTE_ETH_RSS_IPV4 | \
49 : : RTE_ETH_RSS_NONFRAG_IPV4_TCP | \
50 : : RTE_ETH_RSS_IPV6 | \
51 : : RTE_ETH_RSS_IPV6_EX | \
52 : : RTE_ETH_RSS_NONFRAG_IPV6_TCP | \
53 : : RTE_ETH_RSS_IPV6_TCP_EX | \
54 : : RTE_ETH_RSS_NONFRAG_IPV4_UDP | \
55 : : RTE_ETH_RSS_NONFRAG_IPV6_UDP | \
56 : : RTE_ETH_RSS_IPV6_UDP_EX)
57 : :
58 : : /* A list of pages registered with the device during setup and used by a queue
59 : : * as buffers
60 : : */
61 : : struct gve_queue_page_list {
62 : : uint32_t id; /* unique id */
63 : : uint32_t num_entries;
64 : : dma_addr_t *page_buses; /* the dma addrs of the pages */
65 : : union {
66 : : const struct rte_memzone *mz; /* memzone allocated for TX queue */
67 : : void **qpl_bufs; /* RX qpl-buffer list allocated using malloc*/
68 : : };
69 : : };
70 : :
71 : : /* A TX desc ring entry */
72 : : union gve_tx_desc {
73 : : struct gve_tx_pkt_desc pkt; /* first desc for a packet */
74 : : struct gve_tx_seg_desc seg; /* subsequent descs for a packet */
75 : : };
76 : :
77 : : /* Tx desc for DQO format */
78 : : union gve_tx_desc_dqo {
79 : : struct gve_tx_pkt_desc_dqo pkt;
80 : : struct gve_tx_tso_context_desc_dqo tso_ctx;
81 : : struct gve_tx_general_context_desc_dqo general_ctx;
82 : : };
83 : :
84 : : /* Offload features */
85 : : union gve_tx_offload {
86 : : uint64_t data;
87 : : struct {
88 : : uint64_t l2_len:7; /* L2 (MAC) Header Length. */
89 : : uint64_t l3_len:9; /* L3 (IP) Header Length. */
90 : : uint64_t l4_len:8; /* L4 Header Length. */
91 : : uint64_t tso_segsz:16; /* TCP TSO segment size */
92 : : /* uint64_t unused : 24; */
93 : : };
94 : : };
95 : :
96 : : struct gve_tx_iovec {
97 : : uint32_t iov_base; /* offset in fifo */
98 : : uint32_t iov_len;
99 : : };
100 : :
101 : : struct gve_tx_stats {
102 : : uint64_t packets;
103 : : uint64_t bytes;
104 : : uint64_t errors;
105 : : };
106 : :
107 : : struct gve_rx_stats {
108 : : uint64_t packets;
109 : : uint64_t bytes;
110 : : uint64_t errors;
111 : : uint64_t no_mbufs;
112 : : uint64_t no_mbufs_bulk;
113 : : uint64_t imissed;
114 : : };
115 : :
116 : : struct gve_xstats_name_offset {
117 : : char name[RTE_ETH_XSTATS_NAME_SIZE];
118 : : unsigned int offset;
119 : : };
120 : :
121 : : struct gve_tx_queue {
122 : : volatile union gve_tx_desc *tx_desc_ring;
123 : : const struct rte_memzone *mz;
124 : : uint64_t tx_ring_phys_addr;
125 : : struct rte_mbuf **sw_ring;
126 : : volatile rte_be32_t *qtx_tail;
127 : : volatile rte_be32_t *qtx_head;
128 : :
129 : : uint32_t tx_tail;
130 : : uint16_t nb_tx_desc;
131 : : uint16_t nb_free;
132 : : uint16_t nb_used;
133 : : uint32_t next_to_clean;
134 : : uint16_t free_thresh;
135 : : uint16_t rs_thresh;
136 : :
137 : : /* Only valid for DQO_QPL queue format */
138 : : uint16_t sw_tail;
139 : : uint16_t sw_ntc;
140 : : uint16_t sw_nb_free;
141 : : uint32_t fifo_size;
142 : : uint32_t fifo_head;
143 : : uint32_t fifo_avail;
144 : : uint64_t fifo_base;
145 : : struct gve_queue_page_list *qpl;
146 : : struct gve_tx_iovec *iov_ring;
147 : :
148 : : /* stats items */
149 : : struct gve_tx_stats stats;
150 : :
151 : : uint16_t port_id;
152 : : uint16_t queue_id;
153 : :
154 : : uint16_t ntfy_id;
155 : : volatile rte_be32_t *ntfy_addr;
156 : :
157 : : struct gve_priv *hw;
158 : : const struct rte_memzone *qres_mz;
159 : : struct gve_queue_resources *qres;
160 : :
161 : : /* newly added for DQO */
162 : : volatile union gve_tx_desc_dqo *tx_ring;
163 : : struct gve_tx_compl_desc *compl_ring;
164 : : const struct rte_memzone *compl_ring_mz;
165 : : uint64_t compl_ring_phys_addr;
166 : : uint32_t complq_tail;
167 : : uint16_t sw_size;
168 : : uint8_t cur_gen_bit;
169 : : uint32_t last_desc_cleaned;
170 : : void **txqs;
171 : : uint16_t re_cnt;
172 : :
173 : : /* Only valid for DQO_RDA queue format */
174 : : struct gve_tx_queue *complq;
175 : :
176 : : uint8_t is_gqi_qpl;
177 : : };
178 : :
179 : : struct gve_rx_ctx {
180 : : struct rte_mbuf *mbuf_head;
181 : : struct rte_mbuf *mbuf_tail;
182 : : uint16_t total_frags;
183 : : bool drop_pkt;
184 : : };
185 : :
186 : : struct gve_rx_queue {
187 : : volatile struct gve_rx_desc *rx_desc_ring;
188 : : volatile union gve_rx_data_slot *rx_data_ring;
189 : : const struct rte_memzone *mz;
190 : : const struct rte_memzone *data_mz;
191 : : uint64_t rx_ring_phys_addr;
192 : : struct rte_mbuf **sw_ring;
193 : : struct rte_mempool *mpool;
194 : : struct gve_rx_ctx ctx;
195 : :
196 : : uint16_t rx_tail;
197 : : uint16_t nb_rx_desc;
198 : : uint16_t expected_seqno; /* the next expected seqno */
199 : : uint16_t free_thresh;
200 : : uint16_t nb_rx_hold;
201 : : uint32_t next_avail;
202 : : uint32_t nb_avail;
203 : :
204 : : volatile rte_be32_t *qrx_tail;
205 : : volatile rte_be32_t *ntfy_addr;
206 : :
207 : : /* only valid for GQI_QPL queue format */
208 : : struct gve_queue_page_list *qpl;
209 : :
210 : : /* stats items */
211 : : struct gve_rx_stats stats;
212 : :
213 : : struct gve_priv *hw;
214 : : const struct rte_memzone *qres_mz;
215 : : struct gve_queue_resources *qres;
216 : :
217 : : uint16_t port_id;
218 : : uint16_t queue_id;
219 : : uint16_t ntfy_id;
220 : : uint16_t rx_buf_len;
221 : :
222 : : /* newly added for DQO */
223 : : volatile struct gve_rx_desc_dqo *rx_ring;
224 : : struct gve_rx_compl_desc_dqo *compl_ring;
225 : : const struct rte_memzone *compl_ring_mz;
226 : : uint64_t compl_ring_phys_addr;
227 : : uint8_t cur_gen_bit;
228 : : uint16_t bufq_tail;
229 : :
230 : : /* Only valid for DQO_RDA queue format */
231 : : struct gve_rx_queue *bufq;
232 : :
233 : : uint8_t is_gqi_qpl;
234 : : };
235 : :
236 : : struct gve_priv {
237 : : struct gve_irq_db *irq_dbs; /* array of num_ntfy_blks */
238 : : const struct rte_memzone *irq_dbs_mz;
239 : : uint32_t mgmt_msix_idx;
240 : : rte_be32_t *cnt_array; /* array of num_event_counters */
241 : : const struct rte_memzone *cnt_array_mz;
242 : :
243 : : uint16_t num_event_counters;
244 : :
245 : : /* TX ring size default and limits. */
246 : : uint16_t default_tx_desc_cnt;
247 : : uint16_t max_tx_desc_cnt;
248 : : uint16_t min_tx_desc_cnt;
249 : :
250 : : /* RX ring size default and limits. */
251 : : uint16_t default_rx_desc_cnt;
252 : : uint16_t max_rx_desc_cnt;
253 : : uint16_t min_rx_desc_cnt;
254 : :
255 : : uint16_t tx_pages_per_qpl;
256 : :
257 : : /* Only valid for DQO_RDA queue format */
258 : : uint16_t tx_compq_size; /* tx completion queue size */
259 : : uint16_t rx_bufq_size; /* rx buff queue size */
260 : :
261 : : uint64_t max_registered_pages;
262 : : uint64_t num_registered_pages; /* num pages registered with NIC */
263 : : uint16_t default_num_queues; /* default num queues to set up */
264 : : enum gve_queue_format queue_format; /* see enum gve_queue_format */
265 : : uint8_t enable_rsc;
266 : :
267 : : uint16_t max_nb_txq;
268 : : uint16_t max_nb_rxq;
269 : : uint32_t num_ntfy_blks; /* spilt between TX and RX so must be even */
270 : :
271 : : struct gve_registers __iomem *reg_bar0; /* see gve_register.h */
272 : : rte_be32_t __iomem *db_bar2; /* "array" of doorbells */
273 : : struct rte_pci_device *pci_dev;
274 : :
275 : : /* Admin queue - see gve_adminq.h*/
276 : : union gve_adminq_command *adminq;
277 : : struct gve_dma_mem adminq_dma_mem;
278 : : uint32_t adminq_mask; /* masks prod_cnt to adminq size */
279 : : uint32_t adminq_prod_cnt; /* free-running count of AQ cmds executed */
280 : : uint32_t adminq_cmd_fail; /* free-running count of AQ cmds failed */
281 : : uint32_t adminq_timeouts; /* free-running count of AQ cmds timeouts */
282 : : /* free-running count of per AQ cmd executed */
283 : : uint32_t adminq_describe_device_cnt;
284 : : uint32_t adminq_cfg_device_resources_cnt;
285 : : uint32_t adminq_register_page_list_cnt;
286 : : uint32_t adminq_unregister_page_list_cnt;
287 : : uint32_t adminq_create_tx_queue_cnt;
288 : : uint32_t adminq_create_rx_queue_cnt;
289 : : uint32_t adminq_destroy_tx_queue_cnt;
290 : : uint32_t adminq_destroy_rx_queue_cnt;
291 : : uint32_t adminq_dcfg_device_resources_cnt;
292 : : uint32_t adminq_cfg_rss_cnt;
293 : : uint32_t adminq_set_driver_parameter_cnt;
294 : : uint32_t adminq_report_stats_cnt;
295 : : uint32_t adminq_report_link_speed_cnt;
296 : : uint32_t adminq_get_ptype_map_cnt;
297 : : uint32_t adminq_verify_driver_compatibility_cnt;
298 : : volatile uint32_t state_flags;
299 : :
300 : : /* Gvnic device link speed from hypervisor. */
301 : : uint64_t link_speed;
302 : :
303 : : uint16_t max_mtu;
304 : : struct rte_ether_addr dev_addr; /* mac address */
305 : :
306 : : struct gve_tx_queue **txqs;
307 : : struct gve_rx_queue **rxqs;
308 : :
309 : : uint32_t stats_report_len;
310 : : const struct rte_memzone *stats_report_mem;
311 : : uint16_t stats_start_idx; /* start index of array of stats written by NIC */
312 : : uint16_t stats_end_idx; /* end index of array of stats written by NIC */
313 : :
314 : : struct gve_rss_config rss_config;
315 : : struct gve_ptype_lut *ptype_lut_dqo;
316 : : };
317 : :
318 : : static inline bool
319 : : gve_is_gqi(struct gve_priv *priv)
320 : : {
321 [ # # # # : 0 : return priv->queue_format == GVE_GQI_RDA_FORMAT ||
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# ]
322 : : priv->queue_format == GVE_GQI_QPL_FORMAT;
323 : : }
324 : :
325 : : static inline bool
326 : : gve_get_admin_queue_ok(struct gve_priv *priv)
327 : : {
328 : : return !!rte_bit_relaxed_get32(GVE_PRIV_FLAGS_ADMIN_QUEUE_OK,
329 : : &priv->state_flags);
330 : : }
331 : :
332 : : static inline void
333 : : gve_set_admin_queue_ok(struct gve_priv *priv)
334 : : {
335 : : rte_bit_relaxed_set32(GVE_PRIV_FLAGS_ADMIN_QUEUE_OK,
336 : : &priv->state_flags);
337 : : }
338 : :
339 : : static inline void
340 : : gve_clear_admin_queue_ok(struct gve_priv *priv)
341 : : {
342 : : rte_bit_relaxed_clear32(GVE_PRIV_FLAGS_ADMIN_QUEUE_OK,
343 : : &priv->state_flags);
344 : 0 : }
345 : :
346 : : static inline bool
347 : : gve_get_device_resources_ok(struct gve_priv *priv)
348 : : {
349 : : return !!rte_bit_relaxed_get32(GVE_PRIV_FLAGS_DEVICE_RESOURCES_OK,
350 : : &priv->state_flags);
351 : : }
352 : :
353 : : static inline void
354 : : gve_set_device_resources_ok(struct gve_priv *priv)
355 : : {
356 : : rte_bit_relaxed_set32(GVE_PRIV_FLAGS_DEVICE_RESOURCES_OK,
357 : : &priv->state_flags);
358 : : }
359 : :
360 : : static inline void
361 : : gve_clear_device_resources_ok(struct gve_priv *priv)
362 : : {
363 : : rte_bit_relaxed_clear32(GVE_PRIV_FLAGS_DEVICE_RESOURCES_OK,
364 : : &priv->state_flags);
365 : : }
366 : :
367 : : static inline bool
368 : : gve_get_device_rings_ok(struct gve_priv *priv)
369 : : {
370 : : return !!rte_bit_relaxed_get32(GVE_PRIV_FLAGS_DEVICE_RINGS_OK,
371 : : &priv->state_flags);
372 : : }
373 : :
374 : : static inline void
375 : : gve_set_device_rings_ok(struct gve_priv *priv)
376 : : {
377 : : rte_bit_relaxed_set32(GVE_PRIV_FLAGS_DEVICE_RINGS_OK,
378 : : &priv->state_flags);
379 : : }
380 : :
381 : : static inline void
382 : : gve_clear_device_rings_ok(struct gve_priv *priv)
383 : : {
384 : : rte_bit_relaxed_clear32(GVE_PRIV_FLAGS_DEVICE_RINGS_OK,
385 : : &priv->state_flags);
386 : : }
387 : :
388 : : int
389 : : gve_rx_queue_setup(struct rte_eth_dev *dev, uint16_t queue_id, uint16_t nb_desc,
390 : : unsigned int socket_id, const struct rte_eth_rxconf *conf,
391 : : struct rte_mempool *pool);
392 : : int
393 : : gve_tx_queue_setup(struct rte_eth_dev *dev, uint16_t queue_id, uint16_t nb_desc,
394 : : unsigned int socket_id, const struct rte_eth_txconf *conf);
395 : :
396 : : void
397 : : gve_tx_queue_release(struct rte_eth_dev *dev, uint16_t qid);
398 : :
399 : : void
400 : : gve_rx_queue_release(struct rte_eth_dev *dev, uint16_t qid);
401 : :
402 : : int
403 : : gve_tx_queue_start(struct rte_eth_dev *dev, uint16_t tx_queue_id);
404 : :
405 : : int
406 : : gve_rx_queue_start(struct rte_eth_dev *dev, uint16_t rx_queue_id);
407 : :
408 : : int
409 : : gve_tx_queue_stop(struct rte_eth_dev *dev, uint16_t tx_queue_id);
410 : :
411 : : int
412 : : gve_rx_queue_stop(struct rte_eth_dev *dev, uint16_t rx_queue_id);
413 : :
414 : : void
415 : : gve_stop_tx_queues(struct rte_eth_dev *dev);
416 : :
417 : : void
418 : : gve_stop_rx_queues(struct rte_eth_dev *dev);
419 : :
420 : : uint16_t
421 : : gve_rx_burst(void *rxq, struct rte_mbuf **rx_pkts, uint16_t nb_pkts);
422 : :
423 : : uint16_t
424 : : gve_tx_burst(void *txq, struct rte_mbuf **tx_pkts, uint16_t nb_pkts);
425 : :
426 : : void
427 : : gve_set_rx_function(struct rte_eth_dev *dev);
428 : :
429 : : void
430 : : gve_set_tx_function(struct rte_eth_dev *dev);
431 : :
432 : : struct gve_queue_page_list *
433 : : gve_setup_queue_page_list(struct gve_priv *priv, uint16_t queue_id, bool is_rx,
434 : : uint32_t num_pages);
435 : : int
436 : : gve_teardown_queue_page_list(struct gve_priv *priv,
437 : : struct gve_queue_page_list *qpl);
438 : :
439 : : /* Below functions are used for DQO */
440 : :
441 : : int
442 : : gve_rx_queue_setup_dqo(struct rte_eth_dev *dev, uint16_t queue_id,
443 : : uint16_t nb_desc, unsigned int socket_id,
444 : : const struct rte_eth_rxconf *conf,
445 : : struct rte_mempool *pool);
446 : : int
447 : : gve_tx_queue_setup_dqo(struct rte_eth_dev *dev, uint16_t queue_id,
448 : : uint16_t nb_desc, unsigned int socket_id,
449 : : const struct rte_eth_txconf *conf);
450 : :
451 : : void
452 : : gve_tx_queue_release_dqo(struct rte_eth_dev *dev, uint16_t qid);
453 : :
454 : : void
455 : : gve_rx_queue_release_dqo(struct rte_eth_dev *dev, uint16_t qid);
456 : :
457 : : int
458 : : gve_rx_queue_start_dqo(struct rte_eth_dev *dev, uint16_t rx_queue_id);
459 : :
460 : : int
461 : : gve_tx_queue_start_dqo(struct rte_eth_dev *dev, uint16_t tx_queue_id);
462 : :
463 : : int
464 : : gve_rx_queue_stop_dqo(struct rte_eth_dev *dev, uint16_t rx_queue_id);
465 : :
466 : : int
467 : : gve_tx_queue_stop_dqo(struct rte_eth_dev *dev, uint16_t tx_queue_id);
468 : :
469 : : void
470 : : gve_stop_tx_queues_dqo(struct rte_eth_dev *dev);
471 : :
472 : : void
473 : : gve_stop_rx_queues_dqo(struct rte_eth_dev *dev);
474 : :
475 : : uint16_t
476 : : gve_rx_burst_dqo(void *rxq, struct rte_mbuf **rx_pkts, uint16_t nb_pkts);
477 : :
478 : : uint16_t
479 : : gve_tx_burst_dqo(void *txq, struct rte_mbuf **tx_pkts, uint16_t nb_pkts);
480 : :
481 : : void
482 : : gve_set_rx_function_dqo(struct rte_eth_dev *dev);
483 : :
484 : : void
485 : : gve_set_tx_function_dqo(struct rte_eth_dev *dev);
486 : :
487 : : #endif /* _GVE_ETHDEV_H_ */
|