Skip to content

Commit f07181e

Browse files
roylee123lguohan
authored andcommitted
[201807][platform] Accton: As5712-54x. Fix sfputil and accton_util (#2002)
* [platform] accton as5712-54x, fixed 1. Check i2c buses, they may get fliped on every bootup. 2. QSFP's lp_mode and reset are out of port order. 3. Change QSFP is reset with 1 second period. Signed-off-by: roy_lee <[email protected]> * [platform] accton as5712-54x. Fix util.py error about SFP/QSFP's tx_disable and present. Signed-off-by: roy_lee <[email protected]>
1 parent 5e48e6c commit f07181e

File tree

2 files changed

+54
-14
lines changed

2 files changed

+54
-14
lines changed

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

+53-13
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@
22
#
33
# Platform-specific SFP transceiver interface for SONiC
44
#
5-
65
try:
76
import time
7+
import os
88
from sonic_sfp.sfputilbase import SfpUtilBase
99
except ImportError as e:
1010
raise ImportError("%s - required module not found" % str(e))
@@ -21,8 +21,14 @@ class SfpUtil(SfpUtilBase):
2121

2222
BASE_VAL_PATH = "/sys/class/i2c-adapter/i2c-{0}/{1}-0050/"
2323
BASE_OOM_PATH = "/sys/bus/i2c/devices/{0}-0050/"
24-
BASE_CPLD2_PATH = "/sys/bus/i2c/devices/0-0061/"
25-
BASE_CPLD3_PATH = "/sys/bus/i2c/devices/0-0062/"
24+
BASE_CPLD2_PATH = "/sys/bus/i2c/devices/{0}-0061/"
25+
BASE_CPLD3_PATH = "/sys/bus/i2c/devices/{0}-0062/"
26+
I2C_BUS_ORDER = -1
27+
28+
#The sidebands of QSFP is different.
29+
#present is in-order.
30+
#But lp_mode and reset are not.
31+
qsfp_sb_map = [1, 3, 5, 2, 4, 6]
2632

2733
_port_to_is_present = {}
2834
_port_to_lp_mode = {}
@@ -137,18 +143,30 @@ def __init__(self):
137143

138144
SfpUtilBase.__init__(self)
139145

146+
#Two i2c buses might get flipped order, check them both.
147+
def update_i2c_order(self):
148+
if self.I2C_BUS_ORDER < 0:
149+
eeprom_path = "/sys/bus/i2c/devices/1-0057/eeprom"
150+
if os.path.exists(eeprom_path):
151+
self.I2C_BUS_ORDER = 0
152+
eeprom_path = "/sys/bus/i2c/devices/0-0057/eeprom"
153+
if os.path.exists(eeprom_path):
154+
self.I2C_BUS_ORDER = 1
155+
return self.I2C_BUS_ORDER
156+
140157
def get_presence(self, port_num):
141158
# Check for invalid port_num
142159
if port_num < self.port_start or port_num > self.port_end:
143160
return False
144161

162+
order = self.update_i2c_order()
145163
if port_num < 24:
146-
present_path = self.BASE_CPLD2_PATH + "module_present_" + str(self._port_to_i2c_mapping[port_num][0])
164+
present_path = self.BASE_CPLD2_PATH.format(order)
147165
else:
148-
present_path = self.BASE_CPLD3_PATH + "module_present_" + str(self._port_to_i2c_mapping[port_num][0])
166+
present_path = self.BASE_CPLD3_PATH.format(order)
149167

168+
present_path = present_path + "module_present_" + str(self._port_to_i2c_mapping[port_num][0])
150169
self.__port_to_is_present = present_path
151-
152170

153171
try:
154172
val_file = open(self.__port_to_is_present)
@@ -165,11 +183,21 @@ def get_presence(self, port_num):
165183

166184
return False
167185

186+
def qsfp_sb_remap(self, port_num):
187+
qsfp_start = self.qsfp_port_start
188+
qsfp_index = self._port_to_i2c_mapping[port_num][0] - qsfp_start
189+
qsfp_index = self.qsfp_sb_map[qsfp_index-1]
190+
return qsfp_start+qsfp_index
191+
168192
def get_low_power_mode(self, port_num):
169193
if port_num < self.qsfp_port_start or port_num > self.qsfp_port_end:
170194
return False
171195

172-
lp_mode_path = self.BASE_CPLD3_PATH + "module_lp_mode_" + str(self._port_to_i2c_mapping[port_num][0])
196+
order = self.update_i2c_order()
197+
lp_mode_path = self.BASE_CPLD3_PATH.format(order)
198+
lp_mode_path = lp_mode_path + "module_lp_mode_"
199+
q = self.qsfp_sb_remap(port_num)
200+
lp_mode_path = lp_mode_path + str(q)
173201

174202
try:
175203
val_file = open(lp_mode_path)
@@ -190,7 +218,11 @@ def set_low_power_mode(self, port_num, lpmode):
190218
if port_num < self.qsfp_port_start or port_num > self.qsfp_port_end:
191219
return False
192220

193-
lp_mode_path = self.BASE_CPLD3_PATH + "module_lp_mode_" + str(self._port_to_i2c_mapping[port_num][0])
221+
order = self.update_i2c_order()
222+
lp_mode_path = self.BASE_CPLD3_PATH.format(order)
223+
lp_mode_path = lp_mode_path + "module_lp_mode_"
224+
q = self.qsfp_sb_remap(port_num)
225+
lp_mode_path = lp_mode_path + str(q)
194226

195227
try:
196228
reg_file = open(lp_mode_path, 'r+')
@@ -212,17 +244,25 @@ def reset(self, port_num):
212244
if port_num < self.qsfp_port_start or port_num > self.qsfp_port_end:
213245
return False
214246

215-
mod_rst_path = lp_mode_path = self.BASE_CPLD3_PATH + "module_reset_" + str(self._port_to_i2c_mapping[port_num][0])
247+
order = self.update_i2c_order()
248+
lp_mode_path = self.BASE_CPLD3_PATH.format(order)
249+
mod_rst_path = lp_mode_path + "module_reset_"
250+
q = self.qsfp_sb_remap(port_num)
251+
mod_rst_path = mod_rst_path + str(q)
216252

217253
try:
218254
reg_file = open(mod_rst_path, 'r+')
219255
except IOError as e:
220256
print "Error: unable to open file: %s" % str(e)
221257
return False
222258

223-
reg_value = '1'
224-
225-
reg_file.write(reg_value)
259+
#toggle reset
260+
reg_file.seek(0)
261+
reg_file.write('0')
262+
time.sleep(1)
263+
reg_file.seek(0)
264+
reg_file.write('1')
226265
reg_file.close()
266+
return True
227267

228-
return True
268+
return True

0 commit comments

Comments
 (0)