-
Notifications
You must be signed in to change notification settings - Fork 217
400zr initial support #228
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 11 commits
Commits
Show all changes
18 commits
Select commit
Hold shift + click to select a range
68f4ce0
Rebase changes to latest in master
prgeor a53e6d6
resolving conflict and errors
qinchuanares 5e4f6e1
adding test cases
qinchuanares 35177c0
add test cases
qinchuanares 068a4dd
resolving check failures
qinchuanares 854043d
bug fix in set_low_power()
qinchuanares 520aefc
1. fix in get_module_fw_info() to address issue when not both image A…
qinchuanares 1dc4652
1. resolve comments in PR #228. -a open a new file in mem_maps\public…
qinchuanares 20f6b72
removed unused imports in mem_maps\public\c_cmis.py
qinchuanares add1040
resolving comments. 1. return provision status for *set* functions. 2…
qinchuanares a93d90f
make sure all functions in sfp_opte_base.py are good to be called
qinchuanares 20f557a
resolve comments mainly on CDB
qinchuanares 0b9aaf9
resolve CDB raise exception issue. include text as return info
qinchuanares 2de0878
resolve a pipline check error
qinchuanares 9989804
add descriptions to CDB files
qinchuanares 073b445
resolve alerts in LGTM warnings
qinchuanares 0128057
resolve LGTM alerts, make get_module_fw_info() and get_module_fw_upgr…
qinchuanares da51eac
change back to syslog logging
qinchuanares File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
1,328 changes: 1,301 additions & 27 deletions
1,328
sonic_platform_base/sonic_xcvr/api/public/cmis.py
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains hidden or 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 |
|---|---|---|
| @@ -0,0 +1,173 @@ | ||
| """ | ||
| cmisCDB.py | ||
|
|
||
| Implementation of APIs related to VDMs | ||
| """ | ||
|
|
||
| from ...fields import consts | ||
| from ..xcvr_api import XcvrApi | ||
| import struct | ||
| import time | ||
|
|
||
| PAGE_SIZE = 128 | ||
| PAGE_OFFSET = 128 | ||
| THRSH_SPACING = 8 | ||
| VDM_SIZE = 2 | ||
| VDM_FLAG_PAGE = 0x2c | ||
|
|
||
| class CmisVdmApi(XcvrApi): | ||
| def __init__(self, xcvr_eeprom): | ||
| super(CmisVdmApi, self).__init__(xcvr_eeprom) | ||
|
|
||
| def get_F16(self, value): | ||
| ''' | ||
| This function converts raw data to "F16" format defined in cmis. | ||
| ''' | ||
| scale_exponent = (value >> 11) & 0x1f | ||
| mantissa = value & 0x7ff | ||
| result = mantissa*10**(scale_exponent-24) | ||
| return result | ||
|
|
||
| def get_vdm_page(self, page, VDM_flag_page): | ||
| ''' | ||
| This function returns VDM items from a specific VDM page. | ||
| Output format is a dictionary. Key is observable type; value is a dictionary. | ||
| In the inside dictionary, key is lane; value is a list | ||
| [ | ||
| vdm_value, | ||
| vdm_thrsh_high_alarm, | ||
| vdm_thrsh_low_alarm, | ||
| vdm_thrsh_high_warn, | ||
| vdm_thrsh_low_warn, | ||
| vdm_high_alarm_flag, | ||
| vdm_low_alarm_flag, | ||
| vdm_high_warn_flag, | ||
| vdm_low_warn_flag | ||
| ] | ||
| ''' | ||
| if page not in [0x20, 0x21, 0x22, 0x23]: | ||
| raise ValueError('Page not in VDM Descriptor range!') | ||
| vdm_descriptor = self.xcvr_eeprom.read_raw(page * PAGE_SIZE + PAGE_OFFSET, PAGE_SIZE) | ||
|
|
||
| # Odd Adress VDM observable type ID, real-time monitored value in Page + 4 | ||
| vdm_typeID = vdm_descriptor[1::2] | ||
| # Even Address | ||
| # Bit 7-4: Threshold set ID in Page + 8, in group of 8 bytes, 16 sets/page | ||
| # Bit 3-0: n. Monitored lane n+1 | ||
| vdm_lane = [(elem & 0xf) for elem in vdm_descriptor[0::2]] | ||
| VDM_thresholdID = [(elem>>4) for elem in vdm_descriptor[0::2]] | ||
| vdm_valuePage = page + 4 | ||
| vdm_thrshPage = page + 8 | ||
| vdm_Page_data = {} | ||
| VDM_TYPE_DICT = self.xcvr_eeprom.mem_map.codes.VDM_TYPE | ||
| for index, typeID in enumerate(vdm_typeID): | ||
| if typeID not in VDM_TYPE_DICT: | ||
| continue | ||
| else: | ||
| vdm_info_dict = VDM_TYPE_DICT[typeID] | ||
| thrshID = VDM_thresholdID[index] | ||
| vdm_type = vdm_info_dict[0] | ||
| vdm_format = vdm_info_dict[1] | ||
| scale = vdm_info_dict[2] | ||
|
|
||
| vdm_value_offset = vdm_valuePage * PAGE_SIZE + PAGE_OFFSET + VDM_SIZE * index | ||
| vdm_high_alarm_offset = vdm_thrshPage * PAGE_SIZE + PAGE_OFFSET + THRSH_SPACING * thrshID | ||
| vdm_low_alarm_offset = vdm_high_alarm_offset + 2 | ||
| vdm_high_warn_offset = vdm_high_alarm_offset + 4 | ||
| vdm_low_warn_offset = vdm_high_alarm_offset + 6 | ||
|
|
||
| vdm_value_raw = self.xcvr_eeprom.read_raw(vdm_value_offset, VDM_SIZE, True) | ||
| vdm_thrsh_high_alarm_raw = self.xcvr_eeprom.read_raw(vdm_high_alarm_offset, VDM_SIZE, True) | ||
| vdm_thrsh_low_alarm_raw = self.xcvr_eeprom.read_raw(vdm_low_alarm_offset, VDM_SIZE, True) | ||
| vdm_thrsh_high_warn_raw = self.xcvr_eeprom.read_raw(vdm_high_warn_offset, VDM_SIZE, True) | ||
| vdm_thrsh_low_warn_raw = self.xcvr_eeprom.read_raw(vdm_low_warn_offset, VDM_SIZE, True) | ||
| if vdm_format == 'S16': | ||
| vdm_value = struct.unpack('>h',vdm_value_raw)[0] * scale | ||
| vdm_thrsh_high_alarm = struct.unpack('>h', vdm_thrsh_high_alarm_raw)[0] * scale | ||
| vdm_thrsh_low_alarm = struct.unpack('>h', vdm_thrsh_low_alarm_raw)[0] * scale | ||
| vdm_thrsh_high_warn = struct.unpack('>h', vdm_thrsh_high_warn_raw)[0] * scale | ||
| vdm_thrsh_low_warn = struct.unpack('>h', vdm_thrsh_low_warn_raw)[0] * scale | ||
| elif vdm_format == 'U16': | ||
| vdm_value = struct.unpack('>H',vdm_value_raw)[0] * scale | ||
| vdm_thrsh_high_alarm = struct.unpack('>H', vdm_thrsh_high_alarm_raw)[0] * scale | ||
| vdm_thrsh_low_alarm = struct.unpack('>H', vdm_thrsh_low_alarm_raw)[0] * scale | ||
| vdm_thrsh_high_warn = struct.unpack('>H', vdm_thrsh_high_warn_raw)[0] * scale | ||
| vdm_thrsh_low_warn = struct.unpack('>H', vdm_thrsh_low_warn_raw)[0] * scale | ||
| elif vdm_format == 'F16': | ||
| vdm_value_int = struct.unpack('>H',vdm_value_raw)[0] | ||
| vdm_value = self.get_F16(vdm_value_int) | ||
| vdm_thrsh_high_alarm_int = struct.unpack('>H', vdm_thrsh_high_alarm_raw)[0] | ||
| vdm_thrsh_low_alarm_int = struct.unpack('>H', vdm_thrsh_low_alarm_raw)[0] | ||
| vdm_thrsh_high_warn_int = struct.unpack('>H', vdm_thrsh_high_warn_raw)[0] | ||
| vdm_thrsh_low_warn_int = struct.unpack('>H', vdm_thrsh_low_warn_raw)[0] | ||
| vdm_thrsh_high_alarm = self.get_F16(vdm_thrsh_high_alarm_int) | ||
| vdm_thrsh_low_alarm = self.get_F16(vdm_thrsh_low_alarm_int) | ||
| vdm_thrsh_high_warn = self.get_F16(vdm_thrsh_high_warn_int) | ||
| vdm_thrsh_low_warn = self.get_F16(vdm_thrsh_low_warn_int) | ||
| else: | ||
| continue | ||
|
|
||
| vdm_flag_offset = 32 * (page - 0x20) + index//2 | ||
| bit_offset = 4*(index%2) | ||
| vdm_high_alarm_flag = bool((VDM_flag_page[vdm_flag_offset] >> (bit_offset)) & 0x1) | ||
| vdm_low_alarm_flag = bool((VDM_flag_page[vdm_flag_offset] >> (bit_offset+1)) & 0x1) | ||
| vdm_high_warn_flag = bool((VDM_flag_page[vdm_flag_offset] >> (bit_offset+2)) & 0x1) | ||
| vdm_low_warn_flag = bool((VDM_flag_page[vdm_flag_offset] >> (bit_offset+3)) & 0x1) | ||
|
|
||
| if vdm_type not in vdm_Page_data: | ||
| vdm_Page_data[vdm_type] = { | ||
| vdm_lane[index]+1: [ | ||
| vdm_value, | ||
| vdm_thrsh_high_alarm, | ||
| vdm_thrsh_low_alarm, | ||
| vdm_thrsh_high_warn, | ||
| vdm_thrsh_low_warn, | ||
| vdm_high_alarm_flag, | ||
| vdm_low_alarm_flag, | ||
| vdm_high_warn_flag, | ||
| vdm_low_warn_flag] | ||
| } | ||
|
|
||
| else: | ||
| vdm_Page_data[vdm_info_dict[0]][vdm_lane[index]+1] = [ | ||
| vdm_value, | ||
| vdm_thrsh_high_alarm, | ||
| vdm_thrsh_low_alarm, | ||
| vdm_thrsh_high_warn, | ||
| vdm_thrsh_low_warn, | ||
| vdm_high_alarm_flag, | ||
| vdm_low_alarm_flag, | ||
| vdm_high_warn_flag, | ||
| vdm_low_warn_flag] | ||
| return vdm_Page_data | ||
|
|
||
| def get_vdm_allpage(self): | ||
| ''' | ||
| This function returns VDM items from all advertised VDM pages. | ||
| Output format is a dictionary. Key is observable type; value is a dictionary. | ||
| In the inside dictionary, key is lane; value is a list | ||
| [ | ||
| vdm_value, | ||
| vdm_thrsh_high_alarm, | ||
| vdm_thrsh_low_alarm, | ||
| vdm_thrsh_high_warn, | ||
| vdm_thrsh_low_warn, | ||
| vdm_high_alarm_flag, | ||
| vdm_low_alarm_flag, | ||
| vdm_high_warn_flag, | ||
| vdm_low_warn_flag | ||
| ] | ||
| ''' | ||
| vdm_page_supported_raw = self.xcvr_eeprom.read(consts.VDM_SUPPORTED_PAGE) | ||
| if vdm_page_supported_raw is None: | ||
| return None | ||
| VDM_START_PAGE = 0x20 | ||
| vdm = dict() | ||
| self.xcvr_eeprom.write(consts.VDM_CONTROL, 128) | ||
| time.sleep(1) | ||
| self.xcvr_eeprom.write(consts.VDM_CONTROL, 0) | ||
qinchuanares marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| vdm_flag_page = self.xcvr_eeprom.read_raw(VDM_FLAG_PAGE * PAGE_SIZE + PAGE_OFFSET, PAGE_SIZE) | ||
| for page in range(VDM_START_PAGE, VDM_START_PAGE + vdm_page_supported_raw + 1): | ||
| vdm_current_page = self.get_vdm_page(page, vdm_flag_page) | ||
| vdm.update(vdm_current_page) | ||
| return vdm | ||
This file contains hidden or 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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.