Skip to content
This repository was archived by the owner on Jan 3, 2023. It is now read-only.
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
149 changes: 149 additions & 0 deletions device/barefoot/x86_64-accton_wedge100bf_32x-r0/plugins/eeprom.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,149 @@
#!/usr/bin/env python

#############################################################################
#Barefoot Montara/Mavericks
#
# Platform and model specific eeprom subclass, inherits from the base class,
# and provides the followings:
# - the eeprom format definition
# - specific encoder/decoder if there is special need
#############################################################################

try:
import exceptions
import binascii
import time
import optparse
import warnings
import os
import sys
import subprocess
import json
from sonic_eeprom import eeprom_base
from sonic_eeprom import eeprom_tlvinfo
except ImportError, e:
raise ImportError (str(e) + "- required module not found")

eeprom_dict = { "version": ("Version", None, 0 ),
"pcb_mfger": ("PCB Manufacturer", "0x01", 8),
"prod_ser_num": ("Serial Number","0x23",12),
"bfn_pcba_part_num": ("Switch PCBA Part Number","0x02",12),
"odm_pcba_part_num": ("Part Number","0x22",13),
"bfn_pcbb_part_num": ("Switch PCBB Part Number","0x04",12),
"sys_asm_part_num": ("System Assembly Part Number", "0x05", 12),
"prod_state": ("Product Production State", "0x06", 1),
"location": ("EEPROM Location of Fabric", "0x07", 8),
"ext_mac_addr_size": ("Extende MAC Address Size", "0x08", 2),
"sys_mfg_date": ("System Manufacturing Date", "0x25", 4),
"prod_name": ("Product Name", "0x21",12),
"prod_ver": ("Product Version", "0x26", 1),
"prod_part_num": ("Product Part Number", "0x09", 8),
"sys_mfger": ("Manufacturer", "0x2B", 8),
"assembled_at": ("Assembled at","0x08" ,8),
"prod_ast_tag": ("Product Asset Tag", "0x09", 12),
"loc_mac_addr": ("Local MAC address", "0x0A",12),
"crc8": ("CRC8", "0xFE", 1),
"odm_pcba_ser_num": ("ODM PBCA Serial Number", "0x0B", 12),
"ext_mac_addr": ("Extended MAC Address Base", "0x0C",12),
"prod_sub_ver": ("Product Sub Version", "0x0D",1)
}

product_dict = {"Montara":"Wedge100BF-32X-O-AC-F-BF",
"Lower MAV":"Wedge100BF-65X-O-AC-F-BF",
"Upper MAV":"Wedge100BF-65X-O-AC-F-BF"
}

class board(eeprom_tlvinfo.TlvInfoDecoder, eeprom_base.EepromDecoder):

""" On BFN platform onie system eeprom is not mapped to sysfs tree """
def __init__(self, name, path, cpld_root, ro):
self.eeprom_path = ""
super(board, self).__init__(self.eeprom_path, 0, '', True)

def set_cache_name(self,name):
pass

def update_cache(self,e):
pass

def write_cache(self,e):
pass


def read_eeprom(self):
cmd = "docker exec -it syncd eeprom read_eeprom"
output = subprocess.Popen(cmd, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
eeprom,err = output.communicate()
if err != "":
raise RuntimeError("{0:s}".format(err))
else:
return eeprom


def base_mac_addr(self,e):
eeprom = json.loads(e)
mac = eeprom.get("loc_mac_addr",None)
if mac is None:
return "Bad Base Mac Address"
else:
return mac

def serial_number_str(self,e):
eeprom = json.loads(e)
serial = eeprom.get("prod_ser_num", None)
if serial is None:
return "Bad service tag"
else:
return serial

def decode_eeprom(self,e):
eeprom = json.loads(e)
value = ""
total_len = 0
tlvHeader = ""
tlvBody = ""

tlvHeader += "TlvInfo Header:\n"
tlvHeader += " Id String: TlvInfo\n"
tlvHeader += " Version: {0:d}\n".format(eeprom.get("version",1))

for attr, val in eeprom.iteritems():
if val is not None:
if isinstance(val, basestring):
value = val
else:
value = str(val)
type, code, tlvlen = eeprom_dict.get(attr)
if type is not None and tlvlen > 0 and value:
product = product_dict.get(value)
if product is not None:
value = product

tlvlen = len(value)
if tlvlen > 0:
total_len += tlvlen
tlvBody += "{0:s} {1:s} {2:d} {3:s}\n".format(type, code, tlvlen, value)

tlvHeader += " Total Length: {0:d}\n".format(total_len)
tlvHeader += "TLV Name Len Value\n"
tlvHeader += "-------------------- --- -----\n"

sys.stdout.write(tlvHeader)
sys.stdout.write(tlvBody)

def is_checksum_valid(self,e):
# Assumption is checksum verification already done in BMC and correctly parsed and verified information is avail
return (True,0)


# def is_valid_block(self, e):
# pass
#
# def is_valid_block_checksum(self, e):
# pass
#
# def decoder(self, s, t):
# pass
#
# def get_tlv_index(self, e, code):
# pass
88 changes: 88 additions & 0 deletions device/barefoot/x86_64-accton_wedge100bf_32x-r0/plugins/psuutil.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
#
# psuutil.py
# Platform-specific PSU status interface for SONiC
#


import os.path
import subprocess

try:
from sonic_psu.psu_base import PsuBase
except ImportError as e:
raise ImportError(str(e) + "- required module not found")


class PsuUtil(PsuBase):
"""Platform-specific PSUutil class"""

def __init__(self):
PsuBase.__init__(self)

def get_num_psus(self):
"""
Retrieves the number of PSUs available on the device
:return: An integer, the number of PSUs available on the device
"""
cmd = "docker exec -it syncd ps_info get_num_psus"
output = subprocess.Popen(cmd, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
num,err = output.communicate()
if err != "":
raise RuntimeError("{0:s}".format(err))
else:
return int(num.strip())

def get_psu_status(self, index):
"""
Retrieves the oprational status of power supply unit (PSU) defined
by index <index>
:param index: An integer, index of the PSU of which to query status
:return: Boolean, True if PSU is operating properly, False if PSU is\
faulty
"""

cmd = "docker exec -it syncd ps_info get_psu_presence {0:d}".format(index)
output = subprocess.Popen(cmd, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
out,err = output.communicate()
if err != "":
raise RuntimeError("{0:s}".format(err))
else:
if out.strip() == "True":
presence = True
else:
presence = False

cmd = "docker exec -it syncd ps_info get_psu_status {0:d}".format(index)
status = subprocess.Popen(cmd, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
sout,serr = status.communicate()

if serr != "":
raise RuntimeError("{0:s}".format(err))
else:
if sout.strip() == "True":
psu_status = True
else:
psu_status = False

return (presence & psu_status)

def get_psu_presence(self, index):
"""
Retrieves the presence status of power supply unit (PSU) defined
by index <index>
:param index: An integer, index of the PSU of which to query status
:return: Boolean, True if PSU is plugged, False if not
"""

cmd = "docker exec -it syncd ps_info get_psu_presence {0:d}".format(index)
output = subprocess.Popen(cmd, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
out,err = output.communicate()
if err != "":
raise RuntimeError("{0:s}".format(err))
else:
if out.strip() == "True":
presence = True
else:
presence = False

return presence
129 changes: 129 additions & 0 deletions device/barefoot/x86_64-accton_wedge100bf_32x-r0/plugins/sfputil.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,129 @@
# sfputil.py
#
# Platform-specific SFP transceiver interface for SONiC
#

import subprocess
import re

try:
import time
from sonic_sfp.sfputilbase import SfpUtilBase
except ImportError as e:
raise ImportError("%s - required module not found" % str(e))

class SfpUtil(SfpUtilBase):
"""Platform-specific SfpUtil class"""

PORT_START = 0

@property
def port_start(self):
return self.PORT_START

@property
def port_end(self):
cmd = "docker exec -it syncd sfputil get_number_qsfp_ports"
count=subprocess.Popen(cmd, shell=True,stdout=subprocess.PIPE).stdout.read()
return int(count.strip())-1

""" BFN Wedge based platform do not export eeprom info via sysfs path. Hence we skip this"""
@property
def port_to_eeprom_mapping(self):
pass

def __init__(self):
SfpUtilBase.__init__(self)

def get_presence(self, port_num):
# Check for invalid port_num
if port_num < self.port_start or port_num > self.port_end:
return False
qsfp_port = port_num + 1
cmd = "docker exec -it syncd sfputil get_presence {0:s}".format(str(qsfp_port))
presence=subprocess.Popen(cmd, shell=True,stdout=subprocess.PIPE).stdout.read()
if presence.strip() == "True":
return True
else:
return False

def get_low_power_mode(self, port_num):
# Check for invalid port_num
if port_num < self.port_start or port_num > self.port_end:
return False
qsfp_port = port_num + 1
cmd = "docker exec -it syncd sfputil get_lp_mode {0:s}".format(str(qsfp_port))
lpmode=subprocess.Popen(cmd, shell=True,stdout=subprocess.PIPE).stdout.read()
if lpmode.strip() == "True":
return True
else:
return False

@property
def qsfp_ports(self):
return range(self.port_start, self.port_end + 1)

def reset(self, port_num):
# Check for invalid port_num
if port_num < self.port_start or port_num > self.port_end:
return False
qsfp_port = port_num + 1
cmd = "docker exec -i syncd sfputil sfp_reset {0:s}".format(str(qsfp_port))
output = subprocess.Popen(cmd, shell=True,stdout=subprocess.PIPE, stderr=subprocess.PIPE)
out, err = output.communicate()

if err != "":
print "Unable to reset port {0:d} {1:s}".format(port_num, err)
return False
else:
return True

def set_low_power_mode(self, port_num, lpmode):
# Check for invalid port_num
if port_num < self.port_start or port_num > self.port_end:
return False

if lpmode is True:
mode = 1
else:
mode = 0
qsfp_port = port_num + 1
cmd = "docker exec -i syncd sfputil set_low_power_mode {0:s} {1:d}".format(str(qsfp_port),mode)
output = subprocess.Popen(cmd, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
out,err = output.communicate()

if err != "":
print "Unable to set low power mode {0:s}".format(err)
return False

return True

""" Overrides method get_eeprom_raw of baseclasee SpfUtilBase. This method return data from lower & upper page0"""
def get_eeprom_raw(self, port_num):
# Check for invalid port_num
if port_num < self.port_start or port_num > self.port_end:
return False
qsfp_port = port_num + 1
cmd = "docker exec -i syncd sfputil get_eeprom_raw {0:s}".format(str(qsfp_port))
process = subprocess.Popen(cmd, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
sfp_raw, err = process.communicate()
if sfp_raw != "":
raw = re.findall('..?', sfp_raw)
return raw[:256]
else:
return None

""" Overrides method get_eeprom_raw of baseclasee SpfUtilBase. This method return data from page3"""
def get_eeprom_dom_raw(self, port_num):
# Check for invalid port_num
if port_num < self.port_start or port_num > self.port_end:
return False
qsfp_port = port_num + 1
cmd = "docker exec -i syncd sfputil get_eeprom_raw {0:s}".format(str(qsfp_port))
process = subprocess.Popen(cmd, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
sfp_raw, err = process.communicate()
if sfp_raw != "":
raw = re.findall('..?', sfp_raw)
return raw[256:]
else:
return None
Loading