Skip to content

Commit a1e6c2c

Browse files
Peter5Linlguohan
authored andcommitted
Add Pegatron project to branch 201807 (#2299)
* Add Porsche project * Upgrade kernel to 3.16.57-2
1 parent c164caf commit a1e6c2c

27 files changed

+4381
-2
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
porsche t1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
CONSOLE_PORT=0x2f8
2+
CONSOLE_DEV=1
3+
CONSOLE_SPEED=115200
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
#!/usr/bin/env python
2+
3+
try:
4+
import exceptions
5+
import binascii
6+
import time
7+
import optparse
8+
import warnings
9+
import os
10+
import sys
11+
from sonic_eeprom import eeprom_base
12+
from sonic_eeprom import eeprom_tlvinfo
13+
import subprocess
14+
except ImportError, e:
15+
raise ImportError (str(e) + "- required module not found")
16+
17+
class board(eeprom_tlvinfo.TlvInfoDecoder):
18+
_TLV_INFO_MAX_LEN = 256
19+
def __init__(self, name, path, cpld_root, ro):
20+
self.eeprom_path = "/sys/bus/i2c/devices/4-0054/eeprom"
21+
super(board, self).__init__(self.eeprom_path, 0, '', True)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
#
2+
# psuutil.py
3+
# Platform-specific PSU status interface for SONiC
4+
#
5+
6+
7+
import os.path
8+
9+
try:
10+
from sonic_psu.psu_base import PsuBase
11+
except ImportError as e:
12+
raise ImportError(str(e) + "- required module not found")
13+
14+
15+
class PsuUtil(PsuBase):
16+
"""Platform-specific PSUutil class"""
17+
18+
SYSFS_PSU_DIR = "/sys/bus/i2c/devices/7-0075"
19+
20+
def __init__(self):
21+
PsuBase.__init__(self)
22+
23+
24+
# Get sysfs attribute
25+
def get_attr_value(self, attr_path):
26+
27+
retval = 'ERR'
28+
if (not os.path.isfile(attr_path)):
29+
return retval
30+
31+
try:
32+
with open(attr_path, 'r') as fd:
33+
retval = fd.read()
34+
except Exception as error:
35+
logging.error("Unable to open ", attr_path, " file !")
36+
37+
retval = retval.rstrip('\r\n')
38+
39+
fd.close()
40+
return retval
41+
42+
def get_num_psus(self):
43+
"""
44+
Retrieves the number of PSUs available on the device
45+
:return: An integer, the number of PSUs available on the device
46+
"""
47+
MAX_PSUS = 2
48+
return MAX_PSUS
49+
50+
def get_psu_status(self, index):
51+
"""
52+
Retrieves the oprational status of power supply unit (PSU) defined
53+
by index <index>
54+
:param index: An integer, index of the PSU of which to query status
55+
:return: Boolean, True if PSU is operating properly, False if PSU is\
56+
faulty
57+
"""
58+
status = 0
59+
attr_file = 'psu_'+str(index)+'_status'
60+
attr_path = self.SYSFS_PSU_DIR +'/' + attr_file
61+
62+
attr_value = self.get_attr_value(attr_path)
63+
64+
if (attr_value != 'ERR'):
65+
attr_value = int(attr_value, 16)
66+
# Check for PSU status
67+
if (attr_value == 1):
68+
status = 1
69+
70+
return status
71+
72+
def get_psu_presence(self, index):
73+
"""
74+
Retrieves the presence status of power supply unit (PSU) defined
75+
by index <index>
76+
:param index: An integer, index of the PSU of which to query status
77+
:return: Boolean, True if PSU is plugged, False if not
78+
"""
79+
status = 0
80+
attr_file = 'psu_'+str(index)+'_present'
81+
attr_path = self.SYSFS_PSU_DIR +'/' + attr_file
82+
83+
attr_value = self.get_attr_value(attr_path)
84+
85+
if (attr_value != 'ERR'):
86+
attr_value = int(attr_value, 16)
87+
# Check for PSU presence
88+
if (attr_value == 0):
89+
status = 1
90+
91+
return status
92+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,238 @@
1+
#!/usr/bin/env python
2+
3+
try:
4+
import os
5+
import re
6+
import time
7+
from sonic_sfp.sfputilbase import SfpUtilBase
8+
except ImportError, e:
9+
raise ImportError (str(e) + "- required module not found")
10+
11+
12+
class SfpUtil(SfpUtilBase):
13+
"""Platform specific sfputil class"""
14+
15+
port_start = 0
16+
port_end = 53
17+
ports_in_block = 54
18+
cplda_sfp_num = 24
19+
cpldb_sfp_num = 12
20+
cpldc_sfp_num = 18
21+
22+
port_to_eeprom_mapping = {}
23+
port_to_i2c_mapping = {}
24+
sfp_ports = range(0, ports_in_block)
25+
qsfp_ports = range(ports_in_block - 6, ports_in_block)
26+
27+
28+
def __init__(self):
29+
for x in range(self.port_start, self.port_end + 1):
30+
if x < self.cpldb_sfp_num:
31+
self.port_to_i2c_mapping.update({x:7})
32+
elif x < self.cplda_sfp_num + self.cpldb_sfp_num:
33+
self.port_to_i2c_mapping.update({x:6})
34+
else:
35+
self.port_to_i2c_mapping.update({x:8})
36+
37+
for x in range(self.port_start, self.port_end+1):
38+
eeprom_path = '/sys/bus/i2c/devices/{0}-0050/sfp'+str(x+1)+'_eeprom'
39+
port_eeprom_path = eeprom_path.format(self.port_to_i2c_mapping[x])
40+
self.port_to_eeprom_mapping[x] = port_eeprom_path
41+
SfpUtilBase.__init__(self)
42+
43+
44+
def get_presence(self, port_num):
45+
if port_num < self.port_start or port_num > self.port_end:
46+
return False
47+
48+
if port_num < self.cpldb_sfp_num:
49+
presence_path = '/sys/bus/i2c/devices/7-0075/sfp'+str(port_num+1)+'_present'
50+
elif port_num < self.cpldb_sfp_num + self.cplda_sfp_num:
51+
presence_path = '/sys/bus/i2c/devices/6-0074/sfp'+str(port_num+1)+'_present'
52+
else:
53+
presence_path = '/sys/bus/i2c/devices/8-0076/sfp'+str(port_num+1)+'_present'
54+
55+
try:
56+
file = open(presence_path)
57+
except IOError as e:
58+
print "Error: unable to open file: %s" % str(e)
59+
return False
60+
61+
value = int(file.readline().rstrip())
62+
63+
file.close()
64+
if value == 0:
65+
return True
66+
67+
return False
68+
69+
def get_low_power_mode(self, port_num):
70+
if port_num not in self.qsfp_ports:
71+
return False
72+
73+
lowpower_path = '/sys/bus/i2c/devices/8-0076/sfp'+str(port_num+1)+'_lowpower'
74+
75+
try:
76+
file = open(lowpower_path)
77+
except IOError as e:
78+
print "Error: unable to open file: %s" % str(e)
79+
return False
80+
81+
value = int(file.readline().rstrip())
82+
83+
file.close()
84+
if value == 1:
85+
return True
86+
87+
return False
88+
89+
def set_low_power_mode(self, port_num, lpmode):
90+
if port_num not in self.qsfp_ports:
91+
return False
92+
93+
lowpower_path = '/sys/bus/i2c/devices/8-0076/sfp'+str(port_num+1)+'_lowpower'
94+
95+
# LPMode is active high; set or clear the bit accordingly
96+
if lpmode is True:
97+
value = 1
98+
else:
99+
value = 0
100+
101+
try:
102+
file = open(lowpower_path, "r+")
103+
except IOError as e:
104+
print "Error: unable to open file: %s" % str(e)
105+
return False
106+
107+
file.seek(0)
108+
file.write(str(value))
109+
file.close()
110+
111+
return True
112+
113+
def reset(self, port_num):
114+
if port_num not in self.qsfp_ports:
115+
return False
116+
reset_path = '/sys/bus/i2c/devices/8-0076/sfp'+str(port_num+1)+'_reset'
117+
118+
try:
119+
file = open(reset_path, "r+")
120+
except IOError as e:
121+
print "Error: unable to open file: %s" % str(e)
122+
return False
123+
124+
file.seek(0)
125+
file.write(str(2))
126+
file.close()
127+
128+
# Sleep 1 second to allow it to settle
129+
time.sleep(1)
130+
131+
try:
132+
file = open(reset_path, "r+")
133+
except IOError as e:
134+
print "Error: unable to open file: %s" % str(e)
135+
return False
136+
137+
file.seek(0)
138+
file.write(str(1))
139+
file.close()
140+
141+
return True
142+
143+
def read_porttab_mappings(self, porttabfile):
144+
logical = []
145+
logical_to_bcm = {}
146+
logical_to_physical = {}
147+
physical_to_logical = {}
148+
last_fp_port_index = 0
149+
last_portname = ""
150+
first = 1
151+
port_pos_in_file = 0
152+
parse_fmt_port_config_ini = False
153+
154+
try:
155+
f = open(porttabfile)
156+
except:
157+
raise
158+
159+
parse_fmt_port_config_ini = (os.path.basename(porttabfile) == "port_config.ini")
160+
161+
# Read the porttab file and generate dicts
162+
# with mapping for future reference.
163+
# XXX: move the porttab
164+
# parsing stuff to a separate module, or reuse
165+
# if something already exists
166+
for line in f:
167+
line.strip()
168+
if re.search("^#", line) is not None:
169+
continue
170+
171+
# Parsing logic for 'port_config.ini' file
172+
if (parse_fmt_port_config_ini):
173+
# bcm_port is not explicitly listed in port_config.ini format
174+
# Currently we assume ports are listed in numerical order according to bcm_port
175+
# so we use the port's position in the file (zero-based) as bcm_port
176+
portname = line.split()[0]
177+
178+
bcm_port = str(port_pos_in_file)
179+
180+
if len(line.split()) >= 4:
181+
fp_port_index = int(line.split()[3])
182+
else:
183+
fp_port_index = portname.split("Ethernet").pop()
184+
fp_port_index = int(fp_port_index.split("s").pop(0))/4
185+
else: # Parsing logic for older 'portmap.ini' file
186+
(portname, bcm_port) = line.split("=")[1].split(",")[:2]
187+
188+
fp_port_index = portname.split("Ethernet").pop()
189+
fp_port_index = int(fp_port_index.split("s").pop(0))/4
190+
191+
if ((len(self.sfp_ports) > 0) and (fp_port_index not in self.sfp_ports)):
192+
continue
193+
194+
if first == 1:
195+
# Initialize last_[physical|logical]_port
196+
# to the first valid port
197+
last_fp_port_index = fp_port_index
198+
last_portname = portname
199+
first = 0
200+
201+
logical.append(portname)
202+
203+
logical_to_bcm[portname] = "xe" + bcm_port
204+
logical_to_physical[portname] = [fp_port_index]
205+
if physical_to_logical.get(fp_port_index) is None:
206+
physical_to_logical[fp_port_index] = [portname]
207+
else:
208+
physical_to_logical[fp_port_index].append(
209+
portname)
210+
211+
if (fp_port_index - last_fp_port_index) > 1:
212+
# last port was a gang port
213+
for p in range(last_fp_port_index+1, fp_port_index):
214+
logical_to_physical[last_portname].append(p)
215+
if physical_to_logical.get(p) is None:
216+
physical_to_logical[p] = [last_portname]
217+
else:
218+
physical_to_logical[p].append(last_portname)
219+
220+
last_fp_port_index = fp_port_index
221+
last_portname = portname
222+
223+
port_pos_in_file += 1
224+
225+
self.logical = logical
226+
self.logical_to_bcm = logical_to_bcm
227+
self.logical_to_physical = logical_to_physical
228+
self.physical_to_logical = physical_to_logical
229+
230+
"""
231+
print "logical: " + self.logical
232+
print "logical to bcm: " + self.logical_to_bcm
233+
print "logical to physical: " + self.logical_to_physical
234+
print "physical to logical: " + self.physical_to_logical
235+
"""
236+
237+
238+

0 commit comments

Comments
 (0)