blob: 20cdd6dec8cec228cb0a510bf0795f4a449bb448 [file] [log] [blame]
Duke Dudddc5012019-05-29 09:19:24 +08001#!/bin/bash
2
3# get fan state by d-bus command
4function get_fan_state() {
5 get_property_path='xyz.openbmc_project.Sensor.Threshold.Critical CriticalAlarmLow'
Patrick Williams8c226232023-04-15 20:05:21 -05006 fan_state="$(busctl get-property "$1" "$2" "$get_property_path" | awk '{print $2}')"
Duke Dudddc5012019-05-29 09:19:24 +08007 echo "$fan_state"
8}
9
10# set fan pwm by d-bus command
11function set_fan_value() {
12 set_property_path='xyz.openbmc_project.Control.FanPwm'
Patrick Williams8c226232023-04-15 20:05:21 -050013 busctl set-property "$1" "$2" $set_property_path Target t 255
Duke Dudddc5012019-05-29 09:19:24 +080014}
15
16fan_tach_path=( '/xyz/openbmc_project/sensors/fan_tach/Fan0_0_RPM'
17 '/xyz/openbmc_project/sensors/fan_tach/Fan0_1_RPM'
18 '/xyz/openbmc_project/sensors/fan_tach/Fan1_0_RPM'
19 '/xyz/openbmc_project/sensors/fan_tach/Fan1_1_RPM'
20 '/xyz/openbmc_project/sensors/fan_tach/Fan2_0_RPM'
21 '/xyz/openbmc_project/sensors/fan_tach/Fan2_1_RPM'
22 )
23
24check_fail_flag=0
25current_fan_state=()
26while true; do
Patrick Williams8c226232023-04-15 20:05:21 -050027 hwmon_path="$(mapper get-service "${fan_tach_path[0]}")"
28 for i in "${!fan_tach_path[@]}";
Duke Dudddc5012019-05-29 09:19:24 +080029 do
Patrick Williams8c226232023-04-15 20:05:21 -050030 current_fan_state[i%2]=$(get_fan_state "$hwmon_path" "${fan_tach_path[$i]}")
Duke Dudddc5012019-05-29 09:19:24 +080031
32 #Compare state of dual rotors with CriticalAlarmLow to check if fan fail
33 if [ ${#current_fan_state[@]} -eq 2 ];then
34 if [ "${current_fan_state[0]}" == "true" ] && \
35 [ "${current_fan_state[1]}" == "true" ] ;then
36 if [ $check_fail_flag -eq 0 ];then
37 systemctl stop phosphor-pid-control
Patrick Williams8c226232023-04-15 20:05:21 -050038 for j in "${!fan_tach_path[@]}";
Duke Dudddc5012019-05-29 09:19:24 +080039 do
40 #If fan fail is detect, set other fan rpm to pwm 255.
Patrick Williams8c226232023-04-15 20:05:21 -050041 set_fan_value "$hwmon_path" "${fan_tach_path[$j]}"
Duke Dudddc5012019-05-29 09:19:24 +080042 check_fail_flag=1
43 done
44 fi
45 current_fan_state=()
46 break
47 fi
48 current_fan_state=()
49 fi
50
51 #fans are going to normal.
Patrick Williams8c226232023-04-15 20:05:21 -050052 if [ "$i" -eq $((${#fan_tach_path[@]}-1)) ] && [ $check_fail_flag -eq 1 ]; then
Duke Dudddc5012019-05-29 09:19:24 +080053 check_fail_flag=0
54 systemctl restart phosphor-pid-control
55 fi
56 done
57 sleep 2
58done