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

DellEMC : Platform2.0 API Implementation for Chassis [S6000, S6100, Z9100], Fan [S6000] #3381

Merged
merged 5 commits into from
Sep 16, 2019
Merged
Show file tree
Hide file tree
Changes from 4 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 @@ -11,18 +11,34 @@
import os
import time
import datetime
import subprocess
from sonic_platform_base.chassis_base import ChassisBase
from sonic_platform.sfp import Sfp
from sonic_platform.eeprom import Eeprom
from sonic_platform.fan import Fan
except ImportError as e:
raise ImportError(str(e) + "- required module not found")


MAX_S6000_FAN = 3

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'


class Chassis(ChassisBase):
"""
DELLEMC Platform-specific Chassis class
"""

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

sfp_control = ""
PORT_START = 0
Expand Down Expand Up @@ -54,9 +70,20 @@ def __init__(self):
# Get Transceiver status
self.modprs_register = self._get_transceiver_status()

def get_register(self, reg_name):
self.sys_eeprom = Eeprom()
for i in range(MAX_S6000_FAN):
fan = Fan(i)
self._fan_list.append(fan)

# 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)

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

if (not os.path.isfile(mb_reg_file)):
return rv
Expand All @@ -71,11 +98,85 @@ def get_register(self, reg_name):
rv = rv.lstrip(" ")
return rv

def get_name(self):
"""
Retrieves the name of the chassis
Returns:
string: The name of the chassis
"""
return self.sys_eeprom.modelstr()

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

def get_model(self):
"""
Retrieves the model number (or part number) of the chassis
Returns:
string: Model/part number of chassis
"""
return self.sys_eeprom.part_number_str()

def get_serial(self):
"""
Retrieves the serial number of the chassis (Service tag)
Returns:
string: Serial number of chassis
"""
return self.sys_eeprom.serial_str()

def get_status(self):
"""
Retrieves the operational status of the chassis
Returns:
bool: A boolean value, True if chassis is operating properly
False if not
"""
return True

def get_base_mac(self):
"""
Retrieves the base MAC address for the chassis

Returns:
A string containing the MAC address in the format
'XX:XX:XX:XX:XX:XX'
"""
return self.sys_eeprom.base_mac_addr()

def get_serial_number(self):
"""
Retrieves the hardware serial number for the chassis

Returns:
A string containing the hardware serial number for this
chassis.
"""
return self.sys_eeprom.serial_number_str()

def get_system_eeprom_info(self):
"""
Retrieves the full content of system EEPROM information for the
chassis

Returns:
A dictionary where keys are the type code defined in
OCP ONIE TlvInfo EEPROM format and values are their
corresponding values.
"""
return self.sys_eeprom.system_eeprom_info()

def get_reboot_cause(self):
"""
Retrieves the cause of the previous reboot
"""
reset_reason = int(self.get_register('last_reboot_reason'), base=16)
reset_reason = int(self._get_cpld_register('last_reboot_reason'),
base=16)

# In S6000, We track the reboot reason by writing the reason in
# NVRAM. Only Warmboot and Coldboot reason are supported here.
Expand All @@ -85,6 +186,46 @@ def get_reboot_cause(self):

return (ChassisBase.REBOOT_CAUSE_HARDWARE_OTHER, "Invalid Reason")

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 Expand Up @@ -151,3 +292,4 @@ def get_transceiver_change_event(self, timeout=0):
return True, {}
return False, {}


Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,8 @@
fan_eeprom_format = [
('PPID', 's', 20), ('DPN Rev', 's', 3), ('Service Tag', 's', 7),
('Part Number', 's', 10), ('Part Num Revision', 's', 3),
('Mfg Test', 's', 2), ('Number of Fans', 's', 2), ('Fan Type', 's', 1),
('Mfg Test', 's', 2), ('Redundant copy', 's', 82),
('Number of Fans', 's', 1), ('Fan Type', 's', 1),
('Fab Rev', 's', 2)
]

Expand Down Expand Up @@ -86,6 +87,8 @@ def _load_system_eeprom(self):
self.base_mac = 'NA'
self.serial_number = 'NA'
self.part_number = 'NA'
self.model_str = 'NA'
self.serial = 'NA'
self.eeprom_tlv_dict = dict()
else:
eeprom = self.eeprom_data
Expand All @@ -95,6 +98,8 @@ def _load_system_eeprom(self):
self.base_mac = 'NA'
self.serial_number = 'NA'
self.part_number = 'NA'
self.model_str = 'NA'
self.serial = 'NA'
return

total_length = (ord(eeprom[9]) << 8) | ord(eeprom[10])
Expand Down Expand Up @@ -123,11 +128,15 @@ def _load_system_eeprom(self):
tlv_index += ord(eeprom[tlv_index+1]) + 2

self.base_mac = self.eeprom_tlv_dict.get(
hex(self._TLV_CODE_MAC_BASE), 'NA')
"0x%X" % (self._TLV_CODE_MAC_BASE), 'NA')
self.serial_number = self.eeprom_tlv_dict.get(
hex(self._TLV_CODE_SERIAL_NUMBER), 'NA')
"0x%X" % (self._TLV_CODE_SERIAL_NUMBER), 'NA')
self.part_number = self.eeprom_tlv_dict.get(
hex(self._TLV_CODE_PART_NUMBER), 'NA')
"0x%X" % (self._TLV_CODE_PART_NUMBER), 'NA')
self.model_str = self.eeprom_tlv_dict.get(
"0x%X" % (self._TLV_CODE_PRODUCT_NAME), 'NA')
self.serial = self.eeprom_tlv_dict.get(
"0x%X" % (self._TLV_CODE_SERVICE_TAG), 'NA')

def _load_device_eeprom(self):
"""
Expand All @@ -151,14 +160,20 @@ def _load_device_eeprom(self):
if valid:
self.serial_number += "-" + data
else:
seld.serial_number = 'NA'
self.serial_number = 'NA'

(valid, data) = self._get_eeprom_field("Part Number")
if valid:
self.part_number = data
else:
self.part_number = 'NA'

(valid, data) = self._get_eeprom_field("Fan Type")
if valid:
self.fan_type = data
else:
self.fan_type = 'NA'

def _get_eeprom_field(self, field_name):
"""
For a field name specified in the EEPROM format, returns the
Expand All @@ -185,13 +200,31 @@ def part_number_str(self):
"""
return self.part_number

def airflow_fan_type(self):
"""
Returns the airflow fan type.
"""
return int(self.fan_type.encode('hex'), 16)

# System EEPROM specific methods
def base_mac_addr(self):
"""
Returns the base MAC address found in the system EEPROM.
"""
return self.base_mac

def modelstr(self):
"""
Returns the Model name.
"""
return self.model_str

def serial_str(self):
"""
Returns the servicetag number.
"""
return self.serial

def system_eeprom_info(self):
"""
Returns a dictionary, where keys are the type code defined in
Expand Down
Loading