astlpc: Make packet properties depend on protocol version
The astlpc binding will shortly have an implementation of the v3
protocol specification. v3 adjusts the medium-specific packet size to
include a CRC-32 in a packet trailer. Implementing v3 must not impact
the behaviour of earlier protocol versions, so provide an ops struct to
handle version-specific details.
Signed-off-by: Andrew Jeffery <andrew@aj.id.au>
Change-Id: Iab04defa76b57a592442189e6ade58f25ed1d9ae
diff --git a/tests/test_astlpc.c b/tests/test_astlpc.c
index b64100b..632cd6d 100644
--- a/tests/test_astlpc.c
+++ b/tests/test_astlpc.c
@@ -718,7 +718,10 @@
free(lpc_mem);
}
-#define BUFFER_MIN ASTLPC_PACKET_SIZE(MCTP_PACKET_SIZE(MCTP_BTU))
+#define BUFFER_MIN (MCTP_PACKET_SIZE(MCTP_BTU) + 4)
+static const struct mctp_binding_astlpc astlpc_layout_ctx = {
+ .proto = &astlpc_protocol_version[2],
+};
static void astlpc_test_buffers_rx_offset_overflow(void)
{
@@ -727,7 +730,7 @@
.tx = { control_size, BUFFER_MIN },
};
- assert(!mctp_astlpc_layout_validate(&l));
+ assert(!mctp_astlpc_layout_validate(&astlpc_layout_ctx, &l));
}
static void astlpc_test_buffers_tx_offset_overflow(void)
@@ -737,7 +740,7 @@
.tx = { UINT32_MAX, BUFFER_MIN },
};
- assert(!mctp_astlpc_layout_validate(&l));
+ assert(!mctp_astlpc_layout_validate(&astlpc_layout_ctx, &l));
}
static void astlpc_test_buffers_rx_size_overflow(void)
@@ -747,7 +750,7 @@
.tx = { control_size, BUFFER_MIN },
};
- assert(!mctp_astlpc_layout_validate(&l));
+ assert(!mctp_astlpc_layout_validate(&astlpc_layout_ctx, &l));
}
static void astlpc_test_buffers_tx_size_overflow(void)
@@ -757,7 +760,7 @@
.tx = { control_size + BUFFER_MIN, UINT32_MAX },
};
- assert(!mctp_astlpc_layout_validate(&l));
+ assert(!mctp_astlpc_layout_validate(&astlpc_layout_ctx, &l));
}
static void astlpc_test_buffers_rx_window_violation(void)
@@ -767,7 +770,7 @@
.tx = { control_size, BUFFER_MIN },
};
- assert(!mctp_astlpc_layout_validate(&l));
+ assert(!mctp_astlpc_layout_validate(&astlpc_layout_ctx, &l));
}
static void astlpc_test_buffers_tx_window_violation(void)
@@ -777,7 +780,7 @@
.tx = { LPC_WIN_SIZE - BUFFER_MIN + 1, BUFFER_MIN },
};
- assert(!mctp_astlpc_layout_validate(&l));
+ assert(!mctp_astlpc_layout_validate(&astlpc_layout_ctx, &l));
}
static void astlpc_test_buffers_rx_size_fails_btu(void)
@@ -787,7 +790,7 @@
.tx = { control_size + BUFFER_MIN, BUFFER_MIN },
};
- assert(!mctp_astlpc_layout_validate(&l));
+ assert(!mctp_astlpc_layout_validate(&astlpc_layout_ctx, &l));
}
static void astlpc_test_buffers_tx_size_fails_btu(void)
@@ -797,7 +800,7 @@
.tx = { control_size + BUFFER_MIN, BUFFER_MIN - 1 },
};
- assert(!mctp_astlpc_layout_validate(&l));
+ assert(!mctp_astlpc_layout_validate(&astlpc_layout_ctx, &l));
}
static void astlpc_test_buffers_overlap_rx_low(void)
@@ -807,7 +810,7 @@
.tx = { control_size + BUFFER_MIN, 2 * BUFFER_MIN },
};
- assert(!mctp_astlpc_layout_validate(&l));
+ assert(!mctp_astlpc_layout_validate(&astlpc_layout_ctx, &l));
}
static void astlpc_test_buffers_overlap_tx_low(void)
@@ -817,7 +820,7 @@
.tx = { control_size, 2 * BUFFER_MIN },
};
- assert(!mctp_astlpc_layout_validate(&l));
+ assert(!mctp_astlpc_layout_validate(&astlpc_layout_ctx, &l));
}
static void astlpc_test_buffers_overlap_exact(void)
@@ -827,7 +830,7 @@
.tx = { control_size, 2 * BUFFER_MIN },
};
- assert(!mctp_astlpc_layout_validate(&l));
+ assert(!mctp_astlpc_layout_validate(&astlpc_layout_ctx, &l));
}
static void astlpc_test_buffers_overlap_control(void)
@@ -837,7 +840,7 @@
.tx = { control_size + BUFFER_MIN, BUFFER_MIN },
};
- assert(!mctp_astlpc_layout_validate(&l));
+ assert(!mctp_astlpc_layout_validate(&astlpc_layout_ctx, &l));
}
static void astlpc_test_buffers_bad_host_proposal(void)
@@ -1017,6 +1020,7 @@
{
struct astlpc_endpoint bmc, host;
uint8_t kcs[2] = { 0 };
+ uint32_t bmtu, hmtu;
void *lpc_mem;
int rc;
@@ -1025,13 +1029,15 @@
assert(lpc_mem);
/* BMC initialisation */
- rc = endpoint_init(&bmc, 8, MCTP_BINDING_ASTLPC_MODE_BMC, 3 * MCTP_BTU,
- &kcs, lpc_mem);
+ bmtu = 3 * MCTP_BTU;
+ rc = endpoint_init(&bmc, 8, MCTP_BINDING_ASTLPC_MODE_BMC, bmtu, &kcs,
+ lpc_mem);
assert(!rc);
/* Host initialisation with low MTU */
- rc = endpoint_init(&host, 9, MCTP_BINDING_ASTLPC_MODE_HOST,
- 2 * MCTP_BTU, &kcs, lpc_mem);
+ hmtu = 2 * MCTP_BTU;
+ rc = endpoint_init(&host, 9, MCTP_BINDING_ASTLPC_MODE_HOST, hmtu, &kcs,
+ lpc_mem);
assert(!rc);
/* Process low MTU proposal */
@@ -1043,7 +1049,7 @@
assert(rc == 0);
assert(host.astlpc->layout.rx.size ==
- ASTLPC_PACKET_SIZE(MCTP_PACKET_SIZE(2 * MCTP_BTU)));
+ astlpc_layout_ctx.proto->packet_size(MCTP_PACKET_SIZE(hmtu)));
/* Tear-down the host so we can bring up a new one */
endpoint_destroy(&host);
@@ -1052,8 +1058,9 @@
* Bring up a new host endpoint with a higher MTU than we previously
* negotiated
*/
- rc = endpoint_init(&host, 9, MCTP_BINDING_ASTLPC_MODE_HOST,
- 3 * MCTP_BTU, &kcs, lpc_mem);
+ hmtu = 3 * MCTP_BTU;
+ rc = endpoint_init(&host, 9, MCTP_BINDING_ASTLPC_MODE_HOST, hmtu, &kcs,
+ lpc_mem);
assert(!rc);
/* Process high MTU proposal */
@@ -1065,7 +1072,7 @@
assert(rc == 0);
assert(host.astlpc->layout.rx.size ==
- ASTLPC_PACKET_SIZE(MCTP_PACKET_SIZE(3 * MCTP_BTU)));
+ astlpc_layout_ctx.proto->packet_size(MCTP_PACKET_SIZE(bmtu)));
endpoint_destroy(&host);
endpoint_destroy(&bmc);