From 4b8ecfa9cf390cf3088ba11bc0664c705291df68 Mon Sep 17 00:00:00 2001 From: junchao Date: Fri, 16 Oct 2020 10:04:14 +0800 Subject: [PATCH] Re-initialize SFP object when detecting a new SFP insertion --- .../sonic_platform/chassis.py | 19 +++++++++++++++++++ .../mlnx-platform-api/sonic_platform/sfp.py | 10 ++++++++++ 2 files changed, 29 insertions(+) diff --git a/platform/mellanox/mlnx-platform-api/sonic_platform/chassis.py b/platform/mellanox/mlnx-platform-api/sonic_platform/chassis.py index 630b35903dff..2bbb0c64dacd 100644 --- a/platform/mellanox/mlnx-platform-api/sonic_platform/chassis.py +++ b/platform/mellanox/mlnx-platform-api/sonic_platform/chassis.py @@ -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 diff --git a/platform/mellanox/mlnx-platform-api/sonic_platform/sfp.py b/platform/mellanox/mlnx-platform-api/sonic_platform/sfp.py index 1d6a618a370b..e2460c444751 100644 --- a/platform/mellanox/mlnx-platform-api/sonic_platform/sfp.py +++ b/platform/mellanox/mlnx-platform-api/sonic_platform/sfp.py @@ -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() @@ -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):