forked from aws/aws-fpga
-
Notifications
You must be signed in to change notification settings - Fork 0
/
fpga_mgmt.h
259 lines (231 loc) · 8.16 KB
/
fpga_mgmt.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
/*
* Copyright 2015-2017 Amazon.com, Inc. or its affiliates. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License"). You may
* not use this file except in compliance with the License. A copy of the
* License is located at
*
* http://aws.amazon.com/apache2.0/
*
* or in the "license" file accompanying this file. This file is distributed
* on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
* express or implied. See the License for the specific language governing
* permissions and limitations under the License.
*/
#pragma once
#include <stdint.h>
#include <stdbool.h>
#include <stddef.h>
#include "hal/fpga_common.h"
#include "fpga_pci.h"
#ifdef __cplusplus
extern "C" {
#endif
/**
* Initialize the fpga_mgmt library.
* Calls fpga_pci_init.
*
* @returns 0 on success, non-zero on error
*/
int fpga_mgmt_init(void);
/**
* Closes the fpga_mgmt library and its dependencies and releases any acquired
* resources.
*
* @returns 0 on success, non-zero on error
*/
int fpga_mgmt_close(void);
/**
* Get an error code string.
*
* @param[in] err The error code to decode
* @returns a string corresponding to the provided error code.
*/
const char *fpga_mgmt_strerror(int err);
/**
* Get a longer explanation of an error string.
*
* @param[in] err The error code to decode
* @returns a string with an explanation of the likely cause of this error.
*/
const char *fpga_mgmt_strerror_long(int err);
/**
* Sets the command timeout value in multiples of the delay_msec value.
*
* @param[in] value timeout, n * delay_msec
*/
void fpga_mgmt_set_cmd_timeout(uint32_t value);
/**
* Sets the value of the delay_msec. The value is used as the basic unit of time
* used to calculate timeouts for communicating with the mailbox pf.
*
* @param[in] value number of ms used as base time unit
*/
void fpga_mgmt_set_cmd_delay_msec(uint32_t value);
/**
* This structure provides all of the information for
* fpga_mgmt_describe_local_image.
*/
struct fpga_mgmt_image_info {
/** FPGA status: see FPGA_STATUS_XYZ in fpga_common.h */
int status;
/** FPGA status qualifier: see FPGA_ERR_XYZ in fpga_common.h */
int status_q;
int slot_id;
struct fpga_meta_ids ids;
struct fpga_slot_spec spec;
uint32_t sh_version;
struct fpga_metrics_common metrics;
};
/**
* Gets a collection of information about a slot. It populates a
* struct fpga_mgmt_image_info.
*
* @param[in] slot_id the logical slot index
* @param[out] info struct to populate with the slot description
* @param[in] flags set flags for for metrics retrieval options
* @returns 0 on success, non-zero on error
*/
int fpga_mgmt_describe_local_image(int slot_id,
struct fpga_mgmt_image_info *info, uint32_t flags);
/**
* Gets the status of an FPGA.
*
* Status values are defined in fpga_common.h, see FPGA_STATUS_XYZ.
* Status qualifier values are defined in fpga_common.h, see FPGA_ERR_XYZ.
* If you need the AFI id at the same time, use fpga_mgmt_describe_local_image.
*
* @param[in] slot_id the logical slot index
* @param[out] status populated with status value
* @param[out] status_q populated with status qualifier value
* @returns 0 on success, non-zero on error
*/
int fpga_mgmt_get_status(int slot_id, int *status, int *status_q);
/**
* Maps status codes provided by fpga_mgmt_get_status to a human readable
* string.
*
* @param[in] status status code to map
* @returns string containing the human readable form of the status code
*/
const char *fpga_mgmt_get_status_name(int status);
/**
* Asynchronously clears the specified FPGA image slot, including FPGA
* internal and external memories that are used by the slot.
*
* @param[in] slot_id the logical slot index
* @returns 0 on success, non-zero on error
*/
int fpga_mgmt_clear_local_image(int slot_id);
/**
* Synchronously clears the specified FPGA image slot, including FPGA
* internal and external memories that are used by the slot.
* A user-specified timeout may be specified as:
* timeout (retries) * delay_msec (polling period)
*
* @param[in] slot_id the logical slot index
* @param[in] timeout the timeout retries
* @param[in] delay_msec the delay msec between timeout retries
* @param[in/out] info struct to populate with the slot description (or NULL)
* @returns 0 on success, non-zero on error
*/
int fpga_mgmt_clear_local_image_sync(int slot_id,
uint32_t timeout, uint32_t delay_msec,
struct fpga_mgmt_image_info *info);
/**
* Wrapper for fpga_mgmt_load_local_image_flags, with flags set to 0 as a default
*/
int fpga_mgmt_load_local_image(int slot_id, char *afi_id);
/**
* Wrapper for fpga_mgmt_load_local_image_with_options, passing the slot_id, afi_id,
* and flags in the opt structure, with other options set to defaults via
* fpga_mgmt_init_load_local_image_options
*/
int fpga_mgmt_load_local_image_flags(int slot_id, char *afi_id, uint32_t flags);
/*
* @param[in] slot_id the logical slot index
* @param[in] afi_id The Amazon FGPA Image id to be loaded
* @param[in] flags flags to select various options from Common FPGA
* command flags
* @param[in] clock_mains Requested values of the main clock, per group.
Other clocks in the group will be set to low
frequencies.
*/
union fpga_mgmt_load_local_image_options {
uint8_t reserved[1024];
struct {
int slot_id;
char* afi_id;
uint32_t flags;
uint32_t clock_mains[FPGA_MMCM_GROUP_MAX];
};
};
int fpga_mgmt_init_load_local_image_options(union fpga_mgmt_load_local_image_options *opt);
/**
* Asynchronously loads the specified FPGA image to the specified slot number.
*
* @param[in] opt See fpga_mgmt_load_local_image_options
* @returns 0 on success, non-zero on error
*/
int fpga_mgmt_load_local_image_with_options(union fpga_mgmt_load_local_image_options *opt);
/**
* Wrapper for fpga_mgmt_load_local_image_sync_flags, with flags set to 0 as a
* default.
*/
int fpga_mgmt_load_local_image_sync(int slot_id, char *afi_id,
uint32_t timeout, uint32_t delay_msec,
struct fpga_mgmt_image_info *info);
/**
* Wrapper for fpga_mgmt_load_local_image_sync_with_options, passing the slot_id, afi_id,
* and flags in the opt structure, with other options set to defaults via
* fpga_mgmt_init_load_local_image_options
*/
int fpga_mgmt_load_local_image_sync_flags(int slot_id, char *afi_id, uint32_t flags,
uint32_t timeout, uint32_t delay_msec,
struct fpga_mgmt_image_info *info);
/**
* Synchronously loads the specified FPGA image slot to the specified slot
* number.
* A user-specified timeout may be specified as:
* timeout (retries) * delay_msec (polling period)
*
* @param[in] opt See fpga_mgmt_load_local_image_options
* @param[in] timeout the timeout retries
* @param[in] delay_msec the delay msec between timeout retries
* @param[in/out] info struct to populate with the slot description (or NULL)
* @returns 0 on success, non-zero on error
*/
int fpga_mgmt_load_local_image_sync_with_options(union fpga_mgmt_load_local_image_options *opt,
uint32_t timeout, uint32_t delay_msec,
struct fpga_mgmt_image_info *info);
/**
* Gets the status of the 16 virtual LEDs. Their statuses are returned as a
* 16-bit value with each bit corresponding to the on/off state of the LEDs.
*
* @param[in] slot_id the logical slot index
* @param[out] status 16 bits describing the LED states
* @returns 0 on success, non-zero on error
*/
int fpga_mgmt_get_vLED_status(int slot_id, uint16_t *status);
/**
* Sets the status of the 16 virtual dip switches. Their statuses are set as a
* 16-bit value with each bit corresponding to the on/off state of the switches.
*
* @param[in] slot_id the logical slot index
* @param[in] value 16 bits describing the switch states
* @returns 0 on success, non-zero on error
*/
int fpga_mgmt_set_vDIP(int slot_id, uint16_t value);
/**
* Gets the status of the 16 virtual dip switches. Their statuses are returned
* as a 16-bit value with each bit corresponding to the on/off state of the
* switches.
*
* @param[in] slot_id the logical slot index
* @param[out] value 16 bits describing the switch states
* @returns 0 on success, non-zero on error
*/
int fpga_mgmt_get_vDIP_status(int slot_id, uint16_t *value);
#ifdef __cplusplus
}
#endif