LCOV - code coverage report
Current view: top level - drivers/net/gve - gve_ethdev.h (source / functions) Hit Total Coverage
Test: Code coverage Lines: 0 5 0.0 %
Date: 2026-11-01 19:11:22 Functions: 0 0 -
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 0 32 0.0 %

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

Generated by: LCOV version 1.14