Angel Pons | 8a3453f | 2020-04-02 23:48:19 +0200 | [diff] [blame] | 1 | /* SPDX-License-Identifier: GPL-2.0-only */ |
Angel Pons | 8a3453f | 2020-04-02 23:48:19 +0200 | [diff] [blame] | 2 | |
Johnny Lin | f4abe51 | 2019-10-21 09:54:36 +0800 | [diff] [blame] | 3 | #ifndef __IPMI_OPS_H |
| 4 | #define __IPMI_OPS_H |
Johnny Lin | f4abe51 | 2019-10-21 09:54:36 +0800 | [diff] [blame] | 5 | |
| 6 | #include <types.h> |
Sergii Dmytruk | ef7dd5d | 2021-10-22 01:02:32 +0300 | [diff] [blame] | 7 | #include "ipmi_if.h" |
Johnny Lin | f4abe51 | 2019-10-21 09:54:36 +0800 | [diff] [blame] | 8 | #define IPMI_BMC_RESET_WDG_TIMER 0x22 |
| 9 | #define IPMI_BMC_SET_WDG_TIMER 0x24 |
| 10 | #define IPMI_BMC_GET_WDG_TIMER 0x25 |
Johnny Lin | 53509cf | 2019-11-14 14:55:04 +0800 | [diff] [blame] | 11 | #define IPMI_BMC_GET_SYSTEM_GUID 0x37 |
Johnny Lin | f4abe51 | 2019-10-21 09:54:36 +0800 | [diff] [blame] | 12 | |
| 13 | /* BMC watchdog timeout action */ |
| 14 | enum ipmi_bmc_timeout_action_type { |
| 15 | TIMEOUT_NO_ACTION = 0x00, |
| 16 | TIMEOUT_HARD_RESET = 0x01, |
| 17 | TIMEOUT_POWER_DOWN = 0x02, |
| 18 | TIMEOUT_POWER_CYCLE = 0x03, |
| 19 | }; |
| 20 | /* BMC Watchdog timer */ |
| 21 | struct ipmi_wdt_req { |
| 22 | uint8_t timer_use; |
| 23 | uint8_t timer_actions; |
| 24 | uint8_t pretimeout_interval; |
| 25 | uint8_t timer_use_expiration_flags_clr; |
| 26 | uint16_t initial_countdown_val; |
| 27 | } __packed; |
| 28 | |
| 29 | struct ipmi_wdt_rsp { |
| 30 | struct ipmi_rsp resp; |
| 31 | struct ipmi_wdt_req data; |
| 32 | uint16_t present_countdown_val; |
| 33 | } __packed; |
| 34 | |
Johnny Lin | 53509cf | 2019-11-14 14:55:04 +0800 | [diff] [blame] | 35 | struct ipmi_get_system_guid_rsp { |
| 36 | struct ipmi_rsp resp; |
| 37 | uint8_t data[16]; |
| 38 | } __packed; |
Johnny Lin | b9e8448 | 2019-12-02 19:44:04 +0800 | [diff] [blame] | 39 | |
| 40 | struct ipmi_read_fru_data_req { |
| 41 | uint8_t fru_device_id; |
| 42 | uint16_t fru_offset; |
| 43 | uint8_t count; /* count to read, 1-based. */ |
| 44 | } __packed; |
| 45 | |
| 46 | struct ipmi_read_fru_data_rsp { |
| 47 | struct ipmi_rsp resp; |
| 48 | uint8_t count; /* count returned, 1-based. */ |
| 49 | uint8_t data[CONFIG_IPMI_FRU_SINGLE_RW_SZ]; |
| 50 | } __packed; |
| 51 | |
Morgan Jang | ea9787a | 2020-04-09 13:50:43 +0800 | [diff] [blame] | 52 | struct standard_spec_sel_rec { |
| 53 | uint32_t timestamp; |
| 54 | uint16_t gen_id; |
| 55 | uint8_t evm_rev; |
| 56 | uint8_t sensor_type; |
| 57 | uint8_t sensor_num; |
| 58 | uint8_t event_dir_type; |
| 59 | uint8_t event_data[3]; |
Jonathan Zhang | cb3eaf6 | 2022-10-24 13:48:38 -0700 | [diff] [blame] | 60 | } __packed; |
Morgan Jang | ea9787a | 2020-04-09 13:50:43 +0800 | [diff] [blame] | 61 | |
| 62 | struct oem_ts_spec_sel_rec { |
| 63 | uint32_t timestamp; |
| 64 | uint8_t manf_id[3]; |
| 65 | uint8_t oem_defined[6]; |
Jonathan Zhang | cb3eaf6 | 2022-10-24 13:48:38 -0700 | [diff] [blame] | 66 | } __packed; |
Morgan Jang | ea9787a | 2020-04-09 13:50:43 +0800 | [diff] [blame] | 67 | |
| 68 | struct oem_nots_spec_sel_rec { |
| 69 | uint8_t oem_defined[13]; |
Jonathan Zhang | cb3eaf6 | 2022-10-24 13:48:38 -0700 | [diff] [blame] | 70 | } __packed; |
Morgan Jang | ea9787a | 2020-04-09 13:50:43 +0800 | [diff] [blame] | 71 | |
| 72 | /* SEL Event Record */ |
| 73 | struct sel_event_record { |
| 74 | uint16_t record_id; |
| 75 | uint8_t record_type; |
| 76 | union{ |
| 77 | struct standard_spec_sel_rec standard_type; |
| 78 | struct oem_ts_spec_sel_rec oem_ts_type; |
| 79 | struct oem_nots_spec_sel_rec oem_nots_type; |
| 80 | } sel_type; |
| 81 | } __packed; |
| 82 | |
| 83 | struct ipmi_add_sel_rsp { |
| 84 | struct ipmi_rsp resp; |
| 85 | uint16_t record_id; |
| 86 | } __packed; |
| 87 | |
Johnny Lin | b9e8448 | 2019-12-02 19:44:04 +0800 | [diff] [blame] | 88 | /* Platform Management FRU Information Storage Definition Spec. */ |
| 89 | #define PRODUCT_MAN_TYPE_LEN_OFFSET 3 |
| 90 | #define BOARD_MAN_TYPE_LEN_OFFSET 6 |
Johnny Lin | d6a4772 | 2020-01-22 16:36:17 +0800 | [diff] [blame] | 91 | #define CHASSIS_TYPE_OFFSET 2 |
Johnny Lin | b9e8448 | 2019-12-02 19:44:04 +0800 | [diff] [blame] | 92 | |
| 93 | struct ipmi_fru_common_hdr { |
| 94 | uint8_t format_version; |
| 95 | uint8_t internal_use_area_offset; |
| 96 | uint8_t chassis_area_offset; |
| 97 | uint8_t board_area_offset; |
| 98 | uint8_t product_area_offset; |
| 99 | uint8_t multirecord_area_offset; |
| 100 | uint8_t pad; |
| 101 | uint8_t checksum; |
| 102 | } __packed; |
| 103 | |
| 104 | /* The fru_xxx_info only declares the strings that may be added to SMBIOS. */ |
| 105 | struct fru_product_info { |
| 106 | char *manufacturer; |
| 107 | char *product_name; |
| 108 | char *product_partnumber; |
| 109 | char *product_version; |
| 110 | char *serial_number; |
| 111 | char *asset_tag; |
Johnny Lin | db654ea | 2020-04-20 17:32:47 +0800 | [diff] [blame] | 112 | char *fru_file_id; |
| 113 | char **product_custom; |
Paul Menzel | 2dcc722 | 2022-01-05 13:29:53 +0100 | [diff] [blame] | 114 | size_t custom_count; /* Number of custom fields */ |
Johnny Lin | b9e8448 | 2019-12-02 19:44:04 +0800 | [diff] [blame] | 115 | }; |
| 116 | |
| 117 | struct fru_board_info { |
| 118 | char *manufacturer; |
| 119 | char *product_name; |
| 120 | char *serial_number; |
| 121 | char *part_number; |
Johnny Lin | db654ea | 2020-04-20 17:32:47 +0800 | [diff] [blame] | 122 | char *fru_file_id; |
| 123 | char **board_custom; |
Paul Menzel | 2dcc722 | 2022-01-05 13:29:53 +0100 | [diff] [blame] | 124 | size_t custom_count; |
Johnny Lin | b9e8448 | 2019-12-02 19:44:04 +0800 | [diff] [blame] | 125 | }; |
| 126 | |
Johnny Lin | d6a4772 | 2020-01-22 16:36:17 +0800 | [diff] [blame] | 127 | struct fru_chassis_info { |
| 128 | uint8_t chassis_type; |
| 129 | char *chassis_partnumber; |
| 130 | char *serial_number; |
| 131 | char **chassis_custom; |
Paul Menzel | 2dcc722 | 2022-01-05 13:29:53 +0100 | [diff] [blame] | 132 | size_t custom_count; |
Johnny Lin | d6a4772 | 2020-01-22 16:36:17 +0800 | [diff] [blame] | 133 | }; |
| 134 | |
Johnny Lin | b9e8448 | 2019-12-02 19:44:04 +0800 | [diff] [blame] | 135 | struct fru_info_str { |
| 136 | struct fru_product_info prod_info; |
| 137 | struct fru_board_info board_info; |
Johnny Lin | d6a4772 | 2020-01-22 16:36:17 +0800 | [diff] [blame] | 138 | struct fru_chassis_info chassis_info; |
Johnny Lin | b9e8448 | 2019-12-02 19:44:04 +0800 | [diff] [blame] | 139 | }; |
| 140 | |
| 141 | enum typecode { |
| 142 | BINARY = 0, |
| 143 | BCD_PLUS = 1, |
| 144 | ASCII_6BIT = 2, |
| 145 | ASCII_8BIT = 3, |
| 146 | }; |
| 147 | |
| 148 | enum fru_area { |
| 149 | INTERNAL_USE_AREA = 0, |
| 150 | CHASSIS_INFO_AREA = 1, |
| 151 | BOARD_INFO_AREA = 2, |
| 152 | PRODUCT_INFO_AREA = 3, |
| 153 | MULTIRECORD_INFO_AREA = 4, |
| 154 | }; |
Johnny Lin | f4abe51 | 2019-10-21 09:54:36 +0800 | [diff] [blame] | 155 | /* |
| 156 | * Initialize and start BMC FRB2 watchdog timer with the |
| 157 | * provided timer countdown and action values. |
| 158 | * Returns CB_SUCCESS on success and CB_ERR if an error occurred |
| 159 | */ |
| 160 | enum cb_err ipmi_init_and_start_bmc_wdt(const int port, uint16_t countdown, |
| 161 | uint8_t action); |
| 162 | /* Returns CB_SUCCESS on success and CB_ERR if an error occurred */ |
| 163 | enum cb_err ipmi_stop_bmc_wdt(const int port); |
| 164 | |
Johnny Lin | 53509cf | 2019-11-14 14:55:04 +0800 | [diff] [blame] | 165 | /* IPMI get BMC system GUID and store it to parameter uuid. |
| 166 | * Returns CB_SUCCESS on success and CB_ERR if an error occurred */ |
| 167 | enum cb_err ipmi_get_system_guid(const int port, uint8_t *uuid); |
Johnny Lin | b9e8448 | 2019-12-02 19:44:04 +0800 | [diff] [blame] | 168 | |
| 169 | /* Read all FRU inventory areas string data into fru_info_str with |
| 170 | * the same FRU device id. */ |
| 171 | void read_fru_areas(const int port, uint8_t id, uint16_t offset, |
| 172 | struct fru_info_str *fru_info_str); |
| 173 | |
| 174 | /* Read a particular FRU inventory area into fru_info_str. */ |
| 175 | void read_fru_one_area(const int port, uint8_t id, uint16_t offset, |
| 176 | struct fru_info_str *fru_info_str, enum fru_area fru_area); |
Morgan Jang | ea9787a | 2020-04-09 13:50:43 +0800 | [diff] [blame] | 177 | |
| 178 | /* Add a SEL record entry, returns CB_SUCCESS on success and CB_ERR |
| 179 | * if an error occurred */ |
| 180 | enum cb_err ipmi_add_sel(const int port, struct sel_event_record *sel); |
Johnny Lin | db654ea | 2020-04-20 17:32:47 +0800 | [diff] [blame] | 181 | |
| 182 | /* Print all IPMI read FRU data */ |
| 183 | void print_fru_areas(struct fru_info_str *fru_info_str); |
Johnny Lin | f4abe51 | 2019-10-21 09:54:36 +0800 | [diff] [blame] | 184 | #endif |