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 (msglen < sizeof(struct virtchnl_pf_event)) {
269 PMD_DRV_LOG(DEBUG, "Error event");
272 switch (pf_msg->event) {
273 case VIRTCHNL_EVENT_RESET_IMPENDING:
274 PMD_DRV_LOG(DEBUG, "VIRTCHNL_EVENT_RESET_IMPENDING event");
276 rte_eth_dev_callback_process(dev, RTE_ETH_EVENT_INTR_RESET,
279 case VIRTCHNL_EVENT_LINK_CHANGE:
280 PMD_DRV_LOG(DEBUG, "VIRTCHNL_EVENT_LINK_CHANGE event");
281 vf->link_up = pf_msg->event_data.link_event.link_status;
282 if (vf->vf_res->vf_cap_flags & VIRTCHNL_VF_CAP_ADV_LINK_SPEED) {
284 pf_msg->event_data.link_event_adv.link_speed;
286 enum virtchnl_link_speed speed;
287 speed = pf_msg->event_data.link_event.link_speed;
288 vf->link_speed = iavf_convert_link_speed(speed);
290 iavf_dev_link_update(dev, 0);
291 rte_eth_dev_callback_process(dev, RTE_ETH_EVENT_INTR_LSC, NULL);
293 case VIRTCHNL_EVENT_PF_DRIVER_CLOSE:
294 PMD_DRV_LOG(DEBUG, "VIRTCHNL_EVENT_PF_DRIVER_CLOSE event");
297 PMD_DRV_LOG(ERR, " unknown event received %u", pf_msg->event);
303 iavf_handle_virtchnl_msg(struct rte_eth_dev *dev)
305 struct iavf_hw *hw = IAVF_DEV_PRIVATE_TO_HW(dev->data->dev_private);
306 struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(dev->data->dev_private);
307 struct iavf_arq_event_info info;
308 uint16_t pending, aq_opc;
309 enum virtchnl_ops msg_opc;
310 enum iavf_status msg_ret;
313 info.buf_len = IAVF_AQ_BUF_SZ;
315 PMD_DRV_LOG(ERR, "Buffer for adminq resp should not be NULL");
318 info.msg_buf = vf->aq_resp;
322 ret = iavf_clean_arq_element(hw, &info, &pending);
324 if (ret != IAVF_SUCCESS) {
325 PMD_DRV_LOG(INFO, "Failed to read msg from AdminQ,"
329 aq_opc = rte_le_to_cpu_16(info.desc.opcode);
330 /* For the message sent from pf to vf, opcode is stored in
331 * cookie_high of struct iavf_aq_desc, while return error code
332 * are stored in cookie_low, Which is done by PF driver.
334 msg_opc = (enum virtchnl_ops)rte_le_to_cpu_32(
335 info.desc.cookie_high);
336 msg_ret = (enum iavf_status)rte_le_to_cpu_32(
337 info.desc.cookie_low);
339 case iavf_aqc_opc_send_msg_to_vf:
340 if (msg_opc == VIRTCHNL_OP_EVENT) {
341 iavf_handle_pf_event_msg(dev, info.msg_buf,
344 /* check for inline IPsec events */
345 struct inline_ipsec_msg *imsg =
346 (struct inline_ipsec_msg *)info.msg_buf;
347 struct rte_eth_event_ipsec_desc desc;
349 VIRTCHNL_OP_INLINE_IPSEC_CRYPTO &&
350 imsg->ipsec_opcode ==
351 INLINE_IPSEC_OP_EVENT) {
352 struct virtchnl_ipsec_event *ev =
353 imsg->ipsec_data.event;
355 RTE_ETH_EVENT_IPSEC_UNKNOWN;
356 desc.metadata = ev->ipsec_event_data;
357 rte_eth_dev_callback_process(dev,
363 /* read message and it's expected one */
364 if (msg_opc == vf->pend_cmd) {
366 __atomic_sub_fetch(&vf->pend_cmd_count,
367 1, __ATOMIC_RELAXED);
369 _notify_cmd(vf, msg_ret);
372 "command mismatch, expect %u, get %u",
373 vf->pend_cmd, msg_opc);
376 "adminq response is received, opcode = %d",
381 PMD_DRV_LOG(DEBUG, "Request %u is not supported yet",
389 iavf_enable_vlan_strip(struct iavf_adapter *adapter)
391 struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(adapter);
392 struct iavf_cmd_info args;
395 memset(&args, 0, sizeof(args));
396 args.ops = VIRTCHNL_OP_ENABLE_VLAN_STRIPPING;
398 args.in_args_size = 0;
399 args.out_buffer = vf->aq_resp;
400 args.out_size = IAVF_AQ_BUF_SZ;
401 ret = iavf_execute_vf_cmd(adapter, &args, 0);
403 PMD_DRV_LOG(ERR, "Failed to execute command of"
404 " OP_ENABLE_VLAN_STRIPPING");
410 iavf_disable_vlan_strip(struct iavf_adapter *adapter)
412 struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(adapter);
413 struct iavf_cmd_info args;
416 memset(&args, 0, sizeof(args));
417 args.ops = VIRTCHNL_OP_DISABLE_VLAN_STRIPPING;
419 args.in_args_size = 0;
420 args.out_buffer = vf->aq_resp;
421 args.out_size = IAVF_AQ_BUF_SZ;
422 ret = iavf_execute_vf_cmd(adapter, &args, 0);
424 PMD_DRV_LOG(ERR, "Failed to execute command of"
425 " OP_DISABLE_VLAN_STRIPPING");
430 #define VIRTCHNL_VERSION_MAJOR_START 1
431 #define VIRTCHNL_VERSION_MINOR_START 1
433 /* Check API version with sync wait until version read from admin queue */
435 iavf_check_api_version(struct iavf_adapter *adapter)
437 struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(adapter);
438 struct virtchnl_version_info version, *pver;
439 struct iavf_cmd_info args;
442 version.major = VIRTCHNL_VERSION_MAJOR;
443 version.minor = VIRTCHNL_VERSION_MINOR;
445 args.ops = VIRTCHNL_OP_VERSION;
446 args.in_args = (uint8_t *)&version;
447 args.in_args_size = sizeof(version);
448 args.out_buffer = vf->aq_resp;
449 args.out_size = IAVF_AQ_BUF_SZ;
451 err = iavf_execute_vf_cmd(adapter, &args, 0);
453 PMD_INIT_LOG(ERR, "Fail to execute command of OP_VERSION");
457 pver = (struct virtchnl_version_info *)args.out_buffer;
458 vf->virtchnl_version = *pver;
460 if (vf->virtchnl_version.major < VIRTCHNL_VERSION_MAJOR_START ||
461 (vf->virtchnl_version.major == VIRTCHNL_VERSION_MAJOR_START &&
462 vf->virtchnl_version.minor < VIRTCHNL_VERSION_MINOR_START)) {
463 PMD_INIT_LOG(ERR, "VIRTCHNL API version should not be lower"
464 " than (%u.%u) to support Adaptive VF",
465 VIRTCHNL_VERSION_MAJOR_START,
466 VIRTCHNL_VERSION_MAJOR_START);
468 } else if (vf->virtchnl_version.major > VIRTCHNL_VERSION_MAJOR ||
469 (vf->virtchnl_version.major == VIRTCHNL_VERSION_MAJOR &&
470 vf->virtchnl_version.minor > VIRTCHNL_VERSION_MINOR)) {
471 PMD_INIT_LOG(ERR, "PF/VF API version mismatch:(%u.%u)-(%u.%u)",
472 vf->virtchnl_version.major,
473 vf->virtchnl_version.minor,
474 VIRTCHNL_VERSION_MAJOR,
475 VIRTCHNL_VERSION_MINOR);
479 PMD_DRV_LOG(DEBUG, "Peer is supported PF host");
484 iavf_get_vf_resource(struct iavf_adapter *adapter)
486 struct iavf_hw *hw = IAVF_DEV_PRIVATE_TO_HW(adapter);
487 struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(adapter);
488 struct iavf_cmd_info args;
492 args.ops = VIRTCHNL_OP_GET_VF_RESOURCES;
493 args.out_buffer = vf->aq_resp;
494 args.out_size = IAVF_AQ_BUF_SZ;
496 caps = IAVF_BASIC_OFFLOAD_CAPS | VIRTCHNL_VF_CAP_ADV_LINK_SPEED |
497 VIRTCHNL_VF_OFFLOAD_RX_FLEX_DESC |
498 VIRTCHNL_VF_OFFLOAD_FDIR_PF |
499 VIRTCHNL_VF_OFFLOAD_ADV_RSS_PF |
500 VIRTCHNL_VF_OFFLOAD_REQ_QUEUES |
501 VIRTCHNL_VF_OFFLOAD_CRC |
502 VIRTCHNL_VF_OFFLOAD_VLAN_V2 |
503 VIRTCHNL_VF_LARGE_NUM_QPAIRS |
504 VIRTCHNL_VF_OFFLOAD_QOS |
505 VIRTCHNL_VF_OFFLOAD_INLINE_IPSEC_CRYPTO |
508 args.in_args = (uint8_t *)∩︀
509 args.in_args_size = sizeof(caps);
511 err = iavf_execute_vf_cmd(adapter, &args, 0);
515 "Failed to execute command of OP_GET_VF_RESOURCE");
519 len = sizeof(struct virtchnl_vf_resource) +
520 IAVF_MAX_VF_VSI * sizeof(struct virtchnl_vsi_resource);
522 rte_memcpy(vf->vf_res, args.out_buffer,
523 RTE_MIN(args.out_size, len));
524 /* parse VF config message back from PF*/
525 iavf_vf_parse_hw_config(hw, vf->vf_res);
526 for (i = 0; i < vf->vf_res->num_vsis; i++) {
527 if (vf->vf_res->vsi_res[i].vsi_type == VIRTCHNL_VSI_SRIOV)
528 vf->vsi_res = &vf->vf_res->vsi_res[i];
532 PMD_INIT_LOG(ERR, "no LAN VSI found");
536 vf->vsi.vsi_id = vf->vsi_res->vsi_id;
537 vf->vsi.nb_qps = vf->vsi_res->num_queue_pairs;
538 vf->vsi.adapter = adapter;
544 iavf_get_supported_rxdid(struct iavf_adapter *adapter)
546 struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(adapter);
547 struct iavf_cmd_info args;
550 args.ops = VIRTCHNL_OP_GET_SUPPORTED_RXDIDS;
552 args.in_args_size = 0;
553 args.out_buffer = vf->aq_resp;
554 args.out_size = IAVF_AQ_BUF_SZ;
556 ret = iavf_execute_vf_cmd(adapter, &args, 0);
559 "Failed to execute command of OP_GET_SUPPORTED_RXDIDS");
563 vf->supported_rxdid =
564 ((struct virtchnl_supported_rxdids *)args.out_buffer)->supported_rxdids;
570 iavf_config_vlan_strip_v2(struct iavf_adapter *adapter, bool enable)
572 struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(adapter);
573 struct virtchnl_vlan_supported_caps *stripping_caps;
574 struct virtchnl_vlan_setting vlan_strip;
575 struct iavf_cmd_info args;
579 stripping_caps = &vf->vlan_v2_caps.offloads.stripping_support;
581 if ((stripping_caps->outer & VIRTCHNL_VLAN_ETHERTYPE_8100) &&
582 (stripping_caps->outer & VIRTCHNL_VLAN_TOGGLE))
583 ethertype = &vlan_strip.outer_ethertype_setting;
584 else if ((stripping_caps->inner & VIRTCHNL_VLAN_ETHERTYPE_8100) &&
585 (stripping_caps->inner & VIRTCHNL_VLAN_TOGGLE))
586 ethertype = &vlan_strip.inner_ethertype_setting;
590 memset(&vlan_strip, 0, sizeof(vlan_strip));
591 vlan_strip.vport_id = vf->vsi_res->vsi_id;
592 *ethertype = VIRTCHNL_VLAN_ETHERTYPE_8100;
594 args.ops = enable ? VIRTCHNL_OP_ENABLE_VLAN_STRIPPING_V2 :
595 VIRTCHNL_OP_DISABLE_VLAN_STRIPPING_V2;
596 args.in_args = (uint8_t *)&vlan_strip;
597 args.in_args_size = sizeof(vlan_strip);
598 args.out_buffer = vf->aq_resp;
599 args.out_size = IAVF_AQ_BUF_SZ;
600 ret = iavf_execute_vf_cmd(adapter, &args, 0);
602 PMD_DRV_LOG(ERR, "fail to execute command %s",
603 enable ? "VIRTCHNL_OP_ENABLE_VLAN_STRIPPING_V2" :
604 "VIRTCHNL_OP_DISABLE_VLAN_STRIPPING_V2");
610 iavf_config_vlan_insert_v2(struct iavf_adapter *adapter, bool enable)
612 struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(adapter);
613 struct virtchnl_vlan_supported_caps *insertion_caps;
614 struct virtchnl_vlan_setting vlan_insert;
615 struct iavf_cmd_info args;
619 insertion_caps = &vf->vlan_v2_caps.offloads.insertion_support;
621 if ((insertion_caps->outer & VIRTCHNL_VLAN_ETHERTYPE_8100) &&
622 (insertion_caps->outer & VIRTCHNL_VLAN_TOGGLE))
623 ethertype = &vlan_insert.outer_ethertype_setting;
624 else if ((insertion_caps->inner & VIRTCHNL_VLAN_ETHERTYPE_8100) &&
625 (insertion_caps->inner & VIRTCHNL_VLAN_TOGGLE))
626 ethertype = &vlan_insert.inner_ethertype_setting;
630 memset(&vlan_insert, 0, sizeof(vlan_insert));
631 vlan_insert.vport_id = vf->vsi_res->vsi_id;
632 *ethertype = VIRTCHNL_VLAN_ETHERTYPE_8100;
634 args.ops = enable ? VIRTCHNL_OP_ENABLE_VLAN_INSERTION_V2 :
635 VIRTCHNL_OP_DISABLE_VLAN_INSERTION_V2;
636 args.in_args = (uint8_t *)&vlan_insert;
637 args.in_args_size = sizeof(vlan_insert);
638 args.out_buffer = vf->aq_resp;
639 args.out_size = IAVF_AQ_BUF_SZ;
640 ret = iavf_execute_vf_cmd(adapter, &args, 0);
642 PMD_DRV_LOG(ERR, "fail to execute command %s",
643 enable ? "VIRTCHNL_OP_ENABLE_VLAN_INSERTION_V2" :
644 "VIRTCHNL_OP_DISABLE_VLAN_INSERTION_V2");
650 iavf_add_del_vlan_v2(struct iavf_adapter *adapter, uint16_t vlanid, bool add)
652 struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(adapter);
653 struct virtchnl_vlan_supported_caps *supported_caps;
654 struct virtchnl_vlan_filter_list_v2 vlan_filter;
655 struct virtchnl_vlan *vlan_setting;
656 struct iavf_cmd_info args;
657 uint32_t filtering_caps;
660 supported_caps = &vf->vlan_v2_caps.filtering.filtering_support;
661 if (supported_caps->outer) {
662 filtering_caps = supported_caps->outer;
663 vlan_setting = &vlan_filter.filters[0].outer;
665 filtering_caps = supported_caps->inner;
666 vlan_setting = &vlan_filter.filters[0].inner;
669 if (!(filtering_caps & VIRTCHNL_VLAN_ETHERTYPE_8100))
672 memset(&vlan_filter, 0, sizeof(vlan_filter));
673 vlan_filter.vport_id = vf->vsi_res->vsi_id;
674 vlan_filter.num_elements = 1;
675 vlan_setting->tpid = RTE_ETHER_TYPE_VLAN;
676 vlan_setting->tci = vlanid;
678 args.ops = add ? VIRTCHNL_OP_ADD_VLAN_V2 : VIRTCHNL_OP_DEL_VLAN_V2;
679 args.in_args = (uint8_t *)&vlan_filter;
680 args.in_args_size = sizeof(vlan_filter);
681 args.out_buffer = vf->aq_resp;
682 args.out_size = IAVF_AQ_BUF_SZ;
683 err = iavf_execute_vf_cmd(adapter, &args, 0);
685 PMD_DRV_LOG(ERR, "fail to execute command %s",
686 add ? "OP_ADD_VLAN_V2" : "OP_DEL_VLAN_V2");
692 iavf_get_vlan_offload_caps_v2(struct iavf_adapter *adapter)
694 struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(adapter);
695 struct iavf_cmd_info args;
698 args.ops = VIRTCHNL_OP_GET_OFFLOAD_VLAN_V2_CAPS;
700 args.in_args_size = 0;
701 args.out_buffer = vf->aq_resp;
702 args.out_size = IAVF_AQ_BUF_SZ;
704 ret = iavf_execute_vf_cmd(adapter, &args, 0);
707 "Failed to execute command of VIRTCHNL_OP_GET_OFFLOAD_VLAN_V2_CAPS");
711 rte_memcpy(&vf->vlan_v2_caps, vf->aq_resp, sizeof(vf->vlan_v2_caps));
717 iavf_enable_queues(struct iavf_adapter *adapter)
719 struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(adapter);
720 struct virtchnl_queue_select queue_select;
721 struct iavf_cmd_info args;
724 memset(&queue_select, 0, sizeof(queue_select));
725 queue_select.vsi_id = vf->vsi_res->vsi_id;
727 queue_select.rx_queues = BIT(adapter->dev_data->nb_rx_queues) - 1;
728 queue_select.tx_queues = BIT(adapter->dev_data->nb_tx_queues) - 1;
730 args.ops = VIRTCHNL_OP_ENABLE_QUEUES;
731 args.in_args = (u8 *)&queue_select;
732 args.in_args_size = sizeof(queue_select);
733 args.out_buffer = vf->aq_resp;
734 args.out_size = IAVF_AQ_BUF_SZ;
735 err = iavf_execute_vf_cmd(adapter, &args, 0);
738 "Failed to execute command of OP_ENABLE_QUEUES");
745 iavf_disable_queues(struct iavf_adapter *adapter)
747 struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(adapter);
748 struct virtchnl_queue_select queue_select;
749 struct iavf_cmd_info args;
752 memset(&queue_select, 0, sizeof(queue_select));
753 queue_select.vsi_id = vf->vsi_res->vsi_id;
755 queue_select.rx_queues = BIT(adapter->dev_data->nb_rx_queues) - 1;
756 queue_select.tx_queues = BIT(adapter->dev_data->nb_tx_queues) - 1;
758 args.ops = VIRTCHNL_OP_DISABLE_QUEUES;
759 args.in_args = (u8 *)&queue_select;
760 args.in_args_size = sizeof(queue_select);
761 args.out_buffer = vf->aq_resp;
762 args.out_size = IAVF_AQ_BUF_SZ;
763 err = iavf_execute_vf_cmd(adapter, &args, 0);
766 "Failed to execute command of OP_DISABLE_QUEUES");
773 iavf_switch_queue(struct iavf_adapter *adapter, uint16_t qid,
776 struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(adapter);
777 struct virtchnl_queue_select queue_select;
778 struct iavf_cmd_info args;
781 memset(&queue_select, 0, sizeof(queue_select));
782 queue_select.vsi_id = vf->vsi_res->vsi_id;
784 queue_select.rx_queues |= 1 << qid;
786 queue_select.tx_queues |= 1 << qid;
789 args.ops = VIRTCHNL_OP_ENABLE_QUEUES;
791 args.ops = VIRTCHNL_OP_DISABLE_QUEUES;
792 args.in_args = (u8 *)&queue_select;
793 args.in_args_size = sizeof(queue_select);
794 args.out_buffer = vf->aq_resp;
795 args.out_size = IAVF_AQ_BUF_SZ;
796 err = iavf_execute_vf_cmd(adapter, &args, 0);
798 PMD_DRV_LOG(ERR, "Failed to execute command of %s",
799 on ? "OP_ENABLE_QUEUES" : "OP_DISABLE_QUEUES");
804 iavf_enable_queues_lv(struct iavf_adapter *adapter)
806 struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(adapter);
807 struct virtchnl_del_ena_dis_queues *queue_select;
808 struct virtchnl_queue_chunk *queue_chunk;
809 struct iavf_cmd_info args;
812 len = sizeof(struct virtchnl_del_ena_dis_queues) +
813 sizeof(struct virtchnl_queue_chunk) *
814 (IAVF_RXTX_QUEUE_CHUNKS_NUM - 1);
815 queue_select = rte_zmalloc("queue_select", len, 0);
819 queue_chunk = queue_select->chunks.chunks;
820 queue_select->chunks.num_chunks = IAVF_RXTX_QUEUE_CHUNKS_NUM;
821 queue_select->vport_id = vf->vsi_res->vsi_id;
823 queue_chunk[VIRTCHNL_QUEUE_TYPE_TX].type = VIRTCHNL_QUEUE_TYPE_TX;
824 queue_chunk[VIRTCHNL_QUEUE_TYPE_TX].start_queue_id = 0;
825 queue_chunk[VIRTCHNL_QUEUE_TYPE_TX].num_queues =
826 adapter->dev_data->nb_tx_queues;
828 queue_chunk[VIRTCHNL_QUEUE_TYPE_RX].type = VIRTCHNL_QUEUE_TYPE_RX;
829 queue_chunk[VIRTCHNL_QUEUE_TYPE_RX].start_queue_id = 0;
830 queue_chunk[VIRTCHNL_QUEUE_TYPE_RX].num_queues =
831 adapter->dev_data->nb_rx_queues;
833 args.ops = VIRTCHNL_OP_ENABLE_QUEUES_V2;
834 args.in_args = (u8 *)queue_select;
835 args.in_args_size = len;
836 args.out_buffer = vf->aq_resp;
837 args.out_size = IAVF_AQ_BUF_SZ;
838 err = iavf_execute_vf_cmd(adapter, &args, 0);
841 "Failed to execute command of OP_ENABLE_QUEUES_V2");
843 rte_free(queue_select);
848 iavf_disable_queues_lv(struct iavf_adapter *adapter)
850 struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(adapter);
851 struct virtchnl_del_ena_dis_queues *queue_select;
852 struct virtchnl_queue_chunk *queue_chunk;
853 struct iavf_cmd_info args;
856 len = sizeof(struct virtchnl_del_ena_dis_queues) +
857 sizeof(struct virtchnl_queue_chunk) *
858 (IAVF_RXTX_QUEUE_CHUNKS_NUM - 1);
859 queue_select = rte_zmalloc("queue_select", len, 0);
863 queue_chunk = queue_select->chunks.chunks;
864 queue_select->chunks.num_chunks = IAVF_RXTX_QUEUE_CHUNKS_NUM;
865 queue_select->vport_id = vf->vsi_res->vsi_id;
867 queue_chunk[VIRTCHNL_QUEUE_TYPE_TX].type = VIRTCHNL_QUEUE_TYPE_TX;
868 queue_chunk[VIRTCHNL_QUEUE_TYPE_TX].start_queue_id = 0;
869 queue_chunk[VIRTCHNL_QUEUE_TYPE_TX].num_queues =
870 adapter->dev_data->nb_tx_queues;
872 queue_chunk[VIRTCHNL_QUEUE_TYPE_RX].type = VIRTCHNL_QUEUE_TYPE_RX;
873 queue_chunk[VIRTCHNL_QUEUE_TYPE_RX].start_queue_id = 0;
874 queue_chunk[VIRTCHNL_QUEUE_TYPE_RX].num_queues =
875 adapter->dev_data->nb_rx_queues;
877 args.ops = VIRTCHNL_OP_DISABLE_QUEUES_V2;
878 args.in_args = (u8 *)queue_select;
879 args.in_args_size = len;
880 args.out_buffer = vf->aq_resp;
881 args.out_size = IAVF_AQ_BUF_SZ;
882 err = iavf_execute_vf_cmd(adapter, &args, 0);
885 "Failed to execute command of OP_DISABLE_QUEUES_V2");
887 rte_free(queue_select);
892 iavf_switch_queue_lv(struct iavf_adapter *adapter, uint16_t qid,
895 struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(adapter);
896 struct virtchnl_del_ena_dis_queues *queue_select;
897 struct virtchnl_queue_chunk *queue_chunk;
898 struct iavf_cmd_info args;
901 len = sizeof(struct virtchnl_del_ena_dis_queues);
902 queue_select = rte_zmalloc("queue_select", len, 0);
906 queue_chunk = queue_select->chunks.chunks;
907 queue_select->chunks.num_chunks = 1;
908 queue_select->vport_id = vf->vsi_res->vsi_id;
911 queue_chunk->type = VIRTCHNL_QUEUE_TYPE_RX;
912 queue_chunk->start_queue_id = qid;
913 queue_chunk->num_queues = 1;
915 queue_chunk->type = VIRTCHNL_QUEUE_TYPE_TX;
916 queue_chunk->start_queue_id = qid;
917 queue_chunk->num_queues = 1;
921 args.ops = VIRTCHNL_OP_ENABLE_QUEUES_V2;
923 args.ops = VIRTCHNL_OP_DISABLE_QUEUES_V2;
924 args.in_args = (u8 *)queue_select;
925 args.in_args_size = len;
926 args.out_buffer = vf->aq_resp;
927 args.out_size = IAVF_AQ_BUF_SZ;
928 err = iavf_execute_vf_cmd(adapter, &args, 0);
930 PMD_DRV_LOG(ERR, "Failed to execute command of %s",
931 on ? "OP_ENABLE_QUEUES_V2" : "OP_DISABLE_QUEUES_V2");
933 rte_free(queue_select);
938 iavf_configure_rss_lut(struct iavf_adapter *adapter)
940 struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(adapter);
941 struct virtchnl_rss_lut *rss_lut;
942 struct iavf_cmd_info args;
945 len = sizeof(*rss_lut) + vf->vf_res->rss_lut_size - 1;
946 rss_lut = rte_zmalloc("rss_lut", len, 0);
950 rss_lut->vsi_id = vf->vsi_res->vsi_id;
951 rss_lut->lut_entries = vf->vf_res->rss_lut_size;
952 rte_memcpy(rss_lut->lut, vf->rss_lut, vf->vf_res->rss_lut_size);
954 args.ops = VIRTCHNL_OP_CONFIG_RSS_LUT;
955 args.in_args = (u8 *)rss_lut;
956 args.in_args_size = len;
957 args.out_buffer = vf->aq_resp;
958 args.out_size = IAVF_AQ_BUF_SZ;
960 err = iavf_execute_vf_cmd(adapter, &args, 0);
963 "Failed to execute command of OP_CONFIG_RSS_LUT");
970 iavf_configure_rss_key(struct iavf_adapter *adapter)
972 struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(adapter);
973 struct virtchnl_rss_key *rss_key;
974 struct iavf_cmd_info args;
977 len = sizeof(*rss_key) + vf->vf_res->rss_key_size - 1;
978 rss_key = rte_zmalloc("rss_key", len, 0);
982 rss_key->vsi_id = vf->vsi_res->vsi_id;
983 rss_key->key_len = vf->vf_res->rss_key_size;
984 rte_memcpy(rss_key->key, vf->rss_key, vf->vf_res->rss_key_size);
986 args.ops = VIRTCHNL_OP_CONFIG_RSS_KEY;
987 args.in_args = (u8 *)rss_key;
988 args.in_args_size = len;
989 args.out_buffer = vf->aq_resp;
990 args.out_size = IAVF_AQ_BUF_SZ;
992 err = iavf_execute_vf_cmd(adapter, &args, 0);
995 "Failed to execute command of OP_CONFIG_RSS_KEY");
1002 iavf_configure_queues(struct iavf_adapter *adapter,
1003 uint16_t num_queue_pairs, uint16_t index)
1005 struct iavf_rx_queue **rxq =
1006 (struct iavf_rx_queue **)adapter->dev_data->rx_queues;
1007 struct iavf_tx_queue **txq =
1008 (struct iavf_tx_queue **)adapter->dev_data->tx_queues;
1009 struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(adapter);
1010 struct virtchnl_vsi_queue_config_info *vc_config;
1011 struct virtchnl_queue_pair_info *vc_qp;
1012 struct iavf_cmd_info args;
1016 size = sizeof(*vc_config) +
1017 sizeof(vc_config->qpair[0]) * num_queue_pairs;
1018 vc_config = rte_zmalloc("cfg_queue", size, 0);
1022 vc_config->vsi_id = vf->vsi_res->vsi_id;
1023 vc_config->num_queue_pairs = num_queue_pairs;
1025 for (i = index, vc_qp = vc_config->qpair;
1026 i < index + num_queue_pairs;
1028 vc_qp->txq.vsi_id = vf->vsi_res->vsi_id;
1029 vc_qp->txq.queue_id = i;
1031 /* Virtchnnl configure tx queues by pairs */
1032 if (i < adapter->dev_data->nb_tx_queues) {
1033 vc_qp->txq.ring_len = txq[i]->nb_tx_desc;
1034 vc_qp->txq.dma_ring_addr = txq[i]->tx_ring_phys_addr;
1037 vc_qp->rxq.vsi_id = vf->vsi_res->vsi_id;
1038 vc_qp->rxq.queue_id = i;
1039 vc_qp->rxq.max_pkt_size = vf->max_pkt_len;
1041 if (i >= adapter->dev_data->nb_rx_queues)
1044 /* Virtchnnl configure rx queues by pairs */
1045 vc_qp->rxq.ring_len = rxq[i]->nb_rx_desc;
1046 vc_qp->rxq.dma_ring_addr = rxq[i]->rx_ring_phys_addr;
1047 vc_qp->rxq.databuffer_size = rxq[i]->rx_buf_len;
1048 vc_qp->rxq.crc_disable = rxq[i]->crc_len != 0 ? 1 : 0;
1049 #ifndef RTE_LIBRTE_IAVF_16BYTE_RX_DESC
1050 if (vf->vf_res->vf_cap_flags &
1051 VIRTCHNL_VF_OFFLOAD_RX_FLEX_DESC) {
1052 if (vf->supported_rxdid & BIT(rxq[i]->rxdid)) {
1053 vc_qp->rxq.rxdid = rxq[i]->rxdid;
1054 PMD_DRV_LOG(NOTICE, "request RXDID[%d] in Queue[%d]",
1055 vc_qp->rxq.rxdid, i);
1057 PMD_DRV_LOG(NOTICE, "RXDID[%d] is not supported, "
1058 "request default RXDID[%d] in Queue[%d]",
1059 rxq[i]->rxdid, IAVF_RXDID_LEGACY_1, i);
1060 vc_qp->rxq.rxdid = IAVF_RXDID_LEGACY_1;
1063 if (vf->vf_res->vf_cap_flags & VIRTCHNL_VF_CAP_PTP &&
1064 vf->ptp_caps & VIRTCHNL_1588_PTP_CAP_RX_TSTAMP)
1065 vc_qp->rxq.flags |= VIRTCHNL_PTP_RX_TSTAMP;
1068 if (vf->vf_res->vf_cap_flags &
1069 VIRTCHNL_VF_OFFLOAD_RX_FLEX_DESC &&
1070 vf->supported_rxdid & BIT(IAVF_RXDID_LEGACY_0)) {
1071 vc_qp->rxq.rxdid = IAVF_RXDID_LEGACY_0;
1072 PMD_DRV_LOG(NOTICE, "request RXDID[%d] in Queue[%d]",
1073 vc_qp->rxq.rxdid, i);
1075 PMD_DRV_LOG(ERR, "RXDID[%d] is not supported",
1076 IAVF_RXDID_LEGACY_0);
1082 memset(&args, 0, sizeof(args));
1083 args.ops = VIRTCHNL_OP_CONFIG_VSI_QUEUES;
1084 args.in_args = (uint8_t *)vc_config;
1085 args.in_args_size = size;
1086 args.out_buffer = vf->aq_resp;
1087 args.out_size = IAVF_AQ_BUF_SZ;
1089 err = iavf_execute_vf_cmd(adapter, &args, 0);
1091 PMD_DRV_LOG(ERR, "Failed to execute command of"
1092 " VIRTCHNL_OP_CONFIG_VSI_QUEUES");
1094 rte_free(vc_config);
1099 iavf_config_irq_map(struct iavf_adapter *adapter)
1101 struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(adapter);
1102 struct virtchnl_irq_map_info *map_info;
1103 struct virtchnl_vector_map *vecmap;
1104 struct iavf_cmd_info args;
1107 len = sizeof(struct virtchnl_irq_map_info) +
1108 sizeof(struct virtchnl_vector_map) * vf->nb_msix;
1110 map_info = rte_zmalloc("map_info", len, 0);
1114 map_info->num_vectors = vf->nb_msix;
1115 for (i = 0; i < adapter->dev_data->nb_rx_queues; i++) {
1117 &map_info->vecmap[vf->qv_map[i].vector_id - vf->msix_base];
1118 vecmap->vsi_id = vf->vsi_res->vsi_id;
1119 vecmap->rxitr_idx = IAVF_ITR_INDEX_DEFAULT;
1120 vecmap->vector_id = vf->qv_map[i].vector_id;
1121 vecmap->txq_map = 0;
1122 vecmap->rxq_map |= 1 << vf->qv_map[i].queue_id;
1125 args.ops = VIRTCHNL_OP_CONFIG_IRQ_MAP;
1126 args.in_args = (u8 *)map_info;
1127 args.in_args_size = len;
1128 args.out_buffer = vf->aq_resp;
1129 args.out_size = IAVF_AQ_BUF_SZ;
1130 err = iavf_execute_vf_cmd(adapter, &args, 0);
1132 PMD_DRV_LOG(ERR, "fail to execute command OP_CONFIG_IRQ_MAP");
1139 iavf_config_irq_map_lv(struct iavf_adapter *adapter, uint16_t num,
1142 struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(adapter);
1143 struct virtchnl_queue_vector_maps *map_info;
1144 struct virtchnl_queue_vector *qv_maps;
1145 struct iavf_cmd_info args;
1149 len = sizeof(struct virtchnl_queue_vector_maps) +
1150 sizeof(struct virtchnl_queue_vector) * (num - 1);
1152 map_info = rte_zmalloc("map_info", len, 0);
1156 map_info->vport_id = vf->vsi_res->vsi_id;
1157 map_info->num_qv_maps = num;
1158 for (i = index; i < index + map_info->num_qv_maps; i++) {
1159 qv_maps = &map_info->qv_maps[count++];
1160 qv_maps->itr_idx = VIRTCHNL_ITR_IDX_0;
1161 qv_maps->queue_type = VIRTCHNL_QUEUE_TYPE_RX;
1162 qv_maps->queue_id = vf->qv_map[i].queue_id;
1163 qv_maps->vector_id = vf->qv_map[i].vector_id;
1166 args.ops = VIRTCHNL_OP_MAP_QUEUE_VECTOR;
1167 args.in_args = (u8 *)map_info;
1168 args.in_args_size = len;
1169 args.out_buffer = vf->aq_resp;
1170 args.out_size = IAVF_AQ_BUF_SZ;
1171 err = iavf_execute_vf_cmd(adapter, &args, 0);
1173 PMD_DRV_LOG(ERR, "fail to execute command OP_MAP_QUEUE_VECTOR");
1180 iavf_add_del_all_mac_addr(struct iavf_adapter *adapter, bool add)
1182 struct virtchnl_ether_addr_list *list;
1183 struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(adapter);
1184 struct rte_ether_addr *addr;
1185 struct iavf_cmd_info args;
1192 len = sizeof(struct virtchnl_ether_addr_list);
1193 for (i = begin; i < IAVF_NUM_MACADDR_MAX; i++, next_begin++) {
1194 addr = &adapter->dev_data->mac_addrs[i];
1195 if (rte_is_zero_ether_addr(addr))
1197 len += sizeof(struct virtchnl_ether_addr);
1198 if (len >= IAVF_AQ_BUF_SZ) {
1204 list = rte_zmalloc("iavf_del_mac_buffer", len, 0);
1206 PMD_DRV_LOG(ERR, "fail to allocate memory");
1210 for (i = begin; i < next_begin; i++) {
1211 addr = &adapter->dev_data->mac_addrs[i];
1212 if (rte_is_zero_ether_addr(addr))
1214 rte_memcpy(list->list[j].addr, addr->addr_bytes,
1215 sizeof(addr->addr_bytes));
1216 list->list[j].type = (j == 0 ?
1217 VIRTCHNL_ETHER_ADDR_PRIMARY :
1218 VIRTCHNL_ETHER_ADDR_EXTRA);
1219 PMD_DRV_LOG(DEBUG, "add/rm mac:" RTE_ETHER_ADDR_PRT_FMT,
1220 RTE_ETHER_ADDR_BYTES(addr));
1223 list->vsi_id = vf->vsi_res->vsi_id;
1224 list->num_elements = j;
1225 args.ops = add ? VIRTCHNL_OP_ADD_ETH_ADDR :
1226 VIRTCHNL_OP_DEL_ETH_ADDR;
1227 args.in_args = (uint8_t *)list;
1228 args.in_args_size = len;
1229 args.out_buffer = vf->aq_resp;
1230 args.out_size = IAVF_AQ_BUF_SZ;
1231 err = iavf_execute_vf_cmd(adapter, &args, 0);
1233 PMD_DRV_LOG(ERR, "fail to execute command %s",
1234 add ? "OP_ADD_ETHER_ADDRESS" :
1235 "OP_DEL_ETHER_ADDRESS");
1238 } while (begin < IAVF_NUM_MACADDR_MAX);
1242 iavf_query_stats(struct iavf_adapter *adapter,
1243 struct virtchnl_eth_stats **pstats)
1245 struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(adapter);
1246 struct virtchnl_queue_select q_stats;
1247 struct iavf_cmd_info args;
1250 memset(&q_stats, 0, sizeof(q_stats));
1251 q_stats.vsi_id = vf->vsi_res->vsi_id;
1252 args.ops = VIRTCHNL_OP_GET_STATS;
1253 args.in_args = (uint8_t *)&q_stats;
1254 args.in_args_size = sizeof(q_stats);
1255 args.out_buffer = vf->aq_resp;
1256 args.out_size = IAVF_AQ_BUF_SZ;
1258 err = iavf_execute_vf_cmd(adapter, &args, 0);
1260 PMD_DRV_LOG(ERR, "fail to execute command OP_GET_STATS");
1264 *pstats = (struct virtchnl_eth_stats *)args.out_buffer;
1269 iavf_config_promisc(struct iavf_adapter *adapter,
1270 bool enable_unicast,
1271 bool enable_multicast)
1273 struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(adapter);
1274 struct virtchnl_promisc_info promisc;
1275 struct iavf_cmd_info args;
1279 promisc.vsi_id = vf->vsi_res->vsi_id;
1282 promisc.flags |= FLAG_VF_UNICAST_PROMISC;
1284 if (enable_multicast)
1285 promisc.flags |= FLAG_VF_MULTICAST_PROMISC;
1287 args.ops = VIRTCHNL_OP_CONFIG_PROMISCUOUS_MODE;
1288 args.in_args = (uint8_t *)&promisc;
1289 args.in_args_size = sizeof(promisc);
1290 args.out_buffer = vf->aq_resp;
1291 args.out_size = IAVF_AQ_BUF_SZ;
1293 err = iavf_execute_vf_cmd(adapter, &args, 0);
1297 "fail to execute command CONFIG_PROMISCUOUS_MODE");
1299 if (err == -ENOTSUP)
1305 vf->promisc_unicast_enabled = enable_unicast;
1306 vf->promisc_multicast_enabled = enable_multicast;
1311 iavf_add_del_eth_addr(struct iavf_adapter *adapter, struct rte_ether_addr *addr,
1312 bool add, uint8_t type)
1314 struct virtchnl_ether_addr_list *list;
1315 struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(adapter);
1316 uint8_t cmd_buffer[sizeof(struct virtchnl_ether_addr_list) +
1317 sizeof(struct virtchnl_ether_addr)];
1318 struct iavf_cmd_info args;
1321 list = (struct virtchnl_ether_addr_list *)cmd_buffer;
1322 list->vsi_id = vf->vsi_res->vsi_id;
1323 list->num_elements = 1;
1324 list->list[0].type = type;
1325 rte_memcpy(list->list[0].addr, addr->addr_bytes,
1326 sizeof(addr->addr_bytes));
1328 args.ops = add ? VIRTCHNL_OP_ADD_ETH_ADDR : VIRTCHNL_OP_DEL_ETH_ADDR;
1329 args.in_args = cmd_buffer;
1330 args.in_args_size = sizeof(cmd_buffer);
1331 args.out_buffer = vf->aq_resp;
1332 args.out_size = IAVF_AQ_BUF_SZ;
1333 err = iavf_execute_vf_cmd(adapter, &args, 0);
1335 PMD_DRV_LOG(ERR, "fail to execute command %s",
1336 add ? "OP_ADD_ETH_ADDR" : "OP_DEL_ETH_ADDR");
1341 iavf_add_del_vlan(struct iavf_adapter *adapter, uint16_t vlanid, bool add)
1343 struct virtchnl_vlan_filter_list *vlan_list;
1344 struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(adapter);
1345 uint8_t cmd_buffer[sizeof(struct virtchnl_vlan_filter_list) +
1347 struct iavf_cmd_info args;
1350 vlan_list = (struct virtchnl_vlan_filter_list *)cmd_buffer;
1351 vlan_list->vsi_id = vf->vsi_res->vsi_id;
1352 vlan_list->num_elements = 1;
1353 vlan_list->vlan_id[0] = vlanid;
1355 args.ops = add ? VIRTCHNL_OP_ADD_VLAN : VIRTCHNL_OP_DEL_VLAN;
1356 args.in_args = cmd_buffer;
1357 args.in_args_size = sizeof(cmd_buffer);
1358 args.out_buffer = vf->aq_resp;
1359 args.out_size = IAVF_AQ_BUF_SZ;
1360 err = iavf_execute_vf_cmd(adapter, &args, 0);
1362 PMD_DRV_LOG(ERR, "fail to execute command %s",
1363 add ? "OP_ADD_VLAN" : "OP_DEL_VLAN");
1369 iavf_fdir_add(struct iavf_adapter *adapter,
1370 struct iavf_fdir_conf *filter)
1372 struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(adapter);
1373 struct virtchnl_fdir_add *fdir_ret;
1375 struct iavf_cmd_info args;
1378 filter->add_fltr.vsi_id = vf->vsi_res->vsi_id;
1379 filter->add_fltr.validate_only = 0;
1381 args.ops = VIRTCHNL_OP_ADD_FDIR_FILTER;
1382 args.in_args = (uint8_t *)(&filter->add_fltr);
1383 args.in_args_size = sizeof(*(&filter->add_fltr));
1384 args.out_buffer = vf->aq_resp;
1385 args.out_size = IAVF_AQ_BUF_SZ;
1387 err = iavf_execute_vf_cmd(adapter, &args, 0);
1389 PMD_DRV_LOG(ERR, "fail to execute command OP_ADD_FDIR_FILTER");
1393 fdir_ret = (struct virtchnl_fdir_add *)args.out_buffer;
1394 filter->flow_id = fdir_ret->flow_id;
1396 if (fdir_ret->status == VIRTCHNL_FDIR_SUCCESS) {
1398 "Succeed in adding rule request by PF");
1399 } else if (fdir_ret->status == VIRTCHNL_FDIR_FAILURE_RULE_NORESOURCE) {
1401 "Failed to add rule request due to no hw resource");
1403 } else if (fdir_ret->status == VIRTCHNL_FDIR_FAILURE_RULE_EXIST) {
1405 "Failed to add rule request due to the rule is already existed");
1407 } else if (fdir_ret->status == VIRTCHNL_FDIR_FAILURE_RULE_CONFLICT) {
1409 "Failed to add rule request due to the rule is conflict with existing rule");
1411 } else if (fdir_ret->status == VIRTCHNL_FDIR_FAILURE_RULE_INVALID) {
1413 "Failed to add rule request due to the hw doesn't support");
1415 } else if (fdir_ret->status == VIRTCHNL_FDIR_FAILURE_RULE_TIMEOUT) {
1417 "Failed to add rule request due to time out for programming");
1421 "Failed to add rule request due to other reasons");
1429 iavf_fdir_del(struct iavf_adapter *adapter,
1430 struct iavf_fdir_conf *filter)
1432 struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(adapter);
1433 struct virtchnl_fdir_del *fdir_ret;
1435 struct iavf_cmd_info args;
1438 filter->del_fltr.vsi_id = vf->vsi_res->vsi_id;
1439 filter->del_fltr.flow_id = filter->flow_id;
1441 args.ops = VIRTCHNL_OP_DEL_FDIR_FILTER;
1442 args.in_args = (uint8_t *)(&filter->del_fltr);
1443 args.in_args_size = sizeof(filter->del_fltr);
1444 args.out_buffer = vf->aq_resp;
1445 args.out_size = IAVF_AQ_BUF_SZ;
1447 err = iavf_execute_vf_cmd(adapter, &args, 0);
1449 PMD_DRV_LOG(ERR, "fail to execute command OP_DEL_FDIR_FILTER");
1453 fdir_ret = (struct virtchnl_fdir_del *)args.out_buffer;
1455 if (fdir_ret->status == VIRTCHNL_FDIR_SUCCESS) {
1457 "Succeed in deleting rule request by PF");
1458 } else if (fdir_ret->status == VIRTCHNL_FDIR_FAILURE_RULE_NONEXIST) {
1460 "Failed to delete rule request due to this rule doesn't exist");
1462 } else if (fdir_ret->status == VIRTCHNL_FDIR_FAILURE_RULE_TIMEOUT) {
1464 "Failed to delete rule request due to time out for programming");
1468 "Failed to delete rule request due to other reasons");
1476 iavf_fdir_check(struct iavf_adapter *adapter,
1477 struct iavf_fdir_conf *filter)
1479 struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(adapter);
1480 struct virtchnl_fdir_add *fdir_ret;
1482 struct iavf_cmd_info args;
1485 filter->add_fltr.vsi_id = vf->vsi_res->vsi_id;
1486 filter->add_fltr.validate_only = 1;
1488 args.ops = VIRTCHNL_OP_ADD_FDIR_FILTER;
1489 args.in_args = (uint8_t *)(&filter->add_fltr);
1490 args.in_args_size = sizeof(*(&filter->add_fltr));
1491 args.out_buffer = vf->aq_resp;
1492 args.out_size = IAVF_AQ_BUF_SZ;
1494 err = iavf_execute_vf_cmd(adapter, &args, 0);
1496 PMD_DRV_LOG(ERR, "fail to check flow director rule");
1500 fdir_ret = (struct virtchnl_fdir_add *)args.out_buffer;
1502 if (fdir_ret->status == VIRTCHNL_FDIR_SUCCESS) {
1504 "Succeed in checking rule request by PF");
1505 } else if (fdir_ret->status == VIRTCHNL_FDIR_FAILURE_RULE_INVALID) {
1507 "Failed to check rule request due to parameters validation"
1508 " or HW doesn't support");
1512 "Failed to check rule request due to other reasons");
1520 iavf_add_del_rss_cfg(struct iavf_adapter *adapter,
1521 struct virtchnl_rss_cfg *rss_cfg, bool add)
1523 struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(adapter);
1524 struct iavf_cmd_info args;
1527 memset(&args, 0, sizeof(args));
1528 args.ops = add ? VIRTCHNL_OP_ADD_RSS_CFG :
1529 VIRTCHNL_OP_DEL_RSS_CFG;
1530 args.in_args = (u8 *)rss_cfg;
1531 args.in_args_size = sizeof(*rss_cfg);
1532 args.out_buffer = vf->aq_resp;
1533 args.out_size = IAVF_AQ_BUF_SZ;
1535 err = iavf_execute_vf_cmd(adapter, &args, 0);
1538 "Failed to execute command of %s",
1539 add ? "OP_ADD_RSS_CFG" :
1540 "OP_DEL_RSS_INPUT_CFG");
1546 iavf_get_hena_caps(struct iavf_adapter *adapter, uint64_t *caps)
1548 struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(adapter);
1549 struct iavf_cmd_info args;
1552 args.ops = VIRTCHNL_OP_GET_RSS_HENA_CAPS;
1553 args.in_args = NULL;
1554 args.in_args_size = 0;
1555 args.out_buffer = vf->aq_resp;
1556 args.out_size = IAVF_AQ_BUF_SZ;
1558 err = iavf_execute_vf_cmd(adapter, &args, 0);
1561 "Failed to execute command of OP_GET_RSS_HENA_CAPS");
1565 *caps = ((struct virtchnl_rss_hena *)args.out_buffer)->hena;
1570 iavf_set_hena(struct iavf_adapter *adapter, uint64_t hena)
1572 struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(adapter);
1573 struct virtchnl_rss_hena vrh;
1574 struct iavf_cmd_info args;
1578 args.ops = VIRTCHNL_OP_SET_RSS_HENA;
1579 args.in_args = (u8 *)&vrh;
1580 args.in_args_size = sizeof(vrh);
1581 args.out_buffer = vf->aq_resp;
1582 args.out_size = IAVF_AQ_BUF_SZ;
1584 err = iavf_execute_vf_cmd(adapter, &args, 0);
1587 "Failed to execute command of OP_SET_RSS_HENA");
1593 iavf_get_qos_cap(struct iavf_adapter *adapter)
1595 struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(adapter);
1596 struct iavf_cmd_info args;
1600 args.ops = VIRTCHNL_OP_GET_QOS_CAPS;
1601 args.in_args = NULL;
1602 args.in_args_size = 0;
1603 args.out_buffer = vf->aq_resp;
1604 args.out_size = IAVF_AQ_BUF_SZ;
1605 err = iavf_execute_vf_cmd(adapter, &args, 0);
1609 "Failed to execute command of OP_GET_VF_RESOURCE");
1613 len = sizeof(struct virtchnl_qos_cap_list) +
1614 IAVF_MAX_TRAFFIC_CLASS * sizeof(struct virtchnl_qos_cap_elem);
1616 rte_memcpy(vf->qos_cap, args.out_buffer,
1617 RTE_MIN(args.out_size, len));
1622 int iavf_set_q_tc_map(struct rte_eth_dev *dev,
1623 struct virtchnl_queue_tc_mapping *q_tc_mapping, uint16_t size)
1625 struct iavf_adapter *adapter =
1626 IAVF_DEV_PRIVATE_TO_ADAPTER(dev->data->dev_private);
1627 struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(dev->data->dev_private);
1628 struct iavf_cmd_info args;
1631 memset(&args, 0, sizeof(args));
1632 args.ops = VIRTCHNL_OP_CONFIG_QUEUE_TC_MAP;
1633 args.in_args = (uint8_t *)q_tc_mapping;
1634 args.in_args_size = size;
1635 args.out_buffer = vf->aq_resp;
1636 args.out_size = IAVF_AQ_BUF_SZ;
1638 err = iavf_execute_vf_cmd(adapter, &args, 0);
1640 PMD_DRV_LOG(ERR, "Failed to execute command of"
1641 " VIRTCHNL_OP_CONFIG_TC_MAP");
1645 int iavf_set_q_bw(struct rte_eth_dev *dev,
1646 struct virtchnl_queues_bw_cfg *q_bw, uint16_t size)
1648 struct iavf_adapter *adapter =
1649 IAVF_DEV_PRIVATE_TO_ADAPTER(dev->data->dev_private);
1650 struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(dev->data->dev_private);
1651 struct iavf_cmd_info args;
1654 memset(&args, 0, sizeof(args));
1655 args.ops = VIRTCHNL_OP_CONFIG_QUEUE_BW;
1656 args.in_args = (uint8_t *)q_bw;
1657 args.in_args_size = size;
1658 args.out_buffer = vf->aq_resp;
1659 args.out_size = IAVF_AQ_BUF_SZ;
1661 err = iavf_execute_vf_cmd(adapter, &args, 0);
1663 PMD_DRV_LOG(ERR, "Failed to execute command of"
1664 " VIRTCHNL_OP_CONFIG_QUEUE_BW");
1669 iavf_add_del_mc_addr_list(struct iavf_adapter *adapter,
1670 struct rte_ether_addr *mc_addrs,
1671 uint32_t mc_addrs_num, bool add)
1673 struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(adapter);
1674 uint8_t cmd_buffer[sizeof(struct virtchnl_ether_addr_list) +
1675 (IAVF_NUM_MACADDR_MAX * sizeof(struct virtchnl_ether_addr))];
1676 struct virtchnl_ether_addr_list *list;
1677 struct iavf_cmd_info args;
1681 if (mc_addrs == NULL || mc_addrs_num == 0)
1684 list = (struct virtchnl_ether_addr_list *)cmd_buffer;
1685 list->vsi_id = vf->vsi_res->vsi_id;
1686 list->num_elements = mc_addrs_num;
1688 for (i = 0; i < mc_addrs_num; i++) {
1689 if (!IAVF_IS_MULTICAST(mc_addrs[i].addr_bytes)) {
1690 PMD_DRV_LOG(ERR, "Invalid mac:" RTE_ETHER_ADDR_PRT_FMT,
1691 RTE_ETHER_ADDR_BYTES(&mc_addrs[i]));
1695 memcpy(list->list[i].addr, mc_addrs[i].addr_bytes,
1696 sizeof(list->list[i].addr));
1697 list->list[i].type = VIRTCHNL_ETHER_ADDR_EXTRA;
1700 args.ops = add ? VIRTCHNL_OP_ADD_ETH_ADDR : VIRTCHNL_OP_DEL_ETH_ADDR;
1701 args.in_args = cmd_buffer;
1702 args.in_args_size = sizeof(struct virtchnl_ether_addr_list) +
1703 i * sizeof(struct virtchnl_ether_addr);
1704 args.out_buffer = vf->aq_resp;
1705 args.out_size = IAVF_AQ_BUF_SZ;
1706 err = iavf_execute_vf_cmd(adapter, &args, 0);
1709 PMD_DRV_LOG(ERR, "fail to execute command %s",
1710 add ? "OP_ADD_ETH_ADDR" : "OP_DEL_ETH_ADDR");
1718 iavf_request_queues(struct rte_eth_dev *dev, uint16_t num)
1720 struct iavf_adapter *adapter =
1721 IAVF_DEV_PRIVATE_TO_ADAPTER(dev->data->dev_private);
1722 struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(adapter);
1723 struct rte_pci_device *pci_dev = RTE_ETH_DEV_TO_PCI(dev);
1724 struct virtchnl_vf_res_request vfres;
1725 struct iavf_cmd_info args;
1726 uint16_t num_queue_pairs;
1729 if (!(vf->vf_res->vf_cap_flags &
1730 VIRTCHNL_VF_OFFLOAD_REQ_QUEUES)) {
1731 PMD_DRV_LOG(ERR, "request queues not supported");
1736 PMD_DRV_LOG(ERR, "queue number cannot be zero");
1739 vfres.num_queue_pairs = num;
1741 args.ops = VIRTCHNL_OP_REQUEST_QUEUES;
1742 args.in_args = (u8 *)&vfres;
1743 args.in_args_size = sizeof(vfres);
1744 args.out_buffer = vf->aq_resp;
1745 args.out_size = IAVF_AQ_BUF_SZ;
1747 if (vf->vf_res->vf_cap_flags & VIRTCHNL_VF_OFFLOAD_WB_ON_ITR) {
1748 /* disable interrupt to avoid the admin queue message to be read
1749 * before iavf_read_msg_from_pf.
1751 rte_intr_disable(pci_dev->intr_handle);
1752 err = iavf_execute_vf_cmd(adapter, &args, 0);
1753 rte_intr_enable(pci_dev->intr_handle);
1755 rte_eal_alarm_cancel(iavf_dev_alarm_handler, dev);
1756 err = iavf_execute_vf_cmd(adapter, &args, 0);
1757 rte_eal_alarm_set(IAVF_ALARM_INTERVAL,
1758 iavf_dev_alarm_handler, dev);
1762 PMD_DRV_LOG(ERR, "fail to execute command OP_REQUEST_QUEUES");
1766 /* request queues succeeded, vf is resetting */
1768 PMD_DRV_LOG(INFO, "vf is resetting");
1772 /* request additional queues failed, return available number */
1774 ((struct virtchnl_vf_res_request *)args.out_buffer)->num_queue_pairs;
1775 PMD_DRV_LOG(ERR, "request queues failed, only %u queues "
1776 "available", num_queue_pairs);
1782 iavf_get_max_rss_queue_region(struct iavf_adapter *adapter)
1784 struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(adapter);
1785 struct iavf_cmd_info args;
1786 uint16_t qregion_width;
1789 args.ops = VIRTCHNL_OP_GET_MAX_RSS_QREGION;
1790 args.in_args = NULL;
1791 args.in_args_size = 0;
1792 args.out_buffer = vf->aq_resp;
1793 args.out_size = IAVF_AQ_BUF_SZ;
1795 err = iavf_execute_vf_cmd(adapter, &args, 0);
1797 PMD_DRV_LOG(ERR, "Failed to execute command of VIRTCHNL_OP_GET_MAX_RSS_QREGION");
1802 ((struct virtchnl_max_rss_qregion *)args.out_buffer)->qregion_width;
1804 vf->max_rss_qregion = (uint16_t)(1 << qregion_width);
1812 iavf_ipsec_crypto_request(struct iavf_adapter *adapter,
1813 uint8_t *msg, size_t msg_len,
1814 uint8_t *resp_msg, size_t resp_msg_len)
1816 struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(adapter);
1817 struct iavf_cmd_info args;
1820 args.ops = VIRTCHNL_OP_INLINE_IPSEC_CRYPTO;
1822 args.in_args_size = msg_len;
1823 args.out_buffer = vf->aq_resp;
1824 args.out_size = IAVF_AQ_BUF_SZ;
1826 err = iavf_execute_vf_cmd(adapter, &args, 1);
1828 PMD_DRV_LOG(ERR, "fail to execute command %s",
1829 "OP_INLINE_IPSEC_CRYPTO");
1833 memcpy(resp_msg, args.out_buffer, resp_msg_len);
1839 iavf_set_vf_quanta_size(struct iavf_adapter *adapter, u16 start_queue_id, u16 num_queues)
1841 struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(adapter);
1842 struct iavf_cmd_info args;
1843 struct virtchnl_quanta_cfg q_quanta;
1846 if (adapter->devargs.quanta_size == 0)
1849 q_quanta.quanta_size = adapter->devargs.quanta_size;
1850 q_quanta.queue_select.type = VIRTCHNL_QUEUE_TYPE_TX;
1851 q_quanta.queue_select.start_queue_id = start_queue_id;
1852 q_quanta.queue_select.num_queues = num_queues;
1854 args.ops = VIRTCHNL_OP_CONFIG_QUANTA;
1855 args.in_args = (uint8_t *)&q_quanta;
1856 args.in_args_size = sizeof(q_quanta);
1857 args.out_buffer = vf->aq_resp;
1858 args.out_size = IAVF_AQ_BUF_SZ;
1860 err = iavf_execute_vf_cmd(adapter, &args, 0);
1862 PMD_DRV_LOG(ERR, "Failed to execute command VIRTCHNL_OP_CONFIG_QUANTA");
1870 iavf_get_ptp_cap(struct iavf_adapter *adapter)
1872 struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(adapter);
1873 struct virtchnl_ptp_caps ptp_caps;
1874 struct iavf_cmd_info args;
1877 ptp_caps.caps = VIRTCHNL_1588_PTP_CAP_RX_TSTAMP |
1878 VIRTCHNL_1588_PTP_CAP_READ_PHC;
1880 args.ops = VIRTCHNL_OP_1588_PTP_GET_CAPS;
1881 args.in_args = (uint8_t *)&ptp_caps;
1882 args.in_args_size = sizeof(ptp_caps);
1883 args.out_buffer = vf->aq_resp;
1884 args.out_size = IAVF_AQ_BUF_SZ;
1886 err = iavf_execute_vf_cmd(adapter, &args, 0);
1889 "Failed to execute command of OP_1588_PTP_GET_CAPS");
1893 vf->ptp_caps = ((struct virtchnl_ptp_caps *)args.out_buffer)->caps;
1899 iavf_get_phc_time(struct iavf_adapter *adapter)
1901 struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(adapter);
1902 struct virtchnl_phc_time phc_time;
1903 struct iavf_cmd_info args;
1906 args.ops = VIRTCHNL_OP_1588_PTP_GET_TIME;
1907 args.in_args = (uint8_t *)&phc_time;
1908 args.in_args_size = sizeof(phc_time);
1909 args.out_buffer = vf->aq_resp;
1910 args.out_size = IAVF_AQ_BUF_SZ;
1912 err = iavf_execute_vf_cmd(adapter, &args, 0);
1915 "Failed to execute command of VIRTCHNL_OP_1588_PTP_GET_TIME");
1919 adapter->phc_time = ((struct virtchnl_phc_time *)args.out_buffer)->time;