Skip to content
Open
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
3 changes: 2 additions & 1 deletion meta-facebook/yv35-rf/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# SPDX-License-Identifier: Apache-2.0
#SPDX - License - Identifier : Apache - 2.0

cmake_minimum_required(VERSION 3.13.1)

Expand Down Expand Up @@ -36,6 +36,7 @@ target_include_directories(app PRIVATE ${common_path}/service/ipmi/include)
target_include_directories(app PRIVATE ${common_path}/service/logging)
target_include_directories(app PRIVATE ${common_path}/service/mctp)
target_include_directories(app PRIVATE ${common_path}/service/pldm)
target_include_directories(app PRIVATE ${common_path}/service/cci)
target_include_directories(app PRIVATE ${common_path}/service/sensor)
target_include_directories(app PRIVATE ${common_path}/service/usb)
target_include_directories(app PRIVATE ${common_path}/shell/commands)
Expand Down
2 changes: 2 additions & 0 deletions meta-facebook/yv35-rf/src/platform/plat_def.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,7 @@
#define PLAT_DEF_H

#define BMC_USB_PORT "CDC_ACM_0"
#define ENABLE_CCI
#define ENABLE_PM8702

#endif
45 changes: 45 additions & 0 deletions meta-facebook/yv35-rf/src/platform/plat_i2c_target.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
/*
* Copyright (c) Meta Platforms, Inc. and affiliates.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

/*
NAME: I2C TARGET INIT
FILE: plat_i2c_target.c
DESCRIPTION: Provide i2c target EN/CFG table "I2C_TARGET_EN_TABLE[]/I2C_TARGET_CFG_TABLE[]" for init target config.
AUTHOR: MouchenHung
DATE/VERSION: 2021.11.26 - v1.1
Note:
(1) "plat_i2c_target.h" is included by "hal_i2c_target.h"
*/

#include <zephyr.h>
#include <stdio.h>
#include <stdlib.h>
#include "plat_i2c_target.h"

/* I2C target init-enable table */
const bool I2C_TARGET_ENABLE_TABLE[MAX_TARGET_NUM] = {
TARGET_DISABLE, TARGET_ENABLE, TARGET_DISABLE, TARGET_DISABLE,
TARGET_DISABLE, TARGET_DISABLE, TARGET_DISABLE, TARGET_DISABLE,
TARGET_DISABLE, TARGET_DISABLE, TARGET_DISABLE, TARGET_DISABLE,
TARGET_DISABLE, TARGET_DISABLE, TARGET_DISABLE, TARGET_DISABLE,
};

/* I2C target init-config table */
const struct _i2c_target_config I2C_TARGET_CONFIG_TABLE[MAX_TARGET_NUM] = {
{ 0x40, 0xA }, { 0x20, 0xA }, { 0x40, 0xA }, { 0x40, 0xA }, { 0xFF, 0xA }, { 0xFF, 0xA },
{ 0x40, 0x5 }, { 0xFF, 0xA }, { 0x40, 0x4 }, { 0xFF, 0xA }, { 0x40, 0xA }, { 0x40, 0xA },
{ 0x40, 0xA }, { 0x40, 0xA }, { 0xFF, 0xA }, { 0xFF, 0xA },
};
26 changes: 26 additions & 0 deletions meta-facebook/yv35-rf/src/platform/plat_i2c_target.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
/*
* Copyright (c) Meta Platforms, Inc. and affiliates.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

#ifndef PLAT_I2C_SLAVE_H
#define PLAT_I2C_SLAVE_H

#include <drivers/i2c.h>
#include "hal_i2c_target.h"

#define TARGET_ENABLE 1
#define TARGET_DISABLE 0

#endif
12 changes: 12 additions & 0 deletions meta-facebook/yv35-rf/src/platform/plat_init.c
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@
#include "plat_isr.h"
#include "plat_power_seq.h"
#include "power_status.h"
#include "cci.h"
#include "plat_mctp.h"
#include "plat_i2c_target.h"

SCU_CFG scu_cfg[] = {
//register value
Expand All @@ -31,6 +34,15 @@ void pal_pre_init()
{
init_platform_config();
scu_init(scu_cfg, ARRAY_SIZE(scu_cfg));

/* init i2c target */
for (int index = 0; index < MAX_TARGET_NUM; index++) {
if (I2C_TARGET_ENABLE_TABLE[index])
i2c_target_control(
index, (struct _i2c_target_config *)&I2C_TARGET_CONFIG_TABLE[index],
1);
}
plat_mctp_init();
}

void pal_set_sys_status()
Expand Down
230 changes: 230 additions & 0 deletions meta-facebook/yv35-rf/src/platform/plat_mctp.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,230 @@
/*
* Copyright (c) Meta Platforms, Inc. and affiliates.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

/*
* Copyright (c) 2012-2014 Wind River Systems, Inc.
*
* SPDX-License-Identifier: Apache-2.0
*/

#include <zephyr.h>
#include <sys/printk.h>
#include <logging/log.h>
#include <logging/log_ctrl.h>
#include <stdlib.h>
#include "libutil.h"
#include "mctp.h"
#include "mctp_ctrl.h"
#include "pldm.h"
#include "ipmi.h"
#include "sensor.h"
#include "plat_hook.h"
#include "plat_mctp.h"
#include "plat_gpio.h"
#include "cci.h"
#include "pm8702.h"

LOG_MODULE_REGISTER(plat_mctp);
K_TIMER_DEFINE(send_cmd_timer, send_cmd_to_dev, NULL);
K_WORK_DEFINE(send_cmd_work, send_cmd_to_dev_handler);

static mctp_smbus_port smbus_port[] = {
{ .conf.smbus_conf.addr = I2C_ADDR_BIC, .conf.smbus_conf.bus = I2C_BUS_CXL },
};

static mctp_route_entry mctp_route_tbl[] = {
{ CXL_EID, I2C_BUS_CXL, I2C_ADDR_CXL0 },
};

mctp *find_mctp_by_smbus(uint8_t bus)
{
uint8_t i;
for (i = 0; i < ARRAY_SIZE(smbus_port); i++) {
mctp_smbus_port *p = smbus_port + i;
if (!p) {
return NULL;
}
if (bus == p->conf.smbus_conf.bus) {
return p->mctp_inst;
}
}
return NULL;
}

static void set_endpoint_resp_handler(void *args, uint8_t *buf, uint16_t len)
{
CHECK_NULL_ARG(args);
CHECK_NULL_ARG(buf);
LOG_HEXDUMP_INF(buf, len, __func__);
}

static void set_endpoint_resp_timeout(void *args)
{
CHECK_NULL_ARG(args);
mctp_route_entry *p = (mctp_route_entry *)args;
printk("[%s] Endpoint 0x%x set endpoint failed on bus %d \n", __func__, p->endpoint,
p->bus);
}

static void set_dev_endpoint(void)
{
for (uint8_t i = 0; i < ARRAY_SIZE(mctp_route_tbl); i++) {
mctp_route_entry *p = mctp_route_tbl + i;
for (uint8_t j = 0; j < ARRAY_SIZE(smbus_port); j++) {
if (!p) {
return;
}
if (p->bus != smbus_port[j].conf.smbus_conf.bus) {
continue;
}
printk("Prepare send endpoint bus 0x%x, addr 0x%x\n", p->bus, p->addr);
struct _set_eid_req req = { 0 };
req.op = SET_EID_REQ_OP_SET_EID;
req.eid = p->endpoint;

mctp_ctrl_msg msg;
memset(&msg, 0, sizeof(msg));
msg.ext_params.type = MCTP_MEDIUM_TYPE_SMBUS;
msg.ext_params.smbus_ext_params.addr = p->addr;

msg.hdr.cmd = MCTP_CTRL_CMD_SET_ENDPOINT_ID;
msg.hdr.rq = 1;

msg.cmd_data = (uint8_t *)&req;
msg.cmd_data_len = sizeof(req);

msg.recv_resp_cb_fn = set_endpoint_resp_handler;
msg.timeout_cb_fn = set_endpoint_resp_timeout;
msg.timeout_cb_fn_args = p;

mctp_ctrl_send_msg(find_mctp_by_smbus(p->bus), &msg);
}
}
}

static uint8_t mctp_msg_recv(void *mctp_p, uint8_t *buf, uint32_t len, mctp_ext_params ext_params)
{
CHECK_NULL_ARG_WITH_RETURN(mctp_p, MCTP_ERROR);
CHECK_NULL_ARG_WITH_RETURN(buf, MCTP_ERROR);

/* first byte is message type and ic */
uint8_t msg_type = (buf[0] & MCTP_MSG_TYPE_MASK) >> MCTP_MSG_TYPE_SHIFT;

switch (msg_type) {
case MCTP_MSG_TYPE_CTRL:
mctp_ctrl_cmd_handler(mctp_p, buf, len, ext_params);
break;

case MCTP_MSG_TYPE_CCI:
mctp_cci_cmd_handler(mctp_p, buf, len, ext_params);
break;

default:
LOG_WRN("Cannot find message receive function!!");
return MCTP_ERROR;
}

return MCTP_SUCCESS;
}

uint8_t get_mctp_route_info(uint8_t dest_endpoint, void **mctp_inst, mctp_ext_params *ext_params)
{
CHECK_NULL_ARG_WITH_RETURN(mctp_inst, MCTP_ERROR);
CHECK_NULL_ARG_WITH_RETURN(ext_params, MCTP_ERROR);

uint8_t rc = MCTP_ERROR;
uint32_t i;

for (i = 0; i < ARRAY_SIZE(mctp_route_tbl); i++) {
mctp_route_entry *p = mctp_route_tbl + i;
if (!p) {
return MCTP_ERROR;
}
if (p->endpoint == dest_endpoint) {
*mctp_inst = find_mctp_by_smbus(p->bus);
ext_params->type = MCTP_MEDIUM_TYPE_SMBUS;
ext_params->smbus_ext_params.addr = p->addr;
rc = MCTP_SUCCESS;
break;
}
}
return rc;
}

uint8_t get_mctp_info(uint8_t dest_endpoint, mctp **mctp_inst, mctp_ext_params *ext_params)
{
CHECK_NULL_ARG_WITH_RETURN(mctp_inst, MCTP_ERROR);
CHECK_NULL_ARG_WITH_RETURN(ext_params, MCTP_ERROR);

uint8_t rc = MCTP_ERROR;
uint32_t i;

for (i = 0; i < ARRAY_SIZE(mctp_route_tbl); i++) {
mctp_route_entry *p = mctp_route_tbl + i;
if (!p) {
return MCTP_ERROR;
}
if (p->endpoint == dest_endpoint) {
*mctp_inst = find_mctp_by_smbus(p->bus);
ext_params->type = MCTP_MEDIUM_TYPE_SMBUS;
ext_params->smbus_ext_params.addr = p->addr;
rc = MCTP_SUCCESS;
break;
}
}
return rc;
}

void send_cmd_to_dev_handler(struct k_work *work)
{
/* init the device endpoint */
set_dev_endpoint();
}
void send_cmd_to_dev(struct k_timer *timer)
{
k_work_submit(&send_cmd_work);
}

void plat_mctp_init()
{
LOG_INF("plat_mctp_init");
for (uint8_t i = 0; i < ARRAY_SIZE(smbus_port); i++) {
mctp_smbus_port *p = smbus_port + i;
if (!p) {
return;
}
/* init the mctp/cci instance */
LOG_DBG("bus = %x, addr = %x", p->conf.smbus_conf.bus, p->conf.smbus_conf.addr);

p->mctp_inst = mctp_init();
if (!p->mctp_inst) {
LOG_ERR("mctp_init failed!!");
}
LOG_DBG("mctp_inst = %p", p->mctp_inst);
uint8_t rc =
mctp_set_medium_configure(p->mctp_inst, MCTP_MEDIUM_TYPE_SMBUS, p->conf);
LOG_DBG("mctp_set_medium_configure %s",
(rc == MCTP_SUCCESS) ? "success" : "failed");

mctp_reg_endpoint_resolve_func(p->mctp_inst, get_mctp_route_info);
mctp_reg_msg_rx_func(p->mctp_inst, mctp_msg_recv);
mctp_start(p->mctp_inst);
}
/* Only send command to device when DC on */
if (gpio_get(FM_POWER_EN) == POWER_ON) {
k_timer_start(&send_cmd_timer, K_MSEC(3000), K_NO_WAIT);
}
}
Loading