Skip to content

Commit

Permalink
Merge pull request sonic-net#125 from vdahiya12/changes_for_mux_driver
Browse files Browse the repository at this point in the history
[SONIC_SFP] adding support for writing the eeprom address space inside sfputilbase.
  • Loading branch information
vdahiya12 committed Oct 10, 2020
2 parents 111dcf7 + addcb0e commit df61c55
Showing 1 changed file with 31 additions and 0 deletions.
31 changes: 31 additions & 0 deletions sonic_platform_base/sonic_sfp/sfputilbase.py
Original file line number Diff line number Diff line change
Expand Up @@ -369,6 +369,37 @@ def _read_eeprom_devid(self, port_num, devid, offset, num_bytes = 256):

return eeprom_raw

def _write_eeprom_specific_bytes(self, sysfsfile_eeprom, offset, num_bytes, write_buffer):
try:
sysfsfile_eeprom.seek(offset)
sysfsfile_eeprom.write(write_buffer)
except IOError:
print("Error: writing EEPROM sysfs file")
return False

return True

def _write_eeprom_devid(self, port_num, devid, offset, num_bytes, write_buffer):
sysfs_sfp_i2c_client_eeprom_path = self._get_port_eeprom_path(port_num, devid)

if not self._sfp_eeprom_present(sysfs_sfp_i2c_client_eeprom_path, offset):
return False

try:
sysfsfile_eeprom = open(sysfs_sfp_i2c_client_eeprom_path, mode="wb", buffering=0)
except IOError:
print("Error: trying to open sysfs file for writing %s" % sysfs_sfp_i2c_client_eeprom_path)
return False

result = self._write_eeprom_specific_bytes(sysfsfile_eeprom, offset, num_bytes, write_buffer)

try:
sysfsfile_eeprom.close()
except:
return False

return True

def _is_valid_port(self, port_num):
if port_num >= self.port_start and port_num <= self.port_end:
return True
Expand Down

0 comments on commit df61c55

Please sign in to comment.