From 9afd8cedcfae8f6f9caadfac15da11b54c0b4329 Mon Sep 17 00:00:00 2001 From: jostar-yang Date: Thu, 8 Dec 2022 14:26:50 +0800 Subject: [PATCH 01/21] [Edgecore][AS7726/PDDF] Enhance sonic_platform feature Signed-off-by: jostar-yang --- .../x86_64-accton_as7726_32x-r0/pcie.yaml | 471 ++++++++++++++++++ .../pddf/pd-plugin.json | 2 +- .../pddf/pddf-device.json | 31 +- .../pmon_daemon_control.json | 3 +- .../system_health_monitoring_config.json | 17 + .../as7726-32x/sonic_platform/chassis.py | 93 ++-- .../as7726-32x/sonic_platform/helper.py | 117 +++++ .../as7726-32x/sonic_platform/pcie.py | 23 + .../as7726-32x/sonic_platform/thermal.py | 6 + 9 files changed, 720 insertions(+), 43 deletions(-) create mode 100644 device/accton/x86_64-accton_as7726_32x-r0/pcie.yaml create mode 100644 device/accton/x86_64-accton_as7726_32x-r0/system_health_monitoring_config.json create mode 100644 platform/broadcom/sonic-platform-modules-accton/as7726-32x/sonic_platform/helper.py create mode 100644 platform/broadcom/sonic-platform-modules-accton/as7726-32x/sonic_platform/pcie.py diff --git a/device/accton/x86_64-accton_as7726_32x-r0/pcie.yaml b/device/accton/x86_64-accton_as7726_32x-r0/pcie.yaml new file mode 100644 index 000000000000..c019a23aa027 --- /dev/null +++ b/device/accton/x86_64-accton_as7726_32x-r0/pcie.yaml @@ -0,0 +1,471 @@ +- bus: '00' + dev: '00' + fn: '0' + id: 6f00 + name: 'Host bridge: Intel Corporation Xeon E7 v4/Xeon E5 v4/Xeon E3 v4/Xeon D DMI2 + (rev 03)' +- bus: '00' + dev: '01' + fn: '0' + id: 6f02 + name: 'PCI bridge: Intel Corporation Xeon E7 v4/Xeon E5 v4/Xeon E3 v4/Xeon D PCI + Express Root Port 1 (rev 03)' +- bus: '00' + dev: '01' + fn: '1' + id: 6f03 + name: 'PCI bridge: Intel Corporation Xeon E7 v4/Xeon E5 v4/Xeon E3 v4/Xeon D PCI + Express Root Port 1 (rev 03)' +- bus: '00' + dev: '02' + fn: '0' + id: 6f04 + name: 'PCI bridge: Intel Corporation Xeon E7 v4/Xeon E5 v4/Xeon E3 v4/Xeon D PCI + Express Root Port 2 (rev 03)' +- bus: '00' + dev: '02' + fn: '1' + id: 6f05 + name: 'PCI bridge: Intel Corporation Xeon E7 v4/Xeon E5 v4/Xeon E3 v4/Xeon D PCI + Express Root Port 2 (rev 03)' +- bus: '00' + dev: '02' + fn: '2' + id: 6f06 + name: 'PCI bridge: Intel Corporation Xeon E7 v4/Xeon E5 v4/Xeon E3 v4/Xeon D PCI + Express Root Port 2 (rev 03)' +- bus: '00' + dev: '02' + fn: '3' + id: 6f07 + name: 'PCI bridge: Intel Corporation Xeon E7 v4/Xeon E5 v4/Xeon E3 v4/Xeon D PCI + Express Root Port 2 (rev 03)' +- bus: '00' + dev: '03' + fn: '0' + id: 6f08 + name: 'PCI bridge: Intel Corporation Xeon E7 v4/Xeon E5 v4/Xeon E3 v4/Xeon D PCI + Express Root Port 3 (rev 03)' +- bus: '00' + dev: '03' + fn: '1' + id: 6f09 + name: 'PCI bridge: Intel Corporation Xeon E7 v4/Xeon E5 v4/Xeon E3 v4/Xeon D PCI + Express Root Port 3 (rev 03)' +- bus: '00' + dev: '03' + fn: '2' + id: 6f0a + name: 'PCI bridge: Intel Corporation Xeon E7 v4/Xeon E5 v4/Xeon E3 v4/Xeon D PCI + Express Root Port 3 (rev 03)' +- bus: '00' + dev: '03' + fn: '3' + id: 6f0b + name: 'PCI bridge: Intel Corporation Xeon E7 v4/Xeon E5 v4/Xeon E3 v4/Xeon D PCI + Express Root Port 3 (rev 03)' +- bus: '00' + dev: '05' + fn: '0' + id: 6f28 + name: 'System peripheral: Intel Corporation Xeon E7 v4/Xeon E5 v4/Xeon E3 v4/Xeon + D Map/VTd_Misc/System Management (rev 03)' +- bus: '00' + dev: '05' + fn: '1' + id: 6f29 + name: 'System peripheral: Intel Corporation Xeon E7 v4/Xeon E5 v4/Xeon E3 v4/Xeon + D IIO Hot Plug (rev 03)' +- bus: '00' + dev: '05' + fn: '2' + id: 6f2a + name: 'System peripheral: Intel Corporation Xeon E7 v4/Xeon E5 v4/Xeon E3 v4/Xeon + D IIO RAS/Control Status/Global Errors (rev 03)' +- bus: '00' + dev: '05' + fn: '4' + id: 6f2c + name: 'PIC: Intel Corporation Xeon E7 v4/Xeon E5 v4/Xeon E3 v4/Xeon D I/O APIC (rev + 03)' +- bus: '00' + dev: '14' + fn: '0' + id: 8c31 + name: 'USB controller: Intel Corporation 8 Series/C220 Series Chipset Family USB + xHCI (rev 05)' +- bus: '00' + dev: '16' + fn: '0' + id: 8c3a + name: 'Communication controller: Intel Corporation 8 Series/C220 Series Chipset + Family MEI Controller #1 (rev 04)' +- bus: '00' + dev: '16' + fn: '1' + id: 8c3b + name: 'Communication controller: Intel Corporation 8 Series/C220 Series Chipset + Family MEI Controller #2 (rev 04)' +- bus: '00' + dev: 1c + fn: '0' + id: 8c10 + name: 'PCI bridge: Intel Corporation 8 Series/C220 Series Chipset Family PCI Express + Root Port #1 (rev d5)' +- bus: '00' + dev: 1c + fn: '1' + id: 8c12 + name: 'PCI bridge: Intel Corporation 8 Series/C220 Series Chipset Family PCI Express + Root Port #2 (rev d5)' +- bus: '00' + dev: 1c + fn: '4' + id: 8c18 + name: 'PCI bridge: Intel Corporation 8 Series/C220 Series Chipset Family PCI Express + Root Port #5 (rev d5)' +- bus: '00' + dev: 1d + fn: '0' + id: 8c26 + name: 'USB controller: Intel Corporation 8 Series/C220 Series Chipset Family USB + EHCI #1 (rev 05)' +- bus: '00' + dev: 1f + fn: '0' + id: 8c54 + name: 'ISA bridge: Intel Corporation C224 Series Chipset Family Server Standard + SKU LPC Controller (rev 05)' +- bus: '00' + dev: 1f + fn: '2' + id: 8c02 + name: 'SATA controller: Intel Corporation 8 Series/C220 Series Chipset Family 6-port + SATA Controller 1 [AHCI mode] (rev 05)' +- bus: '00' + dev: 1f + fn: '3' + id: 8c22 + name: 'SMBus: Intel Corporation 8 Series/C220 Series Chipset Family SMBus Controller + (rev 05)' +- bus: '03' + dev: '00' + fn: '0' + id: 6f50 + name: 'System peripheral: Intel Corporation Xeon Processor D Family QuickData Technology + Register DMA Channel 0' +- bus: '03' + dev: '00' + fn: '1' + id: 6f51 + name: 'System peripheral: Intel Corporation Xeon Processor D Family QuickData Technology + Register DMA Channel 1' +- bus: '03' + dev: '00' + fn: '2' + id: 6f52 + name: 'System peripheral: Intel Corporation Xeon Processor D Family QuickData Technology + Register DMA Channel 2' +- bus: '03' + dev: '00' + fn: '3' + id: 6f53 + name: 'System peripheral: Intel Corporation Xeon Processor D Family QuickData Technology + Register DMA Channel 3' +- bus: '05' + dev: '00' + fn: '0' + id: 15ab + name: 'Ethernet controller: Intel Corporation Ethernet Connection X552 10 GbE Backplane' +- bus: '05' + dev: '00' + fn: '1' + id: 15ab + name: 'Ethernet controller: Intel Corporation Ethernet Connection X552 10 GbE Backplane' +- bus: '07' + dev: '00' + fn: '0' + id: b870 + name: 'Ethernet controller: Broadcom Inc. and subsidiaries Device b870 (rev 01)' +- bus: 0b + dev: '00' + fn: '0' + id: 165f + name: 'Ethernet controller: Broadcom Inc. and subsidiaries NetXtreme BCM5720 2-port + Gigabit Ethernet PCIe' +- bus: ff + dev: 0b + fn: '0' + id: 6f81 + name: 'System peripheral: Intel Corporation Xeon E7 v4/Xeon E5 v4/Xeon E3 v4/Xeon + D R3 QPI Link 0/1 (rev 03)' +- bus: ff + dev: 0b + fn: '1' + id: 6f36 + name: 'Performance counters: Intel Corporation Xeon E7 v4/Xeon E5 v4/Xeon E3 v4/Xeon + D R3 QPI Link 0/1 (rev 03)' +- bus: ff + dev: 0b + fn: '2' + id: 6f37 + name: 'Performance counters: Intel Corporation Xeon E7 v4/Xeon E5 v4/Xeon E3 v4/Xeon + D R3 QPI Link 0/1 (rev 03)' +- bus: ff + dev: 0b + fn: '3' + id: 6f76 + name: 'System peripheral: Intel Corporation Xeon E7 v4/Xeon E5 v4/Xeon E3 v4/Xeon + D R3 QPI Link Debug (rev 03)' +- bus: ff + dev: 0c + fn: '0' + id: 6fe0 + name: 'System peripheral: Intel Corporation Xeon E7 v4/Xeon E5 v4/Xeon E3 v4/Xeon + D Caching Agent (rev 03)' +- bus: ff + dev: 0c + fn: '1' + id: 6fe1 + name: 'System peripheral: Intel Corporation Xeon E7 v4/Xeon E5 v4/Xeon E3 v4/Xeon + D Caching Agent (rev 03)' +- bus: ff + dev: 0c + fn: '2' + id: 6fe2 + name: 'System peripheral: Intel Corporation Xeon E7 v4/Xeon E5 v4/Xeon E3 v4/Xeon + D Caching Agent (rev 03)' +- bus: ff + dev: 0c + fn: '3' + id: 6fe3 + name: 'System peripheral: Intel Corporation Xeon E7 v4/Xeon E5 v4/Xeon E3 v4/Xeon + D Caching Agent (rev 03)' +- bus: ff + dev: 0f + fn: '0' + id: 6ff8 + name: 'System peripheral: Intel Corporation Xeon E7 v4/Xeon E5 v4/Xeon E3 v4/Xeon + D Caching Agent (rev 03)' +- bus: ff + dev: 0f + fn: '4' + id: 6ffc + name: 'System peripheral: Intel Corporation Xeon E7 v4/Xeon E5 v4/Xeon E3 v4/Xeon + D Caching Agent (rev 03)' +- bus: ff + dev: 0f + fn: '5' + id: 6ffd + name: 'System peripheral: Intel Corporation Xeon E7 v4/Xeon E5 v4/Xeon E3 v4/Xeon + D Caching Agent (rev 03)' +- bus: ff + dev: 0f + fn: '6' + id: 6ffe + name: 'System peripheral: Intel Corporation Xeon E7 v4/Xeon E5 v4/Xeon E3 v4/Xeon + D Caching Agent (rev 03)' +- bus: ff + dev: '10' + fn: '0' + id: 6f1d + name: 'System peripheral: Intel Corporation Xeon E7 v4/Xeon E5 v4/Xeon E3 v4/Xeon + D R2PCIe Agent (rev 03)' +- bus: ff + dev: '10' + fn: '1' + id: 6f34 + name: 'Performance counters: Intel Corporation Xeon E7 v4/Xeon E5 v4/Xeon E3 v4/Xeon + D R2PCIe Agent (rev 03)' +- bus: ff + dev: '10' + fn: '5' + id: 6f1e + name: 'System peripheral: Intel Corporation Xeon E7 v4/Xeon E5 v4/Xeon E3 v4/Xeon + D Ubox (rev 03)' +- bus: ff + dev: '10' + fn: '6' + id: 6f7d + name: 'Performance counters: Intel Corporation Xeon E7 v4/Xeon E5 v4/Xeon E3 v4/Xeon + D Ubox (rev 03)' +- bus: ff + dev: '10' + fn: '7' + id: 6f1f + name: 'System peripheral: Intel Corporation Xeon E7 v4/Xeon E5 v4/Xeon E3 v4/Xeon + D Ubox (rev 03)' +- bus: ff + dev: '12' + fn: '0' + id: 6fa0 + name: 'System peripheral: Intel Corporation Xeon E7 v4/Xeon E5 v4/Xeon E3 v4/Xeon + D Home Agent 0 (rev 03)' +- bus: ff + dev: '12' + fn: '1' + id: 6f30 + name: 'Performance counters: Intel Corporation Xeon E7 v4/Xeon E5 v4/Xeon E3 v4/Xeon + D Home Agent 0 (rev 03)' +- bus: ff + dev: '13' + fn: '0' + id: 6fa8 + name: 'System peripheral: Intel Corporation Xeon E7 v4/Xeon E5 v4/Xeon E3 v4/Xeon + D Memory Controller 0 - Target Address/Thermal/RAS (rev 03)' +- bus: ff + dev: '13' + fn: '1' + id: 6f71 + name: 'System peripheral: Intel Corporation Xeon E7 v4/Xeon E5 v4/Xeon E3 v4/Xeon + D Memory Controller 0 - Target Address/Thermal/RAS (rev 03)' +- bus: ff + dev: '13' + fn: '2' + id: 6faa + name: 'System peripheral: Intel Corporation Xeon E7 v4/Xeon E5 v4/Xeon E3 v4/Xeon + D Memory Controller 0 - Channel Target Address Decoder (rev 03)' +- bus: ff + dev: '13' + fn: '3' + id: 6fab + name: 'System peripheral: Intel Corporation Xeon E7 v4/Xeon E5 v4/Xeon E3 v4/Xeon + D Memory Controller 0 - Channel Target Address Decoder (rev 03)' +- bus: ff + dev: '13' + fn: '4' + id: 6fac + name: 'System peripheral: Intel Corporation Xeon E7 v4/Xeon E5 v4/Xeon E3 v4/Xeon + D Memory Controller 0 - Channel Target Address Decoder (rev 03)' +- bus: ff + dev: '13' + fn: '5' + id: 6fad + name: 'System peripheral: Intel Corporation Xeon E7 v4/Xeon E5 v4/Xeon E3 v4/Xeon + D Memory Controller 0 - Channel Target Address Decoder (rev 03)' +- bus: ff + dev: '13' + fn: '6' + id: 6fae + name: 'System peripheral: Intel Corporation Xeon E7 v4/Xeon E5 v4/Xeon E3 v4/Xeon + D DDRIO Channel 0/1 Broadcast (rev 03)' +- bus: ff + dev: '13' + fn: '7' + id: 6faf + name: 'System peripheral: Intel Corporation Xeon E7 v4/Xeon E5 v4/Xeon E3 v4/Xeon + D DDRIO Global Broadcast (rev 03)' +- bus: ff + dev: '14' + fn: '0' + id: 6fb0 + name: 'System peripheral: Intel Corporation Xeon E7 v4/Xeon E5 v4/Xeon E3 v4/Xeon + D Memory Controller 0 - Channel 0 Thermal Control (rev 03)' +- bus: ff + dev: '14' + fn: '1' + id: 6fb1 + name: 'System peripheral: Intel Corporation Xeon E7 v4/Xeon E5 v4/Xeon E3 v4/Xeon + D Memory Controller 0 - Channel 1 Thermal Control (rev 03)' +- bus: ff + dev: '14' + fn: '2' + id: 6fb2 + name: 'System peripheral: Intel Corporation Xeon E7 v4/Xeon E5 v4/Xeon E3 v4/Xeon + D Memory Controller 0 - Channel 0 Error (rev 03)' +- bus: ff + dev: '14' + fn: '3' + id: 6fb3 + name: 'System peripheral: Intel Corporation Xeon E7 v4/Xeon E5 v4/Xeon E3 v4/Xeon + D Memory Controller 0 - Channel 1 Error (rev 03)' +- bus: ff + dev: '14' + fn: '4' + id: 6fbc + name: 'System peripheral: Intel Corporation Xeon E7 v4/Xeon E5 v4/Xeon E3 v4/Xeon + D DDRIO Channel 0/1 Interface (rev 03)' +- bus: ff + dev: '14' + fn: '5' + id: 6fbd + name: 'System peripheral: Intel Corporation Xeon E7 v4/Xeon E5 v4/Xeon E3 v4/Xeon + D DDRIO Channel 0/1 Interface (rev 03)' +- bus: ff + dev: '14' + fn: '6' + id: 6fbe + name: 'System peripheral: Intel Corporation Xeon E7 v4/Xeon E5 v4/Xeon E3 v4/Xeon + D DDRIO Channel 0/1 Interface (rev 03)' +- bus: ff + dev: '14' + fn: '7' + id: 6fbf + name: 'System peripheral: Intel Corporation Xeon E7 v4/Xeon E5 v4/Xeon E3 v4/Xeon + D DDRIO Channel 0/1 Interface (rev 03)' +- bus: ff + dev: '15' + fn: '0' + id: 6fb4 + name: 'System peripheral: Intel Corporation Xeon E7 v4/Xeon E5 v4/Xeon E3 v4/Xeon + D Memory Controller 0 - Channel 2 Thermal Control (rev 03)' +- bus: ff + dev: '15' + fn: '1' + id: 6fb5 + name: 'System peripheral: Intel Corporation Xeon E7 v4/Xeon E5 v4/Xeon E3 v4/Xeon + D Memory Controller 0 - Channel 3 Thermal Control (rev 03)' +- bus: ff + dev: '15' + fn: '2' + id: 6fb6 + name: 'System peripheral: Intel Corporation Xeon E7 v4/Xeon E5 v4/Xeon E3 v4/Xeon + D Memory Controller 0 - Channel 2 Error (rev 03)' +- bus: ff + dev: '15' + fn: '3' + id: 6fb7 + name: 'System peripheral: Intel Corporation Xeon E7 v4/Xeon E5 v4/Xeon E3 v4/Xeon + D Memory Controller 0 - Channel 3 Error (rev 03)' +- bus: ff + dev: 1e + fn: '0' + id: 6f98 + name: 'System peripheral: Intel Corporation Xeon E7 v4/Xeon E5 v4/Xeon E3 v4/Xeon + D Power Control Unit (rev 03)' +- bus: ff + dev: 1e + fn: '1' + id: 6f99 + name: 'System peripheral: Intel Corporation Xeon E7 v4/Xeon E5 v4/Xeon E3 v4/Xeon + D Power Control Unit (rev 03)' +- bus: ff + dev: 1e + fn: '2' + id: 6f9a + name: 'System peripheral: Intel Corporation Xeon E7 v4/Xeon E5 v4/Xeon E3 v4/Xeon + D Power Control Unit (rev 03)' +- bus: ff + dev: 1e + fn: '3' + id: 6fc0 + name: 'System peripheral: Intel Corporation Xeon E7 v4/Xeon E5 v4/Xeon E3 v4/Xeon + D Power Control Unit (rev 03)' +- bus: ff + dev: 1e + fn: '4' + id: 6f9c + name: 'System peripheral: Intel Corporation Xeon E7 v4/Xeon E5 v4/Xeon E3 v4/Xeon + D Power Control Unit (rev 03)' +- bus: ff + dev: 1f + fn: '0' + id: 6f88 + name: 'System peripheral: Intel Corporation Xeon E7 v4/Xeon E5 v4/Xeon E3 v4/Xeon + D Power Control Unit (rev 03)' +- bus: ff + dev: 1f + fn: '2' + id: 6f8a + name: 'System peripheral: Intel Corporation Xeon E7 v4/Xeon E5 v4/Xeon E3 v4/Xeon + D Power Control Unit (rev 03)' diff --git a/device/accton/x86_64-accton_as7726_32x-r0/pddf/pd-plugin.json b/device/accton/x86_64-accton_as7726_32x-r0/pddf/pd-plugin.json index b4e2cc4ac8cb..2b8ad2c459b1 100644 --- a/device/accton/x86_64-accton_as7726_32x-r0/pddf/pd-plugin.json +++ b/device/accton/x86_64-accton_as7726_32x-r0/pddf/pd-plugin.json @@ -61,7 +61,7 @@ "duty_cycle_to_pwm": "lambda dc: ((dc*100)/625 -1)", - "pwm_to_duty_cycle": "lambda pwm: (((pwm+1)*625+75)/100)" + "pwm_to_duty_cycle": "lambda pwm: (((pwm+1)*625)/100)" } } diff --git a/device/accton/x86_64-accton_as7726_32x-r0/pddf/pddf-device.json b/device/accton/x86_64-accton_as7726_32x-r0/pddf/pddf-device.json index b73f22b54191..95f9642773cf 100644 --- a/device/accton/x86_64-accton_as7726_32x-r0/pddf/pddf-device.json +++ b/device/accton/x86_64-accton_as7726_32x-r0/pddf/pddf-device.json @@ -5,7 +5,7 @@ "num_fantrays":6, "num_fans_pertray":2, "num_ports":34, - "num_temps":5, + "num_temps":7, "pddf_dev_types": { "description":"AS7726 - Below is the list of supported PDDF device types (chip names) for various components. If any component uses some other driver, we will create the client using 'echo > /new_device' method", @@ -1865,7 +1865,34 @@ ] } }, - + "TEMP6" : + { + "dev_info": { "device_type":"TEMP_SENSOR", "device_name":"TEMP6"}, + "dev_attr": { "display_name":"pch_haswell-virtual-0"}, + "i2c": + { + "path_info": {"sysfs_base_path": "/sys/class/hwmon/hwmon0"}, + "attr_list": + [ + { "attr_name": "temp1_input"} + ] + } + }, + "TEMP7" : + { + "dev_info": { "device_type":"TEMP_SENSOR", "device_name":"TEMP7"}, + "dev_attr": { "display_name":"coretemp-isa-0000"}, + "i2c": + { + "path_info": {"sysfs_base_path": "/sys/class/hwmon/hwmon1"}, + "attr_list": + [ + { "attr_name": "temp1_high_crit_threshold", "drv_attr_name":"temp1_crit"}, + { "attr_name": "temp1_high_threshold", "drv_attr_name":"temp1_max"}, + { "attr_name": "temp1_input"} + ] + } + }, "SYSSTATUS": { "dev_info":{ "device_type":"SYSSTAT", "device_name":"SYSSTATUS"}, diff --git a/device/accton/x86_64-accton_as7726_32x-r0/pmon_daemon_control.json b/device/accton/x86_64-accton_as7726_32x-r0/pmon_daemon_control.json index a3b204e20d8d..44bad6494229 100644 --- a/device/accton/x86_64-accton_as7726_32x-r0/pmon_daemon_control.json +++ b/device/accton/x86_64-accton_as7726_32x-r0/pmon_daemon_control.json @@ -1,5 +1,4 @@ { - "skip_ledd": true, - "skip_pcied": true + "skip_ledd": true } diff --git a/device/accton/x86_64-accton_as7726_32x-r0/system_health_monitoring_config.json b/device/accton/x86_64-accton_as7726_32x-r0/system_health_monitoring_config.json new file mode 100644 index 000000000000..53b14bec17be --- /dev/null +++ b/device/accton/x86_64-accton_as7726_32x-r0/system_health_monitoring_config.json @@ -0,0 +1,17 @@ +{ + "services_to_ignore": [], + "devices_to_ignore": [ + "asic", + "psu.voltage", + "psu.temperature", + "PSU1_FAN1.speed", + "PSU2_FAN1.speed" + ], + "user_defined_checkers": [], + "polling_interval": 60, + "led_color": { + "fault": "STATUS_LED_COLOR_AMBER", + "normal": "STATUS_LED_COLOR_GREEN", + "booting": "STATUS_LED_COLOR_OFF" + } +} diff --git a/platform/broadcom/sonic-platform-modules-accton/as7726-32x/sonic_platform/chassis.py b/platform/broadcom/sonic-platform-modules-accton/as7726-32x/sonic_platform/chassis.py index 8ff20a760562..1f23dcf81c57 100644 --- a/platform/broadcom/sonic-platform-modules-accton/as7726-32x/sonic_platform/chassis.py +++ b/platform/broadcom/sonic-platform-modules-accton/as7726-32x/sonic_platform/chassis.py @@ -8,58 +8,59 @@ try: import sys - import time from sonic_platform_pddf_base.pddf_chassis import PddfChassis + from .event import SfpEvent + from .helper import APIHelper except ImportError as e: raise ImportError(str(e) + "- required module not found") +NUM_COMPONENT = 6 +HOST_REBOOT_CAUSE_PATH = "/host/reboot-cause/" +PMON_REBOOT_CAUSE_PATH = "/usr/share/sonic/platform/api_files/reboot-cause/" +REBOOT_CAUSE_FILE = "reboot-cause.txt" class Chassis(PddfChassis): """ PDDF Platform-specific Chassis class """ + SYSLED_DEV_NAME = "DIAG_LED" + def __init__(self, pddf_data=None, pddf_plugin_data=None): PddfChassis.__init__(self, pddf_data, pddf_plugin_data) + self.__initialize_components() + self._api_helper = APIHelper() + self._sfpevent = SfpEvent(self.get_all_sfps()) + + + def __initialize_components(self): + from sonic_platform.component import Component + for index in range(NUM_COMPONENT): + component = Component(index) + self._component_list.append(component) # Provide the functions/variables below for which implementation is to be overwritten - sfp_change_event_data = {'valid': 0, 'last': 0, 'present': 0} - def get_change_event(self, timeout=2000): - now = time.time() - port_dict = {} - change_dict = {} - change_dict['sfp'] = port_dict - - if timeout < 1000: - timeout = 1000 - timeout = timeout / float(1000) # Convert to secs - - if now < (self.sfp_change_event_data['last'] + timeout) and self.sfp_change_event_data['valid']: - return True, change_dict - - bitmap = 0 - for i in range(34): - modpres = self.get_sfp(i+1).get_presence() - if modpres: - bitmap = bitmap | (1 << i) - - changed_ports = self.sfp_change_event_data['present'] ^ bitmap - if changed_ports: - for i in range(34): - if (changed_ports & (1 << i)): - if (bitmap & (1 << i)) == 0: - port_dict[i+1] = '0' - else: - port_dict[i+1] = '1' - - - # Update teh cache dict - self.sfp_change_event_data['present'] = bitmap - self.sfp_change_event_data['last'] = now - self.sfp_change_event_data['valid'] = 1 - return True, change_dict - else: - return True, change_dict + def get_change_event(self, timeout=0): + return self._sfpevent.get_sfp_event(timeout) + + def get_reboot_cause(self): + """ + Retrieves the cause of the previous reboot + + Returns: + A tuple (string, string) where the first element is a string + containing the cause of the previous reboot. This string must be + one of the predefined strings in this class. If the first string + is "REBOOT_CAUSE_HARDWARE_OTHER", the second string can be used + to pass a description of the reboot cause. + """ + + reboot_cause_path = (HOST_REBOOT_CAUSE_PATH + REBOOT_CAUSE_FILE) + sw_reboot_cause = self._api_helper.read_txt_file( + reboot_cause_path) or "Unknown" + + + return ('REBOOT_CAUSE_NON_HARDWARE', sw_reboot_cause) def get_sfp(self, index): @@ -84,3 +85,19 @@ def get_sfp(self, index): sys.stderr.write("SFP index {} out of range (1-{})\n".format( index, len(self._sfp_list))) return sfp + + def initizalize_system_led(self): + return + + def get_status_led(self): + return self.get_system_led(self.SYSLED_DEV_NAME) + + def set_status_led(self, color): + return self.set_system_led(self.SYSLED_DEV_NAME, color) + + def get_port_or_cage_type(self, port): + from sonic_platform_base.sfp_base import SfpBase + if port in range(1, 32): + return SfpBase.SFP_PORT_TYPE_BIT_QSFP | SfpBase.SFP_PORT_TYPE_BIT_QSFP_PLUS | SfpBase.SFP_PORT_TYPE_BIT_QSFP28 + else: + return SfpBase.SFP_PORT_TYPE_BIT_SFP | SfpBase.SFP_PORT_TYPE_BIT_SFP_PLUS diff --git a/platform/broadcom/sonic-platform-modules-accton/as7726-32x/sonic_platform/helper.py b/platform/broadcom/sonic-platform-modules-accton/as7726-32x/sonic_platform/helper.py new file mode 100644 index 000000000000..b124ca29f0df --- /dev/null +++ b/platform/broadcom/sonic-platform-modules-accton/as7726-32x/sonic_platform/helper.py @@ -0,0 +1,117 @@ +import os +import struct +import subprocess +from mmap import * +from sonic_py_common import device_info + +HOST_CHK_CMD = "docker > /dev/null 2>&1" +EMPTY_STRING = "" + + +class APIHelper(): + + def __init__(self): + (self.platform, self.hwsku) = device_info.get_platform_and_hwsku() + + def is_host(self): + return os.system(HOST_CHK_CMD) == 0 + + def pci_get_value(self, resource, offset): + status = True + result = "" + try: + fd = os.open(resource, os.O_RDWR) + mm = mmap(fd, 0) + mm.seek(int(offset)) + read_data_stream = mm.read(4) + result = struct.unpack('I', read_data_stream) + except Exception: + status = False + return status, result + + def run_command(self, cmd): + status = True + result = "" + try: + p = subprocess.Popen( + cmd, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE) + raw_data, err = p.communicate() + if err == '': + result = raw_data.strip() + except Exception: + status = False + return status, result + + def run_interactive_command(self, cmd): + try: + os.system(cmd) + except Exception: + return False + return True + + def read_txt_file(self, file_path): + try: + with open(file_path, 'r', errors='replace') as fd: + data = fd.read() + return data.strip() + except IOError: + pass + return None + + def write_txt_file(self, file_path, value): + try: + with open(file_path, 'w') as fd: + fd.write(str(value)) + except IOError: + return False + return True + + def ipmi_raw(self, netfn, cmd): + status = True + result = "" + try: + cmd = "ipmitool raw {} {}".format(str(netfn), str(cmd)) + p = subprocess.Popen( + cmd, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE) + raw_data, err = p.communicate() + if err == '': + result = raw_data.strip() + else: + status = False + except Exception: + status = False + return status, result + + def ipmi_fru_id(self, id, key=None): + status = True + result = "" + try: + cmd = "ipmitool fru print {}".format(str( + id)) if not key else "ipmitool fru print {0} | grep '{1}' ".format(str(id), str(key)) + + p = subprocess.Popen( + cmd, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE) + raw_data, err = p.communicate() + if err == '': + result = raw_data.strip() + else: + status = False + except Exception: + status = False + return status, result + + def ipmi_set_ss_thres(self, id, threshold_key, value): + status = True + result = "" + try: + cmd = "ipmitool sensor thresh '{}' {} {}".format(str(id), str(threshold_key), str(value)) + p = subprocess.Popen( + cmd, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE) + raw_data, err = p.communicate() + if err == '': + result = raw_data.strip() + else: + status = False + except Exception: + status = False + return status, result diff --git a/platform/broadcom/sonic-platform-modules-accton/as7726-32x/sonic_platform/pcie.py b/platform/broadcom/sonic-platform-modules-accton/as7726-32x/sonic_platform/pcie.py new file mode 100644 index 000000000000..0d972249af09 --- /dev/null +++ b/platform/broadcom/sonic-platform-modules-accton/as7726-32x/sonic_platform/pcie.py @@ -0,0 +1,23 @@ +############################################################################# +# Edgecore +# +# Module contains an implementation of SONiC Platform Base API and +# provides the fan status which are available in the platform +# Base PCIe class +############################################################################# + +import logging + + +try: + from sonic_platform.component import Component + from sonic_platform_base.sonic_pcie.pcie_common import PcieUtil +except ImportError as e: + raise ImportError(str(e) + "- required module not found") + + +class Pcie(PcieUtil): + """Edgecore Platform-specific PCIe class""" + + def __init__(self, platform_path): + PcieUtil.__init__(self, platform_path) diff --git a/platform/broadcom/sonic-platform-modules-accton/as7726-32x/sonic_platform/thermal.py b/platform/broadcom/sonic-platform-modules-accton/as7726-32x/sonic_platform/thermal.py index 77d6ec7ae886..d5cd4ebe5562 100644 --- a/platform/broadcom/sonic-platform-modules-accton/as7726-32x/sonic_platform/thermal.py +++ b/platform/broadcom/sonic-platform-modules-accton/as7726-32x/sonic_platform/thermal.py @@ -15,3 +15,9 @@ def __init__(self, index, pddf_data=None, pddf_plugin_data=None, is_psu_thermal= PddfThermal.__init__(self, index, pddf_data, pddf_plugin_data, is_psu_thermal, psu_index) # Provide the functions/variables below for which implementation is to be overwritten + def get_status(self): + get_temp=self.get_temperature() + + if get_temp is not None: + return True if get_temp else False + From e5cedd9be811e6ba13e996a53262073b95bb68e4 Mon Sep 17 00:00:00 2001 From: jostar-yang Date: Fri, 9 Dec 2022 15:07:44 +0800 Subject: [PATCH 02/21] Fix LGTM alerts --- .../as7726-32x/sonic_platform/pcie.py | 4 ---- 1 file changed, 4 deletions(-) diff --git a/platform/broadcom/sonic-platform-modules-accton/as7726-32x/sonic_platform/pcie.py b/platform/broadcom/sonic-platform-modules-accton/as7726-32x/sonic_platform/pcie.py index 0d972249af09..e4da32adf9f8 100644 --- a/platform/broadcom/sonic-platform-modules-accton/as7726-32x/sonic_platform/pcie.py +++ b/platform/broadcom/sonic-platform-modules-accton/as7726-32x/sonic_platform/pcie.py @@ -6,11 +6,7 @@ # Base PCIe class ############################################################################# -import logging - - try: - from sonic_platform.component import Component from sonic_platform_base.sonic_pcie.pcie_common import PcieUtil except ImportError as e: raise ImportError(str(e) + "- required module not found") From cdad806f093f391155a4116bdba56b125f93d6ab Mon Sep 17 00:00:00 2001 From: jostar-yang Date: Mon, 12 Dec 2022 14:24:34 +0800 Subject: [PATCH 03/21] Add get_name to pass pytest --- .../as7726-32x/sonic_platform/fan.py | 16 ++++++++++++- .../as7726-32x/sonic_platform/fan_drawer.py | 8 +++++++ .../as7726-32x/sonic_platform/psu.py | 21 +++++++++++++++++ .../as7726-32x/sonic_platform/sfp.py | 23 +++++++++++++++++++ .../as7726-32x/sonic_platform/thermal.py | 6 +++++ 5 files changed, 73 insertions(+), 1 deletion(-) diff --git a/platform/broadcom/sonic-platform-modules-accton/as7726-32x/sonic_platform/fan.py b/platform/broadcom/sonic-platform-modules-accton/as7726-32x/sonic_platform/fan.py index 23d8be5a8a9e..38fe9dde9565 100644 --- a/platform/broadcom/sonic-platform-modules-accton/as7726-32x/sonic_platform/fan.py +++ b/platform/broadcom/sonic-platform-modules-accton/as7726-32x/sonic_platform/fan.py @@ -6,6 +6,9 @@ except ImportError as e: raise ImportError(str(e) + "- required module not found") +FAN_NAME_LIST = ["FAN-1F", "FAN-1R", "FAN-2F", "FAN-2R", + "FAN-3F", "FAN-3R", "FAN-4F", "FAN-4R", + "FAN-5F", "FAN-5R", "FAN-6F", "FAN-6R"] class Fan(PddfFan): """PDDF Platform-Specific Fan class""" @@ -15,5 +18,16 @@ def __init__(self, tray_idx, fan_idx=0, pddf_data=None, pddf_plugin_data=None, i PddfFan.__init__(self, tray_idx, fan_idx, pddf_data, pddf_plugin_data, is_psu_fan, psu_index) # Provide the functions/variables below for which implementation is to be overwritten - # Since AS4630 psu_fan airflow direction cant be read from sysfs, it is fixed as 'F2B' or 'intake' + + def get_name(self): + """ + Retrieves the name of the device + Returns: + string: The name of the device + """ + fan_name = FAN_NAME_LIST[(self.fantray_index-1)*2 + self.fan_index-1] \ + if not self.is_psu_fan \ + else "PSU-{} FAN-{}".format(self.fans_psu_index, self.fan_index) + + return fan_name diff --git a/platform/broadcom/sonic-platform-modules-accton/as7726-32x/sonic_platform/fan_drawer.py b/platform/broadcom/sonic-platform-modules-accton/as7726-32x/sonic_platform/fan_drawer.py index 3b9bb607f632..5d8bc41f650e 100644 --- a/platform/broadcom/sonic-platform-modules-accton/as7726-32x/sonic_platform/fan_drawer.py +++ b/platform/broadcom/sonic-platform-modules-accton/as7726-32x/sonic_platform/fan_drawer.py @@ -15,3 +15,11 @@ def __init__(self, tray_idx, pddf_data=None, pddf_plugin_data=None): PddfFanDrawer.__init__(self, tray_idx, pddf_data, pddf_plugin_data) # Provide the functions/variables below for which implementation is to be overwritten + def get_name(self): + """ + Retrieves the fan drawer name + Returns: + string: The name of the device + """ + return "FanTray{}".format(self.fantray_index) + diff --git a/platform/broadcom/sonic-platform-modules-accton/as7726-32x/sonic_platform/psu.py b/platform/broadcom/sonic-platform-modules-accton/as7726-32x/sonic_platform/psu.py index a2a330206551..48cdbab12132 100644 --- a/platform/broadcom/sonic-platform-modules-accton/as7726-32x/sonic_platform/psu.py +++ b/platform/broadcom/sonic-platform-modules-accton/as7726-32x/sonic_platform/psu.py @@ -17,6 +17,27 @@ def __init__(self, index, pddf_data=None, pddf_plugin_data=None): PddfPsu.__init__(self, index, pddf_data, pddf_plugin_data) # Provide the functions/variables below for which implementation is to be overwritten + def get_voltage_high_threshold(self): + """ + Retrieves the high threshold PSU voltage output + Returns: + A float number, the high threshold output voltage in volts, + e.g. 12.1 + """ + return 14.72 + + def get_voltage_low_threshold(self): + """ + Retrieves the low threshold PSU voltage output + Returns: + A float number, the low threshold output voltage in volts, + e.g. 12.1 + """ + return 7.68 + + def get_name(self): + return "PSU-{}".format(self.psu_index) + def get_maximum_supplied_power(self): """ Retrieves the maximum supplied power by PSU (or PSU capacity) diff --git a/platform/broadcom/sonic-platform-modules-accton/as7726-32x/sonic_platform/sfp.py b/platform/broadcom/sonic-platform-modules-accton/as7726-32x/sonic_platform/sfp.py index d9b6e491bef4..17d7e9b6c7c1 100644 --- a/platform/broadcom/sonic-platform-modules-accton/as7726-32x/sonic_platform/sfp.py +++ b/platform/broadcom/sonic-platform-modules-accton/as7726-32x/sonic_platform/sfp.py @@ -1,7 +1,10 @@ #!/usr/bin/env python try: + import natsort from sonic_platform_pddf_base.pddf_sfp import PddfSfp + from sonic_platform_base.sonic_sfp.sfputilhelper import SfpUtilHelper + from sonic_py_common import device_info except ImportError as e: raise ImportError (str(e) + "- required module not found") @@ -15,3 +18,23 @@ def __init__(self, index, pddf_data=None, pddf_plugin_data=None): PddfSfp.__init__(self, index, pddf_data, pddf_plugin_data) # Provide the functions/variables below for which implementation is to be overwritten + def __get_path_to_port_config_file(self): + platform, hwsku = device_info.get_platform_and_hwsku() + hwsku_path = "/".join(["/usr/share/sonic/platform",hwsku]) + return "/".join([hwsku_path, "port_config.ini"]) + + def get_name(self): + """ + Retrieves the name of the device + Returns: + string: The name of the device + """ + sfputil_helper = SfpUtilHelper() + sfputil_helper.read_porttab_mappings( + self.__get_path_to_port_config_file()) + + logical_port_list = sfputil_helper.logical + logical_port_list = natsort.natsorted(logical_port_list) + name = logical_port_list[self.port_index-1] or "Unknown" + + return name diff --git a/platform/broadcom/sonic-platform-modules-accton/as7726-32x/sonic_platform/thermal.py b/platform/broadcom/sonic-platform-modules-accton/as7726-32x/sonic_platform/thermal.py index d5cd4ebe5562..98749cbe650f 100644 --- a/platform/broadcom/sonic-platform-modules-accton/as7726-32x/sonic_platform/thermal.py +++ b/platform/broadcom/sonic-platform-modules-accton/as7726-32x/sonic_platform/thermal.py @@ -15,6 +15,12 @@ def __init__(self, index, pddf_data=None, pddf_plugin_data=None, is_psu_thermal= PddfThermal.__init__(self, index, pddf_data, pddf_plugin_data, is_psu_thermal, psu_index) # Provide the functions/variables below for which implementation is to be overwritten + def get_name(self): + if self.is_psu_thermal: + return "PSU-{0} temp sensor 1".format(self.thermals_psu_index) + else: + return "Temp sensor {0}".format(self.thermal_index) + def get_status(self): get_temp=self.get_temperature() From be7af5c8c8cad95d4e11a625123870d506b117cc Mon Sep 17 00:00:00 2001 From: jostar-yang Date: Mon, 12 Dec 2022 15:26:07 +0800 Subject: [PATCH 04/21] Modify fan direction name to lower case --- .../pddf/pd-plugin.json | 4 ++-- .../pddf/pddf-device.json | 17 ++--------------- 2 files changed, 4 insertions(+), 17 deletions(-) diff --git a/device/accton/x86_64-accton_as7726_32x-r0/pddf/pd-plugin.json b/device/accton/x86_64-accton_as7726_32x-r0/pddf/pd-plugin.json index 2b8ad2c459b1..d79bdb4d52a7 100644 --- a/device/accton/x86_64-accton_as7726_32x-r0/pddf/pd-plugin.json +++ b/device/accton/x86_64-accton_as7726_32x-r0/pddf/pd-plugin.json @@ -34,7 +34,7 @@ { "i2c": { - "valmap": { "F2B":"EXHAUST", "B2F":"INTAKE" } + "valmap": { "F2B":"exhaust", "B2F":"intake" } } }, @@ -47,7 +47,7 @@ { "i2c": { - "valmap": {"1":"EXHAUST", "0":"INTAKE"} + "valmap": {"1":"exhaust", "0":"intake"} } }, diff --git a/device/accton/x86_64-accton_as7726_32x-r0/pddf/pddf-device.json b/device/accton/x86_64-accton_as7726_32x-r0/pddf/pddf-device.json index 95f9642773cf..f7953c74a346 100644 --- a/device/accton/x86_64-accton_as7726_32x-r0/pddf/pddf-device.json +++ b/device/accton/x86_64-accton_as7726_32x-r0/pddf/pddf-device.json @@ -5,7 +5,7 @@ "num_fantrays":6, "num_fans_pertray":2, "num_ports":34, - "num_temps":7, + "num_temps":6, "pddf_dev_types": { "description":"AS7726 - Below is the list of supported PDDF device types (chip names) for various components. If any component uses some other driver, we will create the client using 'echo > /new_device' method", @@ -1868,23 +1868,10 @@ "TEMP6" : { "dev_info": { "device_type":"TEMP_SENSOR", "device_name":"TEMP6"}, - "dev_attr": { "display_name":"pch_haswell-virtual-0"}, - "i2c": - { - "path_info": {"sysfs_base_path": "/sys/class/hwmon/hwmon0"}, - "attr_list": - [ - { "attr_name": "temp1_input"} - ] - } - }, - "TEMP7" : - { - "dev_info": { "device_type":"TEMP_SENSOR", "device_name":"TEMP7"}, "dev_attr": { "display_name":"coretemp-isa-0000"}, "i2c": { - "path_info": {"sysfs_base_path": "/sys/class/hwmon/hwmon1"}, + "path_info": {"sysfs_base_path": "/sys/class/hwmon/hwmon0"}, "attr_list": [ { "attr_name": "temp1_high_crit_threshold", "drv_attr_name":"temp1_crit"}, From 2b3e8a5a3d2c8a86e3bd8ab5f1fd70037305202c Mon Sep 17 00:00:00 2001 From: jostar-yang Date: Wed, 21 Dec 2022 16:38:49 +0800 Subject: [PATCH 05/21] Add platform.json to pass pytest --- .../x86_64-accton_as7726_32x-r0/platform.json | 637 ++++++++++++++++++ .../as7726-32x/sonic_platform/event.py | 60 ++ 2 files changed, 697 insertions(+) create mode 100644 device/accton/x86_64-accton_as7726_32x-r0/platform.json create mode 100644 platform/broadcom/sonic-platform-modules-accton/as7726-32x/sonic_platform/event.py diff --git a/device/accton/x86_64-accton_as7726_32x-r0/platform.json b/device/accton/x86_64-accton_as7726_32x-r0/platform.json new file mode 100644 index 000000000000..bb5216c8710c --- /dev/null +++ b/device/accton/x86_64-accton_as7726_32x-r0/platform.json @@ -0,0 +1,637 @@ +{ + "chassis": { + "name": "7726-32X", + "components": [ + { + "name": "CPLD1" + }, + { + "name": "CPLD2" + }, + { + "name": "CPLD3" + }, + { + "name": "CPLD4" + }, + { + "name": "CPLD5" + }, + { + "name": "BIOS" + } + ], + "fans": [ + { + "name": "FAN-1F" + }, + { + "name": "FAN-1R" + }, + { + "name": "FAN-2F" + }, + { + "name": "FAN-2R" + }, + { + "name": "FAN-3F" + }, + { + "name": "FAN-3R" + }, + { + "name": "FAN-4F" + }, + { + "name": "FAN-4R" + }, + { + "name": "FAN-5F" + }, + { + "name": "FAN-5R" + }, + { + "name": "FAN-6F" + }, + { + "name": "FAN-6R" + } + ], + "fan_drawers":[ + { + "name": "FanTray1", + "num_fans" : 2, + "fans": [ + { + "name": "FAN-1F" + }, + { + "name": "FAN-1R" + } + ] + }, + { + "name": "FanTray2", + "num_fans" : 2, + "fans": [ + { + "name": "FAN-2F" + }, + { + "name": "FAN-2R" + } + ] + }, + { + "name": "FanTray3", + "num_fans" : 2, + "fans": [ + { + "name": "FAN-3F" + }, + { + "name": "FAN-3R" + } + ] + }, + { + "name": "FanTray4", + "num_fans" : 2, + "fans": [ + { + "name": "FAN-4F" + }, + { + "name": "FAN-4R" + } + ] + }, + { + "name": "FanTray5", + "num_fans" : 2, + "fans": [ + { + "name": "FAN-5F" + }, + { + "name": "FAN-5R" + } + ] + }, + { + "name": "FanTray6", + "num_fans" : 2, + "fans": [ + { + "name": "FAN-6F" + }, + { + "name": "FAN-6R" + } + ] + } + ], + "psus": [ + { + "name": "PSU-1", + "fans": [ + { + "name": "PSU-1 FAN-1" + } + ], + "thermals": [ + { + "name": "PSU-1 temp sensor 1" + } + ] + }, + { + "name": "PSU-2", + "fans": [ + { + "name": "PSU-2 FAN-1" + } + ], + "thermals": [ + { + "name": "PSU-2 temp sensor 2" + } + ] + } + ], + "thermals": [ + { + "name": "Temp sensor 1" + }, + { + "name": "Temp sensor 2" + }, + { + "name": "Temp sensor 3" + }, + { + "name": "Temp sensor 4" + }, + { + "name": "Temp sensor 5" + }, + { + "name": "CPU Temp" + } + ], + "sfps": [ + { + "name": "Ethernet0" + }, + { + "name": "Ethernet4" + }, + { + "name": "Ethernet8" + }, + { + "name": "Ethernet12" + }, + { + "name": "Ethernet16" + }, + { + "name": "Ethernet20" + }, + { + "name": "Ethernet24" + }, + { + "name": "Ethernet28" + }, + { + "name": "Ethernet32" + }, + { + "name": "Ethernet36" + }, + { + "name": "Ethernet40" + }, + { + "name": "Ethernet44" + }, + { + "name": "Ethernet48" + }, + { + "name": "Ethernet52" + }, + { + "name": "Ethernet56" + }, + { + "name": "Ethernet60" + }, + { + "name": "Ethernet64" + }, + { + "name": "Ethernet68" + }, + { + "name": "Ethernet72" + }, + { + "name": "Ethernet76" + }, + { + "name": "Ethernet80" + }, + { + "name": "Ethernet84" + }, + { + "name": "Ethernet88" + }, + { + "name": "Ethernet92" + }, + { + "name": "Ethernet96" + }, + { + "name": "Ethernet100" + }, + { + "name": "Ethernet104" + }, + { + "name": "Ethernet108" + }, + { + "name": "Ethernet112" + }, + { + "name": "Ethernet116" + }, + { + "name": "Ethernet120" + }, + { + "name": "Ethernet124" + } + ] + }, + "interfaces": { + "Ethernet0": { + "index": "1,1,1,1", + "lanes": "1,2,3,4", + "breakout_modes": { + "1x100G[40G]": ["Eth1(Port1)"], + "2x50G": ["Eth1/1(Port1)", "Eth1/2(Port1)"], + "4x25G": ["Eth1/1(Port1)", "Eth1/2(Port1)", "Eth1/3(Port1)", "Eth1/4(Port1)"], + "4x10G": ["Eth1/1(Port1)", "Eth1/2(Port1)", "Eth1/3(Port1)", "Eth1/4(Port1)"] + } + }, + + "Ethernet4": { + "index": "2,2,2,2", + "lanes": "5,6,7,8", + "breakout_modes": { + "1x100G[40G]": ["Eth2(Port2)"], + "2x50G": ["Eth2/1(Port2)", "Eth2/2(Port2)"], + "4x25G": ["Eth2/1(Port2)", "Eth2/2(Port2)", "Eth2/3(Port2)", "Eth2/4(Port2)"], + "4x10G": ["Eth2/1(Port2)", "Eth2/2(Port2)", "Eth2/3(Port2)", "Eth2/4(Port2)"] + } + }, + + "Ethernet8": { + "index": "3,3,3,3", + "lanes": "9,10,11,12", + "breakout_modes": { + "1x100G[40G]": ["Eth3(Port3)"], + "2x50G": ["Eth3/1(Port3)", "Eth3/2(Port3)"], + "4x25G": ["Eth3/1(Port3)", "Eth3/2(Port3)", "Eth3/3(Port3)", "Eth3/4(Port3)"], + "4x10G": ["Eth3/1(Port3)", "Eth3/2(Port3)", "Eth3/3(Port3)", "Eth3/4(Port3)"] + } + }, + + "Ethernet12": { + "index": "4,4,4,4", + "lanes": "13,14,15,16", + "breakout_modes": { + "1x100G[40G]": ["Eth4(Port4)"], + "2x50G": ["Eth4/1(Port4)", "Eth4/2(Port4)"], + "4x25G": ["Eth4/1(Port4)", "Eth4/2(Port4)", "Eth4/3(Port4)", "Eth4/4(Port4)"], + "4x10G": ["Eth4/1(Port4)", "Eth4/2(Port4)", "Eth4/3(Port4)", "Eth4/4(Port4)"] + } + }, + + "Ethernet16": { + "index": "5,5,5,5", + "lanes": "17,18,19,20", + "breakout_modes": { + "1x100G[40G]": ["Eth5(Port5)"], + "2x50G": ["Eth5/1(Port5)", "Eth5/2(Port5)"], + "4x25G": ["Eth5/1(Port5)", "Eth5/2(Port5)", "Eth5/3(Port5)", "Eth5/4(Port5)"], + "4x10G": ["Eth5/1(Port5)", "Eth5/2(Port5)", "Eth5/3(Port5)", "Eth5/4(Port5)"] + } + }, + + "Ethernet20": { + "index": "6,6,6,6", + "lanes": "21,22,23,24", + "breakout_modes": { + "1x100G[40G]": ["Eth6(Port6)"], + "2x50G": ["Eth6/1(Port6)", "Eth6/2(Port6)"], + "4x25G": ["Eth6/1(Port6)", "Eth6/2(Port6)", "Eth6/3(Port6)", "Eth6/4(Port6)"], + "4x10G": ["Eth6/1(Port6)", "Eth6/2(Port6)", "Eth6/3(Port6)", "Eth6/4(Port6)"] + } + }, + + "Ethernet24": { + "index": "7,7,7,7", + "lanes": "25,26,27,28", + "breakout_modes": { + "1x100G[40G]": ["Eth7(Port7)"], + "2x50G": ["Eth7/1(Port7)", "Eth7/2(Port7)"], + "4x25G": ["Eth7/1(Port7)", "Eth7/2(Port7)", "Eth7/3(Port7)", "Eth7/4(Port7)"], + "4x10G": ["Eth7/1(Port7)", "Eth7/2(Port7)", "Eth7/3(Port7)", "Eth7/4(Port7)"] + } + }, + + "Ethernet28": { + "index": "8,8,8,8", + "lanes": "29,30,31,32", + "breakout_modes": { + "1x100G[40G]": ["Eth8(Port8)"], + "2x50G": ["Eth8/1(Port8)", "Eth8/2(Port8)"], + "4x25G": ["Eth8/1(Port8)", "Eth8/2(Port8)", "Eth8/3(Port8)", "Eth8/4(Port8)"], + "4x10G": ["Eth8/1(Port8)", "Eth8/2(Port8)", "Eth8/3(Port8)", "Eth8/4(Port8)"] + } + }, + + "Ethernet32": { + "index": "9,9,9,9", + "lanes": "33,34,35,36", + "breakout_modes": { + "1x100G[40G]": ["Eth9(Port9)"], + "2x50G": ["Eth9/1(Port9)", "Eth9/2(Port9)"], + "4x25G": ["Eth9/1(Port9)", "Eth9/2(Port9)", "Eth9/3(Port9)", "Eth9/4(Port9)"], + "4x10G": ["Eth9/1(Port9)", "Eth9/2(Port9)", "Eth9/3(Port9)", "Eth9/4(Port9)"] + } + }, + + "Ethernet36": { + "index": "10,10,10,10", + "lanes": "37,38,39,40", + "breakout_modes": { + "1x100G[40G]": ["Eth10(Port10)"], + "2x50G": ["Eth10/1(Port10)", "Eth10/2(Port10)"], + "4x25G": ["Eth10/1(Port10)", "Eth10/2(Port10)", "Eth10/3(Port10)", "Eth10/4(Port10)"], + "4x10G": ["Eth10/1(Port10)", "Eth10/2(Port10)", "Eth10/3(Port10)", "Eth10/4(Port10)"] + } + }, + + "Ethernet40": { + "index": "11,11,11,11", + "lanes": "41,42,43,44", + "breakout_modes": { + "1x100G[40G]": ["Eth11(Port11)"], + "2x50G": ["Eth11/1(Port11)", "Eth11/2(Port11)"], + "4x25G": ["Eth11/1(Port11)", "Eth11/2(Port11)", "Eth11/3(Port11)", "Eth11/4(Port11)"], + "4x10G": ["Eth11/1(Port11)", "Eth11/2(Port11)", "Eth11/3(Port11)", "Eth11/4(Port11)"] + } + }, + + "Ethernet44": { + "index": "12,12,12,12", + "lanes": "45,46,47,48", + "breakout_modes": { + "1x100G[40G]": ["Eth12(Port12)"], + "2x50G": ["Eth12/1(Port12)", "Eth12/2(Port12)"], + "4x25G": ["Eth12/1(Port12)", "Eth12/2(Port12)", "Eth12/3(Port12)", "Eth12/4(Port12)"], + "4x10G": ["Eth12/1(Port12)", "Eth12/2(Port12)", "Eth12/3(Port12)", "Eth12/4(Port12)"] + } + }, + + "Ethernet48": { + "index": "13,13,13,13", + "lanes": "49,50,51,52", + "breakout_modes": { + "1x100G[40G]": ["Eth13(Port13)"], + "2x50G": ["Eth13/1(Port13)", "Eth13/2(Port13)"], + "4x25G": ["Eth13/1(Port13)", "Eth13/2(Port13)", "Eth13/3(Port13)", "Eth13/4(Port13)"], + "4x10G": ["Eth13/1(Port13)", "Eth13/2(Port13)", "Eth13/3(Port13)", "Eth13/4(Port13)"] + } + }, + + "Ethernet52": { + "index": "14,14,14,14", + "lanes": "53,54,55,56", + "breakout_modes": { + "1x100G[40G]": ["Eth14(Port14)"], + "2x50G": ["Eth14/1(Port14)", "Eth14/2(Port14)"], + "4x25G": ["Eth14/1(Port14)", "Eth14/2(Port14)", "Eth14/3(Port14)", "Eth14/4(Port14)"], + "4x10G": ["Eth14/1(Port14)", "Eth14/2(Port14)", "Eth14/3(Port14)", "Eth14/4(Port14)"] + } + }, + + "Ethernet56": { + "index": "15,15,15,15", + "lanes": "57,58,59,60", + "breakout_modes": { + "1x100G[40G]": ["Eth15(Port15)"], + "2x50G": ["Eth15/1(Port15)", "Eth15/2(Port15)"], + "4x25G": ["Eth15/1(Port15)", "Eth15/2(Port15)", "Eth15/3(Port15)", "Eth15/4(Port15)"], + "4x10G": ["Eth15/1(Port15)", "Eth15/2(Port15)", "Eth15/3(Port15)", "Eth15/4(Port15)"] + } + }, + + "Ethernet60": { + "index": "16,16,16,16", + "lanes": "61,62,63,64", + "breakout_modes": { + "1x100G[40G]": ["Eth16(Port16)"], + "2x50G": ["Eth16/1(Port16)", "Eth16/2(Port16)"], + "4x25G": ["Eth16/1(Port16)", "Eth16/2(Port16)", "Eth16/3(Port16)", "Eth16/4(Port16)"], + "4x10G": ["Eth16/1(Port16)", "Eth16/2(Port16)", "Eth16/3(Port16)", "Eth16/4(Port16)"] + } + }, + + "Ethernet64": { + "index": "17,17,17,17", + "lanes": "65,66,67,68", + "breakout_modes": { + "1x100G[40G]": ["Eth17(Port17)"], + "2x50G": ["Eth17/1(Port17)", "Eth17/2(Port17)"], + "4x25G": ["Eth17/1(Port17)", "Eth17/2(Port17)", "Eth17/3(Port17)", "Eth17/4(Port17)"], + "4x10G": ["Eth17/1(Port17)", "Eth17/2(Port17)", "Eth17/3(Port17)", "Eth17/4(Port17)"] + } + }, + + "Ethernet68": { + "index": "18,18,18,18", + "lanes": "69,70,71,72", + "breakout_modes": { + "1x100G[40G]": ["Eth18(Port18)"], + "2x50G": ["Eth18/1(Port18)", "Eth18/2(Port18)"], + "4x25G": ["Eth18/1(Port18)", "Eth18/2(Port18)", "Eth18/3(Port18)", "Eth18/4(Port18)"], + "4x10G": ["Eth18/1(Port18)", "Eth18/2(Port18)", "Eth18/3(Port18)", "Eth18/4(Port18)"] + } + }, + + "Ethernet72": { + "index": "19,19,19,19", + "lanes": "73,74,75,76", + "breakout_modes": { + "1x100G[40G]": ["Eth19(Port19)"], + "2x50G": ["Eth19/1(Port19)", "Eth19/2(Port19)"], + "4x25G": ["Eth19/1(Port19)", "Eth19/2(Port19)", "Eth19/3(Port19)", "Eth19/4(Port19)"], + "4x10G": ["Eth19/1(Port19)", "Eth19/2(Port19)", "Eth19/3(Port19)", "Eth19/4(Port19)"] + } + }, + + "Ethernet76": { + "index": "20,20,20,20", + "lanes": "77,78,79,80", + "breakout_modes": { + "1x100G[40G]": ["Eth20(Port20)"], + "2x50G": ["Eth20/1(Port20)", "Eth20/2(Port20)"], + "4x25G": ["Eth20/1(Port20)", "Eth20/2(Port20)", "Eth20/3(Port20)", "Eth20/4(Port20)"], + "4x10G": ["Eth20/1(Port20)", "Eth20/2(Port20)", "Eth20/3(Port20)", "Eth20/4(Port20)"] + } + }, + + "Ethernet80": { + "index": "21,21,21,21", + "lanes": "81,82,83,84", + "breakout_modes": { + "1x100G[40G]": ["Eth21(Port21)"], + "2x50G": ["Eth21/1(Port21)", "Eth21/2(Port21)"], + "4x25G": ["Eth21/1(Port21)", "Eth21/2(Port21)", "Eth21/3(Port21)", "Eth21/4(Port21)"], + "4x10G": ["Eth21/1(Port21)", "Eth21/2(Port21)", "Eth21/3(Port21)", "Eth21/4(Port21)"] + } + }, + + "Ethernet84": { + "index": "22,22,22,22", + "lanes": "85,86,87,88", + "breakout_modes": { + "1x100G[40G]": ["Eth22(Port22)"], + "2x50G": ["Eth22/1(Port22)", "Eth22/2(Port22)"], + "4x25G": ["Eth22/1(Port22)", "Eth22/2(Port22)", "Eth22/3(Port22)", "Eth22/4(Port22)"], + "4x10G": ["Eth22/1(Port22)", "Eth22/2(Port22)", "Eth22/3(Port22)", "Eth22/4(Port22)"] + } + }, + + "Ethernet88": { + "index": "23,23,23,23", + "lanes": "89,90,91,92", + "breakout_modes": { + "1x100G[40G]": ["Eth23(Port23)"], + "2x50G": ["Eth23/1(Port23)", "Eth23/2(Port23)"], + "4x25G": ["Eth23/1(Port23)", "Eth23/2(Port23)", "Eth23/3(Port23)", "Eth23/4(Port23)"], + "4x10G": ["Eth23/1(Port23)", "Eth23/2(Port23)", "Eth23/3(Port23)", "Eth23/4(Port23)"] + } + }, + + "Ethernet92": { + "index": "24,24,24,24", + "lanes": "93,94,95,96", + "breakout_modes": { + "1x100G[40G]": ["Eth24(Port24)"], + "2x50G": ["Eth24/1(Port24)", "Eth24/2(Port24)"], + "4x25G": ["Eth24/1(Port24)", "Eth24/2(Port24)", "Eth24/3(Port24)", "Eth24/4(Port24)"], + "4x10G": ["Eth24/1(Port24)", "Eth24/2(Port24)", "Eth24/3(Port24)", "Eth24/4(Port24)"] + } + }, + + "Ethernet96": { + "index": "25,25,25,25", + "lanes": "97,98,99,100", + "breakout_modes": { + "1x100G[40G]": ["Eth25(Port25)"], + "2x50G": ["Eth25/1(Port25)", "Eth25/2(Port25)"], + "4x25G": ["Eth25/1(Port25)", "Eth25/2(Port25)", "Eth25/3(Port25)", "Eth25/4(Port25)"], + "4x10G": ["Eth25/1(Port25)", "Eth25/2(Port25)", "Eth25/3(Port25)", "Eth25/4(Port25)"] + } + }, + + "Ethernet100": { + "index": "26,26,26,26", + "lanes": "101,102,103,104", + "breakout_modes": { + "1x100G[40G]": ["Eth26(Port26)"], + "2x50G": ["Eth26/1(Port26)", "Eth26/2(Port26)"], + "4x25G": ["Eth26/1(Port26)", "Eth26/2(Port26)", "Eth26/3(Port26)", "Eth26/4(Port26)"], + "4x10G": ["Eth26/1(Port26)", "Eth26/2(Port26)", "Eth26/3(Port26)", "Eth26/4(Port26)"] + } + }, + + "Ethernet104": { + "index": "27,27,27,27", + "lanes": "105,106,107,108", + "breakout_modes": { + "1x100G[40G]": ["Eth27(Port27)"], + "2x50G": ["Eth27/1(Port27)", "Eth27/2(Port27)"], + "4x25G": ["Eth27/1(Port27)", "Eth27/2(Port27)", "Eth27/3(Port27)", "Eth27/4(Port27)"], + "4x10G": ["Eth27/1(Port27)", "Eth27/2(Port27)", "Eth27/3(Port27)", "Eth27/4(Port27)"] + } + }, + + "Ethernet108": { + "index": "28,28,28,28", + "lanes": "109,110,111,112", + "breakout_modes": { + "1x100G[40G]": ["Eth28(Port28)"], + "2x50G": ["Eth28/1(Port28)", "Eth28/2(Port28)"], + "4x25G": ["Eth28/1(Port28)", "Eth28/2(Port28)", "Eth28/3(Port28)", "Eth28/4(Port28)"], + "4x10G": ["Eth28/1(Port28)", "Eth28/2(Port28)", "Eth28/3(Port28)", "Eth28/4(Port28)"] + } + }, + + "Ethernet112": { + "index": "29,29,29,29", + "lanes": "113,114,115,116", + "breakout_modes": { + "1x100G[40G]": ["Eth29(Port29)"], + "2x50G": ["Eth29/1(Port29)", "Eth29/2(Port29)"], + "4x25G": ["Eth29/1(Port29)", "Eth29/2(Port29)", "Eth29/3(Port29)", "Eth29/4(Port29)"], + "4x10G": ["Eth29/1(Port29)", "Eth29/2(Port29)", "Eth29/3(Port29)", "Eth29/4(Port29)"] + } + }, + + "Ethernet116": { + "index": "30,30,30,30", + "lanes": "117,118,119,120", + "breakout_modes": { + "1x100G[40G]": ["Eth30(Port30)"], + "2x50G": ["Eth30/1(Port30)", "Eth30/2(Port30)"], + "4x25G": ["Eth30/1(Port30)", "Eth30/2(Port30)", "Eth30/3(Port30)", "Eth30/4(Port30)"], + "4x10G": ["Eth30/1(Port30)", "Eth30/2(Port30)", "Eth30/3(Port30)", "Eth30/4(Port30)"] + } + }, + + "Ethernet120": { + "index": "31,31,31,31", + "lanes": "121,122,123,124", + "breakout_modes": { + "1x100G[40G]": ["Eth31(Port31)"], + "2x50G": ["Eth31/1(Port31)", "Eth31/2(Port31)"], + "4x25G": ["Eth31/1(Port31)", "Eth31/2(Port31)", "Eth31/3(Port31)", "Eth31/4(Port31)"], + "4x10G": ["Eth31/1(Port31)", "Eth31/2(Port31)", "Eth31/3(Port31)", "Eth31/4(Port31)"] + } + }, + + "Ethernet124": { + "index": "32,32,32,32", + "lanes": "125,126,127,128", + "breakout_modes": { + "1x100G[40G]": ["Eth32(Port32)"], + "2x50G": ["Eth32/1(Port32)", "Eth32/2(Port32)"], + "4x25G": ["Eth32/1(Port32)", "Eth32/2(Port32)", "Eth32/3(Port32)", "Eth32/4(Port32)"], + "4x10G": ["Eth32/1(Port32)", "Eth32/2(Port32)", "Eth32/3(Port32)", "Eth32/4(Port32)"] + } + } + } +} + diff --git a/platform/broadcom/sonic-platform-modules-accton/as7726-32x/sonic_platform/event.py b/platform/broadcom/sonic-platform-modules-accton/as7726-32x/sonic_platform/event.py new file mode 100644 index 000000000000..d5dac6d7f7e0 --- /dev/null +++ b/platform/broadcom/sonic-platform-modules-accton/as7726-32x/sonic_platform/event.py @@ -0,0 +1,60 @@ +try: + import time + from sonic_py_common.logger import Logger +except ImportError as e: + raise ImportError(repr(e) + " - required module not found") + +POLL_INTERVAL_IN_SEC = 1 + +class SfpEvent: + ''' Listen to insert/remove sfp events ''' + + def __init__(self, sfp_list): + self._sfp_list = sfp_list + self._logger = Logger() + self._sfp_change_event_data = {'present': 0} + + def get_presence_bitmap(self): + bitmap = 0 + for sfp in self._sfp_list: + modpres = sfp.get_presence() + i=sfp.get_position_in_parent() - 1 + if modpres: + bitmap = bitmap | (1 << i) + return bitmap + + def get_sfp_event(self, timeout=2000): + port_dict = {} + change_dict = {} + change_dict['sfp'] = port_dict + + if timeout < 1000: + cd_ms = 1000 + else: + cd_ms = timeout + + while cd_ms > 0: + bitmap = self.get_presence_bitmap() + changed_ports = self._sfp_change_event_data['present'] ^ bitmap + if changed_ports != 0: + break + time.sleep(POLL_INTERVAL_IN_SEC) + # timeout=0 means wait for event forever + if timeout != 0: + cd_ms = cd_ms - POLL_INTERVAL_IN_SEC * 1000 + + if changed_ports != 0: + for sfp in self._sfp_list: + i=sfp.get_position_in_parent() - 1 + if (changed_ports & (1 << i)): + if (bitmap & (1 << i)) == 0: + port_dict[i+1] = '0' + else: + port_dict[i+1] = '1' + + + # Update the cache dict + self._sfp_change_event_data['present'] = bitmap + return True, change_dict + else: + return True, change_dict From 2315510cd26854b62df438224dd2139134114c77 Mon Sep 17 00:00:00 2001 From: jostar-yang Date: Thu, 22 Dec 2022 14:03:58 +0800 Subject: [PATCH 06/21] Add compoment.py --- .../as7726-32x/sonic_platform/component.py | 192 ++++++++++++++++++ 1 file changed, 192 insertions(+) create mode 100644 platform/broadcom/sonic-platform-modules-accton/as7726-32x/sonic_platform/component.py diff --git a/platform/broadcom/sonic-platform-modules-accton/as7726-32x/sonic_platform/component.py b/platform/broadcom/sonic-platform-modules-accton/as7726-32x/sonic_platform/component.py new file mode 100644 index 000000000000..945e9c176d00 --- /dev/null +++ b/platform/broadcom/sonic-platform-modules-accton/as7726-32x/sonic_platform/component.py @@ -0,0 +1,192 @@ +############################################################################# +# +# Component contains an implementation of SONiC Platform Base API and +# provides the components firmware management function +# +############################################################################# + +try: + import subprocess + from sonic_platform_base.component_base import ComponentBase +except ImportError as e: + raise ImportError(str(e) + "- required module not found") + +CPLD_ADDR_MAPPING = { + "CPLD1": ['11', '0x60'], + "CPLD2": ['12', '0x62'], + "CPLD3": ['13', '0x64'], + "CPLD4": ['54', '0x66'] +} +SYSFS_PATH = "/sys/bus/i2c/devices/" +BIOS_VERSION_PATH = "/sys/class/dmi/id/bios_version" +COMPONENT_LIST= [ + ("CPLD1", "CPLD 1"), + ("CPLD2", "CPLD 2"), + ("CPLD3", "CPLD 3"), + ("CPLD4", "CPLD 4"), + ("CPLD5", "CPLD 5"), + ("BIOS", "Basic Input/Output System") + +] + +class Component(ComponentBase): + """Platform-specific Component class""" + + DEVICE_TYPE = "component" + + def __init__(self, component_index=0): + self.index = component_index + self.name = self.get_name() + + def __run_command(self, command): + # Run bash command and print output to stdout + try: + process = subprocess.Popen( + shlex.split(command), stdout=subprocess.PIPE) + while True: + output = process.stdout.readline() + if output == '' and process.poll() is not None: + break + rc = process.poll() + if rc != 0: + return False + except Exception: + return False + return True + + def __get_bios_version(self): + # Retrieves the BIOS firmware version + try: + with open(BIOS_VERSION_PATH, 'r') as fd: + bios_version = fd.read() + return bios_version.strip() + except Exception as e: + return None + + def __get_cpld_version(self): + # Retrieves the CPLD firmware version + cpld_version = dict() + for cpld_name in CPLD_ADDR_MAPPING: + cmd = "i2cget -f -y {0} {1} 0x1".format(CPLD_ADDR_MAPPING[cpld_name][0], CPLD_ADDR_MAPPING[cpld_name][1]) + status, value = subprocess.getstatusoutput(cmd) + if not status: + cpld_version_raw = value.rstrip() + cpld_version[cpld_name] = "{}".format(int(cpld_version_raw,16)) + + return cpld_version + + + def __get_cpld_cpu_version(self): + try: + cpu_version = dict() + cmd = "i2cget -f -y 0 0x65 0x01" + status, output1 = subprocess.getstatusoutput(cmd) + if status == 0 : + cpu_version = "{}".format(output1[2:]) + else : + cpu_version = 'None' + except Exception as e: + cpu_version = 'None' + + return cpu_version + + def get_name(self): + """ + Retrieves the name of the component + Returns: + A string containing the name of the component + """ + return COMPONENT_LIST[self.index][0] + + def get_description(self): + """ + Retrieves the description of the component + Returns: + A string containing the description of the component + """ + return COMPONENT_LIST[self.index][1] + + def get_firmware_version(self): + """ + Retrieves the firmware version of module + Returns: + string: The firmware versions of the module + """ + fw_version = None + + if self.name == "BIOS": + fw_version = self.__get_bios_version() + elif "CPLD5" in self.name: + fw_version = self.__get_cpld_cpu_version() + elif "CPLD" in self.name: + cpld_version = self.__get_cpld_version() + fw_version = cpld_version.get(self.name) + + return fw_version + + def install_firmware(self, image_path): + """ + Install firmware to module + Args: + image_path: A string, path to firmware image + Returns: + A boolean, True if install successfully, False if not + """ + raise NotImplementedError + + def get_presence(self): + """ + Retrieves the presence of the device + Returns: + bool: True if device is present, False if not + """ + return True + + def get_model(self): + """ + Retrieves the model number (or part number) of the device + Returns: + string: Model/part number of device + """ + return 'N/A' + + def get_serial(self): + """ + Retrieves the serial number of the device + Returns: + string: Serial number of device + """ + return 'N/A' + + def get_status(self): + """ + Retrieves the operational status of the device + Returns: + A boolean value, True if device is operating properly, False if not + """ + return True + + def get_position_in_parent(self): + """ + Retrieves 1-based relative physical position in parent device. + If the agent cannot determine the parent-relative position + for some reason, or if the associated value of + entPhysicalContainedIn is'0', then the value '-1' is returned + Returns: + integer: The 1-based relative physical position in parent device + or -1 if cannot determine the position + """ + return -1 + + def is_replaceable(self): + """ + Indicate whether this device is replaceable. + Returns: + bool: True if it is replaceable. + """ + return False + + + + + From f3637e4a32e1d6ad2427ebfa13e0e48febb0fec8 Mon Sep 17 00:00:00 2001 From: jostar-yang Date: Thu, 19 Jan 2023 10:46:47 +0800 Subject: [PATCH 07/21] Add enable fan-wdt and kick --- .../modules/accton_as7726_32x_fan.c | 3 +- .../utils/accton_as7726_32x_pddf_monitor.py | 38 ++++++++++++++++++- 2 files changed, 37 insertions(+), 4 deletions(-) diff --git a/platform/broadcom/sonic-platform-modules-accton/as7726-32x/modules/accton_as7726_32x_fan.c b/platform/broadcom/sonic-platform-modules-accton/as7726-32x/modules/accton_as7726_32x_fan.c index 0341b3802b0f..bc8e11236027 100755 --- a/platform/broadcom/sonic-platform-modules-accton/as7726-32x/modules/accton_as7726_32x_fan.c +++ b/platform/broadcom/sonic-platform-modules-accton/as7726-32x/modules/accton_as7726_32x_fan.c @@ -45,7 +45,6 @@ static struct as7726_32x_fan_data *as7726_32x_fan_update_device(struct device *d static ssize_t fan_show_value(struct device *dev, struct device_attribute *da, char *buf); static ssize_t set_duty_cycle(struct device *dev, struct device_attribute *da, const char *buf, size_t count); -static ssize_t get_sys_temp(struct device *dev, struct device_attribute *da, char *buf); /* fan related data, the index should match sysfs_fan_attributes */ @@ -294,7 +293,7 @@ static ssize_t set_duty_cycle(struct device *dev, struct device_attribute *da, if (value < 0 || value > FAN_MAX_DUTY_CYCLE) return -EINVAL; - as7726_32x_fan_write_value(client, 0x33, 0); /* Disable fan speed watch dog */ + //as7726_32x_fan_write_value(client, 0x33, 0); /* Disable fan speed watch dog */ as7726_32x_fan_write_value(client, fan_reg[FAN_DUTY_CYCLE_PERCENTAGE], duty_cycle_to_reg_val(value)); return count; } diff --git a/platform/broadcom/sonic-platform-modules-accton/as7726-32x/utils/accton_as7726_32x_pddf_monitor.py b/platform/broadcom/sonic-platform-modules-accton/as7726-32x/utils/accton_as7726_32x_pddf_monitor.py index 2b18ac646ac9..4a3d4af98498 100755 --- a/platform/broadcom/sonic-platform-modules-accton/as7726-32x/utils/accton_as7726_32x_pddf_monitor.py +++ b/platform/broadcom/sonic-platform-modules-accton/as7726-32x/utils/accton_as7726_32x_pddf_monitor.py @@ -21,6 +21,7 @@ # 4/20/2018: Jostar modify for as7726_32x # 12/03/2018:Jostar modify for as7726_32x thermal plan # 11/16/2020:Jostar modify for as7726_32x thermal plan based on PDDF +# 11/19/2023:Jostar modify to add kick fan-wdt # ------------------------------------------------------------------ try: @@ -32,6 +33,7 @@ import logging.handlers import time from sonic_platform import platform + from sonic_py_common.general import getstatusoutput_noshell except ImportError as e: raise ImportError('%s - required module not found' % str(e)) @@ -162,7 +164,7 @@ def manage_fans(self): } fan_dir= platform_chassis.get_fan(0).get_direction() - if fan_dir == 'EXHAUST': + if fan_dir == 'exhaust': fan_policy = fan_policy_f2b else: fan_policy = fan_policy_b2f @@ -305,15 +307,47 @@ def main(argv): global platform_chassis platform_chassis = platform.Platform().get_chassis() - + cmd_str = ["i2cset", "-y", "-f", "54", "0x66", "0x33", "0x0"] + status, output = getstatusoutput_noshell(cmd_str) + if status: + print("Warning: Fan speed watchdog could not be disabled") + + cmd_str = ["i2cset", "-y", "-f", "54", "0x66", "0x33", "0x1"] + status, output = getstatusoutput_noshell(cmd_str) + if status: + print("Warning: Fan speed watchdog could not be enabled") + + #Timer need to be set after enable. + #if set timer is eralier than enable wdt. Speed will become to wdt speed after 6sec. + cmd_str = ["i2cset", "-y", "-f", "54", "0x66", "0x31", "0xF0"] + status, output = getstatusoutput_noshell(cmd_str) + if status: + print("Warning: Fan speed watchdog timer could not be disabled") + platform_chassis.get_fan(0).set_speed(38) print("set default fan speed to 37.5%") monitor = device_monitor(log_file, log_level) + + cmd_kick = ["i2cset", "-y", "-f", "54", "0x66", "0x31", "0xF0"] #kick WDT + cmd_check_wdt = ["i2cget", "-y", "-f", "54", "0x66", "0x33"] # Loop forever, doing something useful hopefully: while True: monitor.manage_fans() + getstatusoutput_noshell(cmd_kick) time.sleep(10) + #polling to check fan-wdt status + status, output = getstatusoutput_noshell(cmd_check_wdt) + if status is not None: + val= int(output,16) + if (val & 0x1) == 0: + logging.warning('Detect Fan-WDT disable') + logging.warning('Try to enable Fan-WDT') + cmd_str = ["i2cset", "-y", "-f", "54", "0x66", "0x33", "0x1"] + getstatusoutput_noshell(cmd_str) + cmd_str = ["i2cset", "-y", "-f", "54", "0x66", "0x31", "0xF0"] + getstatusoutput_noshell(cmd_str) + if __name__ == '__main__': main(sys.argv[1:]) From 045a8df6f0d4bbce090df82d218f195b216fb729 Mon Sep 17 00:00:00 2001 From: jostar-yang Date: Thu, 9 Feb 2023 17:50:19 +0800 Subject: [PATCH 08/21] Fix Semgrep check --- .../x86_64-accton_as7726_32x-r0/platform.json | 22 +++--- .../as7726-32x/sonic_platform/component.py | 52 +++---------- .../as7726-32x/sonic_platform/helper.py | 78 ++----------------- .../as7726-32x/sonic_platform/thermal.py | 9 +++ 4 files changed, 36 insertions(+), 125 deletions(-) diff --git a/device/accton/x86_64-accton_as7726_32x-r0/platform.json b/device/accton/x86_64-accton_as7726_32x-r0/platform.json index bb5216c8710c..222ea329b325 100644 --- a/device/accton/x86_64-accton_as7726_32x-r0/platform.json +++ b/device/accton/x86_64-accton_as7726_32x-r0/platform.json @@ -3,19 +3,19 @@ "name": "7726-32X", "components": [ { - "name": "CPLD1" + "name": "MB CPLD1" }, { - "name": "CPLD2" + "name": "MB CPLD2" }, { - "name": "CPLD3" + "name": "MB CPLD3" }, { - "name": "CPLD4" + "name": "FAN CPLD" }, { - "name": "CPLD5" + "name": "CPU CPLD" }, { "name": "BIOS" @@ -156,26 +156,26 @@ ], "thermals": [ { - "name": "PSU-2 temp sensor 2" + "name": "PSU-2 temp sensor 1" } ] } ], "thermals": [ { - "name": "Temp sensor 1" + "name": "CB_temp(0x4B)" }, { - "name": "Temp sensor 2" + "name": "FB_temp(0x4C)" }, { - "name": "Temp sensor 3" + "name": "MB_FrontMAC_temp(0x49)" }, { - "name": "Temp sensor 4" + "name": "MB_LeftCenter_temp(0x4A)" }, { - "name": "Temp sensor 5" + "name": "MB_RearMAC_temp(0x48)" }, { "name": "CPU Temp" diff --git a/platform/broadcom/sonic-platform-modules-accton/as7726-32x/sonic_platform/component.py b/platform/broadcom/sonic-platform-modules-accton/as7726-32x/sonic_platform/component.py index 945e9c176d00..ce01079a7816 100644 --- a/platform/broadcom/sonic-platform-modules-accton/as7726-32x/sonic_platform/component.py +++ b/platform/broadcom/sonic-platform-modules-accton/as7726-32x/sonic_platform/component.py @@ -12,19 +12,20 @@ raise ImportError(str(e) + "- required module not found") CPLD_ADDR_MAPPING = { - "CPLD1": ['11', '0x60'], - "CPLD2": ['12', '0x62'], - "CPLD3": ['13', '0x64'], - "CPLD4": ['54', '0x66'] + "MB CPLD1": ['11', '0x60'], + "MB CPLD2": ['12', '0x62'], + "MB CPLD3": ['13', '0x64'], + "FAN CPLD": ['54', '0x66'], + "CPU CPLD": ['0', '0x65'], } SYSFS_PATH = "/sys/bus/i2c/devices/" BIOS_VERSION_PATH = "/sys/class/dmi/id/bios_version" COMPONENT_LIST= [ - ("CPLD1", "CPLD 1"), - ("CPLD2", "CPLD 2"), - ("CPLD3", "CPLD 3"), - ("CPLD4", "CPLD 4"), - ("CPLD5", "CPLD 5"), + ("MB CPLD1", "Mainboard CPLD 1"), + ("MB CPLD2", "Mainboard CPLD 2"), + ("MB CPLD3", "Mainboard CPLD 3"), + ("FAN CPLD", "Fan board CPLD"), + ("CPU CPLD", "CPU CPLD"), ("BIOS", "Basic Input/Output System") ] @@ -38,22 +39,6 @@ def __init__(self, component_index=0): self.index = component_index self.name = self.get_name() - def __run_command(self, command): - # Run bash command and print output to stdout - try: - process = subprocess.Popen( - shlex.split(command), stdout=subprocess.PIPE) - while True: - output = process.stdout.readline() - if output == '' and process.poll() is not None: - break - rc = process.poll() - if rc != 0: - return False - except Exception: - return False - return True - def __get_bios_version(self): # Retrieves the BIOS firmware version try: @@ -75,21 +60,6 @@ def __get_cpld_version(self): return cpld_version - - def __get_cpld_cpu_version(self): - try: - cpu_version = dict() - cmd = "i2cget -f -y 0 0x65 0x01" - status, output1 = subprocess.getstatusoutput(cmd) - if status == 0 : - cpu_version = "{}".format(output1[2:]) - else : - cpu_version = 'None' - except Exception as e: - cpu_version = 'None' - - return cpu_version - def get_name(self): """ Retrieves the name of the component @@ -116,8 +86,6 @@ def get_firmware_version(self): if self.name == "BIOS": fw_version = self.__get_bios_version() - elif "CPLD5" in self.name: - fw_version = self.__get_cpld_cpu_version() elif "CPLD" in self.name: cpld_version = self.__get_cpld_version() fw_version = cpld_version.get(self.name) diff --git a/platform/broadcom/sonic-platform-modules-accton/as7726-32x/sonic_platform/helper.py b/platform/broadcom/sonic-platform-modules-accton/as7726-32x/sonic_platform/helper.py index b124ca29f0df..5162803fb51f 100644 --- a/platform/broadcom/sonic-platform-modules-accton/as7726-32x/sonic_platform/helper.py +++ b/platform/broadcom/sonic-platform-modules-accton/as7726-32x/sonic_platform/helper.py @@ -4,7 +4,7 @@ from mmap import * from sonic_py_common import device_info -HOST_CHK_CMD = "docker > /dev/null 2>&1" +HOST_CHK_CMD = ["docker"] EMPTY_STRING = "" @@ -14,7 +14,11 @@ def __init__(self): (self.platform, self.hwsku) = device_info.get_platform_and_hwsku() def is_host(self): - return os.system(HOST_CHK_CMD) == 0 + try: + status, output = getstatusoutput_noshell(HOST_CHK_CMD) + return status == 0 + except Exception: + return False def pci_get_value(self, resource, offset): status = True @@ -29,26 +33,6 @@ def pci_get_value(self, resource, offset): status = False return status, result - def run_command(self, cmd): - status = True - result = "" - try: - p = subprocess.Popen( - cmd, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE) - raw_data, err = p.communicate() - if err == '': - result = raw_data.strip() - except Exception: - status = False - return status, result - - def run_interactive_command(self, cmd): - try: - os.system(cmd) - except Exception: - return False - return True - def read_txt_file(self, file_path): try: with open(file_path, 'r', errors='replace') as fd: @@ -65,53 +49,3 @@ def write_txt_file(self, file_path, value): except IOError: return False return True - - def ipmi_raw(self, netfn, cmd): - status = True - result = "" - try: - cmd = "ipmitool raw {} {}".format(str(netfn), str(cmd)) - p = subprocess.Popen( - cmd, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE) - raw_data, err = p.communicate() - if err == '': - result = raw_data.strip() - else: - status = False - except Exception: - status = False - return status, result - - def ipmi_fru_id(self, id, key=None): - status = True - result = "" - try: - cmd = "ipmitool fru print {}".format(str( - id)) if not key else "ipmitool fru print {0} | grep '{1}' ".format(str(id), str(key)) - - p = subprocess.Popen( - cmd, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE) - raw_data, err = p.communicate() - if err == '': - result = raw_data.strip() - else: - status = False - except Exception: - status = False - return status, result - - def ipmi_set_ss_thres(self, id, threshold_key, value): - status = True - result = "" - try: - cmd = "ipmitool sensor thresh '{}' {} {}".format(str(id), str(threshold_key), str(value)) - p = subprocess.Popen( - cmd, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE) - raw_data, err = p.communicate() - if err == '': - result = raw_data.strip() - else: - status = False - except Exception: - status = False - return status, result diff --git a/platform/broadcom/sonic-platform-modules-accton/as7726-32x/sonic_platform/thermal.py b/platform/broadcom/sonic-platform-modules-accton/as7726-32x/sonic_platform/thermal.py index 98749cbe650f..343b7883d049 100644 --- a/platform/broadcom/sonic-platform-modules-accton/as7726-32x/sonic_platform/thermal.py +++ b/platform/broadcom/sonic-platform-modules-accton/as7726-32x/sonic_platform/thermal.py @@ -13,12 +13,21 @@ class Thermal(PddfThermal): def __init__(self, index, pddf_data=None, pddf_plugin_data=None, is_psu_thermal=False, psu_index=0): PddfThermal.__init__(self, index, pddf_data, pddf_plugin_data, is_psu_thermal, psu_index) + + self.pddf_obj = pddf_data + self.thermal_obj_name = "TEMP{}".format(self.thermal_index) + self.thermal_obj = self.pddf_obj.data[self.thermal_obj_name] # Provide the functions/variables below for which implementation is to be overwritten def get_name(self): if self.is_psu_thermal: return "PSU-{0} temp sensor 1".format(self.thermals_psu_index) else: + if 'dev_attr' in self.thermal_obj.keys(): + if 'display_name' in self.thermal_obj['dev_attr']: + return str(self.thermal_obj['dev_attr']['display_name']) + + # In case of errors return "Temp sensor {0}".format(self.thermal_index) def get_status(self): From 122fd258b0544602b0e8e962f2c7d7fa154ff282 Mon Sep 17 00:00:00 2001 From: jostar-yang Date: Fri, 10 Feb 2023 15:02:21 +0800 Subject: [PATCH 09/21] Modify CPLD name to more detail --- .../x86_64-accton_as7726_32x-r0/platform.json | 12 +++++------ .../as7726-32x/sonic_platform/component.py | 20 +++++++++---------- .../as7726-32x/sonic_platform/helper.py | 4 +++- 3 files changed, 19 insertions(+), 17 deletions(-) diff --git a/device/accton/x86_64-accton_as7726_32x-r0/platform.json b/device/accton/x86_64-accton_as7726_32x-r0/platform.json index 222ea329b325..896d9d1b57de 100644 --- a/device/accton/x86_64-accton_as7726_32x-r0/platform.json +++ b/device/accton/x86_64-accton_as7726_32x-r0/platform.json @@ -3,19 +3,19 @@ "name": "7726-32X", "components": [ { - "name": "MB CPLD1" + "name": "MB_CPLD1" }, - { - "name": "MB CPLD2" + { + "name": "MB_CPLD2" }, { - "name": "MB CPLD3" + "name": "MB_CPLD3" }, { - "name": "FAN CPLD" + "name": "FAN_CPLD" }, { - "name": "CPU CPLD" + "name": "CPU_CPLD" }, { "name": "BIOS" diff --git a/platform/broadcom/sonic-platform-modules-accton/as7726-32x/sonic_platform/component.py b/platform/broadcom/sonic-platform-modules-accton/as7726-32x/sonic_platform/component.py index ce01079a7816..7bda9206f950 100644 --- a/platform/broadcom/sonic-platform-modules-accton/as7726-32x/sonic_platform/component.py +++ b/platform/broadcom/sonic-platform-modules-accton/as7726-32x/sonic_platform/component.py @@ -12,20 +12,20 @@ raise ImportError(str(e) + "- required module not found") CPLD_ADDR_MAPPING = { - "MB CPLD1": ['11', '0x60'], - "MB CPLD2": ['12', '0x62'], - "MB CPLD3": ['13', '0x64'], - "FAN CPLD": ['54', '0x66'], - "CPU CPLD": ['0', '0x65'], + "MB_CPLD1": ['11', '0x60'], + "MB_CPLD2": ['12', '0x62'], + "MB_CPLD3": ['13', '0x64'], + "FAN_CPLD": ['54', '0x66'], + "CPU_CPLD": ['0', '0x65'], } SYSFS_PATH = "/sys/bus/i2c/devices/" BIOS_VERSION_PATH = "/sys/class/dmi/id/bios_version" COMPONENT_LIST= [ - ("MB CPLD1", "Mainboard CPLD 1"), - ("MB CPLD2", "Mainboard CPLD 2"), - ("MB CPLD3", "Mainboard CPLD 3"), - ("FAN CPLD", "Fan board CPLD"), - ("CPU CPLD", "CPU CPLD"), + ("MB_CPLD1", "Mainboard CPLD(0x60)"), + ("MB_CPLD2", "Mainboard CPLD(0x62)"), + ("MB_CPLD3", "Mainboard CPLD(0x64)"), + ("FAN_CPLD", "Fan board CPLD(0x66)"), + ("CPU_CPLD", "CPU CPLD(0x65)"), ("BIOS", "Basic Input/Output System") ] diff --git a/platform/broadcom/sonic-platform-modules-accton/as7726-32x/sonic_platform/helper.py b/platform/broadcom/sonic-platform-modules-accton/as7726-32x/sonic_platform/helper.py index 5162803fb51f..09c2af7a8756 100644 --- a/platform/broadcom/sonic-platform-modules-accton/as7726-32x/sonic_platform/helper.py +++ b/platform/broadcom/sonic-platform-modules-accton/as7726-32x/sonic_platform/helper.py @@ -37,7 +37,9 @@ def read_txt_file(self, file_path): try: with open(file_path, 'r', errors='replace') as fd: data = fd.read() - return data.strip() + ret = data.strip() + if len(ret) > 0: + return ret except IOError: pass return None From d2b2118326a3af246c0d2f4e122fc574b1dff144 Mon Sep 17 00:00:00 2001 From: jostar-yang Date: Tue, 14 Feb 2023 16:12:06 +0800 Subject: [PATCH 10/21] Modify sys_led attr name --- .../pddf/pddf-device.json | 14 +++++++------- .../as7726-32x/sonic_platform/fan.py | 19 +++++++++++++++++++ .../as7726-32x/sonic_platform/fan_drawer.py | 16 ++++++++++++++++ .../utils/accton_as7726_32x_pddf_monitor.py | 8 ++++---- 4 files changed, 46 insertions(+), 11 deletions(-) diff --git a/device/accton/x86_64-accton_as7726_32x-r0/pddf/pddf-device.json b/device/accton/x86_64-accton_as7726_32x-r0/pddf/pddf-device.json index f7953c74a346..78494a51baf5 100644 --- a/device/accton/x86_64-accton_as7726_32x-r0/pddf/pddf-device.json +++ b/device/accton/x86_64-accton_as7726_32x-r0/pddf/pddf-device.json @@ -1904,12 +1904,12 @@ "LOC_LED": { "dev_info": { "device_type":"LED", "device_name":"LOC_LED"}, - "dev_attr": { "index":"0"}, + "dev_attr": { "index":"0", "flag": "rw"}, "i2c" : { "attr_list": [ - {"attr_name":"STATUS_LED_COLOR_BLUE", "descr" : "", "bits" : "7", "value" : "0x0", "swpld_addr" : "0x60", "swpld_addr_offset" : "0x41"}, - {"attr_name":"STATUS_LED_COLOR_OFF", "descr" : "", "bits" : "7", "value" : "0x1", "swpld_addr" : "0x60", "swpld_addr_offset" : "0x41"} + {"attr_name":"blue", "descr" : "", "bits" : "7", "value" : "0x0", "swpld_addr" : "0x60", "swpld_addr_offset" : "0x41"}, + {"attr_name":"off", "descr" : "", "bits" : "7", "value" : "0x1", "swpld_addr" : "0x60", "swpld_addr_offset" : "0x41"} ] } }, @@ -1917,13 +1917,13 @@ "DIAG_LED": { "dev_info": { "device_type":"LED", "device_name":"DIAG_LED"}, - "dev_attr": { "index":"0"}, + "dev_attr": { "index":"0", "flag": "rw"}, "i2c" : { "attr_list": [ - {"attr_name":"STATUS_LED_COLOR_GREEN", "descr" : "", "bits" : "1:0", "value" : "0x2", "swpld_addr" : "0x60", "swpld_addr_offset" : "0x41"}, - {"attr_name":"STATUS_LED_COLOR_RED", "descr" : "" ,"bits" : "1:0", "value" : "0x1", "swpld_addr" : "0x60", "swpld_addr_offset" : "0x41"}, - {"attr_name":"STATUS_LED_COLOR_OFF", "descr" : "" ,"bits" : "1:0", "value" : "0x3", "swpld_addr" : "0x60", "swpld_addr_offset" : "0x41"} + {"attr_name":"green", "descr" : "", "bits" : "1:0", "value" : "0x2", "swpld_addr" : "0x60", "swpld_addr_offset" : "0x41"}, + {"attr_name":"red", "descr" : "" ,"bits" : "1:0", "value" : "0x1", "swpld_addr" : "0x60", "swpld_addr_offset" : "0x41"}, + {"attr_name":"off", "descr" : "" ,"bits" : "1:0", "value" : "0x3", "swpld_addr" : "0x60", "swpld_addr_offset" : "0x41"} ] } diff --git a/platform/broadcom/sonic-platform-modules-accton/as7726-32x/sonic_platform/fan.py b/platform/broadcom/sonic-platform-modules-accton/as7726-32x/sonic_platform/fan.py index 38fe9dde9565..89406230e5e9 100644 --- a/platform/broadcom/sonic-platform-modules-accton/as7726-32x/sonic_platform/fan.py +++ b/platform/broadcom/sonic-platform-modules-accton/as7726-32x/sonic_platform/fan.py @@ -31,3 +31,22 @@ def get_name(self): return fan_name + + + + def get_model(self): + """ + Retrieves the model number (or part number) of the device + Returns: + string: Model/part number of device + """ + + return "N/A" + + def get_serial(self): + """ + Retrieves the serial number of the device + Returns: + string: Serial number of device + """ + return "N/A" diff --git a/platform/broadcom/sonic-platform-modules-accton/as7726-32x/sonic_platform/fan_drawer.py b/platform/broadcom/sonic-platform-modules-accton/as7726-32x/sonic_platform/fan_drawer.py index 5d8bc41f650e..e4e37f962067 100644 --- a/platform/broadcom/sonic-platform-modules-accton/as7726-32x/sonic_platform/fan_drawer.py +++ b/platform/broadcom/sonic-platform-modules-accton/as7726-32x/sonic_platform/fan_drawer.py @@ -23,3 +23,19 @@ def get_name(self): """ return "FanTray{}".format(self.fantray_index) + def get_model(self): + """ + Retrieves the model number (or part number) of the device + Returns: + string: Model/part number of device + """ + return self._fan_list[0].get_model() + + def get_serial(self): + """ + Retrieves the serial number of the device + Returns: + string: Serial number of device + """ + return self._fan_list[0].get_serial() + diff --git a/platform/broadcom/sonic-platform-modules-accton/as7726-32x/utils/accton_as7726_32x_pddf_monitor.py b/platform/broadcom/sonic-platform-modules-accton/as7726-32x/utils/accton_as7726_32x_pddf_monitor.py index 4a3d4af98498..5d27ba134a91 100755 --- a/platform/broadcom/sonic-platform-modules-accton/as7726-32x/utils/accton_as7726_32x_pddf_monitor.py +++ b/platform/broadcom/sonic-platform-modules-accton/as7726-32x/utils/accton_as7726_32x_pddf_monitor.py @@ -307,10 +307,10 @@ def main(argv): global platform_chassis platform_chassis = platform.Platform().get_chassis() - cmd_str = ["i2cset", "-y", "-f", "54", "0x66", "0x33", "0x0"] - status, output = getstatusoutput_noshell(cmd_str) - if status: - print("Warning: Fan speed watchdog could not be disabled") + #cmd_str = ["i2cset", "-y", "-f", "54", "0x66", "0x33", "0x0"] + #status, output = getstatusoutput_noshell(cmd_str) + #if status: + # print("Warning: Fan speed watchdog could not be disabled") cmd_str = ["i2cset", "-y", "-f", "54", "0x66", "0x33", "0x1"] status, output = getstatusoutput_noshell(cmd_str) From 0fcffa20a309795d96658b6a946b5bc4e53a21ff Mon Sep 17 00:00:00 2001 From: jostar-yang Date: Thu, 16 Feb 2023 11:25:57 +0800 Subject: [PATCH 11/21] Modify eeprom.py to support cache --- .../as7726-32x/sonic_platform/eeprom.py | 76 ++++++++++++++++++- 1 file changed, 75 insertions(+), 1 deletion(-) diff --git a/platform/broadcom/sonic-platform-modules-accton/as7726-32x/sonic_platform/eeprom.py b/platform/broadcom/sonic-platform-modules-accton/as7726-32x/sonic_platform/eeprom.py index a87ecc9f6feb..ca9b5ce062d1 100644 --- a/platform/broadcom/sonic-platform-modules-accton/as7726-32x/sonic_platform/eeprom.py +++ b/platform/broadcom/sonic-platform-modules-accton/as7726-32x/sonic_platform/eeprom.py @@ -2,13 +2,87 @@ try: from sonic_platform_pddf_base.pddf_eeprom import PddfEeprom + import os except ImportError as e: raise ImportError(str(e) + "- required module not found") +CACHE_ROOT = '/var/cache/sonic/decode-syseeprom' +CACHE_FILE = 'syseeprom_cache' class Eeprom(PddfEeprom): + _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) + #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) + self.eeprom_tlv_dict = dict() + + # Create the cache directory if not created + if not os.path.exists(CACHE_ROOT): + try: + os.makedirs(CACHE_ROOT) + except Exception as e: + print("Error in creating Eeprom cache directory - {}".format(str(e))) + + # Assign cache_name in eeprom_base.py + try: + self.set_cache_name(os.path.join(CACHE_ROOT, CACHE_FILE)) + except: + pass + + try: + self.eeprom_data = self.read_eeprom() + except Exception as e: + self.eeprom_data = "N/A" + raise RuntimeError("Eeprom is not Programmed - Error: {}".format(str(e))) + else: + eeprom = self.eeprom_data + + try: + self.update_cache(eeprom) + except: + pass + + 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) < len(eeprom) 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: + value = str(((tlv[2]) << 24) | ((tlv[3]) << 16) | + ((tlv[4]) << 8) | (tlv[5])) + value += str(tlv[6:6 + (tlv[1])]) + 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 + # Provide the functions/variables below for which implementation is to be overwritten From bc460f6e62da29c52d828d3a81756f4d278fbcca Mon Sep 17 00:00:00 2001 From: jostar-yang Date: Fri, 17 Feb 2023 14:28:31 +0800 Subject: [PATCH 12/21] Modify devices_to_ignore for pus_fan --- .../system_health_monitoring_config.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/device/accton/x86_64-accton_as7726_32x-r0/system_health_monitoring_config.json b/device/accton/x86_64-accton_as7726_32x-r0/system_health_monitoring_config.json index 53b14bec17be..958dca9a4ff3 100644 --- a/device/accton/x86_64-accton_as7726_32x-r0/system_health_monitoring_config.json +++ b/device/accton/x86_64-accton_as7726_32x-r0/system_health_monitoring_config.json @@ -4,8 +4,8 @@ "asic", "psu.voltage", "psu.temperature", - "PSU1_FAN1.speed", - "PSU2_FAN1.speed" + "PSU-1 FAN-1.speed", + "PSU-2 FAN-1.speed" ], "user_defined_checkers": [], "polling_interval": 60, From dbe07a398971b617a9757746da6a4494b0f3a4e4 Mon Sep 17 00:00:00 2001 From: jostar-yang Date: Tue, 21 Feb 2023 11:25:28 +0800 Subject: [PATCH 13/21] Add psu_fan target speed --- .../x86_64-accton_as7726_32x-r0/platform.json | 2 +- .../system_health_monitoring_config.json | 4 +-- .../as7726-32x/sonic_platform/chassis.py | 31 ++++++++++++++++++- .../as7726-32x/sonic_platform/fan.py | 13 ++++++++ 4 files changed, 45 insertions(+), 5 deletions(-) diff --git a/device/accton/x86_64-accton_as7726_32x-r0/platform.json b/device/accton/x86_64-accton_as7726_32x-r0/platform.json index 896d9d1b57de..c75e1532c7e7 100644 --- a/device/accton/x86_64-accton_as7726_32x-r0/platform.json +++ b/device/accton/x86_64-accton_as7726_32x-r0/platform.json @@ -178,7 +178,7 @@ "name": "MB_RearMAC_temp(0x48)" }, { - "name": "CPU Temp" + "name": "coretemp-isa-0000" } ], "sfps": [ diff --git a/device/accton/x86_64-accton_as7726_32x-r0/system_health_monitoring_config.json b/device/accton/x86_64-accton_as7726_32x-r0/system_health_monitoring_config.json index 958dca9a4ff3..bb3bec0efab0 100644 --- a/device/accton/x86_64-accton_as7726_32x-r0/system_health_monitoring_config.json +++ b/device/accton/x86_64-accton_as7726_32x-r0/system_health_monitoring_config.json @@ -3,9 +3,7 @@ "devices_to_ignore": [ "asic", "psu.voltage", - "psu.temperature", - "PSU-1 FAN-1.speed", - "PSU-2 FAN-1.speed" + "psu.temperature" ], "user_defined_checkers": [], "polling_interval": 60, diff --git a/platform/broadcom/sonic-platform-modules-accton/as7726-32x/sonic_platform/chassis.py b/platform/broadcom/sonic-platform-modules-accton/as7726-32x/sonic_platform/chassis.py index 1f23dcf81c57..e1c3b1f57e99 100644 --- a/platform/broadcom/sonic-platform-modules-accton/as7726-32x/sonic_platform/chassis.py +++ b/platform/broadcom/sonic-platform-modules-accton/as7726-32x/sonic_platform/chassis.py @@ -85,7 +85,7 @@ def get_sfp(self, index): sys.stderr.write("SFP index {} out of range (1-{})\n".format( index, len(self._sfp_list))) return sfp - + def initizalize_system_led(self): return @@ -101,3 +101,32 @@ def get_port_or_cage_type(self, port): return SfpBase.SFP_PORT_TYPE_BIT_QSFP | SfpBase.SFP_PORT_TYPE_BIT_QSFP_PLUS | SfpBase.SFP_PORT_TYPE_BIT_QSFP28 else: return SfpBase.SFP_PORT_TYPE_BIT_SFP | SfpBase.SFP_PORT_TYPE_BIT_SFP_PLUS + + def get_position_in_parent(self): + """ + Retrieves 1-based relative physical position in parent device. + If the agent cannot determine the parent-relative position + for some reason, or if the associated value of + entPhysicalContainedIn is'0', then the value '-1' is returned + Returns: + integer: The 1-based relative physical position in parent device + or -1 if cannot determine the position + """ + return -1 + + def is_replaceable(self): + """ + Indicate whether this device is replaceable. + Returns: + bool: True if it is replaceable. + """ + return False + + def get_revision(self): + """ + Retrieves the hardware revision of the device + + Returns: + string: Revision value of device + """ + return 'N/A' \ No newline at end of file diff --git a/platform/broadcom/sonic-platform-modules-accton/as7726-32x/sonic_platform/fan.py b/platform/broadcom/sonic-platform-modules-accton/as7726-32x/sonic_platform/fan.py index 89406230e5e9..3611ac5d2594 100644 --- a/platform/broadcom/sonic-platform-modules-accton/as7726-32x/sonic_platform/fan.py +++ b/platform/broadcom/sonic-platform-modules-accton/as7726-32x/sonic_platform/fan.py @@ -50,3 +50,16 @@ def get_serial(self): string: Serial number of device """ return "N/A" + + def get_target_speed(self): + """ + Retrieves the target (expected) speed of the fan + + Returns: + An integer, the percentage of full fan speed, in the range 0 (off) + to 100 (full speed) + """ + if self.is_psu_fan: + return super().get_speed() + else: + return super().get_target_speed() From cb2be4167564cb046aaa0f76a1e07d7ce0174f09 Mon Sep 17 00:00:00 2001 From: jostar-yang Date: Tue, 21 Feb 2023 15:11:21 +0800 Subject: [PATCH 14/21] Modify system_health_monitoring_config.json led_color string --- .../system_health_monitoring_config.json | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/device/accton/x86_64-accton_as7726_32x-r0/system_health_monitoring_config.json b/device/accton/x86_64-accton_as7726_32x-r0/system_health_monitoring_config.json index bb3bec0efab0..930308045951 100644 --- a/device/accton/x86_64-accton_as7726_32x-r0/system_health_monitoring_config.json +++ b/device/accton/x86_64-accton_as7726_32x-r0/system_health_monitoring_config.json @@ -8,8 +8,8 @@ "user_defined_checkers": [], "polling_interval": 60, "led_color": { - "fault": "STATUS_LED_COLOR_AMBER", - "normal": "STATUS_LED_COLOR_GREEN", - "booting": "STATUS_LED_COLOR_OFF" + "fault": "amber", + "normal": "green", + "booting": "off" } } From 2a96a94a29d7e4cabe8c1c01ddc8cca2627949dc Mon Sep 17 00:00:00 2001 From: roger530-ho Date: Wed, 15 Mar 2023 01:42:57 +0000 Subject: [PATCH 15/21] Fix pytest issue --- .../pddf/pddf-device.json | 14 +- .../x86_64-accton_as7726_32x-r0/platform.json | 341 +++++++++++++++--- .../platform_components.json | 14 + .../system_health_monitoring_config.json | 4 +- .../as7726-32x/sonic_platform/chassis.py | 2 +- .../as7726-32x/sonic_platform/component.py | 39 +- .../as7726-32x/sonic_platform/eeprom.py | 76 +--- .../as7726-32x/sonic_platform/event.py | 59 ++- .../as7726-32x/sonic_platform/fan.py | 13 + .../as7726-32x/sonic_platform/helper.py | 317 +++++++++++++++- .../as7726-32x/sonic_platform/psu.py | 36 +- .../as7726-32x/sonic_platform/sfp.py | 153 ++++++++ .../as7726-32x/sonic_platform/thermal.py | 236 +++++++++++- .../utils/accton_as7726_32x_util.py | 239 ++++++++++-- 14 files changed, 1343 insertions(+), 200 deletions(-) create mode 100644 device/accton/x86_64-accton_as7726_32x-r0/platform_components.json diff --git a/device/accton/x86_64-accton_as7726_32x-r0/pddf/pddf-device.json b/device/accton/x86_64-accton_as7726_32x-r0/pddf/pddf-device.json index 78494a51baf5..5b2cabb749b9 100644 --- a/device/accton/x86_64-accton_as7726_32x-r0/pddf/pddf-device.json +++ b/device/accton/x86_64-accton_as7726_32x-r0/pddf/pddf-device.json @@ -4,7 +4,7 @@ "num_psus":2, "num_fantrays":6, "num_fans_pertray":2, - "num_ports":34, + "num_ports":32, "num_temps":6, "pddf_dev_types": { @@ -1657,7 +1657,11 @@ { "attr_name":"psu_i_out", "attr_devaddr":"0x58", "attr_devtype":"pmbus", "attr_offset":"0x8c", "attr_mask":"0x0", "attr_cmpval":"0xff", "attr_len":"2"}, { "attr_name":"psu_p_out", "attr_devaddr":"0x58", "attr_devtype":"pmbus", "attr_offset":"0x96", "attr_mask":"0x0", "attr_cmpval":"0xff", "attr_len":"2"}, { "attr_name":"psu_fan1_speed_rpm", "attr_devaddr":"0x58", "attr_devtype":"pmbus", "attr_offset":"0x90", "attr_mask":"0x0", "attr_cmpval":"0xff", "attr_len":"2"}, - { "attr_name":"psu_temp1_input", "attr_devaddr":"0x58", "attr_devtype":"pmbus", "attr_offset":"0x8d", "attr_mask":"0x0", "attr_cmpval":"0xff", "attr_len":"2"} + { "attr_name":"psu_temp1_input", "attr_devaddr":"0x58", "attr_devtype":"pmbus", "attr_offset":"0x8d", "attr_mask":"0x0", "attr_cmpval":"0xff", "attr_len":"2"}, + { "attr_name":"psu_v_out_max", "attr_devaddr":"0x58", "attr_devtype":"pmbus", "attr_offset":"0xa5", "attr_mask":"0x0", "attr_cmpval":"0xff", "attr_len":"2"}, + { "attr_name":"psu_v_out_min", "attr_devaddr":"0x58", "attr_devtype":"pmbus", "attr_offset":"0xa4", "attr_mask":"0x0", "attr_cmpval":"0xff", "attr_len":"2"}, + { "attr_name":"psu_p_out_max", "attr_devaddr":"0x58", "attr_devtype":"pmbus", "attr_offset":"0xa7", "attr_mask":"0x0", "attr_cmpval":"0xff", "attr_len":"2"}, + { "attr_name":"psu_temp1_high_threshold", "attr_devaddr":"0x58", "attr_devtype":"pmbus", "attr_offset":"0xa8", "attr_mask":"0x0", "attr_cmpval":"0xff", "attr_len":"2"} ] } }, @@ -1705,7 +1709,11 @@ { "attr_name":"psu_i_out", "attr_devaddr":"0x5b", "attr_devtype":"pmbus", "attr_offset":"0x8c", "attr_mask":"0x0", "attr_cmpval":"0xff", "attr_len":"2"}, { "attr_name":"psu_p_out", "attr_devaddr":"0x5b", "attr_devtype":"pmbus", "attr_offset":"0x96", "attr_mask":"0x0", "attr_cmpval":"0xff", "attr_len":"2"}, { "attr_name":"psu_fan1_speed_rpm", "attr_devaddr":"0x5b", "attr_devtype":"pmbus", "attr_offset":"0x90", "attr_mask":"0x0", "attr_cmpval":"0xff", "attr_len":"2"}, - { "attr_name":"psu_temp1_input", "attr_devaddr":"0x5b", "attr_devtype":"pmbus", "attr_offset":"0x8d", "attr_mask":"0x0", "attr_cmpval":"0xff", "attr_len":"2"} + { "attr_name":"psu_temp1_input", "attr_devaddr":"0x5b", "attr_devtype":"pmbus", "attr_offset":"0x8d", "attr_mask":"0x0", "attr_cmpval":"0xff", "attr_len":"2"}, + { "attr_name":"psu_v_out_max", "attr_devaddr":"0x5b", "attr_devtype":"pmbus", "attr_offset":"0xa5", "attr_mask":"0x0", "attr_cmpval":"0xff", "attr_len":"2"}, + { "attr_name":"psu_v_out_min", "attr_devaddr":"0x5b", "attr_devtype":"pmbus", "attr_offset":"0xa4", "attr_mask":"0x0", "attr_cmpval":"0xff", "attr_len":"2"}, + { "attr_name":"psu_p_out_max", "attr_devaddr":"0x5b", "attr_devtype":"pmbus", "attr_offset":"0xa7", "attr_mask":"0x0", "attr_cmpval":"0xff", "attr_len":"2"}, + { "attr_name":"psu_temp1_high_threshold", "attr_devaddr":"0x5b", "attr_devtype":"pmbus", "attr_offset":"0xa8", "attr_mask":"0x0", "attr_cmpval":"0xff", "attr_len":"2"} ] } }, diff --git a/device/accton/x86_64-accton_as7726_32x-r0/platform.json b/device/accton/x86_64-accton_as7726_32x-r0/platform.json index c75e1532c7e7..3ca60cf1c291 100644 --- a/device/accton/x86_64-accton_as7726_32x-r0/platform.json +++ b/device/accton/x86_64-accton_as7726_32x-r0/platform.json @@ -1,6 +1,11 @@ { "chassis": { "name": "7726-32X", + "thermal_manager":false, + "status_led": { + "controllable": true, + "colors": ["green", "red", "off"] + }, "components": [ { "name": "MB_CPLD1" @@ -23,112 +28,298 @@ ], "fans": [ { - "name": "FAN-1F" - }, - { - "name": "FAN-1R" - }, - { - "name": "FAN-2F" - }, - { - "name": "FAN-2R" - }, - { - "name": "FAN-3F" - }, - { - "name": "FAN-3R" - }, - { - "name": "FAN-4F" - }, - { - "name": "FAN-4R" - }, - { - "name": "FAN-5F" - }, - { - "name": "FAN-5R" - }, - { - "name": "FAN-6F" - }, - { - "name": "FAN-6R" + "name": "FAN-1F", + "speed": { + "controllable": true, + "minimum": 32 + }, + "status_led": { + "controllable": false + } + }, + { + "name": "FAN-1R", + "speed": { + "controllable": true, + "minimum": 32 + }, + "status_led": { + "controllable": false + } + }, + { + "name": "FAN-2F", + "speed": { + "controllable": true, + "minimum": 32 + }, + "status_led": { + "controllable": false + } + }, + { + "name": "FAN-2R", + "speed": { + "controllable": true, + "minimum": 32 + }, + "status_led": { + "controllable": false + } + }, + { + "name": "FAN-3F", + "speed": { + "controllable": true, + "minimum": 32 + }, + "status_led": { + "controllable": false + } + }, + { + "name": "FAN-3R", + "speed": { + "controllable": true, + "minimum": 32 + }, + "status_led": { + "controllable": false + } + }, + { + "name": "FAN-4F", + "speed": { + "controllable": true, + "minimum": 32 + }, + "status_led": { + "controllable": false + } + }, + { + "name": "FAN-4R", + "speed": { + "controllable": true, + "minimum": 32 + }, + "status_led": { + "controllable": false + } + }, + { + "name": "FAN-5F", + "speed": { + "controllable": true, + "minimum": 32 + }, + "status_led": { + "controllable": false + } + }, + { + "name": "FAN-5R", + "speed": { + "controllable": true, + "minimum": 32 + }, + "status_led": { + "controllable": false + } + }, + { + "name": "FAN-6F", + "speed": { + "controllable": true, + "minimum": 32 + }, + "status_led": { + "controllable": false + } + }, + { + "name": "FAN-6R", + "speed": { + "controllable": true, + "minimum": 32 + }, + "status_led": { + "controllable": false + } } ], "fan_drawers":[ { "name": "FanTray1", + "status_led": { + "controllable": false + }, "num_fans" : 2, "fans": [ { - "name": "FAN-1F" + "name": "FAN-1F", + "speed": { + "controllable": true, + "minimum": 32 + }, + "status_led": { + "controllable": false + } }, { - "name": "FAN-1R" + "name": "FAN-1R", + "speed": { + "controllable": true, + "minimum": 32 + }, + "status_led": { + "controllable": false + } } ] }, { "name": "FanTray2", + "status_led": { + "controllable": false + }, "num_fans" : 2, "fans": [ { - "name": "FAN-2F" + "name": "FAN-2F", + "speed": { + "controllable": true, + "minimum": 32 + }, + "status_led": { + "controllable": false + } }, { - "name": "FAN-2R" + "name": "FAN-2R", + "speed": { + "controllable": true, + "minimum": 32 + }, + "status_led": { + "controllable": false + } } ] }, { "name": "FanTray3", + "status_led": { + "controllable": false + }, "num_fans" : 2, "fans": [ { - "name": "FAN-3F" + "name": "FAN-3F", + "speed": { + "controllable": true, + "minimum": 32 + }, + "status_led": { + "controllable": false + } }, { - "name": "FAN-3R" + "name": "FAN-3R", + "speed": { + "controllable": true, + "minimum": 32 + }, + "status_led": { + "controllable": false + } } ] }, { "name": "FanTray4", + "status_led": { + "controllable": false + }, "num_fans" : 2, "fans": [ { - "name": "FAN-4F" + "name": "FAN-4F", + "speed": { + "controllable": true, + "minimum": 32 + }, + "status_led": { + "controllable": false + } }, { - "name": "FAN-4R" + "name": "FAN-4R", + "speed": { + "controllable": true, + "minimum": 32 + }, + "status_led": { + "controllable": false + } } ] }, { "name": "FanTray5", + "status_led": { + "controllable": false + }, "num_fans" : 2, "fans": [ { - "name": "FAN-5F" + "name": "FAN-5F", + "speed": { + "controllable": true, + "minimum": 32 + }, + "status_led": { + "controllable": false + } }, { - "name": "FAN-5R" + "name": "FAN-5R", + "speed": { + "controllable": true, + "minimum": 32 + }, + "status_led": { + "controllable": false + } } ] }, { "name": "FanTray6", + "status_led": { + "controllable": false + }, "num_fans" : 2, "fans": [ { - "name": "FAN-6F" + "name": "FAN-6F", + "speed": { + "controllable": true, + "minimum": 32 + }, + "status_led": { + "controllable": false + } }, { - "name": "FAN-6R" + "name": "FAN-6R", + "speed": { + "controllable": true, + "minimum": 32 + }, + "status_led": { + "controllable": false + } } ] } @@ -136,6 +327,9 @@ "psus": [ { "name": "PSU-1", + "status_led": { + "controllable": false + }, "fans": [ { "name": "PSU-1 FAN-1" @@ -143,12 +337,18 @@ ], "thermals": [ { - "name": "PSU-1 temp sensor 1" + "name": "PSU-1 temp sensor 1", + "controllable": false, + "low-crit-threshold": false, + "high-crit-threshold": false } ] }, { "name": "PSU-2", + "status_led": { + "controllable": false + }, "fans": [ { "name": "PSU-2 FAN-1" @@ -156,29 +356,62 @@ ], "thermals": [ { - "name": "PSU-2 temp sensor 1" + "name": "PSU-2 temp sensor 2", + "controllable": false, + "low-crit-threshold": false, + "high-crit-threshold": false } ] } ], "thermals": [ { - "name": "CB_temp(0x4B)" + "name": "CB_temp(0x4B)", + "controllable": true, + "low-threshold": false, + "high-threshold": true, + "low-crit-threshold": false, + "high-crit-threshold": false }, { - "name": "FB_temp(0x4C)" + "name": "FB_temp(0x4C)", + "controllable": true, + "low-threshold": false, + "high-threshold": true, + "low-crit-threshold": false, + "high-crit-threshold": false }, { - "name": "MB_FrontMAC_temp(0x49)" + "name": "MB_FrontMAC_temp(0x49)", + "controllable": true, + "low-threshold": false, + "high-threshold": true, + "low-crit-threshold": false, + "high-crit-threshold": false }, { - "name": "MB_LeftCenter_temp(0x4A)" + "name": "MB_LeftCenter_temp(0x4A)", + "controllable": true, + "low-threshold": false, + "high-threshold": true, + "low-crit-threshold": false, + "high-crit-threshold": false }, { - "name": "MB_RearMAC_temp(0x48)" + "name": "MB_RearMAC_temp(0x48)", + "controllable": true, + "low-threshold": false, + "high-threshold": true, + "low-crit-threshold": false, + "high-crit-threshold": false }, { - "name": "coretemp-isa-0000" + "name": "coretemp-isa-0000", + "controllable": false, + "low-threshold": false, + "high-threshold": true, + "low-crit-threshold": false, + "high-crit-threshold": true } ], "sfps": [ diff --git a/device/accton/x86_64-accton_as7726_32x-r0/platform_components.json b/device/accton/x86_64-accton_as7726_32x-r0/platform_components.json new file mode 100644 index 000000000000..bf9378baeb4b --- /dev/null +++ b/device/accton/x86_64-accton_as7726_32x-r0/platform_components.json @@ -0,0 +1,14 @@ +{ + "chassis": { + "7726-32X-O-AC-F": { + "component": { + "MB_CPLD1": { }, + "MB_CPLD2": { }, + "MB_CPLD3": { }, + "FAN_CPLD": { }, + "CPU_CPLD": { }, + "BIOS": { } + } + } + } +} diff --git a/device/accton/x86_64-accton_as7726_32x-r0/system_health_monitoring_config.json b/device/accton/x86_64-accton_as7726_32x-r0/system_health_monitoring_config.json index 930308045951..2eb552f83f09 100644 --- a/device/accton/x86_64-accton_as7726_32x-r0/system_health_monitoring_config.json +++ b/device/accton/x86_64-accton_as7726_32x-r0/system_health_monitoring_config.json @@ -1,9 +1,7 @@ { "services_to_ignore": [], "devices_to_ignore": [ - "asic", - "psu.voltage", - "psu.temperature" + "asic" ], "user_defined_checkers": [], "polling_interval": 60, diff --git a/platform/broadcom/sonic-platform-modules-accton/as7726-32x/sonic_platform/chassis.py b/platform/broadcom/sonic-platform-modules-accton/as7726-32x/sonic_platform/chassis.py index e1c3b1f57e99..c0cfc5c79ca2 100644 --- a/platform/broadcom/sonic-platform-modules-accton/as7726-32x/sonic_platform/chassis.py +++ b/platform/broadcom/sonic-platform-modules-accton/as7726-32x/sonic_platform/chassis.py @@ -129,4 +129,4 @@ def get_revision(self): Returns: string: Revision value of device """ - return 'N/A' \ No newline at end of file + return self._eeprom.revision_str() diff --git a/platform/broadcom/sonic-platform-modules-accton/as7726-32x/sonic_platform/component.py b/platform/broadcom/sonic-platform-modules-accton/as7726-32x/sonic_platform/component.py index 7bda9206f950..704b4e22082f 100644 --- a/platform/broadcom/sonic-platform-modules-accton/as7726-32x/sonic_platform/component.py +++ b/platform/broadcom/sonic-platform-modules-accton/as7726-32x/sonic_platform/component.py @@ -6,8 +6,10 @@ ############################################################################# try: - import subprocess + import os + import json from sonic_platform_base.component_base import ComponentBase + from sonic_py_common.general import getstatusoutput_noshell except ImportError as e: raise ImportError(str(e) + "- required module not found") @@ -52,8 +54,8 @@ def __get_cpld_version(self): # Retrieves the CPLD firmware version cpld_version = dict() for cpld_name in CPLD_ADDR_MAPPING: - cmd = "i2cget -f -y {0} {1} 0x1".format(CPLD_ADDR_MAPPING[cpld_name][0], CPLD_ADDR_MAPPING[cpld_name][1]) - status, value = subprocess.getstatusoutput(cmd) + cmd = ["i2cget", "-f", "-y", CPLD_ADDR_MAPPING[cpld_name][0], CPLD_ADDR_MAPPING[cpld_name][1], "0x1"] + status, value = getstatusoutput_noshell(cmd) if not status: cpld_version_raw = value.rstrip() cpld_version[cpld_name] = "{}".format(int(cpld_version_raw,16)) @@ -100,7 +102,36 @@ def install_firmware(self, image_path): Returns: A boolean, True if install successfully, False if not """ - raise NotImplementedError + ret, output = getstatusoutput_noshell(["tar", "-C", "/tmp", "-xzf", image_path ] ) + if ret != 0 : + print("Installation failed because of wrong image package") + return False + + if False == os.path.exists("/tmp/install.json") : + print("Installation failed without jsonfile") + return False + + input_file = open ('/tmp/install.json') + json_array = json.load(input_file) + ret = 1 + for item in json_array: + if item.get('id')==None or item.get('path')==None: + continue + if self.name == item['id'] and item['path'] and item.get('cpu'): + print( "Find", item['id'], item['path'], item['cpu'] ) + ret, output = getstatusoutput_noshell(["/tmp/run_install.sh", item['id'], item['path'], item['cpu'] ]) + if ret==0: + break + elif self.name == item['id'] and item['path']: + print( "Find", item['id'], item['path'] ) + ret, output = getstatusoutput_noshell(["/tmp/run_install.sh", item['id'], item['path'] ]) + if ret==0: + break + + if ret==0: + return True + else : + return False def get_presence(self): """ diff --git a/platform/broadcom/sonic-platform-modules-accton/as7726-32x/sonic_platform/eeprom.py b/platform/broadcom/sonic-platform-modules-accton/as7726-32x/sonic_platform/eeprom.py index ca9b5ce062d1..a87ecc9f6feb 100644 --- a/platform/broadcom/sonic-platform-modules-accton/as7726-32x/sonic_platform/eeprom.py +++ b/platform/broadcom/sonic-platform-modules-accton/as7726-32x/sonic_platform/eeprom.py @@ -2,87 +2,13 @@ try: from sonic_platform_pddf_base.pddf_eeprom import PddfEeprom - import os except ImportError as e: raise ImportError(str(e) + "- required module not found") -CACHE_ROOT = '/var/cache/sonic/decode-syseeprom' -CACHE_FILE = 'syseeprom_cache' class Eeprom(PddfEeprom): - _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) - self.eeprom_tlv_dict = dict() - - # Create the cache directory if not created - if not os.path.exists(CACHE_ROOT): - try: - os.makedirs(CACHE_ROOT) - except Exception as e: - print("Error in creating Eeprom cache directory - {}".format(str(e))) - - # Assign cache_name in eeprom_base.py - try: - self.set_cache_name(os.path.join(CACHE_ROOT, CACHE_FILE)) - except: - pass - - try: - self.eeprom_data = self.read_eeprom() - except Exception as e: - self.eeprom_data = "N/A" - raise RuntimeError("Eeprom is not Programmed - Error: {}".format(str(e))) - else: - eeprom = self.eeprom_data - - try: - self.update_cache(eeprom) - except: - pass - - 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) < len(eeprom) 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: - value = str(((tlv[2]) << 24) | ((tlv[3]) << 16) | - ((tlv[4]) << 8) | (tlv[5])) - value += str(tlv[6:6 + (tlv[1])]) - 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 - + PddfEeprom.__init__(self, pddf_data, pddf_plugin_data) # Provide the functions/variables below for which implementation is to be overwritten diff --git a/platform/broadcom/sonic-platform-modules-accton/as7726-32x/sonic_platform/event.py b/platform/broadcom/sonic-platform-modules-accton/as7726-32x/sonic_platform/event.py index d5dac6d7f7e0..1a2f60dbb67f 100644 --- a/platform/broadcom/sonic-platform-modules-accton/as7726-32x/sonic_platform/event.py +++ b/platform/broadcom/sonic-platform-modules-accton/as7726-32x/sonic_platform/event.py @@ -1,11 +1,21 @@ try: import time from sonic_py_common.logger import Logger + from .sfp import Sfp except ImportError as e: raise ImportError(repr(e) + " - required module not found") POLL_INTERVAL_IN_SEC = 1 +# SFP errors that will block eeprom accessing +SFP_BLOCKING_ERRORS = [ + Sfp.SFP_ERROR_BIT_I2C_STUCK, + Sfp.SFP_ERROR_BIT_BAD_EEPROM, + Sfp.SFP_ERROR_BIT_UNSUPPORTED_CABLE, + Sfp.SFP_ERROR_BIT_HIGH_TEMP, + Sfp.SFP_ERROR_BIT_BAD_CABLE +] + class SfpEvent: ''' Listen to insert/remove sfp events ''' @@ -46,15 +56,54 @@ def get_sfp_event(self, timeout=2000): if changed_ports != 0: for sfp in self._sfp_list: i=sfp.get_position_in_parent() - 1 - if (changed_ports & (1 << i)): - if (bitmap & (1 << i)) == 0: - port_dict[i+1] = '0' - else: - port_dict[i+1] = '1' + if (changed_ports & (1 << i)) == 0: + continue + + if (bitmap & (1 << i)) == 0: + port_dict[i+1] = '0' + else: + # sfp.refresh_optoe_dev_class() + sfp_state_bits = self.get_sfp_state_bits(sfp, True) + sfp_state_bits = self.check_sfp_blocking_errors(sfp_state_bits) + port_dict[i+1] = str(sfp_state_bits) # Update the cache dict self._sfp_change_event_data['present'] = bitmap return True, change_dict else: return True, change_dict + + def get_sfp_state_bits(self, sfp, present): + sfp_state_bits = 0 + + if present is True: + sfp_state_bits |= Sfp.SFP_STATUS_BIT_INSERTED + else: + return sfp_state_bits + + status = sfp.validate_eeprom() + if status is None: + sfp_state_bits |= Sfp.SFP_ERROR_BIT_I2C_STUCK + return sfp_state_bits + elif status is not True: + sfp_state_bits |= Sfp.SFP_ERROR_BIT_BAD_EEPROM + return sfp_state_bits + + status = sfp.validate_temperature() + if status is None: + sfp_state_bits |= Sfp.SFP_ERROR_BIT_I2C_STUCK + return sfp_state_bits + elif status is not True: + sfp_state_bits |= Sfp.SFP_ERROR_BIT_HIGH_TEMP + return sfp_state_bits + + return sfp_state_bits + + def check_sfp_blocking_errors(self, sfp_state_bits): + for i in SFP_BLOCKING_ERRORS: + if (i & sfp_state_bits) == 0: + continue + sfp_state_bits |= Sfp.SFP_ERROR_BIT_BLOCKING + + return sfp_state_bits diff --git a/platform/broadcom/sonic-platform-modules-accton/as7726-32x/sonic_platform/fan.py b/platform/broadcom/sonic-platform-modules-accton/as7726-32x/sonic_platform/fan.py index 3611ac5d2594..46df75e256db 100644 --- a/platform/broadcom/sonic-platform-modules-accton/as7726-32x/sonic_platform/fan.py +++ b/platform/broadcom/sonic-platform-modules-accton/as7726-32x/sonic_platform/fan.py @@ -63,3 +63,16 @@ def get_target_speed(self): return super().get_speed() else: return super().get_target_speed() + + def get_direction(self): + """ + Retrieves the direction of fan + Returns: + A string, either FAN_DIRECTION_INTAKE or FAN_DIRECTION_EXHAUST + depending on fan direction + """ + direction = super().get_direction() + if direction is not None and len(direction) > 0: + return direction + + return 'N/A' diff --git a/platform/broadcom/sonic-platform-modules-accton/as7726-32x/sonic_platform/helper.py b/platform/broadcom/sonic-platform-modules-accton/as7726-32x/sonic_platform/helper.py index 09c2af7a8756..b5e2e5a226fd 100644 --- a/platform/broadcom/sonic-platform-modules-accton/as7726-32x/sonic_platform/helper.py +++ b/platform/broadcom/sonic-platform-modules-accton/as7726-32x/sonic_platform/helper.py @@ -1,8 +1,14 @@ import os import struct -import subprocess +import json +import fcntl from mmap import * from sonic_py_common import device_info +from sonic_py_common import logger +from threading import Lock +from typing import cast +from sonic_py_common.general import getstatusoutput_noshell_pipe +from sonic_py_common.general import getstatusoutput_noshell HOST_CHK_CMD = ["docker"] EMPTY_STRING = "" @@ -33,6 +39,13 @@ def pci_get_value(self, resource, offset): status = False return status, result + def run_interactive_command(self, cmd): + try: + os.system(cmd) + except Exception: + return False + return True + def read_txt_file(self, file_path): try: with open(file_path, 'r', errors='replace') as fd: @@ -51,3 +64,305 @@ def write_txt_file(self, file_path, value): except IOError: return False return True + + def ipmi_raw(self, netfn, cmd): + status = True + result = "" + try: + err, raw_data = getstatusoutput_noshell_pipe(['ipmitool', 'raw', str(netfn), str(cmd)]) + if err == [0]: + result = raw_data.strip() + else: + status = False + except Exception: + status = False + return status, result + + def ipmi_fru_id(self, id, key=None): + status = True + result = "" + try: + if (key is None): + err, raw_data = getstatusoutput_noshell_pipe(['ipmitool', 'fru', 'print', str(id)]) + else: + err, raw_data = getstatusoutput_noshell_pipe(['ipmitool', 'fru', 'print', str(id)], ['grep', str(key)]) + if err == [0] or err == [0, 0]: + result = raw_data.strip() + else: + status = False + except Exception: + status = False + return status, result + + def ipmi_set_ss_thres(self, id, threshold_key, value): + status = True + result = "" + try: + err, raw_data = getstatusoutput_noshell_pipe(['ipmitool', 'sensor', 'thresh', str(id), str(threshold_key), str(value)]) + if err == [0]: + result = raw_data.strip() + else: + status = False + except Exception: + status = False + return status, result + + +class FileLock: + """ + Due to pmon docker not installing the py-filelock, this class + implements a simple file lock feature. + Ref: https://github.com/tox-dev/py-filelock/blob/main/src/filelock/ + """ + + def __init__(self, lock_file): + self._lock_file = lock_file + self._thread_lock = Lock() + self.is_locked = False + + def acquire(self): + with self._thread_lock: + if self.is_locked: + return + + fd = os.open(self._lock_file, flags=(os.O_RDWR | os.O_CREAT | os.O_TRUNC)) + fcntl.flock(fd, fcntl.LOCK_EX) + self._lock_file_fd = fd + self.is_locked = True + + def release(self): + with self._thread_lock: + if self.is_locked: + fd = cast(int, self._lock_file_fd) + self._lock_file_fd = None + fcntl.flock(fd, fcntl.LOCK_UN) + os.close(fd) + self.is_locked = False + + def __enter__(self): + self.acquire() + return self + + def __exit__(self, exc_type, exc_val, traceback): + self.release() + + def __del__(self): + self.release() + + +DEVICE_THRESHOLD_JSON_PATH = "/tmp/device_threshold.json" + +class DeviceThreshold: + HIGH_THRESHOLD = 'high_threshold' + LOW_THRESHOLD = 'low_threshold' + HIGH_CRIT_THRESHOLD = 'high_critical_threshold' + LOW_CRIT_THRESHOLD = 'low_critical_threshold' + NOT_AVAILABLE = 'N/A' + + def __init__(self, th_name = NOT_AVAILABLE): + self.flock = FileLock("{}.lock".format(DEVICE_THRESHOLD_JSON_PATH)) + self.name = th_name + self.__log = logger.Logger(log_identifier="DeviceThreshold") + + self.__db_data = {} + self.__db_mtime = 0 + + def __reload_db(self): + try: + db_data = {} + with self.flock: + with open(DEVICE_THRESHOLD_JSON_PATH, "r") as db_file: + db_data = json.load(db_file) + except Exception as e: + self.__log.log_warning('{}'.format(str(e))) + return None + + return db_data + + def __get_data(self, field): + """ + Retrieves data frome JSON file by field + + Args : + field: String + + Returns: + A string if getting is successfully, 'N/A' if not + """ + if os.path.exists(DEVICE_THRESHOLD_JSON_PATH): + new_mtime = os.path.getmtime(DEVICE_THRESHOLD_JSON_PATH) + if new_mtime != self.__db_mtime: + new_data = self.__reload_db() + if new_data is not None: + self.__db_data = new_data + self.__db_mtime = new_mtime + + if self.name not in self.__db_data.keys(): + return self.NOT_AVAILABLE + + if field not in self.__db_data[self.name].keys(): + return self.NOT_AVAILABLE + + return self.__db_data[self.name][field] + + def __set_data(self, field, new_val): + """ + Set data to JSON file by field + + Args : + field: String + new_val: String + + Returns: + A boolean, True if setting is set successfully, False if not + """ + if self.name not in self.__db_data.keys(): + self.__db_data[self.name] = {} + + old_val = self.__db_data[self.name].get(field, None) + if old_val is not None and old_val == new_val: + return True + + self.__db_data[self.name][field] = new_val + + try: + with self.flock: + db_data = {} + mode = "r+" if os.path.exists(DEVICE_THRESHOLD_JSON_PATH) else "w+" + with open(DEVICE_THRESHOLD_JSON_PATH, mode) as db_file: + if mode == "r+": + db_data = json.load(db_file) + + if self.name not in db_data.keys(): + db_data[self.name] = {} + + db_data[self.name][field] = new_val + + if mode == "r+": + db_file.seek(0) + # erase old data + db_file.truncate(0) + # write all data + json.dump(db_data, db_file, indent=4) + self.__db_mtime = os.path.getmtime(DEVICE_THRESHOLD_JSON_PATH) + except Exception as e: + self.__log.log_error('{}'.format(str(e))) + return False + + return True + + def get_high_threshold(self): + """ + Retrieves the high threshold temperature from JSON file. + + Returns: + string : the high threshold temperature of thermal, + e.g. "30.125" + """ + return self.__get_data(self.HIGH_THRESHOLD) + + def set_high_threshold(self, temperature): + """ + Sets the high threshold temperature of thermal + Args : + temperature: A string of temperature, e.g. "30.125" + Returns: + A boolean, True if threshold is set successfully, False if not + """ + if isinstance(temperature, str) is not True: + raise TypeError('The parameter requires string type.') + + try: + if temperature != self.NOT_AVAILABLE: + float(temperature) + except ValueError: + raise ValueError('The parameter requires a float string. ex:\"30.1\"') + + return self.__set_data(self.HIGH_THRESHOLD, temperature) + + def get_low_threshold(self): + """ + Retrieves the low threshold temperature from JSON file. + + Returns: + string : the low threshold temperature of thermal, + e.g. "30.125" + """ + return self.__get_data(self.LOW_THRESHOLD) + + def set_low_threshold(self, temperature): + """ + Sets the low threshold temperature of thermal + Args : + temperature: A string of temperature, e.g. "30.125" + Returns: + A boolean, True if threshold is set successfully, False if not + """ + if isinstance(temperature, str) is not True: + raise TypeError('The parameter requires string type.') + + try: + if temperature != self.NOT_AVAILABLE: + float(temperature) + except ValueError: + raise ValueError('The parameter requires a float string. ex:\"30.1\"') + + return self.__set_data(self.LOW_THRESHOLD, temperature) + + def get_high_critical_threshold(self): + """ + Retrieves the high critical threshold temperature from JSON file. + + Returns: + string : the high critical threshold temperature of thermal, + e.g. "30.125" + """ + return self.__get_data(self.HIGH_CRIT_THRESHOLD) + + def set_high_critical_threshold(self, temperature): + """ + Sets the high critical threshold temperature of thermal + Args : + temperature: A string of temperature, e.g. "30.125" + Returns: + A boolean, True if threshold is set successfully, False if not + """ + if isinstance(temperature, str) is not True: + raise TypeError('The parameter requires string type.') + + try: + if temperature != self.NOT_AVAILABLE: + float(temperature) + except ValueError: + raise ValueError('The parameter requires a float string. ex:\"30.1\"') + + return self.__set_data(self.HIGH_CRIT_THRESHOLD, temperature) + + def get_low_critical_threshold(self): + """ + Retrieves the low critical threshold temperature from JSON file. + + Returns: + string : the low critical threshold temperature of thermal, + e.g. "30.125" + """ + return self.__get_data(self.LOW_CRIT_THRESHOLD) + + def set_low_critical_threshold(self, temperature): + """ + Sets the low critical threshold temperature of thermal + Args : + temperature: A string of temperature, e.g. "30.125" + Returns: + A boolean, True if threshold is set successfully, False if not + """ + if isinstance(temperature, str) is not True: + raise TypeError('The parameter requires string type.') + + try: + if temperature != self.NOT_AVAILABLE: + float(temperature) + except ValueError: + raise ValueError('The parameter requires a float string. ex:\"30.1\"') + + return self.__set_data(self.LOW_CRIT_THRESHOLD, temperature) diff --git a/platform/broadcom/sonic-platform-modules-accton/as7726-32x/sonic_platform/psu.py b/platform/broadcom/sonic-platform-modules-accton/as7726-32x/sonic_platform/psu.py index 48cdbab12132..18b3ab0d848d 100644 --- a/platform/broadcom/sonic-platform-modules-accton/as7726-32x/sonic_platform/psu.py +++ b/platform/broadcom/sonic-platform-modules-accton/as7726-32x/sonic_platform/psu.py @@ -11,8 +11,6 @@ class Psu(PddfPsu): """PDDF Platform-Specific PSU class""" - PLATFORM_PSU_CAPACITY = 1200 - def __init__(self, index, pddf_data=None, pddf_plugin_data=None): PddfPsu.__init__(self, index, pddf_data, pddf_plugin_data) @@ -38,28 +36,30 @@ def get_voltage_low_threshold(self): def get_name(self): return "PSU-{}".format(self.psu_index) - def get_maximum_supplied_power(self): + def get_temperature_high_threshold(self): """ - Retrieves the maximum supplied power by PSU (or PSU capacity) + Retrieves the high threshold temperature of PSU Returns: - A float number, the maximum power output in Watts. - e.g. 1200.1 + A float number, the high threshold temperature of PSU in Celsius + up to nearest thousandth of one degree Celsius, e.g. 30.125 """ - return float(self.PLATFORM_PSU_CAPACITY) + threshold = super().get_temperature_high_threshold() - def get_capacity(self): - """ - Gets the capacity (maximum output power) of the PSU in watts + for psu_thermal_idx in range(self.num_psu_thermals): + try: + tmp = self._thermal_list[psu_thermal_idx].get_high_threshold() + if threshold > tmp or threshold == 0.0: + threshold = tmp + except Exception: + pass - Returns: - An integer, the capacity of PSU - """ - return (self.PLATFORM_PSU_CAPACITY) + return threshold - def get_type(self): + def get_revision(self): """ - Gets the type of the PSU + Retrieves the hardware revision of the device + Returns: - A string, the type of PSU (AC/DC) + string: Revision value of device """ - return "AC" + return 'N/A' diff --git a/platform/broadcom/sonic-platform-modules-accton/as7726-32x/sonic_platform/sfp.py b/platform/broadcom/sonic-platform-modules-accton/as7726-32x/sonic_platform/sfp.py index 17d7e9b6c7c1..a0189bfcbc7c 100644 --- a/platform/broadcom/sonic-platform-modules-accton/as7726-32x/sonic_platform/sfp.py +++ b/platform/broadcom/sonic-platform-modules-accton/as7726-32x/sonic_platform/sfp.py @@ -14,8 +14,20 @@ class Sfp(PddfSfp): PDDF Platform-Specific Sfp class """ + SFP_TYPE_CODE_LIST = [ + 0x03, # SFP/SFP+/SFP28 + 0x0b # DWDM-SFP/SFP+ + ] + QSFP_TYPE_CODE_LIST = [ + 0x0c, # QSFP + 0x0d, # QSFP+ or later + 0x11, # QSFP28 or later + 0xe1 # QSFP28 EDFA + ] + def __init__(self, index, pddf_data=None, pddf_plugin_data=None): PddfSfp.__init__(self, index, pddf_data, pddf_plugin_data) + self.index = self.port_index # Provide the functions/variables below for which implementation is to be overwritten def __get_path_to_port_config_file(self): @@ -38,3 +50,144 @@ def get_name(self): name = logical_port_list[self.port_index-1] or "Unknown" return name + + def __validate_eeprom_sfp(self): + checksum_test = 0 + eeprom_raw = self.read_eeprom(0, 96) + if eeprom_raw is None: + return None + + for i in range(0, 63): + checksum_test = (checksum_test + eeprom_raw[i]) & 0xFF + else: + if checksum_test != eeprom_raw[63]: + return False + + checksum_test = 0 + for i in range(64, 95): + checksum_test = (checksum_test + eeprom_raw[i]) & 0xFF + else: + if checksum_test != eeprom_raw[95]: + return False + + api = self.get_xcvr_api() + if api is None: + return False + + if api.is_flat_memory(): + return True + + checksum_test = 0 + eeprom_raw = self.read_eeprom(384, 96) + if eeprom_raw is None: + return None + + for i in range(0, 95): + checksum_test = (checksum_test + eeprom_raw[i]) & 0xFF + else: + if checksum_test != eeprom_raw[95]: + return False + + return True + + def __validate_eeprom_qsfp(self): + checksum_test = 0 + eeprom_raw = self.read_eeprom(128, 96) + if eeprom_raw is None: + return None + + for i in range(0, 63): + checksum_test = (checksum_test + eeprom_raw[i]) & 0xFF + else: + if checksum_test != eeprom_raw[63]: + return False + + checksum_test = 0 + for i in range(64, 95): + checksum_test = (checksum_test + eeprom_raw[i]) & 0xFF + else: + if checksum_test != eeprom_raw[95]: + return False + + api = self.get_xcvr_api() + if api is None: + return False + + if api.is_flat_memory(): + return True + + return True + + def validate_eeprom(self): + id_byte_raw = self.read_eeprom(0, 1) + if id_byte_raw is None: + return None + + id = id_byte_raw[0] + if id in self.QSFP_TYPE_CODE_LIST: + return self.__validate_eeprom_qsfp() + elif id in self.SFP_TYPE_CODE_LIST: + return self.__validate_eeprom_sfp() + else: + return False + + def validate_temperature(self): + temperature = self.get_temperature() + if temperature is None: + return None + + threshold_dict = self.get_transceiver_threshold_info() + if threshold_dict is None: + return None + + if isinstance(temperature, float) is not True: + return True + + if isinstance(threshold_dict['temphighalarm'], float) is not True: + return True + + return threshold_dict['temphighalarm'] > temperature + + def __get_error_description(self): + if not self.get_presence(): + return self.SFP_STATUS_UNPLUGGED + + err_stat = self.SFP_STATUS_BIT_INSERTED + + status = self.validate_eeprom() + if status is not True: + err_stat = (err_stat | self.SFP_ERROR_BIT_BAD_EEPROM) + + status = self.validate_temperature() + if status is not True: + err_stat = (err_stat | self.SFP_ERROR_BIT_HIGH_TEMP) + + if err_stat is self.SFP_STATUS_BIT_INSERTED: + return self.SFP_STATUS_OK + else: + err_desc = '' + cnt = 0 + for key in self.SFP_ERROR_BIT_TO_DESCRIPTION_DICT: + if (err_stat & key) != 0: + if cnt > 0: + err_desc = err_desc + "|" + cnt = cnt + 1 + err_desc = err_desc + self.SFP_ERROR_BIT_TO_DESCRIPTION_DICT[key].replace(" ", "_") + + return err_desc + + def get_error_description(self): + """ + Retrives the error descriptions of the SFP module + Returns: + String that represents the current error descriptions of vendor specific errors + In case there are multiple errors, they should be joined by '|', + like: "Bad EEPROM|Unsupported cable" + """ + try: + ret = super().get_error_description() + if ret is not None: + return ret + except NotImplementedError: + pass + return self.__get_error_description() diff --git a/platform/broadcom/sonic-platform-modules-accton/as7726-32x/sonic_platform/thermal.py b/platform/broadcom/sonic-platform-modules-accton/as7726-32x/sonic_platform/thermal.py index 343b7883d049..1fbe0ae921ee 100644 --- a/platform/broadcom/sonic-platform-modules-accton/as7726-32x/sonic_platform/thermal.py +++ b/platform/broadcom/sonic-platform-modules-accton/as7726-32x/sonic_platform/thermal.py @@ -3,17 +3,79 @@ try: from sonic_platform_pddf_base.pddf_thermal import PddfThermal + from .helper import DeviceThreshold except ImportError as e: raise ImportError(str(e) + "- required module not found") +NOT_AVAILABLE = DeviceThreshold.NOT_AVAILABLE +HIGH_THRESHOLD = DeviceThreshold.HIGH_THRESHOLD +LOW_THRESHOLD = DeviceThreshold.LOW_THRESHOLD +HIGH_CRIT_THRESHOLD = DeviceThreshold.HIGH_CRIT_THRESHOLD +LOW_CRIT_THRESHOLD = DeviceThreshold.LOW_CRIT_THRESHOLD +DEFAULT_THRESHOLD = { + 'CB_temp(0x4B)' : { + HIGH_THRESHOLD : '80.0', + LOW_THRESHOLD : NOT_AVAILABLE, + HIGH_CRIT_THRESHOLD : NOT_AVAILABLE, + LOW_CRIT_THRESHOLD : NOT_AVAILABLE + }, + 'FB_temp(0x4C)' : { + HIGH_THRESHOLD : '80.0', + LOW_THRESHOLD : NOT_AVAILABLE, + HIGH_CRIT_THRESHOLD : NOT_AVAILABLE, + LOW_CRIT_THRESHOLD : NOT_AVAILABLE + }, + 'MB_FrontMAC_temp(0x49)' : { + HIGH_THRESHOLD : '80.0', + LOW_THRESHOLD : NOT_AVAILABLE, + HIGH_CRIT_THRESHOLD : NOT_AVAILABLE, + LOW_CRIT_THRESHOLD : NOT_AVAILABLE + }, + 'MB_LeftCenter_temp(0x4A)' : { + HIGH_THRESHOLD : '80.0', + LOW_THRESHOLD : NOT_AVAILABLE, + HIGH_CRIT_THRESHOLD : NOT_AVAILABLE, + LOW_CRIT_THRESHOLD : NOT_AVAILABLE + }, + 'MB_RearMAC_temp(0x48)' : { + HIGH_THRESHOLD : '80.0', + LOW_THRESHOLD : NOT_AVAILABLE, + HIGH_CRIT_THRESHOLD : NOT_AVAILABLE, + LOW_CRIT_THRESHOLD : NOT_AVAILABLE + }, + 'coretemp-isa-0000' : { + HIGH_THRESHOLD : '82.0', + LOW_THRESHOLD : NOT_AVAILABLE, + HIGH_CRIT_THRESHOLD : '104.0', + LOW_CRIT_THRESHOLD : NOT_AVAILABLE + }, + 'PSU-1 temp sensor 1' : { + HIGH_THRESHOLD : '80.0', + LOW_THRESHOLD : NOT_AVAILABLE, + HIGH_CRIT_THRESHOLD : NOT_AVAILABLE, + LOW_CRIT_THRESHOLD : NOT_AVAILABLE + }, + 'PSU-2 temp sensor 1' : { + HIGH_THRESHOLD : '80.0', + LOW_THRESHOLD : NOT_AVAILABLE, + HIGH_CRIT_THRESHOLD : NOT_AVAILABLE, + LOW_CRIT_THRESHOLD : NOT_AVAILABLE + } +} class Thermal(PddfThermal): """PDDF Platform-Specific Thermal class""" def __init__(self, index, pddf_data=None, pddf_plugin_data=None, is_psu_thermal=False, psu_index=0): PddfThermal.__init__(self, index, pddf_data, pddf_plugin_data, is_psu_thermal, psu_index) - + # Threshold Configuration + self.__conf = DeviceThreshold(self.get_name()) + # Default threshold. + self.__default_threshold = DEFAULT_THRESHOLD[self.get_name()] + self.min_temperature = None + self.max_temperature = None + self.pddf_obj = pddf_data self.thermal_obj_name = "TEMP{}".format(self.thermal_index) self.thermal_obj = self.pddf_obj.data[self.thermal_obj_name] @@ -36,3 +98,175 @@ def get_status(self): if get_temp is not None: return True if get_temp else False + def get_temperature(self): + current = super().get_temperature() + + if self.min_temperature is None or \ + current < self.min_temperature: + self.min_temperature = current + + if self.max_temperature is None or \ + current > self.max_temperature: + self.max_temperature = current + + return current + + def set_high_threshold(self, temperature): + try: + value = float(temperature) + except Exception: + return False + + # The new value can not be more than the default value. + default_value = self.__default_threshold[HIGH_THRESHOLD] + if default_value != NOT_AVAILABLE: + if value > float(default_value): + return False + + try: + self.__conf.set_high_threshold(str(value)) + except Exception: + return False + + return True + + def get_high_threshold(self): + value = self.__conf.get_high_threshold() + if value != NOT_AVAILABLE: + return float(value) + + default_value = self.__default_threshold[HIGH_THRESHOLD] + if default_value != NOT_AVAILABLE: + return float(default_value) + + raise NotImplementedError + + def set_low_threshold(self, temperature): + try: + value = float(temperature) + except Exception: + return False + + # The new value can not be less than the default value. + default_value = self.__default_threshold[LOW_THRESHOLD] + if default_value != NOT_AVAILABLE: + if value < float(default_value): + return False + + try: + self.__conf.set_low_threshold(str(value)) + except Exception: + return False + + return True + + def get_low_threshold(self): + value = self.__conf.get_low_threshold() + if value != NOT_AVAILABLE: + return float(value) + + default_value = self.__default_threshold[LOW_THRESHOLD] + if default_value != NOT_AVAILABLE: + return float(default_value) + + raise NotImplementedError + + def set_high_critical_threshold(self, temperature): + try: + value = float(temperature) + except Exception: + return False + + # The new value can not be more than the default value. + default_value = self.__default_threshold[HIGH_CRIT_THRESHOLD] + if default_value != NOT_AVAILABLE: + if value > float(default_value): + return False + + try: + self.__conf.set_high_critical_threshold(str(value)) + except Exception: + return False + + return True + + def get_high_critical_threshold(self): + value = self.__conf.get_high_critical_threshold() + if value != NOT_AVAILABLE: + return float(value) + + default_value = self.__default_threshold[HIGH_CRIT_THRESHOLD] + if default_value != NOT_AVAILABLE: + return float(default_value) + + raise NotImplementedError + + def set_low_critical_threshold(self, temperature): + try: + value = float(temperature) + except Exception: + return False + + # The new value can not be less than the default value. + default_value = self.__default_threshold[LOW_CRIT_THRESHOLD] + if default_value != NOT_AVAILABLE: + if value < float(default_value): + return False + + try: + self.__conf.set_low_critical_threshold(str(value)) + except Exception: + return False + + return True + + def get_low_critical_threshold(self): + value = self.__conf.get_low_critical_threshold() + if value != NOT_AVAILABLE: + return float(value) + + default_value = self.__default_threshold[LOW_CRIT_THRESHOLD] + if default_value != NOT_AVAILABLE: + return float(default_value) + + raise NotImplementedError + + def get_model(self): + """ + Retrieves the model number (or part number) of the device + Returns: + string: Model/part number of device + """ + return 'N/A' + + def get_serial(self): + """ + Retrieves the serial number of the device + Returns: + string: Serial number of device + """ + return 'N/A' + + def get_minimum_recorded(self): + """ + Retrieves the minimum recorded temperature of thermal + Returns: + A float number, the minimum recorded temperature of thermal in Celsius + up to nearest thousandth of one degree Celsius, e.g. 30.125 + """ + if self.min_temperature is None: + self.get_temperature() + + return self.min_temperature + + def get_maximum_recorded(self): + """ + Retrieves the maximum recorded temperature of thermal + Returns: + A float number, the maximum recorded temperature of thermal in Celsius + up to nearest thousandth of one degree Celsius, e.g. 30.125 + """ + if self.min_temperature is None: + self.get_temperature() + + return self.max_temperature diff --git a/platform/broadcom/sonic-platform-modules-accton/as7726-32x/utils/accton_as7726_32x_util.py b/platform/broadcom/sonic-platform-modules-accton/as7726-32x/utils/accton_as7726_32x_util.py index 949f1230de99..0386e74001a1 100755 --- a/platform/broadcom/sonic-platform-modules-accton/as7726-32x/utils/accton_as7726_32x_util.py +++ b/platform/broadcom/sonic-platform-modules-accton/as7726-32x/utils/accton_as7726_32x_util.py @@ -16,22 +16,27 @@ # along with this program. If not, see . """ -Usage: %(scriptName)s [options] command object - -options: - -h | --help : this help message - -d | --debug : run with debug mode - -f | --force : ignore error during installation or clean -command: - install : install drivers and generate related sysfs nodes - clean : uninstall drivers and remove related sysfs nodes +usage: accton_as7726_32x_util.py [-h] [-d] [-f] {install,clean,threshold} ... + +AS7726-32X Platform Utility + +optional arguments: + -h, --help show this help message and exit + -d, --debug run with debug mode + -f, --force ignore error during installation or clean + +Utility Command: + {install,clean,threshold} + install : install drivers and generate related sysfs nodes + clean : uninstall drivers and remove related sysfs nodes + threshold : modify thermal threshold """ import subprocess -import getopt import sys import logging import re import time +import argparse from sonic_py_common.general import getstatusoutput_noshell PROJECT_NAME = 'as7726_32x' @@ -109,37 +114,44 @@ def main(): global DEBUG global args global FORCE + global THRESHOLD_RANGE_LOW, THRESHOLD_RANGE_HIGH + + util_parser = argparse.ArgumentParser(description="AS7726-32X Platform Utility") + util_parser.add_argument("-d", "--debug", dest='debug', action='store_true', default=False, + help="run with debug mode") + util_parser.add_argument("-f", "--force", dest='force', action='store_true', default=False, + help="ignore error during installation or clean") + subcommand = util_parser.add_subparsers(dest='cmd', title='Utility Command', required=True) + subcommand.add_parser('install', help=': install drivers and generate related sysfs nodes') + subcommand.add_parser('clean', help=': uninstall drivers and remove related sysfs nodes') + threshold_parser = subcommand.add_parser('threshold', help=': modify thermal threshold') + threshold_parser.add_argument("-l", dest='list', action='store_true', default=False, + help="list avaliable thermal") + threshold_parser.add_argument("-t", dest='thermal', type=str, metavar='THERMAL_NAME', + help="thermal name, ex: -t 'Temp sensor 1'") + threshold_parser.add_argument("-ht", dest='high_threshold', type=restricted_float, + metavar='THRESHOLD_VALUE', + help="high threshold: %.1f ~ %.1f" % (THRESHOLD_RANGE_LOW, THRESHOLD_RANGE_HIGH)) + threshold_parser.add_argument("-hct", dest='high_crit_threshold', type=restricted_float, + metavar='THRESHOLD_VALUE', + help="high critical threshold : %.1f ~ %.1f" % (THRESHOLD_RANGE_LOW, THRESHOLD_RANGE_HIGH)) + args = util_parser.parse_args() - if len(sys.argv)<2: - show_help() - - options, args = getopt.getopt(sys.argv[1:], 'hdf', ['help', - 'debug', - 'force', - ]) if DEBUG == True: - print(options) print(args) print((len(sys.argv))) - for opt, arg in options: - if opt in ('-h', '--help'): - show_help() - elif opt in ('-d', '--debug'): - DEBUG = True - logging.basicConfig(level=logging.INFO) - elif opt in ('-f', '--force'): - FORCE = 1 - else: - logging.info('no option') - for arg in args: - if arg == 'install': - do_install() - elif arg == 'clean': - do_uninstall() - else: - show_help() + DEBUG = args.debug + if DEBUG: + logging.basicConfig(level=logging.INFO) + FORCE = 1 if args.force else 0 + if args.cmd == 'install': + do_install() + elif args.cmd == 'clean': + do_uninstall() + elif args.cmd == 'threshold': + do_threshold() return 0 @@ -365,5 +377,162 @@ def device_exist(): ret2, log = log_os_system("ls "+i2c_prefix+"i2c-2", 0) return not(ret1 or ret2) +THRESHOLD_RANGE_LOW = 30.0 +THRESHOLD_RANGE_HIGH = 110.0 +# Code to initialize chassis object +init_chassis_code = \ + "import sonic_platform.platform\n"\ + "platform = sonic_platform.platform.Platform()\n"\ + "chassis = platform.get_chassis()\n\n" + +# Looking for thermal +looking_for_thermal_code = \ + "thermal = None\n"\ + "all_thermals = chassis.get_all_thermals()\n"\ + "for psu in chassis.get_all_psus():\n"\ + " all_thermals += psu.get_all_thermals()\n"\ + "for tmp in all_thermals:\n"\ + " if '{}' == tmp.get_name():\n"\ + " thermal = tmp\n"\ + " break\n"\ + "if thermal == None:\n"\ + " print('{} not found!')\n"\ + " exit(1)\n\n" + +def avaliable_thermals(): + global init_chassis_code + + get_all_thermal_name_code = \ + "thermal_list = []\n"\ + "all_thermals = chassis.get_all_thermals()\n"\ + "for psu in chassis.get_all_psus():\n"\ + " all_thermals += psu.get_all_thermals()\n"\ + "for tmp in all_thermals:\n"\ + " thermal_list.append(tmp.get_name())\n"\ + "print(str(thermal_list)[1:-1])\n" + + all_code = "{}{}".format(init_chassis_code, get_all_thermal_name_code) + + status, output = getstatusoutput_noshell(["docker", "exec", "pmon", "python3", "-c", all_code]) + if status != 0: + return "" + return output + +def restricted_float(x): + global THRESHOLD_RANGE_LOW, THRESHOLD_RANGE_HIGH + + try: + x = float(x) + except ValueError: + raise argparse.ArgumentTypeError("%r not a floating-point literal" % (x,)) + + if x < THRESHOLD_RANGE_LOW or x > THRESHOLD_RANGE_HIGH: + raise argparse.ArgumentTypeError("%r not in range [%.1f ~ %.1f]" % + (x, THRESHOLD_RANGE_LOW, THRESHOLD_RANGE_HIGH)) + + return x + +def get_high_threshold(name): + global init_chassis_code, looking_for_thermal_code + + get_high_threshold_code = \ + "try:\n"\ + " print(thermal.get_high_threshold())\n"\ + " exit(0)\n"\ + "except NotImplementedError:\n"\ + " print('Not implement the get_high_threshold method!')\n"\ + " exit(1)" + + all_code = "{}{}{}".format(init_chassis_code, looking_for_thermal_code.format(name, name), + get_high_threshold_code) + + status, output = getstatusoutput_noshell(["docker", "exec", "pmon", "python3", "-c", all_code]) + if status == 1: + return None + + return float(output) + +def get_high_crit_threshold(name): + global init_chassis_code, looking_for_thermal_code + + get_high_crit_threshold_code = \ + "try:\n"\ + " print(thermal.get_high_critical_threshold())\n"\ + " exit(0)\n"\ + "except NotImplementedError:\n"\ + " print('Not implement the get_high_critical_threshold method!')\n"\ + " exit(1)" + + all_code = "{}{}{}".format(init_chassis_code, looking_for_thermal_code.format(name, name), + get_high_crit_threshold_code) + + status, output = getstatusoutput_noshell(["docker", "exec", "pmon", "python3", "-c", all_code]) + if status == 1: + return None + + return float(output) + +def do_threshold(): + global args, init_chassis_code, looking_for_thermal_code + + if args.list: + print("Thermals: " + avaliable_thermals()) + return + + if args.thermal is None: + print("The following arguments are required: -t") + return + + set_threshold_code = "" + if args.high_threshold is not None: + if args.high_crit_threshold is not None and \ + args.high_threshold >= args.high_crit_threshold: + print("Invalid Threshold!(High threshold can not be more than " \ + "or equal to high critical threshold.)") + exit(1) + + high_crit = get_high_crit_threshold(args.thermal) + if high_crit is not None and \ + args.high_threshold >= high_crit: + print("Invalid Threshold!(High threshold can not be more than " \ + "or equal to high critical threshold.)") + exit(1) + + set_threshold_code += \ + "try:\n"\ + " if thermal.set_high_threshold({}) is False:\n"\ + " print('{}: set_high_threshold failure!')\n"\ + " exit(1)\n"\ + "except NotImplementedError:\n"\ + " print('Not implement the set_high_threshold method!')\n"\ + "print('Apply the new high threshold successfully.')\n"\ + "\n".format(args.high_threshold, args.thermal) + + if args.high_crit_threshold is not None: + high = get_high_threshold(args.thermal) + if high is not None and \ + args.high_crit_threshold <= high: + print("Invalid Threshold!(High critical threshold can not " \ + "be less than or equal to high threshold.)") + exit(1) + + set_threshold_code += \ + "try:\n"\ + " if thermal.set_high_critical_threshold({}) is False:\n"\ + " print('{}: set_high_critical_threshold failure!')\n"\ + " exit(1)\n"\ + "except NotImplementedError:\n"\ + " print('Not implement the set_high_critical_threshold method!')\n"\ + "print('Apply the new high critical threshold successfully.')\n"\ + "\n".format(args.high_crit_threshold, args.thermal) + + if set_threshold_code == "": + return + + all_code = "{}{}{}".format(init_chassis_code, looking_for_thermal_code.format(args.thermal, args.thermal), set_threshold_code) + + status, output = getstatusoutput_noshell(["docker", "exec", "pmon", "python3", "-c", all_code]) + print(output) + if __name__ == "__main__": main() From c64e3841a4e30e241adf7221a627e9329c24a28d Mon Sep 17 00:00:00 2001 From: roger530-ho Date: Thu, 13 Apr 2023 10:18:26 +0000 Subject: [PATCH 16/21] Fix incorrect variable --- .../as7726-32x/sonic_platform/thermal.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/platform/broadcom/sonic-platform-modules-accton/as7726-32x/sonic_platform/thermal.py b/platform/broadcom/sonic-platform-modules-accton/as7726-32x/sonic_platform/thermal.py index 1fbe0ae921ee..b5c0644a705c 100644 --- a/platform/broadcom/sonic-platform-modules-accton/as7726-32x/sonic_platform/thermal.py +++ b/platform/broadcom/sonic-platform-modules-accton/as7726-32x/sonic_platform/thermal.py @@ -266,7 +266,7 @@ def get_maximum_recorded(self): A float number, the maximum recorded temperature of thermal in Celsius up to nearest thousandth of one degree Celsius, e.g. 30.125 """ - if self.min_temperature is None: + if self.max_temperature is None: self.get_temperature() return self.max_temperature From 459bf031778778a39cca337cb846b1b4d2b78b38 Mon Sep 17 00:00:00 2001 From: jostar-yang Date: Tue, 2 May 2023 16:11:12 +0800 Subject: [PATCH 17/21] Support to show CPU all core temp --- .../pddf/pddf-device.json | 65 ++++++++++++++++++- 1 file changed, 63 insertions(+), 2 deletions(-) diff --git a/device/accton/x86_64-accton_as7726_32x-r0/pddf/pddf-device.json b/device/accton/x86_64-accton_as7726_32x-r0/pddf/pddf-device.json index 5b2cabb749b9..54c372df1976 100644 --- a/device/accton/x86_64-accton_as7726_32x-r0/pddf/pddf-device.json +++ b/device/accton/x86_64-accton_as7726_32x-r0/pddf/pddf-device.json @@ -5,7 +5,7 @@ "num_fantrays":6, "num_fans_pertray":2, "num_ports":32, - "num_temps":6, + "num_temps":10, "pddf_dev_types": { "description":"AS7726 - Below is the list of supported PDDF device types (chip names) for various components. If any component uses some other driver, we will create the client using 'echo > /new_device' method", @@ -1876,7 +1876,7 @@ "TEMP6" : { "dev_info": { "device_type":"TEMP_SENSOR", "device_name":"TEMP6"}, - "dev_attr": { "display_name":"coretemp-isa-0000"}, + "dev_attr": { "display_name":"CPU_Package_temp"}, "i2c": { "path_info": {"sysfs_base_path": "/sys/class/hwmon/hwmon0"}, @@ -1888,6 +1888,67 @@ ] } }, + + "TEMP7" : + { + "dev_info": { "device_type":"TEMP_SENSOR", "device_name":"TEMP7"}, + "dev_attr": { "display_name":"CPU_Core_0_temp"}, + "i2c": + { + "path_info": {"sysfs_base_path": "/sys/class/hwmon/hwmon0"}, + "attr_list": + [ + { "attr_name": "temp1_high_crit_threshold", "drv_attr_name":"temp2_crit"}, + { "attr_name": "temp1_high_threshold", "drv_attr_name":"temp2_max"}, + { "attr_name": "temp1_input", "drv_attr_name":"temp2_input"} + ] + } + }, + "TEMP8" : + { + "dev_info": { "device_type":"TEMP_SENSOR", "device_name":"TEMP8"}, + "dev_attr": { "display_name":"CPU_Core_1_temp"}, + "i2c": + { + "path_info": {"sysfs_base_path": "/sys/class/hwmon/hwmon0"}, + "attr_list": + [ + { "attr_name": "temp1_high_crit_threshold", "drv_attr_name":"temp3_crit"}, + { "attr_name": "temp1_high_threshold", "drv_attr_name":"temp3_max"}, + { "attr_name": "temp1_input", "drv_attr_name":"temp3_input"} + ] + } + }, + "TEMP9" : + { + "dev_info": { "device_type":"TEMP_SENSOR", "device_name":"TEMP9"}, + "dev_attr": { "display_name":"CPU_Core_2_temp"}, + "i2c": + { + "path_info": {"sysfs_base_path": "/sys/class/hwmon/hwmon0"}, + "attr_list": + [ + { "attr_name": "temp1_high_crit_threshold", "drv_attr_name":"temp4_crit"}, + { "attr_name": "temp1_high_threshold", "drv_attr_name":"temp4_max"}, + { "attr_name": "temp1_input", "drv_attr_name":"temp4_input"} + ] + } + }, + "TEMP10" : + { + "dev_info": { "device_type":"TEMP_SENSOR", "device_name":"TEMP10"}, + "dev_attr": { "display_name":"CPU_Core_3_temp"}, + "i2c": + { + "path_info": {"sysfs_base_path": "/sys/class/hwmon/hwmon0"}, + "attr_list": + [ + { "attr_name": "temp1_high_crit_threshold", "drv_attr_name":"temp5_crit"}, + { "attr_name": "temp1_high_threshold", "drv_attr_name":"temp5_max"}, + { "attr_name": "temp1_input", "drv_attr_name":"temp5_input"} + ] + } + }, "SYSSTATUS": { "dev_info":{ "device_type":"SYSSTAT", "device_name":"SYSSTATUS"}, From 4f1c650a6764bf52c085e67217fed90e61dd1d05 Mon Sep 17 00:00:00 2001 From: roger530-ho Date: Tue, 20 Jun 2023 01:13:33 +0000 Subject: [PATCH 18/21] Add CPU all core temp --- .../x86_64-accton_as7726_32x-r0/platform.json | 34 ++++++++++++++++++- .../as7726-32x/sonic_platform/thermal.py | 26 +++++++++++++- 2 files changed, 58 insertions(+), 2 deletions(-) diff --git a/device/accton/x86_64-accton_as7726_32x-r0/platform.json b/device/accton/x86_64-accton_as7726_32x-r0/platform.json index 3ca60cf1c291..a0e25f83a8a4 100644 --- a/device/accton/x86_64-accton_as7726_32x-r0/platform.json +++ b/device/accton/x86_64-accton_as7726_32x-r0/platform.json @@ -406,7 +406,39 @@ "high-crit-threshold": false }, { - "name": "coretemp-isa-0000", + "name": "CPU_Package_temp", + "controllable": false, + "low-threshold": false, + "high-threshold": true, + "low-crit-threshold": false, + "high-crit-threshold": true + }, + { + "name": "CPU_Core_0_temp", + "controllable": false, + "low-threshold": false, + "high-threshold": true, + "low-crit-threshold": false, + "high-crit-threshold": true + }, + { + "name": "CPU_Core_1_temp", + "controllable": false, + "low-threshold": false, + "high-threshold": true, + "low-crit-threshold": false, + "high-crit-threshold": true + }, + { + "name": "CPU_Core_2_temp", + "controllable": false, + "low-threshold": false, + "high-threshold": true, + "low-crit-threshold": false, + "high-crit-threshold": true + }, + { + "name": "CPU_Core_3_temp", "controllable": false, "low-threshold": false, "high-threshold": true, diff --git a/platform/broadcom/sonic-platform-modules-accton/as7726-32x/sonic_platform/thermal.py b/platform/broadcom/sonic-platform-modules-accton/as7726-32x/sonic_platform/thermal.py index b5c0644a705c..6bf478bbda50 100644 --- a/platform/broadcom/sonic-platform-modules-accton/as7726-32x/sonic_platform/thermal.py +++ b/platform/broadcom/sonic-platform-modules-accton/as7726-32x/sonic_platform/thermal.py @@ -44,7 +44,31 @@ HIGH_CRIT_THRESHOLD : NOT_AVAILABLE, LOW_CRIT_THRESHOLD : NOT_AVAILABLE }, - 'coretemp-isa-0000' : { + 'CPU_Package_temp' : { + HIGH_THRESHOLD : '82.0', + LOW_THRESHOLD : NOT_AVAILABLE, + HIGH_CRIT_THRESHOLD : '104.0', + LOW_CRIT_THRESHOLD : NOT_AVAILABLE + }, + 'CPU_Core_0_temp' : { + HIGH_THRESHOLD : '82.0', + LOW_THRESHOLD : NOT_AVAILABLE, + HIGH_CRIT_THRESHOLD : '104.0', + LOW_CRIT_THRESHOLD : NOT_AVAILABLE + }, + 'CPU_Core_1_temp' : { + HIGH_THRESHOLD : '82.0', + LOW_THRESHOLD : NOT_AVAILABLE, + HIGH_CRIT_THRESHOLD : '104.0', + LOW_CRIT_THRESHOLD : NOT_AVAILABLE + }, + 'CPU_Core_2_temp' : { + HIGH_THRESHOLD : '82.0', + LOW_THRESHOLD : NOT_AVAILABLE, + HIGH_CRIT_THRESHOLD : '104.0', + LOW_CRIT_THRESHOLD : NOT_AVAILABLE + }, + 'CPU_Core_3_temp' : { HIGH_THRESHOLD : '82.0', LOW_THRESHOLD : NOT_AVAILABLE, HIGH_CRIT_THRESHOLD : '104.0', From 66fa15a654de4922d619a8eeaeb5598628e21f42 Mon Sep 17 00:00:00 2001 From: roger530-ho Date: Tue, 15 Aug 2023 02:05:02 +0000 Subject: [PATCH 19/21] [Edgecore][AS7726-32X] Read the data when the PSU is in the power-good state. --- .../as7726-32x/sonic_platform/psu.py | 65 +++++++++++++++++++ 1 file changed, 65 insertions(+) diff --git a/platform/broadcom/sonic-platform-modules-accton/as7726-32x/sonic_platform/psu.py b/platform/broadcom/sonic-platform-modules-accton/as7726-32x/sonic_platform/psu.py index 18b3ab0d848d..a349319d4af2 100644 --- a/platform/broadcom/sonic-platform-modules-accton/as7726-32x/sonic_platform/psu.py +++ b/platform/broadcom/sonic-platform-modules-accton/as7726-32x/sonic_platform/psu.py @@ -63,3 +63,68 @@ def get_revision(self): string: Revision value of device """ return 'N/A' + + def get_model(self): + """ + Retrieves the model number (or part number) of the device + + Returns: + string: Model/part number of device + """ + model = super().get_model() + if model and model.strip() == "": + return None + + return model + + def get_serial(self): + """ + Retrieves the serial number of the device + + Returns: + string: Serial number of device + """ + serial = super().get_serial() + if serial and serial.strip() == "": + return None + + return serial + + def get_voltage(self): + """ + Retrieves current PSU voltage output + + Returns: + A float number, the output voltage in volts, + e.g. 12.1 + """ + if self.get_status() is not True: + return 0.0 + + return super().get_voltage() + + def get_current(self): + """ + Retrieves present electric current supplied by PSU + + Returns: + A float number, electric current in amperes, + e.g. 15.4 + """ + if self.get_status() is not True: + return 0.0 + + return super().get_current() + + def get_power(self): + """ + Retrieves current energy supplied by PSU + + Returns: + A float number, the power in watts, + e.g. 302.6 + """ + if self.get_status() is not True: + return 0.0 + + return super().get_power() From c352370fffdd69256b883bee03c788dacb67231c Mon Sep 17 00:00:00 2001 From: jostar-yang Date: Thu, 28 Sep 2023 15:00:59 +0800 Subject: [PATCH 20/21] Fix port33,34 to use optoe2 for sfp --- .../x86_64-accton_as7726_32x-r0/pddf/pddf-device.json | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/device/accton/x86_64-accton_as7726_32x-r0/pddf/pddf-device.json b/device/accton/x86_64-accton_as7726_32x-r0/pddf/pddf-device.json index 54c372df1976..5d395d6388aa 100644 --- a/device/accton/x86_64-accton_as7726_32x-r0/pddf/pddf-device.json +++ b/device/accton/x86_64-accton_as7726_32x-r0/pddf/pddf-device.json @@ -4,7 +4,7 @@ "num_psus":2, "num_fantrays":6, "num_fans_pertray":2, - "num_ports":32, + "num_ports":34, "num_temps":10, "pddf_dev_types": { @@ -1545,7 +1545,7 @@ "dev_info": { "device_type":"", "device_name":"PORT33-EEPROM", "device_parent":"MUX2", "virt_parent":"PORT33"}, "i2c": { - "topo_info": { "parent_bus":"0xf", "dev_addr":"0x50", "dev_type":"optoe1"}, + "topo_info": { "parent_bus":"0xf", "dev_addr":"0x50", "dev_type":"optoe2"}, "attr_list": [ { "attr_name":"eeprom"} @@ -1584,7 +1584,7 @@ "dev_info": { "device_type":"", "device_name":"PORT34-EEPROM", "device_parent":"MUX2", "virt_parent":"PORT34"}, "i2c": { - "topo_info": { "parent_bus":"0x10", "dev_addr":"0x50", "dev_type":"optoe1"}, + "topo_info": { "parent_bus":"0x10", "dev_addr":"0x50", "dev_type":"optoe2"}, "attr_list": [ { "attr_name":"eeprom"} From 6c8cab5467f3cc9b6a0a43deba647098655660d9 Mon Sep 17 00:00:00 2001 From: jostar-yang Date: Wed, 4 Sep 2024 11:13:44 +0800 Subject: [PATCH 21/21] Add reset() in sfp.py for check sfp_port to avoid fail --- .../as7726-32x/sonic_platform/sfp.py | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/platform/broadcom/sonic-platform-modules-accton/as7726-32x/sonic_platform/sfp.py b/platform/broadcom/sonic-platform-modules-accton/as7726-32x/sonic_platform/sfp.py index a0189bfcbc7c..eb12ed5ef71b 100644 --- a/platform/broadcom/sonic-platform-modules-accton/as7726-32x/sonic_platform/sfp.py +++ b/platform/broadcom/sonic-platform-modules-accton/as7726-32x/sonic_platform/sfp.py @@ -51,6 +51,17 @@ def get_name(self): return name + def get_reset_status(self): + if self.sfp_type == "QSFP28": + return super().get_reset_status() + return False + + + def reset(self): + if self.sfp_type == "QSFP28": + return super().reset() + else: + return False def __validate_eeprom_sfp(self): checksum_test = 0 eeprom_raw = self.read_eeprom(0, 96)