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 /* Internal data structures */ 28 29 enum mctp_bus_state { 30 mctp_bus_state_constructed = 0, 31 mctp_bus_state_tx_enabled, 32 mctp_bus_state_tx_disabled, 33 }; 34 35 struct mctp_bus { 36 mctp_eid_t eid; 37 struct mctp_binding *binding; 38 enum mctp_bus_state state; 39 struct mctp *mctp; 40 41 /* Current message to transmit */ 42 void *tx_msg; 43 /* Position in tx_msg */ 44 size_t tx_msgpos; 45 /* Length of tx_msg */ 46 size_t tx_msglen; 47 /* Length of current packet payload */ 48 size_t tx_pktlen; 49 uint8_t tx_seq; 50 uint8_t tx_src; 51 uint8_t tx_dest; 52 bool tx_to; 53 uint8_t tx_tag; 54 55 /* todo: routing */ 56 }; 57 58 struct mctp_msg_ctx { 59 /* NULL buf indicates an unused mctp_msg_ctx */ 60 void *buf; 61 62 uint8_t src; 63 uint8_t dest; 64 uint8_t tag; 65 uint8_t last_seq; 66 size_t buf_size; 67 size_t buf_alloc_size; 68 size_t fragment_size; 69 }; 70 71 struct mctp_req_tag { 72 /* 0 is an unused entry */ 73 mctp_eid_t local; 74 mctp_eid_t remote; 75 uint8_t tag; 76 }; 77 78 struct mctp { 79 int n_busses; 80 struct mctp_bus busses[MCTP_MAX_BUSSES]; 81 82 /* Message RX callback */ 83 mctp_rx_fn message_rx; 84 void *message_rx_data; 85 86 /* Packet capture callback */ 87 mctp_capture_fn capture; 88 void *capture_data; 89 90 /* Message reassembly. */ 91 struct mctp_msg_ctx msg_ctxs[MCTP_REASSEMBLY_CTXS]; 92 93 /* Allocated outbound TO tags */ 94 struct mctp_req_tag req_tags[MCTP_REQ_TAGS]; 95 /* used to avoid always allocating tag 0 */ 96 uint8_t tag_round_robin; 97 98 enum { 99 ROUTE_ENDPOINT, 100 ROUTE_BRIDGE, 101 } route_policy; 102 size_t max_message_size; 103 104 void *alloc_ctx; 105 }; 106