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