368c4fa9fe
* [device/celestica] Add silverstone device plugins and configs * add port led fireware of PAM4! * [platform/broadcom] Add Celestica silverstone platform module. * Add switch configuration Silverstone! * Add 128x100 configuration! * Delete serdes copper parameter! * [device/celestica] Fix incorrect index in Silverstone 128x100G port cfg * [platform/broadcom] Remove unrelated platform other than Silverstone * [device/celestica] Silverstone remove minigraphs * [device/celestica] Silverstone update sai.profile to use hwsku path * [device/celestica] Silverstone format sfputil codes * [device/celestica] Add speed column to Silverstone 32x400G port conf * [device/celestica] Silverstone disable 10G ports prevent orchagent crash *These ports will be added later after BRCM SAI support SFP. * Remove LED redundancy configuration and add comments! * [plugins/sfputil] update Silverstone ports to QSFP-DD type * [plugins/sfputil] Silverstone fix return NotImplementedError with raise
187 lines
5.4 KiB
Python
Executable File
187 lines
5.4 KiB
Python
Executable File
#!/usr/bin/env python
|
|
#
|
|
# Platform-specific SFP transceiver interface for SONiC
|
|
# This plugin supports QSFP-DD, QSFP and SFP.
|
|
|
|
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 = 1
|
|
PORT_END = 34
|
|
OSFP_PORT_START = 1
|
|
OSFP_PORT_END = 32
|
|
SFP_PORT_START = 33
|
|
SFP_PORT_END = 34
|
|
|
|
EEPROM_OFFSET = 9
|
|
PORT_INFO_PATH = '/sys/class/silverstone_fpga'
|
|
|
|
_port_name = ""
|
|
_port_to_eeprom_mapping = {}
|
|
_port_to_i2cbus_mapping = {}
|
|
|
|
@property
|
|
def port_start(self):
|
|
return self.PORT_START
|
|
|
|
@property
|
|
def port_end(self):
|
|
return self.PORT_END
|
|
|
|
@property
|
|
def qsfp_ports(self):
|
|
return []
|
|
|
|
@property
|
|
def osfp_ports(self):
|
|
return range(self.OSFP_PORT_START, self.OSFP_PORT_END + 1)
|
|
|
|
@property
|
|
def port_to_eeprom_mapping(self):
|
|
return self._port_to_eeprom_mapping
|
|
|
|
@property
|
|
def port_to_i2cbus_mapping(self):
|
|
return self._port_to_i2cbus_mapping
|
|
|
|
def get_port_name(self, port_num):
|
|
if port_num in self.osfp_ports:
|
|
self._port_name = "QSFP" + str(port_num - self.OSFP_PORT_START + 1)
|
|
else:
|
|
self._port_name = "SFP" + str(port_num - self.SFP_PORT_START + 1)
|
|
return self._port_name
|
|
|
|
def get_eeprom_dom_raw(self, port_num):
|
|
if port_num in self.osfp_ports:
|
|
# QSFP DOM EEPROM is also at addr 0x50 and thus also stored in eeprom_ifraw
|
|
return None
|
|
else:
|
|
# Read dom eeprom at addr 0x51
|
|
return self._read_eeprom_devid(port_num, self.DOM_EEPROM_ADDR, 256)
|
|
|
|
def __init__(self):
|
|
# Override port_to_eeprom_mapping for class initialization
|
|
eeprom_path = '/sys/bus/i2c/devices/i2c-{0}/{0}-0050/eeprom'
|
|
|
|
for x in range(self.PORT_START, self.PORT_END+1):
|
|
self.port_to_i2cbus_mapping[x] = (x + self.EEPROM_OFFSET)
|
|
self.port_to_eeprom_mapping[x] = eeprom_path.format(
|
|
x + self.EEPROM_OFFSET)
|
|
SfpUtilBase.__init__(self)
|
|
|
|
def get_presence(self, port_num):
|
|
# Check for invalid port_num
|
|
if port_num not in range(self.port_start, self.port_end + 1):
|
|
return False
|
|
|
|
# Get path for access port presence status
|
|
port_name = self.get_port_name(port_num)
|
|
sysfs_filename = "qsfp_modprs" if port_num in self.osfp_ports else "sfp_modabs"
|
|
reg_path = "/".join([self.PORT_INFO_PATH, port_name, sysfs_filename])
|
|
|
|
# Read status
|
|
try:
|
|
reg_file = open(reg_path)
|
|
content = reg_file.readline().rstrip()
|
|
reg_value = int(content)
|
|
except IOError as e:
|
|
print "Error: unable to open file: %s" % str(e)
|
|
return False
|
|
|
|
# Module present is active low
|
|
if reg_value == 0:
|
|
return True
|
|
|
|
return False
|
|
|
|
def get_low_power_mode(self, port_num):
|
|
# Check for invalid QSFP port_num
|
|
if port_num not in self.osfp_ports:
|
|
return False
|
|
|
|
try:
|
|
port_name = self.get_port_name(port_num)
|
|
reg_file = open("/".join([self.PORT_INFO_PATH,
|
|
port_name, "qsfp_lpmode"]))
|
|
except IOError as e:
|
|
print "Error: unable to open file: %s" % str(e)
|
|
return False
|
|
|
|
# Read status
|
|
content = reg_file.readline().rstrip()
|
|
reg_value = int(content)
|
|
# low power mode is active high
|
|
if reg_value == 0:
|
|
return False
|
|
|
|
return True
|
|
|
|
def set_low_power_mode(self, port_num, lpmode):
|
|
# Check for invalid QSFP port_num
|
|
if port_num not in self.osfp_ports:
|
|
return False
|
|
|
|
try:
|
|
port_name = self.get_port_name(port_num)
|
|
reg_file = open("/".join([self.PORT_INFO_PATH,
|
|
port_name, "qsfp_lpmode"]), "r+")
|
|
except IOError as e:
|
|
print "Error: unable to open file: %s" % str(e)
|
|
return False
|
|
|
|
content = hex(lpmode)
|
|
|
|
reg_file.seek(0)
|
|
reg_file.write(content)
|
|
reg_file.close()
|
|
|
|
return True
|
|
|
|
def reset(self, port_num):
|
|
# Check for invalid QSFP port_num
|
|
if port_num not in self.osfp_ports:
|
|
return False
|
|
|
|
try:
|
|
port_name = self.get_port_name(port_num)
|
|
reg_file = open("/".join([self.PORT_INFO_PATH,
|
|
port_name, "qsfp_reset"]), "w")
|
|
except IOError as e:
|
|
print "Error: unable to open file: %s" % str(e)
|
|
return False
|
|
|
|
# Convert our register value back to a hex string and write back
|
|
reg_file.seek(0)
|
|
reg_file.write(hex(0))
|
|
reg_file.close()
|
|
|
|
# Sleep 1 second to allow it to settle
|
|
time.sleep(1)
|
|
|
|
# Flip the bit back high and write back to the register to take port out of reset
|
|
try:
|
|
reg_file = open(
|
|
"/".join([self.PORT_INFO_PATH, port_name, "qsfp_reset"]), "w")
|
|
except IOError as e:
|
|
print "Error: unable to open file: %s" % str(e)
|
|
return False
|
|
|
|
reg_file.seek(0)
|
|
reg_file.write(hex(1))
|
|
reg_file.close()
|
|
|
|
return True
|
|
|
|
def get_transceiver_change_event(self, timeout=0):
|
|
"""
|
|
TBD
|
|
"""
|
|
raise NotImplementedError
|