diff --git a/control.c b/control.c index ceada6bdccacd1c67896270abc7e4228aec9ef36..648e1c59bd5514ca62f2b6e9fa589d1b9c9ca92c 100644 --- a/control.c +++ b/control.c @@ -36,8 +36,6 @@ int control_lpc_state(struct mbox_context *context) int control_reset(struct mbox_context *context) { - int rc; - /* We don't let the host access flash if the daemon is suspened */ if (context->state & STATE_SUSPENDED) { return -EBUSY; @@ -49,18 +47,7 @@ int control_reset(struct mbox_context *context) * mapping back to flash, or memory in case we're using a virtual pnor. * Better set the bmc event to notify the host of this. */ - if (windows_reset_all(context)) { - rc = protocol_events_set(context, BMC_EVENT_WINDOW_RESET); - if (rc < 0) { - return rc; - } - } - rc = lpc_reset(context); - if (rc < 0) { - return rc; - } - - return 0; + return protocol_reset(context); } int control_kill(struct mbox_context *context) diff --git a/mboxd.c b/mboxd.c index 84bbf69bc5abd49e6e20165309d627a15239c06f..c2f2623a8a99dde377df44306470f89e0f44ff4e 100644 --- a/mboxd.c +++ b/mboxd.c @@ -147,21 +147,9 @@ static int poll_loop(struct mbox_context *context) context->terminate = true; break; case SIGHUP: - /* Host didn't request reset -> Notify it */ - if (windows_reset_all(context)) { - rc = protocol_events_set(context, - BMC_EVENT_WINDOW_RESET); - if (rc < 0) { - MSG_ERR("Failed to notify host of reset, expect host-side corruption\n"); - break; - } - } - rc = lpc_reset(context); + rc = protocol_reset(context); if (rc < 0) { - MSG_ERR("WARNING: Failed to point the " - "LPC bus back to flash on " - "SIGHUP\nIf the host requires " - "this expect problems...\n"); + MSG_ERR("Failed to reset on SIGHUP\n"); } break; default: @@ -191,15 +179,9 @@ static int poll_loop(struct mbox_context *context) } } - /* Best to reset windows and the lpc mapping for safety */ - /* Host didn't request reset -> Notify it */ - windows_reset_all(context); - - rc = lpc_reset(context); - /* Not much we can do if this fails */ + rc = protocol_reset(context); if (rc < 0) { - MSG_ERR("WARNING: Failed to point the LPC bus back to flash\n" - "If the host requires this expect problems...\n"); + MSG_ERR("Failed to reset during poll loop cleanup\n"); } return rc; @@ -407,10 +389,7 @@ int main(int argc, char **argv) #endif /* Set the LPC bus mapping */ - rc = lpc_reset(context); - if (rc) { - MSG_ERR("LPC configuration failed, RESET required: %d\n", rc); - } + __protocol_reset(context); /* We're ready to go, alert the host */ context->bmc_events |= BMC_EVENT_DAEMON_READY; diff --git a/protocol.c b/protocol.c index 8eb06ae0694cc2aefd27e592bbf073ffdbef5038..2a04d897a0f113ed8deee2b44e38a10ae82f1ec4 100644 --- a/protocol.c +++ b/protocol.c @@ -532,3 +532,38 @@ void protocol_free(struct mbox_context *context) { return; } + +/* Don't do any state manipulation, just perform the reset */ +int __protocol_reset(struct mbox_context *context) +{ + windows_reset_all(context); + + return lpc_reset(context); +} + +/* Prevent the host from performing actions whilst reset takes place */ +int protocol_reset(struct mbox_context *context) +{ + int rc; + + rc = protocol_events_clear(context, BMC_EVENT_DAEMON_READY); + if (rc < 0) { + MSG_ERR("Failed to clear daemon ready state, reset failed\n"); + return rc; + } + + rc = __protocol_reset(context); + if (rc < 0) { + MSG_ERR("Failed to reset protocol, daemon remains not ready\n"); + return rc; + } + + rc = protocol_events_set(context, + BMC_EVENT_DAEMON_READY | BMC_EVENT_PROTOCOL_RESET); + if (rc < 0) { + MSG_ERR("Failed to set daemon ready state, daemon remains not ready\n"); + return rc; + } + + return 0; +} diff --git a/protocol.h b/protocol.h index 2c1e725e5216f6d4ee151cb101493f4f9a1b305d..5a678c6e312ecd5ae9051ec55fc33ce97fcb2ab3 100644 --- a/protocol.h +++ b/protocol.h @@ -121,6 +121,12 @@ void protocol_free(struct mbox_context *context); int protocol_negotiate_version(struct mbox_context *context, uint8_t requested); +/* Sneaky reset: Don't tell the host */ +int __protocol_reset(struct mbox_context *context); + +/* Noisy reset: Tell the host */ +int protocol_reset(struct mbox_context *context); + int protocol_events_put(struct mbox_context *context, const struct transport_ops *ops); int protocol_events_set(struct mbox_context *context, uint8_t bmc_event);