blob: d5639328df4471c0de3a58c6c03c31912134063f [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>
Willy Tu87a8b112021-12-13 22:26:56 -08006#include <ipmid/api-types.hpp>
7#include <ipmid/message.hpp>
8#include <span>
9#include <vector>
Patrick Venture38e8c6e2018-10-24 09:23:35 -070010
11using std::uint8_t;
12
13namespace oem
14{
15namespace i2c
16{
17/*
18 * Request header
19 */
20constexpr size_t requestHeaderBus = 0;
21constexpr size_t requestHeaderFlags = 1;
22constexpr size_t requestHeaderLen = 2;
23
24typedef uint8_t BusId;
25typedef uint8_t ReqFlags;
26
27constexpr ReqFlags requestFlagsUsePec = (1 << 7);
28
29/*
30 * Request step.
31 */
32constexpr size_t stepHeaderDevAndDir = 0;
33constexpr size_t stepHeaderFlags = 1;
34constexpr size_t stepHeaderParm = 2;
35constexpr size_t stepHeaderLen = 3;
36
37typedef uint8_t DevAddr;
38typedef uint8_t StepFlags;
39constexpr StepFlags stepFlagsRecvLen = (1 << 7);
40constexpr StepFlags stepFlagsNoStart = (1 << 6);
41
42// So far 2 steps suffics, so 4 should be safe.
43constexpr size_t maxSteps = 4;
44
45// Currently we specify 32 byte payload limit;
46// but for block read with PEC that entails 34 total bytes.
47constexpr size_t largestReply = 34;
48
49} // namespace i2c
50
Willy Tu87a8b112021-12-13 22:26:56 -080051using Resp = ipmi::RspType<std::vector<uint8_t>>;
52
Patrick Venture38e8c6e2018-10-24 09:23:35 -070053/**
54 * I2c is a global i2c-via-ipmi manager and IPMI handler.
55 */
56class I2c
57{
58 public:
59 /**
Willy Tu87a8b112021-12-13 22:26:56 -080060 * Register OEM IPMI handler.
Patrick Venture38e8c6e2018-10-24 09:23:35 -070061 */
Willy Tu87a8b112021-12-13 22:26:56 -080062 void registerOemRouter();
Patrick Venture38e8c6e2018-10-24 09:23:35 -070063
64 /**
65 * The i2c-via-ipmi commands go through this method.
66 *
Willy Tu87a8b112021-12-13 22:26:56 -080067 * @param[in] ctx - IPMI Request Context.
68 * @param[in] data - Request Data.
69 * @return IPMI response.
Patrick Venture38e8c6e2018-10-24 09:23:35 -070070 */
Willy Tu87a8b112021-12-13 22:26:56 -080071 Resp transfer(ipmi::Context::ptr ctx, std::span<const uint8_t> data);
Patrick Venture38e8c6e2018-10-24 09:23:35 -070072};
73
74} // namespace oem