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 PMD_DRV_LOG(WARNING, "command mismatch, expect %u, get %u",
57 vf->pend_cmd, opcode);
58 return IAVF_ERR_OPCODE_MISMATCH;
65 iavf_execute_vf_cmd(struct iavf_adapter *adapter, struct iavf_cmd_info *args)
67 struct iavf_hw *hw = IAVF_DEV_PRIVATE_TO_HW(adapter);
68 struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(adapter);
73 if (_atomic_set_cmd(vf, args->ops))
76 ret = iavf_aq_send_msg_to_pf(hw, args->ops, IAVF_SUCCESS,
77 args->in_args, args->in_args_size, NULL);
79 PMD_DRV_LOG(ERR, "fail to send cmd %d", args->ops);
85 case VIRTCHNL_OP_RESET_VF:
86 /*no need to wait for response */
89 case VIRTCHNL_OP_VERSION:
90 case VIRTCHNL_OP_GET_VF_RESOURCES:
91 case VIRTCHNL_OP_GET_SUPPORTED_RXDIDS:
92 /* for init virtchnl ops, need to poll the response */
94 ret = iavf_read_msg_from_pf(adapter, args->out_size,
96 if (ret == IAVF_SUCCESS)
98 rte_delay_ms(ASQ_DELAY_MS);
99 } while (i++ < MAX_TRY_TIMES);
100 if (i >= MAX_TRY_TIMES ||
101 vf->cmd_retval != VIRTCHNL_STATUS_SUCCESS) {
103 PMD_DRV_LOG(ERR, "No response or return failure (%d)"
104 " for cmd %d", vf->cmd_retval, args->ops);
110 /* For other virtchnl ops in running time,
111 * wait for the cmd done flag.
114 if (vf->pend_cmd == VIRTCHNL_OP_UNKNOWN)
116 rte_delay_ms(ASQ_DELAY_MS);
117 /* If don't read msg or read sys event, continue */
118 } while (i++ < MAX_TRY_TIMES);
119 /* If there's no response is received, clear command */
120 if (i >= MAX_TRY_TIMES ||
121 vf->cmd_retval != VIRTCHNL_STATUS_SUCCESS) {
123 PMD_DRV_LOG(ERR, "No response or return failure (%d)"
124 " for cmd %d", vf->cmd_retval, args->ops);
134 iavf_convert_link_speed(enum virtchnl_link_speed virt_link_speed)
138 switch (virt_link_speed) {
139 case VIRTCHNL_LINK_SPEED_100MB:
142 case VIRTCHNL_LINK_SPEED_1GB:
145 case VIRTCHNL_LINK_SPEED_10GB:
148 case VIRTCHNL_LINK_SPEED_40GB:
151 case VIRTCHNL_LINK_SPEED_20GB:
154 case VIRTCHNL_LINK_SPEED_25GB:
157 case VIRTCHNL_LINK_SPEED_2_5GB:
160 case VIRTCHNL_LINK_SPEED_5GB:
172 iavf_handle_pf_event_msg(struct rte_eth_dev *dev, uint8_t *msg,
175 struct virtchnl_pf_event *pf_msg =
176 (struct virtchnl_pf_event *)msg;
177 struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(dev->data->dev_private);
179 if (msglen < sizeof(struct virtchnl_pf_event)) {
180 PMD_DRV_LOG(DEBUG, "Error event");
183 switch (pf_msg->event) {
184 case VIRTCHNL_EVENT_RESET_IMPENDING:
185 PMD_DRV_LOG(DEBUG, "VIRTCHNL_EVENT_RESET_IMPENDING event");
186 _rte_eth_dev_callback_process(dev, RTE_ETH_EVENT_INTR_RESET,
189 case VIRTCHNL_EVENT_LINK_CHANGE:
190 PMD_DRV_LOG(DEBUG, "VIRTCHNL_EVENT_LINK_CHANGE event");
191 vf->link_up = pf_msg->event_data.link_event.link_status;
192 if (vf->vf_res->vf_cap_flags & VIRTCHNL_VF_CAP_ADV_LINK_SPEED) {
194 pf_msg->event_data.link_event_adv.link_speed;
196 enum virtchnl_link_speed speed;
197 speed = pf_msg->event_data.link_event.link_speed;
198 vf->link_speed = iavf_convert_link_speed(speed);
200 iavf_dev_link_update(dev, 0);
201 _rte_eth_dev_callback_process(dev, RTE_ETH_EVENT_INTR_LSC,
204 case VIRTCHNL_EVENT_PF_DRIVER_CLOSE:
205 PMD_DRV_LOG(DEBUG, "VIRTCHNL_EVENT_PF_DRIVER_CLOSE event");
208 PMD_DRV_LOG(ERR, " unknown event received %u", pf_msg->event);
214 iavf_handle_virtchnl_msg(struct rte_eth_dev *dev)
216 struct iavf_hw *hw = IAVF_DEV_PRIVATE_TO_HW(dev->data->dev_private);
217 struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(dev->data->dev_private);
218 struct iavf_arq_event_info info;
219 uint16_t pending, aq_opc;
220 enum virtchnl_ops msg_opc;
221 enum iavf_status msg_ret;
224 info.buf_len = IAVF_AQ_BUF_SZ;
226 PMD_DRV_LOG(ERR, "Buffer for adminq resp should not be NULL");
229 info.msg_buf = vf->aq_resp;
233 ret = iavf_clean_arq_element(hw, &info, &pending);
235 if (ret != IAVF_SUCCESS) {
236 PMD_DRV_LOG(INFO, "Failed to read msg from AdminQ,"
240 aq_opc = rte_le_to_cpu_16(info.desc.opcode);
241 /* For the message sent from pf to vf, opcode is stored in
242 * cookie_high of struct iavf_aq_desc, while return error code
243 * are stored in cookie_low, Which is done by PF driver.
245 msg_opc = (enum virtchnl_ops)rte_le_to_cpu_32(
246 info.desc.cookie_high);
247 msg_ret = (enum iavf_status)rte_le_to_cpu_32(
248 info.desc.cookie_low);
250 case iavf_aqc_opc_send_msg_to_vf:
251 if (msg_opc == VIRTCHNL_OP_EVENT) {
252 iavf_handle_pf_event_msg(dev, info.msg_buf,
255 /* read message and it's expected one */
256 if (msg_opc == vf->pend_cmd)
257 _notify_cmd(vf, msg_ret);
259 PMD_DRV_LOG(ERR, "command mismatch,"
261 vf->pend_cmd, msg_opc);
263 "adminq response is received,"
264 " opcode = %d", msg_opc);
268 PMD_DRV_LOG(ERR, "Request %u is not supported yet",
276 iavf_enable_vlan_strip(struct iavf_adapter *adapter)
278 struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(adapter);
279 struct iavf_cmd_info args;
282 memset(&args, 0, sizeof(args));
283 args.ops = VIRTCHNL_OP_ENABLE_VLAN_STRIPPING;
285 args.in_args_size = 0;
286 args.out_buffer = vf->aq_resp;
287 args.out_size = IAVF_AQ_BUF_SZ;
288 ret = iavf_execute_vf_cmd(adapter, &args);
290 PMD_DRV_LOG(ERR, "Failed to execute command of"
291 " OP_ENABLE_VLAN_STRIPPING");
297 iavf_disable_vlan_strip(struct iavf_adapter *adapter)
299 struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(adapter);
300 struct iavf_cmd_info args;
303 memset(&args, 0, sizeof(args));
304 args.ops = VIRTCHNL_OP_DISABLE_VLAN_STRIPPING;
306 args.in_args_size = 0;
307 args.out_buffer = vf->aq_resp;
308 args.out_size = IAVF_AQ_BUF_SZ;
309 ret = iavf_execute_vf_cmd(adapter, &args);
311 PMD_DRV_LOG(ERR, "Failed to execute command of"
312 " OP_DISABLE_VLAN_STRIPPING");
317 #define VIRTCHNL_VERSION_MAJOR_START 1
318 #define VIRTCHNL_VERSION_MINOR_START 1
320 /* Check API version with sync wait until version read from admin queue */
322 iavf_check_api_version(struct iavf_adapter *adapter)
324 struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(adapter);
325 struct virtchnl_version_info version, *pver;
326 struct iavf_cmd_info args;
329 version.major = VIRTCHNL_VERSION_MAJOR;
330 version.minor = VIRTCHNL_VERSION_MINOR;
332 args.ops = VIRTCHNL_OP_VERSION;
333 args.in_args = (uint8_t *)&version;
334 args.in_args_size = sizeof(version);
335 args.out_buffer = vf->aq_resp;
336 args.out_size = IAVF_AQ_BUF_SZ;
338 err = iavf_execute_vf_cmd(adapter, &args);
340 PMD_INIT_LOG(ERR, "Fail to execute command of OP_VERSION");
344 pver = (struct virtchnl_version_info *)args.out_buffer;
345 vf->virtchnl_version = *pver;
347 if (vf->virtchnl_version.major < VIRTCHNL_VERSION_MAJOR_START ||
348 (vf->virtchnl_version.major == VIRTCHNL_VERSION_MAJOR_START &&
349 vf->virtchnl_version.minor < VIRTCHNL_VERSION_MINOR_START)) {
350 PMD_INIT_LOG(ERR, "VIRTCHNL API version should not be lower"
351 " than (%u.%u) to support Adapative VF",
352 VIRTCHNL_VERSION_MAJOR_START,
353 VIRTCHNL_VERSION_MAJOR_START);
355 } else if (vf->virtchnl_version.major > VIRTCHNL_VERSION_MAJOR ||
356 (vf->virtchnl_version.major == VIRTCHNL_VERSION_MAJOR &&
357 vf->virtchnl_version.minor > VIRTCHNL_VERSION_MINOR)) {
358 PMD_INIT_LOG(ERR, "PF/VF API version mismatch:(%u.%u)-(%u.%u)",
359 vf->virtchnl_version.major,
360 vf->virtchnl_version.minor,
361 VIRTCHNL_VERSION_MAJOR,
362 VIRTCHNL_VERSION_MINOR);
366 PMD_DRV_LOG(DEBUG, "Peer is supported PF host");
371 iavf_get_vf_resource(struct iavf_adapter *adapter)
373 struct iavf_hw *hw = IAVF_DEV_PRIVATE_TO_HW(adapter);
374 struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(adapter);
375 struct iavf_cmd_info args;
379 args.ops = VIRTCHNL_OP_GET_VF_RESOURCES;
380 args.out_buffer = vf->aq_resp;
381 args.out_size = IAVF_AQ_BUF_SZ;
383 caps = IAVF_BASIC_OFFLOAD_CAPS | VIRTCHNL_VF_CAP_ADV_LINK_SPEED |
384 VIRTCHNL_VF_OFFLOAD_RX_FLEX_DESC |
385 VIRTCHNL_VF_OFFLOAD_FDIR_PF |
386 VIRTCHNL_VF_OFFLOAD_ADV_RSS_PF;
388 args.in_args = (uint8_t *)∩︀
389 args.in_args_size = sizeof(caps);
391 err = iavf_execute_vf_cmd(adapter, &args);
395 "Failed to execute command of OP_GET_VF_RESOURCE");
399 len = sizeof(struct virtchnl_vf_resource) +
400 IAVF_MAX_VF_VSI * sizeof(struct virtchnl_vsi_resource);
402 rte_memcpy(vf->vf_res, args.out_buffer,
403 RTE_MIN(args.out_size, len));
404 /* parse VF config message back from PF*/
405 iavf_vf_parse_hw_config(hw, vf->vf_res);
406 for (i = 0; i < vf->vf_res->num_vsis; i++) {
407 if (vf->vf_res->vsi_res[i].vsi_type == VIRTCHNL_VSI_SRIOV)
408 vf->vsi_res = &vf->vf_res->vsi_res[i];
412 PMD_INIT_LOG(ERR, "no LAN VSI found");
416 vf->vsi.vsi_id = vf->vsi_res->vsi_id;
417 vf->vsi.nb_qps = vf->vsi_res->num_queue_pairs;
418 vf->vsi.adapter = adapter;
424 iavf_get_supported_rxdid(struct iavf_adapter *adapter)
426 struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(adapter);
427 struct iavf_cmd_info args;
430 args.ops = VIRTCHNL_OP_GET_SUPPORTED_RXDIDS;
432 args.in_args_size = 0;
433 args.out_buffer = vf->aq_resp;
434 args.out_size = IAVF_AQ_BUF_SZ;
436 ret = iavf_execute_vf_cmd(adapter, &args);
439 "Failed to execute command of OP_GET_SUPPORTED_RXDIDS");
443 vf->supported_rxdid =
444 ((struct virtchnl_supported_rxdids *)args.out_buffer)->supported_rxdids;
450 iavf_enable_queues(struct iavf_adapter *adapter)
452 struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(adapter);
453 struct virtchnl_queue_select queue_select;
454 struct iavf_cmd_info args;
457 memset(&queue_select, 0, sizeof(queue_select));
458 queue_select.vsi_id = vf->vsi_res->vsi_id;
460 queue_select.rx_queues = BIT(adapter->eth_dev->data->nb_rx_queues) - 1;
461 queue_select.tx_queues = BIT(adapter->eth_dev->data->nb_tx_queues) - 1;
463 args.ops = VIRTCHNL_OP_ENABLE_QUEUES;
464 args.in_args = (u8 *)&queue_select;
465 args.in_args_size = sizeof(queue_select);
466 args.out_buffer = vf->aq_resp;
467 args.out_size = IAVF_AQ_BUF_SZ;
468 err = iavf_execute_vf_cmd(adapter, &args);
471 "Failed to execute command of OP_ENABLE_QUEUES");
478 iavf_disable_queues(struct iavf_adapter *adapter)
480 struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(adapter);
481 struct virtchnl_queue_select queue_select;
482 struct iavf_cmd_info args;
485 memset(&queue_select, 0, sizeof(queue_select));
486 queue_select.vsi_id = vf->vsi_res->vsi_id;
488 queue_select.rx_queues = BIT(adapter->eth_dev->data->nb_rx_queues) - 1;
489 queue_select.tx_queues = BIT(adapter->eth_dev->data->nb_tx_queues) - 1;
491 args.ops = VIRTCHNL_OP_DISABLE_QUEUES;
492 args.in_args = (u8 *)&queue_select;
493 args.in_args_size = sizeof(queue_select);
494 args.out_buffer = vf->aq_resp;
495 args.out_size = IAVF_AQ_BUF_SZ;
496 err = iavf_execute_vf_cmd(adapter, &args);
499 "Failed to execute command of OP_DISABLE_QUEUES");
506 iavf_switch_queue(struct iavf_adapter *adapter, uint16_t qid,
509 struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(adapter);
510 struct virtchnl_queue_select queue_select;
511 struct iavf_cmd_info args;
514 memset(&queue_select, 0, sizeof(queue_select));
515 queue_select.vsi_id = vf->vsi_res->vsi_id;
517 queue_select.rx_queues |= 1 << qid;
519 queue_select.tx_queues |= 1 << qid;
522 args.ops = VIRTCHNL_OP_ENABLE_QUEUES;
524 args.ops = VIRTCHNL_OP_DISABLE_QUEUES;
525 args.in_args = (u8 *)&queue_select;
526 args.in_args_size = sizeof(queue_select);
527 args.out_buffer = vf->aq_resp;
528 args.out_size = IAVF_AQ_BUF_SZ;
529 err = iavf_execute_vf_cmd(adapter, &args);
531 PMD_DRV_LOG(ERR, "Failed to execute command of %s",
532 on ? "OP_ENABLE_QUEUES" : "OP_DISABLE_QUEUES");
537 iavf_configure_rss_lut(struct iavf_adapter *adapter)
539 struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(adapter);
540 struct virtchnl_rss_lut *rss_lut;
541 struct iavf_cmd_info args;
544 len = sizeof(*rss_lut) + vf->vf_res->rss_lut_size - 1;
545 rss_lut = rte_zmalloc("rss_lut", len, 0);
549 rss_lut->vsi_id = vf->vsi_res->vsi_id;
550 rss_lut->lut_entries = vf->vf_res->rss_lut_size;
551 rte_memcpy(rss_lut->lut, vf->rss_lut, vf->vf_res->rss_lut_size);
553 args.ops = VIRTCHNL_OP_CONFIG_RSS_LUT;
554 args.in_args = (u8 *)rss_lut;
555 args.in_args_size = len;
556 args.out_buffer = vf->aq_resp;
557 args.out_size = IAVF_AQ_BUF_SZ;
559 err = iavf_execute_vf_cmd(adapter, &args);
562 "Failed to execute command of OP_CONFIG_RSS_LUT");
569 iavf_configure_rss_key(struct iavf_adapter *adapter)
571 struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(adapter);
572 struct virtchnl_rss_key *rss_key;
573 struct iavf_cmd_info args;
576 len = sizeof(*rss_key) + vf->vf_res->rss_key_size - 1;
577 rss_key = rte_zmalloc("rss_key", len, 0);
581 rss_key->vsi_id = vf->vsi_res->vsi_id;
582 rss_key->key_len = vf->vf_res->rss_key_size;
583 rte_memcpy(rss_key->key, vf->rss_key, vf->vf_res->rss_key_size);
585 args.ops = VIRTCHNL_OP_CONFIG_RSS_KEY;
586 args.in_args = (u8 *)rss_key;
587 args.in_args_size = len;
588 args.out_buffer = vf->aq_resp;
589 args.out_size = IAVF_AQ_BUF_SZ;
591 err = iavf_execute_vf_cmd(adapter, &args);
594 "Failed to execute command of OP_CONFIG_RSS_KEY");
601 iavf_configure_queues(struct iavf_adapter *adapter)
603 struct iavf_rx_queue **rxq =
604 (struct iavf_rx_queue **)adapter->eth_dev->data->rx_queues;
605 struct iavf_tx_queue **txq =
606 (struct iavf_tx_queue **)adapter->eth_dev->data->tx_queues;
607 struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(adapter);
608 struct virtchnl_vsi_queue_config_info *vc_config;
609 struct virtchnl_queue_pair_info *vc_qp;
610 struct iavf_cmd_info args;
614 size = sizeof(*vc_config) +
615 sizeof(vc_config->qpair[0]) * vf->num_queue_pairs;
616 vc_config = rte_zmalloc("cfg_queue", size, 0);
620 vc_config->vsi_id = vf->vsi_res->vsi_id;
621 vc_config->num_queue_pairs = vf->num_queue_pairs;
623 for (i = 0, vc_qp = vc_config->qpair;
624 i < vf->num_queue_pairs;
626 vc_qp->txq.vsi_id = vf->vsi_res->vsi_id;
627 vc_qp->txq.queue_id = i;
628 /* Virtchnnl configure queues by pairs */
629 if (i < adapter->eth_dev->data->nb_tx_queues) {
630 vc_qp->txq.ring_len = txq[i]->nb_tx_desc;
631 vc_qp->txq.dma_ring_addr = txq[i]->tx_ring_phys_addr;
633 vc_qp->rxq.vsi_id = vf->vsi_res->vsi_id;
634 vc_qp->rxq.queue_id = i;
635 vc_qp->rxq.max_pkt_size = vf->max_pkt_len;
636 /* Virtchnnl configure queues by pairs */
637 if (i < adapter->eth_dev->data->nb_rx_queues) {
638 vc_qp->rxq.ring_len = rxq[i]->nb_rx_desc;
639 vc_qp->rxq.dma_ring_addr = rxq[i]->rx_ring_phys_addr;
640 vc_qp->rxq.databuffer_size = rxq[i]->rx_buf_len;
643 #ifndef RTE_LIBRTE_IAVF_16BYTE_RX_DESC
644 if (vf->vf_res->vf_cap_flags &
645 VIRTCHNL_VF_OFFLOAD_RX_FLEX_DESC &&
646 vf->supported_rxdid & BIT(IAVF_RXDID_COMMS_OVS_1)) {
647 vc_qp->rxq.rxdid = IAVF_RXDID_COMMS_OVS_1;
648 PMD_DRV_LOG(NOTICE, "request RXDID == %d in "
649 "Queue[%d]", vc_qp->rxq.rxdid, i);
651 vc_qp->rxq.rxdid = IAVF_RXDID_LEGACY_1;
652 PMD_DRV_LOG(NOTICE, "request RXDID == %d in "
653 "Queue[%d]", vc_qp->rxq.rxdid, i);
656 if (vf->vf_res->vf_cap_flags &
657 VIRTCHNL_VF_OFFLOAD_RX_FLEX_DESC &&
658 vf->supported_rxdid & BIT(IAVF_RXDID_LEGACY_0)) {
659 vc_qp->rxq.rxdid = IAVF_RXDID_LEGACY_0;
660 PMD_DRV_LOG(NOTICE, "request RXDID == %d in "
661 "Queue[%d]", vc_qp->rxq.rxdid, i);
663 PMD_DRV_LOG(ERR, "RXDID == 0 is not supported");
669 memset(&args, 0, sizeof(args));
670 args.ops = VIRTCHNL_OP_CONFIG_VSI_QUEUES;
671 args.in_args = (uint8_t *)vc_config;
672 args.in_args_size = size;
673 args.out_buffer = vf->aq_resp;
674 args.out_size = IAVF_AQ_BUF_SZ;
676 err = iavf_execute_vf_cmd(adapter, &args);
678 PMD_DRV_LOG(ERR, "Failed to execute command of"
679 " VIRTCHNL_OP_CONFIG_VSI_QUEUES");
686 iavf_config_irq_map(struct iavf_adapter *adapter)
688 struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(adapter);
689 struct virtchnl_irq_map_info *map_info;
690 struct virtchnl_vector_map *vecmap;
691 struct iavf_cmd_info args;
694 len = sizeof(struct virtchnl_irq_map_info) +
695 sizeof(struct virtchnl_vector_map) * vf->nb_msix;
697 map_info = rte_zmalloc("map_info", len, 0);
701 map_info->num_vectors = vf->nb_msix;
702 for (i = 0; i < vf->nb_msix; i++) {
703 vecmap = &map_info->vecmap[i];
704 vecmap->vsi_id = vf->vsi_res->vsi_id;
705 vecmap->rxitr_idx = IAVF_ITR_INDEX_DEFAULT;
706 vecmap->vector_id = vf->msix_base + i;
708 vecmap->rxq_map = vf->rxq_map[vf->msix_base + i];
711 args.ops = VIRTCHNL_OP_CONFIG_IRQ_MAP;
712 args.in_args = (u8 *)map_info;
713 args.in_args_size = len;
714 args.out_buffer = vf->aq_resp;
715 args.out_size = IAVF_AQ_BUF_SZ;
716 err = iavf_execute_vf_cmd(adapter, &args);
718 PMD_DRV_LOG(ERR, "fail to execute command OP_CONFIG_IRQ_MAP");
725 iavf_add_del_all_mac_addr(struct iavf_adapter *adapter, bool add)
727 struct virtchnl_ether_addr_list *list;
728 struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(adapter);
729 struct rte_ether_addr *addr;
730 struct iavf_cmd_info args;
737 len = sizeof(struct virtchnl_ether_addr_list);
738 for (i = begin; i < IAVF_NUM_MACADDR_MAX; i++, next_begin++) {
739 addr = &adapter->eth_dev->data->mac_addrs[i];
740 if (rte_is_zero_ether_addr(addr))
742 len += sizeof(struct virtchnl_ether_addr);
743 if (len >= IAVF_AQ_BUF_SZ) {
749 list = rte_zmalloc("iavf_del_mac_buffer", len, 0);
751 PMD_DRV_LOG(ERR, "fail to allocate memory");
755 for (i = begin; i < next_begin; i++) {
756 addr = &adapter->eth_dev->data->mac_addrs[i];
757 if (rte_is_zero_ether_addr(addr))
759 rte_memcpy(list->list[j].addr, addr->addr_bytes,
760 sizeof(addr->addr_bytes));
761 PMD_DRV_LOG(DEBUG, "add/rm mac:%x:%x:%x:%x:%x:%x",
762 addr->addr_bytes[0], addr->addr_bytes[1],
763 addr->addr_bytes[2], addr->addr_bytes[3],
764 addr->addr_bytes[4], addr->addr_bytes[5]);
767 list->vsi_id = vf->vsi_res->vsi_id;
768 list->num_elements = j;
769 args.ops = add ? VIRTCHNL_OP_ADD_ETH_ADDR :
770 VIRTCHNL_OP_DEL_ETH_ADDR;
771 args.in_args = (uint8_t *)list;
772 args.in_args_size = len;
773 args.out_buffer = vf->aq_resp;
774 args.out_size = IAVF_AQ_BUF_SZ;
775 err = iavf_execute_vf_cmd(adapter, &args);
777 PMD_DRV_LOG(ERR, "fail to execute command %s",
778 add ? "OP_ADD_ETHER_ADDRESS" :
779 "OP_DEL_ETHER_ADDRESS");
782 } while (begin < IAVF_NUM_MACADDR_MAX);
786 iavf_query_stats(struct iavf_adapter *adapter,
787 struct virtchnl_eth_stats **pstats)
789 struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(adapter);
790 struct virtchnl_queue_select q_stats;
791 struct iavf_cmd_info args;
794 memset(&q_stats, 0, sizeof(q_stats));
795 q_stats.vsi_id = vf->vsi_res->vsi_id;
796 args.ops = VIRTCHNL_OP_GET_STATS;
797 args.in_args = (uint8_t *)&q_stats;
798 args.in_args_size = sizeof(q_stats);
799 args.out_buffer = vf->aq_resp;
800 args.out_size = IAVF_AQ_BUF_SZ;
802 err = iavf_execute_vf_cmd(adapter, &args);
804 PMD_DRV_LOG(ERR, "fail to execute command OP_GET_STATS");
808 *pstats = (struct virtchnl_eth_stats *)args.out_buffer;
813 iavf_config_promisc(struct iavf_adapter *adapter,
815 bool enable_multicast)
817 struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(adapter);
818 struct virtchnl_promisc_info promisc;
819 struct iavf_cmd_info args;
823 promisc.vsi_id = vf->vsi_res->vsi_id;
826 promisc.flags |= FLAG_VF_UNICAST_PROMISC;
828 if (enable_multicast)
829 promisc.flags |= FLAG_VF_MULTICAST_PROMISC;
831 args.ops = VIRTCHNL_OP_CONFIG_PROMISCUOUS_MODE;
832 args.in_args = (uint8_t *)&promisc;
833 args.in_args_size = sizeof(promisc);
834 args.out_buffer = vf->aq_resp;
835 args.out_size = IAVF_AQ_BUF_SZ;
837 err = iavf_execute_vf_cmd(adapter, &args);
841 "fail to execute command CONFIG_PROMISCUOUS_MODE");
846 iavf_add_del_eth_addr(struct iavf_adapter *adapter, struct rte_ether_addr *addr,
849 struct virtchnl_ether_addr_list *list;
850 struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(adapter);
851 uint8_t cmd_buffer[sizeof(struct virtchnl_ether_addr_list) +
852 sizeof(struct virtchnl_ether_addr)];
853 struct iavf_cmd_info args;
856 list = (struct virtchnl_ether_addr_list *)cmd_buffer;
857 list->vsi_id = vf->vsi_res->vsi_id;
858 list->num_elements = 1;
859 rte_memcpy(list->list[0].addr, addr->addr_bytes,
860 sizeof(addr->addr_bytes));
862 args.ops = add ? VIRTCHNL_OP_ADD_ETH_ADDR : VIRTCHNL_OP_DEL_ETH_ADDR;
863 args.in_args = cmd_buffer;
864 args.in_args_size = sizeof(cmd_buffer);
865 args.out_buffer = vf->aq_resp;
866 args.out_size = IAVF_AQ_BUF_SZ;
867 err = iavf_execute_vf_cmd(adapter, &args);
869 PMD_DRV_LOG(ERR, "fail to execute command %s",
870 add ? "OP_ADD_ETH_ADDR" : "OP_DEL_ETH_ADDR");
875 iavf_add_del_vlan(struct iavf_adapter *adapter, uint16_t vlanid, bool add)
877 struct virtchnl_vlan_filter_list *vlan_list;
878 struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(adapter);
879 uint8_t cmd_buffer[sizeof(struct virtchnl_vlan_filter_list) +
881 struct iavf_cmd_info args;
884 vlan_list = (struct virtchnl_vlan_filter_list *)cmd_buffer;
885 vlan_list->vsi_id = vf->vsi_res->vsi_id;
886 vlan_list->num_elements = 1;
887 vlan_list->vlan_id[0] = vlanid;
889 args.ops = add ? VIRTCHNL_OP_ADD_VLAN : VIRTCHNL_OP_DEL_VLAN;
890 args.in_args = cmd_buffer;
891 args.in_args_size = sizeof(cmd_buffer);
892 args.out_buffer = vf->aq_resp;
893 args.out_size = IAVF_AQ_BUF_SZ;
894 err = iavf_execute_vf_cmd(adapter, &args);
896 PMD_DRV_LOG(ERR, "fail to execute command %s",
897 add ? "OP_ADD_VLAN" : "OP_DEL_VLAN");
903 iavf_fdir_add(struct iavf_adapter *adapter,
904 struct iavf_fdir_conf *filter)
906 struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(adapter);
907 struct virtchnl_fdir_add *fdir_ret;
909 struct iavf_cmd_info args;
912 filter->add_fltr.vsi_id = vf->vsi_res->vsi_id;
913 filter->add_fltr.validate_only = 0;
915 args.ops = VIRTCHNL_OP_ADD_FDIR_FILTER;
916 args.in_args = (uint8_t *)(&filter->add_fltr);
917 args.in_args_size = sizeof(*(&filter->add_fltr));
918 args.out_buffer = vf->aq_resp;
919 args.out_size = IAVF_AQ_BUF_SZ;
921 err = iavf_execute_vf_cmd(adapter, &args);
923 PMD_DRV_LOG(ERR, "fail to execute command OP_ADD_FDIR_FILTER");
927 fdir_ret = (struct virtchnl_fdir_add *)args.out_buffer;
928 filter->flow_id = fdir_ret->flow_id;
930 if (fdir_ret->status == VIRTCHNL_FDIR_SUCCESS) {
932 "Succeed in adding rule request by PF");
933 } else if (fdir_ret->status == VIRTCHNL_FDIR_FAILURE_RULE_NORESOURCE) {
935 "Failed to add rule request due to no hw resource");
937 } else if (fdir_ret->status == VIRTCHNL_FDIR_FAILURE_RULE_EXIST) {
939 "Failed to add rule request due to the rule is already existed");
941 } else if (fdir_ret->status == VIRTCHNL_FDIR_FAILURE_RULE_CONFLICT) {
943 "Failed to add rule request due to the rule is conflict with existing rule");
945 } else if (fdir_ret->status == VIRTCHNL_FDIR_FAILURE_RULE_INVALID) {
947 "Failed to add rule request due to the hw doesn't support");
949 } else if (fdir_ret->status == VIRTCHNL_FDIR_FAILURE_RULE_TIMEOUT) {
951 "Failed to add rule request due to time out for programming");
955 "Failed to add rule request due to other reasons");
963 iavf_fdir_del(struct iavf_adapter *adapter,
964 struct iavf_fdir_conf *filter)
966 struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(adapter);
967 struct virtchnl_fdir_del *fdir_ret;
969 struct iavf_cmd_info args;
972 filter->del_fltr.vsi_id = vf->vsi_res->vsi_id;
973 filter->del_fltr.flow_id = filter->flow_id;
975 args.ops = VIRTCHNL_OP_DEL_FDIR_FILTER;
976 args.in_args = (uint8_t *)(&filter->del_fltr);
977 args.in_args_size = sizeof(filter->del_fltr);
978 args.out_buffer = vf->aq_resp;
979 args.out_size = IAVF_AQ_BUF_SZ;
981 err = iavf_execute_vf_cmd(adapter, &args);
983 PMD_DRV_LOG(ERR, "fail to execute command OP_DEL_FDIR_FILTER");
987 fdir_ret = (struct virtchnl_fdir_del *)args.out_buffer;
989 if (fdir_ret->status == VIRTCHNL_FDIR_SUCCESS) {
991 "Succeed in deleting rule request by PF");
992 } else if (fdir_ret->status == VIRTCHNL_FDIR_FAILURE_RULE_NONEXIST) {
994 "Failed to delete rule request due to this rule doesn't exist");
996 } else if (fdir_ret->status == VIRTCHNL_FDIR_FAILURE_RULE_TIMEOUT) {
998 "Failed to delete rule request due to time out for programming");
1002 "Failed to delete rule request due to other reasons");
1010 iavf_fdir_check(struct iavf_adapter *adapter,
1011 struct iavf_fdir_conf *filter)
1013 struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(adapter);
1014 struct virtchnl_fdir_add *fdir_ret;
1016 struct iavf_cmd_info args;
1019 filter->add_fltr.vsi_id = vf->vsi_res->vsi_id;
1020 filter->add_fltr.validate_only = 1;
1022 args.ops = VIRTCHNL_OP_ADD_FDIR_FILTER;
1023 args.in_args = (uint8_t *)(&filter->add_fltr);
1024 args.in_args_size = sizeof(*(&filter->add_fltr));
1025 args.out_buffer = vf->aq_resp;
1026 args.out_size = IAVF_AQ_BUF_SZ;
1028 err = iavf_execute_vf_cmd(adapter, &args);
1030 PMD_DRV_LOG(ERR, "fail to check flow direcotor rule");
1034 fdir_ret = (struct virtchnl_fdir_add *)args.out_buffer;
1036 if (fdir_ret->status == VIRTCHNL_FDIR_SUCCESS) {
1038 "Succeed in checking rule request by PF");
1039 } else if (fdir_ret->status == VIRTCHNL_FDIR_FAILURE_RULE_INVALID) {
1041 "Failed to check rule request due to parameters validation"
1042 " or HW doesn't support");
1046 "Failed to check rule request due to other reasons");
1054 iavf_add_del_rss_cfg(struct iavf_adapter *adapter,
1055 struct virtchnl_rss_cfg *rss_cfg, bool add)
1057 struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(adapter);
1058 struct iavf_cmd_info args;
1061 memset(&args, 0, sizeof(args));
1062 args.ops = add ? VIRTCHNL_OP_ADD_RSS_CFG :
1063 VIRTCHNL_OP_DEL_RSS_CFG;
1064 args.in_args = (u8 *)rss_cfg;
1065 args.in_args_size = sizeof(*rss_cfg);
1066 args.out_buffer = vf->aq_resp;
1067 args.out_size = IAVF_AQ_BUF_SZ;
1069 err = iavf_execute_vf_cmd(adapter, &args);
1072 "Failed to execute command of %s",
1073 add ? "OP_ADD_RSS_CFG" :
1074 "OP_DEL_RSS_INPUT_CFG");