Skip to content

Commit

Permalink
[Mellanox] fix sfp eeprom unreadable after switching from SW to FW co…
Browse files Browse the repository at this point in the history
…ntrol mode (sonic-net#19563)

- Why I did it
The reading of eeprom instantly after switch the module from sw control to fw control might fail, so add a delay

Signed-off-by: Yuanzhe, Liu <[email protected]>
  • Loading branch information
yuazhe authored Jul 29, 2024
1 parent 3ff9f4f commit 66e491d
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -499,16 +499,18 @@ def get_change_event_for_module_host_management_mode(self, timeout):
s.on_event(event)

if s.in_stable_state():
self.sfp_module.SFP.wait_sfp_eeprom_ready([s], 2)
s.fill_change_event(port_dict)
s.refresh_poll_obj(self.poll_obj, self.registered_fds)
else:
logger.log_debug(f'SFP {sfp_index} does not reach stable state, state={s.state}')

ready_sfp_set = wait_ready_task.get_ready_set()
for sfp_index in ready_sfp_set:
s = self._sfp_list[sfp_index]
s.on_event(sfp.EVENT_RESET_DONE)
if s.in_stable_state():
self.sfp_module.SFP.wait_sfp_eeprom_ready([s], 2)
s.fill_change_event(port_dict)
s.refresh_poll_obj(self.poll_obj, self.registered_fds)
else:
Expand Down
18 changes: 17 additions & 1 deletion platform/mellanox/mlnx-platform-api/sonic_platform/sfp.py
Original file line number Diff line number Diff line change
Expand Up @@ -500,6 +500,21 @@ def get_presence(self):
return False
eeprom_raw = self._read_eeprom(0, 1, log_on_error=False)
return eeprom_raw is not None

@classmethod
def wait_sfp_eeprom_ready(cls, sfp_list, wait_time):
not_ready_list = sfp_list

while wait_time > 0:
not_ready_list = [s for s in not_ready_list if s.state == STATE_FW_CONTROL and s._read_eeprom(0, 2,False) is None]
if not_ready_list:
time.sleep(0.1)
wait_time -= 0.1
else:
return

for s in not_ready_list:
logger.log_error(f'SFP {s.sdk_index} eeprom is not ready')

# read eeprom specfic bytes beginning from offset with size as num_bytes
def read_eeprom(self, offset, num_bytes):
Expand Down Expand Up @@ -1723,7 +1738,8 @@ def initialize_sfp_modules(cls, sfp_list):
logger.log_error(f'SFP {index} is not in stable state after initializing, state={s.state}')
logger.log_notice(f'SFP {index} is in state {s.state} after module initialization')


cls.wait_sfp_eeprom_ready(sfp_list, 2)

class RJ45Port(NvidiaSFPCommon):
"""class derived from SFP, representing RJ45 ports"""

Expand Down

0 comments on commit 66e491d

Please sign in to comment.