Skip to content

Commit

Permalink
[Nokia ixs7215] Platform API fixes (#9025)
Browse files Browse the repository at this point in the history
* [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
  • Loading branch information
dflynn-Nokia authored and qiluo-msft committed Oct 27, 2021
1 parent f5fbb0b commit 5b6fdf2
Show file tree
Hide file tree
Showing 4 changed files with 82 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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")

Expand All @@ -27,6 +28,8 @@
('Serial Number', 's', 11)
]

sonic_logger = logger.Logger('eeprom')


class Eeprom(TlvInfoDecoder):
"""Nokia platform-specific EEPROM class"""
Expand All @@ -51,7 +54,7 @@ def __init__(self, is_psu=False, psu_index=0, is_fan=False, fan_index=0):
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
Expand Down Expand Up @@ -79,6 +82,7 @@ def _load_system_eeprom(self):
# 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'
Expand All @@ -88,6 +92,7 @@ def _load_system_eeprom(self):
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'
Expand Down Expand Up @@ -144,10 +149,12 @@ def _load_device_eeprom(self):
# 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")
Expand All @@ -164,6 +171,7 @@ def _load_device_eeprom(self):
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
Expand All @@ -172,10 +180,12 @@ def _load_device_eeprom(self):
# 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]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
########################################################################

try:
import os
import sys
from sonic_platform_base.psu_base import PsuBase
from sonic_py_common import logger
Expand Down Expand Up @@ -39,6 +40,34 @@ def __init__(self, psu_index):
# 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
Expand Down Expand Up @@ -242,7 +271,20 @@ def get_status_master_led(self):
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):
"""
Expand All @@ -252,5 +294,22 @@ def set_status_master_led(self, color):
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
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@

import os
import sys
import time

try:
from sonic_platform_base.sfp_base import SfpBase
Expand Down Expand Up @@ -795,28 +794,22 @@ def reset(self):
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:
Expand All @@ -834,8 +827,8 @@ def tx_disable(self, tx_disable):
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:
Expand All @@ -846,7 +839,7 @@ def tx_disable(self, tx_disable):
DEVICE_ADDRESS = 0x41
DEVICE_REG = 0x5
bus.write_byte_data(DEVICE_ADDRESS, DEVICE_REG, setbits)

return True

def tx_disable_channel(self, channel, disable):
Expand Down

0 comments on commit 5b6fdf2

Please sign in to comment.