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>
23 #include "iavf_rxtx.h"
25 #define MAX_TRY_TIMES 200
26 #define ASQ_DELAY_MS 10
28 /* Read data in admin queue to get msg from pf driver */
29 static enum iavf_status
30 iavf_read_msg_from_pf(struct iavf_adapter *adapter, uint16_t buf_len,
33 struct iavf_hw *hw = IAVF_DEV_PRIVATE_TO_HW(adapter);
34 struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(adapter);
35 struct iavf_arq_event_info event;
36 enum virtchnl_ops opcode;
39 event.buf_len = buf_len;
41 ret = iavf_clean_arq_element(hw, &event, NULL);
42 /* Can't read any msg from adminQ */
44 PMD_DRV_LOG(DEBUG, "Can't read msg from AQ");
48 opcode = (enum virtchnl_ops)rte_le_to_cpu_32(event.desc.cookie_high);
49 vf->cmd_retval = (enum virtchnl_status_code)rte_le_to_cpu_32(
50 event.desc.cookie_low);
52 PMD_DRV_LOG(DEBUG, "AQ from pf carries opcode %u, retval %d",
53 opcode, vf->cmd_retval);
55 if (opcode != vf->pend_cmd) {
56 if (opcode != VIRTCHNL_OP_EVENT) {
58 "command mismatch, expect %u, get %u",
59 vf->pend_cmd, opcode);
61 return IAVF_ERR_OPCODE_MISMATCH;
68 iavf_execute_vf_cmd(struct iavf_adapter *adapter, struct iavf_cmd_info *args)
70 struct iavf_hw *hw = IAVF_DEV_PRIVATE_TO_HW(adapter);
71 struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(adapter);
76 if (_atomic_set_cmd(vf, args->ops))
79 ret = iavf_aq_send_msg_to_pf(hw, args->ops, IAVF_SUCCESS,
80 args->in_args, args->in_args_size, NULL);
82 PMD_DRV_LOG(ERR, "fail to send cmd %d", args->ops);
88 case VIRTCHNL_OP_RESET_VF:
89 /*no need to wait for response */
92 case VIRTCHNL_OP_VERSION:
93 case VIRTCHNL_OP_GET_VF_RESOURCES:
94 case VIRTCHNL_OP_GET_SUPPORTED_RXDIDS:
95 /* for init virtchnl ops, need to poll the response */
97 ret = iavf_read_msg_from_pf(adapter, args->out_size,
99 if (ret == IAVF_SUCCESS)
101 rte_delay_ms(ASQ_DELAY_MS);
102 } while (i++ < MAX_TRY_TIMES);
103 if (i >= MAX_TRY_TIMES ||
104 vf->cmd_retval != VIRTCHNL_STATUS_SUCCESS) {
106 PMD_DRV_LOG(ERR, "No response or return failure (%d)"
107 " for cmd %d", vf->cmd_retval, args->ops);
113 /* For other virtchnl ops in running time,
114 * wait for the cmd done flag.
117 if (vf->pend_cmd == VIRTCHNL_OP_UNKNOWN)
119 rte_delay_ms(ASQ_DELAY_MS);
120 /* If don't read msg or read sys event, continue */
121 } while (i++ < MAX_TRY_TIMES);
122 /* If there's no response is received, clear command */
123 if (i >= MAX_TRY_TIMES ||
124 vf->cmd_retval != VIRTCHNL_STATUS_SUCCESS) {
126 PMD_DRV_LOG(ERR, "No response or return failure (%d)"
127 " for cmd %d", vf->cmd_retval, args->ops);
137 iavf_convert_link_speed(enum virtchnl_link_speed virt_link_speed)
141 switch (virt_link_speed) {
142 case VIRTCHNL_LINK_SPEED_100MB:
145 case VIRTCHNL_LINK_SPEED_1GB:
148 case VIRTCHNL_LINK_SPEED_10GB:
151 case VIRTCHNL_LINK_SPEED_40GB:
154 case VIRTCHNL_LINK_SPEED_20GB:
157 case VIRTCHNL_LINK_SPEED_25GB:
160 case VIRTCHNL_LINK_SPEED_2_5GB:
163 case VIRTCHNL_LINK_SPEED_5GB:
175 iavf_handle_pf_event_msg(struct rte_eth_dev *dev, uint8_t *msg,
178 struct virtchnl_pf_event *pf_msg =
179 (struct virtchnl_pf_event *)msg;
180 struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(dev->data->dev_private);
182 if (msglen < sizeof(struct virtchnl_pf_event)) {
183 PMD_DRV_LOG(DEBUG, "Error event");
186 switch (pf_msg->event) {
187 case VIRTCHNL_EVENT_RESET_IMPENDING:
188 PMD_DRV_LOG(DEBUG, "VIRTCHNL_EVENT_RESET_IMPENDING event");
189 _rte_eth_dev_callback_process(dev, RTE_ETH_EVENT_INTR_RESET,
192 case VIRTCHNL_EVENT_LINK_CHANGE:
193 PMD_DRV_LOG(DEBUG, "VIRTCHNL_EVENT_LINK_CHANGE event");
194 vf->link_up = pf_msg->event_data.link_event.link_status;
195 if (vf->vf_res->vf_cap_flags & VIRTCHNL_VF_CAP_ADV_LINK_SPEED) {
197 pf_msg->event_data.link_event_adv.link_speed;
199 enum virtchnl_link_speed speed;
200 speed = pf_msg->event_data.link_event.link_speed;
201 vf->link_speed = iavf_convert_link_speed(speed);
203 iavf_dev_link_update(dev, 0);
204 _rte_eth_dev_callback_process(dev, RTE_ETH_EVENT_INTR_LSC,
207 case VIRTCHNL_EVENT_PF_DRIVER_CLOSE:
208 PMD_DRV_LOG(DEBUG, "VIRTCHNL_EVENT_PF_DRIVER_CLOSE event");
211 PMD_DRV_LOG(ERR, " unknown event received %u", pf_msg->event);
217 iavf_handle_virtchnl_msg(struct rte_eth_dev *dev)
219 struct iavf_hw *hw = IAVF_DEV_PRIVATE_TO_HW(dev->data->dev_private);
220 struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(dev->data->dev_private);
221 struct iavf_arq_event_info info;
222 uint16_t pending, aq_opc;
223 enum virtchnl_ops msg_opc;
224 enum iavf_status msg_ret;
227 info.buf_len = IAVF_AQ_BUF_SZ;
229 PMD_DRV_LOG(ERR, "Buffer for adminq resp should not be NULL");
232 info.msg_buf = vf->aq_resp;
236 ret = iavf_clean_arq_element(hw, &info, &pending);
238 if (ret != IAVF_SUCCESS) {
239 PMD_DRV_LOG(INFO, "Failed to read msg from AdminQ,"
243 aq_opc = rte_le_to_cpu_16(info.desc.opcode);
244 /* For the message sent from pf to vf, opcode is stored in
245 * cookie_high of struct iavf_aq_desc, while return error code
246 * are stored in cookie_low, Which is done by PF driver.
248 msg_opc = (enum virtchnl_ops)rte_le_to_cpu_32(
249 info.desc.cookie_high);
250 msg_ret = (enum iavf_status)rte_le_to_cpu_32(
251 info.desc.cookie_low);
253 case iavf_aqc_opc_send_msg_to_vf:
254 if (msg_opc == VIRTCHNL_OP_EVENT) {
255 iavf_handle_pf_event_msg(dev, info.msg_buf,
258 /* read message and it's expected one */
259 if (msg_opc == vf->pend_cmd)
260 _notify_cmd(vf, msg_ret);
262 PMD_DRV_LOG(ERR, "command mismatch,"
264 vf->pend_cmd, msg_opc);
266 "adminq response is received,"
267 " opcode = %d", msg_opc);
271 PMD_DRV_LOG(DEBUG, "Request %u is not supported yet",
279 iavf_enable_vlan_strip(struct iavf_adapter *adapter)
281 struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(adapter);
282 struct iavf_cmd_info args;
285 memset(&args, 0, sizeof(args));
286 args.ops = VIRTCHNL_OP_ENABLE_VLAN_STRIPPING;
288 args.in_args_size = 0;
289 args.out_buffer = vf->aq_resp;
290 args.out_size = IAVF_AQ_BUF_SZ;
291 ret = iavf_execute_vf_cmd(adapter, &args);
293 PMD_DRV_LOG(ERR, "Failed to execute command of"
294 " OP_ENABLE_VLAN_STRIPPING");
300 iavf_disable_vlan_strip(struct iavf_adapter *adapter)
302 struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(adapter);
303 struct iavf_cmd_info args;
306 memset(&args, 0, sizeof(args));
307 args.ops = VIRTCHNL_OP_DISABLE_VLAN_STRIPPING;
309 args.in_args_size = 0;
310 args.out_buffer = vf->aq_resp;
311 args.out_size = IAVF_AQ_BUF_SZ;
312 ret = iavf_execute_vf_cmd(adapter, &args);
314 PMD_DRV_LOG(ERR, "Failed to execute command of"
315 " OP_DISABLE_VLAN_STRIPPING");
320 #define VIRTCHNL_VERSION_MAJOR_START 1
321 #define VIRTCHNL_VERSION_MINOR_START 1
323 /* Check API version with sync wait until version read from admin queue */
325 iavf_check_api_version(struct iavf_adapter *adapter)
327 struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(adapter);
328 struct virtchnl_version_info version, *pver;
329 struct iavf_cmd_info args;
332 version.major = VIRTCHNL_VERSION_MAJOR;
333 version.minor = VIRTCHNL_VERSION_MINOR;
335 args.ops = VIRTCHNL_OP_VERSION;
336 args.in_args = (uint8_t *)&version;
337 args.in_args_size = sizeof(version);
338 args.out_buffer = vf->aq_resp;
339 args.out_size = IAVF_AQ_BUF_SZ;
341 err = iavf_execute_vf_cmd(adapter, &args);
343 PMD_INIT_LOG(ERR, "Fail to execute command of OP_VERSION");
347 pver = (struct virtchnl_version_info *)args.out_buffer;
348 vf->virtchnl_version = *pver;
350 if (vf->virtchnl_version.major < VIRTCHNL_VERSION_MAJOR_START ||
351 (vf->virtchnl_version.major == VIRTCHNL_VERSION_MAJOR_START &&
352 vf->virtchnl_version.minor < VIRTCHNL_VERSION_MINOR_START)) {
353 PMD_INIT_LOG(ERR, "VIRTCHNL API version should not be lower"
354 " than (%u.%u) to support Adapative VF",
355 VIRTCHNL_VERSION_MAJOR_START,
356 VIRTCHNL_VERSION_MAJOR_START);
358 } else if (vf->virtchnl_version.major > VIRTCHNL_VERSION_MAJOR ||
359 (vf->virtchnl_version.major == VIRTCHNL_VERSION_MAJOR &&
360 vf->virtchnl_version.minor > VIRTCHNL_VERSION_MINOR)) {
361 PMD_INIT_LOG(ERR, "PF/VF API version mismatch:(%u.%u)-(%u.%u)",
362 vf->virtchnl_version.major,
363 vf->virtchnl_version.minor,
364 VIRTCHNL_VERSION_MAJOR,
365 VIRTCHNL_VERSION_MINOR);
369 PMD_DRV_LOG(DEBUG, "Peer is supported PF host");
374 iavf_get_vf_resource(struct iavf_adapter *adapter)
376 struct iavf_hw *hw = IAVF_DEV_PRIVATE_TO_HW(adapter);
377 struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(adapter);
378 struct iavf_cmd_info args;
382 args.ops = VIRTCHNL_OP_GET_VF_RESOURCES;
383 args.out_buffer = vf->aq_resp;
384 args.out_size = IAVF_AQ_BUF_SZ;
386 caps = IAVF_BASIC_OFFLOAD_CAPS | VIRTCHNL_VF_CAP_ADV_LINK_SPEED |
387 VIRTCHNL_VF_OFFLOAD_RX_FLEX_DESC |
388 VIRTCHNL_VF_OFFLOAD_FDIR_PF |
389 VIRTCHNL_VF_OFFLOAD_ADV_RSS_PF;
391 args.in_args = (uint8_t *)∩︀
392 args.in_args_size = sizeof(caps);
394 err = iavf_execute_vf_cmd(adapter, &args);
398 "Failed to execute command of OP_GET_VF_RESOURCE");
402 len = sizeof(struct virtchnl_vf_resource) +
403 IAVF_MAX_VF_VSI * sizeof(struct virtchnl_vsi_resource);
405 rte_memcpy(vf->vf_res, args.out_buffer,
406 RTE_MIN(args.out_size, len));
407 /* parse VF config message back from PF*/
408 iavf_vf_parse_hw_config(hw, vf->vf_res);
409 for (i = 0; i < vf->vf_res->num_vsis; i++) {
410 if (vf->vf_res->vsi_res[i].vsi_type == VIRTCHNL_VSI_SRIOV)
411 vf->vsi_res = &vf->vf_res->vsi_res[i];
415 PMD_INIT_LOG(ERR, "no LAN VSI found");
419 vf->vsi.vsi_id = vf->vsi_res->vsi_id;
420 vf->vsi.nb_qps = vf->vsi_res->num_queue_pairs;
421 vf->vsi.adapter = adapter;
427 iavf_get_supported_rxdid(struct iavf_adapter *adapter)
429 struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(adapter);
430 struct iavf_cmd_info args;
433 args.ops = VIRTCHNL_OP_GET_SUPPORTED_RXDIDS;
435 args.in_args_size = 0;
436 args.out_buffer = vf->aq_resp;
437 args.out_size = IAVF_AQ_BUF_SZ;
439 ret = iavf_execute_vf_cmd(adapter, &args);
442 "Failed to execute command of OP_GET_SUPPORTED_RXDIDS");
446 vf->supported_rxdid =
447 ((struct virtchnl_supported_rxdids *)args.out_buffer)->supported_rxdids;
453 iavf_enable_queues(struct iavf_adapter *adapter)
455 struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(adapter);
456 struct virtchnl_queue_select queue_select;
457 struct iavf_cmd_info args;
460 memset(&queue_select, 0, sizeof(queue_select));
461 queue_select.vsi_id = vf->vsi_res->vsi_id;
463 queue_select.rx_queues = BIT(adapter->eth_dev->data->nb_rx_queues) - 1;
464 queue_select.tx_queues = BIT(adapter->eth_dev->data->nb_tx_queues) - 1;
466 args.ops = VIRTCHNL_OP_ENABLE_QUEUES;
467 args.in_args = (u8 *)&queue_select;
468 args.in_args_size = sizeof(queue_select);
469 args.out_buffer = vf->aq_resp;
470 args.out_size = IAVF_AQ_BUF_SZ;
471 err = iavf_execute_vf_cmd(adapter, &args);
474 "Failed to execute command of OP_ENABLE_QUEUES");
481 iavf_disable_queues(struct iavf_adapter *adapter)
483 struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(adapter);
484 struct virtchnl_queue_select queue_select;
485 struct iavf_cmd_info args;
488 memset(&queue_select, 0, sizeof(queue_select));
489 queue_select.vsi_id = vf->vsi_res->vsi_id;
491 queue_select.rx_queues = BIT(adapter->eth_dev->data->nb_rx_queues) - 1;
492 queue_select.tx_queues = BIT(adapter->eth_dev->data->nb_tx_queues) - 1;
494 args.ops = VIRTCHNL_OP_DISABLE_QUEUES;
495 args.in_args = (u8 *)&queue_select;
496 args.in_args_size = sizeof(queue_select);
497 args.out_buffer = vf->aq_resp;
498 args.out_size = IAVF_AQ_BUF_SZ;
499 err = iavf_execute_vf_cmd(adapter, &args);
502 "Failed to execute command of OP_DISABLE_QUEUES");
509 iavf_switch_queue(struct iavf_adapter *adapter, uint16_t qid,
512 struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(adapter);
513 struct virtchnl_queue_select queue_select;
514 struct iavf_cmd_info args;
517 memset(&queue_select, 0, sizeof(queue_select));
518 queue_select.vsi_id = vf->vsi_res->vsi_id;
520 queue_select.rx_queues |= 1 << qid;
522 queue_select.tx_queues |= 1 << qid;
525 args.ops = VIRTCHNL_OP_ENABLE_QUEUES;
527 args.ops = VIRTCHNL_OP_DISABLE_QUEUES;
528 args.in_args = (u8 *)&queue_select;
529 args.in_args_size = sizeof(queue_select);
530 args.out_buffer = vf->aq_resp;
531 args.out_size = IAVF_AQ_BUF_SZ;
532 err = iavf_execute_vf_cmd(adapter, &args);
534 PMD_DRV_LOG(ERR, "Failed to execute command of %s",
535 on ? "OP_ENABLE_QUEUES" : "OP_DISABLE_QUEUES");
540 iavf_configure_rss_lut(struct iavf_adapter *adapter)
542 struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(adapter);
543 struct virtchnl_rss_lut *rss_lut;
544 struct iavf_cmd_info args;
547 len = sizeof(*rss_lut) + vf->vf_res->rss_lut_size - 1;
548 rss_lut = rte_zmalloc("rss_lut", len, 0);
552 rss_lut->vsi_id = vf->vsi_res->vsi_id;
553 rss_lut->lut_entries = vf->vf_res->rss_lut_size;
554 rte_memcpy(rss_lut->lut, vf->rss_lut, vf->vf_res->rss_lut_size);
556 args.ops = VIRTCHNL_OP_CONFIG_RSS_LUT;
557 args.in_args = (u8 *)rss_lut;
558 args.in_args_size = len;
559 args.out_buffer = vf->aq_resp;
560 args.out_size = IAVF_AQ_BUF_SZ;
562 err = iavf_execute_vf_cmd(adapter, &args);
565 "Failed to execute command of OP_CONFIG_RSS_LUT");
572 iavf_configure_rss_key(struct iavf_adapter *adapter)
574 struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(adapter);
575 struct virtchnl_rss_key *rss_key;
576 struct iavf_cmd_info args;
579 len = sizeof(*rss_key) + vf->vf_res->rss_key_size - 1;
580 rss_key = rte_zmalloc("rss_key", len, 0);
584 rss_key->vsi_id = vf->vsi_res->vsi_id;
585 rss_key->key_len = vf->vf_res->rss_key_size;
586 rte_memcpy(rss_key->key, vf->rss_key, vf->vf_res->rss_key_size);
588 args.ops = VIRTCHNL_OP_CONFIG_RSS_KEY;
589 args.in_args = (u8 *)rss_key;
590 args.in_args_size = len;
591 args.out_buffer = vf->aq_resp;
592 args.out_size = IAVF_AQ_BUF_SZ;
594 err = iavf_execute_vf_cmd(adapter, &args);
597 "Failed to execute command of OP_CONFIG_RSS_KEY");
604 iavf_configure_queues(struct iavf_adapter *adapter)
606 struct iavf_rx_queue **rxq =
607 (struct iavf_rx_queue **)adapter->eth_dev->data->rx_queues;
608 struct iavf_tx_queue **txq =
609 (struct iavf_tx_queue **)adapter->eth_dev->data->tx_queues;
610 struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(adapter);
611 struct virtchnl_vsi_queue_config_info *vc_config;
612 struct virtchnl_queue_pair_info *vc_qp;
613 struct iavf_cmd_info args;
617 size = sizeof(*vc_config) +
618 sizeof(vc_config->qpair[0]) * vf->num_queue_pairs;
619 vc_config = rte_zmalloc("cfg_queue", size, 0);
623 vc_config->vsi_id = vf->vsi_res->vsi_id;
624 vc_config->num_queue_pairs = vf->num_queue_pairs;
626 for (i = 0, vc_qp = vc_config->qpair;
627 i < vf->num_queue_pairs;
629 vc_qp->txq.vsi_id = vf->vsi_res->vsi_id;
630 vc_qp->txq.queue_id = i;
631 /* Virtchnnl configure queues by pairs */
632 if (i < adapter->eth_dev->data->nb_tx_queues) {
633 vc_qp->txq.ring_len = txq[i]->nb_tx_desc;
634 vc_qp->txq.dma_ring_addr = txq[i]->tx_ring_phys_addr;
636 vc_qp->rxq.vsi_id = vf->vsi_res->vsi_id;
637 vc_qp->rxq.queue_id = i;
638 vc_qp->rxq.max_pkt_size = vf->max_pkt_len;
639 /* Virtchnnl configure queues by pairs */
640 if (i < adapter->eth_dev->data->nb_rx_queues) {
641 vc_qp->rxq.ring_len = rxq[i]->nb_rx_desc;
642 vc_qp->rxq.dma_ring_addr = rxq[i]->rx_ring_phys_addr;
643 vc_qp->rxq.databuffer_size = rxq[i]->rx_buf_len;
646 #ifndef RTE_LIBRTE_IAVF_16BYTE_RX_DESC
647 if (vf->vf_res->vf_cap_flags &
648 VIRTCHNL_VF_OFFLOAD_RX_FLEX_DESC &&
649 vf->supported_rxdid & BIT(IAVF_RXDID_COMMS_OVS_1)) {
650 vc_qp->rxq.rxdid = IAVF_RXDID_COMMS_OVS_1;
651 PMD_DRV_LOG(NOTICE, "request RXDID == %d in "
652 "Queue[%d]", vc_qp->rxq.rxdid, i);
654 vc_qp->rxq.rxdid = IAVF_RXDID_LEGACY_1;
655 PMD_DRV_LOG(NOTICE, "request RXDID == %d in "
656 "Queue[%d]", vc_qp->rxq.rxdid, i);
659 if (vf->vf_res->vf_cap_flags &
660 VIRTCHNL_VF_OFFLOAD_RX_FLEX_DESC &&
661 vf->supported_rxdid & BIT(IAVF_RXDID_LEGACY_0)) {
662 vc_qp->rxq.rxdid = IAVF_RXDID_LEGACY_0;
663 PMD_DRV_LOG(NOTICE, "request RXDID == %d in "
664 "Queue[%d]", vc_qp->rxq.rxdid, i);
666 PMD_DRV_LOG(ERR, "RXDID == 0 is not supported");
672 memset(&args, 0, sizeof(args));
673 args.ops = VIRTCHNL_OP_CONFIG_VSI_QUEUES;
674 args.in_args = (uint8_t *)vc_config;
675 args.in_args_size = size;
676 args.out_buffer = vf->aq_resp;
677 args.out_size = IAVF_AQ_BUF_SZ;
679 err = iavf_execute_vf_cmd(adapter, &args);
681 PMD_DRV_LOG(ERR, "Failed to execute command of"
682 " VIRTCHNL_OP_CONFIG_VSI_QUEUES");
689 iavf_config_irq_map(struct iavf_adapter *adapter)
691 struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(adapter);
692 struct virtchnl_irq_map_info *map_info;
693 struct virtchnl_vector_map *vecmap;
694 struct iavf_cmd_info args;
697 len = sizeof(struct virtchnl_irq_map_info) +
698 sizeof(struct virtchnl_vector_map) * vf->nb_msix;
700 map_info = rte_zmalloc("map_info", len, 0);
704 map_info->num_vectors = vf->nb_msix;
705 for (i = 0; i < vf->nb_msix; i++) {
706 vecmap = &map_info->vecmap[i];
707 vecmap->vsi_id = vf->vsi_res->vsi_id;
708 vecmap->rxitr_idx = IAVF_ITR_INDEX_DEFAULT;
709 vecmap->vector_id = vf->msix_base + i;
711 vecmap->rxq_map = vf->rxq_map[vf->msix_base + i];
714 args.ops = VIRTCHNL_OP_CONFIG_IRQ_MAP;
715 args.in_args = (u8 *)map_info;
716 args.in_args_size = len;
717 args.out_buffer = vf->aq_resp;
718 args.out_size = IAVF_AQ_BUF_SZ;
719 err = iavf_execute_vf_cmd(adapter, &args);
721 PMD_DRV_LOG(ERR, "fail to execute command OP_CONFIG_IRQ_MAP");
728 iavf_add_del_all_mac_addr(struct iavf_adapter *adapter, bool add)
730 struct virtchnl_ether_addr_list *list;
731 struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(adapter);
732 struct rte_ether_addr *addr;
733 struct iavf_cmd_info args;
740 len = sizeof(struct virtchnl_ether_addr_list);
741 for (i = begin; i < IAVF_NUM_MACADDR_MAX; i++, next_begin++) {
742 addr = &adapter->eth_dev->data->mac_addrs[i];
743 if (rte_is_zero_ether_addr(addr))
745 len += sizeof(struct virtchnl_ether_addr);
746 if (len >= IAVF_AQ_BUF_SZ) {
752 list = rte_zmalloc("iavf_del_mac_buffer", len, 0);
754 PMD_DRV_LOG(ERR, "fail to allocate memory");
758 for (i = begin; i < next_begin; i++) {
759 addr = &adapter->eth_dev->data->mac_addrs[i];
760 if (rte_is_zero_ether_addr(addr))
762 rte_memcpy(list->list[j].addr, addr->addr_bytes,
763 sizeof(addr->addr_bytes));
764 PMD_DRV_LOG(DEBUG, "add/rm mac:%x:%x:%x:%x:%x:%x",
765 addr->addr_bytes[0], addr->addr_bytes[1],
766 addr->addr_bytes[2], addr->addr_bytes[3],
767 addr->addr_bytes[4], addr->addr_bytes[5]);
770 list->vsi_id = vf->vsi_res->vsi_id;
771 list->num_elements = j;
772 args.ops = add ? VIRTCHNL_OP_ADD_ETH_ADDR :
773 VIRTCHNL_OP_DEL_ETH_ADDR;
774 args.in_args = (uint8_t *)list;
775 args.in_args_size = len;
776 args.out_buffer = vf->aq_resp;
777 args.out_size = IAVF_AQ_BUF_SZ;
778 err = iavf_execute_vf_cmd(adapter, &args);
780 PMD_DRV_LOG(ERR, "fail to execute command %s",
781 add ? "OP_ADD_ETHER_ADDRESS" :
782 "OP_DEL_ETHER_ADDRESS");
785 } while (begin < IAVF_NUM_MACADDR_MAX);
789 iavf_query_stats(struct iavf_adapter *adapter,
790 struct virtchnl_eth_stats **pstats)
792 struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(adapter);
793 struct virtchnl_queue_select q_stats;
794 struct iavf_cmd_info args;
797 memset(&q_stats, 0, sizeof(q_stats));
798 q_stats.vsi_id = vf->vsi_res->vsi_id;
799 args.ops = VIRTCHNL_OP_GET_STATS;
800 args.in_args = (uint8_t *)&q_stats;
801 args.in_args_size = sizeof(q_stats);
802 args.out_buffer = vf->aq_resp;
803 args.out_size = IAVF_AQ_BUF_SZ;
805 err = iavf_execute_vf_cmd(adapter, &args);
807 PMD_DRV_LOG(ERR, "fail to execute command OP_GET_STATS");
811 *pstats = (struct virtchnl_eth_stats *)args.out_buffer;
816 iavf_config_promisc(struct iavf_adapter *adapter,
818 bool enable_multicast)
820 struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(adapter);
821 struct virtchnl_promisc_info promisc;
822 struct iavf_cmd_info args;
826 promisc.vsi_id = vf->vsi_res->vsi_id;
829 promisc.flags |= FLAG_VF_UNICAST_PROMISC;
831 if (enable_multicast)
832 promisc.flags |= FLAG_VF_MULTICAST_PROMISC;
834 args.ops = VIRTCHNL_OP_CONFIG_PROMISCUOUS_MODE;
835 args.in_args = (uint8_t *)&promisc;
836 args.in_args_size = sizeof(promisc);
837 args.out_buffer = vf->aq_resp;
838 args.out_size = IAVF_AQ_BUF_SZ;
840 err = iavf_execute_vf_cmd(adapter, &args);
844 "fail to execute command CONFIG_PROMISCUOUS_MODE");
849 iavf_add_del_eth_addr(struct iavf_adapter *adapter, struct rte_ether_addr *addr,
852 struct virtchnl_ether_addr_list *list;
853 struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(adapter);
854 uint8_t cmd_buffer[sizeof(struct virtchnl_ether_addr_list) +
855 sizeof(struct virtchnl_ether_addr)];
856 struct iavf_cmd_info args;
859 list = (struct virtchnl_ether_addr_list *)cmd_buffer;
860 list->vsi_id = vf->vsi_res->vsi_id;
861 list->num_elements = 1;
862 rte_memcpy(list->list[0].addr, addr->addr_bytes,
863 sizeof(addr->addr_bytes));
865 args.ops = add ? VIRTCHNL_OP_ADD_ETH_ADDR : VIRTCHNL_OP_DEL_ETH_ADDR;
866 args.in_args = cmd_buffer;
867 args.in_args_size = sizeof(cmd_buffer);
868 args.out_buffer = vf->aq_resp;
869 args.out_size = IAVF_AQ_BUF_SZ;
870 err = iavf_execute_vf_cmd(adapter, &args);
872 PMD_DRV_LOG(ERR, "fail to execute command %s",
873 add ? "OP_ADD_ETH_ADDR" : "OP_DEL_ETH_ADDR");
878 iavf_add_del_vlan(struct iavf_adapter *adapter, uint16_t vlanid, bool add)
880 struct virtchnl_vlan_filter_list *vlan_list;
881 struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(adapter);
882 uint8_t cmd_buffer[sizeof(struct virtchnl_vlan_filter_list) +
884 struct iavf_cmd_info args;
887 vlan_list = (struct virtchnl_vlan_filter_list *)cmd_buffer;
888 vlan_list->vsi_id = vf->vsi_res->vsi_id;
889 vlan_list->num_elements = 1;
890 vlan_list->vlan_id[0] = vlanid;
892 args.ops = add ? VIRTCHNL_OP_ADD_VLAN : VIRTCHNL_OP_DEL_VLAN;
893 args.in_args = cmd_buffer;
894 args.in_args_size = sizeof(cmd_buffer);
895 args.out_buffer = vf->aq_resp;
896 args.out_size = IAVF_AQ_BUF_SZ;
897 err = iavf_execute_vf_cmd(adapter, &args);
899 PMD_DRV_LOG(ERR, "fail to execute command %s",
900 add ? "OP_ADD_VLAN" : "OP_DEL_VLAN");
906 iavf_fdir_add(struct iavf_adapter *adapter,
907 struct iavf_fdir_conf *filter)
909 struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(adapter);
910 struct virtchnl_fdir_add *fdir_ret;
912 struct iavf_cmd_info args;
915 filter->add_fltr.vsi_id = vf->vsi_res->vsi_id;
916 filter->add_fltr.validate_only = 0;
918 args.ops = VIRTCHNL_OP_ADD_FDIR_FILTER;
919 args.in_args = (uint8_t *)(&filter->add_fltr);
920 args.in_args_size = sizeof(*(&filter->add_fltr));
921 args.out_buffer = vf->aq_resp;
922 args.out_size = IAVF_AQ_BUF_SZ;
924 err = iavf_execute_vf_cmd(adapter, &args);
926 PMD_DRV_LOG(ERR, "fail to execute command OP_ADD_FDIR_FILTER");
930 fdir_ret = (struct virtchnl_fdir_add *)args.out_buffer;
931 filter->flow_id = fdir_ret->flow_id;
933 if (fdir_ret->status == VIRTCHNL_FDIR_SUCCESS) {
935 "Succeed in adding rule request by PF");
936 } else if (fdir_ret->status == VIRTCHNL_FDIR_FAILURE_RULE_NORESOURCE) {
938 "Failed to add rule request due to no hw resource");
940 } else if (fdir_ret->status == VIRTCHNL_FDIR_FAILURE_RULE_EXIST) {
942 "Failed to add rule request due to the rule is already existed");
944 } else if (fdir_ret->status == VIRTCHNL_FDIR_FAILURE_RULE_CONFLICT) {
946 "Failed to add rule request due to the rule is conflict with existing rule");
948 } else if (fdir_ret->status == VIRTCHNL_FDIR_FAILURE_RULE_INVALID) {
950 "Failed to add rule request due to the hw doesn't support");
952 } else if (fdir_ret->status == VIRTCHNL_FDIR_FAILURE_RULE_TIMEOUT) {
954 "Failed to add rule request due to time out for programming");
958 "Failed to add rule request due to other reasons");
966 iavf_fdir_del(struct iavf_adapter *adapter,
967 struct iavf_fdir_conf *filter)
969 struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(adapter);
970 struct virtchnl_fdir_del *fdir_ret;
972 struct iavf_cmd_info args;
975 filter->del_fltr.vsi_id = vf->vsi_res->vsi_id;
976 filter->del_fltr.flow_id = filter->flow_id;
978 args.ops = VIRTCHNL_OP_DEL_FDIR_FILTER;
979 args.in_args = (uint8_t *)(&filter->del_fltr);
980 args.in_args_size = sizeof(filter->del_fltr);
981 args.out_buffer = vf->aq_resp;
982 args.out_size = IAVF_AQ_BUF_SZ;
984 err = iavf_execute_vf_cmd(adapter, &args);
986 PMD_DRV_LOG(ERR, "fail to execute command OP_DEL_FDIR_FILTER");
990 fdir_ret = (struct virtchnl_fdir_del *)args.out_buffer;
992 if (fdir_ret->status == VIRTCHNL_FDIR_SUCCESS) {
994 "Succeed in deleting rule request by PF");
995 } else if (fdir_ret->status == VIRTCHNL_FDIR_FAILURE_RULE_NONEXIST) {
997 "Failed to delete rule request due to this rule doesn't exist");
999 } else if (fdir_ret->status == VIRTCHNL_FDIR_FAILURE_RULE_TIMEOUT) {
1001 "Failed to delete rule request due to time out for programming");
1005 "Failed to delete rule request due to other reasons");
1013 iavf_fdir_check(struct iavf_adapter *adapter,
1014 struct iavf_fdir_conf *filter)
1016 struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(adapter);
1017 struct virtchnl_fdir_add *fdir_ret;
1019 struct iavf_cmd_info args;
1022 filter->add_fltr.vsi_id = vf->vsi_res->vsi_id;
1023 filter->add_fltr.validate_only = 1;
1025 args.ops = VIRTCHNL_OP_ADD_FDIR_FILTER;
1026 args.in_args = (uint8_t *)(&filter->add_fltr);
1027 args.in_args_size = sizeof(*(&filter->add_fltr));
1028 args.out_buffer = vf->aq_resp;
1029 args.out_size = IAVF_AQ_BUF_SZ;
1031 err = iavf_execute_vf_cmd(adapter, &args);
1033 PMD_DRV_LOG(ERR, "fail to check flow direcotor rule");
1037 fdir_ret = (struct virtchnl_fdir_add *)args.out_buffer;
1039 if (fdir_ret->status == VIRTCHNL_FDIR_SUCCESS) {
1041 "Succeed in checking rule request by PF");
1042 } else if (fdir_ret->status == VIRTCHNL_FDIR_FAILURE_RULE_INVALID) {
1044 "Failed to check rule request due to parameters validation"
1045 " or HW doesn't support");
1049 "Failed to check rule request due to other reasons");
1057 iavf_add_del_rss_cfg(struct iavf_adapter *adapter,
1058 struct virtchnl_rss_cfg *rss_cfg, bool add)
1060 struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(adapter);
1061 struct iavf_cmd_info args;
1064 memset(&args, 0, sizeof(args));
1065 args.ops = add ? VIRTCHNL_OP_ADD_RSS_CFG :
1066 VIRTCHNL_OP_DEL_RSS_CFG;
1067 args.in_args = (u8 *)rss_cfg;
1068 args.in_args_size = sizeof(*rss_cfg);
1069 args.out_buffer = vf->aq_resp;
1070 args.out_size = IAVF_AQ_BUF_SZ;
1072 err = iavf_execute_vf_cmd(adapter, &args);
1075 "Failed to execute command of %s",
1076 add ? "OP_ADD_RSS_CFG" :
1077 "OP_DEL_RSS_INPUT_CFG");
1083 iavf_add_del_mc_addr_list(struct iavf_adapter *adapter,
1084 struct rte_ether_addr *mc_addrs,
1085 uint32_t mc_addrs_num, bool add)
1087 struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(adapter);
1088 uint8_t cmd_buffer[sizeof(struct virtchnl_ether_addr_list) +
1089 (IAVF_NUM_MACADDR_MAX * sizeof(struct virtchnl_ether_addr))];
1090 struct virtchnl_ether_addr_list *list;
1091 struct iavf_cmd_info args;
1095 if (mc_addrs == NULL || mc_addrs_num == 0)
1098 if (mc_addrs_num > IAVF_NUM_MACADDR_MAX)
1101 list = (struct virtchnl_ether_addr_list *)cmd_buffer;
1102 list->vsi_id = vf->vsi_res->vsi_id;
1103 list->num_elements = mc_addrs_num;
1105 for (i = 0; i < mc_addrs_num; i++) {
1106 if (!IAVF_IS_MULTICAST(mc_addrs[i].addr_bytes)) {
1107 PMD_DRV_LOG(ERR, "Invalid mac:%x:%x:%x:%x:%x:%x",
1108 mc_addrs[i].addr_bytes[0],
1109 mc_addrs[i].addr_bytes[1],
1110 mc_addrs[i].addr_bytes[2],
1111 mc_addrs[i].addr_bytes[3],
1112 mc_addrs[i].addr_bytes[4],
1113 mc_addrs[i].addr_bytes[5]);
1117 memcpy(list->list[i].addr, mc_addrs[i].addr_bytes,
1118 sizeof(list->list[i].addr));
1121 args.ops = add ? VIRTCHNL_OP_ADD_ETH_ADDR : VIRTCHNL_OP_DEL_ETH_ADDR;
1122 args.in_args = cmd_buffer;
1123 args.in_args_size = sizeof(struct virtchnl_ether_addr_list) +
1124 i * sizeof(struct virtchnl_ether_addr);
1125 args.out_buffer = vf->aq_resp;
1126 args.out_size = IAVF_AQ_BUF_SZ;
1127 err = iavf_execute_vf_cmd(adapter, &args);
1130 PMD_DRV_LOG(ERR, "fail to execute command %s",
1131 add ? "OP_ADD_ETH_ADDR" : "OP_DEL_ETH_ADDR");