Skip to content

Commit 7e89fad

Browse files
authored
[AS4630-54TE] Fixes to sfp.py for sfputil usage (#8985)
* Fix KeyError exception while sfputil show eeprom. * Implement reset/lpmode related APIs, which need PR8115's sysfs. * Fix EEPROM byte offset in several APIs * Fix typos * Implement get_position_in_parent() and is_replaceable() Signed-off-by: Sean Wu <[email protected]>
1 parent aad2761 commit 7e89fad

File tree

1 file changed

+39
-17
lines changed
  • device/accton/x86_64-accton_as4630_54te-r0/sonic_platform

1 file changed

+39
-17
lines changed

device/accton/x86_64-accton_as4630_54te-r0/sonic_platform/sfp.py

Lines changed: 39 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@
7474
QSFP_CHANNL_TX_FAULT_STATUS_WIDTH = 1
7575
QSFP_POWEROVERRIDE_OFFSET = 93
7676
QSFP_POWEROVERRIDE_WIDTH = 1
77+
QSFP_PAGE03_OFFSET = 384
7778
QSFP_MODULE_THRESHOLD_OFFSET = 128
7879
QSFP_MODULE_THRESHOLD_WIDTH = 24
7980
QSFP_CHANNEL_THRESHOLD_OFFSET = 176
@@ -152,7 +153,8 @@ def __init__(self, sfp_index=0):
152153
self.port_to_eeprom_mapping[x] = eeprom_path.format(self._port_to_i2c_mapping[x])
153154

154155
self.info_dict_keys = ['type', 'vendor_rev', 'serial', 'manufacturer', 'model', 'connector', 'encoding', 'ext_identifier',
155-
'ext_rateselect_compliance', 'cable_type', 'cable_length', 'nominal_bit_rate', 'specification_compliance', 'vendor_date', 'vendor_oui']
156+
'ext_rateselect_compliance', 'cable_type', 'cable_length', 'nominal_bit_rate', 'specification_compliance', 'vendor_date', 'vendor_oui',
157+
'application_advertisement', 'type_abbrv_name']
156158

157159
self.dom_dict_keys = ['rx_los', 'tx_fault', 'reset_status', 'power_lpmode', 'tx_disable', 'tx_disable_channel', 'temperature', 'voltage',
158160
'rx1power', 'rx2power', 'rx3power', 'rx4power', 'tx1bias', 'tx2bias', 'tx3bias', 'tx4bias', 'tx1power', 'tx2power', 'tx3power', 'tx4power']
@@ -247,6 +249,7 @@ def get_transceiver_info(self):
247249
specification_compliance |1*255VCHAR |specification compliance
248250
vendor_date |1*255VCHAR |vendor date
249251
vendor_oui |1*255VCHAR |vendor OUI
252+
application_advertisement |1*255VCHAR |supported applications advertisement
250253
========================================================================
251254
"""
252255
# check present status
@@ -442,7 +445,7 @@ def get_transceiver_bulk_status(self):
442445
qsfp_dom_capability_raw = self.__read_eeprom_specific_bytes(
443446
(offset_xcvr + XCVR_DOM_CAPABILITY_OFFSET), XCVR_DOM_CAPABILITY_WIDTH)
444447
if qsfp_dom_capability_raw is not None:
445-
qspf_dom_capability_data = sfpi_obj.parse_qsfp_dom_capability(
448+
qspf_dom_capability_data = sfpi_obj.parse_dom_capability(
446449
qsfp_dom_capability_raw, 0)
447450
else:
448451
return None
@@ -598,10 +601,11 @@ def get_transceiver_threshold_info(self):
598601
if not self.get_presence() or not sfpd_obj:
599602
return {}
600603

604+
offset = QSFP_PAGE03_OFFSET
601605
transceiver_dom_threshold_dict = dict.fromkeys(
602606
self.threshold_dict_keys, 'N/A')
603607
dom_thres_raw = self.__read_eeprom_specific_bytes(
604-
QSFP_MODULE_THRESHOLD_OFFSET, QSFP_MODULE_THRESHOLD_WIDTH) if self.get_presence() and sfpd_obj else None
608+
offset + QSFP_MODULE_THRESHOLD_OFFSET, QSFP_MODULE_THRESHOLD_WIDTH) if self.get_presence() and sfpd_obj else None
605609

606610
if dom_thres_raw:
607611
module_threshold_values = sfpd_obj.parse_module_threshold_values(
@@ -618,7 +622,7 @@ def get_transceiver_threshold_info(self):
618622
transceiver_dom_threshold_dict['vcclowwarning'] = module_threshold_data['VccLowWarning']['value']
619623

620624
dom_thres_raw = self.__read_eeprom_specific_bytes(
621-
QSFP_CHANNEL_THRESHOLD_OFFSET, QSFP_CHANNEL_THRESHOLD_WIDTH) if self.get_presence() and sfpd_obj else None
625+
offset + QSFP_CHANNEL_THRESHOLD_OFFSET, QSFP_CHANNEL_THRESHOLD_WIDTH) if self.get_presence() and sfpd_obj else None
622626
channel_threshold_values = sfpd_obj.parse_channel_threshold_values(
623627
dom_thres_raw, 0)
624628
channel_threshold_data = channel_threshold_values.get('data')
@@ -648,11 +652,16 @@ def get_reset_status(self):
648652
Returns:
649653
A Boolean, True if reset enabled, False if disabled
650654
"""
651-
if self.port_num < 49: #Copper port, no sysfs
655+
if self.port_num < 53: # non-QSFP ports don't support it.
652656
return False
653657

654-
return False # CPLD port doesn't support this feature
658+
reset_path="{}{}{}".format(CPLD_I2C_PATH , "module_reset_" , str(self.port_num))
659+
val = self._api_helper.read_txt_file(reset_path)
655660

661+
if val is not None:
662+
return int(val, 10) == 1
663+
else:
664+
return False
656665

657666
def get_rx_los(self):
658667
"""
@@ -827,7 +836,7 @@ def get_power_set(self):
827836
return False
828837

829838
dom_control_raw = self.__read_eeprom_specific_bytes(
830-
QSFP_POWEROVERRIDE_OFFSET, QSFP_CONTROL_WIDTH) if self.get_presence() else None
839+
QSFP_CONTROL_OFFSET, QSFP_CONTROL_WIDTH) if self.get_presence() else None
831840
if dom_control_raw is not None:
832841
dom_control_data = sfpd_obj.parse_control_bytes(dom_control_raw, 0)
833842
power_set = (
@@ -852,7 +861,7 @@ def get_power_override(self):
852861
return False
853862

854863
dom_control_raw = self.__read_eeprom_specific_bytes(
855-
QSFP_POWEROVERRIDE_OFFSET, QSFP_CONTROL_WIDTH) if self.get_presence() else None
864+
QSFP_CONTROL_OFFSET, QSFP_CONTROL_WIDTH) if self.get_presence() else None
856865
if dom_control_raw is not None:
857866
dom_control_data = sfpd_obj.parse_control_bytes(dom_control_raw, 0)
858867
power_override = (
@@ -939,23 +948,19 @@ def reset(self):
939948
A boolean, True if successful, False if not
940949
"""
941950
# Check for invalid port_num
942-
if self.port_num < 49: #Copper port, no sysfs
951+
if self.port_num < 53: # non-QSFP ports don't support it.
943952
return False
944953

945-
'''
946954
reset_path = "{}{}{}".format(CPLD_I2C_PATH, 'module_reset_', self.port_num)
947-
ret = self.__write_txt_file(reset_path, 1)
955+
ret = self._api_helper.write_txt_file(reset_path, 1)
948956
if ret is not True:
949957
return ret
950-
958+
951959
time.sleep(0.01)
952-
ret = self.__write_txt_file(reset_path, 0)
960+
ret = self._api_helper.write_txt_file(reset_path, 0)
953961
time.sleep(0.2)
954-
955-
return ret
956-
'''
957962

958-
return False #CPLD doens't support this feature
963+
return ret
959964

960965
def tx_disable(self, tx_disable):
961966
"""
@@ -1167,3 +1172,20 @@ def get_status(self):
11671172
A boolean value, True if device is operating properly, False if not
11681173
"""
11691174
return self.get_presence() and self.get_transceiver_bulk_status()
1175+
1176+
def get_position_in_parent(self):
1177+
"""
1178+
Retrieves 1-based relative physical position in parent device. If the agent cannot determine the parent-relative position
1179+
for some reason, or if the associated value of entPhysicalContainedIn is '0', then the value '-1' is returned
1180+
Returns:
1181+
integer: The 1-based relative physical position in parent device or -1 if cannot determine the position
1182+
"""
1183+
return self.port_num
1184+
1185+
def is_replaceable(self):
1186+
"""
1187+
Indicate whether this device is replaceable.
1188+
Returns:
1189+
bool: True if it is replaceable.
1190+
"""
1191+
return True

0 commit comments

Comments
 (0)