From 7670b49927ccddf7d090442dc3aa348cccb0c02b Mon Sep 17 00:00:00 2001 From: Stephen Sun <5379172+stephenxs@users.noreply.github.com> Date: Thu, 17 Jun 2021 00:25:53 +0800 Subject: [PATCH] [sonic_platform/sfp_base] Add common definition for get SFP error status (#194) Add common definitions for getting SFP error status - Platform API definition: `get_sfp_status` - Related constant definitions Signed-off-by: Stephen Sun --- sonic_platform_base/sfp_base.py | 44 +++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) diff --git a/sonic_platform_base/sfp_base.py b/sonic_platform_base/sfp_base.py index a472e49051f3..b3e6e9f488d4 100644 --- a/sonic_platform_base/sfp_base.py +++ b/sonic_platform_base/sfp_base.py @@ -16,6 +16,41 @@ class SfpBase(device_base.DeviceBase): # Device type definition. Note, this is a constant. DEVICE_TYPE = "sfp" + # Generic error types definition + SFP_STATUS_INITIALIZING = 'Initializing' + SFP_STATUS_OK = 'OK' + SFP_STATUS_UNPLUGGED = 'Unplugged' + SFP_STATUS_DISABLED = 'Disabled' + SFP_ERROR_DESCRIPTION_BLOCKING = 'Blocking EEPROM from being read' + SFP_ERROR_DESCRIPTION_POWER_BUDGET_EXCEEDED = 'Power budget exceeded' + SFP_ERROR_DESCRIPTION_I2C_STUCK = 'Bus stuck (I2C data or clock shorted)' + SFP_ERROR_DESCRIPTION_BAD_EEPROM = 'Bad or unsupported EEPROM' + SFP_ERROR_DESCRIPTION_UNSUPPORTED_CABLE = 'Unsupported cable' + SFP_ERROR_DESCRIPTION_HIGH_TEMP = 'High temperature' + SFP_ERROR_DESCRIPTION_BAD_CABLE = 'Bad cable (module/cable is shorted)' + + # SFP status + SFP_STATUS_BIT_REMOVED = 0x00000000 + SFP_STATUS_BIT_INSERTED = 0x00000001 + # SFP error status + SFP_ERROR_BIT_BLOCKING = 0x00000002 + SFP_ERROR_BIT_POWER_BUDGET_EXCEEDED = 0x00000004 + SFP_ERROR_BIT_I2C_STUCK = 0x00000008 + SFP_ERROR_BIT_BAD_EEPROM = 0x00000010 + SFP_ERROR_BIT_UNSUPPORTED_CABLE = 0x00000020 + SFP_ERROR_BIT_HIGH_TEMP = 0x00000040 + SFP_ERROR_BIT_BAD_CABLE = 0x00000080 + + SFP_ERROR_BIT_TO_DESCRIPTION_DICT = { + SFP_ERROR_BIT_BLOCKING: SFP_ERROR_DESCRIPTION_BLOCKING, + SFP_ERROR_BIT_POWER_BUDGET_EXCEEDED: SFP_ERROR_DESCRIPTION_POWER_BUDGET_EXCEEDED, + SFP_ERROR_BIT_I2C_STUCK: SFP_ERROR_DESCRIPTION_I2C_STUCK, + SFP_ERROR_BIT_BAD_EEPROM: SFP_ERROR_DESCRIPTION_BAD_EEPROM, + SFP_ERROR_BIT_UNSUPPORTED_CABLE: SFP_ERROR_DESCRIPTION_UNSUPPORTED_CABLE, + SFP_ERROR_BIT_HIGH_TEMP: SFP_ERROR_DESCRIPTION_HIGH_TEMP, + SFP_ERROR_BIT_BAD_CABLE: SFP_ERROR_DESCRIPTION_BAD_CABLE + } + def __init__(self): # List of ThermalBase-derived objects representing all thermals # available on the SFP @@ -384,4 +419,13 @@ def write_eeprom(self, offset, num_bytes, write_buffer): """ raise NotImplementedError + def get_error_description(self): + """ + Retrives the error descriptions of the SFP module + Returns: + String that represents the current error descriptions of vendor specific errors + In case there are multiple errors, they should be joined by '|', + like: "Bad EEPROM|Unsupported cable" + """ + raise NotImplementedError