Skip to content

Commit

Permalink
libflash/mbox-flash: Use BMC suggested timeout value
Browse files Browse the repository at this point in the history
Signed-off-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 Dec 15, 2017
1 parent 1095ed9 commit de554c1
Showing 1 changed file with 26 additions and 11 deletions.
37 changes: 26 additions & 11 deletions libflash/mbox-flash.c
Expand Up @@ -50,6 +50,7 @@ struct lpc_window {

struct mbox_flash_data {
int version;
uint16_t timeout;
uint32_t shift;
struct lpc_window read;
struct lpc_window write;
Expand Down Expand Up @@ -286,7 +287,12 @@ static int mbox_flash_ack(struct mbox_flash_data *mbox_flash, uint8_t reg)
/* Clear this first so msg_send() doesn't freak out */
mbox_flash->reboot = false;

rc = msg_send(mbox_flash, &msg, MBOX_DEFAULT_TIMEOUT);
/*
* Use a lower timeout - there is strong evidence to suggest the
* BMC won't respond, don't waste time spinning here just have the
* high levels retry when the BMC might be back
*/
rc = msg_send(mbox_flash, &msg, 3);

/* Still need to deal with it, we've only acked it now. */
mbox_flash->reboot = true;
Expand Down Expand Up @@ -340,6 +346,9 @@ static void mbox_flash_do_get_mbox_info(struct mbox_flash_data *mbox_flash,
mbox_flash->write.size = blocks_to_bytes(mbox_flash, msg_get_u16(msg, 3));
} else { /* V2 compatible */
mbox_flash->shift = msg_get_u8(msg, 5);
mbox_flash->timeout = msg_get_u16(msg, 6);
if (mbox_flash->timeout == 0)
mbox_flash->timeout = MBOX_DEFAULT_TIMEOUT;
}
/* Callers will handle the case where the version is not known
*
Expand Down Expand Up @@ -472,13 +481,13 @@ static int mbox_flash_mark_write(struct mbox_flash_data *mbox_flash,
msg_put_u16(&msg, 2, end - start); /* Total Length */
}

rc = msg_send(mbox_flash, &msg, MBOX_DEFAULT_TIMEOUT);
rc = msg_send(mbox_flash, &msg, mbox_flash->timeout);
if (rc) {
prlog(PR_ERR, "Failed to enqueue/send BMC MBOX message\n");
return rc;
}

rc = wait_for_bmc(mbox_flash, MBOX_DEFAULT_TIMEOUT);
rc = wait_for_bmc(mbox_flash, mbox_flash->timeout);
if (rc)
prlog(PR_ERR, "Error waiting for BMC\n");

Expand Down Expand Up @@ -519,13 +528,13 @@ static int mbox_flash_flush(struct mbox_flash_data *mbox_flash)
return FLASH_ERR_DEVICE_GONE;
}

rc = msg_send(mbox_flash, &msg, MBOX_DEFAULT_TIMEOUT);
rc = msg_send(mbox_flash, &msg, mbox_flash->timeout);
if (rc) {
prlog(PR_ERR, "Failed to enqueue/send BMC MBOX message\n");
return rc;
}

rc = wait_for_bmc(mbox_flash, MBOX_DEFAULT_TIMEOUT);
rc = wait_for_bmc(mbox_flash, mbox_flash->timeout);
if (rc)
prlog(PR_ERR, "Error waiting for BMC\n");

Expand Down Expand Up @@ -568,7 +577,7 @@ static int mbox_window_move(struct mbox_flash_data *mbox_flash,
win->cur_pos = pos & ~mbox_flash_mask(mbox_flash);

msg_put_u16(&msg, 0, bytes_to_blocks(mbox_flash, pos));
rc = msg_send(mbox_flash, &msg, MBOX_DEFAULT_TIMEOUT);
rc = msg_send(mbox_flash, &msg, mbox_flash->timeout);
if (rc) {
prlog(PR_ERR, "Failed to enqueue/send BMC MBOX message\n");
return rc;
Expand All @@ -577,7 +586,7 @@ static int mbox_window_move(struct mbox_flash_data *mbox_flash,
mbox_flash->read.open = false;
mbox_flash->write.open = false;

rc = wait_for_bmc(mbox_flash, MBOX_DEFAULT_TIMEOUT);
rc = wait_for_bmc(mbox_flash, mbox_flash->timeout);
if (rc) {
prlog(PR_ERR, "Error waiting for BMC\n");
return rc;
Expand Down Expand Up @@ -725,13 +734,13 @@ static int mbox_flash_get_info(struct blocklevel_device *bl, const char **name,
*name = NULL;

mbox_flash->busy = true;
rc = msg_send(mbox_flash, &msg, MBOX_DEFAULT_TIMEOUT);
rc = msg_send(mbox_flash, &msg, mbox_flash->timeout);
if (rc) {
prlog(PR_ERR, "Failed to enqueue/send BMC MBOX message\n");
return rc;
}

if (wait_for_bmc(mbox_flash, MBOX_DEFAULT_TIMEOUT)) {
if (wait_for_bmc(mbox_flash, mbox_flash->timeout)) {
prlog(PR_ERR, "Error waiting for BMC\n");
return rc;
}
Expand Down Expand Up @@ -904,6 +913,12 @@ static int protocol_init(struct mbox_flash_data *mbox_flash)
*/
mbox_flash->shift = 12;

/*
* For V1 we'll use this value.
* V2: The init code (may) update this
*/
mbox_flash->timeout = MBOX_DEFAULT_TIMEOUT;

/*
* Always attempt init with V2.
* The GET_MBOX_INFO response will confirm that the other side can
Expand All @@ -912,13 +927,13 @@ static int protocol_init(struct mbox_flash_data *mbox_flash)
mbox_flash->version = 2;

msg_put_u8(&msg, 0, mbox_flash->version);
rc = msg_send(mbox_flash, &msg, MBOX_DEFAULT_TIMEOUT);
rc = msg_send(mbox_flash, &msg, mbox_flash->timeout);
if (rc) {
prlog(PR_ERR, "Failed to enqueue/send BMC MBOX message\n");
return rc;
}

rc = wait_for_bmc(mbox_flash, MBOX_DEFAULT_TIMEOUT);
rc = wait_for_bmc(mbox_flash, mbox_flash->timeout);
if (rc) {
prlog(PR_ERR, "Error waiting for BMC\n");
return rc;
Expand Down

0 comments on commit de554c1

Please sign in to comment.