Jeremy Kerr | 3d36ee2 | 2019-05-30 11:15:37 +0800 | [diff] [blame] | 1 | /* SPDX-License-Identifier: Apache-2.0 OR GPL-2.0-or-later */ |
Jeremy Kerr | 672c885 | 2019-03-01 12:18:07 +0800 | [diff] [blame] | 2 | |
Andrew Jeffery | 3286f17 | 2020-03-17 23:04:13 +1030 | [diff] [blame] | 3 | #if HAVE_CONFIG_H |
| 4 | #include "config.h" |
| 5 | #endif |
| 6 | |
| 7 | #if HAVE_ENDIAN_H |
Jeremy Kerr | 92a10a6 | 2019-08-28 16:55:54 +0530 | [diff] [blame] | 8 | #include <endian.h> |
Andrew Jeffery | 3286f17 | 2020-03-17 23:04:13 +1030 | [diff] [blame] | 9 | #endif |
| 10 | |
| 11 | #include <assert.h> |
Andrew Jeffery | 7cd72f1 | 2020-05-12 20:27:59 +0930 | [diff] [blame] | 12 | #include <errno.h> |
Andrew Jeffery | edfe383 | 2020-02-06 11:52:11 +1030 | [diff] [blame] | 13 | #include <inttypes.h> |
Jeremy Kerr | 672c885 | 2019-03-01 12:18:07 +0800 | [diff] [blame] | 14 | #include <stdbool.h> |
| 15 | #include <stdlib.h> |
| 16 | #include <string.h> |
Jeremy Kerr | 672c885 | 2019-03-01 12:18:07 +0800 | [diff] [blame] | 17 | |
Jeremy Kerr | 672c885 | 2019-03-01 12:18:07 +0800 | [diff] [blame] | 18 | #define pr_fmt(x) "astlpc: " x |
| 19 | |
Andrew Jeffery | eba19a3 | 2021-03-09 23:09:40 +1030 | [diff] [blame] | 20 | #include "container_of.h" |
| 21 | #include "crc32.h" |
Jeremy Kerr | 672c885 | 2019-03-01 12:18:07 +0800 | [diff] [blame] | 22 | #include "libmctp.h" |
| 23 | #include "libmctp-alloc.h" |
| 24 | #include "libmctp-log.h" |
| 25 | #include "libmctp-astlpc.h" |
Andrew Jeffery | 4622cad | 2020-11-03 22:20:18 +1030 | [diff] [blame] | 26 | #include "range.h" |
Jeremy Kerr | 672c885 | 2019-03-01 12:18:07 +0800 | [diff] [blame] | 27 | |
Jeremy Kerr | b214c64 | 2019-11-27 11:34:00 +0800 | [diff] [blame] | 28 | #ifdef MCTP_HAVE_FILEIO |
Jeremy Kerr | 92a10a6 | 2019-08-28 16:55:54 +0530 | [diff] [blame] | 29 | |
Jeremy Kerr | c6f676d | 2019-12-19 09:24:06 +0800 | [diff] [blame] | 30 | #include <unistd.h> |
Jeremy Kerr | 92a10a6 | 2019-08-28 16:55:54 +0530 | [diff] [blame] | 31 | #include <fcntl.h> |
Andrew Jeffery | 1111c6a | 2022-07-25 20:44:39 +0930 | [diff] [blame] | 32 | #include <poll.h> |
Jeremy Kerr | 92a10a6 | 2019-08-28 16:55:54 +0530 | [diff] [blame] | 33 | #include <sys/ioctl.h> |
| 34 | #include <sys/mman.h> |
| 35 | #include <linux/aspeed-lpc-ctrl.h> |
| 36 | |
| 37 | /* kernel interface */ |
Jeremy Kerr | 92a10a6 | 2019-08-28 16:55:54 +0530 | [diff] [blame] | 38 | static const char *lpc_path = "/dev/aspeed-lpc-ctrl"; |
| 39 | |
| 40 | #endif |
| 41 | |
Rashmica Gupta | 45d1332 | 2022-08-10 12:12:14 +1000 | [diff] [blame] | 42 | enum mctp_astlpc_cmd { |
| 43 | cmd_initialise = 0x00, |
| 44 | cmd_tx_begin = 0x01, |
| 45 | cmd_rx_complete = 0x02, |
| 46 | cmd_dummy_value = 0xff, |
| 47 | }; |
| 48 | |
Andrew Jeffery | fe763e9 | 2022-08-05 23:16:17 +0930 | [diff] [blame] | 49 | enum mctp_astlpc_buffer_state { |
| 50 | /* |
| 51 | * Prior to "Channel Ready" we mark the buffers as "idle" to catch illegal accesses. In this |
| 52 | * state neither side is considered the owner of the buffer. |
| 53 | * |
| 54 | * Upon "Channel Ready", each side transitions the buffers from the initial "idle" state |
| 55 | * to the following target states: |
| 56 | * |
| 57 | * Tx buffer: "acquired" |
| 58 | * Rx buffer: "released" |
| 59 | */ |
| 60 | buffer_state_idle, |
| 61 | |
| 62 | /* |
| 63 | * Beyond initialisation by "Channel Ready", buffers are in the "acquired" state once: |
| 64 | * |
| 65 | * 1. We dequeue a control command transferring the buffer to our ownership out of the KCS |
| 66 | * interface, and |
| 67 | * 2. We are yet to complete all of our required accesses to the buffer |
| 68 | * |
| 69 | * * The Tx buffer enters the "acquired" state when we dequeue the "Rx Complete" command |
| 70 | * * The Rx buffer enters the "acquired" state when we dequeue the "Tx Begin" command |
| 71 | * |
| 72 | * It is a failure of implementation if it's possible for both sides to simultaneously |
| 73 | * consider a buffer as "acquired". |
| 74 | */ |
| 75 | buffer_state_acquired, |
| 76 | |
| 77 | /* |
| 78 | * Buffers are in the "prepared" state when: |
| 79 | * |
| 80 | * 1. We have completed all of our required accesses (read or write) for the buffer, and |
| 81 | * 2. We have not yet successfully enqueued the control command to hand off ownership |
| 82 | */ |
| 83 | buffer_state_prepared, |
| 84 | |
| 85 | /* |
| 86 | * Beyond initialisation by "Channel Ready", buffers are in the "released" state once: |
| 87 | * |
| 88 | * 1. We successfully enqueue the control command transferring ownership to the remote |
| 89 | * side in to the KCS interface |
| 90 | * |
| 91 | * * The Tx buffer enters the "released" state when we enqueue the "Tx Begin" command |
| 92 | * * The Rx buffer enters the "released" state when we enqueue the "Rx Complete" command |
| 93 | * |
| 94 | * It may be the case that both sides simultaneously consider a buffer to be in the |
| 95 | * "released" state. However, if this is true, it must also be true that a buffer ownership |
| 96 | * transfer command has been enqueued in the KCS interface and is yet to be dequeued. |
| 97 | */ |
| 98 | buffer_state_released, |
| 99 | }; |
| 100 | |
Andrew Jeffery | 7cd72f1 | 2020-05-12 20:27:59 +0930 | [diff] [blame] | 101 | struct mctp_astlpc_buffer { |
| 102 | uint32_t offset; |
| 103 | uint32_t size; |
Andrew Jeffery | fe763e9 | 2022-08-05 23:16:17 +0930 | [diff] [blame] | 104 | enum mctp_astlpc_buffer_state state; |
Andrew Jeffery | 7cd72f1 | 2020-05-12 20:27:59 +0930 | [diff] [blame] | 105 | }; |
| 106 | |
| 107 | struct mctp_astlpc_layout { |
| 108 | struct mctp_astlpc_buffer rx; |
| 109 | struct mctp_astlpc_buffer tx; |
| 110 | }; |
| 111 | |
Andrew Jeffery | 88412be | 2021-03-09 22:05:22 +1030 | [diff] [blame] | 112 | struct mctp_astlpc_protocol { |
| 113 | uint16_t version; |
| 114 | uint32_t (*packet_size)(uint32_t body); |
| 115 | uint32_t (*body_size)(uint32_t packet); |
Andrew Jeffery | eba19a3 | 2021-03-09 23:09:40 +1030 | [diff] [blame] | 116 | void (*pktbuf_protect)(struct mctp_pktbuf *pkt); |
| 117 | bool (*pktbuf_validate)(struct mctp_pktbuf *pkt); |
Andrew Jeffery | 88412be | 2021-03-09 22:05:22 +1030 | [diff] [blame] | 118 | }; |
| 119 | |
Jeremy Kerr | 672c885 | 2019-03-01 12:18:07 +0800 | [diff] [blame] | 120 | struct mctp_binding_astlpc { |
Patrick Williams | a721c2d | 2022-12-04 14:30:26 -0600 | [diff] [blame] | 121 | struct mctp_binding binding; |
Jeremy Kerr | bc53d35 | 2019-08-28 14:26:14 +0530 | [diff] [blame] | 122 | |
Andrew Jeffery | 55fb90b | 2020-05-12 13:54:37 +0930 | [diff] [blame] | 123 | void *lpc_map; |
Andrew Jeffery | 7cd72f1 | 2020-05-12 20:27:59 +0930 | [diff] [blame] | 124 | struct mctp_astlpc_layout layout; |
| 125 | |
| 126 | uint8_t mode; |
Andrew Jeffery | a936898 | 2020-06-09 13:07:39 +0930 | [diff] [blame] | 127 | uint32_t requested_mtu; |
Jeremy Kerr | bc53d35 | 2019-08-28 14:26:14 +0530 | [diff] [blame] | 128 | |
Andrew Jeffery | 88412be | 2021-03-09 22:05:22 +1030 | [diff] [blame] | 129 | const struct mctp_astlpc_protocol *proto; |
| 130 | |
Jeremy Kerr | bc53d35 | 2019-08-28 14:26:14 +0530 | [diff] [blame] | 131 | /* direct ops data */ |
Andrew Jeffery | 55fb90b | 2020-05-12 13:54:37 +0930 | [diff] [blame] | 132 | struct mctp_binding_astlpc_ops ops; |
| 133 | void *ops_data; |
Jeremy Kerr | bc53d35 | 2019-08-28 14:26:14 +0530 | [diff] [blame] | 134 | |
| 135 | /* fileio ops data */ |
Andrew Jeffery | 979c6a1 | 2020-05-23 20:04:49 +0930 | [diff] [blame] | 136 | int kcs_fd; |
| 137 | uint8_t kcs_status; |
Jeremy Kerr | 672c885 | 2019-03-01 12:18:07 +0800 | [diff] [blame] | 138 | }; |
| 139 | |
Patrick Williams | a721c2d | 2022-12-04 14:30:26 -0600 | [diff] [blame] | 140 | #define binding_to_astlpc(b) \ |
Jeremy Kerr | 672c885 | 2019-03-01 12:18:07 +0800 | [diff] [blame] | 141 | container_of(b, struct mctp_binding_astlpc, binding) |
| 142 | |
Andrew Jeffery | 9101a2a | 2020-05-22 16:08:03 +0930 | [diff] [blame] | 143 | #define astlpc_prlog(ctx, lvl, fmt, ...) \ |
| 144 | do { \ |
| 145 | bool __bmc = ((ctx)->mode == MCTP_BINDING_ASTLPC_MODE_BMC); \ |
| 146 | mctp_prlog(lvl, pr_fmt("%s: " fmt), __bmc ? "bmc" : "host", \ |
| 147 | ##__VA_ARGS__); \ |
| 148 | } while (0) |
| 149 | |
| 150 | #define astlpc_prerr(ctx, fmt, ...) \ |
| 151 | astlpc_prlog(ctx, MCTP_LOG_ERR, fmt, ##__VA_ARGS__) |
| 152 | #define astlpc_prwarn(ctx, fmt, ...) \ |
| 153 | astlpc_prlog(ctx, MCTP_LOG_WARNING, fmt, ##__VA_ARGS__) |
Andrew Jeffery | 99b9d23 | 2023-06-23 15:15:30 +0930 | [diff] [blame] | 154 | #define astlpc_prnotice(ctx, fmt, ...) \ |
| 155 | astlpc_prlog(ctx, MCTP_LOG_NOTICE, fmt, ##__VA_ARGS__) |
Andrew Jeffery | 9101a2a | 2020-05-22 16:08:03 +0930 | [diff] [blame] | 156 | #define astlpc_prinfo(ctx, fmt, ...) \ |
| 157 | astlpc_prlog(ctx, MCTP_LOG_INFO, fmt, ##__VA_ARGS__) |
| 158 | #define astlpc_prdebug(ctx, fmt, ...) \ |
| 159 | astlpc_prlog(ctx, MCTP_LOG_DEBUG, fmt, ##__VA_ARGS__) |
| 160 | |
Andrew Jeffery | 7cd72f1 | 2020-05-12 20:27:59 +0930 | [diff] [blame] | 161 | /* clang-format off */ |
| 162 | #define ASTLPC_MCTP_MAGIC 0x4d435450 |
Andrew Jeffery | 4e8264b | 2020-05-23 20:34:33 +0930 | [diff] [blame] | 163 | #define ASTLPC_VER_BAD 0 |
Andrew Jeffery | 7cd72f1 | 2020-05-12 20:27:59 +0930 | [diff] [blame] | 164 | #define ASTLPC_VER_MIN 1 |
Andrew Jeffery | 7cd72f1 | 2020-05-12 20:27:59 +0930 | [diff] [blame] | 165 | |
Andrew Jeffery | 3a54066 | 2020-05-26 19:55:30 +0930 | [diff] [blame] | 166 | /* Support testing of new binding protocols */ |
| 167 | #ifndef ASTLPC_VER_CUR |
Andrew Jeffery | eba19a3 | 2021-03-09 23:09:40 +1030 | [diff] [blame] | 168 | #define ASTLPC_VER_CUR 3 |
Andrew Jeffery | 3a54066 | 2020-05-26 19:55:30 +0930 | [diff] [blame] | 169 | #endif |
Andrew Jeffery | 7cd72f1 | 2020-05-12 20:27:59 +0930 | [diff] [blame] | 170 | /* clang-format on */ |
Jeremy Kerr | 672c885 | 2019-03-01 12:18:07 +0800 | [diff] [blame] | 171 | |
Andrew Jeffery | 88412be | 2021-03-09 22:05:22 +1030 | [diff] [blame] | 172 | #ifndef ARRAY_SIZE |
| 173 | #define ARRAY_SIZE(a) (sizeof(a) / sizeof(a[0])) |
| 174 | #endif |
| 175 | |
| 176 | static uint32_t astlpc_packet_size_v1(uint32_t body) |
| 177 | { |
| 178 | assert((body + 4) > body); |
| 179 | |
| 180 | return body + 4; |
| 181 | } |
| 182 | |
| 183 | static uint32_t astlpc_body_size_v1(uint32_t packet) |
| 184 | { |
| 185 | assert((packet - 4) < packet); |
| 186 | |
| 187 | return packet - 4; |
| 188 | } |
| 189 | |
Andrew Jeffery | eba19a3 | 2021-03-09 23:09:40 +1030 | [diff] [blame] | 190 | void astlpc_pktbuf_protect_v1(struct mctp_pktbuf *pkt) |
| 191 | { |
| 192 | (void)pkt; |
| 193 | } |
| 194 | |
| 195 | bool astlpc_pktbuf_validate_v1(struct mctp_pktbuf *pkt) |
| 196 | { |
| 197 | (void)pkt; |
| 198 | return true; |
| 199 | } |
| 200 | |
| 201 | static uint32_t astlpc_packet_size_v3(uint32_t body) |
| 202 | { |
| 203 | assert((body + 4 + 4) > body); |
| 204 | |
| 205 | return body + 4 + 4; |
| 206 | } |
| 207 | |
| 208 | static uint32_t astlpc_body_size_v3(uint32_t packet) |
| 209 | { |
| 210 | assert((packet - 4 - 4) < packet); |
| 211 | |
| 212 | return packet - 4 - 4; |
| 213 | } |
| 214 | |
| 215 | void astlpc_pktbuf_protect_v3(struct mctp_pktbuf *pkt) |
| 216 | { |
| 217 | uint32_t code; |
| 218 | |
| 219 | code = htobe32(crc32(mctp_pktbuf_hdr(pkt), mctp_pktbuf_size(pkt))); |
| 220 | mctp_prdebug("%s: 0x%" PRIx32, __func__, code); |
| 221 | mctp_pktbuf_push(pkt, &code, 4); |
| 222 | } |
| 223 | |
| 224 | bool astlpc_pktbuf_validate_v3(struct mctp_pktbuf *pkt) |
| 225 | { |
| 226 | uint32_t code; |
| 227 | void *check; |
| 228 | |
| 229 | code = be32toh(crc32(mctp_pktbuf_hdr(pkt), mctp_pktbuf_size(pkt) - 4)); |
| 230 | mctp_prdebug("%s: 0x%" PRIx32, __func__, code); |
| 231 | check = mctp_pktbuf_pop(pkt, 4); |
| 232 | return check && !memcmp(&code, check, 4); |
| 233 | } |
| 234 | |
Andrew Jeffery | 88412be | 2021-03-09 22:05:22 +1030 | [diff] [blame] | 235 | static const struct mctp_astlpc_protocol astlpc_protocol_version[] = { |
| 236 | [0] = { |
| 237 | .version = 0, |
| 238 | .packet_size = NULL, |
| 239 | .body_size = NULL, |
Andrew Jeffery | eba19a3 | 2021-03-09 23:09:40 +1030 | [diff] [blame] | 240 | .pktbuf_protect = NULL, |
| 241 | .pktbuf_validate = NULL, |
Andrew Jeffery | 88412be | 2021-03-09 22:05:22 +1030 | [diff] [blame] | 242 | }, |
| 243 | [1] = { |
| 244 | .version = 1, |
| 245 | .packet_size = astlpc_packet_size_v1, |
| 246 | .body_size = astlpc_body_size_v1, |
Andrew Jeffery | eba19a3 | 2021-03-09 23:09:40 +1030 | [diff] [blame] | 247 | .pktbuf_protect = astlpc_pktbuf_protect_v1, |
| 248 | .pktbuf_validate = astlpc_pktbuf_validate_v1, |
Andrew Jeffery | 88412be | 2021-03-09 22:05:22 +1030 | [diff] [blame] | 249 | }, |
| 250 | [2] = { |
| 251 | .version = 2, |
| 252 | .packet_size = astlpc_packet_size_v1, |
| 253 | .body_size = astlpc_body_size_v1, |
Andrew Jeffery | eba19a3 | 2021-03-09 23:09:40 +1030 | [diff] [blame] | 254 | .pktbuf_protect = astlpc_pktbuf_protect_v1, |
| 255 | .pktbuf_validate = astlpc_pktbuf_validate_v1, |
| 256 | }, |
| 257 | [3] = { |
| 258 | .version = 3, |
| 259 | .packet_size = astlpc_packet_size_v3, |
| 260 | .body_size = astlpc_body_size_v3, |
| 261 | .pktbuf_protect = astlpc_pktbuf_protect_v3, |
| 262 | .pktbuf_validate = astlpc_pktbuf_validate_v3, |
Andrew Jeffery | 88412be | 2021-03-09 22:05:22 +1030 | [diff] [blame] | 263 | }, |
| 264 | }; |
| 265 | |
Jeremy Kerr | 672c885 | 2019-03-01 12:18:07 +0800 | [diff] [blame] | 266 | struct mctp_lpcmap_hdr { |
Andrew Jeffery | 3a54066 | 2020-05-26 19:55:30 +0930 | [diff] [blame] | 267 | uint32_t magic; |
Jeremy Kerr | 672c885 | 2019-03-01 12:18:07 +0800 | [diff] [blame] | 268 | |
Andrew Jeffery | 3a54066 | 2020-05-26 19:55:30 +0930 | [diff] [blame] | 269 | uint16_t bmc_ver_min; |
| 270 | uint16_t bmc_ver_cur; |
| 271 | uint16_t host_ver_min; |
| 272 | uint16_t host_ver_cur; |
| 273 | uint16_t negotiated_ver; |
| 274 | uint16_t pad0; |
Jeremy Kerr | 672c885 | 2019-03-01 12:18:07 +0800 | [diff] [blame] | 275 | |
Andrew Jeffery | 3a54066 | 2020-05-26 19:55:30 +0930 | [diff] [blame] | 276 | struct { |
| 277 | uint32_t rx_offset; |
| 278 | uint32_t rx_size; |
| 279 | uint32_t tx_offset; |
| 280 | uint32_t tx_size; |
| 281 | } layout; |
Jeremy Kerr | 672c885 | 2019-03-01 12:18:07 +0800 | [diff] [blame] | 282 | } __attribute__((packed)); |
| 283 | |
Andrew Jeffery | 3a54066 | 2020-05-26 19:55:30 +0930 | [diff] [blame] | 284 | static const uint32_t control_size = 0x100; |
Jeremy Kerr | 672c885 | 2019-03-01 12:18:07 +0800 | [diff] [blame] | 285 | |
Patrick Williams | a721c2d | 2022-12-04 14:30:26 -0600 | [diff] [blame] | 286 | #define LPC_WIN_SIZE (1 * 1024 * 1024) |
Jeremy Kerr | 672c885 | 2019-03-01 12:18:07 +0800 | [diff] [blame] | 287 | |
Patrick Williams | a721c2d | 2022-12-04 14:30:26 -0600 | [diff] [blame] | 288 | #define KCS_STATUS_BMC_READY 0x80 |
| 289 | #define KCS_STATUS_CHANNEL_ACTIVE 0x40 |
| 290 | #define KCS_STATUS_IBF 0x02 |
| 291 | #define KCS_STATUS_OBF 0x01 |
Jeremy Kerr | 672c885 | 2019-03-01 12:18:07 +0800 | [diff] [blame] | 292 | |
Andrew Jeffery | f13cb97 | 2020-05-28 09:30:09 +0930 | [diff] [blame] | 293 | static inline int mctp_astlpc_kcs_write(struct mctp_binding_astlpc *astlpc, |
| 294 | enum mctp_binding_astlpc_kcs_reg reg, |
| 295 | uint8_t val) |
| 296 | { |
| 297 | return astlpc->ops.kcs_write(astlpc->ops_data, reg, val); |
| 298 | } |
| 299 | |
| 300 | static inline int mctp_astlpc_kcs_read(struct mctp_binding_astlpc *astlpc, |
| 301 | enum mctp_binding_astlpc_kcs_reg reg, |
| 302 | uint8_t *val) |
| 303 | { |
| 304 | return astlpc->ops.kcs_read(astlpc->ops_data, reg, val); |
| 305 | } |
| 306 | |
Andrew Jeffery | 55fb90b | 2020-05-12 13:54:37 +0930 | [diff] [blame] | 307 | static inline int mctp_astlpc_lpc_write(struct mctp_binding_astlpc *astlpc, |
| 308 | const void *buf, long offset, |
| 309 | size_t len) |
Jeremy Kerr | bc53d35 | 2019-08-28 14:26:14 +0530 | [diff] [blame] | 310 | { |
Andrew Jeffery | 55fb90b | 2020-05-12 13:54:37 +0930 | [diff] [blame] | 311 | astlpc_prdebug(astlpc, "%s: %zu bytes to 0x%lx", __func__, len, offset); |
| 312 | |
| 313 | assert(offset >= 0); |
| 314 | |
| 315 | /* Indirect access */ |
| 316 | if (astlpc->ops.lpc_write) { |
| 317 | void *data = astlpc->ops_data; |
| 318 | |
| 319 | return astlpc->ops.lpc_write(data, buf, offset, len); |
| 320 | } |
| 321 | |
| 322 | /* Direct mapping */ |
| 323 | assert(astlpc->lpc_map); |
| 324 | memcpy(&((char *)astlpc->lpc_map)[offset], buf, len); |
| 325 | |
| 326 | return 0; |
| 327 | } |
| 328 | |
| 329 | static inline int mctp_astlpc_lpc_read(struct mctp_binding_astlpc *astlpc, |
| 330 | void *buf, long offset, size_t len) |
| 331 | { |
| 332 | astlpc_prdebug(astlpc, "%s: %zu bytes from 0x%lx", __func__, len, |
| 333 | offset); |
| 334 | |
| 335 | assert(offset >= 0); |
| 336 | |
| 337 | /* Indirect access */ |
| 338 | if (astlpc->ops.lpc_read) { |
| 339 | void *data = astlpc->ops_data; |
| 340 | |
| 341 | return astlpc->ops.lpc_read(data, buf, offset, len); |
| 342 | } |
| 343 | |
| 344 | /* Direct mapping */ |
| 345 | assert(astlpc->lpc_map); |
| 346 | memcpy(buf, &((char *)astlpc->lpc_map)[offset], len); |
| 347 | |
| 348 | return 0; |
Jeremy Kerr | bc53d35 | 2019-08-28 14:26:14 +0530 | [diff] [blame] | 349 | } |
| 350 | |
Andrew Jeffery | 99b9d23 | 2023-06-23 15:15:30 +0930 | [diff] [blame] | 351 | static void |
| 352 | mctp_astlpc_kcs_print_status_write(struct mctp_binding_astlpc *astlpc, |
| 353 | uint8_t status) |
| 354 | { |
| 355 | astlpc_prnotice( |
| 356 | astlpc, "Binding state is 0x%hhx: BMC %s, Channel %s, OBF %s", |
| 357 | status, status & KCS_STATUS_BMC_READY ? "active" : "inactive", |
| 358 | status & KCS_STATUS_CHANNEL_ACTIVE ? "active" : "inactive", |
| 359 | status & KCS_STATUS_OBF ? "preserved" : "cleared"); |
| 360 | } |
| 361 | |
Andrew Jeffery | d0f5da0 | 2020-05-28 09:12:55 +0930 | [diff] [blame] | 362 | static int mctp_astlpc_kcs_set_status(struct mctp_binding_astlpc *astlpc, |
| 363 | uint8_t status) |
| 364 | { |
| 365 | uint8_t data; |
| 366 | int rc; |
| 367 | |
| 368 | /* Since we're setting the status register, we want the other endpoint |
| 369 | * to be interrupted. However, some hardware may only raise a host-side |
| 370 | * interrupt on an ODR event. |
| 371 | * So, write a dummy value of 0xff to ODR, which will ensure that an |
| 372 | * interrupt is triggered, and can be ignored by the host. |
| 373 | */ |
Rashmica Gupta | 45d1332 | 2022-08-10 12:12:14 +1000 | [diff] [blame] | 374 | data = cmd_dummy_value; |
Andrew Jeffery | d0f5da0 | 2020-05-28 09:12:55 +0930 | [diff] [blame] | 375 | |
Andrew Jeffery | f13cb97 | 2020-05-28 09:30:09 +0930 | [diff] [blame] | 376 | rc = mctp_astlpc_kcs_write(astlpc, MCTP_ASTLPC_KCS_REG_STATUS, status); |
Andrew Jeffery | d0f5da0 | 2020-05-28 09:12:55 +0930 | [diff] [blame] | 377 | if (rc) { |
| 378 | astlpc_prwarn(astlpc, "KCS status write failed"); |
| 379 | return -1; |
| 380 | } |
| 381 | |
Andrew Jeffery | 99b9d23 | 2023-06-23 15:15:30 +0930 | [diff] [blame] | 382 | mctp_astlpc_kcs_print_status_write(astlpc, status); |
| 383 | |
Andrew Jeffery | f13cb97 | 2020-05-28 09:30:09 +0930 | [diff] [blame] | 384 | rc = mctp_astlpc_kcs_write(astlpc, MCTP_ASTLPC_KCS_REG_DATA, data); |
Andrew Jeffery | d0f5da0 | 2020-05-28 09:12:55 +0930 | [diff] [blame] | 385 | if (rc) { |
| 386 | astlpc_prwarn(astlpc, "KCS dummy data write failed"); |
| 387 | return -1; |
| 388 | } |
| 389 | |
| 390 | return 0; |
| 391 | } |
| 392 | |
Andrew Jeffery | 3a54066 | 2020-05-26 19:55:30 +0930 | [diff] [blame] | 393 | static int mctp_astlpc_layout_read(struct mctp_binding_astlpc *astlpc, |
| 394 | struct mctp_astlpc_layout *layout) |
| 395 | { |
| 396 | struct mctp_lpcmap_hdr hdr; |
| 397 | int rc; |
| 398 | |
| 399 | rc = mctp_astlpc_lpc_read(astlpc, &hdr, 0, sizeof(hdr)); |
| 400 | if (rc < 0) |
| 401 | return rc; |
| 402 | |
| 403 | /* Flip the buffers as the names are defined in terms of the host */ |
| 404 | if (astlpc->mode == MCTP_BINDING_ASTLPC_MODE_BMC) { |
| 405 | layout->rx.offset = be32toh(hdr.layout.tx_offset); |
| 406 | layout->rx.size = be32toh(hdr.layout.tx_size); |
| 407 | layout->tx.offset = be32toh(hdr.layout.rx_offset); |
| 408 | layout->tx.size = be32toh(hdr.layout.rx_size); |
| 409 | } else { |
| 410 | assert(astlpc->mode == MCTP_BINDING_ASTLPC_MODE_HOST); |
| 411 | |
| 412 | layout->rx.offset = be32toh(hdr.layout.rx_offset); |
| 413 | layout->rx.size = be32toh(hdr.layout.rx_size); |
| 414 | layout->tx.offset = be32toh(hdr.layout.tx_offset); |
| 415 | layout->tx.size = be32toh(hdr.layout.tx_size); |
| 416 | } |
| 417 | |
| 418 | return 0; |
| 419 | } |
| 420 | |
| 421 | static int mctp_astlpc_layout_write(struct mctp_binding_astlpc *astlpc, |
| 422 | struct mctp_astlpc_layout *layout) |
| 423 | { |
| 424 | uint32_t rx_size_be; |
| 425 | |
| 426 | if (astlpc->mode == MCTP_BINDING_ASTLPC_MODE_BMC) { |
| 427 | struct mctp_lpcmap_hdr hdr; |
| 428 | |
| 429 | /* |
| 430 | * Flip the buffers as the names are defined in terms of the |
| 431 | * host |
| 432 | */ |
| 433 | hdr.layout.rx_offset = htobe32(layout->tx.offset); |
| 434 | hdr.layout.rx_size = htobe32(layout->tx.size); |
| 435 | hdr.layout.tx_offset = htobe32(layout->rx.offset); |
| 436 | hdr.layout.tx_size = htobe32(layout->rx.size); |
| 437 | |
| 438 | return mctp_astlpc_lpc_write(astlpc, &hdr.layout, |
Patrick Williams | a721c2d | 2022-12-04 14:30:26 -0600 | [diff] [blame] | 439 | offsetof(struct mctp_lpcmap_hdr, |
| 440 | layout), |
| 441 | sizeof(hdr.layout)); |
Andrew Jeffery | 3a54066 | 2020-05-26 19:55:30 +0930 | [diff] [blame] | 442 | } |
| 443 | |
| 444 | assert(astlpc->mode == MCTP_BINDING_ASTLPC_MODE_HOST); |
| 445 | |
| 446 | /* |
| 447 | * As of v2 we only need to write rx_size - the offsets are controlled |
| 448 | * by the BMC, as is the BMC's rx_size (host tx_size). |
| 449 | */ |
| 450 | rx_size_be = htobe32(layout->rx.size); |
| 451 | return mctp_astlpc_lpc_write(astlpc, &rx_size_be, |
Patrick Williams | a721c2d | 2022-12-04 14:30:26 -0600 | [diff] [blame] | 452 | offsetof(struct mctp_lpcmap_hdr, |
| 453 | layout.rx_size), |
| 454 | sizeof(rx_size_be)); |
Andrew Jeffery | 3a54066 | 2020-05-26 19:55:30 +0930 | [diff] [blame] | 455 | } |
| 456 | |
Andrew Jeffery | 88412be | 2021-03-09 22:05:22 +1030 | [diff] [blame] | 457 | static bool |
| 458 | mctp_astlpc_buffer_validate(const struct mctp_binding_astlpc *astlpc, |
| 459 | const struct mctp_astlpc_buffer *buf, |
| 460 | const char *name) |
Andrew Jeffery | 3a54066 | 2020-05-26 19:55:30 +0930 | [diff] [blame] | 461 | { |
| 462 | /* Check for overflow */ |
| 463 | if (buf->offset + buf->size < buf->offset) { |
| 464 | mctp_prerr( |
| 465 | "%s packet buffer parameters overflow: offset: 0x%" PRIx32 |
| 466 | ", size: %" PRIu32, |
| 467 | name, buf->offset, buf->size); |
| 468 | return false; |
| 469 | } |
| 470 | |
| 471 | /* Check that the buffers are contained within the allocated space */ |
| 472 | if (buf->offset + buf->size > LPC_WIN_SIZE) { |
| 473 | mctp_prerr( |
| 474 | "%s packet buffer parameters exceed %uM window size: offset: 0x%" PRIx32 |
| 475 | ", size: %" PRIu32, |
| 476 | name, (LPC_WIN_SIZE / (1024 * 1024)), buf->offset, |
| 477 | buf->size); |
| 478 | return false; |
| 479 | } |
| 480 | |
| 481 | /* Check that the baseline transmission unit is supported */ |
Patrick Williams | a721c2d | 2022-12-04 14:30:26 -0600 | [diff] [blame] | 482 | if (buf->size < |
| 483 | astlpc->proto->packet_size(MCTP_PACKET_SIZE(MCTP_BTU))) { |
Andrew Jeffery | 3a54066 | 2020-05-26 19:55:30 +0930 | [diff] [blame] | 484 | mctp_prerr( |
Patrick Williams | a721c2d | 2022-12-04 14:30:26 -0600 | [diff] [blame] | 485 | "%s packet buffer too small: Require %" PRIu32 |
| 486 | " bytes to support the %u byte baseline transmission unit, found %" PRIu32, |
Andrew Jeffery | 88412be | 2021-03-09 22:05:22 +1030 | [diff] [blame] | 487 | name, |
| 488 | astlpc->proto->packet_size(MCTP_PACKET_SIZE(MCTP_BTU)), |
Andrew Jeffery | 3a54066 | 2020-05-26 19:55:30 +0930 | [diff] [blame] | 489 | MCTP_BTU, buf->size); |
| 490 | return false; |
| 491 | } |
| 492 | |
| 493 | /* Check for overlap with the control space */ |
| 494 | if (buf->offset < control_size) { |
| 495 | mctp_prerr( |
| 496 | "%s packet buffer overlaps control region {0x%" PRIx32 |
| 497 | ", %" PRIu32 "}: Rx {0x%" PRIx32 ", %" PRIu32 "}", |
| 498 | name, 0U, control_size, buf->offset, buf->size); |
| 499 | return false; |
| 500 | } |
| 501 | |
| 502 | return true; |
| 503 | } |
| 504 | |
Andrew Jeffery | 88412be | 2021-03-09 22:05:22 +1030 | [diff] [blame] | 505 | static bool |
| 506 | mctp_astlpc_layout_validate(const struct mctp_binding_astlpc *astlpc, |
| 507 | const struct mctp_astlpc_layout *layout) |
Andrew Jeffery | 3a54066 | 2020-05-26 19:55:30 +0930 | [diff] [blame] | 508 | { |
Andrew Jeffery | 88412be | 2021-03-09 22:05:22 +1030 | [diff] [blame] | 509 | const struct mctp_astlpc_buffer *rx = &layout->rx; |
| 510 | const struct mctp_astlpc_buffer *tx = &layout->tx; |
Andrew Jeffery | 3a54066 | 2020-05-26 19:55:30 +0930 | [diff] [blame] | 511 | bool rx_valid, tx_valid; |
| 512 | |
Andrew Jeffery | 88412be | 2021-03-09 22:05:22 +1030 | [diff] [blame] | 513 | rx_valid = mctp_astlpc_buffer_validate(astlpc, rx, "Rx"); |
| 514 | tx_valid = mctp_astlpc_buffer_validate(astlpc, tx, "Tx"); |
Andrew Jeffery | 3a54066 | 2020-05-26 19:55:30 +0930 | [diff] [blame] | 515 | |
| 516 | if (!(rx_valid && tx_valid)) |
| 517 | return false; |
| 518 | |
| 519 | /* Check that the buffers are disjoint */ |
| 520 | if ((rx->offset <= tx->offset && rx->offset + rx->size > tx->offset) || |
| 521 | (tx->offset <= rx->offset && tx->offset + tx->size > rx->offset)) { |
| 522 | mctp_prerr("Rx and Tx packet buffers overlap: Rx {0x%" PRIx32 |
| 523 | ", %" PRIu32 "}, Tx {0x%" PRIx32 ", %" PRIu32 "}", |
| 524 | rx->offset, rx->size, tx->offset, tx->size); |
| 525 | return false; |
| 526 | } |
| 527 | |
| 528 | return true; |
| 529 | } |
| 530 | |
Andrew Jeffery | 7cd72f1 | 2020-05-12 20:27:59 +0930 | [diff] [blame] | 531 | static int mctp_astlpc_init_bmc(struct mctp_binding_astlpc *astlpc) |
| 532 | { |
Andrew Jeffery | 55fb90b | 2020-05-12 13:54:37 +0930 | [diff] [blame] | 533 | struct mctp_lpcmap_hdr hdr = { 0 }; |
Andrew Jeffery | 7cd72f1 | 2020-05-12 20:27:59 +0930 | [diff] [blame] | 534 | uint8_t status; |
Andrew Jeffery | 88412be | 2021-03-09 22:05:22 +1030 | [diff] [blame] | 535 | uint32_t sz; |
Andrew Jeffery | 3a54066 | 2020-05-26 19:55:30 +0930 | [diff] [blame] | 536 | |
| 537 | /* |
| 538 | * The largest buffer size is half of the allocated MCTP space |
| 539 | * excluding the control space. |
| 540 | */ |
| 541 | sz = ((LPC_WIN_SIZE - control_size) / 2); |
| 542 | |
| 543 | /* |
| 544 | * Trim the MTU to a multiple of 16 to meet the requirements of 12.17 |
| 545 | * Query Hop in DSP0236 v1.3.0. |
| 546 | */ |
Andrew Jeffery | 88412be | 2021-03-09 22:05:22 +1030 | [diff] [blame] | 547 | sz = MCTP_BODY_SIZE(astlpc->proto->body_size(sz)); |
Andrew Jeffery | 3a54066 | 2020-05-26 19:55:30 +0930 | [diff] [blame] | 548 | sz &= ~0xfUL; |
Andrew Jeffery | 88412be | 2021-03-09 22:05:22 +1030 | [diff] [blame] | 549 | sz = astlpc->proto->packet_size(MCTP_PACKET_SIZE(sz)); |
Andrew Jeffery | 7cd72f1 | 2020-05-12 20:27:59 +0930 | [diff] [blame] | 550 | |
Andrew Jeffery | a936898 | 2020-06-09 13:07:39 +0930 | [diff] [blame] | 551 | if (astlpc->requested_mtu) { |
Andrew Jeffery | 88412be | 2021-03-09 22:05:22 +1030 | [diff] [blame] | 552 | uint32_t rpkt, rmtu; |
Andrew Jeffery | a936898 | 2020-06-09 13:07:39 +0930 | [diff] [blame] | 553 | |
Andrew Jeffery | 88412be | 2021-03-09 22:05:22 +1030 | [diff] [blame] | 554 | rmtu = astlpc->requested_mtu; |
| 555 | rpkt = astlpc->proto->packet_size(MCTP_PACKET_SIZE(rmtu)); |
| 556 | sz = MIN(sz, rpkt); |
Andrew Jeffery | a936898 | 2020-06-09 13:07:39 +0930 | [diff] [blame] | 557 | } |
| 558 | |
Andrew Jeffery | 7cd72f1 | 2020-05-12 20:27:59 +0930 | [diff] [blame] | 559 | /* Flip the buffers as the names are defined in terms of the host */ |
Andrew Jeffery | 3a54066 | 2020-05-26 19:55:30 +0930 | [diff] [blame] | 560 | astlpc->layout.tx.offset = control_size; |
| 561 | astlpc->layout.tx.size = sz; |
| 562 | astlpc->layout.rx.offset = |
| 563 | astlpc->layout.tx.offset + astlpc->layout.tx.size; |
| 564 | astlpc->layout.rx.size = sz; |
| 565 | |
Andrew Jeffery | 88412be | 2021-03-09 22:05:22 +1030 | [diff] [blame] | 566 | if (!mctp_astlpc_layout_validate(astlpc, &astlpc->layout)) { |
| 567 | astlpc_prerr(astlpc, "Cannot support an MTU of %" PRIu32, sz); |
Andrew Jeffery | a936898 | 2020-06-09 13:07:39 +0930 | [diff] [blame] | 568 | return -EINVAL; |
| 569 | } |
Andrew Jeffery | 7cd72f1 | 2020-05-12 20:27:59 +0930 | [diff] [blame] | 570 | |
Andrew Jeffery | 55fb90b | 2020-05-12 13:54:37 +0930 | [diff] [blame] | 571 | hdr = (struct mctp_lpcmap_hdr){ |
| 572 | .magic = htobe32(ASTLPC_MCTP_MAGIC), |
| 573 | .bmc_ver_min = htobe16(ASTLPC_VER_MIN), |
| 574 | .bmc_ver_cur = htobe16(ASTLPC_VER_CUR), |
Andrew Jeffery | 7cd72f1 | 2020-05-12 20:27:59 +0930 | [diff] [blame] | 575 | |
Andrew Jeffery | 55fb90b | 2020-05-12 13:54:37 +0930 | [diff] [blame] | 576 | /* Flip the buffers back as we're now describing the host's |
| 577 | * configuration to the host */ |
Andrew Jeffery | 3a54066 | 2020-05-26 19:55:30 +0930 | [diff] [blame] | 578 | .layout.rx_offset = htobe32(astlpc->layout.tx.offset), |
| 579 | .layout.rx_size = htobe32(astlpc->layout.tx.size), |
| 580 | .layout.tx_offset = htobe32(astlpc->layout.rx.offset), |
| 581 | .layout.tx_size = htobe32(astlpc->layout.rx.size), |
Andrew Jeffery | 55fb90b | 2020-05-12 13:54:37 +0930 | [diff] [blame] | 582 | }; |
Andrew Jeffery | 7cd72f1 | 2020-05-12 20:27:59 +0930 | [diff] [blame] | 583 | |
Andrew Jeffery | 55fb90b | 2020-05-12 13:54:37 +0930 | [diff] [blame] | 584 | mctp_astlpc_lpc_write(astlpc, &hdr, 0, sizeof(hdr)); |
Andrew Jeffery | 7cd72f1 | 2020-05-12 20:27:59 +0930 | [diff] [blame] | 585 | |
Andrew Jeffery | b3b55a6 | 2020-07-06 13:34:18 +0930 | [diff] [blame] | 586 | /* |
| 587 | * Set status indicating that the BMC is now active. Be explicit about |
| 588 | * clearing OBF; we're reinitialising the binding and so any previous |
| 589 | * buffer state is irrelevant. |
| 590 | */ |
| 591 | status = KCS_STATUS_BMC_READY & ~KCS_STATUS_OBF; |
Andrew Jeffery | d0f5da0 | 2020-05-28 09:12:55 +0930 | [diff] [blame] | 592 | return mctp_astlpc_kcs_set_status(astlpc, status); |
Andrew Jeffery | 7cd72f1 | 2020-05-12 20:27:59 +0930 | [diff] [blame] | 593 | } |
| 594 | |
| 595 | static int mctp_binding_astlpc_start_bmc(struct mctp_binding *b) |
| 596 | { |
| 597 | struct mctp_binding_astlpc *astlpc = |
| 598 | container_of(b, struct mctp_binding_astlpc, binding); |
| 599 | |
Andrew Jeffery | 88412be | 2021-03-09 22:05:22 +1030 | [diff] [blame] | 600 | astlpc->proto = &astlpc_protocol_version[ASTLPC_VER_CUR]; |
| 601 | |
Andrew Jeffery | 7cd72f1 | 2020-05-12 20:27:59 +0930 | [diff] [blame] | 602 | return mctp_astlpc_init_bmc(astlpc); |
| 603 | } |
| 604 | |
Andrew Jeffery | 4e8264b | 2020-05-23 20:34:33 +0930 | [diff] [blame] | 605 | static bool mctp_astlpc_validate_version(uint16_t bmc_ver_min, |
| 606 | uint16_t bmc_ver_cur, |
| 607 | uint16_t host_ver_min, |
| 608 | uint16_t host_ver_cur) |
| 609 | { |
| 610 | if (!(bmc_ver_min && bmc_ver_cur && host_ver_min && host_ver_cur)) { |
| 611 | mctp_prerr("Invalid version present in [%" PRIu16 ", %" PRIu16 |
| 612 | "], [%" PRIu16 ", %" PRIu16 "]", |
| 613 | bmc_ver_min, bmc_ver_cur, host_ver_min, |
| 614 | host_ver_cur); |
| 615 | return false; |
| 616 | } else if (bmc_ver_min > bmc_ver_cur) { |
| 617 | mctp_prerr("Invalid bmc version range [%" PRIu16 ", %" PRIu16 |
| 618 | "]", |
| 619 | bmc_ver_min, bmc_ver_cur); |
| 620 | return false; |
| 621 | } else if (host_ver_min > host_ver_cur) { |
| 622 | mctp_prerr("Invalid host version range [%" PRIu16 ", %" PRIu16 |
| 623 | "]", |
| 624 | host_ver_min, host_ver_cur); |
| 625 | return false; |
| 626 | } else if ((host_ver_cur < bmc_ver_min) || |
| 627 | (host_ver_min > bmc_ver_cur)) { |
| 628 | mctp_prerr( |
| 629 | "Unable to satisfy version negotiation with ranges [%" PRIu16 |
| 630 | ", %" PRIu16 "] and [%" PRIu16 ", %" PRIu16 "]", |
| 631 | bmc_ver_min, bmc_ver_cur, host_ver_min, host_ver_cur); |
| 632 | return false; |
| 633 | } |
| 634 | |
| 635 | return true; |
| 636 | } |
| 637 | |
Andrew Jeffery | 3a54066 | 2020-05-26 19:55:30 +0930 | [diff] [blame] | 638 | static int mctp_astlpc_negotiate_layout_host(struct mctp_binding_astlpc *astlpc) |
| 639 | { |
| 640 | struct mctp_astlpc_layout layout; |
Andrew Jeffery | 88412be | 2021-03-09 22:05:22 +1030 | [diff] [blame] | 641 | uint32_t rmtu; |
Andrew Jeffery | 3a54066 | 2020-05-26 19:55:30 +0930 | [diff] [blame] | 642 | uint32_t sz; |
| 643 | int rc; |
| 644 | |
| 645 | rc = mctp_astlpc_layout_read(astlpc, &layout); |
| 646 | if (rc < 0) |
| 647 | return rc; |
| 648 | |
Andrew Jeffery | 88412be | 2021-03-09 22:05:22 +1030 | [diff] [blame] | 649 | if (!mctp_astlpc_layout_validate(astlpc, &layout)) { |
Andrew Jeffery | 3a54066 | 2020-05-26 19:55:30 +0930 | [diff] [blame] | 650 | astlpc_prerr( |
| 651 | astlpc, |
| 652 | "BMC provided invalid buffer layout: Rx {0x%" PRIx32 |
| 653 | ", %" PRIu32 "}, Tx {0x%" PRIx32 ", %" PRIu32 "}", |
| 654 | layout.rx.offset, layout.rx.size, layout.tx.offset, |
| 655 | layout.tx.size); |
| 656 | return -EINVAL; |
| 657 | } |
| 658 | |
Andrew Jeffery | a936898 | 2020-06-09 13:07:39 +0930 | [diff] [blame] | 659 | astlpc_prinfo(astlpc, "Desire an MTU of %" PRIu32 " bytes", |
| 660 | astlpc->requested_mtu); |
| 661 | |
Andrew Jeffery | 88412be | 2021-03-09 22:05:22 +1030 | [diff] [blame] | 662 | rmtu = astlpc->requested_mtu; |
| 663 | sz = astlpc->proto->packet_size(MCTP_PACKET_SIZE(rmtu)); |
Andrew Jeffery | 3a54066 | 2020-05-26 19:55:30 +0930 | [diff] [blame] | 664 | layout.rx.size = sz; |
| 665 | |
Andrew Jeffery | 88412be | 2021-03-09 22:05:22 +1030 | [diff] [blame] | 666 | if (!mctp_astlpc_layout_validate(astlpc, &layout)) { |
Andrew Jeffery | 3a54066 | 2020-05-26 19:55:30 +0930 | [diff] [blame] | 667 | astlpc_prerr( |
| 668 | astlpc, |
| 669 | "Generated invalid buffer layout with size %" PRIu32 |
| 670 | ": Rx {0x%" PRIx32 ", %" PRIu32 "}, Tx {0x%" PRIx32 |
| 671 | ", %" PRIu32 "}", |
| 672 | sz, layout.rx.offset, layout.rx.size, layout.tx.offset, |
| 673 | layout.tx.size); |
| 674 | return -EINVAL; |
| 675 | } |
| 676 | |
Andrew Jeffery | a936898 | 2020-06-09 13:07:39 +0930 | [diff] [blame] | 677 | astlpc_prinfo(astlpc, "Requesting MTU of %" PRIu32 " bytes", |
| 678 | astlpc->requested_mtu); |
Andrew Jeffery | 3a54066 | 2020-05-26 19:55:30 +0930 | [diff] [blame] | 679 | |
| 680 | return mctp_astlpc_layout_write(astlpc, &layout); |
| 681 | } |
| 682 | |
Andrew Jeffery | 88412be | 2021-03-09 22:05:22 +1030 | [diff] [blame] | 683 | static uint16_t mctp_astlpc_negotiate_version(uint16_t bmc_ver_min, |
| 684 | uint16_t bmc_ver_cur, |
| 685 | uint16_t host_ver_min, |
| 686 | uint16_t host_ver_cur) |
| 687 | { |
| 688 | if (!mctp_astlpc_validate_version(bmc_ver_min, bmc_ver_cur, |
| 689 | host_ver_min, host_ver_cur)) |
| 690 | return ASTLPC_VER_BAD; |
| 691 | |
| 692 | if (bmc_ver_cur < host_ver_cur) |
| 693 | return bmc_ver_cur; |
| 694 | |
| 695 | return host_ver_cur; |
| 696 | } |
| 697 | |
Andrew Jeffery | 7cd72f1 | 2020-05-12 20:27:59 +0930 | [diff] [blame] | 698 | static int mctp_astlpc_init_host(struct mctp_binding_astlpc *astlpc) |
| 699 | { |
Andrew Jeffery | 55fb90b | 2020-05-12 13:54:37 +0930 | [diff] [blame] | 700 | const uint16_t ver_min_be = htobe16(ASTLPC_VER_MIN); |
| 701 | const uint16_t ver_cur_be = htobe16(ASTLPC_VER_CUR); |
Andrew Jeffery | 88412be | 2021-03-09 22:05:22 +1030 | [diff] [blame] | 702 | uint16_t bmc_ver_min, bmc_ver_cur, negotiated; |
Andrew Jeffery | 55fb90b | 2020-05-12 13:54:37 +0930 | [diff] [blame] | 703 | struct mctp_lpcmap_hdr hdr; |
Andrew Jeffery | 7cd72f1 | 2020-05-12 20:27:59 +0930 | [diff] [blame] | 704 | uint8_t status; |
| 705 | int rc; |
| 706 | |
Andrew Jeffery | f13cb97 | 2020-05-28 09:30:09 +0930 | [diff] [blame] | 707 | rc = mctp_astlpc_kcs_read(astlpc, MCTP_ASTLPC_KCS_REG_STATUS, &status); |
Andrew Jeffery | 7cd72f1 | 2020-05-12 20:27:59 +0930 | [diff] [blame] | 708 | if (rc) { |
| 709 | mctp_prwarn("KCS status read failed"); |
| 710 | return rc; |
| 711 | } |
| 712 | |
| 713 | astlpc->kcs_status = status; |
| 714 | |
| 715 | if (!(status & KCS_STATUS_BMC_READY)) |
| 716 | return -EHOSTDOWN; |
| 717 | |
Andrew Jeffery | 55fb90b | 2020-05-12 13:54:37 +0930 | [diff] [blame] | 718 | mctp_astlpc_lpc_read(astlpc, &hdr, 0, sizeof(hdr)); |
Andrew Jeffery | 7cd72f1 | 2020-05-12 20:27:59 +0930 | [diff] [blame] | 719 | |
Andrew Jeffery | 4e8264b | 2020-05-23 20:34:33 +0930 | [diff] [blame] | 720 | bmc_ver_min = be16toh(hdr.bmc_ver_min); |
| 721 | bmc_ver_cur = be16toh(hdr.bmc_ver_cur); |
| 722 | |
Andrew Jeffery | 88412be | 2021-03-09 22:05:22 +1030 | [diff] [blame] | 723 | /* Calculate the expected value of negotiated_ver */ |
Patrick Williams | a721c2d | 2022-12-04 14:30:26 -0600 | [diff] [blame] | 724 | negotiated = mctp_astlpc_negotiate_version( |
| 725 | bmc_ver_min, bmc_ver_cur, ASTLPC_VER_MIN, ASTLPC_VER_CUR); |
Andrew Jeffery | 88412be | 2021-03-09 22:05:22 +1030 | [diff] [blame] | 726 | if (!negotiated) { |
Andrew Jeffery | 4e8264b | 2020-05-23 20:34:33 +0930 | [diff] [blame] | 727 | astlpc_prerr(astlpc, "Cannot negotiate with invalid versions"); |
| 728 | return -EINVAL; |
| 729 | } |
| 730 | |
Andrew Jeffery | 88412be | 2021-03-09 22:05:22 +1030 | [diff] [blame] | 731 | /* Assign protocol ops so we can calculate the packet buffer sizes */ |
| 732 | assert(negotiated < ARRAY_SIZE(astlpc_protocol_version)); |
| 733 | astlpc->proto = &astlpc_protocol_version[negotiated]; |
| 734 | |
| 735 | /* Negotiate packet buffers in v2 style if the BMC supports it */ |
| 736 | if (negotiated >= 2) { |
Andrew Jeffery | 3a54066 | 2020-05-26 19:55:30 +0930 | [diff] [blame] | 737 | rc = mctp_astlpc_negotiate_layout_host(astlpc); |
| 738 | if (rc < 0) |
| 739 | return rc; |
| 740 | } |
| 741 | |
Andrew Jeffery | 88412be | 2021-03-09 22:05:22 +1030 | [diff] [blame] | 742 | /* Advertise the host's supported protocol versions */ |
Andrew Jeffery | 55fb90b | 2020-05-12 13:54:37 +0930 | [diff] [blame] | 743 | mctp_astlpc_lpc_write(astlpc, &ver_min_be, |
| 744 | offsetof(struct mctp_lpcmap_hdr, host_ver_min), |
| 745 | sizeof(ver_min_be)); |
Andrew Jeffery | 7cd72f1 | 2020-05-12 20:27:59 +0930 | [diff] [blame] | 746 | |
Andrew Jeffery | 55fb90b | 2020-05-12 13:54:37 +0930 | [diff] [blame] | 747 | mctp_astlpc_lpc_write(astlpc, &ver_cur_be, |
| 748 | offsetof(struct mctp_lpcmap_hdr, host_ver_cur), |
| 749 | sizeof(ver_cur_be)); |
Andrew Jeffery | 7cd72f1 | 2020-05-12 20:27:59 +0930 | [diff] [blame] | 750 | |
| 751 | /* Send channel init command */ |
Andrew Jeffery | f13cb97 | 2020-05-28 09:30:09 +0930 | [diff] [blame] | 752 | rc = mctp_astlpc_kcs_write(astlpc, MCTP_ASTLPC_KCS_REG_DATA, 0x0); |
Andrew Jeffery | 7cd72f1 | 2020-05-12 20:27:59 +0930 | [diff] [blame] | 753 | if (rc) { |
Andrew Jeffery | 9101a2a | 2020-05-22 16:08:03 +0930 | [diff] [blame] | 754 | astlpc_prwarn(astlpc, "KCS write failed"); |
Andrew Jeffery | 7cd72f1 | 2020-05-12 20:27:59 +0930 | [diff] [blame] | 755 | } |
| 756 | |
Andrew Jeffery | 88412be | 2021-03-09 22:05:22 +1030 | [diff] [blame] | 757 | /* |
| 758 | * Configure the host so `astlpc->proto->version == 0` holds until we |
| 759 | * receive a subsequent status update from the BMC. Until then, |
| 760 | * `astlpc->proto->version == 0` indicates that we're yet to complete |
| 761 | * the channel initialisation handshake. |
| 762 | * |
| 763 | * When the BMC provides a status update with KCS_STATUS_CHANNEL_ACTIVE |
| 764 | * set we will assign the appropriate protocol ops struct in accordance |
| 765 | * with `negotiated_ver`. |
| 766 | */ |
| 767 | astlpc->proto = &astlpc_protocol_version[ASTLPC_VER_BAD]; |
| 768 | |
Andrew Jeffery | 7cd72f1 | 2020-05-12 20:27:59 +0930 | [diff] [blame] | 769 | return rc; |
| 770 | } |
| 771 | |
| 772 | static int mctp_binding_astlpc_start_host(struct mctp_binding *b) |
| 773 | { |
| 774 | struct mctp_binding_astlpc *astlpc = |
| 775 | container_of(b, struct mctp_binding_astlpc, binding); |
| 776 | |
| 777 | return mctp_astlpc_init_host(astlpc); |
| 778 | } |
| 779 | |
| 780 | static bool __mctp_astlpc_kcs_ready(struct mctp_binding_astlpc *astlpc, |
| 781 | uint8_t status, bool is_write) |
| 782 | { |
| 783 | bool is_bmc; |
| 784 | bool ready_state; |
| 785 | uint8_t flag; |
| 786 | |
| 787 | is_bmc = (astlpc->mode == MCTP_BINDING_ASTLPC_MODE_BMC); |
| 788 | flag = (is_bmc ^ is_write) ? KCS_STATUS_IBF : KCS_STATUS_OBF; |
| 789 | ready_state = is_write ? 0 : 1; |
| 790 | |
| 791 | return !!(status & flag) == ready_state; |
| 792 | } |
| 793 | |
| 794 | static inline bool |
| 795 | mctp_astlpc_kcs_read_ready(struct mctp_binding_astlpc *astlpc, uint8_t status) |
| 796 | { |
| 797 | return __mctp_astlpc_kcs_ready(astlpc, status, false); |
| 798 | } |
| 799 | |
| 800 | static inline bool |
| 801 | mctp_astlpc_kcs_write_ready(struct mctp_binding_astlpc *astlpc, uint8_t status) |
| 802 | { |
| 803 | return __mctp_astlpc_kcs_ready(astlpc, status, true); |
| 804 | } |
| 805 | |
Jeremy Kerr | 672c885 | 2019-03-01 12:18:07 +0800 | [diff] [blame] | 806 | static int mctp_astlpc_kcs_send(struct mctp_binding_astlpc *astlpc, |
Rashmica Gupta | 45d1332 | 2022-08-10 12:12:14 +1000 | [diff] [blame] | 807 | enum mctp_astlpc_cmd data) |
Jeremy Kerr | 672c885 | 2019-03-01 12:18:07 +0800 | [diff] [blame] | 808 | { |
| 809 | uint8_t status; |
| 810 | int rc; |
| 811 | |
Patrick Williams | a721c2d | 2022-12-04 14:30:26 -0600 | [diff] [blame] | 812 | rc = mctp_astlpc_kcs_read(astlpc, MCTP_ASTLPC_KCS_REG_STATUS, &status); |
Andrew Jeffery | fe763e9 | 2022-08-05 23:16:17 +0930 | [diff] [blame] | 813 | if (rc) { |
| 814 | astlpc_prwarn(astlpc, "KCS status read failed"); |
| 815 | return -EIO; |
Jeremy Kerr | 672c885 | 2019-03-01 12:18:07 +0800 | [diff] [blame] | 816 | } |
Andrew Jeffery | fe763e9 | 2022-08-05 23:16:17 +0930 | [diff] [blame] | 817 | if (!mctp_astlpc_kcs_write_ready(astlpc, status)) |
| 818 | return -EBUSY; |
Jeremy Kerr | 672c885 | 2019-03-01 12:18:07 +0800 | [diff] [blame] | 819 | |
Andrew Jeffery | f13cb97 | 2020-05-28 09:30:09 +0930 | [diff] [blame] | 820 | rc = mctp_astlpc_kcs_write(astlpc, MCTP_ASTLPC_KCS_REG_DATA, data); |
Jeremy Kerr | bc53d35 | 2019-08-28 14:26:14 +0530 | [diff] [blame] | 821 | if (rc) { |
Andrew Jeffery | 9101a2a | 2020-05-22 16:08:03 +0930 | [diff] [blame] | 822 | astlpc_prwarn(astlpc, "KCS data write failed"); |
Andrew Jeffery | fe763e9 | 2022-08-05 23:16:17 +0930 | [diff] [blame] | 823 | return -EIO; |
Jeremy Kerr | 672c885 | 2019-03-01 12:18:07 +0800 | [diff] [blame] | 824 | } |
| 825 | |
| 826 | return 0; |
| 827 | } |
| 828 | |
| 829 | static int mctp_binding_astlpc_tx(struct mctp_binding *b, |
Patrick Williams | a721c2d | 2022-12-04 14:30:26 -0600 | [diff] [blame] | 830 | struct mctp_pktbuf *pkt) |
Jeremy Kerr | 672c885 | 2019-03-01 12:18:07 +0800 | [diff] [blame] | 831 | { |
| 832 | struct mctp_binding_astlpc *astlpc = binding_to_astlpc(b); |
Andrew Jeffery | 55fb90b | 2020-05-12 13:54:37 +0930 | [diff] [blame] | 833 | uint32_t len, len_be; |
Andrew Jeffery | edfe383 | 2020-02-06 11:52:11 +1030 | [diff] [blame] | 834 | struct mctp_hdr *hdr; |
Andrew Jeffery | fe763e9 | 2022-08-05 23:16:17 +0930 | [diff] [blame] | 835 | int rc; |
Jeremy Kerr | 672c885 | 2019-03-01 12:18:07 +0800 | [diff] [blame] | 836 | |
Andrew Jeffery | edfe383 | 2020-02-06 11:52:11 +1030 | [diff] [blame] | 837 | hdr = mctp_pktbuf_hdr(pkt); |
Jeremy Kerr | 672c885 | 2019-03-01 12:18:07 +0800 | [diff] [blame] | 838 | len = mctp_pktbuf_size(pkt); |
Andrew Jeffery | edfe383 | 2020-02-06 11:52:11 +1030 | [diff] [blame] | 839 | |
Andrew Jeffery | 9101a2a | 2020-05-22 16:08:03 +0930 | [diff] [blame] | 840 | astlpc_prdebug(astlpc, |
| 841 | "%s: Transmitting %" PRIu32 |
| 842 | "-byte packet (%hhu, %hhu, 0x%hhx)", |
| 843 | __func__, len, hdr->src, hdr->dest, hdr->flags_seq_tag); |
Andrew Jeffery | edfe383 | 2020-02-06 11:52:11 +1030 | [diff] [blame] | 844 | |
Andrew Jeffery | 88412be | 2021-03-09 22:05:22 +1030 | [diff] [blame] | 845 | if (len > astlpc->proto->body_size(astlpc->layout.tx.size)) { |
Andrew Jeffery | 0721f58 | 2022-09-29 12:12:39 +0930 | [diff] [blame] | 846 | astlpc_prwarn(astlpc, "invalid TX len %" PRIu32 ": %" PRIu32, |
| 847 | len, |
| 848 | astlpc->proto->body_size(astlpc->layout.tx.size)); |
| 849 | return -EMSGSIZE; |
Jeremy Kerr | 672c885 | 2019-03-01 12:18:07 +0800 | [diff] [blame] | 850 | } |
| 851 | |
Andrew Jeffery | fe763e9 | 2022-08-05 23:16:17 +0930 | [diff] [blame] | 852 | mctp_binding_set_tx_enabled(b, false); |
| 853 | |
Andrew Jeffery | 55fb90b | 2020-05-12 13:54:37 +0930 | [diff] [blame] | 854 | len_be = htobe32(len); |
| 855 | mctp_astlpc_lpc_write(astlpc, &len_be, astlpc->layout.tx.offset, |
| 856 | sizeof(len_be)); |
Andrew Jeffery | eba19a3 | 2021-03-09 23:09:40 +1030 | [diff] [blame] | 857 | |
| 858 | astlpc->proto->pktbuf_protect(pkt); |
| 859 | len = mctp_pktbuf_size(pkt); |
| 860 | |
Andrew Jeffery | 55fb90b | 2020-05-12 13:54:37 +0930 | [diff] [blame] | 861 | mctp_astlpc_lpc_write(astlpc, hdr, astlpc->layout.tx.offset + 4, len); |
Jeremy Kerr | 672c885 | 2019-03-01 12:18:07 +0800 | [diff] [blame] | 862 | |
Andrew Jeffery | fe763e9 | 2022-08-05 23:16:17 +0930 | [diff] [blame] | 863 | astlpc->layout.tx.state = buffer_state_prepared; |
Jeremy Kerr | 672c885 | 2019-03-01 12:18:07 +0800 | [diff] [blame] | 864 | |
Rashmica Gupta | 45d1332 | 2022-08-10 12:12:14 +1000 | [diff] [blame] | 865 | rc = mctp_astlpc_kcs_send(astlpc, cmd_tx_begin); |
Andrew Jeffery | fe763e9 | 2022-08-05 23:16:17 +0930 | [diff] [blame] | 866 | if (!rc) |
| 867 | astlpc->layout.tx.state = buffer_state_released; |
Andrew Jeffery | eba19a3 | 2021-03-09 23:09:40 +1030 | [diff] [blame] | 868 | |
Andrew Jeffery | fe763e9 | 2022-08-05 23:16:17 +0930 | [diff] [blame] | 869 | return rc == -EBUSY ? 0 : rc; |
Jeremy Kerr | 672c885 | 2019-03-01 12:18:07 +0800 | [diff] [blame] | 870 | } |
| 871 | |
Matt Johnston | 4a09e1d | 2024-09-13 14:55:58 +0800 | [diff] [blame] | 872 | /* Update binding pkt_size and reallocate tx_storage */ |
| 873 | static int mctp_astlpc_set_pkt_size(struct mctp_binding_astlpc *astlpc, |
| 874 | size_t pkt_size) |
| 875 | { |
| 876 | size_t body = MCTP_BODY_SIZE(pkt_size); |
| 877 | body += astlpc->binding.pkt_header + astlpc->binding.pkt_trailer; |
| 878 | size_t pktbuf_size = MCTP_PKTBUF_SIZE(body); |
| 879 | /* Reallocate TX storage */ |
| 880 | if (astlpc->binding.tx_storage) { |
| 881 | __mctp_free(astlpc->binding.tx_storage); |
| 882 | } |
| 883 | astlpc->binding.tx_storage = __mctp_alloc(pktbuf_size); |
| 884 | if (!astlpc->binding.tx_storage) { |
| 885 | return -ENOMEM; |
| 886 | } |
| 887 | |
| 888 | astlpc->binding.pkt_size = pkt_size; |
| 889 | return 0; |
| 890 | } |
| 891 | |
Andrew Jeffery | 3a54066 | 2020-05-26 19:55:30 +0930 | [diff] [blame] | 892 | static uint32_t mctp_astlpc_calculate_mtu(struct mctp_binding_astlpc *astlpc, |
| 893 | struct mctp_astlpc_layout *layout) |
| 894 | { |
Andrew Jeffery | 88412be | 2021-03-09 22:05:22 +1030 | [diff] [blame] | 895 | uint32_t low, high, limit, rpkt; |
Andrew Jeffery | 3a54066 | 2020-05-26 19:55:30 +0930 | [diff] [blame] | 896 | |
| 897 | /* Derive the largest MTU the BMC _can_ support */ |
| 898 | low = MIN(astlpc->layout.rx.offset, astlpc->layout.tx.offset); |
| 899 | high = MAX(astlpc->layout.rx.offset, astlpc->layout.tx.offset); |
| 900 | limit = high - low; |
| 901 | |
Andrew Jeffery | a936898 | 2020-06-09 13:07:39 +0930 | [diff] [blame] | 902 | /* Determine the largest MTU the BMC _wants_ to support */ |
| 903 | if (astlpc->requested_mtu) { |
Andrew Jeffery | 88412be | 2021-03-09 22:05:22 +1030 | [diff] [blame] | 904 | uint32_t rmtu = astlpc->requested_mtu; |
Andrew Jeffery | a936898 | 2020-06-09 13:07:39 +0930 | [diff] [blame] | 905 | |
Andrew Jeffery | 88412be | 2021-03-09 22:05:22 +1030 | [diff] [blame] | 906 | rpkt = astlpc->proto->packet_size(MCTP_PACKET_SIZE(rmtu)); |
| 907 | limit = MIN(limit, rpkt); |
Andrew Jeffery | a936898 | 2020-06-09 13:07:39 +0930 | [diff] [blame] | 908 | } |
Andrew Jeffery | 3a54066 | 2020-05-26 19:55:30 +0930 | [diff] [blame] | 909 | |
| 910 | /* Determine the accepted MTU, applied both directions by convention */ |
Andrew Jeffery | 88412be | 2021-03-09 22:05:22 +1030 | [diff] [blame] | 911 | rpkt = MIN(limit, layout->tx.size); |
| 912 | return MCTP_BODY_SIZE(astlpc->proto->body_size(rpkt)); |
Andrew Jeffery | 3a54066 | 2020-05-26 19:55:30 +0930 | [diff] [blame] | 913 | } |
| 914 | |
Andrew Jeffery | 88412be | 2021-03-09 22:05:22 +1030 | [diff] [blame] | 915 | static int mctp_astlpc_negotiate_layout_bmc(struct mctp_binding_astlpc *astlpc) |
Andrew Jeffery | 3a54066 | 2020-05-26 19:55:30 +0930 | [diff] [blame] | 916 | { |
| 917 | struct mctp_astlpc_layout proposed, pending; |
| 918 | uint32_t sz, mtu; |
| 919 | int rc; |
| 920 | |
Andrew Jeffery | 88412be | 2021-03-09 22:05:22 +1030 | [diff] [blame] | 921 | /* Do we have a valid protocol version? */ |
| 922 | if (!astlpc->proto->version) |
| 923 | return -EINVAL; |
| 924 | |
Andrew Jeffery | 3a54066 | 2020-05-26 19:55:30 +0930 | [diff] [blame] | 925 | /* Extract the host's proposed layout */ |
| 926 | rc = mctp_astlpc_layout_read(astlpc, &proposed); |
| 927 | if (rc < 0) |
| 928 | return rc; |
| 929 | |
Andrew Jeffery | 88412be | 2021-03-09 22:05:22 +1030 | [diff] [blame] | 930 | /* Do we have a reasonable layout? */ |
| 931 | if (!mctp_astlpc_layout_validate(astlpc, &proposed)) |
Andrew Jeffery | 3a54066 | 2020-05-26 19:55:30 +0930 | [diff] [blame] | 932 | return -EINVAL; |
| 933 | |
| 934 | /* Negotiate the MTU */ |
| 935 | mtu = mctp_astlpc_calculate_mtu(astlpc, &proposed); |
Andrew Jeffery | 88412be | 2021-03-09 22:05:22 +1030 | [diff] [blame] | 936 | sz = astlpc->proto->packet_size(MCTP_PACKET_SIZE(mtu)); |
Andrew Jeffery | 3a54066 | 2020-05-26 19:55:30 +0930 | [diff] [blame] | 937 | |
| 938 | /* |
| 939 | * Use symmetric MTUs by convention and to pass constraints in rx/tx |
| 940 | * functions |
| 941 | */ |
| 942 | pending = astlpc->layout; |
| 943 | pending.tx.size = sz; |
| 944 | pending.rx.size = sz; |
| 945 | |
Andrew Jeffery | 88412be | 2021-03-09 22:05:22 +1030 | [diff] [blame] | 946 | if (mctp_astlpc_layout_validate(astlpc, &pending)) { |
Andrew Jeffery | 3a54066 | 2020-05-26 19:55:30 +0930 | [diff] [blame] | 947 | /* We found a sensible Rx MTU, so honour it */ |
| 948 | astlpc->layout = pending; |
| 949 | |
| 950 | /* Enforce the negotiated MTU */ |
| 951 | rc = mctp_astlpc_layout_write(astlpc, &astlpc->layout); |
| 952 | if (rc < 0) |
| 953 | return rc; |
| 954 | |
| 955 | astlpc_prinfo(astlpc, "Negotiated an MTU of %" PRIu32 " bytes", |
| 956 | mtu); |
| 957 | } else { |
| 958 | astlpc_prwarn(astlpc, "MTU negotiation failed"); |
| 959 | return -EINVAL; |
| 960 | } |
| 961 | |
Matt Johnston | 4a09e1d | 2024-09-13 14:55:58 +0800 | [diff] [blame] | 962 | if (astlpc->proto->version >= 2) { |
| 963 | rc = mctp_astlpc_set_pkt_size(astlpc, MCTP_PACKET_SIZE(mtu)); |
| 964 | if (rc) { |
| 965 | astlpc_prwarn(astlpc, "Allocation error"); |
| 966 | return rc; |
| 967 | } |
| 968 | } |
Andrew Jeffery | 3a54066 | 2020-05-26 19:55:30 +0930 | [diff] [blame] | 969 | |
| 970 | return 0; |
| 971 | } |
| 972 | |
Jeremy Kerr | 672c885 | 2019-03-01 12:18:07 +0800 | [diff] [blame] | 973 | static void mctp_astlpc_init_channel(struct mctp_binding_astlpc *astlpc) |
| 974 | { |
Andrew Jeffery | 4e8264b | 2020-05-23 20:34:33 +0930 | [diff] [blame] | 975 | uint16_t negotiated, negotiated_be; |
| 976 | struct mctp_lpcmap_hdr hdr; |
| 977 | uint8_t status; |
Andrew Jeffery | 3a54066 | 2020-05-26 19:55:30 +0930 | [diff] [blame] | 978 | int rc; |
Andrew Jeffery | 4e8264b | 2020-05-23 20:34:33 +0930 | [diff] [blame] | 979 | |
| 980 | mctp_astlpc_lpc_read(astlpc, &hdr, 0, sizeof(hdr)); |
| 981 | |
| 982 | /* Version negotiation */ |
Andrew Jeffery | 7f7fdc1 | 2023-05-12 15:56:47 +0930 | [diff] [blame] | 983 | negotiated = mctp_astlpc_negotiate_version(ASTLPC_VER_MIN, |
| 984 | ASTLPC_VER_CUR, |
| 985 | be16toh(hdr.host_ver_min), |
| 986 | be16toh(hdr.host_ver_cur)); |
Andrew Jeffery | 4e8264b | 2020-05-23 20:34:33 +0930 | [diff] [blame] | 987 | |
Andrew Jeffery | 88412be | 2021-03-09 22:05:22 +1030 | [diff] [blame] | 988 | /* MTU negotiation requires knowing which protocol we'll use */ |
| 989 | assert(negotiated < ARRAY_SIZE(astlpc_protocol_version)); |
| 990 | astlpc->proto = &astlpc_protocol_version[negotiated]; |
| 991 | |
Andrew Jeffery | 3a54066 | 2020-05-26 19:55:30 +0930 | [diff] [blame] | 992 | /* Host Rx MTU negotiation: Failure terminates channel init */ |
Andrew Jeffery | 88412be | 2021-03-09 22:05:22 +1030 | [diff] [blame] | 993 | rc = mctp_astlpc_negotiate_layout_bmc(astlpc); |
Andrew Jeffery | 3a54066 | 2020-05-26 19:55:30 +0930 | [diff] [blame] | 994 | if (rc < 0) |
| 995 | negotiated = ASTLPC_VER_BAD; |
| 996 | |
Andrew Jeffery | 4e8264b | 2020-05-23 20:34:33 +0930 | [diff] [blame] | 997 | /* Populate the negotiated version */ |
Andrew Jeffery | 4e8264b | 2020-05-23 20:34:33 +0930 | [diff] [blame] | 998 | negotiated_be = htobe16(negotiated); |
| 999 | mctp_astlpc_lpc_write(astlpc, &negotiated_be, |
Andrew Jeffery | 55fb90b | 2020-05-12 13:54:37 +0930 | [diff] [blame] | 1000 | offsetof(struct mctp_lpcmap_hdr, negotiated_ver), |
Andrew Jeffery | 4e8264b | 2020-05-23 20:34:33 +0930 | [diff] [blame] | 1001 | sizeof(negotiated_be)); |
Andrew Jeffery | 55fb90b | 2020-05-12 13:54:37 +0930 | [diff] [blame] | 1002 | |
Andrew Jeffery | fe763e9 | 2022-08-05 23:16:17 +0930 | [diff] [blame] | 1003 | /* Track buffer ownership */ |
| 1004 | astlpc->layout.tx.state = buffer_state_acquired; |
| 1005 | astlpc->layout.rx.state = buffer_state_released; |
| 1006 | |
Andrew Jeffery | 4e8264b | 2020-05-23 20:34:33 +0930 | [diff] [blame] | 1007 | /* Finalise the configuration */ |
| 1008 | status = KCS_STATUS_BMC_READY | KCS_STATUS_OBF; |
| 1009 | if (negotiated > 0) { |
| 1010 | astlpc_prinfo(astlpc, "Negotiated binding version %" PRIu16, |
| 1011 | negotiated); |
| 1012 | status |= KCS_STATUS_CHANNEL_ACTIVE; |
| 1013 | } else { |
Andrew Jeffery | 88412be | 2021-03-09 22:05:22 +1030 | [diff] [blame] | 1014 | astlpc_prerr(astlpc, "Failed to initialise channel"); |
Andrew Jeffery | 4e8264b | 2020-05-23 20:34:33 +0930 | [diff] [blame] | 1015 | } |
Jeremy Kerr | 672c885 | 2019-03-01 12:18:07 +0800 | [diff] [blame] | 1016 | |
Andrew Jeffery | 4e8264b | 2020-05-23 20:34:33 +0930 | [diff] [blame] | 1017 | mctp_astlpc_kcs_set_status(astlpc, status); |
| 1018 | |
| 1019 | mctp_binding_set_tx_enabled(&astlpc->binding, |
| 1020 | status & KCS_STATUS_CHANNEL_ACTIVE); |
Jeremy Kerr | 672c885 | 2019-03-01 12:18:07 +0800 | [diff] [blame] | 1021 | } |
| 1022 | |
| 1023 | static void mctp_astlpc_rx_start(struct mctp_binding_astlpc *astlpc) |
| 1024 | { |
| 1025 | struct mctp_pktbuf *pkt; |
Rashmica Gupta | f447b4f | 2022-10-11 17:44:31 +1100 | [diff] [blame] | 1026 | struct mctp_hdr *hdr; |
Andrew Jeffery | eba19a3 | 2021-03-09 23:09:40 +1030 | [diff] [blame] | 1027 | uint32_t body, packet; |
Jeremy Kerr | 672c885 | 2019-03-01 12:18:07 +0800 | [diff] [blame] | 1028 | |
Andrew Jeffery | eba19a3 | 2021-03-09 23:09:40 +1030 | [diff] [blame] | 1029 | mctp_astlpc_lpc_read(astlpc, &body, astlpc->layout.rx.offset, |
| 1030 | sizeof(body)); |
| 1031 | body = be32toh(body); |
Jeremy Kerr | bc53d35 | 2019-08-28 14:26:14 +0530 | [diff] [blame] | 1032 | |
Andrew Jeffery | eba19a3 | 2021-03-09 23:09:40 +1030 | [diff] [blame] | 1033 | if (body > astlpc->proto->body_size(astlpc->layout.rx.size)) { |
| 1034 | astlpc_prwarn(astlpc, "invalid RX len 0x%x", body); |
Jeremy Kerr | 672c885 | 2019-03-01 12:18:07 +0800 | [diff] [blame] | 1035 | return; |
| 1036 | } |
| 1037 | |
Andrew Jeffery | 0f05b6c | 2022-11-15 11:37:50 +1030 | [diff] [blame] | 1038 | if ((size_t)body > astlpc->binding.pkt_size) { |
Andrew Jeffery | eba19a3 | 2021-03-09 23:09:40 +1030 | [diff] [blame] | 1039 | astlpc_prwarn(astlpc, "invalid RX len 0x%x", body); |
Jeremy Kerr | 672c885 | 2019-03-01 12:18:07 +0800 | [diff] [blame] | 1040 | return; |
| 1041 | } |
| 1042 | |
Andrew Jeffery | eba19a3 | 2021-03-09 23:09:40 +1030 | [diff] [blame] | 1043 | /* Eliminate the medium-specific header that we just read */ |
| 1044 | packet = astlpc->proto->packet_size(body) - 4; |
| 1045 | pkt = mctp_pktbuf_alloc(&astlpc->binding, packet); |
Christian Geddes | ae59f4f | 2021-09-01 09:54:25 -0500 | [diff] [blame] | 1046 | if (!pkt) { |
Patrick Williams | a721c2d | 2022-12-04 14:30:26 -0600 | [diff] [blame] | 1047 | astlpc_prwarn(astlpc, "unable to allocate pktbuf len 0x%x", |
| 1048 | packet); |
Christian Geddes | ae59f4f | 2021-09-01 09:54:25 -0500 | [diff] [blame] | 1049 | return; |
| 1050 | } |
Jeremy Kerr | 672c885 | 2019-03-01 12:18:07 +0800 | [diff] [blame] | 1051 | |
Andrew Jeffery | eba19a3 | 2021-03-09 23:09:40 +1030 | [diff] [blame] | 1052 | /* |
| 1053 | * Read payload and medium-specific trailer from immediately after the |
| 1054 | * medium-specific header. |
| 1055 | */ |
Andrew Jeffery | 55fb90b | 2020-05-12 13:54:37 +0930 | [diff] [blame] | 1056 | mctp_astlpc_lpc_read(astlpc, mctp_pktbuf_hdr(pkt), |
Andrew Jeffery | eba19a3 | 2021-03-09 23:09:40 +1030 | [diff] [blame] | 1057 | astlpc->layout.rx.offset + 4, packet); |
Jeremy Kerr | 672c885 | 2019-03-01 12:18:07 +0800 | [diff] [blame] | 1058 | |
Andrew Jeffery | fe763e9 | 2022-08-05 23:16:17 +0930 | [diff] [blame] | 1059 | astlpc->layout.rx.state = buffer_state_prepared; |
| 1060 | |
Christian Geddes | ae59f4f | 2021-09-01 09:54:25 -0500 | [diff] [blame] | 1061 | /* Inform the other side of the MCTP interface that we have read |
| 1062 | * the packet off the bus before handling the contents of the packet. |
| 1063 | */ |
Rashmica Gupta | 45d1332 | 2022-08-10 12:12:14 +1000 | [diff] [blame] | 1064 | if (!mctp_astlpc_kcs_send(astlpc, cmd_rx_complete)) |
Andrew Jeffery | fe763e9 | 2022-08-05 23:16:17 +0930 | [diff] [blame] | 1065 | astlpc->layout.rx.state = buffer_state_released; |
Christian Geddes | ae59f4f | 2021-09-01 09:54:25 -0500 | [diff] [blame] | 1066 | |
Rashmica Gupta | f447b4f | 2022-10-11 17:44:31 +1100 | [diff] [blame] | 1067 | hdr = mctp_pktbuf_hdr(pkt); |
| 1068 | if (hdr->ver != 1) { |
| 1069 | mctp_pktbuf_free(pkt); |
| 1070 | astlpc_prdebug(astlpc, "Dropped packet with invalid version"); |
| 1071 | return; |
| 1072 | } |
| 1073 | |
Andrew Jeffery | eba19a3 | 2021-03-09 23:09:40 +1030 | [diff] [blame] | 1074 | /* |
| 1075 | * v3 will validate the CRC32 in the medium-specific trailer and adjust |
| 1076 | * the packet size accordingly. On older protocols validation is a no-op |
| 1077 | * that always returns true. |
| 1078 | */ |
| 1079 | if (astlpc->proto->pktbuf_validate(pkt)) { |
| 1080 | mctp_bus_rx(&astlpc->binding, pkt); |
| 1081 | } else { |
| 1082 | /* TODO: Drop any associated assembly */ |
Andrew Jeffery | eba19a3 | 2021-03-09 23:09:40 +1030 | [diff] [blame] | 1083 | astlpc_prdebug(astlpc, "Dropped corrupt packet"); |
| 1084 | } |
Matt Johnston | 4a09e1d | 2024-09-13 14:55:58 +0800 | [diff] [blame] | 1085 | mctp_pktbuf_free(pkt); |
Jeremy Kerr | 672c885 | 2019-03-01 12:18:07 +0800 | [diff] [blame] | 1086 | } |
| 1087 | |
| 1088 | static void mctp_astlpc_tx_complete(struct mctp_binding_astlpc *astlpc) |
| 1089 | { |
Andrew Jeffery | fe763e9 | 2022-08-05 23:16:17 +0930 | [diff] [blame] | 1090 | astlpc->layout.tx.state = buffer_state_acquired; |
Jeremy Kerr | 672c885 | 2019-03-01 12:18:07 +0800 | [diff] [blame] | 1091 | mctp_binding_set_tx_enabled(&astlpc->binding, true); |
| 1092 | } |
| 1093 | |
Andrew Jeffery | 4e8264b | 2020-05-23 20:34:33 +0930 | [diff] [blame] | 1094 | static int mctp_astlpc_finalise_channel(struct mctp_binding_astlpc *astlpc) |
| 1095 | { |
Andrew Jeffery | 3a54066 | 2020-05-26 19:55:30 +0930 | [diff] [blame] | 1096 | struct mctp_astlpc_layout layout; |
Andrew Jeffery | 4e8264b | 2020-05-23 20:34:33 +0930 | [diff] [blame] | 1097 | uint16_t negotiated; |
| 1098 | int rc; |
| 1099 | |
| 1100 | rc = mctp_astlpc_lpc_read(astlpc, &negotiated, |
| 1101 | offsetof(struct mctp_lpcmap_hdr, |
| 1102 | negotiated_ver), |
| 1103 | sizeof(negotiated)); |
| 1104 | if (rc < 0) |
| 1105 | return rc; |
| 1106 | |
| 1107 | negotiated = be16toh(negotiated); |
Andrew Jeffery | 88412be | 2021-03-09 22:05:22 +1030 | [diff] [blame] | 1108 | astlpc_prerr(astlpc, "Version negotiation got: %u", negotiated); |
Andrew Jeffery | 4e8264b | 2020-05-23 20:34:33 +0930 | [diff] [blame] | 1109 | |
| 1110 | if (negotiated == ASTLPC_VER_BAD || negotiated < ASTLPC_VER_MIN || |
| 1111 | negotiated > ASTLPC_VER_CUR) { |
| 1112 | astlpc_prerr(astlpc, "Failed to negotiate version, got: %u\n", |
| 1113 | negotiated); |
| 1114 | return -EINVAL; |
| 1115 | } |
| 1116 | |
Andrew Jeffery | 88412be | 2021-03-09 22:05:22 +1030 | [diff] [blame] | 1117 | assert(negotiated < ARRAY_SIZE(astlpc_protocol_version)); |
| 1118 | astlpc->proto = &astlpc_protocol_version[negotiated]; |
Andrew Jeffery | 4e8264b | 2020-05-23 20:34:33 +0930 | [diff] [blame] | 1119 | |
Andrew Jeffery | 3a54066 | 2020-05-26 19:55:30 +0930 | [diff] [blame] | 1120 | rc = mctp_astlpc_layout_read(astlpc, &layout); |
| 1121 | if (rc < 0) |
| 1122 | return rc; |
| 1123 | |
Andrew Jeffery | 88412be | 2021-03-09 22:05:22 +1030 | [diff] [blame] | 1124 | if (!mctp_astlpc_layout_validate(astlpc, &layout)) { |
Andrew Jeffery | 3a54066 | 2020-05-26 19:55:30 +0930 | [diff] [blame] | 1125 | mctp_prerr("BMC proposed invalid buffer parameters"); |
| 1126 | return -EINVAL; |
| 1127 | } |
| 1128 | |
| 1129 | astlpc->layout = layout; |
| 1130 | |
| 1131 | if (negotiated >= 2) |
| 1132 | astlpc->binding.pkt_size = |
Andrew Jeffery | 88412be | 2021-03-09 22:05:22 +1030 | [diff] [blame] | 1133 | astlpc->proto->body_size(astlpc->layout.tx.size); |
Andrew Jeffery | 3a54066 | 2020-05-26 19:55:30 +0930 | [diff] [blame] | 1134 | |
Andrew Jeffery | fe763e9 | 2022-08-05 23:16:17 +0930 | [diff] [blame] | 1135 | /* Track buffer ownership */ |
| 1136 | astlpc->layout.tx.state = buffer_state_acquired; |
| 1137 | astlpc->layout.rx.state = buffer_state_released; |
| 1138 | |
Andrew Jeffery | 4e8264b | 2020-05-23 20:34:33 +0930 | [diff] [blame] | 1139 | return 0; |
| 1140 | } |
| 1141 | |
Andrew Jeffery | 7cd72f1 | 2020-05-12 20:27:59 +0930 | [diff] [blame] | 1142 | static int mctp_astlpc_update_channel(struct mctp_binding_astlpc *astlpc, |
| 1143 | uint8_t status) |
| 1144 | { |
| 1145 | uint8_t updated; |
| 1146 | int rc = 0; |
| 1147 | |
| 1148 | assert(astlpc->mode == MCTP_BINDING_ASTLPC_MODE_HOST); |
| 1149 | |
| 1150 | updated = astlpc->kcs_status ^ status; |
| 1151 | |
Andrew Jeffery | d0f5da0 | 2020-05-28 09:12:55 +0930 | [diff] [blame] | 1152 | astlpc_prdebug(astlpc, "%s: status: 0x%x, update: 0x%x", __func__, |
| 1153 | status, updated); |
| 1154 | |
Andrew Jeffery | 7cd72f1 | 2020-05-12 20:27:59 +0930 | [diff] [blame] | 1155 | if (updated & KCS_STATUS_BMC_READY) { |
Andrew Jeffery | d0f5da0 | 2020-05-28 09:12:55 +0930 | [diff] [blame] | 1156 | if (status & KCS_STATUS_BMC_READY) { |
| 1157 | astlpc->kcs_status = status; |
| 1158 | return astlpc->binding.start(&astlpc->binding); |
| 1159 | } else { |
Andrew Jeffery | fe763e9 | 2022-08-05 23:16:17 +0930 | [diff] [blame] | 1160 | /* Shut down the channel */ |
| 1161 | astlpc->layout.rx.state = buffer_state_idle; |
| 1162 | astlpc->layout.tx.state = buffer_state_idle; |
Andrew Jeffery | 7cd72f1 | 2020-05-12 20:27:59 +0930 | [diff] [blame] | 1163 | mctp_binding_set_tx_enabled(&astlpc->binding, false); |
Andrew Jeffery | d0f5da0 | 2020-05-28 09:12:55 +0930 | [diff] [blame] | 1164 | } |
Andrew Jeffery | 7cd72f1 | 2020-05-12 20:27:59 +0930 | [diff] [blame] | 1165 | } |
| 1166 | |
Andrew Jeffery | 88412be | 2021-03-09 22:05:22 +1030 | [diff] [blame] | 1167 | if (astlpc->proto->version == 0 || |
Patrick Williams | a721c2d | 2022-12-04 14:30:26 -0600 | [diff] [blame] | 1168 | updated & KCS_STATUS_CHANNEL_ACTIVE) { |
Andrew Jeffery | 4e8264b | 2020-05-23 20:34:33 +0930 | [diff] [blame] | 1169 | bool enable; |
| 1170 | |
Andrew Jeffery | fe763e9 | 2022-08-05 23:16:17 +0930 | [diff] [blame] | 1171 | astlpc->layout.rx.state = buffer_state_idle; |
| 1172 | astlpc->layout.tx.state = buffer_state_idle; |
Andrew Jeffery | 4e8264b | 2020-05-23 20:34:33 +0930 | [diff] [blame] | 1173 | rc = mctp_astlpc_finalise_channel(astlpc); |
| 1174 | enable = (status & KCS_STATUS_CHANNEL_ACTIVE) && rc == 0; |
Andrew Jeffery | 4e8264b | 2020-05-23 20:34:33 +0930 | [diff] [blame] | 1175 | mctp_binding_set_tx_enabled(&astlpc->binding, enable); |
| 1176 | } |
Andrew Jeffery | 7cd72f1 | 2020-05-12 20:27:59 +0930 | [diff] [blame] | 1177 | |
| 1178 | astlpc->kcs_status = status; |
| 1179 | |
| 1180 | return rc; |
| 1181 | } |
| 1182 | |
Frederic Barrat | 4df106d | 2023-05-16 17:45:42 +0200 | [diff] [blame] | 1183 | bool mctp_astlpc_tx_done(struct mctp_binding_astlpc *astlpc) |
| 1184 | { |
| 1185 | return astlpc->layout.tx.state == buffer_state_acquired; |
| 1186 | } |
| 1187 | |
Jeremy Kerr | 672c885 | 2019-03-01 12:18:07 +0800 | [diff] [blame] | 1188 | int mctp_astlpc_poll(struct mctp_binding_astlpc *astlpc) |
| 1189 | { |
Jeremy Kerr | bc53d35 | 2019-08-28 14:26:14 +0530 | [diff] [blame] | 1190 | uint8_t status, data; |
Jeremy Kerr | 672c885 | 2019-03-01 12:18:07 +0800 | [diff] [blame] | 1191 | int rc; |
| 1192 | |
Andrew Jeffery | fe763e9 | 2022-08-05 23:16:17 +0930 | [diff] [blame] | 1193 | if (astlpc->layout.rx.state == buffer_state_prepared) |
Rashmica Gupta | 45d1332 | 2022-08-10 12:12:14 +1000 | [diff] [blame] | 1194 | if (!mctp_astlpc_kcs_send(astlpc, cmd_rx_complete)) |
Andrew Jeffery | fe763e9 | 2022-08-05 23:16:17 +0930 | [diff] [blame] | 1195 | astlpc->layout.rx.state = buffer_state_released; |
| 1196 | |
| 1197 | if (astlpc->layout.tx.state == buffer_state_prepared) |
Rashmica Gupta | 45d1332 | 2022-08-10 12:12:14 +1000 | [diff] [blame] | 1198 | if (!mctp_astlpc_kcs_send(astlpc, cmd_tx_begin)) |
Andrew Jeffery | fe763e9 | 2022-08-05 23:16:17 +0930 | [diff] [blame] | 1199 | astlpc->layout.tx.state = buffer_state_released; |
| 1200 | |
Andrew Jeffery | f13cb97 | 2020-05-28 09:30:09 +0930 | [diff] [blame] | 1201 | rc = mctp_astlpc_kcs_read(astlpc, MCTP_ASTLPC_KCS_REG_STATUS, &status); |
Jeremy Kerr | bc53d35 | 2019-08-28 14:26:14 +0530 | [diff] [blame] | 1202 | if (rc) { |
Andrew Jeffery | 9101a2a | 2020-05-22 16:08:03 +0930 | [diff] [blame] | 1203 | astlpc_prwarn(astlpc, "KCS read error"); |
Jeremy Kerr | 672c885 | 2019-03-01 12:18:07 +0800 | [diff] [blame] | 1204 | return -1; |
Jeremy Kerr | 672c885 | 2019-03-01 12:18:07 +0800 | [diff] [blame] | 1205 | } |
| 1206 | |
Andrew Jeffery | 9101a2a | 2020-05-22 16:08:03 +0930 | [diff] [blame] | 1207 | astlpc_prdebug(astlpc, "%s: status: 0x%hhx", __func__, status); |
Andrew Jeffery | edfe383 | 2020-02-06 11:52:11 +1030 | [diff] [blame] | 1208 | |
Andrew Jeffery | 7cd72f1 | 2020-05-12 20:27:59 +0930 | [diff] [blame] | 1209 | if (!mctp_astlpc_kcs_read_ready(astlpc, status)) |
Jeremy Kerr | 672c885 | 2019-03-01 12:18:07 +0800 | [diff] [blame] | 1210 | return 0; |
| 1211 | |
Andrew Jeffery | f13cb97 | 2020-05-28 09:30:09 +0930 | [diff] [blame] | 1212 | rc = mctp_astlpc_kcs_read(astlpc, MCTP_ASTLPC_KCS_REG_DATA, &data); |
Jeremy Kerr | bc53d35 | 2019-08-28 14:26:14 +0530 | [diff] [blame] | 1213 | if (rc) { |
Andrew Jeffery | 9101a2a | 2020-05-22 16:08:03 +0930 | [diff] [blame] | 1214 | astlpc_prwarn(astlpc, "KCS data read error"); |
Jeremy Kerr | bc53d35 | 2019-08-28 14:26:14 +0530 | [diff] [blame] | 1215 | return -1; |
| 1216 | } |
| 1217 | |
Andrew Jeffery | 9101a2a | 2020-05-22 16:08:03 +0930 | [diff] [blame] | 1218 | astlpc_prdebug(astlpc, "%s: data: 0x%hhx", __func__, data); |
Andrew Jeffery | edfe383 | 2020-02-06 11:52:11 +1030 | [diff] [blame] | 1219 | |
Rashmica Gupta | 45d1332 | 2022-08-10 12:12:14 +1000 | [diff] [blame] | 1220 | if (!astlpc->proto->version && |
| 1221 | !(data == cmd_initialise || data == cmd_dummy_value)) { |
Andrew Jeffery | afcb701 | 2021-01-28 17:00:36 +1030 | [diff] [blame] | 1222 | astlpc_prwarn(astlpc, "Invalid message for binding state: 0x%x", |
| 1223 | data); |
| 1224 | return 0; |
| 1225 | } |
| 1226 | |
Jeremy Kerr | 672c885 | 2019-03-01 12:18:07 +0800 | [diff] [blame] | 1227 | switch (data) { |
Rashmica Gupta | 45d1332 | 2022-08-10 12:12:14 +1000 | [diff] [blame] | 1228 | case cmd_initialise: |
Jeremy Kerr | 672c885 | 2019-03-01 12:18:07 +0800 | [diff] [blame] | 1229 | mctp_astlpc_init_channel(astlpc); |
| 1230 | break; |
Rashmica Gupta | 45d1332 | 2022-08-10 12:12:14 +1000 | [diff] [blame] | 1231 | case cmd_tx_begin: |
Andrew Jeffery | fe763e9 | 2022-08-05 23:16:17 +0930 | [diff] [blame] | 1232 | if (astlpc->layout.rx.state != buffer_state_released) { |
Patrick Williams | a721c2d | 2022-12-04 14:30:26 -0600 | [diff] [blame] | 1233 | astlpc_prerr( |
| 1234 | astlpc, |
| 1235 | "Protocol error: Invalid Rx buffer state for event %d: %d\n", |
| 1236 | data, astlpc->layout.rx.state); |
Andrew Jeffery | fe763e9 | 2022-08-05 23:16:17 +0930 | [diff] [blame] | 1237 | return 0; |
| 1238 | } |
Jeremy Kerr | 672c885 | 2019-03-01 12:18:07 +0800 | [diff] [blame] | 1239 | mctp_astlpc_rx_start(astlpc); |
| 1240 | break; |
Rashmica Gupta | 45d1332 | 2022-08-10 12:12:14 +1000 | [diff] [blame] | 1241 | case cmd_rx_complete: |
Andrew Jeffery | fe763e9 | 2022-08-05 23:16:17 +0930 | [diff] [blame] | 1242 | if (astlpc->layout.tx.state != buffer_state_released) { |
Patrick Williams | a721c2d | 2022-12-04 14:30:26 -0600 | [diff] [blame] | 1243 | astlpc_prerr( |
| 1244 | astlpc, |
| 1245 | "Protocol error: Invalid Tx buffer state for event %d: %d\n", |
| 1246 | data, astlpc->layout.tx.state); |
Andrew Jeffery | fe763e9 | 2022-08-05 23:16:17 +0930 | [diff] [blame] | 1247 | return 0; |
| 1248 | } |
Jeremy Kerr | 672c885 | 2019-03-01 12:18:07 +0800 | [diff] [blame] | 1249 | mctp_astlpc_tx_complete(astlpc); |
| 1250 | break; |
Rashmica Gupta | 45d1332 | 2022-08-10 12:12:14 +1000 | [diff] [blame] | 1251 | case cmd_dummy_value: |
Andrew Jeffery | 7cd72f1 | 2020-05-12 20:27:59 +0930 | [diff] [blame] | 1252 | /* No responsibilities for the BMC on 0xff */ |
Andrew Jeffery | d0f5da0 | 2020-05-28 09:12:55 +0930 | [diff] [blame] | 1253 | if (astlpc->mode == MCTP_BINDING_ASTLPC_MODE_HOST) { |
| 1254 | rc = mctp_astlpc_update_channel(astlpc, status); |
| 1255 | if (rc < 0) |
| 1256 | return rc; |
| 1257 | } |
| 1258 | break; |
Jeremy Kerr | 672c885 | 2019-03-01 12:18:07 +0800 | [diff] [blame] | 1259 | default: |
Andrew Jeffery | 9101a2a | 2020-05-22 16:08:03 +0930 | [diff] [blame] | 1260 | astlpc_prwarn(astlpc, "unknown message 0x%x", data); |
Jeremy Kerr | 672c885 | 2019-03-01 12:18:07 +0800 | [diff] [blame] | 1261 | } |
Andrew Jeffery | d0f5da0 | 2020-05-28 09:12:55 +0930 | [diff] [blame] | 1262 | |
| 1263 | /* Handle silent loss of bmc-ready */ |
| 1264 | if (astlpc->mode == MCTP_BINDING_ASTLPC_MODE_HOST) { |
Rashmica Gupta | 45d1332 | 2022-08-10 12:12:14 +1000 | [diff] [blame] | 1265 | if (!(status & KCS_STATUS_BMC_READY && data == cmd_dummy_value)) |
Andrew Jeffery | d0f5da0 | 2020-05-28 09:12:55 +0930 | [diff] [blame] | 1266 | return mctp_astlpc_update_channel(astlpc, status); |
| 1267 | } |
| 1268 | |
| 1269 | return rc; |
Jeremy Kerr | 672c885 | 2019-03-01 12:18:07 +0800 | [diff] [blame] | 1270 | } |
| 1271 | |
Jeremy Kerr | bc53d35 | 2019-08-28 14:26:14 +0530 | [diff] [blame] | 1272 | /* allocate and basic initialisation */ |
Andrew Jeffery | 7cd72f1 | 2020-05-12 20:27:59 +0930 | [diff] [blame] | 1273 | static struct mctp_binding_astlpc *__mctp_astlpc_init(uint8_t mode, |
| 1274 | uint32_t mtu) |
Jeremy Kerr | bc53d35 | 2019-08-28 14:26:14 +0530 | [diff] [blame] | 1275 | { |
| 1276 | struct mctp_binding_astlpc *astlpc; |
| 1277 | |
Andrew Jeffery | 7cd72f1 | 2020-05-12 20:27:59 +0930 | [diff] [blame] | 1278 | assert((mode == MCTP_BINDING_ASTLPC_MODE_BMC) || |
| 1279 | (mode == MCTP_BINDING_ASTLPC_MODE_HOST)); |
| 1280 | |
Jeremy Kerr | bc53d35 | 2019-08-28 14:26:14 +0530 | [diff] [blame] | 1281 | astlpc = __mctp_alloc(sizeof(*astlpc)); |
Andrew Jeffery | 7cd72f1 | 2020-05-12 20:27:59 +0930 | [diff] [blame] | 1282 | if (!astlpc) |
| 1283 | return NULL; |
| 1284 | |
Jeremy Kerr | bc53d35 | 2019-08-28 14:26:14 +0530 | [diff] [blame] | 1285 | memset(astlpc, 0, sizeof(*astlpc)); |
Andrew Jeffery | 7cd72f1 | 2020-05-12 20:27:59 +0930 | [diff] [blame] | 1286 | astlpc->mode = mode; |
| 1287 | astlpc->lpc_map = NULL; |
Andrew Jeffery | fe763e9 | 2022-08-05 23:16:17 +0930 | [diff] [blame] | 1288 | astlpc->layout.rx.state = buffer_state_idle; |
| 1289 | astlpc->layout.tx.state = buffer_state_idle; |
Andrew Jeffery | a936898 | 2020-06-09 13:07:39 +0930 | [diff] [blame] | 1290 | astlpc->requested_mtu = mtu; |
Jeremy Kerr | bc53d35 | 2019-08-28 14:26:14 +0530 | [diff] [blame] | 1291 | astlpc->binding.name = "astlpc"; |
| 1292 | astlpc->binding.version = 1; |
Andrew Jeffery | eba19a3 | 2021-03-09 23:09:40 +1030 | [diff] [blame] | 1293 | astlpc->binding.pkt_header = 4; |
| 1294 | astlpc->binding.pkt_trailer = 4; |
Andrew Jeffery | 7cd72f1 | 2020-05-12 20:27:59 +0930 | [diff] [blame] | 1295 | astlpc->binding.tx = mctp_binding_astlpc_tx; |
| 1296 | if (mode == MCTP_BINDING_ASTLPC_MODE_BMC) |
| 1297 | astlpc->binding.start = mctp_binding_astlpc_start_bmc; |
| 1298 | else if (mode == MCTP_BINDING_ASTLPC_MODE_HOST) |
| 1299 | astlpc->binding.start = mctp_binding_astlpc_start_host; |
| 1300 | else { |
Andrew Jeffery | 9101a2a | 2020-05-22 16:08:03 +0930 | [diff] [blame] | 1301 | astlpc_prerr(astlpc, "%s: Invalid mode: %d\n", __func__, mode); |
Andrew Jeffery | 7cd72f1 | 2020-05-12 20:27:59 +0930 | [diff] [blame] | 1302 | __mctp_free(astlpc); |
| 1303 | return NULL; |
| 1304 | } |
Jeremy Kerr | bc53d35 | 2019-08-28 14:26:14 +0530 | [diff] [blame] | 1305 | |
Matt Johnston | 4a09e1d | 2024-09-13 14:55:58 +0800 | [diff] [blame] | 1306 | if (mctp_astlpc_set_pkt_size( |
| 1307 | astlpc, |
| 1308 | MCTP_PACKET_SIZE(mtu > MCTP_BTU ? mtu : MCTP_BTU)) != 0) { |
| 1309 | astlpc_prerr(astlpc, "%s: Allocation error", __func__); |
| 1310 | __mctp_free(astlpc); |
| 1311 | return NULL; |
| 1312 | } |
| 1313 | |
Jeremy Kerr | bc53d35 | 2019-08-28 14:26:14 +0530 | [diff] [blame] | 1314 | return astlpc; |
| 1315 | } |
| 1316 | |
Jeremy Kerr | 3b36d17 | 2019-09-04 11:56:09 +0800 | [diff] [blame] | 1317 | struct mctp_binding *mctp_binding_astlpc_core(struct mctp_binding_astlpc *b) |
| 1318 | { |
| 1319 | return &b->binding; |
| 1320 | } |
| 1321 | |
Andrew Jeffery | 7cd72f1 | 2020-05-12 20:27:59 +0930 | [diff] [blame] | 1322 | struct mctp_binding_astlpc * |
| 1323 | mctp_astlpc_init(uint8_t mode, uint32_t mtu, void *lpc_map, |
| 1324 | const struct mctp_binding_astlpc_ops *ops, void *ops_data) |
Jeremy Kerr | bc53d35 | 2019-08-28 14:26:14 +0530 | [diff] [blame] | 1325 | { |
| 1326 | struct mctp_binding_astlpc *astlpc; |
Jeremy Kerr | bc53d35 | 2019-08-28 14:26:14 +0530 | [diff] [blame] | 1327 | |
Andrew Jeffery | 7cd72f1 | 2020-05-12 20:27:59 +0930 | [diff] [blame] | 1328 | if (!(mode == MCTP_BINDING_ASTLPC_MODE_BMC || |
| 1329 | mode == MCTP_BINDING_ASTLPC_MODE_HOST)) { |
| 1330 | mctp_prerr("Unknown binding mode: %u", mode); |
| 1331 | return NULL; |
| 1332 | } |
| 1333 | |
Andrew Jeffery | 7cd72f1 | 2020-05-12 20:27:59 +0930 | [diff] [blame] | 1334 | astlpc = __mctp_astlpc_init(mode, mtu); |
Jeremy Kerr | bc53d35 | 2019-08-28 14:26:14 +0530 | [diff] [blame] | 1335 | if (!astlpc) |
| 1336 | return NULL; |
| 1337 | |
| 1338 | memcpy(&astlpc->ops, ops, sizeof(astlpc->ops)); |
| 1339 | astlpc->ops_data = ops_data; |
| 1340 | astlpc->lpc_map = lpc_map; |
Andrew Jeffery | 7cd72f1 | 2020-05-12 20:27:59 +0930 | [diff] [blame] | 1341 | astlpc->mode = mode; |
Jeremy Kerr | bc53d35 | 2019-08-28 14:26:14 +0530 | [diff] [blame] | 1342 | |
Jeremy Kerr | bc53d35 | 2019-08-28 14:26:14 +0530 | [diff] [blame] | 1343 | return astlpc; |
| 1344 | } |
| 1345 | |
Andrew Jeffery | 7cd72f1 | 2020-05-12 20:27:59 +0930 | [diff] [blame] | 1346 | struct mctp_binding_astlpc * |
| 1347 | mctp_astlpc_init_ops(const struct mctp_binding_astlpc_ops *ops, void *ops_data, |
| 1348 | void *lpc_map) |
| 1349 | { |
| 1350 | return mctp_astlpc_init(MCTP_BINDING_ASTLPC_MODE_BMC, MCTP_BTU, lpc_map, |
| 1351 | ops, ops_data); |
| 1352 | } |
| 1353 | |
Andrew Jeffery | 4663f67 | 2020-03-10 23:36:24 +1030 | [diff] [blame] | 1354 | void mctp_astlpc_destroy(struct mctp_binding_astlpc *astlpc) |
| 1355 | { |
Andrew Jeffery | d0f5da0 | 2020-05-28 09:12:55 +0930 | [diff] [blame] | 1356 | /* Clear channel-active and bmc-ready */ |
| 1357 | if (astlpc->mode == MCTP_BINDING_ASTLPC_MODE_BMC) |
Andrew Jeffery | 7c4509a | 2021-08-26 14:56:16 +0930 | [diff] [blame] | 1358 | mctp_astlpc_kcs_set_status(astlpc, 0); |
Matt Johnston | 4a09e1d | 2024-09-13 14:55:58 +0800 | [diff] [blame] | 1359 | __mctp_free(astlpc->binding.tx_storage); |
Andrew Jeffery | 4663f67 | 2020-03-10 23:36:24 +1030 | [diff] [blame] | 1360 | __mctp_free(astlpc); |
| 1361 | } |
| 1362 | |
Jeremy Kerr | b214c64 | 2019-11-27 11:34:00 +0800 | [diff] [blame] | 1363 | #ifdef MCTP_HAVE_FILEIO |
Andrew Jeffery | 55fb90b | 2020-05-12 13:54:37 +0930 | [diff] [blame] | 1364 | |
Jeremy Kerr | bc53d35 | 2019-08-28 14:26:14 +0530 | [diff] [blame] | 1365 | static int mctp_astlpc_init_fileio_lpc(struct mctp_binding_astlpc *astlpc) |
Jeremy Kerr | 672c885 | 2019-03-01 12:18:07 +0800 | [diff] [blame] | 1366 | { |
| 1367 | struct aspeed_lpc_ctrl_mapping map = { |
| 1368 | .window_type = ASPEED_LPC_CTRL_WINDOW_MEMORY, |
| 1369 | .window_id = 0, /* There's only one */ |
| 1370 | .flags = 0, |
| 1371 | .addr = 0, |
| 1372 | .offset = 0, |
| 1373 | .size = 0 |
| 1374 | }; |
Andrew Jeffery | 979c6a1 | 2020-05-23 20:04:49 +0930 | [diff] [blame] | 1375 | void *lpc_map_base; |
Jeremy Kerr | 672c885 | 2019-03-01 12:18:07 +0800 | [diff] [blame] | 1376 | int fd, rc; |
| 1377 | |
| 1378 | fd = open(lpc_path, O_RDWR | O_SYNC); |
| 1379 | if (fd < 0) { |
Andrew Jeffery | 9101a2a | 2020-05-22 16:08:03 +0930 | [diff] [blame] | 1380 | astlpc_prwarn(astlpc, "LPC open (%s) failed", lpc_path); |
Jeremy Kerr | 672c885 | 2019-03-01 12:18:07 +0800 | [diff] [blame] | 1381 | return -1; |
| 1382 | } |
| 1383 | |
| 1384 | rc = ioctl(fd, ASPEED_LPC_CTRL_IOCTL_GET_SIZE, &map); |
| 1385 | if (rc) { |
Andrew Jeffery | 9101a2a | 2020-05-22 16:08:03 +0930 | [diff] [blame] | 1386 | astlpc_prwarn(astlpc, "LPC GET_SIZE failed"); |
Jeremy Kerr | 672c885 | 2019-03-01 12:18:07 +0800 | [diff] [blame] | 1387 | close(fd); |
| 1388 | return -1; |
| 1389 | } |
| 1390 | |
Andrew Jeffery | c1d5c54 | 2021-10-27 15:25:48 +1030 | [diff] [blame] | 1391 | /* |
| 1392 | * 🚨🚨🚨 |
| 1393 | * |
| 1394 | * Decouple ourselves from hiomapd[1] (another user of the FW2AHB) by |
| 1395 | * mapping the FW2AHB to the reserved memory here as well. |
| 1396 | * |
| 1397 | * It's not possible to use the MCTP ASTLPC binding on machines that |
| 1398 | * need the FW2AHB bridge mapped anywhere except to the reserved memory |
| 1399 | * (e.g. the host SPI NOR). |
| 1400 | * |
| 1401 | * [1] https://github.com/openbmc/hiomapd/ |
| 1402 | * |
| 1403 | * 🚨🚨🚨 |
| 1404 | * |
| 1405 | * The following calculation must align with what's going on in |
| 1406 | * hiomapd's lpc.c so as not to disrupt its behaviour: |
| 1407 | * |
| 1408 | * https://github.com/openbmc/hiomapd/blob/5ff50e3cbd7702aefc185264e4adfb9952040575/lpc.c#L68 |
| 1409 | * |
| 1410 | * 🚨🚨🚨 |
| 1411 | */ |
| 1412 | |
| 1413 | /* Map the reserved memory at the top of the 28-bit LPC firmware address space */ |
| 1414 | map.addr = 0x0FFFFFFF & -map.size; |
Patrick Williams | a721c2d | 2022-12-04 14:30:26 -0600 | [diff] [blame] | 1415 | astlpc_prinfo( |
| 1416 | astlpc, |
| 1417 | "Configuring FW2AHB to map reserved memory at 0x%08x for 0x%x in the LPC FW cycle address-space", |
| 1418 | map.addr, map.size); |
Andrew Jeffery | c1d5c54 | 2021-10-27 15:25:48 +1030 | [diff] [blame] | 1419 | |
| 1420 | rc = ioctl(fd, ASPEED_LPC_CTRL_IOCTL_MAP, &map); |
| 1421 | if (rc) { |
Patrick Williams | a721c2d | 2022-12-04 14:30:26 -0600 | [diff] [blame] | 1422 | astlpc_prwarn(astlpc, |
| 1423 | "Failed to map FW2AHB to reserved memory"); |
Andrew Jeffery | c1d5c54 | 2021-10-27 15:25:48 +1030 | [diff] [blame] | 1424 | close(fd); |
| 1425 | return -1; |
| 1426 | } |
| 1427 | |
| 1428 | /* Map the reserved memory into our address space */ |
Andrew Jeffery | 979c6a1 | 2020-05-23 20:04:49 +0930 | [diff] [blame] | 1429 | lpc_map_base = |
| 1430 | mmap(NULL, map.size, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0); |
| 1431 | if (lpc_map_base == MAP_FAILED) { |
Andrew Jeffery | 9101a2a | 2020-05-22 16:08:03 +0930 | [diff] [blame] | 1432 | astlpc_prwarn(astlpc, "LPC mmap failed"); |
Jeremy Kerr | 672c885 | 2019-03-01 12:18:07 +0800 | [diff] [blame] | 1433 | rc = -1; |
| 1434 | } else { |
Matt Johnston | 3ef4778 | 2024-12-11 15:19:06 +0800 | [diff] [blame] | 1435 | astlpc->lpc_map = |
| 1436 | (uint8_t *)lpc_map_base + map.size - LPC_WIN_SIZE; |
Jeremy Kerr | 672c885 | 2019-03-01 12:18:07 +0800 | [diff] [blame] | 1437 | } |
| 1438 | |
| 1439 | close(fd); |
| 1440 | |
| 1441 | return rc; |
| 1442 | } |
| 1443 | |
Konstantin Aladyshev | 400766f | 2023-09-07 15:57:25 +0300 | [diff] [blame] | 1444 | static int mctp_astlpc_init_fileio_kcs(struct mctp_binding_astlpc *astlpc, |
| 1445 | const char *kcs_path) |
Jeremy Kerr | 672c885 | 2019-03-01 12:18:07 +0800 | [diff] [blame] | 1446 | { |
| 1447 | astlpc->kcs_fd = open(kcs_path, O_RDWR); |
| 1448 | if (astlpc->kcs_fd < 0) |
| 1449 | return -1; |
| 1450 | |
| 1451 | return 0; |
| 1452 | } |
| 1453 | |
Jeremy Kerr | bc53d35 | 2019-08-28 14:26:14 +0530 | [diff] [blame] | 1454 | static int __mctp_astlpc_fileio_kcs_read(void *arg, |
Patrick Williams | a721c2d | 2022-12-04 14:30:26 -0600 | [diff] [blame] | 1455 | enum mctp_binding_astlpc_kcs_reg reg, |
| 1456 | uint8_t *val) |
Jeremy Kerr | bc53d35 | 2019-08-28 14:26:14 +0530 | [diff] [blame] | 1457 | { |
| 1458 | struct mctp_binding_astlpc *astlpc = arg; |
| 1459 | off_t offset = reg; |
| 1460 | int rc; |
| 1461 | |
| 1462 | rc = pread(astlpc->kcs_fd, val, 1, offset); |
| 1463 | |
| 1464 | return rc == 1 ? 0 : -1; |
| 1465 | } |
| 1466 | |
| 1467 | static int __mctp_astlpc_fileio_kcs_write(void *arg, |
Patrick Williams | a721c2d | 2022-12-04 14:30:26 -0600 | [diff] [blame] | 1468 | enum mctp_binding_astlpc_kcs_reg reg, |
| 1469 | uint8_t val) |
Jeremy Kerr | bc53d35 | 2019-08-28 14:26:14 +0530 | [diff] [blame] | 1470 | { |
| 1471 | struct mctp_binding_astlpc *astlpc = arg; |
| 1472 | off_t offset = reg; |
| 1473 | int rc; |
| 1474 | |
| 1475 | rc = pwrite(astlpc->kcs_fd, &val, 1, offset); |
| 1476 | |
| 1477 | return rc == 1 ? 0 : -1; |
| 1478 | } |
| 1479 | |
Andrew Jeffery | 1111c6a | 2022-07-25 20:44:39 +0930 | [diff] [blame] | 1480 | int mctp_astlpc_init_pollfd(struct mctp_binding_astlpc *astlpc, |
| 1481 | struct pollfd *pollfd) |
| 1482 | { |
Andrew Jeffery | fe763e9 | 2022-08-05 23:16:17 +0930 | [diff] [blame] | 1483 | bool release; |
| 1484 | |
Andrew Jeffery | 1111c6a | 2022-07-25 20:44:39 +0930 | [diff] [blame] | 1485 | pollfd->fd = astlpc->kcs_fd; |
Andrew Jeffery | fe763e9 | 2022-08-05 23:16:17 +0930 | [diff] [blame] | 1486 | pollfd->events = 0; |
| 1487 | |
| 1488 | release = astlpc->layout.rx.state == buffer_state_prepared || |
Patrick Williams | a721c2d | 2022-12-04 14:30:26 -0600 | [diff] [blame] | 1489 | astlpc->layout.tx.state == buffer_state_prepared; |
Andrew Jeffery | fe763e9 | 2022-08-05 23:16:17 +0930 | [diff] [blame] | 1490 | |
| 1491 | pollfd->events = release ? POLLOUT : POLLIN; |
Andrew Jeffery | 1111c6a | 2022-07-25 20:44:39 +0930 | [diff] [blame] | 1492 | |
| 1493 | return 0; |
| 1494 | } |
| 1495 | |
Konstantin Aladyshev | 400766f | 2023-09-07 15:57:25 +0300 | [diff] [blame] | 1496 | struct mctp_binding_astlpc *mctp_astlpc_init_fileio(const char *kcs_path) |
Jeremy Kerr | 672c885 | 2019-03-01 12:18:07 +0800 | [diff] [blame] | 1497 | { |
| 1498 | struct mctp_binding_astlpc *astlpc; |
| 1499 | int rc; |
| 1500 | |
Andrew Jeffery | 7cd72f1 | 2020-05-12 20:27:59 +0930 | [diff] [blame] | 1501 | /* |
| 1502 | * If we're doing file IO then we're very likely not running |
Andrew Jeffery | 8877c46 | 2020-06-15 12:22:53 +0930 | [diff] [blame] | 1503 | * freestanding, so lets assume that we're on the BMC side. |
| 1504 | * |
| 1505 | * Requesting an MTU of 0 requests the largest possible MTU, whatever |
| 1506 | * value that might take. |
Andrew Jeffery | 7cd72f1 | 2020-05-12 20:27:59 +0930 | [diff] [blame] | 1507 | */ |
Andrew Jeffery | 8877c46 | 2020-06-15 12:22:53 +0930 | [diff] [blame] | 1508 | astlpc = __mctp_astlpc_init(MCTP_BINDING_ASTLPC_MODE_BMC, 0); |
Jeremy Kerr | bc53d35 | 2019-08-28 14:26:14 +0530 | [diff] [blame] | 1509 | if (!astlpc) |
| 1510 | return NULL; |
Jeremy Kerr | 672c885 | 2019-03-01 12:18:07 +0800 | [diff] [blame] | 1511 | |
Jeremy Kerr | bc53d35 | 2019-08-28 14:26:14 +0530 | [diff] [blame] | 1512 | /* Set internal operations for kcs. We use direct accesses to the lpc |
| 1513 | * map area */ |
| 1514 | astlpc->ops.kcs_read = __mctp_astlpc_fileio_kcs_read; |
| 1515 | astlpc->ops.kcs_write = __mctp_astlpc_fileio_kcs_write; |
| 1516 | astlpc->ops_data = astlpc; |
| 1517 | |
| 1518 | rc = mctp_astlpc_init_fileio_lpc(astlpc); |
Jeremy Kerr | 672c885 | 2019-03-01 12:18:07 +0800 | [diff] [blame] | 1519 | if (rc) { |
| 1520 | free(astlpc); |
| 1521 | return NULL; |
| 1522 | } |
| 1523 | |
Konstantin Aladyshev | 400766f | 2023-09-07 15:57:25 +0300 | [diff] [blame] | 1524 | rc = mctp_astlpc_init_fileio_kcs(astlpc, kcs_path); |
Jeremy Kerr | 672c885 | 2019-03-01 12:18:07 +0800 | [diff] [blame] | 1525 | if (rc) { |
| 1526 | free(astlpc); |
| 1527 | return NULL; |
| 1528 | } |
| 1529 | |
Jeremy Kerr | 672c885 | 2019-03-01 12:18:07 +0800 | [diff] [blame] | 1530 | return astlpc; |
| 1531 | } |
Jeremy Kerr | 92a10a6 | 2019-08-28 16:55:54 +0530 | [diff] [blame] | 1532 | #else |
Konstantin Aladyshev | 400766f | 2023-09-07 15:57:25 +0300 | [diff] [blame] | 1533 | struct mctp_binding_astlpc * |
| 1534 | mctp_astlpc_init_fileio(const char *kcs_path __unused) |
Jeremy Kerr | 92a10a6 | 2019-08-28 16:55:54 +0530 | [diff] [blame] | 1535 | { |
Andrew Jeffery | 5b2702d | 2022-07-25 16:21:43 +0930 | [diff] [blame] | 1536 | mctp_prlog(MCTP_LOG_ERR, "%s: Missing support for file IO", __func__); |
Jeremy Kerr | 92a10a6 | 2019-08-28 16:55:54 +0530 | [diff] [blame] | 1537 | return NULL; |
| 1538 | } |
Jeremy Kerr | 672c885 | 2019-03-01 12:18:07 +0800 | [diff] [blame] | 1539 | |
Andrew Jeffery | 1111c6a | 2022-07-25 20:44:39 +0930 | [diff] [blame] | 1540 | int mctp_astlpc_init_pollfd(struct mctp_binding_astlpc *astlpc __unused, |
| 1541 | struct pollfd *pollfd __unused) |
| 1542 | { |
| 1543 | mctp_prlog(MCTP_LOG_ERR, "%s: Missing support for file IO", __func__); |
| 1544 | return -1; |
| 1545 | } |
Jeremy Kerr | 92a10a6 | 2019-08-28 16:55:54 +0530 | [diff] [blame] | 1546 | #endif |