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_atomic.h>
18 #include <rte_ether.h>
19 #include <ethdev_driver.h>
20 #include <ethdev_pci.h>
24 #include "iavf_rxtx.h"
26 #define MAX_TRY_TIMES 200
27 #define ASQ_DELAY_MS 10
30 iavf_convert_link_speed(enum virtchnl_link_speed virt_link_speed)
34 switch (virt_link_speed) {
35 case VIRTCHNL_LINK_SPEED_100MB:
38 case VIRTCHNL_LINK_SPEED_1GB:
41 case VIRTCHNL_LINK_SPEED_10GB:
44 case VIRTCHNL_LINK_SPEED_40GB:
47 case VIRTCHNL_LINK_SPEED_20GB:
50 case VIRTCHNL_LINK_SPEED_25GB:
53 case VIRTCHNL_LINK_SPEED_2_5GB:
56 case VIRTCHNL_LINK_SPEED_5GB:
67 /* Read data in admin queue to get msg from pf driver */
68 static enum iavf_aq_result
69 iavf_read_msg_from_pf(struct iavf_adapter *adapter, uint16_t buf_len,
72 struct iavf_hw *hw = IAVF_DEV_PRIVATE_TO_HW(adapter);
73 struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(adapter);
74 struct rte_eth_dev *dev = adapter->eth_dev;
75 struct iavf_arq_event_info event;
76 enum iavf_aq_result result = IAVF_MSG_NON;
77 enum virtchnl_ops opcode;
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(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)
148 struct iavf_hw *hw = IAVF_DEV_PRIVATE_TO_HW(adapter);
149 struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(adapter);
150 enum iavf_aq_result result;
151 enum iavf_status ret;
158 if (_atomic_set_cmd(vf, args->ops))
161 ret = iavf_aq_send_msg_to_pf(hw, args->ops, IAVF_SUCCESS,
162 args->in_args, args->in_args_size, NULL);
164 PMD_DRV_LOG(ERR, "fail to send cmd %d", args->ops);
170 case VIRTCHNL_OP_RESET_VF:
171 /*no need to wait for response */
174 case VIRTCHNL_OP_VERSION:
175 case VIRTCHNL_OP_GET_VF_RESOURCES:
176 case VIRTCHNL_OP_GET_SUPPORTED_RXDIDS:
177 case VIRTCHNL_OP_GET_OFFLOAD_VLAN_V2_CAPS:
178 /* for init virtchnl ops, need to poll the response */
180 result = iavf_read_msg_from_pf(adapter, args->out_size,
182 if (result == IAVF_MSG_CMD)
184 rte_delay_ms(ASQ_DELAY_MS);
185 } while (i++ < MAX_TRY_TIMES);
186 if (i >= MAX_TRY_TIMES ||
187 vf->cmd_retval != VIRTCHNL_STATUS_SUCCESS) {
189 PMD_DRV_LOG(ERR, "No response or return failure (%d)"
190 " for cmd %d", vf->cmd_retval, args->ops);
194 case VIRTCHNL_OP_REQUEST_QUEUES:
196 * ignore async reply, only wait for system message,
197 * vf_reset = true if get VIRTCHNL_EVENT_RESET_IMPENDING,
198 * if not, means request queues failed.
201 result = iavf_read_msg_from_pf(adapter, args->out_size,
203 if (result == IAVF_MSG_SYS && vf->vf_reset) {
205 } else if (result == IAVF_MSG_CMD ||
206 result == IAVF_MSG_ERR) {
210 rte_delay_ms(ASQ_DELAY_MS);
211 /* If don't read msg or read sys event, continue */
212 } while (i++ < MAX_TRY_TIMES);
213 if (i >= MAX_TRY_TIMES ||
214 vf->cmd_retval != VIRTCHNL_STATUS_SUCCESS) {
216 PMD_DRV_LOG(ERR, "No response or return failure (%d)"
217 " for cmd %d", vf->cmd_retval, args->ops);
222 /* For other virtchnl ops in running time,
223 * wait for the cmd done flag.
226 if (vf->pend_cmd == VIRTCHNL_OP_UNKNOWN)
228 rte_delay_ms(ASQ_DELAY_MS);
229 /* If don't read msg or read sys event, continue */
230 } while (i++ < MAX_TRY_TIMES);
231 /* If there's no response is received, clear command */
232 if (i >= MAX_TRY_TIMES ||
233 vf->cmd_retval != VIRTCHNL_STATUS_SUCCESS) {
235 PMD_DRV_LOG(ERR, "No response or return failure (%d)"
236 " for cmd %d", vf->cmd_retval, args->ops);
246 iavf_handle_pf_event_msg(struct rte_eth_dev *dev, uint8_t *msg,
249 struct virtchnl_pf_event *pf_msg =
250 (struct virtchnl_pf_event *)msg;
251 struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(dev->data->dev_private);
253 if (msglen < sizeof(struct virtchnl_pf_event)) {
254 PMD_DRV_LOG(DEBUG, "Error event");
257 switch (pf_msg->event) {
258 case VIRTCHNL_EVENT_RESET_IMPENDING:
259 PMD_DRV_LOG(DEBUG, "VIRTCHNL_EVENT_RESET_IMPENDING event");
261 rte_eth_dev_callback_process(dev, RTE_ETH_EVENT_INTR_RESET,
264 case VIRTCHNL_EVENT_LINK_CHANGE:
265 PMD_DRV_LOG(DEBUG, "VIRTCHNL_EVENT_LINK_CHANGE event");
266 vf->link_up = pf_msg->event_data.link_event.link_status;
267 if (vf->vf_res->vf_cap_flags & VIRTCHNL_VF_CAP_ADV_LINK_SPEED) {
269 pf_msg->event_data.link_event_adv.link_speed;
271 enum virtchnl_link_speed speed;
272 speed = pf_msg->event_data.link_event.link_speed;
273 vf->link_speed = iavf_convert_link_speed(speed);
275 iavf_dev_link_update(dev, 0);
276 rte_eth_dev_callback_process(dev, RTE_ETH_EVENT_INTR_LSC, NULL);
278 case VIRTCHNL_EVENT_PF_DRIVER_CLOSE:
279 PMD_DRV_LOG(DEBUG, "VIRTCHNL_EVENT_PF_DRIVER_CLOSE event");
282 PMD_DRV_LOG(ERR, " unknown event received %u", pf_msg->event);
288 iavf_handle_virtchnl_msg(struct rte_eth_dev *dev)
290 struct iavf_hw *hw = IAVF_DEV_PRIVATE_TO_HW(dev->data->dev_private);
291 struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(dev->data->dev_private);
292 struct iavf_arq_event_info info;
293 uint16_t pending, aq_opc;
294 enum virtchnl_ops msg_opc;
295 enum iavf_status msg_ret;
298 info.buf_len = IAVF_AQ_BUF_SZ;
300 PMD_DRV_LOG(ERR, "Buffer for adminq resp should not be NULL");
303 info.msg_buf = vf->aq_resp;
307 ret = iavf_clean_arq_element(hw, &info, &pending);
309 if (ret != IAVF_SUCCESS) {
310 PMD_DRV_LOG(INFO, "Failed to read msg from AdminQ,"
314 aq_opc = rte_le_to_cpu_16(info.desc.opcode);
315 /* For the message sent from pf to vf, opcode is stored in
316 * cookie_high of struct iavf_aq_desc, while return error code
317 * are stored in cookie_low, Which is done by PF driver.
319 msg_opc = (enum virtchnl_ops)rte_le_to_cpu_32(
320 info.desc.cookie_high);
321 msg_ret = (enum iavf_status)rte_le_to_cpu_32(
322 info.desc.cookie_low);
324 case iavf_aqc_opc_send_msg_to_vf:
325 if (msg_opc == VIRTCHNL_OP_EVENT) {
326 iavf_handle_pf_event_msg(dev, info.msg_buf,
329 /* read message and it's expected one */
330 if (msg_opc == vf->pend_cmd)
331 _notify_cmd(vf, msg_ret);
333 PMD_DRV_LOG(ERR, "command mismatch,"
335 vf->pend_cmd, msg_opc);
337 "adminq response is received,"
338 " opcode = %d", msg_opc);
342 PMD_DRV_LOG(DEBUG, "Request %u is not supported yet",
350 iavf_enable_vlan_strip(struct iavf_adapter *adapter)
352 struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(adapter);
353 struct iavf_cmd_info args;
356 memset(&args, 0, sizeof(args));
357 args.ops = VIRTCHNL_OP_ENABLE_VLAN_STRIPPING;
359 args.in_args_size = 0;
360 args.out_buffer = vf->aq_resp;
361 args.out_size = IAVF_AQ_BUF_SZ;
362 ret = iavf_execute_vf_cmd(adapter, &args);
364 PMD_DRV_LOG(ERR, "Failed to execute command of"
365 " OP_ENABLE_VLAN_STRIPPING");
371 iavf_disable_vlan_strip(struct iavf_adapter *adapter)
373 struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(adapter);
374 struct iavf_cmd_info args;
377 memset(&args, 0, sizeof(args));
378 args.ops = VIRTCHNL_OP_DISABLE_VLAN_STRIPPING;
380 args.in_args_size = 0;
381 args.out_buffer = vf->aq_resp;
382 args.out_size = IAVF_AQ_BUF_SZ;
383 ret = iavf_execute_vf_cmd(adapter, &args);
385 PMD_DRV_LOG(ERR, "Failed to execute command of"
386 " OP_DISABLE_VLAN_STRIPPING");
391 #define VIRTCHNL_VERSION_MAJOR_START 1
392 #define VIRTCHNL_VERSION_MINOR_START 1
394 /* Check API version with sync wait until version read from admin queue */
396 iavf_check_api_version(struct iavf_adapter *adapter)
398 struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(adapter);
399 struct virtchnl_version_info version, *pver;
400 struct iavf_cmd_info args;
403 version.major = VIRTCHNL_VERSION_MAJOR;
404 version.minor = VIRTCHNL_VERSION_MINOR;
406 args.ops = VIRTCHNL_OP_VERSION;
407 args.in_args = (uint8_t *)&version;
408 args.in_args_size = sizeof(version);
409 args.out_buffer = vf->aq_resp;
410 args.out_size = IAVF_AQ_BUF_SZ;
412 err = iavf_execute_vf_cmd(adapter, &args);
414 PMD_INIT_LOG(ERR, "Fail to execute command of OP_VERSION");
418 pver = (struct virtchnl_version_info *)args.out_buffer;
419 vf->virtchnl_version = *pver;
421 if (vf->virtchnl_version.major < VIRTCHNL_VERSION_MAJOR_START ||
422 (vf->virtchnl_version.major == VIRTCHNL_VERSION_MAJOR_START &&
423 vf->virtchnl_version.minor < VIRTCHNL_VERSION_MINOR_START)) {
424 PMD_INIT_LOG(ERR, "VIRTCHNL API version should not be lower"
425 " than (%u.%u) to support Adapative VF",
426 VIRTCHNL_VERSION_MAJOR_START,
427 VIRTCHNL_VERSION_MAJOR_START);
429 } else if (vf->virtchnl_version.major > VIRTCHNL_VERSION_MAJOR ||
430 (vf->virtchnl_version.major == VIRTCHNL_VERSION_MAJOR &&
431 vf->virtchnl_version.minor > VIRTCHNL_VERSION_MINOR)) {
432 PMD_INIT_LOG(ERR, "PF/VF API version mismatch:(%u.%u)-(%u.%u)",
433 vf->virtchnl_version.major,
434 vf->virtchnl_version.minor,
435 VIRTCHNL_VERSION_MAJOR,
436 VIRTCHNL_VERSION_MINOR);
440 PMD_DRV_LOG(DEBUG, "Peer is supported PF host");
445 iavf_get_vf_resource(struct iavf_adapter *adapter)
447 struct iavf_hw *hw = IAVF_DEV_PRIVATE_TO_HW(adapter);
448 struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(adapter);
449 struct iavf_cmd_info args;
453 args.ops = VIRTCHNL_OP_GET_VF_RESOURCES;
454 args.out_buffer = vf->aq_resp;
455 args.out_size = IAVF_AQ_BUF_SZ;
457 caps = IAVF_BASIC_OFFLOAD_CAPS | VIRTCHNL_VF_CAP_ADV_LINK_SPEED |
458 VIRTCHNL_VF_OFFLOAD_RX_FLEX_DESC |
459 VIRTCHNL_VF_OFFLOAD_FDIR_PF |
460 VIRTCHNL_VF_OFFLOAD_ADV_RSS_PF |
461 VIRTCHNL_VF_OFFLOAD_REQ_QUEUES |
462 VIRTCHNL_VF_OFFLOAD_CRC |
463 VIRTCHNL_VF_OFFLOAD_VLAN_V2 |
464 VIRTCHNL_VF_LARGE_NUM_QPAIRS;
466 args.in_args = (uint8_t *)∩︀
467 args.in_args_size = sizeof(caps);
469 err = iavf_execute_vf_cmd(adapter, &args);
473 "Failed to execute command of OP_GET_VF_RESOURCE");
477 len = sizeof(struct virtchnl_vf_resource) +
478 IAVF_MAX_VF_VSI * sizeof(struct virtchnl_vsi_resource);
480 rte_memcpy(vf->vf_res, args.out_buffer,
481 RTE_MIN(args.out_size, len));
482 /* parse VF config message back from PF*/
483 iavf_vf_parse_hw_config(hw, vf->vf_res);
484 for (i = 0; i < vf->vf_res->num_vsis; i++) {
485 if (vf->vf_res->vsi_res[i].vsi_type == VIRTCHNL_VSI_SRIOV)
486 vf->vsi_res = &vf->vf_res->vsi_res[i];
490 PMD_INIT_LOG(ERR, "no LAN VSI found");
494 vf->vsi.vsi_id = vf->vsi_res->vsi_id;
495 vf->vsi.nb_qps = vf->vsi_res->num_queue_pairs;
496 vf->vsi.adapter = adapter;
502 iavf_get_supported_rxdid(struct iavf_adapter *adapter)
504 struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(adapter);
505 struct iavf_cmd_info args;
508 args.ops = VIRTCHNL_OP_GET_SUPPORTED_RXDIDS;
510 args.in_args_size = 0;
511 args.out_buffer = vf->aq_resp;
512 args.out_size = IAVF_AQ_BUF_SZ;
514 ret = iavf_execute_vf_cmd(adapter, &args);
517 "Failed to execute command of OP_GET_SUPPORTED_RXDIDS");
521 vf->supported_rxdid =
522 ((struct virtchnl_supported_rxdids *)args.out_buffer)->supported_rxdids;
528 iavf_config_vlan_strip_v2(struct iavf_adapter *adapter, bool enable)
530 struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(adapter);
531 struct virtchnl_vlan_supported_caps *supported_caps;
532 struct virtchnl_vlan_offload vlan_strip;
533 struct iavf_cmd_info args;
534 uint32_t stripping_caps;
535 uint32_t *vlan_setting;
538 supported_caps = &vf->vlan_v2_caps.offloads.stripping_support;
539 if (supported_caps->outer) {
540 stripping_caps = supported_caps->outer;
541 vlan_setting = &vlan_strip.outer_ethertype_setting;
543 stripping_caps = supported_caps->inner;
544 vlan_setting = &vlan_strip.inner_ethertype_setting;
547 if (!(stripping_caps & VIRTCHNL_VLAN_ETHERTYPE_8100))
550 memset(&vlan_strip, 0, sizeof(vlan_strip));
551 vlan_strip.vport_id = vf->vsi_res->vsi_id;
552 *vlan_setting = VIRTCHNL_VLAN_ETHERTYPE_8100;
554 args.ops = enable ? VIRTCHNL_OP_ENABLE_VLAN_STRIPPING_V2 :
555 VIRTCHNL_OP_DISABLE_VLAN_STRIPPING_V2;
556 args.in_args = (uint8_t *)&vlan_strip;
557 args.in_args_size = sizeof(vlan_strip);
558 args.out_buffer = vf->aq_resp;
559 args.out_size = IAVF_AQ_BUF_SZ;
560 ret = iavf_execute_vf_cmd(adapter, &args);
562 PMD_DRV_LOG(ERR, "fail to execute command %s",
563 enable ? "VIRTCHNL_OP_ENABLE_VLAN_STRIPPING_V2" :
564 "VIRTCHNL_OP_DISABLE_VLAN_STRIPPING_V2");
570 iavf_config_vlan_insert_v2(struct iavf_adapter *adapter, bool enable)
572 struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(adapter);
573 struct virtchnl_vlan_supported_caps *supported_caps;
574 struct virtchnl_vlan_offload vlan_insert;
575 struct iavf_cmd_info args;
576 uint32_t insertion_caps;
577 uint32_t *vlan_setting;
580 supported_caps = &vf->vlan_v2_caps.offloads.insertion_support;
581 if (supported_caps->outer) {
582 insertion_caps = supported_caps->outer;
583 vlan_setting = &vlan_insert.outer_ethertype_setting;
585 insertion_caps = supported_caps->inner;
586 vlan_setting = &vlan_insert.inner_ethertype_setting;
589 if (!(insertion_caps & VIRTCHNL_VLAN_ETHERTYPE_8100))
592 memset(&vlan_insert, 0, sizeof(vlan_insert));
593 vlan_insert.vport_id = vf->vsi_res->vsi_id;
594 *vlan_setting = VIRTCHNL_VLAN_ETHERTYPE_8100;
596 args.ops = enable ? VIRTCHNL_OP_ENABLE_VLAN_INSERTION_V2 :
597 VIRTCHNL_OP_DISABLE_VLAN_INSERTION_V2;
598 args.in_args = (uint8_t *)&vlan_insert;
599 args.in_args_size = sizeof(vlan_insert);
600 args.out_buffer = vf->aq_resp;
601 args.out_size = IAVF_AQ_BUF_SZ;
602 ret = iavf_execute_vf_cmd(adapter, &args);
604 PMD_DRV_LOG(ERR, "fail to execute command %s",
605 enable ? "VIRTCHNL_OP_ENABLE_VLAN_INSERTION_V2" :
606 "VIRTCHNL_OP_DISABLE_VLAN_INSERTION_V2");
612 iavf_add_del_vlan_v2(struct iavf_adapter *adapter, uint16_t vlanid, bool add)
614 struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(adapter);
615 struct virtchnl_vlan_supported_caps *supported_caps;
616 struct virtchnl_vlan_filter_list_v2 vlan_filter;
617 struct virtchnl_vlan *vlan_setting;
618 struct iavf_cmd_info args;
619 uint32_t filtering_caps;
622 supported_caps = &vf->vlan_v2_caps.filtering.filtering_support;
623 if (supported_caps->outer) {
624 filtering_caps = supported_caps->outer;
625 vlan_setting = &vlan_filter.filters[0].outer;
627 filtering_caps = supported_caps->inner;
628 vlan_setting = &vlan_filter.filters[0].inner;
631 if (!(filtering_caps & VIRTCHNL_VLAN_ETHERTYPE_8100))
634 memset(&vlan_filter, 0, sizeof(vlan_filter));
635 vlan_filter.vport_id = vf->vsi_res->vsi_id;
636 vlan_filter.num_elements = 1;
637 vlan_setting->tpid = RTE_ETHER_TYPE_VLAN;
638 vlan_setting->tci = vlanid;
640 args.ops = add ? VIRTCHNL_OP_ADD_VLAN_V2 : VIRTCHNL_OP_DEL_VLAN_V2;
641 args.in_args = (uint8_t *)&vlan_filter;
642 args.in_args_size = sizeof(vlan_filter);
643 args.out_buffer = vf->aq_resp;
644 args.out_size = IAVF_AQ_BUF_SZ;
645 err = iavf_execute_vf_cmd(adapter, &args);
647 PMD_DRV_LOG(ERR, "fail to execute command %s",
648 add ? "OP_ADD_VLAN_V2" : "OP_DEL_VLAN_V2");
654 iavf_get_vlan_offload_caps_v2(struct iavf_adapter *adapter)
656 struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(adapter);
657 struct iavf_cmd_info args;
660 args.ops = VIRTCHNL_OP_GET_OFFLOAD_VLAN_V2_CAPS;
662 args.in_args_size = 0;
663 args.out_buffer = vf->aq_resp;
664 args.out_size = IAVF_AQ_BUF_SZ;
666 ret = iavf_execute_vf_cmd(adapter, &args);
669 "Failed to execute command of VIRTCHNL_OP_GET_OFFLOAD_VLAN_V2_CAPS");
673 rte_memcpy(&vf->vlan_v2_caps, vf->aq_resp, sizeof(vf->vlan_v2_caps));
679 iavf_enable_queues(struct iavf_adapter *adapter)
681 struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(adapter);
682 struct virtchnl_queue_select queue_select;
683 struct iavf_cmd_info args;
686 memset(&queue_select, 0, sizeof(queue_select));
687 queue_select.vsi_id = vf->vsi_res->vsi_id;
689 queue_select.rx_queues = BIT(adapter->eth_dev->data->nb_rx_queues) - 1;
690 queue_select.tx_queues = BIT(adapter->eth_dev->data->nb_tx_queues) - 1;
692 args.ops = VIRTCHNL_OP_ENABLE_QUEUES;
693 args.in_args = (u8 *)&queue_select;
694 args.in_args_size = sizeof(queue_select);
695 args.out_buffer = vf->aq_resp;
696 args.out_size = IAVF_AQ_BUF_SZ;
697 err = iavf_execute_vf_cmd(adapter, &args);
700 "Failed to execute command of OP_ENABLE_QUEUES");
707 iavf_disable_queues(struct iavf_adapter *adapter)
709 struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(adapter);
710 struct virtchnl_queue_select queue_select;
711 struct iavf_cmd_info args;
714 memset(&queue_select, 0, sizeof(queue_select));
715 queue_select.vsi_id = vf->vsi_res->vsi_id;
717 queue_select.rx_queues = BIT(adapter->eth_dev->data->nb_rx_queues) - 1;
718 queue_select.tx_queues = BIT(adapter->eth_dev->data->nb_tx_queues) - 1;
720 args.ops = VIRTCHNL_OP_DISABLE_QUEUES;
721 args.in_args = (u8 *)&queue_select;
722 args.in_args_size = sizeof(queue_select);
723 args.out_buffer = vf->aq_resp;
724 args.out_size = IAVF_AQ_BUF_SZ;
725 err = iavf_execute_vf_cmd(adapter, &args);
728 "Failed to execute command of OP_DISABLE_QUEUES");
735 iavf_switch_queue(struct iavf_adapter *adapter, uint16_t qid,
738 struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(adapter);
739 struct virtchnl_queue_select queue_select;
740 struct iavf_cmd_info args;
743 memset(&queue_select, 0, sizeof(queue_select));
744 queue_select.vsi_id = vf->vsi_res->vsi_id;
746 queue_select.rx_queues |= 1 << qid;
748 queue_select.tx_queues |= 1 << qid;
751 args.ops = VIRTCHNL_OP_ENABLE_QUEUES;
753 args.ops = VIRTCHNL_OP_DISABLE_QUEUES;
754 args.in_args = (u8 *)&queue_select;
755 args.in_args_size = sizeof(queue_select);
756 args.out_buffer = vf->aq_resp;
757 args.out_size = IAVF_AQ_BUF_SZ;
758 err = iavf_execute_vf_cmd(adapter, &args);
760 PMD_DRV_LOG(ERR, "Failed to execute command of %s",
761 on ? "OP_ENABLE_QUEUES" : "OP_DISABLE_QUEUES");
766 iavf_enable_queues_lv(struct iavf_adapter *adapter)
768 struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(adapter);
769 struct virtchnl_del_ena_dis_queues *queue_select;
770 struct virtchnl_queue_chunk *queue_chunk;
771 struct iavf_cmd_info args;
774 len = sizeof(struct virtchnl_del_ena_dis_queues) +
775 sizeof(struct virtchnl_queue_chunk) *
776 (IAVF_RXTX_QUEUE_CHUNKS_NUM - 1);
777 queue_select = rte_zmalloc("queue_select", len, 0);
781 queue_chunk = queue_select->chunks.chunks;
782 queue_select->chunks.num_chunks = IAVF_RXTX_QUEUE_CHUNKS_NUM;
783 queue_select->vport_id = vf->vsi_res->vsi_id;
785 queue_chunk[VIRTCHNL_QUEUE_TYPE_TX].type = VIRTCHNL_QUEUE_TYPE_TX;
786 queue_chunk[VIRTCHNL_QUEUE_TYPE_TX].start_queue_id = 0;
787 queue_chunk[VIRTCHNL_QUEUE_TYPE_TX].num_queues =
788 adapter->eth_dev->data->nb_tx_queues;
790 queue_chunk[VIRTCHNL_QUEUE_TYPE_RX].type = VIRTCHNL_QUEUE_TYPE_RX;
791 queue_chunk[VIRTCHNL_QUEUE_TYPE_RX].start_queue_id = 0;
792 queue_chunk[VIRTCHNL_QUEUE_TYPE_RX].num_queues =
793 adapter->eth_dev->data->nb_rx_queues;
795 args.ops = VIRTCHNL_OP_ENABLE_QUEUES_V2;
796 args.in_args = (u8 *)queue_select;
797 args.in_args_size = len;
798 args.out_buffer = vf->aq_resp;
799 args.out_size = IAVF_AQ_BUF_SZ;
800 err = iavf_execute_vf_cmd(adapter, &args);
803 "Failed to execute command of OP_ENABLE_QUEUES_V2");
805 rte_free(queue_select);
810 iavf_disable_queues_lv(struct iavf_adapter *adapter)
812 struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(adapter);
813 struct virtchnl_del_ena_dis_queues *queue_select;
814 struct virtchnl_queue_chunk *queue_chunk;
815 struct iavf_cmd_info args;
818 len = sizeof(struct virtchnl_del_ena_dis_queues) +
819 sizeof(struct virtchnl_queue_chunk) *
820 (IAVF_RXTX_QUEUE_CHUNKS_NUM - 1);
821 queue_select = rte_zmalloc("queue_select", len, 0);
825 queue_chunk = queue_select->chunks.chunks;
826 queue_select->chunks.num_chunks = IAVF_RXTX_QUEUE_CHUNKS_NUM;
827 queue_select->vport_id = vf->vsi_res->vsi_id;
829 queue_chunk[VIRTCHNL_QUEUE_TYPE_TX].type = VIRTCHNL_QUEUE_TYPE_TX;
830 queue_chunk[VIRTCHNL_QUEUE_TYPE_TX].start_queue_id = 0;
831 queue_chunk[VIRTCHNL_QUEUE_TYPE_TX].num_queues =
832 adapter->eth_dev->data->nb_tx_queues;
834 queue_chunk[VIRTCHNL_QUEUE_TYPE_RX].type = VIRTCHNL_QUEUE_TYPE_RX;
835 queue_chunk[VIRTCHNL_QUEUE_TYPE_RX].start_queue_id = 0;
836 queue_chunk[VIRTCHNL_QUEUE_TYPE_RX].num_queues =
837 adapter->eth_dev->data->nb_rx_queues;
839 args.ops = VIRTCHNL_OP_DISABLE_QUEUES_V2;
840 args.in_args = (u8 *)queue_select;
841 args.in_args_size = len;
842 args.out_buffer = vf->aq_resp;
843 args.out_size = IAVF_AQ_BUF_SZ;
844 err = iavf_execute_vf_cmd(adapter, &args);
847 "Failed to execute command of OP_DISABLE_QUEUES_V2");
849 rte_free(queue_select);
854 iavf_switch_queue_lv(struct iavf_adapter *adapter, uint16_t qid,
857 struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(adapter);
858 struct virtchnl_del_ena_dis_queues *queue_select;
859 struct virtchnl_queue_chunk *queue_chunk;
860 struct iavf_cmd_info args;
863 len = sizeof(struct virtchnl_del_ena_dis_queues);
864 queue_select = rte_zmalloc("queue_select", len, 0);
868 queue_chunk = queue_select->chunks.chunks;
869 queue_select->chunks.num_chunks = 1;
870 queue_select->vport_id = vf->vsi_res->vsi_id;
873 queue_chunk->type = VIRTCHNL_QUEUE_TYPE_RX;
874 queue_chunk->start_queue_id = qid;
875 queue_chunk->num_queues = 1;
877 queue_chunk->type = VIRTCHNL_QUEUE_TYPE_TX;
878 queue_chunk->start_queue_id = qid;
879 queue_chunk->num_queues = 1;
883 args.ops = VIRTCHNL_OP_ENABLE_QUEUES_V2;
885 args.ops = VIRTCHNL_OP_DISABLE_QUEUES_V2;
886 args.in_args = (u8 *)queue_select;
887 args.in_args_size = len;
888 args.out_buffer = vf->aq_resp;
889 args.out_size = IAVF_AQ_BUF_SZ;
890 err = iavf_execute_vf_cmd(adapter, &args);
892 PMD_DRV_LOG(ERR, "Failed to execute command of %s",
893 on ? "OP_ENABLE_QUEUES_V2" : "OP_DISABLE_QUEUES_V2");
895 rte_free(queue_select);
900 iavf_configure_rss_lut(struct iavf_adapter *adapter)
902 struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(adapter);
903 struct virtchnl_rss_lut *rss_lut;
904 struct iavf_cmd_info args;
907 len = sizeof(*rss_lut) + vf->vf_res->rss_lut_size - 1;
908 rss_lut = rte_zmalloc("rss_lut", len, 0);
912 rss_lut->vsi_id = vf->vsi_res->vsi_id;
913 rss_lut->lut_entries = vf->vf_res->rss_lut_size;
914 rte_memcpy(rss_lut->lut, vf->rss_lut, vf->vf_res->rss_lut_size);
916 args.ops = VIRTCHNL_OP_CONFIG_RSS_LUT;
917 args.in_args = (u8 *)rss_lut;
918 args.in_args_size = len;
919 args.out_buffer = vf->aq_resp;
920 args.out_size = IAVF_AQ_BUF_SZ;
922 err = iavf_execute_vf_cmd(adapter, &args);
925 "Failed to execute command of OP_CONFIG_RSS_LUT");
932 iavf_configure_rss_key(struct iavf_adapter *adapter)
934 struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(adapter);
935 struct virtchnl_rss_key *rss_key;
936 struct iavf_cmd_info args;
939 len = sizeof(*rss_key) + vf->vf_res->rss_key_size - 1;
940 rss_key = rte_zmalloc("rss_key", len, 0);
944 rss_key->vsi_id = vf->vsi_res->vsi_id;
945 rss_key->key_len = vf->vf_res->rss_key_size;
946 rte_memcpy(rss_key->key, vf->rss_key, vf->vf_res->rss_key_size);
948 args.ops = VIRTCHNL_OP_CONFIG_RSS_KEY;
949 args.in_args = (u8 *)rss_key;
950 args.in_args_size = len;
951 args.out_buffer = vf->aq_resp;
952 args.out_size = IAVF_AQ_BUF_SZ;
954 err = iavf_execute_vf_cmd(adapter, &args);
957 "Failed to execute command of OP_CONFIG_RSS_KEY");
964 iavf_configure_queues(struct iavf_adapter *adapter,
965 uint16_t num_queue_pairs, uint16_t index)
967 struct iavf_rx_queue **rxq =
968 (struct iavf_rx_queue **)adapter->eth_dev->data->rx_queues;
969 struct iavf_tx_queue **txq =
970 (struct iavf_tx_queue **)adapter->eth_dev->data->tx_queues;
971 struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(adapter);
972 struct virtchnl_vsi_queue_config_info *vc_config;
973 struct virtchnl_queue_pair_info *vc_qp;
974 struct iavf_cmd_info args;
978 size = sizeof(*vc_config) +
979 sizeof(vc_config->qpair[0]) * num_queue_pairs;
980 vc_config = rte_zmalloc("cfg_queue", size, 0);
984 vc_config->vsi_id = vf->vsi_res->vsi_id;
985 vc_config->num_queue_pairs = num_queue_pairs;
987 for (i = index, vc_qp = vc_config->qpair;
988 i < index + num_queue_pairs;
990 vc_qp->txq.vsi_id = vf->vsi_res->vsi_id;
991 vc_qp->txq.queue_id = i;
993 /* Virtchnnl configure tx queues by pairs */
994 if (i < adapter->eth_dev->data->nb_tx_queues) {
995 vc_qp->txq.ring_len = txq[i]->nb_tx_desc;
996 vc_qp->txq.dma_ring_addr = txq[i]->tx_ring_phys_addr;
999 vc_qp->rxq.vsi_id = vf->vsi_res->vsi_id;
1000 vc_qp->rxq.queue_id = i;
1001 vc_qp->rxq.max_pkt_size = vf->max_pkt_len;
1003 if (i >= adapter->eth_dev->data->nb_rx_queues)
1006 /* Virtchnnl configure rx queues by pairs */
1007 vc_qp->rxq.ring_len = rxq[i]->nb_rx_desc;
1008 vc_qp->rxq.dma_ring_addr = rxq[i]->rx_ring_phys_addr;
1009 vc_qp->rxq.databuffer_size = rxq[i]->rx_buf_len;
1010 vc_qp->rxq.crc_disable = rxq[i]->crc_len != 0 ? 1 : 0;
1011 #ifndef RTE_LIBRTE_IAVF_16BYTE_RX_DESC
1012 if (vf->vf_res->vf_cap_flags &
1013 VIRTCHNL_VF_OFFLOAD_RX_FLEX_DESC &&
1014 vf->supported_rxdid & BIT(rxq[i]->rxdid)) {
1015 vc_qp->rxq.rxdid = rxq[i]->rxdid;
1016 PMD_DRV_LOG(NOTICE, "request RXDID[%d] in Queue[%d]",
1017 vc_qp->rxq.rxdid, i);
1019 PMD_DRV_LOG(NOTICE, "RXDID[%d] is not supported, "
1020 "request default RXDID[%d] in Queue[%d]",
1021 rxq[i]->rxdid, IAVF_RXDID_LEGACY_1, i);
1022 vc_qp->rxq.rxdid = IAVF_RXDID_LEGACY_1;
1025 if (vf->vf_res->vf_cap_flags &
1026 VIRTCHNL_VF_OFFLOAD_RX_FLEX_DESC &&
1027 vf->supported_rxdid & BIT(IAVF_RXDID_LEGACY_0)) {
1028 vc_qp->rxq.rxdid = IAVF_RXDID_LEGACY_0;
1029 PMD_DRV_LOG(NOTICE, "request RXDID[%d] in Queue[%d]",
1030 vc_qp->rxq.rxdid, i);
1032 PMD_DRV_LOG(ERR, "RXDID[%d] is not supported",
1033 IAVF_RXDID_LEGACY_0);
1039 memset(&args, 0, sizeof(args));
1040 args.ops = VIRTCHNL_OP_CONFIG_VSI_QUEUES;
1041 args.in_args = (uint8_t *)vc_config;
1042 args.in_args_size = size;
1043 args.out_buffer = vf->aq_resp;
1044 args.out_size = IAVF_AQ_BUF_SZ;
1046 err = iavf_execute_vf_cmd(adapter, &args);
1048 PMD_DRV_LOG(ERR, "Failed to execute command of"
1049 " VIRTCHNL_OP_CONFIG_VSI_QUEUES");
1051 rte_free(vc_config);
1056 iavf_config_irq_map(struct iavf_adapter *adapter)
1058 struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(adapter);
1059 struct virtchnl_irq_map_info *map_info;
1060 struct virtchnl_vector_map *vecmap;
1061 struct iavf_cmd_info args;
1064 len = sizeof(struct virtchnl_irq_map_info) +
1065 sizeof(struct virtchnl_vector_map) * vf->nb_msix;
1067 map_info = rte_zmalloc("map_info", len, 0);
1071 map_info->num_vectors = vf->nb_msix;
1072 for (i = 0; i < adapter->eth_dev->data->nb_rx_queues; i++) {
1074 &map_info->vecmap[vf->qv_map[i].vector_id - vf->msix_base];
1075 vecmap->vsi_id = vf->vsi_res->vsi_id;
1076 vecmap->rxitr_idx = IAVF_ITR_INDEX_DEFAULT;
1077 vecmap->vector_id = vf->qv_map[i].vector_id;
1078 vecmap->txq_map = 0;
1079 vecmap->rxq_map |= 1 << vf->qv_map[i].queue_id;
1082 args.ops = VIRTCHNL_OP_CONFIG_IRQ_MAP;
1083 args.in_args = (u8 *)map_info;
1084 args.in_args_size = len;
1085 args.out_buffer = vf->aq_resp;
1086 args.out_size = IAVF_AQ_BUF_SZ;
1087 err = iavf_execute_vf_cmd(adapter, &args);
1089 PMD_DRV_LOG(ERR, "fail to execute command OP_CONFIG_IRQ_MAP");
1096 iavf_config_irq_map_lv(struct iavf_adapter *adapter, uint16_t num,
1099 struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(adapter);
1100 struct virtchnl_queue_vector_maps *map_info;
1101 struct virtchnl_queue_vector *qv_maps;
1102 struct iavf_cmd_info args;
1106 len = sizeof(struct virtchnl_queue_vector_maps) +
1107 sizeof(struct virtchnl_queue_vector) * (num - 1);
1109 map_info = rte_zmalloc("map_info", len, 0);
1113 map_info->vport_id = vf->vsi_res->vsi_id;
1114 map_info->num_qv_maps = num;
1115 for (i = index; i < index + map_info->num_qv_maps; i++) {
1116 qv_maps = &map_info->qv_maps[count++];
1117 qv_maps->itr_idx = VIRTCHNL_ITR_IDX_0;
1118 qv_maps->queue_type = VIRTCHNL_QUEUE_TYPE_RX;
1119 qv_maps->queue_id = vf->qv_map[i].queue_id;
1120 qv_maps->vector_id = vf->qv_map[i].vector_id;
1123 args.ops = VIRTCHNL_OP_MAP_QUEUE_VECTOR;
1124 args.in_args = (u8 *)map_info;
1125 args.in_args_size = len;
1126 args.out_buffer = vf->aq_resp;
1127 args.out_size = IAVF_AQ_BUF_SZ;
1128 err = iavf_execute_vf_cmd(adapter, &args);
1130 PMD_DRV_LOG(ERR, "fail to execute command OP_MAP_QUEUE_VECTOR");
1137 iavf_add_del_all_mac_addr(struct iavf_adapter *adapter, bool add)
1139 struct virtchnl_ether_addr_list *list;
1140 struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(adapter);
1141 struct rte_ether_addr *addr;
1142 struct iavf_cmd_info args;
1149 len = sizeof(struct virtchnl_ether_addr_list);
1150 for (i = begin; i < IAVF_NUM_MACADDR_MAX; i++, next_begin++) {
1151 addr = &adapter->eth_dev->data->mac_addrs[i];
1152 if (rte_is_zero_ether_addr(addr))
1154 len += sizeof(struct virtchnl_ether_addr);
1155 if (len >= IAVF_AQ_BUF_SZ) {
1161 list = rte_zmalloc("iavf_del_mac_buffer", len, 0);
1163 PMD_DRV_LOG(ERR, "fail to allocate memory");
1167 for (i = begin; i < next_begin; i++) {
1168 addr = &adapter->eth_dev->data->mac_addrs[i];
1169 if (rte_is_zero_ether_addr(addr))
1171 rte_memcpy(list->list[j].addr, addr->addr_bytes,
1172 sizeof(addr->addr_bytes));
1173 PMD_DRV_LOG(DEBUG, "add/rm mac:%x:%x:%x:%x:%x:%x",
1174 addr->addr_bytes[0], addr->addr_bytes[1],
1175 addr->addr_bytes[2], addr->addr_bytes[3],
1176 addr->addr_bytes[4], addr->addr_bytes[5]);
1179 list->vsi_id = vf->vsi_res->vsi_id;
1180 list->num_elements = j;
1181 args.ops = add ? VIRTCHNL_OP_ADD_ETH_ADDR :
1182 VIRTCHNL_OP_DEL_ETH_ADDR;
1183 args.in_args = (uint8_t *)list;
1184 args.in_args_size = len;
1185 args.out_buffer = vf->aq_resp;
1186 args.out_size = IAVF_AQ_BUF_SZ;
1187 err = iavf_execute_vf_cmd(adapter, &args);
1189 PMD_DRV_LOG(ERR, "fail to execute command %s",
1190 add ? "OP_ADD_ETHER_ADDRESS" :
1191 "OP_DEL_ETHER_ADDRESS");
1194 } while (begin < IAVF_NUM_MACADDR_MAX);
1198 iavf_query_stats(struct iavf_adapter *adapter,
1199 struct virtchnl_eth_stats **pstats)
1201 struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(adapter);
1202 struct virtchnl_queue_select q_stats;
1203 struct iavf_cmd_info args;
1206 memset(&q_stats, 0, sizeof(q_stats));
1207 q_stats.vsi_id = vf->vsi_res->vsi_id;
1208 args.ops = VIRTCHNL_OP_GET_STATS;
1209 args.in_args = (uint8_t *)&q_stats;
1210 args.in_args_size = sizeof(q_stats);
1211 args.out_buffer = vf->aq_resp;
1212 args.out_size = IAVF_AQ_BUF_SZ;
1214 err = iavf_execute_vf_cmd(adapter, &args);
1216 PMD_DRV_LOG(ERR, "fail to execute command OP_GET_STATS");
1220 *pstats = (struct virtchnl_eth_stats *)args.out_buffer;
1225 iavf_config_promisc(struct iavf_adapter *adapter,
1226 bool enable_unicast,
1227 bool enable_multicast)
1229 struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(adapter);
1230 struct virtchnl_promisc_info promisc;
1231 struct iavf_cmd_info args;
1235 promisc.vsi_id = vf->vsi_res->vsi_id;
1238 promisc.flags |= FLAG_VF_UNICAST_PROMISC;
1240 if (enable_multicast)
1241 promisc.flags |= FLAG_VF_MULTICAST_PROMISC;
1243 args.ops = VIRTCHNL_OP_CONFIG_PROMISCUOUS_MODE;
1244 args.in_args = (uint8_t *)&promisc;
1245 args.in_args_size = sizeof(promisc);
1246 args.out_buffer = vf->aq_resp;
1247 args.out_size = IAVF_AQ_BUF_SZ;
1249 err = iavf_execute_vf_cmd(adapter, &args);
1253 "fail to execute command CONFIG_PROMISCUOUS_MODE");
1255 if (err == IAVF_NOT_SUPPORTED)
1261 vf->promisc_unicast_enabled = enable_unicast;
1262 vf->promisc_multicast_enabled = enable_multicast;
1267 iavf_add_del_eth_addr(struct iavf_adapter *adapter, struct rte_ether_addr *addr,
1270 struct virtchnl_ether_addr_list *list;
1271 struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(adapter);
1272 uint8_t cmd_buffer[sizeof(struct virtchnl_ether_addr_list) +
1273 sizeof(struct virtchnl_ether_addr)];
1274 struct iavf_cmd_info args;
1277 list = (struct virtchnl_ether_addr_list *)cmd_buffer;
1278 list->vsi_id = vf->vsi_res->vsi_id;
1279 list->num_elements = 1;
1280 rte_memcpy(list->list[0].addr, addr->addr_bytes,
1281 sizeof(addr->addr_bytes));
1283 args.ops = add ? VIRTCHNL_OP_ADD_ETH_ADDR : VIRTCHNL_OP_DEL_ETH_ADDR;
1284 args.in_args = cmd_buffer;
1285 args.in_args_size = sizeof(cmd_buffer);
1286 args.out_buffer = vf->aq_resp;
1287 args.out_size = IAVF_AQ_BUF_SZ;
1288 err = iavf_execute_vf_cmd(adapter, &args);
1290 PMD_DRV_LOG(ERR, "fail to execute command %s",
1291 add ? "OP_ADD_ETH_ADDR" : "OP_DEL_ETH_ADDR");
1296 iavf_add_del_vlan(struct iavf_adapter *adapter, uint16_t vlanid, bool add)
1298 struct virtchnl_vlan_filter_list *vlan_list;
1299 struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(adapter);
1300 uint8_t cmd_buffer[sizeof(struct virtchnl_vlan_filter_list) +
1302 struct iavf_cmd_info args;
1305 vlan_list = (struct virtchnl_vlan_filter_list *)cmd_buffer;
1306 vlan_list->vsi_id = vf->vsi_res->vsi_id;
1307 vlan_list->num_elements = 1;
1308 vlan_list->vlan_id[0] = vlanid;
1310 args.ops = add ? VIRTCHNL_OP_ADD_VLAN : VIRTCHNL_OP_DEL_VLAN;
1311 args.in_args = cmd_buffer;
1312 args.in_args_size = sizeof(cmd_buffer);
1313 args.out_buffer = vf->aq_resp;
1314 args.out_size = IAVF_AQ_BUF_SZ;
1315 err = iavf_execute_vf_cmd(adapter, &args);
1317 PMD_DRV_LOG(ERR, "fail to execute command %s",
1318 add ? "OP_ADD_VLAN" : "OP_DEL_VLAN");
1324 iavf_fdir_add(struct iavf_adapter *adapter,
1325 struct iavf_fdir_conf *filter)
1327 struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(adapter);
1328 struct virtchnl_fdir_add *fdir_ret;
1330 struct iavf_cmd_info args;
1333 filter->add_fltr.vsi_id = vf->vsi_res->vsi_id;
1334 filter->add_fltr.validate_only = 0;
1336 args.ops = VIRTCHNL_OP_ADD_FDIR_FILTER;
1337 args.in_args = (uint8_t *)(&filter->add_fltr);
1338 args.in_args_size = sizeof(*(&filter->add_fltr));
1339 args.out_buffer = vf->aq_resp;
1340 args.out_size = IAVF_AQ_BUF_SZ;
1342 err = iavf_execute_vf_cmd(adapter, &args);
1344 PMD_DRV_LOG(ERR, "fail to execute command OP_ADD_FDIR_FILTER");
1348 fdir_ret = (struct virtchnl_fdir_add *)args.out_buffer;
1349 filter->flow_id = fdir_ret->flow_id;
1351 if (fdir_ret->status == VIRTCHNL_FDIR_SUCCESS) {
1353 "Succeed in adding rule request by PF");
1354 } else if (fdir_ret->status == VIRTCHNL_FDIR_FAILURE_RULE_NORESOURCE) {
1356 "Failed to add rule request due to no hw resource");
1358 } else if (fdir_ret->status == VIRTCHNL_FDIR_FAILURE_RULE_EXIST) {
1360 "Failed to add rule request due to the rule is already existed");
1362 } else if (fdir_ret->status == VIRTCHNL_FDIR_FAILURE_RULE_CONFLICT) {
1364 "Failed to add rule request due to the rule is conflict with existing rule");
1366 } else if (fdir_ret->status == VIRTCHNL_FDIR_FAILURE_RULE_INVALID) {
1368 "Failed to add rule request due to the hw doesn't support");
1370 } else if (fdir_ret->status == VIRTCHNL_FDIR_FAILURE_RULE_TIMEOUT) {
1372 "Failed to add rule request due to time out for programming");
1376 "Failed to add rule request due to other reasons");
1384 iavf_fdir_del(struct iavf_adapter *adapter,
1385 struct iavf_fdir_conf *filter)
1387 struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(adapter);
1388 struct virtchnl_fdir_del *fdir_ret;
1390 struct iavf_cmd_info args;
1393 filter->del_fltr.vsi_id = vf->vsi_res->vsi_id;
1394 filter->del_fltr.flow_id = filter->flow_id;
1396 args.ops = VIRTCHNL_OP_DEL_FDIR_FILTER;
1397 args.in_args = (uint8_t *)(&filter->del_fltr);
1398 args.in_args_size = sizeof(filter->del_fltr);
1399 args.out_buffer = vf->aq_resp;
1400 args.out_size = IAVF_AQ_BUF_SZ;
1402 err = iavf_execute_vf_cmd(adapter, &args);
1404 PMD_DRV_LOG(ERR, "fail to execute command OP_DEL_FDIR_FILTER");
1408 fdir_ret = (struct virtchnl_fdir_del *)args.out_buffer;
1410 if (fdir_ret->status == VIRTCHNL_FDIR_SUCCESS) {
1412 "Succeed in deleting rule request by PF");
1413 } else if (fdir_ret->status == VIRTCHNL_FDIR_FAILURE_RULE_NONEXIST) {
1415 "Failed to delete rule request due to this rule doesn't exist");
1417 } else if (fdir_ret->status == VIRTCHNL_FDIR_FAILURE_RULE_TIMEOUT) {
1419 "Failed to delete rule request due to time out for programming");
1423 "Failed to delete rule request due to other reasons");
1431 iavf_fdir_check(struct iavf_adapter *adapter,
1432 struct iavf_fdir_conf *filter)
1434 struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(adapter);
1435 struct virtchnl_fdir_add *fdir_ret;
1437 struct iavf_cmd_info args;
1440 filter->add_fltr.vsi_id = vf->vsi_res->vsi_id;
1441 filter->add_fltr.validate_only = 1;
1443 args.ops = VIRTCHNL_OP_ADD_FDIR_FILTER;
1444 args.in_args = (uint8_t *)(&filter->add_fltr);
1445 args.in_args_size = sizeof(*(&filter->add_fltr));
1446 args.out_buffer = vf->aq_resp;
1447 args.out_size = IAVF_AQ_BUF_SZ;
1449 err = iavf_execute_vf_cmd(adapter, &args);
1451 PMD_DRV_LOG(ERR, "fail to check flow direcotor rule");
1455 fdir_ret = (struct virtchnl_fdir_add *)args.out_buffer;
1457 if (fdir_ret->status == VIRTCHNL_FDIR_SUCCESS) {
1459 "Succeed in checking rule request by PF");
1460 } else if (fdir_ret->status == VIRTCHNL_FDIR_FAILURE_RULE_INVALID) {
1462 "Failed to check rule request due to parameters validation"
1463 " or HW doesn't support");
1467 "Failed to check rule request due to other reasons");
1475 iavf_add_del_rss_cfg(struct iavf_adapter *adapter,
1476 struct virtchnl_rss_cfg *rss_cfg, bool add)
1478 struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(adapter);
1479 struct iavf_cmd_info args;
1482 memset(&args, 0, sizeof(args));
1483 args.ops = add ? VIRTCHNL_OP_ADD_RSS_CFG :
1484 VIRTCHNL_OP_DEL_RSS_CFG;
1485 args.in_args = (u8 *)rss_cfg;
1486 args.in_args_size = sizeof(*rss_cfg);
1487 args.out_buffer = vf->aq_resp;
1488 args.out_size = IAVF_AQ_BUF_SZ;
1490 err = iavf_execute_vf_cmd(adapter, &args);
1493 "Failed to execute command of %s",
1494 add ? "OP_ADD_RSS_CFG" :
1495 "OP_DEL_RSS_INPUT_CFG");
1501 iavf_set_hena(struct iavf_adapter *adapter, uint64_t hena)
1503 struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(adapter);
1504 struct virtchnl_rss_hena vrh;
1505 struct iavf_cmd_info args;
1509 args.ops = VIRTCHNL_OP_SET_RSS_HENA;
1510 args.in_args = (u8 *)&vrh;
1511 args.in_args_size = sizeof(vrh);
1512 args.out_buffer = vf->aq_resp;
1513 args.out_size = IAVF_AQ_BUF_SZ;
1515 err = iavf_execute_vf_cmd(adapter, &args);
1518 "Failed to execute command of OP_SET_RSS_HENA");
1524 iavf_add_del_mc_addr_list(struct iavf_adapter *adapter,
1525 struct rte_ether_addr *mc_addrs,
1526 uint32_t mc_addrs_num, bool add)
1528 struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(adapter);
1529 uint8_t cmd_buffer[sizeof(struct virtchnl_ether_addr_list) +
1530 (IAVF_NUM_MACADDR_MAX * sizeof(struct virtchnl_ether_addr))];
1531 struct virtchnl_ether_addr_list *list;
1532 struct iavf_cmd_info args;
1536 if (mc_addrs == NULL || mc_addrs_num == 0)
1539 list = (struct virtchnl_ether_addr_list *)cmd_buffer;
1540 list->vsi_id = vf->vsi_res->vsi_id;
1541 list->num_elements = mc_addrs_num;
1543 for (i = 0; i < mc_addrs_num; i++) {
1544 if (!IAVF_IS_MULTICAST(mc_addrs[i].addr_bytes)) {
1545 PMD_DRV_LOG(ERR, "Invalid mac:%x:%x:%x:%x:%x:%x",
1546 mc_addrs[i].addr_bytes[0],
1547 mc_addrs[i].addr_bytes[1],
1548 mc_addrs[i].addr_bytes[2],
1549 mc_addrs[i].addr_bytes[3],
1550 mc_addrs[i].addr_bytes[4],
1551 mc_addrs[i].addr_bytes[5]);
1555 memcpy(list->list[i].addr, mc_addrs[i].addr_bytes,
1556 sizeof(list->list[i].addr));
1559 args.ops = add ? VIRTCHNL_OP_ADD_ETH_ADDR : VIRTCHNL_OP_DEL_ETH_ADDR;
1560 args.in_args = cmd_buffer;
1561 args.in_args_size = sizeof(struct virtchnl_ether_addr_list) +
1562 i * sizeof(struct virtchnl_ether_addr);
1563 args.out_buffer = vf->aq_resp;
1564 args.out_size = IAVF_AQ_BUF_SZ;
1565 err = iavf_execute_vf_cmd(adapter, &args);
1568 PMD_DRV_LOG(ERR, "fail to execute command %s",
1569 add ? "OP_ADD_ETH_ADDR" : "OP_DEL_ETH_ADDR");
1577 iavf_request_queues(struct iavf_adapter *adapter, uint16_t num)
1579 struct rte_eth_dev *dev = adapter->eth_dev;
1580 struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(adapter);
1581 struct rte_pci_device *pci_dev = RTE_ETH_DEV_TO_PCI(dev);
1582 struct virtchnl_vf_res_request vfres;
1583 struct iavf_cmd_info args;
1584 uint16_t num_queue_pairs;
1587 if (!(vf->vf_res->vf_cap_flags &
1588 VIRTCHNL_VF_OFFLOAD_REQ_QUEUES)) {
1589 PMD_DRV_LOG(ERR, "request queues not supported");
1594 PMD_DRV_LOG(ERR, "queue number cannot be zero");
1597 vfres.num_queue_pairs = num;
1599 args.ops = VIRTCHNL_OP_REQUEST_QUEUES;
1600 args.in_args = (u8 *)&vfres;
1601 args.in_args_size = sizeof(vfres);
1602 args.out_buffer = vf->aq_resp;
1603 args.out_size = IAVF_AQ_BUF_SZ;
1606 * disable interrupt to avoid the admin queue message to be read
1607 * before iavf_read_msg_from_pf.
1609 rte_intr_disable(&pci_dev->intr_handle);
1610 err = iavf_execute_vf_cmd(adapter, &args);
1611 rte_intr_enable(&pci_dev->intr_handle);
1613 PMD_DRV_LOG(ERR, "fail to execute command OP_REQUEST_QUEUES");
1617 /* request queues succeeded, vf is resetting */
1619 PMD_DRV_LOG(INFO, "vf is resetting");
1623 /* request additional queues failed, return available number */
1625 ((struct virtchnl_vf_res_request *)args.out_buffer)->num_queue_pairs;
1626 PMD_DRV_LOG(ERR, "request queues failed, only %u queues "
1627 "available", num_queue_pairs);
1633 iavf_get_max_rss_queue_region(struct iavf_adapter *adapter)
1635 struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(adapter);
1636 struct iavf_cmd_info args;
1637 uint16_t qregion_width;
1640 args.ops = VIRTCHNL_OP_GET_MAX_RSS_QREGION;
1641 args.in_args = NULL;
1642 args.in_args_size = 0;
1643 args.out_buffer = vf->aq_resp;
1644 args.out_size = IAVF_AQ_BUF_SZ;
1646 err = iavf_execute_vf_cmd(adapter, &args);
1648 PMD_DRV_LOG(ERR, "Failed to execute command of VIRTCHNL_OP_GET_MAX_RSS_QREGION");
1653 ((struct virtchnl_max_rss_qregion *)args.out_buffer)->qregion_width;
1655 vf->max_rss_qregion = (uint16_t)(1 << qregion_width);