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