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 2000
28 #define ASQ_DELAY_MS 1
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 iavf_arq_event_info event;
76 enum iavf_aq_result result = IAVF_MSG_NON;
77 enum virtchnl_ops opcode;
80 event.buf_len = buf_len;
82 ret = iavf_clean_arq_element(hw, &event, NULL);
83 /* Can't read any msg from adminQ */
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;
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);
95 PMD_DRV_LOG(DEBUG, "AQ from pf carries opcode %u, retval %d",
96 opcode, vf->cmd_retval);
98 if (opcode == VIRTCHNL_OP_EVENT) {
99 struct virtchnl_pf_event *vpe =
100 (struct virtchnl_pf_event *)event.msg_buf;
102 result = IAVF_MSG_SYS;
103 switch (vpe->event) {
104 case VIRTCHNL_EVENT_LINK_CHANGE:
106 vpe->event_data.link_event.link_status;
107 if (vf->vf_res->vf_cap_flags &
108 VIRTCHNL_VF_CAP_ADV_LINK_SPEED) {
110 vpe->event_data.link_event_adv.link_speed;
112 enum virtchnl_link_speed speed;
113 speed = vpe->event_data.link_event.link_speed;
114 vf->link_speed = iavf_convert_link_speed(speed);
116 iavf_dev_link_update(vf->eth_dev, 0);
117 PMD_DRV_LOG(INFO, "Link status update:%s",
118 vf->link_up ? "up" : "down");
120 case VIRTCHNL_EVENT_RESET_IMPENDING:
122 PMD_DRV_LOG(INFO, "VF is resetting");
124 case VIRTCHNL_EVENT_PF_DRIVER_CLOSE:
125 vf->dev_closed = true;
126 PMD_DRV_LOG(INFO, "PF driver closed");
129 PMD_DRV_LOG(ERR, "%s: Unknown event %d from pf",
130 __func__, vpe->event);
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;
146 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;
161 if (_atomic_set_async_response_cmd(vf, args->ops))
164 if (_atomic_set_cmd(vf, args->ops))
168 ret = iavf_aq_send_msg_to_pf(hw, args->ops, IAVF_SUCCESS,
169 args->in_args, args->in_args_size, NULL);
171 PMD_DRV_LOG(ERR, "fail to send cmd %d", args->ops);
177 case VIRTCHNL_OP_RESET_VF:
178 /*no need to wait for response */
181 case VIRTCHNL_OP_VERSION:
182 case VIRTCHNL_OP_GET_VF_RESOURCES:
183 case VIRTCHNL_OP_GET_SUPPORTED_RXDIDS:
184 case VIRTCHNL_OP_GET_OFFLOAD_VLAN_V2_CAPS:
185 /* for init virtchnl ops, need to poll the response */
187 result = iavf_read_msg_from_pf(adapter, args->out_size,
189 if (result == IAVF_MSG_CMD)
191 iavf_msec_delay(ASQ_DELAY_MS);
192 } while (i++ < MAX_TRY_TIMES);
193 if (i >= MAX_TRY_TIMES ||
194 vf->cmd_retval != VIRTCHNL_STATUS_SUCCESS) {
196 PMD_DRV_LOG(ERR, "No response or return failure (%d)"
197 " for cmd %d", vf->cmd_retval, args->ops);
201 case VIRTCHNL_OP_REQUEST_QUEUES:
203 * ignore async reply, only wait for system message,
204 * vf_reset = true if get VIRTCHNL_EVENT_RESET_IMPENDING,
205 * if not, means request queues failed.
208 result = iavf_read_msg_from_pf(adapter, args->out_size,
210 if (result == IAVF_MSG_SYS && vf->vf_reset) {
212 } else if (result == IAVF_MSG_CMD ||
213 result == IAVF_MSG_ERR) {
217 iavf_msec_delay(ASQ_DELAY_MS);
218 /* If don't read msg or read sys event, continue */
219 } while (i++ < MAX_TRY_TIMES);
220 if (i >= MAX_TRY_TIMES ||
221 vf->cmd_retval != VIRTCHNL_STATUS_SUCCESS) {
223 PMD_DRV_LOG(ERR, "No response or return failure (%d)"
224 " for cmd %d", vf->cmd_retval, args->ops);
229 /* For other virtchnl ops in running time,
230 * wait for the cmd done flag.
233 if (vf->pend_cmd == VIRTCHNL_OP_UNKNOWN)
235 iavf_msec_delay(ASQ_DELAY_MS);
236 /* If don't read msg or read sys event, continue */
237 } while (i++ < MAX_TRY_TIMES);
239 if (i >= MAX_TRY_TIMES) {
240 PMD_DRV_LOG(ERR, "No response for cmd %d", args->ops);
243 } else if (vf->cmd_retval ==
244 VIRTCHNL_STATUS_ERR_NOT_SUPPORTED) {
245 PMD_DRV_LOG(ERR, "Cmd %d not supported", args->ops);
247 } else if (vf->cmd_retval != VIRTCHNL_STATUS_SUCCESS) {
248 PMD_DRV_LOG(ERR, "Return failure %d for cmd %d",
249 vf->cmd_retval, args->ops);
259 iavf_handle_pf_event_msg(struct rte_eth_dev *dev, uint8_t *msg,
262 struct iavf_adapter *adapter =
263 IAVF_DEV_PRIVATE_TO_ADAPTER(dev->data->dev_private);
264 struct iavf_info *vf = &adapter->vf;
265 struct virtchnl_pf_event *pf_msg =
266 (struct virtchnl_pf_event *)msg;
268 if (adapter->closed) {
269 PMD_DRV_LOG(DEBUG, "Port closed");
273 if (msglen < sizeof(struct virtchnl_pf_event)) {
274 PMD_DRV_LOG(DEBUG, "Error event");
277 switch (pf_msg->event) {
278 case VIRTCHNL_EVENT_RESET_IMPENDING:
279 PMD_DRV_LOG(DEBUG, "VIRTCHNL_EVENT_RESET_IMPENDING event");
281 rte_eth_dev_callback_process(dev, RTE_ETH_EVENT_INTR_RESET,
284 case VIRTCHNL_EVENT_LINK_CHANGE:
285 PMD_DRV_LOG(DEBUG, "VIRTCHNL_EVENT_LINK_CHANGE event");
286 vf->link_up = pf_msg->event_data.link_event.link_status;
287 if (vf->vf_res->vf_cap_flags & VIRTCHNL_VF_CAP_ADV_LINK_SPEED) {
289 pf_msg->event_data.link_event_adv.link_speed;
291 enum virtchnl_link_speed speed;
292 speed = pf_msg->event_data.link_event.link_speed;
293 vf->link_speed = iavf_convert_link_speed(speed);
295 iavf_dev_link_update(dev, 0);
296 rte_eth_dev_callback_process(dev, RTE_ETH_EVENT_INTR_LSC, NULL);
298 case VIRTCHNL_EVENT_PF_DRIVER_CLOSE:
299 PMD_DRV_LOG(DEBUG, "VIRTCHNL_EVENT_PF_DRIVER_CLOSE event");
302 PMD_DRV_LOG(ERR, " unknown event received %u", pf_msg->event);
308 iavf_handle_virtchnl_msg(struct rte_eth_dev *dev)
310 struct iavf_hw *hw = IAVF_DEV_PRIVATE_TO_HW(dev->data->dev_private);
311 struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(dev->data->dev_private);
312 struct iavf_arq_event_info info;
313 uint16_t pending, aq_opc;
314 enum virtchnl_ops msg_opc;
315 enum iavf_status msg_ret;
318 info.buf_len = IAVF_AQ_BUF_SZ;
320 PMD_DRV_LOG(ERR, "Buffer for adminq resp should not be NULL");
323 info.msg_buf = vf->aq_resp;
327 ret = iavf_clean_arq_element(hw, &info, &pending);
329 if (ret != IAVF_SUCCESS) {
330 PMD_DRV_LOG(INFO, "Failed to read msg from AdminQ,"
334 aq_opc = rte_le_to_cpu_16(info.desc.opcode);
335 /* For the message sent from pf to vf, opcode is stored in
336 * cookie_high of struct iavf_aq_desc, while return error code
337 * are stored in cookie_low, Which is done by PF driver.
339 msg_opc = (enum virtchnl_ops)rte_le_to_cpu_32(
340 info.desc.cookie_high);
341 msg_ret = (enum iavf_status)rte_le_to_cpu_32(
342 info.desc.cookie_low);
344 case iavf_aqc_opc_send_msg_to_vf:
345 if (msg_opc == VIRTCHNL_OP_EVENT) {
346 iavf_handle_pf_event_msg(dev, info.msg_buf,
349 /* check for inline IPsec events */
350 struct inline_ipsec_msg *imsg =
351 (struct inline_ipsec_msg *)info.msg_buf;
352 struct rte_eth_event_ipsec_desc desc;
354 VIRTCHNL_OP_INLINE_IPSEC_CRYPTO &&
355 imsg->ipsec_opcode ==
356 INLINE_IPSEC_OP_EVENT) {
357 struct virtchnl_ipsec_event *ev =
358 imsg->ipsec_data.event;
360 RTE_ETH_EVENT_IPSEC_UNKNOWN;
361 desc.metadata = ev->ipsec_event_data;
362 rte_eth_dev_callback_process(dev,
368 /* read message and it's expected one */
369 if (msg_opc == vf->pend_cmd) {
371 __atomic_sub_fetch(&vf->pend_cmd_count,
372 1, __ATOMIC_RELAXED);
374 _notify_cmd(vf, msg_ret);
377 "command mismatch, expect %u, get %u",
378 vf->pend_cmd, msg_opc);
381 "adminq response is received, opcode = %d",
386 PMD_DRV_LOG(DEBUG, "Request %u is not supported yet",
394 iavf_enable_vlan_strip(struct iavf_adapter *adapter)
396 struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(adapter);
397 struct iavf_cmd_info args;
400 memset(&args, 0, sizeof(args));
401 args.ops = VIRTCHNL_OP_ENABLE_VLAN_STRIPPING;
403 args.in_args_size = 0;
404 args.out_buffer = vf->aq_resp;
405 args.out_size = IAVF_AQ_BUF_SZ;
406 ret = iavf_execute_vf_cmd(adapter, &args, 0);
408 PMD_DRV_LOG(ERR, "Failed to execute command of"
409 " OP_ENABLE_VLAN_STRIPPING");
415 iavf_disable_vlan_strip(struct iavf_adapter *adapter)
417 struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(adapter);
418 struct iavf_cmd_info args;
421 memset(&args, 0, sizeof(args));
422 args.ops = VIRTCHNL_OP_DISABLE_VLAN_STRIPPING;
424 args.in_args_size = 0;
425 args.out_buffer = vf->aq_resp;
426 args.out_size = IAVF_AQ_BUF_SZ;
427 ret = iavf_execute_vf_cmd(adapter, &args, 0);
429 PMD_DRV_LOG(ERR, "Failed to execute command of"
430 " OP_DISABLE_VLAN_STRIPPING");
435 #define VIRTCHNL_VERSION_MAJOR_START 1
436 #define VIRTCHNL_VERSION_MINOR_START 1
438 /* Check API version with sync wait until version read from admin queue */
440 iavf_check_api_version(struct iavf_adapter *adapter)
442 struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(adapter);
443 struct virtchnl_version_info version, *pver;
444 struct iavf_cmd_info args;
447 version.major = VIRTCHNL_VERSION_MAJOR;
448 version.minor = VIRTCHNL_VERSION_MINOR;
450 args.ops = VIRTCHNL_OP_VERSION;
451 args.in_args = (uint8_t *)&version;
452 args.in_args_size = sizeof(version);
453 args.out_buffer = vf->aq_resp;
454 args.out_size = IAVF_AQ_BUF_SZ;
456 err = iavf_execute_vf_cmd(adapter, &args, 0);
458 PMD_INIT_LOG(ERR, "Fail to execute command of OP_VERSION");
462 pver = (struct virtchnl_version_info *)args.out_buffer;
463 vf->virtchnl_version = *pver;
465 if (vf->virtchnl_version.major < VIRTCHNL_VERSION_MAJOR_START ||
466 (vf->virtchnl_version.major == VIRTCHNL_VERSION_MAJOR_START &&
467 vf->virtchnl_version.minor < VIRTCHNL_VERSION_MINOR_START)) {
468 PMD_INIT_LOG(ERR, "VIRTCHNL API version should not be lower"
469 " than (%u.%u) to support Adaptive VF",
470 VIRTCHNL_VERSION_MAJOR_START,
471 VIRTCHNL_VERSION_MAJOR_START);
473 } else if (vf->virtchnl_version.major > VIRTCHNL_VERSION_MAJOR ||
474 (vf->virtchnl_version.major == VIRTCHNL_VERSION_MAJOR &&
475 vf->virtchnl_version.minor > VIRTCHNL_VERSION_MINOR)) {
476 PMD_INIT_LOG(ERR, "PF/VF API version mismatch:(%u.%u)-(%u.%u)",
477 vf->virtchnl_version.major,
478 vf->virtchnl_version.minor,
479 VIRTCHNL_VERSION_MAJOR,
480 VIRTCHNL_VERSION_MINOR);
484 PMD_DRV_LOG(DEBUG, "Peer is supported PF host");
489 iavf_get_vf_resource(struct iavf_adapter *adapter)
491 struct iavf_hw *hw = IAVF_DEV_PRIVATE_TO_HW(adapter);
492 struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(adapter);
493 struct iavf_cmd_info args;
497 args.ops = VIRTCHNL_OP_GET_VF_RESOURCES;
498 args.out_buffer = vf->aq_resp;
499 args.out_size = IAVF_AQ_BUF_SZ;
501 caps = IAVF_BASIC_OFFLOAD_CAPS | VIRTCHNL_VF_CAP_ADV_LINK_SPEED |
502 VIRTCHNL_VF_OFFLOAD_RX_FLEX_DESC |
503 VIRTCHNL_VF_OFFLOAD_FDIR_PF |
504 VIRTCHNL_VF_OFFLOAD_ADV_RSS_PF |
505 VIRTCHNL_VF_OFFLOAD_REQ_QUEUES |
506 VIRTCHNL_VF_OFFLOAD_CRC |
507 VIRTCHNL_VF_OFFLOAD_VLAN_V2 |
508 VIRTCHNL_VF_LARGE_NUM_QPAIRS |
509 VIRTCHNL_VF_OFFLOAD_QOS |
510 VIRTCHNL_VF_OFFLOAD_INLINE_IPSEC_CRYPTO |
513 args.in_args = (uint8_t *)∩︀
514 args.in_args_size = sizeof(caps);
516 err = iavf_execute_vf_cmd(adapter, &args, 0);
520 "Failed to execute command of OP_GET_VF_RESOURCE");
524 len = sizeof(struct virtchnl_vf_resource) +
525 IAVF_MAX_VF_VSI * sizeof(struct virtchnl_vsi_resource);
527 rte_memcpy(vf->vf_res, args.out_buffer,
528 RTE_MIN(args.out_size, len));
529 /* parse VF config message back from PF*/
530 iavf_vf_parse_hw_config(hw, vf->vf_res);
531 for (i = 0; i < vf->vf_res->num_vsis; i++) {
532 if (vf->vf_res->vsi_res[i].vsi_type == VIRTCHNL_VSI_SRIOV)
533 vf->vsi_res = &vf->vf_res->vsi_res[i];
537 PMD_INIT_LOG(ERR, "no LAN VSI found");
541 vf->vsi.vsi_id = vf->vsi_res->vsi_id;
542 vf->vsi.nb_qps = vf->vsi_res->num_queue_pairs;
543 vf->vsi.adapter = adapter;
549 iavf_get_supported_rxdid(struct iavf_adapter *adapter)
551 struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(adapter);
552 struct iavf_cmd_info args;
555 args.ops = VIRTCHNL_OP_GET_SUPPORTED_RXDIDS;
557 args.in_args_size = 0;
558 args.out_buffer = vf->aq_resp;
559 args.out_size = IAVF_AQ_BUF_SZ;
561 ret = iavf_execute_vf_cmd(adapter, &args, 0);
564 "Failed to execute command of OP_GET_SUPPORTED_RXDIDS");
568 vf->supported_rxdid =
569 ((struct virtchnl_supported_rxdids *)args.out_buffer)->supported_rxdids;
575 iavf_config_vlan_strip_v2(struct iavf_adapter *adapter, bool enable)
577 struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(adapter);
578 struct virtchnl_vlan_supported_caps *stripping_caps;
579 struct virtchnl_vlan_setting vlan_strip;
580 struct iavf_cmd_info args;
584 stripping_caps = &vf->vlan_v2_caps.offloads.stripping_support;
586 if ((stripping_caps->outer & VIRTCHNL_VLAN_ETHERTYPE_8100) &&
587 (stripping_caps->outer & VIRTCHNL_VLAN_TOGGLE))
588 ethertype = &vlan_strip.outer_ethertype_setting;
589 else if ((stripping_caps->inner & VIRTCHNL_VLAN_ETHERTYPE_8100) &&
590 (stripping_caps->inner & VIRTCHNL_VLAN_TOGGLE))
591 ethertype = &vlan_strip.inner_ethertype_setting;
595 memset(&vlan_strip, 0, sizeof(vlan_strip));
596 vlan_strip.vport_id = vf->vsi_res->vsi_id;
597 *ethertype = VIRTCHNL_VLAN_ETHERTYPE_8100;
599 args.ops = enable ? VIRTCHNL_OP_ENABLE_VLAN_STRIPPING_V2 :
600 VIRTCHNL_OP_DISABLE_VLAN_STRIPPING_V2;
601 args.in_args = (uint8_t *)&vlan_strip;
602 args.in_args_size = sizeof(vlan_strip);
603 args.out_buffer = vf->aq_resp;
604 args.out_size = IAVF_AQ_BUF_SZ;
605 ret = iavf_execute_vf_cmd(adapter, &args, 0);
607 PMD_DRV_LOG(ERR, "fail to execute command %s",
608 enable ? "VIRTCHNL_OP_ENABLE_VLAN_STRIPPING_V2" :
609 "VIRTCHNL_OP_DISABLE_VLAN_STRIPPING_V2");
615 iavf_config_vlan_insert_v2(struct iavf_adapter *adapter, bool enable)
617 struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(adapter);
618 struct virtchnl_vlan_supported_caps *insertion_caps;
619 struct virtchnl_vlan_setting vlan_insert;
620 struct iavf_cmd_info args;
624 insertion_caps = &vf->vlan_v2_caps.offloads.insertion_support;
626 if ((insertion_caps->outer & VIRTCHNL_VLAN_ETHERTYPE_8100) &&
627 (insertion_caps->outer & VIRTCHNL_VLAN_TOGGLE))
628 ethertype = &vlan_insert.outer_ethertype_setting;
629 else if ((insertion_caps->inner & VIRTCHNL_VLAN_ETHERTYPE_8100) &&
630 (insertion_caps->inner & VIRTCHNL_VLAN_TOGGLE))
631 ethertype = &vlan_insert.inner_ethertype_setting;
635 memset(&vlan_insert, 0, sizeof(vlan_insert));
636 vlan_insert.vport_id = vf->vsi_res->vsi_id;
637 *ethertype = VIRTCHNL_VLAN_ETHERTYPE_8100;
639 args.ops = enable ? VIRTCHNL_OP_ENABLE_VLAN_INSERTION_V2 :
640 VIRTCHNL_OP_DISABLE_VLAN_INSERTION_V2;
641 args.in_args = (uint8_t *)&vlan_insert;
642 args.in_args_size = sizeof(vlan_insert);
643 args.out_buffer = vf->aq_resp;
644 args.out_size = IAVF_AQ_BUF_SZ;
645 ret = iavf_execute_vf_cmd(adapter, &args, 0);
647 PMD_DRV_LOG(ERR, "fail to execute command %s",
648 enable ? "VIRTCHNL_OP_ENABLE_VLAN_INSERTION_V2" :
649 "VIRTCHNL_OP_DISABLE_VLAN_INSERTION_V2");
655 iavf_add_del_vlan_v2(struct iavf_adapter *adapter, uint16_t vlanid, bool add)
657 struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(adapter);
658 struct virtchnl_vlan_supported_caps *supported_caps;
659 struct virtchnl_vlan_filter_list_v2 vlan_filter;
660 struct virtchnl_vlan *vlan_setting;
661 struct iavf_cmd_info args;
662 uint32_t filtering_caps;
665 supported_caps = &vf->vlan_v2_caps.filtering.filtering_support;
666 if (supported_caps->outer) {
667 filtering_caps = supported_caps->outer;
668 vlan_setting = &vlan_filter.filters[0].outer;
670 filtering_caps = supported_caps->inner;
671 vlan_setting = &vlan_filter.filters[0].inner;
674 if (!(filtering_caps & VIRTCHNL_VLAN_ETHERTYPE_8100))
677 memset(&vlan_filter, 0, sizeof(vlan_filter));
678 vlan_filter.vport_id = vf->vsi_res->vsi_id;
679 vlan_filter.num_elements = 1;
680 vlan_setting->tpid = RTE_ETHER_TYPE_VLAN;
681 vlan_setting->tci = vlanid;
683 args.ops = add ? VIRTCHNL_OP_ADD_VLAN_V2 : VIRTCHNL_OP_DEL_VLAN_V2;
684 args.in_args = (uint8_t *)&vlan_filter;
685 args.in_args_size = sizeof(vlan_filter);
686 args.out_buffer = vf->aq_resp;
687 args.out_size = IAVF_AQ_BUF_SZ;
688 err = iavf_execute_vf_cmd(adapter, &args, 0);
690 PMD_DRV_LOG(ERR, "fail to execute command %s",
691 add ? "OP_ADD_VLAN_V2" : "OP_DEL_VLAN_V2");
697 iavf_get_vlan_offload_caps_v2(struct iavf_adapter *adapter)
699 struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(adapter);
700 struct iavf_cmd_info args;
703 args.ops = VIRTCHNL_OP_GET_OFFLOAD_VLAN_V2_CAPS;
705 args.in_args_size = 0;
706 args.out_buffer = vf->aq_resp;
707 args.out_size = IAVF_AQ_BUF_SZ;
709 ret = iavf_execute_vf_cmd(adapter, &args, 0);
712 "Failed to execute command of VIRTCHNL_OP_GET_OFFLOAD_VLAN_V2_CAPS");
716 rte_memcpy(&vf->vlan_v2_caps, vf->aq_resp, sizeof(vf->vlan_v2_caps));
722 iavf_enable_queues(struct iavf_adapter *adapter)
724 struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(adapter);
725 struct virtchnl_queue_select queue_select;
726 struct iavf_cmd_info args;
729 memset(&queue_select, 0, sizeof(queue_select));
730 queue_select.vsi_id = vf->vsi_res->vsi_id;
732 queue_select.rx_queues = BIT(adapter->dev_data->nb_rx_queues) - 1;
733 queue_select.tx_queues = BIT(adapter->dev_data->nb_tx_queues) - 1;
735 args.ops = VIRTCHNL_OP_ENABLE_QUEUES;
736 args.in_args = (u8 *)&queue_select;
737 args.in_args_size = sizeof(queue_select);
738 args.out_buffer = vf->aq_resp;
739 args.out_size = IAVF_AQ_BUF_SZ;
740 err = iavf_execute_vf_cmd(adapter, &args, 0);
743 "Failed to execute command of OP_ENABLE_QUEUES");
750 iavf_disable_queues(struct iavf_adapter *adapter)
752 struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(adapter);
753 struct virtchnl_queue_select queue_select;
754 struct iavf_cmd_info args;
757 memset(&queue_select, 0, sizeof(queue_select));
758 queue_select.vsi_id = vf->vsi_res->vsi_id;
760 queue_select.rx_queues = BIT(adapter->dev_data->nb_rx_queues) - 1;
761 queue_select.tx_queues = BIT(adapter->dev_data->nb_tx_queues) - 1;
763 args.ops = VIRTCHNL_OP_DISABLE_QUEUES;
764 args.in_args = (u8 *)&queue_select;
765 args.in_args_size = sizeof(queue_select);
766 args.out_buffer = vf->aq_resp;
767 args.out_size = IAVF_AQ_BUF_SZ;
768 err = iavf_execute_vf_cmd(adapter, &args, 0);
771 "Failed to execute command of OP_DISABLE_QUEUES");
778 iavf_switch_queue(struct iavf_adapter *adapter, uint16_t qid,
781 struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(adapter);
782 struct virtchnl_queue_select queue_select;
783 struct iavf_cmd_info args;
789 memset(&queue_select, 0, sizeof(queue_select));
790 queue_select.vsi_id = vf->vsi_res->vsi_id;
792 queue_select.rx_queues |= 1 << qid;
794 queue_select.tx_queues |= 1 << qid;
797 args.ops = VIRTCHNL_OP_ENABLE_QUEUES;
799 args.ops = VIRTCHNL_OP_DISABLE_QUEUES;
800 args.in_args = (u8 *)&queue_select;
801 args.in_args_size = sizeof(queue_select);
802 args.out_buffer = vf->aq_resp;
803 args.out_size = IAVF_AQ_BUF_SZ;
804 err = iavf_execute_vf_cmd(adapter, &args, 0);
806 PMD_DRV_LOG(ERR, "Failed to execute command of %s",
807 on ? "OP_ENABLE_QUEUES" : "OP_DISABLE_QUEUES");
812 iavf_enable_queues_lv(struct iavf_adapter *adapter)
814 struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(adapter);
815 struct virtchnl_del_ena_dis_queues *queue_select;
816 struct virtchnl_queue_chunk *queue_chunk;
817 struct iavf_cmd_info args;
820 len = sizeof(struct virtchnl_del_ena_dis_queues) +
821 sizeof(struct virtchnl_queue_chunk) *
822 (IAVF_RXTX_QUEUE_CHUNKS_NUM - 1);
823 queue_select = rte_zmalloc("queue_select", len, 0);
827 queue_chunk = queue_select->chunks.chunks;
828 queue_select->chunks.num_chunks = IAVF_RXTX_QUEUE_CHUNKS_NUM;
829 queue_select->vport_id = vf->vsi_res->vsi_id;
831 queue_chunk[VIRTCHNL_QUEUE_TYPE_TX].type = VIRTCHNL_QUEUE_TYPE_TX;
832 queue_chunk[VIRTCHNL_QUEUE_TYPE_TX].start_queue_id = 0;
833 queue_chunk[VIRTCHNL_QUEUE_TYPE_TX].num_queues =
834 adapter->dev_data->nb_tx_queues;
836 queue_chunk[VIRTCHNL_QUEUE_TYPE_RX].type = VIRTCHNL_QUEUE_TYPE_RX;
837 queue_chunk[VIRTCHNL_QUEUE_TYPE_RX].start_queue_id = 0;
838 queue_chunk[VIRTCHNL_QUEUE_TYPE_RX].num_queues =
839 adapter->dev_data->nb_rx_queues;
841 args.ops = VIRTCHNL_OP_ENABLE_QUEUES_V2;
842 args.in_args = (u8 *)queue_select;
843 args.in_args_size = len;
844 args.out_buffer = vf->aq_resp;
845 args.out_size = IAVF_AQ_BUF_SZ;
846 err = iavf_execute_vf_cmd(adapter, &args, 0);
849 "Failed to execute command of OP_ENABLE_QUEUES_V2");
851 rte_free(queue_select);
856 iavf_disable_queues_lv(struct iavf_adapter *adapter)
858 struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(adapter);
859 struct virtchnl_del_ena_dis_queues *queue_select;
860 struct virtchnl_queue_chunk *queue_chunk;
861 struct iavf_cmd_info args;
864 len = sizeof(struct virtchnl_del_ena_dis_queues) +
865 sizeof(struct virtchnl_queue_chunk) *
866 (IAVF_RXTX_QUEUE_CHUNKS_NUM - 1);
867 queue_select = rte_zmalloc("queue_select", len, 0);
871 queue_chunk = queue_select->chunks.chunks;
872 queue_select->chunks.num_chunks = IAVF_RXTX_QUEUE_CHUNKS_NUM;
873 queue_select->vport_id = vf->vsi_res->vsi_id;
875 queue_chunk[VIRTCHNL_QUEUE_TYPE_TX].type = VIRTCHNL_QUEUE_TYPE_TX;
876 queue_chunk[VIRTCHNL_QUEUE_TYPE_TX].start_queue_id = 0;
877 queue_chunk[VIRTCHNL_QUEUE_TYPE_TX].num_queues =
878 adapter->dev_data->nb_tx_queues;
880 queue_chunk[VIRTCHNL_QUEUE_TYPE_RX].type = VIRTCHNL_QUEUE_TYPE_RX;
881 queue_chunk[VIRTCHNL_QUEUE_TYPE_RX].start_queue_id = 0;
882 queue_chunk[VIRTCHNL_QUEUE_TYPE_RX].num_queues =
883 adapter->dev_data->nb_rx_queues;
885 args.ops = VIRTCHNL_OP_DISABLE_QUEUES_V2;
886 args.in_args = (u8 *)queue_select;
887 args.in_args_size = len;
888 args.out_buffer = vf->aq_resp;
889 args.out_size = IAVF_AQ_BUF_SZ;
890 err = iavf_execute_vf_cmd(adapter, &args, 0);
893 "Failed to execute command of OP_DISABLE_QUEUES_V2");
895 rte_free(queue_select);
900 iavf_switch_queue_lv(struct iavf_adapter *adapter, uint16_t qid,
903 struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(adapter);
904 struct virtchnl_del_ena_dis_queues *queue_select;
905 struct virtchnl_queue_chunk *queue_chunk;
906 struct iavf_cmd_info args;
909 len = sizeof(struct virtchnl_del_ena_dis_queues);
910 queue_select = rte_zmalloc("queue_select", len, 0);
914 queue_chunk = queue_select->chunks.chunks;
915 queue_select->chunks.num_chunks = 1;
916 queue_select->vport_id = vf->vsi_res->vsi_id;
919 queue_chunk->type = VIRTCHNL_QUEUE_TYPE_RX;
920 queue_chunk->start_queue_id = qid;
921 queue_chunk->num_queues = 1;
923 queue_chunk->type = VIRTCHNL_QUEUE_TYPE_TX;
924 queue_chunk->start_queue_id = qid;
925 queue_chunk->num_queues = 1;
929 args.ops = VIRTCHNL_OP_ENABLE_QUEUES_V2;
931 args.ops = VIRTCHNL_OP_DISABLE_QUEUES_V2;
932 args.in_args = (u8 *)queue_select;
933 args.in_args_size = len;
934 args.out_buffer = vf->aq_resp;
935 args.out_size = IAVF_AQ_BUF_SZ;
936 err = iavf_execute_vf_cmd(adapter, &args, 0);
938 PMD_DRV_LOG(ERR, "Failed to execute command of %s",
939 on ? "OP_ENABLE_QUEUES_V2" : "OP_DISABLE_QUEUES_V2");
941 rte_free(queue_select);
946 iavf_configure_rss_lut(struct iavf_adapter *adapter)
948 struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(adapter);
949 struct virtchnl_rss_lut *rss_lut;
950 struct iavf_cmd_info args;
953 len = sizeof(*rss_lut) + vf->vf_res->rss_lut_size - 1;
954 rss_lut = rte_zmalloc("rss_lut", len, 0);
958 rss_lut->vsi_id = vf->vsi_res->vsi_id;
959 rss_lut->lut_entries = vf->vf_res->rss_lut_size;
960 rte_memcpy(rss_lut->lut, vf->rss_lut, vf->vf_res->rss_lut_size);
962 args.ops = VIRTCHNL_OP_CONFIG_RSS_LUT;
963 args.in_args = (u8 *)rss_lut;
964 args.in_args_size = len;
965 args.out_buffer = vf->aq_resp;
966 args.out_size = IAVF_AQ_BUF_SZ;
968 err = iavf_execute_vf_cmd(adapter, &args, 0);
971 "Failed to execute command of OP_CONFIG_RSS_LUT");
978 iavf_configure_rss_key(struct iavf_adapter *adapter)
980 struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(adapter);
981 struct virtchnl_rss_key *rss_key;
982 struct iavf_cmd_info args;
985 len = sizeof(*rss_key) + vf->vf_res->rss_key_size - 1;
986 rss_key = rte_zmalloc("rss_key", len, 0);
990 rss_key->vsi_id = vf->vsi_res->vsi_id;
991 rss_key->key_len = vf->vf_res->rss_key_size;
992 rte_memcpy(rss_key->key, vf->rss_key, vf->vf_res->rss_key_size);
994 args.ops = VIRTCHNL_OP_CONFIG_RSS_KEY;
995 args.in_args = (u8 *)rss_key;
996 args.in_args_size = len;
997 args.out_buffer = vf->aq_resp;
998 args.out_size = IAVF_AQ_BUF_SZ;
1000 err = iavf_execute_vf_cmd(adapter, &args, 0);
1003 "Failed to execute command of OP_CONFIG_RSS_KEY");
1010 iavf_configure_queues(struct iavf_adapter *adapter,
1011 uint16_t num_queue_pairs, uint16_t index)
1013 struct iavf_rx_queue **rxq =
1014 (struct iavf_rx_queue **)adapter->dev_data->rx_queues;
1015 struct iavf_tx_queue **txq =
1016 (struct iavf_tx_queue **)adapter->dev_data->tx_queues;
1017 struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(adapter);
1018 struct virtchnl_vsi_queue_config_info *vc_config;
1019 struct virtchnl_queue_pair_info *vc_qp;
1020 struct iavf_cmd_info args;
1024 size = sizeof(*vc_config) +
1025 sizeof(vc_config->qpair[0]) * num_queue_pairs;
1026 vc_config = rte_zmalloc("cfg_queue", size, 0);
1030 vc_config->vsi_id = vf->vsi_res->vsi_id;
1031 vc_config->num_queue_pairs = num_queue_pairs;
1033 for (i = index, vc_qp = vc_config->qpair;
1034 i < index + num_queue_pairs;
1036 vc_qp->txq.vsi_id = vf->vsi_res->vsi_id;
1037 vc_qp->txq.queue_id = i;
1039 /* Virtchnnl configure tx queues by pairs */
1040 if (i < adapter->dev_data->nb_tx_queues) {
1041 vc_qp->txq.ring_len = txq[i]->nb_tx_desc;
1042 vc_qp->txq.dma_ring_addr = txq[i]->tx_ring_phys_addr;
1045 vc_qp->rxq.vsi_id = vf->vsi_res->vsi_id;
1046 vc_qp->rxq.queue_id = i;
1047 vc_qp->rxq.max_pkt_size = vf->max_pkt_len;
1049 if (i >= adapter->dev_data->nb_rx_queues)
1052 /* Virtchnnl configure rx queues by pairs */
1053 vc_qp->rxq.ring_len = rxq[i]->nb_rx_desc;
1054 vc_qp->rxq.dma_ring_addr = rxq[i]->rx_ring_phys_addr;
1055 vc_qp->rxq.databuffer_size = rxq[i]->rx_buf_len;
1056 vc_qp->rxq.crc_disable = rxq[i]->crc_len != 0 ? 1 : 0;
1057 #ifndef RTE_LIBRTE_IAVF_16BYTE_RX_DESC
1058 if (vf->vf_res->vf_cap_flags &
1059 VIRTCHNL_VF_OFFLOAD_RX_FLEX_DESC) {
1060 if (vf->supported_rxdid & BIT(rxq[i]->rxdid)) {
1061 vc_qp->rxq.rxdid = rxq[i]->rxdid;
1062 PMD_DRV_LOG(NOTICE, "request RXDID[%d] in Queue[%d]",
1063 vc_qp->rxq.rxdid, i);
1065 PMD_DRV_LOG(NOTICE, "RXDID[%d] is not supported, "
1066 "request default RXDID[%d] in Queue[%d]",
1067 rxq[i]->rxdid, IAVF_RXDID_LEGACY_1, i);
1068 vc_qp->rxq.rxdid = IAVF_RXDID_LEGACY_1;
1071 if (vf->vf_res->vf_cap_flags & VIRTCHNL_VF_CAP_PTP &&
1072 vf->ptp_caps & VIRTCHNL_1588_PTP_CAP_RX_TSTAMP)
1073 vc_qp->rxq.flags |= VIRTCHNL_PTP_RX_TSTAMP;
1076 if (vf->vf_res->vf_cap_flags &
1077 VIRTCHNL_VF_OFFLOAD_RX_FLEX_DESC &&
1078 vf->supported_rxdid & BIT(IAVF_RXDID_LEGACY_0)) {
1079 vc_qp->rxq.rxdid = IAVF_RXDID_LEGACY_0;
1080 PMD_DRV_LOG(NOTICE, "request RXDID[%d] in Queue[%d]",
1081 vc_qp->rxq.rxdid, i);
1083 PMD_DRV_LOG(ERR, "RXDID[%d] is not supported",
1084 IAVF_RXDID_LEGACY_0);
1090 memset(&args, 0, sizeof(args));
1091 args.ops = VIRTCHNL_OP_CONFIG_VSI_QUEUES;
1092 args.in_args = (uint8_t *)vc_config;
1093 args.in_args_size = size;
1094 args.out_buffer = vf->aq_resp;
1095 args.out_size = IAVF_AQ_BUF_SZ;
1097 err = iavf_execute_vf_cmd(adapter, &args, 0);
1099 PMD_DRV_LOG(ERR, "Failed to execute command of"
1100 " VIRTCHNL_OP_CONFIG_VSI_QUEUES");
1102 rte_free(vc_config);
1107 iavf_config_irq_map(struct iavf_adapter *adapter)
1109 struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(adapter);
1110 struct virtchnl_irq_map_info *map_info;
1111 struct virtchnl_vector_map *vecmap;
1112 struct iavf_cmd_info args;
1115 len = sizeof(struct virtchnl_irq_map_info) +
1116 sizeof(struct virtchnl_vector_map) * vf->nb_msix;
1118 map_info = rte_zmalloc("map_info", len, 0);
1122 map_info->num_vectors = vf->nb_msix;
1123 for (i = 0; i < adapter->dev_data->nb_rx_queues; i++) {
1125 &map_info->vecmap[vf->qv_map[i].vector_id - vf->msix_base];
1126 vecmap->vsi_id = vf->vsi_res->vsi_id;
1127 vecmap->rxitr_idx = IAVF_ITR_INDEX_DEFAULT;
1128 vecmap->vector_id = vf->qv_map[i].vector_id;
1129 vecmap->txq_map = 0;
1130 vecmap->rxq_map |= 1 << vf->qv_map[i].queue_id;
1133 args.ops = VIRTCHNL_OP_CONFIG_IRQ_MAP;
1134 args.in_args = (u8 *)map_info;
1135 args.in_args_size = len;
1136 args.out_buffer = vf->aq_resp;
1137 args.out_size = IAVF_AQ_BUF_SZ;
1138 err = iavf_execute_vf_cmd(adapter, &args, 0);
1140 PMD_DRV_LOG(ERR, "fail to execute command OP_CONFIG_IRQ_MAP");
1147 iavf_config_irq_map_lv(struct iavf_adapter *adapter, uint16_t num,
1150 struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(adapter);
1151 struct virtchnl_queue_vector_maps *map_info;
1152 struct virtchnl_queue_vector *qv_maps;
1153 struct iavf_cmd_info args;
1157 len = sizeof(struct virtchnl_queue_vector_maps) +
1158 sizeof(struct virtchnl_queue_vector) * (num - 1);
1160 map_info = rte_zmalloc("map_info", len, 0);
1164 map_info->vport_id = vf->vsi_res->vsi_id;
1165 map_info->num_qv_maps = num;
1166 for (i = index; i < index + map_info->num_qv_maps; i++) {
1167 qv_maps = &map_info->qv_maps[count++];
1168 qv_maps->itr_idx = VIRTCHNL_ITR_IDX_0;
1169 qv_maps->queue_type = VIRTCHNL_QUEUE_TYPE_RX;
1170 qv_maps->queue_id = vf->qv_map[i].queue_id;
1171 qv_maps->vector_id = vf->qv_map[i].vector_id;
1174 args.ops = VIRTCHNL_OP_MAP_QUEUE_VECTOR;
1175 args.in_args = (u8 *)map_info;
1176 args.in_args_size = len;
1177 args.out_buffer = vf->aq_resp;
1178 args.out_size = IAVF_AQ_BUF_SZ;
1179 err = iavf_execute_vf_cmd(adapter, &args, 0);
1181 PMD_DRV_LOG(ERR, "fail to execute command OP_MAP_QUEUE_VECTOR");
1188 iavf_add_del_all_mac_addr(struct iavf_adapter *adapter, bool add)
1190 struct virtchnl_ether_addr_list *list;
1191 struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(adapter);
1192 struct rte_ether_addr *addr;
1193 struct iavf_cmd_info args;
1200 len = sizeof(struct virtchnl_ether_addr_list);
1201 for (i = begin; i < IAVF_NUM_MACADDR_MAX; i++, next_begin++) {
1202 addr = &adapter->dev_data->mac_addrs[i];
1203 if (rte_is_zero_ether_addr(addr))
1205 len += sizeof(struct virtchnl_ether_addr);
1206 if (len >= IAVF_AQ_BUF_SZ) {
1212 list = rte_zmalloc("iavf_del_mac_buffer", len, 0);
1214 PMD_DRV_LOG(ERR, "fail to allocate memory");
1218 for (i = begin; i < next_begin; i++) {
1219 addr = &adapter->dev_data->mac_addrs[i];
1220 if (rte_is_zero_ether_addr(addr))
1222 rte_memcpy(list->list[j].addr, addr->addr_bytes,
1223 sizeof(addr->addr_bytes));
1224 list->list[j].type = (j == 0 ?
1225 VIRTCHNL_ETHER_ADDR_PRIMARY :
1226 VIRTCHNL_ETHER_ADDR_EXTRA);
1227 PMD_DRV_LOG(DEBUG, "add/rm mac:" RTE_ETHER_ADDR_PRT_FMT,
1228 RTE_ETHER_ADDR_BYTES(addr));
1231 list->vsi_id = vf->vsi_res->vsi_id;
1232 list->num_elements = j;
1233 args.ops = add ? VIRTCHNL_OP_ADD_ETH_ADDR :
1234 VIRTCHNL_OP_DEL_ETH_ADDR;
1235 args.in_args = (uint8_t *)list;
1236 args.in_args_size = len;
1237 args.out_buffer = vf->aq_resp;
1238 args.out_size = IAVF_AQ_BUF_SZ;
1239 err = iavf_execute_vf_cmd(adapter, &args, 0);
1241 PMD_DRV_LOG(ERR, "fail to execute command %s",
1242 add ? "OP_ADD_ETHER_ADDRESS" :
1243 "OP_DEL_ETHER_ADDRESS");
1246 } while (begin < IAVF_NUM_MACADDR_MAX);
1250 iavf_query_stats(struct iavf_adapter *adapter,
1251 struct virtchnl_eth_stats **pstats)
1253 struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(adapter);
1254 struct virtchnl_queue_select q_stats;
1255 struct iavf_cmd_info args;
1258 if (adapter->closed)
1261 memset(&q_stats, 0, sizeof(q_stats));
1262 q_stats.vsi_id = vf->vsi_res->vsi_id;
1263 args.ops = VIRTCHNL_OP_GET_STATS;
1264 args.in_args = (uint8_t *)&q_stats;
1265 args.in_args_size = sizeof(q_stats);
1266 args.out_buffer = vf->aq_resp;
1267 args.out_size = IAVF_AQ_BUF_SZ;
1269 err = iavf_execute_vf_cmd(adapter, &args, 0);
1271 PMD_DRV_LOG(ERR, "fail to execute command OP_GET_STATS");
1275 *pstats = (struct virtchnl_eth_stats *)args.out_buffer;
1280 iavf_config_promisc(struct iavf_adapter *adapter,
1281 bool enable_unicast,
1282 bool enable_multicast)
1284 struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(adapter);
1285 struct virtchnl_promisc_info promisc;
1286 struct iavf_cmd_info args;
1289 if (adapter->closed)
1293 promisc.vsi_id = vf->vsi_res->vsi_id;
1296 promisc.flags |= FLAG_VF_UNICAST_PROMISC;
1298 if (enable_multicast)
1299 promisc.flags |= FLAG_VF_MULTICAST_PROMISC;
1301 args.ops = VIRTCHNL_OP_CONFIG_PROMISCUOUS_MODE;
1302 args.in_args = (uint8_t *)&promisc;
1303 args.in_args_size = sizeof(promisc);
1304 args.out_buffer = vf->aq_resp;
1305 args.out_size = IAVF_AQ_BUF_SZ;
1307 err = iavf_execute_vf_cmd(adapter, &args, 0);
1311 "fail to execute command CONFIG_PROMISCUOUS_MODE");
1313 if (err == -ENOTSUP)
1319 vf->promisc_unicast_enabled = enable_unicast;
1320 vf->promisc_multicast_enabled = enable_multicast;
1325 iavf_add_del_eth_addr(struct iavf_adapter *adapter, struct rte_ether_addr *addr,
1326 bool add, uint8_t type)
1328 struct virtchnl_ether_addr_list *list;
1329 struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(adapter);
1330 uint8_t cmd_buffer[sizeof(struct virtchnl_ether_addr_list) +
1331 sizeof(struct virtchnl_ether_addr)];
1332 struct iavf_cmd_info args;
1335 if (adapter->closed)
1338 list = (struct virtchnl_ether_addr_list *)cmd_buffer;
1339 list->vsi_id = vf->vsi_res->vsi_id;
1340 list->num_elements = 1;
1341 list->list[0].type = type;
1342 rte_memcpy(list->list[0].addr, addr->addr_bytes,
1343 sizeof(addr->addr_bytes));
1345 args.ops = add ? VIRTCHNL_OP_ADD_ETH_ADDR : VIRTCHNL_OP_DEL_ETH_ADDR;
1346 args.in_args = cmd_buffer;
1347 args.in_args_size = sizeof(cmd_buffer);
1348 args.out_buffer = vf->aq_resp;
1349 args.out_size = IAVF_AQ_BUF_SZ;
1350 err = iavf_execute_vf_cmd(adapter, &args, 0);
1352 PMD_DRV_LOG(ERR, "fail to execute command %s",
1353 add ? "OP_ADD_ETH_ADDR" : "OP_DEL_ETH_ADDR");
1358 iavf_add_del_vlan(struct iavf_adapter *adapter, uint16_t vlanid, bool add)
1360 struct virtchnl_vlan_filter_list *vlan_list;
1361 struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(adapter);
1362 uint8_t cmd_buffer[sizeof(struct virtchnl_vlan_filter_list) +
1364 struct iavf_cmd_info args;
1367 vlan_list = (struct virtchnl_vlan_filter_list *)cmd_buffer;
1368 vlan_list->vsi_id = vf->vsi_res->vsi_id;
1369 vlan_list->num_elements = 1;
1370 vlan_list->vlan_id[0] = vlanid;
1372 args.ops = add ? VIRTCHNL_OP_ADD_VLAN : VIRTCHNL_OP_DEL_VLAN;
1373 args.in_args = cmd_buffer;
1374 args.in_args_size = sizeof(cmd_buffer);
1375 args.out_buffer = vf->aq_resp;
1376 args.out_size = IAVF_AQ_BUF_SZ;
1377 err = iavf_execute_vf_cmd(adapter, &args, 0);
1379 PMD_DRV_LOG(ERR, "fail to execute command %s",
1380 add ? "OP_ADD_VLAN" : "OP_DEL_VLAN");
1386 iavf_fdir_add(struct iavf_adapter *adapter,
1387 struct iavf_fdir_conf *filter)
1389 struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(adapter);
1390 struct virtchnl_fdir_add *fdir_ret;
1392 struct iavf_cmd_info args;
1395 filter->add_fltr.vsi_id = vf->vsi_res->vsi_id;
1396 filter->add_fltr.validate_only = 0;
1398 args.ops = VIRTCHNL_OP_ADD_FDIR_FILTER;
1399 args.in_args = (uint8_t *)(&filter->add_fltr);
1400 args.in_args_size = sizeof(*(&filter->add_fltr));
1401 args.out_buffer = vf->aq_resp;
1402 args.out_size = IAVF_AQ_BUF_SZ;
1404 err = iavf_execute_vf_cmd(adapter, &args, 0);
1406 PMD_DRV_LOG(ERR, "fail to execute command OP_ADD_FDIR_FILTER");
1410 fdir_ret = (struct virtchnl_fdir_add *)args.out_buffer;
1411 filter->flow_id = fdir_ret->flow_id;
1413 if (fdir_ret->status == VIRTCHNL_FDIR_SUCCESS) {
1415 "Succeed in adding rule request by PF");
1416 } else if (fdir_ret->status == VIRTCHNL_FDIR_FAILURE_RULE_NORESOURCE) {
1418 "Failed to add rule request due to no hw resource");
1420 } else if (fdir_ret->status == VIRTCHNL_FDIR_FAILURE_RULE_EXIST) {
1422 "Failed to add rule request due to the rule is already existed");
1424 } else if (fdir_ret->status == VIRTCHNL_FDIR_FAILURE_RULE_CONFLICT) {
1426 "Failed to add rule request due to the rule is conflict with existing rule");
1428 } else if (fdir_ret->status == VIRTCHNL_FDIR_FAILURE_RULE_INVALID) {
1430 "Failed to add rule request due to the hw doesn't support");
1432 } else if (fdir_ret->status == VIRTCHNL_FDIR_FAILURE_RULE_TIMEOUT) {
1434 "Failed to add rule request due to time out for programming");
1438 "Failed to add rule request due to other reasons");
1446 iavf_fdir_del(struct iavf_adapter *adapter,
1447 struct iavf_fdir_conf *filter)
1449 struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(adapter);
1450 struct virtchnl_fdir_del *fdir_ret;
1452 struct iavf_cmd_info args;
1455 filter->del_fltr.vsi_id = vf->vsi_res->vsi_id;
1456 filter->del_fltr.flow_id = filter->flow_id;
1458 args.ops = VIRTCHNL_OP_DEL_FDIR_FILTER;
1459 args.in_args = (uint8_t *)(&filter->del_fltr);
1460 args.in_args_size = sizeof(filter->del_fltr);
1461 args.out_buffer = vf->aq_resp;
1462 args.out_size = IAVF_AQ_BUF_SZ;
1464 err = iavf_execute_vf_cmd(adapter, &args, 0);
1466 PMD_DRV_LOG(ERR, "fail to execute command OP_DEL_FDIR_FILTER");
1470 fdir_ret = (struct virtchnl_fdir_del *)args.out_buffer;
1472 if (fdir_ret->status == VIRTCHNL_FDIR_SUCCESS) {
1474 "Succeed in deleting rule request by PF");
1475 } else if (fdir_ret->status == VIRTCHNL_FDIR_FAILURE_RULE_NONEXIST) {
1477 "Failed to delete rule request due to this rule doesn't exist");
1479 } else if (fdir_ret->status == VIRTCHNL_FDIR_FAILURE_RULE_TIMEOUT) {
1481 "Failed to delete rule request due to time out for programming");
1485 "Failed to delete rule request due to other reasons");
1493 iavf_fdir_check(struct iavf_adapter *adapter,
1494 struct iavf_fdir_conf *filter)
1496 struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(adapter);
1497 struct virtchnl_fdir_add *fdir_ret;
1499 struct iavf_cmd_info args;
1502 filter->add_fltr.vsi_id = vf->vsi_res->vsi_id;
1503 filter->add_fltr.validate_only = 1;
1505 args.ops = VIRTCHNL_OP_ADD_FDIR_FILTER;
1506 args.in_args = (uint8_t *)(&filter->add_fltr);
1507 args.in_args_size = sizeof(*(&filter->add_fltr));
1508 args.out_buffer = vf->aq_resp;
1509 args.out_size = IAVF_AQ_BUF_SZ;
1511 err = iavf_execute_vf_cmd(adapter, &args, 0);
1513 PMD_DRV_LOG(ERR, "fail to check flow director rule");
1517 fdir_ret = (struct virtchnl_fdir_add *)args.out_buffer;
1519 if (fdir_ret->status == VIRTCHNL_FDIR_SUCCESS) {
1521 "Succeed in checking rule request by PF");
1522 } else if (fdir_ret->status == VIRTCHNL_FDIR_FAILURE_RULE_INVALID) {
1524 "Failed to check rule request due to parameters validation"
1525 " or HW doesn't support");
1529 "Failed to check rule request due to other reasons");
1537 iavf_add_del_rss_cfg(struct iavf_adapter *adapter,
1538 struct virtchnl_rss_cfg *rss_cfg, bool add)
1540 struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(adapter);
1541 struct iavf_cmd_info args;
1544 memset(&args, 0, sizeof(args));
1545 args.ops = add ? VIRTCHNL_OP_ADD_RSS_CFG :
1546 VIRTCHNL_OP_DEL_RSS_CFG;
1547 args.in_args = (u8 *)rss_cfg;
1548 args.in_args_size = sizeof(*rss_cfg);
1549 args.out_buffer = vf->aq_resp;
1550 args.out_size = IAVF_AQ_BUF_SZ;
1552 err = iavf_execute_vf_cmd(adapter, &args, 0);
1555 "Failed to execute command of %s",
1556 add ? "OP_ADD_RSS_CFG" :
1557 "OP_DEL_RSS_INPUT_CFG");
1563 iavf_get_hena_caps(struct iavf_adapter *adapter, uint64_t *caps)
1565 struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(adapter);
1566 struct iavf_cmd_info args;
1569 args.ops = VIRTCHNL_OP_GET_RSS_HENA_CAPS;
1570 args.in_args = NULL;
1571 args.in_args_size = 0;
1572 args.out_buffer = vf->aq_resp;
1573 args.out_size = IAVF_AQ_BUF_SZ;
1575 err = iavf_execute_vf_cmd(adapter, &args, 0);
1578 "Failed to execute command of OP_GET_RSS_HENA_CAPS");
1582 *caps = ((struct virtchnl_rss_hena *)args.out_buffer)->hena;
1587 iavf_set_hena(struct iavf_adapter *adapter, uint64_t hena)
1589 struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(adapter);
1590 struct virtchnl_rss_hena vrh;
1591 struct iavf_cmd_info args;
1595 args.ops = VIRTCHNL_OP_SET_RSS_HENA;
1596 args.in_args = (u8 *)&vrh;
1597 args.in_args_size = sizeof(vrh);
1598 args.out_buffer = vf->aq_resp;
1599 args.out_size = IAVF_AQ_BUF_SZ;
1601 err = iavf_execute_vf_cmd(adapter, &args, 0);
1604 "Failed to execute command of OP_SET_RSS_HENA");
1610 iavf_get_qos_cap(struct iavf_adapter *adapter)
1612 struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(adapter);
1613 struct iavf_cmd_info args;
1617 args.ops = VIRTCHNL_OP_GET_QOS_CAPS;
1618 args.in_args = NULL;
1619 args.in_args_size = 0;
1620 args.out_buffer = vf->aq_resp;
1621 args.out_size = IAVF_AQ_BUF_SZ;
1622 err = iavf_execute_vf_cmd(adapter, &args, 0);
1626 "Failed to execute command of OP_GET_VF_RESOURCE");
1630 len = sizeof(struct virtchnl_qos_cap_list) +
1631 IAVF_MAX_TRAFFIC_CLASS * sizeof(struct virtchnl_qos_cap_elem);
1633 rte_memcpy(vf->qos_cap, args.out_buffer,
1634 RTE_MIN(args.out_size, len));
1639 int iavf_set_q_tc_map(struct rte_eth_dev *dev,
1640 struct virtchnl_queue_tc_mapping *q_tc_mapping, uint16_t size)
1642 struct iavf_adapter *adapter =
1643 IAVF_DEV_PRIVATE_TO_ADAPTER(dev->data->dev_private);
1644 struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(dev->data->dev_private);
1645 struct iavf_cmd_info args;
1648 memset(&args, 0, sizeof(args));
1649 args.ops = VIRTCHNL_OP_CONFIG_QUEUE_TC_MAP;
1650 args.in_args = (uint8_t *)q_tc_mapping;
1651 args.in_args_size = size;
1652 args.out_buffer = vf->aq_resp;
1653 args.out_size = IAVF_AQ_BUF_SZ;
1655 err = iavf_execute_vf_cmd(adapter, &args, 0);
1657 PMD_DRV_LOG(ERR, "Failed to execute command of"
1658 " VIRTCHNL_OP_CONFIG_TC_MAP");
1662 int iavf_set_q_bw(struct rte_eth_dev *dev,
1663 struct virtchnl_queues_bw_cfg *q_bw, uint16_t size)
1665 struct iavf_adapter *adapter =
1666 IAVF_DEV_PRIVATE_TO_ADAPTER(dev->data->dev_private);
1667 struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(dev->data->dev_private);
1668 struct iavf_cmd_info args;
1671 memset(&args, 0, sizeof(args));
1672 args.ops = VIRTCHNL_OP_CONFIG_QUEUE_BW;
1673 args.in_args = (uint8_t *)q_bw;
1674 args.in_args_size = size;
1675 args.out_buffer = vf->aq_resp;
1676 args.out_size = IAVF_AQ_BUF_SZ;
1678 err = iavf_execute_vf_cmd(adapter, &args, 0);
1680 PMD_DRV_LOG(ERR, "Failed to execute command of"
1681 " VIRTCHNL_OP_CONFIG_QUEUE_BW");
1686 iavf_add_del_mc_addr_list(struct iavf_adapter *adapter,
1687 struct rte_ether_addr *mc_addrs,
1688 uint32_t mc_addrs_num, bool add)
1690 struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(adapter);
1691 uint8_t cmd_buffer[sizeof(struct virtchnl_ether_addr_list) +
1692 (IAVF_NUM_MACADDR_MAX * sizeof(struct virtchnl_ether_addr))];
1693 struct virtchnl_ether_addr_list *list;
1694 struct iavf_cmd_info args;
1698 if (mc_addrs == NULL || mc_addrs_num == 0)
1701 list = (struct virtchnl_ether_addr_list *)cmd_buffer;
1702 list->vsi_id = vf->vsi_res->vsi_id;
1703 list->num_elements = mc_addrs_num;
1705 for (i = 0; i < mc_addrs_num; i++) {
1706 if (!IAVF_IS_MULTICAST(mc_addrs[i].addr_bytes)) {
1707 PMD_DRV_LOG(ERR, "Invalid mac:" RTE_ETHER_ADDR_PRT_FMT,
1708 RTE_ETHER_ADDR_BYTES(&mc_addrs[i]));
1712 memcpy(list->list[i].addr, mc_addrs[i].addr_bytes,
1713 sizeof(list->list[i].addr));
1714 list->list[i].type = VIRTCHNL_ETHER_ADDR_EXTRA;
1717 args.ops = add ? VIRTCHNL_OP_ADD_ETH_ADDR : VIRTCHNL_OP_DEL_ETH_ADDR;
1718 args.in_args = cmd_buffer;
1719 args.in_args_size = sizeof(struct virtchnl_ether_addr_list) +
1720 i * sizeof(struct virtchnl_ether_addr);
1721 args.out_buffer = vf->aq_resp;
1722 args.out_size = IAVF_AQ_BUF_SZ;
1723 err = iavf_execute_vf_cmd(adapter, &args, 0);
1726 PMD_DRV_LOG(ERR, "fail to execute command %s",
1727 add ? "OP_ADD_ETH_ADDR" : "OP_DEL_ETH_ADDR");
1735 iavf_request_queues(struct rte_eth_dev *dev, uint16_t num)
1737 struct iavf_adapter *adapter =
1738 IAVF_DEV_PRIVATE_TO_ADAPTER(dev->data->dev_private);
1739 struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(adapter);
1740 struct rte_pci_device *pci_dev = RTE_ETH_DEV_TO_PCI(dev);
1741 struct virtchnl_vf_res_request vfres;
1742 struct iavf_cmd_info args;
1743 uint16_t num_queue_pairs;
1746 if (!(vf->vf_res->vf_cap_flags &
1747 VIRTCHNL_VF_OFFLOAD_REQ_QUEUES)) {
1748 PMD_DRV_LOG(ERR, "request queues not supported");
1753 PMD_DRV_LOG(ERR, "queue number cannot be zero");
1756 vfres.num_queue_pairs = num;
1758 args.ops = VIRTCHNL_OP_REQUEST_QUEUES;
1759 args.in_args = (u8 *)&vfres;
1760 args.in_args_size = sizeof(vfres);
1761 args.out_buffer = vf->aq_resp;
1762 args.out_size = IAVF_AQ_BUF_SZ;
1764 if (vf->vf_res->vf_cap_flags & VIRTCHNL_VF_OFFLOAD_WB_ON_ITR) {
1765 /* disable interrupt to avoid the admin queue message to be read
1766 * before iavf_read_msg_from_pf.
1768 rte_intr_disable(pci_dev->intr_handle);
1769 err = iavf_execute_vf_cmd(adapter, &args, 0);
1770 rte_intr_enable(pci_dev->intr_handle);
1772 rte_eal_alarm_cancel(iavf_dev_alarm_handler, dev);
1773 err = iavf_execute_vf_cmd(adapter, &args, 0);
1774 rte_eal_alarm_set(IAVF_ALARM_INTERVAL,
1775 iavf_dev_alarm_handler, dev);
1779 PMD_DRV_LOG(ERR, "fail to execute command OP_REQUEST_QUEUES");
1783 /* request queues succeeded, vf is resetting */
1785 PMD_DRV_LOG(INFO, "vf is resetting");
1789 /* request additional queues failed, return available number */
1791 ((struct virtchnl_vf_res_request *)args.out_buffer)->num_queue_pairs;
1792 PMD_DRV_LOG(ERR, "request queues failed, only %u queues "
1793 "available", num_queue_pairs);
1799 iavf_get_max_rss_queue_region(struct iavf_adapter *adapter)
1801 struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(adapter);
1802 struct iavf_cmd_info args;
1803 uint16_t qregion_width;
1806 args.ops = VIRTCHNL_OP_GET_MAX_RSS_QREGION;
1807 args.in_args = NULL;
1808 args.in_args_size = 0;
1809 args.out_buffer = vf->aq_resp;
1810 args.out_size = IAVF_AQ_BUF_SZ;
1812 err = iavf_execute_vf_cmd(adapter, &args, 0);
1814 PMD_DRV_LOG(ERR, "Failed to execute command of VIRTCHNL_OP_GET_MAX_RSS_QREGION");
1819 ((struct virtchnl_max_rss_qregion *)args.out_buffer)->qregion_width;
1821 vf->max_rss_qregion = (uint16_t)(1 << qregion_width);
1829 iavf_ipsec_crypto_request(struct iavf_adapter *adapter,
1830 uint8_t *msg, size_t msg_len,
1831 uint8_t *resp_msg, size_t resp_msg_len)
1833 struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(adapter);
1834 struct iavf_cmd_info args;
1837 args.ops = VIRTCHNL_OP_INLINE_IPSEC_CRYPTO;
1839 args.in_args_size = msg_len;
1840 args.out_buffer = vf->aq_resp;
1841 args.out_size = IAVF_AQ_BUF_SZ;
1843 err = iavf_execute_vf_cmd(adapter, &args, 1);
1845 PMD_DRV_LOG(ERR, "fail to execute command %s",
1846 "OP_INLINE_IPSEC_CRYPTO");
1850 memcpy(resp_msg, args.out_buffer, resp_msg_len);
1856 iavf_set_vf_quanta_size(struct iavf_adapter *adapter, u16 start_queue_id, u16 num_queues)
1858 struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(adapter);
1859 struct iavf_cmd_info args;
1860 struct virtchnl_quanta_cfg q_quanta;
1863 if (adapter->devargs.quanta_size == 0)
1866 q_quanta.quanta_size = adapter->devargs.quanta_size;
1867 q_quanta.queue_select.type = VIRTCHNL_QUEUE_TYPE_TX;
1868 q_quanta.queue_select.start_queue_id = start_queue_id;
1869 q_quanta.queue_select.num_queues = num_queues;
1871 args.ops = VIRTCHNL_OP_CONFIG_QUANTA;
1872 args.in_args = (uint8_t *)&q_quanta;
1873 args.in_args_size = sizeof(q_quanta);
1874 args.out_buffer = vf->aq_resp;
1875 args.out_size = IAVF_AQ_BUF_SZ;
1877 err = iavf_execute_vf_cmd(adapter, &args, 0);
1879 PMD_DRV_LOG(ERR, "Failed to execute command VIRTCHNL_OP_CONFIG_QUANTA");
1887 iavf_get_ptp_cap(struct iavf_adapter *adapter)
1889 struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(adapter);
1890 struct virtchnl_ptp_caps ptp_caps;
1891 struct iavf_cmd_info args;
1894 ptp_caps.caps = VIRTCHNL_1588_PTP_CAP_RX_TSTAMP |
1895 VIRTCHNL_1588_PTP_CAP_READ_PHC;
1897 args.ops = VIRTCHNL_OP_1588_PTP_GET_CAPS;
1898 args.in_args = (uint8_t *)&ptp_caps;
1899 args.in_args_size = sizeof(ptp_caps);
1900 args.out_buffer = vf->aq_resp;
1901 args.out_size = IAVF_AQ_BUF_SZ;
1903 err = iavf_execute_vf_cmd(adapter, &args, 0);
1906 "Failed to execute command of OP_1588_PTP_GET_CAPS");
1910 vf->ptp_caps = ((struct virtchnl_ptp_caps *)args.out_buffer)->caps;
1916 iavf_get_phc_time(struct iavf_rx_queue *rxq)
1918 struct iavf_adapter *adapter = rxq->vsi->adapter;
1919 struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(adapter);
1920 struct virtchnl_phc_time phc_time;
1921 struct iavf_cmd_info args;
1924 args.ops = VIRTCHNL_OP_1588_PTP_GET_TIME;
1925 args.in_args = (uint8_t *)&phc_time;
1926 args.in_args_size = sizeof(phc_time);
1927 args.out_buffer = vf->aq_resp;
1928 args.out_size = IAVF_AQ_BUF_SZ;
1930 rte_spinlock_lock(&vf->phc_time_aq_lock);
1931 err = iavf_execute_vf_cmd(adapter, &args, 0);
1934 "Failed to execute command of VIRTCHNL_OP_1588_PTP_GET_TIME");
1937 rxq->phc_time = ((struct virtchnl_phc_time *)args.out_buffer)->time;
1940 rte_spinlock_unlock(&vf->phc_time_aq_lock);