Skip to content

Commit

Permalink
CSCwc62380: 202012 qsfpdd eeprom corruption fixes (zhenggen-xu#8)
Browse files Browse the repository at this point in the history
* CSCwc62380: Fix incorrect qsfpdd eeprom page change causing link issue

Signed-off-by: ankgoyal <ankgoyal@cisco.com>

* CSCwc74647: Add qsfpdd eeprom file locking changes in device plugin code

Signed-off-by: ankgoyal <ankgoyal@cisco.com>

* CSCwc62380: address review comments

Signed-off-by: ankgoyal <ankgoyal@cisco.com>

* CSCwc74647: address review comments

Signed-off-by: ankgoyal <ankgoyal@cisco.com>

Signed-off-by: ankgoyal <ankgoyal@cisco.com>
  • Loading branch information
ankgoyal27 authored Aug 24, 2022
1 parent 31465e6 commit c2f3ac6
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 14 deletions.
31 changes: 22 additions & 9 deletions device/cisco/x86_64-cisco_N3K_C3432D/plugins/qsfpdd.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
from collections import OrderedDict
import re
from sonic_sfp.sffbase import sffbase
from sonic_platform.utils import xcvr_eeprom_rw_unlock
from sonic_platform.utils import xcvr_eeprom_rw_lock
except ImportError as e:
raise ImportError (str(e) + "- required module not found")

Expand Down Expand Up @@ -698,7 +700,7 @@ def dom_voltage_supported(self, eeprom_data, eeprom_ele):
'decode': dom_monitor}}


PORT_START = 50
EEPROM_OFFSET = 50
def read_bytes(self, sysfs_eeprom_path, offset, num_bytes):
#offset=128
#num_bytes=128
Expand Down Expand Up @@ -730,9 +732,9 @@ def read_bytes(self, sysfs_eeprom_path, offset, num_bytes):

def get_qsfpdd_page_data(self, eeprom_ele, start_pos):

sysfs_eeprom_path="/sys/bus/i2c/devices/%d-0050/eeprom" % (self.port + self.PORT_START)
sysfs_eeprom_path="/sys/bus/i2c/devices/%d-0050/eeprom" % (self.port + self.EEPROM_OFFSET)

page = None
page = 0
offset=128
num_bytes=128

Expand All @@ -746,8 +748,6 @@ def get_qsfpdd_page_data(self, eeprom_ele, start_pos):

sfp_log("Upper page %d not cached" % (page))

#set upper page
os.system("/usr/sbin/i2cset -y -f %d 0x50 127 %d b" % (self.port + self.PORT_START, page))
else:
#Lower page should be already cached
if 'lpage' in self.page_data:
Expand All @@ -758,7 +758,14 @@ def get_qsfpdd_page_data(self, eeprom_ele, start_pos):
sfp_log("Lower page not cached")
return None

fd=xcvr_eeprom_rw_lock(self.port)
if fd is None:
print("Unable to acquire lock to read qsfpdd page data for port %d" % self.port)
return None
#set upper page
os.system("/usr/sbin/i2cset -y -f %d 0x50 127 %d b" % (self.port + self.EEPROM_OFFSET, page))
eeprom_raw = self.read_bytes(sysfs_eeprom_path, offset, num_bytes)
xcvr_eeprom_rw_unlock(fd)
if page is not None and eeprom_raw is not None:
self.page_data[page] = eeprom_raw
#cache lower page
Expand All @@ -783,8 +790,16 @@ def parse_sff_element(self, eeprom_data, eeprom_ele, start_pos):
return None

def get_lower_page(self):
sysfs_eeprom_path="/sys/bus/i2c/devices/%d-0050/eeprom" % (self.port + self.PORT_START)
return self.read_bytes(sysfs_eeprom_path, 0, 128)
fd=xcvr_eeprom_rw_lock(self.port)
if fd is None:
print("Unable to acquire lock to get qsfpdd lower page data for port %d" % self.port)
return None
# Set page 0 for port self.port
os.system("/usr/sbin/i2cset -y -f %d 0x50 127 0x0 b" % (self.port + self.EEPROM_OFFSET))
sysfs_eeprom_path="/sys/bus/i2c/devices/%d-0050/eeprom" % (self.port + self.EEPROM_OFFSET)
eeprom_raw = self.read_bytes(sysfs_eeprom_path, 0, 128)
xcvr_eeprom_rw_unlock(fd)
return eeprom_raw

def __init__(self, port, sfp_data=None, eeprom_raw_data=None, calibration_type=1):
self._calibration_type = calibration_type
Expand Down Expand Up @@ -816,8 +831,6 @@ def __init__(self, port, sfp_data=None, eeprom_raw_data=None, calibration_type=1
self.dom_data = sffbase.parse(self, self.dom_map,
eeprom_raw_data, start_pos)

os.system("/usr/sbin/i2cset -y -f %d 0x50 127 0x0 b" % (self.port + self.PORT_START))

#print(self.dom_data)

def parse(self, eeprom_raw_data, start_pos):
Expand Down
22 changes: 19 additions & 3 deletions device/cisco/x86_64-cisco_N3K_C3432D/plugins/sfputil.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
import time
from sonic_sfp.sfputilbase import SfpUtilBase
from sonic_eeprom import eeprom_dts
from sonic_platform.utils import xcvr_eeprom_rw_unlock
from sonic_platform.utils import xcvr_eeprom_rw_lock
import sys

# import syslog
Expand Down Expand Up @@ -205,11 +207,17 @@ def reset_page(self, port_num, page):

def get_eeprom_dict(self, port_num):

# Ensure page zero is set
# Acquire lock and ensure page zero is set
if port_num in self.osfp_ports:
fd=xcvr_eeprom_rw_lock(port_num)
if fd is None:
print("Unable to acquire lock to get eeprom data for port %d" % port_num)
return None
self.reset_page(port_num, 0)

sfp_data = super(SfpUtilCisco, self).get_eeprom_dict(port_num)
sfp_data = super(SfpUtilCisco, self).get_eeprom_dict(port_num)
xcvr_eeprom_rw_unlock(fd)
else:
sfp_data = super(SfpUtilCisco, self).get_eeprom_dict(port_num)

if sfp_data is None:
return sfp_data
Expand Down Expand Up @@ -342,7 +350,15 @@ def qsfp_find_port_type(self, p, offset=0):
sfp_log("Port:%d not present" % p)
return

# Acquire lock and ensure page zero is set
fd=xcvr_eeprom_rw_lock(p)
if fd is None:
sfp_log("Unable to acquire lock to get port type for port %d" % p)
return None
# set page 0 for port p
os.system("/usr/sbin/i2cset -y -f %d 0x50 127 %d b" % (p + self.EEPROM_OFFSET, 0))
eeprom_ifraw = self.get_eeprom_raw(p)
xcvr_eeprom_rw_unlock(fd)
#sfp_log(eeprom_ifraw)
if eeprom_ifraw is None:
return
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -839,8 +839,6 @@ def __init__(self, port, sfp_data=None, eeprom_raw_data=None, calibration_type=1
self.dom_data = super(qsfpddDom, self).parse(self.dom_map,
eeprom_raw_data, start_pos)

os.system("/usr/sbin/i2cset -y -f %d 0x50 127 0x0 b" % (self.port + self.PORT_START))

sfp_log(self.dom_data)

def dump_pretty(self):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -862,6 +862,7 @@ def set_power_override(self, port_num, power_override, power_set):
if fd is None:
logger.log_error("Unable to acquire lock in set_power_override for port {}".format(port_num))
return status
self.reset_page(port_num, 0)
run_cmd = '/usr/sbin/i2cset -y -f ' + str(self.EEPROM_OFFSET + port_num) + ' 0x' + str(self.EEPROM_OFFSET) + ' ' + str(QSFP_DD_GLOBAL_CONTROL_BYTES_OFFSET ) + ' ' + str(hex(data))
os.system(run_cmd)
status = True
Expand Down

0 comments on commit c2f3ac6

Please sign in to comment.