event/octeontx: add configure function
[dpdk.git] / drivers / event / octeontx / ssovf_evdev.c
1 /*
2  *   BSD LICENSE
3  *
4  *   Copyright (C) Cavium networks Ltd. 2017.
5  *
6  *   Redistribution and use in source and binary forms, with or without
7  *   modification, are permitted provided that the following conditions
8  *   are met:
9  *
10  *     * Redistributions of source code must retain the above copyright
11  *       notice, this list of conditions and the following disclaimer.
12  *     * Redistributions in binary form must reproduce the above copyright
13  *       notice, this list of conditions and the following disclaimer in
14  *       the documentation and/or other materials provided with the
15  *       distribution.
16  *     * Neither the name of Cavium networks nor the names of its
17  *       contributors may be used to endorse or promote products derived
18  *       from this software without specific prior written permission.
19  *
20  *   THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
21  *   "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
22  *   LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
23  *   A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
24  *   OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
25  *   SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
26  *   LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
27  *   DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
28  *   THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29  *   (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
30  *   OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31  */
32
33 #include <rte_common.h>
34 #include <rte_debug.h>
35 #include <rte_dev.h>
36 #include <rte_eal.h>
37 #include <rte_lcore.h>
38 #include <rte_log.h>
39 #include <rte_malloc.h>
40 #include <rte_memory.h>
41 #include <rte_memzone.h>
42 #include <rte_vdev.h>
43
44 #include "ssovf_evdev.h"
45
46 /* SSOPF Mailbox messages */
47
48 struct ssovf_mbox_dev_info {
49         uint64_t min_deq_timeout_ns;
50         uint64_t max_deq_timeout_ns;
51         uint32_t max_num_events;
52 };
53
54 static int
55 ssovf_mbox_dev_info(struct ssovf_mbox_dev_info *info)
56 {
57         struct octeontx_mbox_hdr hdr = {0};
58         uint16_t len = sizeof(struct ssovf_mbox_dev_info);
59
60         hdr.coproc = SSO_COPROC;
61         hdr.msg = SSO_GET_DEV_INFO;
62         hdr.vfid = 0;
63
64         memset(info, 0, len);
65         return octeontx_ssovf_mbox_send(&hdr, NULL, 0, info, len);
66 }
67
68 struct ssovf_mbox_getwork_wait {
69         uint64_t wait_ns;
70 };
71
72 static int
73 ssovf_mbox_getwork_tmo_set(uint32_t timeout_ns)
74 {
75         struct octeontx_mbox_hdr hdr = {0};
76         struct ssovf_mbox_getwork_wait tmo_set;
77         uint16_t len = sizeof(struct ssovf_mbox_getwork_wait);
78         int ret;
79
80         hdr.coproc = SSO_COPROC;
81         hdr.msg = SSO_SET_GETWORK_WAIT;
82         hdr.vfid = 0;
83
84         tmo_set.wait_ns = timeout_ns;
85         ret = octeontx_ssovf_mbox_send(&hdr, &tmo_set, len, NULL, 0);
86         if (ret)
87                 ssovf_log_err("Failed to set getwork timeout(%d)", ret);
88
89         return ret;
90 }
91
92 static void
93 ssovf_info_get(struct rte_eventdev *dev, struct rte_event_dev_info *dev_info)
94 {
95         struct ssovf_evdev *edev = ssovf_pmd_priv(dev);
96
97         dev_info->min_dequeue_timeout_ns = edev->min_deq_timeout_ns;
98         dev_info->max_dequeue_timeout_ns = edev->max_deq_timeout_ns;
99         dev_info->max_event_queues = edev->max_event_queues;
100         dev_info->max_event_queue_flows = (1ULL << 20);
101         dev_info->max_event_queue_priority_levels = 8;
102         dev_info->max_event_priority_levels = 1;
103         dev_info->max_event_ports = edev->max_event_ports;
104         dev_info->max_event_port_dequeue_depth = 1;
105         dev_info->max_event_port_enqueue_depth = 1;
106         dev_info->max_num_events =  edev->max_num_events;
107         dev_info->event_dev_cap = RTE_EVENT_DEV_CAP_QUEUE_QOS |
108                                         RTE_EVENT_DEV_CAP_DISTRIBUTED_SCHED |
109                                         RTE_EVENT_DEV_CAP_QUEUE_ALL_TYPES;
110 }
111
112 static int
113 ssovf_configure(const struct rte_eventdev *dev)
114 {
115         struct rte_event_dev_config *conf = &dev->data->dev_conf;
116         struct ssovf_evdev *edev = ssovf_pmd_priv(dev);
117         uint64_t deq_tmo_ns;
118
119         ssovf_func_trace();
120         deq_tmo_ns = conf->dequeue_timeout_ns;
121
122         if (conf->event_dev_cfg & RTE_EVENT_DEV_CFG_PER_DEQUEUE_TIMEOUT) {
123                 edev->is_timeout_deq = 1;
124                 deq_tmo_ns = edev->min_deq_timeout_ns;
125         }
126         edev->nb_event_queues = conf->nb_event_queues;
127         edev->nb_event_ports = conf->nb_event_ports;
128
129         return ssovf_mbox_getwork_tmo_set(deq_tmo_ns);
130 }
131
132 /* Initialize and register event driver with DPDK Application */
133 static const struct rte_eventdev_ops ssovf_ops = {
134         .dev_infos_get    = ssovf_info_get,
135         .dev_configure    = ssovf_configure,
136 };
137
138 static int
139 ssovf_vdev_probe(const char *name, const char *params)
140 {
141         struct octeontx_ssovf_info oinfo;
142         struct ssovf_mbox_dev_info info;
143         struct ssovf_evdev *edev;
144         struct rte_eventdev *eventdev;
145         static int ssovf_init_once;
146         int ret;
147
148         RTE_SET_USED(params);
149
150         /* More than one instance is not supported */
151         if (ssovf_init_once) {
152                 ssovf_log_err("Request to create >1 %s instance", name);
153                 return -EINVAL;
154         }
155
156         eventdev = rte_event_pmd_vdev_init(name, sizeof(struct ssovf_evdev),
157                                 rte_socket_id());
158         if (eventdev == NULL) {
159                 ssovf_log_err("Failed to create eventdev vdev %s", name);
160                 return -ENOMEM;
161         }
162         eventdev->dev_ops = &ssovf_ops;
163
164         /* For secondary processes, the primary has done all the work */
165         if (rte_eal_process_type() != RTE_PROC_PRIMARY)
166                 return 0;
167
168         ret = octeontx_ssovf_info(&oinfo);
169         if (ret) {
170                 ssovf_log_err("Failed to probe and validate ssovfs %d", ret);
171                 goto error;
172         }
173
174         edev = ssovf_pmd_priv(eventdev);
175         edev->max_event_ports = oinfo.total_ssowvfs;
176         edev->max_event_queues = oinfo.total_ssovfs;
177         edev->is_timeout_deq = 0;
178
179         ret = ssovf_mbox_dev_info(&info);
180         if (ret < 0 || ret != sizeof(struct ssovf_mbox_dev_info)) {
181                 ssovf_log_err("Failed to get mbox devinfo %d", ret);
182                 goto error;
183         }
184
185         edev->min_deq_timeout_ns = info.min_deq_timeout_ns;
186         edev->max_deq_timeout_ns = info.max_deq_timeout_ns;
187         edev->max_num_events =  info.max_num_events;
188         ssovf_log_dbg("min_deq_tmo=%"PRId64" max_deq_tmo=%"PRId64" max_evts=%d",
189                         info.min_deq_timeout_ns, info.max_deq_timeout_ns,
190                         info.max_num_events);
191
192         if (!edev->max_event_ports || !edev->max_event_queues) {
193                 ssovf_log_err("Not enough eventdev resource queues=%d ports=%d",
194                         edev->max_event_queues, edev->max_event_ports);
195                 ret = -ENODEV;
196                 goto error;
197         }
198
199         ssovf_log_info("Initializing %s domain=%d max_queues=%d max_ports=%d",
200                         name, oinfo.domain, edev->max_event_queues,
201                         edev->max_event_ports);
202
203         ssovf_init_once = 1;
204         return 0;
205
206 error:
207         rte_event_pmd_vdev_uninit(name);
208         return ret;
209 }
210
211 static int
212 ssovf_vdev_remove(const char *name)
213 {
214         ssovf_log_info("Closing %s", name);
215         return rte_event_pmd_vdev_uninit(name);
216 }
217
218 static struct rte_vdev_driver vdev_ssovf_pmd = {
219         .probe = ssovf_vdev_probe,
220         .remove = ssovf_vdev_remove
221 };
222
223 RTE_PMD_REGISTER_VDEV(EVENTDEV_NAME_OCTEONTX_PMD, vdev_ssovf_pmd);