xref: /openbmc/libmctp/i2c-internal.h (revision e5b941d9)
1 /* SPDX-License-Identifier: Apache-2.0 OR GPL-2.0-or-later */
2 #pragma once
3 
4 #include <assert.h>
5 #include "libmctp.h"
6 #include "libmctp-i2c.h"
7 
8 /* Limited by bytecount field */
9 static_assert(I2C_BTU <= 254);
10 
11 #ifndef MCTP_I2C_NEIGH_COUNT
12 #define MCTP_I2C_NEIGH_COUNT 4
13 #endif
14 
15 struct mctp_i2c_hdr {
16 	uint8_t dest;
17 	uint8_t cmd;
18 	uint8_t bytecount;
19 	uint8_t source;
20 };
21 
22 struct mctp_i2c_neigh {
23 	bool used;
24 	/* 7-bit address */
25 	uint8_t addr;
26 	uint8_t eid;
27 	/* from platform_now(), for LRU eviction */
28 	uint64_t last_seen_timestamp;
29 };
30 
31 struct mctp_binding_i2c {
32 	struct mctp_binding binding;
33 
34 	struct mctp_i2c_neigh neigh[MCTP_I2C_NEIGH_COUNT];
35 
36 	uint8_t own_addr;
37 
38 	uint8_t tx_storage[sizeof(struct mctp_i2c_hdr) +
39 			   MCTP_PKTBUF_SIZE(I2C_BTU)] __attribute((aligned(8)));
40 	uint8_t rx_storage[sizeof(struct mctp_i2c_hdr) +
41 			   MCTP_PKTBUF_SIZE(I2C_BTU)] __attribute((aligned(8)));
42 
43 	mctp_i2c_tx_fn tx_fn;
44 	void *tx_ctx;
45 };
46