Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[device/celestica]: update api and fixes bug #191

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand All @@ -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:
Expand Down Expand Up @@ -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 #########################
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,21 +54,20 @@

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
if self.is_psu_fan:
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):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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
Expand Down
19 changes: 9 additions & 10 deletions device/celestica/x86_64-cel_questone2bd-r0/sonic_platform/psu.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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,
Expand All @@ -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):
Expand Down Expand Up @@ -218,19 +221,15 @@ 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):
"""
Retrieves the serial number of the device
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):
"""
Expand Down