Jason M. Bills | 3f7c5e4 | 2018-10-03 14:00:41 -0700 | [diff] [blame] | 1 | /* |
| 2 | // Copyright (c) 2017 2018 Intel Corporation |
| 3 | // |
| 4 | // Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | // you may not use this file except in compliance with the License. |
| 6 | // You may obtain a copy of the License at |
| 7 | // |
| 8 | // http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | // |
| 10 | // Unless required by applicable law or agreed to in writing, software |
| 11 | // distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | // See the License for the specific language governing permissions and |
| 14 | // limitations under the License. |
| 15 | */ |
| 16 | |
| 17 | #pragma once |
Vernon Mauery | e035c58 | 2023-06-06 15:15:14 -0700 | [diff] [blame] | 18 | #include <ipmid/api-types.hpp> |
| 19 | #include <ipmid/api.hpp> |
Jason M. Bills | 3f7c5e4 | 2018-10-03 14:00:41 -0700 | [diff] [blame] | 20 | |
James Feist | fcd2d3a | 2020-05-28 10:38:15 -0700 | [diff] [blame] | 21 | #include <cstdint> |
| 22 | |
Jason M. Bills | 3f7c5e4 | 2018-10-03 14:00:41 -0700 | [diff] [blame] | 23 | static constexpr uint8_t ipmiSdrVersion = 0x51; |
| 24 | |
Jason M. Bills | c04e2e7 | 2018-11-28 15:15:56 -0800 | [diff] [blame] | 25 | namespace intel_oem::ipmi::sel |
| 26 | { |
Jason M. Bills | c04e2e7 | 2018-11-28 15:15:56 -0800 | [diff] [blame] | 27 | static constexpr uint8_t selOperationSupport = 0x02; |
| 28 | static constexpr uint8_t systemEvent = 0x02; |
| 29 | static constexpr size_t systemEventSize = 3; |
| 30 | static constexpr uint8_t oemTsEventFirst = 0xC0; |
| 31 | static constexpr uint8_t oemTsEventLast = 0xDF; |
| 32 | static constexpr size_t oemTsEventSize = 9; |
| 33 | static constexpr uint8_t oemEventFirst = 0xE0; |
| 34 | static constexpr uint8_t oemEventLast = 0xFF; |
| 35 | static constexpr size_t oemEventSize = 13; |
| 36 | static constexpr uint8_t eventMsgRev = 0x04; |
| 37 | } // namespace intel_oem::ipmi::sel |
| 38 | |
Vernon Mauery | e035c58 | 2023-06-06 15:15:14 -0700 | [diff] [blame] | 39 | ////////////////////////////////////////////////////////////////////////////// |
| 40 | // |
| 41 | // blurbs from ipmi-host/sensorhandler.hpp |
| 42 | // |
| 43 | ////////////////////////////////////////////////////////////////////////////// |
| 44 | static constexpr int FULL_RECORD_ID_STR_MAX_LENGTH = 16; |
| 45 | namespace get_sdr |
| 46 | { |
| 47 | // Record header |
| 48 | struct SensorDataRecordHeader |
| 49 | { |
| 50 | uint8_t record_id_lsb; |
| 51 | uint8_t record_id_msb; |
| 52 | uint8_t sdr_version; |
| 53 | uint8_t record_type; |
| 54 | uint8_t record_length; // Length not counting the header |
| 55 | } __attribute__((packed)); |
| 56 | |
| 57 | namespace header |
| 58 | { |
| 59 | |
| 60 | inline void set_record_id(int id, SensorDataRecordHeader* hdr) |
| 61 | { |
| 62 | hdr->record_id_lsb = (id & 0xFF); |
| 63 | hdr->record_id_msb = (id >> 8) & 0xFF; |
| 64 | }; |
| 65 | |
| 66 | } // namespace header |
| 67 | |
| 68 | /** @struct SensorDataFruRecordKey |
| 69 | * |
| 70 | * FRU Device Locator Record(key) - SDR Type 11 |
| 71 | */ |
| 72 | struct SensorDataFruRecordKey |
| 73 | { |
| 74 | uint8_t deviceAddress; |
| 75 | uint8_t fruID; |
| 76 | uint8_t accessLun; |
| 77 | uint8_t channelNumber; |
| 78 | } __attribute__((packed)); |
| 79 | |
| 80 | static constexpr int FRU_RECORD_DEVICE_ID_MAX_LENGTH = 16; |
| 81 | |
| 82 | /** @struct SensorDataFruRecordBody |
| 83 | * |
| 84 | * FRU Device Locator Record(body) - SDR Type 11 |
| 85 | */ |
| 86 | struct SensorDataFruRecordBody |
| 87 | { |
| 88 | uint8_t reserved; |
| 89 | uint8_t deviceType; |
| 90 | uint8_t deviceTypeModifier; |
| 91 | uint8_t entityID; |
| 92 | uint8_t entityInstance; |
| 93 | uint8_t oem; |
| 94 | uint8_t deviceIDLen; |
| 95 | char deviceID[FRU_RECORD_DEVICE_ID_MAX_LENGTH]; |
| 96 | } __attribute__((packed)); |
| 97 | |
| 98 | /** @struct SensorDataFruRecord |
| 99 | * |
| 100 | * FRU Device Locator Record - SDR Type 11 |
| 101 | */ |
| 102 | struct SensorDataFruRecord |
| 103 | { |
| 104 | SensorDataRecordHeader header; |
| 105 | SensorDataFruRecordKey key; |
| 106 | SensorDataFruRecordBody body; |
| 107 | } __attribute__((packed)); |
| 108 | |
| 109 | enum SensorDataRecordType |
| 110 | { |
| 111 | SENSOR_DATA_FULL_RECORD = 0x1, |
| 112 | SENSOR_DATA_EVENT_RECORD = 0x3, |
| 113 | SENSOR_DATA_FRU_RECORD = 0x11, |
| 114 | SENSOR_DATA_ENTITY_RECORD = 0x8, |
| 115 | }; |
| 116 | |
| 117 | // Record key |
| 118 | struct SensorDataRecordKey |
| 119 | { |
| 120 | uint8_t owner_id; |
| 121 | uint8_t owner_lun; |
| 122 | uint8_t sensor_number; |
| 123 | } __attribute__((packed)); |
| 124 | |
| 125 | struct SensorDataFullRecordBody |
| 126 | { |
| 127 | uint8_t entity_id; |
| 128 | uint8_t entity_instance; |
| 129 | uint8_t sensor_initialization; |
| 130 | uint8_t sensor_capabilities; // no macro support |
| 131 | uint8_t sensor_type; |
| 132 | uint8_t event_reading_type; |
| 133 | uint8_t supported_assertions[2]; // no macro support |
| 134 | uint8_t supported_deassertions[2]; // no macro support |
| 135 | uint8_t discrete_reading_setting_mask[2]; // no macro support |
| 136 | uint8_t sensor_units_1; |
| 137 | uint8_t sensor_units_2_base; |
| 138 | uint8_t sensor_units_3_modifier; |
| 139 | uint8_t linearization; |
| 140 | uint8_t m_lsb; |
| 141 | uint8_t m_msb_and_tolerance; |
| 142 | uint8_t b_lsb; |
| 143 | uint8_t b_msb_and_accuracy_lsb; |
| 144 | uint8_t accuracy_and_sensor_direction; |
| 145 | uint8_t r_b_exponents; |
| 146 | uint8_t analog_characteristic_flags; // no macro support |
| 147 | uint8_t nominal_reading; |
| 148 | uint8_t normal_max; |
| 149 | uint8_t normal_min; |
| 150 | uint8_t sensor_max; |
| 151 | uint8_t sensor_min; |
| 152 | uint8_t upper_nonrecoverable_threshold; |
| 153 | uint8_t upper_critical_threshold; |
| 154 | uint8_t upper_noncritical_threshold; |
| 155 | uint8_t lower_nonrecoverable_threshold; |
| 156 | uint8_t lower_critical_threshold; |
| 157 | uint8_t lower_noncritical_threshold; |
| 158 | uint8_t positive_threshold_hysteresis; |
| 159 | uint8_t negative_threshold_hysteresis; |
| 160 | uint16_t reserved; |
| 161 | uint8_t oem_reserved; |
| 162 | uint8_t id_string_info; |
| 163 | char id_string[FULL_RECORD_ID_STR_MAX_LENGTH]; |
| 164 | } __attribute__((packed)); |
| 165 | |
| 166 | struct SensorDataFullRecord |
| 167 | { |
| 168 | SensorDataRecordHeader header; |
| 169 | SensorDataRecordKey key; |
| 170 | SensorDataFullRecordBody body; |
| 171 | } __attribute__((packed)); |
| 172 | |
| 173 | namespace body |
| 174 | { |
| 175 | inline void set_id_strlen(uint8_t len, SensorDataFullRecordBody* body) |
| 176 | { |
| 177 | body->id_string_info &= ~(0x1f); |
| 178 | body->id_string_info |= len & 0x1f; |
| 179 | }; |
| 180 | inline void set_id_type(uint8_t type, SensorDataFullRecordBody* body) |
| 181 | { |
| 182 | body->id_string_info &= ~(3 << 6); |
| 183 | body->id_string_info |= (type & 0x3) << 6; |
| 184 | }; |
| 185 | } // namespace body |
| 186 | } // namespace get_sdr |
| 187 | ////////////////////////////////////////////////////////////////////////////// |
| 188 | // |
| 189 | // <end> blurbs from ipmi-host/sensorhandler.hpp |
| 190 | // |
| 191 | ////////////////////////////////////////////////////////////////////////////// |
| 192 | |
| 193 | ////////////////////////////////////////////////////////////////////////////// |
| 194 | // |
| 195 | // blurbs from ipmi-host/selutility.hpp |
| 196 | // |
| 197 | ////////////////////////////////////////////////////////////////////////////// |
| 198 | namespace ipmi::sel |
| 199 | { |
| 200 | static constexpr auto firstEntry = 0x0000; |
| 201 | static constexpr auto lastEntry = 0xFFFF; |
| 202 | static constexpr auto entireRecord = 0xFF; |
| 203 | static constexpr auto selVersion = 0x51; |
| 204 | static constexpr auto invalidTimeStamp = 0xFFFFFFFF; |
| 205 | static constexpr auto getEraseStatus = 0x00; |
| 206 | static constexpr auto eraseComplete = 0x01; |
| 207 | static constexpr auto initiateErase = 0xAA; |
| 208 | |
| 209 | } // namespace ipmi::sel |
| 210 | ////////////////////////////////////////////////////////////////////////////// |
| 211 | // |
| 212 | // <end> blurbs from ipmi-host/selutility.hpp |
| 213 | // |
| 214 | ////////////////////////////////////////////////////////////////////////////// |
| 215 | |
Jason M. Bills | 3f7c5e4 | 2018-10-03 14:00:41 -0700 | [diff] [blame] | 216 | #pragma pack(push, 1) |
Jason M. Bills | 3f7c5e4 | 2018-10-03 14:00:41 -0700 | [diff] [blame] | 217 | struct GetSDRReq |
| 218 | { |
| 219 | uint16_t reservationID; |
| 220 | uint16_t recordID; |
| 221 | uint8_t offset; |
| 222 | uint8_t bytesToRead; |
| 223 | }; |
| 224 | #pragma pack(pop) |
| 225 | |
| 226 | enum class SdrRepositoryInfoOps : uint8_t |
| 227 | { |
| 228 | allocCommandSupported = 0x1, |
| 229 | reserveSDRRepositoryCommandSupported = 0x2, |
| 230 | partialAddSDRSupported = 0x4, |
| 231 | deleteSDRSupported = 0x8, |
| 232 | reserved = 0x10, |
| 233 | modalLSB = 0x20, |
| 234 | modalMSB = 0x40, |
| 235 | overflow = 0x80 |
| 236 | }; |
| 237 | |
Jason M. Bills | e2d1aee | 2018-10-03 15:57:18 -0700 | [diff] [blame] | 238 | enum class GetFRUAreaAccessType : uint8_t |
| 239 | { |
| 240 | byte = 0x0, |
| 241 | words = 0x1 |
| 242 | }; |
| 243 | |
Jason M. Bills | 3f7c5e4 | 2018-10-03 14:00:41 -0700 | [diff] [blame] | 244 | enum class SensorUnits : uint8_t |
| 245 | { |
| 246 | unspecified = 0x0, |
| 247 | degreesC = 0x1, |
| 248 | volts = 0x4, |
| 249 | amps = 0x5, |
| 250 | watts = 0x6, |
| 251 | rpm = 0x12, |
| 252 | }; |
| 253 | |
Jason M. Bills | e2d1aee | 2018-10-03 15:57:18 -0700 | [diff] [blame] | 254 | #pragma pack(push, 1) |
James Feist | 74c50c6 | 2019-08-14 14:18:41 -0700 | [diff] [blame] | 255 | struct Type12Record |
| 256 | { |
| 257 | get_sdr::SensorDataRecordHeader header; |
Matt Simmering | 80d4d5f | 2023-02-15 15:18:51 -0800 | [diff] [blame] | 258 | uint8_t targetAddress; |
James Feist | 74c50c6 | 2019-08-14 14:18:41 -0700 | [diff] [blame] | 259 | uint8_t channelNumber; |
| 260 | uint8_t powerStateNotification; |
| 261 | uint8_t deviceCapabilities; |
Johnathan Mantey | f4d5e05 | 2021-09-22 12:58:08 -0700 | [diff] [blame] | 262 | // define reserved bytes explicitly. The uint24_t is silently expanded to |
| 263 | // uint32_t, which ruins the byte alignment required by this structure. |
| 264 | uint8_t reserved[3]; |
James Feist | 74c50c6 | 2019-08-14 14:18:41 -0700 | [diff] [blame] | 265 | uint8_t entityID; |
| 266 | uint8_t entityInstance; |
| 267 | uint8_t oem; |
| 268 | uint8_t typeLengthCode; |
| 269 | char name[16]; |
Johnathan Mantey | f4d5e05 | 2021-09-22 12:58:08 -0700 | [diff] [blame] | 270 | |
| 271 | Type12Record(uint16_t recordID, uint8_t address, uint8_t chNumber, |
| 272 | uint8_t pwrStateNotification, uint8_t capabilities, |
| 273 | uint8_t eid, uint8_t entityInst, uint8_t mfrDefined, |
| 274 | const std::string& sensorname) : |
Matt Simmering | 80d4d5f | 2023-02-15 15:18:51 -0800 | [diff] [blame] | 275 | targetAddress(address), |
Johnathan Mantey | f4d5e05 | 2021-09-22 12:58:08 -0700 | [diff] [blame] | 276 | channelNumber(chNumber), powerStateNotification(pwrStateNotification), |
| 277 | deviceCapabilities(capabilities), reserved{}, entityID(eid), |
| 278 | entityInstance(entityInst), oem(mfrDefined) |
| 279 | { |
| 280 | get_sdr::header::set_record_id(recordID, &header); |
| 281 | header.sdr_version = ipmiSdrVersion; |
| 282 | header.record_type = 0x12; |
| 283 | size_t nameLen = std::min(sensorname.size(), sizeof(name)); |
| 284 | header.record_length = sizeof(Type12Record) - |
| 285 | sizeof(get_sdr::SensorDataRecordHeader) - |
| 286 | sizeof(name) + nameLen; |
| 287 | typeLengthCode = 0xc0 | nameLen; |
| 288 | std::copy(sensorname.begin(), sensorname.begin() + nameLen, name); |
| 289 | } |
James Feist | 74c50c6 | 2019-08-14 14:18:41 -0700 | [diff] [blame] | 290 | }; |
| 291 | #pragma pack(pop) |
| 292 | |
Yong Li | fee5e4c | 2020-01-17 19:36:29 +0800 | [diff] [blame] | 293 | #pragma pack(push, 1) |
| 294 | struct NMDiscoveryRecord |
| 295 | { |
| 296 | get_sdr::SensorDataRecordHeader header; |
| 297 | uint8_t oemID0; |
| 298 | uint8_t oemID1; |
| 299 | uint8_t oemID2; |
| 300 | uint8_t subType; |
| 301 | uint8_t version; |
Matt Simmering | 80d4d5f | 2023-02-15 15:18:51 -0800 | [diff] [blame] | 302 | uint8_t targetAddress; |
Yong Li | fee5e4c | 2020-01-17 19:36:29 +0800 | [diff] [blame] | 303 | uint8_t channelNumber; |
| 304 | uint8_t healthEventSensor; |
| 305 | uint8_t exceptionEventSensor; |
| 306 | uint8_t operationalCapSensor; |
| 307 | uint8_t thresholdExceededSensor; |
| 308 | }; |
| 309 | #pragma pack(pop) |
| 310 | |
Jason M. Bills | 3f7c5e4 | 2018-10-03 14:00:41 -0700 | [diff] [blame] | 311 | namespace ipmi |
| 312 | { |
| 313 | namespace storage |
| 314 | { |
James Feist | 74c50c6 | 2019-08-14 14:18:41 -0700 | [diff] [blame] | 315 | |
Yong Li | fee5e4c | 2020-01-17 19:36:29 +0800 | [diff] [blame] | 316 | constexpr const size_t nmDiscoverySDRCount = 1; |
James Feist | 74c50c6 | 2019-08-14 14:18:41 -0700 | [diff] [blame] | 317 | constexpr const size_t type12Count = 2; |
Vernon Mauery | dcff150 | 2022-09-28 11:12:46 -0700 | [diff] [blame] | 318 | ipmi::Cc getFruSdrs(ipmi::Context::ptr& ctx, size_t index, |
| 319 | get_sdr::SensorDataFruRecord& resp); |
Jason M. Bills | 3f7c5e4 | 2018-10-03 14:00:41 -0700 | [diff] [blame] | 320 | |
Vernon Mauery | dcff150 | 2022-09-28 11:12:46 -0700 | [diff] [blame] | 321 | ipmi::Cc getFruSdrCount(ipmi::Context::ptr& ctx, size_t& count); |
James Feist | 74c50c6 | 2019-08-14 14:18:41 -0700 | [diff] [blame] | 322 | |
| 323 | std::vector<uint8_t> getType12SDRs(uint16_t index, uint16_t recordId); |
Yong Li | fee5e4c | 2020-01-17 19:36:29 +0800 | [diff] [blame] | 324 | std::vector<uint8_t> getNMDiscoverySDR(uint16_t index, uint16_t recordId); |
Jason M. Bills | 3f7c5e4 | 2018-10-03 14:00:41 -0700 | [diff] [blame] | 325 | } // namespace storage |
| 326 | } // namespace ipmi |