Skip to content

Commit ba3d85e

Browse files
sridhar-ravindranjleveque
authored andcommitted
[DELLEMC][S6000] 201811 Porting of Platform 2.0 Reboot Reason (#3156) (#3286)
1 parent 36c9d99 commit ba3d85e

File tree

16 files changed

+310
-78
lines changed

16 files changed

+310
-78
lines changed

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

+12-72
Original file line numberDiff line numberDiff line change
@@ -11,89 +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
16+
echo -n "Setting up board... "
7017

71-
add_i2c_devices
18+
/usr/local/bin/s6000_platform.sh init
7219

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

7923
stop)
80-
echo "done."
81-
82-
remove_i2c_devices
24+
/usr/local/bin/s6000_platform.sh deinit
25+
echo "done."
8326

84-
rmmod dell_s6000_platform
85-
rmmod i2c_mux_gpio
86-
;;
27+
;;
8728

8829
force-reload|restart)
89-
echo "Not supported"
90-
;;
30+
echo "Not supported"
31+
;;
9132

9233
*)
93-
echo "Usage: /etc/init.d/platform-modules-s6000.init {start|stop}"
94-
exit 1
95-
;;
34+
echo "Usage: /etc/init.d/platform-modules-s6000.init {start|stop}"
35+
exit 1
36+
;;
9637
esac
9738

9839
exit 0
99-
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
@@ -9,6 +9,8 @@
99
#include <linux/platform_device.h>
1010
#include <linux/i2c/sff-8436.h>
1111
#include <linux/delay.h>
12+
#include <linux/gpio.h>
13+
#include <linux/nvram.h>
1214

1315
#define S6000_MUX_BASE_NR 10
1416
#define QSFP_MODULE_BASE_NR 20
@@ -20,6 +22,7 @@
2022
#define QSFP_MODULE_NUM 16
2123
#define QSFP_DEVICE_NUM 2
2224

25+
#define RTC_NVRAM_REBOOT_REASON_OFFSET 0x49
2326

2427
static void device_release(struct device *dev)
2528
{
@@ -1061,6 +1064,24 @@ static ssize_t get_slave_cpld_ver(struct device *dev,
10611064
return sprintf(buf, "0x%x\n", data);
10621065
}
10631066

1067+
static ssize_t get_reboot_reason(struct device *dev,
1068+
struct device_attribute *devattr, char *buf)
1069+
{
1070+
uint8_t data = 0;
1071+
1072+
/* Last Reboot reason in saved in RTC NVRAM offset 0x49
1073+
* We write the reboot reason into nvram offset,
1074+
* as part of platform_reboot implementation from userspace.
1075+
1076+
* COLD_RESET = 0xE # Cold Reset (value)
1077+
* WARM_RESET = 0x6 # Warm Reset (value)
1078+
*/
1079+
1080+
/* Read it from this offset, and export it as last_reboot_reason */
1081+
data = nvram_read_byte(RTC_NVRAM_REBOOT_REASON_OFFSET);
1082+
1083+
return sprintf(buf, "0x%x\n", data);
1084+
}
10641085

10651086
static DEVICE_ATTR(qsfp_modsel, S_IRUGO, get_modsel, NULL);
10661087
static DEVICE_ATTR(qsfp_modprs, S_IRUGO, get_modprs, NULL);
@@ -1083,6 +1104,7 @@ static DEVICE_ATTR(fan2_led, S_IRUGO | S_IWUSR, get_fan2_led, set_fan2_led);
10831104
static DEVICE_ATTR(system_cpld_ver, S_IRUGO, get_system_cpld_ver, NULL);
10841105
static DEVICE_ATTR(master_cpld_ver, S_IRUGO, get_master_cpld_ver, NULL);
10851106
static DEVICE_ATTR(slave_cpld_ver, S_IRUGO, get_slave_cpld_ver, NULL);
1107+
static DEVICE_ATTR(last_reboot_reason, S_IRUGO, get_reboot_reason, NULL);
10861108

10871109
static struct attribute *s6000_cpld_attrs[] = {
10881110
&dev_attr_qsfp_modsel.attr,
@@ -1106,6 +1128,7 @@ static struct attribute *s6000_cpld_attrs[] = {
11061128
&dev_attr_system_cpld_ver.attr,
11071129
&dev_attr_master_cpld_ver.attr,
11081130
&dev_attr_slave_cpld_ver.attr,
1131+
&dev_attr_last_reboot_reason.attr,
11091132
NULL,
11101133
};
11111134

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)