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 Adapative 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;
507 args.in_args = (uint8_t *)∩︀
508 args.in_args_size = sizeof(caps);
510 err = iavf_execute_vf_cmd(adapter, &args, 0);
514 "Failed to execute command of OP_GET_VF_RESOURCE");
518 len = sizeof(struct virtchnl_vf_resource) +
519 IAVF_MAX_VF_VSI * sizeof(struct virtchnl_vsi_resource);
521 rte_memcpy(vf->vf_res, args.out_buffer,
522 RTE_MIN(args.out_size, len));
523 /* parse VF config message back from PF*/
524 iavf_vf_parse_hw_config(hw, vf->vf_res);
525 for (i = 0; i < vf->vf_res->num_vsis; i++) {
526 if (vf->vf_res->vsi_res[i].vsi_type == VIRTCHNL_VSI_SRIOV)
527 vf->vsi_res = &vf->vf_res->vsi_res[i];
531 PMD_INIT_LOG(ERR, "no LAN VSI found");
535 vf->vsi.vsi_id = vf->vsi_res->vsi_id;
536 vf->vsi.nb_qps = vf->vsi_res->num_queue_pairs;
537 vf->vsi.adapter = adapter;
543 iavf_get_supported_rxdid(struct iavf_adapter *adapter)
545 struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(adapter);
546 struct iavf_cmd_info args;
549 args.ops = VIRTCHNL_OP_GET_SUPPORTED_RXDIDS;
551 args.in_args_size = 0;
552 args.out_buffer = vf->aq_resp;
553 args.out_size = IAVF_AQ_BUF_SZ;
555 ret = iavf_execute_vf_cmd(adapter, &args, 0);
558 "Failed to execute command of OP_GET_SUPPORTED_RXDIDS");
562 vf->supported_rxdid =
563 ((struct virtchnl_supported_rxdids *)args.out_buffer)->supported_rxdids;
569 iavf_config_vlan_strip_v2(struct iavf_adapter *adapter, bool enable)
571 struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(adapter);
572 struct virtchnl_vlan_supported_caps *stripping_caps;
573 struct virtchnl_vlan_setting vlan_strip;
574 struct iavf_cmd_info args;
578 stripping_caps = &vf->vlan_v2_caps.offloads.stripping_support;
580 if ((stripping_caps->outer & VIRTCHNL_VLAN_ETHERTYPE_8100) &&
581 (stripping_caps->outer & VIRTCHNL_VLAN_TOGGLE))
582 ethertype = &vlan_strip.outer_ethertype_setting;
583 else if ((stripping_caps->inner & VIRTCHNL_VLAN_ETHERTYPE_8100) &&
584 (stripping_caps->inner & VIRTCHNL_VLAN_TOGGLE))
585 ethertype = &vlan_strip.inner_ethertype_setting;
589 memset(&vlan_strip, 0, sizeof(vlan_strip));
590 vlan_strip.vport_id = vf->vsi_res->vsi_id;
591 *ethertype = VIRTCHNL_VLAN_ETHERTYPE_8100;
593 args.ops = enable ? VIRTCHNL_OP_ENABLE_VLAN_STRIPPING_V2 :
594 VIRTCHNL_OP_DISABLE_VLAN_STRIPPING_V2;
595 args.in_args = (uint8_t *)&vlan_strip;
596 args.in_args_size = sizeof(vlan_strip);
597 args.out_buffer = vf->aq_resp;
598 args.out_size = IAVF_AQ_BUF_SZ;
599 ret = iavf_execute_vf_cmd(adapter, &args, 0);
601 PMD_DRV_LOG(ERR, "fail to execute command %s",
602 enable ? "VIRTCHNL_OP_ENABLE_VLAN_STRIPPING_V2" :
603 "VIRTCHNL_OP_DISABLE_VLAN_STRIPPING_V2");
609 iavf_config_vlan_insert_v2(struct iavf_adapter *adapter, bool enable)
611 struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(adapter);
612 struct virtchnl_vlan_supported_caps *insertion_caps;
613 struct virtchnl_vlan_setting vlan_insert;
614 struct iavf_cmd_info args;
618 insertion_caps = &vf->vlan_v2_caps.offloads.insertion_support;
620 if ((insertion_caps->outer & VIRTCHNL_VLAN_ETHERTYPE_8100) &&
621 (insertion_caps->outer & VIRTCHNL_VLAN_TOGGLE))
622 ethertype = &vlan_insert.outer_ethertype_setting;
623 else if ((insertion_caps->inner & VIRTCHNL_VLAN_ETHERTYPE_8100) &&
624 (insertion_caps->inner & VIRTCHNL_VLAN_TOGGLE))
625 ethertype = &vlan_insert.inner_ethertype_setting;
629 memset(&vlan_insert, 0, sizeof(vlan_insert));
630 vlan_insert.vport_id = vf->vsi_res->vsi_id;
631 *ethertype = VIRTCHNL_VLAN_ETHERTYPE_8100;
633 args.ops = enable ? VIRTCHNL_OP_ENABLE_VLAN_INSERTION_V2 :
634 VIRTCHNL_OP_DISABLE_VLAN_INSERTION_V2;
635 args.in_args = (uint8_t *)&vlan_insert;
636 args.in_args_size = sizeof(vlan_insert);
637 args.out_buffer = vf->aq_resp;
638 args.out_size = IAVF_AQ_BUF_SZ;
639 ret = iavf_execute_vf_cmd(adapter, &args, 0);
641 PMD_DRV_LOG(ERR, "fail to execute command %s",
642 enable ? "VIRTCHNL_OP_ENABLE_VLAN_INSERTION_V2" :
643 "VIRTCHNL_OP_DISABLE_VLAN_INSERTION_V2");
649 iavf_add_del_vlan_v2(struct iavf_adapter *adapter, uint16_t vlanid, bool add)
651 struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(adapter);
652 struct virtchnl_vlan_supported_caps *supported_caps;
653 struct virtchnl_vlan_filter_list_v2 vlan_filter;
654 struct virtchnl_vlan *vlan_setting;
655 struct iavf_cmd_info args;
656 uint32_t filtering_caps;
659 supported_caps = &vf->vlan_v2_caps.filtering.filtering_support;
660 if (supported_caps->outer) {
661 filtering_caps = supported_caps->outer;
662 vlan_setting = &vlan_filter.filters[0].outer;
664 filtering_caps = supported_caps->inner;
665 vlan_setting = &vlan_filter.filters[0].inner;
668 if (!(filtering_caps & VIRTCHNL_VLAN_ETHERTYPE_8100))
671 memset(&vlan_filter, 0, sizeof(vlan_filter));
672 vlan_filter.vport_id = vf->vsi_res->vsi_id;
673 vlan_filter.num_elements = 1;
674 vlan_setting->tpid = RTE_ETHER_TYPE_VLAN;
675 vlan_setting->tci = vlanid;
677 args.ops = add ? VIRTCHNL_OP_ADD_VLAN_V2 : VIRTCHNL_OP_DEL_VLAN_V2;
678 args.in_args = (uint8_t *)&vlan_filter;
679 args.in_args_size = sizeof(vlan_filter);
680 args.out_buffer = vf->aq_resp;
681 args.out_size = IAVF_AQ_BUF_SZ;
682 err = iavf_execute_vf_cmd(adapter, &args, 0);
684 PMD_DRV_LOG(ERR, "fail to execute command %s",
685 add ? "OP_ADD_VLAN_V2" : "OP_DEL_VLAN_V2");
691 iavf_get_vlan_offload_caps_v2(struct iavf_adapter *adapter)
693 struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(adapter);
694 struct iavf_cmd_info args;
697 args.ops = VIRTCHNL_OP_GET_OFFLOAD_VLAN_V2_CAPS;
699 args.in_args_size = 0;
700 args.out_buffer = vf->aq_resp;
701 args.out_size = IAVF_AQ_BUF_SZ;
703 ret = iavf_execute_vf_cmd(adapter, &args, 0);
706 "Failed to execute command of VIRTCHNL_OP_GET_OFFLOAD_VLAN_V2_CAPS");
710 rte_memcpy(&vf->vlan_v2_caps, vf->aq_resp, sizeof(vf->vlan_v2_caps));
716 iavf_enable_queues(struct iavf_adapter *adapter)
718 struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(adapter);
719 struct virtchnl_queue_select queue_select;
720 struct iavf_cmd_info args;
723 memset(&queue_select, 0, sizeof(queue_select));
724 queue_select.vsi_id = vf->vsi_res->vsi_id;
726 queue_select.rx_queues = BIT(adapter->dev_data->nb_rx_queues) - 1;
727 queue_select.tx_queues = BIT(adapter->dev_data->nb_tx_queues) - 1;
729 args.ops = VIRTCHNL_OP_ENABLE_QUEUES;
730 args.in_args = (u8 *)&queue_select;
731 args.in_args_size = sizeof(queue_select);
732 args.out_buffer = vf->aq_resp;
733 args.out_size = IAVF_AQ_BUF_SZ;
734 err = iavf_execute_vf_cmd(adapter, &args, 0);
737 "Failed to execute command of OP_ENABLE_QUEUES");
744 iavf_disable_queues(struct iavf_adapter *adapter)
746 struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(adapter);
747 struct virtchnl_queue_select queue_select;
748 struct iavf_cmd_info args;
751 memset(&queue_select, 0, sizeof(queue_select));
752 queue_select.vsi_id = vf->vsi_res->vsi_id;
754 queue_select.rx_queues = BIT(adapter->dev_data->nb_rx_queues) - 1;
755 queue_select.tx_queues = BIT(adapter->dev_data->nb_tx_queues) - 1;
757 args.ops = VIRTCHNL_OP_DISABLE_QUEUES;
758 args.in_args = (u8 *)&queue_select;
759 args.in_args_size = sizeof(queue_select);
760 args.out_buffer = vf->aq_resp;
761 args.out_size = IAVF_AQ_BUF_SZ;
762 err = iavf_execute_vf_cmd(adapter, &args, 0);
765 "Failed to execute command of OP_DISABLE_QUEUES");
772 iavf_switch_queue(struct iavf_adapter *adapter, uint16_t qid,
775 struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(adapter);
776 struct virtchnl_queue_select queue_select;
777 struct iavf_cmd_info args;
780 memset(&queue_select, 0, sizeof(queue_select));
781 queue_select.vsi_id = vf->vsi_res->vsi_id;
783 queue_select.rx_queues |= 1 << qid;
785 queue_select.tx_queues |= 1 << qid;
788 args.ops = VIRTCHNL_OP_ENABLE_QUEUES;
790 args.ops = VIRTCHNL_OP_DISABLE_QUEUES;
791 args.in_args = (u8 *)&queue_select;
792 args.in_args_size = sizeof(queue_select);
793 args.out_buffer = vf->aq_resp;
794 args.out_size = IAVF_AQ_BUF_SZ;
795 err = iavf_execute_vf_cmd(adapter, &args, 0);
797 PMD_DRV_LOG(ERR, "Failed to execute command of %s",
798 on ? "OP_ENABLE_QUEUES" : "OP_DISABLE_QUEUES");
803 iavf_enable_queues_lv(struct iavf_adapter *adapter)
805 struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(adapter);
806 struct virtchnl_del_ena_dis_queues *queue_select;
807 struct virtchnl_queue_chunk *queue_chunk;
808 struct iavf_cmd_info args;
811 len = sizeof(struct virtchnl_del_ena_dis_queues) +
812 sizeof(struct virtchnl_queue_chunk) *
813 (IAVF_RXTX_QUEUE_CHUNKS_NUM - 1);
814 queue_select = rte_zmalloc("queue_select", len, 0);
818 queue_chunk = queue_select->chunks.chunks;
819 queue_select->chunks.num_chunks = IAVF_RXTX_QUEUE_CHUNKS_NUM;
820 queue_select->vport_id = vf->vsi_res->vsi_id;
822 queue_chunk[VIRTCHNL_QUEUE_TYPE_TX].type = VIRTCHNL_QUEUE_TYPE_TX;
823 queue_chunk[VIRTCHNL_QUEUE_TYPE_TX].start_queue_id = 0;
824 queue_chunk[VIRTCHNL_QUEUE_TYPE_TX].num_queues =
825 adapter->dev_data->nb_tx_queues;
827 queue_chunk[VIRTCHNL_QUEUE_TYPE_RX].type = VIRTCHNL_QUEUE_TYPE_RX;
828 queue_chunk[VIRTCHNL_QUEUE_TYPE_RX].start_queue_id = 0;
829 queue_chunk[VIRTCHNL_QUEUE_TYPE_RX].num_queues =
830 adapter->dev_data->nb_rx_queues;
832 args.ops = VIRTCHNL_OP_ENABLE_QUEUES_V2;
833 args.in_args = (u8 *)queue_select;
834 args.in_args_size = len;
835 args.out_buffer = vf->aq_resp;
836 args.out_size = IAVF_AQ_BUF_SZ;
837 err = iavf_execute_vf_cmd(adapter, &args, 0);
840 "Failed to execute command of OP_ENABLE_QUEUES_V2");
842 rte_free(queue_select);
847 iavf_disable_queues_lv(struct iavf_adapter *adapter)
849 struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(adapter);
850 struct virtchnl_del_ena_dis_queues *queue_select;
851 struct virtchnl_queue_chunk *queue_chunk;
852 struct iavf_cmd_info args;
855 len = sizeof(struct virtchnl_del_ena_dis_queues) +
856 sizeof(struct virtchnl_queue_chunk) *
857 (IAVF_RXTX_QUEUE_CHUNKS_NUM - 1);
858 queue_select = rte_zmalloc("queue_select", len, 0);
862 queue_chunk = queue_select->chunks.chunks;
863 queue_select->chunks.num_chunks = IAVF_RXTX_QUEUE_CHUNKS_NUM;
864 queue_select->vport_id = vf->vsi_res->vsi_id;
866 queue_chunk[VIRTCHNL_QUEUE_TYPE_TX].type = VIRTCHNL_QUEUE_TYPE_TX;
867 queue_chunk[VIRTCHNL_QUEUE_TYPE_TX].start_queue_id = 0;
868 queue_chunk[VIRTCHNL_QUEUE_TYPE_TX].num_queues =
869 adapter->dev_data->nb_tx_queues;
871 queue_chunk[VIRTCHNL_QUEUE_TYPE_RX].type = VIRTCHNL_QUEUE_TYPE_RX;
872 queue_chunk[VIRTCHNL_QUEUE_TYPE_RX].start_queue_id = 0;
873 queue_chunk[VIRTCHNL_QUEUE_TYPE_RX].num_queues =
874 adapter->dev_data->nb_rx_queues;
876 args.ops = VIRTCHNL_OP_DISABLE_QUEUES_V2;
877 args.in_args = (u8 *)queue_select;
878 args.in_args_size = len;
879 args.out_buffer = vf->aq_resp;
880 args.out_size = IAVF_AQ_BUF_SZ;
881 err = iavf_execute_vf_cmd(adapter, &args, 0);
884 "Failed to execute command of OP_DISABLE_QUEUES_V2");
886 rte_free(queue_select);
891 iavf_switch_queue_lv(struct iavf_adapter *adapter, uint16_t qid,
894 struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(adapter);
895 struct virtchnl_del_ena_dis_queues *queue_select;
896 struct virtchnl_queue_chunk *queue_chunk;
897 struct iavf_cmd_info args;
900 len = sizeof(struct virtchnl_del_ena_dis_queues);
901 queue_select = rte_zmalloc("queue_select", len, 0);
905 queue_chunk = queue_select->chunks.chunks;
906 queue_select->chunks.num_chunks = 1;
907 queue_select->vport_id = vf->vsi_res->vsi_id;
910 queue_chunk->type = VIRTCHNL_QUEUE_TYPE_RX;
911 queue_chunk->start_queue_id = qid;
912 queue_chunk->num_queues = 1;
914 queue_chunk->type = VIRTCHNL_QUEUE_TYPE_TX;
915 queue_chunk->start_queue_id = qid;
916 queue_chunk->num_queues = 1;
920 args.ops = VIRTCHNL_OP_ENABLE_QUEUES_V2;
922 args.ops = VIRTCHNL_OP_DISABLE_QUEUES_V2;
923 args.in_args = (u8 *)queue_select;
924 args.in_args_size = len;
925 args.out_buffer = vf->aq_resp;
926 args.out_size = IAVF_AQ_BUF_SZ;
927 err = iavf_execute_vf_cmd(adapter, &args, 0);
929 PMD_DRV_LOG(ERR, "Failed to execute command of %s",
930 on ? "OP_ENABLE_QUEUES_V2" : "OP_DISABLE_QUEUES_V2");
932 rte_free(queue_select);
937 iavf_configure_rss_lut(struct iavf_adapter *adapter)
939 struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(adapter);
940 struct virtchnl_rss_lut *rss_lut;
941 struct iavf_cmd_info args;
944 len = sizeof(*rss_lut) + vf->vf_res->rss_lut_size - 1;
945 rss_lut = rte_zmalloc("rss_lut", len, 0);
949 rss_lut->vsi_id = vf->vsi_res->vsi_id;
950 rss_lut->lut_entries = vf->vf_res->rss_lut_size;
951 rte_memcpy(rss_lut->lut, vf->rss_lut, vf->vf_res->rss_lut_size);
953 args.ops = VIRTCHNL_OP_CONFIG_RSS_LUT;
954 args.in_args = (u8 *)rss_lut;
955 args.in_args_size = len;
956 args.out_buffer = vf->aq_resp;
957 args.out_size = IAVF_AQ_BUF_SZ;
959 err = iavf_execute_vf_cmd(adapter, &args, 0);
962 "Failed to execute command of OP_CONFIG_RSS_LUT");
969 iavf_configure_rss_key(struct iavf_adapter *adapter)
971 struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(adapter);
972 struct virtchnl_rss_key *rss_key;
973 struct iavf_cmd_info args;
976 len = sizeof(*rss_key) + vf->vf_res->rss_key_size - 1;
977 rss_key = rte_zmalloc("rss_key", len, 0);
981 rss_key->vsi_id = vf->vsi_res->vsi_id;
982 rss_key->key_len = vf->vf_res->rss_key_size;
983 rte_memcpy(rss_key->key, vf->rss_key, vf->vf_res->rss_key_size);
985 args.ops = VIRTCHNL_OP_CONFIG_RSS_KEY;
986 args.in_args = (u8 *)rss_key;
987 args.in_args_size = len;
988 args.out_buffer = vf->aq_resp;
989 args.out_size = IAVF_AQ_BUF_SZ;
991 err = iavf_execute_vf_cmd(adapter, &args, 0);
994 "Failed to execute command of OP_CONFIG_RSS_KEY");
1001 iavf_configure_queues(struct iavf_adapter *adapter,
1002 uint16_t num_queue_pairs, uint16_t index)
1004 struct iavf_rx_queue **rxq =
1005 (struct iavf_rx_queue **)adapter->dev_data->rx_queues;
1006 struct iavf_tx_queue **txq =
1007 (struct iavf_tx_queue **)adapter->dev_data->tx_queues;
1008 struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(adapter);
1009 struct virtchnl_vsi_queue_config_info *vc_config;
1010 struct virtchnl_queue_pair_info *vc_qp;
1011 struct iavf_cmd_info args;
1015 size = sizeof(*vc_config) +
1016 sizeof(vc_config->qpair[0]) * num_queue_pairs;
1017 vc_config = rte_zmalloc("cfg_queue", size, 0);
1021 vc_config->vsi_id = vf->vsi_res->vsi_id;
1022 vc_config->num_queue_pairs = num_queue_pairs;
1024 for (i = index, vc_qp = vc_config->qpair;
1025 i < index + num_queue_pairs;
1027 vc_qp->txq.vsi_id = vf->vsi_res->vsi_id;
1028 vc_qp->txq.queue_id = i;
1030 /* Virtchnnl configure tx queues by pairs */
1031 if (i < adapter->dev_data->nb_tx_queues) {
1032 vc_qp->txq.ring_len = txq[i]->nb_tx_desc;
1033 vc_qp->txq.dma_ring_addr = txq[i]->tx_ring_phys_addr;
1036 vc_qp->rxq.vsi_id = vf->vsi_res->vsi_id;
1037 vc_qp->rxq.queue_id = i;
1038 vc_qp->rxq.max_pkt_size = vf->max_pkt_len;
1040 if (i >= adapter->dev_data->nb_rx_queues)
1043 /* Virtchnnl configure rx queues by pairs */
1044 vc_qp->rxq.ring_len = rxq[i]->nb_rx_desc;
1045 vc_qp->rxq.dma_ring_addr = rxq[i]->rx_ring_phys_addr;
1046 vc_qp->rxq.databuffer_size = rxq[i]->rx_buf_len;
1047 vc_qp->rxq.crc_disable = rxq[i]->crc_len != 0 ? 1 : 0;
1048 #ifndef RTE_LIBRTE_IAVF_16BYTE_RX_DESC
1049 if (vf->vf_res->vf_cap_flags &
1050 VIRTCHNL_VF_OFFLOAD_RX_FLEX_DESC &&
1051 vf->supported_rxdid & BIT(rxq[i]->rxdid)) {
1052 vc_qp->rxq.rxdid = rxq[i]->rxdid;
1053 PMD_DRV_LOG(NOTICE, "request RXDID[%d] in Queue[%d]",
1054 vc_qp->rxq.rxdid, i);
1056 PMD_DRV_LOG(NOTICE, "RXDID[%d] is not supported, "
1057 "request default RXDID[%d] in Queue[%d]",
1058 rxq[i]->rxdid, IAVF_RXDID_LEGACY_1, i);
1059 vc_qp->rxq.rxdid = IAVF_RXDID_LEGACY_1;
1062 if (vf->vf_res->vf_cap_flags &
1063 VIRTCHNL_VF_OFFLOAD_RX_FLEX_DESC &&
1064 vf->supported_rxdid & BIT(IAVF_RXDID_LEGACY_0)) {
1065 vc_qp->rxq.rxdid = IAVF_RXDID_LEGACY_0;
1066 PMD_DRV_LOG(NOTICE, "request RXDID[%d] in Queue[%d]",
1067 vc_qp->rxq.rxdid, i);
1069 PMD_DRV_LOG(ERR, "RXDID[%d] is not supported",
1070 IAVF_RXDID_LEGACY_0);
1076 memset(&args, 0, sizeof(args));
1077 args.ops = VIRTCHNL_OP_CONFIG_VSI_QUEUES;
1078 args.in_args = (uint8_t *)vc_config;
1079 args.in_args_size = size;
1080 args.out_buffer = vf->aq_resp;
1081 args.out_size = IAVF_AQ_BUF_SZ;
1083 err = iavf_execute_vf_cmd(adapter, &args, 0);
1085 PMD_DRV_LOG(ERR, "Failed to execute command of"
1086 " VIRTCHNL_OP_CONFIG_VSI_QUEUES");
1088 rte_free(vc_config);
1093 iavf_config_irq_map(struct iavf_adapter *adapter)
1095 struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(adapter);
1096 struct virtchnl_irq_map_info *map_info;
1097 struct virtchnl_vector_map *vecmap;
1098 struct iavf_cmd_info args;
1101 len = sizeof(struct virtchnl_irq_map_info) +
1102 sizeof(struct virtchnl_vector_map) * vf->nb_msix;
1104 map_info = rte_zmalloc("map_info", len, 0);
1108 map_info->num_vectors = vf->nb_msix;
1109 for (i = 0; i < adapter->dev_data->nb_rx_queues; i++) {
1111 &map_info->vecmap[vf->qv_map[i].vector_id - vf->msix_base];
1112 vecmap->vsi_id = vf->vsi_res->vsi_id;
1113 vecmap->rxitr_idx = IAVF_ITR_INDEX_DEFAULT;
1114 vecmap->vector_id = vf->qv_map[i].vector_id;
1115 vecmap->txq_map = 0;
1116 vecmap->rxq_map |= 1 << vf->qv_map[i].queue_id;
1119 args.ops = VIRTCHNL_OP_CONFIG_IRQ_MAP;
1120 args.in_args = (u8 *)map_info;
1121 args.in_args_size = len;
1122 args.out_buffer = vf->aq_resp;
1123 args.out_size = IAVF_AQ_BUF_SZ;
1124 err = iavf_execute_vf_cmd(adapter, &args, 0);
1126 PMD_DRV_LOG(ERR, "fail to execute command OP_CONFIG_IRQ_MAP");
1133 iavf_config_irq_map_lv(struct iavf_adapter *adapter, uint16_t num,
1136 struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(adapter);
1137 struct virtchnl_queue_vector_maps *map_info;
1138 struct virtchnl_queue_vector *qv_maps;
1139 struct iavf_cmd_info args;
1143 len = sizeof(struct virtchnl_queue_vector_maps) +
1144 sizeof(struct virtchnl_queue_vector) * (num - 1);
1146 map_info = rte_zmalloc("map_info", len, 0);
1150 map_info->vport_id = vf->vsi_res->vsi_id;
1151 map_info->num_qv_maps = num;
1152 for (i = index; i < index + map_info->num_qv_maps; i++) {
1153 qv_maps = &map_info->qv_maps[count++];
1154 qv_maps->itr_idx = VIRTCHNL_ITR_IDX_0;
1155 qv_maps->queue_type = VIRTCHNL_QUEUE_TYPE_RX;
1156 qv_maps->queue_id = vf->qv_map[i].queue_id;
1157 qv_maps->vector_id = vf->qv_map[i].vector_id;
1160 args.ops = VIRTCHNL_OP_MAP_QUEUE_VECTOR;
1161 args.in_args = (u8 *)map_info;
1162 args.in_args_size = len;
1163 args.out_buffer = vf->aq_resp;
1164 args.out_size = IAVF_AQ_BUF_SZ;
1165 err = iavf_execute_vf_cmd(adapter, &args, 0);
1167 PMD_DRV_LOG(ERR, "fail to execute command OP_MAP_QUEUE_VECTOR");
1174 iavf_add_del_all_mac_addr(struct iavf_adapter *adapter, bool add)
1176 struct virtchnl_ether_addr_list *list;
1177 struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(adapter);
1178 struct rte_ether_addr *addr;
1179 struct iavf_cmd_info args;
1186 len = sizeof(struct virtchnl_ether_addr_list);
1187 for (i = begin; i < IAVF_NUM_MACADDR_MAX; i++, next_begin++) {
1188 addr = &adapter->dev_data->mac_addrs[i];
1189 if (rte_is_zero_ether_addr(addr))
1191 len += sizeof(struct virtchnl_ether_addr);
1192 if (len >= IAVF_AQ_BUF_SZ) {
1198 list = rte_zmalloc("iavf_del_mac_buffer", len, 0);
1200 PMD_DRV_LOG(ERR, "fail to allocate memory");
1204 for (i = begin; i < next_begin; i++) {
1205 addr = &adapter->dev_data->mac_addrs[i];
1206 if (rte_is_zero_ether_addr(addr))
1208 rte_memcpy(list->list[j].addr, addr->addr_bytes,
1209 sizeof(addr->addr_bytes));
1210 list->list[j].type = (j == 0 ?
1211 VIRTCHNL_ETHER_ADDR_PRIMARY :
1212 VIRTCHNL_ETHER_ADDR_EXTRA);
1213 PMD_DRV_LOG(DEBUG, "add/rm mac:" RTE_ETHER_ADDR_PRT_FMT,
1214 RTE_ETHER_ADDR_BYTES(addr));
1217 list->vsi_id = vf->vsi_res->vsi_id;
1218 list->num_elements = j;
1219 args.ops = add ? VIRTCHNL_OP_ADD_ETH_ADDR :
1220 VIRTCHNL_OP_DEL_ETH_ADDR;
1221 args.in_args = (uint8_t *)list;
1222 args.in_args_size = len;
1223 args.out_buffer = vf->aq_resp;
1224 args.out_size = IAVF_AQ_BUF_SZ;
1225 err = iavf_execute_vf_cmd(adapter, &args, 0);
1227 PMD_DRV_LOG(ERR, "fail to execute command %s",
1228 add ? "OP_ADD_ETHER_ADDRESS" :
1229 "OP_DEL_ETHER_ADDRESS");
1232 } while (begin < IAVF_NUM_MACADDR_MAX);
1236 iavf_query_stats(struct iavf_adapter *adapter,
1237 struct virtchnl_eth_stats **pstats)
1239 struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(adapter);
1240 struct virtchnl_queue_select q_stats;
1241 struct iavf_cmd_info args;
1244 memset(&q_stats, 0, sizeof(q_stats));
1245 q_stats.vsi_id = vf->vsi_res->vsi_id;
1246 args.ops = VIRTCHNL_OP_GET_STATS;
1247 args.in_args = (uint8_t *)&q_stats;
1248 args.in_args_size = sizeof(q_stats);
1249 args.out_buffer = vf->aq_resp;
1250 args.out_size = IAVF_AQ_BUF_SZ;
1252 err = iavf_execute_vf_cmd(adapter, &args, 0);
1254 PMD_DRV_LOG(ERR, "fail to execute command OP_GET_STATS");
1258 *pstats = (struct virtchnl_eth_stats *)args.out_buffer;
1263 iavf_config_promisc(struct iavf_adapter *adapter,
1264 bool enable_unicast,
1265 bool enable_multicast)
1267 struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(adapter);
1268 struct virtchnl_promisc_info promisc;
1269 struct iavf_cmd_info args;
1273 promisc.vsi_id = vf->vsi_res->vsi_id;
1276 promisc.flags |= FLAG_VF_UNICAST_PROMISC;
1278 if (enable_multicast)
1279 promisc.flags |= FLAG_VF_MULTICAST_PROMISC;
1281 args.ops = VIRTCHNL_OP_CONFIG_PROMISCUOUS_MODE;
1282 args.in_args = (uint8_t *)&promisc;
1283 args.in_args_size = sizeof(promisc);
1284 args.out_buffer = vf->aq_resp;
1285 args.out_size = IAVF_AQ_BUF_SZ;
1287 err = iavf_execute_vf_cmd(adapter, &args, 0);
1291 "fail to execute command CONFIG_PROMISCUOUS_MODE");
1293 if (err == -ENOTSUP)
1299 vf->promisc_unicast_enabled = enable_unicast;
1300 vf->promisc_multicast_enabled = enable_multicast;
1305 iavf_add_del_eth_addr(struct iavf_adapter *adapter, struct rte_ether_addr *addr,
1306 bool add, uint8_t type)
1308 struct virtchnl_ether_addr_list *list;
1309 struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(adapter);
1310 uint8_t cmd_buffer[sizeof(struct virtchnl_ether_addr_list) +
1311 sizeof(struct virtchnl_ether_addr)];
1312 struct iavf_cmd_info args;
1315 list = (struct virtchnl_ether_addr_list *)cmd_buffer;
1316 list->vsi_id = vf->vsi_res->vsi_id;
1317 list->num_elements = 1;
1318 list->list[0].type = type;
1319 rte_memcpy(list->list[0].addr, addr->addr_bytes,
1320 sizeof(addr->addr_bytes));
1322 args.ops = add ? VIRTCHNL_OP_ADD_ETH_ADDR : VIRTCHNL_OP_DEL_ETH_ADDR;
1323 args.in_args = cmd_buffer;
1324 args.in_args_size = sizeof(cmd_buffer);
1325 args.out_buffer = vf->aq_resp;
1326 args.out_size = IAVF_AQ_BUF_SZ;
1327 err = iavf_execute_vf_cmd(adapter, &args, 0);
1329 PMD_DRV_LOG(ERR, "fail to execute command %s",
1330 add ? "OP_ADD_ETH_ADDR" : "OP_DEL_ETH_ADDR");
1335 iavf_add_del_vlan(struct iavf_adapter *adapter, uint16_t vlanid, bool add)
1337 struct virtchnl_vlan_filter_list *vlan_list;
1338 struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(adapter);
1339 uint8_t cmd_buffer[sizeof(struct virtchnl_vlan_filter_list) +
1341 struct iavf_cmd_info args;
1344 vlan_list = (struct virtchnl_vlan_filter_list *)cmd_buffer;
1345 vlan_list->vsi_id = vf->vsi_res->vsi_id;
1346 vlan_list->num_elements = 1;
1347 vlan_list->vlan_id[0] = vlanid;
1349 args.ops = add ? VIRTCHNL_OP_ADD_VLAN : VIRTCHNL_OP_DEL_VLAN;
1350 args.in_args = cmd_buffer;
1351 args.in_args_size = sizeof(cmd_buffer);
1352 args.out_buffer = vf->aq_resp;
1353 args.out_size = IAVF_AQ_BUF_SZ;
1354 err = iavf_execute_vf_cmd(adapter, &args, 0);
1356 PMD_DRV_LOG(ERR, "fail to execute command %s",
1357 add ? "OP_ADD_VLAN" : "OP_DEL_VLAN");
1363 iavf_fdir_add(struct iavf_adapter *adapter,
1364 struct iavf_fdir_conf *filter)
1366 struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(adapter);
1367 struct virtchnl_fdir_add *fdir_ret;
1369 struct iavf_cmd_info args;
1372 filter->add_fltr.vsi_id = vf->vsi_res->vsi_id;
1373 filter->add_fltr.validate_only = 0;
1375 args.ops = VIRTCHNL_OP_ADD_FDIR_FILTER;
1376 args.in_args = (uint8_t *)(&filter->add_fltr);
1377 args.in_args_size = sizeof(*(&filter->add_fltr));
1378 args.out_buffer = vf->aq_resp;
1379 args.out_size = IAVF_AQ_BUF_SZ;
1381 err = iavf_execute_vf_cmd(adapter, &args, 0);
1383 PMD_DRV_LOG(ERR, "fail to execute command OP_ADD_FDIR_FILTER");
1387 fdir_ret = (struct virtchnl_fdir_add *)args.out_buffer;
1388 filter->flow_id = fdir_ret->flow_id;
1390 if (fdir_ret->status == VIRTCHNL_FDIR_SUCCESS) {
1392 "Succeed in adding rule request by PF");
1393 } else if (fdir_ret->status == VIRTCHNL_FDIR_FAILURE_RULE_NORESOURCE) {
1395 "Failed to add rule request due to no hw resource");
1397 } else if (fdir_ret->status == VIRTCHNL_FDIR_FAILURE_RULE_EXIST) {
1399 "Failed to add rule request due to the rule is already existed");
1401 } else if (fdir_ret->status == VIRTCHNL_FDIR_FAILURE_RULE_CONFLICT) {
1403 "Failed to add rule request due to the rule is conflict with existing rule");
1405 } else if (fdir_ret->status == VIRTCHNL_FDIR_FAILURE_RULE_INVALID) {
1407 "Failed to add rule request due to the hw doesn't support");
1409 } else if (fdir_ret->status == VIRTCHNL_FDIR_FAILURE_RULE_TIMEOUT) {
1411 "Failed to add rule request due to time out for programming");
1415 "Failed to add rule request due to other reasons");
1423 iavf_fdir_del(struct iavf_adapter *adapter,
1424 struct iavf_fdir_conf *filter)
1426 struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(adapter);
1427 struct virtchnl_fdir_del *fdir_ret;
1429 struct iavf_cmd_info args;
1432 filter->del_fltr.vsi_id = vf->vsi_res->vsi_id;
1433 filter->del_fltr.flow_id = filter->flow_id;
1435 args.ops = VIRTCHNL_OP_DEL_FDIR_FILTER;
1436 args.in_args = (uint8_t *)(&filter->del_fltr);
1437 args.in_args_size = sizeof(filter->del_fltr);
1438 args.out_buffer = vf->aq_resp;
1439 args.out_size = IAVF_AQ_BUF_SZ;
1441 err = iavf_execute_vf_cmd(adapter, &args, 0);
1443 PMD_DRV_LOG(ERR, "fail to execute command OP_DEL_FDIR_FILTER");
1447 fdir_ret = (struct virtchnl_fdir_del *)args.out_buffer;
1449 if (fdir_ret->status == VIRTCHNL_FDIR_SUCCESS) {
1451 "Succeed in deleting rule request by PF");
1452 } else if (fdir_ret->status == VIRTCHNL_FDIR_FAILURE_RULE_NONEXIST) {
1454 "Failed to delete rule request due to this rule doesn't exist");
1456 } else if (fdir_ret->status == VIRTCHNL_FDIR_FAILURE_RULE_TIMEOUT) {
1458 "Failed to delete rule request due to time out for programming");
1462 "Failed to delete rule request due to other reasons");
1470 iavf_fdir_check(struct iavf_adapter *adapter,
1471 struct iavf_fdir_conf *filter)
1473 struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(adapter);
1474 struct virtchnl_fdir_add *fdir_ret;
1476 struct iavf_cmd_info args;
1479 filter->add_fltr.vsi_id = vf->vsi_res->vsi_id;
1480 filter->add_fltr.validate_only = 1;
1482 args.ops = VIRTCHNL_OP_ADD_FDIR_FILTER;
1483 args.in_args = (uint8_t *)(&filter->add_fltr);
1484 args.in_args_size = sizeof(*(&filter->add_fltr));
1485 args.out_buffer = vf->aq_resp;
1486 args.out_size = IAVF_AQ_BUF_SZ;
1488 err = iavf_execute_vf_cmd(adapter, &args, 0);
1490 PMD_DRV_LOG(ERR, "fail to check flow direcotor rule");
1494 fdir_ret = (struct virtchnl_fdir_add *)args.out_buffer;
1496 if (fdir_ret->status == VIRTCHNL_FDIR_SUCCESS) {
1498 "Succeed in checking rule request by PF");
1499 } else if (fdir_ret->status == VIRTCHNL_FDIR_FAILURE_RULE_INVALID) {
1501 "Failed to check rule request due to parameters validation"
1502 " or HW doesn't support");
1506 "Failed to check rule request due to other reasons");
1514 iavf_add_del_rss_cfg(struct iavf_adapter *adapter,
1515 struct virtchnl_rss_cfg *rss_cfg, bool add)
1517 struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(adapter);
1518 struct iavf_cmd_info args;
1521 memset(&args, 0, sizeof(args));
1522 args.ops = add ? VIRTCHNL_OP_ADD_RSS_CFG :
1523 VIRTCHNL_OP_DEL_RSS_CFG;
1524 args.in_args = (u8 *)rss_cfg;
1525 args.in_args_size = sizeof(*rss_cfg);
1526 args.out_buffer = vf->aq_resp;
1527 args.out_size = IAVF_AQ_BUF_SZ;
1529 err = iavf_execute_vf_cmd(adapter, &args, 0);
1532 "Failed to execute command of %s",
1533 add ? "OP_ADD_RSS_CFG" :
1534 "OP_DEL_RSS_INPUT_CFG");
1540 iavf_get_hena_caps(struct iavf_adapter *adapter, uint64_t *caps)
1542 struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(adapter);
1543 struct iavf_cmd_info args;
1546 args.ops = VIRTCHNL_OP_GET_RSS_HENA_CAPS;
1547 args.in_args = NULL;
1548 args.in_args_size = 0;
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 OP_GET_RSS_HENA_CAPS");
1559 *caps = ((struct virtchnl_rss_hena *)args.out_buffer)->hena;
1564 iavf_set_hena(struct iavf_adapter *adapter, uint64_t hena)
1566 struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(adapter);
1567 struct virtchnl_rss_hena vrh;
1568 struct iavf_cmd_info args;
1572 args.ops = VIRTCHNL_OP_SET_RSS_HENA;
1573 args.in_args = (u8 *)&vrh;
1574 args.in_args_size = sizeof(vrh);
1575 args.out_buffer = vf->aq_resp;
1576 args.out_size = IAVF_AQ_BUF_SZ;
1578 err = iavf_execute_vf_cmd(adapter, &args, 0);
1581 "Failed to execute command of OP_SET_RSS_HENA");
1587 iavf_get_qos_cap(struct iavf_adapter *adapter)
1589 struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(adapter);
1590 struct iavf_cmd_info args;
1594 args.ops = VIRTCHNL_OP_GET_QOS_CAPS;
1595 args.in_args = NULL;
1596 args.in_args_size = 0;
1597 args.out_buffer = vf->aq_resp;
1598 args.out_size = IAVF_AQ_BUF_SZ;
1599 err = iavf_execute_vf_cmd(adapter, &args, 0);
1603 "Failed to execute command of OP_GET_VF_RESOURCE");
1607 len = sizeof(struct virtchnl_qos_cap_list) +
1608 IAVF_MAX_TRAFFIC_CLASS * sizeof(struct virtchnl_qos_cap_elem);
1610 rte_memcpy(vf->qos_cap, args.out_buffer,
1611 RTE_MIN(args.out_size, len));
1616 int iavf_set_q_tc_map(struct rte_eth_dev *dev,
1617 struct virtchnl_queue_tc_mapping *q_tc_mapping, uint16_t size)
1619 struct iavf_adapter *adapter =
1620 IAVF_DEV_PRIVATE_TO_ADAPTER(dev->data->dev_private);
1621 struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(dev->data->dev_private);
1622 struct iavf_cmd_info args;
1625 memset(&args, 0, sizeof(args));
1626 args.ops = VIRTCHNL_OP_CONFIG_QUEUE_TC_MAP;
1627 args.in_args = (uint8_t *)q_tc_mapping;
1628 args.in_args_size = size;
1629 args.out_buffer = vf->aq_resp;
1630 args.out_size = IAVF_AQ_BUF_SZ;
1632 err = iavf_execute_vf_cmd(adapter, &args, 0);
1634 PMD_DRV_LOG(ERR, "Failed to execute command of"
1635 " VIRTCHNL_OP_CONFIG_TC_MAP");
1640 iavf_add_del_mc_addr_list(struct iavf_adapter *adapter,
1641 struct rte_ether_addr *mc_addrs,
1642 uint32_t mc_addrs_num, bool add)
1644 struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(adapter);
1645 uint8_t cmd_buffer[sizeof(struct virtchnl_ether_addr_list) +
1646 (IAVF_NUM_MACADDR_MAX * sizeof(struct virtchnl_ether_addr))];
1647 struct virtchnl_ether_addr_list *list;
1648 struct iavf_cmd_info args;
1652 if (mc_addrs == NULL || mc_addrs_num == 0)
1655 list = (struct virtchnl_ether_addr_list *)cmd_buffer;
1656 list->vsi_id = vf->vsi_res->vsi_id;
1657 list->num_elements = mc_addrs_num;
1659 for (i = 0; i < mc_addrs_num; i++) {
1660 if (!IAVF_IS_MULTICAST(mc_addrs[i].addr_bytes)) {
1661 PMD_DRV_LOG(ERR, "Invalid mac:" RTE_ETHER_ADDR_PRT_FMT,
1662 RTE_ETHER_ADDR_BYTES(&mc_addrs[i]));
1666 memcpy(list->list[i].addr, mc_addrs[i].addr_bytes,
1667 sizeof(list->list[i].addr));
1668 list->list[i].type = VIRTCHNL_ETHER_ADDR_EXTRA;
1671 args.ops = add ? VIRTCHNL_OP_ADD_ETH_ADDR : VIRTCHNL_OP_DEL_ETH_ADDR;
1672 args.in_args = cmd_buffer;
1673 args.in_args_size = sizeof(struct virtchnl_ether_addr_list) +
1674 i * sizeof(struct virtchnl_ether_addr);
1675 args.out_buffer = vf->aq_resp;
1676 args.out_size = IAVF_AQ_BUF_SZ;
1677 err = iavf_execute_vf_cmd(adapter, &args, 0);
1680 PMD_DRV_LOG(ERR, "fail to execute command %s",
1681 add ? "OP_ADD_ETH_ADDR" : "OP_DEL_ETH_ADDR");
1689 iavf_request_queues(struct rte_eth_dev *dev, uint16_t num)
1691 struct iavf_adapter *adapter =
1692 IAVF_DEV_PRIVATE_TO_ADAPTER(dev->data->dev_private);
1693 struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(adapter);
1694 struct rte_pci_device *pci_dev = RTE_ETH_DEV_TO_PCI(dev);
1695 struct virtchnl_vf_res_request vfres;
1696 struct iavf_cmd_info args;
1697 uint16_t num_queue_pairs;
1700 if (!(vf->vf_res->vf_cap_flags &
1701 VIRTCHNL_VF_OFFLOAD_REQ_QUEUES)) {
1702 PMD_DRV_LOG(ERR, "request queues not supported");
1707 PMD_DRV_LOG(ERR, "queue number cannot be zero");
1710 vfres.num_queue_pairs = num;
1712 args.ops = VIRTCHNL_OP_REQUEST_QUEUES;
1713 args.in_args = (u8 *)&vfres;
1714 args.in_args_size = sizeof(vfres);
1715 args.out_buffer = vf->aq_resp;
1716 args.out_size = IAVF_AQ_BUF_SZ;
1718 if (vf->vf_res->vf_cap_flags & VIRTCHNL_VF_OFFLOAD_WB_ON_ITR) {
1719 /* disable interrupt to avoid the admin queue message to be read
1720 * before iavf_read_msg_from_pf.
1722 rte_intr_disable(pci_dev->intr_handle);
1723 err = iavf_execute_vf_cmd(adapter, &args, 0);
1724 rte_intr_enable(pci_dev->intr_handle);
1726 rte_eal_alarm_cancel(iavf_dev_alarm_handler, dev);
1727 err = iavf_execute_vf_cmd(adapter, &args, 0);
1728 rte_eal_alarm_set(IAVF_ALARM_INTERVAL,
1729 iavf_dev_alarm_handler, dev);
1733 PMD_DRV_LOG(ERR, "fail to execute command OP_REQUEST_QUEUES");
1737 /* request queues succeeded, vf is resetting */
1739 PMD_DRV_LOG(INFO, "vf is resetting");
1743 /* request additional queues failed, return available number */
1745 ((struct virtchnl_vf_res_request *)args.out_buffer)->num_queue_pairs;
1746 PMD_DRV_LOG(ERR, "request queues failed, only %u queues "
1747 "available", num_queue_pairs);
1753 iavf_get_max_rss_queue_region(struct iavf_adapter *adapter)
1755 struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(adapter);
1756 struct iavf_cmd_info args;
1757 uint16_t qregion_width;
1760 args.ops = VIRTCHNL_OP_GET_MAX_RSS_QREGION;
1761 args.in_args = NULL;
1762 args.in_args_size = 0;
1763 args.out_buffer = vf->aq_resp;
1764 args.out_size = IAVF_AQ_BUF_SZ;
1766 err = iavf_execute_vf_cmd(adapter, &args, 0);
1768 PMD_DRV_LOG(ERR, "Failed to execute command of VIRTCHNL_OP_GET_MAX_RSS_QREGION");
1773 ((struct virtchnl_max_rss_qregion *)args.out_buffer)->qregion_width;
1775 vf->max_rss_qregion = (uint16_t)(1 << qregion_width);
1783 iavf_ipsec_crypto_request(struct iavf_adapter *adapter,
1784 uint8_t *msg, size_t msg_len,
1785 uint8_t *resp_msg, size_t resp_msg_len)
1787 struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(adapter);
1788 struct iavf_cmd_info args;
1791 args.ops = VIRTCHNL_OP_INLINE_IPSEC_CRYPTO;
1793 args.in_args_size = msg_len;
1794 args.out_buffer = vf->aq_resp;
1795 args.out_size = IAVF_AQ_BUF_SZ;
1797 err = iavf_execute_vf_cmd(adapter, &args, 1);
1799 PMD_DRV_LOG(ERR, "fail to execute command %s",
1800 "OP_INLINE_IPSEC_CRYPTO");
1804 memcpy(resp_msg, args.out_buffer, resp_msg_len);