[Mellanox] Re-initialize SFP object when detecting a new SFP insertion (#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.
This commit is contained in:
Junchao-Mellanox 2020-10-24 03:36:11 +08:00 committed by GitHub
parent 5bfe37ca42
commit 15c59e1d8c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 29 additions and 0 deletions

View File

@ -465,10 +465,29 @@ class Chassis(ChassisBase):
status = self.sfp_event.check_sfp_status(port_dict, timeout) status = self.sfp_event.check_sfp_status(port_dict, timeout)
if status: if status:
self.reinit_sfps(port_dict)
return True, {'sfp':port_dict} return True, {'sfp':port_dict}
else: else:
return True, {'sfp':{}} 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): def get_thermal_manager(self):
from .thermal_manager import ThermalManager from .thermal_manager import ThermalManager
return ThermalManager return ThermalManager

View File

@ -279,6 +279,9 @@ PORT_TYPE_MASK = 0xF0000000
NVE_MASK = PORT_TYPE_MASK & (PORT_TYPE_NVE << PORT_TYPE_OFFSET) NVE_MASK = PORT_TYPE_MASK & (PORT_TYPE_NVE << PORT_TYPE_OFFSET)
CPU_MASK = PORT_TYPE_MASK & (PORT_TYPE_CPU << 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 # Global logger class instance
logger = Logger() logger = Logger()
@ -316,6 +319,13 @@ class SFP(SfpBase):
self.sdk_handle = sdk_handle self.sdk_handle = sdk_handle
self.sdk_index = sfp_index 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): def get_presence(self):
""" """