Skip to content

Commit

Permalink
libflash/mbox-flash: Update to V2 of the protocol
Browse files Browse the repository at this point in the history
Updated version 2 of the protocol can be found at:
https://github.com/openbmc/mboxbridge/blob/master/Documentation/mbox_protocol.md

This commit changes mbox-flash such that it will preferentially talk
version 2 to any capable daemon but still remain capable of talking to
v1 daemons.

Version two changes some of the command definitions for increased
consistency and usability.
Version two includes more attention bits - these are now dealt with at a
simple level.

Signed-off-by: Cyril Bur <cyril.bur@au1.ibm.com>
Signed-off-by: Suraj Jitindar Singh <sjitindarsingh@gmail.com>
Acked-by: Cyril Bur <cyril.bur@au1.ibm.com>
Signed-off-by: Stewart Smith <stewart@linux.vnet.ibm.com>
  • Loading branch information
cyrilbur-ibm authored and stewartsmith committed May 26, 2017
1 parent 0322cd8 commit 3476c6e
Show file tree
Hide file tree
Showing 4 changed files with 600 additions and 143 deletions.
38 changes: 30 additions & 8 deletions hw/lpc-mbox.c
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,6 @@

#define MBOX_MAX_QUEUE_LEN 5

#define BMC_RESET 1
#define BMC_COMPLETE 2

struct mbox {
uint32_t base;
int queue_len;
Expand All @@ -62,6 +59,8 @@ struct mbox {
struct timer poller;
void (*callback)(struct bmc_mbox_msg *msg, void *priv);
void *drv_data;
void (*attn)(uint8_t bits, void *priv);
void *attn_data;
struct lock lock; /* Protect in_flight */
struct bmc_mbox_msg *in_flight;
};
Expand Down Expand Up @@ -182,29 +181,39 @@ static void mbox_poll(struct timer *t __unused, void *data __unused,
* something to tell us.
*/
if (bmc_mbox_inb(MBOX_STATUS_1) & MBOX_STATUS_1_ATTN) {
uint8_t action;
uint8_t action, all;

/* W1C on that reg */
bmc_mbox_outb(MBOX_STATUS_1_ATTN, MBOX_STATUS_1);

action = bmc_mbox_inb(MBOX_FLAG_REG);
all = action = bmc_mbox_inb(MBOX_FLAG_REG);
prlog(PR_TRACE, "Got a status register interrupt with action 0x%02x\n",
action);

if (action & BMC_RESET) {
if (action & MBOX_ATTN_BMC_REBOOT) {
/*
* It's unlikely that something needs to be done at the
* driver level. Let libflash deal with it.
* Print something just in case, it is quite a signficant
* event.
*/
prlog(PR_WARNING, "BMC reset detected\n");
action &= ~BMC_RESET;
action &= ~MBOX_ATTN_BMC_REBOOT;
}

if (action & MBOX_ATTN_BMC_WINDOW_RESET)
action &= ~MBOX_ATTN_BMC_WINDOW_RESET;

if (action & MBOX_ATTN_BMC_FLASH_LOST)
action &= ~MBOX_ATTN_BMC_FLASH_LOST;

if (action & MBOX_ATTN_BMC_DAEMON_READY)
action &= ~MBOX_ATTN_BMC_DAEMON_READY;

if (action)
prlog(PR_ERR, "Got a status bit set that don't know about: 0x%02x\n",
action);

mbox.attn(all, mbox.attn_data);
}

schedule_timer(&mbox.poller,
Expand Down Expand Up @@ -246,6 +255,19 @@ int bmc_mbox_register_callback(void (*callback)(struct bmc_mbox_msg *msg, void *
return 0;
}

int bmc_mbox_register_attn(void (*callback)(uint8_t bits, void *priv),
void *drv_data)
{
mbox.attn = callback;
mbox.attn_data = drv_data;
return 0;
}

uint8_t bmc_mbox_get_attn_reg(void)
{
return bmc_mbox_inb(MBOX_FLAG_REG);
}

void mbox_init(void)
{
const struct dt_property *prop;
Expand Down
11 changes: 11 additions & 0 deletions include/lpc-mbox.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,21 @@
#define MBOX_C_MARK_WRITE_DIRTY 0x07
#define MBOX_C_WRITE_FLUSH 0x08
#define MBOX_C_BMC_EVENT_ACK 0x09
#define MBOX_C_MARK_WRITE_ERASED 0x0a
#define MBOX_COMMAND_COUNT 10

#define MBOX_R_SUCCESS 0x01
#define MBOX_R_PARAM_ERROR 0x02
#define MBOX_R_WRITE_ERROR 0x03
#define MBOX_R_SYSTEM_ERROR 0x04
#define MBOX_R_TIMEOUT 0x05

#define MBOX_ATTN_ACK_MASK 0x3
#define MBOX_ATTN_BMC_REBOOT (1 << 0)
#define MBOX_ATTN_BMC_WINDOW_RESET (1 << 1)
#define MBOX_ATTN_BMC_FLASH_LOST (1 << 6)
#define MBOX_ATTN_BMC_DAEMON_READY (1 << 7)

/* Default poll interval before interrupts are working */
#define MBOX_DEFAULT_POLL_MS 200

Expand All @@ -55,4 +63,7 @@ struct bmc_mbox_msg {
int bmc_mbox_enqueue(struct bmc_mbox_msg *msg);
int bmc_mbox_register_callback(void (*callback)(struct bmc_mbox_msg *msg, void *priv),
void *drv_data);
int bmc_mbox_register_attn(void (*callback)(uint8_t bits, void *priv),
void *drv_data);
uint8_t bmc_mbox_get_attn_reg(void);
#endif /* __LPC_MBOX_H */
2 changes: 2 additions & 0 deletions libflash/errors.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,5 +31,7 @@
#define FLASH_ERR_CTRL_TIMEOUT 13
#define FLASH_ERR_ECC_INVALID 14
#define FLASH_ERR_BAD_READ 15
#define FLASH_ERR_DEVICE_GONE 16
#define FLASH_ERR_AGAIN 17

#endif /* __LIBFLASH_ERRORS_H */

0 comments on commit 3476c6e

Please sign in to comment.