-
Notifications
You must be signed in to change notification settings - Fork 1.5k
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
[Seastone] fix QSFP no change event issue for Seastone #13776
Open
qnos
wants to merge
1
commit into
sonic-net:master
Choose a base branch
from
qnos:cel-seastone-sfp-change-event-fix
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
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
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
66 changes: 55 additions & 11 deletions
66
device/celestica/x86_64-cel_seastone-r0/sonic_platform/event.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 |
---|---|---|
@@ -1,52 +1,96 @@ | ||
try: | ||
import select | ||
import time | ||
from .helper import APIHelper | ||
from sonic_py_common.logger import Logger | ||
except ImportError as e: | ||
raise ImportError(repr(e) + " - required module not found") | ||
|
||
|
||
QSFP_MODPRS_IRQ = '/sys/devices/platform/dx010_cpld/qsfp_modprs_irq' | ||
GPIO_SUS6 = "/sys/devices/platform/slx-ich.0/sci_int_gpio_sus6" | ||
QSFP_EVENT_POLLING_MODE = True | ||
|
||
|
||
class SfpEvent: | ||
''' Listen to insert/remove sfp events ''' | ||
|
||
QSFP_MODPRS_IRQ = '/sys/devices/platform/dx010_cpld/qsfp_modprs_irq' | ||
GPIO_SUS6 = "/sys/devices/platform/slx-ich.0/sci_int_gpio_sus6" | ||
|
||
def __init__(self, sfp_list): | ||
self._api_helper = APIHelper() | ||
self._sfp_list = sfp_list | ||
self._logger = Logger() | ||
|
||
sfp_change_event_data = {'valid': 0, 'last': 0, 'present': 0} | ||
|
||
def get_sfp_event(self, timeout): | ||
epoll = select.epoll() | ||
port_dict = {} | ||
|
||
if QSFP_EVENT_POLLING_MODE: | ||
# Using polling mode | ||
now = time.time() | ||
|
||
if timeout < 1000: | ||
timeout = 1000 | ||
timeout = timeout / float(1000) # Convert to secs | ||
|
||
if now < (self.sfp_change_event_data['last'] + timeout) \ | ||
and self.sfp_change_event_data['valid']: | ||
return True, port_dict | ||
|
||
bitmap = 0 | ||
for sfp in self._sfp_list: | ||
modpres = sfp.get_presence() | ||
index = sfp.get_index() | ||
if modpres: | ||
bitmap = bitmap | (1 << index) | ||
|
||
changed_ports = self.sfp_change_event_data['present'] ^ bitmap | ||
if changed_ports: | ||
for sfp in self._sfp_list: | ||
index = sfp.get_index() | ||
if changed_ports & (1 << index): | ||
if (bitmap & (1 << index)) == 0: | ||
port_dict[str(index + 1)] = '0' | ||
else: | ||
port_dict[str(index + 1)] = '1' | ||
|
||
# Update the cache dict | ||
self.sfp_change_event_data['present'] = bitmap | ||
self.sfp_change_event_data['last'] = now | ||
self.sfp_change_event_data['valid'] = 1 | ||
|
||
return True, port_dict | ||
|
||
# SFP event from GPIO interrupt pin | ||
epoll = select.epoll() | ||
timeout_sec = timeout/1000 | ||
|
||
try: | ||
# We get notified when there is an SCI interrupt from GPIO SUS6 | ||
fd = open(self.GPIO_SUS6, "r") | ||
fd = open(GPIO_SUS6, "r") | ||
fd.read() | ||
|
||
epoll.register(fd.fileno(), select.EPOLLIN & select.EPOLLET) | ||
events = epoll.poll(timeout=timeout_sec if timeout != 0 else -1) | ||
if events: | ||
# Read the QSFP ABS interrupt & status registers | ||
port_changes = self._api_helper.read_one_line_file( | ||
self.QSFP_MODPRS_IRQ) | ||
QSFP_MODPRS_IRQ) | ||
changes = int(port_changes, 16) | ||
for sfp in self._sfp_list: | ||
change = (changes >> sfp.port_num-1) & 1 | ||
index = sfp.get_index() | ||
change = (changes >> index) & 1 | ||
if change == 1: | ||
port_dict[str(sfp.port_num)] = str( | ||
port_dict[str(index + 1)] = str( | ||
int(sfp.get_presence())) | ||
|
||
return port_dict | ||
return True, port_dict | ||
except Exception as e: | ||
self._logger.log_error("Failed to detect SfpEvent - " + repr(e)) | ||
return False | ||
return False, port_dict | ||
|
||
finally: | ||
fd.close() | ||
epoll.close() | ||
|
||
return False | ||
return False, port_dict |
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
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.
We always use polling mode for seastones?