From 9b337c4ff4084f1ceab545459cf890c2079d7017 Mon Sep 17 00:00:00 2001 From: nonodark Date: Fri, 10 May 2024 14:51:12 +0800 Subject: [PATCH] Update old platform code. * s6301-56st * s7801-54xs * s8901-54xc * s9110-32x * s9300-32d --- .../installer.conf | 2 +- .../pddf/pd-plugin.json | 24 +- .../pddf/pddf-device.json | 131 +- .../sensors.conf | 1 - .../installer.conf | 2 +- .../pddf/pd-plugin.json | 13 +- .../pddf/pddf-device.json | 47 +- .../sensors.conf | 1 - .../installer.conf | 2 +- .../pddf/pd-plugin.json | 13 +- .../pddf/pddf-device.json | 47 +- .../sensors.conf | 1 - .../UFISPACE-S9110-32X/sai.profile | 0 .../td3-x7-s9110-32x.config.bcm | 0 .../custom_led.bin | Bin .../installer.conf | 2 +- .../led_proc_init.soc | 0 .../pddf/pd-plugin.json | 8 +- .../pddf/pddf-device-beta.json | 139 +- .../pddf/pddf-device-pvt.json | 139 +- .../x86_64-ufispace_s9110_32x-r0/sensors.conf | 1 - .../td4-s9300-32x400G.config.yml | 9 +- .../custom_led.bin | Bin 356 -> 716 bytes .../installer.conf | 2 +- .../pddf/pd-plugin.json | 6 +- .../pddf/pddf-device.json | 200 +- .../platform_components.json | 13 + platform/broadcom/one-image.mk | 8 +- .../broadcom/platform-modules-ufispace.dep | 10 + platform/broadcom/rules.dep | 2 + .../sonic-platform-ufispace-s9300-32d.prerm | 2 + .../s6301-56st/modules/Makefile | 2 +- .../s6301-56st/modules/pddf_custom_psu.c | 124 + .../modules/x86-64-ufispace-s6301-56st-lpc.c | 130 +- .../x86-64-ufispace-s6301-56st-sys-eeprom.c | 4 +- .../s6301-56st/sonic_platform/chassis.py | 36 +- .../s6301-56st/sonic_platform/fan.py | 58 +- .../s6301-56st/sonic_platform/psu.py | 42 +- .../s6301-56st/sonic_platform/watchdog.py | 23 - .../utils/pddf_pre_driver_install.sh | 11 - .../modules/pddf_custom_sysstatus_module.c | 10 +- .../modules/x86-64-ufispace-s7801-54xs-cpld.c | 2 +- .../x86-64-ufispace-s7801-54xs-sys-eeprom.c | 4 +- .../s7801-54xs/sonic_platform/chassis.py | 11 + .../s7801-54xs/sonic_platform/component.py | 20 +- .../s7801-54xs/sonic_platform/psu.py | 29 + .../utils/pddf_post_device_create.sh | 2 +- .../utils/pddf_pre_driver_install.sh | 8 - .../s7801-54xs/utils/pre_pddf_init.sh | 5 - .../modules/pddf_custom_sysstatus_module.c | 10 +- .../modules/x86-64-ufispace-s8901-54xc-cpld.c | 2 +- .../x86-64-ufispace-s8901-54xc-sys-eeprom.c | 4 +- .../s8901-54xc/sonic_platform/chassis.py | 11 + .../s8901-54xc/sonic_platform/component.py | 20 +- .../s8901-54xc/sonic_platform/psu.py | 29 + .../utils/pddf_post_device_create.sh | 2 +- .../utils/pddf_pre_driver_install.sh | 8 - .../s8901-54xc/utils/pre_pddf_init.sh | 5 - .../modules/pddf_custom_sysstatus_module.c | 10 +- .../modules/x86-64-ufispace-s9110-32x-cpld.c | 4 +- .../x86-64-ufispace-s9110-32x-sys-eeprom.c | 4 +- .../s9110-32x/sonic_platform/chassis.py | 11 + .../s9110-32x/sonic_platform/component.py | 20 +- .../s9110-32x/sonic_platform/fan.py | 1 - .../s9110-32x/sonic_platform/psu.py | 31 +- .../utils/pddf_post_device_create.sh | 2 +- .../utils/pddf_pre_driver_install.sh | 11 - .../modules/pddf_custom_sysstatus_module.c | 9 +- .../modules/x86-64-ufispace-s9300-32d-cpld.c | 3276 ++++++++--------- .../modules/x86-64-ufispace-s9300-32d-cpld.h | 502 +-- .../modules/x86-64-ufispace-s9300-32d-lpc.c | 1666 +++++---- .../x86-64-ufispace-s9300-32d-sys-eeprom.c | 548 +-- .../s9300-32d/sonic_platform/chassis.py | 14 +- .../s9300-32d/sonic_platform/component.py | 20 +- .../s9300-32d/sonic_platform/fan.py | 6 +- .../s9300-32d/sonic_platform/psu.py | 20 +- .../s9300-32d/sonic_platform/sfp.py | 14 + .../s9300-32d/sonic_platform/watchdog.py | 23 - .../utils/pddf_post_device_create.sh | 3 + .../utils/pddf_pre_driver_install.sh | 11 - 80 files changed, 4088 insertions(+), 3555 deletions(-) delete mode 100644 device/ufispace/x86_64-ufispace_s6301_56st-r0/sensors.conf delete mode 100644 device/ufispace/x86_64-ufispace_s7801_54xs-r0/sensors.conf delete mode 100644 device/ufispace/x86_64-ufispace_s8901_54xc-r0/sensors.conf mode change 100755 => 100644 device/ufispace/x86_64-ufispace_s9110_32x-r0/UFISPACE-S9110-32X/sai.profile mode change 100755 => 100644 device/ufispace/x86_64-ufispace_s9110_32x-r0/UFISPACE-S9110-32X/td3-x7-s9110-32x.config.bcm mode change 100755 => 100644 device/ufispace/x86_64-ufispace_s9110_32x-r0/custom_led.bin mode change 100755 => 100644 device/ufispace/x86_64-ufispace_s9110_32x-r0/led_proc_init.soc delete mode 100644 device/ufispace/x86_64-ufispace_s9110_32x-r0/sensors.conf create mode 100644 device/ufispace/x86_64-ufispace_s9300_32d-r0/platform_components.json create mode 100644 platform/broadcom/platform-modules-ufispace.dep create mode 100644 platform/broadcom/sonic-platform-modules-ufispace/debian/sonic-platform-ufispace-s9300-32d.prerm create mode 100644 platform/broadcom/sonic-platform-modules-ufispace/s6301-56st/modules/pddf_custom_psu.c delete mode 100644 platform/broadcom/sonic-platform-modules-ufispace/s6301-56st/sonic_platform/watchdog.py delete mode 100755 platform/broadcom/sonic-platform-modules-ufispace/s6301-56st/utils/pddf_pre_driver_install.sh delete mode 100755 platform/broadcom/sonic-platform-modules-ufispace/s7801-54xs/utils/pddf_pre_driver_install.sh delete mode 100755 platform/broadcom/sonic-platform-modules-ufispace/s7801-54xs/utils/pre_pddf_init.sh delete mode 100755 platform/broadcom/sonic-platform-modules-ufispace/s8901-54xc/utils/pddf_pre_driver_install.sh delete mode 100755 platform/broadcom/sonic-platform-modules-ufispace/s8901-54xc/utils/pre_pddf_init.sh delete mode 100755 platform/broadcom/sonic-platform-modules-ufispace/s9110-32x/utils/pddf_pre_driver_install.sh delete mode 100644 platform/broadcom/sonic-platform-modules-ufispace/s9300-32d/sonic_platform/watchdog.py delete mode 100755 platform/broadcom/sonic-platform-modules-ufispace/s9300-32d/utils/pddf_pre_driver_install.sh diff --git a/device/ufispace/x86_64-ufispace_s6301_56st-r0/installer.conf b/device/ufispace/x86_64-ufispace_s6301_56st-r0/installer.conf index 8f9944da69a6..74b02f076689 100644 --- a/device/ufispace/x86_64-ufispace_s6301_56st-r0/installer.conf +++ b/device/ufispace/x86_64-ufispace_s6301_56st-r0/installer.conf @@ -1,4 +1,4 @@ CONSOLE_PORT=0x3f8 CONSOLE_DEV=0 CONSOLE_SPEED=115200 -ONIE_PLATFORM_EXTRA_CMDLINE_LINUX="module_blacklist=gpio_ich nomodeset pcie_aspm=off" +ONIE_PLATFORM_EXTRA_CMDLINE_LINUX="modprobe.blacklist=gpio_ich,qat_c3xxx nomodeset pcie_aspm=off" diff --git a/device/ufispace/x86_64-ufispace_s6301_56st-r0/pddf/pd-plugin.json b/device/ufispace/x86_64-ufispace_s6301_56st-r0/pddf/pd-plugin.json index 49c09b0a7888..eae9cd37952a 100644 --- a/device/ufispace/x86_64-ufispace_s6301_56st-r0/pddf/pd-plugin.json +++ b/device/ufispace/x86_64-ufispace_s6301_56st-r0/pddf/pd-plugin.json @@ -21,6 +21,10 @@ "psu_present": { "i2c": + { + "valmap": { "1":true, "0":false } + }, + "bmc": { "valmap": { "1":true, "0":false } } @@ -33,14 +37,15 @@ "valmap": { "1": true, "0":false } } }, + "psu_support_list": [ - {"Mfr_id": "ASPOWER","Model": "U1A-K10150-DRB-13", "Dir": "EXHAUST"}, - {"Mfr_id": "ASPOWER","Model": "U1A-K0150-B-13", "Dir": "INTAKE"}, - {"Mfr_id": "ASPOWER","Model": "U1D-K0150-A-13", "Dir": "EXHAUST"}, - {"Mfr_id": "ASPOWER","Model": "U1D-K0150-B-13", "Dir": "INTAKE"} + {"Manufacturer": "ASPOWER","Name": "U1A-K10150-DRB-13", "MaxSpd": "PSU_AC_FAN_MAX_SPEED", "Dir": "EXHAUST", "Type": "AC" }, + {"Manufacturer": "ASPOWER","Name": "U1A-K0150-B-13", "MaxSpd": "PSU_AC_FAN_MAX_SPEED", "Dir": "INTAKE", "Type": "AC"}, + {"Manufacturer": "ASPOWER","Name": "U1D-K0150-A-13", "MaxSpd": "PSU_DC_FAN_MAX_SPEED", "Dir": "EXHAUST", "Type": "DC"}, + {"Manufacturer": "ASPOWER","Name": "U1D-K0150-B-13", "MaxSpd": "PSU_DC_FAN_MAX_SPEED", "Dir": "INTAKE", "Type": "DC"} ], - "PSU_FAN_MAX_SPEED":"13000" + "valmap": {"PSU_FAN_MAX_SPEED": "13000", "PSU_AC_FAN_MAX_SPEED": "13000", "PSU_DC_FAN_MAX_SPEED":"13000", "DEFAULT_TYPE": "AC"} }, "FAN": @@ -63,15 +68,6 @@ "FAN_MAX_SPEED":"25000" }, - - "LED": - { - "capability": - { - "ro": ["SYS_LED", "FAN_LED", "PSU1_LED", "PSU2_LED"], - "rw": ["ID_LED"] - } - }, "REBOOT_CAUSE": { "reboot_cause_file": "/host/reboot-cause/reboot-cause.txt" diff --git a/device/ufispace/x86_64-ufispace_s6301_56st-r0/pddf/pddf-device.json b/device/ufispace/x86_64-ufispace_s6301_56st-r0/pddf/pddf-device.json index abf83dd93e48..5f906161fe21 100644 --- a/device/ufispace/x86_64-ufispace_s6301_56st-r0/pddf/pddf-device.json +++ b/device/ufispace/x86_64-ufispace_s6301_56st-r0/pddf/pddf-device.json @@ -24,9 +24,11 @@ "pddf_xcvr" ] }, + "std_perm_kos": [ + "i2c-i801", + "i2c-ismt" + ], "std_kos": [ - "i2c_i801", - "i2c-ismt", "i2c_dev", "i2c_mux_pca954x", "optoe", @@ -41,9 +43,12 @@ "pddf_cpld_driver", "pddf_mux_module", "pddf_xcvr_module", + "pddf_fpgapci_driver", "pddf_xcvr_driver_module", "pddf_psu_driver_module", "pddf_psu_module", + "pddf_fpgai2c_module", + "pddf_fpgai2c_driver", "pddf_fan_driver_module", "pddf_fan_module", "pddf_led_module", @@ -51,7 +56,8 @@ ], "custom_kos": [ "x86-64-ufispace-s6301-56st-lpc", - "x86-64-ufispace-s6301-56st-sys-eeprom" + "x86-64-ufispace-s6301-56st-sys-eeprom", + "pddf_custom_psu" ] }, "SYSTEM": { @@ -861,7 +867,19 @@ { "itf":"pmbus", "dev":"PSU1-PMBUS" }, { "itf":"eeprom", "dev":"PSU1-EEPROM" } ] - } + }, + "bmc": { + "ipmitool": { + "attr_list": [ + { + "attr_name": "psu_present", + "bmc_cmd": "i2cget -y -f 2 0x58 0x0 > /dev/null 2>&1; [ $? -ne 0 ] && echo '0' || echo '1'", + "raw": "1", + "type": "raw" + } + ] + } + } }, "PSU1-PMBUS": { "dev_info": { @@ -877,16 +895,6 @@ "dev_type": "psu_pmbus" }, "attr_list": [ - { - "attr_name": "psu_present", - "attr_devaddr":"0x33", - "attr_devtype": "cpld", - "attr_devname":"CPLD1", - "attr_offset": "0x59", - "attr_mask": "0x1", - "attr_cmpval": "0x0", - "attr_len": "1" - }, { "attr_name": "psu_power_good", "attr_devaddr": "0x33", @@ -951,6 +959,24 @@ "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_v_out_max", + "attr_devaddr": "0x58", + "attr_devtype": "pmbus", + "attr_offset": "0xa5", + "attr_mask": "0x0", + "attr_cmpval": "0xff", + "attr_len": "2" + }, { "attr_name": "psu_i_out", "attr_devaddr": "0x58", @@ -969,6 +995,15 @@ "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_fan1_speed_rpm", "attr_devaddr": "0x58", @@ -1026,7 +1061,19 @@ { "itf":"pmbus", "dev":"PSU2-PMBUS" }, { "itf":"eeprom", "dev":"PSU2-EEPROM" } ] - } + }, + "bmc": { + "ipmitool": { + "attr_list": [ + { + "attr_name": "psu_present", + "bmc_cmd": "i2cget -y -f 2 0x59 0x0 > /dev/null 2>&1; [ $? -ne 0 ] && echo '0' || echo '1'", + "raw": "1", + "type": "raw" + } + ] + } + } }, "PSU2-PMBUS": { "dev_info": { @@ -1042,16 +1089,6 @@ "dev_type": "psu_pmbus" }, "attr_list": [ - { - "attr_name": "psu_present", - "attr_devaddr":"0x33", - "attr_devtype": "cpld", - "attr_devname":"CPLD1", - "attr_offset": "0x59", - "attr_mask": "0x2", - "attr_cmpval": "0x0", - "attr_len": "1" - }, { "attr_name": "psu_power_good", "attr_devaddr": "0x33", @@ -1116,6 +1153,24 @@ "attr_cmpval": "0xff", "attr_len": "2" }, + { + "attr_name": "psu_v_out_min", + "attr_devaddr": "0x59", + "attr_devtype": "pmbus", + "attr_offset": "0xa4", + "attr_mask": "0x0", + "attr_cmpval": "0xff", + "attr_len": "2" + }, + { + "attr_name": "psu_v_out_max", + "attr_devaddr": "0x59", + "attr_devtype": "pmbus", + "attr_offset": "0xa5", + "attr_mask": "0x0", + "attr_cmpval": "0xff", + "attr_len": "2" + }, { "attr_name": "psu_i_out", "attr_devaddr": "0x59", @@ -1134,6 +1189,15 @@ "attr_cmpval": "0xff", "attr_len": "2" }, + { + "attr_name": "psu_p_out_max", + "attr_devaddr": "0x59", + "attr_devtype": "pmbus", + "attr_offset": "0xa7", + "attr_mask": "0x0", + "attr_cmpval": "0xff", + "attr_len": "2" + }, { "attr_name": "psu_fan1_speed_rpm", "attr_devaddr": "0x59", @@ -1239,7 +1303,8 @@ "device_name": "SYS_LED" }, "dev_attr": { - "index": "0" + "index": "0", + "flag": "ro" }, "i2c": { "attr_list": [ @@ -1286,13 +1351,14 @@ ] } }, - "ID_LED": { + "LOC_LED": { "dev_info": { "device_type": "LED", "device_name": "LOC_LED" }, "dev_attr": { - "index": "0" + "index": "0", + "flag": "rw" }, "i2c": { "attr_list": [ @@ -1329,7 +1395,8 @@ "device_name": "FAN_LED" }, "dev_attr": { - "index": "0" + "index": "0", + "flag": "ro" }, "i2c": { "attr_list": [ @@ -1382,7 +1449,8 @@ "device_name": "PSU_LED" }, "dev_attr": { - "index": "1" + "index": "1", + "flag": "ro" }, "i2c": { "attr_list": [ @@ -1435,7 +1503,8 @@ "device_name": "PSU_LED" }, "dev_attr": { - "index": "0" + "index": "0", + "flag": "ro" }, "i2c": { "attr_list": [ diff --git a/device/ufispace/x86_64-ufispace_s6301_56st-r0/sensors.conf b/device/ufispace/x86_64-ufispace_s6301_56st-r0/sensors.conf deleted file mode 100644 index b1a69433405b..000000000000 --- a/device/ufispace/x86_64-ufispace_s6301_56st-r0/sensors.conf +++ /dev/null @@ -1 +0,0 @@ -# libsensors configuration file diff --git a/device/ufispace/x86_64-ufispace_s7801_54xs-r0/installer.conf b/device/ufispace/x86_64-ufispace_s7801_54xs-r0/installer.conf index 8f9944da69a6..74b02f076689 100644 --- a/device/ufispace/x86_64-ufispace_s7801_54xs-r0/installer.conf +++ b/device/ufispace/x86_64-ufispace_s7801_54xs-r0/installer.conf @@ -1,4 +1,4 @@ CONSOLE_PORT=0x3f8 CONSOLE_DEV=0 CONSOLE_SPEED=115200 -ONIE_PLATFORM_EXTRA_CMDLINE_LINUX="module_blacklist=gpio_ich nomodeset pcie_aspm=off" +ONIE_PLATFORM_EXTRA_CMDLINE_LINUX="modprobe.blacklist=gpio_ich,qat_c3xxx nomodeset pcie_aspm=off" diff --git a/device/ufispace/x86_64-ufispace_s7801_54xs-r0/pddf/pd-plugin.json b/device/ufispace/x86_64-ufispace_s7801_54xs-r0/pddf/pd-plugin.json index 81ff5e283bc9..842d9996a0ba 100644 --- a/device/ufispace/x86_64-ufispace_s7801_54xs-r0/pddf/pd-plugin.json +++ b/device/ufispace/x86_64-ufispace_s7801_54xs-r0/pddf/pd-plugin.json @@ -55,16 +55,19 @@ "psu_support_list": [ - {"Manufacturer": "FSPGROUP", "Name": "YNEB0450BM", "MaxSpd": "PSU_FAN_MAX_SPEED_AC"}, - {"Manufacturer": "FSPGROUP", "Name": "YNEB0450AM", "MaxSpd": "PSU_FAN_MAX_SPEED_DC"}, - {"Manufacturer": "DELTA", "Name": "DPS-450AB-27", "MaxSpd": "PSU_FAN_MAX_SPEED_AC"}, - {"Manufacturer": "DELTA", "Name": "DPS-450AB-28", "MaxSpd": "PSU_FAN_MAX_SPEED_DC"} + {"Manufacturer": "FSPGROUP", "Name": "YNEB0450BM", "MaxSpd": "PSU_FAN_MAX_SPEED_AC", "Type": "AC"}, + {"Manufacturer": "FSPGROUP", "Name": "YNEB0450AM", "MaxSpd": "PSU_FAN_MAX_SPEED_DC", "Type": "DC"}, + {"Manufacturer": "DELTA", "Name": "DPS-450AB-27", "MaxSpd": "PSU_FAN_MAX_SPEED_AC", "Type": "AC"}, + {"Manufacturer": "DELTA", "Name": "DPS-450AB-28", "MaxSpd": "PSU_FAN_MAX_SPEED_DC", "Type": "DC"}, + {"Manufacturer": "DELTA", "Name": "DPS-450AB-32", "MaxSpd": "PSU_FAN_MAX_SPEED_DC", "Type": "DC"}, + {"Manufacturer": "DELTA", "Name": "DPS-450AB-33", "MaxSpd": "PSU_FAN_MAX_SPEED_AC", "Type": "AC"} ], "valmap": { "PSU_FAN_MAX_SPEED":"20000", "PSU_FAN_MAX_SPEED_AC":"20000", - "PSU_FAN_MAX_SPEED_DC":"18000" + "PSU_FAN_MAX_SPEED_DC":"18000", + "DEFAULT_TYPE": "AC" } }, "FAN": diff --git a/device/ufispace/x86_64-ufispace_s7801_54xs-r0/pddf/pddf-device.json b/device/ufispace/x86_64-ufispace_s7801_54xs-r0/pddf/pddf-device.json index 7110b2ed6cc3..640a61800ed4 100644 --- a/device/ufispace/x86_64-ufispace_s7801_54xs-r0/pddf/pddf-device.json +++ b/device/ufispace/x86_64-ufispace_s7801_54xs-r0/pddf/pddf-device.json @@ -18,9 +18,11 @@ "pddf_xcvr" ] }, + "std_perm_kos": [ + "i2c-i801", + "i2c-ismt" + ], "std_kos": [ - "i2c_i801", - "i2c_ismt", "i2c_dev", "i2c_mux_pca954x", "coretemp", @@ -33,9 +35,12 @@ "pddf_cpld_driver", "pddf_mux_module", "pddf_xcvr_module", + "pddf_fpgapci_driver", "pddf_xcvr_driver_module", "pddf_psu_driver_module", "pddf_psu_module", + "pddf_fpgai2c_module", + "pddf_fpgai2c_driver", "pddf_fan_driver_module", "pddf_fan_module", "pddf_led_module", @@ -1907,6 +1912,24 @@ "bmc_cmd": "ipmitool raw 0x3c 0x30 0x0 | xargs | cut -d' ' -f1", "raw": "1", "type": "raw" + }, + { + "attr_name": "psu_v_in", + "bmc_cmd": "ipmitool sdr get -c PSU0_VIN | sed -e 's/,,/,N\\/A,/g' -e 's/,,/,N\\/A,/g'", + "raw": "0", + "separator": ",", + "field_name": "PSU0_VIN", + "field_pos": "2", + "mult": "1000" + }, + { + "attr_name": "psu_i_in", + "bmc_cmd": "ipmitool sdr get -c PSU0_IIN | sed -e 's/,,/,N\\/A,/g' -e 's/,,/,N\\/A,/g'", + "raw": "0", + "separator": ",", + "field_name": "PSU0_IIN", + "field_pos": "2", + "mult": "1000" } ] } @@ -2030,6 +2053,24 @@ "bmc_cmd": "ipmitool raw 0x3c 0x30 0x0 | xargs | cut -d' ' -f2", "raw": "1", "type": "raw" + }, + { + "attr_name": "psu_v_in", + "bmc_cmd": "ipmitool sdr get -c PSU1_VIN | sed -e 's/,,/,N\\/A,/g' -e 's/,,/,N\\/A,/g'", + "raw": "0", + "separator": ",", + "field_name": "PSU1_VIN", + "field_pos": "2", + "mult": "1000" + }, + { + "attr_name": "psu_i_in", + "bmc_cmd": "ipmitool sdr get -c PSU1_IIN | sed -e 's/,,/,N\\/A,/g' -e 's/,,/,N\\/A,/g'", + "raw": "0", + "separator": ",", + "field_name": "PSU1_IIN", + "field_pos": "2", + "mult": "1000" } ] } @@ -2463,7 +2504,7 @@ ] } }, - "ID_LED": { + "LOC_LED": { "dev_info": { "device_type": "LED", "device_name": "LOC_LED" diff --git a/device/ufispace/x86_64-ufispace_s7801_54xs-r0/sensors.conf b/device/ufispace/x86_64-ufispace_s7801_54xs-r0/sensors.conf deleted file mode 100644 index b1a69433405b..000000000000 --- a/device/ufispace/x86_64-ufispace_s7801_54xs-r0/sensors.conf +++ /dev/null @@ -1 +0,0 @@ -# libsensors configuration file diff --git a/device/ufispace/x86_64-ufispace_s8901_54xc-r0/installer.conf b/device/ufispace/x86_64-ufispace_s8901_54xc-r0/installer.conf index 8f9944da69a6..74b02f076689 100644 --- a/device/ufispace/x86_64-ufispace_s8901_54xc-r0/installer.conf +++ b/device/ufispace/x86_64-ufispace_s8901_54xc-r0/installer.conf @@ -1,4 +1,4 @@ CONSOLE_PORT=0x3f8 CONSOLE_DEV=0 CONSOLE_SPEED=115200 -ONIE_PLATFORM_EXTRA_CMDLINE_LINUX="module_blacklist=gpio_ich nomodeset pcie_aspm=off" +ONIE_PLATFORM_EXTRA_CMDLINE_LINUX="modprobe.blacklist=gpio_ich,qat_c3xxx nomodeset pcie_aspm=off" diff --git a/device/ufispace/x86_64-ufispace_s8901_54xc-r0/pddf/pd-plugin.json b/device/ufispace/x86_64-ufispace_s8901_54xc-r0/pddf/pd-plugin.json index 81ff5e283bc9..842d9996a0ba 100644 --- a/device/ufispace/x86_64-ufispace_s8901_54xc-r0/pddf/pd-plugin.json +++ b/device/ufispace/x86_64-ufispace_s8901_54xc-r0/pddf/pd-plugin.json @@ -55,16 +55,19 @@ "psu_support_list": [ - {"Manufacturer": "FSPGROUP", "Name": "YNEB0450BM", "MaxSpd": "PSU_FAN_MAX_SPEED_AC"}, - {"Manufacturer": "FSPGROUP", "Name": "YNEB0450AM", "MaxSpd": "PSU_FAN_MAX_SPEED_DC"}, - {"Manufacturer": "DELTA", "Name": "DPS-450AB-27", "MaxSpd": "PSU_FAN_MAX_SPEED_AC"}, - {"Manufacturer": "DELTA", "Name": "DPS-450AB-28", "MaxSpd": "PSU_FAN_MAX_SPEED_DC"} + {"Manufacturer": "FSPGROUP", "Name": "YNEB0450BM", "MaxSpd": "PSU_FAN_MAX_SPEED_AC", "Type": "AC"}, + {"Manufacturer": "FSPGROUP", "Name": "YNEB0450AM", "MaxSpd": "PSU_FAN_MAX_SPEED_DC", "Type": "DC"}, + {"Manufacturer": "DELTA", "Name": "DPS-450AB-27", "MaxSpd": "PSU_FAN_MAX_SPEED_AC", "Type": "AC"}, + {"Manufacturer": "DELTA", "Name": "DPS-450AB-28", "MaxSpd": "PSU_FAN_MAX_SPEED_DC", "Type": "DC"}, + {"Manufacturer": "DELTA", "Name": "DPS-450AB-32", "MaxSpd": "PSU_FAN_MAX_SPEED_DC", "Type": "DC"}, + {"Manufacturer": "DELTA", "Name": "DPS-450AB-33", "MaxSpd": "PSU_FAN_MAX_SPEED_AC", "Type": "AC"} ], "valmap": { "PSU_FAN_MAX_SPEED":"20000", "PSU_FAN_MAX_SPEED_AC":"20000", - "PSU_FAN_MAX_SPEED_DC":"18000" + "PSU_FAN_MAX_SPEED_DC":"18000", + "DEFAULT_TYPE": "AC" } }, "FAN": diff --git a/device/ufispace/x86_64-ufispace_s8901_54xc-r0/pddf/pddf-device.json b/device/ufispace/x86_64-ufispace_s8901_54xc-r0/pddf/pddf-device.json index 18d0dd9abe2b..2fb21d277e57 100644 --- a/device/ufispace/x86_64-ufispace_s8901_54xc-r0/pddf/pddf-device.json +++ b/device/ufispace/x86_64-ufispace_s8901_54xc-r0/pddf/pddf-device.json @@ -18,9 +18,11 @@ "pddf_xcvr" ] }, + "std_perm_kos": [ + "i2c-i801", + "i2c-ismt" + ], "std_kos": [ - "i2c_i801", - "i2c_ismt", "i2c_dev", "i2c_mux_pca954x", "coretemp", @@ -33,9 +35,12 @@ "pddf_cpld_driver", "pddf_mux_module", "pddf_xcvr_module", + "pddf_fpgapci_driver", "pddf_xcvr_driver_module", "pddf_psu_driver_module", "pddf_psu_module", + "pddf_fpgai2c_module", + "pddf_fpgai2c_driver", "pddf_fan_driver_module", "pddf_fan_module", "pddf_led_module", @@ -1907,6 +1912,24 @@ "bmc_cmd": "ipmitool raw 0x3c 0x30 0x0 | xargs | cut -d' ' -f1", "raw": "1", "type": "raw" + }, + { + "attr_name": "psu_v_in", + "bmc_cmd": "ipmitool sdr get -c PSU0_VIN | sed -e 's/,,/,N\\/A,/g' -e 's/,,/,N\\/A,/g'", + "raw": "0", + "separator": ",", + "field_name": "PSU0_VIN", + "field_pos": "2", + "mult": "1000" + }, + { + "attr_name": "psu_i_in", + "bmc_cmd": "ipmitool sdr get -c PSU0_IIN | sed -e 's/,,/,N\\/A,/g' -e 's/,,/,N\\/A,/g'", + "raw": "0", + "separator": ",", + "field_name": "PSU0_IIN", + "field_pos": "2", + "mult": "1000" } ] } @@ -2030,6 +2053,24 @@ "bmc_cmd": "ipmitool raw 0x3c 0x30 0x0 | xargs | cut -d' ' -f2", "raw": "1", "type": "raw" + }, + { + "attr_name": "psu_v_in", + "bmc_cmd": "ipmitool sdr get -c PSU1_VIN | sed -e 's/,,/,N\\/A,/g' -e 's/,,/,N\\/A,/g'", + "raw": "0", + "separator": ",", + "field_name": "PSU1_VIN", + "field_pos": "2", + "mult": "1000" + }, + { + "attr_name": "psu_i_in", + "bmc_cmd": "ipmitool sdr get -c PSU1_IIN | sed -e 's/,,/,N\\/A,/g' -e 's/,,/,N\\/A,/g'", + "raw": "0", + "separator": ",", + "field_name": "PSU1_IIN", + "field_pos": "2", + "mult": "1000" } ] } @@ -2463,7 +2504,7 @@ ] } }, - "ID_LED": { + "LOC_LED": { "dev_info": { "device_type": "LED", "device_name": "LOC_LED" diff --git a/device/ufispace/x86_64-ufispace_s8901_54xc-r0/sensors.conf b/device/ufispace/x86_64-ufispace_s8901_54xc-r0/sensors.conf deleted file mode 100644 index b1a69433405b..000000000000 --- a/device/ufispace/x86_64-ufispace_s8901_54xc-r0/sensors.conf +++ /dev/null @@ -1 +0,0 @@ -# libsensors configuration file diff --git a/device/ufispace/x86_64-ufispace_s9110_32x-r0/UFISPACE-S9110-32X/sai.profile b/device/ufispace/x86_64-ufispace_s9110_32x-r0/UFISPACE-S9110-32X/sai.profile old mode 100755 new mode 100644 diff --git a/device/ufispace/x86_64-ufispace_s9110_32x-r0/UFISPACE-S9110-32X/td3-x7-s9110-32x.config.bcm b/device/ufispace/x86_64-ufispace_s9110_32x-r0/UFISPACE-S9110-32X/td3-x7-s9110-32x.config.bcm old mode 100755 new mode 100644 diff --git a/device/ufispace/x86_64-ufispace_s9110_32x-r0/custom_led.bin b/device/ufispace/x86_64-ufispace_s9110_32x-r0/custom_led.bin old mode 100755 new mode 100644 diff --git a/device/ufispace/x86_64-ufispace_s9110_32x-r0/installer.conf b/device/ufispace/x86_64-ufispace_s9110_32x-r0/installer.conf index 8f9944da69a6..74b02f076689 100644 --- a/device/ufispace/x86_64-ufispace_s9110_32x-r0/installer.conf +++ b/device/ufispace/x86_64-ufispace_s9110_32x-r0/installer.conf @@ -1,4 +1,4 @@ CONSOLE_PORT=0x3f8 CONSOLE_DEV=0 CONSOLE_SPEED=115200 -ONIE_PLATFORM_EXTRA_CMDLINE_LINUX="module_blacklist=gpio_ich nomodeset pcie_aspm=off" +ONIE_PLATFORM_EXTRA_CMDLINE_LINUX="modprobe.blacklist=gpio_ich,qat_c3xxx nomodeset pcie_aspm=off" diff --git a/device/ufispace/x86_64-ufispace_s9110_32x-r0/led_proc_init.soc b/device/ufispace/x86_64-ufispace_s9110_32x-r0/led_proc_init.soc old mode 100755 new mode 100644 diff --git a/device/ufispace/x86_64-ufispace_s9110_32x-r0/pddf/pd-plugin.json b/device/ufispace/x86_64-ufispace_s9110_32x-r0/pddf/pd-plugin.json index 775f0c934f05..99e551ed2845 100644 --- a/device/ufispace/x86_64-ufispace_s9110_32x-r0/pddf/pd-plugin.json +++ b/device/ufispace/x86_64-ufispace_s9110_32x-r0/pddf/pd-plugin.json @@ -45,12 +45,12 @@ }, "psu_support_list": [ - {"Manufacturer": "FSPGROUP","Name": "YNEE0750EM", "MaxSpd": "PSU_AC_FAN_MAX_SPEED"}, - {"Manufacturer": "FSPGROUP","Name": "YNEE0750BM", "MaxSpd": "PSU_AC_FAN_MAX_SPEED"}, - {"Manufacturer": "FSPGROUP","Name": "YNEE0750AM", "MaxSpd": "PSU_DC_FAN_MAX_SPEED"} + {"Manufacturer": "FSPGROUP","Name": "YNEE0750EM", "MaxSpd": "PSU_AC_FAN_MAX_SPEED", "Type":"AC"}, + {"Manufacturer": "FSPGROUP","Name": "YNEE0750BM", "MaxSpd": "PSU_AC_FAN_MAX_SPEED", "Type":"AC"}, + {"Manufacturer": "FSPGROUP","Name": "YNEE0750AM", "MaxSpd": "PSU_DC_FAN_MAX_SPEED", "Type":"DC"} ], - "valmap": {"PSU_AC_FAN_MAX_SPEED": "26500", "PSU_DC_FAN_MAX_SPEED":"29000"} + "valmap": {"PSU_AC_FAN_MAX_SPEED": "26500", "PSU_DC_FAN_MAX_SPEED":"29000", "DEFAULT_TYPE": "AC"} }, "FAN": diff --git a/device/ufispace/x86_64-ufispace_s9110_32x-r0/pddf/pddf-device-beta.json b/device/ufispace/x86_64-ufispace_s9110_32x-r0/pddf/pddf-device-beta.json index d55cf071f5c3..aafa6cc81447 100644 --- a/device/ufispace/x86_64-ufispace_s9110_32x-r0/pddf/pddf-device-beta.json +++ b/device/ufispace/x86_64-ufispace_s9110_32x-r0/pddf/pddf-device-beta.json @@ -18,9 +18,11 @@ "pddf_xcvr" ] }, + "std_perm_kos": [ + "i2c-i801", + "i2c-ismt" + ], "std_kos": [ - "i2c_i801", - "i2c-ismt", "i2c_dev", "i2c_mux_pca954x", "optoe" @@ -31,9 +33,12 @@ "pddf_cpld_driver", "pddf_mux_module", "pddf_xcvr_module", + "pddf_fpgapci_driver", "pddf_xcvr_driver_module", "pddf_psu_driver_module", "pddf_psu_module", + "pddf_fpgai2c_module", + "pddf_fpgai2c_driver", "pddf_fan_driver_module", "pddf_fan_module", "pddf_led_module" @@ -65,7 +70,7 @@ }, "SMBUS1": { "dev_info": { - "device_type": "SMBUS", "device_name": "SMBUS1", "device_parent": "SYSTEM" + "device_type": "SMBUS", "device_name": "SMBUS1", "device_parent": "SYSTEM" }, "i2c": { "topo_info": { @@ -752,6 +757,24 @@ "bmc_cmd": "ipmitool raw 0x3c 0x30 0x0 | xargs | cut -d' ' -f1", "raw": "1", "type": "raw" + }, + { + "attr_name": "psu_v_in", + "bmc_cmd": "ipmitool sdr get -c PSU0_VIN | sed -e 's/,,/,N\\/A,/g' -e 's/,,/,N\\/A,/g'", + "raw": "0", + "separator": ",", + "field_name": "PSU0_VIN", + "field_pos": "2", + "mult": "1000" + }, + { + "attr_name": "psu_i_in", + "bmc_cmd": "ipmitool sdr get -c PSU0_IIN | sed -e 's/,,/,N\\/A,/g' -e 's/,,/,N\\/A,/g'", + "raw": "0", + "separator": ",", + "field_name": "PSU0_IIN", + "field_pos": "2", + "mult": "1000" } ] } @@ -875,6 +898,24 @@ "bmc_cmd": "ipmitool raw 0x3c 0x30 0x0 | xargs | cut -d' ' -f2", "raw": "1", "type": "raw" + }, + { + "attr_name": "psu_v_in", + "bmc_cmd": "ipmitool sdr get -c PSU1_VIN | sed -e 's/,,/,N\\/A,/g' -e 's/,,/,N\\/A,/g'", + "raw": "0", + "separator": ",", + "field_name": "PSU1_VIN", + "field_pos": "2", + "mult": "1000" + }, + { + "attr_name": "psu_i_in", + "bmc_cmd": "ipmitool sdr get -c PSU1_IIN | sed -e 's/,,/,N\\/A,/g' -e 's/,,/,N\\/A,/g'", + "raw": "0", + "separator": ",", + "field_name": "PSU1_IIN", + "field_pos": "2", + "mult": "1000" } ] } @@ -1320,7 +1361,7 @@ ] } }, - "ID_LED": { + "LOC_LED": { "dev_info": { "device_type": "LED", "device_name": "LOC_LED" @@ -1360,7 +1401,7 @@ }, "PORT1": { "dev_info": { - "device_type": "QSFP", + "device_type": "QSFP28", "device_name": "PORT1", "device_parent": "MUX3" }, @@ -1459,7 +1500,7 @@ }, "PORT2": { "dev_info": { - "device_type": "QSFP", + "device_type": "QSFP28", "device_name": "PORT2", "device_parent": "MUX3" }, @@ -1558,7 +1599,7 @@ }, "PORT3": { "dev_info": { - "device_type": "QSFP", + "device_type": "QSFP28", "device_name": "PORT3", "device_parent": "MUX3" }, @@ -1657,7 +1698,7 @@ }, "PORT4": { "dev_info": { - "device_type": "QSFP", + "device_type": "QSFP28", "device_name": "PORT4", "device_parent": "MUX3" }, @@ -1756,7 +1797,7 @@ }, "PORT5": { "dev_info": { - "device_type": "QSFP", + "device_type": "QSFP28", "device_name": "PORT5", "device_parent": "MUX3" }, @@ -1855,7 +1896,7 @@ }, "PORT6": { "dev_info": { - "device_type": "QSFP", + "device_type": "QSFP28", "device_name": "PORT6", "device_parent": "MUX3" }, @@ -1954,7 +1995,7 @@ }, "PORT7": { "dev_info": { - "device_type": "QSFP", + "device_type": "QSFP28", "device_name": "PORT7", "device_parent": "MUX3" }, @@ -2053,7 +2094,7 @@ }, "PORT8": { "dev_info": { - "device_type": "QSFP", + "device_type": "QSFP28", "device_name": "PORT8", "device_parent": "MUX3" }, @@ -2152,7 +2193,7 @@ }, "PORT9": { "dev_info": { - "device_type": "QSFP", + "device_type": "QSFP28", "device_name": "PORT9", "device_parent": "MUX4" }, @@ -2251,7 +2292,7 @@ }, "PORT10": { "dev_info": { - "device_type": "QSFP", + "device_type": "QSFP28", "device_name": "PORT10", "device_parent": "MUX4" }, @@ -2350,7 +2391,7 @@ }, "PORT11": { "dev_info": { - "device_type": "QSFP", + "device_type": "QSFP28", "device_name": "PORT11", "device_parent": "MUX4" }, @@ -2449,7 +2490,7 @@ }, "PORT12": { "dev_info": { - "device_type": "QSFP", + "device_type": "QSFP28", "device_name": "PORT12", "device_parent": "MUX4" }, @@ -2548,7 +2589,7 @@ }, "PORT13": { "dev_info": { - "device_type": "QSFP", + "device_type": "QSFP28", "device_name": "PORT13", "device_parent": "MUX4" }, @@ -2647,7 +2688,7 @@ }, "PORT14": { "dev_info": { - "device_type": "QSFP", + "device_type": "QSFP28", "device_name": "PORT14", "device_parent": "MUX4" }, @@ -2746,7 +2787,7 @@ }, "PORT15": { "dev_info": { - "device_type": "QSFP", + "device_type": "QSFP28", "device_name": "PORT15", "device_parent": "MUX4" }, @@ -2845,7 +2886,7 @@ }, "PORT16": { "dev_info": { - "device_type": "QSFP", + "device_type": "QSFP28", "device_name": "PORT16", "device_parent": "MUX4" }, @@ -2944,7 +2985,7 @@ }, "PORT17": { "dev_info": { - "device_type": "QSFP", + "device_type": "QSFP28", "device_name": "PORT17", "device_parent": "MUX5" }, @@ -3043,7 +3084,7 @@ }, "PORT18": { "dev_info": { - "device_type": "QSFP", + "device_type": "QSFP28", "device_name": "PORT18", "device_parent": "MUX5" }, @@ -3142,7 +3183,7 @@ }, "PORT19": { "dev_info": { - "device_type": "QSFP", + "device_type": "QSFP28", "device_name": "PORT19", "device_parent": "MUX5" }, @@ -3241,7 +3282,7 @@ }, "PORT20": { "dev_info": { - "device_type": "QSFP", + "device_type": "QSFP28", "device_name": "PORT20", "device_parent": "MUX5" }, @@ -3340,7 +3381,7 @@ }, "PORT21": { "dev_info": { - "device_type": "QSFP", + "device_type": "QSFP28", "device_name": "PORT21", "device_parent": "MUX5" }, @@ -3439,7 +3480,7 @@ }, "PORT22": { "dev_info": { - "device_type": "QSFP", + "device_type": "QSFP28", "device_name": "PORT22", "device_parent": "MUX5" }, @@ -3538,7 +3579,7 @@ }, "PORT23": { "dev_info": { - "device_type": "QSFP", + "device_type": "QSFP28", "device_name": "PORT23", "device_parent": "MUX5" }, @@ -3635,17 +3676,17 @@ ] } }, - "PORT24": { - "dev_info": { - "device_type": "QSFP", - "device_name": "PORT24", - "device_parent": "MUX5" - }, - "dev_attr": { - "dev_idx": "24" - }, - "i2c": { - "interface": [ + "PORT24": { + "dev_info": { + "device_type": "QSFP28", + "device_name": "PORT24", + "device_parent": "MUX5" + }, + "dev_attr": { + "dev_idx": "24" + }, + "i2c": { + "interface": [ { "itf": "eeprom", "dev": "PORT24-EEPROM" @@ -3654,9 +3695,9 @@ "itf": "control", "dev": "PORT24-CTRL" } - ] - } - }, + ] + } + }, "PORT24-EEPROM": { "dev_info": { "device_type": "", @@ -3736,7 +3777,7 @@ }, "PORT25": { "dev_info": { - "device_type": "QSFP", + "device_type": "QSFP28", "device_name": "PORT25", "device_parent": "MUX6" }, @@ -3835,7 +3876,7 @@ }, "PORT26": { "dev_info": { - "device_type": "QSFP", + "device_type": "QSFP28", "device_name": "PORT26", "device_parent": "MUX6" }, @@ -3934,7 +3975,7 @@ }, "PORT27": { "dev_info": { - "device_type": "QSFP", + "device_type": "QSFP28", "device_name": "PORT27", "device_parent": "MUX6" }, @@ -4033,7 +4074,7 @@ }, "PORT28": { "dev_info": { - "device_type": "QSFP", + "device_type": "QSFP28", "device_name": "PORT28", "device_parent": "MUX6" }, @@ -4132,7 +4173,7 @@ }, "PORT29": { "dev_info": { - "device_type": "QSFP", + "device_type": "QSFP28", "device_name": "PORT29", "device_parent": "MUX6" }, @@ -4231,7 +4272,7 @@ }, "PORT30": { "dev_info": { - "device_type": "QSFP", + "device_type": "QSFP28", "device_name": "PORT30", "device_parent": "MUX6" }, @@ -4330,7 +4371,7 @@ }, "PORT31": { "dev_info": { - "device_type": "QSFP", + "device_type": "QSFP28", "device_name": "PORT31", "device_parent": "MUX6" }, @@ -4429,7 +4470,7 @@ }, "PORT32": { "dev_info": { - "device_type": "QSFP", + "device_type": "QSFP28", "device_name": "PORT32", "device_parent": "MUX6" }, diff --git a/device/ufispace/x86_64-ufispace_s9110_32x-r0/pddf/pddf-device-pvt.json b/device/ufispace/x86_64-ufispace_s9110_32x-r0/pddf/pddf-device-pvt.json index 4f86b045c858..dec149491308 100644 --- a/device/ufispace/x86_64-ufispace_s9110_32x-r0/pddf/pddf-device-pvt.json +++ b/device/ufispace/x86_64-ufispace_s9110_32x-r0/pddf/pddf-device-pvt.json @@ -18,9 +18,11 @@ "pddf_xcvr" ] }, + "std_perm_kos": [ + "i2c-i801", + "i2c-ismt" + ], "std_kos": [ - "i2c_i801", - "i2c-ismt", "i2c_dev", "i2c_mux_pca954x", "optoe" @@ -31,9 +33,12 @@ "pddf_cpld_driver", "pddf_mux_module", "pddf_xcvr_module", + "pddf_fpgapci_driver", "pddf_xcvr_driver_module", "pddf_psu_driver_module", "pddf_psu_module", + "pddf_fpgai2c_module", + "pddf_fpgai2c_driver", "pddf_fan_driver_module", "pddf_fan_module", "pddf_led_module" @@ -65,7 +70,7 @@ }, "SMBUS1": { "dev_info": { - "device_type": "SMBUS", "device_name": "SMBUS1", "device_parent": "SYSTEM" + "device_type": "SMBUS", "device_name": "SMBUS1", "device_parent": "SYSTEM" }, "i2c": { "topo_info": { @@ -752,6 +757,24 @@ "bmc_cmd": "ipmitool raw 0x3c 0x30 0x0 | xargs | cut -d' ' -f1", "raw": "1", "type": "raw" + }, + { + "attr_name": "psu_v_in", + "bmc_cmd": "ipmitool sdr get -c PSU0_VIN | sed -e 's/,,/,N\\/A,/g' -e 's/,,/,N\\/A,/g'", + "raw": "0", + "separator": ",", + "field_name": "PSU0_VIN", + "field_pos": "2", + "mult": "1000" + }, + { + "attr_name": "psu_i_in", + "bmc_cmd": "ipmitool sdr get -c PSU0_IIN | sed -e 's/,,/,N\\/A,/g' -e 's/,,/,N\\/A,/g'", + "raw": "0", + "separator": ",", + "field_name": "PSU0_IIN", + "field_pos": "2", + "mult": "1000" } ] } @@ -875,6 +898,24 @@ "bmc_cmd": "ipmitool raw 0x3c 0x30 0x0 | xargs | cut -d' ' -f2", "raw": "1", "type": "raw" + }, + { + "attr_name": "psu_v_in", + "bmc_cmd": "ipmitool sdr get -c PSU1_VIN | sed -e 's/,,/,N\\/A,/g' -e 's/,,/,N\\/A,/g'", + "raw": "0", + "separator": ",", + "field_name": "PSU1_VIN", + "field_pos": "2", + "mult": "1000" + }, + { + "attr_name": "psu_i_in", + "bmc_cmd": "ipmitool sdr get -c PSU1_IIN | sed -e 's/,,/,N\\/A,/g' -e 's/,,/,N\\/A,/g'", + "raw": "0", + "separator": ",", + "field_name": "PSU1_IIN", + "field_pos": "2", + "mult": "1000" } ] } @@ -1276,7 +1317,7 @@ ] } }, - "ID_LED": { + "LOC_LED": { "dev_info": { "device_type": "LED", "device_name": "LOC_LED" @@ -1316,7 +1357,7 @@ }, "PORT1": { "dev_info": { - "device_type": "QSFP", + "device_type": "QSFP28", "device_name": "PORT1", "device_parent": "MUX3" }, @@ -1415,7 +1456,7 @@ }, "PORT2": { "dev_info": { - "device_type": "QSFP", + "device_type": "QSFP28", "device_name": "PORT2", "device_parent": "MUX3" }, @@ -1514,7 +1555,7 @@ }, "PORT3": { "dev_info": { - "device_type": "QSFP", + "device_type": "QSFP28", "device_name": "PORT3", "device_parent": "MUX3" }, @@ -1613,7 +1654,7 @@ }, "PORT4": { "dev_info": { - "device_type": "QSFP", + "device_type": "QSFP28", "device_name": "PORT4", "device_parent": "MUX3" }, @@ -1712,7 +1753,7 @@ }, "PORT5": { "dev_info": { - "device_type": "QSFP", + "device_type": "QSFP28", "device_name": "PORT5", "device_parent": "MUX3" }, @@ -1811,7 +1852,7 @@ }, "PORT6": { "dev_info": { - "device_type": "QSFP", + "device_type": "QSFP28", "device_name": "PORT6", "device_parent": "MUX3" }, @@ -1910,7 +1951,7 @@ }, "PORT7": { "dev_info": { - "device_type": "QSFP", + "device_type": "QSFP28", "device_name": "PORT7", "device_parent": "MUX3" }, @@ -2009,7 +2050,7 @@ }, "PORT8": { "dev_info": { - "device_type": "QSFP", + "device_type": "QSFP28", "device_name": "PORT8", "device_parent": "MUX3" }, @@ -2108,7 +2149,7 @@ }, "PORT9": { "dev_info": { - "device_type": "QSFP", + "device_type": "QSFP28", "device_name": "PORT9", "device_parent": "MUX4" }, @@ -2207,7 +2248,7 @@ }, "PORT10": { "dev_info": { - "device_type": "QSFP", + "device_type": "QSFP28", "device_name": "PORT10", "device_parent": "MUX4" }, @@ -2306,7 +2347,7 @@ }, "PORT11": { "dev_info": { - "device_type": "QSFP", + "device_type": "QSFP28", "device_name": "PORT11", "device_parent": "MUX4" }, @@ -2405,7 +2446,7 @@ }, "PORT12": { "dev_info": { - "device_type": "QSFP", + "device_type": "QSFP28", "device_name": "PORT12", "device_parent": "MUX4" }, @@ -2504,7 +2545,7 @@ }, "PORT13": { "dev_info": { - "device_type": "QSFP", + "device_type": "QSFP28", "device_name": "PORT13", "device_parent": "MUX4" }, @@ -2603,7 +2644,7 @@ }, "PORT14": { "dev_info": { - "device_type": "QSFP", + "device_type": "QSFP28", "device_name": "PORT14", "device_parent": "MUX4" }, @@ -2702,7 +2743,7 @@ }, "PORT15": { "dev_info": { - "device_type": "QSFP", + "device_type": "QSFP28", "device_name": "PORT15", "device_parent": "MUX4" }, @@ -2801,7 +2842,7 @@ }, "PORT16": { "dev_info": { - "device_type": "QSFP", + "device_type": "QSFP28", "device_name": "PORT16", "device_parent": "MUX4" }, @@ -2900,7 +2941,7 @@ }, "PORT17": { "dev_info": { - "device_type": "QSFP", + "device_type": "QSFP28", "device_name": "PORT17", "device_parent": "MUX5" }, @@ -2999,7 +3040,7 @@ }, "PORT18": { "dev_info": { - "device_type": "QSFP", + "device_type": "QSFP28", "device_name": "PORT18", "device_parent": "MUX5" }, @@ -3098,7 +3139,7 @@ }, "PORT19": { "dev_info": { - "device_type": "QSFP", + "device_type": "QSFP28", "device_name": "PORT19", "device_parent": "MUX5" }, @@ -3197,7 +3238,7 @@ }, "PORT20": { "dev_info": { - "device_type": "QSFP", + "device_type": "QSFP28", "device_name": "PORT20", "device_parent": "MUX5" }, @@ -3296,7 +3337,7 @@ }, "PORT21": { "dev_info": { - "device_type": "QSFP", + "device_type": "QSFP28", "device_name": "PORT21", "device_parent": "MUX5" }, @@ -3395,7 +3436,7 @@ }, "PORT22": { "dev_info": { - "device_type": "QSFP", + "device_type": "QSFP28", "device_name": "PORT22", "device_parent": "MUX5" }, @@ -3494,7 +3535,7 @@ }, "PORT23": { "dev_info": { - "device_type": "QSFP", + "device_type": "QSFP28", "device_name": "PORT23", "device_parent": "MUX5" }, @@ -3591,17 +3632,17 @@ ] } }, - "PORT24": { - "dev_info": { - "device_type": "QSFP", - "device_name": "PORT24", - "device_parent": "MUX5" - }, - "dev_attr": { - "dev_idx": "24" - }, - "i2c": { - "interface": [ + "PORT24": { + "dev_info": { + "device_type": "QSFP28", + "device_name": "PORT24", + "device_parent": "MUX5" + }, + "dev_attr": { + "dev_idx": "24" + }, + "i2c": { + "interface": [ { "itf": "eeprom", "dev": "PORT24-EEPROM" @@ -3610,9 +3651,9 @@ "itf": "control", "dev": "PORT24-CTRL" } - ] - } - }, + ] + } + }, "PORT24-EEPROM": { "dev_info": { "device_type": "", @@ -3692,7 +3733,7 @@ }, "PORT25": { "dev_info": { - "device_type": "QSFP", + "device_type": "QSFP28", "device_name": "PORT25", "device_parent": "MUX6" }, @@ -3791,7 +3832,7 @@ }, "PORT26": { "dev_info": { - "device_type": "QSFP", + "device_type": "QSFP28", "device_name": "PORT26", "device_parent": "MUX6" }, @@ -3890,7 +3931,7 @@ }, "PORT27": { "dev_info": { - "device_type": "QSFP", + "device_type": "QSFP28", "device_name": "PORT27", "device_parent": "MUX6" }, @@ -3989,7 +4030,7 @@ }, "PORT28": { "dev_info": { - "device_type": "QSFP", + "device_type": "QSFP28", "device_name": "PORT28", "device_parent": "MUX6" }, @@ -4088,7 +4129,7 @@ }, "PORT29": { "dev_info": { - "device_type": "QSFP", + "device_type": "QSFP28", "device_name": "PORT29", "device_parent": "MUX6" }, @@ -4187,7 +4228,7 @@ }, "PORT30": { "dev_info": { - "device_type": "QSFP", + "device_type": "QSFP28", "device_name": "PORT30", "device_parent": "MUX6" }, @@ -4286,7 +4327,7 @@ }, "PORT31": { "dev_info": { - "device_type": "QSFP", + "device_type": "QSFP28", "device_name": "PORT31", "device_parent": "MUX6" }, @@ -4385,7 +4426,7 @@ }, "PORT32": { "dev_info": { - "device_type": "QSFP", + "device_type": "QSFP28", "device_name": "PORT32", "device_parent": "MUX6" }, diff --git a/device/ufispace/x86_64-ufispace_s9110_32x-r0/sensors.conf b/device/ufispace/x86_64-ufispace_s9110_32x-r0/sensors.conf deleted file mode 100644 index 29e3604b4127..000000000000 --- a/device/ufispace/x86_64-ufispace_s9110_32x-r0/sensors.conf +++ /dev/null @@ -1 +0,0 @@ -# libsensors configuration file \ No newline at end of file diff --git a/device/ufispace/x86_64-ufispace_s9300_32d-r0/UFISPACE-S9300-32D/td4-s9300-32x400G.config.yml b/device/ufispace/x86_64-ufispace_s9300_32d-r0/UFISPACE-S9300-32D/td4-s9300-32x400G.config.yml index a661adfdc4a4..703d0d1091b5 100644 --- a/device/ufispace/x86_64-ufispace_s9300_32d-r0/UFISPACE-S9300-32D/td4-s9300-32x400G.config.yml +++ b/device/ufispace/x86_64-ufispace_s9300_32d-r0/UFISPACE-S9300-32D/td4-s9300-32x400G.config.yml @@ -1,4 +1,4 @@ -#r1.0.0 +#r1.0.1 # # BCM56880 32x400g port configuration. # @@ -26,7 +26,6 @@ device: CORE_CLK_FREQ: CLK_1350MHZ # PP CLOCK FREQUENCY PP_CLK_FREQ: CLK_1350MHZ - VARIANT: DNA_4_9_5_0 ... --- device: @@ -35,12 +34,6 @@ device: FP_ING_OPERMODE: GLOBAL_PIPE_AWARE ... --- -device: - 0: - TM_SCHEDULER_CONFIG: - NUM_MC_Q: NUM_MC_Q_4 -... ---- bcm_device: 0: global: diff --git a/device/ufispace/x86_64-ufispace_s9300_32d-r0/custom_led.bin b/device/ufispace/x86_64-ufispace_s9300_32d-r0/custom_led.bin index 1cbd43d6a5f1d6e1da31a2b34dbe7888311c98b0..968e54a03e12a9bc347fef7dfde01c14da67b15b 100644 GIT binary patch literal 716 zcmYk(Ur1A70EY4N9W}8LA`%wM3`#Y#;E2cNak}M#UG$hWp4}m3i$7Es$lm(?s((b9Wun;Ln(EpYS=Xh1usUJ! z|21oK75TS@V-Hx_pCZB$u2(c+r08x#)h%Pv2%p)Z3A0jjnwA+hPiVs1t~tGyH|z~K zR9}a~<+FUYMKK^{iEAdJ>eJDGJx9NZs=?T2H{|NXb2(M0C_+(`7{nnS39w-s5|M;t zY)1-q!j4p=L4%GA>_HaxA{YCShXNeLArzq)hfxYA+&GGIRNxqnqY_o9#z~w)E$VO@ z9vCp;LjxMogtKVIIh@A@wBRBxp$+ZmfQ2jQL>Ibo4cBoKJ?KRr`Z0jpxP!YG#1QV` zJ|5s99^o;bU=&X=hH*?Fgh{->OT5BsOk)PKh+rOX@eUubfRFf$FId7?M6rx-_>L9) Tz)!5<7k=Xp{$d?M@IN*H$)APp literal 356 zcmYkyJxBs!9LMqJQG3y;cPONM?lMq`kP0dqx=a6H&`@FYLfE|sS6f?+*${0xN>fdB z(oob8*dVtQEnbsBgH6&9*w|#hwuaC0<=eQ=&?+rbf*N;$ARFd#JjF-6;Uam$HucV3 zQZ$%Wca<%&2lAw^r3bHBoAtFBigi?vtrF=8KGU_|r%t*}$yc+bB(YIeX-Y{;U-8%e z9}ygXm5-m@`X=O9)#b9Y%>>t4Bvosda#~q)^j5)*ZlM@C!!ddUH;05`=1j*7$=yA4P*i<#ZRw@HKp7fSU)^P@)MrblRGI_=Iox0nQoo!Y>}STr2

/dev/null | tr -s ' ' | cut -d' ' -f3-5 | grep 'Manufacturer') && echo $_rv || echo 'Manufacturer : N/A'", "raw": "0", + "separator": ":", "field_name": "Manufacturer", - "field_pos": "3", - "delimiter": ":" + "field_pos": "2" }, { "attr_name": "psu_model_name", - "bmc_cmd": "ipmitool fru print 1 | tr -s ' ' | cut -d' ' -f3-5", + "bmc_cmd": "_rv=$(ipmitool fru print 1 2>/dev/null | tr -s ' ' | cut -d' ' -f3-5 | grep 'Name') && echo $_rv || echo 'Name : N/A'", "raw": "0", + "separator": ":", "field_name": "Name", - "field_pos": "3", - "delimiter": ":" + "field_pos": "2" }, { "attr_name": "psu_serial_num", - "bmc_cmd": "ipmitool fru print 1 | tr -s ' ' | cut -d' ' -f3-5", + "bmc_cmd": "_rv=$(ipmitool fru print 1 2>/dev/null | tr -s ' ' | cut -d' ' -f3-5 | grep 'Serial') && echo $_rv || echo 'Serial : N/A'", "raw": "0", + "separator": ":", "field_name": "Serial", - "field_pos": "3", - "delimiter": ":" + "field_pos": "2" }, { "attr_name": "psu_fan1_dir", @@ -1211,72 +1193,96 @@ "attr_list": [ { "attr_name": "psu_present", - "bmc_cmd": "ipmitool sensor", + "bmc_cmd": "ipmitool sdr -c get PSU1_PRSNT_L | sed -e 's/,,/,N\\/A,/g' -e 's/,,/,N\\/A,/g'", "raw": "0", "field_name": "PSU1_PRSNT_L", - "field_pos": "7" + "field_pos": "5", + "separator": "," }, { "attr_name": "psu_power_good", - "bmc_cmd": "ipmitool sensor", + "bmc_cmd": "ipmitool sdr -c get PSU1_PWROK_H | sed -e 's/,,/,N\\/A,/g' -e 's/,,/,N\\/A,/g'", "raw": "0", "field_name": "PSU1_PWROK_H", - "field_pos": "7" + "field_pos": "5", + "separator": "," }, { "attr_name": "psu_v_out", - "bmc_cmd": "ipmitool sensor", + "bmc_cmd": "ipmitool sdr -c get PSU1_VOUT | sed -e 's/,,/,N\\/A,/g' -e 's/,,/,N\\/A,/g'", "raw": "0", "field_name": "PSU1_VOUT", - "field_pos": "3", - "mult": "1000" + "field_pos": "2", + "mult": "1000", + "separator": "," }, { "attr_name": "psu_i_out", - "bmc_cmd": "ipmitool sensor", + "bmc_cmd": "ipmitool sdr -c get PSU1_IOUT | sed -e 's/,,/,N\\/A,/g' -e 's/,,/,N\\/A,/g'", "raw": "0", "field_name": "PSU1_IOUT", - "field_pos": "3", + "field_pos": "2", + "mult": "1000", + "separator": "," + }, + { + "attr_name": "psu_v_in", + "bmc_cmd": "ipmitool sdr get -c PSU1_VIN | sed -e 's/,,/,N\\/A,/g' -e 's/,,/,N\\/A,/g'", + "raw": "0", + "separator": ",", + "field_name": "PSU1_VIN", + "field_pos": "2", + "mult": "1000" + }, + { + "attr_name": "psu_i_in", + "bmc_cmd": "ipmitool sdr get -c PSU1_IIN | sed -e 's/,,/,N\\/A,/g' -e 's/,,/,N\\/A,/g'", + "raw": "0", + "separator": ",", + "field_name": "PSU1_IIN", + "field_pos": "2", "mult": "1000" }, { "attr_name": "psu_temp1_input", - "bmc_cmd": "ipmitool sensor", + "bmc_cmd": "ipmitool sdr -c get PSU1_TEMP | sed -e 's/,,/,N\\/A,/g' -e 's/,,/,N\\/A,/g'", "raw": "0", "field_name": "PSU1_TEMP", - "field_pos": "3", - "mult": "1000" + "field_pos": "2", + "mult": "1000", + "separator": "," }, { "attr_name": "psu_fan1_speed_rpm", - "bmc_cmd": "ipmitool sensor", + "bmc_cmd": "ipmitool sdr -c get PSU1_FAN1 | sed -e 's/,,/,N\\/A,/g' -e 's/,,/,N\\/A,/g'", "raw": "0", "field_name": "PSU1_FAN1", - "field_pos": "3" + "field_pos": "2", + "separator": "," }, { "attr_name": "psu_mfr_id", - "bmc_cmd": "ipmitool fru print 2 | tr -s ' ' | cut -d' ' -f3-5", + "bmc_cmd": "_rv=$(ipmitool fru print 2 2>/dev/null | tr -s ' ' | cut -d' ' -f3-5 | grep 'Manufacturer') && echo $_rv || echo 'Manufacturer : N/A'", "raw": "0", + "separator": ":", "field_name": "Manufacturer", - "field_pos": "3", - "delimiter": ":" + "field_pos": "2" }, { "attr_name": "psu_model_name", - "bmc_cmd": "ipmitool fru print 2 | tr -s ' ' | cut -d' ' -f3-5", + "bmc_cmd": "_rv=$(ipmitool fru print 2 2>/dev/null | tr -s ' ' | cut -d' ' -f3-5 | grep 'Name') && echo $_rv || echo 'Name : N/A'", "raw": "0", + "separator": ":", "field_name": "Name", - "field_pos": "3", - "delimiter": ":" + "field_pos": "2" }, { "attr_name": "psu_serial_num", - "bmc_cmd": "ipmitool fru print 2 | tr -s ' ' | cut -d' ' -f3-5", + "bmc_cmd": "_rv=$(ipmitool fru print 2 2>/dev/null | tr -s ' ' | cut -d' ' -f3-5 | grep 'Serial') && echo $_rv || echo 'Serial : N/A'", "raw": "0", + "separator": ":", "field_name": "Serial", - "field_pos": "3", - "delimiter": ":" + "field_pos": "2" }, { "attr_name": "psu_fan1_dir", @@ -1679,7 +1685,7 @@ ] } }, - "ID_LED": { + "LOC_LED": { "dev_info": { "device_type": "LED", "device_name": "LOC_LED" diff --git a/device/ufispace/x86_64-ufispace_s9300_32d-r0/platform_components.json b/device/ufispace/x86_64-ufispace_s9300_32d-r0/platform_components.json new file mode 100644 index 000000000000..30f8635ca822 --- /dev/null +++ b/device/ufispace/x86_64-ufispace_s9300_32d-r0/platform_components.json @@ -0,0 +1,13 @@ +{ + "chassis": { + "x86_64-ufispace_s9300_32d-r0": { + "component": { + "CPLD1": { }, + "CPLD2": { }, + "CPLD3": { }, + "BIOS": { }, + "BMC": {} + } + } + } +} diff --git a/platform/broadcom/one-image.mk b/platform/broadcom/one-image.mk index c9660299ed7e..0803216aa986 100755 --- a/platform/broadcom/one-image.mk +++ b/platform/broadcom/one-image.mk @@ -82,11 +82,11 @@ $(SONIC_ONE_IMAGE)_LAZY_INSTALLS += $(DELL_S6000_PLATFORM_MODULE) \ $(NOKIA_IXR7250_PLATFORM_MODULE) \ $(TENCENT_TCS8400_PLATFORM_MODULE) \ $(TENCENT_TCS9400_PLATFORM_MODULE) \ - $(UFISPACE_S9300_32D_PLATFORM_MODULE) \ - $(UFISPACE_S9110_32X_PLATFORM_MODULE) \ - $(UFISPACE_S8901_54XC_PLATFORM_MODULE) \ + $(UFISPACE_S6301_56ST_PLATFORM_MODULE) \ $(UFISPACE_S7801_54XS_PLATFORM_MODULE) \ - $(UFISPACE_S6301_56ST_PLATFORM_MODULE) + $(UFISPACE_S8901_54XC_PLATFORM_MODULE) \ + $(UFISPACE_S9110_32X_PLATFORM_MODULE) \ + $(UFISPACE_S9300_32D_PLATFORM_MODULE) $(SONIC_ONE_IMAGE)_LAZY_BUILD_INSTALLS = $(BRCM_OPENNSL_KERNEL) $(BRCM_DNX_OPENNSL_KERNEL) ifeq ($(INSTALL_DEBUG_TOOLS),y) diff --git a/platform/broadcom/platform-modules-ufispace.dep b/platform/broadcom/platform-modules-ufispace.dep new file mode 100644 index 000000000000..a6609b3c6f2b --- /dev/null +++ b/platform/broadcom/platform-modules-ufispace.dep @@ -0,0 +1,10 @@ + +MPATH := $($(UFISPACE_S9300_32D_PLATFORM_MODULE)_SRC_PATH) +DEP_FILES := $(SONIC_COMMON_FILES_LIST) platform/broadcom/platform-modules-ufispace.mk platform/broadcom/platform-modules-ufispace.dep +DEP_FILES += $(SONIC_COMMON_BASE_FILES_LIST) +DEP_FILES += $(shell git ls-files $(MPATH)) + +$(UFISPACE_S9300_32D_PLATFORM_MODULE)_CACHE_MODE := GIT_CONTENT_SHA +$(UFISPACE_S9300_32D_PLATFORM_MODULE)_DEP_FLAGS := $(SONIC_COMMON_FLAGS_LIST) +$(UFISPACE_S9300_32D_PLATFORM_MODULE)_DEP_FILES := $(DEP_FILES) + diff --git a/platform/broadcom/rules.dep b/platform/broadcom/rules.dep index e27e370b9a27..f118ab50674d 100644 --- a/platform/broadcom/rules.dep +++ b/platform/broadcom/rules.dep @@ -5,6 +5,7 @@ include $(PLATFORM_PATH)/sai.dep # * Nokia # * Juniper # * Ragile +# * Ufispace include $(PLATFORM_PATH)/platform-modules-s6000.dep include $(PLATFORM_PATH)/platform-modules-dell.dep include $(PLATFORM_PATH)/platform-modules-arista.dep @@ -20,6 +21,7 @@ include $(PLATFORM_PATH)/platform-modules-quanta.dep #include $(PLATFORM_PATH)/platform-modules-ragile.dep include $(PLATFORM_PATH)/platform-modules-ruijie.dep include $(PLATFORM_PATH)/platform-modules-brcm-xlr-gts.dep +#include $(PLATFORM_PATH)/platform-modules-ufispace.dep include $(PLATFORM_PATH)/docker-syncd-brcm.dep include $(PLATFORM_PATH)/docker-syncd-brcm-rpc.dep include $(PLATFORM_PATH)/docker-saiserver-brcm.dep diff --git a/platform/broadcom/sonic-platform-modules-ufispace/debian/sonic-platform-ufispace-s9300-32d.prerm b/platform/broadcom/sonic-platform-modules-ufispace/debian/sonic-platform-ufispace-s9300-32d.prerm new file mode 100644 index 000000000000..f9fe8c017ab0 --- /dev/null +++ b/platform/broadcom/sonic-platform-modules-ufispace/debian/sonic-platform-ufispace-s9300-32d.prerm @@ -0,0 +1,2 @@ +systemctl stop pddf-platform-init.service +systemctl disable pddf-platform-init.service diff --git a/platform/broadcom/sonic-platform-modules-ufispace/s6301-56st/modules/Makefile b/platform/broadcom/sonic-platform-modules-ufispace/s6301-56st/modules/Makefile index 7c2273d0063b..e27865a9be3d 100644 --- a/platform/broadcom/sonic-platform-modules-ufispace/s6301-56st/modules/Makefile +++ b/platform/broadcom/sonic-platform-modules-ufispace/s6301-56st/modules/Makefile @@ -1,5 +1,5 @@ -MODULE_NAME = x86-64-ufispace-s6301-56st-sys-eeprom.o x86-64-ufispace-s6301-56st-lpc.o +MODULE_NAME = x86-64-ufispace-s6301-56st-sys-eeprom.o x86-64-ufispace-s6301-56st-lpc.o pddf_custom_psu.o obj-m := $(MODULE_NAME) CFLAGS_pddf_custom_sysstatus_module.o := -I$(M)/../../../../pddf/i2c/modules/include diff --git a/platform/broadcom/sonic-platform-modules-ufispace/s6301-56st/modules/pddf_custom_psu.c b/platform/broadcom/sonic-platform-modules-ufispace/s6301-56st/modules/pddf_custom_psu.c new file mode 100644 index 000000000000..b71f0b90b0cf --- /dev/null +++ b/platform/broadcom/sonic-platform-modules-ufispace/s6301-56st/modules/pddf_custom_psu.c @@ -0,0 +1,124 @@ +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include "../../../../pddf/i2c/modules/include/pddf_psu_defs.h" + +#define PSU_REG_VOUT_MODE 0x20 +#define PSU_REG_READ_VOUT 0x8b + +ssize_t pddf_show_custom_psu_v_out(struct device *dev, struct device_attribute *da, char *buf); +extern PSU_SYSFS_ATTR_DATA access_psu_v_out; + +static int two_complement_to_int(u16 data, u8 valid_bit, int mask) +{ + u16 valid_data = data & mask; + bool is_negative = valid_data >> (valid_bit - 1); + + return is_negative ? (-(((~valid_data) & mask) + 1)) : valid_data; +} + +static u8 psu_get_vout_mode(struct i2c_client *client) +{ + u8 status = 0, retry = 10; + uint8_t offset = PSU_REG_VOUT_MODE; + + while (retry) { + status = i2c_smbus_read_byte_data((struct i2c_client *)client, offset); + if (unlikely(status < 0)) { + msleep(60); + retry--; + continue; + } + break; + } + + if (status < 0) + { + printk(KERN_ERR "%s: Get PSU Vout mode failed\n", __func__); + return 0; + } + else + { + /*printk(KERN_ERR "%s: vout_mode reg value 0x%x\n", __func__, status);*/ + return status; + } +} + +static u16 psu_get_v_out(struct i2c_client *client) +{ + u16 status = 0, retry = 10; + uint8_t offset = PSU_REG_READ_VOUT; + + while (retry) { + status = i2c_smbus_read_word_data((struct i2c_client *)client, offset); + if (unlikely(status < 0)) { + msleep(60); + retry--; + continue; + } + break; + } + + if (status < 0) + { + printk(KERN_ERR "%s: Get PSU Vout failed\n", __func__); + return 0; + } + else + { + /*printk(KERN_ERR "%s: vout reg value 0x%x\n", __func__, status);*/ + return status; + } +} + +ssize_t pddf_show_custom_psu_v_out(struct device *dev, struct device_attribute *da, char *buf) +{ + struct i2c_client *client = to_i2c_client(dev); + struct sensor_device_attribute *attr = to_sensor_dev_attr(da); + int exponent, mantissa; + int multiplier = 1000; + + u16 value = psu_get_v_out(client); + u8 vout_mode = psu_get_vout_mode(client); + + if ((vout_mode >> 5) == 0) + exponent = two_complement_to_int(vout_mode & 0x1f, 5, 0x1f); + else + { + /*printk(KERN_ERR "%s: Only support linear mode for vout mode\n", __func__);*/ + exponent = 0; + } + mantissa = value; + if (exponent >= 0) + return sprintf(buf, "%d\n", (mantissa << exponent) * multiplier); + else + return sprintf(buf, "%d\n", (mantissa * multiplier) / (1 << -exponent)); +} + +static int __init pddf_custom_psu_init(void) +{ + access_psu_v_out.show = pddf_show_custom_psu_v_out; + access_psu_v_out.do_get = NULL; + return 0; +} + +static void __exit pddf_custom_psu_exit(void) +{ + return; +} + +MODULE_AUTHOR("Broadcom"); +MODULE_DESCRIPTION("pddf custom psu api"); +MODULE_LICENSE("GPL"); + +module_init(pddf_custom_psu_init); +module_exit(pddf_custom_psu_exit); + diff --git a/platform/broadcom/sonic-platform-modules-ufispace/s6301-56st/modules/x86-64-ufispace-s6301-56st-lpc.c b/platform/broadcom/sonic-platform-modules-ufispace/s6301-56st/modules/x86-64-ufispace-s6301-56st-lpc.c index 9b42c8f2b88f..5858d989af50 100644 --- a/platform/broadcom/sonic-platform-modules-ufispace/s6301-56st/modules/x86-64-ufispace-s6301-56st-lpc.c +++ b/platform/broadcom/sonic-platform-modules-ufispace/s6301-56st/modules/x86-64-ufispace-s6301-56st-lpc.c @@ -26,7 +26,7 @@ #include #include #include -#include +#include #include #include @@ -44,6 +44,7 @@ #define REG_BASE_CPU 0x600 #define REG_BASE_MB 0x700 +#define REG_BASE_EC 0xe000 //MB CPLD #define REG_MB_BRD_ID_0 (REG_BASE_MB + 0x00) @@ -59,6 +60,10 @@ #define REG_MB_SYS_LED_STATUS_1 (REG_BASE_MB + 0x82) #define REG_MB_SYS_LED_STATUS_2 (REG_BASE_MB + 0x83) #define REG_MB_SYS_LED_STATUS_3 (REG_BASE_MB + 0x84) +#define REG_MB_POWER_EN (REG_BASE_MB + 0x95) +//EC +#define REG_EC_SEL (REG_BASE_EC + 0x394) +#define REG_EC_PSU_RST (REG_BASE_EC + 0x392) #define MASK_ALL (0xFF) @@ -94,6 +99,9 @@ enum lpc_sysfs_attributes { ATT_MB_LED_LNK, ATT_MB_LED_PWR0, ATT_MB_LED_PWR1, + ATT_MB_POWER_EN, + //EC + ATT_EC_PSU_RESET, //BSP ATT_BSP_VERSION, ATT_BSP_DEBUG, @@ -477,6 +485,10 @@ static ssize_t read_lpc_callback(struct device *dev, mask = 0xF; base = BASE_HEX; break; + case ATT_MB_POWER_EN: + reg = REG_MB_POWER_EN; + base = BASE_HEX; + break; //BSP case ATT_BSP_REG_VALUE: if (kstrtou16(bsp_reg, 0, ®) < 0) @@ -511,6 +523,9 @@ static ssize_t write_lpc_callback(struct device *dev, reg = REG_MB_SYS_LED_CTRL_1; mask = 0xF; break; + case ATT_MB_POWER_EN: + reg = REG_MB_POWER_EN; + break; default: return -EINVAL; } @@ -557,18 +572,18 @@ static ssize_t write_bsp_callback(struct device *dev, switch (attr->index) { case ATT_BSP_VERSION: str = bsp_version; - str_len = sizeof(str); + str_len = sizeof(bsp_version); break; case ATT_BSP_DEBUG: str = bsp_debug; - str_len = sizeof(str); + str_len = sizeof(bsp_debug); break; case ATT_BSP_REG: if(kstrtou16(buf, 0, ®) < 0) return -EINVAL; str = bsp_reg; - str_len = sizeof(str); + str_len = sizeof(bsp_reg); break; default: return -EINVAL; @@ -621,6 +636,41 @@ static ssize_t read_gpio_max_callback(struct device *dev, return -1; } +/* set psu_reset register value */ +static ssize_t write_ec_psu_reset(struct device *dev, + struct device_attribute *da, const char *buf, size_t count) +{ + u8 val = 0; + u8 reg_val = 0; + static int psu_reset_flag = 0; + + if (kstrtou8(buf, 0, &val) < 0) + return -EINVAL; + + if (psu_reset_flag == 0) { + if (val == 0) { + mutex_lock(&lpc_data->access_lock); + psu_reset_flag = 1; + reg_val = 0x1; + outb(reg_val, REG_EC_SEL); + BSP_LOG_W("reg=0x%04x, reg_val=0x%02x", REG_EC_SEL, reg_val); + reg_val = 0x21; + outb(reg_val, REG_EC_PSU_RST); + BSP_LOG_W("reg=0x%04x, reg_val=0x%02x", REG_EC_PSU_RST, reg_val); + psu_reset_flag = 0; + mutex_unlock(&lpc_data->access_lock); + } else { + return -EINVAL; + } + } else { + printk(KERN_INFO "PSU is resetting... (ignore)\n"); + mutex_lock(&lpc_data->access_lock); + mutex_unlock(&lpc_data->access_lock); + } + + return count; +} + //SENSOR_DEVICE_ATTR - MB static SENSOR_DEVICE_ATTR(board_id_0, S_IRUGO, read_lpc_callback, NULL, ATT_MB_BRD_ID_0); static SENSOR_DEVICE_ATTR(board_id_1, S_IRUGO, read_lpc_callback, NULL, ATT_MB_BRD_ID_1); @@ -644,7 +694,9 @@ static SENSOR_DEVICE_ATTR(led_fan, S_IRUGO, read_lpc_callback, NULL, A static SENSOR_DEVICE_ATTR(led_lnk, S_IRUGO, read_lpc_callback, NULL, ATT_MB_LED_LNK); static SENSOR_DEVICE_ATTR(led_pwr1, S_IRUGO, read_lpc_callback, NULL, ATT_MB_LED_PWR1); static SENSOR_DEVICE_ATTR(led_pwr0, S_IRUGO, read_lpc_callback, NULL, ATT_MB_LED_PWR0); - +static SENSOR_DEVICE_ATTR(power_en, S_IRUGO | S_IWUSR, read_lpc_callback, write_lpc_callback, ATT_MB_POWER_EN); +//SENSOR_DEVICE_ATTR - EC +static SENSOR_DEVICE_ATTR(psu_reset, S_IRUGO | S_IWUSR, NULL, write_ec_psu_reset, ATT_EC_PSU_RESET); //SENSOR_DEVICE_ATTR - BSP static SENSOR_DEVICE_ATTR(bsp_version , S_IRUGO | S_IWUSR, read_bsp_callback, write_bsp_callback, ATT_BSP_VERSION); static SENSOR_DEVICE_ATTR(bsp_debug , S_IRUGO | S_IWUSR, read_bsp_callback, write_bsp_callback, ATT_BSP_DEBUG); @@ -659,25 +711,31 @@ static struct attribute *mb_cpld_attrs[] = { &sensor_dev_attr_board_id_0.dev_attr.attr, &sensor_dev_attr_board_id_1.dev_attr.attr, &sensor_dev_attr_mb_cpld_1_version.dev_attr.attr, - &sensor_dev_attr_mb_cpld_1_version_h.dev_attr.attr, - &sensor_dev_attr_board_sku_id.dev_attr.attr, - &sensor_dev_attr_board_hw_id.dev_attr.attr, - &sensor_dev_attr_board_id_type.dev_attr.attr, - &sensor_dev_attr_board_build_id.dev_attr.attr, - &sensor_dev_attr_board_deph_id.dev_attr.attr, - &sensor_dev_attr_board_ext_id.dev_attr.attr, - &sensor_dev_attr_mux_reset.dev_attr.attr, - &sensor_dev_attr_fan_status.dev_attr.attr, - &sensor_dev_attr_psu_status.dev_attr.attr, - &sensor_dev_attr_port_led_clear.dev_attr.attr, - &sensor_dev_attr_led_sys.dev_attr.attr, - &sensor_dev_attr_led_id.dev_attr.attr, - &sensor_dev_attr_led_poe.dev_attr.attr, - &sensor_dev_attr_led_spd.dev_attr.attr, - &sensor_dev_attr_led_fan.dev_attr.attr, - &sensor_dev_attr_led_lnk.dev_attr.attr, - &sensor_dev_attr_led_pwr0.dev_attr.attr, - &sensor_dev_attr_led_pwr1.dev_attr.attr, + &sensor_dev_attr_mb_cpld_1_version_h.dev_attr.attr, + &sensor_dev_attr_board_sku_id.dev_attr.attr, + &sensor_dev_attr_board_hw_id.dev_attr.attr, + &sensor_dev_attr_board_id_type.dev_attr.attr, + &sensor_dev_attr_board_build_id.dev_attr.attr, + &sensor_dev_attr_board_deph_id.dev_attr.attr, + &sensor_dev_attr_board_ext_id.dev_attr.attr, + &sensor_dev_attr_mux_reset.dev_attr.attr, + &sensor_dev_attr_fan_status.dev_attr.attr, + &sensor_dev_attr_psu_status.dev_attr.attr, + &sensor_dev_attr_port_led_clear.dev_attr.attr, + &sensor_dev_attr_led_sys.dev_attr.attr, + &sensor_dev_attr_led_id.dev_attr.attr, + &sensor_dev_attr_led_poe.dev_attr.attr, + &sensor_dev_attr_led_spd.dev_attr.attr, + &sensor_dev_attr_led_fan.dev_attr.attr, + &sensor_dev_attr_led_lnk.dev_attr.attr, + &sensor_dev_attr_led_pwr0.dev_attr.attr, + &sensor_dev_attr_led_pwr1.dev_attr.attr, + &sensor_dev_attr_power_en.dev_attr.attr, + NULL, +}; + +static struct attribute *ec_attrs[] = { + &sensor_dev_attr_psu_reset.dev_attr.attr, NULL, }; @@ -697,6 +755,11 @@ static struct attribute_group mb_cpld_attr_grp = { .attrs = mb_cpld_attrs, }; +static struct attribute_group ec_attr_grp = { + .name = "ec", + .attrs = ec_attrs, +}; + static struct attribute_group bsp_attr_grp = { .name = "bsp", .attrs = bsp_attrs, @@ -717,7 +780,7 @@ static struct platform_device lpc_dev = { static int lpc_drv_probe(struct platform_device *pdev) { - int i = 0, grp_num = 2; + int i = 0, grp_num = 3; int err[5] = {0}; struct attribute_group *grp; @@ -734,6 +797,9 @@ static int lpc_drv_probe(struct platform_device *pdev) grp = &mb_cpld_attr_grp; break; case 1: + grp = &ec_attr_grp; + break; + case 2: grp = &bsp_attr_grp; break; default: @@ -758,6 +824,9 @@ static int lpc_drv_probe(struct platform_device *pdev) grp = &mb_cpld_attr_grp; break; case 1: + grp = &ec_attr_grp; + break; + case 2: grp = &bsp_attr_grp; break; default: @@ -779,6 +848,7 @@ static int lpc_drv_probe(struct platform_device *pdev) static int lpc_drv_remove(struct platform_device *pdev) { sysfs_remove_group(&pdev->dev.kobj, &mb_cpld_attr_grp); + sysfs_remove_group(&pdev->dev.kobj, &ec_attr_grp); sysfs_remove_group(&pdev->dev.kobj, &bsp_attr_grp); return 0; @@ -798,18 +868,18 @@ int lpc_init(void) err = platform_driver_register(&lpc_drv); if(err) { - printk(KERN_ERR "%s(#%d): platform_driver_register failed(%d)\n", + printk(KERN_ERR "%s(#%d): platform_driver_register failed(%d)\n", __func__, __LINE__, err); - return err; + return err; } err = platform_device_register(&lpc_dev); if(err) { - printk(KERN_ERR "%s(#%d): platform_device_register failed(%d)\n", + printk(KERN_ERR "%s(#%d): platform_device_register failed(%d)\n", __func__, __LINE__, err); - platform_driver_unregister(&lpc_drv); - return err; + platform_driver_unregister(&lpc_drv); + return err; } return err; diff --git a/platform/broadcom/sonic-platform-modules-ufispace/s6301-56st/modules/x86-64-ufispace-s6301-56st-sys-eeprom.c b/platform/broadcom/sonic-platform-modules-ufispace/s6301-56st/modules/x86-64-ufispace-s6301-56st-sys-eeprom.c index 5c6dec193ef6..69699ae457c6 100644 --- a/platform/broadcom/sonic-platform-modules-ufispace/s6301-56st/modules/x86-64-ufispace-s6301-56st-sys-eeprom.c +++ b/platform/broadcom/sonic-platform-modules-ufispace/s6301-56st/modules/x86-64-ufispace-s6301-56st-sys-eeprom.c @@ -28,6 +28,8 @@ #include #include +#define _memset(s, c, n) memset(s, c, n) + /* Addresses to scan */ static const unsigned short normal_i2c[] = { /*0x50, 0x51, 0x52, 0x53, 0x54, 0x55, 0x56, 0x57,*/ I2C_CLIENT_END }; @@ -220,7 +222,7 @@ static int sys_eeprom_probe(struct i2c_client *client, #ifdef __STDC_LIB_EXT1__ memset_s(data->data, EEPROM_SIZE, 0xff, EEPROM_SIZE); #else - memset(data->data, 0xff, EEPROM_SIZE); + _memset(data->data, 0xff, EEPROM_SIZE); #endif i2c_set_clientdata(client, data); diff --git a/platform/broadcom/sonic-platform-modules-ufispace/s6301-56st/sonic_platform/chassis.py b/platform/broadcom/sonic-platform-modules-ufispace/s6301-56st/sonic_platform/chassis.py index ab3e44f74432..585ecdbe197c 100644 --- a/platform/broadcom/sonic-platform-modules-ufispace/s6301-56st/sonic_platform/chassis.py +++ b/platform/broadcom/sonic-platform-modules-ufispace/s6301-56st/sonic_platform/chassis.py @@ -39,7 +39,7 @@ def get_name(self): Returns: string: The name of the chassis """ - return device_info.get_platform() + return self._eeprom.platform_name_str() def initizalize_system_led(self): return True @@ -175,26 +175,7 @@ def get_sfp(self, index): except IndexError: sys.stderr.write("SFP index {} out of range (1-{})\n".format( index, len(self._sfp_list))) - return sfp - - def set_system_led(self, led_device_name, color): - """ - Sets the color of an System LED device - Args: - led_device_name: a pre-defined LED device name list used in pddf-device.json. - color: A string representing the color with which to set a LED - Returns: - bool: True if the LED state is set successfully, False if not - """ - - if led_device_name in self.plugin_data['LED']['capability']['rw']: - result, msg = self.pddf_obj.set_system_led_color(led_device_name, color) - if not result and msg: - print(msg) - return (result) - else: - print("Not Support") - return False + return sfp def get_reboot_cause(self): """ @@ -217,4 +198,15 @@ def get_reboot_cause(self): except IOError: sw_reboot_cause = "Unknown" - return ('REBOOT_CAUSE_NON_HARDWARE', sw_reboot_cause) \ No newline at end of file + return ('REBOOT_CAUSE_NON_HARDWARE', sw_reboot_cause) + + def get_serial_number(self): + """ + Retrieves the hardware serial number for the chassis + + Returns: + A string containing the hardware serial number for this + chassis. + """ + + return self.get_serial() \ No newline at end of file diff --git a/platform/broadcom/sonic-platform-modules-ufispace/s6301-56st/sonic_platform/fan.py b/platform/broadcom/sonic-platform-modules-ufispace/s6301-56st/sonic_platform/fan.py index 2eadfd0a465a..6685e8c8961a 100644 --- a/platform/broadcom/sonic-platform-modules-ufispace/s6301-56st/sonic_platform/fan.py +++ b/platform/broadcom/sonic-platform-modules-ufispace/s6301-56st/sonic_platform/fan.py @@ -19,6 +19,25 @@ def __init__(self, tray_idx, fan_idx=0, pddf_data=None, pddf_plugin_data=None, i # Provide the functions/variables below for which implementation is to be overwritten # Since psu_fan airflow direction cant be read from sysfs, it is fixed as 'F2B' or 'intake' + def get_max_speed(self): + """ + Retrieves the max speed + + Returns: + An Integer, the max speed + """ + if self.is_psu_fan: + psu_fru = PsuFru(self.fans_psu_index) + max_speed = int(self.plugin_data['PSU']['valmap']['PSU_FAN_MAX_SPEED']) + for dev in self.plugin_data['PSU']['psu_support_list']: + if dev['Manufacturer'] == psu_fru.mfr_id and dev['Name'] == psu_fru.model: + max_speed = int(self.plugin_data['PSU']['valmap'][dev['MaxSpd']]) + break + else: + max_speed = int(self.plugin_data['FAN']['FAN_MAX_SPEED']) + + return max_speed + def get_speed(self): """ Retrieves the speed of fan as a percentage of full speed @@ -28,15 +47,12 @@ def get_speed(self): to 100 (full speed) """ speed_percentage = 0 - if self.is_psu_fan: - max_speed = int(self.plugin_data['PSU']['PSU_FAN_MAX_SPEED']) - else: - max_speed = int(self.plugin_data['FAN']['FAN_MAX_SPEED']) + max_speed = self.get_max_speed() speed = int(self.get_speed_rpm()) - speed_percentage = round((speed*100)/max_speed) + return min(speed_percentage, 100) def get_speed_rpm(self): @@ -63,7 +79,7 @@ def get_speed_rpm(self): ucd_path = "/sys/bus/i2c/devices/5-0034/hwmon/" if os.path.exists(ucd_path): hwmon_dir = os.listdir(ucd_path) - with open("{}/{}/temp{}_input".format(ucd_path, hwmon_dir[0], self.fantray_index), "rb") as f: + with open("{}/{}/fan{}_input".format(ucd_path, hwmon_dir[0], self.fantray_index), "rb") as f: rpm_speed = int(f.read().strip()) return rpm_speed @@ -81,7 +97,7 @@ def get_direction(self): if psu_fru.mfr_id == "not available": return direction for dev in self.plugin_data['PSU']['psu_support_list']: - if dev['Mfr_id'] == psu_fru.mfr_id and dev['Model'] == psu_fru.model: + if dev['Manufacturer'] == psu_fru.mfr_id and dev['Name'] == psu_fru.model: dir = dev['Dir'] break else: @@ -98,34 +114,6 @@ def get_direction(self): return dir - def get_presence(self): - """ - Retrieves the presence of the device - Returns: - bool: True if device is present, False if not - """ - presence = False - if self.is_psu_fan: - attr = "psu_present" - device = "PSU{}".format(self.fans_psu_index) - else: - attr = "fan{}_present".format(self.fantray_index) - device = "FAN-CTRL" - - output = self.pddf_obj.get_attr_name_output(device, attr) - if not output: - return presence - - - mode = output['mode'] - val = output['status'].strip() - vmap = self.plugin_data['FAN']['present'][mode]['valmap'] - - if val in vmap: - presence = vmap[val] - - return presence - def get_target_speed(self): """ Retrieves the target (expected) speed of the fan diff --git a/platform/broadcom/sonic-platform-modules-ufispace/s6301-56st/sonic_platform/psu.py b/platform/broadcom/sonic-platform-modules-ufispace/s6301-56st/sonic_platform/psu.py index 008aa600cdf8..fff8de4aa953 100644 --- a/platform/broadcom/sonic-platform-modules-ufispace/s6301-56st/sonic_platform/psu.py +++ b/platform/broadcom/sonic-platform-modules-ufispace/s6301-56st/sonic_platform/psu.py @@ -10,23 +10,12 @@ class Psu(PddfPsu): """PDDF Platform-Specific PSU class""" - - PLATFORM_PSU_CAPACITY = 750 def __init__(self, index, pddf_data=None, pddf_plugin_data=None): PddfPsu.__init__(self, index, pddf_data, pddf_plugin_data) self.psu_fru = PsuFru(self.psu_index) # Provide the functions/variables below for which implementation is to be overwritten - def get_maximum_supplied_power(self): - """ - Retrieves the maximum supplied power by PSU (or PSU capacity) - Returns: - A float number, the maximum power output in Watts. - e.g. 1200.1 - """ - return float(self.PLATFORM_PSU_CAPACITY) - def get_power(self): """ Retrieves current energy supplied by PSU @@ -65,3 +54,34 @@ def get_serial(self): string: Serial number of device """ return self.psu_fru.serial.rstrip() + + def get_capacity(self): + """ + Retrieves the maximum supplied power by PSU (or PSU capacity) + Returns: + A float number, the maximum power output in Watts. + e.g. 1200.1 + """ + return self.get_maximum_supplied_power() + + def get_type(self): + """ + Gets the type of the PSU + + Returns: + A string, the type of PSU (AC/DC) + """ + mfr = self.get_mfr_id() + model = self.get_model() + ptype = self.plugin_data['PSU']['valmap']['DEFAULT_TYPE'] + + if mfr and model : + for dev in self.plugin_data['PSU']['psu_support_list']: + if dev['Manufacturer'] == mfr and dev['Name'] == model: + ptype = dev['Type'] + break + + + return ptype + + diff --git a/platform/broadcom/sonic-platform-modules-ufispace/s6301-56st/sonic_platform/watchdog.py b/platform/broadcom/sonic-platform-modules-ufispace/s6301-56st/sonic_platform/watchdog.py deleted file mode 100644 index 88660b1a1faa..000000000000 --- a/platform/broadcom/sonic-platform-modules-ufispace/s6301-56st/sonic_platform/watchdog.py +++ /dev/null @@ -1,23 +0,0 @@ -#!/usr/bin/env python - -############################################################################# -# -# Module contains an implementation of platform specific watchdog API's -# -############################################################################# - -try: - from sonic_platform_pddf_base.pddf_watchdog import PddfWatchdog -except ImportError as e: - raise ImportError(str(e) + "- required module not found") - -class Watchdog(PddfWatchdog): - """ - PDDF Platform-specific Chassis class - """ - - def __init__(self): - PddfWatchdog.__init__(self) - self.timeout= 180 - - # Provide the functions/variables below for which implementation is to be overwritten diff --git a/platform/broadcom/sonic-platform-modules-ufispace/s6301-56st/utils/pddf_pre_driver_install.sh b/platform/broadcom/sonic-platform-modules-ufispace/s6301-56st/utils/pddf_pre_driver_install.sh deleted file mode 100755 index 187943061e6c..000000000000 --- a/platform/broadcom/sonic-platform-modules-ufispace/s6301-56st/utils/pddf_pre_driver_install.sh +++ /dev/null @@ -1,11 +0,0 @@ -#!/bin/bash -#rmmod gpio_ich -if [ ! -f /tmp/._pddf_pre_driver_init_completion ]; then - # make sure igb/i40e init in correct order - rmmod i2c-i801 - rmmod i2c_ismt - modprobe -r i2c-i801 - modprobe -r i2c_ismt - date > /tmp/._pddf_pre_driver_init_completion -fi -echo "PDDF driver pre-install completed" diff --git a/platform/broadcom/sonic-platform-modules-ufispace/s7801-54xs/modules/pddf_custom_sysstatus_module.c b/platform/broadcom/sonic-platform-modules-ufispace/s7801-54xs/modules/pddf_custom_sysstatus_module.c index b50bb428000a..d68f85670a10 100644 --- a/platform/broadcom/sonic-platform-modules-ufispace/s7801-54xs/modules/pddf_custom_sysstatus_module.c +++ b/platform/broadcom/sonic-platform-modules-ufispace/s7801-54xs/modules/pddf_custom_sysstatus_module.c @@ -1,6 +1,6 @@ /* * Copyright 2019 Broadcom. - * The term ��Broadcom�� refers to Broadcom Inc. and/or its subsidiaries. + * The term "Broadcom" refers to Broadcom Inc. and/or its subsidiaries. * * 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 @@ -33,6 +33,7 @@ #include "../../../../pddf/i2c/modules/include/pddf_client_defs.h" #include "../../../../pddf/i2c/modules/include/pddf_sysstatus_defs.h" +#define _memset(s, c, n) memset(s, c, n) SYSSTATUS_DATA sysstatus_data = {0}; @@ -142,8 +143,9 @@ ssize_t show_sysstatus_data(struct device *dev, struct device_attribute *da, cha if (sysstatus_addr_attrs==NULL ) { - printk(KERN_DEBUG "%s is not supported attribute for this client\n",data->sysstatus_addr_attrs[i].aname); + printk(KERN_DEBUG "%s is not supported attribute for this client\n",attr->dev_attr.attr.name); status = 0; + return sprintf(buf, "0x%x\n", status); } else { @@ -173,7 +175,7 @@ ssize_t store_sysstatus_data(struct device *dev, struct device_attribute *da, co if (sysstatus_addr_attrs==NULL) { - printk(KERN_DEBUG "%s is not supported attribute for this client\n",data->sysstatus_addr_attrs[i].aname); + printk(KERN_DEBUG "%s is not supported attribute for this client\n",attr->dev_attr.attr.name); return -EINVAL; } else @@ -207,7 +209,7 @@ static ssize_t do_attr_operation(struct device *dev, struct device_attribute *da #ifdef __STDC_LIB_EXT1__ memset_s(&pdata->sysstatus_addr_attr, sizeof(pdata->sysstatus_addr_attr, 0, sizeof(pdata->sysstatus_addr_attr)); #else - memset(&pdata->sysstatus_addr_attr, 0, sizeof(pdata->sysstatus_addr_attr)); + _memset(&pdata->sysstatus_addr_attr, 0, sizeof(pdata->sysstatus_addr_attr)); #endif return count; diff --git a/platform/broadcom/sonic-platform-modules-ufispace/s7801-54xs/modules/x86-64-ufispace-s7801-54xs-cpld.c b/platform/broadcom/sonic-platform-modules-ufispace/s7801-54xs/modules/x86-64-ufispace-s7801-54xs-cpld.c index 0cefcb8aac5f..f00db70afec3 100644 --- a/platform/broadcom/sonic-platform-modules-ufispace/s7801-54xs/modules/x86-64-ufispace-s7801-54xs-cpld.c +++ b/platform/broadcom/sonic-platform-modules-ufispace/s7801-54xs/modules/x86-64-ufispace-s7801-54xs-cpld.c @@ -1050,7 +1050,7 @@ static ssize_t write_bsp_callback(struct device *dev, switch (attr->index) { case BSP_DEBUG: str = bsp_debug; - str_len = sizeof(str); + str_len = sizeof(bsp_debug); ret = write_bsp(buf, str, str_len, count); if (kstrtou8(buf, 0, &bsp_debug_u8) < 0) { diff --git a/platform/broadcom/sonic-platform-modules-ufispace/s7801-54xs/modules/x86-64-ufispace-s7801-54xs-sys-eeprom.c b/platform/broadcom/sonic-platform-modules-ufispace/s7801-54xs/modules/x86-64-ufispace-s7801-54xs-sys-eeprom.c index f9f7728deb3d..31b605bb3d6d 100644 --- a/platform/broadcom/sonic-platform-modules-ufispace/s7801-54xs/modules/x86-64-ufispace-s7801-54xs-sys-eeprom.c +++ b/platform/broadcom/sonic-platform-modules-ufispace/s7801-54xs/modules/x86-64-ufispace-s7801-54xs-sys-eeprom.c @@ -28,6 +28,8 @@ #include #include +#define _memset(s, c, n) memset(s, c, n) + /* Addresses to scan */ static const unsigned short normal_i2c[] = { /*0x50, 0x51, 0x52, 0x53, 0x54, 0x55, 0x56, 0x57,*/ I2C_CLIENT_END }; @@ -220,7 +222,7 @@ static int sys_eeprom_probe(struct i2c_client *client, #ifdef __STDC_LIB_EXT1__ memset_s(data->data, EEPROM_SIZE, 0xff, EEPROM_SIZE); #else - memset(data->data, 0xff, EEPROM_SIZE); + _memset(data->data, 0xff, EEPROM_SIZE); #endif i2c_set_clientdata(client, data); mutex_init(&data->update_lock); diff --git a/platform/broadcom/sonic-platform-modules-ufispace/s7801-54xs/sonic_platform/chassis.py b/platform/broadcom/sonic-platform-modules-ufispace/s7801-54xs/sonic_platform/chassis.py index 085f2af2ff85..0b02f9a834c2 100644 --- a/platform/broadcom/sonic-platform-modules-ufispace/s7801-54xs/sonic_platform/chassis.py +++ b/platform/broadcom/sonic-platform-modules-ufispace/s7801-54xs/sonic_platform/chassis.py @@ -191,3 +191,14 @@ def get_reboot_cause(self): sw_reboot_cause = "Unknown" return ('REBOOT_CAUSE_NON_HARDWARE', sw_reboot_cause) + + def get_serial_number(self): + """ + Retrieves the hardware serial number for the chassis + + Returns: + A string containing the hardware serial number for this + chassis. + """ + + return self.get_serial() \ No newline at end of file diff --git a/platform/broadcom/sonic-platform-modules-ufispace/s7801-54xs/sonic_platform/component.py b/platform/broadcom/sonic-platform-modules-ufispace/s7801-54xs/sonic_platform/component.py index 1c583079f8c2..d5d8d8226fd8 100644 --- a/platform/broadcom/sonic-platform-modules-ufispace/s7801-54xs/sonic_platform/component.py +++ b/platform/broadcom/sonic-platform-modules-ufispace/s7801-54xs/sonic_platform/component.py @@ -18,9 +18,7 @@ } BMC_CMDS = { - "VER1": "ipmitool mc info | grep 'Firmware Revision' | cut -d':' -f2 | cut -d'.' -f1", - "VER2": "ipmitool mc info | grep 'Firmware Revision' | cut -d':' -f2 | cut -d'.' -f2", - "VER3": "echo $((`ipmitool mc info | grep 'Aux Firmware Rev Info' -A 2 | sed -n '2p'` + 0))", + "BMC": "bash -c 'tmp=$(ipmitool raw 0x6 0x1) && r=($(echo \"$tmp\" | cut -d \" \" -f 4,5,16,15,14)) && echo ${r[0]}.${r[1]}.${r[4]}.${r[3]}${r[2]}'", } BIOS_VERSION_PATH = "/sys/class/dmi/id/bios_version" @@ -69,17 +67,11 @@ def _get_cpld_version(self): def _get_bmc_version(self): # Retrieves the BMC firmware version - bmc_ver = dict() - for ver in BMC_CMDS: - status, value = subprocess.getstatusoutput(BMC_CMDS[ver]) - if not status: - bmc_ver[ver] = int(value.rstrip()) - else: - return None - - bmc_version = "{}.{}.{}".format(bmc_ver["VER1"], bmc_ver["VER2"], bmc_ver["VER3"]) - - return bmc_version + status, value = subprocess.getstatusoutput(BMC_CMDS["BMC"]) + if not status: + return value + else: + return None def get_name(self): """ diff --git a/platform/broadcom/sonic-platform-modules-ufispace/s7801-54xs/sonic_platform/psu.py b/platform/broadcom/sonic-platform-modules-ufispace/s7801-54xs/sonic_platform/psu.py index 38b32412d024..cae583254015 100644 --- a/platform/broadcom/sonic-platform-modules-ufispace/s7801-54xs/sonic_platform/psu.py +++ b/platform/broadcom/sonic-platform-modules-ufispace/s7801-54xs/sonic_platform/psu.py @@ -36,3 +36,32 @@ def get_power(self): # power is returned in micro watts return round(float(self.get_voltage()*self.get_current()), 2) + + def get_capacity(self): + """ + Retrieves the maximum supplied power by PSU (or PSU capacity) + Returns: + A float number, the maximum power output in Watts. + e.g. 1200.1 + """ + return self.get_maximum_supplied_power() + + def get_type(self): + """ + Gets the type of the PSU + + Returns: + A string, the type of PSU (AC/DC) + """ + mfr = self.get_mfr_id() + model = self.get_model() + ptype = self.plugin_data['PSU']['valmap']['DEFAULT_TYPE'] + + if mfr and model : + for dev in self.plugin_data['PSU']['psu_support_list']: + if dev['Manufacturer'] == mfr and dev['Name'] == model: + ptype = dev['Type'] + break + + + return ptype \ No newline at end of file diff --git a/platform/broadcom/sonic-platform-modules-ufispace/s7801-54xs/utils/pddf_post_device_create.sh b/platform/broadcom/sonic-platform-modules-ufispace/s7801-54xs/utils/pddf_post_device_create.sh index 4a55252ea936..c6fe10aba368 100755 --- a/platform/broadcom/sonic-platform-modules-ufispace/s7801-54xs/utils/pddf_post_device_create.sh +++ b/platform/broadcom/sonic-platform-modules-ufispace/s7801-54xs/utils/pddf_post_device_create.sh @@ -6,7 +6,7 @@ timeout 3 ipmitool mc watchdog off pddf_ledutil setstatusled SYNC_LED off pddf_ledutil setstatusled SYS_LED off -pddf_ledutil setstatusled ID_LED off +pddf_ledutil setstatusled LOC_LED off #set status led to green to indicate platform init done curr_led=$(pddf_ledutil getstatusled SYS_LED) diff --git a/platform/broadcom/sonic-platform-modules-ufispace/s7801-54xs/utils/pddf_pre_driver_install.sh b/platform/broadcom/sonic-platform-modules-ufispace/s7801-54xs/utils/pddf_pre_driver_install.sh deleted file mode 100755 index 9ada6c235c48..000000000000 --- a/platform/broadcom/sonic-platform-modules-ufispace/s7801-54xs/utils/pddf_pre_driver_install.sh +++ /dev/null @@ -1,8 +0,0 @@ -#!/bin/bash -#rmmod gpio_ich -if [ ! -f /tmp/._pddf_pre_driver_init_completion ]; then - rmmod i2c_i801 - rmmod i2c_ismt - date > /tmp/._pddf_pre_driver_init_completion -fi -echo "PDDF driver pre-install completed" diff --git a/platform/broadcom/sonic-platform-modules-ufispace/s7801-54xs/utils/pre_pddf_init.sh b/platform/broadcom/sonic-platform-modules-ufispace/s7801-54xs/utils/pre_pddf_init.sh deleted file mode 100755 index 63a2e205808e..000000000000 --- a/platform/broadcom/sonic-platform-modules-ufispace/s7801-54xs/utils/pre_pddf_init.sh +++ /dev/null @@ -1,5 +0,0 @@ -#!/bin/bash -#rmmod gpio_ich -modprobe -rq i2c_i801 -modprobe -rq i2c_smbus -echo "Pre PDDF init steps completed successully" diff --git a/platform/broadcom/sonic-platform-modules-ufispace/s8901-54xc/modules/pddf_custom_sysstatus_module.c b/platform/broadcom/sonic-platform-modules-ufispace/s8901-54xc/modules/pddf_custom_sysstatus_module.c index b50bb428000a..d68f85670a10 100644 --- a/platform/broadcom/sonic-platform-modules-ufispace/s8901-54xc/modules/pddf_custom_sysstatus_module.c +++ b/platform/broadcom/sonic-platform-modules-ufispace/s8901-54xc/modules/pddf_custom_sysstatus_module.c @@ -1,6 +1,6 @@ /* * Copyright 2019 Broadcom. - * The term ��Broadcom�� refers to Broadcom Inc. and/or its subsidiaries. + * The term "Broadcom" refers to Broadcom Inc. and/or its subsidiaries. * * 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 @@ -33,6 +33,7 @@ #include "../../../../pddf/i2c/modules/include/pddf_client_defs.h" #include "../../../../pddf/i2c/modules/include/pddf_sysstatus_defs.h" +#define _memset(s, c, n) memset(s, c, n) SYSSTATUS_DATA sysstatus_data = {0}; @@ -142,8 +143,9 @@ ssize_t show_sysstatus_data(struct device *dev, struct device_attribute *da, cha if (sysstatus_addr_attrs==NULL ) { - printk(KERN_DEBUG "%s is not supported attribute for this client\n",data->sysstatus_addr_attrs[i].aname); + printk(KERN_DEBUG "%s is not supported attribute for this client\n",attr->dev_attr.attr.name); status = 0; + return sprintf(buf, "0x%x\n", status); } else { @@ -173,7 +175,7 @@ ssize_t store_sysstatus_data(struct device *dev, struct device_attribute *da, co if (sysstatus_addr_attrs==NULL) { - printk(KERN_DEBUG "%s is not supported attribute for this client\n",data->sysstatus_addr_attrs[i].aname); + printk(KERN_DEBUG "%s is not supported attribute for this client\n",attr->dev_attr.attr.name); return -EINVAL; } else @@ -207,7 +209,7 @@ static ssize_t do_attr_operation(struct device *dev, struct device_attribute *da #ifdef __STDC_LIB_EXT1__ memset_s(&pdata->sysstatus_addr_attr, sizeof(pdata->sysstatus_addr_attr, 0, sizeof(pdata->sysstatus_addr_attr)); #else - memset(&pdata->sysstatus_addr_attr, 0, sizeof(pdata->sysstatus_addr_attr)); + _memset(&pdata->sysstatus_addr_attr, 0, sizeof(pdata->sysstatus_addr_attr)); #endif return count; diff --git a/platform/broadcom/sonic-platform-modules-ufispace/s8901-54xc/modules/x86-64-ufispace-s8901-54xc-cpld.c b/platform/broadcom/sonic-platform-modules-ufispace/s8901-54xc/modules/x86-64-ufispace-s8901-54xc-cpld.c index 63eec91d4819..8634aabe9676 100644 --- a/platform/broadcom/sonic-platform-modules-ufispace/s8901-54xc/modules/x86-64-ufispace-s8901-54xc-cpld.c +++ b/platform/broadcom/sonic-platform-modules-ufispace/s8901-54xc/modules/x86-64-ufispace-s8901-54xc-cpld.c @@ -1050,7 +1050,7 @@ static ssize_t write_bsp_callback(struct device *dev, switch (attr->index) { case BSP_DEBUG: str = bsp_debug; - str_len = sizeof(str); + str_len = sizeof(bsp_debug); ret = write_bsp(buf, str, str_len, count); if (kstrtou8(buf, 0, &bsp_debug_u8) < 0) { diff --git a/platform/broadcom/sonic-platform-modules-ufispace/s8901-54xc/modules/x86-64-ufispace-s8901-54xc-sys-eeprom.c b/platform/broadcom/sonic-platform-modules-ufispace/s8901-54xc/modules/x86-64-ufispace-s8901-54xc-sys-eeprom.c index f9f7728deb3d..31b605bb3d6d 100644 --- a/platform/broadcom/sonic-platform-modules-ufispace/s8901-54xc/modules/x86-64-ufispace-s8901-54xc-sys-eeprom.c +++ b/platform/broadcom/sonic-platform-modules-ufispace/s8901-54xc/modules/x86-64-ufispace-s8901-54xc-sys-eeprom.c @@ -28,6 +28,8 @@ #include #include +#define _memset(s, c, n) memset(s, c, n) + /* Addresses to scan */ static const unsigned short normal_i2c[] = { /*0x50, 0x51, 0x52, 0x53, 0x54, 0x55, 0x56, 0x57,*/ I2C_CLIENT_END }; @@ -220,7 +222,7 @@ static int sys_eeprom_probe(struct i2c_client *client, #ifdef __STDC_LIB_EXT1__ memset_s(data->data, EEPROM_SIZE, 0xff, EEPROM_SIZE); #else - memset(data->data, 0xff, EEPROM_SIZE); + _memset(data->data, 0xff, EEPROM_SIZE); #endif i2c_set_clientdata(client, data); mutex_init(&data->update_lock); diff --git a/platform/broadcom/sonic-platform-modules-ufispace/s8901-54xc/sonic_platform/chassis.py b/platform/broadcom/sonic-platform-modules-ufispace/s8901-54xc/sonic_platform/chassis.py index 085f2af2ff85..0b02f9a834c2 100644 --- a/platform/broadcom/sonic-platform-modules-ufispace/s8901-54xc/sonic_platform/chassis.py +++ b/platform/broadcom/sonic-platform-modules-ufispace/s8901-54xc/sonic_platform/chassis.py @@ -191,3 +191,14 @@ def get_reboot_cause(self): sw_reboot_cause = "Unknown" return ('REBOOT_CAUSE_NON_HARDWARE', sw_reboot_cause) + + def get_serial_number(self): + """ + Retrieves the hardware serial number for the chassis + + Returns: + A string containing the hardware serial number for this + chassis. + """ + + return self.get_serial() \ No newline at end of file diff --git a/platform/broadcom/sonic-platform-modules-ufispace/s8901-54xc/sonic_platform/component.py b/platform/broadcom/sonic-platform-modules-ufispace/s8901-54xc/sonic_platform/component.py index 1c583079f8c2..d5d8d8226fd8 100644 --- a/platform/broadcom/sonic-platform-modules-ufispace/s8901-54xc/sonic_platform/component.py +++ b/platform/broadcom/sonic-platform-modules-ufispace/s8901-54xc/sonic_platform/component.py @@ -18,9 +18,7 @@ } BMC_CMDS = { - "VER1": "ipmitool mc info | grep 'Firmware Revision' | cut -d':' -f2 | cut -d'.' -f1", - "VER2": "ipmitool mc info | grep 'Firmware Revision' | cut -d':' -f2 | cut -d'.' -f2", - "VER3": "echo $((`ipmitool mc info | grep 'Aux Firmware Rev Info' -A 2 | sed -n '2p'` + 0))", + "BMC": "bash -c 'tmp=$(ipmitool raw 0x6 0x1) && r=($(echo \"$tmp\" | cut -d \" \" -f 4,5,16,15,14)) && echo ${r[0]}.${r[1]}.${r[4]}.${r[3]}${r[2]}'", } BIOS_VERSION_PATH = "/sys/class/dmi/id/bios_version" @@ -69,17 +67,11 @@ def _get_cpld_version(self): def _get_bmc_version(self): # Retrieves the BMC firmware version - bmc_ver = dict() - for ver in BMC_CMDS: - status, value = subprocess.getstatusoutput(BMC_CMDS[ver]) - if not status: - bmc_ver[ver] = int(value.rstrip()) - else: - return None - - bmc_version = "{}.{}.{}".format(bmc_ver["VER1"], bmc_ver["VER2"], bmc_ver["VER3"]) - - return bmc_version + status, value = subprocess.getstatusoutput(BMC_CMDS["BMC"]) + if not status: + return value + else: + return None def get_name(self): """ diff --git a/platform/broadcom/sonic-platform-modules-ufispace/s8901-54xc/sonic_platform/psu.py b/platform/broadcom/sonic-platform-modules-ufispace/s8901-54xc/sonic_platform/psu.py index 38b32412d024..cae583254015 100644 --- a/platform/broadcom/sonic-platform-modules-ufispace/s8901-54xc/sonic_platform/psu.py +++ b/platform/broadcom/sonic-platform-modules-ufispace/s8901-54xc/sonic_platform/psu.py @@ -36,3 +36,32 @@ def get_power(self): # power is returned in micro watts return round(float(self.get_voltage()*self.get_current()), 2) + + def get_capacity(self): + """ + Retrieves the maximum supplied power by PSU (or PSU capacity) + Returns: + A float number, the maximum power output in Watts. + e.g. 1200.1 + """ + return self.get_maximum_supplied_power() + + def get_type(self): + """ + Gets the type of the PSU + + Returns: + A string, the type of PSU (AC/DC) + """ + mfr = self.get_mfr_id() + model = self.get_model() + ptype = self.plugin_data['PSU']['valmap']['DEFAULT_TYPE'] + + if mfr and model : + for dev in self.plugin_data['PSU']['psu_support_list']: + if dev['Manufacturer'] == mfr and dev['Name'] == model: + ptype = dev['Type'] + break + + + return ptype \ No newline at end of file diff --git a/platform/broadcom/sonic-platform-modules-ufispace/s8901-54xc/utils/pddf_post_device_create.sh b/platform/broadcom/sonic-platform-modules-ufispace/s8901-54xc/utils/pddf_post_device_create.sh index 4a55252ea936..c6fe10aba368 100755 --- a/platform/broadcom/sonic-platform-modules-ufispace/s8901-54xc/utils/pddf_post_device_create.sh +++ b/platform/broadcom/sonic-platform-modules-ufispace/s8901-54xc/utils/pddf_post_device_create.sh @@ -6,7 +6,7 @@ timeout 3 ipmitool mc watchdog off pddf_ledutil setstatusled SYNC_LED off pddf_ledutil setstatusled SYS_LED off -pddf_ledutil setstatusled ID_LED off +pddf_ledutil setstatusled LOC_LED off #set status led to green to indicate platform init done curr_led=$(pddf_ledutil getstatusled SYS_LED) diff --git a/platform/broadcom/sonic-platform-modules-ufispace/s8901-54xc/utils/pddf_pre_driver_install.sh b/platform/broadcom/sonic-platform-modules-ufispace/s8901-54xc/utils/pddf_pre_driver_install.sh deleted file mode 100755 index 9ada6c235c48..000000000000 --- a/platform/broadcom/sonic-platform-modules-ufispace/s8901-54xc/utils/pddf_pre_driver_install.sh +++ /dev/null @@ -1,8 +0,0 @@ -#!/bin/bash -#rmmod gpio_ich -if [ ! -f /tmp/._pddf_pre_driver_init_completion ]; then - rmmod i2c_i801 - rmmod i2c_ismt - date > /tmp/._pddf_pre_driver_init_completion -fi -echo "PDDF driver pre-install completed" diff --git a/platform/broadcom/sonic-platform-modules-ufispace/s8901-54xc/utils/pre_pddf_init.sh b/platform/broadcom/sonic-platform-modules-ufispace/s8901-54xc/utils/pre_pddf_init.sh deleted file mode 100755 index 63a2e205808e..000000000000 --- a/platform/broadcom/sonic-platform-modules-ufispace/s8901-54xc/utils/pre_pddf_init.sh +++ /dev/null @@ -1,5 +0,0 @@ -#!/bin/bash -#rmmod gpio_ich -modprobe -rq i2c_i801 -modprobe -rq i2c_smbus -echo "Pre PDDF init steps completed successully" diff --git a/platform/broadcom/sonic-platform-modules-ufispace/s9110-32x/modules/pddf_custom_sysstatus_module.c b/platform/broadcom/sonic-platform-modules-ufispace/s9110-32x/modules/pddf_custom_sysstatus_module.c index 35a032f4277e..ace5c9d8cbe0 100644 --- a/platform/broadcom/sonic-platform-modules-ufispace/s9110-32x/modules/pddf_custom_sysstatus_module.c +++ b/platform/broadcom/sonic-platform-modules-ufispace/s9110-32x/modules/pddf_custom_sysstatus_module.c @@ -1,6 +1,6 @@ /* * Copyright 2019 Broadcom. - * The term ��Broadcom�� refers to Broadcom Inc. and/or its subsidiaries. + * The term "Broadcom" refers to Broadcom Inc. and/or its subsidiaries. * * 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 @@ -33,6 +33,7 @@ #include "../../../../pddf/i2c/modules/include/pddf_client_defs.h" #include "../../../../pddf/i2c/modules/include/pddf_sysstatus_defs.h" +#define _memset(s, c, n) memset(s, c, n) SYSSTATUS_DATA sysstatus_data = {0}; @@ -140,8 +141,9 @@ ssize_t show_sysstatus_data(struct device *dev, struct device_attribute *da, cha if (sysstatus_addr_attrs==NULL ) { - printk(KERN_DEBUG "%s is not supported attribute for this client\n",data->sysstatus_addr_attrs[i].aname); + printk(KERN_DEBUG "%s is not supported attribute for this client\n",attr->dev_attr.attr.name); status = 0; + return sprintf(buf, "0x%x\n", status); } else { @@ -171,7 +173,7 @@ ssize_t store_sysstatus_data(struct device *dev, struct device_attribute *da, co if (sysstatus_addr_attrs==NULL) { - printk(KERN_DEBUG "%s is not supported attribute for this client\n",data->sysstatus_addr_attrs[i].aname); + printk(KERN_DEBUG "%s is not supported attribute for this client\n",attr->dev_attr.attr.name); return -EINVAL; } else @@ -205,7 +207,7 @@ static ssize_t do_attr_operation(struct device *dev, struct device_attribute *da #ifdef __STDC_LIB_EXT1__ memset_s(&pdata->sysstatus_addr_attr, sizeof(pdata->sysstatus_addr_attr, 0, sizeof(pdata->sysstatus_addr_attr)); #else - memset(&pdata->sysstatus_addr_attr, 0, sizeof(pdata->sysstatus_addr_attr)); + _memset(&pdata->sysstatus_addr_attr, 0, sizeof(pdata->sysstatus_addr_attr)); #endif return count; diff --git a/platform/broadcom/sonic-platform-modules-ufispace/s9110-32x/modules/x86-64-ufispace-s9110-32x-cpld.c b/platform/broadcom/sonic-platform-modules-ufispace/s9110-32x/modules/x86-64-ufispace-s9110-32x-cpld.c index af54108ee1b3..4bbd43d8bdcc 100644 --- a/platform/broadcom/sonic-platform-modules-ufispace/s9110-32x/modules/x86-64-ufispace-s9110-32x-cpld.c +++ b/platform/broadcom/sonic-platform-modules-ufispace/s9110-32x/modules/x86-64-ufispace-s9110-32x-cpld.c @@ -863,7 +863,7 @@ static ssize_t bsp_callback_store(struct device *dev, switch (attr->index) { case BSP_DEBUG: str = bsp_debug; - str_len = sizeof(str); + str_len = sizeof(bsp_debug); ret = bsp_write(buf, str, str_len, count); if (kstrtou8(buf, 0, &bsp_debug_u8) < 0) { @@ -1272,8 +1272,6 @@ static int cpld_probe(struct i2c_client *client, if (INVALID(ret, cpld1, cpld2)) { dev_info(&client->dev, "cpld id %d(device) not valid\n", ret); - //status = -EPERM; - //goto exit; } data->index = dev_id->driver_data; diff --git a/platform/broadcom/sonic-platform-modules-ufispace/s9110-32x/modules/x86-64-ufispace-s9110-32x-sys-eeprom.c b/platform/broadcom/sonic-platform-modules-ufispace/s9110-32x/modules/x86-64-ufispace-s9110-32x-sys-eeprom.c index 976ba05052e7..e87fc4e9de3c 100644 --- a/platform/broadcom/sonic-platform-modules-ufispace/s9110-32x/modules/x86-64-ufispace-s9110-32x-sys-eeprom.c +++ b/platform/broadcom/sonic-platform-modules-ufispace/s9110-32x/modules/x86-64-ufispace-s9110-32x-sys-eeprom.c @@ -28,6 +28,8 @@ #include #include +#define _memset(s, c, n) memset(s, c, n) + /* Addresses to scan */ static const unsigned short normal_i2c[] = { /*0x50, 0x51, 0x52, 0x53, 0x54, 0x55, 0x56, 0x57,*/ I2C_CLIENT_END }; @@ -220,7 +222,7 @@ static int sys_eeprom_probe(struct i2c_client *client, #ifdef __STDC_LIB_EXT1__ memset_s(data->data, EEPROM_SIZE, 0xff, EEPROM_SIZE); #else - memset(data->data, 0xff, EEPROM_SIZE); + _memset(data->data, 0xff, EEPROM_SIZE); #endif i2c_set_clientdata(client, data); mutex_init(&data->update_lock); diff --git a/platform/broadcom/sonic-platform-modules-ufispace/s9110-32x/sonic_platform/chassis.py b/platform/broadcom/sonic-platform-modules-ufispace/s9110-32x/sonic_platform/chassis.py index 530332cf1506..78a3d9d4106a 100644 --- a/platform/broadcom/sonic-platform-modules-ufispace/s9110-32x/sonic_platform/chassis.py +++ b/platform/broadcom/sonic-platform-modules-ufispace/s9110-32x/sonic_platform/chassis.py @@ -189,3 +189,14 @@ def get_reboot_cause(self): sw_reboot_cause = "Unknown" return ('REBOOT_CAUSE_NON_HARDWARE', sw_reboot_cause) + + def get_serial_number(self): + """ + Retrieves the hardware serial number for the chassis + + Returns: + A string containing the hardware serial number for this + chassis. + """ + + return self.get_serial() \ No newline at end of file diff --git a/platform/broadcom/sonic-platform-modules-ufispace/s9110-32x/sonic_platform/component.py b/platform/broadcom/sonic-platform-modules-ufispace/s9110-32x/sonic_platform/component.py index 1c583079f8c2..d5d8d8226fd8 100644 --- a/platform/broadcom/sonic-platform-modules-ufispace/s9110-32x/sonic_platform/component.py +++ b/platform/broadcom/sonic-platform-modules-ufispace/s9110-32x/sonic_platform/component.py @@ -18,9 +18,7 @@ } BMC_CMDS = { - "VER1": "ipmitool mc info | grep 'Firmware Revision' | cut -d':' -f2 | cut -d'.' -f1", - "VER2": "ipmitool mc info | grep 'Firmware Revision' | cut -d':' -f2 | cut -d'.' -f2", - "VER3": "echo $((`ipmitool mc info | grep 'Aux Firmware Rev Info' -A 2 | sed -n '2p'` + 0))", + "BMC": "bash -c 'tmp=$(ipmitool raw 0x6 0x1) && r=($(echo \"$tmp\" | cut -d \" \" -f 4,5,16,15,14)) && echo ${r[0]}.${r[1]}.${r[4]}.${r[3]}${r[2]}'", } BIOS_VERSION_PATH = "/sys/class/dmi/id/bios_version" @@ -69,17 +67,11 @@ def _get_cpld_version(self): def _get_bmc_version(self): # Retrieves the BMC firmware version - bmc_ver = dict() - for ver in BMC_CMDS: - status, value = subprocess.getstatusoutput(BMC_CMDS[ver]) - if not status: - bmc_ver[ver] = int(value.rstrip()) - else: - return None - - bmc_version = "{}.{}.{}".format(bmc_ver["VER1"], bmc_ver["VER2"], bmc_ver["VER3"]) - - return bmc_version + status, value = subprocess.getstatusoutput(BMC_CMDS["BMC"]) + if not status: + return value + else: + return None def get_name(self): """ diff --git a/platform/broadcom/sonic-platform-modules-ufispace/s9110-32x/sonic_platform/fan.py b/platform/broadcom/sonic-platform-modules-ufispace/s9110-32x/sonic_platform/fan.py index c38ebdedea5b..3705fae2bf7c 100644 --- a/platform/broadcom/sonic-platform-modules-ufispace/s9110-32x/sonic_platform/fan.py +++ b/platform/broadcom/sonic-platform-modules-ufispace/s9110-32x/sonic_platform/fan.py @@ -108,7 +108,6 @@ def get_presence(self): if not output: return False - mode = output['mode'] presence = output['status'].rstrip() vmap = self.plugin_data['FAN']['present'][mode]['valmap'] diff --git a/platform/broadcom/sonic-platform-modules-ufispace/s9110-32x/sonic_platform/psu.py b/platform/broadcom/sonic-platform-modules-ufispace/s9110-32x/sonic_platform/psu.py index 4f7e843361d4..091926788328 100644 --- a/platform/broadcom/sonic-platform-modules-ufispace/s9110-32x/sonic_platform/psu.py +++ b/platform/broadcom/sonic-platform-modules-ufispace/s9110-32x/sonic_platform/psu.py @@ -35,4 +35,33 @@ def get_maximum_supplied_power(self): A float number, the maximum power output in Watts. e.g. 1200.1 """ - return float(self.PLATFORM_PSU_CAPACITY) \ No newline at end of file + return float(self.PLATFORM_PSU_CAPACITY) + + def get_capacity(self): + """ + Retrieves the maximum supplied power by PSU (or PSU capacity) + Returns: + A float number, the maximum power output in Watts. + e.g. 1200.1 + """ + return self.get_maximum_supplied_power() + + def get_type(self): + """ + Gets the type of the PSU + + Returns: + A string, the type of PSU (AC/DC) + """ + mfr = self.get_mfr_id() + model = self.get_model() + ptype = self.plugin_data['PSU']['valmap']['DEFAULT_TYPE'] + + if mfr and model : + for dev in self.plugin_data['PSU']['psu_support_list']: + if dev['Manufacturer'] == mfr and dev['Name'] == model: + ptype = dev['Type'] + break + + + return ptype \ No newline at end of file diff --git a/platform/broadcom/sonic-platform-modules-ufispace/s9110-32x/utils/pddf_post_device_create.sh b/platform/broadcom/sonic-platform-modules-ufispace/s9110-32x/utils/pddf_post_device_create.sh index 47076d99c4ca..f38d420267d2 100755 --- a/platform/broadcom/sonic-platform-modules-ufispace/s9110-32x/utils/pddf_post_device_create.sh +++ b/platform/broadcom/sonic-platform-modules-ufispace/s9110-32x/utils/pddf_post_device_create.sh @@ -5,7 +5,7 @@ echo "Disable BMC watchdog" timeout 3 ipmitool mc watchdog off pddf_ledutil setstatusled SYS_LED off -pddf_ledutil setstatusled ID_LED off +pddf_ledutil setstatusled LOC_LED off curr_led=$(pddf_ledutil getstatusled SYS_LED) pddf_ledutil setstatusled SYS_LED green diff --git a/platform/broadcom/sonic-platform-modules-ufispace/s9110-32x/utils/pddf_pre_driver_install.sh b/platform/broadcom/sonic-platform-modules-ufispace/s9110-32x/utils/pddf_pre_driver_install.sh deleted file mode 100755 index 187943061e6c..000000000000 --- a/platform/broadcom/sonic-platform-modules-ufispace/s9110-32x/utils/pddf_pre_driver_install.sh +++ /dev/null @@ -1,11 +0,0 @@ -#!/bin/bash -#rmmod gpio_ich -if [ ! -f /tmp/._pddf_pre_driver_init_completion ]; then - # make sure igb/i40e init in correct order - rmmod i2c-i801 - rmmod i2c_ismt - modprobe -r i2c-i801 - modprobe -r i2c_ismt - date > /tmp/._pddf_pre_driver_init_completion -fi -echo "PDDF driver pre-install completed" diff --git a/platform/broadcom/sonic-platform-modules-ufispace/s9300-32d/modules/pddf_custom_sysstatus_module.c b/platform/broadcom/sonic-platform-modules-ufispace/s9300-32d/modules/pddf_custom_sysstatus_module.c index 7a0b03a70d65..b61219c0088d 100644 --- a/platform/broadcom/sonic-platform-modules-ufispace/s9300-32d/modules/pddf_custom_sysstatus_module.c +++ b/platform/broadcom/sonic-platform-modules-ufispace/s9300-32d/modules/pddf_custom_sysstatus_module.c @@ -1,6 +1,6 @@ /* * Copyright 2019 Broadcom. - * The term ¡§Broadcom¡¨ refers to Broadcom Inc. and/or its subsidiaries. + * The term "Broadcom" refers to Broadcom Inc. and/or its subsidiaries. * * 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 @@ -33,6 +33,7 @@ #include "../../../../pddf/i2c/modules/include/pddf_client_defs.h" #include "../../../../pddf/i2c/modules/include/pddf_sysstatus_defs.h" +#define _memset(s, c, n) memset(s, c, n) SYSSTATUS_DATA sysstatus_data = {0}; @@ -132,7 +133,7 @@ ssize_t show_sysstatus_data(struct device *dev, struct device_attribute *da, cha if (sysstatus_addr_attrs==NULL ) { - printk(KERN_DEBUG "%s is not supported attribute for this client\n",data->sysstatus_addr_attrs[i].aname); + printk(KERN_DEBUG "%s is not supported attribute for this client\n",attr->dev_attr.attr.name); status = 0; } else @@ -163,7 +164,7 @@ ssize_t store_sysstatus_data(struct device *dev, struct device_attribute *da, co if (sysstatus_addr_attrs==NULL) { - printk(KERN_DEBUG "%s is not supported attribute for this client\n",data->sysstatus_addr_attrs[i].aname); + printk(KERN_DEBUG "%s is not supported attribute for this client\n",attr->dev_attr.attr.name); return -EINVAL; } else @@ -196,7 +197,7 @@ static ssize_t do_attr_operation(struct device *dev, struct device_attribute *da #ifdef __STDC_LIB_EXT1__ memset_s(&pdata->sysstatus_addr_attr, sizeof(pdata->sysstatus_addr_attr), 0, sizeof(pdata->sysstatus_addr_attr)); #else - memset(&pdata->sysstatus_addr_attr, 0, sizeof(pdata->sysstatus_addr_attr)); + _memset(&pdata->sysstatus_addr_attr, 0, sizeof(pdata->sysstatus_addr_attr)); #endif return count; diff --git a/platform/broadcom/sonic-platform-modules-ufispace/s9300-32d/modules/x86-64-ufispace-s9300-32d-cpld.c b/platform/broadcom/sonic-platform-modules-ufispace/s9300-32d/modules/x86-64-ufispace-s9300-32d-cpld.c index 39f6694140e2..657f9753dfed 100644 --- a/platform/broadcom/sonic-platform-modules-ufispace/s9300-32d/modules/x86-64-ufispace-s9300-32d-cpld.c +++ b/platform/broadcom/sonic-platform-modules-ufispace/s9300-32d/modules/x86-64-ufispace-s9300-32d-cpld.c @@ -1,1638 +1,1638 @@ -/* - * A i2c cpld driver for the ufispace_s9300_32d - * - * Copyright (C) 2017-2019 UfiSpace Technology Corporation. - * Jason Tsai - * - * Based on ad7414.c - * Copyright 2006 Stefan Roese , DENX Software Engineering - * - * 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. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. - */ -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include "x86-64-ufispace-s9300-32d-cpld.h" - -#ifdef DEBUG -#define DEBUG_PRINT(fmt, args...) \ - printk(KERN_INFO "%s:%s[%d]: " fmt "\r\n", \ - __FILE__, __func__, __LINE__, ##args) -#else -#define DEBUG_PRINT(fmt, args...) -#endif - -#define BSP_LOG_R(fmt, args...) \ - _bsp_log (LOG_READ, KERN_INFO "%s:%s[%d]: " fmt "\r\n", \ - __FILE__, __func__, __LINE__, ##args) -#define BSP_LOG_W(fmt, args...) \ - _bsp_log (LOG_WRITE, KERN_INFO "%s:%s[%d]: " fmt "\r\n", \ - __FILE__, __func__, __LINE__, ##args) - -#define I2C_READ_BYTE_DATA(ret, lock, i2c_client, reg) \ -{ \ - mutex_lock(lock); \ - ret = i2c_smbus_read_byte_data(i2c_client, reg); \ - mutex_unlock(lock); \ - BSP_LOG_R("cpld[%d], reg=0x%03x, reg_val=0x%02x", data->index, reg, ret); \ -} -#define I2C_WRITE_BYTE_DATA(ret, lock, i2c_client, reg, val) \ -{ \ - mutex_lock(lock); \ - ret = i2c_smbus_write_byte_data(i2c_client, reg, val); \ - mutex_unlock(lock); \ - BSP_LOG_W("cpld[%d], reg=0x%03x, reg_val=0x%02x", data->index, reg, val); \ -} - -/* CPLD sysfs attributes index */ -enum s9300_cpld_sysfs_attributes { - /* CPLD1 */ - CPLD_ACCESS_REG, - CPLD_REGISTER_VAL, - CPLD_SKU_ID, - CPLD_HW_REV, - CPLD_DEPH_REV, - CPLD_BUILD_REV, - CPLD_ID_TYPE, - CPLD_MAJOR_VER, - CPLD_MINOR_VER, - CPLD_BUILD_VER, - CPLD_VERION_H, - CPLD_ID, - CPLD_MAC_INTR, - CPLD_10G_PHY_INTR, - CPLD_CPLD_FRU_INTR, - CPLD_THERMAL_ALERT_INTR, - CPLD_MISC_INTR, - CPLD_SYSTEM_INTR, - CPLD_MAC_INTR_MASK, - CPLD_10G_PHY_INTR_MASK, - CPLD_CPLD_FRU_INTR_MASK, - CPLD_THERMAL_ALERT_INTR_MASK, - CPLD_MISC_INTR_MASK, - CPLD_MAC_INTR_EVENT, - CPLD_10G_PHY_INTR_EVENT, - CPLD_CPLD_FRU_INTR_EVENT, - CPLD_THERMAL_ALERT_INTR_EVENT, - CPLD_MISC_INTR_EVENT, - CPLD_MAC_RST, - CPLD_10G_PHY_RST, - CPLD_BMC_RST, - CPLD_USB_RST, - CPLD_MUX_RST, - CPLD_MISC_RST, - CPLD_BMC_WATCHDOG, - CPLD_DAU_BD_PRES, - CPLD_PSU_STATUS, - CPLD_SYS_PW_STATUS, - CPLD_MISC, - CPLD_MUX_CTRL, - CPLD_MAC_QSFP_SEL_CTRL, - CPLD_SYS_LED_CTRL_1, - CPLD_SYS_LED_CTRL_2, - CPLD_BEACON_LED_CTRL, - CPLD_PORT_LED_CLR_CTRL, - CPLD_EVENT_DETECT_CTRL, - /* CPLD2 */ - CPLD_QSFPDD_MOD_INT_G0, - CPLD_QSFPDD_MOD_INT_G1, - CPLD_QSFPDD_MOD_INT_G2, - CPLD_QSFPDD_MOD_INT_G3, - CPLD_QSFPDD_PRES_G0, - CPLD_QSFPDD_PRES_G1, - CPLD_QSFPDD_PRES_G2, - CPLD_QSFPDD_PRES_G3, - CPLD_QSFPDD_FUSE_INT_G0, - CPLD_QSFPDD_FUSE_INT_G1, - CPLD_QSFPDD_FUSE_INT_G2, - CPLD_QSFPDD_FUSE_INT_G3, - CPLD_SFP_TXFAULT, - CPLD_SFP_ABS, - CPLD_SFP_RXLOS, - CPLD_QSFPDD_MOD_INT_MASK_G0, - CPLD_QSFPDD_MOD_INT_MASK_G1, - CPLD_QSFPDD_MOD_INT_MASK_G2, - CPLD_QSFPDD_MOD_INT_MASK_G3, - CPLD_QSFPDD_PRES_MASK_G0, - CPLD_QSFPDD_PRES_MASK_G1, - CPLD_QSFPDD_PRES_MASK_G2, - CPLD_QSFPDD_PRES_MASK_G3, - CPLD_QSFPDD_FUSE_INT_MASK_G0, - CPLD_QSFPDD_FUSE_INT_MASK_G1, - CPLD_QSFPDD_FUSE_INT_MASK_G2, - CPLD_QSFPDD_FUSE_INT_MASK_G3, - CPLD_SFP_TXFAULT_MASK, - CPLD_SFP_ABS_MASK, - CPLD_SFP_RXLOS_MASK, - CPLD_QSFPDD_MOD_INT_EVENT_G0, - CPLD_QSFPDD_MOD_INT_EVENT_G1, - CPLD_QSFPDD_MOD_INT_EVENT_G2, - CPLD_QSFPDD_MOD_INT_EVENT_G3, - CPLD_QSFPDD_PRES_EVENT_G0, - CPLD_QSFPDD_PRES_EVENT_G1, - CPLD_QSFPDD_PRES_EVENT_G2, - CPLD_QSFPDD_PRES_EVENT_G3, - CPLD_QSFPDD_FUSE_INT_EVENT_G0, - CPLD_QSFPDD_FUSE_INT_EVENT_G1, - CPLD_QSFPDD_FUSE_INT_EVENT_G2, - CPLD_QSFPDD_FUSE_INT_EVENT_G3, - CPLD_SFP_TXFAULT_EVENT, - CPLD_SFP_ABS_EVENT, - CPLD_SFP_RXLOS_EVENT, - CPLD_QSFPDD_RESET_CTRL_G0, - CPLD_QSFPDD_RESET_CTRL_G1, - CPLD_QSFPDD_RESET_CTRL_G2, - CPLD_QSFPDD_RESET_CTRL_G3, - CPLD_QSFPDD_LP_MODE_G0, - CPLD_QSFPDD_LP_MODE_G1, - CPLD_QSFPDD_LP_MODE_G2, - CPLD_QSFPDD_LP_MODE_G3, - CPLD_SFP_TX_DIS, - CPLD_SFP_RS, - CPLD_SFP_TS, - CPLD_PORT_INT_STATUS, - - //BSP DEBUG - BSP_DEBUG -}; - -enum bsp_log_types { - LOG_NONE, - LOG_RW, - LOG_READ, - LOG_WRITE -}; - -enum bsp_log_ctrl { - LOG_DISABLE, - LOG_ENABLE -}; - -/* CPLD sysfs attributes hook functions */ -static ssize_t read_access_register(struct device *dev, - struct device_attribute *da, char *buf); -static ssize_t write_access_register(struct device *dev, - struct device_attribute *da, const char *buf, size_t count); -static ssize_t read_register_value(struct device *dev, - struct device_attribute *da, char *buf); -static ssize_t write_register_value(struct device *dev, - struct device_attribute *da, const char *buf, size_t count); -static ssize_t read_hw_rev_cb(struct device *dev, - struct device_attribute *da, char *buf); -static ssize_t read_cpld_version_cb(struct device *dev, - struct device_attribute *da, char *buf); -static ssize_t read_cpld_callback(struct device *dev, - struct device_attribute *da, char *buf); -static ssize_t write_cpld_callback(struct device *dev, - struct device_attribute *da, const char *buf, size_t count); -static ssize_t read_cpld_version_h_cb(struct device *dev, - struct device_attribute *da, char *buf); -// cpld access api -static ssize_t read_cpld_reg(struct device *dev, char *buf, u8 reg); -static ssize_t write_cpld_reg(struct device *dev, const char *buf, size_t count, u8 reg); -static bool read_cpld_reg_raw_byte(struct device *dev, u8 reg, u8 *val, int *errno); -static bool read_cpld_reg_raw_int(struct device *dev, u8 reg, int *val); -// bsp debug api -static ssize_t read_bsp(char *buf, char *str); -static ssize_t write_bsp(const char *buf, char *str, size_t str_len, size_t count); -static ssize_t read_bsp_callback(struct device *dev, - struct device_attribute *da, char *buf); -static ssize_t write_bsp_callback(struct device *dev, - struct device_attribute *da, const char *buf, size_t count); - -static LIST_HEAD(cpld_client_list); /* client list for cpld */ -static struct mutex list_lock; /* mutex for client list */ - -struct cpld_client_node { - struct i2c_client *client; - struct list_head list; -}; - -struct cpld_data { - int index; /* CPLD index */ - struct mutex access_lock; /* mutex for cpld access */ - u8 access_reg; /* register to access */ -}; - -/* CPLD device id and data */ -static const struct i2c_device_id s9300_cpld_id[] = { - { "s9300_32d_cpld1", cpld1 }, - { "s9300_32d_cpld2", cpld2 }, - { "s9300_32d_cpld3", cpld3 }, - {} -}; - -char bsp_debug[2]="0"; -u8 enable_log_read=LOG_DISABLE; -u8 enable_log_write=LOG_DISABLE; - -/* Addresses scanned for s9300_cpld */ -static const unsigned short cpld_i2c_addr[] = { 0x30, 0x31, 0x32, I2C_CLIENT_END }; - -/* define all support register access of cpld in attribute */ -/* CPLD1 */ -static SENSOR_DEVICE_ATTR(cpld_access_register, S_IWUSR | S_IRUGO, \ - read_access_register, write_access_register, CPLD_ACCESS_REG); -static SENSOR_DEVICE_ATTR(cpld_register_value, S_IWUSR | S_IRUGO, \ - read_register_value, write_register_value, CPLD_REGISTER_VAL); -static SENSOR_DEVICE_ATTR(cpld_sku_id, S_IRUGO, \ - read_cpld_callback, NULL, CPLD_SKU_ID); -static SENSOR_DEVICE_ATTR(cpld_hw_rev, S_IRUGO, \ - read_hw_rev_cb, NULL, CPLD_HW_REV); -static SENSOR_DEVICE_ATTR(cpld_deph_rev, S_IRUGO, \ - read_hw_rev_cb, NULL, CPLD_DEPH_REV); -static SENSOR_DEVICE_ATTR(cpld_build_rev, S_IRUGO, \ - read_hw_rev_cb, NULL, CPLD_BUILD_REV); -static SENSOR_DEVICE_ATTR(cpld_id_type, S_IRUGO, \ - read_hw_rev_cb, NULL, CPLD_ID_TYPE); -static SENSOR_DEVICE_ATTR(cpld_major_ver, S_IRUGO, \ - read_cpld_version_cb, NULL, CPLD_MAJOR_VER); -static SENSOR_DEVICE_ATTR(cpld_minor_ver, S_IRUGO, \ - read_cpld_version_cb, NULL, CPLD_MINOR_VER); -static SENSOR_DEVICE_ATTR(cpld_build_ver, S_IRUGO, \ - read_cpld_callback, NULL, CPLD_BUILD_VER); -static SENSOR_DEVICE_ATTR(cpld_version_h, S_IRUGO, \ - read_cpld_version_h_cb, NULL, CPLD_VERION_H); -static SENSOR_DEVICE_ATTR(cpld_id, S_IRUGO, \ - read_cpld_callback, NULL, CPLD_ID); -static SENSOR_DEVICE_ATTR(cpld_mac_intr, S_IRUGO, \ - read_cpld_callback, NULL, CPLD_MAC_INTR); -static SENSOR_DEVICE_ATTR(cpld_10g_phy_intr, S_IRUGO, \ - read_cpld_callback, NULL, CPLD_10G_PHY_INTR); -static SENSOR_DEVICE_ATTR(cpld_cpld_fru_intr, S_IRUGO, \ - read_cpld_callback, NULL, CPLD_CPLD_FRU_INTR); -static SENSOR_DEVICE_ATTR(cpld_thermal_alert_intr, S_IRUGO, \ - read_cpld_callback, NULL, CPLD_THERMAL_ALERT_INTR); -static SENSOR_DEVICE_ATTR(cpld_misc_intr, S_IRUGO, \ - read_cpld_callback, NULL, CPLD_MISC_INTR); -static SENSOR_DEVICE_ATTR(cpld_system_intr, S_IRUGO, \ - read_cpld_callback, NULL, CPLD_SYSTEM_INTR); -static SENSOR_DEVICE_ATTR(cpld_mac_intr_mask, S_IWUSR | S_IRUGO, \ - read_cpld_callback, write_cpld_callback, CPLD_MAC_INTR_MASK); -static SENSOR_DEVICE_ATTR(cpld_10g_phy_intr_mask, S_IWUSR | S_IRUGO, \ - read_cpld_callback, write_cpld_callback, CPLD_10G_PHY_INTR_MASK); -static SENSOR_DEVICE_ATTR(cpld_cpld_fru_intr_mask, S_IWUSR | S_IRUGO, \ - read_cpld_callback, write_cpld_callback, CPLD_CPLD_FRU_INTR_MASK); -static SENSOR_DEVICE_ATTR(cpld_thermal_alert_intr_mask, S_IWUSR | S_IRUGO, \ - read_cpld_callback, write_cpld_callback, CPLD_THERMAL_ALERT_INTR_MASK); -static SENSOR_DEVICE_ATTR(cpld_misc_intr_mask, S_IWUSR | S_IRUGO, \ - read_cpld_callback, write_cpld_callback, CPLD_MISC_INTR_MASK); -static SENSOR_DEVICE_ATTR(cpld_mac_intr_event, S_IRUGO, \ - read_cpld_callback, NULL, CPLD_MAC_INTR_EVENT); -static SENSOR_DEVICE_ATTR(cpld_10g_phy_intr_event, S_IRUGO, \ - read_cpld_callback, NULL, CPLD_10G_PHY_INTR_EVENT); -static SENSOR_DEVICE_ATTR(cpld_cpld_fru_intr_event, S_IRUGO, \ - read_cpld_callback, NULL, CPLD_CPLD_FRU_INTR_EVENT); -static SENSOR_DEVICE_ATTR(cpld_thermal_alert_intr_event, S_IRUGO, \ - read_cpld_callback, NULL, CPLD_THERMAL_ALERT_INTR_EVENT); -static SENSOR_DEVICE_ATTR(cpld_misc_intr_event, S_IRUGO, \ - read_cpld_callback, NULL, CPLD_MISC_INTR_EVENT); -static SENSOR_DEVICE_ATTR(cpld_mac_rst, S_IWUSR | S_IRUGO, \ - read_cpld_callback, write_cpld_callback, CPLD_MAC_RST); -static SENSOR_DEVICE_ATTR(cpld_10g_phy_rst, S_IWUSR | S_IRUGO, \ - read_cpld_callback, write_cpld_callback, CPLD_10G_PHY_RST); -static SENSOR_DEVICE_ATTR(cpld_bmc_rst, S_IWUSR | S_IRUGO, \ - read_cpld_callback, write_cpld_callback, CPLD_BMC_RST); -static SENSOR_DEVICE_ATTR(cpld_usb_rst, S_IWUSR | S_IRUGO, \ - read_cpld_callback, write_cpld_callback, CPLD_USB_RST); -static SENSOR_DEVICE_ATTR(cpld_mux_rst, S_IWUSR | S_IRUGO, \ - read_cpld_callback, write_cpld_callback, CPLD_MUX_RST); -static SENSOR_DEVICE_ATTR(cpld_misc_rst, S_IWUSR | S_IRUGO, \ - read_cpld_callback, write_cpld_callback, CPLD_MISC_RST); -static SENSOR_DEVICE_ATTR(cpld_bmc_watchdog, S_IWUSR | S_IRUGO, \ - read_cpld_callback, write_cpld_callback, CPLD_BMC_WATCHDOG); -static SENSOR_DEVICE_ATTR(cpld_dau_bd_pres, S_IRUGO, \ - read_cpld_callback, NULL, CPLD_DAU_BD_PRES); -static SENSOR_DEVICE_ATTR(cpld_psu_status, S_IRUGO, \ - read_cpld_callback, NULL, CPLD_PSU_STATUS); -static SENSOR_DEVICE_ATTR(cpld_sys_pw_status, S_IRUGO, \ - read_cpld_callback, NULL, CPLD_SYS_PW_STATUS); -static SENSOR_DEVICE_ATTR(cpld_misc, S_IRUGO, \ - read_cpld_callback, NULL, CPLD_MISC); -static SENSOR_DEVICE_ATTR(cpld_mux_ctrl, S_IWUSR | S_IRUGO, \ - read_cpld_callback, write_cpld_callback, CPLD_MUX_CTRL); -static SENSOR_DEVICE_ATTR(cpld_mac_qsfp_sel_ctrl, S_IWUSR | S_IRUGO, \ - read_cpld_callback, write_cpld_callback, CPLD_MAC_QSFP_SEL_CTRL); -static SENSOR_DEVICE_ATTR(cpld_sys_led_ctrl_1, S_IRUGO, \ - read_cpld_callback, NULL, CPLD_SYS_LED_CTRL_1); -static SENSOR_DEVICE_ATTR(cpld_sys_led_ctrl_2, S_IRUGO, \ - read_cpld_callback, NULL, CPLD_SYS_LED_CTRL_2); -static SENSOR_DEVICE_ATTR(cpld_beacon_led_ctrl, S_IWUSR | S_IRUGO, \ - read_cpld_callback, write_cpld_callback, CPLD_BEACON_LED_CTRL); -static SENSOR_DEVICE_ATTR(cpld_port_led_clr_ctrl, S_IWUSR | S_IRUGO, \ - read_cpld_callback, write_cpld_callback, CPLD_PORT_LED_CLR_CTRL); -static SENSOR_DEVICE_ATTR(cpld_event_detect_ctrl, S_IWUSR | S_IRUGO, \ - read_cpld_callback, write_cpld_callback, CPLD_EVENT_DETECT_CTRL); -/* CPLD2 */ -static SENSOR_DEVICE_ATTR(cpld_qsfpdd_mod_int_g0, S_IRUGO, \ - read_cpld_callback, NULL, CPLD_QSFPDD_MOD_INT_G0); -static SENSOR_DEVICE_ATTR(cpld_qsfpdd_mod_int_g1, S_IRUGO, \ - read_cpld_callback, NULL, CPLD_QSFPDD_MOD_INT_G1); -static SENSOR_DEVICE_ATTR(cpld_qsfpdd_mod_int_g2, S_IRUGO, \ - read_cpld_callback, NULL, CPLD_QSFPDD_MOD_INT_G2); -static SENSOR_DEVICE_ATTR(cpld_qsfpdd_mod_int_g3, S_IRUGO, \ - read_cpld_callback, NULL, CPLD_QSFPDD_MOD_INT_G3); -static SENSOR_DEVICE_ATTR(cpld_qsfpdd_pres_g0, S_IRUGO, \ - read_cpld_callback, NULL, CPLD_QSFPDD_PRES_G0); -static SENSOR_DEVICE_ATTR(cpld_qsfpdd_pres_g1, S_IRUGO, \ - read_cpld_callback, NULL, CPLD_QSFPDD_PRES_G1); -static SENSOR_DEVICE_ATTR(cpld_qsfpdd_pres_g2, S_IRUGO, \ - read_cpld_callback, NULL, CPLD_QSFPDD_PRES_G2); -static SENSOR_DEVICE_ATTR(cpld_qsfpdd_pres_g3, S_IRUGO, \ - read_cpld_callback, NULL, CPLD_QSFPDD_PRES_G3); -static SENSOR_DEVICE_ATTR(cpld_qsfpdd_fuse_int_g0, S_IRUGO, \ - read_cpld_callback, NULL, CPLD_QSFPDD_FUSE_INT_G0); -static SENSOR_DEVICE_ATTR(cpld_qsfpdd_fuse_int_g1, S_IRUGO, \ - read_cpld_callback, NULL, CPLD_QSFPDD_FUSE_INT_G1); -static SENSOR_DEVICE_ATTR(cpld_qsfpdd_fuse_int_g2, S_IRUGO, \ - read_cpld_callback, NULL, CPLD_QSFPDD_FUSE_INT_G2); -static SENSOR_DEVICE_ATTR(cpld_qsfpdd_fuse_int_g3, S_IRUGO, \ - read_cpld_callback, NULL, CPLD_QSFPDD_FUSE_INT_G3); -static SENSOR_DEVICE_ATTR(cpld_sfp_txfault, S_IRUGO, \ - read_cpld_callback, NULL, CPLD_SFP_TXFAULT); -static SENSOR_DEVICE_ATTR(cpld_sfp_abs, S_IRUGO, \ - read_cpld_callback, NULL, CPLD_SFP_ABS); -static SENSOR_DEVICE_ATTR(cpld_sfp_rxlos, S_IRUGO, \ - read_cpld_callback, NULL, CPLD_SFP_RXLOS); -static SENSOR_DEVICE_ATTR(cpld_qsfpdd_mod_int_mask_g0, S_IWUSR | S_IRUGO, \ - read_cpld_callback, write_cpld_callback, CPLD_QSFPDD_MOD_INT_MASK_G0); -static SENSOR_DEVICE_ATTR(cpld_qsfpdd_mod_int_mask_g1, S_IWUSR | S_IRUGO, \ - read_cpld_callback, write_cpld_callback, CPLD_QSFPDD_MOD_INT_MASK_G1); -static SENSOR_DEVICE_ATTR(cpld_qsfpdd_mod_int_mask_g2, S_IWUSR | S_IRUGO, \ - read_cpld_callback, write_cpld_callback, CPLD_QSFPDD_MOD_INT_MASK_G2); -static SENSOR_DEVICE_ATTR(cpld_qsfpdd_mod_int_mask_g3, S_IWUSR | S_IRUGO, \ - read_cpld_callback, write_cpld_callback, CPLD_QSFPDD_MOD_INT_MASK_G3); -static SENSOR_DEVICE_ATTR(cpld_qsfpdd_pres_mask_g0, S_IWUSR | S_IRUGO, \ - read_cpld_callback, write_cpld_callback, CPLD_QSFPDD_PRES_MASK_G0); -static SENSOR_DEVICE_ATTR(cpld_qsfpdd_pres_mask_g1, S_IWUSR | S_IRUGO, \ - read_cpld_callback, write_cpld_callback, CPLD_QSFPDD_PRES_MASK_G1); -static SENSOR_DEVICE_ATTR(cpld_qsfpdd_pres_mask_g2, S_IWUSR | S_IRUGO, \ - read_cpld_callback, write_cpld_callback, CPLD_QSFPDD_PRES_MASK_G2); -static SENSOR_DEVICE_ATTR(cpld_qsfpdd_pres_mask_g3, S_IWUSR | S_IRUGO, \ - read_cpld_callback, write_cpld_callback, CPLD_QSFPDD_PRES_MASK_G3); -static SENSOR_DEVICE_ATTR(cpld_qsfpdd_fuse_int_mask_g0, S_IWUSR | S_IRUGO, \ - read_cpld_callback, write_cpld_callback, CPLD_QSFPDD_FUSE_INT_MASK_G0); -static SENSOR_DEVICE_ATTR(cpld_qsfpdd_fuse_int_mask_g1, S_IWUSR | S_IRUGO, \ - read_cpld_callback, write_cpld_callback, CPLD_QSFPDD_FUSE_INT_MASK_G1); -static SENSOR_DEVICE_ATTR(cpld_qsfpdd_fuse_int_mask_g2, S_IWUSR | S_IRUGO, \ - read_cpld_callback, write_cpld_callback, CPLD_QSFPDD_FUSE_INT_MASK_G2); -static SENSOR_DEVICE_ATTR(cpld_qsfpdd_fuse_int_mask_g3, S_IWUSR | S_IRUGO, \ - read_cpld_callback, write_cpld_callback, CPLD_QSFPDD_FUSE_INT_MASK_G3); -static SENSOR_DEVICE_ATTR(cpld_sfp_txfault_mask, S_IWUSR | S_IRUGO, \ - read_cpld_callback, write_cpld_callback, CPLD_SFP_TXFAULT_MASK); -static SENSOR_DEVICE_ATTR(cpld_sfp_abs_mask, S_IWUSR | S_IRUGO, \ - read_cpld_callback, write_cpld_callback, CPLD_SFP_ABS_MASK); -static SENSOR_DEVICE_ATTR(cpld_sfp_rxlos_mask, S_IWUSR | S_IRUGO, \ - read_cpld_callback, write_cpld_callback, CPLD_SFP_RXLOS_MASK); -static SENSOR_DEVICE_ATTR(cpld_qsfpdd_mod_int_event_g0, S_IRUGO, \ - read_cpld_callback, NULL, CPLD_QSFPDD_MOD_INT_EVENT_G0); -static SENSOR_DEVICE_ATTR(cpld_qsfpdd_mod_int_event_g1, S_IRUGO, \ - read_cpld_callback, NULL, CPLD_QSFPDD_MOD_INT_EVENT_G1); -static SENSOR_DEVICE_ATTR(cpld_qsfpdd_mod_int_event_g2, S_IRUGO, \ - read_cpld_callback, NULL, CPLD_QSFPDD_MOD_INT_EVENT_G2); -static SENSOR_DEVICE_ATTR(cpld_qsfpdd_mod_int_event_g3, S_IRUGO, \ - read_cpld_callback, NULL, CPLD_QSFPDD_MOD_INT_EVENT_G3); -static SENSOR_DEVICE_ATTR(cpld_qsfpdd_pres_event_g0, S_IRUGO, \ - read_cpld_callback, NULL, CPLD_QSFPDD_PRES_EVENT_G0); -static SENSOR_DEVICE_ATTR(cpld_qsfpdd_pres_event_g1, S_IRUGO, \ - read_cpld_callback, NULL, CPLD_QSFPDD_PRES_EVENT_G1); -static SENSOR_DEVICE_ATTR(cpld_qsfpdd_pres_event_g2, S_IRUGO, \ - read_cpld_callback, NULL, CPLD_QSFPDD_PRES_EVENT_G2); -static SENSOR_DEVICE_ATTR(cpld_qsfpdd_pres_event_g3, S_IRUGO, \ - read_cpld_callback, NULL, CPLD_QSFPDD_PRES_EVENT_G3); -static SENSOR_DEVICE_ATTR(cpld_qsfpdd_fuse_int_event_g0, S_IRUGO, \ - read_cpld_callback, NULL, CPLD_QSFPDD_FUSE_INT_EVENT_G0); -static SENSOR_DEVICE_ATTR(cpld_qsfpdd_fuse_int_event_g1, S_IRUGO, \ - read_cpld_callback, NULL, CPLD_QSFPDD_FUSE_INT_EVENT_G1); -static SENSOR_DEVICE_ATTR(cpld_qsfpdd_fuse_int_event_g2, S_IRUGO, \ - read_cpld_callback, NULL, CPLD_QSFPDD_FUSE_INT_EVENT_G2); -static SENSOR_DEVICE_ATTR(cpld_qsfpdd_fuse_int_event_g3, S_IRUGO, \ - read_cpld_callback, NULL, CPLD_QSFPDD_FUSE_INT_EVENT_G3); -static SENSOR_DEVICE_ATTR(cpld_sfp_txfault_event, S_IRUGO, \ - read_cpld_callback, NULL, CPLD_SFP_TXFAULT_EVENT); -static SENSOR_DEVICE_ATTR(cpld_sfp_abs_event, S_IRUGO, \ - read_cpld_callback, NULL, CPLD_SFP_ABS_EVENT); -static SENSOR_DEVICE_ATTR(cpld_sfp_rxlos_event, S_IRUGO, \ - read_cpld_callback, NULL, CPLD_SFP_RXLOS_EVENT); -static SENSOR_DEVICE_ATTR(cpld_qsfpdd_reset_ctrl_g0, \ - S_IWUSR | S_IRUGO, \ - read_cpld_callback, write_cpld_callback, \ - CPLD_QSFPDD_RESET_CTRL_G0); -static SENSOR_DEVICE_ATTR(cpld_qsfpdd_reset_ctrl_g1, \ - S_IWUSR | S_IRUGO, \ - read_cpld_callback, write_cpld_callback, \ - CPLD_QSFPDD_RESET_CTRL_G1); -static SENSOR_DEVICE_ATTR(cpld_qsfpdd_reset_ctrl_g2, \ - S_IWUSR | S_IRUGO, \ - read_cpld_callback, write_cpld_callback, \ - CPLD_QSFPDD_RESET_CTRL_G2); -static SENSOR_DEVICE_ATTR(cpld_qsfpdd_reset_ctrl_g3, \ - S_IWUSR | S_IRUGO, \ - read_cpld_callback, write_cpld_callback, \ - CPLD_QSFPDD_RESET_CTRL_G3); -static SENSOR_DEVICE_ATTR(cpld_qsfpdd_lp_mode_g0, \ - S_IWUSR | S_IRUGO, \ - read_cpld_callback, write_cpld_callback, \ - CPLD_QSFPDD_LP_MODE_G0); -static SENSOR_DEVICE_ATTR(cpld_qsfpdd_lp_mode_g1, \ - S_IWUSR | S_IRUGO, \ - read_cpld_callback, write_cpld_callback, \ - CPLD_QSFPDD_LP_MODE_G1); -static SENSOR_DEVICE_ATTR(cpld_qsfpdd_lp_mode_g2, \ - S_IWUSR | S_IRUGO, \ - read_cpld_callback, write_cpld_callback, \ - CPLD_QSFPDD_LP_MODE_G2); -static SENSOR_DEVICE_ATTR(cpld_qsfpdd_lp_mode_g3, \ - S_IWUSR | S_IRUGO, \ - read_cpld_callback, write_cpld_callback, \ - CPLD_QSFPDD_LP_MODE_G3); -static SENSOR_DEVICE_ATTR(cpld_sfp_tx_dis, S_IWUSR | S_IRUGO, \ - read_cpld_callback, write_cpld_callback, CPLD_SFP_TX_DIS); -static SENSOR_DEVICE_ATTR(cpld_sfp_rs, S_IWUSR | S_IRUGO, \ - read_cpld_callback, write_cpld_callback, CPLD_SFP_RS); -static SENSOR_DEVICE_ATTR(cpld_sfp_ts, S_IWUSR | S_IRUGO, \ - read_cpld_callback, write_cpld_callback, CPLD_SFP_TS); -static SENSOR_DEVICE_ATTR(cpld_port_int_status, S_IRUGO, \ - read_cpld_callback, NULL, CPLD_PORT_INT_STATUS); -//BSP DEBUG -static SENSOR_DEVICE_ATTR(bsp_debug, S_IRUGO | S_IWUSR, \ - read_bsp_callback, write_bsp_callback, BSP_DEBUG); - -/* define support attributes of cpldx , total 3 */ -/* cpld 1 */ -static struct attribute *s9300_cpld1_attributes[] = { - &sensor_dev_attr_cpld_access_register.dev_attr.attr, - &sensor_dev_attr_cpld_register_value.dev_attr.attr, - &sensor_dev_attr_cpld_sku_id.dev_attr.attr, - &sensor_dev_attr_cpld_hw_rev.dev_attr.attr, - &sensor_dev_attr_cpld_deph_rev.dev_attr.attr, - &sensor_dev_attr_cpld_build_rev.dev_attr.attr, - &sensor_dev_attr_cpld_id_type.dev_attr.attr, - &sensor_dev_attr_cpld_major_ver.dev_attr.attr, - &sensor_dev_attr_cpld_minor_ver.dev_attr.attr, - &sensor_dev_attr_cpld_build_ver.dev_attr.attr, - &sensor_dev_attr_cpld_version_h.dev_attr.attr, - &sensor_dev_attr_cpld_id.dev_attr.attr, - &sensor_dev_attr_cpld_mac_intr.dev_attr.attr, - &sensor_dev_attr_cpld_10g_phy_intr.dev_attr.attr, - &sensor_dev_attr_cpld_cpld_fru_intr.dev_attr.attr, - &sensor_dev_attr_cpld_thermal_alert_intr.dev_attr.attr, - &sensor_dev_attr_cpld_misc_intr.dev_attr.attr, - &sensor_dev_attr_cpld_system_intr.dev_attr.attr, - &sensor_dev_attr_cpld_mac_intr_mask.dev_attr.attr, - &sensor_dev_attr_cpld_10g_phy_intr_mask.dev_attr.attr, - &sensor_dev_attr_cpld_cpld_fru_intr_mask.dev_attr.attr, - &sensor_dev_attr_cpld_thermal_alert_intr_mask.dev_attr.attr, - &sensor_dev_attr_cpld_misc_intr_mask.dev_attr.attr, - &sensor_dev_attr_cpld_mac_intr_event.dev_attr.attr, - &sensor_dev_attr_cpld_10g_phy_intr_event.dev_attr.attr, - &sensor_dev_attr_cpld_cpld_fru_intr_event.dev_attr.attr, - &sensor_dev_attr_cpld_thermal_alert_intr_event.dev_attr.attr, - &sensor_dev_attr_cpld_misc_intr_event.dev_attr.attr, - &sensor_dev_attr_cpld_mac_rst.dev_attr.attr, - &sensor_dev_attr_cpld_10g_phy_rst.dev_attr.attr, - &sensor_dev_attr_cpld_bmc_rst.dev_attr.attr, - &sensor_dev_attr_cpld_usb_rst.dev_attr.attr, - &sensor_dev_attr_cpld_mux_rst.dev_attr.attr, - &sensor_dev_attr_cpld_misc_rst.dev_attr.attr, - &sensor_dev_attr_cpld_bmc_watchdog.dev_attr.attr, - &sensor_dev_attr_cpld_dau_bd_pres.dev_attr.attr, - &sensor_dev_attr_cpld_psu_status.dev_attr.attr, - &sensor_dev_attr_cpld_sys_pw_status.dev_attr.attr, - &sensor_dev_attr_cpld_misc.dev_attr.attr, - &sensor_dev_attr_cpld_mux_ctrl.dev_attr.attr, - &sensor_dev_attr_cpld_mac_qsfp_sel_ctrl.dev_attr.attr, - &sensor_dev_attr_cpld_sys_led_ctrl_1.dev_attr.attr, - &sensor_dev_attr_cpld_sys_led_ctrl_2.dev_attr.attr, - &sensor_dev_attr_cpld_beacon_led_ctrl.dev_attr.attr, - &sensor_dev_attr_cpld_port_led_clr_ctrl.dev_attr.attr, - &sensor_dev_attr_cpld_event_detect_ctrl.dev_attr.attr, - &sensor_dev_attr_bsp_debug.dev_attr.attr, - NULL -}; - -/* cpld 2 */ -static struct attribute *s9300_cpld2_attributes[] = { - &sensor_dev_attr_cpld_access_register.dev_attr.attr, - &sensor_dev_attr_cpld_register_value.dev_attr.attr, - &sensor_dev_attr_cpld_major_ver.dev_attr.attr, - &sensor_dev_attr_cpld_minor_ver.dev_attr.attr, - &sensor_dev_attr_cpld_build_ver.dev_attr.attr, - &sensor_dev_attr_cpld_version_h.dev_attr.attr, - &sensor_dev_attr_cpld_id.dev_attr.attr, - &sensor_dev_attr_cpld_qsfpdd_mod_int_g0.dev_attr.attr, - &sensor_dev_attr_cpld_qsfpdd_mod_int_g1.dev_attr.attr, - &sensor_dev_attr_cpld_qsfpdd_mod_int_g2.dev_attr.attr, - &sensor_dev_attr_cpld_qsfpdd_mod_int_g3.dev_attr.attr, - &sensor_dev_attr_cpld_qsfpdd_pres_g0.dev_attr.attr, - &sensor_dev_attr_cpld_qsfpdd_pres_g1.dev_attr.attr, - &sensor_dev_attr_cpld_qsfpdd_pres_g2.dev_attr.attr, - &sensor_dev_attr_cpld_qsfpdd_pres_g3.dev_attr.attr, - &sensor_dev_attr_cpld_qsfpdd_fuse_int_g0.dev_attr.attr, - &sensor_dev_attr_cpld_qsfpdd_fuse_int_g1.dev_attr.attr, - &sensor_dev_attr_cpld_qsfpdd_fuse_int_g2.dev_attr.attr, - &sensor_dev_attr_cpld_qsfpdd_fuse_int_g3.dev_attr.attr, - &sensor_dev_attr_cpld_sfp_txfault.dev_attr.attr, - &sensor_dev_attr_cpld_sfp_abs.dev_attr.attr, - &sensor_dev_attr_cpld_sfp_rxlos.dev_attr.attr, - &sensor_dev_attr_cpld_qsfpdd_mod_int_mask_g0.dev_attr.attr, - &sensor_dev_attr_cpld_qsfpdd_mod_int_mask_g1.dev_attr.attr, - &sensor_dev_attr_cpld_qsfpdd_mod_int_mask_g2.dev_attr.attr, - &sensor_dev_attr_cpld_qsfpdd_mod_int_mask_g3.dev_attr.attr, - &sensor_dev_attr_cpld_qsfpdd_pres_mask_g0.dev_attr.attr, - &sensor_dev_attr_cpld_qsfpdd_pres_mask_g1.dev_attr.attr, - &sensor_dev_attr_cpld_qsfpdd_pres_mask_g2.dev_attr.attr, - &sensor_dev_attr_cpld_qsfpdd_pres_mask_g3.dev_attr.attr, - &sensor_dev_attr_cpld_qsfpdd_fuse_int_mask_g0.dev_attr.attr, - &sensor_dev_attr_cpld_qsfpdd_fuse_int_mask_g1.dev_attr.attr, - &sensor_dev_attr_cpld_qsfpdd_fuse_int_mask_g2.dev_attr.attr, - &sensor_dev_attr_cpld_qsfpdd_fuse_int_mask_g3.dev_attr.attr, - &sensor_dev_attr_cpld_sfp_txfault_mask.dev_attr.attr, - &sensor_dev_attr_cpld_sfp_abs_mask.dev_attr.attr, - &sensor_dev_attr_cpld_sfp_rxlos_mask.dev_attr.attr, - &sensor_dev_attr_cpld_qsfpdd_mod_int_event_g0.dev_attr.attr, - &sensor_dev_attr_cpld_qsfpdd_mod_int_event_g1.dev_attr.attr, - &sensor_dev_attr_cpld_qsfpdd_mod_int_event_g2.dev_attr.attr, - &sensor_dev_attr_cpld_qsfpdd_mod_int_event_g3.dev_attr.attr, - &sensor_dev_attr_cpld_qsfpdd_pres_event_g0.dev_attr.attr, - &sensor_dev_attr_cpld_qsfpdd_pres_event_g1.dev_attr.attr, - &sensor_dev_attr_cpld_qsfpdd_pres_event_g2.dev_attr.attr, - &sensor_dev_attr_cpld_qsfpdd_pres_event_g3.dev_attr.attr, - &sensor_dev_attr_cpld_qsfpdd_fuse_int_event_g0.dev_attr.attr, - &sensor_dev_attr_cpld_qsfpdd_fuse_int_event_g1.dev_attr.attr, - &sensor_dev_attr_cpld_qsfpdd_fuse_int_event_g2.dev_attr.attr, - &sensor_dev_attr_cpld_qsfpdd_fuse_int_event_g3.dev_attr.attr, - &sensor_dev_attr_cpld_sfp_txfault_event.dev_attr.attr, - &sensor_dev_attr_cpld_sfp_abs_event.dev_attr.attr, - &sensor_dev_attr_cpld_sfp_rxlos_event.dev_attr.attr, - &sensor_dev_attr_cpld_qsfpdd_reset_ctrl_g0.dev_attr.attr, - &sensor_dev_attr_cpld_qsfpdd_reset_ctrl_g1.dev_attr.attr, - &sensor_dev_attr_cpld_qsfpdd_reset_ctrl_g2.dev_attr.attr, - &sensor_dev_attr_cpld_qsfpdd_reset_ctrl_g3.dev_attr.attr, - &sensor_dev_attr_cpld_qsfpdd_lp_mode_g0.dev_attr.attr, - &sensor_dev_attr_cpld_qsfpdd_lp_mode_g1.dev_attr.attr, - &sensor_dev_attr_cpld_qsfpdd_lp_mode_g2.dev_attr.attr, - &sensor_dev_attr_cpld_qsfpdd_lp_mode_g3.dev_attr.attr, - &sensor_dev_attr_cpld_sfp_tx_dis.dev_attr.attr, - &sensor_dev_attr_cpld_sfp_rs.dev_attr.attr, - &sensor_dev_attr_cpld_sfp_ts.dev_attr.attr, - &sensor_dev_attr_cpld_port_int_status.dev_attr.attr, - NULL -}; - -/* cpld 3 */ -static struct attribute *s9300_cpld3_attributes[] = { - &sensor_dev_attr_cpld_access_register.dev_attr.attr, - &sensor_dev_attr_cpld_register_value.dev_attr.attr, - &sensor_dev_attr_cpld_major_ver.dev_attr.attr, - &sensor_dev_attr_cpld_minor_ver.dev_attr.attr, - &sensor_dev_attr_cpld_build_ver.dev_attr.attr, - &sensor_dev_attr_cpld_version_h.dev_attr.attr, - &sensor_dev_attr_cpld_id.dev_attr.attr, - NULL -}; - -/* cpld 1 attributes group */ -static const struct attribute_group s9300_cpld1_group = { - .attrs = s9300_cpld1_attributes, -}; -/* cpld 2 attributes group */ -static const struct attribute_group s9300_cpld2_group = { - .attrs = s9300_cpld2_attributes, -}; -/* cpld 3 attributes group */ -static const struct attribute_group s9300_cpld3_group = { - .attrs = s9300_cpld3_attributes, -}; - -static int _bsp_log(u8 log_type, char *fmt, ...) -{ - if ((log_type==LOG_READ && enable_log_read) || - (log_type==LOG_WRITE && enable_log_write)) { - va_list args; - int r; - - va_start(args, fmt); - r = vprintk(fmt, args); - va_end(args); - - return r; - } else { - return 0; - } -} - -static int _config_bsp_log(u8 log_type) -{ - switch(log_type) { - case LOG_NONE: - enable_log_read = LOG_DISABLE; - enable_log_write = LOG_DISABLE; - break; - case LOG_RW: - enable_log_read = LOG_ENABLE; - enable_log_write = LOG_ENABLE; - break; - case LOG_READ: - enable_log_read = LOG_ENABLE; - enable_log_write = LOG_DISABLE; - break; - case LOG_WRITE: - enable_log_read = LOG_DISABLE; - enable_log_write = LOG_ENABLE; - break; - default: - return -EINVAL; - } - return 0; -} - -/* get bsp value */ -static ssize_t read_bsp(char *buf, char *str) -{ - ssize_t len=0; - - len=sprintf(buf, "%s", str); - BSP_LOG_R("reg_val=%s", str); - - return len; -} - -/* set bsp value */ -static ssize_t write_bsp(const char *buf, char *str, size_t str_len, size_t count) -{ - snprintf(str, str_len, "%s", buf); - BSP_LOG_W("reg_val=%s", str); - - return count; -} - -/* get bsp parameter value */ -static ssize_t read_bsp_callback(struct device *dev, - struct device_attribute *da, char *buf) -{ - struct sensor_device_attribute *attr = to_sensor_dev_attr(da); - int str_len=0; - char *str=NULL; - - switch (attr->index) { - case BSP_DEBUG: - str = bsp_debug; - str_len = sizeof(bsp_debug); - break; - default: - return -EINVAL; - } - return read_bsp(buf, str); -} - -/* set bsp parameter value */ -static ssize_t write_bsp_callback(struct device *dev, - struct device_attribute *da, const char *buf, size_t count) -{ - struct sensor_device_attribute *attr = to_sensor_dev_attr(da); - int str_len=0; - char *str=NULL; - ssize_t ret = 0; - u8 bsp_debug_u8 = 0; - - switch (attr->index) { - case BSP_DEBUG: - str = bsp_debug; - str_len = sizeof(str); - ret = write_bsp(buf, str, str_len, count); - - if (kstrtou8(buf, 0, &bsp_debug_u8) < 0) { - return -EINVAL; - } else if (_config_bsp_log(bsp_debug_u8) < 0) { - return -EINVAL; - } - return ret; - default: - return -EINVAL; - } - return 0; -} - -/* read access register from cpld data */ -static ssize_t read_access_register(struct device *dev, - struct device_attribute *da, - char *buf) -{ - struct i2c_client *client = to_i2c_client(dev); - struct cpld_data *data = i2c_get_clientdata(client); - u8 reg = data->access_reg; - - return sprintf(buf, "0x%x\n", reg); -} - -/* write access register to cpld data */ -static ssize_t write_access_register(struct device *dev, - struct device_attribute *da, - const char *buf, - size_t count) -{ - struct i2c_client *client = to_i2c_client(dev); - struct cpld_data *data = i2c_get_clientdata(client); - u8 reg; - - if (kstrtou8(buf, 0, ®) < 0) - return -EINVAL; - - data->access_reg = reg; - return count; -} - -/* read the value of access register in cpld data */ -static ssize_t read_register_value(struct device *dev, - struct device_attribute *da, - char *buf) -{ - struct i2c_client *client = to_i2c_client(dev); - struct cpld_data *data = i2c_get_clientdata(client); - u8 reg = data->access_reg; - int reg_val; - - I2C_READ_BYTE_DATA(reg_val, &data->access_lock, client, reg); - - if (reg_val < 0) - return reg_val; - - return sprintf(buf, "0x%x\n", reg_val); -} - -/* wrtie the value to access register in cpld data */ -static ssize_t write_register_value(struct device *dev, - struct device_attribute *da, - const char *buf, - size_t count) -{ - struct i2c_client *client = to_i2c_client(dev); - struct cpld_data *data = i2c_get_clientdata(client); - int ret = -EIO; - u8 reg = data->access_reg; - u8 reg_val; - - if (kstrtou8(buf, 0, ®_val) < 0) - return -EINVAL; - - I2C_WRITE_BYTE_DATA(ret, &data->access_lock, client, reg, reg_val); - - if (unlikely(ret < 0)) { - dev_err(dev, "I2C_WRITE_BYTE_DATA error, return=%d\n", ret); - return ret; - } - - return count; -} - -/* get cpld register value */ -static ssize_t read_cpld_reg(struct device *dev, - char *buf, - u8 reg) -{ - int reg_val; - - if (read_cpld_reg_raw_int(dev, reg, ®_val)) - return sprintf(buf, "0x%02x\n", reg_val); - else - return reg_val; -} - -static bool read_cpld_reg_raw_int(struct device *dev, u8 reg, int *val) -{ - struct i2c_client *client = to_i2c_client(dev); - struct cpld_data *data = i2c_get_clientdata(client); - I2C_READ_BYTE_DATA(*val, &data->access_lock, client, reg); - if (unlikely(*val < 0)) { - dev_err(dev, "read_cpld_reg_raw_int() error, return=%d\n", *val); - return false; - } - return true; -} - -static bool read_cpld_reg_raw_byte(struct device *dev, u8 reg, u8 *val, int *errno) -{ - int reg_val; - - if (read_cpld_reg_raw_int(dev, reg, ®_val)) { - *val = (u8)reg_val; - return true; - } else { - *errno = reg_val; - return false; - } -} - -/* handle read for attributes */ -static ssize_t read_cpld_callback(struct device *dev, - struct device_attribute *da, char *buf) -{ - struct sensor_device_attribute *attr = to_sensor_dev_attr(da); - u8 reg = 0; - - switch (attr->index) { - case CPLD_SKU_ID: - reg = CPLD_SKU_ID_REG; - break; - case CPLD_ID: - reg = CPLD_ID_REG; - break; - case CPLD_BUILD_VER: - reg = CPLD_BUILD_VER_REG; - break; - case CPLD_MAC_INTR: - reg = CPLD_MAC_INTR_REG; - break; - case CPLD_10G_PHY_INTR: - reg = CPLD_10G_PHY_INTR_REG; - break; - case CPLD_CPLD_FRU_INTR: - reg = CPLD_CPLD_FRU_INTR_REG; - break; - case CPLD_THERMAL_ALERT_INTR: - reg = CPLD_THERMAL_ALERT_INTR_REG; - break; - case CPLD_MISC_INTR: - reg = CPLD_MISC_INTR_REG; - break; - case CPLD_SYSTEM_INTR: - reg = CPLD_SYSTEM_INTR_REG; - break; - case CPLD_MAC_INTR_MASK: - reg = CPLD_MAC_INTR_MASK_REG; - break; - case CPLD_10G_PHY_INTR_MASK: - reg = CPLD_10G_PHY_INTR_MASK_REG; - break; - case CPLD_CPLD_FRU_INTR_MASK: - reg = CPLD_CPLD_FRU_INTR_MASK_REG; - break; - case CPLD_THERMAL_ALERT_INTR_MASK: - reg = CPLD_THERMAL_ALERT_INTR_MASK_REG; - break; - case CPLD_MISC_INTR_MASK: - reg = CPLD_MISC_INTR_MASK_REG; - break; - case CPLD_MAC_INTR_EVENT: - reg = CPLD_MAC_INTR_EVENT_REG; - break; - case CPLD_10G_PHY_INTR_EVENT: - reg = CPLD_10G_PHY_INTR_EVENT_REG; - break; - case CPLD_CPLD_FRU_INTR_EVENT: - reg = CPLD_CPLD_FRU_INTR_EVENT_REG; - break; - case CPLD_THERMAL_ALERT_INTR_EVENT: - reg = CPLD_THERMAL_ALERT_INTR_EVENT_REG; - break; - case CPLD_MISC_INTR_EVENT: - reg = CPLD_MISC_INTR_EVENT_REG; - break; - case CPLD_MAC_RST: - reg = CPLD_MAC_RST_REG; - break; - case CPLD_10G_PHY_RST: - reg = CPLD_10G_PHY_RST_REG; - break; - case CPLD_BMC_RST: - reg = CPLD_BMC_RST_REG; - break; - case CPLD_USB_RST: - reg = CPLD_USB_RST_REG; - break; - case CPLD_MUX_RST: - reg = CPLD_MUX_RST_REG; - break; - case CPLD_MISC_RST: - reg = CPLD_MISC_RST_REG; - break; - case CPLD_BMC_WATCHDOG: - reg = CPLD_BMC_WATCHDOG_REG; - break; - case CPLD_DAU_BD_PRES: - reg = CPLD_DAU_BD_PRES_REG; - break; - case CPLD_PSU_STATUS: - reg = CPLD_PSU_STATUS_REG; - break; - case CPLD_SYS_PW_STATUS: - reg = CPLD_SYS_PW_STATUS_REG; - break; - case CPLD_MISC: - reg = CPLD_MISC_REG; - break; - case CPLD_MUX_CTRL: - reg = CPLD_MUX_CTRL_REG; - break; - case CPLD_MAC_QSFP_SEL_CTRL: - reg = CPLD_MAC_QSFP_SEL_CTRL_REG; - break; - case CPLD_SYS_LED_CTRL_1: - reg = CPLD_SYS_LED_CTRL_1_REG; - break; - case CPLD_SYS_LED_CTRL_2: - reg = CPLD_SYS_LED_CTRL_2_REG; - break; - case CPLD_BEACON_LED_CTRL: - reg = CPLD_BEACON_LED_CTRL_REG; - break; - case CPLD_PORT_LED_CLR_CTRL: - reg = CPLD_PORT_LED_CLR_CTRL_REG; - break; - case CPLD_EVENT_DETECT_CTRL: - reg = CPLD_EVENT_DETECT_CTRL_REG; - break; - case CPLD_QSFPDD_MOD_INT_G0: - reg = CPLD_QSFPDD_MOD_INT_G0_REG; - break; - case CPLD_QSFPDD_MOD_INT_G1: - reg = CPLD_QSFPDD_MOD_INT_G1_REG; - break; - case CPLD_QSFPDD_MOD_INT_G2: - reg = CPLD_QSFPDD_MOD_INT_G2_REG; - break; - case CPLD_QSFPDD_MOD_INT_G3: - reg = CPLD_QSFPDD_MOD_INT_G3_REG; - break; - case CPLD_QSFPDD_PRES_G0: - reg = CPLD_QSFPDD_PRES_G0_REG; - break; - case CPLD_QSFPDD_PRES_G1: - reg = CPLD_QSFPDD_PRES_G1_REG; - break; - case CPLD_QSFPDD_PRES_G2: - reg = CPLD_QSFPDD_PRES_G2_REG; - break; - case CPLD_QSFPDD_PRES_G3: - reg = CPLD_QSFPDD_PRES_G3_REG; - break; - case CPLD_QSFPDD_FUSE_INT_G0: - reg = CPLD_QSFPDD_FUSE_INT_G0_REG; - break; - case CPLD_QSFPDD_FUSE_INT_G1: - reg = CPLD_QSFPDD_FUSE_INT_G1_REG; - break; - case CPLD_QSFPDD_FUSE_INT_G2: - reg = CPLD_QSFPDD_FUSE_INT_G2_REG; - break; - case CPLD_QSFPDD_FUSE_INT_G3: - reg = CPLD_QSFPDD_FUSE_INT_G3_REG; - break; - case CPLD_SFP_TXFAULT: - reg = CPLD_SFP_TXFAULT_REG; - break; - case CPLD_SFP_ABS: - reg = CPLD_SFP_ABS_REG; - break; - case CPLD_SFP_RXLOS: - reg = CPLD_SFP_RXLOS_REG; - break; - case CPLD_QSFPDD_MOD_INT_MASK_G0: - reg = CPLD_QSFPDD_MOD_INT_MASK_G0_REG; - break; - case CPLD_QSFPDD_MOD_INT_MASK_G1: - reg = CPLD_QSFPDD_MOD_INT_MASK_G1_REG; - break; - case CPLD_QSFPDD_MOD_INT_MASK_G2: - reg = CPLD_QSFPDD_MOD_INT_MASK_G2_REG; - break; - case CPLD_QSFPDD_MOD_INT_MASK_G3: - reg = CPLD_QSFPDD_MOD_INT_MASK_G3_REG; - break; - case CPLD_QSFPDD_PRES_MASK_G0: - reg = CPLD_QSFPDD_PRES_MASK_G0_REG; - break; - case CPLD_QSFPDD_PRES_MASK_G1: - reg = CPLD_QSFPDD_PRES_MASK_G1_REG; - break; - case CPLD_QSFPDD_PRES_MASK_G2: - reg = CPLD_QSFPDD_PRES_MASK_G2_REG; - break; - case CPLD_QSFPDD_PRES_MASK_G3: - reg = CPLD_QSFPDD_PRES_MASK_G3_REG; - break; - case CPLD_QSFPDD_FUSE_INT_MASK_G0: - reg = CPLD_QSFPDD_FUSE_INT_MASK_G0_REG; - break; - case CPLD_QSFPDD_FUSE_INT_MASK_G1: - reg = CPLD_QSFPDD_FUSE_INT_MASK_G1_REG; - break; - case CPLD_QSFPDD_FUSE_INT_MASK_G2: - reg = CPLD_QSFPDD_FUSE_INT_MASK_G2_REG; - break; - case CPLD_QSFPDD_FUSE_INT_MASK_G3: - reg = CPLD_QSFPDD_FUSE_INT_MASK_G3_REG; - break; - case CPLD_SFP_TXFAULT_MASK: - reg = CPLD_SFP_TXFAULT_MASK_REG; - break; - case CPLD_SFP_ABS_MASK: - reg = CPLD_SFP_ABS_MASK_REG; - break; - case CPLD_SFP_RXLOS_MASK: - reg = CPLD_SFP_RXLOS_MASK_REG; - break; - case CPLD_QSFPDD_MOD_INT_EVENT_G0: - reg = CPLD_QSFPDD_MOD_INT_EVENT_G0_REG; - break; - case CPLD_QSFPDD_MOD_INT_EVENT_G1: - reg = CPLD_QSFPDD_MOD_INT_EVENT_G1_REG; - break; - case CPLD_QSFPDD_MOD_INT_EVENT_G2: - reg = CPLD_QSFPDD_MOD_INT_EVENT_G2_REG; - break; - case CPLD_QSFPDD_MOD_INT_EVENT_G3: - reg = CPLD_QSFPDD_MOD_INT_EVENT_G3_REG; - break; - case CPLD_QSFPDD_PRES_EVENT_G0: - reg = CPLD_QSFPDD_PRES_EVENT_G0_REG; - break; - case CPLD_QSFPDD_PRES_EVENT_G1: - reg = CPLD_QSFPDD_PRES_EVENT_G1_REG; - break; - case CPLD_QSFPDD_PRES_EVENT_G2: - reg = CPLD_QSFPDD_PRES_EVENT_G2_REG; - break; - case CPLD_QSFPDD_PRES_EVENT_G3: - reg = CPLD_QSFPDD_PRES_EVENT_G3_REG; - break; - case CPLD_QSFPDD_FUSE_INT_EVENT_G0: - reg = CPLD_QSFPDD_FUSE_INT_EVENT_G0_REG; - break; - case CPLD_QSFPDD_FUSE_INT_EVENT_G1: - reg = CPLD_QSFPDD_FUSE_INT_EVENT_G1_REG; - break; - case CPLD_QSFPDD_FUSE_INT_EVENT_G2: - reg = CPLD_QSFPDD_FUSE_INT_EVENT_G2_REG; - break; - case CPLD_QSFPDD_FUSE_INT_EVENT_G3: - reg = CPLD_QSFPDD_FUSE_INT_EVENT_G3_REG; - break; - case CPLD_SFP_TXFAULT_EVENT: - reg = CPLD_SFP_TXFAULT_EVENT_REG; - break; - case CPLD_SFP_ABS_EVENT: - reg = CPLD_SFP_ABS_EVENT_REG; - break; - case CPLD_SFP_RXLOS_EVENT: - reg = CPLD_SFP_RXLOS_EVENT_REG; - break; - case CPLD_QSFPDD_RESET_CTRL_G0: - reg = CPLD_QSFPDD_RESET_CTRL_G0_REG; - break; - case CPLD_QSFPDD_RESET_CTRL_G1: - reg = CPLD_QSFPDD_RESET_CTRL_G1_REG; - break; - case CPLD_QSFPDD_RESET_CTRL_G2: - reg = CPLD_QSFPDD_RESET_CTRL_G2_REG; - break; - case CPLD_QSFPDD_RESET_CTRL_G3: - reg = CPLD_QSFPDD_RESET_CTRL_G3_REG; - break; - case CPLD_QSFPDD_LP_MODE_G0: - reg = CPLD_QSFPDD_LP_MODE_G0_REG; - break; - case CPLD_QSFPDD_LP_MODE_G1: - reg = CPLD_QSFPDD_LP_MODE_G1_REG; - break; - case CPLD_QSFPDD_LP_MODE_G2: - reg = CPLD_QSFPDD_LP_MODE_G2_REG; - break; - case CPLD_QSFPDD_LP_MODE_G3: - reg = CPLD_QSFPDD_LP_MODE_G3_REG; - break; - case CPLD_SFP_TX_DIS: - reg = CPLD_SFP_TX_DIS_REG; - break; - case CPLD_SFP_RS: - reg = CPLD_SFP_RS_REG; - break; - case CPLD_SFP_TS: - reg = CPLD_SFP_TS_REG; - break; - case CPLD_PORT_INT_STATUS: - reg = CPLD_PORT_INT_STATUS_REG; - break; - default: - return -EINVAL; - } - return read_cpld_reg(dev, buf, reg); -} - -/* handle read for hw_rev attributes */ -static ssize_t read_hw_rev_cb(struct device *dev, - struct device_attribute *da, char *buf) -{ - struct sensor_device_attribute *attr = to_sensor_dev_attr(da); - u8 reg = CPLD_HW_REV_REG; - u8 reg_val = 0; - int errno = 0; - u8 res; - - if (!read_cpld_reg_raw_byte(dev, reg, ®_val, &errno)) - return errno; - - switch (attr->index) { - case CPLD_HW_REV: - HW_REV_GET(reg_val, res); - break; - case CPLD_DEPH_REV: - DEPH_REV_GET(reg_val, res); - break; - case CPLD_BUILD_REV: - BUILD_REV_GET(reg_val, res); - break; - case CPLD_ID_TYPE: - ID_TYPE_GET(reg_val, res); - break; - default: - return -EINVAL; - } - return sprintf(buf, "0x%02x\n", res); -} - -/* handle read for cpld_version attributes */ -static ssize_t read_cpld_version_cb(struct device *dev, - struct device_attribute *da, char *buf) -{ - struct sensor_device_attribute *attr = to_sensor_dev_attr(da); - u8 reg = CPLD_VERSION_REG; - u8 reg_val = 0; - int errno = 0; - u8 res; - - if (!read_cpld_reg_raw_byte(dev, reg, ®_val, &errno)) - return errno; - - switch (attr->index) { - case CPLD_MAJOR_VER: - CPLD_MAJOR_VERSION_GET(reg_val, res); - break; - case CPLD_MINOR_VER: - CPLD_MINOR_VERSION_GET(reg_val, res); - break; - default: - return -EINVAL; - } - return sprintf(buf, "0x%02x\n", res); -} - -/* handle read human-readable string for cpld_version attributes */ -static ssize_t read_cpld_version_h_cb(struct device *dev, - struct device_attribute *da, char *buf) -{ - u8 reg = CPLD_VERSION_REG; - u8 reg_val = 0; - int errno = 0; - u8 major, minor, build; - - //get major/minor register value - if(!read_cpld_reg_raw_byte(dev, reg, ®_val, &errno)) - return errno; - CPLD_MAJOR_VERSION_GET(reg_val, major); - CPLD_MINOR_VERSION_GET(reg_val, minor); - - //get build register value - reg = CPLD_BUILD_VER_REG; - if(!read_cpld_reg_raw_byte(dev, reg, &build, &errno)) - return errno; - - //version string format : xx.xx.xxx - return sprintf(buf, "%d.%02d.%03d\n", major, minor, build); -} - -/* handle write for attributes */ -static ssize_t write_cpld_callback(struct device *dev, - struct device_attribute *da, const char *buf, size_t count) -{ - struct sensor_device_attribute *attr = to_sensor_dev_attr(da); - u8 reg = 0; - - switch (attr->index) { - case CPLD_MAC_INTR_MASK: - reg = CPLD_MAC_INTR_MASK_REG; - break; - case CPLD_10G_PHY_INTR_MASK: - reg = CPLD_10G_PHY_INTR_MASK_REG; - break; - case CPLD_CPLD_FRU_INTR_MASK: - reg = CPLD_CPLD_FRU_INTR_MASK_REG; - break; - case CPLD_THERMAL_ALERT_INTR_MASK: - reg = CPLD_THERMAL_ALERT_INTR_MASK_REG; - break; - case CPLD_MISC_INTR_MASK: - reg = CPLD_MISC_INTR_MASK_REG; - break; - case CPLD_MAC_RST: - reg = CPLD_MAC_RST_REG; - break; - case CPLD_10G_PHY_RST: - reg = CPLD_10G_PHY_RST_REG; - break; - case CPLD_BMC_RST: - reg = CPLD_BMC_RST_REG; - break; - case CPLD_USB_RST: - reg = CPLD_USB_RST_REG; - break; - case CPLD_MUX_RST: - reg = CPLD_MUX_RST_REG; - break; - case CPLD_MISC_RST: - reg = CPLD_MISC_RST_REG; - break; - case CPLD_BMC_WATCHDOG: - reg = CPLD_BMC_WATCHDOG_REG; - break; - case CPLD_MUX_CTRL: - reg = CPLD_MUX_CTRL_REG; - break; - case CPLD_MAC_QSFP_SEL_CTRL: - reg = CPLD_MAC_QSFP_SEL_CTRL_REG; - break; - case CPLD_BEACON_LED_CTRL: - reg = CPLD_BEACON_LED_CTRL_REG; - break; - case CPLD_PORT_LED_CLR_CTRL: - reg = CPLD_PORT_LED_CLR_CTRL_REG; - break; - case CPLD_EVENT_DETECT_CTRL: - reg = CPLD_EVENT_DETECT_CTRL_REG; - break; - case CPLD_QSFPDD_MOD_INT_MASK_G0: - reg = CPLD_QSFPDD_MOD_INT_MASK_G0_REG; - break; - case CPLD_QSFPDD_MOD_INT_MASK_G1: - reg = CPLD_QSFPDD_MOD_INT_MASK_G1_REG; - break; - case CPLD_QSFPDD_MOD_INT_MASK_G2: - reg = CPLD_QSFPDD_MOD_INT_MASK_G2_REG; - break; - case CPLD_QSFPDD_MOD_INT_MASK_G3: - reg = CPLD_QSFPDD_MOD_INT_MASK_G3_REG; - break; - case CPLD_QSFPDD_PRES_MASK_G0: - reg = CPLD_QSFPDD_PRES_MASK_G0_REG; - break; - case CPLD_QSFPDD_PRES_MASK_G1: - reg = CPLD_QSFPDD_PRES_MASK_G1_REG; - break; - case CPLD_QSFPDD_PRES_MASK_G2: - reg = CPLD_QSFPDD_PRES_MASK_G2_REG; - break; - case CPLD_QSFPDD_PRES_MASK_G3: - reg = CPLD_QSFPDD_PRES_MASK_G3_REG; - break; - case CPLD_QSFPDD_FUSE_INT_MASK_G0: - reg = CPLD_QSFPDD_FUSE_INT_MASK_G0_REG; - break; - case CPLD_QSFPDD_FUSE_INT_MASK_G1: - reg = CPLD_QSFPDD_FUSE_INT_MASK_G1_REG; - break; - case CPLD_QSFPDD_FUSE_INT_MASK_G2: - reg = CPLD_QSFPDD_FUSE_INT_MASK_G2_REG; - break; - case CPLD_QSFPDD_FUSE_INT_MASK_G3: - reg = CPLD_QSFPDD_FUSE_INT_MASK_G3_REG; - break; - case CPLD_SFP_TXFAULT_MASK: - reg = CPLD_SFP_TXFAULT_MASK_REG; - break; - case CPLD_SFP_ABS_MASK: - reg = CPLD_SFP_ABS_MASK_REG; - break; - case CPLD_SFP_RXLOS_MASK: - reg = CPLD_SFP_RXLOS_MASK_REG; - break; - case CPLD_QSFPDD_RESET_CTRL_G0: - reg = CPLD_QSFPDD_RESET_CTRL_G0_REG; - break; - case CPLD_QSFPDD_RESET_CTRL_G1: - reg = CPLD_QSFPDD_RESET_CTRL_G1_REG; - break; - case CPLD_QSFPDD_RESET_CTRL_G2: - reg = CPLD_QSFPDD_RESET_CTRL_G2_REG; - break; - case CPLD_QSFPDD_RESET_CTRL_G3: - reg = CPLD_QSFPDD_RESET_CTRL_G3_REG; - break; - case CPLD_QSFPDD_LP_MODE_G0: - reg = CPLD_QSFPDD_LP_MODE_G0_REG; - break; - case CPLD_QSFPDD_LP_MODE_G1: - reg = CPLD_QSFPDD_LP_MODE_G1_REG; - break; - case CPLD_QSFPDD_LP_MODE_G2: - reg = CPLD_QSFPDD_LP_MODE_G2_REG; - break; - case CPLD_QSFPDD_LP_MODE_G3: - reg = CPLD_QSFPDD_LP_MODE_G3_REG; - break; - case CPLD_SFP_TX_DIS: - reg = CPLD_SFP_TX_DIS_REG; - break; - case CPLD_SFP_RS: - reg = CPLD_SFP_RS_REG; - break; - case CPLD_SFP_TS: - reg = CPLD_SFP_TS_REG; - break; - default: - return -EINVAL; - } - return write_cpld_reg(dev, buf, count, reg); -} - -/* set cpld register value */ -static ssize_t write_cpld_reg(struct device *dev, - const char *buf, - size_t count, - u8 reg) -{ - struct i2c_client *client = to_i2c_client(dev); - struct cpld_data *data = i2c_get_clientdata(client); - u8 reg_val; - int ret; - - if (kstrtou8(buf, 0, ®_val) < 0) - return -EINVAL; - - I2C_WRITE_BYTE_DATA(ret, &data->access_lock, - client, reg, reg_val); - - if (unlikely(ret < 0)) { - dev_err(dev, "I2C_WRITE_BYTE_DATA error, return=%d\n", ret); - return ret; - } - - return count; -} - -/* add valid cpld client to list */ -static void s9300_cpld_add_client(struct i2c_client *client) -{ - struct cpld_client_node *node = NULL; - - node = kzalloc(sizeof(struct cpld_client_node), GFP_KERNEL); - if (!node) { - dev_info(&client->dev, - "Can't allocate cpld_client_node for index %d\n", - client->addr); - return; - } - - node->client = client; - - mutex_lock(&list_lock); - list_add(&node->list, &cpld_client_list); - mutex_unlock(&list_lock); -} - -/* remove exist cpld client in list */ -static void s9300_cpld_remove_client(struct i2c_client *client) -{ - struct list_head *list_node = NULL; - struct cpld_client_node *cpld_node = NULL; - int found = 0; - - mutex_lock(&list_lock); - list_for_each(list_node, &cpld_client_list) { - cpld_node = list_entry(list_node, - struct cpld_client_node, list); - - if (cpld_node->client == client) { - found = 1; - break; - } - } - - if (found) { - list_del(list_node); - kfree(cpld_node); - } - mutex_unlock(&list_lock); -} - -/* cpld drvier probe */ -static int s9300_cpld_probe(struct i2c_client *client, - const struct i2c_device_id *dev_id) -{ - int status; - struct cpld_data *data = NULL; - int ret = -EPERM; - int idx; - - data = kzalloc(sizeof(struct cpld_data), GFP_KERNEL); - if (!data) - return -ENOMEM; - - /* init cpld data for client */ - i2c_set_clientdata(client, data); - mutex_init(&data->access_lock); - - if (!i2c_check_functionality(client->adapter, - I2C_FUNC_SMBUS_BYTE_DATA)) { - dev_info(&client->dev, - "i2c_check_functionality failed (0x%x)\n", - client->addr); - status = -EIO; - goto exit; - } - - /* get cpld id from device */ - ret = i2c_smbus_read_byte_data(client, CPLD_ID_REG); - - if (ret < 0) { - dev_info(&client->dev, - "fail to get cpld id (0x%x) at addr (0x%x)\n", - CPLD_ID_REG, client->addr); - status = -EIO; - goto exit; - } - - CPLD_ID_ID_GET(ret, idx); - - if (INVALID(idx, cpld1, cpld3)) { - dev_info(&client->dev, - "cpld id %d(device) not valid\n", idx); - //status = -EPERM; - //goto exit; - } - - data->index = dev_id->driver_data; - - /* register sysfs hooks for different cpld group */ - dev_info(&client->dev, "probe cpld with index %d\n", data->index); - switch (data->index) { - case cpld1: - status = sysfs_create_group(&client->dev.kobj, - &s9300_cpld1_group); - break; - case cpld2: - status = sysfs_create_group(&client->dev.kobj, - &s9300_cpld2_group); - break; - case cpld3: - status = sysfs_create_group(&client->dev.kobj, - &s9300_cpld3_group); - break; - default: - status = -EINVAL; - } - - if (status) - goto exit; - - dev_info(&client->dev, "chip found\n"); - - /* add probe chip to client list */ - s9300_cpld_add_client(client); - - return 0; -exit: - switch (data->index) { - case cpld1: - sysfs_remove_group(&client->dev.kobj, &s9300_cpld1_group); - break; - case cpld2: - sysfs_remove_group(&client->dev.kobj, &s9300_cpld2_group); - break; - case cpld3: - sysfs_remove_group(&client->dev.kobj, &s9300_cpld3_group); - break; - default: - break; - } - return status; -} - -/* cpld drvier remove */ -static int s9300_cpld_remove(struct i2c_client *client) -{ - struct cpld_data *data = i2c_get_clientdata(client); - - switch (data->index) { - case cpld1: - sysfs_remove_group(&client->dev.kobj, &s9300_cpld1_group); - break; - case cpld2: - sysfs_remove_group(&client->dev.kobj, &s9300_cpld2_group); - break; - case cpld3: - sysfs_remove_group(&client->dev.kobj, &s9300_cpld3_group); - break; - } - - s9300_cpld_remove_client(client); - return 0; -} - -MODULE_DEVICE_TABLE(i2c, s9300_cpld_id); - -static struct i2c_driver s9300_cpld_driver = { - .class = I2C_CLASS_HWMON, - .driver = { - .name = "x86_64_ufispace_s9300_32d_cpld", - }, - .probe = s9300_cpld_probe, - .remove = s9300_cpld_remove, - .id_table = s9300_cpld_id, - .address_list = cpld_i2c_addr, -}; - -/* provide cpld register read */ -/* cpld_idx indicate the index of cpld device */ -int s9300_cpld_read(u8 cpld_idx, - u8 reg) -{ - struct list_head *list_node = NULL; - struct cpld_client_node *cpld_node = NULL; - int ret = -EPERM; - struct cpld_data *data; - - list_for_each(list_node, &cpld_client_list) { - cpld_node = list_entry(list_node, - struct cpld_client_node, list); - data = i2c_get_clientdata(cpld_node->client); - if (data->index == cpld_idx) { - DEBUG_PRINT("cpld_idx=%d, read reg 0x%02x", - cpld_idx, reg); - I2C_READ_BYTE_DATA(ret, &data->access_lock, - cpld_node->client, reg); - DEBUG_PRINT("cpld_idx=%d, read reg 0x%02x = 0x%02x", - cpld_idx, reg, ret); - break; - } - } - - return ret; -} -EXPORT_SYMBOL(s9300_cpld_read); - -/* provide cpld register write */ -/* cpld_idx indicate the index of cpld device */ -int s9300_cpld_write(u8 cpld_idx, - u8 reg, - u8 value) -{ - struct list_head *list_node = NULL; - struct cpld_client_node *cpld_node = NULL; - int ret = -EIO; - struct cpld_data *data; - - list_for_each(list_node, &cpld_client_list) { - cpld_node = list_entry(list_node, - struct cpld_client_node, list); - data = i2c_get_clientdata(cpld_node->client); - - if (data->index == cpld_idx) { - I2C_WRITE_BYTE_DATA(ret, &data->access_lock, - cpld_node->client, - reg, value); - DEBUG_PRINT("cpld_idx=%d, write reg 0x%02x val 0x%02x, ret=%d", - cpld_idx, reg, value, ret); - break; - } - } - - return ret; -} -EXPORT_SYMBOL(s9300_cpld_write); - -static int __init s9300_cpld_init(void) -{ - mutex_init(&list_lock); - return i2c_add_driver(&s9300_cpld_driver); -} - -static void __exit s9300_cpld_exit(void) -{ - i2c_del_driver(&s9300_cpld_driver); -} - -MODULE_AUTHOR("Leo Lin "); -MODULE_DESCRIPTION("x86_64_ufispace_s9300_cpld driver"); -MODULE_LICENSE("GPL"); - -module_init(s9300_cpld_init); -module_exit(s9300_cpld_exit); +/* + * A i2c cpld driver for the ufispace_s9300_32d + * + * Copyright (C) 2017-2019 UfiSpace Technology Corporation. + * Jason Tsai + * + * Based on ad7414.c + * Copyright 2006 Stefan Roese , DENX Software Engineering + * + * 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. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + */ +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include "x86-64-ufispace-s9300-32d-cpld.h" + +#ifdef DEBUG +#define DEBUG_PRINT(fmt, args...) \ + printk(KERN_INFO "%s:%s[%d]: " fmt "\r\n", \ + __FILE__, __func__, __LINE__, ##args) +#else +#define DEBUG_PRINT(fmt, args...) +#endif + +#define BSP_LOG_R(fmt, args...) \ + _bsp_log (LOG_READ, KERN_INFO "%s:%s[%d]: " fmt "\r\n", \ + __FILE__, __func__, __LINE__, ##args) +#define BSP_LOG_W(fmt, args...) \ + _bsp_log (LOG_WRITE, KERN_INFO "%s:%s[%d]: " fmt "\r\n", \ + __FILE__, __func__, __LINE__, ##args) + +#define I2C_READ_BYTE_DATA(ret, lock, i2c_client, reg) \ +{ \ + mutex_lock(lock); \ + ret = i2c_smbus_read_byte_data(i2c_client, reg); \ + mutex_unlock(lock); \ + BSP_LOG_R("cpld[%d], reg=0x%03x, reg_val=0x%02x", data->index, reg, ret); \ +} +#define I2C_WRITE_BYTE_DATA(ret, lock, i2c_client, reg, val) \ +{ \ + mutex_lock(lock); \ + ret = i2c_smbus_write_byte_data(i2c_client, reg, val); \ + mutex_unlock(lock); \ + BSP_LOG_W("cpld[%d], reg=0x%03x, reg_val=0x%02x", data->index, reg, val); \ +} + +/* CPLD sysfs attributes index */ +enum s9300_cpld_sysfs_attributes { + /* CPLD1 */ + CPLD_ACCESS_REG, + CPLD_REGISTER_VAL, + CPLD_SKU_ID, + CPLD_HW_REV, + CPLD_DEPH_REV, + CPLD_BUILD_REV, + CPLD_ID_TYPE, + CPLD_MAJOR_VER, + CPLD_MINOR_VER, + CPLD_BUILD_VER, + CPLD_VERION_H, + CPLD_ID, + CPLD_MAC_INTR, + CPLD_10G_PHY_INTR, + CPLD_CPLD_FRU_INTR, + CPLD_THERMAL_ALERT_INTR, + CPLD_MISC_INTR, + CPLD_SYSTEM_INTR, + CPLD_MAC_INTR_MASK, + CPLD_10G_PHY_INTR_MASK, + CPLD_CPLD_FRU_INTR_MASK, + CPLD_THERMAL_ALERT_INTR_MASK, + CPLD_MISC_INTR_MASK, + CPLD_MAC_INTR_EVENT, + CPLD_10G_PHY_INTR_EVENT, + CPLD_CPLD_FRU_INTR_EVENT, + CPLD_THERMAL_ALERT_INTR_EVENT, + CPLD_MISC_INTR_EVENT, + CPLD_MAC_RST, + CPLD_10G_PHY_RST, + CPLD_BMC_RST, + CPLD_USB_RST, + CPLD_MUX_RST, + CPLD_MISC_RST, + CPLD_BMC_WATCHDOG, + CPLD_DAU_BD_PRES, + CPLD_PSU_STATUS, + CPLD_SYS_PW_STATUS, + CPLD_MISC, + CPLD_MUX_CTRL, + CPLD_MAC_QSFP_SEL_CTRL, + CPLD_SYS_LED_CTRL_1, + CPLD_SYS_LED_CTRL_2, + CPLD_BEACON_LED_CTRL, + CPLD_PORT_LED_CLR_CTRL, + CPLD_EVENT_DETECT_CTRL, + /* CPLD2 */ + CPLD_QSFPDD_MOD_INT_G0, + CPLD_QSFPDD_MOD_INT_G1, + CPLD_QSFPDD_MOD_INT_G2, + CPLD_QSFPDD_MOD_INT_G3, + CPLD_QSFPDD_PRES_G0, + CPLD_QSFPDD_PRES_G1, + CPLD_QSFPDD_PRES_G2, + CPLD_QSFPDD_PRES_G3, + CPLD_QSFPDD_FUSE_INT_G0, + CPLD_QSFPDD_FUSE_INT_G1, + CPLD_QSFPDD_FUSE_INT_G2, + CPLD_QSFPDD_FUSE_INT_G3, + CPLD_SFP_TXFAULT, + CPLD_SFP_ABS, + CPLD_SFP_RXLOS, + CPLD_QSFPDD_MOD_INT_MASK_G0, + CPLD_QSFPDD_MOD_INT_MASK_G1, + CPLD_QSFPDD_MOD_INT_MASK_G2, + CPLD_QSFPDD_MOD_INT_MASK_G3, + CPLD_QSFPDD_PRES_MASK_G0, + CPLD_QSFPDD_PRES_MASK_G1, + CPLD_QSFPDD_PRES_MASK_G2, + CPLD_QSFPDD_PRES_MASK_G3, + CPLD_QSFPDD_FUSE_INT_MASK_G0, + CPLD_QSFPDD_FUSE_INT_MASK_G1, + CPLD_QSFPDD_FUSE_INT_MASK_G2, + CPLD_QSFPDD_FUSE_INT_MASK_G3, + CPLD_SFP_TXFAULT_MASK, + CPLD_SFP_ABS_MASK, + CPLD_SFP_RXLOS_MASK, + CPLD_QSFPDD_MOD_INT_EVENT_G0, + CPLD_QSFPDD_MOD_INT_EVENT_G1, + CPLD_QSFPDD_MOD_INT_EVENT_G2, + CPLD_QSFPDD_MOD_INT_EVENT_G3, + CPLD_QSFPDD_PRES_EVENT_G0, + CPLD_QSFPDD_PRES_EVENT_G1, + CPLD_QSFPDD_PRES_EVENT_G2, + CPLD_QSFPDD_PRES_EVENT_G3, + CPLD_QSFPDD_FUSE_INT_EVENT_G0, + CPLD_QSFPDD_FUSE_INT_EVENT_G1, + CPLD_QSFPDD_FUSE_INT_EVENT_G2, + CPLD_QSFPDD_FUSE_INT_EVENT_G3, + CPLD_SFP_TXFAULT_EVENT, + CPLD_SFP_ABS_EVENT, + CPLD_SFP_RXLOS_EVENT, + CPLD_QSFPDD_RESET_CTRL_G0, + CPLD_QSFPDD_RESET_CTRL_G1, + CPLD_QSFPDD_RESET_CTRL_G2, + CPLD_QSFPDD_RESET_CTRL_G3, + CPLD_QSFPDD_LP_MODE_G0, + CPLD_QSFPDD_LP_MODE_G1, + CPLD_QSFPDD_LP_MODE_G2, + CPLD_QSFPDD_LP_MODE_G3, + CPLD_SFP_TX_DIS, + CPLD_SFP_RS, + CPLD_SFP_TS, + CPLD_PORT_INT_STATUS, + + //BSP DEBUG + BSP_DEBUG +}; + +enum bsp_log_types { + LOG_NONE, + LOG_RW, + LOG_READ, + LOG_WRITE +}; + +enum bsp_log_ctrl { + LOG_DISABLE, + LOG_ENABLE +}; + +/* CPLD sysfs attributes hook functions */ +static ssize_t read_access_register(struct device *dev, + struct device_attribute *da, char *buf); +static ssize_t write_access_register(struct device *dev, + struct device_attribute *da, const char *buf, size_t count); +static ssize_t read_register_value(struct device *dev, + struct device_attribute *da, char *buf); +static ssize_t write_register_value(struct device *dev, + struct device_attribute *da, const char *buf, size_t count); +static ssize_t read_hw_rev_cb(struct device *dev, + struct device_attribute *da, char *buf); +static ssize_t read_cpld_version_cb(struct device *dev, + struct device_attribute *da, char *buf); +static ssize_t read_cpld_callback(struct device *dev, + struct device_attribute *da, char *buf); +static ssize_t write_cpld_callback(struct device *dev, + struct device_attribute *da, const char *buf, size_t count); +static ssize_t read_cpld_version_h_cb(struct device *dev, + struct device_attribute *da, char *buf); +// cpld access api +static ssize_t read_cpld_reg(struct device *dev, char *buf, u8 reg); +static ssize_t write_cpld_reg(struct device *dev, const char *buf, size_t count, u8 reg); +static bool read_cpld_reg_raw_byte(struct device *dev, u8 reg, u8 *val, int *errno); +static bool read_cpld_reg_raw_int(struct device *dev, u8 reg, int *val); +// bsp debug api +static ssize_t read_bsp(char *buf, char *str); +static ssize_t write_bsp(const char *buf, char *str, size_t str_len, size_t count); +static ssize_t read_bsp_callback(struct device *dev, + struct device_attribute *da, char *buf); +static ssize_t write_bsp_callback(struct device *dev, + struct device_attribute *da, const char *buf, size_t count); + +static LIST_HEAD(cpld_client_list); /* client list for cpld */ +static struct mutex list_lock; /* mutex for client list */ + +struct cpld_client_node { + struct i2c_client *client; + struct list_head list; +}; + +struct cpld_data { + int index; /* CPLD index */ + struct mutex access_lock; /* mutex for cpld access */ + u8 access_reg; /* register to access */ +}; + +/* CPLD device id and data */ +static const struct i2c_device_id s9300_cpld_id[] = { + { "s9300_32d_cpld1", cpld1 }, + { "s9300_32d_cpld2", cpld2 }, + { "s9300_32d_cpld3", cpld3 }, + {} +}; + +char bsp_debug[2]="0"; +u8 enable_log_read=LOG_DISABLE; +u8 enable_log_write=LOG_DISABLE; + +/* Addresses scanned for s9300_cpld */ +static const unsigned short cpld_i2c_addr[] = { 0x30, 0x31, 0x32, I2C_CLIENT_END }; + +/* define all support register access of cpld in attribute */ +/* CPLD1 */ +static SENSOR_DEVICE_ATTR(cpld_access_register, S_IWUSR | S_IRUGO, \ + read_access_register, write_access_register, CPLD_ACCESS_REG); +static SENSOR_DEVICE_ATTR(cpld_register_value, S_IWUSR | S_IRUGO, \ + read_register_value, write_register_value, CPLD_REGISTER_VAL); +static SENSOR_DEVICE_ATTR(cpld_sku_id, S_IRUGO, \ + read_cpld_callback, NULL, CPLD_SKU_ID); +static SENSOR_DEVICE_ATTR(cpld_hw_rev, S_IRUGO, \ + read_hw_rev_cb, NULL, CPLD_HW_REV); +static SENSOR_DEVICE_ATTR(cpld_deph_rev, S_IRUGO, \ + read_hw_rev_cb, NULL, CPLD_DEPH_REV); +static SENSOR_DEVICE_ATTR(cpld_build_rev, S_IRUGO, \ + read_hw_rev_cb, NULL, CPLD_BUILD_REV); +static SENSOR_DEVICE_ATTR(cpld_id_type, S_IRUGO, \ + read_hw_rev_cb, NULL, CPLD_ID_TYPE); +static SENSOR_DEVICE_ATTR(cpld_major_ver, S_IRUGO, \ + read_cpld_version_cb, NULL, CPLD_MAJOR_VER); +static SENSOR_DEVICE_ATTR(cpld_minor_ver, S_IRUGO, \ + read_cpld_version_cb, NULL, CPLD_MINOR_VER); +static SENSOR_DEVICE_ATTR(cpld_build_ver, S_IRUGO, \ + read_cpld_callback, NULL, CPLD_BUILD_VER); +static SENSOR_DEVICE_ATTR(cpld_version_h, S_IRUGO, \ + read_cpld_version_h_cb, NULL, CPLD_VERION_H); +static SENSOR_DEVICE_ATTR(cpld_id, S_IRUGO, \ + read_cpld_callback, NULL, CPLD_ID); +static SENSOR_DEVICE_ATTR(cpld_mac_intr, S_IRUGO, \ + read_cpld_callback, NULL, CPLD_MAC_INTR); +static SENSOR_DEVICE_ATTR(cpld_10g_phy_intr, S_IRUGO, \ + read_cpld_callback, NULL, CPLD_10G_PHY_INTR); +static SENSOR_DEVICE_ATTR(cpld_cpld_fru_intr, S_IRUGO, \ + read_cpld_callback, NULL, CPLD_CPLD_FRU_INTR); +static SENSOR_DEVICE_ATTR(cpld_thermal_alert_intr, S_IRUGO, \ + read_cpld_callback, NULL, CPLD_THERMAL_ALERT_INTR); +static SENSOR_DEVICE_ATTR(cpld_misc_intr, S_IRUGO, \ + read_cpld_callback, NULL, CPLD_MISC_INTR); +static SENSOR_DEVICE_ATTR(cpld_system_intr, S_IRUGO, \ + read_cpld_callback, NULL, CPLD_SYSTEM_INTR); +static SENSOR_DEVICE_ATTR(cpld_mac_intr_mask, S_IWUSR | S_IRUGO, \ + read_cpld_callback, write_cpld_callback, CPLD_MAC_INTR_MASK); +static SENSOR_DEVICE_ATTR(cpld_10g_phy_intr_mask, S_IWUSR | S_IRUGO, \ + read_cpld_callback, write_cpld_callback, CPLD_10G_PHY_INTR_MASK); +static SENSOR_DEVICE_ATTR(cpld_cpld_fru_intr_mask, S_IWUSR | S_IRUGO, \ + read_cpld_callback, write_cpld_callback, CPLD_CPLD_FRU_INTR_MASK); +static SENSOR_DEVICE_ATTR(cpld_thermal_alert_intr_mask, S_IWUSR | S_IRUGO, \ + read_cpld_callback, write_cpld_callback, CPLD_THERMAL_ALERT_INTR_MASK); +static SENSOR_DEVICE_ATTR(cpld_misc_intr_mask, S_IWUSR | S_IRUGO, \ + read_cpld_callback, write_cpld_callback, CPLD_MISC_INTR_MASK); +static SENSOR_DEVICE_ATTR(cpld_mac_intr_event, S_IRUGO, \ + read_cpld_callback, NULL, CPLD_MAC_INTR_EVENT); +static SENSOR_DEVICE_ATTR(cpld_10g_phy_intr_event, S_IRUGO, \ + read_cpld_callback, NULL, CPLD_10G_PHY_INTR_EVENT); +static SENSOR_DEVICE_ATTR(cpld_cpld_fru_intr_event, S_IRUGO, \ + read_cpld_callback, NULL, CPLD_CPLD_FRU_INTR_EVENT); +static SENSOR_DEVICE_ATTR(cpld_thermal_alert_intr_event, S_IRUGO, \ + read_cpld_callback, NULL, CPLD_THERMAL_ALERT_INTR_EVENT); +static SENSOR_DEVICE_ATTR(cpld_misc_intr_event, S_IRUGO, \ + read_cpld_callback, NULL, CPLD_MISC_INTR_EVENT); +static SENSOR_DEVICE_ATTR(cpld_mac_rst, S_IWUSR | S_IRUGO, \ + read_cpld_callback, write_cpld_callback, CPLD_MAC_RST); +static SENSOR_DEVICE_ATTR(cpld_10g_phy_rst, S_IWUSR | S_IRUGO, \ + read_cpld_callback, write_cpld_callback, CPLD_10G_PHY_RST); +static SENSOR_DEVICE_ATTR(cpld_bmc_rst, S_IWUSR | S_IRUGO, \ + read_cpld_callback, write_cpld_callback, CPLD_BMC_RST); +static SENSOR_DEVICE_ATTR(cpld_usb_rst, S_IWUSR | S_IRUGO, \ + read_cpld_callback, write_cpld_callback, CPLD_USB_RST); +static SENSOR_DEVICE_ATTR(cpld_mux_rst, S_IWUSR | S_IRUGO, \ + read_cpld_callback, write_cpld_callback, CPLD_MUX_RST); +static SENSOR_DEVICE_ATTR(cpld_misc_rst, S_IWUSR | S_IRUGO, \ + read_cpld_callback, write_cpld_callback, CPLD_MISC_RST); +static SENSOR_DEVICE_ATTR(cpld_bmc_watchdog, S_IWUSR | S_IRUGO, \ + read_cpld_callback, write_cpld_callback, CPLD_BMC_WATCHDOG); +static SENSOR_DEVICE_ATTR(cpld_dau_bd_pres, S_IRUGO, \ + read_cpld_callback, NULL, CPLD_DAU_BD_PRES); +static SENSOR_DEVICE_ATTR(cpld_psu_status, S_IRUGO, \ + read_cpld_callback, NULL, CPLD_PSU_STATUS); +static SENSOR_DEVICE_ATTR(cpld_sys_pw_status, S_IRUGO, \ + read_cpld_callback, NULL, CPLD_SYS_PW_STATUS); +static SENSOR_DEVICE_ATTR(cpld_misc, S_IRUGO, \ + read_cpld_callback, NULL, CPLD_MISC); +static SENSOR_DEVICE_ATTR(cpld_mux_ctrl, S_IWUSR | S_IRUGO, \ + read_cpld_callback, write_cpld_callback, CPLD_MUX_CTRL); +static SENSOR_DEVICE_ATTR(cpld_mac_qsfp_sel_ctrl, S_IWUSR | S_IRUGO, \ + read_cpld_callback, write_cpld_callback, CPLD_MAC_QSFP_SEL_CTRL); +static SENSOR_DEVICE_ATTR(cpld_sys_led_ctrl_1, S_IRUGO, \ + read_cpld_callback, NULL, CPLD_SYS_LED_CTRL_1); +static SENSOR_DEVICE_ATTR(cpld_sys_led_ctrl_2, S_IRUGO, \ + read_cpld_callback, NULL, CPLD_SYS_LED_CTRL_2); +static SENSOR_DEVICE_ATTR(cpld_beacon_led_ctrl, S_IWUSR | S_IRUGO, \ + read_cpld_callback, write_cpld_callback, CPLD_BEACON_LED_CTRL); +static SENSOR_DEVICE_ATTR(cpld_port_led_clr_ctrl, S_IWUSR | S_IRUGO, \ + read_cpld_callback, write_cpld_callback, CPLD_PORT_LED_CLR_CTRL); +static SENSOR_DEVICE_ATTR(cpld_event_detect_ctrl, S_IWUSR | S_IRUGO, \ + read_cpld_callback, write_cpld_callback, CPLD_EVENT_DETECT_CTRL); +/* CPLD2 */ +static SENSOR_DEVICE_ATTR(cpld_qsfpdd_mod_int_g0, S_IRUGO, \ + read_cpld_callback, NULL, CPLD_QSFPDD_MOD_INT_G0); +static SENSOR_DEVICE_ATTR(cpld_qsfpdd_mod_int_g1, S_IRUGO, \ + read_cpld_callback, NULL, CPLD_QSFPDD_MOD_INT_G1); +static SENSOR_DEVICE_ATTR(cpld_qsfpdd_mod_int_g2, S_IRUGO, \ + read_cpld_callback, NULL, CPLD_QSFPDD_MOD_INT_G2); +static SENSOR_DEVICE_ATTR(cpld_qsfpdd_mod_int_g3, S_IRUGO, \ + read_cpld_callback, NULL, CPLD_QSFPDD_MOD_INT_G3); +static SENSOR_DEVICE_ATTR(cpld_qsfpdd_pres_g0, S_IRUGO, \ + read_cpld_callback, NULL, CPLD_QSFPDD_PRES_G0); +static SENSOR_DEVICE_ATTR(cpld_qsfpdd_pres_g1, S_IRUGO, \ + read_cpld_callback, NULL, CPLD_QSFPDD_PRES_G1); +static SENSOR_DEVICE_ATTR(cpld_qsfpdd_pres_g2, S_IRUGO, \ + read_cpld_callback, NULL, CPLD_QSFPDD_PRES_G2); +static SENSOR_DEVICE_ATTR(cpld_qsfpdd_pres_g3, S_IRUGO, \ + read_cpld_callback, NULL, CPLD_QSFPDD_PRES_G3); +static SENSOR_DEVICE_ATTR(cpld_qsfpdd_fuse_int_g0, S_IRUGO, \ + read_cpld_callback, NULL, CPLD_QSFPDD_FUSE_INT_G0); +static SENSOR_DEVICE_ATTR(cpld_qsfpdd_fuse_int_g1, S_IRUGO, \ + read_cpld_callback, NULL, CPLD_QSFPDD_FUSE_INT_G1); +static SENSOR_DEVICE_ATTR(cpld_qsfpdd_fuse_int_g2, S_IRUGO, \ + read_cpld_callback, NULL, CPLD_QSFPDD_FUSE_INT_G2); +static SENSOR_DEVICE_ATTR(cpld_qsfpdd_fuse_int_g3, S_IRUGO, \ + read_cpld_callback, NULL, CPLD_QSFPDD_FUSE_INT_G3); +static SENSOR_DEVICE_ATTR(cpld_sfp_txfault, S_IRUGO, \ + read_cpld_callback, NULL, CPLD_SFP_TXFAULT); +static SENSOR_DEVICE_ATTR(cpld_sfp_abs, S_IRUGO, \ + read_cpld_callback, NULL, CPLD_SFP_ABS); +static SENSOR_DEVICE_ATTR(cpld_sfp_rxlos, S_IRUGO, \ + read_cpld_callback, NULL, CPLD_SFP_RXLOS); +static SENSOR_DEVICE_ATTR(cpld_qsfpdd_mod_int_mask_g0, S_IWUSR | S_IRUGO, \ + read_cpld_callback, write_cpld_callback, CPLD_QSFPDD_MOD_INT_MASK_G0); +static SENSOR_DEVICE_ATTR(cpld_qsfpdd_mod_int_mask_g1, S_IWUSR | S_IRUGO, \ + read_cpld_callback, write_cpld_callback, CPLD_QSFPDD_MOD_INT_MASK_G1); +static SENSOR_DEVICE_ATTR(cpld_qsfpdd_mod_int_mask_g2, S_IWUSR | S_IRUGO, \ + read_cpld_callback, write_cpld_callback, CPLD_QSFPDD_MOD_INT_MASK_G2); +static SENSOR_DEVICE_ATTR(cpld_qsfpdd_mod_int_mask_g3, S_IWUSR | S_IRUGO, \ + read_cpld_callback, write_cpld_callback, CPLD_QSFPDD_MOD_INT_MASK_G3); +static SENSOR_DEVICE_ATTR(cpld_qsfpdd_pres_mask_g0, S_IWUSR | S_IRUGO, \ + read_cpld_callback, write_cpld_callback, CPLD_QSFPDD_PRES_MASK_G0); +static SENSOR_DEVICE_ATTR(cpld_qsfpdd_pres_mask_g1, S_IWUSR | S_IRUGO, \ + read_cpld_callback, write_cpld_callback, CPLD_QSFPDD_PRES_MASK_G1); +static SENSOR_DEVICE_ATTR(cpld_qsfpdd_pres_mask_g2, S_IWUSR | S_IRUGO, \ + read_cpld_callback, write_cpld_callback, CPLD_QSFPDD_PRES_MASK_G2); +static SENSOR_DEVICE_ATTR(cpld_qsfpdd_pres_mask_g3, S_IWUSR | S_IRUGO, \ + read_cpld_callback, write_cpld_callback, CPLD_QSFPDD_PRES_MASK_G3); +static SENSOR_DEVICE_ATTR(cpld_qsfpdd_fuse_int_mask_g0, S_IWUSR | S_IRUGO, \ + read_cpld_callback, write_cpld_callback, CPLD_QSFPDD_FUSE_INT_MASK_G0); +static SENSOR_DEVICE_ATTR(cpld_qsfpdd_fuse_int_mask_g1, S_IWUSR | S_IRUGO, \ + read_cpld_callback, write_cpld_callback, CPLD_QSFPDD_FUSE_INT_MASK_G1); +static SENSOR_DEVICE_ATTR(cpld_qsfpdd_fuse_int_mask_g2, S_IWUSR | S_IRUGO, \ + read_cpld_callback, write_cpld_callback, CPLD_QSFPDD_FUSE_INT_MASK_G2); +static SENSOR_DEVICE_ATTR(cpld_qsfpdd_fuse_int_mask_g3, S_IWUSR | S_IRUGO, \ + read_cpld_callback, write_cpld_callback, CPLD_QSFPDD_FUSE_INT_MASK_G3); +static SENSOR_DEVICE_ATTR(cpld_sfp_txfault_mask, S_IWUSR | S_IRUGO, \ + read_cpld_callback, write_cpld_callback, CPLD_SFP_TXFAULT_MASK); +static SENSOR_DEVICE_ATTR(cpld_sfp_abs_mask, S_IWUSR | S_IRUGO, \ + read_cpld_callback, write_cpld_callback, CPLD_SFP_ABS_MASK); +static SENSOR_DEVICE_ATTR(cpld_sfp_rxlos_mask, S_IWUSR | S_IRUGO, \ + read_cpld_callback, write_cpld_callback, CPLD_SFP_RXLOS_MASK); +static SENSOR_DEVICE_ATTR(cpld_qsfpdd_mod_int_event_g0, S_IRUGO, \ + read_cpld_callback, NULL, CPLD_QSFPDD_MOD_INT_EVENT_G0); +static SENSOR_DEVICE_ATTR(cpld_qsfpdd_mod_int_event_g1, S_IRUGO, \ + read_cpld_callback, NULL, CPLD_QSFPDD_MOD_INT_EVENT_G1); +static SENSOR_DEVICE_ATTR(cpld_qsfpdd_mod_int_event_g2, S_IRUGO, \ + read_cpld_callback, NULL, CPLD_QSFPDD_MOD_INT_EVENT_G2); +static SENSOR_DEVICE_ATTR(cpld_qsfpdd_mod_int_event_g3, S_IRUGO, \ + read_cpld_callback, NULL, CPLD_QSFPDD_MOD_INT_EVENT_G3); +static SENSOR_DEVICE_ATTR(cpld_qsfpdd_pres_event_g0, S_IRUGO, \ + read_cpld_callback, NULL, CPLD_QSFPDD_PRES_EVENT_G0); +static SENSOR_DEVICE_ATTR(cpld_qsfpdd_pres_event_g1, S_IRUGO, \ + read_cpld_callback, NULL, CPLD_QSFPDD_PRES_EVENT_G1); +static SENSOR_DEVICE_ATTR(cpld_qsfpdd_pres_event_g2, S_IRUGO, \ + read_cpld_callback, NULL, CPLD_QSFPDD_PRES_EVENT_G2); +static SENSOR_DEVICE_ATTR(cpld_qsfpdd_pres_event_g3, S_IRUGO, \ + read_cpld_callback, NULL, CPLD_QSFPDD_PRES_EVENT_G3); +static SENSOR_DEVICE_ATTR(cpld_qsfpdd_fuse_int_event_g0, S_IRUGO, \ + read_cpld_callback, NULL, CPLD_QSFPDD_FUSE_INT_EVENT_G0); +static SENSOR_DEVICE_ATTR(cpld_qsfpdd_fuse_int_event_g1, S_IRUGO, \ + read_cpld_callback, NULL, CPLD_QSFPDD_FUSE_INT_EVENT_G1); +static SENSOR_DEVICE_ATTR(cpld_qsfpdd_fuse_int_event_g2, S_IRUGO, \ + read_cpld_callback, NULL, CPLD_QSFPDD_FUSE_INT_EVENT_G2); +static SENSOR_DEVICE_ATTR(cpld_qsfpdd_fuse_int_event_g3, S_IRUGO, \ + read_cpld_callback, NULL, CPLD_QSFPDD_FUSE_INT_EVENT_G3); +static SENSOR_DEVICE_ATTR(cpld_sfp_txfault_event, S_IRUGO, \ + read_cpld_callback, NULL, CPLD_SFP_TXFAULT_EVENT); +static SENSOR_DEVICE_ATTR(cpld_sfp_abs_event, S_IRUGO, \ + read_cpld_callback, NULL, CPLD_SFP_ABS_EVENT); +static SENSOR_DEVICE_ATTR(cpld_sfp_rxlos_event, S_IRUGO, \ + read_cpld_callback, NULL, CPLD_SFP_RXLOS_EVENT); +static SENSOR_DEVICE_ATTR(cpld_qsfpdd_reset_ctrl_g0, \ + S_IWUSR | S_IRUGO, \ + read_cpld_callback, write_cpld_callback, \ + CPLD_QSFPDD_RESET_CTRL_G0); +static SENSOR_DEVICE_ATTR(cpld_qsfpdd_reset_ctrl_g1, \ + S_IWUSR | S_IRUGO, \ + read_cpld_callback, write_cpld_callback, \ + CPLD_QSFPDD_RESET_CTRL_G1); +static SENSOR_DEVICE_ATTR(cpld_qsfpdd_reset_ctrl_g2, \ + S_IWUSR | S_IRUGO, \ + read_cpld_callback, write_cpld_callback, \ + CPLD_QSFPDD_RESET_CTRL_G2); +static SENSOR_DEVICE_ATTR(cpld_qsfpdd_reset_ctrl_g3, \ + S_IWUSR | S_IRUGO, \ + read_cpld_callback, write_cpld_callback, \ + CPLD_QSFPDD_RESET_CTRL_G3); +static SENSOR_DEVICE_ATTR(cpld_qsfpdd_lp_mode_g0, \ + S_IWUSR | S_IRUGO, \ + read_cpld_callback, write_cpld_callback, \ + CPLD_QSFPDD_LP_MODE_G0); +static SENSOR_DEVICE_ATTR(cpld_qsfpdd_lp_mode_g1, \ + S_IWUSR | S_IRUGO, \ + read_cpld_callback, write_cpld_callback, \ + CPLD_QSFPDD_LP_MODE_G1); +static SENSOR_DEVICE_ATTR(cpld_qsfpdd_lp_mode_g2, \ + S_IWUSR | S_IRUGO, \ + read_cpld_callback, write_cpld_callback, \ + CPLD_QSFPDD_LP_MODE_G2); +static SENSOR_DEVICE_ATTR(cpld_qsfpdd_lp_mode_g3, \ + S_IWUSR | S_IRUGO, \ + read_cpld_callback, write_cpld_callback, \ + CPLD_QSFPDD_LP_MODE_G3); +static SENSOR_DEVICE_ATTR(cpld_sfp_tx_dis, S_IWUSR | S_IRUGO, \ + read_cpld_callback, write_cpld_callback, CPLD_SFP_TX_DIS); +static SENSOR_DEVICE_ATTR(cpld_sfp_rs, S_IWUSR | S_IRUGO, \ + read_cpld_callback, write_cpld_callback, CPLD_SFP_RS); +static SENSOR_DEVICE_ATTR(cpld_sfp_ts, S_IWUSR | S_IRUGO, \ + read_cpld_callback, write_cpld_callback, CPLD_SFP_TS); +static SENSOR_DEVICE_ATTR(cpld_port_int_status, S_IRUGO, \ + read_cpld_callback, NULL, CPLD_PORT_INT_STATUS); +//BSP DEBUG +static SENSOR_DEVICE_ATTR(bsp_debug, S_IRUGO | S_IWUSR, \ + read_bsp_callback, write_bsp_callback, BSP_DEBUG); + +/* define support attributes of cpldx , total 3 */ +/* cpld 1 */ +static struct attribute *s9300_cpld1_attributes[] = { + &sensor_dev_attr_cpld_access_register.dev_attr.attr, + &sensor_dev_attr_cpld_register_value.dev_attr.attr, + &sensor_dev_attr_cpld_sku_id.dev_attr.attr, + &sensor_dev_attr_cpld_hw_rev.dev_attr.attr, + &sensor_dev_attr_cpld_deph_rev.dev_attr.attr, + &sensor_dev_attr_cpld_build_rev.dev_attr.attr, + &sensor_dev_attr_cpld_id_type.dev_attr.attr, + &sensor_dev_attr_cpld_major_ver.dev_attr.attr, + &sensor_dev_attr_cpld_minor_ver.dev_attr.attr, + &sensor_dev_attr_cpld_build_ver.dev_attr.attr, + &sensor_dev_attr_cpld_version_h.dev_attr.attr, + &sensor_dev_attr_cpld_id.dev_attr.attr, + &sensor_dev_attr_cpld_mac_intr.dev_attr.attr, + &sensor_dev_attr_cpld_10g_phy_intr.dev_attr.attr, + &sensor_dev_attr_cpld_cpld_fru_intr.dev_attr.attr, + &sensor_dev_attr_cpld_thermal_alert_intr.dev_attr.attr, + &sensor_dev_attr_cpld_misc_intr.dev_attr.attr, + &sensor_dev_attr_cpld_system_intr.dev_attr.attr, + &sensor_dev_attr_cpld_mac_intr_mask.dev_attr.attr, + &sensor_dev_attr_cpld_10g_phy_intr_mask.dev_attr.attr, + &sensor_dev_attr_cpld_cpld_fru_intr_mask.dev_attr.attr, + &sensor_dev_attr_cpld_thermal_alert_intr_mask.dev_attr.attr, + &sensor_dev_attr_cpld_misc_intr_mask.dev_attr.attr, + &sensor_dev_attr_cpld_mac_intr_event.dev_attr.attr, + &sensor_dev_attr_cpld_10g_phy_intr_event.dev_attr.attr, + &sensor_dev_attr_cpld_cpld_fru_intr_event.dev_attr.attr, + &sensor_dev_attr_cpld_thermal_alert_intr_event.dev_attr.attr, + &sensor_dev_attr_cpld_misc_intr_event.dev_attr.attr, + &sensor_dev_attr_cpld_mac_rst.dev_attr.attr, + &sensor_dev_attr_cpld_10g_phy_rst.dev_attr.attr, + &sensor_dev_attr_cpld_bmc_rst.dev_attr.attr, + &sensor_dev_attr_cpld_usb_rst.dev_attr.attr, + &sensor_dev_attr_cpld_mux_rst.dev_attr.attr, + &sensor_dev_attr_cpld_misc_rst.dev_attr.attr, + &sensor_dev_attr_cpld_bmc_watchdog.dev_attr.attr, + &sensor_dev_attr_cpld_dau_bd_pres.dev_attr.attr, + &sensor_dev_attr_cpld_psu_status.dev_attr.attr, + &sensor_dev_attr_cpld_sys_pw_status.dev_attr.attr, + &sensor_dev_attr_cpld_misc.dev_attr.attr, + &sensor_dev_attr_cpld_mux_ctrl.dev_attr.attr, + &sensor_dev_attr_cpld_mac_qsfp_sel_ctrl.dev_attr.attr, + &sensor_dev_attr_cpld_sys_led_ctrl_1.dev_attr.attr, + &sensor_dev_attr_cpld_sys_led_ctrl_2.dev_attr.attr, + &sensor_dev_attr_cpld_beacon_led_ctrl.dev_attr.attr, + &sensor_dev_attr_cpld_port_led_clr_ctrl.dev_attr.attr, + &sensor_dev_attr_cpld_event_detect_ctrl.dev_attr.attr, + &sensor_dev_attr_bsp_debug.dev_attr.attr, + NULL +}; + +/* cpld 2 */ +static struct attribute *s9300_cpld2_attributes[] = { + &sensor_dev_attr_cpld_access_register.dev_attr.attr, + &sensor_dev_attr_cpld_register_value.dev_attr.attr, + &sensor_dev_attr_cpld_major_ver.dev_attr.attr, + &sensor_dev_attr_cpld_minor_ver.dev_attr.attr, + &sensor_dev_attr_cpld_build_ver.dev_attr.attr, + &sensor_dev_attr_cpld_version_h.dev_attr.attr, + &sensor_dev_attr_cpld_id.dev_attr.attr, + &sensor_dev_attr_cpld_qsfpdd_mod_int_g0.dev_attr.attr, + &sensor_dev_attr_cpld_qsfpdd_mod_int_g1.dev_attr.attr, + &sensor_dev_attr_cpld_qsfpdd_mod_int_g2.dev_attr.attr, + &sensor_dev_attr_cpld_qsfpdd_mod_int_g3.dev_attr.attr, + &sensor_dev_attr_cpld_qsfpdd_pres_g0.dev_attr.attr, + &sensor_dev_attr_cpld_qsfpdd_pres_g1.dev_attr.attr, + &sensor_dev_attr_cpld_qsfpdd_pres_g2.dev_attr.attr, + &sensor_dev_attr_cpld_qsfpdd_pres_g3.dev_attr.attr, + &sensor_dev_attr_cpld_qsfpdd_fuse_int_g0.dev_attr.attr, + &sensor_dev_attr_cpld_qsfpdd_fuse_int_g1.dev_attr.attr, + &sensor_dev_attr_cpld_qsfpdd_fuse_int_g2.dev_attr.attr, + &sensor_dev_attr_cpld_qsfpdd_fuse_int_g3.dev_attr.attr, + &sensor_dev_attr_cpld_sfp_txfault.dev_attr.attr, + &sensor_dev_attr_cpld_sfp_abs.dev_attr.attr, + &sensor_dev_attr_cpld_sfp_rxlos.dev_attr.attr, + &sensor_dev_attr_cpld_qsfpdd_mod_int_mask_g0.dev_attr.attr, + &sensor_dev_attr_cpld_qsfpdd_mod_int_mask_g1.dev_attr.attr, + &sensor_dev_attr_cpld_qsfpdd_mod_int_mask_g2.dev_attr.attr, + &sensor_dev_attr_cpld_qsfpdd_mod_int_mask_g3.dev_attr.attr, + &sensor_dev_attr_cpld_qsfpdd_pres_mask_g0.dev_attr.attr, + &sensor_dev_attr_cpld_qsfpdd_pres_mask_g1.dev_attr.attr, + &sensor_dev_attr_cpld_qsfpdd_pres_mask_g2.dev_attr.attr, + &sensor_dev_attr_cpld_qsfpdd_pres_mask_g3.dev_attr.attr, + &sensor_dev_attr_cpld_qsfpdd_fuse_int_mask_g0.dev_attr.attr, + &sensor_dev_attr_cpld_qsfpdd_fuse_int_mask_g1.dev_attr.attr, + &sensor_dev_attr_cpld_qsfpdd_fuse_int_mask_g2.dev_attr.attr, + &sensor_dev_attr_cpld_qsfpdd_fuse_int_mask_g3.dev_attr.attr, + &sensor_dev_attr_cpld_sfp_txfault_mask.dev_attr.attr, + &sensor_dev_attr_cpld_sfp_abs_mask.dev_attr.attr, + &sensor_dev_attr_cpld_sfp_rxlos_mask.dev_attr.attr, + &sensor_dev_attr_cpld_qsfpdd_mod_int_event_g0.dev_attr.attr, + &sensor_dev_attr_cpld_qsfpdd_mod_int_event_g1.dev_attr.attr, + &sensor_dev_attr_cpld_qsfpdd_mod_int_event_g2.dev_attr.attr, + &sensor_dev_attr_cpld_qsfpdd_mod_int_event_g3.dev_attr.attr, + &sensor_dev_attr_cpld_qsfpdd_pres_event_g0.dev_attr.attr, + &sensor_dev_attr_cpld_qsfpdd_pres_event_g1.dev_attr.attr, + &sensor_dev_attr_cpld_qsfpdd_pres_event_g2.dev_attr.attr, + &sensor_dev_attr_cpld_qsfpdd_pres_event_g3.dev_attr.attr, + &sensor_dev_attr_cpld_qsfpdd_fuse_int_event_g0.dev_attr.attr, + &sensor_dev_attr_cpld_qsfpdd_fuse_int_event_g1.dev_attr.attr, + &sensor_dev_attr_cpld_qsfpdd_fuse_int_event_g2.dev_attr.attr, + &sensor_dev_attr_cpld_qsfpdd_fuse_int_event_g3.dev_attr.attr, + &sensor_dev_attr_cpld_sfp_txfault_event.dev_attr.attr, + &sensor_dev_attr_cpld_sfp_abs_event.dev_attr.attr, + &sensor_dev_attr_cpld_sfp_rxlos_event.dev_attr.attr, + &sensor_dev_attr_cpld_qsfpdd_reset_ctrl_g0.dev_attr.attr, + &sensor_dev_attr_cpld_qsfpdd_reset_ctrl_g1.dev_attr.attr, + &sensor_dev_attr_cpld_qsfpdd_reset_ctrl_g2.dev_attr.attr, + &sensor_dev_attr_cpld_qsfpdd_reset_ctrl_g3.dev_attr.attr, + &sensor_dev_attr_cpld_qsfpdd_lp_mode_g0.dev_attr.attr, + &sensor_dev_attr_cpld_qsfpdd_lp_mode_g1.dev_attr.attr, + &sensor_dev_attr_cpld_qsfpdd_lp_mode_g2.dev_attr.attr, + &sensor_dev_attr_cpld_qsfpdd_lp_mode_g3.dev_attr.attr, + &sensor_dev_attr_cpld_sfp_tx_dis.dev_attr.attr, + &sensor_dev_attr_cpld_sfp_rs.dev_attr.attr, + &sensor_dev_attr_cpld_sfp_ts.dev_attr.attr, + &sensor_dev_attr_cpld_port_int_status.dev_attr.attr, + NULL +}; + +/* cpld 3 */ +static struct attribute *s9300_cpld3_attributes[] = { + &sensor_dev_attr_cpld_access_register.dev_attr.attr, + &sensor_dev_attr_cpld_register_value.dev_attr.attr, + &sensor_dev_attr_cpld_major_ver.dev_attr.attr, + &sensor_dev_attr_cpld_minor_ver.dev_attr.attr, + &sensor_dev_attr_cpld_build_ver.dev_attr.attr, + &sensor_dev_attr_cpld_version_h.dev_attr.attr, + &sensor_dev_attr_cpld_id.dev_attr.attr, + NULL +}; + +/* cpld 1 attributes group */ +static const struct attribute_group s9300_cpld1_group = { + .attrs = s9300_cpld1_attributes, +}; +/* cpld 2 attributes group */ +static const struct attribute_group s9300_cpld2_group = { + .attrs = s9300_cpld2_attributes, +}; +/* cpld 3 attributes group */ +static const struct attribute_group s9300_cpld3_group = { + .attrs = s9300_cpld3_attributes, +}; + +static int _bsp_log(u8 log_type, char *fmt, ...) +{ + if ((log_type==LOG_READ && enable_log_read) || + (log_type==LOG_WRITE && enable_log_write)) { + va_list args; + int r; + + va_start(args, fmt); + r = vprintk(fmt, args); + va_end(args); + + return r; + } else { + return 0; + } +} + +static int _config_bsp_log(u8 log_type) +{ + switch(log_type) { + case LOG_NONE: + enable_log_read = LOG_DISABLE; + enable_log_write = LOG_DISABLE; + break; + case LOG_RW: + enable_log_read = LOG_ENABLE; + enable_log_write = LOG_ENABLE; + break; + case LOG_READ: + enable_log_read = LOG_ENABLE; + enable_log_write = LOG_DISABLE; + break; + case LOG_WRITE: + enable_log_read = LOG_DISABLE; + enable_log_write = LOG_ENABLE; + break; + default: + return -EINVAL; + } + return 0; +} + +/* get bsp value */ +static ssize_t read_bsp(char *buf, char *str) +{ + ssize_t len=0; + + len=sprintf(buf, "%s", str); + BSP_LOG_R("reg_val=%s", str); + + return len; +} + +/* set bsp value */ +static ssize_t write_bsp(const char *buf, char *str, size_t str_len, size_t count) +{ + snprintf(str, str_len, "%s", buf); + BSP_LOG_W("reg_val=%s", str); + + return count; +} + +/* get bsp parameter value */ +static ssize_t read_bsp_callback(struct device *dev, + struct device_attribute *da, char *buf) +{ + struct sensor_device_attribute *attr = to_sensor_dev_attr(da); + int str_len=0; + char *str=NULL; + + switch (attr->index) { + case BSP_DEBUG: + str = bsp_debug; + str_len = sizeof(bsp_debug); + break; + default: + return -EINVAL; + } + return read_bsp(buf, str); +} + +/* set bsp parameter value */ +static ssize_t write_bsp_callback(struct device *dev, + struct device_attribute *da, const char *buf, size_t count) +{ + struct sensor_device_attribute *attr = to_sensor_dev_attr(da); + int str_len=0; + char *str=NULL; + ssize_t ret = 0; + u8 bsp_debug_u8 = 0; + + switch (attr->index) { + case BSP_DEBUG: + str = bsp_debug; + str_len = sizeof(bsp_debug); + ret = write_bsp(buf, str, str_len, count); + + if (kstrtou8(buf, 0, &bsp_debug_u8) < 0) { + return -EINVAL; + } else if (_config_bsp_log(bsp_debug_u8) < 0) { + return -EINVAL; + } + return ret; + default: + return -EINVAL; + } + return 0; +} + +/* read access register from cpld data */ +static ssize_t read_access_register(struct device *dev, + struct device_attribute *da, + char *buf) +{ + struct i2c_client *client = to_i2c_client(dev); + struct cpld_data *data = i2c_get_clientdata(client); + u8 reg = data->access_reg; + + return sprintf(buf, "0x%x\n", reg); +} + +/* write access register to cpld data */ +static ssize_t write_access_register(struct device *dev, + struct device_attribute *da, + const char *buf, + size_t count) +{ + struct i2c_client *client = to_i2c_client(dev); + struct cpld_data *data = i2c_get_clientdata(client); + u8 reg; + + if (kstrtou8(buf, 0, ®) < 0) + return -EINVAL; + + data->access_reg = reg; + return count; +} + +/* read the value of access register in cpld data */ +static ssize_t read_register_value(struct device *dev, + struct device_attribute *da, + char *buf) +{ + struct i2c_client *client = to_i2c_client(dev); + struct cpld_data *data = i2c_get_clientdata(client); + u8 reg = data->access_reg; + int reg_val; + + I2C_READ_BYTE_DATA(reg_val, &data->access_lock, client, reg); + + if (reg_val < 0) + return reg_val; + + return sprintf(buf, "0x%x\n", reg_val); +} + +/* wrtie the value to access register in cpld data */ +static ssize_t write_register_value(struct device *dev, + struct device_attribute *da, + const char *buf, + size_t count) +{ + struct i2c_client *client = to_i2c_client(dev); + struct cpld_data *data = i2c_get_clientdata(client); + int ret = -EIO; + u8 reg = data->access_reg; + u8 reg_val; + + if (kstrtou8(buf, 0, ®_val) < 0) + return -EINVAL; + + I2C_WRITE_BYTE_DATA(ret, &data->access_lock, client, reg, reg_val); + + if (unlikely(ret < 0)) { + dev_err(dev, "I2C_WRITE_BYTE_DATA error, return=%d\n", ret); + return ret; + } + + return count; +} + +/* get cpld register value */ +static ssize_t read_cpld_reg(struct device *dev, + char *buf, + u8 reg) +{ + int reg_val; + + if (read_cpld_reg_raw_int(dev, reg, ®_val)) + return sprintf(buf, "0x%02x\n", reg_val); + else + return reg_val; +} + +static bool read_cpld_reg_raw_int(struct device *dev, u8 reg, int *val) +{ + struct i2c_client *client = to_i2c_client(dev); + struct cpld_data *data = i2c_get_clientdata(client); + I2C_READ_BYTE_DATA(*val, &data->access_lock, client, reg); + if (unlikely(*val < 0)) { + dev_err(dev, "read_cpld_reg_raw_int() error, return=%d\n", *val); + return false; + } + return true; +} + +static bool read_cpld_reg_raw_byte(struct device *dev, u8 reg, u8 *val, int *errno) +{ + int reg_val; + + if (read_cpld_reg_raw_int(dev, reg, ®_val)) { + *val = (u8)reg_val; + return true; + } else { + *errno = reg_val; + return false; + } +} + +/* handle read for attributes */ +static ssize_t read_cpld_callback(struct device *dev, + struct device_attribute *da, char *buf) +{ + struct sensor_device_attribute *attr = to_sensor_dev_attr(da); + u8 reg = 0; + + switch (attr->index) { + case CPLD_SKU_ID: + reg = CPLD_SKU_ID_REG; + break; + case CPLD_ID: + reg = CPLD_ID_REG; + break; + case CPLD_BUILD_VER: + reg = CPLD_BUILD_VER_REG; + break; + case CPLD_MAC_INTR: + reg = CPLD_MAC_INTR_REG; + break; + case CPLD_10G_PHY_INTR: + reg = CPLD_10G_PHY_INTR_REG; + break; + case CPLD_CPLD_FRU_INTR: + reg = CPLD_CPLD_FRU_INTR_REG; + break; + case CPLD_THERMAL_ALERT_INTR: + reg = CPLD_THERMAL_ALERT_INTR_REG; + break; + case CPLD_MISC_INTR: + reg = CPLD_MISC_INTR_REG; + break; + case CPLD_SYSTEM_INTR: + reg = CPLD_SYSTEM_INTR_REG; + break; + case CPLD_MAC_INTR_MASK: + reg = CPLD_MAC_INTR_MASK_REG; + break; + case CPLD_10G_PHY_INTR_MASK: + reg = CPLD_10G_PHY_INTR_MASK_REG; + break; + case CPLD_CPLD_FRU_INTR_MASK: + reg = CPLD_CPLD_FRU_INTR_MASK_REG; + break; + case CPLD_THERMAL_ALERT_INTR_MASK: + reg = CPLD_THERMAL_ALERT_INTR_MASK_REG; + break; + case CPLD_MISC_INTR_MASK: + reg = CPLD_MISC_INTR_MASK_REG; + break; + case CPLD_MAC_INTR_EVENT: + reg = CPLD_MAC_INTR_EVENT_REG; + break; + case CPLD_10G_PHY_INTR_EVENT: + reg = CPLD_10G_PHY_INTR_EVENT_REG; + break; + case CPLD_CPLD_FRU_INTR_EVENT: + reg = CPLD_CPLD_FRU_INTR_EVENT_REG; + break; + case CPLD_THERMAL_ALERT_INTR_EVENT: + reg = CPLD_THERMAL_ALERT_INTR_EVENT_REG; + break; + case CPLD_MISC_INTR_EVENT: + reg = CPLD_MISC_INTR_EVENT_REG; + break; + case CPLD_MAC_RST: + reg = CPLD_MAC_RST_REG; + break; + case CPLD_10G_PHY_RST: + reg = CPLD_10G_PHY_RST_REG; + break; + case CPLD_BMC_RST: + reg = CPLD_BMC_RST_REG; + break; + case CPLD_USB_RST: + reg = CPLD_USB_RST_REG; + break; + case CPLD_MUX_RST: + reg = CPLD_MUX_RST_REG; + break; + case CPLD_MISC_RST: + reg = CPLD_MISC_RST_REG; + break; + case CPLD_BMC_WATCHDOG: + reg = CPLD_BMC_WATCHDOG_REG; + break; + case CPLD_DAU_BD_PRES: + reg = CPLD_DAU_BD_PRES_REG; + break; + case CPLD_PSU_STATUS: + reg = CPLD_PSU_STATUS_REG; + break; + case CPLD_SYS_PW_STATUS: + reg = CPLD_SYS_PW_STATUS_REG; + break; + case CPLD_MISC: + reg = CPLD_MISC_REG; + break; + case CPLD_MUX_CTRL: + reg = CPLD_MUX_CTRL_REG; + break; + case CPLD_MAC_QSFP_SEL_CTRL: + reg = CPLD_MAC_QSFP_SEL_CTRL_REG; + break; + case CPLD_SYS_LED_CTRL_1: + reg = CPLD_SYS_LED_CTRL_1_REG; + break; + case CPLD_SYS_LED_CTRL_2: + reg = CPLD_SYS_LED_CTRL_2_REG; + break; + case CPLD_BEACON_LED_CTRL: + reg = CPLD_BEACON_LED_CTRL_REG; + break; + case CPLD_PORT_LED_CLR_CTRL: + reg = CPLD_PORT_LED_CLR_CTRL_REG; + break; + case CPLD_EVENT_DETECT_CTRL: + reg = CPLD_EVENT_DETECT_CTRL_REG; + break; + case CPLD_QSFPDD_MOD_INT_G0: + reg = CPLD_QSFPDD_MOD_INT_G0_REG; + break; + case CPLD_QSFPDD_MOD_INT_G1: + reg = CPLD_QSFPDD_MOD_INT_G1_REG; + break; + case CPLD_QSFPDD_MOD_INT_G2: + reg = CPLD_QSFPDD_MOD_INT_G2_REG; + break; + case CPLD_QSFPDD_MOD_INT_G3: + reg = CPLD_QSFPDD_MOD_INT_G3_REG; + break; + case CPLD_QSFPDD_PRES_G0: + reg = CPLD_QSFPDD_PRES_G0_REG; + break; + case CPLD_QSFPDD_PRES_G1: + reg = CPLD_QSFPDD_PRES_G1_REG; + break; + case CPLD_QSFPDD_PRES_G2: + reg = CPLD_QSFPDD_PRES_G2_REG; + break; + case CPLD_QSFPDD_PRES_G3: + reg = CPLD_QSFPDD_PRES_G3_REG; + break; + case CPLD_QSFPDD_FUSE_INT_G0: + reg = CPLD_QSFPDD_FUSE_INT_G0_REG; + break; + case CPLD_QSFPDD_FUSE_INT_G1: + reg = CPLD_QSFPDD_FUSE_INT_G1_REG; + break; + case CPLD_QSFPDD_FUSE_INT_G2: + reg = CPLD_QSFPDD_FUSE_INT_G2_REG; + break; + case CPLD_QSFPDD_FUSE_INT_G3: + reg = CPLD_QSFPDD_FUSE_INT_G3_REG; + break; + case CPLD_SFP_TXFAULT: + reg = CPLD_SFP_TXFAULT_REG; + break; + case CPLD_SFP_ABS: + reg = CPLD_SFP_ABS_REG; + break; + case CPLD_SFP_RXLOS: + reg = CPLD_SFP_RXLOS_REG; + break; + case CPLD_QSFPDD_MOD_INT_MASK_G0: + reg = CPLD_QSFPDD_MOD_INT_MASK_G0_REG; + break; + case CPLD_QSFPDD_MOD_INT_MASK_G1: + reg = CPLD_QSFPDD_MOD_INT_MASK_G1_REG; + break; + case CPLD_QSFPDD_MOD_INT_MASK_G2: + reg = CPLD_QSFPDD_MOD_INT_MASK_G2_REG; + break; + case CPLD_QSFPDD_MOD_INT_MASK_G3: + reg = CPLD_QSFPDD_MOD_INT_MASK_G3_REG; + break; + case CPLD_QSFPDD_PRES_MASK_G0: + reg = CPLD_QSFPDD_PRES_MASK_G0_REG; + break; + case CPLD_QSFPDD_PRES_MASK_G1: + reg = CPLD_QSFPDD_PRES_MASK_G1_REG; + break; + case CPLD_QSFPDD_PRES_MASK_G2: + reg = CPLD_QSFPDD_PRES_MASK_G2_REG; + break; + case CPLD_QSFPDD_PRES_MASK_G3: + reg = CPLD_QSFPDD_PRES_MASK_G3_REG; + break; + case CPLD_QSFPDD_FUSE_INT_MASK_G0: + reg = CPLD_QSFPDD_FUSE_INT_MASK_G0_REG; + break; + case CPLD_QSFPDD_FUSE_INT_MASK_G1: + reg = CPLD_QSFPDD_FUSE_INT_MASK_G1_REG; + break; + case CPLD_QSFPDD_FUSE_INT_MASK_G2: + reg = CPLD_QSFPDD_FUSE_INT_MASK_G2_REG; + break; + case CPLD_QSFPDD_FUSE_INT_MASK_G3: + reg = CPLD_QSFPDD_FUSE_INT_MASK_G3_REG; + break; + case CPLD_SFP_TXFAULT_MASK: + reg = CPLD_SFP_TXFAULT_MASK_REG; + break; + case CPLD_SFP_ABS_MASK: + reg = CPLD_SFP_ABS_MASK_REG; + break; + case CPLD_SFP_RXLOS_MASK: + reg = CPLD_SFP_RXLOS_MASK_REG; + break; + case CPLD_QSFPDD_MOD_INT_EVENT_G0: + reg = CPLD_QSFPDD_MOD_INT_EVENT_G0_REG; + break; + case CPLD_QSFPDD_MOD_INT_EVENT_G1: + reg = CPLD_QSFPDD_MOD_INT_EVENT_G1_REG; + break; + case CPLD_QSFPDD_MOD_INT_EVENT_G2: + reg = CPLD_QSFPDD_MOD_INT_EVENT_G2_REG; + break; + case CPLD_QSFPDD_MOD_INT_EVENT_G3: + reg = CPLD_QSFPDD_MOD_INT_EVENT_G3_REG; + break; + case CPLD_QSFPDD_PRES_EVENT_G0: + reg = CPLD_QSFPDD_PRES_EVENT_G0_REG; + break; + case CPLD_QSFPDD_PRES_EVENT_G1: + reg = CPLD_QSFPDD_PRES_EVENT_G1_REG; + break; + case CPLD_QSFPDD_PRES_EVENT_G2: + reg = CPLD_QSFPDD_PRES_EVENT_G2_REG; + break; + case CPLD_QSFPDD_PRES_EVENT_G3: + reg = CPLD_QSFPDD_PRES_EVENT_G3_REG; + break; + case CPLD_QSFPDD_FUSE_INT_EVENT_G0: + reg = CPLD_QSFPDD_FUSE_INT_EVENT_G0_REG; + break; + case CPLD_QSFPDD_FUSE_INT_EVENT_G1: + reg = CPLD_QSFPDD_FUSE_INT_EVENT_G1_REG; + break; + case CPLD_QSFPDD_FUSE_INT_EVENT_G2: + reg = CPLD_QSFPDD_FUSE_INT_EVENT_G2_REG; + break; + case CPLD_QSFPDD_FUSE_INT_EVENT_G3: + reg = CPLD_QSFPDD_FUSE_INT_EVENT_G3_REG; + break; + case CPLD_SFP_TXFAULT_EVENT: + reg = CPLD_SFP_TXFAULT_EVENT_REG; + break; + case CPLD_SFP_ABS_EVENT: + reg = CPLD_SFP_ABS_EVENT_REG; + break; + case CPLD_SFP_RXLOS_EVENT: + reg = CPLD_SFP_RXLOS_EVENT_REG; + break; + case CPLD_QSFPDD_RESET_CTRL_G0: + reg = CPLD_QSFPDD_RESET_CTRL_G0_REG; + break; + case CPLD_QSFPDD_RESET_CTRL_G1: + reg = CPLD_QSFPDD_RESET_CTRL_G1_REG; + break; + case CPLD_QSFPDD_RESET_CTRL_G2: + reg = CPLD_QSFPDD_RESET_CTRL_G2_REG; + break; + case CPLD_QSFPDD_RESET_CTRL_G3: + reg = CPLD_QSFPDD_RESET_CTRL_G3_REG; + break; + case CPLD_QSFPDD_LP_MODE_G0: + reg = CPLD_QSFPDD_LP_MODE_G0_REG; + break; + case CPLD_QSFPDD_LP_MODE_G1: + reg = CPLD_QSFPDD_LP_MODE_G1_REG; + break; + case CPLD_QSFPDD_LP_MODE_G2: + reg = CPLD_QSFPDD_LP_MODE_G2_REG; + break; + case CPLD_QSFPDD_LP_MODE_G3: + reg = CPLD_QSFPDD_LP_MODE_G3_REG; + break; + case CPLD_SFP_TX_DIS: + reg = CPLD_SFP_TX_DIS_REG; + break; + case CPLD_SFP_RS: + reg = CPLD_SFP_RS_REG; + break; + case CPLD_SFP_TS: + reg = CPLD_SFP_TS_REG; + break; + case CPLD_PORT_INT_STATUS: + reg = CPLD_PORT_INT_STATUS_REG; + break; + default: + return -EINVAL; + } + return read_cpld_reg(dev, buf, reg); +} + +/* handle read for hw_rev attributes */ +static ssize_t read_hw_rev_cb(struct device *dev, + struct device_attribute *da, char *buf) +{ + struct sensor_device_attribute *attr = to_sensor_dev_attr(da); + u8 reg = CPLD_HW_REV_REG; + u8 reg_val = 0; + int errno = 0; + u8 res; + + if (!read_cpld_reg_raw_byte(dev, reg, ®_val, &errno)) + return errno; + + switch (attr->index) { + case CPLD_HW_REV: + HW_REV_GET(reg_val, res); + break; + case CPLD_DEPH_REV: + DEPH_REV_GET(reg_val, res); + break; + case CPLD_BUILD_REV: + BUILD_REV_GET(reg_val, res); + break; + case CPLD_ID_TYPE: + ID_TYPE_GET(reg_val, res); + break; + default: + return -EINVAL; + } + return sprintf(buf, "0x%02x\n", res); +} + +/* handle read for cpld_version attributes */ +static ssize_t read_cpld_version_cb(struct device *dev, + struct device_attribute *da, char *buf) +{ + struct sensor_device_attribute *attr = to_sensor_dev_attr(da); + u8 reg = CPLD_VERSION_REG; + u8 reg_val = 0; + int errno = 0; + u8 res; + + if (!read_cpld_reg_raw_byte(dev, reg, ®_val, &errno)) + return errno; + + switch (attr->index) { + case CPLD_MAJOR_VER: + CPLD_MAJOR_VERSION_GET(reg_val, res); + break; + case CPLD_MINOR_VER: + CPLD_MINOR_VERSION_GET(reg_val, res); + break; + default: + return -EINVAL; + } + return sprintf(buf, "0x%02x\n", res); +} + +/* handle read human-readable string for cpld_version attributes */ +static ssize_t read_cpld_version_h_cb(struct device *dev, + struct device_attribute *da, char *buf) +{ + u8 reg = CPLD_VERSION_REG; + u8 reg_val = 0; + int errno = 0; + u8 major, minor, build; + + //get major/minor register value + if(!read_cpld_reg_raw_byte(dev, reg, ®_val, &errno)) + return errno; + CPLD_MAJOR_VERSION_GET(reg_val, major); + CPLD_MINOR_VERSION_GET(reg_val, minor); + + //get build register value + reg = CPLD_BUILD_VER_REG; + if(!read_cpld_reg_raw_byte(dev, reg, &build, &errno)) + return errno; + + //version string format : xx.xx.xxx + return sprintf(buf, "%d.%02d.%03d\n", major, minor, build); +} + +/* handle write for attributes */ +static ssize_t write_cpld_callback(struct device *dev, + struct device_attribute *da, const char *buf, size_t count) +{ + struct sensor_device_attribute *attr = to_sensor_dev_attr(da); + u8 reg = 0; + + switch (attr->index) { + case CPLD_MAC_INTR_MASK: + reg = CPLD_MAC_INTR_MASK_REG; + break; + case CPLD_10G_PHY_INTR_MASK: + reg = CPLD_10G_PHY_INTR_MASK_REG; + break; + case CPLD_CPLD_FRU_INTR_MASK: + reg = CPLD_CPLD_FRU_INTR_MASK_REG; + break; + case CPLD_THERMAL_ALERT_INTR_MASK: + reg = CPLD_THERMAL_ALERT_INTR_MASK_REG; + break; + case CPLD_MISC_INTR_MASK: + reg = CPLD_MISC_INTR_MASK_REG; + break; + case CPLD_MAC_RST: + reg = CPLD_MAC_RST_REG; + break; + case CPLD_10G_PHY_RST: + reg = CPLD_10G_PHY_RST_REG; + break; + case CPLD_BMC_RST: + reg = CPLD_BMC_RST_REG; + break; + case CPLD_USB_RST: + reg = CPLD_USB_RST_REG; + break; + case CPLD_MUX_RST: + reg = CPLD_MUX_RST_REG; + break; + case CPLD_MISC_RST: + reg = CPLD_MISC_RST_REG; + break; + case CPLD_BMC_WATCHDOG: + reg = CPLD_BMC_WATCHDOG_REG; + break; + case CPLD_MUX_CTRL: + reg = CPLD_MUX_CTRL_REG; + break; + case CPLD_MAC_QSFP_SEL_CTRL: + reg = CPLD_MAC_QSFP_SEL_CTRL_REG; + break; + case CPLD_BEACON_LED_CTRL: + reg = CPLD_BEACON_LED_CTRL_REG; + break; + case CPLD_PORT_LED_CLR_CTRL: + reg = CPLD_PORT_LED_CLR_CTRL_REG; + break; + case CPLD_EVENT_DETECT_CTRL: + reg = CPLD_EVENT_DETECT_CTRL_REG; + break; + case CPLD_QSFPDD_MOD_INT_MASK_G0: + reg = CPLD_QSFPDD_MOD_INT_MASK_G0_REG; + break; + case CPLD_QSFPDD_MOD_INT_MASK_G1: + reg = CPLD_QSFPDD_MOD_INT_MASK_G1_REG; + break; + case CPLD_QSFPDD_MOD_INT_MASK_G2: + reg = CPLD_QSFPDD_MOD_INT_MASK_G2_REG; + break; + case CPLD_QSFPDD_MOD_INT_MASK_G3: + reg = CPLD_QSFPDD_MOD_INT_MASK_G3_REG; + break; + case CPLD_QSFPDD_PRES_MASK_G0: + reg = CPLD_QSFPDD_PRES_MASK_G0_REG; + break; + case CPLD_QSFPDD_PRES_MASK_G1: + reg = CPLD_QSFPDD_PRES_MASK_G1_REG; + break; + case CPLD_QSFPDD_PRES_MASK_G2: + reg = CPLD_QSFPDD_PRES_MASK_G2_REG; + break; + case CPLD_QSFPDD_PRES_MASK_G3: + reg = CPLD_QSFPDD_PRES_MASK_G3_REG; + break; + case CPLD_QSFPDD_FUSE_INT_MASK_G0: + reg = CPLD_QSFPDD_FUSE_INT_MASK_G0_REG; + break; + case CPLD_QSFPDD_FUSE_INT_MASK_G1: + reg = CPLD_QSFPDD_FUSE_INT_MASK_G1_REG; + break; + case CPLD_QSFPDD_FUSE_INT_MASK_G2: + reg = CPLD_QSFPDD_FUSE_INT_MASK_G2_REG; + break; + case CPLD_QSFPDD_FUSE_INT_MASK_G3: + reg = CPLD_QSFPDD_FUSE_INT_MASK_G3_REG; + break; + case CPLD_SFP_TXFAULT_MASK: + reg = CPLD_SFP_TXFAULT_MASK_REG; + break; + case CPLD_SFP_ABS_MASK: + reg = CPLD_SFP_ABS_MASK_REG; + break; + case CPLD_SFP_RXLOS_MASK: + reg = CPLD_SFP_RXLOS_MASK_REG; + break; + case CPLD_QSFPDD_RESET_CTRL_G0: + reg = CPLD_QSFPDD_RESET_CTRL_G0_REG; + break; + case CPLD_QSFPDD_RESET_CTRL_G1: + reg = CPLD_QSFPDD_RESET_CTRL_G1_REG; + break; + case CPLD_QSFPDD_RESET_CTRL_G2: + reg = CPLD_QSFPDD_RESET_CTRL_G2_REG; + break; + case CPLD_QSFPDD_RESET_CTRL_G3: + reg = CPLD_QSFPDD_RESET_CTRL_G3_REG; + break; + case CPLD_QSFPDD_LP_MODE_G0: + reg = CPLD_QSFPDD_LP_MODE_G0_REG; + break; + case CPLD_QSFPDD_LP_MODE_G1: + reg = CPLD_QSFPDD_LP_MODE_G1_REG; + break; + case CPLD_QSFPDD_LP_MODE_G2: + reg = CPLD_QSFPDD_LP_MODE_G2_REG; + break; + case CPLD_QSFPDD_LP_MODE_G3: + reg = CPLD_QSFPDD_LP_MODE_G3_REG; + break; + case CPLD_SFP_TX_DIS: + reg = CPLD_SFP_TX_DIS_REG; + break; + case CPLD_SFP_RS: + reg = CPLD_SFP_RS_REG; + break; + case CPLD_SFP_TS: + reg = CPLD_SFP_TS_REG; + break; + default: + return -EINVAL; + } + return write_cpld_reg(dev, buf, count, reg); +} + +/* set cpld register value */ +static ssize_t write_cpld_reg(struct device *dev, + const char *buf, + size_t count, + u8 reg) +{ + struct i2c_client *client = to_i2c_client(dev); + struct cpld_data *data = i2c_get_clientdata(client); + u8 reg_val; + int ret; + + if (kstrtou8(buf, 0, ®_val) < 0) + return -EINVAL; + + I2C_WRITE_BYTE_DATA(ret, &data->access_lock, + client, reg, reg_val); + + if (unlikely(ret < 0)) { + dev_err(dev, "I2C_WRITE_BYTE_DATA error, return=%d\n", ret); + return ret; + } + + return count; +} + +/* add valid cpld client to list */ +static void s9300_cpld_add_client(struct i2c_client *client) +{ + struct cpld_client_node *node = NULL; + + node = kzalloc(sizeof(struct cpld_client_node), GFP_KERNEL); + if (!node) { + dev_info(&client->dev, + "Can't allocate cpld_client_node for index %d\n", + client->addr); + return; + } + + node->client = client; + + mutex_lock(&list_lock); + list_add(&node->list, &cpld_client_list); + mutex_unlock(&list_lock); +} + +/* remove exist cpld client in list */ +static void s9300_cpld_remove_client(struct i2c_client *client) +{ + struct list_head *list_node = NULL; + struct cpld_client_node *cpld_node = NULL; + int found = 0; + + mutex_lock(&list_lock); + list_for_each(list_node, &cpld_client_list) { + cpld_node = list_entry(list_node, + struct cpld_client_node, list); + + if (cpld_node->client == client) { + found = 1; + break; + } + } + + if (found) { + list_del(list_node); + kfree(cpld_node); + } + mutex_unlock(&list_lock); +} + +/* cpld drvier probe */ +static int s9300_cpld_probe(struct i2c_client *client, + const struct i2c_device_id *dev_id) +{ + int status; + struct cpld_data *data = NULL; + int ret = -EPERM; + int idx; + + data = kzalloc(sizeof(struct cpld_data), GFP_KERNEL); + if (!data) + return -ENOMEM; + + /* init cpld data for client */ + i2c_set_clientdata(client, data); + mutex_init(&data->access_lock); + + if (!i2c_check_functionality(client->adapter, + I2C_FUNC_SMBUS_BYTE_DATA)) { + dev_info(&client->dev, + "i2c_check_functionality failed (0x%x)\n", + client->addr); + status = -EIO; + goto exit; + } + + /* get cpld id from device */ + ret = i2c_smbus_read_byte_data(client, CPLD_ID_REG); + + if (ret < 0) { + dev_info(&client->dev, + "fail to get cpld id (0x%x) at addr (0x%x)\n", + CPLD_ID_REG, client->addr); + status = -EIO; + goto exit; + } + + CPLD_ID_ID_GET(ret, idx); + + if (INVALID(idx, cpld1, cpld3)) { + dev_info(&client->dev, + "cpld id %d(device) not valid\n", idx); + //status = -EPERM; + //goto exit; + } + + data->index = dev_id->driver_data; + + /* register sysfs hooks for different cpld group */ + dev_info(&client->dev, "probe cpld with index %d\n", data->index); + switch (data->index) { + case cpld1: + status = sysfs_create_group(&client->dev.kobj, + &s9300_cpld1_group); + break; + case cpld2: + status = sysfs_create_group(&client->dev.kobj, + &s9300_cpld2_group); + break; + case cpld3: + status = sysfs_create_group(&client->dev.kobj, + &s9300_cpld3_group); + break; + default: + status = -EINVAL; + } + + if (status) + goto exit; + + dev_info(&client->dev, "chip found\n"); + + /* add probe chip to client list */ + s9300_cpld_add_client(client); + + return 0; +exit: + switch (data->index) { + case cpld1: + sysfs_remove_group(&client->dev.kobj, &s9300_cpld1_group); + break; + case cpld2: + sysfs_remove_group(&client->dev.kobj, &s9300_cpld2_group); + break; + case cpld3: + sysfs_remove_group(&client->dev.kobj, &s9300_cpld3_group); + break; + default: + break; + } + return status; +} + +/* cpld drvier remove */ +static int s9300_cpld_remove(struct i2c_client *client) +{ + struct cpld_data *data = i2c_get_clientdata(client); + + switch (data->index) { + case cpld1: + sysfs_remove_group(&client->dev.kobj, &s9300_cpld1_group); + break; + case cpld2: + sysfs_remove_group(&client->dev.kobj, &s9300_cpld2_group); + break; + case cpld3: + sysfs_remove_group(&client->dev.kobj, &s9300_cpld3_group); + break; + } + + s9300_cpld_remove_client(client); + return 0; +} + +MODULE_DEVICE_TABLE(i2c, s9300_cpld_id); + +static struct i2c_driver s9300_cpld_driver = { + .class = I2C_CLASS_HWMON, + .driver = { + .name = "x86_64_ufispace_s9300_32d_cpld", + }, + .probe = s9300_cpld_probe, + .remove = s9300_cpld_remove, + .id_table = s9300_cpld_id, + .address_list = cpld_i2c_addr, +}; + +/* provide cpld register read */ +/* cpld_idx indicate the index of cpld device */ +int s9300_cpld_read(u8 cpld_idx, + u8 reg) +{ + struct list_head *list_node = NULL; + struct cpld_client_node *cpld_node = NULL; + int ret = -EPERM; + struct cpld_data *data; + + list_for_each(list_node, &cpld_client_list) { + cpld_node = list_entry(list_node, + struct cpld_client_node, list); + data = i2c_get_clientdata(cpld_node->client); + if (data->index == cpld_idx) { + DEBUG_PRINT("cpld_idx=%d, read reg 0x%02x", + cpld_idx, reg); + I2C_READ_BYTE_DATA(ret, &data->access_lock, + cpld_node->client, reg); + DEBUG_PRINT("cpld_idx=%d, read reg 0x%02x = 0x%02x", + cpld_idx, reg, ret); + break; + } + } + + return ret; +} +EXPORT_SYMBOL(s9300_cpld_read); + +/* provide cpld register write */ +/* cpld_idx indicate the index of cpld device */ +int s9300_cpld_write(u8 cpld_idx, + u8 reg, + u8 value) +{ + struct list_head *list_node = NULL; + struct cpld_client_node *cpld_node = NULL; + int ret = -EIO; + struct cpld_data *data; + + list_for_each(list_node, &cpld_client_list) { + cpld_node = list_entry(list_node, + struct cpld_client_node, list); + data = i2c_get_clientdata(cpld_node->client); + + if (data->index == cpld_idx) { + I2C_WRITE_BYTE_DATA(ret, &data->access_lock, + cpld_node->client, + reg, value); + DEBUG_PRINT("cpld_idx=%d, write reg 0x%02x val 0x%02x, ret=%d", + cpld_idx, reg, value, ret); + break; + } + } + + return ret; +} +EXPORT_SYMBOL(s9300_cpld_write); + +static int __init s9300_cpld_init(void) +{ + mutex_init(&list_lock); + return i2c_add_driver(&s9300_cpld_driver); +} + +static void __exit s9300_cpld_exit(void) +{ + i2c_del_driver(&s9300_cpld_driver); +} + +MODULE_AUTHOR("Leo Lin "); +MODULE_DESCRIPTION("x86_64_ufispace_s9300_cpld driver"); +MODULE_LICENSE("GPL"); + +module_init(s9300_cpld_init); +module_exit(s9300_cpld_exit); diff --git a/platform/broadcom/sonic-platform-modules-ufispace/s9300-32d/modules/x86-64-ufispace-s9300-32d-cpld.h b/platform/broadcom/sonic-platform-modules-ufispace/s9300-32d/modules/x86-64-ufispace-s9300-32d-cpld.h index d135e476e8cd..e2fd7e44a7fc 100644 --- a/platform/broadcom/sonic-platform-modules-ufispace/s9300-32d/modules/x86-64-ufispace-s9300-32d-cpld.h +++ b/platform/broadcom/sonic-platform-modules-ufispace/s9300-32d/modules/x86-64-ufispace-s9300-32d-cpld.h @@ -1,251 +1,251 @@ -/* header file for i2c cpld driver of ufispace_s9300_32d - * - * Copyright (C) 2017 UfiSpace Technology Corporation. - * Leo Lin - * - * 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. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. - */ - -#ifndef UFISPACE_S9300_I2C_CPLD_H -#define UFISPACE_S9300_I2C_CPLD_H - -/* CPLD device index value */ -enum cpld_id { - cpld1, - cpld2, - cpld3, -}; - -enum LED_BLINK { - NOBLINK, - BLINK, -}; - -enum LED_BLINK_SPEED { - BLINK_1X, // 0.5hz - BLINK_4X, // 2hz -}; - -enum LED_STATUS { - OFF, - ON, -}; - -enum LED_YELLOW { - YELLOW_OFF, - YELLOW_ON, -}; - -enum LED_GREEN { - GREEN_OFF, - GREEN_ON, -}; - -/* QSFPDD port number */ -#define QSFPDD_MAX_PORT_NUM 32 -#define QSFPDD_MIN_PORT_NUM 1 - -/* SFP+ port number */ -#define SFP_MAX_PORT_NUM 4 -#define SFP_MIN_PORT_NUM 1 - - -/* CPLD registers */ -/* CPLD 1 */ -#define CPLD_SKU_ID_REG 0x00 -#define CPLD_HW_REV_REG 0x01 -#define CPLD_VERSION_REG 0x02 -#define CPLD_ID_REG 0x03 -#define CPLD_BUILD_VER_REG 0x04 -// Interrupt status -#define CPLD_MAC_INTR_REG 0x10 -#define CPLD_10G_PHY_INTR_REG 0x13 -#define CPLD_CPLD_FRU_INTR_REG 0x14 -#define CPLD_THERMAL_ALERT_INTR_REG 0x16 -#define CPLD_MISC_INTR_REG 0x1B -#define CPLD_SYSTEM_INTR_REG 0x1D -// Interrupt mask -#define CPLD_MAC_INTR_MASK_REG 0x20 -#define CPLD_10G_PHY_INTR_MASK_REG 0x23 -#define CPLD_CPLD_FRU_INTR_MASK_REG 0x24 -#define CPLD_THERMAL_ALERT_INTR_MASK_REG 0x26 -#define CPLD_MISC_INTR_MASK_REG 0x2B -// Interrupt event -#define CPLD_MAC_INTR_EVENT_REG 0x30 -#define CPLD_10G_PHY_INTR_EVENT_REG 0x33 -#define CPLD_CPLD_FRU_INTR_EVENT_REG 0x14 -#define CPLD_THERMAL_ALERT_INTR_EVENT_REG 0x16 -#define CPLD_MISC_INTR_EVENT_REG 0x1B -// Reset ctrl -#define CPLD_MAC_RST_REG 0x40 -#define CPLD_10G_PHY_RST_REG 0x42 -#define CPLD_BMC_RST_REG 0x43 -#define CPLD_USB_RST_REG 0x44 -#define CPLD_MUX_RST_REG 0x46 -#define CPLD_MISC_RST_REG 0x48 -#define CPLD_BMC_WATCHDOG_REG 0x4D -// Sys status -#define CPLD_DAU_BD_PRES_REG 0x50 -#define CPLD_PSU_STATUS_REG 0x51 -#define CPLD_SYS_PW_STATUS_REG 0x52 -#define CPLD_MISC_REG 0x5B -// Mux ctrl -#define CPLD_MUX_CTRL_REG 0x5C -#define CPLD_MAC_QSFP_SEL_CTRL_REG 0x5F -// Led ctrl -#define CPLD_SYS_LED_CTRL_1_REG 0x80 -#define CPLD_SYS_LED_CTRL_2_REG 0x81 -#define CPLD_BEACON_LED_CTRL_REG 0x84 -#define CPLD_PORT_LED_CLR_CTRL_REG 0x85 -// Event Detect Ctrl -#define CPLD_EVENT_DETECT_CTRL_REG 0x5D - -/* CPLD 2 */ -/* G0 - port 0 ~ 7 - G1 - port 8 ~ 15 - G2 - port 16 ~ 23 - G3 - port 24 ~ 31 - */ -// Interrupt status -#define CPLD_QSFPDD_MOD_INT_G0_REG 0x10 -#define CPLD_QSFPDD_MOD_INT_G1_REG 0x11 -#define CPLD_QSFPDD_MOD_INT_G2_REG 0x12 -#define CPLD_QSFPDD_MOD_INT_G3_REG 0x13 -#define CPLD_QSFPDD_PRES_G0_REG 0x14 -#define CPLD_QSFPDD_PRES_G1_REG 0x15 -#define CPLD_QSFPDD_PRES_G2_REG 0x16 -#define CPLD_QSFPDD_PRES_G3_REG 0x17 -#define CPLD_QSFPDD_FUSE_INT_G0_REG 0x18 -#define CPLD_QSFPDD_FUSE_INT_G1_REG 0x19 -#define CPLD_QSFPDD_FUSE_INT_G2_REG 0x1A -#define CPLD_QSFPDD_FUSE_INT_G3_REG 0x1B -#define CPLD_SFP_TXFAULT_REG 0x1D -#define CPLD_SFP_ABS_REG 0x1E -#define CPLD_SFP_RXLOS_REG 0x1F -// Interrupt mask -#define CPLD_QSFPDD_MOD_INT_MASK_G0_REG 0x20 -#define CPLD_QSFPDD_MOD_INT_MASK_G1_REG 0x21 -#define CPLD_QSFPDD_MOD_INT_MASK_G2_REG 0x22 -#define CPLD_QSFPDD_MOD_INT_MASK_G3_REG 0x23 -#define CPLD_QSFPDD_PRES_MASK_G0_REG 0x24 -#define CPLD_QSFPDD_PRES_MASK_G1_REG 0x25 -#define CPLD_QSFPDD_PRES_MASK_G2_REG 0x26 -#define CPLD_QSFPDD_PRES_MASK_G3_REG 0x27 -#define CPLD_QSFPDD_FUSE_INT_MASK_G0_REG 0x28 -#define CPLD_QSFPDD_FUSE_INT_MASK_G1_REG 0x29 -#define CPLD_QSFPDD_FUSE_INT_MASK_G2_REG 0x2A -#define CPLD_QSFPDD_FUSE_INT_MASK_G3_REG 0x2B -#define CPLD_SFP_TXFAULT_MASK_REG 0x2D -#define CPLD_SFP_ABS_MASK_REG 0x2E -#define CPLD_SFP_RXLOS_MASK_REG 0x2F -// Interrupt event -#define CPLD_QSFPDD_MOD_INT_EVENT_G0_REG 0x30 -#define CPLD_QSFPDD_MOD_INT_EVENT_G1_REG 0x31 -#define CPLD_QSFPDD_MOD_INT_EVENT_G2_REG 0x32 -#define CPLD_QSFPDD_MOD_INT_EVENT_G3_REG 0x33 -#define CPLD_QSFPDD_PRES_EVENT_G0_REG 0x34 -#define CPLD_QSFPDD_PRES_EVENT_G1_REG 0x35 -#define CPLD_QSFPDD_PRES_EVENT_G2_REG 0x36 -#define CPLD_QSFPDD_PRES_EVENT_G3_REG 0x37 -#define CPLD_QSFPDD_FUSE_INT_EVENT_G0_REG 0x38 -#define CPLD_QSFPDD_FUSE_INT_EVENT_G1_REG 0x39 -#define CPLD_QSFPDD_FUSE_INT_EVENT_G2_REG 0x3A -#define CPLD_QSFPDD_FUSE_INT_EVENT_G3_REG 0x3B -#define CPLD_SFP_TXFAULT_EVENT_REG 0x3D -#define CPLD_SFP_ABS_EVENT_REG 0x3E -#define CPLD_SFP_RXLOS_EVENT_REG 0x3F -// Port ctrl -#define CPLD_QSFPDD_RESET_CTRL_G0_REG 0x40 -#define CPLD_QSFPDD_RESET_CTRL_G1_REG 0x41 -#define CPLD_QSFPDD_RESET_CTRL_G2_REG 0x42 -#define CPLD_QSFPDD_RESET_CTRL_G3_REG 0x43 -#define CPLD_QSFPDD_LP_MODE_G0_REG 0x44 -#define CPLD_QSFPDD_LP_MODE_G1_REG 0x45 -#define CPLD_QSFPDD_LP_MODE_G2_REG 0x46 -#define CPLD_QSFPDD_LP_MODE_G3_REG 0x47 -#define CPLD_SFP_TX_DIS_REG 0x55 -#define CPLD_SFP_RS_REG 0x56 -#define CPLD_SFP_TS_REG 0x57 -// Port status -#define CPLD_PORT_INT_STATUS_REG 0x58 - - -/* bit field structure for register value */ -struct cpld_reg_sku_id_t { - u8 model_id:8; -}; - -struct cpld_reg_hw_rev_t { - u8 hw_rev:2; - u8 deph_rev:1; - u8 build_rev:3; - u8 reserved:1; - u8 id_type:1; -}; - -struct cpld_reg_version_t { - u8 minor:6; - u8 major:2; -}; - -struct cpld_reg_id_t { - u8 id:3; - u8 release:5; -}; - -struct cpld_reg_beacon_led_ctrl_t { - u8 reserve:5; - u8 speed:1; - u8 blink:1; - u8 onoff:1; -}; - -/* common manipulation */ -#define INVALID(i, min, max) ((i < min) || (i > max) ? 1u : 0u) -#define READ_BIT(val, bit) ((0u == (val & (1<bf_name) -#define READ_BF_1(bf_struct, val, bf_name, bf_value) \ - bf_struct bf; \ - bf.data = val; \ - bf_value = bf.bf_name -#define HW_REV_GET(val, res) \ - READ_BF(cpld_reg_hw_rev_t, val, hw_rev, res) -#define DEPH_REV_GET(val, res) \ - READ_BF(cpld_reg_hw_rev_t, val, deph_rev, res) -#define BUILD_REV_GET(val, res) \ - READ_BF(cpld_reg_hw_rev_t, val, build_rev, res) -#define ID_TYPE_GET(val, res) \ - READ_BF(cpld_reg_hw_rev_t, val, id_type, res) -#define CPLD_MAJOR_VERSION_GET(val, res) \ - READ_BF(cpld_reg_version_t, val, major, res) -#define CPLD_MINOR_VERSION_GET(val, res) \ - READ_BF(cpld_reg_version_t, val, minor, res) -#define CPLD_ID_ID_GET(val, res) \ - READ_BF(cpld_reg_id_t, val, id, res) - -/* CPLD access functions */ -extern int s9300_cpld_read(u8 cpld_idx, u8 reg); -extern int s9300_cpld_write(u8 cpld_idx, u8 reg, u8 value); - -#endif - +/* header file for i2c cpld driver of ufispace_s9300_32d + * + * Copyright (C) 2017 UfiSpace Technology Corporation. + * Leo Lin + * + * 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. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + */ + +#ifndef UFISPACE_S9300_I2C_CPLD_H +#define UFISPACE_S9300_I2C_CPLD_H + +/* CPLD device index value */ +enum cpld_id { + cpld1, + cpld2, + cpld3, +}; + +enum LED_BLINK { + NOBLINK, + BLINK, +}; + +enum LED_BLINK_SPEED { + BLINK_1X, // 0.5hz + BLINK_4X, // 2hz +}; + +enum LED_STATUS { + OFF, + ON, +}; + +enum LED_YELLOW { + YELLOW_OFF, + YELLOW_ON, +}; + +enum LED_GREEN { + GREEN_OFF, + GREEN_ON, +}; + +/* QSFPDD port number */ +#define QSFPDD_MAX_PORT_NUM 32 +#define QSFPDD_MIN_PORT_NUM 1 + +/* SFP+ port number */ +#define SFP_MAX_PORT_NUM 4 +#define SFP_MIN_PORT_NUM 1 + + +/* CPLD registers */ +/* CPLD 1 */ +#define CPLD_SKU_ID_REG 0x00 +#define CPLD_HW_REV_REG 0x01 +#define CPLD_VERSION_REG 0x02 +#define CPLD_ID_REG 0x03 +#define CPLD_BUILD_VER_REG 0x04 +// Interrupt status +#define CPLD_MAC_INTR_REG 0x10 +#define CPLD_10G_PHY_INTR_REG 0x13 +#define CPLD_CPLD_FRU_INTR_REG 0x14 +#define CPLD_THERMAL_ALERT_INTR_REG 0x16 +#define CPLD_MISC_INTR_REG 0x1B +#define CPLD_SYSTEM_INTR_REG 0x1D +// Interrupt mask +#define CPLD_MAC_INTR_MASK_REG 0x20 +#define CPLD_10G_PHY_INTR_MASK_REG 0x23 +#define CPLD_CPLD_FRU_INTR_MASK_REG 0x24 +#define CPLD_THERMAL_ALERT_INTR_MASK_REG 0x26 +#define CPLD_MISC_INTR_MASK_REG 0x2B +// Interrupt event +#define CPLD_MAC_INTR_EVENT_REG 0x30 +#define CPLD_10G_PHY_INTR_EVENT_REG 0x33 +#define CPLD_CPLD_FRU_INTR_EVENT_REG 0x14 +#define CPLD_THERMAL_ALERT_INTR_EVENT_REG 0x16 +#define CPLD_MISC_INTR_EVENT_REG 0x1B +// Reset ctrl +#define CPLD_MAC_RST_REG 0x40 +#define CPLD_10G_PHY_RST_REG 0x42 +#define CPLD_BMC_RST_REG 0x43 +#define CPLD_USB_RST_REG 0x44 +#define CPLD_MUX_RST_REG 0x46 +#define CPLD_MISC_RST_REG 0x48 +#define CPLD_BMC_WATCHDOG_REG 0x4D +// Sys status +#define CPLD_DAU_BD_PRES_REG 0x50 +#define CPLD_PSU_STATUS_REG 0x51 +#define CPLD_SYS_PW_STATUS_REG 0x52 +#define CPLD_MISC_REG 0x5B +// Mux ctrl +#define CPLD_MUX_CTRL_REG 0x5C +#define CPLD_MAC_QSFP_SEL_CTRL_REG 0x5F +// Led ctrl +#define CPLD_SYS_LED_CTRL_1_REG 0x80 +#define CPLD_SYS_LED_CTRL_2_REG 0x81 +#define CPLD_BEACON_LED_CTRL_REG 0x84 +#define CPLD_PORT_LED_CLR_CTRL_REG 0x85 +// Event Detect Ctrl +#define CPLD_EVENT_DETECT_CTRL_REG 0x5D + +/* CPLD 2 */ +/* G0 - port 0 ~ 7 + G1 - port 8 ~ 15 + G2 - port 16 ~ 23 + G3 - port 24 ~ 31 + */ +// Interrupt status +#define CPLD_QSFPDD_MOD_INT_G0_REG 0x10 +#define CPLD_QSFPDD_MOD_INT_G1_REG 0x11 +#define CPLD_QSFPDD_MOD_INT_G2_REG 0x12 +#define CPLD_QSFPDD_MOD_INT_G3_REG 0x13 +#define CPLD_QSFPDD_PRES_G0_REG 0x14 +#define CPLD_QSFPDD_PRES_G1_REG 0x15 +#define CPLD_QSFPDD_PRES_G2_REG 0x16 +#define CPLD_QSFPDD_PRES_G3_REG 0x17 +#define CPLD_QSFPDD_FUSE_INT_G0_REG 0x18 +#define CPLD_QSFPDD_FUSE_INT_G1_REG 0x19 +#define CPLD_QSFPDD_FUSE_INT_G2_REG 0x1A +#define CPLD_QSFPDD_FUSE_INT_G3_REG 0x1B +#define CPLD_SFP_TXFAULT_REG 0x1D +#define CPLD_SFP_ABS_REG 0x1E +#define CPLD_SFP_RXLOS_REG 0x1F +// Interrupt mask +#define CPLD_QSFPDD_MOD_INT_MASK_G0_REG 0x20 +#define CPLD_QSFPDD_MOD_INT_MASK_G1_REG 0x21 +#define CPLD_QSFPDD_MOD_INT_MASK_G2_REG 0x22 +#define CPLD_QSFPDD_MOD_INT_MASK_G3_REG 0x23 +#define CPLD_QSFPDD_PRES_MASK_G0_REG 0x24 +#define CPLD_QSFPDD_PRES_MASK_G1_REG 0x25 +#define CPLD_QSFPDD_PRES_MASK_G2_REG 0x26 +#define CPLD_QSFPDD_PRES_MASK_G3_REG 0x27 +#define CPLD_QSFPDD_FUSE_INT_MASK_G0_REG 0x28 +#define CPLD_QSFPDD_FUSE_INT_MASK_G1_REG 0x29 +#define CPLD_QSFPDD_FUSE_INT_MASK_G2_REG 0x2A +#define CPLD_QSFPDD_FUSE_INT_MASK_G3_REG 0x2B +#define CPLD_SFP_TXFAULT_MASK_REG 0x2D +#define CPLD_SFP_ABS_MASK_REG 0x2E +#define CPLD_SFP_RXLOS_MASK_REG 0x2F +// Interrupt event +#define CPLD_QSFPDD_MOD_INT_EVENT_G0_REG 0x30 +#define CPLD_QSFPDD_MOD_INT_EVENT_G1_REG 0x31 +#define CPLD_QSFPDD_MOD_INT_EVENT_G2_REG 0x32 +#define CPLD_QSFPDD_MOD_INT_EVENT_G3_REG 0x33 +#define CPLD_QSFPDD_PRES_EVENT_G0_REG 0x34 +#define CPLD_QSFPDD_PRES_EVENT_G1_REG 0x35 +#define CPLD_QSFPDD_PRES_EVENT_G2_REG 0x36 +#define CPLD_QSFPDD_PRES_EVENT_G3_REG 0x37 +#define CPLD_QSFPDD_FUSE_INT_EVENT_G0_REG 0x38 +#define CPLD_QSFPDD_FUSE_INT_EVENT_G1_REG 0x39 +#define CPLD_QSFPDD_FUSE_INT_EVENT_G2_REG 0x3A +#define CPLD_QSFPDD_FUSE_INT_EVENT_G3_REG 0x3B +#define CPLD_SFP_TXFAULT_EVENT_REG 0x3D +#define CPLD_SFP_ABS_EVENT_REG 0x3E +#define CPLD_SFP_RXLOS_EVENT_REG 0x3F +// Port ctrl +#define CPLD_QSFPDD_RESET_CTRL_G0_REG 0x40 +#define CPLD_QSFPDD_RESET_CTRL_G1_REG 0x41 +#define CPLD_QSFPDD_RESET_CTRL_G2_REG 0x42 +#define CPLD_QSFPDD_RESET_CTRL_G3_REG 0x43 +#define CPLD_QSFPDD_LP_MODE_G0_REG 0x44 +#define CPLD_QSFPDD_LP_MODE_G1_REG 0x45 +#define CPLD_QSFPDD_LP_MODE_G2_REG 0x46 +#define CPLD_QSFPDD_LP_MODE_G3_REG 0x47 +#define CPLD_SFP_TX_DIS_REG 0x55 +#define CPLD_SFP_RS_REG 0x56 +#define CPLD_SFP_TS_REG 0x57 +// Port status +#define CPLD_PORT_INT_STATUS_REG 0x58 + + +/* bit field structure for register value */ +struct cpld_reg_sku_id_t { + u8 model_id:8; +}; + +struct cpld_reg_hw_rev_t { + u8 hw_rev:2; + u8 deph_rev:1; + u8 build_rev:3; + u8 reserved:1; + u8 id_type:1; +}; + +struct cpld_reg_version_t { + u8 minor:6; + u8 major:2; +}; + +struct cpld_reg_id_t { + u8 id:3; + u8 release:5; +}; + +struct cpld_reg_beacon_led_ctrl_t { + u8 reserve:5; + u8 speed:1; + u8 blink:1; + u8 onoff:1; +}; + +/* common manipulation */ +#define INVALID(i, min, max) ((i < min) || (i > max) ? 1u : 0u) +#define READ_BIT(val, bit) ((0u == (val & (1<bf_name) +#define READ_BF_1(bf_struct, val, bf_name, bf_value) \ + bf_struct bf; \ + bf.data = val; \ + bf_value = bf.bf_name +#define HW_REV_GET(val, res) \ + READ_BF(cpld_reg_hw_rev_t, val, hw_rev, res) +#define DEPH_REV_GET(val, res) \ + READ_BF(cpld_reg_hw_rev_t, val, deph_rev, res) +#define BUILD_REV_GET(val, res) \ + READ_BF(cpld_reg_hw_rev_t, val, build_rev, res) +#define ID_TYPE_GET(val, res) \ + READ_BF(cpld_reg_hw_rev_t, val, id_type, res) +#define CPLD_MAJOR_VERSION_GET(val, res) \ + READ_BF(cpld_reg_version_t, val, major, res) +#define CPLD_MINOR_VERSION_GET(val, res) \ + READ_BF(cpld_reg_version_t, val, minor, res) +#define CPLD_ID_ID_GET(val, res) \ + READ_BF(cpld_reg_id_t, val, id, res) + +/* CPLD access functions */ +extern int s9300_cpld_read(u8 cpld_idx, u8 reg); +extern int s9300_cpld_write(u8 cpld_idx, u8 reg, u8 value); + +#endif + diff --git a/platform/broadcom/sonic-platform-modules-ufispace/s9300-32d/modules/x86-64-ufispace-s9300-32d-lpc.c b/platform/broadcom/sonic-platform-modules-ufispace/s9300-32d/modules/x86-64-ufispace-s9300-32d-lpc.c index a00d8320221b..d227f631748b 100644 --- a/platform/broadcom/sonic-platform-modules-ufispace/s9300-32d/modules/x86-64-ufispace-s9300-32d-lpc.c +++ b/platform/broadcom/sonic-platform-modules-ufispace/s9300-32d/modules/x86-64-ufispace-s9300-32d-lpc.c @@ -1,816 +1,850 @@ -/* - * A lpc driver for the ufispace_s9300_32d - * - * Copyright (C) 2017-2020 UfiSpace Technology Corporation. - * Jason Tsai - * - * Based on ad7414.c - * Copyright 2006 Stefan Roese , DENX Software Engineering - * - * 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. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. - */ -#include -#include -#include -#include -#include - -#define BSP_LOG_R(fmt, args...) \ - _bsp_log (LOG_READ, KERN_INFO "%s:%s[%d]: " fmt "\r\n", \ - __FILE__, __func__, __LINE__, ##args) -#define BSP_LOG_W(fmt, args...) \ - _bsp_log (LOG_WRITE, KERN_INFO "%s:%s[%d]: " fmt "\r\n", \ - __FILE__, __func__, __LINE__, ##args) - -#define DRIVER_NAME "x86_64_ufispace_s9300_32d_lpc" -#define CPU_BDE 0 -#define CPU_SKY 1 -#define CPU_TYPE CPU_SKY - -/* LPC registers */ - -#define REG_BASE_CPU 0x600 - -#if CPU_TYPE == CPU_SKY -#define REG_BASE_MB 0xE00 -#define REG_BASE_I2C_ALERT 0x700 -#else -#define REG_BASE_MB 0x700 -#define REG_BASE_I2C_ALERT 0xF000 -#endif - -//CPU CPLD -#define REG_CPU_CPLD_VERSION (REG_BASE_CPU + 0x00) -#define REG_CPU_STATUS_0 (REG_BASE_CPU + 0x01) -#define REG_CPU_STATUS_1 (REG_BASE_CPU + 0x02) -#define REG_CPU_CTRL_0 (REG_BASE_CPU + 0x03) -#define REG_CPU_CTRL_1 (REG_BASE_CPU + 0x04) -#define REG_CPU_CPLD_BUILD (REG_BASE_CPU + 0xE0) - -//MB CPLD -//TBD, need to change after CPLD spec release -#define REG_MB_BRD_ID_0 (REG_BASE_MB + 0x00) -#define REG_MB_BRD_ID_1 (REG_BASE_MB + 0x01) -#define REG_MB_CPLD_VERSION (REG_BASE_MB + 0x02) -#define REG_MB_CPLD_BUILD (REG_BASE_MB + 0x04) -#define REG_MB_MUX_RESET (REG_BASE_MB + 0x46) -#define REG_MB_MUX_CTRL (REG_BASE_MB + 0x5c) - -//I2C Alert -#if CPU_TYPE == CPU_SKY -#define REG_ALERT_STATUS (REG_BASE_I2C_ALERT + 0x80) -#else -#define REG_ALERT_STATUS (REG_BASE_I2C_ALERT + 0x00) -#define REG_ALERT_DISABLE (REG_BASE_I2C_ALERT + 0x11) -#endif - -#define MASK_ALL (0xFF) -#define LPC_MDELAY (5) - -/* LPC sysfs attributes index */ -enum lpc_sysfs_attributes { - //CPU CPLD - ATT_CPU_CPLD_VERSION, - ATT_CPU_CPLD_VERSION_H, - ATT_CPU_BIOS_BOOT_ROM, - ATT_CPU_BIOS_BOOT_CFG, - ATT_CPU_CPLD_BUILD, - //MB CPLD - ATT_MB_BRD_ID_0, - ATT_MB_BRD_ID_1, - ATT_MB_CPLD_1_VERSION, - ATT_MB_CPLD_1_VERSION_H, - ATT_MB_CPLD_1_BUILD, - ATT_MB_MUX_CTRL, - ATT_MB_MUX_RESET, - ATT_MB_BRD_SKU_ID, - ATT_MB_BRD_HW_ID, - ATT_MB_BRD_ID_TYPE, - ATT_MB_BRD_BUILD_ID, - ATT_MB_BRD_DEPH_ID, - //I2C Alert - ATT_ALERT_STATUS, -#if CPU_TYPE == CPU_BDE - ATT_ALERT_DISABLE, -#endif - //BSP - ATT_BSP_VERSION, - ATT_BSP_DEBUG, - ATT_BSP_REG, - ATT_MAX -}; - -enum bsp_log_types { - LOG_NONE, - LOG_RW, - LOG_READ, - LOG_WRITE -}; - -enum bsp_log_ctrl { - LOG_DISABLE, - LOG_ENABLE -}; - -struct lpc_data_s { - struct mutex access_lock; -}; - -struct lpc_data_s *lpc_data; -char bsp_version[16]=""; -char bsp_debug[2]="0"; -char bsp_reg[8]="0x0"; -u8 enable_log_read=LOG_DISABLE; -u8 enable_log_write=LOG_DISABLE; - -/* reg shift */ -static u8 _shift(u8 mask) -{ - int i=0, mask_one=1; - - for(i=0; i<8; ++i) { - if ((mask & mask_one) == 1) - return i; - else - mask >>= 1; - } - - return -1; -} - -/* reg mask and shift */ -static u8 _mask_shift(u8 val, u8 mask) -{ - int shift=0; - - shift = _shift(mask); - - return (val & mask) >> shift; -} - -static u8 _bit_operation(u8 reg_val, u8 bit, u8 bit_val) -{ - if (bit_val == 0) - reg_val = reg_val & ~(1 << bit); - else - reg_val = reg_val | (1 << bit); - return reg_val; -} - -static int _bsp_log(u8 log_type, char *fmt, ...) -{ - if ((log_type==LOG_READ && enable_log_read) || - (log_type==LOG_WRITE && enable_log_write)) { - va_list args; - int r; - - va_start(args, fmt); - r = vprintk(fmt, args); - va_end(args); - - return r; - } else { - return 0; - } -} - -static int _config_bsp_log(u8 log_type) -{ - switch(log_type) { - case LOG_NONE: - enable_log_read = LOG_DISABLE; - enable_log_write = LOG_DISABLE; - break; - case LOG_RW: - enable_log_read = LOG_ENABLE; - enable_log_write = LOG_ENABLE; - break; - case LOG_READ: - enable_log_read = LOG_ENABLE; - enable_log_write = LOG_DISABLE; - break; - case LOG_WRITE: - enable_log_read = LOG_DISABLE; - enable_log_write = LOG_ENABLE; - break; - default: - return -EINVAL; - } - return 0; -} - -/* get lpc register value */ -static u8 _read_lpc_reg(u16 reg, u8 mask) -{ - u8 reg_val; - - mutex_lock(&lpc_data->access_lock); - reg_val=_mask_shift(inb(reg), mask); - mutex_unlock(&lpc_data->access_lock); - - BSP_LOG_R("reg=0x%03x, reg_val=0x%02x", reg, reg_val); - - return reg_val; -} - -/* get lpc register value */ -static ssize_t read_lpc_reg(u16 reg, u8 mask, char *buf) -{ - u8 reg_val; - int len=0; - - reg_val = _read_lpc_reg(reg, mask); - len=sprintf(buf,"0x%x\n", reg_val); - - return len; -} - -/* set lpc register value */ -static ssize_t write_lpc_reg(u16 reg, u8 mask, const char *buf, size_t count) -{ - u8 reg_val, reg_val_now, shift; - - if (kstrtou8(buf, 0, ®_val) < 0) - return -EINVAL; - - //apply SINGLE BIT operation if mask is specified, multiple bits are not supported - if (mask != MASK_ALL) { - reg_val_now = _read_lpc_reg(reg, 0x0); - shift = _shift(mask); - reg_val = _bit_operation(reg_val_now, shift, reg_val); - } - - mutex_lock(&lpc_data->access_lock); - - outb(reg_val, reg); - mdelay(LPC_MDELAY); - - mutex_unlock(&lpc_data->access_lock); - - BSP_LOG_W("reg=0x%03x, reg_val=0x%02x", reg, reg_val); - - return count; -} - -/* get bsp value */ -static ssize_t read_bsp(char *buf, char *str) -{ - ssize_t len=0; - - mutex_lock(&lpc_data->access_lock); - len=sprintf(buf, "%s", str); - mutex_unlock(&lpc_data->access_lock); - - BSP_LOG_R("reg_val=%s", str); - - return len; -} - -/* set bsp value */ -static ssize_t write_bsp(const char *buf, char *str, size_t str_len, size_t count) -{ - mutex_lock(&lpc_data->access_lock); - snprintf(str, str_len, "%s", buf); - mutex_unlock(&lpc_data->access_lock); - - BSP_LOG_W("reg_val=%s", str); - - return count; -} - -/* get cpu cpld version in human readable format */ -static ssize_t read_cpu_cpld_version_h(struct device *dev, - struct device_attribute *da, char *buf) -{ - ssize_t len=0; - u16 reg = REG_CPU_CPLD_VERSION; - u8 mask = MASK_ALL; - u8 mask_major = 0b11000000; - u8 mask_minor = 0b00111111; - u8 reg_val; - u8 major, minor, build; - - mutex_lock(&lpc_data->access_lock); - reg_val = _mask_shift(inb(reg), mask); - major = _mask_shift(reg_val, mask_major); - minor = _mask_shift(reg_val, mask_minor); - reg = REG_CPU_CPLD_BUILD; - build = _mask_shift(inb(reg), mask); - len = sprintf(buf, "%d.%02d.%03d\n", major, minor, build); - mutex_unlock(&lpc_data->access_lock); - - BSP_LOG_R("reg=0x%03x, reg_val=0x%02x", reg, reg_val); - - return len; -} - -/* get mb cpld version in human readable format */ -static ssize_t read_mb_cpld_1_version_h(struct device *dev, - struct device_attribute *da, char *buf) -{ - ssize_t len=0; - u16 reg = REG_MB_CPLD_VERSION; - u8 mask = MASK_ALL; - u8 mask_major = 0b11000000; - u8 mask_minor = 0b00111111; - u8 reg_val; - u8 major, minor, build; - - mutex_lock(&lpc_data->access_lock); - reg_val = _mask_shift(inb(reg), mask); - major = _mask_shift(reg_val, mask_major); - minor = _mask_shift(reg_val, mask_minor); - reg = REG_MB_CPLD_BUILD; - build = _mask_shift(inb(reg), mask); - len = sprintf(buf, "%d.%02d.%03d\n", major, minor, build); - mutex_unlock(&lpc_data->access_lock); - - BSP_LOG_R("reg=0x%03x, reg_val=0x%02x", reg, reg_val); - - return len; -} - -/* get mux_reset register value */ -static ssize_t read_mux_reset_callback(struct device *dev, - struct device_attribute *da, char *buf) -{ - int len = 0; - u16 reg = REG_MB_MUX_RESET; - u8 mask = 0b00011111; - u8 reg_val; - - mutex_lock(&lpc_data->access_lock); - reg_val=_mask_shift(inb(reg), mask); - BSP_LOG_R("reg=0x%03x, reg_val=0x%02x", reg, reg_val); - len=sprintf(buf, "%d\n", reg_val); - mutex_unlock(&lpc_data->access_lock); - - return len; -} - -/* set mux_reset register value */ -static ssize_t write_mux_reset_callback(struct device *dev, - struct device_attribute *da, const char *buf, size_t count) -{ - u8 val = 0; - u16 reg = REG_MB_MUX_RESET; - u8 reg_val = 0; - u8 mask = 0b00011111; - static int mux_reset_flag = 0; - - if (kstrtou8(buf, 0, &val) < 0) - return -EINVAL; - - if (mux_reset_flag == 0) { - if (val == 0) { - mutex_lock(&lpc_data->access_lock); - mux_reset_flag = 1; - BSP_LOG_W("i2c mux reset is triggered..."); - - reg_val = inb(reg); - outb((reg_val & ~mask), reg); - mdelay(LPC_MDELAY); - BSP_LOG_W("reg=0x%03x, reg_val=0x%02x", reg, reg_val & ~mask); - mdelay(500); - outb((reg_val | mask), reg); - mdelay(LPC_MDELAY); - BSP_LOG_W("reg=0x%03x, reg_val=0x%02x", reg, reg_val | mask); - mdelay(500); - mux_reset_flag = 0; - mutex_unlock(&lpc_data->access_lock); - } else { - return -EINVAL; - } - } else { - BSP_LOG_W("i2c mux is resetting... (ignore)"); - mutex_lock(&lpc_data->access_lock); - mutex_unlock(&lpc_data->access_lock); - } - - return count; -} - -/* get lpc register value */ -static ssize_t read_lpc_callback(struct device *dev, - struct device_attribute *da, char *buf) -{ - struct sensor_device_attribute *attr = to_sensor_dev_attr(da); - u16 reg = 0; - u8 mask = MASK_ALL; - - switch (attr->index) { - //CPU CPLD - case ATT_CPU_CPLD_VERSION: - reg = REG_CPU_CPLD_VERSION; - break; - case ATT_CPU_BIOS_BOOT_ROM: - reg = REG_CPU_STATUS_1; - mask = 0x80; - break; - case ATT_CPU_BIOS_BOOT_CFG: - reg = REG_CPU_CTRL_1; - mask = 0x80; - break; - case ATT_CPU_CPLD_BUILD: - reg = REG_CPU_CPLD_BUILD; - break; - //MB CPLD - case ATT_MB_BRD_ID_0: - reg = REG_MB_BRD_ID_0; - break; - case ATT_MB_BRD_ID_1: - reg = REG_MB_BRD_ID_1; - break; - case ATT_MB_CPLD_1_VERSION: - reg = REG_MB_CPLD_VERSION; - break; - case ATT_MB_CPLD_1_BUILD: - reg = REG_MB_CPLD_BUILD; - break; - case ATT_MB_BRD_SKU_ID: - reg = REG_MB_BRD_ID_0; - mask = 0xFF; - break; - case ATT_MB_BRD_HW_ID: - reg = REG_MB_BRD_ID_1; - mask = 0x03; - break; - case ATT_MB_BRD_ID_TYPE: - reg = REG_MB_BRD_ID_1; - mask = 0x80; - break; - case ATT_MB_BRD_BUILD_ID: - reg = REG_MB_BRD_ID_1; - mask = 0x38; - break; - case ATT_MB_BRD_DEPH_ID: - reg = REG_MB_BRD_ID_1; - mask = 0x04; - break; - case ATT_MB_MUX_CTRL: - reg = REG_MB_MUX_CTRL; - break; - //I2C Alert - case ATT_ALERT_STATUS: - reg = REG_ALERT_STATUS; - mask = 0x20; - break; -#if CPU_TYPE == CPU_BDE - case ATT_ALERT_DISABLE: - reg = REG_ALERT_DISABLE; - mask = 0x04; - break; -#endif - //BSP - case ATT_BSP_REG: - if (kstrtou16(bsp_reg, 0, ®) < 0) - return -EINVAL; - break; - default: - return -EINVAL; - } - return read_lpc_reg(reg, mask, buf); -} - -/* set lpc register value */ -static ssize_t write_lpc_callback(struct device *dev, - struct device_attribute *da, const char *buf, size_t count) -{ - struct sensor_device_attribute *attr = to_sensor_dev_attr(da); - u16 reg = 0; - u8 mask = MASK_ALL; - - switch (attr->index) { - case ATT_MB_MUX_CTRL: - reg = REG_MB_MUX_CTRL; - break; - default: - return -EINVAL; - } - return write_lpc_reg(reg, mask, buf, count); -} - -/* get bsp parameter value */ -static ssize_t read_bsp_callback(struct device *dev, - struct device_attribute *da, char *buf) -{ - struct sensor_device_attribute *attr = to_sensor_dev_attr(da); - int str_len=0; - char *str=NULL; - - switch (attr->index) { - case ATT_BSP_VERSION: - str = bsp_version; - str_len = sizeof(bsp_version); - break; - case ATT_BSP_DEBUG: - str = bsp_debug; - str_len = sizeof(bsp_debug); - break; - case ATT_BSP_REG: - str = bsp_reg; - str_len = sizeof(bsp_reg); - break; - default: - return -EINVAL; - } - return read_bsp(buf, str); -} - -/* set bsp parameter value */ -static ssize_t write_bsp_callback(struct device *dev, - struct device_attribute *da, const char *buf, size_t count) -{ - struct sensor_device_attribute *attr = to_sensor_dev_attr(da); - int str_len=0; - char *str=NULL; - u16 reg = 0; - u8 bsp_debug_u8 = 0; - - switch (attr->index) { - case ATT_BSP_VERSION: - str = bsp_version; - str_len = sizeof(str); - break; - case ATT_BSP_DEBUG: - str = bsp_debug; - str_len = sizeof(str); - break; - case ATT_BSP_REG: - if (kstrtou16(buf, 0, ®) < 0) - return -EINVAL; - - str = bsp_reg; - str_len = sizeof(str); - break; - default: - return -EINVAL; - } - - if (attr->index == ATT_BSP_DEBUG) { - if (kstrtou8(buf, 0, &bsp_debug_u8) < 0) { - return -EINVAL; - } else if (_config_bsp_log(bsp_debug_u8) < 0) { - return -EINVAL; - } - } - - return write_bsp(buf, str, str_len, count); -} - -//SENSOR_DEVICE_ATTR - CPU -static SENSOR_DEVICE_ATTR(cpu_cpld_version, S_IRUGO, read_lpc_callback, NULL, ATT_CPU_CPLD_VERSION); -static SENSOR_DEVICE_ATTR(cpu_cpld_version_h, S_IRUGO, read_cpu_cpld_version_h, NULL, ATT_CPU_CPLD_VERSION_H); -static SENSOR_DEVICE_ATTR(boot_rom, S_IRUGO, read_lpc_callback, NULL, ATT_CPU_BIOS_BOOT_ROM); -static SENSOR_DEVICE_ATTR(boot_cfg, S_IRUGO, read_lpc_callback, NULL, ATT_CPU_BIOS_BOOT_CFG); -static SENSOR_DEVICE_ATTR(cpu_cpld_build, S_IRUGO, read_lpc_callback, NULL, ATT_CPU_CPLD_BUILD); -//SENSOR_DEVICE_ATTR - MB -static SENSOR_DEVICE_ATTR(board_id_0, S_IRUGO, read_lpc_callback, NULL, ATT_MB_BRD_ID_0); -static SENSOR_DEVICE_ATTR(board_id_1, S_IRUGO, read_lpc_callback, NULL, ATT_MB_BRD_ID_1); -static SENSOR_DEVICE_ATTR(mb_cpld_1_version, S_IRUGO, read_lpc_callback, NULL, ATT_MB_CPLD_1_VERSION); -static SENSOR_DEVICE_ATTR(mb_cpld_1_version_h, S_IRUGO, read_mb_cpld_1_version_h, NULL, ATT_MB_CPLD_1_VERSION_H); -static SENSOR_DEVICE_ATTR(mb_cpld_1_build, S_IRUGO, read_lpc_callback, NULL, ATT_MB_CPLD_1_BUILD); -static SENSOR_DEVICE_ATTR(mux_ctrl, S_IRUGO | S_IWUSR, read_lpc_callback, write_lpc_callback, ATT_MB_MUX_CTRL); -static SENSOR_DEVICE_ATTR(mux_reset, S_IRUGO | S_IWUSR, read_mux_reset_callback, write_mux_reset_callback, ATT_MB_MUX_RESET); -static SENSOR_DEVICE_ATTR(board_sku_id, S_IRUGO, read_lpc_callback, NULL, ATT_MB_BRD_SKU_ID); -static SENSOR_DEVICE_ATTR(board_hw_id, S_IRUGO, read_lpc_callback, NULL, ATT_MB_BRD_HW_ID); -static SENSOR_DEVICE_ATTR(board_id_type, S_IRUGO, read_lpc_callback, NULL, ATT_MB_BRD_ID_TYPE); -static SENSOR_DEVICE_ATTR(board_build_id, S_IRUGO, read_lpc_callback, NULL, ATT_MB_BRD_BUILD_ID); -static SENSOR_DEVICE_ATTR(board_deph_id, S_IRUGO, read_lpc_callback, NULL, ATT_MB_BRD_DEPH_ID); -//SENSOR_DEVICE_ATTR - I2C Alert -static SENSOR_DEVICE_ATTR(alert_status, S_IRUGO, read_lpc_callback, NULL, ATT_ALERT_STATUS); -#if CPU_TYPE == CPU_BDE -static SENSOR_DEVICE_ATTR(alert_disable, S_IRUGO, read_lpc_callback, NULL, ATT_ALERT_DISABLE); -#endif -//SENSOR_DEVICE_ATTR - BSP -static SENSOR_DEVICE_ATTR(bsp_version, S_IRUGO | S_IWUSR, read_bsp_callback, write_bsp_callback, ATT_BSP_VERSION); -static SENSOR_DEVICE_ATTR(bsp_debug, S_IRUGO | S_IWUSR, read_bsp_callback, write_bsp_callback, ATT_BSP_DEBUG); -static SENSOR_DEVICE_ATTR(bsp_reg, S_IRUGO | S_IWUSR, read_lpc_callback, write_bsp_callback, ATT_BSP_REG); - -static struct attribute *cpu_cpld_attrs[] = { - &sensor_dev_attr_cpu_cpld_version.dev_attr.attr, - &sensor_dev_attr_cpu_cpld_version_h.dev_attr.attr, - &sensor_dev_attr_cpu_cpld_build.dev_attr.attr, - NULL, -}; - -static struct attribute *mb_cpld_attrs[] = { - &sensor_dev_attr_board_id_0.dev_attr.attr, - &sensor_dev_attr_board_id_1.dev_attr.attr, - &sensor_dev_attr_mb_cpld_1_version.dev_attr.attr, - &sensor_dev_attr_mb_cpld_1_version_h.dev_attr.attr, - &sensor_dev_attr_mb_cpld_1_build.dev_attr.attr, - &sensor_dev_attr_board_sku_id.dev_attr.attr, - &sensor_dev_attr_board_hw_id.dev_attr.attr, - &sensor_dev_attr_board_id_type.dev_attr.attr, - &sensor_dev_attr_board_build_id.dev_attr.attr, - &sensor_dev_attr_board_deph_id.dev_attr.attr, - &sensor_dev_attr_mux_ctrl.dev_attr.attr, - &sensor_dev_attr_mux_reset.dev_attr.attr, - NULL, -}; - -static struct attribute *bios_attrs[] = { - &sensor_dev_attr_boot_rom.dev_attr.attr, - &sensor_dev_attr_boot_cfg.dev_attr.attr, - NULL, -}; - -static struct attribute *i2c_alert_attrs[] = { - &sensor_dev_attr_alert_status.dev_attr.attr, -#if CPU_TYPE == CPU_BDE - &sensor_dev_attr_alert_disable.dev_attr.attr, -#endif - NULL, -}; - -static struct attribute *bsp_attrs[] = { - &sensor_dev_attr_bsp_version.dev_attr.attr, - &sensor_dev_attr_bsp_debug.dev_attr.attr, - &sensor_dev_attr_bsp_reg.dev_attr.attr, - NULL, -}; - -static struct attribute_group cpu_cpld_attr_grp = { - .name = "cpu_cpld", - .attrs = cpu_cpld_attrs, -}; - -static struct attribute_group mb_cpld_attr_grp = { - .name = "mb_cpld", - .attrs = mb_cpld_attrs, -}; - -static struct attribute_group bios_attr_grp = { - .name = "bios", - .attrs = bios_attrs, -}; - -static struct attribute_group i2c_alert_attr_grp = { - .name = "i2c_alert", - .attrs = i2c_alert_attrs, -}; - -static struct attribute_group bsp_attr_grp = { - .name = "bsp", - .attrs = bsp_attrs, -}; - -static void lpc_dev_release( struct device * dev) -{ - return; -} - -static struct platform_device lpc_dev = { - .name = DRIVER_NAME, - .id = -1, - .dev = { - .release = lpc_dev_release, - } -}; - -static int lpc_drv_probe(struct platform_device *pdev) -{ - int i = 0, grp_num = 5; - int err[5] = {0}; - struct attribute_group *grp; - - lpc_data = devm_kzalloc(&pdev->dev, sizeof(struct lpc_data_s), - GFP_KERNEL); - if (!lpc_data) - return -ENOMEM; - - mutex_init(&lpc_data->access_lock); - - for (i=0; idev.kobj, grp); - if (err[i]) { - printk(KERN_ERR "Cannot create sysfs for group %s\n", grp->name); - goto exit; - } else { - continue; - } - } - - return 0; - -exit: - for (i=0; idev.kobj, grp); - if (!err[i]) { - //remove previous successful cases - continue; - } else { - //remove first failed case, then return - return err[i]; - } - } - return 0; -} - -static int lpc_drv_remove(struct platform_device *pdev) -{ - sysfs_remove_group(&pdev->dev.kobj, &cpu_cpld_attr_grp); - sysfs_remove_group(&pdev->dev.kobj, &mb_cpld_attr_grp); - sysfs_remove_group(&pdev->dev.kobj, &bios_attr_grp); - sysfs_remove_group(&pdev->dev.kobj, &i2c_alert_attr_grp); - sysfs_remove_group(&pdev->dev.kobj, &bsp_attr_grp); - - return 0; -} - -static struct platform_driver lpc_drv = { - .probe = lpc_drv_probe, - .remove = __exit_p(lpc_drv_remove), - .driver = { - .name = DRIVER_NAME, - }, -}; - -int lpc_init(void) -{ - int err = 0; - - err = platform_driver_register(&lpc_drv); - if (err) { - printk(KERN_ERR "%s(#%d): platform_driver_register failed(%d)\n", - __func__, __LINE__, err); - - return err; - } - - err = platform_device_register(&lpc_dev); - if (err) { - printk(KERN_ERR "%s(#%d): platform_device_register failed(%d)\n", - __func__, __LINE__, err); - platform_driver_unregister(&lpc_drv); - return err; - } - - return err; -} - -void lpc_exit(void) -{ - platform_driver_unregister(&lpc_drv); - platform_device_unregister(&lpc_dev); -} - -MODULE_AUTHOR("Leo Lin "); -MODULE_DESCRIPTION("x86_64_ufispace_s9300_32d_lpc driver"); -MODULE_LICENSE("GPL"); - -module_init(lpc_init); -module_exit(lpc_exit); +/* + * A lpc driver for the ufispace_s9300_32d + * + * Copyright (C) 2017-2020 UfiSpace Technology Corporation. + * Jason Tsai + * + * Based on ad7414.c + * Copyright 2006 Stefan Roese , DENX Software Engineering + * + * 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. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + */ +#include +#include +#include +#include +#include + +#define BSP_LOG_R(fmt, args...) \ + _bsp_log (LOG_READ, KERN_INFO "%s:%s[%d]: " fmt "\r\n", \ + __FILE__, __func__, __LINE__, ##args) +#define BSP_LOG_W(fmt, args...) \ + _bsp_log (LOG_WRITE, KERN_INFO "%s:%s[%d]: " fmt "\r\n", \ + __FILE__, __func__, __LINE__, ##args) + +#define BSP_PR(level, fmt, args...) _bsp_log (LOG_SYS, level "[BSP]" fmt "\r\n", ##args) + +#define DRIVER_NAME "x86_64_ufispace_s9300_32d_lpc" +#define CPU_BDE 0 +#define CPU_SKY 1 +#define CPU_TYPE CPU_SKY + +/* LPC registers */ + +#define REG_BASE_CPU 0x600 + +#if CPU_TYPE == CPU_SKY +#define REG_BASE_MB 0xE00 +#define REG_BASE_I2C_ALERT 0x700 +#else +#define REG_BASE_MB 0x700 +#define REG_BASE_I2C_ALERT 0xF000 +#endif + +//CPU CPLD +#define REG_CPU_CPLD_VERSION (REG_BASE_CPU + 0x00) +#define REG_CPU_STATUS_0 (REG_BASE_CPU + 0x01) +#define REG_CPU_STATUS_1 (REG_BASE_CPU + 0x02) +#define REG_CPU_CTRL_0 (REG_BASE_CPU + 0x03) +#define REG_CPU_CTRL_1 (REG_BASE_CPU + 0x04) +#define REG_CPU_CPLD_BUILD (REG_BASE_CPU + 0xE0) + +//MB CPLD +//TBD, need to change after CPLD spec release +#define REG_MB_BRD_ID_0 (REG_BASE_MB + 0x00) +#define REG_MB_BRD_ID_1 (REG_BASE_MB + 0x01) +#define REG_MB_CPLD_VERSION (REG_BASE_MB + 0x02) +#define REG_MB_CPLD_BUILD (REG_BASE_MB + 0x04) +#define REG_MB_MUX_RESET (REG_BASE_MB + 0x46) +#define REG_MB_MUX_CTRL (REG_BASE_MB + 0x5c) + +//I2C Alert +#if CPU_TYPE == CPU_SKY +#define REG_ALERT_STATUS (REG_BASE_I2C_ALERT + 0x80) +#else +#define REG_ALERT_STATUS (REG_BASE_I2C_ALERT + 0x00) +#define REG_ALERT_DISABLE (REG_BASE_I2C_ALERT + 0x11) +#endif + +#define MASK_ALL (0xFF) +#define LPC_MDELAY (5) + +/* LPC sysfs attributes index */ +enum lpc_sysfs_attributes { + //CPU CPLD + ATT_CPU_CPLD_VERSION, + ATT_CPU_CPLD_VERSION_H, + ATT_CPU_BIOS_BOOT_ROM, + ATT_CPU_BIOS_BOOT_CFG, + ATT_CPU_CPLD_BUILD, + //MB CPLD + ATT_MB_BRD_ID_0, + ATT_MB_BRD_ID_1, + ATT_MB_CPLD_1_VERSION, + ATT_MB_CPLD_1_VERSION_H, + ATT_MB_CPLD_1_BUILD, + ATT_MB_MUX_CTRL, + ATT_MB_MUX_RESET, + ATT_MB_BRD_SKU_ID, + ATT_MB_BRD_HW_ID, + ATT_MB_BRD_ID_TYPE, + ATT_MB_BRD_BUILD_ID, + ATT_MB_BRD_DEPH_ID, + //I2C Alert + ATT_ALERT_STATUS, +#if CPU_TYPE == CPU_BDE + ATT_ALERT_DISABLE, +#endif + //BSP + ATT_BSP_VERSION, + ATT_BSP_DEBUG, + ATT_BSP_PR_INFO, + ATT_BSP_PR_ERR, + ATT_BSP_REG, + ATT_MAX +}; + +enum bsp_log_types { + LOG_NONE, + LOG_RW, + LOG_READ, + LOG_WRITE, + LOG_SYS +}; + +enum bsp_log_ctrl { + LOG_DISABLE, + LOG_ENABLE +}; + +struct lpc_data_s { + struct mutex access_lock; +}; + +struct lpc_data_s *lpc_data; +char bsp_version[16]=""; +char bsp_debug[2]="0"; +char bsp_reg[8]="0x0"; +u8 enable_log_read=LOG_DISABLE; +u8 enable_log_write=LOG_DISABLE; +u8 enable_log_sys=LOG_ENABLE; + +/* reg shift */ +static u8 _shift(u8 mask) +{ + int i=0, mask_one=1; + + for(i=0; i<8; ++i) { + if ((mask & mask_one) == 1) + return i; + else + mask >>= 1; + } + + return -1; +} + +/* reg mask and shift */ +static u8 _mask_shift(u8 val, u8 mask) +{ + int shift=0; + + shift = _shift(mask); + + return (val & mask) >> shift; +} + +static u8 _bit_operation(u8 reg_val, u8 bit, u8 bit_val) +{ + if (bit_val == 0) + reg_val = reg_val & ~(1 << bit); + else + reg_val = reg_val | (1 << bit); + return reg_val; +} + +static int _bsp_log(u8 log_type, char *fmt, ...) +{ + if ((log_type==LOG_READ && enable_log_read) || + (log_type==LOG_WRITE && enable_log_write) || + (log_type==LOG_SYS && enable_log_sys) ) { + va_list args; + int r; + + va_start(args, fmt); + r = vprintk(fmt, args); + va_end(args); + + return r; + } else { + return 0; + } +} + +static int _config_bsp_log(u8 log_type) +{ + switch(log_type) { + case LOG_NONE: + enable_log_read = LOG_DISABLE; + enable_log_write = LOG_DISABLE; + break; + case LOG_RW: + enable_log_read = LOG_ENABLE; + enable_log_write = LOG_ENABLE; + break; + case LOG_READ: + enable_log_read = LOG_ENABLE; + enable_log_write = LOG_DISABLE; + break; + case LOG_WRITE: + enable_log_read = LOG_DISABLE; + enable_log_write = LOG_ENABLE; + break; + default: + return -EINVAL; + } + return 0; +} + +/* get lpc register value */ +static u8 _read_lpc_reg(u16 reg, u8 mask) +{ + u8 reg_val; + + mutex_lock(&lpc_data->access_lock); + reg_val=_mask_shift(inb(reg), mask); + mutex_unlock(&lpc_data->access_lock); + + BSP_LOG_R("reg=0x%03x, reg_val=0x%02x", reg, reg_val); + + return reg_val; +} + +/* get lpc register value */ +static ssize_t read_lpc_reg(u16 reg, u8 mask, char *buf) +{ + u8 reg_val; + int len=0; + + reg_val = _read_lpc_reg(reg, mask); + len=sprintf(buf,"0x%x\n", reg_val); + + return len; +} + +/* set lpc register value */ +static ssize_t write_lpc_reg(u16 reg, u8 mask, const char *buf, size_t count) +{ + u8 reg_val, reg_val_now, shift; + + if (kstrtou8(buf, 0, ®_val) < 0) + return -EINVAL; + + //apply SINGLE BIT operation if mask is specified, multiple bits are not supported + if (mask != MASK_ALL) { + reg_val_now = _read_lpc_reg(reg, 0x0); + shift = _shift(mask); + reg_val = _bit_operation(reg_val_now, shift, reg_val); + } + + mutex_lock(&lpc_data->access_lock); + + outb(reg_val, reg); + mdelay(LPC_MDELAY); + + mutex_unlock(&lpc_data->access_lock); + + BSP_LOG_W("reg=0x%03x, reg_val=0x%02x", reg, reg_val); + + return count; +} + +/* get bsp value */ +static ssize_t read_bsp(char *buf, char *str) +{ + ssize_t len=0; + + mutex_lock(&lpc_data->access_lock); + len=sprintf(buf, "%s", str); + mutex_unlock(&lpc_data->access_lock); + + BSP_LOG_R("reg_val=%s", str); + + return len; +} + +/* set bsp value */ +static ssize_t write_bsp(const char *buf, char *str, size_t str_len, size_t count) +{ + mutex_lock(&lpc_data->access_lock); + snprintf(str, str_len, "%s", buf); + mutex_unlock(&lpc_data->access_lock); + + BSP_LOG_W("reg_val=%s", str); + + return count; +} + +/* get cpu cpld version in human readable format */ +static ssize_t read_cpu_cpld_version_h(struct device *dev, + struct device_attribute *da, char *buf) +{ + ssize_t len=0; + u16 reg = REG_CPU_CPLD_VERSION; + u8 mask = MASK_ALL; + u8 mask_major = 0b11000000; + u8 mask_minor = 0b00111111; + u8 reg_val; + u8 major, minor, build; + + mutex_lock(&lpc_data->access_lock); + reg_val = _mask_shift(inb(reg), mask); + major = _mask_shift(reg_val, mask_major); + minor = _mask_shift(reg_val, mask_minor); + reg = REG_CPU_CPLD_BUILD; + build = _mask_shift(inb(reg), mask); + len = sprintf(buf, "%d.%02d.%03d\n", major, minor, build); + mutex_unlock(&lpc_data->access_lock); + + BSP_LOG_R("reg=0x%03x, reg_val=0x%02x", reg, reg_val); + + return len; +} + +/* get mb cpld version in human readable format */ +static ssize_t read_mb_cpld_1_version_h(struct device *dev, + struct device_attribute *da, char *buf) +{ + ssize_t len=0; + u16 reg = REG_MB_CPLD_VERSION; + u8 mask = MASK_ALL; + u8 mask_major = 0b11000000; + u8 mask_minor = 0b00111111; + u8 reg_val; + u8 major, minor, build; + + mutex_lock(&lpc_data->access_lock); + reg_val = _mask_shift(inb(reg), mask); + major = _mask_shift(reg_val, mask_major); + minor = _mask_shift(reg_val, mask_minor); + reg = REG_MB_CPLD_BUILD; + build = _mask_shift(inb(reg), mask); + len = sprintf(buf, "%d.%02d.%03d\n", major, minor, build); + mutex_unlock(&lpc_data->access_lock); + + BSP_LOG_R("reg=0x%03x, reg_val=0x%02x", reg, reg_val); + + return len; +} + +/* get mux_reset register value */ +static ssize_t read_mux_reset_callback(struct device *dev, + struct device_attribute *da, char *buf) +{ + int len = 0; + u16 reg = REG_MB_MUX_RESET; + u8 mask = 0b00011111; + u8 reg_val; + + mutex_lock(&lpc_data->access_lock); + reg_val=_mask_shift(inb(reg), mask); + BSP_LOG_R("reg=0x%03x, reg_val=0x%02x", reg, reg_val); + len=sprintf(buf, "%d\n", reg_val); + mutex_unlock(&lpc_data->access_lock); + + return len; +} + +/* set mux_reset register value */ +static ssize_t write_mux_reset_callback(struct device *dev, + struct device_attribute *da, const char *buf, size_t count) +{ + u8 val = 0; + u16 reg = REG_MB_MUX_RESET; + u8 reg_val = 0; + u8 mask = 0b00011111; + static int mux_reset_flag = 0; + + if (kstrtou8(buf, 0, &val) < 0) + return -EINVAL; + + if (mux_reset_flag == 0) { + if (val == 0) { + mutex_lock(&lpc_data->access_lock); + mux_reset_flag = 1; + BSP_LOG_W("i2c mux reset is triggered..."); + + reg_val = inb(reg); + outb((reg_val & ~mask), reg); + mdelay(LPC_MDELAY); + BSP_LOG_W("reg=0x%03x, reg_val=0x%02x", reg, reg_val & ~mask); + mdelay(500); + outb((reg_val | mask), reg); + mdelay(LPC_MDELAY); + BSP_LOG_W("reg=0x%03x, reg_val=0x%02x", reg, reg_val | mask); + mdelay(500); + mux_reset_flag = 0; + mutex_unlock(&lpc_data->access_lock); + } else { + return -EINVAL; + } + } else { + BSP_LOG_W("i2c mux is resetting... (ignore)"); + mutex_lock(&lpc_data->access_lock); + mutex_unlock(&lpc_data->access_lock); + } + + return count; +} + +/* get lpc register value */ +static ssize_t read_lpc_callback(struct device *dev, + struct device_attribute *da, char *buf) +{ + struct sensor_device_attribute *attr = to_sensor_dev_attr(da); + u16 reg = 0; + u8 mask = MASK_ALL; + + switch (attr->index) { + //CPU CPLD + case ATT_CPU_CPLD_VERSION: + reg = REG_CPU_CPLD_VERSION; + break; + case ATT_CPU_BIOS_BOOT_ROM: + reg = REG_CPU_STATUS_1; + mask = 0x80; + break; + case ATT_CPU_BIOS_BOOT_CFG: + reg = REG_CPU_CTRL_1; + mask = 0x80; + break; + case ATT_CPU_CPLD_BUILD: + reg = REG_CPU_CPLD_BUILD; + break; + //MB CPLD + case ATT_MB_BRD_ID_0: + reg = REG_MB_BRD_ID_0; + break; + case ATT_MB_BRD_ID_1: + reg = REG_MB_BRD_ID_1; + break; + case ATT_MB_CPLD_1_VERSION: + reg = REG_MB_CPLD_VERSION; + break; + case ATT_MB_CPLD_1_BUILD: + reg = REG_MB_CPLD_BUILD; + break; + case ATT_MB_BRD_SKU_ID: + reg = REG_MB_BRD_ID_0; + mask = 0xFF; + break; + case ATT_MB_BRD_HW_ID: + reg = REG_MB_BRD_ID_1; + mask = 0x03; + break; + case ATT_MB_BRD_ID_TYPE: + reg = REG_MB_BRD_ID_1; + mask = 0x80; + break; + case ATT_MB_BRD_BUILD_ID: + reg = REG_MB_BRD_ID_1; + mask = 0x38; + break; + case ATT_MB_BRD_DEPH_ID: + reg = REG_MB_BRD_ID_1; + mask = 0x04; + break; + case ATT_MB_MUX_CTRL: + reg = REG_MB_MUX_CTRL; + break; + //I2C Alert + case ATT_ALERT_STATUS: + reg = REG_ALERT_STATUS; + mask = 0x20; + break; +#if CPU_TYPE == CPU_BDE + case ATT_ALERT_DISABLE: + reg = REG_ALERT_DISABLE; + mask = 0x04; + break; +#endif + //BSP + case ATT_BSP_REG: + if (kstrtou16(bsp_reg, 0, ®) < 0) + return -EINVAL; + break; + default: + return -EINVAL; + } + return read_lpc_reg(reg, mask, buf); +} + +/* set lpc register value */ +static ssize_t write_lpc_callback(struct device *dev, + struct device_attribute *da, const char *buf, size_t count) +{ + struct sensor_device_attribute *attr = to_sensor_dev_attr(da); + u16 reg = 0; + u8 mask = MASK_ALL; + + switch (attr->index) { + case ATT_MB_MUX_CTRL: + reg = REG_MB_MUX_CTRL; + break; + default: + return -EINVAL; + } + return write_lpc_reg(reg, mask, buf, count); +} + +/* get bsp parameter value */ +static ssize_t read_bsp_callback(struct device *dev, + struct device_attribute *da, char *buf) +{ + struct sensor_device_attribute *attr = to_sensor_dev_attr(da); + int str_len=0; + char *str=NULL; + + switch (attr->index) { + case ATT_BSP_VERSION: + str = bsp_version; + str_len = sizeof(bsp_version); + break; + case ATT_BSP_DEBUG: + str = bsp_debug; + str_len = sizeof(bsp_debug); + break; + case ATT_BSP_REG: + str = bsp_reg; + str_len = sizeof(bsp_reg); + break; + default: + return -EINVAL; + } + return read_bsp(buf, str); +} + +/* set bsp parameter value */ +static ssize_t write_bsp_callback(struct device *dev, + struct device_attribute *da, const char *buf, size_t count) +{ + struct sensor_device_attribute *attr = to_sensor_dev_attr(da); + int str_len=0; + char *str=NULL; + u16 reg = 0; + u8 bsp_debug_u8 = 0; + + switch (attr->index) { + case ATT_BSP_VERSION: + str = bsp_version; + str_len = sizeof(bsp_version); + break; + case ATT_BSP_DEBUG: + str = bsp_debug; + str_len = sizeof(bsp_debug); + break; + case ATT_BSP_REG: + if (kstrtou16(buf, 0, ®) < 0) + return -EINVAL; + + str = bsp_reg; + str_len = sizeof(bsp_reg); + break; + default: + return -EINVAL; + } + + if (attr->index == ATT_BSP_DEBUG) { + if (kstrtou8(buf, 0, &bsp_debug_u8) < 0) { + return -EINVAL; + } else if (_config_bsp_log(bsp_debug_u8) < 0) { + return -EINVAL; + } + } + + return write_bsp(buf, str, str_len, count); +} + +static ssize_t write_bsp_pr_callback(struct device *dev, + struct device_attribute *da, const char *buf, size_t count) +{ + struct sensor_device_attribute *attr = to_sensor_dev_attr(da); + int str_len = strlen(buf); + + if(str_len <= 0) + return str_len; + + switch (attr->index) { + case ATT_BSP_PR_INFO: + BSP_PR(KERN_INFO, "%s", buf); + break; + case ATT_BSP_PR_ERR: + BSP_PR(KERN_ERR, "%s", buf); + break; + default: + return -EINVAL; + } + + return str_len; +} + +//SENSOR_DEVICE_ATTR - CPU +static SENSOR_DEVICE_ATTR(cpu_cpld_version, S_IRUGO, read_lpc_callback, NULL, ATT_CPU_CPLD_VERSION); +static SENSOR_DEVICE_ATTR(cpu_cpld_version_h, S_IRUGO, read_cpu_cpld_version_h, NULL, ATT_CPU_CPLD_VERSION_H); +static SENSOR_DEVICE_ATTR(boot_rom, S_IRUGO, read_lpc_callback, NULL, ATT_CPU_BIOS_BOOT_ROM); +static SENSOR_DEVICE_ATTR(boot_cfg, S_IRUGO, read_lpc_callback, NULL, ATT_CPU_BIOS_BOOT_CFG); +static SENSOR_DEVICE_ATTR(cpu_cpld_build, S_IRUGO, read_lpc_callback, NULL, ATT_CPU_CPLD_BUILD); +//SENSOR_DEVICE_ATTR - MB +static SENSOR_DEVICE_ATTR(board_id_0, S_IRUGO, read_lpc_callback, NULL, ATT_MB_BRD_ID_0); +static SENSOR_DEVICE_ATTR(board_id_1, S_IRUGO, read_lpc_callback, NULL, ATT_MB_BRD_ID_1); +static SENSOR_DEVICE_ATTR(mb_cpld_1_version, S_IRUGO, read_lpc_callback, NULL, ATT_MB_CPLD_1_VERSION); +static SENSOR_DEVICE_ATTR(mb_cpld_1_version_h, S_IRUGO, read_mb_cpld_1_version_h, NULL, ATT_MB_CPLD_1_VERSION_H); +static SENSOR_DEVICE_ATTR(mb_cpld_1_build, S_IRUGO, read_lpc_callback, NULL, ATT_MB_CPLD_1_BUILD); +static SENSOR_DEVICE_ATTR(mux_ctrl, S_IRUGO | S_IWUSR, read_lpc_callback, write_lpc_callback, ATT_MB_MUX_CTRL); +static SENSOR_DEVICE_ATTR(mux_reset, S_IRUGO | S_IWUSR, read_mux_reset_callback, write_mux_reset_callback, ATT_MB_MUX_RESET); +static SENSOR_DEVICE_ATTR(board_sku_id, S_IRUGO, read_lpc_callback, NULL, ATT_MB_BRD_SKU_ID); +static SENSOR_DEVICE_ATTR(board_hw_id, S_IRUGO, read_lpc_callback, NULL, ATT_MB_BRD_HW_ID); +static SENSOR_DEVICE_ATTR(board_id_type, S_IRUGO, read_lpc_callback, NULL, ATT_MB_BRD_ID_TYPE); +static SENSOR_DEVICE_ATTR(board_build_id, S_IRUGO, read_lpc_callback, NULL, ATT_MB_BRD_BUILD_ID); +static SENSOR_DEVICE_ATTR(board_deph_id, S_IRUGO, read_lpc_callback, NULL, ATT_MB_BRD_DEPH_ID); +//SENSOR_DEVICE_ATTR - I2C Alert +static SENSOR_DEVICE_ATTR(alert_status, S_IRUGO, read_lpc_callback, NULL, ATT_ALERT_STATUS); +#if CPU_TYPE == CPU_BDE +static SENSOR_DEVICE_ATTR(alert_disable, S_IRUGO, read_lpc_callback, NULL, ATT_ALERT_DISABLE); +#endif +//SENSOR_DEVICE_ATTR - BSP +static SENSOR_DEVICE_ATTR(bsp_version, S_IRUGO | S_IWUSR, read_bsp_callback, write_bsp_callback, ATT_BSP_VERSION); +static SENSOR_DEVICE_ATTR(bsp_debug, S_IRUGO | S_IWUSR, read_bsp_callback, write_bsp_callback, ATT_BSP_DEBUG); +static SENSOR_DEVICE_ATTR(bsp_pr_info, S_IWUSR, NULL, write_bsp_pr_callback, ATT_BSP_PR_INFO); +static SENSOR_DEVICE_ATTR(bsp_pr_err, S_IWUSR, NULL, write_bsp_pr_callback, ATT_BSP_PR_ERR); +static SENSOR_DEVICE_ATTR(bsp_reg, S_IRUGO | S_IWUSR, read_lpc_callback, write_bsp_callback, ATT_BSP_REG); + +static struct attribute *cpu_cpld_attrs[] = { + &sensor_dev_attr_cpu_cpld_version.dev_attr.attr, + &sensor_dev_attr_cpu_cpld_version_h.dev_attr.attr, + &sensor_dev_attr_cpu_cpld_build.dev_attr.attr, + NULL, +}; + +static struct attribute *mb_cpld_attrs[] = { + &sensor_dev_attr_board_id_0.dev_attr.attr, + &sensor_dev_attr_board_id_1.dev_attr.attr, + &sensor_dev_attr_mb_cpld_1_version.dev_attr.attr, + &sensor_dev_attr_mb_cpld_1_version_h.dev_attr.attr, + &sensor_dev_attr_mb_cpld_1_build.dev_attr.attr, + &sensor_dev_attr_board_sku_id.dev_attr.attr, + &sensor_dev_attr_board_hw_id.dev_attr.attr, + &sensor_dev_attr_board_id_type.dev_attr.attr, + &sensor_dev_attr_board_build_id.dev_attr.attr, + &sensor_dev_attr_board_deph_id.dev_attr.attr, + &sensor_dev_attr_mux_ctrl.dev_attr.attr, + &sensor_dev_attr_mux_reset.dev_attr.attr, + NULL, +}; + +static struct attribute *bios_attrs[] = { + &sensor_dev_attr_boot_rom.dev_attr.attr, + &sensor_dev_attr_boot_cfg.dev_attr.attr, + NULL, +}; + +static struct attribute *i2c_alert_attrs[] = { + &sensor_dev_attr_alert_status.dev_attr.attr, +#if CPU_TYPE == CPU_BDE + &sensor_dev_attr_alert_disable.dev_attr.attr, +#endif + NULL, +}; + +static struct attribute *bsp_attrs[] = { + &sensor_dev_attr_bsp_version.dev_attr.attr, + &sensor_dev_attr_bsp_debug.dev_attr.attr, + &sensor_dev_attr_bsp_pr_info.dev_attr.attr, + &sensor_dev_attr_bsp_pr_err.dev_attr.attr, + &sensor_dev_attr_bsp_reg.dev_attr.attr, + NULL, +}; + +static struct attribute_group cpu_cpld_attr_grp = { + .name = "cpu_cpld", + .attrs = cpu_cpld_attrs, +}; + +static struct attribute_group mb_cpld_attr_grp = { + .name = "mb_cpld", + .attrs = mb_cpld_attrs, +}; + +static struct attribute_group bios_attr_grp = { + .name = "bios", + .attrs = bios_attrs, +}; + +static struct attribute_group i2c_alert_attr_grp = { + .name = "i2c_alert", + .attrs = i2c_alert_attrs, +}; + +static struct attribute_group bsp_attr_grp = { + .name = "bsp", + .attrs = bsp_attrs, +}; + +static void lpc_dev_release( struct device * dev) +{ + return; +} + +static struct platform_device lpc_dev = { + .name = DRIVER_NAME, + .id = -1, + .dev = { + .release = lpc_dev_release, + } +}; + +static int lpc_drv_probe(struct platform_device *pdev) +{ + int i = 0, grp_num = 5; + int err[5] = {0}; + struct attribute_group *grp; + + lpc_data = devm_kzalloc(&pdev->dev, sizeof(struct lpc_data_s), + GFP_KERNEL); + if (!lpc_data) + return -ENOMEM; + + mutex_init(&lpc_data->access_lock); + + for (i=0; idev.kobj, grp); + if (err[i]) { + printk(KERN_ERR "Cannot create sysfs for group %s\n", grp->name); + goto exit; + } else { + continue; + } + } + + return 0; + +exit: + for (i=0; idev.kobj, grp); + if (!err[i]) { + //remove previous successful cases + continue; + } else { + //remove first failed case, then return + return err[i]; + } + } + return 0; +} + +static int lpc_drv_remove(struct platform_device *pdev) +{ + sysfs_remove_group(&pdev->dev.kobj, &cpu_cpld_attr_grp); + sysfs_remove_group(&pdev->dev.kobj, &mb_cpld_attr_grp); + sysfs_remove_group(&pdev->dev.kobj, &bios_attr_grp); + sysfs_remove_group(&pdev->dev.kobj, &i2c_alert_attr_grp); + sysfs_remove_group(&pdev->dev.kobj, &bsp_attr_grp); + + return 0; +} + +static struct platform_driver lpc_drv = { + .probe = lpc_drv_probe, + .remove = __exit_p(lpc_drv_remove), + .driver = { + .name = DRIVER_NAME, + }, +}; + +int lpc_init(void) +{ + int err = 0; + + err = platform_driver_register(&lpc_drv); + if (err) { + printk(KERN_ERR "%s(#%d): platform_driver_register failed(%d)\n", + __func__, __LINE__, err); + + return err; + } + + err = platform_device_register(&lpc_dev); + if (err) { + printk(KERN_ERR "%s(#%d): platform_device_register failed(%d)\n", + __func__, __LINE__, err); + platform_driver_unregister(&lpc_drv); + return err; + } + + return err; +} + +void lpc_exit(void) +{ + platform_driver_unregister(&lpc_drv); + platform_device_unregister(&lpc_dev); +} + +MODULE_AUTHOR("Leo Lin "); +MODULE_DESCRIPTION("x86_64_ufispace_s9300_32d_lpc driver"); +MODULE_LICENSE("GPL"); + +module_init(lpc_init); +module_exit(lpc_exit); diff --git a/platform/broadcom/sonic-platform-modules-ufispace/s9300-32d/modules/x86-64-ufispace-s9300-32d-sys-eeprom.c b/platform/broadcom/sonic-platform-modules-ufispace/s9300-32d/modules/x86-64-ufispace-s9300-32d-sys-eeprom.c index 225a8c50d636..e72afddc7419 100644 --- a/platform/broadcom/sonic-platform-modules-ufispace/s9300-32d/modules/x86-64-ufispace-s9300-32d-sys-eeprom.c +++ b/platform/broadcom/sonic-platform-modules-ufispace/s9300-32d/modules/x86-64-ufispace-s9300-32d-sys-eeprom.c @@ -1,273 +1,275 @@ -/* - * Copyright (C) 1998, 1999 Frodo Looijaard and - * Philip Edelbrock - * Copyright (C) 2003 Greg Kroah-Hartman - * Copyright (C) 2003 IBM Corp. - * Copyright (C) 2004 Jean Delvare - * - * 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. - */ - -/* enable dev_dbg print out */ -//#define DEBUG - -#define __STDC_WANT_LIB_EXT1__ 1 -#include -#include -#include -#include -#include -#include -#include - -/* Addresses to scan */ -static const unsigned short normal_i2c[] = { /*0x50, 0x51, 0x52, 0x53, 0x54, - 0x55, 0x56, 0x57,*/ I2C_CLIENT_END }; - -/* Size of EEPROM in bytes */ -#define EEPROM_SIZE 512 - -#define SLICE_BITS (6) -#define SLICE_SIZE (1 << SLICE_BITS) -#define SLICE_NUM (EEPROM_SIZE/SLICE_SIZE) - -/* Each client has this additional data */ -struct eeprom_data { - struct mutex update_lock; - u8 valid; /* bitfield, bit!=0 if slice is valid */ - unsigned long last_updated[SLICE_NUM]; /* In jiffies, 8 slices */ - u8 data[EEPROM_SIZE]; /* Register values */ -}; - - -static void sys_eeprom_update_client(struct i2c_client *client, u8 slice) -{ - struct eeprom_data *data = i2c_get_clientdata(client); - int i, j; - int ret; - int addr; - - mutex_lock(&data->update_lock); - - if (!(data->valid & (1 << slice)) || - time_after(jiffies, data->last_updated[slice] + 300 * HZ)) { - dev_dbg(&client->dev, "Starting eeprom update, slice %u\n", slice); - - addr = slice << SLICE_BITS; - - ret = i2c_smbus_write_byte_data(client, (u8)((addr >> 8) & 0xFF), (u8)(addr & 0xFF)); - /* select the eeprom address */ - if (ret < 0) { - dev_err(&client->dev, "address set failed\n"); - goto exit; - } - - if (!i2c_check_functionality(client->adapter, I2C_FUNC_SMBUS_READ_BYTE)) { - goto exit; - } - - for (i = slice << SLICE_BITS; i < (slice + 1) << SLICE_BITS; i+= SLICE_SIZE) { - for (j = i; j < (i+SLICE_SIZE); j++) { - int res; - - res = i2c_smbus_read_byte(client); - if (res < 0) { - goto exit; - } - - data->data[j] = res & 0xFF; - } - } - - data->last_updated[slice] = jiffies; - data->valid |= (1 << slice); - } -exit: - mutex_unlock(&data->update_lock); -} - -static ssize_t sys_eeprom_read(struct file *filp, struct kobject *kobj, - struct bin_attribute *bin_attr, - char *buf, loff_t off, size_t count) -{ - struct i2c_client *client = to_i2c_client(container_of(kobj, struct device, kobj)); - struct eeprom_data *data = i2c_get_clientdata(client); - u8 slice; - - if (off > EEPROM_SIZE) { - return 0; - } - if (off + count > EEPROM_SIZE) { - count = EEPROM_SIZE - off; - } - if (count == 0) { - return 0; - } - - /* Only refresh slices which contain requested bytes */ - for (slice = off >> SLICE_BITS; slice <= (off + count - 1) >> SLICE_BITS; slice++) { - sys_eeprom_update_client(client, slice); - } - - memcpy(buf, &data->data[off], count); - - return count; -} - -static ssize_t sys_eeprom_write(struct file *filp, struct kobject *kobj, - struct bin_attribute *bin_attr, - char *buf, loff_t off, size_t count) -{ - struct i2c_client *client = to_i2c_client(container_of(kobj, struct device, kobj)); - struct eeprom_data *data = i2c_get_clientdata(client); - int ret; - int i; - u8 cmd; - u16 value16; - - dev_dbg(&client->dev, "sys_eeprom_write off=%d, count=%d\n", (int)off, (int)count); - - if (off > EEPROM_SIZE) { - return 0; - } - if (off + count > EEPROM_SIZE) { - count = EEPROM_SIZE - off; - } - if (count == 0) { - return 0; - } - - mutex_lock(&data->update_lock); - - for(i=0; i < count; i++) { - /* write command */ - cmd = (off >> 8) & 0xff; - value16 = off & 0xff; - value16 |= buf[i] << 8; - ret = i2c_smbus_write_word_data(client, cmd, value16); - - if (ret < 0) { - dev_err(&client->dev, "write address failed at %d \n", (int)off); - goto exit; - } - - off++; - - /* need to wait for write complete */ - udelay(10000); - } -exit: - mutex_unlock(&data->update_lock); - /* force to update client when reading */ - for(i=0; i < SLICE_NUM; i++) { - data->last_updated[i] = 0; - } - - return count; -} - -static struct bin_attribute sys_eeprom_attr = { - .attr = { - .name = "eeprom", - .mode = S_IRUGO | S_IWUSR, - }, - .size = EEPROM_SIZE, - .read = sys_eeprom_read, - .write = sys_eeprom_write, -}; - -/* Return 0 if detection is successful, -ENODEV otherwise */ -static int sys_eeprom_detect(struct i2c_client *client, struct i2c_board_info *info) -{ - struct i2c_adapter *adapter = client->adapter; - - /* EDID EEPROMs are often 24C00 EEPROMs, which answer to all - addresses 0x50-0x57, but we only care about 0x51 and 0x55. So decline - attaching to addresses >= 0x56 on DDC buses */ - if (!(adapter->class & I2C_CLASS_SPD) && client->addr >= 0x56) { - return -ENODEV; - } - - if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_READ_BYTE) - && !i2c_check_functionality(adapter, I2C_FUNC_SMBUS_WRITE_BYTE_DATA)) { - return -ENODEV; - } - - strlcpy(info->type, "eeprom", I2C_NAME_SIZE); - - return 0; -} - -static int sys_eeprom_probe(struct i2c_client *client, - const struct i2c_device_id *id) -{ - struct eeprom_data *data; - int err; - - if (!(data = kzalloc(sizeof(struct eeprom_data), GFP_KERNEL))) { - err = -ENOMEM; - goto exit; - } - -#ifdef __STDC_LIB_EXT1__ - memset_s(data->data, EEPROM_SIZE, 0xff, EEPROM_SIZE); -#else - memset(data->data, 0xff, EEPROM_SIZE); -#endif - - i2c_set_clientdata(client, data); - mutex_init(&data->update_lock); - - /* create the sysfs eeprom file */ - err = sysfs_create_bin_file(&client->dev.kobj, &sys_eeprom_attr); - if (err) { - goto exit_kfree; - } - - return 0; - -exit_kfree: - kfree(data); -exit: - return err; -} - -static int sys_eeprom_remove(struct i2c_client *client) -{ - sysfs_remove_bin_file(&client->dev.kobj, &sys_eeprom_attr); - kfree(i2c_get_clientdata(client)); - - return 0; -} - -static const struct i2c_device_id sys_eeprom_id[] = { - { "sys_eeprom", 0 }, - { } -}; - -static struct i2c_driver sys_eeprom_driver = { - .driver = { - .name = "sys_eeprom", - }, - .probe = sys_eeprom_probe, - .remove = sys_eeprom_remove, - .id_table = sys_eeprom_id, - - .class = I2C_CLASS_DDC | I2C_CLASS_SPD, - .detect = sys_eeprom_detect, - .address_list = normal_i2c, -}; - -module_i2c_driver(sys_eeprom_driver); - -MODULE_AUTHOR("Wade "); -MODULE_DESCRIPTION("UfiSpace Mother Board EEPROM driver"); -MODULE_LICENSE("GPL"); +/* + * Copyright (C) 1998, 1999 Frodo Looijaard and + * Philip Edelbrock + * Copyright (C) 2003 Greg Kroah-Hartman + * Copyright (C) 2003 IBM Corp. + * Copyright (C) 2004 Jean Delvare + * + * 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. + */ + +/* enable dev_dbg print out */ +//#define DEBUG + +#define __STDC_WANT_LIB_EXT1__ 1 +#include +#include +#include +#include +#include +#include +#include + +#define _memset(s, c, n) memset(s, c, n) + +/* Addresses to scan */ +static const unsigned short normal_i2c[] = { /*0x50, 0x51, 0x52, 0x53, 0x54, + 0x55, 0x56, 0x57,*/ I2C_CLIENT_END }; + +/* Size of EEPROM in bytes */ +#define EEPROM_SIZE 512 + +#define SLICE_BITS (6) +#define SLICE_SIZE (1 << SLICE_BITS) +#define SLICE_NUM (EEPROM_SIZE/SLICE_SIZE) + +/* Each client has this additional data */ +struct eeprom_data { + struct mutex update_lock; + u8 valid; /* bitfield, bit!=0 if slice is valid */ + unsigned long last_updated[SLICE_NUM]; /* In jiffies, 8 slices */ + u8 data[EEPROM_SIZE]; /* Register values */ +}; + + +static void sys_eeprom_update_client(struct i2c_client *client, u8 slice) +{ + struct eeprom_data *data = i2c_get_clientdata(client); + int i, j; + int ret; + int addr; + + mutex_lock(&data->update_lock); + + if (!(data->valid & (1 << slice)) || + time_after(jiffies, data->last_updated[slice] + 300 * HZ)) { + dev_dbg(&client->dev, "Starting eeprom update, slice %u\n", slice); + + addr = slice << SLICE_BITS; + + ret = i2c_smbus_write_byte_data(client, (u8)((addr >> 8) & 0xFF), (u8)(addr & 0xFF)); + /* select the eeprom address */ + if (ret < 0) { + dev_err(&client->dev, "address set failed\n"); + goto exit; + } + + if (!i2c_check_functionality(client->adapter, I2C_FUNC_SMBUS_READ_BYTE)) { + goto exit; + } + + for (i = slice << SLICE_BITS; i < (slice + 1) << SLICE_BITS; i+= SLICE_SIZE) { + for (j = i; j < (i+SLICE_SIZE); j++) { + int res; + + res = i2c_smbus_read_byte(client); + if (res < 0) { + goto exit; + } + + data->data[j] = res & 0xFF; + } + } + + data->last_updated[slice] = jiffies; + data->valid |= (1 << slice); + } +exit: + mutex_unlock(&data->update_lock); +} + +static ssize_t sys_eeprom_read(struct file *filp, struct kobject *kobj, + struct bin_attribute *bin_attr, + char *buf, loff_t off, size_t count) +{ + struct i2c_client *client = to_i2c_client(container_of(kobj, struct device, kobj)); + struct eeprom_data *data = i2c_get_clientdata(client); + u8 slice; + + if (off > EEPROM_SIZE) { + return 0; + } + if (off + count > EEPROM_SIZE) { + count = EEPROM_SIZE - off; + } + if (count == 0) { + return 0; + } + + /* Only refresh slices which contain requested bytes */ + for (slice = off >> SLICE_BITS; slice <= (off + count - 1) >> SLICE_BITS; slice++) { + sys_eeprom_update_client(client, slice); + } + + memcpy(buf, &data->data[off], count); + + return count; +} + +static ssize_t sys_eeprom_write(struct file *filp, struct kobject *kobj, + struct bin_attribute *bin_attr, + char *buf, loff_t off, size_t count) +{ + struct i2c_client *client = to_i2c_client(container_of(kobj, struct device, kobj)); + struct eeprom_data *data = i2c_get_clientdata(client); + int ret; + int i; + u8 cmd; + u16 value16; + + dev_dbg(&client->dev, "sys_eeprom_write off=%d, count=%d\n", (int)off, (int)count); + + if (off > EEPROM_SIZE) { + return 0; + } + if (off + count > EEPROM_SIZE) { + count = EEPROM_SIZE - off; + } + if (count == 0) { + return 0; + } + + mutex_lock(&data->update_lock); + + for(i=0; i < count; i++) { + /* write command */ + cmd = (off >> 8) & 0xff; + value16 = off & 0xff; + value16 |= buf[i] << 8; + ret = i2c_smbus_write_word_data(client, cmd, value16); + + if (ret < 0) { + dev_err(&client->dev, "write address failed at %d \n", (int)off); + goto exit; + } + + off++; + + /* need to wait for write complete */ + udelay(10000); + } +exit: + mutex_unlock(&data->update_lock); + /* force to update client when reading */ + for(i=0; i < SLICE_NUM; i++) { + data->last_updated[i] = 0; + } + + return count; +} + +static struct bin_attribute sys_eeprom_attr = { + .attr = { + .name = "eeprom", + .mode = S_IRUGO | S_IWUSR, + }, + .size = EEPROM_SIZE, + .read = sys_eeprom_read, + .write = sys_eeprom_write, +}; + +/* Return 0 if detection is successful, -ENODEV otherwise */ +static int sys_eeprom_detect(struct i2c_client *client, struct i2c_board_info *info) +{ + struct i2c_adapter *adapter = client->adapter; + + /* EDID EEPROMs are often 24C00 EEPROMs, which answer to all + addresses 0x50-0x57, but we only care about 0x51 and 0x55. So decline + attaching to addresses >= 0x56 on DDC buses */ + if (!(adapter->class & I2C_CLASS_SPD) && client->addr >= 0x56) { + return -ENODEV; + } + + if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_READ_BYTE) + && !i2c_check_functionality(adapter, I2C_FUNC_SMBUS_WRITE_BYTE_DATA)) { + return -ENODEV; + } + + strlcpy(info->type, "eeprom", I2C_NAME_SIZE); + + return 0; +} + +static int sys_eeprom_probe(struct i2c_client *client, + const struct i2c_device_id *id) +{ + struct eeprom_data *data; + int err; + + if (!(data = kzalloc(sizeof(struct eeprom_data), GFP_KERNEL))) { + err = -ENOMEM; + goto exit; + } + +#ifdef __STDC_LIB_EXT1__ + memset_s(data->data, EEPROM_SIZE, 0xff, EEPROM_SIZE); +#else + _memset(data->data, 0xff, EEPROM_SIZE); +#endif + + i2c_set_clientdata(client, data); + mutex_init(&data->update_lock); + + /* create the sysfs eeprom file */ + err = sysfs_create_bin_file(&client->dev.kobj, &sys_eeprom_attr); + if (err) { + goto exit_kfree; + } + + return 0; + +exit_kfree: + kfree(data); +exit: + return err; +} + +static int sys_eeprom_remove(struct i2c_client *client) +{ + sysfs_remove_bin_file(&client->dev.kobj, &sys_eeprom_attr); + kfree(i2c_get_clientdata(client)); + + return 0; +} + +static const struct i2c_device_id sys_eeprom_id[] = { + { "sys_eeprom", 0 }, + { } +}; + +static struct i2c_driver sys_eeprom_driver = { + .driver = { + .name = "sys_eeprom", + }, + .probe = sys_eeprom_probe, + .remove = sys_eeprom_remove, + .id_table = sys_eeprom_id, + + .class = I2C_CLASS_DDC | I2C_CLASS_SPD, + .detect = sys_eeprom_detect, + .address_list = normal_i2c, +}; + +module_i2c_driver(sys_eeprom_driver); + +MODULE_AUTHOR("Wade "); +MODULE_DESCRIPTION("UfiSpace Mother Board EEPROM driver"); +MODULE_LICENSE("GPL"); diff --git a/platform/broadcom/sonic-platform-modules-ufispace/s9300-32d/sonic_platform/chassis.py b/platform/broadcom/sonic-platform-modules-ufispace/s9300-32d/sonic_platform/chassis.py index 267add0756d1..3f02f73daa8a 100644 --- a/platform/broadcom/sonic-platform-modules-ufispace/s9300-32d/sonic_platform/chassis.py +++ b/platform/broadcom/sonic-platform-modules-ufispace/s9300-32d/sonic_platform/chassis.py @@ -9,6 +9,7 @@ try: import time from sonic_platform_pddf_base.pddf_chassis import PddfChassis + from sonic_py_common import device_info except ImportError as e: raise ImportError(str(e) + "- required module not found") @@ -174,4 +175,15 @@ def get_reboot_cause(self): except IOError: sw_reboot_cause = "Unknown" - return ('REBOOT_CAUSE_NON_HARDWARE', sw_reboot_cause) \ No newline at end of file + return ('REBOOT_CAUSE_NON_HARDWARE', sw_reboot_cause) + + def get_serial_number(self): + """ + Retrieves the hardware serial number for the chassis + + Returns: + A string containing the hardware serial number for this + chassis. + """ + + return self.get_serial() \ No newline at end of file diff --git a/platform/broadcom/sonic-platform-modules-ufispace/s9300-32d/sonic_platform/component.py b/platform/broadcom/sonic-platform-modules-ufispace/s9300-32d/sonic_platform/component.py index f3346725c667..b94a10d616d6 100644 --- a/platform/broadcom/sonic-platform-modules-ufispace/s9300-32d/sonic_platform/component.py +++ b/platform/broadcom/sonic-platform-modules-ufispace/s9300-32d/sonic_platform/component.py @@ -18,9 +18,7 @@ } BMC_CMDS = { - "VER1": "ipmitool mc info | grep 'Firmware Revision' | cut -d':' -f2 | cut -d'.' -f1", - "VER2": "ipmitool mc info | grep 'Firmware Revision' | cut -d':' -f2 | cut -d'.' -f2", - "VER3": "echo $((`ipmitool mc info | grep 'Aux Firmware Rev Info' -A 2 | sed -n '2p'` + 0))", + "BMC": "bash -c 'tmp=$(ipmitool raw 0x6 0x1) && r=($(echo \"$tmp\" | cut -d \" \" -f 4,5,16,15,14)) && echo ${r[0]}.${r[1]}.${r[4]}.${r[3]}${r[2]}'", } BIOS_VERSION_PATH = "/sys/class/dmi/id/bios_version" @@ -83,17 +81,11 @@ def _get_cpld_version(self): def _get_bmc_version(self): # Retrieves the BMC firmware version - bmc_ver = dict() - for ver in BMC_CMDS: - status, value = subprocess.getstatusoutput(BMC_CMDS[ver]) - if not status: - bmc_ver[ver] = int(value.rstrip()) - else: - return None - - bmc_version = "{}.{}.{}".format(bmc_ver["VER1"], bmc_ver["VER2"], bmc_ver["VER3"]) - - return bmc_version + status, value = subprocess.getstatusoutput(BMC_CMDS["BMC"]) + if not status: + return value + else: + return None def get_name(self): """ diff --git a/platform/broadcom/sonic-platform-modules-ufispace/s9300-32d/sonic_platform/fan.py b/platform/broadcom/sonic-platform-modules-ufispace/s9300-32d/sonic_platform/fan.py index 6b99493ecb41..a2ef7be03721 100644 --- a/platform/broadcom/sonic-platform-modules-ufispace/s9300-32d/sonic_platform/fan.py +++ b/platform/broadcom/sonic-platform-modules-ufispace/s9300-32d/sonic_platform/fan.py @@ -135,7 +135,11 @@ def get_presence(self): mode = output['mode'] val = output['status'].strip() - vmap = self.plugin_data['FAN']['present'][mode]['valmap'] + + if self.is_psu_fan: + vmap = self.plugin_data['PSU']['psu_present'][mode]['valmap'] + else: + vmap = self.plugin_data['FAN']['present'][mode]['valmap'] if val in vmap: presence = vmap[val] diff --git a/platform/broadcom/sonic-platform-modules-ufispace/s9300-32d/sonic_platform/psu.py b/platform/broadcom/sonic-platform-modules-ufispace/s9300-32d/sonic_platform/psu.py index 29319e424b4d..3e213415f314 100644 --- a/platform/broadcom/sonic-platform-modules-ufispace/s9300-32d/sonic_platform/psu.py +++ b/platform/broadcom/sonic-platform-modules-ufispace/s9300-32d/sonic_platform/psu.py @@ -10,7 +10,7 @@ class Psu(PddfPsu): """PDDF Platform-Specific PSU class""" - PLATFORM_PSU_CAPACITY = 2000 + PLATFORM_PSU_CAPACITY = 1300 def __init__(self, index, pddf_data=None, pddf_plugin_data=None): PddfPsu.__init__(self, index, pddf_data, pddf_plugin_data) @@ -36,3 +36,21 @@ def get_power(self): # power is returned in micro watts return round(float(self.get_voltage()*self.get_current()), 2) + + def get_capacity(self): + """ + Retrieves the maximum supplied power by PSU (or PSU capacity) + Returns: + A float number, the maximum power output in Watts. + e.g. 1200.1 + """ + return self.get_maximum_supplied_power() + + def get_type(self): + """ + Gets the type of the PSU + + Returns: + A string, the type of PSU (AC/DC) + """ + return self.plugin_data['PSU']['DEFAULT_TYPE'] \ No newline at end of file diff --git a/platform/broadcom/sonic-platform-modules-ufispace/s9300-32d/sonic_platform/sfp.py b/platform/broadcom/sonic-platform-modules-ufispace/s9300-32d/sonic_platform/sfp.py index d9b6e491bef4..c7919482f69c 100644 --- a/platform/broadcom/sonic-platform-modules-ufispace/s9300-32d/sonic_platform/sfp.py +++ b/platform/broadcom/sonic-platform-modules-ufispace/s9300-32d/sonic_platform/sfp.py @@ -13,5 +13,19 @@ class Sfp(PddfSfp): def __init__(self, index, pddf_data=None, pddf_plugin_data=None): PddfSfp.__init__(self, index, pddf_data, pddf_plugin_data) + self.index = index # Provide the functions/variables below for which implementation is to be overwritten + + 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" + """ + if not self.get_presence(): + return self.SFP_STATUS_UNPLUGGED + + return self.SFP_STATUS_OK diff --git a/platform/broadcom/sonic-platform-modules-ufispace/s9300-32d/sonic_platform/watchdog.py b/platform/broadcom/sonic-platform-modules-ufispace/s9300-32d/sonic_platform/watchdog.py deleted file mode 100644 index 88660b1a1faa..000000000000 --- a/platform/broadcom/sonic-platform-modules-ufispace/s9300-32d/sonic_platform/watchdog.py +++ /dev/null @@ -1,23 +0,0 @@ -#!/usr/bin/env python - -############################################################################# -# -# Module contains an implementation of platform specific watchdog API's -# -############################################################################# - -try: - from sonic_platform_pddf_base.pddf_watchdog import PddfWatchdog -except ImportError as e: - raise ImportError(str(e) + "- required module not found") - -class Watchdog(PddfWatchdog): - """ - PDDF Platform-specific Chassis class - """ - - def __init__(self): - PddfWatchdog.__init__(self) - self.timeout= 180 - - # Provide the functions/variables below for which implementation is to be overwritten diff --git a/platform/broadcom/sonic-platform-modules-ufispace/s9300-32d/utils/pddf_post_device_create.sh b/platform/broadcom/sonic-platform-modules-ufispace/s9300-32d/utils/pddf_post_device_create.sh index 69e75aeef28d..e4de7ae3669e 100755 --- a/platform/broadcom/sonic-platform-modules-ufispace/s9300-32d/utils/pddf_post_device_create.sh +++ b/platform/broadcom/sonic-platform-modules-ufispace/s9300-32d/utils/pddf_post_device_create.sh @@ -1,3 +1,6 @@ #!/bin/bash +#disable bmc watchdog +timeout 3 ipmitool mc watchdog off + echo 1 > /sys/kernel/pddf/devices/sysstatus/sysstatus_data/port_led_clr_ctrl echo "PDDF device post-create completed" diff --git a/platform/broadcom/sonic-platform-modules-ufispace/s9300-32d/utils/pddf_pre_driver_install.sh b/platform/broadcom/sonic-platform-modules-ufispace/s9300-32d/utils/pddf_pre_driver_install.sh deleted file mode 100755 index 52bcb3962ea3..000000000000 --- a/platform/broadcom/sonic-platform-modules-ufispace/s9300-32d/utils/pddf_pre_driver_install.sh +++ /dev/null @@ -1,11 +0,0 @@ -#!/bin/bash -#rmmod gpio_ich -if [ ! -f /tmp/._pddf_pre_driver_init_completion ]; then - # make sure igb/i40e init in correct order - rmmod i40e - rmmod igb - modprobe igb - modprobe i40e - date > /tmp/._pddf_pre_driver_init_completion -fi -echo "PDDF driver pre-install completed"