event/dlb: add token pop API
[dpdk.git] / drivers / event / dlb / rte_pmd_dlb.c
1 /* SPDX-License-Identifier: BSD-3-Clause
2  * Copyright(c) 2020 Intel Corporation
3  */
4
5 #include "rte_eventdev.h"
6 #include "rte_eventdev_pmd.h"
7 #include "rte_pmd_dlb.h"
8 #include "dlb_priv.h"
9 #include "dlb_inline_fns.h"
10
11 int
12 rte_pmd_dlb_set_token_pop_mode(uint8_t dev_id,
13                                uint8_t port_id,
14                                enum dlb_token_pop_mode mode)
15 {
16         struct dlb_eventdev *dlb;
17         struct rte_eventdev *dev;
18
19         RTE_EVENTDEV_VALID_DEVID_OR_ERR_RET(dev_id, -EINVAL);
20         dev = &rte_eventdevs[dev_id];
21
22         dlb = dlb_pmd_priv(dev);
23
24         if (mode >= NUM_TOKEN_POP_MODES)
25                 return -EINVAL;
26
27         /* The event device must be configured, but not yet started */
28         if (!dlb->configured || dlb->run_state != DLB_RUN_STATE_STOPPED)
29                 return -EINVAL;
30
31         /* The token pop mode must be set before configuring the port */
32         if (port_id >= dlb->num_ports || dlb->ev_ports[port_id].setup_done)
33                 return -EINVAL;
34
35         dlb->ev_ports[port_id].qm_port.token_pop_mode = mode;
36
37         return 0;
38 }