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_handle_pf_event_msg(struct rte_eth_dev *dev, uint8_t *msg,
137 struct virtchnl_pf_event *pf_msg =
138 (struct virtchnl_pf_event *)msg;
139 struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(dev->data->dev_private);
141 if (msglen < sizeof(struct virtchnl_pf_event)) {
142 PMD_DRV_LOG(DEBUG, "Error event");
145 switch (pf_msg->event) {
146 case VIRTCHNL_EVENT_RESET_IMPENDING:
147 PMD_DRV_LOG(DEBUG, "VIRTCHNL_EVENT_RESET_IMPENDING event");
148 _rte_eth_dev_callback_process(dev, RTE_ETH_EVENT_INTR_RESET,
151 case VIRTCHNL_EVENT_LINK_CHANGE:
152 PMD_DRV_LOG(DEBUG, "VIRTCHNL_EVENT_LINK_CHANGE event");
153 vf->link_up = pf_msg->event_data.link_event.link_status;
154 vf->link_speed = pf_msg->event_data.link_event_adv.link_speed;
155 iavf_dev_link_update(dev, 0);
156 _rte_eth_dev_callback_process(dev, RTE_ETH_EVENT_INTR_LSC,
159 case VIRTCHNL_EVENT_PF_DRIVER_CLOSE:
160 PMD_DRV_LOG(DEBUG, "VIRTCHNL_EVENT_PF_DRIVER_CLOSE event");
163 PMD_DRV_LOG(ERR, " unknown event received %u", pf_msg->event);
169 iavf_handle_virtchnl_msg(struct rte_eth_dev *dev)
171 struct iavf_hw *hw = IAVF_DEV_PRIVATE_TO_HW(dev->data->dev_private);
172 struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(dev->data->dev_private);
173 struct iavf_arq_event_info info;
174 uint16_t pending, aq_opc;
175 enum virtchnl_ops msg_opc;
176 enum iavf_status msg_ret;
179 info.buf_len = IAVF_AQ_BUF_SZ;
181 PMD_DRV_LOG(ERR, "Buffer for adminq resp should not be NULL");
184 info.msg_buf = vf->aq_resp;
188 ret = iavf_clean_arq_element(hw, &info, &pending);
190 if (ret != IAVF_SUCCESS) {
191 PMD_DRV_LOG(INFO, "Failed to read msg from AdminQ,"
195 aq_opc = rte_le_to_cpu_16(info.desc.opcode);
196 /* For the message sent from pf to vf, opcode is stored in
197 * cookie_high of struct iavf_aq_desc, while return error code
198 * are stored in cookie_low, Which is done by PF driver.
200 msg_opc = (enum virtchnl_ops)rte_le_to_cpu_32(
201 info.desc.cookie_high);
202 msg_ret = (enum iavf_status)rte_le_to_cpu_32(
203 info.desc.cookie_low);
205 case iavf_aqc_opc_send_msg_to_vf:
206 if (msg_opc == VIRTCHNL_OP_EVENT) {
207 iavf_handle_pf_event_msg(dev, info.msg_buf,
210 /* read message and it's expected one */
211 if (msg_opc == vf->pend_cmd)
212 _notify_cmd(vf, msg_ret);
214 PMD_DRV_LOG(ERR, "command mismatch,"
216 vf->pend_cmd, msg_opc);
218 "adminq response is received,"
219 " opcode = %d", msg_opc);
223 PMD_DRV_LOG(ERR, "Request %u is not supported yet",
231 iavf_enable_vlan_strip(struct iavf_adapter *adapter)
233 struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(adapter);
234 struct iavf_cmd_info args;
237 memset(&args, 0, sizeof(args));
238 args.ops = VIRTCHNL_OP_ENABLE_VLAN_STRIPPING;
240 args.in_args_size = 0;
241 args.out_buffer = vf->aq_resp;
242 args.out_size = IAVF_AQ_BUF_SZ;
243 ret = iavf_execute_vf_cmd(adapter, &args);
245 PMD_DRV_LOG(ERR, "Failed to execute command of"
246 " OP_ENABLE_VLAN_STRIPPING");
252 iavf_disable_vlan_strip(struct iavf_adapter *adapter)
254 struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(adapter);
255 struct iavf_cmd_info args;
258 memset(&args, 0, sizeof(args));
259 args.ops = VIRTCHNL_OP_DISABLE_VLAN_STRIPPING;
261 args.in_args_size = 0;
262 args.out_buffer = vf->aq_resp;
263 args.out_size = IAVF_AQ_BUF_SZ;
264 ret = iavf_execute_vf_cmd(adapter, &args);
266 PMD_DRV_LOG(ERR, "Failed to execute command of"
267 " OP_DISABLE_VLAN_STRIPPING");
272 #define VIRTCHNL_VERSION_MAJOR_START 1
273 #define VIRTCHNL_VERSION_MINOR_START 1
275 /* Check API version with sync wait until version read from admin queue */
277 iavf_check_api_version(struct iavf_adapter *adapter)
279 struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(adapter);
280 struct virtchnl_version_info version, *pver;
281 struct iavf_cmd_info args;
284 version.major = VIRTCHNL_VERSION_MAJOR;
285 version.minor = VIRTCHNL_VERSION_MINOR;
287 args.ops = VIRTCHNL_OP_VERSION;
288 args.in_args = (uint8_t *)&version;
289 args.in_args_size = sizeof(version);
290 args.out_buffer = vf->aq_resp;
291 args.out_size = IAVF_AQ_BUF_SZ;
293 err = iavf_execute_vf_cmd(adapter, &args);
295 PMD_INIT_LOG(ERR, "Fail to execute command of OP_VERSION");
299 pver = (struct virtchnl_version_info *)args.out_buffer;
300 vf->virtchnl_version = *pver;
302 if (vf->virtchnl_version.major < VIRTCHNL_VERSION_MAJOR_START ||
303 (vf->virtchnl_version.major == VIRTCHNL_VERSION_MAJOR_START &&
304 vf->virtchnl_version.minor < VIRTCHNL_VERSION_MINOR_START)) {
305 PMD_INIT_LOG(ERR, "VIRTCHNL API version should not be lower"
306 " than (%u.%u) to support Adapative VF",
307 VIRTCHNL_VERSION_MAJOR_START,
308 VIRTCHNL_VERSION_MAJOR_START);
310 } else if (vf->virtchnl_version.major > VIRTCHNL_VERSION_MAJOR ||
311 (vf->virtchnl_version.major == VIRTCHNL_VERSION_MAJOR &&
312 vf->virtchnl_version.minor > VIRTCHNL_VERSION_MINOR)) {
313 PMD_INIT_LOG(ERR, "PF/VF API version mismatch:(%u.%u)-(%u.%u)",
314 vf->virtchnl_version.major,
315 vf->virtchnl_version.minor,
316 VIRTCHNL_VERSION_MAJOR,
317 VIRTCHNL_VERSION_MINOR);
321 PMD_DRV_LOG(DEBUG, "Peer is supported PF host");
326 iavf_get_vf_resource(struct iavf_adapter *adapter)
328 struct iavf_hw *hw = IAVF_DEV_PRIVATE_TO_HW(adapter);
329 struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(adapter);
330 struct iavf_cmd_info args;
334 args.ops = VIRTCHNL_OP_GET_VF_RESOURCES;
335 args.out_buffer = vf->aq_resp;
336 args.out_size = IAVF_AQ_BUF_SZ;
338 /* TODO: basic offload capabilities, need to
339 * add advanced/optional offload capabilities
342 caps = IAVF_BASIC_OFFLOAD_CAPS | VIRTCHNL_VF_CAP_ADV_LINK_SPEED |
343 VIRTCHNL_VF_OFFLOAD_RX_FLEX_DESC |
344 VIRTCHNL_VF_OFFLOAD_FDIR_PF;
346 args.in_args = (uint8_t *)∩︀
347 args.in_args_size = sizeof(caps);
349 err = iavf_execute_vf_cmd(adapter, &args);
353 "Failed to execute command of OP_GET_VF_RESOURCE");
357 len = sizeof(struct virtchnl_vf_resource) +
358 IAVF_MAX_VF_VSI * sizeof(struct virtchnl_vsi_resource);
360 rte_memcpy(vf->vf_res, args.out_buffer,
361 RTE_MIN(args.out_size, len));
362 /* parse VF config message back from PF*/
363 iavf_vf_parse_hw_config(hw, vf->vf_res);
364 for (i = 0; i < vf->vf_res->num_vsis; i++) {
365 if (vf->vf_res->vsi_res[i].vsi_type == VIRTCHNL_VSI_SRIOV)
366 vf->vsi_res = &vf->vf_res->vsi_res[i];
370 PMD_INIT_LOG(ERR, "no LAN VSI found");
374 vf->vsi.vsi_id = vf->vsi_res->vsi_id;
375 vf->vsi.nb_qps = vf->vsi_res->num_queue_pairs;
376 vf->vsi.adapter = adapter;
382 iavf_get_supported_rxdid(struct iavf_adapter *adapter)
384 struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(adapter);
385 struct iavf_cmd_info args;
388 args.ops = VIRTCHNL_OP_GET_SUPPORTED_RXDIDS;
390 args.in_args_size = 0;
391 args.out_buffer = vf->aq_resp;
392 args.out_size = IAVF_AQ_BUF_SZ;
394 ret = iavf_execute_vf_cmd(adapter, &args);
397 "Failed to execute command of OP_GET_SUPPORTED_RXDIDS");
401 vf->supported_rxdid =
402 ((struct virtchnl_supported_rxdids *)args.out_buffer)->supported_rxdids;
408 iavf_enable_queues(struct iavf_adapter *adapter)
410 struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(adapter);
411 struct virtchnl_queue_select queue_select;
412 struct iavf_cmd_info args;
415 memset(&queue_select, 0, sizeof(queue_select));
416 queue_select.vsi_id = vf->vsi_res->vsi_id;
418 queue_select.rx_queues = BIT(adapter->eth_dev->data->nb_rx_queues) - 1;
419 queue_select.tx_queues = BIT(adapter->eth_dev->data->nb_tx_queues) - 1;
421 args.ops = VIRTCHNL_OP_ENABLE_QUEUES;
422 args.in_args = (u8 *)&queue_select;
423 args.in_args_size = sizeof(queue_select);
424 args.out_buffer = vf->aq_resp;
425 args.out_size = IAVF_AQ_BUF_SZ;
426 err = iavf_execute_vf_cmd(adapter, &args);
429 "Failed to execute command of OP_ENABLE_QUEUES");
436 iavf_disable_queues(struct iavf_adapter *adapter)
438 struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(adapter);
439 struct virtchnl_queue_select queue_select;
440 struct iavf_cmd_info args;
443 memset(&queue_select, 0, sizeof(queue_select));
444 queue_select.vsi_id = vf->vsi_res->vsi_id;
446 queue_select.rx_queues = BIT(adapter->eth_dev->data->nb_rx_queues) - 1;
447 queue_select.tx_queues = BIT(adapter->eth_dev->data->nb_tx_queues) - 1;
449 args.ops = VIRTCHNL_OP_DISABLE_QUEUES;
450 args.in_args = (u8 *)&queue_select;
451 args.in_args_size = sizeof(queue_select);
452 args.out_buffer = vf->aq_resp;
453 args.out_size = IAVF_AQ_BUF_SZ;
454 err = iavf_execute_vf_cmd(adapter, &args);
457 "Failed to execute command of OP_DISABLE_QUEUES");
464 iavf_switch_queue(struct iavf_adapter *adapter, uint16_t qid,
467 struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(adapter);
468 struct virtchnl_queue_select queue_select;
469 struct iavf_cmd_info args;
472 memset(&queue_select, 0, sizeof(queue_select));
473 queue_select.vsi_id = vf->vsi_res->vsi_id;
475 queue_select.rx_queues |= 1 << qid;
477 queue_select.tx_queues |= 1 << qid;
480 args.ops = VIRTCHNL_OP_ENABLE_QUEUES;
482 args.ops = VIRTCHNL_OP_DISABLE_QUEUES;
483 args.in_args = (u8 *)&queue_select;
484 args.in_args_size = sizeof(queue_select);
485 args.out_buffer = vf->aq_resp;
486 args.out_size = IAVF_AQ_BUF_SZ;
487 err = iavf_execute_vf_cmd(adapter, &args);
489 PMD_DRV_LOG(ERR, "Failed to execute command of %s",
490 on ? "OP_ENABLE_QUEUES" : "OP_DISABLE_QUEUES");
495 iavf_configure_rss_lut(struct iavf_adapter *adapter)
497 struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(adapter);
498 struct virtchnl_rss_lut *rss_lut;
499 struct iavf_cmd_info args;
502 len = sizeof(*rss_lut) + vf->vf_res->rss_lut_size - 1;
503 rss_lut = rte_zmalloc("rss_lut", len, 0);
507 rss_lut->vsi_id = vf->vsi_res->vsi_id;
508 rss_lut->lut_entries = vf->vf_res->rss_lut_size;
509 rte_memcpy(rss_lut->lut, vf->rss_lut, vf->vf_res->rss_lut_size);
511 args.ops = VIRTCHNL_OP_CONFIG_RSS_LUT;
512 args.in_args = (u8 *)rss_lut;
513 args.in_args_size = len;
514 args.out_buffer = vf->aq_resp;
515 args.out_size = IAVF_AQ_BUF_SZ;
517 err = iavf_execute_vf_cmd(adapter, &args);
520 "Failed to execute command of OP_CONFIG_RSS_LUT");
527 iavf_configure_rss_key(struct iavf_adapter *adapter)
529 struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(adapter);
530 struct virtchnl_rss_key *rss_key;
531 struct iavf_cmd_info args;
534 len = sizeof(*rss_key) + vf->vf_res->rss_key_size - 1;
535 rss_key = rte_zmalloc("rss_key", len, 0);
539 rss_key->vsi_id = vf->vsi_res->vsi_id;
540 rss_key->key_len = vf->vf_res->rss_key_size;
541 rte_memcpy(rss_key->key, vf->rss_key, vf->vf_res->rss_key_size);
543 args.ops = VIRTCHNL_OP_CONFIG_RSS_KEY;
544 args.in_args = (u8 *)rss_key;
545 args.in_args_size = len;
546 args.out_buffer = vf->aq_resp;
547 args.out_size = IAVF_AQ_BUF_SZ;
549 err = iavf_execute_vf_cmd(adapter, &args);
552 "Failed to execute command of OP_CONFIG_RSS_KEY");
559 iavf_configure_queues(struct iavf_adapter *adapter)
561 struct iavf_rx_queue **rxq =
562 (struct iavf_rx_queue **)adapter->eth_dev->data->rx_queues;
563 struct iavf_tx_queue **txq =
564 (struct iavf_tx_queue **)adapter->eth_dev->data->tx_queues;
565 struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(adapter);
566 struct virtchnl_vsi_queue_config_info *vc_config;
567 struct virtchnl_queue_pair_info *vc_qp;
568 struct iavf_cmd_info args;
572 size = sizeof(*vc_config) +
573 sizeof(vc_config->qpair[0]) * vf->num_queue_pairs;
574 vc_config = rte_zmalloc("cfg_queue", size, 0);
578 vc_config->vsi_id = vf->vsi_res->vsi_id;
579 vc_config->num_queue_pairs = vf->num_queue_pairs;
581 for (i = 0, vc_qp = vc_config->qpair;
582 i < vf->num_queue_pairs;
584 vc_qp->txq.vsi_id = vf->vsi_res->vsi_id;
585 vc_qp->txq.queue_id = i;
586 /* Virtchnnl configure queues by pairs */
587 if (i < adapter->eth_dev->data->nb_tx_queues) {
588 vc_qp->txq.ring_len = txq[i]->nb_tx_desc;
589 vc_qp->txq.dma_ring_addr = txq[i]->tx_ring_phys_addr;
591 vc_qp->rxq.vsi_id = vf->vsi_res->vsi_id;
592 vc_qp->rxq.queue_id = i;
593 vc_qp->rxq.max_pkt_size = vf->max_pkt_len;
594 /* Virtchnnl configure queues by pairs */
595 if (i < adapter->eth_dev->data->nb_rx_queues) {
596 vc_qp->rxq.ring_len = rxq[i]->nb_rx_desc;
597 vc_qp->rxq.dma_ring_addr = rxq[i]->rx_ring_phys_addr;
598 vc_qp->rxq.databuffer_size = rxq[i]->rx_buf_len;
600 #ifndef RTE_LIBRTE_IAVF_16BYTE_RX_DESC
601 if (vf->vf_res->vf_cap_flags &
602 VIRTCHNL_VF_OFFLOAD_RX_FLEX_DESC &&
603 vf->supported_rxdid & BIT(IAVF_RXDID_COMMS_OVS_1)) {
604 vc_qp->rxq.rxdid = IAVF_RXDID_COMMS_OVS_1;
605 PMD_DRV_LOG(NOTICE, "request RXDID == %d in "
606 "Queue[%d]", vc_qp->rxq.rxdid, i);
608 vc_qp->rxq.rxdid = IAVF_RXDID_LEGACY_1;
609 PMD_DRV_LOG(NOTICE, "request RXDID == %d in "
610 "Queue[%d]", vc_qp->rxq.rxdid, i);
613 if (vf->vf_res->vf_cap_flags &
614 VIRTCHNL_VF_OFFLOAD_RX_FLEX_DESC &&
615 vf->supported_rxdid & BIT(IAVF_RXDID_LEGACY_0)) {
616 vc_qp->rxq.rxdid = IAVF_RXDID_LEGACY_0;
617 PMD_DRV_LOG(NOTICE, "request RXDID == %d in "
618 "Queue[%d]", vc_qp->rxq.rxdid, i);
620 PMD_DRV_LOG(ERR, "RXDID == 0 is not supported");
627 memset(&args, 0, sizeof(args));
628 args.ops = VIRTCHNL_OP_CONFIG_VSI_QUEUES;
629 args.in_args = (uint8_t *)vc_config;
630 args.in_args_size = size;
631 args.out_buffer = vf->aq_resp;
632 args.out_size = IAVF_AQ_BUF_SZ;
634 err = iavf_execute_vf_cmd(adapter, &args);
636 PMD_DRV_LOG(ERR, "Failed to execute command of"
637 " VIRTCHNL_OP_CONFIG_VSI_QUEUES");
644 iavf_config_irq_map(struct iavf_adapter *adapter)
646 struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(adapter);
647 struct virtchnl_irq_map_info *map_info;
648 struct virtchnl_vector_map *vecmap;
649 struct iavf_cmd_info args;
652 len = sizeof(struct virtchnl_irq_map_info) +
653 sizeof(struct virtchnl_vector_map) * vf->nb_msix;
655 map_info = rte_zmalloc("map_info", len, 0);
659 map_info->num_vectors = vf->nb_msix;
660 for (i = 0; i < vf->nb_msix; i++) {
661 vecmap = &map_info->vecmap[i];
662 vecmap->vsi_id = vf->vsi_res->vsi_id;
663 vecmap->rxitr_idx = IAVF_ITR_INDEX_DEFAULT;
664 vecmap->vector_id = vf->msix_base + i;
666 vecmap->rxq_map = vf->rxq_map[vf->msix_base + i];
669 args.ops = VIRTCHNL_OP_CONFIG_IRQ_MAP;
670 args.in_args = (u8 *)map_info;
671 args.in_args_size = len;
672 args.out_buffer = vf->aq_resp;
673 args.out_size = IAVF_AQ_BUF_SZ;
674 err = iavf_execute_vf_cmd(adapter, &args);
676 PMD_DRV_LOG(ERR, "fail to execute command OP_CONFIG_IRQ_MAP");
683 iavf_add_del_all_mac_addr(struct iavf_adapter *adapter, bool add)
685 struct virtchnl_ether_addr_list *list;
686 struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(adapter);
687 struct rte_ether_addr *addr;
688 struct iavf_cmd_info args;
695 len = sizeof(struct virtchnl_ether_addr_list);
696 for (i = begin; i < IAVF_NUM_MACADDR_MAX; i++, next_begin++) {
697 addr = &adapter->eth_dev->data->mac_addrs[i];
698 if (rte_is_zero_ether_addr(addr))
700 len += sizeof(struct virtchnl_ether_addr);
701 if (len >= IAVF_AQ_BUF_SZ) {
707 list = rte_zmalloc("iavf_del_mac_buffer", len, 0);
709 PMD_DRV_LOG(ERR, "fail to allocate memory");
713 for (i = begin; i < next_begin; i++) {
714 addr = &adapter->eth_dev->data->mac_addrs[i];
715 if (rte_is_zero_ether_addr(addr))
717 rte_memcpy(list->list[j].addr, addr->addr_bytes,
718 sizeof(addr->addr_bytes));
719 PMD_DRV_LOG(DEBUG, "add/rm mac:%x:%x:%x:%x:%x:%x",
720 addr->addr_bytes[0], addr->addr_bytes[1],
721 addr->addr_bytes[2], addr->addr_bytes[3],
722 addr->addr_bytes[4], addr->addr_bytes[5]);
725 list->vsi_id = vf->vsi_res->vsi_id;
726 list->num_elements = j;
727 args.ops = add ? VIRTCHNL_OP_ADD_ETH_ADDR :
728 VIRTCHNL_OP_DEL_ETH_ADDR;
729 args.in_args = (uint8_t *)list;
730 args.in_args_size = len;
731 args.out_buffer = vf->aq_resp;
732 args.out_size = IAVF_AQ_BUF_SZ;
733 err = iavf_execute_vf_cmd(adapter, &args);
735 PMD_DRV_LOG(ERR, "fail to execute command %s",
736 add ? "OP_ADD_ETHER_ADDRESS" :
737 "OP_DEL_ETHER_ADDRESS");
740 } while (begin < IAVF_NUM_MACADDR_MAX);
744 iavf_query_stats(struct iavf_adapter *adapter,
745 struct virtchnl_eth_stats **pstats)
747 struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(adapter);
748 struct virtchnl_queue_select q_stats;
749 struct iavf_cmd_info args;
752 memset(&q_stats, 0, sizeof(q_stats));
753 q_stats.vsi_id = vf->vsi_res->vsi_id;
754 args.ops = VIRTCHNL_OP_GET_STATS;
755 args.in_args = (uint8_t *)&q_stats;
756 args.in_args_size = sizeof(q_stats);
757 args.out_buffer = vf->aq_resp;
758 args.out_size = IAVF_AQ_BUF_SZ;
760 err = iavf_execute_vf_cmd(adapter, &args);
762 PMD_DRV_LOG(ERR, "fail to execute command OP_GET_STATS");
766 *pstats = (struct virtchnl_eth_stats *)args.out_buffer;
771 iavf_config_promisc(struct iavf_adapter *adapter,
773 bool enable_multicast)
775 struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(adapter);
776 struct virtchnl_promisc_info promisc;
777 struct iavf_cmd_info args;
781 promisc.vsi_id = vf->vsi_res->vsi_id;
784 promisc.flags |= FLAG_VF_UNICAST_PROMISC;
786 if (enable_multicast)
787 promisc.flags |= FLAG_VF_MULTICAST_PROMISC;
789 args.ops = VIRTCHNL_OP_CONFIG_PROMISCUOUS_MODE;
790 args.in_args = (uint8_t *)&promisc;
791 args.in_args_size = sizeof(promisc);
792 args.out_buffer = vf->aq_resp;
793 args.out_size = IAVF_AQ_BUF_SZ;
795 err = iavf_execute_vf_cmd(adapter, &args);
799 "fail to execute command CONFIG_PROMISCUOUS_MODE");
804 iavf_add_del_eth_addr(struct iavf_adapter *adapter, struct rte_ether_addr *addr,
807 struct virtchnl_ether_addr_list *list;
808 struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(adapter);
809 uint8_t cmd_buffer[sizeof(struct virtchnl_ether_addr_list) +
810 sizeof(struct virtchnl_ether_addr)];
811 struct iavf_cmd_info args;
814 list = (struct virtchnl_ether_addr_list *)cmd_buffer;
815 list->vsi_id = vf->vsi_res->vsi_id;
816 list->num_elements = 1;
817 rte_memcpy(list->list[0].addr, addr->addr_bytes,
818 sizeof(addr->addr_bytes));
820 args.ops = add ? VIRTCHNL_OP_ADD_ETH_ADDR : VIRTCHNL_OP_DEL_ETH_ADDR;
821 args.in_args = cmd_buffer;
822 args.in_args_size = sizeof(cmd_buffer);
823 args.out_buffer = vf->aq_resp;
824 args.out_size = IAVF_AQ_BUF_SZ;
825 err = iavf_execute_vf_cmd(adapter, &args);
827 PMD_DRV_LOG(ERR, "fail to execute command %s",
828 add ? "OP_ADD_ETH_ADDR" : "OP_DEL_ETH_ADDR");
833 iavf_add_del_vlan(struct iavf_adapter *adapter, uint16_t vlanid, bool add)
835 struct virtchnl_vlan_filter_list *vlan_list;
836 struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(adapter);
837 uint8_t cmd_buffer[sizeof(struct virtchnl_vlan_filter_list) +
839 struct iavf_cmd_info args;
842 vlan_list = (struct virtchnl_vlan_filter_list *)cmd_buffer;
843 vlan_list->vsi_id = vf->vsi_res->vsi_id;
844 vlan_list->num_elements = 1;
845 vlan_list->vlan_id[0] = vlanid;
847 args.ops = add ? VIRTCHNL_OP_ADD_VLAN : VIRTCHNL_OP_DEL_VLAN;
848 args.in_args = cmd_buffer;
849 args.in_args_size = sizeof(cmd_buffer);
850 args.out_buffer = vf->aq_resp;
851 args.out_size = IAVF_AQ_BUF_SZ;
852 err = iavf_execute_vf_cmd(adapter, &args);
854 PMD_DRV_LOG(ERR, "fail to execute command %s",
855 add ? "OP_ADD_VLAN" : "OP_DEL_VLAN");
861 iavf_fdir_add(struct iavf_adapter *adapter,
862 struct iavf_fdir_conf *filter)
864 struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(adapter);
865 struct virtchnl_fdir_add *fdir_ret;
867 struct iavf_cmd_info args;
870 filter->add_fltr.vsi_id = vf->vsi_res->vsi_id;
871 filter->add_fltr.validate_only = 0;
873 args.ops = VIRTCHNL_OP_ADD_FDIR_FILTER;
874 args.in_args = (uint8_t *)(&filter->add_fltr);
875 args.in_args_size = sizeof(*(&filter->add_fltr));
876 args.out_buffer = vf->aq_resp;
877 args.out_size = IAVF_AQ_BUF_SZ;
879 err = iavf_execute_vf_cmd(adapter, &args);
881 PMD_DRV_LOG(ERR, "fail to execute command OP_ADD_FDIR_FILTER");
885 fdir_ret = (struct virtchnl_fdir_add *)args.out_buffer;
886 filter->flow_id = fdir_ret->flow_id;
888 if (fdir_ret->status == VIRTCHNL_FDIR_SUCCESS) {
890 "Succeed in adding rule request by PF");
891 } else if (fdir_ret->status == VIRTCHNL_FDIR_FAILURE_RULE_NORESOURCE) {
893 "Failed to add rule request due to no hw resource");
895 } else if (fdir_ret->status == VIRTCHNL_FDIR_FAILURE_RULE_EXIST) {
897 "Failed to add rule request due to the rule is already existed");
899 } else if (fdir_ret->status == VIRTCHNL_FDIR_FAILURE_RULE_CONFLICT) {
901 "Failed to add rule request due to the rule is conflict with existing rule");
903 } else if (fdir_ret->status == VIRTCHNL_FDIR_FAILURE_RULE_INVALID) {
905 "Failed to add rule request due to the hw doesn't support");
907 } else if (fdir_ret->status == VIRTCHNL_FDIR_FAILURE_RULE_TIMEOUT) {
909 "Failed to add rule request due to time out for programming");
913 "Failed to add rule request due to other reasons");
921 iavf_fdir_del(struct iavf_adapter *adapter,
922 struct iavf_fdir_conf *filter)
924 struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(adapter);
925 struct virtchnl_fdir_del *fdir_ret;
927 struct iavf_cmd_info args;
930 filter->del_fltr.vsi_id = vf->vsi_res->vsi_id;
931 filter->del_fltr.flow_id = filter->flow_id;
933 args.ops = VIRTCHNL_OP_DEL_FDIR_FILTER;
934 args.in_args = (uint8_t *)(&filter->del_fltr);
935 args.in_args_size = sizeof(filter->del_fltr);
936 args.out_buffer = vf->aq_resp;
937 args.out_size = IAVF_AQ_BUF_SZ;
939 err = iavf_execute_vf_cmd(adapter, &args);
941 PMD_DRV_LOG(ERR, "fail to execute command OP_DEL_FDIR_FILTER");
945 fdir_ret = (struct virtchnl_fdir_del *)args.out_buffer;
947 if (fdir_ret->status == VIRTCHNL_FDIR_SUCCESS) {
949 "Succeed in deleting rule request by PF");
950 } else if (fdir_ret->status == VIRTCHNL_FDIR_FAILURE_RULE_NONEXIST) {
952 "Failed to delete rule request due to this rule doesn't exist");
954 } else if (fdir_ret->status == VIRTCHNL_FDIR_FAILURE_RULE_TIMEOUT) {
956 "Failed to delete rule request due to time out for programming");
960 "Failed to delete rule request due to other reasons");
968 iavf_fdir_check(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_add *fdir_ret;
974 struct iavf_cmd_info args;
977 filter->add_fltr.vsi_id = vf->vsi_res->vsi_id;
978 filter->add_fltr.validate_only = 1;
980 args.ops = VIRTCHNL_OP_ADD_FDIR_FILTER;
981 args.in_args = (uint8_t *)(&filter->add_fltr);
982 args.in_args_size = sizeof(*(&filter->add_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 check flow direcotor rule");
992 fdir_ret = (struct virtchnl_fdir_add *)args.out_buffer;
994 if (fdir_ret->status == VIRTCHNL_FDIR_SUCCESS) {
996 "Succeed in checking rule request by PF");
997 } else if (fdir_ret->status == VIRTCHNL_FDIR_FAILURE_RULE_INVALID) {
999 "Failed to check rule request due to parameters validation"
1000 " or HW doesn't support");
1004 "Failed to check rule request due to other reasons");