Skip to content

Commit

Permalink
[DELLEMC][S6000] 201811 Porting of Platform 2.0 Reboot Reason (#3156) (
Browse files Browse the repository at this point in the history
  • Loading branch information
sridhar-ravindran authored and jleveque committed Aug 7, 2019
1 parent 36c9d99 commit ba3d85e
Show file tree
Hide file tree
Showing 16 changed files with 310 additions and 78 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,89 +11,29 @@
# Short-Description: Setup S6000 board.
### END INIT INFO

add_i2c_devices() {

echo 24c02 0x50 > /sys/class/i2c-adapter/i2c-1/new_device
echo 24c02 0x51 > /sys/class/i2c-adapter/i2c-1/new_device
echo dni_dps460 0x58 > /sys/class/i2c-adapter/i2c-1/new_device
echo dni_dps460 0x59 > /sys/class/i2c-adapter/i2c-1/new_device
echo jc42 0x18 > /sys/class/i2c-adapter/i2c-10/new_device
echo emc1403 0x4d > /sys/class/i2c-adapter/i2c-10/new_device
echo spd 0x50 > /sys/class/i2c-adapter/i2c-10/new_device
echo 24c02 0x53 > /sys/class/i2c-adapter/i2c-10/new_device
echo max6620 0x29 > /sys/class/i2c-adapter/i2c-11/new_device
echo max6620 0x2a > /sys/class/i2c-adapter/i2c-11/new_device
echo ltc4215 0x40 > /sys/class/i2c-adapter/i2c-11/new_device
echo ltc4215 0x42 > /sys/class/i2c-adapter/i2c-11/new_device
echo tmp75 0x4c > /sys/class/i2c-adapter/i2c-11/new_device
echo tmp75 0x4d > /sys/class/i2c-adapter/i2c-11/new_device
echo tmp75 0x4e > /sys/class/i2c-adapter/i2c-11/new_device
echo 24c02 0x51 > /sys/class/i2c-adapter/i2c-11/new_device
echo 24c02 0x52 > /sys/class/i2c-adapter/i2c-11/new_device
echo 24c02 0x53 > /sys/class/i2c-adapter/i2c-11/new_device
for i in `seq 0 31`; do
echo sff8436 0x50 > /sys/class/i2c-adapter/i2c-$((20+i))/new_device
done
}

remove_i2c_devices() {
echo 0x50 > /sys/class/i2c-adapter/i2c-1/delete_device
echo 0x51 > /sys/class/i2c-adapter/i2c-1/delete_device
echo 0x58 > /sys/class/i2c-adapter/i2c-1/delete_device
echo 0x59 > /sys/class/i2c-adapter/i2c-1/delete_device
echo 0x18 > /sys/class/i2c-adapter/i2c-10/delete_device
echo 0x4d > /sys/class/i2c-adapter/i2c-10/delete_device
echo 0x50 > /sys/class/i2c-adapter/i2c-10/delete_device
echo 0x53 > /sys/class/i2c-adapter/i2c-10/delete_device
echo 0x29 > /sys/class/i2c-adapter/i2c-11/delete_device
echo 0x2a > /sys/class/i2c-adapter/i2c-11/delete_device
echo 0x40 > /sys/class/i2c-adapter/i2c-11/delete_device
echo 0x42 > /sys/class/i2c-adapter/i2c-11/delete_device
echo 0x4c > /sys/class/i2c-adapter/i2c-11/delete_device
echo 0x4d > /sys/class/i2c-adapter/i2c-11/delete_device
echo 0x4e > /sys/class/i2c-adapter/i2c-11/delete_device
echo 0x51 > /sys/class/i2c-adapter/i2c-11/delete_device
echo 0x52 > /sys/class/i2c-adapter/i2c-11/delete_device
echo 0x53 > /sys/class/i2c-adapter/i2c-11/delete_device
for i in `seq 0 31`; do
echo 0x50 > /sys/class/i2c-adapter/i2c-$((20+i))/delete_device
done
}

case "$1" in
start)
echo -n "Setting up board... "

depmod -a
modprobe i2c_mux_gpio
modprobe dell_s6000_platform
echo -n "Setting up board... "

add_i2c_devices
/usr/local/bin/s6000_platform.sh init

/usr/local/bin/set-fan-speed 15000
/usr/local/bin/reset-qsfp

echo "done."
;;
echo "done."
;;

stop)
echo "done."

remove_i2c_devices
/usr/local/bin/s6000_platform.sh deinit
echo "done."

rmmod dell_s6000_platform
rmmod i2c_mux_gpio
;;
;;

force-reload|restart)
echo "Not supported"
;;
echo "Not supported"
;;

*)
echo "Usage: /etc/init.d/platform-modules-s6000.init {start|stop}"
exit 1
;;
echo "Usage: /etc/init.d/platform-modules-s6000.init {start|stop}"
exit 1
;;
esac

exit 0

Original file line number Diff line number Diff line change
@@ -1,2 +1,6 @@
s6000/scripts/s6000_platform.sh usr/local/bin
s6000/scripts/reset-qsfp usr/local/bin
s6000/scripts/set-fan-speed usr/local/bin
s6000/systemd/platform-modules-s6000.service etc/systemd/system
common/io_rd_wr.py usr/local/bin
s6000/modules/sonic_platform-1.0-py2-none-any.whl usr/share/sonic/device/x86_64-dell_s6000_s1220-r0
8 changes: 8 additions & 0 deletions platform/broadcom/sonic-platform-modules-dell/debian/rules
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,10 @@ override_dh_auto_build:
cd $(MOD_SRC_DIR)/$${mod}; \
python2.7 setup.py bdist_wheel -d $(MOD_SRC_DIR)/$${mod}/modules; \
cd $(MOD_SRC_DIR); \
elif [ $$mod = "s6000" ]; then \
cd $(MOD_SRC_DIR)/$${mod}; \
python2.7 setup.py bdist_wheel -d $(MOD_SRC_DIR)/$${mod}/modules; \
cd $(MOD_SRC_DIR); \
fi; \
echo "making man page alias $$mod -> $$mod APIs";\
make -C $(KERNEL_SRC)/build M=$(MOD_SRC_DIR)/$${mod}/modules; \
Expand Down Expand Up @@ -59,6 +63,10 @@ override_dh_clean:
rm -f $(MOD_SRC_DIR)/$${mod}/modules/*.whl; \
rm -rf $(MOD_SRC_DIR)/$${mod}/build; \
rm -rf $(MOD_SRC_DIR)/$${mod}/build/*.egg-info; \
elif [ $$mod = "s6000" ]; then \
rm -f $(MOD_SRC_DIR)/$${mod}/modules/*.whl; \
rm -rf $(MOD_SRC_DIR)/$${mod}/build; \
rm -rf $(MOD_SRC_DIR)/$${mod}/build/*.egg-info; \
fi; \
make -C $(KERNEL_SRC)/build M=$(MOD_SRC_DIR)/$${mod}/modules clean; \
done)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
#include <linux/platform_device.h>
#include <linux/i2c/sff-8436.h>
#include <linux/delay.h>
#include <linux/gpio.h>
#include <linux/nvram.h>

#define S6000_MUX_BASE_NR 10
#define QSFP_MODULE_BASE_NR 20
Expand All @@ -20,6 +22,7 @@
#define QSFP_MODULE_NUM 16
#define QSFP_DEVICE_NUM 2

#define RTC_NVRAM_REBOOT_REASON_OFFSET 0x49

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

static ssize_t get_reboot_reason(struct device *dev,
struct device_attribute *devattr, char *buf)
{
uint8_t data = 0;

/* Last Reboot reason in saved in RTC NVRAM offset 0x49
* We write the reboot reason into nvram offset,
* as part of platform_reboot implementation from userspace.
* COLD_RESET = 0xE # Cold Reset (value)
* WARM_RESET = 0x6 # Warm Reset (value)
*/

/* Read it from this offset, and export it as last_reboot_reason */
data = nvram_read_byte(RTC_NVRAM_REBOOT_REASON_OFFSET);

return sprintf(buf, "0x%x\n", data);
}

static DEVICE_ATTR(qsfp_modsel, S_IRUGO, get_modsel, NULL);
static DEVICE_ATTR(qsfp_modprs, S_IRUGO, get_modprs, NULL);
Expand All @@ -1083,6 +1104,7 @@ static DEVICE_ATTR(fan2_led, S_IRUGO | S_IWUSR, get_fan2_led, set_fan2_led);
static DEVICE_ATTR(system_cpld_ver, S_IRUGO, get_system_cpld_ver, NULL);
static DEVICE_ATTR(master_cpld_ver, S_IRUGO, get_master_cpld_ver, NULL);
static DEVICE_ATTR(slave_cpld_ver, S_IRUGO, get_slave_cpld_ver, NULL);
static DEVICE_ATTR(last_reboot_reason, S_IRUGO, get_reboot_reason, NULL);

static struct attribute *s6000_cpld_attrs[] = {
&dev_attr_qsfp_modsel.attr,
Expand All @@ -1106,6 +1128,7 @@ static struct attribute *s6000_cpld_attrs[] = {
&dev_attr_system_cpld_ver.attr,
&dev_attr_master_cpld_ver.attr,
&dev_attr_slave_cpld_ver.attr,
&dev_attr_last_reboot_reason.attr,
NULL,
};

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
#!/bin/bash

### BEGIN INIT INFO
# Provides: setup-board
# Required-Start:
# Required-Stop:
# Should-Start:
# Should-Stop:
# Default-Start: S
# Default-Stop: 0 6
# Short-Description: Setup S6000 board.
### END INIT INFO

add_i2c_devices() {

echo 24c02 0x50 > /sys/class/i2c-adapter/i2c-1/new_device
echo 24c02 0x51 > /sys/class/i2c-adapter/i2c-1/new_device
echo dni_dps460 0x58 > /sys/class/i2c-adapter/i2c-1/new_device
echo dni_dps460 0x59 > /sys/class/i2c-adapter/i2c-1/new_device
echo jc42 0x18 > /sys/class/i2c-adapter/i2c-10/new_device
echo emc1403 0x4d > /sys/class/i2c-adapter/i2c-10/new_device
echo spd 0x50 > /sys/class/i2c-adapter/i2c-10/new_device
echo 24c02 0x53 > /sys/class/i2c-adapter/i2c-10/new_device
echo max6620 0x29 > /sys/class/i2c-adapter/i2c-11/new_device
echo max6620 0x2a > /sys/class/i2c-adapter/i2c-11/new_device
echo ltc4215 0x40 > /sys/class/i2c-adapter/i2c-11/new_device
echo ltc4215 0x42 > /sys/class/i2c-adapter/i2c-11/new_device
echo tmp75 0x4c > /sys/class/i2c-adapter/i2c-11/new_device
echo tmp75 0x4d > /sys/class/i2c-adapter/i2c-11/new_device
echo tmp75 0x4e > /sys/class/i2c-adapter/i2c-11/new_device
echo 24c02 0x51 > /sys/class/i2c-adapter/i2c-11/new_device
echo 24c02 0x52 > /sys/class/i2c-adapter/i2c-11/new_device
echo 24c02 0x53 > /sys/class/i2c-adapter/i2c-11/new_device
for i in `seq 0 31`; do
echo sff8436 0x50 > /sys/class/i2c-adapter/i2c-$((20+i))/new_device
done
}

remove_i2c_devices() {
echo 0x50 > /sys/class/i2c-adapter/i2c-1/delete_device
echo 0x51 > /sys/class/i2c-adapter/i2c-1/delete_device
echo 0x58 > /sys/class/i2c-adapter/i2c-1/delete_device
echo 0x59 > /sys/class/i2c-adapter/i2c-1/delete_device
echo 0x18 > /sys/class/i2c-adapter/i2c-10/delete_device
echo 0x4d > /sys/class/i2c-adapter/i2c-10/delete_device
echo 0x50 > /sys/class/i2c-adapter/i2c-10/delete_device
echo 0x53 > /sys/class/i2c-adapter/i2c-10/delete_device
echo 0x29 > /sys/class/i2c-adapter/i2c-11/delete_device
echo 0x2a > /sys/class/i2c-adapter/i2c-11/delete_device
echo 0x40 > /sys/class/i2c-adapter/i2c-11/delete_device
echo 0x42 > /sys/class/i2c-adapter/i2c-11/delete_device
echo 0x4c > /sys/class/i2c-adapter/i2c-11/delete_device
echo 0x4d > /sys/class/i2c-adapter/i2c-11/delete_device
echo 0x4e > /sys/class/i2c-adapter/i2c-11/delete_device
echo 0x51 > /sys/class/i2c-adapter/i2c-11/delete_device
echo 0x52 > /sys/class/i2c-adapter/i2c-11/delete_device
echo 0x53 > /sys/class/i2c-adapter/i2c-11/delete_device
for i in `seq 0 31`; do
echo 0x50 > /sys/class/i2c-adapter/i2c-$((20+i))/delete_device
done
}

install_python_api_package() {
device="/usr/share/sonic/device"
platform=$(/usr/local/bin/sonic-cfggen -H -v DEVICE_METADATA.localhost.platform)

if [ -e $device/$platform/sonic_platform-1.0-py2-none-any.whl ]; then
rv=$(pip install $device/$platform/sonic_platform-1.0-py2-none-any.whl)
fi
}

remove_python_api_package() {
rv=$(pip show sonic-platform > /dev/null 2>/dev/null)
if [ $? -eq 0 ]; then
rv = $(pip uninstall -y sonic-platform > /dev/null 2>/dev/null)
fi
}

if [[ "$1" == "init" ]]; then
depmod -a
modprobe nvram
modprobe i2c_mux_gpio
modprobe dell_s6000_platform
install_python_api_package

add_i2c_devices

/usr/local/bin/set-fan-speed 15000
/usr/local/bin/reset-qsfp
elif [[ "$1" == "deinit" ]]; then
remove_i2c_devices
rmmod dell_s6000_platform
rmmod nvram
rmmod i2c_mux_gpio
remove_python_api_package
else
echo "s6000_platform : Invalid option !"
fi
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
__all__ = ["platform", "chassis"]
from sonic_platform import *
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
#!/usr/bin/env python

#############################################################################
#
# Module contains an implementation of SONiC Platform Base API and
# provides the platform information
#
#############################################################################

try:
import os
from sonic_platform_base.chassis_base import ChassisBase
except ImportError as e:
raise ImportError(str(e) + "- required module not found")


class Chassis(ChassisBase):
"""
DELLEMC Platform-specific Chassis class
"""

MAILBOX_DIR = "/sys/devices/platform/dell-s6000-cpld.0"

reset_reason_dict = {}
reset_reason_dict[0xe] = ChassisBase.REBOOT_CAUSE_NON_HARDWARE
reset_reason_dict[0x6] = ChassisBase.REBOOT_CAUSE_NON_HARDWARE

def __init__(self):
ChassisBase.__init__(self)

def get_register(self, reg_name):
rv = 'ERR'
mb_reg_file = self.MAILBOX_DIR+'/'+reg_name

if (not os.path.isfile(mb_reg_file)):
return rv

try:
with open(mb_reg_file, 'r') as fd:
rv = fd.read()
except Exception as error:
rv = 'ERR'

rv = rv.rstrip('\r\n')
rv = rv.lstrip(" ")
return rv

def get_reboot_cause(self):
"""
Retrieves the cause of the previous reboot
"""
reset_reason = int(self.get_register('last_reboot_reason'), base=16)

# In S6000, We track the reboot reason by writing the reason in
# NVRAM. Only Warmboot and Coldboot reason are supported here.

if (reset_reason in self.reset_reason_dict):
return (self.reset_reason_dict[reset_reason], None)

return (ChassisBase.REBOOT_CAUSE_HARDWARE_OTHER, "Invalid Reason")

Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#!/usr/bin/env python

#############################################################################
#
# Module contains an implementation of SONiC Platform Base API and
# provides the platform information
#
#############################################################################

try:
import os
from sonic_platform_base.platform_base import PlatformBase
from sonic_platform.chassis import Chassis
except ImportError as e:
raise ImportError(str(e) + "- required module not found")


class Platform(PlatformBase):
"""
DELLEMC Platform-specific class
"""

def __init__(self):
PlatformBase.__init__(self)
self._chassis = Chassis()

Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ Before=pmon.service

[Service]
Type=oneshot
ExecStart=-/etc/init.d/platform-modules-s6000 start
ExecStop=-/etc/init.d/platform-modules-s6000 stop
ExecStart=/usr/local/bin/s6000_platform.sh init
ExecStop=/usr/local/bin/s6000_platform.sh deinit
RemainAfterExit=yes

[Install]
Expand Down
Loading

0 comments on commit ba3d85e

Please sign in to comment.