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, NULL);
206 case VIRTCHNL_EVENT_PF_DRIVER_CLOSE:
207 PMD_DRV_LOG(DEBUG, "VIRTCHNL_EVENT_PF_DRIVER_CLOSE event");
210 PMD_DRV_LOG(ERR, " unknown event received %u", pf_msg->event);
216 iavf_handle_virtchnl_msg(struct rte_eth_dev *dev)
218 struct iavf_hw *hw = IAVF_DEV_PRIVATE_TO_HW(dev->data->dev_private);
219 struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(dev->data->dev_private);
220 struct iavf_arq_event_info info;
221 uint16_t pending, aq_opc;
222 enum virtchnl_ops msg_opc;
223 enum iavf_status msg_ret;
226 info.buf_len = IAVF_AQ_BUF_SZ;
228 PMD_DRV_LOG(ERR, "Buffer for adminq resp should not be NULL");
231 info.msg_buf = vf->aq_resp;
235 ret = iavf_clean_arq_element(hw, &info, &pending);
237 if (ret != IAVF_SUCCESS) {
238 PMD_DRV_LOG(INFO, "Failed to read msg from AdminQ,"
242 aq_opc = rte_le_to_cpu_16(info.desc.opcode);
243 /* For the message sent from pf to vf, opcode is stored in
244 * cookie_high of struct iavf_aq_desc, while return error code
245 * are stored in cookie_low, Which is done by PF driver.
247 msg_opc = (enum virtchnl_ops)rte_le_to_cpu_32(
248 info.desc.cookie_high);
249 msg_ret = (enum iavf_status)rte_le_to_cpu_32(
250 info.desc.cookie_low);
252 case iavf_aqc_opc_send_msg_to_vf:
253 if (msg_opc == VIRTCHNL_OP_EVENT) {
254 iavf_handle_pf_event_msg(dev, info.msg_buf,
257 /* read message and it's expected one */
258 if (msg_opc == vf->pend_cmd)
259 _notify_cmd(vf, msg_ret);
261 PMD_DRV_LOG(ERR, "command mismatch,"
263 vf->pend_cmd, msg_opc);
265 "adminq response is received,"
266 " opcode = %d", msg_opc);
270 PMD_DRV_LOG(DEBUG, "Request %u is not supported yet",
278 iavf_enable_vlan_strip(struct iavf_adapter *adapter)
280 struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(adapter);
281 struct iavf_cmd_info args;
284 memset(&args, 0, sizeof(args));
285 args.ops = VIRTCHNL_OP_ENABLE_VLAN_STRIPPING;
287 args.in_args_size = 0;
288 args.out_buffer = vf->aq_resp;
289 args.out_size = IAVF_AQ_BUF_SZ;
290 ret = iavf_execute_vf_cmd(adapter, &args);
292 PMD_DRV_LOG(ERR, "Failed to execute command of"
293 " OP_ENABLE_VLAN_STRIPPING");
299 iavf_disable_vlan_strip(struct iavf_adapter *adapter)
301 struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(adapter);
302 struct iavf_cmd_info args;
305 memset(&args, 0, sizeof(args));
306 args.ops = VIRTCHNL_OP_DISABLE_VLAN_STRIPPING;
308 args.in_args_size = 0;
309 args.out_buffer = vf->aq_resp;
310 args.out_size = IAVF_AQ_BUF_SZ;
311 ret = iavf_execute_vf_cmd(adapter, &args);
313 PMD_DRV_LOG(ERR, "Failed to execute command of"
314 " OP_DISABLE_VLAN_STRIPPING");
319 #define VIRTCHNL_VERSION_MAJOR_START 1
320 #define VIRTCHNL_VERSION_MINOR_START 1
322 /* Check API version with sync wait until version read from admin queue */
324 iavf_check_api_version(struct iavf_adapter *adapter)
326 struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(adapter);
327 struct virtchnl_version_info version, *pver;
328 struct iavf_cmd_info args;
331 version.major = VIRTCHNL_VERSION_MAJOR;
332 version.minor = VIRTCHNL_VERSION_MINOR;
334 args.ops = VIRTCHNL_OP_VERSION;
335 args.in_args = (uint8_t *)&version;
336 args.in_args_size = sizeof(version);
337 args.out_buffer = vf->aq_resp;
338 args.out_size = IAVF_AQ_BUF_SZ;
340 err = iavf_execute_vf_cmd(adapter, &args);
342 PMD_INIT_LOG(ERR, "Fail to execute command of OP_VERSION");
346 pver = (struct virtchnl_version_info *)args.out_buffer;
347 vf->virtchnl_version = *pver;
349 if (vf->virtchnl_version.major < VIRTCHNL_VERSION_MAJOR_START ||
350 (vf->virtchnl_version.major == VIRTCHNL_VERSION_MAJOR_START &&
351 vf->virtchnl_version.minor < VIRTCHNL_VERSION_MINOR_START)) {
352 PMD_INIT_LOG(ERR, "VIRTCHNL API version should not be lower"
353 " than (%u.%u) to support Adapative VF",
354 VIRTCHNL_VERSION_MAJOR_START,
355 VIRTCHNL_VERSION_MAJOR_START);
357 } else if (vf->virtchnl_version.major > VIRTCHNL_VERSION_MAJOR ||
358 (vf->virtchnl_version.major == VIRTCHNL_VERSION_MAJOR &&
359 vf->virtchnl_version.minor > VIRTCHNL_VERSION_MINOR)) {
360 PMD_INIT_LOG(ERR, "PF/VF API version mismatch:(%u.%u)-(%u.%u)",
361 vf->virtchnl_version.major,
362 vf->virtchnl_version.minor,
363 VIRTCHNL_VERSION_MAJOR,
364 VIRTCHNL_VERSION_MINOR);
368 PMD_DRV_LOG(DEBUG, "Peer is supported PF host");
373 iavf_get_vf_resource(struct iavf_adapter *adapter)
375 struct iavf_hw *hw = IAVF_DEV_PRIVATE_TO_HW(adapter);
376 struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(adapter);
377 struct iavf_cmd_info args;
381 args.ops = VIRTCHNL_OP_GET_VF_RESOURCES;
382 args.out_buffer = vf->aq_resp;
383 args.out_size = IAVF_AQ_BUF_SZ;
385 caps = IAVF_BASIC_OFFLOAD_CAPS | VIRTCHNL_VF_CAP_ADV_LINK_SPEED |
386 VIRTCHNL_VF_OFFLOAD_RX_FLEX_DESC |
387 VIRTCHNL_VF_OFFLOAD_FDIR_PF |
388 VIRTCHNL_VF_OFFLOAD_ADV_RSS_PF;
390 args.in_args = (uint8_t *)∩︀
391 args.in_args_size = sizeof(caps);
393 err = iavf_execute_vf_cmd(adapter, &args);
397 "Failed to execute command of OP_GET_VF_RESOURCE");
401 len = sizeof(struct virtchnl_vf_resource) +
402 IAVF_MAX_VF_VSI * sizeof(struct virtchnl_vsi_resource);
404 rte_memcpy(vf->vf_res, args.out_buffer,
405 RTE_MIN(args.out_size, len));
406 /* parse VF config message back from PF*/
407 iavf_vf_parse_hw_config(hw, vf->vf_res);
408 for (i = 0; i < vf->vf_res->num_vsis; i++) {
409 if (vf->vf_res->vsi_res[i].vsi_type == VIRTCHNL_VSI_SRIOV)
410 vf->vsi_res = &vf->vf_res->vsi_res[i];
414 PMD_INIT_LOG(ERR, "no LAN VSI found");
418 vf->vsi.vsi_id = vf->vsi_res->vsi_id;
419 vf->vsi.nb_qps = vf->vsi_res->num_queue_pairs;
420 vf->vsi.adapter = adapter;
426 iavf_get_supported_rxdid(struct iavf_adapter *adapter)
428 struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(adapter);
429 struct iavf_cmd_info args;
432 args.ops = VIRTCHNL_OP_GET_SUPPORTED_RXDIDS;
434 args.in_args_size = 0;
435 args.out_buffer = vf->aq_resp;
436 args.out_size = IAVF_AQ_BUF_SZ;
438 ret = iavf_execute_vf_cmd(adapter, &args);
441 "Failed to execute command of OP_GET_SUPPORTED_RXDIDS");
445 vf->supported_rxdid =
446 ((struct virtchnl_supported_rxdids *)args.out_buffer)->supported_rxdids;
452 iavf_enable_queues(struct iavf_adapter *adapter)
454 struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(adapter);
455 struct virtchnl_queue_select queue_select;
456 struct iavf_cmd_info args;
459 memset(&queue_select, 0, sizeof(queue_select));
460 queue_select.vsi_id = vf->vsi_res->vsi_id;
462 queue_select.rx_queues = BIT(adapter->eth_dev->data->nb_rx_queues) - 1;
463 queue_select.tx_queues = BIT(adapter->eth_dev->data->nb_tx_queues) - 1;
465 args.ops = VIRTCHNL_OP_ENABLE_QUEUES;
466 args.in_args = (u8 *)&queue_select;
467 args.in_args_size = sizeof(queue_select);
468 args.out_buffer = vf->aq_resp;
469 args.out_size = IAVF_AQ_BUF_SZ;
470 err = iavf_execute_vf_cmd(adapter, &args);
473 "Failed to execute command of OP_ENABLE_QUEUES");
480 iavf_disable_queues(struct iavf_adapter *adapter)
482 struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(adapter);
483 struct virtchnl_queue_select queue_select;
484 struct iavf_cmd_info args;
487 memset(&queue_select, 0, sizeof(queue_select));
488 queue_select.vsi_id = vf->vsi_res->vsi_id;
490 queue_select.rx_queues = BIT(adapter->eth_dev->data->nb_rx_queues) - 1;
491 queue_select.tx_queues = BIT(adapter->eth_dev->data->nb_tx_queues) - 1;
493 args.ops = VIRTCHNL_OP_DISABLE_QUEUES;
494 args.in_args = (u8 *)&queue_select;
495 args.in_args_size = sizeof(queue_select);
496 args.out_buffer = vf->aq_resp;
497 args.out_size = IAVF_AQ_BUF_SZ;
498 err = iavf_execute_vf_cmd(adapter, &args);
501 "Failed to execute command of OP_DISABLE_QUEUES");
508 iavf_switch_queue(struct iavf_adapter *adapter, uint16_t qid,
511 struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(adapter);
512 struct virtchnl_queue_select queue_select;
513 struct iavf_cmd_info args;
516 memset(&queue_select, 0, sizeof(queue_select));
517 queue_select.vsi_id = vf->vsi_res->vsi_id;
519 queue_select.rx_queues |= 1 << qid;
521 queue_select.tx_queues |= 1 << qid;
524 args.ops = VIRTCHNL_OP_ENABLE_QUEUES;
526 args.ops = VIRTCHNL_OP_DISABLE_QUEUES;
527 args.in_args = (u8 *)&queue_select;
528 args.in_args_size = sizeof(queue_select);
529 args.out_buffer = vf->aq_resp;
530 args.out_size = IAVF_AQ_BUF_SZ;
531 err = iavf_execute_vf_cmd(adapter, &args);
533 PMD_DRV_LOG(ERR, "Failed to execute command of %s",
534 on ? "OP_ENABLE_QUEUES" : "OP_DISABLE_QUEUES");
539 iavf_configure_rss_lut(struct iavf_adapter *adapter)
541 struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(adapter);
542 struct virtchnl_rss_lut *rss_lut;
543 struct iavf_cmd_info args;
546 len = sizeof(*rss_lut) + vf->vf_res->rss_lut_size - 1;
547 rss_lut = rte_zmalloc("rss_lut", len, 0);
551 rss_lut->vsi_id = vf->vsi_res->vsi_id;
552 rss_lut->lut_entries = vf->vf_res->rss_lut_size;
553 rte_memcpy(rss_lut->lut, vf->rss_lut, vf->vf_res->rss_lut_size);
555 args.ops = VIRTCHNL_OP_CONFIG_RSS_LUT;
556 args.in_args = (u8 *)rss_lut;
557 args.in_args_size = len;
558 args.out_buffer = vf->aq_resp;
559 args.out_size = IAVF_AQ_BUF_SZ;
561 err = iavf_execute_vf_cmd(adapter, &args);
564 "Failed to execute command of OP_CONFIG_RSS_LUT");
571 iavf_configure_rss_key(struct iavf_adapter *adapter)
573 struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(adapter);
574 struct virtchnl_rss_key *rss_key;
575 struct iavf_cmd_info args;
578 len = sizeof(*rss_key) + vf->vf_res->rss_key_size - 1;
579 rss_key = rte_zmalloc("rss_key", len, 0);
583 rss_key->vsi_id = vf->vsi_res->vsi_id;
584 rss_key->key_len = vf->vf_res->rss_key_size;
585 rte_memcpy(rss_key->key, vf->rss_key, vf->vf_res->rss_key_size);
587 args.ops = VIRTCHNL_OP_CONFIG_RSS_KEY;
588 args.in_args = (u8 *)rss_key;
589 args.in_args_size = len;
590 args.out_buffer = vf->aq_resp;
591 args.out_size = IAVF_AQ_BUF_SZ;
593 err = iavf_execute_vf_cmd(adapter, &args);
596 "Failed to execute command of OP_CONFIG_RSS_KEY");
603 iavf_configure_queues(struct iavf_adapter *adapter)
605 struct iavf_rx_queue **rxq =
606 (struct iavf_rx_queue **)adapter->eth_dev->data->rx_queues;
607 struct iavf_tx_queue **txq =
608 (struct iavf_tx_queue **)adapter->eth_dev->data->tx_queues;
609 struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(adapter);
610 struct virtchnl_vsi_queue_config_info *vc_config;
611 struct virtchnl_queue_pair_info *vc_qp;
612 struct iavf_cmd_info args;
616 size = sizeof(*vc_config) +
617 sizeof(vc_config->qpair[0]) * vf->num_queue_pairs;
618 vc_config = rte_zmalloc("cfg_queue", size, 0);
622 vc_config->vsi_id = vf->vsi_res->vsi_id;
623 vc_config->num_queue_pairs = vf->num_queue_pairs;
625 for (i = 0, vc_qp = vc_config->qpair;
626 i < vf->num_queue_pairs;
628 vc_qp->txq.vsi_id = vf->vsi_res->vsi_id;
629 vc_qp->txq.queue_id = i;
630 /* Virtchnnl configure queues by pairs */
631 if (i < adapter->eth_dev->data->nb_tx_queues) {
632 vc_qp->txq.ring_len = txq[i]->nb_tx_desc;
633 vc_qp->txq.dma_ring_addr = txq[i]->tx_ring_phys_addr;
635 vc_qp->rxq.vsi_id = vf->vsi_res->vsi_id;
636 vc_qp->rxq.queue_id = i;
637 vc_qp->rxq.max_pkt_size = vf->max_pkt_len;
638 /* Virtchnnl configure queues by pairs */
639 if (i < adapter->eth_dev->data->nb_rx_queues) {
640 vc_qp->rxq.ring_len = rxq[i]->nb_rx_desc;
641 vc_qp->rxq.dma_ring_addr = rxq[i]->rx_ring_phys_addr;
642 vc_qp->rxq.databuffer_size = rxq[i]->rx_buf_len;
645 #ifndef RTE_LIBRTE_IAVF_16BYTE_RX_DESC
646 if (vf->vf_res->vf_cap_flags &
647 VIRTCHNL_VF_OFFLOAD_RX_FLEX_DESC &&
648 vf->supported_rxdid & BIT(IAVF_RXDID_COMMS_OVS_1)) {
649 vc_qp->rxq.rxdid = IAVF_RXDID_COMMS_OVS_1;
650 PMD_DRV_LOG(NOTICE, "request RXDID == %d in "
651 "Queue[%d]", vc_qp->rxq.rxdid, i);
653 vc_qp->rxq.rxdid = IAVF_RXDID_LEGACY_1;
654 PMD_DRV_LOG(NOTICE, "request RXDID == %d in "
655 "Queue[%d]", vc_qp->rxq.rxdid, i);
658 if (vf->vf_res->vf_cap_flags &
659 VIRTCHNL_VF_OFFLOAD_RX_FLEX_DESC &&
660 vf->supported_rxdid & BIT(IAVF_RXDID_LEGACY_0)) {
661 vc_qp->rxq.rxdid = IAVF_RXDID_LEGACY_0;
662 PMD_DRV_LOG(NOTICE, "request RXDID == %d in "
663 "Queue[%d]", vc_qp->rxq.rxdid, i);
665 PMD_DRV_LOG(ERR, "RXDID == 0 is not supported");
671 memset(&args, 0, sizeof(args));
672 args.ops = VIRTCHNL_OP_CONFIG_VSI_QUEUES;
673 args.in_args = (uint8_t *)vc_config;
674 args.in_args_size = size;
675 args.out_buffer = vf->aq_resp;
676 args.out_size = IAVF_AQ_BUF_SZ;
678 err = iavf_execute_vf_cmd(adapter, &args);
680 PMD_DRV_LOG(ERR, "Failed to execute command of"
681 " VIRTCHNL_OP_CONFIG_VSI_QUEUES");
688 iavf_config_irq_map(struct iavf_adapter *adapter)
690 struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(adapter);
691 struct virtchnl_irq_map_info *map_info;
692 struct virtchnl_vector_map *vecmap;
693 struct iavf_cmd_info args;
696 len = sizeof(struct virtchnl_irq_map_info) +
697 sizeof(struct virtchnl_vector_map) * vf->nb_msix;
699 map_info = rte_zmalloc("map_info", len, 0);
703 map_info->num_vectors = vf->nb_msix;
704 for (i = 0; i < vf->nb_msix; i++) {
705 vecmap = &map_info->vecmap[i];
706 vecmap->vsi_id = vf->vsi_res->vsi_id;
707 vecmap->rxitr_idx = IAVF_ITR_INDEX_DEFAULT;
708 vecmap->vector_id = vf->msix_base + i;
710 vecmap->rxq_map = vf->rxq_map[vf->msix_base + i];
713 args.ops = VIRTCHNL_OP_CONFIG_IRQ_MAP;
714 args.in_args = (u8 *)map_info;
715 args.in_args_size = len;
716 args.out_buffer = vf->aq_resp;
717 args.out_size = IAVF_AQ_BUF_SZ;
718 err = iavf_execute_vf_cmd(adapter, &args);
720 PMD_DRV_LOG(ERR, "fail to execute command OP_CONFIG_IRQ_MAP");
727 iavf_add_del_all_mac_addr(struct iavf_adapter *adapter, bool add)
729 struct virtchnl_ether_addr_list *list;
730 struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(adapter);
731 struct rte_ether_addr *addr;
732 struct iavf_cmd_info args;
739 len = sizeof(struct virtchnl_ether_addr_list);
740 for (i = begin; i < IAVF_NUM_MACADDR_MAX; i++, next_begin++) {
741 addr = &adapter->eth_dev->data->mac_addrs[i];
742 if (rte_is_zero_ether_addr(addr))
744 len += sizeof(struct virtchnl_ether_addr);
745 if (len >= IAVF_AQ_BUF_SZ) {
751 list = rte_zmalloc("iavf_del_mac_buffer", len, 0);
753 PMD_DRV_LOG(ERR, "fail to allocate memory");
757 for (i = begin; i < next_begin; i++) {
758 addr = &adapter->eth_dev->data->mac_addrs[i];
759 if (rte_is_zero_ether_addr(addr))
761 rte_memcpy(list->list[j].addr, addr->addr_bytes,
762 sizeof(addr->addr_bytes));
763 PMD_DRV_LOG(DEBUG, "add/rm mac:%x:%x:%x:%x:%x:%x",
764 addr->addr_bytes[0], addr->addr_bytes[1],
765 addr->addr_bytes[2], addr->addr_bytes[3],
766 addr->addr_bytes[4], addr->addr_bytes[5]);
769 list->vsi_id = vf->vsi_res->vsi_id;
770 list->num_elements = j;
771 args.ops = add ? VIRTCHNL_OP_ADD_ETH_ADDR :
772 VIRTCHNL_OP_DEL_ETH_ADDR;
773 args.in_args = (uint8_t *)list;
774 args.in_args_size = len;
775 args.out_buffer = vf->aq_resp;
776 args.out_size = IAVF_AQ_BUF_SZ;
777 err = iavf_execute_vf_cmd(adapter, &args);
779 PMD_DRV_LOG(ERR, "fail to execute command %s",
780 add ? "OP_ADD_ETHER_ADDRESS" :
781 "OP_DEL_ETHER_ADDRESS");
784 } while (begin < IAVF_NUM_MACADDR_MAX);
788 iavf_query_stats(struct iavf_adapter *adapter,
789 struct virtchnl_eth_stats **pstats)
791 struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(adapter);
792 struct virtchnl_queue_select q_stats;
793 struct iavf_cmd_info args;
796 memset(&q_stats, 0, sizeof(q_stats));
797 q_stats.vsi_id = vf->vsi_res->vsi_id;
798 args.ops = VIRTCHNL_OP_GET_STATS;
799 args.in_args = (uint8_t *)&q_stats;
800 args.in_args_size = sizeof(q_stats);
801 args.out_buffer = vf->aq_resp;
802 args.out_size = IAVF_AQ_BUF_SZ;
804 err = iavf_execute_vf_cmd(adapter, &args);
806 PMD_DRV_LOG(ERR, "fail to execute command OP_GET_STATS");
810 *pstats = (struct virtchnl_eth_stats *)args.out_buffer;
815 iavf_config_promisc(struct iavf_adapter *adapter,
817 bool enable_multicast)
819 struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(adapter);
820 struct virtchnl_promisc_info promisc;
821 struct iavf_cmd_info args;
825 promisc.vsi_id = vf->vsi_res->vsi_id;
828 promisc.flags |= FLAG_VF_UNICAST_PROMISC;
830 if (enable_multicast)
831 promisc.flags |= FLAG_VF_MULTICAST_PROMISC;
833 args.ops = VIRTCHNL_OP_CONFIG_PROMISCUOUS_MODE;
834 args.in_args = (uint8_t *)&promisc;
835 args.in_args_size = sizeof(promisc);
836 args.out_buffer = vf->aq_resp;
837 args.out_size = IAVF_AQ_BUF_SZ;
839 err = iavf_execute_vf_cmd(adapter, &args);
843 "fail to execute command CONFIG_PROMISCUOUS_MODE");
848 iavf_add_del_eth_addr(struct iavf_adapter *adapter, struct rte_ether_addr *addr,
851 struct virtchnl_ether_addr_list *list;
852 struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(adapter);
853 uint8_t cmd_buffer[sizeof(struct virtchnl_ether_addr_list) +
854 sizeof(struct virtchnl_ether_addr)];
855 struct iavf_cmd_info args;
858 list = (struct virtchnl_ether_addr_list *)cmd_buffer;
859 list->vsi_id = vf->vsi_res->vsi_id;
860 list->num_elements = 1;
861 rte_memcpy(list->list[0].addr, addr->addr_bytes,
862 sizeof(addr->addr_bytes));
864 args.ops = add ? VIRTCHNL_OP_ADD_ETH_ADDR : VIRTCHNL_OP_DEL_ETH_ADDR;
865 args.in_args = cmd_buffer;
866 args.in_args_size = sizeof(cmd_buffer);
867 args.out_buffer = vf->aq_resp;
868 args.out_size = IAVF_AQ_BUF_SZ;
869 err = iavf_execute_vf_cmd(adapter, &args);
871 PMD_DRV_LOG(ERR, "fail to execute command %s",
872 add ? "OP_ADD_ETH_ADDR" : "OP_DEL_ETH_ADDR");
877 iavf_add_del_vlan(struct iavf_adapter *adapter, uint16_t vlanid, bool add)
879 struct virtchnl_vlan_filter_list *vlan_list;
880 struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(adapter);
881 uint8_t cmd_buffer[sizeof(struct virtchnl_vlan_filter_list) +
883 struct iavf_cmd_info args;
886 vlan_list = (struct virtchnl_vlan_filter_list *)cmd_buffer;
887 vlan_list->vsi_id = vf->vsi_res->vsi_id;
888 vlan_list->num_elements = 1;
889 vlan_list->vlan_id[0] = vlanid;
891 args.ops = add ? VIRTCHNL_OP_ADD_VLAN : VIRTCHNL_OP_DEL_VLAN;
892 args.in_args = cmd_buffer;
893 args.in_args_size = sizeof(cmd_buffer);
894 args.out_buffer = vf->aq_resp;
895 args.out_size = IAVF_AQ_BUF_SZ;
896 err = iavf_execute_vf_cmd(adapter, &args);
898 PMD_DRV_LOG(ERR, "fail to execute command %s",
899 add ? "OP_ADD_VLAN" : "OP_DEL_VLAN");
905 iavf_fdir_add(struct iavf_adapter *adapter,
906 struct iavf_fdir_conf *filter)
908 struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(adapter);
909 struct virtchnl_fdir_add *fdir_ret;
911 struct iavf_cmd_info args;
914 filter->add_fltr.vsi_id = vf->vsi_res->vsi_id;
915 filter->add_fltr.validate_only = 0;
917 args.ops = VIRTCHNL_OP_ADD_FDIR_FILTER;
918 args.in_args = (uint8_t *)(&filter->add_fltr);
919 args.in_args_size = sizeof(*(&filter->add_fltr));
920 args.out_buffer = vf->aq_resp;
921 args.out_size = IAVF_AQ_BUF_SZ;
923 err = iavf_execute_vf_cmd(adapter, &args);
925 PMD_DRV_LOG(ERR, "fail to execute command OP_ADD_FDIR_FILTER");
929 fdir_ret = (struct virtchnl_fdir_add *)args.out_buffer;
930 filter->flow_id = fdir_ret->flow_id;
932 if (fdir_ret->status == VIRTCHNL_FDIR_SUCCESS) {
934 "Succeed in adding rule request by PF");
935 } else if (fdir_ret->status == VIRTCHNL_FDIR_FAILURE_RULE_NORESOURCE) {
937 "Failed to add rule request due to no hw resource");
939 } else if (fdir_ret->status == VIRTCHNL_FDIR_FAILURE_RULE_EXIST) {
941 "Failed to add rule request due to the rule is already existed");
943 } else if (fdir_ret->status == VIRTCHNL_FDIR_FAILURE_RULE_CONFLICT) {
945 "Failed to add rule request due to the rule is conflict with existing rule");
947 } else if (fdir_ret->status == VIRTCHNL_FDIR_FAILURE_RULE_INVALID) {
949 "Failed to add rule request due to the hw doesn't support");
951 } else if (fdir_ret->status == VIRTCHNL_FDIR_FAILURE_RULE_TIMEOUT) {
953 "Failed to add rule request due to time out for programming");
957 "Failed to add rule request due to other reasons");
965 iavf_fdir_del(struct iavf_adapter *adapter,
966 struct iavf_fdir_conf *filter)
968 struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(adapter);
969 struct virtchnl_fdir_del *fdir_ret;
971 struct iavf_cmd_info args;
974 filter->del_fltr.vsi_id = vf->vsi_res->vsi_id;
975 filter->del_fltr.flow_id = filter->flow_id;
977 args.ops = VIRTCHNL_OP_DEL_FDIR_FILTER;
978 args.in_args = (uint8_t *)(&filter->del_fltr);
979 args.in_args_size = sizeof(filter->del_fltr);
980 args.out_buffer = vf->aq_resp;
981 args.out_size = IAVF_AQ_BUF_SZ;
983 err = iavf_execute_vf_cmd(adapter, &args);
985 PMD_DRV_LOG(ERR, "fail to execute command OP_DEL_FDIR_FILTER");
989 fdir_ret = (struct virtchnl_fdir_del *)args.out_buffer;
991 if (fdir_ret->status == VIRTCHNL_FDIR_SUCCESS) {
993 "Succeed in deleting rule request by PF");
994 } else if (fdir_ret->status == VIRTCHNL_FDIR_FAILURE_RULE_NONEXIST) {
996 "Failed to delete rule request due to this rule doesn't exist");
998 } else if (fdir_ret->status == VIRTCHNL_FDIR_FAILURE_RULE_TIMEOUT) {
1000 "Failed to delete rule request due to time out for programming");
1004 "Failed to delete rule request due to other reasons");
1012 iavf_fdir_check(struct iavf_adapter *adapter,
1013 struct iavf_fdir_conf *filter)
1015 struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(adapter);
1016 struct virtchnl_fdir_add *fdir_ret;
1018 struct iavf_cmd_info args;
1021 filter->add_fltr.vsi_id = vf->vsi_res->vsi_id;
1022 filter->add_fltr.validate_only = 1;
1024 args.ops = VIRTCHNL_OP_ADD_FDIR_FILTER;
1025 args.in_args = (uint8_t *)(&filter->add_fltr);
1026 args.in_args_size = sizeof(*(&filter->add_fltr));
1027 args.out_buffer = vf->aq_resp;
1028 args.out_size = IAVF_AQ_BUF_SZ;
1030 err = iavf_execute_vf_cmd(adapter, &args);
1032 PMD_DRV_LOG(ERR, "fail to check flow direcotor rule");
1036 fdir_ret = (struct virtchnl_fdir_add *)args.out_buffer;
1038 if (fdir_ret->status == VIRTCHNL_FDIR_SUCCESS) {
1040 "Succeed in checking rule request by PF");
1041 } else if (fdir_ret->status == VIRTCHNL_FDIR_FAILURE_RULE_INVALID) {
1043 "Failed to check rule request due to parameters validation"
1044 " or HW doesn't support");
1048 "Failed to check rule request due to other reasons");
1056 iavf_add_del_rss_cfg(struct iavf_adapter *adapter,
1057 struct virtchnl_rss_cfg *rss_cfg, bool add)
1059 struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(adapter);
1060 struct iavf_cmd_info args;
1063 memset(&args, 0, sizeof(args));
1064 args.ops = add ? VIRTCHNL_OP_ADD_RSS_CFG :
1065 VIRTCHNL_OP_DEL_RSS_CFG;
1066 args.in_args = (u8 *)rss_cfg;
1067 args.in_args_size = sizeof(*rss_cfg);
1068 args.out_buffer = vf->aq_resp;
1069 args.out_size = IAVF_AQ_BUF_SZ;
1071 err = iavf_execute_vf_cmd(adapter, &args);
1074 "Failed to execute command of %s",
1075 add ? "OP_ADD_RSS_CFG" :
1076 "OP_DEL_RSS_INPUT_CFG");
1082 iavf_add_del_mc_addr_list(struct iavf_adapter *adapter,
1083 struct rte_ether_addr *mc_addrs,
1084 uint32_t mc_addrs_num, bool add)
1086 struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(adapter);
1087 uint8_t cmd_buffer[sizeof(struct virtchnl_ether_addr_list) +
1088 (IAVF_NUM_MACADDR_MAX * sizeof(struct virtchnl_ether_addr))];
1089 struct virtchnl_ether_addr_list *list;
1090 struct iavf_cmd_info args;
1094 if (mc_addrs == NULL || mc_addrs_num == 0)
1097 if (mc_addrs_num > IAVF_NUM_MACADDR_MAX)
1100 list = (struct virtchnl_ether_addr_list *)cmd_buffer;
1101 list->vsi_id = vf->vsi_res->vsi_id;
1102 list->num_elements = mc_addrs_num;
1104 for (i = 0; i < mc_addrs_num; i++) {
1105 if (!IAVF_IS_MULTICAST(mc_addrs[i].addr_bytes)) {
1106 PMD_DRV_LOG(ERR, "Invalid mac:%x:%x:%x:%x:%x:%x",
1107 mc_addrs[i].addr_bytes[0],
1108 mc_addrs[i].addr_bytes[1],
1109 mc_addrs[i].addr_bytes[2],
1110 mc_addrs[i].addr_bytes[3],
1111 mc_addrs[i].addr_bytes[4],
1112 mc_addrs[i].addr_bytes[5]);
1116 memcpy(list->list[i].addr, mc_addrs[i].addr_bytes,
1117 sizeof(list->list[i].addr));
1120 args.ops = add ? VIRTCHNL_OP_ADD_ETH_ADDR : VIRTCHNL_OP_DEL_ETH_ADDR;
1121 args.in_args = cmd_buffer;
1122 args.in_args_size = sizeof(struct virtchnl_ether_addr_list) +
1123 i * sizeof(struct virtchnl_ether_addr);
1124 args.out_buffer = vf->aq_resp;
1125 args.out_size = IAVF_AQ_BUF_SZ;
1126 err = iavf_execute_vf_cmd(adapter, &args);
1129 PMD_DRV_LOG(ERR, "fail to execute command %s",
1130 add ? "OP_ADD_ETH_ADDR" : "OP_DEL_ETH_ADDR");