New upstream version 18.08
[deb_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
17
18 #include <rte_bus.h>
19 #include <rte_pci.h>
20
21 /** Name of Intel FPGA Bus */
22 #define IFPGA_BUS_NAME ifpga
23
24 /* Forward declarations */
25 struct rte_afu_device;
26 struct rte_afu_driver;
27
28 /** Double linked list of Intel FPGA AFU device. */
29 TAILQ_HEAD(ifpga_afu_dev_list, rte_afu_device);
30 /** Double linked list of Intel FPGA AFU device drivers. */
31 TAILQ_HEAD(ifpga_afu_drv_list, rte_afu_driver);
32
33 #define IFPGA_BUS_BITSTREAM_PATH_MAX_LEN 256
34
35 struct rte_afu_uuid {
36         uint64_t uuid_low;
37         uint64_t uuid_high;
38 } __attribute__ ((packed));
39
40 #define IFPGA_BUS_DEV_PORT_MAX 4
41
42 /**
43  * A structure describing an ID for a AFU driver. Each driver provides a
44  * table of these IDs for each device that it supports.
45  */
46 struct rte_afu_id {
47         struct rte_afu_uuid uuid;
48         int      port; /**< port number */
49 } __attribute__ ((packed));
50
51 /**
52  * A structure PR (Partial Reconfiguration) configuration AFU driver.
53  */
54
55 struct rte_afu_pr_conf {
56         struct rte_afu_id afu_id;
57         int pr_enable;
58         char bs_path[IFPGA_BUS_BITSTREAM_PATH_MAX_LEN];
59 };
60
61 #define AFU_PRI_STR_SIZE (PCI_PRI_STR_SIZE + 8)
62
63 /**
64  * A structure describing a AFU device.
65  */
66 struct rte_afu_device {
67         TAILQ_ENTRY(rte_afu_device) next;       /**< Next in device list. */
68         struct rte_device device;               /**< Inherit core device */
69         struct rte_rawdev *rawdev;    /**< Point Rawdev */
70         struct rte_afu_id id;                   /**< AFU id within FPGA. */
71         uint32_t num_region;   /**< number of regions found */
72         struct rte_mem_resource mem_resource[PCI_MAX_RESOURCE];
73                                                 /**< AFU Memory Resource */
74         struct rte_intr_handle intr_handle;     /**< Interrupt handle */
75         struct rte_afu_driver *driver;          /**< Associated driver */
76         char path[IFPGA_BUS_BITSTREAM_PATH_MAX_LEN];
77 } __attribute__ ((packed));
78
79 /**
80  * @internal
81  * Helper macro for drivers that need to convert to struct rte_afu_device.
82  */
83 #define RTE_DEV_TO_AFU(ptr) \
84         container_of(ptr, struct rte_afu_device, device)
85
86 #define RTE_DRV_TO_AFU_CONST(ptr) \
87         container_of(ptr, const struct rte_afu_driver, driver)
88
89 /**
90  * Initialization function for the driver called during FPGA BUS probing.
91  */
92 typedef int (afu_probe_t)(struct rte_afu_device *);
93
94 /**
95  * Uninitialization function for the driver called during hotplugging.
96  */
97 typedef int (afu_remove_t)(struct rte_afu_device *);
98
99 /**
100  * A structure describing a AFU device.
101  */
102 struct rte_afu_driver {
103         TAILQ_ENTRY(rte_afu_driver) next;       /**< Next afu driver. */
104         struct rte_driver driver;               /**< Inherit core driver. */
105         afu_probe_t *probe;                     /**< Device Probe function. */
106         afu_remove_t *remove;                   /**< Device Remove function. */
107         const struct rte_afu_uuid *id_table;    /**< AFU uuid within FPGA. */
108 };
109
110 static inline const char *
111 rte_ifpga_device_name(const struct rte_afu_device *afu)
112 {
113         if (afu && afu->device.name)
114                 return afu->device.name;
115         return NULL;
116 }
117
118 /**
119  * Register a ifpga afu device driver.
120  *
121  * @param driver
122  *   A pointer to a rte_afu_driver structure describing the driver
123  *   to be registered.
124  */
125 void rte_ifpga_driver_register(struct rte_afu_driver *driver);
126
127 /**
128  * Unregister a ifpga afu device driver.
129  *
130  * @param driver
131  *   A pointer to a rte_afu_driver structure describing the driver
132  *   to be unregistered.
133  */
134 void rte_ifpga_driver_unregister(struct rte_afu_driver *driver);
135
136 #define RTE_PMD_REGISTER_AFU(nm, afudrv)\
137 static const char *afudrvinit_ ## nm ## _alias;\
138 RTE_INIT(afudrvinitfn_ ##afudrv)\
139 {\
140         (afudrv).driver.name = RTE_STR(nm);\
141         (afudrv).driver.alias = afudrvinit_ ## nm ## _alias;\
142         rte_ifpga_driver_register(&afudrv);\
143 } \
144 RTE_PMD_EXPORT_NAME(nm, __COUNTER__)
145
146 #define RTE_PMD_REGISTER_AFU_ALIAS(nm, alias)\
147 static const char *afudrvinit_ ## nm ## _alias = RTE_STR(alias)
148
149 #endif /* _RTE_BUS_IFPGA_H_ */