[devices]: DELL Platform 2.0 API Infra and Reboot Reason support in Z9100 & S6100 (#3147)

This commit is contained in:
sridhar-ravindran 2019-07-24 03:52:16 +05:30 committed by lguohan
parent 7a9d04ee73
commit 148df177ba
12 changed files with 250 additions and 0 deletions

View File

@ -25,6 +25,24 @@ if [ -e /usr/share/sonic/platform/fancontrol ]; then
supervisorctl start fancontrol
fi
# If the sonic-platform package is not installed, try to install it
pip show sonic-platform > /dev/null 2>&1
if [ $? -ne 0 ]; then
SONIC_PLATFORM_WHEEL="/usr/share/sonic/platform/sonic_platform-1.0-py2-none-any.whl"
echo "sonic-platform package not installed, attempting to install..."
if [ -e ${SONIC_PLATFORM_WHEEL} ]; then
pip install ${SONIC_PLATFORM_WHEEL}
if [ $? -eq 0 ]; then
echo "Successfully installed ${SONIC_PLATFORM_WHEEL}"
else
echo "Error: Failed to install ${SONIC_PLATFORM_WHEEL}"
fi
else
echo "Error: Unable to locate ${SONIC_PLATFORM_WHEEL}"
fi
fi
supervisorctl start ledd
supervisorctl start xcvrd

View File

@ -8,3 +8,4 @@ common/platform_reboot usr/share/sonic/device/x86_64-dell_s6100_c2538-r0
s6100/scripts/platform_sensors.py usr/local/bin
s6100/scripts/sensors usr/bin
s6100/systemd/platform-modules-s6100.service etc/systemd/system
s6100/modules/sonic_platform-1.0-py2-none-any.whl usr/share/sonic/device/x86_64-dell_s6100_c2538-r0

View File

@ -7,5 +7,6 @@ common/fstrim.service etc/systemd/system
common/platform_reboot usr/share/sonic/device/x86_64-dell_z9100_c2538-r0
z9100/scripts/platform_sensors.py usr/local/bin
z9100/scripts/sensors usr/bin
z9100/modules/sonic_platform-1.0-py2-none-any.whl usr/share/sonic/device/x86_64-dell_z9100_c2538-r0
z9100/cfg/z9100-modules.conf etc/modules-load.d
z9100/systemd/platform-modules-z9100.service etc/systemd/system

View File

@ -16,9 +16,15 @@ override_dh_auto_build:
if [ $$mod = "s6100" ]; then \
cp $(COMMON_DIR)/dell_pmc.c $(MOD_SRC_DIR)/$${mod}/modules/dell_s6100_lpc.c; \
cp $(COMMON_DIR)/dell_ich.c $(MOD_SRC_DIR)/$${mod}/modules/dell_ich.c; \
cd $(MOD_SRC_DIR)/$${mod}; \
python2.7 setup.py bdist_wheel -d $(MOD_SRC_DIR)/$${mod}/modules; \
cd $(MOD_SRC_DIR); \
elif [ $$mod = "z9100" ]; then \
cp $(COMMON_DIR)/dell_pmc.c $(MOD_SRC_DIR)/$${mod}/modules/dell_mailbox.c; \
cp $(COMMON_DIR)/dell_ich.c $(MOD_SRC_DIR)/$${mod}/modules/dell_ich.c; \
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; \
@ -40,9 +46,15 @@ override_dh_clean:
if [ $$mod = "s6100" ]; then \
rm -f $(MOD_SRC_DIR)/$${mod}/modules/dell_s6100_lpc.c; \
rm -f $(MOD_SRC_DIR)/$${mod}/modules/dell_ich.c; \
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 = "z9100" ]; then \
rm -f $(MOD_SRC_DIR)/$${mod}/modules/dell_mailbox.c; \
rm -f $(MOD_SRC_DIR)/$${mod}/modules/dell_ich.c; \
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)

View File

@ -217,6 +217,14 @@ reset_muxes() {
io_rd_wr.py --set --val 0xff --offset 0x20b
}
install_python_api_package() {
device="/usr/share/sonic/device"
platform=$(/usr/local/bin/sonic-cfggen -H -v DEVICE_METADATA.localhost.platform)
rv=$(pip install $device/$platform/sonic_platform-1.0-py2-none-any.whl)
echo "pip install result = $rv"
}
init_devnum
if [[ "$1" == "init" ]]; then
@ -235,6 +243,9 @@ if [[ "$1" == "init" ]]; then
switch_board_qsfp "new_device"
switch_board_qsfp_lpmode "disable"
xcvr_presence_interrupts "enable"
install_python_api_package
elif [[ "$1" == "deinit" ]]; then
xcvr_presence_interrupts "disable"
switch_board_sfp "delete_device"

View File

@ -0,0 +1,30 @@
from setuptools import setup
setup(
name='sonic-platform',
version='1.0',
description='SONiC platform API implementation on DellEmc Platforms',
license='Apache 2.0',
author='SONiC Team',
author_email='linuxnetdev@microsoft.com',
url='https://github.com/Azure/sonic-buildimage',
maintainer='DellEMC',
maintainer_email='dell-sonic@dell.com',
packages=[
'sonic_platform',
],
classifiers=[
'Development Status :: 3 - Alpha',
'Environment :: Plugins',
'Intended Audience :: Developers',
'Intended Audience :: Information Technology',
'Intended Audience :: System Administrators',
'License :: OSI Approved :: Apache Software License',
'Natural Language :: English',
'Operating System :: POSIX :: Linux',
'Programming Language :: Python :: 2.7',
'Topic :: Utilities',
],
keywords='sonic SONiC platform PLATFORM',
)

View File

@ -0,0 +1,82 @@
#!/usr/bin/env python
#############################################################################
# DELLEMC
#
# 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
"""
HWMON_DIR = "/sys/devices/platform/SMF.512/hwmon/"
HWMON_NODE = os.listdir(HWMON_DIR)[0]
MAILBOX_DIR = HWMON_DIR + HWMON_NODE
reset_reason_dict = {}
reset_reason_dict[11] = ChassisBase.REBOOT_CAUSE_POWER_LOSS
reset_reason_dict[33] = ChassisBase.REBOOT_CAUSE_WATCHDOG
reset_reason_dict[44] = ChassisBase.REBOOT_CAUSE_NON_HARDWARE
reset_reason_dict[55] = ChassisBase.REBOOT_CAUSE_NON_HARDWARE
power_reason_dict = {}
power_reason_dict[11] = ChassisBase.REBOOT_CAUSE_POWER_LOSS
power_reason_dict[22] = ChassisBase.REBOOT_CAUSE_THERMAL_OVERLOAD_CPU
power_reason_dict[33] = ChassisBase.REBOOT_CAUSE_THERMAL_OVERLOAD_ASIC
power_reason_dict[44] = ChassisBase.REBOOT_CAUSE_INSUFFICIENT_FAN_SPEED
def __init__(self):
ChassisBase.__init__(self)
def get_pmc_register(self, reg_name):
rv = 'ERR'
mb_reg_file = self.MAILBOX_DIR+'/'+reg_name
if (not os.path.isfile(mb_reg_file)):
print mb_reg_file, 'not found !'
return rv
try:
with open(mb_reg_file, 'r') as fd:
rv = fd.read()
except Exception as error:
logging.error("Unable to open ", mb_reg_file, "file !")
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_pmc_register('smf_reset_reason'))
power_reason = int(self.get_pmc_register('smf_poweron_reason'))
# Reset_Reason = 11 ==> PowerLoss
# So return the reboot reason from Last Power_Reason Dictionary
# If Reset_Reason is not 11 return from Reset_Reason dictionary
# Also check if power_reason, reset_reason are valid values by
# checking key presence in dictionary else return
# REBOOT_CAUSE_HARDWARE_OTHER as the Power_Reason and Reset_Reason
# registers returned invalid data
if (reset_reason == 11):
if (power_reason in self.power_reason_dict):
return (self.power_reason_dict[power_reason], None)
else:
if (reset_reason in self.reset_reason_dict):
return (self.reset_reason_dict[reset_reason], None)
return (ChassisBase.REBOOT_CAUSE_HARDWARE_OTHER, "Invalid Reason")

View File

@ -200,6 +200,14 @@ init_switch_port_led() {
}
install_python_api_package() {
device="/usr/share/sonic/device"
platform=$(/usr/local/bin/sonic-cfggen -H -v DEVICE_METADATA.localhost.platform)
rv=$(pip install $device/$platform/sonic_platform-1.0-py2-none-any.whl)
echo "pip install result = $rv"
}
init_devnum
if [[ "$1" == "init" ]]; then
@ -220,6 +228,7 @@ if [[ "$1" == "init" ]]; then
#Copy led_proc_init.soc
init_switch_port_led
install_python_api_package
value=0x0
echo $value > /sys/class/i2c-adapter/i2c-14/14-003e/qsfp_lpmode

View File

@ -0,0 +1 @@
../s6100/setup.py

View File

@ -0,0 +1 @@
../../s6100/sonic_platform/__init__.py

View File

@ -0,0 +1,82 @@
#!/usr/bin/env python
#############################################################################
# DELLEMC
#
# 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
"""
HWMON_DIR = "/sys/devices/platform/SMF.512/hwmon/"
HWMON_NODE = os.listdir(HWMON_DIR)[0]
MAILBOX_DIR = HWMON_DIR + HWMON_NODE
reset_reason_dict = {}
reset_reason_dict[11] = ChassisBase.REBOOT_CAUSE_POWER_LOSS
reset_reason_dict[33] = ChassisBase.REBOOT_CAUSE_WATCHDOG
reset_reason_dict[44] = ChassisBase.REBOOT_CAUSE_NON_HARDWARE
reset_reason_dict[55] = ChassisBase.REBOOT_CAUSE_NON_HARDWARE
power_reason_dict = {}
power_reason_dict[11] = ChassisBase.REBOOT_CAUSE_POWER_LOSS
power_reason_dict[22] = ChassisBase.REBOOT_CAUSE_THERMAL_OVERLOAD_CPU
power_reason_dict[33] = ChassisBase.REBOOT_CAUSE_THERMAL_OVERLOAD_ASIC
power_reason_dict[44] = ChassisBase.REBOOT_CAUSE_INSUFFICIENT_FAN_SPEED
def __init__(self):
ChassisBase.__init__(self)
def get_pmc_register(self, reg_name):
rv = 'ERR'
mb_reg_file = self.MAILBOX_DIR+'/'+reg_name
if (not os.path.isfile(mb_reg_file)):
print mb_reg_file, 'not found !'
return rv
try:
with open(mb_reg_file, 'r') as fd:
rv = fd.read()
except Exception as error:
logging.error("Unable to open ", mb_reg_file, "file !")
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_pmc_register('smf_reset_reason'))
power_reason = int(self.get_pmc_register('smf_poweron_reason'))
# Reset_Reason = 11 ==> PowerLoss
# So return the reboot reason from Last Power_Reason Dictionary
# If Reset_Reason is not 11 return from Reset_Reason dictionary
# Also check if power_reason, reset_reason are valid values by
# checking key presence in dictionary else return
# REBOOT_CAUSE_HARDWARE_OTHER as the Power_Reason and Reset_Reason
# registers returned invalid data
if (reset_reason == 11):
if (power_reason in self.power_reason_dict):
return (self.power_reason_dict[power_reason], None)
else:
if (reset_reason in self.reset_reason_dict):
return (self.reset_reason_dict[reset_reason], None)
return (ChassisBase.REBOOT_CAUSE_HARDWARE_OTHER, "Invalid Reason")