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);
79 if (_atomic_set_cmd(vf, args->ops))
82 ret = iavf_aq_send_msg_to_pf(hw, args->ops, IAVF_SUCCESS,
83 args->in_args, args->in_args_size, NULL);
85 PMD_DRV_LOG(ERR, "fail to send cmd %d", args->ops);
91 case VIRTCHNL_OP_RESET_VF:
92 /*no need to wait for response */
95 case VIRTCHNL_OP_VERSION:
96 case VIRTCHNL_OP_GET_VF_RESOURCES:
97 case VIRTCHNL_OP_GET_SUPPORTED_RXDIDS:
98 /* for init virtchnl ops, need to poll the response */
100 ret = iavf_read_msg_from_pf(adapter, args->out_size,
102 if (ret == IAVF_SUCCESS)
104 rte_delay_ms(ASQ_DELAY_MS);
105 } while (i++ < MAX_TRY_TIMES);
106 if (i >= MAX_TRY_TIMES ||
107 vf->cmd_retval != VIRTCHNL_STATUS_SUCCESS) {
109 PMD_DRV_LOG(ERR, "No response or return failure (%d)"
110 " for cmd %d", vf->cmd_retval, args->ops);
116 /* For other virtchnl ops in running time,
117 * wait for the cmd done flag.
120 if (vf->pend_cmd == VIRTCHNL_OP_UNKNOWN)
122 rte_delay_ms(ASQ_DELAY_MS);
123 /* If don't read msg or read sys event, continue */
124 } while (i++ < MAX_TRY_TIMES);
125 /* If there's no response is received, clear command */
126 if (i >= MAX_TRY_TIMES ||
127 vf->cmd_retval != VIRTCHNL_STATUS_SUCCESS) {
129 PMD_DRV_LOG(ERR, "No response or return failure (%d)"
130 " for cmd %d", vf->cmd_retval, args->ops);
140 iavf_convert_link_speed(enum virtchnl_link_speed virt_link_speed)
144 switch (virt_link_speed) {
145 case VIRTCHNL_LINK_SPEED_100MB:
148 case VIRTCHNL_LINK_SPEED_1GB:
151 case VIRTCHNL_LINK_SPEED_10GB:
154 case VIRTCHNL_LINK_SPEED_40GB:
157 case VIRTCHNL_LINK_SPEED_20GB:
160 case VIRTCHNL_LINK_SPEED_25GB:
163 case VIRTCHNL_LINK_SPEED_2_5GB:
166 case VIRTCHNL_LINK_SPEED_5GB:
178 iavf_handle_pf_event_msg(struct rte_eth_dev *dev, uint8_t *msg,
181 struct virtchnl_pf_event *pf_msg =
182 (struct virtchnl_pf_event *)msg;
183 struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(dev->data->dev_private);
185 if (msglen < sizeof(struct virtchnl_pf_event)) {
186 PMD_DRV_LOG(DEBUG, "Error event");
189 switch (pf_msg->event) {
190 case VIRTCHNL_EVENT_RESET_IMPENDING:
191 PMD_DRV_LOG(DEBUG, "VIRTCHNL_EVENT_RESET_IMPENDING event");
193 rte_eth_dev_callback_process(dev, RTE_ETH_EVENT_INTR_RESET,
196 case VIRTCHNL_EVENT_LINK_CHANGE:
197 PMD_DRV_LOG(DEBUG, "VIRTCHNL_EVENT_LINK_CHANGE event");
198 vf->link_up = pf_msg->event_data.link_event.link_status;
199 if (vf->vf_res->vf_cap_flags & VIRTCHNL_VF_CAP_ADV_LINK_SPEED) {
201 pf_msg->event_data.link_event_adv.link_speed;
203 enum virtchnl_link_speed speed;
204 speed = pf_msg->event_data.link_event.link_speed;
205 vf->link_speed = iavf_convert_link_speed(speed);
207 iavf_dev_link_update(dev, 0);
208 rte_eth_dev_callback_process(dev, RTE_ETH_EVENT_INTR_LSC, NULL);
210 case VIRTCHNL_EVENT_PF_DRIVER_CLOSE:
211 PMD_DRV_LOG(DEBUG, "VIRTCHNL_EVENT_PF_DRIVER_CLOSE event");
214 PMD_DRV_LOG(ERR, " unknown event received %u", pf_msg->event);
220 iavf_handle_virtchnl_msg(struct rte_eth_dev *dev)
222 struct iavf_hw *hw = IAVF_DEV_PRIVATE_TO_HW(dev->data->dev_private);
223 struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(dev->data->dev_private);
224 struct iavf_arq_event_info info;
225 uint16_t pending, aq_opc;
226 enum virtchnl_ops msg_opc;
227 enum iavf_status msg_ret;
230 info.buf_len = IAVF_AQ_BUF_SZ;
232 PMD_DRV_LOG(ERR, "Buffer for adminq resp should not be NULL");
235 info.msg_buf = vf->aq_resp;
239 ret = iavf_clean_arq_element(hw, &info, &pending);
241 if (ret != IAVF_SUCCESS) {
242 PMD_DRV_LOG(INFO, "Failed to read msg from AdminQ,"
246 aq_opc = rte_le_to_cpu_16(info.desc.opcode);
247 /* For the message sent from pf to vf, opcode is stored in
248 * cookie_high of struct iavf_aq_desc, while return error code
249 * are stored in cookie_low, Which is done by PF driver.
251 msg_opc = (enum virtchnl_ops)rte_le_to_cpu_32(
252 info.desc.cookie_high);
253 msg_ret = (enum iavf_status)rte_le_to_cpu_32(
254 info.desc.cookie_low);
256 case iavf_aqc_opc_send_msg_to_vf:
257 if (msg_opc == VIRTCHNL_OP_EVENT) {
258 iavf_handle_pf_event_msg(dev, info.msg_buf,
261 /* read message and it's expected one */
262 if (msg_opc == vf->pend_cmd)
263 _notify_cmd(vf, msg_ret);
265 PMD_DRV_LOG(ERR, "command mismatch,"
267 vf->pend_cmd, msg_opc);
269 "adminq response is received,"
270 " opcode = %d", msg_opc);
274 PMD_DRV_LOG(DEBUG, "Request %u is not supported yet",
282 iavf_enable_vlan_strip(struct iavf_adapter *adapter)
284 struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(adapter);
285 struct iavf_cmd_info args;
288 memset(&args, 0, sizeof(args));
289 args.ops = VIRTCHNL_OP_ENABLE_VLAN_STRIPPING;
291 args.in_args_size = 0;
292 args.out_buffer = vf->aq_resp;
293 args.out_size = IAVF_AQ_BUF_SZ;
294 ret = iavf_execute_vf_cmd(adapter, &args);
296 PMD_DRV_LOG(ERR, "Failed to execute command of"
297 " OP_ENABLE_VLAN_STRIPPING");
303 iavf_disable_vlan_strip(struct iavf_adapter *adapter)
305 struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(adapter);
306 struct iavf_cmd_info args;
309 memset(&args, 0, sizeof(args));
310 args.ops = VIRTCHNL_OP_DISABLE_VLAN_STRIPPING;
312 args.in_args_size = 0;
313 args.out_buffer = vf->aq_resp;
314 args.out_size = IAVF_AQ_BUF_SZ;
315 ret = iavf_execute_vf_cmd(adapter, &args);
317 PMD_DRV_LOG(ERR, "Failed to execute command of"
318 " OP_DISABLE_VLAN_STRIPPING");
323 #define VIRTCHNL_VERSION_MAJOR_START 1
324 #define VIRTCHNL_VERSION_MINOR_START 1
326 /* Check API version with sync wait until version read from admin queue */
328 iavf_check_api_version(struct iavf_adapter *adapter)
330 struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(adapter);
331 struct virtchnl_version_info version, *pver;
332 struct iavf_cmd_info args;
335 version.major = VIRTCHNL_VERSION_MAJOR;
336 version.minor = VIRTCHNL_VERSION_MINOR;
338 args.ops = VIRTCHNL_OP_VERSION;
339 args.in_args = (uint8_t *)&version;
340 args.in_args_size = sizeof(version);
341 args.out_buffer = vf->aq_resp;
342 args.out_size = IAVF_AQ_BUF_SZ;
344 err = iavf_execute_vf_cmd(adapter, &args);
346 PMD_INIT_LOG(ERR, "Fail to execute command of OP_VERSION");
350 pver = (struct virtchnl_version_info *)args.out_buffer;
351 vf->virtchnl_version = *pver;
353 if (vf->virtchnl_version.major < VIRTCHNL_VERSION_MAJOR_START ||
354 (vf->virtchnl_version.major == VIRTCHNL_VERSION_MAJOR_START &&
355 vf->virtchnl_version.minor < VIRTCHNL_VERSION_MINOR_START)) {
356 PMD_INIT_LOG(ERR, "VIRTCHNL API version should not be lower"
357 " than (%u.%u) to support Adapative VF",
358 VIRTCHNL_VERSION_MAJOR_START,
359 VIRTCHNL_VERSION_MAJOR_START);
361 } else if (vf->virtchnl_version.major > VIRTCHNL_VERSION_MAJOR ||
362 (vf->virtchnl_version.major == VIRTCHNL_VERSION_MAJOR &&
363 vf->virtchnl_version.minor > VIRTCHNL_VERSION_MINOR)) {
364 PMD_INIT_LOG(ERR, "PF/VF API version mismatch:(%u.%u)-(%u.%u)",
365 vf->virtchnl_version.major,
366 vf->virtchnl_version.minor,
367 VIRTCHNL_VERSION_MAJOR,
368 VIRTCHNL_VERSION_MINOR);
372 PMD_DRV_LOG(DEBUG, "Peer is supported PF host");
377 iavf_get_vf_resource(struct iavf_adapter *adapter)
379 struct iavf_hw *hw = IAVF_DEV_PRIVATE_TO_HW(adapter);
380 struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(adapter);
381 struct iavf_cmd_info args;
385 args.ops = VIRTCHNL_OP_GET_VF_RESOURCES;
386 args.out_buffer = vf->aq_resp;
387 args.out_size = IAVF_AQ_BUF_SZ;
389 caps = IAVF_BASIC_OFFLOAD_CAPS | VIRTCHNL_VF_CAP_ADV_LINK_SPEED |
390 VIRTCHNL_VF_OFFLOAD_RX_FLEX_DESC |
391 VIRTCHNL_VF_OFFLOAD_FDIR_PF |
392 VIRTCHNL_VF_OFFLOAD_ADV_RSS_PF;
394 args.in_args = (uint8_t *)∩︀
395 args.in_args_size = sizeof(caps);
397 err = iavf_execute_vf_cmd(adapter, &args);
401 "Failed to execute command of OP_GET_VF_RESOURCE");
405 len = sizeof(struct virtchnl_vf_resource) +
406 IAVF_MAX_VF_VSI * sizeof(struct virtchnl_vsi_resource);
408 rte_memcpy(vf->vf_res, args.out_buffer,
409 RTE_MIN(args.out_size, len));
410 /* parse VF config message back from PF*/
411 iavf_vf_parse_hw_config(hw, vf->vf_res);
412 for (i = 0; i < vf->vf_res->num_vsis; i++) {
413 if (vf->vf_res->vsi_res[i].vsi_type == VIRTCHNL_VSI_SRIOV)
414 vf->vsi_res = &vf->vf_res->vsi_res[i];
418 PMD_INIT_LOG(ERR, "no LAN VSI found");
422 vf->vsi.vsi_id = vf->vsi_res->vsi_id;
423 vf->vsi.nb_qps = vf->vsi_res->num_queue_pairs;
424 vf->vsi.adapter = adapter;
430 iavf_get_supported_rxdid(struct iavf_adapter *adapter)
432 struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(adapter);
433 struct iavf_cmd_info args;
436 args.ops = VIRTCHNL_OP_GET_SUPPORTED_RXDIDS;
438 args.in_args_size = 0;
439 args.out_buffer = vf->aq_resp;
440 args.out_size = IAVF_AQ_BUF_SZ;
442 ret = iavf_execute_vf_cmd(adapter, &args);
445 "Failed to execute command of OP_GET_SUPPORTED_RXDIDS");
449 vf->supported_rxdid =
450 ((struct virtchnl_supported_rxdids *)args.out_buffer)->supported_rxdids;
456 iavf_enable_queues(struct iavf_adapter *adapter)
458 struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(adapter);
459 struct virtchnl_queue_select queue_select;
460 struct iavf_cmd_info args;
463 memset(&queue_select, 0, sizeof(queue_select));
464 queue_select.vsi_id = vf->vsi_res->vsi_id;
466 queue_select.rx_queues = BIT(adapter->eth_dev->data->nb_rx_queues) - 1;
467 queue_select.tx_queues = BIT(adapter->eth_dev->data->nb_tx_queues) - 1;
469 args.ops = VIRTCHNL_OP_ENABLE_QUEUES;
470 args.in_args = (u8 *)&queue_select;
471 args.in_args_size = sizeof(queue_select);
472 args.out_buffer = vf->aq_resp;
473 args.out_size = IAVF_AQ_BUF_SZ;
474 err = iavf_execute_vf_cmd(adapter, &args);
477 "Failed to execute command of OP_ENABLE_QUEUES");
484 iavf_disable_queues(struct iavf_adapter *adapter)
486 struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(adapter);
487 struct virtchnl_queue_select queue_select;
488 struct iavf_cmd_info args;
491 memset(&queue_select, 0, sizeof(queue_select));
492 queue_select.vsi_id = vf->vsi_res->vsi_id;
494 queue_select.rx_queues = BIT(adapter->eth_dev->data->nb_rx_queues) - 1;
495 queue_select.tx_queues = BIT(adapter->eth_dev->data->nb_tx_queues) - 1;
497 args.ops = VIRTCHNL_OP_DISABLE_QUEUES;
498 args.in_args = (u8 *)&queue_select;
499 args.in_args_size = sizeof(queue_select);
500 args.out_buffer = vf->aq_resp;
501 args.out_size = IAVF_AQ_BUF_SZ;
502 err = iavf_execute_vf_cmd(adapter, &args);
505 "Failed to execute command of OP_DISABLE_QUEUES");
512 iavf_switch_queue(struct iavf_adapter *adapter, uint16_t qid,
515 struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(adapter);
516 struct virtchnl_queue_select queue_select;
517 struct iavf_cmd_info args;
520 memset(&queue_select, 0, sizeof(queue_select));
521 queue_select.vsi_id = vf->vsi_res->vsi_id;
523 queue_select.rx_queues |= 1 << qid;
525 queue_select.tx_queues |= 1 << qid;
528 args.ops = VIRTCHNL_OP_ENABLE_QUEUES;
530 args.ops = VIRTCHNL_OP_DISABLE_QUEUES;
531 args.in_args = (u8 *)&queue_select;
532 args.in_args_size = sizeof(queue_select);
533 args.out_buffer = vf->aq_resp;
534 args.out_size = IAVF_AQ_BUF_SZ;
535 err = iavf_execute_vf_cmd(adapter, &args);
537 PMD_DRV_LOG(ERR, "Failed to execute command of %s",
538 on ? "OP_ENABLE_QUEUES" : "OP_DISABLE_QUEUES");
543 iavf_configure_rss_lut(struct iavf_adapter *adapter)
545 struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(adapter);
546 struct virtchnl_rss_lut *rss_lut;
547 struct iavf_cmd_info args;
550 len = sizeof(*rss_lut) + vf->vf_res->rss_lut_size - 1;
551 rss_lut = rte_zmalloc("rss_lut", len, 0);
555 rss_lut->vsi_id = vf->vsi_res->vsi_id;
556 rss_lut->lut_entries = vf->vf_res->rss_lut_size;
557 rte_memcpy(rss_lut->lut, vf->rss_lut, vf->vf_res->rss_lut_size);
559 args.ops = VIRTCHNL_OP_CONFIG_RSS_LUT;
560 args.in_args = (u8 *)rss_lut;
561 args.in_args_size = len;
562 args.out_buffer = vf->aq_resp;
563 args.out_size = IAVF_AQ_BUF_SZ;
565 err = iavf_execute_vf_cmd(adapter, &args);
568 "Failed to execute command of OP_CONFIG_RSS_LUT");
575 iavf_configure_rss_key(struct iavf_adapter *adapter)
577 struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(adapter);
578 struct virtchnl_rss_key *rss_key;
579 struct iavf_cmd_info args;
582 len = sizeof(*rss_key) + vf->vf_res->rss_key_size - 1;
583 rss_key = rte_zmalloc("rss_key", len, 0);
587 rss_key->vsi_id = vf->vsi_res->vsi_id;
588 rss_key->key_len = vf->vf_res->rss_key_size;
589 rte_memcpy(rss_key->key, vf->rss_key, vf->vf_res->rss_key_size);
591 args.ops = VIRTCHNL_OP_CONFIG_RSS_KEY;
592 args.in_args = (u8 *)rss_key;
593 args.in_args_size = len;
594 args.out_buffer = vf->aq_resp;
595 args.out_size = IAVF_AQ_BUF_SZ;
597 err = iavf_execute_vf_cmd(adapter, &args);
600 "Failed to execute command of OP_CONFIG_RSS_KEY");
607 iavf_configure_queues(struct iavf_adapter *adapter)
609 struct iavf_rx_queue **rxq =
610 (struct iavf_rx_queue **)adapter->eth_dev->data->rx_queues;
611 struct iavf_tx_queue **txq =
612 (struct iavf_tx_queue **)adapter->eth_dev->data->tx_queues;
613 struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(adapter);
614 struct virtchnl_vsi_queue_config_info *vc_config;
615 struct virtchnl_queue_pair_info *vc_qp;
616 struct iavf_cmd_info args;
620 size = sizeof(*vc_config) +
621 sizeof(vc_config->qpair[0]) * vf->num_queue_pairs;
622 vc_config = rte_zmalloc("cfg_queue", size, 0);
626 vc_config->vsi_id = vf->vsi_res->vsi_id;
627 vc_config->num_queue_pairs = vf->num_queue_pairs;
629 for (i = 0, vc_qp = vc_config->qpair;
630 i < vf->num_queue_pairs;
632 vc_qp->txq.vsi_id = vf->vsi_res->vsi_id;
633 vc_qp->txq.queue_id = i;
634 /* Virtchnnl configure queues by pairs */
635 if (i < adapter->eth_dev->data->nb_tx_queues) {
636 vc_qp->txq.ring_len = txq[i]->nb_tx_desc;
637 vc_qp->txq.dma_ring_addr = txq[i]->tx_ring_phys_addr;
639 vc_qp->rxq.vsi_id = vf->vsi_res->vsi_id;
640 vc_qp->rxq.queue_id = i;
641 vc_qp->rxq.max_pkt_size = vf->max_pkt_len;
642 /* Virtchnnl configure queues by pairs */
643 if (i < adapter->eth_dev->data->nb_rx_queues) {
644 vc_qp->rxq.ring_len = rxq[i]->nb_rx_desc;
645 vc_qp->rxq.dma_ring_addr = rxq[i]->rx_ring_phys_addr;
646 vc_qp->rxq.databuffer_size = rxq[i]->rx_buf_len;
649 #ifndef RTE_LIBRTE_IAVF_16BYTE_RX_DESC
650 if (vf->vf_res->vf_cap_flags &
651 VIRTCHNL_VF_OFFLOAD_RX_FLEX_DESC &&
652 vf->supported_rxdid & BIT(IAVF_RXDID_COMMS_OVS_1)) {
653 vc_qp->rxq.rxdid = IAVF_RXDID_COMMS_OVS_1;
654 PMD_DRV_LOG(NOTICE, "request RXDID == %d in "
655 "Queue[%d]", vc_qp->rxq.rxdid, i);
657 vc_qp->rxq.rxdid = IAVF_RXDID_LEGACY_1;
658 PMD_DRV_LOG(NOTICE, "request RXDID == %d in "
659 "Queue[%d]", vc_qp->rxq.rxdid, i);
662 if (vf->vf_res->vf_cap_flags &
663 VIRTCHNL_VF_OFFLOAD_RX_FLEX_DESC &&
664 vf->supported_rxdid & BIT(IAVF_RXDID_LEGACY_0)) {
665 vc_qp->rxq.rxdid = IAVF_RXDID_LEGACY_0;
666 PMD_DRV_LOG(NOTICE, "request RXDID == %d in "
667 "Queue[%d]", vc_qp->rxq.rxdid, i);
669 PMD_DRV_LOG(ERR, "RXDID == 0 is not supported");
675 memset(&args, 0, sizeof(args));
676 args.ops = VIRTCHNL_OP_CONFIG_VSI_QUEUES;
677 args.in_args = (uint8_t *)vc_config;
678 args.in_args_size = size;
679 args.out_buffer = vf->aq_resp;
680 args.out_size = IAVF_AQ_BUF_SZ;
682 err = iavf_execute_vf_cmd(adapter, &args);
684 PMD_DRV_LOG(ERR, "Failed to execute command of"
685 " VIRTCHNL_OP_CONFIG_VSI_QUEUES");
692 iavf_config_irq_map(struct iavf_adapter *adapter)
694 struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(adapter);
695 struct virtchnl_irq_map_info *map_info;
696 struct virtchnl_vector_map *vecmap;
697 struct iavf_cmd_info args;
700 len = sizeof(struct virtchnl_irq_map_info) +
701 sizeof(struct virtchnl_vector_map) * vf->nb_msix;
703 map_info = rte_zmalloc("map_info", len, 0);
707 map_info->num_vectors = vf->nb_msix;
708 for (i = 0; i < vf->nb_msix; i++) {
709 vecmap = &map_info->vecmap[i];
710 vecmap->vsi_id = vf->vsi_res->vsi_id;
711 vecmap->rxitr_idx = IAVF_ITR_INDEX_DEFAULT;
712 vecmap->vector_id = vf->msix_base + i;
714 vecmap->rxq_map = vf->rxq_map[vf->msix_base + i];
717 args.ops = VIRTCHNL_OP_CONFIG_IRQ_MAP;
718 args.in_args = (u8 *)map_info;
719 args.in_args_size = len;
720 args.out_buffer = vf->aq_resp;
721 args.out_size = IAVF_AQ_BUF_SZ;
722 err = iavf_execute_vf_cmd(adapter, &args);
724 PMD_DRV_LOG(ERR, "fail to execute command OP_CONFIG_IRQ_MAP");
731 iavf_add_del_all_mac_addr(struct iavf_adapter *adapter, bool add)
733 struct virtchnl_ether_addr_list *list;
734 struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(adapter);
735 struct rte_ether_addr *addr;
736 struct iavf_cmd_info args;
743 len = sizeof(struct virtchnl_ether_addr_list);
744 for (i = begin; i < IAVF_NUM_MACADDR_MAX; i++, next_begin++) {
745 addr = &adapter->eth_dev->data->mac_addrs[i];
746 if (rte_is_zero_ether_addr(addr))
748 len += sizeof(struct virtchnl_ether_addr);
749 if (len >= IAVF_AQ_BUF_SZ) {
755 list = rte_zmalloc("iavf_del_mac_buffer", len, 0);
757 PMD_DRV_LOG(ERR, "fail to allocate memory");
761 for (i = begin; i < next_begin; i++) {
762 addr = &adapter->eth_dev->data->mac_addrs[i];
763 if (rte_is_zero_ether_addr(addr))
765 rte_memcpy(list->list[j].addr, addr->addr_bytes,
766 sizeof(addr->addr_bytes));
767 PMD_DRV_LOG(DEBUG, "add/rm mac:%x:%x:%x:%x:%x:%x",
768 addr->addr_bytes[0], addr->addr_bytes[1],
769 addr->addr_bytes[2], addr->addr_bytes[3],
770 addr->addr_bytes[4], addr->addr_bytes[5]);
773 list->vsi_id = vf->vsi_res->vsi_id;
774 list->num_elements = j;
775 args.ops = add ? VIRTCHNL_OP_ADD_ETH_ADDR :
776 VIRTCHNL_OP_DEL_ETH_ADDR;
777 args.in_args = (uint8_t *)list;
778 args.in_args_size = len;
779 args.out_buffer = vf->aq_resp;
780 args.out_size = IAVF_AQ_BUF_SZ;
781 err = iavf_execute_vf_cmd(adapter, &args);
783 PMD_DRV_LOG(ERR, "fail to execute command %s",
784 add ? "OP_ADD_ETHER_ADDRESS" :
785 "OP_DEL_ETHER_ADDRESS");
788 } while (begin < IAVF_NUM_MACADDR_MAX);
792 iavf_query_stats(struct iavf_adapter *adapter,
793 struct virtchnl_eth_stats **pstats)
795 struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(adapter);
796 struct virtchnl_queue_select q_stats;
797 struct iavf_cmd_info args;
800 memset(&q_stats, 0, sizeof(q_stats));
801 q_stats.vsi_id = vf->vsi_res->vsi_id;
802 args.ops = VIRTCHNL_OP_GET_STATS;
803 args.in_args = (uint8_t *)&q_stats;
804 args.in_args_size = sizeof(q_stats);
805 args.out_buffer = vf->aq_resp;
806 args.out_size = IAVF_AQ_BUF_SZ;
808 err = iavf_execute_vf_cmd(adapter, &args);
810 PMD_DRV_LOG(ERR, "fail to execute command OP_GET_STATS");
814 *pstats = (struct virtchnl_eth_stats *)args.out_buffer;
819 iavf_config_promisc(struct iavf_adapter *adapter,
821 bool enable_multicast)
823 struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(adapter);
824 struct virtchnl_promisc_info promisc;
825 struct iavf_cmd_info args;
829 promisc.vsi_id = vf->vsi_res->vsi_id;
832 promisc.flags |= FLAG_VF_UNICAST_PROMISC;
834 if (enable_multicast)
835 promisc.flags |= FLAG_VF_MULTICAST_PROMISC;
837 args.ops = VIRTCHNL_OP_CONFIG_PROMISCUOUS_MODE;
838 args.in_args = (uint8_t *)&promisc;
839 args.in_args_size = sizeof(promisc);
840 args.out_buffer = vf->aq_resp;
841 args.out_size = IAVF_AQ_BUF_SZ;
843 err = iavf_execute_vf_cmd(adapter, &args);
847 "fail to execute command CONFIG_PROMISCUOUS_MODE");
849 if (err == IAVF_NOT_SUPPORTED)
855 vf->promisc_unicast_enabled = enable_unicast;
856 vf->promisc_multicast_enabled = enable_multicast;
861 iavf_add_del_eth_addr(struct iavf_adapter *adapter, struct rte_ether_addr *addr,
864 struct virtchnl_ether_addr_list *list;
865 struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(adapter);
866 uint8_t cmd_buffer[sizeof(struct virtchnl_ether_addr_list) +
867 sizeof(struct virtchnl_ether_addr)];
868 struct iavf_cmd_info args;
871 list = (struct virtchnl_ether_addr_list *)cmd_buffer;
872 list->vsi_id = vf->vsi_res->vsi_id;
873 list->num_elements = 1;
874 rte_memcpy(list->list[0].addr, addr->addr_bytes,
875 sizeof(addr->addr_bytes));
877 args.ops = add ? VIRTCHNL_OP_ADD_ETH_ADDR : VIRTCHNL_OP_DEL_ETH_ADDR;
878 args.in_args = cmd_buffer;
879 args.in_args_size = sizeof(cmd_buffer);
880 args.out_buffer = vf->aq_resp;
881 args.out_size = IAVF_AQ_BUF_SZ;
882 err = iavf_execute_vf_cmd(adapter, &args);
884 PMD_DRV_LOG(ERR, "fail to execute command %s",
885 add ? "OP_ADD_ETH_ADDR" : "OP_DEL_ETH_ADDR");
890 iavf_add_del_vlan(struct iavf_adapter *adapter, uint16_t vlanid, bool add)
892 struct virtchnl_vlan_filter_list *vlan_list;
893 struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(adapter);
894 uint8_t cmd_buffer[sizeof(struct virtchnl_vlan_filter_list) +
896 struct iavf_cmd_info args;
899 vlan_list = (struct virtchnl_vlan_filter_list *)cmd_buffer;
900 vlan_list->vsi_id = vf->vsi_res->vsi_id;
901 vlan_list->num_elements = 1;
902 vlan_list->vlan_id[0] = vlanid;
904 args.ops = add ? VIRTCHNL_OP_ADD_VLAN : VIRTCHNL_OP_DEL_VLAN;
905 args.in_args = cmd_buffer;
906 args.in_args_size = sizeof(cmd_buffer);
907 args.out_buffer = vf->aq_resp;
908 args.out_size = IAVF_AQ_BUF_SZ;
909 err = iavf_execute_vf_cmd(adapter, &args);
911 PMD_DRV_LOG(ERR, "fail to execute command %s",
912 add ? "OP_ADD_VLAN" : "OP_DEL_VLAN");
918 iavf_fdir_add(struct iavf_adapter *adapter,
919 struct iavf_fdir_conf *filter)
921 struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(adapter);
922 struct virtchnl_fdir_add *fdir_ret;
924 struct iavf_cmd_info args;
927 filter->add_fltr.vsi_id = vf->vsi_res->vsi_id;
928 filter->add_fltr.validate_only = 0;
930 args.ops = VIRTCHNL_OP_ADD_FDIR_FILTER;
931 args.in_args = (uint8_t *)(&filter->add_fltr);
932 args.in_args_size = sizeof(*(&filter->add_fltr));
933 args.out_buffer = vf->aq_resp;
934 args.out_size = IAVF_AQ_BUF_SZ;
936 err = iavf_execute_vf_cmd(adapter, &args);
938 PMD_DRV_LOG(ERR, "fail to execute command OP_ADD_FDIR_FILTER");
942 fdir_ret = (struct virtchnl_fdir_add *)args.out_buffer;
943 filter->flow_id = fdir_ret->flow_id;
945 if (fdir_ret->status == VIRTCHNL_FDIR_SUCCESS) {
947 "Succeed in adding rule request by PF");
948 } else if (fdir_ret->status == VIRTCHNL_FDIR_FAILURE_RULE_NORESOURCE) {
950 "Failed to add rule request due to no hw resource");
952 } else if (fdir_ret->status == VIRTCHNL_FDIR_FAILURE_RULE_EXIST) {
954 "Failed to add rule request due to the rule is already existed");
956 } else if (fdir_ret->status == VIRTCHNL_FDIR_FAILURE_RULE_CONFLICT) {
958 "Failed to add rule request due to the rule is conflict with existing rule");
960 } else if (fdir_ret->status == VIRTCHNL_FDIR_FAILURE_RULE_INVALID) {
962 "Failed to add rule request due to the hw doesn't support");
964 } else if (fdir_ret->status == VIRTCHNL_FDIR_FAILURE_RULE_TIMEOUT) {
966 "Failed to add rule request due to time out for programming");
970 "Failed to add rule request due to other reasons");
978 iavf_fdir_del(struct iavf_adapter *adapter,
979 struct iavf_fdir_conf *filter)
981 struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(adapter);
982 struct virtchnl_fdir_del *fdir_ret;
984 struct iavf_cmd_info args;
987 filter->del_fltr.vsi_id = vf->vsi_res->vsi_id;
988 filter->del_fltr.flow_id = filter->flow_id;
990 args.ops = VIRTCHNL_OP_DEL_FDIR_FILTER;
991 args.in_args = (uint8_t *)(&filter->del_fltr);
992 args.in_args_size = sizeof(filter->del_fltr);
993 args.out_buffer = vf->aq_resp;
994 args.out_size = IAVF_AQ_BUF_SZ;
996 err = iavf_execute_vf_cmd(adapter, &args);
998 PMD_DRV_LOG(ERR, "fail to execute command OP_DEL_FDIR_FILTER");
1002 fdir_ret = (struct virtchnl_fdir_del *)args.out_buffer;
1004 if (fdir_ret->status == VIRTCHNL_FDIR_SUCCESS) {
1006 "Succeed in deleting rule request by PF");
1007 } else if (fdir_ret->status == VIRTCHNL_FDIR_FAILURE_RULE_NONEXIST) {
1009 "Failed to delete rule request due to this rule doesn't exist");
1011 } else if (fdir_ret->status == VIRTCHNL_FDIR_FAILURE_RULE_TIMEOUT) {
1013 "Failed to delete rule request due to time out for programming");
1017 "Failed to delete rule request due to other reasons");
1025 iavf_fdir_check(struct iavf_adapter *adapter,
1026 struct iavf_fdir_conf *filter)
1028 struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(adapter);
1029 struct virtchnl_fdir_add *fdir_ret;
1031 struct iavf_cmd_info args;
1034 filter->add_fltr.vsi_id = vf->vsi_res->vsi_id;
1035 filter->add_fltr.validate_only = 1;
1037 args.ops = VIRTCHNL_OP_ADD_FDIR_FILTER;
1038 args.in_args = (uint8_t *)(&filter->add_fltr);
1039 args.in_args_size = sizeof(*(&filter->add_fltr));
1040 args.out_buffer = vf->aq_resp;
1041 args.out_size = IAVF_AQ_BUF_SZ;
1043 err = iavf_execute_vf_cmd(adapter, &args);
1045 PMD_DRV_LOG(ERR, "fail to check flow direcotor rule");
1049 fdir_ret = (struct virtchnl_fdir_add *)args.out_buffer;
1051 if (fdir_ret->status == VIRTCHNL_FDIR_SUCCESS) {
1053 "Succeed in checking rule request by PF");
1054 } else if (fdir_ret->status == VIRTCHNL_FDIR_FAILURE_RULE_INVALID) {
1056 "Failed to check rule request due to parameters validation"
1057 " or HW doesn't support");
1061 "Failed to check rule request due to other reasons");
1069 iavf_add_del_rss_cfg(struct iavf_adapter *adapter,
1070 struct virtchnl_rss_cfg *rss_cfg, bool add)
1072 struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(adapter);
1073 struct iavf_cmd_info args;
1076 memset(&args, 0, sizeof(args));
1077 args.ops = add ? VIRTCHNL_OP_ADD_RSS_CFG :
1078 VIRTCHNL_OP_DEL_RSS_CFG;
1079 args.in_args = (u8 *)rss_cfg;
1080 args.in_args_size = sizeof(*rss_cfg);
1081 args.out_buffer = vf->aq_resp;
1082 args.out_size = IAVF_AQ_BUF_SZ;
1084 err = iavf_execute_vf_cmd(adapter, &args);
1087 "Failed to execute command of %s",
1088 add ? "OP_ADD_RSS_CFG" :
1089 "OP_DEL_RSS_INPUT_CFG");
1095 iavf_add_del_mc_addr_list(struct iavf_adapter *adapter,
1096 struct rte_ether_addr *mc_addrs,
1097 uint32_t mc_addrs_num, bool add)
1099 struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(adapter);
1100 uint8_t cmd_buffer[sizeof(struct virtchnl_ether_addr_list) +
1101 (IAVF_NUM_MACADDR_MAX * sizeof(struct virtchnl_ether_addr))];
1102 struct virtchnl_ether_addr_list *list;
1103 struct iavf_cmd_info args;
1107 if (mc_addrs == NULL || mc_addrs_num == 0)
1110 if (mc_addrs_num > IAVF_NUM_MACADDR_MAX)
1113 list = (struct virtchnl_ether_addr_list *)cmd_buffer;
1114 list->vsi_id = vf->vsi_res->vsi_id;
1115 list->num_elements = mc_addrs_num;
1117 for (i = 0; i < mc_addrs_num; i++) {
1118 if (!IAVF_IS_MULTICAST(mc_addrs[i].addr_bytes)) {
1119 PMD_DRV_LOG(ERR, "Invalid mac:%x:%x:%x:%x:%x:%x",
1120 mc_addrs[i].addr_bytes[0],
1121 mc_addrs[i].addr_bytes[1],
1122 mc_addrs[i].addr_bytes[2],
1123 mc_addrs[i].addr_bytes[3],
1124 mc_addrs[i].addr_bytes[4],
1125 mc_addrs[i].addr_bytes[5]);
1129 memcpy(list->list[i].addr, mc_addrs[i].addr_bytes,
1130 sizeof(list->list[i].addr));
1133 args.ops = add ? VIRTCHNL_OP_ADD_ETH_ADDR : VIRTCHNL_OP_DEL_ETH_ADDR;
1134 args.in_args = cmd_buffer;
1135 args.in_args_size = sizeof(struct virtchnl_ether_addr_list) +
1136 i * sizeof(struct virtchnl_ether_addr);
1137 args.out_buffer = vf->aq_resp;
1138 args.out_size = IAVF_AQ_BUF_SZ;
1139 err = iavf_execute_vf_cmd(adapter, &args);
1142 PMD_DRV_LOG(ERR, "fail to execute command %s",
1143 add ? "OP_ADD_ETH_ADDR" : "OP_DEL_ETH_ADDR");