From 4f9e9cfe73bd20d0a09be95170c1a189e2adb2dd Mon Sep 17 00:00:00 2001 From: Felix Radensky Date: Thu, 16 Jan 2025 14:38:01 +0200 Subject: [PATCH] hw-mgmt: scripts: Fix creation and removal of psuN_i2c_bus files These files are created when PSU cables are plugged in and removed when PSU cable are plugged out. Instead, they should be created and removed when PSUs are plugged in and plugged out respectively. Otherwise there is no way to distingush between dummy PSU and real PSU that was disconnected from power. Bug: 4176785 Signed-off-by: Felix Radensky --- usr/usr/bin/hw-management-chassis-events.sh | 25 +++++++++++++++++++++ usr/usr/bin/hw-management-thermal-events.sh | 5 ----- 2 files changed, 25 insertions(+), 5 deletions(-) diff --git a/usr/usr/bin/hw-management-chassis-events.sh b/usr/usr/bin/hw-management-chassis-events.sh index 68209f42c..634ffbf7a 100755 --- a/usr/usr/bin/hw-management-chassis-events.sh +++ b/usr/usr/bin/hw-management-chassis-events.sh @@ -652,6 +652,31 @@ function handle_hotplug_event() fi fi ;; + psu*) + psu_name="$attribute" + # SN5600, SN5400 systems have PSU2 with I2C address 0x5a. In udev rules 0x5a corresponds to psu4. + if [[ ( $sku == "HI144" || $sku == "HI147" ) && "$2" == "psu4" ]]; then + psu_name="psu2" + fi + find_i2c_bus + i2c_comex_mon_bus_default=$(< $i2c_comex_mon_bus_default_file) + comex_bus=$((i2c_comex_mon_bus_default+i2c_bus_offset)) + busdir=$(echo "$5""$3" |xargs dirname |xargs dirname) + busfolder=$(basename "$busdir") + bus="${busfolder:0:${#busfolder}-5}" + # Verify if this is COMEX device + if [ "$bus" == "$comex_bus" ]; then + return + fi + + if [ "$event" -eq 1 ]; then + echo "$bus" > $config_path/"$psu_name"_i2c_bus + else + if [ -e "$config_path"/"$psu_name"_i2c_bus ]; then + rm -f $config_path/"$psu_name"_i2c_bus + fi + fi + ;; *) ;; esac diff --git a/usr/usr/bin/hw-management-thermal-events.sh b/usr/usr/bin/hw-management-thermal-events.sh index 9453958fd..379595a3a 100755 --- a/usr/usr/bin/hw-management-thermal-events.sh +++ b/usr/usr/bin/hw-management-thermal-events.sh @@ -869,8 +869,6 @@ if [ "$1" == "add" ]; then # Allow PS controller to stabilize retry_helper "ls" 0.2 20 "$2 takes too long to init" "$5""$3"/in1_input sleep 1 - # Set I2C bus for psu - echo "$bus" > $config_path/"$psu_name"_i2c_bus # Set default fan speed psu_set_fan_speed "$psu_name" $(< $fan_psu_default) # Add thermal attributes @@ -1421,9 +1419,6 @@ else rm -f "$config_path"/"$psu_name"_power_slope rm -f "$config_path"/"$psu_name"_power_capacity fi - if [ -e "$config_path"/"$psu_name"_i2c_bus ]; then - rm -f "$config_path"/"$psu_name"_i2c_bus - fi fi if [ "$2" == "sxcore" ]; then /usr/bin/hw-management.sh chipdown 0 "$4/$5"