New upstream version 18.08
[deb_dpdk.git] / drivers / bus / dpaa / rte_dpaa_bus.h
1 /* SPDX-License-Identifier: BSD-3-Clause
2  *
3  *   Copyright 2017 NXP
4  *
5  */
6 #ifndef __RTE_DPAA_BUS_H__
7 #define __RTE_DPAA_BUS_H__
8
9 #include <rte_bus.h>
10 #include <rte_mempool.h>
11
12 #include <fsl_usd.h>
13 #include <fsl_qman.h>
14 #include <fsl_bman.h>
15 #include <of.h>
16 #include <netcfg.h>
17
18 #define DPAA_MEMPOOL_OPS_NAME   "dpaa"
19
20 #define DEV_TO_DPAA_DEVICE(ptr) \
21                 container_of(ptr, struct rte_dpaa_device, device)
22
23 /* DPAA SoC identifier; If this is not available, it can be concluded
24  * that board is non-DPAA. Single slot is currently supported.
25  */
26 #define DPAA_SOC_ID_FILE        "/sys/devices/soc0/soc_id"
27
28 #define SVR_LS1043A_FAMILY      0x87920000
29 #define SVR_LS1046A_FAMILY      0x87070000
30 #define SVR_MASK                0xffff0000
31
32 extern unsigned int dpaa_svr_family;
33
34 extern RTE_DEFINE_PER_LCORE(bool, dpaa_io);
35
36 struct rte_dpaa_device;
37 struct rte_dpaa_driver;
38
39 /* DPAA Device and Driver lists for DPAA bus */
40 TAILQ_HEAD(rte_dpaa_device_list, rte_dpaa_device);
41 TAILQ_HEAD(rte_dpaa_driver_list, rte_dpaa_driver);
42
43 /* Configuration variables exported from DPAA bus */
44 extern struct netcfg_info *dpaa_netcfg;
45
46 enum rte_dpaa_type {
47         FSL_DPAA_ETH = 1,
48         FSL_DPAA_CRYPTO,
49 };
50
51 struct rte_dpaa_bus {
52         struct rte_bus bus;
53         struct rte_dpaa_device_list device_list;
54         struct rte_dpaa_driver_list driver_list;
55         int device_count;
56 };
57
58 struct dpaa_device_id {
59         uint8_t fman_id; /**< Fman interface ID, for ETH type device */
60         uint8_t mac_id; /**< Fman MAC interface ID, for ETH type device */
61         uint16_t dev_id; /**< Device Identifier from DPDK */
62 };
63
64 struct rte_dpaa_device {
65         TAILQ_ENTRY(rte_dpaa_device) next;
66         struct rte_device device;
67         union {
68                 struct rte_eth_dev *eth_dev;
69                 struct rte_cryptodev *crypto_dev;
70         };
71         struct rte_dpaa_driver *driver;
72         struct dpaa_device_id id;
73         enum rte_dpaa_type device_type; /**< Ethernet or crypto type device */
74         char name[RTE_ETH_NAME_MAX_LEN];
75 };
76
77 typedef int (*rte_dpaa_probe_t)(struct rte_dpaa_driver *dpaa_drv,
78                                 struct rte_dpaa_device *dpaa_dev);
79 typedef int (*rte_dpaa_remove_t)(struct rte_dpaa_device *dpaa_dev);
80
81 struct rte_dpaa_driver {
82         TAILQ_ENTRY(rte_dpaa_driver) next;
83         struct rte_driver driver;
84         struct rte_dpaa_bus *dpaa_bus;
85         enum rte_dpaa_type drv_type;
86         rte_dpaa_probe_t probe;
87         rte_dpaa_remove_t remove;
88 };
89
90 struct dpaa_portal {
91         uint32_t bman_idx; /**< BMAN Portal ID*/
92         uint32_t qman_idx; /**< QMAN Portal ID*/
93         uint64_t tid;/**< Parent Thread id for this portal */
94 };
95
96 /* Various structures representing contiguous memory maps */
97 struct dpaa_memseg {
98         TAILQ_ENTRY(dpaa_memseg) next;
99         char *vaddr;
100         rte_iova_t iova;
101         size_t len;
102 };
103
104 TAILQ_HEAD(dpaa_memseg_list, dpaa_memseg);
105 extern struct dpaa_memseg_list rte_dpaa_memsegs;
106
107 /* Either iterate over the list of internal memseg references or fallback to
108  * EAL memseg based iova2virt.
109  */
110 static inline void *rte_dpaa_mem_ptov(phys_addr_t paddr)
111 {
112         struct dpaa_memseg *ms;
113
114         /* Check if the address is already part of the memseg list internally
115          * maintained by the dpaa driver.
116          */
117         TAILQ_FOREACH(ms, &rte_dpaa_memsegs, next) {
118                 if (paddr >= ms->iova && paddr <
119                         ms->iova + ms->len)
120                         return RTE_PTR_ADD(ms->vaddr, (uintptr_t)(paddr - ms->iova));
121         }
122
123         /* If not, Fallback to full memseg list searching */
124         return rte_mem_iova2virt(paddr);
125 }
126
127 /**
128  * Register a DPAA driver.
129  *
130  * @param driver
131  *   A pointer to a rte_dpaa_driver structure describing the driver
132  *   to be registered.
133  */
134 void rte_dpaa_driver_register(struct rte_dpaa_driver *driver);
135
136 /**
137  * Unregister a DPAA driver.
138  *
139  * @param driver
140  *      A pointer to a rte_dpaa_driver structure describing the driver
141  *      to be unregistered.
142  */
143 void rte_dpaa_driver_unregister(struct rte_dpaa_driver *driver);
144
145 /**
146  * Initialize a DPAA portal
147  *
148  * @param arg
149  *      Per thread ID
150  *
151  * @return
152  *      0 in case of success, error otherwise
153  */
154 int rte_dpaa_portal_init(void *arg);
155
156 int rte_dpaa_portal_fq_init(void *arg, struct qman_fq *fq);
157
158 int rte_dpaa_portal_fq_close(struct qman_fq *fq);
159
160 /**
161  * Cleanup a DPAA Portal
162  */
163 void dpaa_portal_finish(void *arg);
164
165 /** Helper for DPAA device registration from driver (eth, crypto) instance */
166 #define RTE_PMD_REGISTER_DPAA(nm, dpaa_drv) \
167 RTE_INIT(dpaainitfn_ ##nm) \
168 {\
169         (dpaa_drv).driver.name = RTE_STR(nm);\
170         rte_dpaa_driver_register(&dpaa_drv); \
171 } \
172 RTE_PMD_EXPORT_NAME(nm, __COUNTER__)
173
174 /* Create storage for dqrr entries per lcore */
175 #define DPAA_PORTAL_DEQUEUE_DEPTH       16
176 struct dpaa_portal_dqrr {
177         void *mbuf[DPAA_PORTAL_DEQUEUE_DEPTH];
178         uint64_t dqrr_held;
179         uint8_t dqrr_size;
180 };
181
182 RTE_DECLARE_PER_LCORE(struct dpaa_portal_dqrr, held_bufs);
183
184 #define DPAA_PER_LCORE_DQRR_SIZE       RTE_PER_LCORE(held_bufs).dqrr_size
185 #define DPAA_PER_LCORE_DQRR_HELD       RTE_PER_LCORE(held_bufs).dqrr_held
186 #define DPAA_PER_LCORE_DQRR_MBUF(i)    RTE_PER_LCORE(held_bufs).mbuf[i]
187
188 #ifdef __cplusplus
189 }
190 #endif
191
192 #endif /* __RTE_DPAA_BUS_H__ */