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]: Fix thermalctld issue #168

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 @@ -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
Expand Down Expand Up @@ -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
Expand Down
30 changes: 15 additions & 15 deletions device/celestica/x86_64-cel_questone2bd-r0/sonic_platform/fan.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -56,14 +59,15 @@
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
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.index = self.fan_tray_index * 2 + self.fan_index

Expand Down Expand Up @@ -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))
Expand All @@ -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"
Expand All @@ -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

Expand All @@ -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):
"""
Expand Down Expand Up @@ -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"))
Expand All @@ -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"))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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)
Expand All @@ -197,4 +213,4 @@ def read_eeprom_sysfs(self,sys_path,sysfs_file):
return data
except:
pass
return False
return None
24 changes: 17 additions & 7 deletions device/celestica/x86_64-cel_questone2bd-r0/sonic_platform/psu.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -208,19 +218,19 @@ 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):
"""
Retrieves the serial number of the device
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):
"""
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"""
Expand Down Expand Up @@ -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
Expand Down