Skip to contentSkip to conversation

ipmi: bmc-sim improvements

PATCH Superseded Nicholas Piggin 2 participants 11 messages Mar 31, 2025 – Apr 1, 2025

v1 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

cover ipmi: bmc-sim improvements

These little things came up when looking at behaviour of IPMI with the bmc-sim implementation running the ppc powernv machine, and trying to clean up error messages and missing features.

Thanks,
Nick

Nicholas Piggin (3):
ipmi/bmc-sim: implement watchdog dont log flag ipmi/bmc-sim: add error handling for 'Set BMC Global Enables' command ipmi/bmc-sim: Add 'Get Channel Info' command

 include/hw/ipmi/ipmi.h | 14 ++++++++
 hw/ipmi/ipmi_bmc_sim.c | 73 +++++++++++++++++++++++++++++++++++++++---
 hw/ipmi/ipmi_bt.c      |  2 ++
 hw/ipmi/ipmi_kcs.c     |  1 +
 4 files changed, 86 insertions(+), 4 deletions(-)
Signature · 1 line
2.47.1
#1 lore raw

PATCH 1/3 ipmi/bmc-sim: implement watchdog dont log flag

If the dont-log flag is set in the 'timer use' field for the 'set watchdog' command, a watchdog timeout will not get logged as a timer use expiration.

---
 hw/ipmi/ipmi_bmc_sim.c | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)
hw/ipmi/ipmi_bmc_sim.c +6 -1
index 6157ac71201..32161044c0b 100644
@@ -733,7 +733,12 @@ static void ipmi_sim_handle_timeout(IPMIBmcSim *ibs)
 
  do_full_expiry:
     ibs->watchdog_running = 0; /* Stop the watchdog on a timeout */
-    ibs->watchdog_expired |= (1 << IPMI_BMC_WATCHDOG_GET_USE(ibs));
+
+    /* Log the expiry if the don't log bit is clear */
+    if (!IPMI_BMC_WATCHDOG_GET_DONT_LOG(ibs)) {
+        ibs->watchdog_expired |= (1 << IPMI_BMC_WATCHDOG_GET_USE(ibs));
+    }
+
     switch (IPMI_BMC_WATCHDOG_GET_ACTION(ibs)) {
     case IPMI_BMC_WATCHDOG_ACTION_NONE:
         sensor_set_discrete_bit(ibs, IPMI_WATCHDOG_SENSOR, 0, 1,
Signature · 1 line
2.47.1
#6 lore raw

PATCH 2/3 ipmi/bmc-sim: add error handling for 'Set BMC Global Enables' command

In reply to Nicholas Piggin

Mask out unsupported bits and return failure if attempting to set any. This is not required by the IPMI spec, but it does require that system software not change bits it isn't aware of.

---
 hw/ipmi/ipmi_bmc_sim.c | 10 +++++++++-
 1 file changed, 9 insertions(+), 1 deletion(-)
hw/ipmi/ipmi_bmc_sim.c +9 -1
index 32161044c0b..8c3313aa65f 100644
@@ -234,6 +234,7 @@ struct IPMIBmcSim {
 #define IPMI_BMC_MSG_FLAG_RCV_MSG_QUEUE_SET(s) \
     (IPMI_BMC_MSG_FLAG_RCV_MSG_QUEUE & (s)->msg_flags)
 
+#define IPMI_BMC_GLOBAL_ENABLES_SUPPORTED 0x0f
 #define IPMI_BMC_RCV_MSG_QUEUE_INT_BIT    0
 #define IPMI_BMC_EVBUF_FULL_INT_BIT       1
 #define IPMI_BMC_EVENT_MSG_BUF_BIT        2
@@ -930,7 +931,14 @@ static void set_bmc_global_enables(IPMIBmcSim *ibs,
                                    uint8_t *cmd, unsigned int cmd_len,
                                    RspBuffer *rsp)
 {
-    set_global_enables(ibs, cmd[2]);
+    uint8_t val = cmd[2];
+
+    if (val & ~IPMI_BMC_GLOBAL_ENABLES_SUPPORTED) {
+        rsp_buffer_set_error(rsp, IPMI_CC_INVALID_DATA_FIELD);
+        return;
+    }
+
+    set_global_enables(ibs, val);
 }
 
 static void get_bmc_global_enables(IPMIBmcSim *ibs,
Signature · 1 line
2.47.1
#7 lore raw

PATCH 3/3 ipmi/bmc-sim: Add 'Get Channel Info' command

In reply to Nicholas Piggin

Linux issues this command when booting a powernv machine.

---
 include/hw/ipmi/ipmi.h | 14 +++++++++++
 hw/ipmi/ipmi_bmc_sim.c | 56 ++++++++++++++++++++++++++++++++++++++++--
 hw/ipmi/ipmi_bt.c      |  2 ++
 hw/ipmi/ipmi_kcs.c     |  1 +
 4 files changed, 71 insertions(+), 2 deletions(-)
include/hw/ipmi/ipmi.h +14 -0
index 77a7213ed93..5f01a50cd86 100644
@@ -41,6 +41,15 @@ enum ipmi_op {
     IPMI_SEND_NMI
 };
 
+/* Channel properties */
+#define IPMI_CHANNEL_IPMB                0x00
+#define IPMI_CHANNEL_SYSTEM              0x0f
+#define IPMI_CH_MEDIUM_IPMB              0x01
+#define IPMI_CH_MEDIUM_SYSTEM            0x0c
+#define IPMI_CH_PROTOCOL_IPMB            0x01
+#define IPMI_CH_PROTOCOL_KCS             0x05
+#define IPMI_CH_PROTOCOL_BT_15           0x08
+
 #define IPMI_CC_INVALID_CMD                              0xc1
 #define IPMI_CC_COMMAND_INVALID_FOR_LUN                  0xc2
 #define IPMI_CC_TIMEOUT                                  0xc3
@@ -170,6 +179,11 @@ struct IPMIInterfaceClass {
      * Return the firmware info for a device.
      */
     void (*get_fwinfo)(struct IPMIInterface *s, IPMIFwInfo *info);
+
+    /*
+     * IPMI channel protocol type number.
+     */
+    uint8_t protocol;
 };
 
 /*
hw/ipmi/ipmi_bmc_sim.c +54 -2

80 lines not on this page · raw message

hw/ipmi/ipmi_bt.c +2 -0
index 583fc64730c..d639c151c4d 100644
@@ -434,4 +434,6 @@ void ipmi_bt_class_init(IPMIInterfaceClass *iic)
     iic->handle_if_event = ipmi_bt_handle_event;
     iic->set_irq_enable = ipmi_bt_set_irq_enable;
     iic->reset = ipmi_bt_handle_reset;
+    /* BT System Interface Format, IPMI v1.5 */
+    iic->protocol = IPMI_CH_PROTOCOL_BT_15;
 }
hw/ipmi/ipmi_kcs.c +1 -0
index c15977cab4c..8af7698286d 100644
@@ -420,4 +420,5 @@ void ipmi_kcs_class_init(IPMIInterfaceClass *iic)
     iic->handle_rsp = ipmi_kcs_handle_rsp;
     iic->handle_if_event = ipmi_kcs_handle_event;
     iic->set_irq_enable = ipmi_kcs_set_irq_enable;
+    iic->protocol = IPMI_CH_PROTOCOL_KCS;
 }
Signature · 1 line
2.47.1
#2 lore raw

Re: [PATCH 1/3] ipmi/bmc-sim: implement watchdog dont log flag

In reply to Nicholas Piggin
Quoted 14 lines · Nicholas Piggin

If the dont-log flag is set in the 'timer use' field for the 'set watchdog' command, a watchdog timeout will not get logged as a timer use expiration.

---
 hw/ipmi/ipmi_bmc_sim.c | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)
hw/ipmi/ipmi_bmc_sim.c +0 -0
index 6157ac71201..32161044c0b 100644

hw/ipmi/ipmi_bmc_sim.c static void ipmi_sim_handle_timeout(IPMIBmcSim *ibs) · line 741

Quoted 10 lines
hw/ipmi/ipmi_bmc_sim.c +6 -1
@@ -733,7 +733,12 @@ static void ipmi_sim_handle_timeout(IPMIBmcSim *ibs)
 
  do_full_expiry:
     ibs->watchdog_running = 0; /* Stop the watchdog on a timeout */
-    ibs->watchdog_expired |= (1 << IPMI_BMC_WATCHDOG_GET_USE(ibs));
+
+    /* Log the expiry if the don't log bit is clear */
+    if (!IPMI_BMC_WATCHDOG_GET_DONT_LOG(ibs)) {
+        ibs->watchdog_expired |= (1 << IPMI_BMC_WATCHDOG_GET_USE(ibs));
+    }
+

Are you sure this is correct? The spec doesn't say what this means, but I would assume this means "Don't add a system log" not "Don't set the expiry happened bit".

Quoted 6 lines
hw/ipmi/ipmi_bmc_sim.c +0 -0
     switch (IPMI_BMC_WATCHDOG_GET_ACTION(ibs)) {
     case IPMI_BMC_WATCHDOG_ACTION_NONE:
         sensor_set_discrete_bit(ibs, IPMI_WATCHDOG_SENSOR, 0, 1,
Signature · 1 line
2.47.1
#8 lore raw

Re: [PATCH 3/3] ipmi/bmc-sim: Add 'Get Channel Info' command

In reply to Nicholas Piggin
Quoted 1 line · Nicholas Piggin

Linux issues this command when booting a powernv machine.

This is good, just a couple of nits.

Quoted 15 lines
---
 include/hw/ipmi/ipmi.h | 14 +++++++++++
 hw/ipmi/ipmi_bmc_sim.c | 56 ++++++++++++++++++++++++++++++++++++++++--
 hw/ipmi/ipmi_bt.c      |  2 ++
 hw/ipmi/ipmi_kcs.c     |  1 +
 4 files changed, 71 insertions(+), 2 deletions(-)
include/hw/ipmi/ipmi.h +0 -0
index 77a7213ed93..5f01a50cd86 100644
@@ -41,6 +41,15 @@ enum ipmi_op {
     IPMI_SEND_NMI

include/hw/ipmi/ipmi.h enum ipmi_op { · line 51

Quoted 10 lines
include/hw/ipmi/ipmi.h +8 -0
 };
 
+/* Channel properties */
+#define IPMI_CHANNEL_IPMB                0x00
+#define IPMI_CHANNEL_SYSTEM              0x0f
+#define IPMI_CH_MEDIUM_IPMB              0x01
+#define IPMI_CH_MEDIUM_SYSTEM            0x0c
+#define IPMI_CH_PROTOCOL_IPMB            0x01
+#define IPMI_CH_PROTOCOL_KCS             0x05
+#define IPMI_CH_PROTOCOL_BT_15           0x08

I know it's picky, but could you spell out CHANNEL here?

Quoted 50 lines
include/hw/ipmi/ipmi.h +6 -0
+
 #define IPMI_CC_INVALID_CMD                              0xc1
 #define IPMI_CC_COMMAND_INVALID_FOR_LUN                  0xc2
 #define IPMI_CC_TIMEOUT                                  0xc3
@@ -170,6 +179,11 @@ struct IPMIInterfaceClass {
      * Return the firmware info for a device.
      */
     void (*get_fwinfo)(struct IPMIInterface *s, IPMIFwInfo *info);
+
+    /*
+     * IPMI channel protocol type number.
+     */
+    uint8_t protocol;
 };
 
 /*
hw/ipmi/ipmi_bmc_sim.c +10 -2
index 8c3313aa65f..9198f854bd9 100644
@@ -70,6 +70,7 @@
 #define IPMI_CMD_GET_MSG                  0x33
 #define IPMI_CMD_SEND_MSG                 0x34
 #define IPMI_CMD_READ_EVT_MSG_BUF         0x35
+#define IPMI_CMD_GET_CHANNEL_INFO         0x42
 
 #define IPMI_NETFN_STORAGE            0x0a
 
@@ -1033,8 +1034,8 @@ static void send_msg(IPMIBmcSim *ibs,
     uint8_t *buf;
     uint8_t netfn, rqLun, rsLun, rqSeq;
 
-    if (cmd[2] != 0) {
-        /* We only handle channel 0 with no options */
+    if (cmd[2] != IPMI_CHANNEL_IPMB) {
+        /* We only handle channel 0h (IPMB) with no options */
         rsp_buffer_set_error(rsp, IPMI_CC_INVALID_DATA_FIELD);
         return;
     }
@@ -1232,6 +1233,56 @@ static void get_watchdog_timer(IPMIBmcSim *ibs,
     }
 }
 
+static void get_channel_info(IPMIBmcSim *ibs,
+                             uint8_t *cmd, unsigned int cmd_len,
+                             RspBuffer *rsp)
+{
+    IPMIInterface *s = ibs->parent.intf;
+    IPMIInterfaceClass *k = IPMI_INTERFACE_GET_CLASS(s);
+    uint8_t ch = cmd[1] & 0x0f;

hw/ipmi/ipmi_bmc_sim.c static void get_watchdog_timer(IPMIBmcSim *ibs, · line 1252

Quoted 10 lines
hw/ipmi/ipmi_bmc_sim.c +10 -0
+
+    /* Only define channel 0h (IPMB) and Fh (system interface) */
+
+    if (ch == 0x0e) { /* "This channel" */
+        ch = IPMI_CHANNEL_SYSTEM;
+    }
+    rsp_buffer_push(rsp, ch);
+
+    if (ch != IPMI_CHANNEL_IPMB && ch != IPMI_CHANNEL_SYSTEM) {
+        /* Not supported */

I think that an all zero response is a valid response. I think you should return a IPMI_CC_INVALID_DATA_FIELD instead, right?

Quoted 11 lines
hw/ipmi/ipmi_bmc_sim.c +11 -0
+        int i;
+        for (i = 0; i < 8; i++) {
+            rsp_buffer_push(rsp, 0x00);
+        }
+        return;
+    }
+
+    if (ch == IPMI_CHANNEL_IPMB) {
+        rsp_buffer_push(rsp, IPMI_CH_MEDIUM_IPMB);
+        rsp_buffer_push(rsp, IPMI_CH_PROTOCOL_IPMB);
+    } else { /* IPMI_CHANNEL_SYSTEM */

hw/ipmi/ipmi_bmc_sim.c static void get_watchdog_timer(IPMIBmcSim *ibs, · line 1273

Quoted 10 lines
hw/ipmi/ipmi_bmc_sim.c +10 -0
+        rsp_buffer_push(rsp, IPMI_CH_MEDIUM_SYSTEM);
+        rsp_buffer_push(rsp, k->protocol);
+    }
+
+    rsp_buffer_push(rsp, 0x00); /* Session-less */
+
+    /* IPMI Vendor ID */
+    rsp_buffer_push(rsp, 0xf2);
+    rsp_buffer_push(rsp, 0x1b);
+    rsp_buffer_push(rsp, 0x00);

Where does this come from?

hw/ipmi/ipmi_bmc_sim.c static void get_watchdog_timer(IPMIBmcSim *ibs, · line 1278

Quoted 5 lines
hw/ipmi/ipmi_bmc_sim.c +5 -0
+
+    if (ch == IPMI_CHANNEL_SYSTEM) {
+        /* IRQ assigned by ACPI/PnP (XXX?) */
+        rsp_buffer_push(rsp, 0x60);
+        rsp_buffer_push(rsp, 0x60);

The interrupt should be available. For the isa versions there is a get_fwinfo function pointer that you can fetch this with. For PCI it's more complicated, unfortunately.

-corey

Quoted 42 lines
hw/ipmi/ipmi_bmc_sim.c +8 -0
+    } else {
+        /* Reserved */
+        rsp_buffer_push(rsp, 0x00);
+        rsp_buffer_push(rsp, 0x00);
+    }
+}
+
 static void get_sdr_rep_info(IPMIBmcSim *ibs,
                              uint8_t *cmd, unsigned int cmd_len,
                              RspBuffer *rsp)
@@ -2028,6 +2079,7 @@ static const IPMICmdHandler app_cmds[] = {
     [IPMI_CMD_RESET_WATCHDOG_TIMER] = { reset_watchdog_timer },
     [IPMI_CMD_SET_WATCHDOG_TIMER] = { set_watchdog_timer, 8 },
     [IPMI_CMD_GET_WATCHDOG_TIMER] = { get_watchdog_timer },
+    [IPMI_CMD_GET_CHANNEL_INFO] = { get_channel_info, 3 },
 };
 static const IPMINetfn app_netfn = {
     .cmd_nums = ARRAY_SIZE(app_cmds),
hw/ipmi/ipmi_bt.c +2 -0
index 583fc64730c..d639c151c4d 100644
@@ -434,4 +434,6 @@ void ipmi_bt_class_init(IPMIInterfaceClass *iic)
     iic->handle_if_event = ipmi_bt_handle_event;
     iic->set_irq_enable = ipmi_bt_set_irq_enable;
     iic->reset = ipmi_bt_handle_reset;
+    /* BT System Interface Format, IPMI v1.5 */
+    iic->protocol = IPMI_CH_PROTOCOL_BT_15;
 }
hw/ipmi/ipmi_kcs.c +1 -0
index c15977cab4c..8af7698286d 100644
@@ -420,4 +420,5 @@ void ipmi_kcs_class_init(IPMIInterfaceClass *iic)
     iic->handle_rsp = ipmi_kcs_handle_rsp;
     iic->handle_if_event = ipmi_kcs_handle_event;
     iic->set_irq_enable = ipmi_kcs_set_irq_enable;
+    iic->protocol = IPMI_CH_PROTOCOL_KCS;
 }
Signature · 1 line
2.47.1
#3 lore raw

Re: [PATCH 1/3] ipmi/bmc-sim: implement watchdog dont log flag

In reply to Corey Minyard
Quoted 16 lines · Corey Minyard
Quoted 15 lines · Nicholas Piggin

If the dont-log flag is set in the 'timer use' field for the 'set watchdog' command, a watchdog timeout will not get logged as a timer use expiration.

---
 hw/ipmi/ipmi_bmc_sim.c | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)
hw/ipmi/ipmi_bmc_sim.c +0 -0
index 6157ac71201..32161044c0b 100644
@@ -733,7 +733,12 @@ static void ipmi_sim_handle_timeout(IPMIBmcSim *ibs)
 
Quoted 13 lines

hw/ipmi/ipmi_bmc_sim.c static void ipmi_sim_handle_timeout(IPMIBmcSim *ibs) · line 741

Quoted 9 lines
hw/ipmi/ipmi_bmc_sim.c +6 -1
  do_full_expiry:
     ibs->watchdog_running = 0; /* Stop the watchdog on a timeout */
-    ibs->watchdog_expired |= (1 << IPMI_BMC_WATCHDOG_GET_USE(ibs));
+
+    /* Log the expiry if the don't log bit is clear */
+    if (!IPMI_BMC_WATCHDOG_GET_DONT_LOG(ibs)) {
+        ibs->watchdog_expired |= (1 << IPMI_BMC_WATCHDOG_GET_USE(ibs));
+    }
+

Are you sure this is correct? The spec doesn't say what this means, but I would assume this means "Don't add a system log" not "Don't set the expiry happened bit".

From IPMI spec, Set Watchdog Timer command timer use field of byte 1 says "timer use (logged on expiration when “don’t log” bit = 0b)". But it also says it should disable the timeout sensor event logging. I missed that part, I will see if I can make that work.

Thanks,
Nick

#4 lore raw

Re: [PATCH 1/3] ipmi/bmc-sim: implement watchdog dont log flag

Quoted 31 lines · Nicholas Piggin
Quoted 16 lines · Corey Minyard
Quoted 15 lines · Nicholas Piggin

If the dont-log flag is set in the 'timer use' field for the 'set watchdog' command, a watchdog timeout will not get logged as a timer use expiration.

---
 hw/ipmi/ipmi_bmc_sim.c | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)
hw/ipmi/ipmi_bmc_sim.c +0 -0
index 6157ac71201..32161044c0b 100644
@@ -733,7 +733,12 @@ static void ipmi_sim_handle_timeout(IPMIBmcSim *ibs)
 
Quoted 13 lines

hw/ipmi/ipmi_bmc_sim.c static void ipmi_sim_handle_timeout(IPMIBmcSim *ibs) · line 741

Quoted 9 lines
hw/ipmi/ipmi_bmc_sim.c +6 -1
  do_full_expiry:
     ibs->watchdog_running = 0; /* Stop the watchdog on a timeout */
-    ibs->watchdog_expired |= (1 << IPMI_BMC_WATCHDOG_GET_USE(ibs));
+
+    /* Log the expiry if the don't log bit is clear */
+    if (!IPMI_BMC_WATCHDOG_GET_DONT_LOG(ibs)) {
+        ibs->watchdog_expired |= (1 << IPMI_BMC_WATCHDOG_GET_USE(ibs));
+    }
+

Are you sure this is correct? The spec doesn't say what this means, but I would assume this means "Don't add a system log" not "Don't set the expiry happened bit".

Quoted 4 lines

From IPMI spec, Set Watchdog Timer command timer use field of byte 1 says "timer use (logged on expiration when “don’t log” bit = 0b)". But it also says it should disable the timeout sensor event logging. I missed that part, I will see if I can make that work.

It doesn't currently add an event to the log, I don't think. If you want to add that, it's fine.

However, as it is, your change will cause the Get Watchdog Timer command to return the wrong value for Timer Use Expiration flags. It's not what you want to do.

What bug are you trying to solve?

-corey

#9 lore raw

Re: [PATCH 3/3] ipmi/bmc-sim: Add 'Get Channel Info' command

In reply to Corey Minyard
Quoted 22 lines · Corey Minyard
Quoted 1 line · Nicholas Piggin

Linux issues this command when booting a powernv machine.

This is good, just a couple of nits.

Quoted 17 lines
---
 include/hw/ipmi/ipmi.h | 14 +++++++++++
 hw/ipmi/ipmi_bmc_sim.c | 56 ++++++++++++++++++++++++++++++++++++++++--
 hw/ipmi/ipmi_bt.c      |  2 ++
 hw/ipmi/ipmi_kcs.c     |  1 +
 4 files changed, 71 insertions(+), 2 deletions(-)
include/hw/ipmi/ipmi.h +0 -0
index 77a7213ed93..5f01a50cd86 100644
@@ -41,6 +41,15 @@ enum ipmi_op {
     IPMI_SEND_NMI
 };
 
Quoted 10 lines

include/hw/ipmi/ipmi.h enum ipmi_op { · line 51

Quoted 8 lines
include/hw/ipmi/ipmi.h +8 -0
+/* Channel properties */
+#define IPMI_CHANNEL_IPMB                0x00
+#define IPMI_CHANNEL_SYSTEM              0x0f
+#define IPMI_CH_MEDIUM_IPMB              0x01
+#define IPMI_CH_MEDIUM_SYSTEM            0x0c
+#define IPMI_CH_PROTOCOL_IPMB            0x01
+#define IPMI_CH_PROTOCOL_KCS             0x05
+#define IPMI_CH_PROTOCOL_BT_15           0x08

I know it's picky, but could you spell out CHANNEL here?

Sure.

Quoted 55 lines
Quoted 55 lines
include/hw/ipmi/ipmi.h +6 -0
+
 #define IPMI_CC_INVALID_CMD                              0xc1
 #define IPMI_CC_COMMAND_INVALID_FOR_LUN                  0xc2
 #define IPMI_CC_TIMEOUT                                  0xc3
@@ -170,6 +179,11 @@ struct IPMIInterfaceClass {
      * Return the firmware info for a device.
      */
     void (*get_fwinfo)(struct IPMIInterface *s, IPMIFwInfo *info);
+
+    /*
+     * IPMI channel protocol type number.
+     */
+    uint8_t protocol;
 };
 
 /*
hw/ipmi/ipmi_bmc_sim.c +15 -2
index 8c3313aa65f..9198f854bd9 100644
@@ -70,6 +70,7 @@
 #define IPMI_CMD_GET_MSG                  0x33
 #define IPMI_CMD_SEND_MSG                 0x34
 #define IPMI_CMD_READ_EVT_MSG_BUF         0x35
+#define IPMI_CMD_GET_CHANNEL_INFO         0x42
 
 #define IPMI_NETFN_STORAGE            0x0a
 
@@ -1033,8 +1034,8 @@ static void send_msg(IPMIBmcSim *ibs,
     uint8_t *buf;
     uint8_t netfn, rqLun, rsLun, rqSeq;
 
-    if (cmd[2] != 0) {
-        /* We only handle channel 0 with no options */
+    if (cmd[2] != IPMI_CHANNEL_IPMB) {
+        /* We only handle channel 0h (IPMB) with no options */
         rsp_buffer_set_error(rsp, IPMI_CC_INVALID_DATA_FIELD);
         return;
     }
@@ -1232,6 +1233,56 @@ static void get_watchdog_timer(IPMIBmcSim *ibs,
     }
 }
 
+static void get_channel_info(IPMIBmcSim *ibs,
+                             uint8_t *cmd, unsigned int cmd_len,
+                             RspBuffer *rsp)
+{
+    IPMIInterface *s = ibs->parent.intf;
+    IPMIInterfaceClass *k = IPMI_INTERFACE_GET_CLASS(s);
+    uint8_t ch = cmd[1] & 0x0f;
+
+    /* Only define channel 0h (IPMB) and Fh (system interface) */
+
+    if (ch == 0x0e) { /* "This channel" */
+        ch = IPMI_CHANNEL_SYSTEM;
Quoted 8 lines

hw/ipmi/ipmi_bmc_sim.c static void get_watchdog_timer(IPMIBmcSim *ibs, · line 1252

Quoted 5 lines
hw/ipmi/ipmi_bmc_sim.c +5 -0
+    }
+    rsp_buffer_push(rsp, ch);
+
+    if (ch != IPMI_CHANNEL_IPMB && ch != IPMI_CHANNEL_SYSTEM) {
+        /* Not supported */

I think that an all zero response is a valid response. I think you should return a IPMI_CC_INVALID_DATA_FIELD instead, right?

I can't remember, I dug the patch out from a while ago. I can't actually see anywhere it is made clear in the spec, do you? I agree an invalid error sounds better. I'll try to see how ipmi tools handles it.

Quoted 15 lines
Quoted 15 lines
hw/ipmi/ipmi_bmc_sim.c +15 -0
+        int i;
+        for (i = 0; i < 8; i++) {
+            rsp_buffer_push(rsp, 0x00);
+        }
+        return;
+    }
+
+    if (ch == IPMI_CHANNEL_IPMB) {
+        rsp_buffer_push(rsp, IPMI_CH_MEDIUM_IPMB);
+        rsp_buffer_push(rsp, IPMI_CH_PROTOCOL_IPMB);
+    } else { /* IPMI_CHANNEL_SYSTEM */
+        rsp_buffer_push(rsp, IPMI_CH_MEDIUM_SYSTEM);
+        rsp_buffer_push(rsp, k->protocol);
+    }
+
Quoted 8 lines

hw/ipmi/ipmi_bmc_sim.c static void get_watchdog_timer(IPMIBmcSim *ibs, · line 1273

Quoted 6 lines
hw/ipmi/ipmi_bmc_sim.c +6 -0
+    rsp_buffer_push(rsp, 0x00); /* Session-less */
+
+    /* IPMI Vendor ID */
+    rsp_buffer_push(rsp, 0xf2);
+    rsp_buffer_push(rsp, 0x1b);
+    rsp_buffer_push(rsp, 0x00);

Where does this come from?

IPMI spec Get Channel Info Command, search "IPMI Enterprise Number" From my reading, all channel info responses contain this.

Quoted 9 lines

hw/ipmi/ipmi_bmc_sim.c static void get_watchdog_timer(IPMIBmcSim *ibs, · line 1278

Quoted 5 lines
hw/ipmi/ipmi_bmc_sim.c +5 -0
+
+    if (ch == IPMI_CHANNEL_SYSTEM) {
+        /* IRQ assigned by ACPI/PnP (XXX?) */
+        rsp_buffer_push(rsp, 0x60);
+        rsp_buffer_push(rsp, 0x60);

The interrupt should be available. For the isa versions there is a get_fwinfo function pointer that you can fetch this with. For PCI it's more complicated, unfortunately.

These are for the two interrupts. QEMU seems to tie both to the same line, I guess that's okay?

That interface looks good, but what I was concerned about is whether that implies the irq is hard coded or whether the platform can assign it, does it mean unassigned? I don't know a lot about irq routing or what IPMI clients would use it for.

Anyhow I'll respin with changes.

Thanks,
Nick

#10 lore raw

Re: [PATCH 3/3] ipmi/bmc-sim: Add 'Get Channel Info' command

Quoted 23 lines · Nicholas Piggin
Quoted 13 lines · Corey Minyard
Quoted 12 lines · Nicholas Piggin
hw/ipmi/ipmi_bmc_sim.c +12 -0
+static void get_channel_info(IPMIBmcSim *ibs,
+                             uint8_t *cmd, unsigned int cmd_len,
+                             RspBuffer *rsp)
+{
+    IPMIInterface *s = ibs->parent.intf;
+    IPMIInterfaceClass *k = IPMI_INTERFACE_GET_CLASS(s);
+    uint8_t ch = cmd[1] & 0x0f;
+
+    /* Only define channel 0h (IPMB) and Fh (system interface) */
+
+    if (ch == 0x0e) { /* "This channel" */
+        ch = IPMI_CHANNEL_SYSTEM;
Quoted 8 lines

hw/ipmi/ipmi_bmc_sim.c static void get_watchdog_timer(IPMIBmcSim *ibs, · line 1252

Quoted 5 lines
hw/ipmi/ipmi_bmc_sim.c +5 -0
+    }
+    rsp_buffer_push(rsp, ch);
+
+    if (ch != IPMI_CHANNEL_IPMB && ch != IPMI_CHANNEL_SYSTEM) {
+        /* Not supported */

I think that an all zero response is a valid response. I think you should return a IPMI_CC_INVALID_DATA_FIELD instead, right?

Quoted 3 lines

I can't remember, I dug the patch out from a while ago. I can't actually see anywhere it is made clear in the spec, do you? I agree an invalid error sounds better. I'll try to see how ipmi tools handles it.

I'm fairly sure an error response is ok. Please pursue that.

Quoted 25 lines
Quoted 16 lines
Quoted 16 lines
hw/ipmi/ipmi_bmc_sim.c +15 -0
+        int i;
+        for (i = 0; i < 8; i++) {
+            rsp_buffer_push(rsp, 0x00);
+        }
+        return;
+    }
+
+    if (ch == IPMI_CHANNEL_IPMB) {
+        rsp_buffer_push(rsp, IPMI_CH_MEDIUM_IPMB);
+        rsp_buffer_push(rsp, IPMI_CH_PROTOCOL_IPMB);
+    } else { /* IPMI_CHANNEL_SYSTEM */
+        rsp_buffer_push(rsp, IPMI_CH_MEDIUM_SYSTEM);
+        rsp_buffer_push(rsp, k->protocol);
+    }
+
Quoted 8 lines

hw/ipmi/ipmi_bmc_sim.c static void get_watchdog_timer(IPMIBmcSim *ibs, · line 1273

Quoted 6 lines
hw/ipmi/ipmi_bmc_sim.c +6 -0
+    rsp_buffer_push(rsp, 0x00); /* Session-less */
+
+    /* IPMI Vendor ID */
+    rsp_buffer_push(rsp, 0xf2);
+    rsp_buffer_push(rsp, 0x1b);
+    rsp_buffer_push(rsp, 0x00);

Where does this come from?

Quoted 2 lines

IPMI spec Get Channel Info Command, search "IPMI Enterprise Number" From my reading, all channel info responses contain this.

Oh, sorry, I should have read on this. This is fine.

Quoted 7 lines
Quoted 7 lines
Quoted 6 lines
hw/ipmi/ipmi_bmc_sim.c +5 -0
+
+    if (ch == IPMI_CHANNEL_SYSTEM) {
+        /* IRQ assigned by ACPI/PnP (XXX?) */
+        rsp_buffer_push(rsp, 0x60);
+        rsp_buffer_push(rsp, 0x60);
Quoted 6 lines
Quoted 3 lines

The interrupt should be available. For the isa versions there is a get_fwinfo function pointer that you can fetch this with. For PCI it's more complicated, unfortunately.

These are for the two interrupts. QEMU seems to tie both to the same line, I guess that's okay?

Yes, they are the same.

Quoted 5 lines

That interface looks good, but what I was concerned about is whether that implies the irq is hard coded or whether the platform can assign it, does it mean unassigned? I don't know a lot about irq routing or what IPMI clients would use it for.

For isa-based devices, it's hard-coded by the configuration. That one should be easy to get.

For PCI, I'm not so sure. It would take some research to figure it out.

Quoted 2 lines

Anyhow I'll respin with changes.

Thanks,

-corey

Quoted 3 lines

Thanks,
Nick

#5 lore raw

Re: [PATCH 1/3] ipmi/bmc-sim: implement watchdog dont log flag

In reply to Corey Minyard
Quoted 32 lines · Corey Minyard
Quoted 31 lines · Nicholas Piggin
Quoted 29 lines · Corey Minyard
Quoted 14 lines · Nicholas Piggin

If the dont-log flag is set in the 'timer use' field for the 'set watchdog' command, a watchdog timeout will not get logged as a timer use expiration.

---
 hw/ipmi/ipmi_bmc_sim.c | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)
hw/ipmi/ipmi_bmc_sim.c +0 -0
index 6157ac71201..32161044c0b 100644

hw/ipmi/ipmi_bmc_sim.c static void ipmi_sim_handle_timeout(IPMIBmcSim *ibs) · line 741

Quoted 10 lines
hw/ipmi/ipmi_bmc_sim.c +6 -1
@@ -733,7 +733,12 @@ static void ipmi_sim_handle_timeout(IPMIBmcSim *ibs)
 
  do_full_expiry:
     ibs->watchdog_running = 0; /* Stop the watchdog on a timeout */
-    ibs->watchdog_expired |= (1 << IPMI_BMC_WATCHDOG_GET_USE(ibs));
+
+    /* Log the expiry if the don't log bit is clear */
+    if (!IPMI_BMC_WATCHDOG_GET_DONT_LOG(ibs)) {
+        ibs->watchdog_expired |= (1 << IPMI_BMC_WATCHDOG_GET_USE(ibs));
+    }
+

Are you sure this is correct? The spec doesn't say what this means, but I would assume this means "Don't add a system log" not "Don't set the expiry happened bit".

Quoted 7 lines
Quoted 4 lines

From IPMI spec, Set Watchdog Timer command timer use field of byte 1 says "timer use (logged on expiration when “don’t log” bit = 0b)". But it also says it should disable the timeout sensor event logging. I missed that part, I will see if I can make that work.

It doesn't currently add an event to the log, I don't think. If you want to add that, it's fine.

Actually, I'm wrong here. It does generate an event through the sensor handling, the sensor_set_discrete_bit() function will cause an event to be generated. However, you can't just not call that function, you need the event set. I think the best way would be to add a "do_log" parameter to that function to suppress the log in this case.

-corey

Quoted 8 lines

However, as it is, your change will cause the Get Watchdog Timer command to return the wrong value for Timer Use Expiration flags. It's not what you want to do.

What bug are you trying to solve?

-corey