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

[device/plugins] Celestica seastone2 add python plugins #76

Merged
merged 3 commits into from Apr 24, 2019
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
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#!/usr/bin/env python

#############################################################################
# Celestica DX010
# Celestica Seastone2
#
# Platform and model specific eeprom subclass, inherits from the base class,
# and provides the followings:
Expand Down
38 changes: 29 additions & 9 deletions device/celestica/x86_64-cel_seastone_2-r0/plugins/psuutil.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ class PsuUtil(PsuBase):
"""Platform-specific PSUutil class"""

def __init__(self):
self.ipmi_sensor = "docker exec -ti pmon ipmitool sensor"
PsuBase.__init__(self)

def run_command(self, command):
Expand All @@ -26,7 +27,11 @@ def run_command(self, command):
return out

def find_value(self, grep_string):
return re.findall("[-+]?\d*\.\d+|\d+", grep_string)
result = re.search(".+\| (0x\d{2})\d{2}\|.+", grep_string)
if result:
return result.group(1)
else:
return result

def get_num_psus(self):
"""
Expand All @@ -44,15 +49,20 @@ def get_psu_status(self, index):
"""
if index is None:
return False
grep_key = "PSUL_CIn" if index == 1 else "PSUR_CIn"
grep_string = self.run_command('ipmitool sdr | grep '+ grep_key)
raw_cIn_value = self.find_value(grep_string)
cIn_value = float(raw_cIn_value[0])

grep_key = "PSUL_Status" if index == 1 else "PSUR_Status"
grep_string = self.run_command(self.ipmi_sensor + ' | grep '+ grep_key)
status_byte = self.find_value(grep_string)

if float(cIn_value) == 0.0:
if status_byte is None:
return False

return True
failure_detected = (int(status_byte, 16) >> 1) & 1
input_lost = (int(status_byte, 16) >> 3) & 1
if failure_detected or input_lost:
return False
else:
return True

def get_psu_presence(self, index):
"""
Expand All @@ -64,5 +74,15 @@ def get_psu_presence(self, index):
if index is None:
return False

### TBD ###
return True
grep_key = "PSUL_Status" if index == 1 else "PSUR_Status"
grep_string = self.run_command(self.ipmi_sensor + ' | grep '+ grep_key)
status_byte = self.find_value(grep_string)

if status_byte is None:
return False

presence = ( int(status_byte, 16) >> 0 ) & 1
if presence:
return True
else:
return False
74 changes: 50 additions & 24 deletions device/celestica/x86_64-cel_seastone_2-r0/plugins/sfputil.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,16 @@ class SfpUtil(SfpUtilBase):
"""Platform-specific SfpUtil class"""

PORT_START = 1
PORT_END = 56
QSFP_PORT_START = 49
QSFP_PORT_END = 56
PORT_END = 33
QSFP_PORT_START = 1
QSFP_PORT_END = 32

EEPROM_OFFSET = 1
PORT_INFO_PATH = '/sys/class/seastone2_fpga'

_port_name = ""
_port_to_eeprom_mapping = {}
_port_to_i2cbus_mapping = {}

@property
def port_start(self):
Expand All @@ -39,56 +41,70 @@ def qsfp_ports(self):
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 > self.QSFP_PORT_START - 1:
if port_num in self.qsfp_ports:
self._port_name = "QSFP" + str(port_num - self.QSFP_PORT_START + 1)
else:
self._port_name = "SFP" + str(port_num)
return self._port_name

# def get_eeprom_dom_raw(self, port_num):
# if port_num in self.qsfp_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_eeprom_mapping[x] = eeprom_path.format(x + self.EEPROM_OFFSET)
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 < self.port_start or port_num > self.port_end:
if port_num not in range(self.port_start, self.port_end + 1):
return False

sysfs_filename = "sfp_modabs"
# Get path for access port presence status
port_name = self.get_port_name(port_num)
if port_num in self.qsfp_ports:
sysfs_filename = "qsfp_modprs"
try:

reg_file = open("/sys/devices/platform/questone2/SFF/"+port_name+"/"+sysfs_filename)
sysfs_filename = "qsfp_modprs" if port_num in self.qsfp_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

# Read status
content = reg_file.readline().rstrip()
reg_value = int(content)

# ModPrsL is active low
# 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 < self.port_start or port_num > self.port_end or port_num <= 48:
if port_num not in self.qsfp_ports:
return False

try:
port_name = self.get_port_name(port_num)
reg_file = open("/sys/devices/platform/questone2/SFF/"+port_name+"/qsfp_lpmode")
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
Expand All @@ -104,12 +120,13 @@ def get_low_power_mode(self, port_num):

def set_low_power_mode(self, port_num, lpmode):
# Check for invalid QSFP port_num
if port_num < self.port_start or port_num > self.port_end or port_num <= 48:
if port_num not in self.qsfp_ports:
return False

try:
port_name = self.get_port_name(port_num)
reg_file = open("/sys/devices/platform/questone2/SFF/"+port_name+"/qsfp_lpmode", "r+")
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
Expand All @@ -124,12 +141,13 @@ def set_low_power_mode(self, port_num, lpmode):

def reset(self, port_num):
# Check for invalid QSFP port_num
if port_num < self.port_start or port_num > self.port_end or port_num <= 48:
if port_num not in self.qsfp_ports:
return False

try:
port_name = self.get_port_name(port_num)
reg_file = open("/sys/devices/platform/questone2/SFF/"+port_name+"/qsfp_reset", "w")
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
Expand All @@ -144,7 +162,8 @@ def reset(self, port_num):

# Flip the bit back high and write back to the register to take port out of reset
try:
reg_file = open("/sys/devices/platform/questone2/SFF/"+port_name+"/qsfp_reset", "w")
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
Expand All @@ -154,3 +173,10 @@ def reset(self, port_num):
reg_file.close()

return True

def get_transceiver_change_event(self, timeout=0):
"""
TBD: When the feature request.
"""
return NotImplementedError