Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add set/get lpmode and mode_rst feature for qsfp #1261

Merged
merged 2 commits into from
Dec 21, 2017
Merged
Show file tree
Hide file tree
Changes from all 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
76 changes: 70 additions & 6 deletions device/accton/x86_64-accton_as5712_54x-r0/plugins/sfputil.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,13 @@ class SfpUtil(SfpUtilBase):
PORT_START = 0
PORT_END = 71
PORTS_IN_BLOCK = 72
QSFP_PORT_START = 72
QSFP_PORT_START = 48
QSFP_PORT_END = 72

BASE_VAL_PATH = "/sys/class/i2c-adapter/i2c-{0}/{1}-0050/"

_port_to_is_present = {}
_port_to_lp_mode = {}

_port_to_eeprom_mapping = {}
_port_to_i2c_mapping = {
Expand Down Expand Up @@ -107,6 +108,14 @@ def port_start(self):
def port_end(self):
return self.PORT_END

@property
def qsfp_port_start(self):
return self.QSFP_PORT_START

@property
def qsfp_port_end(self):
return self.QSFP_PORT_END

@property
def qsfp_ports(self):
return range(self.QSFP_PORT_START, self.PORTS_IN_BLOCK + 1)
Expand Down Expand Up @@ -148,11 +157,66 @@ def get_presence(self, port_num):

return False

def get_low_power_mode(self, port_num):
raise NotImplementedError
def get_low_power_mode(self, port_num):
if port_num < self.qsfp_port_start or port_num > self.qsfp_port_end:
return False

lp_mode_path = self.BASE_VAL_PATH + "sfp_lp_mode"
self.__port_to_lp_mode = lp_mode_path.format(self._port_to_i2c_mapping[port_num][0], self._port_to_i2c_mapping[port_num][1])

try:
val_file = open(self.__port_to_lp_mode)
except IOError as e:
print "Error: unable to open file: %s" % str(e)
return False

content = val_file.readline().rstrip()
val_file.close()

# content is a string, either "0" or "1"
if content == "1":
return True

def set_low_power_mode(self, port_num, lpmode):
raise NotImplementedError
return False

def set_low_power_mode(self, port_num, lpmode):
if port_num < self.qsfp_port_start or port_num > self.qsfp_port_end:
return False

lp_mode_path = self.BASE_VAL_PATH + "sfp_lp_mode"
self.__port_to_lp_mode = lp_mode_path.format(self._port_to_i2c_mapping[port_num][0], self._port_to_i2c_mapping[port_num][1])

try:
reg_file = open(self.__port_to_lp_mode, 'r+')
except IOError as e:
print "Error: unable to open file: %s" % str(e)
return False

if lpmode is True:
reg_value = '1'
else:
reg_value = '0'

reg_file.write(reg_value)
reg_file.close()

return True

def reset(self, port_num):
raise NotImplementedError
if port_num < self.qsfp_port_start or port_num > self.qsfp_port_end:
return False

mod_rst_path = self.BASE_VAL_PATH + "sfp_mod_rst"
self.__port_to_mod_rst = mod_rst_path.format(self._port_to_i2c_mapping[port_num][0], self._port_to_i2c_mapping[port_num][1])
try:
reg_file = open(self.__port_to_mod_rst, 'r+')
except IOError as e:
print "Error: unable to open file: %s" % str(e)
return False

reg_value = '1'

reg_file.write(reg_value)
reg_file.close()

return True