diff --git a/device/accton/x86_64-accton_as7816_64x-r0/pcie.yaml b/device/accton/x86_64-accton_as7816_64x-r0/pcie.yaml new file mode 100644 index 00000000000..a021e60ab8f --- /dev/null +++ b/device/accton/x86_64-accton_as7816_64x-r0/pcie.yaml @@ -0,0 +1,465 @@ +- 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: 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: b970 + name: 'Ethernet controller: Broadcom Inc. and subsidiaries Device b970 (rev 11)' +- 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_as7816_64x-r0/pddf/pd-plugin.json b/device/accton/x86_64-accton_as7816_64x-r0/pddf/pd-plugin.json index eae22f99e39..edb5a5ad9a3 100644 --- a/device/accton/x86_64-accton_as7816_64x-r0/pddf/pd-plugin.json +++ b/device/accton/x86_64-accton_as7816_64x-r0/pddf/pd-plugin.json @@ -32,11 +32,11 @@ { "i2c": { - "valmap": { "F2B":"EXHAUST", "B2F":"INTAKE" } + "valmap": { "F2B":"exhaust", "B2F":"intake" } } }, - "PSU_FAN_MAX_SPEED":"18000" + "PSU_FAN_MAX_SPEED":"26688" }, "FAN": @@ -45,7 +45,7 @@ { "i2c": { - "valmap": {"1":"INTAKE", "0":"EXHAUST"} + "valmap": {"1":"intake", "0":"exhaust"} } }, diff --git a/device/accton/x86_64-accton_as7816_64x-r0/pddf/pddf-device.json b/device/accton/x86_64-accton_as7816_64x-r0/pddf/pddf-device.json index f373f39601e..f1671ade3f4 100644 --- a/device/accton/x86_64-accton_as7816_64x-r0/pddf/pddf-device.json +++ b/device/accton/x86_64-accton_as7816_64x-r0/pddf/pddf-device.json @@ -5,7 +5,7 @@ "num_fantrays":4, "num_fans_pertray":2, "num_ports":64, - "num_temps": 6, + "num_temps": 11, "pddf_dev_types": { "description":"AS7816-64X - 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", @@ -177,7 +177,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"} ] } }, @@ -226,7 +230,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"} ] } }, @@ -406,6 +414,81 @@ ] } }, + "TEMP7" : + { + "dev_info": { "device_type":"TEMP_SENSOR", "device_name":"TEMP7"}, + "dev_attr": { "display_name":"CPU_Package_temp"}, + "i2c": + { + "path_info": {"sysfs_base_path": "/sys/class/hwmon/hwmon0"}, + "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"} + ] + } + }, + "TEMP8" : + { + "dev_info": { "device_type":"TEMP_SENSOR", "device_name":"TEMP8"}, + "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"} + ] + } + }, + "TEMP9" : + { + "dev_info": { "device_type":"TEMP_SENSOR", "device_name":"TEMP9"}, + "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"} + ] + } + }, + "TEMP10" : + { + "dev_info": { "device_type":"TEMP_SENSOR", "device_name":"TEMP10"}, + "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"} + ] + } + }, + "TEMP11" : + { + "dev_info": { "device_type":"TEMP_SENSOR", "device_name":"TEMP11"}, + "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"} + ] + } + }, "CPLD1": { "dev_info": { "device_type":"CPLD", "device_name":"CPLD1", "device_parent":"MUX3"}, @@ -3182,8 +3265,8 @@ "i2c" : { "attr_list": [ - {"attr_name":"STATUS_LED_COLOR_AMBER", "descr" : "Amber", "bits" : "4", "value" : "0x0", "swpld_addr" : "0x60", "swpld_addr_offset" : "0x30"}, - {"attr_name":"STATUS_LED_COLOR_OFF", "descr" : "Off", "bits" : "4", "value" : "0x1", "swpld_addr" : "0x60", "swpld_addr_offset" : "0x30"} + {"attr_name":"amber", "descr" : "Amber", "bits" : "4", "value" : "0x0", "swpld_addr" : "0x60", "swpld_addr_offset" : "0x30"}, + {"attr_name":"off", "descr" : "Off", "bits" : "4", "value" : "0x1", "swpld_addr" : "0x60", "swpld_addr_offset" : "0x30"} ] } }, @@ -3195,11 +3278,53 @@ "i2c" : { "attr_list": [ - {"attr_name":"STATUS_LED_COLOR_GREEN", "descr" : "Green", "bits" : "1:0", "value" : "0x2", "swpld_addr" : "0x60", "swpld_addr_offset" : "0x30"}, - {"attr_name":"STATUS_LED_COLOR_RED", "descr" : "Red" ,"bits" : "1:0", "value" : "0x1", "swpld_addr" : "0x60", "swpld_addr_offset" : "0x30"}, - {"attr_name":"STATUS_LED_COLOR_OFF", "descr" : "Off" ,"bits" : "1:0", "value" : "0x3", "swpld_addr" : "0x60", "swpld_addr_offset" : "0x30"} + {"attr_name":"green", "descr" : "Green", "bits" : "1:0", "value" : "0x2", "swpld_addr" : "0x60", "swpld_addr_offset" : "0x30"}, + {"attr_name":"red", "descr" : "Red" ,"bits" : "1:0", "value" : "0x1", "swpld_addr" : "0x60", "swpld_addr_offset" : "0x30"}, + {"attr_name":"off", "descr" : "Off" ,"bits" : "1:0", "value" : "0x3", "swpld_addr" : "0x60", "swpld_addr_offset" : "0x30"} + ] + } + + }, + + "PSU1_LED": + { + "dev_info": { "device_type":"LED", "device_name":"PSU_LED"}, + "dev_attr": { "index":"0"}, + "i2c" : { + "attr_list": + [ + {"attr_name":"green", "descr": "Green", "bits" : "1:0", "value" : "0x2", "swpld_addr" : "0x60", "swpld_addr_offset" : "0x31"}, + {"attr_name":"amber", "descr": "Amber", "bits" : "1:0", "value" : "0x1", "swpld_addr" : "0x60", "swpld_addr_offset" : "0x31"}, + {"attr_name":"off", "descr": "Off", "bits" : "1:0", "value" : "0x3", "swpld_addr" : "0x60", "swpld_addr_offset" : "0x31"} ] } + }, + + "PSU2_LED": + { + "dev_info": { "device_type":"LED", "device_name":"PSU_LED"}, + "dev_attr": { "index":"1"}, + "i2c" : { + "attr_list": + [ + {"attr_name":"green", "descr": "Green", "bits" : "3:2", "value" : "0x2", "swpld_addr" : "0x60", "swpld_addr_offset" : "0x31"}, + {"attr_name":"amber", "descr": "Amber", "bits" : "3:2", "value" : "0x1", "swpld_addr" : "0x60", "swpld_addr_offset" : "0x31"}, + {"attr_name":"off", "descr": "Off", "bits" : "3:2", "value" : "0x3", "swpld_addr" : "0x60", "swpld_addr_offset" : "0x31"} + ] + } + }, - } + "FAN_LED": + { + "dev_info": { "device_type":"LED", "device_name":"FAN_LED"}, + "dev_attr": { "index":"0"}, + "i2c" : { + "attr_list": + [ + {"attr_name":"green", "descr": "Green", "bits" : "3:2", "value" : "0x2", "swpld_addr" : "0x60", "swpld_addr_offset" : "0x30"}, + {"attr_name":"amber", "descr": "Amber", "bits" : "3:2", "value" : "0x1", "swpld_addr" : "0x60", "swpld_addr_offset" : "0x30"}, + {"attr_name":"off", "descr": "Off", "bits" : "3:2", "value" : "0x3", "swpld_addr" : "0x60", "swpld_addr_offset" : "0x30"} + ] + } + } } diff --git a/device/accton/x86_64-accton_as7816_64x-r0/platform.json b/device/accton/x86_64-accton_as7816_64x-r0/platform.json index aa0f78a032a..04c53c896b2 100755 --- a/device/accton/x86_64-accton_as7816_64x-r0/platform.json +++ b/device/accton/x86_64-accton_as7816_64x-r0/platform.json @@ -1,6 +1,11 @@ { "chassis": { "name": "7816-64X", + "thermal_manager":false, + "status_led": { + "controllable": true, + "colors": ["green", "red", "off"] + }, "components": [ { "name": "CPLD1" @@ -15,88 +20,222 @@ "name": "CPLD4" }, { - "name": "BIOS" - } - ], - "fans": [ - { - "name": "FAN-1F" - }, - { - "name": "FAN-1R" + "name": "CPLD5" }, { - "name": "FAN-2F" + "name": "CPLD6" }, { - "name": "FAN-2R" - }, - { - "name": "FAN-3F" - }, - { - "name": "FAN-3R" - }, - { - "name": "FAN-4F" - }, + "name": "BIOS" + } + ], + "fans": [ { - "name": "FAN-4R" + "name": "FAN-1F", + "speed": { + "controllable": true, + "minimum": 18 + }, + "status_led": { + "controllable": false + } + }, + { + "name": "FAN-1R", + "speed": { + "controllable": true, + "minimum": 18 + }, + "status_led": { + "controllable": false + } + }, + { + "name": "FAN-2F", + "speed": { + "controllable": true, + "minimum": 18 + }, + "status_led": { + "controllable": false + } + }, + { + "name": "FAN-2R", + "speed": { + "controllable": true, + "minimum": 18 + }, + "status_led": { + "controllable": false + } + }, + { + "name": "FAN-3F", + "speed": { + "controllable": true, + "minimum": 18 + }, + "status_led": { + "controllable": false + } + }, + { + "name": "FAN-3R", + "speed": { + "controllable": true, + "minimum": 18 + }, + "status_led": { + "controllable": false + } + }, + { + "name": "FAN-4F", + "speed": { + "controllable": true, + "minimum": 18 + }, + "status_led": { + "controllable": false + } + }, + { + "name": "FAN-4R", + "speed": { + "controllable": true, + "minimum": 18 + }, + "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": 18 + }, + "status_led": { + "controllable": false + } }, { - "name": "FAN-1R" + "name": "FAN-1R", + "speed": { + "controllable": true, + "minimum": 18 + }, + "status_led": { + "controllable": false + } } ] }, { "name": "FanTray2", + "status_led": { + "controllable": false + }, "num_fans" : 2, "fans": [ { - "name": "FAN-2F" + "name": "FAN-2F", + "speed": { + "controllable": true, + "minimum": 18 + }, + "status_led": { + "controllable": false + } }, { - "name": "FAN-2R" + "name": "FAN-2R", + "speed": { + "controllable": true, + "minimum": 18 + }, + "status_led": { + "controllable": false + } } ] }, { "name": "FanTray3", + "status_led": { + "controllable": false + }, "num_fans" : 2, "fans": [ { - "name": "FAN-3F" + "name": "FAN-3F", + "speed": { + "controllable": true, + "minimum": 18 + }, + "status_led": { + "controllable": false + } }, { - "name": "FAN-3R" + "name": "FAN-3R", + "speed": { + "controllable": true, + "minimum": 18 + }, + "status_led": { + "controllable": false + } } ] }, { "name": "FanTray4", + "status_led": { + "controllable": false + }, "num_fans" : 2, "fans": [ { - "name": "FAN-4F" + "name": "FAN-4F", + "speed": { + "controllable": true, + "minimum": 18 + }, + "status_led": { + "controllable": false + } }, { - "name": "FAN-4R" + "name": "FAN-4R", + "speed": { + "controllable": true, + "minimum": 18 + }, + "status_led": { + "controllable": false + } } ] } - ], + ], "psus": [ { "name": "PSU-1", + "status_led": { + "controllable": true, + "colors": ["green", "amber", "off"] + }, "fans": [ { "name": "PSU-1 FAN-1" @@ -104,12 +243,19 @@ ], "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": true, + "colors": ["green", "amber", "off"] + }, "fans": [ { "name": "PSU-2 FAN-1" @@ -117,29 +263,106 @@ ], "thermals": [ { - "name": "PSU-2 temp sensor 2" + "name": "PSU-2 temp sensor 2", + "controllable": false, + "low-crit-threshold": false, + "high-crit-threshold": false } ] } ], "thermals": [ { - "name": "Temp sensor 1" - }, - { - "name": "Temp sensor 2" - }, - { - "name": "Temp sensor 3" - }, - { - "name": "Temp sensor 4" - }, - { - "name": "Temp sensor 5" - }, - { - "name": "Temp sensor 6" + "name": "FB_1_temp(0x4D)", + "controllable": true, + "low-threshold": false, + "high-threshold": true, + "low-crit-threshold": false, + "high-crit-threshold": false, + "minimum-recorded": false, + "maximum-recorded": false + }, + { + "name": "FB_2_temp(0x4E)", + "controllable": true, + "low-threshold": false, + "high-threshold": true, + "low-crit-threshold": false, + "high-crit-threshold": false, + "minimum-recorded": false, + "maximum-recorded": false + }, + { + "name": "MB_MAC_temp(0x48)", + "controllable": true, + "low-threshold": false, + "high-threshold": true, + "low-crit-threshold": false, + "high-crit-threshold": false + }, + { + "name": "MB_RearCenter_temp(0x49)", + "controllable": true, + "low-threshold": false, + "high-threshold": true, + "low-crit-threshold": false, + "high-crit-threshold": false + }, + { + "name": "MB_RightCenter_temp(0x4A)", + "controllable": true, + "low-threshold": false, + "high-threshold": true, + "low-crit-threshold": false, + "high-crit-threshold": false + }, + { + "name": "CpuBoard_temp(0x4B)", + "controllable": true, + "low-threshold": false, + "high-threshold": true, + "low-crit-threshold": false, + "high-crit-threshold": false + }, + { + "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, + "low-crit-threshold": false, + "high-crit-threshold": true } ], "sfps": [ diff --git a/device/accton/x86_64-accton_as7816_64x-r0/platform_components.json b/device/accton/x86_64-accton_as7816_64x-r0/platform_components.json new file mode 100644 index 00000000000..17bdcb08515 --- /dev/null +++ b/device/accton/x86_64-accton_as7816_64x-r0/platform_components.json @@ -0,0 +1,15 @@ +{ + "chassis": { + "7816-64X-O-AC-F-R": { + "component": { + "CPLD1": { }, + "CPLD2": { }, + "CPLD3": { }, + "CPLD4": { }, + "CPLD5": { }, + "CPLD6": { }, + "BIOS": { } + } + } + } +} diff --git a/device/accton/x86_64-accton_as7816_64x-r0/pmon_daemon_control.json b/device/accton/x86_64-accton_as7816_64x-r0/pmon_daemon_control.json index a3b204e20d8..44bad649422 100644 --- a/device/accton/x86_64-accton_as7816_64x-r0/pmon_daemon_control.json +++ b/device/accton/x86_64-accton_as7816_64x-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_as7816_64x-r0/system_health_monitoring_config.json b/device/accton/x86_64-accton_as7816_64x-r0/system_health_monitoring_config.json index 92be29dfdea..7e3fdbf9537 100644 --- a/device/accton/x86_64-accton_as7816_64x-r0/system_health_monitoring_config.json +++ b/device/accton/x86_64-accton_as7816_64x-r0/system_health_monitoring_config.json @@ -1,15 +1,13 @@ { "services_to_ignore": [], "devices_to_ignore": [ - "asic", - "psu.temperature" - + "asic" ], "user_defined_checkers": [], "polling_interval": 60, "led_color": { - "fault": "STATUS_LED_COLOR_RED", - "normal": "STATUS_LED_COLOR_GREEN", - "booting": "STATUS_LED_COLOR_GREEN" + "fault": "red", + "normal": "green", + "booting": "green" } } diff --git a/platform/broadcom/sonic-platform-modules-accton/as7816-64x/modules/accton_psu_api.h b/platform/broadcom/sonic-platform-modules-accton/as7816-64x/modules/accton_psu_api.h new file mode 120000 index 00000000000..a6b156930a8 --- /dev/null +++ b/platform/broadcom/sonic-platform-modules-accton/as7816-64x/modules/accton_psu_api.h @@ -0,0 +1 @@ +../../common/modules/accton_psu_api.h \ No newline at end of file diff --git a/platform/broadcom/sonic-platform-modules-accton/as7816-64x/modules/accton_psu_defs.h b/platform/broadcom/sonic-platform-modules-accton/as7816-64x/modules/accton_psu_defs.h new file mode 120000 index 00000000000..96202b3ead2 --- /dev/null +++ b/platform/broadcom/sonic-platform-modules-accton/as7816-64x/modules/accton_psu_defs.h @@ -0,0 +1 @@ +../../common/modules/accton_psu_defs.h \ No newline at end of file diff --git a/platform/broadcom/sonic-platform-modules-accton/as7816-64x/sonic_platform/chassis.py b/platform/broadcom/sonic-platform-modules-accton/as7816-64x/sonic_platform/chassis.py index c597c0d8bb1..4b79ff1c747 100644 --- a/platform/broadcom/sonic-platform-modules-accton/as7816-64x/sonic_platform/chassis.py +++ b/platform/broadcom/sonic-platform-modules-accton/as7816-64x/sonic_platform/chassis.py @@ -8,59 +8,39 @@ 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 = 7 +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._sfpevent = SfpEvent(self.get_all_sfps()) + self._api_helper = APIHelper() - # 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(64): - 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(64): - 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 __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 + def get_change_event(self, timeout=0): + return self._sfpevent.get_sfp_event(timeout) def get_sfp(self, index): """ @@ -84,3 +64,63 @@ 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 + return SfpBase.SFP_PORT_TYPE_BIT_QSFP28 + + 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_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_revision(self): + """ + Retrieves the hardware revision of the device + + Returns: + string: Revision value of device + """ + return self._eeprom.revision_str() diff --git a/platform/broadcom/sonic-platform-modules-accton/as7816-64x/sonic_platform/component.py b/platform/broadcom/sonic-platform-modules-accton/as7816-64x/sonic_platform/component.py new file mode 100644 index 00000000000..24f34a6d127 --- /dev/null +++ b/platform/broadcom/sonic-platform-modules-accton/as7816-64x/sonic_platform/component.py @@ -0,0 +1,207 @@ +############################################################################# +# +# Component contains an implementation of SONiC Platform Base API and +# provides the components firmware management function +# +############################################################################# + +try: + 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") + +CPLD_ADDR_MAPPING = { + "CPLD1": ['19', '0x60'], + "CPLD2": ['20', '0x62'], + "CPLD3": ['21', '0x64'], + "CPLD4": ['22', '0x66'], + "CPLD5": ['17', '0x68'] +} +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 FAN"), + ("CPLD6", "CPLD CPU"), + ("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 __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", 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)) + + return cpld_version + + def __get_cpld_cpu_version(self): + try: + cpu_version = dict() + cmd = ["i2cget", "-f", "-y", "0", "0x65", "0x01"] + status, output1 = getstatusoutput_noshell(cmd) + if status == 0 : + cmd = ["i2cget", "-f", "-y", "0", "0x65", "0xff"] + status, output2 = getstatusoutput_noshell(cmd) + if status == 0 : + cpu_version = "{}{}{}".format(output1[2:],".",output2[2:]) + else : + cpu_version = 'None' + 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 "CPLD6" 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 + """ + 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): + """ + 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 diff --git a/platform/broadcom/sonic-platform-modules-accton/as7816-64x/sonic_platform/event.py b/platform/broadcom/sonic-platform-modules-accton/as7816-64x/sonic_platform/event.py new file mode 100644 index 00000000000..1a2f60dbb67 --- /dev/null +++ b/platform/broadcom/sonic-platform-modules-accton/as7816-64x/sonic_platform/event.py @@ -0,0 +1,109 @@ +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 ''' + + 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)) == 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/as7816-64x/sonic_platform/fan.py b/platform/broadcom/sonic-platform-modules-accton/as7816-64x/sonic_platform/fan.py index 2db163c7d28..c7d5c86dc8c 100644 --- a/platform/broadcom/sonic-platform-modules-accton/as7816-64x/sonic_platform/fan.py +++ b/platform/broadcom/sonic-platform-modules-accton/as7816-64x/sonic_platform/fan.py @@ -6,6 +6,8 @@ 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"] class Fan(PddfFan): """PDDF Platform-Specific Fan class""" @@ -30,21 +32,49 @@ def get_direction(self): direction = self.FAN_DIRECTION_EXHAUST else: - idx = (self.fantray_index-1)*self.platform['num_fans_pertray'] + self.fan_index - attr = "fan" + str(idx) + "_direction" - output = self.pddf_obj.get_attr_name_output("FAN-CTRL", attr) - if not output: - return False - - mode = output['mode'] - val = output['status'] - - val = val.rstrip() - vmap = self.plugin_data['FAN']['direction'][mode]['valmap'] - if val in vmap: - direction = vmap[val] - else: - direction = val + direction = super().get_direction() + if direction is not None and len(direction) > 0: + direction = 'N/A' return direction + 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 + + 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_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() diff --git a/platform/broadcom/sonic-platform-modules-accton/as7816-64x/sonic_platform/fan_drawer.py b/platform/broadcom/sonic-platform-modules-accton/as7816-64x/sonic_platform/fan_drawer.py index 3b9bb607f63..09c1048b512 100644 --- a/platform/broadcom/sonic-platform-modules-accton/as7816-64x/sonic_platform/fan_drawer.py +++ b/platform/broadcom/sonic-platform-modules-accton/as7816-64x/sonic_platform/fan_drawer.py @@ -15,3 +15,27 @@ 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) + + 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/as7816-64x/sonic_platform/helper.py b/platform/broadcom/sonic-platform-modules-accton/as7816-64x/sonic_platform/helper.py new file mode 100644 index 00000000000..400c3e8c3c3 --- /dev/null +++ b/platform/broadcom/sonic-platform-modules-accton/as7816-64x/sonic_platform/helper.py @@ -0,0 +1,366 @@ +import os +import struct +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 = "" + + +class APIHelper(): + + def __init__(self): + (self.platform, self.hwsku) = device_info.get_platform_and_hwsku() + + def is_host(self): + try: + status, output = getstatusoutput_noshell(HOST_CHK_CMD) + return status == 0 + except Exception: + return False + + 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_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: + 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/as7816-64x/sonic_platform/pcie.py b/platform/broadcom/sonic-platform-modules-accton/as7816-64x/sonic_platform/pcie.py new file mode 100644 index 00000000000..73d3627dbf7 --- /dev/null +++ b/platform/broadcom/sonic-platform-modules-accton/as7816-64x/sonic_platform/pcie.py @@ -0,0 +1,19 @@ +############################################################################# +# Edgecore +# +# Module contains an implementation of SONiC Platform Base API and +# provides the fan status which are available in the platform +# Base PCIe class +############################################################################# + +try: + 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) \ No newline at end of file diff --git a/platform/broadcom/sonic-platform-modules-accton/as7816-64x/sonic_platform/psu.py b/platform/broadcom/sonic-platform-modules-accton/as7816-64x/sonic_platform/psu.py index 46a1396597a..0e9490f1d9b 100644 --- a/platform/broadcom/sonic-platform-modules-accton/as7816-64x/sonic_platform/psu.py +++ b/platform/broadcom/sonic-platform-modules-accton/as7816-64x/sonic_platform/psu.py @@ -11,25 +11,102 @@ 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) # Provide the functions/variables below for which implementation is to be overwritten - def get_maximum_supplied_power(self): + def get_name(self): + return "PSU-{}".format(self.psu_index) + + def get_revision(self): + """ + Retrieves the hardware revision of the device + + Returns: + string: Revision value of device + """ + return 'N/A' + + def get_temperature_high_threshold(self): + """ + Retrieves the high threshold temperature of PSU + Returns: + A float number, the high threshold temperature of PSU in Celsius + up to nearest thousandth of one degree Celsius, e.g. 30.125 """ - Retrieves the maximum supplied power by PSU (or PSU capacity) + threshold = super().get_temperature_high_threshold() + + 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 + + return threshold + + def get_model(self): + """ + Retrieves the model number (or part number) of the device + Returns: - A float number, the maximum power output in Watts. - e.g. 1200.1 + string: Model/part number of device """ - return float(self.PLATFORM_PSU_CAPACITY) + model = super().get_model() + if model and model.strip() == "": + return None - def get_type(self): + return model + + def get_serial(self): """ - Gets the type of the PSU + Retrieves the serial number of the device + Returns: - A string, the type of PSU (AC/DC) + string: Serial number of device """ - return "AC" + 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() diff --git a/platform/broadcom/sonic-platform-modules-accton/as7816-64x/sonic_platform/sfp.py b/platform/broadcom/sonic-platform-modules-accton/as7816-64x/sonic_platform/sfp.py index d9b6e491bef..4dab7d7143b 100644 --- a/platform/broadcom/sonic-platform-modules-accton/as7816-64x/sonic_platform/sfp.py +++ b/platform/broadcom/sonic-platform-modules-accton/as7816-64x/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") @@ -11,7 +14,220 @@ 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_position_in_parent(self): + """Retrieves 1-based relative physical position in parent device.""" + return self.port_index + + 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 + + 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] + + 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() + + def get_lpmode(self): + + lpmode = False + + if self.get_presence()==False: + return False + + device = 'PORT{}'.format(self.port_index) + output = self.pddf_obj.get_attr_name_output(device, 'xcvr_lpmode') + + if output: + status = int(output['status'].rstrip()) + + if status == 1: + lpmode = True + else: + lpmode = False + else: + xcvr_id = self._xcvr_api_factory._get_id() + + if xcvr_id is not None: + if xcvr_id == 0x18 or xcvr_id == 0x19 or xcvr_id == 0x1e: + # QSFP-DD or OSFP + # Use common SfpOptoeBase implementation for get_lpmode + lpmode = super().get_lpmode() + elif xcvr_id == 0x11 or xcvr_id == 0x0d or xcvr_id == 0x0c: + # QSFP28, QSFP+, QSFP + # get_power_set() is not defined in the optoe_base class + api = self.get_xcvr_api() + power_set = api.get_power_set() + power_override = self.get_power_override() + + return power_set if power_override else False + + return lpmode \ No newline at end of file diff --git a/platform/broadcom/sonic-platform-modules-accton/as7816-64x/sonic_platform/thermal.py b/platform/broadcom/sonic-platform-modules-accton/as7816-64x/sonic_platform/thermal.py index 77d6ec7ae88..0ae3557e089 100644 --- a/platform/broadcom/sonic-platform-modules-accton/as7816-64x/sonic_platform/thermal.py +++ b/platform/broadcom/sonic-platform-modules-accton/as7816-64x/sonic_platform/thermal.py @@ -3,9 +3,96 @@ 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 = { + 'FB_1_temp(0x4D)' : { + HIGH_THRESHOLD : '80.0', + LOW_THRESHOLD : NOT_AVAILABLE, + HIGH_CRIT_THRESHOLD : NOT_AVAILABLE, + LOW_CRIT_THRESHOLD : NOT_AVAILABLE + }, + 'FB_2_temp(0x4E)' : { + HIGH_THRESHOLD : '80.0', + LOW_THRESHOLD : NOT_AVAILABLE, + HIGH_CRIT_THRESHOLD : NOT_AVAILABLE, + LOW_CRIT_THRESHOLD : NOT_AVAILABLE + }, + 'MB_MAC_temp(0x48)' : { + HIGH_THRESHOLD : '80.0', + LOW_THRESHOLD : NOT_AVAILABLE, + HIGH_CRIT_THRESHOLD : NOT_AVAILABLE, + LOW_CRIT_THRESHOLD : NOT_AVAILABLE + }, + 'MB_RearCenter_temp(0x49)' : { + HIGH_THRESHOLD : '80.0', + LOW_THRESHOLD : NOT_AVAILABLE, + HIGH_CRIT_THRESHOLD : NOT_AVAILABLE, + LOW_CRIT_THRESHOLD : NOT_AVAILABLE + }, + 'MB_RightCenter_temp(0x4A)' : { + HIGH_THRESHOLD : '80.0', + LOW_THRESHOLD : NOT_AVAILABLE, + HIGH_CRIT_THRESHOLD : NOT_AVAILABLE, + LOW_CRIT_THRESHOLD : NOT_AVAILABLE + }, + 'CpuBoard_temp(0x4B)' : { + HIGH_THRESHOLD : '80.0', + LOW_THRESHOLD : NOT_AVAILABLE, + HIGH_CRIT_THRESHOLD : NOT_AVAILABLE, + LOW_CRIT_THRESHOLD : NOT_AVAILABLE + }, + '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', + 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): @@ -13,5 +100,200 @@ 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) + # 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 # 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): + get_temp=self.get_temperature() + + 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) + + return super().get_high_threshold() + + 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) + + return super().get_high_critical_threshold() + + 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.max_temperature is None: + self.get_temperature() + + return self.max_temperature diff --git a/platform/broadcom/sonic-platform-modules-accton/as7816-64x/utils/accton_as7816_64x_util.py b/platform/broadcom/sonic-platform-modules-accton/as7816-64x/utils/accton_as7816_64x_util.py index 5ab3d8f20e9..3f1c5e68244 100755 --- a/platform/broadcom/sonic-platform-modules-accton/as7816-64x/utils/accton_as7816_64x_util.py +++ b/platform/broadcom/sonic-platform-modules-accton/as7816-64x/utils/accton_as7816_64x_util.py @@ -16,22 +16,30 @@ # 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_as7816_64x_util.py [-h] [-d] [-f] {install,clean,threshold} ... + +AS7816-64X 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 + api : install SONiC platform API + api_clean : uninstall SONiC platform API + threshold : modify thermal threshold """ import subprocess -import getopt import sys import logging import re import time import os +import argparse from sonic_py_common.general import getstatusoutput_noshell @@ -56,42 +64,48 @@ def main(): global DEBUG global args global FORCE + global THRESHOLD_RANGE_LOW, THRESHOLD_RANGE_HIGH - if len(sys.argv)<2: - show_help() - - options, args = getopt.getopt(sys.argv[1:], 'hdf', ['help', - 'debug', - 'force', - ]) + util_parser = argparse.ArgumentParser(description="AS7816-64X 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') + subcommand.add_parser('api', help=': install SONiC platform API') + subcommand.add_parser('api_clean', help=': uninstall SONiC platform API') + 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 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() - elif arg == 'api': - do_sonic_platform_install() - elif arg == 'api_clean': - do_sonic_platform_clean() - - else: - show_help() + DEBUG = args.debug + FORCE = 1 if args.force else 0 + if args.cmd == 'install': + do_install() + elif args.cmd == 'clean': + do_uninstall() + elif args.cmd == 'api': + do_sonic_platform_install() + elif args.cmd == 'api_clean': + do_sonic_platform_clean() + elif args.cmd == 'threshold': + do_threshold() return 0 @@ -150,7 +164,7 @@ def driver_check(): kos = [ 'modprobe i2c_dev', -'modprobe i2c_mux_pca954x force_deselect_on_exit=1', +'modprobe i2c_mux_pca954x', 'modprobe optoe', 'modprobe accton_i2c_cpld' , 'modprobe ym2651y' , @@ -256,6 +270,14 @@ def device_install(): if FORCE == 0: return status + # set all pca954x idle_disconnect + cmd = 'echo -2 | tee /sys/bus/i2c/drivers/pca954x/*-00*/idle_state' + status, output = log_os_system(cmd, 1) + if status: + print(output) + if FORCE == 0: + return status + for i in range(0,len(sfp_map)): path = "/sys/bus/i2c/devices/i2c-"+str(sfp_map[i])+"/new_device" status, output =log_os_system("echo optoe1 0x50 > " + path, 1) @@ -394,5 +416,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() diff --git a/platform/broadcom/sonic-platform-modules-accton/as7816-64x/utils/accton_as7816_pddf_monitor.py b/platform/broadcom/sonic-platform-modules-accton/as7816-64x/utils/accton_as7816_pddf_monitor.py index 8d64cc96170..76d571841f1 100755 --- a/platform/broadcom/sonic-platform-modules-accton/as7816-64x/utils/accton_as7816_pddf_monitor.py +++ b/platform/broadcom/sonic-platform-modules-accton/as7816-64x/utils/accton_as7816_pddf_monitor.py @@ -30,7 +30,8 @@ import logging.config import time # this is only being used as part of the example import signal - from sonic_platform import platform + from sonic_platform import platform, fan + from collections import namedtuple except ImportError as e: raise ImportError('%s - required module not found' % str(e)) @@ -38,6 +39,61 @@ VERSION = '1.0' FUNCTION_NAME = 'accton_as7816_monitor' DUTY_MAX = 100 +DUTY_DEF = 40 + +FANDUTY_BY_LEVEL={ + 'LV_5' : DUTY_DEF, + 'LV_7' : 52, + 'LV_9' : 64, + 'LV_B' : 76, + 'LV_D' : 88, + 'LV_F' : DUTY_MAX, +} +FANLEVEL_BY_DUTY={ + DUTY_DEF : 'LV_5', + 52 : 'LV_7', + 64 : 'LV_9', + 76 : 'LV_B', + 88 : 'LV_D', + DUTY_MAX : 'LV_F', +} + +NA_L = 0 +NA_H = 999999 +Threshold = namedtuple('Threshold', ['val', 'next_lv']) + +UP_TH_F2B = { #order :0x4D,0x4E,0x48,0x49,0x4A,0x4B + 'LV_5': Threshold([36000,38000,57000,60000,40000,39000], 'LV_7'), + 'LV_7': Threshold([43000,44000,62000,64000,46000,45000], 'LV_B'), + 'LV_9': Threshold([ NA_L, NA_L, NA_L, NA_L, NA_L, NA_L], 'LV_B'), # NA, force to change level. + 'LV_B': Threshold([48000,49000, NA_H, NA_H,51000,49000], 'LV_D'), + 'LV_D': Threshold([53000,54000,67000,70000,55000,54000], 'LV_F'), + 'LV_F': Threshold([ NA_H, NA_H, NA_H, NA_H, NA_H, NA_H], 'LV_F') # Won't go any higher. +} +DOWN_TH_F2B = { + 'LV_5': Threshold([ NA_L, NA_L, NA_L, NA_L, NA_L, NA_L], 'LV_5'), # Won't go any lower. + 'LV_7': Threshold([34000,36000,55000,58000,38000,37000], 'LV_5'), + 'LV_9': Threshold([ NA_H, NA_H, NA_H, NA_H, NA_H, NA_H], 'LV_7'), # NA, force to change level. + 'LV_B': Threshold([40000,41000,60000,62000,43000,42000], 'LV_7'), + 'LV_D': Threshold([46000,47000,65000,68000,49000,47000], 'LV_B'), + 'LV_F': Threshold([51000,52000, NA_H, NA_H,53000,52000], 'LV_D') +} +UP_TH_B2F = { + 'LV_5': Threshold([26000,26000,52000,41000,34000,27000], 'LV_7'), + 'LV_7': Threshold([31000,31000, NA_H, NA_H,38000,32000], 'LV_9'), + 'LV_9': Threshold([37000,36000,57000,48000,42000,37000], 'LV_B'), + 'LV_B': Threshold([42000,42000,61000,52000,46000,42000], 'LV_D'), + 'LV_D': Threshold([47000,47000,66000,57000,51000,47000], 'LV_F'), + 'LV_F': Threshold([ NA_H, NA_H, NA_H, NA_H, NA_H, NA_H], 'LV_F') # Won't go any higher. +} +DOWN_TH_B2F = { + 'LV_5': Threshold([NA_L,NA_L,NA_L,NA_L,NA_L,NA_L], 'LV_5'), # Won't go any lower. + 'LV_7': Threshold([24000,24000,50000,39000,32000,25000], 'LV_5'), + 'LV_9': Threshold([29000,29000,55000,45000,36000,30000], 'LV_7'), + 'LV_B': Threshold([34000,34000, NA_H, NA_H,40000,35000], 'LV_9'), + 'LV_D': Threshold([40000,40000,59000,50000,44000,40000], 'LV_B'), + 'LV_F': Threshold([45000,45000,63000,55000,48000,45000], 'LV_D') +} platform_chassis = None THERMAL_NUM_ON_MAIN_BROAD = 6 @@ -48,35 +104,26 @@ temp_test_data = 0 -def get_thermal_avg_temp(): - global platform_chassis +def get_temperature(thermal): global test_temp_list global test_temp global temp_test_data global test_temp_revert - sum_temp = 0 if test_temp == 0: - for x in range(THERMAL_NUM_ON_MAIN_BROAD): - sum_temp = sum_temp + platform_chassis.get_thermal(x).get_temperature()*1000 - - else: - for x in range(THERMAL_NUM_ON_MAIN_BROAD): - sum_temp = sum_temp + test_temp_list[x] + return thermal.get_temperature() * 1000 - avg = sum_temp/THERMAL_NUM_ON_MAIN_BROAD + idx = thermal.get_position_in_parent() - 1 + temp = test_temp_list[idx] + temp_test_data - if test_temp == 1: + if idx == THERMAL_NUM_ON_MAIN_BROAD - 1: if test_temp_revert == 0: temp_test_data = temp_test_data+2000 else: temp_test_data = temp_test_data-2000 - - avg = avg + temp_test_data - - avg = (avg/1000)*1000 # round down for hysteresis. - - return avg + temp = (temp/1000)*1000 + logging.debug('set test temp %d to thermal%d', temp, idx) + return temp # Make a class we can use to capture stdout and sterr in the log @@ -85,10 +132,16 @@ class accton_as7816_monitor(object): _ori_temp = 0 _new_perc = 0 _ori_perc = 0 - THERMAL_NUM_ON_MAIN_BROAD = 6 def __init__(self, log_file, log_level): """Needs a logger and a logger level.""" + global platform_chassis + self.thermals = platform_chassis.get_all_thermals() + self.fans = platform_chassis.get_all_fans() + self.is_fan_f2b = self.fans[0].get_direction().lower() == fan.Fan.FAN_DIRECTION_EXHAUST + self.up_th = UP_TH_F2B if self.is_fan_f2b == True else UP_TH_B2F + self.down_th = DOWN_TH_F2B if self.is_fan_f2b == True else DOWN_TH_B2F + # set up logging to file logging.basicConfig( filename=log_file, @@ -109,46 +162,51 @@ def __init__(self, log_file, log_level): logging.debug('SET. logfile:%s / loglevel:%d', log_file, log_level) def manage_fans(self): - global platform_chassis FAN_NUM = 2 FAN_TRAY_NUM = 4 - max_duty = DUTY_MAX - fan_policy = { - 0: [52, 0, 43000], - 1: [63, 43000, 46000], - 2: [75, 46000, 52000], - 3: [88, 52000, 57000], - 4: [max_duty, 57000, 100000], - } for x in range(FAN_TRAY_NUM * FAN_NUM): - if not platform_chassis.get_fan(x).get_status() or not platform_chassis.get_fan(x).get_speed_rpm(): - logging.debug('INFO. SET new_perc to %d (FAN stauts is None/Fault. fan_num:%d)', max_duty, x+1) - platform_chassis.get_fan(0).set_speed(max_duty) + if not self.fans[x].get_status() or not self.fans[x].get_speed_rpm(): + logging.debug('INFO. SET new_perc to %d (FAN stauts is None/Fault. fan_num:%d)', DUTY_MAX, x+1) + self.fans[0].set_speed(DUTY_MAX) return True # Find if current duty matched any of define duty. # If not, set it to highest one. - #cur_duty_cycle = fan.get_fan_duty_cycle() - cur_duty_cycle = platform_chassis.get_fan(0).get_speed() - new_duty_cycle = cur_duty_cycle - for x in range(0, len(fan_policy)): - if cur_duty_cycle == fan_policy[x][0]: + cur_duty_cycle = self.fans[0].get_speed() + fanlevel = FANLEVEL_BY_DUTY.get(cur_duty_cycle, 'LV_F') + + # decide target level by thermal sensor input. + can_level_up = False + can_level_down = True + skip_monitor = ['coretemp-isa-0000', 'Temp sensor 7'] + for thermal in self.thermals: + if thermal.get_name() in skip_monitor: + continue + temp = get_temperature(thermal) + th_idx= thermal.get_position_in_parent() - 1 + high = self.up_th[fanlevel].val[th_idx] + low = self.down_th[fanlevel].val[th_idx] + # perform level up if anyone is higher than high_th. + if temp >= high: + can_level_up = True break - if x == len(fan_policy): - platform_chassis.get_fan(0).set_speed(fan_policy[0][0]) - cur_duty_cycle = max_duty - - # Decide fan duty by if avg of sensors falls into any of fan_policy{} - get_temp = get_thermal_avg_temp() + # cancel level down if anyone is higher than low_th. + if temp > low: + can_level_down = False + + if can_level_up: + next_fanlevel = self.up_th[fanlevel].next_lv + elif can_level_down: + next_fanlevel = self.down_th[fanlevel].next_lv + else: + next_fanlevel = fanlevel + new_duty_cycle = FANDUTY_BY_LEVEL.get(next_fanlevel, DUTY_MAX) - for x in range(0, len(fan_policy)): - y = len(fan_policy) - x - 1 # checked from highest - if get_temp > fan_policy[y][1] and get_temp < fan_policy[y][2]: - new_duty_cycle = fan_policy[y][0] if(new_duty_cycle != cur_duty_cycle): - platform_chassis.get_fan(0).set_speed(new_duty_cycle) + logging.debug(f'set fanduty from {cur_duty_cycle} to {new_duty_cycle}') + self.fans[0].set_speed(new_duty_cycle) return True diff --git a/platform/broadcom/sonic-platform-modules-accton/common/modules/accton_psu_api.h b/platform/broadcom/sonic-platform-modules-accton/common/modules/accton_psu_api.h new file mode 100644 index 00000000000..d522979f1e8 --- /dev/null +++ b/platform/broadcom/sonic-platform-modules-accton/common/modules/accton_psu_api.h @@ -0,0 +1,29 @@ +/* + * Copyright 2022 Accton Technology Corporation. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * + * Description: + * PSU driver related api declarations + */ + +#ifndef ACCTON_PSU_API_H +#define ACCTON_PSU_API_H + +#include "accton_psu_defs.h" + +/** Description: + * Register psu status entry, set entry as NULL to unregister + */ +extern int register_psu_status_entry(PSU_STATUS_ENTRY *entry); + +#endif /* ACCTON_PSU_API_H */ diff --git a/platform/broadcom/sonic-platform-modules-accton/common/modules/accton_psu_defs.h b/platform/broadcom/sonic-platform-modules-accton/common/modules/accton_psu_defs.h new file mode 100644 index 00000000000..11bb253a573 --- /dev/null +++ b/platform/broadcom/sonic-platform-modules-accton/common/modules/accton_psu_defs.h @@ -0,0 +1,28 @@ +/* + * Copyright 2022 Accton Technology Corporation. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * + * Description: + * Platform PSU defines/structures header file + */ + +#ifndef ACCTON_PSU_DEFS_H +#define ACCTON_PSU_DEFS_H + +typedef struct PSU_STATUS_ENTRY +{ + int (*get_presence)(void *client); + int (*get_powergood)(void *client); +} PSU_STATUS_ENTRY; + +#endif /* ACCTON_PSU_DEFS_H */ diff --git a/platform/broadcom/sonic-platform-modules-accton/common/modules/ym2651y.c b/platform/broadcom/sonic-platform-modules-accton/common/modules/ym2651y.c index 20cef5d61a3..0180fa6d738 100755 --- a/platform/broadcom/sonic-platform-modules-accton/common/modules/ym2651y.c +++ b/platform/broadcom/sonic-platform-modules-accton/common/modules/ym2651y.c @@ -31,29 +31,62 @@ #include #include #include +#include +#include +#include "accton_psu_defs.h" +#define __STDC_WANT_LIB_EXT1__ 1 +#include #define MAX_FAN_DUTY_CYCLE 100 +#define ACCESS_INTERVAL_MAX 120 +#define ACCESS_INTERVAL_YM1151D_DEFAULT 60 +#define REFRESH_INTERVAL_SECOND 3 +#define REFRESH_INTERVAL_MSEC (REFRESH_INTERVAL_SECOND * 1000) +#define REFRESH_INTERVAL_HZ (REFRESH_INTERVAL_SECOND * HZ) + +#define EXIT_IF_POWER_FAILED(c) \ + do { \ + if (ym2651y_is_powergood(c) != 1) \ + goto exit; \ + } while (0) + +#define SLEEP_IF_INTERVAL(pInterval) \ + do { \ + int interval = atomic_read(pInterval); \ + if (interval > 0) \ + msleep(interval); \ + } while (0) + +/* SLEEP_IF_INTERVAL should be called before EXIT_IF_POWER_FAILED. + * It is known that accessing PSU when power failed might cause problems. + * So it is better to do sleep before checking power status because it avoids + * the risk that power status changes to failed during the sleep period. + */ +#define VALIDATE_POWERGOOD_AND_INTERVAL(client, pInterval) \ + do { \ + SLEEP_IF_INTERVAL(pInterval); \ + EXIT_IF_POWER_FAILED(client); \ + } while (0) + +struct mutex entry_lock; +PSU_STATUS_ENTRY access_psu_status = { NULL, NULL }; /* Addresses scanned */ -static const unsigned short normal_i2c[] = { 0x58, 0x5b, I2C_CLIENT_END }; +static const unsigned short normal_i2c[] = { 0x58, 0x59, 0x5b, I2C_CLIENT_END }; enum chips { YM2651, YM2401, YM2851, YM1401A, - YPEB1200AM + YPEB1200AM, + YM1151D, + UMEC_UPD150SA, + UMEC_UP1K21R }; -/* Each client has this additional data - */ -struct ym2651y_data { - struct device *hwmon_dev; - struct mutex update_lock; - char valid; /* !=0 if registers are valid */ - unsigned long last_updated; /* In jiffies */ - u8 chip; /* chip id */ +struct pmbus_register_value { u8 capability; /* Register value */ u16 status_word; /* Register value */ u8 fan_fault; /* Register value */ @@ -62,7 +95,7 @@ struct ym2651y_data { u16 i_out; /* Register value */ u16 p_out; /* Register value */ u8 vout_mode; /* Register value */ - u16 temp; /* Register value */ + u16 temp_input[3]; /* Register value */ u16 fan_speed; /* Register value */ u16 fan_duty_cycle[2]; /* Register value */ u8 fan_dir[4]; /* Register value */ @@ -81,6 +114,21 @@ struct ym2651y_data { u16 mfr_vout_max; /* Register value */ }; +/* Each client has this additional data + */ +struct ym2651y_data { + struct device *hwmon_dev; + struct mutex update_lock; + struct task_struct *update_task; + struct completion update_stop; + atomic_t access_interval; + char valid; /* !=0 if registers are valid */ + unsigned long last_updated; /* In jiffies */ + u8 chip; /* chip id */ + u8 mfr_serial_supported; + struct pmbus_register_value reg_val; +}; + static ssize_t show_vout(struct device *dev, struct device_attribute *da, char *buf); static ssize_t show_byte(struct device *dev, struct device_attribute *da, @@ -95,7 +143,14 @@ static ssize_t show_over_temp(struct device *dev, struct device_attribute *da, char *buf); static ssize_t show_ascii(struct device *dev, struct device_attribute *da, char *buf); -static struct ym2651y_data *ym2651y_update_device(struct device *dev); +static ssize_t show_interval(struct device *dev, struct device_attribute *da, + char *buf); +static ssize_t set_interval(struct device *dev, struct device_attribute *da, + const char *buf, size_t count); +static int mfr_serial_supported(u8 chip); +static int ym2651y_update_device(struct i2c_client *client, + struct pmbus_register_value *data); +static int ym2651y_update_thread(void *arg); static ssize_t set_fan_duty_cycle(struct device *dev, struct device_attribute *da, const char *buf, size_t count); static int ym2651y_write_word(struct i2c_client *client, u8 reg, u16 value); @@ -112,6 +167,8 @@ enum ym2651y_sysfs_attributes { PSU_P_OUT, PSU_P_OUT_UV, /*In Unit of microVolt, instead of mini.*/ PSU_TEMP1_INPUT, + PSU_TEMP2_INPUT, + PSU_TEMP3_INPUT, PSU_FAN1_SPEED, PSU_FAN1_DUTY_CYCLE, PSU_PMBUS_REVISION, @@ -127,7 +184,8 @@ enum ym2651y_sysfs_attributes { PSU_MFR_IIN_MAX, PSU_MFR_IOUT_MAX, PSU_MFR_PIN_MAX, - PSU_MFR_POUT_MAX + PSU_MFR_POUT_MAX, + PSU_ACCESS_INTERVAL }; /* sysfs attributes for hwmon @@ -141,6 +199,8 @@ static SENSOR_DEVICE_ATTR(psu_v_out, S_IRUGO, show_vout, NULL, PSU_V_OU static SENSOR_DEVICE_ATTR(psu_i_out, S_IRUGO, show_linear, NULL, PSU_I_OUT); static SENSOR_DEVICE_ATTR(psu_p_out, S_IRUGO, show_linear, NULL, PSU_P_OUT); static SENSOR_DEVICE_ATTR(psu_temp1_input, S_IRUGO, show_linear, NULL, PSU_TEMP1_INPUT); +static SENSOR_DEVICE_ATTR(psu_temp2_input, S_IRUGO, show_linear, NULL, PSU_TEMP2_INPUT); +static SENSOR_DEVICE_ATTR(psu_temp3_input, S_IRUGO, show_linear, NULL, PSU_TEMP3_INPUT); static SENSOR_DEVICE_ATTR(psu_fan1_speed_rpm, S_IRUGO, show_linear, NULL, PSU_FAN1_SPEED); static SENSOR_DEVICE_ATTR(psu_fan1_duty_cycle_percentage, S_IWUSR | S_IRUGO, show_linear, set_fan_duty_cycle, PSU_FAN1_DUTY_CYCLE); static SENSOR_DEVICE_ATTR(psu_fan_dir, S_IRUGO, show_ascii, NULL, PSU_FAN_DIRECTION); @@ -158,14 +218,19 @@ static SENSOR_DEVICE_ATTR(psu_mfr_iin_max, S_IRUGO, show_linear, NULL, PSU_MFR static SENSOR_DEVICE_ATTR(psu_mfr_iout_max, S_IRUGO, show_linear, NULL, PSU_MFR_IOUT_MAX); static SENSOR_DEVICE_ATTR(psu_mfr_pin_max, S_IRUGO, show_linear, NULL, PSU_MFR_PIN_MAX); static SENSOR_DEVICE_ATTR(psu_mfr_pout_max, S_IRUGO, show_linear, NULL, PSU_MFR_POUT_MAX); +static SENSOR_DEVICE_ATTR(psu_access_interval, S_IWUSR | S_IRUGO, show_interval, set_interval, PSU_ACCESS_INTERVAL); /*Duplicate nodes for lm-sensors.*/ static SENSOR_DEVICE_ATTR(in3_input, S_IRUGO, show_vout, NULL, PSU_V_OUT); static SENSOR_DEVICE_ATTR(curr2_input, S_IRUGO, show_linear, NULL, PSU_I_OUT); static SENSOR_DEVICE_ATTR(power2_input, S_IRUGO, show_linear, NULL, PSU_P_OUT_UV); static SENSOR_DEVICE_ATTR(temp1_input, S_IRUGO, show_linear, NULL, PSU_TEMP1_INPUT); +static SENSOR_DEVICE_ATTR(temp2_input, S_IRUGO, show_linear, NULL, PSU_TEMP2_INPUT); +static SENSOR_DEVICE_ATTR(temp3_input, S_IRUGO, show_linear, NULL, PSU_TEMP3_INPUT); static SENSOR_DEVICE_ATTR(fan1_input, S_IRUGO, show_linear, NULL, PSU_FAN1_SPEED); static SENSOR_DEVICE_ATTR(temp1_fault, S_IRUGO, show_word, NULL, PSU_TEMP_FAULT); +static SENSOR_DEVICE_ATTR(temp2_fault, S_IRUGO, show_word, NULL, PSU_TEMP_FAULT); +static SENSOR_DEVICE_ATTR(temp3_fault, S_IRUGO, show_word, NULL, PSU_TEMP_FAULT); static struct attribute *ym2651y_attributes[] = { &sensor_dev_attr_psu_power_on.dev_attr.attr, @@ -177,6 +242,8 @@ static struct attribute *ym2651y_attributes[] = { &sensor_dev_attr_psu_i_out.dev_attr.attr, &sensor_dev_attr_psu_p_out.dev_attr.attr, &sensor_dev_attr_psu_temp1_input.dev_attr.attr, + &sensor_dev_attr_psu_temp2_input.dev_attr.attr, + &sensor_dev_attr_psu_temp3_input.dev_attr.attr, &sensor_dev_attr_psu_fan1_speed_rpm.dev_attr.attr, &sensor_dev_attr_psu_fan1_duty_cycle_percentage.dev_attr.attr, &sensor_dev_attr_psu_fan_dir.dev_attr.attr, @@ -194,13 +261,18 @@ static struct attribute *ym2651y_attributes[] = { &sensor_dev_attr_psu_mfr_vout_min.dev_attr.attr, &sensor_dev_attr_psu_mfr_vout_max.dev_attr.attr, &sensor_dev_attr_psu_mfr_iout_max.dev_attr.attr, + &sensor_dev_attr_psu_access_interval.dev_attr.attr, /*Duplicate nodes for lm-sensors.*/ &sensor_dev_attr_curr2_input.dev_attr.attr, &sensor_dev_attr_in3_input.dev_attr.attr, &sensor_dev_attr_power2_input.dev_attr.attr, &sensor_dev_attr_temp1_input.dev_attr.attr, + &sensor_dev_attr_temp2_input.dev_attr.attr, + &sensor_dev_attr_temp3_input.dev_attr.attr, &sensor_dev_attr_fan1_input.dev_attr.attr, &sensor_dev_attr_temp1_fault.dev_attr.attr, + &sensor_dev_attr_temp2_fault.dev_attr.attr, + &sensor_dev_attr_temp3_fault.dev_attr.attr, NULL }; @@ -208,32 +280,59 @@ static ssize_t show_byte(struct device *dev, struct device_attribute *da, char *buf) { struct sensor_device_attribute *attr = to_sensor_dev_attr(da); - struct ym2651y_data *data = ym2651y_update_device(dev); + struct i2c_client *client = to_i2c_client(dev); + struct ym2651y_data *data = i2c_get_clientdata(client); + u8 status = 0; - return (attr->index == PSU_PMBUS_REVISION) ? sprintf(buf, "%d\n", data->pmbus_revision) : - sprintf(buf, "0\n"); + mutex_lock(&data->update_lock); + if (!data->valid) { + goto exit; + } + + if (attr->index == PSU_PMBUS_REVISION) + status = data->reg_val.pmbus_revision; + + mutex_unlock(&data->update_lock); + return sprintf(buf, "%d\n", status); + +exit: + mutex_unlock(&data->update_lock); + return 0; } static ssize_t show_word(struct device *dev, struct device_attribute *da, char *buf) { struct sensor_device_attribute *attr = to_sensor_dev_attr(da); - struct ym2651y_data *data = ym2651y_update_device(dev); + struct i2c_client *client = to_i2c_client(dev); + struct ym2651y_data *data = i2c_get_clientdata(client); u16 status = 0; + mutex_lock(&data->update_lock); + if (!data->valid) { + goto exit; + } + switch (attr->index) { case PSU_POWER_ON: /* psu_power_on, low byte bit 6 of status_word, 0=>ON, 1=>OFF */ - status = (data->status_word & 0x40) ? 0 : 1; + status = (data->reg_val.status_word & 0x40) ? 0 : 1; break; case PSU_TEMP_FAULT: /* psu_temp_fault, low byte bit 2 of status_word, 0=>Normal, 1=>temp fault */ - status = (data->status_word & 0x4) >> 2; + status = (data->reg_val.status_word & 0x4) >> 2; break; case PSU_POWER_GOOD: /* psu_power_good, high byte bit 3 of status_word, 0=>OK, 1=>FAIL */ - status = (data->status_word & 0x800) ? 0 : 1; + status = (data->reg_val.status_word & 0x800) ? 0 : 1; break; + default: + goto exit; } + mutex_unlock(&data->update_lock); return sprintf(buf, "%d\n", status); + +exit: + mutex_unlock(&data->update_lock); + return 0; } static int two_complement_to_int(u16 data, u8 valid_bit, int mask) @@ -262,8 +361,8 @@ static ssize_t set_fan_duty_cycle(struct device *dev, struct device_attribute *d return -EINVAL; mutex_lock(&data->update_lock); - data->fan_duty_cycle[nr] = speed; - ym2651y_write_word(client, 0x3B + nr, data->fan_duty_cycle[nr]); + data->reg_val.fan_duty_cycle[nr] = speed; + ym2651y_write_word(client, 0x3B + nr, data->reg_val.fan_duty_cycle[nr]); mutex_unlock(&data->update_lock); return count; @@ -273,151 +372,214 @@ static ssize_t show_linear(struct device *dev, struct device_attribute *da, char *buf) { struct sensor_device_attribute *attr = to_sensor_dev_attr(da); - struct ym2651y_data *data = ym2651y_update_device(dev); - + struct i2c_client *client = to_i2c_client(dev); + struct ym2651y_data *data = i2c_get_clientdata(client); u16 value = 0; int exponent, mantissa; int multiplier = 1000; + mutex_lock(&data->update_lock); + if (!data->valid) { + goto exit; + } + switch (attr->index) { case PSU_V_OUT: - value = data->v_out; + value = data->reg_val.v_out; break; case PSU_I_OUT: - value = data->i_out; + value = data->reg_val.i_out; break; case PSU_P_OUT_UV: multiplier = 1000000; /*For lm-sensors, unit is micro-Volt.*/ /*Passing through*/ case PSU_P_OUT: - value = data->p_out; + value = data->reg_val.p_out; break; case PSU_TEMP1_INPUT: - value = data->temp; + case PSU_TEMP2_INPUT: + case PSU_TEMP3_INPUT: + value = data->reg_val.temp_input[attr->index - PSU_TEMP1_INPUT]; break; case PSU_FAN1_SPEED: - value = data->fan_speed; + value = data->reg_val.fan_speed; multiplier = 1; break; case PSU_FAN1_DUTY_CYCLE: - value = data->fan_duty_cycle[0]; + value = data->reg_val.fan_duty_cycle[0]; multiplier = 1; break; case PSU_MFR_VIN_MIN: - value = data->mfr_vin_min; + value = data->reg_val.mfr_vin_min; break; case PSU_MFR_VIN_MAX: - value = data->mfr_vin_max; + value = data->reg_val.mfr_vin_max; break; case PSU_MFR_VOUT_MIN: - value = data->mfr_vout_min; + value = data->reg_val.mfr_vout_min; break; case PSU_MFR_VOUT_MAX: - value = data->mfr_vout_max; + value = data->reg_val.mfr_vout_max; break; case PSU_MFR_PIN_MAX: - value = data->mfr_pin_max; + value = data->reg_val.mfr_pin_max; break; case PSU_MFR_POUT_MAX: - value = data->mfr_pout_max; + value = data->reg_val.mfr_pout_max; break; case PSU_MFR_IOUT_MAX: - value = data->mfr_iout_max; + value = data->reg_val.mfr_iout_max; break; case PSU_MFR_IIN_MAX: - value = data->mfr_iin_max; + value = data->reg_val.mfr_iin_max; break; + default: + goto exit; } + mutex_unlock(&data->update_lock); exponent = two_complement_to_int(value >> 11, 5, 0x1f); mantissa = two_complement_to_int(value & 0x7ff, 11, 0x7ff); return (exponent >= 0) ? sprintf(buf, "%d\n", (mantissa << exponent) * multiplier) : sprintf(buf, "%d\n", (mantissa * multiplier) / (1 << -exponent)); + +exit: + mutex_unlock(&data->update_lock); + return 0; } static ssize_t show_fan_fault(struct device *dev, struct device_attribute *da, char *buf) { struct sensor_device_attribute *attr = to_sensor_dev_attr(da); - struct ym2651y_data *data = ym2651y_update_device(dev); + struct i2c_client *client = to_i2c_client(dev); + struct ym2651y_data *data = i2c_get_clientdata(client); + u8 shift = 0; + u8 fan_fault = 0; - u8 shift = (attr->index == PSU_FAN1_FAULT) ? 7 : 6; + mutex_lock(&data->update_lock); + if (!data->valid) { + goto exit; + } - return sprintf(buf, "%d\n", data->fan_fault >> shift); + fan_fault = data->reg_val.fan_fault; + mutex_unlock(&data->update_lock); + + shift = (attr->index == PSU_FAN1_FAULT) ? 7 : 6; + return sprintf(buf, "%d\n", fan_fault >> shift); + +exit: + mutex_unlock(&data->update_lock); + return 0; } static ssize_t show_over_temp(struct device *dev, struct device_attribute *da, char *buf) { - struct ym2651y_data *data = ym2651y_update_device(dev); + struct i2c_client *client = to_i2c_client(dev); + struct ym2651y_data *data = i2c_get_clientdata(client); + u8 over_temp = 0; - return sprintf(buf, "%d\n", data->over_temp >> 7); + mutex_lock(&data->update_lock); + if (!data->valid) { + goto exit; + } + + over_temp = data->reg_val.over_temp; + mutex_unlock(&data->update_lock); + return sprintf(buf, "%d\n", over_temp >> 7); + +exit: + mutex_unlock(&data->update_lock); + return 0; } static ssize_t show_ascii(struct device *dev, struct device_attribute *da, char *buf) { struct sensor_device_attribute *attr = to_sensor_dev_attr(da); - struct ym2651y_data *data = ym2651y_update_device(dev); + struct i2c_client *client = to_i2c_client(dev); + struct ym2651y_data *data = i2c_get_clientdata(client); + ssize_t ret = 0; u8 *ptr = NULL; + mutex_lock(&data->update_lock); + if (!data->valid) { + goto exit; + } + switch (attr->index) { case PSU_FAN_DIRECTION: /* psu_fan_dir */ if (data->chip==YPEB1200AM) { - memcpy(data->fan_dir, "F2B", 3); - data->fan_dir[3]='\0'; + #ifdef __STDC_LIB_EXT1__ + memcpy_s(data->reg_val.fan_dir, 3, "F2B", 3); + #else + memcpy(data->reg_val.fan_dir, "F2B", 3); + #endif + data->reg_val.fan_dir[3]='\0'; } - ptr = data->fan_dir; + ptr = data->reg_val.fan_dir; break; case PSU_MFR_SERIAL: /* psu_mfr_serial */ - ptr = data->mfr_serial+1; /* The first byte is the count byte of string. */ + ptr = data->reg_val.mfr_serial+1; /* The first byte is the count byte of string. */ break; case PSU_MFR_ID: /* psu_mfr_id */ - ptr = data->mfr_id+1; /* The first byte is the count byte of string. */ + ptr = data->reg_val.mfr_id+1; /* The first byte is the count byte of string. */ break; case PSU_MFR_MODEL: /* psu_mfr_model */ - ptr = data->mfr_model+1; /* The first byte is the count byte of string. */ + ptr = data->reg_val.mfr_model+1; /* The first byte is the count byte of string. */ break; case PSU_MFR_REVISION: /* psu_mfr_revision */ - ptr = data->mfr_revsion+1; + ptr = data->reg_val.mfr_revsion+1; break; default: - return 0; + goto exit; } - return sprintf(buf, "%s\n", ptr); + ret = sprintf(buf, "%s\n", ptr); + +exit: + mutex_unlock(&data->update_lock); + return ret; } static ssize_t show_vout_by_mode(struct device *dev, struct device_attribute *da, char *buf) { struct sensor_device_attribute *attr = to_sensor_dev_attr(da); - struct ym2651y_data *data = ym2651y_update_device(dev); + struct i2c_client *client = to_i2c_client(dev); + struct ym2651y_data *data = i2c_get_clientdata(client); int exponent, mantissa; int multiplier = 1000; + mutex_lock(&data->update_lock); if (!data->valid) { - return 0; + goto exit; } - exponent = two_complement_to_int(data->vout_mode, 5, 0x1f); + exponent = two_complement_to_int(data->reg_val.vout_mode, 5, 0x1f); switch (attr->index) { case PSU_MFR_VOUT_MIN: - mantissa = data->mfr_vout_min; + mantissa = data->reg_val.mfr_vout_min; break; case PSU_MFR_VOUT_MAX: - mantissa = data->mfr_vout_max; + mantissa = data->reg_val.mfr_vout_max; break; case PSU_V_OUT: - mantissa = data->v_out; + mantissa = data->reg_val.v_out; break; default: - return 0; + goto exit; } + mutex_unlock(&data->update_lock); return (exponent > 0) ? sprintf(buf, "%d\n", (mantissa << exponent) * multiplier) : sprintf(buf, "%d\n", (mantissa * multiplier) / (1 << -exponent)); + +exit: + mutex_unlock(&data->update_lock); + return 0; } static ssize_t show_vout(struct device *dev, struct device_attribute *da, @@ -434,6 +596,34 @@ static ssize_t show_vout(struct device *dev, struct device_attribute *da, } } +static ssize_t show_interval(struct device *dev, struct device_attribute *da, + char *buf) +{ + struct i2c_client *client = to_i2c_client(dev); + struct ym2651y_data *data = i2c_get_clientdata(client); + + return sprintf(buf, "%d\n", atomic_read(&data->access_interval)); +} + +static ssize_t set_interval(struct device *dev, struct device_attribute *da, + const char *buf, size_t count) +{ + int status; + long interval; + struct i2c_client *client = to_i2c_client(dev); + struct ym2651y_data *data = i2c_get_clientdata(client); + + status = kstrtol(buf, 10, &interval); + if (status) + return status; + + if (interval < 0 || interval > ACCESS_INTERVAL_MAX) + return -EINVAL; + + atomic_set(&data->access_interval, (int)interval); + return count; +} + static const struct attribute_group ym2651y_group = { .attrs = ym2651y_attributes, }; @@ -461,6 +651,7 @@ static int ym2651y_probe(struct i2c_client *client, i2c_set_clientdata(client, data); mutex_init(&data->update_lock); data->chip = dev_id->driver_data; + data->mfr_serial_supported = mfr_serial_supported(data->chip); dev_info(&client->dev, "chip found\n"); /* Register sysfs hooks */ @@ -475,11 +666,26 @@ static int ym2651y_probe(struct i2c_client *client, goto exit_remove; } + /* create update thread */ + if (data->chip == YM1151D) + atomic_set(&data->access_interval, ACCESS_INTERVAL_YM1151D_DEFAULT); + else + atomic_set(&data->access_interval, 0); + + init_completion(&data->update_stop); + data->update_task = kthread_run(ym2651y_update_thread, client, "ym2651y_update_task"); + if (IS_ERR(data->update_task)) { + dev_dbg(&client->dev, "Failed to create ym2651y update task!\n"); + goto exit_hwmon; + } + dev_info(&client->dev, "%s: psu '%s'\n", dev_name(data->hwmon_dev), client->name); return 0; +exit_hwmon: + hwmon_device_unregister(data->hwmon_dev); exit_remove: sysfs_remove_group(&client->dev.kobj, &ym2651y_group); exit_free: @@ -493,6 +699,10 @@ static int ym2651y_remove(struct i2c_client *client) { struct ym2651y_data *data = i2c_get_clientdata(client); + /* Stop update task */ + kthread_stop(data->update_task); + wait_for_completion(&data->update_stop); + hwmon_device_unregister(data->hwmon_dev); sysfs_remove_group(&client->dev.kobj, &ym2651y_group); kfree(data); @@ -506,6 +716,9 @@ static const struct i2c_device_id ym2651y_id[] = { { "ym2851", YM2851 }, { "ym1401a",YM1401A}, { "ype1200am", YPEB1200AM }, + { "ym1151d", YM1151D }, + { "umec_upd150sa", UMEC_UPD150SA }, + { "umec_up1k21r", UMEC_UP1K21R }, {} }; MODULE_DEVICE_TABLE(i2c, ym2651y_id); @@ -521,6 +734,23 @@ static struct i2c_driver ym2651y_driver = { .address_list = normal_i2c, }; +static int ym2651y_is_powergood(struct i2c_client *client) +{ + int powergood = 0; + + mutex_lock(&entry_lock); + if (access_psu_status.get_powergood == NULL) { + powergood = 1; /* skip powergood validation if API is not registered */ + goto exit; + } + + powergood = access_psu_status.get_powergood(client); + +exit: + mutex_unlock(&entry_lock); + return powergood; +} + static int ym2651y_read_byte(struct i2c_client *client, u8 reg) { return i2c_smbus_read_byte_data(client, reg); @@ -539,8 +769,9 @@ static int ym2651y_write_word(struct i2c_client *client, u8 reg, u16 value) static int ym2651y_read_block(struct i2c_client *client, u8 command, u8 *data, int data_len) { - int result = i2c_smbus_read_i2c_block_data(client, command, data_len, data); + int result; + result = i2c_smbus_read_i2c_block_data(client, command, data_len, data); if (unlikely(result < 0)) goto abort; if (unlikely(result != data_len)) { @@ -564,15 +795,10 @@ struct reg_data_word { u16 *value; }; -static struct ym2651y_data *ym2651y_update_device(struct device *dev) +static int ym2651y_update_device(struct i2c_client *client, + struct pmbus_register_value *data) { - struct i2c_client *client = to_i2c_client(dev); - struct ym2651y_data *data = i2c_get_clientdata(client); - - mutex_lock(&data->update_lock); - - if (time_after(jiffies, data->last_updated + HZ + HZ / 2) - || !data->valid) { + struct ym2651y_data *driver_data = i2c_get_clientdata(client); int i, status, length; u8 command, buf; u8 fan_dir[5] = {0}; @@ -586,7 +812,9 @@ static struct ym2651y_data *ym2651y_update_device(struct device *dev) {0x8b, &data->v_out}, {0x8c, &data->i_out}, {0x96, &data->p_out}, - {0x8d, &data->temp}, + {0x8d, &(data->temp_input[0])}, + {0x8e, &(data->temp_input[1])}, + {0x8f, &(data->temp_input[2])}, {0x3b, &(data->fan_duty_cycle[0])}, {0x3c, &(data->fan_duty_cycle[1])}, {0x90, &data->fan_speed}, @@ -604,8 +832,9 @@ static struct ym2651y_data *ym2651y_update_device(struct device *dev) /* Read byte data */ for (i = 0; i < ARRAY_SIZE(regs_byte); i++) { - status = ym2651y_read_byte(client, regs_byte[i].reg); + VALIDATE_POWERGOOD_AND_INTERVAL(client, &driver_data->access_interval); + status = ym2651y_read_byte(client, regs_byte[i].reg); if (status < 0) { dev_dbg(&client->dev, "reg %d, err %d\n", @@ -620,10 +849,20 @@ static struct ym2651y_data *ym2651y_update_device(struct device *dev) /* Read word data */ for (i = 0; i < ARRAY_SIZE(regs_word); i++) { - status = ym2651y_read_word(client, regs_word[i].reg); + VALIDATE_POWERGOOD_AND_INTERVAL(client, &driver_data->access_interval); + + /* To prevent hardware errors, + access to temp2_input and temp3_input should be skipped + if the chip ID is not in the following list. */ + if (regs_word[i].reg == 0x8e || regs_word[i].reg == 0x8f) { + if (driver_data->chip != UMEC_UPD150SA && + driver_data->chip != UMEC_UP1K21R) { + continue; + } + } - if (status < 0) - { + status = ym2651y_read_word(client, regs_word[i].reg); + if (status < 0) { dev_dbg(&client->dev, "reg %d, err %d\n", regs_word[i].reg, status); *(regs_word[i].value) = 0; @@ -636,109 +875,178 @@ static struct ym2651y_data *ym2651y_update_device(struct device *dev) /* Read fan_direction */ command = 0xC3; + VALIDATE_POWERGOOD_AND_INTERVAL(client, &driver_data->access_interval); status = ym2651y_read_block(client, command, fan_dir, ARRAY_SIZE(fan_dir)-1); - - if (status < 0) { - dev_dbg(&client->dev, "reg %d, err %d\n", command, status); - goto exit; - } - + if (status == 0) { strncpy(data->fan_dir, fan_dir+1, ARRAY_SIZE(data->fan_dir)-1); data->fan_dir[ARRAY_SIZE(data->fan_dir)-1] = '\0'; + } /* Read mfr_id */ command = 0x99; + VALIDATE_POWERGOOD_AND_INTERVAL(client, &driver_data->access_interval); status = ym2651y_read_block(client, command, data->mfr_id, ARRAY_SIZE(data->mfr_id)-1); + if (status == 0) data->mfr_id[ARRAY_SIZE(data->mfr_id)-1] = '\0'; - if (status < 0) - dev_dbg(&client->dev, "reg %d, err %d\n", command, status); - /* Read mfr_model */ command = 0x9a; length = 1; /* Read first byte to determine the length of data */ + VALIDATE_POWERGOOD_AND_INTERVAL(client, &driver_data->access_interval); status = ym2651y_read_block(client, command, &buf, length); - if (status < 0) { - dev_dbg(&client->dev, "reg %d, err %d\n", command, status); - goto exit; - } + if (status == 0 && buf != 0xFF) { + VALIDATE_POWERGOOD_AND_INTERVAL(client, &driver_data->access_interval); status = ym2651y_read_block(client, command, data->mfr_model, buf+1); - + if (status == 0) { if ((buf+1) >= (ARRAY_SIZE(data->mfr_model)-1)) - { data->mfr_model[ARRAY_SIZE(data->mfr_model)-1] = '\0'; - } else data->mfr_model[buf+1] = '\0'; - - if (status < 0) - { - dev_dbg(&client->dev, "reg %d, err %d\n", command, status); - goto exit; + } } /*YM-1401A PSU doens't support to get serial_num, so ignore it. *It's vout doesn't support linear, so let it use show_vout_by_mode(). */ - if(!strncmp("YM-1401A", data->mfr_model+1, strlen("YM-1401A"))) - { - data->chip=YM1401A; + if (!strncmp("YM-1401A", data->mfr_model+1, strlen("YM-1401A"))) { + driver_data->chip=YM1401A; } - else - { + else if (driver_data->mfr_serial_supported) { /* Read mfr_serial */ command = 0x9e; length = 1; /* Read first byte to determine the length of data */ + VALIDATE_POWERGOOD_AND_INTERVAL(client, &driver_data->access_interval); status = ym2651y_read_block(client, command, &buf, length); - if (status < 0) { - dev_dbg(&client->dev, "reg %d, err %d\n", command, status); - goto exit; - } + if (status == 0 && buf != 0xFF) { + VALIDATE_POWERGOOD_AND_INTERVAL(client, &driver_data->access_interval); status = ym2651y_read_block(client, command, data->mfr_serial, buf+1); - + if (status == 0) { if ((buf+1) >= (ARRAY_SIZE(data->mfr_serial)-1)) - { data->mfr_serial[ARRAY_SIZE(data->mfr_serial)-1] = '\0'; - } else data->mfr_serial[buf+1] = '\0'; - - if (status < 0) - { - dev_dbg(&client->dev, "reg %d, err %d\n", command, status); - goto exit; + } } } /* Read mfr_revsion */ command = 0x9b; + VALIDATE_POWERGOOD_AND_INTERVAL(client, &driver_data->access_interval); status = ym2651y_read_block(client, command, data->mfr_revsion, ARRAY_SIZE(data->mfr_revsion)-1); + if (status == 0) data->mfr_revsion[ARRAY_SIZE(data->mfr_revsion)-1] = '\0'; - if (status < 0) - { - dev_dbg(&client->dev, "reg %d, err %d\n", command, status); - goto exit; + return 1; /* Return 1 for valid data, 0 for invalid */ + +exit: + return 0; } - data->last_updated = jiffies; +static int ym2651y_update_thread(void *arg) +{ + int valid = 0; + unsigned long start_time = 0; + unsigned long next_start_time = 0; /* expected next start time */ + struct i2c_client *client = arg; + struct ym2651y_data *data = i2c_get_clientdata(client); + + if (data == NULL) + return -EINVAL; + + while (!kthread_should_stop()) { + struct pmbus_register_value reg_val = { 0 }; + + start_time = jiffies; + valid = ym2651y_update_device(client, ®_val); + + mutex_lock(&data->update_lock); data->valid = 1; + if (valid) { + #ifdef __STDC_LIB_EXT1__ + memcpy_s(&data->reg_val, sizeof(reg_val), ®_val, sizeof(reg_val)); + #else + memcpy(&data->reg_val, ®_val, sizeof(reg_val)); + #endif + } else { + #ifdef __STDC_LIB_EXT1__ + memset_s(&data->reg_val, sizeof(reg_val), 0, sizeof(reg_val)); + #else + memset(&data->reg_val, 0, sizeof(reg_val)); + #endif + + /* PMBus STATUS_WORD(0x79): psu_power_on, low byte bit 6, 0=>ON, 1=>OFF */ + data->reg_val.status_word |= 0x40; + + /* PMBus STATUS_WORD(0x79): psu_power_good, high byte bit 3, 0=>OK, 1=>FAIL */ + data->reg_val.status_word |= 0x800; + + /* psu_power_good = failed, modified to return 1023 degree for python used. */ + data->reg_val.temp_input[0] = 0x3ff; + data->reg_val.temp_input[1] = 0x3ff; + data->reg_val.temp_input[2] = 0x3ff; + } + mutex_unlock(&data->update_lock); + + next_start_time = start_time + REFRESH_INTERVAL_HZ; + if (time_before(jiffies, next_start_time)) { + /* Sleep if time consumed is less than REFRESH_INTERVAL_SECOND */ + msleep(min(jiffies_to_msecs(next_start_time - jiffies), REFRESH_INTERVAL_MSEC)); + } } - exit: - mutex_unlock(&data->update_lock); + complete_all(&data->update_stop); + return 0; +} + +int register_psu_status_entry(PSU_STATUS_ENTRY *entry) +{ + mutex_lock(&entry_lock); + + if (entry) { + access_psu_status.get_presence = entry->get_presence; + access_psu_status.get_powergood = entry->get_powergood; + } + else { + access_psu_status.get_presence = NULL; + access_psu_status.get_powergood = NULL; + } + + mutex_unlock(&entry_lock); + return 0; +} +EXPORT_SYMBOL(register_psu_status_entry); - return data; +static int __init ym2651y_init(void) +{ + mutex_init(&entry_lock); + return i2c_add_driver(&ym2651y_driver); } -module_i2c_driver(ym2651y_driver); +static void __exit ym2651y_exit(void) +{ + i2c_del_driver(&ym2651y_driver); +} + +static int mfr_serial_supported(u8 chip) +{ + int i = 0; + u8 supported_chips[] = {}; + + for (i = 0; i < ARRAY_SIZE(supported_chips); i++) { + if (chip == supported_chips[i]) + return 1; +} + + return 0; +} MODULE_AUTHOR("Brandon Chuang "); MODULE_DESCRIPTION("3Y Power YM-2651Y driver"); MODULE_LICENSE("GPL"); - +module_init(ym2651y_init); +module_exit(ym2651y_exit);