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

* Add lpmode set/get . mode_reset feature for qsfp

* Add lp mode, set/get and mode_rst feature for sfp
This commit is contained in:
jostar-yang 2017-12-21 17:54:32 +08:00 committed by lguohan
parent eadd74fb84
commit db49660b86
2 changed files with 71 additions and 7 deletions

View File

@ -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 = {
@ -107,6 +108,14 @@ class SfpUtil(SfpUtilBase):
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)
@ -149,10 +158,65 @@ class SfpUtil(SfpUtilBase):
return False
def get_low_power_mode(self, port_num):
raise NotImplementedError
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
return False
def set_low_power_mode(self, port_num, lpmode):
raise NotImplementedError
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

@ -1 +1 @@
Subproject commit 7ba26ec403c7f0d0acb958f794311ac3fd1af9a1
Subproject commit 7c39d916d2b5d248c8067669e72b75ed7240b348