Skip to content

Commit

Permalink
[Mellanox] Remove EEPROM write limitation if it is software control
Browse files Browse the repository at this point in the history
  • Loading branch information
Junchao-Mellanox committed Oct 20, 2023
1 parent 174583c commit 51ffce2
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 13 deletions.
17 changes: 5 additions & 12 deletions platform/mellanox/mlnx-platform-api/sonic_platform/sfp.py
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,6 @@
SFP_SYSFS_STATUS_ERROR = 'statuserror'
SFP_SYSFS_PRESENT = 'present'
SFP_SYSFS_RESET = 'reset'
SFP_SYSFS_HWRESET = 'hw_reset'
SFP_SYSFS_POWER_MODE = 'power_mode'
SFP_SYSFS_POWER_MODE_POLICY = 'power_mode_policy'
POWER_MODE_POLICY_HIGH = 1
Expand Down Expand Up @@ -332,17 +331,8 @@ def reset(self):
refer plugins/sfpreset.py
"""
try:
if not self.is_sw_control():
file_path = SFP_SDK_MODULE_SYSFS_ROOT_TEMPLATE.format(self.sdk_index) + SFP_SYSFS_RESET
return utils.write_file(file_path, '1')
else:
file_path = SFP_SDK_MODULE_SYSFS_ROOT_TEMPLATE.format(self.sdk_index) + SFP_SYSFS_HWRESET
return utils.write_file(file_path, '0') and utils.write_file(file_path, '1')
except Exception as e:
print(f'Failed to reset module - {e}')
logger.log_error(f'Failed to reset module - {e}')
return False
file_path = SFP_SDK_MODULE_SYSFS_ROOT_TEMPLATE.format(self.sdk_index) + SFP_SYSFS_RESET
return utils.write_file(file_path, '1')

def set_lpmode(self, lpmode):
"""
Expand Down Expand Up @@ -493,6 +483,9 @@ def _is_write_protected(self, page, page_offset, num_bytes):
Returns:
bool: True if the limited bytes is hit
"""
if self.is_sw_control():
return False

eeprom_path = self._get_eeprom_path()
limited_data = limited_eeprom.get(self._get_sfp_type_str(eeprom_path))
if not limited_data:
Expand Down
7 changes: 6 additions & 1 deletion platform/mellanox/mlnx-platform-api/tests/test_sfp.py
Original file line number Diff line number Diff line change
Expand Up @@ -144,8 +144,13 @@ def test_sfp_read_eeprom(self, mock_get_page):

@mock.patch('sonic_platform.sfp.SFP._get_eeprom_path', mock.MagicMock(return_value = None))
@mock.patch('sonic_platform.sfp.SFP._get_sfp_type_str')
def test_is_write_protected(self, mock_get_type_str):
@mock.patch('sonic_platform.sfp.SFP.is_sw_control')
def test_is_write_protected(self, mock_sw_control, mock_get_type_str):
sfp = SFP(0)
mock_sw_control.return_value = True
assert not sfp._is_write_protected(page=0, page_offset=26, num_bytes=1)

mock_sw_control.return_value = False
mock_get_type_str.return_value = 'cmis'
assert sfp._is_write_protected(page=0, page_offset=26, num_bytes=1)
assert not sfp._is_write_protected(page=0, page_offset=27, num_bytes=1)
Expand Down

0 comments on commit 51ffce2

Please sign in to comment.