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; |
Andrew Jeffery | fe0c9e8 | 2018-11-01 14:02:17 +1030 | [diff] [blame] | 8 | struct transport_ops; |
Andrew Jeffery | 1e531af | 2018-08-07 13:32:57 +0930 | [diff] [blame] | 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 | |
Andrew Jeffery | 91a8745 | 2018-08-07 14:54:14 +0930 | [diff] [blame] | 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 | |
Andrew Jeffery | 22fa500 | 2018-08-07 15:22:50 +0930 | [diff] [blame] | 48 | struct protocol_create_window { |
| 49 | struct { |
| 50 | uint16_t offset; |
| 51 | uint16_t size; |
| 52 | uint8_t id; |
Andrew Jeffery | 4bcec8e | 2018-08-07 15:33:41 +0930 | [diff] [blame] | 53 | bool ro; |
Andrew Jeffery | 22fa500 | 2018-08-07 15:22:50 +0930 | [diff] [blame] | 54 | } req; |
| 55 | struct { |
| 56 | uint16_t lpc_address; |
| 57 | uint16_t size; |
| 58 | uint16_t offset; |
| 59 | } resp; |
| 60 | }; |
| 61 | |
Andrew Jeffery | a336e43 | 2018-08-07 16:00:40 +0930 | [diff] [blame] | 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 | |
Andrew Jeffery | 62a3daa | 2018-08-07 22:30:32 +0930 | [diff] [blame] | 77 | struct protocol_erase { |
| 78 | struct { |
| 79 | uint16_t offset; |
| 80 | uint16_t size; |
| 81 | } req; |
| 82 | }; |
| 83 | |
Andrew Jeffery | 9b920cf | 2018-08-07 22:49:19 +0930 | [diff] [blame] | 84 | struct protocol_flush { |
| 85 | struct { |
| 86 | uint16_t offset; |
| 87 | uint32_t size; |
| 88 | } req; |
| 89 | }; |
Andrew Jeffery | 62a3daa | 2018-08-07 22:30:32 +0930 | [diff] [blame] | 90 | |
Andrew Jeffery | 093eda5 | 2018-08-07 23:10:43 +0930 | [diff] [blame] | 91 | struct protocol_close { |
| 92 | struct { |
| 93 | uint8_t flags; |
| 94 | } req; |
| 95 | }; |
| 96 | |
Andrew Jeffery | c5c8304 | 2018-08-07 23:22:05 +0930 | [diff] [blame] | 97 | struct protocol_ack { |
| 98 | struct { |
| 99 | uint8_t flags; |
| 100 | } req; |
| 101 | }; |
| 102 | |
Andrew Jeffery | 1e531af | 2018-08-07 13:32:57 +0930 | [diff] [blame] | 103 | struct protocol_ops { |
Andrew Jeffery | ab666a5 | 2018-08-07 14:28:09 +0930 | [diff] [blame] | 104 | int (*reset)(struct mbox_context *context); |
Andrew Jeffery | 1e531af | 2018-08-07 13:32:57 +0930 | [diff] [blame] | 105 | int (*get_info)(struct mbox_context *context, |
| 106 | struct protocol_get_info *io); |
Andrew Jeffery | 91a8745 | 2018-08-07 14:54:14 +0930 | [diff] [blame] | 107 | int (*get_flash_info)(struct mbox_context *context, |
| 108 | struct protocol_get_flash_info *io); |
Andrew Jeffery | 4bcec8e | 2018-08-07 15:33:41 +0930 | [diff] [blame] | 109 | int (*create_window)(struct mbox_context *context, |
| 110 | struct protocol_create_window *io); |
Andrew Jeffery | a336e43 | 2018-08-07 16:00:40 +0930 | [diff] [blame] | 111 | int (*mark_dirty)(struct mbox_context *context, |
| 112 | struct protocol_mark_dirty *io); |
Andrew Jeffery | 62a3daa | 2018-08-07 22:30:32 +0930 | [diff] [blame] | 113 | int (*erase)(struct mbox_context *context, struct protocol_erase *io); |
Andrew Jeffery | 9b920cf | 2018-08-07 22:49:19 +0930 | [diff] [blame] | 114 | int (*flush)(struct mbox_context *context, struct protocol_flush *io); |
Andrew Jeffery | 093eda5 | 2018-08-07 23:10:43 +0930 | [diff] [blame] | 115 | int (*close)(struct mbox_context *context, struct protocol_close *io); |
Andrew Jeffery | c5c8304 | 2018-08-07 23:22:05 +0930 | [diff] [blame] | 116 | int (*ack)(struct mbox_context *context, struct protocol_ack *io); |
Andrew Jeffery | 1e531af | 2018-08-07 13:32:57 +0930 | [diff] [blame] | 117 | }; |
| 118 | |
| 119 | int protocol_init(struct mbox_context *context); |
| 120 | void protocol_free(struct mbox_context *context); |
| 121 | |
Andrew Jeffery | f69760d | 2019-03-14 16:54:13 +1030 | [diff] [blame] | 122 | /* Sneaky reset: Don't tell the host */ |
| 123 | int __protocol_reset(struct mbox_context *context); |
| 124 | |
| 125 | /* Noisy reset: Tell the host */ |
| 126 | int protocol_reset(struct mbox_context *context); |
| 127 | |
Andrew Jeffery | fe0c9e8 | 2018-11-01 14:02:17 +1030 | [diff] [blame] | 128 | int protocol_events_put(struct mbox_context *context, |
| 129 | const struct transport_ops *ops); |
Andrew Jeffery | 2ebfd20 | 2018-08-20 11:46:28 +0930 | [diff] [blame] | 130 | int protocol_events_set(struct mbox_context *context, uint8_t bmc_event); |
| 131 | int protocol_events_clear(struct mbox_context *context, uint8_t bmc_event); |
Andrew Jeffery | 5335f09 | 2018-08-09 14:56:08 +0930 | [diff] [blame] | 132 | |
Andrew Jeffery | 1e531af | 2018-08-07 13:32:57 +0930 | [diff] [blame] | 133 | #endif /* PROTOCOL_H */ |