1 /* SPDX-License-Identifier: GPL-2.0-only */ 2 3 #ifndef __IPMI_IF_H 4 #define __IPMI_IF_H 5 6 /* Common API and code for different IPMI interfaces in different stages */ 7 8 #include <stdint.h> 9 10 #define IPMI_NETFN_CHASSIS 0x00 11 #define IPMI_NETFN_BRIDGE 0x02 12 #define IPMI_NETFN_SENSOREVENT 0x04 13 #define IPMI_NETFN_APPLICATION 0x06 14 #define IPMI_BMC_GET_DEVICE_ID 0x01 15 #define IPMI_IPMI_VERSION_MINOR(x) ((x) >> 4) 16 #define IPMI_IPMI_VERSION_MAJOR(x) ((x) & 0xf) 17 #define IPMI_BMC_GET_SELFTEST_RESULTS 0x04 18 #define IPMI_APP_SELFTEST_RESERVED 0xFF 19 #define IPMI_APP_SELFTEST_NO_ERROR 0x55 20 #define IPMI_APP_SELFTEST_NOT_IMPLEMENTED 0x56 21 #define IPMI_APP_SELFTEST_ERROR 0x57 22 #define IPMI_APP_SELFTEST_FATAL_HW_ERROR 0x58 23 24 #define IPMI_NETFN_FIRMWARE 0x08 25 #define IPMI_NETFN_STORAGE 0x0a 26 #define IPMI_READ_FRU_DATA 0x11 27 #define IPMI_ADD_SEL_ENTRY 0x44 28 #define IPMI_NETFN_TRANSPORT 0x0c 29 30 #define IPMI_CMD_ACPI_POWERON 0x06 31 32 struct ipmi_rsp { 33 uint8_t lun; 34 uint8_t cmd; 35 uint8_t completion_code; 36 } __packed; 37 38 /* Get Device ID */ 39 struct ipmi_devid_rsp { 40 struct ipmi_rsp resp; 41 uint8_t device_id; 42 uint8_t device_revision; 43 uint8_t fw_rev1; 44 uint8_t fw_rev2; 45 uint8_t ipmi_version; 46 uint8_t additional_device_support; 47 uint8_t manufacturer_id[3]; 48 uint8_t product_id[2]; 49 } __packed; 50 51 /* Get Self Test Results */ 52 struct ipmi_selftest_rsp { 53 struct ipmi_rsp resp; 54 uint8_t result; 55 uint8_t param; 56 } __packed; 57 58 struct device; 59 60 /* 61 * Sends a command and reads its response. Input buffer is for payload, but 62 * output includes `struct ipmi_rsp` as a header. Returns number of bytes copied 63 * into the buffer or -1. 64 */ 65 int ipmi_message(int port, int netfn, int lun, int cmd, 66 const unsigned char *inmsg, int inlen, 67 unsigned char *outmsg, int outlen); 68 69 /* Run basic IPMI init functions in romstage from the provided PnP device, 70 * returns CB_SUCCESS on success and CB_ERR if an error occurred. */ 71 enum cb_err ipmi_premem_init(const uint16_t port, const uint16_t device); 72 73 int ipmi_get_device_id(const struct device *dev, struct ipmi_devid_rsp *rsp); 74 75 int ipmi_process_self_test_result(const struct device *dev); 76 77 void ipmi_bmc_version(uint8_t *ipmi_bmc_major_revision, uint8_t *ipmi_bmc_minor_revision); 78 79 #endif /* __IPMI_IF_H */ 80