Skip to content
Merged
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions sonic_platform_base/sonic_xcvr/sfp_optoe_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@

from ..sfp_base import SfpBase

SFP_OPTOE_PAGE_SELECT_OFFSET = 127
SFP_OPTOE_UPPER_PAGE0_OFFSET = 128
SFP_OPTOE_PAGE_SIZE = 128

class SfpOptoeBase(SfpBase):
def __init__(self):
SfpBase.__init__(self)
Expand Down Expand Up @@ -261,6 +265,12 @@ def set_optoe_write_max(self, write_max):
except (OSError, IOError):
pass

def get_optoe_current_page(self):
return self.read_eeprom(SFP_OPTOE_PAGE_SELECT_OFFSET, 1)[0]

def set_page0(self):
self.write_eeprom(SFP_OPTOE_PAGE_SELECT_OFFSET, 1, bytearray([0x00]))

def set_optoe_write_timeout(self, write_timeout):
sys_path = self.get_eeprom_path()
sys_path = sys_path.replace("eeprom", "write_timeout")
Expand All @@ -273,6 +283,12 @@ def set_optoe_write_timeout(self, write_timeout):
def read_eeprom(self, offset, num_bytes):
try:
with open(self.get_eeprom_path(), mode='rb', buffering=0) as f:
if offset >= SFP_OPTOE_UPPER_PAGE0_OFFSET and \
offset < (SFP_OPTOE_UPPER_PAGE0_OFFSET+SFP_OPTOE_PAGE_SIZE) and \
self.get_optoe_current_page() != 0:
# Restoring the page to 0 helps in cases where the optoe driver failed to restore
# the page when say the module was busy with CDB command processing
self.set_page0()
f.seek(offset)
return bytearray(f.read(num_bytes))
except (OSError, IOError):
Expand Down
Loading