event/octeontx: add octeontx eventdev driver
[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 static int
69 ssovf_vdev_probe(const char *name, const char *params)
70 {
71         struct octeontx_ssovf_info oinfo;
72         struct ssovf_mbox_dev_info info;
73         struct ssovf_evdev *edev;
74         struct rte_eventdev *eventdev;
75         static int ssovf_init_once;
76         int ret;
77
78         RTE_SET_USED(params);
79
80         /* More than one instance is not supported */
81         if (ssovf_init_once) {
82                 ssovf_log_err("Request to create >1 %s instance", name);
83                 return -EINVAL;
84         }
85
86         eventdev = rte_event_pmd_vdev_init(name, sizeof(struct ssovf_evdev),
87                                 rte_socket_id());
88         if (eventdev == NULL) {
89                 ssovf_log_err("Failed to create eventdev vdev %s", name);
90                 return -ENOMEM;
91         }
92         eventdev->dev_ops = NULL;
93
94         /* For secondary processes, the primary has done all the work */
95         if (rte_eal_process_type() != RTE_PROC_PRIMARY)
96                 return 0;
97
98         ret = octeontx_ssovf_info(&oinfo);
99         if (ret) {
100                 ssovf_log_err("Failed to probe and validate ssovfs %d", ret);
101                 goto error;
102         }
103
104         edev = ssovf_pmd_priv(eventdev);
105         edev->max_event_ports = oinfo.total_ssowvfs;
106         edev->max_event_queues = oinfo.total_ssovfs;
107         edev->is_timeout_deq = 0;
108
109         ret = ssovf_mbox_dev_info(&info);
110         if (ret < 0 || ret != sizeof(struct ssovf_mbox_dev_info)) {
111                 ssovf_log_err("Failed to get mbox devinfo %d", ret);
112                 goto error;
113         }
114
115         edev->min_deq_timeout_ns = info.min_deq_timeout_ns;
116         edev->max_deq_timeout_ns = info.max_deq_timeout_ns;
117         edev->max_num_events =  info.max_num_events;
118         ssovf_log_dbg("min_deq_tmo=%"PRId64" max_deq_tmo=%"PRId64" max_evts=%d",
119                         info.min_deq_timeout_ns, info.max_deq_timeout_ns,
120                         info.max_num_events);
121
122         if (!edev->max_event_ports || !edev->max_event_queues) {
123                 ssovf_log_err("Not enough eventdev resource queues=%d ports=%d",
124                         edev->max_event_queues, edev->max_event_ports);
125                 ret = -ENODEV;
126                 goto error;
127         }
128
129         ssovf_log_info("Initializing %s domain=%d max_queues=%d max_ports=%d",
130                         name, oinfo.domain, edev->max_event_queues,
131                         edev->max_event_ports);
132
133         ssovf_init_once = 1;
134         return 0;
135
136 error:
137         rte_event_pmd_vdev_uninit(name);
138         return ret;
139 }
140
141 static int
142 ssovf_vdev_remove(const char *name)
143 {
144         ssovf_log_info("Closing %s", name);
145         return rte_event_pmd_vdev_uninit(name);
146 }
147
148 static struct rte_vdev_driver vdev_ssovf_pmd = {
149         .probe = ssovf_vdev_probe,
150         .remove = ssovf_vdev_remove
151 };
152
153 RTE_PMD_REGISTER_VDEV(EVENTDEV_NAME_OCTEONTX_PMD, vdev_ssovf_pmd);