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

Generated by: LCOV version 1.14