blob: 6dbac029c125982506f211bcde930cf1a3cf2e5a [file] [log] [blame]
Vernon Mauerya3702c12019-05-22 13:20:59 -07001/*
2// Copyright (c) 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#pragma once
Vernon Mauery15419dd2019-05-24 09:40:30 -070017#include <ipmid/api.hpp>
Vernon Mauerya3702c12019-05-22 13:20:59 -070018#include <sdbusplus/message.hpp>
19#include <sdbusplus/server/interface.hpp>
20
21/**
22 * @brief Response queue defines
23 */
24constexpr int responseQueueMaxSize = 20;
25
26/**
27 * @brief Ipmb misc
28 */
29constexpr uint8_t ipmbLunMask = 0x03;
30constexpr uint8_t ipmbSeqMask = 0x3F;
31constexpr uint8_t ipmbMeSlaveAddress = 0x2C;
32constexpr uint8_t ipmbMeChannelNum = 1;
33
34/**
35 * @brief Ipmb getters
36 */
37constexpr uint8_t ipmbNetFnGet(uint8_t netFnLun)
38{
39 return netFnLun >> 2;
40}
41
42constexpr uint8_t ipmbLunFromNetFnLunGet(uint8_t netFnLun)
43{
44 return netFnLun & ipmbLunMask;
45}
46
47constexpr uint8_t ipmbSeqGet(uint8_t seqNumLun)
48{
49 return seqNumLun >> 2;
50}
51
52constexpr uint8_t ipmbLunFromSeqLunGet(uint8_t seqNumLun)
53{
54 return seqNumLun & ipmbLunMask;
55}
56
57/**
58 * @brief Ipmb setters
59 */
60constexpr uint8_t ipmbNetFnLunSet(uint8_t netFn, uint8_t lun)
61{
62 return ((netFn << 2) | (lun & ipmbLunMask));
63}
64
65constexpr uint8_t ipmbSeqLunSet(uint8_t seq, uint8_t lun)
66{
67 return ((seq << 2) | (lun & ipmbLunMask));
68}
69
70constexpr size_t ipmbMaxDataSize = 256;
71constexpr size_t ipmbConnectionHeaderLength = 3;
72constexpr size_t ipmbResponseDataHeaderLength = 4;
73constexpr size_t ipmbRequestDataHeaderLength = 3;
74constexpr size_t ipmbChecksum2StartOffset = 3;
75constexpr size_t ipmbChecksumSize = 1;
76constexpr size_t ipmbMinFrameLength = 7;
77constexpr size_t ipmbMaxFrameLength = ipmbConnectionHeaderLength +
78 ipmbResponseDataHeaderLength +
79 ipmbChecksumSize + ipmbMaxDataSize;
80
81/**
82 * @brief Channel types
83 */
84constexpr uint8_t targetChannelIpmb = 0x1;
85constexpr uint8_t targetChannelIcmb10 = 0x2;
86constexpr uint8_t targetChannelIcmb09 = 0x3;
87constexpr uint8_t targetChannelLan = 0x4;
88constexpr uint8_t targetChannelSerialModem = 0x5;
89constexpr uint8_t targetChannelOtherLan = 0x6;
90constexpr uint8_t targetChannelPciSmbus = 0x7;
91constexpr uint8_t targetChannelSmbus10 = 0x8;
92constexpr uint8_t targetChannelSmbus20 = 0x9;
93constexpr uint8_t targetChannelSystemInterface = 0xC;
94
95/**
96 * @brief Channel modes
97 */
98constexpr uint8_t modeNoTracking = 0x0;
99constexpr uint8_t modeTrackRequest = 0x1;
100constexpr uint8_t modeSendRaw = 0x2;
101
102/**
Vernon Mauerya3702c12019-05-22 13:20:59 -0700103 * @brief Ipmb frame
104 */
105typedef struct
106{
107 /// @brief IPMB frame header
108 union
109 {
110 /// @brief IPMB request header
111 struct
112 {
113 /** @brief IPMB Connection Header Format */
114 uint8_t address;
115 uint8_t rsNetFnLUN;
116 uint8_t checksum1;
117 /** @brief IPMB Header */
118 uint8_t rqSA;
119 uint8_t rqSeqLUN;
120 uint8_t cmd;
121 uint8_t data[];
122 } Req;
123 /// @brief IPMB response header
124 struct
125 {
126 uint8_t address;
127 /** @brief IPMB Connection Header Format */
128 uint8_t rqNetFnLUN;
129 uint8_t checksum1;
130 /** @brief IPMB Header */
131 uint8_t rsSA;
132 uint8_t rsSeqLUN;
133 uint8_t cmd;
134 uint8_t completionCode;
135 uint8_t data[];
136 } Resp;
137 } Header;
138} __attribute__((packed)) ipmbHeader;
139
140/**
141 * @brief Ipmb messages
142 */
143struct IpmbRequest
144{
145 uint8_t address;
146 uint8_t netFn;
147 uint8_t rsLun;
148 uint8_t rqSA;
149 uint8_t seq;
150 uint8_t rqLun;
151 uint8_t cmd;
152 std::vector<uint8_t> data;
153
154 IpmbRequest(const ipmbHeader *ipmbBuffer, size_t bufferLength);
155
156 void prepareRequest(sdbusplus::message::message &mesg);
157};
158
159struct IpmbResponse
160{
161 uint8_t address;
162 uint8_t netFn;
163 uint8_t rqLun;
164 uint8_t rsSA;
165 uint8_t seq;
166 uint8_t rsLun;
167 uint8_t cmd;
168 uint8_t completionCode;
169 std::vector<uint8_t> data;
170
171 IpmbResponse(uint8_t address, uint8_t netFn, uint8_t rqLun, uint8_t rsSA,
172 uint8_t seq, uint8_t rsLun, uint8_t cmd,
173 uint8_t completionCode, std::vector<uint8_t> &inputData);
174
175 void ipmbToi2cConstruct(uint8_t *buffer, size_t *bufferLength);
176};
177
178/**
Vernon Mauerya3702c12019-05-22 13:20:59 -0700179 * @brief Get Message Flags Response
180 */
Yong Lic3580e92019-08-15 14:36:47 +0800181constexpr uint8_t getMsgFlagReceiveMessageBit = 0;
182constexpr uint8_t getMsgFlagEventMessageBit = 1;
183constexpr uint8_t getMsgFlagWatchdogPreTimeOutBit = 3;
184constexpr uint8_t getMsgFlagOEM0Bit = 5;
185constexpr uint8_t getMsgFlagOEM1Bit = 6;
186constexpr uint8_t getMsgFlagOEM2Bit = 7;
Vernon Mauerya3702c12019-05-22 13:20:59 -0700187
Vernon Mauerya3702c12019-05-22 13:20:59 -0700188/** @class Bridging
189 *
190 * @brief Implement commands to support IPMI bridging.
191 */
192class Bridging
193{
194 public:
Vernon Mauery15419dd2019-05-24 09:40:30 -0700195 Bridging() = default;
Yong Lic3580e92019-08-15 14:36:47 +0800196 std::size_t getResponseQueueSize();
Vernon Mauerya3702c12019-05-22 13:20:59 -0700197
jayaprakash Mutyala405f54a2019-10-18 18:23:27 +0000198 void clearResponseQueue();
199
Deepak Kumar Sahu24d2d562019-07-14 16:05:19 +0000200 ipmi::Cc handleIpmbChannel(const uint8_t tracking,
201 const std::vector<uint8_t> &msgData,
202 std::vector<uint8_t> &rspData);
Vernon Mauerya3702c12019-05-22 13:20:59 -0700203
Deepak Kumar Sahu24d2d562019-07-14 16:05:19 +0000204 void insertMessageInQueue(IpmbResponse msg);
205
206 IpmbResponse getMessageFromQueue();
207
208 void eraseMessageFromQueue();
Vernon Mauerya3702c12019-05-22 13:20:59 -0700209
210 private:
211 std::vector<IpmbResponse> responseQueue;
Vernon Mauerya3702c12019-05-22 13:20:59 -0700212};