LCOV - code coverage report
Current view: top level - drivers/net/enic/base - vnic_dev.c (source / functions) Hit Total Coverage
Test: Code coverage Lines: 0 566 0.0 %
Date: 2025-01-02 22:41:34 Functions: 0 67 0.0 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 0 295 0.0 %

           Branch data     Line data    Source code
       1                 :            : /* SPDX-License-Identifier: BSD-3-Clause
       2                 :            :  * Copyright 2008-2017 Cisco Systems, Inc.  All rights reserved.
       3                 :            :  * Copyright 2007 Nuova Systems, Inc.  All rights reserved.
       4                 :            :  */
       5                 :            : 
       6                 :            : #include <rte_memzone.h>
       7                 :            : #include <rte_memcpy.h>
       8                 :            : #include <rte_string_fns.h>
       9                 :            : #include <rte_ether.h>
      10                 :            : 
      11                 :            : #include "vnic_dev.h"
      12                 :            : #include "vnic_resource.h"
      13                 :            : #include "vnic_devcmd.h"
      14                 :            : #include "vnic_nic.h"
      15                 :            : #include "vnic_stats.h"
      16                 :            : #include "vnic_flowman.h"
      17                 :            : 
      18                 :            : 
      19                 :            : enum vnic_proxy_type {
      20                 :            :         PROXY_NONE,
      21                 :            :         PROXY_BY_BDF,
      22                 :            :         PROXY_BY_INDEX,
      23                 :            : };
      24                 :            : 
      25                 :            : struct vnic_res {
      26                 :            :         void __iomem *vaddr;
      27                 :            :         dma_addr_t bus_addr;
      28                 :            :         unsigned int count;
      29                 :            : };
      30                 :            : 
      31                 :            : struct vnic_intr_coal_timer_info {
      32                 :            :         uint32_t mul;
      33                 :            :         uint32_t div;
      34                 :            :         uint32_t max_usec;
      35                 :            : };
      36                 :            : 
      37                 :            : struct vnic_dev {
      38                 :            :         void *priv;
      39                 :            :         struct rte_pci_device *pdev;
      40                 :            :         struct vnic_res res[RES_TYPE_MAX];
      41                 :            :         enum vnic_dev_intr_mode intr_mode;
      42                 :            :         struct vnic_devcmd __iomem *devcmd;
      43                 :            :         struct vnic_devcmd_notify *notify;
      44                 :            :         struct vnic_devcmd_notify notify_copy;
      45                 :            :         dma_addr_t notify_pa;
      46                 :            :         uint32_t notify_sz;
      47                 :            :         dma_addr_t linkstatus_pa;
      48                 :            :         struct vnic_stats *stats;
      49                 :            :         dma_addr_t stats_pa;
      50                 :            :         struct vnic_sriov_stats *sriov_stats;
      51                 :            :         dma_addr_t sriov_stats_pa;
      52                 :            :         struct vnic_devcmd_fw_info *fw_info;
      53                 :            :         dma_addr_t fw_info_pa;
      54                 :            :         struct fm_info *flowman_info;
      55                 :            :         dma_addr_t flowman_info_pa;
      56                 :            :         enum vnic_proxy_type proxy;
      57                 :            :         uint32_t proxy_index;
      58                 :            :         uint64_t args[VNIC_DEVCMD_NARGS];
      59                 :            :         int in_reset;
      60                 :            :         struct vnic_intr_coal_timer_info intr_coal_timer_info;
      61                 :            :         void *(*alloc_consistent)(void *priv, size_t size,
      62                 :            :                 dma_addr_t *dma_handle, uint8_t *name);
      63                 :            :         void (*free_consistent)(void *priv,
      64                 :            :                 size_t size, void *vaddr,
      65                 :            :                 dma_addr_t dma_handle);
      66                 :            :         /*
      67                 :            :          * Used to serialize devcmd access, currently from PF and its
      68                 :            :          * VF representors. When there are no representors, lock is
      69                 :            :          * not used.
      70                 :            :          */
      71                 :            :         int locked;
      72                 :            :         void (*lock)(void *priv);
      73                 :            :         void (*unlock)(void *priv);
      74                 :            :         struct vnic_dev *pf_vdev;
      75                 :            :         int vf_id;
      76                 :            : };
      77                 :            : 
      78                 :            : #define VNIC_MAX_RES_HDR_SIZE \
      79                 :            :         (sizeof(struct vnic_resource_header) + \
      80                 :            :         sizeof(struct vnic_resource) * RES_TYPE_MAX)
      81                 :            : #define VNIC_RES_STRIDE 128
      82                 :            : 
      83                 :          0 : void *vnic_dev_priv(struct vnic_dev *vdev)
      84                 :            : {
      85                 :          0 :         return vdev->priv;
      86                 :            : }
      87                 :            : 
      88                 :          0 : void vnic_register_cbacks(struct vnic_dev *vdev,
      89                 :            :         void *(*alloc_consistent)(void *priv, size_t size,
      90                 :            :             dma_addr_t *dma_handle, uint8_t *name),
      91                 :            :         void (*free_consistent)(void *priv,
      92                 :            :             size_t size, void *vaddr,
      93                 :            :             dma_addr_t dma_handle))
      94                 :            : {
      95                 :          0 :         vdev->alloc_consistent = alloc_consistent;
      96                 :          0 :         vdev->free_consistent = free_consistent;
      97                 :          0 : }
      98                 :            : 
      99                 :          0 : void vnic_register_lock(struct vnic_dev *vdev, void (*lock)(void *priv),
     100                 :            :         void (*unlock)(void *priv))
     101                 :            : {
     102                 :          0 :         vdev->lock = lock;
     103                 :          0 :         vdev->unlock = unlock;
     104                 :          0 :         vdev->locked = 0;
     105                 :          0 : }
     106                 :            : 
     107                 :          0 : static int vnic_dev_discover_res(struct vnic_dev *vdev,
     108                 :            :         struct vnic_dev_bar *bar, unsigned int num_bars)
     109                 :            : {
     110                 :            :         struct vnic_resource_header __iomem *rh;
     111                 :            :         struct mgmt_barmap_hdr __iomem *mrh;
     112                 :            :         struct vnic_resource __iomem *r;
     113                 :            :         uint8_t type;
     114                 :            : 
     115         [ #  # ]:          0 :         if (num_bars == 0)
     116                 :            :                 return -EINVAL;
     117                 :            : 
     118         [ #  # ]:          0 :         if (bar->len < VNIC_MAX_RES_HDR_SIZE) {
     119                 :          0 :                 pr_err("vNIC BAR0 res hdr length error\n");
     120                 :          0 :                 return -EINVAL;
     121                 :            :         }
     122                 :            : 
     123                 :          0 :         rh  = bar->vaddr;
     124                 :            :         mrh = bar->vaddr;
     125         [ #  # ]:          0 :         if (!rh) {
     126                 :          0 :                 pr_err("vNIC BAR0 res hdr not mem-mapped\n");
     127                 :          0 :                 return -EINVAL;
     128                 :            :         }
     129                 :            : 
     130                 :            :         /* Check for mgmt vnic in addition to normal vnic */
     131   [ #  #  #  # ]:          0 :         if ((ioread32(&rh->magic) != VNIC_RES_MAGIC) ||
     132                 :            :                 (ioread32(&rh->version) != VNIC_RES_VERSION)) {
     133   [ #  #  #  # ]:          0 :                 if ((ioread32(&mrh->magic) != MGMTVNIC_MAGIC) ||
     134                 :            :                         (ioread32(&mrh->version) != MGMTVNIC_VERSION)) {
     135                 :          0 :                         pr_err("vNIC BAR0 res magic/version error " \
     136                 :            :                                 "exp (%lx/%lx) or (%lx/%lx), curr (%x/%x)\n",
     137                 :            :                                 VNIC_RES_MAGIC, VNIC_RES_VERSION,
     138                 :            :                                 MGMTVNIC_MAGIC, MGMTVNIC_VERSION,
     139                 :            :                                 ioread32(&rh->magic), ioread32(&rh->version));
     140                 :          0 :                         return -EINVAL;
     141                 :            :                 }
     142                 :            :         }
     143                 :            : 
     144         [ #  # ]:          0 :         if (ioread32(&mrh->magic) == MGMTVNIC_MAGIC)
     145                 :          0 :                 r = (struct vnic_resource __iomem *)(mrh + 1);
     146                 :            :         else
     147                 :          0 :                 r = (struct vnic_resource __iomem *)(rh + 1);
     148                 :            : 
     149                 :            : 
     150         [ #  # ]:          0 :         while ((type = ioread8(&r->type)) != RES_TYPE_EOL) {
     151                 :            :                 uint8_t bar_num = ioread8(&r->bar);
     152                 :            :                 uint32_t bar_offset = ioread32(&r->bar_offset);
     153                 :            :                 uint32_t count = ioread32(&r->count);
     154                 :            :                 uint32_t len;
     155                 :            : 
     156                 :          0 :                 r++;
     157                 :            : 
     158         [ #  # ]:          0 :                 if (bar_num >= num_bars)
     159                 :          0 :                         continue;
     160                 :            : 
     161   [ #  #  #  # ]:          0 :                 if (!bar[bar_num].len || !bar[bar_num].vaddr)
     162                 :          0 :                         continue;
     163                 :            : 
     164      [ #  #  # ]:          0 :                 switch (type) {
     165                 :          0 :                 case RES_TYPE_WQ:
     166                 :            :                 case RES_TYPE_RQ:
     167                 :            :                 case RES_TYPE_CQ:
     168                 :            :                 case RES_TYPE_INTR_CTRL:
     169                 :            :                 case RES_TYPE_ADMIN_WQ:
     170                 :            :                 case RES_TYPE_ADMIN_RQ:
     171                 :            :                 case RES_TYPE_ADMIN_CQ:
     172                 :            :                         /* each count is stride bytes long */
     173                 :          0 :                         len = count * VNIC_RES_STRIDE;
     174         [ #  # ]:          0 :                         if (len + bar_offset > bar[bar_num].len) {
     175                 :          0 :                                 pr_err("vNIC BAR0 resource %d " \
     176                 :            :                                         "out-of-bounds, offset 0x%x + " \
     177                 :            :                                         "size 0x%x > bar len 0x%lx\n",
     178                 :            :                                         type, bar_offset,
     179                 :            :                                         len,
     180                 :            :                                         bar[bar_num].len);
     181                 :          0 :                                 return -EINVAL;
     182                 :            :                         }
     183                 :            :                         break;
     184                 :            :                 case RES_TYPE_INTR_PBA_LEGACY:
     185                 :            :                 case RES_TYPE_DEVCMD:
     186                 :            :                         len = count;
     187                 :            :                         break;
     188                 :          0 :                 default:
     189                 :          0 :                         continue;
     190                 :            :                 }
     191                 :            : 
     192                 :          0 :                 vdev->res[type].count = count;
     193                 :          0 :                 vdev->res[type].vaddr = (char __iomem *)bar[bar_num].vaddr +
     194                 :            :                     bar_offset;
     195                 :          0 :                 vdev->res[type].bus_addr = bar[bar_num].bus_addr + bar_offset;
     196                 :            :         }
     197                 :            : 
     198                 :            :         return 0;
     199                 :            : }
     200                 :            : 
     201                 :          0 : unsigned int vnic_dev_get_res_count(struct vnic_dev *vdev,
     202                 :            :         enum vnic_res_type type)
     203                 :            : {
     204                 :          0 :         return vdev->res[type].count;
     205                 :            : }
     206                 :            : 
     207                 :          0 : void __iomem *vnic_dev_get_res(struct vnic_dev *vdev, enum vnic_res_type type,
     208                 :            :         unsigned int index)
     209                 :            : {
     210         [ #  # ]:          0 :         if (!vdev->res[type].vaddr)
     211                 :            :                 return NULL;
     212                 :            : 
     213         [ #  # ]:          0 :         switch (type) {
     214                 :          0 :         case RES_TYPE_WQ:
     215                 :            :         case RES_TYPE_RQ:
     216                 :            :         case RES_TYPE_CQ:
     217                 :            :         case RES_TYPE_INTR_CTRL:
     218                 :            :         case RES_TYPE_ADMIN_WQ:
     219                 :            :         case RES_TYPE_ADMIN_RQ:
     220                 :            :         case RES_TYPE_ADMIN_CQ:
     221                 :          0 :                 return (char __iomem *)vdev->res[type].vaddr +
     222                 :          0 :                         index * VNIC_RES_STRIDE;
     223                 :            :         default:
     224                 :            :                 return (char __iomem *)vdev->res[type].vaddr;
     225                 :            :         }
     226                 :            : }
     227                 :            : 
     228                 :          0 : unsigned int vnic_dev_desc_ring_size(struct vnic_dev_ring *ring,
     229                 :            :         unsigned int desc_count, unsigned int desc_size)
     230                 :            : {
     231                 :            :         /* The base address of the desc rings must be 512 byte aligned.
     232                 :            :          * Descriptor count is aligned to groups of 32 descriptors.  A
     233                 :            :          * count of 0 means the maximum 4096 descriptors.  Descriptor
     234                 :            :          * size is aligned to 16 bytes.
     235                 :            :          */
     236                 :            : 
     237                 :            :         unsigned int count_align = 32;
     238                 :            :         unsigned int desc_align = 16;
     239                 :            : 
     240                 :          0 :         ring->base_align = 512;
     241                 :            : 
     242         [ #  # ]:          0 :         if (desc_count == 0)
     243                 :            :                 desc_count = 4096;
     244                 :            : 
     245                 :          0 :         ring->desc_count = VNIC_ALIGN(desc_count, count_align);
     246                 :            : 
     247                 :          0 :         ring->desc_size = VNIC_ALIGN(desc_size, desc_align);
     248                 :            : 
     249                 :          0 :         ring->size = ring->desc_count * ring->desc_size;
     250                 :          0 :         ring->size_unaligned = ring->size + ring->base_align;
     251                 :            : 
     252                 :          0 :         return ring->size_unaligned;
     253                 :            : }
     254                 :            : 
     255                 :          0 : void vnic_dev_clear_desc_ring(struct vnic_dev_ring *ring)
     256                 :            : {
     257                 :          0 :         memset(ring->descs, 0, ring->size);
     258                 :          0 : }
     259                 :            : 
     260                 :          0 : int vnic_dev_alloc_desc_ring(struct vnic_dev *vdev,
     261                 :            :         struct vnic_dev_ring *ring,
     262                 :            :         unsigned int desc_count, unsigned int desc_size,
     263                 :            :         __rte_unused unsigned int socket_id,
     264                 :            :         char *z_name)
     265                 :            : {
     266                 :            :         void *alloc_addr;
     267                 :          0 :         dma_addr_t alloc_pa = 0;
     268                 :            : 
     269                 :          0 :         vnic_dev_desc_ring_size(ring, desc_count, desc_size);
     270                 :          0 :         alloc_addr = vdev->alloc_consistent(vdev->priv,
     271                 :            :                                             ring->size_unaligned,
     272                 :            :                                             &alloc_pa, (uint8_t *)z_name);
     273         [ #  # ]:          0 :         if (!alloc_addr) {
     274                 :          0 :                 pr_err("Failed to allocate ring (size=%d), aborting\n",
     275                 :            :                         (int)ring->size);
     276                 :          0 :                 return -ENOMEM;
     277                 :            :         }
     278                 :          0 :         ring->descs_unaligned = alloc_addr;
     279         [ #  # ]:          0 :         if (!alloc_pa) {
     280                 :          0 :                 pr_err("Failed to map allocated ring (size=%d), aborting\n",
     281                 :            :                         (int)ring->size);
     282                 :          0 :                 vdev->free_consistent(vdev->priv,
     283                 :            :                                       ring->size_unaligned,
     284                 :            :                                       alloc_addr,
     285                 :            :                                       alloc_pa);
     286                 :          0 :                 return -ENOMEM;
     287                 :            :         }
     288                 :          0 :         ring->base_addr_unaligned = alloc_pa;
     289                 :            : 
     290                 :          0 :         ring->base_addr = VNIC_ALIGN(ring->base_addr_unaligned,
     291                 :            :                 ring->base_align);
     292                 :          0 :         ring->descs = (uint8_t *)ring->descs_unaligned +
     293                 :          0 :             (ring->base_addr - ring->base_addr_unaligned);
     294                 :            : 
     295                 :          0 :         vnic_dev_clear_desc_ring(ring);
     296                 :            : 
     297                 :          0 :         ring->desc_avail = ring->desc_count - 1;
     298                 :            : 
     299                 :          0 :         return 0;
     300                 :            : }
     301                 :            : 
     302                 :          0 : void vnic_dev_free_desc_ring(__rte_unused  struct vnic_dev *vdev,
     303                 :            :         struct vnic_dev_ring *ring)
     304                 :            : {
     305         [ #  # ]:          0 :         if (ring->descs) {
     306                 :          0 :                 vdev->free_consistent(vdev->priv,
     307                 :            :                                       ring->size_unaligned,
     308                 :            :                                       ring->descs_unaligned,
     309                 :            :                                       ring->base_addr_unaligned);
     310                 :          0 :                 ring->descs = NULL;
     311                 :            :         }
     312                 :          0 : }
     313                 :            : 
     314                 :          0 : static int _vnic_dev_cmd(struct vnic_dev *vdev, enum vnic_devcmd_cmd cmd,
     315                 :            :         int wait)
     316                 :            : {
     317                 :          0 :         struct vnic_devcmd __iomem *devcmd = vdev->devcmd;
     318                 :            :         unsigned int i;
     319                 :            :         int delay;
     320                 :            :         uint32_t status;
     321                 :            :         int err;
     322                 :            : 
     323                 :            :         status = ioread32(&devcmd->status);
     324         [ #  # ]:          0 :         if (status == 0xFFFFFFFF) {
     325                 :            :                 /* PCI-e target device is gone */
     326                 :            :                 return -ENODEV;
     327                 :            :         }
     328         [ #  # ]:          0 :         if (status & STAT_BUSY) {
     329                 :            : 
     330                 :          0 :                 pr_err("Busy devcmd %d\n",  _CMD_N(cmd));
     331                 :          0 :                 return -EBUSY;
     332                 :            :         }
     333                 :            : 
     334         [ #  # ]:          0 :         if (_CMD_DIR(cmd) & _CMD_DIR_WRITE) {
     335         [ #  # ]:          0 :                 for (i = 0; i < VNIC_DEVCMD_NARGS; i++)
     336                 :          0 :                         writeq(vdev->args[i], &devcmd->args[i]);
     337                 :            :                 rte_wmb(); /* complete all writes initiated till now */
     338                 :            :         }
     339                 :            : 
     340                 :            :         iowrite32(cmd, &devcmd->cmd);
     341                 :            : 
     342         [ #  # ]:          0 :         if ((_CMD_FLAGS(cmd) & _CMD_FLAGS_NOWAIT))
     343                 :            :                 return 0;
     344                 :            : 
     345         [ #  # ]:          0 :         for (delay = 0; delay < wait; delay++) {
     346                 :            : 
     347                 :          0 :                 usleep(100);
     348                 :            : 
     349                 :            :                 status = ioread32(&devcmd->status);
     350         [ #  # ]:          0 :                 if (status == 0xFFFFFFFF) {
     351                 :            :                         /* PCI-e target device is gone */
     352                 :            :                         return -ENODEV;
     353                 :            :                 }
     354                 :            : 
     355         [ #  # ]:          0 :                 if (!(status & STAT_BUSY)) {
     356         [ #  # ]:          0 :                         if (status & STAT_ERROR) {
     357                 :          0 :                                 err = -(int)readq(&devcmd->args[0]);
     358                 :          0 :                                 if (cmd != CMD_CAPABILITY &&
     359   [ #  #  #  # ]:          0 :                                     cmd != CMD_OVERLAY_OFFLOAD_CTRL &&
     360                 :            :                                     cmd != CMD_GET_SUPP_FEATURE_VER)
     361                 :          0 :                                         pr_err("Devcmd %d failed " \
     362                 :            :                                                 "with error code %d\n",
     363                 :            :                                                 _CMD_N(cmd), err);
     364                 :          0 :                                 return err;
     365                 :            :                         }
     366                 :            : 
     367         [ #  # ]:          0 :                         if (_CMD_DIR(cmd) & _CMD_DIR_READ) {
     368                 :            :                                 rte_rmb();/* finish all reads */
     369         [ #  # ]:          0 :                                 for (i = 0; i < VNIC_DEVCMD_NARGS; i++)
     370                 :          0 :                                         vdev->args[i] = readq(&devcmd->args[i]);
     371                 :            :                         }
     372                 :            : 
     373                 :          0 :                         return 0;
     374                 :            :                 }
     375                 :            :         }
     376                 :            : 
     377                 :          0 :         pr_err("Timedout devcmd %d\n", _CMD_N(cmd));
     378                 :          0 :         return -ETIMEDOUT;
     379                 :            : }
     380                 :            : 
     381                 :          0 : static int vnic_dev_cmd_proxy(struct vnic_dev *vdev,
     382                 :            :         enum vnic_devcmd_cmd proxy_cmd, enum vnic_devcmd_cmd cmd,
     383                 :            :         uint64_t *args, int nargs, int wait)
     384                 :            : {
     385                 :            :         uint32_t status;
     386                 :            :         int err;
     387                 :            : 
     388                 :            :         /*
     389                 :            :          * Proxy command consumes 2 arguments. One for proxy index,
     390                 :            :          * the other is for command to be proxied
     391                 :            :          */
     392         [ #  # ]:          0 :         if (nargs > VNIC_DEVCMD_NARGS - 2) {
     393                 :          0 :                 pr_err("number of args %d exceeds the maximum\n", nargs);
     394                 :          0 :                 return -EINVAL;
     395                 :            :         }
     396                 :          0 :         memset(vdev->args, 0, sizeof(vdev->args));
     397                 :            : 
     398                 :          0 :         vdev->args[0] = vdev->proxy_index;
     399                 :          0 :         vdev->args[1] = cmd;
     400                 :          0 :         memcpy(&vdev->args[2], args, nargs * sizeof(args[0]));
     401                 :            : 
     402                 :          0 :         err = _vnic_dev_cmd(vdev, proxy_cmd, wait);
     403         [ #  # ]:          0 :         if (err)
     404                 :            :                 return err;
     405                 :            : 
     406                 :          0 :         status = (uint32_t)vdev->args[0];
     407         [ #  # ]:          0 :         if (status & STAT_ERROR) {
     408                 :          0 :                 err = (int)vdev->args[1];
     409                 :          0 :                 if (err != ERR_ECMDUNKNOWN ||
     410         [ #  # ]:          0 :                     cmd != CMD_CAPABILITY)
     411                 :          0 :                         pr_err("Error %d proxy devcmd %d\n", err, _CMD_N(cmd));
     412                 :          0 :                 return err;
     413                 :            :         }
     414                 :            : 
     415                 :          0 :         memcpy(args, &vdev->args[1], nargs * sizeof(args[0]));
     416                 :            : 
     417                 :          0 :         return 0;
     418                 :            : }
     419                 :            : 
     420                 :          0 : static int vnic_dev_cmd_no_proxy(struct vnic_dev *vdev,
     421                 :            :         enum vnic_devcmd_cmd cmd, uint64_t *args, int nargs, int wait)
     422                 :            : {
     423                 :            :         int err;
     424                 :            : 
     425         [ #  # ]:          0 :         if (nargs > VNIC_DEVCMD_NARGS) {
     426                 :          0 :                 pr_err("number of args %d exceeds the maximum\n", nargs);
     427                 :          0 :                 return -EINVAL;
     428                 :            :         }
     429                 :          0 :         memset(vdev->args, 0, sizeof(vdev->args));
     430                 :          0 :         memcpy(vdev->args, args, nargs * sizeof(args[0]));
     431                 :            : 
     432                 :          0 :         err = _vnic_dev_cmd(vdev, cmd, wait);
     433                 :            : 
     434                 :            :         memcpy(args, vdev->args, nargs * sizeof(args[0]));
     435                 :            : 
     436                 :          0 :         return err;
     437                 :            : }
     438                 :            : 
     439                 :          0 : void vnic_dev_cmd_proxy_by_index_start(struct vnic_dev *vdev, uint16_t index)
     440                 :            : {
     441                 :          0 :         vdev->proxy = PROXY_BY_INDEX;
     442                 :          0 :         vdev->proxy_index = index;
     443                 :          0 : }
     444                 :            : 
     445                 :          0 : void vnic_dev_cmd_proxy_end(struct vnic_dev *vdev)
     446                 :            : {
     447                 :          0 :         vdev->proxy = PROXY_NONE;
     448                 :          0 :         vdev->proxy_index = 0;
     449                 :          0 : }
     450                 :            : 
     451                 :          0 : int vnic_dev_cmd(struct vnic_dev *vdev, enum vnic_devcmd_cmd cmd,
     452                 :            :         uint64_t *a0, uint64_t *a1, int wait)
     453                 :            : {
     454                 :            :         uint64_t args[2];
     455                 :            :         bool vf_rep;
     456                 :            :         int vf_idx;
     457                 :            :         int err;
     458                 :            : 
     459                 :            :         vf_rep = false;
     460         [ #  # ]:          0 :         if (vdev->pf_vdev) {
     461                 :            :                 vf_rep = true;
     462                 :          0 :                 vf_idx = vdev->vf_id;
     463                 :            :                 /* Everything below assumes PF vdev */
     464                 :            :                 vdev = vdev->pf_vdev;
     465                 :            :         }
     466         [ #  # ]:          0 :         if (vdev->lock)
     467                 :          0 :                 vdev->lock(vdev->priv);
     468                 :            :         /* For VF representor, proxy devcmd to VF index */
     469         [ #  # ]:          0 :         if (vf_rep)
     470                 :          0 :                 vnic_dev_cmd_proxy_by_index_start(vdev, vf_idx);
     471                 :            : 
     472                 :          0 :         args[0] = *a0;
     473                 :          0 :         args[1] = *a1;
     474      [ #  #  # ]:          0 :         memset(vdev->args, 0, sizeof(vdev->args));
     475                 :            : 
     476      [ #  #  # ]:          0 :         switch (vdev->proxy) {
     477                 :          0 :         case PROXY_BY_INDEX:
     478                 :          0 :                 err =  vnic_dev_cmd_proxy(vdev, CMD_PROXY_BY_INDEX, cmd,
     479                 :            :                                 args, ARRAY_SIZE(args), wait);
     480                 :          0 :                 break;
     481                 :          0 :         case PROXY_BY_BDF:
     482                 :          0 :                 err =  vnic_dev_cmd_proxy(vdev, CMD_PROXY_BY_BDF, cmd,
     483                 :            :                                 args, ARRAY_SIZE(args), wait);
     484                 :          0 :                 break;
     485                 :          0 :         case PROXY_NONE:
     486                 :            :         default:
     487                 :          0 :                 err = vnic_dev_cmd_no_proxy(vdev, cmd, args, 2, wait);
     488                 :          0 :                 break;
     489                 :            :         }
     490                 :            : 
     491         [ #  # ]:          0 :         if (vf_rep)
     492                 :          0 :                 vnic_dev_cmd_proxy_end(vdev);
     493         [ #  # ]:          0 :         if (vdev->unlock)
     494                 :          0 :                 vdev->unlock(vdev->priv);
     495         [ #  # ]:          0 :         if (err == 0) {
     496                 :          0 :                 *a0 = args[0];
     497                 :          0 :                 *a1 = args[1];
     498                 :            :         }
     499                 :            : 
     500                 :          0 :         return err;
     501                 :            : }
     502                 :            : 
     503                 :          0 : int vnic_dev_cmd_args(struct vnic_dev *vdev, enum vnic_devcmd_cmd cmd,
     504                 :            :                       uint64_t *args, int nargs, int wait)
     505                 :            : {
     506                 :            :         bool vf_rep;
     507                 :            :         int vf_idx;
     508                 :            :         int err;
     509                 :            : 
     510                 :            :         vf_rep = false;
     511         [ #  # ]:          0 :         if (vdev->pf_vdev) {
     512                 :            :                 vf_rep = true;
     513                 :          0 :                 vf_idx = vdev->vf_id;
     514                 :            :                 vdev = vdev->pf_vdev;
     515                 :            :         }
     516         [ #  # ]:          0 :         if (vdev->lock)
     517                 :          0 :                 vdev->lock(vdev->priv);
     518         [ #  # ]:          0 :         if (vf_rep)
     519                 :          0 :                 vnic_dev_cmd_proxy_by_index_start(vdev, vf_idx);
     520                 :            : 
     521      [ #  #  # ]:          0 :         switch (vdev->proxy) {
     522                 :          0 :         case PROXY_BY_INDEX:
     523                 :          0 :                 err = vnic_dev_cmd_proxy(vdev, CMD_PROXY_BY_INDEX, cmd,
     524                 :            :                                 args, nargs, wait);
     525                 :          0 :                 break;
     526                 :          0 :         case PROXY_BY_BDF:
     527                 :          0 :                 err = vnic_dev_cmd_proxy(vdev, CMD_PROXY_BY_BDF, cmd,
     528                 :            :                                 args, nargs, wait);
     529                 :          0 :                 break;
     530                 :          0 :         case PROXY_NONE:
     531                 :            :         default:
     532                 :          0 :                 err = vnic_dev_cmd_no_proxy(vdev, cmd, args, nargs, wait);
     533                 :          0 :                 break;
     534                 :            :         }
     535                 :            : 
     536         [ #  # ]:          0 :         if (vf_rep)
     537                 :          0 :                 vnic_dev_cmd_proxy_end(vdev);
     538         [ #  # ]:          0 :         if (vdev->unlock)
     539                 :          0 :                 vdev->unlock(vdev->priv);
     540                 :          0 :         return err;
     541                 :            : }
     542                 :            : 
     543                 :          0 : int vnic_dev_fw_info(struct vnic_dev *vdev,
     544                 :            :                      struct vnic_devcmd_fw_info **fw_info)
     545                 :            : {
     546                 :            :         char name[RTE_MEMZONE_NAMESIZE];
     547                 :          0 :         uint64_t a0, a1 = 0;
     548                 :            :         int wait = 1000;
     549                 :            :         int err = 0;
     550                 :            :         static uint32_t instance;
     551                 :            : 
     552         [ #  # ]:          0 :         if (!vdev->fw_info) {
     553                 :          0 :                 snprintf((char *)name, sizeof(name), "vnic_fw_info-%u",
     554                 :            :                          instance++);
     555                 :          0 :                 vdev->fw_info = vdev->alloc_consistent(vdev->priv,
     556                 :            :                         sizeof(struct vnic_devcmd_fw_info),
     557                 :            :                         &vdev->fw_info_pa, (uint8_t *)name);
     558         [ #  # ]:          0 :                 if (!vdev->fw_info)
     559                 :            :                         return -ENOMEM;
     560                 :          0 :                 a0 = vdev->fw_info_pa;
     561                 :          0 :                 a1 = sizeof(struct vnic_devcmd_fw_info);
     562                 :          0 :                 err = vnic_dev_cmd(vdev, CMD_MCPU_FW_INFO,
     563                 :            :                                    &a0, &a1, wait);
     564                 :            :         }
     565                 :          0 :         *fw_info = vdev->fw_info;
     566                 :          0 :         return err;
     567                 :            : }
     568                 :            : 
     569                 :          0 : static int vnic_dev_advanced_filters_cap(struct vnic_dev *vdev, uint64_t *args,
     570                 :            :                 int nargs)
     571                 :            : {
     572                 :          0 :         memset(args, 0, nargs * sizeof(*args));
     573                 :          0 :         args[0] = CMD_ADD_ADV_FILTER;
     574                 :          0 :         args[1] = FILTER_CAP_MODE_V1_FLAG;
     575                 :          0 :         return vnic_dev_cmd_args(vdev, CMD_CAPABILITY, args, nargs, 1000);
     576                 :            : }
     577                 :            : 
     578                 :          0 : int vnic_dev_capable_adv_filters(struct vnic_dev *vdev)
     579                 :            : {
     580                 :          0 :         uint64_t a0 = CMD_ADD_ADV_FILTER, a1 = 0;
     581                 :            :         int wait = 1000;
     582                 :            :         int err;
     583                 :            : 
     584                 :          0 :         err = vnic_dev_cmd(vdev, CMD_CAPABILITY, &a0, &a1, wait);
     585         [ #  # ]:          0 :         if (err)
     586                 :            :                 return 0;
     587                 :          0 :         return (a1 >= (uint32_t)FILTER_DPDK_1);
     588                 :            : }
     589                 :            : 
     590                 :          0 : int vnic_dev_flowman_cmd(struct vnic_dev *vdev, uint64_t *args, int nargs)
     591                 :            : {
     592                 :            :         int wait = 1000;
     593                 :            : 
     594                 :          0 :         return vnic_dev_cmd_args(vdev, CMD_FLOW_MANAGER_OP, args, nargs, wait);
     595                 :            : }
     596                 :            : 
     597                 :          0 : static int vnic_dev_flowman_enable(struct vnic_dev *vdev, uint32_t *mode,
     598                 :            :                                    uint8_t *filter_actions)
     599                 :            : {
     600                 :            :         char name[RTE_MEMZONE_NAMESIZE];
     601                 :            :         uint64_t args[3];
     602                 :            :         uint64_t ops;
     603                 :            :         static uint32_t instance;
     604                 :            : 
     605                 :            :         /* Advanced filtering is a prerequisite */
     606         [ #  # ]:          0 :         if (!vnic_dev_capable_adv_filters(vdev))
     607                 :            :                 return 0;
     608                 :            :         /* flowman devcmd available? */
     609         [ #  # ]:          0 :         if (!vnic_dev_capable(vdev, CMD_FLOW_MANAGER_OP))
     610                 :            :                 return 0;
     611                 :            :         /* Have the version we are using? */
     612                 :          0 :         args[0] = FM_API_VERSION_QUERY;
     613         [ #  # ]:          0 :         if (vnic_dev_flowman_cmd(vdev, args, 1))
     614                 :            :                 return 0;
     615         [ #  # ]:          0 :         if ((args[0] & (1ULL << FM_VERSION)) == 0)
     616                 :            :                 return 0;
     617                 :            :         /* Select the version */
     618                 :          0 :         args[0] = FM_API_VERSION_SELECT;
     619                 :          0 :         args[1] = FM_VERSION;
     620         [ #  # ]:          0 :         if (vnic_dev_flowman_cmd(vdev, args, 2))
     621                 :            :                 return 0;
     622                 :            :         /* Can we get fm_info? */
     623         [ #  # ]:          0 :         if (!vdev->flowman_info) {
     624                 :          0 :                 snprintf((char *)name, sizeof(name), "vnic_fm_info-%u",
     625                 :            :                          instance++);
     626                 :          0 :                 vdev->flowman_info = vdev->alloc_consistent(vdev->priv,
     627                 :            :                         sizeof(struct fm_info),
     628                 :            :                         &vdev->flowman_info_pa, (uint8_t *)name);
     629         [ #  # ]:          0 :                 if (!vdev->flowman_info)
     630                 :            :                         return 0;
     631                 :            :         }
     632                 :          0 :         args[0] = FM_INFO_QUERY;
     633                 :          0 :         args[1] = vdev->flowman_info_pa;
     634                 :          0 :         args[2] = sizeof(struct fm_info);
     635         [ #  # ]:          0 :         if (vnic_dev_flowman_cmd(vdev, args, 3))
     636                 :            :                 return 0;
     637                 :            :         /* Have required operations? */
     638                 :            :         ops = (1ULL << FMOP_END) |
     639                 :            :                 (1ULL << FMOP_DROP) |
     640                 :            :                 (1ULL << FMOP_RQ_STEER) |
     641                 :            :                 (1ULL << FMOP_EXACT_MATCH) |
     642                 :            :                 (1ULL << FMOP_MARK) |
     643                 :            :                 (1ULL << FMOP_TAG) |
     644                 :            :                 (1ULL << FMOP_EG_HAIRPIN) |
     645                 :            :                 (1ULL << FMOP_ENCAP) |
     646                 :            :                 (1ULL << FMOP_DECAP_NOSTRIP);
     647         [ #  # ]:          0 :         if ((vdev->flowman_info->fm_op_mask & ops) != ops)
     648                 :            :                 return 0;
     649                 :            :         /* Good to use flowman now */
     650                 :          0 :         *mode = FILTER_FLOWMAN;
     651                 :          0 :         *filter_actions = FILTER_ACTION_RQ_STEERING_FLAG |
     652                 :            :                 FILTER_ACTION_FILTER_ID_FLAG |
     653                 :            :                 FILTER_ACTION_COUNTER_FLAG |
     654                 :            :                 FILTER_ACTION_DROP_FLAG;
     655                 :          0 :         return 1;
     656                 :            : }
     657                 :            : 
     658                 :            : /*  Determine the "best" filtering mode VIC is capable of. Returns one of 4
     659                 :            :  *  value or 0 if filtering is unavailble:
     660                 :            :  *      FILTER_FLOWMAN- flowman api capable
     661                 :            :  *      FILTER_DPDK_1- advanced filters availabile
     662                 :            :  *      FILTER_USNIC_IP_FLAG - advanced filters but with the restriction that
     663                 :            :  *              the IP layer must explicitly specified. I.e. cannot have a UDP
     664                 :            :  *              filter that matches both IPv4 and IPv6.
     665                 :            :  *      FILTER_IPV4_5TUPLE - fallback if either of the 2 above aren't available.
     666                 :            :  *              all other filter types are not available.
     667                 :            :  *   Retrun true in filter_tags if supported
     668                 :            :  */
     669                 :          0 : int vnic_dev_capable_filter_mode(struct vnic_dev *vdev, uint32_t *mode,
     670                 :            :                                  uint8_t *filter_actions)
     671                 :            : {
     672                 :            :         uint64_t args[4];
     673                 :            :         int err;
     674                 :            :         uint32_t max_level = 0;
     675                 :            : 
     676                 :            :         /* If flowman is available, use it as it is the most capable API */
     677         [ #  # ]:          0 :         if (vnic_dev_flowman_enable(vdev, mode, filter_actions))
     678                 :            :                 return 0;
     679                 :            : 
     680                 :          0 :         err = vnic_dev_advanced_filters_cap(vdev, args, 4);
     681                 :            : 
     682                 :            :         /* determine supported filter actions */
     683                 :          0 :         *filter_actions = FILTER_ACTION_RQ_STEERING_FLAG; /* always available */
     684         [ #  # ]:          0 :         if (args[2] == FILTER_CAP_MODE_V1)
     685                 :          0 :                 *filter_actions = args[3];
     686                 :            : 
     687   [ #  #  #  #  :          0 :         if (err || ((args[0] == 1) && (args[1] == 0))) {
                   #  # ]
     688                 :            :                 /* Adv filter Command not supported or adv filters available but
     689                 :            :                  * not enabled. Try the normal filter capability command.
     690                 :            :                  */
     691                 :          0 :                 args[0] = CMD_ADD_FILTER;
     692                 :          0 :                 args[1] = 0;
     693                 :          0 :                 err = vnic_dev_cmd_args(vdev, CMD_CAPABILITY, args, 2, 1000);
     694                 :            :                 /*
     695                 :            :                  * ERR_EPERM may be returned if, for example, vNIC is
     696                 :            :                  * on a VF. It simply means no filtering is available
     697                 :            :                  */
     698         [ #  # ]:          0 :                 if (err == -ERR_EPERM) {
     699                 :          0 :                         *mode = 0;
     700                 :          0 :                         return 0;
     701                 :            :                 }
     702         [ #  # ]:          0 :                 if (err)
     703                 :            :                         return err;
     704                 :          0 :                 max_level = args[1];
     705                 :          0 :                 goto parse_max_level;
     706         [ #  # ]:          0 :         } else if (args[2] == FILTER_CAP_MODE_V1) {
     707                 :            :                 /* parse filter capability mask in args[1] */
     708         [ #  # ]:          0 :                 if (args[1] & FILTER_DPDK_1_FLAG)
     709                 :          0 :                         *mode = FILTER_DPDK_1;
     710         [ #  # ]:          0 :                 else if (args[1] & FILTER_USNIC_IP_FLAG)
     711                 :          0 :                         *mode = FILTER_USNIC_IP;
     712         [ #  # ]:          0 :                 else if (args[1] & FILTER_IPV4_5TUPLE_FLAG)
     713                 :          0 :                         *mode = FILTER_IPV4_5TUPLE;
     714                 :          0 :                 return 0;
     715                 :            :         }
     716                 :          0 :         max_level = args[1];
     717                 :          0 : parse_max_level:
     718         [ #  # ]:          0 :         if (max_level >= (uint32_t)FILTER_USNIC_IP)
     719                 :          0 :                 *mode = FILTER_USNIC_IP;
     720                 :            :         else
     721                 :          0 :                 *mode = FILTER_IPV4_5TUPLE;
     722                 :            :         return 0;
     723                 :            : }
     724                 :            : 
     725                 :          0 : void vnic_dev_capable_udp_rss_weak(struct vnic_dev *vdev, bool *cfg_chk,
     726                 :            :                                    bool *weak)
     727                 :            : {
     728                 :          0 :         uint64_t a0 = CMD_NIC_CFG, a1 = 0;
     729                 :            :         int wait = 1000;
     730                 :            :         int err;
     731                 :            : 
     732                 :          0 :         *cfg_chk = false;
     733                 :          0 :         *weak = false;
     734                 :          0 :         err = vnic_dev_cmd(vdev, CMD_CAPABILITY, &a0, &a1, wait);
     735   [ #  #  #  #  :          0 :         if (err == 0 && a0 != 0 && a1 != 0) {
                   #  # ]
     736                 :          0 :                 *cfg_chk = true;
     737                 :          0 :                 *weak = !!((a1 >> 32) & CMD_NIC_CFG_CAPF_UDP_WEAK);
     738                 :            :         }
     739                 :          0 : }
     740                 :            : 
     741                 :          0 : int vnic_dev_capable(struct vnic_dev *vdev, enum vnic_devcmd_cmd cmd)
     742                 :            : {
     743                 :          0 :         uint64_t a0 = (uint32_t)cmd, a1 = 0;
     744                 :            :         int wait = 1000;
     745                 :            :         int err;
     746                 :            : 
     747                 :          0 :         err = vnic_dev_cmd(vdev, CMD_CAPABILITY, &a0, &a1, wait);
     748                 :            : 
     749   [ #  #  #  # ]:          0 :         return !(err || a0);
     750                 :            : }
     751                 :            : 
     752                 :          0 : int vnic_dev_spec(struct vnic_dev *vdev, unsigned int offset, size_t size,
     753                 :            :         void *value)
     754                 :            : {
     755                 :            :         uint64_t a0, a1;
     756                 :            :         int wait = 1000;
     757                 :            :         int err;
     758                 :            : 
     759                 :          0 :         a0 = offset;
     760                 :          0 :         a1 = size;
     761                 :            : 
     762                 :          0 :         err = vnic_dev_cmd(vdev, CMD_DEV_SPEC, &a0, &a1, wait);
     763                 :            : 
     764   [ #  #  #  #  :          0 :         switch (size) {
                      # ]
     765                 :          0 :         case 1:
     766                 :          0 :                 *(uint8_t *)value = (uint8_t)a0;
     767                 :          0 :                 break;
     768                 :          0 :         case 2:
     769                 :          0 :                 *(uint16_t *)value = (uint16_t)a0;
     770                 :          0 :                 break;
     771                 :          0 :         case 4:
     772                 :          0 :                 *(uint32_t *)value = (uint32_t)a0;
     773                 :          0 :                 break;
     774                 :          0 :         case 8:
     775                 :          0 :                 *(uint64_t *)value = a0;
     776                 :          0 :                 break;
     777                 :          0 :         default:
     778                 :          0 :                 BUG();
     779                 :          0 :                 break;
     780                 :            :         }
     781                 :            : 
     782                 :          0 :         return err;
     783                 :            : }
     784                 :            : 
     785                 :          0 : int vnic_dev_stats_clear(struct vnic_dev *vdev)
     786                 :            : {
     787                 :          0 :         uint64_t a0 = 0, a1 = 0;
     788                 :            :         int wait = 1000;
     789                 :            : 
     790                 :          0 :         return vnic_dev_cmd(vdev, CMD_STATS_CLEAR, &a0, &a1, wait);
     791                 :            : }
     792                 :            : 
     793                 :          0 : int vnic_dev_stats_dump(struct vnic_dev *vdev, struct vnic_stats **stats)
     794                 :            : {
     795                 :            :         uint64_t a0, a1;
     796                 :            :         int wait = 1000;
     797                 :            : 
     798         [ #  # ]:          0 :         if (!vdev->stats)
     799                 :            :                 return -ENOMEM;
     800                 :            : 
     801                 :          0 :         *stats = vdev->stats;
     802                 :          0 :         a0 = vdev->stats_pa;
     803                 :          0 :         a1 = sizeof(struct vnic_stats);
     804                 :            : 
     805                 :          0 :         return vnic_dev_cmd(vdev, CMD_STATS_DUMP, &a0, &a1, wait);
     806                 :            : }
     807                 :            : 
     808                 :          0 : int vnic_dev_close(struct vnic_dev *vdev)
     809                 :            : {
     810                 :          0 :         uint64_t a0 = 0, a1 = 0;
     811                 :            :         int wait = 1000;
     812                 :            : 
     813                 :          0 :         return vnic_dev_cmd(vdev, CMD_CLOSE, &a0, &a1, wait);
     814                 :            : }
     815                 :            : 
     816                 :          0 : int vnic_dev_enable_wait(struct vnic_dev *vdev)
     817                 :            : {
     818                 :          0 :         uint64_t a0 = 0, a1 = 0;
     819                 :            :         int wait = 1000;
     820                 :            : 
     821         [ #  # ]:          0 :         if (vnic_dev_capable(vdev, CMD_ENABLE_WAIT))
     822                 :          0 :                 return vnic_dev_cmd(vdev, CMD_ENABLE_WAIT, &a0, &a1, wait);
     823                 :            :         else
     824                 :          0 :                 return vnic_dev_cmd(vdev, CMD_ENABLE, &a0, &a1, wait);
     825                 :            : }
     826                 :            : 
     827                 :          0 : int vnic_dev_disable(struct vnic_dev *vdev)
     828                 :            : {
     829                 :          0 :         uint64_t a0 = 0, a1 = 0;
     830                 :            :         int wait = 1000;
     831                 :            : 
     832                 :          0 :         return vnic_dev_cmd(vdev, CMD_DISABLE, &a0, &a1, wait);
     833                 :            : }
     834                 :            : 
     835                 :          0 : int vnic_dev_open(struct vnic_dev *vdev, int arg)
     836                 :            : {
     837                 :          0 :         uint64_t a0 = (uint32_t)arg, a1 = 0;
     838                 :            :         int wait = 1000;
     839                 :            : 
     840                 :          0 :         return vnic_dev_cmd(vdev, CMD_OPEN, &a0, &a1, wait);
     841                 :            : }
     842                 :            : 
     843                 :          0 : int vnic_dev_open_done(struct vnic_dev *vdev, int *done)
     844                 :            : {
     845                 :          0 :         uint64_t a0 = 0, a1 = 0;
     846                 :            :         int wait = 1000;
     847                 :            :         int err;
     848                 :            : 
     849                 :          0 :         *done = 0;
     850                 :            : 
     851                 :          0 :         err = vnic_dev_cmd(vdev, CMD_OPEN_STATUS, &a0, &a1, wait);
     852         [ #  # ]:          0 :         if (err)
     853                 :            :                 return err;
     854                 :            : 
     855                 :          0 :         *done = (a0 == 0);
     856                 :            : 
     857                 :          0 :         return 0;
     858                 :            : }
     859                 :            : 
     860                 :          0 : int vnic_dev_get_mac_addr(struct vnic_dev *vdev, uint8_t *mac_addr)
     861                 :            : {
     862                 :          0 :         uint64_t a0 = 0, a1 = 0;
     863                 :            :         int wait = 1000;
     864                 :            :         int err, i;
     865                 :            : 
     866         [ #  # ]:          0 :         for (i = 0; i < RTE_ETHER_ADDR_LEN; i++)
     867                 :          0 :                 mac_addr[i] = 0;
     868                 :            : 
     869                 :          0 :         err = vnic_dev_cmd(vdev, CMD_GET_MAC_ADDR, &a0, &a1, wait);
     870         [ #  # ]:          0 :         if (err)
     871                 :            :                 return err;
     872                 :            : 
     873         [ #  # ]:          0 :         for (i = 0; i < RTE_ETHER_ADDR_LEN; i++)
     874                 :          0 :                 mac_addr[i] = ((uint8_t *)&a0)[i];
     875                 :            : 
     876                 :            :         return 0;
     877                 :            : }
     878                 :            : 
     879                 :          0 : int vnic_dev_packet_filter(struct vnic_dev *vdev, int directed, int multicast,
     880                 :            :         int broadcast, int promisc, int allmulti)
     881                 :            : {
     882                 :          0 :         uint64_t a0, a1 = 0;
     883                 :            :         int wait = 1000;
     884                 :            :         int err;
     885                 :            : 
     886                 :          0 :         a0 = (directed ? CMD_PFILTER_DIRECTED : 0) |
     887         [ #  # ]:          0 :              (multicast ? CMD_PFILTER_MULTICAST : 0) |
     888         [ #  # ]:          0 :              (broadcast ? CMD_PFILTER_BROADCAST : 0) |
     889         [ #  # ]:          0 :              (promisc ? CMD_PFILTER_PROMISCUOUS : 0) |
     890         [ #  # ]:          0 :              (allmulti ? CMD_PFILTER_ALL_MULTICAST : 0);
     891                 :            : 
     892                 :          0 :         err = vnic_dev_cmd(vdev, CMD_PACKET_FILTER, &a0, &a1, wait);
     893         [ #  # ]:          0 :         if (err)
     894                 :          0 :                 pr_err("Can't set packet filter\n");
     895                 :            : 
     896                 :          0 :         return err;
     897                 :            : }
     898                 :            : 
     899                 :          0 : int vnic_dev_add_addr(struct vnic_dev *vdev, uint8_t *addr)
     900                 :            : {
     901                 :          0 :         uint64_t a0 = 0, a1 = 0;
     902                 :            :         int wait = 1000;
     903                 :            :         int err;
     904                 :            :         int i;
     905                 :            : 
     906         [ #  # ]:          0 :         for (i = 0; i < RTE_ETHER_ADDR_LEN; i++)
     907                 :          0 :                 ((uint8_t *)&a0)[i] = addr[i];
     908                 :            : 
     909                 :          0 :         err = vnic_dev_cmd(vdev, CMD_ADDR_ADD, &a0, &a1, wait);
     910         [ #  # ]:          0 :         if (err)
     911                 :          0 :                 pr_err("Can't add addr [" RTE_ETHER_ADDR_PRT_FMT "], %d\n",
     912                 :            :                         addr[0], addr[1], addr[2], addr[3], addr[4], addr[5],
     913                 :            :                         err);
     914                 :            : 
     915                 :          0 :         return err;
     916                 :            : }
     917                 :            : 
     918                 :          0 : int vnic_dev_del_addr(struct vnic_dev *vdev, uint8_t *addr)
     919                 :            : {
     920                 :          0 :         uint64_t a0 = 0, a1 = 0;
     921                 :            :         int wait = 1000;
     922                 :            :         int err;
     923                 :            :         int i;
     924                 :            : 
     925         [ #  # ]:          0 :         for (i = 0; i < RTE_ETHER_ADDR_LEN; i++)
     926                 :          0 :                 ((uint8_t *)&a0)[i] = addr[i];
     927                 :            : 
     928                 :          0 :         err = vnic_dev_cmd(vdev, CMD_ADDR_DEL, &a0, &a1, wait);
     929         [ #  # ]:          0 :         if (err)
     930                 :          0 :                 pr_err("Can't del addr [" RTE_ETHER_ADDR_PRT_FMT "], %d\n",
     931                 :            :                         addr[0], addr[1], addr[2], addr[3], addr[4], addr[5],
     932                 :            :                         err);
     933                 :            : 
     934                 :          0 :         return err;
     935                 :            : }
     936                 :            : 
     937                 :          0 : int vnic_dev_set_ig_vlan_rewrite_mode(struct vnic_dev *vdev,
     938                 :            :         uint8_t ig_vlan_rewrite_mode)
     939                 :            : {
     940                 :          0 :         uint64_t a0 = ig_vlan_rewrite_mode, a1 = 0;
     941                 :            :         int wait = 1000;
     942                 :            : 
     943         [ #  # ]:          0 :         if (vnic_dev_capable(vdev, CMD_IG_VLAN_REWRITE_MODE))
     944                 :          0 :                 return vnic_dev_cmd(vdev, CMD_IG_VLAN_REWRITE_MODE,
     945                 :            :                                 &a0, &a1, wait);
     946                 :            :         else
     947                 :            :                 return 0;
     948                 :            : }
     949                 :            : 
     950                 :          0 : void vnic_dev_set_reset_flag(struct vnic_dev *vdev, int state)
     951                 :            : {
     952                 :          0 :         vdev->in_reset = state;
     953                 :          0 : }
     954                 :            : 
     955                 :            : static inline int vnic_dev_in_reset(struct vnic_dev *vdev)
     956                 :            : {
     957                 :          0 :         return vdev->in_reset;
     958                 :            : }
     959                 :            : 
     960         [ #  # ]:          0 : int vnic_dev_notify_setcmd(struct vnic_dev *vdev,
     961                 :            :         void *notify_addr, dma_addr_t notify_pa, uint16_t intr)
     962                 :            : {
     963                 :            :         uint64_t a0, a1;
     964                 :            :         int wait = 1000;
     965                 :            :         int r;
     966                 :            : 
     967                 :            :         memset(notify_addr, 0, sizeof(struct vnic_devcmd_notify));
     968         [ #  # ]:          0 :         if (!vnic_dev_in_reset(vdev)) {
     969                 :          0 :                 vdev->notify = notify_addr;
     970                 :          0 :                 vdev->notify_pa = notify_pa;
     971                 :            :         }
     972                 :            : 
     973                 :          0 :         a0 = (uint64_t)notify_pa;
     974                 :          0 :         a1 = ((uint64_t)intr << 32) & 0x0000ffff00000000ULL;
     975                 :          0 :         a1 += sizeof(struct vnic_devcmd_notify);
     976                 :            : 
     977                 :          0 :         r = vnic_dev_cmd(vdev, CMD_NOTIFY, &a0, &a1, wait);
     978         [ #  # ]:          0 :         if (!vnic_dev_in_reset(vdev))
     979         [ #  # ]:          0 :                 vdev->notify_sz = (r == 0) ? (uint32_t)a1 : 0;
     980                 :            : 
     981                 :          0 :         return r;
     982                 :            : }
     983                 :            : 
     984                 :          0 : int vnic_dev_notify_set(struct vnic_dev *vdev, uint16_t intr)
     985                 :            : {
     986                 :            :         void *notify_addr = NULL;
     987                 :          0 :         dma_addr_t notify_pa = 0;
     988                 :            :         char name[RTE_MEMZONE_NAMESIZE];
     989                 :            :         static uint32_t instance;
     990                 :            : 
     991   [ #  #  #  # ]:          0 :         if (vdev->notify || vdev->notify_pa) {
     992                 :          0 :                 return vnic_dev_notify_setcmd(vdev, vdev->notify,
     993                 :            :                                               vdev->notify_pa, intr);
     994                 :            :         }
     995         [ #  # ]:          0 :         if (!vnic_dev_in_reset(vdev)) {
     996                 :          0 :                 snprintf((char *)name, sizeof(name),
     997                 :            :                         "vnic_notify-%u", instance++);
     998                 :          0 :                 notify_addr = vdev->alloc_consistent(vdev->priv,
     999                 :            :                         sizeof(struct vnic_devcmd_notify),
    1000                 :            :                         &notify_pa, (uint8_t *)name);
    1001         [ #  # ]:          0 :                 if (!notify_addr)
    1002                 :            :                         return -ENOMEM;
    1003                 :            :         }
    1004                 :            : 
    1005                 :          0 :         return vnic_dev_notify_setcmd(vdev, notify_addr, notify_pa, intr);
    1006                 :            : }
    1007                 :            : 
    1008                 :          0 : int vnic_dev_notify_unsetcmd(struct vnic_dev *vdev)
    1009                 :            : {
    1010                 :            :         uint64_t a0, a1;
    1011                 :            :         int wait = 1000;
    1012                 :            :         int err;
    1013                 :            : 
    1014                 :          0 :         a0 = 0;  /* paddr = 0 to unset notify buffer */
    1015                 :            :         a1 = 0x0000ffff00000000ULL; /* intr num = -1 to unreg for intr */
    1016                 :          0 :         a1 += sizeof(struct vnic_devcmd_notify);
    1017                 :            : 
    1018                 :          0 :         err = vnic_dev_cmd(vdev, CMD_NOTIFY, &a0, &a1, wait);
    1019         [ #  # ]:          0 :         if (!vnic_dev_in_reset(vdev)) {
    1020                 :          0 :                 vdev->notify = NULL;
    1021                 :          0 :                 vdev->notify_pa = 0;
    1022                 :          0 :                 vdev->notify_sz = 0;
    1023                 :            :         }
    1024                 :            : 
    1025                 :          0 :         return err;
    1026                 :            : }
    1027                 :            : 
    1028                 :          0 : int vnic_dev_notify_unset(struct vnic_dev *vdev)
    1029                 :            : {
    1030   [ #  #  #  # ]:          0 :         if (vdev->notify && !vnic_dev_in_reset(vdev)) {
    1031                 :          0 :                 vdev->free_consistent(vdev->priv,
    1032                 :            :                         sizeof(struct vnic_devcmd_notify),
    1033                 :            :                         vdev->notify,
    1034                 :            :                         vdev->notify_pa);
    1035                 :            :         }
    1036                 :            : 
    1037                 :          0 :         return vnic_dev_notify_unsetcmd(vdev);
    1038                 :            : }
    1039                 :            : 
    1040                 :          0 : static int vnic_dev_notify_ready(struct vnic_dev *vdev)
    1041                 :            : {
    1042                 :            :         uint32_t *words;
    1043                 :          0 :         unsigned int nwords = vdev->notify_sz / 4;
    1044                 :            :         unsigned int i;
    1045                 :            :         uint32_t csum;
    1046                 :            : 
    1047   [ #  #  #  # ]:          0 :         if (!vdev->notify || !vdev->notify_sz)
    1048                 :            :                 return 0;
    1049                 :            : 
    1050                 :            :         do {
    1051                 :            :                 csum = 0;
    1052         [ #  # ]:          0 :                 rte_memcpy(&vdev->notify_copy, vdev->notify, vdev->notify_sz);
    1053                 :            :                 words = (uint32_t *)&vdev->notify_copy;
    1054         [ #  # ]:          0 :                 for (i = 1; i < nwords; i++)
    1055                 :          0 :                         csum += words[i];
    1056         [ #  # ]:          0 :         } while (csum != words[0]);
    1057                 :            : 
    1058                 :            :         return 1;
    1059                 :            : }
    1060                 :            : 
    1061                 :          0 : int vnic_dev_init(struct vnic_dev *vdev, int arg)
    1062                 :            : {
    1063                 :          0 :         uint64_t a0 = (uint32_t)arg, a1 = 0;
    1064                 :            :         int wait = 1000;
    1065                 :            :         int r = 0;
    1066                 :            : 
    1067         [ #  # ]:          0 :         if (vnic_dev_capable(vdev, CMD_INIT))
    1068                 :          0 :                 r = vnic_dev_cmd(vdev, CMD_INIT, &a0, &a1, wait);
    1069                 :            :         else {
    1070                 :          0 :                 vnic_dev_cmd(vdev, CMD_INIT_v1, &a0, &a1, wait);
    1071         [ #  # ]:          0 :                 if (a0 & CMD_INITF_DEFAULT_MAC) {
    1072                 :            :                         /* Emulate these for old CMD_INIT_v1 which
    1073                 :            :                          * didn't pass a0 so no CMD_INITF_*.
    1074                 :            :                          */
    1075                 :          0 :                         vnic_dev_cmd(vdev, CMD_GET_MAC_ADDR, &a0, &a1, wait);
    1076                 :          0 :                         vnic_dev_cmd(vdev, CMD_ADDR_ADD, &a0, &a1, wait);
    1077                 :            :                 }
    1078                 :            :         }
    1079                 :          0 :         return r;
    1080                 :            : }
    1081                 :            : 
    1082                 :          0 : void vnic_dev_intr_coal_timer_info_default(struct vnic_dev *vdev)
    1083                 :            : {
    1084                 :            :         /* Default: hardware intr coal timer is in units of 1.5 usecs */
    1085                 :          0 :         vdev->intr_coal_timer_info.mul = 2;
    1086                 :          0 :         vdev->intr_coal_timer_info.div = 3;
    1087                 :          0 :         vdev->intr_coal_timer_info.max_usec =
    1088                 :          0 :                 vnic_dev_intr_coal_timer_hw_to_usec(vdev, 0xffff);
    1089                 :          0 : }
    1090                 :            : 
    1091                 :          0 : int vnic_dev_link_status(struct vnic_dev *vdev)
    1092                 :            : {
    1093         [ #  # ]:          0 :         if (!vnic_dev_notify_ready(vdev))
    1094                 :            :                 return 0;
    1095                 :            : 
    1096                 :          0 :         return vdev->notify_copy.link_state;
    1097                 :            : }
    1098                 :            : 
    1099                 :          0 : uint32_t vnic_dev_port_speed(struct vnic_dev *vdev)
    1100                 :            : {
    1101         [ #  # ]:          0 :         if (!vnic_dev_notify_ready(vdev))
    1102                 :            :                 return 0;
    1103                 :            : 
    1104                 :          0 :         return vdev->notify_copy.port_speed;
    1105                 :            : }
    1106                 :            : 
    1107                 :          0 : uint32_t vnic_dev_mtu(struct vnic_dev *vdev)
    1108                 :            : {
    1109         [ #  # ]:          0 :         if (!vnic_dev_notify_ready(vdev))
    1110                 :            :                 return 0;
    1111                 :            : 
    1112                 :          0 :         return vdev->notify_copy.mtu;
    1113                 :            : }
    1114                 :            : 
    1115                 :          0 : uint32_t vnic_dev_uif(struct vnic_dev *vdev)
    1116                 :            : {
    1117         [ #  # ]:          0 :         if (!vnic_dev_notify_ready(vdev))
    1118                 :            :                 return 0;
    1119                 :            : 
    1120                 :          0 :         return vdev->notify_copy.uif;
    1121                 :            : }
    1122                 :            : 
    1123                 :          0 : uint32_t vnic_dev_intr_coal_timer_usec_to_hw(struct vnic_dev *vdev,
    1124                 :            :                                              uint32_t usec)
    1125                 :            : {
    1126                 :          0 :         return (usec * vdev->intr_coal_timer_info.mul) /
    1127                 :          0 :                 vdev->intr_coal_timer_info.div;
    1128                 :            : }
    1129                 :            : 
    1130                 :          0 : uint32_t vnic_dev_intr_coal_timer_hw_to_usec(struct vnic_dev *vdev,
    1131                 :            :                                              uint32_t hw_cycles)
    1132                 :            : {
    1133                 :          0 :         return (hw_cycles * vdev->intr_coal_timer_info.div) /
    1134                 :          0 :                 vdev->intr_coal_timer_info.mul;
    1135                 :            : }
    1136                 :            : 
    1137                 :          0 : uint32_t vnic_dev_get_intr_coal_timer_max(struct vnic_dev *vdev)
    1138                 :            : {
    1139                 :          0 :         return vdev->intr_coal_timer_info.max_usec;
    1140                 :            : }
    1141                 :            : 
    1142                 :          0 : int vnic_dev_alloc_stats_mem(struct vnic_dev *vdev)
    1143                 :            : {
    1144                 :            :         char name[RTE_MEMZONE_NAMESIZE];
    1145                 :            :         static uint32_t instance;
    1146                 :            : 
    1147                 :          0 :         snprintf((char *)name, sizeof(name), "vnic_stats-%u", instance++);
    1148                 :          0 :         vdev->stats = vdev->alloc_consistent(vdev->priv,
    1149                 :            :                                              sizeof(struct vnic_stats),
    1150                 :            :                                              &vdev->stats_pa, (uint8_t *)name);
    1151         [ #  # ]:          0 :         return vdev->stats == NULL ? -ENOMEM : 0;
    1152                 :            : }
    1153                 :            : 
    1154                 :          0 : int vnic_dev_alloc_sriov_stats_mem(struct vnic_dev *vdev)
    1155                 :            : {
    1156                 :            :         char name[RTE_MEMZONE_NAMESIZE];
    1157                 :            :         static uint32_t instance;
    1158                 :            : 
    1159                 :          0 :         snprintf((char *)name, sizeof(name), "vnic_sriov_stats-%u", instance++);
    1160                 :          0 :         vdev->sriov_stats = vdev->alloc_consistent(vdev->priv,
    1161                 :            :                                              sizeof(struct vnic_sriov_stats),
    1162                 :            :                                              &vdev->sriov_stats_pa, (uint8_t *)name);
    1163         [ #  # ]:          0 :         return vdev->sriov_stats == NULL ? -ENOMEM : 0;
    1164                 :            : }
    1165                 :            : 
    1166                 :          0 : void vnic_dev_unregister(struct vnic_dev *vdev)
    1167                 :            : {
    1168         [ #  # ]:          0 :         if (vdev) {
    1169         [ #  # ]:          0 :                 if (vdev->notify)
    1170                 :          0 :                         vdev->free_consistent(vdev->priv,
    1171                 :            :                                 sizeof(struct vnic_devcmd_notify),
    1172                 :            :                                 vdev->notify,
    1173                 :            :                                 vdev->notify_pa);
    1174         [ #  # ]:          0 :                 if (vdev->stats)
    1175                 :          0 :                         vdev->free_consistent(vdev->priv,
    1176                 :            :                                 sizeof(struct vnic_stats),
    1177                 :            :                                 vdev->stats, vdev->stats_pa);
    1178         [ #  # ]:          0 :                 if (vdev->sriov_stats)
    1179                 :          0 :                         vdev->free_consistent(vdev->priv,
    1180                 :            :                                 sizeof(struct vnic_sriov_stats),
    1181                 :            :                                 vdev->sriov_stats, vdev->sriov_stats_pa);
    1182         [ #  # ]:          0 :                 if (vdev->flowman_info)
    1183                 :          0 :                         vdev->free_consistent(vdev->priv,
    1184                 :            :                                 sizeof(struct fm_info),
    1185                 :            :                                 vdev->flowman_info, vdev->flowman_info_pa);
    1186         [ #  # ]:          0 :                 if (vdev->fw_info)
    1187                 :          0 :                         vdev->free_consistent(vdev->priv,
    1188                 :            :                                 sizeof(struct vnic_devcmd_fw_info),
    1189                 :            :                                 vdev->fw_info, vdev->fw_info_pa);
    1190                 :          0 :                 rte_free(vdev);
    1191                 :            :         }
    1192                 :          0 : }
    1193                 :            : 
    1194                 :          0 : struct vnic_dev *vnic_dev_register(struct vnic_dev *vdev,
    1195                 :            :         void *priv, struct rte_pci_device *pdev, struct vnic_dev_bar *bar,
    1196                 :            :         unsigned int num_bars)
    1197                 :            : {
    1198         [ #  # ]:          0 :         if (!vdev) {
    1199                 :            :                 char name[RTE_MEMZONE_NAMESIZE];
    1200                 :          0 :                 snprintf((char *)name, sizeof(name), "%s-vnic",
    1201                 :            :                           pdev->device.name);
    1202                 :          0 :                 vdev = (struct vnic_dev *)rte_zmalloc_socket(name,
    1203                 :            :                                         sizeof(struct vnic_dev),
    1204                 :            :                                         RTE_CACHE_LINE_SIZE,
    1205                 :            :                                         pdev->device.numa_node);
    1206         [ #  # ]:          0 :                 if (!vdev)
    1207                 :          0 :                         return NULL;
    1208                 :            :         }
    1209                 :            : 
    1210                 :          0 :         vdev->priv = priv;
    1211                 :          0 :         vdev->pdev = pdev;
    1212                 :            : 
    1213         [ #  # ]:          0 :         if (vnic_dev_discover_res(vdev, bar, num_bars))
    1214                 :          0 :                 goto err_out;
    1215                 :            : 
    1216                 :          0 :         vdev->devcmd = vnic_dev_get_res(vdev, RES_TYPE_DEVCMD, 0);
    1217         [ #  # ]:          0 :         if (!vdev->devcmd)
    1218                 :          0 :                 goto err_out;
    1219                 :            : 
    1220                 :            :         return vdev;
    1221                 :            : 
    1222                 :          0 : err_out:
    1223                 :          0 :         vnic_dev_unregister(vdev);
    1224                 :          0 :         return NULL;
    1225                 :            : }
    1226                 :            : 
    1227                 :          0 : struct vnic_dev *vnic_vf_rep_register(void *priv, struct vnic_dev *pf_vdev,
    1228                 :            :         int vf_id)
    1229                 :            : {
    1230                 :            :         struct vnic_dev *vdev;
    1231                 :            : 
    1232                 :          0 :         vdev = (struct vnic_dev *)rte_zmalloc("enic-vf-rep-vdev",
    1233                 :            :                                 sizeof(struct vnic_dev), RTE_CACHE_LINE_SIZE);
    1234         [ #  # ]:          0 :         if (!vdev)
    1235                 :            :                 return NULL;
    1236                 :          0 :         vdev->priv = priv;
    1237                 :          0 :         vdev->pf_vdev = pf_vdev;
    1238                 :          0 :         vdev->vf_id = vf_id;
    1239                 :          0 :         vdev->alloc_consistent = pf_vdev->alloc_consistent;
    1240                 :          0 :         vdev->free_consistent = pf_vdev->free_consistent;
    1241                 :          0 :         return vdev;
    1242                 :            : }
    1243                 :            : 
    1244                 :            : /*
    1245                 :            :  *  vnic_dev_classifier: Add/Delete classifier entries
    1246                 :            :  *  @vdev: vdev of the device
    1247                 :            :  *  @cmd: CLSF_ADD for Add filter
    1248                 :            :  *        CLSF_DEL for Delete filter
    1249                 :            :  *  @entry: In case of ADD filter, the caller passes the RQ number in this
    1250                 :            :  *          variable.
    1251                 :            :  *          This function stores the filter_id returned by the
    1252                 :            :  *          firmware in the same variable before return;
    1253                 :            :  *
    1254                 :            :  *          In case of DEL filter, the caller passes the RQ number. Return
    1255                 :            :  *          value is irrelevant.
    1256                 :            :  * @data: filter data
    1257                 :            :  * @action: action data
    1258                 :            :  */
    1259                 :          0 : int vnic_dev_classifier(struct vnic_dev *vdev, uint8_t cmd, uint16_t *entry,
    1260                 :            :         struct filter_v2 *data, struct filter_action_v2 *action_v2)
    1261                 :            : {
    1262                 :          0 :         uint64_t a0 = 0, a1 = 0;
    1263                 :            :         int wait = 1000;
    1264                 :            :         dma_addr_t tlv_pa;
    1265                 :            :         int ret = -EINVAL;
    1266                 :            :         struct filter_tlv *tlv, *tlv_va;
    1267                 :            :         uint64_t tlv_size;
    1268                 :            :         uint32_t filter_size, action_size;
    1269                 :            :         static unsigned int unique_id;
    1270                 :            :         char z_name[RTE_MEMZONE_NAMESIZE];
    1271                 :            :         enum vnic_devcmd_cmd dev_cmd;
    1272                 :            : 
    1273         [ #  # ]:          0 :         if (cmd == CLSF_ADD) {
    1274                 :          0 :                 dev_cmd = (data->type >= FILTER_DPDK_1) ?
    1275         [ #  # ]:          0 :                           CMD_ADD_ADV_FILTER : CMD_ADD_FILTER;
    1276                 :            : 
    1277                 :            :                 filter_size = vnic_filter_size(data);
    1278                 :            :                 action_size = vnic_action_size(action_v2);
    1279                 :            : 
    1280                 :          0 :                 tlv_size = filter_size + action_size +
    1281                 :            :                     2*sizeof(struct filter_tlv);
    1282                 :          0 :                 snprintf((char *)z_name, sizeof(z_name),
    1283                 :            :                         "vnic_clsf_%u", unique_id++);
    1284                 :          0 :                 tlv_va = vdev->alloc_consistent(vdev->priv,
    1285                 :            :                         tlv_size, &tlv_pa, (uint8_t *)z_name);
    1286         [ #  # ]:          0 :                 if (!tlv_va)
    1287                 :            :                         return -ENOMEM;
    1288                 :            :                 tlv = tlv_va;
    1289                 :          0 :                 a0 = tlv_pa;
    1290                 :          0 :                 a1 = tlv_size;
    1291                 :            :                 memset(tlv, 0, tlv_size);
    1292                 :          0 :                 tlv->type = CLSF_TLV_FILTER;
    1293                 :          0 :                 tlv->length = filter_size;
    1294                 :          0 :                 memcpy(&tlv->val, (void *)data, filter_size);
    1295                 :            : 
    1296                 :          0 :                 tlv = (struct filter_tlv *)((char *)tlv +
    1297                 :          0 :                                          sizeof(struct filter_tlv) +
    1298                 :            :                                          filter_size);
    1299                 :            : 
    1300                 :          0 :                 tlv->type = CLSF_TLV_ACTION;
    1301                 :          0 :                 tlv->length = action_size;
    1302                 :          0 :                 memcpy(&tlv->val, (void *)action_v2, action_size);
    1303                 :          0 :                 ret = vnic_dev_cmd(vdev, dev_cmd, &a0, &a1, wait);
    1304                 :          0 :                 *entry = (uint16_t)a0;
    1305                 :          0 :                 vdev->free_consistent(vdev->priv, tlv_size, tlv_va, tlv_pa);
    1306         [ #  # ]:          0 :         } else if (cmd == CLSF_DEL) {
    1307                 :          0 :                 a0 = *entry;
    1308                 :          0 :                 ret = vnic_dev_cmd(vdev, CMD_DEL_FILTER, &a0, &a1, wait);
    1309                 :            :         }
    1310                 :            : 
    1311                 :            :         return ret;
    1312                 :            : }
    1313                 :            : 
    1314                 :          0 : int vnic_dev_overlay_offload_ctrl(struct vnic_dev *vdev, uint8_t overlay,
    1315                 :            :                                   uint8_t config)
    1316                 :            : {
    1317                 :          0 :         uint64_t a0 = overlay;
    1318                 :          0 :         uint64_t a1 = config;
    1319                 :            :         int wait = 1000;
    1320                 :            : 
    1321                 :          0 :         return vnic_dev_cmd(vdev, CMD_OVERLAY_OFFLOAD_CTRL, &a0, &a1, wait);
    1322                 :            : }
    1323                 :            : 
    1324                 :          0 : int vnic_dev_overlay_offload_cfg(struct vnic_dev *vdev, uint8_t overlay,
    1325                 :            :                                  uint16_t vxlan_udp_port_number)
    1326                 :            : {
    1327                 :          0 :         uint64_t a1 = vxlan_udp_port_number;
    1328                 :          0 :         uint64_t a0 = overlay;
    1329                 :            :         int wait = 1000;
    1330                 :            : 
    1331                 :          0 :         return vnic_dev_cmd(vdev, CMD_OVERLAY_OFFLOAD_CFG, &a0, &a1, wait);
    1332                 :            : }
    1333                 :            : 
    1334                 :          0 : int vnic_dev_capable_vxlan(struct vnic_dev *vdev)
    1335                 :            : {
    1336                 :          0 :         uint64_t a0 = VIC_FEATURE_VXLAN;
    1337                 :          0 :         uint64_t a1 = 0;
    1338                 :            :         int wait = 1000;
    1339                 :            :         int ret;
    1340                 :            : 
    1341                 :          0 :         ret = vnic_dev_cmd(vdev, CMD_GET_SUPP_FEATURE_VER, &a0, &a1, wait);
    1342                 :            :         /* 1 if the NIC can do VXLAN for both IPv4 and IPv6 with multiple WQs */
    1343         [ #  # ]:          0 :         return ret == 0 &&
    1344         [ #  # ]:          0 :                 (a1 & (FEATURE_VXLAN_IPV6 | FEATURE_VXLAN_MULTI_WQ)) ==
    1345                 :            :                 (FEATURE_VXLAN_IPV6 | FEATURE_VXLAN_MULTI_WQ);
    1346                 :            : }
    1347                 :            : 
    1348                 :          0 : int vnic_dev_capable_geneve(struct vnic_dev *vdev)
    1349                 :            : {
    1350                 :          0 :         uint64_t a0 = VIC_FEATURE_GENEVE;
    1351                 :          0 :         uint64_t a1 = 0;
    1352                 :            :         int wait = 1000;
    1353                 :            :         int ret;
    1354                 :            : 
    1355                 :          0 :         ret = vnic_dev_cmd(vdev, CMD_GET_SUPP_FEATURE_VER, &a0, &a1, wait);
    1356   [ #  #  #  # ]:          0 :         return ret == 0 && !!(a1 & FEATURE_GENEVE_OPTIONS);
    1357                 :            : }
    1358                 :            : 
    1359                 :          0 : uint64_t vnic_dev_capable_cq_entry_size(struct vnic_dev *vdev)
    1360                 :            : {
    1361                 :          0 :         uint64_t a0 = CMD_CQ_ENTRY_SIZE_SET;
    1362                 :          0 :         uint64_t a1 = 0;
    1363                 :            :         int wait = 1000;
    1364                 :            :         int ret;
    1365                 :            : 
    1366                 :          0 :         ret = vnic_dev_cmd(vdev, CMD_CAPABILITY, &a0, &a1, wait);
    1367                 :            :         /* All models support 16B CQ entry by default */
    1368   [ #  #  #  # ]:          0 :         if (!(ret == 0 && a0 == 0))
    1369                 :          0 :                 a1 = VNIC_RQ_CQ_ENTRY_SIZE_16_CAPABLE;
    1370                 :          0 :         return a1;
    1371                 :            : }
    1372                 :            : 
    1373                 :          0 : int vnic_dev_set_cq_entry_size(struct vnic_dev *vdev, uint32_t rq_idx,
    1374                 :            :                                uint32_t size_flag)
    1375                 :            : {
    1376                 :          0 :         uint64_t a0 = rq_idx;
    1377                 :          0 :         uint64_t a1 = size_flag;
    1378                 :            :         int wait = 1000;
    1379                 :            : 
    1380                 :          0 :         return vnic_dev_cmd(vdev, CMD_CQ_ENTRY_SIZE_SET, &a0, &a1, wait);
    1381                 :            : }
    1382                 :            : 
    1383                 :          0 : int vnic_dev_enable_admin_qp(struct vnic_dev *vdev, uint32_t enable)
    1384                 :            : {
    1385                 :            :         uint64_t a0, a1;
    1386                 :            :         int wait = 1000;
    1387                 :            : 
    1388                 :          0 :         a0 = QP_TYPE_ADMIN;
    1389                 :          0 :         a1 = enable;
    1390                 :          0 :         return vnic_dev_cmd(vdev, CMD_QP_TYPE_SET, &a0, &a1, wait);
    1391                 :            : }
    1392                 :            : 
    1393                 :          0 : int vnic_dev_sriov_stats(struct vnic_dev *vdev, struct vnic_sriov_stats **stats)
    1394                 :            : {
    1395                 :            :         uint64_t a0, a1;
    1396                 :            :         int wait = 1000;
    1397                 :            :         int err;
    1398                 :            : 
    1399                 :          0 :         a0 = vdev->sriov_stats_pa;
    1400                 :          0 :         a1 = sizeof(struct vnic_sriov_stats);
    1401                 :          0 :         err = vnic_dev_cmd(vdev, CMD_SRIOV_STATS_GET, &a0, &a1, wait);
    1402         [ #  # ]:          0 :         if (!err)
    1403                 :          0 :                 *stats = vdev->sriov_stats;
    1404                 :          0 :         return err;
    1405                 :            : }

Generated by: LCOV version 1.14