Andrew Jeffery | 0247c73 | 2020-02-06 11:48:52 +1030 | [diff] [blame] | 1 | /* SPDX-License-Identifier: Apache-2.0 OR GPL-2.0-or-later */ |
| 2 | |
Andrew Jeffery | 2cda40f | 2020-02-28 15:26:20 +1030 | [diff] [blame] | 3 | #ifdef HAVE_CONFIG_H |
Andrew Jeffery | 0247c73 | 2020-02-06 11:48:52 +1030 | [diff] [blame] | 4 | #include "config.h" |
Andrew Jeffery | 2cda40f | 2020-02-28 15:26:20 +1030 | [diff] [blame] | 5 | #endif |
| 6 | |
Andrew Jeffery | df5f6b9 | 2020-05-12 21:39:06 +0930 | [diff] [blame] | 7 | #include "astlpc.c" |
| 8 | |
| 9 | #ifdef pr_fmt |
| 10 | #undef pr_fmt |
| 11 | #define pr_fmt(x) "test: " x |
| 12 | #endif |
| 13 | |
Andrew Jeffery | 0247c73 | 2020-02-06 11:48:52 +1030 | [diff] [blame] | 14 | #include "libmctp-astlpc.h" |
| 15 | #include "libmctp-log.h" |
Przemyslaw Czarnowski | ff25d7e | 2020-03-26 11:39:37 +0100 | [diff] [blame] | 16 | #include "container_of.h" |
Andrew Jeffery | 0247c73 | 2020-02-06 11:48:52 +1030 | [diff] [blame] | 17 | |
| 18 | #ifdef NDEBUG |
| 19 | #undef NDEBUG |
| 20 | #endif |
| 21 | |
Andrew Jeffery | 0247c73 | 2020-02-06 11:48:52 +1030 | [diff] [blame] | 22 | #include <assert.h> |
| 23 | #include <stdint.h> |
| 24 | #include <stdio.h> |
| 25 | #include <stdlib.h> |
| 26 | #include <string.h> |
| 27 | |
Andrew Jeffery | 0247c73 | 2020-02-06 11:48:52 +1030 | [diff] [blame] | 28 | struct mctp_binding_astlpc_mmio { |
| 29 | struct mctp_binding_astlpc astlpc; |
Andrew Jeffery | d5e3cd7 | 2020-05-12 22:10:22 +0930 | [diff] [blame] | 30 | bool bmc; |
Andrew Jeffery | 0247c73 | 2020-02-06 11:48:52 +1030 | [diff] [blame] | 31 | |
Andrew Jeffery | d5e3cd7 | 2020-05-12 22:10:22 +0930 | [diff] [blame] | 32 | uint8_t (*kcs)[2]; |
Andrew Jeffery | 0247c73 | 2020-02-06 11:48:52 +1030 | [diff] [blame] | 33 | |
| 34 | size_t lpc_size; |
| 35 | uint8_t *lpc; |
| 36 | }; |
| 37 | |
Andrew Jeffery | 5a7c2db | 2020-05-22 20:13:42 +0930 | [diff] [blame] | 38 | struct astlpc_endpoint { |
| 39 | struct mctp_binding_astlpc_mmio mmio; |
| 40 | struct mctp_binding_astlpc *astlpc; |
| 41 | struct mctp *mctp; |
| 42 | }; |
| 43 | |
| 44 | struct astlpc_test { |
| 45 | struct astlpc_endpoint bmc; |
| 46 | struct astlpc_endpoint host; |
| 47 | uint8_t kcs[2]; |
| 48 | uint8_t *lpc_mem; |
| 49 | |
| 50 | void *msg; |
| 51 | uint8_t count; |
| 52 | }; |
| 53 | |
| 54 | #define binding_to_mmio(b) \ |
Andrew Jeffery | 0247c73 | 2020-02-06 11:48:52 +1030 | [diff] [blame] | 55 | container_of(b, struct mctp_binding_astlpc_mmio, astlpc) |
| 56 | |
Andrew Jeffery | 53ea147 | 2020-05-23 21:06:24 +0930 | [diff] [blame] | 57 | static int mctp_astlpc_mmio_kcs_read(void *data, |
| 58 | enum mctp_binding_astlpc_kcs_reg reg, |
| 59 | uint8_t *val) |
Andrew Jeffery | 0247c73 | 2020-02-06 11:48:52 +1030 | [diff] [blame] | 60 | { |
| 61 | struct mctp_binding_astlpc_mmio *mmio = binding_to_mmio(data); |
| 62 | |
Andrew Jeffery | d5e3cd7 | 2020-05-12 22:10:22 +0930 | [diff] [blame] | 63 | *val = (*mmio->kcs)[reg]; |
Andrew Jeffery | 0247c73 | 2020-02-06 11:48:52 +1030 | [diff] [blame] | 64 | |
Andrew Jeffery | d3c0bf0 | 2020-05-28 15:28:40 +0930 | [diff] [blame] | 65 | mctp_prdebug("%s: 0x%hhx from %s", __func__, *val, |
| 66 | reg ? "status" : "data"); |
Andrew Jeffery | 0247c73 | 2020-02-06 11:48:52 +1030 | [diff] [blame] | 67 | |
Andrew Jeffery | d5e3cd7 | 2020-05-12 22:10:22 +0930 | [diff] [blame] | 68 | if (reg == MCTP_ASTLPC_KCS_REG_DATA) { |
| 69 | uint8_t flag = mmio->bmc ? KCS_STATUS_IBF : KCS_STATUS_OBF; |
| 70 | (*mmio->kcs)[MCTP_ASTLPC_KCS_REG_STATUS] &= ~flag; |
| 71 | } |
Andrew Jeffery | 0247c73 | 2020-02-06 11:48:52 +1030 | [diff] [blame] | 72 | |
| 73 | return 0; |
| 74 | } |
| 75 | |
Andrew Jeffery | 53ea147 | 2020-05-23 21:06:24 +0930 | [diff] [blame] | 76 | static int mctp_astlpc_mmio_kcs_write(void *data, |
| 77 | enum mctp_binding_astlpc_kcs_reg reg, |
| 78 | uint8_t val) |
Andrew Jeffery | 0247c73 | 2020-02-06 11:48:52 +1030 | [diff] [blame] | 79 | { |
| 80 | struct mctp_binding_astlpc_mmio *mmio = binding_to_mmio(data); |
Andrew Jeffery | d5e3cd7 | 2020-05-12 22:10:22 +0930 | [diff] [blame] | 81 | uint8_t *regp; |
Andrew Jeffery | 0247c73 | 2020-02-06 11:48:52 +1030 | [diff] [blame] | 82 | |
Andrew Jeffery | d5e3cd7 | 2020-05-12 22:10:22 +0930 | [diff] [blame] | 83 | assert(reg == MCTP_ASTLPC_KCS_REG_DATA || |
| 84 | reg == MCTP_ASTLPC_KCS_REG_STATUS); |
Andrew Jeffery | 0247c73 | 2020-02-06 11:48:52 +1030 | [diff] [blame] | 85 | |
Andrew Jeffery | d5e3cd7 | 2020-05-12 22:10:22 +0930 | [diff] [blame] | 86 | if (reg == MCTP_ASTLPC_KCS_REG_DATA) { |
| 87 | uint8_t flag = mmio->bmc ? KCS_STATUS_OBF : KCS_STATUS_IBF; |
| 88 | (*mmio->kcs)[MCTP_ASTLPC_KCS_REG_STATUS] |= flag; |
| 89 | } |
| 90 | |
| 91 | regp = &(*mmio->kcs)[reg]; |
Andrew Jeffery | 0247c73 | 2020-02-06 11:48:52 +1030 | [diff] [blame] | 92 | if (reg == MCTP_ASTLPC_KCS_REG_STATUS) |
Andrew Jeffery | d5e3cd7 | 2020-05-12 22:10:22 +0930 | [diff] [blame] | 93 | *regp = (val & ~0xbU) | (val & *regp & 1); |
Andrew Jeffery | 0247c73 | 2020-02-06 11:48:52 +1030 | [diff] [blame] | 94 | else |
Andrew Jeffery | d5e3cd7 | 2020-05-12 22:10:22 +0930 | [diff] [blame] | 95 | *regp = val; |
Andrew Jeffery | 0247c73 | 2020-02-06 11:48:52 +1030 | [diff] [blame] | 96 | |
Andrew Jeffery | d3c0bf0 | 2020-05-28 15:28:40 +0930 | [diff] [blame] | 97 | mctp_prdebug("%s: 0x%hhx to %s", __func__, val, |
| 98 | reg ? "status" : "data"); |
Andrew Jeffery | 0247c73 | 2020-02-06 11:48:52 +1030 | [diff] [blame] | 99 | |
| 100 | return 0; |
| 101 | } |
Andrew Jeffery | 06b2cd8 | 2020-03-17 23:12:27 +1030 | [diff] [blame] | 102 | int mctp_astlpc_mmio_lpc_read(void *data, void *buf, long offset, size_t len) |
Andrew Jeffery | 0247c73 | 2020-02-06 11:48:52 +1030 | [diff] [blame] | 103 | { |
| 104 | struct mctp_binding_astlpc_mmio *mmio = binding_to_mmio(data); |
| 105 | |
Andrew Jeffery | 1dbf021 | 2020-05-12 13:53:50 +0930 | [diff] [blame] | 106 | mctp_prdebug("%s: %zu bytes from 0x%lx", __func__, len, offset); |
| 107 | |
Andrew Jeffery | 06b2cd8 | 2020-03-17 23:12:27 +1030 | [diff] [blame] | 108 | assert(offset >= 0L); |
Andrew Jeffery | 0247c73 | 2020-02-06 11:48:52 +1030 | [diff] [blame] | 109 | assert(offset + len < mmio->lpc_size); |
| 110 | |
| 111 | memcpy(buf, mmio->lpc + offset, len); |
| 112 | |
Andrew Jeffery | 0247c73 | 2020-02-06 11:48:52 +1030 | [diff] [blame] | 113 | return 0; |
| 114 | } |
| 115 | |
Andrew Jeffery | 06b2cd8 | 2020-03-17 23:12:27 +1030 | [diff] [blame] | 116 | int mctp_astlpc_mmio_lpc_write(void *data, void *buf, long offset, size_t len) |
Andrew Jeffery | 0247c73 | 2020-02-06 11:48:52 +1030 | [diff] [blame] | 117 | { |
| 118 | struct mctp_binding_astlpc_mmio *mmio = binding_to_mmio(data); |
| 119 | |
Andrew Jeffery | 1dbf021 | 2020-05-12 13:53:50 +0930 | [diff] [blame] | 120 | mctp_prdebug("%s: %zu bytes to 0x%lx", __func__, len, offset); |
| 121 | |
Andrew Jeffery | 06b2cd8 | 2020-03-17 23:12:27 +1030 | [diff] [blame] | 122 | assert(offset >= 0L); |
Andrew Jeffery | 0247c73 | 2020-02-06 11:48:52 +1030 | [diff] [blame] | 123 | assert(offset + len < mmio->lpc_size); |
| 124 | |
| 125 | memcpy(mmio->lpc + offset, buf, len); |
| 126 | |
Andrew Jeffery | 0247c73 | 2020-02-06 11:48:52 +1030 | [diff] [blame] | 127 | return 0; |
| 128 | } |
| 129 | |
Andrew Jeffery | b93b611 | 2020-06-05 14:13:44 +0930 | [diff] [blame] | 130 | #define __unused __attribute__((unused)) |
| 131 | |
| 132 | static void rx_message(uint8_t eid __unused, void *data __unused, void *msg, |
| 133 | size_t len) |
Andrew Jeffery | 0247c73 | 2020-02-06 11:48:52 +1030 | [diff] [blame] | 134 | { |
Andrew Jeffery | 5a7c2db | 2020-05-22 20:13:42 +0930 | [diff] [blame] | 135 | struct astlpc_test *test = data; |
Andrew Jeffery | 0247c73 | 2020-02-06 11:48:52 +1030 | [diff] [blame] | 136 | |
Andrew Jeffery | 5a7c2db | 2020-05-22 20:13:42 +0930 | [diff] [blame] | 137 | mctp_prdebug("MCTP message received: msg: %p, len %zd", msg, len); |
Andrew Jeffery | 0247c73 | 2020-02-06 11:48:52 +1030 | [diff] [blame] | 138 | |
Andrew Jeffery | 5a7c2db | 2020-05-22 20:13:42 +0930 | [diff] [blame] | 139 | assert(len > 0); |
| 140 | assert(msg); |
| 141 | assert(test); |
| 142 | assert(test->msg); |
| 143 | assert(!memcmp(test->msg, msg, len)); |
| 144 | |
| 145 | test->count++; |
Andrew Jeffery | 0247c73 | 2020-02-06 11:48:52 +1030 | [diff] [blame] | 146 | } |
| 147 | |
Andrew Jeffery | 53ea147 | 2020-05-23 21:06:24 +0930 | [diff] [blame] | 148 | static const struct mctp_binding_astlpc_ops mctp_binding_astlpc_mmio_ops = { |
Andrew Jeffery | 0247c73 | 2020-02-06 11:48:52 +1030 | [diff] [blame] | 149 | .kcs_read = mctp_astlpc_mmio_kcs_read, |
| 150 | .kcs_write = mctp_astlpc_mmio_kcs_write, |
| 151 | .lpc_read = mctp_astlpc_mmio_lpc_read, |
| 152 | .lpc_write = mctp_astlpc_mmio_lpc_write, |
| 153 | }; |
| 154 | |
Andrew Jeffery | d5e3cd7 | 2020-05-12 22:10:22 +0930 | [diff] [blame] | 155 | static void endpoint_init(struct astlpc_endpoint *ep, mctp_eid_t eid, |
| 156 | uint8_t mode, uint8_t (*kcs)[2], void *lpc_mem, |
| 157 | size_t lpc_size) |
| 158 | { |
| 159 | /* |
| 160 | * Configure the direction of the KCS interface so we know whether to |
| 161 | * set or clear IBF or OBF on writes or reads. |
| 162 | */ |
| 163 | ep->mmio.bmc = (mode == MCTP_BINDING_ASTLPC_MODE_BMC); |
| 164 | |
| 165 | ep->mctp = mctp_init(); |
| 166 | assert(ep->mctp); |
| 167 | |
Andrew Jeffery | d5e3cd7 | 2020-05-12 22:10:22 +0930 | [diff] [blame] | 168 | /* Inject KCS registers */ |
| 169 | ep->mmio.kcs = kcs; |
| 170 | |
| 171 | /* Inject the heap allocation as the LPC mapping */ |
| 172 | ep->mmio.lpc_size = lpc_size; |
| 173 | ep->mmio.lpc = lpc_mem; |
| 174 | |
| 175 | /* Initialise the binding */ |
Andrew Jeffery | 129ef93 | 2020-05-22 16:24:19 +0930 | [diff] [blame] | 176 | ep->astlpc = mctp_astlpc_init(mode, MCTP_BTU, lpc_mem, |
Andrew Jeffery | d5e3cd7 | 2020-05-12 22:10:22 +0930 | [diff] [blame] | 177 | &mctp_binding_astlpc_mmio_ops, &ep->mmio); |
| 178 | |
| 179 | mctp_register_bus(ep->mctp, &ep->astlpc->binding, eid); |
| 180 | } |
| 181 | |
| 182 | static void endpoint_destroy(struct astlpc_endpoint *ep) |
| 183 | { |
| 184 | mctp_astlpc_destroy(ep->astlpc); |
| 185 | mctp_destroy(ep->mctp); |
| 186 | } |
| 187 | |
Andrew Jeffery | cb5d55c | 2020-05-22 13:26:27 +0930 | [diff] [blame] | 188 | static void network_init(struct astlpc_test *ctx) |
| 189 | { |
| 190 | const size_t lpc_size = 1 * 1024 * 1024; |
| 191 | |
| 192 | ctx->lpc_mem = calloc(1, lpc_size); |
| 193 | assert(ctx->lpc_mem); |
| 194 | |
| 195 | /* BMC initialisation */ |
| 196 | endpoint_init(&ctx->bmc, 8, MCTP_BINDING_ASTLPC_MODE_BMC, &ctx->kcs, |
| 197 | ctx->lpc_mem, lpc_size); |
| 198 | |
| 199 | /* Host initialisation */ |
| 200 | endpoint_init(&ctx->host, 9, MCTP_BINDING_ASTLPC_MODE_HOST, &ctx->kcs, |
| 201 | ctx->lpc_mem, lpc_size); |
| 202 | |
| 203 | /* BMC processes host channel init request, alerts host */ |
| 204 | mctp_astlpc_poll(ctx->bmc.astlpc); |
| 205 | assert(ctx->kcs[KCS_REG_STATUS] & KCS_STATUS_CHANNEL_ACTIVE); |
| 206 | assert(ctx->kcs[KCS_REG_DATA] == 0xff); |
| 207 | |
| 208 | /* Host dequeues channel init result */ |
| 209 | mctp_astlpc_poll(ctx->host.astlpc); |
| 210 | } |
| 211 | |
| 212 | static void network_destroy(struct astlpc_test *ctx) |
| 213 | { |
| 214 | endpoint_destroy(&ctx->bmc); |
| 215 | endpoint_destroy(&ctx->host); |
| 216 | free(ctx->lpc_mem); |
| 217 | } |
| 218 | |
Andrew Jeffery | 129ef93 | 2020-05-22 16:24:19 +0930 | [diff] [blame] | 219 | static void astlpc_assert_tx_packet(struct astlpc_endpoint *src, |
| 220 | const void *expected, size_t len) |
| 221 | { |
| 222 | const size_t tx_body = src->astlpc->layout.tx.offset + 4 + 4; |
| 223 | const void *test = ((char *)src->astlpc->lpc_map) + tx_body; |
| 224 | assert(!memcmp(test, expected, len)); |
| 225 | } |
| 226 | |
Andrew Jeffery | e756de8 | 2020-05-22 12:30:58 +0930 | [diff] [blame] | 227 | static void astlpc_test_packetised_message_bmc_to_host(void) |
Andrew Jeffery | d5e3cd7 | 2020-05-12 22:10:22 +0930 | [diff] [blame] | 228 | { |
Andrew Jeffery | cb5d55c | 2020-05-22 13:26:27 +0930 | [diff] [blame] | 229 | struct astlpc_test ctx = { 0 }; |
Andrew Jeffery | d5e3cd7 | 2020-05-12 22:10:22 +0930 | [diff] [blame] | 230 | uint8_t msg[2 * MCTP_BTU]; |
Andrew Jeffery | 0247c73 | 2020-02-06 11:48:52 +1030 | [diff] [blame] | 231 | int rc; |
| 232 | |
Andrew Jeffery | d5e3cd7 | 2020-05-12 22:10:22 +0930 | [diff] [blame] | 233 | /* Test harness initialisation */ |
| 234 | |
Andrew Jeffery | 5a7c2db | 2020-05-22 20:13:42 +0930 | [diff] [blame] | 235 | network_init(&ctx); |
| 236 | |
Andrew Jeffery | 0247c73 | 2020-02-06 11:48:52 +1030 | [diff] [blame] | 237 | memset(&msg[0], 0x5a, MCTP_BTU); |
| 238 | memset(&msg[MCTP_BTU], 0xa5, MCTP_BTU); |
| 239 | |
Andrew Jeffery | 5a7c2db | 2020-05-22 20:13:42 +0930 | [diff] [blame] | 240 | ctx.msg = &msg[0]; |
| 241 | ctx.count = 0; |
| 242 | mctp_set_rx_all(ctx.host.mctp, rx_message, &ctx); |
Andrew Jeffery | 0247c73 | 2020-02-06 11:48:52 +1030 | [diff] [blame] | 243 | |
| 244 | /* BMC sends a message */ |
Andrew Jeffery | cb5d55c | 2020-05-22 13:26:27 +0930 | [diff] [blame] | 245 | rc = mctp_message_tx(ctx.bmc.mctp, 9, msg, sizeof(msg)); |
Andrew Jeffery | 0247c73 | 2020-02-06 11:48:52 +1030 | [diff] [blame] | 246 | assert(rc == 0); |
Andrew Jeffery | d5e3cd7 | 2020-05-12 22:10:22 +0930 | [diff] [blame] | 247 | |
Andrew Jeffery | 129ef93 | 2020-05-22 16:24:19 +0930 | [diff] [blame] | 248 | /* Host receives the first packet */ |
Andrew Jeffery | cb5d55c | 2020-05-22 13:26:27 +0930 | [diff] [blame] | 249 | mctp_astlpc_poll(ctx.host.astlpc); |
Andrew Jeffery | 0247c73 | 2020-02-06 11:48:52 +1030 | [diff] [blame] | 250 | |
Andrew Jeffery | 0247c73 | 2020-02-06 11:48:52 +1030 | [diff] [blame] | 251 | /* BMC dequeues ownership hand-over and sends the queued packet */ |
Andrew Jeffery | cb5d55c | 2020-05-22 13:26:27 +0930 | [diff] [blame] | 252 | rc = mctp_astlpc_poll(ctx.bmc.astlpc); |
Andrew Jeffery | 0247c73 | 2020-02-06 11:48:52 +1030 | [diff] [blame] | 253 | assert(rc == 0); |
| 254 | |
Andrew Jeffery | 129ef93 | 2020-05-22 16:24:19 +0930 | [diff] [blame] | 255 | /* Host receives the next packet */ |
Andrew Jeffery | cb5d55c | 2020-05-22 13:26:27 +0930 | [diff] [blame] | 256 | assert(ctx.kcs[MCTP_ASTLPC_KCS_REG_STATUS] & KCS_STATUS_OBF); |
| 257 | assert(ctx.kcs[MCTP_ASTLPC_KCS_REG_DATA] == 0x01); |
Andrew Jeffery | 0247c73 | 2020-02-06 11:48:52 +1030 | [diff] [blame] | 258 | |
Andrew Jeffery | 129ef93 | 2020-05-22 16:24:19 +0930 | [diff] [blame] | 259 | astlpc_assert_tx_packet(&ctx.bmc, &msg[MCTP_BTU], MCTP_BTU); |
Andrew Jeffery | 0247c73 | 2020-02-06 11:48:52 +1030 | [diff] [blame] | 260 | |
Andrew Jeffery | 5a7c2db | 2020-05-22 20:13:42 +0930 | [diff] [blame] | 261 | /* Host receives final packet */ |
| 262 | mctp_astlpc_poll(ctx.host.astlpc); |
| 263 | assert(ctx.count == 1); |
| 264 | |
Andrew Jeffery | cb5d55c | 2020-05-22 13:26:27 +0930 | [diff] [blame] | 265 | network_destroy(&ctx); |
Andrew Jeffery | e756de8 | 2020-05-22 12:30:58 +0930 | [diff] [blame] | 266 | } |
| 267 | |
Andrew Jeffery | 8f3eb72 | 2020-05-22 20:23:49 +0930 | [diff] [blame^] | 268 | static void astlpc_test_simple_message_bmc_to_host(void) |
| 269 | { |
| 270 | struct astlpc_test ctx = { 0 }; |
| 271 | uint8_t msg[MCTP_BTU]; |
| 272 | int rc; |
| 273 | |
| 274 | /* Test harness initialisation */ |
| 275 | |
| 276 | network_init(&ctx); |
| 277 | |
| 278 | memset(&msg[0], 0x5a, MCTP_BTU); |
| 279 | |
| 280 | ctx.msg = &msg[0]; |
| 281 | ctx.count = 0; |
| 282 | mctp_set_rx_all(ctx.host.mctp, rx_message, &ctx); |
| 283 | |
| 284 | /* BMC sends the single-packet message */ |
| 285 | rc = mctp_message_tx(ctx.bmc.mctp, 9, msg, sizeof(msg)); |
| 286 | assert(rc == 0); |
| 287 | assert(ctx.kcs[MCTP_ASTLPC_KCS_REG_STATUS] & KCS_STATUS_OBF); |
| 288 | assert(ctx.kcs[MCTP_ASTLPC_KCS_REG_DATA] == 0x01); |
| 289 | |
| 290 | astlpc_assert_tx_packet(&ctx.bmc, &msg[0], MCTP_BTU); |
| 291 | |
| 292 | /* Host receives the single-packet message */ |
| 293 | mctp_astlpc_poll(ctx.host.astlpc); |
| 294 | assert(ctx.count == 1); |
| 295 | |
| 296 | /* Host returns Rx area ownership to BMC */ |
| 297 | assert(!(ctx.kcs[MCTP_ASTLPC_KCS_REG_STATUS] & KCS_STATUS_OBF)); |
| 298 | assert(ctx.kcs[MCTP_ASTLPC_KCS_REG_DATA] == 0x02); |
| 299 | assert(ctx.kcs[MCTP_ASTLPC_KCS_REG_STATUS] & KCS_STATUS_IBF); |
| 300 | |
| 301 | /* BMC dequeues ownership hand-over and sends the queued packet */ |
| 302 | rc = mctp_astlpc_poll(ctx.bmc.astlpc); |
| 303 | assert(rc == 0); |
| 304 | |
| 305 | network_destroy(&ctx); |
| 306 | } |
| 307 | |
Andrew Jeffery | f1a2131 | 2020-05-22 12:48:21 +0930 | [diff] [blame] | 308 | static void astlpc_test_simple_init(void) |
| 309 | { |
| 310 | struct astlpc_endpoint bmc, host; |
| 311 | uint8_t kcs[2] = { 0 }; |
| 312 | size_t lpc_size; |
| 313 | void *lpc_mem; |
| 314 | |
| 315 | /* Test harness initialisation */ |
| 316 | lpc_size = 1 * 1024 * 1024; |
| 317 | lpc_mem = calloc(1, lpc_size); |
| 318 | assert(lpc_mem); |
| 319 | |
Andrew Jeffery | 8f3eb72 | 2020-05-22 20:23:49 +0930 | [diff] [blame^] | 320 | /* BMC initialisation */ |
Andrew Jeffery | f1a2131 | 2020-05-22 12:48:21 +0930 | [diff] [blame] | 321 | endpoint_init(&bmc, 8, MCTP_BINDING_ASTLPC_MODE_BMC, &kcs, lpc_mem, |
| 322 | lpc_size); |
| 323 | |
| 324 | /* Verify the BMC binding was initialised */ |
| 325 | assert(kcs[MCTP_ASTLPC_KCS_REG_STATUS] & KCS_STATUS_BMC_READY); |
| 326 | |
Andrew Jeffery | 8f3eb72 | 2020-05-22 20:23:49 +0930 | [diff] [blame^] | 327 | /* Host initialisation */ |
Andrew Jeffery | f1a2131 | 2020-05-22 12:48:21 +0930 | [diff] [blame] | 328 | endpoint_init(&host, 9, MCTP_BINDING_ASTLPC_MODE_HOST, &kcs, lpc_mem, |
| 329 | lpc_size); |
| 330 | |
| 331 | /* Host sends channel init command */ |
| 332 | assert(kcs[MCTP_ASTLPC_KCS_REG_STATUS] & KCS_STATUS_IBF); |
| 333 | assert(kcs[MCTP_ASTLPC_KCS_REG_DATA] == 0x00); |
| 334 | |
| 335 | /* BMC receives host channel init request */ |
| 336 | mctp_astlpc_poll(bmc.astlpc); |
| 337 | |
| 338 | /* BMC sends init response */ |
| 339 | assert(kcs[MCTP_ASTLPC_KCS_REG_STATUS] & KCS_STATUS_OBF); |
| 340 | assert(kcs[MCTP_ASTLPC_KCS_REG_STATUS] & KCS_STATUS_CHANNEL_ACTIVE); |
| 341 | assert(kcs[MCTP_ASTLPC_KCS_REG_DATA] == 0xff); |
| 342 | |
| 343 | /* Host dequeues data */ |
| 344 | mctp_astlpc_poll(host.astlpc); |
| 345 | |
| 346 | endpoint_destroy(&bmc); |
| 347 | endpoint_destroy(&host); |
| 348 | free(lpc_mem); |
| 349 | } |
| 350 | |
Andrew Jeffery | e756de8 | 2020-05-22 12:30:58 +0930 | [diff] [blame] | 351 | int main(void) |
| 352 | { |
| 353 | mctp_set_log_stdio(MCTP_LOG_DEBUG); |
| 354 | |
Andrew Jeffery | f1a2131 | 2020-05-22 12:48:21 +0930 | [diff] [blame] | 355 | astlpc_test_simple_init(); |
Andrew Jeffery | 8f3eb72 | 2020-05-22 20:23:49 +0930 | [diff] [blame^] | 356 | astlpc_test_simple_message_bmc_to_host(); |
Andrew Jeffery | e756de8 | 2020-05-22 12:30:58 +0930 | [diff] [blame] | 357 | astlpc_test_packetised_message_bmc_to_host(); |
Andrew Jeffery | 11b7e92 | 2020-03-10 23:37:09 +1030 | [diff] [blame] | 358 | |
Andrew Jeffery | 0247c73 | 2020-02-06 11:48:52 +1030 | [diff] [blame] | 359 | return 0; |
| 360 | } |