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
29 iavf_convert_link_speed(enum virtchnl_link_speed virt_link_speed)
33 switch (virt_link_speed) {
34 case VIRTCHNL_LINK_SPEED_100MB:
37 case VIRTCHNL_LINK_SPEED_1GB:
40 case VIRTCHNL_LINK_SPEED_10GB:
43 case VIRTCHNL_LINK_SPEED_40GB:
46 case VIRTCHNL_LINK_SPEED_20GB:
49 case VIRTCHNL_LINK_SPEED_25GB:
52 case VIRTCHNL_LINK_SPEED_2_5GB:
55 case VIRTCHNL_LINK_SPEED_5GB:
66 /* Read data in admin queue to get msg from pf driver */
67 static enum iavf_aq_result
68 iavf_read_msg_from_pf(struct iavf_adapter *adapter, uint16_t buf_len,
71 struct iavf_hw *hw = IAVF_DEV_PRIVATE_TO_HW(adapter);
72 struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(adapter);
73 struct rte_eth_dev *dev = adapter->eth_dev;
74 struct iavf_arq_event_info event;
75 enum iavf_aq_result result = IAVF_MSG_NON;
76 enum virtchnl_ops opcode;
79 event.buf_len = buf_len;
81 ret = iavf_clean_arq_element(hw, &event, NULL);
82 /* Can't read any msg from adminQ */
84 PMD_DRV_LOG(DEBUG, "Can't read msg from AQ");
85 if (ret != IAVF_ERR_ADMIN_QUEUE_NO_WORK)
86 result = IAVF_MSG_ERR;
90 opcode = (enum virtchnl_ops)rte_le_to_cpu_32(event.desc.cookie_high);
91 vf->cmd_retval = (enum virtchnl_status_code)rte_le_to_cpu_32(
92 event.desc.cookie_low);
94 PMD_DRV_LOG(DEBUG, "AQ from pf carries opcode %u, retval %d",
95 opcode, vf->cmd_retval);
97 if (opcode == VIRTCHNL_OP_EVENT) {
98 struct virtchnl_pf_event *vpe =
99 (struct virtchnl_pf_event *)event.msg_buf;
101 result = IAVF_MSG_SYS;
102 switch (vpe->event) {
103 case VIRTCHNL_EVENT_LINK_CHANGE:
105 vpe->event_data.link_event.link_status;
106 if (vf->vf_res->vf_cap_flags &
107 VIRTCHNL_VF_CAP_ADV_LINK_SPEED) {
109 vpe->event_data.link_event_adv.link_speed;
111 enum virtchnl_link_speed speed;
112 speed = vpe->event_data.link_event.link_speed;
113 vf->link_speed = iavf_convert_link_speed(speed);
115 iavf_dev_link_update(dev, 0);
116 PMD_DRV_LOG(INFO, "Link status update:%s",
117 vf->link_up ? "up" : "down");
119 case VIRTCHNL_EVENT_RESET_IMPENDING:
121 PMD_DRV_LOG(INFO, "VF is resetting");
123 case VIRTCHNL_EVENT_PF_DRIVER_CLOSE:
124 vf->dev_closed = true;
125 PMD_DRV_LOG(INFO, "PF driver closed");
128 PMD_DRV_LOG(ERR, "%s: Unknown event %d from pf",
129 __func__, vpe->event);
132 /* async reply msg on command issued by vf previously */
133 result = IAVF_MSG_CMD;
134 if (opcode != vf->pend_cmd) {
135 PMD_DRV_LOG(WARNING, "command mismatch, expect %u, get %u",
136 vf->pend_cmd, opcode);
137 result = IAVF_MSG_ERR;
145 iavf_execute_vf_cmd(struct iavf_adapter *adapter, struct iavf_cmd_info *args)
147 struct iavf_hw *hw = IAVF_DEV_PRIVATE_TO_HW(adapter);
148 struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(adapter);
149 enum iavf_aq_result result;
150 enum iavf_status ret;
157 if (_atomic_set_cmd(vf, args->ops))
160 ret = iavf_aq_send_msg_to_pf(hw, args->ops, IAVF_SUCCESS,
161 args->in_args, args->in_args_size, NULL);
163 PMD_DRV_LOG(ERR, "fail to send cmd %d", args->ops);
169 case VIRTCHNL_OP_RESET_VF:
170 /*no need to wait for response */
173 case VIRTCHNL_OP_VERSION:
174 case VIRTCHNL_OP_GET_VF_RESOURCES:
175 case VIRTCHNL_OP_GET_SUPPORTED_RXDIDS:
176 /* for init virtchnl ops, need to poll the response */
178 result = iavf_read_msg_from_pf(adapter, args->out_size,
180 if (result == IAVF_MSG_CMD)
182 rte_delay_ms(ASQ_DELAY_MS);
183 } while (i++ < MAX_TRY_TIMES);
184 if (i >= MAX_TRY_TIMES ||
185 vf->cmd_retval != VIRTCHNL_STATUS_SUCCESS) {
187 PMD_DRV_LOG(ERR, "No response or return failure (%d)"
188 " for cmd %d", vf->cmd_retval, args->ops);
194 /* For other virtchnl ops in running time,
195 * wait for the cmd done flag.
198 if (vf->pend_cmd == VIRTCHNL_OP_UNKNOWN)
200 rte_delay_ms(ASQ_DELAY_MS);
201 /* If don't read msg or read sys event, continue */
202 } while (i++ < MAX_TRY_TIMES);
203 /* If there's no response is received, clear command */
204 if (i >= MAX_TRY_TIMES ||
205 vf->cmd_retval != VIRTCHNL_STATUS_SUCCESS) {
207 PMD_DRV_LOG(ERR, "No response or return failure (%d)"
208 " for cmd %d", vf->cmd_retval, args->ops);
218 iavf_handle_pf_event_msg(struct rte_eth_dev *dev, uint8_t *msg,
221 struct virtchnl_pf_event *pf_msg =
222 (struct virtchnl_pf_event *)msg;
223 struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(dev->data->dev_private);
225 if (msglen < sizeof(struct virtchnl_pf_event)) {
226 PMD_DRV_LOG(DEBUG, "Error event");
229 switch (pf_msg->event) {
230 case VIRTCHNL_EVENT_RESET_IMPENDING:
231 PMD_DRV_LOG(DEBUG, "VIRTCHNL_EVENT_RESET_IMPENDING event");
233 rte_eth_dev_callback_process(dev, RTE_ETH_EVENT_INTR_RESET,
236 case VIRTCHNL_EVENT_LINK_CHANGE:
237 PMD_DRV_LOG(DEBUG, "VIRTCHNL_EVENT_LINK_CHANGE event");
238 vf->link_up = pf_msg->event_data.link_event.link_status;
239 if (vf->vf_res->vf_cap_flags & VIRTCHNL_VF_CAP_ADV_LINK_SPEED) {
241 pf_msg->event_data.link_event_adv.link_speed;
243 enum virtchnl_link_speed speed;
244 speed = pf_msg->event_data.link_event.link_speed;
245 vf->link_speed = iavf_convert_link_speed(speed);
247 iavf_dev_link_update(dev, 0);
248 rte_eth_dev_callback_process(dev, RTE_ETH_EVENT_INTR_LSC, NULL);
250 case VIRTCHNL_EVENT_PF_DRIVER_CLOSE:
251 PMD_DRV_LOG(DEBUG, "VIRTCHNL_EVENT_PF_DRIVER_CLOSE event");
254 PMD_DRV_LOG(ERR, " unknown event received %u", pf_msg->event);
260 iavf_handle_virtchnl_msg(struct rte_eth_dev *dev)
262 struct iavf_hw *hw = IAVF_DEV_PRIVATE_TO_HW(dev->data->dev_private);
263 struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(dev->data->dev_private);
264 struct iavf_arq_event_info info;
265 uint16_t pending, aq_opc;
266 enum virtchnl_ops msg_opc;
267 enum iavf_status msg_ret;
270 info.buf_len = IAVF_AQ_BUF_SZ;
272 PMD_DRV_LOG(ERR, "Buffer for adminq resp should not be NULL");
275 info.msg_buf = vf->aq_resp;
279 ret = iavf_clean_arq_element(hw, &info, &pending);
281 if (ret != IAVF_SUCCESS) {
282 PMD_DRV_LOG(INFO, "Failed to read msg from AdminQ,"
286 aq_opc = rte_le_to_cpu_16(info.desc.opcode);
287 /* For the message sent from pf to vf, opcode is stored in
288 * cookie_high of struct iavf_aq_desc, while return error code
289 * are stored in cookie_low, Which is done by PF driver.
291 msg_opc = (enum virtchnl_ops)rte_le_to_cpu_32(
292 info.desc.cookie_high);
293 msg_ret = (enum iavf_status)rte_le_to_cpu_32(
294 info.desc.cookie_low);
296 case iavf_aqc_opc_send_msg_to_vf:
297 if (msg_opc == VIRTCHNL_OP_EVENT) {
298 iavf_handle_pf_event_msg(dev, info.msg_buf,
301 /* read message and it's expected one */
302 if (msg_opc == vf->pend_cmd)
303 _notify_cmd(vf, msg_ret);
305 PMD_DRV_LOG(ERR, "command mismatch,"
307 vf->pend_cmd, msg_opc);
309 "adminq response is received,"
310 " opcode = %d", msg_opc);
314 PMD_DRV_LOG(DEBUG, "Request %u is not supported yet",
322 iavf_enable_vlan_strip(struct iavf_adapter *adapter)
324 struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(adapter);
325 struct iavf_cmd_info args;
328 memset(&args, 0, sizeof(args));
329 args.ops = VIRTCHNL_OP_ENABLE_VLAN_STRIPPING;
331 args.in_args_size = 0;
332 args.out_buffer = vf->aq_resp;
333 args.out_size = IAVF_AQ_BUF_SZ;
334 ret = iavf_execute_vf_cmd(adapter, &args);
336 PMD_DRV_LOG(ERR, "Failed to execute command of"
337 " OP_ENABLE_VLAN_STRIPPING");
343 iavf_disable_vlan_strip(struct iavf_adapter *adapter)
345 struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(adapter);
346 struct iavf_cmd_info args;
349 memset(&args, 0, sizeof(args));
350 args.ops = VIRTCHNL_OP_DISABLE_VLAN_STRIPPING;
352 args.in_args_size = 0;
353 args.out_buffer = vf->aq_resp;
354 args.out_size = IAVF_AQ_BUF_SZ;
355 ret = iavf_execute_vf_cmd(adapter, &args);
357 PMD_DRV_LOG(ERR, "Failed to execute command of"
358 " OP_DISABLE_VLAN_STRIPPING");
363 #define VIRTCHNL_VERSION_MAJOR_START 1
364 #define VIRTCHNL_VERSION_MINOR_START 1
366 /* Check API version with sync wait until version read from admin queue */
368 iavf_check_api_version(struct iavf_adapter *adapter)
370 struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(adapter);
371 struct virtchnl_version_info version, *pver;
372 struct iavf_cmd_info args;
375 version.major = VIRTCHNL_VERSION_MAJOR;
376 version.minor = VIRTCHNL_VERSION_MINOR;
378 args.ops = VIRTCHNL_OP_VERSION;
379 args.in_args = (uint8_t *)&version;
380 args.in_args_size = sizeof(version);
381 args.out_buffer = vf->aq_resp;
382 args.out_size = IAVF_AQ_BUF_SZ;
384 err = iavf_execute_vf_cmd(adapter, &args);
386 PMD_INIT_LOG(ERR, "Fail to execute command of OP_VERSION");
390 pver = (struct virtchnl_version_info *)args.out_buffer;
391 vf->virtchnl_version = *pver;
393 if (vf->virtchnl_version.major < VIRTCHNL_VERSION_MAJOR_START ||
394 (vf->virtchnl_version.major == VIRTCHNL_VERSION_MAJOR_START &&
395 vf->virtchnl_version.minor < VIRTCHNL_VERSION_MINOR_START)) {
396 PMD_INIT_LOG(ERR, "VIRTCHNL API version should not be lower"
397 " than (%u.%u) to support Adapative VF",
398 VIRTCHNL_VERSION_MAJOR_START,
399 VIRTCHNL_VERSION_MAJOR_START);
401 } else if (vf->virtchnl_version.major > VIRTCHNL_VERSION_MAJOR ||
402 (vf->virtchnl_version.major == VIRTCHNL_VERSION_MAJOR &&
403 vf->virtchnl_version.minor > VIRTCHNL_VERSION_MINOR)) {
404 PMD_INIT_LOG(ERR, "PF/VF API version mismatch:(%u.%u)-(%u.%u)",
405 vf->virtchnl_version.major,
406 vf->virtchnl_version.minor,
407 VIRTCHNL_VERSION_MAJOR,
408 VIRTCHNL_VERSION_MINOR);
412 PMD_DRV_LOG(DEBUG, "Peer is supported PF host");
417 iavf_get_vf_resource(struct iavf_adapter *adapter)
419 struct iavf_hw *hw = IAVF_DEV_PRIVATE_TO_HW(adapter);
420 struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(adapter);
421 struct iavf_cmd_info args;
425 args.ops = VIRTCHNL_OP_GET_VF_RESOURCES;
426 args.out_buffer = vf->aq_resp;
427 args.out_size = IAVF_AQ_BUF_SZ;
429 caps = IAVF_BASIC_OFFLOAD_CAPS | VIRTCHNL_VF_CAP_ADV_LINK_SPEED |
430 VIRTCHNL_VF_OFFLOAD_RX_FLEX_DESC |
431 VIRTCHNL_VF_OFFLOAD_FDIR_PF |
432 VIRTCHNL_VF_OFFLOAD_ADV_RSS_PF;
434 args.in_args = (uint8_t *)∩︀
435 args.in_args_size = sizeof(caps);
437 err = iavf_execute_vf_cmd(adapter, &args);
441 "Failed to execute command of OP_GET_VF_RESOURCE");
445 len = sizeof(struct virtchnl_vf_resource) +
446 IAVF_MAX_VF_VSI * sizeof(struct virtchnl_vsi_resource);
448 rte_memcpy(vf->vf_res, args.out_buffer,
449 RTE_MIN(args.out_size, len));
450 /* parse VF config message back from PF*/
451 iavf_vf_parse_hw_config(hw, vf->vf_res);
452 for (i = 0; i < vf->vf_res->num_vsis; i++) {
453 if (vf->vf_res->vsi_res[i].vsi_type == VIRTCHNL_VSI_SRIOV)
454 vf->vsi_res = &vf->vf_res->vsi_res[i];
458 PMD_INIT_LOG(ERR, "no LAN VSI found");
462 vf->vsi.vsi_id = vf->vsi_res->vsi_id;
463 vf->vsi.nb_qps = vf->vsi_res->num_queue_pairs;
464 vf->vsi.adapter = adapter;
470 iavf_get_supported_rxdid(struct iavf_adapter *adapter)
472 struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(adapter);
473 struct iavf_cmd_info args;
476 args.ops = VIRTCHNL_OP_GET_SUPPORTED_RXDIDS;
478 args.in_args_size = 0;
479 args.out_buffer = vf->aq_resp;
480 args.out_size = IAVF_AQ_BUF_SZ;
482 ret = iavf_execute_vf_cmd(adapter, &args);
485 "Failed to execute command of OP_GET_SUPPORTED_RXDIDS");
489 vf->supported_rxdid =
490 ((struct virtchnl_supported_rxdids *)args.out_buffer)->supported_rxdids;
496 iavf_enable_queues(struct iavf_adapter *adapter)
498 struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(adapter);
499 struct virtchnl_queue_select queue_select;
500 struct iavf_cmd_info args;
503 memset(&queue_select, 0, sizeof(queue_select));
504 queue_select.vsi_id = vf->vsi_res->vsi_id;
506 queue_select.rx_queues = BIT(adapter->eth_dev->data->nb_rx_queues) - 1;
507 queue_select.tx_queues = BIT(adapter->eth_dev->data->nb_tx_queues) - 1;
509 args.ops = VIRTCHNL_OP_ENABLE_QUEUES;
510 args.in_args = (u8 *)&queue_select;
511 args.in_args_size = sizeof(queue_select);
512 args.out_buffer = vf->aq_resp;
513 args.out_size = IAVF_AQ_BUF_SZ;
514 err = iavf_execute_vf_cmd(adapter, &args);
517 "Failed to execute command of OP_ENABLE_QUEUES");
524 iavf_disable_queues(struct iavf_adapter *adapter)
526 struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(adapter);
527 struct virtchnl_queue_select queue_select;
528 struct iavf_cmd_info args;
531 memset(&queue_select, 0, sizeof(queue_select));
532 queue_select.vsi_id = vf->vsi_res->vsi_id;
534 queue_select.rx_queues = BIT(adapter->eth_dev->data->nb_rx_queues) - 1;
535 queue_select.tx_queues = BIT(adapter->eth_dev->data->nb_tx_queues) - 1;
537 args.ops = VIRTCHNL_OP_DISABLE_QUEUES;
538 args.in_args = (u8 *)&queue_select;
539 args.in_args_size = sizeof(queue_select);
540 args.out_buffer = vf->aq_resp;
541 args.out_size = IAVF_AQ_BUF_SZ;
542 err = iavf_execute_vf_cmd(adapter, &args);
545 "Failed to execute command of OP_DISABLE_QUEUES");
552 iavf_switch_queue(struct iavf_adapter *adapter, uint16_t qid,
555 struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(adapter);
556 struct virtchnl_queue_select queue_select;
557 struct iavf_cmd_info args;
560 memset(&queue_select, 0, sizeof(queue_select));
561 queue_select.vsi_id = vf->vsi_res->vsi_id;
563 queue_select.rx_queues |= 1 << qid;
565 queue_select.tx_queues |= 1 << qid;
568 args.ops = VIRTCHNL_OP_ENABLE_QUEUES;
570 args.ops = VIRTCHNL_OP_DISABLE_QUEUES;
571 args.in_args = (u8 *)&queue_select;
572 args.in_args_size = sizeof(queue_select);
573 args.out_buffer = vf->aq_resp;
574 args.out_size = IAVF_AQ_BUF_SZ;
575 err = iavf_execute_vf_cmd(adapter, &args);
577 PMD_DRV_LOG(ERR, "Failed to execute command of %s",
578 on ? "OP_ENABLE_QUEUES" : "OP_DISABLE_QUEUES");
583 iavf_configure_rss_lut(struct iavf_adapter *adapter)
585 struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(adapter);
586 struct virtchnl_rss_lut *rss_lut;
587 struct iavf_cmd_info args;
590 len = sizeof(*rss_lut) + vf->vf_res->rss_lut_size - 1;
591 rss_lut = rte_zmalloc("rss_lut", len, 0);
595 rss_lut->vsi_id = vf->vsi_res->vsi_id;
596 rss_lut->lut_entries = vf->vf_res->rss_lut_size;
597 rte_memcpy(rss_lut->lut, vf->rss_lut, vf->vf_res->rss_lut_size);
599 args.ops = VIRTCHNL_OP_CONFIG_RSS_LUT;
600 args.in_args = (u8 *)rss_lut;
601 args.in_args_size = len;
602 args.out_buffer = vf->aq_resp;
603 args.out_size = IAVF_AQ_BUF_SZ;
605 err = iavf_execute_vf_cmd(adapter, &args);
608 "Failed to execute command of OP_CONFIG_RSS_LUT");
615 iavf_configure_rss_key(struct iavf_adapter *adapter)
617 struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(adapter);
618 struct virtchnl_rss_key *rss_key;
619 struct iavf_cmd_info args;
622 len = sizeof(*rss_key) + vf->vf_res->rss_key_size - 1;
623 rss_key = rte_zmalloc("rss_key", len, 0);
627 rss_key->vsi_id = vf->vsi_res->vsi_id;
628 rss_key->key_len = vf->vf_res->rss_key_size;
629 rte_memcpy(rss_key->key, vf->rss_key, vf->vf_res->rss_key_size);
631 args.ops = VIRTCHNL_OP_CONFIG_RSS_KEY;
632 args.in_args = (u8 *)rss_key;
633 args.in_args_size = len;
634 args.out_buffer = vf->aq_resp;
635 args.out_size = IAVF_AQ_BUF_SZ;
637 err = iavf_execute_vf_cmd(adapter, &args);
640 "Failed to execute command of OP_CONFIG_RSS_KEY");
647 iavf_configure_queues(struct iavf_adapter *adapter)
649 struct iavf_rx_queue **rxq =
650 (struct iavf_rx_queue **)adapter->eth_dev->data->rx_queues;
651 struct iavf_tx_queue **txq =
652 (struct iavf_tx_queue **)adapter->eth_dev->data->tx_queues;
653 struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(adapter);
654 struct virtchnl_vsi_queue_config_info *vc_config;
655 struct virtchnl_queue_pair_info *vc_qp;
656 struct iavf_cmd_info args;
660 size = sizeof(*vc_config) +
661 sizeof(vc_config->qpair[0]) * vf->num_queue_pairs;
662 vc_config = rte_zmalloc("cfg_queue", size, 0);
666 vc_config->vsi_id = vf->vsi_res->vsi_id;
667 vc_config->num_queue_pairs = vf->num_queue_pairs;
669 for (i = 0, vc_qp = vc_config->qpair;
670 i < vf->num_queue_pairs;
672 vc_qp->txq.vsi_id = vf->vsi_res->vsi_id;
673 vc_qp->txq.queue_id = i;
674 /* Virtchnnl configure queues by pairs */
675 if (i < adapter->eth_dev->data->nb_tx_queues) {
676 vc_qp->txq.ring_len = txq[i]->nb_tx_desc;
677 vc_qp->txq.dma_ring_addr = txq[i]->tx_ring_phys_addr;
679 vc_qp->rxq.vsi_id = vf->vsi_res->vsi_id;
680 vc_qp->rxq.queue_id = i;
681 vc_qp->rxq.max_pkt_size = vf->max_pkt_len;
682 /* Virtchnnl configure queues by pairs */
683 if (i < adapter->eth_dev->data->nb_rx_queues) {
684 vc_qp->rxq.ring_len = rxq[i]->nb_rx_desc;
685 vc_qp->rxq.dma_ring_addr = rxq[i]->rx_ring_phys_addr;
686 vc_qp->rxq.databuffer_size = rxq[i]->rx_buf_len;
689 #ifndef RTE_LIBRTE_IAVF_16BYTE_RX_DESC
690 if (vf->vf_res->vf_cap_flags &
691 VIRTCHNL_VF_OFFLOAD_RX_FLEX_DESC &&
692 vf->supported_rxdid & BIT(IAVF_RXDID_COMMS_OVS_1)) {
693 vc_qp->rxq.rxdid = IAVF_RXDID_COMMS_OVS_1;
694 PMD_DRV_LOG(NOTICE, "request RXDID == %d in "
695 "Queue[%d]", vc_qp->rxq.rxdid, i);
697 vc_qp->rxq.rxdid = IAVF_RXDID_LEGACY_1;
698 PMD_DRV_LOG(NOTICE, "request RXDID == %d in "
699 "Queue[%d]", vc_qp->rxq.rxdid, i);
702 if (vf->vf_res->vf_cap_flags &
703 VIRTCHNL_VF_OFFLOAD_RX_FLEX_DESC &&
704 vf->supported_rxdid & BIT(IAVF_RXDID_LEGACY_0)) {
705 vc_qp->rxq.rxdid = IAVF_RXDID_LEGACY_0;
706 PMD_DRV_LOG(NOTICE, "request RXDID == %d in "
707 "Queue[%d]", vc_qp->rxq.rxdid, i);
709 PMD_DRV_LOG(ERR, "RXDID == 0 is not supported");
715 memset(&args, 0, sizeof(args));
716 args.ops = VIRTCHNL_OP_CONFIG_VSI_QUEUES;
717 args.in_args = (uint8_t *)vc_config;
718 args.in_args_size = size;
719 args.out_buffer = vf->aq_resp;
720 args.out_size = IAVF_AQ_BUF_SZ;
722 err = iavf_execute_vf_cmd(adapter, &args);
724 PMD_DRV_LOG(ERR, "Failed to execute command of"
725 " VIRTCHNL_OP_CONFIG_VSI_QUEUES");
732 iavf_config_irq_map(struct iavf_adapter *adapter)
734 struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(adapter);
735 struct virtchnl_irq_map_info *map_info;
736 struct virtchnl_vector_map *vecmap;
737 struct iavf_cmd_info args;
740 len = sizeof(struct virtchnl_irq_map_info) +
741 sizeof(struct virtchnl_vector_map) * vf->nb_msix;
743 map_info = rte_zmalloc("map_info", len, 0);
747 map_info->num_vectors = vf->nb_msix;
748 for (i = 0; i < vf->nb_msix; i++) {
749 vecmap = &map_info->vecmap[i];
750 vecmap->vsi_id = vf->vsi_res->vsi_id;
751 vecmap->rxitr_idx = IAVF_ITR_INDEX_DEFAULT;
752 vecmap->vector_id = vf->msix_base + i;
754 vecmap->rxq_map = vf->rxq_map[vf->msix_base + i];
757 args.ops = VIRTCHNL_OP_CONFIG_IRQ_MAP;
758 args.in_args = (u8 *)map_info;
759 args.in_args_size = len;
760 args.out_buffer = vf->aq_resp;
761 args.out_size = IAVF_AQ_BUF_SZ;
762 err = iavf_execute_vf_cmd(adapter, &args);
764 PMD_DRV_LOG(ERR, "fail to execute command OP_CONFIG_IRQ_MAP");
771 iavf_add_del_all_mac_addr(struct iavf_adapter *adapter, bool add)
773 struct virtchnl_ether_addr_list *list;
774 struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(adapter);
775 struct rte_ether_addr *addr;
776 struct iavf_cmd_info args;
783 len = sizeof(struct virtchnl_ether_addr_list);
784 for (i = begin; i < IAVF_NUM_MACADDR_MAX; i++, next_begin++) {
785 addr = &adapter->eth_dev->data->mac_addrs[i];
786 if (rte_is_zero_ether_addr(addr))
788 len += sizeof(struct virtchnl_ether_addr);
789 if (len >= IAVF_AQ_BUF_SZ) {
795 list = rte_zmalloc("iavf_del_mac_buffer", len, 0);
797 PMD_DRV_LOG(ERR, "fail to allocate memory");
801 for (i = begin; i < next_begin; i++) {
802 addr = &adapter->eth_dev->data->mac_addrs[i];
803 if (rte_is_zero_ether_addr(addr))
805 rte_memcpy(list->list[j].addr, addr->addr_bytes,
806 sizeof(addr->addr_bytes));
807 PMD_DRV_LOG(DEBUG, "add/rm mac:%x:%x:%x:%x:%x:%x",
808 addr->addr_bytes[0], addr->addr_bytes[1],
809 addr->addr_bytes[2], addr->addr_bytes[3],
810 addr->addr_bytes[4], addr->addr_bytes[5]);
813 list->vsi_id = vf->vsi_res->vsi_id;
814 list->num_elements = j;
815 args.ops = add ? VIRTCHNL_OP_ADD_ETH_ADDR :
816 VIRTCHNL_OP_DEL_ETH_ADDR;
817 args.in_args = (uint8_t *)list;
818 args.in_args_size = len;
819 args.out_buffer = vf->aq_resp;
820 args.out_size = IAVF_AQ_BUF_SZ;
821 err = iavf_execute_vf_cmd(adapter, &args);
823 PMD_DRV_LOG(ERR, "fail to execute command %s",
824 add ? "OP_ADD_ETHER_ADDRESS" :
825 "OP_DEL_ETHER_ADDRESS");
828 } while (begin < IAVF_NUM_MACADDR_MAX);
832 iavf_query_stats(struct iavf_adapter *adapter,
833 struct virtchnl_eth_stats **pstats)
835 struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(adapter);
836 struct virtchnl_queue_select q_stats;
837 struct iavf_cmd_info args;
840 memset(&q_stats, 0, sizeof(q_stats));
841 q_stats.vsi_id = vf->vsi_res->vsi_id;
842 args.ops = VIRTCHNL_OP_GET_STATS;
843 args.in_args = (uint8_t *)&q_stats;
844 args.in_args_size = sizeof(q_stats);
845 args.out_buffer = vf->aq_resp;
846 args.out_size = IAVF_AQ_BUF_SZ;
848 err = iavf_execute_vf_cmd(adapter, &args);
850 PMD_DRV_LOG(ERR, "fail to execute command OP_GET_STATS");
854 *pstats = (struct virtchnl_eth_stats *)args.out_buffer;
859 iavf_config_promisc(struct iavf_adapter *adapter,
861 bool enable_multicast)
863 struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(adapter);
864 struct virtchnl_promisc_info promisc;
865 struct iavf_cmd_info args;
869 promisc.vsi_id = vf->vsi_res->vsi_id;
872 promisc.flags |= FLAG_VF_UNICAST_PROMISC;
874 if (enable_multicast)
875 promisc.flags |= FLAG_VF_MULTICAST_PROMISC;
877 args.ops = VIRTCHNL_OP_CONFIG_PROMISCUOUS_MODE;
878 args.in_args = (uint8_t *)&promisc;
879 args.in_args_size = sizeof(promisc);
880 args.out_buffer = vf->aq_resp;
881 args.out_size = IAVF_AQ_BUF_SZ;
883 err = iavf_execute_vf_cmd(adapter, &args);
887 "fail to execute command CONFIG_PROMISCUOUS_MODE");
889 if (err == IAVF_NOT_SUPPORTED)
895 vf->promisc_unicast_enabled = enable_unicast;
896 vf->promisc_multicast_enabled = enable_multicast;
901 iavf_add_del_eth_addr(struct iavf_adapter *adapter, struct rte_ether_addr *addr,
904 struct virtchnl_ether_addr_list *list;
905 struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(adapter);
906 uint8_t cmd_buffer[sizeof(struct virtchnl_ether_addr_list) +
907 sizeof(struct virtchnl_ether_addr)];
908 struct iavf_cmd_info args;
911 list = (struct virtchnl_ether_addr_list *)cmd_buffer;
912 list->vsi_id = vf->vsi_res->vsi_id;
913 list->num_elements = 1;
914 rte_memcpy(list->list[0].addr, addr->addr_bytes,
915 sizeof(addr->addr_bytes));
917 args.ops = add ? VIRTCHNL_OP_ADD_ETH_ADDR : VIRTCHNL_OP_DEL_ETH_ADDR;
918 args.in_args = cmd_buffer;
919 args.in_args_size = sizeof(cmd_buffer);
920 args.out_buffer = vf->aq_resp;
921 args.out_size = IAVF_AQ_BUF_SZ;
922 err = iavf_execute_vf_cmd(adapter, &args);
924 PMD_DRV_LOG(ERR, "fail to execute command %s",
925 add ? "OP_ADD_ETH_ADDR" : "OP_DEL_ETH_ADDR");
930 iavf_add_del_vlan(struct iavf_adapter *adapter, uint16_t vlanid, bool add)
932 struct virtchnl_vlan_filter_list *vlan_list;
933 struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(adapter);
934 uint8_t cmd_buffer[sizeof(struct virtchnl_vlan_filter_list) +
936 struct iavf_cmd_info args;
939 vlan_list = (struct virtchnl_vlan_filter_list *)cmd_buffer;
940 vlan_list->vsi_id = vf->vsi_res->vsi_id;
941 vlan_list->num_elements = 1;
942 vlan_list->vlan_id[0] = vlanid;
944 args.ops = add ? VIRTCHNL_OP_ADD_VLAN : VIRTCHNL_OP_DEL_VLAN;
945 args.in_args = cmd_buffer;
946 args.in_args_size = sizeof(cmd_buffer);
947 args.out_buffer = vf->aq_resp;
948 args.out_size = IAVF_AQ_BUF_SZ;
949 err = iavf_execute_vf_cmd(adapter, &args);
951 PMD_DRV_LOG(ERR, "fail to execute command %s",
952 add ? "OP_ADD_VLAN" : "OP_DEL_VLAN");
958 iavf_fdir_add(struct iavf_adapter *adapter,
959 struct iavf_fdir_conf *filter)
961 struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(adapter);
962 struct virtchnl_fdir_add *fdir_ret;
964 struct iavf_cmd_info args;
967 filter->add_fltr.vsi_id = vf->vsi_res->vsi_id;
968 filter->add_fltr.validate_only = 0;
970 args.ops = VIRTCHNL_OP_ADD_FDIR_FILTER;
971 args.in_args = (uint8_t *)(&filter->add_fltr);
972 args.in_args_size = sizeof(*(&filter->add_fltr));
973 args.out_buffer = vf->aq_resp;
974 args.out_size = IAVF_AQ_BUF_SZ;
976 err = iavf_execute_vf_cmd(adapter, &args);
978 PMD_DRV_LOG(ERR, "fail to execute command OP_ADD_FDIR_FILTER");
982 fdir_ret = (struct virtchnl_fdir_add *)args.out_buffer;
983 filter->flow_id = fdir_ret->flow_id;
985 if (fdir_ret->status == VIRTCHNL_FDIR_SUCCESS) {
987 "Succeed in adding rule request by PF");
988 } else if (fdir_ret->status == VIRTCHNL_FDIR_FAILURE_RULE_NORESOURCE) {
990 "Failed to add rule request due to no hw resource");
992 } else if (fdir_ret->status == VIRTCHNL_FDIR_FAILURE_RULE_EXIST) {
994 "Failed to add rule request due to the rule is already existed");
996 } else if (fdir_ret->status == VIRTCHNL_FDIR_FAILURE_RULE_CONFLICT) {
998 "Failed to add rule request due to the rule is conflict with existing rule");
1000 } else if (fdir_ret->status == VIRTCHNL_FDIR_FAILURE_RULE_INVALID) {
1002 "Failed to add rule request due to the hw doesn't support");
1004 } else if (fdir_ret->status == VIRTCHNL_FDIR_FAILURE_RULE_TIMEOUT) {
1006 "Failed to add rule request due to time out for programming");
1010 "Failed to add rule request due to other reasons");
1018 iavf_fdir_del(struct iavf_adapter *adapter,
1019 struct iavf_fdir_conf *filter)
1021 struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(adapter);
1022 struct virtchnl_fdir_del *fdir_ret;
1024 struct iavf_cmd_info args;
1027 filter->del_fltr.vsi_id = vf->vsi_res->vsi_id;
1028 filter->del_fltr.flow_id = filter->flow_id;
1030 args.ops = VIRTCHNL_OP_DEL_FDIR_FILTER;
1031 args.in_args = (uint8_t *)(&filter->del_fltr);
1032 args.in_args_size = sizeof(filter->del_fltr);
1033 args.out_buffer = vf->aq_resp;
1034 args.out_size = IAVF_AQ_BUF_SZ;
1036 err = iavf_execute_vf_cmd(adapter, &args);
1038 PMD_DRV_LOG(ERR, "fail to execute command OP_DEL_FDIR_FILTER");
1042 fdir_ret = (struct virtchnl_fdir_del *)args.out_buffer;
1044 if (fdir_ret->status == VIRTCHNL_FDIR_SUCCESS) {
1046 "Succeed in deleting rule request by PF");
1047 } else if (fdir_ret->status == VIRTCHNL_FDIR_FAILURE_RULE_NONEXIST) {
1049 "Failed to delete rule request due to this rule doesn't exist");
1051 } else if (fdir_ret->status == VIRTCHNL_FDIR_FAILURE_RULE_TIMEOUT) {
1053 "Failed to delete rule request due to time out for programming");
1057 "Failed to delete rule request due to other reasons");
1065 iavf_fdir_check(struct iavf_adapter *adapter,
1066 struct iavf_fdir_conf *filter)
1068 struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(adapter);
1069 struct virtchnl_fdir_add *fdir_ret;
1071 struct iavf_cmd_info args;
1074 filter->add_fltr.vsi_id = vf->vsi_res->vsi_id;
1075 filter->add_fltr.validate_only = 1;
1077 args.ops = VIRTCHNL_OP_ADD_FDIR_FILTER;
1078 args.in_args = (uint8_t *)(&filter->add_fltr);
1079 args.in_args_size = sizeof(*(&filter->add_fltr));
1080 args.out_buffer = vf->aq_resp;
1081 args.out_size = IAVF_AQ_BUF_SZ;
1083 err = iavf_execute_vf_cmd(adapter, &args);
1085 PMD_DRV_LOG(ERR, "fail to check flow direcotor rule");
1089 fdir_ret = (struct virtchnl_fdir_add *)args.out_buffer;
1091 if (fdir_ret->status == VIRTCHNL_FDIR_SUCCESS) {
1093 "Succeed in checking rule request by PF");
1094 } else if (fdir_ret->status == VIRTCHNL_FDIR_FAILURE_RULE_INVALID) {
1096 "Failed to check rule request due to parameters validation"
1097 " or HW doesn't support");
1101 "Failed to check rule request due to other reasons");
1109 iavf_add_del_rss_cfg(struct iavf_adapter *adapter,
1110 struct virtchnl_rss_cfg *rss_cfg, bool add)
1112 struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(adapter);
1113 struct iavf_cmd_info args;
1116 memset(&args, 0, sizeof(args));
1117 args.ops = add ? VIRTCHNL_OP_ADD_RSS_CFG :
1118 VIRTCHNL_OP_DEL_RSS_CFG;
1119 args.in_args = (u8 *)rss_cfg;
1120 args.in_args_size = sizeof(*rss_cfg);
1121 args.out_buffer = vf->aq_resp;
1122 args.out_size = IAVF_AQ_BUF_SZ;
1124 err = iavf_execute_vf_cmd(adapter, &args);
1127 "Failed to execute command of %s",
1128 add ? "OP_ADD_RSS_CFG" :
1129 "OP_DEL_RSS_INPUT_CFG");
1135 iavf_add_del_mc_addr_list(struct iavf_adapter *adapter,
1136 struct rte_ether_addr *mc_addrs,
1137 uint32_t mc_addrs_num, bool add)
1139 struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(adapter);
1140 uint8_t cmd_buffer[sizeof(struct virtchnl_ether_addr_list) +
1141 (IAVF_NUM_MACADDR_MAX * sizeof(struct virtchnl_ether_addr))];
1142 struct virtchnl_ether_addr_list *list;
1143 struct iavf_cmd_info args;
1147 if (mc_addrs == NULL || mc_addrs_num == 0)
1150 list = (struct virtchnl_ether_addr_list *)cmd_buffer;
1151 list->vsi_id = vf->vsi_res->vsi_id;
1152 list->num_elements = mc_addrs_num;
1154 for (i = 0; i < mc_addrs_num; i++) {
1155 if (!IAVF_IS_MULTICAST(mc_addrs[i].addr_bytes)) {
1156 PMD_DRV_LOG(ERR, "Invalid mac:%x:%x:%x:%x:%x:%x",
1157 mc_addrs[i].addr_bytes[0],
1158 mc_addrs[i].addr_bytes[1],
1159 mc_addrs[i].addr_bytes[2],
1160 mc_addrs[i].addr_bytes[3],
1161 mc_addrs[i].addr_bytes[4],
1162 mc_addrs[i].addr_bytes[5]);
1166 memcpy(list->list[i].addr, mc_addrs[i].addr_bytes,
1167 sizeof(list->list[i].addr));
1170 args.ops = add ? VIRTCHNL_OP_ADD_ETH_ADDR : VIRTCHNL_OP_DEL_ETH_ADDR;
1171 args.in_args = cmd_buffer;
1172 args.in_args_size = sizeof(struct virtchnl_ether_addr_list) +
1173 i * sizeof(struct virtchnl_ether_addr);
1174 args.out_buffer = vf->aq_resp;
1175 args.out_size = IAVF_AQ_BUF_SZ;
1176 err = iavf_execute_vf_cmd(adapter, &args);
1179 PMD_DRV_LOG(ERR, "fail to execute command %s",
1180 add ? "OP_ADD_ETH_ADDR" : "OP_DEL_ETH_ADDR");