2
2
#
3
3
# Platform-specific SFP transceiver interface for SONiC
4
4
#
5
-
6
5
try :
7
6
import time
7
+ import os
8
8
from sonic_sfp .sfputilbase import SfpUtilBase
9
9
except ImportError as e :
10
10
raise ImportError ("%s - required module not found" % str (e ))
@@ -21,8 +21,14 @@ class SfpUtil(SfpUtilBase):
21
21
22
22
BASE_VAL_PATH = "/sys/class/i2c-adapter/i2c-{0}/{1}-0050/"
23
23
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 ]
26
32
27
33
_port_to_is_present = {}
28
34
_port_to_lp_mode = {}
@@ -137,18 +143,30 @@ def __init__(self):
137
143
138
144
SfpUtilBase .__init__ (self )
139
145
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
+
140
157
def get_presence (self , port_num ):
141
158
# Check for invalid port_num
142
159
if port_num < self .port_start or port_num > self .port_end :
143
160
return False
144
161
162
+ order = self .update_i2c_order ()
145
163
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 )
147
165
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 )
149
167
168
+ present_path = present_path + "module_present_" + str (self ._port_to_i2c_mapping [port_num ][0 ])
150
169
self .__port_to_is_present = present_path
151
-
152
170
153
171
try :
154
172
val_file = open (self .__port_to_is_present )
@@ -165,11 +183,21 @@ def get_presence(self, port_num):
165
183
166
184
return False
167
185
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
+
168
192
def get_low_power_mode (self , port_num ):
169
193
if port_num < self .qsfp_port_start or port_num > self .qsfp_port_end :
170
194
return False
171
195
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 )
173
201
174
202
try :
175
203
val_file = open (lp_mode_path )
@@ -190,7 +218,11 @@ def set_low_power_mode(self, port_num, lpmode):
190
218
if port_num < self .qsfp_port_start or port_num > self .qsfp_port_end :
191
219
return False
192
220
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 )
194
226
195
227
try :
196
228
reg_file = open (lp_mode_path , 'r+' )
@@ -212,25 +244,32 @@ def reset(self, port_num):
212
244
if port_num < self .qsfp_port_start or port_num > self .qsfp_port_end :
213
245
return False
214
246
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 )
216
252
217
253
try :
218
254
reg_file = open (mod_rst_path , 'r+' )
219
255
except IOError as e :
220
256
print "Error: unable to open file: %s" % str (e )
221
257
return False
222
258
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' )
226
265
reg_file .close ()
227
-
228
266
return True
229
-
267
+
230
268
def get_transceiver_change_event (self ):
231
269
"""
232
270
TODO: This function need to be implemented
233
271
when decide to support monitoring SFP(Xcvrd)
234
272
on this platform.
235
273
"""
236
274
raise NotImplementedError
275
+
0 commit comments