xref: /qemu/include/hw/ipmi/ipmi.h (revision 7fabcdb942c2eefa3a40f4cc5ebae25cc13f6ddc)
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 
6815139b8eSCorey Minyard /*
6915139b8eSCorey Minyard  * Used for transferring information to interfaces that add
7015139b8eSCorey Minyard  * entries to firmware tables.
7115139b8eSCorey Minyard  */
7215139b8eSCorey Minyard typedef struct IPMIFwInfo {
7315139b8eSCorey Minyard     const char *interface_name;
7415139b8eSCorey Minyard     int interface_type;
7515139b8eSCorey Minyard     uint8_t ipmi_spec_major_revision;
7615139b8eSCorey Minyard     uint8_t ipmi_spec_minor_revision;
7715139b8eSCorey Minyard     uint8_t i2c_slave_address;
7815139b8eSCorey Minyard     uint32_t uuid;
7915139b8eSCorey Minyard 
8015139b8eSCorey Minyard     uint64_t base_address;
8115139b8eSCorey Minyard     uint64_t register_length;
8215139b8eSCorey Minyard     uint8_t register_spacing;
8315139b8eSCorey Minyard     enum {
8415139b8eSCorey Minyard         IPMI_MEMSPACE_IO,
8515139b8eSCorey Minyard         IPMI_MEMSPACE_MEM32,
8615139b8eSCorey Minyard         IPMI_MEMSPACE_MEM64,
8715139b8eSCorey Minyard         IPMI_MEMSPACE_SMBUS
8815139b8eSCorey Minyard     } memspace;
8915139b8eSCorey Minyard 
9015139b8eSCorey Minyard     int interrupt_number;
9115139b8eSCorey Minyard     enum {
9215139b8eSCorey Minyard         IPMI_LEVEL_IRQ,
9315139b8eSCorey Minyard         IPMI_EDGE_IRQ
9415139b8eSCorey Minyard     } irq_type;
9515139b8eSCorey Minyard } IPMIFwInfo;
9615139b8eSCorey Minyard 
9715139b8eSCorey Minyard /*
9815139b8eSCorey Minyard  * Called by each instantiated IPMI interface device to get it's uuid.
9915139b8eSCorey Minyard  */
10015139b8eSCorey Minyard uint32_t ipmi_next_uuid(void);
10115139b8eSCorey Minyard 
10223076bb3SCorey Minyard /* IPMI Interface types (KCS, SMIC, BT) are prefixed with this */
10323076bb3SCorey Minyard #define TYPE_IPMI_INTERFACE_PREFIX "ipmi-interface-"
10423076bb3SCorey Minyard 
10523076bb3SCorey Minyard /*
10623076bb3SCorey Minyard  * An IPMI Interface, the interface for talking between the target
10723076bb3SCorey Minyard  * and the BMC.
10823076bb3SCorey Minyard  */
10923076bb3SCorey Minyard #define TYPE_IPMI_INTERFACE "ipmi-interface"
11023076bb3SCorey Minyard #define IPMI_INTERFACE(obj) \
11123076bb3SCorey Minyard      INTERFACE_CHECK(IPMIInterface, (obj), TYPE_IPMI_INTERFACE)
11223076bb3SCorey Minyard #define IPMI_INTERFACE_CLASS(class) \
11323076bb3SCorey Minyard      OBJECT_CLASS_CHECK(IPMIInterfaceClass, (class), TYPE_IPMI_INTERFACE)
11423076bb3SCorey Minyard #define IPMI_INTERFACE_GET_CLASS(class) \
11523076bb3SCorey Minyard      OBJECT_GET_CLASS(IPMIInterfaceClass, (class), TYPE_IPMI_INTERFACE)
11623076bb3SCorey Minyard 
11723076bb3SCorey Minyard typedef struct IPMIInterface {
11823076bb3SCorey Minyard     Object parent;
11923076bb3SCorey Minyard } IPMIInterface;
12023076bb3SCorey Minyard 
12123076bb3SCorey Minyard typedef struct IPMIInterfaceClass {
12223076bb3SCorey Minyard     InterfaceClass parent;
12323076bb3SCorey Minyard 
12423076bb3SCorey Minyard     void (*init)(struct IPMIInterface *s, Error **errp);
12523076bb3SCorey Minyard 
12623076bb3SCorey Minyard     /*
12723076bb3SCorey Minyard      * Perform various operations on the hardware.  If checkonly is
12823076bb3SCorey Minyard      * true, it will return if the operation can be performed, but it
12923076bb3SCorey Minyard      * will not do the operation.
13023076bb3SCorey Minyard      */
13123076bb3SCorey Minyard     int (*do_hw_op)(struct IPMIInterface *s, enum ipmi_op op, int checkonly);
13223076bb3SCorey Minyard 
13323076bb3SCorey Minyard     /*
13423076bb3SCorey Minyard      * Enable/disable irqs on the interface when the BMC requests this.
13523076bb3SCorey Minyard      */
13623076bb3SCorey Minyard     void (*set_irq_enable)(struct IPMIInterface *s, int val);
13723076bb3SCorey Minyard 
13823076bb3SCorey Minyard     /*
13923076bb3SCorey Minyard      * Handle an event that occurred on the interface, generally the.
14023076bb3SCorey Minyard      * target writing to a register.
14123076bb3SCorey Minyard      */
14223076bb3SCorey Minyard     void (*handle_if_event)(struct IPMIInterface *s);
14323076bb3SCorey Minyard 
14423076bb3SCorey Minyard     /*
14523076bb3SCorey Minyard      * The interfaces use this to perform certain ops
14623076bb3SCorey Minyard      */
14723076bb3SCorey Minyard     void (*set_atn)(struct IPMIInterface *s, int val, int irq);
14823076bb3SCorey Minyard 
14923076bb3SCorey Minyard     /*
15023076bb3SCorey Minyard      * Got an IPMI warm/cold reset.
15123076bb3SCorey Minyard      */
15223076bb3SCorey Minyard     void (*reset)(struct IPMIInterface *s, bool is_cold);
15323076bb3SCorey Minyard 
15423076bb3SCorey Minyard     /*
15523076bb3SCorey Minyard      * Handle a response from the bmc.
15623076bb3SCorey Minyard      */
15723076bb3SCorey Minyard     void (*handle_rsp)(struct IPMIInterface *s, uint8_t msg_id,
15823076bb3SCorey Minyard                        unsigned char *rsp, unsigned int rsp_len);
15923076bb3SCorey Minyard 
16023076bb3SCorey Minyard     /*
16123076bb3SCorey Minyard      * Set by the owner to hold the backend data for the interface.
16223076bb3SCorey Minyard      */
16323076bb3SCorey Minyard     void *(*get_backend_data)(struct IPMIInterface *s);
16415139b8eSCorey Minyard 
16515139b8eSCorey Minyard     /*
16615139b8eSCorey Minyard      * Return the firmware info for a device.
16715139b8eSCorey Minyard      */
16815139b8eSCorey Minyard     void (*get_fwinfo)(struct IPMIInterface *s, IPMIFwInfo *info);
16923076bb3SCorey Minyard } IPMIInterfaceClass;
17023076bb3SCorey Minyard 
17123076bb3SCorey Minyard /*
17223076bb3SCorey Minyard  * Define a BMC simulator (or perhaps a connection to a real BMC)
17323076bb3SCorey Minyard  */
17423076bb3SCorey Minyard #define TYPE_IPMI_BMC "ipmi-bmc"
17523076bb3SCorey Minyard #define IPMI_BMC(obj) \
17623076bb3SCorey Minyard      OBJECT_CHECK(IPMIBmc, (obj), TYPE_IPMI_BMC)
17723076bb3SCorey Minyard #define IPMI_BMC_CLASS(obj_class) \
17823076bb3SCorey Minyard      OBJECT_CLASS_CHECK(IPMIBmcClass, (obj_class), TYPE_IPMI_BMC)
17923076bb3SCorey Minyard #define IPMI_BMC_GET_CLASS(obj) \
18023076bb3SCorey Minyard      OBJECT_GET_CLASS(IPMIBmcClass, (obj), TYPE_IPMI_BMC)
18123076bb3SCorey Minyard 
18223076bb3SCorey Minyard typedef struct IPMIBmc {
18323076bb3SCorey Minyard     DeviceState parent;
18423076bb3SCorey Minyard 
18523076bb3SCorey Minyard     uint8_t slave_addr;
18623076bb3SCorey Minyard 
18723076bb3SCorey Minyard     IPMIInterface *intf;
18823076bb3SCorey Minyard } IPMIBmc;
18923076bb3SCorey Minyard 
19023076bb3SCorey Minyard typedef struct IPMIBmcClass {
19123076bb3SCorey Minyard     DeviceClass parent;
19223076bb3SCorey Minyard 
19323076bb3SCorey Minyard     /* Called when the system resets to report to the bmc. */
19423076bb3SCorey Minyard     void (*handle_reset)(struct IPMIBmc *s);
19523076bb3SCorey Minyard 
19623076bb3SCorey Minyard     /*
19723076bb3SCorey Minyard      * Handle a command to the bmc.
19823076bb3SCorey Minyard      */
19923076bb3SCorey Minyard     void (*handle_command)(struct IPMIBmc *s,
20023076bb3SCorey Minyard                            uint8_t *cmd, unsigned int cmd_len,
20123076bb3SCorey Minyard                            unsigned int max_cmd_len,
20223076bb3SCorey Minyard                            uint8_t msg_id);
20323076bb3SCorey Minyard } IPMIBmcClass;
20423076bb3SCorey Minyard 
20523076bb3SCorey Minyard /*
20623076bb3SCorey Minyard  * Add a link property to obj that points to a BMC.
20723076bb3SCorey Minyard  */
20823076bb3SCorey Minyard void ipmi_bmc_find_and_link(Object *obj, Object **bmc);
20923076bb3SCorey Minyard 
21023076bb3SCorey Minyard #ifdef IPMI_DEBUG
21123076bb3SCorey Minyard #define ipmi_debug(fs, ...) \
21223076bb3SCorey Minyard     fprintf(stderr, "IPMI (%s): " fs, __func__, ##__VA_ARGS__)
21323076bb3SCorey Minyard #else
21423076bb3SCorey Minyard #define ipmi_debug(fs, ...)
21523076bb3SCorey Minyard #endif
21623076bb3SCorey Minyard 
217a2295f0aSCédric Le Goater struct ipmi_sdr_header {
218a2295f0aSCédric Le Goater     uint8_t  rec_id[2];
219a2295f0aSCédric Le Goater     uint8_t  sdr_version;               /* 0x51 */
220a2295f0aSCédric Le Goater     uint8_t  rec_type;
221a2295f0aSCédric Le Goater     uint8_t  rec_length;
222a2295f0aSCédric Le Goater };
223a2295f0aSCédric Le Goater #define IPMI_SDR_HEADER_SIZE     sizeof(struct ipmi_sdr_header)
224a2295f0aSCédric Le Goater 
225a2295f0aSCédric Le Goater #define ipmi_sdr_recid(sdr) ((sdr)->rec_id[0] | ((sdr)->rec_id[1] << 8))
226a2295f0aSCédric Le Goater #define ipmi_sdr_length(sdr) ((sdr)->rec_length + IPMI_SDR_HEADER_SIZE)
227a2295f0aSCédric Le Goater 
228a2295f0aSCédric Le Goater /*
229a2295f0aSCédric Le Goater  * 43.2 SDR Type 02h. Compact Sensor Record
230a2295f0aSCédric Le Goater  */
231a2295f0aSCédric Le Goater #define IPMI_SDR_COMPACT_TYPE    2
232a2295f0aSCédric Le Goater 
233a2295f0aSCédric Le Goater struct ipmi_sdr_compact {
234a2295f0aSCédric Le Goater     struct ipmi_sdr_header header;
235a2295f0aSCédric Le Goater 
236a2295f0aSCédric Le Goater     uint8_t  sensor_owner_id;
237a2295f0aSCédric Le Goater     uint8_t  sensor_owner_lun;
238a2295f0aSCédric Le Goater     uint8_t  sensor_owner_number;       /* byte 8 */
239a2295f0aSCédric Le Goater     uint8_t  entity_id;
240a2295f0aSCédric Le Goater     uint8_t  entity_instance;
241a2295f0aSCédric Le Goater     uint8_t  sensor_init;
242a2295f0aSCédric Le Goater     uint8_t  sensor_caps;
243a2295f0aSCédric Le Goater     uint8_t  sensor_type;
244a2295f0aSCédric Le Goater     uint8_t  reading_type;
245a2295f0aSCédric Le Goater     uint8_t  assert_mask[2];            /* byte 16 */
246a2295f0aSCédric Le Goater     uint8_t  deassert_mask[2];
247a2295f0aSCédric Le Goater     uint8_t  discrete_mask[2];
248a2295f0aSCédric Le Goater     uint8_t  sensor_unit1;
249a2295f0aSCédric Le Goater     uint8_t  sensor_unit2;
250a2295f0aSCédric Le Goater     uint8_t  sensor_unit3;
251a2295f0aSCédric Le Goater     uint8_t  sensor_direction[2];       /* byte 24 */
252a2295f0aSCédric Le Goater     uint8_t  positive_threshold;
253a2295f0aSCédric Le Goater     uint8_t  negative_threshold;
254a2295f0aSCédric Le Goater     uint8_t  reserved[3];
255a2295f0aSCédric Le Goater     uint8_t  oem;
256a2295f0aSCédric Le Goater     uint8_t  id_str_len;                /* byte 32 */
257a2295f0aSCédric Le Goater     uint8_t  id_string[16];
258a2295f0aSCédric Le Goater };
259a2295f0aSCédric Le Goater 
260a2295f0aSCédric Le Goater typedef uint8_t ipmi_sdr_compact_buffer[sizeof(struct ipmi_sdr_compact)];
261a2295f0aSCédric Le Goater 
262*7fabcdb9SCédric Le Goater int ipmi_bmc_sdr_find(IPMIBmc *b, uint16_t recid,
263*7fabcdb9SCédric Le Goater                       const struct ipmi_sdr_compact **sdr, uint16_t *nextrec);
26423076bb3SCorey Minyard #endif
265