diff --git a/dockers/docker-platform-monitor/start.sh.j2 b/dockers/docker-platform-monitor/start.sh.j2 index e9f0ebf6cd8..e610e3ee6b0 100644 --- a/dockers/docker-platform-monitor/start.sh.j2 +++ b/dockers/docker-platform-monitor/start.sh.j2 @@ -37,6 +37,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 + {% if not skip_ledd %} supervisorctl start ledd {% endif %} diff --git a/files/image_config/platform/rc.local b/files/image_config/platform/rc.local index 3596eb18419..c1c3f9706f2 100755 --- a/files/image_config/platform/rc.local +++ b/files/image_config/platform/rc.local @@ -265,6 +265,16 @@ if [ -f $FIRST_BOOT_FILE ]; then touch /tmp/pending_config_initialization fi + # Notify firstboot to Platform, to use it for reboot-cause + touch /tmp/notify_firstboot_to_platform + + # create reboot-cause/platform/$platform/ directory + # /host/reboot-cause/platform/reboot-reason + # will be used to track last reboot reason + if [ ! -d /host/reboot-cause/platform ]; then + mkdir -p /host/reboot-cause/platform + fi + if [ -d /host/image-$SONIC_VERSION/platform/$platform ]; then dpkg -i /host/image-$SONIC_VERSION/platform/$platform/*.deb fi diff --git a/platform/broadcom/platform-modules-dell.mk b/platform/broadcom/platform-modules-dell.mk index a2d051ffd91..5c8032c8b43 100644 --- a/platform/broadcom/platform-modules-dell.mk +++ b/platform/broadcom/platform-modules-dell.mk @@ -1,26 +1,36 @@ -# Dell Z9100, S6100, Z9264F Platform modules +# Dell S6000, Z9100, S6100, Z9264F Platform modules -DELL_Z9264F_PLATFORM_MODULE_VERSION = 1.1 +DELL_S6000_PLATFORM_MODULE_VERSION = 1.1 DELL_Z9100_PLATFORM_MODULE_VERSION = 1.1 DELL_S6100_PLATFORM_MODULE_VERSION = 1.1 +DELL_Z9264F_PLATFORM_MODULE_VERSION = 1.1 -export DELL_Z9264F_PLATFORM_MODULE_VERSION +export DELL_S6000_PLATFORM_MODULE_VERSION export DELL_Z9100_PLATFORM_MODULE_VERSION export DELL_S6100_PLATFORM_MODULE_VERSION +export DELL_Z9264F_PLATFORM_MODULE_VERSION + +# Dell Z9100 Platform modules DELL_Z9100_PLATFORM_MODULE = platform-modules-z9100_$(DELL_Z9100_PLATFORM_MODULE_VERSION)_amd64.deb $(DELL_Z9100_PLATFORM_MODULE)_SRC_PATH = $(PLATFORM_PATH)/sonic-platform-modules-dell $(DELL_Z9100_PLATFORM_MODULE)_DEPENDS += $(LINUX_HEADERS) $(LINUX_HEADERS_COMMON) $(DELL_Z9100_PLATFORM_MODULE)_PLATFORM = x86_64-dell_z9100_c2538-r0 SONIC_DPKG_DEBS += $(DELL_Z9100_PLATFORM_MODULE) +# Dell S6100 Platform modules DELL_S6100_PLATFORM_MODULE = platform-modules-s6100_$(DELL_S6100_PLATFORM_MODULE_VERSION)_amd64.deb $(DELL_S6100_PLATFORM_MODULE)_PLATFORM = x86_64-dell_s6100_c2538-r0 $(eval $(call add_extra_package,$(DELL_Z9100_PLATFORM_MODULE),$(DELL_S6100_PLATFORM_MODULE))) +# Dell Z9264F Platform modules DELL_Z9264F_PLATFORM_MODULE = platform-modules-z9264f_$(DELL_Z9264F_PLATFORM_MODULE_VERSION)_amd64.deb $(DELL_Z9264F_PLATFORM_MODULE)_PLATFORM = x86_64-dellemc_z9264f_c3538-r0 $(eval $(call add_extra_package,$(DELL_Z9100_PLATFORM_MODULE),$(DELL_Z9264F_PLATFORM_MODULE))) +# Dell S6000 Platform modules +DELL_S6000_PLATFORM_MODULE = platform-modules-s6000_$(DELL_S6000_PLATFORM_MODULE_VERSION)_amd64.deb +$(DELL_S6000_PLATFORM_MODULE)_PLATFORM = x86_64-dell_s6000_s1220-r0 +$(eval $(call add_extra_package,$(DELL_Z9100_PLATFORM_MODULE),$(DELL_S6000_PLATFORM_MODULE))) SONIC_STRETCH_DEBS += $(DELL_Z9100_PLATFORM_MODULE) diff --git a/platform/broadcom/platform-modules-s6000.mk b/platform/broadcom/platform-modules-s6000.mk deleted file mode 100644 index 00cd2cadf2d..00000000000 --- a/platform/broadcom/platform-modules-s6000.mk +++ /dev/null @@ -1,13 +0,0 @@ -# Dell S6000 Platform modules - -DELL_S6000_PLATFORM_MODULE_VERSION = 1.0 - -export DELL_S6000_PLATFORM_MODULE_VERSION - -DELL_S6000_PLATFORM_MODULE = platform-modules-s6000_$(DELL_S6000_PLATFORM_MODULE_VERSION)_amd64.deb -$(DELL_S6000_PLATFORM_MODULE)_SRC_PATH = $(PLATFORM_PATH)/sonic-platform-modules-s6000 -$(DELL_S6000_PLATFORM_MODULE)_DEPENDS += $(LINUX_HEADERS) $(LINUX_HEADERS_COMMON) -$(DELL_S6000_PLATFORM_MODULE)_PLATFORM = x86_64-dell_s6000_s1220-r0 -SONIC_DPKG_DEBS += $(DELL_S6000_PLATFORM_MODULE) - -SONIC_STRETCH_DEBS += $(DELL_S6000_PLATFORM_MODULE) diff --git a/platform/broadcom/rules.mk b/platform/broadcom/rules.mk index abedbbe1d65..02eb58df0cc 100644 --- a/platform/broadcom/rules.mk +++ b/platform/broadcom/rules.mk @@ -1,6 +1,5 @@ include $(PLATFORM_PATH)/sai-modules.mk include $(PLATFORM_PATH)/sai.mk -include $(PLATFORM_PATH)/platform-modules-s6000.mk include $(PLATFORM_PATH)/platform-modules-dell.mk include $(PLATFORM_PATH)/platform-modules-arista.mk include $(PLATFORM_PATH)/platform-modules-ingrasys.mk diff --git a/platform/broadcom/sonic-platform-modules-dell/common/dell_pmc.c b/platform/broadcom/sonic-platform-modules-dell/common/dell_pmc.c index b8ed4bbb082..d3597b81841 100644 --- a/platform/broadcom/sonic-platform-modules-dell/common/dell_pmc.c +++ b/platform/broadcom/sonic-platform-modules-dell/common/dell_pmc.c @@ -43,9 +43,11 @@ #define IOREGION_LENGTH 0x4 #define SMF_ADDR_REG_OFFSET 0 #define SMF_READ_DATA_REG_OFFSET 2 +#define SMF_WRITE_DATA_REG_OFFSET 3 #define SMF_REG_ADDR 0x200 -#define SMF_PROBE_ADDR 0x210 +#define SMF_POR_SRC_REG 0x209 #define SMF_RST_SRC_REG 0x20A +#define SMF_PROBE_ADDR 0x210 #define SIO_REG_DEVID 0x1 #define SIO_Z9100_ID 0x1 @@ -150,6 +152,8 @@ #define CPU_7_MONITOR_STATUS 0x02E8 #define CPU_8_MONITOR_STATUS 0x02E9 +/* Mailbox PowerOn Reason */ +#define TRACK_POWERON_REASON 0x05FF unsigned long *mmio; static struct kobject *dell_kobj; @@ -440,6 +444,18 @@ struct smf_sio_data { enum kinds kind; }; +static int smf_write_reg(struct smf_data *data, u16 reg, u16 dev_data) +{ + int res = 0; + + mutex_lock(&data->lock); + outb_p(reg>> 8, data->addr + SMF_ADDR_REG_OFFSET); + outb_p(reg & 0xff, data->addr + SMF_ADDR_REG_OFFSET + 1); + outb_p(dev_data & 0xff, data->addr + SMF_WRITE_DATA_REG_OFFSET); + mutex_unlock(&data->lock); + + return res; +} static int smf_read_reg(struct smf_data *data, u16 reg) { @@ -519,6 +535,53 @@ static ssize_t show_reset_reason(struct device *dev, return sprintf(buf, "%x\n", ret); } +/* SMF Power ON Reason */ +static ssize_t show_power_on_reason(struct device *dev, + struct device_attribute *devattr, char *buf) +{ + unsigned int ret = 0; + + ret = inb(SMF_POR_SRC_REG); + + if(ret < 0) + return ret; + + return sprintf(buf, "%x\n", ret); +} + +/* SMF Mailbox Power ON Reason */ +static ssize_t set_mb_poweron_reason(struct device *dev, + struct device_attribute *devattr, const char *buf, size_t count) +{ + int err = 0; + unsigned int dev_data = 0; + struct smf_data *data = dev_get_drvdata(dev); + + err = kstrtouint(buf, 16, &dev_data); + if (err) + return err; + + err = smf_write_reg(data, TRACK_POWERON_REASON, dev_data); + + if(err < 0) + return err; + + return count; +} + +static ssize_t show_mb_poweron_reason(struct device *dev, + struct device_attribute *devattr, char *buf) +{ + unsigned int ret = 0; + struct smf_data *data = dev_get_drvdata(dev); + + ret = smf_read_reg(data, TRACK_POWERON_REASON); + + if(ret < 0) + return ret; + + return sprintf(buf, "0x%x\n", ret); +} /* FANIN ATTR */ static ssize_t @@ -1800,11 +1863,20 @@ static SENSOR_DEVICE_ATTR(smf_firmware_ver, S_IRUGO, show_smf_version, NULL, 1); /* SMF Reset Reason */ static SENSOR_DEVICE_ATTR(smf_reset_reason, S_IRUGO, show_reset_reason, NULL, 1); +/* SMF PowerOn Reason */ +static SENSOR_DEVICE_ATTR(smf_poweron_reason, S_IRUGO, + show_power_on_reason, NULL, 1); + +/* Mailbox Power tracking Reason */ +static SENSOR_DEVICE_ATTR(mb_poweron_reason, S_IRUGO|S_IWUSR, + show_mb_poweron_reason, set_mb_poweron_reason, 0); static struct attribute *smf_dell_attrs[] = { &sensor_dev_attr_smf_version.dev_attr.attr, &sensor_dev_attr_smf_firmware_ver.dev_attr.attr, &sensor_dev_attr_smf_reset_reason.dev_attr.attr, + &sensor_dev_attr_smf_poweron_reason.dev_attr.attr, + &sensor_dev_attr_mb_poweron_reason.dev_attr.attr, &sensor_dev_attr_fan_tray_presence.dev_attr.attr, &sensor_dev_attr_fan1_airflow.dev_attr.attr, &sensor_dev_attr_fan3_airflow.dev_attr.attr, diff --git a/platform/broadcom/sonic-platform-modules-dell/common/platform_reboot b/platform/broadcom/sonic-platform-modules-dell/common/platform_reboot index 3e165630658..81d272326ec 100755 --- a/platform/broadcom/sonic-platform-modules-dell/common/platform_reboot +++ b/platform/broadcom/sonic-platform-modules-dell/common/platform_reboot @@ -2,9 +2,14 @@ import sys import os import struct +import subprocess PORT_RES = '/dev/port' +def track_reboot(): + # Run plugin script which will track the cli triggered reboot, fastboot, warmboot + res = subprocess.check_output(['/usr/local/bin/fastboot_plugin']) + return def portio_reg_write(resource, offset, val): fd = os.open(resource, os.O_RDWR) @@ -21,5 +26,6 @@ def portio_reg_write(resource, offset, val): os.close(fd) if __name__ == "__main__": + track_reboot() portio_reg_write(PORT_RES, 0xcf9, 0xe) diff --git a/platform/broadcom/sonic-platform-modules-dell/debian/control b/platform/broadcom/sonic-platform-modules-dell/debian/control index c30a261fd9d..cc24fa13cc6 100644 --- a/platform/broadcom/sonic-platform-modules-dell/debian/control +++ b/platform/broadcom/sonic-platform-modules-dell/debian/control @@ -5,7 +5,7 @@ Maintainer: Dell Team Build-Depends: debhelper (>= 8.0.0), bzip2 Standards-Version: 3.9.3 -Package: platform-modules-z9264f +Package: platform-modules-s6000 Architecture: amd64 Depends: linux-image-4.9.0-9-2-amd64 Description: kernel modules for platform devices such as fan, led, sfp @@ -20,3 +20,7 @@ Architecture: amd64 Depends: linux-image-4.9.0-9-2-amd64 Description: kernel modules for platform devices such as fan, led, sfp +Package: platform-modules-z9264f +Architecture: amd64 +Depends: linux-image-4.9.0-9-2-amd64 +Description: kernel modules for platform devices such as fan, led, sfp diff --git a/platform/broadcom/sonic-platform-modules-dell/debian/platform-modules-s6000.init b/platform/broadcom/sonic-platform-modules-dell/debian/platform-modules-s6000.init new file mode 100755 index 00000000000..94bddb6afe2 --- /dev/null +++ b/platform/broadcom/sonic-platform-modules-dell/debian/platform-modules-s6000.init @@ -0,0 +1,39 @@ +#!/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 + +case "$1" in +start) + echo -n "Setting up board... " + + /usr/local/bin/s6000_platform.sh init + + echo "done." + ;; + +stop) + /usr/local/bin/s6000_platform.sh deinit + echo "done." + + ;; + +force-reload|restart) + echo "Not supported" + ;; + +*) + echo "Usage: /etc/init.d/platform-modules-s6000.init {start|stop}" + exit 1 + ;; +esac + +exit 0 diff --git a/platform/broadcom/sonic-platform-modules-dell/debian/platform-modules-s6000.install b/platform/broadcom/sonic-platform-modules-dell/debian/platform-modules-s6000.install new file mode 100644 index 00000000000..c2dcb5dc03a --- /dev/null +++ b/platform/broadcom/sonic-platform-modules-dell/debian/platform-modules-s6000.install @@ -0,0 +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 diff --git a/platform/broadcom/sonic-platform-modules-dell/debian/platform-modules-s6000.postinst b/platform/broadcom/sonic-platform-modules-dell/debian/platform-modules-s6000.postinst new file mode 100644 index 00000000000..a9b90fa86f3 --- /dev/null +++ b/platform/broadcom/sonic-platform-modules-dell/debian/platform-modules-s6000.postinst @@ -0,0 +1,7 @@ +# postinst script for S6000 + +# Enable Dell-S6000-platform-service +depmod -a +systemctl enable platform-modules-s6000.service +systemctl start platform-modules-s6000.service +#DEBHELPER# diff --git a/platform/broadcom/sonic-platform-modules-dell/debian/platform-modules-s6100.install b/platform/broadcom/sonic-platform-modules-dell/debian/platform-modules-s6100.install index eef7c106304..7f4455b1346 100644 --- a/platform/broadcom/sonic-platform-modules-dell/debian/platform-modules-s6100.install +++ b/platform/broadcom/sonic-platform-modules-dell/debian/platform-modules-s6100.install @@ -3,6 +3,10 @@ s6100/scripts/s6100_platform.sh usr/local/bin common/dell_i2c_utils.sh usr/local/bin common/io_rd_wr.py usr/local/bin common/platform_reboot usr/share/sonic/device/x86_64-dell_s6100_c2538-r0 +s6100/scripts/fastboot_plugin usr/share/sonic/device/x86_64-dell_s6100_c2538-r0 +s6100/scripts/fastboot_plugin usr/local/bin +s6100/scripts/track_reboot_reason.sh 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 diff --git a/platform/broadcom/sonic-platform-modules-dell/debian/platform-modules-z9100.install b/platform/broadcom/sonic-platform-modules-dell/debian/platform-modules-z9100.install index e332f1affdc..f0bb8ce80dd 100644 --- a/platform/broadcom/sonic-platform-modules-dell/debian/platform-modules-z9100.install +++ b/platform/broadcom/sonic-platform-modules-dell/debian/platform-modules-z9100.install @@ -3,11 +3,15 @@ z9100/scripts/z9100_platform.sh usr/local/bin common/dell_i2c_utils.sh usr/local/bin common/io_rd_wr.py usr/local/bin common/platform_reboot usr/share/sonic/device/x86_64-dell_z9100_c2538-r0 +z9100/scripts/fastboot_plugin usr/share/sonic/device/x86_64-dell_z9100_c2538-r0 +z9100/scripts/fastboot_plugin usr/local/bin +z9100/scripts/track_reboot_reason.sh usr/share/sonic/device/x86_64-dell_z9100_c2538-r0 z9100/scripts/platform_sensors.py usr/local/bin z9100/scripts/z9100_qsfp_monitor.py usr/local/bin z9100/scripts/z9100_preemp_db.py usr/local/bin z9100/scripts/qsfp_monitor 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 z9100/systemd/z9100-qsfp-monitor.service etc/systemd/system diff --git a/platform/broadcom/sonic-platform-modules-dell/debian/rules b/platform/broadcom/sonic-platform-modules-dell/debian/rules index 860e46bf700..4db58cc7444 100755 --- a/platform/broadcom/sonic-platform-modules-dell/debian/rules +++ b/platform/broadcom/sonic-platform-modules-dell/debian/rules @@ -5,7 +5,7 @@ export INSTALL_MOD_DIR:=extra KVERSION ?= $(shell uname -r) KERNEL_SRC := /lib/modules/$(KVERSION) MOD_SRC_DIR:= $(shell pwd) -MODULE_DIRS:= s6100 z9100 z9264f +MODULE_DIRS:= s6000 z9100 s6100 z9264f COMMON_DIR := common %: @@ -16,9 +16,19 @@ 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); \ + 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; \ @@ -30,6 +40,10 @@ override_dh_auto_install: $(KERNEL_SRC)/$(INSTALL_MOD_DIR); \ cp $(MOD_SRC_DIR)/$${mod}/modules/*.ko \ debian/platform-modules-$${mod}/$(KERNEL_SRC)/$(INSTALL_MOD_DIR); \ + if [ $$mod = "s6000" ]; then \ + dh_installdirs -pplatform-modules-$${mod} usr/local/bin ; \ + cp -r $(MOD_SRC_DIR)/$${mod}/scripts/* debian/platform-modules-$${mod}/usr/local/bin; \ + fi; \ done) override_dh_usrlocal: @@ -40,9 +54,19 @@ 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; \ + 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) diff --git a/platform/broadcom/sonic-platform-modules-s6000/LICENSE b/platform/broadcom/sonic-platform-modules-dell/s6000/LICENSE similarity index 100% rename from platform/broadcom/sonic-platform-modules-s6000/LICENSE rename to platform/broadcom/sonic-platform-modules-dell/s6000/LICENSE diff --git a/platform/broadcom/sonic-platform-modules-s6000/MAINTAINERS b/platform/broadcom/sonic-platform-modules-dell/s6000/MAINTAINERS similarity index 100% rename from platform/broadcom/sonic-platform-modules-s6000/MAINTAINERS rename to platform/broadcom/sonic-platform-modules-dell/s6000/MAINTAINERS diff --git a/platform/broadcom/sonic-platform-modules-s6000/README.md b/platform/broadcom/sonic-platform-modules-dell/s6000/README.md similarity index 100% rename from platform/broadcom/sonic-platform-modules-s6000/README.md rename to platform/broadcom/sonic-platform-modules-dell/s6000/README.md diff --git a/platform/broadcom/sonic-platform-modules-s6000/modules/Makefile b/platform/broadcom/sonic-platform-modules-dell/s6000/modules/Makefile similarity index 100% rename from platform/broadcom/sonic-platform-modules-s6000/modules/Makefile rename to platform/broadcom/sonic-platform-modules-dell/s6000/modules/Makefile diff --git a/platform/broadcom/sonic-platform-modules-s6000/modules/dell_s6000_platform.c b/platform/broadcom/sonic-platform-modules-dell/s6000/modules/dell_s6000_platform.c similarity index 97% rename from platform/broadcom/sonic-platform-modules-s6000/modules/dell_s6000_platform.c rename to platform/broadcom/sonic-platform-modules-dell/s6000/modules/dell_s6000_platform.c index 3ac029e73ff..0463ac30e58 100644 --- a/platform/broadcom/sonic-platform-modules-s6000/modules/dell_s6000_platform.c +++ b/platform/broadcom/sonic-platform-modules-dell/s6000/modules/dell_s6000_platform.c @@ -10,6 +10,7 @@ #include #include #include +#include #define S6000_MUX_BASE_NR 10 #define QSFP_MODULE_BASE_NR 20 @@ -23,6 +24,8 @@ #define GPIO_I2C_MUX_PIN 10 +#define RTC_NVRAM_REBOOT_REASON_OFFSET 0x49 + static void device_release(struct device *dev) { return; @@ -1094,6 +1097,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); @@ -1116,6 +1137,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, @@ -1139,6 +1161,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, }; diff --git a/platform/broadcom/sonic-platform-modules-s6000/scripts/reset-qsfp b/platform/broadcom/sonic-platform-modules-dell/s6000/scripts/reset-qsfp similarity index 100% rename from platform/broadcom/sonic-platform-modules-s6000/scripts/reset-qsfp rename to platform/broadcom/sonic-platform-modules-dell/s6000/scripts/reset-qsfp diff --git a/platform/broadcom/sonic-platform-modules-s6000/debian/platform-modules-s6000.init b/platform/broadcom/sonic-platform-modules-dell/s6000/scripts/s6000_platform.sh similarity index 81% rename from platform/broadcom/sonic-platform-modules-s6000/debian/platform-modules-s6000.init rename to platform/broadcom/sonic-platform-modules-dell/s6000/scripts/s6000_platform.sh index 6566f362cc4..316fbaec5fe 100755 --- a/platform/broadcom/sonic-platform-modules-s6000/debian/platform-modules-s6000.init +++ b/platform/broadcom/sonic-platform-modules-dell/s6000/scripts/s6000_platform.sh @@ -60,42 +60,39 @@ remove_i2c_devices() { done } -case "$1" in -start) - echo -n "Setting up board... " +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 - modprobe nvram + install_python_api_package add_i2c_devices /usr/local/bin/set-fan-speed 15000 /usr/local/bin/reset-qsfp - - echo "done." - ;; - -stop) - echo "done." - +elif [[ "$1" == "deinit" ]]; then remove_i2c_devices - - rmmod nvram rmmod dell_s6000_platform + rmmod nvram rmmod i2c_mux_gpio - ;; - -force-reload|restart) - echo "Not supported" - ;; - -*) - echo "Usage: /etc/init.d/platform-modules-s6000.init {start|stop}" - exit 1 - ;; -esac - -exit 0 - + remove_python_api_package +else + echo "s6000_platform : Invalid option !" +fi diff --git a/platform/broadcom/sonic-platform-modules-s6000/scripts/set-fan-speed b/platform/broadcom/sonic-platform-modules-dell/s6000/scripts/set-fan-speed similarity index 100% rename from platform/broadcom/sonic-platform-modules-s6000/scripts/set-fan-speed rename to platform/broadcom/sonic-platform-modules-dell/s6000/scripts/set-fan-speed diff --git a/platform/broadcom/sonic-platform-modules-dell/s6000/setup.py b/platform/broadcom/sonic-platform-modules-dell/s6000/setup.py new file mode 120000 index 00000000000..4f6de9941d9 --- /dev/null +++ b/platform/broadcom/sonic-platform-modules-dell/s6000/setup.py @@ -0,0 +1 @@ +../s6100/setup.py \ No newline at end of file diff --git a/platform/broadcom/sonic-platform-modules-dell/s6000/sonic_platform/__init__.py b/platform/broadcom/sonic-platform-modules-dell/s6000/sonic_platform/__init__.py new file mode 100755 index 00000000000..d82f3749319 --- /dev/null +++ b/platform/broadcom/sonic-platform-modules-dell/s6000/sonic_platform/__init__.py @@ -0,0 +1,2 @@ +__all__ = ["platform", "chassis"] +from sonic_platform import * diff --git a/platform/broadcom/sonic-platform-modules-dell/s6000/sonic_platform/chassis.py b/platform/broadcom/sonic-platform-modules-dell/s6000/sonic_platform/chassis.py new file mode 100755 index 00000000000..48ac7037787 --- /dev/null +++ b/platform/broadcom/sonic-platform-modules-dell/s6000/sonic_platform/chassis.py @@ -0,0 +1,64 @@ +#!/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 + """ + # In S6000, We track the reboot reason by writing the reason in + # NVRAM. Only Warmboot and Coldboot reason are supported here. + # Since it does not support any hardware reason, we return + # non_hardware as default + + lrr = self._get_register('last_reboot_reason') + if (lrr != 'ERR'): + reset_reason = int(lrr, base=16) + if (reset_reason in self.reset_reason_dict): + return (self.reset_reason_dict[reset_reason], None) + + return (ChassisBase.REBOOT_CAUSE_NON_HARDWARE, None) + diff --git a/platform/broadcom/sonic-platform-modules-dell/s6000/sonic_platform/platform.py b/platform/broadcom/sonic-platform-modules-dell/s6000/sonic_platform/platform.py new file mode 100755 index 00000000000..426db717281 --- /dev/null +++ b/platform/broadcom/sonic-platform-modules-dell/s6000/sonic_platform/platform.py @@ -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() + diff --git a/platform/broadcom/sonic-platform-modules-s6000/systemd/platform-modules-s6000.service b/platform/broadcom/sonic-platform-modules-dell/s6000/systemd/platform-modules-s6000.service similarity index 62% rename from platform/broadcom/sonic-platform-modules-s6000/systemd/platform-modules-s6000.service rename to platform/broadcom/sonic-platform-modules-dell/s6000/systemd/platform-modules-s6000.service index 246dee9b64f..b55a466890b 100644 --- a/platform/broadcom/sonic-platform-modules-s6000/systemd/platform-modules-s6000.service +++ b/platform/broadcom/sonic-platform-modules-dell/s6000/systemd/platform-modules-s6000.service @@ -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] diff --git a/platform/broadcom/sonic-platform-modules-dell/s6100/scripts/fastboot_plugin b/platform/broadcom/sonic-platform-modules-dell/s6100/scripts/fastboot_plugin new file mode 100755 index 00000000000..d385be3bc68 --- /dev/null +++ b/platform/broadcom/sonic-platform-modules-dell/s6100/scripts/fastboot_plugin @@ -0,0 +1,6 @@ +#!/bin/bash + +if [[ -d /sys/devices/platform/SMF.512/hwmon/ ]]; then + cd /sys/devices/platform/SMF.512/hwmon/* + echo 0xcc > mb_poweron_reason +fi diff --git a/platform/broadcom/sonic-platform-modules-dell/s6100/scripts/s6100_platform.sh b/platform/broadcom/sonic-platform-modules-dell/s6100/scripts/s6100_platform.sh index 1ac6ce93bc1..3d0e0cefd5e 100755 --- a/platform/broadcom/sonic-platform-modules-dell/s6100/scripts/s6100_platform.sh +++ b/platform/broadcom/sonic-platform-modules-dell/s6100/scripts/s6100_platform.sh @@ -217,6 +217,26 @@ reset_muxes() { io_rd_wr.py --set --val 0xff --offset 0x20b } +track_reboot_reason() { + /usr/share/sonic/device/x86_64-dell_s6100_c2538-r0/track_reboot_reason.sh + status=$(echo $?) + return status +} + +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) +} + +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 +} + init_devnum if [[ "$1" == "init" ]]; then @@ -225,6 +245,7 @@ if [[ "$1" == "init" ]]; then modprobe dell_ich modprobe dell_s6100_iom_cpld modprobe dell_s6100_lpc + track_reboot_reason cpu_board_mux "new_device" switch_board_mux "new_device" @@ -235,6 +256,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" @@ -250,6 +274,7 @@ elif [[ "$1" == "deinit" ]]; then modprobe -r i2c-mux-pca954x modprobe -r i2c-dev modprobe -r dell_ich + remove_python_api_package else echo "s6100_platform : Invalid option !" fi diff --git a/platform/broadcom/sonic-platform-modules-dell/s6100/scripts/track_reboot_reason.sh b/platform/broadcom/sonic-platform-modules-dell/s6100/scripts/track_reboot_reason.sh new file mode 100755 index 00000000000..71fff409ad0 --- /dev/null +++ b/platform/broadcom/sonic-platform-modules-dell/s6100/scripts/track_reboot_reason.sh @@ -0,0 +1,111 @@ +#!/bin/bash + +syslog_found=false +syslog_1_found=false +reboot_dir_found=false +reboot_file_found=false + +if [[ -f /var/log/syslog ]]; then + syslog_found=true +fi + +if [[ -f /var/log/syslog.1 ]]; then + syslog_1_found=true +fi + +if [[ -d /host/reboot-cause/platform ]]; then + reboot_dir_found=true + if [[ -f /host/reboot-cause/platform/reboot_reason ]]; then + reboot_file_found=true + fi +fi + +track_thermal() { + prev_thermal=$(cat /host/reboot-cause/platform/reboot_reason | grep thermal | cut -d ' ' -f2-4) + curr_poweron_reason=$(cd /sys/devices/platform/SMF.512/hwmon/*; cat smf_poweron_reason) + if [[ $curr_poweron_reason = "11" ]]; then + return 0 + fi + if [[ $prev_thermal = $curr_poweron_reason ]]; then + return 0 + else + sed -i "2s/.*/thermal $curr_poweron_reason/" /host/reboot-cause/platform/reboot_reason + return 1 + fi + + return 0 +} + +track_watchdog() +{ + if [[ $syslog_found = true ]]; then + wd_log="$(tac /var/log/syslog | grep -a "watchdog did not stop" | grep -a "CRIT kernel")" + if [[ $wd_log = "" ]] && [[ $syslog_1_found = true ]]; then + wd_log="$(tac /var/log/syslog.1 | grep -a "watchdog did not stop" | grep -a "CRIT kernel")" + fi + fi + + if [[ $wd_log = "" ]]; then + return 0 + fi + + if [[ $reboot_dir_found = true ]]; then + echo "$wd_log" > /host/reboot-cause/platform/tmp + wd_log=$(head -n 1 /host/reboot-cause/platform/tmp) + wd_timestamp=$(echo $wd_log | cut -d ' ' -f1-3) + wd_date=$(echo $wd_timestamp | cut -d '.' -f1) + + if [[ $reboot_file_found = true ]]; then + prev_wd=$(cat /host/reboot-cause/platform/reboot_reason | grep watchdog | cut -d ' ' -f2-4) + + if [[ $prev_wd = $wd_date ]]; then + rm -rf /host/reboot-cause/platform/tmp + return 0 + else + sed -i "1s/.*/watchdog $wd_date/" /host/reboot-cause/platform/reboot_reason + rm -rf /host/reboot-cause/platform/tmp + return 1 + fi + fi + fi +} + +track_reboot_reason() { + if [[ $reboot_file_found = false ]]; then + echo "watchdog None" > /host/reboot-cause/platform/reboot_reason + echo "thermal None" >> /host/reboot-cause/platform/reboot_reason + fi + + if [[ -d /sys/devices/platform/SMF.512/hwmon/ ]]; then + track_thermal + is_thermal_reboot=$(echo $?) + + track_watchdog + is_wd_reboot=$(echo $?) + + rv=$(cd /sys/devices/platform/SMF.512/hwmon/*; cat mb_poweron_reason) + reason=$(echo $rv | cut -d 'x' -f2) + if [[ $reason = "ff" ]]; then + sed -i "2s/.*/thermal None/" /host/reboot-cause/platform/reboot_reason + cd /sys/devices/platform/SMF.512/hwmon/* + if [[ -e /tmp/notify_firstboot_to_platform ]]; then + echo 0x01 > mb_poweron_reason + else + echo 0xbb > mb_poweron_reason + fi + elif [[ $is_thermal_reboot = 1 ]]; then + cd /sys/devices/platform/SMF.512/hwmon/* + echo 0xee > mb_poweron_reason + elif [[ $is_wd_reboot = 1 ]]; then + cd /sys/devices/platform/SMF.512/hwmon/* + echo 0xdd > mb_poweron_reason + elif [[ $reason = "cc" ]]; then + cd /sys/devices/platform/SMF.512/hwmon/* + echo 0xaa > mb_poweron_reason + else + cd /sys/devices/platform/SMF.512/hwmon/* + echo 0x99 > mb_poweron_reason + fi + fi +} +track_reboot_reason diff --git a/platform/broadcom/sonic-platform-modules-dell/s6100/setup.py b/platform/broadcom/sonic-platform-modules-dell/s6100/setup.py new file mode 100755 index 00000000000..eb95775c667 --- /dev/null +++ b/platform/broadcom/sonic-platform-modules-dell/s6100/setup.py @@ -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', +) + diff --git a/platform/broadcom/sonic-platform-modules-dell/s6100/sonic_platform/__init__.py b/platform/broadcom/sonic-platform-modules-dell/s6100/sonic_platform/__init__.py new file mode 100755 index 00000000000..4bfefa0fb63 --- /dev/null +++ b/platform/broadcom/sonic-platform-modules-dell/s6100/sonic_platform/__init__.py @@ -0,0 +1,3 @@ +__all__ = ["platform", "chassis"] +from sonic_platform import * + diff --git a/platform/broadcom/sonic-platform-modules-dell/s6100/sonic_platform/chassis.py b/platform/broadcom/sonic-platform-modules-dell/s6100/sonic_platform/chassis.py new file mode 100755 index 00000000000..236866d713d --- /dev/null +++ b/platform/broadcom/sonic-platform-modules-dell/s6100/sonic_platform/chassis.py @@ -0,0 +1,104 @@ +#!/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_reason_smf_register(self): + # Returns 0xAA on software reload + # Returns 0xFF on power-cycle + # Returns 0x01 on first-boot + smf_mb_reg_reason = self._get_pmc_register('mb_poweron_reason') + return int(smf_mb_reg_reason, 16) + + 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')) + smf_mb_reg_reason = self._get_reboot_reason_smf_register() + + if ((smf_mb_reg_reason == 0x01) and (power_reason == 0x11)): + return (ChassisBase.REBOOT_CAUSE_NON_HARDWARE, None) + + # 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 + + # In S6100, if Reset_Reason is not 11 and smf_mb_reg_reason + # is ff or bb, then it is PowerLoss + if (reset_reason == 11): + if (power_reason in self.power_reason_dict): + return (self.power_reason_dict[power_reason], None) + else: + if (smf_mb_reg_reason == 0xaa): + return (ChassisBase.REBOOT_CAUSE_NON_HARDWARE, None) + elif ((smf_mb_reg_reason == 0xbb) or (smf_mb_reg_reason == 0xff)): + return (ChassisBase.REBOOT_CAUSE_POWER_LOSS, None) + elif (smf_mb_reg_reason == 0xdd): + return (ChassisBase.REBOOT_CAUSE_WATCHDOG, None) + elif (smf_mb_reg_reason == 0xee): + return (self.power_reason_dict[power_reason], None) + else: + return (ChassisBase.REBOOT_CAUSE_NON_HARDWARE, None) + + return (ChassisBase.REBOOT_CAUSE_HARDWARE_OTHER, "Invalid Reason") + diff --git a/platform/broadcom/sonic-platform-modules-dell/s6100/sonic_platform/platform.py b/platform/broadcom/sonic-platform-modules-dell/s6100/sonic_platform/platform.py new file mode 100755 index 00000000000..426db717281 --- /dev/null +++ b/platform/broadcom/sonic-platform-modules-dell/s6100/sonic_platform/platform.py @@ -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() + diff --git a/platform/broadcom/sonic-platform-modules-dell/z9100/scripts/fastboot_plugin b/platform/broadcom/sonic-platform-modules-dell/z9100/scripts/fastboot_plugin new file mode 100755 index 00000000000..d385be3bc68 --- /dev/null +++ b/platform/broadcom/sonic-platform-modules-dell/z9100/scripts/fastboot_plugin @@ -0,0 +1,6 @@ +#!/bin/bash + +if [[ -d /sys/devices/platform/SMF.512/hwmon/ ]]; then + cd /sys/devices/platform/SMF.512/hwmon/* + echo 0xcc > mb_poweron_reason +fi diff --git a/platform/broadcom/sonic-platform-modules-dell/z9100/scripts/track_reboot_reason.sh b/platform/broadcom/sonic-platform-modules-dell/z9100/scripts/track_reboot_reason.sh new file mode 100755 index 00000000000..71fff409ad0 --- /dev/null +++ b/platform/broadcom/sonic-platform-modules-dell/z9100/scripts/track_reboot_reason.sh @@ -0,0 +1,111 @@ +#!/bin/bash + +syslog_found=false +syslog_1_found=false +reboot_dir_found=false +reboot_file_found=false + +if [[ -f /var/log/syslog ]]; then + syslog_found=true +fi + +if [[ -f /var/log/syslog.1 ]]; then + syslog_1_found=true +fi + +if [[ -d /host/reboot-cause/platform ]]; then + reboot_dir_found=true + if [[ -f /host/reboot-cause/platform/reboot_reason ]]; then + reboot_file_found=true + fi +fi + +track_thermal() { + prev_thermal=$(cat /host/reboot-cause/platform/reboot_reason | grep thermal | cut -d ' ' -f2-4) + curr_poweron_reason=$(cd /sys/devices/platform/SMF.512/hwmon/*; cat smf_poweron_reason) + if [[ $curr_poweron_reason = "11" ]]; then + return 0 + fi + if [[ $prev_thermal = $curr_poweron_reason ]]; then + return 0 + else + sed -i "2s/.*/thermal $curr_poweron_reason/" /host/reboot-cause/platform/reboot_reason + return 1 + fi + + return 0 +} + +track_watchdog() +{ + if [[ $syslog_found = true ]]; then + wd_log="$(tac /var/log/syslog | grep -a "watchdog did not stop" | grep -a "CRIT kernel")" + if [[ $wd_log = "" ]] && [[ $syslog_1_found = true ]]; then + wd_log="$(tac /var/log/syslog.1 | grep -a "watchdog did not stop" | grep -a "CRIT kernel")" + fi + fi + + if [[ $wd_log = "" ]]; then + return 0 + fi + + if [[ $reboot_dir_found = true ]]; then + echo "$wd_log" > /host/reboot-cause/platform/tmp + wd_log=$(head -n 1 /host/reboot-cause/platform/tmp) + wd_timestamp=$(echo $wd_log | cut -d ' ' -f1-3) + wd_date=$(echo $wd_timestamp | cut -d '.' -f1) + + if [[ $reboot_file_found = true ]]; then + prev_wd=$(cat /host/reboot-cause/platform/reboot_reason | grep watchdog | cut -d ' ' -f2-4) + + if [[ $prev_wd = $wd_date ]]; then + rm -rf /host/reboot-cause/platform/tmp + return 0 + else + sed -i "1s/.*/watchdog $wd_date/" /host/reboot-cause/platform/reboot_reason + rm -rf /host/reboot-cause/platform/tmp + return 1 + fi + fi + fi +} + +track_reboot_reason() { + if [[ $reboot_file_found = false ]]; then + echo "watchdog None" > /host/reboot-cause/platform/reboot_reason + echo "thermal None" >> /host/reboot-cause/platform/reboot_reason + fi + + if [[ -d /sys/devices/platform/SMF.512/hwmon/ ]]; then + track_thermal + is_thermal_reboot=$(echo $?) + + track_watchdog + is_wd_reboot=$(echo $?) + + rv=$(cd /sys/devices/platform/SMF.512/hwmon/*; cat mb_poweron_reason) + reason=$(echo $rv | cut -d 'x' -f2) + if [[ $reason = "ff" ]]; then + sed -i "2s/.*/thermal None/" /host/reboot-cause/platform/reboot_reason + cd /sys/devices/platform/SMF.512/hwmon/* + if [[ -e /tmp/notify_firstboot_to_platform ]]; then + echo 0x01 > mb_poweron_reason + else + echo 0xbb > mb_poweron_reason + fi + elif [[ $is_thermal_reboot = 1 ]]; then + cd /sys/devices/platform/SMF.512/hwmon/* + echo 0xee > mb_poweron_reason + elif [[ $is_wd_reboot = 1 ]]; then + cd /sys/devices/platform/SMF.512/hwmon/* + echo 0xdd > mb_poweron_reason + elif [[ $reason = "cc" ]]; then + cd /sys/devices/platform/SMF.512/hwmon/* + echo 0xaa > mb_poweron_reason + else + cd /sys/devices/platform/SMF.512/hwmon/* + echo 0x99 > mb_poweron_reason + fi + fi +} +track_reboot_reason diff --git a/platform/broadcom/sonic-platform-modules-dell/z9100/scripts/z9100_platform.sh b/platform/broadcom/sonic-platform-modules-dell/z9100/scripts/z9100_platform.sh index 3cc48e52110..d67cd7bbc8f 100755 --- a/platform/broadcom/sonic-platform-modules-dell/z9100/scripts/z9100_platform.sh +++ b/platform/broadcom/sonic-platform-modules-dell/z9100/scripts/z9100_platform.sh @@ -200,6 +200,26 @@ init_switch_port_led() { } +track_reboot_reason() { + /usr/share/sonic/device/x86_64-dell_z9100_c2538-r0/track_reboot_reason.sh + status=$(echo $?) + return status +} + +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) +} + +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 +} + init_devnum if [[ "$1" == "init" ]]; then @@ -208,6 +228,7 @@ if [[ "$1" == "init" ]]; then modprobe dell_ich modprobe dell_mailbox modprobe dell_z9100_cpld + track_reboot_reason cpu_board_mux "new_device" switch_board_mux "new_device" @@ -220,6 +241,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 @@ -241,6 +263,7 @@ elif [[ "$1" == "deinit" ]]; then modprobe -r i2c-mux-pca954x modprobe -r i2c-dev modprobe -r dell_ich + remove_python_api_package else echo "z9100_platform : Invalid option !" fi diff --git a/platform/broadcom/sonic-platform-modules-dell/z9100/setup.py b/platform/broadcom/sonic-platform-modules-dell/z9100/setup.py new file mode 120000 index 00000000000..4f6de9941d9 --- /dev/null +++ b/platform/broadcom/sonic-platform-modules-dell/z9100/setup.py @@ -0,0 +1 @@ +../s6100/setup.py \ No newline at end of file diff --git a/platform/broadcom/sonic-platform-modules-dell/z9100/sonic_platform/__init__.py b/platform/broadcom/sonic-platform-modules-dell/z9100/sonic_platform/__init__.py new file mode 100755 index 00000000000..4bfefa0fb63 --- /dev/null +++ b/platform/broadcom/sonic-platform-modules-dell/z9100/sonic_platform/__init__.py @@ -0,0 +1,3 @@ +__all__ = ["platform", "chassis"] +from sonic_platform import * + diff --git a/platform/broadcom/sonic-platform-modules-dell/z9100/sonic_platform/chassis.py b/platform/broadcom/sonic-platform-modules-dell/z9100/sonic_platform/chassis.py new file mode 100755 index 00000000000..aef60bec129 --- /dev/null +++ b/platform/broadcom/sonic-platform-modules-dell/z9100/sonic_platform/chassis.py @@ -0,0 +1,104 @@ +#!/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_reason_smf_register(self): + # Returns 0xAA on software reload + # Returns 0xFF on power-cycle + # Returns 0x01 on first-boot + smf_mb_reg_reason = self._get_pmc_register('mb_poweron_reason') + return int(smf_mb_reg_reason, 16) + + 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')) + smf_mb_reg_reason = self._get_reboot_reason_smf_register() + + if ((smf_mb_reg_reason == 0x01) and (power_reason == 0x11)): + return (ChassisBase.REBOOT_CAUSE_NON_HARDWARE, None) + + # 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 + + # In Z9100, if Reset_Reason is not 11 and smf_mb_reg_reason + # is ff or bb, then it is PowerLoss + if (reset_reason == 11): + if (power_reason in self.power_reason_dict): + return (self.power_reason_dict[power_reason], None) + else: + if (smf_mb_reg_reason == 0xaa): + return (ChassisBase.REBOOT_CAUSE_NON_HARDWARE, None) + elif ((smf_mb_reg_reason == 0xbb) or (smf_mb_reg_reason == 0xff)): + return (ChassisBase.REBOOT_CAUSE_POWER_LOSS, None) + elif (smf_mb_reg_reason == 0xdd): + return (ChassisBase.REBOOT_CAUSE_WATCHDOG, None) + elif (smf_mb_reg_reason == 0xee): + return (self.power_reason_dict[power_reason], None) + else: + return (ChassisBase.REBOOT_CAUSE_NON_HARDWARE, None) + + return (ChassisBase.REBOOT_CAUSE_HARDWARE_OTHER, "Invalid Reason") + diff --git a/platform/broadcom/sonic-platform-modules-dell/z9100/sonic_platform/platform.py b/platform/broadcom/sonic-platform-modules-dell/z9100/sonic_platform/platform.py new file mode 100755 index 00000000000..426db717281 --- /dev/null +++ b/platform/broadcom/sonic-platform-modules-dell/z9100/sonic_platform/platform.py @@ -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() + diff --git a/platform/broadcom/sonic-platform-modules-s6000/.gitignore b/platform/broadcom/sonic-platform-modules-s6000/.gitignore deleted file mode 100644 index 7f287d53822..00000000000 --- a/platform/broadcom/sonic-platform-modules-s6000/.gitignore +++ /dev/null @@ -1,50 +0,0 @@ -# Object files -*.o -*.ko -*.obj -*.elf - -# Precompiled Headers -*.gch -*.pch - -# Libraries -*.lib -*.a -*.la -*.lo - -# Shared objects (inc. Windows DLLs) -*.dll -*.so -*.so.* -*.dylib - -# Executables -*.exe -*.out -*.app -*.i*86 -*.x86_64 -*.hex - -# Debug files -*.dSYM/ -*.su - -# Kernel Module Compile Results -*.mod* -*.cmd -*.o.d -.tmp_versions/ -modules.order -Module.symvers -Mkfile.old -dkms.conf - -# Debian packaging -*.debhelper.log -*.postinst.debhelper -*.postrm.debhelper -*.prerm.debhelper -*.substvars diff --git a/platform/broadcom/sonic-platform-modules-s6000/debian/changelog b/platform/broadcom/sonic-platform-modules-s6000/debian/changelog deleted file mode 100644 index 0a6b7820bde..00000000000 --- a/platform/broadcom/sonic-platform-modules-s6000/debian/changelog +++ /dev/null @@ -1,5 +0,0 @@ -platform-modules-s6000 (1.0) unstable; urgency=low - - * Initial release - - -- Shuotian Cheng Mon, 11 Nov 2015 11:11:11 -0800 diff --git a/platform/broadcom/sonic-platform-modules-s6000/debian/compat b/platform/broadcom/sonic-platform-modules-s6000/debian/compat deleted file mode 100644 index 45a4fb75db8..00000000000 --- a/platform/broadcom/sonic-platform-modules-s6000/debian/compat +++ /dev/null @@ -1 +0,0 @@ -8 diff --git a/platform/broadcom/sonic-platform-modules-s6000/debian/control b/platform/broadcom/sonic-platform-modules-s6000/debian/control deleted file mode 100644 index a9f2a76ebed..00000000000 --- a/platform/broadcom/sonic-platform-modules-s6000/debian/control +++ /dev/null @@ -1,12 +0,0 @@ -Source: platform-modules-s6000 -Section: main -Priority: extra -Maintainer: Shuotian Cheng -Build-Depends: debhelper (>= 8.0.0), bzip2 -Standards-Version: 3.9.3 - -Package: platform-modules-s6000 -Architecture: amd64 -Depends: linux-image-4.9.0-9-2-amd64 -Description: kernel modules for platform devices such as fan, led, sfp - diff --git a/platform/broadcom/sonic-platform-modules-s6000/debian/copyright b/platform/broadcom/sonic-platform-modules-s6000/debian/copyright deleted file mode 100644 index 6fbc5a7f6ca..00000000000 --- a/platform/broadcom/sonic-platform-modules-s6000/debian/copyright +++ /dev/null @@ -1,16 +0,0 @@ -Provides linux sysfs interface to Dell S6000 platform hardware peripherals -Copyright (C) 2016 Microsoft - -This program is free software; you can redistribute it and/or -modify it under the terms of the GNU General Public License -as published by the Free Software Foundation; either version 2 -of the License, or (at your option) any later version. - -This program is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -GNU General Public License for more details. - -You should have received a copy of the GNU General Public License -along with this program; if not, write to the Free Software -Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. diff --git a/platform/broadcom/sonic-platform-modules-s6000/debian/platform-modules-s6000.install b/platform/broadcom/sonic-platform-modules-s6000/debian/platform-modules-s6000.install deleted file mode 100644 index 8fdf12a41c8..00000000000 --- a/platform/broadcom/sonic-platform-modules-s6000/debian/platform-modules-s6000.install +++ /dev/null @@ -1,2 +0,0 @@ -systemd/platform-modules-s6000.service lib/systemd/system -scripts/io_rd_wr.py usr/local/bin diff --git a/platform/broadcom/sonic-platform-modules-s6000/debian/rules b/platform/broadcom/sonic-platform-modules-s6000/debian/rules deleted file mode 100755 index 5473743ea38..00000000000 --- a/platform/broadcom/sonic-platform-modules-s6000/debian/rules +++ /dev/null @@ -1,32 +0,0 @@ -#!/usr/bin/make -f - -export INSTALL_MOD_DIR:=extra - -PACKAGE_NAME := platform-modules-s6000 -KVERSION ?= $(shell uname -r) -KERNEL_SRC := /lib/modules/$(KVERSION) -MODULE_SRC := $(shell pwd)/modules -SCRIPT_SRC := $(shell pwd)/scripts - -%: - dh $@ --with=systemd - -override_dh_auto_build: - make -C $(KERNEL_SRC)/build M=$(MODULE_SRC) - -override_dh_auto_install: - dh_installdirs -p$(PACKAGE_NAME) $(KERNEL_SRC)/$(INSTALL_MOD_DIR) - cp $(MODULE_SRC)/*.ko debian/$(PACKAGE_NAME)/$(KERNEL_SRC)/$(INSTALL_MOD_DIR) - dh_installdirs -p$(PACKAGE_NAME) usr/local/bin - cp -r $(SCRIPT_SRC)/* debian/$(PACKAGE_NAME)/usr/local/bin - -override_dh_usrlocal: - -override_dh_pysupport: - -override_dh_clean: - dh_clean - rm -f $(MODULE_SRC)/*.o $(MODULE_SRC)/*.ko $(MODULE_SRC)/*.mod.c $(MODULE_SRC)/.*.cmd - rm -f $(MODULE_SRC)/Module.markers $(MODULE_SRC)/Module.symvers $(MODULE_SRC)/modules.order - rm -rf $(MODULE_SRC)/.tmp_versions -