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