Skip to content

Commit 7fc76b9

Browse files
[sonic_pcie] Add get_pcie_aer_stats and its common implementation (#144)
Introduce a new platform API get_pcie_aer_stats in class PcieBase for retrieving AER stats of a PCIe device. Add common implementation of get_pcie_aer_stats in class PcieUtil Ref: sonic-net/SONiC#702
1 parent 8664efc commit 7fc76b9

File tree

2 files changed

+101
-41
lines changed

2 files changed

+101
-41
lines changed
Lines changed: 65 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -1,41 +1,65 @@
1-
#
2-
# pcie_base.py
3-
#
4-
# Abstract base class for implementing platform-specific
5-
# PCIE functionality for SONiC
6-
#
7-
8-
try:
9-
import abc
10-
except ImportError as e:
11-
raise ImportError (str(e) + " - required module not found")
12-
13-
class PcieBase(object):
14-
def __init__(self, path):
15-
"""
16-
Constructor
17-
18-
Args:
19-
pcieutil file and config file path
20-
"""
21-
22-
@abc.abstractmethod
23-
def get_pcie_device(self):
24-
"""
25-
get current device pcie info
26-
27-
Returns:
28-
A list including pcie device info
29-
"""
30-
return []
31-
32-
33-
@abc.abstractmethod
34-
def get_pcie_check(self):
35-
"""
36-
Check Pcie device with config file
37-
38-
Returns:
39-
A list including pcie device and test result info
40-
"""
41-
return []
1+
#
2+
# pcie_base.py
3+
#
4+
# Abstract base class for implementing platform-specific
5+
# PCIE functionality for SONiC
6+
#
7+
8+
try:
9+
import abc
10+
except ImportError as e:
11+
raise ImportError(str(e) + " - required module not found")
12+
13+
14+
class PcieBase(object):
15+
def __init__(self, path):
16+
"""
17+
Constructor
18+
19+
Args:
20+
pcieutil file and config file path
21+
"""
22+
23+
@abc.abstractmethod
24+
def get_pcie_device(self):
25+
"""
26+
get current device pcie info
27+
28+
Returns:
29+
A list including pcie device info
30+
"""
31+
return []
32+
33+
@abc.abstractmethod
34+
def get_pcie_check(self):
35+
"""
36+
Check Pcie device with config file
37+
38+
Returns:
39+
A list including pcie device and test result info
40+
"""
41+
return []
42+
43+
@abc.abstractmethod
44+
def get_pcie_aer_stats(self, domain, bus, dev, fn):
45+
"""
46+
Returns a nested dictionary containing the AER stats belonging to a
47+
PCIe device
48+
49+
Args:
50+
domain, bus, dev, fn: Domain, bus, device, function of the PCIe
51+
device respectively
52+
53+
Returns:
54+
A nested dictionary where key is severity 'correctable', 'fatal' or
55+
'non_fatal', value is a dictionary of key, value pairs in the format:
56+
{'AER Error type': Error count}
57+
58+
Ex. {'correctable': {'BadDLLP': 0, 'BadTLP': 0},
59+
'fatal': {'RxOF': 0, 'MalfTLP': 0},
60+
'non_fatal': {'RxOF': 0, 'MalfTLP': 0}}
61+
62+
For PCIe devices that do not support AER, the value for each
63+
severity key is an empty dictionary.
64+
"""
65+
return {}

sonic_platform_base/sonic_pcie/pcie_common.py

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,42 @@ def get_pcie_check(self):
9898
item_conf["result"] = "Failed"
9999
return self.confInfo
100100

101+
# return AER stats of PCIe device
102+
def get_pcie_aer_stats(self, domain=0, bus=0, device=0, func=0):
103+
aer_stats = {'correctable': {}, 'fatal': {}, 'non_fatal': {}}
104+
dev_path = os.path.join('/sys/bus/pci/devices', '%04x:%02x:%02x.%d' % (domain, bus, device, func))
105+
106+
# construct AER sysfs filepath
107+
correctable_path = os.path.join(dev_path, "aer_dev_correctable")
108+
fatal_path = os.path.join(dev_path, "aer_dev_fatal")
109+
non_fatal_path = os.path.join(dev_path, "aer_dev_nonfatal")
110+
111+
# update AER-correctable fields
112+
if os.path.isfile(correctable_path):
113+
with open(correctable_path, 'r') as fh:
114+
lines = fh.readlines()
115+
for line in lines:
116+
correctable_field, value = line.split()
117+
aer_stats['correctable'][correctable_field] = value
118+
119+
# update AER-Fatal fields
120+
if os.path.isfile(fatal_path):
121+
with open(fatal_path, 'r') as fh:
122+
lines = fh.readlines()
123+
for line in lines:
124+
fatal_field, value = line.split()
125+
aer_stats['fatal'][fatal_field] = value
126+
127+
# update AER-Non Fatal fields
128+
if os.path.isfile(non_fatal_path):
129+
with open(non_fatal_path, 'r') as fh:
130+
lines = fh.readlines()
131+
for line in lines:
132+
non_fatal_field, value = line.split()
133+
aer_stats['non_fatal'][non_fatal_field] = value
134+
135+
return aer_stats
136+
101137
# generate the config file with current pci device
102138
def dump_conf_yaml(self):
103139
curInfo = self.get_pcie_device()

0 commit comments

Comments
 (0)