protocol.c (c48d07020273abbbb76817f3be899807aba020c3) protocol.c (5335f0930db13a19e1c52b4f746e43db8f79fd76)
1// SPDX-License-Identifier: Apache-2.0
2// Copyright (C) 2018 IBM Corp.
3#include "config.h"
4
5#include <errno.h>
6#include <stdint.h>
7
1// SPDX-License-Identifier: Apache-2.0
2// Copyright (C) 2018 IBM Corp.
3#include "config.h"
4
5#include <errno.h>
6#include <stdint.h>
7
8#include "common.h"
8#include "flash.h"
9#include "mbox.h"
10#include "lpc.h"
9#include "flash.h"
10#include "mbox.h"
11#include "lpc.h"
11#include "transport_mbox.h" /* TODO: Remove dependency on transport_mbox.h */
12#include "windows.h"
13
12#include "windows.h"
13
14/*
15 * protocol_events_set() - Set BMC events
16 * @context: The mbox context pointer
17 * @bmc_event: The bits to set
18 * @write_back: Whether to write back to the register -> will interrupt host
19 *
20 * Return: 0 on success otherwise negative error code
21 */
22int protocol_events_set(struct mbox_context *context, uint8_t bmc_event,
23 bool write_back)
24{
25 uint8_t mask = 0x00;
26
27 switch (context->version) {
28 case API_VERSION_1:
29 mask = BMC_EVENT_V1_MASK;
30 break;
31 default:
32 mask = BMC_EVENT_V2_MASK;
33 break;
34 }
35
36 context->bmc_events |= (bmc_event & mask);
37 MSG_DBG("BMC Events set to: 0x%.2x\n", context->bmc_events);
38
39 return write_back ? context->transport->flush_events(context) : 0;
40}
41
42/*
43 * protocol_events_clear() - Clear BMC events
44 * @context: The mbox context pointer
45 * @bmc_event: The bits to clear
46 * @write_back: Whether to write back to the register -> will interrupt host
47 *
48 * Return: 0 on success otherwise negative error code
49 */
50int protocol_events_clear(struct mbox_context *context, uint8_t bmc_event,
51 bool write_back)
52{
53 context->bmc_events &= ~bmc_event;
54 MSG_DBG("BMC Events clear to: 0x%.2x\n", context->bmc_events);
55
56 return write_back ? context->transport->flush_events(context) : 0;
57}
58
14int protocol_v1_reset(struct mbox_context *context)
15{
16 /* Host requested it -> No BMC Event */
59int protocol_v1_reset(struct mbox_context *context)
60{
61 /* Host requested it -> No BMC Event */
17 windows_reset_all(context, NO_BMC_EVENT);
62 windows_reset_all(context, EVENT_SUPPRESS);
18 return lpc_reset(context);
19}
20
21int protocol_v1_get_info(struct mbox_context *context,
22 struct protocol_get_info *io)
23{
24 uint8_t old_version = context->version;
25 int rc;
26
27 /* Bootstrap protocol version. This may involve {up,down}grading */
28 rc = protocol_negotiate_version(context, io->req.api_version);
29 if (rc < 0)
30 return rc;
31
32 /* Do the {up,down}grade if necessary*/
33 if (rc != old_version) {
63 return lpc_reset(context);
64}
65
66int protocol_v1_get_info(struct mbox_context *context,
67 struct protocol_get_info *io)
68{
69 uint8_t old_version = context->version;
70 int rc;
71
72 /* Bootstrap protocol version. This may involve {up,down}grading */
73 rc = protocol_negotiate_version(context, io->req.api_version);
74 if (rc < 0)
75 return rc;
76
77 /* Do the {up,down}grade if necessary*/
78 if (rc != old_version) {
34 windows_reset_all(context, SET_BMC_EVENT);
79 windows_reset_all(context, EVENT_TRIGGER);
35 return context->protocol->get_info(context, io);
36 }
37
38 /* Record the negotiated version for the response */
39 io->resp.api_version = rc;
40
41 /* Now do all required intialisation for v1 */
42 context->block_size_shift = BLOCK_SIZE_SHIFT_V1;

--- 56 unchanged lines hidden (view full) ---

99 */
100 if (context->current_is_write) {
101 rc = context->protocol->flush(context, NULL);
102 if (rc < 0) {
103 MSG_ERR("Couldn't Flush Write Window\n");
104 return rc;
105 }
106 }
80 return context->protocol->get_info(context, io);
81 }
82
83 /* Record the negotiated version for the response */
84 io->resp.api_version = rc;
85
86 /* Now do all required intialisation for v1 */
87 context->block_size_shift = BLOCK_SIZE_SHIFT_V1;

--- 56 unchanged lines hidden (view full) ---

144 */
145 if (context->current_is_write) {
146 rc = context->protocol->flush(context, NULL);
147 if (rc < 0) {
148 MSG_ERR("Couldn't Flush Write Window\n");
149 return rc;
150 }
151 }
107 windows_close_current(context, NO_BMC_EVENT, FLAGS_NONE);
152 windows_close_current(context, EVENT_SUPPRESS, FLAGS_NONE);
108 }
109
110 /* Offset the host has requested */
111 MSG_INFO("Host requested flash @ 0x%.8x\n", offset);
112 /* Check if we have an existing window */
113 context->current = windows_search(context, offset,
114 context->version == API_VERSION_1);
115

--- 163 unchanged lines hidden (view full) ---

279 rc = protocol_v1_flush(context, NULL);
280 if (rc < 0) {
281 MSG_ERR("Couldn't Flush Write Window\n");
282 return rc;
283 }
284 }
285
286 /* Host asked for it -> Don't set the BMC Event */
153 }
154
155 /* Offset the host has requested */
156 MSG_INFO("Host requested flash @ 0x%.8x\n", offset);
157 /* Check if we have an existing window */
158 context->current = windows_search(context, offset,
159 context->version == API_VERSION_1);
160

--- 163 unchanged lines hidden (view full) ---

324 rc = protocol_v1_flush(context, NULL);
325 if (rc < 0) {
326 MSG_ERR("Couldn't Flush Write Window\n");
327 return rc;
328 }
329 }
330
331 /* Host asked for it -> Don't set the BMC Event */
287 windows_close_current(context, NO_BMC_EVENT, io->req.flags);
332 windows_close_current(context, EVENT_SUPPRESS, io->req.flags);
288
289 return 0;
290}
291
292int protocol_v1_ack(struct mbox_context *context, struct protocol_ack *io)
293{
333
334 return 0;
335}
336
337int protocol_v1_ack(struct mbox_context *context, struct protocol_ack *io)
338{
294 return clr_bmc_events(context, (io->req.flags & BMC_EVENT_ACK_MASK),
295 SET_BMC_EVENT);
339 return protocol_events_clear(context, (io->req.flags & BMC_EVENT_ACK_MASK),
340 EVENT_TRIGGER);
296}
297
298/*
299 * get_suggested_timeout() - get the suggested timeout value in seconds
300 * @context: The mbox context pointer
301 *
302 * Return: Suggested timeout in seconds
303 */

--- 18 unchanged lines hidden (view full) ---

322
323 /* Bootstrap protocol version. This may involve {up,down}grading */
324 rc = protocol_negotiate_version(context, io->req.api_version);
325 if (rc < 0)
326 return rc;
327
328 /* Do the {up,down}grade if necessary*/
329 if (rc != old_version) {
341}
342
343/*
344 * get_suggested_timeout() - get the suggested timeout value in seconds
345 * @context: The mbox context pointer
346 *
347 * Return: Suggested timeout in seconds
348 */

--- 18 unchanged lines hidden (view full) ---

367
368 /* Bootstrap protocol version. This may involve {up,down}grading */
369 rc = protocol_negotiate_version(context, io->req.api_version);
370 if (rc < 0)
371 return rc;
372
373 /* Do the {up,down}grade if necessary*/
374 if (rc != old_version) {
330 windows_reset_all(context, SET_BMC_EVENT);
375 windows_reset_all(context, EVENT_TRIGGER);
331 return context->protocol->get_info(context, io);
332 }
333
334 /* Record the negotiated version for the response */
335 io->resp.api_version = rc;
336
337 /* Now do all required intialisation for v2 */
338 context->block_size_shift = log_2(context->mtd_info.erasesize);

--- 105 unchanged lines hidden (view full) ---

444 rc = protocol_v2_flush(context, NULL);
445 if (rc < 0) {
446 MSG_ERR("Couldn't Flush Write Window\n");
447 return rc;
448 }
449 }
450
451 /* Host asked for it -> Don't set the BMC Event */
376 return context->protocol->get_info(context, io);
377 }
378
379 /* Record the negotiated version for the response */
380 io->resp.api_version = rc;
381
382 /* Now do all required intialisation for v2 */
383 context->block_size_shift = log_2(context->mtd_info.erasesize);

--- 105 unchanged lines hidden (view full) ---

489 rc = protocol_v2_flush(context, NULL);
490 if (rc < 0) {
491 MSG_ERR("Couldn't Flush Write Window\n");
492 return rc;
493 }
494 }
495
496 /* Host asked for it -> Don't set the BMC Event */
452 windows_close_current(context, NO_BMC_EVENT, io->req.flags);
497 windows_close_current(context, EVENT_SUPPRESS, io->req.flags);
453
454 return 0;
455}
456
457int protocol_init(struct mbox_context *context)
458{
459 protocol_negotiate_version(context, API_MAX_VERSION);
460
461 return 0;
462}
463
464void protocol_free(struct mbox_context *context)
465{
466 return;
467}
498
499 return 0;
500}
501
502int protocol_init(struct mbox_context *context)
503{
504 protocol_negotiate_version(context, API_MAX_VERSION);
505
506 return 0;
507}
508
509void protocol_free(struct mbox_context *context)
510{
511 return;
512}