New upstream version 17.11.1
[deb_dpdk.git] / drivers / bus / fslmc / rte_fslmc.h
1 /*-
2  *   BSD LICENSE
3  *
4  *   Copyright 2016 NXP.
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 NXP 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 #ifndef _RTE_FSLMC_H_
34 #define _RTE_FSLMC_H_
35
36 /**
37  * @file
38  *
39  * RTE FSLMC Bus Interface
40  */
41
42 #ifdef __cplusplus
43 extern "C" {
44 #endif
45
46 #include <stdio.h>
47 #include <stdlib.h>
48 #include <limits.h>
49 #include <errno.h>
50 #include <sys/queue.h>
51 #include <stdint.h>
52 #include <inttypes.h>
53 #include <linux/vfio.h>
54
55 #include <rte_debug.h>
56 #include <rte_interrupts.h>
57 #include <rte_dev.h>
58 #include <rte_bus.h>
59 #include <rte_tailq.h>
60
61 #include <fslmc_vfio.h>
62
63 #define FSLMC_OBJECT_MAX_LEN 32   /**< Length of each device on bus */
64
65 struct rte_dpaa2_driver;
66
67 /* DPAA2 Device and Driver lists for FSLMC bus */
68 TAILQ_HEAD(rte_fslmc_device_list, rte_dpaa2_device);
69 TAILQ_HEAD(rte_fslmc_driver_list, rte_dpaa2_driver);
70
71 extern struct rte_fslmc_bus rte_fslmc_bus;
72
73 enum rte_dpaa2_dev_type {
74         /* Devices backed by DPDK driver */
75         DPAA2_ETH,      /**< DPNI type device*/
76         DPAA2_CRYPTO,   /**< DPSECI type device */
77         DPAA2_CON,      /**< DPCONC type device */
78         /* Devices not backed by a DPDK driver: DPIO, DPBP, DPCI, DPMCP */
79         DPAA2_BPOOL,    /**< DPBP type device */
80         DPAA2_IO,       /**< DPIO type device */
81         DPAA2_CI,       /**< DPCI type device */
82         DPAA2_MPORTAL,  /**< DPMCP type device */
83         /* Unknown device placeholder */
84         DPAA2_UNKNOWN
85 };
86
87 TAILQ_HEAD(rte_dpaa2_object_list, rte_dpaa2_object);
88
89 typedef int (*rte_dpaa2_obj_create_t)(int vdev_fd,
90                                       struct vfio_device_info *obj_info,
91                                       int object_id);
92
93 /**
94  * A structure describing a DPAA2 object.
95  */
96 struct rte_dpaa2_object {
97         TAILQ_ENTRY(rte_dpaa2_object) next; /**< Next in list. */
98         const char *name;                   /**< Name of Object. */
99         enum rte_dpaa2_dev_type dev_type;   /**< Type of device */
100         rte_dpaa2_obj_create_t create;
101 };
102
103 /**
104  * A structure describing a DPAA2 device.
105  */
106 struct rte_dpaa2_device {
107         TAILQ_ENTRY(rte_dpaa2_device) next; /**< Next probed DPAA2 device. */
108         struct rte_device device;           /**< Inherit core device */
109         union {
110                 struct rte_eth_dev *eth_dev;        /**< ethernet device */
111                 struct rte_cryptodev *cryptodev;    /**< Crypto Device */
112         };
113         enum rte_dpaa2_dev_type dev_type;   /**< Device Type */
114         uint16_t object_id;                 /**< DPAA2 Object ID */
115         struct rte_intr_handle intr_handle; /**< Interrupt handle */
116         struct rte_dpaa2_driver *driver;    /**< Associated driver */
117         char name[FSLMC_OBJECT_MAX_LEN];    /**< DPAA2 Object name*/
118 };
119
120 typedef int (*rte_dpaa2_probe_t)(struct rte_dpaa2_driver *dpaa2_drv,
121                                  struct rte_dpaa2_device *dpaa2_dev);
122 typedef int (*rte_dpaa2_remove_t)(struct rte_dpaa2_device *dpaa2_dev);
123
124 /**
125  * A structure describing a DPAA2 driver.
126  */
127 struct rte_dpaa2_driver {
128         TAILQ_ENTRY(rte_dpaa2_driver) next; /**< Next in list. */
129         struct rte_driver driver;           /**< Inherit core driver. */
130         struct rte_fslmc_bus *fslmc_bus;    /**< FSLMC bus reference */
131         uint32_t drv_flags;                 /**< Flags for controlling device.*/
132         enum rte_dpaa2_dev_type drv_type;   /**< Driver Type */
133         rte_dpaa2_probe_t probe;
134         rte_dpaa2_remove_t remove;
135 };
136
137 /*
138  * FSLMC bus
139  */
140 struct rte_fslmc_bus {
141         struct rte_bus bus;     /**< Generic Bus object */
142         struct rte_fslmc_device_list device_list;
143                                 /**< FSLMC DPAA2 Device list */
144         struct rte_fslmc_driver_list driver_list;
145                                 /**< FSLMC DPAA2 Driver list */
146         int device_count;
147                                 /**< Optional: Count of devices on bus */
148 };
149
150 /**
151  * Register a DPAA2 driver.
152  *
153  * @param driver
154  *   A pointer to a rte_dpaa2_driver structure describing the driver
155  *   to be registered.
156  */
157 void rte_fslmc_driver_register(struct rte_dpaa2_driver *driver);
158
159 /**
160  * Unregister a DPAA2 driver.
161  *
162  * @param driver
163  *   A pointer to a rte_dpaa2_driver structure describing the driver
164  *   to be unregistered.
165  */
166 void rte_fslmc_driver_unregister(struct rte_dpaa2_driver *driver);
167
168 /** Helper for DPAA2 device registration from driver (eth, crypto) instance */
169 #define RTE_PMD_REGISTER_DPAA2(nm, dpaa2_drv) \
170 RTE_INIT(dpaa2initfn_ ##nm); \
171 static void dpaa2initfn_ ##nm(void) \
172 {\
173         (dpaa2_drv).driver.name = RTE_STR(nm);\
174         rte_fslmc_driver_register(&dpaa2_drv); \
175 } \
176 RTE_PMD_EXPORT_NAME(nm, __COUNTER__)
177
178 /**
179  * Register a DPAA2 MC Object driver.
180  *
181  * @param mc_object
182  *   A pointer to a rte_dpaa_object structure describing the mc object
183  *   to be registered.
184  */
185 void rte_fslmc_object_register(struct rte_dpaa2_object *object);
186
187 /** Helper for DPAA2 object registration */
188 #define RTE_PMD_REGISTER_DPAA2_OBJECT(nm, dpaa2_obj) \
189 RTE_INIT(dpaa2objinitfn_ ##nm); \
190 static void dpaa2objinitfn_ ##nm(void) \
191 {\
192         (dpaa2_obj).name = RTE_STR(nm);\
193         rte_fslmc_object_register(&dpaa2_obj); \
194 } \
195 RTE_PMD_EXPORT_NAME(nm, __COUNTER__)
196
197 #ifdef __cplusplus
198 }
199 #endif
200
201 #endif /* _RTE_FSLMC_H_ */