Patrick Venture | 38e8c6e | 2018-10-24 09:23:35 -0700 | [diff] [blame] | 1 | #pragma once |
| 2 | |
William A. Kennington III | d7f368a | 2019-02-07 14:54:38 -0800 | [diff] [blame] | 3 | #include <ipmid/api.h> |
Patrick Venture | 38e8c6e | 2018-10-24 09:23:35 -0700 | [diff] [blame] | 4 | |
| 5 | #include <cstdint> |
William A. Kennington III | d7f368a | 2019-02-07 14:54:38 -0800 | [diff] [blame] | 6 | #include <ipmid/oemrouter.hpp> |
Patrick Venture | 38e8c6e | 2018-10-24 09:23:35 -0700 | [diff] [blame] | 7 | |
| 8 | using std::uint8_t; |
| 9 | |
| 10 | namespace oem |
| 11 | { |
| 12 | namespace i2c |
| 13 | { |
| 14 | /* |
| 15 | * Request header |
| 16 | */ |
| 17 | constexpr size_t requestHeaderBus = 0; |
| 18 | constexpr size_t requestHeaderFlags = 1; |
| 19 | constexpr size_t requestHeaderLen = 2; |
| 20 | |
| 21 | typedef uint8_t BusId; |
| 22 | typedef uint8_t ReqFlags; |
| 23 | |
| 24 | constexpr ReqFlags requestFlagsUsePec = (1 << 7); |
| 25 | |
| 26 | /* |
| 27 | * Request step. |
| 28 | */ |
| 29 | constexpr size_t stepHeaderDevAndDir = 0; |
| 30 | constexpr size_t stepHeaderFlags = 1; |
| 31 | constexpr size_t stepHeaderParm = 2; |
| 32 | constexpr size_t stepHeaderLen = 3; |
| 33 | |
| 34 | typedef uint8_t DevAddr; |
| 35 | typedef uint8_t StepFlags; |
| 36 | constexpr StepFlags stepFlagsRecvLen = (1 << 7); |
| 37 | constexpr StepFlags stepFlagsNoStart = (1 << 6); |
| 38 | |
| 39 | // So far 2 steps suffics, so 4 should be safe. |
| 40 | constexpr size_t maxSteps = 4; |
| 41 | |
| 42 | // Currently we specify 32 byte payload limit; |
| 43 | // but for block read with PEC that entails 34 total bytes. |
| 44 | constexpr size_t largestReply = 34; |
| 45 | |
| 46 | } // namespace i2c |
| 47 | |
| 48 | /** |
| 49 | * I2c is a global i2c-via-ipmi manager and IPMI handler. |
| 50 | */ |
| 51 | class I2c |
| 52 | { |
| 53 | public: |
| 54 | /** |
| 55 | * Allows specification of the mechanism to register OEM IPMI handler. |
| 56 | * |
| 57 | * @param[in] oemRouter - A pointer to a router instance. |
| 58 | */ |
| 59 | void registerWith(Router* oemRouter); |
| 60 | |
| 61 | /** |
| 62 | * The i2c-via-ipmi commands go through this method. |
| 63 | * |
| 64 | * @param[in] cmd - the IPMI command. |
| 65 | * @param[in] reqBuf - the IPMI command buffer. |
| 66 | * @param[in,out] replyBuf - the IPMI response buffer. |
| 67 | * @param[in,out] dataLen - pointer to request length, set to reply length. |
| 68 | * @return IPMI return code. |
| 69 | */ |
| 70 | ipmi_ret_t transfer(ipmi_cmd_t cmd, const uint8_t* reqBuf, |
| 71 | uint8_t* replyBuf, size_t* dataLen); |
| 72 | }; |
| 73 | |
| 74 | } // namespace oem |