mempool: introduce helpers for populate and required size
[dpdk.git] / drivers / bus / ifpga / rte_bus_ifpga.h
1 /* SPDX-License-Identifier: BSD-3-Clause
2  * Copyright(c) 2010-2018 Intel Corporation
3  */
4
5 #ifndef _RTE_BUS_IFPGA_H_
6 #define _RTE_BUS_IFPGA_H_
7
8 /**
9  * @file
10  *
11  * RTE Intel FPGA Bus Interface
12  */
13
14 #ifdef __cplusplus
15 extern "C" {
16 #endif /* __cplusplus */
17
18 #include <rte_bus.h>
19 #include <rte_pci.h>
20 #include <rte_spinlock.h>
21
22 /** Name of Intel FPGA Bus */
23 #define IFPGA_BUS_NAME ifpga
24
25 /* Forward declarations */
26 struct rte_afu_device;
27 struct rte_afu_driver;
28
29 /** Double linked list of Intel FPGA AFU device. */
30 TAILQ_HEAD(ifpga_afu_dev_list, rte_afu_device);
31 /** Double linked list of Intel FPGA AFU device drivers. */
32 TAILQ_HEAD(ifpga_afu_drv_list, rte_afu_driver);
33
34 #define IFPGA_BUS_BITSTREAM_PATH_MAX_LEN 256
35
36 struct rte_afu_uuid {
37         uint64_t uuid_low;
38         uint64_t uuid_high;
39 } __attribute__ ((packed));
40
41 #define IFPGA_BUS_DEV_PORT_MAX 4
42
43 /**
44  * A structure describing an ID for a AFU driver. Each driver provides a
45  * table of these IDs for each device that it supports.
46  */
47 struct rte_afu_id {
48         struct rte_afu_uuid uuid;
49         int      port; /**< port number */
50 } __attribute__ ((packed));
51
52 /**
53  * A structure PR (Partial Reconfiguration) configuration AFU driver.
54  */
55
56 struct rte_afu_pr_conf {
57         struct rte_afu_id afu_id;
58         int pr_enable;
59         char bs_path[IFPGA_BUS_BITSTREAM_PATH_MAX_LEN];
60 };
61
62 #define AFU_PRI_STR_SIZE (PCI_PRI_STR_SIZE + 8)
63
64 struct rte_afu_shared {
65         rte_spinlock_t lock;
66         void *data;
67 };
68
69 /**
70  * A structure describing a AFU device.
71  */
72 struct rte_afu_device {
73         TAILQ_ENTRY(rte_afu_device) next;       /**< Next in device list. */
74         struct rte_device device;               /**< Inherit core device */
75         struct rte_rawdev *rawdev;    /**< Point Rawdev */
76         struct rte_afu_id id;                   /**< AFU id within FPGA. */
77         uint32_t num_region;   /**< number of regions found */
78         struct rte_mem_resource mem_resource[PCI_MAX_RESOURCE];
79                                                 /**< AFU Memory Resource */
80         struct rte_afu_shared shared;
81         struct rte_intr_handle intr_handle;     /**< Interrupt handle */
82         struct rte_afu_driver *driver;          /**< Associated driver */
83         char path[IFPGA_BUS_BITSTREAM_PATH_MAX_LEN];
84 } __attribute__ ((packed));
85
86 /**
87  * @internal
88  * Helper macro for drivers that need to convert to struct rte_afu_device.
89  */
90 #define RTE_DEV_TO_AFU(ptr) \
91         container_of(ptr, struct rte_afu_device, device)
92
93 /**
94  * Initialization function for the driver called during FPGA BUS probing.
95  */
96 typedef int (afu_probe_t)(struct rte_afu_device *);
97
98 /**
99  * Uninitialization function for the driver called during hotplugging.
100  */
101 typedef int (afu_remove_t)(struct rte_afu_device *);
102
103 /**
104  * A structure describing a AFU device.
105  */
106 struct rte_afu_driver {
107         TAILQ_ENTRY(rte_afu_driver) next;       /**< Next afu driver. */
108         struct rte_driver driver;               /**< Inherit core driver. */
109         afu_probe_t *probe;                     /**< Device Probe function. */
110         afu_remove_t *remove;                   /**< Device Remove function. */
111         const struct rte_afu_uuid *id_table;    /**< AFU uuid within FPGA. */
112 };
113
114 static inline const char *
115 rte_ifpga_device_name(const struct rte_afu_device *afu)
116 {
117         if (afu && afu->device.name)
118                 return afu->device.name;
119         return NULL;
120 }
121
122 /**
123  * Find AFU by AFU name.
124  *
125  * @param name
126  *   A pointer to AFU name string.
127  */
128 struct rte_afu_device *
129 rte_ifpga_find_afu_by_name(const char *name);
130
131 /**
132  * Register a ifpga afu device driver.
133  *
134  * @param driver
135  *   A pointer to a rte_afu_driver structure describing the driver
136  *   to be registered.
137  */
138 void rte_ifpga_driver_register(struct rte_afu_driver *driver);
139
140 /**
141  * Unregister a ifpga afu device driver.
142  *
143  * @param driver
144  *   A pointer to a rte_afu_driver structure describing the driver
145  *   to be unregistered.
146  */
147 void rte_ifpga_driver_unregister(struct rte_afu_driver *driver);
148
149 #define RTE_PMD_REGISTER_AFU(nm, afudrv)\
150 static const char *afudrvinit_ ## nm ## _alias;\
151 RTE_INIT(afudrvinitfn_ ##afudrv)\
152 {\
153         (afudrv).driver.name = RTE_STR(nm);\
154         (afudrv).driver.alias = afudrvinit_ ## nm ## _alias;\
155         rte_ifpga_driver_register(&afudrv);\
156 } \
157 RTE_PMD_EXPORT_NAME(nm, __COUNTER__)
158
159 #define RTE_PMD_REGISTER_AFU_ALIAS(nm, alias)\
160 static const char *afudrvinit_ ## nm ## _alias = RTE_STR(alias)
161
162 #ifdef __cplusplus
163 }
164 #endif /* __cplusplus */
165
166 #endif /* _RTE_BUS_IFPGA_H_ */