From 5b6fdf244c4636d167d422a72ef46e9e6d9232b9 Mon Sep 17 00:00:00 2001 From: dflynn-Nokia <60479697+dflynn-Nokia@users.noreply.github.com> Date: Tue, 26 Oct 2021 21:57:56 -0400 Subject: [PATCH] [Nokia ixs7215] Platform API fixes (#9025) * [Nokia ixs7215] Platform API fixes This commit delivers the following fixes - Fix bug preventing access to second PSU eeprom - Fix bug preventing updates to front panel PSU status led - Fix SFP reset test case failure * Fix LGTM alert --- .../7215/scripts/nokia-7215init.sh | 2 +- .../7215/sonic_platform/eeprom.py | 12 +++- .../7215/sonic_platform/psu.py | 63 ++++++++++++++++++- .../7215/sonic_platform/sfp.py | 25 +++----- 4 files changed, 82 insertions(+), 20 deletions(-) diff --git a/platform/marvell-armhf/sonic-platform-nokia/7215/scripts/nokia-7215init.sh b/platform/marvell-armhf/sonic-platform-nokia/7215/scripts/nokia-7215init.sh index 3f23afe1fc..f8a7ad54b3 100755 --- a/platform/marvell-armhf/sonic-platform-nokia/7215/scripts/nokia-7215init.sh +++ b/platform/marvell-armhf/sonic-platform-nokia/7215/scripts/nokia-7215init.sh @@ -52,8 +52,8 @@ echo eeprom 0x55 > /sys/class/i2c-adapter/i2c-0/new_device echo eeprom 0x56 > /sys/class/i2c-adapter/i2c-0/new_device # Enumerate PSU eeprom devices +echo eeprom 0x50 > /sys/class/i2c-adapter/i2c-1/new_device echo eeprom 0x51 > /sys/class/i2c-adapter/i2c-1/new_device -echo eeprom 0x52 > /sys/class/i2c-adapter/i2c-1/new_device # Enable optical SFP Tx i2cset -y -m 0x0f 0 0x41 0x5 0x00 diff --git a/platform/marvell-armhf/sonic-platform-nokia/7215/sonic_platform/eeprom.py b/platform/marvell-armhf/sonic-platform-nokia/7215/sonic_platform/eeprom.py index d0e3e00fff..b3b31605b2 100644 --- a/platform/marvell-armhf/sonic-platform-nokia/7215/sonic_platform/eeprom.py +++ b/platform/marvell-armhf/sonic-platform-nokia/7215/sonic_platform/eeprom.py @@ -16,6 +16,7 @@ try: from sonic_platform_base.sonic_eeprom.eeprom_base import EepromDecoder from sonic_platform_base.sonic_eeprom.eeprom_tlvinfo import TlvInfoDecoder + from sonic_py_common import logger except ImportError as e: raise ImportError(str(e) + "- required module not found") @@ -27,6 +28,8 @@ psu_eeprom_format = [ ('Serial Number', 's', 11) ] +sonic_logger = logger.Logger('eeprom') + class Eeprom(TlvInfoDecoder): """Nokia platform-specific EEPROM class""" @@ -51,7 +54,7 @@ class Eeprom(TlvInfoDecoder): self.index = psu_index self.start_offset = 18 self.eeprom_path = self.I2C_DIR \ - + "i2c-1/1-005{}/eeprom".format(self.index) + + "i2c-1/1-005{}/eeprom".format(self.index - 1) self.format = psu_eeprom_format # Decode device eeprom as per specified format @@ -79,6 +82,7 @@ class Eeprom(TlvInfoDecoder): # Read System EEPROM as per ONIE TlvInfo EEPROM format. self.eeprom_data = self.read_eeprom() except Exception as e: + sonic_logger.log_warning("Unable to read system eeprom") self.base_mac = 'NA' self.serial_number = 'NA' self.part_number = 'NA' @@ -88,6 +92,7 @@ class Eeprom(TlvInfoDecoder): else: eeprom = self.eeprom_data if not self.is_valid_tlvinfo_header(eeprom): + sonic_logger.log_warning("Invalid system eeprom TLV header") self.base_mac = 'NA' self.serial_number = 'NA' self.part_number = 'NA' @@ -144,10 +149,12 @@ class Eeprom(TlvInfoDecoder): # Read Fan/PSU EEPROM as per the specified format. self.eeprom_data = EepromDecoder.read_eeprom(self) except Exception as e: + sonic_logger.log_warning("Unable to read device eeprom for PSU#{}".format(self.index)) return # Bail out if PSU eeprom unavailable if self.eeprom_data[0] == 255: + sonic_logger.log_warning("Uninitialized device eeprom for PSU#{}".format(self.index)) return (valid, data) = self._get_eeprom_field("Model") @@ -164,6 +171,7 @@ class Eeprom(TlvInfoDecoder): if valid: self.serial_number = data.decode() except Exception as e: + sonic_logger.log_warning("Unable to read serial# of PSU#{}".format(self.index)) return # Fan device eeproms use ONIE TLV format @@ -172,10 +180,12 @@ class Eeprom(TlvInfoDecoder): # Read Fan EEPROM as per ONIE TlvInfo EEPROM format. self.eeprom_data = self.read_eeprom() except Exception as e: + sonic_logger.log_warning("Unable to read device eeprom for Fan#{}".format(self.index)) return eeprom = self.eeprom_data if not self.is_valid_tlvinfo_header(eeprom): + sonic_logger.log_warning("Invalid device eeprom TLV header for Fan#{}".format(self.index)) return total_length = (eeprom[9] << 8) | eeprom[10] diff --git a/platform/marvell-armhf/sonic-platform-nokia/7215/sonic_platform/psu.py b/platform/marvell-armhf/sonic-platform-nokia/7215/sonic_platform/psu.py index 90025db7ff..6217555f0d 100644 --- a/platform/marvell-armhf/sonic-platform-nokia/7215/sonic_platform/psu.py +++ b/platform/marvell-armhf/sonic-platform-nokia/7215/sonic_platform/psu.py @@ -7,6 +7,7 @@ ######################################################################## try: + import os import sys from sonic_platform_base.psu_base import PsuBase from sonic_py_common import logger @@ -39,6 +40,34 @@ class Psu(PsuBase): # PSU eeprom self.eeprom = Eeprom(is_psu=True, psu_index=self.index) + def _write_sysfs_file(self, sysfs_file, value): + rv = 'ERR' + + if (not os.path.isfile(sysfs_file)): + return rv + try: + with open(sysfs_file, 'w') as fd: + rv = fd.write(str(value)) + except Exception as e: + rv = 'ERR' + + return rv + + def _read_sysfs_file(self, sysfs_file): + rv = 'ERR' + + if (not os.path.isfile(sysfs_file)): + return rv + try: + with open(sysfs_file, 'r') as fd: + rv = fd.read() + except Exception as e: + rv = 'ERR' + + rv = rv.rstrip('\r\n') + rv = rv.lstrip(" ") + return rv + def get_name(self): """ Retrieves the name of the device @@ -242,7 +271,20 @@ class Psu(PsuBase): Returns: A string, one of the predefined STATUS_LED_COLOR_* strings. """ - return self._psu_master_led_color + if (not os.path.isfile("/sys/class/gpio/psuLedGreen/value") or + not os.path.isfile("/sys/class/gpio/psuLedAmber/value")): + return None + + green = self._read_sysfs_file("/sys/class/gpio/psuLedGreen/value") + amber = self._read_sysfs_file("/sys/class/gpio/psuLedAmber/value") + if green == "ERR" or amber == "ERR": + return None + if green == "1": + return self.STATUS_LED_COLOR_GREEN + elif amber == "1": + return self.STATUS_LED_COLOR_AMBER + else: + return None def set_status_master_led(self, color): """ @@ -252,5 +294,22 @@ class Psu(PsuBase): bool: True if status LED state is set successfully, False if not """ - self._psu_master_led_color = color + if (not os.path.isfile("/sys/class/gpio/psuLedGreen/value") or + not os.path.isfile("/sys/class/gpio/psuLedAmber/value")): + return False + + if color == self.STATUS_LED_COLOR_GREEN: + rvg = self._write_sysfs_file("/sys/class/gpio/psuLedGreen/value", 1) + if rvg != "ERR": + rva = self._write_sysfs_file("/sys/class/gpio/psuLedAmber/value", 0) + elif color == self.STATUS_LED_COLOR_AMBER: + rvg = self._write_sysfs_file("/sys/class/gpio/psuLedGreen/value", 0) + if rvg != "ERR": + rva = self._write_sysfs_file("/sys/class/gpio/psuLedAmber/value", 1) + else: + return False + + if rvg == "ERR" or rva == "ERR": + return False + return True 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 244e48e1e6..d5f9cdb8e7 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 @@ -5,7 +5,6 @@ import os import sys -import time try: from sonic_platform_base.sfp_base import SfpBase @@ -795,28 +794,22 @@ class Sfp(SfpBase): Reset SFP. Returns: A boolean, True if successful, False if not - """ - if self.sfp_type == COPPER_TYPE: - return False - - self.tx_disable(True) - time.sleep(1) - self.tx_disable(False) - - return True + """ + # RJ45 and SFP ports not resettable + return False def tx_disable(self, tx_disable): """ - Disable SFP TX + 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 self.sfp_type == COPPER_TYPE: return False - + if smbus_present == 0: # if called from sfputil outside of pmon cmdstatus, register = cmd.getstatusoutput('sudo i2cget -y 0 0x41 0x5') if cmdstatus: @@ -834,8 +827,8 @@ class Sfp(SfpBase): if tx_disable == True: setbits = register | mask else: - setbits = register & ~mask - + 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: @@ -846,7 +839,7 @@ class Sfp(SfpBase): DEVICE_ADDRESS = 0x41 DEVICE_REG = 0x5 bus.write_byte_data(DEVICE_ADDRESS, DEVICE_REG, setbits) - + return True def tx_disable_channel(self, channel, disable):