commit | 1fe5899eacb2f736766be07fe1a053784ed016b3 | [log] [tgz] |
---|---|---|
author | Nikhil Namjoshi <nikhilnamjoshi@google.com> | Tue Jan 09 04:00:12 2024 +0000 |
committer | Nikhil Namjoshi <nikhilnamjoshi@google.com> | Wed Jan 10 20:30:29 2024 +0000 |
tree | 254904f436e70d9294d330736814879357b9c3df | |
parent | 5c90129312a384af5e27fdf96f8e79981ff32fe5 [diff] |
serial: Recover the state machine when a request's bytes are dropped Today we use the byte 0x7e to indicate serial framing flag and serial trailing flag as well. In cases, when a request fails due to certain bytes getting dropped, the libmctp serial state machine never recovers and all the subsequent requests fail. This is happens because the serial trailing flag is same as the framing flag. Assuming an example packet 7e 01 04 ff ff ff ff 85 72 7e where 7e -> MCTP Serial Framing Flag 01 -> MCTP Serial Revision 04 -> Length of the Data bytes Next 4 bytes -> Data Bytes 85 -> fcs1 72 -> fcs2 7e -> MCTP Serial Trailing Flag If some bytes are dropped (say 1st 4 bytes 7e 01 04 ff) in hardware or on the requester driver, then the libmctp responder state machine will catch this and drop all the packets until it gets the next MCTP Serial Framing Byte. However since the MCTP Serial Trailing byte of the current request is also 0x7e, the state machine would assume this to be start of the packet for next request and will soon realize that the next byte 0x7e (next request's MCTP Serial Framing Byte) is not MCTP_SERIAL_REVISION i.e. 0x01. So it will start dropping bytes for the next request too. We can recover from this scenario, as here the failed request's trailer flag would take us to STATE_WAIT_REVISION, where we will receive 0x7e (next request's framing flag) Tested: Verified the fix on a real scenario where bytes get dropped in USB hardware. The state machine responds with failure for the current request, but is able to process the next requests fine. Change-Id: I9d853876a9765671d0067df21aab006bcf116dbc Signed-off-by: Nikhil Namjoshi <nikhilnamjoshi@google.com>
This library is intended to be a portable implementation of the Management Component Transport Protocol (MCTP), as defined by DMTF standard "DSP0236", plus transport binding specifications.
The APIs and ABI of libmctp are not yet stablised as we continue to explore ways to present the MCTP protocol to firmware and applications. Please bear with us!
When we approach a complete implementation of DSP0236 we will consider the suitability of the API/ABI for stabilisation.
In the mean time, we'd like your feedback on the library's suitability for your environment.
To initialise the MCTP stack with a single hardware bus:
mctp = mctp_init()
: Initialise the MCTP corebinding = mctp_<binding>_init()
: Initialise a hardware bindingmctp_register_bus(mctp, binding, eid)
: Register the hardware binding with the core, using a predefined EIDThen, register a function call to be invoked when a message is received:
mctp_set_rx_all(mctp, function)
: Provide a callback to be invoked when a MCTP message is receivedOr transmit a message:
mctp_message_tx(mctp, message, len)
: Transmit a MCTP messageThe binding may require you to notify it to receive packets. For example, for the serial binding, the mctp_serial_read()
function should be invoked when the file-descriptor for the serial device has data available.
libmctp implements basic support for bridging between two hardware bindings. In this mode, bindings may have different MTUs, so packets are reassembled into their messages, then the messages are re-packetised for the outgoing binding.
For bridging between two endpoints, use the mctp_bridge_busses()
function:
mctp = mctp_init()
: Initialise the MCTP coreb1 = mctp_<binding>_init(); b2 = mctp_<binding>_init()
: Initialise two hardware bindingsmctp_bridge_busses(mctp, b1, b2)
: Setup bridgeNote that no EIDs are defined here; the bridge does not deliver any messages to a local rx callback, and messages are bridged as-is.
Hardware bindings provide a method for libmctp to send and receive packets to/from hardware. A binding defines a hardware specific structure (struct mctp_binding_<name>
), which wraps the generic binding (struct mctp_binding
):
struct mctp_binding_foo { struct mctp_binding binding; /* hardware-specific members here... */ };
The binding code then provides a method (_init
) to allocate and initialise the binding; this may be of any prototype (calling code will know what arguments to pass):
struct mctp_binding_foo *mctp_binding_foo_init(void);
or maybe the foo
binding needs a path argument:
struct mctp_binding_foo *mctp_binding_foo_init(const char *path);
The binding then needs to provide a function (_core
) to convert the hardware-specific struct to the libmctp generic core struct
struct mctp_binding *mctp_binding_foo_core(struct mctp_binding_foo *b);
(Implementations of this will usually be fairly consistent, just returning b->binding
). Callers can then use that generic pointer to register the binding with the core:
struct mctp_binding *binding = mctp_binding_foo_core(foo); mctp_register_bus(mctp, binding, 8);
The libmctp code is intended to be integrated into other codebases by two methods:
as a simple library (libmctp.{a,so}
) which can be compiled separately and linked into the containing project
as a set of sources to be included into the containing project (either imported, or as a git subtree/submodule)
For (1), you can use the top-level makefile to produce libmctp.a
.
For (2), the Makefile.inc
file provides the minimum set of dependencies to either build libmctp.a, or just the actual object files (LIBMCTP_OBS
), which you can include into your existing make definitions. You'll want to set LIBMTCP_DIR
to refer to the subdirectory that contains that makefile, so we can set the correct paths to sources.
This library is intended to be portable to be used in a range of environments, but the main targets are:
For the latter, we need to support customisation of the functions that libmctp uses (for example, POSIX file IO is not available).
In order to support these, we have a few compile-time definitions:
MCTP_HAVE_FILEIO
: define if POSIX file io is available, allowing the serial hardware binding to access char devices for IO.
MCTP_HAVE_SYSLOG
: allow logging to syslog, through the vsyslog
call.
MCTP_DEFAULT_ALLOC
: set default allocator functions (malloc, free, realloc), so that applications do not have to provide their own.