Skip to content

Commit 95558ad

Browse files
sridhar-ravindranlguohan
authored andcommitted
[DELLEMC][S6000] Platform 2.0 Reboot Reason and fixed issue in process-reboot-cause (#3156)
Added Reboot Reason for S6000 in platform 2.0 Fixed issue in process-reboot-cause Added package uninstall code in platform de-init code for z9100, s6100 - How I did it -> Added support for S6000 Reboot Reason -> Added platform.py for all platforms -> Verified show reboot-cause command with the code changes. Added UT logs with show reboot-cause -> Modified process-reboot-cause service to start after pmon.service. In S6000, we have to wait for nvram to be loaded. -> If reboot-cause service starts before pmon.service, show reboot-cause is showing incorrect reason. -> Bug fix in process-reboot-cause file - import sonic_platform + import sonic_platform.platform
1 parent efe9438 commit 95558ad

File tree

16 files changed

+309
-80
lines changed

16 files changed

+309
-80
lines changed

platform/broadcom/sonic-platform-modules-dell/debian/platform-modules-s6000.init

+12-74
Original file line numberDiff line numberDiff line change
@@ -11,91 +11,29 @@
1111
# Short-Description: Setup S6000 board.
1212
### END INIT INFO
1313

14-
add_i2c_devices() {
15-
16-
echo 24c02 0x50 > /sys/class/i2c-adapter/i2c-1/new_device
17-
echo 24c02 0x51 > /sys/class/i2c-adapter/i2c-1/new_device
18-
echo dni_dps460 0x58 > /sys/class/i2c-adapter/i2c-1/new_device
19-
echo dni_dps460 0x59 > /sys/class/i2c-adapter/i2c-1/new_device
20-
echo jc42 0x18 > /sys/class/i2c-adapter/i2c-10/new_device
21-
echo emc1403 0x4d > /sys/class/i2c-adapter/i2c-10/new_device
22-
echo spd 0x50 > /sys/class/i2c-adapter/i2c-10/new_device
23-
echo 24c02 0x53 > /sys/class/i2c-adapter/i2c-10/new_device
24-
echo max6620 0x29 > /sys/class/i2c-adapter/i2c-11/new_device
25-
echo max6620 0x2a > /sys/class/i2c-adapter/i2c-11/new_device
26-
echo ltc4215 0x40 > /sys/class/i2c-adapter/i2c-11/new_device
27-
echo ltc4215 0x42 > /sys/class/i2c-adapter/i2c-11/new_device
28-
echo tmp75 0x4c > /sys/class/i2c-adapter/i2c-11/new_device
29-
echo tmp75 0x4d > /sys/class/i2c-adapter/i2c-11/new_device
30-
echo tmp75 0x4e > /sys/class/i2c-adapter/i2c-11/new_device
31-
echo 24c02 0x51 > /sys/class/i2c-adapter/i2c-11/new_device
32-
echo 24c02 0x52 > /sys/class/i2c-adapter/i2c-11/new_device
33-
echo 24c02 0x53 > /sys/class/i2c-adapter/i2c-11/new_device
34-
for i in `seq 0 31`; do
35-
echo sff8436 0x50 > /sys/class/i2c-adapter/i2c-$((20+i))/new_device
36-
done
37-
}
38-
39-
remove_i2c_devices() {
40-
echo 0x50 > /sys/class/i2c-adapter/i2c-1/delete_device
41-
echo 0x51 > /sys/class/i2c-adapter/i2c-1/delete_device
42-
echo 0x58 > /sys/class/i2c-adapter/i2c-1/delete_device
43-
echo 0x59 > /sys/class/i2c-adapter/i2c-1/delete_device
44-
echo 0x18 > /sys/class/i2c-adapter/i2c-10/delete_device
45-
echo 0x4d > /sys/class/i2c-adapter/i2c-10/delete_device
46-
echo 0x50 > /sys/class/i2c-adapter/i2c-10/delete_device
47-
echo 0x53 > /sys/class/i2c-adapter/i2c-10/delete_device
48-
echo 0x29 > /sys/class/i2c-adapter/i2c-11/delete_device
49-
echo 0x2a > /sys/class/i2c-adapter/i2c-11/delete_device
50-
echo 0x40 > /sys/class/i2c-adapter/i2c-11/delete_device
51-
echo 0x42 > /sys/class/i2c-adapter/i2c-11/delete_device
52-
echo 0x4c > /sys/class/i2c-adapter/i2c-11/delete_device
53-
echo 0x4d > /sys/class/i2c-adapter/i2c-11/delete_device
54-
echo 0x4e > /sys/class/i2c-adapter/i2c-11/delete_device
55-
echo 0x51 > /sys/class/i2c-adapter/i2c-11/delete_device
56-
echo 0x52 > /sys/class/i2c-adapter/i2c-11/delete_device
57-
echo 0x53 > /sys/class/i2c-adapter/i2c-11/delete_device
58-
for i in `seq 0 31`; do
59-
echo 0x50 > /sys/class/i2c-adapter/i2c-$((20+i))/delete_device
60-
done
61-
}
62-
6314
case "$1" in
6415
start)
65-
echo -n "Setting up board... "
66-
67-
depmod -a
68-
modprobe i2c_mux_gpio
69-
modprobe dell_s6000_platform
70-
modprobe nvram
16+
echo -n "Setting up board... "
7117

72-
add_i2c_devices
18+
/usr/local/bin/s6000_platform.sh init
7319

74-
/usr/local/bin/set-fan-speed 15000
75-
/usr/local/bin/reset-qsfp
76-
77-
echo "done."
78-
;;
20+
echo "done."
21+
;;
7922

8023
stop)
81-
echo "done."
82-
83-
remove_i2c_devices
24+
/usr/local/bin/s6000_platform.sh deinit
25+
echo "done."
8426

85-
rmmod nvram
86-
rmmod dell_s6000_platform
87-
rmmod i2c_mux_gpio
88-
;;
27+
;;
8928

9029
force-reload|restart)
91-
echo "Not supported"
92-
;;
30+
echo "Not supported"
31+
;;
9332

9433
*)
95-
echo "Usage: /etc/init.d/platform-modules-s6000.init {start|stop}"
96-
exit 1
97-
;;
34+
echo "Usage: /etc/init.d/platform-modules-s6000.init {start|stop}"
35+
exit 1
36+
;;
9837
esac
9938

10039
exit 0
101-
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,6 @@
1+
s6000/scripts/s6000_platform.sh usr/local/bin
2+
s6000/scripts/reset-qsfp usr/local/bin
3+
s6000/scripts/set-fan-speed usr/local/bin
14
s6000/systemd/platform-modules-s6000.service etc/systemd/system
25
common/io_rd_wr.py usr/local/bin
6+
s6000/modules/sonic_platform-1.0-py2-none-any.whl usr/share/sonic/device/x86_64-dell_s6000_s1220-r0

platform/broadcom/sonic-platform-modules-dell/debian/rules

+8
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,10 @@ override_dh_auto_build:
2525
cd $(MOD_SRC_DIR)/$${mod}; \
2626
python2.7 setup.py bdist_wheel -d $(MOD_SRC_DIR)/$${mod}/modules; \
2727
cd $(MOD_SRC_DIR); \
28+
elif [ $$mod = "s6000" ]; then \
29+
cd $(MOD_SRC_DIR)/$${mod}; \
30+
python2.7 setup.py bdist_wheel -d $(MOD_SRC_DIR)/$${mod}/modules; \
31+
cd $(MOD_SRC_DIR); \
2832
fi; \
2933
echo "making man page alias $$mod -> $$mod APIs";\
3034
make -C $(KERNEL_SRC)/build M=$(MOD_SRC_DIR)/$${mod}/modules; \
@@ -59,6 +63,10 @@ override_dh_clean:
5963
rm -f $(MOD_SRC_DIR)/$${mod}/modules/*.whl; \
6064
rm -rf $(MOD_SRC_DIR)/$${mod}/build; \
6165
rm -rf $(MOD_SRC_DIR)/$${mod}/build/*.egg-info; \
66+
elif [ $$mod = "s6000" ]; then \
67+
rm -f $(MOD_SRC_DIR)/$${mod}/modules/*.whl; \
68+
rm -rf $(MOD_SRC_DIR)/$${mod}/build; \
69+
rm -rf $(MOD_SRC_DIR)/$${mod}/build/*.egg-info; \
6270
fi; \
6371
make -C $(KERNEL_SRC)/build M=$(MOD_SRC_DIR)/$${mod}/modules clean; \
6472
done)

platform/broadcom/sonic-platform-modules-dell/s6000/modules/dell_s6000_platform.c

+23
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
#include <linux/i2c/sff-8436.h>
1111
#include <linux/delay.h>
1212
#include <linux/gpio.h>
13+
#include <linux/nvram.h>
1314

1415
#define S6000_MUX_BASE_NR 10
1516
#define QSFP_MODULE_BASE_NR 20
@@ -23,6 +24,8 @@
2324

2425
#define GPIO_I2C_MUX_PIN 10
2526

27+
#define RTC_NVRAM_REBOOT_REASON_OFFSET 0x49
28+
2629
static void device_release(struct device *dev)
2730
{
2831
return;
@@ -1094,6 +1097,24 @@ static ssize_t get_slave_cpld_ver(struct device *dev,
10941097
return sprintf(buf, "0x%x\n", data);
10951098
}
10961099

1100+
static ssize_t get_reboot_reason(struct device *dev,
1101+
struct device_attribute *devattr, char *buf)
1102+
{
1103+
uint8_t data = 0;
1104+
1105+
/* Last Reboot reason in saved in RTC NVRAM offset 0x49
1106+
* We write the reboot reason into nvram offset,
1107+
* as part of platform_reboot implementation from userspace.
1108+
1109+
* COLD_RESET = 0xE # Cold Reset (value)
1110+
* WARM_RESET = 0x6 # Warm Reset (value)
1111+
*/
1112+
1113+
/* Read it from this offset, and export it as last_reboot_reason */
1114+
data = nvram_read_byte(RTC_NVRAM_REBOOT_REASON_OFFSET);
1115+
1116+
return sprintf(buf, "0x%x\n", data);
1117+
}
10971118

10981119
static DEVICE_ATTR(qsfp_modsel, S_IRUGO, get_modsel, NULL);
10991120
static DEVICE_ATTR(qsfp_modprs, S_IRUGO, get_modprs, NULL);
@@ -1116,6 +1137,7 @@ static DEVICE_ATTR(fan2_led, S_IRUGO | S_IWUSR, get_fan2_led, set_fan2_led);
11161137
static DEVICE_ATTR(system_cpld_ver, S_IRUGO, get_system_cpld_ver, NULL);
11171138
static DEVICE_ATTR(master_cpld_ver, S_IRUGO, get_master_cpld_ver, NULL);
11181139
static DEVICE_ATTR(slave_cpld_ver, S_IRUGO, get_slave_cpld_ver, NULL);
1140+
static DEVICE_ATTR(last_reboot_reason, S_IRUGO, get_reboot_reason, NULL);
11191141

11201142
static struct attribute *s6000_cpld_attrs[] = {
11211143
&dev_attr_qsfp_modsel.attr,
@@ -1139,6 +1161,7 @@ static struct attribute *s6000_cpld_attrs[] = {
11391161
&dev_attr_system_cpld_ver.attr,
11401162
&dev_attr_master_cpld_ver.attr,
11411163
&dev_attr_slave_cpld_ver.attr,
1164+
&dev_attr_last_reboot_reason.attr,
11421165
NULL,
11431166
};
11441167

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
#!/bin/bash
2+
3+
### BEGIN INIT INFO
4+
# Provides: setup-board
5+
# Required-Start:
6+
# Required-Stop:
7+
# Should-Start:
8+
# Should-Stop:
9+
# Default-Start: S
10+
# Default-Stop: 0 6
11+
# Short-Description: Setup S6000 board.
12+
### END INIT INFO
13+
14+
add_i2c_devices() {
15+
16+
echo 24c02 0x50 > /sys/class/i2c-adapter/i2c-1/new_device
17+
echo 24c02 0x51 > /sys/class/i2c-adapter/i2c-1/new_device
18+
echo dni_dps460 0x58 > /sys/class/i2c-adapter/i2c-1/new_device
19+
echo dni_dps460 0x59 > /sys/class/i2c-adapter/i2c-1/new_device
20+
echo jc42 0x18 > /sys/class/i2c-adapter/i2c-10/new_device
21+
echo emc1403 0x4d > /sys/class/i2c-adapter/i2c-10/new_device
22+
echo spd 0x50 > /sys/class/i2c-adapter/i2c-10/new_device
23+
echo 24c02 0x53 > /sys/class/i2c-adapter/i2c-10/new_device
24+
echo max6620 0x29 > /sys/class/i2c-adapter/i2c-11/new_device
25+
echo max6620 0x2a > /sys/class/i2c-adapter/i2c-11/new_device
26+
echo ltc4215 0x40 > /sys/class/i2c-adapter/i2c-11/new_device
27+
echo ltc4215 0x42 > /sys/class/i2c-adapter/i2c-11/new_device
28+
echo tmp75 0x4c > /sys/class/i2c-adapter/i2c-11/new_device
29+
echo tmp75 0x4d > /sys/class/i2c-adapter/i2c-11/new_device
30+
echo tmp75 0x4e > /sys/class/i2c-adapter/i2c-11/new_device
31+
echo 24c02 0x51 > /sys/class/i2c-adapter/i2c-11/new_device
32+
echo 24c02 0x52 > /sys/class/i2c-adapter/i2c-11/new_device
33+
echo 24c02 0x53 > /sys/class/i2c-adapter/i2c-11/new_device
34+
for i in `seq 0 31`; do
35+
echo sff8436 0x50 > /sys/class/i2c-adapter/i2c-$((20+i))/new_device
36+
done
37+
}
38+
39+
remove_i2c_devices() {
40+
echo 0x50 > /sys/class/i2c-adapter/i2c-1/delete_device
41+
echo 0x51 > /sys/class/i2c-adapter/i2c-1/delete_device
42+
echo 0x58 > /sys/class/i2c-adapter/i2c-1/delete_device
43+
echo 0x59 > /sys/class/i2c-adapter/i2c-1/delete_device
44+
echo 0x18 > /sys/class/i2c-adapter/i2c-10/delete_device
45+
echo 0x4d > /sys/class/i2c-adapter/i2c-10/delete_device
46+
echo 0x50 > /sys/class/i2c-adapter/i2c-10/delete_device
47+
echo 0x53 > /sys/class/i2c-adapter/i2c-10/delete_device
48+
echo 0x29 > /sys/class/i2c-adapter/i2c-11/delete_device
49+
echo 0x2a > /sys/class/i2c-adapter/i2c-11/delete_device
50+
echo 0x40 > /sys/class/i2c-adapter/i2c-11/delete_device
51+
echo 0x42 > /sys/class/i2c-adapter/i2c-11/delete_device
52+
echo 0x4c > /sys/class/i2c-adapter/i2c-11/delete_device
53+
echo 0x4d > /sys/class/i2c-adapter/i2c-11/delete_device
54+
echo 0x4e > /sys/class/i2c-adapter/i2c-11/delete_device
55+
echo 0x51 > /sys/class/i2c-adapter/i2c-11/delete_device
56+
echo 0x52 > /sys/class/i2c-adapter/i2c-11/delete_device
57+
echo 0x53 > /sys/class/i2c-adapter/i2c-11/delete_device
58+
for i in `seq 0 31`; do
59+
echo 0x50 > /sys/class/i2c-adapter/i2c-$((20+i))/delete_device
60+
done
61+
}
62+
63+
install_python_api_package() {
64+
device="/usr/share/sonic/device"
65+
platform=$(/usr/local/bin/sonic-cfggen -H -v DEVICE_METADATA.localhost.platform)
66+
67+
if [ -e $device/$platform/sonic_platform-1.0-py2-none-any.whl ]; then
68+
rv=$(pip install $device/$platform/sonic_platform-1.0-py2-none-any.whl)
69+
fi
70+
}
71+
72+
remove_python_api_package() {
73+
rv=$(pip show sonic-platform > /dev/null 2>/dev/null)
74+
if [ $? -eq 0 ]; then
75+
rv = $(pip uninstall -y sonic-platform > /dev/null 2>/dev/null)
76+
fi
77+
}
78+
79+
if [[ "$1" == "init" ]]; then
80+
depmod -a
81+
modprobe nvram
82+
modprobe i2c_mux_gpio
83+
modprobe dell_s6000_platform
84+
install_python_api_package
85+
86+
add_i2c_devices
87+
88+
/usr/local/bin/set-fan-speed 15000
89+
/usr/local/bin/reset-qsfp
90+
elif [[ "$1" == "deinit" ]]; then
91+
remove_i2c_devices
92+
rmmod dell_s6000_platform
93+
rmmod nvram
94+
rmmod i2c_mux_gpio
95+
remove_python_api_package
96+
else
97+
echo "s6000_platform : Invalid option !"
98+
fi
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
../s6100/setup.py
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
__all__ = ["platform", "chassis"]
2+
from sonic_platform import *
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
#!/usr/bin/env python
2+
3+
#############################################################################
4+
#
5+
# Module contains an implementation of SONiC Platform Base API and
6+
# provides the platform information
7+
#
8+
#############################################################################
9+
10+
try:
11+
import os
12+
from sonic_platform_base.chassis_base import ChassisBase
13+
except ImportError as e:
14+
raise ImportError(str(e) + "- required module not found")
15+
16+
17+
class Chassis(ChassisBase):
18+
"""
19+
DELLEMC Platform-specific Chassis class
20+
"""
21+
22+
MAILBOX_DIR = "/sys/devices/platform/dell-s6000-cpld.0"
23+
24+
reset_reason_dict = {}
25+
reset_reason_dict[0xe] = ChassisBase.REBOOT_CAUSE_NON_HARDWARE
26+
reset_reason_dict[0x6] = ChassisBase.REBOOT_CAUSE_NON_HARDWARE
27+
28+
def __init__(self):
29+
ChassisBase.__init__(self)
30+
31+
def get_register(self, reg_name):
32+
rv = 'ERR'
33+
mb_reg_file = self.MAILBOX_DIR+'/'+reg_name
34+
35+
if (not os.path.isfile(mb_reg_file)):
36+
return rv
37+
38+
try:
39+
with open(mb_reg_file, 'r') as fd:
40+
rv = fd.read()
41+
except Exception as error:
42+
rv = 'ERR'
43+
44+
rv = rv.rstrip('\r\n')
45+
rv = rv.lstrip(" ")
46+
return rv
47+
48+
def get_reboot_cause(self):
49+
"""
50+
Retrieves the cause of the previous reboot
51+
"""
52+
reset_reason = int(self.get_register('last_reboot_reason'), base=16)
53+
54+
# In S6000, We track the reboot reason by writing the reason in
55+
# NVRAM. Only Warmboot and Coldboot reason are supported here.
56+
57+
if (reset_reason in self.reset_reason_dict):
58+
return (self.reset_reason_dict[reset_reason], None)
59+
60+
return (ChassisBase.REBOOT_CAUSE_HARDWARE_OTHER, "Invalid Reason")
61+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
#!/usr/bin/env python
2+
3+
#############################################################################
4+
#
5+
# Module contains an implementation of SONiC Platform Base API and
6+
# provides the platform information
7+
#
8+
#############################################################################
9+
10+
try:
11+
import os
12+
from sonic_platform_base.platform_base import PlatformBase
13+
from sonic_platform.chassis import Chassis
14+
except ImportError as e:
15+
raise ImportError(str(e) + "- required module not found")
16+
17+
18+
class Platform(PlatformBase):
19+
"""
20+
DELLEMC Platform-specific class
21+
"""
22+
23+
def __init__(self):
24+
PlatformBase.__init__(self)
25+
self._chassis = Chassis()
26+

platform/broadcom/sonic-platform-modules-dell/s6000/systemd/platform-modules-s6000.service

+2-2
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@ Before=pmon.service
55

66
[Service]
77
Type=oneshot
8-
ExecStart=-/etc/init.d/platform-modules-s6000 start
9-
ExecStop=-/etc/init.d/platform-modules-s6000 stop
8+
ExecStart=/usr/local/bin/s6000_platform.sh init
9+
ExecStop=/usr/local/bin/s6000_platform.sh deinit
1010
RemainAfterExit=yes
1111

1212
[Install]

0 commit comments

Comments
 (0)