Skip to content

Commit

Permalink
Add diagnostic monitoring APIs for DOM, VDM and status access for CMI…
Browse files Browse the repository at this point in the history
…S modules (#515)

* Add diagnostic monitoring APIs for DOM, VDM and status access for CMIS modules

Signed-off-by: Mihir Patel <patelmi@microsoft.com>

* Removed flag keyword from dictionary returned for DOM flags

* Added description for get_transceiver_vdm_real_value

---------

Signed-off-by: Mihir Patel <patelmi@microsoft.com>
  • Loading branch information
mihirpat1 authored Nov 15, 2024
1 parent bad49e2 commit 9fc9c85
Show file tree
Hide file tree
Showing 8 changed files with 938 additions and 74 deletions.
53 changes: 9 additions & 44 deletions sonic_platform_base/sonic_xcvr/api/public/c_cmis.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,12 @@
"""
from sonic_py_common import logger
from ...fields import consts
from .cmis import CmisApi
from .cmis import CmisApi, CMIS_VDM_KEY_TO_DB_PREFIX_KEY_MAP
import time
BYTELENGTH = 8
VDM_FREEZE = 128
VDM_UNFREEZE = 0
SYSLOG_IDENTIFIER = "CCmisApi"

VDM_KEY_TO_DB_KEY_PREFIX_MAP = {
C_CMIS_DELTA_VDM_KEY_TO_DB_PREFIX_KEY_MAP = {
'Modulator Bias X/I [%]' : 'biasxi',
'Modulator Bias X/Q [%]' : 'biasxq',
'Modulator Bias X_Phase [%]' : 'biasxp',
Expand Down Expand Up @@ -51,6 +49,10 @@ class CCmisApi(CmisApi):
def __init__(self, xcvr_eeprom):
super(CCmisApi, self).__init__(xcvr_eeprom)

def _get_vdm_key_to_db_prefix_map(self):
combined_map = {**CMIS_VDM_KEY_TO_DB_PREFIX_KEY_MAP, **C_CMIS_DELTA_VDM_KEY_TO_DB_PREFIX_KEY_MAP}
return combined_map

def _update_dict_if_vdm_key_exists(self, dict_to_be_updated, new_key, vdm_dict_key, vdm_subtype_index, lane=1):
'''
This function updates the dictionary with the VDM value if the vdm_dict_key exists.
Expand Down Expand Up @@ -209,43 +211,6 @@ def set_tx_power(self, tx_power):
time.sleep(1)
return status

def freeze_vdm_stats(self):
'''
This function freeze all the vdm statistics reporting registers.
When raised by the host, causes the module to freeze and hold all
reported statistics reporting registers (minimum, maximum and
average values)in Pages 24h-27h.
Returns True if the provision succeeds and False incase of failure.
'''
return self.xcvr_eeprom.write(consts.VDM_CONTROL, VDM_FREEZE)

def get_vdm_freeze_status(self):
'''
This function reads and returns the vdm Freeze done status.
Returns True if the vdm stats freeze is successful and False if not freeze.
'''
return self.xcvr_eeprom.read(consts.VDM_FREEZE_DONE)

def unfreeze_vdm_stats(self):
'''
This function unfreeze all the vdm statistics reporting registers.
When freeze is ceased by the host, releases the freeze request, allowing the
reported minimum, maximum and average values to update again.
Returns True if the provision succeeds and False incase of failure.
'''
return self.xcvr_eeprom.write(consts.VDM_CONTROL, VDM_UNFREEZE)

def get_vdm_unfreeze_status(self):
'''
This function reads and returns the vdm unfreeze status.
Returns True if the vdm stats unfreeze is successful and False if not unfreeze.
'''
return self.xcvr_eeprom.read(consts.VDM_UNFREEZE_DONE)

def get_pm_all(self):
'''
This function returns the PMs reported in Page 34h and 35h in OIF C-CMIS document
Expand Down Expand Up @@ -440,7 +405,7 @@ def get_transceiver_bulk_status(self):
"""
trans_dom = super(CCmisApi,self).get_transceiver_bulk_status()

for vdm_key, trans_dom_key in VDM_KEY_TO_DB_KEY_PREFIX_MAP.items():
for vdm_key, trans_dom_key in C_CMIS_DELTA_VDM_KEY_TO_DB_PREFIX_KEY_MAP.items():
self._update_dict_if_vdm_key_exists(trans_dom, trans_dom_key, vdm_key, 0)

trans_dom['laser_config_freq'] = self.get_laser_config_freq()
Expand Down Expand Up @@ -561,7 +526,7 @@ def get_transceiver_threshold_info(self):
"""
trans_dom_th = super(CCmisApi,self).get_transceiver_threshold_info()

for vdm_key, trans_dom_th_key_prefix in VDM_KEY_TO_DB_KEY_PREFIX_MAP.items():
for vdm_key, trans_dom_th_key_prefix in C_CMIS_DELTA_VDM_KEY_TO_DB_PREFIX_KEY_MAP.items():
for i in range(1, 5):
trans_dom_th_key = trans_dom_th_key_prefix + VDM_SUBTYPE_IDX_MAP[i]
self._update_dict_if_vdm_key_exists(trans_dom_th, trans_dom_th_key, vdm_key, i)
Expand Down Expand Up @@ -753,7 +718,7 @@ def get_transceiver_status(self):
trans_status['invalid_channel_num'] = 'InvalidChannel' in laser_tuning_summary
trans_status['tuning_complete'] = 'TuningComplete' in laser_tuning_summary

for vdm_key, trans_status_key_prefix in VDM_KEY_TO_DB_KEY_PREFIX_MAP.items():
for vdm_key, trans_status_key_prefix in C_CMIS_DELTA_VDM_KEY_TO_DB_PREFIX_KEY_MAP.items():
for i in range(5, 9):
trans_status_key = trans_status_key_prefix + VDM_SUBTYPE_IDX_MAP[i]
self._update_dict_if_vdm_key_exists(trans_status, trans_status_key, vdm_key, i)
Expand Down
428 changes: 428 additions & 0 deletions sonic_platform_base/sonic_xcvr/api/public/cmis.py

Large diffs are not rendered by default.

9 changes: 6 additions & 3 deletions sonic_platform_base/sonic_xcvr/api/public/cmisVDM.py
Original file line number Diff line number Diff line change
Expand Up @@ -195,8 +195,11 @@ def get_vdm_allpage(self, field_option=ALL_FIELD ):
vdm_low_warn_flag
]
'''
vdm_page_supported_raw = self.xcvr_eeprom.read(consts.VDM_SUPPORTED_PAGE)
if vdm_page_supported_raw is None:
vdm_pages_supported = self.xcvr_eeprom.read(consts.VDM_SUPPORTED)
if not vdm_pages_supported:
return None
vdm_groups_supported_raw = self.xcvr_eeprom.read(consts.VDM_SUPPORTED_PAGE)
if vdm_groups_supported_raw is None:
return None
VDM_START_PAGE = 0x20
vdm = dict()
Expand All @@ -206,7 +209,7 @@ def get_vdm_allpage(self, field_option=ALL_FIELD ):
else:
vdm_flag_page = None

for page in range(VDM_START_PAGE, VDM_START_PAGE + vdm_page_supported_raw + 1):
for page in range(VDM_START_PAGE, VDM_START_PAGE + vdm_groups_supported_raw + 1):
vdm_current_page = self.get_vdm_page(page, vdm_flag_page, field_option)
vdm.update(vdm_current_page)
return vdm
34 changes: 34 additions & 0 deletions sonic_platform_base/sonic_xcvr/api/xcvr_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,15 @@ def get_transceiver_bulk_status(self):
"""
raise NotImplementedError

def get_transceiver_dom_flags(self):
"""
Retrieves the DOM flags for this xcvr
Returns:
A dict containing dom flags for this xcvr
"""
raise NotImplementedError

def get_transceiver_threshold_info(self):
"""
Retrieves threshold info for this xcvr
Expand Down Expand Up @@ -242,6 +251,31 @@ def get_transceiver_status(self):
"""
raise NotImplementedError

def get_transceiver_status_flags(self):
"""
Retrieves status flags of this xcvr
"""
raise NotImplementedError

def get_transceiver_vdm_real_value(self):
"""
Retrieves VDM real (sample) values for this xcvr (applicable for CMIS and C-CMIS)
Specifically, it retrieves sample data from pages 24h to 27h
"""
raise NotImplementedError

def get_transceiver_vdm_thresholds(self):
"""
Retrieves VDM thresholds for this xcvr (applicable for CMIS and C-CMIS)
"""
raise NotImplementedError

def get_transceiver_vdm_flags(self):
"""
Retrieves VDM flags for this xcvr (applicable for CMIS and C-CMIS)
"""
raise NotImplementedError

def get_transceiver_pm(self):
"""
Retrieves PM (Performance Monitoring) info for this xcvr (applicable for C-CMIS)
Expand Down
24 changes: 24 additions & 0 deletions sonic_platform_base/sonic_xcvr/sfp_optoe_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,10 @@ def get_transceiver_bulk_status(self):
api = self.get_xcvr_api()
return api.get_transceiver_bulk_status() if api is not None else None

def get_transceiver_dom_flags(self):
api = self.get_xcvr_api()
return api.get_transceiver_dom_flags() if api is not None else None

def get_transceiver_threshold_info(self):
api = self.get_xcvr_api()
return api.get_transceiver_threshold_info() if api is not None else None
Expand All @@ -39,6 +43,10 @@ def get_transceiver_status(self):
api = self.get_xcvr_api()
return api.get_transceiver_status() if api is not None else None

def get_transceiver_status_flags(self):
api = self.get_xcvr_api()
return api.get_transceiver_status_flags() if api is not None else None

def get_transceiver_loopback(self):
api = self.get_xcvr_api()
return api.get_transceiver_loopback() if api is not None else None
Expand All @@ -47,6 +55,22 @@ def is_coherent_module(self):
api = self.get_xcvr_api()
return api.is_coherent_module() if api is not None else None

def get_transceiver_vdm_real_value(self):
"""
Retrieves VDM real (sample) values for this xcvr (applicable for CMIS and C-CMIS)
Specifically, it retrieves sample data from pages 24h to 27h
"""
api = self.get_xcvr_api()
return api.get_transceiver_vdm_real_value() if api is not None else None

def get_transceiver_vdm_thresholds(self):
api = self.get_xcvr_api()
return api.get_transceiver_vdm_thresholds() if api is not None else None

def get_transceiver_vdm_flags(self):
api = self.get_xcvr_api()
return api.get_transceiver_vdm_flags() if api is not None else None

def get_transceiver_pm(self):
api = self.get_xcvr_api()
return api.get_transceiver_pm() if api is not None else None
Expand Down
Loading

0 comments on commit 9fc9c85

Please sign in to comment.