Skip to content

Commit

Permalink
[Mellanox] Added functionality to handle empty EEPROM files (sonic-ne…
Browse files Browse the repository at this point in the history
…t#20190)

- Why I did it
On Mellanox platforms, it was decided that a good way to simulate an I2C stuck scenario would be to have the files representing the module's EEPROM remain empty. When these files are empty, module initialization will not complete because the read_eeprom() function gets stuck in an infinite loop (while num_bytes > 0: will never evaluate to False as the decrement operation num_bytes -= read_length has no effect). This happens because 0 bytes are always read from the EEPROM when it is empty. This PR addresses this issue.

- How I did it
On Mellanox platforms only, I added a validation check to ensure that if an attempt to read from the EEPROM results in 0 bytes read, the _read_eeprom() function exits and returns None.

- How to verify it
Simulate the empty EEPROM (can be done as described in the script below), update _get_eeprom_path() to redirect to the empty EEPROM location, config reload, and verify that not all ports are down.
  • Loading branch information
tshalvi authored Oct 22, 2024
1 parent a06a559 commit e5449f2
Showing 1 changed file with 3 additions and 0 deletions.
3 changes: 3 additions & 0 deletions platform/mellanox/mlnx-platform-api/sonic_platform/sfp.py
Original file line number Diff line number Diff line change
Expand Up @@ -494,6 +494,9 @@ def _read_eeprom(self, offset, num_bytes, log_on_error=True):
else:
result += content
read_length = len(content)
if read_length == 0:
logger.log_error(f'SFP {self.sdk_index}: EEPROM page {page} is empty, no data retrieved')
return None
num_bytes -= read_length
if num_bytes > 0:
page_size = f.seek(0, os.SEEK_END)
Expand Down

0 comments on commit e5449f2

Please sign in to comment.