OpenBIC
OpenSource Bridge-IC
ssif.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 SSIF_H
18#define SSIF_H
19
20#include "plat_def.h"
21#ifdef ENABLE_SSIF
22
23#include <stdbool.h>
24#include <stdint.h>
25#include <zephyr.h>
26#include "ipmb.h"
27#include "hal_i2c_target.h"
28
29#define SSIF_THREAD_STACK_SIZE 4096
30#define SSIF_POLLING_INTERVAL 100
31#define SSIF_MAX_IPMI_DATA_SIZE 32
32#define SSIF_BUFF_SIZE 50
33
34#define SSIF_TASK_NAME_LEN 32
35
36#define SSIF_MULTI_RD_KEY 0x0001
37
38#define CMD_SYS_INFO_FW_VERSION 0x01
39
40#define SSIF_ERR_RCD_SIZE 100
41
42typedef enum ssif_status {
43 SSIF_STATUS_WAIT_FOR_WR_START,
44 SSIF_STATUS_WAIT_FOR_WR_NEXT,
45 SSIF_STATUS_WAIT_FOR_RD_START,
46 SSIF_STATUS_WAIT_FOR_RD_NEXT,
47
48 SSIF_STATUS_WR_SINGLE_START = 0x10,
49 SSIF_STATUS_WR_MULTI_START,
50 SSIF_STATUS_WR_MIDDLE,
51 SSIF_STATUS_WR_END,
52
53 SSIF_STATUS_RD_START = 0x20,
54 SSIF_STATUS_RD_MIDDLE,
55 SSIF_STATUS_RD_RETRY,
56 SSIF_STATUS_RD_END,
57} ssif_status_t;
58
59typedef enum ssif_err_status {
60 SSIF_STATUS_NO_ERR,
61 SSIF_STATUS_INVALID_CMD,
62 SSIF_STATUS_INVALID_CMD_IN_CUR_STATUS,
63 SSIF_STATUS_INVALID_PEC,
64 SSIF_STATUS_INVALID_LEN,
65 SSIF_STATUS_ADDR_LCK_TIMEOUT, // Address lock timeout
66 SSIF_STATUS_ADDR_LOCK_ERR, // Address lock lock/unlock error
67 SSIF_STATUS_MUTEX_ERR, // Mutex error in ssif set data
68 SSIF_STATUS_RSP_MSG_TIMEOUT, // Failed to send out msg or receive response msg
69 SSIF_STATUS_RSP_NOT_READY, // Can't get response msg while data collect
70 SSIF_STATUS_TARGET_WR_RD_ERROR, // I2C target write read error
71 SSIF_STATUS_UNKNOWN_ERR = 0xFF,
72} ssif_err_status_t;
73
74enum ssif_cmd {
75 SSIF_WR_SINGLE = 0x02,
76 SSIF_WR_MULTI_START = 0x06,
77 SSIF_WR_MULTI_MIDDLE = 0x07,
78 SSIF_WR_MULTI_END = 0x08,
79
80 SSIF_RD_START = 0x03, // SINGLE/MULTI
81 SSIF_RD_NEXT = 0x09, // MIDDLE/END
82 SSIF_RD_RETRY = 0x0A,
83};
84
85typedef enum ssif_action {
86 SSIF_SEND_IPMI,
87 SSIF_COLLECT_DATA,
88} ssif_action_t;
89
90struct ssif_init_cfg {
91 uint8_t i2c_bus;
92 uint8_t addr; // bic itself, 7bit
93 uint8_t target_msgq_cnt; // maximum msg count for target msg queue
94};
95
96typedef struct _ssif_dev {
97 uint8_t index;
98 uint8_t i2c_bus;
99 uint8_t addr; // bic itself, 7bit
100 bool addr_lock;
101 int64_t exp_to_ms;
102 k_tid_t ssif_task_tid;
103 K_KERNEL_STACK_MEMBER(ssif_task_stack, SSIF_THREAD_STACK_SIZE);
104 uint8_t task_name[SSIF_TASK_NAME_LEN];
105 struct k_thread task_thread;
106 struct k_mutex rsp_buff_mutex;
107 struct k_sem rsp_buff_sem;
108 uint8_t rsp_buff[IPMI_MSG_MAX_LENGTH];
109 uint16_t rsp_buf_len; // Length of collected data
110 uint16_t remain_data_len; // Length of remain data
111 ipmi_msg_cfg current_ipmi_msg;
112 uint16_t cur_rd_blck; // for multi-read middle/end
113
114 ssif_status_t cur_status;
115 ssif_err_status_t err_status_lst[SSIF_ERR_RCD_SIZE]; // history error status
116 uint8_t err_idx; //
117 ssif_err_status_t err_status; // last error status
118} ssif_dev;
119
120struct ssif_wr_start {
121 uint8_t len;
122 uint8_t netfn; // netfn(6bit) + lun(2bit)
123 uint8_t cmd;
124 uint8_t data[SSIF_MAX_IPMI_DATA_SIZE - 2]; // -netfn -cmd
125} __attribute__((packed));
126
127struct ssif_wr_middle {
128 uint8_t len;
129 uint8_t data[SSIF_MAX_IPMI_DATA_SIZE];
130} __attribute__((packed));
131
132struct ssif_rd_single {
133 uint8_t len;
134 uint8_t netfn; // netfn(6bit) + lun(2bit)
135 uint8_t cmd;
136 uint8_t cmplt_code;
137 uint8_t data[SSIF_MAX_IPMI_DATA_SIZE - 3]; // -netfn -cmd -cc
138} __attribute__((packed));
139
140struct ssif_rd_start {
141 uint8_t len;
142 uint16_t start_key; // should equal 0x0001
143 uint8_t netfn; // netfn(6bit) + lun(2bit)
144 uint8_t cmd;
145 uint8_t cmplt_code;
146 uint8_t data[SSIF_MAX_IPMI_DATA_SIZE - 5]; // -netfn -cmd -cc -key(2bytes)
147} __attribute__((packed));
148
149struct ssif_rd_middle {
150 uint8_t len;
151 uint8_t block;
152 uint8_t data[0];
153} __attribute__((packed));
154
155void ssif_device_init(struct ssif_init_cfg *config, uint8_t size);
156ssif_err_status_t ssif_get_error_status();
157bool ssif_set_data(uint8_t channel, ipmi_msg_cfg *msg_cfg);
158void ssif_error_record(uint8_t channel, ssif_err_status_t errcode);
159ssif_dev *ssif_inst_get_by_bus(uint8_t bus);
160void pal_ssif_alert_trigger(uint8_t status);
163bool get_ssif_ok();
164void reset_ssif_ok();
165
166#endif /* ENABLE_SSIF */
167
168#endif /* SSIF_H */
K_KERNEL_STACK_MEMBER(wdt_thread_stack, WDT_THREAD_STACK_SIZE)
uint8_t netfn
Definition: ipmb.h:1
#define IPMI_MSG_MAX_LENGTH
Definition: ipmb.h:71
uint8_t cmd
Definition: isl69259.c:1
uint8_t data[]
Definition: isl69259.c:2
uint8_t addr
Definition: isl69259.c:0
typedef __attribute__
Definition: mctp_ctrl.h:109
uint8_t status
Definition: mctp_ctrl.h:1
uint16_t size
Definition: pldm_oem.h:0
Definition: ipmb.h:189
Definition: ipmb.h:165
void pal_ssif_alert_trigger(uint8_t status)
Definition: plat_ssif.c:29
void pal_add_sel_handler(ipmi_msg *msg)
Definition: plat_ssif.c:60
void pal_bios_post_complete()
Definition: plat_ssif.c:49