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 | 1e531af | 2018-08-07 13:32:57 +0930 | [diff] [blame] | 47 | struct protocol_ops { |
Andrew Jeffery | ab666a5 | 2018-08-07 14:28:09 +0930 | [diff] [blame] | 48 | int (*reset)(struct mbox_context *context); |
Andrew Jeffery | 1e531af | 2018-08-07 13:32:57 +0930 | [diff] [blame] | 49 | int (*get_info)(struct mbox_context *context, |
| 50 | struct protocol_get_info *io); |
Andrew Jeffery | 91a8745 | 2018-08-07 14:54:14 +0930 | [diff] [blame^] | 51 | int (*get_flash_info)(struct mbox_context *context, |
| 52 | struct protocol_get_flash_info *io); |
Andrew Jeffery | 1e531af | 2018-08-07 13:32:57 +0930 | [diff] [blame] | 53 | }; |
| 54 | |
| 55 | int protocol_init(struct mbox_context *context); |
| 56 | void protocol_free(struct mbox_context *context); |
| 57 | |
| 58 | int protocol_negotiate_version(struct mbox_context *context, uint8_t requested); |
| 59 | |
| 60 | /* Protocol v1 */ |
Andrew Jeffery | ab666a5 | 2018-08-07 14:28:09 +0930 | [diff] [blame] | 61 | int protocol_v1_reset(struct mbox_context *context); |
Andrew Jeffery | 1e531af | 2018-08-07 13:32:57 +0930 | [diff] [blame] | 62 | int protocol_v1_get_info(struct mbox_context *context, |
| 63 | struct protocol_get_info *io); |
Andrew Jeffery | 91a8745 | 2018-08-07 14:54:14 +0930 | [diff] [blame^] | 64 | int protocol_v1_get_flash_info(struct mbox_context *context, |
| 65 | struct protocol_get_flash_info *io); |
Andrew Jeffery | 1e531af | 2018-08-07 13:32:57 +0930 | [diff] [blame] | 66 | |
| 67 | /* Protocol v2 */ |
| 68 | int protocol_v2_get_info(struct mbox_context *context, |
| 69 | struct protocol_get_info *io); |
Andrew Jeffery | 91a8745 | 2018-08-07 14:54:14 +0930 | [diff] [blame^] | 70 | int protocol_v2_get_flash_info(struct mbox_context *context, |
| 71 | struct protocol_get_flash_info *io); |
Andrew Jeffery | 1e531af | 2018-08-07 13:32:57 +0930 | [diff] [blame] | 72 | |
| 73 | #endif /* PROTOCOL_H */ |