Skip to content

Commit

Permalink
DellEMC : Platform2.0 API Implementation for Component [S6000, S6100,…
Browse files Browse the repository at this point in the history
… Z9100] (#3588)
  • Loading branch information
ArunSaravananBalachandran authored and jleveque committed Oct 17, 2019
1 parent 2d87ca4 commit ee4ca2c
Show file tree
Hide file tree
Showing 7 changed files with 495 additions and 363 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,24 +18,15 @@
from sonic_platform.fan import Fan
from sonic_platform.psu import Psu
from sonic_platform.thermal import Thermal
from sonic_platform.component import Component
except ImportError as e:
raise ImportError(str(e) + "- required module not found")


MAX_S6000_FAN = 3
MAX_S6000_PSU = 2
MAX_S6000_THERMAL = 10

BIOS_QUERY_VERSION_COMMAND = "dmidecode -s system-version"
#components definitions
COMPONENT_BIOS = "BIOS"
COMPONENT_CPLD1 = "CPLD1"
COMPONENT_CPLD2 = "CPLD2"
COMPONENT_CPLD3 = "CPLD3"

CPLD1_VERSION = 'system_cpld_ver'
CPLD2_VERSION = 'master_cpld_ver'
CPLD3_VERSION = 'slave_cpld_ver'
MAX_S6000_COMPONENT = 4


class Chassis(ChassisBase):
Expand Down Expand Up @@ -87,11 +78,9 @@ def __init__(self):
thermal = Thermal(i)
self._thermal_list.append(thermal)

# Initialize component list
self._component_name_list.append(COMPONENT_BIOS)
self._component_name_list.append(COMPONENT_CPLD1)
self._component_name_list.append(COMPONENT_CPLD2)
self._component_name_list.append(COMPONENT_CPLD3)
for i in range(MAX_S6000_COMPONENT):
component = Component(i)
self._component_list.append(component)

def _get_cpld_register(self, reg_name):
rv = 'ERR'
Expand Down Expand Up @@ -178,7 +167,7 @@ def get_system_eeprom_info(self):
Returns:
A dictionary where keys are the type code defined in
OCP ONIE TlvInfo EEPROM format and values are their
OCP ONIE TlvInfo EEPROM format and values are their
corresponding values.
"""
return self.sys_eeprom.system_eeprom_info()
Expand All @@ -200,46 +189,6 @@ def get_reboot_cause(self):

return (ChassisBase.REBOOT_CAUSE_NON_HARDWARE, None)

def _get_command_result(self, cmdline):
try:
proc = subprocess.Popen(cmdline, stdout=subprocess.PIPE,
shell=True, stderr=subprocess.STDOUT)
stdout = proc.communicate()[0]
proc.wait()
result = stdout.rstrip('\n')
except OSError:
result = ''

return result

def _get_cpld_version(self,cpld_name):
"""
Cpld Version
"""
cpld_ver = int(self._get_cpld_register(cpld_name),16)
return cpld_ver

def get_firmware_version(self, component_name):
"""
Retrieves platform-specific hardware/firmware versions for
chassis componenets such as BIOS, CPLD, FPGA, etc.
Args:
component_name: A string, the component name.
Returns:
A string containing platform-specific component versions
"""
if component_name in self._component_name_list :
if component_name == COMPONENT_BIOS:
return self._get_command_result(BIOS_QUERY_VERSION_COMMAND)
elif component_name == COMPONENT_CPLD1:
return self._get_cpld_version(CPLD1_VERSION)
elif component_name == COMPONENT_CPLD2:
return self._get_cpld_version(CPLD2_VERSION)
elif component_name == COMPONENT_CPLD3:
return self._get_cpld_version(CPLD3_VERSION)

return None

def _get_transceiver_status(self):
presence_ctrl = self.sfp_control + 'qsfp_modprs'
try:
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,130 @@
#!/usr/bin/env python

########################################################################
# DELLEMC S6000
#
# Module contains an implementation of SONiC Platform Base API and
# provides the Components' (e.g., BIOS, CPLD, FPGA, etc.) available in
# the platform
#
########################################################################

try:
import os
import subprocess
from sonic_platform_base.component_base import ComponentBase
except ImportError as e:
raise ImportError(str(e) + "- required module not found")

BIOS_QUERY_VERSION_COMMAND = "dmidecode -s system-version"


class Component(ComponentBase):
"""DellEMC Platform-specific Component class"""

CPLD_DIR = "/sys/devices/platform/dell-s6000-cpld.0"

CHASSIS_COMPONENTS = [
["BIOS", ("Performs initialization of hardware components during "
"booting")],
["System-CPLD", "Used for managing CPU board devices and power"],
["Master-CPLD", ("Used for managing Fan, PSU, system LEDs, QSFP "
"modules (1-16)")],
["Slave-CPLD", "Used for managing QSFP modules (17-32)"]
]

def __init__(self, component_index):
self.index = component_index
self.name = self.CHASSIS_COMPONENTS[self.index][0]
self.description = self.CHASSIS_COMPONENTS[self.index][1]

def _get_cpld_register(self, reg_name):
rv = 'ERR'
mb_reg_file = self.CPLD_DIR+'/'+reg_name

if (not os.path.isfile(mb_reg_file)):
return rv

try:
with open(mb_reg_file, 'r') as fd:
rv = fd.read()
except Exception as error:
rv = 'ERR'

rv = rv.rstrip('\r\n')
rv = rv.lstrip(" ")
return rv

def _get_command_result(self, cmdline):
try:
proc = subprocess.Popen(cmdline.split(), stdout=subprocess.PIPE,
stderr=subprocess.STDOUT)
stdout = proc.communicate()[0]
proc.wait()
result = stdout.rstrip('\n')
except OSError:
result = None

return result

def _get_cpld_version(self, cpld_number):
cpld_version_reg = {
1: "system_cpld_ver",
2: "master_cpld_ver",
3: "slave_cpld_ver"
}

cpld_version = self._get_cpld_register(cpld_version_reg[cpld_number])

if cpld_version != 'ERR':
return str(int(cpld_version, 16))
else:
return 'NA'

def get_name(self):
"""
Retrieves the name of the component
Returns:
A string containing the name of the component
"""
return self.name

def get_description(self):
"""
Retrieves the description of the component
Returns:
A string containing the description of the component
"""
return self.description

def get_firmware_version(self):
"""
Retrieves the firmware version of the component
Returns:
A string containing the firmware version of the component
"""
if self.index == 0:
bios_ver = self._get_command_result(BIOS_QUERY_VERSION_COMMAND)

if not bios_ver:
return 'NA'
else:
return bios_ver

elif self.index <= 3:
return self._get_cpld_version(self.index)

def install_firmware(self, image_path):
"""
Installs firmware to the component
Args:
image_path: A string, path to firmware image
Returns:
A boolean, True if install was successful, False if not
"""
return False
Loading

0 comments on commit ee4ca2c

Please sign in to comment.