API,core: Add reference from binding to mctp core
All of the prototype binding implementations so far have added a
reference to the core struct mctp from their binding.
This change adds a the struct mctp pointer to struct mctp_binding, so it
doesn't need to be included in every implementation.
This also allows us to drop the struct mctp * argument where we have a
reference to a binding.
Signed-off-by: Jeremy Kerr <jk@ozlabs.org>
diff --git a/core.c b/core.c
index c11564a..71b54ce 100644
--- a/core.c
+++ b/core.c
@@ -238,13 +238,14 @@
mctp->busses[0].binding = binding;
mctp->busses[0].eid = eid;
binding->bus = &mctp->busses[0];
+ binding->mctp = mctp;
return 0;
}
-void mctp_bus_rx(struct mctp *mctp, struct mctp_binding *binding,
- struct mctp_pktbuf *pkt)
+void mctp_bus_rx(struct mctp_binding *binding, struct mctp_pktbuf *pkt)
{
struct mctp_bus *bus = binding->bus;
+ struct mctp *mctp = binding->mctp;
struct mctp_msg_ctx *ctx;
struct mctp_hdr *hdr;
uint8_t flags, seq, tag;
@@ -318,8 +319,7 @@
}
}
-static int mctp_packet_tx(struct mctp *mctp __attribute__((unused)),
- struct mctp_bus *bus,
+static int mctp_packet_tx(struct mctp_bus *bus,
struct mctp_pktbuf *pkt)
{
return bus->binding->tx(bus->binding, pkt);
@@ -370,7 +370,7 @@
for (pkt = mctp->tx_queue_head; pkt;) {
mctp_prdebug("sending pkt, len %d",
mctp_pktbuf_size(pkt));
- mctp_packet_tx(mctp, bus, pkt);
+ mctp_packet_tx(bus, pkt);
tmp = pkt->next;
mctp_pktbuf_free(pkt);
pkt = tmp;
diff --git a/libmctp.h b/libmctp.h
index c477a2a..291b639 100644
--- a/libmctp.h
+++ b/libmctp.h
@@ -82,12 +82,12 @@
const char *name;
uint8_t version;
struct mctp_bus *bus;
+ struct mctp *mctp;
int (*tx)(struct mctp_binding *binding,
struct mctp_pktbuf *pkt);
};
-void mctp_bus_rx(struct mctp *mctp, struct mctp_binding *binding,
- struct mctp_pktbuf *pkt);
+void mctp_bus_rx(struct mctp_binding *binding, struct mctp_pktbuf *pkt);
/* environment-specific allocation */
void mctp_set_alloc_ops(void *(*alloc)(size_t),
diff --git a/serial.c b/serial.c
index 482cedb..c9f6c90 100644
--- a/serial.c
+++ b/serial.c
@@ -19,7 +19,6 @@
struct mctp_binding_serial {
struct mctp_binding binding;
- struct mctp *mctp;
int fd;
unsigned long bus_id;
@@ -138,7 +137,7 @@
assert(pkt);
if (valid)
- mctp_bus_rx(serial->mctp, &serial->binding, pkt);
+ mctp_bus_rx(&serial->binding, pkt);
mctp_pktbuf_free(pkt);
serial->rx_pkt = NULL;
@@ -294,7 +293,6 @@
struct mctp *mctp, mctp_eid_t eid)
{
assert(serial->fd >= 0);
- serial->mctp = mctp;
mctp_register_bus(mctp, &serial->binding, eid);
}