Skip to content

Commit db49660

Browse files
jostar-yanglguohan
authored andcommitted
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
1 parent eadd74f commit db49660

2 files changed

Lines changed: 71 additions & 7 deletions

File tree

device/accton/x86_64-accton_as5712_54x-r0/plugins/sfputil.py

Lines changed: 70 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,13 @@ class SfpUtil(SfpUtilBase):
1616
PORT_START = 0
1717
PORT_END = 71
1818
PORTS_IN_BLOCK = 72
19-
QSFP_PORT_START = 72
19+
QSFP_PORT_START = 48
2020
QSFP_PORT_END = 72
2121

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

2424
_port_to_is_present = {}
25+
_port_to_lp_mode = {}
2526

2627
_port_to_eeprom_mapping = {}
2728
_port_to_i2c_mapping = {
@@ -107,6 +108,14 @@ def port_start(self):
107108
def port_end(self):
108109
return self.PORT_END
109110

111+
@property
112+
def qsfp_port_start(self):
113+
return self.QSFP_PORT_START
114+
115+
@property
116+
def qsfp_port_end(self):
117+
return self.QSFP_PORT_END
118+
110119
@property
111120
def qsfp_ports(self):
112121
return range(self.QSFP_PORT_START, self.PORTS_IN_BLOCK + 1)
@@ -148,11 +157,66 @@ def get_presence(self, port_num):
148157

149158
return False
150159

151-
def get_low_power_mode(self, port_num):
152-
raise NotImplementedError
160+
def get_low_power_mode(self, port_num):
161+
if port_num < self.qsfp_port_start or port_num > self.qsfp_port_end:
162+
return False
163+
164+
lp_mode_path = self.BASE_VAL_PATH + "sfp_lp_mode"
165+
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])
166+
167+
try:
168+
val_file = open(self.__port_to_lp_mode)
169+
except IOError as e:
170+
print "Error: unable to open file: %s" % str(e)
171+
return False
172+
173+
content = val_file.readline().rstrip()
174+
val_file.close()
175+
176+
# content is a string, either "0" or "1"
177+
if content == "1":
178+
return True
153179

154-
def set_low_power_mode(self, port_num, lpmode):
155-
raise NotImplementedError
180+
return False
181+
182+
def set_low_power_mode(self, port_num, lpmode):
183+
if port_num < self.qsfp_port_start or port_num > self.qsfp_port_end:
184+
return False
185+
186+
lp_mode_path = self.BASE_VAL_PATH + "sfp_lp_mode"
187+
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])
188+
189+
try:
190+
reg_file = open(self.__port_to_lp_mode, 'r+')
191+
except IOError as e:
192+
print "Error: unable to open file: %s" % str(e)
193+
return False
194+
195+
if lpmode is True:
196+
reg_value = '1'
197+
else:
198+
reg_value = '0'
199+
200+
reg_file.write(reg_value)
201+
reg_file.close()
202+
203+
return True
156204

157205
def reset(self, port_num):
158-
raise NotImplementedError
206+
if port_num < self.qsfp_port_start or port_num > self.qsfp_port_end:
207+
return False
208+
209+
mod_rst_path = self.BASE_VAL_PATH + "sfp_mod_rst"
210+
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])
211+
try:
212+
reg_file = open(self.__port_to_mod_rst, 'r+')
213+
except IOError as e:
214+
print "Error: unable to open file: %s" % str(e)
215+
return False
216+
217+
reg_value = '1'
218+
219+
reg_file.write(reg_value)
220+
reg_file.close()
221+
222+
return True

0 commit comments

Comments
 (0)