-
Notifications
You must be signed in to change notification settings - Fork 166
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #26 from stephenxs/sfp-bit-map-error-status
Enhanced - Handle the error status returned by platform APIs
- Loading branch information
Showing
4 changed files
with
79 additions
and
100 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,35 +1,37 @@ | ||
from sonic_platform_base.sfp_base import SfpBase | ||
|
||
# SFP status definition, shall be aligned with the definition in get_change_event() of ChassisBase | ||
SFP_STATUS_REMOVED = '0' | ||
SFP_STATUS_INSERTED = '1' | ||
|
||
# SFP error code dictinary, new elements can be added if new errors need to be supported. | ||
SFP_STATUS_ERR_DICT = { | ||
2: 'SFP_STATUS_ERR_I2C_STUCK', | ||
4: 'SFP_STATUS_ERR_BAD_EEPROM', | ||
8: 'SFP_STATUS_ERR_UNSUPPORTED_CABLE', | ||
16: 'SFP_STATUS_ERR_HIGH_TEMP', | ||
32: 'SFP_STATUS_ERR_BAD_CABLE' | ||
} | ||
|
||
error_code_block_eeprom_reading = set((error_code for error_code in SFP_STATUS_ERR_DICT.keys())) | ||
error_str_block_eeprom_reading = set((error for error in SFP_STATUS_ERR_DICT.values())) | ||
|
||
|
||
def is_error_block_eeprom_reading(status): | ||
int_status = int(status) | ||
for error_code in error_code_block_eeprom_reading: | ||
if int_status & error_code: | ||
return True | ||
return False | ||
SFP_ERRORS_BLOCKING_MASK = 0x02 | ||
SFP_ERRORS_GENERIC_MASK = 0x0000FFFE | ||
SFP_ERRORS_VENDOR_SPECIFIC_MASK = 0xFFFF0000 | ||
|
||
def is_error_block_eeprom_reading(error_bits): | ||
return 0 != (error_bits & SFP_ERRORS_BLOCKING_MASK) | ||
|
||
|
||
def has_vendor_specific_error(error_bits): | ||
return 0 != (error_bits & SFP_ERRORS_VENDOR_SPECIFIC_MASK) | ||
|
||
|
||
def fetch_generic_error_description(error_bits): | ||
generic_error_bits = (error_bits & SFP_ERRORS_GENERIC_MASK) | ||
error_descriptions = [] | ||
if generic_error_bits: | ||
for error_bit, error_description in SfpBase.SFP_ERROR_BIT_TO_DESCRIPTION_DICT.items(): | ||
if error_bit & generic_error_bits: | ||
error_descriptions.append(error_description) | ||
return error_descriptions | ||
|
||
|
||
def detect_port_in_error_status(logical_port_name, status_tbl): | ||
rec, fvp = status_tbl.get(logical_port_name) | ||
if rec: | ||
status_dict = dict(fvp) | ||
if 'error' in status_dict: | ||
for error in error_str_block_eeprom_reading: | ||
if error in status_dict['error']: | ||
return True | ||
error = status_dict.get('error') | ||
return SfpBase.SFP_ERROR_DESCRIPTION_BLOCKING in error | ||
return False | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters