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