1 /* SPDX-License-Identifier: Apache-2.0 */ 2 /* Copyright (C) 2018 IBM Corp. */ 3 4 #ifndef PROTOCOL_H 5 #define PROTOCOL_H 6 7 struct mbox_context; 8 struct transport_ops; 9 10 /* 11 * The GET_MBOX_INFO command is special as it can change the interface based on 12 * negotiation. As such we need to accommodate all response types 13 */ 14 struct protocol_get_info { 15 struct { 16 uint8_t api_version; 17 } req; 18 struct { 19 uint8_t api_version; 20 union { 21 struct { 22 uint16_t read_window_size; 23 uint16_t write_window_size; 24 } v1; 25 struct { 26 uint8_t block_size_shift; 27 uint16_t timeout; 28 } v2; 29 }; 30 } resp; 31 }; 32 33 struct protocol_get_flash_info { 34 struct { 35 union { 36 struct { 37 uint32_t flash_size; 38 uint32_t erase_size; 39 } v1; 40 struct { 41 uint16_t flash_size; 42 uint16_t erase_size; 43 } v2; 44 }; 45 } resp; 46 }; 47 48 struct protocol_create_window { 49 struct { 50 uint16_t offset; 51 uint16_t size; 52 uint8_t id; 53 bool ro; 54 } req; 55 struct { 56 uint16_t lpc_address; 57 uint16_t size; 58 uint16_t offset; 59 } resp; 60 }; 61 62 struct protocol_mark_dirty { 63 struct { 64 union { 65 struct { 66 uint16_t offset; 67 uint32_t size; 68 } v1; 69 struct { 70 uint16_t offset; 71 uint16_t size; 72 } v2; 73 }; 74 } req; 75 }; 76 77 struct protocol_erase { 78 struct { 79 uint16_t offset; 80 uint16_t size; 81 } req; 82 }; 83 84 struct protocol_flush { 85 struct { 86 uint16_t offset; 87 uint32_t size; 88 } req; 89 }; 90 91 struct protocol_close { 92 struct { 93 uint8_t flags; 94 } req; 95 }; 96 97 struct protocol_ack { 98 struct { 99 uint8_t flags; 100 } req; 101 }; 102 103 struct protocol_ops { 104 int (*reset)(struct mbox_context *context); 105 int (*get_info)(struct mbox_context *context, 106 struct protocol_get_info *io); 107 int (*get_flash_info)(struct mbox_context *context, 108 struct protocol_get_flash_info *io); 109 int (*create_window)(struct mbox_context *context, 110 struct protocol_create_window *io); 111 int (*mark_dirty)(struct mbox_context *context, 112 struct protocol_mark_dirty *io); 113 int (*erase)(struct mbox_context *context, struct protocol_erase *io); 114 int (*flush)(struct mbox_context *context, struct protocol_flush *io); 115 int (*close)(struct mbox_context *context, struct protocol_close *io); 116 int (*ack)(struct mbox_context *context, struct protocol_ack *io); 117 }; 118 119 int protocol_init(struct mbox_context *context); 120 void protocol_free(struct mbox_context *context); 121 122 int protocol_negotiate_version(struct mbox_context *context, uint8_t requested); 123 124 int protocol_events_put(struct mbox_context *context, 125 const struct transport_ops *ops); 126 int protocol_events_set(struct mbox_context *context, uint8_t bmc_event); 127 int protocol_events_clear(struct mbox_context *context, uint8_t bmc_event); 128 129 /* Protocol v1 */ 130 int protocol_v1_reset(struct mbox_context *context); 131 int protocol_v1_get_info(struct mbox_context *context, 132 struct protocol_get_info *io); 133 int protocol_v1_get_flash_info(struct mbox_context *context, 134 struct protocol_get_flash_info *io); 135 int protocol_v1_create_window(struct mbox_context *context, 136 struct protocol_create_window *io); 137 int protocol_v1_mark_dirty(struct mbox_context *context, 138 struct protocol_mark_dirty *io); 139 int protocol_v1_flush(struct mbox_context *context, struct protocol_flush *io); 140 int protocol_v1_close(struct mbox_context *context, struct protocol_close *io); 141 int protocol_v1_ack(struct mbox_context *context, struct protocol_ack *io); 142 143 /* Protocol v2 */ 144 int protocol_v2_get_info(struct mbox_context *context, 145 struct protocol_get_info *io); 146 int protocol_v2_get_flash_info(struct mbox_context *context, 147 struct protocol_get_flash_info *io); 148 int protocol_v2_create_window(struct mbox_context *context, 149 struct protocol_create_window *io); 150 int protocol_v2_mark_dirty(struct mbox_context *context, 151 struct protocol_mark_dirty *io); 152 int protocol_v2_erase(struct mbox_context *context, 153 struct protocol_erase *io); 154 int protocol_v2_flush(struct mbox_context *context, struct protocol_flush *io); 155 int protocol_v2_close(struct mbox_context *context, struct protocol_close *io); 156 157 #endif /* PROTOCOL_H */ 158