Skip to content

Commit

Permalink
HIOMAP: Reset bmc mbox in MPIPL path
Browse files Browse the repository at this point in the history
During boot SBE and early hostboot does not use HIOMAP protocol to get image
from PNOR. Instead it expects PNOR TOC and Hostboot Boot Loader to be
available at particular address in LPC bus. mbox daemon in BMC side takes
care of this during normal boot. Once boot is complete mbox daemon switches
to normal mode.

During normal reboot, BMC side mbox daemon gets notification and takes care of
loading PNOR TOC and HBBL to LPC bus again.

In MPIPL path, OPAL calls SBE S0 interrupt to initiate MPIPL. BMC will not be
aware of this. But SBE expects PNOR TOC and HBBL to be available in LPC bus at
predefined address. Hence call HIOMAP Reset from OPAL in assert path.

This needs working LPC and IPMI driver in OPAL. If we have issue in these
drivers then we may not be able to reset BMC MBOX properly. Hence MPIPL may
fail. We have to live with this until we find a way to intiate BMC on MPIPL.

CC: Andrew Jeffery <andrew@aj.id.au>
Signed-off-by: Vasant Hegde <hegdevasant@linux.vnet.ibm.com>
Reviewed-by: Andrew Jeffery <andrew@aj.id.au>
[oliver: rebased]
Signed-off-by: Oliver O'Halloran <oohall@gmail.com>
  • Loading branch information
Vasant Hegde authored and oohal committed Aug 15, 2019
1 parent fbd875d commit aa694ea
Show file tree
Hide file tree
Showing 10 changed files with 251 additions and 4 deletions.
12 changes: 12 additions & 0 deletions core/flash.c
Expand Up @@ -15,6 +15,7 @@
#include <device.h>
#include <libflash/libflash.h>
#include <libflash/libffs.h>
#include <libflash/ipmi-hiomap.h>
#include <libflash/blocklevel.h>
#include <libflash/ecc.h>
#include <libstb/secureboot.h>
Expand Down Expand Up @@ -79,6 +80,17 @@ void flash_release(void)
unlock(&flash_lock);
}

bool flash_unregister(void)
{
struct blocklevel_device *bl = system_flash->bl;

if (bl->exit)
return bl->exit(bl);

prlog(PR_NOTICE, "FLASH: Unregister flash device is not supported\n");
return true;
}

static int flash_nvram_info(uint32_t *total_size)
{
int rc;
Expand Down
6 changes: 6 additions & 0 deletions hw/sbe-p9.c
Expand Up @@ -952,6 +952,12 @@ void p9_sbe_terminate(void)
if (!dt_find_by_path(opal_node, "dump"))
return;

/* Unregister flash. It will request BMC MBOX reset */
if (!flash_unregister()) {
prlog(PR_DEBUG, "Failed to reset BMC MBOX\n");
return;
}

/* Save crashing CPU details */
opal_mpipl_save_crashing_pir();

Expand Down
1 change: 1 addition & 0 deletions include/skiboot.h
Expand Up @@ -212,6 +212,7 @@ extern int flash_start_preload_resource(enum resource_id id, uint32_t subid,
extern int flash_resource_loaded(enum resource_id id, uint32_t idx);
extern bool flash_reserve(void);
extern void flash_release(void);
extern bool flash_unregister(void);
#define FLASH_SUBPART_ALIGNMENT 0x1000
#define FLASH_SUBPART_HEADER_SIZE FLASH_SUBPART_ALIGNMENT
extern int flash_subpart_info(void *part_header, uint32_t header_len,
Expand Down
1 change: 1 addition & 0 deletions libflash/blocklevel.h
Expand Up @@ -35,6 +35,7 @@ struct blocklevel_device {
int (*erase)(struct blocklevel_device *bl, uint64_t pos, uint64_t len);
int (*get_info)(struct blocklevel_device *bl, const char **name, uint64_t *total_size,
uint32_t *erase_granule);
bool (*exit)(struct blocklevel_device *bl);

/*
* Keep the erase mask so that blocklevel_erase() can do sanity checking
Expand Down
32 changes: 31 additions & 1 deletion libflash/ipmi-hiomap.c
Expand Up @@ -210,6 +210,7 @@ static void ipmi_hiomap_cmd_cb(struct ipmi_msg *msg)
case HIOMAP_C_FLUSH:
case HIOMAP_C_ACK:
case HIOMAP_C_ERASE:
case HIOMAP_C_RESET:
if (msg->resp_size != 2) {
prerror("%u: Unexpected response size: %u\n", msg->data[0],
msg->resp_size);
Expand Down Expand Up @@ -516,6 +517,29 @@ static int hiomap_erase(struct ipmi_hiomap *ctx, uint64_t offset,
return 0;
}

static bool hiomap_reset(struct ipmi_hiomap *ctx)
{
RESULT_INIT(res, ctx);
unsigned char req[2];
struct ipmi_msg *msg;

prlog(PR_NOTICE, "Reset\n");

req[0] = HIOMAP_C_RESET;
req[1] = ++ctx->seq;
msg = ipmi_mkmsg(IPMI_DEFAULT_INTERFACE,
bmc_platform->sw->ipmi_oem_hiomap_cmd,
ipmi_hiomap_cmd_cb, &res, req, sizeof(req), 2);
ipmi_queue_msg_sync(msg);

if (res.cc != IPMI_CC_NO_ERROR) {
prlog(PR_ERR, "%s failed: %d\n", __func__, res.cc);
return false;
}

return true;
}

static void hiomap_event(uint8_t events, void *context)
{
struct ipmi_hiomap *ctx = context;
Expand Down Expand Up @@ -906,6 +930,7 @@ int ipmi_hiomap_init(struct blocklevel_device **bl)
ctx->bl.write = &ipmi_hiomap_write;
ctx->bl.erase = &ipmi_hiomap_erase;
ctx->bl.get_info = &ipmi_hiomap_get_flash_info;
ctx->bl.exit = &ipmi_hiomap_exit;

hiomap_init(ctx);

Expand Down Expand Up @@ -955,11 +980,16 @@ int ipmi_hiomap_init(struct blocklevel_device **bl)
return rc;
}

void ipmi_hiomap_exit(struct blocklevel_device *bl)
bool ipmi_hiomap_exit(struct blocklevel_device *bl)
{
bool status = true;

struct ipmi_hiomap *ctx;
if (bl) {
ctx = container_of(bl, struct ipmi_hiomap, bl);
status = hiomap_reset(ctx);
free(ctx);
}

return status;
}
2 changes: 1 addition & 1 deletion libflash/ipmi-hiomap.h
Expand Up @@ -40,6 +40,6 @@ struct ipmi_hiomap {
};

int ipmi_hiomap_init(struct blocklevel_device **bl);
void ipmi_hiomap_exit(struct blocklevel_device *bl);
bool ipmi_hiomap_exit(struct blocklevel_device *bl);

#endif /* __LIBFLASH_IPMI_HIOMAP_H */
29 changes: 28 additions & 1 deletion libflash/mbox-flash.c
Expand Up @@ -803,6 +803,28 @@ static int mbox_flash_read(struct blocklevel_device *bl, uint64_t pos,
return rc;
}

static bool mbox_flash_reset(struct blocklevel_device *bl)
{
int rc;
struct mbox_flash_data *mbox_flash;
struct bmc_mbox_msg msg = MSG_CREATE(MBOX_C_RESET_STATE);

prlog(PR_NOTICE, "MBOX reset\n");
mbox_flash = container_of(bl, struct mbox_flash_data, bl);

rc = msg_send(mbox_flash, &msg, mbox_flash->timeout);
if (rc) {
prlog(PR_ERR, "Failed to enqueue/send BMC MBOX RESET msg\n");
return false;
}
if (wait_for_bmc(mbox_flash, mbox_flash->timeout)) {
prlog(PR_ERR, "Error waiting for BMC\n");
return false;
}

return true;
}

static int mbox_flash_get_info(struct blocklevel_device *bl, const char **name,
uint64_t *total_size, uint32_t *erase_granule)
{
Expand Down Expand Up @@ -1138,6 +1160,7 @@ int mbox_flash_init(struct blocklevel_device **bl)
mbox_flash->bl.write = &mbox_flash_write;
mbox_flash->bl.erase = &mbox_flash_erase_v2;
mbox_flash->bl.get_info = &mbox_flash_get_info;
mbox_flash->bl.exit = &mbox_flash_exit;

if (bmc_mbox_get_attn_reg() & MBOX_ATTN_BMC_REBOOT)
rc = handle_reboot(mbox_flash);
Expand All @@ -1154,11 +1177,15 @@ int mbox_flash_init(struct blocklevel_device **bl)
return 0;
}

void mbox_flash_exit(struct blocklevel_device *bl)
bool mbox_flash_exit(struct blocklevel_device *bl)
{
bool status = true;
struct mbox_flash_data *mbox_flash;
if (bl) {
status = mbox_flash_reset(bl);
mbox_flash = container_of(bl, struct mbox_flash_data, bl);
free(mbox_flash);
}

return status;
}
2 changes: 1 addition & 1 deletion libflash/mbox-flash.h
Expand Up @@ -6,7 +6,7 @@

int mbox_flash_lock(struct blocklevel_device *bl, uint64_t pos, uint64_t len);
int mbox_flash_init(struct blocklevel_device **bl);
void mbox_flash_exit(struct blocklevel_device *bl);
bool mbox_flash_exit(struct blocklevel_device *bl);
#endif /* __LIBFLASH_MBOX_FLASH_H */


1 change: 1 addition & 0 deletions libflash/test/mbox-server.c
Expand Up @@ -273,6 +273,7 @@ int bmc_mbox_enqueue(struct bmc_mbox_msg *msg,
switch (msg->command) {
case MBOX_C_RESET_STATE:
prlog(PR_INFO, "RESET_STATE\n");
server_state.win_type = WIN_CLOSED;
rc = open_window(msg, false, 0, LPC_BLOCKS);
memset(msg->args, 0, sizeof(msg->args));
break;
Expand Down

0 comments on commit aa694ea

Please sign in to comment.