diff --git a/device/celestica/x86_64-cel_questone2bd-r0/sonic_platform/chassis.py b/device/celestica/x86_64-cel_questone2bd-r0/sonic_platform/chassis.py index d33be4769ce6..7f439d2048f0 100644 --- a/device/celestica/x86_64-cel_questone2bd-r0/sonic_platform/chassis.py +++ b/device/celestica/x86_64-cel_questone2bd-r0/sonic_platform/chassis.py @@ -40,13 +40,14 @@ def __init__(self): ChassisBase.__init__(self) self._api_helper = APIHelper() self.sfp_module_initialized = False - self.__initialize_components() if not self._api_helper.is_host(): - self.__initialize_psu() self.__initialize_fan() + self.__initialize_psu() self.__initialize_eeprom() self.__initialize_thermals() + else: + self.__initialize_components() def __initialize_sfp(self): from sonic_platform.sfp import Sfp @@ -114,7 +115,6 @@ def get_system_eeprom_info(self): def get_reboot_cause(self): """ Retrieves the cause of the previous reboot - Returns: A tuple (string, string) where the first element is a string containing the cause of the previous reboot. This string must be diff --git a/device/celestica/x86_64-cel_questone2bd-r0/sonic_platform/fan.py b/device/celestica/x86_64-cel_questone2bd-r0/sonic_platform/fan.py index 6c060e852d47..7d4e1647ab95 100644 --- a/device/celestica/x86_64-cel_questone2bd-r0/sonic_platform/fan.py +++ b/device/celestica/x86_64-cel_questone2bd-r0/sonic_platform/fan.py @@ -30,11 +30,14 @@ FAN_MAX_RPM = FAN_MAX_PWM * FAN_RPM_MULTIPLIER FAN_PRESENT_SYSFS = "fan{}_present" FAN_PWM_SYSFS = "fan{}_pwm" +FAN_INPUT_SYSFS = "fan{}_input" FAN_DIRECTION_SYSFS = "fan{}_dir" FAN_LED_SYSFS = "fan{}_led" FAN_LED_GREEN_CMD = "0x1" FAN_LED_RED_CMD = "0x2" FAN_LED_OFF_CMD = "0x3" +FAN_FRONT_MAX_RPM = 29700 +FAN_REAR_MAX_RPM = 24700 PSU_FAN_MAX_RPM = 30000 PSU_HWMON_PATH = "/sys/bus/i2c/devices/i2c-{0}/{0}-00{1}/hwmon" @@ -56,7 +59,7 @@ class Fan(FanBase): """Platform-specific Fan class""" - def __init__(self, fan_tray_index, fan_index=0, is_psu_fan=False, psu_index=0): + def __init__(self, fan_tray_index, fan_index=0, is_psu_fan=False, psu_index=0, psu_fan_direction=0): self.fan_index = fan_index self.fan_tray_index = fan_tray_index self.is_psu_fan = is_psu_fan @@ -64,6 +67,7 @@ def __init__(self, fan_tray_index, fan_index=0, is_psu_fan=False, psu_index=0): self.psu_index = psu_index self.psu_hwmon_path = PSU_HWMON_PATH.format( PSU_I2C_MAPPING[self.psu_index]["i2c_num"], PSU_I2C_MAPPING[self.psu_index]["pmbus_reg"]) + self.psu_fan_direction = self.FAN_DIRECTION_EXHAUST if psu_fan_direction else self.FAN_DIRECTION_INTAKE self._api_helper = APIHelper() self.index = self.fan_tray_index * 2 + self.fan_index @@ -91,7 +95,7 @@ def get_direction(self): depending on fan direction """ if self.is_psu_fan: - return self.FAN_DIRECTION_EXHAUST + return self.psu_fan_direction fan_direction_val = self.__read_fan_sysfs( FAN_DIRECTION_SYSFS.format(self.fan_tray_index+1)) @@ -109,6 +113,7 @@ def get_speed(self): M = 150 Max = 38250 RPM """ + speed_rpm = 0 if self.is_psu_fan: speed = 0 fan_name = "fan{}_input" @@ -121,13 +126,11 @@ def get_speed(self): hwmon, fan_name.format(self.fan_index+1)) speed_rpm = self._api_helper.read_one_line_file(fan_path) speed = int(float(speed_rpm) / PSU_FAN_MAX_RPM * 100) - - return speed - - speed_raw = self.__read_fan_sysfs( - FAN_PWM_SYSFS.format(self.fan_tray_index+1)) - speed_val = int(speed_raw, 16) - speed = int(float(speed_val)/FAN_MAX_PWM * 100) + else: + speed_rpm = self.__read_fan_sysfs( + FAN_INPUT_SYSFS.format(self.fan_tray_index+1)) + fan_max_rpm = FAN_FRONT_MAX_RPM if "F" in self.get_name() else FAN_REAR_MAX_RPM + speed = int(float(speed_rpm) / fan_max_rpm * 100) return speed @@ -144,8 +147,7 @@ def get_target_speed(self): 0 : when PWM mode is use pwm : when pwm mode is not use """ - target = 0 - return target + return "N/A" def get_speed_tolerance(self): """ @@ -267,8 +269,7 @@ def get_model(self): string: Model/part number of device """ if self.is_psu_fan: - temp_file = PSU_MUX_HWMON_PATH.format((self.fan_tray_index+1) + 75) - return self._api_helper.fru_decode_product_model(self._api_helper.read_eeprom_sysfs(temp_file, "eeprom")) + return 'N/A' temp_file = FAN_MUX_HWMON_PATH.format((self.fan_tray_index+1) * 2) return self._api_helper.fru_decode_product_model(self._api_helper.read_eeprom_sysfs(temp_file, "eeprom")) @@ -280,8 +281,7 @@ def get_serial(self): string: Serial number of device """ if self.is_psu_fan: - temp_file = PSU_MUX_HWMON_PATH.format((self.fan_tray_index+1) + 75) - return self._api_helper.fru_decode_product_serial(self._api_helper.read_eeprom_sysfs(temp_file, "eeprom")) + return 'N/A' temp_file = FAN_MUX_HWMON_PATH.format((self.fan_tray_index+1) * 2) return self._api_helper.fru_decode_product_serial(self._api_helper.read_eeprom_sysfs(temp_file, "eeprom")) diff --git a/device/celestica/x86_64-cel_questone2bd-r0/sonic_platform/helper.py b/device/celestica/x86_64-cel_questone2bd-r0/sonic_platform/helper.py index acc7af0424b6..0645a2962b79 100644 --- a/device/celestica/x86_64-cel_questone2bd-r0/sonic_platform/helper.py +++ b/device/celestica/x86_64-cel_questone2bd-r0/sonic_platform/helper.py @@ -150,6 +150,7 @@ def ipmi_set_ss_thres(self, id, threshold_key, value): return status, result def fru_decode_product_serial(self, data): + if data[4] != 00: start_product_info = ord(data[4]) * 8 start_format_version = start_product_info @@ -166,10 +167,10 @@ def fru_decode_product_serial(self, data): start_product_serial_number = start_product_version + start_product_version_length +1 start_product_serial_number_length = ord(data[start_product_serial_number]) & 0x1F return data[start_product_serial_number+1:start_product_serial_number+start_product_serial_number_length+1] - else: - return None + return "N/A" def fru_decode_product_model(self, data): + if data[4] != 00: start_product_info = ord(data[4]) * 8 start_format_version = start_product_info @@ -186,8 +187,23 @@ def fru_decode_product_model(self, data): start_product_serial_number = start_product_version + start_product_version_length +1 start_product_serial_number_length = ord(data[start_product_serial_number]) & 0x1F return data[start_product_module_number+1:start_product_module_number+start_product_module_number_length+1] - else: - return None + + return "N/A" + + def fru_decode_product_name(self, data): + + if data[4] != 00: + start_product_info = ord(data[4]) * 8 + start_format_version = start_product_info + start_product_info = start_format_version + 1 + start_product_Lang_code = start_product_info + 1 + start_product_Manu_name = start_product_Lang_code + 1 + start_product_Manu_name_length = ord(data[start_product_Manu_name]) & 0x0F + start_product_name = start_product_Manu_name + start_product_Manu_name_length + 1 + start_product_name_length = ord(data[start_product_name]) & 0x0F + return data[start_product_name+1: start_product_name+start_product_name_length+1] + + return "N/A" def read_eeprom_sysfs(self,sys_path,sysfs_file): sysfs_path = os.path.join(sys_path, sysfs_file) @@ -197,4 +213,4 @@ def read_eeprom_sysfs(self,sys_path,sysfs_file): return data except: pass - return False \ No newline at end of file + return None diff --git a/device/celestica/x86_64-cel_questone2bd-r0/sonic_platform/psu.py b/device/celestica/x86_64-cel_questone2bd-r0/sonic_platform/psu.py index 7e1584496cdd..23c5f514a795 100644 --- a/device/celestica/x86_64-cel_questone2bd-r0/sonic_platform/psu.py +++ b/device/celestica/x86_64-cel_questone2bd-r0/sonic_platform/psu.py @@ -58,12 +58,22 @@ class Psu(PsuBase): def __init__(self, psu_index): PsuBase.__init__(self) self.index = psu_index - for fan_index in range(0, PSU_NUM_FAN[self.index]): - fan = Fan(fan_index, 0, is_psu_fan=True, psu_index=self.index) - self._fan_list.append(fan) self.hwmon_path = HWMON_PATH.format( PSU_INFO_MAPPING[self.index]["i2c_num"], PSU_INFO_MAPPING[self.index]["pmbus_reg"]) self._api_helper = APIHelper() + for fan_index in range(0, PSU_NUM_FAN[self.index]): + fan = Fan(fan_index, 0, is_psu_fan=True, psu_index=self.index, + psu_fan_direction=self.__get_fan_direction()) + self._fan_list.append(fan) + + def __get_fan_direction(self): + # DPS-1100FB = Intake + # DPS-1100AB = exhaust + eeprom_path = PSU_MUX_HWMON_PATH.format( + ((self.index) + 75), self.index+50) + fru_pn = self._api_helper.fru_decode_product_name( + self._api_helper.read_eeprom_sysfs(eeprom_path, "eeprom")) + return 0 if "FB" in fru_pn else 1 def __search_file_by_contain(self, directory, search_str, file_start): for dirpath, dirnames, files in os.walk(directory): @@ -208,9 +218,9 @@ def get_model(self): Returns: string: Model/part number of device """ - temp_file = PSU_MUX_HWMON_PATH.format( + eeprom_path = PSU_MUX_HWMON_PATH.format( ((self.index) + 75), self.index+50) - return self._api_helper.fru_decode_product_model(self._api_helper.read_eeprom_sysfs(temp_file, "eeprom")) + return self._api_helper.fru_decode_product_model(self._api_helper.read_eeprom_sysfs(eeprom_path, "eeprom")) def get_serial(self): """ @@ -218,9 +228,9 @@ def get_serial(self): Returns: string: Serial number of device """ - temp_file = PSU_MUX_HWMON_PATH.format( + eeprom_path = PSU_MUX_HWMON_PATH.format( ((self.index) + 75), self.index+50) - return self._api_helper.fru_decode_product_serial(self._api_helper.read_eeprom_sysfs(temp_file, "eeprom")) + return self._api_helper.fru_decode_product_serial(self._api_helper.read_eeprom_sysfs(eeprom_path, "eeprom")) def get_status(self): """ diff --git a/device/celestica/x86_64-cel_questone2bd-r0/sonic_platform/thermal.py b/device/celestica/x86_64-cel_questone2bd-r0/sonic_platform/thermal.py index ed1dad64810d..ee84a9e1f681 100644 --- a/device/celestica/x86_64-cel_questone2bd-r0/sonic_platform/thermal.py +++ b/device/celestica/x86_64-cel_questone2bd-r0/sonic_platform/thermal.py @@ -21,7 +21,7 @@ SENSORS_HWMON_PATH = "/sys/bus/i2c/devices/i2c-{0}/{0}-00{1}" SENSORS_MUX_HWMON_PATH = "/sys/bus/i2c/devices/i2c-{0}/i2c-{1}/{1}-00{2}" -DEFAULT_VAL = 0.0 +DEFAULT_VAL = 'N/A' class Thermal(ThermalBase): """Platform-specific Thermal class""" @@ -84,7 +84,7 @@ def __get_temp(self, temp_file): temp_file_path = os.path.join(hwmon_path, temp_file) raw_temp = self._api_helper.read_txt_file(temp_file_path) temp = float(raw_temp)/1000 - return "{:.3f}".format(temp) + return float("{:.3f}".format(temp)) except: continue return DEFAULT_VAL