xref: /dpdk/lib/ethdev/rte_ethdev_cman.c (revision 0e21c7c07d623719d61cc7e2e85613e8c71d9a57)
16b81dddbSJerin Jacob /* SPDX-License-Identifier: BSD-3-Clause
26b81dddbSJerin Jacob  * Copyright(C) 2022 Marvell International Ltd.
36b81dddbSJerin Jacob  */
46b81dddbSJerin Jacob 
56b81dddbSJerin Jacob #include <stdint.h>
66b81dddbSJerin Jacob 
76b81dddbSJerin Jacob #include <rte_errno.h>
86b81dddbSJerin Jacob #include "rte_ethdev.h"
96b81dddbSJerin Jacob #include "ethdev_driver.h"
106b81dddbSJerin Jacob #include "ethdev_private.h"
116679cf21SAnkur Dwivedi #include "ethdev_trace.h"
126b81dddbSJerin Jacob 
136b81dddbSJerin Jacob /* Get congestion management information for a port */
146b81dddbSJerin Jacob int
rte_eth_cman_info_get(uint16_t port_id,struct rte_eth_cman_info * info)156b81dddbSJerin Jacob rte_eth_cman_info_get(uint16_t port_id, struct rte_eth_cman_info *info)
166b81dddbSJerin Jacob {
176b81dddbSJerin Jacob 	struct rte_eth_dev *dev;
186679cf21SAnkur Dwivedi 	int ret;
196b81dddbSJerin Jacob 
206b81dddbSJerin Jacob 	RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
216b81dddbSJerin Jacob 	dev = &rte_eth_devices[port_id];
226b81dddbSJerin Jacob 
236b81dddbSJerin Jacob 	if (info == NULL) {
24*0e21c7c0SDavid Marchand 		RTE_ETHDEV_LOG_LINE(ERR, "congestion management info is NULL");
256b81dddbSJerin Jacob 		return -EINVAL;
266b81dddbSJerin Jacob 	}
276b81dddbSJerin Jacob 
286b81dddbSJerin Jacob 	if (dev->dev_ops->cman_info_get == NULL) {
29*0e21c7c0SDavid Marchand 		RTE_ETHDEV_LOG_LINE(ERR, "Function not implemented");
306b81dddbSJerin Jacob 		return -ENOTSUP;
316b81dddbSJerin Jacob 	}
326b81dddbSJerin Jacob 
336b81dddbSJerin Jacob 	memset(info, 0, sizeof(struct rte_eth_cman_info));
346679cf21SAnkur Dwivedi 	ret = eth_err(port_id, (*dev->dev_ops->cman_info_get)(dev, info));
356679cf21SAnkur Dwivedi 
366679cf21SAnkur Dwivedi 	rte_eth_trace_cman_info_get(port_id, info, ret);
376679cf21SAnkur Dwivedi 
386679cf21SAnkur Dwivedi 	return ret;
396b81dddbSJerin Jacob }
406b81dddbSJerin Jacob 
416b81dddbSJerin Jacob /* Initialize congestion management structure with default values */
426b81dddbSJerin Jacob int
rte_eth_cman_config_init(uint16_t port_id,struct rte_eth_cman_config * config)436b81dddbSJerin Jacob rte_eth_cman_config_init(uint16_t port_id, struct rte_eth_cman_config *config)
446b81dddbSJerin Jacob {
456b81dddbSJerin Jacob 	struct rte_eth_dev *dev;
466679cf21SAnkur Dwivedi 	int ret;
476b81dddbSJerin Jacob 
486b81dddbSJerin Jacob 	RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
496b81dddbSJerin Jacob 	dev = &rte_eth_devices[port_id];
506b81dddbSJerin Jacob 
516b81dddbSJerin Jacob 	if (config == NULL) {
52*0e21c7c0SDavid Marchand 		RTE_ETHDEV_LOG_LINE(ERR, "congestion management config is NULL");
536b81dddbSJerin Jacob 		return -EINVAL;
546b81dddbSJerin Jacob 	}
556b81dddbSJerin Jacob 
566b81dddbSJerin Jacob 	if (dev->dev_ops->cman_config_init == NULL) {
57*0e21c7c0SDavid Marchand 		RTE_ETHDEV_LOG_LINE(ERR, "Function not implemented");
586b81dddbSJerin Jacob 		return -ENOTSUP;
596b81dddbSJerin Jacob 	}
606b81dddbSJerin Jacob 
616b81dddbSJerin Jacob 	memset(config, 0, sizeof(struct rte_eth_cman_config));
626679cf21SAnkur Dwivedi 	ret = eth_err(port_id, (*dev->dev_ops->cman_config_init)(dev, config));
636679cf21SAnkur Dwivedi 
646679cf21SAnkur Dwivedi 	rte_eth_trace_cman_config_init(port_id, config, ret);
656679cf21SAnkur Dwivedi 
666679cf21SAnkur Dwivedi 	return ret;
676b81dddbSJerin Jacob }
686b81dddbSJerin Jacob 
696b81dddbSJerin Jacob /* Configure congestion management on a port */
706b81dddbSJerin Jacob int
rte_eth_cman_config_set(uint16_t port_id,const struct rte_eth_cman_config * config)716b81dddbSJerin Jacob rte_eth_cman_config_set(uint16_t port_id, const struct rte_eth_cman_config *config)
726b81dddbSJerin Jacob {
736b81dddbSJerin Jacob 	struct rte_eth_dev *dev;
746679cf21SAnkur Dwivedi 	int ret;
756b81dddbSJerin Jacob 
766b81dddbSJerin Jacob 	RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
776b81dddbSJerin Jacob 	dev = &rte_eth_devices[port_id];
786b81dddbSJerin Jacob 
796b81dddbSJerin Jacob 	if (config == NULL) {
80*0e21c7c0SDavid Marchand 		RTE_ETHDEV_LOG_LINE(ERR, "congestion management config is NULL");
816b81dddbSJerin Jacob 		return -EINVAL;
826b81dddbSJerin Jacob 	}
836b81dddbSJerin Jacob 
846b81dddbSJerin Jacob 	if (dev->dev_ops->cman_config_set == NULL) {
85*0e21c7c0SDavid Marchand 		RTE_ETHDEV_LOG_LINE(ERR, "Function not implemented");
866b81dddbSJerin Jacob 		return -ENOTSUP;
876b81dddbSJerin Jacob 	}
886b81dddbSJerin Jacob 
896679cf21SAnkur Dwivedi 	ret = eth_err(port_id, (*dev->dev_ops->cman_config_set)(dev, config));
906679cf21SAnkur Dwivedi 
916679cf21SAnkur Dwivedi 	rte_eth_trace_cman_config_set(port_id, config, ret);
926679cf21SAnkur Dwivedi 
936679cf21SAnkur Dwivedi 	return ret;
946b81dddbSJerin Jacob }
956b81dddbSJerin Jacob 
966b81dddbSJerin Jacob /* Retrieve congestion management configuration of a port */
976b81dddbSJerin Jacob int
rte_eth_cman_config_get(uint16_t port_id,struct rte_eth_cman_config * config)986b81dddbSJerin Jacob rte_eth_cman_config_get(uint16_t port_id, struct rte_eth_cman_config *config)
996b81dddbSJerin Jacob {
1006b81dddbSJerin Jacob 	struct rte_eth_dev *dev;
1016679cf21SAnkur Dwivedi 	int ret;
1026b81dddbSJerin Jacob 
1036b81dddbSJerin Jacob 	RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
1046b81dddbSJerin Jacob 	dev = &rte_eth_devices[port_id];
1056b81dddbSJerin Jacob 
1066b81dddbSJerin Jacob 	if (config == NULL) {
107*0e21c7c0SDavid Marchand 		RTE_ETHDEV_LOG_LINE(ERR, "congestion management config is NULL");
1086b81dddbSJerin Jacob 		return -EINVAL;
1096b81dddbSJerin Jacob 	}
1106b81dddbSJerin Jacob 
1116b81dddbSJerin Jacob 	if (dev->dev_ops->cman_config_get == NULL) {
112*0e21c7c0SDavid Marchand 		RTE_ETHDEV_LOG_LINE(ERR, "Function not implemented");
1136b81dddbSJerin Jacob 		return -ENOTSUP;
1146b81dddbSJerin Jacob 	}
1156b81dddbSJerin Jacob 
1166b81dddbSJerin Jacob 	memset(config, 0, sizeof(struct rte_eth_cman_config));
1176679cf21SAnkur Dwivedi 	ret = eth_err(port_id, (*dev->dev_ops->cman_config_get)(dev, config));
1186679cf21SAnkur Dwivedi 
1196679cf21SAnkur Dwivedi 	rte_eth_trace_cman_config_get(port_id, config, ret);
1206679cf21SAnkur Dwivedi 
1216679cf21SAnkur Dwivedi 	return ret;
1226b81dddbSJerin Jacob }
123