Skip to content

Commit

Permalink
[device/celestica]: fix utilities tools error
Browse files Browse the repository at this point in the history
* [device/celestica]: fix sfputil

* [device/celestica]: fix firmware util
  • Loading branch information
Wirut Getbamrung authored May 17, 2021
1 parent f5f9b35 commit 6f65438
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 56 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"chassis": {
"E1031": {
"Celestica-E1031-T48S4": {
"component": {
"BIOS": {},
"SMC_CPLD": {},
Expand Down
61 changes: 8 additions & 53 deletions device/celestica/x86_64-cel_e1031-r0/plugins/sfputil.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,63 +11,17 @@ class SfpUtil(SfpUtilBase):
"""Platform-specific SfpUtil class"""

PORT_START = 1
PORT_END = 52
PORT_END = 55
SFP_PORT_START = 49
SFP_PORT_END = 52
port_to_i2c_mapping = {
1: None,
2: None,
3: None,
4: None,
5: None,
6: None,
7: None,
8: None,
9: None,
10: None,
11: None,
12: None,
13: None,
14: None,
15: None,
16: None,
17: None,
18: None,
19: None,
20: None,
21: None,
22: None,
23: None,
24: None,
25: None,
26: None,
27: None,
28: None,
29: None,
30: None,
31: None,
32: None,
33: None,
34: None,
35: None,
36: None,
37: None,
38: None,
39: None,
40: None,
41: None,
42: None,
43: None,
44: None,
45: None,
46: None,
47: None,
48: None,
49: 15,
50: 14,
51: 17,
52: 16
}
_port_to_eeprom_mapping = {}
_sfp_port = list(range(49, PORT_END + 1))
_sfp_port = list(range(SFP_PORT_START, SFP_PORT_END + 1))

@property
def port_start(self):
Expand All @@ -89,7 +43,7 @@ def __init__(self):
# Override port_to_eeprom_mapping for class initialization
eeprom_path = '/sys/bus/i2c/devices/i2c-{0}/{0}-0050/eeprom'
for x in range(self.PORT_START, self.PORT_END + 1):
port_eeprom_path = eeprom_path.format(self.port_to_i2c_mapping[x])
port_eeprom_path = eeprom_path.format(self.port_to_i2c_mapping[x]) if x in self._sfp_port else None
self.port_to_eeprom_mapping[x] = port_eeprom_path
SfpUtilBase.__init__(self)

Expand All @@ -103,7 +57,7 @@ def get_presence(self, port_num):
try:
with open(sfp_modabs_path, 'r') as port_status:
status = int(port_status.read(), 16)
status = (status >> (port_num - 49)) & 1
status = (status >> (port_num - self.SFP_PORT_START)) & 1
except IOError:
return False

Expand Down Expand Up @@ -138,7 +92,8 @@ def get_transceiver_change_event(self, timeout=0):
for port_num in self._sfp_port:
change = (changes >> (port_num - 49)) & 1
if change == 1:
port_dict[str(port_num)] = str(int(self.get_presence(port_num)))
port_dict[str(port_num)] = str(
int(self.get_presence(port_num)))
found_flag = 1

if not found_flag:
Expand Down
8 changes: 6 additions & 2 deletions device/celestica/x86_64-cel_e1031-r0/sonic_platform/sfp.py
Original file line number Diff line number Diff line change
Expand Up @@ -242,8 +242,12 @@ def __read_eeprom_specific_bytes(self, offset, num_bytes):
sysfs_sfp_i2c_client_eeprom_path, mode="rb", buffering=0)
sysfsfile_eeprom.seek(offset)
raw = sysfsfile_eeprom.read(num_bytes)
for n in range(0, num_bytes):
eeprom_raw[n] = hex(ord(raw[n]))[2:].zfill(2)
if isinstance(raw, str):
for n in range(0, num_bytes):
eeprom_raw[n] = hex(ord(raw[n]))[2:].zfill(2)
else:
for n in range(0, num_bytes):
eeprom_raw[n] = hex(raw[n])[2:].zfill(2)
except BaseException:
pass
finally:
Expand Down

0 comments on commit 6f65438

Please sign in to comment.