From 832daa21ab33cc61ed12b95a0a0a6bb18367a542 Mon Sep 17 00:00:00 2001 From: leimingsheng Date: Thu, 25 Dec 2025 17:34:51 +0800 Subject: [PATCH] =?UTF-8?q?feat(master=20:=20nicsensor)=20update=20to=201.?= =?UTF-8?q?8.4=20[=E9=87=8D=E8=A6=81]=20=E6=96=B0=E5=A2=9Epmbus=E5=8A=9F?= =?UTF-8?q?=E8=83=BD=EF=BC=8C=E7=94=B1=E4=BA=8Epmbus=E4=BB=A3=E7=A0=81?= =?UTF-8?q?=E9=87=8F=E6=9E=81=E5=A4=A7=E4=B8=94=E5=90=8E=E6=9C=9F=E5=8F=AF?= =?UTF-8?q?=E8=83=BD=E9=9C=80=E8=A6=81=E4=BA=BA=E4=B8=BA=E7=BB=B4=E6=8A=A4?= =?UTF-8?q?=EF=BC=8C=E5=B0=86pmbus=E4=BD=9C=E4=B8=BA=E6=8F=92=E4=BB=B6?= =?UTF-8?q?=E5=8A=9F=E8=83=BD=E5=8A=A0=E5=85=A5=E5=88=B0nicsensor=E4=B8=AD?= =?UTF-8?q?.=20=E5=90=8E=E6=9C=9F=E7=BB=B4=E6=8A=A4=20pmbus=5Fcmd=5Flist.s?= =?UTF-8?q?h=20=E5=8D=B3=E5=8F=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 遗留事项:pmbus set功能未实现,当前仅支持读取 --- nicsensor.sh | 41 ++++++++++++- pmbus_cmd_list.sh | 145 ++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 185 insertions(+), 1 deletion(-) create mode 100644 pmbus_cmd_list.sh diff --git a/nicsensor.sh b/nicsensor.sh index d8cc15b..5c758aa 100755 --- a/nicsensor.sh +++ b/nicsensor.sh @@ -1,5 +1,5 @@ #!/bin/sh -SCRIPT_VERSION="1.8.3" +SCRIPT_VERSION="1.8.4" # --------------------------------------------------------- # Project Feature Varible (Change if need) # --------------------------------------------------------- @@ -142,6 +142,13 @@ log="/tmp/nicsensor_debug.log" # --------------------------------------------------------- # Script Function Defination # --------------------------------------------------------- +search_plugin_help(){ + PMBUS_PLUGIN="./pmbus_cmd_list.sh" + if [ -e ${PMBUS_PLUGIN} ];then + $PMBUS_PLUGIN "help" + fi +} + print_usage(){ echo "" echo "================>>> nicsensor script usage <<<==================" @@ -189,6 +196,8 @@ print_usage(){ echo " 3) E.G. : ./nicsensor.sh set server 5280m7" echo " : ./nicsensor.sh set debug 1" echo " : ./nicsensor.sh set detect 1" + echo "" + search_plugin_help } # print format message to console|debuglog @@ -1227,6 +1236,33 @@ process_fru(){ fi } +#@Param1 : Pmbus Command, hex data +#@Param2 : Pmbus reading size, BYTE(1)|WORD(2)|BLOCK(3)|RAW(4) +transfer_pmbus_command(){ + pmbus_res=`i2ctransfer -y $i2c_bus w1@$chip_slave $1 r$2` + reset_pca9548 $i2c_bus $pca9548_slave + fmt_print "console" $INFO "$option_data Result: $pmbus_res" +} + +# Do pmbus test if plugin avalible +process_pmbus(){ + PMBUS_PLUGIN="./pmbus_cmd_list.sh" + if [ -e ${PMBUS_PLUGIN} ];then + str_pmbus_cmd=$option_data + hex_pmbus_cmd=`$PMBUS_PLUGIN "code" $str_pmbus_cmd` + + if [ "$hex_pmbus_cmd" = "0xff" ];then + fmt_print "console" $ERROR "Unsupport PMBUS Command : $str_pmbus_cmd" + exit 1 + fi + + hex_pmbus_size=`$PMBUS_PLUGIN "size" $str_pmbus_cmd` + transfer_pmbus_command $hex_pmbus_cmd $hex_pmbus_size + else + fmt_print "console" $ERROR "Can't find pmbus plugin file, please copy pmbus_cmd_list.sh to here!" + fi +} + # This function is temporarily retained for future functional expansion handle_reserve(){ fmt_print "console" $INFO "Waiting for user defined" @@ -1271,6 +1307,9 @@ start_get_sensor(){ "fru") process_fru ;; + "pmbus") + process_pmbus + ;; "reserve") handle_reserve ;; diff --git a/pmbus_cmd_list.sh b/pmbus_cmd_list.sh new file mode 100644 index 0000000..d012807 --- /dev/null +++ b/pmbus_cmd_list.sh @@ -0,0 +1,145 @@ +#!/bin/sh + +# Desc : This script used to find pmbus code and read size +# Todo : Support PMBUS Setting Function +# Version : 0.1 +# Date : 2025-12-25 +# Changelist : 2025-12-25|v0.1 Create this file + +# How to use this pmbus plugin? +# Copy this file to the dir as same as nicsensor.sh + +# --------------------------------------------------------- +# Varible Define +# --------------------------------------------------------- +operation_type=$1 +str_cmd=$2 +hex_cmd=0xff +read_size=0 + +PMBUS_BYTE=1 +PMBUS_WORD=2 +PMBUS_BLOCK=3 +PMBUS_RAW=4 + +# --------------------------------------------------------- +# Function Define +# --------------------------------------------------------- +pmbus_command_help(){ + echo " Extend Function - PMBUS command test" + echo " 1) Command Format : ./nicsensor.sh [slot] pmbus [slave] [command]" + echo " 2) Option Detail" + echo " - [slot] : 0 1 2 3 4 5 ..." + echo " - [slave] : power manage chip slave address , please provide 7 bit address" + echo " - [command] : The pmbus command which will set to the power manage chip" + echo " 3) E.G. : ./nicsensor.sh pcie1 pmbus 0x60 READ_TEMPERATURE_1" + echo "" + echo " *****************Pmbus Support Command List********************" + echo " Command Name Code Read Size " + echo " READ_VIN 0x88 Word " + echo " READ_IIN 0x89 Word " + echo " READ_VOUT 0x8b Word " + echo " READ_IOUT 0x8c Word " + echo " READ_TEMPERATURE_1 0x8d Word " + echo " READ_TEMPERATURE_2 0x8e Word " + echo " READ_TEMPERATURE_3 0x8f Word " + echo " READ_POUT 0x96 Word " + echo " READ_PIN 0x97 Word " + echo " ***************************************************************" + echo "" +} + +find_pmbus_hex_code(){ + case ${str_cmd} in + "READ_VIN") + hex_cmd=0x88 + ;; + "READ_IIN") + hex_cmd=0x89 + ;; + "READ_VOUT") + hex_cmd=0x8b + ;; + "READ_IOUT") + hex_cmd=0x8c + ;; + "READ_TEMPERATURE_1") + hex_cmd=0x8d + ;; + "READ_TEMPERATURE_2") + hex_cmd=0x8e + ;; + "READ_TEMPERATURE_3") + hex_cmd=0x8f + ;; + "READ_POUT") + hex_cmd=0x96 + ;; + "READ_PIN") + hex_cmd=0x97 + ;; + *) + hex_cmd=0xff + ;; + esac + echo $hex_cmd +} + +find_pmbus_read_size(){ + case ${str_cmd} in + "READ_VIN") + read_size=$PMBUS_WORD + ;; + "READ_IIN") + read_size=$PMBUS_WORD + ;; + "READ_VOUT") + read_size=$PMBUS_WORD + ;; + "READ_IOUT") + read_size=$PMBUS_WORD + ;; + "READ_TEMPERATURE_1") + read_size=$PMBUS_WORD + ;; + "READ_TEMPERATURE_2") + read_size=$PMBUS_WORD + ;; + "READ_TEMPERATURE_3") + read_size=$PMBUS_WORD + ;; + "READ_POUT") + read_size=$PMBUS_WORD + ;; + "READ_PIN") + read_size=$PMBUS_WORD + ;; + *) + read_size=0 + ;; + esac + echo $read_size +} + +main(){ + + case ${operation_type} in + "code") + find_pmbus_hex_code + ;; + "size") + find_pmbus_read_size + ;; + "help") + pmbus_command_help + ;; + *) + echo "Error command type" + ;; + esac +} + +# --------------------------------------------------------- +# Start Execute Script(main) +# --------------------------------------------------------- +main \ No newline at end of file