Skip to content

Commit c9559ed

Browse files
author
Wirut Getbamrung
authored
Merge pull request sonic-net#191 from mudsut4ke/201911_cel_wb_fix_reboot_cause
[device/celestica]: update api and fixes bug
2 parents ee9640e + d4b9a14 commit c9559ed

File tree

4 files changed

+28
-45
lines changed

4 files changed

+28
-45
lines changed

device/celestica/x86_64-cel_questone2bd-r0/sonic_platform/chassis.py

+13-28
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,6 @@
3535
REBOOT_CAUSE_REG = "0xA106"
3636
TLV_EEPROM_I2C_BUS = 0
3737
TLV_EEPROM_I2C_ADDR = 56
38-
3938
BASE_CPLD_PLATFORM = "questone2bd.cpldb"
4039
BASE_GETREG_PATH = "/sys/devices/platform/{}/getreg".format(BASE_CPLD_PLATFORM)
4140

@@ -52,12 +51,12 @@ def __init__(self):
5251
ChassisBase.__init__(self)
5352
self._api_helper = APIHelper()
5453
self.sfp_module_initialized = False
54+
self.__initialize_eeprom()
5555
self.POLL_INTERVAL = 1
5656

5757
if not self._api_helper.is_host():
5858
self.__initialize_fan()
5959
self.__initialize_psu()
60-
self.__initialize_eeprom()
6160
self.__initialize_thermals()
6261
self.__initialize_interrupts()
6362
else:
@@ -176,33 +175,19 @@ def get_reboot_cause(self):
176175
is "REBOOT_CAUSE_HARDWARE_OTHER", the second string can be used
177176
to pass a description of the reboot cause.
178177
"""
179-
180-
raw_cause = self._api_helper.get_register_value(
178+
hx_cause = self._api_helper.get_register_value(
181179
BASE_GETREG_PATH, REBOOT_CAUSE_REG)
182-
hx_cause = raw_cause.lower()
183-
reboot_cause = {
184-
"0x00": self.REBOOT_CAUSE_HARDWARE_OTHER,
185-
"0x11": self.REBOOT_CAUSE_POWER_LOSS,
186-
"0x22": self.REBOOT_CAUSE_NON_HARDWARE,
187-
"0x33": self.REBOOT_CAUSE_HARDWARE_OTHER,
188-
"0x44": self.REBOOT_CAUSE_NON_HARDWARE,
189-
"0x55": self.REBOOT_CAUSE_NON_HARDWARE,
190-
"0x66": self.REBOOT_CAUSE_WATCHDOG,
191-
"0x77": self.REBOOT_CAUSE_NON_HARDWARE
192-
}.get(hx_cause, self.REBOOT_CAUSE_HARDWARE_OTHER)
193-
194-
description = {
195-
"0x00": "Unknown reason",
196-
"0x11": "The last reset is Power on reset",
197-
"0x22": "The last reset is soft-set CPU warm reset",
198-
"0x33": "The last reset is soft-set CPU cold reset",
199-
"0x44": "The last reset is CPU warm reset",
200-
"0x55": "The last reset is CPU cold reset",
201-
"0x66": "The last reset is watchdog reset",
202-
"0x77": "The last reset is power cycle reset"
203-
}.get(hx_cause, "Unknown reason")
204-
205-
return (reboot_cause, description)
180+
181+
return {
182+
"0x00": (self.REBOOT_CAUSE_HARDWARE_OTHER, 'Unknown'),
183+
"0x11": (self.REBOOT_CAUSE_POWER_LOSS, 'The last reset is Power on reset'),
184+
"0x22": (self.REBOOT_CAUSE_HARDWARE_OTHER, 'The last reset is soft-set CPU warm reset'),
185+
"0x33": (self.REBOOT_CAUSE_HARDWARE_OTHER, 'The last reset is soft-set CPU cold reset'),
186+
"0x44": (self.REBOOT_CAUSE_HARDWARE_OTHER, 'The last reset is CPU warm reset'),
187+
"0x55": (self.REBOOT_CAUSE_HARDWARE_OTHER, 'The last reset is CPU cold reset'),
188+
"0x66": (self.REBOOT_CAUSE_WATCHDOG, 'The last reset is watchdog reset'),
189+
"0x77": (self.REBOOT_CAUSE_HARDWARE_OTHER, 'The last reset is power cycle reset'),
190+
}.get(hx_cause.lower(), (self.REBOOT_CAUSE_HARDWARE_OTHER, 'Unknown'))
206191

207192
##############################################################
208193
######################## SFP methods #########################

device/celestica/x86_64-cel_questone2bd-r0/sonic_platform/fan.py

+3-4
Original file line numberDiff line numberDiff line change
@@ -54,21 +54,20 @@
5454

5555
FAN_MUX_HWMON_PATH = "/sys/bus/i2c/devices/i2c-66/i2c-{0}/{0}-0050/"
5656
PSU_MUX_HWMON_PATH = "/sys/bus/i2c/devices/i2c-68/i2c-{0}/{0}-0050/"
57-
57+
NULL_VAL = 'N/A'
5858

5959
class Fan(FanBase):
6060
"""Platform-specific Fan class"""
6161

62-
def __init__(self, fan_tray_index, fan_index=0, is_psu_fan=False, psu_index=0, psu_fan_direction=0):
62+
def __init__(self, fan_tray_index, fan_index=0, is_psu_fan=False, psu_index=0, psu_fan_direction=NULL_VAL):
6363
self.fan_index = fan_index
6464
self.fan_tray_index = fan_tray_index
6565
self.is_psu_fan = is_psu_fan
6666
if self.is_psu_fan:
6767
self.psu_index = psu_index
6868
self.psu_hwmon_path = PSU_HWMON_PATH.format(
6969
PSU_I2C_MAPPING[self.psu_index]["i2c_num"], PSU_I2C_MAPPING[self.psu_index]["pmbus_reg"])
70-
self.psu_fan_direction = self.FAN_DIRECTION_EXHAUST if psu_fan_direction else self.FAN_DIRECTION_INTAKE
71-
self._api_helper = APIHelper()
70+
self.psu_fan_direction = psu_fan_direction
7271
self.index = self.fan_tray_index * 2 + self.fan_index
7372

7473
def __read_fan_sysfs(self, sysfs_file):

device/celestica/x86_64-cel_questone2bd-r0/sonic_platform/helper.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@ def ipmi_set_ss_thres(self, id, threshold_key, value):
151151

152152
def fru_decode_product_serial(self, data):
153153

154-
if data[4] != 00:
154+
if data and data[4] != 00:
155155
start_product_info = ord(data[4]) * 8
156156
start_format_version = start_product_info
157157
start_product_info = start_format_version + 1
@@ -171,7 +171,7 @@ def fru_decode_product_serial(self, data):
171171

172172
def fru_decode_product_model(self, data):
173173

174-
if data[4] != 00:
174+
if data and data[4] != 00:
175175
start_product_info = ord(data[4]) * 8
176176
start_format_version = start_product_info
177177
start_product_info = start_format_version + 1
@@ -192,7 +192,7 @@ def fru_decode_product_model(self, data):
192192

193193
def fru_decode_product_name(self, data):
194194

195-
if data[4] != 00:
195+
if data and data[4] != 00:
196196
start_product_info = ord(data[4]) * 8
197197
start_format_version = start_product_info
198198
start_product_info = start_format_version + 1

device/celestica/x86_64-cel_questone2bd-r0/sonic_platform/psu.py

+9-10
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@
4343
}
4444
PSU_STATUS_REGISTER = "0xA160"
4545
HWMON_PATH = "/sys/bus/i2c/devices/i2c-{0}/{0}-00{1}/hwmon"
46+
I2C_PATH = "/sys/bus/i2c/devices/i2c-{0}/{0}-00{1}/"
4647
PSU_POWER_DIVIDER = 1000000
4748
PSU_VOLT_DIVIDER = 1000
4849
PSU_CUR_DIVIDER = 1000
@@ -60,6 +61,8 @@ def __init__(self, psu_index):
6061
self.index = psu_index
6162
self.hwmon_path = HWMON_PATH.format(
6263
PSU_INFO_MAPPING[self.index]["i2c_num"], PSU_INFO_MAPPING[self.index]["pmbus_reg"])
64+
self.eeprom_path = I2C_PATH.format(
65+
PSU_INFO_MAPPING[self.index]["i2c_num"], PSU_INFO_MAPPING[self.index]["eeprom_reg"])
6366
self._api_helper = APIHelper()
6467
for fan_index in range(0, PSU_NUM_FAN[self.index]):
6568
fan = Fan(fan_index, 0, is_psu_fan=True, psu_index=self.index,
@@ -69,11 +72,11 @@ def __init__(self, psu_index):
6972
def __get_fan_direction(self):
7073
# DPS-1100FB = Intake
7174
# DPS-1100AB = exhaust
72-
eeprom_path = PSU_MUX_HWMON_PATH.format(
73-
((self.index) + 75), self.index+50)
7475
fru_pn = self._api_helper.fru_decode_product_name(
75-
self._api_helper.read_eeprom_sysfs(eeprom_path, "eeprom"))
76-
return 0 if "FB" in fru_pn else 1
76+
self._api_helper.read_eeprom_sysfs(self.eeprom_path, "eeprom"))
77+
return Fan.FAN_DIRECTION_INTAKE if "FB" in fru_pn \
78+
else Fan.FAN_DIRECTION_EXHAUST if "AB" in fru_pn \
79+
else Fan.FAN_DIRECTION_NOT_APPLICABLE
7780

7881
def __search_file_by_contain(self, directory, search_str, file_start):
7982
for dirpath, dirnames, files in os.walk(directory):
@@ -218,19 +221,15 @@ def get_model(self):
218221
Returns:
219222
string: Model/part number of device
220223
"""
221-
eeprom_path = PSU_MUX_HWMON_PATH.format(
222-
((self.index) + 75), self.index+50)
223-
return self._api_helper.fru_decode_product_model(self._api_helper.read_eeprom_sysfs(eeprom_path, "eeprom"))
224+
return self._api_helper.fru_decode_product_model(self._api_helper.read_eeprom_sysfs(self.eeprom_path, "eeprom"))
224225

225226
def get_serial(self):
226227
"""
227228
Retrieves the serial number of the device
228229
Returns:
229230
string: Serial number of device
230231
"""
231-
eeprom_path = PSU_MUX_HWMON_PATH.format(
232-
((self.index) + 75), self.index+50)
233-
return self._api_helper.fru_decode_product_serial(self._api_helper.read_eeprom_sysfs(eeprom_path, "eeprom"))
232+
return self._api_helper.fru_decode_product_serial(self._api_helper.read_eeprom_sysfs(self.eeprom_path, "eeprom"))
234233

235234
def get_status(self):
236235
"""

0 commit comments

Comments
 (0)