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" 29a27bd6c7SMarkus Armbruster #include "hw/qdev-core.h" 3023076bb3SCorey Minyard 3123076bb3SCorey Minyard #define MAX_IPMI_MSG_SIZE 300 3223076bb3SCorey Minyard 3323076bb3SCorey Minyard enum ipmi_op { 3423076bb3SCorey Minyard IPMI_RESET_CHASSIS, 3523076bb3SCorey Minyard IPMI_POWEROFF_CHASSIS, 3623076bb3SCorey Minyard IPMI_POWERON_CHASSIS, 3723076bb3SCorey Minyard IPMI_POWERCYCLE_CHASSIS, 3823076bb3SCorey Minyard IPMI_PULSE_DIAG_IRQ, 3923076bb3SCorey Minyard IPMI_SHUTDOWN_VIA_ACPI_OVERTEMP, 4023076bb3SCorey Minyard IPMI_SEND_NMI 4123076bb3SCorey Minyard }; 4223076bb3SCorey Minyard 4323076bb3SCorey Minyard #define IPMI_CC_INVALID_CMD 0xc1 4423076bb3SCorey Minyard #define IPMI_CC_COMMAND_INVALID_FOR_LUN 0xc2 4523076bb3SCorey Minyard #define IPMI_CC_TIMEOUT 0xc3 4623076bb3SCorey Minyard #define IPMI_CC_OUT_OF_SPACE 0xc4 4723076bb3SCorey Minyard #define IPMI_CC_INVALID_RESERVATION 0xc5 4823076bb3SCorey Minyard #define IPMI_CC_REQUEST_DATA_TRUNCATED 0xc6 4923076bb3SCorey Minyard #define IPMI_CC_REQUEST_DATA_LENGTH_INVALID 0xc7 5023076bb3SCorey Minyard #define IPMI_CC_PARM_OUT_OF_RANGE 0xc9 5123076bb3SCorey Minyard #define IPMI_CC_CANNOT_RETURN_REQ_NUM_BYTES 0xca 5223076bb3SCorey Minyard #define IPMI_CC_REQ_ENTRY_NOT_PRESENT 0xcb 5323076bb3SCorey Minyard #define IPMI_CC_INVALID_DATA_FIELD 0xcc 5423076bb3SCorey Minyard #define IPMI_CC_BMC_INIT_IN_PROGRESS 0xd2 5523076bb3SCorey Minyard #define IPMI_CC_COMMAND_NOT_SUPPORTED 0xd5 5623076bb3SCorey Minyard 5723076bb3SCorey Minyard #define IPMI_NETFN_APP 0x06 5823076bb3SCorey Minyard 5923076bb3SCorey Minyard #define IPMI_DEBUG 1 6023076bb3SCorey Minyard 6123076bb3SCorey Minyard /* Specified in the SMBIOS spec. */ 6223076bb3SCorey Minyard #define IPMI_SMBIOS_KCS 0x01 6323076bb3SCorey Minyard #define IPMI_SMBIOS_SMIC 0x02 6423076bb3SCorey Minyard #define IPMI_SMBIOS_BT 0x03 6523076bb3SCorey Minyard #define IPMI_SMBIOS_SSIF 0x04 6623076bb3SCorey Minyard 6715139b8eSCorey Minyard /* 6815139b8eSCorey Minyard * Used for transferring information to interfaces that add 6915139b8eSCorey Minyard * entries to firmware tables. 7015139b8eSCorey Minyard */ 7115139b8eSCorey Minyard typedef struct IPMIFwInfo { 7215139b8eSCorey Minyard const char *interface_name; 7315139b8eSCorey Minyard int interface_type; 7415139b8eSCorey Minyard uint8_t ipmi_spec_major_revision; 7515139b8eSCorey Minyard uint8_t ipmi_spec_minor_revision; 7615139b8eSCorey Minyard uint8_t i2c_slave_address; 7715139b8eSCorey Minyard uint32_t uuid; 7815139b8eSCorey Minyard 7915139b8eSCorey Minyard uint64_t base_address; 8015139b8eSCorey Minyard uint64_t register_length; 8115139b8eSCorey Minyard uint8_t register_spacing; 8215139b8eSCorey Minyard enum { 8315139b8eSCorey Minyard IPMI_MEMSPACE_IO, 8415139b8eSCorey Minyard IPMI_MEMSPACE_MEM32, 8515139b8eSCorey Minyard IPMI_MEMSPACE_MEM64, 8615139b8eSCorey Minyard IPMI_MEMSPACE_SMBUS 8715139b8eSCorey Minyard } memspace; 8815139b8eSCorey Minyard 8915139b8eSCorey Minyard int interrupt_number; 9015139b8eSCorey Minyard enum { 9115139b8eSCorey Minyard IPMI_LEVEL_IRQ, 9215139b8eSCorey Minyard IPMI_EDGE_IRQ 9315139b8eSCorey Minyard } irq_type; 9415139b8eSCorey Minyard } IPMIFwInfo; 9515139b8eSCorey Minyard 9615139b8eSCorey Minyard /* 9715139b8eSCorey Minyard * Called by each instantiated IPMI interface device to get it's uuid. 9815139b8eSCorey Minyard */ 9915139b8eSCorey Minyard uint32_t ipmi_next_uuid(void); 10015139b8eSCorey Minyard 10123076bb3SCorey Minyard /* IPMI Interface types (KCS, SMIC, BT) are prefixed with this */ 10223076bb3SCorey Minyard #define TYPE_IPMI_INTERFACE_PREFIX "ipmi-interface-" 10323076bb3SCorey Minyard 10423076bb3SCorey Minyard /* 10523076bb3SCorey Minyard * An IPMI Interface, the interface for talking between the target 10623076bb3SCorey Minyard * and the BMC. 10723076bb3SCorey Minyard */ 10823076bb3SCorey Minyard #define TYPE_IPMI_INTERFACE "ipmi-interface" 10923076bb3SCorey Minyard #define IPMI_INTERFACE(obj) \ 11023076bb3SCorey Minyard INTERFACE_CHECK(IPMIInterface, (obj), TYPE_IPMI_INTERFACE) 11123076bb3SCorey Minyard #define IPMI_INTERFACE_CLASS(class) \ 11223076bb3SCorey Minyard OBJECT_CLASS_CHECK(IPMIInterfaceClass, (class), TYPE_IPMI_INTERFACE) 11323076bb3SCorey Minyard #define IPMI_INTERFACE_GET_CLASS(class) \ 11423076bb3SCorey Minyard OBJECT_GET_CLASS(IPMIInterfaceClass, (class), TYPE_IPMI_INTERFACE) 11523076bb3SCorey Minyard 116aa1b35b9SMarc-André Lureau typedef struct IPMIInterface IPMIInterface; 11723076bb3SCorey Minyard 11823076bb3SCorey Minyard typedef struct IPMIInterfaceClass { 11923076bb3SCorey Minyard InterfaceClass parent; 12023076bb3SCorey Minyard 121*79d29a9dSCorey Minyard /* 122*79d29a9dSCorey Minyard * min_size is the requested I/O size and must be a power of 2. 123*79d29a9dSCorey Minyard * This is so PCI (or other busses) can request a bigger range. 124*79d29a9dSCorey Minyard * Use 0 for the default. 125*79d29a9dSCorey Minyard */ 126*79d29a9dSCorey Minyard void (*init)(struct IPMIInterface *s, unsigned int min_size, Error **errp); 12723076bb3SCorey Minyard 12823076bb3SCorey Minyard /* 12923076bb3SCorey Minyard * Perform various operations on the hardware. If checkonly is 13023076bb3SCorey Minyard * true, it will return if the operation can be performed, but it 13123076bb3SCorey Minyard * will not do the operation. 13223076bb3SCorey Minyard */ 13323076bb3SCorey Minyard int (*do_hw_op)(struct IPMIInterface *s, enum ipmi_op op, int checkonly); 13423076bb3SCorey Minyard 13523076bb3SCorey Minyard /* 13623076bb3SCorey Minyard * Enable/disable irqs on the interface when the BMC requests this. 13723076bb3SCorey Minyard */ 13823076bb3SCorey Minyard void (*set_irq_enable)(struct IPMIInterface *s, int val); 13923076bb3SCorey Minyard 14023076bb3SCorey Minyard /* 14123076bb3SCorey Minyard * Handle an event that occurred on the interface, generally the. 14223076bb3SCorey Minyard * target writing to a register. 14323076bb3SCorey Minyard */ 14423076bb3SCorey Minyard void (*handle_if_event)(struct IPMIInterface *s); 14523076bb3SCorey Minyard 14623076bb3SCorey Minyard /* 14723076bb3SCorey Minyard * The interfaces use this to perform certain ops 14823076bb3SCorey Minyard */ 14923076bb3SCorey Minyard void (*set_atn)(struct IPMIInterface *s, int val, int irq); 15023076bb3SCorey Minyard 15123076bb3SCorey Minyard /* 15223076bb3SCorey Minyard * Got an IPMI warm/cold reset. 15323076bb3SCorey Minyard */ 15423076bb3SCorey Minyard void (*reset)(struct IPMIInterface *s, bool is_cold); 15523076bb3SCorey Minyard 15623076bb3SCorey Minyard /* 15723076bb3SCorey Minyard * Handle a response from the bmc. 15823076bb3SCorey Minyard */ 15923076bb3SCorey Minyard void (*handle_rsp)(struct IPMIInterface *s, uint8_t msg_id, 16023076bb3SCorey Minyard unsigned char *rsp, unsigned int rsp_len); 16123076bb3SCorey Minyard 16223076bb3SCorey Minyard /* 16323076bb3SCorey Minyard * Set by the owner to hold the backend data for the interface. 16423076bb3SCorey Minyard */ 16523076bb3SCorey Minyard void *(*get_backend_data)(struct IPMIInterface *s); 16615139b8eSCorey Minyard 16715139b8eSCorey Minyard /* 16815139b8eSCorey Minyard * Return the firmware info for a device. 16915139b8eSCorey Minyard */ 17015139b8eSCorey Minyard void (*get_fwinfo)(struct IPMIInterface *s, IPMIFwInfo *info); 17123076bb3SCorey Minyard } IPMIInterfaceClass; 17223076bb3SCorey Minyard 17323076bb3SCorey Minyard /* 17423076bb3SCorey Minyard * Define a BMC simulator (or perhaps a connection to a real BMC) 17523076bb3SCorey Minyard */ 17623076bb3SCorey Minyard #define TYPE_IPMI_BMC "ipmi-bmc" 17723076bb3SCorey Minyard #define IPMI_BMC(obj) \ 17823076bb3SCorey Minyard OBJECT_CHECK(IPMIBmc, (obj), TYPE_IPMI_BMC) 17923076bb3SCorey Minyard #define IPMI_BMC_CLASS(obj_class) \ 18023076bb3SCorey Minyard OBJECT_CLASS_CHECK(IPMIBmcClass, (obj_class), TYPE_IPMI_BMC) 18123076bb3SCorey Minyard #define IPMI_BMC_GET_CLASS(obj) \ 18223076bb3SCorey Minyard OBJECT_GET_CLASS(IPMIBmcClass, (obj), TYPE_IPMI_BMC) 18323076bb3SCorey Minyard 18423076bb3SCorey Minyard typedef struct IPMIBmc { 18523076bb3SCorey Minyard DeviceState parent; 18623076bb3SCorey Minyard 18723076bb3SCorey Minyard uint8_t slave_addr; 18823076bb3SCorey Minyard 18923076bb3SCorey Minyard IPMIInterface *intf; 19023076bb3SCorey Minyard } IPMIBmc; 19123076bb3SCorey Minyard 19223076bb3SCorey Minyard typedef struct IPMIBmcClass { 19323076bb3SCorey Minyard DeviceClass parent; 19423076bb3SCorey Minyard 19523076bb3SCorey Minyard /* Called when the system resets to report to the bmc. */ 19623076bb3SCorey Minyard void (*handle_reset)(struct IPMIBmc *s); 19723076bb3SCorey Minyard 19823076bb3SCorey Minyard /* 19923076bb3SCorey Minyard * Handle a command to the bmc. 20023076bb3SCorey Minyard */ 20123076bb3SCorey Minyard void (*handle_command)(struct IPMIBmc *s, 20223076bb3SCorey Minyard uint8_t *cmd, unsigned int cmd_len, 20323076bb3SCorey Minyard unsigned int max_cmd_len, 20423076bb3SCorey Minyard uint8_t msg_id); 20523076bb3SCorey Minyard } IPMIBmcClass; 20623076bb3SCorey Minyard 20723076bb3SCorey Minyard /* 20823076bb3SCorey Minyard * Add a link property to obj that points to a BMC. 20923076bb3SCorey Minyard */ 21023076bb3SCorey Minyard void ipmi_bmc_find_and_link(Object *obj, Object **bmc); 21123076bb3SCorey Minyard 21223076bb3SCorey Minyard #ifdef IPMI_DEBUG 21323076bb3SCorey Minyard #define ipmi_debug(fs, ...) \ 21423076bb3SCorey Minyard fprintf(stderr, "IPMI (%s): " fs, __func__, ##__VA_ARGS__) 21523076bb3SCorey Minyard #else 21623076bb3SCorey Minyard #define ipmi_debug(fs, ...) 21723076bb3SCorey Minyard #endif 21823076bb3SCorey Minyard 219a2295f0aSCédric Le Goater struct ipmi_sdr_header { 220a2295f0aSCédric Le Goater uint8_t rec_id[2]; 221a2295f0aSCédric Le Goater uint8_t sdr_version; /* 0x51 */ 222a2295f0aSCédric Le Goater uint8_t rec_type; 223a2295f0aSCédric Le Goater uint8_t rec_length; 224a2295f0aSCédric Le Goater }; 225a2295f0aSCédric Le Goater #define IPMI_SDR_HEADER_SIZE sizeof(struct ipmi_sdr_header) 226a2295f0aSCédric Le Goater 227a2295f0aSCédric Le Goater #define ipmi_sdr_recid(sdr) ((sdr)->rec_id[0] | ((sdr)->rec_id[1] << 8)) 228a2295f0aSCédric Le Goater #define ipmi_sdr_length(sdr) ((sdr)->rec_length + IPMI_SDR_HEADER_SIZE) 229a2295f0aSCédric Le Goater 230a2295f0aSCédric Le Goater /* 231a2295f0aSCédric Le Goater * 43.2 SDR Type 02h. Compact Sensor Record 232a2295f0aSCédric Le Goater */ 233a2295f0aSCédric Le Goater #define IPMI_SDR_COMPACT_TYPE 2 234a2295f0aSCédric Le Goater 235a2295f0aSCédric Le Goater struct ipmi_sdr_compact { 236a2295f0aSCédric Le Goater struct ipmi_sdr_header header; 237a2295f0aSCédric Le Goater 238a2295f0aSCédric Le Goater uint8_t sensor_owner_id; 239a2295f0aSCédric Le Goater uint8_t sensor_owner_lun; 240a2295f0aSCédric Le Goater uint8_t sensor_owner_number; /* byte 8 */ 241a2295f0aSCédric Le Goater uint8_t entity_id; 242a2295f0aSCédric Le Goater uint8_t entity_instance; 243a2295f0aSCédric Le Goater uint8_t sensor_init; 244a2295f0aSCédric Le Goater uint8_t sensor_caps; 245a2295f0aSCédric Le Goater uint8_t sensor_type; 246a2295f0aSCédric Le Goater uint8_t reading_type; 247a2295f0aSCédric Le Goater uint8_t assert_mask[2]; /* byte 16 */ 248a2295f0aSCédric Le Goater uint8_t deassert_mask[2]; 249a2295f0aSCédric Le Goater uint8_t discrete_mask[2]; 250a2295f0aSCédric Le Goater uint8_t sensor_unit1; 251a2295f0aSCédric Le Goater uint8_t sensor_unit2; 252a2295f0aSCédric Le Goater uint8_t sensor_unit3; 253a2295f0aSCédric Le Goater uint8_t sensor_direction[2]; /* byte 24 */ 254a2295f0aSCédric Le Goater uint8_t positive_threshold; 255a2295f0aSCédric Le Goater uint8_t negative_threshold; 256a2295f0aSCédric Le Goater uint8_t reserved[3]; 257a2295f0aSCédric Le Goater uint8_t oem; 258a2295f0aSCédric Le Goater uint8_t id_str_len; /* byte 32 */ 259a2295f0aSCédric Le Goater uint8_t id_string[16]; 260a2295f0aSCédric Le Goater }; 261a2295f0aSCédric Le Goater 262a2295f0aSCédric Le Goater typedef uint8_t ipmi_sdr_compact_buffer[sizeof(struct ipmi_sdr_compact)]; 263a2295f0aSCédric Le Goater 2647fabcdb9SCédric Le Goater int ipmi_bmc_sdr_find(IPMIBmc *b, uint16_t recid, 2657fabcdb9SCédric Le Goater const struct ipmi_sdr_compact **sdr, uint16_t *nextrec); 266cd60d85eSCédric Le Goater void ipmi_bmc_gen_event(IPMIBmc *b, uint8_t *evt, bool log); 267cd60d85eSCédric Le Goater 26823076bb3SCorey Minyard #endif 269