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]: Implement device base APIs for Fan/PSU API based on the new platform API #3163

Merged
merged 3 commits into from
Jul 23, 2019
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 @@ -18,17 +18,17 @@
from sonic_platform_base.chassis_base import ChassisBase
from sonic_platform.fan import Fan
from sonic_platform.psu import Psu
from sonic_platform.device import Device
from sonic_platform.component import Component
from sonic_platform.watchdog import Watchdog
except ImportError as e:
raise ImportError(str(e) + "- required module not found")

CONFIG_DB_PATH = "/etc/sonic/config_db.json"
NUM_FAN = 3
NUM_PSU = 2
CONFIG_DB_PATH = "/etc/sonic/config_db.json"
RESET_REGISTER = "0x112"
REBOOT_CAUSE_PATH = "/host/reboot-cause/previous-reboot-cause.txt"
COMPONENT_NAME_LIST = ["SMC_CPLD", "MMC_CPLD", "BIOS"]


class Chassis(ChassisBase):
Expand All @@ -43,8 +43,7 @@ def __init__(self):
psu = Psu(index)
self._psu_list.append(psu)
ChassisBase.__init__(self)
self._component_device = Device("component")
self._component_name_list = self._component_device.get_name_list()
self._component_name_list = COMPONENT_NAME_LIST
self._watchdog = Watchdog()

def __read_config_db(self):
Expand Down
47 changes: 0 additions & 47 deletions device/celestica/x86_64-cel_e1031-r0/sonic_platform/device.py

This file was deleted.

29 changes: 27 additions & 2 deletions device/celestica/x86_64-cel_e1031-r0/sonic_platform/fan.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
EMC2305_FAN_PWM = "pwm{}"
EMC2305_FAN_TARGET = "fan{}_target"
EMC2305_FAN_INPUT = "pwm{}"
FAN_NAME_LIST = ["FAN-1", "FAN-2", "FAN-3"]


class Fan(FanBase):
Expand All @@ -43,8 +44,7 @@ def __init__(self, fan_index):
'index_map': [1, 2, 4]
}
]

# TODO: Add fan presence status in sysfs

self.fan_e1031_presence = "fan{}_prs"
self.fan_e1031_direction = "fan{}_dir"
self.fan_e1031_led = "fan{}_led"
Expand Down Expand Up @@ -181,3 +181,28 @@ def set_status_led(self, color):
return False

return True

def get_name(self):
"""
Retrieves the name of the device
Returns:
string: The name of the device
"""
return FAN_NAME_LIST[self.index]

def get_presence(self):
"""
Retrieves the presence of the PSU
Returns:
bool: True if PSU is present, False if not
"""

try:
fan_direction_file = (FAN_PATH +
self.fan_e1031_presence.format(self.index+1))
with open(fan_direction_file, 'r') as file:
present = int(file.read().strip('\r\n'))
except IOError:
return False

return present == 0
44 changes: 44 additions & 0 deletions device/celestica/x86_64-cel_e1031-r0/sonic_platform/psu.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@

FAN_E1031_SPEED_PATH = "/sys/class/hwmon/hwmon{}/fan1_input"
FAN_MAX_RPM = 11000
PSU_NAME_LIST = ["PSU-R", "PSU-L"]


class Psu(PsuBase):
Expand All @@ -27,6 +28,9 @@ class Psu(PsuBase):
def __init__(self, psu_index):
PsuBase.__init__(self)
self.index = psu_index
self.psu_path = "/sys/devices/platform/e1031.smc/"
self.psu_presence = "psu{}_prs"
self.psu_oper_status = "psu{}_status"

def get_fan(self):
"""
Expand Down Expand Up @@ -59,3 +63,43 @@ def set_status_led(self, color):
"""
# Hardware not supported
return False

def get_name(self):
"""
Retrieves the name of the device
Returns:
string: The name of the device
"""
return PSU_NAME_LIST[self.index]

def get_presence(self):
"""
Retrieves the presence of the PSU
Returns:
bool: True if PSU is present, False if not
"""
psu_location = ["R", "L"]
status = 0
try:
with open(self.psu_path + self.psu_presence.format(psu_location[self.index]), 'r') as psu_prs:
status = int(psu_prs.read())
except IOError:
return False

return status == 1

def get_status(self):
"""
Retrieves the operational status of the device
Returns:
A boolean value, True if device is operating properly, False if not
"""
psu_location = ["R", "L"]
status = 0
try:
with open(self.psu_path + self.psu_oper_status.format(psu_location[self.index]), 'r') as power_status:
status = int(power_status.read())
except IOError:
return False

return status == 1
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
from sonic_platform_base.chassis_base import ChassisBase
from sonic_platform.fan import Fan
from sonic_platform.psu import Psu
from sonic_platform.device import Device
from sonic_platform.component import Component
from sonic_platform.watchdog import Watchdog
except ImportError as e:
Expand All @@ -29,6 +28,7 @@
NUM_PSU = 2
RESET_REGISTER = "0x103"
REBOOT_CAUSE_PATH = "/host/reboot-cause/previous-reboot-cause.txt"
COMPONENT_NAME_LIST = ["CPLD1", "CPLD2", "CPLD3", "CPLD4", "BIOS"]


class Chassis(ChassisBase):
Expand All @@ -43,8 +43,7 @@ def __init__(self):
psu = Psu(index)
self._psu_list.append(psu)
ChassisBase.__init__(self)
self._component_device = Device("component")
self._component_name_list = self._component_device.get_name_list()
self._component_name_list = COMPONENT_NAME_LIST
self._watchdog = Watchdog()

def __read_config_db(self):
Expand Down
47 changes: 0 additions & 47 deletions device/celestica/x86_64-cel_seastone-r0/sonic_platform/device.py

This file was deleted.

19 changes: 19 additions & 0 deletions device/celestica/x86_64-cel_seastone-r0/sonic_platform/fan.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
EMC2305_FAN_PWM = "pwm{}"
EMC2305_FAN_TARGET = "fan{}_target"
EMC2305_FAN_INPUT = "pwm{}"
FAN_NAME_LIST = ["FAN-1", "FAN-2", "FAN-3", "FAN-4", "FAN-5"]


class Fan(FanBase):
Expand Down Expand Up @@ -226,3 +227,21 @@ def set_status_led(self, color):
return False

return True

def get_name(self):
"""
Retrieves the name of the device
Returns:
string: The name of the device
"""
return FAN_NAME_LIST[self.index]

def get_presence(self):
"""
Retrieves the presence of the PSU
Returns:
bool: True if PSU is present, False if not
"""
raw = self.get_gpio_value(self.dx010_fan_gpio[self.index+1]['prs'])

return int(raw, 10) == 0
53 changes: 53 additions & 0 deletions device/celestica/x86_64-cel_seastone-r0/sonic_platform/psu.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@
FAN_DX010_SPEED_PATH = "/sys/class/hwmon/hwmon{}/fan1_input"
GREEN_LED_PATH = "/sys/devices/platform/leds_dx010/leds/dx010:green:p-{}/brightness"
FAN_MAX_RPM = 11000
SYS_GPIO_DIR = "/sys/class/gpio"
PSU_NAME_LIST = ["PSU-1", "PSU-2"]


class Psu(PsuBase):
Expand All @@ -29,6 +31,31 @@ def __init__(self, psu_index):
PsuBase.__init__(self)
self.index = psu_index
self.green_led_path = GREEN_LED_PATH.format(self.index+1)
self.dx010_psu_gpio = [
{'base': self.get_gpio_base()},
{'prs': 27, 'status': 22},
{'prs': 28, 'status': 25}
]

def get_gpio_base(self):
for r in os.listdir(SYS_GPIO_DIR):
if "gpiochip" in r:
return int(r[8:], 10)
return 216 # Reserve

def get_gpio_value(self, pinnum):
gpio_base = self.dx010_psu_gpio[0]['base']
gpio_file = "{}/gpio{}/value".format(SYS_GPIO_DIR,
str(gpio_base+pinnum))

try:
with open(gpio_file, 'r') as fd:
retval = fd.read()
except IOError:
raise IOError("Unable to open " + gpio_file + "file !")

retval = retval.rstrip('\r\n')
return retval

def get_fan(self):
"""
Expand Down Expand Up @@ -76,3 +103,29 @@ def set_status_led(self, color):
return False

return True

def get_name(self):
"""
Retrieves the name of the device
Returns:
string: The name of the device
"""
return PSU_NAME_LIST[self.index]

def get_presence(self):
"""
Retrieves the presence of the PSU
Returns:
bool: True if PSU is present, False if not
"""
raw = self.get_gpio_value(self.dx010_psu_gpio[self.index+1]['prs'])
return int(raw, 10) == 0

def get_status(self):
"""
Retrieves the operational status of the device
Returns:
A boolean value, True if device is operating properly, False if not
"""
raw = self.get_gpio_value(self.dx010_psu_gpio[self.index+1]['status'])
return int(raw, 10) == 1
Loading