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