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 <rte_ethdev_driver.h>
20 #include <rte_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 /* for init virtchnl ops, need to poll the response */
179 result = iavf_read_msg_from_pf(adapter, args->out_size,
181 if (result == IAVF_MSG_CMD)
183 rte_delay_ms(ASQ_DELAY_MS);
184 } while (i++ < MAX_TRY_TIMES);
185 if (i >= MAX_TRY_TIMES ||
186 vf->cmd_retval != VIRTCHNL_STATUS_SUCCESS) {
188 PMD_DRV_LOG(ERR, "No response or return failure (%d)"
189 " for cmd %d", vf->cmd_retval, args->ops);
193 case VIRTCHNL_OP_REQUEST_QUEUES:
195 * ignore async reply, only wait for system message,
196 * vf_reset = true if get VIRTCHNL_EVENT_RESET_IMPENDING,
197 * if not, means request queues failed.
200 result = iavf_read_msg_from_pf(adapter, args->out_size,
202 if (result == IAVF_MSG_SYS && vf->vf_reset) {
204 } else if (result == IAVF_MSG_CMD ||
205 result == IAVF_MSG_ERR) {
209 rte_delay_ms(ASQ_DELAY_MS);
210 /* If don't read msg or read sys event, continue */
211 } while (i++ < MAX_TRY_TIMES);
212 if (i >= MAX_TRY_TIMES ||
213 vf->cmd_retval != VIRTCHNL_STATUS_SUCCESS) {
215 PMD_DRV_LOG(ERR, "No response or return failure (%d)"
216 " for cmd %d", vf->cmd_retval, args->ops);
221 /* For other virtchnl ops in running time,
222 * wait for the cmd done flag.
225 if (vf->pend_cmd == VIRTCHNL_OP_UNKNOWN)
227 rte_delay_ms(ASQ_DELAY_MS);
228 /* If don't read msg or read sys event, continue */
229 } while (i++ < MAX_TRY_TIMES);
230 /* If there's no response is received, clear command */
231 if (i >= MAX_TRY_TIMES ||
232 vf->cmd_retval != VIRTCHNL_STATUS_SUCCESS) {
234 PMD_DRV_LOG(ERR, "No response or return failure (%d)"
235 " for cmd %d", vf->cmd_retval, args->ops);
245 iavf_handle_pf_event_msg(struct rte_eth_dev *dev, uint8_t *msg,
248 struct virtchnl_pf_event *pf_msg =
249 (struct virtchnl_pf_event *)msg;
250 struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(dev->data->dev_private);
252 if (msglen < sizeof(struct virtchnl_pf_event)) {
253 PMD_DRV_LOG(DEBUG, "Error event");
256 switch (pf_msg->event) {
257 case VIRTCHNL_EVENT_RESET_IMPENDING:
258 PMD_DRV_LOG(DEBUG, "VIRTCHNL_EVENT_RESET_IMPENDING event");
260 rte_eth_dev_callback_process(dev, RTE_ETH_EVENT_INTR_RESET,
263 case VIRTCHNL_EVENT_LINK_CHANGE:
264 PMD_DRV_LOG(DEBUG, "VIRTCHNL_EVENT_LINK_CHANGE event");
265 vf->link_up = pf_msg->event_data.link_event.link_status;
266 if (vf->vf_res->vf_cap_flags & VIRTCHNL_VF_CAP_ADV_LINK_SPEED) {
268 pf_msg->event_data.link_event_adv.link_speed;
270 enum virtchnl_link_speed speed;
271 speed = pf_msg->event_data.link_event.link_speed;
272 vf->link_speed = iavf_convert_link_speed(speed);
274 iavf_dev_link_update(dev, 0);
275 rte_eth_dev_callback_process(dev, RTE_ETH_EVENT_INTR_LSC, NULL);
277 case VIRTCHNL_EVENT_PF_DRIVER_CLOSE:
278 PMD_DRV_LOG(DEBUG, "VIRTCHNL_EVENT_PF_DRIVER_CLOSE event");
281 PMD_DRV_LOG(ERR, " unknown event received %u", pf_msg->event);
287 iavf_handle_virtchnl_msg(struct rte_eth_dev *dev)
289 struct iavf_hw *hw = IAVF_DEV_PRIVATE_TO_HW(dev->data->dev_private);
290 struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(dev->data->dev_private);
291 struct iavf_arq_event_info info;
292 uint16_t pending, aq_opc;
293 enum virtchnl_ops msg_opc;
294 enum iavf_status msg_ret;
297 info.buf_len = IAVF_AQ_BUF_SZ;
299 PMD_DRV_LOG(ERR, "Buffer for adminq resp should not be NULL");
302 info.msg_buf = vf->aq_resp;
306 ret = iavf_clean_arq_element(hw, &info, &pending);
308 if (ret != IAVF_SUCCESS) {
309 PMD_DRV_LOG(INFO, "Failed to read msg from AdminQ,"
313 aq_opc = rte_le_to_cpu_16(info.desc.opcode);
314 /* For the message sent from pf to vf, opcode is stored in
315 * cookie_high of struct iavf_aq_desc, while return error code
316 * are stored in cookie_low, Which is done by PF driver.
318 msg_opc = (enum virtchnl_ops)rte_le_to_cpu_32(
319 info.desc.cookie_high);
320 msg_ret = (enum iavf_status)rte_le_to_cpu_32(
321 info.desc.cookie_low);
323 case iavf_aqc_opc_send_msg_to_vf:
324 if (msg_opc == VIRTCHNL_OP_EVENT) {
325 iavf_handle_pf_event_msg(dev, info.msg_buf,
328 /* read message and it's expected one */
329 if (msg_opc == vf->pend_cmd)
330 _notify_cmd(vf, msg_ret);
332 PMD_DRV_LOG(ERR, "command mismatch,"
334 vf->pend_cmd, msg_opc);
336 "adminq response is received,"
337 " opcode = %d", msg_opc);
341 PMD_DRV_LOG(DEBUG, "Request %u is not supported yet",
349 iavf_enable_vlan_strip(struct iavf_adapter *adapter)
351 struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(adapter);
352 struct iavf_cmd_info args;
355 memset(&args, 0, sizeof(args));
356 args.ops = VIRTCHNL_OP_ENABLE_VLAN_STRIPPING;
358 args.in_args_size = 0;
359 args.out_buffer = vf->aq_resp;
360 args.out_size = IAVF_AQ_BUF_SZ;
361 ret = iavf_execute_vf_cmd(adapter, &args);
363 PMD_DRV_LOG(ERR, "Failed to execute command of"
364 " OP_ENABLE_VLAN_STRIPPING");
370 iavf_disable_vlan_strip(struct iavf_adapter *adapter)
372 struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(adapter);
373 struct iavf_cmd_info args;
376 memset(&args, 0, sizeof(args));
377 args.ops = VIRTCHNL_OP_DISABLE_VLAN_STRIPPING;
379 args.in_args_size = 0;
380 args.out_buffer = vf->aq_resp;
381 args.out_size = IAVF_AQ_BUF_SZ;
382 ret = iavf_execute_vf_cmd(adapter, &args);
384 PMD_DRV_LOG(ERR, "Failed to execute command of"
385 " OP_DISABLE_VLAN_STRIPPING");
390 #define VIRTCHNL_VERSION_MAJOR_START 1
391 #define VIRTCHNL_VERSION_MINOR_START 1
393 /* Check API version with sync wait until version read from admin queue */
395 iavf_check_api_version(struct iavf_adapter *adapter)
397 struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(adapter);
398 struct virtchnl_version_info version, *pver;
399 struct iavf_cmd_info args;
402 version.major = VIRTCHNL_VERSION_MAJOR;
403 version.minor = VIRTCHNL_VERSION_MINOR;
405 args.ops = VIRTCHNL_OP_VERSION;
406 args.in_args = (uint8_t *)&version;
407 args.in_args_size = sizeof(version);
408 args.out_buffer = vf->aq_resp;
409 args.out_size = IAVF_AQ_BUF_SZ;
411 err = iavf_execute_vf_cmd(adapter, &args);
413 PMD_INIT_LOG(ERR, "Fail to execute command of OP_VERSION");
417 pver = (struct virtchnl_version_info *)args.out_buffer;
418 vf->virtchnl_version = *pver;
420 if (vf->virtchnl_version.major < VIRTCHNL_VERSION_MAJOR_START ||
421 (vf->virtchnl_version.major == VIRTCHNL_VERSION_MAJOR_START &&
422 vf->virtchnl_version.minor < VIRTCHNL_VERSION_MINOR_START)) {
423 PMD_INIT_LOG(ERR, "VIRTCHNL API version should not be lower"
424 " than (%u.%u) to support Adapative VF",
425 VIRTCHNL_VERSION_MAJOR_START,
426 VIRTCHNL_VERSION_MAJOR_START);
428 } else if (vf->virtchnl_version.major > VIRTCHNL_VERSION_MAJOR ||
429 (vf->virtchnl_version.major == VIRTCHNL_VERSION_MAJOR &&
430 vf->virtchnl_version.minor > VIRTCHNL_VERSION_MINOR)) {
431 PMD_INIT_LOG(ERR, "PF/VF API version mismatch:(%u.%u)-(%u.%u)",
432 vf->virtchnl_version.major,
433 vf->virtchnl_version.minor,
434 VIRTCHNL_VERSION_MAJOR,
435 VIRTCHNL_VERSION_MINOR);
439 PMD_DRV_LOG(DEBUG, "Peer is supported PF host");
444 iavf_get_vf_resource(struct iavf_adapter *adapter)
446 struct iavf_hw *hw = IAVF_DEV_PRIVATE_TO_HW(adapter);
447 struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(adapter);
448 struct iavf_cmd_info args;
452 args.ops = VIRTCHNL_OP_GET_VF_RESOURCES;
453 args.out_buffer = vf->aq_resp;
454 args.out_size = IAVF_AQ_BUF_SZ;
456 caps = IAVF_BASIC_OFFLOAD_CAPS | VIRTCHNL_VF_CAP_ADV_LINK_SPEED |
457 VIRTCHNL_VF_OFFLOAD_RX_FLEX_DESC |
458 VIRTCHNL_VF_OFFLOAD_FDIR_PF |
459 VIRTCHNL_VF_OFFLOAD_ADV_RSS_PF |
460 VIRTCHNL_VF_OFFLOAD_REQ_QUEUES |
461 VIRTCHNL_VF_LARGE_NUM_QPAIRS;
463 args.in_args = (uint8_t *)∩︀
464 args.in_args_size = sizeof(caps);
466 err = iavf_execute_vf_cmd(adapter, &args);
470 "Failed to execute command of OP_GET_VF_RESOURCE");
474 len = sizeof(struct virtchnl_vf_resource) +
475 IAVF_MAX_VF_VSI * sizeof(struct virtchnl_vsi_resource);
477 rte_memcpy(vf->vf_res, args.out_buffer,
478 RTE_MIN(args.out_size, len));
479 /* parse VF config message back from PF*/
480 iavf_vf_parse_hw_config(hw, vf->vf_res);
481 for (i = 0; i < vf->vf_res->num_vsis; i++) {
482 if (vf->vf_res->vsi_res[i].vsi_type == VIRTCHNL_VSI_SRIOV)
483 vf->vsi_res = &vf->vf_res->vsi_res[i];
487 PMD_INIT_LOG(ERR, "no LAN VSI found");
491 vf->vsi.vsi_id = vf->vsi_res->vsi_id;
492 vf->vsi.nb_qps = vf->vsi_res->num_queue_pairs;
493 vf->vsi.adapter = adapter;
499 iavf_get_supported_rxdid(struct iavf_adapter *adapter)
501 struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(adapter);
502 struct iavf_cmd_info args;
505 args.ops = VIRTCHNL_OP_GET_SUPPORTED_RXDIDS;
507 args.in_args_size = 0;
508 args.out_buffer = vf->aq_resp;
509 args.out_size = IAVF_AQ_BUF_SZ;
511 ret = iavf_execute_vf_cmd(adapter, &args);
514 "Failed to execute command of OP_GET_SUPPORTED_RXDIDS");
518 vf->supported_rxdid =
519 ((struct virtchnl_supported_rxdids *)args.out_buffer)->supported_rxdids;
525 iavf_enable_queues(struct iavf_adapter *adapter)
527 struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(adapter);
528 struct virtchnl_queue_select queue_select;
529 struct iavf_cmd_info args;
532 memset(&queue_select, 0, sizeof(queue_select));
533 queue_select.vsi_id = vf->vsi_res->vsi_id;
535 queue_select.rx_queues = BIT(adapter->eth_dev->data->nb_rx_queues) - 1;
536 queue_select.tx_queues = BIT(adapter->eth_dev->data->nb_tx_queues) - 1;
538 args.ops = VIRTCHNL_OP_ENABLE_QUEUES;
539 args.in_args = (u8 *)&queue_select;
540 args.in_args_size = sizeof(queue_select);
541 args.out_buffer = vf->aq_resp;
542 args.out_size = IAVF_AQ_BUF_SZ;
543 err = iavf_execute_vf_cmd(adapter, &args);
546 "Failed to execute command of OP_ENABLE_QUEUES");
553 iavf_disable_queues(struct iavf_adapter *adapter)
555 struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(adapter);
556 struct virtchnl_queue_select queue_select;
557 struct iavf_cmd_info args;
560 memset(&queue_select, 0, sizeof(queue_select));
561 queue_select.vsi_id = vf->vsi_res->vsi_id;
563 queue_select.rx_queues = BIT(adapter->eth_dev->data->nb_rx_queues) - 1;
564 queue_select.tx_queues = BIT(adapter->eth_dev->data->nb_tx_queues) - 1;
566 args.ops = VIRTCHNL_OP_DISABLE_QUEUES;
567 args.in_args = (u8 *)&queue_select;
568 args.in_args_size = sizeof(queue_select);
569 args.out_buffer = vf->aq_resp;
570 args.out_size = IAVF_AQ_BUF_SZ;
571 err = iavf_execute_vf_cmd(adapter, &args);
574 "Failed to execute command of OP_DISABLE_QUEUES");
581 iavf_switch_queue(struct iavf_adapter *adapter, uint16_t qid,
584 struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(adapter);
585 struct virtchnl_queue_select queue_select;
586 struct iavf_cmd_info args;
589 memset(&queue_select, 0, sizeof(queue_select));
590 queue_select.vsi_id = vf->vsi_res->vsi_id;
592 queue_select.rx_queues |= 1 << qid;
594 queue_select.tx_queues |= 1 << qid;
597 args.ops = VIRTCHNL_OP_ENABLE_QUEUES;
599 args.ops = VIRTCHNL_OP_DISABLE_QUEUES;
600 args.in_args = (u8 *)&queue_select;
601 args.in_args_size = sizeof(queue_select);
602 args.out_buffer = vf->aq_resp;
603 args.out_size = IAVF_AQ_BUF_SZ;
604 err = iavf_execute_vf_cmd(adapter, &args);
606 PMD_DRV_LOG(ERR, "Failed to execute command of %s",
607 on ? "OP_ENABLE_QUEUES" : "OP_DISABLE_QUEUES");
612 iavf_configure_rss_lut(struct iavf_adapter *adapter)
614 struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(adapter);
615 struct virtchnl_rss_lut *rss_lut;
616 struct iavf_cmd_info args;
619 len = sizeof(*rss_lut) + vf->vf_res->rss_lut_size - 1;
620 rss_lut = rte_zmalloc("rss_lut", len, 0);
624 rss_lut->vsi_id = vf->vsi_res->vsi_id;
625 rss_lut->lut_entries = vf->vf_res->rss_lut_size;
626 rte_memcpy(rss_lut->lut, vf->rss_lut, vf->vf_res->rss_lut_size);
628 args.ops = VIRTCHNL_OP_CONFIG_RSS_LUT;
629 args.in_args = (u8 *)rss_lut;
630 args.in_args_size = len;
631 args.out_buffer = vf->aq_resp;
632 args.out_size = IAVF_AQ_BUF_SZ;
634 err = iavf_execute_vf_cmd(adapter, &args);
637 "Failed to execute command of OP_CONFIG_RSS_LUT");
644 iavf_configure_rss_key(struct iavf_adapter *adapter)
646 struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(adapter);
647 struct virtchnl_rss_key *rss_key;
648 struct iavf_cmd_info args;
651 len = sizeof(*rss_key) + vf->vf_res->rss_key_size - 1;
652 rss_key = rte_zmalloc("rss_key", len, 0);
656 rss_key->vsi_id = vf->vsi_res->vsi_id;
657 rss_key->key_len = vf->vf_res->rss_key_size;
658 rte_memcpy(rss_key->key, vf->rss_key, vf->vf_res->rss_key_size);
660 args.ops = VIRTCHNL_OP_CONFIG_RSS_KEY;
661 args.in_args = (u8 *)rss_key;
662 args.in_args_size = len;
663 args.out_buffer = vf->aq_resp;
664 args.out_size = IAVF_AQ_BUF_SZ;
666 err = iavf_execute_vf_cmd(adapter, &args);
669 "Failed to execute command of OP_CONFIG_RSS_KEY");
676 iavf_configure_queues(struct iavf_adapter *adapter)
678 struct iavf_rx_queue **rxq =
679 (struct iavf_rx_queue **)adapter->eth_dev->data->rx_queues;
680 struct iavf_tx_queue **txq =
681 (struct iavf_tx_queue **)adapter->eth_dev->data->tx_queues;
682 struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(adapter);
683 struct virtchnl_vsi_queue_config_info *vc_config;
684 struct virtchnl_queue_pair_info *vc_qp;
685 struct iavf_cmd_info args;
689 size = sizeof(*vc_config) +
690 sizeof(vc_config->qpair[0]) * vf->num_queue_pairs;
691 vc_config = rte_zmalloc("cfg_queue", size, 0);
695 vc_config->vsi_id = vf->vsi_res->vsi_id;
696 vc_config->num_queue_pairs = vf->num_queue_pairs;
698 for (i = 0, vc_qp = vc_config->qpair;
699 i < vf->num_queue_pairs;
701 vc_qp->txq.vsi_id = vf->vsi_res->vsi_id;
702 vc_qp->txq.queue_id = i;
703 /* Virtchnnl configure queues by pairs */
704 if (i < adapter->eth_dev->data->nb_tx_queues) {
705 vc_qp->txq.ring_len = txq[i]->nb_tx_desc;
706 vc_qp->txq.dma_ring_addr = txq[i]->tx_ring_phys_addr;
708 vc_qp->rxq.vsi_id = vf->vsi_res->vsi_id;
709 vc_qp->rxq.queue_id = i;
710 vc_qp->rxq.max_pkt_size = vf->max_pkt_len;
711 /* Virtchnnl configure queues by pairs */
712 if (i < adapter->eth_dev->data->nb_rx_queues) {
713 vc_qp->rxq.ring_len = rxq[i]->nb_rx_desc;
714 vc_qp->rxq.dma_ring_addr = rxq[i]->rx_ring_phys_addr;
715 vc_qp->rxq.databuffer_size = rxq[i]->rx_buf_len;
718 #ifndef RTE_LIBRTE_IAVF_16BYTE_RX_DESC
719 if (vf->vf_res->vf_cap_flags &
720 VIRTCHNL_VF_OFFLOAD_RX_FLEX_DESC &&
721 vf->supported_rxdid & BIT(IAVF_RXDID_COMMS_OVS_1)) {
722 vc_qp->rxq.rxdid = IAVF_RXDID_COMMS_OVS_1;
723 PMD_DRV_LOG(NOTICE, "request RXDID == %d in "
724 "Queue[%d]", vc_qp->rxq.rxdid, i);
726 vc_qp->rxq.rxdid = IAVF_RXDID_LEGACY_1;
727 PMD_DRV_LOG(NOTICE, "request RXDID == %d in "
728 "Queue[%d]", vc_qp->rxq.rxdid, i);
731 if (vf->vf_res->vf_cap_flags &
732 VIRTCHNL_VF_OFFLOAD_RX_FLEX_DESC &&
733 vf->supported_rxdid & BIT(IAVF_RXDID_LEGACY_0)) {
734 vc_qp->rxq.rxdid = IAVF_RXDID_LEGACY_0;
735 PMD_DRV_LOG(NOTICE, "request RXDID == %d in "
736 "Queue[%d]", vc_qp->rxq.rxdid, i);
738 PMD_DRV_LOG(ERR, "RXDID == 0 is not supported");
744 memset(&args, 0, sizeof(args));
745 args.ops = VIRTCHNL_OP_CONFIG_VSI_QUEUES;
746 args.in_args = (uint8_t *)vc_config;
747 args.in_args_size = size;
748 args.out_buffer = vf->aq_resp;
749 args.out_size = IAVF_AQ_BUF_SZ;
751 err = iavf_execute_vf_cmd(adapter, &args);
753 PMD_DRV_LOG(ERR, "Failed to execute command of"
754 " VIRTCHNL_OP_CONFIG_VSI_QUEUES");
761 iavf_config_irq_map(struct iavf_adapter *adapter)
763 struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(adapter);
764 struct virtchnl_irq_map_info *map_info;
765 struct virtchnl_vector_map *vecmap;
766 struct iavf_cmd_info args;
769 len = sizeof(struct virtchnl_irq_map_info) +
770 sizeof(struct virtchnl_vector_map) * vf->nb_msix;
772 map_info = rte_zmalloc("map_info", len, 0);
776 map_info->num_vectors = vf->nb_msix;
777 for (i = 0; i < vf->nb_msix; i++) {
778 vecmap = &map_info->vecmap[i];
779 vecmap->vsi_id = vf->vsi_res->vsi_id;
780 vecmap->rxitr_idx = IAVF_ITR_INDEX_DEFAULT;
781 vecmap->vector_id = vf->msix_base + i;
783 vecmap->rxq_map = vf->rxq_map[vf->msix_base + i];
786 args.ops = VIRTCHNL_OP_CONFIG_IRQ_MAP;
787 args.in_args = (u8 *)map_info;
788 args.in_args_size = len;
789 args.out_buffer = vf->aq_resp;
790 args.out_size = IAVF_AQ_BUF_SZ;
791 err = iavf_execute_vf_cmd(adapter, &args);
793 PMD_DRV_LOG(ERR, "fail to execute command OP_CONFIG_IRQ_MAP");
800 iavf_add_del_all_mac_addr(struct iavf_adapter *adapter, bool add)
802 struct virtchnl_ether_addr_list *list;
803 struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(adapter);
804 struct rte_ether_addr *addr;
805 struct iavf_cmd_info args;
812 len = sizeof(struct virtchnl_ether_addr_list);
813 for (i = begin; i < IAVF_NUM_MACADDR_MAX; i++, next_begin++) {
814 addr = &adapter->eth_dev->data->mac_addrs[i];
815 if (rte_is_zero_ether_addr(addr))
817 len += sizeof(struct virtchnl_ether_addr);
818 if (len >= IAVF_AQ_BUF_SZ) {
824 list = rte_zmalloc("iavf_del_mac_buffer", len, 0);
826 PMD_DRV_LOG(ERR, "fail to allocate memory");
830 for (i = begin; i < next_begin; i++) {
831 addr = &adapter->eth_dev->data->mac_addrs[i];
832 if (rte_is_zero_ether_addr(addr))
834 rte_memcpy(list->list[j].addr, addr->addr_bytes,
835 sizeof(addr->addr_bytes));
836 PMD_DRV_LOG(DEBUG, "add/rm mac:%x:%x:%x:%x:%x:%x",
837 addr->addr_bytes[0], addr->addr_bytes[1],
838 addr->addr_bytes[2], addr->addr_bytes[3],
839 addr->addr_bytes[4], addr->addr_bytes[5]);
842 list->vsi_id = vf->vsi_res->vsi_id;
843 list->num_elements = j;
844 args.ops = add ? VIRTCHNL_OP_ADD_ETH_ADDR :
845 VIRTCHNL_OP_DEL_ETH_ADDR;
846 args.in_args = (uint8_t *)list;
847 args.in_args_size = len;
848 args.out_buffer = vf->aq_resp;
849 args.out_size = IAVF_AQ_BUF_SZ;
850 err = iavf_execute_vf_cmd(adapter, &args);
852 PMD_DRV_LOG(ERR, "fail to execute command %s",
853 add ? "OP_ADD_ETHER_ADDRESS" :
854 "OP_DEL_ETHER_ADDRESS");
857 } while (begin < IAVF_NUM_MACADDR_MAX);
861 iavf_query_stats(struct iavf_adapter *adapter,
862 struct virtchnl_eth_stats **pstats)
864 struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(adapter);
865 struct virtchnl_queue_select q_stats;
866 struct iavf_cmd_info args;
869 memset(&q_stats, 0, sizeof(q_stats));
870 q_stats.vsi_id = vf->vsi_res->vsi_id;
871 args.ops = VIRTCHNL_OP_GET_STATS;
872 args.in_args = (uint8_t *)&q_stats;
873 args.in_args_size = sizeof(q_stats);
874 args.out_buffer = vf->aq_resp;
875 args.out_size = IAVF_AQ_BUF_SZ;
877 err = iavf_execute_vf_cmd(adapter, &args);
879 PMD_DRV_LOG(ERR, "fail to execute command OP_GET_STATS");
883 *pstats = (struct virtchnl_eth_stats *)args.out_buffer;
888 iavf_config_promisc(struct iavf_adapter *adapter,
890 bool enable_multicast)
892 struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(adapter);
893 struct virtchnl_promisc_info promisc;
894 struct iavf_cmd_info args;
898 promisc.vsi_id = vf->vsi_res->vsi_id;
901 promisc.flags |= FLAG_VF_UNICAST_PROMISC;
903 if (enable_multicast)
904 promisc.flags |= FLAG_VF_MULTICAST_PROMISC;
906 args.ops = VIRTCHNL_OP_CONFIG_PROMISCUOUS_MODE;
907 args.in_args = (uint8_t *)&promisc;
908 args.in_args_size = sizeof(promisc);
909 args.out_buffer = vf->aq_resp;
910 args.out_size = IAVF_AQ_BUF_SZ;
912 err = iavf_execute_vf_cmd(adapter, &args);
916 "fail to execute command CONFIG_PROMISCUOUS_MODE");
918 if (err == IAVF_NOT_SUPPORTED)
924 vf->promisc_unicast_enabled = enable_unicast;
925 vf->promisc_multicast_enabled = enable_multicast;
930 iavf_add_del_eth_addr(struct iavf_adapter *adapter, struct rte_ether_addr *addr,
933 struct virtchnl_ether_addr_list *list;
934 struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(adapter);
935 uint8_t cmd_buffer[sizeof(struct virtchnl_ether_addr_list) +
936 sizeof(struct virtchnl_ether_addr)];
937 struct iavf_cmd_info args;
940 list = (struct virtchnl_ether_addr_list *)cmd_buffer;
941 list->vsi_id = vf->vsi_res->vsi_id;
942 list->num_elements = 1;
943 rte_memcpy(list->list[0].addr, addr->addr_bytes,
944 sizeof(addr->addr_bytes));
946 args.ops = add ? VIRTCHNL_OP_ADD_ETH_ADDR : VIRTCHNL_OP_DEL_ETH_ADDR;
947 args.in_args = cmd_buffer;
948 args.in_args_size = sizeof(cmd_buffer);
949 args.out_buffer = vf->aq_resp;
950 args.out_size = IAVF_AQ_BUF_SZ;
951 err = iavf_execute_vf_cmd(adapter, &args);
953 PMD_DRV_LOG(ERR, "fail to execute command %s",
954 add ? "OP_ADD_ETH_ADDR" : "OP_DEL_ETH_ADDR");
959 iavf_add_del_vlan(struct iavf_adapter *adapter, uint16_t vlanid, bool add)
961 struct virtchnl_vlan_filter_list *vlan_list;
962 struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(adapter);
963 uint8_t cmd_buffer[sizeof(struct virtchnl_vlan_filter_list) +
965 struct iavf_cmd_info args;
968 vlan_list = (struct virtchnl_vlan_filter_list *)cmd_buffer;
969 vlan_list->vsi_id = vf->vsi_res->vsi_id;
970 vlan_list->num_elements = 1;
971 vlan_list->vlan_id[0] = vlanid;
973 args.ops = add ? VIRTCHNL_OP_ADD_VLAN : VIRTCHNL_OP_DEL_VLAN;
974 args.in_args = cmd_buffer;
975 args.in_args_size = sizeof(cmd_buffer);
976 args.out_buffer = vf->aq_resp;
977 args.out_size = IAVF_AQ_BUF_SZ;
978 err = iavf_execute_vf_cmd(adapter, &args);
980 PMD_DRV_LOG(ERR, "fail to execute command %s",
981 add ? "OP_ADD_VLAN" : "OP_DEL_VLAN");
987 iavf_fdir_add(struct iavf_adapter *adapter,
988 struct iavf_fdir_conf *filter)
990 struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(adapter);
991 struct virtchnl_fdir_add *fdir_ret;
993 struct iavf_cmd_info args;
996 filter->add_fltr.vsi_id = vf->vsi_res->vsi_id;
997 filter->add_fltr.validate_only = 0;
999 args.ops = VIRTCHNL_OP_ADD_FDIR_FILTER;
1000 args.in_args = (uint8_t *)(&filter->add_fltr);
1001 args.in_args_size = sizeof(*(&filter->add_fltr));
1002 args.out_buffer = vf->aq_resp;
1003 args.out_size = IAVF_AQ_BUF_SZ;
1005 err = iavf_execute_vf_cmd(adapter, &args);
1007 PMD_DRV_LOG(ERR, "fail to execute command OP_ADD_FDIR_FILTER");
1011 fdir_ret = (struct virtchnl_fdir_add *)args.out_buffer;
1012 filter->flow_id = fdir_ret->flow_id;
1014 if (fdir_ret->status == VIRTCHNL_FDIR_SUCCESS) {
1016 "Succeed in adding rule request by PF");
1017 } else if (fdir_ret->status == VIRTCHNL_FDIR_FAILURE_RULE_NORESOURCE) {
1019 "Failed to add rule request due to no hw resource");
1021 } else if (fdir_ret->status == VIRTCHNL_FDIR_FAILURE_RULE_EXIST) {
1023 "Failed to add rule request due to the rule is already existed");
1025 } else if (fdir_ret->status == VIRTCHNL_FDIR_FAILURE_RULE_CONFLICT) {
1027 "Failed to add rule request due to the rule is conflict with existing rule");
1029 } else if (fdir_ret->status == VIRTCHNL_FDIR_FAILURE_RULE_INVALID) {
1031 "Failed to add rule request due to the hw doesn't support");
1033 } else if (fdir_ret->status == VIRTCHNL_FDIR_FAILURE_RULE_TIMEOUT) {
1035 "Failed to add rule request due to time out for programming");
1039 "Failed to add rule request due to other reasons");
1047 iavf_fdir_del(struct iavf_adapter *adapter,
1048 struct iavf_fdir_conf *filter)
1050 struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(adapter);
1051 struct virtchnl_fdir_del *fdir_ret;
1053 struct iavf_cmd_info args;
1056 filter->del_fltr.vsi_id = vf->vsi_res->vsi_id;
1057 filter->del_fltr.flow_id = filter->flow_id;
1059 args.ops = VIRTCHNL_OP_DEL_FDIR_FILTER;
1060 args.in_args = (uint8_t *)(&filter->del_fltr);
1061 args.in_args_size = sizeof(filter->del_fltr);
1062 args.out_buffer = vf->aq_resp;
1063 args.out_size = IAVF_AQ_BUF_SZ;
1065 err = iavf_execute_vf_cmd(adapter, &args);
1067 PMD_DRV_LOG(ERR, "fail to execute command OP_DEL_FDIR_FILTER");
1071 fdir_ret = (struct virtchnl_fdir_del *)args.out_buffer;
1073 if (fdir_ret->status == VIRTCHNL_FDIR_SUCCESS) {
1075 "Succeed in deleting rule request by PF");
1076 } else if (fdir_ret->status == VIRTCHNL_FDIR_FAILURE_RULE_NONEXIST) {
1078 "Failed to delete rule request due to this rule doesn't exist");
1080 } else if (fdir_ret->status == VIRTCHNL_FDIR_FAILURE_RULE_TIMEOUT) {
1082 "Failed to delete rule request due to time out for programming");
1086 "Failed to delete rule request due to other reasons");
1094 iavf_fdir_check(struct iavf_adapter *adapter,
1095 struct iavf_fdir_conf *filter)
1097 struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(adapter);
1098 struct virtchnl_fdir_add *fdir_ret;
1100 struct iavf_cmd_info args;
1103 filter->add_fltr.vsi_id = vf->vsi_res->vsi_id;
1104 filter->add_fltr.validate_only = 1;
1106 args.ops = VIRTCHNL_OP_ADD_FDIR_FILTER;
1107 args.in_args = (uint8_t *)(&filter->add_fltr);
1108 args.in_args_size = sizeof(*(&filter->add_fltr));
1109 args.out_buffer = vf->aq_resp;
1110 args.out_size = IAVF_AQ_BUF_SZ;
1112 err = iavf_execute_vf_cmd(adapter, &args);
1114 PMD_DRV_LOG(ERR, "fail to check flow direcotor rule");
1118 fdir_ret = (struct virtchnl_fdir_add *)args.out_buffer;
1120 if (fdir_ret->status == VIRTCHNL_FDIR_SUCCESS) {
1122 "Succeed in checking rule request by PF");
1123 } else if (fdir_ret->status == VIRTCHNL_FDIR_FAILURE_RULE_INVALID) {
1125 "Failed to check rule request due to parameters validation"
1126 " or HW doesn't support");
1130 "Failed to check rule request due to other reasons");
1138 iavf_add_del_rss_cfg(struct iavf_adapter *adapter,
1139 struct virtchnl_rss_cfg *rss_cfg, bool add)
1141 struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(adapter);
1142 struct iavf_cmd_info args;
1145 memset(&args, 0, sizeof(args));
1146 args.ops = add ? VIRTCHNL_OP_ADD_RSS_CFG :
1147 VIRTCHNL_OP_DEL_RSS_CFG;
1148 args.in_args = (u8 *)rss_cfg;
1149 args.in_args_size = sizeof(*rss_cfg);
1150 args.out_buffer = vf->aq_resp;
1151 args.out_size = IAVF_AQ_BUF_SZ;
1153 err = iavf_execute_vf_cmd(adapter, &args);
1156 "Failed to execute command of %s",
1157 add ? "OP_ADD_RSS_CFG" :
1158 "OP_DEL_RSS_INPUT_CFG");
1164 iavf_add_del_mc_addr_list(struct iavf_adapter *adapter,
1165 struct rte_ether_addr *mc_addrs,
1166 uint32_t mc_addrs_num, bool add)
1168 struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(adapter);
1169 uint8_t cmd_buffer[sizeof(struct virtchnl_ether_addr_list) +
1170 (IAVF_NUM_MACADDR_MAX * sizeof(struct virtchnl_ether_addr))];
1171 struct virtchnl_ether_addr_list *list;
1172 struct iavf_cmd_info args;
1176 if (mc_addrs == NULL || mc_addrs_num == 0)
1179 list = (struct virtchnl_ether_addr_list *)cmd_buffer;
1180 list->vsi_id = vf->vsi_res->vsi_id;
1181 list->num_elements = mc_addrs_num;
1183 for (i = 0; i < mc_addrs_num; i++) {
1184 if (!IAVF_IS_MULTICAST(mc_addrs[i].addr_bytes)) {
1185 PMD_DRV_LOG(ERR, "Invalid mac:%x:%x:%x:%x:%x:%x",
1186 mc_addrs[i].addr_bytes[0],
1187 mc_addrs[i].addr_bytes[1],
1188 mc_addrs[i].addr_bytes[2],
1189 mc_addrs[i].addr_bytes[3],
1190 mc_addrs[i].addr_bytes[4],
1191 mc_addrs[i].addr_bytes[5]);
1195 memcpy(list->list[i].addr, mc_addrs[i].addr_bytes,
1196 sizeof(list->list[i].addr));
1199 args.ops = add ? VIRTCHNL_OP_ADD_ETH_ADDR : VIRTCHNL_OP_DEL_ETH_ADDR;
1200 args.in_args = cmd_buffer;
1201 args.in_args_size = sizeof(struct virtchnl_ether_addr_list) +
1202 i * sizeof(struct virtchnl_ether_addr);
1203 args.out_buffer = vf->aq_resp;
1204 args.out_size = IAVF_AQ_BUF_SZ;
1205 err = iavf_execute_vf_cmd(adapter, &args);
1208 PMD_DRV_LOG(ERR, "fail to execute command %s",
1209 add ? "OP_ADD_ETH_ADDR" : "OP_DEL_ETH_ADDR");
1217 iavf_request_queues(struct iavf_adapter *adapter, uint16_t num)
1219 struct rte_eth_dev *dev = adapter->eth_dev;
1220 struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(adapter);
1221 struct rte_pci_device *pci_dev = RTE_ETH_DEV_TO_PCI(dev);
1222 struct virtchnl_vf_res_request vfres;
1223 struct iavf_cmd_info args;
1224 uint16_t num_queue_pairs;
1227 if (!(vf->vf_res->vf_cap_flags &
1228 VIRTCHNL_VF_OFFLOAD_REQ_QUEUES)) {
1229 PMD_DRV_LOG(ERR, "request queues not supported");
1234 PMD_DRV_LOG(ERR, "queue number cannot be zero");
1237 vfres.num_queue_pairs = num;
1239 args.ops = VIRTCHNL_OP_REQUEST_QUEUES;
1240 args.in_args = (u8 *)&vfres;
1241 args.in_args_size = sizeof(vfres);
1242 args.out_buffer = vf->aq_resp;
1243 args.out_size = IAVF_AQ_BUF_SZ;
1246 * disable interrupt to avoid the admin queue message to be read
1247 * before iavf_read_msg_from_pf.
1249 rte_intr_disable(&pci_dev->intr_handle);
1250 err = iavf_execute_vf_cmd(adapter, &args);
1251 rte_intr_enable(&pci_dev->intr_handle);
1253 PMD_DRV_LOG(ERR, "fail to execute command OP_REQUEST_QUEUES");
1257 /* request queues succeeded, vf is resetting */
1259 PMD_DRV_LOG(INFO, "vf is resetting");
1263 /* request additional queues failed, return available number */
1265 ((struct virtchnl_vf_res_request *)args.out_buffer)->num_queue_pairs;
1266 PMD_DRV_LOG(ERR, "request queues failed, only %u queues "
1267 "available", num_queue_pairs);
1273 iavf_get_max_rss_queue_region(struct iavf_adapter *adapter)
1275 struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(adapter);
1276 struct iavf_cmd_info args;
1277 uint16_t qregion_width;
1280 args.ops = VIRTCHNL_OP_GET_MAX_RSS_QREGION;
1281 args.in_args = NULL;
1282 args.in_args_size = 0;
1283 args.out_buffer = vf->aq_resp;
1284 args.out_size = IAVF_AQ_BUF_SZ;
1286 err = iavf_execute_vf_cmd(adapter, &args);
1288 PMD_DRV_LOG(ERR, "Failed to execute command of VIRTCHNL_OP_GET_MAX_RSS_QREGION");
1293 ((struct virtchnl_max_rss_qregion *)args.out_buffer)->qregion_width;
1295 vf->max_rss_qregion = (uint16_t)(1 << qregion_width);