From 6f31f8b4bec200450149e18ce848688317401ed3 Mon Sep 17 00:00:00 2001 From: nicwu-cel Date: Thu, 28 Apr 2022 07:10:40 +0000 Subject: [PATCH] [Author]: jersyang@celestica.com [Jira ID]:N/A fix the i2c controller initialize sequence --- .../x86_64-cel_belgite-r0/installer.conf | 2 +- .../belgite/pddf/sonic_platform/eeprom.py | 57 ++++++++++++++++++- .../scripts/pddf_post_device_create.sh | 3 +- platform/pddf/i2c/utils/pddf_util.py | 4 +- platform/pddf/i2c/utils/pddfparse.py | 28 +-------- .../sonic_platform_pddf_base/pddfapi.py | 28 +-------- 6 files changed, 65 insertions(+), 57 deletions(-) diff --git a/device/celestica/x86_64-cel_belgite-r0/installer.conf b/device/celestica/x86_64-cel_belgite-r0/installer.conf index 61846e4455e0..6ba1f09f192f 100644 --- a/device/celestica/x86_64-cel_belgite-r0/installer.conf +++ b/device/celestica/x86_64-cel_belgite-r0/installer.conf @@ -1,4 +1,4 @@ CONSOLE_PORT=0x3f8 CONSOLE_DEV=0 CONSOLE_SPEED=9600 -ONIE_PLATFORM_EXTRA_CMDLINE_LINUX="intel_iommu=off module_blacklist=gpio_ich crashkernel=0M-2G:256M,2G-4G:320M,4G-8G:384M,8G-:448M acpi_no_watchdog" +ONIE_PLATFORM_EXTRA_CMDLINE_LINUX="intel_iommu=off module_blacklist=gpio_ich,i2c-ismt,i2c_ismt,i2c-i801,i2c_i801 crashkernel=0M-2G:256M,2G-4G:320M,4G-8G:384M,8G-:448M acpi_no_watchdog" diff --git a/platform/broadcom/sonic-platform-modules-cel/belgite/pddf/sonic_platform/eeprom.py b/platform/broadcom/sonic-platform-modules-cel/belgite/pddf/sonic_platform/eeprom.py index b49c65ffe571..bc1ef6420b68 100644 --- a/platform/broadcom/sonic-platform-modules-cel/belgite/pddf/sonic_platform/eeprom.py +++ b/platform/broadcom/sonic-platform-modules-cel/belgite/pddf/sonic_platform/eeprom.py @@ -6,8 +6,63 @@ class Eeprom(PddfEeprom): + _TLV_DISPLAY_VENDOR_EXT = True + _TLV_INFO_MAX_LEN = 256 + pddf_obj = {} + plugin_data = {} + def __init__(self, pddf_data=None, pddf_plugin_data=None): - PddfEeprom.__init__(self, pddf_data, pddf_plugin_data) + if not pddf_data or not pddf_plugin_data: + raise ValueError('PDDF JSON data error') + + self.pddf_obj = pddf_data + self.plugin_data = pddf_plugin_data + + # system EEPROM always has device name EEPROM1 + self.eeprom_path = self.pddf_obj.get_path("EEPROM1", "eeprom") + if self.eeprom_path is None: + return + + super(PddfEeprom, self).__init__(self.eeprom_path, 0, '', True) + #super().__init__(self.pddf_obj, self.plugin_data) + self.eeprom_tlv_dict = dict() + try: + self.eeprom_data = self.read_eeprom() + except Exception as e: + self.eeprom_data = "N/A" + raise RuntimeError("PddfEeprom is not Programmed - Error: {}".format(str(e))) + else: + eeprom = self.eeprom_data + + if not self.is_valid_tlvinfo_header(eeprom): + return + + total_length = ((eeprom[9]) << 8) | (eeprom[10]) + tlv_index = self._TLV_INFO_HDR_LEN + tlv_end = self._TLV_INFO_HDR_LEN + total_length + + while (tlv_index + 2) < self._TLV_INFO_MAX_LEN and tlv_index < tlv_end: + if not self.is_valid_tlv(eeprom[tlv_index:]): + break + + tlv = eeprom[tlv_index:tlv_index + 2 + + (eeprom[tlv_index + 1])] + code = "0x%02X" % ((tlv[0])) + + if (tlv[0]) == self._TLV_CODE_VENDOR_EXT: + name = "Vendor Extension" #lgtm [py/multiple-definition] + value = "" + if self._TLV_DISPLAY_VENDOR_EXT: + for c in tlv[2:2 + tlv[1]]: + value += "0x%02X " % c + else: + name, value = self.decoder(None, tlv) + + self.eeprom_tlv_dict[code] = value + if (eeprom[tlv_index]) == self._TLV_CODE_CRC_32: + break + + tlv_index += (eeprom[tlv_index+1]) + 2 def vendor_ext_str(self): """ diff --git a/platform/broadcom/sonic-platform-modules-cel/belgite/scripts/pddf_post_device_create.sh b/platform/broadcom/sonic-platform-modules-cel/belgite/scripts/pddf_post_device_create.sh index 8dd9ac8a8486..414eea7a2b40 100755 --- a/platform/broadcom/sonic-platform-modules-cel/belgite/scripts/pddf_post_device_create.sh +++ b/platform/broadcom/sonic-platform-modules-cel/belgite/scripts/pddf_post_device_create.sh @@ -6,4 +6,5 @@ sudo i2cset -y -f 6 0x49 0x1 0x2 sleep 0.1 #Set LM75 shutdown enable sudo i2cset -y -f 2 0x32 0x45 0x1 - + +echo -2 | tee /sys/bus/i2c/drivers/pca954x/*-00*/idle_state diff --git a/platform/pddf/i2c/utils/pddf_util.py b/platform/pddf/i2c/utils/pddf_util.py index fdefc8933c15..d3ee5e43aca9 100755 --- a/platform/pddf/i2c/utils/pddf_util.py +++ b/platform/pddf/i2c/utils/pddf_util.py @@ -21,7 +21,7 @@ import shutil import subprocess import sys - +from sonic_py_common import device_info import pddfparse PLATFORM_ROOT_PATH = '/usr/share/sonic/device' @@ -139,7 +139,7 @@ def driver_check(): def get_path_to_device(): # Get platform and hwsku - (platform, hwsku) = pddf_obj.get_platform_and_hwsku() + (platform, hwsku) = device_info.get_platform_and_hwsku() # Load platform module from source platform_path = "/".join([PLATFORM_ROOT_PATH, platform]) diff --git a/platform/pddf/i2c/utils/pddfparse.py b/platform/pddf/i2c/utils/pddfparse.py index b8c7f39138a5..8d48586ee0b6 100755 --- a/platform/pddf/i2c/utils/pddfparse.py +++ b/platform/pddf/i2c/utils/pddfparse.py @@ -8,6 +8,7 @@ import sys import time import unicodedata +from sonic_py_common import device_info bmc_cache = {} cache = {} @@ -33,7 +34,7 @@ class PddfParse(): def __init__(self): if not os.path.exists("/usr/share/sonic/platform"): - platform, hwsku = self.get_platform_and_hwsku() + platform, hwsku = device_info.get_platform_and_hwsku() os.symlink("/usr/share/sonic/device/"+platform, "/usr/share/sonic/platform") try: @@ -47,31 +48,6 @@ def __init__(self): self.data_sysfs_obj = {} self.sysfs_obj = {} - # Returns platform and HW SKU - def get_platform_and_hwsku(self): - try: - proc = subprocess.Popen([SONIC_CFGGEN_PATH, '-H', '-v', PLATFORM_KEY], - stdout=subprocess.PIPE, - shell=False, - universal_newlines=True, - stderr=subprocess.STDOUT) - stdout = proc.communicate()[0] - proc.wait() - platform = stdout.rstrip('\n') - - proc = subprocess.Popen([SONIC_CFGGEN_PATH, '-d', '-v', HWSKU_KEY], - stdout=subprocess.PIPE, - shell=False, - universal_newlines=True, - stderr=subprocess.STDOUT) - stdout = proc.communicate()[0] - proc.wait() - hwsku = stdout.rstrip('\n') - except OSError as e: - raise OSError("Cannot detect platform") - - return (platform, hwsku) - ################################################################################################################### # GENERIC DEFS ################################################################################################################### diff --git a/platform/pddf/platform-api-pddf-base/sonic_platform_pddf_base/pddfapi.py b/platform/pddf/platform-api-pddf-base/sonic_platform_pddf_base/pddfapi.py index 7e9a382d0c46..352ad1b1744f 100644 --- a/platform/pddf/platform-api-pddf-base/sonic_platform_pddf_base/pddfapi.py +++ b/platform/pddf/platform-api-pddf-base/sonic_platform_pddf_base/pddfapi.py @@ -6,6 +6,7 @@ import subprocess import time import unicodedata +from sonic_py_common import device_info bmc_cache = {} cache = {} @@ -31,7 +32,7 @@ class PddfApi(): def __init__(self): if not os.path.exists("/usr/share/sonic/platform"): - self.platform, self.hwsku = self.get_platform_and_hwsku() + self.platform, self.hwsku = device_info.get_platform_and_hwsku() os.symlink("/usr/share/sonic/device/"+self.platform, "/usr/share/sonic/platform") try: @@ -44,31 +45,6 @@ def __init__(self): self.data_sysfs_obj = {} self.sysfs_obj = {} - # Returns platform and HW SKU - def get_platform_and_hwsku(self): - try: - proc = subprocess.Popen([SONIC_CFGGEN_PATH, '-H', '-v', PLATFORM_KEY], - stdout=subprocess.PIPE, - shell=False, - universal_newlines=True, - stderr=subprocess.STDOUT) - stdout = proc.communicate()[0] - proc.wait() - platform = stdout.rstrip('\n') - - proc = subprocess.Popen([SONIC_CFGGEN_PATH, '-d', '-v', HWSKU_KEY], - stdout=subprocess.PIPE, - shell=False, - universal_newlines=True, - stderr=subprocess.STDOUT) - stdout = proc.communicate()[0] - proc.wait() - hwsku = stdout.rstrip('\n') - except OSError as e: - raise OSError("Cannot detect platform") - - return (platform, hwsku) - ################################################################################################################# # GENERIC DEFS #################################################################################################################