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

Add Pegatron project to branch 201807 #2299

Merged
merged 2 commits into from
Dec 4, 2018
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
1 change: 1 addition & 0 deletions device/pegatron/x86_64-pegatron_porsche-r0/default_sku
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
porsche t1
3 changes: 3 additions & 0 deletions device/pegatron/x86_64-pegatron_porsche-r0/installer.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
CONSOLE_PORT=0x2f8
CONSOLE_DEV=1
CONSOLE_SPEED=115200
21 changes: 21 additions & 0 deletions device/pegatron/x86_64-pegatron_porsche-r0/plugins/eeprom.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#!/usr/bin/env python

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

class board(eeprom_tlvinfo.TlvInfoDecoder):
_TLV_INFO_MAX_LEN = 256
def __init__(self, name, path, cpld_root, ro):
self.eeprom_path = "/sys/bus/i2c/devices/4-0054/eeprom"
super(board, self).__init__(self.eeprom_path, 0, '', True)
92 changes: 92 additions & 0 deletions device/pegatron/x86_64-pegatron_porsche-r0/plugins/psuutil.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
#
# psuutil.py
# Platform-specific PSU status interface for SONiC
#


import os.path

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"""

SYSFS_PSU_DIR = "/sys/bus/i2c/devices/7-0075"

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


# Get sysfs attribute
def get_attr_value(self, attr_path):

retval = 'ERR'
if (not os.path.isfile(attr_path)):
return retval

try:
with open(attr_path, 'r') as fd:
retval = fd.read()
except Exception as error:
logging.error("Unable to open ", attr_path, " file !")

retval = retval.rstrip('\r\n')

fd.close()
return retval

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
"""
MAX_PSUS = 2
return MAX_PSUS

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
"""
status = 0
attr_file = 'psu_'+str(index)+'_status'
attr_path = self.SYSFS_PSU_DIR +'/' + attr_file

attr_value = self.get_attr_value(attr_path)

if (attr_value != 'ERR'):
attr_value = int(attr_value, 16)
# Check for PSU status
if (attr_value == 1):
status = 1

return 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
"""
status = 0
attr_file = 'psu_'+str(index)+'_present'
attr_path = self.SYSFS_PSU_DIR +'/' + attr_file

attr_value = self.get_attr_value(attr_path)

if (attr_value != 'ERR'):
attr_value = int(attr_value, 16)
# Check for PSU presence
if (attr_value == 0):
status = 1

return status

238 changes: 238 additions & 0 deletions device/pegatron/x86_64-pegatron_porsche-r0/plugins/sfputil.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,238 @@
#!/usr/bin/env python

try:
import os
import re
import time
from sonic_sfp.sfputilbase import SfpUtilBase
except ImportError, e:
raise ImportError (str(e) + "- required module not found")


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

port_start = 0
port_end = 53
ports_in_block = 54
cplda_sfp_num = 24
cpldb_sfp_num = 12
cpldc_sfp_num = 18

port_to_eeprom_mapping = {}
port_to_i2c_mapping = {}
sfp_ports = range(0, ports_in_block)
qsfp_ports = range(ports_in_block - 6, ports_in_block)


def __init__(self):
for x in range(self.port_start, self.port_end + 1):
if x < self.cpldb_sfp_num:
self.port_to_i2c_mapping.update({x:7})
elif x < self.cplda_sfp_num + self.cpldb_sfp_num:
self.port_to_i2c_mapping.update({x:6})
else:
self.port_to_i2c_mapping.update({x:8})

for x in range(self.port_start, self.port_end+1):
eeprom_path = '/sys/bus/i2c/devices/{0}-0050/sfp'+str(x+1)+'_eeprom'
port_eeprom_path = eeprom_path.format(self.port_to_i2c_mapping[x])
self.port_to_eeprom_mapping[x] = port_eeprom_path
SfpUtilBase.__init__(self)


def get_presence(self, port_num):
if port_num < self.port_start or port_num > self.port_end:
return False

if port_num < self.cpldb_sfp_num:
presence_path = '/sys/bus/i2c/devices/7-0075/sfp'+str(port_num+1)+'_present'
elif port_num < self.cpldb_sfp_num + self.cplda_sfp_num:
presence_path = '/sys/bus/i2c/devices/6-0074/sfp'+str(port_num+1)+'_present'
else:
presence_path = '/sys/bus/i2c/devices/8-0076/sfp'+str(port_num+1)+'_present'

try:
file = open(presence_path)
except IOError as e:
print "Error: unable to open file: %s" % str(e)
return False

value = int(file.readline().rstrip())

file.close()
if value == 0:
return True

return False

def get_low_power_mode(self, port_num):
if port_num not in self.qsfp_ports:
return False

lowpower_path = '/sys/bus/i2c/devices/8-0076/sfp'+str(port_num+1)+'_lowpower'

try:
file = open(lowpower_path)
except IOError as e:
print "Error: unable to open file: %s" % str(e)
return False

value = int(file.readline().rstrip())

file.close()
if value == 1:
return True

return False

def set_low_power_mode(self, port_num, lpmode):
if port_num not in self.qsfp_ports:
return False

lowpower_path = '/sys/bus/i2c/devices/8-0076/sfp'+str(port_num+1)+'_lowpower'

# LPMode is active high; set or clear the bit accordingly
if lpmode is True:
value = 1
else:
value = 0

try:
file = open(lowpower_path, "r+")
except IOError as e:
print "Error: unable to open file: %s" % str(e)
return False

file.seek(0)
file.write(str(value))
file.close()

return True

def reset(self, port_num):
if port_num not in self.qsfp_ports:
return False
reset_path = '/sys/bus/i2c/devices/8-0076/sfp'+str(port_num+1)+'_reset'

try:
file = open(reset_path, "r+")
except IOError as e:
print "Error: unable to open file: %s" % str(e)
return False

file.seek(0)
file.write(str(2))
file.close()

# Sleep 1 second to allow it to settle
time.sleep(1)

try:
file = open(reset_path, "r+")
except IOError as e:
print "Error: unable to open file: %s" % str(e)
return False

file.seek(0)
file.write(str(1))
file.close()

return True

def read_porttab_mappings(self, porttabfile):
logical = []
logical_to_bcm = {}
logical_to_physical = {}
physical_to_logical = {}
last_fp_port_index = 0
last_portname = ""
first = 1
port_pos_in_file = 0
parse_fmt_port_config_ini = False

try:
f = open(porttabfile)
except:
raise

parse_fmt_port_config_ini = (os.path.basename(porttabfile) == "port_config.ini")

# Read the porttab file and generate dicts
# with mapping for future reference.
# XXX: move the porttab
# parsing stuff to a separate module, or reuse
# if something already exists
for line in f:
line.strip()
if re.search("^#", line) is not None:
continue

# Parsing logic for 'port_config.ini' file
if (parse_fmt_port_config_ini):
# bcm_port is not explicitly listed in port_config.ini format
# Currently we assume ports are listed in numerical order according to bcm_port
# so we use the port's position in the file (zero-based) as bcm_port
portname = line.split()[0]

bcm_port = str(port_pos_in_file)

if len(line.split()) >= 4:
fp_port_index = int(line.split()[3])
else:
fp_port_index = portname.split("Ethernet").pop()
fp_port_index = int(fp_port_index.split("s").pop(0))/4
else: # Parsing logic for older 'portmap.ini' file
(portname, bcm_port) = line.split("=")[1].split(",")[:2]

fp_port_index = portname.split("Ethernet").pop()
fp_port_index = int(fp_port_index.split("s").pop(0))/4

if ((len(self.sfp_ports) > 0) and (fp_port_index not in self.sfp_ports)):
continue

if first == 1:
# Initialize last_[physical|logical]_port
# to the first valid port
last_fp_port_index = fp_port_index
last_portname = portname
first = 0

logical.append(portname)

logical_to_bcm[portname] = "xe" + bcm_port
logical_to_physical[portname] = [fp_port_index]
if physical_to_logical.get(fp_port_index) is None:
physical_to_logical[fp_port_index] = [portname]
else:
physical_to_logical[fp_port_index].append(
portname)

if (fp_port_index - last_fp_port_index) > 1:
# last port was a gang port
for p in range(last_fp_port_index+1, fp_port_index):
logical_to_physical[last_portname].append(p)
if physical_to_logical.get(p) is None:
physical_to_logical[p] = [last_portname]
else:
physical_to_logical[p].append(last_portname)

last_fp_port_index = fp_port_index
last_portname = portname

port_pos_in_file += 1

self.logical = logical
self.logical_to_bcm = logical_to_bcm
self.logical_to_physical = logical_to_physical
self.physical_to_logical = physical_to_logical

"""
print "logical: " + self.logical
print "logical to bcm: " + self.logical_to_bcm
print "logical to physical: " + self.logical_to_physical
print "physical to logical: " + self.physical_to_logical
"""



Loading