nicsensor/readme.md
2025-06-20 15:41:30 +08:00

223 lines
8.4 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)
## 目录
- [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_扩展功能)
- [3 常见问题](#3_常见问题)
- [3.1 ADC128传感器读值为0](#3_1_adc128传感器读值为0)
- [3.2 脚本执行时出现大批量语法错误](#3_2_脚本执行时出现大批量语法错误)
- [4 附属工具](#4_附属工具)
- [4.1 FruParse](#4_1_fruparse)
- [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卡
**当前支持测试的传感器类型**
- adc128
- ina3221
- emc1413
- tmp468
- tmp112
> [!tip]
> 每次执行脚本都可以在 `/tmp/nicsensor_debug.log` 查询详细的命令执行记录
## 2_使用方法
> [!warning]
> 在使用时针对网卡的硬件特性需要定制化修改脚本的 `Project Varible` ,变量的对应关系及说明见[Project变量说明](#6_1_project变量说明)
### 2_1_传感器读取
**命令格式**
``` shell
./nicsensor.sh <pcie_slot> <sensor_tpye> <sensor_slave>
```
**参数说明**
- `pcie slot`:网卡位于的PCIE SLOT槽位,需要指定pcie/ocp, 不指定时默认为pcie类型
- `sensor type`:传感器类型
- `sensor slave`:传感器的slave地址
**命令示例**
``` shell
# 读取pcie2槽位上的adc128的信息, adc128芯片的地址为0x1f(7bit)
./nicsensor.sh pcie2 adc128 0x1f
```
### 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>
```
**参数说明**
- `pcie slot`:网卡位于的PCIE SLOT槽位,需要指定pcie/ocp, 不指定时默认为pcie类型
- `eeprom slave`: FRU所在的eeprom芯片的slave地址
- `filename`: 仅在写入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_命令透传
**命令格式**
``` shell
./nicsensor.sh <pcie_slot> chip <chip slave> <command>
```
**参数说明**
- `pcie slot`:网卡位于的PCIE SLOT槽位,需要指定pcie/ocp, 不指定时默认为pcie类型
- `chip slave`: 芯片的slave地址
- `command`: 要透传执行的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_调试模式使用
> 关联变量 `DEBUG_MODE`, 启用调试模式时需要将该变量的值配置为1
如果不需要借助脚本来选通服务器上对应的channel, 仅需要做传感器数值测试, 可以启用调试模式。
在调试模式下, 脚本不会执行选通PCA9641以及PCA9546/9548的操作。仅直接测试传感器。因此需要手动调整两个变量
- `DEBUG_MODE`
- `i2c_bus`
> 关联变量 `DISABLE_DETECT`, 启用时配置为1, 将不会在切换PCA9641和PCA9548时进行i2cdetect
### 2_6_扩展功能
脚本中预留了函数 `handle_reserve` 用于扩展功能。针对有特殊需求的项目可能会使用。
`handle_reserve` 中可以自定义需要对网卡实现的功能。在调用该函数之前脚本会将 PCA9641及PCA9548选通。扩展功能时无需考虑PCA9641和PCA9548的状态。
## 3_常见问题
### 3_1_ADC128传感器读值为0
ADC128传感器在使用时需要初始化, 因此第一次读取时传感器可能并未完成初始化, 所以读值为0
### 3_2_脚本执行时出现大批量语法错误
通常是因为服务器上含有PCA9641切断了BMC的I2C控制权导致重试即可
## 4_附属工具
### 4_1_FruParse
提供了一个简单python脚本用于解析FRU的数据, 将nicsensor读取到的FRU数据拷贝到frudata.txt后, 执行
`python fru_parse.py`即可将读取到的数据转化为FRU内容
## 5_关于nicsensor_v2
nicsensor_v2将服务器选通channel和读取传感器数值的功能解耦因此在单独使用某个功能时可以直接找到对应的脚本进行测试。
详见[nicsensor_v2](./nicsensor_v2/readme.md)
## 6_附录
### 6_1_Project变量说明
**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对应的名称
**FRU**相关
- `fru_offset`: 网卡FRU所在eeprom的偏移量。默认值为 0x00 0x00
**所用服务器**
- `server_type`: 脚本将工作在哪个服务器上?支持的服务器列表见`Support_Server_List`, 默认值为`default`,支持自动识别受支持的型号。