Skip to content

Commit 8b7ae8c

Browse files
committed
[Edgecore][as7726/PDDF] Add needed api to sonic_platform
Signed-off-by: jostar-yang <[email protected]>
1 parent f3809c2 commit 8b7ae8c

10 files changed

Lines changed: 506 additions & 41 deletions

File tree

device/accton/x86_64-accton_as7726_32x-r0/pddf/pd-plugin.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@
3434
{
3535
"i2c":
3636
{
37-
"valmap": { "F2B":"EXHAUST", "B2F":"INTAKE" }
37+
"valmap": { "F2B":"exhaust", "B2F":"intake" }
3838
}
3939
},
4040

@@ -47,7 +47,7 @@
4747
{
4848
"i2c":
4949
{
50-
"valmap": {"1":"EXHAUST", "0":"INTAKE"}
50+
"valmap": {"1":"exhaust", "0":"intake"}
5151
}
5252
},
5353

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
{
2+
"services_to_ignore": [],
3+
"devices_to_ignore": [
4+
"asic",
5+
"psu.voltage",
6+
"psu.temperature",
7+
"PSU1_FAN1.speed",
8+
"PSU2_FAN1.speed"
9+
],
10+
"user_defined_checkers": [],
11+
"polling_interval": 60,
12+
"led_color": {
13+
"fault": "STATUS_LED_COLOR_AMBER",
14+
"normal": "STATUS_LED_COLOR_GREEN",
15+
"booting": "STATUS_LED_COLOR_OFF"
16+
}
17+
}

platform/broadcom/sonic-platform-modules-accton/as7726-32x/sonic_platform/chassis.py

Lines changed: 76 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -8,58 +8,59 @@
88

99
try:
1010
import sys
11-
import time
1211
from sonic_platform_pddf_base.pddf_chassis import PddfChassis
12+
from .event import SfpEvent
13+
from .helper import APIHelper
1314
except ImportError as e:
1415
raise ImportError(str(e) + "- required module not found")
1516

17+
NUM_COMPONENT = 6
18+
HOST_REBOOT_CAUSE_PATH = "/host/reboot-cause/"
19+
PMON_REBOOT_CAUSE_PATH = "/usr/share/sonic/platform/api_files/reboot-cause/"
20+
REBOOT_CAUSE_FILE = "reboot-cause.txt"
1621

1722
class Chassis(PddfChassis):
1823
"""
1924
PDDF Platform-specific Chassis class
2025
"""
2126

27+
SYSLED_DEV_NAME = "DIAG_LED"
28+
2229
def __init__(self, pddf_data=None, pddf_plugin_data=None):
2330
PddfChassis.__init__(self, pddf_data, pddf_plugin_data)
31+
self.__initialize_components()
32+
self._api_helper = APIHelper()
33+
self._sfpevent = SfpEvent(self.get_all_sfps())
34+
35+
36+
def __initialize_components(self):
37+
from sonic_platform.component import Component
38+
for index in range(NUM_COMPONENT):
39+
component = Component(index)
40+
self._component_list.append(component)
2441

2542
# Provide the functions/variables below for which implementation is to be overwritten
26-
sfp_change_event_data = {'valid': 0, 'last': 0, 'present': 0}
27-
def get_change_event(self, timeout=2000):
28-
now = time.time()
29-
port_dict = {}
30-
change_dict = {}
31-
change_dict['sfp'] = port_dict
32-
33-
if timeout < 1000:
34-
timeout = 1000
35-
timeout = timeout / float(1000) # Convert to secs
36-
37-
if now < (self.sfp_change_event_data['last'] + timeout) and self.sfp_change_event_data['valid']:
38-
return True, change_dict
39-
40-
bitmap = 0
41-
for i in range(34):
42-
modpres = self.get_sfp(i+1).get_presence()
43-
if modpres:
44-
bitmap = bitmap | (1 << i)
45-
46-
changed_ports = self.sfp_change_event_data['present'] ^ bitmap
47-
if changed_ports:
48-
for i in range(34):
49-
if (changed_ports & (1 << i)):
50-
if (bitmap & (1 << i)) == 0:
51-
port_dict[i+1] = '0'
52-
else:
53-
port_dict[i+1] = '1'
54-
55-
56-
# Update teh cache dict
57-
self.sfp_change_event_data['present'] = bitmap
58-
self.sfp_change_event_data['last'] = now
59-
self.sfp_change_event_data['valid'] = 1
60-
return True, change_dict
61-
else:
62-
return True, change_dict
43+
def get_change_event(self, timeout=0):
44+
return self._sfpevent.get_sfp_event(timeout)
45+
46+
def get_reboot_cause(self):
47+
"""
48+
Retrieves the cause of the previous reboot
49+
50+
Returns:
51+
A tuple (string, string) where the first element is a string
52+
containing the cause of the previous reboot. This string must be
53+
one of the predefined strings in this class. If the first string
54+
is "REBOOT_CAUSE_HARDWARE_OTHER", the second string can be used
55+
to pass a description of the reboot cause.
56+
"""
57+
58+
reboot_cause_path = (HOST_REBOOT_CAUSE_PATH + REBOOT_CAUSE_FILE)
59+
sw_reboot_cause = self._api_helper.read_txt_file(
60+
reboot_cause_path) or "Unknown"
61+
62+
63+
return ('REBOOT_CAUSE_NON_HARDWARE', sw_reboot_cause)
6364

6465

6566
def get_sfp(self, index):
@@ -84,3 +85,40 @@ def get_sfp(self, index):
8485
sys.stderr.write("SFP index {} out of range (1-{})\n".format(
8586
index, len(self._sfp_list)))
8687
return sfp
88+
89+
def get_position_in_parent(self):
90+
"""
91+
Retrieves 1-based relative physical position in parent device. If the agent cannot determine the parent-relative position
92+
for some reason, or if the associated value of entPhysicalContainedIn is '0', then the value '-1' is returned
93+
Returns:
94+
integer: The 1-based relative physical position in parent device or -1 if cannot determine the position
95+
"""
96+
return -1
97+
98+
def get_num_sfps(self):
99+
return len(self._sfp_list)
100+
101+
def is_replaceable(self):
102+
"""
103+
Indicate whether this device is replaceable.
104+
Returns:
105+
bool: True if it is replaceable.
106+
"""
107+
return False
108+
109+
110+
def initizalize_system_led(self):
111+
return
112+
113+
def get_status_led(self):
114+
return self.get_system_led(self.SYSLED_DEV_NAME)
115+
116+
def set_status_led(self, color):
117+
return self.set_system_led(self.SYSLED_DEV_NAME, color)
118+
119+
def get_port_or_cage_type(self, port):
120+
from sonic_platform_base.sfp_base import SfpBase
121+
if port in range(1, 32):
122+
return SfpBase.SFP_PORT_TYPE_BIT_QSFP | SfpBase.SFP_PORT_TYPE_BIT_QSFP_PLUS | SfpBase.SFP_PORT_TYPE_BIT_QSFP28
123+
else:
124+
return SfpBase.SFP_PORT_TYPE_BIT_SFP | SfpBase.SFP_PORT_TYPE_BIT_SFP_PLUS
Lines changed: 190 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,190 @@
1+
#############################################################################
2+
#
3+
# Component contains an implementation of SONiC Platform Base API and
4+
# provides the components firmware management function
5+
#
6+
#############################################################################
7+
8+
try:
9+
import subprocess
10+
from sonic_platform_base.component_base import ComponentBase
11+
except ImportError as e:
12+
raise ImportError(str(e) + "- required module not found")
13+
14+
CPLD_ADDR_MAPPING = {
15+
"CPLD1": ['11', '0x60'],
16+
"CPLD2": ['12', '0x62'],
17+
"CPLD3": ['13', '0x64'],
18+
"CPLD4": ['54', '0x66']
19+
}
20+
SYSFS_PATH = "/sys/bus/i2c/devices/"
21+
BIOS_VERSION_PATH = "/sys/class/dmi/id/bios_version"
22+
COMPONENT_LIST= [
23+
("CPLD1", "CPLD 1"),
24+
("CPLD2", "CPLD 2"),
25+
("CPLD3", "CPLD 3"),
26+
("CPLD4", "CPLD 4"),
27+
("CPLD5", "CPLD 5"),
28+
("BIOS", "Basic Input/Output System")
29+
30+
]
31+
32+
class Component(ComponentBase):
33+
"""Platform-specific Component class"""
34+
35+
DEVICE_TYPE = "component"
36+
37+
def __init__(self, component_index=0):
38+
self.index = component_index
39+
self.name = self.get_name()
40+
41+
def __run_command(self, command):
42+
# Run bash command and print output to stdout
43+
try:
44+
process = subprocess.Popen(
45+
shlex.split(command), stdout=subprocess.PIPE)
46+
while True:
47+
output = process.stdout.readline()
48+
if output == '' and process.poll() is not None:
49+
break
50+
rc = process.poll()
51+
if rc != 0:
52+
return False
53+
except Exception:
54+
return False
55+
return True
56+
57+
def __get_bios_version(self):
58+
# Retrieves the BIOS firmware version
59+
try:
60+
with open(BIOS_VERSION_PATH, 'r') as fd:
61+
bios_version = fd.read()
62+
return bios_version.strip()
63+
except Exception as e:
64+
return None
65+
66+
def __get_cpld_version(self):
67+
# Retrieves the CPLD firmware version
68+
cpld_version = dict()
69+
for cpld_name in CPLD_ADDR_MAPPING:
70+
cmd = "i2cget -f -y {0} {1} 0x1".format(CPLD_ADDR_MAPPING[cpld_name][0], CPLD_ADDR_MAPPING[cpld_name][1])
71+
status, value = subprocess.getstatusoutput(cmd)
72+
if not status:
73+
cpld_version_raw = value.rstrip()
74+
cpld_version[cpld_name] = "{}".format(int(cpld_version_raw,16))
75+
76+
return cpld_version
77+
78+
79+
def __get_cpld_cpu_version(self):
80+
try:
81+
cpu_version = dict()
82+
cmd = "i2cget -f -y 0 0x65 0x01"
83+
status, output1 = subprocess.getstatusoutput(cmd)
84+
if status == 0 :
85+
cpu_version = "{}".format(output1[2:])
86+
else :
87+
cpu_version = 'None'
88+
except Exception as e:
89+
cpu_version = 'None'
90+
91+
return cpu_version
92+
93+
def get_name(self):
94+
"""
95+
Retrieves the name of the component
96+
Returns:
97+
A string containing the name of the component
98+
"""
99+
return COMPONENT_LIST[self.index][0]
100+
101+
def get_description(self):
102+
"""
103+
Retrieves the description of the component
104+
Returns:
105+
A string containing the description of the component
106+
"""
107+
return COMPONENT_LIST[self.index][1]
108+
109+
def get_firmware_version(self):
110+
"""
111+
Retrieves the firmware version of module
112+
Returns:
113+
string: The firmware versions of the module
114+
"""
115+
fw_version = None
116+
117+
if self.name == "BIOS":
118+
fw_version = self.__get_bios_version()
119+
elif "CPLD5" in self.name:
120+
fw_version = self.__get_cpld_cpu_version()
121+
elif "CPLD" in self.name:
122+
cpld_version = self.__get_cpld_version()
123+
fw_version = cpld_version.get(self.name)
124+
125+
return fw_version
126+
127+
def install_firmware(self, image_path):
128+
"""
129+
Install firmware to module
130+
Args:
131+
image_path: A string, path to firmware image
132+
Returns:
133+
A boolean, True if install successfully, False if not
134+
"""
135+
raise NotImplementedError
136+
137+
def get_presence(self):
138+
"""
139+
Retrieves the presence of the device
140+
Returns:
141+
bool: True if device is present, False if not
142+
"""
143+
return True
144+
145+
def get_model(self):
146+
"""
147+
Retrieves the model number (or part number) of the device
148+
Returns:
149+
string: Model/part number of device
150+
"""
151+
return 'N/A'
152+
153+
def get_serial(self):
154+
"""
155+
Retrieves the serial number of the device
156+
Returns:
157+
string: Serial number of device
158+
"""
159+
return 'N/A'
160+
161+
def get_status(self):
162+
"""
163+
Retrieves the operational status of the device
164+
Returns:
165+
A boolean value, True if device is operating properly, False if not
166+
"""
167+
return True
168+
169+
def get_position_in_parent(self):
170+
"""
171+
Retrieves 1-based relative physical position in parent device.
172+
If the agent cannot determine the parent-relative position
173+
for some reason, or if the associated value of
174+
entPhysicalContainedIn is'0', then the value '-1' is returned
175+
Returns:
176+
integer: The 1-based relative physical position in parent device
177+
or -1 if cannot determine the position
178+
"""
179+
return -1
180+
181+
def is_replaceable(self):
182+
"""
183+
Indicate whether this device is replaceable.
184+
Returns:
185+
bool: True if it is replaceable.
186+
"""
187+
return False
188+
189+
190+

0 commit comments

Comments
 (0)