004701f6477b539c341a2f1d85769bd2cc4886f8
[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 void
9 otx2_tim_init(struct rte_pci_device *pci_dev, struct otx2_dev *cmn_dev)
10 {
11         struct rsrc_attach_req *atch_req;
12         struct free_rsrcs_rsp *rsrc_cnt;
13         const struct rte_memzone *mz;
14         struct otx2_tim_evdev *dev;
15         int rc;
16
17         if (rte_eal_process_type() != RTE_PROC_PRIMARY)
18                 return;
19
20         mz = rte_memzone_reserve(RTE_STR(OTX2_TIM_EVDEV_NAME),
21                                  sizeof(struct otx2_tim_evdev),
22                                  rte_socket_id(), 0);
23         if (mz == NULL) {
24                 otx2_tim_dbg("Unable to allocate memory for TIM Event device");
25                 return;
26         }
27
28         dev = mz->addr;
29         dev->pci_dev = pci_dev;
30         dev->mbox = cmn_dev->mbox;
31         dev->bar2 = cmn_dev->bar2;
32
33         otx2_mbox_alloc_msg_free_rsrc_cnt(dev->mbox);
34         rc = otx2_mbox_process_msg(dev->mbox, (void *)&rsrc_cnt);
35         if (rc < 0) {
36                 otx2_err("Unable to get free rsrc count.");
37                 goto mz_free;
38         }
39
40         dev->nb_rings = rsrc_cnt->tim;
41
42         if (!dev->nb_rings) {
43                 otx2_tim_dbg("No TIM Logical functions provisioned.");
44                 goto mz_free;
45         }
46
47         atch_req = otx2_mbox_alloc_msg_attach_resources(dev->mbox);
48         atch_req->modify = true;
49         atch_req->timlfs = dev->nb_rings;
50
51         rc = otx2_mbox_process(dev->mbox);
52         if (rc < 0) {
53                 otx2_err("Unable to attach TIM rings.");
54                 goto mz_free;
55         }
56
57         return;
58
59 mz_free:
60         rte_memzone_free(mz);
61 }
62
63 void
64 otx2_tim_fini(void)
65 {
66         struct otx2_tim_evdev *dev = tim_priv_get();
67         struct rsrc_detach_req *dtch_req;
68
69         if (rte_eal_process_type() != RTE_PROC_PRIMARY)
70                 return;
71
72         dtch_req = otx2_mbox_alloc_msg_detach_resources(dev->mbox);
73         dtch_req->partial = true;
74         dtch_req->timlfs = true;
75
76         otx2_mbox_process(dev->mbox);
77         rte_memzone_free(rte_memzone_lookup(RTE_STR(OTX2_TIM_EVDEV_NAME)));
78 }