From 9a6e83c5552e49d11f602131859cca4eafff28d0 Mon Sep 17 00:00:00 2001 From: Alistair Popple Date: Tue, 23 Feb 2016 15:34:33 +1100 Subject: hw/bt.c: Fix message timeout Commit fb457c9 (hw/bt: Ask the BMC for its BT interface capabilities) sets the BT message timeout based on the IPMI get capabilities command. This adds a new structure containing a uint8_t to store the message timeout in seconds (msg_timeout). This introduces two problems: 1) The code that checks for timeouts assumes msg_timeout is in units of the timebase (tb_hz). 2) If get_bt_caps() fails msg_timeout is set to BT_MSG_TIMEOUT which is in units of tb_hz and easily overflows a uint8_t. This patch solves the above two problems by changing the definition of BT_MSG_TIMEOUT to seconds and using secs_to_tb() when comparing timebases. It also converts the timebase comparison to use tb_compare(). Signed-off-by: Alistair Popple Cc: Cyril Bur Cc: Stewart Smith Cc: Jeremy Kerr Cc: Mamatha Inamdar Tested-by: Vipin K Parashar Reviewed-by: Vaibhav Jain Signed-off-by: Stewart Smith --- hw/bt.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) (limited to 'hw/bt.c') diff --git a/hw/bt.c b/hw/bt.c index df4a4f0..3325f69 100644 --- a/hw/bt.c +++ b/hw/bt.c @@ -24,6 +24,7 @@ #include #include #include +#include /* BT registers */ #define BT_CTRL 0 @@ -65,9 +66,9 @@ #define BT_MAX_QUEUE_LEN 10 /* - * How long (in TB ticks) before a message is timed out. + * How long (in seconds) before a message is timed out. */ -#define BT_MSG_TIMEOUT (secs_to_tb(3)) +#define BT_MSG_TIMEOUT 3 /* * Maximum number of times to attempt sending a message before giving up. @@ -390,7 +391,8 @@ static void bt_expire_old_msg(uint64_t tb) bt_msg = list_top(&bt.msgq, struct bt_msg, link); - if (bt_msg && bt_msg->tb > 0 && (bt_msg->tb + bt.caps.msg_timeout) < tb) { + if (bt_msg && bt_msg->tb > 0 && + (tb_compare(tb, bt_msg->tb + secs_to_tb(bt.caps.msg_timeout)) == TB_AAFTERB)) { if (bt_msg->send_count < BT_MAX_SEND_COUNT) { /* A message timeout is usually due to the BMC clearing the H2B_ATN flag without actually -- cgit v1.1