Skip to content

Commit

Permalink
[Mellanox] Re-initialize SFP object when detecting a new SFP insertion (
Browse files Browse the repository at this point in the history
sonic-net#5695)

When detecting a new SFP insertion, read its SFP type and DOM capability from EEPROM again.

SFP object will be initialized to a certain type even if no SFP present. A case could be:

1. A SFP object is initialized to QSFP type by default when there is no SFP present
2. User insert a SFP with an adapter to this QSFP port
3. The SFP object fail to read EEPROM because it still treats itself as QSFP.

This PR fixes this issue.
  • Loading branch information
Junchao-Mellanox authored and santhosh-kt committed Feb 25, 2021
1 parent 98b61e2 commit f554f70
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 0 deletions.
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 @@ -465,10 +465,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 @@ -279,6 +279,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 Down Expand Up @@ -316,6 +319,13 @@ def __init__(self, sfp_index, sfp_type, sdk_handle):
self.sdk_handle = sdk_handle
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()

def get_presence(self):
"""
Expand Down

0 comments on commit f554f70

Please sign in to comment.