Skip to content
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
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -182,8 +182,8 @@ def get_change_event(self, timeout=0):
if not self.sfp_module_initialized:
self.__initialize_sfp()

sfp_event = SfpEvent(self._sfp_list).get_sfp_event(timeout)
if sfp_event:
succeed, sfp_event = SfpEvent(self._sfp_list).get_sfp_event(timeout)
if succeed:
return True, {'sfp': sfp_event}

return False, {'sfp': {}}
Expand Down
66 changes: 55 additions & 11 deletions device/celestica/x86_64-cel_seastone-r0/sonic_platform/event.py
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
Copy link
Contributor

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?



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
8 changes: 8 additions & 0 deletions device/celestica/x86_64-cel_seastone-r0/sonic_platform/sfp.py
Original file line number Diff line number Diff line change
Expand Up @@ -2195,6 +2195,14 @@ def get_position_in_parent(self):
"""
return 0

def get_index(self):
"""
Retrieves current sfp index
Returns:
A int value, sfp index
"""
return self._index

def is_replaceable(self):
"""
Retrieves if replaceable
Expand Down