nicsensor/readme.md
2026-03-11 14:28:21 +08:00

430 lines
16 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

# nicsensor工具使用说明
> 本说明仅针对 nicsensorv1.x系列脚本
> 1.x系列工具本体: [nicsensor.sh](./nicsensor.sh)
## 快速使用
工具Usage `./nicsensor.sh help`
工具版本查询 `./nicsensor.sh version`
读取传感器:`./nicsensor.sh pcie0 ina3221 0x42` (读取PCIE_0 上网卡的 INA3221 传感器slave地址0x42)
## 目录
- [nicsensor工具使用说明](#nicsensor工具使用说明)
- [目录](#目录)
- [1.简介](#1_简介)
- [2.使用方法](#2_使用方法)
- [2.1 传感器读取](#2_1_传感器读取)
- [2.2 FRU读写](#2_2_fru读写)
- [2.3 命令透传](#2_3_命令透传)
- [2.4 服务器网卡通道I2C信息扫描](#2_4_服务器网卡通道I2C信息扫描)
- [2.5 调试模式](#2_5_调试模式)
- [2.6 扩展功能](#2_6_扩展功能)
- [2.7 参数配置](#2_7_参数配置)
- [2.8 PMBUS功能测试](#2_8_pmbus功能)
- [2.9 压力测试stress](#2_9_压力测试stress)
- [3.常见问题](#3_常见问题)
- [3.1 ADC128传感器读值为0](#3_1_adc128传感器读值为0)
- [3.2 脚本执行时出现大批量语法错误](#3_2_脚本执行时出现大批量语法错误)
- [3.3 传感器读值不正确](#3_3_传感器读值不正确)
- [4.附属工具](#4_附属工具)
- [4.1 FruParse](#4_1_fruparse)
- [4.2 nicsensor\_s(已停用)](#4_2_nicsensor_s)
- [5.关于nicsensor\_v2](#5_关于nicsensor_v2)
- [6.附录](#6_附录)
- [6.1 Project变量说明](#6_1_project变量说明)
## 1_简介
nicsensor工具是在带有i2ctool工具(i2ctransfer、i2cdetect)的BMC下用于测试网卡I2C功能的工具。
**当前支持的功能有:**
- 读取网卡上的I2C传感器
- 读取并修改网卡上的FRU
- 透传I2C命令到网卡的芯片上
- 遍历服务器上的PCIE插槽的I2C信息
- 部分服务器类型支持读取OCP卡
- 支持记录单次运行日志
- 支持测试PMBUS功能**(new)**
- 支持进行压力测试**(new)**
**当前支持测试的传感器类型**
- adc128
- ina3221
- ina226**(new)**
- emc1413
- tmp468
- tmp112
- lm95241**(new)**
## 2_使用方法
> [!warning]
> 在使用时针对网卡的硬件特性需要定制化修改脚本的 `Project Varible` ,变量的对应关系及说明见[Project变量说明](#6_1_project变量说明)
### 2_1_传感器读取
**命令格式**
``` shell
./nicsensor.sh <pcie_slot> <sensor_tpye> <sensor_slave>
```
**参数说明**
| Properties | type | 说明 |
| -------------- | ------- | ------------------------------------------------------------ |
| `pcie slot` | string | 网卡位于的PCIE SLOT槽位,需要指定pcie/ocp, 不指定时默认为pcie类型 |
| `sensor type` | string | 传感器类型 |
| `sensor slave` | hex num | 传感器的slave地址(7 bit) |
**命令示例**
``` shell
# 读取pcie2槽位上的adc128的信息, adc128芯片的地址为0x1f(7bit)
./nicsensor.sh pcie2 adc128 0x1f
# 读取pcie3槽位上的ina3221的信息, ina3221芯片的地址为0x40(7bit)
./nicsensor.sh 3 ina3221 0x40
# 读取ocp0槽位上的tmp112的信息, tmp112芯片的地址为0x48(7bit)
./nicsensor.sh ocp0 tmp112 0x48
```
### 2_2_FRU读写
> [!warning]
> 在写入网卡FRU操作时受限于服务器PCA9641的影响**建议**将服务器关机后执行
**命令格式**
``` shell
# 读取FRU
./nicsensor.sh <pcie_slot> fru <eeprom_slave>
# 写入FRU
./nicsensor.sh <pcie_slot> fru <eeprom_slave> write <filename>
```
**参数说明**
| Properties | type | 说明 |
| -------------- | ------- | ------------------------------------------------------------ |
| `pcie slot` | string | 网卡位于的PCIE SLOT槽位,需要指定pcie/ocp, 不指定时默认为pcie类型 |
| `eeprom slave` | hex num | FRU所在的eeprom芯片的slave地址(7 bit) |
| `filename` | string | 仅在写入FRU时提供, 要写入的FRU bin文件路径 |
**命令示例**
``` shell
# 读取pcie2槽位上的fru信息, eeprom的芯片地址为0x50(7bit)
./nicsensor.sh pcie2 fru 0x50
# 写入pcie2槽位上网卡的fru
./nicsensor.sh pcie2 fru 0x50 write fru.bin
```
### 2_3_命令透传
提供对芯片直接执行i2c命令的能力通常用于访问网卡核心芯片如FPGANic Controller等。
**命令格式**
``` shell
./nicsensor.sh <pcie_slot> chip <chip slave> <command>
```
**参数说明**
| Properties | type | 说明 |
| ------------ | ------- | ------------------------------------------------------------ |
| `pcie slot` | string | 网卡位于的PCIE SLOT槽位,需要指定pcie/ocp, 不指定时默认为pcie类型 |
| `chip slave` | hex num | 芯片的slave地址(7 bit) |
| `command` | string | 要透传执行的I2C命令 |
**命令示例**
``` shell
# 对pcie2槽位上的chip透传命令 i2ctransfer -y 12 w2@0x11 0x00 0x00 r2 , 芯片地址为0x11(7bit)
./nicsensor.sh pcie2 chip 0x11 "i2ctransfer -y 12 w2@0x11 0x00 0x00 r2"
```
### 2_4_服务器网卡通道I2C信息扫描
**命令格式**
``` shell
./nicsensor.sh detect <nic_type>
```
**参数说明**
- `nic type`:需要指定pcie/ocp, 不指定时默认为pcie类型
**命令示例**
``` shell
./nicsensor.sh detect pcie
```
### 2_5_调试模式
如果不需要借助脚本来选通服务器上对应的channel, 仅需要做传感器数值测试, 可以启用调试模式。
在调试模式下, 脚本不会执行选通PCA9641以及PCA9546/9548的操作。仅直接测试传感器。
**开启调试模式**
``````sh
./nicsensor.sh set debug 1
``````
**关闭调试模式**
``````sh
./nicsensor.sh set debug 0
``````
### 2_6_扩展功能
脚本中预留了函数 `handle_reserve` 用于扩展功能。针对有特殊需求的项目可能会使用。
`handle_reserve` 中可以自定义需要对网卡实现的功能。在调用该函数之前脚本会将 PCA9641及PCA9548选通。扩展功能时无需考虑PCA9641和PCA9548的状态。
### 2_7_参数配置
可以通过一组名为 `get/set` 的指令对脚本中的如下变量做即时修改而无需修改脚本(下电后恢复默认)。支持修改的变量如下:
| Properties | 对应脚本变量 | 说明 |
| ------------ | ---------------- | ---------------------------------------- |
| `server` | `server_type` | 脚本应用的服务器类型 |
| `debug` | `DEBUG_MODE` | 是否启用调试模式 |
| `n_detect` | `DISABLE_DETECT` | 是否禁止执行时的i2c detect操作 |
| `fru_size` | `fru_size` | 默认fru的读取字节数 |
| `fru_offset` | `fru_offset` | 默认fru在eeprom的起始偏移地址 |
| `i2cbus` | `i2c_bus` | 默认的i2c bus通常需要搭配debug一起使用 |
**命令格式**
``` shell
./nicsensor.sh <get/set> <property> <value>
```
**命令示例**
``` shell
./nicsensor.sh set server 5280m7
./nicsneosr.sh get debug
```
### 2_8_PMBUS功能
> [!warning]
> 支持的脚本版本v1.9及以上
> PMBUS功能属于额外的功能,需要将 [pmbus_cmd_list.sh](./pmbus_cmd_list.sh) 拷贝到和nicsensor脚本相同的目录。
> 如果不添加该脚本, 该功能无法正常使用
**命令格式**
``` shell
./nicsensor.sh <pcie slot> pmbus <chip slave> <pmbus cmd>
```
**参数说明**
- `pcie slot`: 网卡位于的PCIE SLOT槽位,需要指定pcie/ocp, 不指定时默认为pcie类型
- `chip slave`: 芯片的slave地址
- `pmbus cmd`: 要读取的pmbus命令码, 支持列表请使用命令 `./nicsensor.sh help` 查询
**命令示例**
``` shell
./nicsensor.sh pcie1 pmbus 0x60 READ_TEMPERATURE_1
```
### 2_9_压力测试stress
> [!Warning]
>
> 支持的脚本版本v1.10及以上
>
> 压力测试属于额外的功能,需要将 [stress_test.sh](./stress_test.sh) 拷贝到和nicsensor脚本相同的目录。
>
> 如果不添加该脚本,该功能无法正常使用
**功能介绍**
一个模块化的压力测试工具通过配置文件管理测试参数支持灵活设置测试轮次、间隔、传感器类型等方便用户进行nicsensor的稳定性测试。
**命令格式**
``````sh
./nicsensor.sh <pcie slot> stress <option> <option data>
``````
**参数说明**
| 参数名称 | 数据类型 | 说明 |
| ------------- | -------- | ------------------------------------------------------------ |
| `pcie slot` | string | nicsensor工具通用格式在这里无特殊含义 |
| `option` | string | 要执行的stress命令类型有如下取值<br>`start` : 开始执行压力测试无需option data<br>`show`: 显示压力测试的配置项, 无需option data<br>`round`: 要执行的压力测试圈数<br>`tool`: 要使用的nicsensor脚本默认为nicsensor.sh<br>`interval`: 每一圈执行的时间间隔,单位为秒(s)<br>`slot`: 目标测试的插槽号<br>`sensor`: 需要测试的传感器类型<br>`slave`: 目标传感器的slave地址 |
| `option data` | string | 依据option类型决定是否需要该字段 |
**命令示例**
``````sh
#场景说明对pcie1的网卡压测 ina3221(0x42) 100次, 读取间隔2s
# step 1 配置测试项
./nicsensor.sh pcie1 stress round 100
./nicsensor.sh pcie1 stress interval 2
./nicsensor.sh pcie1 stress slot pcie1
./nicsensor.sh pcie1 stress sensor ina3221
./nicsensor.sh pcie1 stress slave 0x42
# step 2 查看测试项是否符合预期
./nicsensor.sh pcie1 stress show
# step 3 开始测试
./nicsensor.sh pcie1 stress start
``````
## 3_常见问题
### 3_1_ADC128传感器读值为0
ADC128传感器在使用时需要初始化, 因此第一次读取时传感器可能并未完成初始化, 所以读值为0
### 3_2_脚本执行时出现大批量语法错误
通常是因为服务器上含有PCA9641切断了BMC的I2C控制权导致, 重试即可
### 3_3_传感器读值不正确
常见于ina3221传感器读值明显不正确, 因为ina3221的i2c slave地址比较敏感, 容易和pca9641产生冲突, 可首先按照i2c地址冲突的方向去排查问题。
## 4_附属工具
### 4_1_FruParse
提供了一个简单python脚本用于解析FRU的数据, 将nicsensor读取到的FRU数据拷贝到frudata.txt后, 执行
`python fru_parse.py`即可将读取到的数据转化为FRU内容
**工具路径**:[fru_parse.py](./tool/fru_parse/fru_parse.py)
### 4_2_nicsensor_s
该工具已于`nicsensor v1.10` 移除
~~基于脚本版本1.8, 剔除了所有记日志的操作, 用于加速i2c的执行, 确保在9641工作的生命周期内尽快完成i2c任务~~
~~**工具路径**:[nicsensor_s.sh](./nicsensor_s.sh)~~
## 5_关于nicsensor_v2
nicsensor_v2将服务器选通channel和读取传感器数值的功能解耦, 因此在单独使用某个功能时可以直接找到对应的脚本进行测试。
详见[nicsensor_v2](./nicsensor_v2/readme.md)
## 6_附录
### 6_1_Project变量说明
> [!important]
> 对于所有传感器的`xxx_Channel_name`, 将其配置为`disable`即可跳过对应的channel的数据解析。
> 推荐在硬件上空置的Channel将其配置为 `disable`,防止脚本解析数据时出现混淆
**ADC128**相关
| 变量 | 定义 |
| -------------------------- | ----------------------------------- |
| `votage_division_factor_0` | ADC128芯片Channel 0的分压系数 |
| `votage_division_factor_1` | ADC128芯片Channel 1的分压系数 |
| `votage_division_factor_2` | ADC128芯片Channel 2的分压系数 |
| `votage_division_factor_3` | ADC128芯片Channel 3的分压系数 |
| `votage_division_factor_4` | ADC128芯片Channel 4的分压系数 |
| `votage_division_factor_5` | ADC128芯片Channel 5的分压系数 |
| `votage_division_factor_6` | ADC128芯片Channel 6的分压系数 |
| `votage_division_factor_7` | ADC128芯片Channel 7的分压系数 |
| `ADC128_Channel0_name` | 定制化ADC128芯片Channel 0的电压名称 |
| `ADC128_Channel1_name` | 定制化ADC128芯片Channel 1的电压名称 |
| `ADC128_Channel2_name` | 定制化ADC128芯片Channel 2的电压名称 |
| `ADC128_Channel3_name` | 定制化ADC128芯片Channel 3的电压名称 |
| `ADC128_Channel4_name` | 定制化ADC128芯片Channel 4的电压名称 |
| `ADC128_Channel5_name` | 定制化ADC128芯片Channel 5的电压名称 |
| `ADC128_Channel6_name` | 定制化ADC128芯片Channel 6的电压名称 |
| `ADC128_Channel7_name` | 定制化ADC128芯片Channel 7的电压名称 |
**INA3221**相关
| 变量 | 定义 |
| ----------------------- | ----------------------------------------------------- |
| `shunt_resistor_0` | INA3221芯片的Channel 0外接的分流电阻的大小(单位:毫欧) |
| `shunt_resistor_1` | INA3221芯片的Channel 1外接的分流电阻的大小(单位:毫欧) |
| `shunt_resistor_2` | INA3221芯片的Channel 2外接的分流电阻的大小(单位:毫欧) |
| `INA3221_Channel0_name` | 定制化INA3221芯片Channel 0的名称 |
| `INA3221_Channel1_name` | 定制化INA3221芯片Channel 1的名称 |
| `INA3221_Channel2_name` | 定制化INA3221芯片Channel 2的名称 |
**EMC1413**相关
| 变量 | 定义 |
| ----------------------- | ------------------------------------ |
| `EMC1413_Channel0_name` | 定制化EMC1413芯片Channel 0的温度名称 |
| `EMC1413_Channel1_name` | 定制化EMC1413芯片Channel 1的温度名称 |
| `EMC1413_Channel2_name` | 定制化EMC1413芯片Channel 2的温度名称 |
**TMP468**相关
| 变量 | 定义 |
| ---------------------- | ----------------------------------------- |
| `TMP468_Channel0_name` | 定制化TMP468芯片Loacl Channel的温度名称 |
| `TMP468_Channel1_name` | 定制化TMP468芯片Remote1 Channel的温度名称 |
| `TMP468_Channel2_name` | 定制化TMP468芯片Remote2 Channel的温度名称 |
| `TMP468_Channel3_name` | 定制化TMP468芯片Remote3 Channel的温度名称 |
| `TMP468_Channel4_name` | 定制化TMP468芯片Remote4 Channel的温度名称 |
| `TMP468_Channel5_name` | 定制化TMP468芯片Remote5 Channel的温度名称 |
| `TMP468_Channel6_name` | 定制化TMP468芯片Remote6 Channel的温度名称 |
| `TMP468_Channel7_name` | 定制化TMP468芯片Remote7 Channel的温度名称 |
| `TMP468_Channel8_name` | 定制化TMP468芯片Remote8 Channel的温度名称 |
**TMP112**相关
| 变量 | 定义 |
| -------------------- | ---------------------- |
| `TMP112_Sensor_name` | 定制化TMP112对应的名称 |
**INA226**相关
| 变量 | 定义 |
| ---------------------- | ------------------------------- |
| `INA226_Channel0_name` | 定制化INA226芯片Channel 0的名称 |
**LM95241**相关
| 变量 | 定义 |
| ---------------------- | ------------------------------------------ |
| `LM95241_Local_name` | 定制化LM95241芯片Loacl Channel的温度名称 |
| `LM95241_Remote1_name` | 定制化LM95241芯片Remote1 Channel的温度名称 |
| `LM95241_Remote2_name` | 定制化LM95241芯片Remote2 Channel的温度名称 |