Dell: S6100 fix xcvrd crash (#9206)

This commit is contained in:
Aravind Mani 2021-11-10 20:13:26 +05:30 committed by GitHub
parent e2bffdf9e7
commit b31220530a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -12,11 +12,12 @@ try:
import re
import struct
import time
import syslog
from sonic_platform_base.sfp_base import SfpBase
from sonic_platform_base.sonic_sfp.sff8436 import sff8436InterfaceId
from sonic_platform_base.sonic_sfp.sff8436 import sff8436Dom
except ImportError as e:
raise ImportError(str(e) + "- required module not found")
except ImportError as err:
raise ImportError(str(err) + "- required module not found")
PAGE_OFFSET = 0
@ -422,15 +423,11 @@ class Sfp(SfpBase):
presence_ctrl = self.sfp_control + 'qsfp_modprs'
try:
reg_file = open(presence_ctrl)
except IOError as e:
return False
reg_hex = reg_file.readline().rstrip()
# content is a string containing the hex
# representation of the register
reg_value = int(reg_hex, 16)
# Mask off the bit corresponding to our port
if (self.sfp_ctrl_idx > 15):
index = self.sfp_ctrl_idx % 16
@ -439,11 +436,11 @@ class Sfp(SfpBase):
# Mask off the bit corresponding to our port
mask = (1 << index)
# ModPrsL is active low
if ((reg_value & mask) == 0):
return True
except (IOError, ValueError) as err:
syslog.syslog(syslog.LOG_ERR, str(err))
return False
def get_model(self):
@ -478,15 +475,11 @@ class Sfp(SfpBase):
reset_ctrl = self.sfp_control + 'qsfp_reset'
try:
reg_file = open(reset_ctrl, "r+")
except IOError as e:
return False
reg_hex = reg_file.readline().rstrip()
# content is a string containing the hex
# representation of the register
reg_value = int(reg_hex, 16)
# Mask off the bit corresponding to our port
if (self.sfp_ctrl_idx > 15):
index = self.sfp_ctrl_idx % 16
@ -500,6 +493,9 @@ class Sfp(SfpBase):
else:
reset_status = False
except (IOError, ValueError) as err:
syslog.syslog(syslog.LOG_ERR, str(err))
return False
return reset_status
def get_rx_los(self):
@ -615,8 +611,6 @@ class Sfp(SfpBase):
lpmode_ctrl = self.sfp_control + 'qsfp_lpmode'
try:
reg_file = open(lpmode_ctrl, "r+")
except IOError as e:
return False
reg_hex = reg_file.readline().rstrip()
@ -637,6 +631,10 @@ class Sfp(SfpBase):
else:
lpmode_state = True
except (IOError, ValueError) as err:
syslog.syslog(syslog.LOG_ERR, str(err))
return False
return lpmode_state
def get_power_override(self):
@ -731,12 +729,9 @@ class Sfp(SfpBase):
try:
# Open reset_ctrl in both read & write mode
reg_file = open(reset_ctrl, "r+")
except IOError as e:
return False
reg_hex = reg_file.readline().rstrip()
reg_value = int(reg_hex, 16)
# Mask off the bit corresponding to our port
if (self.sfp_ctrl_idx > 15):
index = self.sfp_ctrl_idx % 16
@ -757,19 +752,18 @@ class Sfp(SfpBase):
# Sleep 1 second to allow it to settle
time.sleep(1)
# Flip the bit back high and write back to the
# register to take port out of reset
try:
reg_file = open(reset_ctrl, "w")
except IOError as e:
return False
reg_value = reg_value | mask
reg_file.seek(0)
reg_file.write(hex(reg_value))
reg_file.close()
except (IOError, ValueError) as err:
syslog.syslog(syslog.LOG_ERR, str(err))
return False
return True
def set_lpmode(self, lpmode):
@ -779,11 +773,8 @@ class Sfp(SfpBase):
lpmode_ctrl = self.sfp_control + 'qsfp_lpmode'
try:
reg_file = open(lpmode_ctrl, "r+")
except IOError as e:
return False
reg_hex = reg_file.readline().rstrip()
# content is a string containing the hex
# representation of the register
reg_value = int(reg_hex, 16)
@ -808,6 +799,9 @@ class Sfp(SfpBase):
reg_file.seek(0)
reg_file.write(content)
reg_file.close()
except (IOError, ValueError) as err:
syslog.syslog(syslog.LOG_ERR, str(err))
return False
return True