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

[Mellanox] Re-initialize SFP object when detecting a new SFP insertion #5695

Merged
merged 1 commit into from
Oct 23, 2020
Merged
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
19 changes: 19 additions & 0 deletions platform/mellanox/mlnx-platform-api/sonic_platform/chassis.py
Original file line number Diff line number Diff line change
Expand Up @@ -455,10 +455,29 @@ def get_change_event(self, timeout=0):
status = self.sfp_event.check_sfp_status(port_dict, timeout)

if status:
self.reinit_sfps(port_dict)
return True, {'sfp':port_dict}
else:
return True, {'sfp':{}}

def reinit_sfps(self, port_dict):
"""
Re-initialize SFP if there is any newly inserted SFPs
:param port_dict: SFP event data
:return:
"""
# SFP not initialize yet, do nothing
if not self.sfp_module_initialized:
return

from . import sfp
for index, status in port_dict.items():
if status == sfp.SFP_STATUS_INSERTED:
try:
self.get_sfp(index).reinit()
except Exception as e:
logger.log_error("Fail to re-initialize SFP {} - {}".format(index, repr(e)))

def get_thermal_manager(self):
from .thermal_manager import ThermalManager
return ThermalManager
Expand Down
10 changes: 10 additions & 0 deletions platform/mellanox/mlnx-platform-api/sonic_platform/sfp.py
Original file line number Diff line number Diff line change
Expand Up @@ -280,6 +280,9 @@
NVE_MASK = PORT_TYPE_MASK & (PORT_TYPE_NVE << PORT_TYPE_OFFSET)
CPU_MASK = PORT_TYPE_MASK & (PORT_TYPE_CPU << PORT_TYPE_OFFSET)

# parameters for SFP presence
SFP_STATUS_INSERTED = '1'

# Global logger class instance
logger = Logger()

Expand All @@ -296,6 +299,13 @@ def __init__(self, sfp_index, sfp_type):
self.sdk_handle = None
self.sdk_index = sfp_index

def reinit(self):
"""
Re-initialize this SFP object when a new SFP inserted
:return:
"""
self._detect_sfp_type(self.sfp_type)
self._dom_capability_detect()

#SDK initializing stuff
def _initialize_sdk_handle(self):
Expand Down