-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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
[Mellanox][pcied] Ignore bus on pcie.yaml for Mellanox switches #8063
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
69 changes: 69 additions & 0 deletions
69
platform/mellanox/mlnx-platform-api/sonic_platform/pcie.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
######################################################################## | ||
# | ||
# Copyright (C) 2021, NVIDIA CORPORATION & AFFILIATES. All rights reserved. | ||
# | ||
# Module contains a platform specific implementation of SONiC Platform | ||
# Base PCIe class | ||
# | ||
######################################################################## | ||
import os | ||
import re | ||
|
||
try: | ||
from sonic_platform_base.sonic_pcie.pcie_common import PcieUtil | ||
except ImportError as e: | ||
raise ImportError(str(e) + "- required module not found") | ||
|
||
SYSFS_PCI_DEVICE_PATH = '/sys/bus/pci/devices/' | ||
|
||
|
||
class Pcie(PcieUtil): | ||
# check the current PCIe device with config file and return the result | ||
# use bus from _device_id_to_bus_map instead of from yaml file | ||
def get_pcie_check(self): | ||
self.load_config_file() | ||
for item_conf in self.confInfo: | ||
id_conf = item_conf["id"] | ||
dev_conf = item_conf["dev"] | ||
fn_conf = item_conf["fn"] | ||
bus_conf = self._device_id_to_bus_map.get(id_conf) | ||
if bus_conf and self.check_pcie_sysfs(bus=int(bus_conf, base=16), device=int(dev_conf, base=16), | ||
func=int(fn_conf, base=16)): | ||
item_conf["result"] = "Passed" | ||
else: | ||
item_conf["result"] = "Failed" | ||
return self.confInfo | ||
|
||
# Create | ||
def _create_device_id_to_bus_map(self): | ||
self._device_id_to_bus_map = {} | ||
self.load_config_file() | ||
device_folders = os.listdir(SYSFS_PCI_DEVICE_PATH) | ||
for folder in device_folders: | ||
# For each folder in the sysfs tree we check if it matches the normal PCIe device folder pattern, | ||
# If match we add the device id from the device file and the bus from the folder name to the map | ||
# | ||
# Example for device folder name: 0000:ff:0b.1 | ||
# | ||
# The folder name is built from: | ||
# 4 hex digit of domain | ||
# colon ':' | ||
# 2 hex digit of bus - this is what we are looking for | ||
# colon ':' | ||
# 2 hex digit of id | ||
# dot '.' | ||
# 1 digit of fn | ||
pattern_for_device_folder = re.search('....:(..):..\..', folder) | ||
if pattern_for_device_folder: | ||
bus = pattern_for_device_folder.group(1) | ||
with open(os.path.join('/sys/bus/pci/devices', folder, 'device'), 'r') as device_file: | ||
# The 'device' file contain an hex repesantaion of the id key in the yaml file. | ||
# Example of the file contact: | ||
# 0x6fe2 | ||
# We will strip the new line character, and remove the 0x prefix that is not needed. | ||
device_id = device_file.read().strip().replace('0x', '') | ||
self._device_id_to_bus_map[device_id] = bus | ||
|
||
def __init__(self, platform_path): | ||
PcieUtil.__init__(self, platform_path) | ||
self._create_device_id_to_bus_map() |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This regex is hard to read. Could you give some examples and explanations?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
An example for a dir name is: 0000:ff:0b.1
The name of the folder is created from: {4 digit of domain - always 0}:{2 hex digit of bus}:{2 hex digit - dev}.{fn}
You can see this pattern of the folder name also here:
https://github.com/Azure/sonic-platform-common/blob/87c81de7193ee68568543d982fb8ba38f5e4ad07/sonic_platform_base/sonic_pcie/pcie_common.py#L106
I use this regex to look for the bus (in the above example 'ff').
The dots match any character, so I am checking if the folder that starts with 4 characters (domain), colon, 2 characters of bus (they are in parentheses to create the group I am looking for), a colon, 2 characters of dev, a dot, and the fn.
I tried to create the simplest regex, but I would be glad to hear if you have a different suggestion