From 03ef27531408fbcf9060b62f24ae8d968085353f Mon Sep 17 00:00:00 2001 From: carl-nokia <63672637+carl-nokia@users.noreply.github.com> Date: Fri, 13 Aug 2021 06:27:06 -0400 Subject: [PATCH] [Nokia ixs7215] sfputil support + component tests (#8445) Deliver sfputil support for sfputil show eeprom and sfputil reset along with some component test case fixes Co-authored-by: Carl Keene --- .../plugins/sfputil.py | 22 ++++++- .../7215/sonic_platform/component.py | 49 ++++++++++++++++ .../7215/sonic_platform/sfp.py | 57 ++++++++++++------- 3 files changed, 106 insertions(+), 22 deletions(-) diff --git a/device/nokia/armhf-nokia_ixs7215_52x-r0/plugins/sfputil.py b/device/nokia/armhf-nokia_ixs7215_52x-r0/plugins/sfputil.py index 1ca3b9ec6f..3280ffdc92 100755 --- a/device/nokia/armhf-nokia_ixs7215_52x-r0/plugins/sfputil.py +++ b/device/nokia/armhf-nokia_ixs7215_52x-r0/plugins/sfputil.py @@ -1,4 +1,5 @@ try: + import glob import sonic_platform.platform import sonic_platform.chassis from sonic_sfp.sfputilbase import SfpUtilBase @@ -14,6 +15,12 @@ class SfpUtil(SfpUtilBase): ports_in_block = 4 _port_to_eeprom_mapping = {} + port_to_i2c_mapping = { + 49: 2, + 50: 3, + 51: 4, + 52: 5 + } _changed_ports = [0, 0, 0, 0] @property @@ -33,10 +40,21 @@ class SfpUtil(SfpUtilBase): return self._port_to_eeprom_mapping def __init__(self): - # print " SfpUtil(SfpUtilBase) re-directed to chassis PMON 2.0 " + # Mux Ordering + mux_dev = sorted(glob.glob("/sys/class/i2c-adapter/i2c-0/i2c-[0-9]")) + eeprom_path = "/sys/class/i2c-adapter/i2c-{0}/{0}-0050/eeprom" + y = 0 + for x in range(self.port_start, self.port_end + 1): + mux_dev_num = mux_dev[y] + self.port_to_i2c_mapping[x] = mux_dev_num[-1] + y = y + 1 + port_eeprom_path = eeprom_path.format(self.port_to_i2c_mapping[x]) + self.port_to_eeprom_mapping[x] = port_eeprom_path + self._port_to_eeprom_mapping[x] = port_eeprom_path SfpUtilBase.__init__(self) - self.chassis = sonic_platform.platform.Platform().get_chassis() + self.chassis = sonic_platform.platform.Platform().get_chassis() + def reset(self, port_num): # print " SfpUtil(SfpUtilBase) re-directed to chassis PMON 2.0 " if self.chassis is not None: diff --git a/platform/marvell-armhf/sonic-platform-nokia/7215/sonic_platform/component.py b/platform/marvell-armhf/sonic-platform-nokia/7215/sonic_platform/component.py index 1c219d7920..134856ea42 100644 --- a/platform/marvell-armhf/sonic-platform-nokia/7215/sonic_platform/component.py +++ b/platform/marvell-armhf/sonic-platform-nokia/7215/sonic_platform/component.py @@ -75,6 +75,55 @@ class Component(ComponentBase): """ return self.name + def get_model(self): + """ + Retrieves the part number of the component + Returns: + string: Part number of component + """ + return 'NA' + + def get_serial(self): + """ + Retrieves the serial number of the component + Returns: + string: Serial number of component + """ + return 'NA' + + def get_presence(self): + """ + Retrieves the presence of the component + Returns: + bool: True if present, False if not + """ + return True + + def get_status(self): + """ + Retrieves the operational status of the component + Returns: + bool: True if component is operating properly, False if not + """ + return True + + def get_position_in_parent(self): + """ + Retrieves 1-based relative physical position in parent device. + Returns: + integer: The 1-based relative physical position in parent + device or -1 if cannot determine the position + """ + return -1 + + def is_replaceable(self): + """ + Indicate whether component is replaceable. + Returns: + bool: True if it is replaceable. + """ + return False + def get_description(self): """ Retrieves the description of the component diff --git a/platform/marvell-armhf/sonic-platform-nokia/7215/sonic_platform/sfp.py b/platform/marvell-armhf/sonic-platform-nokia/7215/sonic_platform/sfp.py index 57fcde1614..ead408b41b 100644 --- a/platform/marvell-armhf/sonic-platform-nokia/7215/sonic_platform/sfp.py +++ b/platform/marvell-armhf/sonic-platform-nokia/7215/sonic_platform/sfp.py @@ -777,42 +777,59 @@ class Sfp(SfpBase): def reset(self): """ - Reset SFP and return all user module settings to their default srate. + Reset SFP. Returns: A boolean, True if successful, False if not - """ + """ if self.sfp_type == COPPER_TYPE: return False - path = "/sys/class/i2c-adapter/i2c-{0}/{0}-0050/sfp_port_reset" - port_ps = path.format(self.port_to_i2c_mapping) - - try: - reg_file = open(port_ps, 'w') - except IOError as e: - # print "Error: unable to open file: %s" % str(e) - return False - - # toggle reset - reg_file.seek(0) - reg_file.write('1') + self.tx_disable(True) time.sleep(1) - reg_file.seek(0) - reg_file.write('0') - reg_file.close() + self.tx_disable(False) + return True def tx_disable(self, tx_disable): """ - Disable SFP TX for all channels + Disable SFP TX Args: tx_disable : A Boolean, True to enable tx_disable mode, False to disable tx_disable mode. - Returns: + Returns: A boolean, True if tx_disable is set successfully, False if not """ + if smbus_present == 0: # if called from sfputil outside of pmon + cmdstatus, register = cmd.getstatusoutput('sudo i2cget -y 0 0x41 0x5') + if cmdstatus: + sonic_logger.log_warning("sfp cmdstatus i2c get failed %s" % register ) + return False + register = int(register, 16) + else: + bus = smbus.SMBus(0) + DEVICE_ADDRESS = 0x41 + DEVICE_REG = 0x5 + register = bus.read_byte_data(DEVICE_ADDRESS, DEVICE_REG) - return NotImplementedError + pos = [1, 2, 4, 8] + mask = pos[self.index-SFP_PORT_START] + if tx_disable == True: + setbits = register | mask + else: + setbits = register & ~mask + + if smbus_present == 0: # if called from sfputil outside of pmon + cmdstatus, output = cmd.getstatusoutput('sudo i2cset -y -m 0x0f 0 0x41 0x5 %d' % setbits) + if cmdstatus: + sonic_logger.log_warning("sfp cmdstatus i2c write failed %s" % output ) + return False + else: + bus = smbus.SMBus(0) + DEVICE_ADDRESS = 0x41 + DEVICE_REG = 0x5 + bus.write_byte_data(DEVICE_ADDRESS, DEVICE_REG, setbits) + + return True def tx_disable_channel(self, channel, disable): """