George Hung | b5eef51 | 2021-03-10 16:04:46 +0800 | [diff] [blame] | 1 | #!/bin/bash |
| 2 | # Copyright 2021 Google LLC |
| 3 | # Copyright 2021 Quanta Computer Inc. |
| 4 | # |
| 5 | # Licensed under the Apache License, Version 2.0 (the "License"); |
| 6 | # you may not use this file except in compliance with the License. |
| 7 | # You may obtain a copy of the License at |
| 8 | # |
| 9 | # http://www.apache.org/licenses/LICENSE-2.0 |
| 10 | # |
| 11 | # Unless required by applicable law or agreed to in writing, software |
| 12 | # distributed under the License is distributed on an "AS IS" BASIS, |
| 13 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 14 | # See the License for the specific language governing permissions and |
| 15 | # limitations under the License. |
| 16 | |
| 17 | |
| 18 | target_pwm="$1" |
| 19 | |
| 20 | if [ -z "$target_pwm" ]; then |
| 21 | echo "Target_pwm is not set" >&2 |
| 22 | exit 1 |
| 23 | fi |
| 24 | |
| 25 | zone_num="$(busctl tree xyz.openbmc_project.State.FanCtrl | grep zone | wc -l)" |
| 26 | result=0 |
| 27 | |
| 28 | for (( i = 0; i < ${zone_num}; i++ )); do |
| 29 | retries=4 |
| 30 | busctl_error=-1 |
| 31 | |
| 32 | while (( retries > 0 )) && (( busctl_error != 0 )); do |
| 33 | busctl set-property xyz.openbmc_project.State.FanCtrl /xyz/openbmc_project/settings/fanctrl/zone${i} xyz.openbmc_project.Control.FanSpeed Target t "${target_pwm}" |
| 34 | busctl_error=$? |
| 35 | |
| 36 | if (( busctl_error != 0 )); then |
| 37 | #Retry setting failsafe. Swampd may be running but zone aren't yet built |
| 38 | #so sleep a second to let them be built |
| 39 | sleep 1 |
| 40 | fi |
| 41 | |
| 42 | let retries-=1 |
| 43 | done |
| 44 | |
| 45 | if (( busctl_error != 0 )); then |
| 46 | echo "Failure setting zone${i} fan failsafe to ${target_pwm}" >&2 |
| 47 | result=$busctl_error |
| 48 | else |
| 49 | echo "Setting zone${i} fan failsafe to ${target_pwm}" |
| 50 | fi |
| 51 | done |
| 52 | |
| 53 | exit $result |