[device/celestica]: Implement thermal base API based on the new platform API (#3220)

This commit is contained in:
Wirut Getbamrung 2019-08-05 23:01:51 +07:00 committed by Joe LeVeque
parent 7e98e3f461
commit 1dd2688844
7 changed files with 362 additions and 22 deletions

View File

@ -5,21 +5,28 @@
bus "i2c-3" "i2c-0-mux (chan_id 1)"
bus "i2c-11" "i2c-8-mux (chan_id 1)"
chip "max6697-i2c-3-1a"
label temp1 "CPU board temperature sensor : 1"
label temp2 "CPU board temperature sensor : 2"
label temp3 "CPU board temperature sensor : 3"
chip "max6699-i2c-3-1a"
label temp2 "CPU board temperature sensor : 1"
label temp3 "CPU board temperature sensor : 2"
set temp2_max 90
set temp3_max 90
ignore temp1
ignore temp4
ignore temp5
ignore temp6
ignore temp7
chip "max6697-i2c-11-1a"
label temp1 "Main board temperature sensor : 1"
label temp2 "Main board temperature sensor : 2"
label temp3 "Main board temperature sensor : 3"
label temp4 "Main board temperature sensor : 4"
label temp5 "Main board temperature sensor : 5"
chip "max6699-i2c-11-1a"
label temp1 "Rear panel-Inlet ambient sensor"
label temp2 "Rear panel-Helix shutdown sensor"
label temp3 "Front panel-Inlet ambient sensor (right)"
label temp4 "Front panel-Helix shutdown sensor"
label temp5 "Front panel-Inlet ambient sensor (left)"
set temp1_max 55
set temp2_max 85
set temp3_max 55
set temp4_max 85
set temp5_max 55
ignore temp6
ignore temp7

View File

@ -20,11 +20,13 @@ try:
from sonic_platform.psu import Psu
from sonic_platform.component import Component
from sonic_platform.watchdog import Watchdog
from sonic_platform.thermal import Thermal
except ImportError as e:
raise ImportError(str(e) + "- required module not found")
NUM_FAN = 3
NUM_PSU = 2
NUM_THERMAL = 7
CONFIG_DB_PATH = "/etc/sonic/config_db.json"
RESET_REGISTER = "0x112"
REBOOT_CAUSE_PATH = "/host/reboot-cause/previous-reboot-cause.txt"
@ -42,6 +44,9 @@ class Chassis(ChassisBase):
for index in range(0, NUM_PSU):
psu = Psu(index)
self._psu_list.append(psu)
for index in range(0, NUM_THERMAL):
thermal = Thermal(index)
self._thermal_list.append(thermal)
ChassisBase.__init__(self)
self._component_name_list = COMPONENT_NAME_LIST
self._watchdog = Watchdog()
@ -125,6 +130,7 @@ class Chassis(ChassisBase):
if sw_reboot_cause != "Unexpected reboot":
reboot_cause = self.REBOOT_CAUSE_NON_HARDWARE
description = sw_reboot_cause
elif hw_reboot_cause == "0x11":
reboot_cause = self.REBOOT_CAUSE_POWER_LOSS
elif hw_reboot_cause == "0x33" or hw_reboot_cause == "0x55":

View File

@ -0,0 +1,166 @@
#!/usr/bin/env python
#############################################################################
# Celestica
#
# Thermal contains an implementation of SONiC Platform Base API and
# provides the thermal device status which are available in the platform
#
#############################################################################
import os
import re
import os.path
try:
from sonic_platform_base.thermal_base import ThermalBase
except ImportError as e:
raise ImportError(str(e) + "- required module not found")
class Thermal(ThermalBase):
"""Platform-specific Thermal class"""
THERMAL_NAME_LIST = []
MAINBOARD_SS_PATH = "/sys/class/i2c-adapter/i2c-11/11-001a/hwmon/"
CPUBOARD_SS_PATH = "/sys/class/i2c-adapter/i2c-3/3-001a/hwmon/"
SS_CONFIG_PATH = "/usr/share/sonic/device/x86_64-cel_e1031-r0/sensors.conf"
def __init__(self, thermal_index):
self.index = thermal_index
# Add thermal name
self.THERMAL_NAME_LIST.append("Rear panel-Inlet ambient sensor")
self.THERMAL_NAME_LIST.append("Rear panel-Helix shutdown sensor")
self.THERMAL_NAME_LIST.append(
"Front panel-Inlet ambient sensor (right)")
self.THERMAL_NAME_LIST.append("Front panel-Helix shutdown sensor")
self.THERMAL_NAME_LIST.append(
"Front panel-Inlet ambient sensor (left)")
self.THERMAL_NAME_LIST.append("CPU board temperature sensor : 1")
self.THERMAL_NAME_LIST.append("CPU board temperature sensor : 2")
# Set hwmon path
self.ss_index, self.ss_path = self.__get_ss_info(self.index)
self.ss_key = self.THERMAL_NAME_LIST[self.index]
self.hwmon_name = os.listdir(self.ss_path)[0]
self.hwmon_path = os.path.join(self.ss_path, self.hwmon_name)
def __get_ss_info(self, index):
if self.index <= 4:
ss_path = self.MAINBOARD_SS_PATH
ss_index = index+1
else:
ss_path = self.CPUBOARD_SS_PATH
ss_index = index-3
return ss_index, ss_path
def __read_txt_file(self, file_path):
try:
with open(file_path, 'r') as fd:
data = fd.read()
return data.strip()
except IOError:
raise IOError("Unable to open %s file !" % file_path)
def __get_temp(self, temp_file):
temp_file_path = os.path.join(self.hwmon_path, temp_file)
raw_temp = self.__read_txt_file(temp_file_path)
temp = float(raw_temp)/1000
return "{:.3f}".format(temp)
def __set_threshold(self, file_name, temperature):
temp_file_path = os.path.join(self.hwmon_path, file_name)
try:
with open(temp_file_path, 'w') as fd:
fd.write(str(temperature))
return True
except IOError:
return False
def get_temperature(self):
"""
Retrieves current temperature reading from thermal
Returns:
A float number of current temperature in Celsius up to nearest thousandth
of one degree Celsius, e.g. 30.125
"""
temp_file = "temp{}_input".format(self.ss_index)
return self.__get_temp(temp_file)
def get_high_threshold(self):
"""
Retrieves the high threshold temperature of thermal
Returns:
A float number, the high threshold temperature of thermal in Celsius
up to nearest thousandth of one degree Celsius, e.g. 30.125
"""
temp_file = "temp{}_max".format(self.ss_index)
return self.__get_temp(temp_file)
def set_high_threshold(self, temperature):
"""
Sets the high threshold temperature of thermal
Args :
temperature: A float number up to nearest thousandth of one degree Celsius,
e.g. 30.125
Returns:
A boolean, True if threshold is set successfully, False if not
"""
temp_file = "temp{}_max".format(self.ss_index)
is_set = self.__set_threshold(temp_file, int(temperature*1000))
file_set = False
if is_set:
try:
with open(self.SS_CONFIG_PATH, 'r+') as f:
content = f.readlines()
f.seek(0)
ss_found = False
for idx, val in enumerate(content):
if self.ss_key in val:
ss_found = True
elif ss_found and temp_file in val:
content[idx] = " set {} {}\n".format(
temp_file, temperature)
f.writelines(content)
file_set = True
break
except IOError:
file_set = False
return is_set & file_set
def get_name(self):
"""
Retrieves the name of the thermal device
Returns:
string: The name of the thermal device
"""
return self.THERMAL_NAME_LIST[self.index]
def get_presence(self):
"""
Retrieves the presence of the PSU
Returns:
bool: True if PSU is present, False if not
"""
temp_file = "temp{}_input".format(self.ss_index)
temp_file_path = os.path.join(self.hwmon_path, temp_file)
return os.path.isfile(temp_file_path)
def get_status(self):
"""
Retrieves the operational status of the device
Returns:
A boolean value, True if device is operating properly, False if not
"""
if not self.get_presence():
return False
fault_file = "temp{}_fault".format(self.ss_index)
fault_file_path = os.path.join(self.hwmon_path, fault_file)
if not os.path.isfile(fault_file_path):
return True
raw_txt = self.__read_txt_file(fault_file_path)
return int(raw_txt) == 0

View File

@ -39,29 +39,24 @@ chip "dps460-i2c-*-5b"
# These sensors located on Main Switch Board.
chip "lm75b-i2c-*-48"
label temp1 "Front-panel temp sensor 1"
set temp1_max 43
set temp1_max_hyst 28
set temp1_max 50
chip "lm75b-i2c-*-49"
label temp1 "Front-panel temp sensor 2"
set temp1_max 43
set temp1_max_hyst 28
set temp1_max 50
chip "lm75b-i2c-*-4a"
label temp1 "ASIC temp sensor"
set temp1_max 43
set temp1_max_hyst 28
set temp1_max 70
# These sensors located on CPU Board.
chip "lm75b-i2c-*-48"
label temp1 "Rear-panel temp sensor 1"
set temp1_max 43
set temp1_max_hyst 28
set temp1_max 70
chip "lm75b-i2c-*-4e"
label temp1 "Rear-panel temp sensor 2"
set temp1_max 43
set temp1_max_hyst 28
set temp1_max 70
chip "emc2305-i2c-*-2e"
label fan2 "fan1"

View File

@ -20,12 +20,14 @@ try:
from sonic_platform.psu import Psu
from sonic_platform.component import Component
from sonic_platform.watchdog import Watchdog
from sonic_platform.thermal import Thermal
except ImportError as e:
raise ImportError(str(e) + "- required module not found")
CONFIG_DB_PATH = "/etc/sonic/config_db.json"
NUM_FAN = 5
NUM_PSU = 2
NUM_THERMAL = 5
RESET_REGISTER = "0x103"
REBOOT_CAUSE_PATH = "/host/reboot-cause/previous-reboot-cause.txt"
COMPONENT_NAME_LIST = ["CPLD1", "CPLD2", "CPLD3", "CPLD4", "BIOS"]
@ -42,6 +44,9 @@ class Chassis(ChassisBase):
for index in range(0, NUM_PSU):
psu = Psu(index)
self._psu_list.append(psu)
for index in range(0, NUM_THERMAL):
thermal = Thermal(index)
self._thermal_list.append(thermal)
ChassisBase.__init__(self)
self._component_name_list = COMPONENT_NAME_LIST
self._watchdog = Watchdog()

View File

@ -0,0 +1,161 @@
#!/usr/bin/env python
#############################################################################
# Celestica
#
# Thermal contains an implementation of SONiC Platform Base API and
# provides the thermal device status which are available in the platform
#
#############################################################################
import os
import re
import os.path
try:
from sonic_platform_base.thermal_base import ThermalBase
except ImportError as e:
raise ImportError(str(e) + "- required module not found")
class Thermal(ThermalBase):
"""Platform-specific Thermal class"""
THERMAL_NAME_LIST = []
I2C_ADAPTER_PATH = "/sys/class/i2c-adapter"
SS_CONFIG_PATH = "/usr/share/sonic/device/x86_64-cel_seastone-r0/sensors.conf"
def __init__(self, thermal_index):
self.index = thermal_index
# Add thermal name
self.THERMAL_NAME_LIST.append("Front-panel temp sensor 1")
self.THERMAL_NAME_LIST.append("Front-panel temp sensor 2")
self.THERMAL_NAME_LIST.append("ASIC temp sensor")
self.THERMAL_NAME_LIST.append("Rear-panel temp sensor 1")
self.THERMAL_NAME_LIST.append("Rear-panel temp sensor 2")
# Set hwmon path
i2c_path = {
0: "i2c-5/5-0048", # u4 system-inlet
1: "i2c-6/6-0049", # u2 system-inlet
2: "i2c-7/7-004a", # u44 bmc56960-on-board
3: "i2c-14/14-0048", # u9200 cpu-on-board
4: "i2c-15/15-004e" # u9201 system-outlet
}.get(self.index, None)
self.ss_path = "{}/{}/hwmon".format(self.I2C_ADAPTER_PATH, i2c_path)
self.ss_key = self.THERMAL_NAME_LIST[self.index]
self.ss_index = 1
self.hwmon_name = os.listdir(self.ss_path)[0]
self.hwmon_path = os.path.join(self.ss_path, self.hwmon_name)
def __read_txt_file(self, file_path):
try:
with open(file_path, 'r') as fd:
data = fd.read()
return data.strip()
except IOError:
raise IOError("Unable to open %s file !" % file_path)
def __get_temp(self, temp_file):
temp_file_path = os.path.join(self.hwmon_path, temp_file)
raw_temp = self.__read_txt_file(temp_file_path)
temp = float(raw_temp)/1000
return "{:.3f}".format(temp)
def __set_threshold(self, file_name, temperature):
temp_file_path = os.path.join(self.hwmon_path, file_name)
try:
with open(temp_file_path, 'w') as fd:
fd.write(str(temperature))
return True
except IOError:
return False
def get_temperature(self):
"""
Retrieves current temperature reading from thermal
Returns:
A float number of current temperature in Celsius up to nearest thousandth
of one degree Celsius, e.g. 30.125
"""
temp_file = "temp{}_input".format(self.ss_index)
return self.__get_temp(temp_file)
def get_high_threshold(self):
"""
Retrieves the high threshold temperature of thermal
Returns:
A float number, the high threshold temperature of thermal in Celsius
up to nearest thousandth of one degree Celsius, e.g. 30.125
"""
temp_file = "temp{}_max".format(self.ss_index)
return self.__get_temp(temp_file)
def set_high_threshold(self, temperature):
"""
Sets the high threshold temperature of thermal
Args :
temperature: A float number up to nearest thousandth of one degree Celsius,
e.g. 30.125
Returns:
A boolean, True if threshold is set successfully, False if not
"""
temp_file = "temp{}_max".format(self.ss_index)
is_set = self.__set_threshold(temp_file, int(temperature*1000))
file_set = False
if is_set:
try:
with open(self.SS_CONFIG_PATH, 'r+') as f:
content = f.readlines()
f.seek(0)
ss_found = False
for idx, val in enumerate(content):
if self.ss_key in val:
ss_found = True
elif ss_found and temp_file in val:
content[idx] = " set {} {}\n".format(
temp_file, temperature)
f.writelines(content)
file_set = True
break
except IOError:
file_set = False
return is_set & file_set
def get_name(self):
"""
Retrieves the name of the thermal device
Returns:
string: The name of the thermal device
"""
return self.THERMAL_NAME_LIST[self.index]
def get_presence(self):
"""
Retrieves the presence of the PSU
Returns:
bool: True if PSU is present, False if not
"""
temp_file = "temp{}_input".format(self.ss_index)
temp_file_path = os.path.join(self.hwmon_path, temp_file)
return os.path.isfile(temp_file_path)
def get_status(self):
"""
Retrieves the operational status of the device
Returns:
A boolean value, True if device is operating properly, False if not
"""
if not self.get_presence():
return False
fault_file = "temp{}_fault".format(self.ss_index)
fault_file_path = os.path.join(self.hwmon_path, fault_file)
if not os.path.isfile(fault_file_path):
return True
raw_txt = self.__read_txt_file(fault_file_path)
return int(raw_txt) == 0

View File

@ -49,8 +49,8 @@ start)
# Attach syseeprom
echo 24lc64t 0x50 > /sys/bus/i2c/devices/i2c-2/new_device
echo max6697 0x1a > /sys/bus/i2c/devices/i2c-3/new_device
echo max6697 0x1a > /sys/bus/i2c/devices/i2c-11/new_device
echo max6699 0x1a > /sys/bus/i2c/devices/i2c-3/new_device
echo max6699 0x1a > /sys/bus/i2c/devices/i2c-11/new_device
# Attach PSUs
echo dps200 0x5a > /sys/bus/i2c/devices/i2c-12/new_device