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