From 587b14a3bf4a043941e2bcbaee8eafad6aa3d2a2 Mon Sep 17 00:00:00 2001 From: Andriy Moroz Date: Fri, 20 Oct 2017 04:36:25 +0300 Subject: [PATCH] [Mellanox]: Add get_presence implementation for SFP on Mellanox platforms (#1056) Signed-off-by: Andriy Moroz --- .../x86_64-mlnx_msn2410-r0/plugins/sfputil.py | 17 ++++++++++++++++- .../x86_64-mlnx_msn2700-r0/plugins/sfputil.py | 17 ++++++++++++++++- .../x86_64-mlnx_msn2740-r0/plugins/sfputil.py | 17 ++++++++++++++++- 3 files changed, 48 insertions(+), 3 deletions(-) diff --git a/device/mellanox/x86_64-mlnx_msn2410-r0/plugins/sfputil.py b/device/mellanox/x86_64-mlnx_msn2410-r0/plugins/sfputil.py index db71cb4235..0d7870b785 100644 --- a/device/mellanox/x86_64-mlnx_msn2410-r0/plugins/sfputil.py +++ b/device/mellanox/x86_64-mlnx_msn2410-r0/plugins/sfputil.py @@ -46,8 +46,23 @@ class SfpUtil(SfpUtilBase): SfpUtilBase.__init__(self) def get_presence(self, port_num): + # Check for invalid port_num + if port_num < self.port_start or port_num > self.port_end: + return False - raise NotImplementedError + try: + reg_file = open("/bsp/qsfp/qsfp%d_status" % (port_num+1)) + except IOError as e: + print "Error: unable to open file: %s" % str(e) + return False + + content = reg_file.readline().rstrip() + + # content is a string with the qsfp status + if content == "good": + return True + + return False def get_low_power_mode(self, port_num): diff --git a/device/mellanox/x86_64-mlnx_msn2700-r0/plugins/sfputil.py b/device/mellanox/x86_64-mlnx_msn2700-r0/plugins/sfputil.py index b746af2199..b768cc4402 100644 --- a/device/mellanox/x86_64-mlnx_msn2700-r0/plugins/sfputil.py +++ b/device/mellanox/x86_64-mlnx_msn2700-r0/plugins/sfputil.py @@ -46,8 +46,23 @@ class SfpUtil(SfpUtilBase): SfpUtilBase.__init__(self) def get_presence(self, port_num): + # Check for invalid port_num + if port_num < self.port_start or port_num > self.port_end: + return False - raise NotImplementedError + try: + reg_file = open("/bsp/qsfp/qsfp%d_status" % (port_num+1)) + except IOError as e: + print "Error: unable to open file: %s" % str(e) + return False + + content = reg_file.readline().rstrip() + + # content is a string with the qsfp status + if content == "good": + return True + + return False def get_low_power_mode(self, port_num): diff --git a/device/mellanox/x86_64-mlnx_msn2740-r0/plugins/sfputil.py b/device/mellanox/x86_64-mlnx_msn2740-r0/plugins/sfputil.py index b746af2199..b768cc4402 100644 --- a/device/mellanox/x86_64-mlnx_msn2740-r0/plugins/sfputil.py +++ b/device/mellanox/x86_64-mlnx_msn2740-r0/plugins/sfputil.py @@ -46,8 +46,23 @@ class SfpUtil(SfpUtilBase): SfpUtilBase.__init__(self) def get_presence(self, port_num): + # Check for invalid port_num + if port_num < self.port_start or port_num > self.port_end: + return False - raise NotImplementedError + try: + reg_file = open("/bsp/qsfp/qsfp%d_status" % (port_num+1)) + except IOError as e: + print "Error: unable to open file: %s" % str(e) + return False + + content = reg_file.readline().rstrip() + + # content is a string with the qsfp status + if content == "good": + return True + + return False def get_low_power_mode(self, port_num):