Skip to content

inventec/d7054q28b-Add new platform APIs chassis, eeprom,fan, psu, thermal, sfp #3577

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

Merged
Merged
Show file tree
Hide file tree
Changes from 2 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
@@ -0,0 +1,15 @@
#!/usr/bin/env python

import os
import sys
from setuptools import setup
os.listdir

setup(
name='sonic_platform',
version='1.0',
description='Module to initialize Inventec D7054Q28B platforms',

packages=['sonic_platform'],
)

Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
__all__ = ["platform", "chassis"]
from sonic_platform import *

Original file line number Diff line number Diff line change
@@ -0,0 +1,155 @@
#!/usr/bin/env python
#
# Name: chassis.py, version: 1.0
#
# Description: Module contains the definitions of SONiC platform APIs
#

try:
import os
from sonic_platform_base.chassis_base import ChassisBase
from sonic_platform.eeprom import Eeprom
from sonic_platform.psu import Psu
from sonic_platform.sfp import Sfp
from sonic_platform.fan import Fan
from sonic_platform.watchdog import Watchdog
from sonic_platform.thermal import Thermal

except ImportError as e:
raise ImportError(str(e) + "- required module not found")

class Chassis(ChassisBase):

def __init__(self):
ChassisBase.__init__(self)
self.__num_of_psus = 2
self.__num_of_ports = 54
self.__num_of_sfps = 48
self.__num_of_fans = 4
self.__num_of_thermals = 6

# Initialize EEPROM
self._eeprom = Eeprom()

# Initialize watchdog
#self._watchdog = Watchdog()

# Initialize FAN
for index in range(1, self.__num_of_fans + 1):
fan = Fan(index)
self._fan_list.append(fan)

# Initialize thermal
for index in range(1, self.__num_of_thermals + 1):
thermal = Thermal(index)
self._thermal_list.append(thermal)

# Initialize PSU and PSU_FAN
for index in range(1, self.__num_of_psus + 1):
psu = Psu(index)
self._psu_list.append(psu)
fan = Fan(index, True)
self._fan_list.append(fan)

# Initialize SFP
for index in range(0, self.__num_of_ports):
if index in range(0,self.__num_of_sfps):
sfp = Sfp(index, 'SFP')
else:
sfp = Sfp(index, 'QSFP')

self._sfp_list.append(sfp)

##############################################
# Device methods
##############################################

def get_name(self):
"""
Retrieves the name of the chassis
Returns:
string: The name of the chassis
"""
return self._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._eeprom.part_number_str()

def get_serial(self):
"""
Retrieves the serial number of the chassis
Returns:
string: Serial number of chassis
"""
return self._eeprom.serial_number_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

##############################################
# Chassis methods
##############################################

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._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._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.
Ex. { '0x21':'AG9064', '0x22':'V1.0', '0x23':'AG9064-0109867821',
'0x24':'001c0f000fcd0a', '0x25':'02/03/2018 16:22:00',
'0x26':'01', '0x27':'REV01', '0x28':'AG9064-C2358-16G'}
"""
return self._eeprom.system_eeprom_info()

def get_reboot_cause(self):
"""
Retrieves the cause of the previous reboot
Returns:
A tuple (string, string) where the first element is a string
containing the cause of the previous reboot. This string must be
one of the predefined strings in this class. If the first string
is "REBOOT_CAUSE_HARDWARE_OTHER", the second string can be used
to pass a description of the reboot cause.
"""
raise NotImplementedError
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
#!/usr/bin/env python
#
# Name: eeprom.py, version: 1.0
#
# Description: Module contains the definitions of SONiC platform APIs
#

try:
from sonic_eeprom import eeprom_tlvinfo
import binascii
except ImportError, e:
raise ImportError(str(e) + "- required module not found")

class Eeprom(eeprom_tlvinfo.TlvInfoDecoder):

def __init__(self):
self.__eeprom_path = "/sys/class/i2c-adapter/i2c-0/0-0053/eeprom"
super(Eeprom, self).__init__(self.__eeprom_path, 0, '', True)
self.__eeprom_tlv_dict = dict()
try:
self.__eeprom_data = self.read_eeprom()
except:
self.__eeprom_data = "N/A"
raise RuntimeError("Eeprom is not Programmed")
else:
eeprom = self.__eeprom_data

if not self.is_valid_tlvinfo_header(eeprom):
return

total_length = (ord(eeprom[9]) << 8) | ord(eeprom[10])
tlv_index = self._TLV_INFO_HDR_LEN
tlv_end = self._TLV_INFO_HDR_LEN + total_length

while (tlv_index + 2) < len(eeprom) and tlv_index < tlv_end:
if not self.is_valid_tlv(eeprom[tlv_index:]):
break

tlv = eeprom[tlv_index:tlv_index + 2
+ ord(eeprom[tlv_index + 1])]
code = "0x%02X" % (ord(tlv[0]))

if ord(tlv[0]) == self._TLV_CODE_VENDOR_EXT:
value = str((ord(tlv[2]) << 24) | (ord(tlv[3]) << 16) |
(ord(tlv[4]) << 8) | ord(tlv[5]))
value += str(tlv[6:6 + ord(tlv[1])])
else:
name, value = self.decoder(None, tlv)

self.__eeprom_tlv_dict[code] = value
if ord(eeprom[tlv_index]) == self._TLV_CODE_CRC_32:
break

tlv_index += ord(eeprom[tlv_index+1]) + 2

def serial_number_str(self):
(is_valid, results) = self.get_tlv_field(
self.__eeprom_data, self._TLV_CODE_SERIAL_NUMBER)
if not is_valid:
return "N/A"
return results[2]

def base_mac_addr(self):
(is_valid, t) = self.get_tlv_field(
self.__eeprom_data, self._TLV_CODE_MAC_BASE)
if not is_valid or t[1] != 6:
return super(TlvInfoDecoder, self).switchaddrstr(e)

return ":".join([binascii.b2a_hex(T) for T in t[2]])

def modelstr(self):
(is_valid, results) = self.get_tlv_field(
self.__eeprom_data, self._TLV_CODE_PRODUCT_NAME)
if not is_valid:
return "N/A"

return results[2]

def part_number_str(self):
(is_valid, results) = self.get_tlv_field(
self.__eeprom_data, self._TLV_CODE_PART_NUMBER)
if not is_valid:
return "N/A"

return results[2]

def serial_tag_str(self):
(is_valid, results) = self.get_tlv_field(
self.__eeprom_data, self._TLV_CODE_SERVICE_TAG)
if not is_valid:
return "N/A"

return results[2]

def revision_str(self):
(is_valid, results) = self.get_tlv_field(
self.__eeprom_data, self._TLV_CODE_DEVICE_VERSION)
if not is_valid:
return "N/A"

return results[2]

def system_eeprom_info(self):
"""
Returns a dictionary, where keys are the type code defined in
ONIE EEPROM format and values are their corresponding values
found in the system EEPROM.
"""
return self.__eeprom_tlv_dict

Loading