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

           Branch data     Line data    Source code
       1                 :            : /* SPDX-License-Identifier: BSD-3-Clause
       2                 :            :  * Copyright(c) 2017 Intel Corporation
       3                 :            :  */
       4                 :            : 
       5                 :            : #include <fcntl.h>
       6                 :            : #include <stdio.h>
       7                 :            : #include <errno.h>
       8                 :            : #include <stdint.h>
       9                 :            : #include <string.h>
      10                 :            : #include <unistd.h>
      11                 :            : #include <stdarg.h>
      12                 :            : #include <inttypes.h>
      13                 :            : #include <rte_byteorder.h>
      14                 :            : #include <rte_common.h>
      15                 :            : #include <rte_os_shim.h>
      16                 :            : 
      17                 :            : #include <rte_debug.h>
      18                 :            : #include <rte_alarm.h>
      19                 :            : #include <rte_atomic.h>
      20                 :            : #include <rte_eal.h>
      21                 :            : #include <rte_ether.h>
      22                 :            : #include <ethdev_driver.h>
      23                 :            : #include <ethdev_pci.h>
      24                 :            : #include <dev_driver.h>
      25                 :            : 
      26                 :            : #include "iavf.h"
      27                 :            : #include "iavf_rxtx.h"
      28                 :            : 
      29                 :            : #define MAX_TRY_TIMES 2000
      30                 :            : #define ASQ_DELAY_MS  1
      31                 :            : 
      32                 :            : #define MAX_EVENT_PENDING 16
      33                 :            : 
      34                 :            : struct iavf_event_element {
      35                 :            :         TAILQ_ENTRY(iavf_event_element) next;
      36                 :            :         struct rte_eth_dev *dev;
      37                 :            :         enum rte_eth_event_type event;
      38                 :            :         void *param;
      39                 :            :         size_t param_alloc_size;
      40                 :            :         uint8_t param_alloc_data[0];
      41                 :            : };
      42                 :            : 
      43                 :            : struct iavf_event_handler {
      44                 :            :         RTE_ATOMIC(uint32_t) ndev;
      45                 :            :         rte_thread_t tid;
      46                 :            :         int fd[2];
      47                 :            :         pthread_mutex_t lock;
      48                 :            :         TAILQ_HEAD(event_list, iavf_event_element) pending;
      49                 :            : };
      50                 :            : 
      51                 :            : static struct iavf_event_handler event_handler = {
      52                 :            :         .fd = {-1, -1},
      53                 :            : };
      54                 :            : 
      55                 :            : #ifndef TAILQ_FOREACH_SAFE
      56                 :            : #define TAILQ_FOREACH_SAFE(var, head, field, tvar) \
      57                 :            :         for ((var) = TAILQ_FIRST((head)); \
      58                 :            :                 (var) && ((tvar) = TAILQ_NEXT((var), field), 1); \
      59                 :            :         (var) = (tvar))
      60                 :            : #endif
      61                 :            : 
      62                 :            : static uint32_t
      63                 :          0 : iavf_dev_event_handle(void *param __rte_unused)
      64                 :            : {
      65                 :            :         struct iavf_event_handler *handler = &event_handler;
      66                 :            :         TAILQ_HEAD(event_list, iavf_event_element) pending;
      67                 :            : 
      68                 :          0 :         while (true) {
      69                 :            :                 char unused[MAX_EVENT_PENDING];
      70                 :          0 :                 ssize_t nr = read(handler->fd[0], &unused, sizeof(unused));
      71         [ #  # ]:          0 :                 if (nr <= 0)
      72                 :            :                         break;
      73                 :            : 
      74                 :          0 :                 TAILQ_INIT(&pending);
      75                 :          0 :                 pthread_mutex_lock(&handler->lock);
      76         [ #  # ]:          0 :                 TAILQ_CONCAT(&pending, &handler->pending, next);
      77                 :          0 :                 pthread_mutex_unlock(&handler->lock);
      78                 :            : 
      79                 :            :                 struct iavf_event_element *pos, *save_next;
      80         [ #  # ]:          0 :                 TAILQ_FOREACH_SAFE(pos, &pending, next, save_next) {
      81         [ #  # ]:          0 :                         TAILQ_REMOVE(&pending, pos, next);
      82                 :            : 
      83                 :          0 :                         struct iavf_adapter *adapter = pos->dev->data->dev_private;
      84         [ #  # ]:          0 :                         if (pos->event == RTE_ETH_EVENT_INTR_RESET &&
      85         [ #  # ]:          0 :                             adapter->devargs.auto_reset) {
      86                 :          0 :                                 iavf_handle_hw_reset(pos->dev);
      87                 :          0 :                                 rte_free(pos);
      88                 :          0 :                                 continue;
      89                 :            :                         }
      90                 :            : 
      91                 :          0 :                         rte_eth_dev_callback_process(pos->dev, pos->event, pos->param);
      92                 :          0 :                         rte_free(pos);
      93                 :            :                 }
      94                 :            :         }
      95                 :            : 
      96                 :          0 :         return 0;
      97                 :            : }
      98                 :            : 
      99                 :            : void
     100                 :          0 : iavf_dev_event_post(struct rte_eth_dev *dev,
     101                 :            :                 enum rte_eth_event_type event,
     102                 :            :                 void *param, size_t param_alloc_size)
     103                 :            : {
     104                 :            :         struct iavf_event_handler *handler = &event_handler;
     105                 :            :         char notify_byte;
     106                 :          0 :         struct iavf_event_element *elem = rte_malloc(NULL, sizeof(*elem) + param_alloc_size, 0);
     107         [ #  # ]:          0 :         if (!elem)
     108                 :          0 :                 return;
     109                 :            : 
     110                 :          0 :         elem->dev = dev;
     111                 :          0 :         elem->event = event;
     112                 :          0 :         elem->param = param;
     113                 :          0 :         elem->param_alloc_size = param_alloc_size;
     114         [ #  # ]:          0 :         if (param && param_alloc_size) {
     115         [ #  # ]:          0 :                 rte_memcpy(elem->param_alloc_data, param, param_alloc_size);
     116                 :          0 :                 elem->param = elem->param_alloc_data;
     117                 :            :         }
     118                 :            : 
     119                 :          0 :         pthread_mutex_lock(&handler->lock);
     120                 :          0 :         TAILQ_INSERT_TAIL(&handler->pending, elem, next);
     121                 :          0 :         pthread_mutex_unlock(&handler->lock);
     122                 :            : 
     123                 :          0 :         ssize_t nw = write(handler->fd[1], &notify_byte, 1);
     124                 :            :         RTE_SET_USED(nw);
     125                 :            : }
     126                 :            : 
     127                 :            : int
     128                 :          0 : iavf_dev_event_handler_init(void)
     129                 :            : {
     130                 :            :         struct iavf_event_handler *handler = &event_handler;
     131                 :            : 
     132         [ #  # ]:          0 :         if (rte_atomic_fetch_add_explicit(&handler->ndev, 1, rte_memory_order_relaxed) + 1 != 1)
     133                 :            :                 return 0;
     134                 :            : #if defined(RTE_EXEC_ENV_IS_WINDOWS) && RTE_EXEC_ENV_IS_WINDOWS != 0
     135                 :            :         int err = _pipe(handler->fd, MAX_EVENT_PENDING, O_BINARY);
     136                 :            : #else
     137                 :          0 :         int err = pipe(handler->fd);
     138                 :            : #endif
     139         [ #  # ]:          0 :         if (err != 0) {
     140                 :          0 :                 rte_atomic_fetch_sub_explicit(&handler->ndev, 1, rte_memory_order_relaxed);
     141                 :          0 :                 return -1;
     142                 :            :         }
     143                 :            : 
     144                 :          0 :         TAILQ_INIT(&handler->pending);
     145                 :          0 :         pthread_mutex_init(&handler->lock, NULL);
     146                 :            : 
     147         [ #  # ]:          0 :         if (rte_thread_create_internal_control(&handler->tid, "iavf-event",
     148                 :            :                                 iavf_dev_event_handle, NULL)) {
     149                 :          0 :                 rte_atomic_fetch_sub_explicit(&handler->ndev, 1, rte_memory_order_relaxed);
     150                 :          0 :                 return -1;
     151                 :            :         }
     152                 :            : 
     153                 :            :         return 0;
     154                 :            : }
     155                 :            : 
     156                 :            : void
     157                 :          0 : iavf_dev_event_handler_fini(void)
     158                 :            : {
     159                 :            :         struct iavf_event_handler *handler = &event_handler;
     160                 :            : 
     161         [ #  # ]:          0 :         if (rte_atomic_fetch_sub_explicit(&handler->ndev, 1, rte_memory_order_relaxed) - 1 != 0)
     162                 :            :                 return;
     163                 :            : 
     164                 :          0 :         int unused = pthread_cancel((pthread_t)handler->tid.opaque_id);
     165                 :            :         RTE_SET_USED(unused);
     166                 :          0 :         close(handler->fd[0]);
     167                 :          0 :         close(handler->fd[1]);
     168                 :          0 :         handler->fd[0] = -1;
     169                 :          0 :         handler->fd[1] = -1;
     170                 :            : 
     171                 :          0 :         rte_thread_join(handler->tid, NULL);
     172                 :          0 :         pthread_mutex_destroy(&handler->lock);
     173                 :            : 
     174                 :            :         struct iavf_event_element *pos, *save_next;
     175         [ #  # ]:          0 :         TAILQ_FOREACH_SAFE(pos, &handler->pending, next, save_next) {
     176         [ #  # ]:          0 :                 TAILQ_REMOVE(&handler->pending, pos, next);
     177                 :          0 :                 rte_free(pos);
     178                 :            :         }
     179                 :            : }
     180                 :            : 
     181                 :            : static uint32_t
     182                 :          0 : iavf_convert_link_speed(enum virtchnl_link_speed virt_link_speed)
     183                 :            : {
     184                 :            :         uint32_t speed;
     185                 :            : 
     186   [ #  #  #  #  :          0 :         switch (virt_link_speed) {
             #  #  #  #  
                      # ]
     187                 :            :         case VIRTCHNL_LINK_SPEED_100MB:
     188                 :            :                 speed = 100;
     189                 :            :                 break;
     190                 :          0 :         case VIRTCHNL_LINK_SPEED_1GB:
     191                 :            :                 speed = 1000;
     192                 :          0 :                 break;
     193                 :          0 :         case VIRTCHNL_LINK_SPEED_10GB:
     194                 :            :                 speed = 10000;
     195                 :          0 :                 break;
     196                 :          0 :         case VIRTCHNL_LINK_SPEED_40GB:
     197                 :            :                 speed = 40000;
     198                 :          0 :                 break;
     199                 :          0 :         case VIRTCHNL_LINK_SPEED_20GB:
     200                 :            :                 speed = 20000;
     201                 :          0 :                 break;
     202                 :          0 :         case VIRTCHNL_LINK_SPEED_25GB:
     203                 :            :                 speed = 25000;
     204                 :          0 :                 break;
     205                 :          0 :         case VIRTCHNL_LINK_SPEED_2_5GB:
     206                 :            :                 speed = 2500;
     207                 :          0 :                 break;
     208                 :          0 :         case VIRTCHNL_LINK_SPEED_5GB:
     209                 :            :                 speed = 5000;
     210                 :          0 :                 break;
     211                 :          0 :         default:
     212                 :            :                 speed = 0;
     213                 :          0 :                 break;
     214                 :            :         }
     215                 :            : 
     216                 :          0 :         return speed;
     217                 :            : }
     218                 :            : 
     219                 :            : /* Read data in admin queue to get msg from pf driver */
     220                 :            : static enum iavf_aq_result
     221                 :          0 : iavf_read_msg_from_pf(struct iavf_adapter *adapter, uint16_t buf_len,
     222                 :            :                      uint8_t *buf)
     223                 :            : {
     224                 :          0 :         struct iavf_hw *hw = IAVF_DEV_PRIVATE_TO_HW(adapter);
     225                 :            :         struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(adapter);
     226                 :            :         struct iavf_arq_event_info event;
     227                 :            :         enum iavf_aq_result result = IAVF_MSG_NON;
     228                 :            :         enum virtchnl_ops opcode;
     229                 :            :         int ret;
     230                 :            : 
     231                 :          0 :         event.buf_len = buf_len;
     232                 :          0 :         event.msg_buf = buf;
     233                 :          0 :         ret = iavf_clean_arq_element(hw, &event, NULL);
     234                 :            :         /* Can't read any msg from adminQ */
     235         [ #  # ]:          0 :         if (ret) {
     236                 :          0 :                 PMD_DRV_LOG(DEBUG, "Can't read msg from AQ");
     237         [ #  # ]:          0 :                 if (ret != IAVF_ERR_ADMIN_QUEUE_NO_WORK)
     238                 :            :                         result = IAVF_MSG_ERR;
     239                 :          0 :                 return result;
     240                 :            :         }
     241                 :            : 
     242                 :          0 :         opcode = (enum virtchnl_ops)rte_le_to_cpu_32(event.desc.cookie_high);
     243                 :          0 :         vf->cmd_retval = (enum virtchnl_status_code)rte_le_to_cpu_32(
     244                 :            :                         event.desc.cookie_low);
     245                 :            : 
     246                 :          0 :         PMD_DRV_LOG(DEBUG, "AQ from pf carries opcode %u, retval %d",
     247                 :            :                     opcode, vf->cmd_retval);
     248                 :            : 
     249         [ #  # ]:          0 :         if (opcode == VIRTCHNL_OP_EVENT) {
     250                 :          0 :                 struct virtchnl_pf_event *vpe =
     251                 :            :                         (struct virtchnl_pf_event *)event.msg_buf;
     252                 :            : 
     253                 :            :                 result = IAVF_MSG_SYS;
     254   [ #  #  #  # ]:          0 :                 switch (vpe->event) {
     255                 :          0 :                 case VIRTCHNL_EVENT_LINK_CHANGE:
     256                 :          0 :                         vf->link_up =
     257                 :          0 :                                 vpe->event_data.link_event.link_status;
     258         [ #  # ]:          0 :                         if (vf->vf_res != NULL &&
     259         [ #  # ]:          0 :                             vf->vf_res->vf_cap_flags & VIRTCHNL_VF_CAP_ADV_LINK_SPEED) {
     260                 :          0 :                                 vf->link_speed =
     261                 :          0 :                                     vpe->event_data.link_event_adv.link_speed;
     262                 :            :                         } else {
     263                 :            :                                 enum virtchnl_link_speed speed;
     264                 :          0 :                                 speed = vpe->event_data.link_event.link_speed;
     265                 :          0 :                                 vf->link_speed = iavf_convert_link_speed(speed);
     266                 :            :                         }
     267                 :          0 :                         iavf_dev_link_update(vf->eth_dev, 0);
     268                 :          0 :                         iavf_dev_event_post(vf->eth_dev, RTE_ETH_EVENT_INTR_LSC, NULL, 0);
     269   [ #  #  #  # ]:          0 :                         if (vf->link_up && !vf->vf_reset) {
     270                 :          0 :                                 iavf_dev_watchdog_disable(adapter);
     271                 :            :                         } else {
     272         [ #  # ]:          0 :                                 if (!vf->link_up)
     273                 :          0 :                                         iavf_dev_watchdog_enable(adapter);
     274                 :            :                         }
     275         [ #  # ]:          0 :                         if (adapter->devargs.no_poll_on_link_down) {
     276                 :          0 :                                 iavf_set_no_poll(adapter, true);
     277         [ #  # ]:          0 :                                 if (adapter->no_poll)
     278                 :          0 :                                         PMD_DRV_LOG(DEBUG, "VF no poll turned on");
     279                 :            :                                 else
     280                 :          0 :                                         PMD_DRV_LOG(DEBUG, "VF no poll turned off");
     281                 :            :                         }
     282         [ #  # ]:          0 :                         PMD_DRV_LOG(INFO, "Link status update:%s",
     283                 :            :                                         vf->link_up ? "up" : "down");
     284                 :          0 :                         break;
     285                 :          0 :                 case VIRTCHNL_EVENT_RESET_IMPENDING:
     286                 :          0 :                         vf->vf_reset = true;
     287                 :          0 :                         iavf_set_no_poll(adapter, false);
     288                 :          0 :                         PMD_DRV_LOG(INFO, "VF is resetting");
     289                 :          0 :                         break;
     290                 :          0 :                 case VIRTCHNL_EVENT_PF_DRIVER_CLOSE:
     291                 :          0 :                         vf->dev_closed = true;
     292                 :          0 :                         PMD_DRV_LOG(INFO, "PF driver closed");
     293                 :          0 :                         break;
     294                 :          0 :                 default:
     295                 :          0 :                         PMD_DRV_LOG(ERR, "%s: Unknown event %d from pf",
     296                 :            :                                         __func__, vpe->event);
     297                 :            :                 }
     298                 :            :         }  else {
     299                 :            :                 /* async reply msg on command issued by vf previously */
     300                 :            :                 result = IAVF_MSG_CMD;
     301         [ #  # ]:          0 :                 if (opcode != vf->pend_cmd) {
     302                 :          0 :                         PMD_DRV_LOG(WARNING, "command mismatch, expect %u, get %u",
     303                 :            :                                         vf->pend_cmd, opcode);
     304                 :            :                         result = IAVF_MSG_ERR;
     305                 :            :                 }
     306                 :            :         }
     307                 :            : 
     308                 :            :         return result;
     309                 :            : }
     310                 :            : 
     311                 :            : static int
     312                 :          0 : iavf_execute_vf_cmd(struct iavf_adapter *adapter, struct iavf_cmd_info *args,
     313                 :            :         int async)
     314                 :            : {
     315                 :          0 :         struct iavf_hw *hw = IAVF_DEV_PRIVATE_TO_HW(adapter);
     316                 :          0 :         struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(adapter);
     317                 :            :         enum iavf_aq_result result;
     318                 :            :         enum iavf_status ret;
     319                 :            :         int err = 0;
     320                 :            :         int i = 0;
     321                 :            : 
     322         [ #  # ]:          0 :         if (vf->vf_reset)
     323                 :            :                 return -EIO;
     324                 :            : 
     325                 :            : 
     326         [ #  # ]:          0 :         if (async) {
     327         [ #  # ]:          0 :                 if (_atomic_set_async_response_cmd(vf, args->ops))
     328                 :            :                         return -1;
     329                 :            :         } else {
     330         [ #  # ]:          0 :                 if (_atomic_set_cmd(vf, args->ops))
     331                 :            :                         return -1;
     332                 :            :         }
     333                 :            : 
     334                 :          0 :         ret = iavf_aq_send_msg_to_pf(hw, args->ops, IAVF_SUCCESS,
     335                 :          0 :                                     args->in_args, args->in_args_size, NULL);
     336         [ #  # ]:          0 :         if (ret) {
     337                 :          0 :                 PMD_DRV_LOG(ERR, "fail to send cmd %d", args->ops);
     338                 :            :                 _clear_cmd(vf);
     339                 :          0 :                 return err;
     340                 :            :         }
     341                 :            : 
     342      [ #  #  # ]:          0 :         switch (args->ops) {
     343                 :            :         case VIRTCHNL_OP_RESET_VF:
     344                 :            :         case VIRTCHNL_OP_REQUEST_QUEUES:
     345                 :            :                 /*no need to wait for response */
     346                 :            :                 _clear_cmd(vf);
     347                 :            :                 break;
     348                 :          0 :         case VIRTCHNL_OP_VERSION:
     349                 :            :         case VIRTCHNL_OP_GET_VF_RESOURCES:
     350                 :            :         case VIRTCHNL_OP_GET_SUPPORTED_RXDIDS:
     351                 :            :         case VIRTCHNL_OP_GET_OFFLOAD_VLAN_V2_CAPS:
     352                 :            :                 /* for init virtchnl ops, need to poll the response */
     353                 :            :                 do {
     354                 :          0 :                         result = iavf_read_msg_from_pf(adapter, args->out_size,
     355                 :            :                                                    args->out_buffer);
     356         [ #  # ]:          0 :                         if (result == IAVF_MSG_CMD)
     357                 :            :                                 break;
     358                 :          0 :                         iavf_msec_delay(ASQ_DELAY_MS);
     359         [ #  # ]:          0 :                 } while (i++ < MAX_TRY_TIMES);
     360         [ #  # ]:          0 :                 if (i >= MAX_TRY_TIMES ||
     361         [ #  # ]:          0 :                     vf->cmd_retval != VIRTCHNL_STATUS_SUCCESS) {
     362                 :            :                         err = -1;
     363                 :          0 :                         PMD_DRV_LOG(ERR, "No response or return failure (%d)"
     364                 :            :                                     " for cmd %d", vf->cmd_retval, args->ops);
     365                 :            :                 }
     366                 :            :                 _clear_cmd(vf);
     367                 :            :                 break;
     368                 :          0 :         default:
     369         [ #  # ]:          0 :                 if (rte_thread_is_intr()) {
     370                 :            :                         /* For virtchnl ops were executed in eal_intr_thread,
     371                 :            :                          * need to poll the response.
     372                 :            :                          */
     373                 :            :                         do {
     374                 :          0 :                                 result = iavf_read_msg_from_pf(adapter, args->out_size,
     375                 :            :                                                         args->out_buffer);
     376         [ #  # ]:          0 :                                 if (result == IAVF_MSG_CMD)
     377                 :            :                                         break;
     378                 :          0 :                                 iavf_msec_delay(ASQ_DELAY_MS);
     379         [ #  # ]:          0 :                         } while (i++ < MAX_TRY_TIMES);
     380         [ #  # ]:          0 :                         if (i >= MAX_TRY_TIMES ||
     381         [ #  # ]:          0 :                                 vf->cmd_retval != VIRTCHNL_STATUS_SUCCESS) {
     382                 :            :                                 err = -1;
     383                 :          0 :                                 PMD_DRV_LOG(ERR, "No response or return failure (%d)"
     384                 :            :                                                 " for cmd %d", vf->cmd_retval, args->ops);
     385                 :            :                         }
     386                 :            :                         _clear_cmd(vf);
     387                 :            :                 } else {
     388                 :            :                         /* For other virtchnl ops in running time,
     389                 :            :                          * wait for the cmd done flag.
     390                 :            :                          */
     391                 :            :                         do {
     392         [ #  # ]:          0 :                                 if (vf->pend_cmd == VIRTCHNL_OP_UNKNOWN)
     393                 :            :                                         break;
     394                 :          0 :                                 iavf_msec_delay(ASQ_DELAY_MS);
     395                 :            :                                 /* If don't read msg or read sys event, continue */
     396         [ #  # ]:          0 :                         } while (i++ < MAX_TRY_TIMES);
     397                 :            : 
     398         [ #  # ]:          0 :                         if (i >= MAX_TRY_TIMES) {
     399                 :          0 :                                 PMD_DRV_LOG(ERR, "No response for cmd %d", args->ops);
     400                 :            :                                 _clear_cmd(vf);
     401                 :            :                                 err = -EIO;
     402         [ #  # ]:          0 :                         } else if (vf->cmd_retval ==
     403                 :            :                                 VIRTCHNL_STATUS_ERR_NOT_SUPPORTED) {
     404                 :          0 :                                 PMD_DRV_LOG(ERR, "Cmd %d not supported", args->ops);
     405                 :            :                                 err = -ENOTSUP;
     406         [ #  # ]:          0 :                         } else if (vf->cmd_retval != VIRTCHNL_STATUS_SUCCESS) {
     407                 :          0 :                                 PMD_DRV_LOG(ERR, "Return failure %d for cmd %d",
     408                 :            :                                                 vf->cmd_retval, args->ops);
     409                 :            :                                 err = -EINVAL;
     410                 :            :                         }
     411                 :            :                 }
     412                 :            :                 break;
     413                 :            :         }
     414                 :            : 
     415                 :            :         return err;
     416                 :            : }
     417                 :            : 
     418                 :            : static int
     419                 :          0 : iavf_execute_vf_cmd_safe(struct iavf_adapter *adapter,
     420                 :            :         struct iavf_cmd_info *args, int async)
     421                 :            : {
     422                 :            :         struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(adapter);
     423                 :            :         int ret;
     424                 :          0 :         int is_intr_thread = rte_thread_is_intr();
     425                 :            : 
     426         [ #  # ]:          0 :         if (is_intr_thread) {
     427         [ #  # ]:          0 :                 if (!rte_spinlock_trylock(&vf->aq_lock))
     428                 :            :                         return -EIO;
     429                 :            :         } else {
     430                 :          0 :                 rte_spinlock_lock(&vf->aq_lock);
     431                 :            :         }
     432                 :          0 :         ret = iavf_execute_vf_cmd(adapter, args, async);
     433                 :          0 :         rte_spinlock_unlock(&vf->aq_lock);
     434                 :            : 
     435                 :          0 :         return ret;
     436                 :            : }
     437                 :            : 
     438                 :            : static void
     439                 :          0 : iavf_handle_pf_event_msg(struct rte_eth_dev *dev, uint8_t *msg,
     440                 :            :                         uint16_t msglen)
     441                 :            : {
     442                 :          0 :         struct iavf_adapter *adapter =
     443                 :          0 :                 IAVF_DEV_PRIVATE_TO_ADAPTER(dev->data->dev_private);
     444                 :            :         struct iavf_info *vf = &adapter->vf;
     445                 :            :         struct virtchnl_pf_event *pf_msg =
     446                 :            :                         (struct virtchnl_pf_event *)msg;
     447                 :            : 
     448         [ #  # ]:          0 :         if (adapter->closed) {
     449                 :          0 :                 PMD_DRV_LOG(DEBUG, "Port closed");
     450                 :          0 :                 return;
     451                 :            :         }
     452                 :            : 
     453         [ #  # ]:          0 :         if (msglen < sizeof(struct virtchnl_pf_event)) {
     454                 :          0 :                 PMD_DRV_LOG(DEBUG, "Error event");
     455                 :          0 :                 return;
     456                 :            :         }
     457   [ #  #  #  # ]:          0 :         switch (pf_msg->event) {
     458                 :          0 :         case VIRTCHNL_EVENT_RESET_IMPENDING:
     459                 :          0 :                 PMD_DRV_LOG(DEBUG, "VIRTCHNL_EVENT_RESET_IMPENDING event");
     460                 :          0 :                 vf->link_up = false;
     461         [ #  # ]:          0 :                 if (!vf->vf_reset) {
     462                 :          0 :                         vf->vf_reset = true;
     463                 :          0 :                         iavf_set_no_poll(adapter, false);
     464                 :          0 :                         iavf_dev_event_post(dev, RTE_ETH_EVENT_INTR_RESET,
     465                 :            :                                 NULL, 0);
     466                 :            :                 }
     467                 :            :                 break;
     468                 :          0 :         case VIRTCHNL_EVENT_LINK_CHANGE:
     469                 :          0 :                 PMD_DRV_LOG(DEBUG, "VIRTCHNL_EVENT_LINK_CHANGE event");
     470                 :          0 :                 vf->link_up = pf_msg->event_data.link_event.link_status;
     471         [ #  # ]:          0 :                 if (vf->vf_res->vf_cap_flags & VIRTCHNL_VF_CAP_ADV_LINK_SPEED) {
     472                 :          0 :                         vf->link_speed =
     473                 :          0 :                                 pf_msg->event_data.link_event_adv.link_speed;
     474                 :            :                 } else {
     475                 :            :                         enum virtchnl_link_speed speed;
     476                 :          0 :                         speed = pf_msg->event_data.link_event.link_speed;
     477                 :          0 :                         vf->link_speed = iavf_convert_link_speed(speed);
     478                 :            :                 }
     479                 :          0 :                 iavf_dev_link_update(dev, 0);
     480   [ #  #  #  # ]:          0 :                 if (vf->link_up && !vf->vf_reset) {
     481                 :          0 :                         iavf_dev_watchdog_disable(adapter);
     482                 :            :                 } else {
     483         [ #  # ]:          0 :                         if (!vf->link_up)
     484                 :          0 :                                 iavf_dev_watchdog_enable(adapter);
     485                 :            :                 }
     486         [ #  # ]:          0 :                 if (adapter->devargs.no_poll_on_link_down) {
     487                 :          0 :                         iavf_set_no_poll(adapter, true);
     488         [ #  # ]:          0 :                         if (adapter->no_poll)
     489                 :          0 :                                 PMD_DRV_LOG(DEBUG, "VF no poll turned on");
     490                 :            :                         else
     491                 :          0 :                                 PMD_DRV_LOG(DEBUG, "VF no poll turned off");
     492                 :            :                 }
     493                 :          0 :                 iavf_dev_event_post(dev, RTE_ETH_EVENT_INTR_LSC, NULL, 0);
     494                 :          0 :                 break;
     495                 :          0 :         case VIRTCHNL_EVENT_PF_DRIVER_CLOSE:
     496                 :          0 :                 PMD_DRV_LOG(DEBUG, "VIRTCHNL_EVENT_PF_DRIVER_CLOSE event");
     497                 :          0 :                 break;
     498                 :          0 :         default:
     499                 :          0 :                 PMD_DRV_LOG(ERR, " unknown event received %u", pf_msg->event);
     500                 :          0 :                 break;
     501                 :            :         }
     502                 :            : }
     503                 :            : 
     504                 :            : void
     505                 :          0 : iavf_handle_virtchnl_msg(struct rte_eth_dev *dev)
     506                 :            : {
     507                 :          0 :         struct iavf_hw *hw = IAVF_DEV_PRIVATE_TO_HW(dev->data->dev_private);
     508                 :            :         struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(dev->data->dev_private);
     509                 :            :         struct iavf_arq_event_info info;
     510                 :            :         uint16_t pending, aq_opc;
     511                 :            :         enum virtchnl_ops msg_opc;
     512                 :            :         enum iavf_status msg_ret;
     513                 :            :         int ret;
     514                 :            : 
     515                 :          0 :         info.buf_len = IAVF_AQ_BUF_SZ;
     516         [ #  # ]:          0 :         if (!vf->aq_resp) {
     517                 :          0 :                 PMD_DRV_LOG(ERR, "Buffer for adminq resp should not be NULL");
     518                 :          0 :                 return;
     519                 :            :         }
     520                 :          0 :         info.msg_buf = vf->aq_resp;
     521                 :            : 
     522                 :          0 :         pending = 1;
     523         [ #  # ]:          0 :         while (pending) {
     524                 :          0 :                 ret = iavf_clean_arq_element(hw, &info, &pending);
     525                 :            : 
     526         [ #  # ]:          0 :                 if (ret != IAVF_SUCCESS) {
     527                 :          0 :                         PMD_DRV_LOG(INFO, "Failed to read msg from AdminQ,"
     528                 :            :                                     "ret: %d", ret);
     529                 :          0 :                         break;
     530                 :            :                 }
     531                 :          0 :                 aq_opc = rte_le_to_cpu_16(info.desc.opcode);
     532                 :            :                 /* For the message sent from pf to vf, opcode is stored in
     533                 :            :                  * cookie_high of struct iavf_aq_desc, while return error code
     534                 :            :                  * are stored in cookie_low, Which is done by PF driver.
     535                 :            :                  */
     536                 :          0 :                 msg_opc = (enum virtchnl_ops)rte_le_to_cpu_32(
     537                 :            :                                                   info.desc.cookie_high);
     538                 :          0 :                 msg_ret = (enum iavf_status)rte_le_to_cpu_32(
     539                 :            :                                                   info.desc.cookie_low);
     540         [ #  # ]:          0 :                 switch (aq_opc) {
     541                 :          0 :                 case iavf_aqc_opc_send_msg_to_vf:
     542         [ #  # ]:          0 :                         if (msg_opc == VIRTCHNL_OP_EVENT) {
     543                 :          0 :                                 iavf_handle_pf_event_msg(dev, info.msg_buf,
     544                 :          0 :                                                 info.msg_len);
     545                 :            :                         } else {
     546                 :            :                                 /* check for unsolicited messages i.e. events */
     547         [ #  # ]:          0 :                                 if (info.msg_len > 0) {
     548                 :            :                                         switch (msg_opc) {
     549                 :          0 :                                         case VIRTCHNL_OP_INLINE_IPSEC_CRYPTO: {
     550                 :          0 :                                                 struct inline_ipsec_msg *imsg =
     551                 :            :                                                         (struct inline_ipsec_msg *)info.msg_buf;
     552         [ #  # ]:          0 :                                                 if (imsg->ipsec_opcode
     553                 :          0 :                                                                 == INLINE_IPSEC_OP_EVENT) {
     554                 :            :                                                         struct rte_eth_event_ipsec_desc desc;
     555                 :            :                                                         struct virtchnl_ipsec_event *ev =
     556                 :            :                                                                         imsg->ipsec_data.event;
     557                 :          0 :                                                         desc.subtype =
     558                 :            :                                                                         RTE_ETH_EVENT_IPSEC_UNKNOWN;
     559                 :          0 :                                                         desc.metadata =
     560                 :          0 :                                                                         ev->ipsec_event_data;
     561                 :          0 :                                                         iavf_dev_event_post(dev,
     562                 :            :                                                                 RTE_ETH_EVENT_IPSEC,
     563                 :            :                                                                 &desc, sizeof(desc));
     564                 :            :                                                         continue;
     565                 :            :                                         }
     566                 :            :                                 }
     567                 :            :                                                 break;
     568                 :            :                                         default:
     569                 :            :                                                 break;
     570                 :            :                                         }
     571                 :            : 
     572                 :            :                                 }
     573                 :            : 
     574                 :            :                                 /* read message and it's expected one */
     575         [ #  # ]:          0 :                                 if (msg_opc == vf->pend_cmd) {
     576                 :            :                                         uint32_t cmd_count =
     577                 :          0 :                                         rte_atomic_fetch_sub_explicit(&vf->pend_cmd_count,
     578                 :            :                                                         1, rte_memory_order_relaxed) - 1;
     579         [ #  # ]:          0 :                                         if (cmd_count == 0)
     580                 :            :                                                 _notify_cmd(vf, msg_ret);
     581                 :            :                                 } else {
     582                 :          0 :                                         PMD_DRV_LOG(ERR,
     583                 :            :                                         "command mismatch, expect %u, get %u",
     584                 :            :                                                 vf->pend_cmd, msg_opc);
     585                 :            :                                 }
     586                 :          0 :                                 PMD_DRV_LOG(DEBUG,
     587                 :            :                                 "adminq response is received, opcode = %d",
     588                 :            :                                                 msg_opc);
     589                 :            :                         }
     590                 :            :                         break;
     591                 :          0 :                 default:
     592                 :          0 :                         PMD_DRV_LOG(DEBUG, "Request %u is not supported yet",
     593                 :            :                                     aq_opc);
     594                 :          0 :                         break;
     595                 :            :                 }
     596                 :            :         }
     597                 :            : }
     598                 :            : 
     599                 :            : int
     600                 :          0 : iavf_enable_vlan_strip(struct iavf_adapter *adapter)
     601                 :            : {
     602                 :            :         struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(adapter);
     603                 :            :         struct iavf_cmd_info args;
     604                 :            :         int ret;
     605                 :            : 
     606                 :            :         memset(&args, 0, sizeof(args));
     607                 :          0 :         args.ops = VIRTCHNL_OP_ENABLE_VLAN_STRIPPING;
     608                 :            :         args.in_args = NULL;
     609                 :            :         args.in_args_size = 0;
     610                 :          0 :         args.out_buffer = vf->aq_resp;
     611                 :          0 :         args.out_size = IAVF_AQ_BUF_SZ;
     612                 :          0 :         ret = iavf_execute_vf_cmd_safe(adapter, &args, 0);
     613         [ #  # ]:          0 :         if (ret)
     614                 :          0 :                 PMD_DRV_LOG(ERR, "Failed to execute command of"
     615                 :            :                             " OP_ENABLE_VLAN_STRIPPING");
     616                 :            : 
     617                 :          0 :         return ret;
     618                 :            : }
     619                 :            : 
     620                 :            : int
     621                 :          0 : iavf_disable_vlan_strip(struct iavf_adapter *adapter)
     622                 :            : {
     623                 :            :         struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(adapter);
     624                 :            :         struct iavf_cmd_info args;
     625                 :            :         int ret;
     626                 :            : 
     627                 :            :         memset(&args, 0, sizeof(args));
     628                 :          0 :         args.ops = VIRTCHNL_OP_DISABLE_VLAN_STRIPPING;
     629                 :            :         args.in_args = NULL;
     630                 :            :         args.in_args_size = 0;
     631                 :          0 :         args.out_buffer = vf->aq_resp;
     632                 :          0 :         args.out_size = IAVF_AQ_BUF_SZ;
     633                 :          0 :         ret = iavf_execute_vf_cmd_safe(adapter, &args, 0);
     634         [ #  # ]:          0 :         if (ret)
     635                 :          0 :                 PMD_DRV_LOG(ERR, "Failed to execute command of"
     636                 :            :                             " OP_DISABLE_VLAN_STRIPPING");
     637                 :            : 
     638                 :          0 :         return ret;
     639                 :            : }
     640                 :            : 
     641                 :            : #define VIRTCHNL_VERSION_MAJOR_START 1
     642                 :            : #define VIRTCHNL_VERSION_MINOR_START 1
     643                 :            : 
     644                 :            : /* Check API version with sync wait until version read from admin queue */
     645                 :            : int
     646                 :          0 : iavf_check_api_version(struct iavf_adapter *adapter)
     647                 :            : {
     648                 :            :         struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(adapter);
     649                 :            :         struct virtchnl_version_info version, *pver;
     650                 :            :         struct iavf_cmd_info args;
     651                 :            :         int err;
     652                 :            : 
     653                 :          0 :         version.major = VIRTCHNL_VERSION_MAJOR;
     654                 :          0 :         version.minor = VIRTCHNL_VERSION_MINOR;
     655                 :            : 
     656                 :          0 :         args.ops = VIRTCHNL_OP_VERSION;
     657                 :          0 :         args.in_args = (uint8_t *)&version;
     658                 :          0 :         args.in_args_size = sizeof(version);
     659                 :          0 :         args.out_buffer = vf->aq_resp;
     660                 :          0 :         args.out_size = IAVF_AQ_BUF_SZ;
     661                 :            : 
     662                 :          0 :         err = iavf_execute_vf_cmd_safe(adapter, &args, 0);
     663         [ #  # ]:          0 :         if (err) {
     664                 :          0 :                 PMD_INIT_LOG(ERR, "Fail to execute command of OP_VERSION");
     665                 :          0 :                 return err;
     666                 :            :         }
     667                 :            : 
     668                 :          0 :         pver = (struct virtchnl_version_info *)args.out_buffer;
     669                 :          0 :         vf->virtchnl_version = *pver;
     670                 :            : 
     671         [ #  # ]:          0 :         if (vf->virtchnl_version.major < VIRTCHNL_VERSION_MAJOR_START ||
     672         [ #  # ]:          0 :             (vf->virtchnl_version.major == VIRTCHNL_VERSION_MAJOR_START &&
     673                 :            :              vf->virtchnl_version.minor < VIRTCHNL_VERSION_MINOR_START)) {
     674                 :          0 :                 PMD_INIT_LOG(ERR, "VIRTCHNL API version should not be lower"
     675                 :            :                              " than (%u.%u) to support Adaptive VF",
     676                 :            :                              VIRTCHNL_VERSION_MAJOR_START,
     677                 :            :                              VIRTCHNL_VERSION_MAJOR_START);
     678                 :          0 :                 return -1;
     679         [ #  # ]:          0 :         } else if (vf->virtchnl_version.major > VIRTCHNL_VERSION_MAJOR ||
     680                 :          0 :                    (vf->virtchnl_version.major == VIRTCHNL_VERSION_MAJOR &&
     681         [ #  # ]:          0 :                     vf->virtchnl_version.minor > VIRTCHNL_VERSION_MINOR)) {
     682                 :          0 :                 PMD_INIT_LOG(ERR, "PF/VF API version mismatch:(%u.%u)-(%u.%u)",
     683                 :            :                              vf->virtchnl_version.major,
     684                 :            :                              vf->virtchnl_version.minor,
     685                 :            :                              VIRTCHNL_VERSION_MAJOR,
     686                 :            :                              VIRTCHNL_VERSION_MINOR);
     687                 :          0 :                 return -1;
     688                 :            :         }
     689                 :            : 
     690                 :          0 :         PMD_DRV_LOG(DEBUG, "Peer is supported PF host");
     691                 :          0 :         return 0;
     692                 :            : }
     693                 :            : 
     694                 :            : int
     695                 :          0 : iavf_get_vf_resource(struct iavf_adapter *adapter)
     696                 :            : {
     697                 :          0 :         struct iavf_hw *hw = IAVF_DEV_PRIVATE_TO_HW(adapter);
     698                 :            :         struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(adapter);
     699                 :            :         struct iavf_cmd_info args;
     700                 :            :         uint32_t caps, len;
     701                 :            :         int err, i;
     702                 :            : 
     703                 :          0 :         args.ops = VIRTCHNL_OP_GET_VF_RESOURCES;
     704                 :          0 :         args.out_buffer = vf->aq_resp;
     705                 :          0 :         args.out_size = IAVF_AQ_BUF_SZ;
     706                 :            : 
     707                 :          0 :         caps = IAVF_BASIC_OFFLOAD_CAPS | VIRTCHNL_VF_CAP_ADV_LINK_SPEED |
     708                 :            :                 VIRTCHNL_VF_OFFLOAD_RX_FLEX_DESC |
     709                 :            :                 VIRTCHNL_VF_OFFLOAD_FDIR_PF |
     710                 :            :                 VIRTCHNL_VF_OFFLOAD_ADV_RSS_PF |
     711                 :            :                 VIRTCHNL_VF_OFFLOAD_FSUB_PF |
     712                 :            :                 VIRTCHNL_VF_OFFLOAD_REQ_QUEUES |
     713                 :            :                 VIRTCHNL_VF_OFFLOAD_USO |
     714                 :            :                 VIRTCHNL_VF_OFFLOAD_CRC |
     715                 :            :                 VIRTCHNL_VF_OFFLOAD_VLAN_V2 |
     716                 :            :                 VIRTCHNL_VF_LARGE_NUM_QPAIRS |
     717                 :            :                 VIRTCHNL_VF_OFFLOAD_QOS |
     718                 :            :                 VIRTCHNL_VF_OFFLOAD_INLINE_IPSEC_CRYPTO |
     719                 :            :                 VIRTCHNL_VF_CAP_PTP;
     720                 :            : 
     721                 :          0 :         args.in_args = (uint8_t *)&caps;
     722                 :          0 :         args.in_args_size = sizeof(caps);
     723                 :            : 
     724                 :          0 :         err = iavf_execute_vf_cmd_safe(adapter, &args, 0);
     725                 :            : 
     726         [ #  # ]:          0 :         if (err) {
     727                 :          0 :                 PMD_DRV_LOG(ERR,
     728                 :            :                             "Failed to execute command of OP_GET_VF_RESOURCE");
     729                 :          0 :                 return -1;
     730                 :            :         }
     731                 :            : 
     732                 :            :         len =  sizeof(struct virtchnl_vf_resource) +
     733                 :            :                       IAVF_MAX_VF_VSI * sizeof(struct virtchnl_vsi_resource);
     734                 :            : 
     735                 :          0 :         rte_memcpy(vf->vf_res, args.out_buffer,
     736         [ #  # ]:          0 :                    RTE_MIN(args.out_size, len));
     737                 :            :         /* parse  VF config message back from PF*/
     738                 :          0 :         iavf_vf_parse_hw_config(hw, vf->vf_res);
     739         [ #  # ]:          0 :         for (i = 0; i < vf->vf_res->num_vsis; i++) {
     740         [ #  # ]:          0 :                 if (vf->vf_res->vsi_res[i].vsi_type == VIRTCHNL_VSI_SRIOV)
     741                 :          0 :                         vf->vsi_res = &vf->vf_res->vsi_res[i];
     742                 :            :         }
     743                 :            : 
     744         [ #  # ]:          0 :         if (!vf->vsi_res) {
     745                 :          0 :                 PMD_INIT_LOG(ERR, "no LAN VSI found");
     746                 :          0 :                 return -1;
     747                 :            :         }
     748                 :            : 
     749                 :          0 :         vf->vsi.vsi_id = vf->vsi_res->vsi_id;
     750                 :          0 :         vf->vsi.nb_qps = vf->vsi_res->num_queue_pairs;
     751                 :          0 :         vf->vsi.adapter = adapter;
     752                 :            : 
     753                 :          0 :         return 0;
     754                 :            : }
     755                 :            : 
     756                 :            : int
     757                 :          0 : iavf_get_supported_rxdid(struct iavf_adapter *adapter)
     758                 :            : {
     759                 :            :         struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(adapter);
     760                 :            :         struct iavf_cmd_info args;
     761                 :            :         int ret;
     762                 :            : 
     763                 :          0 :         args.ops = VIRTCHNL_OP_GET_SUPPORTED_RXDIDS;
     764                 :          0 :         args.in_args = NULL;
     765                 :          0 :         args.in_args_size = 0;
     766                 :          0 :         args.out_buffer = vf->aq_resp;
     767                 :          0 :         args.out_size = IAVF_AQ_BUF_SZ;
     768                 :            : 
     769                 :          0 :         ret = iavf_execute_vf_cmd_safe(adapter, &args, 0);
     770         [ #  # ]:          0 :         if (ret) {
     771                 :          0 :                 PMD_DRV_LOG(ERR,
     772                 :            :                             "Failed to execute command of OP_GET_SUPPORTED_RXDIDS");
     773                 :          0 :                 return ret;
     774                 :            :         }
     775                 :            : 
     776                 :          0 :         vf->supported_rxdid =
     777                 :          0 :                 ((struct virtchnl_supported_rxdids *)args.out_buffer)->supported_rxdids;
     778                 :            : 
     779                 :          0 :         return 0;
     780                 :            : }
     781                 :            : 
     782                 :            : int
     783                 :          0 : iavf_config_vlan_strip_v2(struct iavf_adapter *adapter, bool enable)
     784                 :            : {
     785                 :            :         struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(adapter);
     786                 :            :         struct virtchnl_vlan_supported_caps *stripping_caps;
     787                 :            :         struct virtchnl_vlan_setting vlan_strip;
     788                 :            :         struct iavf_cmd_info args;
     789                 :            :         uint32_t *ethertype;
     790                 :            :         int ret;
     791                 :            : 
     792                 :            :         stripping_caps = &vf->vlan_v2_caps.offloads.stripping_support;
     793                 :            : 
     794   [ #  #  #  # ]:          0 :         if ((stripping_caps->outer & VIRTCHNL_VLAN_ETHERTYPE_8100) &&
     795                 :            :             (stripping_caps->outer & VIRTCHNL_VLAN_TOGGLE))
     796                 :            :                 ethertype = &vlan_strip.outer_ethertype_setting;
     797   [ #  #  #  # ]:          0 :         else if ((stripping_caps->inner & VIRTCHNL_VLAN_ETHERTYPE_8100) &&
     798                 :            :                  (stripping_caps->inner & VIRTCHNL_VLAN_TOGGLE))
     799                 :            :                 ethertype = &vlan_strip.inner_ethertype_setting;
     800                 :            :         else
     801                 :            :                 return -ENOTSUP;
     802                 :            : 
     803                 :            :         memset(&vlan_strip, 0, sizeof(vlan_strip));
     804                 :          0 :         vlan_strip.vport_id = vf->vsi_res->vsi_id;
     805                 :          0 :         *ethertype = VIRTCHNL_VLAN_ETHERTYPE_8100;
     806                 :            : 
     807         [ #  # ]:          0 :         args.ops = enable ? VIRTCHNL_OP_ENABLE_VLAN_STRIPPING_V2 :
     808                 :            :                             VIRTCHNL_OP_DISABLE_VLAN_STRIPPING_V2;
     809                 :          0 :         args.in_args = (uint8_t *)&vlan_strip;
     810                 :          0 :         args.in_args_size = sizeof(vlan_strip);
     811                 :          0 :         args.out_buffer = vf->aq_resp;
     812                 :          0 :         args.out_size = IAVF_AQ_BUF_SZ;
     813                 :          0 :         ret = iavf_execute_vf_cmd_safe(adapter, &args, 0);
     814         [ #  # ]:          0 :         if (ret)
     815         [ #  # ]:          0 :                 PMD_DRV_LOG(ERR, "fail to execute command %s",
     816                 :            :                             enable ? "VIRTCHNL_OP_ENABLE_VLAN_STRIPPING_V2" :
     817                 :            :                                      "VIRTCHNL_OP_DISABLE_VLAN_STRIPPING_V2");
     818                 :            : 
     819                 :            :         return ret;
     820                 :            : }
     821                 :            : 
     822                 :            : int
     823                 :          0 : iavf_config_vlan_insert_v2(struct iavf_adapter *adapter, bool enable)
     824                 :            : {
     825                 :            :         struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(adapter);
     826                 :            :         struct virtchnl_vlan_supported_caps *insertion_caps;
     827                 :            :         struct virtchnl_vlan_setting vlan_insert;
     828                 :            :         struct iavf_cmd_info args;
     829                 :            :         uint32_t *ethertype;
     830                 :            :         int ret;
     831                 :            : 
     832                 :            :         insertion_caps = &vf->vlan_v2_caps.offloads.insertion_support;
     833                 :            : 
     834   [ #  #  #  # ]:          0 :         if ((insertion_caps->outer & VIRTCHNL_VLAN_ETHERTYPE_8100) &&
     835                 :            :             (insertion_caps->outer & VIRTCHNL_VLAN_TOGGLE))
     836                 :            :                 ethertype = &vlan_insert.outer_ethertype_setting;
     837   [ #  #  #  # ]:          0 :         else if ((insertion_caps->inner & VIRTCHNL_VLAN_ETHERTYPE_8100) &&
     838                 :            :                  (insertion_caps->inner & VIRTCHNL_VLAN_TOGGLE))
     839                 :            :                 ethertype = &vlan_insert.inner_ethertype_setting;
     840                 :            :         else
     841                 :            :                 return -ENOTSUP;
     842                 :            : 
     843                 :            :         memset(&vlan_insert, 0, sizeof(vlan_insert));
     844                 :          0 :         vlan_insert.vport_id = vf->vsi_res->vsi_id;
     845                 :          0 :         *ethertype = VIRTCHNL_VLAN_ETHERTYPE_8100;
     846                 :            : 
     847         [ #  # ]:          0 :         args.ops = enable ? VIRTCHNL_OP_ENABLE_VLAN_INSERTION_V2 :
     848                 :            :                             VIRTCHNL_OP_DISABLE_VLAN_INSERTION_V2;
     849                 :          0 :         args.in_args = (uint8_t *)&vlan_insert;
     850                 :          0 :         args.in_args_size = sizeof(vlan_insert);
     851                 :          0 :         args.out_buffer = vf->aq_resp;
     852                 :          0 :         args.out_size = IAVF_AQ_BUF_SZ;
     853                 :          0 :         ret = iavf_execute_vf_cmd_safe(adapter, &args, 0);
     854         [ #  # ]:          0 :         if (ret)
     855         [ #  # ]:          0 :                 PMD_DRV_LOG(ERR, "fail to execute command %s",
     856                 :            :                             enable ? "VIRTCHNL_OP_ENABLE_VLAN_INSERTION_V2" :
     857                 :            :                                      "VIRTCHNL_OP_DISABLE_VLAN_INSERTION_V2");
     858                 :            : 
     859                 :            :         return ret;
     860                 :            : }
     861                 :            : 
     862                 :            : int
     863                 :          0 : iavf_add_del_vlan_v2(struct iavf_adapter *adapter, uint16_t vlanid, bool add)
     864                 :            : {
     865                 :            :         struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(adapter);
     866                 :            :         struct virtchnl_vlan_supported_caps *supported_caps;
     867                 :            :         struct virtchnl_vlan_filter_list_v2 vlan_filter;
     868                 :            :         struct virtchnl_vlan *vlan_setting;
     869                 :            :         struct iavf_cmd_info args;
     870                 :            :         uint32_t filtering_caps;
     871                 :            :         int err;
     872                 :            : 
     873                 :            :         supported_caps = &vf->vlan_v2_caps.filtering.filtering_support;
     874         [ #  # ]:          0 :         if (supported_caps->outer) {
     875                 :            :                 filtering_caps = supported_caps->outer;
     876                 :            :                 vlan_setting = &vlan_filter.filters[0].outer;
     877                 :            :         } else {
     878                 :          0 :                 filtering_caps = supported_caps->inner;
     879                 :            :                 vlan_setting = &vlan_filter.filters[0].inner;
     880                 :            :         }
     881                 :            : 
     882         [ #  # ]:          0 :         if (!(filtering_caps & VIRTCHNL_VLAN_ETHERTYPE_8100))
     883                 :            :                 return -ENOTSUP;
     884                 :            : 
     885                 :            :         memset(&vlan_filter, 0, sizeof(vlan_filter));
     886                 :          0 :         vlan_filter.vport_id = vf->vsi_res->vsi_id;
     887                 :          0 :         vlan_filter.num_elements = 1;
     888                 :          0 :         vlan_setting->tpid = RTE_ETHER_TYPE_VLAN;
     889                 :          0 :         vlan_setting->tci = vlanid;
     890                 :            : 
     891         [ #  # ]:          0 :         args.ops = add ? VIRTCHNL_OP_ADD_VLAN_V2 : VIRTCHNL_OP_DEL_VLAN_V2;
     892                 :          0 :         args.in_args = (uint8_t *)&vlan_filter;
     893                 :          0 :         args.in_args_size = sizeof(vlan_filter);
     894                 :          0 :         args.out_buffer = vf->aq_resp;
     895                 :          0 :         args.out_size = IAVF_AQ_BUF_SZ;
     896                 :          0 :         err = iavf_execute_vf_cmd_safe(adapter, &args, 0);
     897         [ #  # ]:          0 :         if (err)
     898         [ #  # ]:          0 :                 PMD_DRV_LOG(ERR, "fail to execute command %s",
     899                 :            :                             add ? "OP_ADD_VLAN_V2" :  "OP_DEL_VLAN_V2");
     900                 :            : 
     901                 :            :         return err;
     902                 :            : }
     903                 :            : 
     904                 :            : int
     905                 :          0 : iavf_get_vlan_offload_caps_v2(struct iavf_adapter *adapter)
     906                 :            : {
     907                 :            :         struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(adapter);
     908                 :            :         struct iavf_cmd_info args;
     909                 :            :         int ret;
     910                 :            : 
     911                 :          0 :         args.ops = VIRTCHNL_OP_GET_OFFLOAD_VLAN_V2_CAPS;
     912                 :          0 :         args.in_args = NULL;
     913                 :          0 :         args.in_args_size = 0;
     914                 :          0 :         args.out_buffer = vf->aq_resp;
     915                 :          0 :         args.out_size = IAVF_AQ_BUF_SZ;
     916                 :            : 
     917                 :          0 :         ret = iavf_execute_vf_cmd_safe(adapter, &args, 0);
     918         [ #  # ]:          0 :         if (ret) {
     919                 :          0 :                 PMD_DRV_LOG(ERR,
     920                 :            :                             "Failed to execute command of VIRTCHNL_OP_GET_OFFLOAD_VLAN_V2_CAPS");
     921                 :          0 :                 return ret;
     922                 :            :         }
     923                 :            : 
     924         [ #  # ]:          0 :         rte_memcpy(&vf->vlan_v2_caps, vf->aq_resp, sizeof(vf->vlan_v2_caps));
     925                 :            : 
     926                 :            :         return 0;
     927                 :            : }
     928                 :            : 
     929                 :            : int
     930                 :          0 : iavf_enable_queues(struct iavf_adapter *adapter)
     931                 :            : {
     932                 :            :         struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(adapter);
     933                 :            :         struct virtchnl_queue_select queue_select;
     934                 :            :         struct iavf_cmd_info args;
     935                 :            :         int err;
     936                 :            : 
     937                 :            :         memset(&queue_select, 0, sizeof(queue_select));
     938                 :          0 :         queue_select.vsi_id = vf->vsi_res->vsi_id;
     939                 :            : 
     940                 :          0 :         queue_select.rx_queues = BIT(adapter->dev_data->nb_rx_queues) - 1;
     941                 :          0 :         queue_select.tx_queues = BIT(adapter->dev_data->nb_tx_queues) - 1;
     942                 :            : 
     943                 :          0 :         args.ops = VIRTCHNL_OP_ENABLE_QUEUES;
     944                 :          0 :         args.in_args = (u8 *)&queue_select;
     945                 :          0 :         args.in_args_size = sizeof(queue_select);
     946                 :          0 :         args.out_buffer = vf->aq_resp;
     947                 :          0 :         args.out_size = IAVF_AQ_BUF_SZ;
     948                 :          0 :         err = iavf_execute_vf_cmd_safe(adapter, &args, 0);
     949         [ #  # ]:          0 :         if (err) {
     950                 :          0 :                 PMD_DRV_LOG(ERR,
     951                 :            :                             "Failed to execute command of OP_ENABLE_QUEUES");
     952                 :          0 :                 return err;
     953                 :            :         }
     954                 :            :         return 0;
     955                 :            : }
     956                 :            : 
     957                 :            : int
     958                 :          0 : iavf_disable_queues(struct iavf_adapter *adapter)
     959                 :            : {
     960                 :            :         struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(adapter);
     961                 :            :         struct virtchnl_queue_select queue_select;
     962                 :            :         struct iavf_cmd_info args;
     963                 :            :         int err;
     964                 :            : 
     965                 :            :         memset(&queue_select, 0, sizeof(queue_select));
     966                 :          0 :         queue_select.vsi_id = vf->vsi_res->vsi_id;
     967                 :            : 
     968                 :          0 :         queue_select.rx_queues = BIT(adapter->dev_data->nb_rx_queues) - 1;
     969                 :          0 :         queue_select.tx_queues = BIT(adapter->dev_data->nb_tx_queues) - 1;
     970                 :            : 
     971                 :          0 :         args.ops = VIRTCHNL_OP_DISABLE_QUEUES;
     972                 :          0 :         args.in_args = (u8 *)&queue_select;
     973                 :          0 :         args.in_args_size = sizeof(queue_select);
     974                 :          0 :         args.out_buffer = vf->aq_resp;
     975                 :          0 :         args.out_size = IAVF_AQ_BUF_SZ;
     976                 :          0 :         err = iavf_execute_vf_cmd_safe(adapter, &args, 0);
     977         [ #  # ]:          0 :         if (err) {
     978                 :          0 :                 PMD_DRV_LOG(ERR,
     979                 :            :                             "Failed to execute command of OP_DISABLE_QUEUES");
     980                 :          0 :                 return err;
     981                 :            :         }
     982                 :            :         return 0;
     983                 :            : }
     984                 :            : 
     985                 :            : int
     986                 :          0 : iavf_switch_queue(struct iavf_adapter *adapter, uint16_t qid,
     987                 :            :                  bool rx, bool on)
     988                 :            : {
     989                 :            :         struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(adapter);
     990                 :            :         struct virtchnl_queue_select queue_select;
     991                 :            :         struct iavf_cmd_info args;
     992                 :            :         int err;
     993                 :            : 
     994         [ #  # ]:          0 :         if (adapter->closed)
     995                 :            :                 return -EIO;
     996                 :            : 
     997                 :            :         memset(&queue_select, 0, sizeof(queue_select));
     998                 :          0 :         queue_select.vsi_id = vf->vsi_res->vsi_id;
     999         [ #  # ]:          0 :         if (rx)
    1000                 :          0 :                 queue_select.rx_queues |= 1 << qid;
    1001                 :            :         else
    1002                 :          0 :                 queue_select.tx_queues |= 1 << qid;
    1003                 :            : 
    1004         [ #  # ]:          0 :         if (on)
    1005                 :          0 :                 args.ops = VIRTCHNL_OP_ENABLE_QUEUES;
    1006                 :            :         else
    1007                 :          0 :                 args.ops = VIRTCHNL_OP_DISABLE_QUEUES;
    1008                 :          0 :         args.in_args = (u8 *)&queue_select;
    1009                 :          0 :         args.in_args_size = sizeof(queue_select);
    1010                 :          0 :         args.out_buffer = vf->aq_resp;
    1011                 :          0 :         args.out_size = IAVF_AQ_BUF_SZ;
    1012                 :          0 :         err = iavf_execute_vf_cmd_safe(adapter, &args, 0);
    1013         [ #  # ]:          0 :         if (err)
    1014         [ #  # ]:          0 :                 PMD_DRV_LOG(ERR, "Failed to execute command of %s",
    1015                 :            :                             on ? "OP_ENABLE_QUEUES" : "OP_DISABLE_QUEUES");
    1016                 :            :         return err;
    1017                 :            : }
    1018                 :            : 
    1019                 :            : int
    1020                 :          0 : iavf_enable_queues_lv(struct iavf_adapter *adapter)
    1021                 :            : {
    1022                 :            :         struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(adapter);
    1023                 :            :         struct virtchnl_del_ena_dis_queues *queue_select;
    1024                 :            :         struct virtchnl_queue_chunk *queue_chunk;
    1025                 :            :         struct iavf_cmd_info args;
    1026                 :            :         int err, len;
    1027                 :            : 
    1028                 :            :         len = sizeof(struct virtchnl_del_ena_dis_queues) +
    1029                 :            :                   sizeof(struct virtchnl_queue_chunk) *
    1030                 :            :                   (IAVF_RXTX_QUEUE_CHUNKS_NUM - 1);
    1031                 :          0 :         queue_select = rte_zmalloc("queue_select", len, 0);
    1032         [ #  # ]:          0 :         if (!queue_select)
    1033                 :            :                 return -ENOMEM;
    1034                 :            : 
    1035                 :            :         queue_chunk = queue_select->chunks.chunks;
    1036                 :          0 :         queue_select->chunks.num_chunks = IAVF_RXTX_QUEUE_CHUNKS_NUM;
    1037                 :          0 :         queue_select->vport_id = vf->vsi_res->vsi_id;
    1038                 :            : 
    1039                 :          0 :         queue_chunk[VIRTCHNL_QUEUE_TYPE_TX].type = VIRTCHNL_QUEUE_TYPE_TX;
    1040                 :          0 :         queue_chunk[VIRTCHNL_QUEUE_TYPE_TX].start_queue_id = 0;
    1041                 :          0 :         queue_chunk[VIRTCHNL_QUEUE_TYPE_TX].num_queues =
    1042                 :          0 :                 adapter->dev_data->nb_tx_queues;
    1043                 :            : 
    1044                 :          0 :         queue_chunk[VIRTCHNL_QUEUE_TYPE_RX].type = VIRTCHNL_QUEUE_TYPE_RX;
    1045                 :          0 :         queue_chunk[VIRTCHNL_QUEUE_TYPE_RX].start_queue_id = 0;
    1046                 :          0 :         queue_chunk[VIRTCHNL_QUEUE_TYPE_RX].num_queues =
    1047                 :          0 :                 adapter->dev_data->nb_rx_queues;
    1048                 :            : 
    1049                 :          0 :         args.ops = VIRTCHNL_OP_ENABLE_QUEUES_V2;
    1050                 :          0 :         args.in_args = (u8 *)queue_select;
    1051                 :          0 :         args.in_args_size = len;
    1052                 :          0 :         args.out_buffer = vf->aq_resp;
    1053                 :          0 :         args.out_size = IAVF_AQ_BUF_SZ;
    1054                 :          0 :         err = iavf_execute_vf_cmd_safe(adapter, &args, 0);
    1055         [ #  # ]:          0 :         if (err)
    1056                 :          0 :                 PMD_DRV_LOG(ERR,
    1057                 :            :                             "Failed to execute command of OP_ENABLE_QUEUES_V2");
    1058                 :            : 
    1059                 :          0 :         rte_free(queue_select);
    1060                 :          0 :         return err;
    1061                 :            : }
    1062                 :            : 
    1063                 :            : int
    1064                 :          0 : iavf_disable_queues_lv(struct iavf_adapter *adapter)
    1065                 :            : {
    1066                 :            :         struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(adapter);
    1067                 :            :         struct virtchnl_del_ena_dis_queues *queue_select;
    1068                 :            :         struct virtchnl_queue_chunk *queue_chunk;
    1069                 :            :         struct iavf_cmd_info args;
    1070                 :            :         int err, len;
    1071                 :            : 
    1072                 :            :         len = sizeof(struct virtchnl_del_ena_dis_queues) +
    1073                 :            :                   sizeof(struct virtchnl_queue_chunk) *
    1074                 :            :                   (IAVF_RXTX_QUEUE_CHUNKS_NUM - 1);
    1075                 :          0 :         queue_select = rte_zmalloc("queue_select", len, 0);
    1076         [ #  # ]:          0 :         if (!queue_select)
    1077                 :            :                 return -ENOMEM;
    1078                 :            : 
    1079                 :            :         queue_chunk = queue_select->chunks.chunks;
    1080                 :          0 :         queue_select->chunks.num_chunks = IAVF_RXTX_QUEUE_CHUNKS_NUM;
    1081                 :          0 :         queue_select->vport_id = vf->vsi_res->vsi_id;
    1082                 :            : 
    1083                 :          0 :         queue_chunk[VIRTCHNL_QUEUE_TYPE_TX].type = VIRTCHNL_QUEUE_TYPE_TX;
    1084                 :          0 :         queue_chunk[VIRTCHNL_QUEUE_TYPE_TX].start_queue_id = 0;
    1085                 :          0 :         queue_chunk[VIRTCHNL_QUEUE_TYPE_TX].num_queues =
    1086                 :          0 :                 adapter->dev_data->nb_tx_queues;
    1087                 :            : 
    1088                 :          0 :         queue_chunk[VIRTCHNL_QUEUE_TYPE_RX].type = VIRTCHNL_QUEUE_TYPE_RX;
    1089                 :          0 :         queue_chunk[VIRTCHNL_QUEUE_TYPE_RX].start_queue_id = 0;
    1090                 :          0 :         queue_chunk[VIRTCHNL_QUEUE_TYPE_RX].num_queues =
    1091                 :          0 :                 adapter->dev_data->nb_rx_queues;
    1092                 :            : 
    1093                 :          0 :         args.ops = VIRTCHNL_OP_DISABLE_QUEUES_V2;
    1094                 :          0 :         args.in_args = (u8 *)queue_select;
    1095                 :          0 :         args.in_args_size = len;
    1096                 :          0 :         args.out_buffer = vf->aq_resp;
    1097                 :          0 :         args.out_size = IAVF_AQ_BUF_SZ;
    1098                 :          0 :         err = iavf_execute_vf_cmd_safe(adapter, &args, 0);
    1099         [ #  # ]:          0 :         if (err)
    1100                 :          0 :                 PMD_DRV_LOG(ERR,
    1101                 :            :                             "Failed to execute command of OP_DISABLE_QUEUES_V2");
    1102                 :            : 
    1103                 :          0 :         rte_free(queue_select);
    1104                 :          0 :         return err;
    1105                 :            : }
    1106                 :            : 
    1107                 :            : int
    1108                 :          0 : iavf_switch_queue_lv(struct iavf_adapter *adapter, uint16_t qid,
    1109                 :            :                  bool rx, bool on)
    1110                 :            : {
    1111                 :            :         struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(adapter);
    1112                 :            :         struct virtchnl_del_ena_dis_queues *queue_select;
    1113                 :            :         struct virtchnl_queue_chunk *queue_chunk;
    1114                 :            :         struct iavf_cmd_info args;
    1115                 :            :         int err, len;
    1116                 :            : 
    1117                 :            :         len = sizeof(struct virtchnl_del_ena_dis_queues);
    1118                 :          0 :         queue_select = rte_zmalloc("queue_select", len, 0);
    1119         [ #  # ]:          0 :         if (!queue_select)
    1120                 :            :                 return -ENOMEM;
    1121                 :            : 
    1122                 :            :         queue_chunk = queue_select->chunks.chunks;
    1123                 :          0 :         queue_select->chunks.num_chunks = 1;
    1124                 :          0 :         queue_select->vport_id = vf->vsi_res->vsi_id;
    1125                 :            : 
    1126         [ #  # ]:          0 :         if (rx) {
    1127                 :          0 :                 queue_chunk->type = VIRTCHNL_QUEUE_TYPE_RX;
    1128                 :          0 :                 queue_chunk->start_queue_id = qid;
    1129                 :          0 :                 queue_chunk->num_queues = 1;
    1130                 :            :         } else {
    1131                 :          0 :                 queue_chunk->type = VIRTCHNL_QUEUE_TYPE_TX;
    1132                 :          0 :                 queue_chunk->start_queue_id = qid;
    1133                 :          0 :                 queue_chunk->num_queues = 1;
    1134                 :            :         }
    1135                 :            : 
    1136         [ #  # ]:          0 :         if (on)
    1137                 :          0 :                 args.ops = VIRTCHNL_OP_ENABLE_QUEUES_V2;
    1138                 :            :         else
    1139                 :          0 :                 args.ops = VIRTCHNL_OP_DISABLE_QUEUES_V2;
    1140                 :          0 :         args.in_args = (u8 *)queue_select;
    1141                 :          0 :         args.in_args_size = len;
    1142                 :          0 :         args.out_buffer = vf->aq_resp;
    1143                 :          0 :         args.out_size = IAVF_AQ_BUF_SZ;
    1144                 :          0 :         err = iavf_execute_vf_cmd_safe(adapter, &args, 0);
    1145         [ #  # ]:          0 :         if (err)
    1146         [ #  # ]:          0 :                 PMD_DRV_LOG(ERR, "Failed to execute command of %s",
    1147                 :            :                             on ? "OP_ENABLE_QUEUES_V2" : "OP_DISABLE_QUEUES_V2");
    1148                 :            : 
    1149                 :          0 :         rte_free(queue_select);
    1150                 :          0 :         return err;
    1151                 :            : }
    1152                 :            : 
    1153                 :            : int
    1154                 :          0 : iavf_configure_rss_lut(struct iavf_adapter *adapter)
    1155                 :            : {
    1156                 :            :         struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(adapter);
    1157                 :            :         struct virtchnl_rss_lut *rss_lut;
    1158                 :            :         struct iavf_cmd_info args;
    1159                 :            :         int len, err = 0;
    1160                 :            : 
    1161                 :          0 :         len = sizeof(*rss_lut) + vf->vf_res->rss_lut_size - 1;
    1162                 :          0 :         rss_lut = rte_zmalloc("rss_lut", len, 0);
    1163         [ #  # ]:          0 :         if (!rss_lut)
    1164                 :            :                 return -ENOMEM;
    1165                 :            : 
    1166                 :          0 :         rss_lut->vsi_id = vf->vsi_res->vsi_id;
    1167                 :          0 :         rss_lut->lut_entries = vf->vf_res->rss_lut_size;
    1168         [ #  # ]:          0 :         rte_memcpy(rss_lut->lut, vf->rss_lut, vf->vf_res->rss_lut_size);
    1169                 :            : 
    1170                 :          0 :         args.ops = VIRTCHNL_OP_CONFIG_RSS_LUT;
    1171                 :          0 :         args.in_args = (u8 *)rss_lut;
    1172                 :          0 :         args.in_args_size = len;
    1173                 :          0 :         args.out_buffer = vf->aq_resp;
    1174                 :          0 :         args.out_size = IAVF_AQ_BUF_SZ;
    1175                 :            : 
    1176                 :          0 :         err = iavf_execute_vf_cmd_safe(adapter, &args, 0);
    1177         [ #  # ]:          0 :         if (err)
    1178                 :          0 :                 PMD_DRV_LOG(ERR,
    1179                 :            :                             "Failed to execute command of OP_CONFIG_RSS_LUT");
    1180                 :            : 
    1181                 :          0 :         rte_free(rss_lut);
    1182                 :          0 :         return err;
    1183                 :            : }
    1184                 :            : 
    1185                 :            : int
    1186                 :          0 : iavf_configure_rss_key(struct iavf_adapter *adapter)
    1187                 :            : {
    1188                 :            :         struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(adapter);
    1189                 :            :         struct virtchnl_rss_key *rss_key;
    1190                 :            :         struct iavf_cmd_info args;
    1191                 :            :         int len, err = 0;
    1192                 :            : 
    1193                 :          0 :         len = sizeof(*rss_key) + vf->vf_res->rss_key_size - 1;
    1194                 :          0 :         rss_key = rte_zmalloc("rss_key", len, 0);
    1195         [ #  # ]:          0 :         if (!rss_key)
    1196                 :            :                 return -ENOMEM;
    1197                 :            : 
    1198                 :          0 :         rss_key->vsi_id = vf->vsi_res->vsi_id;
    1199                 :          0 :         rss_key->key_len = vf->vf_res->rss_key_size;
    1200         [ #  # ]:          0 :         rte_memcpy(rss_key->key, vf->rss_key, vf->vf_res->rss_key_size);
    1201                 :            : 
    1202                 :          0 :         args.ops = VIRTCHNL_OP_CONFIG_RSS_KEY;
    1203                 :          0 :         args.in_args = (u8 *)rss_key;
    1204                 :          0 :         args.in_args_size = len;
    1205                 :          0 :         args.out_buffer = vf->aq_resp;
    1206                 :          0 :         args.out_size = IAVF_AQ_BUF_SZ;
    1207                 :            : 
    1208                 :          0 :         err = iavf_execute_vf_cmd_safe(adapter, &args, 0);
    1209         [ #  # ]:          0 :         if (err)
    1210                 :          0 :                 PMD_DRV_LOG(ERR,
    1211                 :            :                             "Failed to execute command of OP_CONFIG_RSS_KEY");
    1212                 :            : 
    1213                 :          0 :         rte_free(rss_key);
    1214                 :          0 :         return err;
    1215                 :            : }
    1216                 :            : 
    1217                 :            : int
    1218                 :          0 : iavf_configure_queues(struct iavf_adapter *adapter,
    1219                 :            :                 uint16_t num_queue_pairs, uint16_t index)
    1220                 :            : {
    1221                 :          0 :         struct iavf_rx_queue **rxq =
    1222                 :          0 :                 (struct iavf_rx_queue **)adapter->dev_data->rx_queues;
    1223                 :          0 :         struct iavf_tx_queue **txq =
    1224                 :            :                 (struct iavf_tx_queue **)adapter->dev_data->tx_queues;
    1225                 :            :         struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(adapter);
    1226                 :            :         struct virtchnl_vsi_queue_config_info *vc_config;
    1227                 :            :         struct virtchnl_queue_pair_info *vc_qp;
    1228                 :            :         struct iavf_cmd_info args;
    1229                 :            :         uint16_t i, size;
    1230                 :            :         int err;
    1231                 :            : 
    1232                 :          0 :         size = sizeof(*vc_config) +
    1233                 :          0 :                sizeof(vc_config->qpair[0]) * num_queue_pairs;
    1234                 :          0 :         vc_config = rte_zmalloc("cfg_queue", size, 0);
    1235         [ #  # ]:          0 :         if (!vc_config)
    1236                 :            :                 return -ENOMEM;
    1237                 :            : 
    1238                 :          0 :         vc_config->vsi_id = vf->vsi_res->vsi_id;
    1239                 :          0 :         vc_config->num_queue_pairs = num_queue_pairs;
    1240                 :            : 
    1241                 :          0 :         for (i = index, vc_qp = vc_config->qpair;
    1242         [ #  # ]:          0 :                  i < index + num_queue_pairs;
    1243                 :          0 :              i++, vc_qp++) {
    1244                 :          0 :                 vc_qp->txq.vsi_id = vf->vsi_res->vsi_id;
    1245                 :          0 :                 vc_qp->txq.queue_id = i;
    1246                 :            : 
    1247                 :            :                 /* Virtchnnl configure tx queues by pairs */
    1248         [ #  # ]:          0 :                 if (i < adapter->dev_data->nb_tx_queues) {
    1249                 :          0 :                         vc_qp->txq.ring_len = txq[i]->nb_tx_desc;
    1250                 :          0 :                         vc_qp->txq.dma_ring_addr = txq[i]->tx_ring_phys_addr;
    1251                 :            :                 }
    1252                 :            : 
    1253                 :          0 :                 vc_qp->rxq.vsi_id = vf->vsi_res->vsi_id;
    1254                 :          0 :                 vc_qp->rxq.queue_id = i;
    1255                 :          0 :                 vc_qp->rxq.max_pkt_size = vf->max_pkt_len;
    1256                 :            : 
    1257         [ #  # ]:          0 :                 if (i >= adapter->dev_data->nb_rx_queues)
    1258                 :          0 :                         continue;
    1259                 :            : 
    1260                 :            :                 /* Virtchnnl configure rx queues by pairs */
    1261                 :          0 :                 vc_qp->rxq.ring_len = rxq[i]->nb_rx_desc;
    1262                 :          0 :                 vc_qp->rxq.dma_ring_addr = rxq[i]->rx_ring_phys_addr;
    1263                 :          0 :                 vc_qp->rxq.databuffer_size = rxq[i]->rx_buf_len;
    1264                 :          0 :                 vc_qp->rxq.crc_disable = rxq[i]->crc_len != 0 ? 1 : 0;
    1265                 :            : #ifndef RTE_LIBRTE_IAVF_16BYTE_RX_DESC
    1266         [ #  # ]:          0 :                 if (vf->vf_res->vf_cap_flags &
    1267                 :            :                     VIRTCHNL_VF_OFFLOAD_RX_FLEX_DESC) {
    1268         [ #  # ]:          0 :                         if (vf->supported_rxdid & BIT(rxq[i]->rxdid)) {
    1269                 :          0 :                                 vc_qp->rxq.rxdid = rxq[i]->rxdid;
    1270                 :          0 :                                 PMD_DRV_LOG(NOTICE, "request RXDID[%d] in Queue[%d]",
    1271                 :            :                                             vc_qp->rxq.rxdid, i);
    1272                 :            :                         } else {
    1273                 :          0 :                                 PMD_DRV_LOG(NOTICE, "RXDID[%d] is not supported, "
    1274                 :            :                                             "request default RXDID[%d] in Queue[%d]",
    1275                 :            :                                             rxq[i]->rxdid, IAVF_RXDID_LEGACY_1, i);
    1276                 :          0 :                                 vc_qp->rxq.rxdid = IAVF_RXDID_LEGACY_1;
    1277                 :            :                         }
    1278                 :            : 
    1279         [ #  # ]:          0 :                         if (vf->vf_res->vf_cap_flags & VIRTCHNL_VF_CAP_PTP &&
    1280         [ #  # ]:          0 :                             vf->ptp_caps & VIRTCHNL_1588_PTP_CAP_RX_TSTAMP &&
    1281         [ #  # ]:          0 :                             rxq[i]->offloads & RTE_ETH_RX_OFFLOAD_TIMESTAMP)
    1282                 :          0 :                                 vc_qp->rxq.flags |= VIRTCHNL_PTP_RX_TSTAMP;
    1283                 :            :                 }
    1284                 :            : #else
    1285                 :            :                 if (vf->vf_res->vf_cap_flags &
    1286                 :            :                         VIRTCHNL_VF_OFFLOAD_RX_FLEX_DESC &&
    1287                 :            :                         vf->supported_rxdid & BIT(IAVF_RXDID_LEGACY_0)) {
    1288                 :            :                         vc_qp->rxq.rxdid = IAVF_RXDID_LEGACY_0;
    1289                 :            :                         PMD_DRV_LOG(NOTICE, "request RXDID[%d] in Queue[%d]",
    1290                 :            :                                     vc_qp->rxq.rxdid, i);
    1291                 :            :                 } else {
    1292                 :            :                         PMD_DRV_LOG(ERR, "RXDID[%d] is not supported",
    1293                 :            :                                     IAVF_RXDID_LEGACY_0);
    1294                 :            :                         return -1;
    1295                 :            :                 }
    1296                 :            : #endif
    1297                 :            :         }
    1298                 :            : 
    1299                 :            :         memset(&args, 0, sizeof(args));
    1300                 :          0 :         args.ops = VIRTCHNL_OP_CONFIG_VSI_QUEUES;
    1301                 :          0 :         args.in_args = (uint8_t *)vc_config;
    1302                 :          0 :         args.in_args_size = size;
    1303                 :          0 :         args.out_buffer = vf->aq_resp;
    1304                 :          0 :         args.out_size = IAVF_AQ_BUF_SZ;
    1305                 :            : 
    1306                 :          0 :         err = iavf_execute_vf_cmd_safe(adapter, &args, 0);
    1307         [ #  # ]:          0 :         if (err)
    1308                 :          0 :                 PMD_DRV_LOG(ERR, "Failed to execute command of"
    1309                 :            :                             " VIRTCHNL_OP_CONFIG_VSI_QUEUES");
    1310                 :            : 
    1311                 :          0 :         rte_free(vc_config);
    1312                 :          0 :         return err;
    1313                 :            : }
    1314                 :            : 
    1315                 :            : int
    1316                 :          0 : iavf_config_irq_map(struct iavf_adapter *adapter)
    1317                 :            : {
    1318                 :            :         struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(adapter);
    1319                 :            :         struct virtchnl_irq_map_info *map_info;
    1320                 :            :         struct virtchnl_vector_map *vecmap;
    1321                 :            :         struct iavf_cmd_info args;
    1322                 :            :         int len, i, err;
    1323                 :            : 
    1324                 :          0 :         len = sizeof(struct virtchnl_irq_map_info) +
    1325                 :          0 :               sizeof(struct virtchnl_vector_map) * vf->nb_msix;
    1326                 :            : 
    1327                 :          0 :         map_info = rte_zmalloc("map_info", len, 0);
    1328         [ #  # ]:          0 :         if (!map_info)
    1329                 :            :                 return -ENOMEM;
    1330                 :            : 
    1331                 :          0 :         map_info->num_vectors = vf->nb_msix;
    1332         [ #  # ]:          0 :         for (i = 0; i < adapter->dev_data->nb_rx_queues; i++) {
    1333                 :            :                 vecmap =
    1334                 :          0 :                     &map_info->vecmap[vf->qv_map[i].vector_id - vf->msix_base];
    1335                 :          0 :                 vecmap->vsi_id = vf->vsi_res->vsi_id;
    1336                 :          0 :                 vecmap->rxitr_idx = IAVF_ITR_INDEX_DEFAULT;
    1337                 :          0 :                 vecmap->vector_id = vf->qv_map[i].vector_id;
    1338                 :          0 :                 vecmap->txq_map = 0;
    1339                 :          0 :                 vecmap->rxq_map |= 1 << vf->qv_map[i].queue_id;
    1340                 :            :         }
    1341                 :            : 
    1342                 :          0 :         args.ops = VIRTCHNL_OP_CONFIG_IRQ_MAP;
    1343                 :          0 :         args.in_args = (u8 *)map_info;
    1344                 :          0 :         args.in_args_size = len;
    1345                 :          0 :         args.out_buffer = vf->aq_resp;
    1346                 :          0 :         args.out_size = IAVF_AQ_BUF_SZ;
    1347                 :          0 :         err = iavf_execute_vf_cmd_safe(adapter, &args, 0);
    1348         [ #  # ]:          0 :         if (err)
    1349                 :          0 :                 PMD_DRV_LOG(ERR, "fail to execute command OP_CONFIG_IRQ_MAP");
    1350                 :            : 
    1351                 :          0 :         rte_free(map_info);
    1352                 :          0 :         return err;
    1353                 :            : }
    1354                 :            : 
    1355                 :            : int
    1356                 :          0 : iavf_config_irq_map_lv(struct iavf_adapter *adapter, uint16_t num,
    1357                 :            :                 uint16_t index)
    1358                 :            : {
    1359                 :            :         struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(adapter);
    1360                 :            :         struct virtchnl_queue_vector_maps *map_info;
    1361                 :            :         struct virtchnl_queue_vector *qv_maps;
    1362                 :            :         struct iavf_cmd_info args;
    1363                 :            :         int len, i, err;
    1364                 :            :         int count = 0;
    1365                 :            : 
    1366                 :          0 :         len = sizeof(struct virtchnl_queue_vector_maps) +
    1367                 :          0 :               sizeof(struct virtchnl_queue_vector) * (num - 1);
    1368                 :            : 
    1369                 :          0 :         map_info = rte_zmalloc("map_info", len, 0);
    1370         [ #  # ]:          0 :         if (!map_info)
    1371                 :            :                 return -ENOMEM;
    1372                 :            : 
    1373                 :          0 :         map_info->vport_id = vf->vsi_res->vsi_id;
    1374                 :          0 :         map_info->num_qv_maps = num;
    1375         [ #  # ]:          0 :         for (i = index; i < index + map_info->num_qv_maps; i++) {
    1376                 :          0 :                 qv_maps = &map_info->qv_maps[count++];
    1377                 :          0 :                 qv_maps->itr_idx = VIRTCHNL_ITR_IDX_0;
    1378                 :          0 :                 qv_maps->queue_type = VIRTCHNL_QUEUE_TYPE_RX;
    1379                 :          0 :                 qv_maps->queue_id = vf->qv_map[i].queue_id;
    1380                 :          0 :                 qv_maps->vector_id = vf->qv_map[i].vector_id;
    1381                 :            :         }
    1382                 :            : 
    1383                 :          0 :         args.ops = VIRTCHNL_OP_MAP_QUEUE_VECTOR;
    1384                 :          0 :         args.in_args = (u8 *)map_info;
    1385                 :          0 :         args.in_args_size = len;
    1386                 :          0 :         args.out_buffer = vf->aq_resp;
    1387                 :          0 :         args.out_size = IAVF_AQ_BUF_SZ;
    1388                 :          0 :         err = iavf_execute_vf_cmd_safe(adapter, &args, 0);
    1389         [ #  # ]:          0 :         if (err)
    1390                 :          0 :                 PMD_DRV_LOG(ERR, "fail to execute command OP_MAP_QUEUE_VECTOR");
    1391                 :            : 
    1392                 :          0 :         rte_free(map_info);
    1393                 :          0 :         return err;
    1394                 :            : }
    1395                 :            : 
    1396                 :            : void
    1397                 :          0 : iavf_add_del_all_mac_addr(struct iavf_adapter *adapter, bool add)
    1398                 :            : {
    1399                 :            :         struct virtchnl_ether_addr_list *list;
    1400                 :            :         struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(adapter);
    1401                 :            :         struct rte_ether_addr *addr;
    1402                 :            :         struct iavf_cmd_info args;
    1403                 :            :         int len, err, i, j;
    1404                 :            :         int next_begin = 0;
    1405                 :            :         int begin = 0;
    1406                 :            : 
    1407                 :            :         do {
    1408                 :            :                 j = 0;
    1409                 :            :                 len = sizeof(struct virtchnl_ether_addr_list);
    1410         [ #  # ]:          0 :                 for (i = begin; i < IAVF_NUM_MACADDR_MAX; i++, next_begin++) {
    1411         [ #  # ]:          0 :                         addr = &adapter->dev_data->mac_addrs[i];
    1412         [ #  # ]:          0 :                         if (rte_is_zero_ether_addr(addr))
    1413                 :          0 :                                 continue;
    1414                 :          0 :                         len += sizeof(struct virtchnl_ether_addr);
    1415         [ #  # ]:          0 :                         if (len >= IAVF_AQ_BUF_SZ) {
    1416                 :          0 :                                 next_begin = i + 1;
    1417                 :          0 :                                 break;
    1418                 :            :                         }
    1419                 :            :                 }
    1420                 :            : 
    1421                 :          0 :                 list = rte_zmalloc("iavf_del_mac_buffer", len, 0);
    1422         [ #  # ]:          0 :                 if (!list) {
    1423                 :          0 :                         PMD_DRV_LOG(ERR, "fail to allocate memory");
    1424                 :          0 :                         return;
    1425                 :            :                 }
    1426                 :            : 
    1427         [ #  # ]:          0 :                 for (i = begin; i < next_begin; i++) {
    1428         [ #  # ]:          0 :                         addr = &adapter->dev_data->mac_addrs[i];
    1429         [ #  # ]:          0 :                         if (rte_is_zero_ether_addr(addr))
    1430                 :          0 :                                 continue;
    1431         [ #  # ]:          0 :                         rte_memcpy(list->list[j].addr, addr->addr_bytes,
    1432                 :            :                                    sizeof(addr->addr_bytes));
    1433         [ #  # ]:          0 :                         list->list[j].type = (j == 0 ?
    1434                 :            :                                               VIRTCHNL_ETHER_ADDR_PRIMARY :
    1435                 :            :                                               VIRTCHNL_ETHER_ADDR_EXTRA);
    1436                 :          0 :                         PMD_DRV_LOG(DEBUG, "add/rm mac:" RTE_ETHER_ADDR_PRT_FMT,
    1437                 :            :                                     RTE_ETHER_ADDR_BYTES(addr));
    1438                 :          0 :                         j++;
    1439                 :            :                 }
    1440                 :          0 :                 list->vsi_id = vf->vsi_res->vsi_id;
    1441                 :          0 :                 list->num_elements = j;
    1442         [ #  # ]:          0 :                 args.ops = add ? VIRTCHNL_OP_ADD_ETH_ADDR :
    1443                 :            :                            VIRTCHNL_OP_DEL_ETH_ADDR;
    1444                 :          0 :                 args.in_args = (uint8_t *)list;
    1445                 :          0 :                 args.in_args_size = len;
    1446                 :          0 :                 args.out_buffer = vf->aq_resp;
    1447                 :          0 :                 args.out_size = IAVF_AQ_BUF_SZ;
    1448                 :          0 :                 err = iavf_execute_vf_cmd_safe(adapter, &args, 0);
    1449         [ #  # ]:          0 :                 if (err)
    1450         [ #  # ]:          0 :                         PMD_DRV_LOG(ERR, "fail to execute command %s",
    1451                 :            :                                     add ? "OP_ADD_ETHER_ADDRESS" :
    1452                 :            :                                     "OP_DEL_ETHER_ADDRESS");
    1453                 :          0 :                 rte_free(list);
    1454                 :            :                 begin = next_begin;
    1455         [ #  # ]:          0 :         } while (begin < IAVF_NUM_MACADDR_MAX);
    1456                 :            : }
    1457                 :            : 
    1458                 :            : int
    1459                 :          0 : iavf_query_stats(struct iavf_adapter *adapter,
    1460                 :            :                 struct virtchnl_eth_stats **pstats)
    1461                 :            : {
    1462                 :            :         struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(adapter);
    1463                 :            :         struct virtchnl_queue_select q_stats;
    1464                 :            :         struct iavf_cmd_info args;
    1465                 :            :         int err;
    1466                 :            : 
    1467         [ #  # ]:          0 :         if (adapter->closed)
    1468                 :            :                 return -EIO;
    1469                 :            : 
    1470                 :            :         memset(&q_stats, 0, sizeof(q_stats));
    1471                 :          0 :         q_stats.vsi_id = vf->vsi_res->vsi_id;
    1472                 :          0 :         args.ops = VIRTCHNL_OP_GET_STATS;
    1473                 :          0 :         args.in_args = (uint8_t *)&q_stats;
    1474                 :          0 :         args.in_args_size = sizeof(q_stats);
    1475                 :          0 :         args.out_buffer = vf->aq_resp;
    1476                 :          0 :         args.out_size = IAVF_AQ_BUF_SZ;
    1477                 :            : 
    1478                 :          0 :         err = iavf_execute_vf_cmd_safe(adapter, &args, 0);
    1479         [ #  # ]:          0 :         if (err) {
    1480                 :          0 :                 PMD_DRV_LOG(ERR, "fail to execute command OP_GET_STATS");
    1481                 :          0 :                 *pstats = NULL;
    1482                 :          0 :                 return err;
    1483                 :            :         }
    1484                 :          0 :         *pstats = (struct virtchnl_eth_stats *)args.out_buffer;
    1485                 :          0 :         return 0;
    1486                 :            : }
    1487                 :            : 
    1488                 :            : int
    1489                 :          0 : iavf_config_promisc(struct iavf_adapter *adapter,
    1490                 :            :                    bool enable_unicast,
    1491                 :            :                    bool enable_multicast)
    1492                 :            : {
    1493                 :            :         struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(adapter);
    1494                 :            :         struct virtchnl_promisc_info promisc;
    1495                 :            :         struct iavf_cmd_info args;
    1496                 :            :         int err;
    1497                 :            : 
    1498         [ #  # ]:          0 :         if (adapter->closed)
    1499                 :            :                 return -EIO;
    1500                 :            : 
    1501                 :          0 :         promisc.flags = 0;
    1502                 :          0 :         promisc.vsi_id = vf->vsi_res->vsi_id;
    1503                 :            : 
    1504         [ #  # ]:          0 :         if (enable_unicast)
    1505                 :          0 :                 promisc.flags |= FLAG_VF_UNICAST_PROMISC;
    1506                 :            : 
    1507         [ #  # ]:          0 :         if (enable_multicast)
    1508                 :          0 :                 promisc.flags |= FLAG_VF_MULTICAST_PROMISC;
    1509                 :            : 
    1510                 :          0 :         args.ops = VIRTCHNL_OP_CONFIG_PROMISCUOUS_MODE;
    1511                 :          0 :         args.in_args = (uint8_t *)&promisc;
    1512                 :          0 :         args.in_args_size = sizeof(promisc);
    1513                 :          0 :         args.out_buffer = vf->aq_resp;
    1514                 :          0 :         args.out_size = IAVF_AQ_BUF_SZ;
    1515                 :            : 
    1516                 :          0 :         err = iavf_execute_vf_cmd_safe(adapter, &args, 0);
    1517                 :            : 
    1518         [ #  # ]:          0 :         if (err) {
    1519                 :          0 :                 PMD_DRV_LOG(ERR,
    1520                 :            :                             "fail to execute command CONFIG_PROMISCUOUS_MODE");
    1521                 :            : 
    1522         [ #  # ]:          0 :                 if (err == -ENOTSUP)
    1523                 :            :                         return err;
    1524                 :            : 
    1525                 :          0 :                 return -EAGAIN;
    1526                 :            :         }
    1527                 :            : 
    1528                 :          0 :         vf->promisc_unicast_enabled = enable_unicast;
    1529                 :          0 :         vf->promisc_multicast_enabled = enable_multicast;
    1530                 :          0 :         return 0;
    1531                 :            : }
    1532                 :            : 
    1533                 :            : int
    1534                 :          0 : iavf_add_del_eth_addr(struct iavf_adapter *adapter, struct rte_ether_addr *addr,
    1535                 :            :                      bool add, uint8_t type)
    1536                 :            : {
    1537                 :            :         struct virtchnl_ether_addr_list *list;
    1538                 :            :         struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(adapter);
    1539                 :            :         uint8_t cmd_buffer[sizeof(struct virtchnl_ether_addr_list) +
    1540                 :            :                            sizeof(struct virtchnl_ether_addr)];
    1541                 :            :         struct iavf_cmd_info args;
    1542                 :            :         int err;
    1543                 :            : 
    1544         [ #  # ]:          0 :         if (adapter->closed)
    1545                 :            :                 return -EIO;
    1546                 :            : 
    1547                 :            :         list = (struct virtchnl_ether_addr_list *)cmd_buffer;
    1548                 :          0 :         list->vsi_id = vf->vsi_res->vsi_id;
    1549                 :          0 :         list->num_elements = 1;
    1550                 :          0 :         list->list[0].type = type;
    1551         [ #  # ]:          0 :         rte_memcpy(list->list[0].addr, addr->addr_bytes,
    1552                 :            :                    sizeof(addr->addr_bytes));
    1553                 :            : 
    1554         [ #  # ]:          0 :         args.ops = add ? VIRTCHNL_OP_ADD_ETH_ADDR : VIRTCHNL_OP_DEL_ETH_ADDR;
    1555                 :          0 :         args.in_args = cmd_buffer;
    1556                 :          0 :         args.in_args_size = sizeof(cmd_buffer);
    1557                 :          0 :         args.out_buffer = vf->aq_resp;
    1558                 :          0 :         args.out_size = IAVF_AQ_BUF_SZ;
    1559                 :          0 :         err = iavf_execute_vf_cmd_safe(adapter, &args, 0);
    1560         [ #  # ]:          0 :         if (err)
    1561         [ #  # ]:          0 :                 PMD_DRV_LOG(ERR, "fail to execute command %s",
    1562                 :            :                             add ? "OP_ADD_ETH_ADDR" :  "OP_DEL_ETH_ADDR");
    1563                 :            :         return err;
    1564                 :            : }
    1565                 :            : 
    1566                 :            : int
    1567                 :          0 : iavf_add_del_vlan(struct iavf_adapter *adapter, uint16_t vlanid, bool add)
    1568                 :            : {
    1569                 :            :         struct virtchnl_vlan_filter_list *vlan_list;
    1570                 :            :         struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(adapter);
    1571                 :            :         uint8_t cmd_buffer[sizeof(struct virtchnl_vlan_filter_list) +
    1572                 :            :                                                         sizeof(uint16_t)];
    1573                 :            :         struct iavf_cmd_info args;
    1574                 :            :         int err;
    1575                 :            : 
    1576                 :            :         vlan_list = (struct virtchnl_vlan_filter_list *)cmd_buffer;
    1577                 :          0 :         vlan_list->vsi_id = vf->vsi_res->vsi_id;
    1578                 :          0 :         vlan_list->num_elements = 1;
    1579                 :          0 :         vlan_list->vlan_id[0] = vlanid;
    1580                 :            : 
    1581         [ #  # ]:          0 :         args.ops = add ? VIRTCHNL_OP_ADD_VLAN : VIRTCHNL_OP_DEL_VLAN;
    1582                 :          0 :         args.in_args = cmd_buffer;
    1583                 :          0 :         args.in_args_size = sizeof(cmd_buffer);
    1584                 :          0 :         args.out_buffer = vf->aq_resp;
    1585                 :          0 :         args.out_size = IAVF_AQ_BUF_SZ;
    1586                 :          0 :         err = iavf_execute_vf_cmd_safe(adapter, &args, 0);
    1587         [ #  # ]:          0 :         if (err)
    1588         [ #  # ]:          0 :                 PMD_DRV_LOG(ERR, "fail to execute command %s",
    1589                 :            :                             add ? "OP_ADD_VLAN" :  "OP_DEL_VLAN");
    1590                 :            : 
    1591                 :          0 :         return err;
    1592                 :            : }
    1593                 :            : 
    1594                 :            : int
    1595                 :          0 : iavf_fdir_add(struct iavf_adapter *adapter,
    1596                 :            :         struct iavf_fdir_conf *filter)
    1597                 :            : {
    1598                 :            :         struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(adapter);
    1599                 :            :         struct virtchnl_fdir_add *fdir_ret;
    1600                 :            : 
    1601                 :            :         struct iavf_cmd_info args;
    1602                 :            :         int err;
    1603                 :            : 
    1604                 :          0 :         filter->add_fltr.vsi_id = vf->vsi_res->vsi_id;
    1605                 :          0 :         filter->add_fltr.validate_only = 0;
    1606                 :            : 
    1607                 :          0 :         args.ops = VIRTCHNL_OP_ADD_FDIR_FILTER;
    1608                 :          0 :         args.in_args = (uint8_t *)(&filter->add_fltr);
    1609                 :          0 :         args.in_args_size = sizeof(*(&filter->add_fltr));
    1610                 :          0 :         args.out_buffer = vf->aq_resp;
    1611                 :          0 :         args.out_size = IAVF_AQ_BUF_SZ;
    1612                 :            : 
    1613                 :          0 :         err = iavf_execute_vf_cmd_safe(adapter, &args, 0);
    1614         [ #  # ]:          0 :         if (err) {
    1615                 :          0 :                 PMD_DRV_LOG(ERR, "fail to execute command OP_ADD_FDIR_FILTER");
    1616                 :          0 :                 return err;
    1617                 :            :         }
    1618                 :            : 
    1619                 :          0 :         fdir_ret = (struct virtchnl_fdir_add *)args.out_buffer;
    1620                 :          0 :         filter->flow_id = fdir_ret->flow_id;
    1621                 :            : 
    1622         [ #  # ]:          0 :         if (fdir_ret->status == VIRTCHNL_FDIR_SUCCESS) {
    1623                 :          0 :                 PMD_DRV_LOG(INFO,
    1624                 :            :                         "Succeed in adding rule request by PF");
    1625                 :            :         } else if (fdir_ret->status == VIRTCHNL_FDIR_FAILURE_RULE_NORESOURCE) {
    1626                 :          0 :                 PMD_DRV_LOG(ERR,
    1627                 :            :                         "Failed to add rule request due to no hw resource");
    1628                 :          0 :                 return -1;
    1629                 :            :         } else if (fdir_ret->status == VIRTCHNL_FDIR_FAILURE_RULE_EXIST) {
    1630                 :          0 :                 PMD_DRV_LOG(ERR,
    1631                 :            :                         "Failed to add rule request due to the rule is already existed");
    1632                 :          0 :                 return -1;
    1633                 :            :         } else if (fdir_ret->status == VIRTCHNL_FDIR_FAILURE_RULE_CONFLICT) {
    1634                 :          0 :                 PMD_DRV_LOG(ERR,
    1635                 :            :                         "Failed to add rule request due to the rule is conflict with existing rule");
    1636                 :          0 :                 return -1;
    1637                 :            :         } else if (fdir_ret->status == VIRTCHNL_FDIR_FAILURE_RULE_INVALID) {
    1638                 :          0 :                 PMD_DRV_LOG(ERR,
    1639                 :            :                         "Failed to add rule request due to the hw doesn't support");
    1640                 :          0 :                 return -1;
    1641                 :            :         } else if (fdir_ret->status == VIRTCHNL_FDIR_FAILURE_RULE_TIMEOUT) {
    1642                 :          0 :                 PMD_DRV_LOG(ERR,
    1643                 :            :                         "Failed to add rule request due to time out for programming");
    1644                 :          0 :                 return -1;
    1645                 :            :         } else {
    1646                 :          0 :                 PMD_DRV_LOG(ERR,
    1647                 :            :                         "Failed to add rule request due to other reasons");
    1648                 :          0 :                 return -1;
    1649                 :            :         }
    1650                 :            : 
    1651                 :          0 :         return 0;
    1652                 :            : };
    1653                 :            : 
    1654                 :            : int
    1655                 :          0 : iavf_fdir_del(struct iavf_adapter *adapter,
    1656                 :            :         struct iavf_fdir_conf *filter)
    1657                 :            : {
    1658                 :            :         struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(adapter);
    1659                 :            :         struct virtchnl_fdir_del *fdir_ret;
    1660                 :            : 
    1661                 :            :         struct iavf_cmd_info args;
    1662                 :            :         int err;
    1663                 :            : 
    1664                 :          0 :         filter->del_fltr.vsi_id = vf->vsi_res->vsi_id;
    1665                 :          0 :         filter->del_fltr.flow_id = filter->flow_id;
    1666                 :            : 
    1667                 :          0 :         args.ops = VIRTCHNL_OP_DEL_FDIR_FILTER;
    1668                 :          0 :         args.in_args = (uint8_t *)(&filter->del_fltr);
    1669                 :          0 :         args.in_args_size = sizeof(filter->del_fltr);
    1670                 :          0 :         args.out_buffer = vf->aq_resp;
    1671                 :          0 :         args.out_size = IAVF_AQ_BUF_SZ;
    1672                 :            : 
    1673                 :          0 :         err = iavf_execute_vf_cmd_safe(adapter, &args, 0);
    1674         [ #  # ]:          0 :         if (err) {
    1675                 :          0 :                 PMD_DRV_LOG(ERR, "fail to execute command OP_DEL_FDIR_FILTER");
    1676                 :          0 :                 return err;
    1677                 :            :         }
    1678                 :            : 
    1679                 :          0 :         fdir_ret = (struct virtchnl_fdir_del *)args.out_buffer;
    1680                 :            : 
    1681         [ #  # ]:          0 :         if (fdir_ret->status == VIRTCHNL_FDIR_SUCCESS) {
    1682                 :          0 :                 PMD_DRV_LOG(INFO,
    1683                 :            :                         "Succeed in deleting rule request by PF");
    1684         [ #  # ]:          0 :         } else if (fdir_ret->status == VIRTCHNL_FDIR_FAILURE_RULE_NONEXIST) {
    1685                 :          0 :                 PMD_DRV_LOG(ERR,
    1686                 :            :                         "Failed to delete rule request due to this rule doesn't exist");
    1687                 :          0 :                 return -1;
    1688         [ #  # ]:          0 :         } else if (fdir_ret->status == VIRTCHNL_FDIR_FAILURE_RULE_TIMEOUT) {
    1689                 :          0 :                 PMD_DRV_LOG(ERR,
    1690                 :            :                         "Failed to delete rule request due to time out for programming");
    1691                 :          0 :                 return -1;
    1692                 :            :         } else {
    1693                 :          0 :                 PMD_DRV_LOG(ERR,
    1694                 :            :                         "Failed to delete rule request due to other reasons");
    1695                 :          0 :                 return -1;
    1696                 :            :         }
    1697                 :            : 
    1698                 :          0 :         return 0;
    1699                 :            : };
    1700                 :            : 
    1701                 :            : int
    1702                 :          0 : iavf_fdir_check(struct iavf_adapter *adapter,
    1703                 :            :                 struct iavf_fdir_conf *filter)
    1704                 :            : {
    1705                 :            :         struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(adapter);
    1706                 :            :         struct virtchnl_fdir_add *fdir_ret;
    1707                 :            : 
    1708                 :            :         struct iavf_cmd_info args;
    1709                 :            :         int err;
    1710                 :            : 
    1711                 :          0 :         filter->add_fltr.vsi_id = vf->vsi_res->vsi_id;
    1712                 :          0 :         filter->add_fltr.validate_only = 1;
    1713                 :            : 
    1714                 :          0 :         args.ops = VIRTCHNL_OP_ADD_FDIR_FILTER;
    1715                 :          0 :         args.in_args = (uint8_t *)(&filter->add_fltr);
    1716                 :          0 :         args.in_args_size = sizeof(*(&filter->add_fltr));
    1717                 :          0 :         args.out_buffer = vf->aq_resp;
    1718                 :          0 :         args.out_size = IAVF_AQ_BUF_SZ;
    1719                 :            : 
    1720                 :          0 :         err = iavf_execute_vf_cmd_safe(adapter, &args, 0);
    1721         [ #  # ]:          0 :         if (err) {
    1722                 :          0 :                 PMD_DRV_LOG(ERR, "fail to check flow director rule");
    1723                 :          0 :                 return err;
    1724                 :            :         }
    1725                 :            : 
    1726                 :          0 :         fdir_ret = (struct virtchnl_fdir_add *)args.out_buffer;
    1727                 :            : 
    1728         [ #  # ]:          0 :         if (fdir_ret->status == VIRTCHNL_FDIR_SUCCESS) {
    1729                 :          0 :                 PMD_DRV_LOG(INFO,
    1730                 :            :                         "Succeed in checking rule request by PF");
    1731         [ #  # ]:          0 :         } else if (fdir_ret->status == VIRTCHNL_FDIR_FAILURE_RULE_INVALID) {
    1732                 :          0 :                 PMD_DRV_LOG(ERR,
    1733                 :            :                         "Failed to check rule request due to parameters validation"
    1734                 :            :                         " or HW doesn't support");
    1735                 :            :                 err = -1;
    1736                 :            :         } else {
    1737                 :          0 :                 PMD_DRV_LOG(ERR,
    1738                 :            :                         "Failed to check rule request due to other reasons");
    1739                 :            :                 err =  -1;
    1740                 :            :         }
    1741                 :            : 
    1742                 :            :         return err;
    1743                 :            : }
    1744                 :            : 
    1745                 :            : int
    1746                 :          0 : iavf_flow_sub(struct iavf_adapter *adapter, struct iavf_fsub_conf *filter)
    1747                 :            : {
    1748                 :            :         struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(adapter);
    1749                 :            :         struct virtchnl_flow_sub *fsub_cfg;
    1750                 :            :         struct iavf_cmd_info args;
    1751                 :            :         int err;
    1752                 :            : 
    1753                 :          0 :         filter->sub_fltr.vsi_id = vf->vsi_res->vsi_id;
    1754                 :          0 :         filter->sub_fltr.validate_only = 0;
    1755                 :            : 
    1756                 :            :         memset(&args, 0, sizeof(args));
    1757                 :          0 :         args.ops = VIRTCHNL_OP_FLOW_SUBSCRIBE;
    1758                 :          0 :         args.in_args = (uint8_t *)(&filter->sub_fltr);
    1759                 :          0 :         args.in_args_size = sizeof(*(&filter->sub_fltr));
    1760                 :          0 :         args.out_buffer = vf->aq_resp;
    1761                 :          0 :         args.out_size = IAVF_AQ_BUF_SZ;
    1762                 :            : 
    1763                 :          0 :         err = iavf_execute_vf_cmd_safe(adapter, &args, 0);
    1764         [ #  # ]:          0 :         if (err) {
    1765                 :          0 :                 PMD_DRV_LOG(ERR, "Failed to execute command of "
    1766                 :            :                                  "OP_FLOW_SUBSCRIBE");
    1767                 :          0 :                 return err;
    1768                 :            :         }
    1769                 :            : 
    1770                 :          0 :         fsub_cfg = (struct virtchnl_flow_sub *)args.out_buffer;
    1771                 :          0 :         filter->flow_id = fsub_cfg->flow_id;
    1772                 :            : 
    1773         [ #  # ]:          0 :         if (fsub_cfg->status == VIRTCHNL_FSUB_SUCCESS) {
    1774                 :          0 :                 PMD_DRV_LOG(INFO, "Succeed in adding rule request by PF");
    1775         [ #  # ]:          0 :         } else if (fsub_cfg->status == VIRTCHNL_FSUB_FAILURE_RULE_NORESOURCE) {
    1776                 :          0 :                 PMD_DRV_LOG(ERR, "Failed to add rule request due to no hw "
    1777                 :            :                                  "resource");
    1778                 :            :                 err = -1;
    1779         [ #  # ]:          0 :         } else if (fsub_cfg->status == VIRTCHNL_FSUB_FAILURE_RULE_EXIST) {
    1780                 :          0 :                 PMD_DRV_LOG(ERR, "Failed to add rule request due to the rule "
    1781                 :            :                                  "is already existed");
    1782                 :            :                 err = -1;
    1783         [ #  # ]:          0 :         } else if (fsub_cfg->status == VIRTCHNL_FSUB_FAILURE_RULE_INVALID) {
    1784                 :          0 :                 PMD_DRV_LOG(ERR, "Failed to add rule request due to the hw "
    1785                 :            :                                  "doesn't support");
    1786                 :            :                 err = -1;
    1787                 :            :         } else {
    1788                 :          0 :                 PMD_DRV_LOG(ERR, "Failed to add rule request due to other "
    1789                 :            :                                  "reasons");
    1790                 :            :                 err = -1;
    1791                 :            :         }
    1792                 :            : 
    1793                 :            :         return err;
    1794                 :            : }
    1795                 :            : 
    1796                 :            : int
    1797                 :          0 : iavf_flow_unsub(struct iavf_adapter *adapter, struct iavf_fsub_conf *filter)
    1798                 :            : {
    1799                 :            :         struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(adapter);
    1800                 :            :         struct virtchnl_flow_unsub *unsub_cfg;
    1801                 :            :         struct iavf_cmd_info args;
    1802                 :            :         int err;
    1803                 :            : 
    1804                 :          0 :         filter->unsub_fltr.vsi_id = vf->vsi_res->vsi_id;
    1805                 :          0 :         filter->unsub_fltr.flow_id = filter->flow_id;
    1806                 :            : 
    1807                 :            :         memset(&args, 0, sizeof(args));
    1808                 :          0 :         args.ops = VIRTCHNL_OP_FLOW_UNSUBSCRIBE;
    1809                 :          0 :         args.in_args = (uint8_t *)(&filter->unsub_fltr);
    1810                 :          0 :         args.in_args_size = sizeof(filter->unsub_fltr);
    1811                 :          0 :         args.out_buffer = vf->aq_resp;
    1812                 :          0 :         args.out_size = IAVF_AQ_BUF_SZ;
    1813                 :            : 
    1814                 :          0 :         err = iavf_execute_vf_cmd_safe(adapter, &args, 0);
    1815         [ #  # ]:          0 :         if (err) {
    1816                 :          0 :                 PMD_DRV_LOG(ERR, "Failed to execute command of "
    1817                 :            :                                  "OP_FLOW_UNSUBSCRIBE");
    1818                 :          0 :                 return err;
    1819                 :            :         }
    1820                 :            : 
    1821                 :          0 :         unsub_cfg = (struct virtchnl_flow_unsub *)args.out_buffer;
    1822                 :            : 
    1823         [ #  # ]:          0 :         if (unsub_cfg->status == VIRTCHNL_FSUB_SUCCESS) {
    1824                 :          0 :                 PMD_DRV_LOG(INFO, "Succeed in deleting rule request by PF");
    1825         [ #  # ]:          0 :         } else if (unsub_cfg->status == VIRTCHNL_FSUB_FAILURE_RULE_NONEXIST) {
    1826                 :          0 :                 PMD_DRV_LOG(ERR, "Failed to delete rule request due to this "
    1827                 :            :                                  "rule doesn't exist");
    1828                 :            :                 err = -1;
    1829                 :            :         } else {
    1830                 :          0 :                 PMD_DRV_LOG(ERR, "Failed to delete rule request due to other "
    1831                 :            :                                  "reasons");
    1832                 :            :                 err = -1;
    1833                 :            :         }
    1834                 :            : 
    1835                 :            :         return err;
    1836                 :            : }
    1837                 :            : 
    1838                 :            : int
    1839                 :          0 : iavf_flow_sub_check(struct iavf_adapter *adapter,
    1840                 :            :                     struct iavf_fsub_conf *filter)
    1841                 :            : {
    1842                 :            :         struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(adapter);
    1843                 :            :         struct virtchnl_flow_sub *fsub_cfg;
    1844                 :            : 
    1845                 :            :         struct iavf_cmd_info args;
    1846                 :            :         int err;
    1847                 :            : 
    1848                 :          0 :         filter->sub_fltr.vsi_id = vf->vsi_res->vsi_id;
    1849                 :          0 :         filter->sub_fltr.validate_only = 1;
    1850                 :            : 
    1851                 :          0 :         args.ops = VIRTCHNL_OP_FLOW_SUBSCRIBE;
    1852                 :          0 :         args.in_args = (uint8_t *)(&filter->sub_fltr);
    1853                 :          0 :         args.in_args_size = sizeof(*(&filter->sub_fltr));
    1854                 :          0 :         args.out_buffer = vf->aq_resp;
    1855                 :          0 :         args.out_size = IAVF_AQ_BUF_SZ;
    1856                 :            : 
    1857                 :          0 :         err = iavf_execute_vf_cmd_safe(adapter, &args, 0);
    1858         [ #  # ]:          0 :         if (err) {
    1859                 :          0 :                 PMD_DRV_LOG(ERR, "Failed to check flow subscription rule");
    1860                 :          0 :                 return err;
    1861                 :            :         }
    1862                 :            : 
    1863                 :          0 :         fsub_cfg = (struct virtchnl_flow_sub *)args.out_buffer;
    1864                 :            : 
    1865         [ #  # ]:          0 :         if (fsub_cfg->status == VIRTCHNL_FSUB_SUCCESS) {
    1866                 :          0 :                 PMD_DRV_LOG(INFO, "Succeed in checking rule request by PF");
    1867         [ #  # ]:          0 :         } else if (fsub_cfg->status == VIRTCHNL_FSUB_FAILURE_RULE_INVALID) {
    1868                 :          0 :                 PMD_DRV_LOG(ERR, "Failed to check rule request due to "
    1869                 :            :                                  "parameters validation or HW doesn't "
    1870                 :            :                                  "support");
    1871                 :            :                 err = -1;
    1872                 :            :         } else {
    1873                 :          0 :                 PMD_DRV_LOG(ERR, "Failed to check rule request due to other "
    1874                 :            :                                  "reasons");
    1875                 :            :                 err = -1;
    1876                 :            :         }
    1877                 :            : 
    1878                 :            :         return err;
    1879                 :            : }
    1880                 :            : 
    1881                 :            : int
    1882         [ #  # ]:          0 : iavf_add_del_rss_cfg(struct iavf_adapter *adapter,
    1883                 :            :                      struct virtchnl_rss_cfg *rss_cfg, bool add)
    1884                 :            : {
    1885                 :            :         struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(adapter);
    1886                 :            :         struct iavf_cmd_info args;
    1887                 :            :         int err;
    1888                 :            : 
    1889                 :            :         memset(&args, 0, sizeof(args));
    1890         [ #  # ]:          0 :         args.ops = add ? VIRTCHNL_OP_ADD_RSS_CFG :
    1891                 :            :                 VIRTCHNL_OP_DEL_RSS_CFG;
    1892                 :          0 :         args.in_args = (u8 *)rss_cfg;
    1893                 :          0 :         args.in_args_size = sizeof(*rss_cfg);
    1894                 :          0 :         args.out_buffer = vf->aq_resp;
    1895                 :          0 :         args.out_size = IAVF_AQ_BUF_SZ;
    1896                 :            : 
    1897                 :          0 :         err = iavf_execute_vf_cmd_safe(adapter, &args, 0);
    1898         [ #  # ]:          0 :         if (err)
    1899         [ #  # ]:          0 :                 PMD_DRV_LOG(ERR,
    1900                 :            :                             "Failed to execute command of %s",
    1901                 :            :                             add ? "OP_ADD_RSS_CFG" :
    1902                 :            :                             "OP_DEL_RSS_INPUT_CFG");
    1903                 :            : 
    1904                 :          0 :         return err;
    1905                 :            : }
    1906                 :            : 
    1907                 :            : int
    1908                 :          0 : iavf_get_hena_caps(struct iavf_adapter *adapter, uint64_t *caps)
    1909                 :            : {
    1910                 :            :         struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(adapter);
    1911                 :            :         struct iavf_cmd_info args;
    1912                 :            :         int err;
    1913                 :            : 
    1914                 :          0 :         args.ops = VIRTCHNL_OP_GET_RSS_HENA_CAPS;
    1915                 :          0 :         args.in_args = NULL;
    1916                 :          0 :         args.in_args_size = 0;
    1917                 :          0 :         args.out_buffer = vf->aq_resp;
    1918                 :          0 :         args.out_size = IAVF_AQ_BUF_SZ;
    1919                 :            : 
    1920                 :          0 :         err = iavf_execute_vf_cmd_safe(adapter, &args, 0);
    1921         [ #  # ]:          0 :         if (err) {
    1922                 :          0 :                 PMD_DRV_LOG(ERR,
    1923                 :            :                             "Failed to execute command of OP_GET_RSS_HENA_CAPS");
    1924                 :          0 :                 return err;
    1925                 :            :         }
    1926                 :            : 
    1927                 :          0 :         *caps = ((struct virtchnl_rss_hena *)args.out_buffer)->hena;
    1928                 :          0 :         return 0;
    1929                 :            : }
    1930                 :            : 
    1931                 :            : int
    1932                 :          0 : iavf_set_hena(struct iavf_adapter *adapter, uint64_t hena)
    1933                 :            : {
    1934                 :            :         struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(adapter);
    1935                 :            :         struct virtchnl_rss_hena vrh;
    1936                 :            :         struct iavf_cmd_info args;
    1937                 :            :         int err;
    1938                 :            : 
    1939                 :          0 :         vrh.hena = hena;
    1940                 :          0 :         args.ops = VIRTCHNL_OP_SET_RSS_HENA;
    1941                 :          0 :         args.in_args = (u8 *)&vrh;
    1942                 :          0 :         args.in_args_size = sizeof(vrh);
    1943                 :          0 :         args.out_buffer = vf->aq_resp;
    1944                 :          0 :         args.out_size = IAVF_AQ_BUF_SZ;
    1945                 :            : 
    1946                 :          0 :         err = iavf_execute_vf_cmd_safe(adapter, &args, 0);
    1947         [ #  # ]:          0 :         if (err)
    1948                 :          0 :                 PMD_DRV_LOG(ERR,
    1949                 :            :                             "Failed to execute command of OP_SET_RSS_HENA");
    1950                 :            : 
    1951                 :          0 :         return err;
    1952                 :            : }
    1953                 :            : 
    1954                 :            : int
    1955                 :          0 : iavf_get_qos_cap(struct iavf_adapter *adapter)
    1956                 :            : {
    1957                 :            :         struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(adapter);
    1958                 :            :         struct iavf_cmd_info args;
    1959                 :            :         uint32_t len;
    1960                 :            :         int err;
    1961                 :            : 
    1962                 :          0 :         args.ops = VIRTCHNL_OP_GET_QOS_CAPS;
    1963                 :          0 :         args.in_args = NULL;
    1964                 :          0 :         args.in_args_size = 0;
    1965                 :          0 :         args.out_buffer = vf->aq_resp;
    1966                 :          0 :         args.out_size = IAVF_AQ_BUF_SZ;
    1967                 :          0 :         err = iavf_execute_vf_cmd_safe(adapter, &args, 0);
    1968                 :            : 
    1969         [ #  # ]:          0 :         if (err) {
    1970                 :          0 :                 PMD_DRV_LOG(ERR,
    1971                 :            :                             "Failed to execute command of OP_GET_VF_RESOURCE");
    1972                 :          0 :                 return -1;
    1973                 :            :         }
    1974                 :            : 
    1975                 :            :         len =  sizeof(struct virtchnl_qos_cap_list) +
    1976                 :            :                 IAVF_MAX_TRAFFIC_CLASS * sizeof(struct virtchnl_qos_cap_elem);
    1977                 :            : 
    1978                 :          0 :         rte_memcpy(vf->qos_cap, args.out_buffer,
    1979         [ #  # ]:          0 :                    RTE_MIN(args.out_size, len));
    1980                 :            : 
    1981                 :            :         return 0;
    1982                 :            : }
    1983                 :            : 
    1984                 :          0 : int iavf_set_q_tc_map(struct rte_eth_dev *dev,
    1985                 :            :                 struct virtchnl_queue_tc_mapping *q_tc_mapping, uint16_t size)
    1986                 :            : {
    1987                 :          0 :         struct iavf_adapter *adapter =
    1988                 :          0 :                         IAVF_DEV_PRIVATE_TO_ADAPTER(dev->data->dev_private);
    1989                 :            :         struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(dev->data->dev_private);
    1990                 :            :         struct iavf_cmd_info args;
    1991                 :            :         int err;
    1992                 :            : 
    1993                 :            :         memset(&args, 0, sizeof(args));
    1994                 :          0 :         args.ops = VIRTCHNL_OP_CONFIG_QUEUE_TC_MAP;
    1995                 :          0 :         args.in_args = (uint8_t *)q_tc_mapping;
    1996                 :          0 :         args.in_args_size = size;
    1997                 :          0 :         args.out_buffer = vf->aq_resp;
    1998                 :          0 :         args.out_size = IAVF_AQ_BUF_SZ;
    1999                 :            : 
    2000                 :          0 :         err = iavf_execute_vf_cmd_safe(adapter, &args, 0);
    2001         [ #  # ]:          0 :         if (err)
    2002                 :          0 :                 PMD_DRV_LOG(ERR, "Failed to execute command of"
    2003                 :            :                             " VIRTCHNL_OP_CONFIG_TC_MAP");
    2004                 :          0 :         return err;
    2005                 :            : }
    2006                 :            : 
    2007                 :          0 : int iavf_set_q_bw(struct rte_eth_dev *dev,
    2008                 :            :                 struct virtchnl_queues_bw_cfg *q_bw, uint16_t size)
    2009                 :            : {
    2010                 :          0 :         struct iavf_adapter *adapter =
    2011                 :          0 :                         IAVF_DEV_PRIVATE_TO_ADAPTER(dev->data->dev_private);
    2012                 :            :         struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(dev->data->dev_private);
    2013                 :            :         struct iavf_cmd_info args;
    2014                 :            :         int err;
    2015                 :            : 
    2016                 :            :         memset(&args, 0, sizeof(args));
    2017                 :          0 :         args.ops = VIRTCHNL_OP_CONFIG_QUEUE_BW;
    2018                 :          0 :         args.in_args = (uint8_t *)q_bw;
    2019                 :          0 :         args.in_args_size = size;
    2020                 :          0 :         args.out_buffer = vf->aq_resp;
    2021                 :          0 :         args.out_size = IAVF_AQ_BUF_SZ;
    2022                 :            : 
    2023                 :          0 :         err = iavf_execute_vf_cmd_safe(adapter, &args, 0);
    2024         [ #  # ]:          0 :         if (err)
    2025                 :          0 :                 PMD_DRV_LOG(ERR, "Failed to execute command of"
    2026                 :            :                             " VIRTCHNL_OP_CONFIG_QUEUE_BW");
    2027                 :          0 :         return err;
    2028                 :            : }
    2029                 :            : 
    2030                 :            : int
    2031                 :          0 : iavf_add_del_mc_addr_list(struct iavf_adapter *adapter,
    2032                 :            :                         struct rte_ether_addr *mc_addrs,
    2033                 :            :                         uint32_t mc_addrs_num, bool add)
    2034                 :            : {
    2035                 :            :         struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(adapter);
    2036                 :            :         uint8_t cmd_buffer[sizeof(struct virtchnl_ether_addr_list) +
    2037                 :            :                 (IAVF_NUM_MACADDR_MAX * sizeof(struct virtchnl_ether_addr))];
    2038                 :            :         struct virtchnl_ether_addr_list *list;
    2039                 :            :         struct iavf_cmd_info args;
    2040                 :            :         uint32_t i;
    2041                 :            :         int err;
    2042                 :            : 
    2043         [ #  # ]:          0 :         if (mc_addrs == NULL || mc_addrs_num == 0)
    2044                 :            :                 return 0;
    2045                 :            : 
    2046                 :            :         list = (struct virtchnl_ether_addr_list *)cmd_buffer;
    2047                 :          0 :         list->vsi_id = vf->vsi_res->vsi_id;
    2048                 :          0 :         list->num_elements = mc_addrs_num;
    2049                 :            : 
    2050         [ #  # ]:          0 :         for (i = 0; i < mc_addrs_num; i++) {
    2051         [ #  # ]:          0 :                 if (!IAVF_IS_MULTICAST(mc_addrs[i].addr_bytes)) {
    2052                 :          0 :                         PMD_DRV_LOG(ERR, "Invalid mac:" RTE_ETHER_ADDR_PRT_FMT,
    2053                 :            :                                     RTE_ETHER_ADDR_BYTES(&mc_addrs[i]));
    2054                 :          0 :                         return -EINVAL;
    2055                 :            :                 }
    2056                 :            : 
    2057                 :          0 :                 memcpy(list->list[i].addr, mc_addrs[i].addr_bytes,
    2058                 :            :                         sizeof(list->list[i].addr));
    2059                 :          0 :                 list->list[i].type = VIRTCHNL_ETHER_ADDR_EXTRA;
    2060                 :            :         }
    2061                 :            : 
    2062         [ #  # ]:          0 :         args.ops = add ? VIRTCHNL_OP_ADD_ETH_ADDR : VIRTCHNL_OP_DEL_ETH_ADDR;
    2063                 :          0 :         args.in_args = cmd_buffer;
    2064                 :          0 :         args.in_args_size = sizeof(struct virtchnl_ether_addr_list) +
    2065                 :          0 :                 i * sizeof(struct virtchnl_ether_addr);
    2066                 :          0 :         args.out_buffer = vf->aq_resp;
    2067                 :          0 :         args.out_size = IAVF_AQ_BUF_SZ;
    2068                 :          0 :         err = iavf_execute_vf_cmd_safe(adapter, &args, 0);
    2069                 :            : 
    2070         [ #  # ]:          0 :         if (err) {
    2071         [ #  # ]:          0 :                 PMD_DRV_LOG(ERR, "fail to execute command %s",
    2072                 :            :                         add ? "OP_ADD_ETH_ADDR" : "OP_DEL_ETH_ADDR");
    2073                 :          0 :                 return err;
    2074                 :            :         }
    2075                 :            : 
    2076                 :            :         return 0;
    2077                 :            : }
    2078                 :            : 
    2079                 :            : int
    2080                 :          0 : iavf_request_queues(struct rte_eth_dev *dev, uint16_t num)
    2081                 :            : {
    2082                 :          0 :         struct iavf_adapter *adapter =
    2083                 :          0 :                 IAVF_DEV_PRIVATE_TO_ADAPTER(dev->data->dev_private);
    2084                 :            :         struct iavf_info *vf =  IAVF_DEV_PRIVATE_TO_VF(adapter);
    2085                 :            :         struct virtchnl_vf_res_request vfres;
    2086                 :            :         struct iavf_cmd_info args;
    2087                 :            :         uint16_t num_queue_pairs;
    2088                 :            :         int err;
    2089                 :            :         int i = 0;
    2090                 :            : 
    2091         [ #  # ]:          0 :         if (!(vf->vf_res->vf_cap_flags &
    2092                 :            :                 VIRTCHNL_VF_OFFLOAD_REQ_QUEUES)) {
    2093                 :          0 :                 PMD_DRV_LOG(ERR, "request queues not supported");
    2094                 :          0 :                 return -1;
    2095                 :            :         }
    2096                 :            : 
    2097         [ #  # ]:          0 :         if (num == 0) {
    2098                 :          0 :                 PMD_DRV_LOG(ERR, "queue number cannot be zero");
    2099                 :          0 :                 return -1;
    2100                 :            :         }
    2101                 :          0 :         vfres.num_queue_pairs = num;
    2102                 :            : 
    2103                 :          0 :         args.ops = VIRTCHNL_OP_REQUEST_QUEUES;
    2104                 :          0 :         args.in_args = (u8 *)&vfres;
    2105                 :          0 :         args.in_args_size = sizeof(vfres);
    2106                 :          0 :         args.out_buffer = vf->aq_resp;
    2107                 :          0 :         args.out_size = IAVF_AQ_BUF_SZ;
    2108                 :            : 
    2109         [ #  # ]:          0 :         if (vf->vf_res->vf_cap_flags & VIRTCHNL_VF_OFFLOAD_WB_ON_ITR) {
    2110                 :          0 :                 err = iavf_execute_vf_cmd_safe(adapter, &args, 0);
    2111                 :            :         } else {
    2112                 :          0 :                 rte_eal_alarm_cancel(iavf_dev_alarm_handler, dev);
    2113                 :          0 :                 err = iavf_execute_vf_cmd_safe(adapter, &args, 0);
    2114                 :          0 :                 rte_eal_alarm_set(IAVF_ALARM_INTERVAL,
    2115                 :            :                                   iavf_dev_alarm_handler, dev);
    2116                 :            :         }
    2117                 :            : 
    2118         [ #  # ]:          0 :         if (err) {
    2119                 :          0 :                 PMD_DRV_LOG(ERR, "fail to execute command OP_REQUEST_QUEUES");
    2120                 :          0 :                 return err;
    2121                 :            :         }
    2122                 :            : 
    2123                 :            :         /* wait for interrupt notification vf is resetting */
    2124         [ #  # ]:          0 :         while (i++ < MAX_TRY_TIMES) {
    2125         [ #  # ]:          0 :                 if (vf->vf_reset)
    2126                 :            :                         break;
    2127                 :          0 :                 iavf_msec_delay(ASQ_DELAY_MS);
    2128                 :            :         }
    2129                 :            : 
    2130                 :            :         /* request queues succeeded, vf is resetting */
    2131         [ #  # ]:          0 :         if (vf->vf_reset) {
    2132                 :          0 :                 PMD_DRV_LOG(INFO, "vf is resetting");
    2133                 :          0 :                 return 0;
    2134                 :            :         }
    2135                 :            : 
    2136                 :            :         /* request additional queues failed, return available number */
    2137                 :          0 :         num_queue_pairs =
    2138                 :          0 :           ((struct virtchnl_vf_res_request *)args.out_buffer)->num_queue_pairs;
    2139                 :          0 :         PMD_DRV_LOG(ERR, "request queues failed, only %u queues "
    2140                 :            :                 "available", num_queue_pairs);
    2141                 :            : 
    2142                 :          0 :         return -1;
    2143                 :            : }
    2144                 :            : 
    2145                 :            : int
    2146                 :          0 : iavf_get_max_rss_queue_region(struct iavf_adapter *adapter)
    2147                 :            : {
    2148                 :            :         struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(adapter);
    2149                 :            :         struct iavf_cmd_info args;
    2150                 :            :         uint16_t qregion_width;
    2151                 :            :         int err;
    2152                 :            : 
    2153                 :          0 :         args.ops = VIRTCHNL_OP_GET_MAX_RSS_QREGION;
    2154                 :          0 :         args.in_args = NULL;
    2155                 :          0 :         args.in_args_size = 0;
    2156                 :          0 :         args.out_buffer = vf->aq_resp;
    2157                 :          0 :         args.out_size = IAVF_AQ_BUF_SZ;
    2158                 :            : 
    2159                 :          0 :         err = iavf_execute_vf_cmd_safe(adapter, &args, 0);
    2160         [ #  # ]:          0 :         if (err) {
    2161                 :          0 :                 PMD_DRV_LOG(ERR, "Failed to execute command of VIRTCHNL_OP_GET_MAX_RSS_QREGION");
    2162                 :          0 :                 return err;
    2163                 :            :         }
    2164                 :            : 
    2165                 :          0 :         qregion_width =
    2166                 :          0 :         ((struct virtchnl_max_rss_qregion *)args.out_buffer)->qregion_width;
    2167                 :            : 
    2168                 :          0 :         vf->max_rss_qregion = (uint16_t)(1 << qregion_width);
    2169                 :            : 
    2170                 :          0 :         return 0;
    2171                 :            : }
    2172                 :            : 
    2173                 :            : 
    2174                 :            : 
    2175                 :            : int
    2176                 :          0 : iavf_ipsec_crypto_request(struct iavf_adapter *adapter,
    2177                 :            :                 uint8_t *msg, size_t msg_len,
    2178                 :            :                 uint8_t *resp_msg, size_t resp_msg_len)
    2179                 :            : {
    2180                 :            :         struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(adapter);
    2181                 :            :         struct iavf_cmd_info args;
    2182                 :            :         int err;
    2183                 :            : 
    2184                 :          0 :         args.ops = VIRTCHNL_OP_INLINE_IPSEC_CRYPTO;
    2185                 :          0 :         args.in_args = msg;
    2186                 :          0 :         args.in_args_size = msg_len;
    2187                 :          0 :         args.out_buffer = vf->aq_resp;
    2188                 :          0 :         args.out_size = IAVF_AQ_BUF_SZ;
    2189                 :            : 
    2190                 :          0 :         err = iavf_execute_vf_cmd_safe(adapter, &args, 1);
    2191         [ #  # ]:          0 :         if (err) {
    2192                 :          0 :                 PMD_DRV_LOG(ERR, "fail to execute command %s",
    2193                 :            :                                 "OP_INLINE_IPSEC_CRYPTO");
    2194                 :          0 :                 return err;
    2195                 :            :         }
    2196                 :            : 
    2197                 :          0 :         memcpy(resp_msg, args.out_buffer, resp_msg_len);
    2198                 :            : 
    2199                 :          0 :         return 0;
    2200                 :            : }
    2201                 :            : 
    2202                 :            : int
    2203                 :          0 : iavf_set_vf_quanta_size(struct iavf_adapter *adapter, u16 start_queue_id, u16 num_queues)
    2204                 :            : {
    2205                 :            :         struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(adapter);
    2206                 :            :         struct iavf_cmd_info args;
    2207                 :            :         struct virtchnl_quanta_cfg q_quanta;
    2208                 :            :         int err;
    2209                 :            : 
    2210         [ #  # ]:          0 :         if (adapter->devargs.quanta_size == 0)
    2211                 :            :                 return 0;
    2212                 :            : 
    2213                 :          0 :         q_quanta.quanta_size = adapter->devargs.quanta_size;
    2214                 :          0 :         q_quanta.queue_select.type = VIRTCHNL_QUEUE_TYPE_TX;
    2215                 :          0 :         q_quanta.queue_select.start_queue_id = start_queue_id;
    2216                 :          0 :         q_quanta.queue_select.num_queues = num_queues;
    2217                 :            : 
    2218                 :          0 :         args.ops = VIRTCHNL_OP_CONFIG_QUANTA;
    2219                 :          0 :         args.in_args = (uint8_t *)&q_quanta;
    2220                 :          0 :         args.in_args_size = sizeof(q_quanta);
    2221                 :          0 :         args.out_buffer = vf->aq_resp;
    2222                 :          0 :         args.out_size = IAVF_AQ_BUF_SZ;
    2223                 :            : 
    2224                 :          0 :         err = iavf_execute_vf_cmd_safe(adapter, &args, 0);
    2225         [ #  # ]:          0 :         if (err) {
    2226                 :          0 :                 PMD_DRV_LOG(ERR, "Failed to execute command VIRTCHNL_OP_CONFIG_QUANTA");
    2227                 :          0 :                 return err;
    2228                 :            :         }
    2229                 :            : 
    2230                 :            :         return 0;
    2231                 :            : }
    2232                 :            : 
    2233                 :            : int
    2234                 :          0 : iavf_get_ptp_cap(struct iavf_adapter *adapter)
    2235                 :            : {
    2236                 :            :         struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(adapter);
    2237                 :            :         struct virtchnl_ptp_caps ptp_caps;
    2238                 :            :         struct iavf_cmd_info args;
    2239                 :            :         int err;
    2240                 :            : 
    2241                 :          0 :         ptp_caps.caps = VIRTCHNL_1588_PTP_CAP_RX_TSTAMP |
    2242                 :            :                         VIRTCHNL_1588_PTP_CAP_READ_PHC;
    2243                 :            : 
    2244                 :          0 :         args.ops = VIRTCHNL_OP_1588_PTP_GET_CAPS;
    2245                 :          0 :         args.in_args = (uint8_t *)&ptp_caps;
    2246                 :          0 :         args.in_args_size = sizeof(ptp_caps);
    2247                 :          0 :         args.out_buffer = vf->aq_resp;
    2248                 :          0 :         args.out_size = IAVF_AQ_BUF_SZ;
    2249                 :            : 
    2250                 :          0 :         err = iavf_execute_vf_cmd_safe(adapter, &args, 0);
    2251         [ #  # ]:          0 :         if (err) {
    2252                 :          0 :                 PMD_DRV_LOG(ERR,
    2253                 :            :                             "Failed to execute command of OP_1588_PTP_GET_CAPS");
    2254                 :          0 :                 return err;
    2255                 :            :         }
    2256                 :            : 
    2257                 :          0 :         vf->ptp_caps = ((struct virtchnl_ptp_caps *)args.out_buffer)->caps;
    2258                 :            : 
    2259                 :          0 :         return 0;
    2260                 :            : }
    2261                 :            : 
    2262                 :            : int
    2263                 :          0 : iavf_get_phc_time(struct iavf_rx_queue *rxq)
    2264                 :            : {
    2265                 :          0 :         struct iavf_adapter *adapter = rxq->vsi->adapter;
    2266                 :            :         struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(adapter);
    2267                 :            :         struct virtchnl_phc_time phc_time;
    2268                 :            :         struct iavf_cmd_info args;
    2269                 :            :         int err = 0;
    2270                 :            : 
    2271                 :          0 :         args.ops = VIRTCHNL_OP_1588_PTP_GET_TIME;
    2272                 :          0 :         args.in_args = (uint8_t *)&phc_time;
    2273                 :          0 :         args.in_args_size = sizeof(phc_time);
    2274                 :          0 :         args.out_buffer = vf->aq_resp;
    2275                 :          0 :         args.out_size = IAVF_AQ_BUF_SZ;
    2276                 :            : 
    2277                 :          0 :         rte_spinlock_lock(&vf->phc_time_aq_lock);
    2278                 :          0 :         err = iavf_execute_vf_cmd_safe(adapter, &args, 0);
    2279         [ #  # ]:          0 :         if (err) {
    2280                 :          0 :                 PMD_DRV_LOG(ERR,
    2281                 :            :                             "Failed to execute command of VIRTCHNL_OP_1588_PTP_GET_TIME");
    2282                 :          0 :                 goto out;
    2283                 :            :         }
    2284                 :          0 :         rxq->phc_time = ((struct virtchnl_phc_time *)args.out_buffer)->time;
    2285                 :            : 
    2286                 :          0 : out:
    2287                 :            :         rte_spinlock_unlock(&vf->phc_time_aq_lock);
    2288                 :          0 :         return err;
    2289                 :            : }

Generated by: LCOV version 1.14