blob: f571fe1fcf97f062d92d00f17f2afa3ff76f951e [file] [log] [blame]
Andrew Jeffery1e531af2018-08-07 13:32:57 +09301/* SPDX-License-Identifier: Apache-2.0 */
2/* Copyright (C) 2018 IBM Corp. */
3
4#ifndef PROTOCOL_H
5#define PROTOCOL_H
6
7struct mbox_context;
Andrew Jefferyfe0c9e82018-11-01 14:02:17 +10308struct transport_ops;
Andrew Jeffery1e531af2018-08-07 13:32:57 +09309
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 */
14struct 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 Jeffery91a87452018-08-07 14:54:14 +093033struct 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 Jeffery22fa5002018-08-07 15:22:50 +093048struct protocol_create_window {
49 struct {
50 uint16_t offset;
51 uint16_t size;
52 uint8_t id;
Andrew Jeffery4bcec8e2018-08-07 15:33:41 +093053 bool ro;
Andrew Jeffery22fa5002018-08-07 15:22:50 +093054 } req;
55 struct {
56 uint16_t lpc_address;
57 uint16_t size;
58 uint16_t offset;
59 } resp;
60};
61
Andrew Jefferya336e432018-08-07 16:00:40 +093062struct 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 Jeffery62a3daa2018-08-07 22:30:32 +093077struct protocol_erase {
78 struct {
79 uint16_t offset;
80 uint16_t size;
81 } req;
82};
83
Andrew Jeffery9b920cf2018-08-07 22:49:19 +093084struct protocol_flush {
85 struct {
86 uint16_t offset;
87 uint32_t size;
88 } req;
89};
Andrew Jeffery62a3daa2018-08-07 22:30:32 +093090
Andrew Jeffery093eda52018-08-07 23:10:43 +093091struct protocol_close {
92 struct {
93 uint8_t flags;
94 } req;
95};
96
Andrew Jefferyc5c83042018-08-07 23:22:05 +093097struct protocol_ack {
98 struct {
99 uint8_t flags;
100 } req;
101};
102
Andrew Jeffery1e531af2018-08-07 13:32:57 +0930103struct protocol_ops {
Andrew Jefferyab666a52018-08-07 14:28:09 +0930104 int (*reset)(struct mbox_context *context);
Andrew Jeffery1e531af2018-08-07 13:32:57 +0930105 int (*get_info)(struct mbox_context *context,
106 struct protocol_get_info *io);
Andrew Jeffery91a87452018-08-07 14:54:14 +0930107 int (*get_flash_info)(struct mbox_context *context,
108 struct protocol_get_flash_info *io);
Andrew Jeffery4bcec8e2018-08-07 15:33:41 +0930109 int (*create_window)(struct mbox_context *context,
110 struct protocol_create_window *io);
Andrew Jefferya336e432018-08-07 16:00:40 +0930111 int (*mark_dirty)(struct mbox_context *context,
112 struct protocol_mark_dirty *io);
Andrew Jeffery62a3daa2018-08-07 22:30:32 +0930113 int (*erase)(struct mbox_context *context, struct protocol_erase *io);
Andrew Jeffery9b920cf2018-08-07 22:49:19 +0930114 int (*flush)(struct mbox_context *context, struct protocol_flush *io);
Andrew Jeffery093eda52018-08-07 23:10:43 +0930115 int (*close)(struct mbox_context *context, struct protocol_close *io);
Andrew Jefferyc5c83042018-08-07 23:22:05 +0930116 int (*ack)(struct mbox_context *context, struct protocol_ack *io);
Andrew Jeffery1e531af2018-08-07 13:32:57 +0930117};
118
119int protocol_init(struct mbox_context *context);
120void protocol_free(struct mbox_context *context);
121
Andrew Jefferyf69760d2019-03-14 16:54:13 +1030122/* Sneaky reset: Don't tell the host */
123int __protocol_reset(struct mbox_context *context);
124
125/* Noisy reset: Tell the host */
126int protocol_reset(struct mbox_context *context);
127
Andrew Jefferyfe0c9e82018-11-01 14:02:17 +1030128int protocol_events_put(struct mbox_context *context,
129 const struct transport_ops *ops);
Andrew Jeffery2ebfd202018-08-20 11:46:28 +0930130int protocol_events_set(struct mbox_context *context, uint8_t bmc_event);
131int protocol_events_clear(struct mbox_context *context, uint8_t bmc_event);
Andrew Jeffery5335f092018-08-09 14:56:08 +0930132
Andrew Jeffery1e531af2018-08-07 13:32:57 +0930133#endif /* PROTOCOL_H */