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 9729aeed8073..da4521e88136 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 @@ -35,7 +35,6 @@ REBOOT_CAUSE_REG = "0xA106" TLV_EEPROM_I2C_BUS = 0 TLV_EEPROM_I2C_ADDR = 56 - BASE_CPLD_PLATFORM = "questone2bd.cpldb" BASE_GETREG_PATH = "/sys/devices/platform/{}/getreg".format(BASE_CPLD_PLATFORM) @@ -52,12 +51,12 @@ def __init__(self): ChassisBase.__init__(self) self._api_helper = APIHelper() self.sfp_module_initialized = False + self.__initialize_eeprom() self.POLL_INTERVAL = 1 if not self._api_helper.is_host(): self.__initialize_fan() self.__initialize_psu() - self.__initialize_eeprom() self.__initialize_thermals() self.__initialize_interrupts() else: @@ -176,33 +175,19 @@ def get_reboot_cause(self): is "REBOOT_CAUSE_HARDWARE_OTHER", the second string can be used to pass a description of the reboot cause. """ - - raw_cause = self._api_helper.get_register_value( + hx_cause = self._api_helper.get_register_value( BASE_GETREG_PATH, REBOOT_CAUSE_REG) - hx_cause = raw_cause.lower() - reboot_cause = { - "0x00": self.REBOOT_CAUSE_HARDWARE_OTHER, - "0x11": self.REBOOT_CAUSE_POWER_LOSS, - "0x22": self.REBOOT_CAUSE_NON_HARDWARE, - "0x33": self.REBOOT_CAUSE_HARDWARE_OTHER, - "0x44": self.REBOOT_CAUSE_NON_HARDWARE, - "0x55": self.REBOOT_CAUSE_NON_HARDWARE, - "0x66": self.REBOOT_CAUSE_WATCHDOG, - "0x77": self.REBOOT_CAUSE_NON_HARDWARE - }.get(hx_cause, self.REBOOT_CAUSE_HARDWARE_OTHER) - - description = { - "0x00": "Unknown reason", - "0x11": "The last reset is Power on reset", - "0x22": "The last reset is soft-set CPU warm reset", - "0x33": "The last reset is soft-set CPU cold reset", - "0x44": "The last reset is CPU warm reset", - "0x55": "The last reset is CPU cold reset", - "0x66": "The last reset is watchdog reset", - "0x77": "The last reset is power cycle reset" - }.get(hx_cause, "Unknown reason") - - return (reboot_cause, description) + + return { + "0x00": (self.REBOOT_CAUSE_HARDWARE_OTHER, 'Unknown'), + "0x11": (self.REBOOT_CAUSE_POWER_LOSS, 'The last reset is Power on reset'), + "0x22": (self.REBOOT_CAUSE_HARDWARE_OTHER, 'The last reset is soft-set CPU warm reset'), + "0x33": (self.REBOOT_CAUSE_HARDWARE_OTHER, 'The last reset is soft-set CPU cold reset'), + "0x44": (self.REBOOT_CAUSE_HARDWARE_OTHER, 'The last reset is CPU warm reset'), + "0x55": (self.REBOOT_CAUSE_HARDWARE_OTHER, 'The last reset is CPU cold reset'), + "0x66": (self.REBOOT_CAUSE_WATCHDOG, 'The last reset is watchdog reset'), + "0x77": (self.REBOOT_CAUSE_HARDWARE_OTHER, 'The last reset is power cycle reset'), + }.get(hx_cause.lower(), (self.REBOOT_CAUSE_HARDWARE_OTHER, 'Unknown')) ############################################################## ######################## SFP methods ######################### 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 7d4e1647ab95..1f3478086ba3 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 @@ -54,12 +54,12 @@ FAN_MUX_HWMON_PATH = "/sys/bus/i2c/devices/i2c-66/i2c-{0}/{0}-0050/" PSU_MUX_HWMON_PATH = "/sys/bus/i2c/devices/i2c-68/i2c-{0}/{0}-0050/" - +NULL_VAL = 'N/A' class Fan(FanBase): """Platform-specific Fan class""" - def __init__(self, fan_tray_index, fan_index=0, is_psu_fan=False, psu_index=0, psu_fan_direction=0): + def __init__(self, fan_tray_index, fan_index=0, is_psu_fan=False, psu_index=0, psu_fan_direction=NULL_VAL): self.fan_index = fan_index self.fan_tray_index = fan_tray_index self.is_psu_fan = is_psu_fan @@ -67,8 +67,7 @@ def __init__(self, fan_tray_index, fan_index=0, is_psu_fan=False, psu_index=0, p 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.psu_fan_direction = psu_fan_direction self.index = self.fan_tray_index * 2 + self.fan_index def __read_fan_sysfs(self, sysfs_file): 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 0645a2962b79..856f4adf6757 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 @@ -151,7 +151,7 @@ def ipmi_set_ss_thres(self, id, threshold_key, value): def fru_decode_product_serial(self, data): - if data[4] != 00: + if data and data[4] != 00: start_product_info = ord(data[4]) * 8 start_format_version = start_product_info start_product_info = start_format_version + 1 @@ -171,7 +171,7 @@ def fru_decode_product_serial(self, data): def fru_decode_product_model(self, data): - if data[4] != 00: + if data and data[4] != 00: start_product_info = ord(data[4]) * 8 start_format_version = start_product_info start_product_info = start_format_version + 1 @@ -192,7 +192,7 @@ def fru_decode_product_model(self, data): def fru_decode_product_name(self, data): - if data[4] != 00: + if data and data[4] != 00: start_product_info = ord(data[4]) * 8 start_format_version = start_product_info start_product_info = start_format_version + 1 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 23c5f514a795..7cf683eb1b37 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 @@ -43,6 +43,7 @@ } PSU_STATUS_REGISTER = "0xA160" HWMON_PATH = "/sys/bus/i2c/devices/i2c-{0}/{0}-00{1}/hwmon" +I2C_PATH = "/sys/bus/i2c/devices/i2c-{0}/{0}-00{1}/" PSU_POWER_DIVIDER = 1000000 PSU_VOLT_DIVIDER = 1000 PSU_CUR_DIVIDER = 1000 @@ -60,6 +61,8 @@ def __init__(self, psu_index): self.index = psu_index self.hwmon_path = HWMON_PATH.format( PSU_INFO_MAPPING[self.index]["i2c_num"], PSU_INFO_MAPPING[self.index]["pmbus_reg"]) + self.eeprom_path = I2C_PATH.format( + PSU_INFO_MAPPING[self.index]["i2c_num"], PSU_INFO_MAPPING[self.index]["eeprom_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, @@ -69,11 +72,11 @@ def __init__(self, psu_index): 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 + self._api_helper.read_eeprom_sysfs(self.eeprom_path, "eeprom")) + return Fan.FAN_DIRECTION_INTAKE if "FB" in fru_pn \ + else Fan.FAN_DIRECTION_EXHAUST if "AB" in fru_pn \ + else Fan.FAN_DIRECTION_NOT_APPLICABLE def __search_file_by_contain(self, directory, search_str, file_start): for dirpath, dirnames, files in os.walk(directory): @@ -218,9 +221,7 @@ def get_model(self): Returns: string: Model/part number of device """ - 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(eeprom_path, "eeprom")) + return self._api_helper.fru_decode_product_model(self._api_helper.read_eeprom_sysfs(self.eeprom_path, "eeprom")) def get_serial(self): """ @@ -228,9 +229,7 @@ def get_serial(self): Returns: string: Serial number of device """ - 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(eeprom_path, "eeprom")) + return self._api_helper.fru_decode_product_serial(self._api_helper.read_eeprom_sysfs(self.eeprom_path, "eeprom")) def get_status(self): """