openBMC source code

简介: 1、fand1)main函数read_sysfs_int("/sys/bus/i2c/drivers/cmmcpld/13-003e/slotid", &sysfs_value)write_fan_speed(fan + fan_offset, fan_speed)write_fan_le...

1、fand

1)main函数

read_sysfs_int("/sys/bus/i2c/drivers/cmmcpld/13-003e/slotid", &sysfs_value)

write_fan_speed(fan + fan_offset, fan_speed)

write_fan_led(fan + fan_offset, FAN_LED_BLUE)

start_watchdog(0)

while(1){

critical_temp = read_critical_max_temp();
alarm_temp = read_alarm_max_temp();

raising_pwm = calculate_raising_fan_pwm(critical_temp);
falling_pwm = calculate_falling_fan_pwm(critical_temp);

write_fan_led(fan + fan_offset, FAN_LED_RED);

}

 

2)write_fan_speed

int write_fan_speed(const int fan, const int value) {
int unit = value * PWM_UNIT_MAX / 100;

if (unit == PWM_UNIT_MAX)
unit--;

return galaxy100_set_fan_sysfs(fan, unit);
}

 

3)galaxy100_set_fan_sysfs

info = &galaxy100_fantray_info[fan];
channel = &info->channel_info;

snprintf(fullpath, PATH_CACHE_SIZE, "%s/%s", channel->prefix, "fantray1_pwm");
ret = write_sysfs_int(fullpath, value);

snprintf(fullpath, PATH_CACHE_SIZE, "%s/%s", channel->prefix, "fantray2_pwm");
ret = write_sysfs_int(fullpath, value);

snprintf(fullpath, PATH_CACHE_SIZE, "%s/%s", channel->prefix, "fantray3_pwm");
ret = write_sysfs_int(fullpath, value);

 

4) write_sysfs_int

int write_sysfs_int(char *sysfs_path, int buffer)
{
int rc = 0;
char writeBuf[PATH_CACHE_SIZE];
snprintf(writeBuf, PATH_CACHE_SIZE, "%d", buffer);
return write_sysfs_raw(sysfs_path, writeBuf);
}

 

int write_sysfs_raw_internal(const char *device, char *value, int log)

fp = fopen(device, "w");

rc = fputs(value, fp);
fclose(fp);

 

5)  fancpld_attr_table

typedef struct i2c_dev_attr_st_ {
  const char *ida_name;
  const char *ida_help;
  i2c_dev_attr_show_fn ida_show;
  i2c_dev_attr_store_fn ida_store;
  int ida_reg;
  int ida_bit_offset;
  int ida_n_bits;
} i2c_dev_attr_st;

const i2c_dev_attr_st fancpld_attr_table[] = {
  {
    "fantray1_pwm",
    FANTRAY_PWM_HELP,
    I2C_DEV_ATTR_SHOW_DEFAULT,
    I2C_DEV_ATTR_STORE_DEFAULT,
    0x20, 0, 5,
  },
}

static int fancpld_probe(struct i2c_client *client,
const struct i2c_device_id *id)
{
int n_attrs = sizeof(fancpld_attr_table) / sizeof(fancpld_attr_table[0]);
return i2c_dev_sysfs_data_init(client, &fancpld_data,
fancpld_attr_table, n_attrs);
}

 

static struct i2c_driver fancpld_driver = {
.class = I2C_CLASS_HWMON,
.driver = {
.name = "fancpld",
},
.probe = fancpld_probe,
.remove = fancpld_remove,
.id_table = fancpld_id,
.detect = fancpld_detect,
.address_list = normal_i2c,
};

static int __init fancpld_mod_init(void)
{
return i2c_add_driver(&fancpld_driver);
}

 

 

6) i2c_dev_sysfs_store

static ssize_t i2c_dev_sysfs_store(struct device *dev,
                                   struct device_attribute *attr,
                                   const char *buf, size_t count)

if (dev_attr->ida_store != I2C_DEV_ATTR_STORE_DEFAULT) {
return dev_attr->ida_store(dev, attr, buf, count);
}

/* default handling, first read back the current value */
val = i2c_smbus_read_byte_data(client, dev_attr->ida_reg);

 

/* mask out all bits for the value requested */
val &= ~(req_val_mask << dev_attr->ida_bit_offset);
val |= req_val << dev_attr->ida_bit_offset;

val = i2c_smbus_write_byte_data(client, dev_attr->ida_reg, val);

 

7)module_init

Cmmcpld.c (meta-facebook\meta-cmm\recipes-kernel\cpld-mod\files):module_init(cmmcpld_mod_init);
Com_e_driver.c (meta-facebook\meta-wedge100\recipes-kernel\com-e-mod\files):module_init(com_e_mod_init);
Fancpld.c (meta-facebook\meta-cmm\recipes-kernel\cpld-mod\files):module_init(fancpld_mod_init);
Fancpld.c (meta-facebook\meta-wedge100\recipes-kernel\cpld-mod\files):module_init(fancpld_mod_init);
Fb_panther_plus.c (meta-facebook\meta-wedge\recipes-kernel\fb-panther-mod\files):module_init(sensors_panther_plus_init);
Galaxy100_ec.c (meta-facebook\meta-galaxy100\recipes-kernel\i2c-mode\files):module_init(ec_mod_init); Ir358x.c (meta-facebook\meta-galaxy100\recipes-kernel\i2c-mode\files):module_init(ir358x_mod_init); Pwr1014a.c (meta-facebook\meta-galaxy100\recipes-kernel\i2c-mode\files):module_init(pwr1014a_mod_init); Scmcpld.c (meta-facebook\meta-galaxy100\recipes-kernel\cpld-mod\files):module_init(scmcpld_mod_init); Syscpld.c (meta-facebook\meta-galaxy100\recipes-kernel\cpld-mod\files):module_init(syscpld_mod_init); Syscpld.c (meta-facebook\meta-wedge100\recipes-kernel\cpld-mod\files):module_init(syscpld_mod_init);

每个文件对应某个单板的一个设备驱动,每个设备驱动定义一个i2c_dev_attr_st数组,支持用户态通过文件方式进行读写访问。

 

2、lib_ipmb_handle

1)int pal_read_cpu_temp(uint8_t snr_num, float *value)

req->cmd = CMD_NM_SEND_RAW_PECI;

lib_ipmb_handle(bus_id, tbuf, tlen+1, rbuf1, &rlen);

 

2) bic_set_gpio(uint8_t slot_id, uint8_t gpio, uint8_t value)

bic_ipmb_wrapper(slot_id, NETFN_OEM_1S_REQ, CMD_OEM_1S_SET_GPIO, tbuf, 11, rbuf, &rlen)

get_ipmb_bus_id(slot_id)

lib_ipmb_handle(bus_id, tbuf, tlen, &rbuf, &rlen)

// copy the received data back to caller
*rxlen = rlen - IPMB_HDR_SIZE - IPMI_RESP_HDR_SIZE;
memcpy(rxbuf, res->data, *rxlen);

 

3) void lib_ipmb_handle(unsigned char bus_id,

unsigned char *request, unsigned char req_len,
unsigned char *response, unsigned char *res_len) 

sprintf(sock_path, "%s_%d", SOCK_PATH_IPMB, bus_id);  //#define SOCK_PATH_IPMB "/tmp/ipmb_socket"

s = socket(AF_UNIX, SOCK_STREAM, 0)

connect(s, (struct sockaddr *)&remote, len)

send(s, request, req_len, 0)

recv(s, response, MAX_IPMB_RES_LEN, 0)

 

目录
相关文章
|
Linux
在Linux下搭建TFTP服务器
在Linux下搭建TFTP服务器
478 1
|
存储 缓存 编解码
KiCad 插件
AD 文档转 KiCad 文件。 InteractiveHtmlBom kicad_text_tool kicad_tools kicad-action-scripts
2104 0
KiCad 插件
|
11月前
|
Ubuntu Linux 程序员
交叉编译valgrind在嵌入式设备上调试程序
交叉编译valgrind在嵌入式设备上调试程序
|
算法 NoSQL Java
spring cloud的限流算法有哪些?
【8月更文挑战第18天】spring cloud的限流算法有哪些?
271 3
|
存储 监控 安全
裸金属服务器,云用户的新体验
**摘要:** 裸金属服务器是结合物理服务器硬件优势和云服务虚拟化功能的设备,提供专用资源、无性能损失且易于扩展。它支持自动化发放、云硬盘、VPC网络和生命周期管理,适用于核心业务、高性能计算和大数据等。产品特点是快速发放(5分钟内)、共享卷支持、高安全性和灵活部署。常见客户场景包括合规与稳定性需求、低成本资源管理、定制化硬件需求。流行原因包括物理机的安全感、高性能要求、严格安全监管、克服传统托管弊端及适应混合计算场景。
|
人工智能 搜索推荐 固态存储
|
IDE Linux 开发工具
CentOS7.4+REDHAWK2.3.1安装教程——折腾篇
CentOS7.4+REDHAWK2.3.1安装教程——折腾篇
222 0
|
弹性计算 关系型数据库 网络安全
【ECS最佳实践】ECS+RDS构建云服务器主动防御系统部署开源蜜罐系统Hfish及ECS周边功能测试
我已经是阿里云ECS产品的老用户了,阿里的云计算产品性能可靠性毋庸置疑,这次分享一个开源蜜罐系统Hfish的单节点搭建,并围绕ECS周边的技术功能做个简单举例。
29260 27
【ECS最佳实践】ECS+RDS构建云服务器主动防御系统部署开源蜜罐系统Hfish及ECS周边功能测试
|
测试技术 网络安全 虚拟化
libvirt虚拟机热迁移
验证不同迁移特性下的热迁移效率。
3230 0
|
存储 JSON 运维
Facebook 工程经验 --PCIe 故障监控和修复
Facebook 工程经验 --PCIe 故障监控和修复
601 1
Facebook 工程经验 --PCIe 故障监控和修复