raw/ifpga/base: update flash operation interface
[dpdk.git] / drivers / raw / ifpga / rte_pmd_ifpga.h
1 /* SPDX-License-Identifier: BSD-3-Clause
2  * Copyright(c) 2021 Intel Corporation
3  */
4
5 #ifndef _RTE_PMD_IFPGA_H_
6 #define _RTE_PMD_IFPGA_H_
7
8 /**
9  * @file rte_pmd_ifpga.h
10  *
11  * ifpga PMD specific functions.
12  *
13  * @b EXPERIMENTAL: this API may change, or be removed, without prior notice
14  *
15  */
16
17 #ifdef __cplusplus
18 extern "C" {
19 #endif
20
21 #include <stdint.h>
22
23 #define IFPGA_MAX_PORT_NUM   4
24
25 /**
26  * UUID data structure.
27  */
28 typedef struct {
29         uint8_t b[16];
30 } rte_pmd_ifpga_uuid;
31
32 /**
33  * FME property data structure.
34  */
35 typedef struct {
36         uint32_t num_ports;
37         uint32_t boot_page;
38         uint64_t bitstream_id;
39         uint64_t bitstream_metadata;
40         rte_pmd_ifpga_uuid pr_id;
41         uint32_t bmc_version;
42         uint32_t bmc_nios_version;
43 } rte_pmd_ifpga_common_prop;
44
45 /**
46  * port property data structure.
47  */
48 typedef struct {
49         rte_pmd_ifpga_uuid afu_id;
50         uint32_t type;   /* AFU memory access control type */
51 } rte_pmd_ifpga_port_prop;
52
53 /**
54  * FPGA property data structure.
55  */
56 typedef struct {
57         rte_pmd_ifpga_common_prop  common;
58         rte_pmd_ifpga_port_prop    port[IFPGA_MAX_PORT_NUM];
59 } rte_pmd_ifpga_prop;
60
61 /**
62  * PHY information data structure.
63  */
64 typedef struct {
65         uint32_t num_retimers;
66         uint32_t link_speed;
67         uint32_t link_status;
68 } rte_pmd_ifpga_phy_info;
69
70 /**
71  * Get raw device ID from PCI address string like 'Domain:Bus:Dev.Func'
72  *
73  * @param pci_addr
74  *    The PCI address of specified Intel FPGA device.
75  * @param dev_id
76  *    The buffer to output device ID.
77  * @return
78  *   - (0) if successful.
79  *   - (-EINVAL) if bad parameter.
80  *   - (-ENODEV) if FPGA is not probed by ifpga driver.
81  */
82 int
83 rte_pmd_ifpga_get_dev_id(const char *pci_addr, uint16_t *dev_id);
84
85 /**
86  * Get current RSU status of the specified Intel FPGA device
87  *
88  * @param dev_id
89  *    The raw device ID of specified Intel FPGA device.
90  * @param stat
91  *    The buffer to output RSU status.
92  * @param prog
93  *    The buffer to output RSU progress.
94  * @return
95  *   - (0) if successful.
96  *   - (-ENODEV) if dev_id is invalid.
97  *   - (-ENOMEM) if share data is not initialized.
98  */
99 int
100 rte_pmd_ifpga_get_rsu_status(uint16_t dev_id, uint32_t *stat, uint32_t *prog);
101
102 /**
103  * Set current RSU status of the specified Intel FPGA device
104  *
105  * @param dev_id
106  *    The raw device ID of specified Intel FPGA device.
107  * @param stat
108  *    The RSU status value to set.
109  * @param prog
110  *    The RSU progress value to set.
111  * @return
112  *   - (0) if successful.
113  *   - (-ENODEV) if dev_id is invalid.
114  *   - (-ENOMEM) if share data is not initialized.
115  */
116 int
117 rte_pmd_ifpga_set_rsu_status(uint16_t dev_id, uint32_t stat, uint32_t prog);
118
119 /**
120  * Get FPGA property of specified Intel FPGA device
121  *
122  * @param dev_id
123  *    The raw device ID of specified Intel FPGA device.
124  * @param prop
125  *    The data pointer of FPGA property buffer.
126  * @return
127  *   - (0) if successful.
128  *   - (-ENODEV) if dev_id is invalid.
129  *   - (-EBUSY) if FPGA is rebooting.
130  *   - (-EIO) if failed to access hardware.
131  */
132 int
133 rte_pmd_ifpga_get_property(uint16_t dev_id, rte_pmd_ifpga_prop *prop);
134
135 /**
136  * Get PHY information of specified Intel FPGA device
137  *
138  * @param dev_id
139  *    The raw device ID of specified Intel FPGA device.
140  * @param info
141  *    The data pointer of PHY information buffer.
142  * @return
143  *   - (0) if successful.
144  *   - (-ENODEV) if dev_id is invalid.
145  *   - (-EBUSY) if FPGA is rebooting.
146  *   - (-EIO) if failed to access hardware.
147  */
148 int
149 rte_pmd_ifpga_get_phy_info(uint16_t dev_id, rte_pmd_ifpga_phy_info *info);
150
151 /**
152  * Update image flash of specified Intel FPGA device
153  *
154  * @param dev_id
155  *   The raw device ID of specified Intel FPGA device.
156  * @param image
157  *   The image file name string.
158  * @param status
159  *   The detailed update status for debug.
160  * @return
161  *   - (0) if successful.
162  *   - (-ENODEV) if dev_id is invalid.
163  *   - (-EINVAL) if bad parameter or staging area is not initialized.
164  *   - (-EBUSY) if FPGA is updating or rebooting.
165  *   - (-EIO) if failed to open image file.
166  */
167 int
168 rte_pmd_ifpga_update_flash(uint16_t dev_id, const char *image,
169         uint64_t *status);
170
171 /**
172  * Stop flash update of specified Intel FPGA device
173  *
174  * @param dev_id
175  *   The raw device ID of specified Intel FPGA device.
176  * @param force
177  *   Abort the update process by writing register if set non-zero.
178  * @return
179  *   - (0) if successful.
180  *   - (-ENODEV) if dev_id is invalid.
181  *   - (-EINVAL) if bad parameter.
182  *   - (-EAGAIN) if failed with force.
183  */
184 int
185 rte_pmd_ifpga_stop_update(uint16_t dev_id, int force);
186
187 /**
188  * Check current Intel FPGA status and change it to reboot status if it is idle
189  *
190  * @param dev_id
191  *    The raw device ID of specified Intel FPGA device.
192  * @return
193  *   - (0) if FPGA is ready to reboot.
194  *   - (-ENODEV) if dev_id is invalid.
195  *   - (-ENOMEM) if share data is not initialized.
196  *   - (-EBUSY) if FPGA is updating or rebooting.
197  */
198 int
199 rte_pmd_ifpga_reboot_try(uint16_t dev_id);
200
201 /**
202  * Trigger full reconfiguration of specified Intel FPGA device
203  *
204  * @param dev_id
205  *    The raw device ID of specified Intel FPGA device.
206  * @param type
207  *    Select reconfiguration type.
208  *    0 - reconfigure FPGA only.
209  *    1 - reboot the whole card including FPGA.
210  * @param page
211  *    Select image from which flash partition.
212  *    0 - factory partition.
213  *    1 - user partition.
214  * @return
215  *   - (0) if successful.
216  *   - (-ENODEV) if dev_id is invalid.
217  *   - (-EINVAL) if bad parameter.
218  *   - (-EBUSY) if failed to access BMC register.
219  */
220 int
221 rte_pmd_ifpga_reload(uint16_t dev_id, int type, int page);
222
223 /**
224  * Get PCI bus the Intel FPGA driver register to
225  *
226  * @return
227  *   - (valid pointer) if successful.
228  *   - (NULL) if the Intel FPGA driver is not registered to any PCI bus.
229  */
230 const struct rte_pci_bus *
231 rte_pmd_ifpga_get_pci_bus(void);
232
233 /**
234  * Perform PR (partial reconfiguration) on specified Intel FPGA device
235  *
236  * @param dev_id
237  *   The raw device ID of specified Intel FPGA device.
238  * @param port
239  *   The port index of the partial reconfiguration area.
240  * @param file
241  *   The GBS (Green BitStream) image file name string.
242  * @return
243  *   - (0) if successful.
244  *   - (-EINVAL) if bad parameter or operation failed.
245  *   - (-ENOMEM) if failed to allocate memory.
246  */
247 int
248 rte_pmd_ifpga_partial_reconfigure(uint16_t dev_id, int port, const char *file);
249
250 /**
251  * Free software resources allocated by Intel FPGA PMD
252  */
253 void
254 rte_pmd_ifpga_cleanup(void);
255
256 #ifdef __cplusplus
257 }
258 #endif
259
260 #endif /* _RTE_PMD_IFPGA_H_ */