1 /* SPDX-License-Identifier: BSD-3-Clause 2 * Copyright(C) 2022 Marvell International Ltd. 3 */ 4 5 #include <stdint.h> 6 7 #include <rte_errno.h> 8 #include "rte_ethdev.h" 9 #include "ethdev_driver.h" 10 #include "ethdev_private.h" 11 12 /* Get congestion management information for a port */ 13 int 14 rte_eth_cman_info_get(uint16_t port_id, struct rte_eth_cman_info *info) 15 { 16 struct rte_eth_dev *dev; 17 18 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV); 19 dev = &rte_eth_devices[port_id]; 20 21 if (info == NULL) { 22 RTE_ETHDEV_LOG(ERR, "congestion management info is NULL\n"); 23 return -EINVAL; 24 } 25 26 if (dev->dev_ops->cman_info_get == NULL) { 27 RTE_ETHDEV_LOG(ERR, "Function not implemented\n"); 28 return -ENOTSUP; 29 } 30 31 memset(info, 0, sizeof(struct rte_eth_cman_info)); 32 return eth_err(port_id, (*dev->dev_ops->cman_info_get)(dev, info)); 33 } 34 35 /* Initialize congestion management structure with default values */ 36 int 37 rte_eth_cman_config_init(uint16_t port_id, struct rte_eth_cman_config *config) 38 { 39 struct rte_eth_dev *dev; 40 41 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV); 42 dev = &rte_eth_devices[port_id]; 43 44 if (config == NULL) { 45 RTE_ETHDEV_LOG(ERR, "congestion management config is NULL\n"); 46 return -EINVAL; 47 } 48 49 if (dev->dev_ops->cman_config_init == NULL) { 50 RTE_ETHDEV_LOG(ERR, "Function not implemented\n"); 51 return -ENOTSUP; 52 } 53 54 memset(config, 0, sizeof(struct rte_eth_cman_config)); 55 return eth_err(port_id, (*dev->dev_ops->cman_config_init)(dev, config)); 56 } 57 58 /* Configure congestion management on a port */ 59 int 60 rte_eth_cman_config_set(uint16_t port_id, const struct rte_eth_cman_config *config) 61 { 62 struct rte_eth_dev *dev; 63 64 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV); 65 dev = &rte_eth_devices[port_id]; 66 67 if (config == NULL) { 68 RTE_ETHDEV_LOG(ERR, "congestion management config is NULL\n"); 69 return -EINVAL; 70 } 71 72 if (dev->dev_ops->cman_config_set == NULL) { 73 RTE_ETHDEV_LOG(ERR, "Function not implemented\n"); 74 return -ENOTSUP; 75 } 76 77 return eth_err(port_id, (*dev->dev_ops->cman_config_set)(dev, config)); 78 } 79 80 /* Retrieve congestion management configuration of a port */ 81 int 82 rte_eth_cman_config_get(uint16_t port_id, struct rte_eth_cman_config *config) 83 { 84 struct rte_eth_dev *dev; 85 86 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV); 87 dev = &rte_eth_devices[port_id]; 88 89 if (config == NULL) { 90 RTE_ETHDEV_LOG(ERR, "congestion management config is NULL\n"); 91 return -EINVAL; 92 } 93 94 if (dev->dev_ops->cman_config_get == NULL) { 95 RTE_ETHDEV_LOG(ERR, "Function not implemented\n"); 96 return -ENOTSUP; 97 } 98 99 memset(config, 0, sizeof(struct rte_eth_cman_config)); 100 return eth_err(port_id, (*dev->dev_ops->cman_config_get)(dev, config)); 101 } 102