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