This repository has been archived by the owner on Sep 4, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 22
/
libmctp-cmds.h
438 lines (364 loc) · 13.3 KB
/
libmctp-cmds.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
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
/* SPDX-License-Identifier: Apache-2.0 OR GPL-2.0-or-later */
#ifndef _LIBMCTP_CMDS_H
#define _LIBMCTP_CMDS_H
#ifdef __cplusplus
extern "C" {
#endif
#include "libmctp.h"
/*
* Helper structs and functions for MCTP control messages.
* See DSP0236 v1.3.0 sec. 11 for reference.
*/
struct mctp_ctrl_msg_hdr {
uint8_t ic_msg_type;
uint8_t rq_dgram_inst;
uint8_t command_code;
} __attribute__((__packed__));
typedef enum {
set_eid,
force_eid,
reset_eid,
set_discovered_flag
} mctp_ctrl_cmd_set_eid_op;
typedef enum {
allocate_eids,
force_allocation,
get_allocation_info,
reserved
} mctp_ctrl_cmd_allocate_eids_op;
typedef enum {
allocation_accepted,
allocation_rejected,
} mctp_ctrl_cmd_allocate_eids_resp_op;
struct mctp_ctrl_cmd_set_eid {
struct mctp_ctrl_msg_hdr ctrl_msg_hdr;
mctp_ctrl_cmd_set_eid_op operation : 2;
uint8_t : 6;
uint8_t eid;
} __attribute__((__packed__));
struct mctp_ctrl_cmd_allocate_eids {
struct mctp_ctrl_msg_hdr ctrl_msg_hdr;
mctp_ctrl_cmd_allocate_eids_op operation : 2;
uint8_t : 6;
uint8_t eid_pool_size;
uint8_t first_eid;
} __attribute__((__packed__));
struct mctp_ctrl_cmd_get_eid {
struct mctp_ctrl_msg_hdr ctrl_msg_hdr;
} __attribute__((__packed__));
struct mctp_ctrl_cmd_get_uuid {
struct mctp_ctrl_msg_hdr ctrl_msg_hdr;
} __attribute__((__packed__));
struct mctp_ctrl_cmd_get_mctp_ver_support {
struct mctp_ctrl_msg_hdr ctrl_msg_hdr;
uint8_t msg_type_number;
} __attribute__((__packed__));
struct mctp_ctrl_cmd_get_msg_type_support {
struct mctp_ctrl_msg_hdr ctrl_msg_hdr;
} __attribute__((__packed__));
struct mctp_ctrl_cmd_get_vdm_support {
struct mctp_ctrl_msg_hdr ctrl_msg_hdr;
uint8_t vendor_id_set_selector;
} __attribute__((__packed__));
struct mctp_ctrl_cmd_discovery_notify {
struct mctp_ctrl_msg_hdr ctrl_msg_hdr;
} __attribute__((__packed__));
struct mctp_ctrl_cmd_get_routing_table {
struct mctp_ctrl_msg_hdr ctrl_msg_hdr;
uint8_t entry_handle;
} __attribute__((__packed__));
struct mctp_ctrl_cmd_query_hop {
struct mctp_ctrl_msg_hdr ctrl_msg_hdr;
uint8_t target_eid;
uint8_t mctp_ctrl_msg_type;
} __attribute__((__packed__));
#define MCTP_CTRL_HDR_MSG_TYPE 0
#define MCTP_CTRL_HDR_FLAG_REQUEST (1 << 7)
#define MCTP_CTRL_HDR_FLAG_DGRAM (1 << 6)
#define MCTP_CTRL_HDR_INSTANCE_ID_MASK 0x1F
/*
* MCTP Control Command IDs
* See DSP0236 v1.3.0 Table 12.
*/
#define MCTP_CTRL_CMD_RESERVED 0x00
#define MCTP_CTRL_CMD_SET_ENDPOINT_ID 0x01
#define MCTP_CTRL_CMD_GET_ENDPOINT_ID 0x02
#define MCTP_CTRL_CMD_GET_ENDPOINT_UUID 0x03
#define MCTP_CTRL_CMD_GET_VERSION_SUPPORT 0x04
#define MCTP_CTRL_CMD_GET_MESSAGE_TYPE_SUPPORT 0x05
#define MCTP_CTRL_CMD_GET_VENDOR_MESSAGE_SUPPORT 0x06
#define MCTP_CTRL_CMD_RESOLVE_ENDPOINT_ID 0x07
#define MCTP_CTRL_CMD_ALLOCATE_ENDPOINT_IDS 0x08
#define MCTP_CTRL_CMD_ROUTING_INFO_UPDATE 0x09
#define MCTP_CTRL_CMD_GET_ROUTING_TABLE_ENTRIES 0x0A
#define MCTP_CTRL_CMD_PREPARE_ENDPOINT_DISCOVERY 0x0B
#define MCTP_CTRL_CMD_ENDPOINT_DISCOVERY 0x0C
#define MCTP_CTRL_CMD_DISCOVERY_NOTIFY 0x0D
#define MCTP_CTRL_CMD_GET_NETWORK_ID 0x0E
#define MCTP_CTRL_CMD_QUERY_HOP 0x0F
#define MCTP_CTRL_CMD_RESOLVE_UUID 0x10
#define MCTP_CTRL_CMD_QUERY_RATE_LIMIT 0x11
#define MCTP_CTRL_CMD_REQUEST_TX_RATE_LIMIT 0x12
#define MCTP_CTRL_CMD_UPDATE_RATE_LIMIT 0x13
#define MCTP_CTRL_CMD_QUERY_SUPPORTED_INTERFACES 0x14
#define MCTP_CTRL_CMD_MAX 0x15
/* 0xF0 - 0xFF are transport specific */
#define MCTP_CTRL_CMD_FIRST_TRANSPORT 0xF0
#define MCTP_CTRL_CMD_LAST_TRANSPORT 0xFF
/*
* MCTP Control Completion Codes
* See DSP0236 v1.3.0 Table 13.
*/
#define MCTP_CTRL_CC_SUCCESS 0x00
#define MCTP_CTRL_CC_ERROR 0x01
#define MCTP_CTRL_CC_ERROR_INVALID_DATA 0x02
#define MCTP_CTRL_CC_ERROR_INVALID_LENGTH 0x03
#define MCTP_CTRL_CC_ERROR_NOT_READY 0x04
#define MCTP_CTRL_CC_ERROR_UNSUPPORTED_CMD 0x05
/* 0x80 - 0xFF are command specific */
#define MCTP_CTRL_CC_GET_MCTP_VER_SUPPORT_UNSUPPORTED_TYPE 0x80
/* MCTP Set Endpoint ID response fields
* See DSP0236 v1.3.0 Table 14.
*/
#define MCTP_EID_ASSIGNMENT_STATUS_SHIFT 0x4
#define MCTP_EID_ASSIGNMENT_STATUS_MASK 0x3
#define SET_MCTP_EID_ASSIGNMENT_STATUS(field, status) \
((field) |= (((status)&MCTP_EID_ASSIGNMENT_STATUS_MASK) \
<< MCTP_EID_ASSIGNMENT_STATUS_SHIFT))
#define MCTP_SET_EID_ACCEPTED 0x0
#define MCTP_SET_EID_REJECTED 0x1
/* MCTP Physical Transport Binding identifiers
* See DSP0239 v1.7.0 Table 3.
*/
#define MCTP_BINDING_RESERVED 0x00
#define MCTP_BINDING_SMBUS 0x01
#define MCTP_BINDING_PCIE 0x02
#define MCTP_BINDING_USB 0x03
#define MCTP_BINDING_KCS 0x04
#define MCTP_BINDING_SERIAL 0x05
#define MCTP_BINDING_VEDNOR 0x06
#define MCTP_GET_VDM_SUPPORT_PCIE_FORMAT_ID 0x00
#define MCTP_GET_VDM_SUPPORT_IANA_FORMAT_ID 0x01
#define MCTP_GET_VDM_SUPPORT_NO_MORE_CAP_SET 0xFF
typedef union {
struct {
uint32_t data0;
uint16_t data1;
uint16_t data2;
uint16_t data3;
uint8_t data4[6];
} __attribute__((__packed__)) canonical;
uint8_t raw[16];
} guid_t;
#define MCTP_ENDPOINT_TYPE_SHIFT 4
#define MCTP_ENDPOINT_TYPE_MASK 0x3
#define MCTP_SIMPLE_ENDPOINT 0
#define MCTP_BUS_OWNER_BRIDGE 1
#define SET_ENDPOINT_TYPE(field, type) \
((field) |= \
(((type)&MCTP_ENDPOINT_TYPE_MASK) << MCTP_ENDPOINT_TYPE_SHIFT))
#define MCTP_ENDPOINT_ID_TYPE_SHIFT 0
#define MCTP_ENDPOINT_ID_TYPE_MASK 0x3
#define MCTP_DYNAMIC_EID 0
#define MCTP_STATIC_EID 1
#define SET_ENDPOINT_ID_TYPE(field, type) \
((field) |= \
(((type)&MCTP_ENDPOINT_ID_TYPE_MASK) << MCTP_ENDPOINT_ID_TYPE_SHIFT))
/* MCTP Routing Table entry types
* See DSP0236 v1.3.0 Table 27.
*/
#define MCTP_ROUTING_ENTRY_PORT_SHIFT 0
#define MCTP_ROUTING_ENTRY_PORT_MASK 0x1F
#define SET_ROUTING_ENTRY_PORT(field, port) \
((field) |= (((port)&MCTP_ROUTING_ENTRY_PORT_MASK) \
<< MCTP_ROUTING_ENTRY_PORT_SHIFT))
#define GET_ROUTING_ENTRY_PORT(field) \
(((field) >> MCTP_ROUTING_ENTRY_PORT_SHIFT) & \
MCTP_ROUTING_ENTRY_PORT_MASK)
#define MCTP_ROUTING_ENTRY_ASSIGNMENT_TYPE_SHIFT 5
#define MCTP_ROUTING_ENTRY_ASSIGNMENT_TYPE_MASK 0x1
#define MCTP_DYNAMIC_ASSIGNMENT 0
#define MCTP_STATIC_ASSIGNMENT 1
#define SET_ROUTING_ENTRY_ASSIGNMENT_TYPE(field, type) \
((field) |= (((type)&MCTP_ROUTING_ENTRY_ASSIGNMENT_TYPE_MASK) \
<< MCTP_ROUTING_ENTRY_ASSIGNMENT_TYPE_SHIFT))
#define GET_ROUTING_ENTRY_ASSIGNMENT_TYPE(field) \
(((field) >> MCTP_ROUTING_ENTRY_ASSIGNMENT_TYPE_SHIFT) & \
MCTP_ROUTING_ENTRY_ASSIGNMENT_TYPE_MASK)
#define MCTP_ROUTING_ENTRY_TYPE_SHIFT 6
#define MCTP_ROUTING_ENTRY_TYPE_MASK 0x3
#define MCTP_ROUTING_ENTRY_ENDPOINT 0x00
#define MCTP_ROUTING_ENTRY_BRIDGE_AND_ENDPOINTS 0x01
#define MCTP_ROUTING_ENTRY_BRIDGE 0x02
#define MCTP_ROUTING_ENTRY_ENDPOINTS 0x03
#define SET_ROUTING_ENTRY_TYPE(field, type) \
((field) |= (((type)&MCTP_ROUTING_ENTRY_TYPE_MASK) \
<< MCTP_ROUTING_ENTRY_TYPE_SHIFT))
#define GET_ROUTING_ENTRY_TYPE(field) \
(((field) >> MCTP_ROUTING_ENTRY_TYPE_SHIFT) & \
MCTP_ROUTING_ENTRY_TYPE_MASK)
#define MCTP_GET_VERSION_SUPPORT_BASE_INFO 0xFF
struct mctp_ctrl_resp_get_eid {
struct mctp_ctrl_msg_hdr ctrl_hdr;
uint8_t completion_code;
mctp_eid_t eid;
uint8_t eid_type;
uint8_t medium_data;
} __attribute__((__packed__));
struct mctp_ctrl_resp_get_uuid {
struct mctp_ctrl_msg_hdr ctrl_hdr;
uint8_t completion_code;
guid_t uuid;
} __attribute__((__packed__));
struct mctp_ctrl_resp_set_eid {
struct mctp_ctrl_msg_hdr ctrl_hdr;
uint8_t completion_code;
uint8_t status;
mctp_eid_t eid_set;
uint8_t eid_pool_size;
} __attribute__((__packed__));
struct mctp_ctrl_resp_discovery_notify {
struct mctp_ctrl_msg_hdr ctrl_hdr;
uint8_t completion_code;
} __attribute__((__packed__));
struct mctp_ctrl_resp_prepare_discovery {
struct mctp_ctrl_msg_hdr ctrl_hdr;
uint8_t completion_code;
} __attribute__((__packed__));
struct mctp_ctrl_resp_endpoint_discovery {
struct mctp_ctrl_msg_hdr ctrl_hdr;
uint8_t completion_code;
} __attribute__((__packed__));
struct get_routing_table_entry {
uint8_t eid_range_size;
uint8_t starting_eid;
uint8_t entry_type;
uint8_t phys_transport_binding_id;
uint8_t phys_media_type_id;
uint8_t phys_address_size;
} __attribute__((__packed__));
struct mctp_ctrl_resp_routing_info_update {
struct mctp_ctrl_msg_hdr ctrl_hdr;
uint8_t completion_code;
} __attribute__((__packed__));
struct mctp_ctrl_cmd_routing_info_update {
struct mctp_ctrl_msg_hdr ctrl_msg_hdr;
uint8_t count;
uint8_t entries[0];
} __attribute__((__packed__));
struct routing_info_update_entry {
uint8_t type;
uint8_t eid_count;
uint8_t starting_eid;
uint8_t address[0];
} __attribute__((__packed__));
/* Assume 8 byte is enough for holding largest physical address */
#define MAX_PHYSICAL_ADDRESS_SIZE 8
struct get_routing_table_entry_with_address {
struct get_routing_table_entry routing_info;
uint8_t phys_address[MAX_PHYSICAL_ADDRESS_SIZE];
} __attribute__((__packed__));
struct mctp_ctrl_resp_get_routing_table {
struct mctp_ctrl_msg_hdr ctrl_hdr;
uint8_t completion_code;
uint8_t next_entry_handle;
uint8_t number_of_entries;
struct get_routing_table_entry_with_address entries[0];
} __attribute__((__packed__));
struct mctp_ctrl_resp_get_vdm_support {
struct mctp_ctrl_msg_hdr ctrl_hdr;
uint8_t completion_code;
uint8_t vendor_id_set_selector;
uint8_t vendor_id_format;
union {
uint16_t vendor_id_data_pcie;
uint32_t vendor_id_data_iana;
};
/* following bytes are dependent on vendor id format
* and shall be interpreted by appropriate binding handler */
} __attribute__((__packed__));
struct mctp_pci_ctrl_resp_get_vdm_support {
struct mctp_ctrl_msg_hdr ctrl_hdr;
uint8_t completion_code;
uint8_t vendor_id_set_selector;
uint8_t vendor_id_format;
uint16_t vendor_id_data;
uint16_t command_set_type;
} __attribute__((__packed__));
struct mctp_ctrl_resp_get_msg_type_support {
struct mctp_ctrl_msg_hdr ctrl_hdr;
uint8_t completion_code;
uint8_t msg_type_count;
} __attribute__((__packed__));
struct msg_type_entry {
uint8_t msg_type_no;
} __attribute__((__packed__));
struct mctp_ctrl_resp_get_mctp_ver_support {
struct mctp_ctrl_msg_hdr ctrl_hdr;
uint8_t completion_code;
uint8_t number_of_entries;
} __attribute__((__packed__));
struct version_entry {
uint8_t major;
uint8_t minor;
uint8_t update;
uint8_t alpha;
} __attribute__((__packed__));
bool mctp_ctrl_handle_msg(struct mctp *mctp, struct mctp_bus *bus,
mctp_eid_t src, mctp_eid_t dest, void *buffer,
size_t length, bool tag_owner, uint8_t tag,
void *msg_binding_private);
int mctp_set_rx_ctrl(struct mctp *mctp, mctp_rx_fn fn, void *data);
bool mctp_encode_ctrl_cmd_set_eid(struct mctp_ctrl_cmd_set_eid *set_eid_cmd,
uint8_t rq_dgram_inst,
mctp_ctrl_cmd_set_eid_op op, uint8_t eid);
bool mctp_encode_ctrl_cmd_get_eid(struct mctp_ctrl_cmd_get_eid *get_eid_cmd,
uint8_t rq_dgram_inst);
bool mctp_encode_ctrl_cmd_get_uuid(struct mctp_ctrl_cmd_get_uuid *get_uuid_cmd,
uint8_t rq_dgram_inst);
bool mctp_encode_ctrl_cmd_get_ver_support(
struct mctp_ctrl_cmd_get_mctp_ver_support *mctp_ver_support_cmd,
uint8_t rq_dgram_inst, uint8_t msg_type_number);
bool mctp_encode_ctrl_cmd_get_msg_type_support(
struct mctp_ctrl_cmd_get_msg_type_support *msg_type_support_cmd,
uint8_t rq_dgram_inst);
bool mctp_encode_ctrl_cmd_get_vdm_support(
struct mctp_ctrl_cmd_get_vdm_support *vdm_support_cmd,
uint8_t rq_dgram_inst, uint8_t v_id_set_selector);
bool mctp_encode_ctrl_cmd_discovery_notify(
struct mctp_ctrl_cmd_discovery_notify *discovery_notify_cmd,
uint8_t rq_dgram_inst);
bool mctp_encode_ctrl_cmd_get_routing_table(
struct mctp_ctrl_cmd_get_routing_table *get_routing_table_cmd,
uint8_t rq_dgram_inst, uint8_t entry_handle);
bool mctp_encode_ctrl_cmd_routing_information_update(
struct mctp_ctrl_cmd_routing_info_update *routing_info_update_cmd,
uint8_t rq_dgram_inst,
struct get_routing_table_entry_with_address *entries,
uint8_t no_of_entries, size_t *new_req_size);
bool mctp_encode_ctrl_cmd_rsp_get_routing_table(
struct mctp_ctrl_resp_get_routing_table *resp,
struct get_routing_table_entry_with_address *entries,
uint8_t no_of_entries, size_t *resp_size);
bool mctp_encode_ctrl_cmd_query_hop(
struct mctp_ctrl_cmd_query_hop *query_hop_cmd, uint8_t rq_dgram_inst,
const uint8_t eid, const uint8_t mctp_ctrl_msg_type);
bool mctp_encode_ctrl_cmd_allocate_eids(
struct mctp_ctrl_cmd_allocate_eids *set_eid_cmd, uint8_t rq_dgram_inst,
mctp_ctrl_cmd_allocate_eids_op op, uint8_t pool_size, uint8_t eid);
void mctp_set_uuid(struct mctp *mctp, guid_t uuid);
bool mctp_is_mctp_ctrl_msg(void *buf, size_t len);
bool mctp_ctrl_msg_is_req(void *buf, size_t len);
int mctp_ctrl_cmd_set_endpoint_id(struct mctp *mctp, mctp_eid_t dest_eid,
struct mctp_ctrl_cmd_set_eid *request,
struct mctp_ctrl_resp_set_eid *response);
int mctp_ctrl_cmd_get_endpoint_id(struct mctp *mctp, mctp_eid_t dest_eid,
bool bus_owner,
struct mctp_ctrl_resp_get_eid *response);
int mctp_ctrl_cmd_get_vdm_support(
struct mctp *mctp, mctp_eid_t src_eid,
struct mctp_ctrl_resp_get_vdm_support *response);
#ifdef __cplusplus
}
#endif
#endif /* _LIBMCTP_CMDS_H */