Skip to content

Commit

Permalink
[sonic_platform/sfp_base] Add common definition for get SFP error sta…
Browse files Browse the repository at this point in the history
…tus (sonic-net#194)

Add common definitions for getting SFP error status

- Platform API definition: `get_sfp_status`
- Related constant definitions

Signed-off-by: Stephen Sun <[email protected]>
  • Loading branch information
stephenxs authored Jun 16, 2021
1 parent 1336598 commit 7670b49
Showing 1 changed file with 44 additions and 0 deletions.
44 changes: 44 additions & 0 deletions sonic_platform_base/sfp_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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

0 comments on commit 7670b49

Please sign in to comment.