e60d6eba0bf47c84075b6e180dcf528d1bd22a7b
[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
54 #include <rte_debug.h>
55 #include <rte_interrupts.h>
56 #include <rte_dev.h>
57 #include <rte_bus.h>
58
59 struct rte_dpaa2_driver;
60
61 /* DPAA2 Device and Driver lists for FSLMC bus */
62 TAILQ_HEAD(rte_fslmc_device_list, rte_dpaa2_device);
63 TAILQ_HEAD(rte_fslmc_driver_list, rte_dpaa2_driver);
64
65 extern struct rte_fslmc_bus rte_fslmc_bus;
66
67 /**
68  * A structure describing a DPAA2 device.
69  */
70 struct rte_dpaa2_device {
71         TAILQ_ENTRY(rte_dpaa2_device) next; /**< Next probed DPAA2 device. */
72         struct rte_device device;           /**< Inherit core device */
73         union {
74                 struct rte_eth_dev *eth_dev;        /**< ethernet device */
75                 struct rte_cryptodev *cryptodev;    /**< Crypto Device */
76         };
77         uint16_t dev_type;                  /**< Device Type */
78         uint16_t object_id;             /**< DPAA2 Object ID */
79         struct rte_intr_handle intr_handle; /**< Interrupt handle */
80         struct rte_dpaa2_driver *driver;    /**< Associated driver */
81         char name[32];          /**< DPAA2 Object name*/
82 };
83
84 typedef int (*rte_dpaa2_probe_t)(struct rte_dpaa2_driver *dpaa2_drv,
85                                  struct rte_dpaa2_device *dpaa2_dev);
86 typedef int (*rte_dpaa2_remove_t)(struct rte_dpaa2_device *dpaa2_dev);
87
88 /**
89  * A structure describing a DPAA2 driver.
90  */
91 struct rte_dpaa2_driver {
92         TAILQ_ENTRY(rte_dpaa2_driver) next; /**< Next in list. */
93         struct rte_driver driver;           /**< Inherit core driver. */
94         struct rte_fslmc_bus *fslmc_bus;    /**< FSLMC bus reference */
95         uint32_t drv_flags;                 /**< Flags for controlling device.*/
96         uint16_t drv_type;                  /**< Driver Type */
97         rte_dpaa2_probe_t probe;
98         rte_dpaa2_remove_t remove;
99 };
100
101 /*
102  * FSLMC bus
103  */
104 struct rte_fslmc_bus {
105         struct rte_bus bus;     /**< Generic Bus object */
106         struct rte_fslmc_device_list device_list;
107                                 /**< FSLMC DPAA2 Device list */
108         struct rte_fslmc_driver_list driver_list;
109                                 /**< FSLMC DPAA2 Driver list */
110         int device_count;
111                                 /**< Optional: Count of devices on bus */
112 };
113
114 /**
115  * Register a DPAA2 driver.
116  *
117  * @param driver
118  *   A pointer to a rte_dpaa2_driver structure describing the driver
119  *   to be registered.
120  */
121 void rte_fslmc_driver_register(struct rte_dpaa2_driver *driver);
122
123 /**
124  * Unregister a DPAA2 driver.
125  *
126  * @param driver
127  *   A pointer to a rte_dpaa2_driver structure describing the driver
128  *   to be unregistered.
129  */
130 void rte_fslmc_driver_unregister(struct rte_dpaa2_driver *driver);
131
132 /** Helper for DPAA2 device registration from driver (eth, crypto) instance */
133 #define RTE_PMD_REGISTER_DPAA2(nm, dpaa2_drv) \
134 RTE_INIT(dpaa2initfn_ ##nm); \
135 static void dpaa2initfn_ ##nm(void) \
136 {\
137         (dpaa2_drv).driver.name = RTE_STR(nm);\
138         rte_fslmc_driver_register(&dpaa2_drv); \
139 } \
140 RTE_PMD_EXPORT_NAME(nm, __COUNTER__)
141
142 #ifdef __cplusplus
143 }
144 #endif
145
146 #endif /* _RTE_FSLMC_H_ */