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 200
28 #define ASQ_DELAY_MS 10
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)
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 iavf_msec_delay(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 iavf_msec_delay(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 iavf_msec_delay(ASQ_DELAY_MS);
229 /* If don't read msg or read sys event, continue */
230 } while (i++ < MAX_TRY_TIMES);
232 if (i >= MAX_TRY_TIMES) {
233 PMD_DRV_LOG(ERR, "No response for cmd %d", args->ops);
236 } else if (vf->cmd_retval ==
237 VIRTCHNL_STATUS_ERR_NOT_SUPPORTED) {
238 PMD_DRV_LOG(ERR, "Cmd %d not supported", args->ops);
240 } else if (vf->cmd_retval != VIRTCHNL_STATUS_SUCCESS) {
241 PMD_DRV_LOG(ERR, "Return failure %d for cmd %d",
242 vf->cmd_retval, args->ops);
252 iavf_handle_pf_event_msg(struct rte_eth_dev *dev, uint8_t *msg,
255 struct virtchnl_pf_event *pf_msg =
256 (struct virtchnl_pf_event *)msg;
257 struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(dev->data->dev_private);
259 if (msglen < sizeof(struct virtchnl_pf_event)) {
260 PMD_DRV_LOG(DEBUG, "Error event");
263 switch (pf_msg->event) {
264 case VIRTCHNL_EVENT_RESET_IMPENDING:
265 PMD_DRV_LOG(DEBUG, "VIRTCHNL_EVENT_RESET_IMPENDING event");
267 rte_eth_dev_callback_process(dev, RTE_ETH_EVENT_INTR_RESET,
270 case VIRTCHNL_EVENT_LINK_CHANGE:
271 PMD_DRV_LOG(DEBUG, "VIRTCHNL_EVENT_LINK_CHANGE event");
272 vf->link_up = pf_msg->event_data.link_event.link_status;
273 if (vf->vf_res->vf_cap_flags & VIRTCHNL_VF_CAP_ADV_LINK_SPEED) {
275 pf_msg->event_data.link_event_adv.link_speed;
277 enum virtchnl_link_speed speed;
278 speed = pf_msg->event_data.link_event.link_speed;
279 vf->link_speed = iavf_convert_link_speed(speed);
281 iavf_dev_link_update(dev, 0);
282 rte_eth_dev_callback_process(dev, RTE_ETH_EVENT_INTR_LSC, NULL);
284 case VIRTCHNL_EVENT_PF_DRIVER_CLOSE:
285 PMD_DRV_LOG(DEBUG, "VIRTCHNL_EVENT_PF_DRIVER_CLOSE event");
288 PMD_DRV_LOG(ERR, " unknown event received %u", pf_msg->event);
294 iavf_handle_virtchnl_msg(struct rte_eth_dev *dev)
296 struct iavf_hw *hw = IAVF_DEV_PRIVATE_TO_HW(dev->data->dev_private);
297 struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(dev->data->dev_private);
298 struct iavf_arq_event_info info;
299 uint16_t pending, aq_opc;
300 enum virtchnl_ops msg_opc;
301 enum iavf_status msg_ret;
304 info.buf_len = IAVF_AQ_BUF_SZ;
306 PMD_DRV_LOG(ERR, "Buffer for adminq resp should not be NULL");
309 info.msg_buf = vf->aq_resp;
313 ret = iavf_clean_arq_element(hw, &info, &pending);
315 if (ret != IAVF_SUCCESS) {
316 PMD_DRV_LOG(INFO, "Failed to read msg from AdminQ,"
320 aq_opc = rte_le_to_cpu_16(info.desc.opcode);
321 /* For the message sent from pf to vf, opcode is stored in
322 * cookie_high of struct iavf_aq_desc, while return error code
323 * are stored in cookie_low, Which is done by PF driver.
325 msg_opc = (enum virtchnl_ops)rte_le_to_cpu_32(
326 info.desc.cookie_high);
327 msg_ret = (enum iavf_status)rte_le_to_cpu_32(
328 info.desc.cookie_low);
330 case iavf_aqc_opc_send_msg_to_vf:
331 if (msg_opc == VIRTCHNL_OP_EVENT) {
332 iavf_handle_pf_event_msg(dev, info.msg_buf,
335 /* read message and it's expected one */
336 if (msg_opc == vf->pend_cmd)
337 _notify_cmd(vf, msg_ret);
339 PMD_DRV_LOG(ERR, "command mismatch,"
341 vf->pend_cmd, msg_opc);
343 "adminq response is received,"
344 " opcode = %d", msg_opc);
348 PMD_DRV_LOG(DEBUG, "Request %u is not supported yet",
356 iavf_enable_vlan_strip(struct iavf_adapter *adapter)
358 struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(adapter);
359 struct iavf_cmd_info args;
362 memset(&args, 0, sizeof(args));
363 args.ops = VIRTCHNL_OP_ENABLE_VLAN_STRIPPING;
365 args.in_args_size = 0;
366 args.out_buffer = vf->aq_resp;
367 args.out_size = IAVF_AQ_BUF_SZ;
368 ret = iavf_execute_vf_cmd(adapter, &args);
370 PMD_DRV_LOG(ERR, "Failed to execute command of"
371 " OP_ENABLE_VLAN_STRIPPING");
377 iavf_disable_vlan_strip(struct iavf_adapter *adapter)
379 struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(adapter);
380 struct iavf_cmd_info args;
383 memset(&args, 0, sizeof(args));
384 args.ops = VIRTCHNL_OP_DISABLE_VLAN_STRIPPING;
386 args.in_args_size = 0;
387 args.out_buffer = vf->aq_resp;
388 args.out_size = IAVF_AQ_BUF_SZ;
389 ret = iavf_execute_vf_cmd(adapter, &args);
391 PMD_DRV_LOG(ERR, "Failed to execute command of"
392 " OP_DISABLE_VLAN_STRIPPING");
397 #define VIRTCHNL_VERSION_MAJOR_START 1
398 #define VIRTCHNL_VERSION_MINOR_START 1
400 /* Check API version with sync wait until version read from admin queue */
402 iavf_check_api_version(struct iavf_adapter *adapter)
404 struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(adapter);
405 struct virtchnl_version_info version, *pver;
406 struct iavf_cmd_info args;
409 version.major = VIRTCHNL_VERSION_MAJOR;
410 version.minor = VIRTCHNL_VERSION_MINOR;
412 args.ops = VIRTCHNL_OP_VERSION;
413 args.in_args = (uint8_t *)&version;
414 args.in_args_size = sizeof(version);
415 args.out_buffer = vf->aq_resp;
416 args.out_size = IAVF_AQ_BUF_SZ;
418 err = iavf_execute_vf_cmd(adapter, &args);
420 PMD_INIT_LOG(ERR, "Fail to execute command of OP_VERSION");
424 pver = (struct virtchnl_version_info *)args.out_buffer;
425 vf->virtchnl_version = *pver;
427 if (vf->virtchnl_version.major < VIRTCHNL_VERSION_MAJOR_START ||
428 (vf->virtchnl_version.major == VIRTCHNL_VERSION_MAJOR_START &&
429 vf->virtchnl_version.minor < VIRTCHNL_VERSION_MINOR_START)) {
430 PMD_INIT_LOG(ERR, "VIRTCHNL API version should not be lower"
431 " than (%u.%u) to support Adapative VF",
432 VIRTCHNL_VERSION_MAJOR_START,
433 VIRTCHNL_VERSION_MAJOR_START);
435 } else if (vf->virtchnl_version.major > VIRTCHNL_VERSION_MAJOR ||
436 (vf->virtchnl_version.major == VIRTCHNL_VERSION_MAJOR &&
437 vf->virtchnl_version.minor > VIRTCHNL_VERSION_MINOR)) {
438 PMD_INIT_LOG(ERR, "PF/VF API version mismatch:(%u.%u)-(%u.%u)",
439 vf->virtchnl_version.major,
440 vf->virtchnl_version.minor,
441 VIRTCHNL_VERSION_MAJOR,
442 VIRTCHNL_VERSION_MINOR);
446 PMD_DRV_LOG(DEBUG, "Peer is supported PF host");
451 iavf_get_vf_resource(struct iavf_adapter *adapter)
453 struct iavf_hw *hw = IAVF_DEV_PRIVATE_TO_HW(adapter);
454 struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(adapter);
455 struct iavf_cmd_info args;
459 args.ops = VIRTCHNL_OP_GET_VF_RESOURCES;
460 args.out_buffer = vf->aq_resp;
461 args.out_size = IAVF_AQ_BUF_SZ;
463 caps = IAVF_BASIC_OFFLOAD_CAPS | VIRTCHNL_VF_CAP_ADV_LINK_SPEED |
464 VIRTCHNL_VF_OFFLOAD_RX_FLEX_DESC |
465 VIRTCHNL_VF_OFFLOAD_FDIR_PF |
466 VIRTCHNL_VF_OFFLOAD_ADV_RSS_PF |
467 VIRTCHNL_VF_OFFLOAD_REQ_QUEUES |
468 VIRTCHNL_VF_OFFLOAD_CRC |
469 VIRTCHNL_VF_OFFLOAD_VLAN_V2 |
470 VIRTCHNL_VF_LARGE_NUM_QPAIRS |
471 VIRTCHNL_VF_OFFLOAD_QOS;
473 args.in_args = (uint8_t *)∩︀
474 args.in_args_size = sizeof(caps);
476 err = iavf_execute_vf_cmd(adapter, &args);
480 "Failed to execute command of OP_GET_VF_RESOURCE");
484 len = sizeof(struct virtchnl_vf_resource) +
485 IAVF_MAX_VF_VSI * sizeof(struct virtchnl_vsi_resource);
487 rte_memcpy(vf->vf_res, args.out_buffer,
488 RTE_MIN(args.out_size, len));
489 /* parse VF config message back from PF*/
490 iavf_vf_parse_hw_config(hw, vf->vf_res);
491 for (i = 0; i < vf->vf_res->num_vsis; i++) {
492 if (vf->vf_res->vsi_res[i].vsi_type == VIRTCHNL_VSI_SRIOV)
493 vf->vsi_res = &vf->vf_res->vsi_res[i];
497 PMD_INIT_LOG(ERR, "no LAN VSI found");
501 vf->vsi.vsi_id = vf->vsi_res->vsi_id;
502 vf->vsi.nb_qps = vf->vsi_res->num_queue_pairs;
503 vf->vsi.adapter = adapter;
509 iavf_get_supported_rxdid(struct iavf_adapter *adapter)
511 struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(adapter);
512 struct iavf_cmd_info args;
515 args.ops = VIRTCHNL_OP_GET_SUPPORTED_RXDIDS;
517 args.in_args_size = 0;
518 args.out_buffer = vf->aq_resp;
519 args.out_size = IAVF_AQ_BUF_SZ;
521 ret = iavf_execute_vf_cmd(adapter, &args);
524 "Failed to execute command of OP_GET_SUPPORTED_RXDIDS");
528 vf->supported_rxdid =
529 ((struct virtchnl_supported_rxdids *)args.out_buffer)->supported_rxdids;
535 iavf_config_vlan_strip_v2(struct iavf_adapter *adapter, bool enable)
537 struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(adapter);
538 struct virtchnl_vlan_supported_caps *stripping_caps;
539 struct virtchnl_vlan_setting vlan_strip;
540 struct iavf_cmd_info args;
544 stripping_caps = &vf->vlan_v2_caps.offloads.stripping_support;
546 if ((stripping_caps->outer & VIRTCHNL_VLAN_ETHERTYPE_8100) &&
547 (stripping_caps->outer & VIRTCHNL_VLAN_TOGGLE))
548 ethertype = &vlan_strip.outer_ethertype_setting;
549 else if ((stripping_caps->inner & VIRTCHNL_VLAN_ETHERTYPE_8100) &&
550 (stripping_caps->inner & VIRTCHNL_VLAN_TOGGLE))
551 ethertype = &vlan_strip.inner_ethertype_setting;
555 memset(&vlan_strip, 0, sizeof(vlan_strip));
556 vlan_strip.vport_id = vf->vsi_res->vsi_id;
557 *ethertype = VIRTCHNL_VLAN_ETHERTYPE_8100;
559 args.ops = enable ? VIRTCHNL_OP_ENABLE_VLAN_STRIPPING_V2 :
560 VIRTCHNL_OP_DISABLE_VLAN_STRIPPING_V2;
561 args.in_args = (uint8_t *)&vlan_strip;
562 args.in_args_size = sizeof(vlan_strip);
563 args.out_buffer = vf->aq_resp;
564 args.out_size = IAVF_AQ_BUF_SZ;
565 ret = iavf_execute_vf_cmd(adapter, &args);
567 PMD_DRV_LOG(ERR, "fail to execute command %s",
568 enable ? "VIRTCHNL_OP_ENABLE_VLAN_STRIPPING_V2" :
569 "VIRTCHNL_OP_DISABLE_VLAN_STRIPPING_V2");
575 iavf_config_vlan_insert_v2(struct iavf_adapter *adapter, bool enable)
577 struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(adapter);
578 struct virtchnl_vlan_supported_caps *insertion_caps;
579 struct virtchnl_vlan_setting vlan_insert;
580 struct iavf_cmd_info args;
584 insertion_caps = &vf->vlan_v2_caps.offloads.insertion_support;
586 if ((insertion_caps->outer & VIRTCHNL_VLAN_ETHERTYPE_8100) &&
587 (insertion_caps->outer & VIRTCHNL_VLAN_TOGGLE))
588 ethertype = &vlan_insert.outer_ethertype_setting;
589 else if ((insertion_caps->inner & VIRTCHNL_VLAN_ETHERTYPE_8100) &&
590 (insertion_caps->inner & VIRTCHNL_VLAN_TOGGLE))
591 ethertype = &vlan_insert.inner_ethertype_setting;
595 memset(&vlan_insert, 0, sizeof(vlan_insert));
596 vlan_insert.vport_id = vf->vsi_res->vsi_id;
597 *ethertype = VIRTCHNL_VLAN_ETHERTYPE_8100;
599 args.ops = enable ? VIRTCHNL_OP_ENABLE_VLAN_INSERTION_V2 :
600 VIRTCHNL_OP_DISABLE_VLAN_INSERTION_V2;
601 args.in_args = (uint8_t *)&vlan_insert;
602 args.in_args_size = sizeof(vlan_insert);
603 args.out_buffer = vf->aq_resp;
604 args.out_size = IAVF_AQ_BUF_SZ;
605 ret = iavf_execute_vf_cmd(adapter, &args);
607 PMD_DRV_LOG(ERR, "fail to execute command %s",
608 enable ? "VIRTCHNL_OP_ENABLE_VLAN_INSERTION_V2" :
609 "VIRTCHNL_OP_DISABLE_VLAN_INSERTION_V2");
615 iavf_add_del_vlan_v2(struct iavf_adapter *adapter, uint16_t vlanid, bool add)
617 struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(adapter);
618 struct virtchnl_vlan_supported_caps *supported_caps;
619 struct virtchnl_vlan_filter_list_v2 vlan_filter;
620 struct virtchnl_vlan *vlan_setting;
621 struct iavf_cmd_info args;
622 uint32_t filtering_caps;
625 supported_caps = &vf->vlan_v2_caps.filtering.filtering_support;
626 if (supported_caps->outer) {
627 filtering_caps = supported_caps->outer;
628 vlan_setting = &vlan_filter.filters[0].outer;
630 filtering_caps = supported_caps->inner;
631 vlan_setting = &vlan_filter.filters[0].inner;
634 if (!(filtering_caps & VIRTCHNL_VLAN_ETHERTYPE_8100))
637 memset(&vlan_filter, 0, sizeof(vlan_filter));
638 vlan_filter.vport_id = vf->vsi_res->vsi_id;
639 vlan_filter.num_elements = 1;
640 vlan_setting->tpid = RTE_ETHER_TYPE_VLAN;
641 vlan_setting->tci = vlanid;
643 args.ops = add ? VIRTCHNL_OP_ADD_VLAN_V2 : VIRTCHNL_OP_DEL_VLAN_V2;
644 args.in_args = (uint8_t *)&vlan_filter;
645 args.in_args_size = sizeof(vlan_filter);
646 args.out_buffer = vf->aq_resp;
647 args.out_size = IAVF_AQ_BUF_SZ;
648 err = iavf_execute_vf_cmd(adapter, &args);
650 PMD_DRV_LOG(ERR, "fail to execute command %s",
651 add ? "OP_ADD_VLAN_V2" : "OP_DEL_VLAN_V2");
657 iavf_get_vlan_offload_caps_v2(struct iavf_adapter *adapter)
659 struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(adapter);
660 struct iavf_cmd_info args;
663 args.ops = VIRTCHNL_OP_GET_OFFLOAD_VLAN_V2_CAPS;
665 args.in_args_size = 0;
666 args.out_buffer = vf->aq_resp;
667 args.out_size = IAVF_AQ_BUF_SZ;
669 ret = iavf_execute_vf_cmd(adapter, &args);
672 "Failed to execute command of VIRTCHNL_OP_GET_OFFLOAD_VLAN_V2_CAPS");
676 rte_memcpy(&vf->vlan_v2_caps, vf->aq_resp, sizeof(vf->vlan_v2_caps));
682 iavf_enable_queues(struct iavf_adapter *adapter)
684 struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(adapter);
685 struct virtchnl_queue_select queue_select;
686 struct iavf_cmd_info args;
689 memset(&queue_select, 0, sizeof(queue_select));
690 queue_select.vsi_id = vf->vsi_res->vsi_id;
692 queue_select.rx_queues = BIT(adapter->dev_data->nb_rx_queues) - 1;
693 queue_select.tx_queues = BIT(adapter->dev_data->nb_tx_queues) - 1;
695 args.ops = VIRTCHNL_OP_ENABLE_QUEUES;
696 args.in_args = (u8 *)&queue_select;
697 args.in_args_size = sizeof(queue_select);
698 args.out_buffer = vf->aq_resp;
699 args.out_size = IAVF_AQ_BUF_SZ;
700 err = iavf_execute_vf_cmd(adapter, &args);
703 "Failed to execute command of OP_ENABLE_QUEUES");
710 iavf_disable_queues(struct iavf_adapter *adapter)
712 struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(adapter);
713 struct virtchnl_queue_select queue_select;
714 struct iavf_cmd_info args;
717 memset(&queue_select, 0, sizeof(queue_select));
718 queue_select.vsi_id = vf->vsi_res->vsi_id;
720 queue_select.rx_queues = BIT(adapter->dev_data->nb_rx_queues) - 1;
721 queue_select.tx_queues = BIT(adapter->dev_data->nb_tx_queues) - 1;
723 args.ops = VIRTCHNL_OP_DISABLE_QUEUES;
724 args.in_args = (u8 *)&queue_select;
725 args.in_args_size = sizeof(queue_select);
726 args.out_buffer = vf->aq_resp;
727 args.out_size = IAVF_AQ_BUF_SZ;
728 err = iavf_execute_vf_cmd(adapter, &args);
731 "Failed to execute command of OP_DISABLE_QUEUES");
738 iavf_switch_queue(struct iavf_adapter *adapter, uint16_t qid,
741 struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(adapter);
742 struct virtchnl_queue_select queue_select;
743 struct iavf_cmd_info args;
746 memset(&queue_select, 0, sizeof(queue_select));
747 queue_select.vsi_id = vf->vsi_res->vsi_id;
749 queue_select.rx_queues |= 1 << qid;
751 queue_select.tx_queues |= 1 << qid;
754 args.ops = VIRTCHNL_OP_ENABLE_QUEUES;
756 args.ops = VIRTCHNL_OP_DISABLE_QUEUES;
757 args.in_args = (u8 *)&queue_select;
758 args.in_args_size = sizeof(queue_select);
759 args.out_buffer = vf->aq_resp;
760 args.out_size = IAVF_AQ_BUF_SZ;
761 err = iavf_execute_vf_cmd(adapter, &args);
763 PMD_DRV_LOG(ERR, "Failed to execute command of %s",
764 on ? "OP_ENABLE_QUEUES" : "OP_DISABLE_QUEUES");
769 iavf_enable_queues_lv(struct iavf_adapter *adapter)
771 struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(adapter);
772 struct virtchnl_del_ena_dis_queues *queue_select;
773 struct virtchnl_queue_chunk *queue_chunk;
774 struct iavf_cmd_info args;
777 len = sizeof(struct virtchnl_del_ena_dis_queues) +
778 sizeof(struct virtchnl_queue_chunk) *
779 (IAVF_RXTX_QUEUE_CHUNKS_NUM - 1);
780 queue_select = rte_zmalloc("queue_select", len, 0);
784 queue_chunk = queue_select->chunks.chunks;
785 queue_select->chunks.num_chunks = IAVF_RXTX_QUEUE_CHUNKS_NUM;
786 queue_select->vport_id = vf->vsi_res->vsi_id;
788 queue_chunk[VIRTCHNL_QUEUE_TYPE_TX].type = VIRTCHNL_QUEUE_TYPE_TX;
789 queue_chunk[VIRTCHNL_QUEUE_TYPE_TX].start_queue_id = 0;
790 queue_chunk[VIRTCHNL_QUEUE_TYPE_TX].num_queues =
791 adapter->dev_data->nb_tx_queues;
793 queue_chunk[VIRTCHNL_QUEUE_TYPE_RX].type = VIRTCHNL_QUEUE_TYPE_RX;
794 queue_chunk[VIRTCHNL_QUEUE_TYPE_RX].start_queue_id = 0;
795 queue_chunk[VIRTCHNL_QUEUE_TYPE_RX].num_queues =
796 adapter->dev_data->nb_rx_queues;
798 args.ops = VIRTCHNL_OP_ENABLE_QUEUES_V2;
799 args.in_args = (u8 *)queue_select;
800 args.in_args_size = len;
801 args.out_buffer = vf->aq_resp;
802 args.out_size = IAVF_AQ_BUF_SZ;
803 err = iavf_execute_vf_cmd(adapter, &args);
806 "Failed to execute command of OP_ENABLE_QUEUES_V2");
808 rte_free(queue_select);
813 iavf_disable_queues_lv(struct iavf_adapter *adapter)
815 struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(adapter);
816 struct virtchnl_del_ena_dis_queues *queue_select;
817 struct virtchnl_queue_chunk *queue_chunk;
818 struct iavf_cmd_info args;
821 len = sizeof(struct virtchnl_del_ena_dis_queues) +
822 sizeof(struct virtchnl_queue_chunk) *
823 (IAVF_RXTX_QUEUE_CHUNKS_NUM - 1);
824 queue_select = rte_zmalloc("queue_select", len, 0);
828 queue_chunk = queue_select->chunks.chunks;
829 queue_select->chunks.num_chunks = IAVF_RXTX_QUEUE_CHUNKS_NUM;
830 queue_select->vport_id = vf->vsi_res->vsi_id;
832 queue_chunk[VIRTCHNL_QUEUE_TYPE_TX].type = VIRTCHNL_QUEUE_TYPE_TX;
833 queue_chunk[VIRTCHNL_QUEUE_TYPE_TX].start_queue_id = 0;
834 queue_chunk[VIRTCHNL_QUEUE_TYPE_TX].num_queues =
835 adapter->dev_data->nb_tx_queues;
837 queue_chunk[VIRTCHNL_QUEUE_TYPE_RX].type = VIRTCHNL_QUEUE_TYPE_RX;
838 queue_chunk[VIRTCHNL_QUEUE_TYPE_RX].start_queue_id = 0;
839 queue_chunk[VIRTCHNL_QUEUE_TYPE_RX].num_queues =
840 adapter->dev_data->nb_rx_queues;
842 args.ops = VIRTCHNL_OP_DISABLE_QUEUES_V2;
843 args.in_args = (u8 *)queue_select;
844 args.in_args_size = len;
845 args.out_buffer = vf->aq_resp;
846 args.out_size = IAVF_AQ_BUF_SZ;
847 err = iavf_execute_vf_cmd(adapter, &args);
850 "Failed to execute command of OP_DISABLE_QUEUES_V2");
852 rte_free(queue_select);
857 iavf_switch_queue_lv(struct iavf_adapter *adapter, uint16_t qid,
860 struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(adapter);
861 struct virtchnl_del_ena_dis_queues *queue_select;
862 struct virtchnl_queue_chunk *queue_chunk;
863 struct iavf_cmd_info args;
866 len = sizeof(struct virtchnl_del_ena_dis_queues);
867 queue_select = rte_zmalloc("queue_select", len, 0);
871 queue_chunk = queue_select->chunks.chunks;
872 queue_select->chunks.num_chunks = 1;
873 queue_select->vport_id = vf->vsi_res->vsi_id;
876 queue_chunk->type = VIRTCHNL_QUEUE_TYPE_RX;
877 queue_chunk->start_queue_id = qid;
878 queue_chunk->num_queues = 1;
880 queue_chunk->type = VIRTCHNL_QUEUE_TYPE_TX;
881 queue_chunk->start_queue_id = qid;
882 queue_chunk->num_queues = 1;
886 args.ops = VIRTCHNL_OP_ENABLE_QUEUES_V2;
888 args.ops = VIRTCHNL_OP_DISABLE_QUEUES_V2;
889 args.in_args = (u8 *)queue_select;
890 args.in_args_size = len;
891 args.out_buffer = vf->aq_resp;
892 args.out_size = IAVF_AQ_BUF_SZ;
893 err = iavf_execute_vf_cmd(adapter, &args);
895 PMD_DRV_LOG(ERR, "Failed to execute command of %s",
896 on ? "OP_ENABLE_QUEUES_V2" : "OP_DISABLE_QUEUES_V2");
898 rte_free(queue_select);
903 iavf_configure_rss_lut(struct iavf_adapter *adapter)
905 struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(adapter);
906 struct virtchnl_rss_lut *rss_lut;
907 struct iavf_cmd_info args;
910 len = sizeof(*rss_lut) + vf->vf_res->rss_lut_size - 1;
911 rss_lut = rte_zmalloc("rss_lut", len, 0);
915 rss_lut->vsi_id = vf->vsi_res->vsi_id;
916 rss_lut->lut_entries = vf->vf_res->rss_lut_size;
917 rte_memcpy(rss_lut->lut, vf->rss_lut, vf->vf_res->rss_lut_size);
919 args.ops = VIRTCHNL_OP_CONFIG_RSS_LUT;
920 args.in_args = (u8 *)rss_lut;
921 args.in_args_size = len;
922 args.out_buffer = vf->aq_resp;
923 args.out_size = IAVF_AQ_BUF_SZ;
925 err = iavf_execute_vf_cmd(adapter, &args);
928 "Failed to execute command of OP_CONFIG_RSS_LUT");
935 iavf_configure_rss_key(struct iavf_adapter *adapter)
937 struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(adapter);
938 struct virtchnl_rss_key *rss_key;
939 struct iavf_cmd_info args;
942 len = sizeof(*rss_key) + vf->vf_res->rss_key_size - 1;
943 rss_key = rte_zmalloc("rss_key", len, 0);
947 rss_key->vsi_id = vf->vsi_res->vsi_id;
948 rss_key->key_len = vf->vf_res->rss_key_size;
949 rte_memcpy(rss_key->key, vf->rss_key, vf->vf_res->rss_key_size);
951 args.ops = VIRTCHNL_OP_CONFIG_RSS_KEY;
952 args.in_args = (u8 *)rss_key;
953 args.in_args_size = len;
954 args.out_buffer = vf->aq_resp;
955 args.out_size = IAVF_AQ_BUF_SZ;
957 err = iavf_execute_vf_cmd(adapter, &args);
960 "Failed to execute command of OP_CONFIG_RSS_KEY");
967 iavf_configure_queues(struct iavf_adapter *adapter,
968 uint16_t num_queue_pairs, uint16_t index)
970 struct iavf_rx_queue **rxq =
971 (struct iavf_rx_queue **)adapter->dev_data->rx_queues;
972 struct iavf_tx_queue **txq =
973 (struct iavf_tx_queue **)adapter->dev_data->tx_queues;
974 struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(adapter);
975 struct virtchnl_vsi_queue_config_info *vc_config;
976 struct virtchnl_queue_pair_info *vc_qp;
977 struct iavf_cmd_info args;
981 size = sizeof(*vc_config) +
982 sizeof(vc_config->qpair[0]) * num_queue_pairs;
983 vc_config = rte_zmalloc("cfg_queue", size, 0);
987 vc_config->vsi_id = vf->vsi_res->vsi_id;
988 vc_config->num_queue_pairs = num_queue_pairs;
990 for (i = index, vc_qp = vc_config->qpair;
991 i < index + num_queue_pairs;
993 vc_qp->txq.vsi_id = vf->vsi_res->vsi_id;
994 vc_qp->txq.queue_id = i;
996 /* Virtchnnl configure tx queues by pairs */
997 if (i < adapter->dev_data->nb_tx_queues) {
998 vc_qp->txq.ring_len = txq[i]->nb_tx_desc;
999 vc_qp->txq.dma_ring_addr = txq[i]->tx_ring_phys_addr;
1002 vc_qp->rxq.vsi_id = vf->vsi_res->vsi_id;
1003 vc_qp->rxq.queue_id = i;
1004 vc_qp->rxq.max_pkt_size = vf->max_pkt_len;
1006 if (i >= adapter->dev_data->nb_rx_queues)
1009 /* Virtchnnl configure rx queues by pairs */
1010 vc_qp->rxq.ring_len = rxq[i]->nb_rx_desc;
1011 vc_qp->rxq.dma_ring_addr = rxq[i]->rx_ring_phys_addr;
1012 vc_qp->rxq.databuffer_size = rxq[i]->rx_buf_len;
1013 vc_qp->rxq.crc_disable = rxq[i]->crc_len != 0 ? 1 : 0;
1014 #ifndef RTE_LIBRTE_IAVF_16BYTE_RX_DESC
1015 if (vf->vf_res->vf_cap_flags &
1016 VIRTCHNL_VF_OFFLOAD_RX_FLEX_DESC &&
1017 vf->supported_rxdid & BIT(rxq[i]->rxdid)) {
1018 vc_qp->rxq.rxdid = rxq[i]->rxdid;
1019 PMD_DRV_LOG(NOTICE, "request RXDID[%d] in Queue[%d]",
1020 vc_qp->rxq.rxdid, i);
1022 PMD_DRV_LOG(NOTICE, "RXDID[%d] is not supported, "
1023 "request default RXDID[%d] in Queue[%d]",
1024 rxq[i]->rxdid, IAVF_RXDID_LEGACY_1, i);
1025 vc_qp->rxq.rxdid = IAVF_RXDID_LEGACY_1;
1028 if (vf->vf_res->vf_cap_flags &
1029 VIRTCHNL_VF_OFFLOAD_RX_FLEX_DESC &&
1030 vf->supported_rxdid & BIT(IAVF_RXDID_LEGACY_0)) {
1031 vc_qp->rxq.rxdid = IAVF_RXDID_LEGACY_0;
1032 PMD_DRV_LOG(NOTICE, "request RXDID[%d] in Queue[%d]",
1033 vc_qp->rxq.rxdid, i);
1035 PMD_DRV_LOG(ERR, "RXDID[%d] is not supported",
1036 IAVF_RXDID_LEGACY_0);
1042 memset(&args, 0, sizeof(args));
1043 args.ops = VIRTCHNL_OP_CONFIG_VSI_QUEUES;
1044 args.in_args = (uint8_t *)vc_config;
1045 args.in_args_size = size;
1046 args.out_buffer = vf->aq_resp;
1047 args.out_size = IAVF_AQ_BUF_SZ;
1049 err = iavf_execute_vf_cmd(adapter, &args);
1051 PMD_DRV_LOG(ERR, "Failed to execute command of"
1052 " VIRTCHNL_OP_CONFIG_VSI_QUEUES");
1054 rte_free(vc_config);
1059 iavf_config_irq_map(struct iavf_adapter *adapter)
1061 struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(adapter);
1062 struct virtchnl_irq_map_info *map_info;
1063 struct virtchnl_vector_map *vecmap;
1064 struct iavf_cmd_info args;
1067 len = sizeof(struct virtchnl_irq_map_info) +
1068 sizeof(struct virtchnl_vector_map) * vf->nb_msix;
1070 map_info = rte_zmalloc("map_info", len, 0);
1074 map_info->num_vectors = vf->nb_msix;
1075 for (i = 0; i < adapter->dev_data->nb_rx_queues; i++) {
1077 &map_info->vecmap[vf->qv_map[i].vector_id - vf->msix_base];
1078 vecmap->vsi_id = vf->vsi_res->vsi_id;
1079 vecmap->rxitr_idx = IAVF_ITR_INDEX_DEFAULT;
1080 vecmap->vector_id = vf->qv_map[i].vector_id;
1081 vecmap->txq_map = 0;
1082 vecmap->rxq_map |= 1 << vf->qv_map[i].queue_id;
1085 args.ops = VIRTCHNL_OP_CONFIG_IRQ_MAP;
1086 args.in_args = (u8 *)map_info;
1087 args.in_args_size = len;
1088 args.out_buffer = vf->aq_resp;
1089 args.out_size = IAVF_AQ_BUF_SZ;
1090 err = iavf_execute_vf_cmd(adapter, &args);
1092 PMD_DRV_LOG(ERR, "fail to execute command OP_CONFIG_IRQ_MAP");
1099 iavf_config_irq_map_lv(struct iavf_adapter *adapter, uint16_t num,
1102 struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(adapter);
1103 struct virtchnl_queue_vector_maps *map_info;
1104 struct virtchnl_queue_vector *qv_maps;
1105 struct iavf_cmd_info args;
1109 len = sizeof(struct virtchnl_queue_vector_maps) +
1110 sizeof(struct virtchnl_queue_vector) * (num - 1);
1112 map_info = rte_zmalloc("map_info", len, 0);
1116 map_info->vport_id = vf->vsi_res->vsi_id;
1117 map_info->num_qv_maps = num;
1118 for (i = index; i < index + map_info->num_qv_maps; i++) {
1119 qv_maps = &map_info->qv_maps[count++];
1120 qv_maps->itr_idx = VIRTCHNL_ITR_IDX_0;
1121 qv_maps->queue_type = VIRTCHNL_QUEUE_TYPE_RX;
1122 qv_maps->queue_id = vf->qv_map[i].queue_id;
1123 qv_maps->vector_id = vf->qv_map[i].vector_id;
1126 args.ops = VIRTCHNL_OP_MAP_QUEUE_VECTOR;
1127 args.in_args = (u8 *)map_info;
1128 args.in_args_size = len;
1129 args.out_buffer = vf->aq_resp;
1130 args.out_size = IAVF_AQ_BUF_SZ;
1131 err = iavf_execute_vf_cmd(adapter, &args);
1133 PMD_DRV_LOG(ERR, "fail to execute command OP_MAP_QUEUE_VECTOR");
1140 iavf_add_del_all_mac_addr(struct iavf_adapter *adapter, bool add)
1142 struct virtchnl_ether_addr_list *list;
1143 struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(adapter);
1144 struct rte_ether_addr *addr;
1145 struct iavf_cmd_info args;
1152 len = sizeof(struct virtchnl_ether_addr_list);
1153 for (i = begin; i < IAVF_NUM_MACADDR_MAX; i++, next_begin++) {
1154 addr = &adapter->dev_data->mac_addrs[i];
1155 if (rte_is_zero_ether_addr(addr))
1157 len += sizeof(struct virtchnl_ether_addr);
1158 if (len >= IAVF_AQ_BUF_SZ) {
1164 list = rte_zmalloc("iavf_del_mac_buffer", len, 0);
1166 PMD_DRV_LOG(ERR, "fail to allocate memory");
1170 for (i = begin; i < next_begin; i++) {
1171 addr = &adapter->dev_data->mac_addrs[i];
1172 if (rte_is_zero_ether_addr(addr))
1174 rte_memcpy(list->list[j].addr, addr->addr_bytes,
1175 sizeof(addr->addr_bytes));
1176 list->list[j].type = (j == 0 ?
1177 VIRTCHNL_ETHER_ADDR_PRIMARY :
1178 VIRTCHNL_ETHER_ADDR_EXTRA);
1179 PMD_DRV_LOG(DEBUG, "add/rm mac:" RTE_ETHER_ADDR_PRT_FMT,
1180 RTE_ETHER_ADDR_BYTES(addr));
1183 list->vsi_id = vf->vsi_res->vsi_id;
1184 list->num_elements = j;
1185 args.ops = add ? VIRTCHNL_OP_ADD_ETH_ADDR :
1186 VIRTCHNL_OP_DEL_ETH_ADDR;
1187 args.in_args = (uint8_t *)list;
1188 args.in_args_size = len;
1189 args.out_buffer = vf->aq_resp;
1190 args.out_size = IAVF_AQ_BUF_SZ;
1191 err = iavf_execute_vf_cmd(adapter, &args);
1193 PMD_DRV_LOG(ERR, "fail to execute command %s",
1194 add ? "OP_ADD_ETHER_ADDRESS" :
1195 "OP_DEL_ETHER_ADDRESS");
1198 } while (begin < IAVF_NUM_MACADDR_MAX);
1202 iavf_query_stats(struct iavf_adapter *adapter,
1203 struct virtchnl_eth_stats **pstats)
1205 struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(adapter);
1206 struct virtchnl_queue_select q_stats;
1207 struct iavf_cmd_info args;
1210 memset(&q_stats, 0, sizeof(q_stats));
1211 q_stats.vsi_id = vf->vsi_res->vsi_id;
1212 args.ops = VIRTCHNL_OP_GET_STATS;
1213 args.in_args = (uint8_t *)&q_stats;
1214 args.in_args_size = sizeof(q_stats);
1215 args.out_buffer = vf->aq_resp;
1216 args.out_size = IAVF_AQ_BUF_SZ;
1218 err = iavf_execute_vf_cmd(adapter, &args);
1220 PMD_DRV_LOG(ERR, "fail to execute command OP_GET_STATS");
1224 *pstats = (struct virtchnl_eth_stats *)args.out_buffer;
1229 iavf_config_promisc(struct iavf_adapter *adapter,
1230 bool enable_unicast,
1231 bool enable_multicast)
1233 struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(adapter);
1234 struct virtchnl_promisc_info promisc;
1235 struct iavf_cmd_info args;
1239 promisc.vsi_id = vf->vsi_res->vsi_id;
1242 promisc.flags |= FLAG_VF_UNICAST_PROMISC;
1244 if (enable_multicast)
1245 promisc.flags |= FLAG_VF_MULTICAST_PROMISC;
1247 args.ops = VIRTCHNL_OP_CONFIG_PROMISCUOUS_MODE;
1248 args.in_args = (uint8_t *)&promisc;
1249 args.in_args_size = sizeof(promisc);
1250 args.out_buffer = vf->aq_resp;
1251 args.out_size = IAVF_AQ_BUF_SZ;
1253 err = iavf_execute_vf_cmd(adapter, &args);
1257 "fail to execute command CONFIG_PROMISCUOUS_MODE");
1259 if (err == -ENOTSUP)
1265 vf->promisc_unicast_enabled = enable_unicast;
1266 vf->promisc_multicast_enabled = enable_multicast;
1271 iavf_add_del_eth_addr(struct iavf_adapter *adapter, struct rte_ether_addr *addr,
1272 bool add, uint8_t type)
1274 struct virtchnl_ether_addr_list *list;
1275 struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(adapter);
1276 uint8_t cmd_buffer[sizeof(struct virtchnl_ether_addr_list) +
1277 sizeof(struct virtchnl_ether_addr)];
1278 struct iavf_cmd_info args;
1281 list = (struct virtchnl_ether_addr_list *)cmd_buffer;
1282 list->vsi_id = vf->vsi_res->vsi_id;
1283 list->num_elements = 1;
1284 list->list[0].type = type;
1285 rte_memcpy(list->list[0].addr, addr->addr_bytes,
1286 sizeof(addr->addr_bytes));
1288 args.ops = add ? VIRTCHNL_OP_ADD_ETH_ADDR : VIRTCHNL_OP_DEL_ETH_ADDR;
1289 args.in_args = cmd_buffer;
1290 args.in_args_size = sizeof(cmd_buffer);
1291 args.out_buffer = vf->aq_resp;
1292 args.out_size = IAVF_AQ_BUF_SZ;
1293 err = iavf_execute_vf_cmd(adapter, &args);
1295 PMD_DRV_LOG(ERR, "fail to execute command %s",
1296 add ? "OP_ADD_ETH_ADDR" : "OP_DEL_ETH_ADDR");
1301 iavf_add_del_vlan(struct iavf_adapter *adapter, uint16_t vlanid, bool add)
1303 struct virtchnl_vlan_filter_list *vlan_list;
1304 struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(adapter);
1305 uint8_t cmd_buffer[sizeof(struct virtchnl_vlan_filter_list) +
1307 struct iavf_cmd_info args;
1310 vlan_list = (struct virtchnl_vlan_filter_list *)cmd_buffer;
1311 vlan_list->vsi_id = vf->vsi_res->vsi_id;
1312 vlan_list->num_elements = 1;
1313 vlan_list->vlan_id[0] = vlanid;
1315 args.ops = add ? VIRTCHNL_OP_ADD_VLAN : VIRTCHNL_OP_DEL_VLAN;
1316 args.in_args = cmd_buffer;
1317 args.in_args_size = sizeof(cmd_buffer);
1318 args.out_buffer = vf->aq_resp;
1319 args.out_size = IAVF_AQ_BUF_SZ;
1320 err = iavf_execute_vf_cmd(adapter, &args);
1322 PMD_DRV_LOG(ERR, "fail to execute command %s",
1323 add ? "OP_ADD_VLAN" : "OP_DEL_VLAN");
1329 iavf_fdir_add(struct iavf_adapter *adapter,
1330 struct iavf_fdir_conf *filter)
1332 struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(adapter);
1333 struct virtchnl_fdir_add *fdir_ret;
1335 struct iavf_cmd_info args;
1338 filter->add_fltr.vsi_id = vf->vsi_res->vsi_id;
1339 filter->add_fltr.validate_only = 0;
1341 args.ops = VIRTCHNL_OP_ADD_FDIR_FILTER;
1342 args.in_args = (uint8_t *)(&filter->add_fltr);
1343 args.in_args_size = sizeof(*(&filter->add_fltr));
1344 args.out_buffer = vf->aq_resp;
1345 args.out_size = IAVF_AQ_BUF_SZ;
1347 err = iavf_execute_vf_cmd(adapter, &args);
1349 PMD_DRV_LOG(ERR, "fail to execute command OP_ADD_FDIR_FILTER");
1353 fdir_ret = (struct virtchnl_fdir_add *)args.out_buffer;
1354 filter->flow_id = fdir_ret->flow_id;
1356 if (fdir_ret->status == VIRTCHNL_FDIR_SUCCESS) {
1358 "Succeed in adding rule request by PF");
1359 } else if (fdir_ret->status == VIRTCHNL_FDIR_FAILURE_RULE_NORESOURCE) {
1361 "Failed to add rule request due to no hw resource");
1363 } else if (fdir_ret->status == VIRTCHNL_FDIR_FAILURE_RULE_EXIST) {
1365 "Failed to add rule request due to the rule is already existed");
1367 } else if (fdir_ret->status == VIRTCHNL_FDIR_FAILURE_RULE_CONFLICT) {
1369 "Failed to add rule request due to the rule is conflict with existing rule");
1371 } else if (fdir_ret->status == VIRTCHNL_FDIR_FAILURE_RULE_INVALID) {
1373 "Failed to add rule request due to the hw doesn't support");
1375 } else if (fdir_ret->status == VIRTCHNL_FDIR_FAILURE_RULE_TIMEOUT) {
1377 "Failed to add rule request due to time out for programming");
1381 "Failed to add rule request due to other reasons");
1389 iavf_fdir_del(struct iavf_adapter *adapter,
1390 struct iavf_fdir_conf *filter)
1392 struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(adapter);
1393 struct virtchnl_fdir_del *fdir_ret;
1395 struct iavf_cmd_info args;
1398 filter->del_fltr.vsi_id = vf->vsi_res->vsi_id;
1399 filter->del_fltr.flow_id = filter->flow_id;
1401 args.ops = VIRTCHNL_OP_DEL_FDIR_FILTER;
1402 args.in_args = (uint8_t *)(&filter->del_fltr);
1403 args.in_args_size = sizeof(filter->del_fltr);
1404 args.out_buffer = vf->aq_resp;
1405 args.out_size = IAVF_AQ_BUF_SZ;
1407 err = iavf_execute_vf_cmd(adapter, &args);
1409 PMD_DRV_LOG(ERR, "fail to execute command OP_DEL_FDIR_FILTER");
1413 fdir_ret = (struct virtchnl_fdir_del *)args.out_buffer;
1415 if (fdir_ret->status == VIRTCHNL_FDIR_SUCCESS) {
1417 "Succeed in deleting rule request by PF");
1418 } else if (fdir_ret->status == VIRTCHNL_FDIR_FAILURE_RULE_NONEXIST) {
1420 "Failed to delete rule request due to this rule doesn't exist");
1422 } else if (fdir_ret->status == VIRTCHNL_FDIR_FAILURE_RULE_TIMEOUT) {
1424 "Failed to delete rule request due to time out for programming");
1428 "Failed to delete rule request due to other reasons");
1436 iavf_fdir_check(struct iavf_adapter *adapter,
1437 struct iavf_fdir_conf *filter)
1439 struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(adapter);
1440 struct virtchnl_fdir_add *fdir_ret;
1442 struct iavf_cmd_info args;
1445 filter->add_fltr.vsi_id = vf->vsi_res->vsi_id;
1446 filter->add_fltr.validate_only = 1;
1448 args.ops = VIRTCHNL_OP_ADD_FDIR_FILTER;
1449 args.in_args = (uint8_t *)(&filter->add_fltr);
1450 args.in_args_size = sizeof(*(&filter->add_fltr));
1451 args.out_buffer = vf->aq_resp;
1452 args.out_size = IAVF_AQ_BUF_SZ;
1454 err = iavf_execute_vf_cmd(adapter, &args);
1456 PMD_DRV_LOG(ERR, "fail to check flow direcotor rule");
1460 fdir_ret = (struct virtchnl_fdir_add *)args.out_buffer;
1462 if (fdir_ret->status == VIRTCHNL_FDIR_SUCCESS) {
1464 "Succeed in checking rule request by PF");
1465 } else if (fdir_ret->status == VIRTCHNL_FDIR_FAILURE_RULE_INVALID) {
1467 "Failed to check rule request due to parameters validation"
1468 " or HW doesn't support");
1472 "Failed to check rule request due to other reasons");
1480 iavf_add_del_rss_cfg(struct iavf_adapter *adapter,
1481 struct virtchnl_rss_cfg *rss_cfg, bool add)
1483 struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(adapter);
1484 struct iavf_cmd_info args;
1487 memset(&args, 0, sizeof(args));
1488 args.ops = add ? VIRTCHNL_OP_ADD_RSS_CFG :
1489 VIRTCHNL_OP_DEL_RSS_CFG;
1490 args.in_args = (u8 *)rss_cfg;
1491 args.in_args_size = sizeof(*rss_cfg);
1492 args.out_buffer = vf->aq_resp;
1493 args.out_size = IAVF_AQ_BUF_SZ;
1495 err = iavf_execute_vf_cmd(adapter, &args);
1498 "Failed to execute command of %s",
1499 add ? "OP_ADD_RSS_CFG" :
1500 "OP_DEL_RSS_INPUT_CFG");
1506 iavf_get_hena_caps(struct iavf_adapter *adapter, uint64_t *caps)
1508 struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(adapter);
1509 struct iavf_cmd_info args;
1512 args.ops = VIRTCHNL_OP_GET_RSS_HENA_CAPS;
1513 args.in_args = NULL;
1514 args.in_args_size = 0;
1515 args.out_buffer = vf->aq_resp;
1516 args.out_size = IAVF_AQ_BUF_SZ;
1518 err = iavf_execute_vf_cmd(adapter, &args);
1521 "Failed to execute command of OP_GET_RSS_HENA_CAPS");
1525 *caps = ((struct virtchnl_rss_hena *)args.out_buffer)->hena;
1530 iavf_set_hena(struct iavf_adapter *adapter, uint64_t hena)
1532 struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(adapter);
1533 struct virtchnl_rss_hena vrh;
1534 struct iavf_cmd_info args;
1538 args.ops = VIRTCHNL_OP_SET_RSS_HENA;
1539 args.in_args = (u8 *)&vrh;
1540 args.in_args_size = sizeof(vrh);
1541 args.out_buffer = vf->aq_resp;
1542 args.out_size = IAVF_AQ_BUF_SZ;
1544 err = iavf_execute_vf_cmd(adapter, &args);
1547 "Failed to execute command of OP_SET_RSS_HENA");
1553 iavf_get_qos_cap(struct iavf_adapter *adapter)
1555 struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(adapter);
1556 struct iavf_cmd_info args;
1560 args.ops = VIRTCHNL_OP_GET_QOS_CAPS;
1561 args.in_args = NULL;
1562 args.in_args_size = 0;
1563 args.out_buffer = vf->aq_resp;
1564 args.out_size = IAVF_AQ_BUF_SZ;
1565 err = iavf_execute_vf_cmd(adapter, &args);
1569 "Failed to execute command of OP_GET_VF_RESOURCE");
1573 len = sizeof(struct virtchnl_qos_cap_list) +
1574 IAVF_MAX_TRAFFIC_CLASS * sizeof(struct virtchnl_qos_cap_elem);
1576 rte_memcpy(vf->qos_cap, args.out_buffer,
1577 RTE_MIN(args.out_size, len));
1582 int iavf_set_q_tc_map(struct rte_eth_dev *dev,
1583 struct virtchnl_queue_tc_mapping *q_tc_mapping, uint16_t size)
1585 struct iavf_adapter *adapter =
1586 IAVF_DEV_PRIVATE_TO_ADAPTER(dev->data->dev_private);
1587 struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(dev->data->dev_private);
1588 struct iavf_cmd_info args;
1591 memset(&args, 0, sizeof(args));
1592 args.ops = VIRTCHNL_OP_CONFIG_QUEUE_TC_MAP;
1593 args.in_args = (uint8_t *)q_tc_mapping;
1594 args.in_args_size = size;
1595 args.out_buffer = vf->aq_resp;
1596 args.out_size = IAVF_AQ_BUF_SZ;
1598 err = iavf_execute_vf_cmd(adapter, &args);
1600 PMD_DRV_LOG(ERR, "Failed to execute command of"
1601 " VIRTCHNL_OP_CONFIG_TC_MAP");
1606 iavf_add_del_mc_addr_list(struct iavf_adapter *adapter,
1607 struct rte_ether_addr *mc_addrs,
1608 uint32_t mc_addrs_num, bool add)
1610 struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(adapter);
1611 uint8_t cmd_buffer[sizeof(struct virtchnl_ether_addr_list) +
1612 (IAVF_NUM_MACADDR_MAX * sizeof(struct virtchnl_ether_addr))];
1613 struct virtchnl_ether_addr_list *list;
1614 struct iavf_cmd_info args;
1618 if (mc_addrs == NULL || mc_addrs_num == 0)
1621 list = (struct virtchnl_ether_addr_list *)cmd_buffer;
1622 list->vsi_id = vf->vsi_res->vsi_id;
1623 list->num_elements = mc_addrs_num;
1625 for (i = 0; i < mc_addrs_num; i++) {
1626 if (!IAVF_IS_MULTICAST(mc_addrs[i].addr_bytes)) {
1627 PMD_DRV_LOG(ERR, "Invalid mac:" RTE_ETHER_ADDR_PRT_FMT,
1628 RTE_ETHER_ADDR_BYTES(&mc_addrs[i]));
1632 memcpy(list->list[i].addr, mc_addrs[i].addr_bytes,
1633 sizeof(list->list[i].addr));
1634 list->list[i].type = VIRTCHNL_ETHER_ADDR_EXTRA;
1637 args.ops = add ? VIRTCHNL_OP_ADD_ETH_ADDR : VIRTCHNL_OP_DEL_ETH_ADDR;
1638 args.in_args = cmd_buffer;
1639 args.in_args_size = sizeof(struct virtchnl_ether_addr_list) +
1640 i * sizeof(struct virtchnl_ether_addr);
1641 args.out_buffer = vf->aq_resp;
1642 args.out_size = IAVF_AQ_BUF_SZ;
1643 err = iavf_execute_vf_cmd(adapter, &args);
1646 PMD_DRV_LOG(ERR, "fail to execute command %s",
1647 add ? "OP_ADD_ETH_ADDR" : "OP_DEL_ETH_ADDR");
1655 iavf_request_queues(struct rte_eth_dev *dev, uint16_t num)
1657 struct iavf_adapter *adapter =
1658 IAVF_DEV_PRIVATE_TO_ADAPTER(dev->data->dev_private);
1659 struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(adapter);
1660 struct rte_pci_device *pci_dev = RTE_ETH_DEV_TO_PCI(dev);
1661 struct virtchnl_vf_res_request vfres;
1662 struct iavf_cmd_info args;
1663 uint16_t num_queue_pairs;
1666 if (!(vf->vf_res->vf_cap_flags &
1667 VIRTCHNL_VF_OFFLOAD_REQ_QUEUES)) {
1668 PMD_DRV_LOG(ERR, "request queues not supported");
1673 PMD_DRV_LOG(ERR, "queue number cannot be zero");
1676 vfres.num_queue_pairs = num;
1678 args.ops = VIRTCHNL_OP_REQUEST_QUEUES;
1679 args.in_args = (u8 *)&vfres;
1680 args.in_args_size = sizeof(vfres);
1681 args.out_buffer = vf->aq_resp;
1682 args.out_size = IAVF_AQ_BUF_SZ;
1684 if (vf->vf_res->vf_cap_flags & VIRTCHNL_VF_OFFLOAD_WB_ON_ITR) {
1685 /* disable interrupt to avoid the admin queue message to be read
1686 * before iavf_read_msg_from_pf.
1688 rte_intr_disable(&pci_dev->intr_handle);
1689 err = iavf_execute_vf_cmd(adapter, &args);
1690 rte_intr_enable(&pci_dev->intr_handle);
1692 rte_eal_alarm_cancel(iavf_dev_alarm_handler, dev);
1693 err = iavf_execute_vf_cmd(adapter, &args);
1694 rte_eal_alarm_set(IAVF_ALARM_INTERVAL,
1695 iavf_dev_alarm_handler, dev);
1699 PMD_DRV_LOG(ERR, "fail to execute command OP_REQUEST_QUEUES");
1703 /* request queues succeeded, vf is resetting */
1705 PMD_DRV_LOG(INFO, "vf is resetting");
1709 /* request additional queues failed, return available number */
1711 ((struct virtchnl_vf_res_request *)args.out_buffer)->num_queue_pairs;
1712 PMD_DRV_LOG(ERR, "request queues failed, only %u queues "
1713 "available", num_queue_pairs);
1719 iavf_get_max_rss_queue_region(struct iavf_adapter *adapter)
1721 struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(adapter);
1722 struct iavf_cmd_info args;
1723 uint16_t qregion_width;
1726 args.ops = VIRTCHNL_OP_GET_MAX_RSS_QREGION;
1727 args.in_args = NULL;
1728 args.in_args_size = 0;
1729 args.out_buffer = vf->aq_resp;
1730 args.out_size = IAVF_AQ_BUF_SZ;
1732 err = iavf_execute_vf_cmd(adapter, &args);
1734 PMD_DRV_LOG(ERR, "Failed to execute command of VIRTCHNL_OP_GET_MAX_RSS_QREGION");
1739 ((struct virtchnl_max_rss_qregion *)args.out_buffer)->qregion_width;
1741 vf->max_rss_qregion = (uint16_t)(1 << qregion_width);