blob: 2c1e725e5216f6d4ee151cb101493f4f9a1b305d [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
122int protocol_negotiate_version(struct mbox_context *context, uint8_t requested);
123
Andrew Jefferyfe0c9e82018-11-01 14:02:17 +1030124int protocol_events_put(struct mbox_context *context,
125 const struct transport_ops *ops);
Andrew Jeffery2ebfd202018-08-20 11:46:28 +0930126int protocol_events_set(struct mbox_context *context, uint8_t bmc_event);
127int protocol_events_clear(struct mbox_context *context, uint8_t bmc_event);
Andrew Jeffery5335f092018-08-09 14:56:08 +0930128
Andrew Jeffery1e531af2018-08-07 13:32:57 +0930129/* Protocol v1 */
Andrew Jefferyab666a52018-08-07 14:28:09 +0930130int protocol_v1_reset(struct mbox_context *context);
Andrew Jeffery1e531af2018-08-07 13:32:57 +0930131int protocol_v1_get_info(struct mbox_context *context,
132 struct protocol_get_info *io);
Andrew Jeffery91a87452018-08-07 14:54:14 +0930133int protocol_v1_get_flash_info(struct mbox_context *context,
134 struct protocol_get_flash_info *io);
Andrew Jeffery4bcec8e2018-08-07 15:33:41 +0930135int protocol_v1_create_window(struct mbox_context *context,
136 struct protocol_create_window *io);
Andrew Jefferya336e432018-08-07 16:00:40 +0930137int protocol_v1_mark_dirty(struct mbox_context *context,
138 struct protocol_mark_dirty *io);
Andrew Jeffery9b920cf2018-08-07 22:49:19 +0930139int protocol_v1_flush(struct mbox_context *context, struct protocol_flush *io);
Andrew Jeffery093eda52018-08-07 23:10:43 +0930140int protocol_v1_close(struct mbox_context *context, struct protocol_close *io);
Andrew Jefferyc5c83042018-08-07 23:22:05 +0930141int protocol_v1_ack(struct mbox_context *context, struct protocol_ack *io);
Andrew Jeffery1e531af2018-08-07 13:32:57 +0930142
143/* Protocol v2 */
144int protocol_v2_get_info(struct mbox_context *context,
145 struct protocol_get_info *io);
Andrew Jeffery91a87452018-08-07 14:54:14 +0930146int protocol_v2_get_flash_info(struct mbox_context *context,
147 struct protocol_get_flash_info *io);
Andrew Jeffery4bcec8e2018-08-07 15:33:41 +0930148int protocol_v2_create_window(struct mbox_context *context,
149 struct protocol_create_window *io);
Andrew Jefferya336e432018-08-07 16:00:40 +0930150int protocol_v2_mark_dirty(struct mbox_context *context,
151 struct protocol_mark_dirty *io);
Andrew Jeffery62a3daa2018-08-07 22:30:32 +0930152int protocol_v2_erase(struct mbox_context *context,
153 struct protocol_erase *io);
Andrew Jeffery9b920cf2018-08-07 22:49:19 +0930154int protocol_v2_flush(struct mbox_context *context, struct protocol_flush *io);
Andrew Jeffery093eda52018-08-07 23:10:43 +0930155int protocol_v2_close(struct mbox_context *context, struct protocol_close *io);
Andrew Jeffery1e531af2018-08-07 13:32:57 +0930156
157#endif /* PROTOCOL_H */