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 #include "ethdev_trace.h" 12 13 /* Get congestion management information for a port */ 14 int 15 rte_eth_cman_info_get(uint16_t port_id, struct rte_eth_cman_info *info) 16 { 17 struct rte_eth_dev *dev; 18 int ret; 19 20 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV); 21 dev = &rte_eth_devices[port_id]; 22 23 if (info == NULL) { 24 RTE_ETHDEV_LOG_LINE(ERR, "congestion management info is NULL"); 25 return -EINVAL; 26 } 27 28 if (dev->dev_ops->cman_info_get == NULL) { 29 RTE_ETHDEV_LOG_LINE(ERR, "Function not implemented"); 30 return -ENOTSUP; 31 } 32 33 memset(info, 0, sizeof(struct rte_eth_cman_info)); 34 ret = eth_err(port_id, (*dev->dev_ops->cman_info_get)(dev, info)); 35 36 rte_eth_trace_cman_info_get(port_id, info, ret); 37 38 return ret; 39 } 40 41 /* Initialize congestion management structure with default values */ 42 int 43 rte_eth_cman_config_init(uint16_t port_id, struct rte_eth_cman_config *config) 44 { 45 struct rte_eth_dev *dev; 46 int ret; 47 48 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV); 49 dev = &rte_eth_devices[port_id]; 50 51 if (config == NULL) { 52 RTE_ETHDEV_LOG_LINE(ERR, "congestion management config is NULL"); 53 return -EINVAL; 54 } 55 56 if (dev->dev_ops->cman_config_init == NULL) { 57 RTE_ETHDEV_LOG_LINE(ERR, "Function not implemented"); 58 return -ENOTSUP; 59 } 60 61 memset(config, 0, sizeof(struct rte_eth_cman_config)); 62 ret = eth_err(port_id, (*dev->dev_ops->cman_config_init)(dev, config)); 63 64 rte_eth_trace_cman_config_init(port_id, config, ret); 65 66 return ret; 67 } 68 69 /* Configure congestion management on a port */ 70 int 71 rte_eth_cman_config_set(uint16_t port_id, const struct rte_eth_cman_config *config) 72 { 73 struct rte_eth_dev *dev; 74 int ret; 75 76 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV); 77 dev = &rte_eth_devices[port_id]; 78 79 if (config == NULL) { 80 RTE_ETHDEV_LOG_LINE(ERR, "congestion management config is NULL"); 81 return -EINVAL; 82 } 83 84 if (dev->dev_ops->cman_config_set == NULL) { 85 RTE_ETHDEV_LOG_LINE(ERR, "Function not implemented"); 86 return -ENOTSUP; 87 } 88 89 ret = eth_err(port_id, (*dev->dev_ops->cman_config_set)(dev, config)); 90 91 rte_eth_trace_cman_config_set(port_id, config, ret); 92 93 return ret; 94 } 95 96 /* Retrieve congestion management configuration of a port */ 97 int 98 rte_eth_cman_config_get(uint16_t port_id, struct rte_eth_cman_config *config) 99 { 100 struct rte_eth_dev *dev; 101 int ret; 102 103 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV); 104 dev = &rte_eth_devices[port_id]; 105 106 if (config == NULL) { 107 RTE_ETHDEV_LOG_LINE(ERR, "congestion management config is NULL"); 108 return -EINVAL; 109 } 110 111 if (dev->dev_ops->cman_config_get == NULL) { 112 RTE_ETHDEV_LOG_LINE(ERR, "Function not implemented"); 113 return -ENOTSUP; 114 } 115 116 memset(config, 0, sizeof(struct rte_eth_cman_config)); 117 ret = eth_err(port_id, (*dev->dev_ops->cman_config_get)(dev, config)); 118 119 rte_eth_trace_cman_config_get(port_id, config, ret); 120 121 return ret; 122 } 123