New upstream version 18.02
[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 FSL_DPAA_BUS_NAME       "FSL_DPAA_BUS"
19
20 #define DPAA_MEMPOOL_OPS_NAME   "dpaa"
21
22 #define DEV_TO_DPAA_DEVICE(ptr) \
23                 container_of(ptr, struct rte_dpaa_device, device)
24
25 /* DPAA SoC identifier; If this is not available, it can be concluded
26  * that board is non-DPAA. Single slot is currently supported.
27  */
28 #define DPAA_SOC_ID_FILE        "/sys/devices/soc0/soc_id"
29
30 #define SVR_LS1043A_FAMILY      0x87920000
31 #define SVR_LS1046A_FAMILY      0x87070000
32 #define SVR_MASK                0xffff0000
33
34 extern unsigned int dpaa_svr_family;
35
36 extern RTE_DEFINE_PER_LCORE(bool, dpaa_io);
37
38 struct rte_dpaa_device;
39 struct rte_dpaa_driver;
40
41 /* DPAA Device and Driver lists for DPAA bus */
42 TAILQ_HEAD(rte_dpaa_device_list, rte_dpaa_device);
43 TAILQ_HEAD(rte_dpaa_driver_list, rte_dpaa_driver);
44
45 /* Configuration variables exported from DPAA bus */
46 extern struct netcfg_info *dpaa_netcfg;
47
48 enum rte_dpaa_type {
49         FSL_DPAA_ETH = 1,
50         FSL_DPAA_CRYPTO,
51 };
52
53 struct rte_dpaa_bus {
54         struct rte_bus bus;
55         struct rte_dpaa_device_list device_list;
56         struct rte_dpaa_driver_list driver_list;
57         int device_count;
58 };
59
60 struct dpaa_device_id {
61         uint8_t fman_id; /**< Fman interface ID, for ETH type device */
62         uint8_t mac_id; /**< Fman MAC interface ID, for ETH type device */
63         uint16_t dev_id; /**< Device Identifier from DPDK */
64 };
65
66 struct rte_dpaa_device {
67         TAILQ_ENTRY(rte_dpaa_device) next;
68         struct rte_device device;
69         union {
70                 struct rte_eth_dev *eth_dev;
71                 struct rte_cryptodev *crypto_dev;
72         };
73         struct rte_dpaa_driver *driver;
74         struct dpaa_device_id id;
75         enum rte_dpaa_type device_type; /**< Ethernet or crypto type device */
76         char name[RTE_ETH_NAME_MAX_LEN];
77 };
78
79 typedef int (*rte_dpaa_probe_t)(struct rte_dpaa_driver *dpaa_drv,
80                                 struct rte_dpaa_device *dpaa_dev);
81 typedef int (*rte_dpaa_remove_t)(struct rte_dpaa_device *dpaa_dev);
82
83 struct rte_dpaa_driver {
84         TAILQ_ENTRY(rte_dpaa_driver) next;
85         struct rte_driver driver;
86         struct rte_dpaa_bus *dpaa_bus;
87         enum rte_dpaa_type drv_type;
88         rte_dpaa_probe_t probe;
89         rte_dpaa_remove_t remove;
90 };
91
92 struct dpaa_portal {
93         uint32_t bman_idx; /**< BMAN Portal ID*/
94         uint32_t qman_idx; /**< QMAN Portal ID*/
95         uint64_t tid;/**< Parent Thread id for this portal */
96 };
97
98 /* TODO - this is costly, need to write a fast coversion routine */
99 static inline void *rte_dpaa_mem_ptov(phys_addr_t paddr)
100 {
101         const struct rte_memseg *memseg = rte_eal_get_physmem_layout();
102         int i;
103
104         for (i = 0; i < RTE_MAX_MEMSEG && memseg[i].addr != NULL; i++) {
105                 if (paddr >= memseg[i].iova && paddr <
106                         memseg[i].iova + memseg[i].len)
107                         return (uint8_t *)(memseg[i].addr) +
108                                (paddr - memseg[i].iova);
109         }
110
111         return NULL;
112 }
113
114 /**
115  * Register a DPAA driver.
116  *
117  * @param driver
118  *   A pointer to a rte_dpaa_driver structure describing the driver
119  *   to be registered.
120  */
121 void rte_dpaa_driver_register(struct rte_dpaa_driver *driver);
122
123 /**
124  * Unregister a DPAA driver.
125  *
126  * @param driver
127  *      A pointer to a rte_dpaa_driver structure describing the driver
128  *      to be unregistered.
129  */
130 void rte_dpaa_driver_unregister(struct rte_dpaa_driver *driver);
131
132 /**
133  * Initialize a DPAA portal
134  *
135  * @param arg
136  *      Per thread ID
137  *
138  * @return
139  *      0 in case of success, error otherwise
140  */
141 int rte_dpaa_portal_init(void *arg);
142
143 int rte_dpaa_portal_fq_init(void *arg, struct qman_fq *fq);
144
145 int rte_dpaa_portal_fq_close(struct qman_fq *fq);
146
147 /**
148  * Cleanup a DPAA Portal
149  */
150 void dpaa_portal_finish(void *arg);
151
152 /** Helper for DPAA device registration from driver (eth, crypto) instance */
153 #define RTE_PMD_REGISTER_DPAA(nm, dpaa_drv) \
154 RTE_INIT(dpaainitfn_ ##nm); \
155 static void dpaainitfn_ ##nm(void) \
156 {\
157         (dpaa_drv).driver.name = RTE_STR(nm);\
158         rte_dpaa_driver_register(&dpaa_drv); \
159 } \
160 RTE_PMD_EXPORT_NAME(nm, __COUNTER__)
161
162 /* Create storage for dqrr entries per lcore */
163 #define DPAA_PORTAL_DEQUEUE_DEPTH       16
164 struct dpaa_portal_dqrr {
165         void *mbuf[DPAA_PORTAL_DEQUEUE_DEPTH];
166         uint64_t dqrr_held;
167         uint8_t dqrr_size;
168 };
169
170 RTE_DECLARE_PER_LCORE(struct dpaa_portal_dqrr, held_bufs);
171
172 #define DPAA_PER_LCORE_DQRR_SIZE       RTE_PER_LCORE(held_bufs).dqrr_size
173 #define DPAA_PER_LCORE_DQRR_HELD       RTE_PER_LCORE(held_bufs).dqrr_held
174 #define DPAA_PER_LCORE_DQRR_MBUF(i)    RTE_PER_LCORE(held_bufs).mbuf[i]
175
176 #ifdef __cplusplus
177 }
178 #endif
179
180 #endif /* __RTE_DPAA_BUS_H__ */