0f20c163bf1a6ed0ea0b3013336220688b4075ff
[dpdk.git] / drivers / event / octeontx2 / otx2_tim_evdev.c
1 /* SPDX-License-Identifier: BSD-3-Clause
2  * Copyright(C) 2019 Marvell International Ltd.
3  */
4
5 #include "otx2_evdev.h"
6 #include "otx2_tim_evdev.h"
7
8 int
9 otx2_tim_caps_get(const struct rte_eventdev *evdev, uint64_t flags,
10                   uint32_t *caps,
11                   const struct rte_event_timer_adapter_ops **ops)
12 {
13         struct otx2_tim_evdev *dev = tim_priv_get();
14
15         RTE_SET_USED(flags);
16         RTE_SET_USED(ops);
17         if (dev == NULL)
18                 return -ENODEV;
19
20         /* Store evdev pointer for later use. */
21         dev->event_dev = (struct rte_eventdev *)(uintptr_t)evdev;
22         *caps = RTE_EVENT_TIMER_ADAPTER_CAP_INTERNAL_PORT;
23
24         return 0;
25 }
26
27 void
28 otx2_tim_init(struct rte_pci_device *pci_dev, struct otx2_dev *cmn_dev)
29 {
30         struct rsrc_attach_req *atch_req;
31         struct free_rsrcs_rsp *rsrc_cnt;
32         const struct rte_memzone *mz;
33         struct otx2_tim_evdev *dev;
34         int rc;
35
36         if (rte_eal_process_type() != RTE_PROC_PRIMARY)
37                 return;
38
39         mz = rte_memzone_reserve(RTE_STR(OTX2_TIM_EVDEV_NAME),
40                                  sizeof(struct otx2_tim_evdev),
41                                  rte_socket_id(), 0);
42         if (mz == NULL) {
43                 otx2_tim_dbg("Unable to allocate memory for TIM Event device");
44                 return;
45         }
46
47         dev = mz->addr;
48         dev->pci_dev = pci_dev;
49         dev->mbox = cmn_dev->mbox;
50         dev->bar2 = cmn_dev->bar2;
51
52         otx2_mbox_alloc_msg_free_rsrc_cnt(dev->mbox);
53         rc = otx2_mbox_process_msg(dev->mbox, (void *)&rsrc_cnt);
54         if (rc < 0) {
55                 otx2_err("Unable to get free rsrc count.");
56                 goto mz_free;
57         }
58
59         dev->nb_rings = rsrc_cnt->tim;
60
61         if (!dev->nb_rings) {
62                 otx2_tim_dbg("No TIM Logical functions provisioned.");
63                 goto mz_free;
64         }
65
66         atch_req = otx2_mbox_alloc_msg_attach_resources(dev->mbox);
67         atch_req->modify = true;
68         atch_req->timlfs = dev->nb_rings;
69
70         rc = otx2_mbox_process(dev->mbox);
71         if (rc < 0) {
72                 otx2_err("Unable to attach TIM rings.");
73                 goto mz_free;
74         }
75
76         return;
77
78 mz_free:
79         rte_memzone_free(mz);
80 }
81
82 void
83 otx2_tim_fini(void)
84 {
85         struct otx2_tim_evdev *dev = tim_priv_get();
86         struct rsrc_detach_req *dtch_req;
87
88         if (rte_eal_process_type() != RTE_PROC_PRIMARY)
89                 return;
90
91         dtch_req = otx2_mbox_alloc_msg_detach_resources(dev->mbox);
92         dtch_req->partial = true;
93         dtch_req->timlfs = true;
94
95         otx2_mbox_process(dev->mbox);
96         rte_memzone_free(rte_memzone_lookup(RTE_STR(OTX2_TIM_EVDEV_NAME)));
97 }