From c841693007a8a9df1e116aff4bf5caf5a5442bf7 Mon Sep 17 00:00:00 2001 From: Arun Saravanan Balachandran <52521751+ArunSaravananBalachandran@users.noreply.github.com> Date: Fri, 24 Jan 2020 23:38:22 +0530 Subject: [PATCH] DellEMC: Platform2.0 API enhancements in DellEMC S6000 and other API changes (#3956) --- .../s6000/sonic_platform/chassis.py | 1 + .../s6000/sonic_platform/eeprom.py | 4 ++ .../s6000/sonic_platform/fan.py | 42 ++++++++++++++++--- .../s6000/sonic_platform/psu.py | 30 ++++++++++++- .../s6000/sonic_platform/thermal.py | 37 +++++++++++++++- .../s6100/sonic_platform/fan.py | 11 +++-- .../z9100/sonic_platform/chassis.py | 2 +- .../z9100/sonic_platform/fan.py | 11 +++-- 8 files changed, 122 insertions(+), 16 deletions(-) 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 index c212df88c147..e94a7d1210f5 100755 --- a/platform/broadcom/sonic-platform-modules-dell/s6000/sonic_platform/chassis.py +++ b/platform/broadcom/sonic-platform-modules-dell/s6000/sonic_platform/chassis.py @@ -43,6 +43,7 @@ class Chassis(ChassisBase): reset_reason_dict[0x6] = ChassisBase.REBOOT_CAUSE_NON_HARDWARE def __init__(self): + ChassisBase.__init__(self) # Initialize SFP list self.PORT_START = 0 self.PORT_END = 31 diff --git a/platform/broadcom/sonic-platform-modules-dell/s6000/sonic_platform/eeprom.py b/platform/broadcom/sonic-platform-modules-dell/s6000/sonic_platform/eeprom.py index 32462e5a256e..a82fd6a70201 100644 --- a/platform/broadcom/sonic-platform-modules-dell/s6000/sonic_platform/eeprom.py +++ b/platform/broadcom/sonic-platform-modules-dell/s6000/sonic_platform/eeprom.py @@ -150,6 +150,10 @@ def _load_device_eeprom(self): except: self.serial_number = 'NA' self.part_number = 'NA' + if self.is_psu_eeprom: + self.psu_type = 'NA' + else: + self.fan_type = 'NA' else: (valid, data) = self._get_eeprom_field("PPID") if valid: diff --git a/platform/broadcom/sonic-platform-modules-dell/s6000/sonic_platform/fan.py b/platform/broadcom/sonic-platform-modules-dell/s6000/sonic_platform/fan.py index 29555b443a22..92f83c8fbc79 100644 --- a/platform/broadcom/sonic-platform-modules-dell/s6000/sonic_platform/fan.py +++ b/platform/broadcom/sonic-platform-modules-dell/s6000/sonic_platform/fan.py @@ -11,6 +11,7 @@ try: import os + import glob from sonic_platform_base.fan_base import FanBase from sonic_platform.eeprom import Eeprom except ImportError as e: @@ -29,6 +30,7 @@ class Fan(FanBase): def __init__(self, fan_index, psu_fan=False, dependency=None): self.is_psu_fan = psu_fan + self.is_driver_initialized = True if not self.is_psu_fan: # Fan is 1-based in DellEMC platforms @@ -45,10 +47,18 @@ def __init__(self, fan_index, psu_fan=False, dependency=None): else: self.index = fan_index self.dependency = dependency - self.get_fan_speed_reg = self.I2C_DIR +\ - "i2c-1/1-005{}/fan1_target".format(10 - self.index) self.set_fan_speed_reg = self.I2C_DIR +\ "i2c-1/1-005{}/fan1_target".format(10 - self.index) + + hwmon_dir = self.I2C_DIR +\ + "i2c-1/1-005{}/hwmon/".format(10 - self.index) + try: + hwmon_node = os.listdir(hwmon_dir)[0] + except OSError: + hwmon_node = "hwmon*" + self.is_driver_initialized = False + + self.get_fan_speed_reg = hwmon_dir + hwmon_node + '/fan1_input' self.max_fan_speed = MAX_S6000_PSU_FAN_SPEED def _get_cpld_register(self, reg_name): @@ -93,6 +103,14 @@ def _get_i2c_register(self, reg_file): # reg_name and on failure returns 'ERR' rv = 'ERR' + if not self.is_driver_initialized: + reg_file_path = glob.glob(reg_file) + if len(reg_file_path): + reg_file = reg_file_path[0] + self._get_sysfs_path() + else: + return rv + if (not os.path.isfile(reg_file)): return rv @@ -122,6 +140,13 @@ def _set_i2c_register(self, reg_file, value): return rv + def _get_sysfs_path(self): + fan_speed_reg = glob.glob(self.get_fan_speed_reg) + + if len(fan_speed_reg): + self.get_fan_speed_reg = fan_speed_reg[0] + self.is_driver_initialized = True + def get_name(self): """ Retrieves the name of the Fan @@ -200,16 +225,21 @@ def get_direction(self): Returns: A string, either FAN_DIRECTION_INTAKE or FAN_DIRECTION_EXHAUST depending on fan direction + + Notes: + In DellEMC platforms, + - Forward/Exhaust : Air flows from Port side to Fan side. + - Reverse/Intake : Air flows from Fan side to Port side. """ if self.is_psu_fan: - direction = {1: 'FAN_DIRECTION_EXHAUST', 2: 'FAN_DIRECTION_INTAKE', - 3: 'FAN_DIRECTION_EXHAUST', 4: 'FAN_DIRECTION_INTAKE'} + direction = {1: self.FAN_DIRECTION_EXHAUST, 2: self.FAN_DIRECTION_INTAKE, + 3: self.FAN_DIRECTION_EXHAUST, 4: self.FAN_DIRECTION_INTAKE} fan_direction = self.dependency.eeprom.airflow_fan_type() else: - direction = {1: 'FAN_DIRECTION_EXHAUST', 2: 'FAN_DIRECTION_INTAKE'} + direction = {1: self.FAN_DIRECTION_EXHAUST, 2: self.FAN_DIRECTION_INTAKE} fan_direction = self.eeprom.airflow_fan_type() - return direction.get(fan_direction,'NA') + return direction.get(fan_direction, self.FAN_DIRECTION_NOT_APPLICABLE) def get_speed(self): """ diff --git a/platform/broadcom/sonic-platform-modules-dell/s6000/sonic_platform/psu.py b/platform/broadcom/sonic-platform-modules-dell/s6000/sonic_platform/psu.py index e2897a78d9fd..24200f1c7d39 100644 --- a/platform/broadcom/sonic-platform-modules-dell/s6000/sonic_platform/psu.py +++ b/platform/broadcom/sonic-platform-modules-dell/s6000/sonic_platform/psu.py @@ -11,6 +11,7 @@ try: import os + import glob from sonic_platform_base.psu_base import PsuBase from sonic_platform.eeprom import Eeprom from sonic_platform.fan import Fan @@ -29,12 +30,20 @@ def __init__(self, psu_index): self.index = psu_index + 1 self.psu_presence_reg = "psu{}_prs".format(psu_index) self.psu_status_reg = "powersupply_status" + self.is_driver_initialized = False if self.index == 1: ltc_dir = self.I2C_DIR + "i2c-11/11-0042/hwmon/" else: ltc_dir = self.I2C_DIR + "i2c-11/11-0040/hwmon/" - hwmon_node = os.listdir(ltc_dir)[0] + + try: + hwmon_node = os.listdir(ltc_dir)[0] + except OSError: + hwmon_node = "hwmon*" + else: + self.is_driver_initialized = True + self.HWMON_DIR = ltc_dir + hwmon_node + '/' self.psu_voltage_reg = self.HWMON_DIR + "in1_input" @@ -73,6 +82,14 @@ def _get_i2c_register(self, reg_file): # reg_name and on failure returns 'ERR' rv = 'ERR' + if not self.is_driver_initialized: + reg_file_path = glob.glob(reg_file) + if len(reg_file_path): + reg_file = reg_file_path[0] + self._get_sysfs_path() + else: + return rv + if (not os.path.isfile(reg_file)): return rv @@ -86,6 +103,17 @@ def _get_i2c_register(self, reg_file): rv = rv.lstrip(" ") return rv + def _get_sysfs_path(self): + voltage_reg = glob.glob(self.psu_voltage_reg) + current_reg = glob.glob(self.psu_current_reg) + power_reg = glob.glob(self.psu_power_reg) + + if len(voltage_reg) and len(current_reg) and len(power_reg): + self.psu_voltage_reg = voltage_reg_path[0] + self.psu_current_reg = current_reg_path[0] + self.psu_power_reg = power_reg_path[0] + self.is_driver_initialized = True + def get_name(self): """ Retrieves the name of the device diff --git a/platform/broadcom/sonic-platform-modules-dell/s6000/sonic_platform/thermal.py b/platform/broadcom/sonic-platform-modules-dell/s6000/sonic_platform/thermal.py index 70bac0c729d2..a54336d40f1c 100644 --- a/platform/broadcom/sonic-platform-modules-dell/s6000/sonic_platform/thermal.py +++ b/platform/broadcom/sonic-platform-modules-dell/s6000/sonic_platform/thermal.py @@ -11,6 +11,7 @@ try: import os + import glob from sonic_platform_base.thermal_base import ThermalBase from sonic_platform.psu import Psu except ImportError as e: @@ -36,13 +37,19 @@ class Thermal(ThermalBase): def __init__(self, thermal_index): self.index = thermal_index + 1 self.is_psu_thermal = False + self.is_driver_initialized = True self.dependency = None if self.index < 9: i2c_path = self.I2C_DIR + self.I2C_DEV_MAPPING[self.index - 1][0] hwmon_temp_index = self.I2C_DEV_MAPPING[self.index - 1][1] hwmon_temp_suffix = "max" - hwmon_node = os.listdir(i2c_path)[0] + try: + hwmon_node = os.listdir(i2c_path)[0] + except OSError: + hwmon_node = "hwmon*" + self.is_driver_initialized = False + self.HWMON_DIR = i2c_path + hwmon_node + '/' if self.index == 4: @@ -55,7 +62,12 @@ def __init__(self, thermal_index): dev_path = "/sys/devices/platform/coretemp.0/hwmon/" hwmon_temp_index = self.index - 7 hwmon_temp_suffix = "crit" - hwmon_node = os.listdir(dev_path)[0] + try: + hwmon_node = os.listdir(dev_path)[0] + except OSError: + hwmon_node = "hwmon*" + self.is_driver_initialized = False + self.HWMON_DIR = dev_path + hwmon_node + '/' self.thermal_temperature_file = self.HWMON_DIR \ @@ -70,6 +82,14 @@ def _read_sysfs_file(self, sysfs_file): # sysfs_file and on failure returns 'ERR' rv = 'ERR' + if not self.is_driver_initialized: + sysfs_file_path = glob.glob(sysfs_file) + if len(sysfs_file_path): + sysfs_file = sysfs_file_path[0] + self._get_sysfs_path() + else: + return rv + if (not os.path.isfile(sysfs_file)): return rv @@ -83,6 +103,19 @@ def _read_sysfs_file(self, sysfs_file): rv = rv.lstrip(" ") return rv + def _get_sysfs_path(self): + temperature_path = glob.glob(self.thermal_temperature_file) + high_threshold_path = glob.glob(self.thermal_high_threshold_file) + low_threshold_path = glob.glob(self.thermal_low_threshold_file) + + if len(temperature_path) and len(high_threshold_path): + self.thermal_temperature_file = temperature_path[0] + self.thermal_high_threshold_file = high_threshold_path[0] + if len(low_threshold_path): + self.thermal_low_threshold_file = low_threshold_path + + self.is_driver_initialized = True + def get_name(self): """ Retrieves the name of the thermal diff --git a/platform/broadcom/sonic-platform-modules-dell/s6100/sonic_platform/fan.py b/platform/broadcom/sonic-platform-modules-dell/s6100/sonic_platform/fan.py index a2ee0cd10421..49e95357b6f1 100644 --- a/platform/broadcom/sonic-platform-modules-dell/s6100/sonic_platform/fan.py +++ b/platform/broadcom/sonic-platform-modules-dell/s6100/sonic_platform/fan.py @@ -146,7 +146,7 @@ def get_status(self): fantray_status = self._get_pmc_register(self.get_fan_speed_reg) if (fantray_status != 'ERR'): fantray_status = int(fantray_status, 10) - if (fantray_status > 5000): + if (fantray_status > 1000): status = True else: fantray_status = self._get_pmc_register(self.fan_status_reg) @@ -163,13 +163,18 @@ def get_direction(self): Returns: A string, either FAN_DIRECTION_INTAKE or FAN_DIRECTION_EXHAUST depending on fan direction + + Notes: + In DellEMC platforms, + - Forward/Exhaust : Air flows from Port side to Fan side. + - Reverse/Intake : Air flows from Fan side to Port side. """ - direction = ['FAN_DIRECTION_INTAKE', 'FAN_DIRECTION_EXHAUST'] + direction = [self.FAN_DIRECTION_INTAKE, self.FAN_DIRECTION_EXHAUST] fan_direction = self._get_pmc_register(self.get_fan_dir_reg) if (fan_direction != 'ERR') and self.get_presence(): fan_direction = int(fan_direction, 10) else: - return 'N/A' + return self.FAN_DIRECTION_NOT_APPLICABLE return direction[fan_direction] def get_speed(self): 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 index 27164409d962..7f4dab3a19c0 100755 --- a/platform/broadcom/sonic-platform-modules-dell/z9100/sonic_platform/chassis.py +++ b/platform/broadcom/sonic-platform-modules-dell/z9100/sonic_platform/chassis.py @@ -73,6 +73,7 @@ class Chassis(ChassisBase): power_reason_dict[44] = ChassisBase.REBOOT_CAUSE_INSUFFICIENT_FAN_SPEED def __init__(self): + ChassisBase.__init__(self) PORT_START = 0 PORT_END = 31 PORTS_IN_BLOCK = (PORT_END + 1) @@ -92,7 +93,6 @@ def __init__(self): self.PORT_I2C_MAPPING[index][1]) self._sfp_list.append(sfp_node) - ChassisBase.__init__(self) # Initialize EEPROM self._eeprom = Eeprom() for i in range(MAX_Z9100_FANTRAY): diff --git a/platform/broadcom/sonic-platform-modules-dell/z9100/sonic_platform/fan.py b/platform/broadcom/sonic-platform-modules-dell/z9100/sonic_platform/fan.py index 03ac8cd5c71f..6ff688fa3a1e 100755 --- a/platform/broadcom/sonic-platform-modules-dell/z9100/sonic_platform/fan.py +++ b/platform/broadcom/sonic-platform-modules-dell/z9100/sonic_platform/fan.py @@ -145,7 +145,7 @@ def get_status(self): fantray_status = self._get_pmc_register(self.get_fan_speed_reg) if (fantray_status != 'ERR'): fantray_status = int(fantray_status, 10) - if (fantray_status > 5000): + if (fantray_status > 1000): status = True else: fantray_status = self._get_pmc_register(self.fan_status_reg) @@ -162,13 +162,18 @@ def get_direction(self): Returns: A string, either FAN_DIRECTION_INTAKE or FAN_DIRECTION_EXHAUST depending on fan direction + + Notes: + In DellEMC platforms, + - Forward/Exhaust : Air flows from Port side to Fan side. + - Reverse/Intake : Air flows from Fan side to Port side. """ - direction = ['FAN_DIRECTION_INTAKE', 'FAN_DIRECTION_EXHAUST'] + direction = [self.FAN_DIRECTION_INTAKE, self.FAN_DIRECTION_EXHAUST] fan_direction = self._get_pmc_register(self.get_fan_dir_reg) if (fan_direction != 'ERR') and self.get_presence(): fan_direction = int(fan_direction, 10) else: - return 'N/A' + return self.FAN_DIRECTION_NOT_APPLICABLE return direction[fan_direction] def get_speed(self):