|
8 | 8 |
|
9 | 9 | try:
|
10 | 10 | import time
|
11 |
| - from ctypes import create_string_buffer |
| 11 | + from ctypes import c_char |
12 | 12 | from sonic_platform_base.sfp_base import SfpBase
|
13 | 13 | from sonic_platform_base.sonic_sfp.sff8472 import sff8472InterfaceId
|
14 | 14 | from sonic_platform_base.sonic_sfp.sff8472 import sff8472Dom
|
|
121 | 121 | SFP_VOLT_WIDTH = 2
|
122 | 122 | SFP_CHANNL_MON_OFFSET = 100
|
123 | 123 | 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 |
126 | 126 | SFP_TX_DISABLE_HARD_BIT = 7
|
127 | 127 | SFP_TX_DISABLE_SOFT_BIT = 6
|
128 | 128 |
|
@@ -869,7 +869,7 @@ def get_rx_los(self):
|
869 | 869 | elif self.sfp_type == SFP_TYPE:
|
870 | 870 | offset = 256
|
871 | 871 | 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) |
873 | 873 | if dom_channel_monitor_raw is not None:
|
874 | 874 | rx_los_data = int(dom_channel_monitor_raw[0], 16)
|
875 | 875 | rx_los_list.append(rx_los_data & 0x02 != 0)
|
@@ -901,7 +901,7 @@ def get_tx_fault(self):
|
901 | 901 | elif self.sfp_type == SFP_TYPE:
|
902 | 902 | offset = 256
|
903 | 903 | 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) |
905 | 905 | if dom_channel_monitor_raw is not None:
|
906 | 906 | tx_fault_data = int(dom_channel_monitor_raw[0], 16)
|
907 | 907 | tx_fault_list.append(tx_fault_data & 0x04 != 0)
|
@@ -936,7 +936,7 @@ def get_tx_disable(self):
|
936 | 936 | elif self.sfp_type == SFP_TYPE:
|
937 | 937 | offset = 256
|
938 | 938 | 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) |
940 | 940 | if dom_channel_monitor_raw is not None:
|
941 | 941 | tx_disable_data = int(dom_channel_monitor_raw[0], 16)
|
942 | 942 | tx_disable_list.append(tx_disable_data & 0xC0 != 0)
|
@@ -1170,31 +1170,36 @@ def tx_disable(self, tx_disable):
|
1170 | 1170 | Returns:
|
1171 | 1171 | A boolean, True if tx_disable is set successfully, False if not
|
1172 | 1172 | """
|
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 |
1198 | 1203 | return False
|
1199 | 1204 |
|
1200 | 1205 | def tx_disable_channel(self, channel, disable):
|
|
0 commit comments