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))
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");
192 rte_eth_dev_callback_process(dev, RTE_ETH_EVENT_INTR_RESET,
195 case VIRTCHNL_EVENT_LINK_CHANGE:
196 PMD_DRV_LOG(DEBUG, "VIRTCHNL_EVENT_LINK_CHANGE event");
197 vf->link_up = pf_msg->event_data.link_event.link_status;
198 if (vf->vf_res->vf_cap_flags & VIRTCHNL_VF_CAP_ADV_LINK_SPEED) {
200 pf_msg->event_data.link_event_adv.link_speed;
202 enum virtchnl_link_speed speed;
203 speed = pf_msg->event_data.link_event.link_speed;
204 vf->link_speed = iavf_convert_link_speed(speed);
206 iavf_dev_link_update(dev, 0);
207 rte_eth_dev_callback_process(dev, RTE_ETH_EVENT_INTR_LSC, NULL);
209 case VIRTCHNL_EVENT_PF_DRIVER_CLOSE:
210 PMD_DRV_LOG(DEBUG, "VIRTCHNL_EVENT_PF_DRIVER_CLOSE event");
213 PMD_DRV_LOG(ERR, " unknown event received %u", pf_msg->event);
219 iavf_handle_virtchnl_msg(struct rte_eth_dev *dev)
221 struct iavf_hw *hw = IAVF_DEV_PRIVATE_TO_HW(dev->data->dev_private);
222 struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(dev->data->dev_private);
223 struct iavf_arq_event_info info;
224 uint16_t pending, aq_opc;
225 enum virtchnl_ops msg_opc;
226 enum iavf_status msg_ret;
229 info.buf_len = IAVF_AQ_BUF_SZ;
231 PMD_DRV_LOG(ERR, "Buffer for adminq resp should not be NULL");
234 info.msg_buf = vf->aq_resp;
238 ret = iavf_clean_arq_element(hw, &info, &pending);
240 if (ret != IAVF_SUCCESS) {
241 PMD_DRV_LOG(INFO, "Failed to read msg from AdminQ,"
245 aq_opc = rte_le_to_cpu_16(info.desc.opcode);
246 /* For the message sent from pf to vf, opcode is stored in
247 * cookie_high of struct iavf_aq_desc, while return error code
248 * are stored in cookie_low, Which is done by PF driver.
250 msg_opc = (enum virtchnl_ops)rte_le_to_cpu_32(
251 info.desc.cookie_high);
252 msg_ret = (enum iavf_status)rte_le_to_cpu_32(
253 info.desc.cookie_low);
255 case iavf_aqc_opc_send_msg_to_vf:
256 if (msg_opc == VIRTCHNL_OP_EVENT) {
257 iavf_handle_pf_event_msg(dev, info.msg_buf,
260 /* read message and it's expected one */
261 if (msg_opc == vf->pend_cmd)
262 _notify_cmd(vf, msg_ret);
264 PMD_DRV_LOG(ERR, "command mismatch,"
266 vf->pend_cmd, msg_opc);
268 "adminq response is received,"
269 " opcode = %d", msg_opc);
273 PMD_DRV_LOG(DEBUG, "Request %u is not supported yet",
281 iavf_enable_vlan_strip(struct iavf_adapter *adapter)
283 struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(adapter);
284 struct iavf_cmd_info args;
287 memset(&args, 0, sizeof(args));
288 args.ops = VIRTCHNL_OP_ENABLE_VLAN_STRIPPING;
290 args.in_args_size = 0;
291 args.out_buffer = vf->aq_resp;
292 args.out_size = IAVF_AQ_BUF_SZ;
293 ret = iavf_execute_vf_cmd(adapter, &args);
295 PMD_DRV_LOG(ERR, "Failed to execute command of"
296 " OP_ENABLE_VLAN_STRIPPING");
302 iavf_disable_vlan_strip(struct iavf_adapter *adapter)
304 struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(adapter);
305 struct iavf_cmd_info args;
308 memset(&args, 0, sizeof(args));
309 args.ops = VIRTCHNL_OP_DISABLE_VLAN_STRIPPING;
311 args.in_args_size = 0;
312 args.out_buffer = vf->aq_resp;
313 args.out_size = IAVF_AQ_BUF_SZ;
314 ret = iavf_execute_vf_cmd(adapter, &args);
316 PMD_DRV_LOG(ERR, "Failed to execute command of"
317 " OP_DISABLE_VLAN_STRIPPING");
322 #define VIRTCHNL_VERSION_MAJOR_START 1
323 #define VIRTCHNL_VERSION_MINOR_START 1
325 /* Check API version with sync wait until version read from admin queue */
327 iavf_check_api_version(struct iavf_adapter *adapter)
329 struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(adapter);
330 struct virtchnl_version_info version, *pver;
331 struct iavf_cmd_info args;
334 version.major = VIRTCHNL_VERSION_MAJOR;
335 version.minor = VIRTCHNL_VERSION_MINOR;
337 args.ops = VIRTCHNL_OP_VERSION;
338 args.in_args = (uint8_t *)&version;
339 args.in_args_size = sizeof(version);
340 args.out_buffer = vf->aq_resp;
341 args.out_size = IAVF_AQ_BUF_SZ;
343 err = iavf_execute_vf_cmd(adapter, &args);
345 PMD_INIT_LOG(ERR, "Fail to execute command of OP_VERSION");
349 pver = (struct virtchnl_version_info *)args.out_buffer;
350 vf->virtchnl_version = *pver;
352 if (vf->virtchnl_version.major < VIRTCHNL_VERSION_MAJOR_START ||
353 (vf->virtchnl_version.major == VIRTCHNL_VERSION_MAJOR_START &&
354 vf->virtchnl_version.minor < VIRTCHNL_VERSION_MINOR_START)) {
355 PMD_INIT_LOG(ERR, "VIRTCHNL API version should not be lower"
356 " than (%u.%u) to support Adapative VF",
357 VIRTCHNL_VERSION_MAJOR_START,
358 VIRTCHNL_VERSION_MAJOR_START);
360 } else if (vf->virtchnl_version.major > VIRTCHNL_VERSION_MAJOR ||
361 (vf->virtchnl_version.major == VIRTCHNL_VERSION_MAJOR &&
362 vf->virtchnl_version.minor > VIRTCHNL_VERSION_MINOR)) {
363 PMD_INIT_LOG(ERR, "PF/VF API version mismatch:(%u.%u)-(%u.%u)",
364 vf->virtchnl_version.major,
365 vf->virtchnl_version.minor,
366 VIRTCHNL_VERSION_MAJOR,
367 VIRTCHNL_VERSION_MINOR);
371 PMD_DRV_LOG(DEBUG, "Peer is supported PF host");
376 iavf_get_vf_resource(struct iavf_adapter *adapter)
378 struct iavf_hw *hw = IAVF_DEV_PRIVATE_TO_HW(adapter);
379 struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(adapter);
380 struct iavf_cmd_info args;
384 args.ops = VIRTCHNL_OP_GET_VF_RESOURCES;
385 args.out_buffer = vf->aq_resp;
386 args.out_size = IAVF_AQ_BUF_SZ;
388 caps = IAVF_BASIC_OFFLOAD_CAPS | VIRTCHNL_VF_CAP_ADV_LINK_SPEED |
389 VIRTCHNL_VF_OFFLOAD_RX_FLEX_DESC |
390 VIRTCHNL_VF_OFFLOAD_FDIR_PF |
391 VIRTCHNL_VF_OFFLOAD_ADV_RSS_PF;
393 args.in_args = (uint8_t *)∩︀
394 args.in_args_size = sizeof(caps);
396 err = iavf_execute_vf_cmd(adapter, &args);
400 "Failed to execute command of OP_GET_VF_RESOURCE");
404 len = sizeof(struct virtchnl_vf_resource) +
405 IAVF_MAX_VF_VSI * sizeof(struct virtchnl_vsi_resource);
407 rte_memcpy(vf->vf_res, args.out_buffer,
408 RTE_MIN(args.out_size, len));
409 /* parse VF config message back from PF*/
410 iavf_vf_parse_hw_config(hw, vf->vf_res);
411 for (i = 0; i < vf->vf_res->num_vsis; i++) {
412 if (vf->vf_res->vsi_res[i].vsi_type == VIRTCHNL_VSI_SRIOV)
413 vf->vsi_res = &vf->vf_res->vsi_res[i];
417 PMD_INIT_LOG(ERR, "no LAN VSI found");
421 vf->vsi.vsi_id = vf->vsi_res->vsi_id;
422 vf->vsi.nb_qps = vf->vsi_res->num_queue_pairs;
423 vf->vsi.adapter = adapter;
429 iavf_get_supported_rxdid(struct iavf_adapter *adapter)
431 struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(adapter);
432 struct iavf_cmd_info args;
435 args.ops = VIRTCHNL_OP_GET_SUPPORTED_RXDIDS;
437 args.in_args_size = 0;
438 args.out_buffer = vf->aq_resp;
439 args.out_size = IAVF_AQ_BUF_SZ;
441 ret = iavf_execute_vf_cmd(adapter, &args);
444 "Failed to execute command of OP_GET_SUPPORTED_RXDIDS");
448 vf->supported_rxdid =
449 ((struct virtchnl_supported_rxdids *)args.out_buffer)->supported_rxdids;
455 iavf_enable_queues(struct iavf_adapter *adapter)
457 struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(adapter);
458 struct virtchnl_queue_select queue_select;
459 struct iavf_cmd_info args;
462 memset(&queue_select, 0, sizeof(queue_select));
463 queue_select.vsi_id = vf->vsi_res->vsi_id;
465 queue_select.rx_queues = BIT(adapter->eth_dev->data->nb_rx_queues) - 1;
466 queue_select.tx_queues = BIT(adapter->eth_dev->data->nb_tx_queues) - 1;
468 args.ops = VIRTCHNL_OP_ENABLE_QUEUES;
469 args.in_args = (u8 *)&queue_select;
470 args.in_args_size = sizeof(queue_select);
471 args.out_buffer = vf->aq_resp;
472 args.out_size = IAVF_AQ_BUF_SZ;
473 err = iavf_execute_vf_cmd(adapter, &args);
476 "Failed to execute command of OP_ENABLE_QUEUES");
483 iavf_disable_queues(struct iavf_adapter *adapter)
485 struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(adapter);
486 struct virtchnl_queue_select queue_select;
487 struct iavf_cmd_info args;
490 memset(&queue_select, 0, sizeof(queue_select));
491 queue_select.vsi_id = vf->vsi_res->vsi_id;
493 queue_select.rx_queues = BIT(adapter->eth_dev->data->nb_rx_queues) - 1;
494 queue_select.tx_queues = BIT(adapter->eth_dev->data->nb_tx_queues) - 1;
496 args.ops = VIRTCHNL_OP_DISABLE_QUEUES;
497 args.in_args = (u8 *)&queue_select;
498 args.in_args_size = sizeof(queue_select);
499 args.out_buffer = vf->aq_resp;
500 args.out_size = IAVF_AQ_BUF_SZ;
501 err = iavf_execute_vf_cmd(adapter, &args);
504 "Failed to execute command of OP_DISABLE_QUEUES");
511 iavf_switch_queue(struct iavf_adapter *adapter, uint16_t qid,
514 struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(adapter);
515 struct virtchnl_queue_select queue_select;
516 struct iavf_cmd_info args;
519 memset(&queue_select, 0, sizeof(queue_select));
520 queue_select.vsi_id = vf->vsi_res->vsi_id;
522 queue_select.rx_queues |= 1 << qid;
524 queue_select.tx_queues |= 1 << qid;
527 args.ops = VIRTCHNL_OP_ENABLE_QUEUES;
529 args.ops = VIRTCHNL_OP_DISABLE_QUEUES;
530 args.in_args = (u8 *)&queue_select;
531 args.in_args_size = sizeof(queue_select);
532 args.out_buffer = vf->aq_resp;
533 args.out_size = IAVF_AQ_BUF_SZ;
534 err = iavf_execute_vf_cmd(adapter, &args);
536 PMD_DRV_LOG(ERR, "Failed to execute command of %s",
537 on ? "OP_ENABLE_QUEUES" : "OP_DISABLE_QUEUES");
542 iavf_configure_rss_lut(struct iavf_adapter *adapter)
544 struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(adapter);
545 struct virtchnl_rss_lut *rss_lut;
546 struct iavf_cmd_info args;
549 len = sizeof(*rss_lut) + vf->vf_res->rss_lut_size - 1;
550 rss_lut = rte_zmalloc("rss_lut", len, 0);
554 rss_lut->vsi_id = vf->vsi_res->vsi_id;
555 rss_lut->lut_entries = vf->vf_res->rss_lut_size;
556 rte_memcpy(rss_lut->lut, vf->rss_lut, vf->vf_res->rss_lut_size);
558 args.ops = VIRTCHNL_OP_CONFIG_RSS_LUT;
559 args.in_args = (u8 *)rss_lut;
560 args.in_args_size = len;
561 args.out_buffer = vf->aq_resp;
562 args.out_size = IAVF_AQ_BUF_SZ;
564 err = iavf_execute_vf_cmd(adapter, &args);
567 "Failed to execute command of OP_CONFIG_RSS_LUT");
574 iavf_configure_rss_key(struct iavf_adapter *adapter)
576 struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(adapter);
577 struct virtchnl_rss_key *rss_key;
578 struct iavf_cmd_info args;
581 len = sizeof(*rss_key) + vf->vf_res->rss_key_size - 1;
582 rss_key = rte_zmalloc("rss_key", len, 0);
586 rss_key->vsi_id = vf->vsi_res->vsi_id;
587 rss_key->key_len = vf->vf_res->rss_key_size;
588 rte_memcpy(rss_key->key, vf->rss_key, vf->vf_res->rss_key_size);
590 args.ops = VIRTCHNL_OP_CONFIG_RSS_KEY;
591 args.in_args = (u8 *)rss_key;
592 args.in_args_size = len;
593 args.out_buffer = vf->aq_resp;
594 args.out_size = IAVF_AQ_BUF_SZ;
596 err = iavf_execute_vf_cmd(adapter, &args);
599 "Failed to execute command of OP_CONFIG_RSS_KEY");
606 iavf_configure_queues(struct iavf_adapter *adapter)
608 struct iavf_rx_queue **rxq =
609 (struct iavf_rx_queue **)adapter->eth_dev->data->rx_queues;
610 struct iavf_tx_queue **txq =
611 (struct iavf_tx_queue **)adapter->eth_dev->data->tx_queues;
612 struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(adapter);
613 struct virtchnl_vsi_queue_config_info *vc_config;
614 struct virtchnl_queue_pair_info *vc_qp;
615 struct iavf_cmd_info args;
619 size = sizeof(*vc_config) +
620 sizeof(vc_config->qpair[0]) * vf->num_queue_pairs;
621 vc_config = rte_zmalloc("cfg_queue", size, 0);
625 vc_config->vsi_id = vf->vsi_res->vsi_id;
626 vc_config->num_queue_pairs = vf->num_queue_pairs;
628 for (i = 0, vc_qp = vc_config->qpair;
629 i < vf->num_queue_pairs;
631 vc_qp->txq.vsi_id = vf->vsi_res->vsi_id;
632 vc_qp->txq.queue_id = i;
633 /* Virtchnnl configure queues by pairs */
634 if (i < adapter->eth_dev->data->nb_tx_queues) {
635 vc_qp->txq.ring_len = txq[i]->nb_tx_desc;
636 vc_qp->txq.dma_ring_addr = txq[i]->tx_ring_phys_addr;
638 vc_qp->rxq.vsi_id = vf->vsi_res->vsi_id;
639 vc_qp->rxq.queue_id = i;
640 vc_qp->rxq.max_pkt_size = vf->max_pkt_len;
641 /* Virtchnnl configure queues by pairs */
642 if (i < adapter->eth_dev->data->nb_rx_queues) {
643 vc_qp->rxq.ring_len = rxq[i]->nb_rx_desc;
644 vc_qp->rxq.dma_ring_addr = rxq[i]->rx_ring_phys_addr;
645 vc_qp->rxq.databuffer_size = rxq[i]->rx_buf_len;
648 #ifndef RTE_LIBRTE_IAVF_16BYTE_RX_DESC
649 if (vf->vf_res->vf_cap_flags &
650 VIRTCHNL_VF_OFFLOAD_RX_FLEX_DESC &&
651 vf->supported_rxdid & BIT(IAVF_RXDID_COMMS_OVS_1)) {
652 vc_qp->rxq.rxdid = IAVF_RXDID_COMMS_OVS_1;
653 PMD_DRV_LOG(NOTICE, "request RXDID == %d in "
654 "Queue[%d]", vc_qp->rxq.rxdid, i);
656 vc_qp->rxq.rxdid = IAVF_RXDID_LEGACY_1;
657 PMD_DRV_LOG(NOTICE, "request RXDID == %d in "
658 "Queue[%d]", vc_qp->rxq.rxdid, i);
661 if (vf->vf_res->vf_cap_flags &
662 VIRTCHNL_VF_OFFLOAD_RX_FLEX_DESC &&
663 vf->supported_rxdid & BIT(IAVF_RXDID_LEGACY_0)) {
664 vc_qp->rxq.rxdid = IAVF_RXDID_LEGACY_0;
665 PMD_DRV_LOG(NOTICE, "request RXDID == %d in "
666 "Queue[%d]", vc_qp->rxq.rxdid, i);
668 PMD_DRV_LOG(ERR, "RXDID == 0 is not supported");
674 memset(&args, 0, sizeof(args));
675 args.ops = VIRTCHNL_OP_CONFIG_VSI_QUEUES;
676 args.in_args = (uint8_t *)vc_config;
677 args.in_args_size = size;
678 args.out_buffer = vf->aq_resp;
679 args.out_size = IAVF_AQ_BUF_SZ;
681 err = iavf_execute_vf_cmd(adapter, &args);
683 PMD_DRV_LOG(ERR, "Failed to execute command of"
684 " VIRTCHNL_OP_CONFIG_VSI_QUEUES");
691 iavf_config_irq_map(struct iavf_adapter *adapter)
693 struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(adapter);
694 struct virtchnl_irq_map_info *map_info;
695 struct virtchnl_vector_map *vecmap;
696 struct iavf_cmd_info args;
699 len = sizeof(struct virtchnl_irq_map_info) +
700 sizeof(struct virtchnl_vector_map) * vf->nb_msix;
702 map_info = rte_zmalloc("map_info", len, 0);
706 map_info->num_vectors = vf->nb_msix;
707 for (i = 0; i < vf->nb_msix; i++) {
708 vecmap = &map_info->vecmap[i];
709 vecmap->vsi_id = vf->vsi_res->vsi_id;
710 vecmap->rxitr_idx = IAVF_ITR_INDEX_DEFAULT;
711 vecmap->vector_id = vf->msix_base + i;
713 vecmap->rxq_map = vf->rxq_map[vf->msix_base + i];
716 args.ops = VIRTCHNL_OP_CONFIG_IRQ_MAP;
717 args.in_args = (u8 *)map_info;
718 args.in_args_size = len;
719 args.out_buffer = vf->aq_resp;
720 args.out_size = IAVF_AQ_BUF_SZ;
721 err = iavf_execute_vf_cmd(adapter, &args);
723 PMD_DRV_LOG(ERR, "fail to execute command OP_CONFIG_IRQ_MAP");
730 iavf_add_del_all_mac_addr(struct iavf_adapter *adapter, bool add)
732 struct virtchnl_ether_addr_list *list;
733 struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(adapter);
734 struct rte_ether_addr *addr;
735 struct iavf_cmd_info args;
742 len = sizeof(struct virtchnl_ether_addr_list);
743 for (i = begin; i < IAVF_NUM_MACADDR_MAX; i++, next_begin++) {
744 addr = &adapter->eth_dev->data->mac_addrs[i];
745 if (rte_is_zero_ether_addr(addr))
747 len += sizeof(struct virtchnl_ether_addr);
748 if (len >= IAVF_AQ_BUF_SZ) {
754 list = rte_zmalloc("iavf_del_mac_buffer", len, 0);
756 PMD_DRV_LOG(ERR, "fail to allocate memory");
760 for (i = begin; i < next_begin; i++) {
761 addr = &adapter->eth_dev->data->mac_addrs[i];
762 if (rte_is_zero_ether_addr(addr))
764 rte_memcpy(list->list[j].addr, addr->addr_bytes,
765 sizeof(addr->addr_bytes));
766 PMD_DRV_LOG(DEBUG, "add/rm mac:%x:%x:%x:%x:%x:%x",
767 addr->addr_bytes[0], addr->addr_bytes[1],
768 addr->addr_bytes[2], addr->addr_bytes[3],
769 addr->addr_bytes[4], addr->addr_bytes[5]);
772 list->vsi_id = vf->vsi_res->vsi_id;
773 list->num_elements = j;
774 args.ops = add ? VIRTCHNL_OP_ADD_ETH_ADDR :
775 VIRTCHNL_OP_DEL_ETH_ADDR;
776 args.in_args = (uint8_t *)list;
777 args.in_args_size = len;
778 args.out_buffer = vf->aq_resp;
779 args.out_size = IAVF_AQ_BUF_SZ;
780 err = iavf_execute_vf_cmd(adapter, &args);
782 PMD_DRV_LOG(ERR, "fail to execute command %s",
783 add ? "OP_ADD_ETHER_ADDRESS" :
784 "OP_DEL_ETHER_ADDRESS");
787 } while (begin < IAVF_NUM_MACADDR_MAX);
791 iavf_query_stats(struct iavf_adapter *adapter,
792 struct virtchnl_eth_stats **pstats)
794 struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(adapter);
795 struct virtchnl_queue_select q_stats;
796 struct iavf_cmd_info args;
799 memset(&q_stats, 0, sizeof(q_stats));
800 q_stats.vsi_id = vf->vsi_res->vsi_id;
801 args.ops = VIRTCHNL_OP_GET_STATS;
802 args.in_args = (uint8_t *)&q_stats;
803 args.in_args_size = sizeof(q_stats);
804 args.out_buffer = vf->aq_resp;
805 args.out_size = IAVF_AQ_BUF_SZ;
807 err = iavf_execute_vf_cmd(adapter, &args);
809 PMD_DRV_LOG(ERR, "fail to execute command OP_GET_STATS");
813 *pstats = (struct virtchnl_eth_stats *)args.out_buffer;
818 iavf_config_promisc(struct iavf_adapter *adapter,
820 bool enable_multicast)
822 struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(adapter);
823 struct virtchnl_promisc_info promisc;
824 struct iavf_cmd_info args;
828 promisc.vsi_id = vf->vsi_res->vsi_id;
831 promisc.flags |= FLAG_VF_UNICAST_PROMISC;
833 if (enable_multicast)
834 promisc.flags |= FLAG_VF_MULTICAST_PROMISC;
836 args.ops = VIRTCHNL_OP_CONFIG_PROMISCUOUS_MODE;
837 args.in_args = (uint8_t *)&promisc;
838 args.in_args_size = sizeof(promisc);
839 args.out_buffer = vf->aq_resp;
840 args.out_size = IAVF_AQ_BUF_SZ;
842 err = iavf_execute_vf_cmd(adapter, &args);
846 "fail to execute command CONFIG_PROMISCUOUS_MODE");
851 iavf_add_del_eth_addr(struct iavf_adapter *adapter, struct rte_ether_addr *addr,
854 struct virtchnl_ether_addr_list *list;
855 struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(adapter);
856 uint8_t cmd_buffer[sizeof(struct virtchnl_ether_addr_list) +
857 sizeof(struct virtchnl_ether_addr)];
858 struct iavf_cmd_info args;
861 list = (struct virtchnl_ether_addr_list *)cmd_buffer;
862 list->vsi_id = vf->vsi_res->vsi_id;
863 list->num_elements = 1;
864 rte_memcpy(list->list[0].addr, addr->addr_bytes,
865 sizeof(addr->addr_bytes));
867 args.ops = add ? VIRTCHNL_OP_ADD_ETH_ADDR : VIRTCHNL_OP_DEL_ETH_ADDR;
868 args.in_args = cmd_buffer;
869 args.in_args_size = sizeof(cmd_buffer);
870 args.out_buffer = vf->aq_resp;
871 args.out_size = IAVF_AQ_BUF_SZ;
872 err = iavf_execute_vf_cmd(adapter, &args);
874 PMD_DRV_LOG(ERR, "fail to execute command %s",
875 add ? "OP_ADD_ETH_ADDR" : "OP_DEL_ETH_ADDR");
880 iavf_add_del_vlan(struct iavf_adapter *adapter, uint16_t vlanid, bool add)
882 struct virtchnl_vlan_filter_list *vlan_list;
883 struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(adapter);
884 uint8_t cmd_buffer[sizeof(struct virtchnl_vlan_filter_list) +
886 struct iavf_cmd_info args;
889 vlan_list = (struct virtchnl_vlan_filter_list *)cmd_buffer;
890 vlan_list->vsi_id = vf->vsi_res->vsi_id;
891 vlan_list->num_elements = 1;
892 vlan_list->vlan_id[0] = vlanid;
894 args.ops = add ? VIRTCHNL_OP_ADD_VLAN : VIRTCHNL_OP_DEL_VLAN;
895 args.in_args = cmd_buffer;
896 args.in_args_size = sizeof(cmd_buffer);
897 args.out_buffer = vf->aq_resp;
898 args.out_size = IAVF_AQ_BUF_SZ;
899 err = iavf_execute_vf_cmd(adapter, &args);
901 PMD_DRV_LOG(ERR, "fail to execute command %s",
902 add ? "OP_ADD_VLAN" : "OP_DEL_VLAN");
908 iavf_fdir_add(struct iavf_adapter *adapter,
909 struct iavf_fdir_conf *filter)
911 struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(adapter);
912 struct virtchnl_fdir_add *fdir_ret;
914 struct iavf_cmd_info args;
917 filter->add_fltr.vsi_id = vf->vsi_res->vsi_id;
918 filter->add_fltr.validate_only = 0;
920 args.ops = VIRTCHNL_OP_ADD_FDIR_FILTER;
921 args.in_args = (uint8_t *)(&filter->add_fltr);
922 args.in_args_size = sizeof(*(&filter->add_fltr));
923 args.out_buffer = vf->aq_resp;
924 args.out_size = IAVF_AQ_BUF_SZ;
926 err = iavf_execute_vf_cmd(adapter, &args);
928 PMD_DRV_LOG(ERR, "fail to execute command OP_ADD_FDIR_FILTER");
932 fdir_ret = (struct virtchnl_fdir_add *)args.out_buffer;
933 filter->flow_id = fdir_ret->flow_id;
935 if (fdir_ret->status == VIRTCHNL_FDIR_SUCCESS) {
937 "Succeed in adding rule request by PF");
938 } else if (fdir_ret->status == VIRTCHNL_FDIR_FAILURE_RULE_NORESOURCE) {
940 "Failed to add rule request due to no hw resource");
942 } else if (fdir_ret->status == VIRTCHNL_FDIR_FAILURE_RULE_EXIST) {
944 "Failed to add rule request due to the rule is already existed");
946 } else if (fdir_ret->status == VIRTCHNL_FDIR_FAILURE_RULE_CONFLICT) {
948 "Failed to add rule request due to the rule is conflict with existing rule");
950 } else if (fdir_ret->status == VIRTCHNL_FDIR_FAILURE_RULE_INVALID) {
952 "Failed to add rule request due to the hw doesn't support");
954 } else if (fdir_ret->status == VIRTCHNL_FDIR_FAILURE_RULE_TIMEOUT) {
956 "Failed to add rule request due to time out for programming");
960 "Failed to add rule request due to other reasons");
968 iavf_fdir_del(struct iavf_adapter *adapter,
969 struct iavf_fdir_conf *filter)
971 struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(adapter);
972 struct virtchnl_fdir_del *fdir_ret;
974 struct iavf_cmd_info args;
977 filter->del_fltr.vsi_id = vf->vsi_res->vsi_id;
978 filter->del_fltr.flow_id = filter->flow_id;
980 args.ops = VIRTCHNL_OP_DEL_FDIR_FILTER;
981 args.in_args = (uint8_t *)(&filter->del_fltr);
982 args.in_args_size = sizeof(filter->del_fltr);
983 args.out_buffer = vf->aq_resp;
984 args.out_size = IAVF_AQ_BUF_SZ;
986 err = iavf_execute_vf_cmd(adapter, &args);
988 PMD_DRV_LOG(ERR, "fail to execute command OP_DEL_FDIR_FILTER");
992 fdir_ret = (struct virtchnl_fdir_del *)args.out_buffer;
994 if (fdir_ret->status == VIRTCHNL_FDIR_SUCCESS) {
996 "Succeed in deleting rule request by PF");
997 } else if (fdir_ret->status == VIRTCHNL_FDIR_FAILURE_RULE_NONEXIST) {
999 "Failed to delete rule request due to this rule doesn't exist");
1001 } else if (fdir_ret->status == VIRTCHNL_FDIR_FAILURE_RULE_TIMEOUT) {
1003 "Failed to delete rule request due to time out for programming");
1007 "Failed to delete rule request due to other reasons");
1015 iavf_fdir_check(struct iavf_adapter *adapter,
1016 struct iavf_fdir_conf *filter)
1018 struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(adapter);
1019 struct virtchnl_fdir_add *fdir_ret;
1021 struct iavf_cmd_info args;
1024 filter->add_fltr.vsi_id = vf->vsi_res->vsi_id;
1025 filter->add_fltr.validate_only = 1;
1027 args.ops = VIRTCHNL_OP_ADD_FDIR_FILTER;
1028 args.in_args = (uint8_t *)(&filter->add_fltr);
1029 args.in_args_size = sizeof(*(&filter->add_fltr));
1030 args.out_buffer = vf->aq_resp;
1031 args.out_size = IAVF_AQ_BUF_SZ;
1033 err = iavf_execute_vf_cmd(adapter, &args);
1035 PMD_DRV_LOG(ERR, "fail to check flow direcotor rule");
1039 fdir_ret = (struct virtchnl_fdir_add *)args.out_buffer;
1041 if (fdir_ret->status == VIRTCHNL_FDIR_SUCCESS) {
1043 "Succeed in checking rule request by PF");
1044 } else if (fdir_ret->status == VIRTCHNL_FDIR_FAILURE_RULE_INVALID) {
1046 "Failed to check rule request due to parameters validation"
1047 " or HW doesn't support");
1051 "Failed to check rule request due to other reasons");
1059 iavf_add_del_rss_cfg(struct iavf_adapter *adapter,
1060 struct virtchnl_rss_cfg *rss_cfg, bool add)
1062 struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(adapter);
1063 struct iavf_cmd_info args;
1066 memset(&args, 0, sizeof(args));
1067 args.ops = add ? VIRTCHNL_OP_ADD_RSS_CFG :
1068 VIRTCHNL_OP_DEL_RSS_CFG;
1069 args.in_args = (u8 *)rss_cfg;
1070 args.in_args_size = sizeof(*rss_cfg);
1071 args.out_buffer = vf->aq_resp;
1072 args.out_size = IAVF_AQ_BUF_SZ;
1074 err = iavf_execute_vf_cmd(adapter, &args);
1077 "Failed to execute command of %s",
1078 add ? "OP_ADD_RSS_CFG" :
1079 "OP_DEL_RSS_INPUT_CFG");
1085 iavf_add_del_mc_addr_list(struct iavf_adapter *adapter,
1086 struct rte_ether_addr *mc_addrs,
1087 uint32_t mc_addrs_num, bool add)
1089 struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(adapter);
1090 uint8_t cmd_buffer[sizeof(struct virtchnl_ether_addr_list) +
1091 (IAVF_NUM_MACADDR_MAX * sizeof(struct virtchnl_ether_addr))];
1092 struct virtchnl_ether_addr_list *list;
1093 struct iavf_cmd_info args;
1097 if (mc_addrs == NULL || mc_addrs_num == 0)
1100 if (mc_addrs_num > IAVF_NUM_MACADDR_MAX)
1103 list = (struct virtchnl_ether_addr_list *)cmd_buffer;
1104 list->vsi_id = vf->vsi_res->vsi_id;
1105 list->num_elements = mc_addrs_num;
1107 for (i = 0; i < mc_addrs_num; i++) {
1108 if (!IAVF_IS_MULTICAST(mc_addrs[i].addr_bytes)) {
1109 PMD_DRV_LOG(ERR, "Invalid mac:%x:%x:%x:%x:%x:%x",
1110 mc_addrs[i].addr_bytes[0],
1111 mc_addrs[i].addr_bytes[1],
1112 mc_addrs[i].addr_bytes[2],
1113 mc_addrs[i].addr_bytes[3],
1114 mc_addrs[i].addr_bytes[4],
1115 mc_addrs[i].addr_bytes[5]);
1119 memcpy(list->list[i].addr, mc_addrs[i].addr_bytes,
1120 sizeof(list->list[i].addr));
1123 args.ops = add ? VIRTCHNL_OP_ADD_ETH_ADDR : VIRTCHNL_OP_DEL_ETH_ADDR;
1124 args.in_args = cmd_buffer;
1125 args.in_args_size = sizeof(struct virtchnl_ether_addr_list) +
1126 i * sizeof(struct virtchnl_ether_addr);
1127 args.out_buffer = vf->aq_resp;
1128 args.out_size = IAVF_AQ_BUF_SZ;
1129 err = iavf_execute_vf_cmd(adapter, &args);
1132 PMD_DRV_LOG(ERR, "fail to execute command %s",
1133 add ? "OP_ADD_ETH_ADDR" : "OP_DEL_ETH_ADDR");