From 15c59e1d8c8a60306f5f899c716ea2cd8ceed7ba Mon Sep 17 00:00:00 2001 From: Junchao-Mellanox <57339448+Junchao-Mellanox@users.noreply.github.com> Date: Sat, 24 Oct 2020 03:36:11 +0800 Subject: [PATCH] [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. --- .../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 5ad205674b..1682d4649d 100644 --- a/platform/mellanox/mlnx-platform-api/sonic_platform/chassis.py +++ b/platform/mellanox/mlnx-platform-api/sonic_platform/chassis.py @@ -465,10 +465,29 @@ class Chassis(ChassisBase): 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 47a42bf8f8..4814055ca5 100644 --- a/platform/mellanox/mlnx-platform-api/sonic_platform/sfp.py +++ b/platform/mellanox/mlnx-platform-api/sonic_platform/sfp.py @@ -279,6 +279,9 @@ PORT_TYPE_MASK = 0xF0000000 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() @@ -316,6 +319,13 @@ class SFP(SfpBase): 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): """