blob: 3ff3e1fc6a03199b2360842866d3f0cd988d3fae [file] [log] [blame]
Chanh Nguyencf71ae02021-06-11 17:05:38 +07001#!/bin/sh
2
3# When system only use single PSU ( ex : PSU1 ) to power ON normal 12V,
4# HSC2 will be trigged Fault event (FET health).
5# At this time, to plug-in PSU2 in system, PSU2 won't deliver power to
6# +12V_MB because HSC2 is protected by Fault event.
7# Due to HSC2 protected, the PSU redundancy mechanism can't be created.
8# Once PSU1 is plugged out at this moment, system will crash ( reset )
9# because +12V_MB dropped.
10
11# BMC SW work-around solution:
12# - When BMC detect event PSU is plugged in system, BMC will reset HSC
13# by disbale HOT SWAP and then enable HOT SWAP through pmbus command to clear
14# Fault event.
15
16# Note:
17# In case hot swap occurs during BMC reset, BMC still not in operation state,
18# BMC can't detect PSU plug/unplug, then the work-around won't be executed
19
20# Author: Chanh Nguyen <chnguyen@amperecomputing.com>
21
22HSC1_PMBUS_NUM=10
23HSC2_PMBUS_NUM=10
24HSC1_SLAVE_ADDR=0x10
25HSC2_SLAVE_ADDR=0x11
26OPERATION=0x01
27STATUS_MFR_SPECIFIC=0x80
28
29# $1 will be the name of the psu
30PSU=$1
31
Thang Q. Nguyenbd7d6332021-12-06 10:18:21 +000032if [ "$PSU" = 0 ]; then
Chanh Nguyencf71ae02021-06-11 17:05:38 +070033 HSC_PMBUS_NUM=$HSC1_PMBUS_NUM
34 HSC_SLAVE_ADDR=$HSC1_SLAVE_ADDR
Thang Q. Nguyenbd7d6332021-12-06 10:18:21 +000035elif [ "$PSU" = 1 ]; then
Chanh Nguyencf71ae02021-06-11 17:05:38 +070036 HSC_PMBUS_NUM=$HSC2_PMBUS_NUM
37 HSC_SLAVE_ADDR=$HSC2_SLAVE_ADDR
38else
Thang Q. Nguyenbd7d6332021-12-06 10:18:21 +000039 echo "Please choose PSU1 (0) or PSU2 (1)"
40 echo "Ex: ampere_psu_reset_hotswap.sh 0"
Chanh Nguyencf71ae02021-06-11 17:05:38 +070041 exit 0
42fi
43
44# Check HOST state
45chassisstate=$(obmcutil chassisstate | awk -F. '{print $NF}')
Thang Q. Nguyendde1fed2021-11-04 08:30:27 +000046if [ "$chassisstate" = 'Off' ]; then
Chanh Nguyencf71ae02021-06-11 17:05:38 +070047 echo "HOST is being OFF, so can't access the i2c $HSC_PMBUS_NUM. Please Turn ON HOST !"
48 exit 1
49fi
50
51# Check FET health problems
Thang Q. Nguyendde1fed2021-11-04 08:30:27 +000052if ! data=$(i2cget -f -y $HSC_PMBUS_NUM $HSC_SLAVE_ADDR $STATUS_MFR_SPECIFIC); then
Chanh Nguyencf71ae02021-06-11 17:05:38 +070053 echo "ERROR: Can't access the i2c. Please check /dev/i2c-$HSC_PMBUS_NUM"
54 exit 1
55fi
56
57psu_sts=$(((data & 0x80) != 0))
58
Thang Q. Nguyendde1fed2021-11-04 08:30:27 +000059if [ $psu_sts = 1 ]; then
Chanh Nguyencf71ae02021-06-11 17:05:38 +070060 echo "PSU $PSU: FET health problems have been detected"
61 echo "Reset Hot swap output on PSU $PSU"
62 # Disable Hot swap output
63 write_data=0x00
64 i2cset -f -y $HSC_PMBUS_NUM $HSC_SLAVE_ADDR $OPERATION $write_data b
65
66 # Enable Hot swap output
67 write_data=0x80;
68 i2cset -f -y $HSC_PMBUS_NUM $HSC_SLAVE_ADDR $OPERATION $write_data b
69
70else
71 echo "PSU $PSU: FET health problems have not been detected"
Thang Q. Nguyendde1fed2021-11-04 08:30:27 +000072fi