LCOV - code coverage report
Current view: top level - drivers/net/thunderx - nicvf_ethdev.c (source / functions) Hit Total Coverage
Test: Code coverage Lines: 4 958 0.4 %
Date: 2024-01-22 16:26:08 Functions: 4 66 6.1 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 3 622 0.5 %

           Branch data     Line data    Source code
       1                 :            : /* SPDX-License-Identifier: BSD-3-Clause
       2                 :            :  * Copyright(c) 2016 Cavium, Inc
       3                 :            :  */
       4                 :            : 
       5                 :            : #include <assert.h>
       6                 :            : #include <stdio.h>
       7                 :            : #include <stdbool.h>
       8                 :            : #include <errno.h>
       9                 :            : #include <stdint.h>
      10                 :            : #include <string.h>
      11                 :            : #include <unistd.h>
      12                 :            : #include <stdarg.h>
      13                 :            : #include <inttypes.h>
      14                 :            : #include <netinet/in.h>
      15                 :            : #include <sys/queue.h>
      16                 :            : 
      17                 :            : #include <rte_alarm.h>
      18                 :            : #include <rte_branch_prediction.h>
      19                 :            : #include <rte_byteorder.h>
      20                 :            : #include <rte_common.h>
      21                 :            : #include <rte_cycles.h>
      22                 :            : #include <rte_debug.h>
      23                 :            : #include <dev_driver.h>
      24                 :            : #include <rte_eal.h>
      25                 :            : #include <rte_ether.h>
      26                 :            : #include <ethdev_driver.h>
      27                 :            : #include <ethdev_pci.h>
      28                 :            : #include <rte_interrupts.h>
      29                 :            : #include <rte_log.h>
      30                 :            : #include <rte_memory.h>
      31                 :            : #include <rte_memzone.h>
      32                 :            : #include <rte_malloc.h>
      33                 :            : #include <rte_random.h>
      34                 :            : #include <rte_pci.h>
      35                 :            : #include <bus_pci_driver.h>
      36                 :            : #include <rte_tailq.h>
      37                 :            : #include <rte_devargs.h>
      38                 :            : #include <rte_kvargs.h>
      39                 :            : 
      40                 :            : #include "base/nicvf_plat.h"
      41                 :            : 
      42                 :            : #include "nicvf_ethdev.h"
      43                 :            : #include "nicvf_rxtx.h"
      44                 :            : #include "nicvf_svf.h"
      45                 :            : #include "nicvf_logs.h"
      46                 :            : 
      47                 :            : static int nicvf_dev_stop(struct rte_eth_dev *dev);
      48                 :            : static void nicvf_dev_stop_cleanup(struct rte_eth_dev *dev, bool cleanup);
      49                 :            : static void nicvf_vf_stop(struct rte_eth_dev *dev, struct nicvf *nic,
      50                 :            :                           bool cleanup);
      51                 :            : static int nicvf_vlan_offload_config(struct rte_eth_dev *dev, int mask);
      52                 :            : static int nicvf_vlan_offload_set(struct rte_eth_dev *dev, int mask);
      53                 :            : 
      54         [ -  + ]:        235 : RTE_LOG_REGISTER_SUFFIX(nicvf_logtype_mbox, mbox, NOTICE);
      55         [ -  + ]:        235 : RTE_LOG_REGISTER_SUFFIX(nicvf_logtype_init, init, NOTICE);
      56         [ -  + ]:        235 : RTE_LOG_REGISTER_SUFFIX(nicvf_logtype_driver, driver, NOTICE);
      57                 :            : 
      58                 :            : #define NICVF_QLM_MODE_SGMII  7
      59                 :            : #define NICVF_QLM_MODE_XFI   12
      60                 :            : 
      61                 :            : enum nicvf_link_speed {
      62                 :            :         NICVF_LINK_SPEED_SGMII,
      63                 :            :         NICVF_LINK_SPEED_XAUI,
      64                 :            :         NICVF_LINK_SPEED_RXAUI,
      65                 :            :         NICVF_LINK_SPEED_10G_R,
      66                 :            :         NICVF_LINK_SPEED_40G_R,
      67                 :            :         NICVF_LINK_SPEED_RESERVE1,
      68                 :            :         NICVF_LINK_SPEED_QSGMII,
      69                 :            :         NICVF_LINK_SPEED_RESERVE2,
      70                 :            :         NICVF_LINK_SPEED_UNKNOWN = 255
      71                 :            : };
      72                 :            : 
      73                 :            : static inline uint32_t
      74                 :            : nicvf_parse_link_speeds(uint32_t link_speeds)
      75                 :            : {
      76                 :            :         uint32_t link_speed = NICVF_LINK_SPEED_UNKNOWN;
      77                 :            : 
      78         [ #  # ]:          0 :         if (link_speeds & RTE_ETH_LINK_SPEED_40G)
      79                 :            :                 link_speed = NICVF_LINK_SPEED_40G_R;
      80                 :            : 
      81         [ #  # ]:          0 :         if (link_speeds & RTE_ETH_LINK_SPEED_10G) {
      82                 :            :                 link_speed  = NICVF_LINK_SPEED_XAUI;
      83                 :            :                 link_speed |= NICVF_LINK_SPEED_RXAUI;
      84                 :            :                 link_speed |= NICVF_LINK_SPEED_10G_R;
      85                 :            :         }
      86                 :            : 
      87         [ #  # ]:          0 :         if (link_speeds & RTE_ETH_LINK_SPEED_5G)
      88                 :            :                 link_speed = NICVF_LINK_SPEED_QSGMII;
      89                 :            : 
      90         [ #  # ]:          0 :         if (link_speeds & RTE_ETH_LINK_SPEED_1G)
      91                 :            :                 link_speed = NICVF_LINK_SPEED_SGMII;
      92                 :            : 
      93                 :            :         return link_speed;
      94                 :            : }
      95                 :            : 
      96                 :            : static inline uint8_t
      97                 :            : nicvf_parse_eth_link_duplex(uint32_t link_speeds)
      98                 :            : {
      99                 :          0 :         if ((link_speeds & RTE_ETH_LINK_SPEED_10M_HD) ||
     100                 :            :                         (link_speeds & RTE_ETH_LINK_SPEED_100M_HD))
     101                 :            :                 return RTE_ETH_LINK_HALF_DUPLEX;
     102                 :            :         else
     103                 :          0 :                 return RTE_ETH_LINK_FULL_DUPLEX;
     104                 :            : }
     105                 :            : 
     106                 :            : static int
     107         [ #  # ]:          0 : nicvf_apply_link_speed(struct rte_eth_dev *dev)
     108                 :            : {
     109                 :            :         struct nicvf *nic = nicvf_pmd_priv(dev);
     110                 :            :         struct rte_eth_conf *conf = &dev->data->dev_conf;
     111                 :            :         struct change_link_mode cfg;
     112         [ #  # ]:          0 :         if (conf->link_speeds == RTE_ETH_LINK_SPEED_AUTONEG)
     113                 :            :                 /* TODO: Handle this case */
     114                 :            :                 return 0;
     115                 :            : 
     116                 :          0 :         cfg.speed = nicvf_parse_link_speeds(conf->link_speeds);
     117         [ #  # ]:          0 :         cfg.autoneg = (conf->link_speeds & RTE_ETH_LINK_SPEED_FIXED) ? 1 : 0;
     118                 :          0 :         cfg.duplex = nicvf_parse_eth_link_duplex(conf->link_speeds);
     119   [ #  #  #  # ]:          0 :         cfg.qlm_mode = ((conf->link_speeds & RTE_ETH_LINK_SPEED_1G) ?
     120                 :            :                         NICVF_QLM_MODE_SGMII :
     121                 :            :                         (conf->link_speeds & RTE_ETH_LINK_SPEED_10G) ?
     122                 :            :                         NICVF_QLM_MODE_XFI : 0);
     123                 :            : 
     124         [ #  # ]:          0 :         if (cfg.speed != NICVF_LINK_SPEED_UNKNOWN &&
     125   [ #  #  #  # ]:          0 :             (cfg.speed != nic->speed || cfg.duplex != nic->duplex)) {
     126                 :          0 :                 nic->speed = cfg.speed;
     127                 :          0 :                 nic->duplex = cfg.duplex;
     128                 :          0 :                 return nicvf_mbox_change_mode(nic, &cfg);
     129                 :            :         } else {
     130                 :            :                 return 0;
     131                 :            :         }
     132                 :            : }
     133                 :            : 
     134                 :            : static void
     135         [ #  # ]:          0 : nicvf_link_status_update(struct nicvf *nic,
     136                 :            :                          struct rte_eth_link *link)
     137                 :            : {
     138                 :            :         memset(link, 0, sizeof(*link));
     139                 :            : 
     140                 :          0 :         link->link_status = nic->link_up ? RTE_ETH_LINK_UP : RTE_ETH_LINK_DOWN;
     141                 :            : 
     142         [ #  # ]:          0 :         if (nic->duplex == NICVF_HALF_DUPLEX)
     143                 :            :                 link->link_duplex = RTE_ETH_LINK_HALF_DUPLEX;
     144         [ #  # ]:          0 :         else if (nic->duplex == NICVF_FULL_DUPLEX)
     145                 :          0 :                 link->link_duplex = RTE_ETH_LINK_FULL_DUPLEX;
     146                 :          0 :         link->link_speed = nic->speed;
     147                 :          0 :         link->link_autoneg = RTE_ETH_LINK_AUTONEG;
     148                 :          0 : }
     149                 :            : 
     150                 :            : /*Poll for link status change by sending NIC_MBOX_MSG_BGX_LINK_CHANGE msg
     151                 :            :  * periodically to PF.
     152                 :            :  */
     153                 :            : static void
     154                 :          0 : nicvf_interrupt(void *arg)
     155                 :            : {
     156                 :            :         struct rte_eth_dev *dev = arg;
     157                 :            :         struct nicvf *nic = nicvf_pmd_priv(dev);
     158                 :            :         struct rte_eth_link link;
     159                 :            : 
     160                 :            :         rte_eth_linkstatus_get(dev, &link);
     161                 :            : 
     162                 :          0 :         nicvf_mbox_link_change(nic);
     163         [ #  # ]:          0 :         if (nic->link_up != link.link_status) {
     164         [ #  # ]:          0 :                 if (dev->data->dev_conf.intr_conf.lsc) {
     165                 :          0 :                         nicvf_link_status_update(nic, &link);
     166                 :          0 :                         rte_eth_linkstatus_set(dev, &link);
     167                 :            : 
     168                 :          0 :                         rte_eth_dev_callback_process(dev,
     169                 :            :                                                      RTE_ETH_EVENT_INTR_LSC,
     170                 :            :                                                      NULL);
     171                 :            :                 }
     172                 :            :         }
     173                 :            : 
     174                 :          0 :         rte_eal_alarm_set(NICVF_INTR_LINK_POLL_INTERVAL_MS * 1000,
     175                 :            :                                 nicvf_interrupt, dev);
     176                 :          0 : }
     177                 :            : 
     178                 :            : static void
     179                 :          0 : nicvf_vf_interrupt(void *arg)
     180                 :            : {
     181                 :            :         struct nicvf *nic = arg;
     182                 :            : 
     183                 :          0 :         nicvf_reg_poll_interrupts(nic);
     184                 :            : 
     185                 :          0 :         rte_eal_alarm_set(NICVF_INTR_POLL_INTERVAL_MS * 1000,
     186                 :            :                                 nicvf_vf_interrupt, nic);
     187                 :          0 : }
     188                 :            : 
     189                 :            : static int
     190                 :            : nicvf_periodic_alarm_start(void (fn)(void *), void *arg)
     191                 :            : {
     192                 :          0 :         return rte_eal_alarm_set(NICVF_INTR_POLL_INTERVAL_MS * 1000, fn, arg);
     193                 :            : }
     194                 :            : 
     195                 :            : static int
     196                 :            : nicvf_periodic_alarm_stop(void (fn)(void *), void *arg)
     197                 :            : {
     198                 :          0 :         return rte_eal_alarm_cancel(fn, arg);
     199                 :            : }
     200                 :            : 
     201                 :            : /*
     202                 :            :  * Return 0 means link status changed, -1 means not changed
     203                 :            :  */
     204                 :            : static int
     205                 :          0 : nicvf_dev_link_update(struct rte_eth_dev *dev, int wait_to_complete)
     206                 :            : {
     207                 :            : #define CHECK_INTERVAL 100  /* 100ms */
     208                 :            : #define MAX_CHECK_TIME 90   /* 9s (90 * 100ms) in total */
     209                 :            :         struct rte_eth_link link;
     210                 :            :         struct nicvf *nic = nicvf_pmd_priv(dev);
     211                 :            :         int i;
     212                 :            : 
     213                 :          0 :         PMD_INIT_FUNC_TRACE();
     214                 :            : 
     215         [ #  # ]:          0 :         if (wait_to_complete) {
     216                 :            :                 /* rte_eth_link_get() might need to wait up to 9 seconds */
     217         [ #  # ]:          0 :                 for (i = 0; i < MAX_CHECK_TIME; i++) {
     218                 :          0 :                         nicvf_link_status_update(nic, &link);
     219         [ #  # ]:          0 :                         if (link.link_status == RTE_ETH_LINK_UP)
     220                 :            :                                 break;
     221                 :            :                         rte_delay_ms(CHECK_INTERVAL);
     222                 :            :                 }
     223                 :            :         } else {
     224                 :          0 :                 nicvf_link_status_update(nic, &link);
     225                 :            :         }
     226                 :            : 
     227                 :          0 :         return rte_eth_linkstatus_set(dev, &link);
     228                 :            : }
     229                 :            : 
     230                 :            : static int
     231                 :          0 : nicvf_dev_set_mtu(struct rte_eth_dev *dev, uint16_t mtu)
     232                 :            : {
     233                 :            :         struct nicvf *nic = nicvf_pmd_priv(dev);
     234                 :          0 :         uint32_t buffsz, frame_size = mtu + NIC_HW_L2_OVERHEAD;
     235                 :            :         size_t i;
     236                 :            : 
     237                 :          0 :         PMD_INIT_FUNC_TRACE();
     238                 :            : 
     239                 :          0 :         buffsz = dev->data->min_rx_buf_size - RTE_PKTMBUF_HEADROOM;
     240                 :            : 
     241                 :            :         /*
     242                 :            :          * Refuse mtu that requires the support of scattered packets
     243                 :            :          * when this feature has not been enabled before.
     244                 :            :          */
     245         [ #  # ]:          0 :         if (dev->data->dev_started && !dev->data->scattered_rx &&
     246         [ #  # ]:          0 :                 (frame_size + 2 * VLAN_TAG_SIZE > buffsz))
     247                 :            :                 return -EINVAL;
     248                 :            : 
     249                 :            :         /* check <seg size> * <max_seg>  >= max_frame */
     250         [ #  # ]:          0 :         if (dev->data->scattered_rx &&
     251         [ #  # ]:          0 :                 (frame_size + 2 * VLAN_TAG_SIZE > buffsz * NIC_HW_MAX_SEGS))
     252                 :            :                 return -EINVAL;
     253                 :            : 
     254         [ #  # ]:          0 :         if (nicvf_mbox_update_hw_max_frs(nic, mtu))
     255                 :            :                 return -EINVAL;
     256                 :            : 
     257                 :          0 :         nic->mtu = mtu;
     258                 :            : 
     259         [ #  # ]:          0 :         for (i = 0; i < nic->sqs_count; i++)
     260                 :          0 :                 nic->snicvf[i]->mtu = mtu;
     261                 :            : 
     262                 :            :         return 0;
     263                 :            : }
     264                 :            : 
     265                 :            : static int
     266                 :          0 : nicvf_dev_get_regs(struct rte_eth_dev *dev, struct rte_dev_reg_info *regs)
     267                 :            : {
     268         [ #  # ]:          0 :         uint64_t *data = regs->data;
     269                 :            :         struct nicvf *nic = nicvf_pmd_priv(dev);
     270                 :            : 
     271         [ #  # ]:          0 :         if (data == NULL) {
     272                 :          0 :                 regs->length = nicvf_reg_get_count();
     273                 :          0 :                 regs->width = THUNDERX_REG_BYTES;
     274                 :          0 :                 return 0;
     275                 :            :         }
     276                 :            : 
     277                 :            :         /* Support only full register dump */
     278         [ #  # ]:          0 :         if ((regs->length == 0) ||
     279         [ #  # ]:          0 :                 (regs->length == (uint32_t)nicvf_reg_get_count())) {
     280                 :          0 :                 regs->version = nic->vendor_id << 16 | nic->device_id;
     281                 :          0 :                 nicvf_reg_dump(nic, data);
     282                 :          0 :                 return 0;
     283                 :            :         }
     284                 :            :         return -ENOTSUP;
     285                 :            : }
     286                 :            : 
     287                 :            : static int
     288         [ #  # ]:          0 : nicvf_dev_stats_get(struct rte_eth_dev *dev, struct rte_eth_stats *stats)
     289                 :            : {
     290                 :            :         uint16_t qidx;
     291                 :            :         struct nicvf_hw_rx_qstats rx_qstats;
     292                 :            :         struct nicvf_hw_tx_qstats tx_qstats;
     293                 :            :         struct nicvf_hw_stats port_stats;
     294                 :            :         struct nicvf *nic = nicvf_pmd_priv(dev);
     295                 :            :         uint16_t rx_start, rx_end;
     296                 :            :         uint16_t tx_start, tx_end;
     297                 :            :         size_t i;
     298                 :            : 
     299                 :            :         /* RX queue indices for the first VF */
     300                 :            :         nicvf_rx_range(dev, nic, &rx_start, &rx_end);
     301                 :            : 
     302                 :            :         /* Reading per RX ring stats */
     303         [ #  # ]:          0 :         for (qidx = rx_start; qidx <= rx_end; qidx++) {
     304         [ #  # ]:          0 :                 if (qidx >= RTE_ETHDEV_QUEUE_STAT_CNTRS)
     305                 :            :                         break;
     306                 :            : 
     307                 :          0 :                 nicvf_hw_get_rx_qstats(nic, &rx_qstats, qidx);
     308                 :          0 :                 stats->q_ibytes[qidx] = rx_qstats.q_rx_bytes;
     309                 :          0 :                 stats->q_ipackets[qidx] = rx_qstats.q_rx_packets;
     310                 :            :         }
     311                 :            : 
     312                 :            :         /* TX queue indices for the first VF */
     313                 :            :         nicvf_tx_range(dev, nic, &tx_start, &tx_end);
     314                 :            : 
     315                 :            :         /* Reading per TX ring stats */
     316         [ #  # ]:          0 :         for (qidx = tx_start; qidx <= tx_end; qidx++) {
     317         [ #  # ]:          0 :                 if (qidx >= RTE_ETHDEV_QUEUE_STAT_CNTRS)
     318                 :            :                         break;
     319                 :            : 
     320                 :          0 :                 nicvf_hw_get_tx_qstats(nic, &tx_qstats, qidx);
     321                 :          0 :                 stats->q_obytes[qidx] = tx_qstats.q_tx_bytes;
     322                 :          0 :                 stats->q_opackets[qidx] = tx_qstats.q_tx_packets;
     323                 :            :         }
     324                 :            : 
     325         [ #  # ]:          0 :         for (i = 0; i < nic->sqs_count; i++) {
     326                 :          0 :                 struct nicvf *snic = nic->snicvf[i];
     327                 :            : 
     328         [ #  # ]:          0 :                 if (snic == NULL)
     329                 :            :                         break;
     330                 :            : 
     331                 :            :                 /* RX queue indices for a secondary VF */
     332                 :            :                 nicvf_rx_range(dev, snic, &rx_start, &rx_end);
     333                 :            : 
     334                 :            :                 /* Reading per RX ring stats */
     335         [ #  # ]:          0 :                 for (qidx = rx_start; qidx <= rx_end; qidx++) {
     336         [ #  # ]:          0 :                         if (qidx >= RTE_ETHDEV_QUEUE_STAT_CNTRS)
     337                 :            :                                 break;
     338                 :            : 
     339                 :          0 :                         nicvf_hw_get_rx_qstats(snic, &rx_qstats,
     340                 :          0 :                                                qidx % MAX_RCV_QUEUES_PER_QS);
     341                 :          0 :                         stats->q_ibytes[qidx] = rx_qstats.q_rx_bytes;
     342                 :          0 :                         stats->q_ipackets[qidx] = rx_qstats.q_rx_packets;
     343                 :            :                 }
     344                 :            : 
     345                 :            :                 /* TX queue indices for a secondary VF */
     346                 :            :                 nicvf_tx_range(dev, snic, &tx_start, &tx_end);
     347                 :            :                 /* Reading per TX ring stats */
     348         [ #  # ]:          0 :                 for (qidx = tx_start; qidx <= tx_end; qidx++) {
     349         [ #  # ]:          0 :                         if (qidx >= RTE_ETHDEV_QUEUE_STAT_CNTRS)
     350                 :            :                                 break;
     351                 :            : 
     352                 :          0 :                         nicvf_hw_get_tx_qstats(snic, &tx_qstats,
     353                 :          0 :                                                qidx % MAX_SND_QUEUES_PER_QS);
     354                 :          0 :                         stats->q_obytes[qidx] = tx_qstats.q_tx_bytes;
     355                 :          0 :                         stats->q_opackets[qidx] = tx_qstats.q_tx_packets;
     356                 :            :                 }
     357                 :            :         }
     358                 :            : 
     359                 :          0 :         nicvf_hw_get_stats(nic, &port_stats);
     360                 :          0 :         stats->ibytes = port_stats.rx_bytes;
     361                 :          0 :         stats->ipackets = port_stats.rx_ucast_frames;
     362                 :          0 :         stats->ipackets += port_stats.rx_bcast_frames;
     363                 :          0 :         stats->ipackets += port_stats.rx_mcast_frames;
     364                 :          0 :         stats->ierrors = port_stats.rx_l2_errors;
     365                 :          0 :         stats->imissed = port_stats.rx_drop_red;
     366                 :          0 :         stats->imissed += port_stats.rx_drop_overrun;
     367                 :          0 :         stats->imissed += port_stats.rx_drop_bcast;
     368                 :          0 :         stats->imissed += port_stats.rx_drop_mcast;
     369                 :          0 :         stats->imissed += port_stats.rx_drop_l3_bcast;
     370                 :          0 :         stats->imissed += port_stats.rx_drop_l3_mcast;
     371                 :            : 
     372                 :          0 :         stats->obytes = port_stats.tx_bytes_ok;
     373                 :          0 :         stats->opackets = port_stats.tx_ucast_frames_ok;
     374                 :          0 :         stats->opackets += port_stats.tx_bcast_frames_ok;
     375                 :          0 :         stats->opackets += port_stats.tx_mcast_frames_ok;
     376                 :          0 :         stats->oerrors = port_stats.tx_drops;
     377                 :            : 
     378                 :          0 :         return 0;
     379                 :            : }
     380                 :            : 
     381                 :            : static const uint32_t *
     382         [ #  # ]:          0 : nicvf_dev_supported_ptypes_get(struct rte_eth_dev *dev)
     383                 :            : {
     384                 :            :         size_t copied;
     385                 :            :         static uint32_t ptypes[32];
     386                 :            :         struct nicvf *nic = nicvf_pmd_priv(dev);
     387                 :            :         static const uint32_t ptypes_common[] = {
     388                 :            :                 RTE_PTYPE_L3_IPV4,
     389                 :            :                 RTE_PTYPE_L3_IPV4_EXT,
     390                 :            :                 RTE_PTYPE_L3_IPV6,
     391                 :            :                 RTE_PTYPE_L3_IPV6_EXT,
     392                 :            :                 RTE_PTYPE_L4_TCP,
     393                 :            :                 RTE_PTYPE_L4_UDP,
     394                 :            :                 RTE_PTYPE_L4_FRAG,
     395                 :            :         };
     396                 :            :         static const uint32_t ptypes_tunnel[] = {
     397                 :            :                 RTE_PTYPE_TUNNEL_GRE,
     398                 :            :                 RTE_PTYPE_TUNNEL_GENEVE,
     399                 :            :                 RTE_PTYPE_TUNNEL_VXLAN,
     400                 :            :                 RTE_PTYPE_TUNNEL_NVGRE,
     401                 :            :         };
     402                 :            :         static const uint32_t ptypes_end = RTE_PTYPE_UNKNOWN;
     403                 :            : 
     404                 :            :         copied = sizeof(ptypes_common);
     405                 :            :         memcpy(ptypes, ptypes_common, copied);
     406         [ #  # ]:          0 :         if (nicvf_hw_cap(nic) & NICVF_CAP_TUNNEL_PARSING) {
     407                 :            :                 memcpy((char *)ptypes + copied, ptypes_tunnel,
     408                 :            :                         sizeof(ptypes_tunnel));
     409                 :            :                 copied += sizeof(ptypes_tunnel);
     410                 :            :         }
     411                 :            : 
     412                 :          0 :         memcpy((char *)ptypes + copied, &ptypes_end, sizeof(ptypes_end));
     413                 :            : 
     414                 :            :         /* All Ptypes are supported in all Rx functions. */
     415                 :          0 :         return ptypes;
     416                 :            : }
     417                 :            : 
     418                 :            : static int
     419         [ #  # ]:          0 : nicvf_dev_stats_reset(struct rte_eth_dev *dev)
     420                 :            : {
     421                 :            :         int i;
     422                 :            :         uint16_t rxqs = 0, txqs = 0;
     423                 :            :         struct nicvf *nic = nicvf_pmd_priv(dev);
     424                 :            :         uint16_t rx_start, rx_end;
     425                 :            :         uint16_t tx_start, tx_end;
     426                 :            :         int ret;
     427                 :            : 
     428                 :            :         /* Reset all primary nic counters */
     429                 :            :         nicvf_rx_range(dev, nic, &rx_start, &rx_end);
     430         [ #  # ]:          0 :         for (i = rx_start; i <= rx_end; i++)
     431                 :          0 :                 rxqs |= (0x3 << (i * 2));
     432                 :            : 
     433                 :            :         nicvf_tx_range(dev, nic, &tx_start, &tx_end);
     434         [ #  # ]:          0 :         for (i = tx_start; i <= tx_end; i++)
     435                 :          0 :                 txqs |= (0x3 << (i * 2));
     436                 :            : 
     437                 :          0 :         ret = nicvf_mbox_reset_stat_counters(nic, 0x3FFF, 0x1F, rxqs, txqs);
     438         [ #  # ]:          0 :         if (ret != 0)
     439                 :            :                 return ret;
     440                 :            : 
     441                 :            :         /* Reset secondary nic queue counters */
     442         [ #  # ]:          0 :         for (i = 0; i < nic->sqs_count; i++) {
     443                 :          0 :                 struct nicvf *snic = nic->snicvf[i];
     444         [ #  # ]:          0 :                 if (snic == NULL)
     445                 :            :                         break;
     446                 :            : 
     447                 :            :                 nicvf_rx_range(dev, snic, &rx_start, &rx_end);
     448         [ #  # ]:          0 :                 for (i = rx_start; i <= rx_end; i++)
     449                 :          0 :                         rxqs |= (0x3 << ((i % MAX_CMP_QUEUES_PER_QS) * 2));
     450                 :            : 
     451                 :            :                 nicvf_tx_range(dev, snic, &tx_start, &tx_end);
     452         [ #  # ]:          0 :                 for (i = tx_start; i <= tx_end; i++)
     453                 :          0 :                         txqs |= (0x3 << ((i % MAX_SND_QUEUES_PER_QS) * 2));
     454                 :            : 
     455                 :          0 :                 ret = nicvf_mbox_reset_stat_counters(snic, 0, 0, rxqs, txqs);
     456         [ #  # ]:          0 :                 if (ret != 0)
     457                 :          0 :                         return ret;
     458                 :            :         }
     459                 :            : 
     460                 :            :         return 0;
     461                 :            : }
     462                 :            : 
     463                 :            : /* Promiscuous mode enabled by default in LMAC to VF 1:1 map configuration */
     464                 :            : static int
     465                 :          0 : nicvf_dev_promisc_enable(struct rte_eth_dev *dev __rte_unused)
     466                 :            : {
     467                 :          0 :         return 0;
     468                 :            : }
     469                 :            : 
     470                 :            : static inline uint64_t
     471                 :          0 : nicvf_rss_ethdev_to_nic(struct nicvf *nic, uint64_t ethdev_rss)
     472                 :            : {
     473                 :            :         uint64_t nic_rss = 0;
     474                 :            : 
     475         [ #  # ]:          0 :         if (ethdev_rss & RTE_ETH_RSS_IPV4)
     476                 :            :                 nic_rss |= RSS_IP_ENA;
     477                 :            : 
     478         [ #  # ]:          0 :         if (ethdev_rss & RTE_ETH_RSS_IPV6)
     479                 :            :                 nic_rss |= RSS_IP_ENA;
     480                 :            : 
     481         [ #  # ]:          0 :         if (ethdev_rss & RTE_ETH_RSS_NONFRAG_IPV4_UDP)
     482                 :            :                 nic_rss |= (RSS_IP_ENA | RSS_UDP_ENA);
     483                 :            : 
     484         [ #  # ]:          0 :         if (ethdev_rss & RTE_ETH_RSS_NONFRAG_IPV4_TCP)
     485                 :          0 :                 nic_rss |= (RSS_IP_ENA | RSS_TCP_ENA);
     486                 :            : 
     487         [ #  # ]:          0 :         if (ethdev_rss & RTE_ETH_RSS_NONFRAG_IPV6_UDP)
     488                 :          0 :                 nic_rss |= (RSS_IP_ENA | RSS_UDP_ENA);
     489                 :            : 
     490         [ #  # ]:          0 :         if (ethdev_rss & RTE_ETH_RSS_NONFRAG_IPV6_TCP)
     491                 :          0 :                 nic_rss |= (RSS_IP_ENA | RSS_TCP_ENA);
     492                 :            : 
     493         [ #  # ]:          0 :         if (ethdev_rss & RTE_ETH_RSS_PORT)
     494                 :          0 :                 nic_rss |= RSS_L2_EXTENDED_HASH_ENA;
     495                 :            : 
     496         [ #  # ]:          0 :         if (nicvf_hw_cap(nic) & NICVF_CAP_TUNNEL_PARSING) {
     497         [ #  # ]:          0 :                 if (ethdev_rss & RTE_ETH_RSS_VXLAN)
     498                 :          0 :                         nic_rss |= RSS_TUN_VXLAN_ENA;
     499                 :            : 
     500         [ #  # ]:          0 :                 if (ethdev_rss & RTE_ETH_RSS_GENEVE)
     501                 :          0 :                         nic_rss |= RSS_TUN_GENEVE_ENA;
     502                 :            : 
     503         [ #  # ]:          0 :                 if (ethdev_rss & RTE_ETH_RSS_NVGRE)
     504                 :          0 :                         nic_rss |= RSS_TUN_NVGRE_ENA;
     505                 :            :         }
     506                 :            : 
     507                 :          0 :         return nic_rss;
     508                 :            : }
     509                 :            : 
     510                 :            : static inline uint64_t
     511                 :          0 : nicvf_rss_nic_to_ethdev(struct nicvf *nic,  uint64_t nic_rss)
     512                 :            : {
     513                 :            :         uint64_t ethdev_rss = 0;
     514                 :            : 
     515         [ #  # ]:          0 :         if (nic_rss & RSS_IP_ENA)
     516                 :            :                 ethdev_rss |= (RTE_ETH_RSS_IPV4 | RTE_ETH_RSS_IPV6);
     517                 :            : 
     518         [ #  # ]:          0 :         if ((nic_rss & RSS_IP_ENA) && (nic_rss & RSS_TCP_ENA))
     519                 :          0 :                 ethdev_rss |= (RTE_ETH_RSS_NONFRAG_IPV4_TCP |
     520                 :            :                                 RTE_ETH_RSS_NONFRAG_IPV6_TCP);
     521                 :            : 
     522         [ #  # ]:          0 :         if ((nic_rss & RSS_IP_ENA) && (nic_rss & RSS_UDP_ENA))
     523                 :          0 :                 ethdev_rss |= (RTE_ETH_RSS_NONFRAG_IPV4_UDP |
     524                 :            :                                 RTE_ETH_RSS_NONFRAG_IPV6_UDP);
     525                 :            : 
     526         [ #  # ]:          0 :         if (nic_rss & RSS_L2_EXTENDED_HASH_ENA)
     527                 :          0 :                 ethdev_rss |= RTE_ETH_RSS_PORT;
     528                 :            : 
     529         [ #  # ]:          0 :         if (nicvf_hw_cap(nic) & NICVF_CAP_TUNNEL_PARSING) {
     530         [ #  # ]:          0 :                 if (nic_rss & RSS_TUN_VXLAN_ENA)
     531                 :          0 :                         ethdev_rss |= RTE_ETH_RSS_VXLAN;
     532                 :            : 
     533         [ #  # ]:          0 :                 if (nic_rss & RSS_TUN_GENEVE_ENA)
     534                 :          0 :                         ethdev_rss |= RTE_ETH_RSS_GENEVE;
     535                 :            : 
     536         [ #  # ]:          0 :                 if (nic_rss & RSS_TUN_NVGRE_ENA)
     537                 :          0 :                         ethdev_rss |= RTE_ETH_RSS_NVGRE;
     538                 :            :         }
     539                 :          0 :         return ethdev_rss;
     540                 :            : }
     541                 :            : 
     542                 :            : static int
     543         [ #  # ]:          0 : nicvf_dev_reta_query(struct rte_eth_dev *dev,
     544                 :            :                      struct rte_eth_rss_reta_entry64 *reta_conf,
     545                 :            :                      uint16_t reta_size)
     546                 :            : {
     547                 :            :         struct nicvf *nic = nicvf_pmd_priv(dev);
     548                 :            :         uint8_t tbl[NIC_MAX_RSS_IDR_TBL_SIZE];
     549                 :            :         int ret, i, j;
     550                 :            : 
     551         [ #  # ]:          0 :         if (reta_size != NIC_MAX_RSS_IDR_TBL_SIZE) {
     552                 :          0 :                 PMD_DRV_LOG(ERR,
     553                 :            :                             "The size of hash lookup table configured "
     554                 :            :                             "(%u) doesn't match the number hardware can supported "
     555                 :            :                             "(%u)", reta_size, NIC_MAX_RSS_IDR_TBL_SIZE);
     556                 :          0 :                 return -EINVAL;
     557                 :            :         }
     558                 :            : 
     559                 :          0 :         ret = nicvf_rss_reta_query(nic, tbl, NIC_MAX_RSS_IDR_TBL_SIZE);
     560         [ #  # ]:          0 :         if (ret)
     561                 :            :                 return ret;
     562                 :            : 
     563                 :            :         /* Copy RETA table */
     564         [ #  # ]:          0 :         for (i = 0; i < (NIC_MAX_RSS_IDR_TBL_SIZE / RTE_ETH_RETA_GROUP_SIZE); i++) {
     565         [ #  # ]:          0 :                 for (j = 0; j < RTE_ETH_RETA_GROUP_SIZE; j++)
     566         [ #  # ]:          0 :                         if ((reta_conf[i].mask >> j) & 0x01)
     567                 :          0 :                                 reta_conf[i].reta[j] = tbl[j];
     568                 :            :         }
     569                 :            : 
     570                 :            :         return 0;
     571                 :            : }
     572                 :            : 
     573                 :            : static int
     574         [ #  # ]:          0 : nicvf_dev_reta_update(struct rte_eth_dev *dev,
     575                 :            :                       struct rte_eth_rss_reta_entry64 *reta_conf,
     576                 :            :                       uint16_t reta_size)
     577                 :            : {
     578                 :            :         struct nicvf *nic = nicvf_pmd_priv(dev);
     579                 :            :         uint8_t tbl[NIC_MAX_RSS_IDR_TBL_SIZE];
     580                 :            :         int ret, i, j;
     581                 :            : 
     582         [ #  # ]:          0 :         if (reta_size != NIC_MAX_RSS_IDR_TBL_SIZE) {
     583                 :          0 :                 PMD_DRV_LOG(ERR, "The size of hash lookup table configured "
     584                 :            :                         "(%u) doesn't match the number hardware can supported "
     585                 :            :                         "(%u)", reta_size, NIC_MAX_RSS_IDR_TBL_SIZE);
     586                 :          0 :                 return -EINVAL;
     587                 :            :         }
     588                 :            : 
     589                 :          0 :         ret = nicvf_rss_reta_query(nic, tbl, NIC_MAX_RSS_IDR_TBL_SIZE);
     590         [ #  # ]:          0 :         if (ret)
     591                 :            :                 return ret;
     592                 :            : 
     593                 :            :         /* Copy RETA table */
     594         [ #  # ]:          0 :         for (i = 0; i < (NIC_MAX_RSS_IDR_TBL_SIZE / RTE_ETH_RETA_GROUP_SIZE); i++) {
     595         [ #  # ]:          0 :                 for (j = 0; j < RTE_ETH_RETA_GROUP_SIZE; j++)
     596         [ #  # ]:          0 :                         if ((reta_conf[i].mask >> j) & 0x01)
     597                 :          0 :                                 tbl[j] = reta_conf[i].reta[j];
     598                 :            :         }
     599                 :            : 
     600                 :          0 :         return nicvf_rss_reta_update(nic, tbl, NIC_MAX_RSS_IDR_TBL_SIZE);
     601                 :            : }
     602                 :            : 
     603                 :            : static int
     604         [ #  # ]:          0 : nicvf_dev_rss_hash_conf_get(struct rte_eth_dev *dev,
     605                 :            :                             struct rte_eth_rss_conf *rss_conf)
     606                 :            : {
     607                 :            :         struct nicvf *nic = nicvf_pmd_priv(dev);
     608                 :            : 
     609         [ #  # ]:          0 :         if (rss_conf->rss_key)
     610                 :          0 :                 nicvf_rss_get_key(nic, rss_conf->rss_key);
     611                 :            : 
     612                 :          0 :         rss_conf->rss_key_len =  RSS_HASH_KEY_BYTE_SIZE;
     613                 :          0 :         rss_conf->rss_hf = nicvf_rss_nic_to_ethdev(nic, nicvf_rss_get_cfg(nic));
     614                 :          0 :         return 0;
     615                 :            : }
     616                 :            : 
     617                 :            : static int
     618         [ #  # ]:          0 : nicvf_dev_rss_hash_update(struct rte_eth_dev *dev,
     619                 :            :                           struct rte_eth_rss_conf *rss_conf)
     620                 :            : {
     621                 :            :         struct nicvf *nic = nicvf_pmd_priv(dev);
     622                 :            :         uint64_t nic_rss;
     623                 :            : 
     624         [ #  # ]:          0 :         if (rss_conf->rss_key &&
     625         [ #  # ]:          0 :                 rss_conf->rss_key_len != RSS_HASH_KEY_BYTE_SIZE) {
     626                 :          0 :                 PMD_DRV_LOG(ERR, "Hash key size mismatch %u",
     627                 :            :                             rss_conf->rss_key_len);
     628                 :          0 :                 return -EINVAL;
     629                 :            :         }
     630                 :            : 
     631         [ #  # ]:          0 :         if (rss_conf->rss_key)
     632                 :          0 :                 nicvf_rss_set_key(nic, rss_conf->rss_key);
     633                 :            : 
     634                 :          0 :         nic_rss = nicvf_rss_ethdev_to_nic(nic, rss_conf->rss_hf);
     635                 :          0 :         nicvf_rss_set_cfg(nic, nic_rss);
     636                 :          0 :         return 0;
     637                 :            : }
     638                 :            : 
     639                 :            : static int
     640                 :          0 : nicvf_qset_cq_alloc(struct rte_eth_dev *dev, struct nicvf *nic,
     641                 :            :                     struct nicvf_rxq *rxq, uint16_t qidx, uint32_t desc_cnt)
     642                 :            : {
     643                 :            :         const struct rte_memzone *rz;
     644                 :            :         uint32_t ring_size = CMP_QUEUE_SZ_MAX * sizeof(union cq_entry_t);
     645                 :            : 
     646                 :          0 :         rz = rte_eth_dma_zone_reserve(dev, "cq_ring",
     647                 :            :                                       nicvf_netdev_qidx(nic, qidx), ring_size,
     648         [ #  # ]:          0 :                                       NICVF_CQ_BASE_ALIGN_BYTES, nic->node);
     649         [ #  # ]:          0 :         if (rz == NULL) {
     650                 :          0 :                 PMD_INIT_LOG(ERR, "Failed to allocate mem for cq hw ring");
     651                 :          0 :                 return -ENOMEM;
     652                 :            :         }
     653                 :            : 
     654                 :          0 :         memset(rz->addr, 0, ring_size);
     655                 :            : 
     656                 :          0 :         rxq->phys = rz->iova;
     657                 :          0 :         rxq->desc = rz->addr;
     658                 :          0 :         rxq->qlen_mask = desc_cnt - 1;
     659                 :            : 
     660                 :          0 :         return 0;
     661                 :            : }
     662                 :            : 
     663                 :            : static int
     664                 :          0 : nicvf_qset_sq_alloc(struct rte_eth_dev *dev, struct nicvf *nic,
     665                 :            :                     struct nicvf_txq *sq, uint16_t qidx, uint32_t desc_cnt)
     666                 :            : {
     667                 :            :         const struct rte_memzone *rz;
     668                 :            :         uint32_t ring_size = SND_QUEUE_SZ_MAX * sizeof(union sq_entry_t);
     669                 :            : 
     670                 :          0 :         rz = rte_eth_dma_zone_reserve(dev, "sq",
     671                 :            :                                       nicvf_netdev_qidx(nic, qidx), ring_size,
     672         [ #  # ]:          0 :                                       NICVF_SQ_BASE_ALIGN_BYTES, nic->node);
     673         [ #  # ]:          0 :         if (rz == NULL) {
     674                 :          0 :                 PMD_INIT_LOG(ERR, "Failed allocate mem for sq hw ring");
     675                 :          0 :                 return -ENOMEM;
     676                 :            :         }
     677                 :            : 
     678                 :          0 :         memset(rz->addr, 0, ring_size);
     679                 :            : 
     680                 :          0 :         sq->phys = rz->iova;
     681                 :          0 :         sq->desc = rz->addr;
     682                 :          0 :         sq->qlen_mask = desc_cnt - 1;
     683                 :            : 
     684                 :          0 :         return 0;
     685                 :            : }
     686                 :            : 
     687                 :            : static int
     688                 :          0 : nicvf_qset_rbdr_alloc(struct rte_eth_dev *dev, struct nicvf *nic,
     689                 :            :                       uint32_t desc_cnt, uint32_t buffsz)
     690                 :            : {
     691                 :            :         struct nicvf_rbdr *rbdr;
     692                 :            :         const struct rte_memzone *rz;
     693                 :            :         uint32_t ring_size;
     694                 :            : 
     695         [ #  # ]:          0 :         assert(nic->rbdr == NULL);
     696                 :          0 :         rbdr = rte_zmalloc_socket("rbdr", sizeof(struct nicvf_rbdr),
     697                 :          0 :                                   RTE_CACHE_LINE_SIZE, nic->node);
     698         [ #  # ]:          0 :         if (rbdr == NULL) {
     699                 :          0 :                 PMD_INIT_LOG(ERR, "Failed to allocate mem for rbdr");
     700                 :          0 :                 return -ENOMEM;
     701                 :            :         }
     702                 :            : 
     703                 :            :         ring_size = sizeof(struct rbdr_entry_t) * RBDR_QUEUE_SZ_MAX;
     704                 :          0 :         rz = rte_eth_dma_zone_reserve(dev, "rbdr",
     705                 :            :                                       nicvf_netdev_qidx(nic, 0), ring_size,
     706         [ #  # ]:          0 :                                       NICVF_RBDR_BASE_ALIGN_BYTES, nic->node);
     707         [ #  # ]:          0 :         if (rz == NULL) {
     708                 :          0 :                 PMD_INIT_LOG(ERR, "Failed to allocate mem for rbdr desc ring");
     709                 :          0 :                 rte_free(rbdr);
     710                 :          0 :                 return -ENOMEM;
     711                 :            :         }
     712                 :            : 
     713                 :          0 :         memset(rz->addr, 0, ring_size);
     714                 :            : 
     715                 :          0 :         rbdr->phys = rz->iova;
     716                 :          0 :         rbdr->tail = 0;
     717                 :          0 :         rbdr->next_tail = 0;
     718                 :          0 :         rbdr->desc = rz->addr;
     719                 :          0 :         rbdr->buffsz = buffsz;
     720                 :          0 :         rbdr->qlen_mask = desc_cnt - 1;
     721                 :          0 :         rbdr->rbdr_status =
     722                 :          0 :                 nicvf_qset_base(nic, 0) + NIC_QSET_RBDR_0_1_STATUS0;
     723                 :          0 :         rbdr->rbdr_door =
     724                 :          0 :                 nicvf_qset_base(nic, 0) + NIC_QSET_RBDR_0_1_DOOR;
     725                 :            : 
     726                 :          0 :         nic->rbdr = rbdr;
     727                 :          0 :         return 0;
     728                 :            : }
     729                 :            : 
     730                 :            : static void
     731         [ #  # ]:          0 : nicvf_rbdr_release_mbuf(struct rte_eth_dev *dev, struct nicvf *nic,
     732                 :            :                         nicvf_iova_addr_t phy)
     733                 :            : {
     734                 :            :         uint16_t qidx;
     735                 :            :         void *obj;
     736                 :            :         struct nicvf_rxq *rxq;
     737                 :            :         uint16_t rx_start, rx_end;
     738                 :            : 
     739                 :            :         /* Get queue ranges for this VF */
     740                 :            :         nicvf_rx_range(dev, nic, &rx_start, &rx_end);
     741                 :            : 
     742         [ #  # ]:          0 :         for (qidx = rx_start; qidx <= rx_end; qidx++) {
     743                 :          0 :                 rxq = dev->data->rx_queues[qidx];
     744         [ #  # ]:          0 :                 if (rxq->precharge_cnt) {
     745         [ #  # ]:          0 :                         obj = (void *)nicvf_mbuff_phy2virt(phy,
     746                 :            :                                                            rxq->mbuf_phys_off);
     747         [ #  # ]:          0 :                         rte_mempool_put(rxq->pool, obj);
     748                 :          0 :                         rxq->precharge_cnt--;
     749                 :          0 :                         break;
     750                 :            :                 }
     751                 :            :         }
     752                 :          0 : }
     753                 :            : 
     754                 :            : static inline void
     755                 :          0 : nicvf_rbdr_release_mbufs(struct rte_eth_dev *dev, struct nicvf *nic)
     756                 :            : {
     757                 :            :         uint32_t qlen_mask, head;
     758                 :            :         struct rbdr_entry_t *entry;
     759                 :          0 :         struct nicvf_rbdr *rbdr = nic->rbdr;
     760                 :            : 
     761                 :          0 :         qlen_mask = rbdr->qlen_mask;
     762                 :          0 :         head = rbdr->head;
     763         [ #  # ]:          0 :         while (head != rbdr->tail) {
     764                 :          0 :                 entry = rbdr->desc + head;
     765                 :          0 :                 nicvf_rbdr_release_mbuf(dev, nic, entry->full_addr);
     766                 :          0 :                 head++;
     767                 :          0 :                 head = head & qlen_mask;
     768                 :            :         }
     769                 :          0 : }
     770                 :            : 
     771                 :            : static inline void
     772                 :          0 : nicvf_tx_queue_release_mbufs(struct nicvf_txq *txq)
     773                 :            : {
     774                 :            :         uint32_t head;
     775                 :            : 
     776                 :          0 :         head = txq->head;
     777         [ #  # ]:          0 :         while (head != txq->tail) {
     778         [ #  # ]:          0 :                 if (txq->txbuffs[head]) {
     779                 :            :                         rte_pktmbuf_free_seg(txq->txbuffs[head]);
     780                 :          0 :                         txq->txbuffs[head] = NULL;
     781                 :            :                 }
     782                 :          0 :                 head++;
     783                 :          0 :                 head = head & txq->qlen_mask;
     784                 :            :         }
     785                 :          0 : }
     786                 :            : 
     787                 :            : static void
     788                 :          0 : nicvf_tx_queue_reset(struct nicvf_txq *txq)
     789                 :            : {
     790                 :          0 :         uint32_t txq_desc_cnt = txq->qlen_mask + 1;
     791                 :            : 
     792                 :          0 :         memset(txq->desc, 0, sizeof(union sq_entry_t) * txq_desc_cnt);
     793                 :          0 :         memset(txq->txbuffs, 0, sizeof(struct rte_mbuf *) * txq_desc_cnt);
     794                 :          0 :         txq->tail = 0;
     795                 :          0 :         txq->head = 0;
     796                 :          0 :         txq->xmit_bufs = 0;
     797                 :          0 : }
     798                 :            : 
     799                 :            : static inline int
     800                 :          0 : nicvf_vf_start_tx_queue(struct rte_eth_dev *dev, struct nicvf *nic,
     801                 :            :                         uint16_t qidx)
     802                 :            : {
     803                 :            :         struct nicvf_txq *txq;
     804                 :            :         int ret;
     805                 :            : 
     806         [ #  # ]:          0 :         assert(qidx < MAX_SND_QUEUES_PER_QS);
     807                 :            : 
     808   [ #  #  #  # ]:          0 :         if (dev->data->tx_queue_state[nicvf_netdev_qidx(nic, qidx)] ==
     809                 :            :                 RTE_ETH_QUEUE_STATE_STARTED)
     810                 :            :                 return 0;
     811                 :            : 
     812                 :          0 :         txq = dev->data->tx_queues[nicvf_netdev_qidx(nic, qidx)];
     813                 :          0 :         txq->pool = NULL;
     814                 :          0 :         ret = nicvf_qset_sq_config(nic, qidx, txq);
     815         [ #  # ]:          0 :         if (ret) {
     816                 :          0 :                 PMD_INIT_LOG(ERR, "Failed to configure sq VF%d %d %d",
     817                 :            :                              nic->vf_id, qidx, ret);
     818                 :          0 :                 goto config_sq_error;
     819                 :            :         }
     820                 :            : 
     821         [ #  # ]:          0 :         dev->data->tx_queue_state[nicvf_netdev_qidx(nic, qidx)] =
     822                 :            :                 RTE_ETH_QUEUE_STATE_STARTED;
     823                 :          0 :         return ret;
     824                 :            : 
     825                 :            : config_sq_error:
     826                 :          0 :         nicvf_qset_sq_reclaim(nic, qidx);
     827                 :          0 :         return ret;
     828                 :            : }
     829                 :            : 
     830                 :            : static inline int
     831                 :          0 : nicvf_vf_stop_tx_queue(struct rte_eth_dev *dev, struct nicvf *nic,
     832                 :            :                        uint16_t qidx)
     833                 :            : {
     834                 :            :         struct nicvf_txq *txq;
     835                 :            :         int ret;
     836                 :            : 
     837         [ #  # ]:          0 :         assert(qidx < MAX_SND_QUEUES_PER_QS);
     838                 :            : 
     839   [ #  #  #  # ]:          0 :         if (dev->data->tx_queue_state[nicvf_netdev_qidx(nic, qidx)] ==
     840                 :            :                 RTE_ETH_QUEUE_STATE_STOPPED)
     841                 :            :                 return 0;
     842                 :            : 
     843                 :          0 :         ret = nicvf_qset_sq_reclaim(nic, qidx);
     844         [ #  # ]:          0 :         if (ret)
     845                 :          0 :                 PMD_INIT_LOG(ERR, "Failed to reclaim sq VF%d %d %d",
     846                 :            :                              nic->vf_id, qidx, ret);
     847                 :            : 
     848         [ #  # ]:          0 :         txq = dev->data->tx_queues[nicvf_netdev_qidx(nic, qidx)];
     849                 :          0 :         nicvf_tx_queue_release_mbufs(txq);
     850                 :          0 :         nicvf_tx_queue_reset(txq);
     851                 :            : 
     852         [ #  # ]:          0 :         dev->data->tx_queue_state[nicvf_netdev_qidx(nic, qidx)] =
     853                 :            :                 RTE_ETH_QUEUE_STATE_STOPPED;
     854                 :          0 :         return ret;
     855                 :            : }
     856                 :            : 
     857                 :            : static inline int
     858                 :          0 : nicvf_configure_cpi(struct rte_eth_dev *dev)
     859                 :            : {
     860                 :            :         struct nicvf *nic = nicvf_pmd_priv(dev);
     861                 :            :         uint16_t qidx, qcnt;
     862                 :            :         int ret;
     863                 :            : 
     864                 :            :         /* Count started rx queues */
     865         [ #  # ]:          0 :         for (qidx = qcnt = 0; qidx < dev->data->nb_rx_queues; qidx++)
     866         [ #  # ]:          0 :                 if (dev->data->rx_queue_state[qidx] ==
     867                 :            :                     RTE_ETH_QUEUE_STATE_STARTED)
     868                 :          0 :                         qcnt++;
     869                 :            : 
     870                 :          0 :         nic->cpi_alg = CPI_ALG_NONE;
     871                 :          0 :         ret = nicvf_mbox_config_cpi(nic, qcnt);
     872         [ #  # ]:          0 :         if (ret)
     873                 :          0 :                 PMD_INIT_LOG(ERR, "Failed to configure CPI %d", ret);
     874                 :            : 
     875                 :          0 :         return ret;
     876                 :            : }
     877                 :            : 
     878                 :            : static inline int
     879                 :          0 : nicvf_configure_rss(struct rte_eth_dev *dev)
     880                 :            : {
     881                 :            :         struct nicvf *nic = nicvf_pmd_priv(dev);
     882                 :            :         uint64_t rsshf;
     883                 :            :         int ret = -EINVAL;
     884                 :            : 
     885                 :          0 :         rsshf = nicvf_rss_ethdev_to_nic(nic,
     886                 :            :                         dev->data->dev_conf.rx_adv_conf.rss_conf.rss_hf);
     887                 :          0 :         PMD_DRV_LOG(INFO, "mode=%d rx_queues=%d loopback=%d rsshf=0x%" PRIx64,
     888                 :            :                     dev->data->dev_conf.rxmode.mq_mode,
     889                 :            :                     dev->data->nb_rx_queues,
     890                 :            :                     dev->data->dev_conf.lpbk_mode, rsshf);
     891                 :            : 
     892         [ #  # ]:          0 :         if (dev->data->dev_conf.rxmode.mq_mode == RTE_ETH_MQ_RX_NONE)
     893                 :          0 :                 ret = nicvf_rss_term(nic);
     894         [ #  # ]:          0 :         else if (dev->data->dev_conf.rxmode.mq_mode == RTE_ETH_MQ_RX_RSS)
     895                 :          0 :                 ret = nicvf_rss_config(nic, dev->data->nb_rx_queues, rsshf);
     896         [ #  # ]:          0 :         if (ret)
     897                 :          0 :                 PMD_INIT_LOG(ERR, "Failed to configure RSS %d", ret);
     898                 :            : 
     899                 :          0 :         return ret;
     900                 :            : }
     901                 :            : 
     902                 :            : static int
     903         [ #  # ]:          0 : nicvf_configure_rss_reta(struct rte_eth_dev *dev)
     904                 :            : {
     905                 :            :         struct nicvf *nic = nicvf_pmd_priv(dev);
     906                 :            :         unsigned int idx, qmap_size;
     907                 :            :         uint8_t qmap[RTE_MAX_QUEUES_PER_PORT];
     908                 :            :         uint8_t default_reta[NIC_MAX_RSS_IDR_TBL_SIZE];
     909                 :            : 
     910         [ #  # ]:          0 :         if (nic->cpi_alg != CPI_ALG_NONE)
     911                 :            :                 return -EINVAL;
     912                 :            : 
     913                 :            :         /* Prepare queue map */
     914         [ #  # ]:          0 :         for (idx = 0, qmap_size = 0; idx < dev->data->nb_rx_queues; idx++) {
     915         [ #  # ]:          0 :                 if (dev->data->rx_queue_state[idx] ==
     916                 :            :                                 RTE_ETH_QUEUE_STATE_STARTED)
     917                 :          0 :                         qmap[qmap_size++] = idx;
     918                 :            :         }
     919                 :            : 
     920                 :            :         /* Update default RSS RETA */
     921         [ #  # ]:          0 :         for (idx = 0; idx < NIC_MAX_RSS_IDR_TBL_SIZE; idx++)
     922                 :          0 :                 default_reta[idx] = qmap[idx % qmap_size];
     923                 :            : 
     924                 :          0 :         return nicvf_rss_reta_update(nic, default_reta,
     925                 :            :                                      NIC_MAX_RSS_IDR_TBL_SIZE);
     926                 :            : }
     927                 :            : 
     928                 :            : static void
     929                 :          0 : nicvf_dev_tx_queue_release(struct rte_eth_dev *dev, uint16_t qid)
     930                 :            : {
     931                 :          0 :         struct nicvf_txq *txq = dev->data->tx_queues[qid];
     932                 :            : 
     933                 :          0 :         PMD_INIT_FUNC_TRACE();
     934                 :            : 
     935         [ #  # ]:          0 :         if (txq) {
     936         [ #  # ]:          0 :                 if (txq->txbuffs != NULL) {
     937                 :          0 :                         nicvf_tx_queue_release_mbufs(txq);
     938                 :          0 :                         rte_free(txq->txbuffs);
     939                 :          0 :                         txq->txbuffs = NULL;
     940                 :            :                 }
     941                 :          0 :                 rte_free(txq);
     942                 :          0 :                 dev->data->tx_queues[qid] = NULL;
     943                 :            :         }
     944                 :          0 : }
     945                 :            : 
     946                 :            : static void
     947                 :          0 : nicvf_set_tx_function(struct rte_eth_dev *dev)
     948                 :            : {
     949                 :            :         struct nicvf_txq *txq = NULL;
     950                 :            :         size_t i;
     951                 :            :         bool multiseg = false;
     952                 :            : 
     953         [ #  # ]:          0 :         for (i = 0; i < dev->data->nb_tx_queues; i++) {
     954                 :          0 :                 txq = dev->data->tx_queues[i];
     955         [ #  # ]:          0 :                 if (txq->offloads & RTE_ETH_TX_OFFLOAD_MULTI_SEGS) {
     956                 :            :                         multiseg = true;
     957                 :            :                         break;
     958                 :            :                 }
     959                 :            :         }
     960                 :            : 
     961                 :            :         /* Use a simple Tx queue (no offloads, no multi segs) if possible */
     962         [ #  # ]:          0 :         if (multiseg) {
     963                 :          0 :                 PMD_DRV_LOG(DEBUG, "Using multi-segment tx callback");
     964                 :          0 :                 dev->tx_pkt_burst = nicvf_xmit_pkts_multiseg;
     965                 :            :         } else {
     966                 :          0 :                 PMD_DRV_LOG(DEBUG, "Using single-segment tx callback");
     967                 :          0 :                 dev->tx_pkt_burst = nicvf_xmit_pkts;
     968                 :            :         }
     969                 :            : 
     970         [ #  # ]:          0 :         if (!txq)
     971                 :            :                 return;
     972                 :            : 
     973         [ #  # ]:          0 :         if (txq->pool_free == nicvf_single_pool_free_xmited_buffers)
     974                 :          0 :                 PMD_DRV_LOG(DEBUG, "Using single-mempool tx free method");
     975                 :            :         else
     976                 :          0 :                 PMD_DRV_LOG(DEBUG, "Using multi-mempool tx free method");
     977                 :            : }
     978                 :            : 
     979                 :            : static void
     980                 :          0 : nicvf_set_rx_function(struct rte_eth_dev *dev)
     981                 :            : {
     982                 :            :         struct nicvf *nic = nicvf_pmd_priv(dev);
     983                 :            : 
     984                 :          0 :         const eth_rx_burst_t rx_burst_func[2][2][2] = {
     985                 :            :         /* [NORMAL/SCATTER] [CKSUM/NO_CKSUM] [VLAN_STRIP/NO_VLAN_STRIP] */
     986                 :            :                 [0][0][0] = nicvf_recv_pkts_no_offload,
     987                 :            :                 [0][0][1] = nicvf_recv_pkts_vlan_strip,
     988                 :            :                 [0][1][0] = nicvf_recv_pkts_cksum,
     989                 :            :                 [0][1][1] = nicvf_recv_pkts_cksum_vlan_strip,
     990                 :            :                 [1][0][0] = nicvf_recv_pkts_multiseg_no_offload,
     991                 :            :                 [1][0][1] = nicvf_recv_pkts_multiseg_vlan_strip,
     992                 :            :                 [1][1][0] = nicvf_recv_pkts_multiseg_cksum,
     993                 :            :                 [1][1][1] = nicvf_recv_pkts_multiseg_cksum_vlan_strip,
     994                 :            :         };
     995                 :            : 
     996                 :          0 :         dev->rx_pkt_burst =
     997                 :          0 :                 rx_burst_func[dev->data->scattered_rx]
     998                 :          0 :                         [nic->offload_cksum][nic->vlan_strip];
     999                 :          0 : }
    1000                 :            : 
    1001                 :            : static int
    1002                 :          0 : nicvf_dev_tx_queue_setup(struct rte_eth_dev *dev, uint16_t qidx,
    1003                 :            :                          uint16_t nb_desc, unsigned int socket_id,
    1004                 :            :                          const struct rte_eth_txconf *tx_conf)
    1005                 :            : {
    1006                 :            :         uint16_t tx_free_thresh;
    1007                 :            :         bool is_single_pool;
    1008                 :            :         struct nicvf_txq *txq;
    1009                 :            :         struct nicvf *nic = nicvf_pmd_priv(dev);
    1010                 :            :         uint64_t offloads;
    1011                 :            : 
    1012                 :          0 :         PMD_INIT_FUNC_TRACE();
    1013                 :            : 
    1014         [ #  # ]:          0 :         if (qidx >= MAX_SND_QUEUES_PER_QS)
    1015                 :          0 :                 nic = nic->snicvf[qidx / MAX_SND_QUEUES_PER_QS - 1];
    1016                 :            : 
    1017                 :          0 :         qidx = qidx % MAX_SND_QUEUES_PER_QS;
    1018                 :            : 
    1019                 :            :         /* Socket id check */
    1020   [ #  #  #  # ]:          0 :         if (socket_id != (unsigned int)SOCKET_ID_ANY && socket_id != nic->node)
    1021                 :          0 :                 PMD_DRV_LOG(WARNING, "socket_id expected %d, configured %d",
    1022                 :            :                 socket_id, nic->node);
    1023                 :            : 
    1024                 :            :         /* Tx deferred start is not supported */
    1025         [ #  # ]:          0 :         if (tx_conf->tx_deferred_start) {
    1026                 :          0 :                 PMD_INIT_LOG(ERR, "Tx deferred start not supported");
    1027                 :          0 :                 return -EINVAL;
    1028                 :            :         }
    1029                 :            : 
    1030                 :            :         /* Roundup nb_desc to available qsize and validate max number of desc */
    1031                 :          0 :         nb_desc = nicvf_qsize_sq_roundup(nb_desc);
    1032         [ #  # ]:          0 :         if (nb_desc == 0) {
    1033                 :          0 :                 PMD_INIT_LOG(ERR, "Value of nb_desc beyond available sq qsize");
    1034                 :          0 :                 return -EINVAL;
    1035                 :            :         }
    1036                 :            : 
    1037                 :            :         /* Validate tx_free_thresh */
    1038         [ #  # ]:          0 :         tx_free_thresh = (uint16_t)((tx_conf->tx_free_thresh) ?
    1039                 :            :                                 tx_conf->tx_free_thresh :
    1040                 :            :                                 NICVF_DEFAULT_TX_FREE_THRESH);
    1041                 :            : 
    1042         [ #  # ]:          0 :         if (tx_free_thresh > (nb_desc) ||
    1043                 :            :                 tx_free_thresh > NICVF_MAX_TX_FREE_THRESH) {
    1044                 :          0 :                 PMD_INIT_LOG(ERR,
    1045                 :            :                         "tx_free_thresh must be less than the number of TX "
    1046                 :            :                         "descriptors. (tx_free_thresh=%u port=%d "
    1047                 :            :                         "queue=%d)", (unsigned int)tx_free_thresh,
    1048                 :            :                         (int)dev->data->port_id, (int)qidx);
    1049                 :          0 :                 return -EINVAL;
    1050                 :            :         }
    1051                 :            : 
    1052                 :            :         /* Free memory prior to re-allocation if needed. */
    1053   [ #  #  #  # ]:          0 :         if (dev->data->tx_queues[nicvf_netdev_qidx(nic, qidx)] != NULL) {
    1054                 :          0 :                 PMD_TX_LOG(DEBUG, "Freeing memory prior to re-allocation %d",
    1055                 :            :                                 nicvf_netdev_qidx(nic, qidx));
    1056                 :          0 :                 nicvf_dev_tx_queue_release(dev, nicvf_netdev_qidx(nic, qidx));
    1057         [ #  # ]:          0 :                 dev->data->tx_queues[nicvf_netdev_qidx(nic, qidx)] = NULL;
    1058                 :            :         }
    1059                 :            : 
    1060                 :            :         /* Allocating tx queue data structure */
    1061                 :          0 :         txq = rte_zmalloc_socket("ethdev TX queue", sizeof(struct nicvf_txq),
    1062                 :          0 :                                         RTE_CACHE_LINE_SIZE, nic->node);
    1063         [ #  # ]:          0 :         if (txq == NULL) {
    1064                 :          0 :                 PMD_INIT_LOG(ERR, "Failed to allocate txq=%d",
    1065                 :            :                              nicvf_netdev_qidx(nic, qidx));
    1066                 :          0 :                 return -ENOMEM;
    1067                 :            :         }
    1068                 :            : 
    1069                 :          0 :         txq->nic = nic;
    1070                 :          0 :         txq->queue_id = qidx;
    1071                 :          0 :         txq->tx_free_thresh = tx_free_thresh;
    1072         [ #  # ]:          0 :         txq->sq_head = nicvf_qset_base(nic, qidx) + NIC_QSET_SQ_0_7_HEAD;
    1073                 :          0 :         txq->sq_door = nicvf_qset_base(nic, qidx) + NIC_QSET_SQ_0_7_DOOR;
    1074                 :          0 :         offloads = tx_conf->offloads | dev->data->dev_conf.txmode.offloads;
    1075                 :          0 :         txq->offloads = offloads;
    1076                 :            : 
    1077                 :          0 :         is_single_pool = !!(offloads & RTE_ETH_TX_OFFLOAD_MBUF_FAST_FREE);
    1078                 :            : 
    1079                 :            :         /* Choose optimum free threshold value for multipool case */
    1080         [ #  # ]:          0 :         if (!is_single_pool) {
    1081                 :          0 :                 txq->tx_free_thresh = (uint16_t)
    1082         [ #  # ]:          0 :                 (tx_conf->tx_free_thresh == NICVF_DEFAULT_TX_FREE_THRESH ?
    1083                 :            :                                 NICVF_TX_FREE_MPOOL_THRESH :
    1084                 :            :                                 tx_conf->tx_free_thresh);
    1085                 :          0 :                 txq->pool_free = nicvf_multi_pool_free_xmited_buffers;
    1086                 :            :         } else {
    1087                 :          0 :                 txq->pool_free = nicvf_single_pool_free_xmited_buffers;
    1088                 :            :         }
    1089                 :            : 
    1090         [ #  # ]:          0 :         dev->data->tx_queues[nicvf_netdev_qidx(nic, qidx)] = txq;
    1091                 :            : 
    1092                 :            :         /* Allocate software ring */
    1093                 :          0 :         txq->txbuffs = rte_zmalloc_socket("txq->txbuffs",
    1094                 :            :                                 nb_desc * sizeof(struct rte_mbuf *),
    1095                 :          0 :                                 RTE_CACHE_LINE_SIZE, nic->node);
    1096                 :            : 
    1097         [ #  # ]:          0 :         if (txq->txbuffs == NULL) {
    1098                 :          0 :                 nicvf_dev_tx_queue_release(dev, nicvf_netdev_qidx(nic, qidx));
    1099                 :          0 :                 return -ENOMEM;
    1100                 :            :         }
    1101                 :            : 
    1102         [ #  # ]:          0 :         if (nicvf_qset_sq_alloc(dev, nic, txq, qidx, nb_desc)) {
    1103                 :          0 :                 PMD_INIT_LOG(ERR, "Failed to allocate mem for sq %d", qidx);
    1104                 :          0 :                 nicvf_dev_tx_queue_release(dev, nicvf_netdev_qidx(nic, qidx));
    1105                 :          0 :                 return -ENOMEM;
    1106                 :            :         }
    1107                 :            : 
    1108                 :          0 :         nicvf_tx_queue_reset(txq);
    1109                 :            : 
    1110         [ #  # ]:          0 :         PMD_INIT_LOG(DEBUG, "[%d] txq=%p nb_desc=%d desc=%p"
    1111                 :            :                         " phys=0x%" PRIx64 " offloads=0x%" PRIx64,
    1112                 :            :                         nicvf_netdev_qidx(nic, qidx), txq, nb_desc, txq->desc,
    1113                 :            :                         txq->phys, txq->offloads);
    1114                 :            : 
    1115         [ #  # ]:          0 :         dev->data->tx_queue_state[nicvf_netdev_qidx(nic, qidx)] =
    1116                 :            :                 RTE_ETH_QUEUE_STATE_STOPPED;
    1117                 :          0 :         return 0;
    1118                 :            : }
    1119                 :            : 
    1120                 :            : static inline void
    1121                 :          0 : nicvf_rx_queue_release_mbufs(struct rte_eth_dev *dev, struct nicvf_rxq *rxq)
    1122                 :            : {
    1123                 :            :         uint32_t rxq_cnt;
    1124                 :            :         uint32_t nb_pkts, released_pkts = 0;
    1125                 :            :         uint32_t refill_cnt = 0;
    1126                 :            :         struct rte_mbuf *rx_pkts[NICVF_MAX_RX_FREE_THRESH];
    1127                 :            : 
    1128         [ #  # ]:          0 :         if (dev->rx_pkt_burst == NULL)
    1129                 :          0 :                 return;
    1130                 :            : 
    1131         [ #  # ]:          0 :         while ((rxq_cnt = nicvf_dev_rx_queue_count(rxq))) {
    1132                 :          0 :                 nb_pkts = dev->rx_pkt_burst(rxq, rx_pkts,
    1133                 :            :                                         NICVF_MAX_RX_FREE_THRESH);
    1134                 :          0 :                 PMD_DRV_LOG(INFO, "nb_pkts=%d  rxq_cnt=%d", nb_pkts, rxq_cnt);
    1135         [ #  # ]:          0 :                 while (nb_pkts) {
    1136         [ #  # ]:          0 :                         rte_pktmbuf_free_seg(rx_pkts[--nb_pkts]);
    1137                 :          0 :                         released_pkts++;
    1138                 :            :                 }
    1139                 :            :         }
    1140                 :            : 
    1141                 :            : 
    1142                 :          0 :         refill_cnt += nicvf_dev_rbdr_refill(dev,
    1143         [ #  # ]:          0 :                         nicvf_netdev_qidx(rxq->nic, rxq->queue_id));
    1144                 :            : 
    1145                 :          0 :         PMD_DRV_LOG(INFO, "free_cnt=%d  refill_cnt=%d",
    1146                 :            :                     released_pkts, refill_cnt);
    1147                 :            : }
    1148                 :            : 
    1149                 :            : static void
    1150                 :            : nicvf_rx_queue_reset(struct nicvf_rxq *rxq)
    1151                 :            : {
    1152                 :          0 :         rxq->head = 0;
    1153                 :          0 :         rxq->available_space = 0;
    1154                 :          0 :         rxq->recv_buffers = 0;
    1155                 :            : }
    1156                 :            : 
    1157                 :            : static inline int
    1158                 :          0 : nicvf_vf_start_rx_queue(struct rte_eth_dev *dev, struct nicvf *nic,
    1159                 :            :                         uint16_t qidx)
    1160                 :            : {
    1161                 :            :         struct nicvf_rxq *rxq;
    1162                 :            :         int ret;
    1163                 :            : 
    1164         [ #  # ]:          0 :         assert(qidx < MAX_RCV_QUEUES_PER_QS);
    1165                 :            : 
    1166   [ #  #  #  # ]:          0 :         if (dev->data->rx_queue_state[nicvf_netdev_qidx(nic, qidx)] ==
    1167                 :            :                 RTE_ETH_QUEUE_STATE_STARTED)
    1168                 :            :                 return 0;
    1169                 :            : 
    1170                 :            :         /* Update rbdr pointer to all rxq */
    1171                 :          0 :         rxq = dev->data->rx_queues[nicvf_netdev_qidx(nic, qidx)];
    1172                 :          0 :         rxq->shared_rbdr = nic->rbdr;
    1173                 :            : 
    1174                 :          0 :         ret = nicvf_qset_rq_config(nic, qidx, rxq);
    1175         [ #  # ]:          0 :         if (ret) {
    1176                 :          0 :                 PMD_INIT_LOG(ERR, "Failed to configure rq VF%d %d %d",
    1177                 :            :                              nic->vf_id, qidx, ret);
    1178                 :          0 :                 goto config_rq_error;
    1179                 :            :         }
    1180                 :          0 :         ret = nicvf_qset_cq_config(nic, qidx, rxq);
    1181         [ #  # ]:          0 :         if (ret) {
    1182                 :          0 :                 PMD_INIT_LOG(ERR, "Failed to configure cq VF%d %d %d",
    1183                 :            :                              nic->vf_id, qidx, ret);
    1184                 :          0 :                 goto config_cq_error;
    1185                 :            :         }
    1186                 :            : 
    1187         [ #  # ]:          0 :         dev->data->rx_queue_state[nicvf_netdev_qidx(nic, qidx)] =
    1188                 :            :                 RTE_ETH_QUEUE_STATE_STARTED;
    1189                 :          0 :         return 0;
    1190                 :            : 
    1191                 :            : config_cq_error:
    1192                 :          0 :         nicvf_qset_cq_reclaim(nic, qidx);
    1193                 :          0 : config_rq_error:
    1194                 :          0 :         nicvf_qset_rq_reclaim(nic, qidx);
    1195                 :          0 :         return ret;
    1196                 :            : }
    1197                 :            : 
    1198                 :            : static inline int
    1199                 :          0 : nicvf_vf_stop_rx_queue(struct rte_eth_dev *dev, struct nicvf *nic,
    1200                 :            :                        uint16_t qidx)
    1201                 :            : {
    1202                 :            :         struct nicvf_rxq *rxq;
    1203                 :            :         int ret, other_error;
    1204                 :            : 
    1205   [ #  #  #  # ]:          0 :         if (dev->data->rx_queue_state[nicvf_netdev_qidx(nic, qidx)] ==
    1206                 :            :                 RTE_ETH_QUEUE_STATE_STOPPED)
    1207                 :            :                 return 0;
    1208                 :            : 
    1209                 :          0 :         ret = nicvf_qset_rq_reclaim(nic, qidx);
    1210         [ #  # ]:          0 :         if (ret)
    1211                 :          0 :                 PMD_INIT_LOG(ERR, "Failed to reclaim rq VF%d %d %d",
    1212                 :            :                              nic->vf_id, qidx, ret);
    1213                 :            : 
    1214                 :            :         other_error = ret;
    1215         [ #  # ]:          0 :         rxq = dev->data->rx_queues[nicvf_netdev_qidx(nic, qidx)];
    1216                 :          0 :         nicvf_rx_queue_release_mbufs(dev, rxq);
    1217                 :            :         nicvf_rx_queue_reset(rxq);
    1218                 :            : 
    1219                 :          0 :         ret = nicvf_qset_cq_reclaim(nic, qidx);
    1220         [ #  # ]:          0 :         if (ret)
    1221                 :          0 :                 PMD_INIT_LOG(ERR, "Failed to reclaim cq VF%d %d %d",
    1222                 :            :                              nic->vf_id, qidx, ret);
    1223                 :            : 
    1224                 :          0 :         other_error |= ret;
    1225         [ #  # ]:          0 :         dev->data->rx_queue_state[nicvf_netdev_qidx(nic, qidx)] =
    1226                 :            :                 RTE_ETH_QUEUE_STATE_STOPPED;
    1227                 :          0 :         return other_error;
    1228                 :            : }
    1229                 :            : 
    1230                 :            : static void
    1231                 :          0 : nicvf_dev_rx_queue_release(struct rte_eth_dev *dev, uint16_t qid)
    1232                 :            : {
    1233                 :          0 :         PMD_INIT_FUNC_TRACE();
    1234                 :            : 
    1235                 :          0 :         rte_free(dev->data->rx_queues[qid]);
    1236                 :          0 : }
    1237                 :            : 
    1238                 :            : static int
    1239         [ #  # ]:          0 : nicvf_dev_rx_queue_start(struct rte_eth_dev *dev, uint16_t qidx)
    1240                 :            : {
    1241                 :            :         struct nicvf *nic = nicvf_pmd_priv(dev);
    1242                 :            :         int ret;
    1243                 :            : 
    1244         [ #  # ]:          0 :         if (qidx >= MAX_RCV_QUEUES_PER_QS)
    1245                 :          0 :                 nic = nic->snicvf[(qidx / MAX_RCV_QUEUES_PER_QS - 1)];
    1246                 :            : 
    1247                 :          0 :         qidx = qidx % MAX_RCV_QUEUES_PER_QS;
    1248                 :            : 
    1249                 :          0 :         ret = nicvf_vf_start_rx_queue(dev, nic, qidx);
    1250         [ #  # ]:          0 :         if (ret)
    1251                 :            :                 return ret;
    1252                 :            : 
    1253                 :          0 :         ret = nicvf_configure_cpi(dev);
    1254         [ #  # ]:          0 :         if (ret)
    1255                 :            :                 return ret;
    1256                 :            : 
    1257                 :          0 :         return nicvf_configure_rss_reta(dev);
    1258                 :            : }
    1259                 :            : 
    1260                 :            : static int
    1261         [ #  # ]:          0 : nicvf_dev_rx_queue_stop(struct rte_eth_dev *dev, uint16_t qidx)
    1262                 :            : {
    1263                 :            :         int ret;
    1264                 :            :         struct nicvf *nic = nicvf_pmd_priv(dev);
    1265                 :            : 
    1266         [ #  # ]:          0 :         if (qidx >= MAX_SND_QUEUES_PER_QS)
    1267                 :          0 :                 nic = nic->snicvf[(qidx / MAX_SND_QUEUES_PER_QS - 1)];
    1268                 :            : 
    1269                 :          0 :         qidx = qidx % MAX_RCV_QUEUES_PER_QS;
    1270                 :            : 
    1271                 :          0 :         ret = nicvf_vf_stop_rx_queue(dev, nic, qidx);
    1272                 :          0 :         ret |= nicvf_configure_cpi(dev);
    1273                 :          0 :         ret |= nicvf_configure_rss_reta(dev);
    1274                 :          0 :         return ret;
    1275                 :            : }
    1276                 :            : 
    1277                 :            : static int
    1278         [ #  # ]:          0 : nicvf_dev_tx_queue_start(struct rte_eth_dev *dev, uint16_t qidx)
    1279                 :            : {
    1280                 :            :         struct nicvf *nic = nicvf_pmd_priv(dev);
    1281                 :            : 
    1282         [ #  # ]:          0 :         if (qidx >= MAX_SND_QUEUES_PER_QS)
    1283                 :          0 :                 nic = nic->snicvf[(qidx / MAX_SND_QUEUES_PER_QS - 1)];
    1284                 :            : 
    1285                 :          0 :         qidx = qidx % MAX_SND_QUEUES_PER_QS;
    1286                 :            : 
    1287                 :          0 :         return nicvf_vf_start_tx_queue(dev, nic, qidx);
    1288                 :            : }
    1289                 :            : 
    1290                 :            : static int
    1291         [ #  # ]:          0 : nicvf_dev_tx_queue_stop(struct rte_eth_dev *dev, uint16_t qidx)
    1292                 :            : {
    1293                 :            :         struct nicvf *nic = nicvf_pmd_priv(dev);
    1294                 :            : 
    1295         [ #  # ]:          0 :         if (qidx >= MAX_SND_QUEUES_PER_QS)
    1296                 :          0 :                 nic = nic->snicvf[(qidx / MAX_SND_QUEUES_PER_QS - 1)];
    1297                 :            : 
    1298                 :          0 :         qidx = qidx % MAX_SND_QUEUES_PER_QS;
    1299                 :            : 
    1300                 :          0 :         return nicvf_vf_stop_tx_queue(dev, nic, qidx);
    1301                 :            : }
    1302                 :            : 
    1303                 :            : static inline void
    1304                 :          0 : nicvf_rxq_mbuf_setup(struct nicvf_rxq *rxq)
    1305                 :            : {
    1306                 :            :         uintptr_t p;
    1307                 :            :         struct rte_mbuf mb_def;
    1308                 :          0 :         struct nicvf *nic = rxq->nic;
    1309                 :            : 
    1310                 :            :         RTE_BUILD_BUG_ON(sizeof(union mbuf_initializer) != 8);
    1311                 :            :         RTE_BUILD_BUG_ON(offsetof(struct rte_mbuf, data_off) % 8 != 0);
    1312                 :            :         RTE_BUILD_BUG_ON(offsetof(struct rte_mbuf, refcnt) -
    1313                 :            :                                 offsetof(struct rte_mbuf, data_off) != 2);
    1314                 :            :         RTE_BUILD_BUG_ON(offsetof(struct rte_mbuf, nb_segs) -
    1315                 :            :                                 offsetof(struct rte_mbuf, data_off) != 4);
    1316                 :            :         RTE_BUILD_BUG_ON(offsetof(struct rte_mbuf, port) -
    1317                 :            :                                 offsetof(struct rte_mbuf, data_off) != 6);
    1318                 :            :         RTE_BUILD_BUG_ON(offsetof(struct nicvf_rxq, rxq_fastpath_data_end) -
    1319                 :            :                                 offsetof(struct nicvf_rxq,
    1320                 :            :                                         rxq_fastpath_data_start) > 128);
    1321                 :          0 :         mb_def.nb_segs = 1;
    1322                 :          0 :         mb_def.data_off = RTE_PKTMBUF_HEADROOM + (nic->skip_bytes);
    1323                 :          0 :         mb_def.port = rxq->port_id;
    1324                 :            :         rte_mbuf_refcnt_set(&mb_def, 1);
    1325                 :            : 
    1326                 :            :         /* Prevent compiler reordering: rearm_data covers previous fields */
    1327                 :          0 :         rte_compiler_barrier();
    1328                 :            :         p = (uintptr_t)&mb_def.rearm_data;
    1329                 :          0 :         rxq->mbuf_initializer.value = *(uint64_t *)p;
    1330                 :          0 : }
    1331                 :            : 
    1332                 :            : static int
    1333                 :          0 : nicvf_dev_rx_queue_setup(struct rte_eth_dev *dev, uint16_t qidx,
    1334                 :            :                          uint16_t nb_desc, unsigned int socket_id,
    1335                 :            :                          const struct rte_eth_rxconf *rx_conf,
    1336                 :            :                          struct rte_mempool *mp)
    1337                 :            : {
    1338                 :            :         uint16_t rx_free_thresh;
    1339                 :            :         struct nicvf_rxq *rxq;
    1340                 :            :         struct nicvf *nic = nicvf_pmd_priv(dev);
    1341                 :            :         uint64_t offloads;
    1342                 :            :         uint32_t buffsz;
    1343                 :            :         struct rte_pktmbuf_pool_private *mbp_priv;
    1344                 :            : 
    1345                 :          0 :         PMD_INIT_FUNC_TRACE();
    1346                 :            : 
    1347                 :            :         /* First skip check */
    1348                 :            :         mbp_priv = rte_mempool_get_priv(mp);
    1349                 :          0 :         buffsz = mbp_priv->mbuf_data_room_size - RTE_PKTMBUF_HEADROOM;
    1350         [ #  # ]:          0 :         if (buffsz < (uint32_t)(nic->skip_bytes)) {
    1351                 :          0 :                 PMD_INIT_LOG(ERR, "First skip is more than configured buffer size");
    1352                 :          0 :                 return -EINVAL;
    1353                 :            :         }
    1354                 :            : 
    1355         [ #  # ]:          0 :         if (qidx >= MAX_RCV_QUEUES_PER_QS)
    1356                 :          0 :                 nic = nic->snicvf[qidx / MAX_RCV_QUEUES_PER_QS - 1];
    1357                 :            : 
    1358                 :          0 :         qidx = qidx % MAX_RCV_QUEUES_PER_QS;
    1359                 :            : 
    1360                 :            :         /* Socket id check */
    1361   [ #  #  #  # ]:          0 :         if (socket_id != (unsigned int)SOCKET_ID_ANY && socket_id != nic->node)
    1362                 :          0 :                 PMD_DRV_LOG(WARNING, "socket_id expected %d, configured %d",
    1363                 :            :                 socket_id, nic->node);
    1364                 :            : 
    1365                 :            :         /* Mempool memory must be contiguous, so must be one memory segment*/
    1366         [ #  # ]:          0 :         if (mp->nb_mem_chunks != 1) {
    1367                 :          0 :                 PMD_INIT_LOG(ERR, "Non-contiguous mempool, add more huge pages");
    1368                 :          0 :                 return -EINVAL;
    1369                 :            :         }
    1370                 :            : 
    1371                 :            :         /* Mempool memory must be physically contiguous */
    1372         [ #  # ]:          0 :         if (mp->flags & RTE_MEMPOOL_F_NO_IOVA_CONTIG) {
    1373                 :          0 :                 PMD_INIT_LOG(ERR, "Mempool memory must be physically contiguous");
    1374                 :          0 :                 return -EINVAL;
    1375                 :            :         }
    1376                 :            : 
    1377                 :            :         /* Rx deferred start is not supported */
    1378         [ #  # ]:          0 :         if (rx_conf->rx_deferred_start) {
    1379                 :          0 :                 PMD_INIT_LOG(ERR, "Rx deferred start not supported");
    1380                 :          0 :                 return -EINVAL;
    1381                 :            :         }
    1382                 :            : 
    1383                 :            :         /* Roundup nb_desc to available qsize and validate max number of desc */
    1384                 :          0 :         nb_desc = nicvf_qsize_cq_roundup(nb_desc);
    1385         [ #  # ]:          0 :         if (nb_desc == 0) {
    1386                 :          0 :                 PMD_INIT_LOG(ERR, "Value nb_desc beyond available hw cq qsize");
    1387                 :          0 :                 return -EINVAL;
    1388                 :            :         }
    1389                 :            : 
    1390                 :            : 
    1391                 :            :         /* Check rx_free_thresh upper bound */
    1392         [ #  # ]:          0 :         rx_free_thresh = (uint16_t)((rx_conf->rx_free_thresh) ?
    1393                 :            :                                 rx_conf->rx_free_thresh :
    1394                 :            :                                 NICVF_DEFAULT_RX_FREE_THRESH);
    1395         [ #  # ]:          0 :         if (rx_free_thresh > NICVF_MAX_RX_FREE_THRESH ||
    1396         [ #  # ]:          0 :                 rx_free_thresh >= nb_desc * .75) {
    1397                 :          0 :                 PMD_INIT_LOG(ERR, "rx_free_thresh greater than expected %d",
    1398                 :            :                                 rx_free_thresh);
    1399                 :          0 :                 return -EINVAL;
    1400                 :            :         }
    1401                 :            : 
    1402                 :            :         /* Free memory prior to re-allocation if needed */
    1403   [ #  #  #  # ]:          0 :         if (dev->data->rx_queues[nicvf_netdev_qidx(nic, qidx)] != NULL) {
    1404                 :          0 :                 PMD_RX_LOG(DEBUG, "Freeing memory prior to re-allocation %d",
    1405                 :            :                                 nicvf_netdev_qidx(nic, qidx));
    1406                 :          0 :                 nicvf_dev_rx_queue_release(dev, nicvf_netdev_qidx(nic, qidx));
    1407         [ #  # ]:          0 :                 dev->data->rx_queues[nicvf_netdev_qidx(nic, qidx)] = NULL;
    1408                 :            :         }
    1409                 :            : 
    1410                 :            :         /* Allocate rxq memory */
    1411                 :          0 :         rxq = rte_zmalloc_socket("ethdev rx queue", sizeof(struct nicvf_rxq),
    1412                 :          0 :                                         RTE_CACHE_LINE_SIZE, nic->node);
    1413         [ #  # ]:          0 :         if (rxq == NULL) {
    1414                 :          0 :                 PMD_INIT_LOG(ERR, "Failed to allocate rxq=%d",
    1415                 :            :                              nicvf_netdev_qidx(nic, qidx));
    1416                 :          0 :                 return -ENOMEM;
    1417                 :            :         }
    1418                 :            : 
    1419                 :          0 :         rxq->nic = nic;
    1420                 :          0 :         rxq->pool = mp;
    1421                 :          0 :         rxq->queue_id = qidx;
    1422                 :          0 :         rxq->port_id = dev->data->port_id;
    1423                 :          0 :         rxq->rx_free_thresh = rx_free_thresh;
    1424                 :          0 :         rxq->rx_drop_en = rx_conf->rx_drop_en;
    1425         [ #  # ]:          0 :         rxq->cq_status = nicvf_qset_base(nic, qidx) + NIC_QSET_CQ_0_7_STATUS;
    1426                 :          0 :         rxq->cq_door = nicvf_qset_base(nic, qidx) + NIC_QSET_CQ_0_7_DOOR;
    1427         [ #  # ]:          0 :         rxq->precharge_cnt = 0;
    1428                 :            : 
    1429         [ #  # ]:          0 :         if (nicvf_hw_cap(nic) & NICVF_CAP_CQE_RX2)
    1430                 :          0 :                 rxq->rbptr_offset = NICVF_CQE_RX2_RBPTR_WORD;
    1431                 :            :         else
    1432                 :          0 :                 rxq->rbptr_offset = NICVF_CQE_RBPTR_WORD;
    1433                 :            : 
    1434         [ #  # ]:          0 :         dev->data->rx_queues[nicvf_netdev_qidx(nic, qidx)] = rxq;
    1435                 :            : 
    1436                 :          0 :         nicvf_rxq_mbuf_setup(rxq);
    1437                 :            : 
    1438                 :            :         /* Alloc completion queue */
    1439         [ #  # ]:          0 :         if (nicvf_qset_cq_alloc(dev, nic, rxq, rxq->queue_id, nb_desc)) {
    1440                 :          0 :                 PMD_INIT_LOG(ERR, "failed to allocate cq %u", rxq->queue_id);
    1441                 :          0 :                 nicvf_dev_rx_queue_release(dev, nicvf_netdev_qidx(nic, qidx));
    1442                 :          0 :                 return -ENOMEM;
    1443                 :            :         }
    1444                 :            : 
    1445                 :            :         nicvf_rx_queue_reset(rxq);
    1446                 :            : 
    1447                 :          0 :         offloads = rx_conf->offloads | dev->data->dev_conf.rxmode.offloads;
    1448         [ #  # ]:          0 :         PMD_INIT_LOG(DEBUG, "[%d] rxq=%p pool=%s nb_desc=(%d/%d)"
    1449                 :            :                         " phy=0x%" PRIx64 " offloads=0x%" PRIx64,
    1450                 :            :                         nicvf_netdev_qidx(nic, qidx), rxq, mp->name, nb_desc,
    1451                 :            :                         rte_mempool_avail_count(mp), rxq->phys, offloads);
    1452                 :            : 
    1453         [ #  # ]:          0 :         dev->data->rx_queue_state[nicvf_netdev_qidx(nic, qidx)] =
    1454                 :            :                 RTE_ETH_QUEUE_STATE_STOPPED;
    1455                 :          0 :         return 0;
    1456                 :            : }
    1457                 :            : 
    1458                 :            : static int
    1459                 :          0 : nicvf_dev_info_get(struct rte_eth_dev *dev, struct rte_eth_dev_info *dev_info)
    1460                 :            : {
    1461                 :            :         struct nicvf *nic = nicvf_pmd_priv(dev);
    1462                 :          0 :         struct rte_pci_device *pci_dev = RTE_ETH_DEV_TO_PCI(dev);
    1463                 :            : 
    1464                 :          0 :         PMD_INIT_FUNC_TRACE();
    1465                 :            : 
    1466                 :            :         /* Autonegotiation may be disabled */
    1467                 :            :         dev_info->speed_capa = RTE_ETH_LINK_SPEED_FIXED;
    1468         [ #  # ]:          0 :         dev_info->speed_capa |= RTE_ETH_LINK_SPEED_10M | RTE_ETH_LINK_SPEED_100M |
    1469                 :            :                                  RTE_ETH_LINK_SPEED_1G | RTE_ETH_LINK_SPEED_10G;
    1470         [ #  # ]:          0 :         if (nicvf_hw_version(nic) != PCI_SUB_DEVICE_ID_CN81XX_NICVF)
    1471                 :          0 :                 dev_info->speed_capa |= RTE_ETH_LINK_SPEED_40G;
    1472                 :            : 
    1473                 :          0 :         dev_info->min_rx_bufsize = RTE_ETHER_MIN_MTU;
    1474                 :          0 :         dev_info->max_rx_pktlen = NIC_HW_MAX_MTU + RTE_ETHER_HDR_LEN;
    1475                 :          0 :         dev_info->max_rx_queues =
    1476                 :            :                         (uint16_t)MAX_RCV_QUEUES_PER_QS * (MAX_SQS_PER_VF + 1);
    1477                 :          0 :         dev_info->max_tx_queues =
    1478                 :            :                         (uint16_t)MAX_SND_QUEUES_PER_QS * (MAX_SQS_PER_VF + 1);
    1479                 :          0 :         dev_info->max_mac_addrs = 1;
    1480                 :          0 :         dev_info->max_vfs = pci_dev->max_vfs;
    1481                 :            : 
    1482                 :          0 :         dev_info->max_mtu = dev_info->max_rx_pktlen -
    1483                 :            :                                 (RTE_ETHER_HDR_LEN + RTE_ETHER_CRC_LEN);
    1484                 :          0 :         dev_info->min_mtu = dev_info->min_rx_bufsize - NIC_HW_L2_OVERHEAD;
    1485                 :            : 
    1486                 :          0 :         dev_info->rx_offload_capa = NICVF_RX_OFFLOAD_CAPA;
    1487                 :          0 :         dev_info->tx_offload_capa = NICVF_TX_OFFLOAD_CAPA;
    1488                 :          0 :         dev_info->rx_queue_offload_capa = NICVF_RX_OFFLOAD_CAPA;
    1489                 :          0 :         dev_info->tx_queue_offload_capa = NICVF_TX_OFFLOAD_CAPA;
    1490                 :            : 
    1491                 :          0 :         dev_info->reta_size = nic->rss_info.rss_size;
    1492                 :          0 :         dev_info->hash_key_size = RSS_HASH_KEY_BYTE_SIZE;
    1493         [ #  # ]:          0 :         dev_info->flow_type_rss_offloads = NICVF_RSS_OFFLOAD_PASS1;
    1494         [ #  # ]:          0 :         if (nicvf_hw_cap(nic) & NICVF_CAP_TUNNEL_PARSING)
    1495                 :          0 :                 dev_info->flow_type_rss_offloads |= NICVF_RSS_OFFLOAD_TUNNEL;
    1496                 :            : 
    1497                 :          0 :         dev_info->default_rxconf = (struct rte_eth_rxconf) {
    1498                 :            :                 .rx_free_thresh = NICVF_DEFAULT_RX_FREE_THRESH,
    1499                 :            :                 .rx_drop_en = 0,
    1500                 :            :         };
    1501                 :            : 
    1502                 :          0 :         dev_info->default_txconf = (struct rte_eth_txconf) {
    1503                 :            :                 .tx_free_thresh = NICVF_DEFAULT_TX_FREE_THRESH,
    1504                 :            :                 .offloads = RTE_ETH_TX_OFFLOAD_MBUF_FAST_FREE |
    1505                 :            :                         RTE_ETH_TX_OFFLOAD_OUTER_IPV4_CKSUM   |
    1506                 :            :                         RTE_ETH_TX_OFFLOAD_UDP_CKSUM          |
    1507                 :            :                         RTE_ETH_TX_OFFLOAD_TCP_CKSUM,
    1508                 :            :         };
    1509                 :            : 
    1510                 :          0 :         return 0;
    1511                 :            : }
    1512                 :            : 
    1513                 :            : static nicvf_iova_addr_t
    1514         [ #  # ]:          0 : rbdr_rte_mempool_get(void *dev, void *opaque)
    1515                 :            : {
    1516                 :            :         uint16_t qidx;
    1517                 :            :         uintptr_t mbuf;
    1518                 :            :         struct nicvf_rxq *rxq;
    1519                 :            :         struct rte_eth_dev *eth_dev = (struct rte_eth_dev *)dev;
    1520                 :            :         struct nicvf *nic = (struct nicvf *)opaque;
    1521                 :            :         uint16_t rx_start, rx_end;
    1522                 :            : 
    1523                 :            :         /* Get queue ranges for this VF */
    1524                 :            :         nicvf_rx_range(eth_dev, nic, &rx_start, &rx_end);
    1525                 :            : 
    1526         [ #  # ]:          0 :         for (qidx = rx_start; qidx <= rx_end; qidx++) {
    1527                 :          0 :                 rxq = eth_dev->data->rx_queues[qidx];
    1528                 :            :                 /* Maintain equal buffer count across all pools */
    1529         [ #  # ]:          0 :                 if (rxq->precharge_cnt >= rxq->qlen_mask)
    1530                 :          0 :                         continue;
    1531                 :          0 :                 rxq->precharge_cnt++;
    1532                 :          0 :                 mbuf = (uintptr_t)rte_pktmbuf_alloc(rxq->pool);
    1533         [ #  # ]:          0 :                 if (mbuf)
    1534                 :          0 :                         return nicvf_mbuff_virt2phy(mbuf, rxq->mbuf_phys_off);
    1535                 :            :         }
    1536                 :            :         return 0;
    1537                 :            : }
    1538                 :            : 
    1539                 :            : static int
    1540                 :          0 : nicvf_vf_start(struct rte_eth_dev *dev, struct nicvf *nic, uint32_t rbdrsz)
    1541                 :            : {
    1542                 :            :         int ret;
    1543                 :            :         uint16_t qidx, data_off;
    1544                 :            :         uint32_t total_rxq_desc, nb_rbdr_desc, exp_buffs;
    1545                 :            :         uint64_t mbuf_phys_off = 0;
    1546                 :            :         struct nicvf_rxq *rxq;
    1547                 :            :         struct rte_mbuf *mbuf;
    1548                 :            :         uint16_t rx_start, rx_end;
    1549                 :            :         uint16_t tx_start, tx_end;
    1550                 :            :         int mask;
    1551                 :            : 
    1552                 :          0 :         PMD_INIT_FUNC_TRACE();
    1553                 :            : 
    1554                 :            :         /* Userspace process exited without proper shutdown in last run */
    1555         [ #  # ]:          0 :         if (nicvf_qset_rbdr_active(nic, 0))
    1556                 :          0 :                 nicvf_vf_stop(dev, nic, false);
    1557                 :            : 
    1558                 :            :         /* Get queue ranges for this VF */
    1559                 :            :         nicvf_rx_range(dev, nic, &rx_start, &rx_end);
    1560                 :            : 
    1561                 :            :         /*
    1562                 :            :          * Thunderx nicvf PMD can support more than one pool per port only when
    1563                 :            :          * 1) Data payload size is same across all the pools in given port
    1564                 :            :          * AND
    1565                 :            :          * 2) All mbuffs in the pools are from the same hugepage
    1566                 :            :          * AND
    1567                 :            :          * 3) Mbuff metadata size is same across all the pools in given port
    1568                 :            :          *
    1569                 :            :          * This is to support existing application that uses multiple pool/port.
    1570                 :            :          * But, the purpose of using multipool for QoS will not be addressed.
    1571                 :            :          *
    1572                 :            :          */
    1573                 :            : 
    1574                 :            :         /* Validate mempool attributes */
    1575         [ #  # ]:          0 :         for (qidx = rx_start; qidx <= rx_end; qidx++) {
    1576                 :          0 :                 rxq = dev->data->rx_queues[qidx];
    1577                 :          0 :                 rxq->mbuf_phys_off = nicvf_mempool_phy_offset(rxq->pool);
    1578                 :          0 :                 mbuf = rte_pktmbuf_alloc(rxq->pool);
    1579         [ #  # ]:          0 :                 if (mbuf == NULL) {
    1580                 :          0 :                         PMD_INIT_LOG(ERR, "Failed allocate mbuf VF%d qid=%d "
    1581                 :            :                                      "pool=%s",
    1582                 :            :                                      nic->vf_id, qidx, rxq->pool->name);
    1583                 :          0 :                         return -ENOMEM;
    1584                 :            :                 }
    1585                 :            :                 data_off = nicvf_mbuff_meta_length(mbuf);
    1586                 :          0 :                 data_off += RTE_PKTMBUF_HEADROOM;
    1587                 :          0 :                 rte_pktmbuf_free(mbuf);
    1588                 :            : 
    1589         [ #  # ]:          0 :                 if (data_off % RTE_CACHE_LINE_SIZE) {
    1590                 :          0 :                         PMD_INIT_LOG(ERR, "%s: unaligned data_off=%d delta=%d",
    1591                 :            :                                 rxq->pool->name, data_off,
    1592                 :            :                                 data_off % RTE_CACHE_LINE_SIZE);
    1593                 :          0 :                         return -EINVAL;
    1594                 :            :                 }
    1595                 :          0 :                 rxq->mbuf_phys_off -= data_off;
    1596                 :          0 :                 rxq->mbuf_phys_off -= nic->skip_bytes;
    1597                 :            : 
    1598         [ #  # ]:          0 :                 if (mbuf_phys_off == 0)
    1599                 :            :                         mbuf_phys_off = rxq->mbuf_phys_off;
    1600         [ #  # ]:          0 :                 if (mbuf_phys_off != rxq->mbuf_phys_off) {
    1601                 :          0 :                         PMD_INIT_LOG(ERR, "pool params not same,%s VF%d %"
    1602                 :            :                                      PRIx64, rxq->pool->name, nic->vf_id,
    1603                 :            :                                      mbuf_phys_off);
    1604                 :          0 :                         return -EINVAL;
    1605                 :            :                 }
    1606                 :            :         }
    1607                 :            : 
    1608                 :            :         /* Check the level of buffers in the pool */
    1609                 :            :         total_rxq_desc = 0;
    1610         [ #  # ]:          0 :         for (qidx = rx_start; qidx <= rx_end; qidx++) {
    1611                 :          0 :                 rxq = dev->data->rx_queues[qidx];
    1612                 :            :                 /* Count total numbers of rxq descs */
    1613                 :          0 :                 total_rxq_desc += rxq->qlen_mask + 1;
    1614                 :          0 :                 exp_buffs = RTE_MEMPOOL_CACHE_MAX_SIZE + rxq->rx_free_thresh;
    1615                 :          0 :                 exp_buffs *= dev->data->nb_rx_queues;
    1616         [ #  # ]:          0 :                 if (rte_mempool_avail_count(rxq->pool) < exp_buffs) {
    1617                 :          0 :                         PMD_INIT_LOG(ERR, "Buff shortage in pool=%s (%d/%d)",
    1618                 :            :                                      rxq->pool->name,
    1619                 :            :                                      rte_mempool_avail_count(rxq->pool),
    1620                 :            :                                      exp_buffs);
    1621                 :          0 :                         return -ENOENT;
    1622                 :            :                 }
    1623                 :            :         }
    1624                 :            : 
    1625                 :            :         /* Check RBDR desc overflow */
    1626                 :          0 :         ret = nicvf_qsize_rbdr_roundup(total_rxq_desc);
    1627         [ #  # ]:          0 :         if (ret == 0) {
    1628                 :          0 :                 PMD_INIT_LOG(ERR, "Reached RBDR desc limit, reduce nr desc "
    1629                 :            :                              "VF%d", nic->vf_id);
    1630                 :          0 :                 return -ENOMEM;
    1631                 :            :         }
    1632                 :            : 
    1633                 :            :         /* Enable qset */
    1634                 :          0 :         ret = nicvf_qset_config(nic);
    1635         [ #  # ]:          0 :         if (ret) {
    1636                 :          0 :                 PMD_INIT_LOG(ERR, "Failed to enable qset %d VF%d", ret,
    1637                 :            :                              nic->vf_id);
    1638                 :          0 :                 return ret;
    1639                 :            :         }
    1640                 :            : 
    1641                 :            :         /* Allocate RBDR and RBDR ring desc */
    1642                 :          0 :         nb_rbdr_desc = nicvf_qsize_rbdr_roundup(total_rxq_desc);
    1643                 :          0 :         ret = nicvf_qset_rbdr_alloc(dev, nic, nb_rbdr_desc, rbdrsz);
    1644         [ #  # ]:          0 :         if (ret) {
    1645                 :          0 :                 PMD_INIT_LOG(ERR, "Failed to allocate memory for rbdr alloc "
    1646                 :            :                              "VF%d", nic->vf_id);
    1647                 :          0 :                 goto qset_reclaim;
    1648                 :            :         }
    1649                 :            : 
    1650                 :            :         /* Enable and configure RBDR registers */
    1651                 :          0 :         ret = nicvf_qset_rbdr_config(nic, 0);
    1652         [ #  # ]:          0 :         if (ret) {
    1653                 :          0 :                 PMD_INIT_LOG(ERR, "Failed to configure rbdr %d VF%d", ret,
    1654                 :            :                              nic->vf_id);
    1655                 :          0 :                 goto qset_rbdr_free;
    1656                 :            :         }
    1657                 :            : 
    1658                 :            :         /* Fill rte_mempool buffers in RBDR pool and precharge it */
    1659                 :          0 :         ret = nicvf_qset_rbdr_precharge(dev, nic, 0, rbdr_rte_mempool_get,
    1660                 :            :                                         total_rxq_desc);
    1661         [ #  # ]:          0 :         if (ret) {
    1662                 :          0 :                 PMD_INIT_LOG(ERR, "Failed to fill rbdr %d VF%d", ret,
    1663                 :            :                              nic->vf_id);
    1664                 :          0 :                 goto qset_rbdr_reclaim;
    1665                 :            :         }
    1666                 :            : 
    1667                 :          0 :         PMD_DRV_LOG(INFO, "Filled %d out of %d entries in RBDR VF%d",
    1668                 :            :                      nic->rbdr->tail, nb_rbdr_desc, nic->vf_id);
    1669                 :            : 
    1670                 :            :         /* Configure VLAN Strip */
    1671                 :            :         mask = RTE_ETH_VLAN_STRIP_MASK | RTE_ETH_VLAN_FILTER_MASK |
    1672                 :            :                 RTE_ETH_VLAN_EXTEND_MASK;
    1673                 :          0 :         ret = nicvf_vlan_offload_config(dev, mask);
    1674                 :            : 
    1675                 :            :         /* Based on the packet type(IPv4 or IPv6), the nicvf HW aligns L3 data
    1676                 :            :          * to the 64bit memory address.
    1677                 :            :          * The alignment creates a hole in mbuf(between the end of headroom and
    1678                 :            :          * packet data start). The new revision of the HW provides an option to
    1679                 :            :          * disable the L3 alignment feature and make mbuf layout looks
    1680                 :            :          * more like other NICs. For better application compatibility, disabling
    1681                 :            :          * l3 alignment feature on the hardware revisions it supports
    1682                 :            :          */
    1683                 :          0 :         nicvf_apad_config(nic, false);
    1684                 :            : 
    1685                 :            :         /* Get queue ranges for this VF */
    1686                 :            :         nicvf_tx_range(dev, nic, &tx_start, &tx_end);
    1687                 :            : 
    1688                 :            :         /* Configure TX queues */
    1689         [ #  # ]:          0 :         for (qidx = tx_start; qidx <= tx_end; qidx++) {
    1690                 :          0 :                 ret = nicvf_vf_start_tx_queue(dev, nic,
    1691                 :            :                         qidx % MAX_SND_QUEUES_PER_QS);
    1692         [ #  # ]:          0 :                 if (ret)
    1693                 :          0 :                         goto start_txq_error;
    1694                 :            :         }
    1695                 :            : 
    1696                 :            :         /* Configure RX queues */
    1697         [ #  # ]:          0 :         for (qidx = rx_start; qidx <= rx_end; qidx++) {
    1698                 :          0 :                 ret = nicvf_vf_start_rx_queue(dev, nic,
    1699                 :            :                         qidx % MAX_RCV_QUEUES_PER_QS);
    1700         [ #  # ]:          0 :                 if (ret)
    1701                 :          0 :                         goto start_rxq_error;
    1702                 :            :         }
    1703                 :            : 
    1704         [ #  # ]:          0 :         if (!nic->sqs_mode) {
    1705                 :            :                 /* Configure CPI algorithm */
    1706                 :          0 :                 ret = nicvf_configure_cpi(dev);
    1707         [ #  # ]:          0 :                 if (ret)
    1708                 :          0 :                         goto start_txq_error;
    1709                 :            : 
    1710                 :          0 :                 ret = nicvf_mbox_get_rss_size(nic);
    1711         [ #  # ]:          0 :                 if (ret) {
    1712                 :          0 :                         PMD_INIT_LOG(ERR, "Failed to get rss table size");
    1713                 :          0 :                         goto qset_rss_error;
    1714                 :            :                 }
    1715                 :            : 
    1716                 :            :                 /* Configure RSS */
    1717                 :          0 :                 ret = nicvf_configure_rss(dev);
    1718         [ #  # ]:          0 :                 if (ret)
    1719                 :          0 :                         goto qset_rss_error;
    1720                 :            :         }
    1721                 :            : 
    1722                 :            :         /* Done; Let PF make the BGX's RX and TX switches to ON position */
    1723                 :          0 :         nicvf_mbox_cfg_done(nic);
    1724                 :          0 :         return 0;
    1725                 :            : 
    1726                 :          0 : qset_rss_error:
    1727                 :          0 :         nicvf_rss_term(nic);
    1728                 :          0 : start_rxq_error:
    1729         [ #  # ]:          0 :         for (qidx = rx_start; qidx <= rx_end; qidx++)
    1730                 :          0 :                 nicvf_vf_stop_rx_queue(dev, nic, qidx % MAX_RCV_QUEUES_PER_QS);
    1731                 :          0 : start_txq_error:
    1732         [ #  # ]:          0 :         for (qidx = tx_start; qidx <= tx_end; qidx++)
    1733                 :          0 :                 nicvf_vf_stop_tx_queue(dev, nic, qidx % MAX_SND_QUEUES_PER_QS);
    1734                 :          0 : qset_rbdr_reclaim:
    1735                 :          0 :         nicvf_qset_rbdr_reclaim(nic, 0);
    1736                 :          0 :         nicvf_rbdr_release_mbufs(dev, nic);
    1737                 :          0 : qset_rbdr_free:
    1738         [ #  # ]:          0 :         if (nic->rbdr) {
    1739                 :          0 :                 rte_free(nic->rbdr);
    1740                 :          0 :                 nic->rbdr = NULL;
    1741                 :            :         }
    1742                 :          0 : qset_reclaim:
    1743                 :          0 :         nicvf_qset_reclaim(nic);
    1744                 :          0 :         return ret;
    1745                 :            : }
    1746                 :            : 
    1747                 :            : static int
    1748                 :          0 : nicvf_dev_start(struct rte_eth_dev *dev)
    1749                 :            : {
    1750                 :            :         uint16_t qidx;
    1751                 :            :         int ret;
    1752                 :            :         size_t i;
    1753                 :            :         struct nicvf *nic = nicvf_pmd_priv(dev);
    1754                 :            :         struct rte_eth_rxmode *rx_conf = &dev->data->dev_conf.rxmode;
    1755                 :            :         uint16_t mtu;
    1756                 :            :         uint32_t buffsz = 0, rbdrsz = 0;
    1757                 :            :         struct rte_pktmbuf_pool_private *mbp_priv;
    1758                 :            :         struct nicvf_rxq *rxq;
    1759                 :            : 
    1760                 :          0 :         PMD_INIT_FUNC_TRACE();
    1761                 :            : 
    1762                 :            :         /* This function must be called for a primary device */
    1763         [ #  # ]:          0 :         assert_primary(nic);
    1764                 :            : 
    1765                 :            :         /* Validate RBDR buff size */
    1766         [ #  # ]:          0 :         for (qidx = 0; qidx < dev->data->nb_rx_queues; qidx++) {
    1767                 :          0 :                 rxq = dev->data->rx_queues[qidx];
    1768         [ #  # ]:          0 :                 mbp_priv = rte_mempool_get_priv(rxq->pool);
    1769                 :          0 :                 buffsz = mbp_priv->mbuf_data_room_size - RTE_PKTMBUF_HEADROOM;
    1770         [ #  # ]:          0 :                 if (buffsz % 128) {
    1771                 :          0 :                         PMD_INIT_LOG(ERR, "rxbuf size must be multiply of 128");
    1772                 :          0 :                         return -EINVAL;
    1773                 :            :                 }
    1774         [ #  # ]:          0 :                 if (rbdrsz == 0)
    1775                 :            :                         rbdrsz = buffsz;
    1776         [ #  # ]:          0 :                 if (rbdrsz != buffsz) {
    1777                 :          0 :                         PMD_INIT_LOG(ERR, "buffsz not same, qidx=%d (%d/%d)",
    1778                 :            :                                      qidx, rbdrsz, buffsz);
    1779                 :          0 :                         return -EINVAL;
    1780                 :            :                 }
    1781                 :            :         }
    1782                 :            : 
    1783                 :            :         /* Configure loopback */
    1784                 :          0 :         ret = nicvf_loopback_config(nic, dev->data->dev_conf.lpbk_mode);
    1785         [ #  # ]:          0 :         if (ret) {
    1786                 :          0 :                 PMD_INIT_LOG(ERR, "Failed to configure loopback %d", ret);
    1787                 :          0 :                 return ret;
    1788                 :            :         }
    1789                 :            : 
    1790                 :            :         /* Reset all statistics counters attached to this port */
    1791                 :          0 :         ret = nicvf_mbox_reset_stat_counters(nic, 0x3FFF, 0x1F, 0xFFFF, 0xFFFF);
    1792         [ #  # ]:          0 :         if (ret) {
    1793                 :          0 :                 PMD_INIT_LOG(ERR, "Failed to reset stat counters %d", ret);
    1794                 :          0 :                 return ret;
    1795                 :            :         }
    1796                 :            : 
    1797                 :            :         /* Setup scatter mode if needed by jumbo */
    1798         [ #  # ]:          0 :         if (dev->data->mtu + (uint32_t)NIC_HW_L2_OVERHEAD + 2 * VLAN_TAG_SIZE > buffsz)
    1799                 :          0 :                 dev->data->scattered_rx = 1;
    1800         [ #  # ]:          0 :         if ((rx_conf->offloads & RTE_ETH_RX_OFFLOAD_SCATTER) != 0)
    1801                 :          0 :                 dev->data->scattered_rx = 1;
    1802                 :            : 
    1803                 :            :         /* Setup MTU */
    1804                 :            :         mtu = dev->data->mtu;
    1805                 :            : 
    1806         [ #  # ]:          0 :         if (nicvf_dev_set_mtu(dev, mtu)) {
    1807                 :          0 :                 PMD_INIT_LOG(ERR, "Failed to set default mtu size");
    1808                 :          0 :                 return -EBUSY;
    1809                 :            :         }
    1810                 :            : 
    1811                 :            :         /* Apply new link configurations if changed */
    1812                 :          0 :         ret = nicvf_apply_link_speed(dev);
    1813         [ #  # ]:          0 :         if (ret) {
    1814                 :          0 :                 PMD_INIT_LOG(ERR, "Failed to set link configuration\n");
    1815                 :          0 :                 return ret;
    1816                 :            :         }
    1817                 :            : 
    1818                 :          0 :         ret = nicvf_vf_start(dev, nic, rbdrsz);
    1819         [ #  # ]:          0 :         if (ret != 0)
    1820                 :            :                 return ret;
    1821                 :            : 
    1822         [ #  # ]:          0 :         for (i = 0; i < nic->sqs_count; i++) {
    1823         [ #  # ]:          0 :                 assert(nic->snicvf[i]);
    1824                 :            : 
    1825                 :          0 :                 ret = nicvf_vf_start(dev, nic->snicvf[i], rbdrsz);
    1826         [ #  # ]:          0 :                 if (ret != 0)
    1827                 :          0 :                         return ret;
    1828                 :            :         }
    1829                 :            : 
    1830                 :            :         /* Configure callbacks based on offloads */
    1831                 :          0 :         nicvf_set_tx_function(dev);
    1832                 :          0 :         nicvf_set_rx_function(dev);
    1833                 :            : 
    1834                 :          0 :         return 0;
    1835                 :            : }
    1836                 :            : 
    1837                 :            : static void
    1838                 :          0 : nicvf_dev_stop_cleanup(struct rte_eth_dev *dev, bool cleanup)
    1839                 :            : {
    1840                 :            :         size_t i;
    1841                 :            :         int ret;
    1842                 :            :         struct nicvf *nic = nicvf_pmd_priv(dev);
    1843                 :            : 
    1844                 :          0 :         PMD_INIT_FUNC_TRACE();
    1845                 :          0 :         dev->data->dev_started = 0;
    1846                 :            : 
    1847                 :            :         /* Teardown secondary vf first */
    1848         [ #  # ]:          0 :         for (i = 0; i < nic->sqs_count; i++) {
    1849         [ #  # ]:          0 :                 if (!nic->snicvf[i])
    1850                 :          0 :                         continue;
    1851                 :            : 
    1852                 :          0 :                 nicvf_vf_stop(dev, nic->snicvf[i], cleanup);
    1853                 :            :         }
    1854                 :            : 
    1855                 :            :         /* Stop the primary VF now */
    1856                 :          0 :         nicvf_vf_stop(dev, nic, cleanup);
    1857                 :            : 
    1858                 :            :         /* Disable loopback */
    1859                 :          0 :         ret = nicvf_loopback_config(nic, 0);
    1860         [ #  # ]:          0 :         if (ret)
    1861                 :          0 :                 PMD_INIT_LOG(ERR, "Failed to disable loopback %d", ret);
    1862                 :            : 
    1863                 :            :         /* Reclaim CPI configuration */
    1864                 :          0 :         ret = nicvf_mbox_config_cpi(nic, 0);
    1865         [ #  # ]:          0 :         if (ret)
    1866                 :          0 :                 PMD_INIT_LOG(ERR, "Failed to reclaim CPI config %d", ret);
    1867                 :          0 : }
    1868                 :            : 
    1869                 :            : static int
    1870                 :          0 : nicvf_dev_stop(struct rte_eth_dev *dev)
    1871                 :            : {
    1872                 :          0 :         PMD_INIT_FUNC_TRACE();
    1873                 :            : 
    1874                 :          0 :         nicvf_dev_stop_cleanup(dev, false);
    1875                 :            : 
    1876                 :          0 :         return 0;
    1877                 :            : }
    1878                 :            : 
    1879                 :            : static void
    1880                 :          0 : nicvf_vf_stop(struct rte_eth_dev *dev, struct nicvf *nic, bool cleanup)
    1881                 :            : {
    1882                 :            :         int ret;
    1883                 :            :         uint16_t qidx;
    1884                 :            :         uint16_t tx_start, tx_end;
    1885                 :            :         uint16_t rx_start, rx_end;
    1886                 :            : 
    1887                 :          0 :         PMD_INIT_FUNC_TRACE();
    1888                 :            : 
    1889         [ #  # ]:          0 :         if (cleanup) {
    1890                 :            :                 /* Let PF make the BGX's RX and TX switches to OFF position */
    1891                 :          0 :                 nicvf_mbox_shutdown(nic);
    1892                 :            :         }
    1893                 :            : 
    1894                 :            :         /* Disable VLAN Strip */
    1895                 :          0 :         nicvf_vlan_hw_strip(nic, 0);
    1896                 :            : 
    1897                 :            :         /* Get queue ranges for this VF */
    1898                 :            :         nicvf_tx_range(dev, nic, &tx_start, &tx_end);
    1899                 :            : 
    1900         [ #  # ]:          0 :         for (qidx = tx_start; qidx <= tx_end; qidx++)
    1901                 :          0 :                 nicvf_vf_stop_tx_queue(dev, nic, qidx % MAX_SND_QUEUES_PER_QS);
    1902                 :            : 
    1903                 :            :         /* Get queue ranges for this VF */
    1904                 :            :         nicvf_rx_range(dev, nic, &rx_start, &rx_end);
    1905                 :            : 
    1906                 :            :         /* Reclaim rq */
    1907         [ #  # ]:          0 :         for (qidx = rx_start; qidx <= rx_end; qidx++)
    1908                 :          0 :                 nicvf_vf_stop_rx_queue(dev, nic, qidx % MAX_RCV_QUEUES_PER_QS);
    1909                 :            : 
    1910                 :            :         /* Reclaim RBDR */
    1911                 :          0 :         ret = nicvf_qset_rbdr_reclaim(nic, 0);
    1912         [ #  # ]:          0 :         if (ret)
    1913                 :          0 :                 PMD_INIT_LOG(ERR, "Failed to reclaim RBDR %d", ret);
    1914                 :            : 
    1915                 :            :         /* Move all charged buffers in RBDR back to pool */
    1916         [ #  # ]:          0 :         if (nic->rbdr != NULL)
    1917                 :          0 :                 nicvf_rbdr_release_mbufs(dev, nic);
    1918                 :            : 
    1919                 :            :         /* Disable qset */
    1920                 :          0 :         ret = nicvf_qset_reclaim(nic);
    1921         [ #  # ]:          0 :         if (ret)
    1922                 :          0 :                 PMD_INIT_LOG(ERR, "Failed to disable qset %d", ret);
    1923                 :            : 
    1924                 :            :         /* Disable all interrupts */
    1925                 :            :         nicvf_disable_all_interrupts(nic);
    1926                 :            : 
    1927                 :            :         /* Free RBDR SW structure */
    1928         [ #  # ]:          0 :         if (nic->rbdr) {
    1929                 :          0 :                 rte_free(nic->rbdr);
    1930                 :          0 :                 nic->rbdr = NULL;
    1931                 :            :         }
    1932                 :          0 : }
    1933                 :            : 
    1934                 :            : static int
    1935                 :          0 : nicvf_dev_close(struct rte_eth_dev *dev)
    1936                 :            : {
    1937                 :            :         struct nicvf *nic = nicvf_pmd_priv(dev);
    1938                 :            : 
    1939                 :          0 :         PMD_INIT_FUNC_TRACE();
    1940         [ #  # ]:          0 :         if (rte_eal_process_type() != RTE_PROC_PRIMARY)
    1941                 :            :                 return 0;
    1942                 :            : 
    1943                 :          0 :         nicvf_dev_stop_cleanup(dev, true);
    1944                 :            :         nicvf_periodic_alarm_stop(nicvf_interrupt, dev);
    1945                 :            :         nicvf_periodic_alarm_stop(nicvf_vf_interrupt, nic);
    1946                 :            : 
    1947                 :          0 :         rte_intr_instance_free(nic->intr_handle);
    1948                 :            : 
    1949                 :          0 :         return 0;
    1950                 :            : }
    1951                 :            : 
    1952                 :            : static int
    1953                 :          0 : nicvf_request_sqs(struct nicvf *nic)
    1954                 :            : {
    1955                 :            :         size_t i;
    1956                 :            : 
    1957         [ #  # ]:          0 :         assert_primary(nic);
    1958         [ #  # ]:          0 :         assert(nic->sqs_count > 0);
    1959         [ #  # ]:          0 :         assert(nic->sqs_count <= MAX_SQS_PER_VF);
    1960                 :            : 
    1961                 :            :         /* Set no of Rx/Tx queues in each of the SQsets */
    1962         [ #  # ]:          0 :         for (i = 0; i < nic->sqs_count; i++) {
    1963         [ #  # ]:          0 :                 if (nicvf_svf_empty())
    1964                 :          0 :                         rte_panic("Cannot assign sufficient number of "
    1965                 :            :                                   "secondary queues to primary VF%" PRIu8 "\n",
    1966                 :            :                                   nic->vf_id);
    1967                 :            : 
    1968                 :          0 :                 nic->snicvf[i] = nicvf_svf_pop();
    1969                 :          0 :                 nic->snicvf[i]->sqs_id = i;
    1970                 :            :         }
    1971                 :            : 
    1972                 :          0 :         return nicvf_mbox_request_sqs(nic);
    1973                 :            : }
    1974                 :            : 
    1975                 :            : static int
    1976                 :          0 : nicvf_dev_configure(struct rte_eth_dev *dev)
    1977                 :            : {
    1978                 :          0 :         struct rte_eth_dev_data *data = dev->data;
    1979                 :            :         struct rte_eth_conf *conf = &data->dev_conf;
    1980                 :            :         struct rte_eth_rxmode *rxmode = &conf->rxmode;
    1981                 :            :         struct rte_eth_txmode *txmode = &conf->txmode;
    1982                 :            :         struct nicvf *nic = nicvf_pmd_priv(dev);
    1983                 :            :         uint8_t cqcount;
    1984                 :            : 
    1985                 :          0 :         PMD_INIT_FUNC_TRACE();
    1986                 :            : 
    1987         [ #  # ]:          0 :         if (rxmode->mq_mode & RTE_ETH_MQ_RX_RSS_FLAG)
    1988                 :          0 :                 rxmode->offloads |= RTE_ETH_RX_OFFLOAD_RSS_HASH;
    1989                 :            : 
    1990         [ #  # ]:          0 :         if (!rte_eal_has_hugepages()) {
    1991                 :          0 :                 PMD_INIT_LOG(INFO, "Huge page is not configured");
    1992                 :          0 :                 return -EINVAL;
    1993                 :            :         }
    1994                 :            : 
    1995         [ #  # ]:          0 :         if (txmode->mq_mode) {
    1996                 :          0 :                 PMD_INIT_LOG(INFO, "Tx mq_mode DCB or VMDq not supported");
    1997                 :          0 :                 return -EINVAL;
    1998                 :            :         }
    1999                 :            : 
    2000         [ #  # ]:          0 :         if (rxmode->mq_mode != RTE_ETH_MQ_RX_NONE &&
    2001                 :            :                 rxmode->mq_mode != RTE_ETH_MQ_RX_RSS) {
    2002                 :          0 :                 PMD_INIT_LOG(INFO, "Unsupported rx qmode %d", rxmode->mq_mode);
    2003                 :          0 :                 return -EINVAL;
    2004                 :            :         }
    2005                 :            : 
    2006         [ #  # ]:          0 :         if (conf->dcb_capability_en) {
    2007                 :          0 :                 PMD_INIT_LOG(INFO, "DCB enable not supported");
    2008                 :          0 :                 return -EINVAL;
    2009                 :            :         }
    2010                 :            : 
    2011         [ #  # ]:          0 :         assert_primary(nic);
    2012                 :            :         NICVF_STATIC_ASSERT(MAX_RCV_QUEUES_PER_QS == MAX_SND_QUEUES_PER_QS);
    2013                 :          0 :         cqcount = RTE_MAX(data->nb_tx_queues, data->nb_rx_queues);
    2014         [ #  # ]:          0 :         if (cqcount > MAX_RCV_QUEUES_PER_QS) {
    2015                 :          0 :                 nic->sqs_count = RTE_ALIGN_CEIL(cqcount, MAX_RCV_QUEUES_PER_QS);
    2016                 :          0 :                 nic->sqs_count = (nic->sqs_count / MAX_RCV_QUEUES_PER_QS) - 1;
    2017                 :            :         } else {
    2018                 :          0 :                 nic->sqs_count = 0;
    2019                 :            :         }
    2020                 :            : 
    2021         [ #  # ]:          0 :         assert(nic->sqs_count <= MAX_SQS_PER_VF);
    2022                 :            : 
    2023         [ #  # ]:          0 :         if (nic->sqs_count > 0) {
    2024         [ #  # ]:          0 :                 if (nicvf_request_sqs(nic)) {
    2025                 :          0 :                         rte_panic("Cannot assign sufficient number of "
    2026                 :            :                                   "secondary queues to PORT%d VF%" PRIu8 "\n",
    2027                 :            :                                   dev->data->port_id, nic->vf_id);
    2028                 :            :                 }
    2029                 :            :         }
    2030                 :            : 
    2031         [ #  # ]:          0 :         if (rxmode->offloads & RTE_ETH_RX_OFFLOAD_CHECKSUM)
    2032                 :          0 :                 nic->offload_cksum = 1;
    2033                 :            : 
    2034                 :          0 :         PMD_INIT_LOG(DEBUG, "Configured ethdev port%d hwcap=0x%" PRIx64,
    2035                 :            :                 dev->data->port_id, nicvf_hw_cap(nic));
    2036                 :            : 
    2037                 :          0 :         return 0;
    2038                 :            : }
    2039                 :            : 
    2040                 :            : static int
    2041                 :          0 : nicvf_dev_set_link_up(struct rte_eth_dev *dev)
    2042                 :            : {
    2043                 :            :         struct nicvf *nic = nicvf_pmd_priv(dev);
    2044                 :            :         int rc, i;
    2045                 :            : 
    2046                 :          0 :         rc = nicvf_mbox_set_link_up_down(nic, true);
    2047         [ #  # ]:          0 :         if (rc)
    2048                 :          0 :                 goto done;
    2049                 :            : 
    2050                 :            :         /* Start tx queues  */
    2051         [ #  # ]:          0 :         for (i = 0; i < dev->data->nb_tx_queues; i++)
    2052                 :          0 :                 nicvf_dev_tx_queue_start(dev, i);
    2053                 :            : 
    2054                 :          0 : done:
    2055                 :          0 :         return rc;
    2056                 :            : }
    2057                 :            : 
    2058                 :            : static int
    2059                 :          0 : nicvf_dev_set_link_down(struct rte_eth_dev *dev)
    2060                 :            : {
    2061                 :            :         struct nicvf *nic = nicvf_pmd_priv(dev);
    2062                 :            :         int i;
    2063                 :            : 
    2064                 :            :         /* Stop tx queues  */
    2065         [ #  # ]:          0 :         for (i = 0; i < dev->data->nb_tx_queues; i++)
    2066                 :          0 :                 nicvf_dev_tx_queue_stop(dev, i);
    2067                 :            : 
    2068                 :          0 :         return nicvf_mbox_set_link_up_down(nic, false);
    2069                 :            : }
    2070                 :            : 
    2071                 :            : /* Initialize and register driver with DPDK Application */
    2072                 :            : static const struct eth_dev_ops nicvf_eth_dev_ops = {
    2073                 :            :         .dev_configure            = nicvf_dev_configure,
    2074                 :            :         .dev_start                = nicvf_dev_start,
    2075                 :            :         .dev_stop                 = nicvf_dev_stop,
    2076                 :            :         .link_update              = nicvf_dev_link_update,
    2077                 :            :         .dev_close                = nicvf_dev_close,
    2078                 :            :         .stats_get                = nicvf_dev_stats_get,
    2079                 :            :         .stats_reset              = nicvf_dev_stats_reset,
    2080                 :            :         .promiscuous_enable       = nicvf_dev_promisc_enable,
    2081                 :            :         .dev_infos_get            = nicvf_dev_info_get,
    2082                 :            :         .dev_supported_ptypes_get = nicvf_dev_supported_ptypes_get,
    2083                 :            :         .mtu_set                  = nicvf_dev_set_mtu,
    2084                 :            :         .vlan_offload_set         = nicvf_vlan_offload_set,
    2085                 :            :         .reta_update              = nicvf_dev_reta_update,
    2086                 :            :         .reta_query               = nicvf_dev_reta_query,
    2087                 :            :         .rss_hash_update          = nicvf_dev_rss_hash_update,
    2088                 :            :         .rss_hash_conf_get        = nicvf_dev_rss_hash_conf_get,
    2089                 :            :         .rx_queue_start           = nicvf_dev_rx_queue_start,
    2090                 :            :         .rx_queue_stop            = nicvf_dev_rx_queue_stop,
    2091                 :            :         .tx_queue_start           = nicvf_dev_tx_queue_start,
    2092                 :            :         .tx_queue_stop            = nicvf_dev_tx_queue_stop,
    2093                 :            :         .rx_queue_setup           = nicvf_dev_rx_queue_setup,
    2094                 :            :         .rx_queue_release         = nicvf_dev_rx_queue_release,
    2095                 :            :         .tx_queue_setup           = nicvf_dev_tx_queue_setup,
    2096                 :            :         .tx_queue_release         = nicvf_dev_tx_queue_release,
    2097                 :            :         .dev_set_link_up          = nicvf_dev_set_link_up,
    2098                 :            :         .dev_set_link_down        = nicvf_dev_set_link_down,
    2099                 :            :         .get_reg                  = nicvf_dev_get_regs,
    2100                 :            : };
    2101                 :            : 
    2102                 :            : static int
    2103         [ #  # ]:          0 : nicvf_vlan_offload_config(struct rte_eth_dev *dev, int mask)
    2104                 :            : {
    2105                 :            :         struct rte_eth_rxmode *rxmode;
    2106                 :            :         struct nicvf *nic = nicvf_pmd_priv(dev);
    2107                 :            :         rxmode = &dev->data->dev_conf.rxmode;
    2108         [ #  # ]:          0 :         if (mask & RTE_ETH_VLAN_STRIP_MASK) {
    2109         [ #  # ]:          0 :                 if (rxmode->offloads & RTE_ETH_RX_OFFLOAD_VLAN_STRIP)
    2110                 :          0 :                         nicvf_vlan_hw_strip(nic, true);
    2111                 :            :                 else
    2112                 :          0 :                         nicvf_vlan_hw_strip(nic, false);
    2113                 :            :         }
    2114                 :            : 
    2115                 :          0 :         return 0;
    2116                 :            : }
    2117                 :            : 
    2118                 :            : static int
    2119                 :          0 : nicvf_vlan_offload_set(struct rte_eth_dev *dev, int mask)
    2120                 :            : {
    2121                 :          0 :         nicvf_vlan_offload_config(dev, mask);
    2122                 :            : 
    2123                 :          0 :         return 0;
    2124                 :            : }
    2125                 :            : 
    2126                 :            : static inline int
    2127         [ #  # ]:          0 : nicvf_set_first_skip(struct rte_eth_dev *dev)
    2128                 :            : {
    2129                 :            :         int bytes_to_skip = 0;
    2130                 :            :         int ret = 0;
    2131                 :            :         unsigned int i;
    2132                 :            :         struct rte_kvargs *kvlist;
    2133                 :            :         static const char *const skip[] = {
    2134                 :            :                 SKIP_DATA_BYTES,
    2135                 :            :                 NULL};
    2136                 :            :         struct nicvf *nic = nicvf_pmd_priv(dev);
    2137                 :            : 
    2138         [ #  # ]:          0 :         if (!dev->device->devargs) {
    2139                 :          0 :                 nicvf_first_skip_config(nic, 0);
    2140                 :          0 :                 return ret;
    2141                 :            :         }
    2142                 :            : 
    2143                 :          0 :         kvlist = rte_kvargs_parse(dev->device->devargs->args, skip);
    2144         [ #  # ]:          0 :         if (!kvlist)
    2145                 :            :                 return -EINVAL;
    2146                 :            : 
    2147         [ #  # ]:          0 :         if (kvlist->count == 0)
    2148                 :          0 :                 goto exit;
    2149                 :            : 
    2150         [ #  # ]:          0 :         for (i = 0; i != kvlist->count; ++i) {
    2151                 :            :                 const struct rte_kvargs_pair *pair = &kvlist->pairs[i];
    2152                 :            : 
    2153         [ #  # ]:          0 :                 if (!strcmp(pair->key, SKIP_DATA_BYTES))
    2154                 :          0 :                         bytes_to_skip = atoi(pair->value);
    2155                 :            :         }
    2156                 :            : 
    2157                 :            :         /*128 bytes amounts to one cache line*/
    2158         [ #  # ]:          0 :         if (bytes_to_skip >= 0 && bytes_to_skip < 128) {
    2159         [ #  # ]:          0 :                 if (!(bytes_to_skip % 8)) {
    2160                 :          0 :                         nicvf_first_skip_config(nic, (bytes_to_skip / 8));
    2161                 :          0 :                         nic->skip_bytes = bytes_to_skip;
    2162                 :          0 :                         goto kvlist_free;
    2163                 :            :                 } else {
    2164                 :          0 :                         PMD_INIT_LOG(ERR, "skip_data_bytes should be multiple of 8");
    2165                 :            :                         ret = -EINVAL;
    2166                 :          0 :                         goto exit;
    2167                 :            :                 }
    2168                 :            :         } else {
    2169                 :          0 :                 PMD_INIT_LOG(ERR, "skip_data_bytes should be less than 128");
    2170                 :            :                 ret = -EINVAL;
    2171                 :          0 :                 goto exit;
    2172                 :            :         }
    2173                 :          0 : exit:
    2174                 :          0 :         nicvf_first_skip_config(nic, 0);
    2175                 :          0 : kvlist_free:
    2176                 :          0 :         rte_kvargs_free(kvlist);
    2177                 :          0 :         return ret;
    2178                 :            : }
    2179                 :            : static int
    2180                 :          0 : nicvf_eth_dev_uninit(struct rte_eth_dev *dev)
    2181                 :            : {
    2182                 :          0 :         PMD_INIT_FUNC_TRACE();
    2183                 :          0 :         nicvf_dev_close(dev);
    2184                 :          0 :         return 0;
    2185                 :            : }
    2186                 :            : static int
    2187                 :          0 : nicvf_eth_dev_init(struct rte_eth_dev *eth_dev)
    2188                 :            : {
    2189                 :            :         int ret;
    2190                 :            :         struct rte_pci_device *pci_dev;
    2191                 :            :         struct nicvf *nic = nicvf_pmd_priv(eth_dev);
    2192                 :            : 
    2193                 :          0 :         PMD_INIT_FUNC_TRACE();
    2194                 :            : 
    2195                 :          0 :         eth_dev->dev_ops = &nicvf_eth_dev_ops;
    2196                 :          0 :         eth_dev->rx_queue_count = nicvf_dev_rx_queue_count;
    2197                 :            : 
    2198                 :            :         /* For secondary processes, the primary has done all the work */
    2199         [ #  # ]:          0 :         if (rte_eal_process_type() != RTE_PROC_PRIMARY) {
    2200         [ #  # ]:          0 :                 if (nic) {
    2201                 :            :                         /* Setup callbacks for secondary process */
    2202                 :          0 :                         nicvf_set_tx_function(eth_dev);
    2203                 :          0 :                         nicvf_set_rx_function(eth_dev);
    2204                 :          0 :                         return 0;
    2205                 :            :                 } else {
    2206                 :            :                         /* If nic == NULL than it is secondary function
    2207                 :            :                          * so ethdev need to be released by caller */
    2208                 :            :                         return ENOTSUP;
    2209                 :            :                 }
    2210                 :            :         }
    2211                 :            : 
    2212                 :          0 :         pci_dev = RTE_ETH_DEV_TO_PCI(eth_dev);
    2213                 :          0 :         rte_eth_copy_pci_info(eth_dev, pci_dev);
    2214                 :          0 :         eth_dev->data->dev_flags |= RTE_ETH_DEV_AUTOFILL_QUEUE_XSTATS;
    2215                 :            : 
    2216                 :          0 :         nic->device_id = pci_dev->id.device_id;
    2217                 :          0 :         nic->vendor_id = pci_dev->id.vendor_id;
    2218                 :          0 :         nic->subsystem_device_id = pci_dev->id.subsystem_device_id;
    2219                 :          0 :         nic->subsystem_vendor_id = pci_dev->id.subsystem_vendor_id;
    2220                 :            : 
    2221                 :          0 :         PMD_INIT_LOG(DEBUG, "nicvf: device (%x:%x) " PCI_PRI_FMT,
    2222                 :            :                         pci_dev->id.vendor_id, pci_dev->id.device_id,
    2223                 :            :                         pci_dev->addr.domain, pci_dev->addr.bus,
    2224                 :            :                         pci_dev->addr.devid, pci_dev->addr.function);
    2225                 :            : 
    2226                 :          0 :         nic->reg_base = (uintptr_t)pci_dev->mem_resource[0].addr;
    2227         [ #  # ]:          0 :         if (!nic->reg_base) {
    2228                 :          0 :                 PMD_INIT_LOG(ERR, "Failed to map BAR0");
    2229                 :            :                 ret = -ENODEV;
    2230                 :          0 :                 goto fail;
    2231                 :            :         }
    2232                 :            : 
    2233                 :            :         /* Allocate interrupt instance */
    2234                 :          0 :         nic->intr_handle = rte_intr_instance_alloc(RTE_INTR_INSTANCE_F_SHARED);
    2235         [ #  # ]:          0 :         if (nic->intr_handle == NULL) {
    2236                 :          0 :                 PMD_INIT_LOG(ERR, "Failed to allocate intr handle");
    2237                 :            :                 ret = -ENODEV;
    2238                 :          0 :                 goto fail;
    2239                 :            :         }
    2240                 :            : 
    2241                 :            :         nicvf_disable_all_interrupts(nic);
    2242                 :            : 
    2243                 :            :         /* To read mbox messages */
    2244                 :            :         ret = nicvf_periodic_alarm_start(nicvf_vf_interrupt, nic);
    2245         [ #  # ]:          0 :         if (ret) {
    2246                 :          0 :                 PMD_INIT_LOG(ERR, "Failed to start period alarm");
    2247                 :          0 :                 goto fail;
    2248                 :            :         }
    2249                 :            : 
    2250                 :            :         /* To poll link status change*/
    2251                 :            :         ret = nicvf_periodic_alarm_start(nicvf_interrupt, eth_dev);
    2252         [ #  # ]:          0 :         if (ret) {
    2253                 :          0 :                 PMD_INIT_LOG(ERR, "Failed to start period alarm");
    2254                 :          0 :                 goto fail;
    2255                 :            :         }
    2256                 :            : 
    2257                 :          0 :         ret = nicvf_mbox_check_pf_ready(nic);
    2258         [ #  # ]:          0 :         if (ret) {
    2259                 :          0 :                 PMD_INIT_LOG(ERR, "Failed to get ready message from PF");
    2260                 :          0 :                 goto alarm_fail;
    2261                 :            :         } else {
    2262   [ #  #  #  #  :          0 :                 PMD_INIT_LOG(INFO,
                   #  # ]
    2263                 :            :                         "node=%d vf=%d mode=%s sqs=%s loopback_supported=%s",
    2264                 :            :                         nic->node, nic->vf_id,
    2265                 :            :                         nic->tns_mode == NIC_TNS_MODE ? "tns" : "tns-bypass",
    2266                 :            :                         nic->sqs_mode ? "true" : "false",
    2267                 :            :                         nic->loopback_supported ? "true" : "false"
    2268                 :            :                         );
    2269                 :            :         }
    2270                 :            : 
    2271                 :            :         /* To make sure RX DMAC register is set to default value (0x3) */
    2272                 :          0 :         nicvf_mbox_reset_xcast(nic);
    2273                 :            : 
    2274                 :          0 :         ret = nicvf_base_init(nic);
    2275         [ #  # ]:          0 :         if (ret) {
    2276                 :          0 :                 PMD_INIT_LOG(ERR, "Failed to execute nicvf_base_init");
    2277                 :          0 :                 goto malloc_fail;
    2278                 :            :         }
    2279                 :            : 
    2280         [ #  # ]:          0 :         if (nic->sqs_mode) {
    2281                 :            :                 /* Push nic to stack of secondary vfs */
    2282                 :          0 :                 nicvf_svf_push(nic);
    2283                 :            : 
    2284                 :            :                 /* Steal nic pointer from the device for further reuse */
    2285                 :          0 :                 eth_dev->data->dev_private = NULL;
    2286                 :            : 
    2287                 :            :                 nicvf_periodic_alarm_stop(nicvf_interrupt, eth_dev);
    2288                 :            : 
    2289                 :            :                 /* Detach port by returning positive error number */
    2290                 :          0 :                 return ENOTSUP;
    2291                 :            :         }
    2292                 :            : 
    2293                 :          0 :         eth_dev->data->mac_addrs = rte_zmalloc("mac_addr",
    2294                 :            :                                         RTE_ETHER_ADDR_LEN, 0);
    2295         [ #  # ]:          0 :         if (eth_dev->data->mac_addrs == NULL) {
    2296                 :          0 :                 PMD_INIT_LOG(ERR, "Failed to allocate memory for mac addr");
    2297                 :            :                 ret = -ENOMEM;
    2298                 :          0 :                 goto alarm_fail;
    2299                 :            :         }
    2300         [ #  # ]:          0 :         if (rte_is_zero_ether_addr((struct rte_ether_addr *)nic->mac_addr))
    2301                 :          0 :                 rte_eth_random_addr(&nic->mac_addr[0]);
    2302                 :            : 
    2303                 :          0 :         rte_ether_addr_copy((struct rte_ether_addr *)nic->mac_addr,
    2304                 :          0 :                         &eth_dev->data->mac_addrs[0]);
    2305                 :            : 
    2306                 :          0 :         ret = nicvf_mbox_set_mac_addr(nic, nic->mac_addr);
    2307         [ #  # ]:          0 :         if (ret) {
    2308                 :          0 :                 PMD_INIT_LOG(ERR, "Failed to set mac addr");
    2309                 :          0 :                 goto malloc_fail;
    2310                 :            :         }
    2311                 :            : 
    2312                 :          0 :         ret = nicvf_set_first_skip(eth_dev);
    2313         [ #  # ]:          0 :         if (ret) {
    2314                 :          0 :                 PMD_INIT_LOG(ERR, "Failed to configure first skip");
    2315                 :          0 :                 goto malloc_fail;
    2316                 :            :         }
    2317                 :          0 :         PMD_INIT_LOG(INFO, "Port %d (%x:%x) mac=" RTE_ETHER_ADDR_PRT_FMT,
    2318                 :            :                 eth_dev->data->port_id, nic->vendor_id, nic->device_id,
    2319                 :            :                 nic->mac_addr[0], nic->mac_addr[1], nic->mac_addr[2],
    2320                 :            :                 nic->mac_addr[3], nic->mac_addr[4], nic->mac_addr[5]);
    2321                 :            : 
    2322                 :          0 :         return 0;
    2323                 :            : 
    2324                 :          0 : malloc_fail:
    2325                 :          0 :         rte_free(eth_dev->data->mac_addrs);
    2326                 :          0 :         eth_dev->data->mac_addrs = NULL;
    2327                 :          0 : alarm_fail:
    2328                 :            :         nicvf_periodic_alarm_stop(nicvf_interrupt, eth_dev);
    2329                 :            : fail:
    2330                 :            :         return ret;
    2331                 :            : }
    2332                 :            : 
    2333                 :            : static const struct rte_pci_id pci_id_nicvf_map[] = {
    2334                 :            :         {
    2335                 :            :                 .class_id = RTE_CLASS_ANY_ID,
    2336                 :            :                 .vendor_id = PCI_VENDOR_ID_CAVIUM,
    2337                 :            :                 .device_id = PCI_DEVICE_ID_THUNDERX_CN88XX_PASS1_NICVF,
    2338                 :            :                 .subsystem_vendor_id = PCI_VENDOR_ID_CAVIUM,
    2339                 :            :                 .subsystem_device_id = PCI_SUB_DEVICE_ID_CN88XX_PASS1_NICVF,
    2340                 :            :         },
    2341                 :            :         {
    2342                 :            :                 .class_id = RTE_CLASS_ANY_ID,
    2343                 :            :                 .vendor_id = PCI_VENDOR_ID_CAVIUM,
    2344                 :            :                 .device_id = PCI_DEVICE_ID_THUNDERX_NICVF,
    2345                 :            :                 .subsystem_vendor_id = PCI_VENDOR_ID_CAVIUM,
    2346                 :            :                 .subsystem_device_id = PCI_SUB_DEVICE_ID_CN88XX_PASS2_NICVF,
    2347                 :            :         },
    2348                 :            :         {
    2349                 :            :                 .class_id = RTE_CLASS_ANY_ID,
    2350                 :            :                 .vendor_id = PCI_VENDOR_ID_CAVIUM,
    2351                 :            :                 .device_id = PCI_DEVICE_ID_THUNDERX_NICVF,
    2352                 :            :                 .subsystem_vendor_id = PCI_VENDOR_ID_CAVIUM,
    2353                 :            :                 .subsystem_device_id = PCI_SUB_DEVICE_ID_CN81XX_NICVF,
    2354                 :            :         },
    2355                 :            :         {
    2356                 :            :                 .class_id = RTE_CLASS_ANY_ID,
    2357                 :            :                 .vendor_id = PCI_VENDOR_ID_CAVIUM,
    2358                 :            :                 .device_id = PCI_DEVICE_ID_THUNDERX_NICVF,
    2359                 :            :                 .subsystem_vendor_id = PCI_VENDOR_ID_CAVIUM,
    2360                 :            :                 .subsystem_device_id = PCI_SUB_DEVICE_ID_CN83XX_NICVF,
    2361                 :            :         },
    2362                 :            :         {
    2363                 :            :                 .vendor_id = 0,
    2364                 :            :         },
    2365                 :            : };
    2366                 :            : 
    2367                 :          0 : static int nicvf_eth_pci_probe(struct rte_pci_driver *pci_drv __rte_unused,
    2368                 :            :         struct rte_pci_device *pci_dev)
    2369                 :            : {
    2370                 :          0 :         return rte_eth_dev_pci_generic_probe(pci_dev, sizeof(struct nicvf),
    2371                 :            :                 nicvf_eth_dev_init);
    2372                 :            : }
    2373                 :            : 
    2374                 :          0 : static int nicvf_eth_pci_remove(struct rte_pci_device *pci_dev)
    2375                 :            : {
    2376                 :          0 :         return rte_eth_dev_pci_generic_remove(pci_dev, nicvf_eth_dev_uninit);
    2377                 :            : }
    2378                 :            : 
    2379                 :            : static struct rte_pci_driver rte_nicvf_pmd = {
    2380                 :            :         .id_table = pci_id_nicvf_map,
    2381                 :            :         .drv_flags = RTE_PCI_DRV_NEED_MAPPING | RTE_PCI_DRV_KEEP_MAPPED_RES |
    2382                 :            :                         RTE_PCI_DRV_INTR_LSC,
    2383                 :            :         .probe = nicvf_eth_pci_probe,
    2384                 :            :         .remove = nicvf_eth_pci_remove,
    2385                 :            : };
    2386                 :            : 
    2387                 :        235 : RTE_PMD_REGISTER_PCI(net_thunderx, rte_nicvf_pmd);
    2388                 :            : RTE_PMD_REGISTER_PCI_TABLE(net_thunderx, pci_id_nicvf_map);
    2389                 :            : RTE_PMD_REGISTER_KMOD_DEP(net_thunderx, "* igb_uio | uio_pci_generic | vfio-pci");
    2390                 :            : RTE_PMD_REGISTER_PARAM_STRING(net_thunderx, SKIP_DATA_BYTES "=<int>");

Generated by: LCOV version 1.14