xref: /qemu/include/hw/ipmi/ipmi.h (revision a2295f0a5871e2b9d8ea24bc3a1d2e02bda6ef2d)
123076bb3SCorey Minyard /*
223076bb3SCorey Minyard  * IPMI base class
323076bb3SCorey Minyard  *
423076bb3SCorey Minyard  * Copyright (c) 2015 Corey Minyard, MontaVista Software, LLC
523076bb3SCorey Minyard  *
623076bb3SCorey Minyard  * Permission is hereby granted, free of charge, to any person obtaining a copy
723076bb3SCorey Minyard  * of this software and associated documentation files (the "Software"), to deal
823076bb3SCorey Minyard  * in the Software without restriction, including without limitation the rights
923076bb3SCorey Minyard  * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
1023076bb3SCorey Minyard  * copies of the Software, and to permit persons to whom the Software is
1123076bb3SCorey Minyard  * furnished to do so, subject to the following conditions:
1223076bb3SCorey Minyard  *
1323076bb3SCorey Minyard  * The above copyright notice and this permission notice shall be included in
1423076bb3SCorey Minyard  * all copies or substantial portions of the Software.
1523076bb3SCorey Minyard  *
1623076bb3SCorey Minyard  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
1723076bb3SCorey Minyard  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
1823076bb3SCorey Minyard  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
1923076bb3SCorey Minyard  * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
2023076bb3SCorey Minyard  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
2123076bb3SCorey Minyard  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
2223076bb3SCorey Minyard  * THE SOFTWARE.
2323076bb3SCorey Minyard  */
2423076bb3SCorey Minyard 
2523076bb3SCorey Minyard #ifndef HW_IPMI_H
2623076bb3SCorey Minyard #define HW_IPMI_H
2723076bb3SCorey Minyard 
2823076bb3SCorey Minyard #include "exec/memory.h"
2923076bb3SCorey Minyard #include "qemu-common.h"
3023076bb3SCorey Minyard #include "hw/qdev.h"
3123076bb3SCorey Minyard 
3223076bb3SCorey Minyard #define MAX_IPMI_MSG_SIZE 300
3323076bb3SCorey Minyard 
3423076bb3SCorey Minyard enum ipmi_op {
3523076bb3SCorey Minyard     IPMI_RESET_CHASSIS,
3623076bb3SCorey Minyard     IPMI_POWEROFF_CHASSIS,
3723076bb3SCorey Minyard     IPMI_POWERON_CHASSIS,
3823076bb3SCorey Minyard     IPMI_POWERCYCLE_CHASSIS,
3923076bb3SCorey Minyard     IPMI_PULSE_DIAG_IRQ,
4023076bb3SCorey Minyard     IPMI_SHUTDOWN_VIA_ACPI_OVERTEMP,
4123076bb3SCorey Minyard     IPMI_SEND_NMI
4223076bb3SCorey Minyard };
4323076bb3SCorey Minyard 
4423076bb3SCorey Minyard #define IPMI_CC_INVALID_CMD                              0xc1
4523076bb3SCorey Minyard #define IPMI_CC_COMMAND_INVALID_FOR_LUN                  0xc2
4623076bb3SCorey Minyard #define IPMI_CC_TIMEOUT                                  0xc3
4723076bb3SCorey Minyard #define IPMI_CC_OUT_OF_SPACE                             0xc4
4823076bb3SCorey Minyard #define IPMI_CC_INVALID_RESERVATION                      0xc5
4923076bb3SCorey Minyard #define IPMI_CC_REQUEST_DATA_TRUNCATED                   0xc6
5023076bb3SCorey Minyard #define IPMI_CC_REQUEST_DATA_LENGTH_INVALID              0xc7
5123076bb3SCorey Minyard #define IPMI_CC_PARM_OUT_OF_RANGE                        0xc9
5223076bb3SCorey Minyard #define IPMI_CC_CANNOT_RETURN_REQ_NUM_BYTES              0xca
5323076bb3SCorey Minyard #define IPMI_CC_REQ_ENTRY_NOT_PRESENT                    0xcb
5423076bb3SCorey Minyard #define IPMI_CC_INVALID_DATA_FIELD                       0xcc
5523076bb3SCorey Minyard #define IPMI_CC_BMC_INIT_IN_PROGRESS                     0xd2
5623076bb3SCorey Minyard #define IPMI_CC_COMMAND_NOT_SUPPORTED                    0xd5
5723076bb3SCorey Minyard 
5823076bb3SCorey Minyard #define IPMI_NETFN_APP                0x06
5923076bb3SCorey Minyard 
6023076bb3SCorey Minyard #define IPMI_DEBUG 1
6123076bb3SCorey Minyard 
6223076bb3SCorey Minyard /* Specified in the SMBIOS spec. */
6323076bb3SCorey Minyard #define IPMI_SMBIOS_KCS         0x01
6423076bb3SCorey Minyard #define IPMI_SMBIOS_SMIC        0x02
6523076bb3SCorey Minyard #define IPMI_SMBIOS_BT          0x03
6623076bb3SCorey Minyard #define IPMI_SMBIOS_SSIF        0x04
6723076bb3SCorey Minyard 
6823076bb3SCorey Minyard /* IPMI Interface types (KCS, SMIC, BT) are prefixed with this */
6923076bb3SCorey Minyard #define TYPE_IPMI_INTERFACE_PREFIX "ipmi-interface-"
7023076bb3SCorey Minyard 
7123076bb3SCorey Minyard /*
7223076bb3SCorey Minyard  * An IPMI Interface, the interface for talking between the target
7323076bb3SCorey Minyard  * and the BMC.
7423076bb3SCorey Minyard  */
7523076bb3SCorey Minyard #define TYPE_IPMI_INTERFACE "ipmi-interface"
7623076bb3SCorey Minyard #define IPMI_INTERFACE(obj) \
7723076bb3SCorey Minyard      INTERFACE_CHECK(IPMIInterface, (obj), TYPE_IPMI_INTERFACE)
7823076bb3SCorey Minyard #define IPMI_INTERFACE_CLASS(class) \
7923076bb3SCorey Minyard      OBJECT_CLASS_CHECK(IPMIInterfaceClass, (class), TYPE_IPMI_INTERFACE)
8023076bb3SCorey Minyard #define IPMI_INTERFACE_GET_CLASS(class) \
8123076bb3SCorey Minyard      OBJECT_GET_CLASS(IPMIInterfaceClass, (class), TYPE_IPMI_INTERFACE)
8223076bb3SCorey Minyard 
8323076bb3SCorey Minyard typedef struct IPMIInterface {
8423076bb3SCorey Minyard     Object parent;
8523076bb3SCorey Minyard } IPMIInterface;
8623076bb3SCorey Minyard 
8723076bb3SCorey Minyard typedef struct IPMIInterfaceClass {
8823076bb3SCorey Minyard     InterfaceClass parent;
8923076bb3SCorey Minyard 
9023076bb3SCorey Minyard     void (*init)(struct IPMIInterface *s, Error **errp);
9123076bb3SCorey Minyard 
9223076bb3SCorey Minyard     /*
9323076bb3SCorey Minyard      * Perform various operations on the hardware.  If checkonly is
9423076bb3SCorey Minyard      * true, it will return if the operation can be performed, but it
9523076bb3SCorey Minyard      * will not do the operation.
9623076bb3SCorey Minyard      */
9723076bb3SCorey Minyard     int (*do_hw_op)(struct IPMIInterface *s, enum ipmi_op op, int checkonly);
9823076bb3SCorey Minyard 
9923076bb3SCorey Minyard     /*
10023076bb3SCorey Minyard      * Enable/disable irqs on the interface when the BMC requests this.
10123076bb3SCorey Minyard      */
10223076bb3SCorey Minyard     void (*set_irq_enable)(struct IPMIInterface *s, int val);
10323076bb3SCorey Minyard 
10423076bb3SCorey Minyard     /*
10523076bb3SCorey Minyard      * Handle an event that occurred on the interface, generally the.
10623076bb3SCorey Minyard      * target writing to a register.
10723076bb3SCorey Minyard      */
10823076bb3SCorey Minyard     void (*handle_if_event)(struct IPMIInterface *s);
10923076bb3SCorey Minyard 
11023076bb3SCorey Minyard     /*
11123076bb3SCorey Minyard      * The interfaces use this to perform certain ops
11223076bb3SCorey Minyard      */
11323076bb3SCorey Minyard     void (*set_atn)(struct IPMIInterface *s, int val, int irq);
11423076bb3SCorey Minyard 
11523076bb3SCorey Minyard     /*
11623076bb3SCorey Minyard      * Got an IPMI warm/cold reset.
11723076bb3SCorey Minyard      */
11823076bb3SCorey Minyard     void (*reset)(struct IPMIInterface *s, bool is_cold);
11923076bb3SCorey Minyard 
12023076bb3SCorey Minyard     /*
12123076bb3SCorey Minyard      * Handle a response from the bmc.
12223076bb3SCorey Minyard      */
12323076bb3SCorey Minyard     void (*handle_rsp)(struct IPMIInterface *s, uint8_t msg_id,
12423076bb3SCorey Minyard                        unsigned char *rsp, unsigned int rsp_len);
12523076bb3SCorey Minyard 
12623076bb3SCorey Minyard     /*
12723076bb3SCorey Minyard      * Set by the owner to hold the backend data for the interface.
12823076bb3SCorey Minyard      */
12923076bb3SCorey Minyard     void *(*get_backend_data)(struct IPMIInterface *s);
13023076bb3SCorey Minyard } IPMIInterfaceClass;
13123076bb3SCorey Minyard 
13223076bb3SCorey Minyard /*
13323076bb3SCorey Minyard  * Define a BMC simulator (or perhaps a connection to a real BMC)
13423076bb3SCorey Minyard  */
13523076bb3SCorey Minyard #define TYPE_IPMI_BMC "ipmi-bmc"
13623076bb3SCorey Minyard #define IPMI_BMC(obj) \
13723076bb3SCorey Minyard      OBJECT_CHECK(IPMIBmc, (obj), TYPE_IPMI_BMC)
13823076bb3SCorey Minyard #define IPMI_BMC_CLASS(obj_class) \
13923076bb3SCorey Minyard      OBJECT_CLASS_CHECK(IPMIBmcClass, (obj_class), TYPE_IPMI_BMC)
14023076bb3SCorey Minyard #define IPMI_BMC_GET_CLASS(obj) \
14123076bb3SCorey Minyard      OBJECT_GET_CLASS(IPMIBmcClass, (obj), TYPE_IPMI_BMC)
14223076bb3SCorey Minyard 
14323076bb3SCorey Minyard typedef struct IPMIBmc {
14423076bb3SCorey Minyard     DeviceState parent;
14523076bb3SCorey Minyard 
14623076bb3SCorey Minyard     uint8_t slave_addr;
14723076bb3SCorey Minyard 
14823076bb3SCorey Minyard     IPMIInterface *intf;
14923076bb3SCorey Minyard } IPMIBmc;
15023076bb3SCorey Minyard 
15123076bb3SCorey Minyard typedef struct IPMIBmcClass {
15223076bb3SCorey Minyard     DeviceClass parent;
15323076bb3SCorey Minyard 
15423076bb3SCorey Minyard     /* Called when the system resets to report to the bmc. */
15523076bb3SCorey Minyard     void (*handle_reset)(struct IPMIBmc *s);
15623076bb3SCorey Minyard 
15723076bb3SCorey Minyard     /*
15823076bb3SCorey Minyard      * Handle a command to the bmc.
15923076bb3SCorey Minyard      */
16023076bb3SCorey Minyard     void (*handle_command)(struct IPMIBmc *s,
16123076bb3SCorey Minyard                            uint8_t *cmd, unsigned int cmd_len,
16223076bb3SCorey Minyard                            unsigned int max_cmd_len,
16323076bb3SCorey Minyard                            uint8_t msg_id);
16423076bb3SCorey Minyard } IPMIBmcClass;
16523076bb3SCorey Minyard 
16623076bb3SCorey Minyard /*
16723076bb3SCorey Minyard  * Add a link property to obj that points to a BMC.
16823076bb3SCorey Minyard  */
16923076bb3SCorey Minyard void ipmi_bmc_find_and_link(Object *obj, Object **bmc);
17023076bb3SCorey Minyard 
17190b61805SCorey Minyard /*
17290b61805SCorey Minyard  * Used for transferring information to interfaces that add
17390b61805SCorey Minyard  * entries to firmware tables.
17490b61805SCorey Minyard  */
17590b61805SCorey Minyard typedef struct IPMIFwInfo {
17690b61805SCorey Minyard     const char *interface_name;
17790b61805SCorey Minyard     int interface_type;
17890b61805SCorey Minyard     uint8_t ipmi_spec_major_revision;
17990b61805SCorey Minyard     uint8_t ipmi_spec_minor_revision;
18090b61805SCorey Minyard     uint8_t i2c_slave_address;
18190b61805SCorey Minyard     uint32_t uuid;
18290b61805SCorey Minyard 
18390b61805SCorey Minyard     uint64_t base_address;
18490b61805SCorey Minyard     uint64_t register_length;
18590b61805SCorey Minyard     uint8_t register_spacing;
18690b61805SCorey Minyard     enum {
18790b61805SCorey Minyard         IPMI_MEMSPACE_IO,
18890b61805SCorey Minyard         IPMI_MEMSPACE_MEM32,
18990b61805SCorey Minyard         IPMI_MEMSPACE_MEM64,
19090b61805SCorey Minyard         IPMI_MEMSPACE_SMBUS
19190b61805SCorey Minyard     } memspace;
19290b61805SCorey Minyard 
19390b61805SCorey Minyard     int interrupt_number;
19490b61805SCorey Minyard     enum {
19590b61805SCorey Minyard         IPMI_LEVEL_IRQ,
19690b61805SCorey Minyard         IPMI_EDGE_IRQ
19790b61805SCorey Minyard     } irq_type;
19890b61805SCorey Minyard 
19990b61805SCorey Minyard     const char *acpi_parent;
20090b61805SCorey Minyard } IPMIFwInfo;
20190b61805SCorey Minyard 
20290b61805SCorey Minyard void ipmi_add_fwinfo(IPMIFwInfo *info, Error **errp);
20390b61805SCorey Minyard IPMIFwInfo *ipmi_first_fwinfo(void);
20490b61805SCorey Minyard IPMIFwInfo *ipmi_next_fwinfo(IPMIFwInfo *current);
20590b61805SCorey Minyard 
20623076bb3SCorey Minyard #ifdef IPMI_DEBUG
20723076bb3SCorey Minyard #define ipmi_debug(fs, ...) \
20823076bb3SCorey Minyard     fprintf(stderr, "IPMI (%s): " fs, __func__, ##__VA_ARGS__)
20923076bb3SCorey Minyard #else
21023076bb3SCorey Minyard #define ipmi_debug(fs, ...)
21123076bb3SCorey Minyard #endif
21223076bb3SCorey Minyard 
213*a2295f0aSCédric Le Goater struct ipmi_sdr_header {
214*a2295f0aSCédric Le Goater     uint8_t  rec_id[2];
215*a2295f0aSCédric Le Goater     uint8_t  sdr_version;               /* 0x51 */
216*a2295f0aSCédric Le Goater     uint8_t  rec_type;
217*a2295f0aSCédric Le Goater     uint8_t  rec_length;
218*a2295f0aSCédric Le Goater };
219*a2295f0aSCédric Le Goater #define IPMI_SDR_HEADER_SIZE     sizeof(struct ipmi_sdr_header)
220*a2295f0aSCédric Le Goater 
221*a2295f0aSCédric Le Goater #define ipmi_sdr_recid(sdr) ((sdr)->rec_id[0] | ((sdr)->rec_id[1] << 8))
222*a2295f0aSCédric Le Goater #define ipmi_sdr_length(sdr) ((sdr)->rec_length + IPMI_SDR_HEADER_SIZE)
223*a2295f0aSCédric Le Goater 
224*a2295f0aSCédric Le Goater /*
225*a2295f0aSCédric Le Goater  * 43.2 SDR Type 02h. Compact Sensor Record
226*a2295f0aSCédric Le Goater  */
227*a2295f0aSCédric Le Goater #define IPMI_SDR_COMPACT_TYPE    2
228*a2295f0aSCédric Le Goater 
229*a2295f0aSCédric Le Goater struct ipmi_sdr_compact {
230*a2295f0aSCédric Le Goater     struct ipmi_sdr_header header;
231*a2295f0aSCédric Le Goater 
232*a2295f0aSCédric Le Goater     uint8_t  sensor_owner_id;
233*a2295f0aSCédric Le Goater     uint8_t  sensor_owner_lun;
234*a2295f0aSCédric Le Goater     uint8_t  sensor_owner_number;       /* byte 8 */
235*a2295f0aSCédric Le Goater     uint8_t  entity_id;
236*a2295f0aSCédric Le Goater     uint8_t  entity_instance;
237*a2295f0aSCédric Le Goater     uint8_t  sensor_init;
238*a2295f0aSCédric Le Goater     uint8_t  sensor_caps;
239*a2295f0aSCédric Le Goater     uint8_t  sensor_type;
240*a2295f0aSCédric Le Goater     uint8_t  reading_type;
241*a2295f0aSCédric Le Goater     uint8_t  assert_mask[2];            /* byte 16 */
242*a2295f0aSCédric Le Goater     uint8_t  deassert_mask[2];
243*a2295f0aSCédric Le Goater     uint8_t  discrete_mask[2];
244*a2295f0aSCédric Le Goater     uint8_t  sensor_unit1;
245*a2295f0aSCédric Le Goater     uint8_t  sensor_unit2;
246*a2295f0aSCédric Le Goater     uint8_t  sensor_unit3;
247*a2295f0aSCédric Le Goater     uint8_t  sensor_direction[2];       /* byte 24 */
248*a2295f0aSCédric Le Goater     uint8_t  positive_threshold;
249*a2295f0aSCédric Le Goater     uint8_t  negative_threshold;
250*a2295f0aSCédric Le Goater     uint8_t  reserved[3];
251*a2295f0aSCédric Le Goater     uint8_t  oem;
252*a2295f0aSCédric Le Goater     uint8_t  id_str_len;                /* byte 32 */
253*a2295f0aSCédric Le Goater     uint8_t  id_string[16];
254*a2295f0aSCédric Le Goater };
255*a2295f0aSCédric Le Goater 
256*a2295f0aSCédric Le Goater typedef uint8_t ipmi_sdr_compact_buffer[sizeof(struct ipmi_sdr_compact)];
257*a2295f0aSCédric Le Goater 
25823076bb3SCorey Minyard #endif
259