New upstream version 17.11.1
[deb_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 #include <fsl_usd.h>
39 #include <fsl_qman.h>
40 #include <fsl_bman.h>
41 #include <of.h>
42 #include <netcfg.h>
43
44 #define FSL_DPAA_BUS_NAME       "FSL_DPAA_BUS"
45
46 #define DEV_TO_DPAA_DEVICE(ptr) \
47                 container_of(ptr, struct rte_dpaa_device, device)
48
49 struct rte_dpaa_device;
50 struct rte_dpaa_driver;
51
52 /* DPAA Device and Driver lists for DPAA bus */
53 TAILQ_HEAD(rte_dpaa_device_list, rte_dpaa_device);
54 TAILQ_HEAD(rte_dpaa_driver_list, rte_dpaa_driver);
55
56 /* Configuration variables exported from DPAA bus */
57 extern struct netcfg_info *dpaa_netcfg;
58
59 enum rte_dpaa_type {
60         FSL_DPAA_ETH = 1,
61         FSL_DPAA_CRYPTO,
62 };
63
64 struct rte_dpaa_bus {
65         struct rte_bus bus;
66         struct rte_dpaa_device_list device_list;
67         struct rte_dpaa_driver_list driver_list;
68         int device_count;
69 };
70
71 struct dpaa_device_id {
72         uint8_t fman_id; /**< Fman interface ID, for ETH type device */
73         uint8_t mac_id; /**< Fman MAC interface ID, for ETH type device */
74         uint16_t dev_id; /**< Device Identifier from DPDK */
75 };
76
77 struct rte_dpaa_device {
78         TAILQ_ENTRY(rte_dpaa_device) next;
79         struct rte_device device;
80         union {
81                 struct rte_eth_dev *eth_dev;
82                 struct rte_cryptodev *crypto_dev;
83         };
84         struct rte_dpaa_driver *driver;
85         struct dpaa_device_id id;
86         enum rte_dpaa_type device_type; /**< Ethernet or crypto type device */
87         char name[RTE_ETH_NAME_MAX_LEN];
88 };
89
90 typedef int (*rte_dpaa_probe_t)(struct rte_dpaa_driver *dpaa_drv,
91                                 struct rte_dpaa_device *dpaa_dev);
92 typedef int (*rte_dpaa_remove_t)(struct rte_dpaa_device *dpaa_dev);
93
94 struct rte_dpaa_driver {
95         TAILQ_ENTRY(rte_dpaa_driver) next;
96         struct rte_driver driver;
97         struct rte_dpaa_bus *dpaa_bus;
98         enum rte_dpaa_type drv_type;
99         rte_dpaa_probe_t probe;
100         rte_dpaa_remove_t remove;
101 };
102
103 struct dpaa_portal {
104         uint32_t bman_idx; /**< BMAN Portal ID*/
105         uint32_t qman_idx; /**< QMAN Portal ID*/
106         uint64_t tid;/**< Parent Thread id for this portal */
107 };
108
109 /* TODO - this is costly, need to write a fast coversion routine */
110 static inline void *rte_dpaa_mem_ptov(phys_addr_t paddr)
111 {
112         const struct rte_memseg *memseg = rte_eal_get_physmem_layout();
113         int i;
114
115         for (i = 0; i < RTE_MAX_MEMSEG && memseg[i].addr != NULL; i++) {
116                 if (paddr >= memseg[i].iova && paddr <
117                         memseg[i].iova + memseg[i].len)
118                         return (uint8_t *)(memseg[i].addr) +
119                                (paddr - memseg[i].iova);
120         }
121
122         return NULL;
123 }
124
125 /**
126  * Register a DPAA driver.
127  *
128  * @param driver
129  *   A pointer to a rte_dpaa_driver structure describing the driver
130  *   to be registered.
131  */
132 void rte_dpaa_driver_register(struct rte_dpaa_driver *driver);
133
134 /**
135  * Unregister a DPAA driver.
136  *
137  * @param driver
138  *      A pointer to a rte_dpaa_driver structure describing the driver
139  *      to be unregistered.
140  */
141 void rte_dpaa_driver_unregister(struct rte_dpaa_driver *driver);
142
143 /**
144  * Initialize a DPAA portal
145  *
146  * @param arg
147  *      Per thread ID
148  *
149  * @return
150  *      0 in case of success, error otherwise
151  */
152 int rte_dpaa_portal_init(void *arg);
153
154 /**
155  * Cleanup a DPAA Portal
156  */
157 void dpaa_portal_finish(void *arg);
158
159 /** Helper for DPAA device registration from driver (eth, crypto) instance */
160 #define RTE_PMD_REGISTER_DPAA(nm, dpaa_drv) \
161 RTE_INIT(dpaainitfn_ ##nm); \
162 static void dpaainitfn_ ##nm(void) \
163 {\
164         (dpaa_drv).driver.name = RTE_STR(nm);\
165         rte_dpaa_driver_register(&dpaa_drv); \
166 } \
167 RTE_PMD_EXPORT_NAME(nm, __COUNTER__)
168
169 #ifdef __cplusplus
170 }
171 #endif
172
173 #endif /* __RTE_DPAA_BUS_H__ */