[Mellanox] Change SDK API sx_mgmt_phy_module_info_get() to sysfs (#15963)

- Why I did it
Change Mellanox platform API implementation to use ASIC driver sysfs for the module operational state and status error fields.

- How I did it
Modify the platform/mellanox/mlnx-platform-api/sonic_platform/sfp.py file by change the call of sx_mgmt_phy_module_info_get() SDK API to sysfs

- How to verify it
Simulate the unplug cable event
Check the CLI output
sfputil show presence
sfputil show error-status -hw
Simulate the plug cable event
Repeat 2 step

Signed-off-by: vadymhlushko-mlnx <vadymh@nvidia.com>
This commit is contained in:
Vadym Hlushko 2023-08-21 20:54:13 +03:00 committed by mssonicbld
parent 7b8906600c
commit 1f1ae60961

View File

@ -134,6 +134,8 @@ SFP_PAGE0_PATH = '0/i2c-0x50/data'
SFP_A2H_PAGE0_PATH = '0/i2c-0x51/data' SFP_A2H_PAGE0_PATH = '0/i2c-0x51/data'
SFP_SDK_MODULE_SYSFS_ROOT_TEMPLATE = '/sys/module/sx_core/asic0/module{}/' SFP_SDK_MODULE_SYSFS_ROOT_TEMPLATE = '/sys/module/sx_core/asic0/module{}/'
SFP_EEPROM_ROOT_TEMPLATE = SFP_SDK_MODULE_SYSFS_ROOT_TEMPLATE + 'eeprom/pages' SFP_EEPROM_ROOT_TEMPLATE = SFP_SDK_MODULE_SYSFS_ROOT_TEMPLATE + 'eeprom/pages'
SFP_SYSFS_STATUS = 'status'
SFP_SYSFS_STATUS_ERROR = 'statuserror'
SFP_SYSFS_PRESENT = 'present' SFP_SYSFS_PRESENT = 'present'
SFP_SYSFS_RESET = 'reset' SFP_SYSFS_RESET = 'reset'
SFP_SYSFS_POWER_MODE = 'power_mode' SFP_SYSFS_POWER_MODE = 'power_mode'
@ -215,24 +217,18 @@ class NvidiaSFPCommon(SfpOptoeBase):
@classmethod @classmethod
def _get_module_info(self, sdk_handle, sdk_index): def _get_module_info(self, sdk_handle, sdk_index):
""" """
Get error code of the SFP module Get oper state and error code of the SFP module
Returns: Returns:
The error code fetch from SDK API The oper state and error code fetched from sysfs
""" """
module_id_info_list = new_sx_mgmt_module_id_info_t_arr(1) status_file_path = SFP_SDK_MODULE_SYSFS_ROOT_TEMPLATE.format(sdk_index) + SFP_SYSFS_STATUS
module_info_list = new_sx_mgmt_phy_module_info_t_arr(1) oper_state = utils.read_int_from_file(status_file_path)
module_id_info = sx_mgmt_module_id_info_t() status_error_file_path = SFP_SDK_MODULE_SYSFS_ROOT_TEMPLATE.format(sdk_index) + SFP_SYSFS_STATUS_ERROR
module_id_info.slot_id = 0 error_type = utils.read_int_from_file(status_error_file_path)
module_id_info.module_id = sdk_index
sx_mgmt_module_id_info_t_arr_setitem(module_id_info_list, 0, module_id_info)
rc = sx_mgmt_phy_module_info_get(sdk_handle, module_id_info_list, 1, module_info_list) return oper_state, error_type
assert SX_STATUS_SUCCESS == rc, "sx_mgmt_phy_module_info_get failed, error code {}".format(rc)
mod_info = sx_mgmt_phy_module_info_t_arr_getitem(module_info_list, 0)
return mod_info.module_state.oper_state, mod_info.module_state.error_type
class SFP(NvidiaSFPCommon): class SFP(NvidiaSFPCommon):