bus/dpaa: introduce NXP DPAA bus driver skeleton
[dpdk.git] / drivers / bus / dpaa / rte_dpaa_bus.h
1 /*-
2  *   BSD LICENSE
3  *
4  *   Copyright 2017 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 #ifndef __RTE_DPAA_BUS_H__
33 #define __RTE_DPAA_BUS_H__
34
35 #include <rte_bus.h>
36 #include <rte_mempool.h>
37
38 #define FSL_DPAA_BUS_NAME       "FSL_DPAA_BUS"
39
40 #define DEV_TO_DPAA_DEVICE(ptr) \
41                 container_of(ptr, struct rte_dpaa_device, device)
42
43 struct rte_dpaa_device;
44 struct rte_dpaa_driver;
45
46 /* DPAA Device and Driver lists for DPAA bus */
47 TAILQ_HEAD(rte_dpaa_device_list, rte_dpaa_device);
48 TAILQ_HEAD(rte_dpaa_driver_list, rte_dpaa_driver);
49
50 enum rte_dpaa_type {
51         FSL_DPAA_ETH = 1,
52         FSL_DPAA_CRYPTO,
53 };
54
55 struct rte_dpaa_bus {
56         struct rte_bus bus;
57         struct rte_dpaa_device_list device_list;
58         struct rte_dpaa_driver_list driver_list;
59         int device_count;
60 };
61
62 struct dpaa_device_id {
63         uint8_t fman_id; /**< Fman interface ID, for ETH type device */
64         uint8_t mac_id; /**< Fman MAC interface ID, for ETH type device */
65         uint16_t dev_id; /**< Device Identifier from DPDK */
66 };
67
68 struct rte_dpaa_device {
69         TAILQ_ENTRY(rte_dpaa_device) next;
70         struct rte_device device;
71         union {
72                 struct rte_eth_dev *eth_dev;
73                 struct rte_cryptodev *crypto_dev;
74         };
75         struct rte_dpaa_driver *driver;
76         struct dpaa_device_id id;
77         enum rte_dpaa_type device_type; /**< Ethernet or crypto type device */
78         char name[RTE_ETH_NAME_MAX_LEN];
79 };
80
81 typedef int (*rte_dpaa_probe_t)(struct rte_dpaa_driver *dpaa_drv,
82                                 struct rte_dpaa_device *dpaa_dev);
83 typedef int (*rte_dpaa_remove_t)(struct rte_dpaa_device *dpaa_dev);
84
85 struct rte_dpaa_driver {
86         TAILQ_ENTRY(rte_dpaa_driver) next;
87         struct rte_driver driver;
88         struct rte_dpaa_bus *dpaa_bus;
89         enum rte_dpaa_type drv_type;
90         rte_dpaa_probe_t probe;
91         rte_dpaa_remove_t remove;
92 };
93
94 struct dpaa_portal {
95         uint32_t bman_idx; /**< BMAN Portal ID*/
96         uint32_t qman_idx; /**< QMAN Portal ID*/
97         uint64_t tid;/**< Parent Thread id for this portal */
98 };
99
100 /* TODO - this is costly, need to write a fast coversion routine */
101 static inline void *rte_dpaa_mem_ptov(phys_addr_t paddr)
102 {
103         const struct rte_memseg *memseg = rte_eal_get_physmem_layout();
104         int i;
105
106         for (i = 0; i < RTE_MAX_MEMSEG && memseg[i].addr != NULL; i++) {
107                 if (paddr >= memseg[i].phys_addr && paddr <
108                         memseg[i].phys_addr + memseg[i].len)
109                         return (uint8_t *)(memseg[i].addr) +
110                                (paddr - memseg[i].phys_addr);
111         }
112
113         return NULL;
114 }
115
116 /**
117  * Register a DPAA driver.
118  *
119  * @param driver
120  *   A pointer to a rte_dpaa_driver structure describing the driver
121  *   to be registered.
122  */
123 void rte_dpaa_driver_register(struct rte_dpaa_driver *driver);
124
125 /**
126  * Unregister a DPAA driver.
127  *
128  * @param driver
129  *      A pointer to a rte_dpaa_driver structure describing the driver
130  *      to be unregistered.
131  */
132 void rte_dpaa_driver_unregister(struct rte_dpaa_driver *driver);
133
134 /** Helper for DPAA device registration from driver (eth, crypto) instance */
135 #define RTE_PMD_REGISTER_DPAA(nm, dpaa_drv) \
136 RTE_INIT(dpaainitfn_ ##nm); \
137 static void dpaainitfn_ ##nm(void) \
138 {\
139         (dpaa_drv).driver.name = RTE_STR(nm);\
140         rte_dpaa_driver_register(&dpaa_drv); \
141 } \
142 RTE_PMD_EXPORT_NAME(nm, __COUNTER__)
143
144 #ifdef __cplusplus
145 }
146 #endif
147
148 #endif /* __RTE_DPAA_BUS_H__ */