OpenBIC
OpenSource Bridge-IC
ipmb.h
Go to the documentation of this file.
1/*
2 * Copyright (c) Meta Platforms, Inc. and affiliates.
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#ifndef IPMB_H
18#define IPMB_H
20#include <devicetree.h>
21#include <stdio.h>
22
23#if DT_NODE_EXISTS(DT_NODELABEL(ipmb0))
24#define DEV_IPMB_0
25#endif
26
27#if DT_NODE_EXISTS(DT_NODELABEL(ipmb1))
28#define DEV_IPMB_1
29#endif
30
31#if DT_NODE_EXISTS(DT_NODELABEL(ipmb2))
32#define DEV_IPMB_2
33#endif
34
35#if DT_NODE_EXISTS(DT_NODELABEL(ipmb3))
36#define DEV_IPMB_3
37#endif
38
39#if DT_NODE_EXISTS(DT_NODELABEL(ipmb4))
40#define DEV_IPMB_4
41#endif
42
43#if DT_NODE_EXISTS(DT_NODELABEL(ipmb5))
44#define DEV_IPMB_5
45#endif
46
47#if DT_NODE_EXISTS(DT_NODELABEL(ipmb6))
48#define DEV_IPMB_6
49#endif
50
51#if DT_NODE_EXISTS(DT_NODELABEL(ipmb7))
52#define DEV_IPMB_7
53#endif
54
55#if DT_NODE_EXISTS(DT_NODELABEL(ipmb8))
56#define DEV_IPMB_8
57#endif
58
59#if DT_NODE_EXISTS(DT_NODELABEL(ipmb9))
60#define DEV_IPMB_9
61#endif
62
63#define DEBUG_IPMB 0
64
65#define SEQ_NUM 64
66#define MAX_SEQ_QUENE 15
67#define MEM_ALLOCATE_RETRY_TIME 2
68#define IPMI_DATA_MAX_LENGTH 520
69#define IPMB_REQ_HEADER_LENGTH 6
70#define IPMB_RESP_HEADER_LENGTH 7
71#define IPMI_MSG_MAX_LENGTH (IPMI_DATA_MAX_LENGTH + IPMB_RESP_HEADER_LENGTH)
72#define IPMB_TX_RETRY_TIME 5
73#define IPMB_TXQUEUE_LEN 1
74#define IPMB_RXQUEUE_LEN 2
75#define IPMB_TX_STACK_SIZE 3072
76#define IPMB_RX_STACK_SIZE 3072
77#define IPMI_HEADER_CHECKSUM_POSITION 2
78#define IPMB_NETFN_MASK 0xFC
79#define IPMB_DEST_LUN_MASK 0x03
80#define IPMB_SEQ_MASK 0xFC
81#define IPMB_SRC_LUN_MASK 0x03
82#define IPMB_RETRY_DELAY_MS 500
83#define IPMB_POLLING_TIME_MS 1
84#define IPMB_SEQ_TIMEOUT_MS 3000
85#define IPMB_SEQ_TIMEOUT_STACK_SIZE 512
86#define I2C_RETRY_TIME 5
87
88#define RESERVED_IDX 0xFF
89#define RESERVED_BUS 0xFF
90#define RESERVED_ADDRESS 0xFF
91
92#define ENABLE 1
93#define DISABLE 0
94
95#define IS_RESPONSE(msg) (msg.netfn & 0x01)
96
98 SELF = 0x0,
99 ME_IPMB = 0x01,
100 BMC_IPMB = 0x02,
102 EXP1_IPMB = 0x05,
103 SLOT1_BIC = 0x07,
104 SLOT3_BIC = 0x08,
105 BB_IPMB = 0x10,
106 EXP2_IPMB = 0x15,
107 CL_BIC_IPMB = 0x16, // Rainbow falls IPMB channel
109 GL_BIC_IPMB = 0x18, // for NF IPMB channel
110 /* 19h reserved. */
111 EXP3_IPMB = 0x25,
112 EXP4_IPMB = 0x30,
114 /* 1Bh-1Fh reserved. */
115 BMC_USB = 0x20,
116 /* 21h-39h reserved. */
117 PLDM = 0x40,
118 MCTP = 0x41,
119 MPRO_PLDM = 0x42,
121 /* 41h-4Fh reserved. */
126 /* 54h-5Fh are reserved for KCS */
128 /* 61h-6Fh are reserved for SSIF */
130};
131
136};
137
138typedef struct IPMB_config {
139 uint8_t index;
140 uint8_t interface;
141 uint8_t channel;
142 uint8_t bus;
149
151
152typedef enum ipmb_error {
164
165typedef struct ipmi_msg {
166 uint8_t dest_addr;
167 uint8_t netfn;
168 uint8_t dest_LUN;
169 uint8_t hdr_chksum;
170 uint8_t src_addr;
171 uint8_t seq_source;
172 uint8_t seq_target;
173 uint8_t seq;
174 uint8_t pldm_inst_id;
175 uint8_t InF_source;
176 uint8_t InF_target;
177 uint8_t src_LUN;
178 uint8_t cmd;
180 uint16_t data_len;
185 uint32_t timestamp;
186 uint8_t msg_chksum;
187} __attribute__((packed, aligned(4))) ipmi_msg;
188
189typedef struct ipmi_msg_cfg {
191 uint8_t retries;
193} __attribute__((packed, aligned(4))) ipmi_msg_cfg;
194
195bool pal_load_ipmb_config(void);
196bool pal_is_interface_use_ipmb(uint8_t interface_index);
197void ipmb_init(void);
200ipmb_error ipmb_read(ipmi_msg *msg, uint8_t bus);
201void ipmb_tx_suspend(uint8_t index);
202void ipmb_tx_resume(uint8_t index);
203
204void pal_encode_response_bridge_cmd(ipmi_msg *bridge_msg, ipmi_msg_cfg *current_msg_rx,
205 IPMB_config *ipmb_cfg, IPMB_config *IPMB_config_tables);
206
207#endif
Channel_Target
Definition: ipmb.h:97
@ HOST_KCS_2
Definition: ipmb.h:123
@ BMC_USB
Definition: ipmb.h:115
@ SLOT1_BIC
Definition: ipmb.h:103
@ MCTP
Definition: ipmb.h:118
@ EXP4_IPMB
Definition: ipmb.h:112
@ PLDM
Definition: ipmb.h:117
@ MPRO_PLDM
Definition: ipmb.h:119
@ EXP1_IPMB
Definition: ipmb.h:102
@ ME_IPMB
Definition: ipmb.h:99
@ HD_BIC_IPMB
Definition: ipmb.h:108
@ PEER_BMC_IPMB
Definition: ipmb.h:113
@ HOST_KCS_3
Definition: ipmb.h:124
@ HOST_KCS_4
Definition: ipmb.h:125
@ EXP2_IPMB
Definition: ipmb.h:106
@ EXP3_IPMB
Definition: ipmb.h:111
@ BMC_IPMB
Definition: ipmb.h:100
@ GL_BIC_IPMB
Definition: ipmb.h:109
@ SELF
Definition: ipmb.h:98
@ SLOT3_BIC
Definition: ipmb.h:104
@ CL_BIC_IPMB
Definition: ipmb.h:107
@ SERVER_IPMB
Definition: ipmb.h:101
@ BB_IPMB
Definition: ipmb.h:105
@ HOST_SSIF_1
Definition: ipmb.h:127
@ HOST_KCS_1
Definition: ipmb.h:122
@ SATMC_PLDM
Definition: ipmb.h:120
@ RESERVED
Definition: ipmb.h:129
void ipmb_init(void)
Interface
Definition: ipmb.h:132
@ RESERVED_IF
Definition: ipmb.h:135
@ I3C_IF
Definition: ipmb.h:134
@ I2C_IF
Definition: ipmb.h:133
ipmb_error ipmb_read(ipmi_msg *msg, uint8_t bus)
void pal_encode_response_bridge_cmd(ipmi_msg *bridge_msg, ipmi_msg_cfg *current_msg_rx, IPMB_config *ipmb_cfg, IPMB_config *IPMB_config_tables)
ipmb_error ipmb_send_response(ipmi_msg *resp, uint8_t index)
IPMB_config * IPMB_config_table
bool pal_load_ipmb_config(void)
Definition: plat_ipmb.c:38
struct IPMB_config IPMB_config
bool pal_is_interface_use_ipmb(uint8_t interface_index)
Definition: plat_ipmb.c:60
ipmb_error
Definition: ipmb.h:152
@ IPMB_ERROR_UNKNOWN
Definition: ipmb.h:154
@ IPMB_ERROR_HDR_CHECKSUM
Definition: ipmb.h:158
@ IPMB_ERROR_QUEUE_CREATION
Definition: ipmb.h:160
@ IPMB_ERROR_MSG_CHECKSUM
Definition: ipmb.h:159
@ IPMB_ERROR_INVALID_REQ
Definition: ipmb.h:157
@ IPMB_ERROR_MUTEX_LOCK
Definition: ipmb.h:162
@ IPMB_ERROR_SUCCESS
Definition: ipmb.h:153
@ IPMB_ERROR_GET_MESSAGE_QUEUE
Definition: ipmb.h:161
@ IPMB_ERROR_FAILURE
Definition: ipmb.h:155
@ IPMB_ERROR_TIMEOUT
Definition: ipmb.h:156
#define IPMI_MSG_MAX_LENGTH
Definition: ipmb.h:71
ipmb_error ipmb_send_request(ipmi_msg *req, uint8_t index)
struct ipmi_msg __attribute__((packed, aligned(4))) ipmi_msg
void ipmb_tx_suspend(uint8_t index)
void ipmb_tx_resume(uint8_t index)
Definition: ipmb.h:138
uint8_t channel
Definition: ipmb.h:141
char * rx_thread_name
Definition: ipmb.h:146
uint8_t self_address
Definition: ipmb.h:145
uint8_t bus
Definition: ipmb.h:142
uint8_t interface
Definition: ipmb.h:140
char * tx_thread_name
Definition: ipmb.h:147
bool enable_status
Definition: ipmb.h:144
uint8_t channel_target_address
Definition: ipmb.h:143
uint8_t index
Definition: ipmb.h:139
Definition: ipmb.h:189
uint8_t retries
Definition: ipmb.h:191
struct ipmi_msg_cfg * next
Definition: ipmb.h:192
ipmi_msg buffer
Definition: ipmb.h:190
Definition: ipmb.h:165
uint8_t data[IPMI_MSG_MAX_LENGTH]
Definition: ipmb.h:181
uint8_t src_addr
Definition: ipmb.h:170
uint8_t dest_LUN
Definition: ipmb.h:168
uint8_t seq_source
Definition: ipmb.h:171
uint8_t netfn
Definition: ipmb.h:167
uint32_t timestamp
Definition: ipmb.h:185
uint8_t seq
Definition: ipmb.h:173
uint8_t pldm_inst_id
Definition: ipmb.h:174
uint8_t InF_source
Definition: ipmb.h:175
uint16_t data_len
Definition: ipmb.h:180
uint8_t seq_target
Definition: ipmb.h:172
uint8_t completion_code
Definition: ipmb.h:179
uint8_t dest_addr
Definition: ipmb.h:166
uint8_t cmd
Definition: ipmb.h:178
uint8_t hdr_chksum
Definition: ipmb.h:169
uint8_t msg_chksum
Definition: ipmb.h:186
uint8_t InF_target
Definition: ipmb.h:176
uint8_t src_LUN
Definition: ipmb.h:177