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 *stripping_caps;
532 struct virtchnl_vlan_setting vlan_strip;
533 struct iavf_cmd_info args;
537 stripping_caps = &vf->vlan_v2_caps.offloads.stripping_support;
539 if ((stripping_caps->outer & VIRTCHNL_VLAN_ETHERTYPE_8100) &&
540 (stripping_caps->outer & VIRTCHNL_VLAN_TOGGLE))
541 ethertype = &vlan_strip.outer_ethertype_setting;
542 else if ((stripping_caps->inner & VIRTCHNL_VLAN_ETHERTYPE_8100) &&
543 (stripping_caps->inner & VIRTCHNL_VLAN_TOGGLE))
544 ethertype = &vlan_strip.inner_ethertype_setting;
548 memset(&vlan_strip, 0, sizeof(vlan_strip));
549 vlan_strip.vport_id = vf->vsi_res->vsi_id;
550 *ethertype = VIRTCHNL_VLAN_ETHERTYPE_8100;
552 args.ops = enable ? VIRTCHNL_OP_ENABLE_VLAN_STRIPPING_V2 :
553 VIRTCHNL_OP_DISABLE_VLAN_STRIPPING_V2;
554 args.in_args = (uint8_t *)&vlan_strip;
555 args.in_args_size = sizeof(vlan_strip);
556 args.out_buffer = vf->aq_resp;
557 args.out_size = IAVF_AQ_BUF_SZ;
558 ret = iavf_execute_vf_cmd(adapter, &args);
560 PMD_DRV_LOG(ERR, "fail to execute command %s",
561 enable ? "VIRTCHNL_OP_ENABLE_VLAN_STRIPPING_V2" :
562 "VIRTCHNL_OP_DISABLE_VLAN_STRIPPING_V2");
568 iavf_config_vlan_insert_v2(struct iavf_adapter *adapter, bool enable)
570 struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(adapter);
571 struct virtchnl_vlan_supported_caps *insertion_caps;
572 struct virtchnl_vlan_setting vlan_insert;
573 struct iavf_cmd_info args;
577 insertion_caps = &vf->vlan_v2_caps.offloads.insertion_support;
579 if ((insertion_caps->outer & VIRTCHNL_VLAN_ETHERTYPE_8100) &&
580 (insertion_caps->outer & VIRTCHNL_VLAN_TOGGLE))
581 ethertype = &vlan_insert.outer_ethertype_setting;
582 else if ((insertion_caps->inner & VIRTCHNL_VLAN_ETHERTYPE_8100) &&
583 (insertion_caps->inner & VIRTCHNL_VLAN_TOGGLE))
584 ethertype = &vlan_insert.inner_ethertype_setting;
588 memset(&vlan_insert, 0, sizeof(vlan_insert));
589 vlan_insert.vport_id = vf->vsi_res->vsi_id;
590 *ethertype = VIRTCHNL_VLAN_ETHERTYPE_8100;
592 args.ops = enable ? VIRTCHNL_OP_ENABLE_VLAN_INSERTION_V2 :
593 VIRTCHNL_OP_DISABLE_VLAN_INSERTION_V2;
594 args.in_args = (uint8_t *)&vlan_insert;
595 args.in_args_size = sizeof(vlan_insert);
596 args.out_buffer = vf->aq_resp;
597 args.out_size = IAVF_AQ_BUF_SZ;
598 ret = iavf_execute_vf_cmd(adapter, &args);
600 PMD_DRV_LOG(ERR, "fail to execute command %s",
601 enable ? "VIRTCHNL_OP_ENABLE_VLAN_INSERTION_V2" :
602 "VIRTCHNL_OP_DISABLE_VLAN_INSERTION_V2");
608 iavf_add_del_vlan_v2(struct iavf_adapter *adapter, uint16_t vlanid, bool add)
610 struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(adapter);
611 struct virtchnl_vlan_supported_caps *supported_caps;
612 struct virtchnl_vlan_filter_list_v2 vlan_filter;
613 struct virtchnl_vlan *vlan_setting;
614 struct iavf_cmd_info args;
615 uint32_t filtering_caps;
618 supported_caps = &vf->vlan_v2_caps.filtering.filtering_support;
619 if (supported_caps->outer) {
620 filtering_caps = supported_caps->outer;
621 vlan_setting = &vlan_filter.filters[0].outer;
623 filtering_caps = supported_caps->inner;
624 vlan_setting = &vlan_filter.filters[0].inner;
627 if (!(filtering_caps & VIRTCHNL_VLAN_ETHERTYPE_8100))
630 memset(&vlan_filter, 0, sizeof(vlan_filter));
631 vlan_filter.vport_id = vf->vsi_res->vsi_id;
632 vlan_filter.num_elements = 1;
633 vlan_setting->tpid = RTE_ETHER_TYPE_VLAN;
634 vlan_setting->tci = vlanid;
636 args.ops = add ? VIRTCHNL_OP_ADD_VLAN_V2 : VIRTCHNL_OP_DEL_VLAN_V2;
637 args.in_args = (uint8_t *)&vlan_filter;
638 args.in_args_size = sizeof(vlan_filter);
639 args.out_buffer = vf->aq_resp;
640 args.out_size = IAVF_AQ_BUF_SZ;
641 err = iavf_execute_vf_cmd(adapter, &args);
643 PMD_DRV_LOG(ERR, "fail to execute command %s",
644 add ? "OP_ADD_VLAN_V2" : "OP_DEL_VLAN_V2");
650 iavf_get_vlan_offload_caps_v2(struct iavf_adapter *adapter)
652 struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(adapter);
653 struct iavf_cmd_info args;
656 args.ops = VIRTCHNL_OP_GET_OFFLOAD_VLAN_V2_CAPS;
658 args.in_args_size = 0;
659 args.out_buffer = vf->aq_resp;
660 args.out_size = IAVF_AQ_BUF_SZ;
662 ret = iavf_execute_vf_cmd(adapter, &args);
665 "Failed to execute command of VIRTCHNL_OP_GET_OFFLOAD_VLAN_V2_CAPS");
669 rte_memcpy(&vf->vlan_v2_caps, vf->aq_resp, sizeof(vf->vlan_v2_caps));
675 iavf_enable_queues(struct iavf_adapter *adapter)
677 struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(adapter);
678 struct virtchnl_queue_select queue_select;
679 struct iavf_cmd_info args;
682 memset(&queue_select, 0, sizeof(queue_select));
683 queue_select.vsi_id = vf->vsi_res->vsi_id;
685 queue_select.rx_queues = BIT(adapter->eth_dev->data->nb_rx_queues) - 1;
686 queue_select.tx_queues = BIT(adapter->eth_dev->data->nb_tx_queues) - 1;
688 args.ops = VIRTCHNL_OP_ENABLE_QUEUES;
689 args.in_args = (u8 *)&queue_select;
690 args.in_args_size = sizeof(queue_select);
691 args.out_buffer = vf->aq_resp;
692 args.out_size = IAVF_AQ_BUF_SZ;
693 err = iavf_execute_vf_cmd(adapter, &args);
696 "Failed to execute command of OP_ENABLE_QUEUES");
703 iavf_disable_queues(struct iavf_adapter *adapter)
705 struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(adapter);
706 struct virtchnl_queue_select queue_select;
707 struct iavf_cmd_info args;
710 memset(&queue_select, 0, sizeof(queue_select));
711 queue_select.vsi_id = vf->vsi_res->vsi_id;
713 queue_select.rx_queues = BIT(adapter->eth_dev->data->nb_rx_queues) - 1;
714 queue_select.tx_queues = BIT(adapter->eth_dev->data->nb_tx_queues) - 1;
716 args.ops = VIRTCHNL_OP_DISABLE_QUEUES;
717 args.in_args = (u8 *)&queue_select;
718 args.in_args_size = sizeof(queue_select);
719 args.out_buffer = vf->aq_resp;
720 args.out_size = IAVF_AQ_BUF_SZ;
721 err = iavf_execute_vf_cmd(adapter, &args);
724 "Failed to execute command of OP_DISABLE_QUEUES");
731 iavf_switch_queue(struct iavf_adapter *adapter, uint16_t qid,
734 struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(adapter);
735 struct virtchnl_queue_select queue_select;
736 struct iavf_cmd_info args;
739 memset(&queue_select, 0, sizeof(queue_select));
740 queue_select.vsi_id = vf->vsi_res->vsi_id;
742 queue_select.rx_queues |= 1 << qid;
744 queue_select.tx_queues |= 1 << qid;
747 args.ops = VIRTCHNL_OP_ENABLE_QUEUES;
749 args.ops = VIRTCHNL_OP_DISABLE_QUEUES;
750 args.in_args = (u8 *)&queue_select;
751 args.in_args_size = sizeof(queue_select);
752 args.out_buffer = vf->aq_resp;
753 args.out_size = IAVF_AQ_BUF_SZ;
754 err = iavf_execute_vf_cmd(adapter, &args);
756 PMD_DRV_LOG(ERR, "Failed to execute command of %s",
757 on ? "OP_ENABLE_QUEUES" : "OP_DISABLE_QUEUES");
762 iavf_enable_queues_lv(struct iavf_adapter *adapter)
764 struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(adapter);
765 struct virtchnl_del_ena_dis_queues *queue_select;
766 struct virtchnl_queue_chunk *queue_chunk;
767 struct iavf_cmd_info args;
770 len = sizeof(struct virtchnl_del_ena_dis_queues) +
771 sizeof(struct virtchnl_queue_chunk) *
772 (IAVF_RXTX_QUEUE_CHUNKS_NUM - 1);
773 queue_select = rte_zmalloc("queue_select", len, 0);
777 queue_chunk = queue_select->chunks.chunks;
778 queue_select->chunks.num_chunks = IAVF_RXTX_QUEUE_CHUNKS_NUM;
779 queue_select->vport_id = vf->vsi_res->vsi_id;
781 queue_chunk[VIRTCHNL_QUEUE_TYPE_TX].type = VIRTCHNL_QUEUE_TYPE_TX;
782 queue_chunk[VIRTCHNL_QUEUE_TYPE_TX].start_queue_id = 0;
783 queue_chunk[VIRTCHNL_QUEUE_TYPE_TX].num_queues =
784 adapter->eth_dev->data->nb_tx_queues;
786 queue_chunk[VIRTCHNL_QUEUE_TYPE_RX].type = VIRTCHNL_QUEUE_TYPE_RX;
787 queue_chunk[VIRTCHNL_QUEUE_TYPE_RX].start_queue_id = 0;
788 queue_chunk[VIRTCHNL_QUEUE_TYPE_RX].num_queues =
789 adapter->eth_dev->data->nb_rx_queues;
791 args.ops = VIRTCHNL_OP_ENABLE_QUEUES_V2;
792 args.in_args = (u8 *)queue_select;
793 args.in_args_size = len;
794 args.out_buffer = vf->aq_resp;
795 args.out_size = IAVF_AQ_BUF_SZ;
796 err = iavf_execute_vf_cmd(adapter, &args);
799 "Failed to execute command of OP_ENABLE_QUEUES_V2");
801 rte_free(queue_select);
806 iavf_disable_queues_lv(struct iavf_adapter *adapter)
808 struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(adapter);
809 struct virtchnl_del_ena_dis_queues *queue_select;
810 struct virtchnl_queue_chunk *queue_chunk;
811 struct iavf_cmd_info args;
814 len = sizeof(struct virtchnl_del_ena_dis_queues) +
815 sizeof(struct virtchnl_queue_chunk) *
816 (IAVF_RXTX_QUEUE_CHUNKS_NUM - 1);
817 queue_select = rte_zmalloc("queue_select", len, 0);
821 queue_chunk = queue_select->chunks.chunks;
822 queue_select->chunks.num_chunks = IAVF_RXTX_QUEUE_CHUNKS_NUM;
823 queue_select->vport_id = vf->vsi_res->vsi_id;
825 queue_chunk[VIRTCHNL_QUEUE_TYPE_TX].type = VIRTCHNL_QUEUE_TYPE_TX;
826 queue_chunk[VIRTCHNL_QUEUE_TYPE_TX].start_queue_id = 0;
827 queue_chunk[VIRTCHNL_QUEUE_TYPE_TX].num_queues =
828 adapter->eth_dev->data->nb_tx_queues;
830 queue_chunk[VIRTCHNL_QUEUE_TYPE_RX].type = VIRTCHNL_QUEUE_TYPE_RX;
831 queue_chunk[VIRTCHNL_QUEUE_TYPE_RX].start_queue_id = 0;
832 queue_chunk[VIRTCHNL_QUEUE_TYPE_RX].num_queues =
833 adapter->eth_dev->data->nb_rx_queues;
835 args.ops = VIRTCHNL_OP_DISABLE_QUEUES_V2;
836 args.in_args = (u8 *)queue_select;
837 args.in_args_size = len;
838 args.out_buffer = vf->aq_resp;
839 args.out_size = IAVF_AQ_BUF_SZ;
840 err = iavf_execute_vf_cmd(adapter, &args);
843 "Failed to execute command of OP_DISABLE_QUEUES_V2");
845 rte_free(queue_select);
850 iavf_switch_queue_lv(struct iavf_adapter *adapter, uint16_t qid,
853 struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(adapter);
854 struct virtchnl_del_ena_dis_queues *queue_select;
855 struct virtchnl_queue_chunk *queue_chunk;
856 struct iavf_cmd_info args;
859 len = sizeof(struct virtchnl_del_ena_dis_queues);
860 queue_select = rte_zmalloc("queue_select", len, 0);
864 queue_chunk = queue_select->chunks.chunks;
865 queue_select->chunks.num_chunks = 1;
866 queue_select->vport_id = vf->vsi_res->vsi_id;
869 queue_chunk->type = VIRTCHNL_QUEUE_TYPE_RX;
870 queue_chunk->start_queue_id = qid;
871 queue_chunk->num_queues = 1;
873 queue_chunk->type = VIRTCHNL_QUEUE_TYPE_TX;
874 queue_chunk->start_queue_id = qid;
875 queue_chunk->num_queues = 1;
879 args.ops = VIRTCHNL_OP_ENABLE_QUEUES_V2;
881 args.ops = VIRTCHNL_OP_DISABLE_QUEUES_V2;
882 args.in_args = (u8 *)queue_select;
883 args.in_args_size = len;
884 args.out_buffer = vf->aq_resp;
885 args.out_size = IAVF_AQ_BUF_SZ;
886 err = iavf_execute_vf_cmd(adapter, &args);
888 PMD_DRV_LOG(ERR, "Failed to execute command of %s",
889 on ? "OP_ENABLE_QUEUES_V2" : "OP_DISABLE_QUEUES_V2");
891 rte_free(queue_select);
896 iavf_configure_rss_lut(struct iavf_adapter *adapter)
898 struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(adapter);
899 struct virtchnl_rss_lut *rss_lut;
900 struct iavf_cmd_info args;
903 len = sizeof(*rss_lut) + vf->vf_res->rss_lut_size - 1;
904 rss_lut = rte_zmalloc("rss_lut", len, 0);
908 rss_lut->vsi_id = vf->vsi_res->vsi_id;
909 rss_lut->lut_entries = vf->vf_res->rss_lut_size;
910 rte_memcpy(rss_lut->lut, vf->rss_lut, vf->vf_res->rss_lut_size);
912 args.ops = VIRTCHNL_OP_CONFIG_RSS_LUT;
913 args.in_args = (u8 *)rss_lut;
914 args.in_args_size = len;
915 args.out_buffer = vf->aq_resp;
916 args.out_size = IAVF_AQ_BUF_SZ;
918 err = iavf_execute_vf_cmd(adapter, &args);
921 "Failed to execute command of OP_CONFIG_RSS_LUT");
928 iavf_configure_rss_key(struct iavf_adapter *adapter)
930 struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(adapter);
931 struct virtchnl_rss_key *rss_key;
932 struct iavf_cmd_info args;
935 len = sizeof(*rss_key) + vf->vf_res->rss_key_size - 1;
936 rss_key = rte_zmalloc("rss_key", len, 0);
940 rss_key->vsi_id = vf->vsi_res->vsi_id;
941 rss_key->key_len = vf->vf_res->rss_key_size;
942 rte_memcpy(rss_key->key, vf->rss_key, vf->vf_res->rss_key_size);
944 args.ops = VIRTCHNL_OP_CONFIG_RSS_KEY;
945 args.in_args = (u8 *)rss_key;
946 args.in_args_size = len;
947 args.out_buffer = vf->aq_resp;
948 args.out_size = IAVF_AQ_BUF_SZ;
950 err = iavf_execute_vf_cmd(adapter, &args);
953 "Failed to execute command of OP_CONFIG_RSS_KEY");
960 iavf_configure_queues(struct iavf_adapter *adapter,
961 uint16_t num_queue_pairs, uint16_t index)
963 struct iavf_rx_queue **rxq =
964 (struct iavf_rx_queue **)adapter->eth_dev->data->rx_queues;
965 struct iavf_tx_queue **txq =
966 (struct iavf_tx_queue **)adapter->eth_dev->data->tx_queues;
967 struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(adapter);
968 struct virtchnl_vsi_queue_config_info *vc_config;
969 struct virtchnl_queue_pair_info *vc_qp;
970 struct iavf_cmd_info args;
974 size = sizeof(*vc_config) +
975 sizeof(vc_config->qpair[0]) * num_queue_pairs;
976 vc_config = rte_zmalloc("cfg_queue", size, 0);
980 vc_config->vsi_id = vf->vsi_res->vsi_id;
981 vc_config->num_queue_pairs = num_queue_pairs;
983 for (i = index, vc_qp = vc_config->qpair;
984 i < index + num_queue_pairs;
986 vc_qp->txq.vsi_id = vf->vsi_res->vsi_id;
987 vc_qp->txq.queue_id = i;
989 /* Virtchnnl configure tx queues by pairs */
990 if (i < adapter->eth_dev->data->nb_tx_queues) {
991 vc_qp->txq.ring_len = txq[i]->nb_tx_desc;
992 vc_qp->txq.dma_ring_addr = txq[i]->tx_ring_phys_addr;
995 vc_qp->rxq.vsi_id = vf->vsi_res->vsi_id;
996 vc_qp->rxq.queue_id = i;
997 vc_qp->rxq.max_pkt_size = vf->max_pkt_len;
999 if (i >= adapter->eth_dev->data->nb_rx_queues)
1002 /* Virtchnnl configure rx queues by pairs */
1003 vc_qp->rxq.ring_len = rxq[i]->nb_rx_desc;
1004 vc_qp->rxq.dma_ring_addr = rxq[i]->rx_ring_phys_addr;
1005 vc_qp->rxq.databuffer_size = rxq[i]->rx_buf_len;
1006 vc_qp->rxq.crc_disable = rxq[i]->crc_len != 0 ? 1 : 0;
1007 #ifndef RTE_LIBRTE_IAVF_16BYTE_RX_DESC
1008 if (vf->vf_res->vf_cap_flags &
1009 VIRTCHNL_VF_OFFLOAD_RX_FLEX_DESC &&
1010 vf->supported_rxdid & BIT(rxq[i]->rxdid)) {
1011 vc_qp->rxq.rxdid = rxq[i]->rxdid;
1012 PMD_DRV_LOG(NOTICE, "request RXDID[%d] in Queue[%d]",
1013 vc_qp->rxq.rxdid, i);
1015 PMD_DRV_LOG(NOTICE, "RXDID[%d] is not supported, "
1016 "request default RXDID[%d] in Queue[%d]",
1017 rxq[i]->rxdid, IAVF_RXDID_LEGACY_1, i);
1018 vc_qp->rxq.rxdid = IAVF_RXDID_LEGACY_1;
1021 if (vf->vf_res->vf_cap_flags &
1022 VIRTCHNL_VF_OFFLOAD_RX_FLEX_DESC &&
1023 vf->supported_rxdid & BIT(IAVF_RXDID_LEGACY_0)) {
1024 vc_qp->rxq.rxdid = IAVF_RXDID_LEGACY_0;
1025 PMD_DRV_LOG(NOTICE, "request RXDID[%d] in Queue[%d]",
1026 vc_qp->rxq.rxdid, i);
1028 PMD_DRV_LOG(ERR, "RXDID[%d] is not supported",
1029 IAVF_RXDID_LEGACY_0);
1035 memset(&args, 0, sizeof(args));
1036 args.ops = VIRTCHNL_OP_CONFIG_VSI_QUEUES;
1037 args.in_args = (uint8_t *)vc_config;
1038 args.in_args_size = size;
1039 args.out_buffer = vf->aq_resp;
1040 args.out_size = IAVF_AQ_BUF_SZ;
1042 err = iavf_execute_vf_cmd(adapter, &args);
1044 PMD_DRV_LOG(ERR, "Failed to execute command of"
1045 " VIRTCHNL_OP_CONFIG_VSI_QUEUES");
1047 rte_free(vc_config);
1052 iavf_config_irq_map(struct iavf_adapter *adapter)
1054 struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(adapter);
1055 struct virtchnl_irq_map_info *map_info;
1056 struct virtchnl_vector_map *vecmap;
1057 struct iavf_cmd_info args;
1060 len = sizeof(struct virtchnl_irq_map_info) +
1061 sizeof(struct virtchnl_vector_map) * vf->nb_msix;
1063 map_info = rte_zmalloc("map_info", len, 0);
1067 map_info->num_vectors = vf->nb_msix;
1068 for (i = 0; i < adapter->eth_dev->data->nb_rx_queues; i++) {
1070 &map_info->vecmap[vf->qv_map[i].vector_id - vf->msix_base];
1071 vecmap->vsi_id = vf->vsi_res->vsi_id;
1072 vecmap->rxitr_idx = IAVF_ITR_INDEX_DEFAULT;
1073 vecmap->vector_id = vf->qv_map[i].vector_id;
1074 vecmap->txq_map = 0;
1075 vecmap->rxq_map |= 1 << vf->qv_map[i].queue_id;
1078 args.ops = VIRTCHNL_OP_CONFIG_IRQ_MAP;
1079 args.in_args = (u8 *)map_info;
1080 args.in_args_size = len;
1081 args.out_buffer = vf->aq_resp;
1082 args.out_size = IAVF_AQ_BUF_SZ;
1083 err = iavf_execute_vf_cmd(adapter, &args);
1085 PMD_DRV_LOG(ERR, "fail to execute command OP_CONFIG_IRQ_MAP");
1092 iavf_config_irq_map_lv(struct iavf_adapter *adapter, uint16_t num,
1095 struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(adapter);
1096 struct virtchnl_queue_vector_maps *map_info;
1097 struct virtchnl_queue_vector *qv_maps;
1098 struct iavf_cmd_info args;
1102 len = sizeof(struct virtchnl_queue_vector_maps) +
1103 sizeof(struct virtchnl_queue_vector) * (num - 1);
1105 map_info = rte_zmalloc("map_info", len, 0);
1109 map_info->vport_id = vf->vsi_res->vsi_id;
1110 map_info->num_qv_maps = num;
1111 for (i = index; i < index + map_info->num_qv_maps; i++) {
1112 qv_maps = &map_info->qv_maps[count++];
1113 qv_maps->itr_idx = VIRTCHNL_ITR_IDX_0;
1114 qv_maps->queue_type = VIRTCHNL_QUEUE_TYPE_RX;
1115 qv_maps->queue_id = vf->qv_map[i].queue_id;
1116 qv_maps->vector_id = vf->qv_map[i].vector_id;
1119 args.ops = VIRTCHNL_OP_MAP_QUEUE_VECTOR;
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);
1126 PMD_DRV_LOG(ERR, "fail to execute command OP_MAP_QUEUE_VECTOR");
1133 iavf_add_del_all_mac_addr(struct iavf_adapter *adapter, bool add)
1135 struct virtchnl_ether_addr_list *list;
1136 struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(adapter);
1137 struct rte_ether_addr *addr;
1138 struct iavf_cmd_info args;
1145 len = sizeof(struct virtchnl_ether_addr_list);
1146 for (i = begin; i < IAVF_NUM_MACADDR_MAX; i++, next_begin++) {
1147 addr = &adapter->eth_dev->data->mac_addrs[i];
1148 if (rte_is_zero_ether_addr(addr))
1150 len += sizeof(struct virtchnl_ether_addr);
1151 if (len >= IAVF_AQ_BUF_SZ) {
1157 list = rte_zmalloc("iavf_del_mac_buffer", len, 0);
1159 PMD_DRV_LOG(ERR, "fail to allocate memory");
1163 for (i = begin; i < next_begin; i++) {
1164 addr = &adapter->eth_dev->data->mac_addrs[i];
1165 if (rte_is_zero_ether_addr(addr))
1167 rte_memcpy(list->list[j].addr, addr->addr_bytes,
1168 sizeof(addr->addr_bytes));
1169 PMD_DRV_LOG(DEBUG, "add/rm mac:%x:%x:%x:%x:%x:%x",
1170 addr->addr_bytes[0], addr->addr_bytes[1],
1171 addr->addr_bytes[2], addr->addr_bytes[3],
1172 addr->addr_bytes[4], addr->addr_bytes[5]);
1175 list->vsi_id = vf->vsi_res->vsi_id;
1176 list->num_elements = j;
1177 args.ops = add ? VIRTCHNL_OP_ADD_ETH_ADDR :
1178 VIRTCHNL_OP_DEL_ETH_ADDR;
1179 args.in_args = (uint8_t *)list;
1180 args.in_args_size = len;
1181 args.out_buffer = vf->aq_resp;
1182 args.out_size = IAVF_AQ_BUF_SZ;
1183 err = iavf_execute_vf_cmd(adapter, &args);
1185 PMD_DRV_LOG(ERR, "fail to execute command %s",
1186 add ? "OP_ADD_ETHER_ADDRESS" :
1187 "OP_DEL_ETHER_ADDRESS");
1190 } while (begin < IAVF_NUM_MACADDR_MAX);
1194 iavf_query_stats(struct iavf_adapter *adapter,
1195 struct virtchnl_eth_stats **pstats)
1197 struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(adapter);
1198 struct virtchnl_queue_select q_stats;
1199 struct iavf_cmd_info args;
1202 memset(&q_stats, 0, sizeof(q_stats));
1203 q_stats.vsi_id = vf->vsi_res->vsi_id;
1204 args.ops = VIRTCHNL_OP_GET_STATS;
1205 args.in_args = (uint8_t *)&q_stats;
1206 args.in_args_size = sizeof(q_stats);
1207 args.out_buffer = vf->aq_resp;
1208 args.out_size = IAVF_AQ_BUF_SZ;
1210 err = iavf_execute_vf_cmd(adapter, &args);
1212 PMD_DRV_LOG(ERR, "fail to execute command OP_GET_STATS");
1216 *pstats = (struct virtchnl_eth_stats *)args.out_buffer;
1221 iavf_config_promisc(struct iavf_adapter *adapter,
1222 bool enable_unicast,
1223 bool enable_multicast)
1225 struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(adapter);
1226 struct virtchnl_promisc_info promisc;
1227 struct iavf_cmd_info args;
1231 promisc.vsi_id = vf->vsi_res->vsi_id;
1234 promisc.flags |= FLAG_VF_UNICAST_PROMISC;
1236 if (enable_multicast)
1237 promisc.flags |= FLAG_VF_MULTICAST_PROMISC;
1239 args.ops = VIRTCHNL_OP_CONFIG_PROMISCUOUS_MODE;
1240 args.in_args = (uint8_t *)&promisc;
1241 args.in_args_size = sizeof(promisc);
1242 args.out_buffer = vf->aq_resp;
1243 args.out_size = IAVF_AQ_BUF_SZ;
1245 err = iavf_execute_vf_cmd(adapter, &args);
1249 "fail to execute command CONFIG_PROMISCUOUS_MODE");
1251 if (err == IAVF_NOT_SUPPORTED)
1257 vf->promisc_unicast_enabled = enable_unicast;
1258 vf->promisc_multicast_enabled = enable_multicast;
1263 iavf_add_del_eth_addr(struct iavf_adapter *adapter, struct rte_ether_addr *addr,
1266 struct virtchnl_ether_addr_list *list;
1267 struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(adapter);
1268 uint8_t cmd_buffer[sizeof(struct virtchnl_ether_addr_list) +
1269 sizeof(struct virtchnl_ether_addr)];
1270 struct iavf_cmd_info args;
1273 list = (struct virtchnl_ether_addr_list *)cmd_buffer;
1274 list->vsi_id = vf->vsi_res->vsi_id;
1275 list->num_elements = 1;
1276 rte_memcpy(list->list[0].addr, addr->addr_bytes,
1277 sizeof(addr->addr_bytes));
1279 args.ops = add ? VIRTCHNL_OP_ADD_ETH_ADDR : VIRTCHNL_OP_DEL_ETH_ADDR;
1280 args.in_args = cmd_buffer;
1281 args.in_args_size = sizeof(cmd_buffer);
1282 args.out_buffer = vf->aq_resp;
1283 args.out_size = IAVF_AQ_BUF_SZ;
1284 err = iavf_execute_vf_cmd(adapter, &args);
1286 PMD_DRV_LOG(ERR, "fail to execute command %s",
1287 add ? "OP_ADD_ETH_ADDR" : "OP_DEL_ETH_ADDR");
1292 iavf_add_del_vlan(struct iavf_adapter *adapter, uint16_t vlanid, bool add)
1294 struct virtchnl_vlan_filter_list *vlan_list;
1295 struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(adapter);
1296 uint8_t cmd_buffer[sizeof(struct virtchnl_vlan_filter_list) +
1298 struct iavf_cmd_info args;
1301 vlan_list = (struct virtchnl_vlan_filter_list *)cmd_buffer;
1302 vlan_list->vsi_id = vf->vsi_res->vsi_id;
1303 vlan_list->num_elements = 1;
1304 vlan_list->vlan_id[0] = vlanid;
1306 args.ops = add ? VIRTCHNL_OP_ADD_VLAN : VIRTCHNL_OP_DEL_VLAN;
1307 args.in_args = cmd_buffer;
1308 args.in_args_size = sizeof(cmd_buffer);
1309 args.out_buffer = vf->aq_resp;
1310 args.out_size = IAVF_AQ_BUF_SZ;
1311 err = iavf_execute_vf_cmd(adapter, &args);
1313 PMD_DRV_LOG(ERR, "fail to execute command %s",
1314 add ? "OP_ADD_VLAN" : "OP_DEL_VLAN");
1320 iavf_fdir_add(struct iavf_adapter *adapter,
1321 struct iavf_fdir_conf *filter)
1323 struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(adapter);
1324 struct virtchnl_fdir_add *fdir_ret;
1326 struct iavf_cmd_info args;
1329 filter->add_fltr.vsi_id = vf->vsi_res->vsi_id;
1330 filter->add_fltr.validate_only = 0;
1332 args.ops = VIRTCHNL_OP_ADD_FDIR_FILTER;
1333 args.in_args = (uint8_t *)(&filter->add_fltr);
1334 args.in_args_size = sizeof(*(&filter->add_fltr));
1335 args.out_buffer = vf->aq_resp;
1336 args.out_size = IAVF_AQ_BUF_SZ;
1338 err = iavf_execute_vf_cmd(adapter, &args);
1340 PMD_DRV_LOG(ERR, "fail to execute command OP_ADD_FDIR_FILTER");
1344 fdir_ret = (struct virtchnl_fdir_add *)args.out_buffer;
1345 filter->flow_id = fdir_ret->flow_id;
1347 if (fdir_ret->status == VIRTCHNL_FDIR_SUCCESS) {
1349 "Succeed in adding rule request by PF");
1350 } else if (fdir_ret->status == VIRTCHNL_FDIR_FAILURE_RULE_NORESOURCE) {
1352 "Failed to add rule request due to no hw resource");
1354 } else if (fdir_ret->status == VIRTCHNL_FDIR_FAILURE_RULE_EXIST) {
1356 "Failed to add rule request due to the rule is already existed");
1358 } else if (fdir_ret->status == VIRTCHNL_FDIR_FAILURE_RULE_CONFLICT) {
1360 "Failed to add rule request due to the rule is conflict with existing rule");
1362 } else if (fdir_ret->status == VIRTCHNL_FDIR_FAILURE_RULE_INVALID) {
1364 "Failed to add rule request due to the hw doesn't support");
1366 } else if (fdir_ret->status == VIRTCHNL_FDIR_FAILURE_RULE_TIMEOUT) {
1368 "Failed to add rule request due to time out for programming");
1372 "Failed to add rule request due to other reasons");
1380 iavf_fdir_del(struct iavf_adapter *adapter,
1381 struct iavf_fdir_conf *filter)
1383 struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(adapter);
1384 struct virtchnl_fdir_del *fdir_ret;
1386 struct iavf_cmd_info args;
1389 filter->del_fltr.vsi_id = vf->vsi_res->vsi_id;
1390 filter->del_fltr.flow_id = filter->flow_id;
1392 args.ops = VIRTCHNL_OP_DEL_FDIR_FILTER;
1393 args.in_args = (uint8_t *)(&filter->del_fltr);
1394 args.in_args_size = sizeof(filter->del_fltr);
1395 args.out_buffer = vf->aq_resp;
1396 args.out_size = IAVF_AQ_BUF_SZ;
1398 err = iavf_execute_vf_cmd(adapter, &args);
1400 PMD_DRV_LOG(ERR, "fail to execute command OP_DEL_FDIR_FILTER");
1404 fdir_ret = (struct virtchnl_fdir_del *)args.out_buffer;
1406 if (fdir_ret->status == VIRTCHNL_FDIR_SUCCESS) {
1408 "Succeed in deleting rule request by PF");
1409 } else if (fdir_ret->status == VIRTCHNL_FDIR_FAILURE_RULE_NONEXIST) {
1411 "Failed to delete rule request due to this rule doesn't exist");
1413 } else if (fdir_ret->status == VIRTCHNL_FDIR_FAILURE_RULE_TIMEOUT) {
1415 "Failed to delete rule request due to time out for programming");
1419 "Failed to delete rule request due to other reasons");
1427 iavf_fdir_check(struct iavf_adapter *adapter,
1428 struct iavf_fdir_conf *filter)
1430 struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(adapter);
1431 struct virtchnl_fdir_add *fdir_ret;
1433 struct iavf_cmd_info args;
1436 filter->add_fltr.vsi_id = vf->vsi_res->vsi_id;
1437 filter->add_fltr.validate_only = 1;
1439 args.ops = VIRTCHNL_OP_ADD_FDIR_FILTER;
1440 args.in_args = (uint8_t *)(&filter->add_fltr);
1441 args.in_args_size = sizeof(*(&filter->add_fltr));
1442 args.out_buffer = vf->aq_resp;
1443 args.out_size = IAVF_AQ_BUF_SZ;
1445 err = iavf_execute_vf_cmd(adapter, &args);
1447 PMD_DRV_LOG(ERR, "fail to check flow direcotor rule");
1451 fdir_ret = (struct virtchnl_fdir_add *)args.out_buffer;
1453 if (fdir_ret->status == VIRTCHNL_FDIR_SUCCESS) {
1455 "Succeed in checking rule request by PF");
1456 } else if (fdir_ret->status == VIRTCHNL_FDIR_FAILURE_RULE_INVALID) {
1458 "Failed to check rule request due to parameters validation"
1459 " or HW doesn't support");
1463 "Failed to check rule request due to other reasons");
1471 iavf_add_del_rss_cfg(struct iavf_adapter *adapter,
1472 struct virtchnl_rss_cfg *rss_cfg, bool add)
1474 struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(adapter);
1475 struct iavf_cmd_info args;
1478 memset(&args, 0, sizeof(args));
1479 args.ops = add ? VIRTCHNL_OP_ADD_RSS_CFG :
1480 VIRTCHNL_OP_DEL_RSS_CFG;
1481 args.in_args = (u8 *)rss_cfg;
1482 args.in_args_size = sizeof(*rss_cfg);
1483 args.out_buffer = vf->aq_resp;
1484 args.out_size = IAVF_AQ_BUF_SZ;
1486 err = iavf_execute_vf_cmd(adapter, &args);
1489 "Failed to execute command of %s",
1490 add ? "OP_ADD_RSS_CFG" :
1491 "OP_DEL_RSS_INPUT_CFG");
1497 iavf_set_hena(struct iavf_adapter *adapter, uint64_t hena)
1499 struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(adapter);
1500 struct virtchnl_rss_hena vrh;
1501 struct iavf_cmd_info args;
1505 args.ops = VIRTCHNL_OP_SET_RSS_HENA;
1506 args.in_args = (u8 *)&vrh;
1507 args.in_args_size = sizeof(vrh);
1508 args.out_buffer = vf->aq_resp;
1509 args.out_size = IAVF_AQ_BUF_SZ;
1511 err = iavf_execute_vf_cmd(adapter, &args);
1514 "Failed to execute command of OP_SET_RSS_HENA");
1520 iavf_add_del_mc_addr_list(struct iavf_adapter *adapter,
1521 struct rte_ether_addr *mc_addrs,
1522 uint32_t mc_addrs_num, bool add)
1524 struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(adapter);
1525 uint8_t cmd_buffer[sizeof(struct virtchnl_ether_addr_list) +
1526 (IAVF_NUM_MACADDR_MAX * sizeof(struct virtchnl_ether_addr))];
1527 struct virtchnl_ether_addr_list *list;
1528 struct iavf_cmd_info args;
1532 if (mc_addrs == NULL || mc_addrs_num == 0)
1535 list = (struct virtchnl_ether_addr_list *)cmd_buffer;
1536 list->vsi_id = vf->vsi_res->vsi_id;
1537 list->num_elements = mc_addrs_num;
1539 for (i = 0; i < mc_addrs_num; i++) {
1540 if (!IAVF_IS_MULTICAST(mc_addrs[i].addr_bytes)) {
1541 PMD_DRV_LOG(ERR, "Invalid mac:%x:%x:%x:%x:%x:%x",
1542 mc_addrs[i].addr_bytes[0],
1543 mc_addrs[i].addr_bytes[1],
1544 mc_addrs[i].addr_bytes[2],
1545 mc_addrs[i].addr_bytes[3],
1546 mc_addrs[i].addr_bytes[4],
1547 mc_addrs[i].addr_bytes[5]);
1551 memcpy(list->list[i].addr, mc_addrs[i].addr_bytes,
1552 sizeof(list->list[i].addr));
1555 args.ops = add ? VIRTCHNL_OP_ADD_ETH_ADDR : VIRTCHNL_OP_DEL_ETH_ADDR;
1556 args.in_args = cmd_buffer;
1557 args.in_args_size = sizeof(struct virtchnl_ether_addr_list) +
1558 i * sizeof(struct virtchnl_ether_addr);
1559 args.out_buffer = vf->aq_resp;
1560 args.out_size = IAVF_AQ_BUF_SZ;
1561 err = iavf_execute_vf_cmd(adapter, &args);
1564 PMD_DRV_LOG(ERR, "fail to execute command %s",
1565 add ? "OP_ADD_ETH_ADDR" : "OP_DEL_ETH_ADDR");
1573 iavf_request_queues(struct iavf_adapter *adapter, uint16_t num)
1575 struct rte_eth_dev *dev = adapter->eth_dev;
1576 struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(adapter);
1577 struct rte_pci_device *pci_dev = RTE_ETH_DEV_TO_PCI(dev);
1578 struct virtchnl_vf_res_request vfres;
1579 struct iavf_cmd_info args;
1580 uint16_t num_queue_pairs;
1583 if (!(vf->vf_res->vf_cap_flags &
1584 VIRTCHNL_VF_OFFLOAD_REQ_QUEUES)) {
1585 PMD_DRV_LOG(ERR, "request queues not supported");
1590 PMD_DRV_LOG(ERR, "queue number cannot be zero");
1593 vfres.num_queue_pairs = num;
1595 args.ops = VIRTCHNL_OP_REQUEST_QUEUES;
1596 args.in_args = (u8 *)&vfres;
1597 args.in_args_size = sizeof(vfres);
1598 args.out_buffer = vf->aq_resp;
1599 args.out_size = IAVF_AQ_BUF_SZ;
1602 * disable interrupt to avoid the admin queue message to be read
1603 * before iavf_read_msg_from_pf.
1605 rte_intr_disable(&pci_dev->intr_handle);
1606 err = iavf_execute_vf_cmd(adapter, &args);
1607 rte_intr_enable(&pci_dev->intr_handle);
1609 PMD_DRV_LOG(ERR, "fail to execute command OP_REQUEST_QUEUES");
1613 /* request queues succeeded, vf is resetting */
1615 PMD_DRV_LOG(INFO, "vf is resetting");
1619 /* request additional queues failed, return available number */
1621 ((struct virtchnl_vf_res_request *)args.out_buffer)->num_queue_pairs;
1622 PMD_DRV_LOG(ERR, "request queues failed, only %u queues "
1623 "available", num_queue_pairs);
1629 iavf_get_max_rss_queue_region(struct iavf_adapter *adapter)
1631 struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(adapter);
1632 struct iavf_cmd_info args;
1633 uint16_t qregion_width;
1636 args.ops = VIRTCHNL_OP_GET_MAX_RSS_QREGION;
1637 args.in_args = NULL;
1638 args.in_args_size = 0;
1639 args.out_buffer = vf->aq_resp;
1640 args.out_size = IAVF_AQ_BUF_SZ;
1642 err = iavf_execute_vf_cmd(adapter, &args);
1644 PMD_DRV_LOG(ERR, "Failed to execute command of VIRTCHNL_OP_GET_MAX_RSS_QREGION");
1649 ((struct virtchnl_max_rss_qregion *)args.out_buffer)->qregion_width;
1651 vf->max_rss_qregion = (uint16_t)(1 << qregion_width);