blob: 16b8e64ee6e6f2faf6da8ee23999f6f528003a29 [file] [log] [blame]
Andrew Jefferyc7d19472018-08-08 11:43:08 +09301// SPDX-License-Identifier: Apache-2.0
2// Copyright (C) 2018 IBM Corp.
3#include "config.h"
4
5#include <errno.h>
6
Andrew Jeffery26558db2018-08-10 00:22:38 +09307#include "mboxd.h"
Andrew Jefferyc7d19472018-08-08 11:43:08 +09308#include "protocol.h"
9
10static const struct protocol_ops protocol_ops_v1 = {
11 .reset = protocol_v1_reset,
12 .get_info = protocol_v1_get_info,
13 .get_flash_info = protocol_v1_get_flash_info,
14 .create_window = protocol_v1_create_window,
15 .mark_dirty = protocol_v1_mark_dirty,
16 .erase = NULL,
17 .flush = protocol_v1_flush,
18 .close = protocol_v1_close,
19 .ack = protocol_v1_ack,
20};
21
22static const struct protocol_ops protocol_ops_v2 = {
23 .reset = protocol_v1_reset,
24 .get_info = protocol_v2_get_info,
25 .get_flash_info = protocol_v2_get_flash_info,
26 .create_window = protocol_v2_create_window,
27 .mark_dirty = protocol_v2_mark_dirty,
28 .erase = protocol_v2_erase,
29 .flush = protocol_v2_flush,
30 .close = protocol_v2_close,
31 .ack = protocol_v1_ack,
32};
33
34static const struct protocol_ops *protocol_ops_map[] = {
35 [0] = NULL,
36 [1] = &protocol_ops_v1,
37 [2] = &protocol_ops_v2,
38};
39
40int protocol_negotiate_version(struct mbox_context *context,
41 uint8_t requested)
42{
43 /* Check we support the version requested */
44 if (requested < API_MIN_VERSION)
45 return -EINVAL;
46
47 context->version = (requested > API_MAX_VERSION) ?
48 API_MAX_VERSION : requested;
49
50 context->protocol = protocol_ops_map[context->version];
51
52 return context->version;
53}