16
16
class SfpUtil (SfpUtilBase ):
17
17
"""Platform-specific SfpUtil class"""
18
18
19
- PORT_START = 0
20
- PORT_END = 31
19
+ PORT_START = 1
20
+ PORT_END = 32
21
21
PORTS_IN_BLOCK = 32
22
- IOM_1_PORT_START = 0
23
- IOM_1_PORT_END = 11
24
- IOM_2_PORT_START = 12
25
- IOM_2_PORT_END = 21
26
- IOM_3_PORT_START = 22
27
- IOM_3_PORT_END = 31
22
+ IOM_1_PORT_START = 1
23
+ IOM_1_PORT_END = 12
24
+ IOM_2_PORT_START = 13
25
+ IOM_2_PORT_END = 22
26
+ IOM_3_PORT_START = 23
27
+ IOM_3_PORT_END = 32
28
28
29
29
BASE_VAL_PATH = "/sys/class/i2c-adapter/i2c-{0}/{0}-003e/"
30
30
OIR_FD_PATH = "/sys/devices/platform/dell_ich.0/sci_int_gpio_sus6"
@@ -33,38 +33,39 @@ class SfpUtil(SfpUtilBase):
33
33
epoll = - 1
34
34
_port_to_eeprom_mapping = {}
35
35
_port_to_i2c_mapping = {
36
- 0 : [9 , 18 ],
37
- 1 : [9 , 19 ],
38
- 2 : [9 , 20 ],
39
- 3 : [9 , 21 ],
40
- 4 : [9 , 22 ],
41
- 5 : [9 , 23 ],
42
- 6 : [9 , 24 ],
43
- 7 : [9 , 25 ],
44
- 8 : [8 , 26 ],
45
- 9 : [8 , 27 ],
46
- 10 : [8 , 28 ],
47
- 11 : [8 , 29 ],
48
- 12 : [8 , 31 ], # reordered
49
- 13 : [8 , 30 ],
50
- 14 : [8 , 33 ], # reordered
51
- 15 : [8 , 32 ],
52
- 16 : [7 , 34 ],
53
- 17 : [7 , 35 ],
54
- 18 : [7 , 36 ],
55
- 19 : [7 , 37 ],
56
- 20 : [7 , 38 ],
57
- 21 : [7 , 39 ],
58
- 22 : [7 , 40 ],
59
- 23 : [7 , 41 ],
60
- 24 : [6 , 42 ],
61
- 25 : [6 , 43 ],
62
- 26 : [6 , 44 ],
63
- 27 : [6 , 45 ],
64
- 28 : [6 , 46 ],
65
- 29 : [6 , 47 ],
66
- 30 : [6 , 48 ],
67
- 31 : [6 , 49 ]
36
+ 0 : [0 , 00 ], # Dummy Entry
37
+ 1 : [9 , 18 ],
38
+ 2 : [9 , 19 ],
39
+ 3 : [9 , 20 ],
40
+ 4 : [9 , 21 ],
41
+ 5 : [9 , 22 ],
42
+ 6 : [9 , 23 ],
43
+ 7 : [9 , 24 ],
44
+ 8 : [9 , 25 ],
45
+ 9 : [8 , 26 ],
46
+ 10 : [8 , 27 ],
47
+ 11 : [8 , 28 ],
48
+ 12 : [8 , 29 ],
49
+ 13 : [8 , 31 ], # reordered
50
+ 14 : [8 , 30 ],
51
+ 15 : [8 , 33 ], # reordered
52
+ 16 : [8 , 32 ],
53
+ 17 : [7 , 34 ],
54
+ 18 : [7 , 35 ],
55
+ 19 : [7 , 36 ],
56
+ 20 : [7 , 37 ],
57
+ 21 : [7 , 38 ],
58
+ 22 : [7 , 39 ],
59
+ 23 : [7 , 40 ],
60
+ 24 : [7 , 41 ],
61
+ 25 : [6 , 42 ],
62
+ 26 : [6 , 43 ],
63
+ 27 : [6 , 44 ],
64
+ 28 : [6 , 45 ],
65
+ 29 : [6 , 46 ],
66
+ 30 : [6 , 47 ],
67
+ 31 : [6 , 48 ],
68
+ 32 : [6 , 49 ]
68
69
}
69
70
70
71
@property
@@ -127,13 +128,10 @@ def __del__(self):
127
128
self .epoll .close ()
128
129
self .oir_fd .close ()
129
130
130
- def get_presence (self , port_num ):
131
-
132
- global i2c_line
133
-
131
+ def normalize_port (self , port_num ):
134
132
# Check for invalid port_num
135
133
if port_num < self .port_start or port_num > self .port_end :
136
- return False
134
+ return - 1 , - 1
137
135
# port_num and i2c match
138
136
if port_num >= self .iom1_port_start and port_num <= self .iom1_port_end :
139
137
i2c_line = 14
@@ -144,6 +142,24 @@ def get_presence(self, port_num):
144
142
port_num <= self .iom3_port_end ):
145
143
i2c_line = 16
146
144
145
+ # Rationalize port settings
146
+ if port_num >= self .iom1_port_start and port_num <= self .iom1_port_end :
147
+ port_num = port_num - 1
148
+ elif port_num >= self .iom2_port_start and port_num <= self .iom2_port_end :
149
+ port_num = (port_num - 1 ) % 12
150
+ elif (port_num >= self .iom3_port_start and
151
+ port_num <= self .iom3_port_end ):
152
+ port_num = (port_num - 1 ) % 22
153
+
154
+ return i2c_line , port_num
155
+
156
+
157
+ def get_presence (self , port_num ):
158
+
159
+ i2c_line , port_num = self .normalize_port (port_num )
160
+ if port_num == - 1 :
161
+ return False
162
+
147
163
try :
148
164
qsfp_path = self .BASE_VAL_PATH .format (i2c_line )+ "qsfp_modprs"
149
165
reg_file = open (qsfp_path , "r" )
@@ -161,13 +177,6 @@ def get_presence(self, port_num):
161
177
# content is a string containing the hex representation of the register
162
178
reg_value = int (content , 16 )
163
179
164
- # Rationalize port settings
165
- if port_num >= self .iom2_port_start and port_num <= self .iom2_port_end :
166
- port_num = port_num % 12
167
- elif (port_num >= self .iom3_port_start and
168
- port_num <= self .iom3_port_end ):
169
- port_num = port_num % 22
170
-
171
180
# Mask off the bit corresponding to our port
172
181
mask = (1 << port_num )
173
182
@@ -179,20 +188,10 @@ def get_presence(self, port_num):
179
188
180
189
def get_low_power_mode (self , port_num ):
181
190
182
- # Check for invalid port_num
183
- if port_num < self . port_start or port_num > self . port_end :
191
+ i2c_line , port_num = self . normalize_port ( port_num )
192
+ if port_num == - 1 :
184
193
return False
185
194
186
- # port_num and i2c match
187
- if port_num >= self .iom1_port_start and port_num <= self .iom1_port_end :
188
- i2c_line = 14
189
- elif (port_num >= self .iom2_port_start and
190
- port_num <= self .iom2_port_end ):
191
- i2c_line = 15
192
- elif (port_num >= self .iom3_port_start and
193
- port_num <= self .iom3_port_end ):
194
- i2c_line = 16
195
-
196
195
try :
197
196
qsfp_path = self .BASE_VAL_PATH .format (i2c_line )+ "qsfp_lpmode"
198
197
reg_file = open (qsfp_path , "r" )
@@ -210,13 +209,6 @@ def get_low_power_mode(self, port_num):
210
209
# content is a string containing the hex representation of the register
211
210
reg_value = int (content , 16 )
212
211
213
- # Rationalize port settings
214
- if port_num >= self .iom2_port_start and port_num <= self .iom2_port_end :
215
- port_num = port_num % 12
216
- elif (port_num >= self .iom3_port_start and
217
- port_num <= self .iom3_port_end ):
218
- port_num = port_num % 22
219
-
220
212
# Mask off the bit corresponding to our port
221
213
mask = (1 << port_num )
222
214
@@ -228,24 +220,15 @@ def get_low_power_mode(self, port_num):
228
220
229
221
def set_low_power_mode (self , port_num , lpmode ):
230
222
231
- # Check for invalid port_num
232
- if port_num < self . port_start or port_num > self . port_end :
223
+ i2c_line , port_num = self . normalize_port ( port_num )
224
+ if port_num == - 1 :
233
225
return False
234
226
235
- # port_num and i2c match
236
- if port_num >= self .iom1_port_start and port_num <= self .iom1_port_end :
237
- i2c_line = 14
238
- elif (port_num >= self .iom2_port_start and
239
- port_num <= self .iom2_port_end ):
240
- i2c_line = 15
241
- elif (port_num >= self .iom3_port_start and
242
- port_num <= self .iom3_port_end ):
243
- i2c_line = 16
244
-
245
227
try :
246
228
qsfp_path = self .BASE_VAL_PATH .format (i2c_line )+ "qsfp_lpmode"
247
229
reg_file = open (qsfp_path , "r+" )
248
230
231
+
249
232
except IOError as e :
250
233
print "Error: unable to open file: %s" % str (e )
251
234
return False
@@ -259,13 +242,6 @@ def set_low_power_mode(self, port_num, lpmode):
259
242
# content is a string containing the hex representation of the register
260
243
reg_value = int (content , 16 )
261
244
262
- # Rationalize port settings
263
- if port_num >= self .iom2_port_start and port_num <= self .iom2_port_end :
264
- port_num = port_num % 12
265
- elif (port_num >= self .iom3_port_start and
266
- port_num <= self .iom3_port_end ):
267
- port_num = port_num % 22
268
-
269
245
# Mask off the bit corresponding to our port
270
246
mask = (1 << port_num )
271
247
# LPMode is active high; set or clear the bit accordingly
@@ -285,20 +261,10 @@ def set_low_power_mode(self, port_num, lpmode):
285
261
286
262
def reset (self , port_num ):
287
263
288
- # Check for invalid port_num
289
- if port_num < self . port_start or port_num > self . port_end :
264
+ i2c_line , port_num = self . normalize_port ( port_num )
265
+ if port_num == - 1 :
290
266
return False
291
267
292
- # port_num and i2c match
293
- if port_num >= self .iom1_port_start and port_num <= self .iom1_port_end :
294
- i2c_line = 14
295
- elif (port_num >= self .iom2_port_start and
296
- port_num <= self .iom2_port_end ):
297
- i2c_line = 15
298
- elif (port_num >= self .iom3_port_start and
299
- port_num <= self .iom3_port_end ):
300
- i2c_line = 16
301
-
302
268
try :
303
269
qsfp_path = self .BASE_VAL_PATH .format (i2c_line )+ "qsfp_lpmode"
304
270
reg_file = open (qsfp_path , "r+" )
@@ -312,13 +278,6 @@ def reset(self, port_num):
312
278
# File content is a string containing the hex representation of th
313
279
reg_value = int (content , 16 )
314
280
315
- # Rationalize port settings
316
- if port_num >= self .iom2_port_start and port_num <= self .iom2_port_end :
317
- port_num = port_num % 12
318
- elif (port_num >= self .iom3_port_start and
319
- port_num <= self .iom3_port_end ):
320
- port_num = port_num % 22
321
-
322
281
# Mask off the bit corresponding to our port
323
282
mask = (1 << port_num )
324
283
0 commit comments