Skip to content

sb: sitv3: integrate slot-based configuration #2476

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 9 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 46 additions & 1 deletion meta-facebook/sb-si/src/platform/plat_class.c
Original file line number Diff line number Diff line change
Expand Up @@ -25,15 +25,26 @@
#include "plat_pldm_sensor.h"
#include "hal_i3c.h"
#include "plat_i3c.h"
#include <drivers/flash.h>

LOG_MODULE_REGISTER(plat_class);

#define I2C_BUS_TMP I2C_BUS1
#define TMP_EMC1413_SMSC_ID_DEFAULT 0x5D
#define INVALID_SLOT_ID 0xFF

uint16_t BIC_PID = PLAT_DEFAULT_PID;

static uint8_t vr_type = VR_UNKNOWN;
static uint8_t tmp_type = TMP_TYPE_UNKNOWN;

const mmc_info_t mmc_info_table[MAX_SLOT] = {
{ .slot = 0, .eid = MCTP_DEFAULT_ENDPOINT, .pid = PLAT_DEFAULT_PID },
{ .slot = 1, .eid = 0x14, .pid = 0x520 },
{ .slot = 2, .eid = 0x1E, .pid = 0x530 },
{ .slot = 3, .eid = 0x28, .pid = 0x540 },
};

void init_vr_vendor_type(void)
{
I2C_MSG i2c_msg = { 0 };
Expand Down Expand Up @@ -91,7 +102,41 @@ void init_platform_config()

void plat_i3c_set_pid()
{
I3C_MSG i3c_msg;
uint8_t slot_id = get_slot_id();

if (slot_id < MAX_SLOT) {
BIC_PID = mmc_info_table[slot_id].pid;
LOG_INF("Slot ID %d valid, set BIC_PID = 0x%02x", slot_id, BIC_PID);
} else {
LOG_WRN("Invalid slot ID (%d), keep default BIC_PID = 0x%02x", slot_id, BIC_PID);
}

I3C_MSG i3c_msg = { 0 };
i3c_msg.bus = I3C_BUS6;
i3c_set_pid(&i3c_msg, BIC_PID);
}

uint8_t get_slot_id()
{
const struct device *flash_dev = device_get_binding("spi_spim0_cs0");
if (!flash_dev) {
LOG_ERR("Failed to get flash device for slot ID.");
return INVALID_SLOT_ID;
}

uint8_t slot_id = INVALID_SLOT_ID;
uint32_t op_addr = FLASH_SLOT_ADDRESS;

if (flash_read(flash_dev, op_addr, &slot_id, 1) != 0) {
LOG_ERR("Failed to read slot ID from flash at 0x%x", op_addr);
return INVALID_SLOT_ID;
}

if (slot_id >= MAX_SLOT) {
LOG_ERR("Slot ID read from flash is invalid: %d", slot_id);
return INVALID_SLOT_ID;
}

LOG_INF("Read slot ID %d from flash", slot_id);
return slot_id;
}
13 changes: 13 additions & 0 deletions meta-facebook/sb-si/src/platform/plat_class.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@
#ifndef PLAT_CLASS_H
#define PLAT_CLASS_H

#define MAX_SLOT 4
#define FLASH_SLOT_ADDRESS 0x0FF000
#define FLASH_SECTOR 0x1000

typedef enum {
VR_MPS_MP2971_MP2891,
VR_MPS_MP2971_MP29816A,
Expand All @@ -25,6 +29,14 @@ typedef enum {
VR_UNKNOWN,
} si_vr_type_t;

typedef struct {
uint8_t slot;
uint8_t eid;
uint16_t pid;
} mmc_info_t;

extern const mmc_info_t mmc_info_table[MAX_SLOT];

typedef enum {
TMP_TMP432,
TMP_EMC1413,
Expand All @@ -36,5 +48,6 @@ void init_tmp_type();
uint8_t get_vr_type();
uint8_t get_tmp_type();
void plat_i3c_set_pid();
uint8_t get_slot_id();

#endif
1 change: 1 addition & 0 deletions meta-facebook/sb-si/src/platform/plat_def.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
#define ENABLE_PLDM_SENSOR
#define MCTP_SMBUS_WRITE_MAX_RETRY 4
#define RAA229621_MAX_CMD_LINE 1500
#define PLDM_MSG_TIMEOUT_MS 5000

#define MAX_AUX_SENSOR_NAME_LEN 42

Expand Down
2 changes: 1 addition & 1 deletion meta-facebook/sb-si/src/platform/plat_gpio.c
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ GPIO_CFG plat_gpio_cfg[] = {
NULL },
{ CHIP_GPIO, 65, DISABLE, DISABLE, GPIO_INPUT, GPIO_HIGH, OPEN_DRAIN, GPIO_INT_EDGE_BOTH,
NULL },
{ CHIP_GPIO, 66, DISABLE, DISABLE, GPIO_OUTPUT, GPIO_LOW, PUSH_PULL, GPIO_INT_DISABLE,
{ CHIP_GPIO, 66, ENABLE, DISABLE, GPIO_OUTPUT, GPIO_LOW, PUSH_PULL, GPIO_INT_DISABLE,
NULL },
{ CHIP_GPIO, 67, DISABLE, DISABLE, GPIO_INPUT, GPIO_LOW, PUSH_PULL, GPIO_INT_DISABLE,
NULL },
Expand Down
110 changes: 78 additions & 32 deletions meta-facebook/sb-si/src/platform/plat_i2c_target.c
Original file line number Diff line number Diff line change
Expand Up @@ -30,15 +30,16 @@
#include <logging/log.h>
#include "plat_i2c_target.h"
#include "plat_mctp.h"
#include "plat_class.h"
#include <drivers/flash.h>

LOG_MODULE_REGISTER(plat_i2c_target);

static bool command_reply_data_handle(void *arg);
static void command_set_eid_handle(void *arg);
void set_eid_handle(struct k_work *work);
void plat_set_eid_init(int slot_id);
K_WORK_DELAYABLE_DEFINE(set_eid_work, set_eid_handle);
static void command_set_slot_handle(void *arg);
void set_slot_handle(struct k_work *work);
void plat_set_slot_init(int slot_id);
K_WORK_DELAYABLE_DEFINE(set_slot_work, set_slot_handle);

/* I2C target init-enable table */
const bool I2C_TARGET_ENABLE_TABLE[MAX_TARGET_NUM] = {
Expand All @@ -54,23 +55,58 @@ const struct _i2c_target_config I2C_TARGET_CONFIG_TABLE[MAX_TARGET_NUM] = {
{ 0xFF, 0xA },
{ 0x40, 0xA },
{ 0xFF, 0xA },
{ 0x40, 0xA, command_reply_data_handle },
{ 0x40, 0xA },
{ 0xFF, 0xA },
{ 0xFF, 0xA },
{ 0xFF, 0xA },
{ 0xFF, 0xA },
{ 0x42, 0xA, NULL, command_set_eid_handle },
{ 0x42, 0xA, command_reply_data_handle, command_set_slot_handle },
{ 0xFF, 0xA },
};

static bool command_reply_data_handle(void *arg)
{
/*TODO: put board telemetry here*/
struct i2c_target_data *data = (struct i2c_target_data *)arg;

if (data->wr_buffer_idx < 1) {
LOG_ERR("No register offset received before read");
data->target_rd_msg.msg_length = 1;
data->target_rd_msg.msg[0] = 0xFF;
return false;
}

uint8_t reg_offset = data->target_wr_msg.msg[0];

switch (reg_offset) {
case GET_MMC_INFO_REG: {
uint8_t slot = get_slot_id();
if (slot == 0xFF) {
data->target_rd_msg.msg_length = 1;
data->target_rd_msg.msg[0] = 0xFF;
return false;
}

uint8_t eid = plat_get_eid();

data->target_rd_msg.msg_length = 2;
data->target_rd_msg.msg[0] = slot;
data->target_rd_msg.msg[1] = eid;

return false;
LOG_DBG("Reply SLOT=%d, EID=%d", slot, eid);
break;
}

default:
LOG_WRN("Unsupported read register: 0x%02x", reg_offset);
data->target_rd_msg.msg_length = 1;
data->target_rd_msg.msg[0] = 0xFF;
break;
}

return true;
}

static void command_set_eid_handle(void *arg)
static void command_set_slot_handle(void *arg)
{
struct i2c_target_data *data = (struct i2c_target_data *)arg;
data->skip_msg_wr = true;
Expand All @@ -84,20 +120,25 @@ static void command_set_eid_handle(void *arg)

if (data->wr_buffer_idx == 1) {
uint8_t reg_offset = data->target_wr_msg.msg[0];
const mmc_info_t *cfg = &mmc_info_table[0];
LOG_INF("Received reg_offset: 0x%02x", reg_offset);

switch (reg_offset) {
case SLOT_0_I2C_SET_EID_REG:
plat_set_eid_init(0);
case SLOT_0_I2C_SET_SLOT_REG:
cfg = &mmc_info_table[0];
plat_set_slot_init(cfg->slot);
break;
case SLOT_1_I2C_SET_EID_REG:
plat_set_eid_init(1);
case SLOT_1_I2C_SET_SLOT_REG:
cfg = &mmc_info_table[1];
plat_set_slot_init(cfg->slot);
break;
case SLOT_2_I2C_SET_EID_REG:
plat_set_eid_init(2);
case SLOT_2_I2C_SET_SLOT_REG:
cfg = &mmc_info_table[2];
plat_set_slot_init(cfg->slot);
break;
case SLOT_3_I2C_SET_EID_REG:
plat_set_eid_init(3);
case SLOT_3_I2C_SET_SLOT_REG:
cfg = &mmc_info_table[3];
plat_set_slot_init(cfg->slot);
break;
default:
LOG_ERR("Unknown reg offset: 0x%02x", reg_offset);
Expand All @@ -114,14 +155,20 @@ static void command_set_eid_handle(void *arg)
return;
}

void set_eid_handle(struct k_work *work)
void set_slot_handle(struct k_work *work)
{
struct mmc_info *info = CONTAINER_OF(work, struct mmc_info, set_eid_work);
mmc_work_info_t *info = CONTAINER_OF(work, mmc_work_info_t, set_slot_work);
uint8_t slot = info->slot;
uint8_t eid = eid_table[slot];
uint32_t op_addr = EID_ADDRESS;
uint8_t eid = mmc_info_table[slot].eid;

if (slot >= MAX_SLOT) {
LOG_ERR("Invalid slot_id: %d", slot);
free(info);
return;
}
uint32_t op_addr = FLASH_SLOT_ADDRESS;
uint32_t erase_sz = FLASH_SECTOR;
uint8_t write_buf = eid;
uint8_t write_buf = slot;
uint8_t read_back_buf = 0xFF;
uint32_t ret = 0;

Expand All @@ -131,11 +178,6 @@ void set_eid_handle(struct k_work *work)
return;
}

LOG_INF("Setting EID %d for slot %d", eid, slot);

plat_set_eid(eid);
LOG_INF("EID after set: %d", plat_get_eid());

const struct device *flash_dev = device_get_binding("spi_spim0_cs0");
if (!flash_dev) {
LOG_ERR("Failed to get flash device.");
Expand Down Expand Up @@ -163,27 +205,31 @@ void set_eid_handle(struct k_work *work)
LOG_ERR("Failed to read %u.\n", op_addr);
}

LOG_INF("EID:%d get from flash", read_back_buf);
LOG_INF("SLOT:%d get from flash", read_back_buf);

if (memcmp(&write_buf, &read_back_buf, 1) != 0) {
LOG_ERR("Failed to write flash at 0x%x.", op_addr);
LOG_ERR("to be written:%d", write_buf);
LOG_ERR("readback:%d", read_back_buf);
}

LOG_INF("Setting EID %d for slot %d", eid, slot);
plat_set_eid(eid);
LOG_INF("EID after set: %d", plat_get_eid());

free(info);
return;
}

void plat_set_eid_init(int slot_id)
void plat_set_slot_init(int slot_id)
{
struct mmc_info *info = malloc(sizeof(struct mmc_info));
mmc_work_info_t *info = malloc(sizeof(mmc_work_info_t));
if (!info) {
LOG_ERR("Failed to allocate memory for mmc_info");
return;
}

info->slot = slot_id;
k_work_init(&info->set_eid_work, set_eid_handle);
k_work_submit(&info->set_eid_work);
k_work_init(&info->set_slot_work, set_slot_handle);
k_work_submit(&info->set_slot_work);
}
28 changes: 9 additions & 19 deletions meta-facebook/sb-si/src/platform/plat_i2c_target.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,27 +20,17 @@
#include <drivers/i2c.h>
#include "hal_i2c_target.h"

#define MAX_SLOT 4

#define EID_ADDRESS 0x0FF000
#define FLASH_SECTOR 0x1000

static const uint8_t eid_table[MAX_SLOT] = {
10, // SLOT 0
20, // SLOT 1
30, // SLOT 2
40 // SLOT 3
};

struct mmc_info {
struct k_work set_eid_work;
typedef struct {
struct k_work set_slot_work;
int slot;
};
} mmc_work_info_t;

#define SLOT_0_I2C_SET_SLOT_REG 0x40
#define SLOT_1_I2C_SET_SLOT_REG 0x41
#define SLOT_2_I2C_SET_SLOT_REG 0x42
#define SLOT_3_I2C_SET_SLOT_REG 0x43

#define SLOT_0_I2C_SET_EID_REG 0x40
#define SLOT_1_I2C_SET_EID_REG 0x41
#define SLOT_2_I2C_SET_EID_REG 0x42
#define SLOT_3_I2C_SET_EID_REG 0x43
#define GET_MMC_INFO_REG 0x50

#define TARGET_ENABLE 1
#define TARGET_DISABLE 0
Expand Down
2 changes: 1 addition & 1 deletion meta-facebook/sb-si/src/platform/plat_i3c.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,6 @@

#define I3C_BUS_MAX_NUM 6

#define BIC_PID 0x567
#define PLAT_DEFAULT_PID 0x510

#endif
Loading
Loading