Skip to content

Commit cf12aa5

Browse files
qnosEric Zhu
authored andcommitted
[hlx/sfp] fix hlx platform sfp+ tx disable issue (#11532)
Why I did it: To fix hlx platform sfp+ module tx disable issue How I did it: Fix sfp+ tx disable function according SFF-8472 specification Co-authored-by: Eric Zhu <[email protected]>
1 parent 1c8c1a6 commit cf12aa5

File tree

1 file changed

+36
-31
lines changed
  • device/celestica/x86_64-cel_e1031-r0/sonic_platform

1 file changed

+36
-31
lines changed

device/celestica/x86_64-cel_e1031-r0/sonic_platform/sfp.py

Lines changed: 36 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
try:
1010
import time
11-
from ctypes import create_string_buffer
11+
from ctypes import c_char
1212
from sonic_platform_base.sfp_base import SfpBase
1313
from sonic_platform_base.sonic_sfp.sff8472 import sff8472InterfaceId
1414
from sonic_platform_base.sonic_sfp.sff8472 import sff8472Dom
@@ -121,8 +121,8 @@
121121
SFP_VOLT_WIDTH = 2
122122
SFP_CHANNL_MON_OFFSET = 100
123123
SFP_CHANNL_MON_WIDTH = 6
124-
SFP_CHANNL_STATUS_OFFSET = 110
125-
SFP_CHANNL_STATUS_WIDTH = 1
124+
SFP_STATUS_CONTROL_OFFSET = 110
125+
SFP_STATUS_CONTROL_WIDTH = 1
126126
SFP_TX_DISABLE_HARD_BIT = 7
127127
SFP_TX_DISABLE_SOFT_BIT = 6
128128

@@ -869,7 +869,7 @@ def get_rx_los(self):
869869
elif self.sfp_type == SFP_TYPE:
870870
offset = 256
871871
dom_channel_monitor_raw = self._read_eeprom_specific_bytes(
872-
(offset + SFP_CHANNL_STATUS_OFFSET), SFP_CHANNL_STATUS_WIDTH)
872+
(offset + SFP_STATUS_CONTROL_OFFSET), SFP_STATUS_CONTROL_WIDTH)
873873
if dom_channel_monitor_raw is not None:
874874
rx_los_data = int(dom_channel_monitor_raw[0], 16)
875875
rx_los_list.append(rx_los_data & 0x02 != 0)
@@ -901,7 +901,7 @@ def get_tx_fault(self):
901901
elif self.sfp_type == SFP_TYPE:
902902
offset = 256
903903
dom_channel_monitor_raw = self._read_eeprom_specific_bytes(
904-
(offset + SFP_CHANNL_STATUS_OFFSET), SFP_CHANNL_STATUS_WIDTH)
904+
(offset + SFP_STATUS_CONTROL_OFFSET), SFP_STATUS_CONTROL_WIDTH)
905905
if dom_channel_monitor_raw is not None:
906906
tx_fault_data = int(dom_channel_monitor_raw[0], 16)
907907
tx_fault_list.append(tx_fault_data & 0x04 != 0)
@@ -936,7 +936,7 @@ def get_tx_disable(self):
936936
elif self.sfp_type == SFP_TYPE:
937937
offset = 256
938938
dom_channel_monitor_raw = self._read_eeprom_specific_bytes(
939-
(offset + SFP_CHANNL_STATUS_OFFSET), SFP_CHANNL_STATUS_WIDTH)
939+
(offset + SFP_STATUS_CONTROL_OFFSET), SFP_STATUS_CONTROL_WIDTH)
940940
if dom_channel_monitor_raw is not None:
941941
tx_disable_data = int(dom_channel_monitor_raw[0], 16)
942942
tx_disable_list.append(tx_disable_data & 0xC0 != 0)
@@ -1170,31 +1170,36 @@ def tx_disable(self, tx_disable):
11701170
Returns:
11711171
A boolean, True if tx_disable is set successfully, False if not
11721172
"""
1173-
sysfs_sfp_i2c_client_eeprom_path = self.port_to_eeprom_mapping[self.port_num]
1174-
status_control_raw = self._read_eeprom_specific_bytes(
1175-
SFP_CHANNL_STATUS_OFFSET, SFP_CHANNL_STATUS_WIDTH)
1176-
if status_control_raw is not None:
1177-
# Set bit 6 for Soft TX Disable Select
1178-
# 01000000 = 64 and 10111111 = 191
1179-
tx_disable_bit = 64 if tx_disable else 191
1180-
status_control = int(status_control_raw[0], 16)
1181-
tx_disable_ctl = (status_control | tx_disable_bit) if tx_disable else (
1182-
status_control & tx_disable_bit)
1183-
try:
1184-
sysfsfile_eeprom = open(
1185-
sysfs_sfp_i2c_client_eeprom_path, mode="r+b", buffering=0)
1186-
buffer = create_string_buffer(1)
1187-
buffer[0] = chr(tx_disable_ctl)
1188-
# Write to eeprom
1189-
sysfsfile_eeprom.seek(SFP_CHANNL_STATUS_OFFSET)
1190-
sysfsfile_eeprom.write(buffer[0])
1191-
except Exception:
1192-
return False
1193-
finally:
1194-
if sysfsfile_eeprom:
1195-
sysfsfile_eeprom.close()
1196-
time.sleep(0.01)
1197-
return True
1173+
if not self.get_presence():
1174+
return False
1175+
1176+
if self.dom_tx_disable_supported:
1177+
# SFP status/control register at address A2h, byte 110
1178+
offset = 256
1179+
sysfs_sfp_i2c_client_eeprom_path = self.port_to_eeprom_mapping[self.port_num]
1180+
status_control_raw = self._read_eeprom_specific_bytes(
1181+
(offset + SFP_STATUS_CONTROL_OFFSET), SFP_STATUS_CONTROL_WIDTH)
1182+
if status_control_raw is not None:
1183+
# Set bit 6 for Soft TX Disable Select
1184+
# 01000000 = 64 and 10111111 = 191
1185+
tx_disable_bit = 64 if tx_disable else 191
1186+
status_control = int(status_control_raw[0], 16)
1187+
tx_disable_ctl = (status_control | tx_disable_bit) if tx_disable else (
1188+
status_control & tx_disable_bit)
1189+
try:
1190+
sysfsfile_eeprom = open(
1191+
sysfs_sfp_i2c_client_eeprom_path, mode="r+b", buffering=0)
1192+
tx_disable_data = c_char(tx_disable_ctl)
1193+
# Write to eeprom
1194+
sysfsfile_eeprom.seek(offset + SFP_STATUS_CONTROL_OFFSET)
1195+
sysfsfile_eeprom.write(tx_disable_data)
1196+
except Exception:
1197+
return False
1198+
finally:
1199+
if sysfsfile_eeprom:
1200+
sysfsfile_eeprom.close()
1201+
time.sleep(0.01)
1202+
return True
11981203
return False
11991204

12001205
def tx_disable_channel(self, channel, disable):

0 commit comments

Comments
 (0)