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 : : uint64_t too_many_descs;
106 : : };
107 : :
108 : : struct gve_rx_stats {
109 : : uint64_t packets;
110 : : uint64_t bytes;
111 : : uint64_t errors;
112 : : uint64_t no_mbufs;
113 : : uint64_t no_mbufs_bulk;
114 : : uint64_t imissed;
115 : : };
116 : :
117 : : struct gve_xstats_name_offset {
118 : : char name[RTE_ETH_XSTATS_NAME_SIZE];
119 : : unsigned int offset;
120 : : };
121 : :
122 : : struct gve_tx_pkt {
123 : : struct rte_mbuf *mbuf;
124 : : int16_t next_avail_pkt; /* Entry in software ring for next free packet slot */
125 : : };
126 : :
127 : : struct gve_tx_queue {
128 : : volatile union gve_tx_desc *tx_desc_ring;
129 : : const struct rte_memzone *mz;
130 : : uint64_t tx_ring_phys_addr;
131 : : union {
132 : : struct rte_mbuf **sw_ring;
133 : : struct gve_tx_pkt *pkt_ring_dqo;
134 : : };
135 : : volatile rte_be32_t *qtx_tail;
136 : : volatile rte_be32_t *qtx_head;
137 : :
138 : : uint32_t tx_tail;
139 : : uint16_t nb_tx_desc;
140 : : uint16_t nb_complq_desc;
141 : : uint16_t nb_free;
142 : : uint16_t nb_used;
143 : : uint32_t next_to_clean;
144 : : uint16_t free_thresh;
145 : : uint16_t rs_thresh;
146 : :
147 : : /* Only valid for DQO_QPL queue format */
148 : : uint16_t sw_tail;
149 : : uint16_t sw_ntc;
150 : : uint16_t sw_nb_free;
151 : : uint32_t fifo_size;
152 : : uint32_t fifo_head;
153 : : uint32_t fifo_avail;
154 : : uint64_t fifo_base;
155 : : struct gve_queue_page_list *qpl;
156 : : struct gve_tx_iovec *iov_ring;
157 : :
158 : : /* stats items */
159 : : struct gve_tx_stats stats;
160 : :
161 : : uint16_t port_id;
162 : : uint16_t queue_id;
163 : :
164 : : uint16_t ntfy_id;
165 : : volatile rte_be32_t *ntfy_addr;
166 : :
167 : : struct gve_priv *hw;
168 : : const struct rte_memzone *qres_mz;
169 : : struct gve_queue_resources *qres;
170 : :
171 : : /* newly added for DQO */
172 : : volatile union gve_tx_desc_dqo *tx_ring;
173 : : struct gve_tx_compl_desc *compl_ring;
174 : :
175 : : /* List of free completion tags that map into sw_ring. */
176 : : int16_t free_compl_tags_head;
177 : : uint16_t num_free_compl_tags;
178 : :
179 : : const struct rte_memzone *compl_ring_mz;
180 : : uint64_t compl_ring_phys_addr;
181 : : uint32_t complq_tail;
182 : : uint16_t sw_size;
183 : : uint8_t cur_gen_bit;
184 : : uint32_t last_desc_cleaned;
185 : : void **txqs;
186 : : uint16_t re_cnt;
187 : :
188 : : /* Only valid for DQO_RDA queue format */
189 : : struct gve_tx_queue *complq;
190 : :
191 : : uint8_t is_gqi_qpl;
192 : : };
193 : :
194 : : struct gve_rx_ctx {
195 : : struct rte_mbuf *mbuf_head;
196 : : struct rte_mbuf *mbuf_tail;
197 : : uint16_t total_frags;
198 : : bool drop_pkt;
199 : : };
200 : :
201 : : struct gve_rx_queue {
202 : : volatile struct gve_rx_desc *rx_desc_ring;
203 : : volatile union gve_rx_data_slot *rx_data_ring;
204 : : const struct rte_memzone *mz;
205 : : const struct rte_memzone *data_mz;
206 : : uint64_t rx_ring_phys_addr;
207 : : struct rte_mbuf **sw_ring;
208 : : struct rte_mempool *mpool;
209 : : struct gve_rx_ctx ctx;
210 : :
211 : : uint16_t rx_tail;
212 : : uint16_t nb_rx_desc;
213 : : uint16_t expected_seqno; /* the next expected seqno */
214 : : uint16_t free_thresh;
215 : : uint16_t nb_rx_hold;
216 : : uint32_t next_avail;
217 : : uint32_t nb_avail;
218 : :
219 : : volatile rte_be32_t *qrx_tail;
220 : : volatile rte_be32_t *ntfy_addr;
221 : :
222 : : /* only valid for GQI_QPL queue format */
223 : : struct gve_queue_page_list *qpl;
224 : :
225 : : /* stats items */
226 : : struct gve_rx_stats stats;
227 : :
228 : : struct gve_priv *hw;
229 : : const struct rte_memzone *qres_mz;
230 : : struct gve_queue_resources *qres;
231 : :
232 : : uint16_t port_id;
233 : : uint16_t queue_id;
234 : : uint16_t ntfy_id;
235 : : uint16_t rx_buf_len;
236 : :
237 : : /* newly added for DQO */
238 : : volatile struct gve_rx_desc_dqo *rx_ring;
239 : : struct gve_rx_compl_desc_dqo *compl_ring;
240 : : const struct rte_memzone *compl_ring_mz;
241 : : uint64_t compl_ring_phys_addr;
242 : : uint8_t cur_gen_bit;
243 : : uint16_t bufq_tail;
244 : :
245 : : /* List of buffers which are known to be completed by the hardware. */
246 : : int16_t *completed_buf_list;
247 : : int16_t completed_buf_list_head;
248 : :
249 : : /* Only valid for DQO_RDA queue format */
250 : : struct gve_rx_queue *bufq;
251 : :
252 : : uint8_t is_gqi_qpl;
253 : : };
254 : :
255 : : struct gve_priv {
256 : : struct gve_irq_db *irq_dbs; /* array of num_ntfy_blks */
257 : : const struct rte_memzone *irq_dbs_mz;
258 : : uint32_t mgmt_msix_idx;
259 : : rte_be32_t *cnt_array; /* array of num_event_counters */
260 : : const struct rte_memzone *cnt_array_mz;
261 : :
262 : : uint16_t num_event_counters;
263 : :
264 : : /* TX ring size default and limits. */
265 : : uint16_t default_tx_desc_cnt;
266 : : uint16_t max_tx_desc_cnt;
267 : : uint16_t min_tx_desc_cnt;
268 : :
269 : : /* RX ring size default and limits. */
270 : : uint16_t default_rx_desc_cnt;
271 : : uint16_t max_rx_desc_cnt;
272 : : uint16_t min_rx_desc_cnt;
273 : :
274 : : uint16_t tx_pages_per_qpl;
275 : :
276 : : /* Only valid for DQO_RDA queue format */
277 : : uint16_t tx_compq_size; /* tx completion queue size */
278 : : uint16_t rx_bufq_size; /* rx buff queue size */
279 : :
280 : : uint64_t max_registered_pages;
281 : : uint64_t num_registered_pages; /* num pages registered with NIC */
282 : : uint16_t default_num_queues; /* default num queues to set up */
283 : : enum gve_queue_format queue_format; /* see enum gve_queue_format */
284 : : uint8_t enable_rsc;
285 : :
286 : : uint16_t max_nb_txq;
287 : : uint16_t max_nb_rxq;
288 : : uint32_t num_ntfy_blks; /* spilt between TX and RX so must be even */
289 : :
290 : : struct gve_registers __iomem *reg_bar0; /* see gve_register.h */
291 : : rte_be32_t __iomem *db_bar2; /* "array" of doorbells */
292 : : struct rte_pci_device *pci_dev;
293 : :
294 : : /* Admin queue - see gve_adminq.h*/
295 : : union gve_adminq_command *adminq;
296 : : struct gve_dma_mem adminq_dma_mem;
297 : : uint32_t adminq_mask; /* masks prod_cnt to adminq size */
298 : : uint32_t adminq_prod_cnt; /* free-running count of AQ cmds executed */
299 : : uint32_t adminq_cmd_fail; /* free-running count of AQ cmds failed */
300 : : uint32_t adminq_timeouts; /* free-running count of AQ cmds timeouts */
301 : : /* free-running count of per AQ cmd executed */
302 : : uint32_t adminq_describe_device_cnt;
303 : : uint32_t adminq_cfg_device_resources_cnt;
304 : : uint32_t adminq_register_page_list_cnt;
305 : : uint32_t adminq_unregister_page_list_cnt;
306 : : uint32_t adminq_create_tx_queue_cnt;
307 : : uint32_t adminq_create_rx_queue_cnt;
308 : : uint32_t adminq_destroy_tx_queue_cnt;
309 : : uint32_t adminq_destroy_rx_queue_cnt;
310 : : uint32_t adminq_dcfg_device_resources_cnt;
311 : : uint32_t adminq_cfg_rss_cnt;
312 : : uint32_t adminq_set_driver_parameter_cnt;
313 : : uint32_t adminq_report_stats_cnt;
314 : : uint32_t adminq_report_link_speed_cnt;
315 : : uint32_t adminq_get_ptype_map_cnt;
316 : : uint32_t adminq_verify_driver_compatibility_cnt;
317 : : volatile uint32_t state_flags;
318 : :
319 : : /* Gvnic device link speed from hypervisor. */
320 : : uint64_t link_speed;
321 : :
322 : : uint16_t max_mtu;
323 : : struct rte_ether_addr dev_addr; /* mac address */
324 : :
325 : : struct gve_tx_queue **txqs;
326 : : struct gve_rx_queue **rxqs;
327 : :
328 : : uint32_t stats_report_len;
329 : : const struct rte_memzone *stats_report_mem;
330 : : uint16_t stats_start_idx; /* start index of array of stats written by NIC */
331 : : uint16_t stats_end_idx; /* end index of array of stats written by NIC */
332 : :
333 : : struct gve_rss_config rss_config;
334 : : struct gve_ptype_lut *ptype_lut_dqo;
335 : : };
336 : :
337 : : static inline bool
338 : : gve_is_gqi(struct gve_priv *priv)
339 : : {
340 [ # # # # : 0 : return priv->queue_format == GVE_GQI_RDA_FORMAT ||
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# ]
341 : : priv->queue_format == GVE_GQI_QPL_FORMAT;
342 : : }
343 : :
344 : : static inline bool
345 : : gve_get_admin_queue_ok(struct gve_priv *priv)
346 : : {
347 : : return !!rte_bit_relaxed_get32(GVE_PRIV_FLAGS_ADMIN_QUEUE_OK,
348 : : &priv->state_flags);
349 : : }
350 : :
351 : : static inline void
352 : : gve_set_admin_queue_ok(struct gve_priv *priv)
353 : : {
354 : : rte_bit_relaxed_set32(GVE_PRIV_FLAGS_ADMIN_QUEUE_OK,
355 : : &priv->state_flags);
356 : : }
357 : :
358 : : static inline void
359 : : gve_clear_admin_queue_ok(struct gve_priv *priv)
360 : : {
361 : : rte_bit_relaxed_clear32(GVE_PRIV_FLAGS_ADMIN_QUEUE_OK,
362 : : &priv->state_flags);
363 : 0 : }
364 : :
365 : : static inline bool
366 : : gve_get_device_resources_ok(struct gve_priv *priv)
367 : : {
368 : : return !!rte_bit_relaxed_get32(GVE_PRIV_FLAGS_DEVICE_RESOURCES_OK,
369 : : &priv->state_flags);
370 : : }
371 : :
372 : : static inline void
373 : : gve_set_device_resources_ok(struct gve_priv *priv)
374 : : {
375 : : rte_bit_relaxed_set32(GVE_PRIV_FLAGS_DEVICE_RESOURCES_OK,
376 : : &priv->state_flags);
377 : : }
378 : :
379 : : static inline void
380 : : gve_clear_device_resources_ok(struct gve_priv *priv)
381 : : {
382 : : rte_bit_relaxed_clear32(GVE_PRIV_FLAGS_DEVICE_RESOURCES_OK,
383 : : &priv->state_flags);
384 : : }
385 : :
386 : : static inline bool
387 : : gve_get_device_rings_ok(struct gve_priv *priv)
388 : : {
389 : : return !!rte_bit_relaxed_get32(GVE_PRIV_FLAGS_DEVICE_RINGS_OK,
390 : : &priv->state_flags);
391 : : }
392 : :
393 : : static inline void
394 : : gve_set_device_rings_ok(struct gve_priv *priv)
395 : : {
396 : : rte_bit_relaxed_set32(GVE_PRIV_FLAGS_DEVICE_RINGS_OK,
397 : : &priv->state_flags);
398 : : }
399 : :
400 : : static inline void
401 : : gve_clear_device_rings_ok(struct gve_priv *priv)
402 : : {
403 : : rte_bit_relaxed_clear32(GVE_PRIV_FLAGS_DEVICE_RINGS_OK,
404 : : &priv->state_flags);
405 : : }
406 : :
407 : : int
408 : : gve_rx_queue_setup(struct rte_eth_dev *dev, uint16_t queue_id, uint16_t nb_desc,
409 : : unsigned int socket_id, const struct rte_eth_rxconf *conf,
410 : : struct rte_mempool *pool);
411 : : int
412 : : gve_tx_queue_setup(struct rte_eth_dev *dev, uint16_t queue_id, uint16_t nb_desc,
413 : : unsigned int socket_id, const struct rte_eth_txconf *conf);
414 : :
415 : : void
416 : : gve_tx_queue_release(struct rte_eth_dev *dev, uint16_t qid);
417 : :
418 : : void
419 : : gve_rx_queue_release(struct rte_eth_dev *dev, uint16_t qid);
420 : :
421 : : int
422 : : gve_tx_queue_start(struct rte_eth_dev *dev, uint16_t tx_queue_id);
423 : :
424 : : int
425 : : gve_rx_queue_start(struct rte_eth_dev *dev, uint16_t rx_queue_id);
426 : :
427 : : int
428 : : gve_tx_queue_stop(struct rte_eth_dev *dev, uint16_t tx_queue_id);
429 : :
430 : : int
431 : : gve_rx_queue_stop(struct rte_eth_dev *dev, uint16_t rx_queue_id);
432 : :
433 : : void
434 : : gve_stop_tx_queues(struct rte_eth_dev *dev);
435 : :
436 : : void
437 : : gve_stop_rx_queues(struct rte_eth_dev *dev);
438 : :
439 : : uint16_t
440 : : gve_rx_burst(void *rxq, struct rte_mbuf **rx_pkts, uint16_t nb_pkts);
441 : :
442 : : uint16_t
443 : : gve_tx_burst(void *txq, struct rte_mbuf **tx_pkts, uint16_t nb_pkts);
444 : :
445 : : void
446 : : gve_set_rx_function(struct rte_eth_dev *dev);
447 : :
448 : : void
449 : : gve_set_tx_function(struct rte_eth_dev *dev);
450 : :
451 : : struct gve_queue_page_list *
452 : : gve_setup_queue_page_list(struct gve_priv *priv, uint16_t queue_id, bool is_rx,
453 : : uint32_t num_pages);
454 : : int
455 : : gve_teardown_queue_page_list(struct gve_priv *priv,
456 : : struct gve_queue_page_list *qpl);
457 : :
458 : : /* Below functions are used for DQO */
459 : :
460 : : int
461 : : gve_rx_queue_setup_dqo(struct rte_eth_dev *dev, uint16_t queue_id,
462 : : uint16_t nb_desc, unsigned int socket_id,
463 : : const struct rte_eth_rxconf *conf,
464 : : struct rte_mempool *pool);
465 : : int
466 : : gve_tx_queue_setup_dqo(struct rte_eth_dev *dev, uint16_t queue_id,
467 : : uint16_t nb_desc, unsigned int socket_id,
468 : : const struct rte_eth_txconf *conf);
469 : :
470 : : void
471 : : gve_tx_queue_release_dqo(struct rte_eth_dev *dev, uint16_t qid);
472 : :
473 : : void
474 : : gve_rx_queue_release_dqo(struct rte_eth_dev *dev, uint16_t qid);
475 : :
476 : : int
477 : : gve_rx_queue_start_dqo(struct rte_eth_dev *dev, uint16_t rx_queue_id);
478 : :
479 : : int
480 : : gve_tx_queue_start_dqo(struct rte_eth_dev *dev, uint16_t tx_queue_id);
481 : :
482 : : int
483 : : gve_rx_queue_stop_dqo(struct rte_eth_dev *dev, uint16_t rx_queue_id);
484 : :
485 : : int
486 : : gve_tx_queue_stop_dqo(struct rte_eth_dev *dev, uint16_t tx_queue_id);
487 : :
488 : : void
489 : : gve_stop_tx_queues_dqo(struct rte_eth_dev *dev);
490 : :
491 : : void
492 : : gve_stop_rx_queues_dqo(struct rte_eth_dev *dev);
493 : :
494 : : uint16_t
495 : : gve_rx_burst_dqo(void *rxq, struct rte_mbuf **rx_pkts, uint16_t nb_pkts);
496 : :
497 : : uint16_t
498 : : gve_tx_burst_dqo(void *txq, struct rte_mbuf **tx_pkts, uint16_t nb_pkts);
499 : :
500 : : void
501 : : gve_set_rx_function_dqo(struct rte_eth_dev *dev);
502 : :
503 : : void
504 : : gve_set_tx_function_dqo(struct rte_eth_dev *dev);
505 : :
506 : : #endif /* _GVE_ETHDEV_H_ */
|