core: Reuse buffers for tx, allow message pools
Use new m_msg_alloc/m_msg_free operations for whole-message
MCTP buffers. m_realloc is no longer used, instead the maximum
sized buffer is allocated for each reassembly.
This allows applications to keep a pool of MCTP message buffers.
Don't create a queue of packets to transmit, instead reuse a single
binding-provided tx_storage buffer for each transmitted packet, which
can be static for bindings that have a known maximum packet size.
Asynchronous users/bindings can no longer rely on the core for queueing
TX packets, instead they should test mctp_is_tx_ready() prior to calling
mctp_message_tx(). The stack will return -EBUSY from mctp_message_tx()
if there is already a message pending to send.
Bindings must be updated to add the tx_storage member, and the core will
no longer free packets passed to mctp_bus_rx().
Change-Id: I2598bb91026ccef01b268c52b06c0f8e20bebb1e
Signed-off-by: Matt Johnston <matt@codeconstruct.com.au>
diff --git a/tests/test_cmds.c b/tests/test_cmds.c
index ca5e838..2646b8c 100644
--- a/tests/test_cmds.c
+++ b/tests/test_cmds.c
@@ -50,6 +50,7 @@
struct mctp_pktbuf *pkt = mctp_pktbuf_alloc(b, len);
memcpy(mctp_pktbuf_hdr(pkt), buf, len);
mctp_bus_rx(b, pkt);
+ mctp_pktbuf_free(pkt);
}
static void setup_test_binding(struct mctp_binding *test_binding,
@@ -59,6 +60,7 @@
assert(test_endpoint != NULL);
assert(callback_ctx != NULL);
+ uint8_t tx_storage[MCTP_PKTBUF_SIZE(MCTP_BTU)];
memset(test_binding, 0, sizeof(*test_binding));
test_binding->name = "test";
test_binding->version = 1;
@@ -68,6 +70,7 @@
test_binding->pkt_trailer = 0;
test_binding->control_rx = control_message_transport_callback;
test_binding->control_rx_data = callback_ctx;
+ test_binding->tx_storage = tx_storage;
mctp_register_bus(test_endpoint, test_binding, eid_1);
mctp_binding_set_tx_enabled(test_binding, true);