1 /* SPDX-License-Identifier: BSD-3-Clause
2 * Copyright(c) 2017 Intel Corporation
12 #include <rte_byteorder.h>
13 #include <rte_common.h>
15 #include <rte_debug.h>
16 #include <rte_alarm.h>
17 #include <rte_atomic.h>
19 #include <rte_ether.h>
20 #include <ethdev_driver.h>
21 #include <ethdev_pci.h>
25 #include "iavf_rxtx.h"
27 #define MAX_TRY_TIMES 200
28 #define ASQ_DELAY_MS 10
31 iavf_convert_link_speed(enum virtchnl_link_speed virt_link_speed)
35 switch (virt_link_speed) {
36 case VIRTCHNL_LINK_SPEED_100MB:
39 case VIRTCHNL_LINK_SPEED_1GB:
42 case VIRTCHNL_LINK_SPEED_10GB:
45 case VIRTCHNL_LINK_SPEED_40GB:
48 case VIRTCHNL_LINK_SPEED_20GB:
51 case VIRTCHNL_LINK_SPEED_25GB:
54 case VIRTCHNL_LINK_SPEED_2_5GB:
57 case VIRTCHNL_LINK_SPEED_5GB:
68 /* Read data in admin queue to get msg from pf driver */
69 static enum iavf_aq_result
70 iavf_read_msg_from_pf(struct iavf_adapter *adapter, uint16_t buf_len,
73 struct iavf_hw *hw = IAVF_DEV_PRIVATE_TO_HW(adapter);
74 struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(adapter);
75 struct rte_eth_dev *dev = adapter->eth_dev;
76 struct iavf_arq_event_info event;
77 enum iavf_aq_result result = IAVF_MSG_NON;
78 enum virtchnl_ops opcode;
81 event.buf_len = buf_len;
83 ret = iavf_clean_arq_element(hw, &event, NULL);
84 /* Can't read any msg from adminQ */
86 PMD_DRV_LOG(DEBUG, "Can't read msg from AQ");
87 if (ret != IAVF_ERR_ADMIN_QUEUE_NO_WORK)
88 result = IAVF_MSG_ERR;
92 opcode = (enum virtchnl_ops)rte_le_to_cpu_32(event.desc.cookie_high);
93 vf->cmd_retval = (enum virtchnl_status_code)rte_le_to_cpu_32(
94 event.desc.cookie_low);
96 PMD_DRV_LOG(DEBUG, "AQ from pf carries opcode %u, retval %d",
97 opcode, vf->cmd_retval);
99 if (opcode == VIRTCHNL_OP_EVENT) {
100 struct virtchnl_pf_event *vpe =
101 (struct virtchnl_pf_event *)event.msg_buf;
103 result = IAVF_MSG_SYS;
104 switch (vpe->event) {
105 case VIRTCHNL_EVENT_LINK_CHANGE:
107 vpe->event_data.link_event.link_status;
108 if (vf->vf_res->vf_cap_flags &
109 VIRTCHNL_VF_CAP_ADV_LINK_SPEED) {
111 vpe->event_data.link_event_adv.link_speed;
113 enum virtchnl_link_speed speed;
114 speed = vpe->event_data.link_event.link_speed;
115 vf->link_speed = iavf_convert_link_speed(speed);
117 iavf_dev_link_update(dev, 0);
118 PMD_DRV_LOG(INFO, "Link status update:%s",
119 vf->link_up ? "up" : "down");
121 case VIRTCHNL_EVENT_RESET_IMPENDING:
123 PMD_DRV_LOG(INFO, "VF is resetting");
125 case VIRTCHNL_EVENT_PF_DRIVER_CLOSE:
126 vf->dev_closed = true;
127 PMD_DRV_LOG(INFO, "PF driver closed");
130 PMD_DRV_LOG(ERR, "%s: Unknown event %d from pf",
131 __func__, vpe->event);
134 /* async reply msg on command issued by vf previously */
135 result = IAVF_MSG_CMD;
136 if (opcode != vf->pend_cmd) {
137 PMD_DRV_LOG(WARNING, "command mismatch, expect %u, get %u",
138 vf->pend_cmd, opcode);
139 result = IAVF_MSG_ERR;
147 iavf_execute_vf_cmd(struct iavf_adapter *adapter, struct iavf_cmd_info *args)
149 struct iavf_hw *hw = IAVF_DEV_PRIVATE_TO_HW(adapter);
150 struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(adapter);
151 enum iavf_aq_result result;
152 enum iavf_status ret;
159 if (_atomic_set_cmd(vf, args->ops))
162 ret = iavf_aq_send_msg_to_pf(hw, args->ops, IAVF_SUCCESS,
163 args->in_args, args->in_args_size, NULL);
165 PMD_DRV_LOG(ERR, "fail to send cmd %d", args->ops);
171 case VIRTCHNL_OP_RESET_VF:
172 /*no need to wait for response */
175 case VIRTCHNL_OP_VERSION:
176 case VIRTCHNL_OP_GET_VF_RESOURCES:
177 case VIRTCHNL_OP_GET_SUPPORTED_RXDIDS:
178 case VIRTCHNL_OP_GET_OFFLOAD_VLAN_V2_CAPS:
179 /* for init virtchnl ops, need to poll the response */
181 result = iavf_read_msg_from_pf(adapter, args->out_size,
183 if (result == IAVF_MSG_CMD)
185 iavf_msec_delay(ASQ_DELAY_MS);
186 } while (i++ < MAX_TRY_TIMES);
187 if (i >= MAX_TRY_TIMES ||
188 vf->cmd_retval != VIRTCHNL_STATUS_SUCCESS) {
190 PMD_DRV_LOG(ERR, "No response or return failure (%d)"
191 " for cmd %d", vf->cmd_retval, args->ops);
195 case VIRTCHNL_OP_REQUEST_QUEUES:
197 * ignore async reply, only wait for system message,
198 * vf_reset = true if get VIRTCHNL_EVENT_RESET_IMPENDING,
199 * if not, means request queues failed.
202 result = iavf_read_msg_from_pf(adapter, args->out_size,
204 if (result == IAVF_MSG_SYS && vf->vf_reset) {
206 } else if (result == IAVF_MSG_CMD ||
207 result == IAVF_MSG_ERR) {
211 iavf_msec_delay(ASQ_DELAY_MS);
212 /* If don't read msg or read sys event, continue */
213 } while (i++ < MAX_TRY_TIMES);
214 if (i >= MAX_TRY_TIMES ||
215 vf->cmd_retval != VIRTCHNL_STATUS_SUCCESS) {
217 PMD_DRV_LOG(ERR, "No response or return failure (%d)"
218 " for cmd %d", vf->cmd_retval, args->ops);
223 /* For other virtchnl ops in running time,
224 * wait for the cmd done flag.
227 if (vf->pend_cmd == VIRTCHNL_OP_UNKNOWN)
229 iavf_msec_delay(ASQ_DELAY_MS);
230 /* If don't read msg or read sys event, continue */
231 } while (i++ < MAX_TRY_TIMES);
233 if (i >= MAX_TRY_TIMES) {
234 PMD_DRV_LOG(ERR, "No response for cmd %d", args->ops);
237 } else if (vf->cmd_retval ==
238 VIRTCHNL_STATUS_ERR_NOT_SUPPORTED) {
239 PMD_DRV_LOG(ERR, "Cmd %d not supported", args->ops);
241 } else if (vf->cmd_retval != VIRTCHNL_STATUS_SUCCESS) {
242 PMD_DRV_LOG(ERR, "Return failure %d for cmd %d",
243 vf->cmd_retval, args->ops);
253 iavf_handle_pf_event_msg(struct rte_eth_dev *dev, uint8_t *msg,
256 struct virtchnl_pf_event *pf_msg =
257 (struct virtchnl_pf_event *)msg;
258 struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(dev->data->dev_private);
260 if (msglen < sizeof(struct virtchnl_pf_event)) {
261 PMD_DRV_LOG(DEBUG, "Error event");
264 switch (pf_msg->event) {
265 case VIRTCHNL_EVENT_RESET_IMPENDING:
266 PMD_DRV_LOG(DEBUG, "VIRTCHNL_EVENT_RESET_IMPENDING event");
268 rte_eth_dev_callback_process(dev, RTE_ETH_EVENT_INTR_RESET,
271 case VIRTCHNL_EVENT_LINK_CHANGE:
272 PMD_DRV_LOG(DEBUG, "VIRTCHNL_EVENT_LINK_CHANGE event");
273 vf->link_up = pf_msg->event_data.link_event.link_status;
274 if (vf->vf_res->vf_cap_flags & VIRTCHNL_VF_CAP_ADV_LINK_SPEED) {
276 pf_msg->event_data.link_event_adv.link_speed;
278 enum virtchnl_link_speed speed;
279 speed = pf_msg->event_data.link_event.link_speed;
280 vf->link_speed = iavf_convert_link_speed(speed);
282 iavf_dev_link_update(dev, 0);
283 rte_eth_dev_callback_process(dev, RTE_ETH_EVENT_INTR_LSC, NULL);
285 case VIRTCHNL_EVENT_PF_DRIVER_CLOSE:
286 PMD_DRV_LOG(DEBUG, "VIRTCHNL_EVENT_PF_DRIVER_CLOSE event");
289 PMD_DRV_LOG(ERR, " unknown event received %u", pf_msg->event);
295 iavf_handle_virtchnl_msg(struct rte_eth_dev *dev)
297 struct iavf_hw *hw = IAVF_DEV_PRIVATE_TO_HW(dev->data->dev_private);
298 struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(dev->data->dev_private);
299 struct iavf_arq_event_info info;
300 uint16_t pending, aq_opc;
301 enum virtchnl_ops msg_opc;
302 enum iavf_status msg_ret;
305 info.buf_len = IAVF_AQ_BUF_SZ;
307 PMD_DRV_LOG(ERR, "Buffer for adminq resp should not be NULL");
310 info.msg_buf = vf->aq_resp;
314 ret = iavf_clean_arq_element(hw, &info, &pending);
316 if (ret != IAVF_SUCCESS) {
317 PMD_DRV_LOG(INFO, "Failed to read msg from AdminQ,"
321 aq_opc = rte_le_to_cpu_16(info.desc.opcode);
322 /* For the message sent from pf to vf, opcode is stored in
323 * cookie_high of struct iavf_aq_desc, while return error code
324 * are stored in cookie_low, Which is done by PF driver.
326 msg_opc = (enum virtchnl_ops)rte_le_to_cpu_32(
327 info.desc.cookie_high);
328 msg_ret = (enum iavf_status)rte_le_to_cpu_32(
329 info.desc.cookie_low);
331 case iavf_aqc_opc_send_msg_to_vf:
332 if (msg_opc == VIRTCHNL_OP_EVENT) {
333 iavf_handle_pf_event_msg(dev, info.msg_buf,
336 /* read message and it's expected one */
337 if (msg_opc == vf->pend_cmd)
338 _notify_cmd(vf, msg_ret);
340 PMD_DRV_LOG(ERR, "command mismatch,"
342 vf->pend_cmd, msg_opc);
344 "adminq response is received,"
345 " opcode = %d", msg_opc);
349 PMD_DRV_LOG(DEBUG, "Request %u is not supported yet",
357 iavf_enable_vlan_strip(struct iavf_adapter *adapter)
359 struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(adapter);
360 struct iavf_cmd_info args;
363 memset(&args, 0, sizeof(args));
364 args.ops = VIRTCHNL_OP_ENABLE_VLAN_STRIPPING;
366 args.in_args_size = 0;
367 args.out_buffer = vf->aq_resp;
368 args.out_size = IAVF_AQ_BUF_SZ;
369 ret = iavf_execute_vf_cmd(adapter, &args);
371 PMD_DRV_LOG(ERR, "Failed to execute command of"
372 " OP_ENABLE_VLAN_STRIPPING");
378 iavf_disable_vlan_strip(struct iavf_adapter *adapter)
380 struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(adapter);
381 struct iavf_cmd_info args;
384 memset(&args, 0, sizeof(args));
385 args.ops = VIRTCHNL_OP_DISABLE_VLAN_STRIPPING;
387 args.in_args_size = 0;
388 args.out_buffer = vf->aq_resp;
389 args.out_size = IAVF_AQ_BUF_SZ;
390 ret = iavf_execute_vf_cmd(adapter, &args);
392 PMD_DRV_LOG(ERR, "Failed to execute command of"
393 " OP_DISABLE_VLAN_STRIPPING");
398 #define VIRTCHNL_VERSION_MAJOR_START 1
399 #define VIRTCHNL_VERSION_MINOR_START 1
401 /* Check API version with sync wait until version read from admin queue */
403 iavf_check_api_version(struct iavf_adapter *adapter)
405 struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(adapter);
406 struct virtchnl_version_info version, *pver;
407 struct iavf_cmd_info args;
410 version.major = VIRTCHNL_VERSION_MAJOR;
411 version.minor = VIRTCHNL_VERSION_MINOR;
413 args.ops = VIRTCHNL_OP_VERSION;
414 args.in_args = (uint8_t *)&version;
415 args.in_args_size = sizeof(version);
416 args.out_buffer = vf->aq_resp;
417 args.out_size = IAVF_AQ_BUF_SZ;
419 err = iavf_execute_vf_cmd(adapter, &args);
421 PMD_INIT_LOG(ERR, "Fail to execute command of OP_VERSION");
425 pver = (struct virtchnl_version_info *)args.out_buffer;
426 vf->virtchnl_version = *pver;
428 if (vf->virtchnl_version.major < VIRTCHNL_VERSION_MAJOR_START ||
429 (vf->virtchnl_version.major == VIRTCHNL_VERSION_MAJOR_START &&
430 vf->virtchnl_version.minor < VIRTCHNL_VERSION_MINOR_START)) {
431 PMD_INIT_LOG(ERR, "VIRTCHNL API version should not be lower"
432 " than (%u.%u) to support Adapative VF",
433 VIRTCHNL_VERSION_MAJOR_START,
434 VIRTCHNL_VERSION_MAJOR_START);
436 } else if (vf->virtchnl_version.major > VIRTCHNL_VERSION_MAJOR ||
437 (vf->virtchnl_version.major == VIRTCHNL_VERSION_MAJOR &&
438 vf->virtchnl_version.minor > VIRTCHNL_VERSION_MINOR)) {
439 PMD_INIT_LOG(ERR, "PF/VF API version mismatch:(%u.%u)-(%u.%u)",
440 vf->virtchnl_version.major,
441 vf->virtchnl_version.minor,
442 VIRTCHNL_VERSION_MAJOR,
443 VIRTCHNL_VERSION_MINOR);
447 PMD_DRV_LOG(DEBUG, "Peer is supported PF host");
452 iavf_get_vf_resource(struct iavf_adapter *adapter)
454 struct iavf_hw *hw = IAVF_DEV_PRIVATE_TO_HW(adapter);
455 struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(adapter);
456 struct iavf_cmd_info args;
460 args.ops = VIRTCHNL_OP_GET_VF_RESOURCES;
461 args.out_buffer = vf->aq_resp;
462 args.out_size = IAVF_AQ_BUF_SZ;
464 caps = IAVF_BASIC_OFFLOAD_CAPS | VIRTCHNL_VF_CAP_ADV_LINK_SPEED |
465 VIRTCHNL_VF_OFFLOAD_RX_FLEX_DESC |
466 VIRTCHNL_VF_OFFLOAD_FDIR_PF |
467 VIRTCHNL_VF_OFFLOAD_ADV_RSS_PF |
468 VIRTCHNL_VF_OFFLOAD_REQ_QUEUES |
469 VIRTCHNL_VF_OFFLOAD_CRC |
470 VIRTCHNL_VF_OFFLOAD_VLAN_V2 |
471 VIRTCHNL_VF_LARGE_NUM_QPAIRS |
472 VIRTCHNL_VF_OFFLOAD_QOS;
474 args.in_args = (uint8_t *)∩︀
475 args.in_args_size = sizeof(caps);
477 err = iavf_execute_vf_cmd(adapter, &args);
481 "Failed to execute command of OP_GET_VF_RESOURCE");
485 len = sizeof(struct virtchnl_vf_resource) +
486 IAVF_MAX_VF_VSI * sizeof(struct virtchnl_vsi_resource);
488 rte_memcpy(vf->vf_res, args.out_buffer,
489 RTE_MIN(args.out_size, len));
490 /* parse VF config message back from PF*/
491 iavf_vf_parse_hw_config(hw, vf->vf_res);
492 for (i = 0; i < vf->vf_res->num_vsis; i++) {
493 if (vf->vf_res->vsi_res[i].vsi_type == VIRTCHNL_VSI_SRIOV)
494 vf->vsi_res = &vf->vf_res->vsi_res[i];
498 PMD_INIT_LOG(ERR, "no LAN VSI found");
502 vf->vsi.vsi_id = vf->vsi_res->vsi_id;
503 vf->vsi.nb_qps = vf->vsi_res->num_queue_pairs;
504 vf->vsi.adapter = adapter;
510 iavf_get_supported_rxdid(struct iavf_adapter *adapter)
512 struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(adapter);
513 struct iavf_cmd_info args;
516 args.ops = VIRTCHNL_OP_GET_SUPPORTED_RXDIDS;
518 args.in_args_size = 0;
519 args.out_buffer = vf->aq_resp;
520 args.out_size = IAVF_AQ_BUF_SZ;
522 ret = iavf_execute_vf_cmd(adapter, &args);
525 "Failed to execute command of OP_GET_SUPPORTED_RXDIDS");
529 vf->supported_rxdid =
530 ((struct virtchnl_supported_rxdids *)args.out_buffer)->supported_rxdids;
536 iavf_config_vlan_strip_v2(struct iavf_adapter *adapter, bool enable)
538 struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(adapter);
539 struct virtchnl_vlan_supported_caps *stripping_caps;
540 struct virtchnl_vlan_setting vlan_strip;
541 struct iavf_cmd_info args;
545 stripping_caps = &vf->vlan_v2_caps.offloads.stripping_support;
547 if ((stripping_caps->outer & VIRTCHNL_VLAN_ETHERTYPE_8100) &&
548 (stripping_caps->outer & VIRTCHNL_VLAN_TOGGLE))
549 ethertype = &vlan_strip.outer_ethertype_setting;
550 else if ((stripping_caps->inner & VIRTCHNL_VLAN_ETHERTYPE_8100) &&
551 (stripping_caps->inner & VIRTCHNL_VLAN_TOGGLE))
552 ethertype = &vlan_strip.inner_ethertype_setting;
556 memset(&vlan_strip, 0, sizeof(vlan_strip));
557 vlan_strip.vport_id = vf->vsi_res->vsi_id;
558 *ethertype = VIRTCHNL_VLAN_ETHERTYPE_8100;
560 args.ops = enable ? VIRTCHNL_OP_ENABLE_VLAN_STRIPPING_V2 :
561 VIRTCHNL_OP_DISABLE_VLAN_STRIPPING_V2;
562 args.in_args = (uint8_t *)&vlan_strip;
563 args.in_args_size = sizeof(vlan_strip);
564 args.out_buffer = vf->aq_resp;
565 args.out_size = IAVF_AQ_BUF_SZ;
566 ret = iavf_execute_vf_cmd(adapter, &args);
568 PMD_DRV_LOG(ERR, "fail to execute command %s",
569 enable ? "VIRTCHNL_OP_ENABLE_VLAN_STRIPPING_V2" :
570 "VIRTCHNL_OP_DISABLE_VLAN_STRIPPING_V2");
576 iavf_config_vlan_insert_v2(struct iavf_adapter *adapter, bool enable)
578 struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(adapter);
579 struct virtchnl_vlan_supported_caps *insertion_caps;
580 struct virtchnl_vlan_setting vlan_insert;
581 struct iavf_cmd_info args;
585 insertion_caps = &vf->vlan_v2_caps.offloads.insertion_support;
587 if ((insertion_caps->outer & VIRTCHNL_VLAN_ETHERTYPE_8100) &&
588 (insertion_caps->outer & VIRTCHNL_VLAN_TOGGLE))
589 ethertype = &vlan_insert.outer_ethertype_setting;
590 else if ((insertion_caps->inner & VIRTCHNL_VLAN_ETHERTYPE_8100) &&
591 (insertion_caps->inner & VIRTCHNL_VLAN_TOGGLE))
592 ethertype = &vlan_insert.inner_ethertype_setting;
596 memset(&vlan_insert, 0, sizeof(vlan_insert));
597 vlan_insert.vport_id = vf->vsi_res->vsi_id;
598 *ethertype = VIRTCHNL_VLAN_ETHERTYPE_8100;
600 args.ops = enable ? VIRTCHNL_OP_ENABLE_VLAN_INSERTION_V2 :
601 VIRTCHNL_OP_DISABLE_VLAN_INSERTION_V2;
602 args.in_args = (uint8_t *)&vlan_insert;
603 args.in_args_size = sizeof(vlan_insert);
604 args.out_buffer = vf->aq_resp;
605 args.out_size = IAVF_AQ_BUF_SZ;
606 ret = iavf_execute_vf_cmd(adapter, &args);
608 PMD_DRV_LOG(ERR, "fail to execute command %s",
609 enable ? "VIRTCHNL_OP_ENABLE_VLAN_INSERTION_V2" :
610 "VIRTCHNL_OP_DISABLE_VLAN_INSERTION_V2");
616 iavf_add_del_vlan_v2(struct iavf_adapter *adapter, uint16_t vlanid, bool add)
618 struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(adapter);
619 struct virtchnl_vlan_supported_caps *supported_caps;
620 struct virtchnl_vlan_filter_list_v2 vlan_filter;
621 struct virtchnl_vlan *vlan_setting;
622 struct iavf_cmd_info args;
623 uint32_t filtering_caps;
626 supported_caps = &vf->vlan_v2_caps.filtering.filtering_support;
627 if (supported_caps->outer) {
628 filtering_caps = supported_caps->outer;
629 vlan_setting = &vlan_filter.filters[0].outer;
631 filtering_caps = supported_caps->inner;
632 vlan_setting = &vlan_filter.filters[0].inner;
635 if (!(filtering_caps & VIRTCHNL_VLAN_ETHERTYPE_8100))
638 memset(&vlan_filter, 0, sizeof(vlan_filter));
639 vlan_filter.vport_id = vf->vsi_res->vsi_id;
640 vlan_filter.num_elements = 1;
641 vlan_setting->tpid = RTE_ETHER_TYPE_VLAN;
642 vlan_setting->tci = vlanid;
644 args.ops = add ? VIRTCHNL_OP_ADD_VLAN_V2 : VIRTCHNL_OP_DEL_VLAN_V2;
645 args.in_args = (uint8_t *)&vlan_filter;
646 args.in_args_size = sizeof(vlan_filter);
647 args.out_buffer = vf->aq_resp;
648 args.out_size = IAVF_AQ_BUF_SZ;
649 err = iavf_execute_vf_cmd(adapter, &args);
651 PMD_DRV_LOG(ERR, "fail to execute command %s",
652 add ? "OP_ADD_VLAN_V2" : "OP_DEL_VLAN_V2");
658 iavf_get_vlan_offload_caps_v2(struct iavf_adapter *adapter)
660 struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(adapter);
661 struct iavf_cmd_info args;
664 args.ops = VIRTCHNL_OP_GET_OFFLOAD_VLAN_V2_CAPS;
666 args.in_args_size = 0;
667 args.out_buffer = vf->aq_resp;
668 args.out_size = IAVF_AQ_BUF_SZ;
670 ret = iavf_execute_vf_cmd(adapter, &args);
673 "Failed to execute command of VIRTCHNL_OP_GET_OFFLOAD_VLAN_V2_CAPS");
677 rte_memcpy(&vf->vlan_v2_caps, vf->aq_resp, sizeof(vf->vlan_v2_caps));
683 iavf_enable_queues(struct iavf_adapter *adapter)
685 struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(adapter);
686 struct virtchnl_queue_select queue_select;
687 struct iavf_cmd_info args;
690 memset(&queue_select, 0, sizeof(queue_select));
691 queue_select.vsi_id = vf->vsi_res->vsi_id;
693 queue_select.rx_queues = BIT(adapter->eth_dev->data->nb_rx_queues) - 1;
694 queue_select.tx_queues = BIT(adapter->eth_dev->data->nb_tx_queues) - 1;
696 args.ops = VIRTCHNL_OP_ENABLE_QUEUES;
697 args.in_args = (u8 *)&queue_select;
698 args.in_args_size = sizeof(queue_select);
699 args.out_buffer = vf->aq_resp;
700 args.out_size = IAVF_AQ_BUF_SZ;
701 err = iavf_execute_vf_cmd(adapter, &args);
704 "Failed to execute command of OP_ENABLE_QUEUES");
711 iavf_disable_queues(struct iavf_adapter *adapter)
713 struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(adapter);
714 struct virtchnl_queue_select queue_select;
715 struct iavf_cmd_info args;
718 memset(&queue_select, 0, sizeof(queue_select));
719 queue_select.vsi_id = vf->vsi_res->vsi_id;
721 queue_select.rx_queues = BIT(adapter->eth_dev->data->nb_rx_queues) - 1;
722 queue_select.tx_queues = BIT(adapter->eth_dev->data->nb_tx_queues) - 1;
724 args.ops = VIRTCHNL_OP_DISABLE_QUEUES;
725 args.in_args = (u8 *)&queue_select;
726 args.in_args_size = sizeof(queue_select);
727 args.out_buffer = vf->aq_resp;
728 args.out_size = IAVF_AQ_BUF_SZ;
729 err = iavf_execute_vf_cmd(adapter, &args);
732 "Failed to execute command of OP_DISABLE_QUEUES");
739 iavf_switch_queue(struct iavf_adapter *adapter, uint16_t qid,
742 struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(adapter);
743 struct virtchnl_queue_select queue_select;
744 struct iavf_cmd_info args;
747 memset(&queue_select, 0, sizeof(queue_select));
748 queue_select.vsi_id = vf->vsi_res->vsi_id;
750 queue_select.rx_queues |= 1 << qid;
752 queue_select.tx_queues |= 1 << qid;
755 args.ops = VIRTCHNL_OP_ENABLE_QUEUES;
757 args.ops = VIRTCHNL_OP_DISABLE_QUEUES;
758 args.in_args = (u8 *)&queue_select;
759 args.in_args_size = sizeof(queue_select);
760 args.out_buffer = vf->aq_resp;
761 args.out_size = IAVF_AQ_BUF_SZ;
762 err = iavf_execute_vf_cmd(adapter, &args);
764 PMD_DRV_LOG(ERR, "Failed to execute command of %s",
765 on ? "OP_ENABLE_QUEUES" : "OP_DISABLE_QUEUES");
770 iavf_enable_queues_lv(struct iavf_adapter *adapter)
772 struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(adapter);
773 struct virtchnl_del_ena_dis_queues *queue_select;
774 struct virtchnl_queue_chunk *queue_chunk;
775 struct iavf_cmd_info args;
778 len = sizeof(struct virtchnl_del_ena_dis_queues) +
779 sizeof(struct virtchnl_queue_chunk) *
780 (IAVF_RXTX_QUEUE_CHUNKS_NUM - 1);
781 queue_select = rte_zmalloc("queue_select", len, 0);
785 queue_chunk = queue_select->chunks.chunks;
786 queue_select->chunks.num_chunks = IAVF_RXTX_QUEUE_CHUNKS_NUM;
787 queue_select->vport_id = vf->vsi_res->vsi_id;
789 queue_chunk[VIRTCHNL_QUEUE_TYPE_TX].type = VIRTCHNL_QUEUE_TYPE_TX;
790 queue_chunk[VIRTCHNL_QUEUE_TYPE_TX].start_queue_id = 0;
791 queue_chunk[VIRTCHNL_QUEUE_TYPE_TX].num_queues =
792 adapter->eth_dev->data->nb_tx_queues;
794 queue_chunk[VIRTCHNL_QUEUE_TYPE_RX].type = VIRTCHNL_QUEUE_TYPE_RX;
795 queue_chunk[VIRTCHNL_QUEUE_TYPE_RX].start_queue_id = 0;
796 queue_chunk[VIRTCHNL_QUEUE_TYPE_RX].num_queues =
797 adapter->eth_dev->data->nb_rx_queues;
799 args.ops = VIRTCHNL_OP_ENABLE_QUEUES_V2;
800 args.in_args = (u8 *)queue_select;
801 args.in_args_size = len;
802 args.out_buffer = vf->aq_resp;
803 args.out_size = IAVF_AQ_BUF_SZ;
804 err = iavf_execute_vf_cmd(adapter, &args);
807 "Failed to execute command of OP_ENABLE_QUEUES_V2");
809 rte_free(queue_select);
814 iavf_disable_queues_lv(struct iavf_adapter *adapter)
816 struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(adapter);
817 struct virtchnl_del_ena_dis_queues *queue_select;
818 struct virtchnl_queue_chunk *queue_chunk;
819 struct iavf_cmd_info args;
822 len = sizeof(struct virtchnl_del_ena_dis_queues) +
823 sizeof(struct virtchnl_queue_chunk) *
824 (IAVF_RXTX_QUEUE_CHUNKS_NUM - 1);
825 queue_select = rte_zmalloc("queue_select", len, 0);
829 queue_chunk = queue_select->chunks.chunks;
830 queue_select->chunks.num_chunks = IAVF_RXTX_QUEUE_CHUNKS_NUM;
831 queue_select->vport_id = vf->vsi_res->vsi_id;
833 queue_chunk[VIRTCHNL_QUEUE_TYPE_TX].type = VIRTCHNL_QUEUE_TYPE_TX;
834 queue_chunk[VIRTCHNL_QUEUE_TYPE_TX].start_queue_id = 0;
835 queue_chunk[VIRTCHNL_QUEUE_TYPE_TX].num_queues =
836 adapter->eth_dev->data->nb_tx_queues;
838 queue_chunk[VIRTCHNL_QUEUE_TYPE_RX].type = VIRTCHNL_QUEUE_TYPE_RX;
839 queue_chunk[VIRTCHNL_QUEUE_TYPE_RX].start_queue_id = 0;
840 queue_chunk[VIRTCHNL_QUEUE_TYPE_RX].num_queues =
841 adapter->eth_dev->data->nb_rx_queues;
843 args.ops = VIRTCHNL_OP_DISABLE_QUEUES_V2;
844 args.in_args = (u8 *)queue_select;
845 args.in_args_size = len;
846 args.out_buffer = vf->aq_resp;
847 args.out_size = IAVF_AQ_BUF_SZ;
848 err = iavf_execute_vf_cmd(adapter, &args);
851 "Failed to execute command of OP_DISABLE_QUEUES_V2");
853 rte_free(queue_select);
858 iavf_switch_queue_lv(struct iavf_adapter *adapter, uint16_t qid,
861 struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(adapter);
862 struct virtchnl_del_ena_dis_queues *queue_select;
863 struct virtchnl_queue_chunk *queue_chunk;
864 struct iavf_cmd_info args;
867 len = sizeof(struct virtchnl_del_ena_dis_queues);
868 queue_select = rte_zmalloc("queue_select", len, 0);
872 queue_chunk = queue_select->chunks.chunks;
873 queue_select->chunks.num_chunks = 1;
874 queue_select->vport_id = vf->vsi_res->vsi_id;
877 queue_chunk->type = VIRTCHNL_QUEUE_TYPE_RX;
878 queue_chunk->start_queue_id = qid;
879 queue_chunk->num_queues = 1;
881 queue_chunk->type = VIRTCHNL_QUEUE_TYPE_TX;
882 queue_chunk->start_queue_id = qid;
883 queue_chunk->num_queues = 1;
887 args.ops = VIRTCHNL_OP_ENABLE_QUEUES_V2;
889 args.ops = VIRTCHNL_OP_DISABLE_QUEUES_V2;
890 args.in_args = (u8 *)queue_select;
891 args.in_args_size = len;
892 args.out_buffer = vf->aq_resp;
893 args.out_size = IAVF_AQ_BUF_SZ;
894 err = iavf_execute_vf_cmd(adapter, &args);
896 PMD_DRV_LOG(ERR, "Failed to execute command of %s",
897 on ? "OP_ENABLE_QUEUES_V2" : "OP_DISABLE_QUEUES_V2");
899 rte_free(queue_select);
904 iavf_configure_rss_lut(struct iavf_adapter *adapter)
906 struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(adapter);
907 struct virtchnl_rss_lut *rss_lut;
908 struct iavf_cmd_info args;
911 len = sizeof(*rss_lut) + vf->vf_res->rss_lut_size - 1;
912 rss_lut = rte_zmalloc("rss_lut", len, 0);
916 rss_lut->vsi_id = vf->vsi_res->vsi_id;
917 rss_lut->lut_entries = vf->vf_res->rss_lut_size;
918 rte_memcpy(rss_lut->lut, vf->rss_lut, vf->vf_res->rss_lut_size);
920 args.ops = VIRTCHNL_OP_CONFIG_RSS_LUT;
921 args.in_args = (u8 *)rss_lut;
922 args.in_args_size = len;
923 args.out_buffer = vf->aq_resp;
924 args.out_size = IAVF_AQ_BUF_SZ;
926 err = iavf_execute_vf_cmd(adapter, &args);
929 "Failed to execute command of OP_CONFIG_RSS_LUT");
936 iavf_configure_rss_key(struct iavf_adapter *adapter)
938 struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(adapter);
939 struct virtchnl_rss_key *rss_key;
940 struct iavf_cmd_info args;
943 len = sizeof(*rss_key) + vf->vf_res->rss_key_size - 1;
944 rss_key = rte_zmalloc("rss_key", len, 0);
948 rss_key->vsi_id = vf->vsi_res->vsi_id;
949 rss_key->key_len = vf->vf_res->rss_key_size;
950 rte_memcpy(rss_key->key, vf->rss_key, vf->vf_res->rss_key_size);
952 args.ops = VIRTCHNL_OP_CONFIG_RSS_KEY;
953 args.in_args = (u8 *)rss_key;
954 args.in_args_size = len;
955 args.out_buffer = vf->aq_resp;
956 args.out_size = IAVF_AQ_BUF_SZ;
958 err = iavf_execute_vf_cmd(adapter, &args);
961 "Failed to execute command of OP_CONFIG_RSS_KEY");
968 iavf_configure_queues(struct iavf_adapter *adapter,
969 uint16_t num_queue_pairs, uint16_t index)
971 struct iavf_rx_queue **rxq =
972 (struct iavf_rx_queue **)adapter->eth_dev->data->rx_queues;
973 struct iavf_tx_queue **txq =
974 (struct iavf_tx_queue **)adapter->eth_dev->data->tx_queues;
975 struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(adapter);
976 struct virtchnl_vsi_queue_config_info *vc_config;
977 struct virtchnl_queue_pair_info *vc_qp;
978 struct iavf_cmd_info args;
982 size = sizeof(*vc_config) +
983 sizeof(vc_config->qpair[0]) * num_queue_pairs;
984 vc_config = rte_zmalloc("cfg_queue", size, 0);
988 vc_config->vsi_id = vf->vsi_res->vsi_id;
989 vc_config->num_queue_pairs = num_queue_pairs;
991 for (i = index, vc_qp = vc_config->qpair;
992 i < index + num_queue_pairs;
994 vc_qp->txq.vsi_id = vf->vsi_res->vsi_id;
995 vc_qp->txq.queue_id = i;
997 /* Virtchnnl configure tx queues by pairs */
998 if (i < adapter->eth_dev->data->nb_tx_queues) {
999 vc_qp->txq.ring_len = txq[i]->nb_tx_desc;
1000 vc_qp->txq.dma_ring_addr = txq[i]->tx_ring_phys_addr;
1003 vc_qp->rxq.vsi_id = vf->vsi_res->vsi_id;
1004 vc_qp->rxq.queue_id = i;
1005 vc_qp->rxq.max_pkt_size = vf->max_pkt_len;
1007 if (i >= adapter->eth_dev->data->nb_rx_queues)
1010 /* Virtchnnl configure rx queues by pairs */
1011 vc_qp->rxq.ring_len = rxq[i]->nb_rx_desc;
1012 vc_qp->rxq.dma_ring_addr = rxq[i]->rx_ring_phys_addr;
1013 vc_qp->rxq.databuffer_size = rxq[i]->rx_buf_len;
1014 vc_qp->rxq.crc_disable = rxq[i]->crc_len != 0 ? 1 : 0;
1015 #ifndef RTE_LIBRTE_IAVF_16BYTE_RX_DESC
1016 if (vf->vf_res->vf_cap_flags &
1017 VIRTCHNL_VF_OFFLOAD_RX_FLEX_DESC &&
1018 vf->supported_rxdid & BIT(rxq[i]->rxdid)) {
1019 vc_qp->rxq.rxdid = rxq[i]->rxdid;
1020 PMD_DRV_LOG(NOTICE, "request RXDID[%d] in Queue[%d]",
1021 vc_qp->rxq.rxdid, i);
1023 PMD_DRV_LOG(NOTICE, "RXDID[%d] is not supported, "
1024 "request default RXDID[%d] in Queue[%d]",
1025 rxq[i]->rxdid, IAVF_RXDID_LEGACY_1, i);
1026 vc_qp->rxq.rxdid = IAVF_RXDID_LEGACY_1;
1029 if (vf->vf_res->vf_cap_flags &
1030 VIRTCHNL_VF_OFFLOAD_RX_FLEX_DESC &&
1031 vf->supported_rxdid & BIT(IAVF_RXDID_LEGACY_0)) {
1032 vc_qp->rxq.rxdid = IAVF_RXDID_LEGACY_0;
1033 PMD_DRV_LOG(NOTICE, "request RXDID[%d] in Queue[%d]",
1034 vc_qp->rxq.rxdid, i);
1036 PMD_DRV_LOG(ERR, "RXDID[%d] is not supported",
1037 IAVF_RXDID_LEGACY_0);
1043 memset(&args, 0, sizeof(args));
1044 args.ops = VIRTCHNL_OP_CONFIG_VSI_QUEUES;
1045 args.in_args = (uint8_t *)vc_config;
1046 args.in_args_size = size;
1047 args.out_buffer = vf->aq_resp;
1048 args.out_size = IAVF_AQ_BUF_SZ;
1050 err = iavf_execute_vf_cmd(adapter, &args);
1052 PMD_DRV_LOG(ERR, "Failed to execute command of"
1053 " VIRTCHNL_OP_CONFIG_VSI_QUEUES");
1055 rte_free(vc_config);
1060 iavf_config_irq_map(struct iavf_adapter *adapter)
1062 struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(adapter);
1063 struct virtchnl_irq_map_info *map_info;
1064 struct virtchnl_vector_map *vecmap;
1065 struct iavf_cmd_info args;
1068 len = sizeof(struct virtchnl_irq_map_info) +
1069 sizeof(struct virtchnl_vector_map) * vf->nb_msix;
1071 map_info = rte_zmalloc("map_info", len, 0);
1075 map_info->num_vectors = vf->nb_msix;
1076 for (i = 0; i < adapter->eth_dev->data->nb_rx_queues; i++) {
1078 &map_info->vecmap[vf->qv_map[i].vector_id - vf->msix_base];
1079 vecmap->vsi_id = vf->vsi_res->vsi_id;
1080 vecmap->rxitr_idx = IAVF_ITR_INDEX_DEFAULT;
1081 vecmap->vector_id = vf->qv_map[i].vector_id;
1082 vecmap->txq_map = 0;
1083 vecmap->rxq_map |= 1 << vf->qv_map[i].queue_id;
1086 args.ops = VIRTCHNL_OP_CONFIG_IRQ_MAP;
1087 args.in_args = (u8 *)map_info;
1088 args.in_args_size = len;
1089 args.out_buffer = vf->aq_resp;
1090 args.out_size = IAVF_AQ_BUF_SZ;
1091 err = iavf_execute_vf_cmd(adapter, &args);
1093 PMD_DRV_LOG(ERR, "fail to execute command OP_CONFIG_IRQ_MAP");
1100 iavf_config_irq_map_lv(struct iavf_adapter *adapter, uint16_t num,
1103 struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(adapter);
1104 struct virtchnl_queue_vector_maps *map_info;
1105 struct virtchnl_queue_vector *qv_maps;
1106 struct iavf_cmd_info args;
1110 len = sizeof(struct virtchnl_queue_vector_maps) +
1111 sizeof(struct virtchnl_queue_vector) * (num - 1);
1113 map_info = rte_zmalloc("map_info", len, 0);
1117 map_info->vport_id = vf->vsi_res->vsi_id;
1118 map_info->num_qv_maps = num;
1119 for (i = index; i < index + map_info->num_qv_maps; i++) {
1120 qv_maps = &map_info->qv_maps[count++];
1121 qv_maps->itr_idx = VIRTCHNL_ITR_IDX_0;
1122 qv_maps->queue_type = VIRTCHNL_QUEUE_TYPE_RX;
1123 qv_maps->queue_id = vf->qv_map[i].queue_id;
1124 qv_maps->vector_id = vf->qv_map[i].vector_id;
1127 args.ops = VIRTCHNL_OP_MAP_QUEUE_VECTOR;
1128 args.in_args = (u8 *)map_info;
1129 args.in_args_size = len;
1130 args.out_buffer = vf->aq_resp;
1131 args.out_size = IAVF_AQ_BUF_SZ;
1132 err = iavf_execute_vf_cmd(adapter, &args);
1134 PMD_DRV_LOG(ERR, "fail to execute command OP_MAP_QUEUE_VECTOR");
1141 iavf_add_del_all_mac_addr(struct iavf_adapter *adapter, bool add)
1143 struct virtchnl_ether_addr_list *list;
1144 struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(adapter);
1145 struct rte_ether_addr *addr;
1146 struct iavf_cmd_info args;
1153 len = sizeof(struct virtchnl_ether_addr_list);
1154 for (i = begin; i < IAVF_NUM_MACADDR_MAX; i++, next_begin++) {
1155 addr = &adapter->eth_dev->data->mac_addrs[i];
1156 if (rte_is_zero_ether_addr(addr))
1158 len += sizeof(struct virtchnl_ether_addr);
1159 if (len >= IAVF_AQ_BUF_SZ) {
1165 list = rte_zmalloc("iavf_del_mac_buffer", len, 0);
1167 PMD_DRV_LOG(ERR, "fail to allocate memory");
1171 for (i = begin; i < next_begin; i++) {
1172 addr = &adapter->eth_dev->data->mac_addrs[i];
1173 if (rte_is_zero_ether_addr(addr))
1175 rte_memcpy(list->list[j].addr, addr->addr_bytes,
1176 sizeof(addr->addr_bytes));
1177 list->list[j].type = (j == 0 ?
1178 VIRTCHNL_ETHER_ADDR_PRIMARY :
1179 VIRTCHNL_ETHER_ADDR_EXTRA);
1180 PMD_DRV_LOG(DEBUG, "add/rm mac:" RTE_ETHER_ADDR_PRT_FMT,
1181 RTE_ETHER_ADDR_BYTES(addr));
1184 list->vsi_id = vf->vsi_res->vsi_id;
1185 list->num_elements = j;
1186 args.ops = add ? VIRTCHNL_OP_ADD_ETH_ADDR :
1187 VIRTCHNL_OP_DEL_ETH_ADDR;
1188 args.in_args = (uint8_t *)list;
1189 args.in_args_size = len;
1190 args.out_buffer = vf->aq_resp;
1191 args.out_size = IAVF_AQ_BUF_SZ;
1192 err = iavf_execute_vf_cmd(adapter, &args);
1194 PMD_DRV_LOG(ERR, "fail to execute command %s",
1195 add ? "OP_ADD_ETHER_ADDRESS" :
1196 "OP_DEL_ETHER_ADDRESS");
1199 } while (begin < IAVF_NUM_MACADDR_MAX);
1203 iavf_query_stats(struct iavf_adapter *adapter,
1204 struct virtchnl_eth_stats **pstats)
1206 struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(adapter);
1207 struct virtchnl_queue_select q_stats;
1208 struct iavf_cmd_info args;
1211 memset(&q_stats, 0, sizeof(q_stats));
1212 q_stats.vsi_id = vf->vsi_res->vsi_id;
1213 args.ops = VIRTCHNL_OP_GET_STATS;
1214 args.in_args = (uint8_t *)&q_stats;
1215 args.in_args_size = sizeof(q_stats);
1216 args.out_buffer = vf->aq_resp;
1217 args.out_size = IAVF_AQ_BUF_SZ;
1219 err = iavf_execute_vf_cmd(adapter, &args);
1221 PMD_DRV_LOG(ERR, "fail to execute command OP_GET_STATS");
1225 *pstats = (struct virtchnl_eth_stats *)args.out_buffer;
1230 iavf_config_promisc(struct iavf_adapter *adapter,
1231 bool enable_unicast,
1232 bool enable_multicast)
1234 struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(adapter);
1235 struct virtchnl_promisc_info promisc;
1236 struct iavf_cmd_info args;
1240 promisc.vsi_id = vf->vsi_res->vsi_id;
1243 promisc.flags |= FLAG_VF_UNICAST_PROMISC;
1245 if (enable_multicast)
1246 promisc.flags |= FLAG_VF_MULTICAST_PROMISC;
1248 args.ops = VIRTCHNL_OP_CONFIG_PROMISCUOUS_MODE;
1249 args.in_args = (uint8_t *)&promisc;
1250 args.in_args_size = sizeof(promisc);
1251 args.out_buffer = vf->aq_resp;
1252 args.out_size = IAVF_AQ_BUF_SZ;
1254 err = iavf_execute_vf_cmd(adapter, &args);
1258 "fail to execute command CONFIG_PROMISCUOUS_MODE");
1260 if (err == -ENOTSUP)
1266 vf->promisc_unicast_enabled = enable_unicast;
1267 vf->promisc_multicast_enabled = enable_multicast;
1272 iavf_add_del_eth_addr(struct iavf_adapter *adapter, struct rte_ether_addr *addr,
1273 bool add, uint8_t type)
1275 struct virtchnl_ether_addr_list *list;
1276 struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(adapter);
1277 uint8_t cmd_buffer[sizeof(struct virtchnl_ether_addr_list) +
1278 sizeof(struct virtchnl_ether_addr)];
1279 struct iavf_cmd_info args;
1282 list = (struct virtchnl_ether_addr_list *)cmd_buffer;
1283 list->vsi_id = vf->vsi_res->vsi_id;
1284 list->num_elements = 1;
1285 list->list[0].type = type;
1286 rte_memcpy(list->list[0].addr, addr->addr_bytes,
1287 sizeof(addr->addr_bytes));
1289 args.ops = add ? VIRTCHNL_OP_ADD_ETH_ADDR : VIRTCHNL_OP_DEL_ETH_ADDR;
1290 args.in_args = cmd_buffer;
1291 args.in_args_size = sizeof(cmd_buffer);
1292 args.out_buffer = vf->aq_resp;
1293 args.out_size = IAVF_AQ_BUF_SZ;
1294 err = iavf_execute_vf_cmd(adapter, &args);
1296 PMD_DRV_LOG(ERR, "fail to execute command %s",
1297 add ? "OP_ADD_ETH_ADDR" : "OP_DEL_ETH_ADDR");
1302 iavf_add_del_vlan(struct iavf_adapter *adapter, uint16_t vlanid, bool add)
1304 struct virtchnl_vlan_filter_list *vlan_list;
1305 struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(adapter);
1306 uint8_t cmd_buffer[sizeof(struct virtchnl_vlan_filter_list) +
1308 struct iavf_cmd_info args;
1311 vlan_list = (struct virtchnl_vlan_filter_list *)cmd_buffer;
1312 vlan_list->vsi_id = vf->vsi_res->vsi_id;
1313 vlan_list->num_elements = 1;
1314 vlan_list->vlan_id[0] = vlanid;
1316 args.ops = add ? VIRTCHNL_OP_ADD_VLAN : VIRTCHNL_OP_DEL_VLAN;
1317 args.in_args = cmd_buffer;
1318 args.in_args_size = sizeof(cmd_buffer);
1319 args.out_buffer = vf->aq_resp;
1320 args.out_size = IAVF_AQ_BUF_SZ;
1321 err = iavf_execute_vf_cmd(adapter, &args);
1323 PMD_DRV_LOG(ERR, "fail to execute command %s",
1324 add ? "OP_ADD_VLAN" : "OP_DEL_VLAN");
1330 iavf_fdir_add(struct iavf_adapter *adapter,
1331 struct iavf_fdir_conf *filter)
1333 struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(adapter);
1334 struct virtchnl_fdir_add *fdir_ret;
1336 struct iavf_cmd_info args;
1339 filter->add_fltr.vsi_id = vf->vsi_res->vsi_id;
1340 filter->add_fltr.validate_only = 0;
1342 args.ops = VIRTCHNL_OP_ADD_FDIR_FILTER;
1343 args.in_args = (uint8_t *)(&filter->add_fltr);
1344 args.in_args_size = sizeof(*(&filter->add_fltr));
1345 args.out_buffer = vf->aq_resp;
1346 args.out_size = IAVF_AQ_BUF_SZ;
1348 err = iavf_execute_vf_cmd(adapter, &args);
1350 PMD_DRV_LOG(ERR, "fail to execute command OP_ADD_FDIR_FILTER");
1354 fdir_ret = (struct virtchnl_fdir_add *)args.out_buffer;
1355 filter->flow_id = fdir_ret->flow_id;
1357 if (fdir_ret->status == VIRTCHNL_FDIR_SUCCESS) {
1359 "Succeed in adding rule request by PF");
1360 } else if (fdir_ret->status == VIRTCHNL_FDIR_FAILURE_RULE_NORESOURCE) {
1362 "Failed to add rule request due to no hw resource");
1364 } else if (fdir_ret->status == VIRTCHNL_FDIR_FAILURE_RULE_EXIST) {
1366 "Failed to add rule request due to the rule is already existed");
1368 } else if (fdir_ret->status == VIRTCHNL_FDIR_FAILURE_RULE_CONFLICT) {
1370 "Failed to add rule request due to the rule is conflict with existing rule");
1372 } else if (fdir_ret->status == VIRTCHNL_FDIR_FAILURE_RULE_INVALID) {
1374 "Failed to add rule request due to the hw doesn't support");
1376 } else if (fdir_ret->status == VIRTCHNL_FDIR_FAILURE_RULE_TIMEOUT) {
1378 "Failed to add rule request due to time out for programming");
1382 "Failed to add rule request due to other reasons");
1390 iavf_fdir_del(struct iavf_adapter *adapter,
1391 struct iavf_fdir_conf *filter)
1393 struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(adapter);
1394 struct virtchnl_fdir_del *fdir_ret;
1396 struct iavf_cmd_info args;
1399 filter->del_fltr.vsi_id = vf->vsi_res->vsi_id;
1400 filter->del_fltr.flow_id = filter->flow_id;
1402 args.ops = VIRTCHNL_OP_DEL_FDIR_FILTER;
1403 args.in_args = (uint8_t *)(&filter->del_fltr);
1404 args.in_args_size = sizeof(filter->del_fltr);
1405 args.out_buffer = vf->aq_resp;
1406 args.out_size = IAVF_AQ_BUF_SZ;
1408 err = iavf_execute_vf_cmd(adapter, &args);
1410 PMD_DRV_LOG(ERR, "fail to execute command OP_DEL_FDIR_FILTER");
1414 fdir_ret = (struct virtchnl_fdir_del *)args.out_buffer;
1416 if (fdir_ret->status == VIRTCHNL_FDIR_SUCCESS) {
1418 "Succeed in deleting rule request by PF");
1419 } else if (fdir_ret->status == VIRTCHNL_FDIR_FAILURE_RULE_NONEXIST) {
1421 "Failed to delete rule request due to this rule doesn't exist");
1423 } else if (fdir_ret->status == VIRTCHNL_FDIR_FAILURE_RULE_TIMEOUT) {
1425 "Failed to delete rule request due to time out for programming");
1429 "Failed to delete rule request due to other reasons");
1437 iavf_fdir_check(struct iavf_adapter *adapter,
1438 struct iavf_fdir_conf *filter)
1440 struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(adapter);
1441 struct virtchnl_fdir_add *fdir_ret;
1443 struct iavf_cmd_info args;
1446 filter->add_fltr.vsi_id = vf->vsi_res->vsi_id;
1447 filter->add_fltr.validate_only = 1;
1449 args.ops = VIRTCHNL_OP_ADD_FDIR_FILTER;
1450 args.in_args = (uint8_t *)(&filter->add_fltr);
1451 args.in_args_size = sizeof(*(&filter->add_fltr));
1452 args.out_buffer = vf->aq_resp;
1453 args.out_size = IAVF_AQ_BUF_SZ;
1455 err = iavf_execute_vf_cmd(adapter, &args);
1457 PMD_DRV_LOG(ERR, "fail to check flow direcotor rule");
1461 fdir_ret = (struct virtchnl_fdir_add *)args.out_buffer;
1463 if (fdir_ret->status == VIRTCHNL_FDIR_SUCCESS) {
1465 "Succeed in checking rule request by PF");
1466 } else if (fdir_ret->status == VIRTCHNL_FDIR_FAILURE_RULE_INVALID) {
1468 "Failed to check rule request due to parameters validation"
1469 " or HW doesn't support");
1473 "Failed to check rule request due to other reasons");
1481 iavf_add_del_rss_cfg(struct iavf_adapter *adapter,
1482 struct virtchnl_rss_cfg *rss_cfg, bool add)
1484 struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(adapter);
1485 struct iavf_cmd_info args;
1488 memset(&args, 0, sizeof(args));
1489 args.ops = add ? VIRTCHNL_OP_ADD_RSS_CFG :
1490 VIRTCHNL_OP_DEL_RSS_CFG;
1491 args.in_args = (u8 *)rss_cfg;
1492 args.in_args_size = sizeof(*rss_cfg);
1493 args.out_buffer = vf->aq_resp;
1494 args.out_size = IAVF_AQ_BUF_SZ;
1496 err = iavf_execute_vf_cmd(adapter, &args);
1499 "Failed to execute command of %s",
1500 add ? "OP_ADD_RSS_CFG" :
1501 "OP_DEL_RSS_INPUT_CFG");
1507 iavf_get_hena_caps(struct iavf_adapter *adapter, uint64_t *caps)
1509 struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(adapter);
1510 struct iavf_cmd_info args;
1513 args.ops = VIRTCHNL_OP_GET_RSS_HENA_CAPS;
1514 args.in_args = NULL;
1515 args.in_args_size = 0;
1516 args.out_buffer = vf->aq_resp;
1517 args.out_size = IAVF_AQ_BUF_SZ;
1519 err = iavf_execute_vf_cmd(adapter, &args);
1522 "Failed to execute command of OP_GET_RSS_HENA_CAPS");
1526 *caps = ((struct virtchnl_rss_hena *)args.out_buffer)->hena;
1531 iavf_set_hena(struct iavf_adapter *adapter, uint64_t hena)
1533 struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(adapter);
1534 struct virtchnl_rss_hena vrh;
1535 struct iavf_cmd_info args;
1539 args.ops = VIRTCHNL_OP_SET_RSS_HENA;
1540 args.in_args = (u8 *)&vrh;
1541 args.in_args_size = sizeof(vrh);
1542 args.out_buffer = vf->aq_resp;
1543 args.out_size = IAVF_AQ_BUF_SZ;
1545 err = iavf_execute_vf_cmd(adapter, &args);
1548 "Failed to execute command of OP_SET_RSS_HENA");
1554 iavf_get_qos_cap(struct iavf_adapter *adapter)
1556 struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(adapter);
1557 struct iavf_cmd_info args;
1561 args.ops = VIRTCHNL_OP_GET_QOS_CAPS;
1562 args.in_args = NULL;
1563 args.in_args_size = 0;
1564 args.out_buffer = vf->aq_resp;
1565 args.out_size = IAVF_AQ_BUF_SZ;
1566 err = iavf_execute_vf_cmd(adapter, &args);
1570 "Failed to execute command of OP_GET_VF_RESOURCE");
1574 len = sizeof(struct virtchnl_qos_cap_list) +
1575 IAVF_MAX_TRAFFIC_CLASS * sizeof(struct virtchnl_qos_cap_elem);
1577 rte_memcpy(vf->qos_cap, args.out_buffer,
1578 RTE_MIN(args.out_size, len));
1583 int iavf_set_q_tc_map(struct rte_eth_dev *dev,
1584 struct virtchnl_queue_tc_mapping *q_tc_mapping, uint16_t size)
1586 struct iavf_adapter *adapter =
1587 IAVF_DEV_PRIVATE_TO_ADAPTER(dev->data->dev_private);
1588 struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(dev->data->dev_private);
1589 struct iavf_cmd_info args;
1592 memset(&args, 0, sizeof(args));
1593 args.ops = VIRTCHNL_OP_CONFIG_QUEUE_TC_MAP;
1594 args.in_args = (uint8_t *)q_tc_mapping;
1595 args.in_args_size = size;
1596 args.out_buffer = vf->aq_resp;
1597 args.out_size = IAVF_AQ_BUF_SZ;
1599 err = iavf_execute_vf_cmd(adapter, &args);
1601 PMD_DRV_LOG(ERR, "Failed to execute command of"
1602 " VIRTCHNL_OP_CONFIG_TC_MAP");
1607 iavf_add_del_mc_addr_list(struct iavf_adapter *adapter,
1608 struct rte_ether_addr *mc_addrs,
1609 uint32_t mc_addrs_num, bool add)
1611 struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(adapter);
1612 uint8_t cmd_buffer[sizeof(struct virtchnl_ether_addr_list) +
1613 (IAVF_NUM_MACADDR_MAX * sizeof(struct virtchnl_ether_addr))];
1614 struct virtchnl_ether_addr_list *list;
1615 struct iavf_cmd_info args;
1619 if (mc_addrs == NULL || mc_addrs_num == 0)
1622 list = (struct virtchnl_ether_addr_list *)cmd_buffer;
1623 list->vsi_id = vf->vsi_res->vsi_id;
1624 list->num_elements = mc_addrs_num;
1626 for (i = 0; i < mc_addrs_num; i++) {
1627 if (!IAVF_IS_MULTICAST(mc_addrs[i].addr_bytes)) {
1628 PMD_DRV_LOG(ERR, "Invalid mac:" RTE_ETHER_ADDR_PRT_FMT,
1629 RTE_ETHER_ADDR_BYTES(&mc_addrs[i]));
1633 memcpy(list->list[i].addr, mc_addrs[i].addr_bytes,
1634 sizeof(list->list[i].addr));
1635 list->list[i].type = VIRTCHNL_ETHER_ADDR_EXTRA;
1638 args.ops = add ? VIRTCHNL_OP_ADD_ETH_ADDR : VIRTCHNL_OP_DEL_ETH_ADDR;
1639 args.in_args = cmd_buffer;
1640 args.in_args_size = sizeof(struct virtchnl_ether_addr_list) +
1641 i * sizeof(struct virtchnl_ether_addr);
1642 args.out_buffer = vf->aq_resp;
1643 args.out_size = IAVF_AQ_BUF_SZ;
1644 err = iavf_execute_vf_cmd(adapter, &args);
1647 PMD_DRV_LOG(ERR, "fail to execute command %s",
1648 add ? "OP_ADD_ETH_ADDR" : "OP_DEL_ETH_ADDR");
1656 iavf_request_queues(struct iavf_adapter *adapter, uint16_t num)
1658 struct rte_eth_dev *dev = adapter->eth_dev;
1659 struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(adapter);
1660 struct rte_pci_device *pci_dev = RTE_ETH_DEV_TO_PCI(dev);
1661 struct virtchnl_vf_res_request vfres;
1662 struct iavf_cmd_info args;
1663 uint16_t num_queue_pairs;
1666 if (!(vf->vf_res->vf_cap_flags &
1667 VIRTCHNL_VF_OFFLOAD_REQ_QUEUES)) {
1668 PMD_DRV_LOG(ERR, "request queues not supported");
1673 PMD_DRV_LOG(ERR, "queue number cannot be zero");
1676 vfres.num_queue_pairs = num;
1678 args.ops = VIRTCHNL_OP_REQUEST_QUEUES;
1679 args.in_args = (u8 *)&vfres;
1680 args.in_args_size = sizeof(vfres);
1681 args.out_buffer = vf->aq_resp;
1682 args.out_size = IAVF_AQ_BUF_SZ;
1684 if (vf->vf_res->vf_cap_flags & VIRTCHNL_VF_OFFLOAD_WB_ON_ITR) {
1685 /* disable interrupt to avoid the admin queue message to be read
1686 * before iavf_read_msg_from_pf.
1688 rte_intr_disable(&pci_dev->intr_handle);
1689 err = iavf_execute_vf_cmd(adapter, &args);
1690 rte_intr_enable(&pci_dev->intr_handle);
1692 rte_eal_alarm_cancel(iavf_dev_alarm_handler, dev);
1693 err = iavf_execute_vf_cmd(adapter, &args);
1694 rte_eal_alarm_set(IAVF_ALARM_INTERVAL,
1695 iavf_dev_alarm_handler, dev);
1699 PMD_DRV_LOG(ERR, "fail to execute command OP_REQUEST_QUEUES");
1703 /* request queues succeeded, vf is resetting */
1705 PMD_DRV_LOG(INFO, "vf is resetting");
1709 /* request additional queues failed, return available number */
1711 ((struct virtchnl_vf_res_request *)args.out_buffer)->num_queue_pairs;
1712 PMD_DRV_LOG(ERR, "request queues failed, only %u queues "
1713 "available", num_queue_pairs);
1719 iavf_get_max_rss_queue_region(struct iavf_adapter *adapter)
1721 struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(adapter);
1722 struct iavf_cmd_info args;
1723 uint16_t qregion_width;
1726 args.ops = VIRTCHNL_OP_GET_MAX_RSS_QREGION;
1727 args.in_args = NULL;
1728 args.in_args_size = 0;
1729 args.out_buffer = vf->aq_resp;
1730 args.out_size = IAVF_AQ_BUF_SZ;
1732 err = iavf_execute_vf_cmd(adapter, &args);
1734 PMD_DRV_LOG(ERR, "Failed to execute command of VIRTCHNL_OP_GET_MAX_RSS_QREGION");
1739 ((struct virtchnl_max_rss_qregion *)args.out_buffer)->qregion_width;
1741 vf->max_rss_qregion = (uint16_t)(1 << qregion_width);