bus/fslmc: support scanned device count
[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
40 /** Device driver supports link state interrupt */
41 #define RTE_DPAA2_DRV_INTR_LSC  0x0008
42
43 /** Device driver supports IOVA as VA */
44 #define RTE_DPAA2_DRV_IOVA_AS_VA 0X0040
45
46 struct rte_dpaa2_driver;
47
48 /* DPAA2 Device and Driver lists for FSLMC bus */
49 TAILQ_HEAD(rte_fslmc_device_list, rte_dpaa2_device);
50 TAILQ_HEAD(rte_fslmc_driver_list, rte_dpaa2_driver);
51
52 extern struct rte_fslmc_bus rte_fslmc_bus;
53
54 enum rte_dpaa2_dev_type {
55         /* Devices backed by DPDK driver */
56         DPAA2_ETH,      /**< DPNI type device*/
57         DPAA2_CRYPTO,   /**< DPSECI type device */
58         DPAA2_CON,      /**< DPCONC type device */
59         /* Devices not backed by a DPDK driver: DPIO, DPBP, DPCI, DPMCP */
60         DPAA2_BPOOL,    /**< DPBP type device */
61         DPAA2_IO,       /**< DPIO type device */
62         DPAA2_CI,       /**< DPCI type device */
63         DPAA2_MPORTAL,  /**< DPMCP type device */
64         /* Unknown device placeholder */
65         DPAA2_UNKNOWN,
66         DPAA2_DEVTYPE_MAX,
67 };
68
69 TAILQ_HEAD(rte_dpaa2_object_list, rte_dpaa2_object);
70
71 typedef int (*rte_dpaa2_obj_create_t)(int vdev_fd,
72                                       struct vfio_device_info *obj_info,
73                                       int object_id);
74
75 /**
76  * A structure describing a DPAA2 object.
77  */
78 struct rte_dpaa2_object {
79         TAILQ_ENTRY(rte_dpaa2_object) next; /**< Next in list. */
80         const char *name;                   /**< Name of Object. */
81         enum rte_dpaa2_dev_type dev_type;   /**< Type of device */
82         rte_dpaa2_obj_create_t create;
83 };
84
85 /**
86  * A structure describing a DPAA2 device.
87  */
88 struct rte_dpaa2_device {
89         TAILQ_ENTRY(rte_dpaa2_device) next; /**< Next probed DPAA2 device. */
90         struct rte_device device;           /**< Inherit core device */
91         union {
92                 struct rte_eth_dev *eth_dev;        /**< ethernet device */
93                 struct rte_cryptodev *cryptodev;    /**< Crypto Device */
94         };
95         enum rte_dpaa2_dev_type dev_type;   /**< Device Type */
96         uint16_t object_id;                 /**< DPAA2 Object ID */
97         struct rte_intr_handle intr_handle; /**< Interrupt handle */
98         struct rte_dpaa2_driver *driver;    /**< Associated driver */
99         char name[FSLMC_OBJECT_MAX_LEN];    /**< DPAA2 Object name*/
100 };
101
102 typedef int (*rte_dpaa2_probe_t)(struct rte_dpaa2_driver *dpaa2_drv,
103                                  struct rte_dpaa2_device *dpaa2_dev);
104 typedef int (*rte_dpaa2_remove_t)(struct rte_dpaa2_device *dpaa2_dev);
105
106 /**
107  * A structure describing a DPAA2 driver.
108  */
109 struct rte_dpaa2_driver {
110         TAILQ_ENTRY(rte_dpaa2_driver) next; /**< Next in list. */
111         struct rte_driver driver;           /**< Inherit core driver. */
112         struct rte_fslmc_bus *fslmc_bus;    /**< FSLMC bus reference */
113         uint32_t drv_flags;                 /**< Flags for controlling device.*/
114         enum rte_dpaa2_dev_type drv_type;   /**< Driver Type */
115         rte_dpaa2_probe_t probe;
116         rte_dpaa2_remove_t remove;
117 };
118
119 /*
120  * FSLMC bus
121  */
122 struct rte_fslmc_bus {
123         struct rte_bus bus;     /**< Generic Bus object */
124         struct rte_fslmc_device_list device_list;
125                                 /**< FSLMC DPAA2 Device list */
126         struct rte_fslmc_driver_list driver_list;
127                                 /**< FSLMC DPAA2 Driver list */
128         int device_count[DPAA2_DEVTYPE_MAX];
129                                 /**< Count of all devices scanned */
130 };
131
132 /**
133  * Register a DPAA2 driver.
134  *
135  * @param driver
136  *   A pointer to a rte_dpaa2_driver structure describing the driver
137  *   to be registered.
138  */
139 void rte_fslmc_driver_register(struct rte_dpaa2_driver *driver);
140
141 /**
142  * Unregister a DPAA2 driver.
143  *
144  * @param driver
145  *   A pointer to a rte_dpaa2_driver structure describing the driver
146  *   to be unregistered.
147  */
148 void rte_fslmc_driver_unregister(struct rte_dpaa2_driver *driver);
149
150 /** Helper for DPAA2 device registration from driver (eth, crypto) instance */
151 #define RTE_PMD_REGISTER_DPAA2(nm, dpaa2_drv) \
152 RTE_INIT(dpaa2initfn_ ##nm); \
153 static void dpaa2initfn_ ##nm(void) \
154 {\
155         (dpaa2_drv).driver.name = RTE_STR(nm);\
156         rte_fslmc_driver_register(&dpaa2_drv); \
157 } \
158 RTE_PMD_EXPORT_NAME(nm, __COUNTER__)
159
160 /**
161  * Register a DPAA2 MC Object driver.
162  *
163  * @param mc_object
164  *   A pointer to a rte_dpaa_object structure describing the mc object
165  *   to be registered.
166  */
167 void rte_fslmc_object_register(struct rte_dpaa2_object *object);
168
169 /**
170  * Count of a particular type of DPAA2 device scanned on the bus.
171  *
172  * @param dev_type
173  *   Type of device as rte_dpaa2_dev_type enumerator
174  * @return
175  *   >=0 for count; 0 indicates either no device of the said type scanned or
176  *   invalid device type.
177  */
178 uint32_t rte_fslmc_get_device_count(enum rte_dpaa2_dev_type device_type);
179
180 /** Helper for DPAA2 object registration */
181 #define RTE_PMD_REGISTER_DPAA2_OBJECT(nm, dpaa2_obj) \
182 RTE_INIT(dpaa2objinitfn_ ##nm); \
183 static void dpaa2objinitfn_ ##nm(void) \
184 {\
185         (dpaa2_obj).name = RTE_STR(nm);\
186         rte_fslmc_object_register(&dpaa2_obj); \
187 } \
188 RTE_PMD_EXPORT_NAME(nm, __COUNTER__)
189
190 #ifdef __cplusplus
191 }
192 #endif
193
194 #endif /* _RTE_FSLMC_H_ */