mkbp_event: Always mark MKBP interrupt as inactive before setting it again
mkbp_event: Always mark MKBP interrupt as inactive before setting it again

This patch fixes issue with sensors data not flowing to the AP
after ChromeOS reboot.

Issue occurs when ChromeOS doesn't disable sensor FIFO interrupt.
During ChromeOS reboot, EC sends MKBP event to host, but event can't be
served. Hook task calls force_mkbp_if_events(), scheduled by
activate_mkbp_with_events(). Called function sets state.interrupt to
INTERRUPT_INACTIVE and calls active_mkbp_with_events() to set MKBP
interrupt again (again force_mkbp_if_events() is scheduled). This is
repeated 2 times only (limited by state.failed_attempts).

After 3 attempts to generate MKBP interrupt force_mkbp_if_events()
function is not changing state.interrupt to INTERRUPT_INACTIVE. As a
result calling activate_mkbp_with_events() doesn't set MKBP interrupt
and doesn't schedule force_mkbp_if_events() to be called by hook task.

When ChromeOS is running, EC is not able to send MKBP interrupt again,
because it is blocked by INTERRUPT_ACTIVE state. The only way to change
interrupt state is call EC_CMD_GET_NEXT_EVENT host command which will
eventually call set_inactive_if_no_events(). This host command is called
by host only when it receives MKBP interrupt.

This patch fixes vicious circle by setting state.interrupt to
INTERRUPT_INACTIVE in force_mkbp_if_events() always and calling
activate_mkbp_with_events() only when failed_attempts counter doesn't
exceed limit.

It is safe to mark interrupt state as INACTIVE, because
force_mkbp_with_events() function can be only scheduled by
activate_mkbp_with_event() which will set interrupt state to ACTIVE (if
there are still events waiting). Furthermore, failed_attempts counter is
only reset when AP actually pulls all of the events or number of
attempts is exceeded.

BUG=b:162254118
BRANCH=none
TEST=Flash EC ToT on eve. Boot ChromeOS then reboot it.
     Switch to developer console and check if sensors
     works by calling following command:
     'local_test_runner -waituntilready false hardware.SensorRing'

Signed-off-by: Patryk Duda <6aed17a362577cf10cb5675888c1635d522769c1@semihalf.com>
Change-Id: Ic6acf44770aba8d5d00f070de256751128171205
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/2527171
Reviewed-by: Jett Rink <9d4aef0593e6843318d99df31597fb6153b89787@chromium.org>

coreboot/chrome-ec,coreboot/chrome-ec,coreboot/chrome-ec,coreboot/chrome-ec,coreboot/chrome-ec,coreboot/chrome-ec