blob: 652a67830aeb54788c08021902c9c21e86bc4a39 [file] [log] [blame]
Patrick Venture38e8c6e2018-10-24 09:23:35 -07001#pragma once
2
William A. Kennington IIId7f368a2019-02-07 14:54:38 -08003#include <ipmid/api.h>
Patrick Venture38e8c6e2018-10-24 09:23:35 -07004
5#include <cstdint>
William A. Kennington IIId7f368a2019-02-07 14:54:38 -08006#include <ipmid/oemrouter.hpp>
Patrick Venture38e8c6e2018-10-24 09:23:35 -07007
8using std::uint8_t;
9
10namespace oem
11{
12namespace i2c
13{
14/*
15 * Request header
16 */
17constexpr size_t requestHeaderBus = 0;
18constexpr size_t requestHeaderFlags = 1;
19constexpr size_t requestHeaderLen = 2;
20
21typedef uint8_t BusId;
22typedef uint8_t ReqFlags;
23
24constexpr ReqFlags requestFlagsUsePec = (1 << 7);
25
26/*
27 * Request step.
28 */
29constexpr size_t stepHeaderDevAndDir = 0;
30constexpr size_t stepHeaderFlags = 1;
31constexpr size_t stepHeaderParm = 2;
32constexpr size_t stepHeaderLen = 3;
33
34typedef uint8_t DevAddr;
35typedef uint8_t StepFlags;
36constexpr StepFlags stepFlagsRecvLen = (1 << 7);
37constexpr StepFlags stepFlagsNoStart = (1 << 6);
38
39// So far 2 steps suffics, so 4 should be safe.
40constexpr 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.
44constexpr size_t largestReply = 34;
45
46} // namespace i2c
47
48/**
49 * I2c is a global i2c-via-ipmi manager and IPMI handler.
50 */
51class 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