blob: c8e7b25c469306972c88cd27b7b9e2bf0088f518 [file] [log] [blame]
Matt Johnstonf9b99f12024-09-17 16:48:34 +08001/* 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
Matt Johnston44e64df2024-11-05 16:59:42 +080027#ifndef MCTP_DEFAULT_CLOCK_GETTIME
28#define MCTP_DEFAULT_CLOCK_GETTIME 1
29#endif
30
31/* Tag expiry timeout, in milliseconds */
32static const uint64_t MCTP_TAG_TIMEOUT = 6000;
33
Matt Johnstonf9b99f12024-09-17 16:48:34 +080034/* Internal data structures */
35
36enum mctp_bus_state {
37 mctp_bus_state_constructed = 0,
38 mctp_bus_state_tx_enabled,
39 mctp_bus_state_tx_disabled,
40};
41
42struct mctp_bus {
43 mctp_eid_t eid;
44 struct mctp_binding *binding;
45 enum mctp_bus_state state;
46 struct mctp *mctp;
47
48 /* Current message to transmit */
49 void *tx_msg;
50 /* Position in tx_msg */
51 size_t tx_msgpos;
52 /* Length of tx_msg */
53 size_t tx_msglen;
54 /* Length of current packet payload */
55 size_t tx_pktlen;
56 uint8_t tx_seq;
57 uint8_t tx_src;
58 uint8_t tx_dest;
59 bool tx_to;
60 uint8_t tx_tag;
61
62 /* todo: routing */
63};
64
65struct mctp_msg_ctx {
66 /* NULL buf indicates an unused mctp_msg_ctx */
67 void *buf;
68
69 uint8_t src;
70 uint8_t dest;
71 uint8_t tag;
72 uint8_t last_seq;
73 size_t buf_size;
74 size_t buf_alloc_size;
75 size_t fragment_size;
76};
77
78struct mctp_req_tag {
79 /* 0 is an unused entry */
80 mctp_eid_t local;
81 mctp_eid_t remote;
82 uint8_t tag;
Matt Johnston44e64df2024-11-05 16:59:42 +080083 /* time of tag expiry */
84 uint64_t expiry;
Matt Johnstonf9b99f12024-09-17 16:48:34 +080085};
86
87struct mctp {
88 int n_busses;
89 struct mctp_bus busses[MCTP_MAX_BUSSES];
90
91 /* Message RX callback */
92 mctp_rx_fn message_rx;
93 void *message_rx_data;
94
95 /* Packet capture callback */
96 mctp_capture_fn capture;
97 void *capture_data;
98
99 /* Message reassembly. */
100 struct mctp_msg_ctx msg_ctxs[MCTP_REASSEMBLY_CTXS];
101
102 /* Allocated outbound TO tags */
103 struct mctp_req_tag req_tags[MCTP_REQ_TAGS];
104 /* used to avoid always allocating tag 0 */
105 uint8_t tag_round_robin;
106
107 enum {
108 ROUTE_ENDPOINT,
109 ROUTE_BRIDGE,
110 } route_policy;
111 size_t max_message_size;
112
113 void *alloc_ctx;
Matt Johnston44e64df2024-11-05 16:59:42 +0800114
115 uint64_t (*platform_now)(void *);
116 void *platform_now_ctx;
Matt Johnstonf9b99f12024-09-17 16:48:34 +0800117};