xref: /openbmc/libmctp/core-internal.h (revision 4058b2cb)
1 /* SPDX-License-Identifier: Apache-2.0 OR GPL-2.0-or-later */
2 #pragma once
3 
4 #include "libmctp.h"
5 
6 /* 64kb should be sufficient for a single message. Applications
7  * requiring higher sizes can override by setting max_message_size.*/
8 #ifndef MCTP_MAX_MESSAGE_SIZE
9 #define MCTP_MAX_MESSAGE_SIZE 65536
10 #endif
11 
12 /* Must be >= 2 for bridge busses */
13 #ifndef MCTP_MAX_BUSSES
14 #define MCTP_MAX_BUSSES 2
15 #endif
16 
17 /* Concurrent reassembly contexts. */
18 #ifndef MCTP_REASSEMBLY_CTXS
19 #define MCTP_REASSEMBLY_CTXS 16
20 #endif
21 
22 /* Outbound request tags */
23 #ifndef MCTP_REQ_TAGS
24 #define MCTP_REQ_TAGS MCTP_REASSEMBLY_CTXS
25 #endif
26 
27 #ifndef MCTP_DEFAULT_CLOCK_GETTIME
28 #define MCTP_DEFAULT_CLOCK_GETTIME 1
29 #endif
30 
31 #ifndef MCTP_CONTROL_HANDLER
32 #define MCTP_CONTROL_HANDLER 1
33 #endif
34 
35 /* Tag expiry timeout, in milliseconds */
36 static const uint64_t MCTP_TAG_TIMEOUT = 6000;
37 
38 /* Internal data structures */
39 
40 enum mctp_bus_state {
41 	mctp_bus_state_constructed = 0,
42 	mctp_bus_state_tx_enabled,
43 	mctp_bus_state_tx_disabled,
44 };
45 
46 struct mctp_bus {
47 	mctp_eid_t eid;
48 	struct mctp_binding *binding;
49 	enum mctp_bus_state state;
50 	struct mctp *mctp;
51 
52 	/* Current message to transmit */
53 	void *tx_msg;
54 	/* Position in tx_msg */
55 	size_t tx_msgpos;
56 	/* Length of tx_msg */
57 	size_t tx_msglen;
58 	/* Length of current packet payload */
59 	size_t tx_pktlen;
60 	uint8_t tx_seq;
61 	uint8_t tx_src;
62 	uint8_t tx_dest;
63 	bool tx_to;
64 	uint8_t tx_tag;
65 
66 	/* todo: routing */
67 };
68 
69 struct mctp_msg_ctx {
70 	/* NULL buf indicates an unused mctp_msg_ctx */
71 	void *buf;
72 
73 	uint8_t src;
74 	uint8_t dest;
75 	uint8_t tag;
76 	uint8_t last_seq;
77 	size_t buf_size;
78 	size_t buf_alloc_size;
79 	size_t fragment_size;
80 };
81 
82 struct mctp_req_tag {
83 	/* 0 is an unused entry */
84 	mctp_eid_t local;
85 	mctp_eid_t remote;
86 	uint8_t tag;
87 	/* time of tag expiry */
88 	uint64_t expiry;
89 };
90 
91 #define MCTP_CONTROL_MAX_TYPES 10
92 
93 struct mctp_control {
94 	/* Types to report from Get MCTP Version Support */
95 	uint8_t msg_types[MCTP_CONTROL_MAX_TYPES];
96 	size_t num_msg_types;
97 };
98 
99 struct mctp {
100 	int n_busses;
101 	struct mctp_bus busses[MCTP_MAX_BUSSES];
102 
103 	/* Message RX callback */
104 	mctp_rx_fn message_rx;
105 	void *message_rx_data;
106 
107 	/* Packet capture callback */
108 	mctp_capture_fn capture;
109 	void *capture_data;
110 
111 	/* Message reassembly. */
112 	struct mctp_msg_ctx msg_ctxs[MCTP_REASSEMBLY_CTXS];
113 
114 	/* Allocated outbound TO tags */
115 	struct mctp_req_tag req_tags[MCTP_REQ_TAGS];
116 	/* used to avoid always allocating tag 0 */
117 	uint8_t tag_round_robin;
118 
119 	enum {
120 		ROUTE_ENDPOINT,
121 		ROUTE_BRIDGE,
122 	} route_policy;
123 	size_t max_message_size;
124 
125 #if MCTP_CONTROL_HANDLER
126 	struct mctp_control control;
127 #endif
128 
129 	void *alloc_ctx;
130 
131 	uint64_t (*platform_now)(void *);
132 	void *platform_now_ctx;
133 };
134