summaryrefslogtreecommitdiffstats
path: root/meta-openbmc-machines/meta-openpower/common/recipes-phosphor/occ/openpower-occ-control/occ-active.sh
blob: 1a7b19b14bea125b8c4fc454749134f463966068 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
#!/bin/sh
# set and unset occ active for all occ's in system

if [ "$1" == "disable" ]; then
    value='false'
elif [ "$1" == "enable" ]; then
    value='true'
elif [ "$1" == "watchdog" ]; then
    value='true'
else
    echo "Usage: occ-active.sh [argument]"
    echo "  enable  - set occ's to active state"
    echo "  disable - set occ's to inactive state"
    exit -1
fi

if [ "$value" == "true" ]; then
	# Verify host IPL is complete
	while [ ! -e /run/openbmc/host@0-ipl-complete ]; do
		echo "Waiting for host IPL to complete before engaging OCC interface..."
		sleep 1
	done
fi

# Get CPU count
CPU_COUNT=1
STATUS_FLAGS=$(i2cget -y 12 0x31 0x7)
if [ $? != 0 ]; then
	STATUS_FLAGS=$(i2cget -y 12 0x31 0x7)
fi
if [ $? != 0 ]; then
	STATUS_FLAGS=$(i2cget -y 12 0x31 0x7)
fi
CPU_PRESENT_FLAG_N=$(( ${STATUS_FLAGS} & 0x20 ))
if [ $CPU_PRESENT_FLAG_N != 0 ]; then
	CPU_COUNT=$(( ${CPU_COUNT} + 1 ))
fi
echo "Found $CPU_COUNT CPU(s)"

OCC_CONTROL_SERVICE="org.open_power.OCC.Control"

if [ "$value" == "true" ]; then
	# Disable existing OCC service
	busctl tree $OCC_CONTROL_SERVICE --list | grep occ | xargs -r -n1 -I{} \
		busctl set-property $OCC_CONTROL_SERVICE {} org.open_power.OCC.Status \
		OccActive b 'false'

	# Rescan bus to find OCCs
	openpower-proc-control scanFSI
fi

busctl tree $OCC_CONTROL_SERVICE --list | grep occ | xargs -r -n1 -I{} \
	busctl set-property $OCC_CONTROL_SERVICE {} org.open_power.OCC.Status \
	OccActive b $value

if [ "$value" == "true" ]; then
	# Wait 5 seconds before restarting fan controller
	sleep 5
	systemctl restart phosphor-fan-control@0.service
else
        # Unbind all OCC drivers to avoid bus contention on next IPL
	echo occ1-dev0 > /sys/bus/platform/drivers/occ-hwmon/unbind || true
	echo occ2-dev0 > /sys/bus/platform/drivers/occ-hwmon/unbind || true
	echo sbefifo1-dev0 > /sys/bus/platform/drivers/occ/unbind || true
	echo sbefifo2-dev0 > /sys/bus/platform/drivers/occ/unbind || true
fi

if [ "$1" == "watchdog" ]; then
	# Start watchdog
	while [ 1 == 1 ]; do
		sleep 5

		OCC_FAULT=0
		if [ ! -e /sys/bus/platform/drivers/occ/sbefifo1-dev0/occ1-dev0/occ_error ]; then
			OCC_FAULT=1
		else
			STATUS=$(cat /sys/bus/platform/drivers/occ/sbefifo1-dev0/occ1-dev0/occ_error)
			if [ $STATUS != 0 ]; then
				OCC_FAULT=1
			fi
		fi
		if [ $CPU_COUNT -gt 1 ]; then
			if [ ! -e /sys/bus/platform/drivers/occ/sbefifo2-dev0/occ2-dev0/occ_error ]; then
				OCC_FAULT=1
			fi
		else
			if [ $STATUS != 0 ]; then
				OCC_FAULT=1
			fi
		fi

		if [ $OCC_FAULT != 0 ]; then
			# OCC driver failed.  Rescan bus to recover.
			# Disable existing OCC service
			busctl tree $OCC_CONTROL_SERVICE --list | grep occ | xargs -r -n1 -I{} \
				busctl set-property $OCC_CONTROL_SERVICE {} org.open_power.OCC.Status \
				OccActive b 'false'
			# Give enough time for the OCC control service to attempt unload before forcible unbind
			sleep 5
			# Unbind all OCC drivers
			echo occ1-dev0 > /sys/bus/platform/drivers/occ-hwmon/unbind || true
			echo occ2-dev0 > /sys/bus/platform/drivers/occ-hwmon/unbind || true
			echo sbefifo1-dev0 > /sys/bus/platform/drivers/occ/unbind || true
			echo sbefifo2-dev0 > /sys/bus/platform/drivers/occ/unbind || true
			# Wait 10 seconds for OCC to figure out something has happened / bus contention to stop
			sleep 10
			openpower-proc-control scanFSI
			# Re-enable OCC service
			busctl tree $OCC_CONTROL_SERVICE --list | grep occ | xargs -r -n1 -I{} \
				busctl set-property $OCC_CONTROL_SERVICE {} org.open_power.OCC.Status \
				OccActive b 'true'
			# Give the OCC service time to start
			sleep 5
			# Restart fan controller
			systemctl restart phosphor-fan-control@0.service
		fi
	done
fi

exit 0
OpenPOWER on IntegriCloud