diff --git a/device/alibaba/x86_64-alibaba_as13-32h-cl-r0/plugins/sfputil.py b/device/alibaba/x86_64-alibaba_as13-32h-cl-r0/plugins/sfputil.py index a64483cc2e1e..0fa664f47d22 100755 --- a/device/alibaba/x86_64-alibaba_as13-32h-cl-r0/plugins/sfputil.py +++ b/device/alibaba/x86_64-alibaba_as13-32h-cl-r0/plugins/sfputil.py @@ -168,17 +168,34 @@ def tx_disable(self, port_num, disable): False -- enable port tx signal @return True when operation success, False on failure. """ + TX_DISABLE_BYTE_OFFSET = 86 if port_num not in range(self.port_start, self.port_end + 1) or type(disable) != bool: return False - try: - disable = hex(1) if disable else hex(0) - port_name = self.get_port_name(port_num) - reg_file = open( - "/".join([self.PORT_INFO_PATH, port_name, "sfp_txdisable"]), "w") - reg_file.write(disable) - except IOError as e: - print "Error: unable to open file: %s" % str(e) - return False + # QSFP, set eeprom to disable tx + if port_num in self.qsfp_ports: + disable = b'\x0f' if disable else b'\x00' + # open eeprom + try: + with open(self.port_to_eeprom_mapping[port_num], mode="wb", buffering=0) as sysfsfile: + sysfsfile.seek(TX_DISABLE_BYTE_OFFSET) + sysfsfile.write(bytearray(disable)) + except IOError: + return False + except: + return False + + # SFP, set tx_disable pin + else: + try: + disable = hex(1) if disable else hex(0) + port_name = self.get_port_name(port_num) + reg_file = open( + "/".join([self.PORT_INFO_PATH, port_name, "sfp_txdisable"]), "w") + reg_file.write(disable) + reg_file.close() + except IOError as e: + print "Error: unable to open file: %s" % str(e) + return False return True diff --git a/device/alibaba/x86_64-alibaba_as13-48f8h-cl-r0/plugins/sfputil.py b/device/alibaba/x86_64-alibaba_as13-48f8h-cl-r0/plugins/sfputil.py index bc4ded2b9121..a05950ca876e 100755 --- a/device/alibaba/x86_64-alibaba_as13-48f8h-cl-r0/plugins/sfputil.py +++ b/device/alibaba/x86_64-alibaba_as13-48f8h-cl-r0/plugins/sfputil.py @@ -168,17 +168,34 @@ def tx_disable(self, port_num, disable): False -- enable port tx signal @return True when operation success, False on failure. """ + TX_DISABLE_BYTE_OFFSET = 86 if port_num not in range(self.port_start, self.port_end + 1) or type(disable) != bool: return False - try: - disable = hex(1) if disable else hex(0) - port_name = self.get_port_name(port_num) - reg_file = open( - "/".join([self.PORT_INFO_PATH, port_name, "sfp_txdisable"]), "w") - reg_file.write(disable) - except IOError as e: - print "Error: unable to open file: %s" % str(e) - return False + # QSFP, set eeprom to disable tx + if port_num in self.qsfp_ports: + disable = b'\x0f' if disable else b'\x00' + # open eeprom + try: + with open(self.port_to_eeprom_mapping[port_num], mode="wb", buffering=0) as sysfsfile: + sysfsfile.seek(TX_DISABLE_BYTE_OFFSET) + sysfsfile.write(bytearray(disable)) + except IOError: + return False + except: + return False + + # SFP, set tx_disable pin + else: + try: + disable = hex(1) if disable else hex(0) + port_name = self.get_port_name(port_num) + reg_file = open( + "/".join([self.PORT_INFO_PATH, port_name, "sfp_txdisable"]), "w") + reg_file.write(disable) + reg_file.close() + except IOError as e: + print "Error: unable to open file: %s" % str(e) + return False return True diff --git a/device/alibaba/x86_64-alibaba_as23-128h-cl-r0/plugins/sfputil.py b/device/alibaba/x86_64-alibaba_as23-128h-cl-r0/plugins/sfputil.py index 82e4584b720d..14c8d28fa9c4 100755 --- a/device/alibaba/x86_64-alibaba_as23-128h-cl-r0/plugins/sfputil.py +++ b/device/alibaba/x86_64-alibaba_as23-128h-cl-r0/plugins/sfputil.py @@ -168,17 +168,34 @@ def tx_disable(self, port_num, disable): False -- enable port tx signal @return True when operation success, False on failure. """ + TX_DISABLE_BYTE_OFFSET = 86 if port_num not in range(self.port_start, self.port_end + 1) or type(disable) != bool: return False - try: - disable = hex(1) if disable else hex(0) - port_name = self.get_port_name(port_num) - reg_file = open( - "/".join([self.PORT_INFO_PATH, port_name, "sfp_txdisable"]), "w") - reg_file.write(disable) - except IOError as e: - print "Error: unable to open file: %s" % str(e) - return False + # QSFP, set eeprom to disable tx + if port_num in self.qsfp_ports: + disable = b'\x0f' if disable else b'\x00' + # open eeprom + try: + with open(self.port_to_eeprom_mapping[port_num], mode="wb", buffering=0) as sysfsfile: + sysfsfile.seek(TX_DISABLE_BYTE_OFFSET) + sysfsfile.write(bytearray(disable)) + except IOError: + return False + except: + return False + + # SFP, set tx_disable pin + else: + try: + disable = hex(1) if disable else hex(0) + port_name = self.get_port_name(port_num) + reg_file = open( + "/".join([self.PORT_INFO_PATH, port_name, "sfp_txdisable"]), "w") + reg_file.write(disable) + reg_file.close() + except IOError as e: + print "Error: unable to open file: %s" % str(e) + return False return True