LCOV - code coverage report
Current view: top level - app/test - virtual_pmd.c (source / functions) Hit Total Coverage
Test: Code coverage Lines: 0 234 0.0 %
Date: 2026-10-01 18:19:24 Functions: 0 35 0.0 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 0 85 0.0 %

           Branch data     Line data    Source code
       1                 :            : /* SPDX-License-Identifier: BSD-3-Clause
       2                 :            :  * Copyright(c) 2010-2014 Intel Corporation
       3                 :            :  */
       4                 :            : 
       5                 :            : #define ALLOW_INTERNAL_API
       6                 :            : 
       7                 :            : #include <rte_mbuf.h>
       8                 :            : #include <rte_ethdev.h>
       9                 :            : #include <ethdev_driver.h>
      10                 :            : #include <rte_pci.h>
      11                 :            : #include <bus_pci_driver.h>
      12                 :            : #include <rte_malloc.h>
      13                 :            : #include <rte_memcpy.h>
      14                 :            : #include <rte_memory.h>
      15                 :            : #include <rte_ring.h>
      16                 :            : 
      17                 :            : #include "virtual_pmd.h"
      18                 :            : 
      19                 :            : #define MAX_PKT_BURST 512
      20                 :            : 
      21                 :            : static const char *virtual_ethdev_driver_name = "Virtual PMD";
      22                 :            : 
      23                 :            : struct virtual_ethdev_private {
      24                 :            :         struct eth_dev_ops dev_ops;
      25                 :            :         struct rte_eth_stats eth_stats;
      26                 :            : 
      27                 :            :         struct rte_ring *rx_queue;
      28                 :            :         struct rte_ring *tx_queue;
      29                 :            : 
      30                 :            :         int tx_burst_fail_count;
      31                 :            : };
      32                 :            : 
      33                 :            : struct virtual_ethdev_queue {
      34                 :            :         int port_id;
      35                 :            :         int queue_id;
      36                 :            : };
      37                 :            : 
      38                 :            : static int
      39                 :          0 : virtual_ethdev_start_success(struct rte_eth_dev *eth_dev __rte_unused)
      40                 :            : {
      41                 :          0 :         eth_dev->data->dev_started = 1;
      42                 :            : 
      43                 :          0 :         return 0;
      44                 :            : }
      45                 :            : 
      46                 :            : static int
      47                 :          0 : virtual_ethdev_start_fail(struct rte_eth_dev *eth_dev __rte_unused)
      48                 :            : {
      49                 :          0 :         eth_dev->data->dev_started = 0;
      50                 :            : 
      51                 :          0 :         return -1;
      52                 :            : }
      53                 :          0 : static int  virtual_ethdev_stop(struct rte_eth_dev *eth_dev __rte_unused)
      54                 :            : {
      55                 :          0 :         void *pkt = NULL;
      56                 :          0 :         struct virtual_ethdev_private *prv = eth_dev->data->dev_private;
      57                 :            : 
      58                 :          0 :         eth_dev->data->dev_link.link_status = RTE_ETH_LINK_DOWN;
      59                 :          0 :         eth_dev->data->dev_started = 0;
      60   [ #  #  #  #  :          0 :         while (rte_ring_dequeue(prv->rx_queue, &pkt) != -ENOENT)
                      # ]
      61                 :          0 :                 rte_pktmbuf_free(pkt);
      62                 :            : 
      63   [ #  #  #  #  :          0 :         while (rte_ring_dequeue(prv->tx_queue, &pkt) != -ENOENT)
                      # ]
      64                 :          0 :                 rte_pktmbuf_free(pkt);
      65                 :            : 
      66                 :          0 :         return 0;
      67                 :            : }
      68                 :            : 
      69                 :            : static int
      70                 :          0 : virtual_ethdev_close(struct rte_eth_dev *dev __rte_unused)
      71                 :            : {
      72                 :          0 :         return 0;
      73                 :            : }
      74                 :            : 
      75                 :            : static int
      76                 :          0 : virtual_ethdev_configure_success(struct rte_eth_dev *dev __rte_unused)
      77                 :            : {
      78                 :          0 :         return 0;
      79                 :            : }
      80                 :            : 
      81                 :            : static int
      82                 :          0 : virtual_ethdev_configure_fail(struct rte_eth_dev *dev __rte_unused)
      83                 :            : {
      84                 :          0 :         return -1;
      85                 :            : }
      86                 :            : 
      87                 :            : static int
      88                 :          0 : virtual_ethdev_info_get(struct rte_eth_dev *dev __rte_unused,
      89                 :            :                 struct rte_eth_dev_info *dev_info)
      90                 :            : {
      91                 :          0 :         dev_info->driver_name = virtual_ethdev_driver_name;
      92                 :          0 :         dev_info->max_mac_addrs = 1;
      93                 :            : 
      94                 :          0 :         dev_info->max_rx_pktlen = (uint32_t)2048;
      95                 :            : 
      96                 :          0 :         dev_info->max_rx_queues = (uint16_t)128;
      97                 :          0 :         dev_info->max_tx_queues = (uint16_t)512;
      98                 :            : 
      99                 :          0 :         dev_info->min_rx_bufsize = 0;
     100                 :            : 
     101                 :          0 :         return 0;
     102                 :            : }
     103                 :            : 
     104                 :            : static int
     105                 :          0 : virtual_ethdev_rx_queue_setup_success(struct rte_eth_dev *dev,
     106                 :            :                 uint16_t rx_queue_id, uint16_t nb_rx_desc __rte_unused,
     107                 :            :                 unsigned int socket_id,
     108                 :            :                 const struct rte_eth_rxconf *rx_conf __rte_unused,
     109                 :            :                 struct rte_mempool *mb_pool __rte_unused)
     110                 :            : {
     111                 :            :         struct virtual_ethdev_queue *rx_q;
     112                 :            : 
     113                 :          0 :         rx_q = (struct virtual_ethdev_queue *)rte_zmalloc_socket(NULL,
     114                 :            :                         sizeof(struct virtual_ethdev_queue), 0, socket_id);
     115                 :            : 
     116         [ #  # ]:          0 :         if (rx_q == NULL)
     117                 :            :                 return -1;
     118                 :            : 
     119                 :          0 :         rx_q->port_id = dev->data->port_id;
     120                 :          0 :         rx_q->queue_id = rx_queue_id;
     121                 :            : 
     122                 :          0 :         dev->data->rx_queues[rx_queue_id] = rx_q;
     123                 :            : 
     124                 :          0 :         return 0;
     125                 :            : }
     126                 :            : 
     127                 :            : static int
     128                 :          0 : virtual_ethdev_rx_queue_setup_fail(struct rte_eth_dev *dev __rte_unused,
     129                 :            :                 uint16_t rx_queue_id __rte_unused, uint16_t nb_rx_desc __rte_unused,
     130                 :            :                 unsigned int socket_id __rte_unused,
     131                 :            :                 const struct rte_eth_rxconf *rx_conf __rte_unused,
     132                 :            :                 struct rte_mempool *mb_pool __rte_unused)
     133                 :            : {
     134                 :          0 :         return -1;
     135                 :            : }
     136                 :            : 
     137                 :            : static int
     138                 :          0 : virtual_ethdev_tx_queue_setup_success(struct rte_eth_dev *dev,
     139                 :            :                 uint16_t tx_queue_id, uint16_t nb_tx_desc __rte_unused,
     140                 :            :                 unsigned int socket_id,
     141                 :            :                 const struct rte_eth_txconf *tx_conf __rte_unused)
     142                 :            : {
     143                 :            :         struct virtual_ethdev_queue *tx_q;
     144                 :            : 
     145                 :          0 :         tx_q = (struct virtual_ethdev_queue *)rte_zmalloc_socket(NULL,
     146                 :            :                         sizeof(struct virtual_ethdev_queue), 0, socket_id);
     147                 :            : 
     148         [ #  # ]:          0 :         if (tx_q == NULL)
     149                 :            :                 return -1;
     150                 :            : 
     151                 :          0 :         tx_q->port_id = dev->data->port_id;
     152                 :          0 :         tx_q->queue_id = tx_queue_id;
     153                 :            : 
     154                 :          0 :         dev->data->tx_queues[tx_queue_id] = tx_q;
     155                 :            : 
     156                 :          0 :         return 0;
     157                 :            : }
     158                 :            : 
     159                 :            : static int
     160                 :          0 : virtual_ethdev_tx_queue_setup_fail(struct rte_eth_dev *dev __rte_unused,
     161                 :            :                 uint16_t tx_queue_id __rte_unused, uint16_t nb_tx_desc __rte_unused,
     162                 :            :                 unsigned int socket_id __rte_unused,
     163                 :            :                 const struct rte_eth_txconf *tx_conf __rte_unused)
     164                 :            : {
     165                 :          0 :         return -1;
     166                 :            : }
     167                 :            : 
     168                 :            : static int
     169                 :          0 : virtual_ethdev_link_update_success(struct rte_eth_dev *bonding_eth_dev,
     170                 :            :                 int wait_to_complete __rte_unused)
     171                 :            : {
     172         [ #  # ]:          0 :         if (!bonding_eth_dev->data->dev_started)
     173                 :          0 :                 bonding_eth_dev->data->dev_link.link_status = RTE_ETH_LINK_DOWN;
     174                 :            : 
     175                 :          0 :         return 0;
     176                 :            : }
     177                 :            : 
     178                 :            : static int
     179                 :          0 : virtual_ethdev_link_update_fail(struct rte_eth_dev *bonding_eth_dev __rte_unused,
     180                 :            :                 int wait_to_complete __rte_unused)
     181                 :            : {
     182                 :          0 :         return -1;
     183                 :            : }
     184                 :            : 
     185                 :            : static int
     186                 :          0 : virtual_ethdev_stats_get(struct rte_eth_dev *dev, struct rte_eth_stats *stats,
     187                 :            :         struct eth_queue_stats *qstats __rte_unused)
     188                 :            : {
     189                 :          0 :         struct virtual_ethdev_private *dev_private = dev->data->dev_private;
     190                 :            : 
     191         [ #  # ]:          0 :         if (stats)
     192                 :            :                 rte_memcpy(stats, &dev_private->eth_stats, sizeof(*stats));
     193                 :            : 
     194                 :          0 :         return 0;
     195                 :            : }
     196                 :            : 
     197                 :            : static int
     198                 :          0 : virtual_ethdev_stats_reset(struct rte_eth_dev *dev)
     199                 :            : {
     200                 :          0 :         struct virtual_ethdev_private *dev_private = dev->data->dev_private;
     201                 :          0 :         void *pkt = NULL;
     202                 :            : 
     203   [ #  #  #  #  :          0 :         while (rte_ring_dequeue(dev_private->tx_queue, &pkt) == -ENOBUFS)
                      # ]
     204                 :            :                         rte_pktmbuf_free(pkt);
     205                 :            : 
     206                 :            :         /* Reset internal statistics */
     207                 :          0 :         memset(&dev_private->eth_stats, 0, sizeof(dev_private->eth_stats));
     208                 :            : 
     209                 :          0 :         return 0;
     210                 :            : }
     211                 :            : 
     212                 :            : static int
     213                 :          0 : virtual_ethdev_promiscuous_mode_enable(struct rte_eth_dev *dev __rte_unused)
     214                 :            : {
     215                 :          0 :         return 0;
     216                 :            : }
     217                 :            : 
     218                 :            : static int
     219                 :          0 : virtual_ethdev_promiscuous_mode_disable(struct rte_eth_dev *dev __rte_unused)
     220                 :            : {
     221                 :          0 :         return 0;
     222                 :            : }
     223                 :            : 
     224                 :            : static int
     225                 :          0 : virtual_ethdev_mac_address_set(__rte_unused struct rte_eth_dev *dev,
     226                 :            :                                __rte_unused struct rte_ether_addr *addr)
     227                 :            : {
     228                 :          0 :         return 0;
     229                 :            : }
     230                 :            : 
     231                 :            : static const struct eth_dev_ops virtual_ethdev_default_dev_ops = {
     232                 :            :         .dev_configure = virtual_ethdev_configure_success,
     233                 :            :         .dev_start = virtual_ethdev_start_success,
     234                 :            :         .dev_stop = virtual_ethdev_stop,
     235                 :            :         .dev_close = virtual_ethdev_close,
     236                 :            :         .dev_infos_get = virtual_ethdev_info_get,
     237                 :            :         .rx_queue_setup = virtual_ethdev_rx_queue_setup_success,
     238                 :            :         .tx_queue_setup = virtual_ethdev_tx_queue_setup_success,
     239                 :            :         .link_update = virtual_ethdev_link_update_success,
     240                 :            :         .mac_addr_set = virtual_ethdev_mac_address_set,
     241                 :            :         .stats_get = virtual_ethdev_stats_get,
     242                 :            :         .stats_reset = virtual_ethdev_stats_reset,
     243                 :            :         .promiscuous_enable = virtual_ethdev_promiscuous_mode_enable,
     244                 :            :         .promiscuous_disable = virtual_ethdev_promiscuous_mode_disable
     245                 :            : };
     246                 :            : 
     247                 :            : void
     248                 :          0 : virtual_ethdev_start_fn_set_success(uint16_t port_id, uint8_t success)
     249                 :            : {
     250                 :          0 :         struct rte_eth_dev *dev = &rte_eth_devices[port_id];
     251                 :          0 :         struct virtual_ethdev_private *dev_private = dev->data->dev_private;
     252                 :            :         struct eth_dev_ops *dev_ops = &dev_private->dev_ops;
     253                 :            : 
     254         [ #  # ]:          0 :         if (success)
     255                 :          0 :                 dev_ops->dev_start = virtual_ethdev_start_success;
     256                 :            :         else
     257                 :          0 :                 dev_ops->dev_start = virtual_ethdev_start_fail;
     258                 :            : 
     259                 :          0 : }
     260                 :            : 
     261                 :            : void
     262                 :          0 : virtual_ethdev_configure_fn_set_success(uint16_t port_id, uint8_t success)
     263                 :            : {
     264                 :          0 :         struct rte_eth_dev *dev = &rte_eth_devices[port_id];
     265                 :          0 :         struct virtual_ethdev_private *dev_private = dev->data->dev_private;
     266                 :            :         struct eth_dev_ops *dev_ops = &dev_private->dev_ops;
     267                 :            : 
     268         [ #  # ]:          0 :         if (success)
     269                 :          0 :                 dev_ops->dev_configure = virtual_ethdev_configure_success;
     270                 :            :         else
     271                 :          0 :                 dev_ops->dev_configure = virtual_ethdev_configure_fail;
     272                 :          0 : }
     273                 :            : 
     274                 :            : void
     275                 :          0 : virtual_ethdev_rx_queue_setup_fn_set_success(uint16_t port_id, uint8_t success)
     276                 :            : {
     277                 :          0 :         struct rte_eth_dev *dev = &rte_eth_devices[port_id];
     278                 :          0 :         struct virtual_ethdev_private *dev_private = dev->data->dev_private;
     279                 :            :         struct eth_dev_ops *dev_ops = &dev_private->dev_ops;
     280                 :            : 
     281         [ #  # ]:          0 :         if (success)
     282                 :          0 :                 dev_ops->rx_queue_setup = virtual_ethdev_rx_queue_setup_success;
     283                 :            :         else
     284                 :          0 :                 dev_ops->rx_queue_setup = virtual_ethdev_rx_queue_setup_fail;
     285                 :          0 : }
     286                 :            : 
     287                 :            : void
     288                 :          0 : virtual_ethdev_tx_queue_setup_fn_set_success(uint16_t port_id, uint8_t success)
     289                 :            : {
     290                 :          0 :         struct rte_eth_dev *dev = &rte_eth_devices[port_id];
     291                 :          0 :         struct virtual_ethdev_private *dev_private = dev->data->dev_private;
     292                 :            :         struct eth_dev_ops *dev_ops = &dev_private->dev_ops;
     293                 :            : 
     294         [ #  # ]:          0 :         if (success)
     295                 :          0 :                 dev_ops->tx_queue_setup = virtual_ethdev_tx_queue_setup_success;
     296                 :            :         else
     297                 :          0 :                 dev_ops->tx_queue_setup = virtual_ethdev_tx_queue_setup_fail;
     298                 :          0 : }
     299                 :            : 
     300                 :            : void
     301                 :          0 : virtual_ethdev_link_update_fn_set_success(uint16_t port_id, uint8_t success)
     302                 :            : {
     303                 :          0 :         struct rte_eth_dev *dev = &rte_eth_devices[port_id];
     304                 :          0 :         struct virtual_ethdev_private *dev_private = dev->data->dev_private;
     305                 :            :         struct eth_dev_ops *dev_ops = &dev_private->dev_ops;
     306                 :            : 
     307         [ #  # ]:          0 :         if (success)
     308                 :          0 :                 dev_ops->link_update = virtual_ethdev_link_update_success;
     309                 :            :         else
     310                 :          0 :                 dev_ops->link_update = virtual_ethdev_link_update_fail;
     311                 :          0 : }
     312                 :            : 
     313                 :            : 
     314                 :            : static uint16_t
     315                 :          0 : virtual_ethdev_rx_burst_success(void *queue __rte_unused,
     316                 :            :                                                          struct rte_mbuf **bufs,
     317                 :            :                                                          uint16_t nb_pkts)
     318                 :            : {
     319                 :            :         struct rte_eth_dev *vrtl_eth_dev;
     320                 :            :         struct virtual_ethdev_queue *pq_map;
     321                 :            :         struct virtual_ethdev_private *dev_private;
     322                 :            : 
     323                 :            :         int rx_count, i;
     324                 :            : 
     325                 :            :         pq_map = (struct virtual_ethdev_queue *)queue;
     326                 :          0 :         vrtl_eth_dev = &rte_eth_devices[pq_map->port_id];
     327                 :          0 :         dev_private = vrtl_eth_dev->data->dev_private;
     328                 :            : 
     329   [ #  #  #  #  :          0 :         rx_count = rte_ring_dequeue_burst(dev_private->rx_queue, (void **) bufs,
                      # ]
     330                 :            :                         nb_pkts, NULL);
     331                 :            : 
     332                 :            :         /* increments ipackets count */
     333                 :          0 :         dev_private->eth_stats.ipackets += rx_count;
     334                 :            : 
     335                 :            :         /* increments ibytes count */
     336         [ #  # ]:          0 :         for (i = 0; i < rx_count; i++)
     337                 :          0 :                 dev_private->eth_stats.ibytes += rte_pktmbuf_pkt_len(bufs[i]);
     338                 :            : 
     339                 :          0 :         return rx_count;
     340                 :            : }
     341                 :            : 
     342                 :            : static uint16_t
     343                 :          0 : virtual_ethdev_rx_burst_fail(void *queue __rte_unused,
     344                 :            :                                                          struct rte_mbuf **bufs __rte_unused,
     345                 :            :                                                          uint16_t nb_pkts __rte_unused)
     346                 :            : {
     347                 :          0 :         return 0;
     348                 :            : }
     349                 :            : 
     350                 :            : static uint16_t
     351                 :          0 : virtual_ethdev_tx_burst_success(void *queue, struct rte_mbuf **bufs,
     352                 :            :                 uint16_t nb_pkts)
     353                 :            : {
     354                 :            :         struct virtual_ethdev_queue *tx_q = queue;
     355                 :            : 
     356                 :            :         struct rte_eth_dev *vrtl_eth_dev;
     357                 :            :         struct virtual_ethdev_private *dev_private;
     358                 :            : 
     359                 :            :         int i;
     360                 :            : 
     361                 :          0 :         vrtl_eth_dev = &rte_eth_devices[tx_q->port_id];
     362                 :          0 :         dev_private = vrtl_eth_dev->data->dev_private;
     363                 :            : 
     364         [ #  # ]:          0 :         if (!vrtl_eth_dev->data->dev_link.link_status)
     365                 :            :                 nb_pkts = 0;
     366                 :            :         else
     367   [ #  #  #  #  :          0 :                 nb_pkts = rte_ring_enqueue_burst(dev_private->tx_queue, (void **)bufs,
                      # ]
     368                 :            :                                 nb_pkts, NULL);
     369                 :            : 
     370                 :            :         /* increment opacket count */
     371                 :          0 :         dev_private->eth_stats.opackets += nb_pkts;
     372                 :            : 
     373                 :            :         /* increment obytes count */
     374         [ #  # ]:          0 :         for (i = 0; i < nb_pkts; i++)
     375                 :          0 :                 dev_private->eth_stats.obytes += rte_pktmbuf_pkt_len(bufs[i]);
     376                 :            : 
     377                 :          0 :         return nb_pkts;
     378                 :            : }
     379                 :            : 
     380                 :            : static uint16_t
     381                 :          0 : virtual_ethdev_tx_burst_fail(void *queue, struct rte_mbuf **bufs,
     382                 :            :                 uint16_t nb_pkts)
     383                 :            : {
     384                 :            :         struct rte_eth_dev *vrtl_eth_dev = NULL;
     385                 :            :         struct virtual_ethdev_queue *tx_q = NULL;
     386                 :            :         struct virtual_ethdev_private *dev_private = NULL;
     387                 :            : 
     388                 :            :         int i;
     389                 :            : 
     390                 :            :         tx_q = queue;
     391                 :          0 :         vrtl_eth_dev = &rte_eth_devices[tx_q->port_id];
     392                 :          0 :         dev_private = vrtl_eth_dev->data->dev_private;
     393                 :            : 
     394         [ #  # ]:          0 :         if (dev_private->tx_burst_fail_count < nb_pkts) {
     395                 :          0 :                 int successfully_txd = nb_pkts - dev_private->tx_burst_fail_count;
     396                 :            : 
     397                 :            :                 /* increment opacket count */
     398                 :          0 :                 dev_private->eth_stats.opackets += successfully_txd;
     399                 :            : 
     400                 :            :                 /* free packets in burst */
     401         [ #  # ]:          0 :                 for (i = 0; i < successfully_txd; i++) {
     402                 :            :                         /* free packets in burst */
     403                 :          0 :                         rte_pktmbuf_free(bufs[i]);
     404                 :            : 
     405                 :          0 :                         bufs[i] = NULL;
     406                 :            :                 }
     407                 :            : 
     408                 :          0 :                 return successfully_txd;
     409                 :            :         }
     410                 :            : 
     411                 :            :         return 0;
     412                 :            : }
     413                 :            : 
     414                 :            : 
     415                 :            : void
     416                 :          0 : virtual_ethdev_rx_burst_fn_set_success(uint16_t port_id, uint8_t success)
     417                 :            : {
     418                 :          0 :         struct rte_eth_dev *vrtl_eth_dev = &rte_eth_devices[port_id];
     419                 :            : 
     420                 :          0 :         rte_eth_dev_stop(port_id);
     421                 :            : 
     422         [ #  # ]:          0 :         if (success)
     423                 :          0 :                 vrtl_eth_dev->rx_pkt_burst = virtual_ethdev_rx_burst_success;
     424                 :            :         else
     425                 :          0 :                 vrtl_eth_dev->rx_pkt_burst = virtual_ethdev_rx_burst_fail;
     426                 :            : 
     427                 :          0 :         rte_eth_dev_start(port_id);
     428                 :          0 : }
     429                 :            : 
     430                 :            : 
     431                 :            : void
     432                 :          0 : virtual_ethdev_tx_burst_fn_set_success(uint16_t port_id, uint8_t success)
     433                 :            : {
     434                 :            :         struct virtual_ethdev_private *dev_private = NULL;
     435                 :          0 :         struct rte_eth_dev *vrtl_eth_dev = &rte_eth_devices[port_id];
     436                 :            : 
     437                 :          0 :         rte_eth_dev_stop(port_id);
     438                 :          0 :         dev_private = vrtl_eth_dev->data->dev_private;
     439                 :            : 
     440         [ #  # ]:          0 :         if (success)
     441                 :          0 :                 vrtl_eth_dev->tx_pkt_burst = virtual_ethdev_tx_burst_success;
     442                 :            :         else
     443                 :          0 :                 vrtl_eth_dev->tx_pkt_burst = virtual_ethdev_tx_burst_fail;
     444                 :            : 
     445                 :          0 :         dev_private->tx_burst_fail_count = 0;
     446                 :          0 :         rte_eth_dev_start(port_id);
     447                 :          0 : }
     448                 :            : 
     449                 :            : void
     450                 :          0 : virtual_ethdev_tx_burst_fn_set_tx_pkt_fail_count(uint16_t port_id,
     451                 :            :                 uint8_t packet_fail_count)
     452                 :            : {
     453                 :            :         struct virtual_ethdev_private *dev_private = NULL;
     454                 :          0 :         struct rte_eth_dev *vrtl_eth_dev = &rte_eth_devices[port_id];
     455                 :            : 
     456                 :          0 :         dev_private = vrtl_eth_dev->data->dev_private;
     457                 :          0 :         dev_private->tx_burst_fail_count = packet_fail_count;
     458                 :          0 : }
     459                 :            : 
     460                 :            : void
     461                 :          0 : virtual_ethdev_set_link_status(uint16_t port_id, uint8_t link_status)
     462                 :            : {
     463                 :          0 :         struct rte_eth_dev *vrtl_eth_dev = &rte_eth_devices[port_id];
     464                 :            : 
     465                 :          0 :         vrtl_eth_dev->data->dev_link.link_status = link_status;
     466                 :          0 : }
     467                 :            : 
     468                 :            : void
     469                 :          0 : virtual_ethdev_simulate_link_status_interrupt(uint16_t port_id,
     470                 :            :                 uint8_t link_status)
     471                 :            : {
     472                 :          0 :         struct rte_eth_dev *vrtl_eth_dev = &rte_eth_devices[port_id];
     473                 :            : 
     474                 :          0 :         vrtl_eth_dev->data->dev_link.link_status = link_status;
     475                 :            : 
     476                 :          0 :         rte_eth_dev_callback_process(vrtl_eth_dev, RTE_ETH_EVENT_INTR_LSC,
     477                 :            :                                      NULL);
     478                 :          0 : }
     479                 :            : 
     480                 :            : int
     481                 :          0 : virtual_ethdev_add_mbufs_to_rx_queue(uint16_t port_id,
     482                 :            :                 struct rte_mbuf **pkt_burst, int burst_length)
     483                 :            : {
     484                 :          0 :         struct rte_eth_dev *vrtl_eth_dev = &rte_eth_devices[port_id];
     485                 :          0 :         struct virtual_ethdev_private *dev_private =
     486                 :          0 :                         vrtl_eth_dev->data->dev_private;
     487                 :            : 
     488   [ #  #  #  #  :          0 :         return rte_ring_enqueue_burst(dev_private->rx_queue, (void **)pkt_burst,
                      # ]
     489                 :            :                         burst_length, NULL);
     490                 :            : }
     491                 :            : 
     492                 :            : int
     493                 :          0 : virtual_ethdev_get_mbufs_from_tx_queue(uint16_t port_id,
     494                 :            :                 struct rte_mbuf **pkt_burst, int burst_length)
     495                 :            : {
     496                 :            :         struct virtual_ethdev_private *dev_private;
     497                 :          0 :         struct rte_eth_dev *vrtl_eth_dev = &rte_eth_devices[port_id];
     498                 :            : 
     499                 :          0 :         dev_private = vrtl_eth_dev->data->dev_private;
     500   [ #  #  #  #  :          0 :         return rte_ring_dequeue_burst(dev_private->tx_queue, (void **)pkt_burst,
                      # ]
     501                 :            :                 burst_length, NULL);
     502                 :            : }
     503                 :            : 
     504                 :            : 
     505                 :            : int
     506                 :          0 : virtual_ethdev_create(const char *name, struct rte_ether_addr *mac_addr,
     507                 :            :                 uint8_t socket_id, uint8_t isr_support)
     508                 :            : {
     509                 :            :         struct rte_pci_device *pci_dev = NULL;
     510                 :            :         struct rte_eth_dev *eth_dev = NULL;
     511                 :            :         struct rte_pci_driver *pci_drv = NULL;
     512                 :            :         struct rte_pci_id *id_table = NULL;
     513                 :            :         struct virtual_ethdev_private *dev_private = NULL;
     514                 :            :         char name_buf[RTE_RING_NAMESIZE];
     515                 :            : 
     516                 :            : 
     517                 :            :         /* now do all data allocation - for eth_dev structure, dummy pci driver
     518                 :            :          * and internal (dev_private) data
     519                 :            :          */
     520                 :            : 
     521                 :          0 :         pci_dev = rte_zmalloc_socket(name, sizeof(*pci_dev), 0, socket_id);
     522         [ #  # ]:          0 :         if (pci_dev == NULL)
     523                 :          0 :                 goto err;
     524                 :            : 
     525                 :          0 :         pci_drv = rte_zmalloc_socket(name, sizeof(*pci_drv), 0, socket_id);
     526         [ #  # ]:          0 :         if (pci_drv == NULL)
     527                 :          0 :                 goto err;
     528                 :            : 
     529                 :          0 :         id_table = rte_zmalloc_socket(name, sizeof(*id_table), 0, socket_id);
     530         [ #  # ]:          0 :         if (id_table == NULL)
     531                 :          0 :                 goto err;
     532                 :          0 :         id_table->device_id = 0xBEEF;
     533                 :            : 
     534                 :          0 :         dev_private = rte_zmalloc_socket(name, sizeof(*dev_private), 0, socket_id);
     535         [ #  # ]:          0 :         if (dev_private == NULL)
     536                 :          0 :                 goto err;
     537                 :            : 
     538                 :            :         snprintf(name_buf, sizeof(name_buf), "%s_rxQ", name);
     539                 :          0 :         dev_private->rx_queue = rte_ring_create(name_buf, MAX_PKT_BURST, socket_id,
     540                 :            :                         0);
     541         [ #  # ]:          0 :         if (dev_private->rx_queue == NULL)
     542                 :          0 :                 goto err;
     543                 :            : 
     544                 :            :         snprintf(name_buf, sizeof(name_buf), "%s_txQ", name);
     545                 :          0 :         dev_private->tx_queue = rte_ring_create(name_buf, MAX_PKT_BURST, socket_id,
     546                 :            :                         0);
     547         [ #  # ]:          0 :         if (dev_private->tx_queue == NULL)
     548                 :          0 :                 goto err;
     549                 :            : 
     550                 :            :         /* reserve an ethdev entry */
     551                 :          0 :         eth_dev = rte_eth_dev_allocate(name);
     552         [ #  # ]:          0 :         if (eth_dev == NULL)
     553                 :          0 :                 goto err;
     554                 :            : 
     555                 :          0 :         pci_dev->device.numa_node = socket_id;
     556                 :          0 :         pci_dev->device.name = eth_dev->data->name;
     557                 :          0 :         pci_drv->driver.name = virtual_ethdev_driver_name;
     558                 :          0 :         pci_drv->id_table = id_table;
     559                 :            : 
     560         [ #  # ]:          0 :         if (isr_support)
     561                 :          0 :                 pci_drv->drv_flags |= RTE_PCI_DRV_INTR_LSC;
     562                 :            :         else
     563                 :          0 :                 pci_drv->drv_flags &= ~RTE_PCI_DRV_INTR_LSC;
     564                 :            : 
     565                 :            : 
     566                 :          0 :         eth_dev->device = &pci_dev->device;
     567                 :          0 :         eth_dev->device->driver = &pci_drv->driver;
     568                 :            : 
     569                 :          0 :         eth_dev->data->nb_rx_queues = (uint16_t)1;
     570                 :          0 :         eth_dev->data->nb_tx_queues = (uint16_t)1;
     571                 :            : 
     572                 :          0 :         eth_dev->data->dev_link.link_status = RTE_ETH_LINK_DOWN;
     573                 :          0 :         eth_dev->data->dev_link.link_speed = RTE_ETH_SPEED_NUM_10G;
     574                 :          0 :         eth_dev->data->dev_link.link_duplex = RTE_ETH_LINK_FULL_DUPLEX;
     575                 :            : 
     576                 :          0 :         eth_dev->data->mac_addrs = rte_zmalloc(name, RTE_ETHER_ADDR_LEN, 0);
     577         [ #  # ]:          0 :         if (eth_dev->data->mac_addrs == NULL)
     578                 :          0 :                 goto err;
     579                 :            : 
     580                 :            :         memcpy(eth_dev->data->mac_addrs, mac_addr,
     581                 :            :                         sizeof(*eth_dev->data->mac_addrs));
     582                 :            : 
     583                 :          0 :         eth_dev->data->dev_started = 0;
     584                 :          0 :         eth_dev->data->promiscuous = 0;
     585                 :          0 :         eth_dev->data->scattered_rx = 0;
     586                 :          0 :         eth_dev->data->all_multicast = 0;
     587                 :            : 
     588                 :          0 :         eth_dev->data->dev_private = dev_private;
     589                 :            : 
     590                 :            :         /* Copy default device operation functions */
     591                 :          0 :         dev_private->dev_ops = virtual_ethdev_default_dev_ops;
     592                 :          0 :         eth_dev->dev_ops = &dev_private->dev_ops;
     593                 :            : 
     594                 :          0 :         pci_dev->device.driver = &pci_drv->driver;
     595                 :          0 :         eth_dev->device = &pci_dev->device;
     596                 :            : 
     597                 :          0 :         eth_dev->rx_pkt_burst = virtual_ethdev_rx_burst_success;
     598                 :          0 :         eth_dev->tx_pkt_burst = virtual_ethdev_tx_burst_success;
     599                 :            : 
     600                 :          0 :         rte_eth_dev_probing_finish(eth_dev);
     601                 :            : 
     602                 :          0 :         return eth_dev->data->port_id;
     603                 :            : 
     604                 :          0 : err:
     605                 :          0 :         rte_free(pci_dev);
     606                 :          0 :         rte_free(pci_drv);
     607                 :          0 :         rte_free(id_table);
     608                 :          0 :         rte_free(dev_private);
     609                 :            : 
     610                 :          0 :         return -1;
     611                 :            : }

Generated by: LCOV version 1.14