aae5b900bb91a4b301cb5acada92679f9e72bb82
[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                         PMD_DRV_LOG(DEBUG, "add/rm mac:%x:%x:%x:%x:%x:%x",
1170                                     addr->addr_bytes[0], addr->addr_bytes[1],
1171                                     addr->addr_bytes[2], addr->addr_bytes[3],
1172                                     addr->addr_bytes[4], addr->addr_bytes[5]);
1173                         j++;
1174                 }
1175                 list->vsi_id = vf->vsi_res->vsi_id;
1176                 list->num_elements = j;
1177                 args.ops = add ? VIRTCHNL_OP_ADD_ETH_ADDR :
1178                            VIRTCHNL_OP_DEL_ETH_ADDR;
1179                 args.in_args = (uint8_t *)list;
1180                 args.in_args_size = len;
1181                 args.out_buffer = vf->aq_resp;
1182                 args.out_size = IAVF_AQ_BUF_SZ;
1183                 err = iavf_execute_vf_cmd(adapter, &args);
1184                 if (err)
1185                         PMD_DRV_LOG(ERR, "fail to execute command %s",
1186                                     add ? "OP_ADD_ETHER_ADDRESS" :
1187                                     "OP_DEL_ETHER_ADDRESS");
1188                 rte_free(list);
1189                 begin = next_begin;
1190         } while (begin < IAVF_NUM_MACADDR_MAX);
1191 }
1192
1193 int
1194 iavf_query_stats(struct iavf_adapter *adapter,
1195                 struct virtchnl_eth_stats **pstats)
1196 {
1197         struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(adapter);
1198         struct virtchnl_queue_select q_stats;
1199         struct iavf_cmd_info args;
1200         int err;
1201
1202         memset(&q_stats, 0, sizeof(q_stats));
1203         q_stats.vsi_id = vf->vsi_res->vsi_id;
1204         args.ops = VIRTCHNL_OP_GET_STATS;
1205         args.in_args = (uint8_t *)&q_stats;
1206         args.in_args_size = sizeof(q_stats);
1207         args.out_buffer = vf->aq_resp;
1208         args.out_size = IAVF_AQ_BUF_SZ;
1209
1210         err = iavf_execute_vf_cmd(adapter, &args);
1211         if (err) {
1212                 PMD_DRV_LOG(ERR, "fail to execute command OP_GET_STATS");
1213                 *pstats = NULL;
1214                 return err;
1215         }
1216         *pstats = (struct virtchnl_eth_stats *)args.out_buffer;
1217         return 0;
1218 }
1219
1220 int
1221 iavf_config_promisc(struct iavf_adapter *adapter,
1222                    bool enable_unicast,
1223                    bool enable_multicast)
1224 {
1225         struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(adapter);
1226         struct virtchnl_promisc_info promisc;
1227         struct iavf_cmd_info args;
1228         int err;
1229
1230         promisc.flags = 0;
1231         promisc.vsi_id = vf->vsi_res->vsi_id;
1232
1233         if (enable_unicast)
1234                 promisc.flags |= FLAG_VF_UNICAST_PROMISC;
1235
1236         if (enable_multicast)
1237                 promisc.flags |= FLAG_VF_MULTICAST_PROMISC;
1238
1239         args.ops = VIRTCHNL_OP_CONFIG_PROMISCUOUS_MODE;
1240         args.in_args = (uint8_t *)&promisc;
1241         args.in_args_size = sizeof(promisc);
1242         args.out_buffer = vf->aq_resp;
1243         args.out_size = IAVF_AQ_BUF_SZ;
1244
1245         err = iavf_execute_vf_cmd(adapter, &args);
1246
1247         if (err) {
1248                 PMD_DRV_LOG(ERR,
1249                             "fail to execute command CONFIG_PROMISCUOUS_MODE");
1250
1251                 if (err == IAVF_NOT_SUPPORTED)
1252                         return -ENOTSUP;
1253
1254                 return -EAGAIN;
1255         }
1256
1257         vf->promisc_unicast_enabled = enable_unicast;
1258         vf->promisc_multicast_enabled = enable_multicast;
1259         return 0;
1260 }
1261
1262 int
1263 iavf_add_del_eth_addr(struct iavf_adapter *adapter, struct rte_ether_addr *addr,
1264                      bool add)
1265 {
1266         struct virtchnl_ether_addr_list *list;
1267         struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(adapter);
1268         uint8_t cmd_buffer[sizeof(struct virtchnl_ether_addr_list) +
1269                            sizeof(struct virtchnl_ether_addr)];
1270         struct iavf_cmd_info args;
1271         int err;
1272
1273         list = (struct virtchnl_ether_addr_list *)cmd_buffer;
1274         list->vsi_id = vf->vsi_res->vsi_id;
1275         list->num_elements = 1;
1276         rte_memcpy(list->list[0].addr, addr->addr_bytes,
1277                    sizeof(addr->addr_bytes));
1278
1279         args.ops = add ? VIRTCHNL_OP_ADD_ETH_ADDR : VIRTCHNL_OP_DEL_ETH_ADDR;
1280         args.in_args = cmd_buffer;
1281         args.in_args_size = sizeof(cmd_buffer);
1282         args.out_buffer = vf->aq_resp;
1283         args.out_size = IAVF_AQ_BUF_SZ;
1284         err = iavf_execute_vf_cmd(adapter, &args);
1285         if (err)
1286                 PMD_DRV_LOG(ERR, "fail to execute command %s",
1287                             add ? "OP_ADD_ETH_ADDR" :  "OP_DEL_ETH_ADDR");
1288         return err;
1289 }
1290
1291 int
1292 iavf_add_del_vlan(struct iavf_adapter *adapter, uint16_t vlanid, bool add)
1293 {
1294         struct virtchnl_vlan_filter_list *vlan_list;
1295         struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(adapter);
1296         uint8_t cmd_buffer[sizeof(struct virtchnl_vlan_filter_list) +
1297                                                         sizeof(uint16_t)];
1298         struct iavf_cmd_info args;
1299         int err;
1300
1301         vlan_list = (struct virtchnl_vlan_filter_list *)cmd_buffer;
1302         vlan_list->vsi_id = vf->vsi_res->vsi_id;
1303         vlan_list->num_elements = 1;
1304         vlan_list->vlan_id[0] = vlanid;
1305
1306         args.ops = add ? VIRTCHNL_OP_ADD_VLAN : VIRTCHNL_OP_DEL_VLAN;
1307         args.in_args = cmd_buffer;
1308         args.in_args_size = sizeof(cmd_buffer);
1309         args.out_buffer = vf->aq_resp;
1310         args.out_size = IAVF_AQ_BUF_SZ;
1311         err = iavf_execute_vf_cmd(adapter, &args);
1312         if (err)
1313                 PMD_DRV_LOG(ERR, "fail to execute command %s",
1314                             add ? "OP_ADD_VLAN" :  "OP_DEL_VLAN");
1315
1316         return err;
1317 }
1318
1319 int
1320 iavf_fdir_add(struct iavf_adapter *adapter,
1321         struct iavf_fdir_conf *filter)
1322 {
1323         struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(adapter);
1324         struct virtchnl_fdir_add *fdir_ret;
1325
1326         struct iavf_cmd_info args;
1327         int err;
1328
1329         filter->add_fltr.vsi_id = vf->vsi_res->vsi_id;
1330         filter->add_fltr.validate_only = 0;
1331
1332         args.ops = VIRTCHNL_OP_ADD_FDIR_FILTER;
1333         args.in_args = (uint8_t *)(&filter->add_fltr);
1334         args.in_args_size = sizeof(*(&filter->add_fltr));
1335         args.out_buffer = vf->aq_resp;
1336         args.out_size = IAVF_AQ_BUF_SZ;
1337
1338         err = iavf_execute_vf_cmd(adapter, &args);
1339         if (err) {
1340                 PMD_DRV_LOG(ERR, "fail to execute command OP_ADD_FDIR_FILTER");
1341                 return err;
1342         }
1343
1344         fdir_ret = (struct virtchnl_fdir_add *)args.out_buffer;
1345         filter->flow_id = fdir_ret->flow_id;
1346
1347         if (fdir_ret->status == VIRTCHNL_FDIR_SUCCESS) {
1348                 PMD_DRV_LOG(INFO,
1349                         "Succeed in adding rule request by PF");
1350         } else if (fdir_ret->status == VIRTCHNL_FDIR_FAILURE_RULE_NORESOURCE) {
1351                 PMD_DRV_LOG(ERR,
1352                         "Failed to add rule request due to no hw resource");
1353                 return -1;
1354         } else if (fdir_ret->status == VIRTCHNL_FDIR_FAILURE_RULE_EXIST) {
1355                 PMD_DRV_LOG(ERR,
1356                         "Failed to add rule request due to the rule is already existed");
1357                 return -1;
1358         } else if (fdir_ret->status == VIRTCHNL_FDIR_FAILURE_RULE_CONFLICT) {
1359                 PMD_DRV_LOG(ERR,
1360                         "Failed to add rule request due to the rule is conflict with existing rule");
1361                 return -1;
1362         } else if (fdir_ret->status == VIRTCHNL_FDIR_FAILURE_RULE_INVALID) {
1363                 PMD_DRV_LOG(ERR,
1364                         "Failed to add rule request due to the hw doesn't support");
1365                 return -1;
1366         } else if (fdir_ret->status == VIRTCHNL_FDIR_FAILURE_RULE_TIMEOUT) {
1367                 PMD_DRV_LOG(ERR,
1368                         "Failed to add rule request due to time out for programming");
1369                 return -1;
1370         } else {
1371                 PMD_DRV_LOG(ERR,
1372                         "Failed to add rule request due to other reasons");
1373                 return -1;
1374         }
1375
1376         return 0;
1377 };
1378
1379 int
1380 iavf_fdir_del(struct iavf_adapter *adapter,
1381         struct iavf_fdir_conf *filter)
1382 {
1383         struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(adapter);
1384         struct virtchnl_fdir_del *fdir_ret;
1385
1386         struct iavf_cmd_info args;
1387         int err;
1388
1389         filter->del_fltr.vsi_id = vf->vsi_res->vsi_id;
1390         filter->del_fltr.flow_id = filter->flow_id;
1391
1392         args.ops = VIRTCHNL_OP_DEL_FDIR_FILTER;
1393         args.in_args = (uint8_t *)(&filter->del_fltr);
1394         args.in_args_size = sizeof(filter->del_fltr);
1395         args.out_buffer = vf->aq_resp;
1396         args.out_size = IAVF_AQ_BUF_SZ;
1397
1398         err = iavf_execute_vf_cmd(adapter, &args);
1399         if (err) {
1400                 PMD_DRV_LOG(ERR, "fail to execute command OP_DEL_FDIR_FILTER");
1401                 return err;
1402         }
1403
1404         fdir_ret = (struct virtchnl_fdir_del *)args.out_buffer;
1405
1406         if (fdir_ret->status == VIRTCHNL_FDIR_SUCCESS) {
1407                 PMD_DRV_LOG(INFO,
1408                         "Succeed in deleting rule request by PF");
1409         } else if (fdir_ret->status == VIRTCHNL_FDIR_FAILURE_RULE_NONEXIST) {
1410                 PMD_DRV_LOG(ERR,
1411                         "Failed to delete rule request due to this rule doesn't exist");
1412                 return -1;
1413         } else if (fdir_ret->status == VIRTCHNL_FDIR_FAILURE_RULE_TIMEOUT) {
1414                 PMD_DRV_LOG(ERR,
1415                         "Failed to delete rule request due to time out for programming");
1416                 return -1;
1417         } else {
1418                 PMD_DRV_LOG(ERR,
1419                         "Failed to delete rule request due to other reasons");
1420                 return -1;
1421         }
1422
1423         return 0;
1424 };
1425
1426 int
1427 iavf_fdir_check(struct iavf_adapter *adapter,
1428                 struct iavf_fdir_conf *filter)
1429 {
1430         struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(adapter);
1431         struct virtchnl_fdir_add *fdir_ret;
1432
1433         struct iavf_cmd_info args;
1434         int err;
1435
1436         filter->add_fltr.vsi_id = vf->vsi_res->vsi_id;
1437         filter->add_fltr.validate_only = 1;
1438
1439         args.ops = VIRTCHNL_OP_ADD_FDIR_FILTER;
1440         args.in_args = (uint8_t *)(&filter->add_fltr);
1441         args.in_args_size = sizeof(*(&filter->add_fltr));
1442         args.out_buffer = vf->aq_resp;
1443         args.out_size = IAVF_AQ_BUF_SZ;
1444
1445         err = iavf_execute_vf_cmd(adapter, &args);
1446         if (err) {
1447                 PMD_DRV_LOG(ERR, "fail to check flow direcotor rule");
1448                 return err;
1449         }
1450
1451         fdir_ret = (struct virtchnl_fdir_add *)args.out_buffer;
1452
1453         if (fdir_ret->status == VIRTCHNL_FDIR_SUCCESS) {
1454                 PMD_DRV_LOG(INFO,
1455                         "Succeed in checking rule request by PF");
1456         } else if (fdir_ret->status == VIRTCHNL_FDIR_FAILURE_RULE_INVALID) {
1457                 PMD_DRV_LOG(ERR,
1458                         "Failed to check rule request due to parameters validation"
1459                         " or HW doesn't support");
1460                 return -1;
1461         } else {
1462                 PMD_DRV_LOG(ERR,
1463                         "Failed to check rule request due to other reasons");
1464                 return -1;
1465         }
1466
1467         return 0;
1468 }
1469
1470 int
1471 iavf_add_del_rss_cfg(struct iavf_adapter *adapter,
1472                      struct virtchnl_rss_cfg *rss_cfg, bool add)
1473 {
1474         struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(adapter);
1475         struct iavf_cmd_info args;
1476         int err;
1477
1478         memset(&args, 0, sizeof(args));
1479         args.ops = add ? VIRTCHNL_OP_ADD_RSS_CFG :
1480                 VIRTCHNL_OP_DEL_RSS_CFG;
1481         args.in_args = (u8 *)rss_cfg;
1482         args.in_args_size = sizeof(*rss_cfg);
1483         args.out_buffer = vf->aq_resp;
1484         args.out_size = IAVF_AQ_BUF_SZ;
1485
1486         err = iavf_execute_vf_cmd(adapter, &args);
1487         if (err)
1488                 PMD_DRV_LOG(ERR,
1489                             "Failed to execute command of %s",
1490                             add ? "OP_ADD_RSS_CFG" :
1491                             "OP_DEL_RSS_INPUT_CFG");
1492
1493         return err;
1494 }
1495
1496 int
1497 iavf_set_hena(struct iavf_adapter *adapter, uint64_t hena)
1498 {
1499         struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(adapter);
1500         struct virtchnl_rss_hena vrh;
1501         struct iavf_cmd_info args;
1502         int err;
1503
1504         vrh.hena = hena;
1505         args.ops = VIRTCHNL_OP_SET_RSS_HENA;
1506         args.in_args = (u8 *)&vrh;
1507         args.in_args_size = sizeof(vrh);
1508         args.out_buffer = vf->aq_resp;
1509         args.out_size = IAVF_AQ_BUF_SZ;
1510
1511         err = iavf_execute_vf_cmd(adapter, &args);
1512         if (err)
1513                 PMD_DRV_LOG(ERR,
1514                             "Failed to execute command of OP_SET_RSS_HENA");
1515
1516         return err;
1517 }
1518
1519 int
1520 iavf_add_del_mc_addr_list(struct iavf_adapter *adapter,
1521                         struct rte_ether_addr *mc_addrs,
1522                         uint32_t mc_addrs_num, bool add)
1523 {
1524         struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(adapter);
1525         uint8_t cmd_buffer[sizeof(struct virtchnl_ether_addr_list) +
1526                 (IAVF_NUM_MACADDR_MAX * sizeof(struct virtchnl_ether_addr))];
1527         struct virtchnl_ether_addr_list *list;
1528         struct iavf_cmd_info args;
1529         uint32_t i;
1530         int err;
1531
1532         if (mc_addrs == NULL || mc_addrs_num == 0)
1533                 return 0;
1534
1535         list = (struct virtchnl_ether_addr_list *)cmd_buffer;
1536         list->vsi_id = vf->vsi_res->vsi_id;
1537         list->num_elements = mc_addrs_num;
1538
1539         for (i = 0; i < mc_addrs_num; i++) {
1540                 if (!IAVF_IS_MULTICAST(mc_addrs[i].addr_bytes)) {
1541                         PMD_DRV_LOG(ERR, "Invalid mac:%x:%x:%x:%x:%x:%x",
1542                                     mc_addrs[i].addr_bytes[0],
1543                                     mc_addrs[i].addr_bytes[1],
1544                                     mc_addrs[i].addr_bytes[2],
1545                                     mc_addrs[i].addr_bytes[3],
1546                                     mc_addrs[i].addr_bytes[4],
1547                                     mc_addrs[i].addr_bytes[5]);
1548                         return -EINVAL;
1549                 }
1550
1551                 memcpy(list->list[i].addr, mc_addrs[i].addr_bytes,
1552                         sizeof(list->list[i].addr));
1553         }
1554
1555         args.ops = add ? VIRTCHNL_OP_ADD_ETH_ADDR : VIRTCHNL_OP_DEL_ETH_ADDR;
1556         args.in_args = cmd_buffer;
1557         args.in_args_size = sizeof(struct virtchnl_ether_addr_list) +
1558                 i * sizeof(struct virtchnl_ether_addr);
1559         args.out_buffer = vf->aq_resp;
1560         args.out_size = IAVF_AQ_BUF_SZ;
1561         err = iavf_execute_vf_cmd(adapter, &args);
1562
1563         if (err) {
1564                 PMD_DRV_LOG(ERR, "fail to execute command %s",
1565                         add ? "OP_ADD_ETH_ADDR" : "OP_DEL_ETH_ADDR");
1566                 return err;
1567         }
1568
1569         return 0;
1570 }
1571
1572 int
1573 iavf_request_queues(struct iavf_adapter *adapter, uint16_t num)
1574 {
1575         struct rte_eth_dev *dev = adapter->eth_dev;
1576         struct iavf_info *vf =  IAVF_DEV_PRIVATE_TO_VF(adapter);
1577         struct rte_pci_device *pci_dev = RTE_ETH_DEV_TO_PCI(dev);
1578         struct virtchnl_vf_res_request vfres;
1579         struct iavf_cmd_info args;
1580         uint16_t num_queue_pairs;
1581         int err;
1582
1583         if (!(vf->vf_res->vf_cap_flags &
1584                 VIRTCHNL_VF_OFFLOAD_REQ_QUEUES)) {
1585                 PMD_DRV_LOG(ERR, "request queues not supported");
1586                 return -1;
1587         }
1588
1589         if (num == 0) {
1590                 PMD_DRV_LOG(ERR, "queue number cannot be zero");
1591                 return -1;
1592         }
1593         vfres.num_queue_pairs = num;
1594
1595         args.ops = VIRTCHNL_OP_REQUEST_QUEUES;
1596         args.in_args = (u8 *)&vfres;
1597         args.in_args_size = sizeof(vfres);
1598         args.out_buffer = vf->aq_resp;
1599         args.out_size = IAVF_AQ_BUF_SZ;
1600
1601         /*
1602          * disable interrupt to avoid the admin queue message to be read
1603          * before iavf_read_msg_from_pf.
1604          */
1605         rte_intr_disable(&pci_dev->intr_handle);
1606         err = iavf_execute_vf_cmd(adapter, &args);
1607         rte_intr_enable(&pci_dev->intr_handle);
1608         if (err) {
1609                 PMD_DRV_LOG(ERR, "fail to execute command OP_REQUEST_QUEUES");
1610                 return err;
1611         }
1612
1613         /* request queues succeeded, vf is resetting */
1614         if (vf->vf_reset) {
1615                 PMD_DRV_LOG(INFO, "vf is resetting");
1616                 return 0;
1617         }
1618
1619         /* request additional queues failed, return available number */
1620         num_queue_pairs =
1621           ((struct virtchnl_vf_res_request *)args.out_buffer)->num_queue_pairs;
1622         PMD_DRV_LOG(ERR, "request queues failed, only %u queues "
1623                 "available", num_queue_pairs);
1624
1625         return -1;
1626 }
1627
1628 int
1629 iavf_get_max_rss_queue_region(struct iavf_adapter *adapter)
1630 {
1631         struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(adapter);
1632         struct iavf_cmd_info args;
1633         uint16_t qregion_width;
1634         int err;
1635
1636         args.ops = VIRTCHNL_OP_GET_MAX_RSS_QREGION;
1637         args.in_args = NULL;
1638         args.in_args_size = 0;
1639         args.out_buffer = vf->aq_resp;
1640         args.out_size = IAVF_AQ_BUF_SZ;
1641
1642         err = iavf_execute_vf_cmd(adapter, &args);
1643         if (err) {
1644                 PMD_DRV_LOG(ERR, "Failed to execute command of VIRTCHNL_OP_GET_MAX_RSS_QREGION");
1645                 return err;
1646         }
1647
1648         qregion_width =
1649         ((struct virtchnl_max_rss_qregion *)args.out_buffer)->qregion_width;
1650
1651         vf->max_rss_qregion = (uint16_t)(1 << qregion_width);
1652
1653         return 0;
1654 }