[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
This commit is contained in:
parent
030551ba27
commit
33fce6afd1
@ -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
|
echo eeprom 0x56 > /sys/class/i2c-adapter/i2c-0/new_device
|
||||||
|
|
||||||
# Enumerate PSU eeprom devices
|
# 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 0x51 > /sys/class/i2c-adapter/i2c-1/new_device
|
||||||
echo eeprom 0x52 > /sys/class/i2c-adapter/i2c-1/new_device
|
|
||||||
|
|
||||||
# Enable optical SFP Tx
|
# Enable optical SFP Tx
|
||||||
i2cset -y -m 0x0f 0 0x41 0x5 0x00
|
i2cset -y -m 0x0f 0 0x41 0x5 0x00
|
||||||
|
@ -16,6 +16,7 @@
|
|||||||
try:
|
try:
|
||||||
from sonic_platform_base.sonic_eeprom.eeprom_base import EepromDecoder
|
from sonic_platform_base.sonic_eeprom.eeprom_base import EepromDecoder
|
||||||
from sonic_platform_base.sonic_eeprom.eeprom_tlvinfo import TlvInfoDecoder
|
from sonic_platform_base.sonic_eeprom.eeprom_tlvinfo import TlvInfoDecoder
|
||||||
|
from sonic_py_common import logger
|
||||||
except ImportError as e:
|
except ImportError as e:
|
||||||
raise ImportError(str(e) + "- required module not found")
|
raise ImportError(str(e) + "- required module not found")
|
||||||
|
|
||||||
@ -27,6 +28,8 @@ psu_eeprom_format = [
|
|||||||
('Serial Number', 's', 11)
|
('Serial Number', 's', 11)
|
||||||
]
|
]
|
||||||
|
|
||||||
|
sonic_logger = logger.Logger('eeprom')
|
||||||
|
|
||||||
|
|
||||||
class Eeprom(TlvInfoDecoder):
|
class Eeprom(TlvInfoDecoder):
|
||||||
"""Nokia platform-specific EEPROM class"""
|
"""Nokia platform-specific EEPROM class"""
|
||||||
@ -51,7 +54,7 @@ class Eeprom(TlvInfoDecoder):
|
|||||||
self.index = psu_index
|
self.index = psu_index
|
||||||
self.start_offset = 18
|
self.start_offset = 18
|
||||||
self.eeprom_path = self.I2C_DIR \
|
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
|
self.format = psu_eeprom_format
|
||||||
|
|
||||||
# Decode device eeprom as per specified format
|
# Decode device eeprom as per specified format
|
||||||
@ -79,6 +82,7 @@ class Eeprom(TlvInfoDecoder):
|
|||||||
# Read System EEPROM as per ONIE TlvInfo EEPROM format.
|
# Read System EEPROM as per ONIE TlvInfo EEPROM format.
|
||||||
self.eeprom_data = self.read_eeprom()
|
self.eeprom_data = self.read_eeprom()
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
|
sonic_logger.log_warning("Unable to read system eeprom")
|
||||||
self.base_mac = 'NA'
|
self.base_mac = 'NA'
|
||||||
self.serial_number = 'NA'
|
self.serial_number = 'NA'
|
||||||
self.part_number = 'NA'
|
self.part_number = 'NA'
|
||||||
@ -88,6 +92,7 @@ class Eeprom(TlvInfoDecoder):
|
|||||||
else:
|
else:
|
||||||
eeprom = self.eeprom_data
|
eeprom = self.eeprom_data
|
||||||
if not self.is_valid_tlvinfo_header(eeprom):
|
if not self.is_valid_tlvinfo_header(eeprom):
|
||||||
|
sonic_logger.log_warning("Invalid system eeprom TLV header")
|
||||||
self.base_mac = 'NA'
|
self.base_mac = 'NA'
|
||||||
self.serial_number = 'NA'
|
self.serial_number = 'NA'
|
||||||
self.part_number = 'NA'
|
self.part_number = 'NA'
|
||||||
@ -144,10 +149,12 @@ class Eeprom(TlvInfoDecoder):
|
|||||||
# Read Fan/PSU EEPROM as per the specified format.
|
# Read Fan/PSU EEPROM as per the specified format.
|
||||||
self.eeprom_data = EepromDecoder.read_eeprom(self)
|
self.eeprom_data = EepromDecoder.read_eeprom(self)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
|
sonic_logger.log_warning("Unable to read device eeprom for PSU#{}".format(self.index))
|
||||||
return
|
return
|
||||||
|
|
||||||
# Bail out if PSU eeprom unavailable
|
# Bail out if PSU eeprom unavailable
|
||||||
if self.eeprom_data[0] == 255:
|
if self.eeprom_data[0] == 255:
|
||||||
|
sonic_logger.log_warning("Uninitialized device eeprom for PSU#{}".format(self.index))
|
||||||
return
|
return
|
||||||
|
|
||||||
(valid, data) = self._get_eeprom_field("Model")
|
(valid, data) = self._get_eeprom_field("Model")
|
||||||
@ -164,6 +171,7 @@ class Eeprom(TlvInfoDecoder):
|
|||||||
if valid:
|
if valid:
|
||||||
self.serial_number = data.decode()
|
self.serial_number = data.decode()
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
|
sonic_logger.log_warning("Unable to read serial# of PSU#{}".format(self.index))
|
||||||
return
|
return
|
||||||
|
|
||||||
# Fan device eeproms use ONIE TLV format
|
# Fan device eeproms use ONIE TLV format
|
||||||
@ -172,10 +180,12 @@ class Eeprom(TlvInfoDecoder):
|
|||||||
# Read Fan EEPROM as per ONIE TlvInfo EEPROM format.
|
# Read Fan EEPROM as per ONIE TlvInfo EEPROM format.
|
||||||
self.eeprom_data = self.read_eeprom()
|
self.eeprom_data = self.read_eeprom()
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
|
sonic_logger.log_warning("Unable to read device eeprom for Fan#{}".format(self.index))
|
||||||
return
|
return
|
||||||
|
|
||||||
eeprom = self.eeprom_data
|
eeprom = self.eeprom_data
|
||||||
if not self.is_valid_tlvinfo_header(eeprom):
|
if not self.is_valid_tlvinfo_header(eeprom):
|
||||||
|
sonic_logger.log_warning("Invalid device eeprom TLV header for Fan#{}".format(self.index))
|
||||||
return
|
return
|
||||||
|
|
||||||
total_length = (eeprom[9] << 8) | eeprom[10]
|
total_length = (eeprom[9] << 8) | eeprom[10]
|
||||||
|
@ -7,6 +7,7 @@
|
|||||||
########################################################################
|
########################################################################
|
||||||
|
|
||||||
try:
|
try:
|
||||||
|
import os
|
||||||
import sys
|
import sys
|
||||||
from sonic_platform_base.psu_base import PsuBase
|
from sonic_platform_base.psu_base import PsuBase
|
||||||
from sonic_py_common import logger
|
from sonic_py_common import logger
|
||||||
@ -39,6 +40,34 @@ class Psu(PsuBase):
|
|||||||
# PSU eeprom
|
# PSU eeprom
|
||||||
self.eeprom = Eeprom(is_psu=True, psu_index=self.index)
|
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):
|
def get_name(self):
|
||||||
"""
|
"""
|
||||||
Retrieves the name of the device
|
Retrieves the name of the device
|
||||||
@ -242,7 +271,20 @@ class Psu(PsuBase):
|
|||||||
Returns:
|
Returns:
|
||||||
A string, one of the predefined STATUS_LED_COLOR_* strings.
|
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):
|
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
|
bool: True if status LED state is set successfully, False if
|
||||||
not
|
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
|
return True
|
||||||
|
@ -5,7 +5,6 @@
|
|||||||
|
|
||||||
import os
|
import os
|
||||||
import sys
|
import sys
|
||||||
import time
|
|
||||||
|
|
||||||
try:
|
try:
|
||||||
from sonic_platform_base.sfp_base import SfpBase
|
from sonic_platform_base.sfp_base import SfpBase
|
||||||
@ -795,28 +794,22 @@ class Sfp(SfpBase):
|
|||||||
Reset SFP.
|
Reset SFP.
|
||||||
Returns:
|
Returns:
|
||||||
A boolean, True if successful, False if not
|
A boolean, True if successful, False if not
|
||||||
"""
|
"""
|
||||||
if self.sfp_type == COPPER_TYPE:
|
# RJ45 and SFP ports not resettable
|
||||||
return False
|
return False
|
||||||
|
|
||||||
self.tx_disable(True)
|
|
||||||
time.sleep(1)
|
|
||||||
self.tx_disable(False)
|
|
||||||
|
|
||||||
return True
|
|
||||||
|
|
||||||
def tx_disable(self, tx_disable):
|
def tx_disable(self, tx_disable):
|
||||||
"""
|
"""
|
||||||
Disable SFP TX
|
Disable SFP TX
|
||||||
Args:
|
Args:
|
||||||
tx_disable : A Boolean, True to enable tx_disable mode, False to disable
|
tx_disable : A Boolean, True to enable tx_disable mode, False to disable
|
||||||
tx_disable mode.
|
tx_disable mode.
|
||||||
Returns:
|
Returns:
|
||||||
A boolean, True if tx_disable is set successfully, False if not
|
A boolean, True if tx_disable is set successfully, False if not
|
||||||
"""
|
"""
|
||||||
if self.sfp_type == COPPER_TYPE:
|
if self.sfp_type == COPPER_TYPE:
|
||||||
return False
|
return False
|
||||||
|
|
||||||
if smbus_present == 0: # if called from sfputil outside of pmon
|
if smbus_present == 0: # if called from sfputil outside of pmon
|
||||||
cmdstatus, register = cmd.getstatusoutput('sudo i2cget -y 0 0x41 0x5')
|
cmdstatus, register = cmd.getstatusoutput('sudo i2cget -y 0 0x41 0x5')
|
||||||
if cmdstatus:
|
if cmdstatus:
|
||||||
@ -834,8 +827,8 @@ class Sfp(SfpBase):
|
|||||||
if tx_disable == True:
|
if tx_disable == True:
|
||||||
setbits = register | mask
|
setbits = register | mask
|
||||||
else:
|
else:
|
||||||
setbits = register & ~mask
|
setbits = register & ~mask
|
||||||
|
|
||||||
if smbus_present == 0: # if called from sfputil outside of pmon
|
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)
|
cmdstatus, output = cmd.getstatusoutput('sudo i2cset -y -m 0x0f 0 0x41 0x5 %d' % setbits)
|
||||||
if cmdstatus:
|
if cmdstatus:
|
||||||
@ -846,7 +839,7 @@ class Sfp(SfpBase):
|
|||||||
DEVICE_ADDRESS = 0x41
|
DEVICE_ADDRESS = 0x41
|
||||||
DEVICE_REG = 0x5
|
DEVICE_REG = 0x5
|
||||||
bus.write_byte_data(DEVICE_ADDRESS, DEVICE_REG, setbits)
|
bus.write_byte_data(DEVICE_ADDRESS, DEVICE_REG, setbits)
|
||||||
|
|
||||||
return True
|
return True
|
||||||
|
|
||||||
def tx_disable_channel(self, channel, disable):
|
def tx_disable_channel(self, channel, disable):
|
||||||
|
Reference in New Issue
Block a user