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