net/mlx5: fix flow age event triggering
[dpdk.git] / drivers / net / iavf / iavf_vchnl.c
1 /* SPDX-License-Identifier: BSD-3-Clause
2  * Copyright(c) 2017 Intel Corporation
3  */
4
5 #include <stdio.h>
6 #include <errno.h>
7 #include <stdint.h>
8 #include <string.h>
9 #include <unistd.h>
10 #include <stdarg.h>
11 #include <inttypes.h>
12 #include <rte_byteorder.h>
13 #include <rte_common.h>
14
15 #include <rte_debug.h>
16 #include <rte_atomic.h>
17 #include <rte_eal.h>
18 #include <rte_ether.h>
19 #include <ethdev_driver.h>
20 #include <ethdev_pci.h>
21 #include <rte_dev.h>
22
23 #include "iavf.h"
24 #include "iavf_rxtx.h"
25
26 #define MAX_TRY_TIMES 200
27 #define ASQ_DELAY_MS  10
28
29 static uint32_t
30 iavf_convert_link_speed(enum virtchnl_link_speed virt_link_speed)
31 {
32         uint32_t speed;
33
34         switch (virt_link_speed) {
35         case VIRTCHNL_LINK_SPEED_100MB:
36                 speed = 100;
37                 break;
38         case VIRTCHNL_LINK_SPEED_1GB:
39                 speed = 1000;
40                 break;
41         case VIRTCHNL_LINK_SPEED_10GB:
42                 speed = 10000;
43                 break;
44         case VIRTCHNL_LINK_SPEED_40GB:
45                 speed = 40000;
46                 break;
47         case VIRTCHNL_LINK_SPEED_20GB:
48                 speed = 20000;
49                 break;
50         case VIRTCHNL_LINK_SPEED_25GB:
51                 speed = 25000;
52                 break;
53         case VIRTCHNL_LINK_SPEED_2_5GB:
54                 speed = 2500;
55                 break;
56         case VIRTCHNL_LINK_SPEED_5GB:
57                 speed = 5000;
58                 break;
59         default:
60                 speed = 0;
61                 break;
62         }
63
64         return speed;
65 }
66
67 /* Read data in admin queue to get msg from pf driver */
68 static enum iavf_aq_result
69 iavf_read_msg_from_pf(struct iavf_adapter *adapter, uint16_t buf_len,
70                      uint8_t *buf)
71 {
72         struct iavf_hw *hw = IAVF_DEV_PRIVATE_TO_HW(adapter);
73         struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(adapter);
74         struct rte_eth_dev *dev = adapter->eth_dev;
75         struct iavf_arq_event_info event;
76         enum iavf_aq_result result = IAVF_MSG_NON;
77         enum virtchnl_ops opcode;
78         int ret;
79
80         event.buf_len = buf_len;
81         event.msg_buf = buf;
82         ret = iavf_clean_arq_element(hw, &event, NULL);
83         /* Can't read any msg from adminQ */
84         if (ret) {
85                 PMD_DRV_LOG(DEBUG, "Can't read msg from AQ");
86                 if (ret != IAVF_ERR_ADMIN_QUEUE_NO_WORK)
87                         result = IAVF_MSG_ERR;
88                 return result;
89         }
90
91         opcode = (enum virtchnl_ops)rte_le_to_cpu_32(event.desc.cookie_high);
92         vf->cmd_retval = (enum virtchnl_status_code)rte_le_to_cpu_32(
93                         event.desc.cookie_low);
94
95         PMD_DRV_LOG(DEBUG, "AQ from pf carries opcode %u, retval %d",
96                     opcode, vf->cmd_retval);
97
98         if (opcode == VIRTCHNL_OP_EVENT) {
99                 struct virtchnl_pf_event *vpe =
100                         (struct virtchnl_pf_event *)event.msg_buf;
101
102                 result = IAVF_MSG_SYS;
103                 switch (vpe->event) {
104                 case VIRTCHNL_EVENT_LINK_CHANGE:
105                         vf->link_up =
106                                 vpe->event_data.link_event.link_status;
107                         if (vf->vf_res->vf_cap_flags &
108                                 VIRTCHNL_VF_CAP_ADV_LINK_SPEED) {
109                                 vf->link_speed =
110                                     vpe->event_data.link_event_adv.link_speed;
111                         } else {
112                                 enum virtchnl_link_speed speed;
113                                 speed = vpe->event_data.link_event.link_speed;
114                                 vf->link_speed = iavf_convert_link_speed(speed);
115                         }
116                         iavf_dev_link_update(dev, 0);
117                         PMD_DRV_LOG(INFO, "Link status update:%s",
118                                         vf->link_up ? "up" : "down");
119                         break;
120                 case VIRTCHNL_EVENT_RESET_IMPENDING:
121                         vf->vf_reset = true;
122                         PMD_DRV_LOG(INFO, "VF is resetting");
123                         break;
124                 case VIRTCHNL_EVENT_PF_DRIVER_CLOSE:
125                         vf->dev_closed = true;
126                         PMD_DRV_LOG(INFO, "PF driver closed");
127                         break;
128                 default:
129                         PMD_DRV_LOG(ERR, "%s: Unknown event %d from pf",
130                                         __func__, vpe->event);
131                 }
132         }  else {
133                 /* async reply msg on command issued by vf previously */
134                 result = IAVF_MSG_CMD;
135                 if (opcode != vf->pend_cmd) {
136                         PMD_DRV_LOG(WARNING, "command mismatch, expect %u, get %u",
137                                         vf->pend_cmd, opcode);
138                         result = IAVF_MSG_ERR;
139                 }
140         }
141
142         return result;
143 }
144
145 static int
146 iavf_execute_vf_cmd(struct iavf_adapter *adapter, struct iavf_cmd_info *args)
147 {
148         struct iavf_hw *hw = IAVF_DEV_PRIVATE_TO_HW(adapter);
149         struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(adapter);
150         enum iavf_aq_result result;
151         enum iavf_status ret;
152         int err = 0;
153         int i = 0;
154
155         if (vf->vf_reset)
156                 return -EIO;
157
158         if (_atomic_set_cmd(vf, args->ops))
159                 return -1;
160
161         ret = iavf_aq_send_msg_to_pf(hw, args->ops, IAVF_SUCCESS,
162                                     args->in_args, args->in_args_size, NULL);
163         if (ret) {
164                 PMD_DRV_LOG(ERR, "fail to send cmd %d", args->ops);
165                 _clear_cmd(vf);
166                 return err;
167         }
168
169         switch (args->ops) {
170         case VIRTCHNL_OP_RESET_VF:
171                 /*no need to wait for response */
172                 _clear_cmd(vf);
173                 break;
174         case VIRTCHNL_OP_VERSION:
175         case VIRTCHNL_OP_GET_VF_RESOURCES:
176         case VIRTCHNL_OP_GET_SUPPORTED_RXDIDS:
177         case VIRTCHNL_OP_GET_OFFLOAD_VLAN_V2_CAPS:
178                 /* for init virtchnl ops, need to poll the response */
179                 do {
180                         result = iavf_read_msg_from_pf(adapter, args->out_size,
181                                                    args->out_buffer);
182                         if (result == IAVF_MSG_CMD)
183                                 break;
184                         rte_delay_ms(ASQ_DELAY_MS);
185                 } while (i++ < MAX_TRY_TIMES);
186                 if (i >= MAX_TRY_TIMES ||
187                     vf->cmd_retval != VIRTCHNL_STATUS_SUCCESS) {
188                         err = -1;
189                         PMD_DRV_LOG(ERR, "No response or return failure (%d)"
190                                     " for cmd %d", vf->cmd_retval, args->ops);
191                 }
192                 _clear_cmd(vf);
193                 break;
194         case VIRTCHNL_OP_REQUEST_QUEUES:
195                 /*
196                  * ignore async reply, only wait for system message,
197                  * vf_reset = true if get VIRTCHNL_EVENT_RESET_IMPENDING,
198                  * if not, means request queues failed.
199                  */
200                 do {
201                         result = iavf_read_msg_from_pf(adapter, args->out_size,
202                                                    args->out_buffer);
203                         if (result == IAVF_MSG_SYS && vf->vf_reset) {
204                                 break;
205                         } else if (result == IAVF_MSG_CMD ||
206                                 result == IAVF_MSG_ERR) {
207                                 err = -1;
208                                 break;
209                         }
210                         rte_delay_ms(ASQ_DELAY_MS);
211                         /* If don't read msg or read sys event, continue */
212                 } while (i++ < MAX_TRY_TIMES);
213                 if (i >= MAX_TRY_TIMES ||
214                         vf->cmd_retval != VIRTCHNL_STATUS_SUCCESS) {
215                         err = -1;
216                         PMD_DRV_LOG(ERR, "No response or return failure (%d)"
217                                     " for cmd %d", vf->cmd_retval, args->ops);
218                 }
219                 _clear_cmd(vf);
220                 break;
221         default:
222                 /* For other virtchnl ops in running time,
223                  * wait for the cmd done flag.
224                  */
225                 do {
226                         if (vf->pend_cmd == VIRTCHNL_OP_UNKNOWN)
227                                 break;
228                         rte_delay_ms(ASQ_DELAY_MS);
229                         /* If don't read msg or read sys event, continue */
230                 } while (i++ < MAX_TRY_TIMES);
231
232                 if (i >= MAX_TRY_TIMES) {
233                         PMD_DRV_LOG(ERR, "No response for cmd %d", args->ops);
234                         _clear_cmd(vf);
235                         err = -EIO;
236                 } else if (vf->cmd_retval ==
237                            VIRTCHNL_STATUS_ERR_NOT_SUPPORTED) {
238                         PMD_DRV_LOG(ERR, "Cmd %d not supported", args->ops);
239                         err = -ENOTSUP;
240                 } else if (vf->cmd_retval != VIRTCHNL_STATUS_SUCCESS) {
241                         PMD_DRV_LOG(ERR, "Return failure %d for cmd %d",
242                                     vf->cmd_retval, args->ops);
243                         err = -EINVAL;
244                 }
245                 break;
246         }
247
248         return err;
249 }
250
251 static void
252 iavf_handle_pf_event_msg(struct rte_eth_dev *dev, uint8_t *msg,
253                         uint16_t msglen)
254 {
255         struct virtchnl_pf_event *pf_msg =
256                         (struct virtchnl_pf_event *)msg;
257         struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(dev->data->dev_private);
258
259         if (msglen < sizeof(struct virtchnl_pf_event)) {
260                 PMD_DRV_LOG(DEBUG, "Error event");
261                 return;
262         }
263         switch (pf_msg->event) {
264         case VIRTCHNL_EVENT_RESET_IMPENDING:
265                 PMD_DRV_LOG(DEBUG, "VIRTCHNL_EVENT_RESET_IMPENDING event");
266                 vf->vf_reset = true;
267                 rte_eth_dev_callback_process(dev, RTE_ETH_EVENT_INTR_RESET,
268                                               NULL);
269                 break;
270         case VIRTCHNL_EVENT_LINK_CHANGE:
271                 PMD_DRV_LOG(DEBUG, "VIRTCHNL_EVENT_LINK_CHANGE event");
272                 vf->link_up = pf_msg->event_data.link_event.link_status;
273                 if (vf->vf_res->vf_cap_flags & VIRTCHNL_VF_CAP_ADV_LINK_SPEED) {
274                         vf->link_speed =
275                                 pf_msg->event_data.link_event_adv.link_speed;
276                 } else {
277                         enum virtchnl_link_speed speed;
278                         speed = pf_msg->event_data.link_event.link_speed;
279                         vf->link_speed = iavf_convert_link_speed(speed);
280                 }
281                 iavf_dev_link_update(dev, 0);
282                 rte_eth_dev_callback_process(dev, RTE_ETH_EVENT_INTR_LSC, NULL);
283                 break;
284         case VIRTCHNL_EVENT_PF_DRIVER_CLOSE:
285                 PMD_DRV_LOG(DEBUG, "VIRTCHNL_EVENT_PF_DRIVER_CLOSE event");
286                 break;
287         default:
288                 PMD_DRV_LOG(ERR, " unknown event received %u", pf_msg->event);
289                 break;
290         }
291 }
292
293 void
294 iavf_handle_virtchnl_msg(struct rte_eth_dev *dev)
295 {
296         struct iavf_hw *hw = IAVF_DEV_PRIVATE_TO_HW(dev->data->dev_private);
297         struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(dev->data->dev_private);
298         struct iavf_arq_event_info info;
299         uint16_t pending, aq_opc;
300         enum virtchnl_ops msg_opc;
301         enum iavf_status msg_ret;
302         int ret;
303
304         info.buf_len = IAVF_AQ_BUF_SZ;
305         if (!vf->aq_resp) {
306                 PMD_DRV_LOG(ERR, "Buffer for adminq resp should not be NULL");
307                 return;
308         }
309         info.msg_buf = vf->aq_resp;
310
311         pending = 1;
312         while (pending) {
313                 ret = iavf_clean_arq_element(hw, &info, &pending);
314
315                 if (ret != IAVF_SUCCESS) {
316                         PMD_DRV_LOG(INFO, "Failed to read msg from AdminQ,"
317                                     "ret: %d", ret);
318                         break;
319                 }
320                 aq_opc = rte_le_to_cpu_16(info.desc.opcode);
321                 /* For the message sent from pf to vf, opcode is stored in
322                  * cookie_high of struct iavf_aq_desc, while return error code
323                  * are stored in cookie_low, Which is done by PF driver.
324                  */
325                 msg_opc = (enum virtchnl_ops)rte_le_to_cpu_32(
326                                                   info.desc.cookie_high);
327                 msg_ret = (enum iavf_status)rte_le_to_cpu_32(
328                                                   info.desc.cookie_low);
329                 switch (aq_opc) {
330                 case iavf_aqc_opc_send_msg_to_vf:
331                         if (msg_opc == VIRTCHNL_OP_EVENT) {
332                                 iavf_handle_pf_event_msg(dev, info.msg_buf,
333                                                         info.msg_len);
334                         } else {
335                                 /* read message and it's expected one */
336                                 if (msg_opc == vf->pend_cmd)
337                                         _notify_cmd(vf, msg_ret);
338                                 else
339                                         PMD_DRV_LOG(ERR, "command mismatch,"
340                                                     "expect %u, get %u",
341                                                     vf->pend_cmd, msg_opc);
342                                 PMD_DRV_LOG(DEBUG,
343                                             "adminq response is received,"
344                                             " opcode = %d", msg_opc);
345                         }
346                         break;
347                 default:
348                         PMD_DRV_LOG(DEBUG, "Request %u is not supported yet",
349                                     aq_opc);
350                         break;
351                 }
352         }
353 }
354
355 int
356 iavf_enable_vlan_strip(struct iavf_adapter *adapter)
357 {
358         struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(adapter);
359         struct iavf_cmd_info args;
360         int ret;
361
362         memset(&args, 0, sizeof(args));
363         args.ops = VIRTCHNL_OP_ENABLE_VLAN_STRIPPING;
364         args.in_args = NULL;
365         args.in_args_size = 0;
366         args.out_buffer = vf->aq_resp;
367         args.out_size = IAVF_AQ_BUF_SZ;
368         ret = iavf_execute_vf_cmd(adapter, &args);
369         if (ret)
370                 PMD_DRV_LOG(ERR, "Failed to execute command of"
371                             " OP_ENABLE_VLAN_STRIPPING");
372
373         return ret;
374 }
375
376 int
377 iavf_disable_vlan_strip(struct iavf_adapter *adapter)
378 {
379         struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(adapter);
380         struct iavf_cmd_info args;
381         int ret;
382
383         memset(&args, 0, sizeof(args));
384         args.ops = VIRTCHNL_OP_DISABLE_VLAN_STRIPPING;
385         args.in_args = NULL;
386         args.in_args_size = 0;
387         args.out_buffer = vf->aq_resp;
388         args.out_size = IAVF_AQ_BUF_SZ;
389         ret = iavf_execute_vf_cmd(adapter, &args);
390         if (ret)
391                 PMD_DRV_LOG(ERR, "Failed to execute command of"
392                             " OP_DISABLE_VLAN_STRIPPING");
393
394         return ret;
395 }
396
397 #define VIRTCHNL_VERSION_MAJOR_START 1
398 #define VIRTCHNL_VERSION_MINOR_START 1
399
400 /* Check API version with sync wait until version read from admin queue */
401 int
402 iavf_check_api_version(struct iavf_adapter *adapter)
403 {
404         struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(adapter);
405         struct virtchnl_version_info version, *pver;
406         struct iavf_cmd_info args;
407         int err;
408
409         version.major = VIRTCHNL_VERSION_MAJOR;
410         version.minor = VIRTCHNL_VERSION_MINOR;
411
412         args.ops = VIRTCHNL_OP_VERSION;
413         args.in_args = (uint8_t *)&version;
414         args.in_args_size = sizeof(version);
415         args.out_buffer = vf->aq_resp;
416         args.out_size = IAVF_AQ_BUF_SZ;
417
418         err = iavf_execute_vf_cmd(adapter, &args);
419         if (err) {
420                 PMD_INIT_LOG(ERR, "Fail to execute command of OP_VERSION");
421                 return err;
422         }
423
424         pver = (struct virtchnl_version_info *)args.out_buffer;
425         vf->virtchnl_version = *pver;
426
427         if (vf->virtchnl_version.major < VIRTCHNL_VERSION_MAJOR_START ||
428             (vf->virtchnl_version.major == VIRTCHNL_VERSION_MAJOR_START &&
429              vf->virtchnl_version.minor < VIRTCHNL_VERSION_MINOR_START)) {
430                 PMD_INIT_LOG(ERR, "VIRTCHNL API version should not be lower"
431                              " than (%u.%u) to support Adapative VF",
432                              VIRTCHNL_VERSION_MAJOR_START,
433                              VIRTCHNL_VERSION_MAJOR_START);
434                 return -1;
435         } else if (vf->virtchnl_version.major > VIRTCHNL_VERSION_MAJOR ||
436                    (vf->virtchnl_version.major == VIRTCHNL_VERSION_MAJOR &&
437                     vf->virtchnl_version.minor > VIRTCHNL_VERSION_MINOR)) {
438                 PMD_INIT_LOG(ERR, "PF/VF API version mismatch:(%u.%u)-(%u.%u)",
439                              vf->virtchnl_version.major,
440                              vf->virtchnl_version.minor,
441                              VIRTCHNL_VERSION_MAJOR,
442                              VIRTCHNL_VERSION_MINOR);
443                 return -1;
444         }
445
446         PMD_DRV_LOG(DEBUG, "Peer is supported PF host");
447         return 0;
448 }
449
450 int
451 iavf_get_vf_resource(struct iavf_adapter *adapter)
452 {
453         struct iavf_hw *hw = IAVF_DEV_PRIVATE_TO_HW(adapter);
454         struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(adapter);
455         struct iavf_cmd_info args;
456         uint32_t caps, len;
457         int err, i;
458
459         args.ops = VIRTCHNL_OP_GET_VF_RESOURCES;
460         args.out_buffer = vf->aq_resp;
461         args.out_size = IAVF_AQ_BUF_SZ;
462
463         caps = IAVF_BASIC_OFFLOAD_CAPS | VIRTCHNL_VF_CAP_ADV_LINK_SPEED |
464                 VIRTCHNL_VF_OFFLOAD_RX_FLEX_DESC |
465                 VIRTCHNL_VF_OFFLOAD_FDIR_PF |
466                 VIRTCHNL_VF_OFFLOAD_ADV_RSS_PF |
467                 VIRTCHNL_VF_OFFLOAD_REQ_QUEUES |
468                 VIRTCHNL_VF_OFFLOAD_CRC |
469                 VIRTCHNL_VF_OFFLOAD_VLAN_V2 |
470                 VIRTCHNL_VF_LARGE_NUM_QPAIRS;
471
472         args.in_args = (uint8_t *)&caps;
473         args.in_args_size = sizeof(caps);
474
475         err = iavf_execute_vf_cmd(adapter, &args);
476
477         if (err) {
478                 PMD_DRV_LOG(ERR,
479                             "Failed to execute command of OP_GET_VF_RESOURCE");
480                 return -1;
481         }
482
483         len =  sizeof(struct virtchnl_vf_resource) +
484                       IAVF_MAX_VF_VSI * sizeof(struct virtchnl_vsi_resource);
485
486         rte_memcpy(vf->vf_res, args.out_buffer,
487                    RTE_MIN(args.out_size, len));
488         /* parse  VF config message back from PF*/
489         iavf_vf_parse_hw_config(hw, vf->vf_res);
490         for (i = 0; i < vf->vf_res->num_vsis; i++) {
491                 if (vf->vf_res->vsi_res[i].vsi_type == VIRTCHNL_VSI_SRIOV)
492                         vf->vsi_res = &vf->vf_res->vsi_res[i];
493         }
494
495         if (!vf->vsi_res) {
496                 PMD_INIT_LOG(ERR, "no LAN VSI found");
497                 return -1;
498         }
499
500         vf->vsi.vsi_id = vf->vsi_res->vsi_id;
501         vf->vsi.nb_qps = vf->vsi_res->num_queue_pairs;
502         vf->vsi.adapter = adapter;
503
504         return 0;
505 }
506
507 int
508 iavf_get_supported_rxdid(struct iavf_adapter *adapter)
509 {
510         struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(adapter);
511         struct iavf_cmd_info args;
512         int ret;
513
514         args.ops = VIRTCHNL_OP_GET_SUPPORTED_RXDIDS;
515         args.in_args = NULL;
516         args.in_args_size = 0;
517         args.out_buffer = vf->aq_resp;
518         args.out_size = IAVF_AQ_BUF_SZ;
519
520         ret = iavf_execute_vf_cmd(adapter, &args);
521         if (ret) {
522                 PMD_DRV_LOG(ERR,
523                             "Failed to execute command of OP_GET_SUPPORTED_RXDIDS");
524                 return ret;
525         }
526
527         vf->supported_rxdid =
528                 ((struct virtchnl_supported_rxdids *)args.out_buffer)->supported_rxdids;
529
530         return 0;
531 }
532
533 int
534 iavf_config_vlan_strip_v2(struct iavf_adapter *adapter, bool enable)
535 {
536         struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(adapter);
537         struct virtchnl_vlan_supported_caps *stripping_caps;
538         struct virtchnl_vlan_setting vlan_strip;
539         struct iavf_cmd_info args;
540         uint32_t *ethertype;
541         int ret;
542
543         stripping_caps = &vf->vlan_v2_caps.offloads.stripping_support;
544
545         if ((stripping_caps->outer & VIRTCHNL_VLAN_ETHERTYPE_8100) &&
546             (stripping_caps->outer & VIRTCHNL_VLAN_TOGGLE))
547                 ethertype = &vlan_strip.outer_ethertype_setting;
548         else if ((stripping_caps->inner & VIRTCHNL_VLAN_ETHERTYPE_8100) &&
549                  (stripping_caps->inner & VIRTCHNL_VLAN_TOGGLE))
550                 ethertype = &vlan_strip.inner_ethertype_setting;
551         else
552                 return -ENOTSUP;
553
554         memset(&vlan_strip, 0, sizeof(vlan_strip));
555         vlan_strip.vport_id = vf->vsi_res->vsi_id;
556         *ethertype = VIRTCHNL_VLAN_ETHERTYPE_8100;
557
558         args.ops = enable ? VIRTCHNL_OP_ENABLE_VLAN_STRIPPING_V2 :
559                             VIRTCHNL_OP_DISABLE_VLAN_STRIPPING_V2;
560         args.in_args = (uint8_t *)&vlan_strip;
561         args.in_args_size = sizeof(vlan_strip);
562         args.out_buffer = vf->aq_resp;
563         args.out_size = IAVF_AQ_BUF_SZ;
564         ret = iavf_execute_vf_cmd(adapter, &args);
565         if (ret)
566                 PMD_DRV_LOG(ERR, "fail to execute command %s",
567                             enable ? "VIRTCHNL_OP_ENABLE_VLAN_STRIPPING_V2" :
568                                      "VIRTCHNL_OP_DISABLE_VLAN_STRIPPING_V2");
569
570         return ret;
571 }
572
573 int
574 iavf_config_vlan_insert_v2(struct iavf_adapter *adapter, bool enable)
575 {
576         struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(adapter);
577         struct virtchnl_vlan_supported_caps *insertion_caps;
578         struct virtchnl_vlan_setting vlan_insert;
579         struct iavf_cmd_info args;
580         uint32_t *ethertype;
581         int ret;
582
583         insertion_caps = &vf->vlan_v2_caps.offloads.insertion_support;
584
585         if ((insertion_caps->outer & VIRTCHNL_VLAN_ETHERTYPE_8100) &&
586             (insertion_caps->outer & VIRTCHNL_VLAN_TOGGLE))
587                 ethertype = &vlan_insert.outer_ethertype_setting;
588         else if ((insertion_caps->inner & VIRTCHNL_VLAN_ETHERTYPE_8100) &&
589                  (insertion_caps->inner & VIRTCHNL_VLAN_TOGGLE))
590                 ethertype = &vlan_insert.inner_ethertype_setting;
591         else
592                 return -ENOTSUP;
593
594         memset(&vlan_insert, 0, sizeof(vlan_insert));
595         vlan_insert.vport_id = vf->vsi_res->vsi_id;
596         *ethertype = VIRTCHNL_VLAN_ETHERTYPE_8100;
597
598         args.ops = enable ? VIRTCHNL_OP_ENABLE_VLAN_INSERTION_V2 :
599                             VIRTCHNL_OP_DISABLE_VLAN_INSERTION_V2;
600         args.in_args = (uint8_t *)&vlan_insert;
601         args.in_args_size = sizeof(vlan_insert);
602         args.out_buffer = vf->aq_resp;
603         args.out_size = IAVF_AQ_BUF_SZ;
604         ret = iavf_execute_vf_cmd(adapter, &args);
605         if (ret)
606                 PMD_DRV_LOG(ERR, "fail to execute command %s",
607                             enable ? "VIRTCHNL_OP_ENABLE_VLAN_INSERTION_V2" :
608                                      "VIRTCHNL_OP_DISABLE_VLAN_INSERTION_V2");
609
610         return ret;
611 }
612
613 int
614 iavf_add_del_vlan_v2(struct iavf_adapter *adapter, uint16_t vlanid, bool add)
615 {
616         struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(adapter);
617         struct virtchnl_vlan_supported_caps *supported_caps;
618         struct virtchnl_vlan_filter_list_v2 vlan_filter;
619         struct virtchnl_vlan *vlan_setting;
620         struct iavf_cmd_info args;
621         uint32_t filtering_caps;
622         int err;
623
624         supported_caps = &vf->vlan_v2_caps.filtering.filtering_support;
625         if (supported_caps->outer) {
626                 filtering_caps = supported_caps->outer;
627                 vlan_setting = &vlan_filter.filters[0].outer;
628         } else {
629                 filtering_caps = supported_caps->inner;
630                 vlan_setting = &vlan_filter.filters[0].inner;
631         }
632
633         if (!(filtering_caps & VIRTCHNL_VLAN_ETHERTYPE_8100))
634                 return -ENOTSUP;
635
636         memset(&vlan_filter, 0, sizeof(vlan_filter));
637         vlan_filter.vport_id = vf->vsi_res->vsi_id;
638         vlan_filter.num_elements = 1;
639         vlan_setting->tpid = RTE_ETHER_TYPE_VLAN;
640         vlan_setting->tci = vlanid;
641
642         args.ops = add ? VIRTCHNL_OP_ADD_VLAN_V2 : VIRTCHNL_OP_DEL_VLAN_V2;
643         args.in_args = (uint8_t *)&vlan_filter;
644         args.in_args_size = sizeof(vlan_filter);
645         args.out_buffer = vf->aq_resp;
646         args.out_size = IAVF_AQ_BUF_SZ;
647         err = iavf_execute_vf_cmd(adapter, &args);
648         if (err)
649                 PMD_DRV_LOG(ERR, "fail to execute command %s",
650                             add ? "OP_ADD_VLAN_V2" :  "OP_DEL_VLAN_V2");
651
652         return err;
653 }
654
655 int
656 iavf_get_vlan_offload_caps_v2(struct iavf_adapter *adapter)
657 {
658         struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(adapter);
659         struct iavf_cmd_info args;
660         int ret;
661
662         args.ops = VIRTCHNL_OP_GET_OFFLOAD_VLAN_V2_CAPS;
663         args.in_args = NULL;
664         args.in_args_size = 0;
665         args.out_buffer = vf->aq_resp;
666         args.out_size = IAVF_AQ_BUF_SZ;
667
668         ret = iavf_execute_vf_cmd(adapter, &args);
669         if (ret) {
670                 PMD_DRV_LOG(ERR,
671                             "Failed to execute command of VIRTCHNL_OP_GET_OFFLOAD_VLAN_V2_CAPS");
672                 return ret;
673         }
674
675         rte_memcpy(&vf->vlan_v2_caps, vf->aq_resp, sizeof(vf->vlan_v2_caps));
676
677         return 0;
678 }
679
680 int
681 iavf_enable_queues(struct iavf_adapter *adapter)
682 {
683         struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(adapter);
684         struct virtchnl_queue_select queue_select;
685         struct iavf_cmd_info args;
686         int err;
687
688         memset(&queue_select, 0, sizeof(queue_select));
689         queue_select.vsi_id = vf->vsi_res->vsi_id;
690
691         queue_select.rx_queues = BIT(adapter->eth_dev->data->nb_rx_queues) - 1;
692         queue_select.tx_queues = BIT(adapter->eth_dev->data->nb_tx_queues) - 1;
693
694         args.ops = VIRTCHNL_OP_ENABLE_QUEUES;
695         args.in_args = (u8 *)&queue_select;
696         args.in_args_size = sizeof(queue_select);
697         args.out_buffer = vf->aq_resp;
698         args.out_size = IAVF_AQ_BUF_SZ;
699         err = iavf_execute_vf_cmd(adapter, &args);
700         if (err) {
701                 PMD_DRV_LOG(ERR,
702                             "Failed to execute command of OP_ENABLE_QUEUES");
703                 return err;
704         }
705         return 0;
706 }
707
708 int
709 iavf_disable_queues(struct iavf_adapter *adapter)
710 {
711         struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(adapter);
712         struct virtchnl_queue_select queue_select;
713         struct iavf_cmd_info args;
714         int err;
715
716         memset(&queue_select, 0, sizeof(queue_select));
717         queue_select.vsi_id = vf->vsi_res->vsi_id;
718
719         queue_select.rx_queues = BIT(adapter->eth_dev->data->nb_rx_queues) - 1;
720         queue_select.tx_queues = BIT(adapter->eth_dev->data->nb_tx_queues) - 1;
721
722         args.ops = VIRTCHNL_OP_DISABLE_QUEUES;
723         args.in_args = (u8 *)&queue_select;
724         args.in_args_size = sizeof(queue_select);
725         args.out_buffer = vf->aq_resp;
726         args.out_size = IAVF_AQ_BUF_SZ;
727         err = iavf_execute_vf_cmd(adapter, &args);
728         if (err) {
729                 PMD_DRV_LOG(ERR,
730                             "Failed to execute command of OP_DISABLE_QUEUES");
731                 return err;
732         }
733         return 0;
734 }
735
736 int
737 iavf_switch_queue(struct iavf_adapter *adapter, uint16_t qid,
738                  bool rx, bool on)
739 {
740         struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(adapter);
741         struct virtchnl_queue_select queue_select;
742         struct iavf_cmd_info args;
743         int err;
744
745         memset(&queue_select, 0, sizeof(queue_select));
746         queue_select.vsi_id = vf->vsi_res->vsi_id;
747         if (rx)
748                 queue_select.rx_queues |= 1 << qid;
749         else
750                 queue_select.tx_queues |= 1 << qid;
751
752         if (on)
753                 args.ops = VIRTCHNL_OP_ENABLE_QUEUES;
754         else
755                 args.ops = VIRTCHNL_OP_DISABLE_QUEUES;
756         args.in_args = (u8 *)&queue_select;
757         args.in_args_size = sizeof(queue_select);
758         args.out_buffer = vf->aq_resp;
759         args.out_size = IAVF_AQ_BUF_SZ;
760         err = iavf_execute_vf_cmd(adapter, &args);
761         if (err)
762                 PMD_DRV_LOG(ERR, "Failed to execute command of %s",
763                             on ? "OP_ENABLE_QUEUES" : "OP_DISABLE_QUEUES");
764         return err;
765 }
766
767 int
768 iavf_enable_queues_lv(struct iavf_adapter *adapter)
769 {
770         struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(adapter);
771         struct virtchnl_del_ena_dis_queues *queue_select;
772         struct virtchnl_queue_chunk *queue_chunk;
773         struct iavf_cmd_info args;
774         int err, len;
775
776         len = sizeof(struct virtchnl_del_ena_dis_queues) +
777                   sizeof(struct virtchnl_queue_chunk) *
778                   (IAVF_RXTX_QUEUE_CHUNKS_NUM - 1);
779         queue_select = rte_zmalloc("queue_select", len, 0);
780         if (!queue_select)
781                 return -ENOMEM;
782
783         queue_chunk = queue_select->chunks.chunks;
784         queue_select->chunks.num_chunks = IAVF_RXTX_QUEUE_CHUNKS_NUM;
785         queue_select->vport_id = vf->vsi_res->vsi_id;
786
787         queue_chunk[VIRTCHNL_QUEUE_TYPE_TX].type = VIRTCHNL_QUEUE_TYPE_TX;
788         queue_chunk[VIRTCHNL_QUEUE_TYPE_TX].start_queue_id = 0;
789         queue_chunk[VIRTCHNL_QUEUE_TYPE_TX].num_queues =
790                 adapter->eth_dev->data->nb_tx_queues;
791
792         queue_chunk[VIRTCHNL_QUEUE_TYPE_RX].type = VIRTCHNL_QUEUE_TYPE_RX;
793         queue_chunk[VIRTCHNL_QUEUE_TYPE_RX].start_queue_id = 0;
794         queue_chunk[VIRTCHNL_QUEUE_TYPE_RX].num_queues =
795                 adapter->eth_dev->data->nb_rx_queues;
796
797         args.ops = VIRTCHNL_OP_ENABLE_QUEUES_V2;
798         args.in_args = (u8 *)queue_select;
799         args.in_args_size = len;
800         args.out_buffer = vf->aq_resp;
801         args.out_size = IAVF_AQ_BUF_SZ;
802         err = iavf_execute_vf_cmd(adapter, &args);
803         if (err)
804                 PMD_DRV_LOG(ERR,
805                             "Failed to execute command of OP_ENABLE_QUEUES_V2");
806
807         rte_free(queue_select);
808         return err;
809 }
810
811 int
812 iavf_disable_queues_lv(struct iavf_adapter *adapter)
813 {
814         struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(adapter);
815         struct virtchnl_del_ena_dis_queues *queue_select;
816         struct virtchnl_queue_chunk *queue_chunk;
817         struct iavf_cmd_info args;
818         int err, len;
819
820         len = sizeof(struct virtchnl_del_ena_dis_queues) +
821                   sizeof(struct virtchnl_queue_chunk) *
822                   (IAVF_RXTX_QUEUE_CHUNKS_NUM - 1);
823         queue_select = rte_zmalloc("queue_select", len, 0);
824         if (!queue_select)
825                 return -ENOMEM;
826
827         queue_chunk = queue_select->chunks.chunks;
828         queue_select->chunks.num_chunks = IAVF_RXTX_QUEUE_CHUNKS_NUM;
829         queue_select->vport_id = vf->vsi_res->vsi_id;
830
831         queue_chunk[VIRTCHNL_QUEUE_TYPE_TX].type = VIRTCHNL_QUEUE_TYPE_TX;
832         queue_chunk[VIRTCHNL_QUEUE_TYPE_TX].start_queue_id = 0;
833         queue_chunk[VIRTCHNL_QUEUE_TYPE_TX].num_queues =
834                 adapter->eth_dev->data->nb_tx_queues;
835
836         queue_chunk[VIRTCHNL_QUEUE_TYPE_RX].type = VIRTCHNL_QUEUE_TYPE_RX;
837         queue_chunk[VIRTCHNL_QUEUE_TYPE_RX].start_queue_id = 0;
838         queue_chunk[VIRTCHNL_QUEUE_TYPE_RX].num_queues =
839                 adapter->eth_dev->data->nb_rx_queues;
840
841         args.ops = VIRTCHNL_OP_DISABLE_QUEUES_V2;
842         args.in_args = (u8 *)queue_select;
843         args.in_args_size = len;
844         args.out_buffer = vf->aq_resp;
845         args.out_size = IAVF_AQ_BUF_SZ;
846         err = iavf_execute_vf_cmd(adapter, &args);
847         if (err)
848                 PMD_DRV_LOG(ERR,
849                             "Failed to execute command of OP_DISABLE_QUEUES_V2");
850
851         rte_free(queue_select);
852         return err;
853 }
854
855 int
856 iavf_switch_queue_lv(struct iavf_adapter *adapter, uint16_t qid,
857                  bool rx, bool on)
858 {
859         struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(adapter);
860         struct virtchnl_del_ena_dis_queues *queue_select;
861         struct virtchnl_queue_chunk *queue_chunk;
862         struct iavf_cmd_info args;
863         int err, len;
864
865         len = sizeof(struct virtchnl_del_ena_dis_queues);
866         queue_select = rte_zmalloc("queue_select", len, 0);
867         if (!queue_select)
868                 return -ENOMEM;
869
870         queue_chunk = queue_select->chunks.chunks;
871         queue_select->chunks.num_chunks = 1;
872         queue_select->vport_id = vf->vsi_res->vsi_id;
873
874         if (rx) {
875                 queue_chunk->type = VIRTCHNL_QUEUE_TYPE_RX;
876                 queue_chunk->start_queue_id = qid;
877                 queue_chunk->num_queues = 1;
878         } else {
879                 queue_chunk->type = VIRTCHNL_QUEUE_TYPE_TX;
880                 queue_chunk->start_queue_id = qid;
881                 queue_chunk->num_queues = 1;
882         }
883
884         if (on)
885                 args.ops = VIRTCHNL_OP_ENABLE_QUEUES_V2;
886         else
887                 args.ops = VIRTCHNL_OP_DISABLE_QUEUES_V2;
888         args.in_args = (u8 *)queue_select;
889         args.in_args_size = len;
890         args.out_buffer = vf->aq_resp;
891         args.out_size = IAVF_AQ_BUF_SZ;
892         err = iavf_execute_vf_cmd(adapter, &args);
893         if (err)
894                 PMD_DRV_LOG(ERR, "Failed to execute command of %s",
895                             on ? "OP_ENABLE_QUEUES_V2" : "OP_DISABLE_QUEUES_V2");
896
897         rte_free(queue_select);
898         return err;
899 }
900
901 int
902 iavf_configure_rss_lut(struct iavf_adapter *adapter)
903 {
904         struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(adapter);
905         struct virtchnl_rss_lut *rss_lut;
906         struct iavf_cmd_info args;
907         int len, err = 0;
908
909         len = sizeof(*rss_lut) + vf->vf_res->rss_lut_size - 1;
910         rss_lut = rte_zmalloc("rss_lut", len, 0);
911         if (!rss_lut)
912                 return -ENOMEM;
913
914         rss_lut->vsi_id = vf->vsi_res->vsi_id;
915         rss_lut->lut_entries = vf->vf_res->rss_lut_size;
916         rte_memcpy(rss_lut->lut, vf->rss_lut, vf->vf_res->rss_lut_size);
917
918         args.ops = VIRTCHNL_OP_CONFIG_RSS_LUT;
919         args.in_args = (u8 *)rss_lut;
920         args.in_args_size = len;
921         args.out_buffer = vf->aq_resp;
922         args.out_size = IAVF_AQ_BUF_SZ;
923
924         err = iavf_execute_vf_cmd(adapter, &args);
925         if (err)
926                 PMD_DRV_LOG(ERR,
927                             "Failed to execute command of OP_CONFIG_RSS_LUT");
928
929         rte_free(rss_lut);
930         return err;
931 }
932
933 int
934 iavf_configure_rss_key(struct iavf_adapter *adapter)
935 {
936         struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(adapter);
937         struct virtchnl_rss_key *rss_key;
938         struct iavf_cmd_info args;
939         int len, err = 0;
940
941         len = sizeof(*rss_key) + vf->vf_res->rss_key_size - 1;
942         rss_key = rte_zmalloc("rss_key", len, 0);
943         if (!rss_key)
944                 return -ENOMEM;
945
946         rss_key->vsi_id = vf->vsi_res->vsi_id;
947         rss_key->key_len = vf->vf_res->rss_key_size;
948         rte_memcpy(rss_key->key, vf->rss_key, vf->vf_res->rss_key_size);
949
950         args.ops = VIRTCHNL_OP_CONFIG_RSS_KEY;
951         args.in_args = (u8 *)rss_key;
952         args.in_args_size = len;
953         args.out_buffer = vf->aq_resp;
954         args.out_size = IAVF_AQ_BUF_SZ;
955
956         err = iavf_execute_vf_cmd(adapter, &args);
957         if (err)
958                 PMD_DRV_LOG(ERR,
959                             "Failed to execute command of OP_CONFIG_RSS_KEY");
960
961         rte_free(rss_key);
962         return err;
963 }
964
965 int
966 iavf_configure_queues(struct iavf_adapter *adapter,
967                 uint16_t num_queue_pairs, uint16_t index)
968 {
969         struct iavf_rx_queue **rxq =
970                 (struct iavf_rx_queue **)adapter->eth_dev->data->rx_queues;
971         struct iavf_tx_queue **txq =
972                 (struct iavf_tx_queue **)adapter->eth_dev->data->tx_queues;
973         struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(adapter);
974         struct virtchnl_vsi_queue_config_info *vc_config;
975         struct virtchnl_queue_pair_info *vc_qp;
976         struct iavf_cmd_info args;
977         uint16_t i, size;
978         int err;
979
980         size = sizeof(*vc_config) +
981                sizeof(vc_config->qpair[0]) * num_queue_pairs;
982         vc_config = rte_zmalloc("cfg_queue", size, 0);
983         if (!vc_config)
984                 return -ENOMEM;
985
986         vc_config->vsi_id = vf->vsi_res->vsi_id;
987         vc_config->num_queue_pairs = num_queue_pairs;
988
989         for (i = index, vc_qp = vc_config->qpair;
990                  i < index + num_queue_pairs;
991              i++, vc_qp++) {
992                 vc_qp->txq.vsi_id = vf->vsi_res->vsi_id;
993                 vc_qp->txq.queue_id = i;
994
995                 /* Virtchnnl configure tx queues by pairs */
996                 if (i < adapter->eth_dev->data->nb_tx_queues) {
997                         vc_qp->txq.ring_len = txq[i]->nb_tx_desc;
998                         vc_qp->txq.dma_ring_addr = txq[i]->tx_ring_phys_addr;
999                 }
1000
1001                 vc_qp->rxq.vsi_id = vf->vsi_res->vsi_id;
1002                 vc_qp->rxq.queue_id = i;
1003                 vc_qp->rxq.max_pkt_size = vf->max_pkt_len;
1004
1005                 if (i >= adapter->eth_dev->data->nb_rx_queues)
1006                         continue;
1007
1008                 /* Virtchnnl configure rx queues by pairs */
1009                 vc_qp->rxq.ring_len = rxq[i]->nb_rx_desc;
1010                 vc_qp->rxq.dma_ring_addr = rxq[i]->rx_ring_phys_addr;
1011                 vc_qp->rxq.databuffer_size = rxq[i]->rx_buf_len;
1012                 vc_qp->rxq.crc_disable = rxq[i]->crc_len != 0 ? 1 : 0;
1013 #ifndef RTE_LIBRTE_IAVF_16BYTE_RX_DESC
1014                 if (vf->vf_res->vf_cap_flags &
1015                     VIRTCHNL_VF_OFFLOAD_RX_FLEX_DESC &&
1016                     vf->supported_rxdid & BIT(rxq[i]->rxdid)) {
1017                         vc_qp->rxq.rxdid = rxq[i]->rxdid;
1018                         PMD_DRV_LOG(NOTICE, "request RXDID[%d] in Queue[%d]",
1019                                     vc_qp->rxq.rxdid, i);
1020                 } else {
1021                         PMD_DRV_LOG(NOTICE, "RXDID[%d] is not supported, "
1022                                     "request default RXDID[%d] in Queue[%d]",
1023                                     rxq[i]->rxdid, IAVF_RXDID_LEGACY_1, i);
1024                         vc_qp->rxq.rxdid = IAVF_RXDID_LEGACY_1;
1025                 }
1026 #else
1027                 if (vf->vf_res->vf_cap_flags &
1028                         VIRTCHNL_VF_OFFLOAD_RX_FLEX_DESC &&
1029                         vf->supported_rxdid & BIT(IAVF_RXDID_LEGACY_0)) {
1030                         vc_qp->rxq.rxdid = IAVF_RXDID_LEGACY_0;
1031                         PMD_DRV_LOG(NOTICE, "request RXDID[%d] in Queue[%d]",
1032                                     vc_qp->rxq.rxdid, i);
1033                 } else {
1034                         PMD_DRV_LOG(ERR, "RXDID[%d] is not supported",
1035                                     IAVF_RXDID_LEGACY_0);
1036                         return -1;
1037                 }
1038 #endif
1039         }
1040
1041         memset(&args, 0, sizeof(args));
1042         args.ops = VIRTCHNL_OP_CONFIG_VSI_QUEUES;
1043         args.in_args = (uint8_t *)vc_config;
1044         args.in_args_size = size;
1045         args.out_buffer = vf->aq_resp;
1046         args.out_size = IAVF_AQ_BUF_SZ;
1047
1048         err = iavf_execute_vf_cmd(adapter, &args);
1049         if (err)
1050                 PMD_DRV_LOG(ERR, "Failed to execute command of"
1051                             " VIRTCHNL_OP_CONFIG_VSI_QUEUES");
1052
1053         rte_free(vc_config);
1054         return err;
1055 }
1056
1057 int
1058 iavf_config_irq_map(struct iavf_adapter *adapter)
1059 {
1060         struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(adapter);
1061         struct virtchnl_irq_map_info *map_info;
1062         struct virtchnl_vector_map *vecmap;
1063         struct iavf_cmd_info args;
1064         int len, i, err;
1065
1066         len = sizeof(struct virtchnl_irq_map_info) +
1067               sizeof(struct virtchnl_vector_map) * vf->nb_msix;
1068
1069         map_info = rte_zmalloc("map_info", len, 0);
1070         if (!map_info)
1071                 return -ENOMEM;
1072
1073         map_info->num_vectors = vf->nb_msix;
1074         for (i = 0; i < adapter->eth_dev->data->nb_rx_queues; i++) {
1075                 vecmap =
1076                     &map_info->vecmap[vf->qv_map[i].vector_id - vf->msix_base];
1077                 vecmap->vsi_id = vf->vsi_res->vsi_id;
1078                 vecmap->rxitr_idx = IAVF_ITR_INDEX_DEFAULT;
1079                 vecmap->vector_id = vf->qv_map[i].vector_id;
1080                 vecmap->txq_map = 0;
1081                 vecmap->rxq_map |= 1 << vf->qv_map[i].queue_id;
1082         }
1083
1084         args.ops = VIRTCHNL_OP_CONFIG_IRQ_MAP;
1085         args.in_args = (u8 *)map_info;
1086         args.in_args_size = len;
1087         args.out_buffer = vf->aq_resp;
1088         args.out_size = IAVF_AQ_BUF_SZ;
1089         err = iavf_execute_vf_cmd(adapter, &args);
1090         if (err)
1091                 PMD_DRV_LOG(ERR, "fail to execute command OP_CONFIG_IRQ_MAP");
1092
1093         rte_free(map_info);
1094         return err;
1095 }
1096
1097 int
1098 iavf_config_irq_map_lv(struct iavf_adapter *adapter, uint16_t num,
1099                 uint16_t index)
1100 {
1101         struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(adapter);
1102         struct virtchnl_queue_vector_maps *map_info;
1103         struct virtchnl_queue_vector *qv_maps;
1104         struct iavf_cmd_info args;
1105         int len, i, err;
1106         int count = 0;
1107
1108         len = sizeof(struct virtchnl_queue_vector_maps) +
1109               sizeof(struct virtchnl_queue_vector) * (num - 1);
1110
1111         map_info = rte_zmalloc("map_info", len, 0);
1112         if (!map_info)
1113                 return -ENOMEM;
1114
1115         map_info->vport_id = vf->vsi_res->vsi_id;
1116         map_info->num_qv_maps = num;
1117         for (i = index; i < index + map_info->num_qv_maps; i++) {
1118                 qv_maps = &map_info->qv_maps[count++];
1119                 qv_maps->itr_idx = VIRTCHNL_ITR_IDX_0;
1120                 qv_maps->queue_type = VIRTCHNL_QUEUE_TYPE_RX;
1121                 qv_maps->queue_id = vf->qv_map[i].queue_id;
1122                 qv_maps->vector_id = vf->qv_map[i].vector_id;
1123         }
1124
1125         args.ops = VIRTCHNL_OP_MAP_QUEUE_VECTOR;
1126         args.in_args = (u8 *)map_info;
1127         args.in_args_size = len;
1128         args.out_buffer = vf->aq_resp;
1129         args.out_size = IAVF_AQ_BUF_SZ;
1130         err = iavf_execute_vf_cmd(adapter, &args);
1131         if (err)
1132                 PMD_DRV_LOG(ERR, "fail to execute command OP_MAP_QUEUE_VECTOR");
1133
1134         rte_free(map_info);
1135         return err;
1136 }
1137
1138 void
1139 iavf_add_del_all_mac_addr(struct iavf_adapter *adapter, bool add)
1140 {
1141         struct virtchnl_ether_addr_list *list;
1142         struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(adapter);
1143         struct rte_ether_addr *addr;
1144         struct iavf_cmd_info args;
1145         int len, err, i, j;
1146         int next_begin = 0;
1147         int begin = 0;
1148
1149         do {
1150                 j = 0;
1151                 len = sizeof(struct virtchnl_ether_addr_list);
1152                 for (i = begin; i < IAVF_NUM_MACADDR_MAX; i++, next_begin++) {
1153                         addr = &adapter->eth_dev->data->mac_addrs[i];
1154                         if (rte_is_zero_ether_addr(addr))
1155                                 continue;
1156                         len += sizeof(struct virtchnl_ether_addr);
1157                         if (len >= IAVF_AQ_BUF_SZ) {
1158                                 next_begin = i + 1;
1159                                 break;
1160                         }
1161                 }
1162
1163                 list = rte_zmalloc("iavf_del_mac_buffer", len, 0);
1164                 if (!list) {
1165                         PMD_DRV_LOG(ERR, "fail to allocate memory");
1166                         return;
1167                 }
1168
1169                 for (i = begin; i < next_begin; i++) {
1170                         addr = &adapter->eth_dev->data->mac_addrs[i];
1171                         if (rte_is_zero_ether_addr(addr))
1172                                 continue;
1173                         rte_memcpy(list->list[j].addr, addr->addr_bytes,
1174                                    sizeof(addr->addr_bytes));
1175                         list->list[j].type = VIRTCHNL_ETHER_ADDR_EXTRA;
1176                         PMD_DRV_LOG(DEBUG, "add/rm mac:%x:%x:%x:%x:%x:%x",
1177                                     addr->addr_bytes[0], addr->addr_bytes[1],
1178                                     addr->addr_bytes[2], addr->addr_bytes[3],
1179                                     addr->addr_bytes[4], addr->addr_bytes[5]);
1180                         j++;
1181                 }
1182                 list->vsi_id = vf->vsi_res->vsi_id;
1183                 list->num_elements = j;
1184                 args.ops = add ? VIRTCHNL_OP_ADD_ETH_ADDR :
1185                            VIRTCHNL_OP_DEL_ETH_ADDR;
1186                 args.in_args = (uint8_t *)list;
1187                 args.in_args_size = len;
1188                 args.out_buffer = vf->aq_resp;
1189                 args.out_size = IAVF_AQ_BUF_SZ;
1190                 err = iavf_execute_vf_cmd(adapter, &args);
1191                 if (err)
1192                         PMD_DRV_LOG(ERR, "fail to execute command %s",
1193                                     add ? "OP_ADD_ETHER_ADDRESS" :
1194                                     "OP_DEL_ETHER_ADDRESS");
1195                 rte_free(list);
1196                 begin = next_begin;
1197         } while (begin < IAVF_NUM_MACADDR_MAX);
1198 }
1199
1200 int
1201 iavf_query_stats(struct iavf_adapter *adapter,
1202                 struct virtchnl_eth_stats **pstats)
1203 {
1204         struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(adapter);
1205         struct virtchnl_queue_select q_stats;
1206         struct iavf_cmd_info args;
1207         int err;
1208
1209         memset(&q_stats, 0, sizeof(q_stats));
1210         q_stats.vsi_id = vf->vsi_res->vsi_id;
1211         args.ops = VIRTCHNL_OP_GET_STATS;
1212         args.in_args = (uint8_t *)&q_stats;
1213         args.in_args_size = sizeof(q_stats);
1214         args.out_buffer = vf->aq_resp;
1215         args.out_size = IAVF_AQ_BUF_SZ;
1216
1217         err = iavf_execute_vf_cmd(adapter, &args);
1218         if (err) {
1219                 PMD_DRV_LOG(ERR, "fail to execute command OP_GET_STATS");
1220                 *pstats = NULL;
1221                 return err;
1222         }
1223         *pstats = (struct virtchnl_eth_stats *)args.out_buffer;
1224         return 0;
1225 }
1226
1227 int
1228 iavf_config_promisc(struct iavf_adapter *adapter,
1229                    bool enable_unicast,
1230                    bool enable_multicast)
1231 {
1232         struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(adapter);
1233         struct virtchnl_promisc_info promisc;
1234         struct iavf_cmd_info args;
1235         int err;
1236
1237         promisc.flags = 0;
1238         promisc.vsi_id = vf->vsi_res->vsi_id;
1239
1240         if (enable_unicast)
1241                 promisc.flags |= FLAG_VF_UNICAST_PROMISC;
1242
1243         if (enable_multicast)
1244                 promisc.flags |= FLAG_VF_MULTICAST_PROMISC;
1245
1246         args.ops = VIRTCHNL_OP_CONFIG_PROMISCUOUS_MODE;
1247         args.in_args = (uint8_t *)&promisc;
1248         args.in_args_size = sizeof(promisc);
1249         args.out_buffer = vf->aq_resp;
1250         args.out_size = IAVF_AQ_BUF_SZ;
1251
1252         err = iavf_execute_vf_cmd(adapter, &args);
1253
1254         if (err) {
1255                 PMD_DRV_LOG(ERR,
1256                             "fail to execute command CONFIG_PROMISCUOUS_MODE");
1257
1258                 if (err == IAVF_NOT_SUPPORTED)
1259                         return -ENOTSUP;
1260
1261                 return -EAGAIN;
1262         }
1263
1264         vf->promisc_unicast_enabled = enable_unicast;
1265         vf->promisc_multicast_enabled = enable_multicast;
1266         return 0;
1267 }
1268
1269 int
1270 iavf_add_del_eth_addr(struct iavf_adapter *adapter, struct rte_ether_addr *addr,
1271                      bool add, uint8_t type)
1272 {
1273         struct virtchnl_ether_addr_list *list;
1274         struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(adapter);
1275         uint8_t cmd_buffer[sizeof(struct virtchnl_ether_addr_list) +
1276                            sizeof(struct virtchnl_ether_addr)];
1277         struct iavf_cmd_info args;
1278         int err;
1279
1280         list = (struct virtchnl_ether_addr_list *)cmd_buffer;
1281         list->vsi_id = vf->vsi_res->vsi_id;
1282         list->num_elements = 1;
1283         list->list[0].type = type;
1284         rte_memcpy(list->list[0].addr, addr->addr_bytes,
1285                    sizeof(addr->addr_bytes));
1286
1287         args.ops = add ? VIRTCHNL_OP_ADD_ETH_ADDR : VIRTCHNL_OP_DEL_ETH_ADDR;
1288         args.in_args = cmd_buffer;
1289         args.in_args_size = sizeof(cmd_buffer);
1290         args.out_buffer = vf->aq_resp;
1291         args.out_size = IAVF_AQ_BUF_SZ;
1292         err = iavf_execute_vf_cmd(adapter, &args);
1293         if (err)
1294                 PMD_DRV_LOG(ERR, "fail to execute command %s",
1295                             add ? "OP_ADD_ETH_ADDR" :  "OP_DEL_ETH_ADDR");
1296         return err;
1297 }
1298
1299 int
1300 iavf_add_del_vlan(struct iavf_adapter *adapter, uint16_t vlanid, bool add)
1301 {
1302         struct virtchnl_vlan_filter_list *vlan_list;
1303         struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(adapter);
1304         uint8_t cmd_buffer[sizeof(struct virtchnl_vlan_filter_list) +
1305                                                         sizeof(uint16_t)];
1306         struct iavf_cmd_info args;
1307         int err;
1308
1309         vlan_list = (struct virtchnl_vlan_filter_list *)cmd_buffer;
1310         vlan_list->vsi_id = vf->vsi_res->vsi_id;
1311         vlan_list->num_elements = 1;
1312         vlan_list->vlan_id[0] = vlanid;
1313
1314         args.ops = add ? VIRTCHNL_OP_ADD_VLAN : VIRTCHNL_OP_DEL_VLAN;
1315         args.in_args = cmd_buffer;
1316         args.in_args_size = sizeof(cmd_buffer);
1317         args.out_buffer = vf->aq_resp;
1318         args.out_size = IAVF_AQ_BUF_SZ;
1319         err = iavf_execute_vf_cmd(adapter, &args);
1320         if (err)
1321                 PMD_DRV_LOG(ERR, "fail to execute command %s",
1322                             add ? "OP_ADD_VLAN" :  "OP_DEL_VLAN");
1323
1324         return err;
1325 }
1326
1327 int
1328 iavf_fdir_add(struct iavf_adapter *adapter,
1329         struct iavf_fdir_conf *filter)
1330 {
1331         struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(adapter);
1332         struct virtchnl_fdir_add *fdir_ret;
1333
1334         struct iavf_cmd_info args;
1335         int err;
1336
1337         filter->add_fltr.vsi_id = vf->vsi_res->vsi_id;
1338         filter->add_fltr.validate_only = 0;
1339
1340         args.ops = VIRTCHNL_OP_ADD_FDIR_FILTER;
1341         args.in_args = (uint8_t *)(&filter->add_fltr);
1342         args.in_args_size = sizeof(*(&filter->add_fltr));
1343         args.out_buffer = vf->aq_resp;
1344         args.out_size = IAVF_AQ_BUF_SZ;
1345
1346         err = iavf_execute_vf_cmd(adapter, &args);
1347         if (err) {
1348                 PMD_DRV_LOG(ERR, "fail to execute command OP_ADD_FDIR_FILTER");
1349                 return err;
1350         }
1351
1352         fdir_ret = (struct virtchnl_fdir_add *)args.out_buffer;
1353         filter->flow_id = fdir_ret->flow_id;
1354
1355         if (fdir_ret->status == VIRTCHNL_FDIR_SUCCESS) {
1356                 PMD_DRV_LOG(INFO,
1357                         "Succeed in adding rule request by PF");
1358         } else if (fdir_ret->status == VIRTCHNL_FDIR_FAILURE_RULE_NORESOURCE) {
1359                 PMD_DRV_LOG(ERR,
1360                         "Failed to add rule request due to no hw resource");
1361                 return -1;
1362         } else if (fdir_ret->status == VIRTCHNL_FDIR_FAILURE_RULE_EXIST) {
1363                 PMD_DRV_LOG(ERR,
1364                         "Failed to add rule request due to the rule is already existed");
1365                 return -1;
1366         } else if (fdir_ret->status == VIRTCHNL_FDIR_FAILURE_RULE_CONFLICT) {
1367                 PMD_DRV_LOG(ERR,
1368                         "Failed to add rule request due to the rule is conflict with existing rule");
1369                 return -1;
1370         } else if (fdir_ret->status == VIRTCHNL_FDIR_FAILURE_RULE_INVALID) {
1371                 PMD_DRV_LOG(ERR,
1372                         "Failed to add rule request due to the hw doesn't support");
1373                 return -1;
1374         } else if (fdir_ret->status == VIRTCHNL_FDIR_FAILURE_RULE_TIMEOUT) {
1375                 PMD_DRV_LOG(ERR,
1376                         "Failed to add rule request due to time out for programming");
1377                 return -1;
1378         } else {
1379                 PMD_DRV_LOG(ERR,
1380                         "Failed to add rule request due to other reasons");
1381                 return -1;
1382         }
1383
1384         return 0;
1385 };
1386
1387 int
1388 iavf_fdir_del(struct iavf_adapter *adapter,
1389         struct iavf_fdir_conf *filter)
1390 {
1391         struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(adapter);
1392         struct virtchnl_fdir_del *fdir_ret;
1393
1394         struct iavf_cmd_info args;
1395         int err;
1396
1397         filter->del_fltr.vsi_id = vf->vsi_res->vsi_id;
1398         filter->del_fltr.flow_id = filter->flow_id;
1399
1400         args.ops = VIRTCHNL_OP_DEL_FDIR_FILTER;
1401         args.in_args = (uint8_t *)(&filter->del_fltr);
1402         args.in_args_size = sizeof(filter->del_fltr);
1403         args.out_buffer = vf->aq_resp;
1404         args.out_size = IAVF_AQ_BUF_SZ;
1405
1406         err = iavf_execute_vf_cmd(adapter, &args);
1407         if (err) {
1408                 PMD_DRV_LOG(ERR, "fail to execute command OP_DEL_FDIR_FILTER");
1409                 return err;
1410         }
1411
1412         fdir_ret = (struct virtchnl_fdir_del *)args.out_buffer;
1413
1414         if (fdir_ret->status == VIRTCHNL_FDIR_SUCCESS) {
1415                 PMD_DRV_LOG(INFO,
1416                         "Succeed in deleting rule request by PF");
1417         } else if (fdir_ret->status == VIRTCHNL_FDIR_FAILURE_RULE_NONEXIST) {
1418                 PMD_DRV_LOG(ERR,
1419                         "Failed to delete rule request due to this rule doesn't exist");
1420                 return -1;
1421         } else if (fdir_ret->status == VIRTCHNL_FDIR_FAILURE_RULE_TIMEOUT) {
1422                 PMD_DRV_LOG(ERR,
1423                         "Failed to delete rule request due to time out for programming");
1424                 return -1;
1425         } else {
1426                 PMD_DRV_LOG(ERR,
1427                         "Failed to delete rule request due to other reasons");
1428                 return -1;
1429         }
1430
1431         return 0;
1432 };
1433
1434 int
1435 iavf_fdir_check(struct iavf_adapter *adapter,
1436                 struct iavf_fdir_conf *filter)
1437 {
1438         struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(adapter);
1439         struct virtchnl_fdir_add *fdir_ret;
1440
1441         struct iavf_cmd_info args;
1442         int err;
1443
1444         filter->add_fltr.vsi_id = vf->vsi_res->vsi_id;
1445         filter->add_fltr.validate_only = 1;
1446
1447         args.ops = VIRTCHNL_OP_ADD_FDIR_FILTER;
1448         args.in_args = (uint8_t *)(&filter->add_fltr);
1449         args.in_args_size = sizeof(*(&filter->add_fltr));
1450         args.out_buffer = vf->aq_resp;
1451         args.out_size = IAVF_AQ_BUF_SZ;
1452
1453         err = iavf_execute_vf_cmd(adapter, &args);
1454         if (err) {
1455                 PMD_DRV_LOG(ERR, "fail to check flow direcotor rule");
1456                 return err;
1457         }
1458
1459         fdir_ret = (struct virtchnl_fdir_add *)args.out_buffer;
1460
1461         if (fdir_ret->status == VIRTCHNL_FDIR_SUCCESS) {
1462                 PMD_DRV_LOG(INFO,
1463                         "Succeed in checking rule request by PF");
1464         } else if (fdir_ret->status == VIRTCHNL_FDIR_FAILURE_RULE_INVALID) {
1465                 PMD_DRV_LOG(ERR,
1466                         "Failed to check rule request due to parameters validation"
1467                         " or HW doesn't support");
1468                 return -1;
1469         } else {
1470                 PMD_DRV_LOG(ERR,
1471                         "Failed to check rule request due to other reasons");
1472                 return -1;
1473         }
1474
1475         return 0;
1476 }
1477
1478 int
1479 iavf_add_del_rss_cfg(struct iavf_adapter *adapter,
1480                      struct virtchnl_rss_cfg *rss_cfg, bool add)
1481 {
1482         struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(adapter);
1483         struct iavf_cmd_info args;
1484         int err;
1485
1486         memset(&args, 0, sizeof(args));
1487         args.ops = add ? VIRTCHNL_OP_ADD_RSS_CFG :
1488                 VIRTCHNL_OP_DEL_RSS_CFG;
1489         args.in_args = (u8 *)rss_cfg;
1490         args.in_args_size = sizeof(*rss_cfg);
1491         args.out_buffer = vf->aq_resp;
1492         args.out_size = IAVF_AQ_BUF_SZ;
1493
1494         err = iavf_execute_vf_cmd(adapter, &args);
1495         if (err)
1496                 PMD_DRV_LOG(ERR,
1497                             "Failed to execute command of %s",
1498                             add ? "OP_ADD_RSS_CFG" :
1499                             "OP_DEL_RSS_INPUT_CFG");
1500
1501         return err;
1502 }
1503
1504 int
1505 iavf_get_hena_caps(struct iavf_adapter *adapter, uint64_t *caps)
1506 {
1507         struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(adapter);
1508         struct iavf_cmd_info args;
1509         int err;
1510
1511         args.ops = VIRTCHNL_OP_GET_RSS_HENA_CAPS;
1512         args.in_args = NULL;
1513         args.in_args_size = 0;
1514         args.out_buffer = vf->aq_resp;
1515         args.out_size = IAVF_AQ_BUF_SZ;
1516
1517         err = iavf_execute_vf_cmd(adapter, &args);
1518         if (err) {
1519                 PMD_DRV_LOG(ERR,
1520                             "Failed to execute command of OP_GET_RSS_HENA_CAPS");
1521                 return err;
1522         }
1523
1524         *caps = ((struct virtchnl_rss_hena *)args.out_buffer)->hena;
1525         return 0;
1526 }
1527
1528 int
1529 iavf_set_hena(struct iavf_adapter *adapter, uint64_t hena)
1530 {
1531         struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(adapter);
1532         struct virtchnl_rss_hena vrh;
1533         struct iavf_cmd_info args;
1534         int err;
1535
1536         vrh.hena = hena;
1537         args.ops = VIRTCHNL_OP_SET_RSS_HENA;
1538         args.in_args = (u8 *)&vrh;
1539         args.in_args_size = sizeof(vrh);
1540         args.out_buffer = vf->aq_resp;
1541         args.out_size = IAVF_AQ_BUF_SZ;
1542
1543         err = iavf_execute_vf_cmd(adapter, &args);
1544         if (err)
1545                 PMD_DRV_LOG(ERR,
1546                             "Failed to execute command of OP_SET_RSS_HENA");
1547
1548         return err;
1549 }
1550
1551 int
1552 iavf_add_del_mc_addr_list(struct iavf_adapter *adapter,
1553                         struct rte_ether_addr *mc_addrs,
1554                         uint32_t mc_addrs_num, bool add)
1555 {
1556         struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(adapter);
1557         uint8_t cmd_buffer[sizeof(struct virtchnl_ether_addr_list) +
1558                 (IAVF_NUM_MACADDR_MAX * sizeof(struct virtchnl_ether_addr))];
1559         struct virtchnl_ether_addr_list *list;
1560         struct iavf_cmd_info args;
1561         uint32_t i;
1562         int err;
1563
1564         if (mc_addrs == NULL || mc_addrs_num == 0)
1565                 return 0;
1566
1567         list = (struct virtchnl_ether_addr_list *)cmd_buffer;
1568         list->vsi_id = vf->vsi_res->vsi_id;
1569         list->num_elements = mc_addrs_num;
1570
1571         for (i = 0; i < mc_addrs_num; i++) {
1572                 if (!IAVF_IS_MULTICAST(mc_addrs[i].addr_bytes)) {
1573                         PMD_DRV_LOG(ERR, "Invalid mac:%x:%x:%x:%x:%x:%x",
1574                                     mc_addrs[i].addr_bytes[0],
1575                                     mc_addrs[i].addr_bytes[1],
1576                                     mc_addrs[i].addr_bytes[2],
1577                                     mc_addrs[i].addr_bytes[3],
1578                                     mc_addrs[i].addr_bytes[4],
1579                                     mc_addrs[i].addr_bytes[5]);
1580                         return -EINVAL;
1581                 }
1582
1583                 memcpy(list->list[i].addr, mc_addrs[i].addr_bytes,
1584                         sizeof(list->list[i].addr));
1585                 list->list[i].type = VIRTCHNL_ETHER_ADDR_EXTRA;
1586         }
1587
1588         args.ops = add ? VIRTCHNL_OP_ADD_ETH_ADDR : VIRTCHNL_OP_DEL_ETH_ADDR;
1589         args.in_args = cmd_buffer;
1590         args.in_args_size = sizeof(struct virtchnl_ether_addr_list) +
1591                 i * sizeof(struct virtchnl_ether_addr);
1592         args.out_buffer = vf->aq_resp;
1593         args.out_size = IAVF_AQ_BUF_SZ;
1594         err = iavf_execute_vf_cmd(adapter, &args);
1595
1596         if (err) {
1597                 PMD_DRV_LOG(ERR, "fail to execute command %s",
1598                         add ? "OP_ADD_ETH_ADDR" : "OP_DEL_ETH_ADDR");
1599                 return err;
1600         }
1601
1602         return 0;
1603 }
1604
1605 int
1606 iavf_request_queues(struct iavf_adapter *adapter, uint16_t num)
1607 {
1608         struct rte_eth_dev *dev = adapter->eth_dev;
1609         struct iavf_info *vf =  IAVF_DEV_PRIVATE_TO_VF(adapter);
1610         struct rte_pci_device *pci_dev = RTE_ETH_DEV_TO_PCI(dev);
1611         struct virtchnl_vf_res_request vfres;
1612         struct iavf_cmd_info args;
1613         uint16_t num_queue_pairs;
1614         int err;
1615
1616         if (!(vf->vf_res->vf_cap_flags &
1617                 VIRTCHNL_VF_OFFLOAD_REQ_QUEUES)) {
1618                 PMD_DRV_LOG(ERR, "request queues not supported");
1619                 return -1;
1620         }
1621
1622         if (num == 0) {
1623                 PMD_DRV_LOG(ERR, "queue number cannot be zero");
1624                 return -1;
1625         }
1626         vfres.num_queue_pairs = num;
1627
1628         args.ops = VIRTCHNL_OP_REQUEST_QUEUES;
1629         args.in_args = (u8 *)&vfres;
1630         args.in_args_size = sizeof(vfres);
1631         args.out_buffer = vf->aq_resp;
1632         args.out_size = IAVF_AQ_BUF_SZ;
1633
1634         /*
1635          * disable interrupt to avoid the admin queue message to be read
1636          * before iavf_read_msg_from_pf.
1637          */
1638         rte_intr_disable(&pci_dev->intr_handle);
1639         err = iavf_execute_vf_cmd(adapter, &args);
1640         rte_intr_enable(&pci_dev->intr_handle);
1641         if (err) {
1642                 PMD_DRV_LOG(ERR, "fail to execute command OP_REQUEST_QUEUES");
1643                 return err;
1644         }
1645
1646         /* request queues succeeded, vf is resetting */
1647         if (vf->vf_reset) {
1648                 PMD_DRV_LOG(INFO, "vf is resetting");
1649                 return 0;
1650         }
1651
1652         /* request additional queues failed, return available number */
1653         num_queue_pairs =
1654           ((struct virtchnl_vf_res_request *)args.out_buffer)->num_queue_pairs;
1655         PMD_DRV_LOG(ERR, "request queues failed, only %u queues "
1656                 "available", num_queue_pairs);
1657
1658         return -1;
1659 }
1660
1661 int
1662 iavf_get_max_rss_queue_region(struct iavf_adapter *adapter)
1663 {
1664         struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(adapter);
1665         struct iavf_cmd_info args;
1666         uint16_t qregion_width;
1667         int err;
1668
1669         args.ops = VIRTCHNL_OP_GET_MAX_RSS_QREGION;
1670         args.in_args = NULL;
1671         args.in_args_size = 0;
1672         args.out_buffer = vf->aq_resp;
1673         args.out_size = IAVF_AQ_BUF_SZ;
1674
1675         err = iavf_execute_vf_cmd(adapter, &args);
1676         if (err) {
1677                 PMD_DRV_LOG(ERR, "Failed to execute command of VIRTCHNL_OP_GET_MAX_RSS_QREGION");
1678                 return err;
1679         }
1680
1681         qregion_width =
1682         ((struct virtchnl_max_rss_qregion *)args.out_buffer)->qregion_width;
1683
1684         vf->max_rss_qregion = (uint16_t)(1 << qregion_width);
1685
1686         return 0;
1687 }